@asteby/metacore-runtime-react 53.28.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 +18 -0
- package/dist/business/customer-picker.d.ts.map +1 -1
- package/dist/business/customer-picker.js +4 -0
- 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 +16 -1
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +49 -3
- package/dist/dialogs/types.d.ts +4 -0
- package/dist/dialogs/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- 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/record-picker-dialog.d.ts +7 -1
- package/dist/record-picker-dialog.d.ts.map +1 -1
- package/dist/record-picker-dialog.js +18 -3
- package/package.json +6 -6
- package/src/__tests__/dynamic-record-seam.test.tsx +194 -0
- package/src/__tests__/loom-overlay.test.ts +94 -0
- package/src/__tests__/loom-resolve.test.ts +108 -0
- package/src/business/customer-picker.tsx +4 -0
- package/src/dialogs/create-record-dialog.tsx +4 -0
- package/src/dialogs/dynamic-record.tsx +83 -0
- package/src/dialogs/types.ts +4 -0
- package/src/index.ts +1 -0
- 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/record-picker-dialog.tsx +37 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Proposal } from './types.js';
|
|
2
|
+
export interface ProposalQueue {
|
|
3
|
+
pending: Proposal[];
|
|
4
|
+
/** Último parche aplicado, mientras se pueda deshacer. */
|
|
5
|
+
applied: Proposal | null;
|
|
6
|
+
/** Entra a la cola (o se aplica directo si `apply: 'auto'`). */
|
|
7
|
+
push: (p: Proposal) => void;
|
|
8
|
+
accept: (id: string) => void;
|
|
9
|
+
discard: (id: string) => void;
|
|
10
|
+
undo: () => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Cola de propuestas sobre unos valores. `apply` recibe el parche a fusionar; para el
|
|
14
|
+
* deshacer se fusionan los valores previos de las claves tocadas.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useProposalQueue(values: Record<string, unknown>, apply: (patch: Record<string, unknown>) => void): ProposalQueue;
|
|
17
|
+
export interface ProposalReviewProps {
|
|
18
|
+
queue: ProposalQueue;
|
|
19
|
+
/** Etiqueta del campo (la del formulario del anfitrión). */
|
|
20
|
+
labelOf?: (key: string) => string;
|
|
21
|
+
/** Valores actuales, para el «antes». */
|
|
22
|
+
values: Record<string, unknown>;
|
|
23
|
+
}
|
|
24
|
+
/** Diff revisable de las propuestas pendientes + barra de deshacer de la última aplicada. */
|
|
25
|
+
export declare function ProposalReview({ queue, labelOf, values }: ProposalReviewProps): import("react").JSX.Element | null;
|
|
26
|
+
//# sourceMappingURL=proposals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proposals.d.ts","sourceRoot":"","sources":["../../src/loom/proposals.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,MAAM,WAAW,aAAa;IAC1B,OAAO,EAAE,QAAQ,EAAE,CAAA;IACnB,0DAA0D;IAC1D,OAAO,EAAE,QAAQ,GAAG,IAAI,CAAA;IACxB,gEAAgE;IAChE,IAAI,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAA;IAC3B,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC5B,OAAO,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7B,IAAI,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,GAChD,aAAa,CA4Cf;AAQD,MAAM,WAAW,mBAAmB;IAChC,KAAK,EAAE,aAAa,CAAA;IACpB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAA;IACjC,yCAAyC;IACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAClC;AAED,6FAA6F;AAC7F,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,mBAAmB,sCAmE7E"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Proposals: un injerto no muta el formulario; propone un parche. El anfitrión
|
|
3
|
+
// lo muestra como diff («antes → después»), lo aplica o lo descarta, y lo
|
|
4
|
+
// aplicado siempre se puede deshacer. Mismo flujo para la constancia fiscal,
|
|
5
|
+
// una sugerencia de precio o una sugerencia de Aby.
|
|
6
|
+
import { useCallback, useRef, useState } from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { Button } from '@asteby/metacore-ui/primitives';
|
|
9
|
+
/**
|
|
10
|
+
* Cola de propuestas sobre unos valores. `apply` recibe el parche a fusionar; para el
|
|
11
|
+
* deshacer se fusionan los valores previos de las claves tocadas.
|
|
12
|
+
*/
|
|
13
|
+
export function useProposalQueue(values, apply) {
|
|
14
|
+
const [pending, setPending] = useState([]);
|
|
15
|
+
const [applied, setApplied] = useState(null);
|
|
16
|
+
const valuesRef = useRef(values);
|
|
17
|
+
valuesRef.current = values;
|
|
18
|
+
const commit = useCallback((p) => {
|
|
19
|
+
// El "antes" se toma al aplicar (el usuario pudo teclear desde que llegó la propuesta).
|
|
20
|
+
const previous = {};
|
|
21
|
+
for (const k of Object.keys(p.patch))
|
|
22
|
+
previous[k] = valuesRef.current[k];
|
|
23
|
+
apply(p.patch);
|
|
24
|
+
setApplied({ ...p, previous });
|
|
25
|
+
}, [apply]);
|
|
26
|
+
const push = useCallback((p) => {
|
|
27
|
+
if (p.apply === 'auto')
|
|
28
|
+
commit(p);
|
|
29
|
+
else
|
|
30
|
+
setPending((list) => [...list.filter((x) => x.graft !== p.graft), p]);
|
|
31
|
+
}, [commit]);
|
|
32
|
+
const pendingRef = useRef(pending);
|
|
33
|
+
pendingRef.current = pending;
|
|
34
|
+
const appliedRef = useRef(applied);
|
|
35
|
+
appliedRef.current = applied;
|
|
36
|
+
const accept = useCallback((id) => {
|
|
37
|
+
const p = pendingRef.current.find((x) => x.id === id);
|
|
38
|
+
if (p)
|
|
39
|
+
commit(p);
|
|
40
|
+
setPending((list) => list.filter((x) => x.id !== id));
|
|
41
|
+
}, [commit]);
|
|
42
|
+
const discard = useCallback((id) => setPending((list) => list.filter((x) => x.id !== id)), []);
|
|
43
|
+
const undo = useCallback(() => {
|
|
44
|
+
const a = appliedRef.current;
|
|
45
|
+
if (a)
|
|
46
|
+
apply(a.previous);
|
|
47
|
+
setApplied(null);
|
|
48
|
+
}, [apply]);
|
|
49
|
+
return { pending, applied, push, accept, discard, undo };
|
|
50
|
+
}
|
|
51
|
+
const show = (v) => {
|
|
52
|
+
if (v == null || v === '')
|
|
53
|
+
return '—';
|
|
54
|
+
if (typeof v === 'object')
|
|
55
|
+
return v.label ?? JSON.stringify(v);
|
|
56
|
+
return String(v);
|
|
57
|
+
};
|
|
58
|
+
/** Diff revisable de las propuestas pendientes + barra de deshacer de la última aplicada. */
|
|
59
|
+
export function ProposalReview({ queue, labelOf, values }) {
|
|
60
|
+
const { t } = useTranslation();
|
|
61
|
+
const label = (p, k) => p.labels?.[k] ?? labelOf?.(k) ?? k;
|
|
62
|
+
if (!queue.pending.length && !queue.applied)
|
|
63
|
+
return null;
|
|
64
|
+
return (_jsxs("div", { className: "grid gap-2", "data-loom-proposals": "", children: [queue.pending.map((p) => {
|
|
65
|
+
const keys = Object.keys(p.patch);
|
|
66
|
+
return (_jsxs("section", { "aria-label": p.reason ?? t('loom.proposal.title', { defaultValue: 'Cambios propuestos' }), "data-loom-proposal": p.graft, className: "rounded-lg border bg-muted/40 p-3 text-sm", children: [_jsx("p", { className: "font-medium", children: p.reason ?? t('loom.proposal.title', { defaultValue: 'Cambios propuestos' }) }), _jsxs("table", { className: "mt-2 w-full text-xs", children: [_jsx("thead", { className: "sr-only", children: _jsxs("tr", { children: [_jsx("th", { children: t('loom.proposal.field', { defaultValue: 'Campo' }) }), _jsx("th", { children: t('loom.proposal.before', { defaultValue: 'Antes' }) }), _jsx("th", { children: t('loom.proposal.after', { defaultValue: 'Después' }) })] }) }), _jsx("tbody", { children: keys.map((k) => {
|
|
67
|
+
const same = show(values[k]) === show(p.patch[k]);
|
|
68
|
+
return (_jsxs("tr", { "data-field": k, className: same ? 'text-muted-foreground' : undefined, children: [_jsx("td", { className: "py-0.5 pr-2 font-medium", children: label(p, k) }), _jsx("td", { className: "py-0.5 pr-2 text-muted-foreground line-through decoration-muted-foreground/50", children: same ? '' : show(values[k]) }), _jsx("td", { className: "py-0.5", children: show(p.patch[k]) })] }, k));
|
|
69
|
+
}) })] }), _jsxs("div", { className: "mt-2 flex gap-2", children: [_jsx(Button, { type: "button", size: "sm", onClick: () => queue.accept(p.id), children: t('loom.proposal.apply', { defaultValue: 'Aplicar' }) }), _jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => queue.discard(p.id), children: t('loom.proposal.discard', { defaultValue: 'Descartar' }) })] })] }, p.id));
|
|
70
|
+
}), queue.applied ? (_jsxs("div", { role: "status", className: "flex items-center justify-between gap-2 rounded-lg border px-3 py-2 text-xs", "data-loom-applied": "", children: [_jsx("span", { children: t('loom.proposal.applied', {
|
|
71
|
+
defaultValue: 'Se aplicaron {{count}} campos',
|
|
72
|
+
count: Object.keys(queue.applied.patch).length,
|
|
73
|
+
}) }), _jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: queue.undo, children: t('loom.proposal.undo', { defaultValue: 'Deshacer' }) })] })) : null] }));
|
|
74
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { GraftDef, LoomEvent } from './types.js';
|
|
3
|
+
export interface LoomConfig {
|
|
4
|
+
/** Injertos servidos por el servidor (ya filtrados por RBAC/ajustes/preset). */
|
|
5
|
+
grafts: readonly GraftDef[];
|
|
6
|
+
/**
|
|
7
|
+
* Si es true, sólo se montan injertos cuyo id está en `grafts` (los registrados en proceso
|
|
8
|
+
* sin autorización del servidor se explican como `not_granted`).
|
|
9
|
+
*/
|
|
10
|
+
serverAuthoritative: boolean;
|
|
11
|
+
flags?: ReadonlySet<string>;
|
|
12
|
+
settings?: Readonly<Record<string, unknown>>;
|
|
13
|
+
onEvent?: (e: LoomEvent) => void;
|
|
14
|
+
/** Pinta el inspector de seams (desarrollo). */
|
|
15
|
+
inspect?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface LoomProviderProps {
|
|
18
|
+
grafts?: readonly GraftDef[];
|
|
19
|
+
serverAuthoritative?: boolean;
|
|
20
|
+
flags?: Iterable<string>;
|
|
21
|
+
settings?: Readonly<Record<string, unknown>>;
|
|
22
|
+
onEvent?: (e: LoomEvent) => void;
|
|
23
|
+
inspect?: boolean;
|
|
24
|
+
children?: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
export declare function LoomProvider({ grafts, serverAuthoritative, flags, settings, onEvent, inspect, children, }: LoomProviderProps): import("react").JSX.Element;
|
|
27
|
+
export declare function useLoomConfig(): LoomConfig | null;
|
|
28
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/loom/provider.tsx"],"names":[],"mappings":"AAIA,OAAO,EAA8C,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAClF,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAElD,MAAM,WAAW,UAAU;IACvB,gFAAgF;IAChF,MAAM,EAAE,SAAS,QAAQ,EAAE,CAAA;IAC3B;;;OAGG;IACH,mBAAmB,EAAE,OAAO,CAAA;IAC5B,KAAK,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3B,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAC5C,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAA;IAChC,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAID,MAAM,WAAW,iBAAiB;IAC9B,MAAM,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAA;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAA;IACxB,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAC5C,OAAO,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAA;IAChC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACvB;AAED,wBAAgB,YAAY,CAAC,EACzB,MAAW,EACX,mBAA2B,EAC3B,KAAK,EACL,QAAQ,EACR,OAAO,EACP,OAAe,EACf,QAAQ,GACX,EAAE,iBAAiB,+BAsBnB;AAED,wBAAgB,aAAa,IAAI,UAAU,GAAG,IAAI,CAEjD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// LoomProvider — lo que el anfitrión sabe para resolver seams: los injertos que
|
|
3
|
+
// el SERVIDOR autorizó (respuesta de GET /api/ui/grafts, ver RFC 0005 §5), flags,
|
|
4
|
+
// ajustes de la organización y el canal de telemetría. Sin provider, <Seam> sólo
|
|
5
|
+
// monta injertos registrados en proceso (código local de confianza).
|
|
6
|
+
import { createContext, useContext, useMemo, useRef } from 'react';
|
|
7
|
+
const Ctx = createContext(null);
|
|
8
|
+
export function LoomProvider({ grafts = [], serverAuthoritative = false, flags, settings, onEvent, inspect = false, children, }) {
|
|
9
|
+
const onEventRef = useRef(onEvent);
|
|
10
|
+
onEventRef.current = onEvent;
|
|
11
|
+
const flagKey = flags ? [...flags].sort().join(',') : '';
|
|
12
|
+
const value = useMemo(() => ({
|
|
13
|
+
grafts,
|
|
14
|
+
serverAuthoritative,
|
|
15
|
+
flags: new Set(flagKey ? flagKey.split(',') : []),
|
|
16
|
+
settings,
|
|
17
|
+
inspect,
|
|
18
|
+
onEvent: (e) => {
|
|
19
|
+
try {
|
|
20
|
+
onEventRef.current?.(e);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
/* un reporter roto no tumba al anfitrión */
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
}), [grafts, serverAuthoritative, flagKey, settings, inspect]);
|
|
27
|
+
return _jsx(Ctx.Provider, { value: value, children: children });
|
|
28
|
+
}
|
|
29
|
+
export function useLoomConfig() {
|
|
30
|
+
return useContext(Ctx);
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { DataClass, GraftDef, LoomEnv, ResolvedSeam, SeamContract } from './types.js';
|
|
2
|
+
/** Orden canónico: `order` ascendente, luego orden de entrada (estable). */
|
|
3
|
+
export declare function resolveSeam(contract: SeamContract, candidates: readonly GraftDef[], env: LoomEnv): ResolvedSeam;
|
|
4
|
+
/** `fiscal_data.*` cubre `fiscal_data.rfc`; un nombre exacto, sólo a sí mismo. */
|
|
5
|
+
export declare function matchesWrite(key: string, patterns: readonly string[]): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Atenúa un parche: sólo pasan claves que el injerto declaró en `writes` Y que el seam
|
|
8
|
+
* acepta (`writable`). Sin `writes`, el injerto no escribe nada.
|
|
9
|
+
*/
|
|
10
|
+
export declare function attenuatePatch(patch: Record<string, unknown>, writes: readonly string[] | undefined, writable: ReadonlySet<string> | undefined): {
|
|
11
|
+
allowed: Record<string, unknown>;
|
|
12
|
+
dropped: string[];
|
|
13
|
+
};
|
|
14
|
+
/** Sólo las lentes declaradas, congeladas (una lente no declarada no existe para el injerto). */
|
|
15
|
+
export declare function projectLenses(lenses: Readonly<Record<string, unknown>>, reads: readonly string[] | undefined): Readonly<Record<string, unknown>>;
|
|
16
|
+
/** Clases sensibles que un injerto lee: si hay alguna, sus errores salen redactados. */
|
|
17
|
+
export declare function sensitiveClasses(contract: SeamContract, reads: readonly string[] | undefined): DataClass[];
|
|
18
|
+
/**
|
|
19
|
+
* Mensaje apto para telemetría. Un injerto que leyó datos sensibles puede haberlos metido en el
|
|
20
|
+
* mensaje de error (p. ej. `RFC XAXX010101000 inválido`): se sustituye entero.
|
|
21
|
+
*/
|
|
22
|
+
export declare function redactMessage(message: string, classes: readonly DataClass[]): string;
|
|
23
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/loom/resolve.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAgB,MAAM,SAAS,CAAA;AAyCrG,4EAA4E;AAC5E,wBAAgB,WAAW,CAAC,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,QAAQ,EAAE,EAAE,GAAG,EAAE,OAAO,GAAG,YAAY,CAY/G;AAED,kFAAkF;AAClF,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAE9E;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EACrC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,SAAS,GAC1C;IAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAQzD;AAED,iGAAiG;AACjG,wBAAgB,aAAa,CACzB,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACzC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GACrC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAInC;AA2BD,wFAAwF;AACxF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,SAAS,EAAE,CAO1G;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAGpF"}
|
|
@@ -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
|
+
}
|