@nodii/dev 0.6.164 → 0.6.166

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.164";
7
+ export const VERSION = "0.6.166";
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
@@ -27,12 +27,12 @@
27
27
  import { execFileSync } from "node:child_process";
28
28
  import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
29
29
  import { tmpdir } from "node:os";
30
- import { dirname, join, relative, resolve } from "node:path";
30
+ import { basename, dirname, join, relative, resolve } from "node:path";
31
31
  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 = 33;
35
+ export const GENERATOR_FORMAT = 36;
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). */
@@ -505,6 +505,31 @@ export function mergeImports(statements, body = null) {
505
505
  return [...lines, ...[...other].sort()];
506
506
  }
507
507
 
508
+ /** The registry is the authority for block aliases used by Code Connect. */
509
+ export function blockImportPaths(items) {
510
+ const paths = new Map();
511
+ for (const item of items) {
512
+ if (item.type !== "registry:block") continue;
513
+ const files = item.files ?? [];
514
+ for (const file of files) {
515
+ const name = files.length === 1 ? item.name : basename(file.path).replace(/-block(\.tsx?)$/, "$1").replace(/\.[^.]+$/, "");
516
+ paths.set(`@/components/ui/${name}`, file.path);
517
+ }
518
+ }
519
+ return paths;
520
+ }
521
+
522
+ /** Generated pages live in blocks itself, so use the registry's source, not a consumer alias. */
523
+ export function resolveBlockImports(imports, sourcePath, paths = new Map()) {
524
+ if (!sourcePath) return imports;
525
+ return imports.map(statement => statement.replace(/\bfrom\s+(["'])(@\/components\/ui\/[^"']+)\1/, (all, quote, alias) => {
526
+ const target = paths.get(alias);
527
+ if (!target) return all;
528
+ const path = relative(dirname(sourcePath), target).replaceAll("\\", "/").replace(/\.tsx?$/, "");
529
+ return `from ${quote}${path.startsWith(".") ? path : `./${path}`}${quote}`;
530
+ }));
531
+ }
532
+
508
533
  /** The design system's inputs to emitting: templates, the key index, tokens and text utilities. */
509
534
  export function loadDesignSystem(root, { exec = execFileSync, docs } = {}) {
510
535
  const dsFileKey = readJson(join(root, DS_FILE_META)).fileKey;
@@ -527,7 +552,9 @@ export function loadDesignSystem(root, { exec = execFileSync, docs } = {}) {
527
552
  const set = optionalProps.get(doc.component) ?? optionalProps.set(doc.component, new Set()).get(doc.component);
528
553
  for (const name of listed) set.add(name);
529
554
  }
530
- return { dsFileKey, renderer, byKey, colours, textStyles, optionalProps };
555
+ const registryPath = join(root, "apps/web/public/registry.json");
556
+ const registry = existsSync(registryPath) ? readJson(registryPath) : [];
557
+ return { dsFileKey, renderer, byKey, colours, textStyles, optionalProps, blockImports: blockImportPaths(registry.items ?? registry) };
531
558
  }
532
559
 
533
560
  /** `figma connect parse`, the repository's own Code Connect compile, into memory. */
@@ -602,7 +629,7 @@ export function emitSurface(tree, row, ds) {
602
629
  ];
603
630
  const lines = [
604
631
  ...header,
605
- ...mergeImports([...imports, ...(reactTypes.length ? [`import type { ${reactTypes.join(", ")} } from "react";`] : [])], [...views.map((v) => v.body), reactTypes.join(" ")].join("\n")),
632
+ ...mergeImports(resolveBlockImports([...imports, ...(reactTypes.length ? [`import type { ${reactTypes.join(", ")} } from "react";`] : [])], row.sourcePath, ds.blockImports), [...views.map((v) => v.body), reactTypes.join(" ")].join("\n")),
606
633
  "",
607
634
  `export type ${stateType} = ${views.map((v) => JSON.stringify(v.state)).join(" | ")};`,
608
635
  "",
@@ -989,7 +1016,7 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
989
1016
  const scope = nameOf(label ? literalText(label[1]) : node.name, node.name);
990
1017
  return `<DescriptionItem${attrs.replace(value[0], `value={${lift(scope, "value")}}`)}/>`;
991
1018
  });
992
- out = rewriteTags(out, "DetailFact", (attrs) => {
1019
+ out = rewriteTags(out, "DetailFact|RightPaneRow", (attrs) => {
993
1020
  const parsed = tagAttributes(`${attrs}>`, 0);
994
1021
  if (!parsed?.literals.has("value")) return attrs;
995
1022
  const label = parsed.literals.get("label");
@@ -1915,7 +1942,14 @@ function dataProps(views, propsType) {
1915
1942
  if (list) {
1916
1943
  const field = member(entry(list), m[2]);
1917
1944
  const nullable = / == null \? \("(?:[^"\\]|\\.)*"\) : \((?:<div\b[^>]*>\s*)*$/.test(body.slice(0, m.index)) || field.get("\u0000pii")?.raw.endsWith(" | null");
1918
- field.set("\u0000pii", { raw: PII_ROW_FIELD + (nullable ? " | null" : "") });
1945
+ const ref = `${m[1]}.${m[2]}`;
1946
+ const mixed = mixedPiiExpressions(body).find(expression => m.index >= expression.at && m.index < expression.end)?.expression;
1947
+ const alternatives = mixed ? [
1948
+ `{ kind: "person" } & ${PII_ROW_FIELD}`,
1949
+ ...(mixed.includes(`${ref}.kind === "text"`) ? ['{ kind: "text"; text: string }'] : []),
1950
+ ...(mixed.includes(`${ref}.kind === "badge"`) ? ['{ kind: "badge"; text: string }'] : []),
1951
+ ].join(" | ") : null;
1952
+ field.set("\u0000pii", { raw: alternatives ?? PII_ROW_FIELD + (nullable ? " | null" : "") });
1919
1953
  }
1920
1954
  }
1921
1955
  for (const m of body.matchAll(/(^|>)\s*\{([a-z][A-Za-z0-9]*)\}/gm)) {
@@ -2014,9 +2048,9 @@ function drawnRef({ tag, attr, keys, literals, raw }) {
2014
2048
  /** The type the generated file declares for drawnProps (see there). */
2015
2049
  const DRAWN_TYPE = [
2016
2050
  "/** A DS component's props, narrowed to the member of their union this call draws: every required prop passed, every literal one fitting. */",
2017
- "type Drawn<P, K extends PropertyKey, L = {}> = [DrawnOf<P, K, L>] extends [never] ? P : DrawnOf<P, K, L>;",
2051
+ "type Drawn<P, K extends PropertyKey, L = Record<never, never>> = [DrawnOf<P, K, L>] extends [never] ? P : DrawnOf<P, K, L>;",
2018
2052
  "type DrawnOf<P, K extends PropertyKey, L> = P extends unknown",
2019
- " ? [Exclude<{ [k in keyof P]-?: {} extends Pick<P, k> ? never : k }[keyof P], K>] extends [never]",
2053
+ " ? [Exclude<{ [k in keyof P]-?: Record<never, never> extends Pick<P, k> ? never : k }[keyof P], K>] extends [never]",
2020
2054
  " ? [{ [k in keyof L]: k extends keyof P ? (L[k] extends P[k] ? never : k) : never }[keyof L]] extends [never]",
2021
2055
  " ? P",
2022
2056
  " : never",
@@ -2032,6 +2066,7 @@ const DRAWN_TYPE = [
2032
2066
  function tagAttributes(body, at) {
2033
2067
  const names = [];
2034
2068
  const literals = new Map();
2069
+ const values = new Map();
2035
2070
  let i = at;
2036
2071
  const skipString = (q) => {
2037
2072
  for (i++; i < body.length && body[i] !== q; i++) if (body[i] === "\\") i++;
@@ -2052,8 +2087,8 @@ function tagAttributes(body, at) {
2052
2087
  };
2053
2088
  while (i < body.length) {
2054
2089
  while (/\s/.test(body[i] ?? "")) i++;
2055
- if (body.startsWith("/>", i)) return { names, literals, selfClosing: true };
2056
- if (body[i] === ">") return { names, literals, selfClosing: false };
2090
+ if (body.startsWith("/>", i)) return { names, literals, values, end: i + 2, selfClosing: true };
2091
+ if (body[i] === ">") return { names, literals, values, selfClosing: false };
2057
2092
  if (body[i] === "{") return null;
2058
2093
  const name = /^[A-Za-z_][\w:-]*/.exec(body.slice(i))?.[0];
2059
2094
  if (!name) return null;
@@ -2061,6 +2096,7 @@ function tagAttributes(body, at) {
2061
2096
  i += name.length;
2062
2097
  if (body[i] !== "=") {
2063
2098
  literals.set(name, "true");
2099
+ values.set(name, "true");
2064
2100
  continue;
2065
2101
  }
2066
2102
  i++;
@@ -2068,12 +2104,27 @@ function tagAttributes(body, at) {
2068
2104
  const from = i;
2069
2105
  skipString(body[i]);
2070
2106
  literals.set(name, JSON.stringify(body.slice(from + 1, i - 1)));
2107
+ // JSX quoted attributes decode entities; object-property strings do not.
2108
+ const quoted = body.slice(from + 1, i - 1);
2109
+ let unsupportedEntity = false;
2110
+ const decoded = quoted.replace(/&(#x[0-9a-f]+|#\d+|[a-z][a-z0-9]+);/gi, (entity, key) => {
2111
+ const named = { amp: "&", quot: '"', apos: "'", lt: "<", gt: ">", nbsp: "\u00a0" };
2112
+ if (Object.hasOwn(named, key)) return named[key];
2113
+ const point = key.startsWith("#x") ? Number.parseInt(key.slice(2), 16) : key.startsWith("#") ? Number(key.slice(1)) : NaN;
2114
+ if (Number.isInteger(point) && point > 0 && point <= 0x10ffff && !(point >= 0xd800 && point <= 0xdfff)) return String.fromCodePoint(point);
2115
+ unsupportedEntity = true;
2116
+ return entity;
2117
+ });
2118
+ if (unsupportedEntity) literals.delete(name);
2119
+ else literals.set(name, JSON.stringify(decoded));
2120
+ values.set(name, unsupportedEntity ? null : JSON.stringify(decoded));
2071
2121
  continue;
2072
2122
  }
2073
2123
  if (body[i] !== "{") return null;
2074
2124
  const inner = braced();
2075
2125
  if (inner === null) return null;
2076
2126
  const value = inner.trim();
2127
+ values.set(name, value);
2077
2128
  if (/^(true|false|-?\d+(\.\d+)?|"(?:[^"\\\n]|\\.)*")$/.test(value)) literals.set(name, value);
2078
2129
  }
2079
2130
  return null;
@@ -2298,21 +2349,33 @@ function emitNode(node, ctx) {
2298
2349
  const sizing = ctx.bare || node.instance.set === "Detail Section / Row" ? [] : sizeClasses(node, parent, false);
2299
2350
  // A data slot passed straight to a prop is that prop (`trailing={<>{trailing}</>}` → `trailing={trailing}`).
2300
2351
  let own = rendered.code.trim().replace(/=\{<>\{([a-z][A-Za-z0-9]*)\}<\/>\}/g, "={$1}");
2301
- // The toolbar builds rows itself, so its template never renders the table slot.
2302
- // Preserve the published error component drawn there as its errorState contract.
2303
- if (node.instance.set === "Data Table Toolbar" && /^<DataTableToolbarBlock\b/.test(own) && !/\berrorState=/.test(own)) {
2352
+ // The toolbar owns table rendering, so its template does not emit this slot.
2353
+ // Preserve its drawn failure or zero-row composition through the supported props.
2354
+ if (node.instance.set === "Data Table Toolbar" && /^<DataTableToolbarBlock\b/.test(own)) {
2304
2355
  const tableSlot = (node.children ?? []).find(c => c.type === "SLOT" && c.slot === "table" && c.visible !== false);
2305
- const errors = [];
2356
+ const states = [];
2306
2357
  const collect = (current) => {
2307
2358
  if (current.visible === false) return;
2308
- if (current.instance?.remote && current.instance.set === "Error State Page") errors.push(current);
2359
+ if (current.instance?.remote && ["Error State Page", "Empty State"].includes(current.instance.set)) states.push(current);
2309
2360
  else for (const child of current.children ?? []) collect(child);
2310
2361
  };
2311
2362
  if (tableSlot) collect(tableSlot);
2312
- if (errors.length === 1) {
2313
- const errorCode = emitNode(errors[0], { ...ctx, depth: 0, parent: tableSlot, grand: node, path: `${path} › table`, root: false, inTable: false, inSlot: true, chain: [...chain, tableSlot] });
2314
- if (errorCode) own = own.replace(/^<DataTableToolbarBlock\b/, `<DataTableToolbarBlock errorState={${errorCode}}`);
2315
- } else if (errors.length > 1) note(`${path} › table`, "slot", "multiple Error State Page instances in one toolbar table slot: choose one error state");
2363
+ if (states.length === 1) {
2364
+ const error = states[0].instance.set === "Error State Page" || /(?:^|-)error(?:$|-)/.test(ctx.state ?? "");
2365
+ const prop = error ? "errorState" : "emptyState";
2366
+ if (!new RegExp(`\\b${prop}=`).test(own)) {
2367
+ const code = emitNode(states[0], { ...ctx, depth: 0, parent: tableSlot, grand: node, path: `${path} › table`, root: false, bare: true, inTable: false, inSlot: true, chain: [...chain, tableSlot] });
2368
+ if (error && code) own = own.replace(/^<DataTableToolbarBlock\b/, `<DataTableToolbarBlock errorState={${code}}`);
2369
+ else if (code?.startsWith("<EmptyState")) {
2370
+ const parsed = tagAttributes(code, "<EmptyState".length);
2371
+ const allowed = new Set(["title", "description", "actionLabel", "onAction", "actionDisabled", "actionDisabledReason", "illustration", "secondaryAction"]);
2372
+ if (parsed?.selfClosing && !code.slice(parsed.end).trim() && parsed.names.every(name => allowed.has(name) && parsed.values.get(name) !== null)) {
2373
+ const props = [...parsed.values].map(([name, value]) => `${name}: ${value}`).join(", ");
2374
+ own = own.replace(/^<DataTableToolbarBlock\b/, `<DataTableToolbarBlock emptyState={{ ${props} }}`);
2375
+ } else note(`${path} › table`, "slot", "drawn Empty State has props outside the toolbar emptyState contract");
2376
+ } else note(`${path} › table`, "slot", "drawn Empty State cannot be mapped to the toolbar emptyState contract");
2377
+ }
2378
+ } else if (states.length > 1) note(`${path} › table`, "slot", "multiple empty/error instances in one toolbar table slot: choose one state");
2316
2379
  }
2317
2380
  // A tab strip the page controls (tabOf reads the template's own strip first, to gather a run).
2318
2381
  if (!ctx.tabProbe) own = own.replace(/<Tabs panelless(?: defaultValue="[^"]*")?>/g, CONTROLLED_TABS("tab", "onTabChange"));
@@ -2594,6 +2657,18 @@ const PII_ROW_READ = /<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]
2594
2657
  * placeholder, so both are `column1`) cannot share a safe contract. Report a mapping
2595
2658
  * failure in every affected column instead of discarding its PiiText protection.
2596
2659
  */
2660
+ function mixedPiiExpressions(body) {
2661
+ const flat = maskStrings(body);
2662
+ return [...body.matchAll(/\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\.kind === "person" \? \(/g)].map(match => {
2663
+ let depth = 0, end = match.index;
2664
+ for (; end < flat.length; end++) {
2665
+ if (flat[end] === "{") depth++;
2666
+ if (flat[end] === "}" && --depth === 0) break;
2667
+ }
2668
+ return { at: match.index, end: end + 1, param: match[1], key: match[2], expression: body.slice(match.index, end + 1) };
2669
+ });
2670
+ }
2671
+
2597
2672
  function settlePiiColumns(views, unmapped) {
2598
2673
  const NODE_READ = /(^|>)\s*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\}/gm;
2599
2674
  const PII_CELL = />\n[ \t]*(?:<div\b[^>]*>\s*)*<PiiText value=\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*)\.value\} kind="[^\n]*\/>\s*(?:<\/div>\s*)*<\/TableCell>/g;
@@ -2615,7 +2690,56 @@ function settlePiiColumns(views, unmapped) {
2615
2690
  }
2616
2691
  for (const m of view.body.matchAll(NODE_READ)) count(view, openers, m.index, m[2], m[3], "node");
2617
2692
  }
2618
- const mixed = new Map([...reads].filter(([, r]) => r.pii && r.node));
2693
+ // A mixed cell declares its supported alternatives explicitly. Reuse that contract
2694
+ // in views which happen to draw only people or only the plain alternative.
2695
+ for (const view of views) {
2696
+ const openers = listOpeners(view.body);
2697
+ for (const m of mixedPiiExpressions(view.body)) {
2698
+ const r = reads.get(`${listAt(openers, m.at, m.param)}.${m.key}`);
2699
+ if (r) {
2700
+ const { expression } = m;
2701
+ const branches = expression.slice(1, -' : null}'.length).split(/ : (?=[a-z][A-Za-z0-9]*\.[A-Za-z][A-Za-z0-9]*\.kind === ")/);
2702
+ r.alternatives ??= new Map();
2703
+ for (const branch of branches) {
2704
+ const kind = /\.kind === "([^"]+)"/.exec(branch)?.[1];
2705
+ if (r.alternatives.has(kind) && r.alternatives.get(kind) !== branch) r.conflictingMixed = true;
2706
+ r.alternatives.set(kind, branch);
2707
+ }
2708
+ r.mixed = `{${[...r.alternatives.values()].join(" : ")} : null}`;
2709
+ }
2710
+ }
2711
+ }
2712
+ for (const view of views) {
2713
+ const openers = listOpeners(view.body);
2714
+ const replacements = [];
2715
+ for (const m of mixedPiiExpressions(view.body)) {
2716
+ const r = reads.get(`${listAt(openers, m.at, m.param)}.${m.key}`);
2717
+ if (r) replacements.push([m.at, m.end, r.conflictingMixed ? comment(`unmapped: incompatible mixed cell ${r.key}`) : r.mixed]);
2718
+ }
2719
+ for (const [start, end, replacement] of replacements.reverse()) view.body = view.body.slice(0, start) + replacement + view.body.slice(end);
2720
+ }
2721
+ for (const r of reads.values()) if (r.conflictingMixed) {
2722
+ unmapped.push({ variant: r.variant, path: r.list, kind: "table", detail: `column ${r.key} has incompatible mixed-cell templates across views` });
2723
+ r.mixed = comment(`unmapped: incompatible mixed cell ${r.key}`);
2724
+ }
2725
+ const mixed = new Map([...reads].filter(([, r]) => r.pii && r.node && !r.mixed));
2726
+ for (const view of views) {
2727
+ const openers = listOpeners(view.body);
2728
+ view.body = view.body.replace(PII_CELL, (all, param, key, at) => {
2729
+ const r = reads.get(`${listAt(openers, at, param)}.${key}`);
2730
+ return r?.mixed ? `>\n ${r.mixed}\n</TableCell>` : all;
2731
+ });
2732
+ const nullableOpeners = listOpeners(view.body);
2733
+ view.body = view.body.replace(/>\n[ \t]*\{([a-z][A-Za-z0-9]*)\.([A-Za-z][A-Za-z0-9]*) == null \? \("(?:[^"\\]|\\.)*"\) : \((?:<div\b[^>]*>\s*)*<PiiText[^\n]*\/>\s*(?:<\/div>\s*)*\)\}\n[ \t]*<\/TableCell>/g, (all, param, key, at) => {
2734
+ const r = reads.get(`${listAt(nullableOpeners, at, param)}.${key}`);
2735
+ return r?.mixed ? `>\n ${r.mixed}\n</TableCell>` : all;
2736
+ });
2737
+ const plainOpeners = listOpeners(view.body);
2738
+ view.body = view.body.replace(NODE_READ, (all, open, param, key, at) => {
2739
+ const r = reads.get(`${listAt(plainOpeners, at, param)}.${key}`);
2740
+ return r?.mixed ? `${open}${r.mixed}` : all;
2741
+ });
2742
+ }
2619
2743
  // All views share the row type. Once nullable, every view must guard its read.
2620
2744
  for (const view of views) {
2621
2745
  const openers = listOpeners(view.body);
@@ -2699,6 +2823,23 @@ function piiCellText({ cell, code }, ref) {
2699
2823
  return `${before}<PiiText value={${ref}.value} kind="${kind}" model={${ref}.model} relation={${ref}.relation} maskHint={${ref}.maskHint} surface="bulk"${size} />${after}`;
2700
2824
  }
2701
2825
 
2826
+ /** A non-person alternative must be plain text or a plain Badge, never arbitrary JSX. */
2827
+ function plainPiiAlternative(part) {
2828
+ if (part.held || !/^<TableCell\b/.test(part.code ?? "")) return null;
2829
+ const inner = part.code.slice(openTagEnd(part.code) + 1).replace(/<\/TableCell>$/, "").trim();
2830
+ if (/^\{("(?:[^"\\]|\\.)*")\}$/.test(inner)) return { kind: "text" };
2831
+ const badge = /^<Badge([^<>]*)>(?:\{("(?:[^"\\]|\\.)*")\}|([^<>{}]*))<\/Badge>$/.exec(inner);
2832
+ if (!badge || /[{}]/.test(badge[1])) return null;
2833
+ return { kind: "badge", template: `<Badge${badge[1]}>{__plainCellText__}</Badge>` };
2834
+ }
2835
+
2836
+ function mixedPiiText(mixed, ref) {
2837
+ const branches = [`${ref}.kind === "person" ? (${piiCellText(mixed.sample, ref)})`];
2838
+ if (mixed.text) branches.push(`${ref}.kind === "text" ? (<>{${ref}.text}</>)`);
2839
+ if (mixed.badge) branches.push(`${ref}.kind === "badge" ? (${mixed.badge.replace("__plainCellText__", `${ref}.text`)})`);
2840
+ return `{${branches.join(" : ")} : null}`;
2841
+ }
2842
+
2702
2843
  /** Only a plain literal empty cell is compatible with a nullable person. */
2703
2844
  function emptyPiiCell(part) {
2704
2845
  if (part.held || !/^<TableCell\b/.test(part.code ?? "")) return null;
@@ -2847,6 +2988,13 @@ function treeTableOf(node, ctx) {
2847
2988
  ].join("\n"), ctx.depth);
2848
2989
  }
2849
2990
 
2991
+ // The cell template uses a row wrapper to demonstrate Selected in isolation.
2992
+ // Assembly owns that row; lift its selection state once for the whole record.
2993
+ function selectedCell(code) {
2994
+ const match = /^<TableRow selected>\s*([\s\S]*?)\s*<\/TableRow>$/.exec(code?.trim() ?? "");
2995
+ return match && /^<Table(?:Cell|RowActions|SelectionCell)\b/.test(match[1]) ? match[1] : null;
2996
+ }
2997
+
2850
2998
  function tableOf(node, ctx) {
2851
2999
  const shown = (node.children ?? []).filter((c) => c.visible !== false);
2852
3000
  // What follows the rows (a table's Empty State, bare or in its own frame) follows the Table:
@@ -2865,7 +3013,9 @@ function tableOf(node, ctx) {
2865
3013
  for (const cell of (row.children ?? []).filter((c) => c.visible !== false)) {
2866
3014
  if (cell.instance?.remote) {
2867
3015
  const local = [];
2868
- const code = emitNode(cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true, imports: local, note: () => {} });
3016
+ const emitted = emitNode(cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true, imports: local, note: () => {} });
3017
+ const selected = selectedCell(emitted);
3018
+ const code = selected ?? emitted;
2869
3019
  if (isSkeleton(code?.trim())) {
2870
3020
  imports.push(...local);
2871
3021
  cells.push({ cell, code: code.trim(), loading: true });
@@ -2883,7 +3033,7 @@ function tableOf(node, ctx) {
2883
3033
  // Rich Cell) keeps its own template code, as a cell of that row.
2884
3034
  kind = kind === "head" || part === "head" ? "head" : part;
2885
3035
  imports.push(...local);
2886
- cells.push({ cell, code });
3036
+ cells.push({ cell, code, selected: selected !== null });
2887
3037
  } else if (cell.layout || cell.type === "TEXT") cells.push({ cell, code: null });
2888
3038
  else return null;
2889
3039
  }
@@ -2960,7 +3110,7 @@ function tableOf(node, ctx) {
2960
3110
  const density = declaredDensity(parsed.find((p) => p.row === row)?.cells ?? []) ?? tableDensity;
2961
3111
  return `${widthAttr(w)}${density ? ` density="${density}"` : ""}`;
2962
3112
  };
2963
- const cellCode = ({ cell, code, held }, row, d, column = null) => {
3113
+ const cellCode = ({ cell, code, held, selected }, row, d, column = null) => {
2964
3114
  const w = columnWidth(cell);
2965
3115
  if (held) {
2966
3116
  const inner = emitNode(cell, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true });
@@ -2968,7 +3118,8 @@ function tableOf(node, ctx) {
2968
3118
  }
2969
3119
  if (code) {
2970
3120
  // Re-emit for real, so the cell's own unmapped layers are reported.
2971
- return withWidth(emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true, column }), w);
3121
+ const emitted = emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, inTable: true, column });
3122
+ return withWidth(selected ? indent(selectedCell(emitted), d) : emitted, w);
2972
3123
  }
2973
3124
  // The frame stood in for the cell: its size and padding are the TableCell's now.
2974
3125
  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 });
@@ -3040,6 +3191,9 @@ function tableOf(node, ctx) {
3040
3191
  const first = dataRows[0];
3041
3192
  const keys = columnKeys(first.cells.length);
3042
3193
  const rowsName = mark(ctx, listName, "rows", null);
3194
+ let selectedKey = "isSelected";
3195
+ while (keys.includes(selectedKey)) selectedKey += "Row";
3196
+ const selection = dataRows.some(p => p.cells.some(c => c.selected)) ? ` selected={row.${selectedKey}}` : "";
3043
3197
  // A row is a door to its record when the page passes a handler (U03-7; NODII-DEV-CLI-83).
3044
3198
  const rowClick = mark(ctx, listName, "onRowClick", null);
3045
3199
  const inert = mark(ctx, listName, "isRowInert", null);
@@ -3047,10 +3201,11 @@ function tableOf(node, ctx) {
3047
3201
  ctx.note(ctx.path, LIFTED, `${dataRows.length} body row${dataRows.length === 1 ? "" : "s"} lifted as data: rows of { id, ${keys.join(", ")} } (NODII-DEV-CLI-82)`);
3048
3202
  // A column whose every body cell is a PiiText is a person's value: its row field is the
3049
3203
  // served pair and the cell draws PiiText from it, never a node the page could fill with a
3050
- // raw name (U05; cli-140). Mixed content must be compatible with a nullable
3051
- // person; otherwise the column is an explicit mapping failure.
3204
+ // raw name (U05; cli-140). Plain text and plain badges form typed alternatives;
3205
+ // unsupported mixed content remains an explicit mapping failure.
3052
3206
  const invalidPii = new Map();
3053
3207
  const nullablePii = new Map();
3208
+ const mixedPii = new Map();
3054
3209
  const personSamples = new Map();
3055
3210
  const piiColumn = keys.map((key, i) => {
3056
3211
  const people = dataRows.filter((p) => piiCellAttrs(p.cells[i]) !== null);
@@ -3064,13 +3219,19 @@ function tableOf(node, ctx) {
3064
3219
  const empties = others.map(p => emptyPiiCell(p.cells[i]));
3065
3220
  const nullable = drawn > 0 && others.length > 0 && empties.every(value => value !== null) && new Set(empties).size === 1;
3066
3221
  if (nullable) nullablePii.set(i, { sample: people[0].cells[i], empty: empties[0] });
3067
- if (drawn > 0 && drawn < dataRows.length && !nullable) {
3222
+ const plain = others.map(p => plainPiiAlternative(p.cells[i]));
3223
+ const mixed = drawn > 0 && others.length > 0 && !nullable && plain.every(Boolean);
3224
+ if (mixed) {
3225
+ const badges = plain.filter(p => p.kind === "badge");
3226
+ if (new Set(badges.map(p => p.template)).size <= 1) mixedPii.set(i, { sample: people[0].cells[i], badge: badges[0]?.template, text: plain.some(p => p.kind === "text") });
3227
+ }
3228
+ if (drawn > 0 && drawn < dataRows.length && !nullable && !mixedPii.has(i)) {
3068
3229
  const why = `column ${key} mixes PiiText with incompatible non-person content`;
3069
3230
  ctx.note(ctx.path, "table", `${why}: left unmapped (U05; cli-140)`);
3070
3231
  invalidPii.set(i, why);
3071
3232
  return false;
3072
3233
  }
3073
- if (drawn === dataRows.length || nullable) {
3234
+ if (drawn === dataRows.length || nullable || mixedPii.has(i)) {
3074
3235
  const kinds = people.map((p) => piiTreeKind(p.cells[i].cell));
3075
3236
  const why = kinds.some((kind) => !PII_KINDS.has(kind))
3076
3237
  ? `column ${key} has no recognised PiiText kind in one or more body rows`
@@ -3081,7 +3242,7 @@ function tableOf(node, ctx) {
3081
3242
  return false;
3082
3243
  }
3083
3244
  }
3084
- return drawn === dataRows.length || nullable;
3245
+ return drawn === dataRows.length || nullable || mixedPii.has(i);
3085
3246
  });
3086
3247
  const secondaryKeys = new Set(keys);
3087
3248
  const cells = first.cells.map((c, i) => {
@@ -3089,7 +3250,8 @@ function tableOf(node, ctx) {
3089
3250
  let open = `<TableCell${wrapperAttrs(w, first.row)}>`;
3090
3251
  let close = "</TableCell>";
3091
3252
  if (c.code && !c.held) {
3092
- const own = withWidth(emitNode(c.cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${first.row.name}`, root: false, bare: true, inTable: true, scopes: null, note: () => {} }), w).trim();
3253
+ const emitted = emitNode(c.cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${first.row.name}`, root: false, bare: true, inTable: true, scopes: null, note: () => {} });
3254
+ const own = withWidth(c.selected ? selectedCell(emitted) : emitted, w).trim();
3093
3255
  const end = openTagEnd(own);
3094
3256
  const tag = /^<([A-Za-z]+)/.exec(own)[1];
3095
3257
  open = own.slice(0, end + 1).replace(/\s*\/>$/, ">");
@@ -3109,14 +3271,15 @@ function tableOf(node, ctx) {
3109
3271
  if (piiColumn[i]) {
3110
3272
  const nullable = nullablePii.get(i);
3111
3273
  const ref = `row.${keys[i]}`;
3112
- const content = nullable ? `{${ref} == null ? (${nullable.empty}) : (${piiCellText(nullable.sample, ref)})}` : piiCellText(personSamples.get(i) ?? c, ref);
3274
+ const mixed = mixedPii.get(i);
3275
+ const content = mixed ? mixedPiiText(mixed, ref) : nullable ? `{${ref} == null ? (${nullable.empty}) : (${piiCellText(nullable.sample, ref)})}` : piiCellText(personSamples.get(i) ?? c, ref);
3113
3276
  return indent(`${open}\n ${content}\n${close}`, depth + 4);
3114
3277
  }
3115
3278
  return indent(`${open}{row.${keys[i]}}${close}`, depth + 4);
3116
3279
  });
3117
3280
  return [
3118
3281
  indent(`{${rowsName}.map((row) => (`, depth + 2),
3119
- indent(`<TableRow key={row.id} onClick={${inert}?.(row) ? undefined : ${getClick} ? ${getClick}(row) : ${rowClick} && (() => ${rowClick}(row))}>`, depth + 3),
3282
+ indent(`<TableRow key={row.id}${selection} onClick={${inert}?.(row) ? undefined : ${getClick} ? ${getClick}(row) : ${rowClick} && (() => ${rowClick}(row))}>`, depth + 3),
3120
3283
  ...cells,
3121
3284
  indent("</TableRow>", depth + 3),
3122
3285
  indent("))}", depth + 2),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.164",
3
+ "version": "0.6.166",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {