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
@@ -26,6 +26,10 @@
26
26
  * import { DateRangePicker } from 'basalt-ui/controls-dates'
27
27
  * // range: field.range({ presets: ['7d', '30d', '90d', 'ytd'], fallback: '30d', custom: true })
28
28
  * <RangeFilter field={analytics.field.range} customPicker={DateRangePicker} />
29
+ *
30
+ * @example
31
+ * // range: field.range({ presets: ['7d', '30d'], fallback: '30d' }) — no `custom`, no picker
32
+ * <RangeFilter field={analytics.field.range} />
29
33
  */
30
34
  import { SegmentedControl, Select, Stack } from '@mantine/core'
31
35
  import { useEffect, useRef, useState } from 'react'
@@ -35,9 +39,10 @@ import type { FieldHandle } from '../state'
35
39
  import type { RangeField, RangeValue } from '../state/fields'
36
40
  import classes from './controls.module.css'
37
41
  import { useFilterRegistration, useFilterSurface } from './filter-context'
42
+ import type { FilterBase } from './filter-base'
38
43
  import { FilterPill } from './filter-pill'
39
44
  import { CalendarGlyph } from './glyphs'
40
- import { useControlName } from './filter-sheet'
45
+ import { useControlName } from './control-name'
41
46
  import { PanelRow } from './panel-row'
42
47
  import type { UncontrolledProps } from './uncontrolled'
43
48
 
@@ -49,28 +54,6 @@ const CUSTOM_ROW_LABEL = 'Custom range…'
49
54
  /** `7d`, `30d`, `24h`, `90` — a label the mono numeric treatment is for. */
50
55
  const NUMERIC_LABEL = /^\d/
51
56
 
52
- /** Once per label — a filter renders on every navigation, and the wiring is fixed at definition. */
53
- const noPickerWarned = new Set<string>()
54
-
55
- /**
56
- * Dev-only: the field declares `custom: true` and no picker was injected, so the custom window is
57
- * unreachable — the popover shows presets only and the sheet's `Custom range…` row never renders.
58
- * A warning rather than a type error: `custom: true` with presets only is a legal (and tested)
59
- * configuration, and the picker is INJECTED precisely because `@mantine/dates` may be absent, so
60
- * the type cannot tell "deliberately preset-only" from "forgot the import".
61
- */
62
- function warnCustomWithoutPicker(label: string, unreachable: boolean): void {
63
- if (!unreachable || process.env.NODE_ENV === 'production' || noPickerWarned.has(label)) return
64
- noPickerWarned.add(label)
65
- // oxlint-disable-next-line no-console -- a dev-time wiring warning has no other channel
66
- console.warn(
67
- `[basalt-ui] RangeFilter('${label}'): the field declares \`custom: true\` but no ` +
68
- '`customPicker` was injected, so the custom window cannot be reached. Pass ' +
69
- '`customPicker={DateRangePicker}` (`basalt-ui/controls-dates`), or drop `custom: true` from ' +
70
- 'the field. (dev only)',
71
- )
72
- }
73
-
74
57
  /**
75
58
  * The contract a custom-range picker satisfies — `basalt-ui/controls-dates`' `DateRangePicker`, or a
76
59
  * consumer's own. Dates are ISO (`YYYY-MM-DD`), the same shape `field.range` stores and
@@ -82,53 +65,48 @@ export type RangeCustomPickerProps = {
82
65
  }
83
66
 
84
67
  /** Everything about the props that does not depend on the field's `custom` flag. */
85
- type RangeFilterBase<P extends string, C extends boolean> = UncontrolledProps & {
86
- /**
87
- * A range handle from either store factory. Generic over the field's `custom` flag so a
88
- * `field.range({ ... })` WITHOUT `custom` (whose handle is `RangeField<P, false>`, and whose
89
- * values therefore never include `'custom'`) binds with no cast — pinning `C` to its default
90
- * `boolean` here made the setter contravariantly incompatible and forced one at every call site.
91
- */
92
- readonly field: FieldHandle<RangeField<P, C>>
93
- /** Leading pill icon. Defaults to a calendar glyph — a range filter reads as a date control, so
94
- * the glyph is part of the control's identity, not a per-call-site decision. */
95
- readonly icon?: ReactNode
96
- /** Sheet-form heading. The pill's own label is the VALUE, which is what a bar reads. @default 'Range' */
97
- readonly label?: string
98
- }
68
+ type RangeFilterCommon<P extends string, C extends boolean> = UncontrolledProps &
69
+ Omit<FilterBase, 'clearable' | 'label'> & {
70
+ /** Sheet-form heading. The pill's own label is the VALUE, which is what a bar reads. @default 'Range' */
71
+ readonly label?: string
72
+ /**
73
+ * A range handle from either store factory. Generic over the field's `custom` flag so a
74
+ * `field.range({ ... })` WITHOUT `custom` (whose handle is `RangeField<P, false>`, and whose
75
+ * values therefore never include `'custom'`) binds with no cast — pinning `C` to its default
76
+ * `boolean` here made the setter contravariantly incompatible and forced one at every call site.
77
+ */
78
+ readonly field: FieldHandle<RangeField<P, C>>
79
+ }
99
80
 
100
- export type RangeFilterProps<P extends string, C extends boolean = boolean> = RangeFilterBase<
81
+ /**
82
+ * `customPicker` is REQUIRED exactly when the field is `custom: true` and FORBIDDEN otherwise, so
83
+ * the unreachable-affordance state (a custom window nobody can pick) is a type error instead of a
84
+ * dev warning. A widened handle (`C = boolean`) cannot say which, so it must supply the picker.
85
+ */
86
+ export type RangeFilterProps<P extends string, C extends boolean = boolean> = RangeFilterCommon<
101
87
  P,
102
88
  C
103
- > & {
104
- /**
105
- * Rendered when the field declares `custom: true`. Omitted → presets only, which stays LEGAL
106
- * (a range that only ever shows presets is a real configuration) but warns once in dev when the
107
- * field allows a custom window: the affordance is then unreachable, and nothing else says so.
108
- */
109
- readonly customPicker?: ComponentType<RangeCustomPickerProps>
110
- }
89
+ > &
90
+ ([C] extends [false]
91
+ ? { readonly customPicker?: never }
92
+ : { readonly customPicker: ComponentType<RangeCustomPickerProps> })
111
93
 
112
94
  export function RangeFilter<P extends string, C extends boolean = boolean>(
113
95
  props: RangeFilterProps<P, C>,
96
+ ): ReactNode
97
+ // The implementation signature is the widest arm, picker optional; the overload above is the only
98
+ // one a caller sees.
99
+ export function RangeFilter<P extends string>(
100
+ props: Omit<RangeFilterProps<P, boolean>, 'customPicker'> & {
101
+ readonly customPicker?: ComponentType<RangeCustomPickerProps> | undefined
102
+ },
114
103
  ): ReactNode {
115
104
  // F-ERR-1 — without this a missing `field` surfaces as `undefined is not an object
116
105
  // (evaluating 'field.use')`, caught by `RootBoundary`.
117
106
  assertRequiredProps('RangeFilter', props, ['field'], {
118
107
  field: 'bind it to a store field (`store.field.<name>`), never a value/onChange pair.',
119
108
  })
120
- const {
121
- field,
122
- icon,
123
- customPicker,
124
- label = 'Range',
125
- className,
126
- style,
127
- // One cast, at the one boundary a generic `C` cannot be read through: `C` only ever describes
128
- // the FIELD's custom flag, and the body handles both.
129
- } = props as unknown as RangeFilterBase<P, boolean> & {
130
- readonly customPicker?: ComponentType<RangeCustomPickerProps>
131
- }
109
+ const { field, icon, disabled, customPicker: Picker, label = 'Range', className, style } = props
132
110
  const [value, setValue] = field.use()
133
111
  const surface = useFilterSurface()
134
112
  const isDefault = field.isDefault(value)
@@ -142,8 +120,6 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
142
120
  const numeric = presets.length > 0 && presets.every((option) => NUMERIC_LABEL.test(option.label))
143
121
  const inSheet = surface === 'sheet'
144
122
  const inPanel = surface === 'panel'
145
- const Picker = customPicker
146
- warnCustomWithoutPicker(label, allowsCustom && Picker === undefined)
147
123
  // The track is a `radiogroup`; without this it announces unnamed, and the pill it hangs off reads
148
124
  // the VALUE (`30d`), not the filter.
149
125
  const { labelId, nameProps } = useControlName(label, inSheet || inPanel)
@@ -163,7 +139,18 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
163
139
  seenPreset.current = value.preset
164
140
  setCustomOpen(value.preset === 'custom')
165
141
  }, [value.preset])
166
- const showPicker = allowsCustom && Picker !== undefined
142
+ const picker =
143
+ allowsCustom && Picker !== undefined ? (
144
+ <Picker
145
+ value={{ from: value.from, to: value.to }}
146
+ onChange={({ from, to }) => {
147
+ // The injected picker cannot be disabled through its props, so a disabled filter drops
148
+ // what it reports instead.
149
+ if (disabled === true) return
150
+ setValue({ preset: 'custom', from, to } as RangeValue<P | 'custom'>)
151
+ }}
152
+ />
153
+ ) : null
167
154
 
168
155
  // The sheet form is the panel form (`docs/CONTROLS-SPEC.md` §3: "sheet = panel rows inside a
169
156
  // Drawer") — one `Select` holding the presets plus a `Custom range…` row, which reveals the same
@@ -181,13 +168,14 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
181
168
  <Select
182
169
  {...nameProps}
183
170
  allowDeselect={false}
171
+ {...(disabled === true && { disabled: true })}
184
172
  // `customOpen` is what the row reads while the picker is open but no window has been
185
173
  // picked yet — selecting `Custom range…` reveals the calendar, it does not write a
186
174
  // half-built `{ preset: 'custom' }` the codec would have to guess at.
187
175
  value={customOpen ? 'custom' : value.preset}
188
176
  data={[
189
177
  ...presets.map((option) => ({ value: option.value, label: option.label })),
190
- ...(showPicker ? [{ value: 'custom', label: CUSTOM_ROW_LABEL }] : []),
178
+ ...(picker !== null ? [{ value: 'custom', label: CUSTOM_ROW_LABEL }] : []),
191
179
  ]}
192
180
  onChange={(next) => {
193
181
  if (next === null) return
@@ -201,14 +189,7 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
201
189
  setValue({ preset: next } as RangeValue<P | 'custom'>)
202
190
  }}
203
191
  />
204
- {showPicker && customOpen && (
205
- <Picker
206
- value={{ from: value.from, to: value.to }}
207
- onChange={({ from, to }) => {
208
- setValue({ preset: 'custom', from, to } as RangeValue<P | 'custom'>)
209
- }}
210
- />
211
- )}
192
+ {customOpen && picker}
212
193
  </PanelRow>
213
194
  )
214
195
  }
@@ -218,6 +199,7 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
218
199
  <SegmentedControl
219
200
  {...nameProps}
220
201
  size="ctl"
202
+ {...(disabled === true && { disabled: true })}
221
203
  orientation={presets.length >= VERTICAL_FROM ? 'vertical' : 'horizontal'}
222
204
  value={value.preset}
223
205
  data={presets.map((option) => ({ value: option.value, label: option.label }))}
@@ -228,14 +210,7 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
228
210
  setValue({ preset: next } as RangeValue<P | 'custom'>)
229
211
  }}
230
212
  />
231
- {showPicker && (
232
- <Picker
233
- value={{ from: value.from, to: value.to }}
234
- onChange={({ from, to }) => {
235
- setValue({ preset: 'custom', from, to } as RangeValue<P | 'custom'>)
236
- }}
237
- />
238
- )}
213
+ {picker}
239
214
  </Stack>
240
215
  )
241
216
 
@@ -244,6 +219,7 @@ export function RangeFilter<P extends string, C extends boolean = boolean>(
244
219
  label={rangeLabel(value, options)}
245
220
  active={!isDefault}
246
221
  numeric={numeric && value.preset !== 'custom'}
222
+ {...(disabled === true && { disabled: true })}
247
223
  icon={icon ?? <CalendarGlyph />}
248
224
  {...(className !== undefined && { className })}
249
225
  {...(style !== undefined && { style })}
@@ -6,33 +6,42 @@
6
6
  * Keystrokes are DEBOUNCED (200ms) before they reach the field. `field.string()` already writes with
7
7
  * `history: 'replace'`, so an un-debounced input would still not stack history entries — what the
8
8
  * debounce buys is one navigation per phrase instead of one per character, which is the difference
9
- * between a typed query and a re-rendered route tree eight times over.
9
+ * between a typed query and a re-rendered route tree eight times over. The pending phrase is
10
+ * committed at once on Enter and blur, and on unmount while the store still holds the value the
11
+ * draft was based on, so a query submitted, tabbed away from or navigated away from inside the
12
+ * window is never lost.
10
13
  *
11
14
  * @example
12
15
  * // q: field.string({ max: 120 })
13
16
  * <SearchFilter field={table.field.q} placeholder="Search pages" />
14
17
  */
15
- import { TextInput } from '@mantine/core'
18
+ import { CloseButton, TextInput } from '@mantine/core'
16
19
  import { useDebouncedCallback } from '@mantine/hooks'
17
20
  import { useEffect, useRef, useState } from 'react'
18
21
  import type { ReactNode } from 'react'
22
+ import { useIsomorphicLayoutEffect } from '../common/isomorphic-layout-effect'
19
23
  import { assertRequiredProps } from '../common/validate'
20
24
  import type { FieldHandle } from '../state'
21
25
  import type { StringField } from '../state/fields'
26
+ import { useControlName } from './control-name'
27
+ import type { FilterBase } from './filter-base'
22
28
  import { useFilterRegistration, useFilterSurface } from './filter-context'
23
- import { useControlName } from './filter-sheet'
29
+ import { SearchGlyph } from './glyphs'
24
30
  import { PanelRow } from './panel-row'
25
31
  import type { UncontrolledProps } from './uncontrolled'
26
32
 
27
33
  /** One navigation per typed phrase, not per keystroke. */
28
34
  const DEBOUNCE_MS = 200
29
35
 
30
- export type SearchFilterProps = UncontrolledProps & {
31
- readonly field: FieldHandle<StringField>
32
- readonly placeholder?: string
33
- /** Sheet-form heading. @default 'Search' */
34
- readonly label?: string
35
- }
36
+ export type SearchFilterProps = UncontrolledProps &
37
+ Omit<FilterBase, 'icon' | 'label' | 'clearable'> & {
38
+ readonly field: FieldHandle<StringField>
39
+ readonly placeholder?: string
40
+ /** Sheet-form heading and the accessible name. @default 'Search' */
41
+ readonly label?: string
42
+ /** The clear button shown while the box holds text. @default true */
43
+ readonly clearable?: boolean
44
+ }
36
45
 
37
46
  export function SearchFilter(props: SearchFilterProps): ReactNode {
38
47
  // F-ERR-1 — without this a missing `field` surfaces as `undefined is not an object
@@ -40,40 +49,72 @@ export function SearchFilter(props: SearchFilterProps): ReactNode {
40
49
  assertRequiredProps('SearchFilter', props, ['field'], {
41
50
  field: 'bind it to a store field (`store.field.<name>`), never a value/onChange pair.',
42
51
  })
43
- const { field, placeholder, label = 'Search', className, style } = props
52
+ const {
53
+ field,
54
+ placeholder,
55
+ label = 'Search',
56
+ clearable = true,
57
+ disabled,
58
+ className,
59
+ style,
60
+ } = props
44
61
  const [value, setValue] = field.use()
45
62
  const surface = useFilterSurface()
46
- const draft = useDebouncedField(value, setValue)
47
- useFilterRegistration(!field.isDefault(value), () => {
63
+ const draft = useDebouncedField(value, setValue, () => {
48
64
  field.clear()
49
65
  })
66
+ // One clear for the button and for `Reset all`: both cancel the pending phrase, so an unmount in
67
+ // the same commit as a reset cannot write the stale draft back over it.
68
+ useFilterRegistration(!field.isDefault(value), draft.clear)
50
69
 
51
70
  // `placeholder` is optional and, even when set, stops being the name the moment the user types —
52
71
  // so the name comes from `label`, or from the visible heading when the surface draws one.
53
- const named = surface === 'sheet' || surface === 'panel'
54
- const { labelId, nameProps } = useControlName(label, named)
55
- // The pill form has no wrapping home — the `TextInput` itself is the root, so it takes the class
56
- // directly. The panel/sheet forms wrap it in a home that becomes the root instead.
57
- const isPill = surface !== 'panel' && surface !== 'sheet'
72
+ // The sheet form is the panel form (`docs/CONTROLS-SPEC.md` §3: "sheet = panel rows inside a
73
+ // Drawer"). The pill form has no wrapping home — the `TextInput` itself is the root, so it takes
74
+ // the class directly; the panel/sheet forms wrap it in a home that becomes the root instead.
75
+ const inRow = surface === 'sheet' || surface === 'panel'
76
+ const { labelId, nameProps } = useControlName(label, inRow)
58
77
 
59
78
  const input = (
60
79
  <TextInput
61
80
  {...nameProps}
62
81
  size="ctl"
82
+ type="search"
83
+ enterKeyHint="search"
63
84
  value={draft.value}
64
- leftSection={<SearchIcon />}
85
+ leftSection={<SearchGlyph />}
86
+ rightSectionPointerEvents="all"
87
+ {...(clearable &&
88
+ draft.value !== '' && {
89
+ rightSection: (
90
+ <CloseButton
91
+ size="sm"
92
+ aria-label="Clear search"
93
+ disabled={disabled === true}
94
+ // Keeps focus in the box: a blur here would flush the phrase being cleared.
95
+ onMouseDown={(event) => {
96
+ event.preventDefault()
97
+ }}
98
+ onClick={draft.clear}
99
+ />
100
+ ),
101
+ })}
102
+ {...(disabled === true && { disabled: true })}
65
103
  {...(placeholder !== undefined && { placeholder })}
66
104
  onChange={(event) => {
67
105
  draft.set(event.currentTarget.value)
68
106
  }}
69
- {...(isPill && className !== undefined && { className })}
70
- {...(isPill && style !== undefined && { style })}
107
+ onBlur={draft.flush}
108
+ onKeyDown={(event) => {
109
+ // Enter that confirms an IME candidate is not a submit.
110
+ if (event.key === 'Enter' && !event.nativeEvent.isComposing) draft.flush()
111
+ }}
112
+ {...(!inRow && className !== undefined && { className })}
113
+ {...(!inRow && style !== undefined && { style })}
71
114
  />
72
115
  )
73
116
 
74
- // The sheet form is the panel form (`docs/CONTROLS-SPEC.md` §3: "sheet = panel rows inside a
75
- // Drawer") — the same `PanelRow` label-above-control row on both surfaces.
76
- if (surface === 'panel' || surface === 'sheet') {
117
+ if (inRow) {
77
118
  return (
78
119
  <PanelRow
79
120
  label={label}
@@ -89,28 +130,48 @@ export function SearchFilter(props: SearchFilterProps): ReactNode {
89
130
  }
90
131
 
91
132
  /**
92
- * A local draft that lands on the field `DEBOUNCE_MS` after the last keystroke, and that follows the
93
- * field when it changes from OUTSIDE the input (`Reset all`, a back navigation, a deep link).
94
- * `seen` is what separates the two directions: it holds the last value this hook itself committed,
95
- * so an incoming change it did not cause is the only thing that overwrites the draft.
133
+ * A local draft that lands on the field `DEBOUNCE_MS` after the last keystroke — or at once, via
134
+ * `flush` (Enter, blur) — and that follows the field when it changes from OUTSIDE the input
135
+ * (`Reset all`, a back navigation, a deep link).
136
+ *
137
+ * `seen` is what separates the two directions: it is the last value the store is known to hold —
138
+ * written synchronously by this hook's own commits, adopted from the store otherwise — so an
139
+ * incoming change it did not cause is the only thing that overwrites the draft.
96
140
  */
97
141
  function useDebouncedField(
98
142
  value: string,
99
143
  setValue: (next: string) => void,
100
- ): { value: string; set: (next: string) => void } {
144
+ clearField: () => void,
145
+ ): { value: string; set: (next: string) => void; flush: () => void; clear: () => void } {
101
146
  const [draft, setDraft] = useState(value)
102
147
  const seen = useRef(value)
103
- const held = useRef(value)
104
- useEffect(() => {
105
- held.current = value
106
- })
107
- const commit = useDebouncedCallback((next: string) => {
108
- // A phrase typed and erased inside the window ends where it began: nothing to write.
109
- if (next === held.current) return
148
+ const rendered = useRef(value)
149
+ const write = (next: string): void => {
110
150
  seen.current = next
111
151
  setValue(next)
152
+ }
153
+ const commit = useDebouncedCallback((next: string) => {
154
+ // A phrase typed and erased inside the window ends where it began: nothing to write.
155
+ if (next === seen.current) return
156
+ write(next)
112
157
  }, DEBOUNCE_MS)
113
158
 
159
+ // Unmount: a layout cleanup runs before Mantine's own passive one cancels the timer. Flush only
160
+ // while the store still holds what the draft was based on — otherwise an outside change (a
161
+ // `Reset all` that also closed this filter) would be overwritten by a stale phrase.
162
+ const commitRef = useRef(commit)
163
+ useEffect(() => {
164
+ rendered.current = value
165
+ commitRef.current = commit
166
+ })
167
+ useIsomorphicLayoutEffect(
168
+ () => () => {
169
+ if (rendered.current === seen.current) commitRef.current.flush()
170
+ else commitRef.current.cancel()
171
+ },
172
+ [],
173
+ )
174
+
114
175
  useEffect(() => {
115
176
  if (seen.current === value) return
116
177
  seen.current = value
@@ -124,24 +185,16 @@ function useDebouncedField(
124
185
  setDraft(next)
125
186
  commit(next)
126
187
  },
188
+ flush: () => {
189
+ commit.flush()
190
+ },
191
+ // Through the field's own `clear()` — it unsets rather than writing the fallback over it — and
192
+ // unconditional: the store may still hold the old phrase, or an unflushed one.
193
+ clear: () => {
194
+ commit.cancel()
195
+ setDraft('')
196
+ seen.current = rendered.current
197
+ clearField()
198
+ },
127
199
  }
128
200
  }
129
-
130
- function SearchIcon(): ReactNode {
131
- return (
132
- <svg
133
- width={16}
134
- height={16}
135
- viewBox="0 0 24 24"
136
- fill="none"
137
- stroke="currentColor"
138
- strokeWidth={2}
139
- strokeLinecap="round"
140
- strokeLinejoin="round"
141
- aria-hidden
142
- >
143
- <circle cx="11" cy="11" r="7" />
144
- <path d="M21 21l-4.35 -4.35" />
145
- </svg>
146
- )
147
- }
@@ -34,26 +34,10 @@ import { assertRequiredProps } from '../common/validate'
34
34
  import type { EnumField, FieldHandle } from '../state'
35
35
  import type { StringField } from '../state/fields'
36
36
  import { EnumFilter } from './enum-filter'
37
+ import type { FilterBase, FilterOption } from './filter-base'
37
38
  import type { UncontrolledProps } from './uncontrolled'
38
39
 
39
- /**
40
- * One row of a runtime catalogue. Wider than the store's own `FieldOption` by exactly one member:
41
- * `disabled` renders the row and refuses the selection, which a declared enum expresses by leaving
42
- * the value out and a live catalogue cannot (an archived project still labels the rows already
43
- * pointing at it).
44
- */
45
- export type FilterOption = {
46
- readonly value: string
47
- readonly label: string
48
- readonly disabled?: boolean
49
- }
50
-
51
- type SelectFilterCommon = UncontrolledProps & {
52
- readonly label: string
53
- readonly icon?: ReactNode
54
- /** Adds a `Clear` action that writes the field back to its fallback. */
55
- readonly clearable?: boolean
56
- }
40
+ type SelectFilterCommon = UncontrolledProps & FilterBase & { readonly label: string }
57
41
 
58
42
  /** A closed enum field: `options` relabels rows the field already declares, so it is optional. */
59
43
  export type SelectFilterEnumProps<T extends string> = SelectFilterCommon & {
@@ -25,7 +25,9 @@ import { useSyncExternalStore } from 'react'
25
25
  import type { ReactNode } from 'react'
26
26
  import { cx } from '../common/props'
27
27
  import type { BasaltProps } from '../common/props'
28
+ import { relativeTime } from '../format'
28
29
  import { IconSlot } from '../theme/icon-slot'
30
+ import { RefreshGlyph } from './glyphs'
29
31
  import classes from './sync-button.module.css'
30
32
 
31
33
  export type SyncButtonProps = BasaltProps & {
@@ -50,20 +52,6 @@ export type SyncButtonProps = BasaltProps & {
50
52
  /** How often the relative age re-renders. One interval, only while mounted. */
51
53
  export const AGE_REFRESH_MS = 30_000
52
54
 
53
- /**
54
- * Relative age, coarse on purpose: a sync indicator answers "is this stale?", not "how stale to
55
- * the second". Anything under a minute is `just now`, so the label stops flickering while a sync
56
- * has just landed.
57
- */
58
- export function formatAge(ms: number): string {
59
- if (ms < 60_000) return 'just now'
60
- const minutes = Math.floor(ms / 60_000)
61
- if (minutes < 60) return `${minutes}m ago`
62
- const hours = Math.floor(minutes / 60)
63
- if (hours < 24) return `${hours}h ago`
64
- return `${Math.floor(hours / 24)}d ago`
65
- }
66
-
67
55
  function toMillis(at: number | Date | null | undefined): number | undefined {
68
56
  if (at === null || at === undefined) return undefined
69
57
  return at instanceof Date ? at.getTime() : at
@@ -75,17 +63,17 @@ function toMillis(at: number | Date | null | undefined): number | undefined {
75
63
  *
76
64
  * The clock is read through `useSyncExternalStore`, whose server snapshot omits the age. A global
77
65
  * `SyncButton` in `globalActions` renders inline in the shell header (no portal), so under SSR the
78
- * server would emit `just now` and a client hydrating a minute later would emit `1m ago` — a React
66
+ * server would emit `now` and a client hydrating a minute later would emit `1 min. ago` — a React
79
67
  * text mismatch that discards the subtree. Server and hydrating paint both omit the age; React
80
68
  * re-renders with the client snapshot right after. The snapshot is the formatted label, a bucketed
81
- * string (`just now`, `1m ago`, …), so it is stable across calls within a bucket and a tick only
69
+ * string (`now`, `1 min. ago`, …), so it is stable across calls within a bucket and a tick only
82
70
  * re-renders when the label changes. With no timestamp there is no subscription and no timer.
83
71
  */
84
72
  function useRelativeAge(at: number | Date | null | undefined): string | undefined {
85
73
  const timestamp = toMillis(at)
86
74
  return useSyncExternalStore(
87
75
  timestamp === undefined ? subscribeNever : subscribeAgeTick,
88
- () => (timestamp === undefined ? undefined : formatAge(Date.now() - timestamp)),
76
+ () => (timestamp === undefined ? undefined : relativeTime(timestamp, { style: 'short' })),
89
77
  () => undefined,
90
78
  )
91
79
  }
@@ -97,27 +85,6 @@ function subscribeAgeTick(onTick: () => void): () => void {
97
85
  return () => clearInterval(id)
98
86
  }
99
87
 
100
- function RefreshGlyph({ spinning }: { spinning: boolean }) {
101
- return (
102
- <svg
103
- width={16}
104
- height={16}
105
- viewBox="0 0 24 24"
106
- fill="none"
107
- aria-hidden
108
- className={spinning ? classes.spin : undefined}
109
- >
110
- <path
111
- d="M20 11a8 8 0 1 0-2.34 5.66M20 5v6h-6"
112
- stroke="currentColor"
113
- strokeWidth={2}
114
- strokeLinecap="round"
115
- strokeLinejoin="round"
116
- />
117
- </svg>
118
- )
119
- }
120
-
121
88
  /**
122
89
  * @example
123
90
  * // page scope — the page's own data
@@ -181,7 +148,7 @@ export function SyncButton({
181
148
  {...(style !== undefined && { style })}
182
149
  >
183
150
  <IconSlot>
184
- <RefreshGlyph spinning={syncing} />
151
+ <RefreshGlyph className={syncing ? classes.spin : undefined} />
185
152
  </IconSlot>
186
153
  </ActionIcon>
187
154
  ) : (
@@ -191,7 +158,7 @@ export function SyncButton({
191
158
  {...(style !== undefined && { style })}
192
159
  leftSection={
193
160
  <IconSlot>
194
- <RefreshGlyph spinning={syncing} />
161
+ <RefreshGlyph className={syncing ? classes.spin : undefined} />
195
162
  </IconSlot>
196
163
  }
197
164
  {...control}
@@ -17,15 +17,16 @@ import { assertRequiredProps } from '../common/validate'
17
17
  import type { FieldHandle } from '../state'
18
18
  import type { BooleanField } from '../state/fields'
19
19
  import { useFilterRegistration, useFilterSurface } from './filter-context'
20
+ import type { FilterBase } from './filter-base'
20
21
  import { FilterPill } from './filter-pill'
21
22
  import { PanelRow } from './panel-row'
22
23
  import type { UncontrolledProps } from './uncontrolled'
23
24
 
24
- export type ToggleFilterProps = UncontrolledProps & {
25
- readonly field: FieldHandle<BooleanField>
26
- readonly label: string
27
- readonly icon?: ReactNode
28
- }
25
+ export type ToggleFilterProps = UncontrolledProps &
26
+ Omit<FilterBase, 'clearable'> & {
27
+ readonly field: FieldHandle<BooleanField>
28
+ readonly label: string
29
+ }
29
30
 
30
31
  export function ToggleFilter(props: ToggleFilterProps): ReactNode {
31
32
  // F-ERR-1 — without this a missing `field` surfaces as `undefined is not an object
@@ -33,7 +34,7 @@ export function ToggleFilter(props: ToggleFilterProps): ReactNode {
33
34
  assertRequiredProps('ToggleFilter', props, ['field'], {
34
35
  field: 'bind it to a store field (`store.field.<name>`), never a value/onChange pair.',
35
36
  })
36
- const { field, label, icon, className, style } = props
37
+ const { field, label, icon, disabled, className, style } = props
37
38
  const [value, setValue] = field.use()
38
39
  const surface = useFilterSurface()
39
40
  const id = useId()
@@ -51,7 +52,7 @@ export function ToggleFilter(props: ToggleFilterProps): ReactNode {
51
52
  end={
52
53
  <Switch
53
54
  id={id}
54
- aria-label={label}
55
+ {...(disabled === true && { disabled: true })}
55
56
  checked={value}
56
57
  onChange={(event) => {
57
58
  setValue(event.currentTarget.checked)
@@ -70,6 +71,7 @@ export function ToggleFilter(props: ToggleFilterProps): ReactNode {
70
71
  active={value}
71
72
  pressed={value}
72
73
  hideGlyph
74
+ {...(disabled === true && { disabled: true })}
73
75
  {...(icon !== undefined && { icon })}
74
76
  onClick={() => {
75
77
  setValue(!value)