@nodii/dev 0.6.152 → 0.6.154

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
@@ -977,6 +977,21 @@ product-page catalog names the Surface by its published component-set key
977
977
  each head and cell declares its column `width` as Figma sizes it (px for
978
978
  FIXED, `"fill"`, `"hug"`; DESIGN-SYSTEM-177) unless its template already
979
979
  does. A table with no hug column gets `layout="fixed"`.
980
+ - Generated tables accept optional `isRowInert(row)` and `getRowOnClick(row)`
981
+ bindings (hub-492). Inert rows receive no click handler. When supplied,
982
+ `getRowOnClick` owns the choice for each row: returning `undefined` leaves
983
+ that row noninteractive. Otherwise the existing `onRowClick(row)` applies.
984
+ Multiple tables have separate bindings named by their list scopes.
985
+ - A table drawn with published `TableTreeBranchRow` and `TableTreeLeafRow`
986
+ instances becomes a DS `Table` with `role="treegrid"`. Both row kinds must
987
+ be drawn, with matching column counts and a consistent template per kind.
988
+ Its `rows` data carries `kind` (`"branch"` or `"leaf"`), `depth`, the template's
989
+ data slots, and controlled `expanded` / `onExpandedChange` bindings. Supply
990
+ visible rows in preorder, removing descendants when a branch collapses.
991
+ The same per-row navigation bindings apply. Character indentation in plain
992
+ cells does not declare hierarchy; change the Surface to published tree rows
993
+ before regenerating it. A standalone branch also receives controlled
994
+ expansion bindings instead of its drawn literal expansion value.
980
995
  - Loose text takes the DS type utility and colour v2 role, and nothing else.
981
996
  A frame that paints its own fill, stroke, radius or effect keeps only its
982
997
  layout. A shape, or a library instance with no template, is a marked gap in
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.152";
7
+ export const VERSION = "0.6.154";
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 = 18;
35
+ export const GENERATOR_FORMAT = 19;
36
36
  export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
37
37
  export const GENERATED_SUFFIX = ".surface.generated.tsx";
38
38
  /** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
@@ -564,12 +564,13 @@ export function emitSurface(tree, row, ds) {
564
564
  if (emitted.trimStart().startsWith("{/*")) {
565
565
  throw new CliError("SURFACE_VIEW_NOT_LAID_OUT", `${row.id}: view ${JSON.stringify(variant.name)} has no auto layout, so it would generate as an empty page; give the variant (or the App Frame's mainContent) auto layout in Figma, publish, and refetch`, 1);
566
566
  }
567
- return { state, fn, body: emitted };
567
+ return { state, fn, body: emitted, variant: variant.name };
568
568
  });
569
569
  const component = `${pascal(row.id)}Surface`;
570
570
  const stateType = `${component}State`;
571
571
  const propsType = `${component}Props`;
572
572
  const named = resolveScopes(views, scopes, layers);
573
+ settlePiiColumns(views, unmapped);
573
574
  const data = dataProps(views, propsType);
574
575
  // A prop is optional when every template that draws it lists it in `metadata.optionalProps`.
575
576
  const optionalNames = new Map();
@@ -976,6 +977,12 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
976
977
  return `<Badge${toned}>{${lift(at, "label")}}</Badge>`;
977
978
  });
978
979
  }
980
+ // hub-492: the page owns disclosure state, not the drawn Expansion variant.
981
+ out = rewriteTags(out, "TableTreeBranchRow", (attrs) => {
982
+ let next = attrs.replace(/\bexpanded=\{(?:true|false)\}/, () => `expanded={${lift(scope, "expanded")}}`);
983
+ if (!/\bonExpandedChange=/.test(next)) next = next.replace(/(expanded=\{[^}]+\})/, `$1 onExpandedChange={${optionalMark(ctx, scope, "onExpandedChange")}}`);
984
+ return next;
985
+ });
979
986
  // Every Checkbox and Switch is controlled by the page and named by the text beside it
980
987
  // (`pfChecked`, `onPfCheckedChange`): Figma's tick is the sample, never a default, and the
981
988
  // template's own `checked` / `onCheckedChange` (DESIGN-SYSTEM-508) never shared (hub-468).
@@ -1754,12 +1761,20 @@ function dataProps(views, propsType) {
1754
1761
  entry(o.list).list = true;
1755
1762
  view.uses.add(o.list);
1756
1763
  }
1764
+ for (const m of body.matchAll(/row\.kind === "branch"/g)) {
1765
+ const list = listAt(openers, m.index, "row");
1766
+ if (list) member(entry(list), "kind").set("\u0000kind", { raw: '"branch" | "leaf"' });
1767
+ }
1757
1768
  const itemList = (at, name) => (openers.some((o) => o.param === name) ? listAt(openers, at, name) : null);
1758
- for (const m of body.matchAll(/onClick=\{([a-z][A-Za-z0-9]*) && \(\(\) => \1\(([a-z][A-Za-z0-9]*)\)\)\}/g)) {
1759
- const list = listAt(openers, m.index, m[2]);
1769
+ // hub-492: absence of a handler keeps an inert row noninteractive.
1770
+ for (const m of body.matchAll(/onClick=\{([a-z][A-Za-z0-9]*)\?\.\(row\) \? undefined : ([a-z][A-Za-z0-9]*) \? \2\(row\) : ([a-z][A-Za-z0-9]*) && /g)) {
1771
+ const list = listAt(openers, m.index, "row");
1760
1772
  if (!list) continue;
1761
- own(m[1], `(row: ${propsType}[${JSON.stringify(list)}][number]) => void`);
1762
- view.uses.add(m[1]);
1773
+ const item = `${propsType}[${JSON.stringify(list)}][number]`;
1774
+ own(m[1], `(row: ${item}) => boolean`);
1775
+ own(m[2], `(row: ${item}) => (() => void) | undefined`);
1776
+ own(m[3], `(row: ${item}) => void`);
1777
+ for (const name of m.slice(1)) view.uses.add(name);
1763
1778
  }
1764
1779
  for (const m of body.matchAll(/\bsort=\{([a-z][A-Za-z0-9]*) === ("(?:[^"\\\n]|\\.)*") \? ([a-z][A-Za-z0-9]*) : false\} onSort=\{([a-z][A-Za-z0-9]*) && /g)) {
1765
1780
  const [, by, key, dir, change] = m;
@@ -1795,6 +1810,11 @@ function dataProps(views, propsType) {
1795
1810
  const list = itemList(m.index, m[2]);
1796
1811
  if (list) member(entry(list), m[3]).set("\u0000child", { raw: "ReactNode" });
1797
1812
  }
1813
+ // A lifted row's PII column is PiiText's served pair (cli-140).
1814
+ for (const m of body.matchAll(PII_ROW_READ)) {
1815
+ const list = itemList(m.index, m[1]);
1816
+ if (list) member(entry(list), m[2]).set("\u0000pii", { raw: PII_ROW_FIELD });
1817
+ }
1798
1818
  for (const m of body.matchAll(/(^|>)\s*\{([a-z][A-Za-z0-9]*)\}/gm)) {
1799
1819
  if (JS_LITERALS.has(m[2])) continue;
1800
1820
  entry(m[2]).child = true;
@@ -2249,7 +2269,7 @@ function emitNode(node, ctx) {
2249
2269
  return indent(comment(`unmapped: ${node.type.toLowerCase()} ${JSON.stringify(node.name)}`), depth);
2250
2270
  }
2251
2271
 
2252
- const table = tableOf(node, { ...ctx, path });
2272
+ const table = treeTableOf(node, { ...ctx, path }) ?? tableOf(node, { ...ctx, path });
2253
2273
  if (table) return table;
2254
2274
 
2255
2275
  // A frame, group, local component instance or slot: its layout only. A fill,
@@ -2426,6 +2446,69 @@ function tabStrip(run, ctx) {
2426
2446
  ].join("\n");
2427
2447
  }
2428
2448
 
2449
+ /**
2450
+ * A lifted row's PII field: PiiText's served pair, as the page's own PiiText takes it
2451
+ * (`value`, `model`, `relation`, and the server's `maskHint` when it sent one). Nothing else of
2452
+ * PiiText's is offered, so a row can never force a value visible (U05; cli-140).
2453
+ */
2454
+ const PII_KINDS = new Set(["name", "email", "phone", "address", "dob", "document", "text"]);
2455
+ const PII_ROW_FIELD = `{ ${["maskHint?", "model", "relation", "value"].map((k) => `${k}: ComponentProps<typeof PiiText>[${JSON.stringify(k.replace("?", ""))}]`).join("; ")} }`;
2456
+ const PII_ROW_READ = /<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\.value\} kind="/g;
2457
+
2458
+ /**
2459
+ * One list's rows are one type across the views and tables that share it. A column that is
2460
+ * PiiText in one of them and a node in another (two tables whose heads still show Figma's
2461
+ * placeholder, so both are `column1`) can be neither: it stays a node everywhere, as before
2462
+ * cli-140, and the report names it.
2463
+ */
2464
+ function settlePiiColumns(views, unmapped) {
2465
+ const NODE_READ = /(^|>)\s*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\}/gm;
2466
+ const PII_CELL = />\n[ \t]*<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\.value\} kind="[^\n]*\/>\n[ \t]*<\/TableCell>/g;
2467
+ const reads = new Map();
2468
+ const count = (view, openers, at, param, key, how) => {
2469
+ const list = listAt(openers, at, param);
2470
+ if (!list) return;
2471
+ const id = `${list}.${key}`;
2472
+ const r = reads.get(id) ?? reads.set(id, { list, key, pii: 0, node: 0, variant: view.variant }).get(id);
2473
+ r[how]++;
2474
+ };
2475
+ for (const view of views) {
2476
+ const openers = listOpeners(view.body);
2477
+ for (const m of view.body.matchAll(PII_ROW_READ)) count(view, openers, m.index, m[1], m[2], "pii");
2478
+ for (const m of view.body.matchAll(NODE_READ)) count(view, openers, m.index, m[2], m[3], "node");
2479
+ }
2480
+ const mixed = new Map([...reads].filter(([, r]) => r.pii && r.node));
2481
+ if (!mixed.size) return;
2482
+ for (const view of views) {
2483
+ const openers = listOpeners(view.body);
2484
+ view.body = view.body.replace(PII_CELL, (all, param, key, at) => (mixed.has(`${listAt(openers, at, param)}.${key}`) ? `>{${param}.${key}}</TableCell>` : all));
2485
+ }
2486
+ for (const r of mixed.values()) {
2487
+ unmapped.push({ variant: r.variant, path: r.list, kind: LIFTED, detail: `column ${r.key} of ${r.list} is PiiText in ${r.pii} of the ${r.pii + r.node} tables that share its rows: it stays a ReactNode, and the page must draw its people through PiiText itself (U05; cli-140)` });
2488
+ }
2489
+ }
2490
+
2491
+ /** The attributes of the PiiText a body cell's template draws as its whole content (Table cell, Content=PII); null for any other cell. */
2492
+ function piiCellAttrs({ code, held }) {
2493
+ const own = (code ?? "").trim();
2494
+ if (held || !/^<TableCell\b/.test(own)) return null;
2495
+ const inner = own.slice(openTagEnd(own) + 1).replace(/<\/TableCell>$/, "").trim();
2496
+ return /^<PiiText\b([^<>]*?)\s*\/>$/.exec(inner)?.[1] ?? null;
2497
+ }
2498
+
2499
+ function piiTreeKind(cell) {
2500
+ const exposed = Object.entries(cell.instance?.exposed ?? {}).find(([name]) => name.toLowerCase() === "piitext")?.[1];
2501
+ return exposed?.props?.kind;
2502
+ }
2503
+
2504
+ /** That cell's PiiText, reading the served pair at `ref` (`row.employee`), with the kind the tree states for it. */
2505
+ function piiCellText({ cell, code }, ref) {
2506
+ const attrs = piiCellAttrs({ code }) ?? "";
2507
+ const kind = piiTreeKind(cell);
2508
+ const size = /\ssize="\w+"/.exec(attrs)?.[0] ?? "";
2509
+ return `<PiiText value={${ref}.value} kind="${kind}" model={${ref}.model} relation={${ref}.relation} maskHint={${ref}.maskHint}${size} />`;
2510
+ }
2511
+
2429
2512
  /**
2430
2513
  * A table a Surface draws as frames: rows of Table-part instances (what the
2431
2514
  * templates emit as TableHead or TableCell). Those parts are valid only inside
@@ -2493,6 +2576,77 @@ const HEAD_PLACEHOLDER_CHILD = /(<Table(?:Sort)?Head\b[^\n]*>\s*)\{"\s*[Tt]able
2493
2576
  /** A head whose copy is a figure (a year, "Zone 2"): the record's, lifted as its column's heading (hub-468). */
2494
2577
  const HEAD_FIGURE_CHILD = /(<Table(?:Sort)?Head\b[^\n]*>\s*)\{"(?:[^"\\\n]|\\.)*\d(?:[^"\\\n]|\\.)*"\}/;
2495
2578
 
2579
+ // hub-492: only published tree-row instances declare hierarchy. The caller supplies
2580
+ // the visible preorder rows, so collapsing a branch removes its descendants.
2581
+ function treeTableOf(node, ctx) {
2582
+ const shown = (node.children ?? []).filter((c) => c.visible !== false);
2583
+ const rendered = shown.map((child) => {
2584
+ if (!child.instance?.remote) return null;
2585
+ const imports = [];
2586
+ const code = emitNode(child, { ...ctx, depth: 0, parent: null, root: false, bare: true, inTable: true, scopes: null, imports, note: () => {} });
2587
+ const tag = /^<(TableTree(?:Branch|Leaf)Row)\b/.exec(code ?? "")?.[1];
2588
+ return tag ? { child, code, tag, imports } : null;
2589
+ });
2590
+ const first = rendered.findIndex(Boolean);
2591
+ if (first < 0 || rendered.slice(first).some((r) => !r)) return null;
2592
+ const branches = rendered.filter((r) => r?.tag === "TableTreeBranchRow");
2593
+ const leaves = rendered.filter((r) => r?.tag === "TableTreeLeafRow");
2594
+ // Both shapes must be drawn: never invent a missing DS row or its cells.
2595
+ if (!branches.length || !leaves.length) return null;
2596
+ const shape = (r) => r.code.replace(/\bdepth=\{[^}]+\}/, "depth={depth}");
2597
+ if ([branches, leaves].some((group) => group.some((r) => shape(r) !== shape(group[0])))) {
2598
+ ctx.note(ctx.path, "table", "tree rows of one kind have different templates; no single row shape (hub-492)");
2599
+ return indent(comment("unmapped: differing tree-row templates"), ctx.depth);
2600
+ }
2601
+ const header = shown.slice(0, first);
2602
+ const heads = [];
2603
+ const columnCounts = [];
2604
+ for (const row of header) {
2605
+ if (row.layout?.mode !== "HORIZONTAL") return null;
2606
+ const cells = [];
2607
+ for (const cell of row.children ?? []) {
2608
+ const code = emitNode(cell, { ...ctx, depth: 0, root: false, bare: true, inTable: true });
2609
+ if (tablePart(/^<([A-Za-z]+)/.exec(code ?? "")?.[1]) !== "head") return null;
2610
+ cells.push(withWidth(code, columnWidth(cell)));
2611
+ }
2612
+ columnCounts.push(cells.length);
2613
+ heads.push(`<TableRow>${cells.join("")}</TableRow>`);
2614
+ }
2615
+ const bodyColumns = [branches[0], leaves[0]].map((r) => 1 + [...r.code.matchAll(/<Table[A-Za-z]*Cell\b/g)].length);
2616
+ if ([...columnCounts, ...bodyColumns].some((n) => n !== bodyColumns[0])) {
2617
+ ctx.note(ctx.path, "table", "tree header and row templates have different column counts (hub-492)");
2618
+ return indent(comment("unmapped: mismatched tree columns"), ctx.depth);
2619
+ }
2620
+ const module = branches[0].imports.map((s) => /\{[^}]*\bTableTreeBranchRow\b[^}]*\}\s+from\s+["']([^"']+)["']/.exec(s)?.[1]).find(Boolean);
2621
+ if (!module) return null;
2622
+ const scope = listScope(node, ctx, scopeName(node), `tree:${shape(branches[0])}:${shape(leaves[0])}`);
2623
+ const rows = mark(ctx, scope, "rows", null);
2624
+ const inert = mark(ctx, scope, "isRowInert", null);
2625
+ const getClick = mark(ctx, scope, "getRowOnClick", null);
2626
+ const click = mark(ctx, scope, "onRowClick", null);
2627
+ const emit = (sample) => {
2628
+ ctx.imports.push(...sample.imports);
2629
+ let code = sample.code.replace(/\bdepth=\{[^}]+\}/, 'depth={row.depth}');
2630
+ // The templates' data slots stay typed by the DS prop or cell they reach.
2631
+ code = code.replace(/\{([a-z][A-Za-z0-9]*)\}/g, (all, name) => JS_LITERALS.has(name) ? all : `{row.${name}}`);
2632
+ code = code.replace(`<${sample.tag}`, `<${sample.tag} key={row.id} onClick={${inert}?.(row) ? undefined : ${getClick} ? ${getClick}(row) : ${click} && (() => ${click}(row))}`);
2633
+ return code;
2634
+ };
2635
+ const branch = emit(branches[0]);
2636
+ const leaf = emit(leaves[0]);
2637
+ ctx.imports.push(`import { Table, TableBody, TableHeader, TableRow } from "${module}";`);
2638
+ ctx.note(ctx.path, LIFTED, "published branch and leaf rows lifted as visible preorder data (hub-492)");
2639
+ return indent([
2640
+ '<Table role="treegrid">',
2641
+ ...(heads.length ? [' <TableHeader>', ...heads.map((h) => indent(h, 2)), ' </TableHeader>'] : []),
2642
+ ' <TableBody>',
2643
+ ` {${rows}.map((row) => (`,
2644
+ ' row.kind === "branch" ? (', indent(branch, 4),
2645
+ ' ) : (', indent(leaf, 4), ' )',
2646
+ ' ))}', ' </TableBody>', '</Table>',
2647
+ ].join("\n"), ctx.depth);
2648
+ }
2649
+
2496
2650
  function tableOf(node, ctx) {
2497
2651
  const shown = (node.children ?? []).filter((c) => c.visible !== false);
2498
2652
  // What follows the rows (a table's Empty State, bare or in its own frame) follows the Table:
@@ -2682,7 +2836,30 @@ function tableOf(node, ctx) {
2682
2836
  const rowsName = mark(ctx, listName, "rows", null);
2683
2837
  // A row is a door to its record when the page passes a handler (U03-7; NODII-DEV-CLI-83).
2684
2838
  const rowClick = mark(ctx, listName, "onRowClick", null);
2839
+ const inert = mark(ctx, listName, "isRowInert", null);
2840
+ const getClick = mark(ctx, listName, "getRowOnClick", null);
2685
2841
  ctx.note(ctx.path, LIFTED, `${dataRows.length} body row${dataRows.length === 1 ? "" : "s"} lifted as data: rows of { id, ${keys.join(", ")} } (NODII-DEV-CLI-82)`);
2842
+ // A column whose every body cell is a PiiText is a person's value: its row field is the
2843
+ // served pair and the cell draws PiiText from it, never a node the page could fill with a
2844
+ // raw name (U05; cli-140). A column that is PiiText in only some rows stays a node, and
2845
+ // the report names it.
2846
+ const invalidPii = new Map();
2847
+ const piiColumn = keys.map((key, i) => {
2848
+ const drawn = dataRows.filter((p) => piiCellAttrs(p.cells[i]) !== null).length;
2849
+ if (drawn > 0 && drawn < dataRows.length) ctx.note(ctx.path, LIFTED, `column ${key} is PiiText in ${drawn} of ${dataRows.length} body rows: it stays a ReactNode, and the page must draw its people through PiiText itself (U05; cli-140)`);
2850
+ if (drawn === dataRows.length) {
2851
+ const kinds = dataRows.map((p) => piiTreeKind(p.cells[i].cell));
2852
+ const why = kinds.some((kind) => !PII_KINDS.has(kind))
2853
+ ? `column ${key} has no recognised PiiText kind in one or more body rows`
2854
+ : new Set(kinds).size !== 1 ? `column ${key} has incompatible PiiText kinds` : null;
2855
+ if (why) {
2856
+ ctx.note(ctx.path, "table", `${why}: left unmapped (MW8-17.3; cli-140)`);
2857
+ invalidPii.set(i, why);
2858
+ return false;
2859
+ }
2860
+ }
2861
+ return drawn === dataRows.length;
2862
+ });
2686
2863
  const cells = first.cells.map((c, i) => {
2687
2864
  const w = columnWidth(c.cell);
2688
2865
  let open = `<TableCell${wrapperAttrs(w, first.row)}>`;
@@ -2694,11 +2871,13 @@ function tableOf(node, ctx) {
2694
2871
  open = own.slice(0, end + 1).replace(/\s*\/>$/, ">");
2695
2872
  close = `</${tag}>`;
2696
2873
  }
2874
+ if (invalidPii.has(i)) return indent(`${open}${comment(`unmapped: ${invalidPii.get(i)}`)}${close}`, depth + 4);
2875
+ if (piiColumn[i]) return indent(`${open}\n ${piiCellText(c, `row.${keys[i]}`)}\n${close}`, depth + 4);
2697
2876
  return indent(`${open}{row.${keys[i]}}${close}`, depth + 4);
2698
2877
  });
2699
2878
  return [
2700
2879
  indent(`{${rowsName}.map((row) => (`, depth + 2),
2701
- indent(`<TableRow key={row.id} onClick={${rowClick} && (() => ${rowClick}(row))}>`, depth + 3),
2880
+ indent(`<TableRow key={row.id} onClick={${inert}?.(row) ? undefined : ${getClick} ? ${getClick}(row) : ${rowClick} && (() => ${rowClick}(row))}>`, depth + 3),
2702
2881
  ...cells,
2703
2882
  indent("</TableRow>", depth + 3),
2704
2883
  indent("))}", depth + 2),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.152",
3
+ "version": "0.6.154",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {