@nodii/dev 0.6.142 → 0.6.144

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.142";
7
+ export const VERSION = "0.6.144";
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 = 15;
35
+ export const GENERATOR_FORMAT = 16;
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). */
@@ -1091,9 +1091,40 @@ function nameHandlers(code, node, ctx, path, scope) {
1091
1091
  });
1092
1092
  }
1093
1093
 
1094
+ /** A label that is only an arrow glyph names the step it takes ("‹" is Previous, "›" is Next; hub-464). */
1095
+ const GLYPH_WORDS = [[/^[‹«←⟨]+$/, "Previous"], [/^[›»→⟩]+$/, "Next"], [/^[↑]+$/, "Up"], [/^[↓]+$/, "Down"]];
1096
+
1097
+ /**
1098
+ * The prop that hides a button the page shows only sometimes (a permission, a
1099
+ * state): `show<what it does>`, the words and the place of its own handler
1100
+ * (`onStateEstablishmentSizeClick` → `showStateEstablishmentSize`), so two
1101
+ * buttons never share one (hub-478). Optional: a page that passes nothing
1102
+ * shows the button. Null for a part that is not a button, for a probe, and for
1103
+ * a button a table row or another part's slot holds: a row's actions are the
1104
+ * row's, and an Alert's action hides with its Alert.
1105
+ */
1106
+ const SHOWN_TAGS = new Set(["Button", "IconButton", "DecisionButton"]);
1107
+ function showFlag(code, node, ctx, path) {
1108
+ if (!ctx.scopes || ctx.tabProbe || ctx.inTable || ctx.inSlot) return null;
1109
+ const tag = /^<([A-Za-z]+)/.exec(code)?.[1];
1110
+ if (!SHOWN_TAGS.has(tag)) return null;
1111
+ const end = openTagEnd(code);
1112
+ const attrs = code.slice(tag.length + 1, end);
1113
+ const own = new RegExp(String.raw`\b${HANDLER_ATTR[tag]}=\{(__s\d+)_on([A-Z]\w*)Click\}`).exec(attrs);
1114
+ if (own) return `${own[1]}_show${own[2]}`;
1115
+ // A template that draws no handler: the words and place nameHandlers would give it.
1116
+ const label = handlerLabel(tag, attrs, code.slice(end), node) ?? scopeName(node, code, ctx);
1117
+ const { scope, name } = handlerScope(node, ctx, path, null, label, 0);
1118
+ return mark(ctx, scope, name.replace(/^on(\w+)Click$/, "show$1"));
1119
+ }
1120
+
1121
+ /** `drawn` (indented one deeper than `depth`) drawn only while `condition` holds. */
1122
+ const shownWhen = (condition, drawn, depth) => [indent(`{${condition} && (`, depth), drawn, indent(")}", depth)].join("\n");
1123
+
1094
1124
  /** Text as a handler's words: no figure, at most five words, in camelCase; null when nothing is left. */
1095
1125
  function handlerWords(text) {
1096
- const words = (String(text ?? "").match(/[A-Za-z0-9]+/g) ?? []).filter((w) => /[A-Za-z]/.test(w)).slice(0, 5);
1126
+ const glyph = GLYPH_WORDS.find(([re]) => re.test(String(text ?? "").trim()))?.[1];
1127
+ const words = (String(glyph ?? text ?? "").match(/[A-Za-z0-9]+/g) ?? []).filter((w) => /[A-Za-z]/.test(w)).slice(0, 5);
1097
1128
  return words.length ? camelName(words.join(" ")) : null;
1098
1129
  }
1099
1130
 
@@ -1122,7 +1153,8 @@ function handlerLabel(tag, attrs, after, node) {
1122
1153
  }
1123
1154
  if (/\/\s*$/.test(attrs)) return null;
1124
1155
  const close = after.indexOf(`</${tag}>`);
1125
- const inner = close === -1 ? "" : after.slice(0, close);
1156
+ // `after` starts with the `>` that closes the opening tag; it is not the button's text.
1157
+ const inner = close === -1 ? "" : after.slice(after.startsWith(">") ? 1 : 0, close);
1126
1158
  const strings = [...inner.matchAll(/\{("(?:[^"\\\n]|\\.)*")\}/g)].map((m) => JSON.parse(m[1]));
1127
1159
  const bare = inner.replace(/<[^>]*>/g, " ").replace(/\{[^{}]*\}/g, " ").trim();
1128
1160
  return handlerWords(strings.length ? strings.join(" ") : bare) ?? (node ? handlerWords(node.name.replace(/^\s*button\b[\s·:\-–]*/i, "")) : null);
@@ -1364,13 +1396,14 @@ function resolveScopes(views, scopes, layers = new Map()) {
1364
1396
  });
1365
1397
  const marked = /__s(\d+)_([a-z][A-Za-z0-9]*)/g;
1366
1398
  const cap = (s) => s[0].toUpperCase() + s.slice(1);
1399
+ // A setter, a handler and a show flag keep their verb first (`onSaveClick`, `showSsoAdd`, hub-478).
1367
1400
  const scoped = (scope, name) => {
1368
- const m = /^(set|on)([A-Z]\w*)$/.exec(name);
1401
+ const m = /^(set|on|show)([A-Z]\w*)$/.exec(name);
1369
1402
  return m ? `${m[1]}${cap(scope)}${m[2]}` : `${scope}${cap(name)}`;
1370
1403
  };
1371
1404
  // A prefix that tells two layers apart, a word it shares with the name said once.
1372
1405
  const prefixed = (prefix, name) => {
1373
- const m = /^(set|on)([A-Z]\w*)$/.exec(name);
1406
+ const m = /^(set|on|show)([A-Z]\w*)$/.exec(name);
1374
1407
  return m ? `${m[1]}${joinName(cap(prefix), m[2])}` : joinName(prefix, name);
1375
1408
  };
1376
1409
  // Which scope names emit each identifier, and each marked token with the views that draw it.
@@ -1491,6 +1524,15 @@ function dataProps(views, propsType) {
1491
1524
  own(dir, '"asc" | "desc"');
1492
1525
  for (const name of [by, dir, change]) view.uses.add(name);
1493
1526
  }
1527
+ // What the page may hide (hub-478): a part's show flag, and the tabs a strip shows.
1528
+ for (const m of body.matchAll(/\{([a-z][A-Za-z0-9]*) !== false && \(/g)) {
1529
+ own(m[1], "boolean");
1530
+ view.uses.add(m[1]);
1531
+ }
1532
+ for (const m of body.matchAll(/\{\(([a-z][A-Za-z0-9]*)\?\.includes\(("(?:[^"\\\n]|\\.)*")\) \?\? true\) && \(/g)) {
1533
+ (entry(m[1]).tabValues ??= new Set()).add(JSON.parse(m[2]));
1534
+ view.uses.add(m[1]);
1535
+ }
1494
1536
  for (const m of body.matchAll(/([A-Za-z][\w-]*)=\{([a-z][A-Za-z0-9]*)(?:\.([A-Za-z][A-Za-z0-9]*))?\}/g)) {
1495
1537
  if (JS_LITERALS.has(m[2]) || data.get(m[2])?.raw) continue;
1496
1538
  const list = m[3] ? itemList(m.index, m[2]) : null;
@@ -1527,6 +1569,7 @@ function dataProps(views, propsType) {
1527
1569
  view.uses.add(m[2]);
1528
1570
  }
1529
1571
  }
1572
+ for (const d of data.values()) if (d.tabValues) Object.assign(d, { optional: true, raw: `readonly (${union(d.tabValues)})[]` });
1530
1573
  for (const d of data.values()) {
1531
1574
  if (!d.sortKeys) continue;
1532
1575
  const keys = union(d.sortKeys);
@@ -1836,7 +1879,7 @@ function emitNode(node, ctx) {
1836
1879
  const path = root ? ctx.path : `${ctx.path} › ${node.name}`;
1837
1880
  // Every node's ancestors, nearest last: a list is named by the section heading before it (hub-454).
1838
1881
  const chain = [...(ctx.chain ?? []), node];
1839
- const child = (c) => emitNode(c, { ...ctx, depth: depth + 1, parent: node, grand: parent, path, root: false, chain });
1882
+ const child = (c) => emitNode(c, { ...ctx, depth: depth + 1, parent: node, grand: parent, path, root: false, chain, inSlot: false });
1840
1883
  const report = (detail) => note(path, "token", detail);
1841
1884
 
1842
1885
  // A DS library instance: exactly what its Code Connect template emits for this instance's properties.
@@ -1866,7 +1909,7 @@ function emitNode(node, ctx) {
1866
1909
  return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
1867
1910
  }
1868
1911
  const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
1869
- 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}` };
1912
+ const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, inSlot: true, chain: slotNode ? [...chain, slotNode] : chain, layer: `${ctx.layer} › ${prop}` };
1870
1913
  const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
1871
1914
  return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
1872
1915
  };
@@ -1903,9 +1946,11 @@ function emitNode(node, ctx) {
1903
1946
  // into a Table stays reported, never passed off as mapped (MW8-17.3).
1904
1947
  const tag = /^<([A-Za-z]+)/.exec(code)?.[1];
1905
1948
  if (!ctx.inTable && (tablePart(tag) || tag === SKELETON_ROWS)) note(path, "table", `${describe(node)} is a Table part outside any table the generator recognises`);
1906
- if (!sizing.length) return indent(code, depth);
1949
+ const flag = showFlag(own, node, ctx, path);
1950
+ const at = flag ? depth + 1 : depth;
1907
1951
  // Layout around a DS component is the page's; the component itself takes no className (U07-19).
1908
- return [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, depth), indent(code, depth + 1), indent("</div>", depth)].join("\n");
1952
+ const drawn = !sizing.length ? indent(code, at) : [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, at), indent(code, at + 1), indent("</div>", at)].join("\n");
1953
+ return flag ? shownWhen(`${flag} !== false`, drawn, depth) : drawn;
1909
1954
  }
1910
1955
 
1911
1956
  if (node.type === "TEXT") {
@@ -2069,15 +2114,18 @@ function tabStrip(run, ctx) {
2069
2114
  const value = text ? slug(/\d/.test(text) ? nameText(text) : text) : "";
2070
2115
  values.push(value && !values.includes(value) ? value : `tab-${i + 1}`);
2071
2116
  }
2072
- const stripScope = scopeName(ctx.parent ?? { name: "tabs" });
2117
+ const strip = scopeName(ctx.parent ?? { name: "tabs" });
2118
+ // A tab the page shows only sometimes (a permission) is left out of `visibleTabs`; a page
2119
+ // that passes no list shows every tab (hub-478).
2120
+ const visible = mark(ctx, strip, "visibleTabs", null);
2073
2121
  const triggers = tabs.map((t, i) => {
2074
2122
  let trigger = t.trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bvalue="tab"/, `$1value="${values[i]}"`);
2075
- if (counted[i]) trigger = trigger.replace(counted[i], `{${mark(ctx, stripScope, joinName(camelName(values[i]), "tabLabel"), null)}}`);
2076
- return indent(trigger, 2);
2123
+ if (counted[i]) trigger = trigger.replace(counted[i], `{${mark(ctx, strip, joinName(camelName(values[i]), "tabLabel"), null)}}`);
2124
+ return shownWhen(`(${visible}?.includes(${JSON.stringify(values[i])}) ?? true)`, indent(trigger, 3), 2);
2077
2125
  });
2078
2126
  return [
2079
2127
  // The page controls which tab is shown (NODII-DEV-CLI-83); Figma's selected tab is only the drawn one.
2080
- indent(CONTROLLED_TABS(mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "tab", null), mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "onTabChange", null)), depth),
2128
+ indent(CONTROLLED_TABS(mark(ctx, strip, "tab", null), mark(ctx, strip, "onTabChange", null)), depth),
2081
2129
  indent(" <TabsList>", depth),
2082
2130
  ...triggers.map((t) => indent(t, depth)),
2083
2131
  indent(" </TabsList>", depth),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.142",
3
+ "version": "0.6.144",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {