@nodii/dev 0.6.154 → 0.6.155
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/dist/core.js +1 -1
- package/dist/surface.js +107 -13
- package/package.json +1 -1
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.155";
|
|
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 = 21;
|
|
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). */
|
|
@@ -306,7 +306,7 @@ export function trimTree(entry, { row, version }) {
|
|
|
306
306
|
const styles = entry.styles ?? {};
|
|
307
307
|
const keyOf = (componentId) => components[componentId]?.key ?? null;
|
|
308
308
|
|
|
309
|
-
const trim = (node, parentBox) => {
|
|
309
|
+
const trim = (node, parentBox, slotOwner = null) => {
|
|
310
310
|
const out = { type: node.type, name: node.name };
|
|
311
311
|
if (node.visible === false) return { ...out, visible: false };
|
|
312
312
|
const box = node.absoluteBoundingBox;
|
|
@@ -360,6 +360,19 @@ export function trimTree(entry, { row, version }) {
|
|
|
360
360
|
const effects = (node.effects ?? []).filter((e) => e.visible !== false);
|
|
361
361
|
if (effects.length) out.effects = styles[node.styles?.effect]?.name ?? effects.map((e) => e.type).join(",");
|
|
362
362
|
|
|
363
|
+
// A remote component owns its slot container's unmodified paint. Keep the
|
|
364
|
+
// observed values, but distinguish them from Surface-owned overrides. Missing
|
|
365
|
+
// REST provenance stays conservative; the exemption never reaches slot content.
|
|
366
|
+
if (node.type === "SLOT" && Array.isArray(slotOwner?.overrides)) {
|
|
367
|
+
const fields = new Set(slotOwner.overrides.filter(o => o.id === node.id).flatMap(o => o.overriddenFields ?? []));
|
|
368
|
+
if (!fields.has("boundVariables") && !fields.has("styles")) {
|
|
369
|
+
const inherited = Object.entries({ fills: ["fills", "fillStyleId"], strokes: ["strokes", "strokeStyleId", "strokeWeight", "individualStrokeWeights"], radius: ["cornerRadius", "rectangleCornerRadii"], effects: ["effects", "effectStyleId"] })
|
|
370
|
+
.filter(([key, sources]) => out[key] && !sources.some(field => fields.has(field)))
|
|
371
|
+
.map(([key]) => key);
|
|
372
|
+
if (inherited.length) out.inheritedPaint = inherited;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
363
376
|
if (node.type === "INSTANCE") {
|
|
364
377
|
const main = components[node.componentId] ?? {};
|
|
365
378
|
// An instance's own layers, down to (not into) its slots, which are the Surface's.
|
|
@@ -422,7 +435,7 @@ export function trimTree(entry, { row, version }) {
|
|
|
422
435
|
}
|
|
423
436
|
};
|
|
424
437
|
const children = main.remote ? [...slotsOf(node)] : (node.children ?? []);
|
|
425
|
-
if (children.length) out.children = children.map((c) => trim(c, box));
|
|
438
|
+
if (children.length) out.children = children.map((c) => trim(c, box, main.remote ? node : null));
|
|
426
439
|
return out;
|
|
427
440
|
}
|
|
428
441
|
if (node.type === "SLOT") {
|
|
@@ -930,6 +943,24 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
930
943
|
const lifted = [];
|
|
931
944
|
const lift = (at, name) => (lifted.push(name), mark(ctx, at, name));
|
|
932
945
|
let out = liftFieldControls(code, node, ctx, lift, scope);
|
|
946
|
+
// A Tabs Group renders its triggers directly, without tabStrip's sibling assembly.
|
|
947
|
+
// Generic values use the drawn label for a useful name, but keep their routing value.
|
|
948
|
+
// Probes must retain the template's sample until tabStrip assigns each tab its value.
|
|
949
|
+
if (!ctx.tabProbe) {
|
|
950
|
+
out = rewriteTags(out, "TabsTrigger", (attrs, _tag, end) => {
|
|
951
|
+
const value = /\bvalue="([^"]*)"/.exec(attrs)?.[1];
|
|
952
|
+
const body = /\/\s*$/.test(attrs) ? "" : out.slice(end + 1, out.indexOf("</TabsTrigger>", end));
|
|
953
|
+
const label = /\{("(?:[^"\\\n]|\\.)*")\}/.exec(body);
|
|
954
|
+
const name = value && !/^tab(?:-\d+)?$/.test(value) ? camelName(value) : nameOf(label ? JSON.parse(label[1]) : "", value || "tab");
|
|
955
|
+
const own = (prop) => {
|
|
956
|
+
lifted.push(prop);
|
|
957
|
+
return `${prop}={${optionalMark(ctx, `${scope} ${value || name}`, joinName(name, prop))}}`;
|
|
958
|
+
};
|
|
959
|
+
return attrs
|
|
960
|
+
.replace(/\bactionableCount=\{(?:\d+|actionableCount)\}/, () => own("actionableCount"))
|
|
961
|
+
.replace(/\bcountIsFloor(?:=\{(?:true|false|countIsFloor)\})?(?=\s|\/|$)/, () => own("countIsFloor"));
|
|
962
|
+
});
|
|
963
|
+
}
|
|
933
964
|
// An Alert's title or description that names a record's value: a date, an amount, a code,
|
|
934
965
|
// or any figure ("running at 4.2% this period", "3 lines still carry a flag"; hub-468).
|
|
935
966
|
out = out.replace(/<(Alert(Title|Description))>(\{"(?:[^"\\\n]|\\.)*"\})<\/\1>/g, (all, tag, part, lit) =>
|
|
@@ -1813,7 +1844,11 @@ function dataProps(views, propsType) {
|
|
|
1813
1844
|
// A lifted row's PII column is PiiText's served pair (cli-140).
|
|
1814
1845
|
for (const m of body.matchAll(PII_ROW_READ)) {
|
|
1815
1846
|
const list = itemList(m.index, m[1]);
|
|
1816
|
-
if (list)
|
|
1847
|
+
if (list) {
|
|
1848
|
+
const field = member(entry(list), m[2]);
|
|
1849
|
+
const nullable = / == null \? \("(?:[^"\\]|\\.)*"\) : \($/.test(body.slice(0, m.index)) || field.get("\u0000pii")?.raw.endsWith(" | null");
|
|
1850
|
+
field.set("\u0000pii", { raw: PII_ROW_FIELD + (nullable ? " | null" : "") });
|
|
1851
|
+
}
|
|
1817
1852
|
}
|
|
1818
1853
|
for (const m of body.matchAll(/(^|>)\s*\{([a-z][A-Za-z0-9]*)\}/gm)) {
|
|
1819
1854
|
if (JS_LITERALS.has(m[2])) continue;
|
|
@@ -2275,9 +2310,10 @@ function emitNode(node, ctx) {
|
|
|
2275
2310
|
// A frame, group, local component instance or slot: its layout only. A fill,
|
|
2276
2311
|
// stroke, radius or effect it paints itself is not drawn, which would be a
|
|
2277
2312
|
// look-alike of a DS part (MW2-37.2); it is reported as a missing DS part.
|
|
2278
|
-
const
|
|
2313
|
+
const ownPaint = key => !node.inheritedPaint?.includes(key) && node[key];
|
|
2314
|
+
const painted = Boolean(ownPaint("fills")?.length || ownPaint("strokes")?.length || ownPaint("radius") || ownPaint("effects"));
|
|
2279
2315
|
if (painted)
|
|
2280
|
-
note(path, "frame", `${node.instance ? `local component ${describe(node)}` : node.type.toLowerCase()} draws its own ${[
|
|
2316
|
+
note(path, "frame", `${node.instance ? `local component ${describe(node)}` : node.type.toLowerCase()} draws its own ${[ownPaint("fills")?.length && "fill", ownPaint("strokes")?.length && "stroke", ownPaint("radius") && "radius", ownPaint("effects") && `effect ${node.effects}`].filter(Boolean).join(", ")}`);
|
|
2281
2317
|
// A frame that holds layers without auto layout has no flex or grid to
|
|
2282
2318
|
// become: it is refused and reported, never drawn by absolute positions.
|
|
2283
2319
|
if (!node.layout && (node.children ?? []).some((c) => c.visible !== false && !c.absolute)) {
|
|
@@ -2471,17 +2507,36 @@ function settlePiiColumns(views, unmapped) {
|
|
|
2471
2507
|
const id = `${list}.${key}`;
|
|
2472
2508
|
const r = reads.get(id) ?? reads.set(id, { list, key, pii: 0, node: 0, variant: view.variant }).get(id);
|
|
2473
2509
|
r[how]++;
|
|
2510
|
+
return r;
|
|
2474
2511
|
};
|
|
2475
2512
|
for (const view of views) {
|
|
2476
2513
|
const openers = listOpeners(view.body);
|
|
2477
|
-
for (const m of view.body.matchAll(PII_ROW_READ))
|
|
2514
|
+
for (const m of view.body.matchAll(PII_ROW_READ)) {
|
|
2515
|
+
const r = count(view, openers, m.index, m[1], m[2], "pii");
|
|
2516
|
+
const empty = / == null \? \(("(?:[^"\\]|\\.)*")\) : \($/.exec(view.body.slice(0, m.index));
|
|
2517
|
+
if (r && empty) r.empty = empty[1];
|
|
2518
|
+
}
|
|
2478
2519
|
for (const m of view.body.matchAll(NODE_READ)) count(view, openers, m.index, m[2], m[3], "node");
|
|
2479
2520
|
}
|
|
2480
2521
|
const mixed = new Map([...reads].filter(([, r]) => r.pii && r.node));
|
|
2522
|
+
// All views share the row type. Once nullable, every view must guard its read.
|
|
2523
|
+
for (const view of views) {
|
|
2524
|
+
const openers = listOpeners(view.body);
|
|
2525
|
+
view.body = view.body.replace(PII_CELL, (all, param, key, at) => {
|
|
2526
|
+
const r = reads.get(`${listAt(openers, at, param)}.${key}`);
|
|
2527
|
+
if (r?.empty === undefined || r.node) return all;
|
|
2528
|
+
const pii = /<PiiText[^\n]*\/>/.exec(all)[0];
|
|
2529
|
+
return all.replace(pii, `{${param}.${key} == null ? (${r.empty}) : (${pii})}`);
|
|
2530
|
+
});
|
|
2531
|
+
}
|
|
2481
2532
|
if (!mixed.size) return;
|
|
2482
2533
|
for (const view of views) {
|
|
2483
2534
|
const openers = listOpeners(view.body);
|
|
2484
2535
|
view.body = view.body.replace(PII_CELL, (all, param, key, at) => (mixed.has(`${listAt(openers, at, param)}.${key}`) ? `>{${param}.${key}}</TableCell>` : all));
|
|
2536
|
+
// Nullable cells also participate in the cross-view contract. A genuinely
|
|
2537
|
+
// different cell kind must not leave an object read behind a ReactNode type.
|
|
2538
|
+
const nullableOpeners = listOpeners(view.body);
|
|
2539
|
+
view.body = view.body.replace(/>\n[ \t]*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*) == null \? \("(?:[^"\\]|\\.)*"\) : \(<PiiText[^\n]*\/>\)\}\n[ \t]*<\/TableCell>/g, (all, param, key, at) => (mixed.has(`${listAt(nullableOpeners, at, param)}.${key}`) ? `>{${param}.${key}}</TableCell>` : all));
|
|
2485
2540
|
}
|
|
2486
2541
|
for (const r of mixed.values()) {
|
|
2487
2542
|
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)` });
|
|
@@ -2497,6 +2552,24 @@ function piiCellAttrs({ code, held }) {
|
|
|
2497
2552
|
}
|
|
2498
2553
|
|
|
2499
2554
|
function piiTreeKind(cell) {
|
|
2555
|
+
// Rich cells render the Surface-owned content slot, not an exposed instance.
|
|
2556
|
+
// Resolve only that slot's visible PiiText; unrelated slots and hidden samples
|
|
2557
|
+
// must not supply a missing kind, and ambiguous content stays unmapped.
|
|
2558
|
+
if (cell.instance?.set === "Table Rich Cell") {
|
|
2559
|
+
const kinds = [];
|
|
2560
|
+
const visit = (node) => {
|
|
2561
|
+
if (node.visible === false || node.absolute) return;
|
|
2562
|
+
if (node.instance) {
|
|
2563
|
+
if (node.instance.remote && node.instance.set === "PiiText") kinds.push(node.instance.props?.kind);
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2566
|
+
for (const child of node.children ?? []) visit(child);
|
|
2567
|
+
};
|
|
2568
|
+
for (const slot of cell.children ?? []) {
|
|
2569
|
+
if (slot.type === "SLOT" && slot.slot === "content") visit(slot);
|
|
2570
|
+
}
|
|
2571
|
+
return kinds.length === 1 ? kinds[0] : undefined;
|
|
2572
|
+
}
|
|
2500
2573
|
const exposed = Object.entries(cell.instance?.exposed ?? {}).find(([name]) => name.toLowerCase() === "piitext")?.[1];
|
|
2501
2574
|
return exposed?.props?.kind;
|
|
2502
2575
|
}
|
|
@@ -2509,6 +2582,16 @@ function piiCellText({ cell, code }, ref) {
|
|
|
2509
2582
|
return `<PiiText value={${ref}.value} kind="${kind}" model={${ref}.model} relation={${ref}.relation} maskHint={${ref}.maskHint}${size} />`;
|
|
2510
2583
|
}
|
|
2511
2584
|
|
|
2585
|
+
/** Only a plain literal empty cell is compatible with a nullable person. */
|
|
2586
|
+
function emptyPiiCell(part) {
|
|
2587
|
+
if (part.held || !/^<TableCell\b/.test(part.code ?? "")) return null;
|
|
2588
|
+
const inner = part.code.slice(openTagEnd(part.code) + 1).replace(/<\/TableCell>$/, "").trim();
|
|
2589
|
+
const literal = /^\{("(?:[^"\\]|\\.)*")\}$/.exec(inner);
|
|
2590
|
+
if (!literal) return null;
|
|
2591
|
+
const value = JSON.parse(literal[1]);
|
|
2592
|
+
return /^(?:\s*|\s*[-–—]\s*|\s*(?:unassigned|none|system)\s*)$/i.test(value) ? literal[1] : null;
|
|
2593
|
+
}
|
|
2594
|
+
|
|
2512
2595
|
/**
|
|
2513
2596
|
* A table a Surface draws as frames: rows of Table-part instances (what the
|
|
2514
2597
|
* templates emit as TableHead or TableCell). Those parts are valid only inside
|
|
@@ -2844,11 +2927,17 @@ function tableOf(node, ctx) {
|
|
|
2844
2927
|
// raw name (U05; cli-140). A column that is PiiText in only some rows stays a node, and
|
|
2845
2928
|
// the report names it.
|
|
2846
2929
|
const invalidPii = new Map();
|
|
2930
|
+
const nullablePii = new Map();
|
|
2847
2931
|
const piiColumn = keys.map((key, i) => {
|
|
2848
|
-
const
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2932
|
+
const people = dataRows.filter((p) => piiCellAttrs(p.cells[i]) !== null);
|
|
2933
|
+
const drawn = people.length;
|
|
2934
|
+
const others = dataRows.filter((p) => piiCellAttrs(p.cells[i]) === null);
|
|
2935
|
+
const empties = others.map(p => emptyPiiCell(p.cells[i]));
|
|
2936
|
+
const nullable = drawn > 0 && others.length > 0 && empties.every(value => value !== null) && new Set(empties).size === 1;
|
|
2937
|
+
if (nullable) nullablePii.set(i, { sample: people[0].cells[i], empty: empties[0] });
|
|
2938
|
+
if (drawn > 0 && drawn < dataRows.length && !nullable) 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)`);
|
|
2939
|
+
if (drawn === dataRows.length || nullable) {
|
|
2940
|
+
const kinds = people.map((p) => piiTreeKind(p.cells[i].cell));
|
|
2852
2941
|
const why = kinds.some((kind) => !PII_KINDS.has(kind))
|
|
2853
2942
|
? `column ${key} has no recognised PiiText kind in one or more body rows`
|
|
2854
2943
|
: new Set(kinds).size !== 1 ? `column ${key} has incompatible PiiText kinds` : null;
|
|
@@ -2858,7 +2947,7 @@ function tableOf(node, ctx) {
|
|
|
2858
2947
|
return false;
|
|
2859
2948
|
}
|
|
2860
2949
|
}
|
|
2861
|
-
return drawn === dataRows.length;
|
|
2950
|
+
return drawn === dataRows.length || nullable;
|
|
2862
2951
|
});
|
|
2863
2952
|
const cells = first.cells.map((c, i) => {
|
|
2864
2953
|
const w = columnWidth(c.cell);
|
|
@@ -2872,7 +2961,12 @@ function tableOf(node, ctx) {
|
|
|
2872
2961
|
close = `</${tag}>`;
|
|
2873
2962
|
}
|
|
2874
2963
|
if (invalidPii.has(i)) return indent(`${open}${comment(`unmapped: ${invalidPii.get(i)}`)}${close}`, depth + 4);
|
|
2875
|
-
if (piiColumn[i])
|
|
2964
|
+
if (piiColumn[i]) {
|
|
2965
|
+
const nullable = nullablePii.get(i);
|
|
2966
|
+
const ref = `row.${keys[i]}`;
|
|
2967
|
+
const content = nullable ? `{${ref} == null ? (${nullable.empty}) : (${piiCellText(nullable.sample, ref)})}` : piiCellText(c, ref);
|
|
2968
|
+
return indent(`${open}\n ${content}\n${close}`, depth + 4);
|
|
2969
|
+
}
|
|
2876
2970
|
return indent(`${open}{row.${keys[i]}}${close}`, depth + 4);
|
|
2877
2971
|
});
|
|
2878
2972
|
return [
|