@nodii/dev 0.6.138 → 0.6.140
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 +400 -31
- 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.140";
|
|
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 = 14;
|
|
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,6 +528,8 @@ export function emitSurface(tree, row, ds) {
|
|
|
528
528
|
}
|
|
529
529
|
const used = new Set();
|
|
530
530
|
const scopes = new Map();
|
|
531
|
+
// Each layer a scope names: where it sits and the text that labels it (resolveScopes, hub-468).
|
|
532
|
+
const layers = new Map();
|
|
531
533
|
// Each list's columns by name, across views (listScope).
|
|
532
534
|
const shapes = new Map();
|
|
533
535
|
const views = tree.variants.map((variant) => {
|
|
@@ -536,7 +538,7 @@ export function emitSurface(tree, row, ds) {
|
|
|
536
538
|
used.add(state);
|
|
537
539
|
const fn = `${pascal(state)}View`;
|
|
538
540
|
const note = (path, kind, detail) => unmapped.push({ variant: variant.name, path, kind, detail });
|
|
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 }) ?? "";
|
|
541
|
+
const emitted = emitNode(pageBody(variant, row), { depth: 2, parent: null, path: variant.name, ds, imports, note, root: true, scopes, layers, layer: "", state, lists: new Map(), shapes, handlers: new Map() }) ?? "";
|
|
540
542
|
// A view the generator can't lay out is no page at all: generation fails rather than ship
|
|
541
543
|
// an empty view (NODII-DEV-CLI-81).
|
|
542
544
|
if (emitted.trimStart().startsWith("{/*")) {
|
|
@@ -547,7 +549,7 @@ export function emitSurface(tree, row, ds) {
|
|
|
547
549
|
const component = `${pascal(row.id)}Surface`;
|
|
548
550
|
const stateType = `${component}State`;
|
|
549
551
|
const propsType = `${component}Props`;
|
|
550
|
-
resolveScopes(views, scopes);
|
|
552
|
+
resolveScopes(views, scopes, layers);
|
|
551
553
|
const data = dataProps(views, propsType);
|
|
552
554
|
const reactTypes = [data.size && "ComponentProps", [...data.values()].some((d) => /\bReactNode\b/.test(propType(d))) && "ReactNode"].filter(Boolean);
|
|
553
555
|
const drawn = [...data.values()].some((d) => [...d.attrs.values(), ...[...d.members.values()].flatMap((refs) => [...refs.values()])].some((r) => r.keys));
|
|
@@ -767,11 +769,60 @@ function camelName(text) {
|
|
|
767
769
|
return /^[a-z]/.test(name) ? name : `field${name.replace(/^./, (c) => c.toUpperCase())}`;
|
|
768
770
|
}
|
|
769
771
|
|
|
772
|
+
/**
|
|
773
|
+
* A scope's key: its name and the layer that owns it (hub-468), so two
|
|
774
|
+
* layers that share a scope name never share a prop. A list's scope (listScope)
|
|
775
|
+
* is already its own, and is keyed by its name alone (`layer` null).
|
|
776
|
+
*/
|
|
777
|
+
const scopeKey = (scope, layer) => (layer == null ? scope : `${scope}\u0000${layer}`);
|
|
778
|
+
const scopeIndex = (scopes, key) => (scopes.has(key) ? scopes.get(key) : scopes.set(key, scopes.size).get(key));
|
|
779
|
+
|
|
770
780
|
/** `name` marked with `scope` (`__s<n>_name`), as scopeIdentifiers marks a template's identifiers. */
|
|
771
|
-
function mark(ctx, scope, name) {
|
|
781
|
+
function mark(ctx, scope, name, layer = ctx.layer) {
|
|
772
782
|
if (!ctx.scopes) return name;
|
|
773
|
-
|
|
774
|
-
|
|
783
|
+
return `__s${scopeIndex(ctx.scopes, scopeKey(scope, layer))}_${name}`;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Where a node sits in its view, the same in every view that draws it: its
|
|
788
|
+
* layer names from the view's page down, a name its parent holds twice
|
|
789
|
+
* numbered (`Frame`, `Frame#1`). The view's own name is left out, so the same
|
|
790
|
+
* layer in another state view is the same layer, one prop (hub-468).
|
|
791
|
+
*/
|
|
792
|
+
function layerOf(node, ctx) {
|
|
793
|
+
if (ctx.root) return "";
|
|
794
|
+
const same = (ctx.parent?.children ?? []).filter((c) => c.name === node.name);
|
|
795
|
+
const at = same.indexOf(node);
|
|
796
|
+
return `${ctx.layer ?? ""} › ${node.name}${at > 0 ? `#${at}` : ""}`;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* The text that labels a part: the first text of the nearest sibling before it
|
|
801
|
+
* in its frame, else before its frame (a field's label row above its input).
|
|
802
|
+
* Text that is itself a record's value never labels. Null when it has none.
|
|
803
|
+
*/
|
|
804
|
+
function labelBefore(node, ctx) {
|
|
805
|
+
const firstText = (n) => {
|
|
806
|
+
if (n.visible === false) return null;
|
|
807
|
+
if (n.type === "TEXT") return /[A-Za-z]/.test(n.text ?? "") && !RECORD_TEXT(n.text) ? n.text : null;
|
|
808
|
+
if (n.instance?.remote) return null;
|
|
809
|
+
for (const c of n.children ?? []) {
|
|
810
|
+
const found = firstText(c);
|
|
811
|
+
if (found) return found;
|
|
812
|
+
}
|
|
813
|
+
return null;
|
|
814
|
+
};
|
|
815
|
+
const before = (parent, target) => {
|
|
816
|
+
const shown = (parent?.children ?? []).filter((c) => c.visible !== false);
|
|
817
|
+
const at = shown.indexOf(target);
|
|
818
|
+
if (at <= 0) return null;
|
|
819
|
+
for (const c of shown.slice(0, at).reverse()) {
|
|
820
|
+
const found = firstText(c);
|
|
821
|
+
if (found) return found;
|
|
822
|
+
}
|
|
823
|
+
return null;
|
|
824
|
+
};
|
|
825
|
+
return before(ctx.parent, node) ?? (ctx.grand ? before(ctx.grand, ctx.parent) : null);
|
|
775
826
|
}
|
|
776
827
|
|
|
777
828
|
/** What the generator lifted from Figma's sample into the page's props: listed, not counted (NODII-DEV-CLI-82). */
|
|
@@ -813,10 +864,16 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
813
864
|
out = out.replace(/<(Alert(Title|Description))>(\{"(?:[^"\\\n]|\\.)*"\})<\/\1>/g, (all, tag, part, lit) =>
|
|
814
865
|
SAMPLE_VALUE.test(literalText(lit)) ? `<${tag}>{${lift(camelName(ctx.state ?? "alert"), `alert${part}`)}}</${tag}>` : all,
|
|
815
866
|
);
|
|
816
|
-
// An Empty State's
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
867
|
+
// An Empty State's title, description and action label are the page's: its copy depends on
|
|
868
|
+
// the list and the person ("No pay components yet" or "No custom components yet"), and
|
|
869
|
+
// Figma's sample ("Create item", a record's name) is never it (NODII-DEV-CLI-82, hub-468).
|
|
870
|
+
// They are named by the view's state, the default view's as the list's empty state.
|
|
871
|
+
const emptyScope = camelName(ctx.state && ctx.state !== "default" ? ctx.state : "empty");
|
|
872
|
+
out = rewriteTags(out, "EmptyState", (attrs) => {
|
|
873
|
+
const flat = maskStrings(attrs);
|
|
874
|
+
const topLevel = (at) => [...flat.slice(0, at)].reduce((d, c) => d + (c === "{") - (c === "}"), 0) === 0;
|
|
875
|
+
return attrs.replace(new RegExp(String.raw`(^|\s)(title|description|actionLabel)=(${LITERAL})`, "g"), (a, sp, k, _lit, at) => (topLevel(at) ? `${sp}${k}={${lift(emptyScope, joinName(emptyScope, k))}}` : a));
|
|
876
|
+
});
|
|
820
877
|
// An Input Chip's label is a value the field holds, never copy.
|
|
821
878
|
out = out.replace(/<InputChip\b([^>]*?)(\/?)>/g, (all, attrs, close) => {
|
|
822
879
|
const label = new RegExp(String.raw`\blabel=${LITERAL}`).exec(attrs);
|
|
@@ -849,6 +906,42 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
849
906
|
return `<Badge${toned}>{${lift(at, "label")}}</Badge>`;
|
|
850
907
|
});
|
|
851
908
|
}
|
|
909
|
+
// Every Checkbox and Switch is controlled by the page and named by the text beside it
|
|
910
|
+
// (`pfChecked`, `onPfCheckedChange`): Figma's tick is the sample, never a default, and the
|
|
911
|
+
// template's own `checked` / `onCheckedChange` (DESIGN-SYSTEM-508) never shared (hub-468).
|
|
912
|
+
if (TOGGLE.test(out)) {
|
|
913
|
+
out = rewriteTags(out, "Checkbox|Switch", (attrs) => {
|
|
914
|
+
const rest = attrs
|
|
915
|
+
.replace(new RegExp(String.raw`\s+(?:checked|onCheckedChange)=(?:${LITERAL}|\{[^{}]*\})`, "g"), "")
|
|
916
|
+
.replace(/\s+defaultChecked(?:=\{(?:true|false)\})?(?=[\s/>]|$)/g, "");
|
|
917
|
+
return ` checked={${lift(scope, joinName(scope, "checked"))}} onCheckedChange={${lift(scope, `on${cap(joinName(scope, "checkedChange"))}`)}}${rest}`;
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
// A record's progress, priority and amount, a chip's label and a step's status are the
|
|
921
|
+
// record's, never Figma's sample (hub-468). Each is named by where it sits (its frame,
|
|
922
|
+
// numbered among the same parts there); a step by its title, which is copy; an amount
|
|
923
|
+
// by its own setter (`onChange={setAmountMinor}` → `amountMinor`), so the two pair up.
|
|
924
|
+
const place = () => {
|
|
925
|
+
const same = (ctx.parent?.children ?? []).filter((c) => c.visible !== false && c.instance?.set === node.instance?.set);
|
|
926
|
+
return camelName(`${ctx.parent?.name ?? node.name}${same.length > 1 ? ` ${same.indexOf(node) + 1}` : ""}`);
|
|
927
|
+
};
|
|
928
|
+
out = rewriteTags(out, "Progress", (attrs) => attrs.replace(/(^|\s)value=\{-?\d+(?:\.\d+)?\}/, (a, sp) => `${sp}value={${lift(place(), joinName(place(), "value"))}}`));
|
|
929
|
+
out = rewriteTags(out, "PriorityChip", (attrs) => attrs.replace(new RegExp(String.raw`(^|\s)priority=${LITERAL}`), (a, sp) => `${sp}priority={${lift(place(), joinName(place(), "priority"))}}`));
|
|
930
|
+
out = rewriteTags(out, "CurrencyInput", (attrs) =>
|
|
931
|
+
attrs.replace(/(^|\s)valueMinor=\{-?\d+\}/, (a, sp) => {
|
|
932
|
+
const setter = /\bonChange=\{set([A-Z][A-Za-z0-9]*)\}/.exec(attrs);
|
|
933
|
+
return `${sp}valueMinor={${setter ? `${setter[1][0].toLowerCase()}${setter[1].slice(1)}` : lift(place(), joinName(place(), "valueMinor"))}}`;
|
|
934
|
+
}),
|
|
935
|
+
);
|
|
936
|
+
out = rewriteTags(out, "Stepper", (attrs) =>
|
|
937
|
+
attrs.replace(/(\btitle:\s*("(?:[^"\\\n]|\\.)*")\s*,\s*status:\s*)"[a-z_-]+"/g, (a, head, title) => {
|
|
938
|
+
const step = camelName(JSON.parse(title));
|
|
939
|
+
return `${head}${lift(step, joinName(step, "status"))}`;
|
|
940
|
+
}),
|
|
941
|
+
);
|
|
942
|
+
if (!ctx.inTable) {
|
|
943
|
+
out = out.replace(/^<Chip\b((?:[^>{"]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*\})*)>\s*([^<>{}\n]*[A-Za-z0-9][^<>{}\n]*?)\s*<\/Chip>$/, (all, attrs) => `<Chip${attrs}>{${lift(place(), joinName(place(), "label"))}}</Chip>`);
|
|
944
|
+
}
|
|
852
945
|
out = rewriteTags(out, String.raw`Metric(?!CardGroup\b)[A-Za-z]*`, (attrs, tag) => {
|
|
853
946
|
const name = new RegExp(String.raw`\b(?:title|label)=(${LITERAL})`).exec(attrs);
|
|
854
947
|
const at = name ? camelName(literalText(name[1])) : scope;
|
|
@@ -914,6 +1007,171 @@ function positionScope(node, ctx, kind) {
|
|
|
914
1007
|
return camelName(`${ctx.parent?.name ?? kind} ${kind}${siblings.length > 1 ? ` ${siblings.indexOf(node) + 1}` : ""}`);
|
|
915
1008
|
}
|
|
916
1009
|
|
|
1010
|
+
/**
|
|
1011
|
+
* The parts whose template writes one generic handler, whatever the part does:
|
|
1012
|
+
* a Button's and a DecisionButton's `onClick={onClick}`, an Empty State's
|
|
1013
|
+
* `onAction={onAction}`. An Icon Button's template writes none.
|
|
1014
|
+
*/
|
|
1015
|
+
const HANDLER_ATTR = { Button: "onClick", DecisionButton: "onClick", IconButton: "onClick", EmptyState: "onAction" };
|
|
1016
|
+
|
|
1017
|
+
/**
|
|
1018
|
+
* Every button gets its own handler, named by what it does (hub-464):
|
|
1019
|
+
* `on<label>Click` from its own label (a Button's text, an Empty State's
|
|
1020
|
+
* actionLabel, an aria-label), a DecisionButton's from its decision (Reject is
|
|
1021
|
+
* `onRejectClick`, never Approve's), an Icon Button's from its layer name or
|
|
1022
|
+
* icon, and an Icon Button gets the handler its template leaves out. The name
|
|
1023
|
+
* is marked with the section it sits in (a button a template draws inside
|
|
1024
|
+
* another part, with that part's scope), so two buttons with one label in two
|
|
1025
|
+
* sections become `on<section><label>Click` and the same button in another
|
|
1026
|
+
* view keeps its name (resolveScopes). A second button with one name in one
|
|
1027
|
+
* section of a view is numbered.
|
|
1028
|
+
*/
|
|
1029
|
+
function nameHandlers(code, node, ctx, path, scope) {
|
|
1030
|
+
const top = /^<([A-Za-z]+)/.exec(code)?.[1];
|
|
1031
|
+
return rewriteTags(code, Object.keys(HANDLER_ATTR).join("|"), (attrs, tag, end, at) => {
|
|
1032
|
+
const attr = HANDLER_ATTR[tag];
|
|
1033
|
+
const generic = new RegExp(String.raw`\b${attr}=\{${attr}\}`).exec(attrs);
|
|
1034
|
+
if (!generic && (tag !== "IconButton" || new RegExp(String.raw`\b${attr}=`).test(attrs))) return attrs;
|
|
1035
|
+
const own = at === 0 && tag === top;
|
|
1036
|
+
const label = handlerLabel(tag, attrs, code.slice(end), own ? node : null) ?? (own ? null : scope);
|
|
1037
|
+
if (!label) return attrs;
|
|
1038
|
+
const handler = handlerScope(node, ctx, path, own ? null : scope, label, at);
|
|
1039
|
+
const ref = `${attr}={${mark(ctx, handler.scope, handler.name)}}`;
|
|
1040
|
+
// An Icon Button's template draws no handler: the page's is added (hub-464).
|
|
1041
|
+
return generic ? attrs.replace(generic[0], ref) : attrs.replace(/\s*\/?$/, (close) => ` ${ref}${close}`);
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
/** Text as a handler's words: no figure, at most five words, in camelCase; null when nothing is left. */
|
|
1046
|
+
function handlerWords(text) {
|
|
1047
|
+
const words = (String(text ?? "").match(/[A-Za-z0-9]+/g) ?? []).filter((w) => /[A-Za-z]/.test(w)).slice(0, 5);
|
|
1048
|
+
return words.length ? camelName(words.join(" ")) : null;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* What a button does, as a handler's words: a DecisionButton's decision; an
|
|
1053
|
+
* Empty State's actionLabel; an aria-label; a Button's own text (`after` is the
|
|
1054
|
+
* code after its opening tag); an Icon Button's layer name ("IconBtn · Reassign")
|
|
1055
|
+
* or its icon. `node` is the instance the button is (null for a button a
|
|
1056
|
+
* template draws inside another part).
|
|
1057
|
+
*/
|
|
1058
|
+
function handlerLabel(tag, attrs, after, node) {
|
|
1059
|
+
const literal = (name) => {
|
|
1060
|
+
const m = new RegExp(String.raw`(?:^|\s)${name}=(${LITERAL})`).exec(attrs);
|
|
1061
|
+
return m ? literalText(m[1]) : null;
|
|
1062
|
+
};
|
|
1063
|
+
if (tag === "DecisionButton") return handlerWords((/\bdecision="([a-z_]+)"/.exec(attrs)?.[1] ?? "").replace(/_/g, " "));
|
|
1064
|
+
// An Empty State whose action label the Surface doesn't draw is named by its title.
|
|
1065
|
+
if (tag === "EmptyState") return handlerWords(literal("actionLabel") ?? literal("title"));
|
|
1066
|
+
const aria = handlerWords(literal("aria-label"));
|
|
1067
|
+
if (aria) return aria;
|
|
1068
|
+
if (tag === "IconButton") {
|
|
1069
|
+
const layer = node ? handlerWords(node.name.replace(/^\s*icon ?(?:btn|button)\b[\s·:\-–]*/i, "")) : null;
|
|
1070
|
+
if (layer && layer !== camelName(node.instance?.set ?? "")) return layer;
|
|
1071
|
+
const icon = /\bicon=\{<([A-Z][A-Za-z0-9]*?)(?:Icon)?[\s/>]/.exec(attrs)?.[1];
|
|
1072
|
+
return handlerWords(literal("label")) ?? handlerWords(icon?.replace(/([a-z0-9])([A-Z])/g, "$1 $2"));
|
|
1073
|
+
}
|
|
1074
|
+
if (/\/\s*$/.test(attrs)) return null;
|
|
1075
|
+
const close = after.indexOf(`</${tag}>`);
|
|
1076
|
+
const inner = close === -1 ? "" : after.slice(0, close);
|
|
1077
|
+
const strings = [...inner.matchAll(/\{("(?:[^"\\\n]|\\.)*")\}/g)].map((m) => JSON.parse(m[1]));
|
|
1078
|
+
const bare = inner.replace(/<[^>]*>/g, " ").replace(/\{[^{}]*\}/g, " ").trim();
|
|
1079
|
+
return handlerWords(strings.length ? strings.join(" ") : bare) ?? (node ? handlerWords(node.name.replace(/^\s*button\b[\s·:\-–]*/i, "")) : null);
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* A button's handler `{ scope, name }`: `on<label>Click`, marked with `inner`
|
|
1084
|
+
* (the part a template draws it in), else where it sits: the heading of its
|
|
1085
|
+
* section, else the title of the part before it (a step's Section), else its
|
|
1086
|
+
* nearest named frame (a Toolbar), else the page. A second button of one label
|
|
1087
|
+
* in one place of one view is numbered (`onAdd2Click`); a node emitted again
|
|
1088
|
+
* (a table's cells, a tab strip read twice) keeps its number.
|
|
1089
|
+
*/
|
|
1090
|
+
const UNNAMED_FRAME = /^(?:frame|group|auto ?layout|rectangle|container|slot)(?: \d+)?$/i;
|
|
1091
|
+
function handlerScope(node, ctx, path, inner, label, at) {
|
|
1092
|
+
const chain = ctx.chain ?? [];
|
|
1093
|
+
const frames = [...chain.slice(1)].reverse().filter((c) => c.type !== "SLOT" && !c.instance && /[A-Za-z]/.test(c.name ?? ""));
|
|
1094
|
+
// A frame named as the Surfaces name a place ("Row · Email domain allowlist") is that place.
|
|
1095
|
+
const place = frames.map((c) => /\s·\s*(.*[A-Za-z].*)$/.exec(c.name)?.[1]).find(Boolean);
|
|
1096
|
+
const named = frames.find((c) => !UNNAMED_FRAME.test(c.name.trim()))?.name;
|
|
1097
|
+
const scope = inner ?? camelName(place ?? sectionHeading(node, chain) ?? titleBefore(node, chain) ?? named ?? "page");
|
|
1098
|
+
const name = `on${cap(label)}Click`;
|
|
1099
|
+
if (!ctx.handlers || !ctx.scopes) return { scope, name };
|
|
1100
|
+
const key = `${scope}|${name}`;
|
|
1101
|
+
const seen = ctx.handlers.get(key) ?? ctx.handlers.set(key, []).get(key);
|
|
1102
|
+
// The probes (descriptionOf, tabOf) emit a node with no parent, so its place is read from the chain.
|
|
1103
|
+
const id = `${path}@${node.x},${node.y}:${(chain.at(-1)?.children ?? []).indexOf(node)}#${at}`;
|
|
1104
|
+
const n = seen.includes(id) ? seen.indexOf(id) : seen.push(id) - 1;
|
|
1105
|
+
return { scope, name: n ? `on${cap(label)}${n + 1}Click` : name };
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
/**
|
|
1109
|
+
* The title of the nearest DS part before `target` that has one (a step's
|
|
1110
|
+
* Section, in its "Card · Claim" frame), looking up its frames.
|
|
1111
|
+
*/
|
|
1112
|
+
function titleBefore(target, chain) {
|
|
1113
|
+
const titled = (node) => {
|
|
1114
|
+
if (node.visible === false) return null;
|
|
1115
|
+
if (node.instance?.remote) {
|
|
1116
|
+
// A Section names it `Title`, most parts `title`.
|
|
1117
|
+
const title = Object.entries(node.instance.props ?? {}).find(([k]) => /^title$/i.test(k))?.[1];
|
|
1118
|
+
return typeof title === "string" && /[A-Za-z]/.test(title) ? title : null;
|
|
1119
|
+
}
|
|
1120
|
+
for (const c of node.children ?? []) {
|
|
1121
|
+
const found = titled(c);
|
|
1122
|
+
if (found) return found;
|
|
1123
|
+
}
|
|
1124
|
+
return null;
|
|
1125
|
+
};
|
|
1126
|
+
let cur = target;
|
|
1127
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
1128
|
+
const shown = (chain[i].children ?? []).filter((c) => c.visible !== false);
|
|
1129
|
+
for (const sibling of shown.slice(0, Math.max(shown.indexOf(cur), 0)).reverse()) {
|
|
1130
|
+
const found = titled(sibling);
|
|
1131
|
+
if (found) return found;
|
|
1132
|
+
}
|
|
1133
|
+
cur = chain[i];
|
|
1134
|
+
}
|
|
1135
|
+
return null;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
/** A Checkbox or Switch: on or off is the page's, never Figma's sample (DESIGN-SYSTEM-508, hub-468). */
|
|
1139
|
+
const TOGGLE = /^<(?:Checkbox|Switch)\b/;
|
|
1140
|
+
|
|
1141
|
+
/**
|
|
1142
|
+
* The text a box or switch is named by: the nearest text beside it in its
|
|
1143
|
+
* frame, after it first (a checkbox's label follows it), then before it (a
|
|
1144
|
+
* setting's label leads its switch); else the same beside its frame (a box
|
|
1145
|
+
* held in its own size frame). Null when it has none.
|
|
1146
|
+
*/
|
|
1147
|
+
function textNextTo(node, ctx) {
|
|
1148
|
+
const words = (n) => {
|
|
1149
|
+
if (!n || n.visible === false) return null;
|
|
1150
|
+
if (n.type === "TEXT") return /[A-Za-z]/.test(n.text ?? "") && !RECORD_TEXT(n.text) ? n.text : null;
|
|
1151
|
+
if (n.instance?.remote) return null;
|
|
1152
|
+
for (const c of n.children ?? []) {
|
|
1153
|
+
const found = words(c);
|
|
1154
|
+
if (found) return found;
|
|
1155
|
+
}
|
|
1156
|
+
return null;
|
|
1157
|
+
};
|
|
1158
|
+
const beside = (parent, target) => {
|
|
1159
|
+
const shown = (parent?.children ?? []).filter((c) => c.visible !== false);
|
|
1160
|
+
const at = shown.indexOf(target);
|
|
1161
|
+
if (at === -1) return null;
|
|
1162
|
+
for (const c of shown.slice(at + 1)) {
|
|
1163
|
+
const found = words(c);
|
|
1164
|
+
if (found) return found;
|
|
1165
|
+
}
|
|
1166
|
+
for (const c of shown.slice(0, at).reverse()) {
|
|
1167
|
+
const found = words(c);
|
|
1168
|
+
if (found) return found;
|
|
1169
|
+
}
|
|
1170
|
+
return null;
|
|
1171
|
+
};
|
|
1172
|
+
return beside(ctx.parent, node) ?? (ctx.grand ? beside(ctx.grand, ctx.parent) : null);
|
|
1173
|
+
}
|
|
1174
|
+
|
|
917
1175
|
/** The form controls the page owns: a value it passes and a change it hears (NODII-DEV-CLI-82, -83). */
|
|
918
1176
|
const FIELD_CONTROLS = { Input: "onChange", Textarea: "onChange", SelectField: "onValueChange", RadioGroup: "onValueChange" };
|
|
919
1177
|
|
|
@@ -968,7 +1226,16 @@ function fieldScope(node, ctx, code) {
|
|
|
968
1226
|
* (a select's options), so two filters never share one.
|
|
969
1227
|
*/
|
|
970
1228
|
function liftFieldControls(code, node, ctx, lift) {
|
|
971
|
-
|
|
1229
|
+
// A field's placeholder is the page's too: in a Surface it is the value the frame shows
|
|
1230
|
+
// ("Last 30 days", "K*** M***", "Sep 2026"), and a search box's copy names the list
|
|
1231
|
+
// the page searches (hub-468). Named by the field, as its value is.
|
|
1232
|
+
const placeheld = rewriteTags(code, "Input|Textarea|SelectField", (attrs) => {
|
|
1233
|
+
const placeholder = new RegExp(String.raw`(^|\s)placeholder=${LITERAL}`).exec(attrs);
|
|
1234
|
+
if (!placeholder || [...maskStrings(attrs).slice(0, placeholder.index)].reduce((d, c) => d + (c === "{") - (c === "}"), 0) !== 0) return attrs;
|
|
1235
|
+
const scope = fieldScope(node, ctx, code);
|
|
1236
|
+
return attrs.replace(placeholder[0], `${placeholder[1]}placeholder={${lift(scope, `${scope}Placeholder`)}}`);
|
|
1237
|
+
});
|
|
1238
|
+
return placeheld.replace(/<(Input|Textarea|SelectField|RadioGroup)\b((?:[^>"{]|"(?:[^"\\\n]|\\.)*"|\{[^{}]*(?:\{[^{}]*\}[^{}]*)*\})*?)(\s*\/?)>/g, (all, tag, attrs, close) => {
|
|
972
1239
|
if (/\b(value|onChange|onValueChange)=/.test(attrs) || /\{\.\.\./.test(attrs)) return all;
|
|
973
1240
|
const scope = fieldScope(node, ctx, code);
|
|
974
1241
|
const sep = attrs.includes("\n") ? `\n${/\n(\s*)/.exec(attrs)[1]}` : " ";
|
|
@@ -997,7 +1264,7 @@ function rewriteTags(code, names, fn) {
|
|
|
997
1264
|
if (m.index < last) continue;
|
|
998
1265
|
const from = m.index + m[0].length;
|
|
999
1266
|
const end = m.index + openTagEnd(code.slice(m.index));
|
|
1000
|
-
out += code.slice(last, from) + fn(code.slice(from, end), m[1]);
|
|
1267
|
+
out += code.slice(last, from) + fn(code.slice(from, end), m[1], end, m.index);
|
|
1001
1268
|
last = end;
|
|
1002
1269
|
}
|
|
1003
1270
|
return out + code.slice(last);
|
|
@@ -1020,9 +1287,8 @@ const CONTROLLED_TABS = (value, onChange) => `<Tabs panelless value={${value}} o
|
|
|
1020
1287
|
* scope (`__s<n>_date`); resolveScopes later keeps the plain name or scopes it.
|
|
1021
1288
|
* An identifier already marked (an inner instance's, in a slot) keeps its own.
|
|
1022
1289
|
*/
|
|
1023
|
-
function scopeIdentifiers(code, scope, scopes) {
|
|
1024
|
-
|
|
1025
|
-
const n = scopes.get(scope);
|
|
1290
|
+
function scopeIdentifiers(code, scope, scopes, layer = null) {
|
|
1291
|
+
const n = scopeIndex(scopes, scopeKey(scope, layer));
|
|
1026
1292
|
let out = code;
|
|
1027
1293
|
for (const { at, name } of freeIdentifiers(code).reverse()) out = `${out.slice(0, at)}__s${n}_${name}${out.slice(at + name.length)}`;
|
|
1028
1294
|
return out;
|
|
@@ -1033,18 +1299,105 @@ function scopeIdentifiers(code, scope, scopes) {
|
|
|
1033
1299
|
* Date Picker's `date` and `setDate` under "Expires" become
|
|
1034
1300
|
* `expiresDate` and `setExpiresDate`, so two inputs never share a value, a list
|
|
1035
1301
|
* of options or a setter. An identifier one instance alone emits keeps its name.
|
|
1302
|
+
*
|
|
1303
|
+
* Two layers one view draws whose names still come out the same (two frames
|
|
1304
|
+
* both named "Frame", a filter and a record field both labelled "Setting") are
|
|
1305
|
+
* told apart by what sets them apart in that view: the text that labels each,
|
|
1306
|
+
* else the first of their ancestors whose names differ, else their order
|
|
1307
|
+
* (hub-468). Layers in different views that no view draws together
|
|
1308
|
+
* stay one prop: the same field drawn again in another state view.
|
|
1036
1309
|
*/
|
|
1037
|
-
function resolveScopes(views, scopes) {
|
|
1038
|
-
const
|
|
1310
|
+
function resolveScopes(views, scopes, layers = new Map()) {
|
|
1311
|
+
const keys = [...scopes.keys()].map((k) => {
|
|
1312
|
+
const [scope, layer = null] = k.split("\u0000");
|
|
1313
|
+
return { scope, layer };
|
|
1314
|
+
});
|
|
1039
1315
|
const marked = /__s(\d+)_([a-z][A-Za-z0-9]*)/g;
|
|
1040
|
-
const
|
|
1041
|
-
for (const view of views) for (const m of view.body.matchAll(marked)) (users.get(m[2]) ?? users.set(m[2], new Set()).get(m[2])).add(m[1]);
|
|
1316
|
+
const cap = (s) => s[0].toUpperCase() + s.slice(1);
|
|
1042
1317
|
const scoped = (scope, name) => {
|
|
1043
|
-
const cap = (s) => s[0].toUpperCase() + s.slice(1);
|
|
1044
1318
|
const m = /^(set|on)([A-Z]\w*)$/.exec(name);
|
|
1045
1319
|
return m ? `${m[1]}${cap(scope)}${m[2]}` : `${scope}${cap(name)}`;
|
|
1046
1320
|
};
|
|
1047
|
-
|
|
1321
|
+
// A prefix that tells two layers apart, a word it shares with the name said once.
|
|
1322
|
+
const prefixed = (prefix, name) => {
|
|
1323
|
+
const m = /^(set|on)([A-Z]\w*)$/.exec(name);
|
|
1324
|
+
return m ? `${m[1]}${joinName(cap(prefix), m[2])}` : joinName(prefix, name);
|
|
1325
|
+
};
|
|
1326
|
+
// Which scope names emit each identifier, and each marked token with the views that draw it.
|
|
1327
|
+
const users = new Map();
|
|
1328
|
+
const tokens = new Map();
|
|
1329
|
+
views.forEach((view, v) => {
|
|
1330
|
+
for (const m of view.body.matchAll(marked)) {
|
|
1331
|
+
(users.get(m[2]) ?? users.set(m[2], new Set()).get(m[2])).add(keys[Number(m[1])].scope);
|
|
1332
|
+
const t = tokens.get(m[0]) ?? tokens.set(m[0], { n: Number(m[1]), name: m[2], views: new Set() }).get(m[0]);
|
|
1333
|
+
t.views.add(v);
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
const named = new Map();
|
|
1337
|
+
const byName = new Map();
|
|
1338
|
+
for (const [token, t] of tokens) {
|
|
1339
|
+
const plain = users.get(t.name).size > 1 ? scoped(keys[t.n].scope, t.name) : t.name;
|
|
1340
|
+
named.set(token, plain);
|
|
1341
|
+
const owners = byName.get(plain) ?? byName.set(plain, new Map()).get(plain);
|
|
1342
|
+
const layer = keys[t.n].layer ?? `\u0000${keys[t.n].scope}`;
|
|
1343
|
+
const o = owners.get(layer) ?? owners.set(layer, { tokens: [], views: new Set() }).get(layer);
|
|
1344
|
+
o.tokens.push(token);
|
|
1345
|
+
for (const v of t.views) o.views.add(v);
|
|
1346
|
+
}
|
|
1347
|
+
const taken = new Set(byName.keys());
|
|
1348
|
+
for (const [plain, owners] of byName) {
|
|
1349
|
+
const list = [...owners.entries()].map(([layer, o]) => ({ layer, ...o }));
|
|
1350
|
+
// Each view's layers of this name: only two in one view are a clash.
|
|
1351
|
+
const together = views.map((_, v) => list.filter((o) => o.views.has(v)));
|
|
1352
|
+
if (!together.some((inView) => inView.length > 1)) continue;
|
|
1353
|
+
const prefixes = distinguish(list, together, layers);
|
|
1354
|
+
list.forEach((o, i) => {
|
|
1355
|
+
const prefix = prefixes[i];
|
|
1356
|
+
let name = prefix === "" ? plain : prefixed(prefix, plain);
|
|
1357
|
+
if (name !== plain && taken.has(name) && !list.some((x, j) => j < i && prefixes[j] === prefix)) for (let k = 2; taken.has(name); k++) name = `${name.replace(/\d+$/, "")}${k}`;
|
|
1358
|
+
taken.add(name);
|
|
1359
|
+
for (const token of o.tokens) named.set(token, name);
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
for (const view of views) view.body = view.body.replace(marked, (token) => named.get(token));
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
/** `scope` then `name` in camelCase, a word they share at the join said once (`recordSwitcherScope` + `ScopeValue`). */
|
|
1366
|
+
function joinName(scope, name) {
|
|
1367
|
+
const head = name[0].toUpperCase() + name.slice(1);
|
|
1368
|
+
const last = /[A-Z][a-z0-9]*$|^[a-z][a-z0-9]*$/.exec(scope)?.[0] ?? "";
|
|
1369
|
+
const first = /^[A-Z][a-z0-9]*/.exec(head)[0];
|
|
1370
|
+
return last && last.toLowerCase() === first.toLowerCase() ? `${scope}${head.slice(first.length)}` : `${scope}${head}`;
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
/**
|
|
1374
|
+
* What tells apart the layers that share one name, one camelCase prefix each:
|
|
1375
|
+
* the first level at which every view's layers differ, nearest first, of the
|
|
1376
|
+
* text that labels each (`Last reviewed`), then their ancestors (`Card · RSVP`
|
|
1377
|
+
* and `Replies`); a name that differs only by its number among siblings, or
|
|
1378
|
+
* that carries a figure (Figma's sample, "14 filled"), tells nothing. Layers no
|
|
1379
|
+
* view draws together may share a prefix (one prop). When no level does, each
|
|
1380
|
+
* takes its order in the first view that draws it ("", "second", …).
|
|
1381
|
+
*/
|
|
1382
|
+
const ORDINALS = ["", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth"];
|
|
1383
|
+
function distinguish(list, together, layers) {
|
|
1384
|
+
const levels = list.map((o) => {
|
|
1385
|
+
const info = layers.get(o.layer);
|
|
1386
|
+
return [info?.label ?? null, ...(info?.segments ?? []).slice(0, -1).reverse()];
|
|
1387
|
+
});
|
|
1388
|
+
const depth = Math.max(...levels.map((l) => l.length));
|
|
1389
|
+
for (let d = 0; d < depth; d++) {
|
|
1390
|
+
const at = levels.map((l) => (l[d] && !RECORD_TEXT(l[d]) ? camelName(l[d]) : null));
|
|
1391
|
+
const fits = together.every((inView) => {
|
|
1392
|
+
if (inView.length < 2) return true;
|
|
1393
|
+
const names = inView.map((o) => at[list.indexOf(o)]);
|
|
1394
|
+
return names.every((x) => x && !/^field/.test(x)) && new Set(names).size === names.length;
|
|
1395
|
+
});
|
|
1396
|
+
if (fits) return at.map((x) => x ?? "");
|
|
1397
|
+
}
|
|
1398
|
+
const order = list.map(() => null);
|
|
1399
|
+
for (const inView of together) inView.forEach((o, k) => (order[list.indexOf(o)] ??= ORDINALS[k] ?? `item${k + 1}`));
|
|
1400
|
+
return order.map((x) => x ?? "");
|
|
1048
1401
|
}
|
|
1049
1402
|
|
|
1050
1403
|
function dataProps(views, propsType) {
|
|
@@ -1360,6 +1713,12 @@ const comment = (text) => `{/* ${text.replace(/\*\//g, "* /")} */}`;
|
|
|
1360
1713
|
|
|
1361
1714
|
function emitNode(node, ctx) {
|
|
1362
1715
|
if (node.visible === false) return null;
|
|
1716
|
+
// A tab probe (tabOf) emits a child with no parent, to read its template: it never names a layer.
|
|
1717
|
+
if (ctx.scopes && !ctx.tabProbe) {
|
|
1718
|
+
const layer = layerOf(node, ctx);
|
|
1719
|
+
if (!ctx.layers.has(layer)) ctx.layers.set(layer, { segments: layer.split(" › ").slice(1).map((s) => s.replace(/#\d+$/, "")), label: labelBefore(node, ctx) });
|
|
1720
|
+
ctx = { ...ctx, layer };
|
|
1721
|
+
}
|
|
1363
1722
|
const { ds, note, depth, parent, root } = ctx;
|
|
1364
1723
|
const path = root ? ctx.path : `${ctx.path} › ${node.name}`;
|
|
1365
1724
|
// Every node's ancestors, nearest last: a list is named by the section heading before it (hub-454).
|
|
@@ -1394,7 +1753,7 @@ function emitNode(node, ctx) {
|
|
|
1394
1753
|
return comment(`unmapped: slot ${JSON.stringify(prop)} has no auto layout`);
|
|
1395
1754
|
}
|
|
1396
1755
|
const textOwner = TEXT_PROPERTY_PARTS.has(node.instance.set) ? node.instance.set : ctx.textOwner;
|
|
1397
|
-
const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, chain: slotNode ? [...chain, slotNode] : chain };
|
|
1756
|
+
const slotCtx = { ...ctx, depth: 0, parent: slotNode, grand: null, path: `${path} › ${prop}`, root: false, textOwner, inTable: false, chain: slotNode ? [...chain, slotNode] : chain, layer: `${ctx.layer} › ${prop}` };
|
|
1398
1757
|
const inner = emitChildren(slotNode?.children ?? [], (c) => emitNode(c, slotCtx), slotCtx);
|
|
1399
1758
|
return inner.length === 0 ? "<></>" : inner.length === 1 ? inner[0] : `<>\n${inner.map((x) => indent(x, 1)).join("\n")}\n</>`;
|
|
1400
1759
|
};
|
|
@@ -1411,9 +1770,11 @@ function emitNode(node, ctx) {
|
|
|
1411
1770
|
// A tab strip the page controls (tabOf reads the template's own strip first, to gather a run).
|
|
1412
1771
|
if (!ctx.tabProbe) own = own.replace(/<Tabs panelless(?: defaultValue="[^"]*")?>/g, CONTROLLED_TABS("tab", "onTabChange"));
|
|
1413
1772
|
const control = /^<(?:Input|Textarea|SelectField)\b/.test(own.replace(/^<Field\b[^>]*>\s*/, ""));
|
|
1414
|
-
const
|
|
1773
|
+
const toggle = TOGGLE.test(own) ? textNextTo(node, ctx) : null;
|
|
1774
|
+
const scope = control ? fieldScope(node, ctx, own) : toggle ? camelName(toggle) : scopeName(node, own, ctx);
|
|
1775
|
+
own = nameHandlers(own, node, ctx, path, scope);
|
|
1415
1776
|
own = controlHalfControlled(liftRecordData(own, node, ctx, path, scope));
|
|
1416
|
-
const code = ctx.scopes ? scopeIdentifiers(own, scope, ctx.scopes) : own;
|
|
1777
|
+
const code = ctx.scopes ? scopeIdentifiers(own, scope, ctx.scopes, ctx.layer) : own;
|
|
1417
1778
|
// A Table part is valid only inside the DS Table. One the generator could not assemble
|
|
1418
1779
|
// into a Table stays reported, never passed off as mapped (MW8-17.3).
|
|
1419
1780
|
const tag = /^<([A-Za-z]+)/.exec(code)?.[1];
|
|
@@ -1539,7 +1900,7 @@ function descriptionRun(run, ctx) {
|
|
|
1539
1900
|
const { depth, path } = ctx;
|
|
1540
1901
|
const { open, imports } = descriptionOf(run[0], ctx);
|
|
1541
1902
|
ctx.imports.push(...imports);
|
|
1542
|
-
const items = mark(ctx, listScope(run[0], ctx, scopeName(ctx.parent ?? { name: "items" })), "items");
|
|
1903
|
+
const items = mark(ctx, listScope(run[0], ctx, scopeName(ctx.parent ?? { name: "items" })), "items", null);
|
|
1543
1904
|
ctx.note(path, LIFTED, `${run.length} sibling Description Lists lifted as one list of items (NODII-DEV-CLI-82)`);
|
|
1544
1905
|
const list = [
|
|
1545
1906
|
`<DescriptionList${open}>`,
|
|
@@ -1582,7 +1943,7 @@ function tabStrip(run, ctx) {
|
|
|
1582
1943
|
const triggers = tabs.map((t, i) => indent(t.trigger.replace(/(<TabsTrigger\b[\s\S]*?)\bvalue="tab"/, `$1value="${values[i]}"`), 2));
|
|
1583
1944
|
return [
|
|
1584
1945
|
// The page controls which tab is shown (NODII-DEV-CLI-83); Figma's selected tab is only the drawn one.
|
|
1585
|
-
indent(CONTROLLED_TABS(mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "tab"), mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "onTabChange")), depth),
|
|
1946
|
+
indent(CONTROLLED_TABS(mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "tab", null), mark(ctx, scopeName(ctx.parent ?? { name: "tabs" }), "onTabChange", null)), depth),
|
|
1586
1947
|
indent(" <TabsList>", depth),
|
|
1587
1948
|
...triggers.map((t) => indent(t, depth)),
|
|
1588
1949
|
indent(" </TabsList>", depth),
|
|
@@ -1651,6 +2012,10 @@ function openTagEnd(code) {
|
|
|
1651
2012
|
}
|
|
1652
2013
|
return code.length - 1;
|
|
1653
2014
|
}
|
|
2015
|
+
/** The copy a Table head shows until a Surface sets it: Figma's placeholder, never a column's name (hub-468). */
|
|
2016
|
+
const HEAD_PLACEHOLDER = /^\s*table heading\s*$/i;
|
|
2017
|
+
const HEAD_PLACEHOLDER_CHILD = /(<Table(?:Sort)?Head\b[^\n]*>\s*)\{"\s*[Tt]able heading\s*"\}/;
|
|
2018
|
+
|
|
1654
2019
|
function tableOf(node, ctx) {
|
|
1655
2020
|
const shown = (node.children ?? []).filter((c) => c.visible !== false);
|
|
1656
2021
|
// What follows the rows (a table's Empty State, bare or in its own frame) follows the Table:
|
|
@@ -1807,7 +2172,8 @@ function tableOf(node, ctx) {
|
|
|
1807
2172
|
for (let i = 0; i < count; i++) {
|
|
1808
2173
|
const head = headRow?.cells[i];
|
|
1809
2174
|
const text = head?.code ? (/\{"((?:[^"\\\n]|\\.)*)"\}/.exec(head.code)?.[1] ?? /\blabel="([^"]*)"/.exec(head.code)?.[1] ?? "") : "";
|
|
1810
|
-
|
|
2175
|
+
// Figma's placeholder copy ("Table heading") names no column: it is keyed by position.
|
|
2176
|
+
let key = /[A-Za-z0-9]/.test(text) && !HEAD_PLACEHOLDER.test(text) ? camelName(text) : `column${i + 1}`;
|
|
1811
2177
|
while (keys.includes(key) || key === "id") key = `${key}${i + 1}`;
|
|
1812
2178
|
keys.push(key);
|
|
1813
2179
|
}
|
|
@@ -1822,19 +2188,22 @@ function tableOf(node, ctx) {
|
|
|
1822
2188
|
// drawn sort="asc" are Figma's sample.
|
|
1823
2189
|
const controlSort = (code, key) => {
|
|
1824
2190
|
if (!key || !/^\s*<TableSortHead\b/.test(code ?? "")) return code;
|
|
1825
|
-
const [by, dir, change] = ["sortBy", "sortDir", "onSortChange"].map((n) => mark(ctx, listName, n));
|
|
2191
|
+
const [by, dir, change] = ["sortBy", "sortDir", "onSortChange"].map((n) => mark(ctx, listName, n, null));
|
|
1826
2192
|
const k = JSON.stringify(key);
|
|
1827
2193
|
return code
|
|
1828
2194
|
.replace(/(<TableSortHead\b[^>]*?) sort="(?:asc|desc)"/, "$1")
|
|
1829
2195
|
.replace(/\bonSort=\{(?:__s\d+_)?onSort\}/, `sort={${by} === ${k} ? ${dir} : false} onSort={${change} && (() => ${change}(${k}, ${by} === ${k} && ${dir} === "asc" ? "desc" : "asc"))}`);
|
|
1830
2196
|
};
|
|
2197
|
+
// A head that still shows Figma's placeholder copy draws no header the page can read:
|
|
2198
|
+
// its copy is a prop, named by its column, in the list's scope (hub-468).
|
|
2199
|
+
const liftHeading = (code, key) => (key ? code.replace(HEAD_PLACEHOLDER_CHILD, (_, open) => `${open}{${mark(ctx, listName, `${key}Heading`, null)}}`) : code);
|
|
1831
2200
|
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);
|
|
1832
2201
|
const liftedRows = () => {
|
|
1833
2202
|
const first = dataRows[0];
|
|
1834
2203
|
const keys = columnKeys(first.cells.length);
|
|
1835
|
-
const rowsName = mark(ctx, listName, "rows");
|
|
2204
|
+
const rowsName = mark(ctx, listName, "rows", null);
|
|
1836
2205
|
// 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");
|
|
2206
|
+
const rowClick = mark(ctx, listName, "onRowClick", null);
|
|
1838
2207
|
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)`);
|
|
1839
2208
|
const cells = first.cells.map((c, i) => {
|
|
1840
2209
|
const w = columnWidth(c.cell);
|
|
@@ -1866,7 +2235,7 @@ function tableOf(node, ctx) {
|
|
|
1866
2235
|
? [skeletonRows()]
|
|
1867
2236
|
: kind === "body" && liftable
|
|
1868
2237
|
? liftedRows()
|
|
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)]))),
|
|
2238
|
+
: list.flatMap((p) => (p.unrecognised ? [indent(comment(p.unrecognised), depth + 2)] : [indent("<TableRow>", depth + 2), ...p.cells.map((c, i) => (p === headRow ? liftHeading(controlSort(cellCode(c, p.row, depth + 3, headKeys[i]), headKeys[i]), headKeys[i]) : cellCode(c, p.row, depth + 3, null))), indent("</TableRow>", depth + 2)]))),
|
|
1870
2239
|
indent(`</${tag}>`, depth + 1),
|
|
1871
2240
|
];
|
|
1872
2241
|
};
|