@asteby/metacore-runtime-react 53.7.0 → 53.8.1

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 (76) hide show
  1. package/CHANGELOG.md +32 -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/use-option-ids.d.ts.map +1 -1
  42. package/dist/use-option-ids.js +3 -1
  43. package/dist/use-options-resolver.d.ts +4 -1
  44. package/dist/use-options-resolver.d.ts.map +1 -1
  45. package/dist/use-options-resolver.js +27 -16
  46. package/dist/widgets/charts.d.ts.map +1 -1
  47. package/dist/widgets/charts.js +11 -43
  48. package/dist/widgets/widget-format.d.ts +1 -41
  49. package/dist/widgets/widget-format.d.ts.map +1 -1
  50. package/dist/widgets/widget-format.js +3 -138
  51. package/package.json +4 -4
  52. package/src/__tests__/charts-reexport.test.ts +30 -0
  53. package/src/action-modal-dispatcher.tsx +3 -1
  54. package/src/api-context.tsx +14 -0
  55. package/src/cache-scope-inflight.test.ts +369 -0
  56. package/src/cache-scope.test.ts +234 -0
  57. package/src/cache-scope.ts +202 -0
  58. package/src/capability-providers/index.ts +46 -0
  59. package/src/capability-providers/model.test.ts +186 -0
  60. package/src/capability-providers/model.ts +464 -0
  61. package/src/capability-providers/provider-sortable-list.test.tsx +284 -0
  62. package/src/capability-providers/provider-sortable-list.tsx +452 -0
  63. package/src/capability-providers/reorder.ts +29 -0
  64. package/src/dashboard-types.ts +2 -11
  65. package/src/dynamic-kanban.tsx +9 -4
  66. package/src/dynamic-relation.tsx +5 -2
  67. package/src/dynamic-table.tsx +41 -10
  68. package/src/dynamic-view.tsx +3 -1
  69. package/src/index.ts +13 -0
  70. package/src/metadata-cache.ts +85 -15
  71. package/src/query-batch.ts +71 -30
  72. package/src/use-option-ids.ts +3 -1
  73. package/src/use-options-resolver.ts +28 -15
  74. package/src/widgets/charts.tsx +26 -189
  75. package/src/widgets/widget-format.ts +14 -181
  76. package/vitest.setup.ts +16 -0
@@ -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,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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.1",
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",
@@ -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.