@asteby/metacore-runtime-react 47.0.0 → 48.0.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 +42 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +24 -4
- package/dist/audit-info.d.ts +54 -0
- package/dist/audit-info.d.ts.map +1 -0
- package/dist/audit-info.js +142 -0
- package/dist/business/catalog-product-search.d.ts +25 -0
- package/dist/business/catalog-product-search.d.ts.map +1 -0
- package/dist/business/catalog-product-search.js +57 -0
- package/dist/business/catalog.d.ts.map +1 -1
- package/dist/business/catalog.js +2 -0
- package/dist/business/document-editor-model.d.ts +107 -0
- package/dist/business/document-editor-model.d.ts.map +1 -0
- package/dist/business/document-editor-model.js +279 -0
- package/dist/business/document-editor-panels.d.ts +64 -0
- package/dist/business/document-editor-panels.d.ts.map +1 -0
- package/dist/business/document-editor-panels.js +58 -0
- package/dist/business/document-editor.d.ts +27 -0
- package/dist/business/document-editor.d.ts.map +1 -0
- package/dist/business/document-editor.js +445 -0
- package/dist/business/document-lines.d.ts.map +1 -1
- package/dist/business/document-lines.js +5 -1
- package/dist/business/index.d.ts +5 -0
- package/dist/business/index.d.ts.map +1 -1
- package/dist/business/index.js +5 -0
- package/dist/business/line-items.d.ts +7 -0
- package/dist/business/line-items.d.ts.map +1 -1
- package/dist/business/line-items.js +6 -1
- package/dist/business/payment-allocator.d.ts +19 -0
- package/dist/business/payment-allocator.d.ts.map +1 -0
- package/dist/business/payment-allocator.js +31 -0
- package/dist/business/product-search.d.ts +4 -0
- package/dist/business/product-search.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +19 -8
- package/dist/document-form-dialog.d.ts +31 -2
- package/dist/document-form-dialog.d.ts.map +1 -1
- package/dist/document-form-dialog.js +43 -11
- package/dist/dynamic-columns-helpers.d.ts +9 -0
- package/dist/dynamic-columns-helpers.d.ts.map +1 -1
- package/dist/dynamic-columns-helpers.js +19 -0
- package/dist/dynamic-columns.d.ts +8 -2
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +21 -5
- package/dist/dynamic-crud-page.d.ts +6 -0
- package/dist/dynamic-crud-page.d.ts.map +1 -1
- package/dist/dynamic-crud-page.js +14 -5
- package/dist/dynamic-form-schema.d.ts.map +1 -1
- package/dist/dynamic-form-schema.js +15 -3
- package/dist/dynamic-form.d.ts +16 -1
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +81 -20
- package/dist/dynamic-kanban.d.ts +9 -3
- package/dist/dynamic-kanban.d.ts.map +1 -1
- package/dist/dynamic-kanban.js +39 -13
- package/dist/dynamic-line-items.d.ts.map +1 -1
- package/dist/dynamic-line-items.js +3 -0
- package/dist/dynamic-multi-select-field.d.ts.map +1 -1
- package/dist/dynamic-multi-select-field.js +2 -0
- package/dist/dynamic-relation-helpers.d.ts.map +1 -1
- package/dist/dynamic-relation-helpers.js +8 -0
- package/dist/dynamic-relation.js +1 -1
- package/dist/dynamic-select-field.d.ts.map +1 -1
- package/dist/dynamic-select-field.js +4 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -2
- package/dist/installed-addons-context.d.ts +15 -0
- package/dist/installed-addons-context.d.ts.map +1 -0
- package/dist/installed-addons-context.js +39 -0
- package/dist/option-filter.d.ts +31 -0
- package/dist/option-filter.d.ts.map +1 -0
- package/dist/option-filter.js +49 -0
- package/dist/org-runtime-context.d.ts +8 -0
- package/dist/org-runtime-context.d.ts.map +1 -1
- package/dist/org-runtime-context.js +8 -0
- package/dist/org-runtime-provider.d.ts +3 -1
- package/dist/org-runtime-provider.d.ts.map +1 -1
- package/dist/org-runtime-provider.js +3 -3
- package/dist/primitives/aging.d.ts +34 -0
- package/dist/primitives/aging.d.ts.map +1 -0
- package/dist/primitives/aging.js +48 -0
- package/dist/primitives/allocation.d.ts +42 -0
- package/dist/primitives/allocation.d.ts.map +1 -0
- package/dist/primitives/allocation.js +59 -0
- package/dist/primitives/approvals.d.ts +71 -0
- package/dist/primitives/approvals.d.ts.map +1 -0
- package/dist/primitives/approvals.js +48 -0
- package/dist/primitives/contributions.d.ts +82 -0
- package/dist/primitives/contributions.d.ts.map +1 -0
- package/dist/primitives/contributions.js +126 -0
- package/dist/primitives/document-kinds.d.ts +25 -0
- package/dist/primitives/document-kinds.d.ts.map +1 -0
- package/dist/primitives/document-kinds.js +26 -0
- package/dist/primitives/index.d.ts +8 -0
- package/dist/primitives/index.d.ts.map +1 -0
- package/dist/primitives/index.js +23 -0
- package/dist/primitives/panels.d.ts +68 -0
- package/dist/primitives/panels.d.ts.map +1 -0
- package/dist/primitives/panels.js +3 -0
- package/dist/primitives/use-contributions.d.ts +15 -0
- package/dist/primitives/use-contributions.d.ts.map +1 -0
- package/dist/primitives/use-contributions.js +30 -0
- package/dist/record-prefill-bar.d.ts +11 -0
- package/dist/record-prefill-bar.d.ts.map +1 -0
- package/dist/record-prefill-bar.js +33 -0
- package/dist/types.d.ts +142 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/use-options-resolver.d.ts +8 -0
- package/dist/use-options-resolver.d.ts.map +1 -1
- package/dist/use-options-resolver.js +8 -2
- package/package.json +5 -5
- package/src/__tests__/action-modal-grid-layout.test.tsx +1 -1
- package/src/__tests__/apply-sidebar-layout.test.ts +1 -1
- package/src/__tests__/audit-info.test.tsx +103 -0
- package/src/__tests__/catalog-product-search.test.ts +61 -0
- package/src/__tests__/dependent-options.test.tsx +12 -5
- package/src/__tests__/document-editor-model.test.ts +167 -0
- package/src/__tests__/document-editor.test.tsx +261 -0
- package/src/__tests__/document-form-dialog.test.tsx +118 -3
- package/src/__tests__/dynamic-form-select-edit.test.tsx +155 -0
- package/src/__tests__/dynamic-kanban.test.tsx +24 -3
- package/src/__tests__/dynamic-record-extension-label.test.tsx +88 -0
- package/src/__tests__/dynamic-table-infinite-scroll.test.tsx +4 -0
- package/src/__tests__/installed-addons-context.test.tsx +50 -0
- package/src/__tests__/line-item-totals.test.ts +28 -0
- package/src/__tests__/line-items-lock-rows.test.tsx +2 -1
- package/src/__tests__/option-filter.test.tsx +115 -0
- package/src/__tests__/primitives-federated.test.tsx +156 -0
- package/src/__tests__/primitives.test.ts +224 -0
- package/src/__tests__/record-prefill-bar.test.tsx +50 -0
- package/src/__tests__/structured-view-value.test.tsx +5 -1
- package/src/__tests__/wizard-action-modal.test.tsx +1 -1
- package/src/action-modal-dispatcher.tsx +47 -4
- package/src/audit-info.tsx +219 -0
- package/src/business/catalog-product-search.ts +87 -0
- package/src/business/catalog.ts +2 -0
- package/src/business/document-editor-model.ts +325 -0
- package/src/business/document-editor-panels.tsx +164 -0
- package/src/business/document-editor.tsx +727 -0
- package/src/business/document-lines.ts +5 -1
- package/src/business/index.ts +5 -0
- package/src/business/line-items.ts +15 -1
- package/src/business/payment-allocator.tsx +110 -0
- package/src/business/product-search.ts +4 -0
- package/src/dialogs/dynamic-record.tsx +42 -6
- package/src/document-form-dialog.tsx +92 -12
- package/src/dropdown-menu-entry.test.ts +23 -0
- package/src/dynamic-columns-helpers.ts +22 -0
- package/src/dynamic-columns.tsx +23 -6
- package/src/dynamic-crud-page.tsx +22 -3
- package/src/dynamic-form-schema.ts +15 -2
- package/src/dynamic-form.tsx +120 -39
- package/src/dynamic-kanban.tsx +41 -10
- package/src/dynamic-line-items.tsx +3 -0
- package/src/dynamic-multi-select-field.tsx +2 -0
- package/src/dynamic-relation-helpers.ts +9 -0
- package/src/dynamic-relation.tsx +7 -2
- package/src/dynamic-select-field.tsx +4 -0
- package/src/index.ts +34 -1
- package/src/installed-addons-context.tsx +58 -0
- package/src/option-filter.ts +88 -0
- package/src/org-runtime-context.ts +10 -0
- package/src/org-runtime-provider.tsx +7 -2
- package/src/primitives/aging.ts +76 -0
- package/src/primitives/allocation.ts +104 -0
- package/src/primitives/approvals.ts +103 -0
- package/src/primitives/contributions.ts +208 -0
- package/src/primitives/document-kinds.ts +62 -0
- package/src/primitives/index.ts +23 -0
- package/src/primitives/panels.ts +59 -0
- package/src/primitives/use-contributions.ts +42 -0
- package/src/record-prefill-bar.tsx +62 -0
- package/src/row-action-stage-gate.test.ts +33 -0
- package/src/types.ts +142 -0
- package/src/use-options-resolver.ts +19 -1
- package/vitest.config.ts +1 -0
- package/vitest.setup.ts +7 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const categories = [];
|
|
2
|
+
/** Los addons registran su categoría al cargar (purchases: «Compras», fiscal_mexico: «Cancelación CFDI»…). */
|
|
3
|
+
export function registerApprovalCategory(c) {
|
|
4
|
+
categories.push(c);
|
|
5
|
+
return () => {
|
|
6
|
+
const i = categories.indexOf(c);
|
|
7
|
+
if (i >= 0)
|
|
8
|
+
categories.splice(i, 1);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export function categorize(r) {
|
|
12
|
+
return categories.find(c => c.match(r))?.key ?? 'other';
|
|
13
|
+
}
|
|
14
|
+
export function groupApprovals(items) {
|
|
15
|
+
const out = {};
|
|
16
|
+
for (const r of items)
|
|
17
|
+
(out[categorize(r)] ??= []).push(r);
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
export function parseJSONField(v) {
|
|
21
|
+
if (v == null || v === '')
|
|
22
|
+
return null;
|
|
23
|
+
if (typeof v !== 'string')
|
|
24
|
+
return v;
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(v);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Cliente fino sobre las rutas del kernel; la UI lo usa vía useApi(). */
|
|
33
|
+
export function approvalsClient(api) {
|
|
34
|
+
const qs = (q) => Object.entries(q)
|
|
35
|
+
.filter(([, v]) => v !== undefined && v !== '')
|
|
36
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
|
|
37
|
+
.join('&');
|
|
38
|
+
return {
|
|
39
|
+
list: async (q = { status: 'pending', for_me: true }) => {
|
|
40
|
+
const res = await api.get(`/approvals?${qs(q)}`);
|
|
41
|
+
return { items: (res.data?.data ?? []), total: Number(res.data?.meta?.total ?? 0) };
|
|
42
|
+
},
|
|
43
|
+
count: async () => Number((await api.get('/approvals/count')).data?.data?.count ?? 0),
|
|
44
|
+
approve: (id, reason) => api.post(`/approvals/${id}/approve`, { reason }),
|
|
45
|
+
reject: (id, reason) => api.post(`/approvals/${id}/reject`, { reason }),
|
|
46
|
+
approveWithPin: (id, pin, reason) => api.post(`/approvals/${id}/approve-pin`, { pin, reason }),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type ComponentType } from 'react';
|
|
2
|
+
/** Regiones del DocumentEditor/DocumentPage donde se puede contribuir. */
|
|
3
|
+
export type DocumentRegion = 'header.fields' | 'party.card' | 'lines.columns' | 'side.panels' | 'body.sections' | 'footer.actions';
|
|
4
|
+
export interface DocumentEditorContext {
|
|
5
|
+
kind: string;
|
|
6
|
+
model: string;
|
|
7
|
+
values: Record<string, unknown>;
|
|
8
|
+
mode: 'create' | 'edit' | 'view';
|
|
9
|
+
}
|
|
10
|
+
export interface DocumentContribution<P = DocumentContributionProps> {
|
|
11
|
+
/** Id estable `addon.region.name` (dedupe y orden). Re-registrar el mismo id reemplaza. */
|
|
12
|
+
id: string;
|
|
13
|
+
kinds: string[] | '*';
|
|
14
|
+
region: DocumentRegion;
|
|
15
|
+
/** Addon dueño. Si no está instalado, no se renderiza (y el server revalida). */
|
|
16
|
+
requiresAddon?: string;
|
|
17
|
+
/** Mayor = primero. Default 0. */
|
|
18
|
+
priority?: number;
|
|
19
|
+
when?: (ctx: DocumentEditorContext) => boolean;
|
|
20
|
+
/** Componente o loader perezoso del remote (`() => import('fiscal_mexico/CfdiSection')`). */
|
|
21
|
+
component?: ComponentType<P>;
|
|
22
|
+
load?: () => Promise<{
|
|
23
|
+
default: ComponentType<P>;
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Contribución resuelta: `component` siempre presente (si se registró con
|
|
28
|
+
* `load`, es un envoltorio lazy + Suspense que no pinta nada mientras carga).
|
|
29
|
+
*/
|
|
30
|
+
export type ResolvedDocumentContribution<P = DocumentContributionProps> = DocumentContribution<P> & {
|
|
31
|
+
component: ComponentType<P>;
|
|
32
|
+
};
|
|
33
|
+
export interface DocumentContributionProps {
|
|
34
|
+
ctx: DocumentEditorContext;
|
|
35
|
+
setValue: (key: string, value: unknown) => void;
|
|
36
|
+
issues: {
|
|
37
|
+
report: (key: string, issue: {
|
|
38
|
+
severity: 'error' | 'warning';
|
|
39
|
+
message: string;
|
|
40
|
+
}) => void;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Predicado «¿está instalado?»; `useInstalledAddons` lo arma en React. */
|
|
44
|
+
export type IsAddonInstalled = (addonKey: string) => boolean;
|
|
45
|
+
/** Suscripción para useSyncExternalStore (contribuciones y modales). */
|
|
46
|
+
export declare function subscribeContributions(listener: () => void): () => void;
|
|
47
|
+
/** Versión monotónica: cambia en cada register/dispose. */
|
|
48
|
+
export declare function contributionsVersion(): number;
|
|
49
|
+
export declare function slotIdFor(kind: string, region: DocumentRegion): string;
|
|
50
|
+
/**
|
|
51
|
+
* Registra la contribución y la publica en slotRegistry bajo cada `doc:<kind>:<region>`
|
|
52
|
+
* (kinds '*' → `doc:*:<region>`). Devuelve el disposer: AddonLoader lo llama al
|
|
53
|
+
* desmontar o recargar el remote (fiber), así la sección desaparece al desinstalar.
|
|
54
|
+
* Re-registrar el mismo `id` (recarga en caliente) reemplaza la anterior.
|
|
55
|
+
*/
|
|
56
|
+
export declare function registerDocumentContribution<P = DocumentContributionProps>(c: DocumentContribution<P>, source?: string): () => void;
|
|
57
|
+
/**
|
|
58
|
+
* Contribuciones aplicables a `region` para el documento `ctx`, ordenadas por
|
|
59
|
+
* prioridad (desc) y luego id. Pura: no lee React; `useDocumentContributions`
|
|
60
|
+
* la envuelve con useInstalledAddons.
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveContributions(ctx: DocumentEditorContext, region: DocumentRegion, isInstalled: IsAddonInstalled): ResolvedDocumentContribution<any>[];
|
|
63
|
+
export interface FederatedModal<P = any> {
|
|
64
|
+
/** Clave `<addon>.<nombre>`, la misma que `modal` en el manifest. */
|
|
65
|
+
key: string;
|
|
66
|
+
addon: string;
|
|
67
|
+
/** El dispatcher le pasa ActionModalProps (open, onOpenChange, action, model, record…). */
|
|
68
|
+
load: () => Promise<{
|
|
69
|
+
default: ComponentType<P>;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
export declare function registerFederatedModal(m: FederatedModal): () => void;
|
|
73
|
+
/** null si el modal no está registrado o su addon no está instalado. Nunca espera. */
|
|
74
|
+
export declare function resolveFederatedModal(key: string, isInstalled: IsAddonInstalled): FederatedModal | null;
|
|
75
|
+
/**
|
|
76
|
+
* Componente `React.lazy` del modal resuelto, memoizado por registro (no se
|
|
77
|
+
* re-crea en cada render). Quien lo pinta lo envuelve en `<Suspense>`.
|
|
78
|
+
*/
|
|
79
|
+
export declare function federatedModalComponent<P = any>(m: FederatedModal<P>): ComponentType<P>;
|
|
80
|
+
/** Solo para tests. */
|
|
81
|
+
export declare function __resetContributions(): void;
|
|
82
|
+
//# sourceMappingURL=contributions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contributions.d.ts","sourceRoot":"","sources":["../../src/primitives/contributions.ts"],"names":[],"mappings":"AAaA,OAAO,EAAiC,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AAGzE,0EAA0E;AAC1E,MAAM,MAAM,cAAc,GACpB,eAAe,GACf,YAAY,GACZ,eAAe,GACf,aAAa,GACb,eAAe,GACf,gBAAgB,CAAA;AAEtB,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,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"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Registro de contribuciones federadas — cómo un addon mete secciones,
|
|
2
|
+
// columnas, modales, fuentes de «Cargar desde» y vistas previas en la pantalla
|
|
3
|
+
// de OTRO addon sin que ese addon lo conozca.
|
|
4
|
+
//
|
|
5
|
+
// Se monta sobre slotRegistry (slot.tsx) — no es un segundo sistema: cada
|
|
6
|
+
// contribución es un SlotEntry con id canónico `doc:<kind>:<region>` — y añade
|
|
7
|
+
// lo que slot no tiene: `requiresAddon` (se oculta solo si el addon no está
|
|
8
|
+
// instalado o se desinstala en caliente), orden estable, `when` por documento y
|
|
9
|
+
// carga perezosa del componente (import() del remote federado).
|
|
10
|
+
//
|
|
11
|
+
// Contrato estable para remotes federados: los tipos de este archivo. Todo
|
|
12
|
+
// `register*` devuelve un disposer; el AddonLoader lo llama al desmontar o
|
|
13
|
+
// recargar el remote y la contribución desaparece sin recargar la página.
|
|
14
|
+
import { createElement, lazy, Suspense } from 'react';
|
|
15
|
+
import { slotRegistry } from '../slot';
|
|
16
|
+
const contribs = new Map();
|
|
17
|
+
const listeners = new Set();
|
|
18
|
+
let version = 0;
|
|
19
|
+
function notify() {
|
|
20
|
+
version += 1;
|
|
21
|
+
for (const l of [...listeners])
|
|
22
|
+
l();
|
|
23
|
+
}
|
|
24
|
+
/** Suscripción para useSyncExternalStore (contribuciones y modales). */
|
|
25
|
+
export function subscribeContributions(listener) {
|
|
26
|
+
listeners.add(listener);
|
|
27
|
+
return () => {
|
|
28
|
+
listeners.delete(listener);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** Versión monotónica: cambia en cada register/dispose. */
|
|
32
|
+
export function contributionsVersion() {
|
|
33
|
+
return version;
|
|
34
|
+
}
|
|
35
|
+
export function slotIdFor(kind, region) {
|
|
36
|
+
return `doc:${kind}:${region}`;
|
|
37
|
+
}
|
|
38
|
+
/** `load` → componente lazy envuelto en Suspense (fallback vacío: sin saltos de layout). */
|
|
39
|
+
function lazyComponent(load) {
|
|
40
|
+
const Lazy = lazy(load);
|
|
41
|
+
return (props) => createElement(Suspense, { fallback: null }, createElement(Lazy, props));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Registra la contribución y la publica en slotRegistry bajo cada `doc:<kind>:<region>`
|
|
45
|
+
* (kinds '*' → `doc:*:<region>`). Devuelve el disposer: AddonLoader lo llama al
|
|
46
|
+
* desmontar o recargar el remote (fiber), así la sección desaparece al desinstalar.
|
|
47
|
+
* Re-registrar el mismo `id` (recarga en caliente) reemplaza la anterior.
|
|
48
|
+
*/
|
|
49
|
+
export function registerDocumentContribution(c, source) {
|
|
50
|
+
if (!c.component && !c.load)
|
|
51
|
+
throw new Error(`contribution ${c.id}: component o load es obligatorio`);
|
|
52
|
+
contribs.get(c.id)?.dispose();
|
|
53
|
+
const resolved = { ...c, component: c.component ?? lazyComponent(c.load) };
|
|
54
|
+
const kinds = c.kinds === '*' ? ['*'] : c.kinds;
|
|
55
|
+
const slotDisposers = kinds.map(k => slotRegistry.register(slotIdFor(k, c.region), resolved.component, {
|
|
56
|
+
priority: c.priority ?? 0,
|
|
57
|
+
source: source ?? c.requiresAddon ?? c.id,
|
|
58
|
+
}));
|
|
59
|
+
let disposed = false;
|
|
60
|
+
const entry = {
|
|
61
|
+
c: resolved,
|
|
62
|
+
dispose: () => {
|
|
63
|
+
if (disposed)
|
|
64
|
+
return;
|
|
65
|
+
disposed = true;
|
|
66
|
+
slotDisposers.forEach(d => d());
|
|
67
|
+
if (contribs.get(c.id) === entry)
|
|
68
|
+
contribs.delete(c.id);
|
|
69
|
+
notify();
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
contribs.set(c.id, entry);
|
|
73
|
+
notify();
|
|
74
|
+
return entry.dispose;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Contribuciones aplicables a `region` para el documento `ctx`, ordenadas por
|
|
78
|
+
* prioridad (desc) y luego id. Pura: no lee React; `useDocumentContributions`
|
|
79
|
+
* la envuelve con useInstalledAddons.
|
|
80
|
+
*/
|
|
81
|
+
export function resolveContributions(ctx, region, isInstalled) {
|
|
82
|
+
return [...contribs.values()]
|
|
83
|
+
.map(e => e.c)
|
|
84
|
+
.filter(c => c.region === region)
|
|
85
|
+
.filter(c => c.kinds === '*' || c.kinds.includes(ctx.kind))
|
|
86
|
+
.filter(c => !c.requiresAddon || isInstalled(c.requiresAddon))
|
|
87
|
+
.filter(c => !c.when || c.when(ctx))
|
|
88
|
+
.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0) || a.id.localeCompare(b.id));
|
|
89
|
+
}
|
|
90
|
+
const modals = new Map();
|
|
91
|
+
const modalComponents = new WeakMap();
|
|
92
|
+
export function registerFederatedModal(m) {
|
|
93
|
+
modals.set(m.key, m);
|
|
94
|
+
notify();
|
|
95
|
+
return () => {
|
|
96
|
+
if (modals.get(m.key) === m) {
|
|
97
|
+
modals.delete(m.key);
|
|
98
|
+
notify();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** null si el modal no está registrado o su addon no está instalado. Nunca espera. */
|
|
103
|
+
export function resolveFederatedModal(key, isInstalled) {
|
|
104
|
+
const m = modals.get(key);
|
|
105
|
+
return m && isInstalled(m.addon) ? m : null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Componente `React.lazy` del modal resuelto, memoizado por registro (no se
|
|
109
|
+
* re-crea en cada render). Quien lo pinta lo envuelve en `<Suspense>`.
|
|
110
|
+
*/
|
|
111
|
+
export function federatedModalComponent(m) {
|
|
112
|
+
let C = modalComponents.get(m);
|
|
113
|
+
if (!C) {
|
|
114
|
+
C = lazy(m.load);
|
|
115
|
+
modalComponents.set(m, C);
|
|
116
|
+
}
|
|
117
|
+
return C;
|
|
118
|
+
}
|
|
119
|
+
/** Solo para tests. */
|
|
120
|
+
export function __resetContributions() {
|
|
121
|
+
for (const e of [...contribs.values()])
|
|
122
|
+
e.dispose();
|
|
123
|
+
contribs.clear();
|
|
124
|
+
modals.clear();
|
|
125
|
+
notify();
|
|
126
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DocumentFormPreview, DocumentFormSource } from '../types';
|
|
2
|
+
export type PartyRole = 'customer' | 'supplier' | 'none';
|
|
3
|
+
export type LinesMode = 'sale' | 'purchase' | 'credit' | 'allocation' | 'workorder' | 'none';
|
|
4
|
+
export interface DocumentKind {
|
|
5
|
+
key: string;
|
|
6
|
+
label: string;
|
|
7
|
+
model: string;
|
|
8
|
+
party: PartyRole;
|
|
9
|
+
partyModel?: string;
|
|
10
|
+
lines: LinesMode;
|
|
11
|
+
/** Campo de renglones del modelo (one_to_many) o del payload de la acción. */
|
|
12
|
+
linesField?: string;
|
|
13
|
+
sources?: DocumentFormSource[];
|
|
14
|
+
preview?: DocumentFormPreview;
|
|
15
|
+
/** Estados del documento (StageMachine): los muestra StageStepper. */
|
|
16
|
+
stages?: string[];
|
|
17
|
+
/** Addon dueño del tipo (si no está, el tipo no se ofrece). */
|
|
18
|
+
addon: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function registerDocumentKind(k: DocumentKind): () => void;
|
|
21
|
+
export declare function getDocumentKind(key: string): DocumentKind | undefined;
|
|
22
|
+
export declare function listDocumentKinds(isInstalled: (addon: string) => boolean): DocumentKind[];
|
|
23
|
+
/** Tipos base que el core ya tiene (modelos verificados en addons main 9cd69bde). */
|
|
24
|
+
export declare const CORE_DOCUMENT_KINDS: DocumentKind[];
|
|
25
|
+
//# sourceMappingURL=document-kinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-kinds.d.ts","sourceRoot":"","sources":["../../src/primitives/document-kinds.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAEvE,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAA;AACxD,MAAM,MAAM,SAAS,GACf,MAAM,GACN,UAAU,GACV,QAAQ,GACR,YAAY,GACZ,WAAW,GACX,MAAM,CAAA;AAEZ,MAAM,WAAW,YAAY;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,SAAS,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,SAAS,CAAA;IAChB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAA;IAC9B,OAAO,CAAC,EAAE,mBAAmB,CAAA;IAC7B,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;IACjB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAA;CAChB;AAID,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,YAAY,GAAG,MAAM,IAAI,CAKhE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAErE;AAED,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,YAAY,EAAE,CAEzF;AAED,qFAAqF;AACrF,eAAO,MAAM,mBAAmB,EAAE,YAAY,EAU7C,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const kinds = new Map();
|
|
2
|
+
export function registerDocumentKind(k) {
|
|
3
|
+
kinds.set(k.key, k);
|
|
4
|
+
return () => {
|
|
5
|
+
if (kinds.get(k.key) === k)
|
|
6
|
+
kinds.delete(k.key);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export function getDocumentKind(key) {
|
|
10
|
+
return kinds.get(key);
|
|
11
|
+
}
|
|
12
|
+
export function listDocumentKinds(isInstalled) {
|
|
13
|
+
return [...kinds.values()].filter(k => isInstalled(k.addon));
|
|
14
|
+
}
|
|
15
|
+
/** Tipos base que el core ya tiene (modelos verificados en addons main 9cd69bde). */
|
|
16
|
+
export const CORE_DOCUMENT_KINDS = [
|
|
17
|
+
{ key: 'invoice', label: 'Factura', model: 'customers.Invoice', party: 'customer', partyModel: 'customers.Customer', lines: 'sale', linesField: 'items', addon: 'customers' },
|
|
18
|
+
{ key: 'quote', label: 'Cotización', model: 'quotes.Quote', party: 'customer', partyModel: 'customers.Customer', lines: 'sale', linesField: 'items', addon: 'quotes' },
|
|
19
|
+
{ key: 'sales_order', label: 'Pedido', model: 'customers.SalesOrder', party: 'customer', partyModel: 'customers.Customer', lines: 'sale', linesField: 'items', addon: 'customers' },
|
|
20
|
+
{ key: 'payment', label: 'Cobro', model: 'customers.Payment', party: 'customer', partyModel: 'customers.Customer', lines: 'allocation', linesField: 'allocations', addon: 'customers' },
|
|
21
|
+
{ key: 'credit_note', label: 'Nota de crédito', model: 'fiscal_mexico.CreditNote', party: 'customer', partyModel: 'customers.Customer', lines: 'credit', linesField: 'lines', addon: 'fiscal_mexico' },
|
|
22
|
+
{ key: 'purchase_order', label: 'Orden de compra', model: 'purchases.PurchaseOrder', party: 'supplier', partyModel: 'purchases.Supplier', lines: 'purchase', linesField: 'items', addon: 'purchases' },
|
|
23
|
+
{ key: 'supplier_invoice', label: 'Factura de proveedor', model: 'purchases.SupplierInvoice', party: 'supplier', partyModel: 'purchases.Supplier', lines: 'purchase', addon: 'purchases' },
|
|
24
|
+
{ key: 'supplier_payment', label: 'Pago a proveedor', model: 'purchases.PurchasePayment', party: 'supplier', partyModel: 'purchases.Supplier', lines: 'allocation', addon: 'purchases' },
|
|
25
|
+
{ key: 'work_order', label: 'Orden de trabajo', model: 'workshop.WorkOrder', party: 'customer', partyModel: 'customers.Customer', lines: 'workorder', linesField: 'items', addon: 'workshop' },
|
|
26
|
+
];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/primitives/index.ts"],"names":[],"mappings":"AAgBA,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Primitivos de negocio — contrato estable para hosts y remotes federados.
|
|
2
|
+
// Las funciones son puras (sin React ni host) salvo use-contributions; la UI y
|
|
3
|
+
// el backend (wasm) pueden validar con las mismas reglas.
|
|
4
|
+
//
|
|
5
|
+
// allocation PaymentAllocator: allocatePayment / validateAllocation
|
|
6
|
+
// (cobro multi-factura, REP, CxC «Registrar abono», CxP «Aplicar pago»).
|
|
7
|
+
// aging AgingTable: computeAging / daysOverdue / bucketFor (antigüedad de saldos).
|
|
8
|
+
// approvals ApprovalInbox: approvalsClient (rutas /approvals del kernel),
|
|
9
|
+
// registerApprovalCategory / groupApprovals.
|
|
10
|
+
// contributions Secciones y modales federados: registerDocumentContribution,
|
|
11
|
+
// resolveContributions (pura), registerFederatedModal /
|
|
12
|
+
// resolveFederatedModal. Todo register* devuelve su disposer.
|
|
13
|
+
// document-kinds registerDocumentKind / listDocumentKinds / CORE_DOCUMENT_KINDS.
|
|
14
|
+
// panels Tipos de PartyCard / TotalsPanel / PreviewPanel /
|
|
15
|
+
// ValidationChecklist / LoadFromDocument + blockingChecks.
|
|
16
|
+
// use-contributions Hooks: useDocumentContributions, useIsAddonInstalled.
|
|
17
|
+
export * from './allocation';
|
|
18
|
+
export * from './aging';
|
|
19
|
+
export * from './approvals';
|
|
20
|
+
export * from './contributions';
|
|
21
|
+
export * from './document-kinds';
|
|
22
|
+
export * from './panels';
|
|
23
|
+
export * from './use-contributions';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { LineItemsTotals } from '../business/line-items';
|
|
2
|
+
/** PartyCard: lo que se muestra de la contraparte. */
|
|
3
|
+
export interface PartySummary {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
tax_id?: string;
|
|
7
|
+
email?: string;
|
|
8
|
+
phone?: string;
|
|
9
|
+
currency?: string;
|
|
10
|
+
/** Filas extra (incluye las de extensiones `fiscal_data.*`). */
|
|
11
|
+
rows: Array<{
|
|
12
|
+
key: string;
|
|
13
|
+
label: string;
|
|
14
|
+
value: string;
|
|
15
|
+
tone?: 'ok' | 'warn' | 'err';
|
|
16
|
+
}>;
|
|
17
|
+
credit?: {
|
|
18
|
+
limit: number;
|
|
19
|
+
balance: number;
|
|
20
|
+
available: number;
|
|
21
|
+
overdue: number;
|
|
22
|
+
status?: 'active' | 'suspended' | 'delinquent';
|
|
23
|
+
hold_reason?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** TotalsPanel: desglose; los impuestos por tasa los aporta el addon fiscal o el core. */
|
|
27
|
+
export interface TotalsBreakdown extends LineItemsTotals {
|
|
28
|
+
taxes: Array<{
|
|
29
|
+
label: string;
|
|
30
|
+
base: number;
|
|
31
|
+
amount: number;
|
|
32
|
+
}>;
|
|
33
|
+
/** Renglones extra (aplicaciones, saldo a favor, sin aplicar…). */
|
|
34
|
+
extra?: Array<{
|
|
35
|
+
label: string;
|
|
36
|
+
amount: number;
|
|
37
|
+
emphasis?: boolean;
|
|
38
|
+
}>;
|
|
39
|
+
amount_in_words?: string;
|
|
40
|
+
}
|
|
41
|
+
/** PreviewPanel: resultado de la acción de vista previa (`analyze: true`, no escribe). */
|
|
42
|
+
export interface PreviewResult {
|
|
43
|
+
pdf_base64?: string;
|
|
44
|
+
xml?: string;
|
|
45
|
+
html?: string;
|
|
46
|
+
checks: ValidationCheck[];
|
|
47
|
+
}
|
|
48
|
+
/** ValidationChecklist: una revisión (local o del servidor). */
|
|
49
|
+
export interface ValidationCheck {
|
|
50
|
+
key: string;
|
|
51
|
+
severity: 'ok' | 'warning' | 'error';
|
|
52
|
+
message: string;
|
|
53
|
+
/** Campo a enfocar al hacer clic. */
|
|
54
|
+
field?: string;
|
|
55
|
+
/** Si es error y `approval_policy` está, el botón ofrece «Pedir autorización». */
|
|
56
|
+
approval_policy?: string;
|
|
57
|
+
}
|
|
58
|
+
/** LoadFromDocument: candidato a cargar (venta, cotización, ticket, OT, factura origen de NC). */
|
|
59
|
+
export interface LoadCandidate {
|
|
60
|
+
source: string;
|
|
61
|
+
id: string;
|
|
62
|
+
label: string;
|
|
63
|
+
party_id?: string;
|
|
64
|
+
total?: number;
|
|
65
|
+
state?: string;
|
|
66
|
+
}
|
|
67
|
+
export declare function blockingChecks(checks: readonly ValidationCheck[]): ValidationCheck[];
|
|
68
|
+
//# sourceMappingURL=panels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panels.d.ts","sourceRoot":"","sources":["../../src/primitives/panels.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAE7D,sDAAsD;AACtD,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,IAAI,EAAE,KAAK,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,KAAK,CAAA;KAAE,CAAC,CAAA;IACxF,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,WAAW,GA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E,CAEpF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type InstalledAddonsValue } from '../installed-addons-context';
|
|
2
|
+
import { type DocumentEditorContext, type DocumentRegion, type IsAddonInstalled, type ResolvedDocumentContribution } from './contributions';
|
|
3
|
+
/**
|
|
4
|
+
* Predicado de instalación a partir del InstalledAddonsProvider. Sin provider
|
|
5
|
+
* devuelve siempre true: el host solo carga remotes de addons instalados, así
|
|
6
|
+
* que si la contribución existe, su addon está (el servidor revalida igual).
|
|
7
|
+
*/
|
|
8
|
+
export declare function installedPredicate(value: InstalledAddonsValue | null): IsAddonInstalled;
|
|
9
|
+
/** `installedPredicate(useInstalledAddons())`, estable entre renders. */
|
|
10
|
+
export declare function useIsAddonInstalled(): IsAddonInstalled;
|
|
11
|
+
/** Re-pinta en cada register/dispose de contribuciones o modales federados. */
|
|
12
|
+
export declare function useContributionsVersion(): number;
|
|
13
|
+
/** Contribuciones aplicables a `region` del documento `ctx` (ya filtradas y ordenadas). */
|
|
14
|
+
export declare function useDocumentContributions(ctx: DocumentEditorContext, region: DocumentRegion): ResolvedDocumentContribution<any>[];
|
|
15
|
+
//# sourceMappingURL=use-contributions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-contributions.d.ts","sourceRoot":"","sources":["../../src/primitives/use-contributions.ts"],"names":[],"mappings":"AAKA,OAAO,EAAsB,KAAK,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AAC3F,OAAO,EAIH,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,4BAA4B,EACpC,MAAM,iBAAiB,CAAA;AAExB;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,oBAAoB,GAAG,IAAI,GAAG,gBAAgB,CAEvF;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,IAAI,gBAAgB,CAGtD;AAED,+EAA+E;AAC/E,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD;AAED,2FAA2F;AAC3F,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,cAAc,GAAG,4BAA4B,CAAC,GAAG,CAAC,EAAE,CAIhI"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Hooks de React sobre el registro de contribuciones (contributions.ts).
|
|
2
|
+
// La lógica vive en las funciones puras; aquí solo se conecta con
|
|
3
|
+
// useInstalledAddons y con la suscripción para re-pintar cuando un remote
|
|
4
|
+
// registra o se desmonta.
|
|
5
|
+
import { useMemo, useSyncExternalStore } from 'react';
|
|
6
|
+
import { useInstalledAddons } from '../installed-addons-context';
|
|
7
|
+
import { contributionsVersion, resolveContributions, subscribeContributions, } from './contributions';
|
|
8
|
+
/**
|
|
9
|
+
* Predicado de instalación a partir del InstalledAddonsProvider. Sin provider
|
|
10
|
+
* devuelve siempre true: el host solo carga remotes de addons instalados, así
|
|
11
|
+
* que si la contribución existe, su addon está (el servidor revalida igual).
|
|
12
|
+
*/
|
|
13
|
+
export function installedPredicate(value) {
|
|
14
|
+
return value ? (key) => value.addons.has(key) : () => true;
|
|
15
|
+
}
|
|
16
|
+
/** `installedPredicate(useInstalledAddons())`, estable entre renders. */
|
|
17
|
+
export function useIsAddonInstalled() {
|
|
18
|
+
const value = useInstalledAddons();
|
|
19
|
+
return useMemo(() => installedPredicate(value), [value]);
|
|
20
|
+
}
|
|
21
|
+
/** Re-pinta en cada register/dispose de contribuciones o modales federados. */
|
|
22
|
+
export function useContributionsVersion() {
|
|
23
|
+
return useSyncExternalStore(subscribeContributions, contributionsVersion, contributionsVersion);
|
|
24
|
+
}
|
|
25
|
+
/** Contribuciones aplicables a `region` del documento `ctx` (ya filtradas y ordenadas). */
|
|
26
|
+
export function useDocumentContributions(ctx, region) {
|
|
27
|
+
useContributionsVersion();
|
|
28
|
+
const isInstalled = useIsAddonInstalled();
|
|
29
|
+
return resolveContributions(ctx, region, isInstalled);
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type RecordFormMode } from '@asteby/metacore-sdk';
|
|
2
|
+
export interface RecordPrefillBarProps {
|
|
3
|
+
model: string;
|
|
4
|
+
mode: RecordFormMode;
|
|
5
|
+
recordId?: string | null;
|
|
6
|
+
values: Record<string, any>;
|
|
7
|
+
allowedKeys: ReadonlySet<string>;
|
|
8
|
+
onApply: (patch: Record<string, any>) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function RecordPrefillBar({ model, mode, recordId, values, allowedKeys, onApply }: RecordPrefillBarProps): import("react").JSX.Element | null;
|
|
11
|
+
//# sourceMappingURL=record-prefill-bar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-prefill-bar.d.ts","sourceRoot":"","sources":["../src/record-prefill-bar.tsx"],"names":[],"mappings":"AAYA,OAAO,EAIH,KAAK,cAAc,EACtB,MAAM,sBAAsB,CAAA;AAG7B,MAAM,WAAW,qBAAqB;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,cAAc,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC3B,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAA;CAChD;AAED,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,qBAAqB,sCAgC9G"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// RecordPrefillBar — pinta los ayudantes de captura (record-prefill-registry de
|
|
3
|
+
// @asteby/metacore-sdk) arriba del formulario genérico de un modelo.
|
|
4
|
+
//
|
|
5
|
+
// El formulario no conoce a los addons: sólo pregunta "¿quién aporta prefill
|
|
6
|
+
// para <model> en <mode>?". Hoy: fiscal_mexico → «Cargar constancia» en
|
|
7
|
+
// Customer/Supplier. Mañana: un vertical restaurante aporta «Importar menú» en
|
|
8
|
+
// Product, un vertical ferretería «Leer código de proveedor», etc.
|
|
9
|
+
//
|
|
10
|
+
// Seguridad del patch: sólo se aplican claves que el formulario declara
|
|
11
|
+
// (allowedKeys) — un addon no puede inyectar columnas ocultas (organization_id,
|
|
12
|
+
// created_by…) por esta vía; el backend sigue validando como siempre.
|
|
13
|
+
import { useCallback, useSyncExternalStore } from 'react';
|
|
14
|
+
import { getRecordPrefills, recordPrefillsVersion, subscribeRecordPrefills, } from '@asteby/metacore-sdk';
|
|
15
|
+
import { useCan } from './permissions-context';
|
|
16
|
+
export function RecordPrefillBar({ model, mode, recordId, values, allowedKeys, onApply }) {
|
|
17
|
+
// Re-render cuando un remote registra/des-registra (carga tardía o unbind).
|
|
18
|
+
useSyncExternalStore(subscribeRecordPrefills, recordPrefillsVersion, recordPrefillsVersion);
|
|
19
|
+
const can = useCan();
|
|
20
|
+
const items = getRecordPrefills(model, mode).filter(c => !c.permission || can(c.permission));
|
|
21
|
+
const applyValues = useCallback((patch) => {
|
|
22
|
+
const safe = {};
|
|
23
|
+
for (const [k, v] of Object.entries(patch ?? {})) {
|
|
24
|
+
if (allowedKeys.has(k))
|
|
25
|
+
safe[k] = v;
|
|
26
|
+
}
|
|
27
|
+
if (Object.keys(safe).length > 0)
|
|
28
|
+
onApply(safe);
|
|
29
|
+
}, [allowedKeys, onApply]);
|
|
30
|
+
if (items.length === 0)
|
|
31
|
+
return null;
|
|
32
|
+
return (_jsx("div", { className: "flex flex-wrap items-center gap-2", "data-aby-record-prefill": "", children: items.map(({ id, component: C }) => (_jsx(C, { model: model, mode: mode, recordId: recordId ?? undefined, values: values, applyValues: applyValues }, id))) }));
|
|
33
|
+
}
|