@nodii/dev 0.6.112 → 0.6.114
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 +30 -7
- package/dist/core.js +1 -1
- package/dist/surface.js +205 -48
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -884,8 +884,17 @@ product-page catalog names the Surface by its published component-set key
|
|
|
884
884
|
|
|
885
885
|
- **`--fetch`** reads the Surface set from Figma's REST nodes API with
|
|
886
886
|
`FIGMA_PAT` (read-only, one call per 8 s, a 429 waits Retry-After or 30 s
|
|
887
|
-
doubling), at the version the
|
|
888
|
-
the
|
|
887
|
+
doubling), at the version the file's last library publish closed (MW8-17),
|
|
888
|
+
by the design system's snapshot-pin rule: the publish time is the newest
|
|
889
|
+
`updated_at` across the file's published components, component sets and
|
|
890
|
+
styles, and the version read is the newest one whose own `lastModified` is
|
|
891
|
+
at or before it. A later unpublished save is never read, and a committed
|
|
892
|
+
tree's older version does not hold a refetch back. The `Components
|
|
893
|
+
published` label is logged, not required, because a publish can leave its
|
|
894
|
+
version unlabelled. A file with no published rows, or with no version the
|
|
895
|
+
publish closed among its newest 40, is refused with
|
|
896
|
+
`SURFACE_FILE_NOT_PUBLISHED`. `--figma-version V` names a version outright.
|
|
897
|
+
Without `--fetch`, the committed tree under
|
|
889
898
|
`docs/figma-ux-ds/figma/surface-trees/<fileKey>/<componentSetKey>.json` is
|
|
890
899
|
read and Figma is not called.
|
|
891
900
|
- Each DS instance is emitted through its Code Connect template exactly as the
|
|
@@ -923,11 +932,25 @@ product-page catalog names the Surface by its published component-set key
|
|
|
923
932
|
`data.stopped`) and exits 1. A Surface named on its own fails with
|
|
924
933
|
`FIGMA_RATE_LIMITED`. With `--write`, each tree is saved as soon as it is read,
|
|
925
934
|
so a stopped or killed run keeps its reads. Add `--resume` to carry on: it keeps
|
|
926
|
-
a saved tree
|
|
927
|
-
|
|
928
|
-
- **
|
|
929
|
-
|
|
930
|
-
|
|
935
|
+
a saved tree only when it was read at the version this run reads (the file's
|
|
936
|
+
last publish, or `--figma-version V`), and reads the rest.
|
|
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.
|
|
931
954
|
- **Exposed instances and text.** A tree keeps a remote instance's exposed nested
|
|
932
955
|
instances by layer name, for a template's `findInstance`. Text bound to a DS text
|
|
933
956
|
style and a DS colour role is listed as kind `bound-text` and doesn't count against
|
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.114";
|
|
8
8
|
export const configPath = () =>
|
|
9
9
|
process.env.NODII_DEV_CONFIG_PATH ??
|
|
10
10
|
join(homedir(), ".config/nodii-dev/config.json");
|
package/dist/surface.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
// Figma: the product-page catalog (packages/blocks/src/product-pages/
|
|
7
7
|
// catalog.ts) names each Surface by its published component-set key (MW8-20,
|
|
8
8
|
// never a node id); the Surface's frame tree is read from Figma's REST nodes
|
|
9
|
-
// API at
|
|
10
|
-
//
|
|
9
|
+
// API at the file's last library publish (MW8-17: generation reads the
|
|
10
|
+
// published Surface, never a later unpublished save) and committed, trimmed,
|
|
11
|
+
// under docs/figma-ux-ds/figma/surface-trees/; every DS instance is emitted through
|
|
11
12
|
// its Code Connect template exactly as the template gives it (component,
|
|
12
13
|
// props, import), run by the design system's own template harness
|
|
13
14
|
// (./vendor/render-templates.mjs, vendored byte-for-byte); auto-layout becomes
|
|
@@ -31,7 +32,7 @@ import { CliError, VERSION, devRequest, readConfig } from "./core.js";
|
|
|
31
32
|
import { createRenderer } from "./vendor/render-templates.mjs";
|
|
32
33
|
|
|
33
34
|
/** Bumped whenever the emitted code changes shape for the same inputs. */
|
|
34
|
-
export const GENERATOR_FORMAT =
|
|
35
|
+
export const GENERATOR_FORMAT = 7;
|
|
35
36
|
export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
|
|
36
37
|
export const GENERATED_SUFFIX = ".surface.generated.tsx";
|
|
37
38
|
const CATALOG_PATH = "packages/blocks/src/product-pages/catalog.ts";
|
|
@@ -39,7 +40,8 @@ const DS_FILE_META = "infra/figma/figma-file.json";
|
|
|
39
40
|
const ONE_TO_ONE_SNAPSHOT = "docs/figma-ux-ds/figma/1to1/figma-file.snapshot.json";
|
|
40
41
|
const COLOUR_CATALOG = "packages/tokens/src/generated/colour-v2-catalog.json";
|
|
41
42
|
const TYPE_EDGES_CATALOG = "packages/tokens/src/generated/type-edges-v2-catalog.json";
|
|
42
|
-
|
|
43
|
+
/** How many versions to read back from the newest, looking for the one the last publish closed (8 s each). */
|
|
44
|
+
const MAX_VERSION_READS = 40;
|
|
43
45
|
const FIGMA_API = "https://api.figma.com/v1";
|
|
44
46
|
export const MIN_FIGMA_INTERVAL_MS = 8_000;
|
|
45
47
|
const BACKOFF_MS = 30_000;
|
|
@@ -163,6 +165,68 @@ export async function setIndex(figmaGet, fileKey) {
|
|
|
163
165
|
return new Map((body.meta?.component_sets ?? []).map((x) => [x.key, x.node_id]));
|
|
164
166
|
}
|
|
165
167
|
|
|
168
|
+
/** The REST endpoints that list a file's published library (as the DS's checkPublishPin reads them). */
|
|
169
|
+
export const LIBRARY_ENDPOINTS = ["components", "component_sets", "styles"];
|
|
170
|
+
|
|
171
|
+
/** A file's published library: `{ components, component_sets, styles }`, each a list of rows. */
|
|
172
|
+
export async function fetchLibrary(figmaGet, fileKey) {
|
|
173
|
+
const library = {};
|
|
174
|
+
for (const endpoint of LIBRARY_ENDPOINTS) {
|
|
175
|
+
const body = await figmaGet(`/files/${encodeURIComponent(fileKey)}/${endpoint}`);
|
|
176
|
+
library[endpoint] = body.meta?.[endpoint] ?? [];
|
|
177
|
+
}
|
|
178
|
+
return library;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** When the library was last published: the newest `updated_at` across its rows, or null. */
|
|
182
|
+
export function libraryPublishedAt(library) {
|
|
183
|
+
let newest = null;
|
|
184
|
+
for (const endpoint of LIBRARY_ENDPOINTS) {
|
|
185
|
+
for (const row of library[endpoint] ?? []) {
|
|
186
|
+
if (typeof row.updated_at !== "string" || !Number.isFinite(Date.parse(row.updated_at))) continue;
|
|
187
|
+
if (newest === null || Date.parse(row.updated_at) > Date.parse(newest)) newest = row.updated_at;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return newest;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The version the file's last library publish closed (MW8-17: generation reads the
|
|
195
|
+
* published Surface), by the design system's snapshot-pin rule (checkPublishPin,
|
|
196
|
+
* DS-FIGMA-1TO1-GATE-1). A library publish closes the open version and then stamps
|
|
197
|
+
* the library rows' `updated_at`, so the publish time is the newest `updated_at`
|
|
198
|
+
* across components, component sets and styles, and the pin is the newest version
|
|
199
|
+
* whose own `lastModified` (read with `?depth=1&version=`) is at or before it. A
|
|
200
|
+
* version saved after the publish can hold unpublished edits and is never taken.
|
|
201
|
+
* The "Components published" label is reported, not required: a publish can leave
|
|
202
|
+
* its version unlabelled (CS-3009). A file with no published rows, or no version
|
|
203
|
+
* closed by the publish, is refused.
|
|
204
|
+
*/
|
|
205
|
+
export async function lastPublishedVersion(figmaGet, fileKey, { library } = {}) {
|
|
206
|
+
library ??= await fetchLibrary(figmaGet, fileKey);
|
|
207
|
+
const publishedAt = libraryPublishedAt(library);
|
|
208
|
+
if (!publishedAt) throw new CliError("SURFACE_FILE_NOT_PUBLISHED", `${fileKey} has no published library rows, so it has never been published; publish the Surfaces file, or name a version with --figma-version`, 1);
|
|
209
|
+
const at = Date.parse(publishedAt);
|
|
210
|
+
const key = encodeURIComponent(fileKey);
|
|
211
|
+
let path = `/files/${key}/versions?page_size=20`;
|
|
212
|
+
let reads = 0;
|
|
213
|
+
while (path && reads < MAX_VERSION_READS) {
|
|
214
|
+
const body = await figmaGet(path);
|
|
215
|
+
// History comes newest first, and each version closes after the one before it,
|
|
216
|
+
// so the first one closed at or before the publish is the one the publish closed.
|
|
217
|
+
for (const row of body.versions ?? []) {
|
|
218
|
+
if (reads++ >= MAX_VERSION_READS) break;
|
|
219
|
+
const head = await figmaGet(`/files/${key}?depth=1&version=${encodeURIComponent(row.id)}`);
|
|
220
|
+
const closed = Date.parse(head.lastModified);
|
|
221
|
+
if (!Number.isFinite(closed) || closed > at) continue;
|
|
222
|
+
return { version: String(row.id), label: row.label ?? null, closedAt: head.lastModified, publishedAt };
|
|
223
|
+
}
|
|
224
|
+
const next = body.pagination?.next_page;
|
|
225
|
+
path = next ? next.slice(next.indexOf("/files/")) : null;
|
|
226
|
+
}
|
|
227
|
+
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);
|
|
228
|
+
}
|
|
229
|
+
|
|
166
230
|
/** Read one Surface set at a file version and trim it to what the generator reads. */
|
|
167
231
|
export async function fetchSurfaceTree(figmaGet, row, { index, version }) {
|
|
168
232
|
const nodeId = index.get(row.componentSetKey);
|
|
@@ -600,7 +664,10 @@ function colour(prefix, paint, scope, ds, report) {
|
|
|
600
664
|
|
|
601
665
|
/** Text with both DS bindings: listed, but not counted against a Surface being clean. */
|
|
602
666
|
const BOUND_TEXT = "bound-text";
|
|
603
|
-
|
|
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));
|
|
604
671
|
|
|
605
672
|
/** DS parts whose text should be a component property, not slot content (the Q-211 Lock-Change). */
|
|
606
673
|
const TEXT_PROPERTY_PARTS = new Set(["Table cell", "Table Header", "File Viewer"]);
|
|
@@ -634,7 +701,8 @@ function emitNode(node, ctx) {
|
|
|
634
701
|
return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
|
|
635
702
|
}
|
|
636
703
|
const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
|
|
637
|
-
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);
|
|
638
706
|
return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
|
|
639
707
|
};
|
|
640
708
|
const rendered = dsNode ? ds.renderer.renderInstance(ds.dsFileKey, dsNode, values, { slot: slotContent, nested }) : null;
|
|
@@ -646,6 +714,9 @@ function emitNode(node, ctx) {
|
|
|
646
714
|
ctx.imports.push(...rendered.imports);
|
|
647
715
|
const sizing = ctx.bare ? [] : sizeClasses(node, parent, false);
|
|
648
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`);
|
|
649
720
|
if (!sizing.length) return indent(code, depth);
|
|
650
721
|
// Layout around a DS component is the page's; the component itself takes no className (U07-19).
|
|
651
722
|
return [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, depth), indent(code, depth + 1), indent("</div>", depth)].join("\n");
|
|
@@ -694,12 +765,69 @@ function emitNode(node, ctx) {
|
|
|
694
765
|
return indent(comment(`unmapped: ${node.type.toLowerCase()} ${JSON.stringify(node.name)} has no auto layout`), depth);
|
|
695
766
|
}
|
|
696
767
|
const classes = cls([...sizeClasses(node, parent, root), ...layoutClasses(node), node.clips ? "overflow-hidden" : null]);
|
|
697
|
-
const kids = (node.children ?? []
|
|
768
|
+
const kids = emitChildren(node.children ?? [], child, { ...ctx, depth: depth + 1, parent: node, path, root: false });
|
|
698
769
|
const open = `<div${classes ? ` className="${classes}"` : ""}`;
|
|
699
770
|
if (!kids.length) return indent(`${open} />`, depth);
|
|
700
771
|
return [indent(`${open}>`, depth), ...kids, indent("</div>", depth)].join("\n");
|
|
701
772
|
}
|
|
702
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
|
+
|
|
703
831
|
/**
|
|
704
832
|
* A table a Surface draws as frames: rows of Table-part instances (what the
|
|
705
833
|
* templates emit as TableHead or TableCell). Those parts are valid only inside
|
|
@@ -733,11 +861,13 @@ function withWidth(code, w) {
|
|
|
733
861
|
}
|
|
734
862
|
function tableOf(node, ctx) {
|
|
735
863
|
const shown = (node.children ?? []).filter((c) => c.visible !== false);
|
|
736
|
-
//
|
|
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";
|
|
737
867
|
let end = shown.length;
|
|
738
|
-
while (end > 0 && shown[end - 1]
|
|
739
|
-
|
|
740
|
-
|
|
868
|
+
while (end > 0 && !isRow(shown[end - 1])) end -= 1;
|
|
869
|
+
let rows = shown.slice(0, end);
|
|
870
|
+
let after = shown.slice(end);
|
|
741
871
|
if (!rows.length || rows.some((r) => r.instance?.remote || r.type === "TEXT" || r.layout?.mode !== "HORIZONTAL")) return null;
|
|
742
872
|
const imports = [];
|
|
743
873
|
const parsed = [];
|
|
@@ -747,7 +877,7 @@ function tableOf(node, ctx) {
|
|
|
747
877
|
for (const cell of (row.children ?? []).filter((c) => c.visible !== false)) {
|
|
748
878
|
if (cell.instance?.remote) {
|
|
749
879
|
const local = [];
|
|
750
|
-
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: () => {} });
|
|
751
881
|
const part = tablePart(/^<([A-Za-z]+)/.exec(code ?? "")?.[1]);
|
|
752
882
|
// A cell that is no Table part (a component with no template, or a DS part drawn
|
|
753
883
|
// in a row) is held in a TableCell: one such cell must not undo the whole table.
|
|
@@ -756,19 +886,39 @@ function tableOf(node, ctx) {
|
|
|
756
886
|
cells.push({ cell, code, held: true });
|
|
757
887
|
continue;
|
|
758
888
|
}
|
|
759
|
-
|
|
760
|
-
|
|
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;
|
|
761
892
|
imports.push(...local);
|
|
762
893
|
cells.push({ cell, code });
|
|
763
894
|
} else if (cell.layout || cell.type === "TEXT") cells.push({ cell, code: null });
|
|
764
895
|
else return null;
|
|
765
896
|
}
|
|
766
|
-
|
|
767
|
-
|
|
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";
|
|
768
917
|
}
|
|
769
918
|
const module = imports.map((s) => /\{[^}]*\bTable[A-Za-z]*(Cell|Head)\b[^}]*\}\s+from\s+["']([^"']+)["']/.exec(s)?.[2]).find(Boolean);
|
|
770
919
|
if (!module) return null;
|
|
771
|
-
|
|
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)`);
|
|
772
922
|
ctx.imports.push(...imports, `import { Table, TableBody, TableHeader, TableRow } from "${module}";`);
|
|
773
923
|
const { depth } = ctx;
|
|
774
924
|
// A cell the generator wraps has no template to say its density, so it takes the one
|
|
@@ -782,15 +932,15 @@ function tableOf(node, ctx) {
|
|
|
782
932
|
const cellCode = ({ cell, code, held }, row, d) => {
|
|
783
933
|
const w = columnWidth(cell);
|
|
784
934
|
if (held) {
|
|
785
|
-
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 });
|
|
786
936
|
return [indent(`<TableCell${wrapperAttrs(w, row)}>`, d), inner, indent("</TableCell>", d)].join("\n");
|
|
787
937
|
}
|
|
788
938
|
if (code) {
|
|
789
939
|
// Re-emit for real, so the cell's own unmapped layers are reported.
|
|
790
|
-
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);
|
|
791
941
|
}
|
|
792
942
|
// The frame stood in for the cell: its size and padding are the TableCell's now.
|
|
793
|
-
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 });
|
|
794
944
|
return [indent(`<TableCell${wrapperAttrs(w, row)}>`, d), inner, indent("</TableCell>", d)].join("\n");
|
|
795
945
|
};
|
|
796
946
|
// Every column held at px or fill is a fixed table layout; a hug column needs the browser's auto layout.
|
|
@@ -807,7 +957,7 @@ function tableOf(node, ctx) {
|
|
|
807
957
|
};
|
|
808
958
|
const sizing = sizeClasses(node, ctx.parent, ctx.root);
|
|
809
959
|
const table = [indent(fixed ? '<Table layout="fixed">' : "<Table>", depth), ...section("head", "TableHeader"), ...section("body", "TableBody"), indent("</Table>", depth)];
|
|
810
|
-
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);
|
|
811
961
|
if (!sizing.length && !following.length) return table.join("\n");
|
|
812
962
|
const lines = [...table, ...following.flatMap((code) => code.split("\n"))];
|
|
813
963
|
return [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, depth), ...lines.map((line) => indent(line, 1)), indent("</div>", depth)].join("\n");
|
|
@@ -817,15 +967,6 @@ function tableOf(node, ctx) {
|
|
|
817
967
|
// The command
|
|
818
968
|
// ---------------------------------------------------------------------------
|
|
819
969
|
|
|
820
|
-
/** The Figma version to read: --figma-version, the committed tree's, or the Surface reference's pin. */
|
|
821
|
-
function pinnedVersion(root, row, flag) {
|
|
822
|
-
if (flag && flag !== true) return String(flag);
|
|
823
|
-
const path = treePath(root, row);
|
|
824
|
-
if (existsSync(path)) return readJson(path).figmaVersion ?? null;
|
|
825
|
-
const reference = existsSync(join(root, SURFACE_REFERENCE)) ? readJson(join(root, SURFACE_REFERENCE)) : null;
|
|
826
|
-
return reference?.files?.[row.fileKey]?.figmaVersion ?? null;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
970
|
function figmaTokenFrom(env) {
|
|
830
971
|
const token = env.FIGMA_PAT || env.FIGMA_TOKEN;
|
|
831
972
|
if (!token) throw new CliError("FIGMA_TOKEN_REQUIRED", "--fetch reads the Surface from Figma's REST API: set FIGMA_PAT to a token that can read the Surfaces file.", 2);
|
|
@@ -848,7 +989,7 @@ export function unmappedMarkdown(files) {
|
|
|
848
989
|
const lines = [
|
|
849
990
|
"# Surface layers with no Code Connect mapping (U08-14)",
|
|
850
991
|
"",
|
|
851
|
-
"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).",
|
|
852
993
|
"",
|
|
853
994
|
];
|
|
854
995
|
for (const [fileKey, file] of Object.entries(files)) {
|
|
@@ -874,7 +1015,7 @@ export function surfaceScoreboard(selected, results, { unpublished = [], notGene
|
|
|
874
1015
|
const modules = new Map();
|
|
875
1016
|
const of = (row) => {
|
|
876
1017
|
const name = moduleOf(row);
|
|
877
|
-
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: [] });
|
|
878
1019
|
return modules.get(name);
|
|
879
1020
|
};
|
|
880
1021
|
for (const row of selected) of(row).total += 1;
|
|
@@ -885,7 +1026,8 @@ export function surfaceScoreboard(selected, results, { unpublished = [], notGene
|
|
|
885
1026
|
const real = counted(r.unmapped);
|
|
886
1027
|
if (!real.length) entry.clean += 1;
|
|
887
1028
|
entry.unmapped += real.length;
|
|
888
|
-
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;
|
|
889
1031
|
for (const u of real) entry.byKind[u.kind] = (entry.byKind[u.kind] ?? 0) + 1;
|
|
890
1032
|
}
|
|
891
1033
|
return [...modules.values()];
|
|
@@ -910,11 +1052,11 @@ export function scoreboardMarkdown(board, { mode, source, stopped = null }) {
|
|
|
910
1052
|
`**Surface scoreboard** (\`surface generate\`, ${mode} run, \`@nodii/dev\` ${VERSION}, ${source}).`,
|
|
911
1053
|
"",
|
|
912
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.`, ""] : []),
|
|
913
|
-
"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.",
|
|
914
1056
|
"",
|
|
915
|
-
"| Module | Clean / total | Not published | Not generated yet | Unmapped | By kind |",
|
|
916
|
-
"
|
|
917
|
-
...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} |`),
|
|
918
1060
|
];
|
|
919
1061
|
const skipped = board.filter((m) => m.unpublished.length);
|
|
920
1062
|
if (skipped.length) lines.push("", "**Not published, so not generated or scored:**", ...skipped.map((m) => `- ${m.module}: ${namesText(m.unpublished)}`));
|
|
@@ -966,23 +1108,38 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
966
1108
|
renameSync(`${path}.tmp`, path);
|
|
967
1109
|
};
|
|
968
1110
|
const figmaVersion = f["figma-version"] && f["figma-version"] !== true ? String(f["figma-version"]) : null;
|
|
1111
|
+
// --figma-version names a version outright; otherwise each file is read at its last library publish.
|
|
1112
|
+
// The library read that finds the publish also gives the set index, so it is one read per file.
|
|
1113
|
+
const versions = new Map();
|
|
1114
|
+
const versionFor = async (fileKey) => {
|
|
1115
|
+
if (figmaVersion) return figmaVersion;
|
|
1116
|
+
if (!versions.has(fileKey)) {
|
|
1117
|
+
const library = await fetchLibrary(figmaGet, fileKey);
|
|
1118
|
+
indexes.set(fileKey, new Map(library.component_sets.map((x) => [x.key, x.node_id])));
|
|
1119
|
+
const pin = await lastPublishedVersion(figmaGet, fileKey, { library });
|
|
1120
|
+
log(`${fileKey}: last library publish ${pin.publishedAt} closed version ${pin.version} at ${pin.closedAt}${pin.label ? ` ("${pin.label}")` : " (unlabelled)"}`);
|
|
1121
|
+
versions.set(fileKey, pin.version);
|
|
1122
|
+
}
|
|
1123
|
+
return versions.get(fileKey);
|
|
1124
|
+
};
|
|
969
1125
|
let stopped = null;
|
|
970
1126
|
let kept = 0;
|
|
971
1127
|
for (const row of targets) {
|
|
972
1128
|
const path = treePath(root, row);
|
|
973
1129
|
if (f.fetch) {
|
|
974
|
-
if (f.resume && existsSync(path)) {
|
|
975
|
-
const saved = readJson(path);
|
|
976
|
-
if (!figmaVersion || saved.figmaVersion === figmaVersion) {
|
|
977
|
-
log(`keeping ${row.componentSetName ?? row.id}: read at version ${saved.figmaVersion ?? "unknown"}`);
|
|
978
|
-
trees.set(row, saved);
|
|
979
|
-
kept += 1;
|
|
980
|
-
continue;
|
|
981
|
-
}
|
|
982
|
-
}
|
|
983
1130
|
figmaGet ??= pacedFigma(figmaTokenFrom(env), { log });
|
|
984
1131
|
let tree;
|
|
985
1132
|
try {
|
|
1133
|
+
const version = await versionFor(row.fileKey);
|
|
1134
|
+
if (f.resume && existsSync(path)) {
|
|
1135
|
+
const saved = readJson(path);
|
|
1136
|
+
if (saved.figmaVersion === version) {
|
|
1137
|
+
log(`keeping ${row.componentSetName ?? row.id}: read at version ${version}`);
|
|
1138
|
+
trees.set(row, saved);
|
|
1139
|
+
kept += 1;
|
|
1140
|
+
continue;
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
986
1143
|
if (!indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
987
1144
|
// --all covers a module: one unpublished Surface is reported, and the rest still generate.
|
|
988
1145
|
// A Surface named on its own stays a refusal, because the run has nothing else to do.
|
|
@@ -991,8 +1148,8 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
991
1148
|
unpublished.push(row);
|
|
992
1149
|
continue;
|
|
993
1150
|
}
|
|
994
|
-
log(`reading ${row.componentSetName ?? row.id} from Figma`);
|
|
995
|
-
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version
|
|
1151
|
+
log(`reading ${row.componentSetName ?? row.id} from Figma at version ${version}`);
|
|
1152
|
+
tree = await fetchSurfaceTree(figmaGet, row, { index: indexes.get(row.fileKey), version });
|
|
996
1153
|
} catch (error) {
|
|
997
1154
|
// --all keeps what it read and scores it; a Surface named on its own has nothing to keep.
|
|
998
1155
|
if (!f.all || error?.code !== "FIGMA_RATE_LIMITED") throw error;
|