@nodii/dev 0.6.162 → 0.6.163
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 +53 -14
- 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.163";
|
|
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 = 32;
|
|
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). */
|
|
@@ -1025,7 +1025,7 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
1025
1025
|
.replace(/\s+defaultChecked(?:=\{(?:true|false)\})?(?=[\s/>]|$)/g, "");
|
|
1026
1026
|
// A Field's swapped control still belongs to its caller, including pending
|
|
1027
1027
|
// and permission state. Keep the Field's own id, error and hint bindings.
|
|
1028
|
-
const controlled = fieldToggle ? rest.replace(/\s+disabled(?:=(?:\{[^{}]*\}|"[^"]*"))?(?=[\s/>]|$)/g, "") : rest;
|
|
1028
|
+
const controlled = fieldToggle ? rest.replace(/\s+disabled(?:=(?:\{[^{}]*\}|"[^"]*"))?(?=[\s/>]|$)/g, "") : controlDisabled(rest, scope, ctx);
|
|
1029
1029
|
const disabled = fieldToggle ? ` disabled={${lift(scope, joinName(scope, "disabled"))}}` : "";
|
|
1030
1030
|
return ` checked={${lift(scope, joinName(scope, "checked"))}} onCheckedChange={${lift(scope, `on${cap(joinName(scope, "checkedChange"))}`)}}${disabled}${controlled}`;
|
|
1031
1031
|
});
|
|
@@ -1137,10 +1137,10 @@ export const SAMPLE_VALUE = /₹\s?\d|\b\d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|A
|
|
|
1137
1137
|
const RELATIVE_PERIOD = /^(?:(?:this|last|previous|current|next) (?:day|week|month|quarter|year)|today|yesterday|tomorrow)$/i;
|
|
1138
1138
|
const RECORD_TEXT = (text) => SAMPLE_VALUE.test(text) || /\d/.test(text) || RELATIVE_PERIOD.test(text.trim());
|
|
1139
1139
|
|
|
1140
|
-
// A named fact frame is a label/value pair even when its value has no digits
|
|
1140
|
+
// A named fact or field frame is a label/value pair even when its value has no digits
|
|
1141
1141
|
// (for example Status / Active). Keep the label and lift only the value.
|
|
1142
1142
|
function isFactValue(node, parent) {
|
|
1143
|
-
if (parent?.type !== "FRAME" || !/^Fact\s*·\s*\S
|
|
1143
|
+
if (parent?.type !== "FRAME" || !/^(?:Fact|field)\s*·\s*\S/i.test(parent.name ?? "")) return false;
|
|
1144
1144
|
const children = (parent.children ?? []).filter((child) => child.visible !== false);
|
|
1145
1145
|
return children.length === 2 && children.every((child) => child.type === "TEXT") && children[1] === node;
|
|
1146
1146
|
}
|
|
@@ -1460,6 +1460,7 @@ const placedControl = (word) => ({ change: "onValueChange", value: "value", word
|
|
|
1460
1460
|
const NAMED_CHANGE = {
|
|
1461
1461
|
...Object.fromEntries(Object.entries(FIELD_CONTROLS).map(([tag, change]) => [tag, fieldControl(change)])),
|
|
1462
1462
|
MultiSelect: fieldControl("onValueChange"),
|
|
1463
|
+
PeopleSelector: fieldControl("onCommit"),
|
|
1463
1464
|
DateTimePicker: fieldControl("onChange"),
|
|
1464
1465
|
DatePicker: fieldControl("onValueChange"),
|
|
1465
1466
|
DateRangePicker: fieldControl("onChange"),
|
|
@@ -1552,6 +1553,28 @@ function fieldScope(node, ctx, code) {
|
|
|
1552
1553
|
return layer === camelName(node.instance?.set ?? "") || !nameText(node.name) ? nameOf(hint, "field") : layer;
|
|
1553
1554
|
}
|
|
1554
1555
|
|
|
1556
|
+
/** A control keeps its drawn disabled default, while its caller owns later availability. */
|
|
1557
|
+
function controlDisabled(attrs, scope, ctx) {
|
|
1558
|
+
const parsed = tagAttributes(`${attrs}>`, 0);
|
|
1559
|
+
if (!parsed) return attrs;
|
|
1560
|
+
const has = parsed.names.includes("disabled");
|
|
1561
|
+
const literal = parsed.literals.get("disabled");
|
|
1562
|
+
if (has && literal !== "true" && literal !== "false") return attrs;
|
|
1563
|
+
const name = optionalMark(ctx, scope, joinName(scope, "disabled"));
|
|
1564
|
+
const binding = `disabled={${name}${has ? ` ?? ${literal}` : ""}}`;
|
|
1565
|
+
if (!has) return ` ${binding}${attrs}`;
|
|
1566
|
+
const bare = bareAttr(attrs, "disabled");
|
|
1567
|
+
if (bare !== null) return attrs.slice(0, bare) + binding + attrs.slice(bare + "disabled".length);
|
|
1568
|
+
const flat = maskStrings(attrs);
|
|
1569
|
+
for (const m of attrs.matchAll(/(^|\s)disabled=\{\s*(?:true|false)\s*\}/g)) {
|
|
1570
|
+
const start = m.index + m[1].length;
|
|
1571
|
+
if (flat.slice(start, start + "disabled".length) !== "disabled") continue;
|
|
1572
|
+
const depth = [...flat.slice(0, m.index)].reduce((d, c) => d + (c === "{") - (c === "}"), 0);
|
|
1573
|
+
if (depth === 0) return attrs.slice(0, m.index) + m[1] + binding + attrs.slice(m.index + m[0].length);
|
|
1574
|
+
}
|
|
1575
|
+
return attrs;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1555
1578
|
/**
|
|
1556
1579
|
* Every Input, Textarea and SelectField is controlled by the page: Figma's
|
|
1557
1580
|
* sample value (`defaultValue="Apex Labs Pvt Ltd"`) becomes the page's value,
|
|
@@ -1587,6 +1610,7 @@ function liftFieldControls(code, node, ctx, lift, scope) {
|
|
|
1587
1610
|
const changeName = `on${cap(withWord ? joinName(at, word) : at)}Change`;
|
|
1588
1611
|
const value = `${valueAttr}={${lift(at, valueName)}}`;
|
|
1589
1612
|
let next = attrs.replace(change[0], `${change[1]}${handler}={${lift(at, changeName)}}`);
|
|
1613
|
+
if (byField) next = controlDisabled(next, at, ctx);
|
|
1590
1614
|
// Empty values in interactive templates are samples too. An option-only
|
|
1591
1615
|
// MultiSelect snippet is an example option, not the editable trigger.
|
|
1592
1616
|
const part = node.instance?.props?.control?.props?.part ?? node.instance?.props?.part;
|
|
@@ -1622,7 +1646,7 @@ function liftFieldControls(code, node, ctx, lift, scope) {
|
|
|
1622
1646
|
let next = attrs.replace(/\bid="select"/, `id="${kebab(scope)}"`);
|
|
1623
1647
|
const sample = new RegExp(String.raw`\bdefaultValue=${LITERAL}`).exec(next);
|
|
1624
1648
|
next = sample ? next.replace(sample[0], `${value}${sep}${change}`) : `${next}${sep}${value}${sep}${change}`;
|
|
1625
|
-
return `<${tag}${next}${close}>`;
|
|
1649
|
+
return `<${tag}${controlDisabled(next, scope, ctx)}${close}>`;
|
|
1626
1650
|
});
|
|
1627
1651
|
}
|
|
1628
1652
|
|
|
@@ -1849,7 +1873,7 @@ function dataProps(views, propsType) {
|
|
|
1849
1873
|
(entry(m[1]).tabValues ??= new Set()).add(JSON.parse(m[2]));
|
|
1850
1874
|
view.uses.add(m[1]);
|
|
1851
1875
|
}
|
|
1852
|
-
for (const m of body.matchAll(/([A-Za-z][\w-]*)=\{([a-z][A-Za-z0-9]*)(?:\.([A-Za-z][A-Za-z0-9]*))?\}/g)) {
|
|
1876
|
+
for (const m of body.matchAll(/([A-Za-z][\w-]*)=\{([a-z][A-Za-z0-9]*)(?:\.([A-Za-z][A-Za-z0-9]*))?(?: \?\? (?:true|false))?\}/g)) {
|
|
1853
1877
|
if (JS_LITERALS.has(m[2]) || data.get(m[2])?.raw) continue;
|
|
1854
1878
|
const list = m[3] ? itemList(m.index, m[2]) : null;
|
|
1855
1879
|
// A list item's React key is its own: a string, never a DS prop.
|
|
@@ -2285,6 +2309,11 @@ function emitNode(node, ctx) {
|
|
|
2285
2309
|
});
|
|
2286
2310
|
const control = /^<(?:Input|Textarea|SelectField)\b/.test(own.replace(/^<Field\b[^>]*>\s*/, ""));
|
|
2287
2311
|
const toggle = TOGGLE.test(own) ? textNextTo(node, ctx) : null;
|
|
2312
|
+
if (toggle) own = rewriteTags(own, "Checkbox|Switch", (attrs) => {
|
|
2313
|
+
const parsed = tagAttributes(`${attrs}>`, 0);
|
|
2314
|
+
if (!parsed || parsed.names.some(name => name === "aria-label" || name === "aria-labelledby")) return attrs;
|
|
2315
|
+
return ` aria-label={${JSON.stringify(toggle)}}${attrs}`;
|
|
2316
|
+
});
|
|
2288
2317
|
const scope = control ? fieldScope(node, ctx, own) : toggle ? camelName(toggle) : scopeName(node, own, ctx);
|
|
2289
2318
|
own = nameHandlers(own, node, ctx, path, scope);
|
|
2290
2319
|
own = controlHalfControlled(liftRecordData(own, node, ctx, path, scope));
|
|
@@ -2542,8 +2571,8 @@ const PII_ROW_READ = /<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]
|
|
|
2542
2571
|
/**
|
|
2543
2572
|
* One list's rows are one type across the views and tables that share it. A column that is
|
|
2544
2573
|
* PiiText in one of them and a node in another (two tables whose heads still show Figma's
|
|
2545
|
-
* placeholder, so both are `column1`)
|
|
2546
|
-
*
|
|
2574
|
+
* placeholder, so both are `column1`) cannot share a safe contract. Report a mapping
|
|
2575
|
+
* failure in every affected column instead of discarding its PiiText protection.
|
|
2547
2576
|
*/
|
|
2548
2577
|
function settlePiiColumns(views, unmapped) {
|
|
2549
2578
|
const NODE_READ = /(^|>)\s*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\}/gm;
|
|
@@ -2580,14 +2609,19 @@ function settlePiiColumns(views, unmapped) {
|
|
|
2580
2609
|
if (!mixed.size) return;
|
|
2581
2610
|
for (const view of views) {
|
|
2582
2611
|
const openers = listOpeners(view.body);
|
|
2583
|
-
view.body = view.body.replace(PII_CELL, (all, param, key, at) => (mixed.has(`${listAt(openers, at, param)}.${key}`) ?
|
|
2612
|
+
view.body = view.body.replace(PII_CELL, (all, param, key, at) => (mixed.has(`${listAt(openers, at, param)}.${key}`) ? `>${comment(`unmapped: incompatible PII column ${key}`)}</TableCell>` : all));
|
|
2584
2613
|
// Nullable cells also participate in the cross-view contract. A genuinely
|
|
2585
2614
|
// different cell kind must not leave an object read behind a ReactNode type.
|
|
2586
2615
|
const nullableOpeners = listOpeners(view.body);
|
|
2587
|
-
view.body = view.body.replace(/>\n[ \t]*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*) == null \? \("(?:[^"\\]|\\.)*"\) : \((?:<div\b[^>]*>\s*)*<PiiText[^\n]*\/>\s*(?:<\/div>\s*)*\)\}\n[ \t]*<\/TableCell>/g, (all, param, key, at) => (mixed.has(`${listAt(nullableOpeners, at, param)}.${key}`) ?
|
|
2616
|
+
view.body = view.body.replace(/>\n[ \t]*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*) == null \? \("(?:[^"\\]|\\.)*"\) : \((?:<div\b[^>]*>\s*)*<PiiText[^\n]*\/>\s*(?:<\/div>\s*)*\)\}\n[ \t]*<\/TableCell>/g, (all, param, key, at) => (mixed.has(`${listAt(nullableOpeners, at, param)}.${key}`) ? `>${comment(`unmapped: incompatible PII column ${key}`)}</TableCell>` : all));
|
|
2617
|
+
}
|
|
2618
|
+
for (const view of views) {
|
|
2619
|
+
const openers = listOpeners(view.body);
|
|
2620
|
+
view.body = view.body.replace(NODE_READ, (all, open, param, key, at) =>
|
|
2621
|
+
mixed.has(`${listAt(openers, at, param)}.${key}`) ? `${open}${comment(`unmapped: incompatible PII column ${key}`)}` : all);
|
|
2588
2622
|
}
|
|
2589
2623
|
for (const r of mixed.values()) {
|
|
2590
|
-
unmapped.push({ variant: r.variant, path: r.list, kind:
|
|
2624
|
+
unmapped.push({ variant: r.variant, path: r.list, kind: "table", detail: `column ${r.key} of ${r.list} mixes PiiText and incompatible content across views: left unmapped (U05; cli-140)` });
|
|
2591
2625
|
}
|
|
2592
2626
|
}
|
|
2593
2627
|
|
|
@@ -2991,8 +3025,8 @@ function tableOf(node, ctx) {
|
|
|
2991
3025
|
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)`);
|
|
2992
3026
|
// A column whose every body cell is a PiiText is a person's value: its row field is the
|
|
2993
3027
|
// served pair and the cell draws PiiText from it, never a node the page could fill with a
|
|
2994
|
-
// raw name (U05; cli-140).
|
|
2995
|
-
// the
|
|
3028
|
+
// raw name (U05; cli-140). Mixed content must be compatible with a nullable
|
|
3029
|
+
// person; otherwise the column is an explicit mapping failure.
|
|
2996
3030
|
const invalidPii = new Map();
|
|
2997
3031
|
const nullablePii = new Map();
|
|
2998
3032
|
const personSamples = new Map();
|
|
@@ -3008,7 +3042,12 @@ function tableOf(node, ctx) {
|
|
|
3008
3042
|
const empties = others.map(p => emptyPiiCell(p.cells[i]));
|
|
3009
3043
|
const nullable = drawn > 0 && others.length > 0 && empties.every(value => value !== null) && new Set(empties).size === 1;
|
|
3010
3044
|
if (nullable) nullablePii.set(i, { sample: people[0].cells[i], empty: empties[0] });
|
|
3011
|
-
if (drawn > 0 && drawn < dataRows.length && !nullable)
|
|
3045
|
+
if (drawn > 0 && drawn < dataRows.length && !nullable) {
|
|
3046
|
+
const why = `column ${key} mixes PiiText with incompatible non-person content`;
|
|
3047
|
+
ctx.note(ctx.path, "table", `${why}: left unmapped (U05; cli-140)`);
|
|
3048
|
+
invalidPii.set(i, why);
|
|
3049
|
+
return false;
|
|
3050
|
+
}
|
|
3012
3051
|
if (drawn === dataRows.length || nullable) {
|
|
3013
3052
|
const kinds = people.map((p) => piiTreeKind(p.cells[i].cell));
|
|
3014
3053
|
const why = kinds.some((kind) => !PII_KINDS.has(kind))
|