Skip to content

Commit dbb712b

Browse files
committed
Fix a style generation bug on placement of state selector
1 parent 5d183ba commit dbb712b

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ export interface SerializableStyleRule {
562562
// (undocumented)
563563
properties?: Record<string, string>;
564564
// (undocumented)
565+
stateOnContext?: boolean;
566+
// (undocumented)
565567
styles?: string[];
566568
}
567569

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)