@nodii/dev 0.6.195 → 0.6.197
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 +215 -4
- package/package.json +1 -1
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.197";
|
|
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 = 51;
|
|
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
|
|
@@ -644,13 +644,15 @@ export function emitSurface(tree, row, ds) {
|
|
|
644
644
|
const shapes = new Map();
|
|
645
645
|
// The marked identifiers a template lists as optional, and the ones it doesn't (DESIGN-SYSTEM-507).
|
|
646
646
|
const optionals = { optional: new Set(), required: new Set() };
|
|
647
|
+
// Each list the generator assembles from sibling parts (alertRun): its members a page may leave out, and any narrowed type.
|
|
648
|
+
const items = new Map();
|
|
647
649
|
const views = graftAbsentSlots(tree.variants).map((variant) => {
|
|
648
650
|
let state = variant.state;
|
|
649
651
|
while (used.has(state)) state += "-x";
|
|
650
652
|
used.add(state);
|
|
651
653
|
const fn = `${pascal(state)}View`;
|
|
652
654
|
const note = (path, kind, detail) => unmapped.push({ variant: variant.name, path, kind, detail });
|
|
653
|
-
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 }) ?? "";
|
|
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 }) ?? "";
|
|
654
656
|
// A view the generator can't lay out is no page at all: generation fails rather than ship
|
|
655
657
|
// an empty view (NODII-DEV-CLI-81).
|
|
656
658
|
if (emitted.trimStart().startsWith("{/*")) {
|
|
@@ -675,6 +677,12 @@ export function emitSurface(tree, row, ds) {
|
|
|
675
677
|
else if (optionals.required.has(token)) optionalNames.set(name, false);
|
|
676
678
|
}
|
|
677
679
|
for (const [name, optional] of optionalNames) if (optional && data.has(name)) data.get(name).optional = true;
|
|
680
|
+
for (const [token, item] of items) {
|
|
681
|
+
const d = data.get(named.get(token));
|
|
682
|
+
if (!d) continue;
|
|
683
|
+
for (const k of item.optional) d.members.get(k)?.set(OPTIONAL_MEMBER, { optional: true });
|
|
684
|
+
for (const [k, raw] of item.narrow) d.members.get(k)?.set(NARROW_MEMBER, { raw });
|
|
685
|
+
}
|
|
678
686
|
const reactTypes = [data.size && "ComponentProps", [...data.values()].some((d) => /\bReactNode\b/.test(propType(d))) && "ReactNode"].filter(Boolean);
|
|
679
687
|
const drawn = [...data.values()].some((d) => [...d.attrs.values(), ...[...d.members.values()].flatMap((refs) => [...refs.values()])].some((r) => r.keys));
|
|
680
688
|
const header = [
|
|
@@ -1274,6 +1282,9 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
1274
1282
|
if (!ctx.inTable) {
|
|
1275
1283
|
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>`);
|
|
1276
1284
|
}
|
|
1285
|
+
// MetricStatus draws its chip in place of the caption, so a card whose frame shows the
|
|
1286
|
+
// caption hides the chip: it has no chip at all, not an empty one (NODII-DEV-CLI-244).
|
|
1287
|
+
out = rewriteTags(out, "MetricStatus", (attrs) => (/\bcaption=/.test(attrs) ? attrs.replace(/\n?[ \t]*\bchip=\{\{[^{}]*\}\}/, "") : attrs));
|
|
1277
1288
|
out = rewriteTags(out, String.raw`Metric(?!CardGroup\b)[A-Za-z]*`, (attrs, tag) => {
|
|
1278
1289
|
const name = new RegExp(String.raw`\b(?:title|label)=(${LITERAL})`).exec(attrs);
|
|
1279
1290
|
const at = name && nameText(literalText(name[1])) ? nameOf(literalText(name[1])) : scope;
|
|
@@ -1317,6 +1328,15 @@ function liftRecordData(code, node, ctx, path, scope = scopeName(node)) {
|
|
|
1317
1328
|
}
|
|
1318
1329
|
return next;
|
|
1319
1330
|
});
|
|
1331
|
+
// A Chart With Range's series are the page's data, each one's key and label with its points
|
|
1332
|
+
// (generator plan, section a): the template draws two series under Figma's sample labels
|
|
1333
|
+
// ("Email", "SMS"), so a report with three providers showed them under the wrong legend.
|
|
1334
|
+
// The whole array is one prop, typed by the DS's own `series` (NODII-DEV-CLI-222).
|
|
1335
|
+
out = rewriteTags(out, "ChartWithRange", (attrs) => {
|
|
1336
|
+
const at = topLevelAttr(attrs, "series");
|
|
1337
|
+
if (!at) return attrs;
|
|
1338
|
+
return `${attrs.slice(0, at.from)}series={${lift(scope, "series")}}${attrs.slice(at.to)}`;
|
|
1339
|
+
});
|
|
1320
1340
|
out = rewriteTags(out, "PageSizeSelect", (attrs) => attrs.replace(/\bvalue=\{(?:\d+|Number\("(?:[^"\\\n]|\\.)*"\))\}/, () => `value={${lift(scope, "pageSize")}}`));
|
|
1321
1341
|
out = rewriteTags(out, "CopyField", (attrs) => {
|
|
1322
1342
|
const value = new RegExp(String.raw`\bvalue=${LITERAL}`).exec(attrs);
|
|
@@ -1927,6 +1947,30 @@ function bareAttr(attrs, name) {
|
|
|
1927
1947
|
return m ? m.index + m[1].length : null;
|
|
1928
1948
|
}
|
|
1929
1949
|
|
|
1950
|
+
/**
|
|
1951
|
+
* Where an attribute `name={…}` stands in `attrs`, outside strings and other
|
|
1952
|
+
* attributes' braces: { from, to } over the whole `name={…}`, its braces balanced;
|
|
1953
|
+
* else null.
|
|
1954
|
+
*/
|
|
1955
|
+
function topLevelAttr(attrs, name) {
|
|
1956
|
+
const flat = maskStrings(attrs);
|
|
1957
|
+
let depth = 0;
|
|
1958
|
+
for (let i = 0; i < flat.length; i++) {
|
|
1959
|
+
const c = flat[i];
|
|
1960
|
+
if (depth === 0 && flat.startsWith(`${name}={`, i) && (i === 0 || /\s/.test(flat[i - 1]))) {
|
|
1961
|
+
let d = 0;
|
|
1962
|
+
for (let j = i + name.length + 1; j < flat.length; j++) {
|
|
1963
|
+
if (flat[j] === "{") d++;
|
|
1964
|
+
else if (flat[j] === "}" && --d === 0) return { from: i, to: j + 1 };
|
|
1965
|
+
}
|
|
1966
|
+
return null;
|
|
1967
|
+
}
|
|
1968
|
+
if (c === "{") depth++;
|
|
1969
|
+
else if (c === "}") depth--;
|
|
1970
|
+
}
|
|
1971
|
+
return null;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1930
1974
|
/** Tabs the page controls: its tab is a prop, and choosing one calls back (NODII-DEV-CLI-83). */
|
|
1931
1975
|
const CONTROLLED_TABS = (value, onChange) => `<Tabs panelless value={${value}} onValueChange={${onChange}}>`;
|
|
1932
1976
|
|
|
@@ -2455,11 +2499,18 @@ function nestedType(body, at, key) {
|
|
|
2455
2499
|
return null;
|
|
2456
2500
|
}
|
|
2457
2501
|
|
|
2502
|
+
const OPTIONAL_MEMBER = "\u0000optional";
|
|
2503
|
+
const NARROW_MEMBER = "\u0000narrow";
|
|
2458
2504
|
const propType = (d) => {
|
|
2459
2505
|
// A value nested in an object prop is typed by its path from the DS prop (nestedType); `any` only when it has none.
|
|
2460
2506
|
const nested = d.nested ? (d.untyped || !d.nestedTypes?.size ? ["any"] : [...d.nestedTypes]) : [];
|
|
2461
2507
|
const parts = [...[...d.attrs.values()].map(drawnRef), ...(d.child ? ["ReactNode"] : []), ...nested];
|
|
2462
|
-
|
|
2508
|
+
// A member a page may leave out is optional; a narrowed one is typed by its narrowing alone (alertRun).
|
|
2509
|
+
const field = ([k, refs]) => {
|
|
2510
|
+
const types = refs.has(NARROW_MEMBER) ? [refs.get(NARROW_MEMBER)] : [...refs].filter(([id]) => id !== OPTIONAL_MEMBER).map(([, r]) => r);
|
|
2511
|
+
return `${k}${refs.has(OPTIONAL_MEMBER) ? "?" : ""}: ${types.map(drawnRef).join(" & ")}`;
|
|
2512
|
+
};
|
|
2513
|
+
const shape = `{ ${[...d.members.entries()].sort(([a], [b]) => a.localeCompare(b)).map(field).join("; ")} }`;
|
|
2463
2514
|
// A lifted list is an array of its items (NODII-DEV-CLI-82).
|
|
2464
2515
|
if (d.list) parts.push(`Array<${shape}>`);
|
|
2465
2516
|
else if (d.members.size) parts.push(shape);
|
|
@@ -2823,6 +2874,7 @@ function emitChildren(children, emitOne, ctx) {
|
|
|
2823
2874
|
const flush = () => {
|
|
2824
2875
|
if (run.length >= 2 && runKind === "tab") out.push(tabStrip(run, ctx));
|
|
2825
2876
|
else if (run.length >= 2 && runKind === "step") out.push(...stepRun(run, emitOne, ctx));
|
|
2877
|
+
else if (run.length >= 2 && runKind === "alert") out.push(...alertRun(run, emitOne, ctx));
|
|
2826
2878
|
else if (run.length >= 2) out.push(descriptionRun(run, ctx));
|
|
2827
2879
|
else out.push(...run.map(emitOne).filter((x) => x !== null));
|
|
2828
2880
|
run = [];
|
|
@@ -2832,7 +2884,7 @@ function emitChildren(children, emitOne, ctx) {
|
|
|
2832
2884
|
if (c.visible === false) continue;
|
|
2833
2885
|
// Description lists side by side are columns of the layout, each its own list; only a run
|
|
2834
2886
|
// down a column is one list of items (hub-454).
|
|
2835
|
-
const kind = tabOf(c, ctx) ? "tab" : stepOf(c, ctx) ? "step" : !across && descriptionOf(c, ctx) ? `dl${descriptionOf(c, ctx).open}` : null;
|
|
2887
|
+
const kind = alertOf(c) ? "alert" : tabOf(c, ctx) ? "tab" : stepOf(c, ctx) ? "step" : !across && descriptionOf(c, ctx) ? `dl${descriptionOf(c, ctx).open}` : null;
|
|
2836
2888
|
if (kind && kind !== runKind) flush();
|
|
2837
2889
|
if (kind) {
|
|
2838
2890
|
run.push(c);
|
|
@@ -2898,6 +2950,165 @@ function stepRun(run, emitOne, ctx) {
|
|
|
2898
2950
|
return [indent(["<Stepper", " steps={[", ...items, " ]}", ...attrs.map((a) => ` ${a}`), "/>"].join("\n"), ctx.depth)];
|
|
2899
2951
|
}
|
|
2900
2952
|
|
|
2953
|
+
/** A DS Alert instance: a run of two or more siblings is the page's list of alerts (alertRun). */
|
|
2954
|
+
const ALERT_SET = "Alert";
|
|
2955
|
+
/** The DS Alert's tones (alert.tsx), each with its own leading-icon swap in Figma. */
|
|
2956
|
+
const ALERT_TONES = ["default", "info", "success", "warning", "destructive"];
|
|
2957
|
+
const alertOf = (node) => Boolean(node.instance?.remote) && node.instance.set === ALERT_SET && node.visible !== false;
|
|
2958
|
+
|
|
2959
|
+
/** An attribute as JSX, from its literal (tagAttributes): `variant="outline"`, a bare `disabled`, `count={2}`. */
|
|
2960
|
+
const literalAttr = (name, literal) => (literal === "true" ? name : literal.startsWith('"') ? `${name}=${literal}` : `${name}={${literal}}`);
|
|
2961
|
+
|
|
2962
|
+
/**
|
|
2963
|
+
* One Alert as its template draws it, read for what an item of a list of alerts holds:
|
|
2964
|
+
* its tone, its icon, whether it draws a description, and each action button's literal
|
|
2965
|
+
* attributes (at most two buttons, each with plain text). Null when the template draws
|
|
2966
|
+
* anything else (a body, an Icon Button, a button with an icon), so the run stays as drawn.
|
|
2967
|
+
* Emitted as a probe, with no scopes: nothing it names becomes a prop.
|
|
2968
|
+
*/
|
|
2969
|
+
function drawnAlert(node, ctx) {
|
|
2970
|
+
const imports = [];
|
|
2971
|
+
const notes = [];
|
|
2972
|
+
const probe = { ...ctx, depth: 0, bare: true, inTable: false, scopes: null, imports, note: (...n) => notes.push(n) };
|
|
2973
|
+
const code = emitNode(node, probe)?.trim() ?? "";
|
|
2974
|
+
const open = /^<Alert(?: tone="([a-z]+)")?>/.exec(code);
|
|
2975
|
+
if (!open || !code.endsWith("</Alert>") || /<AlertBody\b/.test(code)) return null;
|
|
2976
|
+
let rest = code.slice(open[0].length, -"</Alert>".length);
|
|
2977
|
+
const take = (re) => {
|
|
2978
|
+
const m = re.exec(rest);
|
|
2979
|
+
if (m) rest = rest.slice(0, m.index) + rest.slice(m.index + m[0].length);
|
|
2980
|
+
return m;
|
|
2981
|
+
};
|
|
2982
|
+
const icon = take(/^\s*(<[A-Z][A-Za-z0-9]*(?: [a-z][\w-]*="[^"\n]*")* \/>)/)?.[1] ?? null;
|
|
2983
|
+
if (!take(/^\s*<AlertTitle>[^\n]*?<\/AlertTitle>/)) return null;
|
|
2984
|
+
const description = Boolean(take(/^\s*<AlertDescription>[^\n]*?<\/AlertDescription>/));
|
|
2985
|
+
const action = take(/^\s*<AlertAction>([\s\S]*)<\/AlertAction>/);
|
|
2986
|
+
if (rest.trim()) return null;
|
|
2987
|
+
const buttons = [];
|
|
2988
|
+
if (action) {
|
|
2989
|
+
const found = buttonsIn(action[1]);
|
|
2990
|
+
let left = action[1];
|
|
2991
|
+
for (const b of found) left = left.replace(b.code, "");
|
|
2992
|
+
if (!found.length || found.length > 2 || left.replace(/<>|<\/>/g, "").trim()) return null;
|
|
2993
|
+
for (const b of found) {
|
|
2994
|
+
if (!/^<Button[\s>]/.test(b.code)) return null;
|
|
2995
|
+
const attrs = tagAttributes(b.code, "<Button".length);
|
|
2996
|
+
if (!attrs || attrs.selfClosing) return null;
|
|
2997
|
+
const own = new Map();
|
|
2998
|
+
for (const name of attrs.names) {
|
|
2999
|
+
if (name === "onClick") continue;
|
|
3000
|
+
const literal = attrs.literals.get(name);
|
|
3001
|
+
if (literal === undefined || literal.includes("\\")) return null;
|
|
3002
|
+
own.set(name, literal);
|
|
3003
|
+
}
|
|
3004
|
+
const label = b.code.slice(openTagEnd(b.code) + 1, b.code.lastIndexOf("</Button>")).trim();
|
|
3005
|
+
if (!label || label.includes("<")) return null;
|
|
3006
|
+
buttons.push(own);
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
return { tone: open[1] ?? "default", icon, description, buttons, imports, notes };
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
/**
|
|
3013
|
+
* A run of two or more sibling Alerts is the page's list of alerts (NODII-DEV-CLI-222).
|
|
3014
|
+
* Each Alert drew Figma's sample as copy: its title, its description and its action
|
|
3015
|
+
* ("Payment overdue to A*** N*** (SMS) failed twice." on Notification Overview), so a live
|
|
3016
|
+
* page showed the designer's alerts, always four of them. The run is one prop, `alerts`
|
|
3017
|
+
* (named by its section, as a table's rows are; listScope), drawn with `.map`, each item
|
|
3018
|
+
* `{ id, tone, title, description?, actionLabel?, onAction?, secondaryActionLabel?,
|
|
3019
|
+
* onSecondaryAction? }` typed by the DS parts it reaches. The drawing stays the frame's:
|
|
3020
|
+
* the icon each tone takes, and a button attribute every drawn alert gives alike
|
|
3021
|
+
* (`size="small"`); one the alerts draw differently (`variant`) is the item's own
|
|
3022
|
+
* (`actionVariant`). Tones drawn alike stay literal; tones drawn apart are the item's, each
|
|
3023
|
+
* with the icon the Alert's own per-tone swap gives it (an item's tone is narrowed only to
|
|
3024
|
+
* the tones that have one). Alerts drawn with a body, an icon on some and not others, an
|
|
3025
|
+
* icon that is not its tone's swap, more than two actions, or other sizes stay as drawn. A
|
|
3026
|
+
* lone Alert stays as drawn.
|
|
3027
|
+
*/
|
|
3028
|
+
function alertRun(run, emitOne, ctx) {
|
|
3029
|
+
const asDrawn = () => run.map(emitOne).filter((x) => x !== null);
|
|
3030
|
+
const alerts = run.map((node) => drawnAlert(node, ctx));
|
|
3031
|
+
if (alerts.some((a) => a === null)) return asDrawn();
|
|
3032
|
+
const sizing = run.map((node) => sizeClasses(node, ctx.parent, false));
|
|
3033
|
+
if (new Set(sizing.map((s) => s.join(" "))).size > 1) return asDrawn();
|
|
3034
|
+
if (new Set(alerts.map((a) => a.icon === null)).size > 1) return asDrawn();
|
|
3035
|
+
const drawnTones = [...new Set(alerts.map((a) => a.tone))].sort();
|
|
3036
|
+
const oneTone = drawnTones.length === 1;
|
|
3037
|
+
const iconed = alerts[0].icon !== null;
|
|
3038
|
+
// The icon each tone takes is the Alert's own per-tone swap: the first alert drawn in every
|
|
3039
|
+
// tone, so an item may take a tone the frame doesn't draw. A tone the template draws no icon
|
|
3040
|
+
// for (or doesn't draw) is left out, and the item's tone is narrowed to the tones it can take.
|
|
3041
|
+
const icons = new Map();
|
|
3042
|
+
if (iconed && !oneTone) {
|
|
3043
|
+
for (const tone of ALERT_TONES) {
|
|
3044
|
+
const probe = drawnAlert({ ...run[0], instance: { ...run[0].instance, props: { ...run[0].instance.props, tone } } }, ctx);
|
|
3045
|
+
if (probe?.tone !== tone || probe.icon === null) continue;
|
|
3046
|
+
icons.set(tone, probe.icon);
|
|
3047
|
+
ctx.imports.push(...probe.imports);
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
for (const a of alerts) if (iconed && !oneTone && icons.get(a.tone) !== a.icon) return asDrawn();
|
|
3051
|
+
if (oneTone && new Set(alerts.map((a) => a.icon)).size > 1) return asDrawn();
|
|
3052
|
+
const tones = [...icons.keys()].sort();
|
|
3053
|
+
const optional = new Set();
|
|
3054
|
+
// Each action button by its place: the attributes every alert that draws it gives alike stay drawn.
|
|
3055
|
+
const actions = [0, 1].map((k) => alerts.map((a) => a.buttons[k]).filter(Boolean)).filter((drawn) => drawn.length);
|
|
3056
|
+
const prefixes = ["action", "secondaryAction"];
|
|
3057
|
+
const buttons = actions.map((drawn, k) => {
|
|
3058
|
+
const prefix = prefixes[k];
|
|
3059
|
+
const names = [...new Set(drawn.flatMap((b) => [...b.keys()]))];
|
|
3060
|
+
const attrs = names.map((name) => {
|
|
3061
|
+
const same = drawn.every((b) => b.get(name) === drawn[0].get(name));
|
|
3062
|
+
if (same) return literalAttr(name, drawn[0].get(name));
|
|
3063
|
+
const member = `${prefix}${cap(name)}`;
|
|
3064
|
+
optional.add(member);
|
|
3065
|
+
return `${name}={alert.${member}}`;
|
|
3066
|
+
});
|
|
3067
|
+
const label = `${prefix}Label`;
|
|
3068
|
+
const handler = `on${cap(prefix)}`;
|
|
3069
|
+
optional.add(label).add(handler);
|
|
3070
|
+
return { label, handler, open: `<Button${attrs.map((a) => ` ${a}`).join("")} onClick={alert.${handler}}>` };
|
|
3071
|
+
});
|
|
3072
|
+
// A description is optional in every Alert, drawn or not: one list keeps one shape in every view.
|
|
3073
|
+
optional.add("description");
|
|
3074
|
+
const shape = `alerts:${oneTone ? `${drawnTones[0]}=${alerts[0].icon}` : tones.map((t) => `${t}=${icons.get(t)}`).join(",")}:${buttons.map((b) => b.open).join(",")}`;
|
|
3075
|
+
const scope = listScope(run[0], ctx, "alerts", shape);
|
|
3076
|
+
// A list named by no heading is `alerts`, numbered (`alerts2`) when another list holds the name.
|
|
3077
|
+
const list = mark(ctx, scope, /^alerts\d*$/.test(scope) ? scope : "alerts", null);
|
|
3078
|
+
const iconLine = !iconed ? [] : oneTone ? [alerts[0].icon] : [`{{ ${tones.map((t) => `${t}: ${icons.get(t)}`).join(", ")} }[alert.tone]}`];
|
|
3079
|
+
const toneAttr = oneTone ? (drawnTones[0] === "default" ? "" : ` tone="${drawnTones[0]}"`) : " tone={alert.tone}";
|
|
3080
|
+
const buttonLines = (b) => [b.open, ` {alert.${b.label}}`, "</Button>"];
|
|
3081
|
+
const actionLines = !buttons.length
|
|
3082
|
+
? []
|
|
3083
|
+
: [
|
|
3084
|
+
`{alert.${buttons[0].label} != null && (`,
|
|
3085
|
+
" <AlertAction>",
|
|
3086
|
+
...buttonLines(buttons[0]).map((l) => ` ${l}`),
|
|
3087
|
+
...(buttons[1] ? [` {alert.${buttons[1].label} != null && (`, ...buttonLines(buttons[1]).map((l) => ` ${l}`), " )}"] : []),
|
|
3088
|
+
" </AlertAction>",
|
|
3089
|
+
")}",
|
|
3090
|
+
];
|
|
3091
|
+
const body = [
|
|
3092
|
+
`<Alert${toneAttr}>`,
|
|
3093
|
+
...iconLine.map((l) => ` ${l}`),
|
|
3094
|
+
" <AlertTitle>{alert.title}</AlertTitle>",
|
|
3095
|
+
" {alert.description != null && <AlertDescription>{alert.description}</AlertDescription>}",
|
|
3096
|
+
...actionLines.map((l) => ` ${l}`),
|
|
3097
|
+
"</Alert>",
|
|
3098
|
+
];
|
|
3099
|
+
const item = sizing[0].length ? [`<div key={alert.id} className="${cls(["flex", "flex-col", ...sizing[0]])}">`, ...body.map((l) => ` ${l}`), "</div>"] : [body[0].replace(/^<Alert/, "<Alert key={alert.id}"), ...body.slice(1)];
|
|
3100
|
+
for (const a of alerts) {
|
|
3101
|
+
ctx.imports.push(...a.imports);
|
|
3102
|
+
for (const n of a.notes) if (n[1] !== LIFTED) ctx.note(...n);
|
|
3103
|
+
}
|
|
3104
|
+
// An icon is looked up by its tone, so the item's tone is always one: never null or left out.
|
|
3105
|
+
const tone = 'NonNullable<ComponentProps<typeof Alert>["tone"]>';
|
|
3106
|
+
const narrow = !iconed || oneTone ? null : tones.length < ALERT_TONES.length ? `Extract<${tone}, ${tones.map((t) => JSON.stringify(t)).join(" | ")}>` : tone;
|
|
3107
|
+
ctx.items?.set(list, { optional, narrow: new Map(narrow ? [["tone", narrow]] : []) });
|
|
3108
|
+
ctx.note(ctx.path, LIFTED, `${run.length} sibling Alerts lifted as the page's list of alerts: Figma's sample titles, descriptions and actions are the page's (NODII-DEV-CLI-222)`);
|
|
3109
|
+
return [indent([`{${list}.map((alert) => (`, ...item.map((l) => ` ${l}`), "))}"].join("\n"), ctx.depth)];
|
|
3110
|
+
}
|
|
3111
|
+
|
|
2901
3112
|
const LABEL_FOR = /<Label\b[^>]*?\bhtmlFor=\{([A-Za-z_$][\w$]*)\}/;
|
|
2902
3113
|
const LABELLED_CONTROL = /<(?:Checkbox|Switch|RadioGroupItem|Textarea|Input|SelectField)(?=[\s/>])/;
|
|
2903
3114
|
/**
|