@nodii/dev 0.6.161 → 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 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.161";
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 = 27;
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/.test(parent.name ?? "")) return false;
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,7 +1610,17 @@ 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)}}`);
1590
- const sample = INPUT_FAMILY.test(tag) ? "" : `|${SAMPLE_LITERAL}`;
1613
+ if (byField) next = controlDisabled(next, at, ctx);
1614
+ // Empty values in interactive templates are samples too. An option-only
1615
+ // MultiSelect snippet is an example option, not the editable trigger.
1616
+ const part = node.instance?.props?.control?.props?.part ?? node.instance?.props?.part;
1617
+ const empty = tag === "CurrencyInput" ? String.raw`|\{null\}`
1618
+ : tag === "MultiSelect" && part !== "option" ? String.raw`|\{\[\]\}` : "";
1619
+ const sample = INPUT_FAMILY.test(tag) ? "" : `|${SAMPLE_LITERAL}${empty}`;
1620
+ if (tag === "CurrencyInput") {
1621
+ next = next.replace(new RegExp(String.raw`(^|\s)currency=${LITERAL}`),
1622
+ (_, sp) => `${sp}currency={${lift(at, joinName(at, "currency"))}}`);
1623
+ }
1591
1624
  const drawn = new RegExp(String.raw`(^|\s)(?:${valueAttr}=(?:${GENERIC_VALUE}${sample})|defaultValue=${LITERAL})`).exec(next);
1592
1625
  if (drawn) return next.replace(drawn[0], `${drawn[1]}${value}`);
1593
1626
  if (new RegExp(String.raw`(^|\s)${valueAttr}=`).test(next)) return next;
@@ -1613,7 +1646,7 @@ function liftFieldControls(code, node, ctx, lift, scope) {
1613
1646
  let next = attrs.replace(/\bid="select"/, `id="${kebab(scope)}"`);
1614
1647
  const sample = new RegExp(String.raw`\bdefaultValue=${LITERAL}`).exec(next);
1615
1648
  next = sample ? next.replace(sample[0], `${value}${sep}${change}`) : `${next}${sep}${value}${sep}${change}`;
1616
- return `<${tag}${next}${close}>`;
1649
+ return `<${tag}${controlDisabled(next, scope, ctx)}${close}>`;
1617
1650
  });
1618
1651
  }
1619
1652
 
@@ -1840,7 +1873,7 @@ function dataProps(views, propsType) {
1840
1873
  (entry(m[1]).tabValues ??= new Set()).add(JSON.parse(m[2]));
1841
1874
  view.uses.add(m[1]);
1842
1875
  }
1843
- 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)) {
1844
1877
  if (JS_LITERALS.has(m[2]) || data.get(m[2])?.raw) continue;
1845
1878
  const list = m[3] ? itemList(m.index, m[2]) : null;
1846
1879
  // A list item's React key is its own: a string, never a DS prop.
@@ -2276,6 +2309,11 @@ function emitNode(node, ctx) {
2276
2309
  });
2277
2310
  const control = /^<(?:Input|Textarea|SelectField)\b/.test(own.replace(/^<Field\b[^>]*>\s*/, ""));
2278
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
+ });
2279
2317
  const scope = control ? fieldScope(node, ctx, own) : toggle ? camelName(toggle) : scopeName(node, own, ctx);
2280
2318
  own = nameHandlers(own, node, ctx, path, scope);
2281
2319
  own = controlHalfControlled(liftRecordData(own, node, ctx, path, scope));
@@ -2533,8 +2571,8 @@ const PII_ROW_READ = /<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]
2533
2571
  /**
2534
2572
  * One list's rows are one type across the views and tables that share it. A column that is
2535
2573
  * PiiText in one of them and a node in another (two tables whose heads still show Figma's
2536
- * placeholder, so both are `column1`) can be neither: it stays a node everywhere, as before
2537
- * cli-140, and the report names it.
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.
2538
2576
  */
2539
2577
  function settlePiiColumns(views, unmapped) {
2540
2578
  const NODE_READ = /(^|>)\s*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\}/gm;
@@ -2571,14 +2609,19 @@ function settlePiiColumns(views, unmapped) {
2571
2609
  if (!mixed.size) return;
2572
2610
  for (const view of views) {
2573
2611
  const openers = listOpeners(view.body);
2574
- view.body = view.body.replace(PII_CELL, (all, param, key, at) => (mixed.has(`${listAt(openers, at, param)}.${key}`) ? `>{${param}.${key}}</TableCell>` : all));
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));
2575
2613
  // Nullable cells also participate in the cross-view contract. A genuinely
2576
2614
  // different cell kind must not leave an object read behind a ReactNode type.
2577
2615
  const nullableOpeners = listOpeners(view.body);
2578
- 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));
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);
2579
2622
  }
2580
2623
  for (const r of mixed.values()) {
2581
- 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)` });
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)` });
2582
2625
  }
2583
2626
  }
2584
2627
 
@@ -2982,8 +3025,8 @@ function tableOf(node, ctx) {
2982
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)`);
2983
3026
  // A column whose every body cell is a PiiText is a person's value: its row field is the
2984
3027
  // served pair and the cell draws PiiText from it, never a node the page could fill with a
2985
- // raw name (U05; cli-140). A column that is PiiText in only some rows stays a node, and
2986
- // the report names it.
3028
+ // raw name (U05; cli-140). Mixed content must be compatible with a nullable
3029
+ // person; otherwise the column is an explicit mapping failure.
2987
3030
  const invalidPii = new Map();
2988
3031
  const nullablePii = new Map();
2989
3032
  const personSamples = new Map();
@@ -2999,7 +3042,12 @@ function tableOf(node, ctx) {
2999
3042
  const empties = others.map(p => emptyPiiCell(p.cells[i]));
3000
3043
  const nullable = drawn > 0 && others.length > 0 && empties.every(value => value !== null) && new Set(empties).size === 1;
3001
3044
  if (nullable) nullablePii.set(i, { sample: people[0].cells[i], empty: empties[0] });
3002
- 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)`);
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
+ }
3003
3051
  if (drawn === dataRows.length || nullable) {
3004
3052
  const kinds = people.map((p) => piiTreeKind(p.cells[i].cell));
3005
3053
  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.161",
3
+ "version": "0.6.163",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {