@asteby/metacore-runtime-react 51.0.0 → 52.1.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 (62) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/activity-diff.d.ts +5 -0
  3. package/dist/activity-diff.d.ts.map +1 -1
  4. package/dist/activity-timeline.d.ts.map +1 -1
  5. package/dist/activity-timeline.js +7 -2
  6. package/dist/audit-info.d.ts.map +1 -1
  7. package/dist/audit-info.js +14 -1
  8. package/dist/barcode-scanner.js +4 -4
  9. package/dist/dialogs/dynamic-record.d.ts +3 -1
  10. package/dist/dialogs/dynamic-record.d.ts.map +1 -1
  11. package/dist/dialogs/dynamic-record.js +11 -1
  12. package/dist/dynamic-columns.d.ts.map +1 -1
  13. package/dist/dynamic-columns.js +11 -0
  14. package/dist/dynamic-date-field.js +1 -1
  15. package/dist/dynamic-form.js +2 -2
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -1
  19. package/dist/org-runtime-context.d.ts +27 -0
  20. package/dist/org-runtime-context.d.ts.map +1 -1
  21. package/dist/org-runtime-context.js +6 -0
  22. package/dist/org-runtime-provider.d.ts +13 -2
  23. package/dist/org-runtime-provider.d.ts.map +1 -1
  24. package/dist/org-runtime-provider.js +3 -3
  25. package/dist/provenance.d.ts +216 -0
  26. package/dist/provenance.d.ts.map +1 -0
  27. package/dist/provenance.js +386 -0
  28. package/dist/record-history.d.ts.map +1 -1
  29. package/dist/record-history.js +3 -1
  30. package/dist/sidebar-layout-manager.js +2 -2
  31. package/dist/widgets/charts.d.ts +9 -0
  32. package/dist/widgets/charts.d.ts.map +1 -0
  33. package/dist/widgets/charts.js +55 -0
  34. package/dist/widgets/lazy-charts.d.ts +10 -0
  35. package/dist/widgets/lazy-charts.d.ts.map +1 -0
  36. package/dist/widgets/lazy-charts.js +30 -0
  37. package/dist/widgets/renderers.d.ts +5 -5
  38. package/dist/widgets/renderers.d.ts.map +1 -1
  39. package/dist/widgets/renderers.js +3 -53
  40. package/dist/widgets/widget-renderer.d.ts.map +1 -1
  41. package/dist/widgets/widget-renderer.js +2 -1
  42. package/package.json +8 -4
  43. package/src/__tests__/index-static-graph.test.ts +65 -0
  44. package/src/__tests__/provenance.test.tsx +209 -0
  45. package/src/activity-diff.tsx +5 -0
  46. package/src/activity-timeline.tsx +13 -1
  47. package/src/audit-info.tsx +17 -1
  48. package/src/barcode-scanner.tsx +4 -4
  49. package/src/dialogs/dynamic-record.tsx +18 -0
  50. package/src/dynamic-columns.tsx +14 -0
  51. package/src/dynamic-date-field.tsx +1 -1
  52. package/src/dynamic-form.tsx +2 -2
  53. package/src/index.ts +10 -4
  54. package/src/org-runtime-context.ts +36 -0
  55. package/src/org-runtime-provider.tsx +22 -1
  56. package/src/provenance.tsx +585 -0
  57. package/src/record-history.tsx +14 -3
  58. package/src/sidebar-layout-manager.tsx +2 -2
  59. package/src/widgets/charts.tsx +225 -0
  60. package/src/widgets/lazy-charts.tsx +51 -0
  61. package/src/widgets/renderers.tsx +5 -210
  62. package/src/widgets/widget-renderer.tsx +6 -4
@@ -0,0 +1,225 @@
1
+ // recharts-backed dashboard widgets (bar, line, area, pie, donut). Kept out of
2
+ // the package index on purpose: recharts is ~100 KB gzip and must not ride in
3
+ // the host's first paint. `WidgetRenderer` loads this module with React.lazy;
4
+ // hosts that want the components directly import
5
+ // `@asteby/metacore-runtime-react/charts`. Colors come from theme CSS vars
6
+ // (dark-mode safe), curves are smooth, axes/legends compact, tooltips on.
7
+
8
+ import * as React from 'react'
9
+ import {
10
+ Area,
11
+ AreaChart,
12
+ Bar,
13
+ BarChart,
14
+ CartesianGrid,
15
+ Cell,
16
+ Line,
17
+ LineChart,
18
+ Pie,
19
+ PieChart,
20
+ ResponsiveContainer,
21
+ Tooltip,
22
+ XAxis,
23
+ YAxis,
24
+ } from 'recharts'
25
+ import { cn } from '@asteby/metacore-ui/lib'
26
+ import { WidgetCard, WidgetEmpty } from './widget-card'
27
+ import {
28
+ accentClasses,
29
+ paletteColor,
30
+ formatWidgetValue,
31
+ formatAxisTick,
32
+ CHART_GRID,
33
+ CHART_MUTED,
34
+ type WidgetFormatCtx,
35
+ } from './widget-format'
36
+ import { fmtCtx, hasSeries, type WidgetRenderProps } from './renderers'
37
+
38
+ export type { WidgetRenderProps }
39
+
40
+ // Fixed-height chart body. In the masonry (CSS columns) layout cards take their
41
+ // natural height, so charts need a definite height for ResponsiveContainer to
42
+ // resolve. This height + the card chrome gives every chart card a consistent,
43
+ // taller footprint that balances cleanly against compact stat cards.
44
+ const CHART_H = 'h-[190px]'
45
+ function ChartArea({ children }: { children: React.ReactElement }) {
46
+ return (
47
+ <div className={cn(CHART_H, 'w-full')}>
48
+ <ResponsiveContainer width="100%" height="100%">
49
+ {children}
50
+ </ResponsiveContainer>
51
+ </div>
52
+ )
53
+ }
54
+
55
+ // Compact recharts tooltip styled with theme tokens.
56
+ function ChartTooltip({ ctx }: { ctx: WidgetFormatCtx }) {
57
+ return (
58
+ <Tooltip
59
+ cursor={{ fill: 'var(--muted, rgba(148,163,184,0.12))', opacity: 0.4 }}
60
+ contentStyle={{
61
+ background: 'var(--popover, #fff)',
62
+ border: '1px solid var(--border, #e2e8f0)',
63
+ borderRadius: 8,
64
+ fontSize: 12,
65
+ color: 'var(--popover-foreground, #0f172a)',
66
+ boxShadow: '0 4px 16px rgba(0,0,0,0.08)',
67
+ }}
68
+ labelStyle={{ color: 'var(--muted-foreground, #64748b)', marginBottom: 2 }}
69
+ formatter={(v) => formatWidgetValue(Number(v), ctx)}
70
+ />
71
+ )
72
+ }
73
+ // --- bar ------------------------------------------------------------------
74
+ export function BarWidget(p: WidgetRenderProps) {
75
+ const ctx = fmtCtx(p.spec, p.locale, p.currency)
76
+ const a = accentClasses(p.spec.accent)
77
+ return (
78
+ <WidgetCard
79
+ data-testid={`widget-${p.spec.key}`}
80
+ title={p.spec.title}
81
+ subtitle={p.spec.subtitle}
82
+ icon={p.spec.icon}
83
+ accent={p.spec.accent}
84
+ >
85
+ {hasSeries(p.data) ? (
86
+ <ChartArea>
87
+ <BarChart data={p.data.series} margin={{ top: 4, right: 4, left: -16, bottom: 0 }}>
88
+ <CartesianGrid vertical={false} stroke={CHART_GRID} strokeDasharray="3 3" />
89
+ <XAxis
90
+ dataKey="label"
91
+ tick={{ fontSize: 10, fill: CHART_MUTED }}
92
+ tickLine={false}
93
+ axisLine={false}
94
+ interval="preserveStartEnd"
95
+ />
96
+ <YAxis
97
+ tick={{ fontSize: 10, fill: CHART_MUTED }}
98
+ tickLine={false}
99
+ axisLine={false}
100
+ width={44}
101
+ tickFormatter={(v: number) => formatAxisTick(v, ctx)}
102
+ />
103
+ <ChartTooltip ctx={ctx} />
104
+ <Bar dataKey="value" fill={a.chartVar} radius={[4, 4, 0, 0]} maxBarSize={48} />
105
+ </BarChart>
106
+ </ChartArea>
107
+ ) : (
108
+ <WidgetEmpty message={p.emptyText} />
109
+ )}
110
+ </WidgetCard>
111
+ )
112
+ }
113
+
114
+ // --- line / area (shared) -------------------------------------------------
115
+ function TimeSeriesWidget(p: WidgetRenderProps & { variant: 'line' | 'area' }) {
116
+ const ctx = fmtCtx(p.spec, p.locale, p.currency)
117
+ const a = accentClasses(p.spec.accent)
118
+ const gradId = `wg-grad-${p.spec.key}`
119
+ return (
120
+ <WidgetCard
121
+ data-testid={`widget-${p.spec.key}`}
122
+ title={p.spec.title}
123
+ subtitle={p.spec.subtitle}
124
+ icon={p.spec.icon}
125
+ accent={p.spec.accent}
126
+ >
127
+ {hasSeries(p.data) ? (
128
+ <ChartArea>
129
+ {p.variant === 'area' ? (
130
+ <AreaChart data={p.data.series} margin={{ top: 4, right: 6, left: -16, bottom: 0 }}>
131
+ <defs>
132
+ <linearGradient id={gradId} x1="0" y1="0" x2="0" y2="1">
133
+ <stop offset="0%" stopColor={a.chartVar} stopOpacity={0.35} />
134
+ <stop offset="100%" stopColor={a.chartVar} stopOpacity={0.02} />
135
+ </linearGradient>
136
+ </defs>
137
+ <CartesianGrid vertical={false} stroke={CHART_GRID} strokeDasharray="3 3" />
138
+ <XAxis dataKey="label" tick={{ fontSize: 10, fill: CHART_MUTED }} tickLine={false} axisLine={false} interval="preserveStartEnd" />
139
+ <YAxis tick={{ fontSize: 10, fill: CHART_MUTED }} tickLine={false} axisLine={false} width={44} tickFormatter={(v: number) => formatAxisTick(v, ctx)} />
140
+ <ChartTooltip ctx={ctx} />
141
+ <Area type="monotone" dataKey="value" stroke={a.chartVar} strokeWidth={2} fill={`url(#${gradId})`} />
142
+ </AreaChart>
143
+ ) : (
144
+ <LineChart data={p.data.series} margin={{ top: 4, right: 6, left: -16, bottom: 0 }}>
145
+ <CartesianGrid vertical={false} stroke={CHART_GRID} strokeDasharray="3 3" />
146
+ <XAxis dataKey="label" tick={{ fontSize: 10, fill: CHART_MUTED }} tickLine={false} axisLine={false} interval="preserveStartEnd" />
147
+ <YAxis tick={{ fontSize: 10, fill: CHART_MUTED }} tickLine={false} axisLine={false} width={44} tickFormatter={(v: number) => formatAxisTick(v, ctx)} />
148
+ <ChartTooltip ctx={ctx} />
149
+ <Line type="monotone" dataKey="value" stroke={a.chartVar} strokeWidth={2} dot={false} activeDot={{ r: 4 }} />
150
+ </LineChart>
151
+ )}
152
+ </ChartArea>
153
+ ) : (
154
+ <WidgetEmpty message={p.emptyText} />
155
+ )}
156
+ </WidgetCard>
157
+ )
158
+ }
159
+
160
+ export function LineWidget(p: WidgetRenderProps) {
161
+ return <TimeSeriesWidget {...p} variant="line" />
162
+ }
163
+ export function AreaWidget(p: WidgetRenderProps) {
164
+ return <TimeSeriesWidget {...p} variant="area" />
165
+ }
166
+
167
+ // --- pie / donut (shared) -------------------------------------------------
168
+ function CircularWidget(p: WidgetRenderProps & { variant: 'pie' | 'donut' }) {
169
+ const ctx = fmtCtx(p.spec, p.locale, p.currency)
170
+ return (
171
+ <WidgetCard
172
+ data-testid={`widget-${p.spec.key}`}
173
+ title={p.spec.title}
174
+ subtitle={p.spec.subtitle}
175
+ icon={p.spec.icon}
176
+ accent={p.spec.accent}
177
+ >
178
+ {hasSeries(p.data) ? (
179
+ <div className={cn(CHART_H, 'flex items-center gap-3')}>
180
+ <div className="h-full min-h-0 w-[46%] shrink-0">
181
+ <ResponsiveContainer width="100%" height="100%">
182
+ <PieChart>
183
+ <ChartTooltip ctx={ctx} />
184
+ <Pie
185
+ data={p.data.series}
186
+ dataKey="value"
187
+ nameKey="label"
188
+ innerRadius={p.variant === 'donut' ? '55%' : 0}
189
+ outerRadius="92%"
190
+ paddingAngle={p.variant === 'donut' ? 2 : 0}
191
+ stroke="var(--background, #fff)"
192
+ strokeWidth={2}
193
+ >
194
+ {p.data.series.map((_, i) => (
195
+ <Cell key={i} fill={paletteColor(i)} />
196
+ ))}
197
+ </Pie>
198
+ </PieChart>
199
+ </ResponsiveContainer>
200
+ </div>
201
+ <ul className="flex min-w-0 flex-1 flex-col gap-1.5">
202
+ {p.data.series.slice(0, 6).map((pt, i) => (
203
+ <li key={pt.key} className="flex items-center gap-2 text-xs">
204
+ <span className="size-2.5 shrink-0 rounded-sm" style={{ background: paletteColor(i) }} />
205
+ <span className="truncate text-muted-foreground">{pt.label}</span>
206
+ <span className="ml-auto shrink-0 font-medium tabular-nums text-foreground">
207
+ {formatWidgetValue(pt.value, ctx)}
208
+ </span>
209
+ </li>
210
+ ))}
211
+ </ul>
212
+ </div>
213
+ ) : (
214
+ <WidgetEmpty message={p.emptyText} />
215
+ )}
216
+ </WidgetCard>
217
+ )
218
+ }
219
+
220
+ export function PieWidget(p: WidgetRenderProps) {
221
+ return <CircularWidget {...p} variant="pie" />
222
+ }
223
+ export function DonutWidget(p: WidgetRenderProps) {
224
+ return <CircularWidget {...p} variant="donut" />
225
+ }
@@ -0,0 +1,51 @@
1
+ // Lazy facades for the recharts-backed widgets. The package index and
2
+ // WidgetRenderer import these instead of ./charts, so recharts becomes its own
3
+ // async chunk: it downloads only when a dashboard actually renders a
4
+ // bar/line/area/pie/donut widget. Public names stay the same as before.
5
+
6
+ import * as React from 'react'
7
+ import { WidgetCard } from './widget-card'
8
+ import type { WidgetRenderProps } from './renderers'
9
+
10
+ const loadCharts = () => import('./charts')
11
+
12
+ /** Warm the charts chunk (e.g. on hover of a dashboard link). Idempotent. */
13
+ export function preloadWidgetCharts(): Promise<unknown> {
14
+ return loadCharts()
15
+ }
16
+
17
+ const LazyBar = React.lazy(() => loadCharts().then((m) => ({ default: m.BarWidget })))
18
+ const LazyLine = React.lazy(() => loadCharts().then((m) => ({ default: m.LineWidget })))
19
+ const LazyArea = React.lazy(() => loadCharts().then((m) => ({ default: m.AreaWidget })))
20
+ const LazyPie = React.lazy(() => loadCharts().then((m) => ({ default: m.PieWidget })))
21
+ const LazyDonut = React.lazy(() => loadCharts().then((m) => ({ default: m.DonutWidget })))
22
+
23
+ function ChartFallback(p: WidgetRenderProps) {
24
+ return (
25
+ <WidgetCard
26
+ data-testid={`widget-skeleton-${p.spec.key}`}
27
+ title={p.spec.title}
28
+ subtitle={p.spec.subtitle}
29
+ icon={p.spec.icon}
30
+ accent={p.spec.accent}
31
+ >
32
+ <div className="h-[190px] w-full animate-pulse rounded-md bg-muted" />
33
+ </WidgetCard>
34
+ )
35
+ }
36
+
37
+ function withSuspense(Lazy: React.ComponentType<WidgetRenderProps>) {
38
+ return function LazyChartWidget(p: WidgetRenderProps) {
39
+ return (
40
+ <React.Suspense fallback={<ChartFallback {...p} />}>
41
+ <Lazy {...p} />
42
+ </React.Suspense>
43
+ )
44
+ }
45
+ }
46
+
47
+ export const BarWidget = withSuspense(LazyBar)
48
+ export const LineWidget = withSuspense(LazyLine)
49
+ export const AreaWidget = withSuspense(LazyArea)
50
+ export const PieWidget = withSuspense(LazyPie)
51
+ export const DonutWidget = withSuspense(LazyDonut)
@@ -1,26 +1,10 @@
1
1
  // Built-in dashboard widget renderers, one per declarative `kind`. Each takes
2
2
  // the resolved spec + computed WidgetData + the format context (locale/currency)
3
- // and renders the body INSIDE a <WidgetCard>. recharts powers the charts; colors
4
- // come from theme CSS vars (dark-mode safe), curves are smooth, axes/legends
5
- // compact, tooltips on.
3
+ // and renders the body INSIDE a <WidgetCard>. The recharts-backed kinds
4
+ // (bar/line/area/pie/donut) live in ./charts so this module — and the package
5
+ // index that re-exports it — never pulls recharts into the first paint.
6
6
 
7
7
  import * as React from 'react'
8
- import {
9
- Area,
10
- AreaChart,
11
- Bar,
12
- BarChart,
13
- CartesianGrid,
14
- Cell,
15
- Line,
16
- LineChart,
17
- Pie,
18
- PieChart,
19
- ResponsiveContainer,
20
- Tooltip,
21
- XAxis,
22
- YAxis,
23
- } from 'recharts'
24
8
  import { cn } from '@asteby/metacore-ui/lib'
25
9
  import type { DashboardWidgetSpec, WidgetData } from '../dashboard-types'
26
10
  import { WidgetCard, DeltaChip, WidgetEmpty } from './widget-card'
@@ -44,49 +28,15 @@ export interface WidgetRenderProps {
44
28
  emptyText: string
45
29
  }
46
30
 
47
- const fmtCtx = (
31
+ export const fmtCtx = (
48
32
  spec: DashboardWidgetSpec,
49
33
  locale?: string,
50
34
  currency?: string,
51
35
  ): WidgetFormatCtx => ({ format: spec.format, locale, currency })
52
36
 
53
- const hasSeries = (d?: WidgetData): d is WidgetData & { series: NonNullable<WidgetData['series']> } =>
37
+ export const hasSeries = (d?: WidgetData): d is WidgetData & { series: NonNullable<WidgetData['series']> } =>
54
38
  Array.isArray(d?.series) && d!.series!.length > 0
55
39
 
56
- // Fixed-height chart body. In the masonry (CSS columns) layout cards take their
57
- // natural height, so charts need a definite height for ResponsiveContainer to
58
- // resolve. This height + the card chrome gives every chart card a consistent,
59
- // taller footprint that balances cleanly against compact stat cards.
60
- const CHART_H = 'h-[190px]'
61
- function ChartArea({ children }: { children: React.ReactElement }) {
62
- return (
63
- <div className={cn(CHART_H, 'w-full')}>
64
- <ResponsiveContainer width="100%" height="100%">
65
- {children}
66
- </ResponsiveContainer>
67
- </div>
68
- )
69
- }
70
-
71
- // Compact recharts tooltip styled with theme tokens.
72
- function ChartTooltip({ ctx }: { ctx: WidgetFormatCtx }) {
73
- return (
74
- <Tooltip
75
- cursor={{ fill: 'var(--muted, rgba(148,163,184,0.12))', opacity: 0.4 }}
76
- contentStyle={{
77
- background: 'var(--popover, #fff)',
78
- border: '1px solid var(--border, #e2e8f0)',
79
- borderRadius: 8,
80
- fontSize: 12,
81
- color: 'var(--popover-foreground, #0f172a)',
82
- boxShadow: '0 4px 16px rgba(0,0,0,0.08)',
83
- }}
84
- labelStyle={{ color: 'var(--muted-foreground, #64748b)', marginBottom: 2 }}
85
- formatter={(v: number) => formatWidgetValue(Number(v), ctx)}
86
- />
87
- )
88
- }
89
-
90
40
  // --- stat -----------------------------------------------------------------
91
41
  export function StatWidget(p: WidgetRenderProps) {
92
42
  const ctx = fmtCtx(p.spec, p.locale, p.currency)
@@ -120,161 +70,6 @@ export function StatWidget(p: WidgetRenderProps) {
120
70
  </WidgetCard>
121
71
  )
122
72
  }
123
-
124
- // --- bar ------------------------------------------------------------------
125
- export function BarWidget(p: WidgetRenderProps) {
126
- const ctx = fmtCtx(p.spec, p.locale, p.currency)
127
- const a = accentClasses(p.spec.accent)
128
- return (
129
- <WidgetCard
130
- data-testid={`widget-${p.spec.key}`}
131
- title={p.spec.title}
132
- subtitle={p.spec.subtitle}
133
- icon={p.spec.icon}
134
- accent={p.spec.accent}
135
- >
136
- {hasSeries(p.data) ? (
137
- <ChartArea>
138
- <BarChart data={p.data.series} margin={{ top: 4, right: 4, left: -16, bottom: 0 }}>
139
- <CartesianGrid vertical={false} stroke={CHART_GRID} strokeDasharray="3 3" />
140
- <XAxis
141
- dataKey="label"
142
- tick={{ fontSize: 10, fill: CHART_MUTED }}
143
- tickLine={false}
144
- axisLine={false}
145
- interval="preserveStartEnd"
146
- />
147
- <YAxis
148
- tick={{ fontSize: 10, fill: CHART_MUTED }}
149
- tickLine={false}
150
- axisLine={false}
151
- width={44}
152
- tickFormatter={(v: number) => formatAxisTick(v, ctx)}
153
- />
154
- <ChartTooltip ctx={ctx} />
155
- <Bar dataKey="value" fill={a.chartVar} radius={[4, 4, 0, 0]} maxBarSize={48} />
156
- </BarChart>
157
- </ChartArea>
158
- ) : (
159
- <WidgetEmpty message={p.emptyText} />
160
- )}
161
- </WidgetCard>
162
- )
163
- }
164
-
165
- // --- line / area (shared) -------------------------------------------------
166
- function TimeSeriesWidget(p: WidgetRenderProps & { variant: 'line' | 'area' }) {
167
- const ctx = fmtCtx(p.spec, p.locale, p.currency)
168
- const a = accentClasses(p.spec.accent)
169
- const gradId = `wg-grad-${p.spec.key}`
170
- return (
171
- <WidgetCard
172
- data-testid={`widget-${p.spec.key}`}
173
- title={p.spec.title}
174
- subtitle={p.spec.subtitle}
175
- icon={p.spec.icon}
176
- accent={p.spec.accent}
177
- >
178
- {hasSeries(p.data) ? (
179
- <ChartArea>
180
- {p.variant === 'area' ? (
181
- <AreaChart data={p.data.series} margin={{ top: 4, right: 6, left: -16, bottom: 0 }}>
182
- <defs>
183
- <linearGradient id={gradId} x1="0" y1="0" x2="0" y2="1">
184
- <stop offset="0%" stopColor={a.chartVar} stopOpacity={0.35} />
185
- <stop offset="100%" stopColor={a.chartVar} stopOpacity={0.02} />
186
- </linearGradient>
187
- </defs>
188
- <CartesianGrid vertical={false} stroke={CHART_GRID} strokeDasharray="3 3" />
189
- <XAxis dataKey="label" tick={{ fontSize: 10, fill: CHART_MUTED }} tickLine={false} axisLine={false} interval="preserveStartEnd" />
190
- <YAxis tick={{ fontSize: 10, fill: CHART_MUTED }} tickLine={false} axisLine={false} width={44} tickFormatter={(v: number) => formatAxisTick(v, ctx)} />
191
- <ChartTooltip ctx={ctx} />
192
- <Area type="monotone" dataKey="value" stroke={a.chartVar} strokeWidth={2} fill={`url(#${gradId})`} />
193
- </AreaChart>
194
- ) : (
195
- <LineChart data={p.data.series} margin={{ top: 4, right: 6, left: -16, bottom: 0 }}>
196
- <CartesianGrid vertical={false} stroke={CHART_GRID} strokeDasharray="3 3" />
197
- <XAxis dataKey="label" tick={{ fontSize: 10, fill: CHART_MUTED }} tickLine={false} axisLine={false} interval="preserveStartEnd" />
198
- <YAxis tick={{ fontSize: 10, fill: CHART_MUTED }} tickLine={false} axisLine={false} width={44} tickFormatter={(v: number) => formatAxisTick(v, ctx)} />
199
- <ChartTooltip ctx={ctx} />
200
- <Line type="monotone" dataKey="value" stroke={a.chartVar} strokeWidth={2} dot={false} activeDot={{ r: 4 }} />
201
- </LineChart>
202
- )}
203
- </ChartArea>
204
- ) : (
205
- <WidgetEmpty message={p.emptyText} />
206
- )}
207
- </WidgetCard>
208
- )
209
- }
210
-
211
- export function LineWidget(p: WidgetRenderProps) {
212
- return <TimeSeriesWidget {...p} variant="line" />
213
- }
214
- export function AreaWidget(p: WidgetRenderProps) {
215
- return <TimeSeriesWidget {...p} variant="area" />
216
- }
217
-
218
- // --- pie / donut (shared) -------------------------------------------------
219
- function CircularWidget(p: WidgetRenderProps & { variant: 'pie' | 'donut' }) {
220
- const ctx = fmtCtx(p.spec, p.locale, p.currency)
221
- return (
222
- <WidgetCard
223
- data-testid={`widget-${p.spec.key}`}
224
- title={p.spec.title}
225
- subtitle={p.spec.subtitle}
226
- icon={p.spec.icon}
227
- accent={p.spec.accent}
228
- >
229
- {hasSeries(p.data) ? (
230
- <div className={cn(CHART_H, 'flex items-center gap-3')}>
231
- <div className="h-full min-h-0 w-[46%] shrink-0">
232
- <ResponsiveContainer width="100%" height="100%">
233
- <PieChart>
234
- <ChartTooltip ctx={ctx} />
235
- <Pie
236
- data={p.data.series}
237
- dataKey="value"
238
- nameKey="label"
239
- innerRadius={p.variant === 'donut' ? '55%' : 0}
240
- outerRadius="92%"
241
- paddingAngle={p.variant === 'donut' ? 2 : 0}
242
- stroke="var(--background, #fff)"
243
- strokeWidth={2}
244
- >
245
- {p.data.series.map((_, i) => (
246
- <Cell key={i} fill={paletteColor(i)} />
247
- ))}
248
- </Pie>
249
- </PieChart>
250
- </ResponsiveContainer>
251
- </div>
252
- <ul className="flex min-w-0 flex-1 flex-col gap-1.5">
253
- {p.data.series.slice(0, 6).map((pt, i) => (
254
- <li key={pt.key} className="flex items-center gap-2 text-xs">
255
- <span className="size-2.5 shrink-0 rounded-sm" style={{ background: paletteColor(i) }} />
256
- <span className="truncate text-muted-foreground">{pt.label}</span>
257
- <span className="ml-auto shrink-0 font-medium tabular-nums text-foreground">
258
- {formatWidgetValue(pt.value, ctx)}
259
- </span>
260
- </li>
261
- ))}
262
- </ul>
263
- </div>
264
- ) : (
265
- <WidgetEmpty message={p.emptyText} />
266
- )}
267
- </WidgetCard>
268
- )
269
- }
270
-
271
- export function PieWidget(p: WidgetRenderProps) {
272
- return <CircularWidget {...p} variant="pie" />
273
- }
274
- export function DonutWidget(p: WidgetRenderProps) {
275
- return <CircularWidget {...p} variant="donut" />
276
- }
277
-
278
73
  // --- list (top-N with proportion bars) ------------------------------------
279
74
  export function ListWidget(p: WidgetRenderProps) {
280
75
  const ctx = fmtCtx(p.spec, p.locale, p.currency)
@@ -8,15 +8,17 @@ import type { DashboardWidgetSpec, WidgetData, WidgetSize } from '../dashboard-t
8
8
  import { WidgetCard, WidgetError } from './widget-card'
9
9
  import {
10
10
  StatWidget,
11
+ ListWidget,
12
+ ProgressWidget,
13
+ type WidgetRenderProps,
14
+ } from './renderers'
15
+ import {
11
16
  BarWidget,
12
17
  LineWidget,
13
18
  AreaWidget,
14
19
  PieWidget,
15
20
  DonutWidget,
16
- ListWidget,
17
- ProgressWidget,
18
- type WidgetRenderProps,
19
- } from './renderers'
21
+ } from './lazy-charts'
20
22
 
21
23
  /** Maps a widget size to its column span in the 4-col grid. */
22
24
  export const SIZE_SPAN: Record<WidgetSize, number> = {