@nodii/dev 0.6.162 → 0.6.164

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 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.162";
7
+ export const VERSION = "0.6.164";
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 = 28;
35
+ export const GENERATOR_FORMAT = 33;
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). */
@@ -989,6 +989,17 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
989
989
  const scope = nameOf(label ? literalText(label[1]) : node.name, node.name);
990
990
  return `<DescriptionItem${attrs.replace(value[0], `value={${lift(scope, "value")}}`)}/>`;
991
991
  });
992
+ out = rewriteTags(out, "DetailFact", (attrs) => {
993
+ const parsed = tagAttributes(`${attrs}>`, 0);
994
+ if (!parsed?.literals.has("value")) return attrs;
995
+ const label = parsed.literals.get("label");
996
+ const factScope = nameOf(label ? literalText(label) : node.name, node.name);
997
+ const flat = maskStrings(attrs);
998
+ return attrs.replace(new RegExp(String.raw`\bvalue=${LITERAL}`, "g"), (value, at) => {
999
+ const depth = [...flat.slice(0, at)].reduce((d, c) => d + (c === "{") - (c === "}"), 0);
1000
+ return depth === 0 ? `value={${lift(factScope, "value")}}` : value;
1001
+ });
1002
+ });
992
1003
  out = out.replace(/<StatusPill\b([^>]*?)(\/?)>/g, (all, attrs, close) => {
993
1004
  const label = new RegExp(String.raw`\blabel=${LITERAL}`).exec(attrs);
994
1005
  if (!label) return all;
@@ -1025,7 +1036,7 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
1025
1036
  .replace(/\s+defaultChecked(?:=\{(?:true|false)\})?(?=[\s/>]|$)/g, "");
1026
1037
  // A Field's swapped control still belongs to its caller, including pending
1027
1038
  // and permission state. Keep the Field's own id, error and hint bindings.
1028
- const controlled = fieldToggle ? rest.replace(/\s+disabled(?:=(?:\{[^{}]*\}|"[^"]*"))?(?=[\s/>]|$)/g, "") : rest;
1039
+ const controlled = fieldToggle ? rest.replace(/\s+disabled(?:=(?:\{[^{}]*\}|"[^"]*"))?(?=[\s/>]|$)/g, "") : controlDisabled(rest, scope, ctx);
1029
1040
  const disabled = fieldToggle ? ` disabled={${lift(scope, joinName(scope, "disabled"))}}` : "";
1030
1041
  return ` checked={${lift(scope, joinName(scope, "checked"))}} onCheckedChange={${lift(scope, `on${cap(joinName(scope, "checkedChange"))}`)}}${disabled}${controlled}`;
1031
1042
  });
@@ -1091,7 +1102,14 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
1091
1102
  out = rewriteTags(out, "PageSizeSelect", (attrs) => attrs.replace(/\bvalue=\{(?:\d+|Number\("(?:[^"\\\n]|\\.)*"\))\}/, () => `value={${lift(scope, "pageSize")}}`));
1092
1103
  out = rewriteTags(out, "CopyField", (attrs) => {
1093
1104
  const value = new RegExp(String.raw`\bvalue=${LITERAL}`).exec(attrs);
1094
- return value ? attrs.replace(value[0], `value={${lift(scope, "value")}}`) : attrs;
1105
+ let next = value ? attrs.replace(value[0], `value={${lift(scope, "value")}}`) : attrs;
1106
+ const label = new RegExp(String.raw`\blabel=(${LITERAL})`).exec(next);
1107
+ if (label) {
1108
+ lifted.push("label");
1109
+ const name = optionalMark(ctx, scope, "label");
1110
+ next = next.replace(label[0], `label={${name} ?? ${JSON.stringify(literalText(label[1]))}}`);
1111
+ }
1112
+ return next;
1095
1113
  });
1096
1114
  out = rewriteTags(out, "PiiText", (attrs) => {
1097
1115
  const hint = new RegExp(String.raw`\bmaskHint=${LITERAL}`).exec(attrs);
@@ -1137,10 +1155,10 @@ export const SAMPLE_VALUE = /₹\s?\d|\b\d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|A
1137
1155
  const RELATIVE_PERIOD = /^(?:(?:this|last|previous|current|next) (?:day|week|month|quarter|year)|today|yesterday|tomorrow)$/i;
1138
1156
  const RECORD_TEXT = (text) => SAMPLE_VALUE.test(text) || /\d/.test(text) || RELATIVE_PERIOD.test(text.trim());
1139
1157
 
1140
- // A named fact frame is a label/value pair even when its value has no digits
1158
+ // A named fact or field frame is a label/value pair even when its value has no digits
1141
1159
  // (for example Status / Active). Keep the label and lift only the value.
1142
1160
  function isFactValue(node, parent) {
1143
- if (parent?.type !== "FRAME" || !/^Fact\s*·\s*\S/.test(parent.name ?? "")) return false;
1161
+ if (parent?.type !== "FRAME" || !/^(?:Fact|field)\s*·\s*\S/i.test(parent.name ?? "")) return false;
1144
1162
  const children = (parent.children ?? []).filter((child) => child.visible !== false);
1145
1163
  return children.length === 2 && children.every((child) => child.type === "TEXT") && children[1] === node;
1146
1164
  }
@@ -1460,6 +1478,7 @@ const placedControl = (word) => ({ change: "onValueChange", value: "value", word
1460
1478
  const NAMED_CHANGE = {
1461
1479
  ...Object.fromEntries(Object.entries(FIELD_CONTROLS).map(([tag, change]) => [tag, fieldControl(change)])),
1462
1480
  MultiSelect: fieldControl("onValueChange"),
1481
+ PeopleSelector: fieldControl("onCommit"),
1463
1482
  DateTimePicker: fieldControl("onChange"),
1464
1483
  DatePicker: fieldControl("onValueChange"),
1465
1484
  DateRangePicker: fieldControl("onChange"),
@@ -1552,6 +1571,28 @@ function fieldScope(node, ctx, code) {
1552
1571
  return layer === camelName(node.instance?.set ?? "") || !nameText(node.name) ? nameOf(hint, "field") : layer;
1553
1572
  }
1554
1573
 
1574
+ /** A control keeps its drawn disabled default, while its caller owns later availability. */
1575
+ function controlDisabled(attrs, scope, ctx) {
1576
+ const parsed = tagAttributes(`${attrs}>`, 0);
1577
+ if (!parsed) return attrs;
1578
+ const has = parsed.names.includes("disabled");
1579
+ const literal = parsed.literals.get("disabled");
1580
+ if (has && literal !== "true" && literal !== "false") return attrs;
1581
+ const name = optionalMark(ctx, scope, joinName(scope, "disabled"));
1582
+ const binding = `disabled={${name}${has ? ` ?? ${literal}` : ""}}`;
1583
+ if (!has) return ` ${binding}${attrs}`;
1584
+ const bare = bareAttr(attrs, "disabled");
1585
+ if (bare !== null) return attrs.slice(0, bare) + binding + attrs.slice(bare + "disabled".length);
1586
+ const flat = maskStrings(attrs);
1587
+ for (const m of attrs.matchAll(/(^|\s)disabled=\{\s*(?:true|false)\s*\}/g)) {
1588
+ const start = m.index + m[1].length;
1589
+ if (flat.slice(start, start + "disabled".length) !== "disabled") continue;
1590
+ const depth = [...flat.slice(0, m.index)].reduce((d, c) => d + (c === "{") - (c === "}"), 0);
1591
+ if (depth === 0) return attrs.slice(0, m.index) + m[1] + binding + attrs.slice(m.index + m[0].length);
1592
+ }
1593
+ return attrs;
1594
+ }
1595
+
1555
1596
  /**
1556
1597
  * Every Input, Textarea and SelectField is controlled by the page: Figma's
1557
1598
  * sample value (`defaultValue="Apex Labs Pvt Ltd"`) becomes the page's value,
@@ -1587,6 +1628,7 @@ function liftFieldControls(code, node, ctx, lift, scope) {
1587
1628
  const changeName = `on${cap(withWord ? joinName(at, word) : at)}Change`;
1588
1629
  const value = `${valueAttr}={${lift(at, valueName)}}`;
1589
1630
  let next = attrs.replace(change[0], `${change[1]}${handler}={${lift(at, changeName)}}`);
1631
+ if (byField) next = controlDisabled(next, at, ctx);
1590
1632
  // Empty values in interactive templates are samples too. An option-only
1591
1633
  // MultiSelect snippet is an example option, not the editable trigger.
1592
1634
  const part = node.instance?.props?.control?.props?.part ?? node.instance?.props?.part;
@@ -1622,7 +1664,7 @@ function liftFieldControls(code, node, ctx, lift, scope) {
1622
1664
  let next = attrs.replace(/\bid="select"/, `id="${kebab(scope)}"`);
1623
1665
  const sample = new RegExp(String.raw`\bdefaultValue=${LITERAL}`).exec(next);
1624
1666
  next = sample ? next.replace(sample[0], `${value}${sep}${change}`) : `${next}${sep}${value}${sep}${change}`;
1625
- return `<${tag}${next}${close}>`;
1667
+ return `<${tag}${controlDisabled(next, scope, ctx)}${close}>`;
1626
1668
  });
1627
1669
  }
1628
1670
 
@@ -1849,7 +1891,7 @@ function dataProps(views, propsType) {
1849
1891
  (entry(m[1]).tabValues ??= new Set()).add(JSON.parse(m[2]));
1850
1892
  view.uses.add(m[1]);
1851
1893
  }
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)) {
1894
+ 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
1895
  if (JS_LITERALS.has(m[2]) || data.get(m[2])?.raw) continue;
1854
1896
  const list = m[3] ? itemList(m.index, m[2]) : null;
1855
1897
  // A list item's React key is its own: a string, never a DS prop.
@@ -2251,7 +2293,9 @@ function emitNode(node, ctx) {
2251
2293
  return indent(comment(`unmapped: ${describe(node)} (${why})`), depth);
2252
2294
  }
2253
2295
  ctx.imports.push(...rendered.imports);
2254
- const sizing = ctx.bare ? [] : sizeClasses(node, parent, false);
2296
+ // Detail Section owns its grid. The Row template emits sibling facts,
2297
+ // not a layout box: a wrapper would turn the entire row into one grid cell.
2298
+ const sizing = ctx.bare || node.instance.set === "Detail Section / Row" ? [] : sizeClasses(node, parent, false);
2255
2299
  // A data slot passed straight to a prop is that prop (`trailing={<>{trailing}</>}` → `trailing={trailing}`).
2256
2300
  let own = rendered.code.trim().replace(/=\{<>\{([a-z][A-Za-z0-9]*)\}<\/>\}/g, "={$1}");
2257
2301
  // The toolbar builds rows itself, so its template never renders the table slot.
@@ -2285,6 +2329,11 @@ function emitNode(node, ctx) {
2285
2329
  });
2286
2330
  const control = /^<(?:Input|Textarea|SelectField)\b/.test(own.replace(/^<Field\b[^>]*>\s*/, ""));
2287
2331
  const toggle = TOGGLE.test(own) ? textNextTo(node, ctx) : null;
2332
+ if (toggle) own = rewriteTags(own, "Checkbox|Switch", (attrs) => {
2333
+ const parsed = tagAttributes(`${attrs}>`, 0);
2334
+ if (!parsed || parsed.names.some(name => name === "aria-label" || name === "aria-labelledby")) return attrs;
2335
+ return ` aria-label={${JSON.stringify(toggle)}}${attrs}`;
2336
+ });
2288
2337
  const scope = control ? fieldScope(node, ctx, own) : toggle ? camelName(toggle) : scopeName(node, own, ctx);
2289
2338
  own = nameHandlers(own, node, ctx, path, scope);
2290
2339
  own = controlHalfControlled(liftRecordData(own, node, ctx, path, scope));
@@ -2542,8 +2591,8 @@ const PII_ROW_READ = /<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]
2542
2591
  /**
2543
2592
  * One list's rows are one type across the views and tables that share it. A column that is
2544
2593
  * PiiText in one of them and a node in another (two tables whose heads still show Figma's
2545
- * placeholder, so both are `column1`) can be neither: it stays a node everywhere, as before
2546
- * cli-140, and the report names it.
2594
+ * placeholder, so both are `column1`) cannot share a safe contract. Report a mapping
2595
+ * failure in every affected column instead of discarding its PiiText protection.
2547
2596
  */
2548
2597
  function settlePiiColumns(views, unmapped) {
2549
2598
  const NODE_READ = /(^|>)\s*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\}/gm;
@@ -2580,14 +2629,19 @@ function settlePiiColumns(views, unmapped) {
2580
2629
  if (!mixed.size) return;
2581
2630
  for (const view of views) {
2582
2631
  const openers = listOpeners(view.body);
2583
- view.body = view.body.replace(PII_CELL, (all, param, key, at) => (mixed.has(`${listAt(openers, at, param)}.${key}`) ? `>{${param}.${key}}</TableCell>` : all));
2632
+ 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
2633
  // Nullable cells also participate in the cross-view contract. A genuinely
2585
2634
  // different cell kind must not leave an object read behind a ReactNode type.
2586
2635
  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}`) ? `>{${param}.${key}}</TableCell>` : all));
2636
+ 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));
2637
+ }
2638
+ for (const view of views) {
2639
+ const openers = listOpeners(view.body);
2640
+ view.body = view.body.replace(NODE_READ, (all, open, param, key, at) =>
2641
+ mixed.has(`${listAt(openers, at, param)}.${key}`) ? `${open}${comment(`unmapped: incompatible PII column ${key}`)}` : all);
2588
2642
  }
2589
2643
  for (const r of mixed.values()) {
2590
- 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)` });
2644
+ 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
2645
  }
2592
2646
  }
2593
2647
 
@@ -2640,7 +2694,9 @@ function piiCellText({ cell, code }, ref) {
2640
2694
  const { attrs = "", before = "", after = "" } = piiCellParts({ code }) ?? {};
2641
2695
  const kind = piiTreeKind(cell);
2642
2696
  const size = /\ssize="\w+"/.exec(attrs)?.[0] ?? "";
2643
- return `${before}<PiiText value={${ref}.value} kind="${kind}" model={${ref}.model} relation={${ref}.relation} maskHint={${ref}.maskHint}${size} />${after}`;
2697
+ // Repeated people are a bulk disclosure surface even inside a record page or
2698
+ // a permissive ambient provider. Keep the served self relation unchanged.
2699
+ return `${before}<PiiText value={${ref}.value} kind="${kind}" model={${ref}.model} relation={${ref}.relation} maskHint={${ref}.maskHint} surface="bulk"${size} />${after}`;
2644
2700
  }
2645
2701
 
2646
2702
  /** Only a plain literal empty cell is compatible with a nullable person. */
@@ -2991,8 +3047,8 @@ function tableOf(node, ctx) {
2991
3047
  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
3048
  // A column whose every body cell is a PiiText is a person's value: its row field is the
2993
3049
  // served pair and the cell draws PiiText from it, never a node the page could fill with a
2994
- // raw name (U05; cli-140). A column that is PiiText in only some rows stays a node, and
2995
- // the report names it.
3050
+ // raw name (U05; cli-140). Mixed content must be compatible with a nullable
3051
+ // person; otherwise the column is an explicit mapping failure.
2996
3052
  const invalidPii = new Map();
2997
3053
  const nullablePii = new Map();
2998
3054
  const personSamples = new Map();
@@ -3008,7 +3064,12 @@ function tableOf(node, ctx) {
3008
3064
  const empties = others.map(p => emptyPiiCell(p.cells[i]));
3009
3065
  const nullable = drawn > 0 && others.length > 0 && empties.every(value => value !== null) && new Set(empties).size === 1;
3010
3066
  if (nullable) nullablePii.set(i, { sample: people[0].cells[i], empty: empties[0] });
3011
- 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)`);
3067
+ if (drawn > 0 && drawn < dataRows.length && !nullable) {
3068
+ const why = `column ${key} mixes PiiText with incompatible non-person content`;
3069
+ ctx.note(ctx.path, "table", `${why}: left unmapped (U05; cli-140)`);
3070
+ invalidPii.set(i, why);
3071
+ return false;
3072
+ }
3012
3073
  if (drawn === dataRows.length || nullable) {
3013
3074
  const kinds = people.map((p) => piiTreeKind(p.cells[i].cell));
3014
3075
  const why = kinds.some((kind) => !PII_KINDS.has(kind))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.162",
3
+ "version": "0.6.164",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {