@nodii/dev 0.6.199 → 0.6.200

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
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.200";
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 = 54;
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;
@@ -2610,6 +2646,20 @@ export const INTRINSIC_MAX_PX = 48;
2610
2646
  * positioned absolutely: that frame is refused (see emitNode); only a child
2611
2647
  * Figma itself marks absolute is.
2612
2648
  */
2649
+ /**
2650
+ * A horizontal row Figma clips whose children, laid end to end, are wider than it: Figma draws
2651
+ * them at their own widths and clips the rest (a Carousel's viewport of six 220px metric cards in
2652
+ * a 1168px column). A row whose children fit, or that wraps, is not one.
2653
+ */
2654
+ function overflowsRow(row) {
2655
+ if (!row?.clips || row.layout?.mode !== "HORIZONTAL" || row.layout.wrap || typeof row.width !== "number") return false;
2656
+ const shown = (row.children ?? []).filter((c) => c.visible !== false && !c.absolute);
2657
+ if (shown.length < 2 || shown.some((c) => typeof c.width !== "number")) return false;
2658
+ const [, right, , left] = row.layout.padding ?? [0, 0, 0, 0];
2659
+ const drawn = shown.reduce((sum, c) => sum + c.width, 0) + (row.layout.gap ?? 0) * (shown.length - 1) + (left ?? 0) + (right ?? 0);
2660
+ return drawn > row.width + 0.5;
2661
+ }
2662
+
2613
2663
  function sizeClasses(node, parent, root) {
2614
2664
  const out = [];
2615
2665
  const [h, v] = node.sizing ?? ["FIXED", "FIXED"];
@@ -2618,6 +2668,9 @@ function sizeClasses(node, parent, root) {
2618
2668
  if (node.width === undefined) return out;
2619
2669
  if (root) out.push("w-full");
2620
2670
  else if (h === "FIXED" && node.width <= INTRINSIC_MAX_PX) out.push(`w-${step(node.width)}`, ...(pm === "HORIZONTAL" ? ["shrink-0"] : []));
2671
+ // A row that clips what overflows it (a metric carousel's viewport) keeps a fixed child at its Figma
2672
+ // width: shrink-0, so the overflow is clipped as Figma clips it, not shrunk to fit (cli-279, cli-240).
2673
+ else if (h === "FIXED" && pm === "HORIZONTAL" && overflowsRow(parent)) out.push(`w-${step(node.width)}`, ...(node.maxWidth ? [] : ["max-w-full"]), "shrink-0");
2621
2674
  else if (h === "FIXED") out.push(`w-${step(node.width)}`, ...(node.maxWidth ? [] : ["max-w-full"]), ...(pm === "HORIZONTAL" && !node.minWidth ? ["min-w-0"] : []));
2622
2675
  else if (h === "FILL") out.push(...(pm === "HORIZONTAL" ? ["min-w-0", "flex-1"] : pm === "VERTICAL" ? ["self-stretch"] : ["w-full"]));
2623
2676
  if (!root && v === "FIXED") out.push(`h-${step(node.height)}`, ...(pm === "VERTICAL" ? ["shrink-0"] : []));
@@ -3532,7 +3585,9 @@ function emptyPiiCell(part) {
3532
3585
  * part's template imports from. A frame cell (content Figma lays out inside a
3533
3586
  * row) becomes a TableCell holding that content. Returns null for anything else.
3534
3587
  */
3535
- const tablePart = (tag) => (/^Table[A-Za-z]*Head$/.test(tag ?? "") ? "head" : /^Table[A-Za-z]*Cell$/.test(tag ?? "") ? "body" : null);
3588
+ // TableRowActions is a body cell too: the row-actions cell the table pins to its end edge, drawn as
3589
+ // its own <td>, so it is never held in a second TableCell (cli-279).
3590
+ const tablePart = (tag) => (/^Table[A-Za-z]*Head$/.test(tag ?? "") ? "head" : /^(?:Table[A-Za-z]*Cell|TableRowActions)$/.test(tag ?? "") ? "body" : null);
3536
3591
  /**
3537
3592
  * What the Table cell template emits for `State=Loading` (U07-34.15.3, DEC-0457):
3538
3593
  * one column of the Table's loading state. A body of them becomes one
@@ -3562,7 +3617,7 @@ const widthAttr = (w) => (w === null ? "" : typeof w === "number" ? ` width={${w
3562
3617
  * The DS Table parts that take a column width (`TableColumnWidthProps`). Others, such as
3563
3618
  * TableSelectionCell, have no `width` prop, so they never get one (hub-573).
3564
3619
  */
3565
- const COLUMN_WIDTH_PART = /^\s*<(?:TableHead|TableSortHead|TableCell)[\s>/]/;
3620
+ const COLUMN_WIDTH_PART = /^\s*<(?:TableHead|TableSortHead|TableCell|TableRowActions)[\s>/]/;
3566
3621
  /** Add `width` to a TableHead/TableCell's opening tag, unless its template already declares one. */
3567
3622
  function withWidth(code, w) {
3568
3623
  if (!code) return code;
@@ -3823,7 +3878,11 @@ function tableOf(node, ctx) {
3823
3878
  if (code) {
3824
3879
  // Re-emit for real, so the cell's own unmapped layers are reported.
3825
3880
  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);
3881
+ const own = withWidth(selected ? indent(selectedCell(emitted), d) : emitted, w);
3882
+ const start = own.trimStart();
3883
+ const end = openTagEnd(start);
3884
+ const body = start.slice(end + 1, start.lastIndexOf("</TableCell>"));
3885
+ return !selected && start.lastIndexOf("</TableCell>") > end && oneLine(own, cell, body) ? withTruncate(own) : own;
3827
3886
  }
3828
3887
  // The frame stood in for the cell: its size and padding are the TableCell's now.
3829
3888
  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 +3891,17 @@ function tableOf(node, ctx) {
3832
3891
  // Every column held at px or fill is a fixed table layout; a hug column needs the browser's auto layout.
3833
3892
  const widths = parsed.flatMap((p) => p.cells.map((c) => columnWidth(c.cell)));
3834
3893
  const fixed = widths.length > 0 && widths.every((w) => w !== null && w !== "hug");
3894
+ // Figma's Table cell draws its label on one line and clips the rest: in the committed trees,
3895
+ // a cell whose label needs up to 3.4 times its width is still one 44px row (cli-279). So a text
3896
+ // cell, or a person's PiiText, in a fixed-layout table takes the DS TableCell's own `truncate`,
3897
+ // never a className (U07-19). A cell whose template draws Figma's Truncate property keeps it.
3898
+ const oneLine = (code, cell, body, pii = false) => {
3899
+ const start = code.trimStart();
3900
+ const tag = start.slice(0, openTagEnd(start) + 1);
3901
+ if (!fixed || Object.hasOwn(cell.instance?.props ?? {}, "Truncate") || !/^<TableCell\b/.test(tag) || /\s(?:truncate\b|secondary=)/.test(tag)) return false;
3902
+ return pii || (!/\scontentLayout\b/.test(tag) && /^\{"(?:[^"\\\n]|\\.)*"\}$/.test(body.trim()));
3903
+ };
3904
+ const withTruncate = (code) => code.replace(/^(\s*<TableCell\b[^>]*?)(\s*\/?>)/, "$1 truncate$2");
3835
3905
  // Each column's width as the header's column carries it (the head template's own
3836
3906
  // `width`, else the head cell's sizing); its alignment as the loading cell draws it.
3837
3907
  const skeletonRows = () => {
@@ -3976,6 +4046,7 @@ function tableOf(node, ctx) {
3976
4046
  const tag = /^<([A-Za-z]+)/.exec(own)[1];
3977
4047
  open = withAlign(own.slice(0, end + 1).replace(/\s*\/>$/, ">"), i);
3978
4048
  close = `</${tag}>`;
4049
+ if (oneLine(open, c.cell, own.slice(end + 1, own.lastIndexOf(close)), piiColumn[i])) open = withTruncate(open);
3979
4050
  }
3980
4051
  // Selection is record data even when the drawing shows every row unchecked.
3981
4052
  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.200",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {