@nodii/dev 0.6.113 → 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 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
- - **Table assembly.** A table drawn as frames goes in the DS `Table`'s anatomy. A
938
- cell that is no Table part is held in a `TableCell`, and a wrapped cell takes its
939
- row's density.
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/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.113";
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
@@ -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 = 6;
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
- const counted = (unmapped) => unmapped.filter((u) => u.kind !== BOUND_TEXT);
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 inner = (slotNode?.children ?? []).map((c) => emitNode(c, { ...ctx, depth: 0, parent: slotNode, path: `${path} › ${prop}`, root: false, textOwner })).filter((x) => x !== null);
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 ?? []).map(child).filter((x) => x !== null);
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
- // A DS instance after the rows (a table's Empty State) follows the Table: it must not undo it.
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].instance?.remote) end -= 1;
803
- const rows = shown.slice(0, end);
804
- const after = shown.slice(end);
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
- if (kind && kind !== part) return null;
824
- kind = part;
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
- if (!kind) return null;
831
- parsed.push({ row, kind, cells });
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
- ctx.note(ctx.path, "table", `table drawn as frames (${rows.length} row${rows.length === 1 ? "" : "s"}); assembled into the DS Table's parts`);
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 table drawn as frames, assembled into the DS Table's parts), `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).",
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.length - real.length;
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 is listed in the report, and is not counted here. Total counts every selected Surface, including those not published or not generated yet.",
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)}`));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.113",
3
+ "version": "0.6.114",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {