@asteby/metacore-genui 2.1.1 → 2.3.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.
- package/README.md +54 -6
- package/dist/diagram.d.ts +34 -0
- package/dist/diagram.d.ts.map +1 -0
- package/dist/diagram.js +103 -0
- package/dist/diagram.js.map +1 -0
- package/dist/generated/genui-v2-schema.d.ts +332 -0
- package/dist/generated/genui-v2-schema.d.ts.map +1 -1
- package/dist/generated/genui-v2-schema.js +454 -0
- package/dist/generated/genui-v2-schema.js.map +1 -1
- package/dist/generated/genui-v2.d.ts +342 -1
- package/dist/generated/genui-v2.d.ts.map +1 -1
- package/dist/generative-ui.d.ts +11 -1
- package/dist/generative-ui.d.ts.map +1 -1
- package/dist/generative-ui.js +3 -3
- package/dist/generative-ui.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/map-points.d.ts +31 -0
- package/dist/map-points.d.ts.map +1 -0
- package/dist/map-points.js +60 -0
- package/dist/map-points.js.map +1 -0
- package/dist/markdown.d.ts +13 -0
- package/dist/markdown.d.ts.map +1 -0
- package/dist/markdown.js +63 -0
- package/dist/markdown.js.map +1 -0
- package/dist/metric.d.ts +12 -0
- package/dist/metric.d.ts.map +1 -0
- package/dist/metric.js +80 -0
- package/dist/metric.js.map +1 -0
- package/dist/page/blocks.d.ts +92 -0
- package/dist/page/blocks.d.ts.map +1 -0
- package/dist/page/blocks.js +363 -0
- package/dist/page/blocks.js.map +1 -0
- package/dist/page/context.d.ts +74 -0
- package/dist/page/context.d.ts.map +1 -0
- package/dist/page/context.js +167 -0
- package/dist/page/context.js.map +1 -0
- package/dist/page/custom.d.ts +55 -0
- package/dist/page/custom.d.ts.map +1 -0
- package/dist/page/custom.js +27 -0
- package/dist/page/custom.js.map +1 -0
- package/dist/page/index.d.ts +4 -0
- package/dist/page/index.d.ts.map +1 -0
- package/dist/page/index.js +5 -0
- package/dist/page/index.js.map +1 -0
- package/dist/registry.d.ts +69 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +49 -0
- package/dist/registry.js.map +1 -0
- package/dist/render-v2.d.ts +23 -0
- package/dist/render-v2.d.ts.map +1 -0
- package/dist/render-v2.js +166 -0
- package/dist/render-v2.js.map +1 -0
- package/dist/validate-v2.d.ts.map +1 -1
- package/dist/validate-v2.js +38 -0
- package/dist/validate-v2.js.map +1 -1
- package/package.json +2 -2
- package/schema/genui-v2.schema.json +386 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// PageContext (page@1): estado compartido de una pagina declarativa, bus de
|
|
3
|
+
// eventos minimo y `url_state` opcional. Sin eval: rutas de estado cerradas.
|
|
4
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
export function createPageBus() {
|
|
6
|
+
const handlers = new Map();
|
|
7
|
+
return {
|
|
8
|
+
emit(event) {
|
|
9
|
+
for (const key of [event.name, '*'])
|
|
10
|
+
for (const h of [...(handlers.get(key) ?? [])])
|
|
11
|
+
h(event);
|
|
12
|
+
},
|
|
13
|
+
on(name, handler) {
|
|
14
|
+
let set = handlers.get(name);
|
|
15
|
+
if (!set)
|
|
16
|
+
handlers.set(name, (set = new Set()));
|
|
17
|
+
set.add(handler);
|
|
18
|
+
return () => void set.delete(handler);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const FORBIDDEN = new Set(['__proto__', 'constructor', 'prototype']);
|
|
23
|
+
const SEGMENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
24
|
+
/** Valida una ruta de estado (`a.b.c`): segmentos simples, nunca llaves de prototipo. */
|
|
25
|
+
export function isSafePath(path) {
|
|
26
|
+
return typeof path === 'string' && path.length > 0 && path.split('.').every((s) => SEGMENT.test(s) && !FORBIDDEN.has(s));
|
|
27
|
+
}
|
|
28
|
+
export function getPath(root, path) {
|
|
29
|
+
let cur = root;
|
|
30
|
+
for (const seg of path.split('.')) {
|
|
31
|
+
if (FORBIDDEN.has(seg) || cur === null || typeof cur !== 'object' || !Object.hasOwn(cur, seg))
|
|
32
|
+
return undefined;
|
|
33
|
+
cur = cur[seg];
|
|
34
|
+
}
|
|
35
|
+
return cur;
|
|
36
|
+
}
|
|
37
|
+
export function setPath(root, path, value) {
|
|
38
|
+
if (!isSafePath(path))
|
|
39
|
+
return root;
|
|
40
|
+
const [head, ...rest] = path.split('.');
|
|
41
|
+
if (rest.length === 0)
|
|
42
|
+
return { ...root, [head]: value };
|
|
43
|
+
const child = Object.hasOwn(root, head) && root[head] && typeof root[head] === 'object' ? root[head] : {};
|
|
44
|
+
return { ...root, [head]: setPath(child, rest.join('.'), value) };
|
|
45
|
+
}
|
|
46
|
+
/** Resuelve `state.x.y`, `data.fuente.campo` (primera fila) y `ctx.x`. Cualquier otra raiz: undefined. */
|
|
47
|
+
export function resolveRef(ref, v) {
|
|
48
|
+
if (typeof ref !== 'string')
|
|
49
|
+
return undefined;
|
|
50
|
+
const dot = ref.indexOf('.');
|
|
51
|
+
if (dot < 0)
|
|
52
|
+
return undefined;
|
|
53
|
+
const root = ref.slice(0, dot);
|
|
54
|
+
const rest = ref.slice(dot + 1);
|
|
55
|
+
if (root === 'state')
|
|
56
|
+
return getPath(v.state, rest);
|
|
57
|
+
if (root === 'ctx')
|
|
58
|
+
return getPath(v.ctx ?? {}, rest);
|
|
59
|
+
if (root === 'data') {
|
|
60
|
+
const [name, ...field] = rest.split('.');
|
|
61
|
+
if (FORBIDDEN.has(name) || !v.sources || !Object.hasOwn(v.sources, name))
|
|
62
|
+
return undefined;
|
|
63
|
+
const row = v.sources[name]?.[0];
|
|
64
|
+
return field.length ? getPath(row, field.join('.')) : row;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
/** Predicado de `when` (ref + equals/in/not_in/empty) ya con el valor resuelto. */
|
|
69
|
+
export function evalPredicate(p, value) {
|
|
70
|
+
const isEmpty = value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0);
|
|
71
|
+
if (p.empty !== undefined && p.empty !== isEmpty)
|
|
72
|
+
return false;
|
|
73
|
+
if (Object.hasOwn(p, 'equals') && p.equals !== value)
|
|
74
|
+
return false;
|
|
75
|
+
if (p.in && !p.in.includes(value))
|
|
76
|
+
return false;
|
|
77
|
+
if (p.not_in && p.not_in.includes(value))
|
|
78
|
+
return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
const Ctx = createContext(null);
|
|
82
|
+
const browserUrl = {
|
|
83
|
+
read: () => new URLSearchParams(typeof window === 'undefined' ? '' : window.location.search),
|
|
84
|
+
write: (params) => {
|
|
85
|
+
if (typeof window === 'undefined')
|
|
86
|
+
return;
|
|
87
|
+
const qs = params.toString();
|
|
88
|
+
window.history.replaceState(window.history.state, '', `${window.location.pathname}${qs ? `?${qs}` : ''}${window.location.hash}`);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
const URL_PREFIX = 's.';
|
|
92
|
+
export function PageProvider({ initialState, urlState, urlAdapter = browserUrl, can, sourceStatus, ctx, bus: given, children }) {
|
|
93
|
+
const bus = useMemo(() => given ?? createPageBus(), [given]);
|
|
94
|
+
const keys = useMemo(() => (urlState ?? []).filter((k) => isSafePath(k) && !k.includes('.')), [urlState]);
|
|
95
|
+
const [state, setStateRaw] = useState(() => {
|
|
96
|
+
let s = { ...(initialState ?? {}) };
|
|
97
|
+
if (keys.length) {
|
|
98
|
+
const params = urlAdapter.read();
|
|
99
|
+
for (const k of keys) {
|
|
100
|
+
const raw = params.get(URL_PREFIX + k);
|
|
101
|
+
if (raw === null)
|
|
102
|
+
continue;
|
|
103
|
+
try {
|
|
104
|
+
s = setPath(s, k, JSON.parse(raw));
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
/* valor ilegible: se ignora */
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return s;
|
|
112
|
+
});
|
|
113
|
+
const setState = useCallback((path, value) => {
|
|
114
|
+
if (!isSafePath(path))
|
|
115
|
+
return;
|
|
116
|
+
setStateRaw((prev) => setPath(prev, path, value));
|
|
117
|
+
}, []);
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!keys.length)
|
|
120
|
+
return;
|
|
121
|
+
const params = urlAdapter.read();
|
|
122
|
+
for (const k of keys) {
|
|
123
|
+
const v = state[k];
|
|
124
|
+
if (v === undefined || v === null)
|
|
125
|
+
params.delete(URL_PREFIX + k);
|
|
126
|
+
else
|
|
127
|
+
params.set(URL_PREFIX + k, JSON.stringify(v));
|
|
128
|
+
}
|
|
129
|
+
urlAdapter.write(params);
|
|
130
|
+
}, [state, keys, urlAdapter]);
|
|
131
|
+
const value = useMemo(() => ({
|
|
132
|
+
state,
|
|
133
|
+
setState,
|
|
134
|
+
emit: (name, payload, source) => bus.emit({ name, payload, source }),
|
|
135
|
+
on: bus.on,
|
|
136
|
+
can: can ?? (() => false),
|
|
137
|
+
sourceStatus: sourceStatus ?? {},
|
|
138
|
+
ctx: ctx ?? {},
|
|
139
|
+
}), [state, setState, bus, can, sourceStatus, ctx]);
|
|
140
|
+
return _jsx(Ctx.Provider, { value: value, children: children });
|
|
141
|
+
}
|
|
142
|
+
const NOOP = {
|
|
143
|
+
state: {},
|
|
144
|
+
setState: () => { },
|
|
145
|
+
emit: () => { },
|
|
146
|
+
on: () => () => { },
|
|
147
|
+
can: () => false,
|
|
148
|
+
sourceStatus: {},
|
|
149
|
+
ctx: {},
|
|
150
|
+
};
|
|
151
|
+
/** Contexto de la pagina; fuera de un `PageProvider` es inerte (estado vacio, sin permisos). */
|
|
152
|
+
export function usePageContext() {
|
|
153
|
+
return useContext(Ctx) ?? NOOP;
|
|
154
|
+
}
|
|
155
|
+
/** `[valor, set]` de una ruta de estado. */
|
|
156
|
+
export function usePageState(path) {
|
|
157
|
+
const { state, setState } = usePageContext();
|
|
158
|
+
return [getPath(state, path), useCallback((v) => setState(path, v), [setState, path])];
|
|
159
|
+
}
|
|
160
|
+
/** Suscribe un handler al bus mientras el componente vive. */
|
|
161
|
+
export function usePageEvent(name, handler) {
|
|
162
|
+
const { on } = usePageContext();
|
|
163
|
+
const ref = useRef(handler);
|
|
164
|
+
ref.current = handler;
|
|
165
|
+
useEffect(() => on(name, (e) => ref.current(e)), [on, name]);
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/page/context.tsx"],"names":[],"mappings":";AAAA,4EAA4E;AAC5E,6EAA6E;AAC7E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAA;AAkBpH,MAAM,UAAU,aAAa;IAC3B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAiC,CAAA;IACzD,OAAO;QACL,IAAI,CAAC,KAAK;YACR,KAAK,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC;gBAAE,KAAK,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;oBAAE,CAAC,CAAC,KAAK,CAAC,CAAA;QAC/F,CAAC;QACD,EAAE,CAAC,IAAI,EAAE,OAAO;YACd,IAAI,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;YAC5B,IAAI,CAAC,GAAG;gBAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC,CAAC,CAAA;YAC/C,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YAChB,OAAO,GAAG,EAAE,CAAC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CAAC,GAAG,CAAC,IAAI,IAAI,CAAA;AAChC,CAAC;AAED,4CAA4C;AAC5C,MAAM,UAAU,YAAY,CAAc,IAAY;IACpD,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,cAAc,EAAE,CAAA;IAC5C,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAkB,EAAE,WAAW,CAAC,CAAC,CAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;AAC5G,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,OAAyB;IAClE,MAAM,EAAE,EAAE,EAAE,GAAG,cAAc,EAAE,CAAA;IAC/B,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC3B,GAAG,CAAC,OAAO,GAAG,OAAO,CAAA;IACrB,SAAS,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,CAAA;AAC9D,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { GenUIRow } from '../registry';
|
|
3
|
+
export declare const BLOCK_API: "block@1";
|
|
4
|
+
/** Estado de una fuente tal como la recibe un bloque custom. */
|
|
5
|
+
export interface BlockData {
|
|
6
|
+
status: 'loading' | 'ready' | 'error';
|
|
7
|
+
rows?: GenUIRow[];
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface BlockSize {
|
|
11
|
+
cols?: number;
|
|
12
|
+
rows?: number;
|
|
13
|
+
breakpoint: 'narrow' | 'wide';
|
|
14
|
+
}
|
|
15
|
+
export type BlockScalar = string | number | boolean | null;
|
|
16
|
+
export interface BlockEmit {
|
|
17
|
+
/** Escribe `state.<key>`; solo claves declaradas en `writes`. */
|
|
18
|
+
(event: 'set', payload: {
|
|
19
|
+
key: string;
|
|
20
|
+
value: unknown;
|
|
21
|
+
}): void;
|
|
22
|
+
/** Evento declarado en `events`, payload escalar. */
|
|
23
|
+
(event: string, payload?: Record<string, BlockScalar>): void;
|
|
24
|
+
}
|
|
25
|
+
export interface BlockComponentProps<P = Record<string, BlockScalar | BlockScalar[]>> {
|
|
26
|
+
props: P;
|
|
27
|
+
/** Snapshot de solo lectura de las claves declaradas en `reads` (`state.x`, `ctx.x`). */
|
|
28
|
+
context: Record<string, unknown>;
|
|
29
|
+
/** Fuentes declaradas en `data`, ya resueltas por la pagina. */
|
|
30
|
+
data: Record<string, BlockData>;
|
|
31
|
+
emit: BlockEmit;
|
|
32
|
+
size: BlockSize;
|
|
33
|
+
}
|
|
34
|
+
/** Declaracion de un bloque custom (lo que `contributions.blocks[]` describe + el componente). */
|
|
35
|
+
export interface BlockDefinition<P = Record<string, BlockScalar | BlockScalar[]>> {
|
|
36
|
+
api: typeof BLOCK_API;
|
|
37
|
+
/** `<addon>.<nombre>@<mayor>`, igual que `ext` en genui/v2. */
|
|
38
|
+
name: string;
|
|
39
|
+
/** Subconjunto de JSON Schema de las props (escalares); el host valida antes de montar. */
|
|
40
|
+
props_schema?: Record<string, unknown>;
|
|
41
|
+
reads?: string[];
|
|
42
|
+
writes?: string[];
|
|
43
|
+
data?: string[];
|
|
44
|
+
events?: string[];
|
|
45
|
+
permission?: string;
|
|
46
|
+
component: ComponentType<BlockComponentProps<P>>;
|
|
47
|
+
}
|
|
48
|
+
/** Define un bloque custom. Valida el contrato en el acto (falla ruidosamente al desarrollar). */
|
|
49
|
+
export declare function defineBlock<P = Record<string, BlockScalar | BlockScalar[]>>(def: Omit<BlockDefinition<P>, 'api'> & {
|
|
50
|
+
api?: typeof BLOCK_API;
|
|
51
|
+
}): BlockDefinition<P>;
|
|
52
|
+
/** Registra un bloque custom ya cargado. Devuelve la funcion que lo retira. */
|
|
53
|
+
export declare function registerPageBlock(def: BlockDefinition<any>): () => void;
|
|
54
|
+
export declare function getPageBlock(name: string): BlockDefinition<any> | undefined;
|
|
55
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/page/custom.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAE3C,eAAO,MAAM,SAAS,EAAG,SAAkB,CAAA;AAE3C,gEAAgE;AAChE,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,SAAS,GAAG,OAAO,GAAG,OAAO,CAAA;IACrC,IAAI,CAAC,EAAE,QAAQ,EAAE,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,UAAU,EAAE,QAAQ,GAAG,MAAM,CAAA;CAC9B;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;AAE1D,MAAM,WAAW,SAAS;IACxB,iEAAiE;IACjE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAA;IAC9D,qDAAqD;IACrD,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,IAAI,CAAA;CAC7D;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,EAAE,CAAC;IAClF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G,CAAC,GAAG,SAAS,CAE3E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const BLOCK_API = 'block@1';
|
|
2
|
+
const NAME = /^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*@[1-9][0-9]*$/;
|
|
3
|
+
const KEY = /^(state|ctx)\.[A-Za-z_][A-Za-z0-9_.]*$/;
|
|
4
|
+
/** Define un bloque custom. Valida el contrato en el acto (falla ruidosamente al desarrollar). */
|
|
5
|
+
export function defineBlock(def) {
|
|
6
|
+
if (def.api !== undefined && def.api !== BLOCK_API)
|
|
7
|
+
throw new Error(`defineBlock: api ${String(def.api)} no soportada (solo ${BLOCK_API})`);
|
|
8
|
+
if (!NAME.test(def.name))
|
|
9
|
+
throw new Error(`defineBlock: nombre invalido "${def.name}" (esperado <addon>.<nombre>@<mayor>)`);
|
|
10
|
+
for (const r of def.reads ?? [])
|
|
11
|
+
if (!KEY.test(r))
|
|
12
|
+
throw new Error(`defineBlock: reads "${r}" invalido (state.* o ctx.*)`);
|
|
13
|
+
for (const w of def.writes ?? [])
|
|
14
|
+
if (!/^state\./.test(w) || !KEY.test(w))
|
|
15
|
+
throw new Error(`defineBlock: writes "${w}" invalido (solo state.*)`);
|
|
16
|
+
return { ...def, api: BLOCK_API };
|
|
17
|
+
}
|
|
18
|
+
const blocks = new Map(); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
19
|
+
/** Registra un bloque custom ya cargado. Devuelve la funcion que lo retira. */
|
|
20
|
+
export function registerPageBlock(def) {
|
|
21
|
+
blocks.set(def.name, def);
|
|
22
|
+
return () => void (blocks.get(def.name) === def && blocks.delete(def.name));
|
|
23
|
+
}
|
|
24
|
+
export function getPageBlock(name) {
|
|
25
|
+
return blocks.get(name);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=custom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.js","sourceRoot":"","sources":["../../src/page/custom.ts"],"names":[],"mappings":"AAM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,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;AAC7E,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './custom';
|
|
3
|
+
export { KpiCard, PageBlocks, PageSection, PageView, parseAreas, sanitizeTrack, usePageAction, type PageBlockDef, type PageBlocksProps, type PageGridDef, type PageKpiCardDef, type PageMapDef, type PageSectionDef, type PageSectionMode, type PageViewProps } from './blocks';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/page/index.ts"],"names":[],"mappings":"AACA,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// genui v2 de pagina (page@1 / block@1): contexto, renderers y contrato custom.
|
|
2
|
+
export * from './context';
|
|
3
|
+
export * from './custom';
|
|
4
|
+
export { KpiCard, PageBlocks, PageSection, PageView, parseAreas, sanitizeTrack, usePageAction } from './blocks';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/page/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,aAAa,EAAkK,MAAM,UAAU,CAAA"}
|
|
@@ -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,OAAO,CAAC,CAAA;CAClC;AAED,sCAAsC;AACtC,MAAM,WAAW,uBAAuB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IACxE,KAAK,EAAE,CAAC,CAAA;IACR,yCAAyC;IACzC,YAAY,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,SAAS,CAAA;IACjD,kFAAkF;IAClF,IAAI,CAAC,EAAE,QAAQ,EAA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,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"}
|
package/dist/registry.js
ADDED
|
@@ -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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,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAe,CAAA;AAC/F,CAAC;AAED,MAAM,UAAU,QAAQ;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
|