Skip to content

Commit 270e484

Browse files
authored
AUI: Update CLI from tokens to align with existing properties (#216)
1 parent b48c67a commit 270e484

7 files changed

Lines changed: 45 additions & 52 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "AUI: Update CLI from `tokens` to align with existing `properties`",
4+
"packageName": "@adaptive-web/adaptive-ui",
5+
"email": "47367562+bheston@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "AUI: Update CLI from `tokens` to align with existing `properties`",
4+
"packageName": "@adaptive-web/adaptive-ui-designer-figma",
5+
"email": "47367562+bheston@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

packages/adaptive-ui-designer-figma-plugin/src/core/code-gen.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ export class CodeGen {
8585
const varName = StyleNameMapping[style as keyof typeof StyleNameMapping];
8686
accumulated.push(varName);
8787
});
88-
current.tokens.forEach(token => {
89-
const varName = this.tokenIDMap(token.tokenID);
88+
for (const token of current.properties.entries()) {
89+
const varName = CodeGen.tokenIDMap(token[1]);
9090
accumulated.push(varName);
91-
});
91+
}
9292
return accumulated;
9393
}, new Array<string>());
9494
const importBase = `import { StyleRules } from "@adaptive-web/adaptive-ui";\n`;
@@ -117,16 +117,16 @@ export class CodeGen {
117117
}
118118

119119
let propertiesOut = "";
120-
if (styleRule.tokens.size > 0) {
120+
if (styleRule.properties.size > 0) {
121121
// TODO Need to map tokens better
122-
const tokens = new Array(...styleRule.tokens).map(token => `${token.target}: ${this.tokenIDMap(token.tokenID)}`);
122+
const tokens = new Array(...styleRule.properties).map(token => `${token[0]}: ${CodeGen.tokenIDMap(token[1])}`);
123123
propertiesOut = ` properties: {\n ${tokens.join(",\n ")},\n },\n`;
124124
}
125125

126126
return ` {\n${targetOut}${stylesOut}${propertiesOut} },`;
127127
}
128128

129-
private tokenIDMap(tokenID: string): string {
129+
private static tokenIDMap(tokenID: string): string {
130130
let adjustedID = tokenID;
131131

132132
// TODO: Clean up naming and grouping

packages/adaptive-ui-designer-figma/src/lib/anatomy.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
SerializableBooleanCondition,
99
SerializableStringCondition,
1010
SerializableStyleRule,
11-
SerializableToken,
1211
} from "@adaptive-web/adaptive-ui";
1312
import { AdditionalDataKeys, type PluginUINodeData } from "@adaptive-web/adaptive-ui-designer-core";
1413

@@ -55,32 +54,23 @@ export class StringCondition extends Condition {
5554
}
5655
}
5756

58-
export class Token {
59-
constructor(
60-
public target: string,
61-
public tokenID: string,
62-
) { }
63-
64-
toJSON(): SerializableToken {
65-
return {
66-
target: this.target,
67-
tokenID: this.tokenID,
68-
};
69-
}
70-
}
71-
7257
export class StyleRule {
7358
contextCondition?: Record<string, string | boolean>;
7459
part?: string;
7560
styles: Set<string> = new Set();
76-
tokens: Set<Token> = new Set();
61+
properties: Map<string, string> = new Map();
7762

7863
toJSON(): SerializableStyleRule {
64+
const properties = this.properties.size === 0 ? undefined : Array.from(this.properties.entries()).reduce((prev, next) => {
65+
prev[next[0]] = next[1];
66+
return prev;
67+
}, {} as Record<string, string>);
68+
7969
return {
8070
contextCondition: this.contextCondition,
8171
part: this.part,
8272
styles: this.styles.size === 0 ? undefined : Array.from(this.styles),
83-
tokens: this.tokens.size === 0 ? undefined : Array.from(this.tokens).map(token => token.toJSON()),
73+
properties,
8474
};
8575
}
8676
}
@@ -96,14 +86,14 @@ export class Anatomy {
9686

9787
toJSON(): SerializableAnatomy {
9888
const conditions = Array.from(this.conditions.entries()).reduce((prev, next) => {
99-
prev[next[0]] = next[1].toJSON()
100-
return prev
101-
}, {} as SerializableAnatomy["conditions"])
89+
prev[next[0]] = next[1].toJSON();
90+
return prev;
91+
}, {} as SerializableAnatomy["conditions"]);
10292

10393
const parts = Array.from(this.parts.entries()).reduce((prev, current) => {
10494
prev[current[0]] = makeClassName(current[1]);
10595
return prev;
106-
}, {} as SerializableAnatomy["parts"])
96+
}, {} as SerializableAnatomy["parts"]);
10797

10898
return {
10999
name: this.name,
@@ -278,7 +268,7 @@ function walkNode(node: PluginUINodeData, componentName: string, condition: Reco
278268

279269
node.appliedDesignTokens.forEach((token, target) => {
280270
const tokenRef = token.tokenID;
281-
styleRule.tokens.add(new Token(target, tokenRef));
271+
styleRule.properties.set(target, tokenRef);
282272
});
283273

284274
if (isNotContextNode(nodeName, componentName)) {

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,17 +510,9 @@ export interface SerializableStyleRule {
510510
// (undocumented)
511511
part?: string;
512512
// (undocumented)
513-
styles?: string[];
513+
properties?: Record<string, string>;
514514
// (undocumented)
515-
tokens?: SerializableToken[];
516-
}
517-
518-
// @beta (undocumented)
519-
export interface SerializableToken {
520-
// (undocumented)
521-
target: string;
522-
// (undocumented)
523-
tokenID: string;
515+
styles?: string[];
524516
}
525517

526518
// @public

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import fsp from "fs/promises";
55
import { matcher } from "matcher"
66
import * as prettier from "prettier";
77
import { ComposableStyles, ElementStyles } from '@microsoft/fast-element';
8+
import { CSSDesignToken } from "@microsoft/fast-foundation";
89
import { Command } from 'commander';
910
import { glob } from "glob";
1011
import postcss, { type Processor} from "postcss";
@@ -28,7 +29,6 @@ import {
2829
StyleProperties,
2930
StyleRule,
3031
Styles,
31-
TypedCSSDesignToken
3232
} from "../core/index.js";
3333
import { disabledStyles, focusIndicatorStyles, focusResetStyles } from "../reference/index.js";
3434

@@ -253,10 +253,15 @@ function jsonToAUIStyleSheet(obj: SerializableAnatomy): AUIStyleSheet {
253253
return Styles.Shared.get(name)!;
254254
});
255255

256-
const properties = style.tokens?.reduce((prev, current) => {
257-
prev[current.target] = DesignTokenRegistry.Shared.get(current.tokenID) as TypedCSSDesignToken<any>
258-
return prev;
259-
}, {} as StyleProperties);
256+
const properties: StyleProperties = {};
257+
if (style.properties) {
258+
Object.entries(style.properties).map(entry => {
259+
const target = entry[0];
260+
const value = entry[1];
261+
const token = DesignTokenRegistry.Shared.get(value);
262+
properties[target] = token ? token as CSSDesignToken<any> : value;
263+
});
264+
}
260265

261266
const target: StyleModuleTarget = {
262267
context: obj.context,

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -442,22 +442,14 @@ export type SerializableStringCondition = Record<string, string>;
442442
*/
443443
export type SerializableCondition = SerializableBooleanCondition | SerializableStringCondition;
444444

445-
/**
446-
* @beta
447-
*/
448-
export interface SerializableToken {
449-
target: string,
450-
tokenID: string
451-
}
452-
453445
/**
454446
* @beta
455447
*/
456448
export interface SerializableStyleRule {
457449
contextCondition?: Record<string, string | boolean>;
458450
part?: string,
459451
styles?: string[],
460-
tokens?: SerializableToken[];
452+
properties?: Record<string, string>,
461453
}
462454

463455
/**

0 commit comments

Comments
 (0)