@nodii/dev 0.6.150 → 0.6.151

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.150";
7
+ export const VERSION = "0.6.151";
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 = 17;
35
+ export const GENERATOR_FORMAT = 18;
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). */
@@ -840,6 +840,18 @@ function mark(ctx, scope, name, layer = ctx.layer) {
840
840
  return `__s${scopeIndex(ctx.scopes, scopeKey(scope, layer))}_${name}`;
841
841
  }
842
842
 
843
+ /**
844
+ * A prop the generator lifts that its DS component leaves optional, so the page
845
+ * may pass nothing: a tab's count (none drawn), a KPI's tone (neutral, or no
846
+ * dot) (hub-477). Marked as `mark` does, and counted optional unless a template
847
+ * that draws the same prop requires it.
848
+ */
849
+ function optionalMark(ctx, scope, name, layer = ctx.layer) {
850
+ const token = mark(ctx, scope, name, layer);
851
+ ctx.optionals?.optional.add(token);
852
+ return token;
853
+ }
854
+
843
855
  /**
844
856
  * Where a node sits in its view, the same in every view that draws it: its
845
857
  * layer names from the view's page down, a name its parent holds twice
@@ -1006,7 +1018,8 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
1006
1018
  let next = attrs;
1007
1019
  for (const attr of METRIC_VALUES) {
1008
1020
  const value = new RegExp(String.raw`\b${attr}=${LITERAL}`).exec(next);
1009
- if (value) next = next.replace(value[0], `${attr}={${lift(at, attr)}}`);
1021
+ // A tone the page leaves out is the component's own default (neutral, or no dot; hub-477).
1022
+ if (value) next = next.replace(value[0], `${attr}={${TONE_ATTR.has(attr) ? (lifted.push(attr), optionalMark(ctx, at, attr)) : lift(at, attr)}}`);
1010
1023
  }
1011
1024
  if (tag !== "MetricFilterCard") return next;
1012
1025
  const selected = `selected={${lift(at, "selected")}}`;
@@ -1269,11 +1282,7 @@ function handlerLabel(tag, attrs, after, node) {
1269
1282
  const UNNAMED_FRAME = /^(?:frame|group|auto ?layout|rectangle|container|slot)(?: \d+)?$/i;
1270
1283
  function handlerScope(node, ctx, path, inner, label, at) {
1271
1284
  const chain = ctx.chain ?? [];
1272
- const frames = [...chain.slice(1)].reverse().filter((c) => c.type !== "SLOT" && !c.instance && /[A-Za-z]/.test(c.name ?? ""));
1273
- // A frame named as the Surfaces name a place ("Row · Email domain allowlist") is that place.
1274
- const place = frames.map((c) => /\s·\s*(.*[A-Za-z].*)$/.exec(c.name)?.[1]).find(Boolean);
1275
- const named = frames.find((c) => !UNNAMED_FRAME.test(c.name.trim()))?.name;
1276
- const scope = inner ?? camelName(place ?? sectionHeading(node, chain) ?? titleBefore(node, chain) ?? named ?? "page");
1285
+ const scope = inner ?? placeOf(node, ctx);
1277
1286
  const name = `on${cap(label)}Click`;
1278
1287
  if (!ctx.handlers || !ctx.scopes) return { scope, name };
1279
1288
  const key = `${scope}|${name}`;
@@ -1284,6 +1293,22 @@ function handlerScope(node, ctx, path, inner, label, at) {
1284
1293
  return { scope, name: n ? `on${cap(label)}${n + 1}Click` : name };
1285
1294
  }
1286
1295
 
1296
+ /**
1297
+ * Where a part sits, as a name: the place its frame is named for ("Row · Email
1298
+ * domain allowlist"), else the heading of its section, else the title of the
1299
+ * part before it (a step's Section), else its nearest named frame (a Toolbar),
1300
+ * else the page. A button's handler and an unlabelled control are named by it.
1301
+ */
1302
+ function placeOf(node, ctx, { figures = true } = {}) {
1303
+ const chain = ctx.chain ?? [];
1304
+ const frames = [...chain.slice(1)].reverse().filter((c) => c.type !== "SLOT" && !c.instance && /[A-Za-z]/.test(c.name ?? ""));
1305
+ const place = frames.map((c) => /\s·\s*(.*[A-Za-z].*)$/.exec(c.name)?.[1]).find(Boolean);
1306
+ const named = frames.find((c) => !UNNAMED_FRAME.test(c.name.trim()))?.name;
1307
+ const text = place ?? sectionHeading(node, chain) ?? titleBefore(node, chain) ?? named ?? "page";
1308
+ // A control's place leaves out a count Figma drew ("Replies 7" → replies; hub-481).
1309
+ return figures ? camelName(text) : nameOf(text, text);
1310
+ }
1311
+
1287
1312
  /**
1288
1313
  * The title of the nearest DS part before `target` that has one (a step's
1289
1314
  * Section, in its "Card · Claim" frame), looking up its frames.
@@ -1366,8 +1391,67 @@ function textNextTo(node, ctx) {
1366
1391
  /** The form controls the page owns: a value it passes and a change it hears (NODII-DEV-CLI-82, -83). */
1367
1392
  const FIELD_CONTROLS = { Input: "onChange", Textarea: "onChange", SelectField: "onValueChange", RadioGroup: "onValueChange" };
1368
1393
 
1369
- /** The form controls whose template may wire them with generic names, and the change each hears (hub-481). */
1370
- const NAMED_CHANGE = { ...FIELD_CONTROLS, MultiSelect: "onValueChange", DateTimePicker: "onChange", DatePicker: "onValueChange", DateRangePicker: "onChange" };
1394
+ /**
1395
+ * The form controls whose template wires them with its own generic names
1396
+ * (`onChange={onChange}`, `onValueChange={setView}`, `onChange={setAmountMinor}`):
1397
+ * the change each hears, the attribute its value takes, the word its value is
1398
+ * named by (a field's `value`; a view switch's `view`, a page size's `pageSize`,
1399
+ * an amount's `amountMinor`), whether a change is named with that word too
1400
+ * (`onPayPeriodPageSizeChange`), and whether the field names it (else its
1401
+ * place: a view switch and a page size sit by the list they change) (hub-481).
1402
+ */
1403
+ const fieldControl = (change, value = "value", word = "value") => ({ change, value, word, byField: true, withWord: false });
1404
+ const placedControl = (word) => ({ change: "onValueChange", value: "value", word, byField: false, withWord: true });
1405
+ const NAMED_CHANGE = {
1406
+ ...Object.fromEntries(Object.entries(FIELD_CONTROLS).map(([tag, change]) => [tag, fieldControl(change)])),
1407
+ MultiSelect: fieldControl("onValueChange"),
1408
+ DateTimePicker: fieldControl("onChange"),
1409
+ DatePicker: fieldControl("onValueChange"),
1410
+ DateRangePicker: fieldControl("onChange"),
1411
+ TimePicker: fieldControl("onValueChange"),
1412
+ CurrencyInput: fieldControl("onChange", "valueMinor", "amountMinor"),
1413
+ SegmentedControl: placedControl("view"),
1414
+ PageSizeSelect: placedControl("pageSize"),
1415
+ };
1416
+ /** The controls the page names from the field the Input family's own scope (fieldScope) already reads. */
1417
+ const INPUT_FAMILY = /^(?:Input|Textarea|SelectField)$/;
1418
+ /** A template's own value identifier, and its own setter or bare handler. */
1419
+ const GENERIC_VALUE = String.raw`\{(?:value|date|range|time|view|pageSize|amountMinor)\}`;
1420
+ const GENERIC_CHANGE = String.raw`\{(?:onChange|onValueChange|set[A-Z][A-Za-z0-9]*)\}`;
1421
+ /** Figma's sample value a template writes as a literal: text, a number, an object, a Date. */
1422
+ const SAMPLE_LITERAL = String.raw`"(?:[^"\\\n]|\\.)*"|\{-?\d+(?:\.\d+)?\}|\{Number\("(?:[^"\\\n]|\\.)*"\)\}|\{\{[^{}]*\}\}|\{new Date\([^()]*\)\}`;
1423
+ /** A name made of a date or time format ("dd/mm/yyyy" → ddMmYyyy): a placeholder, never a field. */
1424
+ const FORMAT_NAME = /^(?:dd|mm|yyyy|yy|hh|ss)(?:Dd|Mm|Yyyy|Yy|Hh|Ss)*$/;
1425
+ /** A name that starts with a verb a show flag, a setter or a handler is named by (hub-478). */
1426
+ const VERB_NAME = /^(?:show|set|on)(?:[A-Z]|$)/;
1427
+
1428
+ /**
1429
+ * The label a control is drawn with: its own label or title when its template
1430
+ * draws it and it is not a format, else the text just before it in its frame,
1431
+ * else the text just before its frame (a picker in its own sizing frame, under
1432
+ * "Effective from *"). Null when it has none.
1433
+ */
1434
+ function controlLabel(node, ctx, code) {
1435
+ const props = node.instance?.props ?? {};
1436
+ const own = [props.label, props.title].find((v) => typeof v === "string" && code.includes(JSON.stringify(v)) && nameText(v));
1437
+ if (own && !FORMAT_NAME.test(nameOf(own))) return nameOf(own);
1438
+ const words = (n) => {
1439
+ if (!n || n.visible === false || n.instance) return null;
1440
+ if (n.type === "TEXT") return nameText(n.text) && !RECORD_TEXT(n.text) ? n.text : null;
1441
+ for (const c of n.children ?? []) {
1442
+ const found = words(c);
1443
+ if (found) return found;
1444
+ }
1445
+ return null;
1446
+ };
1447
+ const before = (parent, target) => {
1448
+ const shown = (parent?.children ?? []).filter((c) => c.visible !== false);
1449
+ const at = shown.indexOf(target);
1450
+ return at > 0 ? words(shown[at - 1]) : null;
1451
+ };
1452
+ const text = before(ctx.parent, node) ?? (ctx.grand ? before(ctx.grand, ctx.parent) : null);
1453
+ return text ? nameOf(text) : null;
1454
+ }
1371
1455
 
1372
1456
  /**
1373
1457
  * A control the template half-controls (`defaultValue="chart"` beside
@@ -1429,14 +1513,32 @@ function fieldScope(node, ctx, code) {
1429
1513
  * apart by their place (resolveScopes) (hub-481).
1430
1514
  */
1431
1515
  function liftFieldControls(code, node, ctx, lift, scope) {
1516
+ const top = /^<([A-Za-z]+)/.exec(code.replace(/^<Field\b[^>]*>\s*/, ""))?.[1];
1432
1517
  code = rewriteTags(code, Object.keys(NAMED_CHANGE).join("|"), (attrs, tag) => {
1433
- const handler = NAMED_CHANGE[tag];
1434
- const change = new RegExp(String.raw`(^|\s)${handler}=\{(?:onChange|onValueChange|set(?:Value|Date|Range))\}`).exec(attrs);
1518
+ const { change: handler, value: valueAttr, word, byField, withWord } = NAMED_CHANGE[tag];
1519
+ const change = new RegExp(String.raw`(^|\s)${handler}=${GENERIC_CHANGE}`).exec(attrs);
1435
1520
  if (!change) return attrs;
1436
- const named = attrs.replace(change[0], `${change[1]}${handler}={${lift(scope, `on${cap(scope)}Change`)}}`);
1437
- const sample = String.raw`|"(?:[^"\\\n]|\\.)*"|\{\{[^{}]*\}\}|\{new Date\([^()]*\)\}`;
1438
- const value = new RegExp(String.raw`(^|\s)value=(?:\{(?:value|date|range)\}${/^Date/.test(tag) ? sample : ""})`).exec(named);
1439
- return value ? named.replace(value[0], `${value[1]}value={${lift(scope, `${scope}Value`)}}`) : named;
1521
+ // The Input family keeps the scope fieldScope gave it. A control another part's template draws
1522
+ // (a pager's page size) is that part's, as its button is (nameHandlers). Any other control is
1523
+ // named by its label, else (a field) the scope it was given unless that is a format or only
1524
+ // its set's name, else where it sits.
1525
+ // A label that reads as a verb ("Show") would name a show flag or a setter (resolveScopes), never a field.
1526
+ const beside = INPUT_FAMILY.test(tag) || tag !== top ? null : controlLabel(node, ctx, code);
1527
+ const label = INPUT_FAMILY.test(tag) || tag !== top ? scope : beside && !VERB_NAME.test(beside) ? beside : null;
1528
+ const unnamed = FORMAT_NAME.test(scope) || scope === camelName(node.instance?.set ?? "");
1529
+ const place = () => placeOf(node, ctx, { figures: false });
1530
+ const at = label ?? (byField && !unnamed ? scope : place());
1531
+ const valueName = word === "value" ? `${at}Value` : joinName(at, word);
1532
+ const changeName = `on${cap(withWord ? joinName(at, word) : at)}Change`;
1533
+ const value = `${valueAttr}={${lift(at, valueName)}}`;
1534
+ let next = attrs.replace(change[0], `${change[1]}${handler}={${lift(at, changeName)}}`);
1535
+ const sample = INPUT_FAMILY.test(tag) ? "" : `|${SAMPLE_LITERAL}`;
1536
+ const drawn = new RegExp(String.raw`(^|\s)(?:${valueAttr}=(?:${GENERIC_VALUE}${sample})|defaultValue=${LITERAL})`).exec(next);
1537
+ if (drawn) return next.replace(drawn[0], `${drawn[1]}${value}`);
1538
+ if (new RegExp(String.raw`(^|\s)${valueAttr}=`).test(next)) return next;
1539
+ // A control drawn empty (a Time Picker with no time) takes the page's value too.
1540
+ const sep = next.includes("\n") ? `\n${new RegExp(String.raw`\n(\s*)${handler}=`).exec(next)?.[1] ?? " "}` : " ";
1541
+ return next.replace(new RegExp(String.raw`(^|\s)${handler}=`), (m, sp) => `${sp}${value}${sep}${handler}=`);
1440
1542
  });
1441
1543
  // A field's placeholder is the page's too: in a Surface it is the value the frame shows
1442
1544
  // ("Last 30 days", "K*** M***", "Sep 2026"), and a search box's copy names the list
@@ -1463,6 +1565,7 @@ function liftFieldControls(code, node, ctx, lift, scope) {
1463
1565
  /** A metric card's values that are Figma's sample, never copy (NODII-DEV-CLI-84). */
1464
1566
  // statusTone and tone are the KPI's state ("Unresolved" warning or danger), never the sample's dot (hub-477).
1465
1567
  const METRIC_VALUES = ["value", "caption", "changeAmount", "period", "statusTone", "tone"];
1568
+ const TONE_ATTR = new Set(["statusTone", "tone"]);
1466
1569
 
1467
1570
  /**
1468
1571
  * Each opening tag of `names` (a regex alternation) in `code`, its attributes
@@ -1530,7 +1633,7 @@ function resolveScopes(views, scopes, layers = new Map()) {
1530
1633
  // A setter, a handler and a show flag keep their verb first (`onSaveClick`, `showSsoAdd`, hub-478).
1531
1634
  const scoped = (scope, name) => {
1532
1635
  const m = /^(set|on|show)([A-Z]\w*)$/.exec(name);
1533
- return m ? `${m[1]}${cap(scope)}${m[2]}` : `${scope}${cap(name)}`;
1636
+ return m ? `${m[1]}${cap(scope)}${m[2]}` : toneName(scope, name) ?? joinName(scope, name);
1534
1637
  };
1535
1638
  // A prefix that tells two layers apart, a word it shares with the name said once.
1536
1639
  const prefixed = (prefix, name) => {
@@ -1578,6 +1681,15 @@ function resolveScopes(views, scopes, layers = new Map()) {
1578
1681
  }
1579
1682
 
1580
1683
  /** `scope` then `name` in camelCase, a word they share at the join said once (`recordSwitcherScope` + `ScopeValue`). */
1684
+ /**
1685
+ * A KPI tone named by a stat whose label ends in its own status or state
1686
+ * ("Status", "Policy status", "Review state") says it once: `statusTone`,
1687
+ * `policyStatusTone`, `reviewStateTone`, never `reviewStateStatusTone` (hub-477).
1688
+ */
1689
+ function toneName(scope, name) {
1690
+ return name === "statusTone" && /^(?:status|state)$|[a-z0-9](?:Status|State)$/.test(scope) ? `${scope}Tone` : null;
1691
+ }
1692
+
1581
1693
  function joinName(scope, name) {
1582
1694
  const head = name[0].toUpperCase() + name.slice(1);
1583
1695
  const last = /[A-Z][a-z0-9]*$|^[a-z][a-z0-9]*$/.exec(scope)?.[0] ?? "";
@@ -2299,7 +2411,7 @@ function tabStrip(run, ctx) {
2299
2411
  if (counted[i]) trigger = trigger.replace(counted[i], `{${mark(ctx, strip, joinName(camelName(values[i]), "tabLabel"), null)}}`);
2300
2412
  // A tab's count badge counts the viewer's action items: the page's, named by its tab, never
2301
2413
  // Figma's sample (`actionableCount={5}`) or one count every tab shares; its floor ("99+") too (hub-477).
2302
- const own = (prop) => `${prop}={${mark(ctx, strip, joinName(camelName(values[i]), prop), null)}}`;
2414
+ const own = (prop) => `${prop}={${optionalMark(ctx, strip, joinName(camelName(values[i]), prop), null)}}`;
2303
2415
  trigger = trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bactionableCount=\{(?:\d+|(?:__s\d+_)?actionableCount)\}/, (_, head) => `${head}${own("actionableCount")}`);
2304
2416
  trigger = trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bcountIsFloor(?=\s|>)/, (_, head) => `${head}${own("countIsFloor")}`);
2305
2417
  return shownWhen(`(${visible}?.includes(${JSON.stringify(values[i])}) ?? true)`, indent(trigger, 3), 2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.150",
3
+ "version": "0.6.151",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {