@nodii/dev 0.6.155 → 0.6.157
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 +1 -1
- package/dist/surface.js +52 -12
- package/package.json +1 -1
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.
|
|
7
|
+
export const VERSION = "0.6.157";
|
|
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
|
@@ -32,7 +32,7 @@ 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 =
|
|
35
|
+
export const GENERATOR_FORMAT = 23;
|
|
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). */
|
|
@@ -263,20 +263,20 @@ export async function lastPublishedVersion(figmaGet, fileKey, { library } = {})
|
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
/**
|
|
266
|
-
* Read one Surface set at a file version and trim it to what the generator reads.
|
|
266
|
+
* Read one Surface component or set at a file version and trim it to what the generator reads.
|
|
267
267
|
* `node` locates a set new to its file, not yet in its published listing (cli-144):
|
|
268
|
-
* the read is refused unless that
|
|
268
|
+
* the read is refused unless that component or set has the catalog row's key, which stays
|
|
269
269
|
* the reference (MW8-20); the node id is not kept.
|
|
270
270
|
*/
|
|
271
271
|
export async function fetchSurfaceTree(figmaGet, row, { index, version, node }) {
|
|
272
272
|
const nodeId = node ?? index.get(row.componentSetKey);
|
|
273
|
-
if (!nodeId) throw new CliError("SURFACE_NOT_PUBLISHED", `${row.componentSetName ?? row.id}: component set ${row.componentSetKey} is not among ${row.fileKey}'s published component sets`, 1);
|
|
273
|
+
if (!nodeId) throw new CliError("SURFACE_NOT_PUBLISHED", `${row.componentSetName ?? row.id}: component set ${row.componentSetKey} is not among ${row.fileKey}'s published components or component sets`, 1);
|
|
274
274
|
const body = await figmaGet(`/files/${encodeURIComponent(row.fileKey)}/nodes?ids=${encodeURIComponent(nodeId)}${version ? `&version=${encodeURIComponent(version)}` : ""}`);
|
|
275
275
|
const entry = body.nodes?.[nodeId];
|
|
276
276
|
if (!entry?.document) throw new CliError("FIGMA_NOT_FOUND", `Figma returned no document for ${row.componentSetName ?? row.id}`, 1);
|
|
277
|
-
const found = node ? (entry.document.type === "COMPONENT_SET" ? (entry.componentSets?.[nodeId]?.key ?? null) : null) : row.componentSetKey;
|
|
277
|
+
const found = node ? (entry.document.type === "COMPONENT_SET" ? (entry.componentSets?.[nodeId]?.key ?? null) : entry.document.type === "COMPONENT" ? (entry.components?.[nodeId]?.key ?? null) : null) : row.componentSetKey;
|
|
278
278
|
if (found !== row.componentSetKey)
|
|
279
|
-
throw new CliError("SURFACE_NODE_KEY_MISMATCH", `${row.componentSetName ?? row.id}: node ${nodeId} at version ${version} is ${found ? `component set ${found}` : "not a component set"}, not the catalog's ${row.componentSetKey}; --node only locates the catalog row's own set (cli-144, MW8-20)`, 1);
|
|
279
|
+
throw new CliError("SURFACE_NODE_KEY_MISMATCH", `${row.componentSetName ?? row.id}: node ${nodeId} at version ${version} is ${found ? `component set ${found}` : "not a published component or component set"}, not the catalog's ${row.componentSetKey}; --node only locates the catalog row's own set (cli-144, MW8-20)`, 1);
|
|
280
280
|
return trimTree(entry, { row, version: version ?? body.version ?? null });
|
|
281
281
|
}
|
|
282
282
|
|
|
@@ -2222,6 +2222,22 @@ function emitNode(node, ctx) {
|
|
|
2222
2222
|
const sizing = ctx.bare ? [] : sizeClasses(node, parent, false);
|
|
2223
2223
|
// A data slot passed straight to a prop is that prop (`trailing={<>{trailing}</>}` → `trailing={trailing}`).
|
|
2224
2224
|
let own = rendered.code.trim().replace(/=\{<>\{([a-z][A-Za-z0-9]*)\}<\/>\}/g, "={$1}");
|
|
2225
|
+
// The toolbar builds rows itself, so its template never renders the table slot.
|
|
2226
|
+
// Preserve the published error component drawn there as its errorState contract.
|
|
2227
|
+
if (node.instance.set === "Data Table Toolbar" && /^<DataTableToolbarBlock\b/.test(own) && !/\berrorState=/.test(own)) {
|
|
2228
|
+
const tableSlot = (node.children ?? []).find(c => c.type === "SLOT" && c.slot === "table" && c.visible !== false);
|
|
2229
|
+
const errors = [];
|
|
2230
|
+
const collect = (current) => {
|
|
2231
|
+
if (current.visible === false) return;
|
|
2232
|
+
if (current.instance?.remote && current.instance.set === "Error State Page") errors.push(current);
|
|
2233
|
+
else for (const child of current.children ?? []) collect(child);
|
|
2234
|
+
};
|
|
2235
|
+
if (tableSlot) collect(tableSlot);
|
|
2236
|
+
if (errors.length === 1) {
|
|
2237
|
+
const errorCode = emitNode(errors[0], { ...ctx, depth: 0, parent: tableSlot, grand: node, path: `${path} › table`, root: false, inTable: false, inSlot: true, chain: [...chain, tableSlot] });
|
|
2238
|
+
if (errorCode) own = own.replace(/^<DataTableToolbarBlock\b/, `<DataTableToolbarBlock errorState={${errorCode}}`);
|
|
2239
|
+
} else if (errors.length > 1) note(`${path} › table`, "slot", "multiple Error State Page instances in one toolbar table slot: choose one error state");
|
|
2240
|
+
}
|
|
2225
2241
|
// A tab strip the page controls (tabOf reads the template's own strip first, to gather a run).
|
|
2226
2242
|
if (!ctx.tabProbe) own = own.replace(/<Tabs panelless(?: defaultValue="[^"]*")?>/g, CONTROLLED_TABS("tab", "onTabChange"));
|
|
2227
2243
|
// An Alert that shows its actions with nothing in the slot draws no AlertAction, never an
|
|
@@ -2589,7 +2605,7 @@ function emptyPiiCell(part) {
|
|
|
2589
2605
|
const literal = /^\{("(?:[^"\\]|\\.)*")\}$/.exec(inner);
|
|
2590
2606
|
if (!literal) return null;
|
|
2591
2607
|
const value = JSON.parse(literal[1]);
|
|
2592
|
-
return /^(?:\s*|\s*[-–—]\s*|\s*(?:unassigned|none|system)\s*)$/i.test(value) ? literal[1] : null;
|
|
2608
|
+
return /^(?:\s*|\s*[-–—]\s*|\s*(?:unassigned|none|no one|no reviewer|not needed|not found|system)\s*)$/i.test(value) ? literal[1] : null;
|
|
2593
2609
|
}
|
|
2594
2610
|
|
|
2595
2611
|
/**
|
|
@@ -2928,10 +2944,16 @@ function tableOf(node, ctx) {
|
|
|
2928
2944
|
// the report names it.
|
|
2929
2945
|
const invalidPii = new Map();
|
|
2930
2946
|
const nullablePii = new Map();
|
|
2947
|
+
const personSamples = new Map();
|
|
2931
2948
|
const piiColumn = keys.map((key, i) => {
|
|
2932
2949
|
const people = dataRows.filter((p) => piiCellAttrs(p.cells[i]) !== null);
|
|
2933
|
-
|
|
2934
|
-
|
|
2950
|
+
// "You" in a name column is the viewer's person, not an empty value.
|
|
2951
|
+
// Keep relation supplied by the data binding: self must remain revealed.
|
|
2952
|
+
const selfCells = people.length && people.every(p => piiTreeKind(p.cells[i].cell) === "name")
|
|
2953
|
+
? dataRows.filter(p => /^<TableCell\b[^>]*>\s*\{"You"\}\s*<\/TableCell>$/.test(p.cells[i].code ?? "")) : [];
|
|
2954
|
+
const drawn = people.length + selfCells.length;
|
|
2955
|
+
if (selfCells.length) personSamples.set(i, people[0].cells[i]);
|
|
2956
|
+
const others = dataRows.filter((p) => piiCellAttrs(p.cells[i]) === null && !selfCells.includes(p));
|
|
2935
2957
|
const empties = others.map(p => emptyPiiCell(p.cells[i]));
|
|
2936
2958
|
const nullable = drawn > 0 && others.length > 0 && empties.every(value => value !== null) && new Set(empties).size === 1;
|
|
2937
2959
|
if (nullable) nullablePii.set(i, { sample: people[0].cells[i], empty: empties[0] });
|
|
@@ -2949,6 +2971,7 @@ function tableOf(node, ctx) {
|
|
|
2949
2971
|
}
|
|
2950
2972
|
return drawn === dataRows.length || nullable;
|
|
2951
2973
|
});
|
|
2974
|
+
const secondaryKeys = new Set(keys);
|
|
2952
2975
|
const cells = first.cells.map((c, i) => {
|
|
2953
2976
|
const w = columnWidth(c.cell);
|
|
2954
2977
|
let open = `<TableCell${wrapperAttrs(w, first.row)}>`;
|
|
@@ -2960,11 +2983,21 @@ function tableOf(node, ctx) {
|
|
|
2960
2983
|
open = own.slice(0, end + 1).replace(/\s*\/>$/, ">");
|
|
2961
2984
|
close = `</${tag}>`;
|
|
2962
2985
|
}
|
|
2986
|
+
// Two-line templates own the presentation; both lines belong to each row.
|
|
2987
|
+
// Reserve every header key before naming secondary fields, so a column
|
|
2988
|
+
// called "Environment secondary" cannot alias Environment's second line.
|
|
2989
|
+
if (/^<TableCell\b/.test(open) && /\bsecondary=/.test(open)) {
|
|
2990
|
+
const base = `${keys[i]}Secondary`;
|
|
2991
|
+
let secondary = base;
|
|
2992
|
+
for (let n = 2; secondaryKeys.has(secondary); n++) secondary = `${base}${n}`;
|
|
2993
|
+
secondaryKeys.add(secondary);
|
|
2994
|
+
open = open.replace(new RegExp(`\\bsecondary=(${LITERAL})`), `secondary={row.${secondary}}`);
|
|
2995
|
+
}
|
|
2963
2996
|
if (invalidPii.has(i)) return indent(`${open}${comment(`unmapped: ${invalidPii.get(i)}`)}${close}`, depth + 4);
|
|
2964
2997
|
if (piiColumn[i]) {
|
|
2965
2998
|
const nullable = nullablePii.get(i);
|
|
2966
2999
|
const ref = `row.${keys[i]}`;
|
|
2967
|
-
const content = nullable ? `{${ref} == null ? (${nullable.empty}) : (${piiCellText(nullable.sample, ref)})}` : piiCellText(c, ref);
|
|
3000
|
+
const content = nullable ? `{${ref} == null ? (${nullable.empty}) : (${piiCellText(nullable.sample, ref)})}` : piiCellText(personSamples.get(i) ?? c, ref);
|
|
2968
3001
|
return indent(`${open}\n ${content}\n${close}`, depth + 4);
|
|
2969
3002
|
}
|
|
2970
3003
|
return indent(`${open}{row.${keys[i]}}${close}`, depth + 4);
|
|
@@ -3165,11 +3198,13 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
3165
3198
|
// --figma-version names a version outright; otherwise each file is read at its last library publish.
|
|
3166
3199
|
// The library read that finds the publish also gives the set index, so it is one read per file.
|
|
3167
3200
|
const versions = new Map();
|
|
3201
|
+
const componentIndexes = new Set();
|
|
3168
3202
|
const versionFor = async (fileKey) => {
|
|
3169
3203
|
if (figmaVersion) return figmaVersion;
|
|
3170
3204
|
if (!versions.has(fileKey)) {
|
|
3171
3205
|
const library = await fetchLibrary(figmaGet, fileKey);
|
|
3172
|
-
indexes.set(fileKey, new Map(library.component_sets.map((x) => [x.key, x.node_id])));
|
|
3206
|
+
indexes.set(fileKey, new Map([...library.components, ...library.component_sets].map((x) => [x.key, x.node_id])));
|
|
3207
|
+
componentIndexes.add(fileKey);
|
|
3173
3208
|
const pin = await lastPublishedVersion(figmaGet, fileKey, { library });
|
|
3174
3209
|
log(`${fileKey}: last library publish ${pin.publishedAt} closed version ${pin.version} at ${pin.closedAt}${pin.label ? ` ("${pin.label}")` : " (unlabelled)"}`);
|
|
3175
3210
|
versions.set(fileKey, pin.version);
|
|
@@ -3195,10 +3230,15 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
3195
3230
|
}
|
|
3196
3231
|
}
|
|
3197
3232
|
if (!node && !indexes.has(row.fileKey)) indexes.set(row.fileKey, await setIndex(figmaGet, row.fileKey));
|
|
3233
|
+
if (!node && !indexes.get(row.fileKey).has(row.componentSetKey) && !componentIndexes.has(row.fileKey)) {
|
|
3234
|
+
const published = await figmaGet(`/files/${encodeURIComponent(row.fileKey)}/components`);
|
|
3235
|
+
for (const component of published.meta?.components ?? []) indexes.get(row.fileKey).set(component.key, component.node_id);
|
|
3236
|
+
componentIndexes.add(row.fileKey);
|
|
3237
|
+
}
|
|
3198
3238
|
// --all covers a module: one unpublished Surface is reported, and the rest still generate.
|
|
3199
3239
|
// A Surface named on its own stays a refusal, because the run has nothing else to do.
|
|
3200
3240
|
if (f.all && !indexes.get(row.fileKey).has(row.componentSetKey)) {
|
|
3201
|
-
log(`skipping ${row.componentSetName ?? row.id}: not among ${row.fileKey}'s published component sets`);
|
|
3241
|
+
log(`skipping ${row.componentSetName ?? row.id}: not among ${row.fileKey}'s published components or component sets`);
|
|
3202
3242
|
unpublished.push(row);
|
|
3203
3243
|
continue;
|
|
3204
3244
|
}
|