@nodii/dev 0.6.204 → 0.6.206

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/README.md CHANGED
@@ -1355,6 +1355,15 @@ product-page catalog names the Surface by its published component-set key
1355
1355
  whole, `value={loading ? <Skeleton shape="text" /> : <PiiText value={emailValue} … />}`,
1356
1356
  so PiiText's `value` stays `string | null`. A value that reads nothing (fixed
1357
1357
  copy) is left as it is.
1358
+ - **A one-line Rich Cell truncates (hub-646).** In a fixed-layout
1359
+ table a Table Rich Cell (`contentLayout`) whose content slot holds only one
1360
+ text that hugs its width takes `truncate`, as a one-line Table cell does
1361
+ (cli-279). A Rich Cell holding a DS part keeps its own layout.
1362
+ - **An empty head stays empty (hub-647).** A TableHead Figma draws
1363
+ with no text (or only spaces) is emitted as drawn, `{""}`, with no heading
1364
+ prop: a prop there is one no caller sets. Its column is keyed by position, so
1365
+ its row field and sort key are `columnN`. A head with copy takes an optional
1366
+ `<column>Heading` that defaults to the drawn copy (hub-507).
1358
1367
  - **A person in a fact row is the served pair (DESIGN-SYSTEM-993).** A PiiText in
1359
1368
  a fact row's value slot (a Description List's `value`, a Right Pane / Row's or
1360
1369
  a Detail Section / Row's `valueSlot`) takes `value`, `model` and `relation`
@@ -1362,6 +1371,14 @@ product-page catalog names the Surface by its published component-set key
1362
1371
  optional, as a lifted table's person cell takes `{ value, model, relation,
1363
1372
  maskHint? }`. The page passes them through as served: the relation keeps a
1364
1373
  self value revealed, and the generator never sets a mask (P-10).
1374
+ - **A record page's title and body are its data (NODII-DEV-CLI-293).** On a
1375
+ page whose route ends in a record (`/app/me/forum/policies/$id`, or a tab of it
1376
+ with `?tab=`; with no route, a set named `… .$id …`), the first title-sized
1377
+ loose heading (heading/lg and up) directly in the page's content frame, and
1378
+ the body-sized paragraphs (body/md, body/lg) directly after it up to the next
1379
+ heading, are lifted into props whatever Figma's sample says. Section headings
1380
+ (heading/sm, heading/md), labels, captions (body/sm) and text inside a card,
1381
+ a row or a DS part are kept as before.
1365
1382
  - **Error and Empty views a route drives (NODII-DEV-CLI-260).** The Surface takes
1366
1383
  `<Id>SurfaceInput`: a `state` with the full props, as before, or a literal
1367
1384
  `state` with only the props its view reads (`{ state: "read-error" } &
package/dist/core.js CHANGED
@@ -4,7 +4,7 @@ import { chmod, lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/pr
4
4
  import { homedir, platform } from "node:os";
5
5
  import { basename, dirname, join } from "node:path";
6
6
 
7
- export const VERSION = "0.6.204";
7
+ export const VERSION = "0.6.206";
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
@@ -34,13 +34,13 @@ import { MIN_FIGMA_INTERVAL_MS, figmaRest } from "./figma-rest.js";
34
34
  import { createRenderer } from "./vendor/render-templates.mjs";
35
35
 
36
36
  /** Bumped whenever the emitted code changes shape for the same inputs. */
37
- export const GENERATOR_FORMAT = 57;
37
+ export const GENERATOR_FORMAT = 61;
38
38
  /**
39
39
  * DS parts that are an item of their parent's own list or grid, so they take no sizing
40
40
  * wrapper: a Detail Section / Row's facts are the section grid's cells, a Right Pane / Row
41
41
  * is a <dt>/<dd> pair in its section's <dl> (CLI-210), a Timeline / Entry is an <li> (CLI-167).
42
42
  */
43
- const UNWRAPPED_PARTS = new Set(["Detail Section / Row", "Right Pane / Row", "Timeline / Entry"]);
43
+ const UNWRAPPED_PARTS = new Set(["Detail Section / Row", "Right Pane / Row", "Timeline / Entry", "Plan Step List / Step"]);
44
44
  export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
45
45
  export const GENERATED_SUFFIX = ".surface.generated.tsx";
46
46
  /** Where every generated product page lives, as a git glob (NODII-DEV-CLI-77). */
@@ -696,7 +696,9 @@ export function emitSurface(tree, row, ds) {
696
696
  used.add(state);
697
697
  const fn = `${pascal(state)}View`;
698
698
  const note = (path, kind, detail) => unmapped.push({ variant: variant.name, path, kind, detail });
699
- const emitted = emitNode(pageBody(variant, row), { depth: 2, parent: null, path: variant.name, row, ds, imports, note, root: true, scopes, layers, layer: "", state, lists: new Map(), shapes, handlers: new Map(), shown: new Map(), optionals, items, factTexts }) ?? "";
699
+ const page = pageBody(variant, row);
700
+ const recordTexts = recordPageTexts(page, row, tree.componentSetName);
701
+ const emitted = emitNode(page, { depth: 2, parent: null, path: variant.name, row, ds, imports, note, root: true, scopes, layers, layer: "", state, lists: new Map(), shapes, handlers: new Map(), shown: new Map(), optionals, items, factTexts, recordTexts }) ?? "";
700
702
  // A view the generator can't lay out is no page at all: generation fails rather than ship
701
703
  // an empty view (NODII-DEV-CLI-81).
702
704
  if (emitted.trimStart().startsWith("{/*")) {
@@ -1483,6 +1485,46 @@ export const SAMPLE_VALUE = /₹\s?\d|\b\d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|A
1483
1485
  const RELATIVE_PERIOD = /^(?:(?:this|last|previous|current|next) (?:day|week|month|quarter|year)|today|yesterday|tomorrow)$/i;
1484
1486
  const RECORD_TEXT = (text) => SAMPLE_VALUE.test(text) || /\d/.test(text) || RELATIVE_PERIOD.test(text.trim());
1485
1487
 
1488
+ /**
1489
+ * A record page's own title and body (NODII-DEV-CLI-293): on a page whose route
1490
+ * ends in a record (`/app/me/forum/policies/$id`, a tab of it with `?tab=`), the
1491
+ * page's title is the record's name and the paragraph under it the record's
1492
+ * text, whatever Figma's sample says ("Remote work policy" has no figure, so
1493
+ * RECORD_TEXT alone kept it as copy). Only loose text directly in the page's
1494
+ * content frame counts: its first title-sized heading (heading/lg and up) and
1495
+ * the body-sized paragraphs (body/md, body/lg) after it, up to the next heading.
1496
+ * A section's own heading (heading/sm, heading/md), a label, a caption
1497
+ * (body/sm) and any text inside a card, a row or a DS part stay as they are.
1498
+ * The set of those TEXT nodes, empty on any other Surface.
1499
+ */
1500
+ const RECORD_ROUTE = /\/\$[A-Za-z_]\w*\/?(?:[?#]|$)/;
1501
+ const RECORD_SET = /\.\$[A-Za-z_]\w*(?:\.[A-Za-z][\w-]*)?\s*(?:·|$)/;
1502
+ const TITLE_STYLE = /\b(?:heading|title|display)\/(?:lg|\d*xl)\b/i;
1503
+ const BODY_STYLE = /\bbody\/(?:md|lg)\b/i;
1504
+ export function isRecordPage(row, setName) {
1505
+ if (row?.surfaceType && row.surfaceType !== "page") return false;
1506
+ if (row?.frontendRoute) return RECORD_ROUTE.test(row.frontendRoute);
1507
+ return [row?.componentSetName, setName].some((name) => RECORD_SET.test(name ?? ""));
1508
+ }
1509
+ export function recordPageTexts(body, row, setName) {
1510
+ const found = new Set();
1511
+ if (!body || !isRecordPage(row, setName)) return found;
1512
+ const shown = (n) => (n.children ?? []).filter((c) => c.visible !== false);
1513
+ // The page's content frame: through any lone wrapper frame ("Page") under mainContent.
1514
+ let page = body;
1515
+ for (let kids = shown(page); kids.length === 1 && kids[0].type === "FRAME" && !kids[0].instance; kids = shown(page)) page = kids[0];
1516
+ const kids = shown(page);
1517
+ const at = kids.findIndex((c) => c.type === "TEXT" && TITLE_STYLE.test(c.textStyle ?? "") && /[A-Za-z0-9]/.test(c.text ?? ""));
1518
+ if (at === -1) return found;
1519
+ found.add(kids[at]);
1520
+ for (const c of kids.slice(at + 1)) {
1521
+ if (c.type !== "TEXT") continue;
1522
+ if (HEADING_STYLE.test(c.textStyle ?? "")) break;
1523
+ if (BODY_STYLE.test(c.textStyle ?? "") && /[A-Za-z0-9]/.test(c.text ?? "")) found.add(c);
1524
+ }
1525
+ return found;
1526
+ }
1527
+
1486
1528
  // A named fact or field frame is a label/value pair even when its value has no digits
1487
1529
  // (for example Status / Active). Keep the label and lift only the value.
1488
1530
  function isFactValue(node, parent) {
@@ -2993,7 +3035,7 @@ function emitNode(node, ctx) {
2993
3035
  ]);
2994
3036
  // Text naming a record's value (a date, an amount, a code) is Figma's sample: the page's own (NODII-DEV-CLI-82).
2995
3037
  let content = JSON.stringify(node.text);
2996
- if ((RECORD_TEXT(node.text) || isFactValue(node, parent)) && !ctx.textOwner) {
3038
+ if ((RECORD_TEXT(node.text) || isFactValue(node, parent) || ctx.recordTexts?.has(node)) && !ctx.textOwner) {
2997
3039
  const scope = positionScope(node, ctx, "text");
2998
3040
  const name = mark(ctx, scope, scope);
2999
3041
  note(path, LIFTED, `text ${shown} names a record's value: lifted from Figma's sample into the page's props (NODII-DEV-CLI-82)`);
@@ -3052,7 +3094,7 @@ function sectionCondition(node, ctx, path) {
3052
3094
  // A head of only text (a title and its subtitle) is not the section: its body sits beside it.
3053
3095
  const [first, ...rest] = (node.children ?? []).filter((c) => c.visible !== false);
3054
3096
  const body = rest.some((c) => c.type !== "TEXT");
3055
- const heading = body && first?.type === "TEXT" && HEADING_STYLE.test(first.textStyle ?? "") && !RECORD_TEXT(first.text ?? "") ? first.text : null;
3097
+ const heading = body && first?.type === "TEXT" && HEADING_STYLE.test(first.textStyle ?? "") && !RECORD_TEXT(first.text ?? "") && !ctx.recordTexts?.has(first) ? first.text : null;
3056
3098
  const words = m ? (TABLE_ANATOMY.has(m[1].trim().toLowerCase()) ? null : handlerWords(m[2])) : handlerWords(heading);
3057
3099
  if (!words) return null;
3058
3100
  const { scope, name } = handlerScope(node, { ...ctx, handlers: ctx.shown }, path, null, words, 0);
@@ -3966,11 +4008,21 @@ function tableOf(node, ctx) {
3966
4008
  // a cell whose label needs up to 3.4 times its width is still one 44px row (cli-279). So a text
3967
4009
  // cell, or a person's PiiText, in a fixed-layout table takes the DS TableCell's own `truncate`,
3968
4010
  // never a className (U07-19). A cell whose template draws Figma's Truncate property keeps it.
4011
+ // A Rich Cell (contentLayout) does too when its content slot holds only one text that hugs
4012
+ // its width, which Figma never wraps (compliance.pii.audit-logs' Action; hub-646).
4013
+ const slotLine = (cell) => {
4014
+ const slots = (cell.children ?? []).filter((c) => c.type === "SLOT");
4015
+ const only = slots.length === 1 && slots[0].children?.length === 1 ? slots[0].children[0] : null;
4016
+ return only?.type === "TEXT" && only.sizing?.[0] === "HUG";
4017
+ };
3969
4018
  const oneLine = (code, cell, body, pii = false) => {
3970
4019
  const start = code.trimStart();
3971
4020
  const tag = start.slice(0, openTagEnd(start) + 1);
3972
4021
  if (!fixed || Object.hasOwn(cell.instance?.props ?? {}, "Truncate") || !/^<TableCell\b/.test(tag) || /\s(?:truncate\b|secondary=)/.test(tag)) return false;
3973
- return pii || (!/\scontentLayout\b/.test(tag) && /^\{"(?:[^"\\\n]|\\.)*"\}$/.test(body.trim()));
4022
+ const text = /^\{"(?:[^"\\\n]|\\.)*"\}$/;
4023
+ if (!/\scontentLayout\b/.test(tag)) return pii || text.test(body.trim());
4024
+ // The slot's text line is emitted in a bare <span>.
4025
+ return pii || (slotLine(cell) && text.test(body.trim().replace(/^<span>([\s\S]*)<\/span>$/, "$1").trim()));
3974
4026
  };
3975
4027
  const withTruncate = (code) => code.replace(/^(\s*<TableCell\b[^>]*?)(\s*\/?>)/, "$1 truncate$2");
3976
4028
  // Each column's width as the header's column carries it (the head template's own
@@ -4029,8 +4081,10 @@ function tableOf(node, ctx) {
4029
4081
  if (!key) return code;
4030
4082
  const lifted = code.replace(HEAD_PLACEHOLDER_CHILD, (_, open) => `${open}{${mark(ctx, listName, `${key}Heading`, null)}}`).replace(HEAD_FIGURE_CHILD, (_, open) => `${open}{${mark(ctx, listName, `${key}Heading`, null)}}`);
4031
4083
  // Display copy may follow a selected dimension; row and sort keys still come
4032
- // from the drawing. Existing consumers keep the drawn label (hub-507).
4033
- return lifted.replace(/(<Table(?:Sort)?Head\b[^\n]*>\s*)\{("(?:[^"\\\n]|\\.)*")\}/, (_, open, label) => `${open}{${optionalMark(ctx, listName, `${key}Heading`, null)} ?? ${label}}`);
4084
+ // from the drawing. Existing consumers keep the drawn label (hub-507). A head
4085
+ // Figma draws empty (a menu or check column) stays empty: a prop there is one
4086
+ // no caller sets, so the page would draw copy the frame lacks (hub-647).
4087
+ return lifted.replace(/(<Table(?:Sort)?Head\b[^\n]*>\s*)\{("(?:[^"\\\n]|\\.)*")\}/, (whole, open, label) => (/^"\s*"$/.test(label) ? whole : `${open}{${optionalMark(ctx, listName, `${key}Heading`, null)} ?? ${label}}`));
4034
4088
  };
4035
4089
  // The lifted rows' loading state: as many skeleton rows as Figma draws body rows, each
4036
4090
  // column as wide as the header's (else the first row's) cell and aligned as its head.
@@ -30,7 +30,7 @@
30
30
  // it until it returns [] (each round can reveal instances inside slot
31
31
  // content).
32
32
 
33
- export const VERSION = "1.0.16";
33
+ export const VERSION = "1.0.19";
34
34
 
35
35
  /** @typedef {{ nodeId: string, check: string, detail: string }} Finding */
36
36
  /**
@@ -167,6 +167,20 @@ const SELF_COMPONENT_SET_KEYS = new Set([
167
167
  "8499452873bccfe5d2f29b5322fc1ca18cb103cc", // Profile Name Card
168
168
  "6c1e074dcf69aee388e0300584da09735e314cc3", // Delete Account Card
169
169
  ]);
170
+ // The published Editable Fields block (by key). On a self route's Surface
171
+ // (Surface / home.me.* or me.*) its rows edit the viewer's own record, so
172
+ // the viewer's email and phone there are revealed (P-10; NODII-DEV-CLI-215).
173
+ // Only a row labelled as the viewer's own email or phone counts; another
174
+ // person's contact on the same record is still flagged (PLANNING-HUB-656).
175
+ const EDITABLE_FIELDS_COMPONENT_SET_KEY =
176
+ "454c48893f60d6d55fe783a1c16d0001d3ae859b";
177
+ const SELF_SURFACE = /^Surface \/ (home\.)?me[.!@ ]/;
178
+ // The labels of the viewer's own email and phone rows. An allow-list: any
179
+ // other label (a spouse's phone, a team lead's email, an HRBP) is not the
180
+ // viewer's (PLANNING-HUB-656).
181
+ const SELF_ROW_EXTENSION = /,?\s*(ext\.?|x|#)\s*\d{1,6}\s*$/i;
182
+ const SELF_ROW_LABEL =
183
+ /^(my |your )?((work|personal|official) )?(e-?mail( address)?|phone( number)?|mobile( number)?)$/i;
170
184
  const NOT_A_PERSON = /^(you|the team)$/i;
171
185
  const MASKED = /[*•●]/;
172
186
  const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
@@ -1013,7 +1027,18 @@ export function checkConformance({
1013
1027
  const chain = (stop === -1 ? up : up.slice(0, stop + 1)).filter(
1014
1028
  (x) => x.type === "INSTANCE",
1015
1029
  );
1016
- if (!chain.some((inst) => matchesRole(a, inst, role, library)))
1030
+ // The role's own component is the role, not a drawing of it: the
1031
+ // label of a Decision Button variant is the Decision Button's own
1032
+ // (drift ccac666c, operator, 21 Nov; PLANNING-HUB-623).
1033
+ const ownComponent = up.some(
1034
+ (x) =>
1035
+ (x.type === "COMPONENT_SET" || x.type === "COMPONENT") &&
1036
+ (x.name === role.componentName || x.id === role.nodeId),
1037
+ );
1038
+ if (
1039
+ !ownComponent &&
1040
+ !chain.some((inst) => matchesRole(a, inst, role, library))
1041
+ )
1017
1042
  push(
1018
1043
  findings,
1019
1044
  holder.id,
@@ -1047,6 +1072,7 @@ export function checkConformance({
1047
1072
  if (
1048
1073
  !screenText(a, n, overridden) ||
1049
1074
  isSelf(a, n) ||
1075
+ selfEditableRow(a, n) ||
1050
1076
  revealedByPermission(a, n)
1051
1077
  )
1052
1078
  continue;
@@ -1130,6 +1156,7 @@ export function checkConformance({
1130
1156
  !/\p{L}{2}/u.test(text) ||
1131
1157
  MASKED.test(text) ||
1132
1158
  isSelf(a, n) ||
1159
+ selfEditableRow(a, n) ||
1133
1160
  revealedByPermission(a, n)
1134
1161
  )
1135
1162
  continue;
@@ -1439,6 +1466,68 @@ function drawnSet(a, x) {
1439
1466
  if (x.type === "COMPONENT_SET") return a.componentSets[x.id] ?? null;
1440
1467
  return null;
1441
1468
  }
1469
+ /**
1470
+ * The viewer's own email or phone in an Editable Fields row on a self
1471
+ * route's Surface (NODII-DEV-CLI-215). The row is the block's direct child
1472
+ * holding the text. It is the viewer's only when it has exactly one label (a
1473
+ * shown `label` text, see rowLabelText) that SELF_ROW_LABEL allows, exactly one identifier with no words beside it, and no other text
1474
+ * (PLANNING-HUB-656); anything else fails closed.
1475
+ * Checked per node only, never seeded into the run-wide viewer set, so the
1476
+ * value elsewhere is judged on its own screen.
1477
+ */
1478
+ /**
1479
+ * A shown text that is a self row's label: a layer named `label`, or a text
1480
+ * whose characters come from a TEXT property named `label` on an instance
1481
+ * between it and the row (PLANNING-HUB-656). A property never counts
1482
+ * through a hidden layer, or on its own.
1483
+ */
1484
+ function rowLabelText(a, t, row) {
1485
+ if (/^label\b/i.test(t.name ?? "")) return true;
1486
+ const ref = t.componentPropertyReferences?.characters;
1487
+ if (typeof ref !== "string" || !/^label\b/i.test(ref)) return false;
1488
+ for (const x of [t, ...a.ancestors(t)]) {
1489
+ const v = x.componentProperties?.[ref];
1490
+ if (v) return v.type === "TEXT";
1491
+ if (x.id === row.id) break;
1492
+ }
1493
+ return false;
1494
+ }
1495
+ function selfEditableRow(a, n) {
1496
+ const up = a.ancestors(n);
1497
+ const blockAt = up.findIndex(
1498
+ (x) => drawnSet(a, x)?.key === EDITABLE_FIELDS_COMPONENT_SET_KEY,
1499
+ );
1500
+ if (blockAt < 1) return false;
1501
+ if (
1502
+ !up.some((x) =>
1503
+ SELF_SURFACE.test(
1504
+ x.type === "COMPONENT_SET" ? x.name ?? "" : drawnSet(a, x)?.name ?? "",
1505
+ ),
1506
+ )
1507
+ )
1508
+ return false;
1509
+ const row = up[blockAt - 1];
1510
+ const labels = new Set();
1511
+ let found = 0;
1512
+ for (const t of indexTree(row).byId.values()) {
1513
+ if (t.type !== "TEXT" || !a.shown(t)) continue;
1514
+ // A trailing extension ("ext. 12", "x89", "#7") belongs to the phone.
1515
+ const text = textOf(t).replace(SELF_ROW_EXTENSION, "");
1516
+ const ids = identifiers(text).length;
1517
+ if (ids === 0 && rowLabelText(a, t, row)) labels.add(text.trim());
1518
+ // Any other text (a name, a relation, a note) says whose value it is,
1519
+ // and so do words beside the value itself ("Wife: +91 ...").
1520
+ else if (
1521
+ ids === 0 ||
1522
+ /\p{L}/u.test(text.replace(EMAIL, "").replace(PHONE, ""))
1523
+ )
1524
+ return false;
1525
+ found += ids;
1526
+ }
1527
+ if (labels.size !== 1 || found !== 1) return false;
1528
+ const [label] = labels;
1529
+ return SELF_ROW_LABEL.test(label.replace(/\s*:$/, ""));
1530
+ }
1442
1531
  function isSelf(a, n) {
1443
1532
  const up = a.ancestors(n);
1444
1533
  if (up.some((x) => selfPersonName(a, x))) return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.204",
3
+ "version": "0.6.206",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {