@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
@@ -0,0 +1,452 @@
1
+ /**
2
+ * ProviderSortableList: an ordered list of options with a status badge, a
3
+ * keyboard-accessible drag handle and an "inherits from the organization"
4
+ * marker. Domain-agnostic: the host decides what the ids mean and what to do
5
+ * with the new order.
6
+ *
7
+ * Keyboard: focus the handle, Space/Enter grabs, ArrowUp/ArrowDown move,
8
+ * Space/Enter drops, Escape cancels. Pointer: press the handle and drag.
9
+ * Items that are not eligible (status `unavailable` / `disabled`, `enabled:
10
+ * false` or `eligible: false`) are rendered after the sortable ones in their
11
+ * own list, have no handle, and are never part of the emitted order.
12
+ *
13
+ * `onReorder` emits ONLY the eligible ids. A host that persists the whole
14
+ * list (including ineligible entries that are not merely "does not serve the
15
+ * market", e.g. disabled ones) must merge: keep its own ineligible entries
16
+ * and replace the order of the eligible ones with what is emitted here.
17
+ */
18
+ import * as React from 'react'
19
+ import { useTranslation } from 'react-i18next'
20
+ import type { ProviderStatus } from './model'
21
+ import { dropIndexFromPointer, moveId } from './reorder'
22
+
23
+ export interface ProviderSortableItem {
24
+ id: string
25
+ /**
26
+ * What to show. If it is not plain text, also pass `textLabel`: the handle
27
+ * and the live region announce `textLabel` (never the raw id when avoidable).
28
+ */
29
+ label: React.ReactNode
30
+ /** Plain-text name for assistive technology (handle, live region). */
31
+ textLabel?: string
32
+ status: ProviderStatus
33
+ /** Secondary line (e.g. the account or environment). */
34
+ description?: React.ReactNode
35
+ /** Defaults to `status` not being `unavailable` / `disabled`, and `enabled !== false`. */
36
+ eligible?: boolean
37
+ /**
38
+ * The row's own `enabled` flag. `false` shows the `disabled` badge and
39
+ * makes the item ineligible. With `onEnabledChange` a switch is rendered.
40
+ */
41
+ enabled?: boolean
42
+ /** Per-item actions (e.g. a "connect" link while `missing_credentials`). */
43
+ actions?: React.ReactNode
44
+ }
45
+
46
+ export interface ProviderSortableListLabels {
47
+ ready: string
48
+ missing_credentials: string
49
+ sandbox: string
50
+ unavailable: string
51
+ unhealthy: string
52
+ disabled: string
53
+ inherited: string
54
+ /** Heading (aria-label) of the list of items that cannot be ordered. */
55
+ unavailableGroup: string
56
+ /** Keyboard instructions, linked to every handle with aria-describedby. */
57
+ instructions: string
58
+ /** aria-label of the drag handle; receives the item's text label. */
59
+ handle: (label: string) => string
60
+ /** aria-label of the enabled switch. */
61
+ enable: (label: string) => string
62
+ /** Live-region messages. */
63
+ grabbed: (label: string, position: number, total: number) => string
64
+ moved: (label: string, position: number, total: number) => string
65
+ dropped: (label: string, position: number, total: number) => string
66
+ cancelled: (label: string) => string
67
+ }
68
+
69
+ /** Spanish defaults, kept as a plain constant for hosts that want to spread/override it. */
70
+ export const DEFAULT_PROVIDER_LIST_LABELS: ProviderSortableListLabels = {
71
+ ready: 'Listo',
72
+ missing_credentials: 'Sin credenciales',
73
+ sandbox: 'Sandbox',
74
+ unavailable: 'No atiende',
75
+ unhealthy: 'Con fallas',
76
+ disabled: 'Desactivado',
77
+ inherited: 'Hereda de la organización',
78
+ unavailableGroup: 'Sin orden: no disponibles',
79
+ instructions: 'Espacio o Enter para tomar, flechas para mover, Espacio o Enter para soltar, Escape para cancelar.',
80
+ handle: (l) => `Reordenar ${l}`,
81
+ enable: (l) => `Activar ${l}`,
82
+ grabbed: (l, p, t) => `${l} tomado, posición ${p} de ${t}. Usa las flechas para mover.`,
83
+ moved: (l, p, t) => `${l}, posición ${p} de ${t}.`,
84
+ dropped: (l, p, t) => `${l} soltado en la posición ${p} de ${t}.`,
85
+ cancelled: (l) => `Reordenamiento de ${l} cancelado.`,
86
+ }
87
+
88
+ /** Replaces any `{{name}}` that the translator left (e.g. no i18n instance yet). */
89
+ function fill(s: string, vars: Record<string, string | number>): string {
90
+ return s.replace(/\{\{\s*(\w+)\s*\}\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m))
91
+ }
92
+
93
+ /**
94
+ * Default labels through the host's i18n (`capability_providers.*` keys, same
95
+ * convention as the rest of the package), falling back to the Spanish text.
96
+ * `overrides` always wins.
97
+ */
98
+ function useProviderListLabels(overrides?: Partial<ProviderSortableListLabels>): ProviderSortableListLabels {
99
+ const { t } = useTranslation()
100
+ const D = DEFAULT_PROVIDER_LIST_LABELS
101
+ const s = (key: keyof ProviderSortableListLabels, def: string) =>
102
+ t(`capability_providers.${key}`, { defaultValue: def }) as string
103
+ const f = (key: string, def: string, vars: Record<string, string | number>) =>
104
+ fill(t(`capability_providers.${key}`, { defaultValue: def, ...vars }) as string, vars)
105
+ return {
106
+ ready: s('ready', D.ready),
107
+ missing_credentials: s('missing_credentials', D.missing_credentials),
108
+ sandbox: s('sandbox', D.sandbox),
109
+ unavailable: s('unavailable', D.unavailable),
110
+ unhealthy: s('unhealthy', D.unhealthy),
111
+ disabled: s('disabled', D.disabled),
112
+ inherited: s('inherited', D.inherited),
113
+ unavailableGroup: s('unavailableGroup', D.unavailableGroup),
114
+ instructions: s('instructions', D.instructions),
115
+ handle: (label) => f('handle', 'Reordenar {{label}}', { label }),
116
+ enable: (label) => f('enable', 'Activar {{label}}', { label }),
117
+ grabbed: (label, position, total) =>
118
+ f('grabbed', '{{label}} tomado, posición {{position}} de {{total}}. Usa las flechas para mover.', { label, position, total }),
119
+ moved: (label, position, total) => f('moved', '{{label}}, posición {{position}} de {{total}}.', { label, position, total }),
120
+ dropped: (label, position, total) =>
121
+ f('dropped', '{{label}} soltado en la posición {{position}} de {{total}}.', { label, position, total }),
122
+ cancelled: (label) => f('cancelled', 'Reordenamiento de {{label}} cancelado.', { label }),
123
+ ...overrides,
124
+ }
125
+ }
126
+
127
+ export interface ProviderSortableListProps {
128
+ items: ProviderSortableItem[]
129
+ /** Ids of the eligible items in their current order; unlisted eligible items follow in `items` order. */
130
+ order?: string[]
131
+ /** Emits the new order of the ELIGIBLE items on drop (keyboard or pointer). Never called when nothing moved. */
132
+ onReorder: (order: string[]) => void
133
+ /** The order shown is the organization's, not the market's own. */
134
+ inherited?: boolean
135
+ /** Renders the "inherits from the organization" switch instead of a plain note. */
136
+ onInheritedChange?: (inherited: boolean) => void
137
+ /** Renders a per-item enabled switch. */
138
+ onEnabledChange?: (id: string, enabled: boolean) => void
139
+ disabled?: boolean
140
+ labels?: Partial<ProviderSortableListLabels>
141
+ className?: string
142
+ 'aria-label'?: string
143
+ }
144
+
145
+ const cx = (...c: Array<string | false | undefined>) => c.filter(Boolean).join(' ')
146
+
147
+ const BADGE_TONE: Record<ProviderStatus, string> = {
148
+ ready: 'bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-300',
149
+ missing_credentials: 'bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-300',
150
+ sandbox: 'bg-sky-100 text-sky-800 dark:bg-sky-500/15 dark:text-sky-300',
151
+ unhealthy: 'bg-red-100 text-red-800 dark:bg-red-500/15 dark:text-red-300',
152
+ unavailable: 'bg-muted text-muted-foreground',
153
+ disabled: 'bg-muted text-muted-foreground',
154
+ }
155
+
156
+ function statusOf(i: ProviderSortableItem): ProviderStatus {
157
+ return i.enabled === false ? 'disabled' : i.status
158
+ }
159
+
160
+ function isEligible(i: ProviderSortableItem): boolean {
161
+ if (i.enabled === false) return false
162
+ return i.eligible ?? (i.status !== 'unavailable' && i.status !== 'disabled')
163
+ }
164
+
165
+ /** Eligible ids in display order, honoring `order` first. */
166
+ export function sortableOrder(items: readonly ProviderSortableItem[], order?: readonly string[]): string[] {
167
+ const eligible = items.filter(isEligible).map((i) => i.id)
168
+ const set = new Set(eligible)
169
+ const head = (order ?? []).filter((id, n, a) => set.has(id) && a.indexOf(id) === n)
170
+ return [...head, ...eligible.filter((id) => !head.includes(id))]
171
+ }
172
+
173
+ export function ProviderSortableList({
174
+ items,
175
+ order,
176
+ onReorder,
177
+ inherited,
178
+ onInheritedChange,
179
+ onEnabledChange,
180
+ disabled,
181
+ labels: labelsProp,
182
+ className,
183
+ 'aria-label': ariaLabel,
184
+ }: ProviderSortableListProps) {
185
+ const labels = useProviderListLabels(labelsProp)
186
+ const helpId = React.useId()
187
+ const byId = React.useMemo(() => new Map(items.map((i) => [i.id, i])), [items])
188
+ const base = React.useMemo(() => sortableOrder(items, order), [items, order])
189
+ // While grabbed (keyboard) or dragging (pointer) the list shows a draft.
190
+ const [draft, setDraft] = React.useState<string[] | null>(null)
191
+ const [active, setActive] = React.useState<string | null>(null)
192
+ const [announce, setAnnounce] = React.useState('')
193
+ const rows = React.useRef(new Map<string, HTMLElement>())
194
+ const handles = React.useRef(new Map<string, HTMLElement>())
195
+ const mode = React.useRef<'keyboard' | 'pointer'>('keyboard')
196
+ // True between a programmatic reorder and the moment focus is restored:
197
+ // moving the focused <li> in the DOM makes browsers blur the handle.
198
+ const reordering = React.useRef(false)
199
+
200
+ // The draft is reconciled against the CURRENT items on every render, so an
201
+ // items/order change (refetch, market switch, addon uninstalled) in the
202
+ // middle of a grab can never leave ids that no longer exist.
203
+ const shown = React.useMemo(() => {
204
+ if (!draft) return base
205
+ const live = new Set(base)
206
+ const kept = draft.filter((id, n, a) => live.has(id) && a.indexOf(id) === n)
207
+ return [...kept, ...base.filter((id) => !kept.includes(id))]
208
+ }, [draft, base])
209
+ const shownRef = React.useRef(shown)
210
+ shownRef.current = shown
211
+
212
+ const blocked = items.filter((i) => !isEligible(i))
213
+ const textOf = (id: string) => {
214
+ const item = byId.get(id)
215
+ if (!item) return id
216
+ if (item.textLabel) return item.textLabel
217
+ return typeof item.label === 'string' || typeof item.label === 'number' ? String(item.label) : id
218
+ }
219
+
220
+ const clear = () => {
221
+ setDraft(null)
222
+ setActive(null)
223
+ }
224
+ const commit = (next: string[], id: string, announceUnchanged = true) => {
225
+ const changed = next.some((x, n) => x !== base[n])
226
+ clear()
227
+ if (changed || announceUnchanged) setAnnounce(labels.dropped(textOf(id), next.indexOf(id) + 1, next.length))
228
+ if (changed) onReorder(next)
229
+ }
230
+ const cancel = (id: string) => {
231
+ clear()
232
+ setAnnounce(labels.cancelled(textOf(id)))
233
+ }
234
+ const step = (id: string, delta: number) => {
235
+ const next = moveId(shown, id, delta)
236
+ reordering.current = true
237
+ setDraft(next)
238
+ setAnnounce(labels.moved(textOf(id), next.indexOf(id) + 1, next.length))
239
+ }
240
+
241
+ // Keep the latest closures reachable from the window listeners below.
242
+ const latest = React.useRef({ commit, cancel })
243
+ latest.current = { commit, cancel }
244
+
245
+ // The grabbed item vanished (items changed) or the list got disabled
246
+ // mid-grab: drop the grab without emitting anything.
247
+ React.useEffect(() => {
248
+ if (active && (disabled || !base.includes(active))) clear()
249
+ }, [active, disabled, base])
250
+
251
+ // Moving the focused <li> blurs the handle in real browsers (happy-dom does
252
+ // not): put the focus back on the grabbed handle after every reorder.
253
+ React.useLayoutEffect(() => {
254
+ reordering.current = false
255
+ if (active && mode.current === 'keyboard') {
256
+ const h = handles.current.get(active)
257
+ if (h && document.activeElement !== h) h.focus({ preventScroll: true })
258
+ }
259
+ })
260
+
261
+ // Pointer drag: listen on window while dragging. Pointer capture on the
262
+ // handle would be lost whenever React moves its <li>, leaving the drag
263
+ // half done; window listeners survive any DOM reordering.
264
+ React.useEffect(() => {
265
+ if (!active || mode.current !== 'pointer') return
266
+ const id = active
267
+ const onMove = (e: PointerEvent) => {
268
+ const cur = shownRef.current
269
+ const others = cur.filter((x) => x !== id)
270
+ const mids = others.map((x) => {
271
+ const r = rows.current.get(x)?.getBoundingClientRect()
272
+ return r ? r.top + r.height / 2 : 0
273
+ })
274
+ const to = dropIndexFromPointer(e.clientY, mids)
275
+ const next = [...others.slice(0, to), id, ...others.slice(to)]
276
+ if (next.some((x, n) => x !== cur[n])) setDraft(next)
277
+ }
278
+ const onUp = () => latest.current.commit(shownRef.current, id, false)
279
+ const onCancel = () => latest.current.cancel(id)
280
+ window.addEventListener('pointermove', onMove)
281
+ window.addEventListener('pointerup', onUp)
282
+ window.addEventListener('pointercancel', onCancel)
283
+ return () => {
284
+ window.removeEventListener('pointermove', onMove)
285
+ window.removeEventListener('pointerup', onUp)
286
+ window.removeEventListener('pointercancel', onCancel)
287
+ }
288
+ }, [active])
289
+
290
+ const onKeyDown = (id: string) => (e: React.KeyboardEvent) => {
291
+ if (disabled) return
292
+ const grabbed = active === id
293
+ if (e.key === ' ' || e.key === 'Enter') {
294
+ e.preventDefault()
295
+ if (grabbed) commit(shown, id)
296
+ else {
297
+ mode.current = 'keyboard'
298
+ setActive(id)
299
+ setDraft(base)
300
+ setAnnounce(labels.grabbed(textOf(id), base.indexOf(id) + 1, base.length))
301
+ }
302
+ } else if (grabbed && (e.key === 'ArrowUp' || e.key === 'ArrowLeft')) {
303
+ e.preventDefault()
304
+ step(id, -1)
305
+ } else if (grabbed && (e.key === 'ArrowDown' || e.key === 'ArrowRight')) {
306
+ e.preventDefault()
307
+ step(id, 1)
308
+ } else if (grabbed && e.key === 'Escape') {
309
+ e.preventDefault()
310
+ cancel(id)
311
+ }
312
+ }
313
+
314
+ const onPointerDown = (id: string) => (e: React.PointerEvent) => {
315
+ if (disabled || (e.button !== undefined && e.button !== 0)) return
316
+ mode.current = 'pointer'
317
+ setActive(id)
318
+ setDraft(base)
319
+ }
320
+
321
+ const switches = (item: ProviderSortableItem) =>
322
+ onEnabledChange ? (
323
+ <input
324
+ type="checkbox"
325
+ role="switch"
326
+ disabled={disabled}
327
+ checked={item.enabled !== false}
328
+ aria-label={labels.enable(textOf(item.id))}
329
+ data-enabled-switch={item.id}
330
+ onChange={(e) => onEnabledChange(item.id, e.target.checked)}
331
+ />
332
+ ) : null
333
+
334
+ return (
335
+ <div className={className}>
336
+ {onInheritedChange ? (
337
+ <label
338
+ data-testid="provider-list-inherited"
339
+ className="mb-2 flex items-center gap-2 text-xs text-muted-foreground"
340
+ >
341
+ <input
342
+ type="checkbox"
343
+ role="switch"
344
+ disabled={disabled}
345
+ checked={!!inherited}
346
+ onChange={(e) => onInheritedChange(e.target.checked)}
347
+ />
348
+ {labels.inherited}
349
+ </label>
350
+ ) : (
351
+ inherited && (
352
+ <p data-testid="provider-list-inherited" className="mb-2 text-xs text-muted-foreground">
353
+ {labels.inherited}
354
+ </p>
355
+ )
356
+ )}
357
+ <span id={helpId} className="sr-only">
358
+ {labels.instructions}
359
+ </span>
360
+ <ol aria-label={ariaLabel} className="space-y-1">
361
+ {shown.map((id, n) => {
362
+ const item = byId.get(id)
363
+ if (!item) return null
364
+ const grabbed = active === id
365
+ return (
366
+ <li
367
+ key={id}
368
+ ref={(el) => {
369
+ if (el) rows.current.set(id, el)
370
+ else rows.current.delete(id)
371
+ }}
372
+ data-id={id}
373
+ data-grabbed={grabbed || undefined}
374
+ className={cx(
375
+ 'flex items-center gap-3 rounded-md border px-3 py-2',
376
+ grabbed && 'bg-accent shadow-sm',
377
+ )}
378
+ >
379
+ <button
380
+ type="button"
381
+ disabled={disabled}
382
+ ref={(el) => {
383
+ if (el) handles.current.set(id, el)
384
+ else handles.current.delete(id)
385
+ }}
386
+ aria-label={labels.handle(textOf(id))}
387
+ aria-describedby={helpId}
388
+ aria-pressed={grabbed}
389
+ data-handle={id}
390
+ className="cursor-grab touch-none select-none px-1 text-muted-foreground"
391
+ onKeyDown={onKeyDown(id)}
392
+ onPointerDown={onPointerDown(id)}
393
+ onBlur={() => {
394
+ if (active === id && mode.current === 'keyboard' && !reordering.current) cancel(id)
395
+ }}
396
+ >
397
+ <span aria-hidden="true">⋮⋮</span>
398
+ </button>
399
+ <span className="w-5 text-xs tabular-nums text-muted-foreground">{n + 1}</span>
400
+ <span className="min-w-0 flex-1">
401
+ <span className="block truncate text-sm font-medium">{item.label}</span>
402
+ {item.description && (
403
+ <span className="block truncate text-xs text-muted-foreground">{item.description}</span>
404
+ )}
405
+ </span>
406
+ {item.actions}
407
+ {switches(item)}
408
+ <StatusBadge status={statusOf(item)} labels={labels} />
409
+ </li>
410
+ )
411
+ })}
412
+ </ol>
413
+ {blocked.length > 0 && (
414
+ <ul aria-label={labels.unavailableGroup} className="mt-1 space-y-1">
415
+ {blocked.map((item) => (
416
+ <li
417
+ key={item.id}
418
+ data-id={item.id}
419
+ data-ineligible
420
+ aria-disabled="true"
421
+ className="flex items-center gap-3 rounded-md border border-dashed px-3 py-2 opacity-70"
422
+ >
423
+ <span className="min-w-0 flex-1">
424
+ <span className="block truncate text-sm font-medium">{item.label}</span>
425
+ {item.description && (
426
+ <span className="block truncate text-xs text-muted-foreground">{item.description}</span>
427
+ )}
428
+ </span>
429
+ {item.actions}
430
+ {switches(item)}
431
+ <StatusBadge status={statusOf(item)} labels={labels} />
432
+ </li>
433
+ ))}
434
+ </ul>
435
+ )}
436
+ <div role="status" aria-live="polite" aria-atomic="true" className="sr-only">
437
+ {announce}
438
+ </div>
439
+ </div>
440
+ )
441
+ }
442
+
443
+ function StatusBadge({ status, labels }: { status: ProviderStatus; labels: ProviderSortableListLabels }) {
444
+ return (
445
+ <span
446
+ data-status={status}
447
+ className={cx('shrink-0 rounded-full px-2 py-0.5 text-xs font-medium', BADGE_TONE[status])}
448
+ >
449
+ {labels[status]}
450
+ </span>
451
+ )
452
+ }
@@ -0,0 +1,29 @@
1
+ // Pure reordering helpers for ProviderSortableList: no DOM, no React.
2
+
3
+ /** Move the item at `from` to index `to`; out-of-range or no-op returns the same array. */
4
+ export function moveItem<T>(list: readonly T[], from: number, to: number): T[] {
5
+ if (from < 0 || from >= list.length) return list.slice()
6
+ const target = Math.max(0, Math.min(list.length - 1, to))
7
+ if (target === from) return list.slice()
8
+ const next = list.slice()
9
+ const [item] = next.splice(from, 1)
10
+ next.splice(target, 0, item)
11
+ return next
12
+ }
13
+
14
+ /** Move `id` by `delta` positions within `order` (ids not in `order` are ignored). */
15
+ export function moveId(order: readonly string[], id: string, delta: number): string[] {
16
+ const from = order.indexOf(id)
17
+ if (from < 0) return order.slice()
18
+ return moveItem(order, from, from + delta)
19
+ }
20
+
21
+ /**
22
+ * Index where a dragged item should land given the pointer position and the
23
+ * vertical midpoints of the OTHER rows (document order): 0..midpoints.length.
24
+ */
25
+ export function dropIndexFromPointer(pointerY: number, midpoints: readonly number[]): number {
26
+ let idx = 0
27
+ for (const mid of midpoints) if (pointerY > mid) idx++
28
+ return idx
29
+ }
@@ -20,17 +20,8 @@ export type WidgetKind =
20
20
  /** Grid footprint in a 4-column grid: sm=1, md=2, lg=3, full=4. */
21
21
  export type WidgetSize = 'sm' | 'md' | 'lg' | 'full'
22
22
 
23
- /** Value format applied to the scalar value and to series values. */
24
- export type WidgetFormat = 'number' | 'currency' | 'percent' | 'compact'
25
-
26
- /** Accent color token (theme CSS vars). */
27
- export type WidgetAccent =
28
- | 'emerald'
29
- | 'sky'
30
- | 'violet'
31
- | 'amber'
32
- | 'rose'
33
- | 'slate'
23
+ import type { WidgetAccent, WidgetFormat } from '@asteby/metacore-charts'
24
+ export type { WidgetAccent, WidgetFormat }
34
25
 
35
26
  /** Aggregation kinds for declarative queries. */
36
27
  export type WidgetAggregate = 'count' | 'sum' | 'avg' | 'min' | 'max'
@@ -156,6 +156,7 @@ import { useFlipAnimation } from './use-flip-animation'
156
156
  import { PortalDragOverlay } from './portal-drag-overlay'
157
157
  import { objectLabel } from './dynamic-relation-helpers'
158
158
  import { useMetadataCache } from './metadata-cache'
159
+ import { cacheScope } from './cache-scope'
159
160
  import { useRecordMutationTick } from './use-record-mutation-tick'
160
161
  import { useOptionsResolver } from './use-options-resolver'
161
162
  import { ActivityValueRenderer } from './activity-value-renderer'
@@ -1123,6 +1124,7 @@ function DynamicKanbanBoard({
1123
1124
  } else {
1124
1125
  setLoading(true)
1125
1126
  }
1127
+ const askedScope = cacheScope()
1126
1128
  api
1127
1129
  .get(`/metadata/table/${model}`)
1128
1130
  .then((res) => {
@@ -1130,7 +1132,7 @@ function DynamicKanbanBoard({
1130
1132
  const body = res.data as ApiResponse<TableMetadata>
1131
1133
  if (body.success) {
1132
1134
  setMetadata(body.data)
1133
- cacheMetadata(model, body.data)
1135
+ cacheMetadata(model, body.data, { scope: askedScope })
1134
1136
  }
1135
1137
  })
1136
1138
  .catch((err) => {
@@ -1931,11 +1933,12 @@ function DynamicKanbanBoard({
1931
1933
  setLaneOrderOverride(null)
1932
1934
  try {
1933
1935
  await stageLayout.reset()
1936
+ const askedScope = cacheScope()
1934
1937
  const res = await api.get(`/metadata/table/${model}`)
1935
1938
  const body = res.data as ApiResponse<TableMetadata>
1936
1939
  if (body.success) {
1937
1940
  setMetadata(body.data)
1938
- cacheMetadata(model, body.data)
1941
+ cacheMetadata(model, body.data, { scope: askedScope })
1939
1942
  }
1940
1943
  } catch {
1941
1944
  setLaneOrderOverride(prev)
@@ -2460,11 +2463,12 @@ function DynamicKanbanBoard({
2460
2463
  // The override changes the served label/color/filters — refetch
2461
2464
  // metadata so the board repaints, and reload the cards.
2462
2465
  try {
2466
+ const askedScope = cacheScope()
2463
2467
  const res = await api.get(`/metadata/table/${model}`)
2464
2468
  const body = res.data as ApiResponse<TableMetadata>
2465
2469
  if (body.success) {
2466
2470
  setMetadata(body.data)
2467
- cacheMetadata(model, body.data)
2471
+ cacheMetadata(model, body.data, { scope: askedScope })
2468
2472
  }
2469
2473
  } catch {
2470
2474
  /* keep the current metadata on a refetch miss */
@@ -2474,11 +2478,12 @@ function DynamicKanbanBoard({
2474
2478
  onResetOverride={async (stageKey) => {
2475
2479
  await stageOverrides.reset(stageKey)
2476
2480
  try {
2481
+ const askedScope = cacheScope()
2477
2482
  const res = await api.get(`/metadata/table/${model}`)
2478
2483
  const body = res.data as ApiResponse<TableMetadata>
2479
2484
  if (body.success) {
2480
2485
  setMetadata(body.data)
2481
- cacheMetadata(model, body.data)
2486
+ cacheMetadata(model, body.data, { scope: askedScope })
2482
2487
  }
2483
2488
  } catch {
2484
2489
  /* keep the current metadata on a refetch miss */
@@ -43,6 +43,7 @@ import {
43
43
  import { Plus, Trash2, Pencil, Search } from 'lucide-react'
44
44
  import { useApi } from './api-context'
45
45
  import { useMetadataCache } from './metadata-cache'
46
+ import { cacheScope } from './cache-scope'
46
47
  import { OptionsContext } from './options-context'
47
48
  import { DynamicForm } from './dynamic-form'
48
49
  import { useImageUrl } from './image-url-context'
@@ -338,6 +339,7 @@ function OneToManyRelation({
338
339
  per_page: REL_PAGE_SIZE,
339
340
  }
340
341
  if (debouncedSearch) params.search = debouncedSearch
342
+ const askedScope = cacheScope()
341
343
  const [metaRes, dataRes] = await Promise.all([
342
344
  metadataRef.current ? Promise.resolve(null) : api.get(`/metadata/table/${model}`),
343
345
  api.get(dataEndpoint, { params }),
@@ -345,7 +347,7 @@ function OneToManyRelation({
345
347
  if (metaRes && (metaRes as any).data?.success) {
346
348
  const fresh = (metaRes as { data: ApiResponse<TableMetadata> }).data.data
347
349
  setMetadata(fresh)
348
- cacheMetadata(model, fresh)
350
+ cacheMetadata(model, fresh, { scope: askedScope })
349
351
  }
350
352
  const list = (dataRes as { data: ApiResponse<any[]> }).data
351
353
  setFetchErrorStatus(null)
@@ -742,6 +744,7 @@ function ManyToManyRelation({
742
744
  setLoading(true)
743
745
  try {
744
746
  const params = buildRelationFilterParams(foreignKey, parentId, filters)
747
+ const askedScope = cacheScope()
745
748
  const tasks: Promise<unknown>[] = [
746
749
  api.get(pivotPath, { params }),
747
750
  ]
@@ -759,7 +762,7 @@ function ManyToManyRelation({
759
762
  const metaRes = results[cursor++] as { data: ApiResponse<TableMetadata> }
760
763
  if (metaRes.data?.success) {
761
764
  setTargetMeta(metaRes.data.data)
762
- cacheMetadata(references, metaRes.data.data)
765
+ cacheMetadata(references, metaRes.data.data, { scope: askedScope })
763
766
  }
764
767
  }
765
768
  if (!useResolver) {