Skip to content

Commit 344a5e8

Browse files
authored
AUI state bug fix (#263)
* Fix a style generation bug on placement of state selector * Performance setting default update
1 parent a037da1 commit 344a5e8

File tree

8 files changed

+35
-7
lines changed

8 files changed

+35
-7
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fix a style generation bug on placement of state selector",
4+
"packageName": "@adaptive-web/adaptive-ui",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/adaptive-ui-designer-figma-plugin/src/figma/controller.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import type { PluginMessage} from "../core/messages.js";
44
import { FigmaPluginNode } from "./node.js";
55

66
export class FigmaController extends Controller {
7+
constructor() {
8+
super();
9+
10+
// Ignore invisible nodes for performance by default. There is a setting in the UI to toggle this.
11+
figma.skipInvisibleInstanceChildren = true;
12+
}
13+
714
public async getNode(id: string): Promise<FigmaPluginNode | null> {
815
const node = await figma.getNodeByIdAsync(id);
916
if (node) {

packages/adaptive-ui-designer-figma-plugin/src/figma/main.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import { FigmaController } from "./controller.js";
44

55
const controller = new FigmaController();
66

7-
// Ignore invisible nodes for performance, which means if someone turns them back to visible they may need to run the plugin again.
8-
// Update: With a reasonable number of invisible nodes the speed is no longer intolerable. Better to make sure styling is current.
9-
// figma.skipInvisibleInstanceChildren = true;
10-
117
figma.showUI(__html__, {
128
height: 600,
139
width: 356,

packages/adaptive-ui-designer-figma-plugin/src/ui/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ export class App extends FASTElement {
653653
}
654654

655655
@observable
656-
public skipInvisibleNodes: boolean = false;
656+
public skipInvisibleNodes: boolean = true;
657657
protected skipInvisibleNodesChanged(prev: boolean, next: boolean) {
658658
const message: SkipInvisibleNodesMessage = {
659659
type: "SKIP_INVISIBLE_NODES",

packages/adaptive-ui/docs/api-report.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,8 @@ export interface SerializableStyleRule {
628628
// (undocumented)
629629
properties?: Record<string, string>;
630630
// (undocumented)
631+
stateOnContext?: boolean;
632+
// (undocumented)
631633
styles?: string[];
632634
}
633635

packages/adaptive-ui/src/bin/aui.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ function jsonToAUIStyleSheet(obj: SerializableAnatomy): AUIStyleSheet {
305305
const target: StyleModuleTarget = {
306306
context: obj.context,
307307
contextCondition: createCondition(obj, style),
308+
stateOnContext: style.stateOnContext,
308309
part: resolvePart(obj, style.part),
309310
};
310311

packages/adaptive-ui/src/core/modules/element-styles-renderer.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ import type { ComponentAnatomy, StyleModuleEvaluateParameters, StyleRules } from
88
import { stylePropertyToCssProperty } from "./css.js";
99
import { convertStylesToFocusState, Styles } from "./styles.js";
1010

11+
const deepFreeze =<T>(obj: T): T => {
12+
if (obj && typeof obj === "object" && !Object.isFrozen(obj)) {
13+
Object.getOwnPropertyNames(obj).forEach((prop) => {
14+
const value = (obj as any)[prop];
15+
if (value && typeof value === "object") {
16+
deepFreeze(value);
17+
}
18+
});
19+
Object.freeze(obj);
20+
}
21+
return obj;
22+
}
23+
1124
/**
1225
* The properties and values of a css declaration.
1326
*/
@@ -160,7 +173,7 @@ export class ElementStylesRenderer {
160173
*/
161174
public render(target: StyleModuleTarget, interactivity?: InteractivityDefinition): ElementStyles {
162175
// Construct the evaluation params, not including interactivity if requested
163-
const effectiveInteractivity = interactivity || {};
176+
const effectiveInteractivity = { ...(interactivity || {}) };
164177
if (target.ignoreInteractivity === true) {
165178
Object.assign(effectiveInteractivity, Interactivity.always);
166179
}
@@ -240,6 +253,7 @@ export class ElementStylesRenderer {
240253
public static renderStyleRules(baseStyles: ComposableStyles[] = [], styleRules: StyleRules, anatomy?: ComponentAnatomy<any, any>) {
241254
const globalStyleRules: StyleRules = [];
242255
if (anatomy) {
256+
anatomy = deepFreeze(anatomy);
243257
// If this component can be disabled, apply the style to all children.
244258
if (ElementStylesRenderer.disabledStyles && anatomy.interactivity?.disabled !== undefined) {
245259
// Focus and disabled are related in the way that they define the footprint of an indicator:
@@ -292,7 +306,7 @@ export class ElementStylesRenderer {
292306
const styles = Styles.fromDeclaration(rule);
293307

294308
// Transform the target selector if necessary
295-
const target = rule.target || {} as StyleModuleTarget;
309+
const target = { ...(rule.target || {}) } as StyleModuleTarget;
296310
if (anatomy?.context && target.context === undefined) {
297311
target.context = anatomy.context;
298312
if (anatomy.context === target.part) {

packages/adaptive-ui/src/core/modules/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ export type SerializableCondition = SerializableBooleanCondition | SerializableS
508508
* @beta
509509
*/
510510
export interface SerializableStyleRule {
511+
stateOnContext?: boolean;
511512
contextCondition?: Record<string, string | boolean>;
512513
part?: string,
513514
styles?: string[],

0 commit comments

Comments
 (0)