@asteby/metacore-runtime-react 52.0.0 → 53.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.
Files changed (101) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/addon-loader.d.ts +22 -1
  3. package/dist/addon-loader.d.ts.map +1 -1
  4. package/dist/addon-loader.js +23 -5
  5. package/dist/addon-page-host.d.ts +80 -0
  6. package/dist/addon-page-host.d.ts.map +1 -0
  7. package/dist/addon-page-host.js +216 -0
  8. package/dist/addon-page-loader.d.ts +40 -0
  9. package/dist/addon-page-loader.d.ts.map +1 -0
  10. package/dist/addon-page-loader.js +87 -0
  11. package/dist/dynamic-view.d.ts +20 -1
  12. package/dist/dynamic-view.d.ts.map +1 -1
  13. package/dist/dynamic-view.js +26 -3
  14. package/dist/federated-error-boundary.d.ts +46 -0
  15. package/dist/federated-error-boundary.d.ts.map +1 -0
  16. package/dist/federated-error-boundary.js +55 -0
  17. package/dist/host-api.d.ts +22 -0
  18. package/dist/host-api.d.ts.map +1 -0
  19. package/dist/host-api.js +113 -0
  20. package/dist/index.d.ts +8 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +12 -2
  23. package/dist/testing.d.ts +42 -0
  24. package/dist/testing.d.ts.map +1 -0
  25. package/dist/testing.js +53 -0
  26. package/dist/types.d.ts +13 -0
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/views/calendar-view.d.ts +23 -0
  29. package/dist/views/calendar-view.d.ts.map +1 -0
  30. package/dist/views/calendar-view.js +138 -0
  31. package/dist/views/chart-view.d.ts +14 -0
  32. package/dist/views/chart-view.d.ts.map +1 -0
  33. package/dist/views/chart-view.js +77 -0
  34. package/dist/views/data-source.d.ts +30 -0
  35. package/dist/views/data-source.d.ts.map +1 -0
  36. package/dist/views/data-source.js +103 -0
  37. package/dist/views/index.d.ts +4 -0
  38. package/dist/views/index.d.ts.map +1 -0
  39. package/dist/views/index.js +2 -0
  40. package/dist/views/map-view.d.ts +39 -0
  41. package/dist/views/map-view.d.ts.map +1 -0
  42. package/dist/views/map-view.js +143 -0
  43. package/dist/views/panels.d.ts +13 -0
  44. package/dist/views/panels.d.ts.map +1 -0
  45. package/dist/views/panels.js +119 -0
  46. package/dist/views/registry.d.ts +46 -0
  47. package/dist/views/registry.d.ts.map +1 -0
  48. package/dist/views/registry.js +139 -0
  49. package/dist/views/skeleton.d.ts +5 -0
  50. package/dist/views/skeleton.d.ts.map +1 -0
  51. package/dist/views/skeleton.js +6 -0
  52. package/dist/views/split-view.d.ts +6 -0
  53. package/dist/views/split-view.d.ts.map +1 -0
  54. package/dist/views/split-view.js +52 -0
  55. package/dist/views/timeline-view.d.ts +25 -0
  56. package/dist/views/timeline-view.d.ts.map +1 -0
  57. package/dist/views/timeline-view.js +130 -0
  58. package/dist/views/types.d.ts +87 -0
  59. package/dist/views/types.d.ts.map +1 -0
  60. package/dist/views/types.js +1 -0
  61. package/dist/widgets/charts.d.ts +9 -0
  62. package/dist/widgets/charts.d.ts.map +1 -0
  63. package/dist/widgets/charts.js +55 -0
  64. package/dist/widgets/lazy-charts.d.ts +10 -0
  65. package/dist/widgets/lazy-charts.d.ts.map +1 -0
  66. package/dist/widgets/lazy-charts.js +30 -0
  67. package/dist/widgets/renderers.d.ts +5 -5
  68. package/dist/widgets/renderers.d.ts.map +1 -1
  69. package/dist/widgets/renderers.js +3 -53
  70. package/dist/widgets/widget-renderer.d.ts.map +1 -1
  71. package/dist/widgets/widget-renderer.js +2 -1
  72. package/package.json +21 -5
  73. package/src/__tests__/addon-page-host.test.tsx +122 -0
  74. package/src/__tests__/addon-page-loader.test.tsx +201 -0
  75. package/src/__tests__/declarative-views.test.tsx +351 -0
  76. package/src/__tests__/host-api.test.ts +87 -0
  77. package/src/__tests__/index-static-graph.test.ts +83 -0
  78. package/src/addon-loader.tsx +51 -8
  79. package/src/addon-page-host.tsx +319 -0
  80. package/src/addon-page-loader.tsx +203 -0
  81. package/src/dynamic-view.tsx +61 -3
  82. package/src/federated-error-boundary.tsx +121 -0
  83. package/src/host-api.ts +143 -0
  84. package/src/index.ts +47 -4
  85. package/src/testing.tsx +108 -0
  86. package/src/types.ts +13 -0
  87. package/src/views/calendar-view.tsx +234 -0
  88. package/src/views/chart-view.tsx +122 -0
  89. package/src/views/data-source.ts +127 -0
  90. package/src/views/index.ts +37 -0
  91. package/src/views/map-view.tsx +217 -0
  92. package/src/views/panels.tsx +177 -0
  93. package/src/views/registry.tsx +202 -0
  94. package/src/views/skeleton.tsx +13 -0
  95. package/src/views/split-view.tsx +115 -0
  96. package/src/views/timeline-view.tsx +229 -0
  97. package/src/views/types.ts +105 -0
  98. package/src/widgets/charts.tsx +225 -0
  99. package/src/widgets/lazy-charts.tsx +51 -0
  100. package/src/widgets/renderers.tsx +5 -210
  101. package/src/widgets/widget-renderer.tsx +6 -4
@@ -0,0 +1,130 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // `view_type: timeline` (a model's rows over time) and `kind: timeline` detail
3
+ // panels (a record's child rows, or the items of a capability query such as
4
+ // `commerce.shipping.track`). Lazy chunk. Dates are formatted, never computed:
5
+ // ETAs and statuses are whatever the server returned.
6
+ import * as React from 'react';
7
+ import { useTranslation } from 'react-i18next';
8
+ import { Badge, Button } from '@asteby/metacore-ui/primitives';
9
+ import { buildRelationFilterParams } from '../dynamic-relation-helpers';
10
+ import { displayValue, pickItems, resolveCapabilityInput, sortByDate, toDate, } from './data-source';
11
+ import { ViewSkeleton } from './skeleton';
12
+ const PAGE = 50;
13
+ /** Pure: rows → ordered entries (newest first), grouped when `group_by` is set. */
14
+ export function toTimelineEntries(rows, view) {
15
+ return sortByDate(rows, view.date_field).map((row, i) => ({
16
+ key: String(row.id ?? `${i}`),
17
+ at: toDate(row[view.date_field]),
18
+ title: displayValue(row[view.title_field]),
19
+ status: view.status_field ? displayValue(row[view.status_field]) || undefined : undefined,
20
+ description: view.description_field ? displayValue(row[view.description_field]) || undefined : undefined,
21
+ group: view.group_by ? displayValue(row[view.group_by]) || undefined : undefined,
22
+ row,
23
+ }));
24
+ }
25
+ function useFormatter(locale, timeZone) {
26
+ return React.useMemo(() => {
27
+ try {
28
+ return new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short', timeZone });
29
+ }
30
+ catch {
31
+ return new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
32
+ }
33
+ }, [locale, timeZone]);
34
+ }
35
+ export function TimelineList({ entries, locale, timeZone, onOpen, }) {
36
+ const { t } = useTranslation();
37
+ const fmt = useFormatter(locale, timeZone);
38
+ if (entries.length === 0) {
39
+ return (_jsx("p", { className: "py-8 text-center text-sm text-muted-foreground", "data-testid": "timeline-empty", children: t('metacore.views.empty', 'Sin datos todavía.') }));
40
+ }
41
+ let lastGroup;
42
+ return (_jsx("ol", { className: "relative space-y-4 border-l border-border pl-5", "data-testid": "timeline", children: entries.map((e) => {
43
+ const header = e.group !== undefined && e.group !== lastGroup ? e.group : undefined;
44
+ lastGroup = e.group;
45
+ const body = (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, className: "absolute -left-[5px] mt-1.5 h-2.5 w-2.5 rounded-full border-2 border-background bg-primary" }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "text-sm font-medium text-foreground", children: e.title }), e.status ? _jsx(Badge, { variant: "outline", children: e.status }) : null] }), e.at ? (_jsx("time", { dateTime: e.at.toISOString(), className: "block text-xs text-muted-foreground", children: fmt.format(e.at) })) : null, e.description ? _jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: e.description }) : null] }));
46
+ return (_jsxs(React.Fragment, { children: [header ? (_jsx("li", { className: "-ml-5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: header })) : null, _jsx("li", { className: "relative", children: onOpen ? (_jsx("button", { type: "button", className: "w-full rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", onClick: () => onOpen(e.row), children: body })) : (body) })] }, e.key));
47
+ }) }));
48
+ }
49
+ /** `view_type: timeline` on a nav entry: the model's rows, newest first, paged. */
50
+ export default function TimelineViewRenderer(props) {
51
+ const { model, view, data, locale, timeZone, onOpenRecord, className } = props;
52
+ const { t } = useTranslation();
53
+ const [rows, setRows] = React.useState(null);
54
+ const [total, setTotal] = React.useState();
55
+ const [page, setPage] = React.useState(1);
56
+ const [error, setError] = React.useState(false);
57
+ React.useEffect(() => {
58
+ let cancelled = false;
59
+ setError(false);
60
+ data
61
+ .list(model, { page, per_page: PAGE, sortBy: view.date_field, order: 'desc' })
62
+ .then((res) => {
63
+ if (cancelled)
64
+ return;
65
+ setRows((prev) => (page === 1 || !prev ? res.rows : [...prev, ...res.rows]));
66
+ setTotal(res.total);
67
+ })
68
+ .catch(() => !cancelled && setError(true));
69
+ return () => {
70
+ cancelled = true;
71
+ };
72
+ }, [data, model, view.date_field, page]);
73
+ if (error && !rows) {
74
+ return (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') }));
75
+ }
76
+ if (!rows)
77
+ return _jsx(ViewSkeleton, {});
78
+ const entries = toTimelineEntries(rows, view);
79
+ const more = total !== undefined ? rows.length < total : false;
80
+ return (_jsxs("div", { className: className, children: [_jsx(TimelineList, { entries: entries, locale: locale, timeZone: timeZone, onOpen: onOpenRecord }), more ? (_jsx("div", { className: "mt-4 flex justify-center", children: _jsx(Button, { variant: "outline", size: "sm", onClick: () => setPage((p) => p + 1), children: t('metacore.views.load_more', 'Cargar más') }) })) : null] }));
81
+ }
82
+ /** `kind: timeline` panel: child rows of a relation or a capability's items. */
83
+ export function TimelinePanel({ panel, record, metadata, data, locale, timeZone }) {
84
+ const { t } = useTranslation();
85
+ const view = panel.timeline;
86
+ const source = view?.source;
87
+ const [rows, setRows] = React.useState(null);
88
+ const [error, setError] = React.useState(false);
89
+ const recordId = record.id;
90
+ const sig = JSON.stringify([source, recordId]);
91
+ React.useEffect(() => {
92
+ if (!view || !source)
93
+ return;
94
+ let cancelled = false;
95
+ setRows(null);
96
+ setError(false);
97
+ const run = async () => {
98
+ if (source.capability) {
99
+ const out = await data.capability(source.capability, resolveCapabilityInput(source.input, record));
100
+ return pickItems(out, source.items);
101
+ }
102
+ if (source.relation) {
103
+ const rel = metadata?.relations?.find((r) => r.name === source.relation);
104
+ if (!rel || recordId === undefined || recordId === null)
105
+ return [];
106
+ const res = await data.list(rel.through, {
107
+ ...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope),
108
+ per_page: PAGE,
109
+ sortBy: view.date_field,
110
+ order: 'desc',
111
+ });
112
+ return res.rows;
113
+ }
114
+ return [];
115
+ };
116
+ run().then((r) => !cancelled && setRows(r), () => !cancelled && setError(true));
117
+ return () => {
118
+ cancelled = true;
119
+ };
120
+ // eslint-disable-next-line react-hooks/exhaustive-deps
121
+ }, [data, sig, metadata]);
122
+ if (!view)
123
+ return null;
124
+ if (error) {
125
+ return (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') }));
126
+ }
127
+ if (!rows)
128
+ return _jsx(ViewSkeleton, { height: 200 });
129
+ return _jsx(TimelineList, { entries: toTimelineEntries(rows, view), locale: locale, timeZone: timeZone });
130
+ }
@@ -0,0 +1,87 @@
1
+ import type { ComponentType } from 'react';
2
+ import type { CalendarView, ChartView, DetailPanel, MapView, SplitView, TimelineView, WidgetQuery } from '@asteby/metacore-sdk';
3
+ import type { TableMetadata } from '../types';
4
+ import type { WidgetData } from '../dashboard-types';
5
+ /** `view_type` values rendered by a declarative renderer (table/kanban excluded). */
6
+ export type DeclarativeViewType = 'map' | 'timeline' | 'calendar' | 'chart' | 'split';
7
+ /** Block of `NavView` each type reads. */
8
+ export interface DeclarativeViewConfig {
9
+ map: MapView;
10
+ timeline: TimelineView;
11
+ calendar: CalendarView;
12
+ chart: ChartView;
13
+ split: SplitView;
14
+ }
15
+ /** A page of rows. */
16
+ export interface ViewRows<Row = Record<string, unknown>> {
17
+ rows: Row[];
18
+ total?: number;
19
+ }
20
+ /** List params in the kernel's list syntax (`f_<col>`, `sortBy`, `order`…). */
21
+ export type ViewListParams = Record<string, string | number | boolean | undefined>;
22
+ /**
23
+ * Where declarative renderers read data. The host provides it (default:
24
+ * {@link createApiViewDataSource} over the runtime-react ApiClient). Every
25
+ * call runs with the viewer's permissions server-side; renderers never
26
+ * compute business values (totals, ETAs) — they display what comes back.
27
+ */
28
+ export interface ViewDataSource {
29
+ /** Rows of a model (`GET /data/<model>`). */
30
+ list(model: string, params?: ViewListParams): Promise<ViewRows>;
31
+ /** One record (`GET /data/<model>/<id>`). */
32
+ record(model: string, id: string): Promise<Record<string, unknown> | null>;
33
+ /**
34
+ * Aggregate for a chart view or panel. The host must only answer queries
35
+ * the installed manifests declare (same rule as dashboard widgets): the
36
+ * request names the model and the declared query, never free SQL.
37
+ */
38
+ chart(req: ChartRequest): Promise<WidgetData>;
39
+ /** Capability query (timeline panels with `source.capability`). */
40
+ capability(key: string, input: Record<string, unknown>): Promise<unknown>;
41
+ }
42
+ export interface ChartRequest {
43
+ /** Model whose nav entry / detail declares the chart. */
44
+ model: string;
45
+ query: WidgetQuery;
46
+ /** Detail panels: the relation the query is scoped to, and the record. */
47
+ relation?: string;
48
+ recordId?: string;
49
+ /** Detail panels: the panel key; nav views: undefined. */
50
+ panelKey?: string;
51
+ }
52
+ /** Props every declarative view renderer receives. */
53
+ export interface ViewRendererProps<T extends DeclarativeViewType = DeclarativeViewType> {
54
+ model: string;
55
+ view: DeclarativeViewConfig[T];
56
+ /** Served table metadata (columns, relations, options…), when loaded. */
57
+ metadata?: TableMetadata | null;
58
+ data: ViewDataSource;
59
+ /** Open a record (host route to its detail page or drawer). */
60
+ onOpenRecord?: (row: Record<string, unknown>) => void;
61
+ locale?: string;
62
+ currency?: string;
63
+ timeZone?: string;
64
+ className?: string;
65
+ }
66
+ /** Props every detail panel renderer receives. */
67
+ export interface PanelRendererProps {
68
+ model: string;
69
+ panel: DetailPanel;
70
+ record: Record<string, unknown>;
71
+ metadata?: TableMetadata | null;
72
+ data: ViewDataSource;
73
+ locale?: string;
74
+ currency?: string;
75
+ timeZone?: string;
76
+ onOpenRecord?: (model: string, row: Record<string, unknown>) => void;
77
+ }
78
+ export type ViewRendererComponent = ComponentType<ViewRendererProps<any>>;
79
+ export type PanelRendererComponent = ComponentType<PanelRendererProps>;
80
+ /** Lazy module of a renderer (default export = the component). */
81
+ export type ViewRendererLoader = () => Promise<{
82
+ default: ViewRendererComponent;
83
+ }>;
84
+ export type PanelRendererLoader = () => Promise<{
85
+ default: PanelRendererComponent;
86
+ }>;
87
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/views/types.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAC1C,OAAO,KAAK,EACR,YAAY,EACZ,SAAS,EACT,WAAW,EACX,OAAO,EACP,SAAS,EACT,YAAY,EACZ,WAAW,EACd,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEpD,qFAAqF;AACrF,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,CAAA;AAErF,0CAA0C;AAC1C,MAAM,WAAW,qBAAqB;IAClC,GAAG,EAAE,OAAO,CAAA;IACZ,QAAQ,EAAE,YAAY,CAAA;IACtB,QAAQ,EAAE,YAAY,CAAA;IACtB,KAAK,EAAE,SAAS,CAAA;IAChB,KAAK,EAAE,SAAS,CAAA;CACnB;AAED,sBAAsB;AACtB,MAAM,WAAW,QAAQ,CAAC,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACnD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derProps };
4
+ export declare function BarWidget(p: WidgetRenderProps): React.JSX.Element;
5
+ export declare function LineWidget(p: WidgetRenderProps): React.JSX.Element;
6
+ export declare function AreaWidget(p: WidgetRenderProps): React.JSX.Element;
7
+ export declare function PieWidget(p: WidgetRenderProps): React.JSX.Element;
8
+ export declare function DonutWidget(p: WidgetRenderProps): React.JSX.Element;
9
+ //# sourceMappingURL=charts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"charts.d.ts","sourceRoot":"","sources":["../../src/widgets/charts.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AA4B9B,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAEvE,YAAY,EAAE,iBAAiB,EAAE,CAAA;AAoCjC,wBAAgB,SAAS,CAAC,CAAC,EAAE,iBAAiB,qBAsC7C;AAgDD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBAE9C;AACD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBAE9C;AAuDD,wBAAgB,SAAS,CAAC,CAAC,EAAE,iBAAiB,qBAE7C;AACD,wBAAgB,WAAW,CAAC,CAAC,EAAE,iBAAiB,qBAE/C"}
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, Line, LineChart, Pie, PieChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
3
+ import { cn } from '@asteby/metacore-ui/lib';
4
+ import { WidgetCard, WidgetEmpty } from './widget-card';
5
+ import { accentClasses, paletteColor, formatWidgetValue, formatAxisTick, CHART_GRID, CHART_MUTED, } from './widget-format';
6
+ import { fmtCtx, hasSeries } from './renderers';
7
+ // Fixed-height chart body. In the masonry (CSS columns) layout cards take their
8
+ // natural height, so charts need a definite height for ResponsiveContainer to
9
+ // resolve. This height + the card chrome gives every chart card a consistent,
10
+ // taller footprint that balances cleanly against compact stat cards.
11
+ const CHART_H = 'h-[190px]';
12
+ function ChartArea({ children }) {
13
+ return (_jsx("div", { className: cn(CHART_H, 'w-full'), children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: children }) }));
14
+ }
15
+ // Compact recharts tooltip styled with theme tokens.
16
+ function ChartTooltip({ ctx }) {
17
+ return (_jsx(Tooltip, { cursor: { fill: 'var(--muted, rgba(148,163,184,0.12))', opacity: 0.4 }, contentStyle: {
18
+ background: 'var(--popover, #fff)',
19
+ border: '1px solid var(--border, #e2e8f0)',
20
+ borderRadius: 8,
21
+ fontSize: 12,
22
+ color: 'var(--popover-foreground, #0f172a)',
23
+ boxShadow: '0 4px 16px rgba(0,0,0,0.08)',
24
+ }, labelStyle: { color: 'var(--muted-foreground, #64748b)', marginBottom: 2 }, formatter: (v) => formatWidgetValue(Number(v), ctx) }));
25
+ }
26
+ // --- bar ------------------------------------------------------------------
27
+ export function BarWidget(p) {
28
+ const ctx = fmtCtx(p.spec, p.locale, p.currency);
29
+ const a = accentClasses(p.spec.accent);
30
+ return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsx(ChartArea, { children: _jsxs(BarChart, { data: p.data.series, margin: { top: 4, right: 4, left: -16, bottom: 0 }, children: [_jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Bar, { dataKey: "value", fill: a.chartVar, radius: [4, 4, 0, 0], maxBarSize: 48 })] }) })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
31
+ }
32
+ // --- line / area (shared) -------------------------------------------------
33
+ function TimeSeriesWidget(p) {
34
+ const ctx = fmtCtx(p.spec, p.locale, p.currency);
35
+ const a = accentClasses(p.spec.accent);
36
+ const gradId = `wg-grad-${p.spec.key}`;
37
+ return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsx(ChartArea, { children: p.variant === 'area' ? (_jsxs(AreaChart, { data: p.data.series, margin: { top: 4, right: 6, left: -16, bottom: 0 }, children: [_jsx("defs", { children: _jsxs("linearGradient", { id: gradId, x1: "0", y1: "0", x2: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: a.chartVar, stopOpacity: 0.35 }), _jsx("stop", { offset: "100%", stopColor: a.chartVar, stopOpacity: 0.02 })] }) }), _jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Area, { type: "monotone", dataKey: "value", stroke: a.chartVar, strokeWidth: 2, fill: `url(#${gradId})` })] })) : (_jsxs(LineChart, { data: p.data.series, margin: { top: 4, right: 6, left: -16, bottom: 0 }, children: [_jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Line, { type: "monotone", dataKey: "value", stroke: a.chartVar, strokeWidth: 2, dot: false, activeDot: { r: 4 } })] })) })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
38
+ }
39
+ export function LineWidget(p) {
40
+ return _jsx(TimeSeriesWidget, { ...p, variant: "line" });
41
+ }
42
+ export function AreaWidget(p) {
43
+ return _jsx(TimeSeriesWidget, { ...p, variant: "area" });
44
+ }
45
+ // --- pie / donut (shared) -------------------------------------------------
46
+ function CircularWidget(p) {
47
+ const ctx = fmtCtx(p.spec, p.locale, p.currency);
48
+ return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsxs("div", { className: cn(CHART_H, 'flex items-center gap-3'), children: [_jsx("div", { className: "h-full min-h-0 w-[46%] shrink-0", children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: _jsxs(PieChart, { children: [_jsx(ChartTooltip, { ctx: ctx }), _jsx(Pie, { data: p.data.series, dataKey: "value", nameKey: "label", innerRadius: p.variant === 'donut' ? '55%' : 0, outerRadius: "92%", paddingAngle: p.variant === 'donut' ? 2 : 0, stroke: "var(--background, #fff)", strokeWidth: 2, children: p.data.series.map((_, i) => (_jsx(Cell, { fill: paletteColor(i) }, i))) })] }) }) }), _jsx("ul", { className: "flex min-w-0 flex-1 flex-col gap-1.5", children: p.data.series.slice(0, 6).map((pt, i) => (_jsxs("li", { className: "flex items-center gap-2 text-xs", children: [_jsx("span", { className: "size-2.5 shrink-0 rounded-sm", style: { background: paletteColor(i) } }), _jsx("span", { className: "truncate text-muted-foreground", children: pt.label }), _jsx("span", { className: "ml-auto shrink-0 font-medium tabular-nums text-foreground", children: formatWidgetValue(pt.value, ctx) })] }, pt.key))) })] })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
49
+ }
50
+ export function PieWidget(p) {
51
+ return _jsx(CircularWidget, { ...p, variant: "pie" });
52
+ }
53
+ export function DonutWidget(p) {
54
+ return _jsx(CircularWidget, { ...p, variant: "donut" });
55
+ }
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import type { WidgetRenderProps } from './renderers';
3
+ /** Warm the charts chunk (e.g. on hover of a dashboard link). Idempotent. */
4
+ export declare function preloadWidgetCharts(): Promise<unknown>;
5
+ export declare const BarWidget: (p: WidgetRenderProps) => React.JSX.Element;
6
+ export declare const LineWidget: (p: WidgetRenderProps) => React.JSX.Element;
7
+ export declare const AreaWidget: (p: WidgetRenderProps) => React.JSX.Element;
8
+ export declare const PieWidget: (p: WidgetRenderProps) => React.JSX.Element;
9
+ export declare const DonutWidget: (p: WidgetRenderProps) => React.JSX.Element;
10
+ //# sourceMappingURL=lazy-charts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy-charts.d.ts","sourceRoot":"","sources":["../../src/widgets/lazy-charts.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAIpD,6EAA6E;AAC7E,wBAAgB,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC,CAEtD;AAgCD,eAAO,MAAM,SAAS,MATiB,iBAAiB,sBASV,CAAA;AAC9C,eAAO,MAAM,UAAU,MAVgB,iBAAiB,sBAUR,CAAA;AAChD,eAAO,MAAM,UAAU,MAXgB,iBAAiB,sBAWR,CAAA;AAChD,eAAO,MAAM,SAAS,MAZiB,iBAAiB,sBAYV,CAAA;AAC9C,eAAO,MAAM,WAAW,MAbe,iBAAiB,sBAaN,CAAA"}
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ // Lazy facades for the recharts-backed widgets. The package index and
3
+ // WidgetRenderer import these instead of ./charts, so recharts becomes its own
4
+ // async chunk: it downloads only when a dashboard actually renders a
5
+ // bar/line/area/pie/donut widget. Public names stay the same as before.
6
+ import * as React from 'react';
7
+ import { WidgetCard } from './widget-card';
8
+ const loadCharts = () => import('./charts');
9
+ /** Warm the charts chunk (e.g. on hover of a dashboard link). Idempotent. */
10
+ export function preloadWidgetCharts() {
11
+ return loadCharts();
12
+ }
13
+ const LazyBar = React.lazy(() => loadCharts().then((m) => ({ default: m.BarWidget })));
14
+ const LazyLine = React.lazy(() => loadCharts().then((m) => ({ default: m.LineWidget })));
15
+ const LazyArea = React.lazy(() => loadCharts().then((m) => ({ default: m.AreaWidget })));
16
+ const LazyPie = React.lazy(() => loadCharts().then((m) => ({ default: m.PieWidget })));
17
+ const LazyDonut = React.lazy(() => loadCharts().then((m) => ({ default: m.DonutWidget })));
18
+ function ChartFallback(p) {
19
+ return (_jsx(WidgetCard, { "data-testid": `widget-skeleton-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: _jsx("div", { className: "h-[190px] w-full animate-pulse rounded-md bg-muted" }) }));
20
+ }
21
+ function withSuspense(Lazy) {
22
+ return function LazyChartWidget(p) {
23
+ return (_jsx(React.Suspense, { fallback: _jsx(ChartFallback, { ...p }), children: _jsx(Lazy, { ...p }) }));
24
+ };
25
+ }
26
+ export const BarWidget = withSuspense(LazyBar);
27
+ export const LineWidget = withSuspense(LazyLine);
28
+ export const AreaWidget = withSuspense(LazyArea);
29
+ export const PieWidget = withSuspense(LazyPie);
30
+ export const DonutWidget = withSuspense(LazyDonut);
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import type { DashboardWidgetSpec, WidgetData } from '../dashboard-types';
3
+ import { type WidgetFormatCtx } from './widget-format';
3
4
  export interface WidgetRenderProps {
4
5
  spec: DashboardWidgetSpec;
5
6
  data?: WidgetData;
@@ -8,12 +9,11 @@ export interface WidgetRenderProps {
8
9
  /** i18n: per-widget empty fallback (already translated). */
9
10
  emptyText: string;
10
11
  }
12
+ export declare const fmtCtx: (spec: DashboardWidgetSpec, locale?: string, currency?: string) => WidgetFormatCtx;
13
+ export declare const hasSeries: (d?: WidgetData) => d is WidgetData & {
14
+ series: NonNullable<WidgetData["series"]>;
15
+ };
11
16
  export declare function StatWidget(p: WidgetRenderProps): React.JSX.Element;
12
- export declare function BarWidget(p: WidgetRenderProps): React.JSX.Element;
13
- export declare function LineWidget(p: WidgetRenderProps): React.JSX.Element;
14
- export declare function AreaWidget(p: WidgetRenderProps): React.JSX.Element;
15
- export declare function PieWidget(p: WidgetRenderProps): React.JSX.Element;
16
- export declare function DonutWidget(p: WidgetRenderProps): React.JSX.Element;
17
17
  export declare function ListWidget(p: WidgetRenderProps): React.JSX.Element;
18
18
  export declare function ProgressWidget(p: WidgetRenderProps): React.JSX.Element;
19
19
  //# sourceMappingURL=renderers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../src/widgets/renderers.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAkB9B,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAazE,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,mBAAmB,CAAA;IACzB,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAA;CACpB;AA8CD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBA+B9C;AAGD,wBAAgB,SAAS,CAAC,CAAC,EAAE,iBAAiB,qBAsC7C;AAgDD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBAE9C;AACD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBAE9C;AAuDD,wBAAgB,SAAS,CAAC,CAAC,EAAE,iBAAiB,qBAE7C;AACD,wBAAgB,WAAW,CAAC,CAAC,EAAE,iBAAiB,qBAE/C;AAGD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBAqC9C;AAKD,wBAAgB,cAAc,CAAC,CAAC,EAAE,iBAAiB,qBAkClD"}
1
+ {"version":3,"file":"renderers.d.ts","sourceRoot":"","sources":["../../src/widgets/renderers.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAEzE,OAAO,EAQH,KAAK,eAAe,EACvB,MAAM,iBAAiB,CAAA;AAExB,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,mBAAmB,CAAA;IACzB,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAA;CACpB;AAED,eAAO,MAAM,MAAM,GACf,MAAM,mBAAmB,EACzB,SAAS,MAAM,EACf,WAAW,MAAM,KAClB,eAA8D,CAAA;AAEjE,eAAO,MAAM,SAAS,GAAI,IAAI,UAAU,KAAG,CAAC,IAAI,UAAU,GAAG;IAAE,MAAM,EAAE,WAAW,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAA;CACnD,CAAA;AAGrD,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBA+B9C;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,iBAAiB,qBAqC9C;AAKD,wBAAgB,cAAc,CAAC,CAAC,EAAE,iBAAiB,qBAkClD"}
@@ -1,29 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, Line, LineChart, Pie, PieChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
3
2
  import { cn } from '@asteby/metacore-ui/lib';
4
3
  import { WidgetCard, DeltaChip, WidgetEmpty } from './widget-card';
5
- import { accentClasses, paletteColor, formatWidgetValue, formatAxisTick, formatDelta, CHART_GRID, CHART_MUTED, } from './widget-format';
6
- const fmtCtx = (spec, locale, currency) => ({ format: spec.format, locale, currency });
7
- const hasSeries = (d) => Array.isArray(d?.series) && d.series.length > 0;
8
- // Fixed-height chart body. In the masonry (CSS columns) layout cards take their
9
- // natural height, so charts need a definite height for ResponsiveContainer to
10
- // resolve. This height + the card chrome gives every chart card a consistent,
11
- // taller footprint that balances cleanly against compact stat cards.
12
- const CHART_H = 'h-[190px]';
13
- function ChartArea({ children }) {
14
- return (_jsx("div", { className: cn(CHART_H, 'w-full'), children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: children }) }));
15
- }
16
- // Compact recharts tooltip styled with theme tokens.
17
- function ChartTooltip({ ctx }) {
18
- return (_jsx(Tooltip, { cursor: { fill: 'var(--muted, rgba(148,163,184,0.12))', opacity: 0.4 }, contentStyle: {
19
- background: 'var(--popover, #fff)',
20
- border: '1px solid var(--border, #e2e8f0)',
21
- borderRadius: 8,
22
- fontSize: 12,
23
- color: 'var(--popover-foreground, #0f172a)',
24
- boxShadow: '0 4px 16px rgba(0,0,0,0.08)',
25
- }, labelStyle: { color: 'var(--muted-foreground, #64748b)', marginBottom: 2 }, formatter: (v) => formatWidgetValue(Number(v), ctx) }));
26
- }
4
+ import { accentClasses, formatWidgetValue, formatDelta, } from './widget-format';
5
+ export const fmtCtx = (spec, locale, currency) => ({ format: spec.format, locale, currency });
6
+ export const hasSeries = (d) => Array.isArray(d?.series) && d.series.length > 0;
27
7
  // --- stat -----------------------------------------------------------------
28
8
  export function StatWidget(p) {
29
9
  const ctx = fmtCtx(p.spec, p.locale, p.currency);
@@ -32,36 +12,6 @@ export function StatWidget(p) {
32
12
  const hasValue = typeof value === 'number' && !Number.isNaN(value);
33
13
  return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, headerExtra: typeof delta === 'number' ? (_jsx(DeltaChip, { delta: delta, text: formatDelta(delta, p.locale) })) : undefined, children: hasValue ? (_jsx("div", { className: "flex min-h-[2.5rem] items-end", children: _jsx("div", { className: "text-[2rem] font-semibold leading-none tabular-nums tracking-tight text-foreground", children: formatWidgetValue(value, ctx) }) })) : (_jsx("div", { className: "flex min-h-[2.5rem] items-center text-sm text-muted-foreground", children: p.emptyText })) }));
34
14
  }
35
- // --- bar ------------------------------------------------------------------
36
- export function BarWidget(p) {
37
- const ctx = fmtCtx(p.spec, p.locale, p.currency);
38
- const a = accentClasses(p.spec.accent);
39
- return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsx(ChartArea, { children: _jsxs(BarChart, { data: p.data.series, margin: { top: 4, right: 4, left: -16, bottom: 0 }, children: [_jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Bar, { dataKey: "value", fill: a.chartVar, radius: [4, 4, 0, 0], maxBarSize: 48 })] }) })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
40
- }
41
- // --- line / area (shared) -------------------------------------------------
42
- function TimeSeriesWidget(p) {
43
- const ctx = fmtCtx(p.spec, p.locale, p.currency);
44
- const a = accentClasses(p.spec.accent);
45
- const gradId = `wg-grad-${p.spec.key}`;
46
- return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsx(ChartArea, { children: p.variant === 'area' ? (_jsxs(AreaChart, { data: p.data.series, margin: { top: 4, right: 6, left: -16, bottom: 0 }, children: [_jsx("defs", { children: _jsxs("linearGradient", { id: gradId, x1: "0", y1: "0", x2: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: a.chartVar, stopOpacity: 0.35 }), _jsx("stop", { offset: "100%", stopColor: a.chartVar, stopOpacity: 0.02 })] }) }), _jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Area, { type: "monotone", dataKey: "value", stroke: a.chartVar, strokeWidth: 2, fill: `url(#${gradId})` })] })) : (_jsxs(LineChart, { data: p.data.series, margin: { top: 4, right: 6, left: -16, bottom: 0 }, children: [_jsx(CartesianGrid, { vertical: false, stroke: CHART_GRID, strokeDasharray: "3 3" }), _jsx(XAxis, { dataKey: "label", tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, interval: "preserveStartEnd" }), _jsx(YAxis, { tick: { fontSize: 10, fill: CHART_MUTED }, tickLine: false, axisLine: false, width: 44, tickFormatter: (v) => formatAxisTick(v, ctx) }), _jsx(ChartTooltip, { ctx: ctx }), _jsx(Line, { type: "monotone", dataKey: "value", stroke: a.chartVar, strokeWidth: 2, dot: false, activeDot: { r: 4 } })] })) })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
47
- }
48
- export function LineWidget(p) {
49
- return _jsx(TimeSeriesWidget, { ...p, variant: "line" });
50
- }
51
- export function AreaWidget(p) {
52
- return _jsx(TimeSeriesWidget, { ...p, variant: "area" });
53
- }
54
- // --- pie / donut (shared) -------------------------------------------------
55
- function CircularWidget(p) {
56
- const ctx = fmtCtx(p.spec, p.locale, p.currency);
57
- return (_jsx(WidgetCard, { "data-testid": `widget-${p.spec.key}`, title: p.spec.title, subtitle: p.spec.subtitle, icon: p.spec.icon, accent: p.spec.accent, children: hasSeries(p.data) ? (_jsxs("div", { className: cn(CHART_H, 'flex items-center gap-3'), children: [_jsx("div", { className: "h-full min-h-0 w-[46%] shrink-0", children: _jsx(ResponsiveContainer, { width: "100%", height: "100%", children: _jsxs(PieChart, { children: [_jsx(ChartTooltip, { ctx: ctx }), _jsx(Pie, { data: p.data.series, dataKey: "value", nameKey: "label", innerRadius: p.variant === 'donut' ? '55%' : 0, outerRadius: "92%", paddingAngle: p.variant === 'donut' ? 2 : 0, stroke: "var(--background, #fff)", strokeWidth: 2, children: p.data.series.map((_, i) => (_jsx(Cell, { fill: paletteColor(i) }, i))) })] }) }) }), _jsx("ul", { className: "flex min-w-0 flex-1 flex-col gap-1.5", children: p.data.series.slice(0, 6).map((pt, i) => (_jsxs("li", { className: "flex items-center gap-2 text-xs", children: [_jsx("span", { className: "size-2.5 shrink-0 rounded-sm", style: { background: paletteColor(i) } }), _jsx("span", { className: "truncate text-muted-foreground", children: pt.label }), _jsx("span", { className: "ml-auto shrink-0 font-medium tabular-nums text-foreground", children: formatWidgetValue(pt.value, ctx) })] }, pt.key))) })] })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
58
- }
59
- export function PieWidget(p) {
60
- return _jsx(CircularWidget, { ...p, variant: "pie" });
61
- }
62
- export function DonutWidget(p) {
63
- return _jsx(CircularWidget, { ...p, variant: "donut" });
64
- }
65
15
  // --- list (top-N with proportion bars) ------------------------------------
66
16
  export function ListWidget(p) {
67
17
  const ctx = fmtCtx(p.spec, p.locale, p.currency);
@@ -1 +1 @@
1
- {"version":3,"file":"widget-renderer.d.ts","sourceRoot":"","sources":["../../src/widgets/widget-renderer.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAA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oB,CAAA;AAgBrF,+DAA+D;AAC/D,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAKhD,CAAA;AAED;6EAC6E;AAC7E,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAKjD,CAAA;AAMD;kFACkF;AAClF,wBAAgB,WAAW,CAAC,IAAI,EAAE,mBAAmB,GAAG,UAAU,CAGjE;AAED;4EAC4E;AAC5E,wBAAgB,SAAS,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAG3D;AAED;0EAC0E;AAC1E,wBAAgB,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAE/D;AAiDD,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,mBAAmB,CAAA;IACzB,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAA;IACjB,gDAAgD;IAChD,SAAS,EAAE,MAAM,CAAA;CACpB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAC3B,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,SAAS,EACT,SAAS,GACZ,EAAE,mBAAmB,qBAkDrB;AAED,8DAA8D;AAC9D,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,mBAAmB,CAAA;CAAE,qBAqBrE"}
@@ -5,7 +5,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import * as React from 'react';
6
6
  import { Slot } from '../slot';
7
7
  import { WidgetCard, WidgetError } from './widget-card';
8
- import { StatWidget, BarWidget, LineWidget, AreaWidget, PieWidget, DonutWidget, ListWidget, ProgressWidget, } from './renderers';
8
+ import { StatWidget, ListWidget, ProgressWidget, } from './renderers';
9
+ import { BarWidget, LineWidget, AreaWidget, PieWidget, DonutWidget, } from './lazy-charts';
9
10
  /** Maps a widget size to its column span in the 4-col grid. */
10
11
  export const SIZE_SPAN = {
11
12
  sm: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/metacore-runtime-react",
3
- "version": "52.0.0",
3
+ "version": "53.0.0",
4
4
  "description": "React runtime for metacore hosts — renders addon contributions dynamically",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,6 +14,18 @@
14
14
  ".": {
15
15
  "types": "./dist/index.d.ts",
16
16
  "import": "./dist/index.js"
17
+ },
18
+ "./charts": {
19
+ "types": "./dist/widgets/charts.d.ts",
20
+ "import": "./dist/widgets/charts.js"
21
+ },
22
+ "./testing": {
23
+ "types": "./dist/testing.d.ts",
24
+ "import": "./dist/testing.js"
25
+ },
26
+ "./views/map": {
27
+ "types": "./dist/views/map-view.d.ts",
28
+ "import": "./dist/views/map-view.js"
17
29
  }
18
30
  },
19
31
  "dependencies": {
@@ -21,11 +33,11 @@
21
33
  "@dnd-kit/sortable": "^10.0.0",
22
34
  "@dnd-kit/utilities": "^3.2.2",
23
35
  "@tanstack/react-virtual": "^3.14.13",
24
- "recharts": "^2.15.0",
36
+ "recharts": "^3.8.1",
25
37
  "zod": "^4.3.0"
26
38
  },
27
39
  "peerDependencies": {
28
- "@asteby/metacore-sdk": "^3.14.0",
40
+ "@asteby/metacore-sdk": "^3.15.0",
29
41
  "@asteby/metacore-ui": "^2.28.0",
30
42
  "@tanstack/react-query": ">=5",
31
43
  "@tanstack/react-router": ">=1.100",
@@ -39,7 +51,8 @@
39
51
  "react-i18next": ">=13",
40
52
  "sonner": ">=1.7",
41
53
  "zustand": ">=5",
42
- "@module-federation/runtime": ">=2.5"
54
+ "@module-federation/runtime": ">=2.5",
55
+ "@testing-library/react": ">=14"
43
56
  },
44
57
  "peerDependenciesMeta": {
45
58
  "@tanstack/react-router": {
@@ -50,10 +63,13 @@
50
63
  },
51
64
  "@module-federation/runtime": {
52
65
  "optional": true
66
+ },
67
+ "@testing-library/react": {
68
+ "optional": true
53
69
  }
54
70
  },
55
71
  "devDependencies": {
56
- "@asteby/metacore-sdk": "3.14.0",
72
+ "@asteby/metacore-sdk": "3.15.0",
57
73
  "@asteby/metacore-ui": "2.28.0",
58
74
  "@tanstack/react-query": "^5.95.0",
59
75
  "@tanstack/react-router": "^1.168.0",