Skip to content

Commit 85f1e62

Browse files
authored
Designer: Added ability to mark a node inline for styling (#217)
1 parent 270e484 commit 85f1e62

7 files changed

Lines changed: 58 additions & 16 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": "Designer: Added ability to mark a node `inline` for styling",
4+
"packageName": "@adaptive-web/adaptive-ui-designer-core",
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": "Designer: Added ability to mark a node `inline` for styling",
4+
"packageName": "@adaptive-web/adaptive-ui-designer-figma",
5+
"email": "47367562+bheston@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

packages/adaptive-ui-designer-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { Controller, PluginUIState, STYLE_REMOVE } from "./controller.js";
22
export {
3+
Config,
34
PluginNodeData,
45
AppliedStyleModules,
56
AppliedStyleValues,

packages/adaptive-ui-designer-core/src/model.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ export const AdditionalDataKeys = {
4040

4141
export type AdditionalDataKeys = ValuesOf<typeof AdditionalDataKeys>;
4242

43+
/**
44+
* Configuration options for a node.
45+
*/
46+
export class Config {
47+
/**
48+
* Indicator to treat the node as flattened or inline with the containing hierarchy.
49+
* Usable on Component nodes which exist as a construction convenience and are not
50+
* actual implemented components.
51+
*/
52+
public inline?: boolean;
53+
}
54+
4355
/**
4456
* A design token value.
4557
*/
@@ -113,6 +125,11 @@ export class AdditionalData extends Map<string, string> {}
113125
* Defines the data stored by the plugin on a node instance.
114126
*/
115127
export interface PluginNodeData {
128+
/**
129+
* Configuration options for a node.
130+
*/
131+
config: Config;
132+
116133
/**
117134
* Design token values set directly to the node.
118135
*/
@@ -216,6 +233,7 @@ export const pluginNodesToUINodes = (
216233
componentAppliedDesignTokens: node.componentAppliedDesignTokens,
217234
effectiveAppliedStyleValues: new AppliedStyleValues(),
218235
children,
236+
config: node.config,
219237
designTokens: node.localDesignTokens as DesignTokenValues,
220238
appliedStyleModules: node.appliedStyleModules as AppliedStyleModules,
221239
appliedDesignTokens: node.appliedDesignTokens as AppliedDesignTokens,

packages/adaptive-ui-designer-core/src/node.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
AppliedDesignTokens,
88
AppliedStyleModules,
99
AppliedStyleValues,
10+
Config,
1011
DesignTokenValues,
1112
PluginNodeData,
1213
ReadonlyAppliedDesignTokens,
@@ -214,6 +215,11 @@ export abstract class PluginNode {
214215
*/
215216
public abstract get supports(): Array<StyleProperty>;
216217

218+
/**
219+
* Configuration options for a node.
220+
*/
221+
public config: Config;
222+
217223
protected deserializeLocalDesignTokens(): DesignTokenValues {
218224
const json = this.getPluginData("designTokens");
219225
// console.log(" deserializeLocalDesignTokens", this.debugInfo, json);

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -227,32 +227,29 @@ function parseComponent(node: PluginUINodeData): Anatomy {
227227
return anatomy;
228228
}
229229

230-
function cleanNodeName(nodeName: string): string {
231-
// Remove non-ascii characters
232-
return nodeName.replace(/[^\x20-\x7F]/g, "").trim();
233-
}
234-
235-
function isNotContextNode(nodeName: string, componentName: string): boolean {
236-
return nodeName.toLowerCase() !== componentName.toLowerCase()
230+
function isContextNode(node: PluginUINodeData, componentName: string): boolean {
231+
// Remove non-ascii characters (we tried a convention of decorating template node names)
232+
const nodeName = node.name.replace(/[^\x20-\x7F]/g, "").trim();
233+
return node.type === "COMPONENT" || nodeName.toLowerCase() === componentName.toLowerCase();
237234
}
238235

239236
function walkNode(node: PluginUINodeData, componentName: string, condition: Record<string, string | boolean> | undefined, anatomy: Anatomy): void {
240-
const nodeName = cleanNodeName(node.name);
241-
242-
if (nodeName === "Focus indicator") {
237+
if (node.name === "Focus indicator") {
243238
// Ignore for now
244239
return;
245240
}
246241

247-
if (node.type === "INSTANCE" && isNotContextNode(nodeName, componentName)) {
242+
const isContext = isContextNode(node, componentName);
243+
244+
if (node.type === "INSTANCE" && !(node.config.inline === true || isContext)) {
248245
// TODO: This is too simplified, but it addresses many nested component issues for now.
249246
return;
250247
}
251248

252249
if (!node.name.endsWith(ignoreLayerName)) {
253250
// TODO, not only frames, but what?
254-
if (node.type === "FRAME" && isNotContextNode(nodeName, componentName)) {
255-
anatomy.parts.add(nodeName);
251+
if (node.type === "FRAME" && !isContext) {
252+
anatomy.parts.add(node.name);
256253
}
257254

258255
if (node.appliedStyleModules.length > 0 || node.appliedDesignTokens.size > 0) {
@@ -271,9 +268,9 @@ function walkNode(node: PluginUINodeData, componentName: string, condition: Reco
271268
styleRule.properties.set(target, tokenRef);
272269
});
273270

274-
if (isNotContextNode(nodeName, componentName)) {
275-
anatomy.parts.add(nodeName)
276-
styleRule.part = nodeName;
271+
if (!isContext) {
272+
anatomy.parts.add(node.name)
273+
styleRule.part = node.name;
277274
}
278275

279276
anatomy.styleRules.add(styleRule);

packages/adaptive-ui-designer-figma/src/lib/node-parser.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
AppliedDesignTokens,
66
AppliedStyleModules,
77
AppliedStyleValues,
8+
Config,
89
deserializeMap,
910
DesignTokenValues,
1011
PluginNodeData,
@@ -38,8 +39,12 @@ export function parseNode(node: FigmaRestAPI.Node): PluginUINodeData {
3839
additionalData.set(AdditionalDataKeys.codeGenName, node.name);
3940
}
4041

42+
const configData = getPluginData(node, "config");
4143
const appliedTokensPluginData = getPluginData(node, "appliedDesignTokens");
4244
const appliedStylesPluginData = getPluginData(node, "appliedStyleModules");
45+
const config: Config = configData
46+
? JSON.parse(configData)
47+
: new Config();
4348
const appliedDesignTokens: AppliedDesignTokens = appliedTokensPluginData
4449
? deserializeMap(appliedTokensPluginData)
4550
: new AppliedDesignTokens();
@@ -53,6 +58,7 @@ export function parseNode(node: FigmaRestAPI.Node): PluginUINodeData {
5358
type: node.type,
5459
supports: [],
5560
children: children.map(parseNode),
61+
config,
5662
additionalData,
5763
appliedDesignTokens,
5864
appliedStyleModules,

0 commit comments

Comments
 (0)