@nodii/dev 0.6.193 → 0.6.195
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 +32 -0
- package/dist/core.js +1 -1
- package/dist/surface.js +213 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1315,6 +1315,38 @@ product-page catalog names the Surface by its published component-set key
|
|
|
1315
1315
|
That map is keyed by variant node id, so `--fetch` joins it while it reads
|
|
1316
1316
|
and the tree keeps only each variant's state name; no node id is committed
|
|
1317
1317
|
(MW8-20). A tree that still holds one is refused with `SURFACE_TREE_STALE`.
|
|
1318
|
+
- **Loading flows down (NODII-DEV-CLI-260, MW6-29).** Every Surface takes an
|
|
1319
|
+
optional `loading?: boolean`, and every view passes it to each DS part that
|
|
1320
|
+
draws its own skeleton, whether or not its template draws the prop: `status`
|
|
1321
|
+
on a part on the DS async contract (`DataTable`, `Timeline`, `MetricCard`,
|
|
1322
|
+
`Chart`, `ActivityFeedBlock`, `CommentThreadBlock`, `TenantPickerCardBlock`),
|
|
1323
|
+
else its own `loading` (`PageMetricsBarBlock`, `QrDisplay`) or `isLoading`
|
|
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.
|
|
1328
|
+
- **Error and Empty views a route drives (NODII-DEV-CLI-260).** The Surface takes
|
|
1329
|
+
`<Id>SurfaceInput`: a `state` with the full props, as before, or a literal
|
|
1330
|
+
`state` with only the props its view reads (`{ state: "read-error" } &
|
|
1331
|
+
Partial<Props> & Pick<Props, "error" | "onRetry">`). So a route whose read
|
|
1332
|
+
failed renders `<XSurface state="read-error" error={e} onRetry={retry} />`
|
|
1333
|
+
without the other views' data. Each view takes `Pick<Props, …>` of what it reads.
|
|
1334
|
+
- **The route's wrapper (NODII-DEV-CLI-260).** Where the catalog's `sourcePath`
|
|
1335
|
+
names no page yet, `--write` also writes it: a thin `export function <Id>(props:
|
|
1336
|
+
<Id>SurfaceInput) { return <<Id>Surface {...props} />; }` that re-exports the
|
|
1337
|
+
Surface's types and states, with no Legacy branch. A page that exists is the
|
|
1338
|
+
route's own and is never rewritten; `--check` doesn't compare it. `--json`
|
|
1339
|
+
names a written wrapper in `data.surfaces[].wrapper` (else `null`).
|
|
1340
|
+
- **`data-surface` (NODII-DEV-CLI-260).** Every view's root element carries
|
|
1341
|
+
`data-surface="<catalog id>"`, so a route test asserts `[data-surface]` in any
|
|
1342
|
+
state.
|
|
1343
|
+
- **Loading variants are warned about (NODII-DEV-CLI-260, MW6-29).** A Surface
|
|
1344
|
+
draws no Loading variant: its DS parts draw their own skeleton from `loading`.
|
|
1345
|
+
A Surface whose set still has one (a state named `loading`, `initial-loading`,
|
|
1346
|
+
`loading-…`) is still generated, and `generate` prints one `MW6-29:` line with
|
|
1347
|
+
the count and the Surfaces hit. `--json` lists them in
|
|
1348
|
+
`data.surfaces[].loadingVariants`. The exit code is unchanged for now; it is
|
|
1349
|
+
refused later.
|
|
1318
1350
|
- **`--check`** writes nothing and exits 1 when a generated file differs from
|
|
1319
1351
|
the generator's output. The design system's `surface-gen-equal` CI gate runs
|
|
1320
1352
|
`surface generate --all --check` with a pinned `@nodii/dev`; `--all`
|
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.
|
|
7
|
+
export const VERSION = "0.6.195";
|
|
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 =
|
|
37
|
+
export const GENERATOR_FORMAT = 48;
|
|
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
|
|
@@ -614,6 +614,21 @@ export const textUtility = (styleName, textStyles) => (styleName ? (textStyles.g
|
|
|
614
614
|
* Emit one Surface's generated file. Returns { code, unmapped, states }:
|
|
615
615
|
* `unmapped` lists every layer that has no Code Connect mapping (U08-14).
|
|
616
616
|
*/
|
|
617
|
+
/** A state drawn as the whole Surface loading (`loading`, `initial-loading`, `loading-pages-1-2`). */
|
|
618
|
+
const isLoadingState = (state) => /(^|-)loading(-|$)/.test(state);
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* MW6-29: a Surface draws no Loading variant. Its DS parts draw their own skeleton
|
|
622
|
+
* from `loading`, which the route passes (NODII-DEV-CLI-260). A Surface whose set
|
|
623
|
+
* still has one is warned about now, with a count, and refused later, so
|
|
624
|
+
* `generate` doesn't fail on release day. Null when none is hit.
|
|
625
|
+
*/
|
|
626
|
+
export function loadingVariantWarning(results) {
|
|
627
|
+
const hit = results.filter((r) => r.loadingVariants?.length);
|
|
628
|
+
if (!hit.length) return null;
|
|
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
|
+
}
|
|
631
|
+
|
|
617
632
|
export function emitSurface(tree, row, ds) {
|
|
618
633
|
const imports = [];
|
|
619
634
|
const unmapped = [];
|
|
@@ -641,11 +656,15 @@ export function emitSurface(tree, row, ds) {
|
|
|
641
656
|
if (emitted.trimStart().startsWith("{/*")) {
|
|
642
657
|
throw new CliError("SURFACE_VIEW_NOT_LAID_OUT", `${row.id}: view ${JSON.stringify(variant.name)} has no auto layout, so it would generate as an empty page; give the variant (or the App Frame's mainContent) auto layout in Figma, publish, and refetch`, 1);
|
|
643
658
|
}
|
|
644
|
-
|
|
659
|
+
// The view's root names its Surface, so a route test finds it in any state (NODII-DEV-CLI-260).
|
|
660
|
+
const body = passLoading(emitted).replace(/^(\s*)<div\b/, `$1<div data-surface=${JSON.stringify(row.id)}`);
|
|
661
|
+
return { state, fn, body, variant: variant.name };
|
|
645
662
|
});
|
|
646
663
|
const component = `${pascal(row.id)}Surface`;
|
|
647
664
|
const stateType = `${component}State`;
|
|
648
665
|
const propsType = `${component}Props`;
|
|
666
|
+
const inputType = `${component}Input`;
|
|
667
|
+
const viewProps = (v) => `Pick<${propsType}, ${[...v.uses].sort().map((name) => JSON.stringify(name)).join(" | ")}>`;
|
|
649
668
|
const named = resolveScopes(views, scopes, layers);
|
|
650
669
|
settlePiiColumns(views, unmapped);
|
|
651
670
|
const data = dataProps(views, propsType);
|
|
@@ -682,16 +701,52 @@ export function emitSurface(tree, row, ds) {
|
|
|
682
701
|
"",
|
|
683
702
|
]
|
|
684
703
|
: []),
|
|
704
|
+
// Each state takes the props its own view reads, so a route draws the Error or Empty view
|
|
705
|
+
// from what it has; the full props stay accepted for every state (NODII-DEV-CLI-260).
|
|
706
|
+
"/** What the Surface takes: a state and the props its view reads, or the full props for any state. */",
|
|
707
|
+
`export type ${inputType} =`,
|
|
708
|
+
` | ({ state: ${stateType} } & ${propsType})`,
|
|
709
|
+
...views.map((v, i) => ` | ({ state: ${JSON.stringify(v.state)} } & Partial<${propsType}>${v.uses.size ? ` & ${viewProps(v)}` : ""})${i === views.length - 1 ? ";" : ""}`),
|
|
710
|
+
"",
|
|
685
711
|
`/** ${row.title}: the Surface's ${views.length} variant${views.length === 1 ? "" : "s"}, drawn as Figma composes them. */`,
|
|
686
|
-
|
|
687
|
-
" switch (state) {",
|
|
688
|
-
...views.flatMap((v) => [` case ${JSON.stringify(v.state)}:`, ` return <${v.fn}${v.uses.size ? " {...
|
|
712
|
+
`export function ${component}(props: ${inputType}) {`,
|
|
713
|
+
" switch (props.state) {",
|
|
714
|
+
...views.flatMap((v) => [` case ${JSON.stringify(v.state)}:`, ` return <${v.fn}${v.uses.size ? " {...props}" : ""} />;`]),
|
|
689
715
|
" }",
|
|
690
716
|
"}",
|
|
691
|
-
...views.flatMap((v) => ["", v.uses.size ? `function ${v.fn}({ ${[...v.uses].sort().join(", ")} }: ${
|
|
717
|
+
...views.flatMap((v) => ["", v.uses.size ? `function ${v.fn}({ ${[...v.uses].sort().join(", ")} }: ${viewProps(v)}) {` : `function ${v.fn}() {`, " return (", v.body, " );", "}"]),
|
|
692
718
|
"",
|
|
693
719
|
];
|
|
694
|
-
return {
|
|
720
|
+
return {
|
|
721
|
+
code: lines.join("\n"),
|
|
722
|
+
unmapped,
|
|
723
|
+
states: views.map((v) => v.state),
|
|
724
|
+
loadingVariants: views.map((v) => v.state).filter(isLoadingState),
|
|
725
|
+
wrapper: row.sourcePath ? wrapperCode(row, { component, inputType }) : null,
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* The route's wrapper over the generated Surface: a thin `return <XSurface {...props} />`
|
|
731
|
+
* (NODII-DEV-CLI-260). `--write` writes it at the catalog's sourcePath only when no page
|
|
732
|
+
* is there yet, and never rewrites one: a page that exists is the route's own.
|
|
733
|
+
*/
|
|
734
|
+
export function wrapperCode(row, { component, inputType }) {
|
|
735
|
+
const module = `./${basename(row.sourcePath).replace(/\.tsx$/, "")}${GENERATED_SUFFIX.replace(/\.tsx$/, "")}`;
|
|
736
|
+
const states = `${pascal(row.id).replace(/^./, (c) => c.toLowerCase())}SurfaceStates`;
|
|
737
|
+
return [
|
|
738
|
+
"// The route's wrapper over its generated Surface, written once by `nodii-dev surface generate --write`",
|
|
739
|
+
"// because no product page was here (NODII-DEV-CLI-260). The generator never rewrites it.",
|
|
740
|
+
`import { ${component}, type ${inputType} } from "${module}";`,
|
|
741
|
+
"",
|
|
742
|
+
`export { ${states}, type ${inputType}, type ${component}Props, type ${component}State } from "${module}";`,
|
|
743
|
+
"",
|
|
744
|
+
`/** ${row.title}: the generated Surface; the route passes its state, its data and \`loading\`. */`,
|
|
745
|
+
`export function ${pascal(row.id)}(props: ${inputType}) {`,
|
|
746
|
+
` return <${component} {...props} />;`,
|
|
747
|
+
"}",
|
|
748
|
+
"",
|
|
749
|
+
].join("\n");
|
|
695
750
|
}
|
|
696
751
|
|
|
697
752
|
/**
|
|
@@ -734,8 +789,12 @@ const JS_LITERALS = new Set(["true", "false", "null", "undefined", "this"]);
|
|
|
734
789
|
/** Strings blanked to spaces of the same length, so a position still points into `code`. */
|
|
735
790
|
const maskStrings = (code) => code.replace(/"(?:[^"\\\n]|\\.)*"|`[^`]*`/g, (s) => `"${" ".repeat(s.length - 2)}"`);
|
|
736
791
|
|
|
737
|
-
/**
|
|
738
|
-
|
|
792
|
+
/**
|
|
793
|
+
* A list the generator lifts opens `{rows.map((row) => (`, or, in a Table that
|
|
794
|
+
* draws its skeleton rows while the Surface loads, `{loading ? <TableSkeletonRows … /> : rows.map((row) => (`:
|
|
795
|
+
* [{ at, list, param }] in order.
|
|
796
|
+
*/
|
|
797
|
+
const LIST_OPEN = /\{(?:loading \? <TableSkeletonRows\b[^\n]*? \/> : )?([A-Za-z_][A-Za-z0-9_]*)\.map\(\(([a-z][A-Za-z0-9]*)\) => \(/g;
|
|
739
798
|
const listOpeners = (code) => [...code.matchAll(LIST_OPEN)].map((m) => ({ at: m.index, list: m[1], param: m[2] }));
|
|
740
799
|
/** The list whose item `param` names at position `at`: the nearest opener before it that binds it. */
|
|
741
800
|
const listAt = (openers, at, param) => openers.filter((o) => o.at < at && o.param === param).at(-1)?.list ?? null;
|
|
@@ -2021,6 +2080,11 @@ function dataProps(views, propsType) {
|
|
|
2021
2080
|
for (const view of views) {
|
|
2022
2081
|
view.uses = new Set();
|
|
2023
2082
|
const body = view.body;
|
|
2083
|
+
// The Surface's one loading flag, which its skeleton parts read (passLoading; NODII-DEV-CLI-260).
|
|
2084
|
+
if (LOADING_READ.test(maskStrings(body))) {
|
|
2085
|
+
own("loading", "boolean");
|
|
2086
|
+
view.uses.add("loading");
|
|
2087
|
+
}
|
|
2024
2088
|
// A lifted list (`{rows.map((row) => (`): its item's reads are the list's members.
|
|
2025
2089
|
const openers = listOpeners(body);
|
|
2026
2090
|
for (const o of openers) {
|
|
@@ -2136,6 +2200,8 @@ function dataProps(views, propsType) {
|
|
|
2136
2200
|
view.uses.add(m[2]);
|
|
2137
2201
|
}
|
|
2138
2202
|
}
|
|
2203
|
+
// Every Surface takes loading, so a route passes it alike to each (NODII-DEV-CLI-260).
|
|
2204
|
+
if (!data.has("loading")) own("loading", "boolean");
|
|
2139
2205
|
for (const d of data.values()) if (d.tabValues) Object.assign(d, { optional: true, raw: `readonly (${union(d.tabValues)})[]` });
|
|
2140
2206
|
for (const d of data.values()) {
|
|
2141
2207
|
if (!d.sortKeys) continue;
|
|
@@ -2205,6 +2271,56 @@ function drawnRef({ tag, attr, keys, literals, raw }) {
|
|
|
2205
2271
|
return `Drawn<${props}, ${keys.size ? [...keys].sort().map((k) => JSON.stringify(k)).join(" | ") : "never"}${lit}>[${JSON.stringify(attr)}]`;
|
|
2206
2272
|
}
|
|
2207
2273
|
|
|
2274
|
+
/**
|
|
2275
|
+
* The DS parts that draw their own loading skeleton, and the prop each takes it
|
|
2276
|
+
* through (MW6-29; NODII-DEV-CLI-260): a part on the DS async contract
|
|
2277
|
+
* (DS-ASYNC-STATES-1, `status`), else its own `loading` or `isLoading`. The
|
|
2278
|
+
* Surface's one `loading` prop reaches each of them in every view, whether or
|
|
2279
|
+
* not its template draws the prop, so a route never hand-builds a loading page.
|
|
2280
|
+
* A part whose loading is a busy control (Button) or a picker's option list
|
|
2281
|
+
* (Combobox, PeopleSelector) is not here: its loading is not the page's. A lifted
|
|
2282
|
+
* Table body takes the Table's own TableSkeletonRows (tableOf).
|
|
2283
|
+
*/
|
|
2284
|
+
const LOADING_PARTS = new Map([
|
|
2285
|
+
["DataTable", "status"],
|
|
2286
|
+
["Timeline", "status"],
|
|
2287
|
+
["MetricCard", "status"],
|
|
2288
|
+
["Chart", "status"],
|
|
2289
|
+
["ActivityFeedBlock", "status"],
|
|
2290
|
+
["CommentThreadBlock", "status"],
|
|
2291
|
+
["TenantPickerCardBlock", "status"],
|
|
2292
|
+
["PageMetricsBarBlock", "loading"],
|
|
2293
|
+
["QrDisplay", "loading"],
|
|
2294
|
+
["DataTableToolbarBlock", "isLoading"],
|
|
2295
|
+
["ChartWithRange", "isLoading"],
|
|
2296
|
+
]);
|
|
2297
|
+
const LOADING_ATTR = { status: 'status={loading ? "loading" : undefined}', loading: "loading={loading}", isLoading: "isLoading={loading}" };
|
|
2298
|
+
/** A read of the Surface's loading prop in a view's code (strings masked): never an attribute's name. */
|
|
2299
|
+
const LOADING_READ = /(?<![\w.$-])loading(?![\w$=-])/;
|
|
2300
|
+
|
|
2301
|
+
/**
|
|
2302
|
+
* Pass the Surface's `loading` to every LOADING_PARTS tag in a view's code, as
|
|
2303
|
+
* that tag's first attribute. A tag that already draws the prop (a Loading
|
|
2304
|
+
* variant's literal `isLoading`) keeps what it draws, and one whose attributes
|
|
2305
|
+
* can't be read (a spread) is left as the template gives it.
|
|
2306
|
+
*/
|
|
2307
|
+
function passLoading(code) {
|
|
2308
|
+
const masked = maskStrings(code);
|
|
2309
|
+
let out = "";
|
|
2310
|
+
let last = 0;
|
|
2311
|
+
for (const m of masked.matchAll(/<([A-Z][\w.]*)(?=[\s/>])/g)) {
|
|
2312
|
+
const prop = LOADING_PARTS.get(m[1]);
|
|
2313
|
+
if (!prop) continue;
|
|
2314
|
+
const at = m.index + m[0].length;
|
|
2315
|
+
const attrs = tagAttributes(code, at);
|
|
2316
|
+
if (!attrs || attrs.names.includes(prop)) continue;
|
|
2317
|
+
const line = /^\n([ \t]*)/.exec(code.slice(at));
|
|
2318
|
+
out += code.slice(last, at) + (line ? `\n${line[1]}${LOADING_ATTR[prop]}` : ` ${LOADING_ATTR[prop]}`);
|
|
2319
|
+
last = at;
|
|
2320
|
+
}
|
|
2321
|
+
return out + code.slice(last);
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2208
2324
|
/** The type the generated file declares for drawnProps (see there). */
|
|
2209
2325
|
const DRAWN_TYPE = [
|
|
2210
2326
|
"/** A DS component's props, narrowed to the member of their union this call draws: every required prop passed, every literal one fitting. */",
|
|
@@ -2706,6 +2822,7 @@ function emitChildren(children, emitOne, ctx) {
|
|
|
2706
2822
|
let runKind = null;
|
|
2707
2823
|
const flush = () => {
|
|
2708
2824
|
if (run.length >= 2 && runKind === "tab") out.push(tabStrip(run, ctx));
|
|
2825
|
+
else if (run.length >= 2 && runKind === "step") out.push(...stepRun(run, emitOne, ctx));
|
|
2709
2826
|
else if (run.length >= 2) out.push(descriptionRun(run, ctx));
|
|
2710
2827
|
else out.push(...run.map(emitOne).filter((x) => x !== null));
|
|
2711
2828
|
run = [];
|
|
@@ -2715,7 +2832,7 @@ function emitChildren(children, emitOne, ctx) {
|
|
|
2715
2832
|
if (c.visible === false) continue;
|
|
2716
2833
|
// Description lists side by side are columns of the layout, each its own list; only a run
|
|
2717
2834
|
// down a column is one list of items (hub-454).
|
|
2718
|
-
const kind = tabOf(c, ctx) ? "tab" : !across && descriptionOf(c, ctx) ? `dl${descriptionOf(c, ctx).open}` : null;
|
|
2835
|
+
const kind = tabOf(c, ctx) ? "tab" : stepOf(c, ctx) ? "step" : !across && descriptionOf(c, ctx) ? `dl${descriptionOf(c, ctx).open}` : null;
|
|
2719
2836
|
if (kind && kind !== runKind) flush();
|
|
2720
2837
|
if (kind) {
|
|
2721
2838
|
run.push(c);
|
|
@@ -2730,6 +2847,57 @@ function emitChildren(children, emitOne, ctx) {
|
|
|
2730
2847
|
return pairLabelledControls(out);
|
|
2731
2848
|
}
|
|
2732
2849
|
|
|
2850
|
+
/** The one-step Stepper the Stepper template emits for one Figma Step. */
|
|
2851
|
+
const ONE_STEP_PROBE = /^<Stepper\n\s*steps=\{\[\{ id: "step-1"[\s\S]*\}\]\}(?:\n\s*[A-Za-z]+=(?:"[^"\n]*"|\{[^{}\n]*\}))*\n\/>$/;
|
|
2852
|
+
|
|
2853
|
+
/** A DS instance whose template emits one step of a Stepper. */
|
|
2854
|
+
function stepOf(node, ctx) {
|
|
2855
|
+
if (!node.instance?.remote || node.visible === false) return false;
|
|
2856
|
+
const code = emitNode(node, { ...ctx, depth: 0, parent: null, bare: true, inTable: false, tabProbe: true, scopes: null, imports: [], note: () => {} });
|
|
2857
|
+
return ONE_STEP_PROBE.test(code?.trim() ?? "");
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
/** One emitted step: its `{ id, title, status, … }` (dedented to its own column) and the Stepper's own attributes. */
|
|
2861
|
+
const ONE_STEP = /^( *)<Stepper\n *steps=\{\[(\{[\s\S]*\})\]\}((?:\n *[A-Za-z]+=(?:"[^"\n]*"|\{[^{}\n]*\}))*)\n *\/>$/m;
|
|
2862
|
+
function emittedStep(code) {
|
|
2863
|
+
if ((code?.match(/<Stepper\b/g) ?? []).length !== 1) return null;
|
|
2864
|
+
const m = ONE_STEP.exec(code);
|
|
2865
|
+
if (!m) return null;
|
|
2866
|
+
// Only a sizing wrapper may hold it: anything else beside the step stays as drawn.
|
|
2867
|
+
const rest = code.replace(m[0], "").replace(/^\s*<div className="[^"]*">\s*<\/div>\s*$/, "");
|
|
2868
|
+
if (rest.trim()) return null;
|
|
2869
|
+
const pad = m[1].length + 2;
|
|
2870
|
+
const lead = (line) => line.length - line.trimStart().length;
|
|
2871
|
+
const step = m[2].split("\n").map((line, i) => (i === 0 ? line : line.slice(Math.min(pad, lead(line))))).join("\n");
|
|
2872
|
+
const attrs = m[3].split("\n").map((a) => a.trim()).filter(Boolean);
|
|
2873
|
+
return { step, attrs };
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
/**
|
|
2877
|
+
* A run of sibling Steps is one rail. The Stepper template draws one Figma Step as a
|
|
2878
|
+
* one-step Stepper, and Stepper numbers a step by its place in its own `steps`, so a rail
|
|
2879
|
+
* of n Steps drew n Steppers all numbered 1 (HR New expense: 1 · 1 · 1 · 1). Figma
|
|
2880
|
+
* composes one Stepper with n steps, so the run is one Stepper over every step, each
|
|
2881
|
+
* numbered by its place (`step-1` … `step-n`) with its status still the page's
|
|
2882
|
+
* (DESIGN-SYSTEM-903). Stepper draws no connector after its last step, so the last
|
|
2883
|
+
* step's `showConnector={false}` is dropped; Steps drawn differently (a compact one, a
|
|
2884
|
+
* rail without connectors beside one with) are not one rail and stay as drawn.
|
|
2885
|
+
*/
|
|
2886
|
+
function stepRun(run, emitOne, ctx) {
|
|
2887
|
+
const codes = run.map(emitOne).filter((x) => x !== null);
|
|
2888
|
+
const steps = codes.map(emittedStep);
|
|
2889
|
+
if (steps.length !== run.length || steps.some((s) => s === null)) return codes;
|
|
2890
|
+
const NO_CONNECTOR = "showConnector={false}";
|
|
2891
|
+
const own = (s) => s.attrs.filter((a) => a !== NO_CONNECTOR).join("\n");
|
|
2892
|
+
if (steps.some((s) => own(s) !== own(steps[0]))) return codes;
|
|
2893
|
+
const connectorless = steps.slice(0, -1).every((s) => s.attrs.includes(NO_CONNECTOR));
|
|
2894
|
+
if (!connectorless && steps.slice(0, -1).some((s) => s.attrs.includes(NO_CONNECTOR))) return codes;
|
|
2895
|
+
const attrs = [...steps[0].attrs.filter((a) => a !== NO_CONNECTOR), ...(connectorless ? [NO_CONNECTOR] : [])];
|
|
2896
|
+
ctx.note(ctx.path, ASSEMBLED, `${run.length} sibling Steps gathered into one DS Stepper (DESIGN-SYSTEM-903)`);
|
|
2897
|
+
const items = steps.map((s, i) => ` ${s.step.replace(/^\{ id: "step-\d+"/, `{ id: "step-${i + 1}"`).split("\n").join("\n ")},`);
|
|
2898
|
+
return [indent(["<Stepper", " steps={[", ...items, " ]}", ...attrs.map((a) => ` ${a}`), "/>"].join("\n"), ctx.depth)];
|
|
2899
|
+
}
|
|
2900
|
+
|
|
2733
2901
|
const LABEL_FOR = /<Label\b[^>]*?\bhtmlFor=\{([A-Za-z_$][\w$]*)\}/;
|
|
2734
2902
|
const LABELLED_CONTROL = /<(?:Checkbox|Switch|RadioGroupItem|Textarea|Input|SelectField)(?=[\s/>])/;
|
|
2735
2903
|
/**
|
|
@@ -3200,13 +3368,15 @@ function treeTableOf(node, ctx) {
|
|
|
3200
3368
|
};
|
|
3201
3369
|
const branch = emit(branches[0]);
|
|
3202
3370
|
const leaf = emit(leaves[0]);
|
|
3203
|
-
ctx.imports.push(`import { Table, TableBody, TableHeader, TableRow } from "${module}";`);
|
|
3371
|
+
ctx.imports.push(`import { Table, TableBody, TableHeader, TableRow, ${SKELETON_ROWS} } from "${module}";`);
|
|
3204
3372
|
ctx.note(ctx.path, LIFTED, "published branch and leaf rows lifted as visible preorder data (hub-492)");
|
|
3373
|
+
// While the Surface loads, the body is the Table's own skeleton rows, as many as Figma draws (NODII-DEV-CLI-260).
|
|
3374
|
+
const skeleton = `<${SKELETON_ROWS} columns={${bodyColumns[0]}} rows={${branches.length + leaves.length}} />`;
|
|
3205
3375
|
return indent([
|
|
3206
3376
|
'<Table role="treegrid">',
|
|
3207
3377
|
...(heads.length ? [' <TableHeader>', ...heads.map((h) => indent(h, 2)), ' </TableHeader>'] : []),
|
|
3208
3378
|
' <TableBody>',
|
|
3209
|
-
` {${rows}.map((row) => (`,
|
|
3379
|
+
` {loading ? ${skeleton} : ${rows}.map((row) => (`,
|
|
3210
3380
|
' row.kind === "branch" ? (', indent(branch, 4),
|
|
3211
3381
|
' ) : (', indent(leaf, 4), ' )',
|
|
3212
3382
|
' ))}', ' </TableBody>', '</Table>',
|
|
@@ -3346,7 +3516,8 @@ function tableOf(node, ctx) {
|
|
|
3346
3516
|
ASSEMBLED,
|
|
3347
3517
|
`${rows.length} row${rows.length === 1 ? "" : "s"} of Table parts${plain ? ` (${plain} of them frame cells only)` : ""} assembled into one DS Table${skeleton ? ` (its ${loadingRows.length} row${loadingRows.length === 1 ? "" : "s"} of loading cells as one ${SKELETON_ROWS})` : ""} (MW8-17.3)`,
|
|
3348
3518
|
);
|
|
3349
|
-
|
|
3519
|
+
// TableSkeletonRows draws the loading state, drawn or the lifted rows' own; an unused name is dropped.
|
|
3520
|
+
ctx.imports.push(...imports, `import { Table, TableBody, TableCell, TableHeader, TableRow, ${SKELETON_ROWS} } from "${module}";`);
|
|
3350
3521
|
const { depth } = ctx;
|
|
3351
3522
|
// A cell the generator wraps has no template to say its density, so it takes the one
|
|
3352
3523
|
// its row's template cells declare, or the table's: a row is one height in Figma.
|
|
@@ -3433,6 +3604,20 @@ function tableOf(node, ctx) {
|
|
|
3433
3604
|
// from the drawing. Existing consumers keep the drawn label (hub-507).
|
|
3434
3605
|
return lifted.replace(/(<Table(?:Sort)?Head\b[^\n]*>\s*)\{("(?:[^"\\\n]|\\.)*")\}/, (_, open, label) => `${open}{${optionalMark(ctx, listName, `${key}Heading`, null)} ?? ${label}}`);
|
|
3435
3606
|
};
|
|
3607
|
+
// The lifted rows' loading state: as many skeleton rows as Figma draws body rows, each
|
|
3608
|
+
// column as wide as the header's (else the first row's) cell and aligned as its head.
|
|
3609
|
+
const liftedSkeleton = (count) => {
|
|
3610
|
+
const declared = (code) => /\bwidth=(?:\{(\d+)\}|"(\w+)")/.exec(/^[^>]*/.exec(code ?? "")?.[0] ?? "");
|
|
3611
|
+
const props = Array.from({ length: count }, (_, i) => {
|
|
3612
|
+
const cell = headRow?.cells[i] ?? dataRows[0].cells[i];
|
|
3613
|
+
const d = cell?.code ? declared(cell.code) : null;
|
|
3614
|
+
const w = d ? (d[1] ? Number(d[1]) : d[2]) : cell ? columnWidth(cell.cell) : null;
|
|
3615
|
+
const align = headAlign(i);
|
|
3616
|
+
return [w === null ? null : `width: ${JSON.stringify(w)}`, align ? `colAlign: ${JSON.stringify(align)}` : null, tableDensity ? `density: ${JSON.stringify(tableDensity)}` : null].filter(Boolean);
|
|
3617
|
+
});
|
|
3618
|
+
const cellProps = props.some((p) => p.length) ? ` cellProps={[${props.map((p) => (p.length ? `{ ${p.join(", ")} }` : "{}")).join(", ")}]}` : "";
|
|
3619
|
+
return `<${SKELETON_ROWS} columns={${count}} rows={${dataRows.length}}${cellProps} />`;
|
|
3620
|
+
};
|
|
3436
3621
|
const liftable = !skeleton && dataRows.length > 0 && dataRows.every((p) => !p.unrecognised && !p.framesOnly && p.cells.length === dataRows[0].cells.length) && (!headRow || headRow.cells.length === dataRows[0].cells.length);
|
|
3437
3622
|
const liftedRows = () => {
|
|
3438
3623
|
const first = dataRows[0];
|
|
@@ -3537,7 +3722,9 @@ function tableOf(node, ctx) {
|
|
|
3537
3722
|
...cells,
|
|
3538
3723
|
indent("</TableRow>", depth + 3),
|
|
3539
3724
|
];
|
|
3540
|
-
|
|
3725
|
+
// While the Surface loads, the body is the Table's own skeleton rows, never the page's (NODII-DEV-CLI-260).
|
|
3726
|
+
const open = `{loading ? ${liftedSkeleton(keys.length)} : ${rowsName}.map((row) => (`;
|
|
3727
|
+
if (!groupRows.length) return [indent(open, depth + 2), ...dataRow, indent("))}", depth + 2)];
|
|
3541
3728
|
// The groups are rows of the same list, in drawn order: `{ kind: "group", label }` heads
|
|
3542
3729
|
// the rows after it, drawn as its band's own head across every column (NODII-DEV-CLI-222).
|
|
3543
3730
|
let labelKey = "label";
|
|
@@ -3548,7 +3735,7 @@ function tableOf(node, ctx) {
|
|
|
3548
3735
|
const bandTag = /^<([A-Za-z]+)/.exec(bandCode)[1];
|
|
3549
3736
|
ctx.note(ctx.path, LIFTED, `${groupRows.length} group band${groupRows.length === 1 ? "" : "s"} lifted with the rows: { kind: "group", ${labelKey} } (NODII-DEV-CLI-222)`);
|
|
3550
3737
|
return [
|
|
3551
|
-
indent(
|
|
3738
|
+
indent(open, depth + 2),
|
|
3552
3739
|
indent('row.kind === "group" ? (', depth + 3),
|
|
3553
3740
|
indent("<TableRow key={row.id}>", depth + 4),
|
|
3554
3741
|
indent(`${bandOpen}{row.${labelKey}}</${bandTag}>`, depth + 5),
|
|
@@ -3837,8 +4024,15 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
3837
4024
|
for (const r of results) {
|
|
3838
4025
|
const out = generatedPath(root, r.row);
|
|
3839
4026
|
r.file = relative(root, out);
|
|
4027
|
+
r.wrapperFile = null;
|
|
3840
4028
|
if (f.write) {
|
|
3841
4029
|
writeFileSync(out, r.code);
|
|
4030
|
+
// The route's wrapper, only where no page is yet (wrapperCode).
|
|
4031
|
+
const page = r.wrapper ? join(root, r.row.sourcePath) : null;
|
|
4032
|
+
if (page && !existsSync(page)) {
|
|
4033
|
+
writeFileSync(page, r.wrapper);
|
|
4034
|
+
r.wrapperFile = relative(root, page);
|
|
4035
|
+
}
|
|
3842
4036
|
} else if (f.check) {
|
|
3843
4037
|
const current = existsSync(out) ? readFileSync(out, "utf8") : null;
|
|
3844
4038
|
if (current !== r.code) differences.push({ id: r.row.id, file: r.file, reason: current === null ? "missing" : "differs" });
|
|
@@ -3872,7 +4066,7 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
3872
4066
|
const payload = {
|
|
3873
4067
|
data: {
|
|
3874
4068
|
mode,
|
|
3875
|
-
surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, states: r.states, unmapped: counted(r.unmapped).length })),
|
|
4069
|
+
surfaces: results.map((r) => ({ id: r.row.id, componentSetKey: r.row.componentSetKey, file: r.file, wrapper: r.wrapperFile, states: r.states, loadingVariants: r.loadingVariants ?? [], unmapped: counted(r.unmapped).length })),
|
|
3876
4070
|
differences,
|
|
3877
4071
|
notGeneratedYet: notYet,
|
|
3878
4072
|
generatedWithoutCatalogRow: withoutRow,
|
|
@@ -3888,9 +4082,12 @@ export async function surfaceCommand(action, rest, f, deps = {}) {
|
|
|
3888
4082
|
const lines = results.map(
|
|
3889
4083
|
(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"}`,
|
|
3890
4084
|
);
|
|
4085
|
+
for (const r of results) if (r.wrapperFile) lines.push(`wrote wrapper\t${r.wrapperFile}`);
|
|
3891
4086
|
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\``);
|
|
3892
4087
|
if (withoutRow.length)
|
|
3893
4088
|
lines.push(`no catalog row: ${withoutRow.length} generated page${withoutRow.length === 1 ? "" : "s"} not regenerated or compared, because the product-page catalog has no row for ${withoutRow.length === 1 ? "it" : "them"} (MW8-17.1):`, ...withoutRow.map((x) => ` ${x.file}`));
|
|
4089
|
+
const loadingVariants = loadingVariantWarning(results);
|
|
4090
|
+
if (loadingVariants) lines.push(loadingVariants);
|
|
3894
4091
|
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(", ")}`);
|
|
3895
4092
|
if (f.check && differences.length)
|
|
3896
4093
|
lines.push(`SURFACE_GEN_DIFFERS: ${differences.length} product page${differences.length === 1 ? " differs" : "s differ"} from the generator's output; run \`nodii-dev surface generate --all --write\` and commit, never hand-edit a generated file`);
|