@nodii/dev 0.6.128 → 0.6.129

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.128";
7
+ export const VERSION = "0.6.129";
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 = 9;
35
+ export const GENERATOR_FORMAT = 10;
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). */
@@ -623,7 +623,9 @@ function freeIdentifiers(code) {
623
623
  * or title property, else its layer name, in camelCase (`Subject kind` →
624
624
  * `subjectKind`).
625
625
  */
626
- function scopeName(node) {
626
+ function scopeName(node, ctx = {}) {
627
+ // A dialog's title is the record's (lifted), so the dialog is named by its view.
628
+ if (/Dialog$/.test(node.instance?.set ?? "") && ctx.state) return camelName(ctx.state);
627
629
  const props = node.instance?.props ?? {};
628
630
  const text = [props.label, props.title].find((v) => typeof v === "string" && /[A-Za-z0-9]/.test(v)) ?? node.name ?? "";
629
631
  return camelName(text);
@@ -670,7 +672,21 @@ const literalText = (lit) => JSON.parse(lit.startsWith("{") ? lit.slice(1, -1) :
670
672
  function liftRecordData(code, node, ctx, path) {
671
673
  const lifted = [];
672
674
  const lift = (scope, name) => (lifted.push(name), mark(ctx, scope, name));
673
- let out = code.replace(new RegExp(String.raw`<((?:Alert)?Dialog(Title|Description))\b([^>]*)>\{"(?:[^"\\\n]|\\.)*"\}</\1>`, "g"), (_, tag, part, attrs) => `<${tag}${attrs}>{${lift(camelName(ctx.state ?? "dialog"), part.toLowerCase())}}</${tag}>`);
675
+ let out = liftFieldControls(code, node, ctx, lift);
676
+ // An Alert's title or description that names a record's value (a date, an amount, a code).
677
+ out = out.replace(/<(Alert(Title|Description))>(\{"(?:[^"\\\n]|\\.)*"\})<\/\1>/g, (all, tag, part, lit) =>
678
+ SAMPLE_VALUE.test(literalText(lit)) ? `<${tag}>{${lift(camelName(ctx.state ?? "alert"), `alert${part}`)}}</${tag}>` : all,
679
+ );
680
+ // An Empty State's text that names the record ("Apex Labs Pvt Ltd was closed on 30 Oct 2026").
681
+ out = out.replace(/<EmptyState\b([^>]*?)(\/?)>/g, (all, attrs, close) =>
682
+ `<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}>`,
683
+ );
684
+ // An Input Chip's label is a value the field holds, never copy.
685
+ out = out.replace(/<InputChip\b([^>]*?)(\/?)>/g, (all, attrs, close) => {
686
+ const label = new RegExp(String.raw`\blabel=${LITERAL}`).exec(attrs);
687
+ return label ? `<InputChip${attrs.replace(label[0], `label={${lift(positionScope(node, ctx, "chip"), "label")}}`)}${close}>` : all;
688
+ });
689
+ out = out.replace(new RegExp(String.raw`<((?:Alert)?Dialog(Title|Description))\b([^>]*)>\{"(?:[^"\\\n]|\\.)*"\}</\1>`, "g"), (_, tag, part, attrs) => `<${tag}${attrs}>{${lift(camelName(ctx.state ?? "dialog"), part.toLowerCase())}}</${tag}>`);
674
690
  out = out.replace(/<DescriptionItem\b([^>]*?)\/>/g, (all, attrs) => {
675
691
  const value = new RegExp(String.raw`\bvalue=${LITERAL}`).exec(attrs);
676
692
  if (!value) return all;
@@ -681,8 +697,7 @@ function liftRecordData(code, node, ctx, path) {
681
697
  out = out.replace(/<StatusPill\b([^>]*?)(\/?)>/g, (all, attrs, close) => {
682
698
  const label = new RegExp(String.raw`\blabel=${LITERAL}`).exec(attrs);
683
699
  if (!label) return all;
684
- const siblings = (ctx.parent?.children ?? []).filter((c) => c.visible !== false && c.instance?.set === node.instance?.set);
685
- const scope = camelName(`${ctx.parent?.name ?? "status"} status${siblings.length > 1 ? ` ${siblings.indexOf(node) + 1}` : ""}`);
700
+ const scope = positionScope(node, ctx, "status");
686
701
  const tone = new RegExp(String.raw`\btone=${LITERAL}`).exec(attrs);
687
702
  let next = attrs.replace(label[0], `label={${lift(scope, "label")}}`);
688
703
  next = tone ? next.replace(tone[0], `tone={${lift(scope, "tone")}}`) : next.replace(`label={`, `tone={${lift(scope, "tone")}} label={`);
@@ -692,6 +707,83 @@ function liftRecordData(code, node, ctx, path) {
692
707
  return out;
693
708
  }
694
709
 
710
+ /**
711
+ * Text that names a record's value, not copy: an amount (₹51,900), a date
712
+ * (31 Oct, 09 Oct 2026), an email, a domain or a record code (PAY-8821,
713
+ * CYC-2026-10-HR). Such text is Figma's sample and is lifted (NODII-DEV-CLI-82).
714
+ */
715
+ export const SAMPLE_VALUE = /₹\s?\d|\b\d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b|[\w.+-]+@[a-z0-9-]+\.[a-z]|\b[a-z0-9-]+\.(?:com|in|io|co|org|net)\b|\b[A-Z]{2,5}-\d[\w-]*\b/;
716
+
717
+ /** A part named by where it sits: its parent's name, numbered when the parent holds several of the same set. */
718
+ function positionScope(node, ctx, kind) {
719
+ const siblings = (ctx.parent?.children ?? []).filter((c) => c.visible !== false && (node.instance ? c.instance?.set === node.instance.set : c.type === node.type));
720
+ return camelName(`${ctx.parent?.name ?? kind} ${kind}${siblings.length > 1 ? ` ${siblings.indexOf(node) + 1}` : ""}`);
721
+ }
722
+
723
+ /** The form controls the page owns: a value it passes and a change it hears (NODII-DEV-CLI-82, -83). */
724
+ const FIELD_CONTROLS = { Input: "onChange", Textarea: "onChange", SelectField: "onValueChange", RadioGroup: "onValueChange" };
725
+
726
+ /**
727
+ * A control the template half-controls (`defaultValue="chart"` beside
728
+ * `onValueChange={setView}`, a Segmented Control's view switch), or that
729
+ * hears a change with no value at all, takes its
730
+ * value from the page too: `value={view}`, so the page can set the view it
731
+ * shows, not only hear it change (NODII-DEV-CLI-83).
732
+ */
733
+ export function controlHalfControlled(code) {
734
+ return code.replace(/<([A-Z][A-Za-z]*)\b((?:[^>"{]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\})*?)(\s*\/?)>/g, (all, tag, attrs, close) => {
735
+ const setter = /\bonValueChange=\{set([A-Z][A-Za-z0-9]*)\}/.exec(attrs);
736
+ const sample = new RegExp(String.raw`\bdefaultValue=${LITERAL}`).exec(attrs);
737
+ if (!setter || /\bvalue=/.test(attrs)) return all;
738
+ const value = `value={${setter[1][0].toLowerCase()}${setter[1].slice(1)}}`;
739
+ const sep = attrs.includes("\n") ? `\n${/\n(\s*)onValueChange=/.exec(attrs)?.[1] ?? " "}` : " ";
740
+ return `<${tag}${sample ? attrs.replace(sample[0], value) : attrs.replace(setter[0], `${value}${sep}${setter[0]}`)}${close}>`;
741
+ });
742
+ }
743
+ const cap = (s) => s[0].toUpperCase() + s.slice(1);
744
+ const kebab = (s) => s.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
745
+
746
+ /**
747
+ * What a form control's value is named by: a filter's own placeholder
748
+ * ("Status: All" → status), the label drawn just before it ("Organisation
749
+ * name"), a search box (search), else its layer name.
750
+ */
751
+ function fieldScope(node, ctx, attrs) {
752
+ const props = node.instance?.props ?? {};
753
+ const own = [props.label, props.title].find((v) => typeof v === "string" && /[A-Za-z]/.test(v));
754
+ if (own) return camelName(own);
755
+ const placeholder = new RegExp(String.raw`\bplaceholder=(${LITERAL})`).exec(attrs);
756
+ const hint = placeholder ? literalText(placeholder[1]) : "";
757
+ if (/^[^:]{1,32}:/.test(hint)) return camelName(hint.split(":")[0]);
758
+ const shown = (ctx.parent?.children ?? []).filter((c) => c.visible !== false);
759
+ const before = shown[shown.indexOf(node) - 1];
760
+ if (before?.type === "TEXT" && /[A-Za-z]/.test(before.text ?? "") && !/:\s*$/.test(before.text)) return camelName(before.text);
761
+ if (/^search\b/i.test(hint)) return "search";
762
+ const layer = camelName(node.name);
763
+ return layer === camelName(node.instance?.set ?? "") || !layer ? camelName(hint) || "field" : layer;
764
+ }
765
+
766
+ /**
767
+ * Every Input, Textarea and SelectField is controlled by the page: Figma's
768
+ * sample value (`defaultValue="Apex Labs Pvt Ltd"`) becomes the page's value,
769
+ * and a change calls back. A SelectField's id is its own, not the template's
770
+ * shared `id="select"`. The scope also names the template's own identifiers
771
+ * (a select's options), so two filters never share one.
772
+ */
773
+ function liftFieldControls(code, node, ctx, lift) {
774
+ return code.replace(/<(Input|Textarea|SelectField|RadioGroup)\b((?:[^>"{]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\})*?)(\s*\/?)>/g, (all, tag, attrs, close) => {
775
+ if (/\b(value|onChange|onValueChange)=/.test(attrs) || /\{\.\.\./.test(attrs)) return all;
776
+ const scope = fieldScope(node, ctx, attrs);
777
+ const sep = attrs.includes("\n") ? `\n${/\n(\s*)/.exec(attrs)[1]}` : " ";
778
+ const value = `value={${lift(scope, `${scope}Value`)}}`;
779
+ const change = `${FIELD_CONTROLS[tag]}={${lift(scope, `on${cap(scope)}Change`)}}`;
780
+ let next = attrs.replace(/\bid="select"/, `id="${kebab(scope)}"`);
781
+ const sample = new RegExp(String.raw`\bdefaultValue=${LITERAL}`).exec(next);
782
+ next = sample ? next.replace(sample[0], `${value}${sep}${change}`) : `${next}${sep}${value}${sep}${change}`;
783
+ return `<${tag}${next}${close}>`;
784
+ });
785
+ }
786
+
695
787
  /** Tabs the page controls: its tab is a prop, and choosing one calls back (NODII-DEV-CLI-83). */
696
788
  const CONTROLLED_TABS = (value, onChange) => `<Tabs panelless value={${value}} onValueChange={${onChange}}>`;
697
789
 
@@ -1062,8 +1154,9 @@ function emitNode(node, ctx) {
1062
1154
  let own = rendered.code.trim().replace(/=\{<>\{([a-z][A-Za-z0-9]*)\}<\/>\}/g, "={$1}");
1063
1155
  // A tab strip the page controls (tabOf reads the template's own strip first, to gather a run).
1064
1156
  if (!ctx.tabProbe) own = own.replace(/<Tabs panelless(?: defaultValue="[^"]*")?>/g, CONTROLLED_TABS("tab", "onTabChange"));
1065
- own = liftRecordData(own, node, ctx, path);
1066
- const code = ctx.scopes ? scopeIdentifiers(own, scopeName(node), ctx.scopes) : own;
1157
+ own = controlHalfControlled(liftRecordData(own, node, ctx, path));
1158
+ const control = /^<(?:Input|Textarea|SelectField)\b/.test(own.replace(/^<Field\b[^>]*>\s*/, ""));
1159
+ const code = ctx.scopes ? scopeIdentifiers(own, control ? fieldScope(node, ctx, own) : scopeName(node, ctx), ctx.scopes) : own;
1067
1160
  // A Table part is valid only inside the DS Table. One the generator could not assemble
1068
1161
  // into a Table stays reported, never passed off as mapped (MW8-17.3).
1069
1162
  const tag = /^<([A-Za-z]+)/.exec(code)?.[1];
@@ -1091,7 +1184,15 @@ function emitNode(node, ctx) {
1091
1184
  { CENTER: "text-center", RIGHT: "text-right", JUSTIFIED: "text-justify" }[node.align],
1092
1185
  node.maxLines === 1 ? "truncate" : node.maxLines ? `line-clamp-${node.maxLines}` : null,
1093
1186
  ]);
1094
- return indent(`<span${classes ? ` className="${classes}"` : ""}>{${JSON.stringify(node.text)}}</span>`, depth);
1187
+ // Text naming a record's value (a date, an amount, a code) is Figma's sample: the page's own (NODII-DEV-CLI-82).
1188
+ let content = JSON.stringify(node.text);
1189
+ if (SAMPLE_VALUE.test(node.text) && !ctx.textOwner) {
1190
+ const scope = positionScope(node, ctx, "text");
1191
+ const name = mark(ctx, scope, scope);
1192
+ note(path, LIFTED, `text ${shown} names a record's value: lifted from Figma's sample into the page's props (NODII-DEV-CLI-82)`);
1193
+ content = name;
1194
+ }
1195
+ return indent(`<span${classes ? ` className="${classes}"` : ""}>{${content}}</span>`, depth);
1095
1196
  }
1096
1197
 
1097
1198
  // A shape is not a DS part: it is marked and reported, never drawn as a look-alike (MW2-37.2).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.128",
3
+ "version": "0.6.129",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {