@asteby/metacore-runtime-react 53.7.0 → 53.8.2

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 (80) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/action-modal-dispatcher.d.ts.map +1 -1
  3. package/dist/action-modal-dispatcher.js +3 -1
  4. package/dist/api-context.d.ts.map +1 -1
  5. package/dist/api-context.js +15 -0
  6. package/dist/cache-scope.d.ts +52 -0
  7. package/dist/cache-scope.d.ts.map +1 -0
  8. package/dist/cache-scope.js +200 -0
  9. package/dist/capability-providers/index.d.ts +4 -0
  10. package/dist/capability-providers/index.d.ts.map +1 -0
  11. package/dist/capability-providers/index.js +3 -0
  12. package/dist/capability-providers/model.d.ts +201 -0
  13. package/dist/capability-providers/model.d.ts.map +1 -0
  14. package/dist/capability-providers/model.js +293 -0
  15. package/dist/capability-providers/provider-sortable-list.d.ts +86 -0
  16. package/dist/capability-providers/provider-sortable-list.d.ts.map +1 -0
  17. package/dist/capability-providers/provider-sortable-list.js +263 -0
  18. package/dist/capability-providers/reorder.d.ts +10 -0
  19. package/dist/capability-providers/reorder.d.ts.map +1 -0
  20. package/dist/capability-providers/reorder.js +31 -0
  21. package/dist/dashboard-types.d.ts +2 -4
  22. package/dist/dashboard-types.d.ts.map +1 -1
  23. package/dist/dynamic-kanban.d.ts.map +1 -1
  24. package/dist/dynamic-kanban.js +9 -4
  25. package/dist/dynamic-relation.d.ts.map +1 -1
  26. package/dist/dynamic-relation.js +5 -2
  27. package/dist/dynamic-table.d.ts +2 -0
  28. package/dist/dynamic-table.d.ts.map +1 -1
  29. package/dist/dynamic-table.js +40 -6
  30. package/dist/dynamic-view.d.ts.map +1 -1
  31. package/dist/dynamic-view.js +3 -1
  32. package/dist/index.d.ts +4 -1
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +5 -1
  35. package/dist/metadata-cache.d.ts +22 -2
  36. package/dist/metadata-cache.d.ts.map +1 -1
  37. package/dist/metadata-cache.js +73 -13
  38. package/dist/query-batch.d.ts +12 -0
  39. package/dist/query-batch.d.ts.map +1 -1
  40. package/dist/query-batch.js +70 -29
  41. package/dist/setup/addon-config-surface.d.ts.map +1 -1
  42. package/dist/setup/addon-config-surface.js +13 -2
  43. package/dist/use-option-ids.d.ts.map +1 -1
  44. package/dist/use-option-ids.js +3 -1
  45. package/dist/use-options-resolver.d.ts +4 -1
  46. package/dist/use-options-resolver.d.ts.map +1 -1
  47. package/dist/use-options-resolver.js +27 -16
  48. package/dist/widgets/charts.d.ts.map +1 -1
  49. package/dist/widgets/charts.js +11 -43
  50. package/dist/widgets/widget-format.d.ts +1 -41
  51. package/dist/widgets/widget-format.d.ts.map +1 -1
  52. package/dist/widgets/widget-format.js +3 -138
  53. package/package.json +4 -4
  54. package/src/__tests__/addon-config-surface.test.tsx +14 -2
  55. package/src/__tests__/charts-reexport.test.ts +30 -0
  56. package/src/action-modal-dispatcher.tsx +3 -1
  57. package/src/api-context.tsx +14 -0
  58. package/src/cache-scope-inflight.test.ts +369 -0
  59. package/src/cache-scope.test.ts +234 -0
  60. package/src/cache-scope.ts +202 -0
  61. package/src/capability-providers/index.ts +46 -0
  62. package/src/capability-providers/model.test.ts +186 -0
  63. package/src/capability-providers/model.ts +464 -0
  64. package/src/capability-providers/provider-sortable-list.test.tsx +284 -0
  65. package/src/capability-providers/provider-sortable-list.tsx +452 -0
  66. package/src/capability-providers/reorder.ts +29 -0
  67. package/src/dashboard-types.ts +2 -11
  68. package/src/dynamic-kanban.tsx +9 -4
  69. package/src/dynamic-relation.tsx +5 -2
  70. package/src/dynamic-table.tsx +41 -10
  71. package/src/dynamic-view.tsx +3 -1
  72. package/src/index.ts +13 -0
  73. package/src/metadata-cache.ts +85 -15
  74. package/src/query-batch.ts +71 -30
  75. package/src/setup/addon-config-surface.tsx +12 -2
  76. package/src/use-option-ids.ts +3 -1
  77. package/src/use-options-resolver.ts +28 -15
  78. package/src/widgets/charts.tsx +26 -189
  79. package/src/widgets/widget-format.ts +14 -181
  80. package/vitest.setup.ts +16 -0
@@ -1,55 +1,23 @@
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';
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { AreaChartBody, BarChartBody, DonutChartBody, LineChartBody, PieChartBody, } from '@asteby/metacore-charts/recharts';
4
3
  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 }) }));
4
+ import { hasSeries } from './renderers';
5
+ function ChartWidget(p) {
6
+ const { Body } = p;
7
+ 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(Body, { series: p.data.series, accent: p.spec.accent, format: p.spec.format, locale: p.locale, currency: p.currency, id: p.spec.key })) : (_jsx(WidgetEmpty, { message: p.emptyText })) }));
14
8
  }
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
9
  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 })) }));
10
+ return _jsx(ChartWidget, { ...p, Body: BarChartBody });
38
11
  }
39
12
  export function LineWidget(p) {
40
- return _jsx(TimeSeriesWidget, { ...p, variant: "line" });
13
+ return _jsx(ChartWidget, { ...p, Body: LineChartBody });
41
14
  }
42
15
  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 })) }));
16
+ return _jsx(ChartWidget, { ...p, Body: AreaChartBody });
49
17
  }
50
18
  export function PieWidget(p) {
51
- return _jsx(CircularWidget, { ...p, variant: "pie" });
19
+ return _jsx(ChartWidget, { ...p, Body: PieChartBody });
52
20
  }
53
21
  export function DonutWidget(p) {
54
- return _jsx(CircularWidget, { ...p, variant: "donut" });
22
+ return _jsx(ChartWidget, { ...p, Body: DonutChartBody });
55
23
  }
@@ -1,42 +1,2 @@
1
- import type { WidgetAccent, WidgetFormat } from '../dashboard-types';
2
- export interface WidgetFormatCtx {
3
- format?: WidgetFormat;
4
- locale?: string;
5
- currency?: string;
6
- }
7
- /**
8
- * Formats a scalar/series value with the widget's declared format. `currency`
9
- * uses the org currency + locale (same fallback chain as table cells); `percent`
10
- * treats the value as a fraction (0.142 → "14.2%"); `compact` uses Intl compact
11
- * notation (1_200 → "1.2K").
12
- */
13
- export declare function formatWidgetValue(value: number, { format, locale, currency }: WidgetFormatCtx): string;
14
- /** Axis-tick formatter — always compact so charts stay legible. */
15
- export declare function formatAxisTick(value: number, { format, locale, currency }: WidgetFormatCtx): string;
16
- /** Formats the compare delta fraction (0.142 → "+14.2%"). */
17
- export declare function formatDelta(delta: number, locale?: string): string;
18
- export interface AccentClasses {
19
- /** Icon chip background + foreground. */
20
- chip: string;
21
- /** Text color for accented labels. */
22
- text: string;
23
- /** Solid bar/fill background (progress, list proportion). */
24
- bar: string;
25
- /** Soft track background behind a bar. */
26
- track: string;
27
- /** Hex-ish CSS color used for recharts stroke/fill (var-based). */
28
- chartVar: string;
29
- }
30
- /** Resolves the accent class bundle, defaulting to `sky`. */
31
- export declare function accentClasses(accent?: WidgetAccent): AccentClasses;
32
- /**
33
- * A categorical palette for multi-series charts (pie/donut/bar by bucket).
34
- * Cycles the accent chart vars so slices stay theme-aware + dark-mode safe.
35
- */
36
- export declare const CHART_PALETTE: string[];
37
- /** Picks a palette color by index, wrapping around. */
38
- export declare function paletteColor(index: number): string;
39
- /** Grid/axis muted color from the theme (works in light + dark). */
40
- export declare const CHART_MUTED = "var(--muted-foreground, #94a3b8)";
41
- export declare const CHART_GRID = "var(--border, #e2e8f0)";
1
+ export { formatWidgetValue, formatAxisTick, formatDelta, accentClasses, paletteColor, CHART_PALETTE, CHART_GRID, CHART_MUTED, type AccentClasses, type WidgetFormatCtx, } from '@asteby/metacore-charts';
42
2
  //# sourceMappingURL=widget-format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"widget-format.d.ts","sourceRoot":"","sources":["../../src/widgets/widget-format.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEpE,MAAM,WAAW,eAAe;IAC5B,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC7B,KAAK,EAAE,MAAM,EACb,EAAE,MAAiB,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,eAAe,GACzD,MAAM,CA2BR;AAED,mEAAmE;AACnE,wBAAgB,cAAc,CAC1B,KAAK,EAAE,MAAM,EACb,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,eAAe,GAC9C,MAAM,CAoBR;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAUlE;AAQD,MAAM,WAAW,aAAa;IAC1B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,6DAA6D;IAC7D,GAAG,EAAE,MAAM,CAAA;IACX,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAA;IACb,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAA;CACnB;AAiDD,6DAA6D;AAC7D,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,YAAY,GAAG,aAAa,CAElE;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,EAOjC,CAAA;AAED,uDAAuD;AACvD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,oEAAoE;AACpE,eAAO,MAAM,WAAW,qCAAqC,CAAA;AAC7D,eAAO,MAAM,UAAU,2BAA2B,CAAA"}
1
+ {"version":3,"file":"widget-format.d.ts","sourceRoot":"","sources":["../../src/widgets/widget-format.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,aAAa,EACb,YAAY,EACZ,aAAa,EACb,UAAU,EACV,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,eAAe,GACvB,MAAM,yBAAyB,CAAA"}
@@ -1,138 +1,3 @@
1
- // Shared widget formatting + accent theming. Reuses the same Intl-based
2
- // approach as the table cells (dynamic-columns) so dashboard numbers read
3
- // identically to the grids: org currency + locale, compact notation, percent.
4
- /**
5
- * Formats a scalar/series value with the widget's declared format. `currency`
6
- * uses the org currency + locale (same fallback chain as table cells); `percent`
7
- * treats the value as a fraction (0.142 → "14.2%"); `compact` uses Intl compact
8
- * notation (1_200 → "1.2K").
9
- */
10
- export function formatWidgetValue(value, { format = 'number', locale, currency }) {
11
- if (value === null || value === undefined || Number.isNaN(value))
12
- return '—';
13
- const loc = locale || undefined;
14
- switch (format) {
15
- case 'currency':
16
- return new Intl.NumberFormat(loc, {
17
- style: 'currency',
18
- currency: currency || 'USD',
19
- maximumFractionDigits: 2,
20
- }).format(value);
21
- case 'percent':
22
- return new Intl.NumberFormat(loc, {
23
- style: 'percent',
24
- minimumFractionDigits: 0,
25
- maximumFractionDigits: 1,
26
- }).format(value);
27
- case 'compact':
28
- return new Intl.NumberFormat(loc, {
29
- notation: 'compact',
30
- maximumFractionDigits: 1,
31
- }).format(value);
32
- case 'number':
33
- default:
34
- return new Intl.NumberFormat(loc, {
35
- maximumFractionDigits: 2,
36
- }).format(value);
37
- }
38
- }
39
- /** Axis-tick formatter — always compact so charts stay legible. */
40
- export function formatAxisTick(value, { format, locale, currency }) {
41
- const loc = locale || undefined;
42
- if (format === 'currency') {
43
- return new Intl.NumberFormat(loc, {
44
- style: 'currency',
45
- currency: currency || 'USD',
46
- notation: 'compact',
47
- maximumFractionDigits: 1,
48
- }).format(value);
49
- }
50
- if (format === 'percent') {
51
- return new Intl.NumberFormat(loc, {
52
- style: 'percent',
53
- maximumFractionDigits: 0,
54
- }).format(value);
55
- }
56
- return new Intl.NumberFormat(loc, {
57
- notation: 'compact',
58
- maximumFractionDigits: 1,
59
- }).format(value);
60
- }
61
- /** Formats the compare delta fraction (0.142 → "+14.2%"). */
62
- export function formatDelta(delta, locale) {
63
- const sign = delta > 0 ? '+' : '';
64
- return (sign +
65
- new Intl.NumberFormat(locale || undefined, {
66
- style: 'percent',
67
- minimumFractionDigits: 0,
68
- maximumFractionDigits: 1,
69
- }).format(delta));
70
- }
71
- const ACCENTS = {
72
- emerald: {
73
- chip: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400',
74
- text: 'text-emerald-600 dark:text-emerald-400',
75
- bar: 'bg-emerald-500',
76
- track: 'bg-emerald-500/15',
77
- chartVar: 'var(--color-widget-emerald, #10b981)',
78
- },
79
- sky: {
80
- chip: 'bg-sky-500/10 text-sky-600 dark:text-sky-400',
81
- text: 'text-sky-600 dark:text-sky-400',
82
- bar: 'bg-sky-500',
83
- track: 'bg-sky-500/15',
84
- chartVar: 'var(--color-widget-sky, #0ea5e9)',
85
- },
86
- violet: {
87
- chip: 'bg-violet-500/10 text-violet-600 dark:text-violet-400',
88
- text: 'text-violet-600 dark:text-violet-400',
89
- bar: 'bg-violet-500',
90
- track: 'bg-violet-500/15',
91
- chartVar: 'var(--color-widget-violet, #8b5cf6)',
92
- },
93
- amber: {
94
- chip: 'bg-amber-500/10 text-amber-600 dark:text-amber-400',
95
- text: 'text-amber-600 dark:text-amber-400',
96
- bar: 'bg-amber-500',
97
- track: 'bg-amber-500/15',
98
- chartVar: 'var(--color-widget-amber, #f59e0b)',
99
- },
100
- rose: {
101
- chip: 'bg-rose-500/10 text-rose-600 dark:text-rose-400',
102
- text: 'text-rose-600 dark:text-rose-400',
103
- bar: 'bg-rose-500',
104
- track: 'bg-rose-500/15',
105
- chartVar: 'var(--color-widget-rose, #f43f5e)',
106
- },
107
- slate: {
108
- chip: 'bg-slate-500/10 text-slate-600 dark:text-slate-300',
109
- text: 'text-slate-600 dark:text-slate-300',
110
- bar: 'bg-slate-500',
111
- track: 'bg-slate-500/15',
112
- chartVar: 'var(--color-widget-slate, #64748b)',
113
- },
114
- };
115
- const DEFAULT_ACCENT = 'sky';
116
- /** Resolves the accent class bundle, defaulting to `sky`. */
117
- export function accentClasses(accent) {
118
- return ACCENTS[accent ?? DEFAULT_ACCENT] ?? ACCENTS[DEFAULT_ACCENT];
119
- }
120
- /**
121
- * A categorical palette for multi-series charts (pie/donut/bar by bucket).
122
- * Cycles the accent chart vars so slices stay theme-aware + dark-mode safe.
123
- */
124
- export const CHART_PALETTE = [
125
- ACCENTS.sky.chartVar,
126
- ACCENTS.emerald.chartVar,
127
- ACCENTS.violet.chartVar,
128
- ACCENTS.amber.chartVar,
129
- ACCENTS.rose.chartVar,
130
- ACCENTS.slate.chartVar,
131
- ];
132
- /** Picks a palette color by index, wrapping around. */
133
- export function paletteColor(index) {
134
- return CHART_PALETTE[index % CHART_PALETTE.length];
135
- }
136
- /** Grid/axis muted color from the theme (works in light + dark). */
137
- export const CHART_MUTED = 'var(--muted-foreground, #94a3b8)';
138
- export const CHART_GRID = 'var(--border, #e2e8f0)';
1
+ // Moved to @asteby/metacore-charts (shared palette + formatting). Re-exported
2
+ // here so existing imports keep compiling.
3
+ export { formatWidgetValue, formatAxisTick, formatDelta, accentClasses, paletteColor, CHART_PALETTE, CHART_GRID, CHART_MUTED, } from '@asteby/metacore-charts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/metacore-runtime-react",
3
- "version": "53.7.0",
3
+ "version": "53.8.2",
4
4
  "description": "React runtime for metacore hosts — renders addon contributions dynamically",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,15 +33,15 @@
33
33
  }
34
34
  },
35
35
  "dependencies": {
36
+ "@asteby/metacore-charts": "^0.1.0",
36
37
  "@dnd-kit/core": "^6.3.0",
37
38
  "@dnd-kit/sortable": "^10.0.0",
38
39
  "@dnd-kit/utilities": "^3.2.2",
39
40
  "@tanstack/react-virtual": "^3.14.13",
40
- "recharts": "^3.8.1",
41
41
  "zod": "^4.3.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@asteby/metacore-sdk": "^3.18.0",
44
+ "@asteby/metacore-sdk": "^3.18.1",
45
45
  "@asteby/metacore-ui": "^2.31.0",
46
46
  "@tanstack/react-query": ">=5",
47
47
  "@tanstack/react-router": ">=1.100",
@@ -73,7 +73,7 @@
73
73
  }
74
74
  },
75
75
  "devDependencies": {
76
- "@asteby/metacore-sdk": "3.18.0",
76
+ "@asteby/metacore-sdk": "3.18.1",
77
77
  "@asteby/metacore-ui": "2.31.0",
78
78
  "@tanstack/react-query": "^5.95.0",
79
79
  "@tanstack/react-router": "^1.168.0",
@@ -4,9 +4,9 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
4
4
  import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
5
5
 
6
6
  vi.mock('react-i18next', () => {
7
- const dict: Record<string, string> = { 'pay.public_key': 'Llave pública', 'pay.token': 'Token', 'pay.serie_a': 'Serie A', 'pay.serie_b': 'Serie B' }
7
+ const dict: Record<string, string> = { 'pay.public_key': 'Llave pública', 'pay.token': 'Token', 'pay.serie_a': 'Serie A', 'pay.serie_b': 'Serie B', 'pay.settings.policy': 'Política de guía', 'pay.settings.policy_manual': 'A mano' }
8
8
  const t = (k: string, o?: { defaultValue?: string }) => dict[k] ?? o?.defaultValue ?? k
9
- return { useTranslation: () => ({ t, i18n: { language: 'es', exists: () => true } }) }
9
+ return { useTranslation: () => ({ t, i18n: { language: 'es', exists: (k: string) => k in dict } }) }
10
10
  })
11
11
 
12
12
  import { ApiProvider } from '../api-context'
@@ -244,6 +244,18 @@ describe('AddonConfigSurface', () => {
244
244
  expect(put.body.mode).toBe('a')
245
245
  })
246
246
 
247
+ it('settings: label and option labels resolve from the addon bundle, never the raw key', async () => {
248
+ const defs = [
249
+ { key: 'policy', label: 'pay.settings.policy', type: 'select', options: [{ value: 'manual', label: 'pay.settings.policy_manual' }, { value: 'on_paid', label: 'pay.settings.policy_on_paid' }] },
250
+ { key: 'ghost_limit', label: 'pay.settings.ghost_limit', type: 'text' },
251
+ ]
252
+ setup({ connector: null }, { 'GET /addons/pay/settings': { data: { policy: 'manual' }, definitions: defs } })
253
+ await screen.findByText('Política de guía')
254
+ expect(screen.getByText('A mano')).toBeTruthy()
255
+ expect(screen.getByText('Ghost Limit')).toBeTruthy()
256
+ expect(screen.queryByText('pay.settings.ghost_limit')).toBeNull()
257
+ })
258
+
247
259
  it('per-branch mode only sends what was touched', async () => {
248
260
  const defs = [{ key: 'tip', label: 'Propina', type: 'text', scope: 'branch' }, { key: 'org', label: 'Org', type: 'text' }]
249
261
  const { calls, notify } = setup(
@@ -0,0 +1,30 @@
1
+ // The chart code moved to @asteby/metacore-charts; everything runtime-react
2
+ // used to expose must still be exported from its index, and the formatters
3
+ // must be the very same functions.
4
+ import { describe, expect, it } from 'vitest'
5
+ import * as runtime from '../index'
6
+ import * as charts from '@asteby/metacore-charts'
7
+
8
+ describe('runtime-react keeps exporting the chart surface', () => {
9
+ it.each([
10
+ 'BarWidget', 'LineWidget', 'AreaWidget', 'PieWidget', 'DonutWidget', 'preloadWidgetCharts',
11
+ 'formatWidgetValue', 'formatAxisTick', 'formatDelta', 'accentClasses', 'paletteColor', 'CHART_PALETTE',
12
+ 'WidgetCard', 'WidgetRenderer', 'StatWidget',
13
+ ])('exports %s', (name) => {
14
+ expect((runtime as Record<string, unknown>)[name]).toBeDefined()
15
+ })
16
+
17
+ it('shares the implementation with @asteby/metacore-charts', () => {
18
+ expect(runtime.formatWidgetValue).toBe(charts.formatWidgetValue)
19
+ expect(runtime.paletteColor).toBe(charts.paletteColor)
20
+ expect(runtime.CHART_PALETTE).toBe(charts.CHART_PALETTE)
21
+ expect(runtime.Sparkline).toBe(charts.Sparkline)
22
+ })
23
+
24
+ it('keeps the eager ./charts module exporting the five widgets', async () => {
25
+ const m = await import('../widgets/charts')
26
+ for (const k of ['BarWidget', 'LineWidget', 'AreaWidget', 'PieWidget', 'DonutWidget']) {
27
+ expect(typeof (m as Record<string, unknown>)[k]).toBe('function')
28
+ }
29
+ })
30
+ })
@@ -72,6 +72,7 @@ import { UploadField } from './upload-field'
72
72
  import { isLineItemsField, resolveWidget, resolveDependsValue, getDependsOn, getFieldRef, applyOptionWhen } from './dynamic-form-schema'
73
73
  import { FieldGrid, FieldCell, FieldLabel } from './field-grid'
74
74
  import { useMetadataCache } from './metadata-cache'
75
+ import { cacheScope } from './cache-scope'
75
76
  import {
76
77
  ViewValue,
77
78
  objectLabel,
@@ -800,6 +801,7 @@ function RecordPreview({ model, record }: { model: string; record: any }) {
800
801
  useEffect(() => {
801
802
  if (cached || !model) return
802
803
  let cancelled = false
804
+ const askedScope = cacheScope()
803
805
  api
804
806
  .get(`/metadata/table/${model}`)
805
807
  .then((res) => {
@@ -807,7 +809,7 @@ function RecordPreview({ model, record }: { model: string; record: any }) {
807
809
  const meta = (res.data?.data ?? res.data) as TableMetadata
808
810
  if (meta && Array.isArray(meta.columns)) {
809
811
  setFetched(meta)
810
- setMetadata(model, meta)
812
+ setMetadata(model, meta, { scope: askedScope })
811
813
  }
812
814
  })
813
815
  .catch(() => {
@@ -4,6 +4,7 @@
4
4
  // their app in <ApiProvider value={axiosInstance}> once at the root.
5
5
  import React, { createContext, useContext, useEffect, useMemo } from 'react'
6
6
  import { batchGet, invalidateQueryBatchData } from './query-batch'
7
+ import { syncCacheScope } from './cache-scope'
7
8
  import { invalidateOptionsCache } from './use-options-resolver'
8
9
  import {
9
10
  epochFromAxiosHeaders,
@@ -38,6 +39,19 @@ export interface ApiProviderProps {
38
39
  }
39
40
 
40
41
  export function ApiProvider({ client, batch = true, children }: ApiProviderProps) {
42
+ // Login, logout or an org/user/language switch (also from another tab)
43
+ // empties the scoped caches (metadata store, query batch).
44
+ useEffect(() => {
45
+ syncCacheScope()
46
+ if (typeof window === 'undefined') return
47
+ const onChange = () => syncCacheScope()
48
+ window.addEventListener('storage', onChange)
49
+ window.addEventListener('focus', onChange)
50
+ return () => {
51
+ window.removeEventListener('storage', onChange)
52
+ window.removeEventListener('focus', onChange)
53
+ }
54
+ }, [])
41
55
  // Hosts also write through their own client (native dialogs, settings
42
56
  // screens) without going through useApi(). When the client is axios,
43
57
  // every non-GET response drops what the runtime remembered as well.