@asteby/metacore-runtime-react 45.0.0 → 45.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/action-modal-dispatcher.d.ts +29 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +115 -6
- package/dist/activity-diff.d.ts +2 -0
- package/dist/activity-diff.d.ts.map +1 -1
- package/dist/activity-diff.js +2 -2
- package/dist/approval-events.d.ts +16 -0
- package/dist/approval-events.d.ts.map +1 -0
- package/dist/approval-events.js +27 -0
- package/dist/approval-gate.d.ts +39 -0
- package/dist/approval-gate.d.ts.map +1 -0
- package/dist/approval-gate.js +110 -0
- package/dist/approval-pin-dialog.d.ts +25 -0
- package/dist/approval-pin-dialog.d.ts.map +1 -0
- package/dist/approval-pin-dialog.js +66 -0
- package/dist/business/catalog.d.ts +16 -0
- package/dist/business/catalog.d.ts.map +1 -0
- package/dist/business/catalog.js +50 -0
- package/dist/business/customer-picker.d.ts +39 -0
- package/dist/business/customer-picker.d.ts.map +1 -0
- package/dist/business/customer-picker.js +51 -0
- package/dist/business/feedback.d.ts +72 -0
- package/dist/business/feedback.d.ts.map +1 -0
- package/dist/business/feedback.js +52 -0
- package/dist/business/field-errors.d.ts +26 -0
- package/dist/business/field-errors.d.ts.map +1 -0
- package/dist/business/field-errors.js +59 -0
- package/dist/business/format.d.ts +49 -0
- package/dist/business/format.d.ts.map +1 -0
- package/dist/business/format.js +128 -0
- package/dist/business/index.d.ts +16 -0
- package/dist/business/index.d.ts.map +1 -0
- package/dist/business/index.js +15 -0
- package/dist/business/line-items-editor.d.ts +25 -0
- package/dist/business/line-items-editor.d.ts.map +1 -0
- package/dist/business/line-items-editor.js +36 -0
- package/dist/business/line-items.d.ts +69 -0
- package/dist/business/line-items.d.ts.map +1 -0
- package/dist/business/line-items.js +133 -0
- package/dist/business/payment-capture.d.ts +21 -0
- package/dist/business/payment-capture.d.ts.map +1 -0
- package/dist/business/payment-capture.js +24 -0
- package/dist/business/payment.d.ts +61 -0
- package/dist/business/payment.d.ts.map +1 -0
- package/dist/business/payment.js +74 -0
- package/dist/business/product-picker.d.ts +24 -0
- package/dist/business/product-picker.d.ts.map +1 -0
- package/dist/business/product-picker.js +48 -0
- package/dist/business/product-search.d.ts +70 -0
- package/dist/business/product-search.d.ts.map +1 -0
- package/dist/business/product-search.js +51 -0
- package/dist/business/refund-destination.d.ts +19 -0
- package/dist/business/refund-destination.d.ts.map +1 -0
- package/dist/business/refund-destination.js +31 -0
- package/dist/business/refund.d.ts +29 -0
- package/dist/business/refund.d.ts.map +1 -0
- package/dist/business/refund.js +44 -0
- package/dist/business/return-wizard.d.ts +23 -0
- package/dist/business/return-wizard.d.ts.map +1 -0
- package/dist/business/return-wizard.js +59 -0
- package/dist/business/return.d.ts +90 -0
- package/dist/business/return.d.ts.map +1 -0
- package/dist/business/return.js +112 -0
- package/dist/business/use-async-search.d.ts +10 -0
- package/dist/business/use-async-search.d.ts.map +1 -0
- package/dist/business/use-async-search.js +38 -0
- package/dist/document/action-bar.d.ts +12 -0
- package/dist/document/action-bar.d.ts.map +1 -0
- package/dist/document/action-bar.js +39 -0
- package/dist/document/cancel-with-reason.d.ts +47 -0
- package/dist/document/cancel-with-reason.d.ts.map +1 -0
- package/dist/document/cancel-with-reason.js +52 -0
- package/dist/document/document-header.d.ts +41 -0
- package/dist/document/document-header.d.ts.map +1 -0
- package/dist/document/document-header.js +30 -0
- package/dist/document/document-page.d.ts +37 -0
- package/dist/document/document-page.d.ts.map +1 -0
- package/dist/document/document-page.js +137 -0
- package/dist/document/document-timeline.d.ts +20 -0
- package/dist/document/document-timeline.d.ts.map +1 -0
- package/dist/document/document-timeline.js +26 -0
- package/dist/document/evaluate.d.ts +31 -0
- package/dist/document/evaluate.d.ts.map +1 -0
- package/dist/document/evaluate.js +170 -0
- package/dist/document/format.d.ts +9 -0
- package/dist/document/format.d.ts.map +1 -0
- package/dist/document/format.js +52 -0
- package/dist/document/index.d.ts +13 -0
- package/dist/document/index.d.ts.map +1 -0
- package/dist/document/index.js +12 -0
- package/dist/document/registry.d.ts +20 -0
- package/dist/document/registry.d.ts.map +1 -0
- package/dist/document/registry.js +20 -0
- package/dist/document/smart-buttons.d.ts +16 -0
- package/dist/document/smart-buttons.d.ts.map +1 -0
- package/dist/document/smart-buttons.js +16 -0
- package/dist/document/status-badge.d.ts +16 -0
- package/dist/document/status-badge.d.ts.map +1 -0
- package/dist/document/status-badge.js +23 -0
- package/dist/document/types.d.ts +196 -0
- package/dist/document/types.d.ts.map +1 -0
- package/dist/document/types.js +1 -0
- package/dist/document/use-document-sources.d.ts +14 -0
- package/dist/document/use-document-sources.d.ts.map +1 -0
- package/dist/document/use-document-sources.js +72 -0
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +3 -1
- package/dist/dynamic-relation.d.ts +4 -0
- package/dist/dynamic-relation.d.ts.map +1 -1
- package/dist/dynamic-relation.js +10 -1
- package/dist/dynamic-row-actions.d.ts.map +1 -1
- package/dist/dynamic-row-actions.js +14 -2
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +28 -3
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/reason-prompt.d.ts +59 -0
- package/dist/reason-prompt.d.ts.map +1 -0
- package/dist/reason-prompt.js +111 -0
- package/dist/server-error.d.ts.map +1 -1
- package/dist/server-error.js +19 -0
- package/dist/use-addon-settings.d.ts +17 -3
- package/dist/use-addon-settings.d.ts.map +1 -1
- package/dist/use-addon-settings.js +20 -8
- package/package.json +1 -1
- package/src/__tests__/approval-gate.test.tsx +134 -0
- package/src/__tests__/prefill-from-record.test.ts +69 -0
- package/src/__tests__/reason-prompt.test.tsx +121 -0
- package/src/__tests__/use-addon-settings.test.ts +16 -1
- package/src/action-modal-dispatcher.tsx +145 -3
- package/src/activity-diff.tsx +10 -1
- package/src/approval-events.ts +39 -0
- package/src/approval-gate.tsx +180 -0
- package/src/approval-pin-dialog.tsx +162 -0
- package/src/business/business.test.ts +210 -0
- package/src/business/catalog.ts +68 -0
- package/src/business/customer-picker.tsx +201 -0
- package/src/business/feedback.tsx +141 -0
- package/src/business/field-errors.ts +92 -0
- package/src/business/format.ts +151 -0
- package/src/business/index.ts +15 -0
- package/src/business/line-items-editor.tsx +259 -0
- package/src/business/line-items.ts +190 -0
- package/src/business/payment-capture.tsx +158 -0
- package/src/business/payment.ts +125 -0
- package/src/business/product-picker.tsx +171 -0
- package/src/business/product-search.ts +108 -0
- package/src/business/refund-destination.tsx +121 -0
- package/src/business/refund.ts +72 -0
- package/src/business/return-wizard.tsx +223 -0
- package/src/business/return.ts +181 -0
- package/src/business/use-async-search.ts +43 -0
- package/src/document/__tests__/document-page.test.tsx +107 -0
- package/src/document/__tests__/evaluate.test.ts +140 -0
- package/src/document/action-bar.tsx +140 -0
- package/src/document/cancel-with-reason.tsx +214 -0
- package/src/document/document-header.tsx +140 -0
- package/src/document/document-page.tsx +268 -0
- package/src/document/document-timeline.tsx +66 -0
- package/src/document/evaluate.ts +180 -0
- package/src/document/format.ts +59 -0
- package/src/document/index.ts +28 -0
- package/src/document/registry.ts +39 -0
- package/src/document/smart-buttons.tsx +54 -0
- package/src/document/status-badge.tsx +44 -0
- package/src/document/types.ts +203 -0
- package/src/document/use-document-sources.ts +91 -0
- package/src/dynamic-columns.tsx +5 -1
- package/src/dynamic-relation.tsx +14 -1
- package/src/dynamic-row-actions.tsx +13 -1
- package/src/dynamic-table.tsx +22 -2
- package/src/index.ts +33 -0
- package/src/reason-prompt.tsx +247 -0
- package/src/server-error.ts +20 -0
- package/src/use-addon-settings.ts +26 -7
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// DocumentTimeline — línea de tiempo de eventos de negocio del documento
|
|
3
|
+
// («creó», «timbró», «envió a…», «abrió», «pagó», «solicitó cancelación»,
|
|
4
|
+
// «respuesta del SAT»). Complementa a <RecordHistory> (que muestra diffs de
|
|
5
|
+
// campos): aquí cada entrada es un hecho legible, con actor y hora.
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
7
|
+
import { Circle } from 'lucide-react';
|
|
8
|
+
import { cn } from '@asteby/metacore-ui/lib';
|
|
9
|
+
import { DynamicIcon } from '../dynamic-icon';
|
|
10
|
+
import { formatFieldValue } from './format';
|
|
11
|
+
const TONE_DOT = {
|
|
12
|
+
neutral: 'text-muted-foreground',
|
|
13
|
+
info: 'text-[var(--info,oklch(0.55_0.13_235))]',
|
|
14
|
+
success: 'text-[var(--success,oklch(0.6_0.15_155))]',
|
|
15
|
+
caution: 'text-[var(--warning,oklch(0.6_0.15_65))]',
|
|
16
|
+
warning: 'text-[var(--warning,oklch(0.6_0.15_65))]',
|
|
17
|
+
critical: 'text-destructive',
|
|
18
|
+
};
|
|
19
|
+
export function DocumentTimeline({ entries, emptyText, className, ...fmt }) {
|
|
20
|
+
const { t } = useTranslation();
|
|
21
|
+
if (entries.length === 0) {
|
|
22
|
+
return (_jsx("p", { className: 'rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground', children: emptyText ?? t('document.timeline_empty', { defaultValue: 'Aún no hay actividad en este documento.' }) }));
|
|
23
|
+
}
|
|
24
|
+
const sorted = [...entries].sort((a, b) => new Date(b.at).getTime() - new Date(a.at).getTime());
|
|
25
|
+
return (_jsx("ol", { className: cn('relative flex flex-col gap-4 border-l pl-5', className), "data-document-timeline": '', children: sorted.map((e) => (_jsxs("li", { className: 'relative', children: [_jsx("span", { className: cn('absolute -left-[1.85rem] flex h-5 w-5 items-center justify-center rounded-full bg-card', TONE_DOT[e.tone ?? 'neutral']), children: e.icon ? _jsx(DynamicIcon, { name: e.icon, className: 'h-4 w-4' }) : _jsx(Circle, { className: 'h-3 w-3 fill-current' }) }), _jsx("p", { className: 'text-sm font-medium', children: t(e.label, { defaultValue: e.label }) }), _jsxs("p", { className: 'text-xs text-muted-foreground', children: [formatFieldValue(e.at, 'datetime', fmt), e.actor ? ` · ${e.actor}` : ''] }), e.detail ? _jsx("p", { className: 'mt-1 whitespace-pre-wrap text-sm text-muted-foreground', children: e.detail }) : null] }, e.id))) }));
|
|
26
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { DocumentContext, DocumentSpec, Predicate, ResolvedActionLayout, StatusDef, StatusMachine, When } from './types';
|
|
2
|
+
/** Máximo de secundarias visibles; el resto pasa a «Más…» (§5.2 / §6.2). */
|
|
3
|
+
export declare const MAX_VISIBLE_SECONDARY = 3;
|
|
4
|
+
/**
|
|
5
|
+
* Lee una ruta del contexto. `$.x` son los derivados; `sources.k.length` es el
|
|
6
|
+
* total de una fuente; el resto cuelga del registro (`record.x` o `x`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function readPath(ctx: DocumentContext, path: string): unknown;
|
|
9
|
+
export declare function evaluatePredicate(p: Predicate, ctx: DocumentContext): boolean;
|
|
10
|
+
/** Un arreglo es un AND; sin condición siempre se cumple. */
|
|
11
|
+
export declare function evaluateWhen(when: When | undefined, ctx: DocumentContext): boolean;
|
|
12
|
+
/** Estado actual de una máquina para el registro (o su fallback / un estado desconocido explícito). */
|
|
13
|
+
export declare function resolveStatus(machine: StatusMachine, ctx: DocumentContext): StatusDef | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Distribución de acciones para el estado actual. Una acción `hiddenWhen` se
|
|
16
|
+
* omite; una `blockedWhen` queda deshabilitada con motivo. Más de
|
|
17
|
+
* `MAX_VISIBLE_SECONDARY` secundarias se derraman a «Más…»; una acción marcada
|
|
18
|
+
* `destructive` siempre va a la zona destructiva aunque el layout la ponga en otro lado.
|
|
19
|
+
*/
|
|
20
|
+
export declare function resolveActions(spec: DocumentSpec, ctx: DocumentContext): ResolvedActionLayout;
|
|
21
|
+
/** Interpola `{{campo}}` con valores del registro (sin evaluar código). */
|
|
22
|
+
export declare function interpolate(template: string, ctx: DocumentContext): string;
|
|
23
|
+
/** Título: la interpolación puede dejar vacío el resultado; se prueban alternativas separadas por `||`. */
|
|
24
|
+
export declare function resolveTitle(template: string, ctx: DocumentContext): string;
|
|
25
|
+
/**
|
|
26
|
+
* Quita del spec las acciones que dependen de una acción del modelo que el
|
|
27
|
+
* backend (o el addon que la aporta) no declara: mejor un botón menos que uno
|
|
28
|
+
* que abre un modal vacío. Las que resuelve la propia página (`href`/`openUrl`/`tab`) siempre se conservan.
|
|
29
|
+
*/
|
|
30
|
+
export declare function pruneUnavailableActions(spec: DocumentSpec, availableModelActions: Iterable<string>): DocumentSpec;
|
|
31
|
+
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/document/evaluate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,eAAe,EACf,YAAY,EACZ,SAAS,EAET,oBAAoB,EACpB,SAAS,EACT,aAAa,EACb,IAAI,EACP,MAAM,SAAS,CAAA;AAEhB,4EAA4E;AAC5E,eAAO,MAAM,qBAAqB,IAAI,CAAA;AAEtC;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAuBpE;AAkBD,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CA0B7E;AAED,6DAA6D;AAC7D,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,GAAG,EAAE,eAAe,GAAG,OAAO,CAIlF;AAED,uGAAuG;AACvG,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,eAAe,GAAG,SAAS,GAAG,SAAS,CAQjG;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,eAAe,GAAG,oBAAoB,CAoC7F;AAED,2EAA2E;AAC3E,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,GAAG,MAAM,CAK1E;AAED,2GAA2G;AAC3G,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,GAAG,MAAM,CAM3E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,qBAAqB,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,YAAY,CAMjH"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/** Máximo de secundarias visibles; el resto pasa a «Más…» (§5.2 / §6.2). */
|
|
2
|
+
export const MAX_VISIBLE_SECONDARY = 3;
|
|
3
|
+
/**
|
|
4
|
+
* Lee una ruta del contexto. `$.x` son los derivados; `sources.k.length` es el
|
|
5
|
+
* total de una fuente; el resto cuelga del registro (`record.x` o `x`).
|
|
6
|
+
*/
|
|
7
|
+
export function readPath(ctx, path) {
|
|
8
|
+
if (!path)
|
|
9
|
+
return undefined;
|
|
10
|
+
let parts = path.split('.');
|
|
11
|
+
let cur;
|
|
12
|
+
if (parts[0] === '$') {
|
|
13
|
+
cur = ctx.derived;
|
|
14
|
+
parts = parts.slice(1);
|
|
15
|
+
}
|
|
16
|
+
else if (parts[0] === 'sources') {
|
|
17
|
+
cur = ctx.sources;
|
|
18
|
+
parts = parts.slice(1);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
cur = ctx.record;
|
|
22
|
+
if (parts[0] === 'record')
|
|
23
|
+
parts = parts.slice(1);
|
|
24
|
+
}
|
|
25
|
+
for (const p of parts) {
|
|
26
|
+
if (cur == null)
|
|
27
|
+
return undefined;
|
|
28
|
+
if (p === 'length' && Array.isArray(cur)) {
|
|
29
|
+
cur = cur.length;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
cur = cur[p];
|
|
33
|
+
}
|
|
34
|
+
return cur;
|
|
35
|
+
}
|
|
36
|
+
function sameValue(a, b) {
|
|
37
|
+
if (a == null || b == null)
|
|
38
|
+
return a == b;
|
|
39
|
+
return String(a) === String(b);
|
|
40
|
+
}
|
|
41
|
+
function isTruthy(v) {
|
|
42
|
+
if (v == null || v === false || v === '' || v === 0)
|
|
43
|
+
return false;
|
|
44
|
+
if (Array.isArray(v))
|
|
45
|
+
return v.length > 0;
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
function toNumber(v) {
|
|
49
|
+
const n = typeof v === 'number' ? v : parseFloat(String(v));
|
|
50
|
+
return Number.isFinite(n) ? n : NaN;
|
|
51
|
+
}
|
|
52
|
+
export function evaluatePredicate(p, ctx) {
|
|
53
|
+
const v = readPath(ctx, p.field);
|
|
54
|
+
switch (p.op) {
|
|
55
|
+
case 'eq':
|
|
56
|
+
return sameValue(v, p.value);
|
|
57
|
+
case 'neq':
|
|
58
|
+
return !sameValue(v, p.value);
|
|
59
|
+
case 'in':
|
|
60
|
+
return Array.isArray(p.value) && p.value.some((x) => sameValue(v, x));
|
|
61
|
+
case 'not_in':
|
|
62
|
+
return !(Array.isArray(p.value) && p.value.some((x) => sameValue(v, x)));
|
|
63
|
+
case 'truthy':
|
|
64
|
+
return isTruthy(v);
|
|
65
|
+
case 'falsy':
|
|
66
|
+
return !isTruthy(v);
|
|
67
|
+
case 'gt':
|
|
68
|
+
return toNumber(v) > toNumber(p.value);
|
|
69
|
+
case 'gte':
|
|
70
|
+
return toNumber(v) >= toNumber(p.value);
|
|
71
|
+
case 'lt':
|
|
72
|
+
return toNumber(v) < toNumber(p.value);
|
|
73
|
+
case 'lte':
|
|
74
|
+
return toNumber(v) <= toNumber(p.value);
|
|
75
|
+
default:
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Un arreglo es un AND; sin condición siempre se cumple. */
|
|
80
|
+
export function evaluateWhen(when, ctx) {
|
|
81
|
+
if (!when)
|
|
82
|
+
return true;
|
|
83
|
+
const list = Array.isArray(when) ? when : [when];
|
|
84
|
+
return list.every((p) => evaluatePredicate(p, ctx));
|
|
85
|
+
}
|
|
86
|
+
/** Estado actual de una máquina para el registro (o su fallback / un estado desconocido explícito). */
|
|
87
|
+
export function resolveStatus(machine, ctx) {
|
|
88
|
+
const raw = readPath(ctx, machine.field);
|
|
89
|
+
const value = raw == null ? '' : String(raw);
|
|
90
|
+
const found = machine.states.find((s) => s.value === value);
|
|
91
|
+
if (found)
|
|
92
|
+
return found;
|
|
93
|
+
if (machine.fallback)
|
|
94
|
+
return machine.fallback;
|
|
95
|
+
if (!value)
|
|
96
|
+
return undefined;
|
|
97
|
+
return { value, label: value, tone: 'neutral' };
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Distribución de acciones para el estado actual. Una acción `hiddenWhen` se
|
|
101
|
+
* omite; una `blockedWhen` queda deshabilitada con motivo. Más de
|
|
102
|
+
* `MAX_VISIBLE_SECONDARY` secundarias se derraman a «Más…»; una acción marcada
|
|
103
|
+
* `destructive` siempre va a la zona destructiva aunque el layout la ponga en otro lado.
|
|
104
|
+
*/
|
|
105
|
+
export function resolveActions(spec, ctx) {
|
|
106
|
+
const byKey = new Map(spec.actions.map((a) => [a.key, a]));
|
|
107
|
+
const layout = spec.layouts.find((r) => evaluateWhen(r.when, ctx))?.layout ?? spec.defaultLayout ?? {};
|
|
108
|
+
const resolve = (key) => {
|
|
109
|
+
if (!key)
|
|
110
|
+
return undefined;
|
|
111
|
+
const def = byKey.get(key);
|
|
112
|
+
if (!def || (def.hiddenWhen && evaluateWhen(def.hiddenWhen, ctx)))
|
|
113
|
+
return undefined;
|
|
114
|
+
const rules = def.blockedWhen ? (Array.isArray(def.blockedWhen) ? def.blockedWhen : [def.blockedWhen]) : [];
|
|
115
|
+
const hit = rules.find((r) => evaluateWhen(r.when, ctx));
|
|
116
|
+
return { def, blockedReason: hit?.reason };
|
|
117
|
+
};
|
|
118
|
+
const many = (keys) => (keys ?? []).map(resolve).filter((a) => !!a);
|
|
119
|
+
const destructive = many(layout.destructive);
|
|
120
|
+
const secondary = [];
|
|
121
|
+
const more = [];
|
|
122
|
+
for (const a of [...many(layout.secondary)]) {
|
|
123
|
+
if (a.def.destructive)
|
|
124
|
+
destructive.push(a);
|
|
125
|
+
else
|
|
126
|
+
secondary.push(a);
|
|
127
|
+
}
|
|
128
|
+
for (const a of many(layout.more)) {
|
|
129
|
+
if (a.def.destructive)
|
|
130
|
+
destructive.push(a);
|
|
131
|
+
else
|
|
132
|
+
more.push(a);
|
|
133
|
+
}
|
|
134
|
+
const overflow = secondary.splice(MAX_VISIBLE_SECONDARY);
|
|
135
|
+
more.unshift(...overflow);
|
|
136
|
+
let primary = resolve(layout.primary);
|
|
137
|
+
if (primary?.def.destructive) {
|
|
138
|
+
destructive.unshift(primary);
|
|
139
|
+
primary = undefined;
|
|
140
|
+
}
|
|
141
|
+
return { primary, secondary, more, destructive };
|
|
142
|
+
}
|
|
143
|
+
/** Interpola `{{campo}}` con valores del registro (sin evaluar código). */
|
|
144
|
+
export function interpolate(template, ctx) {
|
|
145
|
+
return template.replace(/\{\{\s*([\w.$]+)\s*\}\}/g, (_, path) => {
|
|
146
|
+
const v = readPath(ctx, path);
|
|
147
|
+
return v == null ? '' : String(v);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/** Título: la interpolación puede dejar vacío el resultado; se prueban alternativas separadas por `||`. */
|
|
151
|
+
export function resolveTitle(template, ctx) {
|
|
152
|
+
for (const alt of template.split('||')) {
|
|
153
|
+
const out = interpolate(alt.trim(), ctx).trim();
|
|
154
|
+
if (out)
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
return '';
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Quita del spec las acciones que dependen de una acción del modelo que el
|
|
161
|
+
* backend (o el addon que la aporta) no declara: mejor un botón menos que uno
|
|
162
|
+
* que abre un modal vacío. Las que resuelve la propia página (`href`/`openUrl`/`tab`) siempre se conservan.
|
|
163
|
+
*/
|
|
164
|
+
export function pruneUnavailableActions(spec, availableModelActions) {
|
|
165
|
+
const have = new Set(availableModelActions);
|
|
166
|
+
return {
|
|
167
|
+
...spec,
|
|
168
|
+
actions: spec.actions.filter((a) => a.href || a.openUrl || a.tab || have.has(a.modelAction ?? a.key)),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DocumentFieldDef } from './types';
|
|
2
|
+
export interface FieldFormatOptions {
|
|
3
|
+
locale?: string;
|
|
4
|
+
currency?: string;
|
|
5
|
+
timeZone?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Formatea un valor de campo; vacío → «—». Moneda y zona horaria son config de la org, no se hardcodean. */
|
|
8
|
+
export declare function formatFieldValue(value: unknown, format?: DocumentFieldDef['format'], opts?: FieldFormatOptions): string;
|
|
9
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../src/document/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,MAAM,WAAW,kBAAkB;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,6GAA6G;AAC7G,wBAAgB,gBAAgB,CAC5B,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,gBAAgB,CAAC,QAAQ,CAAU,EAC3C,IAAI,GAAE,kBAAuB,GAC9B,MAAM,CA6CR"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** Formatea un valor de campo; vacío → «—». Moneda y zona horaria son config de la org, no se hardcodean. */
|
|
2
|
+
export function formatFieldValue(value, format = 'text', opts = {}) {
|
|
3
|
+
if (value === null || value === undefined || value === '')
|
|
4
|
+
return '—';
|
|
5
|
+
const locale = opts.locale || 'es-MX';
|
|
6
|
+
// Relación resuelta por el kernel: `{value,label}` o un objeto con `name`.
|
|
7
|
+
if (typeof value === 'object' && !(value instanceof Date)) {
|
|
8
|
+
const o = value;
|
|
9
|
+
const text = o.label ?? o.name ?? o.title;
|
|
10
|
+
return text == null || text === '' ? '—' : String(text);
|
|
11
|
+
}
|
|
12
|
+
switch (format) {
|
|
13
|
+
case 'money': {
|
|
14
|
+
const n = typeof value === 'number' ? value : parseFloat(String(value));
|
|
15
|
+
if (!Number.isFinite(n))
|
|
16
|
+
return '—';
|
|
17
|
+
try {
|
|
18
|
+
return new Intl.NumberFormat(locale, {
|
|
19
|
+
style: 'currency',
|
|
20
|
+
currency: opts.currency || 'USD',
|
|
21
|
+
}).format(n);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return n.toFixed(2);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
case 'percent': {
|
|
28
|
+
const n = typeof value === 'number' ? value : parseFloat(String(value));
|
|
29
|
+
return Number.isFinite(n) ? `${n}%` : '—';
|
|
30
|
+
}
|
|
31
|
+
case 'date':
|
|
32
|
+
case 'datetime': {
|
|
33
|
+
const d = new Date(String(value));
|
|
34
|
+
if (Number.isNaN(d.getTime()))
|
|
35
|
+
return String(value);
|
|
36
|
+
try {
|
|
37
|
+
return new Intl.DateTimeFormat(locale, {
|
|
38
|
+
dateStyle: 'medium',
|
|
39
|
+
...(format === 'datetime' ? { timeStyle: 'short' } : {}),
|
|
40
|
+
timeZone: opts.timeZone || undefined,
|
|
41
|
+
}).format(d);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return d.toISOString();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
case 'boolean':
|
|
48
|
+
return value ? 'Sí' : 'No';
|
|
49
|
+
default:
|
|
50
|
+
return String(value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { MAX_VISIBLE_SECONDARY, evaluatePredicate, evaluateWhen, interpolate, pruneUnavailableActions, readPath, resolveActions, resolveStatus, resolveTitle, } from './evaluate';
|
|
3
|
+
export { formatFieldValue, type FieldFormatOptions } from './format';
|
|
4
|
+
export { StatusBadge, STATUS_TONE_STYLE, type StatusBadgeProps } from './status-badge';
|
|
5
|
+
export { ActionBar, type ActionBarProps } from './action-bar';
|
|
6
|
+
export { DocumentHeader, type DocumentHeaderProps, type HeaderBadge, type HeaderMetric } from './document-header';
|
|
7
|
+
export { SmartButtons, type SmartButtonItem, type SmartButtonsProps } from './smart-buttons';
|
|
8
|
+
export { DocumentTimeline, type DocumentTimelineProps, type TimelineEntry } from './document-timeline';
|
|
9
|
+
export { CancelWithReason, type CancelPayload, type CancelReason, type CancelWithReasonProps } from './cancel-with-reason';
|
|
10
|
+
export { DocumentPage, type DocumentPageProps } from './document-page';
|
|
11
|
+
export { useDocumentSources, type DocumentSourcesState } from './use-document-sources';
|
|
12
|
+
export { clearDocumentPages, findStatusMachine, getDocumentPage, registerDocumentPage, type DocumentPageRegistration, } from './registry';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/document/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,OAAO,EACH,qBAAqB,EACrB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,uBAAuB,EACvB,QAAQ,EACR,cAAc,EACd,aAAa,EACb,YAAY,GACf,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,gBAAgB,EAAE,KAAK,kBAAkB,EAAE,MAAM,UAAU,CAAA;AACpE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,KAAK,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACtF,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACjH,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAC5F,OAAO,EAAE,gBAAgB,EAAE,KAAK,qBAAqB,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACtG,OAAO,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC1H,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAE,kBAAkB,EAAE,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AACtF,OAAO,EACH,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EACpB,KAAK,wBAAwB,GAChC,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { MAX_VISIBLE_SECONDARY, evaluatePredicate, evaluateWhen, interpolate, pruneUnavailableActions, readPath, resolveActions, resolveStatus, resolveTitle, } from './evaluate';
|
|
3
|
+
export { formatFieldValue } from './format';
|
|
4
|
+
export { StatusBadge, STATUS_TONE_STYLE } from './status-badge';
|
|
5
|
+
export { ActionBar } from './action-bar';
|
|
6
|
+
export { DocumentHeader } from './document-header';
|
|
7
|
+
export { SmartButtons } from './smart-buttons';
|
|
8
|
+
export { DocumentTimeline } from './document-timeline';
|
|
9
|
+
export { CancelWithReason } from './cancel-with-reason';
|
|
10
|
+
export { DocumentPage } from './document-page';
|
|
11
|
+
export { useDocumentSources } from './use-document-sources';
|
|
12
|
+
export { clearDocumentPages, findStatusMachine, getDocumentPage, registerDocumentPage, } from './registry';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DocumentContext, DocumentSpec, StatusMachine } from './types';
|
|
2
|
+
export interface DocumentPageRegistration {
|
|
3
|
+
spec: DocumentSpec;
|
|
4
|
+
/**
|
|
5
|
+
* Calcula derivados (`$.x`) a partir del registro y las fuentes cargadas —
|
|
6
|
+
* p. ej. el estado fiscal a partir de fiscal_documents y el de cobro a
|
|
7
|
+
* partir de saldo y vencimiento. Función pura, sin efectos.
|
|
8
|
+
*/
|
|
9
|
+
derive?: (ctx: Omit<DocumentContext, 'derived'>) => Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Registra la página bajo `spec.model` y, opcionalmente, bajo alias (la ruta
|
|
13
|
+
* `/m/<model>` puede llegar como `invoices` o `Invoice` según el enlace).
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerDocumentPage(reg: DocumentPageRegistration, aliases?: string[]): void;
|
|
16
|
+
export declare function getDocumentPage(model: string): DocumentPageRegistration | undefined;
|
|
17
|
+
export declare function clearDocumentPages(): void;
|
|
18
|
+
/** Catálogo compartido de estados por id de máquina (lo usan las columnas `status` de las pestañas). */
|
|
19
|
+
export declare function findStatusMachine(spec: DocumentSpec, id: string): StatusMachine | undefined;
|
|
20
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/document/registry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE3E,MAAM,WAAW,wBAAwB;IACrC,IAAI,EAAE,YAAY,CAAA;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9E;AAID;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,wBAAwB,EAAE,OAAO,GAAE,MAAM,EAAO,GAAG,IAAI,CAGhG;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAEnF;AAED,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED,wGAAwG;AACxG,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAE3F"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const registry = new Map();
|
|
2
|
+
/**
|
|
3
|
+
* Registra la página bajo `spec.model` y, opcionalmente, bajo alias (la ruta
|
|
4
|
+
* `/m/<model>` puede llegar como `invoices` o `Invoice` según el enlace).
|
|
5
|
+
*/
|
|
6
|
+
export function registerDocumentPage(reg, aliases = []) {
|
|
7
|
+
registry.set(reg.spec.model, reg);
|
|
8
|
+
for (const a of aliases)
|
|
9
|
+
registry.set(a, reg);
|
|
10
|
+
}
|
|
11
|
+
export function getDocumentPage(model) {
|
|
12
|
+
return registry.get(model);
|
|
13
|
+
}
|
|
14
|
+
export function clearDocumentPages() {
|
|
15
|
+
registry.clear();
|
|
16
|
+
}
|
|
17
|
+
/** Catálogo compartido de estados por id de máquina (lo usan las columnas `status` de las pestañas). */
|
|
18
|
+
export function findStatusMachine(spec, id) {
|
|
19
|
+
return spec.statuses.find((s) => s.id === id) ?? spec.catalogs?.find((s) => s.id === id);
|
|
20
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface SmartButtonItem {
|
|
2
|
+
key: string;
|
|
3
|
+
label: string;
|
|
4
|
+
icon?: string;
|
|
5
|
+
/** undefined = botón sin contador (p. ej. «Pedido origen»). */
|
|
6
|
+
count?: number;
|
|
7
|
+
/** Deshabilitado (sin destino / vacío). */
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
onClick?: () => void;
|
|
10
|
+
}
|
|
11
|
+
export interface SmartButtonsProps {
|
|
12
|
+
items: SmartButtonItem[];
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function SmartButtons({ items, className }: SmartButtonsProps): import("react").JSX.Element | null;
|
|
16
|
+
//# sourceMappingURL=smart-buttons.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-buttons.d.ts","sourceRoot":"","sources":["../../src/document/smart-buttons.tsx"],"names":[],"mappings":"AAOA,MAAM,WAAW,eAAe;IAC5B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACvB;AAED,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,eAAe,EAAE,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,YAAY,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,iBAAiB,sCA8BnE"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// SmartButtons — accesos con contador al estilo Odoo (Pagos (2) · REP (1) ·
|
|
3
|
+
// Notas de crédito (0)…). Un botón sin registros se ve atenuado, no oculto,
|
|
4
|
+
// salvo que la definición pida `hideWhenEmpty`.
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { cn } from '@asteby/metacore-ui/lib';
|
|
7
|
+
import { DynamicIcon } from '../dynamic-icon';
|
|
8
|
+
export function SmartButtons({ items, className }) {
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
if (items.length === 0)
|
|
11
|
+
return null;
|
|
12
|
+
return (_jsx("nav", { "aria-label": t('document.related', { defaultValue: 'Relacionados' }), className: cn('flex flex-wrap gap-2', className), "data-smart-buttons": '', children: items.map((it) => {
|
|
13
|
+
const empty = it.count === 0;
|
|
14
|
+
return (_jsxs("button", { type: 'button', disabled: it.disabled, onClick: it.onClick, "data-smart-button": it.key, className: cn('inline-flex items-center gap-2 rounded-md border bg-card px-3 py-1.5 text-sm transition-colors', 'hover:bg-accent disabled:cursor-default disabled:opacity-50 disabled:hover:bg-card', empty && 'text-muted-foreground'), children: [it.icon ? _jsx(DynamicIcon, { name: it.icon, className: 'h-4 w-4' }) : null, _jsx("span", { children: t(it.label, { defaultValue: it.label }) }), it.count !== undefined ? (_jsx("span", { className: 'rounded-full bg-muted px-1.5 text-xs font-semibold tabular-nums', children: it.count })) : null] }, it.key));
|
|
15
|
+
}) }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type LucideIcon } from 'lucide-react';
|
|
2
|
+
import type { StatusDef, StatusTone } from './types';
|
|
3
|
+
type BadgeVariant = 'muted' | 'info' | 'success' | 'warning' | 'danger';
|
|
4
|
+
export declare const STATUS_TONE_STYLE: Record<StatusTone, {
|
|
5
|
+
variant: BadgeVariant;
|
|
6
|
+
icon: LucideIcon;
|
|
7
|
+
}>;
|
|
8
|
+
export interface StatusBadgeProps {
|
|
9
|
+
status: Pick<StatusDef, 'label' | 'tone' | 'strike'>;
|
|
10
|
+
/** Descripción para lectores de pantalla («Estado fiscal»). */
|
|
11
|
+
srLabel?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function StatusBadge({ status, srLabel, className }: StatusBadgeProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=status-badge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status-badge.d.ts","sourceRoot":"","sources":["../../src/document/status-badge.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAkE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAA;AAG9G,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEpD,KAAK,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,CAAA;AAEvE,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,UAAU,EAAE;IAAE,OAAO,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAO7F,CAAA;AAED,MAAM,WAAW,gBAAgB;IAC7B,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAA;IACpD,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,EAAE,gBAAgB,+BAgB3E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// StatusBadge — badge semántico con texto explícito e ícono por tono: el color
|
|
3
|
+
// nunca es la única señal (benchmark §6.3). El catálogo de estados de cada
|
|
4
|
+
// documento vive en su `StatusMachine`; aquí solo se pinta.
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { AlertOctagon, AlertTriangle, CheckCircle2, Circle, Clock, Info } from 'lucide-react';
|
|
7
|
+
import { Badge } from '@asteby/metacore-ui/primitives';
|
|
8
|
+
import { cn } from '@asteby/metacore-ui/lib';
|
|
9
|
+
export const STATUS_TONE_STYLE = {
|
|
10
|
+
neutral: { variant: 'muted', icon: Circle },
|
|
11
|
+
info: { variant: 'info', icon: Info },
|
|
12
|
+
success: { variant: 'success', icon: CheckCircle2 },
|
|
13
|
+
caution: { variant: 'warning', icon: Clock },
|
|
14
|
+
warning: { variant: 'warning', icon: AlertTriangle },
|
|
15
|
+
critical: { variant: 'danger', icon: AlertOctagon },
|
|
16
|
+
};
|
|
17
|
+
export function StatusBadge({ status, srLabel, className }) {
|
|
18
|
+
const { t } = useTranslation();
|
|
19
|
+
const style = STATUS_TONE_STYLE[status.tone] ?? STATUS_TONE_STYLE.neutral;
|
|
20
|
+
const Icon = style.icon;
|
|
21
|
+
const text = t(status.label, { defaultValue: status.label });
|
|
22
|
+
return (_jsxs(Badge, { variant: style.variant, "data-tone": status.tone, className: cn(status.strike && 'line-through', className), children: [_jsx(Icon, { "aria-hidden": true }), srLabel ? _jsxs("span", { className: 'sr-only', children: [srLabel, ": "] }) : null, text] }));
|
|
23
|
+
}
|