@nodii/dev 0.6.149 → 0.6.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -1
- package/dist/cli.js +1 -1
- package/dist/core.js +1 -1
- package/dist/flags.js +1 -1
- package/dist/review.js +59 -2
- package/dist/surface.js +153 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -938,7 +938,7 @@ run the same command again.
|
|
|
938
938
|
### Product pages from Surfaces: `surface generate` (MW8-17)
|
|
939
939
|
|
|
940
940
|
```sh
|
|
941
|
-
nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
941
|
+
nodii-dev surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
942
942
|
nodii-dev surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
943
943
|
```
|
|
944
944
|
|
|
@@ -959,6 +959,11 @@ product-page catalog names the Surface by its published component-set key
|
|
|
959
959
|
version unlabelled. A file with no published rows, or with no version the
|
|
960
960
|
publish closed among its newest 40, is refused with
|
|
961
961
|
`SURFACE_FILE_NOT_PUBLISHED`. `--figma-version V` names a version outright.
|
|
962
|
+
A Surface new to its file is not in the published listing yet
|
|
963
|
+
(`SURFACE_NOT_PUBLISHED`); `--node ID` (only with `--fetch --figma-version V`
|
|
964
|
+
and one named key) locates its set at V, and the read is refused with
|
|
965
|
+
`SURFACE_NODE_KEY_MISMATCH` unless that set's key is the catalog row's. The
|
|
966
|
+
key stays the reference and the node id is not stored (cli-144).
|
|
962
967
|
Without `--fetch`, the committed tree under
|
|
963
968
|
`docs/figma-ux-ds/figma/surface-trees/<fileKey>/<componentSetKey>.json` is
|
|
964
969
|
read and Figma is not called.
|
package/dist/cli.js
CHANGED
|
@@ -185,7 +185,7 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
185
185
|
# values not bound to a variable and non-DS instances; submit reports the
|
|
186
186
|
# same on any Surface node a set touches (refuses where the host enforces).
|
|
187
187
|
# Reads Figma on Dev's token; exit 1 = SURFACES_CHECK_FAILED
|
|
188
|
-
surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
188
|
+
surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
189
189
|
surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]
|
|
190
190
|
# a Surface -> its product page's presentational code, from Code Connect
|
|
191
191
|
# (MW8-17), in a design-system checkout. --fetch reads Figma (FIGMA_PAT, one
|
package/dist/core.js
CHANGED
|
@@ -4,7 +4,7 @@ import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
4
4
|
import { homedir, platform } from "node:os";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
6
|
|
|
7
|
-
export const VERSION = "0.6.
|
|
7
|
+
export const VERSION = "0.6.151";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/flags.js
CHANGED
|
@@ -77,7 +77,7 @@ export const COMMAND_FLAGS = {
|
|
|
77
77
|
"figma apply": ["file", "figma-version", "lane-reads"],
|
|
78
78
|
"figma lock": ["title", "scope", "lane-reads"],
|
|
79
79
|
"figma scope": ["scope", "lane-reads"],
|
|
80
|
-
"surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "report", "post-scoreboard", "resume"],
|
|
80
|
+
"surface generate": ["write", "check", "fetch", "all", "module", "type", "figma-version", "node", "report", "post-scoreboard", "resume"],
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
/** Refuse a flag the command does not declare (USAGE, exit 2), naming the valid ones. */
|
package/dist/review.js
CHANGED
|
@@ -12,6 +12,7 @@ import { promisify } from "node:util";
|
|
|
12
12
|
import { CliError, encode } from "./core.js";
|
|
13
13
|
import { pickerPrompt } from "./gather.js";
|
|
14
14
|
import { componentSetsIn, designCatalogSets } from "./figma-scope.js";
|
|
15
|
+
import { holdsSet, scopeText } from "./figma.js";
|
|
15
16
|
import { gitPrivatePath } from "./safety.js";
|
|
16
17
|
import { GENERATED_PAGE_GLOB, GENERATED_SUFFIX, hasGeneratedPageStamp } from "./surface.js";
|
|
17
18
|
import { VALUE_FLAGS } from "./impact.js";
|
|
@@ -639,6 +640,52 @@ export async function laneChangeSetNodes(request, agentId, fileKeys, templates =
|
|
|
639
640
|
return scoped;
|
|
640
641
|
}
|
|
641
642
|
|
|
643
|
+
/**
|
|
644
|
+
* NODII-DEV-CLI-141 (MW1-57.6): a Surfaces file whose Freeze boundary names no
|
|
645
|
+
* component set is checked on the lock scopes the lane's agent holds there
|
|
646
|
+
* (Dev's lock check), never silently as the whole shared file. Each page,
|
|
647
|
+
* section or component scope is a frame; a create scope has no node of its
|
|
648
|
+
* own, so the set's live items are. Findings in the scope still block: nothing
|
|
649
|
+
* here is file debt, and the whole file is not read. A whole-file lock, or no
|
|
650
|
+
* held set, leaves the file whole, and wholeFile says why.
|
|
651
|
+
* Returns { scoped: { fileKey: { changeSets, nodes, items, templates, lockScopes, fileDebt: false } }, wholeFile: [{ fileKey, reason }] }.
|
|
652
|
+
*/
|
|
653
|
+
export async function laneSurfaceScopes(request, agentId, boundary, templates = []) {
|
|
654
|
+
const candidates = [...new Set(boundary.filter((file) => !file.componentSetKeys?.length).map((file) => file.fileKey))];
|
|
655
|
+
const result = { scoped: {}, wholeFile: [] };
|
|
656
|
+
if (!candidates.length) return result;
|
|
657
|
+
const files = (await request("GET", "/api/v1/design/files")).data ?? [];
|
|
658
|
+
const surfaces = new Set(files.filter((file) => file.kind === "surfaces").map((file) => file.fileKey));
|
|
659
|
+
for (const fileKey of candidates.filter((key) => surfaces.has(key))) {
|
|
660
|
+
const check = agentId ? (await request("GET", `/api/v1/design/files/${encode(fileKey)}/lock/check?agentId=${encode(agentId)}`)).data : null;
|
|
661
|
+
if (!holdsSet(check)) {
|
|
662
|
+
result.wholeFile.push({ fileKey, reason: `the lane's agent holds no change set in ${fileKey}, so it has no scope to check and the whole file is checked (CLI-141)` });
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
const scopes = (check.scopes ?? []).filter((s) => !s.releasedAt && (!s.changeSetId || s.changeSetId === check.changeSetId));
|
|
666
|
+
if (!scopes.length || scopes.some((s) => s.kind === "file")) {
|
|
667
|
+
result.wholeFile.push({ fileKey, reason: `${check.changeSetId} holds the whole file, so the whole file is checked (CLI-141)` });
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
const nodes = new Set();
|
|
671
|
+
const items = [];
|
|
672
|
+
const add = (nodeId, extra) => { if (!nodes.has(nodeId)) items.push({ nodeId, ...extra }); nodes.add(nodeId); };
|
|
673
|
+
for (const s of scopes) if (s.nodeId && ["page", "section", "component"].includes(s.kind)) add(s.nodeId, { changeSet: check.changeSetId });
|
|
674
|
+
if (scopes.some((s) => !s.nodeId)) {
|
|
675
|
+
const set = (await request("GET", `/api/v1/design/change-sets/${encode(check.changeSetId)}`)).data;
|
|
676
|
+
for (const item of set?.items ?? []) if (item.decision !== "withdrawn" && item.change !== "removed" && item.figmaNodeId) add(item.figmaNodeId, { changeSet: check.changeSetId });
|
|
677
|
+
}
|
|
678
|
+
const touched = templates.filter((unit) => unit.fileKey === fileKey);
|
|
679
|
+
for (const unit of touched) add(unit.nodeId, { template: unit.template });
|
|
680
|
+
result.scoped[fileKey] = {
|
|
681
|
+
changeSets: [check.changeSetId], nodes: [...nodes], items,
|
|
682
|
+
templates: [...new Set(touched.map((unit) => unit.template))],
|
|
683
|
+
lockScopes: [...new Set(scopes.map(scopeText))], fileDebt: false,
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
return result;
|
|
687
|
+
}
|
|
688
|
+
|
|
642
689
|
/** A Figma link's file key and node id (`1-2` in a link, `1:2` in the API), or null. */
|
|
643
690
|
export function figmaLinkNode(url) {
|
|
644
691
|
let parsed;
|
|
@@ -747,7 +794,7 @@ export async function swapFor(swaps, { fileKey, nodeId }, readSet) {
|
|
|
747
794
|
* Without a Swap in Dev whose change set holds the node (swapFor), or when
|
|
748
795
|
* Dev's Swaps or change sets can't be read, the missing node stays a finding.
|
|
749
796
|
*/
|
|
750
|
-
export async function figmaFindings(figma, { catalog, check, changeSets = {}, swaps, readSet, lookupSet }) {
|
|
797
|
+
export async function figmaFindings(figma, { catalog, check, changeSets = {}, swaps, readSet, lookupSet, wholeFile = [] }) {
|
|
751
798
|
const scopedFrames = Object.entries(changeSets).flatMap(([fileKey, scoped]) => scoped.nodes.map((nodeId) => {
|
|
752
799
|
const item = scoped.items?.find((x) => x.nodeId === nodeId);
|
|
753
800
|
return { fileKey, nodeId, state: "default", ...(item ? { changeSet: item.changeSet } : {}) };
|
|
@@ -802,6 +849,8 @@ export async function figmaFindings(figma, { catalog, check, changeSets = {}, sw
|
|
|
802
849
|
// verdict as it is (a whole-file DS check is never required, MW2-38.3).
|
|
803
850
|
const fileDebt = [];
|
|
804
851
|
for (const [fileKey, scoped] of Object.entries(changeSets)) {
|
|
852
|
+
// CLI-141: a Surfaces file scoped by its lock is never read whole.
|
|
853
|
+
if (scoped.fileDebt === false) continue;
|
|
805
854
|
const units = new Set(scoped.nodes);
|
|
806
855
|
let data;
|
|
807
856
|
try { data = (await check(fileKey, {})).payload.data; }
|
|
@@ -835,6 +884,8 @@ export async function figmaFindings(figma, { catalog, check, changeSets = {}, sw
|
|
|
835
884
|
...(scopedFiles.some(([, scoped]) => scoped.changeSets.length) ? { changeSets: scopedFiles.filter(([, scoped]) => scoped.changeSets.length).map(([fileKey, scoped]) => ({ fileKey, ids: scoped.changeSets, nodes: (scoped.items ?? []).filter((x) => x.changeSet).length || scoped.nodes.length })) } : {}),
|
|
836
885
|
...(scopedFiles.some(([, scoped]) => scoped.templates?.length) ? { templates: scopedFiles.filter(([, scoped]) => scoped.templates?.length).map(([fileKey, scoped]) => ({ fileKey, paths: scoped.templates, nodes: (scoped.items ?? []).filter((x) => x.template).map((x) => x.nodeId) })) } : {}),
|
|
837
886
|
...(fileDebt.length ? { fileDebt } : {}),
|
|
887
|
+
...(scopedFiles.some(([, scoped]) => scoped.lockScopes?.length) ? { lockScopes: scopedFiles.filter(([, scoped]) => scoped.lockScopes?.length).map(([fileKey, scoped]) => ({ fileKey, changeSet: scoped.changeSets[0], scopes: scoped.lockScopes })) } : {}),
|
|
888
|
+
...(wholeFile.length ? { wholeFile } : {}),
|
|
838
889
|
},
|
|
839
890
|
};
|
|
840
891
|
}
|
|
@@ -1006,8 +1057,14 @@ export async function runLaneCheck(ref, flags, { request, lane, freeze, current,
|
|
|
1006
1057
|
catch (error) {
|
|
1007
1058
|
throw new ReviewerError(UNAVAILABLE, `the lane's change sets could not be read from Dev (${error?.code ?? "ERROR"}: ${error?.message ?? error}), so the Figma check cannot be scoped to their nodes (MW2-38.3) and did not fall back to the whole file`);
|
|
1008
1059
|
}
|
|
1060
|
+
let surfaceScopes;
|
|
1061
|
+
try { surfaceScopes = await laneSurfaceScopes(request, lane.agentId, boundary.filter((file) => !changeSets[file.fileKey]), touched); }
|
|
1062
|
+
catch (error) {
|
|
1063
|
+
throw new ReviewerError(UNAVAILABLE, `the lane's Figma lock scopes could not be read from Dev (${error?.code ?? "ERROR"}: ${error?.message ?? error}), so the Figma check cannot be scoped to them (CLI-141) and did not fall back to the whole file`);
|
|
1064
|
+
}
|
|
1065
|
+
changeSets = { ...changeSets, ...surfaceScopes.scoped };
|
|
1009
1066
|
let checked;
|
|
1010
|
-
try { checked = await figmaFindings(boundary, { catalog, check: designCheck, changeSets, swaps: () => removalSwaps(request), readSet: async (id) => (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(id)}`)).data }); }
|
|
1067
|
+
try { checked = await figmaFindings(boundary, { catalog, check: designCheck, changeSets, wholeFile: surfaceScopes.wholeFile, swaps: () => removalSwaps(request), readSet: async (id) => (await request("GET", `/api/v1/design/change-sets/${encodeURIComponent(id)}`)).data }); }
|
|
1011
1068
|
catch (error) {
|
|
1012
1069
|
if (error instanceof ReviewerError) throw error;
|
|
1013
1070
|
// A Figma outage (a read past its clock, no answer, rate limited) means
|
package/dist/surface.js
CHANGED
|
@@ -32,7 +32,7 @@ import { CliError, VERSION, devRequest, readConfig } from "./core.js";
|
|
|
32
32
|
import { createRenderer } from "./vendor/render-templates.mjs";
|
|
33
33
|
|
|
34
34
|
/** Bumped whenever the emitted code changes shape for the same inputs. */
|
|
35
|
-
export const GENERATOR_FORMAT =
|
|
35
|
+
export const GENERATOR_FORMAT = 18;
|
|
36
36
|
export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
|
|
37
37
|
export const GENERATED_SUFFIX = ".surface.generated.tsx";
|
|
38
38
|
/** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
|
|
@@ -51,9 +51,11 @@ const FIGMA_API = "https://api.figma.com/v1";
|
|
|
51
51
|
export const MIN_FIGMA_INTERVAL_MS = 8_000;
|
|
52
52
|
const BACKOFF_MS = 30_000;
|
|
53
53
|
const SET_KEY = /^[0-9a-f]{40}$/;
|
|
54
|
+
/** A set's node id, as the REST API (5:0) or a Figma URL (5-0) writes it. */
|
|
55
|
+
const NODE_ID = /^(\d+)[:-](\d+)$/;
|
|
54
56
|
|
|
55
57
|
export const SURFACE_USAGE =
|
|
56
|
-
"surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]\n" +
|
|
58
|
+
"surface generate <componentSetKey|route> [--write] [--check] [--fetch] [--figma-version V [--node ID]] [--report FILE] [--post-scoreboard ISSUE] [--resume]\n" +
|
|
57
59
|
"surface generate --all [--module M] [--type page|dialog] [--write] [--check] [--fetch] [--figma-version V] [--report FILE] [--post-scoreboard ISSUE] [--resume]";
|
|
58
60
|
|
|
59
61
|
// ---------------------------------------------------------------------------
|
|
@@ -260,13 +262,21 @@ export async function lastPublishedVersion(figmaGet, fileKey, { library } = {})
|
|
|
260
262
|
throw new CliError("SURFACE_FILE_NOT_PUBLISHED", `${fileKey}: none of its newest ${MAX_VERSION_READS} versions closed at or before its last library publish (${publishedAt}); name a version with --figma-version`, 1);
|
|
261
263
|
}
|
|
262
264
|
|
|
263
|
-
/**
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Read one Surface set at a file version and trim it to what the generator reads.
|
|
267
|
+
* `node` locates a set new to its file, not yet in its published listing (cli-144):
|
|
268
|
+
* the read is refused unless that node's set has the catalog row's key, which stays
|
|
269
|
+
* the reference (MW8-20); the node id is not kept.
|
|
270
|
+
*/
|
|
271
|
+
export async function fetchSurfaceTree(figmaGet, row, { index, version, node }) {
|
|
272
|
+
const nodeId = node ?? index.get(row.componentSetKey);
|
|
266
273
|
if (!nodeId) throw new CliError("SURFACE_NOT_PUBLISHED", `${row.componentSetName ?? row.id}: component set ${row.componentSetKey} is not among ${row.fileKey}'s published component sets`, 1);
|
|
267
274
|
const body = await figmaGet(`/files/${encodeURIComponent(row.fileKey)}/nodes?ids=${encodeURIComponent(nodeId)}${version ? `&version=${encodeURIComponent(version)}` : ""}`);
|
|
268
275
|
const entry = body.nodes?.[nodeId];
|
|
269
276
|
if (!entry?.document) throw new CliError("FIGMA_NOT_FOUND", `Figma returned no document for ${row.componentSetName ?? row.id}`, 1);
|
|
277
|
+
const found = node ? (entry.document.type === "COMPONENT_SET" ? (entry.componentSets?.[nodeId]?.key ?? null) : null) : row.componentSetKey;
|
|
278
|
+
if (found !== row.componentSetKey)
|
|
279
|
+
throw new CliError("SURFACE_NODE_KEY_MISMATCH", `${row.componentSetName ?? row.id}: node ${nodeId} at version ${version} is ${found ? `component set ${found}` : "not a component set"}, not the catalog's ${row.componentSetKey}; --node only locates the catalog row's own set (cli-144, MW8-20)`, 1);
|
|
270
280
|
return trimTree(entry, { row, version: version ?? body.version ?? null });
|
|
271
281
|
}
|
|
272
282
|
|
|
@@ -830,6 +840,18 @@ function mark(ctx, scope, name, layer = ctx.layer) {
|
|
|
830
840
|
return `__s${scopeIndex(ctx.scopes, scopeKey(scope, layer))}_${name}`;
|
|
831
841
|
}
|
|
832
842
|
|
|
843
|
+
/**
|
|
844
|
+
* A prop the generator lifts that its DS component leaves optional, so the page
|
|
845
|
+
* may pass nothing: a tab's count (none drawn), a KPI's tone (neutral, or no
|
|
846
|
+
* dot) (hub-477). Marked as `mark` does, and counted optional unless a template
|
|
847
|
+
* that draws the same prop requires it.
|
|
848
|
+
*/
|
|
849
|
+
function optionalMark(ctx, scope, name, layer = ctx.layer) {
|
|
850
|
+
const token = mark(ctx, scope, name, layer);
|
|
851
|
+
ctx.optionals?.optional.add(token);
|
|
852
|
+
return token;
|
|
853
|
+
}
|
|
854
|
+
|
|
833
855
|
/**
|
|
834
856
|
* Where a node sits in its view, the same in every view that draws it: its
|
|
835
857
|
* layer names from the view's page down, a name its parent holds twice
|
|
@@ -996,7 +1018,8 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
996
1018
|
let next = attrs;
|
|
997
1019
|
for (const attr of METRIC_VALUES) {
|
|
998
1020
|
const value = new RegExp(String.raw`\b${attr}=${LITERAL}`).exec(next);
|
|
999
|
-
|
|
1021
|
+
// A tone the page leaves out is the component's own default (neutral, or no dot; hub-477).
|
|
1022
|
+
if (value) next = next.replace(value[0], `${attr}={${TONE_ATTR.has(attr) ? (lifted.push(attr), optionalMark(ctx, at, attr)) : lift(at, attr)}}`);
|
|
1000
1023
|
}
|
|
1001
1024
|
if (tag !== "MetricFilterCard") return next;
|
|
1002
1025
|
const selected = `selected={${lift(at, "selected")}}`;
|
|
@@ -1259,11 +1282,7 @@ function handlerLabel(tag, attrs, after, node) {
|
|
|
1259
1282
|
const UNNAMED_FRAME = /^(?:frame|group|auto ?layout|rectangle|container|slot)(?: \d+)?$/i;
|
|
1260
1283
|
function handlerScope(node, ctx, path, inner, label, at) {
|
|
1261
1284
|
const chain = ctx.chain ?? [];
|
|
1262
|
-
const
|
|
1263
|
-
// A frame named as the Surfaces name a place ("Row · Email domain allowlist") is that place.
|
|
1264
|
-
const place = frames.map((c) => /\s·\s*(.*[A-Za-z].*)$/.exec(c.name)?.[1]).find(Boolean);
|
|
1265
|
-
const named = frames.find((c) => !UNNAMED_FRAME.test(c.name.trim()))?.name;
|
|
1266
|
-
const scope = inner ?? camelName(place ?? sectionHeading(node, chain) ?? titleBefore(node, chain) ?? named ?? "page");
|
|
1285
|
+
const scope = inner ?? placeOf(node, ctx);
|
|
1267
1286
|
const name = `on${cap(label)}Click`;
|
|
1268
1287
|
if (!ctx.handlers || !ctx.scopes) return { scope, name };
|
|
1269
1288
|
const key = `${scope}|${name}`;
|
|
@@ -1274,6 +1293,22 @@ function handlerScope(node, ctx, path, inner, label, at) {
|
|
|
1274
1293
|
return { scope, name: n ? `on${cap(label)}${n + 1}Click` : name };
|
|
1275
1294
|
}
|
|
1276
1295
|
|
|
1296
|
+
/**
|
|
1297
|
+
* Where a part sits, as a name: the place its frame is named for ("Row · Email
|
|
1298
|
+
* domain allowlist"), else the heading of its section, else the title of the
|
|
1299
|
+
* part before it (a step's Section), else its nearest named frame (a Toolbar),
|
|
1300
|
+
* else the page. A button's handler and an unlabelled control are named by it.
|
|
1301
|
+
*/
|
|
1302
|
+
function placeOf(node, ctx, { figures = true } = {}) {
|
|
1303
|
+
const chain = ctx.chain ?? [];
|
|
1304
|
+
const frames = [...chain.slice(1)].reverse().filter((c) => c.type !== "SLOT" && !c.instance && /[A-Za-z]/.test(c.name ?? ""));
|
|
1305
|
+
const place = frames.map((c) => /\s·\s*(.*[A-Za-z].*)$/.exec(c.name)?.[1]).find(Boolean);
|
|
1306
|
+
const named = frames.find((c) => !UNNAMED_FRAME.test(c.name.trim()))?.name;
|
|
1307
|
+
const text = place ?? sectionHeading(node, chain) ?? titleBefore(node, chain) ?? named ?? "page";
|
|
1308
|
+
// A control's place leaves out a count Figma drew ("Replies 7" → replies; hub-481).
|
|
1309
|
+
return figures ? camelName(text) : nameOf(text, text);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1277
1312
|
/**
|
|
1278
1313
|
* The title of the nearest DS part before `target` that has one (a step's
|
|
1279
1314
|
* Section, in its "Card · Claim" frame), looking up its frames.
|
|
@@ -1356,8 +1391,67 @@ function textNextTo(node, ctx) {
|
|
|
1356
1391
|
/** The form controls the page owns: a value it passes and a change it hears (NODII-DEV-CLI-82, -83). */
|
|
1357
1392
|
const FIELD_CONTROLS = { Input: "onChange", Textarea: "onChange", SelectField: "onValueChange", RadioGroup: "onValueChange" };
|
|
1358
1393
|
|
|
1359
|
-
/**
|
|
1360
|
-
|
|
1394
|
+
/**
|
|
1395
|
+
* The form controls whose template wires them with its own generic names
|
|
1396
|
+
* (`onChange={onChange}`, `onValueChange={setView}`, `onChange={setAmountMinor}`):
|
|
1397
|
+
* the change each hears, the attribute its value takes, the word its value is
|
|
1398
|
+
* named by (a field's `value`; a view switch's `view`, a page size's `pageSize`,
|
|
1399
|
+
* an amount's `amountMinor`), whether a change is named with that word too
|
|
1400
|
+
* (`onPayPeriodPageSizeChange`), and whether the field names it (else its
|
|
1401
|
+
* place: a view switch and a page size sit by the list they change) (hub-481).
|
|
1402
|
+
*/
|
|
1403
|
+
const fieldControl = (change, value = "value", word = "value") => ({ change, value, word, byField: true, withWord: false });
|
|
1404
|
+
const placedControl = (word) => ({ change: "onValueChange", value: "value", word, byField: false, withWord: true });
|
|
1405
|
+
const NAMED_CHANGE = {
|
|
1406
|
+
...Object.fromEntries(Object.entries(FIELD_CONTROLS).map(([tag, change]) => [tag, fieldControl(change)])),
|
|
1407
|
+
MultiSelect: fieldControl("onValueChange"),
|
|
1408
|
+
DateTimePicker: fieldControl("onChange"),
|
|
1409
|
+
DatePicker: fieldControl("onValueChange"),
|
|
1410
|
+
DateRangePicker: fieldControl("onChange"),
|
|
1411
|
+
TimePicker: fieldControl("onValueChange"),
|
|
1412
|
+
CurrencyInput: fieldControl("onChange", "valueMinor", "amountMinor"),
|
|
1413
|
+
SegmentedControl: placedControl("view"),
|
|
1414
|
+
PageSizeSelect: placedControl("pageSize"),
|
|
1415
|
+
};
|
|
1416
|
+
/** The controls the page names from the field the Input family's own scope (fieldScope) already reads. */
|
|
1417
|
+
const INPUT_FAMILY = /^(?:Input|Textarea|SelectField)$/;
|
|
1418
|
+
/** A template's own value identifier, and its own setter or bare handler. */
|
|
1419
|
+
const GENERIC_VALUE = String.raw`\{(?:value|date|range|time|view|pageSize|amountMinor)\}`;
|
|
1420
|
+
const GENERIC_CHANGE = String.raw`\{(?:onChange|onValueChange|set[A-Z][A-Za-z0-9]*)\}`;
|
|
1421
|
+
/** Figma's sample value a template writes as a literal: text, a number, an object, a Date. */
|
|
1422
|
+
const SAMPLE_LITERAL = String.raw`"(?:[^"\\\n]|\\.)*"|\{-?\d+(?:\.\d+)?\}|\{Number\("(?:[^"\\\n]|\\.)*"\)\}|\{\{[^{}]*\}\}|\{new Date\([^()]*\)\}`;
|
|
1423
|
+
/** A name made of a date or time format ("dd/mm/yyyy" → ddMmYyyy): a placeholder, never a field. */
|
|
1424
|
+
const FORMAT_NAME = /^(?:dd|mm|yyyy|yy|hh|ss)(?:Dd|Mm|Yyyy|Yy|Hh|Ss)*$/;
|
|
1425
|
+
/** A name that starts with a verb a show flag, a setter or a handler is named by (hub-478). */
|
|
1426
|
+
const VERB_NAME = /^(?:show|set|on)(?:[A-Z]|$)/;
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* The label a control is drawn with: its own label or title when its template
|
|
1430
|
+
* draws it and it is not a format, else the text just before it in its frame,
|
|
1431
|
+
* else the text just before its frame (a picker in its own sizing frame, under
|
|
1432
|
+
* "Effective from *"). Null when it has none.
|
|
1433
|
+
*/
|
|
1434
|
+
function controlLabel(node, ctx, code) {
|
|
1435
|
+
const props = node.instance?.props ?? {};
|
|
1436
|
+
const own = [props.label, props.title].find((v) => typeof v === "string" && code.includes(JSON.stringify(v)) && nameText(v));
|
|
1437
|
+
if (own && !FORMAT_NAME.test(nameOf(own))) return nameOf(own);
|
|
1438
|
+
const words = (n) => {
|
|
1439
|
+
if (!n || n.visible === false || n.instance) return null;
|
|
1440
|
+
if (n.type === "TEXT") return nameText(n.text) && !RECORD_TEXT(n.text) ? n.text : null;
|
|
1441
|
+
for (const c of n.children ?? []) {
|
|
1442
|
+
const found = words(c);
|
|
1443
|
+
if (found) return found;
|
|
1444
|
+
}
|
|
1445
|
+
return null;
|
|
1446
|
+
};
|
|
1447
|
+
const before = (parent, target) => {
|
|
1448
|
+
const shown = (parent?.children ?? []).filter((c) => c.visible !== false);
|
|
1449
|
+
const at = shown.indexOf(target);
|
|
1450
|
+
return at > 0 ? words(shown[at - 1]) : null;
|
|
1451
|
+
};
|
|
1452
|
+
const text = before(ctx.parent, node) ?? (ctx.grand ? before(ctx.grand, ctx.parent) : null);
|
|
1453
|
+
return text ? nameOf(text) : null;
|
|
1454
|
+
}
|
|
1361
1455
|
|
|
1362
1456
|
/**
|
|
1363
1457
|
* A control the template half-controls (`defaultValue="chart"` beside
|
|
@@ -1419,14 +1513,32 @@ function fieldScope(node, ctx, code) {
|
|
|
1419
1513
|
* apart by their place (resolveScopes) (hub-481).
|
|
1420
1514
|
*/
|
|
1421
1515
|
function liftFieldControls(code, node, ctx, lift, scope) {
|
|
1516
|
+
const top = /^<([A-Za-z]+)/.exec(code.replace(/^<Field\b[^>]*>\s*/, ""))?.[1];
|
|
1422
1517
|
code = rewriteTags(code, Object.keys(NAMED_CHANGE).join("|"), (attrs, tag) => {
|
|
1423
|
-
const handler = NAMED_CHANGE[tag];
|
|
1424
|
-
const change = new RegExp(String.raw`(^|\s)${handler}
|
|
1518
|
+
const { change: handler, value: valueAttr, word, byField, withWord } = NAMED_CHANGE[tag];
|
|
1519
|
+
const change = new RegExp(String.raw`(^|\s)${handler}=${GENERIC_CHANGE}`).exec(attrs);
|
|
1425
1520
|
if (!change) return attrs;
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1521
|
+
// The Input family keeps the scope fieldScope gave it. A control another part's template draws
|
|
1522
|
+
// (a pager's page size) is that part's, as its button is (nameHandlers). Any other control is
|
|
1523
|
+
// named by its label, else (a field) the scope it was given unless that is a format or only
|
|
1524
|
+
// its set's name, else where it sits.
|
|
1525
|
+
// A label that reads as a verb ("Show") would name a show flag or a setter (resolveScopes), never a field.
|
|
1526
|
+
const beside = INPUT_FAMILY.test(tag) || tag !== top ? null : controlLabel(node, ctx, code);
|
|
1527
|
+
const label = INPUT_FAMILY.test(tag) || tag !== top ? scope : beside && !VERB_NAME.test(beside) ? beside : null;
|
|
1528
|
+
const unnamed = FORMAT_NAME.test(scope) || scope === camelName(node.instance?.set ?? "");
|
|
1529
|
+
const place = () => placeOf(node, ctx, { figures: false });
|
|
1530
|
+
const at = label ?? (byField && !unnamed ? scope : place());
|
|
1531
|
+
const valueName = word === "value" ? `${at}Value` : joinName(at, word);
|
|
1532
|
+
const changeName = `on${cap(withWord ? joinName(at, word) : at)}Change`;
|
|
1533
|
+
const value = `${valueAttr}={${lift(at, valueName)}}`;
|
|
1534
|
+
let next = attrs.replace(change[0], `${change[1]}${handler}={${lift(at, changeName)}}`);
|
|
1535
|
+
const sample = INPUT_FAMILY.test(tag) ? "" : `|${SAMPLE_LITERAL}`;
|
|
1536
|
+
const drawn = new RegExp(String.raw`(^|\s)(?:${valueAttr}=(?:${GENERIC_VALUE}${sample})|defaultValue=${LITERAL})`).exec(next);
|
|
1537
|
+
if (drawn) return next.replace(drawn[0], `${drawn[1]}${value}`);
|
|
1538
|
+
if (new RegExp(String.raw`(^|\s)${valueAttr}=`).test(next)) return next;
|
|
1539
|
+
// A control drawn empty (a Time Picker with no time) takes the page's value too.
|
|
1540
|
+
const sep = next.includes("\n") ? `\n${new RegExp(String.raw`\n(\s*)${handler}=`).exec(next)?.[1] ?? " "}` : " ";
|
|
1541
|
+
return next.replace(new RegExp(String.raw`(^|\s)${handler}=`), (m, sp) => `${sp}${value}${sep}${handler}=`);
|
|
1430
1542
|
});
|
|
1431
1543
|
// A field's placeholder is the page's too: in a Surface it is the value the frame shows
|
|
1432
1544
|
// ("Last 30 days", "K*** M***", "Sep 2026"), and a search box's copy names the list
|
|
@@ -1453,6 +1565,7 @@ function liftFieldControls(code, node, ctx, lift, scope) {
|
|
|
1453
1565
|
/** A metric card's values that are Figma's sample, never copy (NODII-DEV-CLI-84). */
|
|
1454
1566
|
// statusTone and tone are the KPI's state ("Unresolved" warning or danger), never the sample's dot (hub-477).
|
|
1455
1567
|
const METRIC_VALUES = ["value", "caption", "changeAmount", "period", "statusTone", "tone"];
|
|
1568
|
+
const TONE_ATTR = new Set(["statusTone", "tone"]);
|
|
1456
1569
|
|
|
1457
1570
|
/**
|
|
1458
1571
|
* Each opening tag of `names` (a regex alternation) in `code`, its attributes
|
|
@@ -1520,7 +1633,7 @@ function resolveScopes(views, scopes, layers = new Map()) {
|
|
|
1520
1633
|
// A setter, a handler and a show flag keep their verb first (`onSaveClick`, `showSsoAdd`, hub-478).
|
|
1521
1634
|
const scoped = (scope, name) => {
|
|
1522
1635
|
const m = /^(set|on|show)([A-Z]\w*)$/.exec(name);
|
|
1523
|
-
return m ? `${m[1]}${cap(scope)}${m[2]}` :
|
|
1636
|
+
return m ? `${m[1]}${cap(scope)}${m[2]}` : toneName(scope, name) ?? joinName(scope, name);
|
|
1524
1637
|
};
|
|
1525
1638
|
// A prefix that tells two layers apart, a word it shares with the name said once.
|
|
1526
1639
|
const prefixed = (prefix, name) => {
|
|
@@ -1568,6 +1681,15 @@ function resolveScopes(views, scopes, layers = new Map()) {
|
|
|
1568
1681
|
}
|
|
1569
1682
|
|
|
1570
1683
|
/** `scope` then `name` in camelCase, a word they share at the join said once (`recordSwitcherScope` + `ScopeValue`). */
|
|
1684
|
+
/**
|
|
1685
|
+
* A KPI tone named by a stat whose label ends in its own status or state
|
|
1686
|
+
* ("Status", "Policy status", "Review state") says it once: `statusTone`,
|
|
1687
|
+
* `policyStatusTone`, `reviewStateTone`, never `reviewStateStatusTone` (hub-477).
|
|
1688
|
+
*/
|
|
1689
|
+
function toneName(scope, name) {
|
|
1690
|
+
return name === "statusTone" && /^(?:status|state)$|[a-z0-9](?:Status|State)$/.test(scope) ? `${scope}Tone` : null;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1571
1693
|
function joinName(scope, name) {
|
|
1572
1694
|
const head = name[0].toUpperCase() + name.slice(1);
|
|
1573
1695
|
const last = /[A-Z][a-z0-9]*$|^[a-z][a-z0-9]*$/.exec(scope)?.[0] ?? "";
|
|
@@ -2289,7 +2411,7 @@ function tabStrip(run, ctx) {
|
|
|
2289
2411
|
if (counted[i]) trigger = trigger.replace(counted[i], `{${mark(ctx, strip, joinName(camelName(values[i]), "tabLabel"), null)}}`);
|
|
2290
2412
|
// A tab's count badge counts the viewer's action items: the page's, named by its tab, never
|
|
2291
2413
|
// Figma's sample (`actionableCount={5}`) or one count every tab shares; its floor ("99+") too (hub-477).
|
|
2292
|
-
const own = (prop) => `${prop}={${
|
|
2414
|
+
const own = (prop) => `${prop}={${optionalMark(ctx, strip, joinName(camelName(values[i]), prop), null)}}`;
|
|
2293
2415
|
trigger = trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bactionableCount=\{(?:\d+|(?:__s\d+_)?actionableCount)\}/, (_, head) => `${head}${own("actionableCount")}`);
|
|
2294
2416
|
trigger = trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bcountIsFloor(?=\s|>)/, (_, head) => `${head}${own("countIsFloor")}`);
|
|
2295
2417
|
return shownWhen(`(${visible}?.includes(${JSON.stringify(values[i])}) ?? true)`, indent(trigger, 3), 2);
|
|
@@ -2722,6 +2844,14 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2722
2844
|
if (f.write && f.check) throw new CliError("USAGE", "--write and --check are separate runs: --write updates the files, --check refuses a difference", 2);
|
|
2723
2845
|
if (f.check && f.fetch) throw new CliError("USAGE", "--check regenerates from the committed trees and never reads Figma; drop --fetch", 2);
|
|
2724
2846
|
if (f.resume && !(f.fetch && f.write)) throw new CliError("USAGE", "--resume continues a stopped read: use it with --fetch --write", 2);
|
|
2847
|
+
// --node locates one named Surface that is new to its file at a named version (cli-144).
|
|
2848
|
+
const nodeMatch = f.node === undefined ? null : NODE_ID.exec(String(f.node));
|
|
2849
|
+
if (f.node !== undefined) {
|
|
2850
|
+
if (!nodeMatch) throw new CliError("USAGE", `--node needs a component set's node id, for example 5:0: got ${f.node === true ? "nothing" : f.node}`, 2);
|
|
2851
|
+
if (!f.fetch || !f["figma-version"] || f["figma-version"] === true) throw new CliError("USAGE", "--node reads Figma at a named version: use it with --fetch --figma-version V", 2);
|
|
2852
|
+
if (f.all || !SET_KEY.test(rest[0] ?? "")) throw new CliError("USAGE", "--node locates one Surface: name it by its component-set key, not --all or a route", 2);
|
|
2853
|
+
}
|
|
2854
|
+
const node = nodeMatch ? `${nodeMatch[1]}:${nodeMatch[2]}` : undefined;
|
|
2725
2855
|
const postTo = f["post-scoreboard"];
|
|
2726
2856
|
if (postTo === true || postTo === "") throw new CliError("USAGE", "--post-scoreboard needs an issue key, for example DESIGN-SYSTEM-249", 2);
|
|
2727
2857
|
const { env = process.env, exec = execFileSync, log = (line) => process.stderr.write(`${line}\n`), figmaGet: injected, docs, cwd } = deps;
|
|
@@ -2791,7 +2921,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2791
2921
|
continue;
|
|
2792
2922
|
}
|
|
2793
2923
|
}
|
|
2794
|
-
if (!indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
2924
|
+
if (!node && !indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
2795
2925
|
// --all covers a module: one unpublished Surface is reported, and the rest still generate.
|
|
2796
2926
|
// A Surface named on its own stays a refusal, because the run has nothing else to do.
|
|
2797
2927
|
if (f.all && !indexes.get(row.fileKey).has(row.componentSetKey)) {
|
|
@@ -2800,7 +2930,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
2800
2930
|
continue;
|
|
2801
2931
|
}
|
|
2802
2932
|
log(`reading ${row.componentSetName ?? row.id} from Figma at version ${version}`);
|
|
2803
|
-
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version });
|
|
2933
|
+
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version, node });
|
|
2804
2934
|
} catch (error) {
|
|
2805
2935
|
// --all keeps what it read and scores it; a Surface named on its own has nothing to keep.
|
|
2806
2936
|
if (!f.all || error?.code !== "FIGMA_RATE_LIMITED") throw error;
|