@asteby/metacore-runtime-react 53.27.0 → 53.29.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/CHANGELOG.md +26 -0
- package/dist/business/customer-picker.d.ts +10 -1
- package/dist/business/customer-picker.d.ts.map +1 -1
- package/dist/business/customer-picker.js +7 -2
- package/dist/dialogs/create-record-dialog.d.ts +1 -1
- package/dist/dialogs/create-record-dialog.d.ts.map +1 -1
- package/dist/dialogs/create-record-dialog.js +2 -2
- package/dist/dialogs/dynamic-record.d.ts +19 -2
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +83 -25
- package/dist/dialogs/types.d.ts +6 -0
- package/dist/dialogs/types.d.ts.map +1 -1
- package/dist/dynamic-crud-page.d.ts.map +1 -1
- package/dist/dynamic-crud-page.js +3 -0
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +6 -5
- package/dist/field-widget-registry.d.ts +6 -0
- package/dist/field-widget-registry.d.ts.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/loom/index.d.ts +9 -0
- package/dist/loom/index.d.ts.map +1 -0
- package/dist/loom/index.js +9 -0
- package/dist/loom/overlay.d.ts +74 -0
- package/dist/loom/overlay.d.ts.map +1 -0
- package/dist/loom/overlay.js +142 -0
- package/dist/loom/proposals.d.ts +26 -0
- package/dist/loom/proposals.d.ts.map +1 -0
- package/dist/loom/proposals.js +74 -0
- package/dist/loom/provider.d.ts +28 -0
- package/dist/loom/provider.d.ts.map +1 -0
- package/dist/loom/provider.js +31 -0
- package/dist/loom/resolve.d.ts +23 -0
- package/dist/loom/resolve.d.ts.map +1 -0
- package/dist/loom/resolve.js +138 -0
- package/dist/loom/seam.d.ts +28 -0
- package/dist/loom/seam.d.ts.map +1 -0
- package/dist/loom/seam.js +127 -0
- package/dist/loom/seams.d.ts +31 -0
- package/dist/loom/seams.d.ts.map +1 -0
- package/dist/loom/seams.js +21 -0
- package/dist/loom/store.d.ts +16 -0
- package/dist/loom/store.d.ts.map +1 -0
- package/dist/loom/store.js +72 -0
- package/dist/loom/types.d.ts +153 -0
- package/dist/loom/types.d.ts.map +1 -0
- package/dist/loom/types.js +1 -0
- package/dist/model-labels.d.ts +26 -0
- package/dist/model-labels.d.ts.map +1 -1
- package/dist/model-labels.js +22 -5
- package/dist/record-picker-dialog.d.ts +10 -1
- package/dist/record-picker-dialog.d.ts.map +1 -1
- package/dist/record-picker-dialog.js +18 -3
- package/dist/record-picker.d.ts +6 -0
- package/dist/record-picker.d.ts.map +1 -1
- package/dist/record-picker.js +4 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/dynamic-record-seam.test.tsx +194 -0
- package/src/__tests__/dynamic-record-texts.test.tsx +22 -0
- package/src/__tests__/field-widget-set-values.test.tsx +65 -0
- package/src/__tests__/loom-overlay.test.ts +94 -0
- package/src/__tests__/loom-resolve.test.ts +108 -0
- package/src/__tests__/model-labels.test.tsx +41 -1
- package/src/__tests__/record-picker-open-on-focus.test.tsx +49 -0
- package/src/business/customer-picker.tsx +17 -0
- package/src/dialogs/create-record-dialog.tsx +6 -0
- package/src/dialogs/dynamic-record.tsx +131 -26
- package/src/dialogs/types.ts +6 -0
- package/src/dynamic-crud-page.tsx +3 -0
- package/src/dynamic-form.tsx +9 -2
- package/src/field-widget-registry.tsx +6 -0
- package/src/index.ts +4 -1
- package/src/loom/index.ts +36 -0
- package/src/loom/overlay.ts +196 -0
- package/src/loom/proposals.tsx +156 -0
- package/src/loom/provider.tsx +69 -0
- package/src/loom/resolve.ts +136 -0
- package/src/loom/seam.tsx +235 -0
- package/src/loom/seams.ts +42 -0
- package/src/loom/store.ts +81 -0
- package/src/loom/types.ts +167 -0
- package/src/model-labels.ts +45 -5
- package/src/record-picker-dialog.tsx +42 -1
- package/src/record-picker.tsx +10 -0
- package/src/types.ts +10 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// Resolución pura de un seam: qué injertos se montan, en qué orden y por qué
|
|
2
|
+
// los demás no. Sin React: la usan <Seam>, el inspector y las pruebas de contrato.
|
|
3
|
+
import { satisfiesSdkRange } from '../slots/sdk-range.js';
|
|
4
|
+
import { getPart } from './store.js';
|
|
5
|
+
const bare = (model) => model.split('.').pop() ?? model;
|
|
6
|
+
const asList = (v) => (v == null ? [] : Array.isArray(v) ? v : [v]);
|
|
7
|
+
function hasComponent(g) {
|
|
8
|
+
if (g.component || g.load)
|
|
9
|
+
return true;
|
|
10
|
+
if (!g.part)
|
|
11
|
+
return false;
|
|
12
|
+
const p = getPart(g.part);
|
|
13
|
+
return !!(p && (p.component || p.load));
|
|
14
|
+
}
|
|
15
|
+
function check(g, contract, env) {
|
|
16
|
+
const skip = (reason, detail) => ({ graft: g, reason, detail });
|
|
17
|
+
if (env.granted && !env.granted.has(g.id))
|
|
18
|
+
return skip('not_granted', 'el servidor no lo listó para este usuario');
|
|
19
|
+
if (g.requires && satisfiesSdkRange(contract.version, g.requires) === false) {
|
|
20
|
+
return skip('version', `pide ${contract.id}@${g.requires}, el anfitrión publica ${contract.version}`);
|
|
21
|
+
}
|
|
22
|
+
const w = g.when;
|
|
23
|
+
if (w) {
|
|
24
|
+
const missing = asList(w.permission).filter((p) => !env.can(p));
|
|
25
|
+
if (missing.length)
|
|
26
|
+
return skip('permission', missing.join(', '));
|
|
27
|
+
if (w.anyPermission?.length && !w.anyPermission.some((p) => env.can(p))) {
|
|
28
|
+
return skip('permission', `alguno de ${w.anyPermission.join(', ')}`);
|
|
29
|
+
}
|
|
30
|
+
if (w.flag && !env.flags?.has(w.flag))
|
|
31
|
+
return skip('flag', w.flag);
|
|
32
|
+
if (w.setting) {
|
|
33
|
+
const v = env.settings?.[w.setting.key];
|
|
34
|
+
const ok = 'equals' in w.setting ? Object.is(v, w.setting.equals) : !!v;
|
|
35
|
+
if (!ok)
|
|
36
|
+
return skip('setting', w.setting.key);
|
|
37
|
+
}
|
|
38
|
+
if (w.model?.length) {
|
|
39
|
+
const m = env.model ? bare(env.model) : undefined;
|
|
40
|
+
if (!m || !w.model.some((x) => bare(x) === m))
|
|
41
|
+
return skip('model', env.model ?? '(sin modelo)');
|
|
42
|
+
}
|
|
43
|
+
if (w.mode?.length && (!env.mode || !w.mode.includes(env.mode)))
|
|
44
|
+
return skip('mode', env.mode ?? '(sin modo)');
|
|
45
|
+
}
|
|
46
|
+
if (!hasComponent(g))
|
|
47
|
+
return skip('no_component', g.part ? `Part ${g.part} no registrado` : undefined);
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/** Orden canónico: `order` ascendente, luego orden de entrada (estable). */
|
|
51
|
+
export function resolveSeam(contract, candidates, env) {
|
|
52
|
+
const mounted = [];
|
|
53
|
+
const skipped = [];
|
|
54
|
+
for (const g of candidates) {
|
|
55
|
+
if (g.seam !== contract.id)
|
|
56
|
+
continue;
|
|
57
|
+
const s = check(g, contract, env);
|
|
58
|
+
if (s)
|
|
59
|
+
skipped.push(s);
|
|
60
|
+
else
|
|
61
|
+
mounted.push(g);
|
|
62
|
+
}
|
|
63
|
+
const indexed = mounted.map((g, i) => ({ g, i }));
|
|
64
|
+
indexed.sort((a, b) => (a.g.order ?? 0) - (b.g.order ?? 0) || a.i - b.i);
|
|
65
|
+
return { mounted: indexed.map((x) => x.g), skipped };
|
|
66
|
+
}
|
|
67
|
+
/** `fiscal_data.*` cubre `fiscal_data.rfc`; un nombre exacto, sólo a sí mismo. */
|
|
68
|
+
export function matchesWrite(key, patterns) {
|
|
69
|
+
return patterns.some((p) => (p.endsWith('.*') ? key.startsWith(p.slice(0, -1)) : p === key));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Atenúa un parche: sólo pasan claves que el injerto declaró en `writes` Y que el seam
|
|
73
|
+
* acepta (`writable`). Sin `writes`, el injerto no escribe nada.
|
|
74
|
+
*/
|
|
75
|
+
export function attenuatePatch(patch, writes, writable) {
|
|
76
|
+
const allowed = {};
|
|
77
|
+
const dropped = [];
|
|
78
|
+
for (const [k, v] of Object.entries(patch ?? {})) {
|
|
79
|
+
if (writable && writable.has(k) && writes && matchesWrite(k, writes))
|
|
80
|
+
allowed[k] = v;
|
|
81
|
+
else
|
|
82
|
+
dropped.push(k);
|
|
83
|
+
}
|
|
84
|
+
return { allowed, dropped };
|
|
85
|
+
}
|
|
86
|
+
/** Sólo las lentes declaradas, congeladas (una lente no declarada no existe para el injerto). */
|
|
87
|
+
export function projectLenses(lenses, reads) {
|
|
88
|
+
const out = {};
|
|
89
|
+
for (const k of reads ?? [])
|
|
90
|
+
if (k in lenses)
|
|
91
|
+
out[k] = freeze(snapshot(lenses[k]));
|
|
92
|
+
return Object.freeze(out);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Copia para congelar sin tocar el estado del anfitrión. Objetos planos y arrays se copian en
|
|
96
|
+
* profundidad; el resto (File, Date, instancias) pasa tal cual y no se congela.
|
|
97
|
+
*/
|
|
98
|
+
function snapshot(v) {
|
|
99
|
+
if (Array.isArray(v))
|
|
100
|
+
return v.map(snapshot);
|
|
101
|
+
if (v && typeof v === 'object' && Object.getPrototypeOf(v) === Object.prototype) {
|
|
102
|
+
const o = {};
|
|
103
|
+
for (const [k, x] of Object.entries(v))
|
|
104
|
+
o[k] = snapshot(x);
|
|
105
|
+
return o;
|
|
106
|
+
}
|
|
107
|
+
return v;
|
|
108
|
+
}
|
|
109
|
+
function freeze(v) {
|
|
110
|
+
if (v && typeof v === 'object' && !Array.isArray(v) && Object.getPrototypeOf(v) !== Object.prototype)
|
|
111
|
+
return v;
|
|
112
|
+
if (v && typeof v === 'object' && !Object.isFrozen(v)) {
|
|
113
|
+
Object.freeze(v);
|
|
114
|
+
for (const x of Object.values(v))
|
|
115
|
+
freeze(x);
|
|
116
|
+
}
|
|
117
|
+
return v;
|
|
118
|
+
}
|
|
119
|
+
const SENSITIVE = new Set(['pii', 'pii.fiscal', 'secret']);
|
|
120
|
+
/** Clases sensibles que un injerto lee: si hay alguna, sus errores salen redactados. */
|
|
121
|
+
export function sensitiveClasses(contract, reads) {
|
|
122
|
+
const out = new Set();
|
|
123
|
+
for (const r of reads ?? []) {
|
|
124
|
+
const c = contract.lenses[r];
|
|
125
|
+
if (c && SENSITIVE.has(c))
|
|
126
|
+
out.add(c);
|
|
127
|
+
}
|
|
128
|
+
return [...out];
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Mensaje apto para telemetría. Un injerto que leyó datos sensibles puede haberlos metido en el
|
|
132
|
+
* mensaje de error (p. ej. `RFC XAXX010101000 inválido`): se sustituye entero.
|
|
133
|
+
*/
|
|
134
|
+
export function redactMessage(message, classes) {
|
|
135
|
+
if (!classes.length)
|
|
136
|
+
return message;
|
|
137
|
+
return `[redactado: ${classes.join(',')}]`;
|
|
138
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { GraftDef, Proposal, ResolvedSeam, SeamContract } from './types.js';
|
|
3
|
+
export interface SeamHostContext {
|
|
4
|
+
model?: string;
|
|
5
|
+
mode?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Injertos de un seam ya resueltos (montados + descartados con motivo). */
|
|
8
|
+
export declare function useSeam(contract: SeamContract, host?: SeamHostContext): ResolvedSeam;
|
|
9
|
+
export interface SeamProps {
|
|
10
|
+
contract: SeamContract;
|
|
11
|
+
/** Valores de las lentes del contrato. */
|
|
12
|
+
lenses: Readonly<Record<string, unknown>>;
|
|
13
|
+
host?: SeamHostContext;
|
|
14
|
+
/** Recibe las propuestas ya atenuadas. Sin él, el seam no acepta propuestas. */
|
|
15
|
+
onProposal?: (p: Proposal) => void;
|
|
16
|
+
/** Atiende una intención; devuelve true si la manejó. */
|
|
17
|
+
onIntent?: (intent: string, payload: unknown, graft: GraftDef) => boolean;
|
|
18
|
+
/** Mientras un injerto perezoso baja. */
|
|
19
|
+
loading?: ReactNode;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function Seam({ contract, lenses, host, onProposal, onIntent, loading, className }: SeamProps): import("react").JSX.Element | null;
|
|
23
|
+
/** Inspector de desarrollo: qué llena el seam y por qué lo demás no se montó. */
|
|
24
|
+
export declare function SeamInspector({ contract, resolved }: {
|
|
25
|
+
contract: SeamContract;
|
|
26
|
+
resolved: ResolvedSeam;
|
|
27
|
+
}): import("react").JSX.Element;
|
|
28
|
+
//# sourceMappingURL=seam.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seam.d.ts","sourceRoot":"","sources":["../../src/loom/seam.tsx"],"names":[],"mappings":"AAIA,OAAO,EASH,KAAK,SAAS,EACjB,MAAM,OAAO,CAAA;AAMd,OAAO,KAAK,EAGR,QAAQ,EAIR,QAAQ,EACR,YAAY,EACZ,YAAY,EACf,MAAM,SAAS,CAAA;AAEhB,MAAM,WAAW,eAAe;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,4EAA4E;AAC5E,wBAAgB,OAAO,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,GAAE,eAAoB,GAAG,YAAY,CAyBxF;AA6BD,MAAM,WAAW,SAAS;IACtB,QAAQ,EAAE,YAAY,CAAA;IACtB,0CAA0C;IAC1C,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACzC,IAAI,CAAC,EAAE,eAAe,CAAA;IACtB,gFAAgF;IAChF,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAA;IAClC,yDAAyD;IACzD,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAA;IACzE,yCAAyC;IACzC,OAAO,CAAC,EAAE,SAAS,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAsFD,wBAAgB,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAc,EAAE,SAAS,EAAE,EAAE,SAAS,sCAsB1G;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,YAAY,CAAA;CAAE,+BAmBvG"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// <Seam> — punto de extensión tipado. El anfitrión publica el contrato (lentes con
|
|
3
|
+
// clase de datos, campos escribibles, intenciones) y Seam monta los injertos que
|
|
4
|
+
// lo cumplen: cada uno aislado (error boundary + Suspense + carga perezosa), con
|
|
5
|
+
// sólo las lentes que declaró y un `propose` atenuado a sus `writes`.
|
|
6
|
+
import { lazy, Suspense, useCallback, useMemo, useRef, useSyncExternalStore, } from 'react';
|
|
7
|
+
import { FederatedErrorBoundary } from '../federated-error-boundary.js';
|
|
8
|
+
import { useCan } from '../permissions-context.js';
|
|
9
|
+
import { useLoomConfig } from './provider.js';
|
|
10
|
+
import { attenuatePatch, projectLenses, redactMessage, resolveSeam, sensitiveClasses } from './resolve.js';
|
|
11
|
+
import { getPart, listGrafts, loomVersion, subscribeLoom } from './store.js';
|
|
12
|
+
/** Injertos de un seam ya resueltos (montados + descartados con motivo). */
|
|
13
|
+
export function useSeam(contract, host = {}) {
|
|
14
|
+
const cfg = useLoomConfig();
|
|
15
|
+
const can = useCan();
|
|
16
|
+
const v = useSyncExternalStore(subscribeLoom, loomVersion, loomVersion);
|
|
17
|
+
return useMemo(() => {
|
|
18
|
+
const local = listGrafts(contract.id);
|
|
19
|
+
const byId = new Map();
|
|
20
|
+
for (const g of local)
|
|
21
|
+
byId.set(g.id, g);
|
|
22
|
+
// Lo servido manda en metadatos (orden, props); el código local aporta el componente.
|
|
23
|
+
for (const s of cfg?.grafts ?? []) {
|
|
24
|
+
if (s.seam !== contract.id)
|
|
25
|
+
continue;
|
|
26
|
+
const l = byId.get(s.id);
|
|
27
|
+
byId.set(s.id, l ? { ...l, ...s, component: l.component, load: s.load ?? l.load, part: s.part ?? l.part } : s);
|
|
28
|
+
}
|
|
29
|
+
const granted = cfg?.serverAuthoritative ? new Set((cfg.grafts ?? []).map((g) => g.id)) : undefined;
|
|
30
|
+
return resolveSeam(contract, [...byId.values()], {
|
|
31
|
+
can,
|
|
32
|
+
flags: cfg?.flags,
|
|
33
|
+
settings: cfg?.settings,
|
|
34
|
+
model: host.model,
|
|
35
|
+
mode: host.mode,
|
|
36
|
+
granted,
|
|
37
|
+
});
|
|
38
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
39
|
+
}, [contract, cfg, can, host.model, host.mode, v]);
|
|
40
|
+
}
|
|
41
|
+
const lazyCache = new WeakMap();
|
|
42
|
+
function toLazy(load) {
|
|
43
|
+
let c = lazyCache.get(load);
|
|
44
|
+
if (!c) {
|
|
45
|
+
c = lazy(async () => {
|
|
46
|
+
const mod = await load();
|
|
47
|
+
const C = mod.default ?? mod;
|
|
48
|
+
if (typeof C !== 'function' && !(C && typeof C === 'object' && '$$typeof' in C)) {
|
|
49
|
+
throw new Error('el módulo del injerto no exporta un componente');
|
|
50
|
+
}
|
|
51
|
+
return { default: C };
|
|
52
|
+
});
|
|
53
|
+
lazyCache.set(load, c);
|
|
54
|
+
}
|
|
55
|
+
return c;
|
|
56
|
+
}
|
|
57
|
+
function componentOf(g) {
|
|
58
|
+
if (g.component)
|
|
59
|
+
return g.component;
|
|
60
|
+
if (g.load)
|
|
61
|
+
return toLazy(g.load);
|
|
62
|
+
const p = g.part ? getPart(g.part) : undefined;
|
|
63
|
+
if (p?.component)
|
|
64
|
+
return p.component;
|
|
65
|
+
if (p?.load)
|
|
66
|
+
return toLazy(p.load);
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
let proposalSeq = 0;
|
|
70
|
+
function GraftMount({ graft, contract, lenses, onProposal, onIntent, loading, report, }) {
|
|
71
|
+
const can = useCan();
|
|
72
|
+
const addon = graft.addon ?? graft.id.split('.')[0] ?? 'host';
|
|
73
|
+
const C = useMemo(() => componentOf(graft), [graft]);
|
|
74
|
+
const view = useMemo(() => projectLenses(lenses, graft.reads), [lenses, graft.reads]);
|
|
75
|
+
const classes = useMemo(() => sensitiveClasses(contract, graft.reads), [contract, graft.reads]);
|
|
76
|
+
const live = useRef({ onProposal, onIntent, report });
|
|
77
|
+
live.current = { onProposal, onIntent, report };
|
|
78
|
+
const propose = useCallback((input) => {
|
|
79
|
+
const { allowed, dropped } = attenuatePatch(input.patch, graft.writes, contract.writable);
|
|
80
|
+
if (dropped.length) {
|
|
81
|
+
live.current.report({ type: 'proposal_dropped_keys', seam: contract.id, graft: graft.id, addon, keys: dropped });
|
|
82
|
+
}
|
|
83
|
+
if (!Object.keys(allowed).length || !live.current.onProposal)
|
|
84
|
+
return;
|
|
85
|
+
live.current.onProposal({
|
|
86
|
+
...input,
|
|
87
|
+
patch: allowed,
|
|
88
|
+
id: `${graft.id}#${++proposalSeq}`,
|
|
89
|
+
graft: graft.id,
|
|
90
|
+
addon,
|
|
91
|
+
previous: {},
|
|
92
|
+
dropped,
|
|
93
|
+
});
|
|
94
|
+
}, [graft.id, graft.writes, contract.id, contract.writable, addon]);
|
|
95
|
+
const emit = useCallback((intent, payload) => {
|
|
96
|
+
if (!contract.intents?.includes(intent))
|
|
97
|
+
return false;
|
|
98
|
+
return live.current.onIntent?.(intent, payload, graft) ?? false;
|
|
99
|
+
}, [contract.intents, graft]);
|
|
100
|
+
const caps = useMemo(() => ({ propose, emit, can }), [propose, emit, can]);
|
|
101
|
+
const meta = useMemo(() => ({ id: graft.id, addon, seam: contract.id }), [graft.id, addon, contract.id]);
|
|
102
|
+
if (!C)
|
|
103
|
+
return null;
|
|
104
|
+
return (_jsx("div", { "data-loom-graft": graft.id, "data-loom-addon": addon, style: { display: 'contents' }, children: _jsx(FederatedErrorBoundary, { addonKey: addon, onError: (err) => report({
|
|
105
|
+
type: 'graft_failed',
|
|
106
|
+
seam: contract.id,
|
|
107
|
+
graft: graft.id,
|
|
108
|
+
addon,
|
|
109
|
+
reason: 'render',
|
|
110
|
+
message: redactMessage(err.message, classes),
|
|
111
|
+
}),
|
|
112
|
+
// Falla en silencio: el anfitrión sigue igual que sin el injerto.
|
|
113
|
+
fallback: () => null, children: _jsx(Suspense, { fallback: loading, children: _jsx(C, { lenses: view, props: graft.props ?? EMPTY, caps: caps, graft: meta }) }) }) }));
|
|
114
|
+
}
|
|
115
|
+
const EMPTY = Object.freeze({});
|
|
116
|
+
export function Seam({ contract, lenses, host, onProposal, onIntent, loading = null, className }) {
|
|
117
|
+
const cfg = useLoomConfig();
|
|
118
|
+
const resolved = useSeam(contract, host);
|
|
119
|
+
const report = useCallback((e) => cfg?.onEvent?.(e), [cfg]);
|
|
120
|
+
if (!resolved.mounted.length && !cfg?.inspect)
|
|
121
|
+
return null;
|
|
122
|
+
return (_jsxs("div", { "data-loom-seam": contract.id, "data-loom-seam-version": contract.version, className: className, style: className ? undefined : { display: 'contents' }, children: [resolved.mounted.map((g) => (_jsx(GraftMount, { graft: g, contract: contract, lenses: lenses, onProposal: onProposal, onIntent: onIntent, loading: loading, report: report }, g.id))), cfg?.inspect ? _jsx(SeamInspector, { contract: contract, resolved: resolved }) : null] }));
|
|
123
|
+
}
|
|
124
|
+
/** Inspector de desarrollo: qué llena el seam y por qué lo demás no se montó. */
|
|
125
|
+
export function SeamInspector({ contract, resolved }) {
|
|
126
|
+
return (_jsxs("details", { "data-loom-inspector": contract.id, className: "rounded border border-dashed border-primary/50 px-2 py-1 text-[11px] text-muted-foreground", children: [_jsxs("summary", { children: [contract.id, "@", contract.version, " \u00B7 ", resolved.mounted.length, " montados \u00B7 ", resolved.skipped.length, " no"] }), _jsxs("ul", { children: [resolved.mounted.map((g) => (_jsxs("li", { children: ["montado: ", g.id] }, g.id))), resolved.skipped.map((s) => (_jsxs("li", { children: ["no montado: ", s.graft.id, ": ", s.reason, s.detail ? ` (${s.detail})` : ''] }, s.graft.id)))] })] }));
|
|
127
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SeamContract } from './types.js';
|
|
2
|
+
/** Arriba del formulario de DynamicRecordDialog (alta/edición). */
|
|
3
|
+
export declare const RECORD_DIALOG_HEADER = "record.dialog.header";
|
|
4
|
+
/** Debajo de los campos del formulario, antes del pie: contenido (no sólo botones) dentro del modal. */
|
|
5
|
+
export declare const RECORD_FORM_SECTION = "record.form.section";
|
|
6
|
+
export type RecordFormSeam = typeof RECORD_DIALOG_HEADER | typeof RECORD_FORM_SECTION;
|
|
7
|
+
export interface RecordDialogHeaderLenses {
|
|
8
|
+
/** Modelo del formulario (`Customer`). */
|
|
9
|
+
model: string;
|
|
10
|
+
mode: 'create' | 'edit';
|
|
11
|
+
/** Id del registro en edición. */
|
|
12
|
+
recordId?: string;
|
|
13
|
+
/** Valores vivos del formulario. Clase `pii`: pueden traer datos personales. */
|
|
14
|
+
values: Record<string, unknown>;
|
|
15
|
+
/** Campos del formulario: `{ key, label, type }`. */
|
|
16
|
+
fields: Array<{
|
|
17
|
+
key: string;
|
|
18
|
+
label: string;
|
|
19
|
+
type?: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Contrato v1 de `record.dialog.header` y `record.form.section` (mismas lentes y propuestas).
|
|
24
|
+
* `writable` = campos editables que el formulario
|
|
25
|
+
* declara (lo calcula el diálogo). Intenciones:
|
|
26
|
+
* - `record.select` `{ record }`: usar un registro existente en lugar de crear (p. ej. el
|
|
27
|
+
* RFC ya existe). Lo atiende quien abrió el diálogo (CustomerPicker la convierte en selección).
|
|
28
|
+
* - `record.edit` `{ id, patch }`: abrir la edición de otro registro con `patch` como propuesta.
|
|
29
|
+
*/
|
|
30
|
+
export declare function recordDialogHeaderContract(writable: ReadonlySet<string>, id?: RecordFormSeam): SeamContract;
|
|
31
|
+
//# sourceMappingURL=seams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seams.d.ts","sourceRoot":"","sources":["../../src/loom/seams.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C,mEAAmE;AACnE,eAAO,MAAM,oBAAoB,yBAAyB,CAAA;AAC1D,wGAAwG;AACxG,eAAO,MAAM,mBAAmB,wBAAwB,CAAA;AACxD,MAAM,MAAM,cAAc,GAAG,OAAO,oBAAoB,GAAG,OAAO,mBAAmB,CAAA;AAErF,MAAM,WAAW,wBAAwB;IACrC,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,QAAQ,GAAG,MAAM,CAAA;IACvB,kCAAkC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gFAAgF;IAChF,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,qDAAqD;IACrD,MAAM,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAC/D;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACtC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,EAC7B,EAAE,GAAE,cAAqC,GAC1C,YAAY,CAQd"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Arriba del formulario de DynamicRecordDialog (alta/edición). */
|
|
2
|
+
export const RECORD_DIALOG_HEADER = 'record.dialog.header';
|
|
3
|
+
/** Debajo de los campos del formulario, antes del pie: contenido (no sólo botones) dentro del modal. */
|
|
4
|
+
export const RECORD_FORM_SECTION = 'record.form.section';
|
|
5
|
+
/**
|
|
6
|
+
* Contrato v1 de `record.dialog.header` y `record.form.section` (mismas lentes y propuestas).
|
|
7
|
+
* `writable` = campos editables que el formulario
|
|
8
|
+
* declara (lo calcula el diálogo). Intenciones:
|
|
9
|
+
* - `record.select` `{ record }`: usar un registro existente en lugar de crear (p. ej. el
|
|
10
|
+
* RFC ya existe). Lo atiende quien abrió el diálogo (CustomerPicker la convierte en selección).
|
|
11
|
+
* - `record.edit` `{ id, patch }`: abrir la edición de otro registro con `patch` como propuesta.
|
|
12
|
+
*/
|
|
13
|
+
export function recordDialogHeaderContract(writable, id = RECORD_DIALOG_HEADER) {
|
|
14
|
+
return {
|
|
15
|
+
id,
|
|
16
|
+
version: '1.0.0',
|
|
17
|
+
lenses: { model: 'public', mode: 'public', recordId: 'internal', values: 'pii', fields: 'public' },
|
|
18
|
+
writable,
|
|
19
|
+
intents: ['record.select', 'record.edit'],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { GraftDef, PartDef } from './types.js';
|
|
2
|
+
type Listener = () => void;
|
|
3
|
+
/** Registra (o reemplaza, mismo id) un injerto. Devuelve el disposer. */
|
|
4
|
+
export declare function registerGraft(def: GraftDef): () => void;
|
|
5
|
+
/** Registra (o reemplaza) un componente expuesto. */
|
|
6
|
+
export declare function registerPart(def: PartDef): () => void;
|
|
7
|
+
export declare function getPart(id: string): PartDef | undefined;
|
|
8
|
+
/** Injertos registrados para un seam, en orden de registro. */
|
|
9
|
+
export declare function listGrafts(seam?: string): GraftDef[];
|
|
10
|
+
/** Quita todo lo de un addon (unbind). Devuelve cuántas entradas. */
|
|
11
|
+
export declare function unregisterLoomByAddon(addon: string): number;
|
|
12
|
+
export declare function clearLoom(): void;
|
|
13
|
+
export declare function subscribeLoom(l: Listener): () => void;
|
|
14
|
+
export declare function loomVersion(): number;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/loom/store.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEhD,KAAK,QAAQ,GAAG,MAAM,IAAI,CAAA;AAa1B,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,IAAI,CAUvD;AAED,qDAAqD;AACrD,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,IAAI,CASrD;AAED,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAEvD;AAED,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,EAAE,CAKpD;AAED,qEAAqE;AACrE,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED,wBAAgB,SAAS,IAAI,IAAI,CAKhC;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,IAAI,CAKrD;AAED,wBAAgB,WAAW,IAAI,MAAM,CAEpC"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const grafts = new Map();
|
|
2
|
+
const parts = new Map();
|
|
3
|
+
const listeners = new Set();
|
|
4
|
+
let version = 0;
|
|
5
|
+
let seq = 0;
|
|
6
|
+
function emit() {
|
|
7
|
+
version++;
|
|
8
|
+
for (const l of [...listeners])
|
|
9
|
+
l();
|
|
10
|
+
}
|
|
11
|
+
/** Registra (o reemplaza, mismo id) un injerto. Devuelve el disposer. */
|
|
12
|
+
export function registerGraft(def) {
|
|
13
|
+
const entry = { def, seq: ++seq };
|
|
14
|
+
grafts.set(def.id, entry);
|
|
15
|
+
emit();
|
|
16
|
+
return () => {
|
|
17
|
+
if (grafts.get(def.id) === entry) {
|
|
18
|
+
grafts.delete(def.id);
|
|
19
|
+
emit();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Registra (o reemplaza) un componente expuesto. */
|
|
24
|
+
export function registerPart(def) {
|
|
25
|
+
parts.set(def.id, def);
|
|
26
|
+
emit();
|
|
27
|
+
return () => {
|
|
28
|
+
if (parts.get(def.id) === def) {
|
|
29
|
+
parts.delete(def.id);
|
|
30
|
+
emit();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export function getPart(id) {
|
|
35
|
+
return parts.get(id);
|
|
36
|
+
}
|
|
37
|
+
/** Injertos registrados para un seam, en orden de registro. */
|
|
38
|
+
export function listGrafts(seam) {
|
|
39
|
+
return [...grafts.values()]
|
|
40
|
+
.filter((e) => !seam || e.def.seam === seam)
|
|
41
|
+
.sort((a, b) => a.seq - b.seq)
|
|
42
|
+
.map((e) => e.def);
|
|
43
|
+
}
|
|
44
|
+
/** Quita todo lo de un addon (unbind). Devuelve cuántas entradas. */
|
|
45
|
+
export function unregisterLoomByAddon(addon) {
|
|
46
|
+
let n = 0;
|
|
47
|
+
for (const [id, e] of [...grafts])
|
|
48
|
+
if (e.def.addon === addon)
|
|
49
|
+
(grafts.delete(id), n++);
|
|
50
|
+
for (const [id, p] of [...parts])
|
|
51
|
+
if (p.addon === addon)
|
|
52
|
+
(parts.delete(id), n++);
|
|
53
|
+
if (n)
|
|
54
|
+
emit();
|
|
55
|
+
return n;
|
|
56
|
+
}
|
|
57
|
+
export function clearLoom() {
|
|
58
|
+
if (!grafts.size && !parts.size)
|
|
59
|
+
return;
|
|
60
|
+
grafts.clear();
|
|
61
|
+
parts.clear();
|
|
62
|
+
emit();
|
|
63
|
+
}
|
|
64
|
+
export function subscribeLoom(l) {
|
|
65
|
+
listeners.add(l);
|
|
66
|
+
return () => {
|
|
67
|
+
listeners.delete(l);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
export function loomVersion() {
|
|
71
|
+
return version;
|
|
72
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
/** Clase de datos de una lente. Decide la redacción en errores/telemetría. */
|
|
3
|
+
export type DataClass = 'public' | 'internal' | 'money' | 'pii' | 'pii.fiscal' | 'secret';
|
|
4
|
+
/** Contrato que el anfitrión publica para un seam. */
|
|
5
|
+
export interface SeamContract {
|
|
6
|
+
id: string;
|
|
7
|
+
/** Semver del contrato (`1.0.0`). Un injerto declara `requires: '^1'`. */
|
|
8
|
+
version: string;
|
|
9
|
+
/** Lentes que el seam ofrece y su clase de datos. */
|
|
10
|
+
lenses: Readonly<Record<string, DataClass>>;
|
|
11
|
+
/**
|
|
12
|
+
* Campos que un injerto puede proponer cambiar en este seam. `undefined` = el seam no
|
|
13
|
+
* acepta propuestas. El anfitrión lo calcula (p. ej. los campos editables del formulario).
|
|
14
|
+
*/
|
|
15
|
+
writable?: ReadonlySet<string>;
|
|
16
|
+
/** Intenciones que el anfitrión atiende (`record.select`, `record.edit`). */
|
|
17
|
+
intents?: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export type GraftKind = 'view' | 'action' | 'transform' | 'source';
|
|
20
|
+
/** Condiciones de montaje. Todas las presentes deben cumplirse. */
|
|
21
|
+
export interface GraftWhen {
|
|
22
|
+
/** Todos estos permisos RBAC. */
|
|
23
|
+
permission?: string | string[];
|
|
24
|
+
/** Al menos uno de estos permisos. */
|
|
25
|
+
anyPermission?: string[];
|
|
26
|
+
/** Feature flag activo. */
|
|
27
|
+
flag?: string;
|
|
28
|
+
/** Ajuste de la organización/addon: presente y verdadero, o igual a `equals`. */
|
|
29
|
+
setting?: {
|
|
30
|
+
key: string;
|
|
31
|
+
equals?: unknown;
|
|
32
|
+
};
|
|
33
|
+
/** Modelos del anfitrión (acepta `Customer` o `customers.Customer`). */
|
|
34
|
+
model?: string[];
|
|
35
|
+
/** Modos del anfitrión (`create`, `edit`, `view`). */
|
|
36
|
+
mode?: string[];
|
|
37
|
+
}
|
|
38
|
+
export interface GraftCapabilities {
|
|
39
|
+
/** Proponer un parche. Sólo pasan los campos de `writes` ∩ `contract.writable`. */
|
|
40
|
+
propose: (p: ProposalInput) => void;
|
|
41
|
+
/** Pedir al anfitrión una intención declarada en el contrato. false = nadie la atendió. */
|
|
42
|
+
emit: (intent: string, payload?: unknown) => boolean;
|
|
43
|
+
/** RBAC del usuario actual (mismo `useCan` del host). */
|
|
44
|
+
can: (permission: string) => boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface GraftProps<P = Record<string, unknown>> {
|
|
47
|
+
/** Sólo las lentes declaradas en `reads`, congeladas. */
|
|
48
|
+
lenses: Readonly<Record<string, unknown>>;
|
|
49
|
+
/** Props estáticas del manifiesto/registro. */
|
|
50
|
+
props: P;
|
|
51
|
+
caps: GraftCapabilities;
|
|
52
|
+
graft: {
|
|
53
|
+
id: string;
|
|
54
|
+
addon: string;
|
|
55
|
+
seam: string;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export type GraftComponent<P = Record<string, unknown>> = ComponentType<GraftProps<P>>;
|
|
59
|
+
export type GraftModule = GraftComponent<any> | {
|
|
60
|
+
default: GraftComponent<any>;
|
|
61
|
+
};
|
|
62
|
+
/** Componente expuesto por un addon (lo que el manifiesto llama `extension_points.parts[]`). */
|
|
63
|
+
export interface PartDef {
|
|
64
|
+
/** `<addon>.<nombre>`. */
|
|
65
|
+
id: string;
|
|
66
|
+
addon?: string;
|
|
67
|
+
version?: string;
|
|
68
|
+
component?: GraftComponent<any>;
|
|
69
|
+
/** Carga perezosa (chunk local o remoto federado). */
|
|
70
|
+
load?: () => Promise<GraftModule>;
|
|
71
|
+
}
|
|
72
|
+
export interface GraftDef {
|
|
73
|
+
/** Id estable `<addon>.<nombre>`; registrar el mismo id reemplaza. */
|
|
74
|
+
id: string;
|
|
75
|
+
addon?: string;
|
|
76
|
+
seam: string;
|
|
77
|
+
/** Rango semver del contrato del seam (`^1`). Sin él, cualquiera. */
|
|
78
|
+
requires?: string;
|
|
79
|
+
kind?: GraftKind;
|
|
80
|
+
/** Ascendente; empates por orden de registro. */
|
|
81
|
+
order?: number;
|
|
82
|
+
when?: GraftWhen;
|
|
83
|
+
/** Lentes que lee. Una lente no declarada no llega. */
|
|
84
|
+
reads?: string[];
|
|
85
|
+
/** Campos que puede proponer cambiar. Admite `prefijo.*`. */
|
|
86
|
+
writes?: string[];
|
|
87
|
+
/** Red que necesita (declarativo; lo hace cumplir el sandbox/CSP, ver RFC §Seguridad). */
|
|
88
|
+
network?: 'none' | 'org' | string[];
|
|
89
|
+
offline?: boolean;
|
|
90
|
+
props?: Record<string, unknown>;
|
|
91
|
+
/** Part que monta (registrado con `registerPart`) o el componente en línea. */
|
|
92
|
+
part?: string;
|
|
93
|
+
component?: GraftComponent<any>;
|
|
94
|
+
load?: () => Promise<GraftModule>;
|
|
95
|
+
}
|
|
96
|
+
export interface ProposalInput {
|
|
97
|
+
patch: Record<string, unknown>;
|
|
98
|
+
/** Por qué (se muestra al usuario): «Datos de la constancia fiscal». */
|
|
99
|
+
reason?: string;
|
|
100
|
+
/** 0..1. */
|
|
101
|
+
confidence?: number;
|
|
102
|
+
/** Etiquetas legibles por campo, si el injerto las conoce. */
|
|
103
|
+
labels?: Record<string, string>;
|
|
104
|
+
/** `review` (por omisión) o `auto` si el preset lo permite. */
|
|
105
|
+
apply?: 'review' | 'auto';
|
|
106
|
+
}
|
|
107
|
+
export interface Proposal extends ProposalInput {
|
|
108
|
+
id: string;
|
|
109
|
+
graft: string;
|
|
110
|
+
addon: string;
|
|
111
|
+
/** Valores antes del parche (para el diff y el deshacer). */
|
|
112
|
+
previous: Record<string, unknown>;
|
|
113
|
+
/** Claves descartadas por no estar en `writes`/`writable`. */
|
|
114
|
+
dropped: string[];
|
|
115
|
+
}
|
|
116
|
+
export type SkipReason = 'not_granted' | 'permission' | 'flag' | 'setting' | 'model' | 'mode' | 'version' | 'no_component';
|
|
117
|
+
export interface SkippedGraft {
|
|
118
|
+
graft: GraftDef;
|
|
119
|
+
reason: SkipReason;
|
|
120
|
+
detail?: string;
|
|
121
|
+
}
|
|
122
|
+
export interface ResolvedSeam {
|
|
123
|
+
mounted: GraftDef[];
|
|
124
|
+
skipped: SkippedGraft[];
|
|
125
|
+
}
|
|
126
|
+
/** Lo que el anfitrión sabe del usuario/organización para evaluar `when`. */
|
|
127
|
+
export interface LoomEnv {
|
|
128
|
+
can: (permission: string) => boolean;
|
|
129
|
+
flags?: ReadonlySet<string>;
|
|
130
|
+
settings?: Readonly<Record<string, unknown>>;
|
|
131
|
+
model?: string;
|
|
132
|
+
mode?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Ids de injertos que el servidor autorizó para este usuario. Presente = el cliente no monta
|
|
135
|
+
* nada fuera de la lista (el servidor manda). Ausente = sólo código local de confianza.
|
|
136
|
+
*/
|
|
137
|
+
granted?: ReadonlySet<string>;
|
|
138
|
+
}
|
|
139
|
+
export type LoomEvent = {
|
|
140
|
+
type: 'graft_failed';
|
|
141
|
+
seam: string;
|
|
142
|
+
graft: string;
|
|
143
|
+
addon: string;
|
|
144
|
+
reason: 'load' | 'render';
|
|
145
|
+
message: string;
|
|
146
|
+
} | {
|
|
147
|
+
type: 'proposal_dropped_keys';
|
|
148
|
+
seam: string;
|
|
149
|
+
graft: string;
|
|
150
|
+
addon: string;
|
|
151
|
+
keys: string[];
|
|
152
|
+
};
|
|
153
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/loom/types.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,KAAK,GAAG,YAAY,GAAG,QAAQ,CAAA;AAEzF,sDAAsD;AACtD,MAAM,WA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Y;IACzB,OAAO,EAAE,QAAQ,EAAE,CAAA;IACnB,OAAO,EAAE,YAAY,EAAE,CAAA;CAC1B;AAED,6EAA6E;AAC7E,MAAM,WAAW,OAAO;IACpB,GAAG,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,OAAO,CAAA;IACpC,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3B,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAChC;AAED,MAAM,MAAM,SAAS,GACf;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAChH;IAAE,IAAI,EAAE,uBAAuB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/model-labels.d.ts
CHANGED
|
@@ -13,6 +13,12 @@
|
|
|
13
13
|
* `models.<model>.new` exists the label is `common.new_model` interpolated
|
|
14
14
|
* with the singular name (`{{prefix}} {{name}}`), prefix overridable via
|
|
15
15
|
* `common.new`.
|
|
16
|
+
*
|
|
17
|
+
* Backend-declared names (already localized by the kernel/bridge) slot in below
|
|
18
|
+
* the host i18n keys: `singular_label` feeds the singular and `new_label` the
|
|
19
|
+
* create label, so a backend that ships "cliente"/"Nuevo cliente" never needs a
|
|
20
|
+
* per-model i18n entry. The create prefix honours grammatical gender
|
|
21
|
+
* (`common.new_f` = "Nueva", `common.new_m` = "Nuevo") before the neutral `common.new`.
|
|
16
22
|
*/
|
|
17
23
|
export type ModelLabelT = (key: string, opts?: Record<string, unknown>) => string;
|
|
18
24
|
export interface ModelLabelInput {
|
|
@@ -25,6 +31,12 @@ export interface ModelLabelInput {
|
|
|
25
31
|
newPrefix?: string;
|
|
26
32
|
titleOverride?: string;
|
|
27
33
|
newLabelOverride?: string;
|
|
34
|
+
/** Backend singular noun (`singular_label`), e.g. "cliente". */
|
|
35
|
+
singularLabel?: string;
|
|
36
|
+
/** Backend create label (`new_label`), e.g. "Nuevo cliente". */
|
|
37
|
+
newLabelMeta?: string;
|
|
38
|
+
/** Grammatical gender of the singular ("m" | "f" | "n"); picks `common.new_<gender>`. */
|
|
39
|
+
gender?: string;
|
|
28
40
|
}
|
|
29
41
|
export interface ModelLabels {
|
|
30
42
|
title: string;
|
|
@@ -33,6 +45,20 @@ export interface ModelLabels {
|
|
|
33
45
|
}
|
|
34
46
|
export declare function defaultSingular(title: string): string;
|
|
35
47
|
export declare function resolveModelLabels(t: ModelLabelT, input: ModelLabelInput): ModelLabels;
|
|
48
|
+
export interface ModelNounInput {
|
|
49
|
+
model: string;
|
|
50
|
+
singularLabel?: string;
|
|
51
|
+
titleKey?: string;
|
|
52
|
+
title?: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Noun used inside dialog verbs ("Editar {noun}"). Order: host i18n
|
|
56
|
+
* `models.<model>.singular` > backend `singular_label` > translated `titleKey`
|
|
57
|
+
* > backend `title`. Empty string when nothing is known (caller falls back).
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveModelNoun(t: ModelLabelT, input: ModelNounInput): string;
|
|
60
|
+
/** Dialog verb ("Crear {{name}}", "Editar {{name}}", "Eliminar {{name}}") through i18n `dynamic.<verb>_title`. */
|
|
61
|
+
export declare function modelVerbTitle(t: ModelLabelT, verb: 'create' | 'edit' | 'delete', name: string, fallback: string): string;
|
|
36
62
|
/** Hook form of {@link resolveModelLabels}, bound to the active i18n instance. */
|
|
37
63
|
export declare function useModelLabels(input: ModelLabelInput): ModelLabels;
|
|
38
64
|
//# sourceMappingURL=model-labels.d.ts.map
|