@nodii/dev 0.6.139 → 0.6.140

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.139";
7
+ export const VERSION = "0.6.140";
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 = 13;
35
+ export const GENERATOR_FORMAT = 14;
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). */
@@ -528,6 +528,8 @@ export function emitSurface(tree, row, ds) {
528
528
  }
529
529
  const used = new Set();
530
530
  const scopes = new Map();
531
+ // Each layer a scope names: where it sits and the text that labels it (resolveScopes, hub-468).
532
+ const layers = new Map();
531
533
  // Each list's columns by name, across views (listScope).
532
534
  const shapes = new Map();
533
535
  const views = tree.variants.map((variant) => {
@@ -536,7 +538,7 @@ export function emitSurface(tree, row, ds) {
536
538
  used.add(state);
537
539
  const fn = `${pascal(state)}View`;
538
540
  const note = (path, kind, detail) => unmapped.push({ variant: variant.name, path, kind, detail });
539
- const emitted = emitNode(pageBody(variant, row), { depth: 2, parent: null, path: variant.name, ds, imports, note, root: true, scopes, state, lists: new Map(), shapes, handlers: new Map() }) ?? "";
541
+ const emitted = emitNode(pageBody(variant, row), { depth: 2, parent: null, path: variant.name, ds, imports, note, root: true, scopes, layers, layer: "", state, lists: new Map(), shapes, handlers: new Map() }) ?? "";
540
542
  // A view the generator can't lay out is no page at all: generation fails rather than ship
541
543
  // an empty view (NODII-DEV-CLI-81).
542
544
  if (emitted.trimStart().startsWith("{/*")) {
@@ -547,7 +549,7 @@ export function emitSurface(tree, row, ds) {
547
549
  const component = `${pascal(row.id)}Surface`;
548
550
  const stateType = `${component}State`;
549
551
  const propsType = `${component}Props`;
550
- resolveScopes(views, scopes);
552
+ resolveScopes(views, scopes, layers);
551
553
  const data = dataProps(views, propsType);
552
554
  const reactTypes = [data.size && "ComponentProps", [...data.values()].some((d) => /\bReactNode\b/.test(propType(d))) && "ReactNode"].filter(Boolean);
553
555
  const drawn = [...data.values()].some((d) => [...d.attrs.values(), ...[...d.members.values()].flatMap((refs) => [...refs.values()])].some((r) => r.keys));
@@ -767,11 +769,60 @@ function camelName(text) {
767
769
  return /^[a-z]/.test(name) ? name : `field${name.replace(/^./, (c) => c.toUpperCase())}`;
768
770
  }
769
771
 
772
+ /**
773
+ * A scope's key: its name and the layer that owns it (hub-468), so two
774
+ * layers that share a scope name never share a prop. A list's scope (listScope)
775
+ * is already its own, and is keyed by its name alone (`layer` null).
776
+ */
777
+ const scopeKey = (scope, layer) => (layer == null ? scope : `${scope}\u0000${layer}`);
778
+ const scopeIndex = (scopes, key) => (scopes.has(key) ? scopes.get(key) : scopes.set(key, scopes.size).get(key));
779
+
770
780
  /** `name` marked with `scope` (`__s<n>_name`), as scopeIdentifiers marks a template's identifiers. */
771
- function mark(ctx, scope, name) {
781
+ function mark(ctx, scope, name, layer = ctx.layer) {
772
782
  if (!ctx.scopes) return name;
773
- if (!ctx.scopes.has(scope)) ctx.scopes.set(scope, ctx.scopes.size);
774
- return `__s${ctx.scopes.get(scope)}_${name}`;
783
+ return `__s${scopeIndex(ctx.scopes, scopeKey(scope, layer))}_${name}`;
784
+ }
785
+
786
+ /**
787
+ * Where a node sits in its view, the same in every view that draws it: its
788
+ * layer names from the view's page down, a name its parent holds twice
789
+ * numbered (`Frame`, `Frame#1`). The view's own name is left out, so the same
790
+ * layer in another state view is the same layer, one prop (hub-468).
791
+ */
792
+ function layerOf(node, ctx) {
793
+ if (ctx.root) return "";
794
+ const same = (ctx.parent?.children ?? []).filter((c) => c.name === node.name);
795
+ const at = same.indexOf(node);
796
+ return `${ctx.layer ?? ""} › ${node.name}${at > 0 ? `#${at}` : ""}`;
797
+ }
798
+
799
+ /**
800
+ * The text that labels a part: the first text of the nearest sibling before it
801
+ * in its frame, else before its frame (a field's label row above its input).
802
+ * Text that is itself a record's value never labels. Null when it has none.
803
+ */
804
+ function labelBefore(node, ctx) {
805
+ const firstText = (n) => {
806
+ if (n.visible === false) return null;
807
+ if (n.type === "TEXT") return /[A-Za-z]/.test(n.text ?? "") && !RECORD_TEXT(n.text) ? n.text : null;
808
+ if (n.instance?.remote) return null;
809
+ for (const c of n.children ?? []) {
810
+ const found = firstText(c);
811
+ if (found) return found;
812
+ }
813
+ return null;
814
+ };
815
+ const before = (parent, target) => {
816
+ const shown = (parent?.children ?? []).filter((c) => c.visible !== false);
817
+ const at = shown.indexOf(target);
818
+ if (at <= 0) return null;
819
+ for (const c of shown.slice(0, at).reverse()) {
820
+ const found = firstText(c);
821
+ if (found) return found;
822
+ }
823
+ return null;
824
+ };
825
+ return before(ctx.parent, node) ?? (ctx.grand ? before(ctx.grand, ctx.parent) : null);
775
826
  }
776
827
 
777
828
  /** What the generator lifted from Figma's sample into the page's props: listed, not counted (NODII-DEV-CLI-82). */
@@ -813,10 +864,16 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
813
864
  out = out.replace(/<(Alert(Title|Description))>(\{"(?:[^"\\\n]|\\.)*"\})<\/\1>/g, (all, tag, part, lit) =>
814
865
  SAMPLE_VALUE.test(literalText(lit)) ? `<${tag}>{${lift(camelName(ctx.state ?? "alert"), `alert${part}`)}}</${tag}>` : all,
815
866
  );
816
- // An Empty State's text that names the record ("Apex Labs Pvt Ltd was closed on 30 Oct 2026").
817
- out = out.replace(/<EmptyState\b([^>]*?)(\/?)>/g, (all, attrs, close) =>
818
- `<EmptyState${attrs.replace(new RegExp(String.raw`\b(title|description)=(${LITERAL})`, "g"), (a, k, lit) => (SAMPLE_VALUE.test(literalText(lit)) ? `${k}={${lift(camelName(`${ctx.state ?? "empty"} empty`), k)}}` : a))}${close}>`,
819
- );
867
+ // An Empty State's title, description and action label are the page's: its copy depends on
868
+ // the list and the person ("No pay components yet" or "No custom components yet"), and
869
+ // Figma's sample ("Create item", a record's name) is never it (NODII-DEV-CLI-82, hub-468).
870
+ // They are named by the view's state, the default view's as the list's empty state.
871
+ const emptyScope = camelName(ctx.state && ctx.state !== "default" ? ctx.state : "empty");
872
+ out = rewriteTags(out, "EmptyState", (attrs) => {
873
+ const flat = maskStrings(attrs);
874
+ const topLevel = (at) => [...flat.slice(0, at)].reduce((d, c) => d + (c === "{") - (c === "}"), 0) === 0;
875
+ return attrs.replace(new RegExp(String.raw`(^|\s)(title|description|actionLabel)=(${LITERAL})`, "g"), (a, sp, k, _lit, at) => (topLevel(at) ? `${sp}${k}={${lift(emptyScope, joinName(emptyScope, k))}}` : a));
876
+ });
820
877
  // An Input Chip's label is a value the field holds, never copy.
821
878
  out = out.replace(/<InputChip\b([^>]*?)(\/?)>/g, (all, attrs, close) => {
822
879
  const label = new RegExp(String.raw`\blabel=${LITERAL}`).exec(attrs);
@@ -849,6 +906,42 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
849
906
  return `<Badge${toned}>{${lift(at, "label")}}</Badge>`;
850
907
  });
851
908
  }
909
+ // Every Checkbox and Switch is controlled by the page and named by the text beside it
910
+ // (`pfChecked`, `onPfCheckedChange`): Figma's tick is the sample, never a default, and the
911
+ // template's own `checked` / `onCheckedChange` (DESIGN-SYSTEM-508) never shared (hub-468).
912
+ if (TOGGLE.test(out)) {
913
+ out = rewriteTags(out, "Checkbox|Switch", (attrs) => {
914
+ const rest = attrs
915
+ .replace(new RegExp(String.raw`\s+(?:checked|onCheckedChange)=(?:${LITERAL}|\{[^{}]*\})`, "g"), "")
916
+ .replace(/\s+defaultChecked(?:=\{(?:true|false)\})?(?=[\s/>]|$)/g, "");
917
+ return ` checked={${lift(scope, joinName(scope, "checked"))}} onCheckedChange={${lift(scope, `on${cap(joinName(scope, "checkedChange"))}`)}}${rest}`;
918
+ });
919
+ }
920
+ // A record's progress, priority and amount, a chip's label and a step's status are the
921
+ // record's, never Figma's sample (hub-468). Each is named by where it sits (its frame,
922
+ // numbered among the same parts there); a step by its title, which is copy; an amount
923
+ // by its own setter (`onChange={setAmountMinor}` → `amountMinor`), so the two pair up.
924
+ const place = () => {
925
+ const same = (ctx.parent?.children ?? []).filter((c) => c.visible !== false && c.instance?.set === node.instance?.set);
926
+ return camelName(`${ctx.parent?.name ?? node.name}${same.length > 1 ? ` ${same.indexOf(node) + 1}` : ""}`);
927
+ };
928
+ out = rewriteTags(out, "Progress", (attrs) => attrs.replace(/(^|\s)value=\{-?\d+(?:\.\d+)?\}/, (a, sp) => `${sp}value={${lift(place(), joinName(place(), "value"))}}`));
929
+ out = rewriteTags(out, "PriorityChip", (attrs) => attrs.replace(new RegExp(String.raw`(^|\s)priority=${LITERAL}`), (a, sp) => `${sp}priority={${lift(place(), joinName(place(), "priority"))}}`));
930
+ out = rewriteTags(out, "CurrencyInput", (attrs) =>
931
+ attrs.replace(/(^|\s)valueMinor=\{-?\d+\}/, (a, sp) => {
932
+ const setter = /\bonChange=\{set([A-Z][A-Za-z0-9]*)\}/.exec(attrs);
933
+ return `${sp}valueMinor={${setter ? `${setter[1][0].toLowerCase()}${setter[1].slice(1)}` : lift(place(), joinName(place(), "valueMinor"))}}`;
934
+ }),
935
+ );
936
+ out = rewriteTags(out, "Stepper", (attrs) =>
937
+ attrs.replace(/(\btitle:\s*("(?:[^"\\\n]|\\.)*")\s*,\s*status:\s*)"[a-z_-]+"/g, (a, head, title) => {
938
+ const step = camelName(JSON.parse(title));
939
+ return `${head}${lift(step, joinName(step, "status"))}`;
940
+ }),
941
+ );
942
+ if (!ctx.inTable) {
943
+ out = out.replace(/^<Chip\b((?:[^>{"]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*\})*)>\s*([^<>{}\n]*[A-Za-z0-9][^<>{}\n]*?)\s*<\/Chip>$/, (all, attrs) => `<Chip${attrs}>{${lift(place(), joinName(place(), "label"))}}</Chip>`);
944
+ }
852
945
  out = rewriteTags(out, String.raw`Metric(?!CardGroup\b)[A-Za-z]*`, (attrs, tag) => {
853
946
  const name = new RegExp(String.raw`\b(?:title|label)=(${LITERAL})`).exec(attrs);
854
947
  const at = name ? camelName(literalText(name[1])) : scope;
@@ -1042,6 +1135,43 @@ function titleBefore(target, chain) {
1042
1135
  return null;
1043
1136
  }
1044
1137
 
1138
+ /** A Checkbox or Switch: on or off is the page's, never Figma's sample (DESIGN-SYSTEM-508, hub-468). */
1139
+ const TOGGLE = /^<(?:Checkbox|Switch)\b/;
1140
+
1141
+ /**
1142
+ * The text a box or switch is named by: the nearest text beside it in its
1143
+ * frame, after it first (a checkbox's label follows it), then before it (a
1144
+ * setting's label leads its switch); else the same beside its frame (a box
1145
+ * held in its own size frame). Null when it has none.
1146
+ */
1147
+ function textNextTo(node, ctx) {
1148
+ const words = (n) => {
1149
+ if (!n || n.visible === false) return null;
1150
+ if (n.type === "TEXT") return /[A-Za-z]/.test(n.text ?? "") && !RECORD_TEXT(n.text) ? n.text : null;
1151
+ if (n.instance?.remote) return null;
1152
+ for (const c of n.children ?? []) {
1153
+ const found = words(c);
1154
+ if (found) return found;
1155
+ }
1156
+ return null;
1157
+ };
1158
+ const beside = (parent, target) => {
1159
+ const shown = (parent?.children ?? []).filter((c) => c.visible !== false);
1160
+ const at = shown.indexOf(target);
1161
+ if (at === -1) return null;
1162
+ for (const c of shown.slice(at + 1)) {
1163
+ const found = words(c);
1164
+ if (found) return found;
1165
+ }
1166
+ for (const c of shown.slice(0, at).reverse()) {
1167
+ const found = words(c);
1168
+ if (found) return found;
1169
+ }
1170
+ return null;
1171
+ };
1172
+ return beside(ctx.parent, node) ?? (ctx.grand ? beside(ctx.grand, ctx.parent) : null);
1173
+ }
1174
+
1045
1175
  /** The form controls the page owns: a value it passes and a change it hears (NODII-DEV-CLI-82, -83). */
1046
1176
  const FIELD_CONTROLS = { Input: "onChange", Textarea: "onChange", SelectField: "onValueChange", RadioGroup: "onValueChange" };
1047
1177
 
@@ -1096,7 +1226,16 @@ function fieldScope(node, ctx, code) {
1096
1226
  * (a select's options), so two filters never share one.
1097
1227
  */
1098
1228
  function liftFieldControls(code, node, ctx, lift) {
1099
- return code.replace(/<(Input|Textarea|SelectField|RadioGroup)\b((?:[^>"{]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\})*?)(\s*\/?)>/g, (all, tag, attrs, close) => {
1229
+ // A field's placeholder is the page's too: in a Surface it is the value the frame shows
1230
+ // ("Last 30 days", "K*** M***", "Sep 2026"), and a search box's copy names the list
1231
+ // the page searches (hub-468). Named by the field, as its value is.
1232
+ const placeheld = rewriteTags(code, "Input|Textarea|SelectField", (attrs) => {
1233
+ const placeholder = new RegExp(String.raw`(^|\s)placeholder=${LITERAL}`).exec(attrs);
1234
+ if (!placeholder || [...maskStrings(attrs).slice(0, placeholder.index)].reduce((d, c) => d + (c === "{") - (c === "}"), 0) !== 0) return attrs;
1235
+ const scope = fieldScope(node, ctx, code);
1236
+ return attrs.replace(placeholder[0], `${placeholder[1]}placeholder={${lift(scope, `${scope}Placeholder`)}}`);
1237
+ });
1238
+ return placeheld.replace(/<(Input|Textarea|SelectField|RadioGroup)\b((?:[^>"{]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\})*?)(\s*\/?)>/g, (all, tag, attrs, close) => {
1100
1239
  if (/\b(value|onChange|onValueChange)=/.test(attrs) || /\{\.\.\./.test(attrs)) return all;
1101
1240
  const scope = fieldScope(node, ctx, code);
1102
1241
  const sep = attrs.includes("\n") ? `\n${/\n(\s*)/.exec(attrs)[1]}` : " ";
@@ -1148,9 +1287,8 @@ const CONTROLLED_TABS = (value, onChange) => `<Tabs panelless value={${value}} o
1148
1287
  * scope (`__s<n>_date`); resolveScopes later keeps the plain name or scopes it.
1149
1288
  * An identifier already marked (an inner instance's, in a slot) keeps its own.
1150
1289
  */
1151
- function scopeIdentifiers(code, scope, scopes) {
1152
- if (!scopes.has(scope)) scopes.set(scope, scopes.size);
1153
- const n = scopes.get(scope);
1290
+ function scopeIdentifiers(code, scope, scopes, layer = null) {
1291
+ const n = scopeIndex(scopes, scopeKey(scope, layer));
1154
1292
  let out = code;
1155
1293
  for (const { at, name } of freeIdentifiers(code).reverse()) out = `${out.slice(0, at)}__s${n}_${name}${out.slice(at + name.length)}`;
1156
1294
  return out;
@@ -1161,18 +1299,105 @@ function scopeIdentifiers(code, scope, scopes) {
1161
1299
  * Date Picker's `date` and `setDate` under "Expires" become
1162
1300
  * `expiresDate` and `setExpiresDate`, so two inputs never share a value, a list
1163
1301
  * of options or a setter. An identifier one instance alone emits keeps its name.
1302
+ *
1303
+ * Two layers one view draws whose names still come out the same (two frames
1304
+ * both named "Frame", a filter and a record field both labelled "Setting") are
1305
+ * told apart by what sets them apart in that view: the text that labels each,
1306
+ * else the first of their ancestors whose names differ, else their order
1307
+ * (hub-468). Layers in different views that no view draws together
1308
+ * stay one prop: the same field drawn again in another state view.
1164
1309
  */
1165
- function resolveScopes(views, scopes) {
1166
- const names = [...scopes.keys()];
1310
+ function resolveScopes(views, scopes, layers = new Map()) {
1311
+ const keys = [...scopes.keys()].map((k) => {
1312
+ const [scope, layer = null] = k.split("\u0000");
1313
+ return { scope, layer };
1314
+ });
1167
1315
  const marked = /__s(\d+)_([a-z][A-Za-z0-9]*)/g;
1168
- const users = new Map();
1169
- for (const view of views) for (const m of view.body.matchAll(marked)) (users.get(m[2]) ?? users.set(m[2], new Set()).get(m[2])).add(m[1]);
1316
+ const cap = (s) => s[0].toUpperCase() + s.slice(1);
1170
1317
  const scoped = (scope, name) => {
1171
- const cap = (s) => s[0].toUpperCase() + s.slice(1);
1172
1318
  const m = /^(set|on)([A-Z]\w*)$/.exec(name);
1173
1319
  return m ? `${m[1]}${cap(scope)}${m[2]}` : `${scope}${cap(name)}`;
1174
1320
  };
1175
- for (const view of views) view.body = view.body.replace(marked, (_, n, name) => (users.get(name).size > 1 ? scoped(names[Number(n)], name) : name));
1321
+ // A prefix that tells two layers apart, a word it shares with the name said once.
1322
+ const prefixed = (prefix, name) => {
1323
+ const m = /^(set|on)([A-Z]\w*)$/.exec(name);
1324
+ return m ? `${m[1]}${joinName(cap(prefix), m[2])}` : joinName(prefix, name);
1325
+ };
1326
+ // Which scope names emit each identifier, and each marked token with the views that draw it.
1327
+ const users = new Map();
1328
+ const tokens = new Map();
1329
+ views.forEach((view, v) => {
1330
+ for (const m of view.body.matchAll(marked)) {
1331
+ (users.get(m[2]) ?? users.set(m[2], new Set()).get(m[2])).add(keys[Number(m[1])].scope);
1332
+ const t = tokens.get(m[0]) ?? tokens.set(m[0], { n: Number(m[1]), name: m[2], views: new Set() }).get(m[0]);
1333
+ t.views.add(v);
1334
+ }
1335
+ });
1336
+ const named = new Map();
1337
+ const byName = new Map();
1338
+ for (const [token, t] of tokens) {
1339
+ const plain = users.get(t.name).size > 1 ? scoped(keys[t.n].scope, t.name) : t.name;
1340
+ named.set(token, plain);
1341
+ const owners = byName.get(plain) ?? byName.set(plain, new Map()).get(plain);
1342
+ const layer = keys[t.n].layer ?? `\u0000${keys[t.n].scope}`;
1343
+ const o = owners.get(layer) ?? owners.set(layer, { tokens: [], views: new Set() }).get(layer);
1344
+ o.tokens.push(token);
1345
+ for (const v of t.views) o.views.add(v);
1346
+ }
1347
+ const taken = new Set(byName.keys());
1348
+ for (const [plain, owners] of byName) {
1349
+ const list = [...owners.entries()].map(([layer, o]) => ({ layer, ...o }));
1350
+ // Each view's layers of this name: only two in one view are a clash.
1351
+ const together = views.map((_, v) => list.filter((o) => o.views.has(v)));
1352
+ if (!together.some((inView) => inView.length > 1)) continue;
1353
+ const prefixes = distinguish(list, together, layers);
1354
+ list.forEach((o, i) => {
1355
+ const prefix = prefixes[i];
1356
+ let name = prefix === "" ? plain : prefixed(prefix, plain);
1357
+ if (name !== plain && taken.has(name) && !list.some((x, j) => j < i && prefixes[j] === prefix)) for (let k = 2; taken.has(name); k++) name = `${name.replace(/\d+$/, "")}${k}`;
1358
+ taken.add(name);
1359
+ for (const token of o.tokens) named.set(token, name);
1360
+ });
1361
+ }
1362
+ for (const view of views) view.body = view.body.replace(marked, (token) => named.get(token));
1363
+ }
1364
+
1365
+ /** `scope` then `name` in camelCase, a word they share at the join said once (`recordSwitcherScope` + `ScopeValue`). */
1366
+ function joinName(scope, name) {
1367
+ const head = name[0].toUpperCase() + name.slice(1);
1368
+ const last = /[A-Z][a-z0-9]*$|^[a-z][a-z0-9]*$/.exec(scope)?.[0] ?? "";
1369
+ const first = /^[A-Z][a-z0-9]*/.exec(head)[0];
1370
+ return last && last.toLowerCase() === first.toLowerCase() ? `${scope}${head.slice(first.length)}` : `${scope}${head}`;
1371
+ }
1372
+
1373
+ /**
1374
+ * What tells apart the layers that share one name, one camelCase prefix each:
1375
+ * the first level at which every view's layers differ, nearest first, of the
1376
+ * text that labels each (`Last reviewed`), then their ancestors (`Card · RSVP`
1377
+ * and `Replies`); a name that differs only by its number among siblings, or
1378
+ * that carries a figure (Figma's sample, "14 filled"), tells nothing. Layers no
1379
+ * view draws together may share a prefix (one prop). When no level does, each
1380
+ * takes its order in the first view that draws it ("", "second", …).
1381
+ */
1382
+ const ORDINALS = ["", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"];
1383
+ function distinguish(list, together, layers) {
1384
+ const levels = list.map((o) => {
1385
+ const info = layers.get(o.layer);
1386
+ return [info?.label ?? null, ...(info?.segments ?? []).slice(0, -1).reverse()];
1387
+ });
1388
+ const depth = Math.max(...levels.map((l) => l.length));
1389
+ for (let d = 0; d < depth; d++) {
1390
+ const at = levels.map((l) => (l[d] && !RECORD_TEXT(l[d]) ? camelName(l[d]) : null));
1391
+ const fits = together.every((inView) => {
1392
+ if (inView.length < 2) return true;
1393
+ const names = inView.map((o) => at[list.indexOf(o)]);
1394
+ return names.every((x) => x && !/^field/.test(x)) && new Set(names).size === names.length;
1395
+ });
1396
+ if (fits) return at.map((x) => x ?? "");
1397
+ }
1398
+ const order = list.map(() => null);
1399
+ for (const inView of together) inView.forEach((o, k) => (order[list.indexOf(o)] ??= ORDINALS[k] ?? `item${k + 1}`));
1400
+ return order.map((x) => x ?? "");
1176
1401
  }
1177
1402
 
1178
1403
  function dataProps(views, propsType) {
@@ -1488,6 +1713,12 @@ const comment = (text) => `{/* ${text.replace(/\*\//g, "* /")} */}`;
1488
1713
 
1489
1714
  function emitNode(node, ctx) {
1490
1715
  if (node.visible === false) return null;
1716
+ // A tab probe (tabOf) emits a child with no parent, to read its template: it never names a layer.
1717
+ if (ctx.scopes && !ctx.tabProbe) {
1718
+ const layer = layerOf(node, ctx);
1719
+ if (!ctx.layers.has(layer)) ctx.layers.set(layer, { segments: layer.split(" › ").slice(1).map((s) => s.replace(/#\d+$/, "")), label: labelBefore(node, ctx) });
1720
+ ctx = { ...ctx, layer };
1721
+ }
1491
1722
  const { ds, note, depth, parent, root } = ctx;
1492
1723
  const path = root ? ctx.path : `${ctx.path} › ${node.name}`;
1493
1724
  // Every node's ancestors, nearest last: a list is named by the section heading before it (hub-454).
@@ -1522,7 +1753,7 @@ function emitNode(node, ctx) {
1522
1753
  return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
1523
1754
  }
1524
1755
  const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
1525
- const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, chain: slotNode ? [...chain, slotNode] : chain };
1756
+ const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, chain: slotNode ? [...chain, slotNode] : chain, layer: `${ctx.layer} › ${prop}` };
1526
1757
  const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
1527
1758
  return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
1528
1759
  };
@@ -1539,10 +1770,11 @@ function emitNode(node, ctx) {
1539
1770
  // A tab strip the page controls (tabOf reads the template's own strip first, to gather a run).
1540
1771
  if (!ctx.tabProbe) own = own.replace(/<Tabs panelless(?: defaultValue="[^"]*")?>/g, CONTROLLED_TABS("tab", "onTabChange"));
1541
1772
  const control = /^<(?:Input|Textarea|SelectField)\b/.test(own.replace(/^<Field\b[^>]*>\s*/, ""));
1542
- const scope = control ? fieldScope(node, ctx, own) : scopeName(node, own, ctx);
1773
+ const toggle = TOGGLE.test(own) ? textNextTo(node, ctx) : null;
1774
+ const scope = control ? fieldScope(node, ctx, own) : toggle ? camelName(toggle) : scopeName(node, own, ctx);
1543
1775
  own = nameHandlers(own, node, ctx, path, scope);
1544
1776
  own = controlHalfControlled(liftRecordData(own, node, ctx, path, scope));
1545
- const code = ctx.scopes ? scopeIdentifiers(own, scope, ctx.scopes) : own;
1777
+ const code = ctx.scopes ? scopeIdentifiers(own, scope, ctx.scopes, ctx.layer) : own;
1546
1778
  // A Table part is valid only inside the DS Table. One the generator could not assemble
1547
1779
  // into a Table stays reported, never passed off as mapped (MW8-17.3).
1548
1780
  const tag = /^<([A-Za-z]+)/.exec(code)?.[1];
@@ -1668,7 +1900,7 @@ function descriptionRun(run, ctx) {
1668
1900
  const { depth, path } = ctx;
1669
1901
  const { open, imports } = descriptionOf(run[0], ctx);
1670
1902
  ctx.imports.push(...imports);
1671
- const items = mark(ctx, listScope(run[0], ctx, scopeName(ctx.parent ?? { name: "items" })), "items");
1903
+ const items = mark(ctx, listScope(run[0], ctx, scopeName(ctx.parent ?? { name: "items" })), "items", null);
1672
1904
  ctx.note(path, LIFTED, `${run.length} sibling Description Lists lifted as one list of items (NODII-DEV-CLI-82)`);
1673
1905
  const list = [
1674
1906
  `<DescriptionList${open}>`,
@@ -1711,7 +1943,7 @@ function tabStrip(run, ctx) {
1711
1943
  const triggers = tabs.map((t, i) => indent(t.trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bvalue="tab"/, `$1value="${values[i]}"`), 2));
1712
1944
  return [
1713
1945
  // The page controls which tab is shown (NODII-DEV-CLI-83); Figma's selected tab is only the drawn one.
1714
- indent(CONTROLLED_TABS(mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "tab"), mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "onTabChange")), depth),
1946
+ indent(CONTROLLED_TABS(mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "tab", null), mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "onTabChange", null)), depth),
1715
1947
  indent(" <TabsList>", depth),
1716
1948
  ...triggers.map((t) => indent(t, depth)),
1717
1949
  indent(" </TabsList>", depth),
@@ -1780,6 +2012,10 @@ function openTagEnd(code) {
1780
2012
  }
1781
2013
  return code.length - 1;
1782
2014
  }
2015
+ /** The copy a Table head shows until a Surface sets it: Figma's placeholder, never a column's name (hub-468). */
2016
+ const HEAD_PLACEHOLDER = /^\s*table heading\s*$/i;
2017
+ const HEAD_PLACEHOLDER_CHILD = /(<Table(?:Sort)?Head\b[^\n]*>\s*)\{"\s*[Tt]able heading\s*"\}/;
2018
+
1783
2019
  function tableOf(node, ctx) {
1784
2020
  const shown = (node.children ?? []).filter((c) => c.visible !== false);
1785
2021
  // What follows the rows (a table's Empty State, bare or in its own frame) follows the Table:
@@ -1936,7 +2172,8 @@ function tableOf(node, ctx) {
1936
2172
  for (let i = 0; i < count; i++) {
1937
2173
  const head = headRow?.cells[i];
1938
2174
  const text = head?.code ? (/\{"((?:[^"\\\n]|\\.)*)"\}/.exec(head.code)?.[1] ?? /\blabel="([^"]*)"/.exec(head.code)?.[1] ?? "") : "";
1939
- let key = /[A-Za-z0-9]/.test(text) ? camelName(text) : `column${i + 1}`;
2175
+ // Figma's placeholder copy ("Table heading") names no column: it is keyed by position.
2176
+ let key = /[A-Za-z0-9]/.test(text) && !HEAD_PLACEHOLDER.test(text) ? camelName(text) : `column${i + 1}`;
1940
2177
  while (keys.includes(key) || key === "id") key = `${key}${i + 1}`;
1941
2178
  keys.push(key);
1942
2179
  }
@@ -1951,19 +2188,22 @@ function tableOf(node, ctx) {
1951
2188
  // drawn sort="asc" are Figma's sample.
1952
2189
  const controlSort = (code, key) => {
1953
2190
  if (!key || !/^\s*<TableSortHead\b/.test(code ?? "")) return code;
1954
- const [by, dir, change] = ["sortBy", "sortDir", "onSortChange"].map((n) => mark(ctx, listName, n));
2191
+ const [by, dir, change] = ["sortBy", "sortDir", "onSortChange"].map((n) => mark(ctx, listName, n, null));
1955
2192
  const k = JSON.stringify(key);
1956
2193
  return code
1957
2194
  .replace(/(<TableSortHead\b[^>]*?) sort="(?:asc|desc)"/, "$1")
1958
2195
  .replace(/\bonSort=\{(?:__s\d+_)?onSort\}/, `sort={${by} === ${k} ? ${dir} : false} onSort={${change} && (() => ${change}(${k}, ${by} === ${k} && ${dir} === "asc" ? "desc" : "asc"))}`);
1959
2196
  };
2197
+ // A head that still shows Figma's placeholder copy draws no header the page can read:
2198
+ // its copy is a prop, named by its column, in the list's scope (hub-468).
2199
+ const liftHeading = (code, key) => (key ? code.replace(HEAD_PLACEHOLDER_CHILD, (_, open) => `${open}{${mark(ctx, listName, `${key}Heading`, null)}}`) : code);
1960
2200
  const liftable = !skeleton && dataRows.length > 0 && dataRows.every((p) => !p.unrecognised && !p.framesOnly && p.cells.length === dataRows[0].cells.length) && (!headRow || headRow.cells.length === dataRows[0].cells.length);
1961
2201
  const liftedRows = () => {
1962
2202
  const first = dataRows[0];
1963
2203
  const keys = columnKeys(first.cells.length);
1964
- const rowsName = mark(ctx, listName, "rows");
2204
+ const rowsName = mark(ctx, listName, "rows", null);
1965
2205
  // A row is a door to its record when the page passes a handler (U03-7; NODII-DEV-CLI-83).
1966
- const rowClick = mark(ctx, listName, "onRowClick");
2206
+ const rowClick = mark(ctx, listName, "onRowClick", null);
1967
2207
  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)`);
1968
2208
  const cells = first.cells.map((c, i) => {
1969
2209
  const w = columnWidth(c.cell);
@@ -1995,7 +2235,7 @@ function tableOf(node, ctx) {
1995
2235
  ? [skeletonRows()]
1996
2236
  : kind === "body" && liftable
1997
2237
  ? liftedRows()
1998
- : list.flatMap((p) => (p.unrecognised ? [indent(comment(p.unrecognised), depth + 2)] : [indent("<TableRow>", depth + 2), ...p.cells.map((c, i) => (p === headRow ? controlSort(cellCode(c, p.row, depth + 3, headKeys[i]), headKeys[i]) : cellCode(c, p.row, depth + 3, null))), indent("</TableRow>", depth + 2)]))),
2238
+ : list.flatMap((p) => (p.unrecognised ? [indent(comment(p.unrecognised), depth + 2)] : [indent("<TableRow>", depth + 2), ...p.cells.map((c, i) => (p === headRow ? liftHeading(controlSort(cellCode(c, p.row, depth + 3, headKeys[i]), headKeys[i]), headKeys[i]) : cellCode(c, p.row, depth + 3, null))), indent("</TableRow>", depth + 2)]))),
1999
2239
  indent(`</${tag}>`, depth + 1),
2000
2240
  ];
2001
2241
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.139",
3
+ "version": "0.6.140",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {