@nodii/dev 0.6.198 → 0.6.199
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 +9 -0
- package/dist/core.js +1 -1
- package/dist/surface.js +58 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1325,6 +1325,15 @@ product-page catalog names the Surface by its published component-set key
|
|
|
1325
1325
|
`{loading ? <TableSkeletonRows … /> : rows.map(…)}` under its real header, a
|
|
1326
1326
|
skeleton row per drawn row. A part that already draws the prop keeps it. So a
|
|
1327
1327
|
route passes `loading` and never hand-builds a loading page.
|
|
1328
|
+
- **A record's facts draw their skeleton (hub-634).** While `loading` is
|
|
1329
|
+
true, the value of each `DescriptionItem`, `DetailFact` and `RightPaneRow`, and
|
|
1330
|
+
the lifted value text of a label/value pair (a frame of two texts, a label then
|
|
1331
|
+
its value), is the DS `<Skeleton shape="text" />`:
|
|
1332
|
+
`value={loading ? <Skeleton shape="text" /> : fromValue}`. A lone Description
|
|
1333
|
+
Item hidden while its value is missing still draws while loading
|
|
1334
|
+
(`{(loading || fromValue != null) && (…)}`). Each value keeps the type of the
|
|
1335
|
+
part that draws it. `Skeleton` is imported from the module the page's DS parts
|
|
1336
|
+
come from; a view with no fact is unchanged.
|
|
1328
1337
|
- **Error and Empty views a route drives (NODII-DEV-CLI-260).** The Surface takes
|
|
1329
1338
|
`<Id>SurfaceInput`: a `state` with the full props, as before, or a literal
|
|
1330
1339
|
`state` with only the props its view reads (`{ state: "read-error" } &
|
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.199";
|
|
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 = 53;
|
|
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
|
|
@@ -646,13 +646,15 @@ export function emitSurface(tree, row, ds) {
|
|
|
646
646
|
const optionals = { optional: new Set(), required: new Set() };
|
|
647
647
|
// Each list the generator assembles from sibling parts (alertRun): its members a page may leave out, and any narrowed type.
|
|
648
648
|
const items = new Map();
|
|
649
|
+
// Each loose text lifted as a fact's value, whose skeleton draws while the Surface loads (skeletonFacts).
|
|
650
|
+
const factTexts = new Set();
|
|
649
651
|
const views = graftAbsentSlots(tree.variants).map((variant) => {
|
|
650
652
|
let state = variant.state;
|
|
651
653
|
while (used.has(state)) state += "-x";
|
|
652
654
|
used.add(state);
|
|
653
655
|
const fn = `${pascal(state)}View`;
|
|
654
656
|
const note = (path, kind, detail) => unmapped.push({ variant: variant.name, path, kind, detail });
|
|
655
|
-
const emitted = emitNode(pageBody(variant, row), { depth: 2, parent: null, path: variant.name, row, ds, imports, note, root: true, scopes, layers, layer: "", state, lists: new Map(), shapes, handlers: new Map(), shown: new Map(), optionals, items }) ?? "";
|
|
657
|
+
const emitted = emitNode(pageBody(variant, row), { depth: 2, parent: null, path: variant.name, row, ds, imports, note, root: true, scopes, layers, layer: "", state, lists: new Map(), shapes, handlers: new Map(), shown: new Map(), optionals, items, factTexts }) ?? "";
|
|
656
658
|
// A view the generator can't lay out is no page at all: generation fails rather than ship
|
|
657
659
|
// an empty view (NODII-DEV-CLI-81).
|
|
658
660
|
if (emitted.trimStart().startsWith("{/*")) {
|
|
@@ -670,6 +672,8 @@ export function emitSurface(tree, row, ds) {
|
|
|
670
672
|
const named = resolveScopes(views, scopes, layers);
|
|
671
673
|
settlePiiColumns(views, unmapped);
|
|
672
674
|
const data = dataProps(views, propsType);
|
|
675
|
+
// After the props are typed from what each part draws: a fact's value is its skeleton while loading.
|
|
676
|
+
skeletonFacts(views, imports, [...factTexts].map((token) => named.get(token) ?? token));
|
|
673
677
|
// A prop is optional when every template that draws it lists it in `metadata.optionalProps`.
|
|
674
678
|
const optionalNames = new Map();
|
|
675
679
|
for (const [token, name] of named) {
|
|
@@ -1401,6 +1405,13 @@ function isFactValue(node, parent) {
|
|
|
1401
1405
|
return children.length === 2 && children.every((child) => child.type === "TEXT") && children[1] === node;
|
|
1402
1406
|
}
|
|
1403
1407
|
|
|
1408
|
+
/** A label/value pair's value: the second of a frame's two texts, after a label that is copy (hub-634). */
|
|
1409
|
+
function isPairValue(node, parent) {
|
|
1410
|
+
if (parent?.type !== "FRAME") return false;
|
|
1411
|
+
const children = (parent.children ?? []).filter((child) => child.visible !== false);
|
|
1412
|
+
return children.length === 2 && children.every((child) => child.type === "TEXT") && children[1] === node && !RECORD_TEXT(children[0].text ?? "");
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1404
1415
|
/** A part named by where it sits: its parent's name, numbered when the parent holds several of the same set. */
|
|
1405
1416
|
function positionScope(node, ctx, kind) {
|
|
1406
1417
|
const siblings = (ctx.parent?.children ?? []).filter((c) => c.visible !== false && (node.instance ? c.instance?.set === node.instance.set : c.type === node.type));
|
|
@@ -2385,6 +2396,50 @@ function passLoading(code) {
|
|
|
2385
2396
|
return out + code.slice(last);
|
|
2386
2397
|
}
|
|
2387
2398
|
|
|
2399
|
+
/**
|
|
2400
|
+
* While the Surface loads, a record's facts draw the DS Skeleton text shape in place of
|
|
2401
|
+
* their values, as a lifted table draws TableSkeletonRows (hub-634): the value
|
|
2402
|
+
* of a Description Item, Detail Fact or Right Pane Row, and a label/value pair's lifted
|
|
2403
|
+
* value text. A fact hidden while its value is missing (a lone Description Item) still
|
|
2404
|
+
* draws its skeleton while loading. Run after the props are typed, so each value keeps
|
|
2405
|
+
* the type of the part that draws it. Skeleton comes from the DS module the page's DS
|
|
2406
|
+
* parts come from; a page with no such import is left as it is.
|
|
2407
|
+
*/
|
|
2408
|
+
const FACT_SKELETON = '<Skeleton shape="text" />';
|
|
2409
|
+
const FACT_PARTS = /<(?:DescriptionItem|DetailFact|RightPaneRow)(?=[\s/>])/g;
|
|
2410
|
+
const FACT_VALUE = /(\svalue=\{)([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\}/;
|
|
2411
|
+
const SKELETON_HOST = /\b(?:DescriptionItem|DescriptionList|DetailFact|DetailSection|Card|Badge|PiiText|Tabs|Field|Alert|EmptyState|Button|TableCell|TableHead)\b/;
|
|
2412
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2413
|
+
function skeletonFacts(views, imports, factTexts) {
|
|
2414
|
+
const module = imports
|
|
2415
|
+
.map((s) => /^import\s+\{([^}]*)\}\s+from\s+["']([^"']+)["']/.exec(s.trim()))
|
|
2416
|
+
.find((m) => m && !/^(?:\.|@\/)/.test(m[2]) && SKELETON_HOST.test(m[1]))?.[2];
|
|
2417
|
+
if (!module) return;
|
|
2418
|
+
let drawn = false;
|
|
2419
|
+
for (const view of views) {
|
|
2420
|
+
let body = view.body;
|
|
2421
|
+
const masked = maskStrings(body);
|
|
2422
|
+
const edits = [];
|
|
2423
|
+
for (const m of masked.matchAll(FACT_PARTS)) {
|
|
2424
|
+
const open = masked.slice(m.index, m.index + openTagEnd(masked.slice(m.index)) + 1);
|
|
2425
|
+
const value = FACT_VALUE.exec(open);
|
|
2426
|
+
if (value) edits.push({ at: m.index + value.index + value[1].length, read: value[2] });
|
|
2427
|
+
}
|
|
2428
|
+
const gated = new Set();
|
|
2429
|
+
for (const { at, read } of edits.reverse()) {
|
|
2430
|
+
body = `${body.slice(0, at)}loading ? ${FACT_SKELETON} : ${body.slice(at)}`;
|
|
2431
|
+
if (!read.includes(".")) gated.add(read);
|
|
2432
|
+
}
|
|
2433
|
+
for (const read of gated) body = body.replace(new RegExp(String.raw`\{${escapeRegExp(read)} != null && \(`, "g"), `{(loading || ${read} != null) && (`);
|
|
2434
|
+
for (const name of factTexts) body = body.replace(new RegExp(String.raw`(<span\b[^>\n]*>)\{${escapeRegExp(name)}\}(</span>)`, "g"), `$1{loading ? ${FACT_SKELETON} : ${name}}$2`);
|
|
2435
|
+
if (body === view.body) continue;
|
|
2436
|
+
view.body = body;
|
|
2437
|
+
view.uses.add("loading");
|
|
2438
|
+
drawn = true;
|
|
2439
|
+
}
|
|
2440
|
+
if (drawn) imports.push(`import { Skeleton } from "${module}";`);
|
|
2441
|
+
}
|
|
2442
|
+
|
|
2388
2443
|
/** The type the generated file declares for drawnProps (see there). */
|
|
2389
2444
|
const DRAWN_TYPE = [
|
|
2390
2445
|
"/** A DS component's props, narrowed to the member of their union this call draws: every required prop passed, every literal one fitting. */",
|
|
@@ -2819,6 +2874,7 @@ function emitNode(node, ctx) {
|
|
|
2819
2874
|
const name = mark(ctx, scope, scope);
|
|
2820
2875
|
note(path, LIFTED, `text ${shown} names a record's value: lifted from Figma's sample into the page's props (NODII-DEV-CLI-82)`);
|
|
2821
2876
|
content = name;
|
|
2877
|
+
if (ctx.scopes && !ctx.inTable && isPairValue(node, parent)) ctx.factTexts?.add(name);
|
|
2822
2878
|
}
|
|
2823
2879
|
return indent(`<span${classes ? ` className="${classes}"` : ""}>{${content}}</span>`, depth);
|
|
2824
2880
|
}
|