@asteby/metacore-runtime-react 50.2.0 → 52.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +26 -0
  3. package/dist/activity-diff.d.ts +5 -0
  4. package/dist/activity-diff.d.ts.map +1 -1
  5. package/dist/activity-timeline.d.ts.map +1 -1
  6. package/dist/activity-timeline.js +10 -3
  7. package/dist/audit-info.d.ts.map +1 -1
  8. package/dist/audit-info.js +17 -3
  9. package/dist/barcode-scanner.js +4 -4
  10. package/dist/dialogs/dynamic-record.d.ts +3 -1
  11. package/dist/dialogs/dynamic-record.d.ts.map +1 -1
  12. package/dist/dialogs/dynamic-record.js +19 -6
  13. package/dist/dynamic-columns.d.ts +6 -0
  14. package/dist/dynamic-columns.d.ts.map +1 -1
  15. package/dist/dynamic-columns.js +41 -7
  16. package/dist/dynamic-date-field.js +1 -1
  17. package/dist/dynamic-form.js +2 -2
  18. package/dist/dynamic-kanban.js +6 -5
  19. package/dist/dynamic-table.d.ts.map +1 -1
  20. package/dist/dynamic-table.js +6 -4
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +2 -1
  24. package/dist/org-runtime-context.d.ts +65 -0
  25. package/dist/org-runtime-context.d.ts.map +1 -1
  26. package/dist/org-runtime-context.js +24 -0
  27. package/dist/org-runtime-provider.d.ts +25 -1
  28. package/dist/org-runtime-provider.d.ts.map +1 -1
  29. package/dist/org-runtime-provider.js +3 -3
  30. package/dist/provenance.d.ts +216 -0
  31. package/dist/provenance.d.ts.map +1 -0
  32. package/dist/provenance.js +386 -0
  33. package/dist/record-history.d.ts.map +1 -1
  34. package/dist/record-history.js +6 -2
  35. package/dist/sidebar-layout-manager.js +2 -2
  36. package/dist/widgets/widget-card.d.ts +7 -2
  37. package/dist/widgets/widget-card.d.ts.map +1 -1
  38. package/dist/widgets/widget-card.js +6 -3
  39. package/package.json +3 -3
  40. package/src/__tests__/org-runtime-number-locale-system-actor.test.tsx +80 -0
  41. package/src/__tests__/provenance.test.tsx +209 -0
  42. package/src/activity-diff.tsx +5 -0
  43. package/src/activity-timeline.tsx +16 -2
  44. package/src/audit-info.tsx +20 -3
  45. package/src/barcode-scanner.tsx +4 -4
  46. package/src/dialogs/dynamic-record.tsx +26 -5
  47. package/src/dynamic-columns.tsx +68 -6
  48. package/src/dynamic-date-field.tsx +1 -1
  49. package/src/dynamic-form.tsx +2 -2
  50. package/src/dynamic-kanban.tsx +6 -5
  51. package/src/dynamic-table.tsx +6 -4
  52. package/src/index.ts +2 -0
  53. package/src/org-runtime-context.ts +92 -0
  54. package/src/org-runtime-provider.tsx +50 -3
  55. package/src/provenance.tsx +585 -0
  56. package/src/record-history.tsx +17 -4
  57. package/src/sidebar-layout-manager.tsx +2 -2
  58. package/src/widgets/widget-card.tsx +26 -3
@@ -12,7 +12,7 @@
12
12
  // column cells are tightly coupled to their design system).
13
13
  import { useEffect, useState, useMemo, useCallback, useRef, type MouseEvent, type ReactNode } from 'react'
14
14
  import { useTranslation } from 'react-i18next'
15
- import { useTimeZone, useCurrency } from './org-runtime-context'
15
+ import { useTimeZone, useCurrency, useNumberLocale } from './org-runtime-context'
16
16
  import { format } from 'date-fns'
17
17
  import type { DateRange } from 'react-day-picker'
18
18
  import { useVirtualizer } from '@tanstack/react-virtual'
@@ -417,6 +417,8 @@ export function DynamicTable({
417
417
  // still selects the mode when `pagination` is absent (back-compat).
418
418
  const infiniteScroll = paginationMode ? paginationMode === 'infinite' : infiniteScrollProp
419
419
  const { t, i18n } = useTranslation()
420
+ // Number/currency locale (org override, e.g. es → es-MX); dates keep i18n.
421
+ const numberLocale = useNumberLocale(i18n.language)
420
422
  const api = useApi()
421
423
  const currentBranch = useCurrentBranch()
422
424
 
@@ -1502,12 +1504,12 @@ export function DynamicTable({
1502
1504
  }
1503
1505
  return actions === viewMetadata.actions ? viewMetadata : { ...viewMetadata, actions }
1504
1506
  })()
1505
- const baseColumns = getDynamicColumns(rowMetadata, handleInternalAction, t, i18n.language, columnFilterConfigs, timeZone, currency, rowActionPredicate)
1507
+ const baseColumns = getDynamicColumns(rowMetadata, handleInternalAction, t, numberLocale, columnFilterConfigs, timeZone, currency, rowActionPredicate)
1506
1508
  const filteredBase = baseColumns.filter((col: ColumnDef<any>) => !effectiveHiddenColumns.includes(col.id as string))
1507
1509
  const actionsCol = filteredBase.find((c: ColumnDef<any>) => c.id === 'actions')
1508
1510
  const otherCols = filteredBase.filter((c: ColumnDef<any>) => c.id !== 'actions')
1509
1511
  return [...otherCols, ...extraColumns, ...(actionsCol ? [actionsCol] : [])]
1510
- }, [viewMetadata, handleInternalAction, effectiveHiddenColumns, allowedActionKeys, extraColumns, t, i18n.language, columnFilterConfigs, getDynamicColumns, timeZone, currency, rowActionPredicate])
1512
+ }, [viewMetadata, handleInternalAction, effectiveHiddenColumns, allowedActionKeys, extraColumns, t, numberLocale, columnFilterConfigs, getDynamicColumns, timeZone, currency, rowActionPredicate])
1511
1513
 
1512
1514
  const filters = useMemo(() => [], [])
1513
1515
 
@@ -1837,7 +1839,7 @@ export function DynamicTable({
1837
1839
  col as any,
1838
1840
  footerTotals[leaf.id],
1839
1841
  currency,
1840
- i18n.language,
1842
+ numberLocale,
1841
1843
  )}
1842
1844
  </TableCell>
1843
1845
  )
package/src/index.ts CHANGED
@@ -370,6 +370,7 @@ export {
370
370
  type SidebarLayoutManagerProps,
371
371
  } from './sidebar-layout-manager'
372
372
  export * from './org-runtime-context'
373
+ export * from './provenance'
373
374
  export * from './business'
374
375
  // Primitivos de negocio (PaymentAllocator, AgingTable, ApprovalInbox,
375
376
  // contribuciones/modales federados, tipos de documento y contratos de paneles).
@@ -439,6 +440,7 @@ export {
439
440
  resolveAvatarSrc,
440
441
  resolveImageSrc,
441
442
  resolveMissingActorLabel,
443
+ isSystemActorColumn,
442
444
  resolveActorDisplayName,
443
445
  resolveRelationLabel,
444
446
  type DynamicColumnsHelpers,
@@ -36,3 +36,95 @@ export const TaxRateContext = createContext<number | undefined>(undefined)
36
36
 
37
37
  /** Reads the nearest org default tax rate (undefined outside a provider). */
38
38
  export const useOrgTaxRate = () => useContext(TaxRateContext)
39
+
40
+ /**
41
+ * Number-locale overrides keyed by UI language: `{ es: 'es-MX' }` makes a
42
+ * Spanish UI format numbers and money the Mexican way (11,461.50) instead of
43
+ * Intl's bare `'es'` (Spain: 11.461,50). Keys match the full language
44
+ * (`'es-mx'`) first, then its base (`'es'`), case-insensitive. `undefined`
45
+ * outside a provider → numbers use the UI language as-is (legacy behaviour).
46
+ */
47
+ export type NumberLocales = Readonly<Record<string, string>>
48
+
49
+ export const NumberLocalesContext = createContext<NumberLocales | undefined>(undefined)
50
+
51
+ /**
52
+ * Pure resolver: the Intl locale numbers should use for `language` given the
53
+ * org's overrides. Returns `language` unchanged when nothing matches.
54
+ */
55
+ export function resolveNumberLocale(
56
+ language: string | undefined,
57
+ locales: NumberLocales | undefined,
58
+ ): string | undefined {
59
+ if (!language || !locales) return language
60
+ const lower = language.toLowerCase()
61
+ const byKey = new Map(Object.entries(locales).map(([k, v]) => [k.toLowerCase(), v]))
62
+ return byKey.get(lower) ?? byKey.get(lower.split('-')[0]) ?? language
63
+ }
64
+
65
+ /**
66
+ * The Intl locale for number/currency formatting of the current UI language
67
+ * (`language`, usually `i18n.language`), honouring the nearest
68
+ * `OrgRuntimeProvider numberLocales`.
69
+ */
70
+ export function useNumberLocale(language: string): string
71
+ export function useNumberLocale(language: string | undefined): string | undefined
72
+ export function useNumberLocale(language: string | undefined): string | undefined {
73
+ return resolveNumberLocale(language, useContext(NumberLocalesContext))
74
+ }
75
+
76
+ /**
77
+ * How the SYSTEM actor (records created or changed by a seed, an event, an
78
+ * agent or an automation — `created_by` empty or `SYSTEM_ACTOR_ID`) is
79
+ * presented: e.g. `{ name: 'Gobi', avatarUrl: '/brand/gobi.png' }`. Read by
80
+ * creator/created_by table cells, AuditInfo, ActivityTimeline, RecordHistory
81
+ * and the record dialog. `undefined` outside a provider → the localized
82
+ * "Sistema"/"System" label and initials (legacy behaviour).
83
+ */
84
+ export interface SystemActor {
85
+ /** Display name (already localized). */
86
+ name?: string
87
+ /** Absolute URL or app path of the avatar image; used as-is. */
88
+ avatarUrl?: string
89
+ }
90
+
91
+ export const SystemActorContext = createContext<SystemActor | undefined>(undefined)
92
+
93
+ /** Reads the nearest system-actor presentation (undefined outside a provider). */
94
+ export const useSystemActor = () => useContext(SystemActorContext)
95
+
96
+ /**
97
+ * How the app's AGENT (its assistant: Gobi in GobiernOS) is presented when a
98
+ * record's provenance says an agent made it or proposed it. Separate from
99
+ * `SystemActor`: unattended platform work (seeds, imports) is not the agent.
100
+ * `undefined` outside a provider → the provenance `actor_name`, else a
101
+ * localized "Asistente"/"Assistant".
102
+ */
103
+ export interface AgentActor {
104
+ /** Display name (already localized). */
105
+ name?: string
106
+ /** Absolute URL or app path of the avatar image; used as-is. */
107
+ avatarUrl?: string
108
+ }
109
+
110
+ export const AgentActorContext = createContext<AgentActor | undefined>(undefined)
111
+
112
+ /** Reads the nearest agent presentation (undefined outside a provider). */
113
+ export const useAgentActor = () => useContext(AgentActorContext)
114
+
115
+ /**
116
+ * Host hook naming the ORIGIN of a record that has no stored provenance but
117
+ * was clearly made by the system (null `created_by_id`): e.g. GobiernOS maps
118
+ * `findings` → "Importación de investigación pública". Return `undefined` when
119
+ * unknown — the badge then shows the system actor alone, never an invented
120
+ * origin.
121
+ */
122
+ export type ProvenanceOriginResolver = (
123
+ model: string | undefined,
124
+ row: Record<string, unknown> | null | undefined,
125
+ ) => string | undefined
126
+
127
+ export const ProvenanceOriginContext = createContext<ProvenanceOriginResolver | undefined>(undefined)
128
+
129
+ /** Reads the nearest origin resolver (undefined outside a provider). */
130
+ export const useProvenanceOrigin = () => useContext(ProvenanceOriginContext)
@@ -1,5 +1,5 @@
1
1
  // OrgRuntimeProvider — one place to feed the org's display config (timezone,
2
- // currency, image-url resolver) to EVERY nested SDK renderer: dynamic tables,
2
+ // currency, number locale, image-url resolver) to EVERY nested SDK renderer: dynamic tables,
3
3
  // relation tables, record dialogs and field cells all read these via context.
4
4
  // The record dialog provides them locally, but standalone surfaces (the
5
5
  // full-page detail view, any table mounted outside a dialog) had no provider,
@@ -12,7 +12,19 @@ import {
12
12
  identityImageUrl,
13
13
  type GetImageUrl,
14
14
  } from './image-url-context'
15
- import { CurrencyContext, TaxRateContext, TimeZoneContext } from './org-runtime-context'
15
+ import {
16
+ AgentActorContext,
17
+ CurrencyContext,
18
+ ProvenanceOriginContext,
19
+ NumberLocalesContext,
20
+ SystemActorContext,
21
+ TaxRateContext,
22
+ TimeZoneContext,
23
+ type AgentActor,
24
+ type NumberLocales,
25
+ type ProvenanceOriginResolver,
26
+ type SystemActor,
27
+ } from './org-runtime-context'
16
28
 
17
29
  export interface OrgRuntimeProviderProps {
18
30
  /** Org IANA timezone (e.g. `America/Mexico_City`). */
@@ -21,6 +33,29 @@ export interface OrgRuntimeProviderProps {
21
33
  currency?: string
22
34
  /** Org default tax rate as a fraction (e.g. `0.16`) for document lines. */
23
35
  taxRate?: number
36
+ /**
37
+ * Number-locale overrides by UI language, e.g. `{ es: 'es-MX' }` so a
38
+ * Spanish UI formats numbers and money as Mexico does (11,461.50). Applies
39
+ * to table cells and footers, kanban cards and lane totals, and the record
40
+ * dialog. Omit to format with the UI language as-is.
41
+ */
42
+ numberLocales?: NumberLocales
43
+ /**
44
+ * Presentation of the system actor (name + avatar) wherever a record shows
45
+ * who created/changed it and nobody did — e.g. `{ name: 'Gobi' }`.
46
+ */
47
+ systemActor?: SystemActor
48
+ /**
49
+ * Presentation of the app's agent (name + avatar) in provenance badges:
50
+ * records an agent made, proposed, or a person made with it — e.g.
51
+ * `{ name: 'Gobi', avatarUrl: '/images/gobi.svg' }`.
52
+ */
53
+ agentActor?: AgentActor
54
+ /**
55
+ * Names the origin of system-made records without stored provenance
56
+ * (legacy rows). Optional; see ProvenanceOriginResolver.
57
+ */
58
+ provenanceOrigin?: ProvenanceOriginResolver
24
59
  /** Resolver turning a stored path into a fetchable URL. Defaults to identity. */
25
60
  getImageUrl?: GetImageUrl
26
61
  children: ReactNode
@@ -30,6 +65,10 @@ export function OrgRuntimeProvider({
30
65
  timeZone,
31
66
  currency,
32
67
  taxRate,
68
+ numberLocales,
69
+ systemActor,
70
+ agentActor,
71
+ provenanceOrigin,
33
72
  getImageUrl = identityImageUrl,
34
73
  children,
35
74
  }: OrgRuntimeProviderProps) {
@@ -38,7 +77,15 @@ export function OrgRuntimeProvider({
38
77
  <TimeZoneContext.Provider value={timeZone}>
39
78
  <CurrencyContext.Provider value={currency}>
40
79
  <TaxRateContext.Provider value={taxRate}>
41
- {children}
80
+ <NumberLocalesContext.Provider value={numberLocales}>
81
+ <SystemActorContext.Provider value={systemActor}>
82
+ <AgentActorContext.Provider value={agentActor}>
83
+ <ProvenanceOriginContext.Provider value={provenanceOrigin}>
84
+ {children}
85
+ </ProvenanceOriginContext.Provider>
86
+ </AgentActorContext.Provider>
87
+ </SystemActorContext.Provider>
88
+ </NumberLocalesContext.Provider>
42
89
  </TaxRateContext.Provider>
43
90
  </CurrencyContext.Provider>
44
91
  </TimeZoneContext.Provider>