@asteby/metacore-runtime-react 53.13.1 → 53.15.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 +20 -0
- package/dist/action-modal-dispatcher.d.ts +1 -1
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +31 -6
- package/dist/dialogs/dynamic-record.d.ts +8 -1
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +34 -4
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +4 -0
- package/dist/dynamic-form-schema.d.ts.map +1 -1
- package/dist/dynamic-form-schema.js +5 -1
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +28 -3
- package/dist/dynamic-kanban.d.ts.map +1 -1
- package/dist/dynamic-kanban.js +33 -1
- package/dist/dynamic-line-items.d.ts.map +1 -1
- package/dist/dynamic-line-items.js +9 -1
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +7 -0
- package/dist/field-grid.d.ts +3 -1
- package/dist/field-grid.d.ts.map +1 -1
- package/dist/field-grid.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/nullable-boolean.d.ts +48 -0
- package/dist/nullable-boolean.d.ts.map +1 -0
- package/dist/nullable-boolean.js +80 -0
- package/dist/slots/addon-slot.d.ts +91 -0
- package/dist/slots/addon-slot.d.ts.map +1 -0
- package/dist/slots/addon-slot.js +219 -0
- package/dist/slots/index.d.ts +3 -0
- package/dist/slots/index.d.ts.map +1 -0
- package/dist/slots/index.js +2 -0
- package/dist/slots/sdk-range.d.ts +6 -0
- package/dist/slots/sdk-range.d.ts.map +1 -0
- package/dist/slots/sdk-range.js +92 -0
- package/dist/tri-state-boolean-impl.d.ts +24 -0
- package/dist/tri-state-boolean-impl.d.ts.map +1 -0
- package/dist/tri-state-boolean-impl.js +35 -0
- package/dist/tri-state-boolean.d.ts +15 -0
- package/dist/tri-state-boolean.d.ts.map +1 -0
- package/dist/tri-state-boolean.js +24 -0
- package/dist/use-dynamic-filters.d.ts.map +1 -1
- package/dist/use-dynamic-filters.js +10 -0
- package/package.json +5 -5
- package/src/__tests__/addon-slot.test.tsx +280 -0
- package/src/__tests__/nullable-boolean.test.tsx +458 -0
- package/src/__tests__/slot-legacy.test.tsx +34 -0
- package/src/action-modal-dispatcher.tsx +32 -6
- package/src/dialogs/dynamic-record.tsx +53 -5
- package/src/dynamic-columns.tsx +3 -0
- package/src/dynamic-form-schema.ts +4 -1
- package/src/dynamic-form.tsx +31 -2
- package/src/dynamic-kanban.tsx +6 -1
- package/src/dynamic-line-items.tsx +9 -1
- package/src/dynamic-table.tsx +5 -0
- package/src/field-grid.tsx +4 -0
- package/src/index.ts +1 -0
- package/src/nullable-boolean.ts +96 -0
- package/src/slots/addon-slot.tsx +452 -0
- package/src/slots/index.ts +18 -0
- package/src/slots/sdk-range.ts +86 -0
- package/src/tri-state-boolean-impl.tsx +71 -0
- package/src/tri-state-boolean.tsx +39 -0
- package/src/use-dynamic-filters.ts +8 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// AddonSlot — punto de montaje de contribuciones de addons en un host.
|
|
3
|
+
//
|
|
4
|
+
// <AddonSlot kind="invoice.footer" context={{ invoiceId }} />
|
|
5
|
+
//
|
|
6
|
+
// Qué pinta, en este orden (`order` ascendente y luego `priority` descendente,
|
|
7
|
+
// ver docs/slot-priority.md):
|
|
8
|
+
// 1. contribuciones declaradas en los manifests instalados
|
|
9
|
+
// (`contributions.slots[]`, ya filtradas por el servidor: permiso,
|
|
10
|
+
// `condition` y org), que se bajan como remoto federado (`slot.entry` es
|
|
11
|
+
// el `expose`);
|
|
12
|
+
// 2. contribuciones en proceso registradas en el slot store canónico
|
|
13
|
+
// (`Registry.registerSlot`, `slotRegistry.register`): una sola lista.
|
|
14
|
+
//
|
|
15
|
+
// Cada contribución vive aislada en su propio ErrorBoundary + Suspense con un
|
|
16
|
+
// timeout: si un remoto lanza, se cuelga o no es compatible, emite
|
|
17
|
+
// `addon_slot_failed{addon,kind,reason}` por el canal de errores del host y
|
|
18
|
+
// muestra su fallback; sus hermanos y el shell no se enteran.
|
|
19
|
+
//
|
|
20
|
+
// Contrato del remoto (C2): `export default function SlotComponent({ context,
|
|
21
|
+
// props, sdk })`. Sin provider ni manifests, solo se pintan las contribuciones
|
|
22
|
+
// en proceso (equivale al `<Slot>` histórico).
|
|
23
|
+
import { createContext, Suspense, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
|
|
24
|
+
import { slotStore } from '@asteby/metacore-sdk';
|
|
25
|
+
import { loadFederatedModule } from '../addon-loader';
|
|
26
|
+
import { FederatedErrorBoundary } from '../federated-error-boundary';
|
|
27
|
+
import { useInstalledAddons } from '../installed-addons-context';
|
|
28
|
+
import { satisfiesSdkRange } from './sdk-range';
|
|
29
|
+
export const ADDON_SLOT_FAILED = 'addon_slot_failed';
|
|
30
|
+
export const DEFAULT_ADDON_SLOT_TIMEOUT_MS = 10_000;
|
|
31
|
+
/** Rango permitido por el contrato C1 para `slot.timeout_ms` del manifest. */
|
|
32
|
+
export const MIN_SLOT_TIMEOUT_MS = 1_000;
|
|
33
|
+
export const MAX_SLOT_TIMEOUT_MS = 30_000;
|
|
34
|
+
/**
|
|
35
|
+
* `timeout_ms` del manifest acotado a 1000..30000. Un valor no numérico, NaN,
|
|
36
|
+
* 0 o negativo se ignora y manda el del host (nunca anula el timeout).
|
|
37
|
+
*/
|
|
38
|
+
export function resolveSlotTimeout(slotValue, hostMs) {
|
|
39
|
+
if (typeof slotValue !== 'number' || !Number.isFinite(slotValue) || slotValue <= 0)
|
|
40
|
+
return hostMs;
|
|
41
|
+
return Math.min(MAX_SLOT_TIMEOUT_MS, Math.max(MIN_SLOT_TIMEOUT_MS, slotValue));
|
|
42
|
+
}
|
|
43
|
+
const Ctx = createContext(null);
|
|
44
|
+
export function AddonSlotProvider({ manifests, sdkVersion, requireIntegrity = false, timeoutMs = DEFAULT_ADDON_SLOT_TIMEOUT_MS, onEvent, children, }) {
|
|
45
|
+
const onEventRef = useRef(onEvent);
|
|
46
|
+
onEventRef.current = onEvent;
|
|
47
|
+
const value = useMemo(() => ({
|
|
48
|
+
manifests,
|
|
49
|
+
sdkVersion,
|
|
50
|
+
requireIntegrity,
|
|
51
|
+
timeoutMs,
|
|
52
|
+
onEvent: (e, d) => onEventRef.current?.(e, d),
|
|
53
|
+
}), [manifests, sdkVersion, requireIntegrity, timeoutMs]);
|
|
54
|
+
return _jsx(Ctx.Provider, { value: value, children: children });
|
|
55
|
+
}
|
|
56
|
+
const EMPTY_OBJ = Object.freeze({});
|
|
57
|
+
/** Orden canónico: `order` ascendente, luego `priority` descendente, luego inserción. */
|
|
58
|
+
export function sortSlotItems(items) {
|
|
59
|
+
return items
|
|
60
|
+
.map((it, i) => ({ it, i }))
|
|
61
|
+
.sort((a, b) => a.it.order - b.it.order || b.it.priority - a.it.priority || a.i - b.i)
|
|
62
|
+
.map((x) => x.it);
|
|
63
|
+
}
|
|
64
|
+
function withTimeout(p, ms, onTimeout) {
|
|
65
|
+
if (!ms || ms <= 0)
|
|
66
|
+
return p;
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const t = setTimeout(() => reject(onTimeout()), ms);
|
|
69
|
+
p.then((v) => {
|
|
70
|
+
clearTimeout(t);
|
|
71
|
+
resolve(v);
|
|
72
|
+
}, (e) => {
|
|
73
|
+
clearTimeout(t);
|
|
74
|
+
reject(e);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
class SlotLoadError extends Error {
|
|
79
|
+
reason;
|
|
80
|
+
constructor(reason, message) {
|
|
81
|
+
super(message);
|
|
82
|
+
this.name = 'SlotLoadError';
|
|
83
|
+
this.reason = reason;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function containerScope(m) {
|
|
87
|
+
return m.frontend?.container || `metacore_${m.key.replace(/[^a-zA-Z0-9]/g, '_')}`;
|
|
88
|
+
}
|
|
89
|
+
function toComponent(mod) {
|
|
90
|
+
const candidate = mod?.default ?? mod;
|
|
91
|
+
if (typeof candidate === 'function')
|
|
92
|
+
return candidate;
|
|
93
|
+
// React.lazy / React.memo / forwardRef son objetos con $$typeof.
|
|
94
|
+
if (candidate && typeof candidate === 'object' && '$$typeof' in candidate) {
|
|
95
|
+
return candidate;
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
function RemoteItem({ kind, item, context, cfg, requireIntegrity, timeoutMs, loading, renderFallback, report, }) {
|
|
100
|
+
const { manifest, slot, addon } = item;
|
|
101
|
+
const fe = manifest.frontend;
|
|
102
|
+
const [state, setState] = useState({ status: 'loading' });
|
|
103
|
+
const reportRef = useRef(report);
|
|
104
|
+
reportRef.current = report;
|
|
105
|
+
const effectiveTimeout = resolveSlotTimeout(slot.timeout_ms, timeoutMs);
|
|
106
|
+
const hostSdk = cfg?.sdkVersion;
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
let cancelled = false;
|
|
109
|
+
const fail = (reason, message) => {
|
|
110
|
+
if (cancelled)
|
|
111
|
+
return;
|
|
112
|
+
const failure = { addon, kind, reason, message };
|
|
113
|
+
setState({ status: 'failed', failure });
|
|
114
|
+
reportRef.current(failure);
|
|
115
|
+
};
|
|
116
|
+
setState({ status: 'loading' });
|
|
117
|
+
if (!fe?.entry) {
|
|
118
|
+
fail('load', `addon ${addon} declares a slot but has no frontend.entry`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
if (requireIntegrity && !fe.integrity) {
|
|
122
|
+
fail('integrity_required', `addon ${addon} has no frontend.integrity and the host requires it`);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (satisfiesSdkRange(hostSdk, fe.sdk) === false) {
|
|
126
|
+
fail('sdk_incompatible', `addon ${addon} needs SDK ${fe.sdk}, host provides ${hostSdk}`);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
let loadPromise;
|
|
130
|
+
try {
|
|
131
|
+
loadPromise = Promise.resolve(loadFederatedModule(containerScope(manifest), fe.entry, slot.entry, fe.integrity));
|
|
132
|
+
}
|
|
133
|
+
catch (e) {
|
|
134
|
+
loadPromise = Promise.reject(e);
|
|
135
|
+
}
|
|
136
|
+
withTimeout(loadPromise, effectiveTimeout, () => new SlotLoadError('timeout', `slot "${slot.entry}" of ${addon} did not load within ${effectiveTimeout} ms`))
|
|
137
|
+
.then((mod) => {
|
|
138
|
+
if (cancelled)
|
|
139
|
+
return;
|
|
140
|
+
const C = toComponent(mod);
|
|
141
|
+
if (!C)
|
|
142
|
+
throw new SlotLoadError('missing_expose', `expose "${slot.entry}" of ${addon} has no default component`);
|
|
143
|
+
setState({ status: 'ready', C });
|
|
144
|
+
})
|
|
145
|
+
.catch((e) => {
|
|
146
|
+
const err = e instanceof Error ? e : new Error(String(e));
|
|
147
|
+
fail(e instanceof SlotLoadError ? e.reason : 'load', err.message);
|
|
148
|
+
});
|
|
149
|
+
return () => {
|
|
150
|
+
cancelled = true;
|
|
151
|
+
};
|
|
152
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
153
|
+
}, [addon, kind, fe?.entry, fe?.integrity, fe?.sdk, slot.entry, requireIntegrity, effectiveTimeout, hostSdk]);
|
|
154
|
+
if (state.status === 'loading')
|
|
155
|
+
return _jsx(_Fragment, { children: loading });
|
|
156
|
+
if (state.status === 'failed')
|
|
157
|
+
return _jsx(_Fragment, { children: renderFallback(state.failure) });
|
|
158
|
+
const { C } = state;
|
|
159
|
+
const sdk = { addon, kind, sdkVersion: hostSdk };
|
|
160
|
+
return (_jsx(RenderGuard, { addon: addon, kind: kind, renderFallback: renderFallback, report: report, resetKey: fe?.entry, children: _jsx(C, { context: context, props: slot.props ?? EMPTY_OBJ, sdk: sdk }) }));
|
|
161
|
+
}
|
|
162
|
+
function RenderGuard({ addon, kind, resetKey, renderFallback, report, children, }) {
|
|
163
|
+
return (_jsx(FederatedErrorBoundary, { addonKey: addon, resetKeys: [resetKey], onError: (error) => report({ addon, kind, reason: 'render', message: error.message }), fallback: ({ error }) => _jsx(_Fragment, { children: renderFallback({ addon, kind, reason: 'render', message: error.message }) }), children: _jsx(Suspense, { fallback: null, children: children }) }));
|
|
164
|
+
}
|
|
165
|
+
export function AddonSlot({ kind, context, className, timeoutMs, requireIntegrity, onEvent, loading = null, fallback = null, empty = null, }) {
|
|
166
|
+
const cfg = useContext(Ctx);
|
|
167
|
+
const installed = useInstalledAddons();
|
|
168
|
+
const ctx = context ?? EMPTY_OBJ;
|
|
169
|
+
const local = useSyncExternalStore((cb) => slotStore.subscribe(cb), () => slotStore.get(kind), () => slotStore.get(kind));
|
|
170
|
+
const items = useMemo(() => {
|
|
171
|
+
const out = [];
|
|
172
|
+
for (const m of cfg?.manifests ?? []) {
|
|
173
|
+
if (installed && !installed.addons.has(m.key))
|
|
174
|
+
continue;
|
|
175
|
+
(m.contributions?.slots ?? []).forEach((slot, i) => {
|
|
176
|
+
if (slot.slot_kind !== kind)
|
|
177
|
+
return;
|
|
178
|
+
out.push({
|
|
179
|
+
type: 'remote',
|
|
180
|
+
id: `${m.key}:${slot.entry}:${i}`,
|
|
181
|
+
addon: m.key,
|
|
182
|
+
order: slot.order ?? 0,
|
|
183
|
+
priority: 0,
|
|
184
|
+
manifest: m,
|
|
185
|
+
slot,
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
local.forEach((entry, i) => {
|
|
190
|
+
if (entry.owner && installed && !installed.addons.has(entry.owner))
|
|
191
|
+
return;
|
|
192
|
+
out.push({
|
|
193
|
+
type: 'local',
|
|
194
|
+
id: `local:${entry.source ?? 'anon'}:${i}`,
|
|
195
|
+
addon: entry.owner ?? entry.source ?? 'host',
|
|
196
|
+
order: 0,
|
|
197
|
+
priority: entry.priority ?? 0,
|
|
198
|
+
entry,
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
return sortSlotItems(out);
|
|
202
|
+
}, [cfg?.manifests, installed, local, kind]);
|
|
203
|
+
const effTimeout = timeoutMs ?? cfg?.timeoutMs ?? DEFAULT_ADDON_SLOT_TIMEOUT_MS;
|
|
204
|
+
const effRequire = requireIntegrity ?? cfg?.requireIntegrity ?? false;
|
|
205
|
+
const handlerRef = useRef(onEvent ?? cfg?.onEvent);
|
|
206
|
+
handlerRef.current = onEvent ?? cfg?.onEvent;
|
|
207
|
+
const report = useRef((f) => {
|
|
208
|
+
try {
|
|
209
|
+
handlerRef.current?.(ADDON_SLOT_FAILED, f);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
/* un reporter roto no tumba el shell */
|
|
213
|
+
}
|
|
214
|
+
}).current;
|
|
215
|
+
const renderFallback = (f) => typeof fallback === 'function' ? fallback(f) : fallback;
|
|
216
|
+
if (items.length === 0)
|
|
217
|
+
return _jsx(_Fragment, { children: empty });
|
|
218
|
+
return (_jsx("div", { "data-addon-slot": kind, className: className, style: className ? undefined : { display: 'contents' }, children: items.map((item) => (_jsx("div", { "data-addon-slot-item": item.addon, style: { display: 'contents' }, children: item.type === 'remote' ? (_jsx(RemoteItem, { kind: kind, item: item, context: ctx, cfg: cfg, requireIntegrity: effRequire, timeoutMs: effTimeout, loading: loading, renderFallback: renderFallback, report: report })) : (_jsx(RenderGuard, { addon: item.addon, kind: kind, renderFallback: renderFallback, report: report, children: _jsx(item.entry.component, { ...ctx, context: ctx, props: EMPTY_OBJ, sdk: { addon: item.addon, kind, sdkVersion: cfg?.sdkVersion } }) })) }, item.id))) }));
|
|
219
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AddonSlot, AddonSlotProvider, sortSlotItems, ADDON_SLOT_FAILED, DEFAULT_ADDON_SLOT_TIMEOUT_MS, resolveSlotTimeout, type AddonSlotProps, type AddonSlotProviderProps, type AddonSlotManifest, type AddonSlotContribution, type AddonSlotSDK, type AddonSlotComponentProps, type AddonSlotFailure, type AddonSlotFailureReason, type AddonSlotEventHandler, } from './addon-slot';
|
|
2
|
+
export { satisfiesSdkRange } from './sdk-range';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/slots/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,6BAA6B,EAC7B,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC7B,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ¿`version` cumple `range`? `true`/`false` si ambos se entienden, `null` si
|
|
3
|
+
* alguno no (rango vacío o versión ilegible = sin restricción conocida).
|
|
4
|
+
*/
|
|
5
|
+
export declare function satisfiesSdkRange(version: string | undefined, range: string | undefined): boolean | null;
|
|
6
|
+
//# sourceMappingURL=sdk-range.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-range.d.ts","sourceRoot":"","sources":["../../src/slots/sdk-range.ts"],"names":[],"mappings":"AAyDA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,IAAI,CAwBxG"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Comprobación mínima de rangos semver para `manifest.frontend.sdk`
|
|
2
|
+
// (p. ej. "^4.0.0", ">=3.2 <5", "~3.18", "3.x", "^3 || ^4"). Sin dependencias.
|
|
3
|
+
// Un rango que no se entiende devuelve `null` (desconocido): el llamador NO lo
|
|
4
|
+
// trata como incompatible, para no romper addons por un rango exótico.
|
|
5
|
+
function parseVersion(s) {
|
|
6
|
+
const m = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:[-+].*)?$/.exec(s.trim());
|
|
7
|
+
if (!m)
|
|
8
|
+
return null;
|
|
9
|
+
return [Number(m[1]), Number(m[2] ?? 0), Number(m[3] ?? 0)];
|
|
10
|
+
}
|
|
11
|
+
function cmp(a, b) {
|
|
12
|
+
for (let i = 0; i < 3; i++)
|
|
13
|
+
if (a[i] !== b[i])
|
|
14
|
+
return a[i] < b[i] ? -1 : 1;
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
/** Un comparador simple (`^1.2.3`, `>=1`, `1.x`, `=1.2.3`) contra `v`. null = no se entiende. */
|
|
18
|
+
function matchComparator(token, v) {
|
|
19
|
+
const m = /^(\^|~|>=|<=|>|<|=)?\s*v?([\dxX*]+(?:\.[\dxX*]+){0,2}(?:[-+][\w.-]+)?)$/.exec(token);
|
|
20
|
+
if (!m)
|
|
21
|
+
return null;
|
|
22
|
+
const op = m[1] ?? '';
|
|
23
|
+
const raw = m[2];
|
|
24
|
+
const parts = raw.split(/[-+]/)[0].split('.');
|
|
25
|
+
const isWild = (p) => p === undefined || /^[xX*]$/.test(p);
|
|
26
|
+
const nums = parts.map((p) => (isWild(p) ? null : Number(p)));
|
|
27
|
+
if (nums[0] === null)
|
|
28
|
+
return op === '<' ? false : true; // "*" / "x"
|
|
29
|
+
const lo = [nums[0], nums[1] ?? 0, nums[2] ?? 0];
|
|
30
|
+
const specified = nums.filter((n) => n !== null).length; // 1..3
|
|
31
|
+
// Límite superior exclusivo para comodín / parcial ("1.2" => <1.3.0).
|
|
32
|
+
const bump = (n) => (n === 1 ? [lo[0] + 1, 0, 0] : n === 2 ? [lo[0], lo[1] + 1, 0] : [lo[0], lo[1], lo[2] + 1]);
|
|
33
|
+
switch (op) {
|
|
34
|
+
case '':
|
|
35
|
+
case '=':
|
|
36
|
+
return cmp(v, lo) >= 0 && cmp(v, bump(specified)) < 0;
|
|
37
|
+
case '>=':
|
|
38
|
+
return cmp(v, lo) >= 0;
|
|
39
|
+
case '>':
|
|
40
|
+
return cmp(v, bump(specified)) >= 0;
|
|
41
|
+
case '<':
|
|
42
|
+
return cmp(v, lo) < 0;
|
|
43
|
+
case '<=':
|
|
44
|
+
return cmp(v, bump(specified)) < 0;
|
|
45
|
+
case '~':
|
|
46
|
+
return cmp(v, lo) >= 0 && cmp(v, bump(specified === 1 ? 1 : 2)) < 0;
|
|
47
|
+
case '^': {
|
|
48
|
+
let hi;
|
|
49
|
+
if (lo[0] > 0 || specified === 1)
|
|
50
|
+
hi = [lo[0] + 1, 0, 0];
|
|
51
|
+
else if (lo[1] > 0 || specified === 2)
|
|
52
|
+
hi = [0, lo[1] + 1, 0];
|
|
53
|
+
else
|
|
54
|
+
hi = [0, 0, lo[2] + 1];
|
|
55
|
+
return cmp(v, lo) >= 0 && cmp(v, hi) < 0;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* ¿`version` cumple `range`? `true`/`false` si ambos se entienden, `null` si
|
|
62
|
+
* alguno no (rango vacío o versión ilegible = sin restricción conocida).
|
|
63
|
+
*/
|
|
64
|
+
export function satisfiesSdkRange(version, range) {
|
|
65
|
+
if (!version || !range || !range.trim())
|
|
66
|
+
return null;
|
|
67
|
+
const v = parseVersion(version);
|
|
68
|
+
if (!v)
|
|
69
|
+
return null;
|
|
70
|
+
let unknown = false;
|
|
71
|
+
for (const alt of range.split('||')) {
|
|
72
|
+
// "1.2.3 - 2.0.0" no se soporta: cae en `unknown`.
|
|
73
|
+
const tokens = alt.trim().split(/\s+/).filter(Boolean);
|
|
74
|
+
if (tokens.length === 0) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
let ok = true;
|
|
78
|
+
for (const t of tokens) {
|
|
79
|
+
const r = matchComparator(t, v);
|
|
80
|
+
if (r === null) {
|
|
81
|
+
unknown = true;
|
|
82
|
+
ok = false;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (!r)
|
|
86
|
+
ok = false;
|
|
87
|
+
}
|
|
88
|
+
if (ok)
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
return unknown ? null : false;
|
|
92
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type TriState = 'true' | 'false' | 'null';
|
|
2
|
+
/** Valor de formulario → estado del control. `''`/null/undefined son «Sin definir». */
|
|
3
|
+
export declare function toTriState(value: unknown): TriState;
|
|
4
|
+
/** Estado del control → valor que viaja al servidor. */
|
|
5
|
+
export declare function fromTriState(state: TriState): boolean | null;
|
|
6
|
+
export interface TriStateBooleanFieldProps {
|
|
7
|
+
id?: string;
|
|
8
|
+
value: unknown;
|
|
9
|
+
onChange: (value: boolean | null) => void;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Nombre accesible del grupo (la etiqueta del campo; se traduce como las demás). */
|
|
12
|
+
label?: string;
|
|
13
|
+
/** id del <label> visible: el radiogroup no es «labelable», se asocia por aria-labelledby. */
|
|
14
|
+
labelledBy?: string;
|
|
15
|
+
size?: 'sm' | 'default';
|
|
16
|
+
invalid?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Control de tres estados para un booleano opcional. Es un `radiogroup`
|
|
20
|
+
* (SegmentedControl de metacore-ui): flechas para moverse, el estado elegido
|
|
21
|
+
* se marca con relleno y `aria-checked`. «Sin definir» envía `null`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function TriStateBooleanField({ id, value, onChange, disabled, label, labelledBy, size, invalid, }: TriStateBooleanFieldProps): import("react").JSX.Element;
|
|
24
|
+
//# sourceMappingURL=tri-state-boolean-impl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tri-state-boolean-impl.d.ts","sourceRoot":"","sources":["../src/tri-state-boolean-impl.tsx"],"names":[],"mappings":"AAKA,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAEhD,uFAAuF;AACvF,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAInD;AAED,wDAAwD;AACxD,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,CAI5D;AAED,MAAM,WAAW,yBAAyB;IACtC,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,OAAO,CAAA;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;IACzC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,qFAAqF;IACrF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,8FAA8F;IAC9F,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,IAAI,CAAC,EAAE,IAAI,GAAG,SAAS,CAAA;IACvB,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,EACjC,EAAE,EACF,KAAK,EACL,QAAQ,EACR,QAAQ,EACR,KAAK,EACL,UAAU,EACV,IAAW,EACX,OAAO,GACV,EAAE,yBAAyB,+BAsB3B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Control de tres estados para booleanos opcionales (ver nullable-boolean.ts).
|
|
3
|
+
// Se carga diferido desde tri-state-boolean.tsx para no pesar en el shell.
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { SegmentedControl } from '@asteby/metacore-ui/primitives';
|
|
6
|
+
/** Valor de formulario → estado del control. `''`/null/undefined son «Sin definir». */
|
|
7
|
+
export function toTriState(value) {
|
|
8
|
+
if (value === true || value === 'true')
|
|
9
|
+
return 'true';
|
|
10
|
+
if (value === false || value === 'false')
|
|
11
|
+
return 'false';
|
|
12
|
+
return 'null';
|
|
13
|
+
}
|
|
14
|
+
/** Estado del control → valor que viaja al servidor. */
|
|
15
|
+
export function fromTriState(state) {
|
|
16
|
+
if (state === 'true')
|
|
17
|
+
return true;
|
|
18
|
+
if (state === 'false')
|
|
19
|
+
return false;
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Control de tres estados para un booleano opcional. Es un `radiogroup`
|
|
24
|
+
* (SegmentedControl de metacore-ui): flechas para moverse, el estado elegido
|
|
25
|
+
* se marca con relleno y `aria-checked`. «Sin definir» envía `null`.
|
|
26
|
+
*/
|
|
27
|
+
export function TriStateBooleanField({ id, value, onChange, disabled, label, labelledBy, size = 'sm', invalid, }) {
|
|
28
|
+
const { t } = useTranslation();
|
|
29
|
+
const items = [
|
|
30
|
+
{ value: 'true', label: t('common.yes', { defaultValue: 'Sí' }), disabled },
|
|
31
|
+
{ value: 'false', label: t('common.no', { defaultValue: 'No' }), disabled },
|
|
32
|
+
{ value: 'null', label: t('common.unset', { defaultValue: 'Sin definir' }), disabled },
|
|
33
|
+
];
|
|
34
|
+
return (_jsx(SegmentedControl, { id: id, items: items, value: toTriState(value), onValueChange: (s) => onChange(fromTriState(s)), "aria-label": label ? t(label, { defaultValue: label }) : t('common.unset', { defaultValue: 'Sin definir' }), "aria-labelledby": labelledBy, "aria-invalid": invalid || undefined, "aria-disabled": disabled || undefined, "data-tri-state": "", size: size, className: "w-fit" }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TriStateBooleanFieldProps } from './tri-state-boolean-impl';
|
|
2
|
+
export type { TriStateBooleanFieldProps } from './tri-state-boolean-impl';
|
|
3
|
+
/**
|
|
4
|
+
* Control Sí / No / Sin definir para un booleano opcional. «Sin definir»
|
|
5
|
+
* envía `null`. Accesible (radiogroup con flechas) y con i18n es/en.
|
|
6
|
+
*/
|
|
7
|
+
export declare function TriStateBooleanField(props: TriStateBooleanFieldProps): import("react").JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* Celda/vista de solo lectura para un booleano NULL: «—» (misma convención que
|
|
10
|
+
* `formatDisplayValue`), con «Sin definir» como nombre accesible y tooltip.
|
|
11
|
+
*/
|
|
12
|
+
export declare function NullBooleanMark({ className }: {
|
|
13
|
+
className?: string;
|
|
14
|
+
}): import("react").JSX.Element;
|
|
15
|
+
//# sourceMappingURL=tri-state-boolean.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tri-state-boolean.d.ts","sourceRoot":"","sources":["../src/tri-state-boolean.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAA;AAEzE,YAAY,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAA;AAMzE;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,+BAMpE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,+BAQpE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Booleanos opcionales: control de tres estados (diferido) y marca de NULL.
|
|
3
|
+
// El control vive en tri-state-boolean-impl.tsx y se carga con React.lazy: sólo
|
|
4
|
+
// lo baja quien abre un formulario con un booleano opcional, así no suma al
|
|
5
|
+
// shell inicial de la app.
|
|
6
|
+
import { Suspense, lazy } from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
const Impl = lazy(() => import('./tri-state-boolean-impl').then((m) => ({ default: m.TriStateBooleanField })));
|
|
9
|
+
/**
|
|
10
|
+
* Control Sí / No / Sin definir para un booleano opcional. «Sin definir»
|
|
11
|
+
* envía `null`. Accesible (radiogroup con flechas) y con i18n es/en.
|
|
12
|
+
*/
|
|
13
|
+
export function TriStateBooleanField(props) {
|
|
14
|
+
return (_jsx(Suspense, { fallback: _jsx("span", { className: "inline-block h-8", "aria-busy": "true" }), children: _jsx(Impl, { ...props }) }));
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Celda/vista de solo lectura para un booleano NULL: «—» (misma convención que
|
|
18
|
+
* `formatDisplayValue`), con «Sin definir» como nombre accesible y tooltip.
|
|
19
|
+
*/
|
|
20
|
+
export function NullBooleanMark({ className }) {
|
|
21
|
+
const { t } = useTranslation();
|
|
22
|
+
const label = t('common.unset', { defaultValue: 'Sin definir' });
|
|
23
|
+
return (_jsx("span", { className: className ?? 'text-muted-foreground', title: label, "aria-label": label, "data-bool-null": "", children: "\u2014" }));
|
|
24
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-dynamic-filters.d.ts","sourceRoot":"","sources":["../src/use-dynamic-filters.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-dynamic-filters.d.ts","sourceRoot":"","sources":["../src/use-dynamic-filters.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,kBAAkB,EAAgB,MAAM,wBAAwB,CAAA;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,MAAM,WAAW,wBAAwB;IACvC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,4EAA4E;IAC5E,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAA;IACxC,sDAAsD;IACtD,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,iFAAiF;IACjF,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAA;IACpD;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACjC,uDAAuD;IACvD,yBAAyB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;IACxE,kEAAkE;IAClE,iBAAiB,EAAE,MAAM,CAAA;IACzB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,aAAa,GAAG,IAAI,EAC9B,IAAI,GAAE,wBAA6B,GAClC,uBAAuB,CAgUzB"}
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
// filtering (RFC: a board is just another view of the model), so the logic is
|
|
12
12
|
// factored here to guarantee both surfaces filter identically.
|
|
13
13
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
14
|
+
import { useTranslation } from 'react-i18next';
|
|
14
15
|
import { useApi } from './api-context';
|
|
16
|
+
import { withBooleanUnsetOption } from './nullable-boolean';
|
|
15
17
|
import { DATE_CELL_TYPES } from './dynamic-columns';
|
|
16
18
|
import { getSearchableColumnKeys } from './column-visibility';
|
|
17
19
|
import { useDebouncedValue } from './use-debounced-value';
|
|
@@ -25,6 +27,9 @@ import { useFacetLoaders, isLongTextColumn } from './use-facet-loaders';
|
|
|
25
27
|
export function useDynamicFilters(metadata, opts = {}) {
|
|
26
28
|
const { defaultFilters, model, endpoint, facetsEndpoint } = opts;
|
|
27
29
|
const api = useApi();
|
|
30
|
+
const { t } = useTranslation();
|
|
31
|
+
// «Sin definir» del filtro booleano (NULL), ver withBooleanUnsetOption.
|
|
32
|
+
const unsetLabel = t('common.unset', { defaultValue: 'Sin definir' });
|
|
28
33
|
const [dynamicFilters, setDynamicFilters] = useState({});
|
|
29
34
|
const [globalFilter, setGlobalFilter] = useState('');
|
|
30
35
|
const debouncedGlobalFilter = useDebouncedValue(globalFilter);
|
|
@@ -161,6 +166,8 @@ export function useDynamicFilters(metadata, opts = {}) {
|
|
|
161
166
|
}
|
|
162
167
|
if (fType === 'select' && options.length === 0 && !f.searchEndpoint)
|
|
163
168
|
continue;
|
|
169
|
+
if (fType === 'boolean')
|
|
170
|
+
options = withBooleanUnsetOption(options, unsetLabel);
|
|
164
171
|
map.set(f.key, {
|
|
165
172
|
filterType: fType,
|
|
166
173
|
filterKey: f.column || f.key,
|
|
@@ -214,6 +221,8 @@ export function useDynamicFilters(metadata, opts = {}) {
|
|
|
214
221
|
: [];
|
|
215
222
|
if (isStageColumn)
|
|
216
223
|
options = stageOptions;
|
|
224
|
+
if (filterType === 'boolean')
|
|
225
|
+
options = withBooleanUnsetOption(options, unsetLabel);
|
|
217
226
|
// (B) Upgrade a plain text filter to a facet value-picker (unless it's a
|
|
218
227
|
// long-text/body column — too many unique values to enumerate).
|
|
219
228
|
let loadOptions;
|
|
@@ -246,6 +255,7 @@ export function useDynamicFilters(metadata, opts = {}) {
|
|
|
246
255
|
facetsBase,
|
|
247
256
|
getFacetLoader,
|
|
248
257
|
facetOptions,
|
|
258
|
+
unsetLabel,
|
|
249
259
|
]);
|
|
250
260
|
// Prewarm every facet field in one burst once the configs settle, so the
|
|
251
261
|
// Sheet popover and the lane value-picker open instantly (values + counts)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-runtime-react",
|
|
3
|
-
"version": "53.
|
|
3
|
+
"version": "53.15.0",
|
|
4
4
|
"description": "React runtime for metacore hosts — renders addon contributions dynamically",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"zod": "^4.3.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@asteby/metacore-sdk": "^3.
|
|
46
|
-
"@asteby/metacore-ui": "^2.32.
|
|
45
|
+
"@asteby/metacore-sdk": "^3.19.0",
|
|
46
|
+
"@asteby/metacore-ui": "^2.32.1",
|
|
47
47
|
"@tanstack/react-query": ">=5",
|
|
48
48
|
"@tanstack/react-router": ">=1.100",
|
|
49
49
|
"@tanstack/react-table": ">=8",
|
|
@@ -74,8 +74,8 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@asteby/metacore-sdk": "3.
|
|
78
|
-
"@asteby/metacore-ui": "2.32.
|
|
77
|
+
"@asteby/metacore-sdk": "3.19.0",
|
|
78
|
+
"@asteby/metacore-ui": "2.32.1",
|
|
79
79
|
"@tanstack/react-query": "^5.95.0",
|
|
80
80
|
"@tanstack/react-router": "^1.168.0",
|
|
81
81
|
"@tanstack/react-table": "^8.20.0",
|