@nodii/dev 0.6.199 → 0.6.201

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
@@ -1322,9 +1322,18 @@ product-page catalog names the Surface by its published component-set key
1322
1322
  `Chart`, `ActivityFeedBlock`, `CommentThreadBlock`, `TenantPickerCardBlock`),
1323
1323
  else its own `loading` (`PageMetricsBarBlock`, `QrDisplay`) or `isLoading`
1324
1324
  (`DataTableToolbarBlock`, `ChartWithRange`). A Table whose rows are lifted draws
1325
- `{loading ? <TableSkeletonRows … /> : rows.map(…)}` under its real header, a
1326
- skeleton row per drawn row. A part that already draws the prop keeps it. So a
1327
- route passes `loading` and never hand-builds a loading page.
1325
+ `{loading ? <TableSkeletonRows … /> : rows.map(…)}` under its real header, as
1326
+ many skeleton rows as the Surface's Loading frame draws (NODII-DEV-CLI-279), or
1327
+ a skeleton row per drawn row when it has none. A part that already draws the
1328
+ prop keeps it. So a route passes `loading` and never hand-builds a loading page.
1329
+ - **A list page keeps to its frames (NODII-DEV-CLI-279).** A clipping row whose
1330
+ fixed-width children overflow it (a metric carousel's viewport) keeps them at
1331
+ their Figma width with `shrink-0`; a row whose children fit still reflows. A
1332
+ text or PiiText cell in a `layout="fixed"` table takes the DS TableCell's
1333
+ `truncate`, as Figma's Table cell draws one line, unless its template draws
1334
+ Figma's `Truncate` property. A template's `TableRowActions` is the row's own
1335
+ cell, never held in a `TableCell`. A `PageSizeSelect` takes an optional
1336
+ `pageSizeOptions` (the DS `options`), since the frame draws only the chosen size.
1328
1337
  - **A record's facts draw their skeleton (hub-634).** While `loading` is
1329
1338
  true, the value of each `DescriptionItem`, `DetailFact` and `RightPaneRow`, and
1330
1339
  the lifted value text of a label/value pair (a frame of two texts, a label then
@@ -1333,7 +1342,12 @@ product-page catalog names the Surface by its published component-set key
1333
1342
  Item hidden while its value is missing still draws while loading
1334
1343
  (`{(loading || fromValue != null) && (…)}`). Each value keeps the type of the
1335
1344
  part that draws it. `Skeleton` is imported from the module the page's DS parts
1336
- come from; a view with no fact is unchanged.
1345
+ come from; a view with no fact is unchanged. The skeleton only takes the
1346
+ fact's own ReactNode `value`, never a typed prop of a DS part inside it
1347
+ (hub-642): a value that is a DS part reading the page's data is replaced
1348
+ whole, `value={loading ? <Skeleton shape="text" /> : <PiiText value={emailValue} … />}`,
1349
+ so PiiText's `value` stays `string | null`. A value that reads nothing (fixed
1350
+ copy) is left as it is.
1337
1351
  - **Error and Empty views a route drives (NODII-DEV-CLI-260).** The Surface takes
1338
1352
  `<Id>SurfaceInput`: a `state` with the full props, as before, or a literal
1339
1353
  `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.199";
7
+ export const VERSION = "0.6.201";
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,7 +34,7 @@ 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 = 53;
37
+ export const GENERATOR_FORMAT = 55;
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
@@ -629,6 +629,32 @@ export function loadingVariantWarning(results) {
629
629
  return `MW6-29: ${hit.length} Surface${hit.length === 1 ? " still draws" : "s still draw"} a Loading variant; its DS parts draw their own skeleton from \`loading\`, so remove the variant in Figma (warned now, refused later): ${hit.map((r) => `${r.row.id} (${r.loadingVariants.join(", ")})`).join(", ")}`;
630
630
  }
631
631
 
632
+ /**
633
+ * A lifted table's loading rows are as many as the Surface's Loading frame draws (cli-279). The
634
+ * lifted skeleton otherwise draws a row per sample row (7 or 10), where the frame's Loading
635
+ * variant draws its own count (5), so the tab views' loading state was too tall. The count is the
636
+ * Loading view's drawn TableSkeletonRows: its one count when it draws one table (or all its tables
637
+ * draw the same), else the count of the table at the same place in the view. A Surface with no
638
+ * Loading frame (MW6-29) keeps a skeleton row per drawn row.
639
+ */
640
+ const DRAWN_SKELETON = /(^|[^?] )<TableSkeletonRows columns=\{\d+\} rows=\{(\d+)\}/gm;
641
+ const LIFTED_SKELETON = /\{loading \? <TableSkeletonRows columns=\{(\d+)\} rows=\{\d+\}/g;
642
+ function skeletonRowsFromLoading(views) {
643
+ const loading = views.find((v) => isLoadingState(v.state) && [...v.body.matchAll(DRAWN_SKELETON)].length);
644
+ if (!loading) return;
645
+ const drawn = [...loading.body.matchAll(DRAWN_SKELETON)].map((m) => m[2]);
646
+ const one = new Set(drawn).size === 1 ? drawn[0] : null;
647
+ for (const v of views) {
648
+ if (v === loading) continue;
649
+ let at = 0;
650
+ v.body = v.body.replace(LIFTED_SKELETON, (whole, columns) => {
651
+ const rows = one ?? drawn[at];
652
+ at += 1;
653
+ return rows === undefined ? whole : `{loading ? <TableSkeletonRows columns={${columns}} rows={${rows}}`;
654
+ });
655
+ }
656
+ }
657
+
632
658
  export function emitSurface(tree, row, ds) {
633
659
  const imports = [];
634
660
  const unmapped = [];
@@ -664,6 +690,7 @@ export function emitSurface(tree, row, ds) {
664
690
  const body = passLoading(emitted).replace(/^(\s*)<div\b/, `$1<div data-surface=${JSON.stringify(row.id)}`);
665
691
  return { state, fn, body, variant: variant.name };
666
692
  });
693
+ skeletonRowsFromLoading(views);
667
694
  const component = `${pascal(row.id)}Surface`;
668
695
  const stateType = `${component}State`;
669
696
  const propsType = `${component}Props`;
@@ -1341,7 +1368,16 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
1341
1368
  if (!at) return attrs;
1342
1369
  return `${attrs.slice(0, at.from)}series={${lift(scope, "series")}}${attrs.slice(at.to)}`;
1343
1370
  });
1344
- out = rewriteTags(out, "PageSizeSelect", (attrs) => attrs.replace(/\bvalue=\{(?:\d+|Number\("(?:[^"\\\n]|\\.)*"\))\}/, () => `value={${lift(scope, "pageSize")}}`));
1371
+ // The sizes a page offers are its own, as its page size is: the Pagination frame draws only the
1372
+ // chosen size (sizeValue "6"), and the DS defaults (10, 20, 50, 100) may not hold it, so the select
1373
+ // showed "10". `options` is optional; a page that passes none keeps the DS defaults (cli-279).
1374
+ out = rewriteTags(out, "PageSizeSelect", (attrs) => {
1375
+ const next = attrs.replace(/\bvalue=\{(?:\d+|Number\("(?:[^"\\\n]|\\.)*"\))\}/, () => `value={${lift(scope, "pageSize")}}`);
1376
+ if (/\boptions=/.test(next)) return next;
1377
+ lifted.push("pageSizeOptions");
1378
+ const options = ` options={${optionalMark(ctx, scope, "pageSizeOptions")}}`;
1379
+ return /\s*\/\s*$/.test(next) ? next.replace(/(\s*\/\s*)$/, `${options}$1`) : `${next}${options}`;
1380
+ });
1345
1381
  out = rewriteTags(out, "CopyField", (attrs) => {
1346
1382
  const value = new RegExp(String.raw`\bvalue=${LITERAL}`).exec(attrs);
1347
1383
  let next = value ? attrs.replace(value[0], `value={${lift(scope, "value")}}`) : attrs;
@@ -2404,10 +2440,24 @@ function passLoading(code) {
2404
2440
  * draws its skeleton while loading. Run after the props are typed, so each value keeps
2405
2441
  * the type of the part that draws it. Skeleton comes from the DS module the page's DS
2406
2442
  * parts come from; a page with no such import is left as it is.
2443
+ *
2444
+ * The skeleton only ever takes a ReactNode slot: the fact part's own top-level `value`
2445
+ * (or a pair's value span). A fact whose value is a DS part reading the page's data
2446
+ * (`value={<PiiText value={emailValue} … />}`) draws the skeleton in place of that whole
2447
+ * part, never inside one of its typed props, so PiiText's `value` stays `string | null`
2448
+ * (hub-642). A value that is fixed copy, or any other expression, is left as it is.
2407
2449
  */
2408
2450
  const FACT_SKELETON = '<Skeleton shape="text" />';
2409
2451
  const FACT_PARTS = /<(?:DescriptionItem|DetailFact|RightPaneRow)(?=[\s/>])/g;
2410
- const FACT_VALUE = /(\svalue=\{)([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\}/;
2452
+ const FACT_READ = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/;
2453
+ /** One JSX element (self-closing, or closed by its own tag) that reads the page's data: `{ident}` somewhere in it. */
2454
+ const factElement = (expr) => {
2455
+ const tag = /^<([A-Z][\w.]*)(?=[\s/>])/.exec(expr)?.[1];
2456
+ if (!tag) return false;
2457
+ const end = openTagEnd(expr);
2458
+ const whole = expr[end - 1] === "/" ? end === expr.length - 1 : expr.endsWith(`</${tag}>`) && expr.indexOf(`<${tag}`, 1) === -1;
2459
+ return whole && /\{[A-Za-z_$][\w$.]*\}/.test(expr);
2460
+ };
2411
2461
  const SKELETON_HOST = /\b(?:DescriptionItem|DescriptionList|DetailFact|DetailSection|Card|Badge|PiiText|Tabs|Field|Alert|EmptyState|Button|TableCell|TableHead)\b/;
2412
2462
  const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2413
2463
  function skeletonFacts(views, imports, factTexts) {
@@ -2421,14 +2471,20 @@ function skeletonFacts(views, imports, factTexts) {
2421
2471
  const masked = maskStrings(body);
2422
2472
  const edits = [];
2423
2473
  for (const m of masked.matchAll(FACT_PARTS)) {
2424
- const open = masked.slice(m.index, m.index + openTagEnd(masked.slice(m.index)) + 1);
2425
- const value = FACT_VALUE.exec(open);
2426
- if (value) edits.push({ at: m.index + value.index + value[1].length, read: value[2] });
2474
+ const at = m.index + m[0].length;
2475
+ const open = masked.slice(at, m.index + openTagEnd(masked.slice(m.index)) + 1);
2476
+ // The part's own value, never a `value` inside a DS part it draws (hub-642).
2477
+ const value = topLevelAttr(open, "value");
2478
+ if (!value) continue;
2479
+ const from = at + value.from + "value={".length;
2480
+ const expr = body.slice(from, at + value.to - 1);
2481
+ if (FACT_READ.test(expr)) edits.push({ at: from, read: expr });
2482
+ else if (factElement(expr)) edits.push({ at: from, read: null });
2427
2483
  }
2428
2484
  const gated = new Set();
2429
2485
  for (const { at, read } of edits.reverse()) {
2430
2486
  body = `${body.slice(0, at)}loading ? ${FACT_SKELETON} : ${body.slice(at)}`;
2431
- if (!read.includes(".")) gated.add(read);
2487
+ if (read && !read.includes(".")) gated.add(read);
2432
2488
  }
2433
2489
  for (const read of gated) body = body.replace(new RegExp(String.raw`\{${escapeRegExp(read)} != null && \(`, "g"), `{(loading || ${read} != null) && (`);
2434
2490
  for (const name of factTexts) body = body.replace(new RegExp(String.raw`(<span\b[^>\n]*>)\{${escapeRegExp(name)}\}(</span>)`, "g"), `$1{loading ? ${FACT_SKELETON} : ${name}}$2`);
@@ -2610,6 +2666,20 @@ export const INTRINSIC_MAX_PX = 48;
2610
2666
  * positioned absolutely: that frame is refused (see emitNode); only a child
2611
2667
  * Figma itself marks absolute is.
2612
2668
  */
2669
+ /**
2670
+ * A horizontal row Figma clips whose children, laid end to end, are wider than it: Figma draws
2671
+ * them at their own widths and clips the rest (a Carousel's viewport of six 220px metric cards in
2672
+ * a 1168px column). A row whose children fit, or that wraps, is not one.
2673
+ */
2674
+ function overflowsRow(row) {
2675
+ if (!row?.clips || row.layout?.mode !== "HORIZONTAL" || row.layout.wrap || typeof row.width !== "number") return false;
2676
+ const shown = (row.children ?? []).filter((c) => c.visible !== false && !c.absolute);
2677
+ if (shown.length < 2 || shown.some((c) => typeof c.width !== "number")) return false;
2678
+ const [, right, , left] = row.layout.padding ?? [0, 0, 0, 0];
2679
+ const drawn = shown.reduce((sum, c) => sum + c.width, 0) + (row.layout.gap ?? 0) * (shown.length - 1) + (left ?? 0) + (right ?? 0);
2680
+ return drawn > row.width + 0.5;
2681
+ }
2682
+
2613
2683
  function sizeClasses(node, parent, root) {
2614
2684
  const out = [];
2615
2685
  const [h, v] = node.sizing ?? ["FIXED", "FIXED"];
@@ -2618,6 +2688,9 @@ function sizeClasses(node, parent, root) {
2618
2688
  if (node.width === undefined) return out;
2619
2689
  if (root) out.push("w-full");
2620
2690
  else if (h === "FIXED" && node.width <= INTRINSIC_MAX_PX) out.push(`w-${step(node.width)}`, ...(pm === "HORIZONTAL" ? ["shrink-0"] : []));
2691
+ // A row that clips what overflows it (a metric carousel's viewport) keeps a fixed child at its Figma
2692
+ // width: shrink-0, so the overflow is clipped as Figma clips it, not shrunk to fit (cli-279, cli-240).
2693
+ else if (h === "FIXED" && pm === "HORIZONTAL" && overflowsRow(parent)) out.push(`w-${step(node.width)}`, ...(node.maxWidth ? [] : ["max-w-full"]), "shrink-0");
2621
2694
  else if (h === "FIXED") out.push(`w-${step(node.width)}`, ...(node.maxWidth ? [] : ["max-w-full"]), ...(pm === "HORIZONTAL" && !node.minWidth ? ["min-w-0"] : []));
2622
2695
  else if (h === "FILL") out.push(...(pm === "HORIZONTAL" ? ["min-w-0", "flex-1"] : pm === "VERTICAL" ? ["self-stretch"] : ["w-full"]));
2623
2696
  if (!root && v === "FIXED") out.push(`h-${step(node.height)}`, ...(pm === "VERTICAL" ? ["shrink-0"] : []));
@@ -3532,7 +3605,9 @@ function emptyPiiCell(part) {
3532
3605
  * part's template imports from. A frame cell (content Figma lays out inside a
3533
3606
  * row) becomes a TableCell holding that content. Returns null for anything else.
3534
3607
  */
3535
- const tablePart = (tag) => (/^Table[A-Za-z]*Head$/.test(tag ?? "") ? "head" : /^Table[A-Za-z]*Cell$/.test(tag ?? "") ? "body" : null);
3608
+ // TableRowActions is a body cell too: the row-actions cell the table pins to its end edge, drawn as
3609
+ // its own <td>, so it is never held in a second TableCell (cli-279).
3610
+ const tablePart = (tag) => (/^Table[A-Za-z]*Head$/.test(tag ?? "") ? "head" : /^(?:Table[A-Za-z]*Cell|TableRowActions)$/.test(tag ?? "") ? "body" : null);
3536
3611
  /**
3537
3612
  * What the Table cell template emits for `State=Loading` (U07-34.15.3, DEC-0457):
3538
3613
  * one column of the Table's loading state. A body of them becomes one
@@ -3562,7 +3637,7 @@ const widthAttr = (w) => (w === null ? "" : typeof w === "number" ? ` width={${w
3562
3637
  * The DS Table parts that take a column width (`TableColumnWidthProps`). Others, such as
3563
3638
  * TableSelectionCell, have no `width` prop, so they never get one (hub-573).
3564
3639
  */
3565
- const COLUMN_WIDTH_PART = /^\s*<(?:TableHead|TableSortHead|TableCell)[\s>/]/;
3640
+ const COLUMN_WIDTH_PART = /^\s*<(?:TableHead|TableSortHead|TableCell|TableRowActions)[\s>/]/;
3566
3641
  /** Add `width` to a TableHead/TableCell's opening tag, unless its template already declares one. */
3567
3642
  function withWidth(code, w) {
3568
3643
  if (!code) return code;
@@ -3823,7 +3898,11 @@ function tableOf(node, ctx) {
3823
3898
  if (code) {
3824
3899
  // Re-emit for real, so the cell's own unmapped layers are reported.
3825
3900
  const emitted = emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true, column });
3826
- return withWidth(selected ? indent(selectedCell(emitted), d) : emitted, w);
3901
+ const own = withWidth(selected ? indent(selectedCell(emitted), d) : emitted, w);
3902
+ const start = own.trimStart();
3903
+ const end = openTagEnd(start);
3904
+ const body = start.slice(end + 1, start.lastIndexOf("</TableCell>"));
3905
+ return !selected && start.lastIndexOf("</TableCell>") > end && oneLine(own, cell, body) ? withTruncate(own) : own;
3827
3906
  }
3828
3907
  // The frame stood in for the cell: its size and padding are the TableCell's now.
3829
3908
  const inner = emitNode({ ...cell, sizing: ["HUG", "HUG"], x: undefined, fills: undefined, strokes: undefined, radius: undefined, ...(cell.layout ? { layout: { ...cell.layout, padding: [0, 0, 0, 0] } } : {}) }, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, inTable: true });
@@ -3832,6 +3911,17 @@ function tableOf(node, ctx) {
3832
3911
  // Every column held at px or fill is a fixed table layout; a hug column needs the browser's auto layout.
3833
3912
  const widths = parsed.flatMap((p) => p.cells.map((c) => columnWidth(c.cell)));
3834
3913
  const fixed = widths.length > 0 && widths.every((w) => w !== null && w !== "hug");
3914
+ // Figma's Table cell draws its label on one line and clips the rest: in the committed trees,
3915
+ // a cell whose label needs up to 3.4 times its width is still one 44px row (cli-279). So a text
3916
+ // cell, or a person's PiiText, in a fixed-layout table takes the DS TableCell's own `truncate`,
3917
+ // never a className (U07-19). A cell whose template draws Figma's Truncate property keeps it.
3918
+ const oneLine = (code, cell, body, pii = false) => {
3919
+ const start = code.trimStart();
3920
+ const tag = start.slice(0, openTagEnd(start) + 1);
3921
+ if (!fixed || Object.hasOwn(cell.instance?.props ?? {}, "Truncate") || !/^<TableCell\b/.test(tag) || /\s(?:truncate\b|secondary=)/.test(tag)) return false;
3922
+ return pii || (!/\scontentLayout\b/.test(tag) && /^\{"(?:[^"\\\n]|\\.)*"\}$/.test(body.trim()));
3923
+ };
3924
+ const withTruncate = (code) => code.replace(/^(\s*<TableCell\b[^>]*?)(\s*\/?>)/, "$1 truncate$2");
3835
3925
  // Each column's width as the header's column carries it (the head template's own
3836
3926
  // `width`, else the head cell's sizing); its alignment as the loading cell draws it.
3837
3927
  const skeletonRows = () => {
@@ -3976,6 +4066,7 @@ function tableOf(node, ctx) {
3976
4066
  const tag = /^<([A-Za-z]+)/.exec(own)[1];
3977
4067
  open = withAlign(own.slice(0, end + 1).replace(/\s*\/>$/, ">"), i);
3978
4068
  close = `</${tag}>`;
4069
+ if (oneLine(open, c.cell, own.slice(end + 1, own.lastIndexOf(close)), piiColumn[i])) open = withTruncate(open);
3979
4070
  }
3980
4071
  // Selection is record data even when the drawing shows every row unchecked.
3981
4072
  if (/^<TableSelectionCell\b/.test(open)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.199",
3
+ "version": "0.6.201",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {