@nodii/dev 0.6.91 → 0.6.93

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
@@ -925,6 +925,14 @@ product-page catalog names the Surface by its published component-set key
925
925
  so a stopped or killed run keeps its reads. Add `--resume` to carry on: it keeps
926
926
  a saved tree and reads only the rest. With `--figma-version V`, it keeps only
927
927
  trees read at `V`.
928
+ - **Table assembly.** A table drawn as frames goes in the DS `Table`'s anatomy. A
929
+ cell that is no Table part is held in a `TableCell`, and a wrapped cell takes its
930
+ row's density.
931
+ - **Exposed instances and text.** A tree keeps a remote instance's exposed nested
932
+ instances by layer name, for a template's `findInstance`. Text bound to a DS text
933
+ style and a DS colour role is listed as kind `bound-text` and doesn't count against
934
+ a Surface being clean. Text missing either binding is unmapped, and so is text in a
935
+ part that should own it as a property.
928
936
  - **Scoreboard.** Every run returns `data.scoreboard`, one row per module, and
929
937
  `--all` also prints it: Surfaces clean out of total, not published, not
930
938
  generated yet, and unmapped layers by kind. A Surface is clean when it has no
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.91";
7
+ export const VERSION = "0.6.93";
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
@@ -31,7 +31,7 @@ import { CliError, VERSION, devRequest, readConfig } from "./core.js";
31
31
  import { createRenderer } from "./vendor/render-templates.mjs";
32
32
 
33
33
  /** Bumped whenever the emitted code changes shape for the same inputs. */
34
- export const GENERATOR_FORMAT = 5;
34
+ export const GENERATOR_FORMAT = 6;
35
35
  export const TREE_DIR = "docs/figma-ux-ds/figma/surface-trees";
36
36
  export const GENERATED_SUFFIX = ".surface.generated.tsx";
37
37
  const CATALOG_PATH = "packages/blocks/src/product-pages/catalog.ts";
@@ -255,17 +255,32 @@ export function trimTree(entry, { row, version }) {
255
255
 
256
256
  if (node.type === "INSTANCE") {
257
257
  const main = components[node.componentId] ?? {};
258
+ const propsOf = (instance) =>
259
+ Object.fromEntries(
260
+ Object.entries(instance.componentProperties ?? {})
261
+ .filter(([, p]) => p.type !== "SLOT")
262
+ .map(([name, p]) => [stripPropId(name), p.type === "INSTANCE_SWAP" ? { swap: keyOf(p.value) } : p.value]),
263
+ );
258
264
  out.instance = {
259
265
  key: main.key ?? null,
260
266
  component: main.name ?? null,
261
267
  set: sets[main.componentSetId]?.name ?? null,
262
268
  remote: Boolean(main.remote),
263
- props: Object.fromEntries(
264
- Object.entries(node.componentProperties ?? {})
265
- .filter(([, p]) => p.type !== "SLOT")
266
- .map(([name, p]) => [stripPropId(name), p.type === "INSTANCE_SWAP" ? { swap: keyOf(p.value) } : p.value]),
267
- ),
269
+ props: propsOf(node),
268
270
  };
271
+ // An exposed nested instance is set on the Surface, and only a template's
272
+ // findInstance can read it, so its properties are kept by layer name.
273
+ if (main.remote && node.exposedInstances?.length) {
274
+ const exposed = {};
275
+ const walk = (parent) => {
276
+ for (const child of parent.children ?? []) {
277
+ if (child.isExposedInstance && !exposed[child.name]) exposed[child.name] = { key: keyOf(child.componentId), props: propsOf(child) };
278
+ walk(child);
279
+ }
280
+ };
281
+ walk(node);
282
+ if (Object.keys(exposed).length) out.instance.exposed = exposed;
283
+ }
269
284
  // A library instance is the template's to draw: only its slots' content is the Surface's.
270
285
  const children = main.remote ? (node.children ?? []).filter((c) => c.type === "SLOT") : (node.children ?? []);
271
286
  if (children.length) out.children = children.map((c) => trim(c, box));
@@ -389,7 +404,9 @@ export function emitSurface(tree, row, ds) {
389
404
  used.add(state);
390
405
  const fn = `${pascal(state)}View`;
391
406
  const note = (path, kind, detail) => unmapped.push({ variant: variant.name, path, kind, detail });
392
- const body = emitNode(variant.root, { depth: 2, parent: null, path: variant.name, ds, imports, note, root: true });
407
+ const emitted = emitNode(variant.root, { depth: 2, parent: null, path: variant.name, ds, imports, note, root: true }) ?? "";
408
+ // A refused root is only a comment, and `return ({/* … */})` is an object, not JSX.
409
+ const body = emitted.trimStart().startsWith("{/*") ? [" <>", indent(emitted.trim(), 3), " </>"].join("\n") : emitted;
393
410
  return { state, fn, body };
394
411
  });
395
412
  const component = `${pascal(row.id)}Surface`;
@@ -572,6 +589,12 @@ function colour(prefix, paint, scope, ds, report) {
572
589
  return null;
573
590
  }
574
591
 
592
+ /** Text with both DS bindings: listed, but not counted against a Surface being clean. */
593
+ const BOUND_TEXT = "bound-text";
594
+ const counted = (unmapped) => unmapped.filter((u) => u.kind !== BOUND_TEXT);
595
+
596
+ /** DS parts whose text should be a component property, not slot content (the Q-211 Lock-Change). */
597
+ const TEXT_PROPERTY_PARTS = new Set(["Table cell", "Table Header", "File Viewer"]);
575
598
  const SHAPES = new Set(["RECTANGLE", "ELLIPSE", "LINE", "VECTOR", "BOOLEAN_OPERATION", "STAR", "REGULAR_POLYGON"]);
576
599
  const cls = (list) => [...new Set(list.filter(Boolean))].join(" ");
577
600
  const describe = (node) => (node.instance ? `${node.instance.set ?? node.instance.component ?? "component"}${node.instance.set ? ` [${node.instance.component}]` : ""}` : node.type);
@@ -587,8 +610,13 @@ function emitNode(node, ctx) {
587
610
  // A DS library instance: exactly what its Code Connect template emits for this instance's properties.
588
611
  if (node.instance?.remote) {
589
612
  const dsNode = node.instance.key ? ds.byKey.get(node.instance.key) : null;
590
- const values = Object.fromEntries(
591
- Object.entries(node.instance.props).map(([name, value]) => [name, value && typeof value === "object" && "swap" in value ? (ds.byKey.get(value.swap) ?? value.swap) : value]),
613
+ const valuesOf = (props) =>
614
+ Object.fromEntries(Object.entries(props).map(([name, value]) => [name, value && typeof value === "object" && "swap" in value ? (ds.byKey.get(value.swap) ?? value.swap) : value]));
615
+ const values = valuesOf(node.instance.props);
616
+ const nested = Object.fromEntries(
617
+ Object.entries(node.instance.exposed ?? {})
618
+ .filter(([, e]) => ds.byKey.has(e.key))
619
+ .map(([layer, e]) => [layer, { nodeId: ds.byKey.get(e.key), values: valuesOf(e.props) }]),
592
620
  );
593
621
  const slotContent = (prop) => {
594
622
  const slotNode = (node.children ?? []).find((c) => c.type === "SLOT" && c.slot === prop);
@@ -596,10 +624,11 @@ function emitNode(node, ctx) {
596
624
  note(`${path} › ${prop}`, "layout", `slot ${prop} has no auto layout`);
597
625
  return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
598
626
  }
599
- const inner = (slotNode?.children ?? []).map((c) => emitNode(c, { ...ctx, depth: 0, parent: slotNode, path: `${path} › ${prop}`, root: false })).filter((x) => x !== null);
627
+ const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
628
+ const inner = (slotNode?.children ?? []).map((c) => emitNode(c, { ...ctx, depth: 0, parent: slotNode, path: `${path} › ${prop}`, root: false, textOwner })).filter((x) => x !== null);
600
629
  return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
601
630
  };
602
- const rendered = dsNode ? ds.renderer.renderInstance(ds.dsFileKey, dsNode, values, { slot: slotContent }) : null;
631
+ const rendered = dsNode ? ds.renderer.renderInstance(ds.dsFileKey, dsNode, values, { slot: slotContent, nested }) : null;
603
632
  if (!rendered || rendered.error || !rendered.code?.trim()) {
604
633
  const why = !dsNode ? "not a published DS library component" : !rendered ? "no Code Connect template" : rendered.error ? `template error: ${rendered.error}` : "the template emits no code";
605
634
  note(path, "instance", `${describe(node)}: ${why}`);
@@ -615,11 +644,19 @@ function emitNode(node, ctx) {
615
644
 
616
645
  if (node.type === "TEXT") {
617
646
  const utility = textUtility(node.textStyle, ds.textStyles);
618
- note(path, "text", `loose text ${JSON.stringify(node.text.length > 60 ? `${node.text.slice(0, 57)}…` : node.text)}${utility ? "" : ` (style ${node.textStyle ?? "none"} has no DS text utility)`}`);
647
+ const role = node.color ? colour("text", node.color, "TEXT_FILL", ds, report) : null;
648
+ // Text bound to a DS text style and a DS colour role is still listed, as its own kind
649
+ // (U08-14), but doesn't count against "clean": its code is that utility and that role,
650
+ // the same "clean" as Dev's Surfaces check. Text missing a binding is unmapped, and so
651
+ // is text that should be a property of the part holding it.
652
+ const shown = JSON.stringify(node.text.length > 60 ? `${node.text.slice(0, 57)}…` : node.text);
653
+ if (ctx.textOwner) note(path, "text", `text ${shown} in a ${ctx.textOwner} slot: it should be a property of ${ctx.textOwner} (DS blocker)`);
654
+ else if (!utility || !role) note(path, "text", `loose text ${shown}${utility ? "" : ` (style ${node.textStyle ?? "none"} has no DS text utility)`}${role ? "" : " (no DS colour role)"}`);
655
+ else note(path, BOUND_TEXT, `text ${shown} bound to ${node.textStyle} and ${role}, with no Code Connect mapping`);
619
656
  const classes = cls([
620
657
  ...sizeClasses(node, parent, false).filter((c) => !c.startsWith("h-")),
621
658
  utility,
622
- node.color ? colour("text", node.color, "TEXT_FILL", ds, report) : null,
659
+ role,
623
660
  { CENTER: "text-center", RIGHT: "text-right", JUSTIFIED: "text-justify" }[node.align],
624
661
  node.maxLines === 1 ? "truncate" : node.maxLines ? `line-clamp-${node.maxLines}` : null,
625
662
  ]);
@@ -686,7 +723,12 @@ function withWidth(code, w) {
686
723
  return code.replace(m[1], `${m[1]}${widthAttr(w)}`);
687
724
  }
688
725
  function tableOf(node, ctx) {
689
- const rows = (node.children ?? []).filter((c) => c.visible !== false);
726
+ const shown = (node.children ?? []).filter((c) => c.visible !== false);
727
+ // A DS instance after the rows (a table's Empty State) follows the Table: it must not undo it.
728
+ let end = shown.length;
729
+ while (end > 0 && shown[end - 1].instance?.remote) end -= 1;
730
+ const rows = shown.slice(0, end);
731
+ const after = shown.slice(end);
690
732
  if (!rows.length || rows.some((r) => r.instance?.remote || r.type === "TEXT" || r.layout?.mode !== "HORIZONTAL")) return null;
691
733
  const imports = [];
692
734
  const parsed = [];
@@ -698,7 +740,14 @@ function tableOf(node, ctx) {
698
740
  const local = [];
699
741
  const code = emitNode(cell, { ...ctx, depth: 0, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true, imports: local, note: () => {} });
700
742
  const part = tablePart(/^<([A-Za-z]+)/.exec(code ?? "")?.[1]);
701
- if (!part || (kind && kind !== part)) return null;
743
+ // A cell that is no Table part (a component with no template, or a DS part drawn
744
+ // in a row) is held in a TableCell: one such cell must not undo the whole table.
745
+ if (!part) {
746
+ imports.push(...local);
747
+ cells.push({ cell, code, held: true });
748
+ continue;
749
+ }
750
+ if (kind && kind !== part) return null;
702
751
  kind = part;
703
752
  imports.push(...local);
704
753
  cells.push({ cell, code });
@@ -713,15 +762,27 @@ function tableOf(node, ctx) {
713
762
  ctx.note(ctx.path, "table", `table drawn as frames (${rows.length} row${rows.length === 1 ? "" : "s"}); assembled into the DS Table's parts`);
714
763
  ctx.imports.push(...imports, `import { Table, TableBody, TableHeader, TableRow } from "${module}";`);
715
764
  const { depth } = ctx;
716
- const cellCode = ({ cell, code }, row, d) => {
765
+ // A cell the generator wraps has no template to say its density, so it takes the one
766
+ // its row's template cells declare, or the table's: a row is one height in Figma.
767
+ const declaredDensity = (cells) => cells.map((c) => (c.held ? null : /\bdensity="(\w+)"/.exec(c.code ?? "")?.[1])).find(Boolean);
768
+ const tableDensity = declaredDensity(parsed.flatMap((p) => p.cells));
769
+ const wrapperAttrs = (w, row) => {
770
+ const density = declaredDensity(parsed.find((p) => p.row === row)?.cells ?? []) ?? tableDensity;
771
+ return `${widthAttr(w)}${density ? ` density="${density}"` : ""}`;
772
+ };
773
+ const cellCode = ({ cell, code, held }, row, d) => {
717
774
  const w = columnWidth(cell);
775
+ if (held) {
776
+ const inner = emitNode(cell, { ...ctx, depth: d + 1, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true });
777
+ return [indent(`<TableCell${wrapperAttrs(w, row)}>`, d), inner, indent("</TableCell>", d)].join("\n");
778
+ }
718
779
  if (code) {
719
780
  // Re-emit for real, so the cell's own unmapped layers are reported.
720
781
  return withWidth(emitNode(cell, { ...ctx, depth: d, parent: null, path: `${ctx.path} › ${row.name}`, root: false, bare: true }), w);
721
782
  }
722
783
  // The frame stood in for the cell: its size and padding are the TableCell's now.
723
784
  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 });
724
- return [indent(`<TableCell${widthAttr(w)}>`, d), inner, indent("</TableCell>", d)].join("\n");
785
+ return [indent(`<TableCell${wrapperAttrs(w, row)}>`, d), inner, indent("</TableCell>", d)].join("\n");
725
786
  };
726
787
  // Every column held at px or fill is a fixed table layout; a hug column needs the browser's auto layout.
727
788
  const widths = parsed.flatMap((p) => p.cells.map((c) => columnWidth(c.cell)));
@@ -737,8 +798,10 @@ function tableOf(node, ctx) {
737
798
  };
738
799
  const sizing = sizeClasses(node, ctx.parent, ctx.root);
739
800
  const table = [indent(fixed ? '<Table layout="fixed">' : "<Table>", depth), ...section("head", "TableHeader"), ...section("body", "TableBody"), indent("</Table>", depth)];
740
- if (!sizing.length) return table.join("\n");
741
- return [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, depth), ...table.map((line) => indent(line, 1)), indent("</div>", depth)].join("\n");
801
+ const following = after.map((c) => emitNode(c, { ...ctx, depth, parent: node, path: `${ctx.path} › ${c.name}`, root: false })).filter((x) => x !== null);
802
+ if (!sizing.length && !following.length) return table.join("\n");
803
+ const lines = [...table, ...following.flatMap((code) => code.split("\n"))];
804
+ return [indent(`<div className="${cls(["flex", "flex-col", ...sizing])}">`, depth), ...lines.map((line) => indent(line, 1)), indent("</div>", depth)].join("\n");
742
805
  }
743
806
 
744
807
  // ---------------------------------------------------------------------------
@@ -776,7 +839,7 @@ export function unmappedMarkdown(files) {
776
839
  const lines = [
777
840
  "# Surface layers with no Code Connect mapping (U08-14)",
778
841
  "",
779
- "Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (loose text, drawn with the DS type utility and colour role), `frame` (a frame that paints its own fill, stroke, radius or effect: only its layout is generated), `table` (a table drawn as frames, assembled into the DS Table's parts), `layout` (a frame or slot with no auto layout), `shape` (a rectangle, ellipse or vector: marked, not drawn), `token` (a text colour that matches no colour v2 role: left out).",
842
+ "Generated by `nodii-dev surface generate --report`. Kinds: `instance` (a library instance the generator cannot emit through a template), `text` (text missing a DS text style or colour role, or text in a part that should own it as a property), `frame` (a frame that paints its own fill, stroke, radius or effect: only its layout is generated), `table` (a table drawn as frames, assembled into the DS Table's parts), `layout` (a frame or slot with no auto layout), `shape` (a rectangle, ellipse or vector: marked, not drawn), `token` (a text colour that matches no colour v2 role: left out), `bound-text` (text bound to a DS text style and colour role, with no Code Connect mapping: listed, not counted against a Surface being clean).",
780
843
  "",
781
844
  ];
782
845
  for (const [fileKey, file] of Object.entries(files)) {
@@ -802,7 +865,7 @@ export function surfaceScoreboard(selected, results, { unpublished = [], notGene
802
865
  const modules = new Map();
803
866
  const of = (row) => {
804
867
  const name = moduleOf(row);
805
- if (!modules.has(name)) modules.set(name, { module: name, total: 0, clean: 0, unmapped: 0, byKind: {}, unpublished: [], notGeneratedYet: [] });
868
+ if (!modules.has(name)) modules.set(name, { module: name, total: 0, clean: 0, unmapped: 0, boundText: 0, byKind: {}, unpublished: [], notGeneratedYet: [] });
806
869
  return modules.get(name);
807
870
  };
808
871
  for (const row of selected) of(row).total += 1;
@@ -810,9 +873,11 @@ export function surfaceScoreboard(selected, results, { unpublished = [], notGene
810
873
  for (const row of notGeneratedYet) of(row).notGeneratedYet.push(row.id);
811
874
  for (const r of results) {
812
875
  const entry = of(r.row);
813
- if (!r.unmapped.length) entry.clean += 1;
814
- entry.unmapped += r.unmapped.length;
815
- for (const u of r.unmapped) entry.byKind[u.kind] = (entry.byKind[u.kind] ?? 0) + 1;
876
+ const real = counted(r.unmapped);
877
+ if (!real.length) entry.clean += 1;
878
+ entry.unmapped += real.length;
879
+ entry.boundText += r.unmapped.length - real.length;
880
+ for (const u of real) entry.byKind[u.kind] = (entry.byKind[u.kind] ?? 0) + 1;
816
881
  }
817
882
  return [...modules.values()];
818
883
  }
@@ -836,7 +901,7 @@ export function scoreboardMarkdown(board, { mode, source, stopped = null }) {
836
901
  `**Surface scoreboard** (\`surface generate\`, ${mode} run, \`@nodii/dev\` ${VERSION}, ${source}).`,
837
902
  "",
838
903
  ...(stopped ? [`**Partial: Figma answered 429 at \`${stopped.at}\`, so the run stopped with ${stopped.notRead.length} Surface${stopped.notRead.length === 1 ? "" : "s"} not read.** They count as not generated yet.`, ""] : []),
839
- "A Surface is clean when it has no unmapped layer. Total counts every selected Surface, including those not published or not generated yet.",
904
+ "A Surface is clean when it has no unmapped layer. Text bound to a DS text style and colour role is listed in the report, and is not counted here. Total counts every selected Surface, including those not published or not generated yet.",
840
905
  "",
841
906
  "| Module | Clean / total | Not published | Not generated yet | Unmapped | By kind |",
842
907
  "|---|---:|---:|---:|---:|---|",
@@ -981,7 +1046,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
981
1046
  const payload = {
982
1047
  data: {
983
1048
  mode,
984
- surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, states: r.states, unmapped: r.unmapped.length })),
1049
+ surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, states: r.states, unmapped: counted(r.unmapped).length })),
985
1050
  differences,
986
1051
  notGeneratedYet: notYet,
987
1052
  unpublished: unpublished.map((row) => ({ id: row.id, componentSetKey: row.componentSetKey, fileKey: row.fileKey })),
@@ -994,7 +1059,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
994
1059
  const human = () => {
995
1060
  if (!f.write && !f.check && !f.all && results.length === 1) return results[0].code;
996
1061
  const lines = results.map(
997
- (r) => `${f.write ? "wrote" : f.check ? (differences.some((d) => d.id === r.row.id) ? "DIFFERS" : "equal") : "generated"}\t${r.file}\t${r.states.length} state${r.states.length === 1 ? "" : "s"}\t${r.unmapped.length} unmapped layer${r.unmapped.length === 1 ? "" : "s"}`,
1062
+ (r) => `${f.write ? "wrote" : f.check ? (differences.some((d) => d.id === r.row.id) ? "DIFFERS" : "equal") : "generated"}\t${r.file}\t${r.states.length} state${r.states.length === 1 ? "" : "s"}\t${counted(r.unmapped).length} unmapped layer${counted(r.unmapped).length === 1 ? "" : "s"}`,
998
1063
  );
999
1064
  if (notYet.length) lines.push(`not generated yet: ${notYet.length} catalog Surface${notYet.length === 1 ? "" : "s"} (no committed tree); generate one with \`nodii-dev surface generate <componentSetKey> --fetch --write\``);
1000
1065
  if (unpublished.length) lines.push(`not published: ${unpublished.length} Surface${unpublished.length === 1 ? "" : "s"} skipped, not generated or scored: ${unpublished.map((row) => row.id).join(", ")}`);
@@ -279,7 +279,7 @@ export function createRenderer(root, docs, options = {}) {
279
279
  return props;
280
280
  }
281
281
 
282
- function makeInstance(context, setNode, props, depth, label, reads = null) {
282
+ function makeInstance(context, setNode, props, depth, label, reads = null, exposed = null) {
283
283
  const need = (name, type) => {
284
284
  reads?.add(name);
285
285
  const prop = props.get(name);
@@ -328,6 +328,17 @@ export function createRenderer(root, docs, options = {}) {
328
328
  return slot;
329
329
  },
330
330
  getPropertyValue: (name) => need(name).value,
331
+ // The snapshot holds component properties, not the layer tree, so a
332
+ // layer lookup answers as Figma does for a layer it cannot find: an
333
+ // error handle. Templates that read exposed nested instances
334
+ // (DEC-0432) fall back to their placeholders here, unless the caller
335
+ // has the instance's exposed layers (renderInstance's `nested`).
336
+ findInstance: (layerName) =>
337
+ exposed?.(layerName) ?? { type: "ERROR", layerName },
338
+ findText: (layerName) => ({ type: "ERROR", layerName }),
339
+ findConnectedInstance: (layerName) => ({ type: "ERROR", layerName }),
340
+ findConnectedInstances: () => [],
341
+ findLayers: () => [],
331
342
  hasCodeConnect: () => true,
332
343
  codeConnectId: () => null,
333
344
  };
@@ -591,7 +602,7 @@ export function createRenderer(root, docs, options = {}) {
591
602
  * instances this way. Returns { code, imports } | { error } | null (no
592
603
  * template maps the component).
593
604
  */
594
- function renderInstance(fileKey, nodeId, values = {}, { slot } = {}) {
605
+ function renderInstance(fileKey, nodeId, values = {}, { slot, nested } = {}) {
595
606
  const context = contexts.get(fileKey);
596
607
  const found = context ? docForComponent(context, nodeId) : null;
597
608
  if (!found?.node) return null;
@@ -600,6 +611,37 @@ export function createRenderer(root, docs, options = {}) {
600
611
  ? context.byId.get(found.node.parentId)
601
612
  : found.node;
602
613
  const label = `${setNode.name} instance`;
614
+ // `nested` is this instance's exposed layers, { layerName: { nodeId, values } }.
615
+ const exposed = (layerName) => {
616
+ const entry = nested?.[layerName];
617
+ const target = entry ? docForComponent(context, entry.nodeId) : null;
618
+ if (!target?.node) return null;
619
+ const targetSet =
620
+ target.node.parentType === "COMPONENT_SET"
621
+ ? context.byId.get(target.node.parentId)
622
+ : target.node;
623
+ const handle = makeInstance(
624
+ context,
625
+ targetSet,
626
+ propsFor(targetSet, target.node, entry.values),
627
+ 1,
628
+ `${label} > ${layerName}`
629
+ );
630
+ return {
631
+ ...handle,
632
+ executeTemplate: () => {
633
+ const result = runTemplate(target.doc, handle);
634
+ return {
635
+ example: result.example.sections.map((section, index) =>
636
+ index === 0
637
+ ? { ...section, nestedImports: result.imports ?? [] }
638
+ : section
639
+ ),
640
+ metadata: result.metadata,
641
+ };
642
+ },
643
+ };
644
+ };
603
645
  try {
604
646
  const result = runTemplate(
605
647
  found.doc,
@@ -608,7 +650,9 @@ export function createRenderer(root, docs, options = {}) {
608
650
  setNode,
609
651
  propsFor(setNode, found.node, values),
610
652
  0,
611
- label
653
+ label,
654
+ null,
655
+ exposed
612
656
  )
613
657
  );
614
658
  const imports = new Set(result.imports ?? []);
@@ -736,5 +780,51 @@ export function createRenderer(root, docs, options = {}) {
736
780
  };
737
781
  }
738
782
 
739
- return { renderDoc, renderVariants, renderInstance, fidelityOf };
783
+ /**
784
+ * Which of its Figma component's properties does a template read, in any
785
+ * case it can be rendered in? (The `code-connect-complete` gate,
786
+ * DESIGN-SYSTEM-252.) Every case `renderDoc` renders (every real variant,
787
+ * booleans at default / all on / all off / each flipped, hostile TEXT) plus
788
+ * every probe of `fidelityOf`, so a property read only behind a toggle
789
+ * counts. Returns { definitions: [{ name, type, options }], read: [name] }
790
+ * or null when the node is not in a snapshot.
791
+ */
792
+ function readsOf(doc) {
793
+ const nodeId = nodeIdFromUrl(doc.figmaNode);
794
+ const context = [...contexts.entries()].find(([fileKey]) =>
795
+ doc.figmaNode.includes(`/design/${fileKey}/`)
796
+ )?.[1];
797
+ const setNode = context?.byId.get(nodeId);
798
+ if (!setNode) return null;
799
+ const reads = new Set();
800
+ for (const entry of casesFor(context, nodeId)) {
801
+ try {
802
+ runTemplate(
803
+ doc,
804
+ makeInstance(
805
+ context,
806
+ entry.setNode,
807
+ propsFor(entry.setNode, entry.variant, entry.overrides),
808
+ 0,
809
+ entry.label,
810
+ reads
811
+ )
812
+ );
813
+ } catch {
814
+ // A render error is the compile gate's to report; the reads made
815
+ // before it still count.
816
+ }
817
+ }
818
+ for (const name of fidelityOf(doc)?.read ?? []) reads.add(name);
819
+ const definitions = Object.entries(setNode.propertyDefinitions ?? {}).map(
820
+ ([key, def]) => ({
821
+ name: stripSuffix(key),
822
+ type: def.type,
823
+ options: def.variantOptions ?? null,
824
+ })
825
+ );
826
+ return { definitions, read: [...reads].sort() };
827
+ }
828
+
829
+ return { renderDoc, renderVariants, renderInstance, fidelityOf, readsOf };
740
830
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nodii/dev",
3
- "version": "0.6.91",
3
+ "version": "0.6.93",
4
4
  "description": "Agent CLI for Nodii Dev, reached through the platform edge",
5
5
  "type": "module",
6
6
  "bin": {