@nodii/dev 0.6.137 → 0.6.138
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 +147 -17
- 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.138";
|
|
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 = 12;
|
|
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). */
|
|
@@ -528,13 +528,15 @@ export function emitSurface(tree, row, ds) {
|
|
|
528
528
|
}
|
|
529
529
|
const used = new Set();
|
|
530
530
|
const scopes = new Map();
|
|
531
|
+
// Each list's columns by name, across views (listScope).
|
|
532
|
+
const shapes = new Map();
|
|
531
533
|
const views = tree.variants.map((variant) => {
|
|
532
534
|
let state = variant.state;
|
|
533
535
|
while (used.has(state)) state += "-x";
|
|
534
536
|
used.add(state);
|
|
535
537
|
const fn = `${pascal(state)}View`;
|
|
536
538
|
const note = (path, kind, detail) => unmapped.push({ variant: variant.name, path, kind, detail });
|
|
537
|
-
const emitted = emitNode(pageBody(variant, row), { depth: 2, parent: null, path: variant.name, ds, imports, note, root: true, scopes, state }) ?? "";
|
|
539
|
+
const emitted = emitNode(pageBody(variant, row), { depth: 2, parent: null, path: variant.name, ds, imports, note, root: true, scopes, state, lists: new Map(), shapes }) ?? "";
|
|
538
540
|
// A view the generator can't lay out is no page at all: generation fails rather than ship
|
|
539
541
|
// an empty view (NODII-DEV-CLI-81).
|
|
540
542
|
if (emitted.trimStart().startsWith("{/*")) {
|
|
@@ -546,7 +548,7 @@ export function emitSurface(tree, row, ds) {
|
|
|
546
548
|
const stateType = `${component}State`;
|
|
547
549
|
const propsType = `${component}Props`;
|
|
548
550
|
resolveScopes(views, scopes);
|
|
549
|
-
const data = dataProps(views);
|
|
551
|
+
const data = dataProps(views, propsType);
|
|
550
552
|
const reactTypes = [data.size && "ComponentProps", [...data.values()].some((d) => /\bReactNode\b/.test(propType(d))) && "ReactNode"].filter(Boolean);
|
|
551
553
|
const drawn = [...data.values()].some((d) => [...d.attrs.values(), ...[...d.members.values()].flatMap((refs) => [...refs.values()])].some((r) => r.keys));
|
|
552
554
|
const header = [
|
|
@@ -568,7 +570,7 @@ export function emitSurface(tree, row, ds) {
|
|
|
568
570
|
? [
|
|
569
571
|
"/** The data and callbacks the Surface's Code Connect templates take (DS-BLK-1): each typed as the DS component it reaches. */",
|
|
570
572
|
`export interface ${propsType} {`,
|
|
571
|
-
...[...data.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([name, d]) => ` ${name}: ${propType(d)};`),
|
|
573
|
+
...[...data.entries()].sort(([a], [b]) => a.localeCompare(b)).map(([name, d]) => ` ${name}${d.optional ? "?" : ""}: ${d.raw ?? propType(d)};`),
|
|
572
574
|
"}",
|
|
573
575
|
"",
|
|
574
576
|
]
|
|
@@ -703,6 +705,61 @@ function textBeside(node, ctx) {
|
|
|
703
705
|
return before(ctx.parent, node) ?? (ctx.grand ? before(ctx.grand, ctx.parent) : null);
|
|
704
706
|
}
|
|
705
707
|
|
|
708
|
+
/** A section's own title: heading-styled text, or the title of a DS section or card header. */
|
|
709
|
+
const HEADING_STYLE = /heading|title/i;
|
|
710
|
+
const HEADER_SET = /\b(section|card|page) ?head(er)?\b/i;
|
|
711
|
+
function headingIn(node) {
|
|
712
|
+
if (node.visible === false) return null;
|
|
713
|
+
if (node.type === "TEXT") return HEADING_STYLE.test(node.textStyle ?? "") && /[A-Za-z0-9]/.test(node.text ?? "") ? node.text : null;
|
|
714
|
+
if (node.instance?.remote) {
|
|
715
|
+
const title = node.instance.props?.title;
|
|
716
|
+
return HEADER_SET.test(node.instance.set ?? "") && typeof title === "string" && /[A-Za-z0-9]/.test(title) ? title : null;
|
|
717
|
+
}
|
|
718
|
+
for (const c of node.children ?? []) {
|
|
719
|
+
const found = headingIn(c);
|
|
720
|
+
if (found) return found;
|
|
721
|
+
}
|
|
722
|
+
return null;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* The heading of the section a part sits in: the nearest heading drawn before
|
|
727
|
+
* it, looking back through its own frame, then its frame's frame, up to the view.
|
|
728
|
+
* `chain` is the part's ancestors, nearest last.
|
|
729
|
+
*/
|
|
730
|
+
function sectionHeading(target, chain) {
|
|
731
|
+
let cur = target;
|
|
732
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
733
|
+
const shown = (chain[i].children ?? []).filter((c) => c.visible !== false);
|
|
734
|
+
const at = shown.indexOf(cur);
|
|
735
|
+
for (const sibling of shown.slice(0, Math.max(at, 0)).reverse()) {
|
|
736
|
+
const found = headingIn(sibling);
|
|
737
|
+
if (found) return found;
|
|
738
|
+
}
|
|
739
|
+
cur = chain[i];
|
|
740
|
+
}
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* The scope a list (a table's rows, a run of description lists) is named by:
|
|
746
|
+
* its section's heading, else `fallback`. Two lists in one view never share a
|
|
747
|
+
* scope, so never a prop (hub-454): a second list under the same
|
|
748
|
+
* heading is numbered. The same list in another view takes the same name; a
|
|
749
|
+
* list of another `shape` (a table's columns) in another view is numbered too,
|
|
750
|
+
* so one prop is never typed as two tables merged.
|
|
751
|
+
*/
|
|
752
|
+
function listScope(target, ctx, fallback, shape = null) {
|
|
753
|
+
const base = sectionHeading(target, ctx.chain ?? []) ?? fallback;
|
|
754
|
+
let name = camelName(base);
|
|
755
|
+
if (!ctx.lists) return name;
|
|
756
|
+
const taken = (n) => (ctx.lists.has(n) && ctx.lists.get(n) !== target) || (shape !== null && ctx.shapes?.has(n) && ctx.shapes.get(n) !== shape);
|
|
757
|
+
for (let n = 2; taken(name); n++) name = camelName(`${base} ${n}`);
|
|
758
|
+
ctx.lists.set(name, target);
|
|
759
|
+
if (shape !== null) ctx.shapes?.set(name, shape);
|
|
760
|
+
return name;
|
|
761
|
+
}
|
|
762
|
+
|
|
706
763
|
/** Text in camelCase as an identifier (`Subject kind` → `subjectKind`, `2FA` → `field2fa`). */
|
|
707
764
|
function camelName(text) {
|
|
708
765
|
const words = String(text ?? "").match(/[A-Za-z0-9]+/g) ?? [];
|
|
@@ -782,6 +839,16 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
782
839
|
next = tone ? next.replace(tone[0], `tone={${lift(scope, "tone")}}`) : next.replace(`label={`, `tone={${lift(scope, "tone")}} label={`);
|
|
783
840
|
return `<StatusPill${next}${close}>`;
|
|
784
841
|
});
|
|
842
|
+
// A Badge beside a record (outside a table) is its status: label and tone are the record's,
|
|
843
|
+
// as a StatusPill's (NODII-DEV-CLI-82). In a table, the lifted rows carry it.
|
|
844
|
+
if (!ctx.inTable) {
|
|
845
|
+
out = out.replace(/^<Badge\b([^>]*)>([^<>{}\n]*[A-Za-z0-9][^<>{}\n]*)<\/Badge>$/, (all, attrs) => {
|
|
846
|
+
const at = positionScope(node, ctx, "status");
|
|
847
|
+
const tone = new RegExp(String.raw`\btone=${LITERAL}`).exec(attrs);
|
|
848
|
+
const toned = tone ? attrs.replace(tone[0], `tone={${lift(at, "tone")}}`) : ` tone={${lift(at, "tone")}}${attrs}`;
|
|
849
|
+
return `<Badge${toned}>{${lift(at, "label")}}</Badge>`;
|
|
850
|
+
});
|
|
851
|
+
}
|
|
785
852
|
out = rewriteTags(out, String.raw`Metric(?!CardGroup\b)[A-Za-z]*`, (attrs, tag) => {
|
|
786
853
|
const name = new RegExp(String.raw`\b(?:title|label)=(${LITERAL})`).exec(attrs);
|
|
787
854
|
const at = name ? camelName(literalText(name[1])) : scope;
|
|
@@ -799,10 +866,11 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
799
866
|
return next.replace(/\s*\/?$/, (end) => ` ${selected}${end}`);
|
|
800
867
|
});
|
|
801
868
|
out = rewriteTags(out, "Pagination|CursorPagination", (attrs, tag) => {
|
|
802
|
-
if (tag === "Pagination" && !/\btype="cursor-bar"/.test(attrs)) return attrs;
|
|
803
869
|
let next = attrs;
|
|
870
|
+
// A numbered pager's summary ("Showing 1 – 5 of 5 results") is list state too.
|
|
804
871
|
const summary = new RegExp(String.raw`\bsummary=${LITERAL}`).exec(next);
|
|
805
872
|
if (summary) next = next.replace(summary[0], `summary={${lift(scope, "summary")}}`);
|
|
873
|
+
if (tag === "Pagination" && !/\btype="cursor-bar"/.test(attrs)) return next;
|
|
806
874
|
for (const attr of ["hasNext", "hasPrev"]) {
|
|
807
875
|
const value = `${attr}={${lift(scope, attr)}}`;
|
|
808
876
|
const bare = bareAttr(next, attr);
|
|
@@ -833,6 +901,13 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
833
901
|
*/
|
|
834
902
|
export const SAMPLE_VALUE = /₹\s?\d|\b\d{1,2} (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\b|[\w.+-]+@[a-z0-9-]+\.[a-z]|\b[a-z0-9-]+\.(?:com|in|io|co|org|net)\b|\b[A-Z]{2,5}-\d[\w-]*\b/;
|
|
835
903
|
|
|
904
|
+
/**
|
|
905
|
+
* Loose text that is a record's value: a sample value, or any text with a figure
|
|
906
|
+
* in it ("3 waiting on you", "v2 · published", "Showing 1 - 10 of 46"), which is a
|
|
907
|
+
* count, a version or a date, never fixed copy (NODII-DEV-CLI-82).
|
|
908
|
+
*/
|
|
909
|
+
const RECORD_TEXT = (text) => SAMPLE_VALUE.test(text) || /\d/.test(text);
|
|
910
|
+
|
|
836
911
|
/** A part named by where it sits: its parent's name, numbered when the parent holds several of the same set. */
|
|
837
912
|
function positionScope(node, ctx, kind) {
|
|
838
913
|
const siblings = (ctx.parent?.children ?? []).filter((c) => c.visible !== false && (node.instance ? c.instance?.set === node.instance.set : c.type === node.type));
|
|
@@ -972,9 +1047,14 @@ function resolveScopes(views, scopes) {
|
|
|
972
1047
|
for (const view of views) view.body = view.body.replace(marked, (_, n, name) => (users.get(name).size > 1 ? scoped(names[Number(n)], name) : name));
|
|
973
1048
|
}
|
|
974
1049
|
|
|
975
|
-
function dataProps(views) {
|
|
1050
|
+
function dataProps(views, propsType) {
|
|
976
1051
|
const data = new Map();
|
|
977
1052
|
const entry = (name) => data.get(name) ?? data.set(name, { attrs: new Map(), child: false, nested: false, members: new Map(), list: false }).get(name);
|
|
1053
|
+
// List state the generator itself writes (tableOf), optional: a page without a record
|
|
1054
|
+
// route or a server sort passes nothing (NODII-DEV-CLI-83).
|
|
1055
|
+
const own = (name, raw) => Object.assign(entry(name), { raw, optional: true });
|
|
1056
|
+
const keysOf = (name) => entry(name).sortKeys ?? (entry(name).sortKeys = new Set());
|
|
1057
|
+
const union = (keys) => [...keys].sort().map((k) => JSON.stringify(k)).join(" | ");
|
|
978
1058
|
const member = (d, name) => d.members.get(name) ?? d.members.set(name, new Map()).get(name);
|
|
979
1059
|
for (const view of views) {
|
|
980
1060
|
view.uses = new Set();
|
|
@@ -986,8 +1066,21 @@ function dataProps(views) {
|
|
|
986
1066
|
view.uses.add(o.list);
|
|
987
1067
|
}
|
|
988
1068
|
const itemList = (at, name) => (openers.some((o) => o.param === name) ? listAt(openers, at, name) : null);
|
|
1069
|
+
for (const m of body.matchAll(/onClick=\{([a-z][A-Za-z0-9]*) && \(\(\) => \1\(([a-z][A-Za-z0-9]*)\)\)\}/g)) {
|
|
1070
|
+
const list = listAt(openers, m.index, m[2]);
|
|
1071
|
+
if (!list) continue;
|
|
1072
|
+
own(m[1], `(row: ${propsType}[${JSON.stringify(list)}][number]) => void`);
|
|
1073
|
+
view.uses.add(m[1]);
|
|
1074
|
+
}
|
|
1075
|
+
for (const m of body.matchAll(/\bsort=\{([a-z][A-Za-z0-9]*) === ("(?:[^"\\\n]|\\.)*") \? ([a-z][A-Za-z0-9]*) : false\} onSort=\{([a-z][A-Za-z0-9]*) && /g)) {
|
|
1076
|
+
const [, by, key, dir, change] = m;
|
|
1077
|
+
keysOf(by).add(JSON.parse(key));
|
|
1078
|
+
keysOf(change).add(JSON.parse(key));
|
|
1079
|
+
own(dir, '"asc" | "desc"');
|
|
1080
|
+
for (const name of [by, dir, change]) view.uses.add(name);
|
|
1081
|
+
}
|
|
989
1082
|
for (const m of body.matchAll(/([A-Za-z][\w-]*)=\{([a-z][A-Za-z0-9]*)(?:\.([A-Za-z][A-Za-z0-9]*))?\}/g)) {
|
|
990
|
-
if (JS_LITERALS.has(m[2])) continue;
|
|
1083
|
+
if (JS_LITERALS.has(m[2]) || data.get(m[2])?.raw) continue;
|
|
991
1084
|
const list = m[3] ? itemList(m.index, m[2]) : null;
|
|
992
1085
|
// A list item's React key is its own: a string, never a DS prop.
|
|
993
1086
|
if (list && m[1] === "key") {
|
|
@@ -1018,6 +1111,14 @@ function dataProps(views) {
|
|
|
1018
1111
|
view.uses.add(m[1]);
|
|
1019
1112
|
}
|
|
1020
1113
|
}
|
|
1114
|
+
for (const d of data.values()) {
|
|
1115
|
+
if (!d.sortKeys) continue;
|
|
1116
|
+
const keys = union(d.sortKeys);
|
|
1117
|
+
d.optional = true;
|
|
1118
|
+
d.raw = d.raw ?? keys;
|
|
1119
|
+
}
|
|
1120
|
+
// The sort's change hears the column and the way, as the heads' keys type them.
|
|
1121
|
+
for (const [name, d] of data) if (d.sortKeys && /^on[A-Z]\w*SortChange$|^onSortChange$/.test(name)) d.raw = `(sortBy: ${union(d.sortKeys)}, sortDir: "asc" | "desc") => void`;
|
|
1021
1122
|
return data;
|
|
1022
1123
|
}
|
|
1023
1124
|
|
|
@@ -1261,7 +1362,9 @@ function emitNode(node, ctx) {
|
|
|
1261
1362
|
if (node.visible === false) return null;
|
|
1262
1363
|
const { ds, note, depth, parent, root } = ctx;
|
|
1263
1364
|
const path = root ? ctx.path : `${ctx.path} › ${node.name}`;
|
|
1264
|
-
|
|
1365
|
+
// Every node's ancestors, nearest last: a list is named by the section heading before it (hub-454).
|
|
1366
|
+
const chain = [...(ctx.chain ?? []), node];
|
|
1367
|
+
const child = (c) => emitNode(c, { ...ctx, depth: depth + 1, parent: node, grand: parent, path, root: false, chain });
|
|
1265
1368
|
const report = (detail) => note(path, "token", detail);
|
|
1266
1369
|
|
|
1267
1370
|
// A DS library instance: exactly what its Code Connect template emits for this instance's properties.
|
|
@@ -1291,7 +1394,7 @@ function emitNode(node, ctx) {
|
|
|
1291
1394
|
return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
|
|
1292
1395
|
}
|
|
1293
1396
|
const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
|
|
1294
|
-
const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false };
|
|
1397
|
+
const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, chain: slotNode ? [...chain, slotNode] : chain };
|
|
1295
1398
|
const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
|
|
1296
1399
|
return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
|
|
1297
1400
|
};
|
|
@@ -1340,7 +1443,7 @@ function emitNode(node, ctx) {
|
|
|
1340
1443
|
]);
|
|
1341
1444
|
// Text naming a record's value (a date, an amount, a code) is Figma's sample: the page's own (NODII-DEV-CLI-82).
|
|
1342
1445
|
let content = JSON.stringify(node.text);
|
|
1343
|
-
if (
|
|
1446
|
+
if (RECORD_TEXT(node.text) && !ctx.textOwner) {
|
|
1344
1447
|
const scope = positionScope(node, ctx, "text");
|
|
1345
1448
|
const name = mark(ctx, scope, scope);
|
|
1346
1449
|
note(path, LIFTED, `text ${shown} names a record's value: lifted from Figma's sample into the page's props (NODII-DEV-CLI-82)`);
|
|
@@ -1371,7 +1474,7 @@ function emitNode(node, ctx) {
|
|
|
1371
1474
|
return indent(comment(`unmapped: ${node.type.toLowerCase()} ${JSON.stringify(node.name)} has no auto layout`), depth);
|
|
1372
1475
|
}
|
|
1373
1476
|
const classes = cls([...sizeClasses(node, parent, root), ...layoutClasses(node), node.clips ? "overflow-hidden" : null]);
|
|
1374
|
-
const kids = emitChildren(node.children ?? [], child, { ...ctx, depth: depth + 1, parent: node, grand: parent, path, root: false });
|
|
1477
|
+
const kids = emitChildren(node.children ?? [], child, { ...ctx, depth: depth + 1, parent: node, grand: parent, path, root: false, chain });
|
|
1375
1478
|
const open = `<div${classes ? ` className="${classes}"` : ""}`;
|
|
1376
1479
|
if (!kids.length) return indent(`${open} />`, depth);
|
|
1377
1480
|
return [indent(`${open}>`, depth), ...kids, indent("</div>", depth)].join("\n");
|
|
@@ -1386,6 +1489,7 @@ function emitNode(node, ctx) {
|
|
|
1386
1489
|
*/
|
|
1387
1490
|
function emitChildren(children, emitOne, ctx) {
|
|
1388
1491
|
const out = [];
|
|
1492
|
+
const across = ctx.parent?.layout?.mode === "HORIZONTAL";
|
|
1389
1493
|
let run = [];
|
|
1390
1494
|
let runKind = null;
|
|
1391
1495
|
const flush = () => {
|
|
@@ -1397,7 +1501,9 @@ function emitChildren(children, emitOne, ctx) {
|
|
|
1397
1501
|
};
|
|
1398
1502
|
for (const c of children) {
|
|
1399
1503
|
if (c.visible === false) continue;
|
|
1400
|
-
|
|
1504
|
+
// Description lists side by side are columns of the layout, each its own list; only a run
|
|
1505
|
+
// down a column is one list of items (hub-454).
|
|
1506
|
+
const kind = tabOf(c, ctx) ? "tab" : !across && descriptionOf(c, ctx) ? `dl${descriptionOf(c, ctx).open}` : null;
|
|
1401
1507
|
if (kind && kind !== runKind) flush();
|
|
1402
1508
|
if (kind) {
|
|
1403
1509
|
run.push(c);
|
|
@@ -1433,7 +1539,7 @@ function descriptionRun(run, ctx) {
|
|
|
1433
1539
|
const { depth, path } = ctx;
|
|
1434
1540
|
const { open, imports } = descriptionOf(run[0], ctx);
|
|
1435
1541
|
ctx.imports.push(...imports);
|
|
1436
|
-
const items = mark(ctx, scopeName(ctx.parent ?? { name: "items" }), "items");
|
|
1542
|
+
const items = mark(ctx, listScope(run[0], ctx, scopeName(ctx.parent ?? { name: "items" })), "items");
|
|
1437
1543
|
ctx.note(path, LIFTED, `${run.length} sibling Description Lists lifted as one list of items (NODII-DEV-CLI-82)`);
|
|
1438
1544
|
const list = [
|
|
1439
1545
|
`<DescriptionList${open}>`,
|
|
@@ -1465,7 +1571,15 @@ function tabStrip(run, ctx) {
|
|
|
1465
1571
|
const { depth, path } = ctx;
|
|
1466
1572
|
const tabs = run.map((c) => tabOf(c, { ...ctx, path: `${path} › ${c.name}` }, { imports: ctx.imports, note: ctx.note }));
|
|
1467
1573
|
ctx.note(path, ASSEMBLED, `${run.length} sibling Tabs gathered into one DS Tab strip (MW8-17.3)`);
|
|
1468
|
-
|
|
1574
|
+
// Each tab's value is its label (`Pending revisions` → `pending-revisions`), so the page can
|
|
1575
|
+
// route by it; tab-<n> when it has none or shares it (NODII-DEV-CLI-83).
|
|
1576
|
+
const values = [];
|
|
1577
|
+
for (const [i, t] of tabs.entries()) {
|
|
1578
|
+
const label = /\{("(?:[^"\\\n]|\\.)*")\}/.exec(t.trigger);
|
|
1579
|
+
const value = label ? slug(JSON.parse(label[1])) : "";
|
|
1580
|
+
values.push(value && !values.includes(value) ? value : `tab-${i + 1}`);
|
|
1581
|
+
}
|
|
1582
|
+
const triggers = tabs.map((t, i) => indent(t.trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bvalue="tab"/, `$1value="${values[i]}"`), 2));
|
|
1469
1583
|
return [
|
|
1470
1584
|
// The page controls which tab is shown (NODII-DEV-CLI-83); Figma's selected tab is only the drawn one.
|
|
1471
1585
|
indent(CONTROLLED_TABS(mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "tab"), mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "onTabChange")), depth),
|
|
@@ -1700,11 +1814,27 @@ function tableOf(node, ctx) {
|
|
|
1700
1814
|
return keys;
|
|
1701
1815
|
};
|
|
1702
1816
|
const headKeys = headRow ? columnKeys(headRow.cells.length) : [];
|
|
1817
|
+
// The table's list state is named by its section, so two tables never share it (hub-454).
|
|
1818
|
+
const listName = listScope(node, ctx, scopeName(node), (headRow ? headKeys : columnKeys(dataRows[0]?.cells.length ?? 0)).join(","));
|
|
1819
|
+
// A sortable head is one column of the list's one sort, which the page owns: which column
|
|
1820
|
+
// and which way, and a change calls back with both, as DataTableToolbarBlock's sortBy,
|
|
1821
|
+
// sortDir and onSortChange (NODII-DEV-CLI-83). The template's per-column onSort and a
|
|
1822
|
+
// drawn sort="asc" are Figma's sample.
|
|
1823
|
+
const controlSort = (code, key) => {
|
|
1824
|
+
if (!key || !/^\s*<TableSortHead\b/.test(code ?? "")) return code;
|
|
1825
|
+
const [by, dir, change] = ["sortBy", "sortDir", "onSortChange"].map((n) => mark(ctx, listName, n));
|
|
1826
|
+
const k = JSON.stringify(key);
|
|
1827
|
+
return code
|
|
1828
|
+
.replace(/(<TableSortHead\b[^>]*?) sort="(?:asc|desc)"/, "$1")
|
|
1829
|
+
.replace(/\bonSort=\{(?:__s\d+_)?onSort\}/, `sort={${by} === ${k} ? ${dir} : false} onSort={${change} && (() => ${change}(${k}, ${by} === ${k} && ${dir} === "asc" ? "desc" : "asc"))}`);
|
|
1830
|
+
};
|
|
1703
1831
|
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);
|
|
1704
1832
|
const liftedRows = () => {
|
|
1705
1833
|
const first = dataRows[0];
|
|
1706
1834
|
const keys = columnKeys(first.cells.length);
|
|
1707
|
-
const rowsName = mark(ctx,
|
|
1835
|
+
const rowsName = mark(ctx, listName, "rows");
|
|
1836
|
+
// A row is a door to its record when the page passes a handler (U03-7; NODII-DEV-CLI-83).
|
|
1837
|
+
const rowClick = mark(ctx, listName, "onRowClick");
|
|
1708
1838
|
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)`);
|
|
1709
1839
|
const cells = first.cells.map((c, i) => {
|
|
1710
1840
|
const w = columnWidth(c.cell);
|
|
@@ -1721,7 +1851,7 @@ function tableOf(node, ctx) {
|
|
|
1721
1851
|
});
|
|
1722
1852
|
return [
|
|
1723
1853
|
indent(`{${rowsName}.map((row) => (`, depth + 2),
|
|
1724
|
-
indent(
|
|
1854
|
+
indent(`<TableRow key={row.id} onClick={${rowClick} && (() => ${rowClick}(row))}>`, depth + 3),
|
|
1725
1855
|
...cells,
|
|
1726
1856
|
indent("</TableRow>", depth + 3),
|
|
1727
1857
|
indent("))}", depth + 2),
|
|
@@ -1736,7 +1866,7 @@ function tableOf(node, ctx) {
|
|
|
1736
1866
|
? [skeletonRows()]
|
|
1737
1867
|
: kind === "body" && liftable
|
|
1738
1868
|
? liftedRows()
|
|
1739
|
-
: list.flatMap((p) => (p.unrecognised ? [indent(comment(p.unrecognised), depth + 2)] : [indent("<TableRow>", depth + 2), ...p.cells.map((c, i) => cellCode(c, p.row, depth + 3,
|
|
1869
|
+
: list.flatMap((p) => (p.unrecognised ? [indent(comment(p.unrecognised), depth + 2)] : [indent("<TableRow>", depth + 2), ...p.cells.map((c, i) => (p === headRow ? controlSort(cellCode(c, p.row, depth + 3, headKeys[i]), headKeys[i]) : cellCode(c, p.row, depth + 3, null))), indent("</TableRow>", depth + 2)]))),
|
|
1740
1870
|
indent(`</${tag}>`, depth + 1),
|
|
1741
1871
|
];
|
|
1742
1872
|
};
|