@nodii/dev 0.6.113 → 0.6.115
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 +17 -3
- package/dist/cli.js +9 -5
- package/dist/core.js +1 -1
- package/dist/design.js +4 -2
- package/dist/figma.js +32 -9
- package/dist/flags.js +2 -2
- package/dist/surface.js +112 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -934,9 +934,23 @@ product-page catalog names the Surface by its published component-set key
|
|
|
934
934
|
so a stopped or killed run keeps its reads. Add `--resume` to carry on: it keeps
|
|
935
935
|
a saved tree only when it was read at the version this run reads (the file's
|
|
936
936
|
last publish, or `--figma-version V`), and reads the rest.
|
|
937
|
-
- **
|
|
938
|
-
|
|
939
|
-
|
|
937
|
+
- **Assembly (MW8-17.3).** The generator assembles what Code Connect provides,
|
|
938
|
+
deterministically, and lists each assembly as kind `assembled`, which doesn't
|
|
939
|
+
count against a Surface being clean:
|
|
940
|
+
- **Tables.** Rows of Table parts (what the templates emit as `TableHead` or
|
|
941
|
+
`TableCell`) become one DS `Table`. A cell that is no Table part is held in a
|
|
942
|
+
`TableCell`, and a wrapped cell takes its row's density. A row of frame cells
|
|
943
|
+
only (a loading row) is a body row of that table when it has as many cells as
|
|
944
|
+
the rows of Table parts; rows of frames alone are never a table. A row with
|
|
945
|
+
any head part is a header row, and a body part in it (a select-all Rich Cell)
|
|
946
|
+
keeps its own code. What follows the rows (an Empty or Error State, bare, in
|
|
947
|
+
its own frame, or as a last row holding one DS instance) follows the Table.
|
|
948
|
+
- **Tabs.** The Tab template draws one tab as a whole strip, so two or more
|
|
949
|
+
sibling Tabs are gathered into one `Tabs panelless` › `TabsList`, values
|
|
950
|
+
`tab-1`, `tab-2`, …, with the selected tab as `defaultValue`. A lone Tab
|
|
951
|
+
stays as its template gives it. This rule goes when DESIGN-SYSTEM-271 lands.
|
|
952
|
+
- **What isn't recognised stays unmapped.** A Table part outside any table the
|
|
953
|
+
generator recognises is reported as kind `table`, never passed off as mapped.
|
|
940
954
|
- **Exposed instances and text.** A tree keeps a remote instance's exposed nested
|
|
941
955
|
instances by layer name, for a template's `findInstance`. Text bound to a DS text
|
|
942
956
|
style and a DS colour role is listed as kind `bound-text` and doesn't count against
|
package/dist/cli.js
CHANGED
|
@@ -206,9 +206,11 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
206
206
|
figma lane-reads-script --nodes ID[,ID]
|
|
207
207
|
# prints the read-only use_figma script that gathers the nodes for --lane-reads
|
|
208
208
|
figma check|log-write|submit|apply|abandon|release
|
|
209
|
-
figma submit CHANGE_SET --file SUBMIT.json [--sync] [--dry-run]
|
|
209
|
+
figma submit CHANGE_SET --file SUBMIT.json [--sync] [--dry-run] [--lane-reads FILE]
|
|
210
210
|
# --dry-run (submit and resubmit) runs Dev's dry run of the
|
|
211
211
|
# submit gate on the same body, as design check --change-set; never writes
|
|
212
|
+
# --lane-reads (submit, resubmit, --dry-run): Dev runs no job and answers on
|
|
213
|
+
# the request from your MCP and REST reads; it names any read it still needs
|
|
212
214
|
# SUBMIT.json: { figmaVersion, writeUp, items: [{ figmaNodeId, change, context,
|
|
213
215
|
# variants: [{ nodeId, name, context, afterPngBase64 }] }] } (DEC-0204);
|
|
214
216
|
# a missing writeUp, context or variant name, or an item with no variants,
|
|
@@ -231,7 +233,7 @@ Usage: nodii-dev <command> [options] [--json]
|
|
|
231
233
|
# must be back at the set's base version first (CHANGE_ITEM_NOT_AT_BASE lists
|
|
232
234
|
# the ones that differ); a withdrawn item never publishes, and the scopes only
|
|
233
235
|
# it sat in are released
|
|
234
|
-
figma resubmit CHANGE_SET PAYLOAD.json [--sync] [--dry-run]
|
|
236
|
+
figma resubmit CHANGE_SET PAYLOAD.json [--sync] [--dry-run] [--lane-reads FILE]
|
|
235
237
|
# holder re-submits every rejected item: applying -> in_review, round + 1;
|
|
236
238
|
# each item needs context, each variant name and context; writeUp optional
|
|
237
239
|
figma changeset show CHANGE_SET # write-up, items, context, variants, round, decision and comment (with the previous round's)
|
|
@@ -1337,8 +1339,9 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1337
1339
|
// --dry-run runs Dev's dry run of the submit gate (design check --change-set)
|
|
1338
1340
|
// on the same body, and never writes (CLI-18).
|
|
1339
1341
|
const dryRun = async (id, text, file) => {
|
|
1342
|
+
const laneReads = f["lane-reads"] ? await readLaneReads(f["lane-reads"]) : undefined;
|
|
1340
1343
|
const result = await designCheckChangeSet(undefined, { "change-set": id, ...(text ? { file } : {}), ...(f["figma-version"] ? { "figma-version": f["figma-version"] } : {}), ...(f.sync ? { sync: true } : {}), ...(f.async ? { async: true } : {}) },
|
|
1341
|
-
{ read: async () => text });
|
|
1344
|
+
{ read: async () => text, ...(laneReads ? { laneReads } : {}) }).catch((error) => { throw laneReadsRefusal(error); });
|
|
1342
1345
|
emit(result.payload, json, result.human);
|
|
1343
1346
|
if (result.exitCode) {
|
|
1344
1347
|
if (!json) console.error(`DS_CONFORMANCE_FAILED: ${result.payload.data.findings.length} finding(s)`);
|
|
@@ -1361,7 +1364,8 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1361
1364
|
if (action === "submit") {
|
|
1362
1365
|
const payload = f.file ? JSON.parse(await readFile(f.file, "utf8")) : { figmaVersion: requireFlag(f, "figma-version") };
|
|
1363
1366
|
// A 200 carries top-level warnings (STALE_FIGMA_VERSION): print them.
|
|
1364
|
-
|
|
1367
|
+
const laneReads = f["lane-reads"] ? await readLaneReads(f["lane-reads"]) : undefined;
|
|
1368
|
+
return emit(await figmaSubmit(rest[0], payload, { sync: submitMode(f), file: f.file || "the submit (no --file)", ...(laneReads ? { laneReads } : {}) }), json, (p) =>
|
|
1365
1369
|
[JSON.stringify(p.data, null, 2), ...conformanceLines({ warnings: p.warnings })].join("\n"));
|
|
1366
1370
|
}
|
|
1367
1371
|
if (action === "file") {
|
|
@@ -1447,7 +1451,7 @@ export async function main(argv = process.argv.slice(2)) {
|
|
|
1447
1451
|
return emit(await figmaWithdraw(rest[0]), json, (p) => `Withdrew ${rest[0]}; it is back in ${p.data?.state ?? "editing"}.`);
|
|
1448
1452
|
}
|
|
1449
1453
|
if (action === "resubmit")
|
|
1450
|
-
return emit(await figmaResubmit(rest[0], rest[1], { sync: submitMode(f) }), json, (p) =>
|
|
1454
|
+
return emit(await figmaResubmit(rest[0], rest[1], { sync: submitMode(f), ...(f["lane-reads"] ? { laneReads: await readLaneReads(f["lane-reads"]) } : {}) }), json, (p) =>
|
|
1451
1455
|
[`Re-submitted ${rest[0]}; it is ${p.data.state}.`, figmaChangeSetText(p.data), ...conformanceLines({ warnings: p.warnings })].join("\n"));
|
|
1452
1456
|
if (action === "changeset") {
|
|
1453
1457
|
if (rest[0] === "list") {
|
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.115";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/design.js
CHANGED
|
@@ -445,9 +445,10 @@ export function designCheckText({ data }) {
|
|
|
445
445
|
* plus the submit-time guards against the set's items: IMAGE_NOT_TRUECOLOR
|
|
446
446
|
* refuses; STALE_FIGMA_VERSION is a warning. Changes no state.
|
|
447
447
|
*/
|
|
448
|
-
export async function designCheckChangeSet(target, flags, { request = devRequest, send, progress, read = (f) => readFile(f, "utf8") } = {}) {
|
|
448
|
+
export async function designCheckChangeSet(target, flags, { request = devRequest, send, progress, read = (f) => readFile(f, "utf8"), laneReads } = {}) {
|
|
449
449
|
const id = flags["change-set"];
|
|
450
|
-
|
|
450
|
+
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
451
|
+
const sync = laneReads ? true : submitMode(flags);
|
|
451
452
|
if (id === true || !id) throw new CliError("USAGE", "--change-set needs a change set id, e.g. --change-set CS-123", 2);
|
|
452
453
|
if (target !== undefined) throw new CliError("USAGE", "design check --change-set CS takes no file: Dev checks the set's own items", 2);
|
|
453
454
|
if (flags["figma-version"] === true) throw new CliError("USAGE", "--figma-version needs a version id", 2);
|
|
@@ -464,6 +465,7 @@ export async function designCheckChangeSet(target, flags, { request = devRequest
|
|
|
464
465
|
if (!body || typeof body !== "object" || Array.isArray(body)) throw new CliError("USAGE", `${flags.file}: expected the submit body, a JSON object`, 2);
|
|
465
466
|
}
|
|
466
467
|
if (flags["figma-version"]) body = { ...body, figmaVersion: String(flags["figma-version"]) };
|
|
468
|
+
if (laneReads) body = { ...body, laneReads };
|
|
467
469
|
let p;
|
|
468
470
|
try {
|
|
469
471
|
p = await figmaConformance(id, body, { request, sync, ...(send ? { send } : {}), ...(progress ? { progress } : {}) });
|
package/dist/figma.js
CHANGED
|
@@ -358,7 +358,7 @@ async function submitCall(id, kind, body, { sync = false, request = devRequest,
|
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
|
|
361
|
-
export async function figmaResubmit(id, file, { request = devRequest, read = (f) => readFile(f, "utf8"), ...options } = {}) {
|
|
361
|
+
export async function figmaResubmit(id, file, { request = devRequest, read = (f) => readFile(f, "utf8"), laneReads, ...options } = {}) {
|
|
362
362
|
if (!id || !file) throw new CliError("USAGE", "figma resubmit CHANGE_SET PAYLOAD.json", 2);
|
|
363
363
|
let text;
|
|
364
364
|
try {
|
|
@@ -368,8 +368,10 @@ export async function figmaResubmit(id, file, { request = devRequest, read = (f)
|
|
|
368
368
|
}
|
|
369
369
|
const body = assertContext(resubmitPayload(text, file), { resubmit: true, file });
|
|
370
370
|
try {
|
|
371
|
-
|
|
371
|
+
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
372
|
+
return await submitCall(id, "resubmit", laneReads ? { ...body, laneReads } : body, { request, ...options, ...(laneReads ? { sync: true } : {}) });
|
|
372
373
|
} catch (error) {
|
|
374
|
+
if (error?.code === "FIGMA_READS_NEEDED") throw laneReadsRefusal(error);
|
|
373
375
|
const say = RESUBMIT_REFUSALS[error?.code];
|
|
374
376
|
if (!say) throw scopeRefusal(error, id) ?? error;
|
|
375
377
|
throw new CliError(error.code, say(id, error.details, error.message), error.exitCode ?? 1, error.details);
|
|
@@ -473,6 +475,13 @@ export function figmaChangeSetListText(rows = [], total = rows.length) {
|
|
|
473
475
|
* the previous round's decision and comment, context and variants. An item with
|
|
474
476
|
* no variants needs a re-submit (DESIGN-SYSTEM-PARITY-4): it is flagged, never hidden.
|
|
475
477
|
*/
|
|
478
|
+
const JOB_KINDS = { conformance: "dry run", resubmit: "re-submit", represent: "re-present", log_write: "logged write" };
|
|
479
|
+
const jobLine = (job) => {
|
|
480
|
+
const head = `${job.state === "running" || job.state === "queued" ? "job" : "last job"}: ${JOB_KINDS[job.kind] ?? job.kind} ${job.id} ${job.state}`;
|
|
481
|
+
if (job.state !== "failed") return job.finishedAt ? `${head} at ${job.finishedAt}` : head;
|
|
482
|
+
return `${head}${job.finishedAt ? ` at ${job.finishedAt}` : ""}: ${job.error?.code ?? "INTERNAL"}${job.error?.message ? `: ${job.error.message}` : ""}`;
|
|
483
|
+
};
|
|
484
|
+
|
|
476
485
|
export function figmaChangeSetText(cs) {
|
|
477
486
|
const c = cs.itemCounts ?? {};
|
|
478
487
|
const lines = [
|
|
@@ -481,6 +490,9 @@ export function figmaChangeSetText(cs) {
|
|
|
481
490
|
`${c.total ?? cs.items.length} items: ${c.approved ?? 0} approved, ${c.rejected ?? 0} rejected, ${c.pending ?? 0} pending`,
|
|
482
491
|
`write-up: ${cs.writeUp ?? (cs.state === "editing" ? "none yet" : `none (${BEFORE_CONTEXT})`)}`,
|
|
483
492
|
];
|
|
493
|
+
// Dev shows the running job, else the last one and how it ended (hub-295),
|
|
494
|
+
// so a failed job never reads as no job.
|
|
495
|
+
if (cs.job) lines.push(jobLine(cs.job));
|
|
484
496
|
for (const item of cs.items ?? []) {
|
|
485
497
|
lines.push(`- ${item.decision} round ${item.round} ${item.figmaNodeId} ${item.entryKey ?? "(new)"} ${item.change} item ${item.id}`);
|
|
486
498
|
if (item.comment) lines.push(` comment: ${item.comment}`);
|
|
@@ -736,10 +748,14 @@ export function checkSubmitPayload(payload, file = "the submit body") {
|
|
|
736
748
|
return assertContext(payload, { file });
|
|
737
749
|
}
|
|
738
750
|
|
|
739
|
-
export async function figmaSubmit(id, payload, { request = devRequest, file = "the submit body", ...options } = {}) {
|
|
751
|
+
export async function figmaSubmit(id, payload, { request = devRequest, file = "the submit body", laneReads, ...options } = {}) {
|
|
740
752
|
checkSubmitPayload(payload, file);
|
|
741
|
-
|
|
742
|
-
|
|
753
|
+
// On the lane's reads Dev answers on the request, with no job (hub-295).
|
|
754
|
+
const sync = laneReads ? { sync: true } : {};
|
|
755
|
+
return changeSetCall(id, (method, path, body) => submitCall(id, "submit", body, { request, ...options, ...sync }))(
|
|
756
|
+
"POST", `/api/v1/design/change-sets/${encode(id)}/submit`, laneReads ? { ...payload, laneReads } : payload).catch((error) => {
|
|
757
|
+
throw laneReadsRefusal(error);
|
|
758
|
+
});
|
|
743
759
|
}
|
|
744
760
|
|
|
745
761
|
/** checkDesignConformance: the submit gate's dry run on a change set; changes no state. Body: { figmaVersion?, items? }. Async unless `sync`. */
|
|
@@ -1026,11 +1042,18 @@ export async function readLaneReads(path, { read = readFile } = {}) {
|
|
|
1026
1042
|
export function laneReadsRefusal(error) {
|
|
1027
1043
|
if (error?.code !== "FIGMA_READS_NEEDED") return error;
|
|
1028
1044
|
const ids = error.details?.nodeIds ?? [];
|
|
1029
|
-
const
|
|
1045
|
+
const read = error.details?.read;
|
|
1046
|
+
// documents, rest and render are REST reads in the lane's own session; Dev's
|
|
1047
|
+
// message names what to read and where it goes (hub-295).
|
|
1048
|
+
const next = read === "base"
|
|
1030
1049
|
? "Compare each with the set's base, add it to base.atBase or base.offBase in the lane-reads file (base.absent if the base version didn't have it, such as the component a create made), and say how in base.how. Then send this again."
|
|
1031
|
-
:
|
|
1032
|
-
?
|
|
1033
|
-
:
|
|
1050
|
+
: read === "render"
|
|
1051
|
+
? "Add the images to the submit body as Dev says, then send this again."
|
|
1052
|
+
: read === "documents" || read === "rest"
|
|
1053
|
+
? "Add the answers to the lane-reads file as Dev says, then send this again."
|
|
1054
|
+
: ids.length
|
|
1055
|
+
? `Add them with the MCP: nodii-dev figma lane-reads-script --nodes ${ids.join(",")}\nThen send this again.`
|
|
1056
|
+
: "This check has no MCP path yet: tell the Steward (hub-295).";
|
|
1034
1057
|
return new CliError(error.code, `${error.message}\n${next}`, error.exitCode ?? 1, error.details);
|
|
1035
1058
|
}
|
|
1036
1059
|
|
package/dist/flags.js
CHANGED
|
@@ -64,8 +64,8 @@ export const COMMAND_FLAGS = {
|
|
|
64
64
|
"request file": ["from", "to", "kind", "summary", "spec", "spec-file", "required-capability", "target-artifact-type", "target-artifact-id"],
|
|
65
65
|
"docs upload": ["class", "change-class", "pending", "decision", "meaning-unchanged", "conformance-ref", "base", "no-embed", ...WAIT],
|
|
66
66
|
"docs ratify": ["domain", "decision", ...WAIT],
|
|
67
|
-
"figma submit": ["file", "figma-version", ...SUBMIT_MODE, "dry-run"],
|
|
68
|
-
"figma resubmit": [...SUBMIT_MODE, "dry-run"],
|
|
67
|
+
"figma submit": ["file", "figma-version", ...SUBMIT_MODE, "dry-run", "lane-reads"],
|
|
68
|
+
"figma resubmit": [...SUBMIT_MODE, "dry-run", "lane-reads"],
|
|
69
69
|
"figma withdraw": ["items", "reason", "lane-reads"],
|
|
70
70
|
"figma lane-reads-script": ["nodes"],
|
|
71
71
|
"figma abandon": ["file"],
|
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 = 7;
|
|
36
36
|
export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
|
|
37
37
|
export const GENERATED_SUFFIX = ".surface.generated.tsx";
|
|
38
38
|
const CATALOG_PATH = "packages/blocks/src/product-pages/catalog.ts";
|
|
@@ -664,7 +664,10 @@ function colour(prefix, paint, scope, ds, report) {
|
|
|
664
664
|
|
|
665
665
|
/** Text with both DS bindings: listed, but not counted against a Surface being clean. */
|
|
666
666
|
const BOUND_TEXT = "bound-text";
|
|
667
|
-
|
|
667
|
+
/** What the generator assembled from Code Connect parts (MW8-17.3): listed, not counted. */
|
|
668
|
+
const ASSEMBLED = "assembled";
|
|
669
|
+
const LISTED_ONLY = new Set([BOUND_TEXT, ASSEMBLED]);
|
|
670
|
+
const counted = (unmapped) => unmapped.filter((u) => !LISTED_ONLY.has(u.kind));
|
|
668
671
|
|
|
669
672
|
/** DS parts whose text should be a component property, not slot content (the Q-211 Lock-Change). */
|
|
670
673
|
const TEXT_PROPERTY_PARTS = new Set(["Table cell", "Table Header", "File Viewer"]);
|
|
@@ -698,7 +701,8 @@ function emitNode(node, ctx) {
|
|
|
698
701
|
return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
|
|
699
702
|
}
|
|
700
703
|
const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
|
|
701
|
-
const
|
|
704
|
+
const slotCtx = { ...ctx, depth: 0, parent: slotNode, path: `${path} › ${prop}`, root: false, textOwner, inTable: false };
|
|
705
|
+
const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
|
|
702
706
|
return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
|
|
703
707
|
};
|
|
704
708
|
const rendered = dsNode ? ds.renderer.renderInstance(ds.dsFileKey, dsNode, values, { slot: slotContent, nested }) : null;
|
|
@@ -710,6 +714,9 @@ function emitNode(node, ctx) {
|
|
|
710
714
|
ctx.imports.push(...rendered.imports);
|
|
711
715
|
const sizing = ctx.bare ? [] : sizeClasses(node, parent, false);
|
|
712
716
|
const code = rendered.code.trim();
|
|
717
|
+
// A Table part is valid only inside the DS Table. One the generator could not assemble
|
|
718
|
+
// into a Table stays reported, never passed off as mapped (MW8-17.3).
|
|
719
|
+
if (!ctx.inTable && tablePart(/^<([A-Za-z]+)/.exec(code)?.[1])) note(path, "table", `${describe(node)} is a Table part outside any table the generator recognises`);
|
|
713
720
|
if (!sizing.length) return indent(code, depth);
|
|
714
721
|
// Layout around a DS component is the page's; the component itself takes no className (U07-19).
|
|
715
722
|
return [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, depth), indent(code, depth + 1), indent("</div>", depth)].join("\n");
|
|
@@ -758,12 +765,69 @@ function emitNode(node, ctx) {
|
|
|
758
765
|
return indent(comment(`unmapped: ${node.type.toLowerCase()} ${JSON.stringify(node.name)} has no auto layout`), depth);
|
|
759
766
|
}
|
|
760
767
|
const classes = cls([...sizeClasses(node, parent, root), ...layoutClasses(node), node.clips ? "overflow-hidden" : null]);
|
|
761
|
-
const kids = (node.children ?? []
|
|
768
|
+
const kids = emitChildren(node.children ?? [], child, { ...ctx, depth: depth + 1, parent: node, path, root: false });
|
|
762
769
|
const open = `<div${classes ? ` className="${classes}"` : ""}`;
|
|
763
770
|
if (!kids.length) return indent(`${open} />`, depth);
|
|
764
771
|
return [indent(`${open}>`, depth), ...kids, indent("</div>", depth)].join("\n");
|
|
765
772
|
}
|
|
766
773
|
|
|
774
|
+
/**
|
|
775
|
+
* A frame's or slot's children, in order, with each run of two or more sibling
|
|
776
|
+
* Tabs gathered into one DS Tab strip (MW8-17.3). The Tab template draws one
|
|
777
|
+
* tab as a whole panelless strip (Tabs › TabsList › one TabsTrigger), so
|
|
778
|
+
* siblings emitted one by one would be separate strips. Hidden siblings don't
|
|
779
|
+
* break a run. To be removed when DESIGN-SYSTEM-271 lands.
|
|
780
|
+
*/
|
|
781
|
+
function emitChildren(children, emitOne, ctx) {
|
|
782
|
+
const out = [];
|
|
783
|
+
let run = [];
|
|
784
|
+
const flush = () => {
|
|
785
|
+
if (run.length >= 2) out.push(tabStrip(run, ctx));
|
|
786
|
+
else out.push(...run.map(emitOne).filter((x) => x !== null));
|
|
787
|
+
run = [];
|
|
788
|
+
};
|
|
789
|
+
for (const c of children) {
|
|
790
|
+
if (c.visible === false) continue;
|
|
791
|
+
if (tabOf(c, ctx)) run.push(c);
|
|
792
|
+
else {
|
|
793
|
+
flush();
|
|
794
|
+
const code = emitOne(c);
|
|
795
|
+
if (code !== null) out.push(code);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
flush();
|
|
799
|
+
return out;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/** The single-tab strip the Tab template emits: Tabs › TabsList › one TabsTrigger. */
|
|
803
|
+
const TAB_STRIP = /^<Tabs panelless( defaultValue="tab")?>\n\s*<TabsList>\n(\s*)(<TabsTrigger\b[\s\S]*?<\/TabsTrigger>)\n\s*<\/TabsList>\n\s*<\/Tabs>$/;
|
|
804
|
+
|
|
805
|
+
/** A DS instance whose template emits one tab: { selected, trigger } (trigger dedented to column 0), else null. */
|
|
806
|
+
function tabOf(node, ctx, { imports = [], note = () => {} } = {}) {
|
|
807
|
+
if (!node.instance?.remote || node.visible === false) return null;
|
|
808
|
+
const code = emitNode(node, { ...ctx, depth: 0, parent: null, bare: true, inTable: false, imports, note });
|
|
809
|
+
const m = TAB_STRIP.exec(code?.trim() ?? "");
|
|
810
|
+
if (!m || (m[3].match(/<TabsTrigger\b/g) ?? []).length !== 1) return null;
|
|
811
|
+
const pad = m[2].length;
|
|
812
|
+
const trigger = m[3].split("\n").map((line, i) => (i === 0 ? line : line.slice(Math.min(pad, line.length - line.trimStart().length)))).join("\n");
|
|
813
|
+
return { selected: Boolean(m[1]), trigger };
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
function tabStrip(run, ctx) {
|
|
817
|
+
const { depth, path } = ctx;
|
|
818
|
+
const tabs = run.map((c) => tabOf(c, { ...ctx, path: `${path} › ${c.name}` }, { imports: ctx.imports, note: ctx.note }));
|
|
819
|
+
const selected = tabs.findIndex((t) => t.selected);
|
|
820
|
+
ctx.note(path, ASSEMBLED, `${run.length} sibling Tabs gathered into one DS Tab strip (MW8-17.3)`);
|
|
821
|
+
const triggers = tabs.map((t, i) => indent(t.trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bvalue="tab"/, `$1value="tab-${i + 1}"`), 2));
|
|
822
|
+
return [
|
|
823
|
+
indent(`<Tabs panelless${selected >= 0 ? ` defaultValue="tab-${selected + 1}"` : ""}>`, depth),
|
|
824
|
+
indent(" <TabsList>", depth),
|
|
825
|
+
...triggers.map((t) => indent(t, depth)),
|
|
826
|
+
indent(" </TabsList>", depth),
|
|
827
|
+
indent("</Tabs>", depth),
|
|
828
|
+
].join("\n");
|
|
829
|
+
}
|
|
830
|
+
|
|
767
831
|
/**
|
|
768
832
|
* A table a Surface draws as frames: rows of Table-part instances (what the
|
|
769
833
|
* templates emit as TableHead or TableCell). Those parts are valid only inside
|
|
@@ -797,11 +861,13 @@ function withWidth(code, w) {
|
|
|
797
861
|
}
|
|
798
862
|
function tableOf(node, ctx) {
|
|
799
863
|
const shown = (node.children ?? []).filter((c) => c.visible !== false);
|
|
800
|
-
//
|
|
864
|
+
// What follows the rows (a table's Empty State, bare or in its own frame) follows the Table:
|
|
865
|
+
// it must not undo it. A row is a frame laid out horizontally.
|
|
866
|
+
const isRow = (r) => !r.instance?.remote && r.type !== "TEXT" && r.layout?.mode === "HORIZONTAL";
|
|
801
867
|
let end = shown.length;
|
|
802
|
-
while (end > 0 && shown[end - 1]
|
|
803
|
-
|
|
804
|
-
|
|
868
|
+
while (end > 0 && !isRow(shown[end - 1])) end -= 1;
|
|
869
|
+
let rows = shown.slice(0, end);
|
|
870
|
+
let after = shown.slice(end);
|
|
805
871
|
if (!rows.length || rows.some((r) => r.instance?.remote || r.type === "TEXT" || r.layout?.mode !== "HORIZONTAL")) return null;
|
|
806
872
|
const imports = [];
|
|
807
873
|
const parsed = [];
|
|
@@ -811,7 +877,7 @@ function tableOf(node, ctx) {
|
|
|
811
877
|
for (const cell of (row.children ?? []).filter((c) => c.visible !== false)) {
|
|
812
878
|
if (cell.instance?.remote) {
|
|
813
879
|
const local = [];
|
|
814
|
-
const code = emitNode(cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, imports: local, note: () => {} });
|
|
880
|
+
const code = emitNode(cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true, imports: local, note: () => {} });
|
|
815
881
|
const part = tablePart(/^<([A-Za-z]+)/.exec(code ?? "")?.[1]);
|
|
816
882
|
// A cell that is no Table part (a component with no template, or a DS part drawn
|
|
817
883
|
// in a row) is held in a TableCell: one such cell must not undo the whole table.
|
|
@@ -820,19 +886,39 @@ function tableOf(node, ctx) {
|
|
|
820
886
|
cells.push({ cell, code, held: true });
|
|
821
887
|
continue;
|
|
822
888
|
}
|
|
823
|
-
|
|
824
|
-
|
|
889
|
+
// A row with any head part is a header row; a body part in it (a select-all
|
|
890
|
+
// Rich Cell) keeps its own template code, as a cell of that row.
|
|
891
|
+
kind = kind === "head" || part === "head" ? "head" : part;
|
|
825
892
|
imports.push(...local);
|
|
826
893
|
cells.push({ cell, code });
|
|
827
894
|
} else if (cell.layout || cell.type === "TEXT") cells.push({ cell, code: null });
|
|
828
895
|
else return null;
|
|
829
896
|
}
|
|
830
|
-
|
|
831
|
-
|
|
897
|
+
// A row with no Table part (a loading row of frame cells) is a body row only beside
|
|
898
|
+
// rows of Table parts, and only with as many cells as they have; checked below.
|
|
899
|
+
const spanning = !kind && cells.length === 1 && cells[0].held;
|
|
900
|
+
if (!kind && cells.some((c) => c.held) && !spanning) return null;
|
|
901
|
+
parsed.push({ row, kind, cells, spanning });
|
|
902
|
+
}
|
|
903
|
+
// A last row that holds one DS instance and no Table part (an Error or Empty State
|
|
904
|
+
// drawn across the table) follows the Table; anywhere else it is no table row.
|
|
905
|
+
while (parsed.length && parsed.at(-1).spanning) {
|
|
906
|
+
after = [parsed.pop().row, ...after];
|
|
907
|
+
rows = rows.slice(0, -1);
|
|
908
|
+
}
|
|
909
|
+
if (parsed.some((p) => p.spanning)) return null;
|
|
910
|
+
const partRows = parsed.filter((p) => p.kind);
|
|
911
|
+
if (!partRows.length) return null;
|
|
912
|
+
const columns = partRows[0].cells.length;
|
|
913
|
+
for (const p of parsed) {
|
|
914
|
+
if (p.kind) continue;
|
|
915
|
+
if (p.cells.length !== columns) return null;
|
|
916
|
+
p.kind = "body";
|
|
832
917
|
}
|
|
833
918
|
const module = imports.map((s) => /\{[^}]*\bTable[A-Za-z]*(Cell|Head)\b[^}]*\}\s+from\s+["']([^"']+)["']/.exec(s)?.[2]).find(Boolean);
|
|
834
919
|
if (!module) return null;
|
|
835
|
-
|
|
920
|
+
const plain = parsed.length - partRows.length;
|
|
921
|
+
ctx.note(ctx.path, ASSEMBLED, `${rows.length} row${rows.length === 1 ? "" : "s"} of Table parts${plain ? ` (${plain} of them frame cells only)` : ""} assembled into one DS Table (MW8-17.3)`);
|
|
836
922
|
ctx.imports.push(...imports, `import { Table, TableBody, TableHeader, TableRow } from "${module}";`);
|
|
837
923
|
const { depth } = ctx;
|
|
838
924
|
// A cell the generator wraps has no template to say its density, so it takes the one
|
|
@@ -846,15 +932,15 @@ function tableOf(node, ctx) {
|
|
|
846
932
|
const cellCode = ({ cell, code, held }, row, d) => {
|
|
847
933
|
const w = columnWidth(cell);
|
|
848
934
|
if (held) {
|
|
849
|
-
const inner = emitNode(cell, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true });
|
|
935
|
+
const inner = emitNode(cell, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true });
|
|
850
936
|
return [indent(`<TableCell${wrapperAttrs(w, row)}>`, d), inner, indent("</TableCell>", d)].join("\n");
|
|
851
937
|
}
|
|
852
938
|
if (code) {
|
|
853
939
|
// Re-emit for real, so the cell's own unmapped layers are reported.
|
|
854
|
-
return withWidth(emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true }), w);
|
|
940
|
+
return withWidth(emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true }), w);
|
|
855
941
|
}
|
|
856
942
|
// The frame stood in for the cell: its size and padding are the TableCell's now.
|
|
857
|
-
const inner = emitNode({ ...cell, sizing: ["HUG", "HUG"], x: undefined, fills: undefined, strokes: undefined, radius: undefined, ...(cell.layout ? { layout: { ...cell.layout, padding: [0, 0, 0, 0] } } : {}) }, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false });
|
|
943
|
+
const inner = emitNode({ ...cell, sizing: ["HUG", "HUG"], x: undefined, fills: undefined, strokes: undefined, radius: undefined, ...(cell.layout ? { layout: { ...cell.layout, padding: [0, 0, 0, 0] } } : {}) }, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, inTable: true });
|
|
858
944
|
return [indent(`<TableCell${wrapperAttrs(w, row)}>`, d), inner, indent("</TableCell>", d)].join("\n");
|
|
859
945
|
};
|
|
860
946
|
// Every column held at px or fill is a fixed table layout; a hug column needs the browser's auto layout.
|
|
@@ -871,7 +957,7 @@ function tableOf(node, ctx) {
|
|
|
871
957
|
};
|
|
872
958
|
const sizing = sizeClasses(node, ctx.parent, ctx.root);
|
|
873
959
|
const table = [indent(fixed ? '<Table layout="fixed">' : "<Table>", depth), ...section("head", "TableHeader"), ...section("body", "TableBody"), indent("</Table>", depth)];
|
|
874
|
-
const following = after.map((c) => emitNode(c, { ...ctx, depth, parent: node, path: `${ctx.path} › ${c.name}`, root: false })).filter((x) => x !== null);
|
|
960
|
+
const following = after.map((c) => emitNode(c, { ...ctx, depth, parent: node, path: `${ctx.path} › ${c.name}`, root: false, inTable: false })).filter((x) => x !== null);
|
|
875
961
|
if (!sizing.length && !following.length) return table.join("\n");
|
|
876
962
|
const lines = [...table, ...following.flatMap((code) => code.split("\n"))];
|
|
877
963
|
return [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, depth), ...lines.map((line) => indent(line, 1)), indent("</div>", depth)].join("\n");
|
|
@@ -903,7 +989,7 @@ export function unmappedMarkdown(files) {
|
|
|
903
989
|
const lines = [
|
|
904
990
|
"# Surface layers with no Code Connect mapping (U08-14)",
|
|
905
991
|
"",
|
|
906
|
-
"Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (text missing a DS text style or colour role, or text in a part that should own it as a property), `frame` (a frame that paints its own fill, stroke, radius or effect: only its layout is generated), `table` (a
|
|
992
|
+
"Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (text missing a DS text style or colour role, or text in a part that should own it as a property), `frame` (a frame that paints its own fill, stroke, radius or effect: only its layout is generated), `table` (a Table part outside any table the generator recognises), `layout` (a frame or slot with no auto layout), `shape` (a rectangle, ellipse or vector: marked, not drawn), `token` (a text colour that matches no colour v2 role: left out), `bound-text` (text bound to a DS text style and colour role, with no Code Connect mapping: listed, not counted against a Surface being clean), `assembled` (rows of Table parts assembled into one DS Table, or sibling Tabs gathered into one Tab strip, MW8-17.3: listed, not counted).",
|
|
907
993
|
"",
|
|
908
994
|
];
|
|
909
995
|
for (const [fileKey, file] of Object.entries(files)) {
|
|
@@ -929,7 +1015,7 @@ export function surfaceScoreboard(selected, results, { unpublished = [], notGene
|
|
|
929
1015
|
const modules = new Map();
|
|
930
1016
|
const of = (row) => {
|
|
931
1017
|
const name = moduleOf(row);
|
|
932
|
-
if (!modules.has(name)) modules.set(name, { module: name, total: 0, clean: 0, unmapped: 0, boundText: 0, byKind: {}, unpublished: [], notGeneratedYet: [] });
|
|
1018
|
+
if (!modules.has(name)) modules.set(name, { module: name, total: 0, clean: 0, unmapped: 0, boundText: 0, assembled: 0, byKind: {}, unpublished: [], notGeneratedYet: [] });
|
|
933
1019
|
return modules.get(name);
|
|
934
1020
|
};
|
|
935
1021
|
for (const row of selected) of(row).total += 1;
|
|
@@ -940,7 +1026,8 @@ export function surfaceScoreboard(selected, results, { unpublished = [], notGene
|
|
|
940
1026
|
const real = counted(r.unmapped);
|
|
941
1027
|
if (!real.length) entry.clean += 1;
|
|
942
1028
|
entry.unmapped += real.length;
|
|
943
|
-
entry.boundText += r.unmapped.
|
|
1029
|
+
entry.boundText += r.unmapped.filter((u) => u.kind === BOUND_TEXT).length;
|
|
1030
|
+
entry.assembled += r.unmapped.filter((u) => u.kind === ASSEMBLED).length;
|
|
944
1031
|
for (const u of real) entry.byKind[u.kind] = (entry.byKind[u.kind] ?? 0) + 1;
|
|
945
1032
|
}
|
|
946
1033
|
return [...modules.values()];
|
|
@@ -965,11 +1052,11 @@ export function scoreboardMarkdown(board, { mode, source, stopped = null }) {
|
|
|
965
1052
|
`**Surface scoreboard** (\`surface generate\`, ${mode} run, \`@nodii/dev\` ${VERSION}, ${source}).`,
|
|
966
1053
|
"",
|
|
967
1054
|
...(stopped ? [`**Partial: Figma answered 429 at \`${stopped.at}\`, so the run stopped with ${stopped.notRead.length} Surface${stopped.notRead.length === 1 ? "" : "s"} not read.** They count as not generated yet.`, ""] : []),
|
|
968
|
-
"A Surface is clean when it has no unmapped layer. Text bound to a DS text style and colour role
|
|
1055
|
+
"A Surface is clean when it has no unmapped layer. Text bound to a DS text style and colour role, and what the generator assembled from Code Connect parts (tables, tab strips), are listed in the report and not counted here. Total counts every selected Surface, including those not published or not generated yet.",
|
|
969
1056
|
"",
|
|
970
|
-
"| Module | Clean / total | Not published | Not generated yet | Unmapped | By kind |",
|
|
971
|
-
"
|
|
972
|
-
...board.map((m) => `| ${m.module} | ${m.clean} / ${m.total} | ${m.unpublished.length} | ${m.notGeneratedYet.length} | ${m.unmapped} | ${byKindText(m.byKind)} |`),
|
|
1057
|
+
"| Module | Clean / total | Not published | Not generated yet | Unmapped | By kind | Assembled |",
|
|
1058
|
+
"|---|---:|---:|---:|---:|---|---:|",
|
|
1059
|
+
...board.map((m) => `| ${m.module} | ${m.clean} / ${m.total} | ${m.unpublished.length} | ${m.notGeneratedYet.length} | ${m.unmapped} | ${byKindText(m.byKind)} | ${m.assembled} |`),
|
|
973
1060
|
];
|
|
974
1061
|
const skipped = board.filter((m) => m.unpublished.length);
|
|
975
1062
|
if (skipped.length) lines.push("", "**Not published, so not generated or scored:**", ...skipped.map((m) => `- ${m.module}: ${namesText(m.unpublished)}`));
|