@asteby/metacore-genui 2.1.0 → 2.2.0

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.
Files changed (44) hide show
  1. package/README.md +40 -6
  2. package/dist/diagram.d.ts +34 -0
  3. package/dist/diagram.d.ts.map +1 -0
  4. package/dist/diagram.js +103 -0
  5. package/dist/diagram.js.map +1 -0
  6. package/dist/generated/genui-v2-schema.d.ts +387 -30
  7. package/dist/generated/genui-v2-schema.d.ts.map +1 -1
  8. package/dist/generated/genui-v2-schema.js +511 -32
  9. package/dist/generated/genui-v2-schema.js.map +1 -1
  10. package/dist/generated/genui-v2.d.ts +346 -2
  11. package/dist/generated/genui-v2.d.ts.map +1 -1
  12. package/dist/generative-ui.d.ts +11 -1
  13. package/dist/generative-ui.d.ts.map +1 -1
  14. package/dist/generative-ui.js +3 -3
  15. package/dist/generative-ui.js.map +1 -1
  16. package/dist/index.d.ts +7 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +8 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/map-points.d.ts +31 -0
  21. package/dist/map-points.d.ts.map +1 -0
  22. package/dist/map-points.js +60 -0
  23. package/dist/map-points.js.map +1 -0
  24. package/dist/markdown.d.ts +13 -0
  25. package/dist/markdown.d.ts.map +1 -0
  26. package/dist/markdown.js +63 -0
  27. package/dist/markdown.js.map +1 -0
  28. package/dist/metric.d.ts +12 -0
  29. package/dist/metric.d.ts.map +1 -0
  30. package/dist/metric.js +80 -0
  31. package/dist/metric.js.map +1 -0
  32. package/dist/registry.d.ts +69 -0
  33. package/dist/registry.d.ts.map +1 -0
  34. package/dist/registry.js +49 -0
  35. package/dist/registry.js.map +1 -0
  36. package/dist/render-v2.d.ts +23 -0
  37. package/dist/render-v2.d.ts.map +1 -0
  38. package/dist/render-v2.js +166 -0
  39. package/dist/render-v2.js.map +1 -0
  40. package/dist/validate-v2.d.ts.map +1 -1
  41. package/dist/validate-v2.js +48 -1
  42. package/dist/validate-v2.js.map +1 -1
  43. package/package.json +2 -2
  44. package/schema/genui-v2.schema.json +443 -32
@@ -0,0 +1,60 @@
1
+ export const MAP_MAX_POINTS = 200;
2
+ const TONES = new Set(['default', 'muted', 'info', 'success', 'warning', 'danger']);
3
+ const DEFAULT_FIELDS = { key: 'id', lat: 'lat', lng: 'lng', label: 'name', status: 'status', group: 'group', tone: 'tone' };
4
+ /**
5
+ * The points of a `map` block, from its inline `points` or from the rows of its
6
+ * `source` through `fields` (column mapping). Rows with invalid coordinates are
7
+ * dropped; the count is clamped to the block limit (data never widens a block).
8
+ * Tone of a point: its own `tone`, else `status_tones[status]`.
9
+ */
10
+ export function normalizeMapPoints(block, rows, text = (v) => String(v ?? '')) {
11
+ const tones = (block.status_tones ?? {});
12
+ const toneOf = (status, own) => {
13
+ if (typeof own === 'string' && TONES.has(own))
14
+ return own;
15
+ return status !== undefined && Object.hasOwn(tones, status) ? tones[status] : undefined;
16
+ };
17
+ const out = [];
18
+ if (Array.isArray(block.points)) {
19
+ for (const p of block.points) { // eslint-disable-line @typescript-eslint/no-explicit-any
20
+ out.push({
21
+ key: p.key, lat: p.lat, lng: p.lng, label: text(p.label), status: p.status, group: p.group, tone: toneOf(p.status, p.tone),
22
+ details: (p.details ?? []).map((d) => ({ label: d.label === undefined ? undefined : text(d.label), value: text(d.value) })),
23
+ });
24
+ }
25
+ return out.slice(0, MAP_MAX_POINTS);
26
+ }
27
+ const f = { ...DEFAULT_FIELDS, ...(block.fields ?? {}) };
28
+ const mapped = new Set(Object.values(f));
29
+ for (const r of rows ?? []) {
30
+ const lat = Number(r[f.lat]);
31
+ const lng = Number(r[f.lng]);
32
+ if (!Number.isFinite(lat) || !Number.isFinite(lng) || Math.abs(lat) > 90 || Math.abs(lng) > 180)
33
+ continue;
34
+ const status = r[f.status] === undefined || r[f.status] === null ? undefined : String(r[f.status]);
35
+ const label = String(r[f.label] ?? r[f.key] ?? '');
36
+ out.push({
37
+ key: String(r[f.key] ?? `${lat},${lng}`), lat, lng, label, status,
38
+ group: r[f.group] === undefined || r[f.group] === null ? undefined : String(r[f.group]),
39
+ tone: toneOf(status, r[f.tone]),
40
+ details: Object.entries(r).filter(([k, v]) => !mapped.has(k) && v !== null && v !== undefined && typeof v !== 'object').slice(0, 8).map(([k, v]) => ({ label: k, value: String(v) })),
41
+ });
42
+ if (out.length >= MAP_MAX_POINTS)
43
+ break;
44
+ }
45
+ return out;
46
+ }
47
+ /** Legend entries: one per distinct `group_by` value (status by default), in first-seen order. */
48
+ export function mapLegend(points, groupBy = 'status') {
49
+ const seen = new Map();
50
+ for (const p of points) {
51
+ const v = (groupBy === 'group' ? p.group : p.status) ?? '—';
52
+ const e = seen.get(v);
53
+ if (e)
54
+ e.count++;
55
+ else
56
+ seen.set(v, { value: v, count: 1, tone: p.tone });
57
+ }
58
+ return [...seen.values()];
59
+ }
60
+ //# sourceMappingURL=map-points.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"map-points.js","sourceRoot":"","sources":["../src/map-points.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;AAEjC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAA;AACnF,MAAM,cAAc,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAW,CAAA;AAEpI;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAiB,EAAE,IAAiB,EAAE,OAA+B,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAC5H,MAAM,KAAK,GAAG,CAAC,KAAK,CA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AAC,MAAM,CAAC,IAAI,GAAG,CAAA;QAC3D,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QACrB,IAAI,CAAC;YAAE,CAAC,CAAC,KAAK,EAAE,CAAA;;YACX,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;IACxD,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAA;AAC3B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type ReactNode } from 'react';
2
+ /**
3
+ * Safe markdown subset parsed to React nodes: paragraphs, bold, italic, inline
4
+ * code, bullet/numbered lists, h3/h4 and links. No HTML (text is always a React
5
+ * child), no images, no tables. Links must pass `isSafeLink`; external ones also
6
+ * need `allowExternalLinks`. There is no `dangerouslySetInnerHTML` anywhere.
7
+ */
8
+ export interface MarkdownOptions {
9
+ allowExternalLinks?: boolean;
10
+ onNavigate?: (path: string) => void;
11
+ }
12
+ export declare function renderMarkdown(source: string, o?: MarkdownOptions): ReactNode;
13
+ //# sourceMappingURL=markdown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAGhD;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;CACpC;AAoCD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAAE,eAAoB,GAAG,SAAS,CA4BjF"}
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment } from 'react';
3
+ import { isSafeLink } from './validate';
4
+ const INLINE = /(\*\*([^*]+)\*\*|\*([^*\s][^*]*)\*|_([^_\s][^_]*)_|`([^`]+)`|\[([^\]]+)\]\(([^)\s]+)\))/g;
5
+ function inline(text, o, keyBase) {
6
+ const out = [];
7
+ let last = 0;
8
+ let n = 0;
9
+ for (const m of text.matchAll(INLINE)) {
10
+ const at = m.index ?? 0;
11
+ if (at > last)
12
+ out.push(text.slice(last, at));
13
+ const key = `${keyBase}-${n++}`;
14
+ if (m[2] !== undefined)
15
+ out.push(_jsx("strong", { children: m[2] }, key));
16
+ else if (m[3] !== undefined || m[4] !== undefined)
17
+ out.push(_jsx("em", { children: m[3] ?? m[4] }, key));
18
+ else if (m[5] !== undefined)
19
+ out.push(_jsx("code", { className: 'rounded bg-muted px-1 py-0.5 text-[0.85em]', children: m[5] }, key));
20
+ else {
21
+ const label = m[6];
22
+ const href = m[7];
23
+ const local = href.startsWith('/');
24
+ if (!isSafeLink(href) || (!local && !o.allowExternalLinks))
25
+ out.push(label);
26
+ else if (local) {
27
+ out.push(_jsx("a", { href: href, className: 'underline underline-offset-2', onClick: (e) => { if (o.onNavigate) {
28
+ e.preventDefault();
29
+ o.onNavigate(href);
30
+ } }, children: label }, key));
31
+ }
32
+ else {
33
+ out.push(_jsx("a", { href: href, target: '_blank', rel: 'noopener noreferrer nofollow', className: 'underline underline-offset-2', children: label }, key));
34
+ }
35
+ }
36
+ last = at + m[0].length;
37
+ }
38
+ if (last < text.length)
39
+ out.push(text.slice(last));
40
+ return out;
41
+ }
42
+ export function renderMarkdown(source, o = {}) {
43
+ const blocks = source.replace(/\r\n?/g, '\n').split(/\n{2,}/);
44
+ return blocks.map((raw, i) => {
45
+ const chunk = raw.trim();
46
+ if (!chunk)
47
+ return null;
48
+ const key = `b${i}`;
49
+ const h = /^(#{3,4})\s+(.+)$/.exec(chunk);
50
+ if (h && !chunk.includes('\n')) {
51
+ return h[1].length === 3 ? _jsx("h3", { className: 'm-0 text-sm font-semibold', children: inline(h[2], o, key) }, key) : _jsx("h4", { className: 'm-0 text-sm font-medium', children: inline(h[2], o, key) }, key);
52
+ }
53
+ const lines = chunk.split('\n');
54
+ if (lines.every((l) => /^\s*[-*]\s+/.test(l))) {
55
+ return _jsx("ul", { className: 'm-0 list-disc pl-5 text-sm', children: lines.map((l, j) => _jsx("li", { children: inline(l.replace(/^\s*[-*]\s+/, ''), o, `${key}-${j}`) }, j)) }, key);
56
+ }
57
+ if (lines.every((l) => /^\s*\d+[.)]\s+/.test(l))) {
58
+ return _jsx("ol", { className: 'm-0 list-decimal pl-5 text-sm', children: lines.map((l, j) => _jsx("li", { children: inline(l.replace(/^\s*\d+[.)]\s+/, ''), o, `${key}-${j}`) }, j)) }, key);
59
+ }
60
+ return (_jsx("p", { className: 'm-0 text-sm', children: lines.map((l, j) => (_jsxs(Fragment, { children: [j > 0 ? _jsx("br", {}) : null, inline(l, o, `${key}-${j}`)] }, j))) }, key));
61
+ });
62
+ }
63
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/markdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAavC,MAAM,MAAM,GAAG,0FAA0F,CAAA;AAEzG,SAAS,MAAM,CAAC,IAAY,EAAE,CAAkB,EAAE,OAAe;IAC/D,MAAM,GAAG,GAAgB,EAAE,CAAA;IAC3B,IAAI,IAAI,GAAG,CAAC,CAAA;IACZ,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAA;QACvB,IAAI,EAAE,GAAG,IAAI;YAAE,GAAG,CAAC,IA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C,EAAE,CAAC,EAAE,EAAE,CAAC,CACnB,MAAC,QAAQ,eACN,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,cAAM,CAAC,CAAC,CAAC,IAAI,EACrB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,EAAE,CAAC,KAFf,CAAC,CAGL,CACZ,CAAC,IANI,GAAG,CAOP,CACL,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { GenUIBlockRendererProps } from './registry';
2
+ import type { Tone } from './types';
3
+ /** Formats a metric value with Intl (no host dependency). Unknown shapes print as text. */
4
+ export declare function formatMetric(value: unknown, format: string | undefined, locale?: string, currency?: string): string;
5
+ /** Tone of a value from its thresholds: the highest `at` the value reaches wins; otherwise the block's own tone. */
6
+ export declare function toneFor(value: unknown, thresholds: Array<{
7
+ at: number;
8
+ tone: Tone;
9
+ }> | undefined, base?: Tone): Tone;
10
+ /** `metric` block: one KPI with trend, severity thresholds and an optional sparkline. */
11
+ export declare function MetricBlock({ block, rows, text, locale, currency }: GenUIBlockRendererProps): import("react").JSX.Element;
12
+ //# sourceMappingURL=metric.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metric.d.ts","sourceRoot":"","sources":["../src/metric.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAEzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAKnC,2FAA2F;AAC3F,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,SAAQ,GAAG,MAAM,CA4BlH;AAED,oHAAoH;AACpH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,GAAG,SAAS,EAAE,IAAI,GAAE,IAAgB,GAAG,IAAI,CAO/H;AAiBD,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,uBAAuB,+BAqC3F"}
package/dist/metric.js ADDED
@@ -0,0 +1,80 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ArrowDownRight, ArrowRight, ArrowUpRight } from 'lucide-react';
3
+ import { cn } from '@asteby/metacore-ui';
4
+ import { TEXT_TONE } from './generative-ui';
5
+ const TREND_ICON = { up: ArrowUpRight, down: ArrowDownRight, flat: ArrowRight };
6
+ const TREND_LABEL = { up: 'al alza', down: 'a la baja', flat: 'estable' };
7
+ /** Formats a metric value with Intl (no host dependency). Unknown shapes print as text. */
8
+ export function formatMetric(value, format, locale, currency = 'MXN') {
9
+ if (value === null || value === undefined)
10
+ return '—';
11
+ const n = typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' && Number.isFinite(Number(value)) ? Number(value) : NaN;
12
+ try {
13
+ switch (format) {
14
+ case 'currency':
15
+ return Number.isNaN(n) ? String(value) : new Intl.NumberFormat(locale, { style: 'currency', currency }).format(n);
16
+ case 'percent':
17
+ return Number.isNaN(n) ? String(value) : new Intl.NumberFormat(locale, { style: 'percent', maximumFractionDigits: 1 }).format(n > 1 ? n / 100 : n);
18
+ case 'compact':
19
+ return Number.isNaN(n) ? String(value) : new Intl.NumberFormat(locale, { notation: 'compact', maximumFractionDigits: 1 }).format(n);
20
+ case 'date':
21
+ case 'datetime': {
22
+ const d = new Date(String(value));
23
+ return Number.isNaN(d.getTime()) ? String(value) : new Intl.DateTimeFormat(locale, format === 'date' ? { dateStyle: 'medium' } : { dateStyle: 'medium', timeStyle: 'short' }).format(d);
24
+ }
25
+ case 'relative_date': {
26
+ const d = new Date(String(value));
27
+ if (Number.isNaN(d.getTime()))
28
+ return String(value);
29
+ const days = Math.round((d.getTime() - Date.now()) / 86_400_000);
30
+ return new Intl.RelativeTimeFormat(locale, { numeric: 'auto' }).format(days, 'day');
31
+ }
32
+ default:
33
+ return Number.isNaN(n) ? String(value) : new Intl.NumberFormat(locale).format(n);
34
+ }
35
+ }
36
+ catch {
37
+ return String(value);
38
+ }
39
+ }
40
+ /** Tone of a value from its thresholds: the highest `at` the value reaches wins; otherwise the block's own tone. */
41
+ export function toneFor(value, thresholds, base = 'default') {
42
+ const n = typeof value === 'number' ? value : Number(value);
43
+ if (!thresholds?.length || !Number.isFinite(n))
44
+ return base;
45
+ let tone = base;
46
+ let best = -Infinity;
47
+ for (const t of thresholds)
48
+ if (n >= t.at && t.at > best)
49
+ (best = t.at), (tone = t.tone);
50
+ return tone;
51
+ }
52
+ function Spark({ values }) {
53
+ if (values.length < 2)
54
+ return null;
55
+ const w = 96;
56
+ const h = 28;
57
+ const min = Math.min(...values);
58
+ const max = Math.max(...values);
59
+ const span = max - min || 1;
60
+ const pts = values.map((v, i) => `${((i / (values.length - 1)) * w).toFixed(1)},${(h - 2 - ((v - min) / span) * (h - 4)).toFixed(1)}`).join(' ');
61
+ return (_jsx("svg", { width: w, height: h, viewBox: `0 0 ${w} ${h}`, "aria-hidden": true, className: 'shrink-0 text-muted-foreground', children: _jsx("polyline", { points: pts, fill: 'none', stroke: 'currentColor', strokeWidth: 1.5, strokeLinejoin: 'round', strokeLinecap: 'round' }) }));
62
+ }
63
+ /** `metric` block: one KPI with trend, severity thresholds and an optional sparkline. */
64
+ export function MetricBlock({ block, rows, text, locale, currency }) {
65
+ const first = block.source ? rows?.[0] : undefined;
66
+ const raw = block.source ? first?.[block.field] : block.value;
67
+ const value = typeof raw === 'object' && raw !== null ? text(raw) : raw;
68
+ const tone = toneFor(value, block.thresholds, block.tone || 'default');
69
+ const spark = block.source
70
+ ? (rows ?? []).length > 1 && block.spark_field
71
+ ? (rows ?? []).map((r) => Number(r[block.spark_field])).filter(Number.isFinite)
72
+ : Array.isArray(first?.[block.spark_field])
73
+ ? first[block.spark_field].map(Number).filter(Number.isFinite)
74
+ : []
75
+ : (block.spark ?? []);
76
+ const Icon = block.trend ? TREND_ICON[block.trend] : null;
77
+ const loading = block.source && rows === undefined;
78
+ return (_jsxs("div", { className: 'flex w-full items-center justify-between gap-3 rounded-lg border bg-card p-3', "data-genui-block": 'metric', "aria-busy": loading || undefined, children: [_jsxs("div", { className: 'min-w-0', children: [_jsx("p", { className: 'm-0 text-xs text-muted-foreground', children: text(block.label) }), _jsxs("p", { className: cn('m-0 flex items-center gap-1 text-2xl font-semibold tabular-nums', TEXT_TONE[tone]), children: [loading ? '…' : formatMetric(value, block.format, locale, currency), Icon ? (_jsxs(_Fragment, { children: [_jsx(Icon, { className: 'size-4', "aria-hidden": true }), _jsx("span", { className: 'sr-only', children: TREND_LABEL[block.trend] })] })) : null] }), block.delta || block.compare ? (_jsxs("p", { className: 'm-0 text-xs text-muted-foreground', children: [block.delta ? _jsx("span", { className: 'font-medium', children: block.delta }) : null, " ", block.compare] })) : null, block.hint ? _jsx("p", { className: 'm-0 text-xs text-muted-foreground', children: text(block.hint) }) : null] }), _jsx(Spark, { values: spark })] }));
79
+ }
80
+ //# sourceMappingURL=metric.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metric.js","sourceRoot":"","sources":["../src/metric.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACvE,OAAO,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAA;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG3C,MAAM,UAAU,GAAG,EAAE,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,UAAU,EAAE,CAAA;AAC/E,MAAM,WAAW,GAAG,EAAE,EAAE,EAAE,SAAS,EAAE,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G,SAAS,EAAC,mCAAmC,YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAK,EACxE,aAAG,SAAS,EAAE,EAAE,CAAC,iEAAiE,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,aACjG,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EACnE,IAAI,CAAC,CAAC,CAAC,CACN,8BACE,KAAC,IAAI,IAAC,SAAS,EAAC,QAAQ,wBAAe,EACvC,eAAM,SAAS,EAAC,SAAS,YAAE,WAAW,CAAC,KAAK,CAAC,KAAa,CAAC,GAAQ,IAClE,CACJ,CAAC,CAAC,CAAC,IAAI,IACN,EACH,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAC9B,aAAG,SAAS,EAAC,mCAAmC,aAC7C,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,eAAM,SAAS,EAAC,aAAa,YAAE,KAAK,CAAC,KAAK,GAAQ,CAAC,CAAC,CAAC,IAAI,OAAG,KAAK,CAAC,OAAO,IACtF,CACL,CAAC,CAAC,CAAC,IAAI,EACP,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,YAAG,SAAS,EAAC,mCAAmC,YAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAK,CAAC,CAAC,CAAC,IAAI,IACxF,EACN,KAAC,KAAK,IAAC,MAAM,EAAE,KAAK,GAAI,IACpB,CACP,CAAA;AACH,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { type ComponentType, type ReactNode } from 'react';
2
+ /** A genui/v2 block as the renderers see it: already validated by `parseGenUI`. */
3
+ export type GenUIBlock = {
4
+ type: string;
5
+ id?: string;
6
+ fallback?: string;
7
+ [key: string]: any;
8
+ };
9
+ export type GenUIRow = Record<string, unknown>;
10
+ /** Rows of a declared `data.<name>` source, resolved by the HOST with the viewer's permissions. */
11
+ export type GenUISources = Record<string, GenUIRow[] | undefined>;
12
+ export interface GenUIActionRequest {
13
+ /** The declared action (a validated verb object), `$ref`s NOT resolved in phase 1. */
14
+ action: Record<string, unknown>;
15
+ /** Block that raised it. */
16
+ blockId?: string;
17
+ /** Free context, e.g. the selected map point. */
18
+ context?: Record<string, unknown>;
19
+ }
20
+ /** What a block renderer receives. */
21
+ export interface GenUIBlockRendererProps<B extends GenUIBlock = GenUIBlock> {
22
+ block: B;
23
+ /** Renders child blocks (containers). */
24
+ renderBlocks: (blocks: GenUIBlock[]) => ReactNode;
25
+ /** Rows of the block's `source`, when the host supplied them (else undefined). */
26
+ rows?: GenUIRow[];
27
+ /** Text of a `label`/`text` value: literal, `{$t}` through the host, `{$ref}` is empty until the binding engine (phase 2). */
28
+ text: (value: unknown) => string;
29
+ navigate: (path: string) => void;
30
+ /** Hands a declared action to the host (`navigate` with a path is handled here). */
31
+ act: (req: GenUIActionRequest) => void;
32
+ allowExternalLinks: boolean;
33
+ locale?: string;
34
+ currency?: string;
35
+ }
36
+ export type GenUIBlockRenderer<B extends GenUIBlock = GenUIBlock> = ComponentType<GenUIBlockRendererProps<B>>;
37
+ /**
38
+ * Registers the renderer of a block type (`map`, `chart`, `form`, an addon's
39
+ * `ext`…). Heavy renderers (MapLibre, charts) live in their own packages and
40
+ * register themselves here, so genui never imports them. Returns a function
41
+ * that restores the previous renderer. A `GenUIProvider` can override per tree.
42
+ */
43
+ export declare function registerGenUIBlockRenderer<B extends GenUIBlock = GenUIBlock>(type: string, renderer: GenUIBlockRenderer<B>): () => void;
44
+ export declare function getGenUIBlockRenderer(type: string): GenUIBlockRenderer | undefined;
45
+ /** Block types with a renderer registered (the `blocks` of the client's caps, plus the built-ins). */
46
+ export declare function registeredGenUIBlocks(): string[];
47
+ export interface GenUIContextValue {
48
+ renderers?: Record<string, GenUIBlockRenderer>;
49
+ sources?: GenUISources;
50
+ onNavigate?: (path: string) => void;
51
+ onAction?: (req: GenUIActionRequest) => void;
52
+ /** Resolves `{$t}` keys. Default: the key itself. */
53
+ t?: (key: string, args?: Record<string, unknown>) => string;
54
+ /** Literal http(s) links. Default off: only the chat turns it on. */
55
+ allowExternalLinks?: boolean;
56
+ locale?: string;
57
+ currency?: string;
58
+ }
59
+ export interface GenUIProviderProps extends GenUIContextValue {
60
+ children?: ReactNode;
61
+ }
62
+ /**
63
+ * Supplies what the host owns: sources already scoped to the viewer, routing,
64
+ * action handling, i18n and per-tree renderer overrides. Providers nest: inner
65
+ * values win, `renderers` and `sources` merge.
66
+ */
67
+ export declare function GenUIProvider({ children, ...value }: GenUIProviderProps): import("react").JSX.Element;
68
+ export declare function useGenUI(): GenUIContextValue;
69
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAsC,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAE9F,mFAAmF;AACnF,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAA;AAE7F,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE9C,mGAAmG;AACnG,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,CAAA;AAEjE,MAAM,WAAW,kBAAkB;IACjC,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,iDAAiD;IACjD,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,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CAAC,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAA;IAC5C,qDAAqD;IACrD,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,MAAM,CAAA;IAC3D,qEAAqE;IACrE,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAID,MAAM,WAAW,kBAAmB,SAAQ,iBAAiB;IAC3D,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,kBAAkB,+BAavE;AAMD,wBAAgB,QAAQ,IAAI,iBAAiB,CAE5C"}
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo } from 'react';
3
+ const registry = new Map();
4
+ /**
5
+ * Registers the renderer of a block type (`map`, `chart`, `form`, an addon's
6
+ * `ext`…). Heavy renderers (MapLibre, charts) live in their own packages and
7
+ * register themselves here, so genui never imports them. Returns a function
8
+ * that restores the previous renderer. A `GenUIProvider` can override per tree.
9
+ */
10
+ export function registerGenUIBlockRenderer(type, renderer) {
11
+ const prev = registry.get(type);
12
+ registry.set(type, renderer);
13
+ return () => {
14
+ if (registry.get(type) === renderer)
15
+ prev ? registry.set(type, prev) : registry.delete(type);
16
+ };
17
+ }
18
+ export function getGenUIBlockRenderer(type) {
19
+ return registry.get(type);
20
+ }
21
+ /** Block types with a renderer registered (the `blocks` of the client's caps, plus the built-ins). */
22
+ export function registeredGenUIBlocks() {
23
+ return [...registry.keys()];
24
+ }
25
+ const Ctx = createContext({});
26
+ /**
27
+ * Supplies what the host owns: sources already scoped to the viewer, routing,
28
+ * action handling, i18n and per-tree renderer overrides. Providers nest: inner
29
+ * values win, `renderers` and `sources` merge.
30
+ */
31
+ export function GenUIProvider({ children, ...value }) {
32
+ const parent = useContext(Ctx);
33
+ const merged = useMemo(() => ({
34
+ ...parent,
35
+ ...stripUndefined(value),
36
+ renderers: { ...parent.renderers, ...value.renderers },
37
+ sources: { ...parent.sources, ...value.sources },
38
+ }),
39
+ // eslint-disable-next-line react-hooks/exhaustive-deps
40
+ [parent, value.renderers, value.sources, value.onNavigate, value.onAction, value.t, value.allowExternalLinks, value.locale, value.currency]);
41
+ return _jsx(Ctx.Provider, { value: merged, children: children });
42
+ }
43
+ function stripUndefined(o) {
44
+ return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
45
+ }
46
+ export function useGenUI() {
47
+ return useContext(Ctx);
48
+ }
49
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAsC,MAAM,OAAO,CAAA;AAsC9F,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA8B,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B,CAAoC,IAAY,EAAE,QAA+B;IACzH,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC/B,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,QAAyC,CAAC,CAAA;IAC7D,OAAO,GAAG,EAAE;QACV,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,QAAQ;YAAE,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC9F,CAAC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO,QAAQ,CAA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AAQ;IACtB,OAAO,UAAU,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface GenUIProps {
3
+ /** Untrusted spec, genui/v1 or genui/v2 (validated here before anything is drawn). */
4
+ spec: unknown;
5
+ /** Rendered when the spec is invalid (default: nothing). */
6
+ fallback?: ReactNode;
7
+ className?: string;
8
+ /** Overrides the provider's `allowExternalLinks` for this tree. */
9
+ allowExternalLinks?: boolean;
10
+ }
11
+ /**
12
+ * genui/v2 renderer. Validates with `parseGenUI` (v1 is upgraded), then draws
13
+ * the closed block set from registered renderers: built-ins here (composition,
14
+ * text, markdown, alert, empty, card, list, metric, diagram, and the v1 blocks)
15
+ * and external ones registered with `registerGenUIBlockRenderer` (map, chart…).
16
+ * A block with no renderer shows its `fallback` text. Phase 1 does not evaluate
17
+ * `when`, `$ref` or declared sources: a block with `when` is not shown (it must
18
+ * never appear without its condition) and sources come from `GenUIProvider`.
19
+ */
20
+ export declare function GenUI({ spec, fallback, className, allowExternalLinks }: GenUIProps): import("react").JSX.Element;
21
+ /** The block types this build can draw by itself (before any `registerGenUIBlockRenderer`). */
22
+ export declare const GENUI_BUILTIN_BLOCKS: readonly string[];
23
+ //# sourceMappingURL=render-v2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-v2.d.ts","sourceRoot":"","sources":["../src/render-v2.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAkBzD,MAAM,WAAW,UAAU;IACzB,sFAAsF;IACtF,IAAI,EAAE,OAAO,CAAA;IACb,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mEAAmE;IACnE,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,QAAe,EAAE,SAAS,EAAE,kBAAkB,EAAE,EAAE,UAAU,+BAQzF;AA2RD,+FAA+F;AAC/F,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAAyB,CAAA"}
@@ -0,0 +1,166 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMemo, useState } from 'react';
3
+ import { AlertTriangle, ChevronDown, Info } from 'lucide-react';
4
+ import { Alert, AlertDescription, AlertTitle, Badge, Button, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, Tabs, TabsContent, TabsList, TabsTrigger, cn } from '@asteby/metacore-ui';
5
+ import { BADGE_VARIANT, Block as V1Block, TEXT_TONE } from './generative-ui';
6
+ import { parseGenUI } from './compat';
7
+ import { DiagramBlock } from './diagram';
8
+ import { MetricBlock } from './metric';
9
+ import { renderMarkdown } from './markdown';
10
+ import { mapLegend, normalizeMapPoints } from './map-points';
11
+ import { getGenUIBlockRenderer, useGenUI } from './registry';
12
+ const GRID_COLS = ['', 'grid-cols-1', 'grid-cols-1 @md:grid-cols-2', 'grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-3', 'grid-cols-1 @md:grid-cols-2 @2xl:grid-cols-4'];
13
+ const BTN = { primary: 'default', secondary: 'secondary', ghost: 'ghost', danger: 'destructive' };
14
+ /**
15
+ * genui/v2 renderer. Validates with `parseGenUI` (v1 is upgraded), then draws
16
+ * the closed block set from registered renderers: built-ins here (composition,
17
+ * text, markdown, alert, empty, card, list, metric, diagram, and the v1 blocks)
18
+ * and external ones registered with `registerGenUIBlockRenderer` (map, chart…).
19
+ * A block with no renderer shows its `fallback` text. Phase 1 does not evaluate
20
+ * `when`, `$ref` or declared sources: a block with `when` is not shown (it must
21
+ * never appear without its condition) and sources come from `GenUIProvider`.
22
+ */
23
+ export function GenUI({ spec, fallback = null, className, allowExternalLinks }) {
24
+ const ctx = useGenUI();
25
+ const allow = allowExternalLinks ?? ctx.allowExternalLinks ?? false;
26
+ const opts = { allowExternalLinks: allow };
27
+ const parsed = useMemo(() => parseGenUI(spec, opts), [spec, allow]); // eslint-disable-line react-hooks/exhaustive-deps
28
+ if (!parsed.ok)
29
+ return _jsx(_Fragment, { children: fallback });
30
+ const doc = parsed.spec;
31
+ return _jsx(Tree, { doc: doc, className: className, allow: allow });
32
+ }
33
+ function Tree({ doc, className, allow }) {
34
+ const ctx = useGenUI();
35
+ const text = (v) => {
36
+ if (typeof v === 'string')
37
+ return v;
38
+ if (v && typeof v === 'object' && '$t' in v) {
39
+ const o = v;
40
+ return ctx.t ? ctx.t(o.$t, o.args) : o.$t;
41
+ }
42
+ return '';
43
+ };
44
+ const navigate = (p) => (ctx.onNavigate ? ctx.onNavigate(p) : void (window.location.href = p));
45
+ const act = (req) => ctx.onAction?.(req);
46
+ const renderBlocks = (blocks) => blocks.map((b, i) => _jsx(BlockHost, { block: b, renderBlocks: renderBlocks, text: text, navigate: navigate, act: act, allowExternalLinks: allow }, b.id ?? i));
47
+ return (_jsxs("section", { className: cn('@container flex w-full flex-col gap-2', className), "aria-label": doc.title ? text(doc.title) : undefined, "data-genui": 'v2', children: [doc.title ? _jsx("h3", { className: 'm-0 text-sm font-semibold text-foreground', children: text(doc.title) }) : null, renderBlocks(doc.blocks)] }));
48
+ }
49
+ function BlockHost({ block, ...rest }) {
50
+ const ctx = useGenUI();
51
+ // A condition the phase-1 renderer cannot evaluate: never show the block without it.
52
+ if (block.when)
53
+ return null;
54
+ const source = typeof block.source === 'string' ? block.source.slice(5) : undefined;
55
+ const rows = source !== undefined && ctx.sources && Object.hasOwn(ctx.sources, source) ? ctx.sources[source] : undefined;
56
+ const props = { ...rest, block, rows, locale: ctx.locale, currency: ctx.currency };
57
+ const own = ctx.renderers && Object.hasOwn(ctx.renderers, block.type) ? ctx.renderers[block.type] : undefined;
58
+ const Custom = own ?? getGenUIBlockRenderer(block.type);
59
+ if (Custom)
60
+ return _jsx(Custom, { ...props });
61
+ const Builtin = BUILTIN[block.type];
62
+ if (Builtin)
63
+ return _jsx(Builtin, { ...props });
64
+ return block.fallback ? _jsx("p", { className: 'm-0 text-sm text-muted-foreground', children: block.fallback }) : null;
65
+ }
66
+ // ---- composition ----
67
+ function Stack({ block, renderBlocks, text }) {
68
+ return (_jsxs("div", { className: cn('flex gap-2', block.direction === 'horizontal' ? 'flex-col @md:flex-row @md:flex-wrap' : 'flex-col'), children: [block.title ? _jsx("h4", { className: 'm-0 w-full text-xs font-medium text-muted-foreground', children: text(block.title) }) : null, renderBlocks(block.blocks)] }));
69
+ }
70
+ function Grid({ block, renderBlocks, text }) {
71
+ const cols = Math.min(4, Math.max(1, Number(block.columns) || 2));
72
+ return (_jsxs("div", { children: [block.title ? _jsx("h4", { className: 'm-0 mb-1 text-xs font-medium text-muted-foreground', children: text(block.title) }) : null, _jsx("div", { className: cn('grid gap-2', GRID_COLS[cols]), children: renderBlocks(block.blocks) })] }));
73
+ }
74
+ function Tabbed({ block, renderBlocks, text }) {
75
+ const tabs = block.tabs;
76
+ const [value, setValue] = useState(tabs[0].key);
77
+ return (_jsxs(Tabs, { value: value, onValueChange: setValue, children: [_jsx(TabsList, { className: 'h-auto flex-wrap', children: tabs.map((t) => (_jsx(TabsTrigger, { value: t.key, children: text(t.label) }, t.key))) }), tabs.map((t) => (_jsx(TabsContent, { value: t.key, className: 'flex flex-col gap-2', children: t.key === value ? renderBlocks(t.blocks) : null }, t.key)))] }));
78
+ }
79
+ function Section({ block, renderBlocks, text }) {
80
+ const [open, setOpen] = useState(!block.collapsed);
81
+ const collapsible = !!block.collapsible;
82
+ return (_jsxs("section", { className: 'flex flex-col gap-2', children: [collapsible ? (_jsxs("button", { type: 'button', className: 'flex w-full items-center gap-1 text-left text-sm font-semibold', "aria-expanded": open, onClick: () => setOpen(!open), children: [_jsx(ChevronDown, { className: cn('size-4 transition-transform', !open && '-rotate-90'), "aria-hidden": true }), text(block.title)] })) : (_jsx("h4", { className: 'm-0 text-sm font-semibold', children: text(block.title) })), open ? renderBlocks(block.blocks) : null] }));
83
+ }
84
+ // ---- content ----
85
+ function Text({ block, text }) {
86
+ return _jsx("p", { className: cn('m-0 whitespace-pre-line break-words text-sm', TEXT_TONE[block.tone || 'default']), children: text(block.text) });
87
+ }
88
+ function Markdown({ block, navigate, allowExternalLinks }) {
89
+ return _jsx("div", { className: 'flex flex-col gap-2', children: renderMarkdown(block.markdown, { allowExternalLinks, onNavigate: navigate }) });
90
+ }
91
+ function AlertBlock({ block, text }) {
92
+ const danger = block.tone === 'danger';
93
+ const Icon = block.tone === 'warning' || danger ? AlertTriangle : Info;
94
+ return (_jsxs(Alert, { variant: danger ? 'destructive' : 'default', className: cn(!danger && block.tone && block.tone !== 'default' && TEXT_TONE[block.tone]), children: [_jsx(Icon, { className: 'size-4', "aria-hidden": true }), block.title ? _jsx(AlertTitle, { children: text(block.title) }) : null, _jsx(AlertDescription, { children: text(block.text) })] }));
95
+ }
96
+ function Actions({ actions, text, navigate, act, blockId, context }) {
97
+ if (!actions?.length)
98
+ return null;
99
+ return (_jsx("div", { className: 'flex flex-wrap gap-2', children: actions.filter((a) => !a.when).map((a, i) => (_jsx(Button, { size: 'sm', variant: BTN[a.variant ?? 'secondary'] ?? 'secondary', onClick: () => run(a, { navigate, act, blockId, context }), children: text(a.label) || a.do }, i))) }));
100
+ }
101
+ /** Plain app navigation runs here; anything else (or anything that asks for confirmation) is the host's. */
102
+ function run(a, o) {
103
+ if (a.do === 'navigate' && typeof a.route?.path === 'string' && !a.confirm)
104
+ return o.navigate(a.route.path);
105
+ o.act({ action: a, blockId: o.blockId, context: o.context });
106
+ }
107
+ function Empty({ block, text, navigate, act }) {
108
+ return (_jsxs("div", { className: 'flex flex-col items-center gap-1 rounded-lg border border-dashed p-6 text-center', children: [_jsx("p", { className: 'm-0 text-sm font-medium', children: text(block.title) }), block.text ? _jsx("p", { className: 'm-0 text-sm text-muted-foreground', children: text(block.text) }) : null, _jsx(Actions, { actions: block.actions, text: text, navigate: navigate, act: act, blockId: block.id })] }));
109
+ }
110
+ function CardBlock({ block, text, navigate, act, allowExternalLinks }) {
111
+ const link = typeof block.link === 'string' && (block.link.startsWith('/') || allowExternalLinks) ? block.link : undefined;
112
+ return (_jsxs(Card, { className: cn(block.tone && block.tone !== 'default' && 'border-l-4'), children: [_jsxs(CardHeader, { children: [_jsxs(CardTitle, { className: 'flex flex-wrap items-center gap-2 text-sm', children: [link ? (_jsx("a", { href: link, className: 'underline-offset-2 hover:underline', ...(link.startsWith('/') ? { onClick: (e) => { e.preventDefault(); navigate(link); } } : { target: '_blank', rel: 'noopener noreferrer nofollow' }), children: text(block.title) })) : (text(block.title)), (block.badges ?? []).map((b, i) => (_jsx(Badge, { variant: BADGE_VARIANT[b.tone || 'default'], children: b.label }, i)))] }), block.subtitle ? _jsx(CardDescription, { children: text(block.subtitle) }) : null] }), block.body || block.fields?.length ? (_jsxs(CardContent, { className: 'flex flex-col gap-2 text-sm', children: [block.body ? _jsx("p", { className: 'm-0 whitespace-pre-line', children: text(block.body) }) : null, block.fields?.length ? (_jsx("dl", { className: 'm-0 grid grid-cols-[minmax(6rem,auto)_1fr] gap-x-4 gap-y-1', children: block.fields.map((f, i) => (_jsxs("div", { className: 'contents', children: [_jsx("dt", { className: 'text-muted-foreground', children: text(f.label) }), _jsx("dd", { className: 'm-0 break-words', children: text(f.value) })] }, i))) })) : null] })) : null, block.actions?.length ? (_jsx(CardFooter, { children: _jsx(Actions, { actions: block.actions, text: text, navigate: navigate, act: act, blockId: block.id }) })) : null] }));
113
+ }
114
+ function ListBlock({ block, text, navigate, act }) {
115
+ return (_jsxs("div", { children: [block.title ? _jsx("p", { className: 'm-0 mb-1 text-xs font-medium text-muted-foreground', children: text(block.title) }) : null, _jsx("ul", { className: 'm-0 flex list-none flex-col divide-y rounded-lg border p-0', children: block.items.map((it, i) => (_jsxs("li", { className: 'flex items-center justify-between gap-3 p-2.5', children: [_jsxs("div", { className: 'min-w-0', children: [_jsxs("p", { className: 'm-0 flex items-center gap-2 text-sm font-medium', children: [text(it.title), it.badge ? _jsx(Badge, { variant: BADGE_VARIANT[it.badge.tone || 'default'], children: it.badge.label }) : null] }), it.description ? _jsx("p", { className: 'm-0 text-xs text-muted-foreground', children: text(it.description) }) : null] }), it.action ? _jsx(Actions, { actions: [it.action], text: text, navigate: navigate, act: act, blockId: block.id, context: { item: i } }) : null] }, i))) })] }));
116
+ }
117
+ /** `stats` is `kpi` with extras: same view over its inline items (sources arrive with the host's rows). */
118
+ function Stats({ block, rows, text, ...rest }) {
119
+ const items = (block.items ?? (rows ?? []).slice(0, 12).map((r) => ({ label: String(r.label ?? ''), value: String(r.value ?? '') })));
120
+ const resolved = items.map((it) => ({ ...it, label: text(it.label), value: text(it.value), hint: it.hint === undefined ? undefined : text(it.hint) }));
121
+ return _jsx(V1Block, { block: { type: 'kpi', title: block.title ? text(block.title) : undefined, items: resolved }, onNavigate: rest.navigate });
122
+ }
123
+ /**
124
+ * v1-shaped blocks keep their v1 view. v2-only fields (`id`, `when`, `fallback`)
125
+ * are dropped and `$t` text is resolved first, so the v1 view sees plain strings.
126
+ */
127
+ function V1Passthrough({ block, text, navigate }) {
128
+ const plain = useMemo(() => resolveText(block, text), [block, text]);
129
+ const { id: _id, when: _w, fallback: _f, ...rest } = plain;
130
+ void _id;
131
+ void _w;
132
+ void _f;
133
+ return _jsx(V1Block, { block: rest, onNavigate: navigate });
134
+ }
135
+ const TEXT_KEYS = new Set(['title', 'text', 'label', 'subtitle', 'body', 'description', 'hint', 'caption', 'value']);
136
+ function resolveText(v, text, key = '') {
137
+ if (Array.isArray(v))
138
+ return v.map((x) => resolveText(x, text, key));
139
+ if (v && typeof v === 'object') {
140
+ if ((('$t' in v) || ('$ref' in v)) && TEXT_KEYS.has(key))
141
+ return text(v);
142
+ if (key === 'rows')
143
+ return v;
144
+ return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, resolveText(x, text, k)]));
145
+ }
146
+ return v;
147
+ }
148
+ /**
149
+ * Accessible stand-in for `map` when no renderer is registered (register
150
+ * `@asteby/metacore-maps/genui` to get the real map): the points as a list
151
+ * with their status written out and the legend.
152
+ */
153
+ function MapFallback({ block, rows, text }) {
154
+ const points = normalizeMapPoints(block, rows, text);
155
+ const legend = mapLegend(points, block.group_by === 'group' ? 'group' : 'status');
156
+ return (_jsxs("section", { "aria-label": block.summary, className: 'rounded-lg border p-2.5', "data-genui-block": 'map-fallback', children: [block.title ? _jsx("p", { className: 'm-0 mb-1 text-xs font-medium text-muted-foreground', children: text(block.title) }) : null, legend.length > 1 ? (_jsx("ul", { className: 'm-0 mb-2 flex list-none flex-wrap gap-1 p-0', children: legend.map((l) => (_jsx("li", { children: _jsxs(Badge, { variant: BADGE_VARIANT[l.tone ?? 'default'], children: [l.value, " \u00B7 ", l.count] }) }, l.value))) })) : null, _jsx("ul", { className: 'm-0 list-none p-0 text-sm', children: points.map((p) => (_jsxs("li", { className: 'flex justify-between gap-2 py-0.5', children: [_jsx("span", { children: p.label }), _jsx("span", { className: 'text-muted-foreground', children: [p.status, `${p.lat.toFixed(3)}, ${p.lng.toFixed(3)}`].filter(Boolean).join(' · ') })] }, p.key))) })] }));
157
+ }
158
+ const BUILTIN = {
159
+ stack: Stack, grid: Grid, tabs: Tabbed, section: Section,
160
+ text: Text, markdown: Markdown, alert: AlertBlock, empty: Empty, card: CardBlock, list: ListBlock,
161
+ metric: MetricBlock, diagram: DiagramBlock, map: MapFallback, stats: Stats,
162
+ kpi: V1Passthrough, links: V1Passthrough, timeline: V1Passthrough, table: V1Passthrough, chart: V1Passthrough, confirm: V1Passthrough,
163
+ };
164
+ /** The block types this build can draw by itself (before any `registerGenUIBlockRenderer`). */
165
+ export const GENUI_BUILTIN_BLOCKS = Object.keys(BUILTIN);
166
+ //# sourceMappingURL=render-v2.js.map