@nodii/dev 0.6.153 → 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 +15 -0
- package/dist/core.js +1 -1
- package/dist/surface.js +94 -7
- package/package.json +1 -1
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.
|
|
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 =
|
|
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). */
|
|
@@ -977,6 +977,12 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
977
977
|
return `<Badge${toned}>{${lift(at, "label")}}</Badge>`;
|
|
978
978
|
});
|
|
979
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
|
+
});
|
|
980
986
|
// Every Checkbox and Switch is controlled by the page and named by the text beside it
|
|
981
987
|
// (`pfChecked`, `onPfCheckedChange`): Figma's tick is the sample, never a default, and the
|
|
982
988
|
// template's own `checked` / `onCheckedChange` (DESIGN-SYSTEM-508) never shared (hub-468).
|
|
@@ -1755,12 +1761,20 @@ function dataProps(views, propsType) {
|
|
|
1755
1761
|
entry(o.list).list = true;
|
|
1756
1762
|
view.uses.add(o.list);
|
|
1757
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
|
+
}
|
|
1758
1768
|
const itemList = (at, name) => (openers.some((o) => o.param === name) ? listAt(openers, at, name) : null);
|
|
1759
|
-
|
|
1760
|
-
|
|
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");
|
|
1761
1772
|
if (!list) continue;
|
|
1762
|
-
|
|
1763
|
-
|
|
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);
|
|
1764
1778
|
}
|
|
1765
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)) {
|
|
1766
1780
|
const [, by, key, dir, change] = m;
|
|
@@ -2255,7 +2269,7 @@ function emitNode(node, ctx) {
|
|
|
2255
2269
|
return indent(comment(`unmapped: ${node.type.toLowerCase()} ${JSON.stringify(node.name)}`), depth);
|
|
2256
2270
|
}
|
|
2257
2271
|
|
|
2258
|
-
const table = tableOf(node, { ...ctx, path });
|
|
2272
|
+
const table = treeTableOf(node, { ...ctx, path }) ?? tableOf(node, { ...ctx, path });
|
|
2259
2273
|
if (table) return table;
|
|
2260
2274
|
|
|
2261
2275
|
// A frame, group, local component instance or slot: its layout only. A fill,
|
|
@@ -2562,6 +2576,77 @@ const HEAD_PLACEHOLDER_CHILD = /(<Table(?:Sort)?Head\b[^\n]*>\s*)\{"\s*[Tt]able
|
|
|
2562
2576
|
/** A head whose copy is a figure (a year, "Zone 2"): the record's, lifted as its column's heading (hub-468). */
|
|
2563
2577
|
const HEAD_FIGURE_CHILD = /(<Table(?:Sort)?Head\b[^\n]*>\s*)\{"(?:[^"\\\n]|\\.)*\d(?:[^"\\\n]|\\.)*"\}/;
|
|
2564
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
|
+
|
|
2565
2650
|
function tableOf(node, ctx) {
|
|
2566
2651
|
const shown = (node.children ?? []).filter((c) => c.visible !== false);
|
|
2567
2652
|
// What follows the rows (a table's Empty State, bare or in its own frame) follows the Table:
|
|
@@ -2751,6 +2836,8 @@ function tableOf(node, ctx) {
|
|
|
2751
2836
|
const rowsName = mark(ctx, listName, "rows", null);
|
|
2752
2837
|
// A row is a door to its record when the page passes a handler (U03-7; NODII-DEV-CLI-83).
|
|
2753
2838
|
const rowClick = mark(ctx, listName, "onRowClick", null);
|
|
2839
|
+
const inert = mark(ctx, listName, "isRowInert", null);
|
|
2840
|
+
const getClick = mark(ctx, listName, "getRowOnClick", null);
|
|
2754
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)`);
|
|
2755
2842
|
// A column whose every body cell is a PiiText is a person's value: its row field is the
|
|
2756
2843
|
// served pair and the cell draws PiiText from it, never a node the page could fill with a
|
|
@@ -2790,7 +2877,7 @@ function tableOf(node, ctx) {
|
|
|
2790
2877
|
});
|
|
2791
2878
|
return [
|
|
2792
2879
|
indent(`{${rowsName}.map((row) => (`, depth + 2),
|
|
2793
|
-
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),
|
|
2794
2881
|
...cells,
|
|
2795
2882
|
indent("</TableRow>", depth + 3),
|
|
2796
2883
|
indent("))}", depth + 2),
|