basalt-ui 2.13.2 → 2.14.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 (143) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/MIGRATING.md +40 -12
  3. package/dist/agent/chat/thread-feed-row.d.ts.map +1 -1
  4. package/dist/agent/chat/thread-feed-row.js +2 -2
  5. package/dist/agent/chat/thread-message.d.ts.map +1 -1
  6. package/dist/agent/chat/thread-message.js +2 -2
  7. package/dist/agent/chat/thread-outcome-card.js +2 -2
  8. package/dist/charts/DualPanel.d.ts.map +1 -1
  9. package/dist/charts/DualPanel.js +1 -0
  10. package/dist/charts/compile.d.ts.map +1 -1
  11. package/dist/charts/compile.js +3 -2
  12. package/dist/charts/cursor.d.ts +10 -6
  13. package/dist/charts/cursor.d.ts.map +1 -1
  14. package/dist/charts/cursor.js +20 -13
  15. package/dist/charts/legend.d.ts +5 -4
  16. package/dist/charts/legend.d.ts.map +1 -1
  17. package/dist/charts/legend.js +3 -3
  18. package/dist/charts/panel.d.ts +2 -0
  19. package/dist/charts/panel.d.ts.map +1 -1
  20. package/dist/charts/panel.js +1 -0
  21. package/dist/commands/notifications/center.d.ts.map +1 -1
  22. package/dist/commands/notifications/center.js +2 -11
  23. package/dist/controls/control-name.d.ts +27 -0
  24. package/dist/controls/control-name.d.ts.map +1 -0
  25. package/dist/controls/control-name.js +11 -0
  26. package/dist/controls/enum-filter.d.ts +3 -6
  27. package/dist/controls/enum-filter.d.ts.map +1 -1
  28. package/dist/controls/enum-filter.js +8 -4
  29. package/dist/controls/filter-base.d.ts +30 -0
  30. package/dist/controls/filter-base.d.ts.map +1 -0
  31. package/dist/controls/filter-base.js +0 -0
  32. package/dist/controls/filter-pill.d.ts +3 -1
  33. package/dist/controls/filter-pill.d.ts.map +1 -1
  34. package/dist/controls/filter-pill.js +2 -0
  35. package/dist/controls/filter-sheet.d.ts +0 -32
  36. package/dist/controls/filter-sheet.d.ts.map +1 -1
  37. package/dist/controls/filter-sheet.js +1 -28
  38. package/dist/controls/glyphs.d.ts +12 -0
  39. package/dist/controls/glyphs.d.ts.map +1 -1
  40. package/dist/controls/glyphs.js +23 -2
  41. package/dist/controls/index.d.ts +2 -1
  42. package/dist/controls/index.d.ts.map +1 -1
  43. package/dist/controls/multi-select-filter.d.ts +8 -3
  44. package/dist/controls/multi-select-filter.d.ts.map +1 -1
  45. package/dist/controls/multi-select-filter.js +27 -10
  46. package/dist/controls/number-filter.d.ts +3 -12
  47. package/dist/controls/number-filter.d.ts.map +1 -1
  48. package/dist/controls/number-filter.js +17 -6
  49. package/dist/controls/panel-row.d.ts +5 -8
  50. package/dist/controls/panel-row.d.ts.map +1 -1
  51. package/dist/controls/panel-row.js +3 -0
  52. package/dist/controls/range-filter.d.ts +14 -14
  53. package/dist/controls/range-filter.d.ts.map +1 -1
  54. package/dist/controls/range-filter.js +18 -41
  55. package/dist/controls/search-filter.d.ts +5 -2
  56. package/dist/controls/search-filter.d.ts.map +1 -1
  57. package/dist/controls/search-filter.js +74 -40
  58. package/dist/controls/select-filter.d.ts +2 -15
  59. package/dist/controls/select-filter.d.ts.map +1 -1
  60. package/dist/controls/sync-button.d.ts +0 -6
  61. package/dist/controls/sync-button.d.ts.map +1 -1
  62. package/dist/controls/sync-button.js +6 -36
  63. package/dist/controls/toggle-filter.d.ts +2 -2
  64. package/dist/controls/toggle-filter.d.ts.map +1 -1
  65. package/dist/controls/toggle-filter.js +3 -2
  66. package/dist/controls/view-tabs.d.ts +3 -4
  67. package/dist/controls/view-tabs.d.ts.map +1 -1
  68. package/dist/controls/view-tabs.js +24 -5
  69. package/dist/format/date.d.ts +43 -10
  70. package/dist/format/date.d.ts.map +1 -1
  71. package/dist/format/date.js +109 -18
  72. package/dist/format/index.d.ts +12 -11
  73. package/dist/format/index.d.ts.map +1 -1
  74. package/dist/format/index.js +11 -2
  75. package/dist/format/measure.d.ts +9 -9
  76. package/dist/format/measure.d.ts.map +1 -1
  77. package/dist/format/measure.js +19 -8
  78. package/dist/format/number.d.ts +35 -27
  79. package/dist/format/number.d.ts.map +1 -1
  80. package/dist/format/number.js +41 -20
  81. package/dist/format/shared.d.ts +38 -7
  82. package/dist/format/shared.d.ts.map +1 -1
  83. package/dist/format/shared.js +61 -13
  84. package/dist/provider/create-router.d.ts +9 -4
  85. package/dist/provider/create-router.d.ts.map +1 -1
  86. package/dist/provider/create-router.js +1 -19
  87. package/dist/provider/error-fallback.module.css +4 -15
  88. package/dist/provider/error-fallback.module.css.d.ts +0 -1
  89. package/dist/provider/fallback.module.css +37 -0
  90. package/dist/provider/fallback.module.css.d.ts +11 -0
  91. package/dist/provider/index.d.ts +13 -1
  92. package/dist/provider/index.d.ts.map +1 -1
  93. package/dist/provider/index.js +10 -1
  94. package/dist/provider/route-defaults.d.ts +10 -0
  95. package/dist/provider/route-defaults.d.ts.map +1 -0
  96. package/dist/provider/route-defaults.js +25 -0
  97. package/dist/provider/route-defaults.module.css +39 -0
  98. package/dist/provider/route-defaults.module.css.d.ts +10 -0
  99. package/llms.txt +35 -14
  100. package/package.json +1 -1
  101. package/src/agent/chat/thread-feed-row.tsx +2 -2
  102. package/src/agent/chat/thread-message.tsx +2 -2
  103. package/src/agent/chat/thread-outcome-card.tsx +2 -2
  104. package/src/charts/DualPanel.tsx +1 -0
  105. package/src/charts/compile.ts +3 -2
  106. package/src/charts/cursor.ts +44 -27
  107. package/src/charts/legend.tsx +9 -6
  108. package/src/charts/panel.tsx +3 -0
  109. package/src/commands/notifications/center.tsx +2 -14
  110. package/src/controls/control-name.ts +33 -0
  111. package/src/controls/enum-filter.tsx +29 -27
  112. package/src/controls/filter-base.ts +31 -0
  113. package/src/controls/filter-pill.tsx +4 -0
  114. package/src/controls/filter-sheet.tsx +0 -56
  115. package/src/controls/glyphs.tsx +45 -2
  116. package/src/controls/index.ts +2 -1
  117. package/src/controls/multi-select-filter.tsx +67 -43
  118. package/src/controls/number-filter.tsx +47 -47
  119. package/src/controls/panel-row.tsx +7 -8
  120. package/src/controls/range-filter.tsx +54 -78
  121. package/src/controls/search-filter.tsx +107 -54
  122. package/src/controls/select-filter.tsx +2 -18
  123. package/src/controls/sync-button.tsx +7 -40
  124. package/src/controls/toggle-filter.tsx +9 -7
  125. package/src/controls/view-tabs.tsx +41 -21
  126. package/src/format/date.ts +189 -36
  127. package/src/format/index.ts +12 -11
  128. package/src/format/measure.ts +29 -18
  129. package/src/format/number.ts +76 -37
  130. package/src/format/shared.ts +116 -25
  131. package/src/provider/create-router.tsx +2 -36
  132. package/src/provider/error-fallback.module.css +4 -15
  133. package/src/provider/error-fallback.module.css.d.ts +0 -1
  134. package/src/provider/fallback.module.css +37 -0
  135. package/src/provider/fallback.module.css.d.ts +11 -0
  136. package/src/provider/index.tsx +25 -1
  137. package/src/provider/route-defaults.module.css +39 -0
  138. package/src/provider/route-defaults.module.css.d.ts +10 -0
  139. package/src/provider/route-defaults.tsx +39 -0
  140. package/dist/agent/chat/relative-time.d.ts +0 -27
  141. package/dist/agent/chat/relative-time.d.ts.map +0 -1
  142. package/dist/agent/chat/relative-time.js +0 -27
  143. package/src/agent/chat/relative-time.ts +0 -55
@@ -1,14 +1,11 @@
1
1
  /**
2
2
  * Number formatting — `Intl.NumberFormat` with the arguments already decided, so a caller states
3
3
  * WHAT a number is rather than how to punctuate it. One implementation: the chart layer imports
4
- * `fmtCompact` from here for its default axis format.
5
- *
6
- * `money`/`percent`/`integer`/`compact`/`deltaPct` are the argo-facing names (seeded from
7
- * `features/*\/{formatters,formulas}.ts`); `fmtCurrency`/`fmtPercent`/`fmtInt`/`fmtCompact` are the
8
- * original chart-formatter names, internal since 2.0 and delegated to by the public names.
4
+ * `compact` from here for its default axis format. Every formatter accepts `null | undefined` and
5
+ * prints {@link NON_FINITE} for it (as for `NaN` / `±Infinity`).
9
6
  */
10
- import { NON_FINITE, numberFormat } from './shared'
11
- import type { LocaleOption } from './shared'
7
+ import { isFiniteNumber, NON_FINITE, numberFormat, scaleThousands } from './shared'
8
+ import type { LocaleOption, Numeric } from './shared'
12
9
 
13
10
  export type { LocaleOption }
14
11
  export { NON_FINITE }
@@ -17,23 +14,27 @@ export { NON_FINITE }
17
14
  * prefix that happens to contain one (`HK$`) survives the lowercasing. */
18
15
  const COMPACT_K = /(\d\s?)K/
19
16
 
20
- export type FmtCompactOptions = LocaleOption & {
21
- /** Significant-ish fraction digits on the compacted number. Default 1 (`1.2k`, `3.4M`). */
17
+ /** `negative` hides the sign of `-0` and of a negative that rounds to zero (`-0.4` → `0`). */
18
+ const SIGN: Intl.NumberFormatOptions = { signDisplay: 'negative' }
19
+
20
+ export type CompactOptions = LocaleOption & {
21
+ /** Fraction digits on the compacted number. Default 1 (`1.2k`, `3.4M`). */
22
22
  digits?: number
23
23
  }
24
24
 
25
25
  /**
26
26
  * Compact notation: `1.2k`, `3.4M`, `-820`. The axis formatter for any count whose range spans
27
- * more than three digits. A non-finite value prints {@link NON_FINITE}.
27
+ * more than three digits.
28
28
  *
29
29
  * Note `Intl`'s compact notation is LOCALE text, not a suffix table: `en` gives `1.2K`, and this
30
30
  * lowercases the `K` to match the package's own numeral style while leaving every other locale's
31
31
  * word (`1,2 Mio.`) untouched.
32
32
  */
33
- export function fmtCompact(value: number, options: FmtCompactOptions = {}): string {
34
- if (!Number.isFinite(value)) return NON_FINITE
33
+ export function compact(value: Numeric, options: CompactOptions = {}): string {
34
+ if (!isFiniteNumber(value)) return NON_FINITE
35
35
  const { digits = 1, locale } = options
36
36
  return numberFormat(locale, {
37
+ ...SIGN,
37
38
  notation: 'compact',
38
39
  compactDisplay: 'short',
39
40
  maximumFractionDigits: digits,
@@ -42,7 +43,7 @@ export function fmtCompact(value: number, options: FmtCompactOptions = {}): stri
42
43
  .replace(COMPACT_K, '$1k')
43
44
  }
44
45
 
45
- export type FmtPercentOptions = LocaleOption & {
46
+ export type PercentOptions = LocaleOption & {
46
47
  /** Fraction digits. Default 0 (`42%`). */
47
48
  digits?: number
48
49
  /**
@@ -52,55 +53,93 @@ export type FmtPercentOptions = LocaleOption & {
52
53
  input?: 'ratio' | 'percent'
53
54
  }
54
55
 
55
- /** Percentages, from either a ratio or an already-scaled percentage. A non-finite value prints
56
- * {@link NON_FINITE}. */
57
- export function fmtPercent(value: number, options: FmtPercentOptions = {}): string {
58
- if (!Number.isFinite(value)) return NON_FINITE
56
+ /** Percentages, from either a ratio or an already-scaled percentage. */
57
+ export function percent(value: Numeric, options: PercentOptions = {}): string {
58
+ if (!isFiniteNumber(value)) return NON_FINITE
59
59
  const { digits = 0, input = 'ratio', locale } = options
60
60
  return numberFormat(locale, {
61
+ ...SIGN,
61
62
  style: 'percent',
62
63
  minimumFractionDigits: digits,
63
64
  maximumFractionDigits: digits,
64
65
  }).format(input === 'percent' ? value / 100 : value)
65
66
  }
66
67
 
67
- /** `percent` — the `basalt-ui/format` name for {@link fmtPercent}. */
68
- export const percent = fmtPercent
69
-
70
- export type FmtCurrencyOptions = LocaleOption & {
68
+ export type MoneyOptions = LocaleOption & {
71
69
  /** ISO 4217 code — required. There is no default currency. */
72
70
  currency: string
73
71
  /** Compact notation for the amount (`$1.2k`). Default false. */
74
72
  compact?: boolean
75
- /** Fraction digits. Default 0 compacted, else the currency's own default (`undefined`). */
73
+ /**
74
+ * Fraction digits. Unset → the currency's own default (USD 2, JPY 0) — or, compacted, up to 1.
75
+ * An explicit number (`0`) pins min and max: an opt-in to rounding away the cents.
76
+ */
76
77
  digits?: number
77
78
  }
78
79
 
79
- /** Money. `fmtCurrency(1234, { currency: 'USD' })` → `$1,234`. A non-finite amount prints
80
- * {@link NON_FINITE}. */
81
- export function fmtCurrency(value: number, options: FmtCurrencyOptions): string {
82
- if (!Number.isFinite(value)) return NON_FINITE
80
+ function fractionDigitOptions(
81
+ isCompact: boolean,
82
+ digits: number | undefined,
83
+ ): Intl.NumberFormatOptions {
84
+ if (isCompact) return { minimumFractionDigits: 0, maximumFractionDigits: digits ?? 1 }
85
+ if (digits === undefined) return {}
86
+ return { minimumFractionDigits: digits, maximumFractionDigits: digits }
87
+ }
88
+
89
+ /** Money. `money(12.5, { currency: 'USD' })` → `$12.50`. */
90
+ export function money(value: Numeric, options: MoneyOptions): string {
91
+ if (!isFiniteNumber(value)) return NON_FINITE
83
92
  const { currency, compact: isCompact = false, digits, locale } = options
84
- const fractionDigits = digits ?? (isCompact ? 1 : 0)
85
93
  return numberFormat(locale, {
94
+ ...SIGN,
86
95
  style: 'currency',
87
96
  currency,
88
97
  ...(isCompact && { notation: 'compact', compactDisplay: 'short' }),
89
- minimumFractionDigits: isCompact ? 0 : fractionDigits,
90
- maximumFractionDigits: fractionDigits,
98
+ ...fractionDigitOptions(isCompact, digits),
91
99
  })
92
100
  .format(value)
93
101
  .replace(COMPACT_K, '$1k')
94
102
  }
95
103
 
96
- /** `money` — the `basalt-ui/format` name for {@link fmtCurrency}. */
97
- export const money = fmtCurrency
104
+ /** Grouped integer: `12,480`. Rounds. */
105
+ export function integer(value: Numeric, options: LocaleOption = {}): string {
106
+ if (!isFiniteNumber(value)) return NON_FINITE
107
+ return numberFormat(options.locale, { ...SIGN, maximumFractionDigits: 0 }).format(value)
108
+ }
109
+
110
+ const BYTE_UNITS = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'] as const
111
+
112
+ export type BytesOptions = LocaleOption & {
113
+ /** Max fraction digits. Default 1 (`1.2 MB`). */
114
+ digits?: number
115
+ }
116
+
117
+ /**
118
+ * Byte sizes in DECIMAL (SI) units — `1 kB` is 1000 bytes, the convention of browsers' download
119
+ * UIs, storage vendors and `Intl`'s own `kilobyte`. `bytes(1_200_000)` → `1.2 MB`; below 1000 it
120
+ * prints whole bytes (`512 B`). Negative values keep their sign. The cap is `PB`.
121
+ */
122
+ export function bytes(value: Numeric, options: BytesOptions = {}): string {
123
+ if (!isFiniteNumber(value)) return NON_FINITE
124
+ const { digits = 1, locale } = options
125
+ const { scaled, unit } = scaleThousands(value, digits, BYTE_UNITS.length - 1)
126
+ const text = numberFormat(locale, {
127
+ ...SIGN,
128
+ maximumFractionDigits: unit === 0 ? 0 : digits,
129
+ }).format(scaled)
130
+ return `${text} ${BYTE_UNITS[unit]}`
131
+ }
98
132
 
99
- /** Grouped integer: `12,480`. Rounds. A non-finite value prints {@link NON_FINITE}. */
100
- export function fmtInt(value: number, options: LocaleOption = {}): string {
101
- if (!Number.isFinite(value)) return NON_FINITE
102
- return numberFormat(options.locale, { maximumFractionDigits: 0 }).format(value)
133
+ export type DeltaOptions = LocaleOption & {
134
+ /** Max fraction digits. Default 1 (`+3.2`). */
135
+ digits?: number
103
136
  }
104
137
 
105
- /** `integer` — the `basalt-ui/format` name for {@link fmtInt}. */
106
- export const integer = fmtInt
138
+ /** A signed change: `+3.2`, `-1`, `0`. Zero (and anything that rounds to it) carries no sign. */
139
+ export function delta(value: Numeric, options: DeltaOptions = {}): string {
140
+ if (!isFiniteNumber(value)) return NON_FINITE
141
+ const { digits = 1, locale } = options
142
+ return numberFormat(locale, { signDisplay: 'exceptZero', maximumFractionDigits: digits }).format(
143
+ value,
144
+ )
145
+ }
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Shared low-level pieces of `basalt-ui/format` — the em-dash sentinel and the memoized
3
- * `Intl.NumberFormat` cache every number formatter in this module reuses. Moved here (out of
4
- * `src/charts/utils/format.ts`, C5 consolidation) so the subpath is the single implementation;
5
- * 2.0's chart layer imports it directly (`docs/V2-SPEC.md` § 9).
2
+ * Shared low-level pieces of `basalt-ui/format`: the {@link NON_FINITE} sentinel, the default
3
+ * locale / time zone ({@link defineFormat}), the memoized `Intl` caches and the number-input
4
+ * guard every formatter in this module reuses. The subpath is the single implementation; the chart
5
+ * layer imports it directly (`docs/V2-SPEC.md` § 9).
6
6
  */
7
7
 
8
8
  /**
@@ -12,43 +12,134 @@
12
12
  */
13
13
  export const NON_FINITE = '—'
14
14
 
15
- /** Options every number formatter here accepts. */
15
+ /** Options every number/measure formatter accepts. */
16
16
  export type LocaleOption = {
17
- /** BCP-47 tag. Default `undefined` — the runtime's own locale. */
18
- locale?: string
17
+ /** BCP-47 tag. Default: the {@link defineFormat} default, else the runtime's own locale. */
18
+ locale?: string | undefined
19
+ }
20
+
21
+ export type FormatDefaults = {
22
+ /** BCP-47 tag every formatter uses when a call passes none. */
23
+ locale?: string | undefined
24
+ /** IANA time zone every date formatter uses when a call passes none. */
25
+ timeZone?: string | undefined
19
26
  }
20
27
 
21
28
  /**
22
- * `Intl.NumberFormat` construction is the expensive half of formatting and a chart formats one
23
- * label per tick per frame, so instances are memoized on their own arguments. The key is the
24
- * serialized options because that is exactly what identifies an instance.
29
+ * `Intl` construction is the expensive half of formatting, so instances are memoized per RESOLVED
30
+ * locale (call locale, else the default) — a changed default can never serve a stale instance.
25
31
  */
26
- const formatterCache = new Map<string, Intl.NumberFormat>()
32
+ const numberCaches = new Map<string, Map<string, Intl.NumberFormat>>()
33
+ const dateCaches = new Map<string, Map<string, Intl.DateTimeFormat>>()
27
34
 
28
- export function numberFormat(
35
+ let defaults: FormatDefaults = {}
36
+
37
+ /**
38
+ * Sets the locale / time zone every formatter in `basalt-ui/format` falls back to when a call
39
+ * passes none. Merges: only DEFINED fields are applied, `undefined` leaves the earlier value.
40
+ *
41
+ * The default is ONE module-global per process (formatters are plain functions, not hooks), so it
42
+ * is an app-wide setting, not a per-request one — a server rendering many locales passes `locale`
43
+ * per call instead. `BasaltProvider`'s `locale` / `timeZone` props call this.
44
+ */
45
+ export function defineFormat(next: FormatDefaults = {}): void {
46
+ const merged: FormatDefaults = {
47
+ locale: next.locale ?? defaults.locale,
48
+ timeZone: next.timeZone ?? defaults.timeZone,
49
+ }
50
+ if (merged.locale === defaults.locale && merged.timeZone === defaults.timeZone) return
51
+ defaults = merged
52
+ numberCaches.clear()
53
+ dateCaches.clear()
54
+ }
55
+
56
+ /** Clears the {@link defineFormat} defaults back to the runtime's own locale and zone. */
57
+ export function resetFormatDefaults(): void {
58
+ defaults = {}
59
+ numberCaches.clear()
60
+ dateCaches.clear()
61
+ }
62
+
63
+ /**
64
+ * Cache key: the options' own entries, sorted, joined — no serialization of the whole object per
65
+ * call (a chart formats one label per tick per frame). Option values here are primitives.
66
+ */
67
+ function optionsKey(options: object): string {
68
+ let key = ''
69
+ for (const [name, value] of Object.entries(options).sort(([a], [b]) => (a < b ? -1 : 1))) {
70
+ key += `${name}=${String(value)};`
71
+ }
72
+ return key
73
+ }
74
+
75
+ function memoize<T>(
76
+ caches: Map<string, Map<string, T>>,
29
77
  locale: string | undefined,
30
- options: Intl.NumberFormatOptions,
31
- ): Intl.NumberFormat {
32
- const key = `${locale ?? ''}|${JSON.stringify(options)}`
33
- const cached = formatterCache.get(key)
78
+ options: object,
79
+ create: () => T,
80
+ ): T {
81
+ const localeKey = locale ?? ''
82
+ let cache = caches.get(localeKey)
83
+ if (cache === undefined) {
84
+ cache = new Map()
85
+ caches.set(localeKey, cache)
86
+ }
87
+ const key = optionsKey(options)
88
+ const cached = cache.get(key)
34
89
  if (cached !== undefined) return cached
35
- const created = new Intl.NumberFormat(locale, options)
36
- formatterCache.set(key, created)
90
+ const created = create()
91
+ cache.set(key, created)
37
92
  return created
38
93
  }
39
94
 
40
- const dateFormatterCache = new Map<string, Intl.DateTimeFormat>()
95
+ export function numberFormat(
96
+ locale: string | undefined,
97
+ options: Intl.NumberFormatOptions,
98
+ ): Intl.NumberFormat {
99
+ const resolved = locale ?? defaults.locale
100
+ return memoize(numberCaches, resolved, options, () => new Intl.NumberFormat(resolved, options))
101
+ }
41
102
 
42
103
  export function dateFormat(
43
104
  locale: string | undefined,
44
105
  options: Intl.DateTimeFormatOptions,
45
106
  ): Intl.DateTimeFormat {
46
- const key = `${locale ?? ''}|${JSON.stringify(options)}`
47
- const cached = dateFormatterCache.get(key)
48
- if (cached !== undefined) return cached
49
- const created = new Intl.DateTimeFormat(locale, options)
50
- dateFormatterCache.set(key, created)
51
- return created
107
+ const resolved = locale ?? defaults.locale
108
+ const withZone =
109
+ options.timeZone === undefined && defaults.timeZone !== undefined
110
+ ? { ...options, timeZone: defaults.timeZone }
111
+ : options
112
+ return memoize(dateCaches, resolved, withZone, () => new Intl.DateTimeFormat(resolved, withZone))
113
+ }
114
+
115
+ /** What every number/measure formatter accepts. */
116
+ export type Numeric = number | null | undefined
117
+
118
+ /** True for a finite number; `null`, `undefined`, `NaN` and `±Infinity` are the inputs every
119
+ * number/measure formatter answers with {@link NON_FINITE}. */
120
+ export function isFiniteNumber(value: Numeric): value is number {
121
+ return typeof value === 'number' && Number.isFinite(value)
122
+ }
123
+
124
+ /**
125
+ * Scales `value` down by 1000 per step (up to `maxUnit`) and returns the step. Rounds FIRST, then
126
+ * promotes when the rounded magnitude reaches 1000 — `999.6` at step 0 is `1000` and belongs to
127
+ * the next unit, not `1,000 B`. Step 0 is whole numbers; higher steps round to `digits`.
128
+ */
129
+ export function scaleThousands(
130
+ value: number,
131
+ digits: number,
132
+ maxUnit: number,
133
+ ): { scaled: number; unit: number } {
134
+ let scaled = value
135
+ let unit = 0
136
+ while (unit < maxUnit) {
137
+ const factor = 10 ** (unit === 0 ? 0 : digits)
138
+ if (Math.round(Math.abs(scaled) * factor) / factor < 1000) break
139
+ scaled /= 1000
140
+ unit += 1
141
+ }
142
+ return { scaled, unit }
52
143
  }
53
144
 
54
145
  /** Coerces the flexible `Date | number | string` inputs this module's date formatters accept into
@@ -5,13 +5,12 @@
5
5
  * pending / error / not-found components, and the route view transition (direction from the
6
6
  * `BasaltShell` nav order, V2-SPEC § 5).
7
7
  */
8
- import { Button, Center, Loader, Stack, Text } from '@mantine/core'
9
8
  import type { QueryClient, QueryClientConfig } from '@tanstack/react-query'
10
9
  import { Router, createRouter } from '@tanstack/react-router'
11
- import type { AnyRoute, ErrorComponentProps, RouterHistory } from '@tanstack/react-router'
12
- import { toErrorMessage } from '../common/errors'
10
+ import type { AnyRoute, RouterHistory } from '@tanstack/react-router'
13
11
  import { makeQueryClient } from '../query-client'
14
12
  import type { RouterHook } from '../telemetry'
13
+ import { ErrorComponent, NotFoundComponent, PendingComponent } from './route-defaults'
15
14
  import {
16
15
  guardViewTransitionRejections,
17
16
  routeViewTransition,
@@ -49,39 +48,6 @@ export type BasaltRouter<
49
48
  readonly [basaltRouterBrand]: true
50
49
  }
51
50
 
52
- function PendingComponent() {
53
- return (
54
- <Center py="xl">
55
- <Loader size="sm" />
56
- </Center>
57
- )
58
- }
59
-
60
- function ErrorComponent({ error, reset }: ErrorComponentProps) {
61
- return (
62
- <Stack align="flex-start" gap="xs" p="md">
63
- <Text fw={600}>Something went wrong</Text>
64
- <Text c="dimmed" size="sm">
65
- {toErrorMessage(error)}
66
- </Text>
67
- <Button size="compact-sm" variant="default" onClick={reset}>
68
- Try again
69
- </Button>
70
- </Stack>
71
- )
72
- }
73
-
74
- function NotFoundComponent() {
75
- return (
76
- <Stack gap={4} p="md">
77
- <Text fw={600}>Page not found</Text>
78
- <Text c="dimmed" size="sm">
79
- This address does not match any page.
80
- </Text>
81
- </Stack>
82
- )
83
- }
84
-
85
51
  /** The options `createBasaltRouter` owns. Each is `never` on it: basalt's, not a consumer knob. */
86
52
  type ManagedKeys = Exclude<keyof BasaltRouterOptions, 'context'>
87
53
 
@@ -1,21 +1,10 @@
1
- /* The boundary renders ABOVE MantineProvider, so its fallback is plain HTML styled here — no
2
- Mantine primitive, no inline style object (hidden-inline-style). Tokens only. */
1
+ /* The boundary renders ABOVE MantineProvider, so its fallback is plain HTML styled here and in the
2
+ shared fallback.module.css — no Mantine primitive, no inline style object (hidden-inline-style). */
3
3
  .root {
4
4
  max-width: 32rem;
5
5
  margin: 0 auto;
6
- padding: var(--vx-space-stack-xl);
6
+ padding: var(--vx-space-stack-xl, 2rem);
7
7
  display: flex;
8
8
  flex-direction: column;
9
- gap: var(--vx-space-stack-md);
10
- }
11
-
12
- .reload {
13
- align-self: flex-start;
14
- font: inherit;
15
- cursor: pointer;
16
- padding: var(--vx-space-stack-xs) var(--vx-space-stack-md);
17
- border: 1px solid var(--vx-divider);
18
- border-radius: var(--vx-radius-ctrl);
19
- background: transparent;
20
- color: inherit;
9
+ gap: var(--vx-space-stack-md, 1rem);
21
10
  }
@@ -4,6 +4,5 @@
4
4
  */
5
5
  declare const classes: {
6
6
  readonly root: string
7
- readonly reload: string
8
7
  }
9
8
  export default classes
@@ -0,0 +1,37 @@
1
+ /* The plain-HTML fallback vocabulary shared by RootBoundary's fallback and the router's default
2
+ screens: both render where Mantine may be absent, so neither can use a Mantine primitive. Every
3
+ --vx-* read carries a literal fallback, so they look right with the provider, with only
4
+ tokens.css, or with nothing. */
5
+ .stack {
6
+ display: flex;
7
+ flex-direction: column;
8
+ align-items: flex-start;
9
+ gap: var(--vx-space-stack-xs, 0.5rem);
10
+ padding: var(--vx-space-stack-md, 1rem);
11
+ }
12
+
13
+ .title {
14
+ margin: 0;
15
+ font-weight: 600;
16
+ }
17
+
18
+ .text {
19
+ margin: 0;
20
+ font-size: var(--vx-text-sm, 0.875rem);
21
+ color: var(--vx-ink2, inherit);
22
+ }
23
+
24
+ .action {
25
+ align-self: flex-start;
26
+ min-width: 2.75rem;
27
+ min-height: 2.75rem;
28
+ font: inherit;
29
+ font-size: var(--vx-text-sm, 0.875rem);
30
+ cursor: pointer;
31
+ padding: 0.25rem var(--vx-space-stack-md, 0.75rem);
32
+ border: 1px solid currentColor;
33
+ border: 1px solid var(--vx-divider, color-mix(in srgb, currentColor 25%, transparent));
34
+ border-radius: var(--vx-radius-ctrl, 6px);
35
+ background: transparent;
36
+ color: inherit;
37
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
3
+ * signature — so dot access stays verbatim under the package's strict flags.
4
+ */
5
+ declare const classes: {
6
+ readonly stack: string
7
+ readonly title: string
8
+ readonly text: string
9
+ readonly action: string
10
+ }
11
+ export default classes
@@ -22,6 +22,7 @@ import type { AnyRouter } from '@tanstack/react-router'
22
22
  import { Component, Suspense, lazy, useEffect, useMemo, useRef, useState } from 'react'
23
23
  import type { ErrorInfo, ReactNode } from 'react'
24
24
  import fallbackClasses from './error-fallback.module.css'
25
+ import sharedFallback from './fallback.module.css'
25
26
  import { cssVariablesResolver } from '../theme'
26
27
  import { useLabTheme } from './lab-theme'
27
28
  import { buildDensityCss, buildFontsCss, buildPaletteCss, buildRadiusCss } from '../tokens/core'
@@ -31,6 +32,8 @@ import { buildPaletteData } from '../tokens/palette'
31
32
  import { useMediaQuery } from '../common/use-media-query'
32
33
  import { registerColorSchemeSetter } from '../commands/shell-bridge'
33
34
  import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
35
+ import { defineFormat } from '../format/shared'
36
+ import type { FormatDefaults } from '../format/shared'
34
37
  import { PageTitle } from '../shell/page-title'
35
38
  import { SizeClassHintContext } from '../shell/use-size-class'
36
39
  import type { SizeClass } from '../shell/use-size-class'
@@ -97,6 +100,18 @@ type BasaltProviderCommonProps = {
97
100
  * action wiring mounts.
98
101
  */
99
102
  spotlight?: boolean
103
+ /**
104
+ * Default BCP-47 locale for every `basalt-ui/format` formatter that gets no per-call `locale`
105
+ * (`integer(1112)` → `1,112` under `en-US`). App-level config, static for the provider's
106
+ * lifetime: it sets ONE module-global default per process (formatters are plain functions, not
107
+ * hooks) and a per-call `locale` is the override. An unset prop LEAVES the current default in
108
+ * place (it never resets it), and changing the prop at runtime does not re-render formatted
109
+ * children.
110
+ */
111
+ locale?: string
112
+ /** Default IANA time zone for the date/time formatters; same lifecycle as `locale`. Unset leaves
113
+ * the current default (initially the runtime's zone). */
114
+ timeZone?: string
100
115
  } & Omit<MantineProviderProps, 'children' | 'theme' | 'defaultColorScheme' | 'cssVariablesResolver'>
101
116
 
102
117
  /**
@@ -142,7 +157,7 @@ function DefaultErrorFallback(): ReactNode {
142
157
  />
143
158
  <button
144
159
  type="button"
145
- className={fallbackClasses.reload}
160
+ className={sharedFallback.action}
146
161
  onClick={() => window.location.reload()}
147
162
  >
148
163
  Reload page
@@ -481,12 +496,21 @@ export function BasaltProvider({
481
496
  sizeClassHint = 'compact',
482
497
  navCommandLabel,
483
498
  spotlight = true,
499
+ locale,
500
+ timeZone,
484
501
  router: mountedRouter,
485
502
  children,
486
503
  ...rest
487
504
  }: BasaltProviderProps) {
488
505
  useDuplicateProviderGuard()
489
506
  useHostAttribute()
507
+ // Applied during render so the first formatted child already sees it; only when a prop changed,
508
+ // and only the props received (an unset one leaves an earlier value or a manual `defineFormat`).
509
+ const appliedFormat = useRef<FormatDefaults>({})
510
+ if (appliedFormat.current.locale !== locale || appliedFormat.current.timeZone !== timeZone) {
511
+ appliedFormat.current = { locale, timeZone }
512
+ defineFormat({ locale, timeZone })
513
+ }
490
514
 
491
515
  // The sink is read through a ref, so an inline `telemetry` function does not re-subscribe.
492
516
  const sink = telemetry ?? (process.env.NODE_ENV === 'production' ? undefined : devConsoleSink)
@@ -0,0 +1,39 @@
1
+ /* The router's default screens render at the route that failed, which can be ABOVE BasaltProvider.
2
+ Shared stack/title/text/action live in fallback.module.css; same literal-fallback rule. */
3
+ .center {
4
+ display: flex;
5
+ justify-content: center;
6
+ padding: var(--vx-space-stack-xl, 2rem) 0;
7
+ }
8
+
9
+ .spinner {
10
+ width: 1.25rem;
11
+ height: 1.25rem;
12
+ border: 2px solid currentColor;
13
+ border-top-color: currentColor;
14
+ border: 2px solid color-mix(in srgb, currentColor 20%, transparent);
15
+ border-top-color: var(--vx-accent, currentColor);
16
+ border-radius: 50%;
17
+ animation: spin 0.8s linear infinite;
18
+ }
19
+
20
+ @keyframes spin {
21
+ to {
22
+ transform: rotate(360deg);
23
+ }
24
+ }
25
+
26
+ /* A static ring is still a loading mark; the aria-label carries the state. */
27
+ @media (prefers-reduced-motion: reduce) {
28
+ .spinner {
29
+ animation: none;
30
+ }
31
+ }
32
+
33
+ /* Not-found is a statement, not an error with an action: its own column, no flex-start alignment. */
34
+ .notFound {
35
+ display: flex;
36
+ flex-direction: column;
37
+ gap: 4px;
38
+ padding: var(--vx-space-stack-md, 1rem);
39
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Typed CSS-module declaration (the S4 CSS-modules path). Named string props — not an index
3
+ * signature — so dot access stays verbatim under the package's strict flags.
4
+ */
5
+ declare const classes: {
6
+ readonly center: string
7
+ readonly spinner: string
8
+ readonly notFound: string
9
+ }
10
+ export default classes
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The router's default pending / error / not-found screens. Provider-free on purpose: a route's
3
+ * screen renders at the route that failed, which can sit above `BasaltProvider` (a root-level error,
4
+ * or a pathless-layout provider), so no Mantine primitive. Wired by `createBasaltRouter`.
5
+ */
6
+ import type { ErrorComponentProps } from '@tanstack/react-router'
7
+ import { toErrorMessage } from '../common/errors'
8
+ import fallback from './fallback.module.css'
9
+ import classes from './route-defaults.module.css'
10
+
11
+ export function PendingComponent() {
12
+ return (
13
+ <div className={classes.center}>
14
+ <output className={classes.spinner} aria-label="Loading" />
15
+ </div>
16
+ )
17
+ }
18
+
19
+ // No log here: `defaultOnCatch` (create-router.tsx) already reports every route error.
20
+ export function ErrorComponent({ error, reset }: ErrorComponentProps) {
21
+ return (
22
+ <div className={fallback.stack} role="alert">
23
+ <p className={fallback.title}>Something went wrong</p>
24
+ <p className={fallback.text}>{toErrorMessage(error)}</p>
25
+ <button type="button" className={fallback.action} onClick={reset}>
26
+ Try again
27
+ </button>
28
+ </div>
29
+ )
30
+ }
31
+
32
+ export function NotFoundComponent() {
33
+ return (
34
+ <div className={classes.notFound}>
35
+ <p className={fallback.title}>Page not found</p>
36
+ <p className={fallback.text}>This address does not match any page.</p>
37
+ </div>
38
+ )
39
+ }