basalt-ui 2.27.1 → 2.28.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 (243) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/MIGRATING.md +172 -12
  3. package/agent/rules/basalt-batteries.md +1 -1
  4. package/agent/rules/basalt-mantine.md +1 -1
  5. package/agent/rules/basalt-tokens.md +2 -2
  6. package/agent/skills/basalt-design/SKILL.md +1 -1
  7. package/agent/skills/basalt-design/references/catalogue.md +40 -36
  8. package/agent/skills/basalt-design/references/recipes.md +47 -0
  9. package/configs/oxlint-basalt.json +2 -1
  10. package/configs/oxlint-plugin.js +110 -2
  11. package/configs/oxlint-plugin.test.ts +99 -4
  12. package/dist/agent/chat/thread-message.d.ts +1 -160
  13. package/dist/agent/chat/thread-message.d.ts.map +1 -1
  14. package/dist/agent/chat/thread-message.js +7 -162
  15. package/dist/agent/chat/virtualize.d.ts +5 -5
  16. package/dist/charts/ChartCard.d.ts +5 -2
  17. package/dist/charts/ChartCard.d.ts.map +1 -1
  18. package/dist/charts/ChartCard.js +46 -13
  19. package/dist/charts/Lines.d.ts.map +1 -1
  20. package/dist/charts/Lines.js +11 -4
  21. package/dist/charts/Sparkline.d.ts +9 -2
  22. package/dist/charts/Sparkline.d.ts.map +1 -1
  23. package/dist/charts/Sparkline.js +104 -41
  24. package/dist/charts/chart-box.module.css +69 -3
  25. package/dist/charts/chart-box.module.css.d.ts +5 -0
  26. package/dist/charts/chart-card.module.css +12 -4
  27. package/dist/charts/chart-card.module.css.d.ts +1 -0
  28. package/dist/charts/compile.d.ts.map +1 -1
  29. package/dist/charts/compile.js +21 -19
  30. package/dist/charts/labels.d.ts +13 -3
  31. package/dist/charts/labels.d.ts.map +1 -1
  32. package/dist/charts/labels.js +131 -20
  33. package/dist/charts/legend.d.ts.map +1 -1
  34. package/dist/charts/legend.js +1 -1
  35. package/dist/charts/ref-label.d.ts +31 -8
  36. package/dist/charts/ref-label.d.ts.map +1 -1
  37. package/dist/charts/ref-label.js +40 -9
  38. package/dist/charts/sparkline.module.css +6 -0
  39. package/dist/charts/state.d.ts +3 -3
  40. package/dist/charts/state.d.ts.map +1 -1
  41. package/dist/charts/state.js +20 -2
  42. package/dist/cli/shot/capture.d.ts +6 -1
  43. package/dist/cli/shot/capture.d.ts.map +1 -1
  44. package/dist/cli/shot/capture.js +18 -5
  45. package/dist/common/empty-copy.d.ts +16 -0
  46. package/dist/common/empty-copy.d.ts.map +1 -0
  47. package/dist/common/empty-copy.js +9 -0
  48. package/dist/common/virtual-rows.d.ts +196 -0
  49. package/dist/common/virtual-rows.d.ts.map +1 -0
  50. package/dist/common/virtual-rows.js +290 -0
  51. package/dist/controls/controls.module.css +33 -1
  52. package/dist/controls/controls.module.css.d.ts +2 -0
  53. package/dist/controls/enum-filter.d.ts.map +1 -1
  54. package/dist/controls/enum-filter.js +8 -2
  55. package/dist/controls/filter-pill.d.ts +27 -3
  56. package/dist/controls/filter-pill.d.ts.map +1 -1
  57. package/dist/controls/filter-pill.js +15 -4
  58. package/dist/controls/form-layout.d.ts +9 -3
  59. package/dist/controls/form-layout.d.ts.map +1 -1
  60. package/dist/controls/form-layout.js +74 -12
  61. package/dist/controls/form-layout.module.css +112 -7
  62. package/dist/controls/form-layout.module.css.d.ts +1 -0
  63. package/dist/controls/multi-select-filter.d.ts +2 -2
  64. package/dist/controls/multi-select-filter.d.ts.map +1 -1
  65. package/dist/controls/multi-select-filter.js +12 -6
  66. package/dist/controls/range-filter.d.ts +1 -1
  67. package/dist/controls/range-filter.d.ts.map +1 -1
  68. package/dist/controls/range-filter.js +8 -2
  69. package/dist/dashboard/bar-list.d.ts +1 -1
  70. package/dist/dashboard/bar-list.d.ts.map +1 -1
  71. package/dist/dashboard/bar-list.js +6 -2
  72. package/dist/dashboard/bar-list.module.css +0 -2
  73. package/dist/dashboard/board-nav.d.ts +22 -0
  74. package/dist/dashboard/board-nav.d.ts.map +1 -0
  75. package/dist/dashboard/board-nav.js +49 -0
  76. package/dist/dashboard/board.d.ts +52 -0
  77. package/dist/dashboard/board.d.ts.map +1 -0
  78. package/dist/dashboard/board.js +228 -0
  79. package/dist/dashboard/board.module.css +160 -0
  80. package/dist/dashboard/board.module.css.d.ts +26 -0
  81. package/dist/dashboard/empty-state.d.ts +3 -3
  82. package/dist/dashboard/empty-state.d.ts.map +1 -1
  83. package/dist/dashboard/empty-state.js +13 -6
  84. package/dist/dashboard/event-list-model.d.ts +51 -0
  85. package/dist/dashboard/event-list-model.d.ts.map +1 -0
  86. package/dist/dashboard/event-list-model.js +72 -0
  87. package/dist/dashboard/event-list-rows.d.ts +23 -0
  88. package/dist/dashboard/event-list-rows.d.ts.map +1 -0
  89. package/dist/dashboard/event-list-rows.js +93 -0
  90. package/dist/dashboard/event-list-scroll.d.ts +27 -0
  91. package/dist/dashboard/event-list-scroll.d.ts.map +1 -0
  92. package/dist/dashboard/event-list-scroll.js +103 -0
  93. package/dist/dashboard/event-list-skeleton.d.ts +10 -0
  94. package/dist/dashboard/event-list-skeleton.d.ts.map +1 -0
  95. package/dist/dashboard/event-list-skeleton.js +36 -0
  96. package/dist/dashboard/event-list.d.ts +65 -0
  97. package/dist/dashboard/event-list.d.ts.map +1 -0
  98. package/dist/dashboard/event-list.js +178 -0
  99. package/dist/dashboard/event-list.module.css +283 -0
  100. package/dist/dashboard/event-list.module.css.d.ts +33 -0
  101. package/dist/dashboard/index.d.ts +2 -0
  102. package/dist/dashboard/index.d.ts.map +1 -1
  103. package/dist/dashboard/index.js +4 -0
  104. package/dist/dashboard/meter-parts.d.ts.map +1 -1
  105. package/dist/dashboard/meter-parts.js +5 -3
  106. package/dist/dashboard/meter.module.css +2 -1
  107. package/dist/dashboard/query-state.js +1 -1
  108. package/dist/dashboard/settings-section.d.ts +4 -1
  109. package/dist/dashboard/settings-section.d.ts.map +1 -1
  110. package/dist/dashboard/settings-section.js +1 -1
  111. package/dist/dashboard/settings-section.module.css +19 -4
  112. package/dist/dashboard/stat-card-parts.d.ts +5 -1
  113. package/dist/dashboard/stat-card-parts.d.ts.map +1 -1
  114. package/dist/dashboard/stat-card-parts.js +8 -3
  115. package/dist/dashboard/stat-card.d.ts.map +1 -1
  116. package/dist/dashboard/stat-card.js +26 -7
  117. package/dist/dashboard/stat-card.module.css +31 -7
  118. package/dist/dashboard/stat-card.module.css.d.ts +3 -0
  119. package/dist/dashboard/stat-strip.js +1 -1
  120. package/dist/dashboard/stat-strip.module.css +4 -1
  121. package/dist/dashboard/widget-header.d.ts.map +1 -1
  122. package/dist/dashboard/widget-header.js +15 -2
  123. package/dist/dashboard/widget-header.module.css +17 -1
  124. package/dist/guard/index.d.ts.map +1 -1
  125. package/dist/guard/index.js +2 -0
  126. package/dist/index.d.ts +1 -1
  127. package/dist/index.d.ts.map +1 -1
  128. package/dist/index.js +4 -0
  129. package/dist/shell/app-main.module.css +18 -0
  130. package/dist/styles.css +46 -8
  131. package/dist/surfaces.d.ts +2 -2
  132. package/dist/surfaces.d.ts.map +1 -1
  133. package/dist/surfaces.js +8 -2
  134. package/dist/table/cell-kinds.d.ts +44 -0
  135. package/dist/table/cell-kinds.d.ts.map +1 -0
  136. package/dist/table/cell-kinds.js +169 -0
  137. package/dist/table/cell-kinds.module.css +55 -0
  138. package/dist/table/cell-kinds.module.css.d.ts +15 -0
  139. package/dist/table/data-table-fold.d.ts +147 -0
  140. package/dist/table/data-table-fold.d.ts.map +1 -0
  141. package/dist/table/data-table-fold.js +288 -0
  142. package/dist/table/data-table-state.d.ts +10 -3
  143. package/dist/table/data-table-state.d.ts.map +1 -1
  144. package/dist/table/data-table-state.js +11 -6
  145. package/dist/table/data-table.d.ts +11 -26
  146. package/dist/table/data-table.d.ts.map +1 -1
  147. package/dist/table/data-table.js +354 -254
  148. package/dist/table/data-table.module.css +210 -3
  149. package/dist/table/data-table.module.css.d.ts +12 -0
  150. package/dist/table/table-features.d.ts +34 -4
  151. package/dist/table/table-features.d.ts.map +1 -1
  152. package/dist/table/table-features.js +10 -0
  153. package/dist/theme/card-inset.module.css +35 -0
  154. package/dist/theme/controls.module.css +32 -0
  155. package/dist/theme/ctl-theme.d.ts.map +1 -1
  156. package/dist/theme/ctl-theme.js +5 -0
  157. package/dist/theme/index.d.ts.map +1 -1
  158. package/dist/theme/index.js +14 -10
  159. package/dist/tokens/core.d.ts +1 -0
  160. package/dist/tokens/core.d.ts.map +1 -1
  161. package/dist/tokens/core.js +1 -0
  162. package/dist/tokens/derive.js +1 -1
  163. package/dist/tokens/palette.d.ts +2 -1
  164. package/dist/tokens/palette.d.ts.map +1 -1
  165. package/llms.txt +34 -5
  166. package/package.json +1 -1
  167. package/src/agent/chat/thread-message.tsx +10 -403
  168. package/src/agent/chat/virtualize.ts +5 -5
  169. package/src/charts/ChartCard.tsx +79 -17
  170. package/src/charts/Lines.tsx +13 -4
  171. package/src/charts/Sparkline.tsx +131 -45
  172. package/src/charts/chart-box.module.css +69 -3
  173. package/src/charts/chart-box.module.css.d.ts +5 -0
  174. package/src/charts/chart-card.module.css +12 -4
  175. package/src/charts/chart-card.module.css.d.ts +1 -0
  176. package/src/charts/compile.ts +24 -20
  177. package/src/charts/labels.ts +175 -24
  178. package/src/charts/legend.tsx +3 -2
  179. package/src/charts/ref-label.ts +86 -17
  180. package/src/charts/sparkline.module.css +6 -0
  181. package/src/charts/state.tsx +36 -7
  182. package/src/cli/shot/capture.ts +29 -6
  183. package/src/common/empty-copy.ts +17 -0
  184. package/src/common/virtual-rows.tsx +682 -0
  185. package/src/controls/controls.module.css +33 -1
  186. package/src/controls/controls.module.css.d.ts +2 -0
  187. package/src/controls/enum-filter.tsx +8 -2
  188. package/src/controls/filter-pill.tsx +80 -27
  189. package/src/controls/form-layout.module.css +112 -7
  190. package/src/controls/form-layout.module.css.d.ts +1 -0
  191. package/src/controls/form-layout.tsx +115 -22
  192. package/src/controls/multi-select-filter.tsx +22 -11
  193. package/src/controls/range-filter.tsx +9 -3
  194. package/src/dashboard/bar-list.module.css +0 -2
  195. package/src/dashboard/bar-list.tsx +8 -5
  196. package/src/dashboard/board-nav.ts +67 -0
  197. package/src/dashboard/board.module.css +160 -0
  198. package/src/dashboard/board.module.css.d.ts +26 -0
  199. package/src/dashboard/board.tsx +394 -0
  200. package/src/dashboard/empty-state.tsx +16 -9
  201. package/src/dashboard/event-list-model.ts +113 -0
  202. package/src/dashboard/event-list-rows.tsx +120 -0
  203. package/src/dashboard/event-list-scroll.ts +145 -0
  204. package/src/dashboard/event-list-skeleton.tsx +58 -0
  205. package/src/dashboard/event-list.module.css +283 -0
  206. package/src/dashboard/event-list.module.css.d.ts +33 -0
  207. package/src/dashboard/event-list.tsx +309 -0
  208. package/src/dashboard/index.ts +2 -0
  209. package/src/dashboard/meter-parts.tsx +9 -2
  210. package/src/dashboard/meter.module.css +2 -1
  211. package/src/dashboard/query-state.tsx +1 -1
  212. package/src/dashboard/settings-section.module.css +19 -4
  213. package/src/dashboard/settings-section.tsx +7 -2
  214. package/src/dashboard/stat-card-parts.tsx +20 -3
  215. package/src/dashboard/stat-card.module.css +31 -7
  216. package/src/dashboard/stat-card.module.css.d.ts +3 -0
  217. package/src/dashboard/stat-card.tsx +25 -6
  218. package/src/dashboard/stat-strip.module.css +4 -1
  219. package/src/dashboard/stat-strip.tsx +1 -1
  220. package/src/dashboard/widget-header.module.css +17 -1
  221. package/src/dashboard/widget-header.tsx +29 -5
  222. package/src/guard/index.ts +2 -0
  223. package/src/index.ts +4 -0
  224. package/src/shell/app-main.module.css +18 -0
  225. package/src/styles.css +46 -8
  226. package/src/surfaces.ts +7 -1
  227. package/src/table/cell-kinds.module.css +55 -0
  228. package/src/table/cell-kinds.module.css.d.ts +15 -0
  229. package/src/table/cell-kinds.tsx +234 -0
  230. package/src/table/data-table-fold.tsx +514 -0
  231. package/src/table/data-table-state.ts +24 -13
  232. package/src/table/data-table.module.css +210 -3
  233. package/src/table/data-table.module.css.d.ts +12 -0
  234. package/src/table/data-table.tsx +406 -359
  235. package/src/table/table-features.ts +44 -4
  236. package/src/theme/__snapshots__/plain-theme.test.ts.snap +2 -66
  237. package/src/theme/card-inset.module.css +35 -0
  238. package/src/theme/controls.module.css +32 -0
  239. package/src/theme/ctl-theme.tsx +8 -0
  240. package/src/theme/index.ts +12 -8
  241. package/src/tokens/core.ts +1 -0
  242. package/src/tokens/derive.ts +1 -1
  243. package/src/tokens/palette.ts +4 -1
@@ -0,0 +1,514 @@
1
+ /**
2
+ * The measured column fold and the pinning it feeds (`docs/CONTROLS-SPEC.md` §2, SPEC § 6.6 /
3
+ * § 9.1): which columns fold off a compact table, which one pins when the folded table still
4
+ * overflows, and the toggle, disclosure and sticky-cell props that draw both. `data-table.tsx`
5
+ * composes them; nothing here knows the rest of the table.
6
+ */
7
+ import { Text } from '@mantine/core'
8
+ import type {
9
+ Cell,
10
+ Column,
11
+ ColumnDef,
12
+ Row,
13
+ RowData,
14
+ Table as TanstackTable,
15
+ } from '@tanstack/react-table'
16
+ import type { CSSProperties, ReactNode, RefObject } from 'react'
17
+ import { useLayoutEffect, useRef, useState } from 'react'
18
+ import { HIT_COARSE } from '../common/hit-floor'
19
+ import { useMeasuredWidths } from '../common/use-measured-widths'
20
+ import { alpha, VX } from '../tokens'
21
+ import { CellContent } from './cell-kinds'
22
+ import { EMPTY_FOLD_SET } from './data-table-state'
23
+ import classes from './data-table.module.css'
24
+ import type { BasaltTableFeatures } from './table-features'
25
+
26
+ /** The column id TanStack will resolve internally for this raw def — explicit `id`, else the
27
+ * accessor key string. */
28
+ export function columnDefId<T extends RowData>(
29
+ column: ColumnDef<BasaltTableFeatures, T, unknown>,
30
+ ): string | undefined {
31
+ if (column.id !== undefined) return column.id
32
+ return 'accessorKey' in column && typeof column.accessorKey === 'string'
33
+ ? column.accessorKey
34
+ : undefined
35
+ }
36
+
37
+ /**
38
+ * Fold order for `meta.priority` — the FIRST id in the returned list folds first. Effective
39
+ * priority is `meta.priority ?? declaredIndex`, so with no `meta.priority` set anywhere it is just
40
+ * the column's position: the LAST declared column folds first, the zero-config default a bare
41
+ * `<BasaltDataTable data columns />` needs. An explicit priority folds a HIGHER number before a
42
+ * lower one; a tie folds in reverse declared order. A column with no resolvable id (an
43
+ * `accessorFn` with no explicit `id`) is never a fold candidate — nothing downstream could
44
+ * reliably re-identify it once hidden.
45
+ */
46
+ export function foldOrder<T extends RowData>(
47
+ columns: readonly ColumnDef<BasaltTableFeatures, T, unknown>[],
48
+ ): string[] {
49
+ return columns
50
+ .map((column, index) => ({
51
+ id: columnDefId(column),
52
+ priority: column.meta?.priority ?? index,
53
+ index,
54
+ }))
55
+ .filter((candidate): candidate is { id: string; priority: number; index: number } =>
56
+ Boolean(candidate.id),
57
+ )
58
+ .toSorted((a, b) => b.priority - a.priority || b.index - a.index)
59
+ .map((candidate) => candidate.id)
60
+ }
61
+
62
+ /** Marks a rendered data column header for `useColumnFold`'s width measurement — never read past
63
+ * that hook, so it carries no styling and needs no CSS-module counterpart. */
64
+ export const FOLD_ID_ATTR = 'data-basalt-fold-id'
65
+ /** The same mark on the columns that are never folded but still take room — the checkbox and the
66
+ * row-actions column — so their widths join the plan's overhead. */
67
+ export const FIXED_ID_ATTR = 'data-basalt-fixed-id'
68
+
69
+ /**
70
+ * How many data columns the fold always leaves visible: the identifier plus its most important
71
+ * value (SPEC § 6.6). A one-column table keeps its one.
72
+ */
73
+ const FOLD_FLOOR = 2
74
+
75
+ const EMPTY_WIDTHS: ReadonlyMap<string, number> = new Map()
76
+
77
+ /** The auto-pinned identifier column's width floor, px, when its `columnDef.minSize` is unset. */
78
+ export const PIN_MIN_WIDTH = 120
79
+
80
+ /** The half pixel per measured width plus the room's own rounding — see {@link planColumnFold}. */
81
+ function roundingSlack(measured: number, fixedCount: number): number {
82
+ return (measured + fixedCount + 1) / 2
83
+ }
84
+
85
+ /**
86
+ * Pure decision: fold columns off the FRONT of `order` (already fold-first sorted) until the
87
+ * still-unfolded ones — plus `overhead` (the columns excluded from candidacy altogether — pinned,
88
+ * `enableHiding: false`, the checkbox and actions columns — which occupy room but can never fold)
89
+ * and the disclosure toggle's own width, once anything is folded — fit `room`, or only
90
+ * {@link FOLD_FLOOR} data columns remain (`fixedCount` of them are the excluded data columns).
91
+ * A candidate with no measured width yet (never rendered) is skipped rather than folded blind,
92
+ * since folding it would remove the one place its width could ever be read from.
93
+ *
94
+ * Every width is a rounded integer (`offsetWidth`, `clientWidth`), and a table that fills its
95
+ * wrapper stretches its columns to sum to `room` exactly — so the rounded sum lands up to half a
96
+ * pixel per column over it, and a table that fits folded a column on hydration (a server-painted
97
+ * table whose cells then moved). The fit check forgives that rounding and nothing more: half a
98
+ * pixel for each measured width (the foldable columns, `fixedCount` and `extraCount` — the
99
+ * excluded data columns and the checkbox / actions ones `overhead` sums), plus half a pixel for
100
+ * `room`'s own rounding (the `+ 1` in the slack).
101
+ */
102
+ export function planColumnFold(input: {
103
+ room: number
104
+ toggleWidth: number
105
+ overhead: number
106
+ /** How many excluded DATA columns `overhead` sums: they count toward the floor and the slack. */
107
+ fixedCount?: number
108
+ /** How many non-data columns (checkbox, actions) `overhead` sums: the slack only. */
109
+ extraCount?: number
110
+ order: readonly string[]
111
+ widths: ReadonlyMap<string, number>
112
+ }): ReadonlySet<string> {
113
+ const { room, toggleWidth, overhead, fixedCount = 0, extraCount = 0, order, widths } = input
114
+ const known = order.filter((id) => widths.has(id))
115
+ const slack = roundingSlack(known.length, fixedCount + extraCount)
116
+ let unfolded = overhead + known.reduce((sum, id) => sum + (widths.get(id) ?? 0), 0)
117
+ const folded = new Set<string>()
118
+ for (const id of known) {
119
+ // Never fold below the floor — a table with every column folded has no row identifier left to
120
+ // read at all, which is worse than the horizontal scroll this exists to avoid; one with only
121
+ // the identifier left hides every value. With no explicit `meta.priority` the survivors are
122
+ // `order`'s LAST ids, which `foldOrder`'s own doc pins as the FIRST declared columns (the
123
+ // last-declared one folds first).
124
+ if (known.length - folded.size + fixedCount <= FOLD_FLOOR) break
125
+ const withToggle = unfolded + (folded.size > 0 ? toggleWidth : 0)
126
+ if (withToggle <= room + slack) break
127
+ folded.add(id)
128
+ unfolded -= widths.get(id) ?? 0
129
+ }
130
+ return folded
131
+ }
132
+
133
+ /**
134
+ * Whether what `planColumnFold` left still overflows `room` — the signal to pin the first column
135
+ * and scroll the rest. Computed from the cached NATURAL widths, never the painted ones: pinning
136
+ * caps the identifier's width, and reading that back would unpin the table the moment the cap made
137
+ * it fit, then pin it again at the next measure.
138
+ */
139
+ function foldOverflows(input: {
140
+ room: number
141
+ toggleWidth: number
142
+ overhead: number
143
+ fixedCount: number
144
+ extraCount: number
145
+ order: readonly string[]
146
+ widths: ReadonlyMap<string, number>
147
+ folded: ReadonlySet<string>
148
+ }): boolean {
149
+ const { room, toggleWidth, overhead, fixedCount, extraCount, order, widths, folded } = input
150
+ const known = order.filter((id) => widths.has(id))
151
+ const kept = known.filter((id) => !folded.has(id))
152
+ const total =
153
+ overhead +
154
+ kept.reduce((sum, id) => sum + (widths.get(id) ?? 0), 0) +
155
+ (folded.size > 0 ? toggleWidth : 0)
156
+ return total > room + roundingSlack(known.length, fixedCount + extraCount)
157
+ }
158
+
159
+ /** The first opaque background up the tree — what a pinned cell must paint to be indistinguishable
160
+ * from the cells it covers, whatever surface the table sits on (a card, the page). */
161
+ function surfaceBehind(el: Element): string {
162
+ for (let node: Element | null = el; node !== null; node = node.parentElement) {
163
+ const color = getComputedStyle(node).backgroundColor
164
+ // theme-allow raw-color-fn — compares a computed value to the browser's own "transparent"
165
+ if (color !== 'rgba(0, 0, 0, 0)' && color !== 'transparent') return color
166
+ }
167
+ return ''
168
+ }
169
+
170
+ /**
171
+ * The general-case measured fold. Reacting to `useMeasuredContainment`'s boolean fit directly
172
+ * (fold one, remeasure, maybe unfold) would oscillate, because folding changes the very box being
173
+ * measured. Instead this reads each candidate `<th data-basalt-fold-id>`'s width once, while it is
174
+ * visible, caches it, and decides analytically (`planColumnFold`). `useMeasuredWidths` owns the
175
+ * cache and the wrapper-vs-table observer that `controls/actions.tsx`'s fold shares.
176
+ */
177
+ export function useColumnFold(input: {
178
+ active: boolean
179
+ order: readonly string[]
180
+ /**
181
+ * Columns excluded from fold candidacy altogether (pinned, or `enableHiding: false`) — they are
182
+ * never in `order`, but they still occupy room, and their measured widths (carried in the same
183
+ * sweep as every eligible column's) become fixed overhead against the fold baseline.
184
+ */
185
+ fixedIds: readonly string[]
186
+ /** The checkbox / actions columns: never folded, never data, but they take room all the same. */
187
+ extraIds: readonly string[]
188
+ /** Every pin CANDIDATE in declared order: the caller's columns minus any it pinned itself. */
189
+ pinCandidates: readonly string[]
190
+ /** False when the caller pinned a start column itself: an explicit pin wins, nothing auto-pins. */
191
+ allowPin: boolean
192
+ /**
193
+ * The body holds no rows (loading, empty, error): its widths are header-only and narrower than
194
+ * the loaded table's, so they never overwrite what a loaded table already measured — the states
195
+ * keep the loaded fold instead of unfolding a column the rows would fold again.
196
+ */
197
+ headerOnly: boolean
198
+ /** The rows the body renders right now: a filter that matches nothing leaves a header-only body too. */
199
+ renderedRows: RefObject<number>
200
+ }): {
201
+ wrapperRef: RefObject<HTMLDivElement | null>
202
+ folded: ReadonlySet<string>
203
+ /** The column pinned to the start edge because the floor-folded table still overflows. */
204
+ pinId: string | undefined
205
+ /** Whether the table is wider than its container right now — i.e. whether the scroller scrolls. */
206
+ overflowing: boolean
207
+ /** The last natural width of every column the sweep has seen, read by the loading skeleton's grid. */
208
+ widths: ReadonlyMap<string, number>
209
+ } {
210
+ const { active, order, fixedIds, extraIds, pinCandidates, allowPin, headerOnly, renderedRows } =
211
+ input
212
+ const wrapperRef = useRef<HTMLDivElement>(null)
213
+ const [folded, setFolded] = useState<ReadonlySet<string>>(EMPTY_FOLD_SET)
214
+ const [pinId, setPinId] = useState<string | undefined>(undefined)
215
+ const [overflowing, setOverflowing] = useState(false)
216
+ const [measuredWidths, setMeasuredWidths] = useState<ReadonlyMap<string, number>>(EMPTY_WIDTHS)
217
+ const latest = useRef({ order, fixedIds, extraIds, pinCandidates, allowPin, headerOnly })
218
+ // The pin the LAST measure decided, written inside `onMeasure` itself: a measure that runs again
219
+ // before React commits the state must still see which column the previous one pinned.
220
+ const decidedPin = useRef<string | undefined>(undefined)
221
+ useLayoutEffect(() => {
222
+ latest.current = { order, fixedIds, extraIds, pinCandidates, allowPin, headerOnly }
223
+ // A deactivated hook decided nothing: the next activation starts from no pin.
224
+ if (!active || order.length === 0) decidedPin.current = undefined
225
+ })
226
+ if ((!active || order.length === 0) && (folded.size > 0 || pinId !== undefined)) {
227
+ setFolded(EMPTY_FOLD_SET)
228
+ setPinId(undefined)
229
+ setOverflowing(false)
230
+ }
231
+
232
+ const { remeasure } = useMeasuredWidths({
233
+ resolveRoot: () => wrapperRef.current,
234
+ signature: `${order.join('|')}::${fixedIds.join('|')}::${extraIds.join('|')}`,
235
+ enabled: active && order.length > 0,
236
+ // The table too, not only the wrapper: a re-measured column set moves its min-content width
237
+ // while the wrapper's own box never changes.
238
+ extra: (root) => [root.querySelector('table')],
239
+ onMeasure: (root, boxes) => {
240
+ const current = latest.current
241
+ for (const cell of root.querySelectorAll<HTMLElement>(
242
+ `[${FOLD_ID_ATTR}], [${FIXED_ID_ATTR}]`,
243
+ )) {
244
+ const id = cell.getAttribute(FOLD_ID_ATTR) ?? cell.getAttribute(FIXED_ID_ATTR)
245
+ if (id === null || cell.offsetWidth === 0) continue
246
+ // The pinned column's painted width is the capped one, and a header-only body's is the
247
+ // narrow one: either way the natural width already cached stays.
248
+ const keepCached =
249
+ (id === decidedPin.current || current.headerOnly || renderedRows.current === 0) &&
250
+ boxes.current.has(id)
251
+ if (!keepCached)
252
+ boxes.current.set(id, { width: cell.offsetWidth, height: cell.offsetHeight })
253
+ }
254
+ const room = root.clientWidth
255
+ // A zero reading is an un-laid-out ancestor, not a table with no room — the same guard
256
+ // `useMeasuredContainment` runs against the aside animating in from 0.
257
+ if (room === 0) return
258
+ // The pinned identifier's cap and the disclosure row's sticky width both read the room, and
259
+ // a pinned cell paints the surface the table sits on.
260
+ root.style.setProperty('--basalt-table-room', `${room}px`)
261
+ const surface = surfaceBehind(root)
262
+ if (surface !== '') root.style.setProperty('--basalt-table-surface', surface)
263
+ const widths = new Map([...boxes.current].map(([id, box]) => [id, box.width]))
264
+ setMeasuredWidths((prev) =>
265
+ prev.size === widths.size && [...widths].every(([id, width]) => prev.get(id) === width)
266
+ ? prev
267
+ : widths,
268
+ )
269
+ const overhead = [...current.fixedIds, ...current.extraIds].reduce(
270
+ (sum, id) => sum + (widths.get(id) ?? 0),
271
+ 0,
272
+ )
273
+ const plan = {
274
+ room,
275
+ // The disclosure toggle is a fixed icon-button cell matched to the coarse hit floor, so it
276
+ // reads as one more `--vx-hit` control rather than a narrower afterthought.
277
+ toggleWidth: HIT_COARSE,
278
+ overhead,
279
+ fixedCount: current.fixedIds.length,
280
+ extraCount: current.extraIds.length,
281
+ order: current.order,
282
+ widths,
283
+ }
284
+ const next = planColumnFold(plan)
285
+ setFolded((prev) =>
286
+ prev.size === next.size && [...prev].every((id) => next.has(id)) ? prev : next,
287
+ )
288
+ const nextPin =
289
+ current.allowPin && foldOverflows({ ...plan, folded: next })
290
+ ? current.pinCandidates.find((id) => !next.has(id))
291
+ : undefined
292
+ decidedPin.current = nextPin
293
+ setPinId(nextPin)
294
+ const table = root.querySelector('table')
295
+ setOverflowing(table !== null && table.offsetWidth > room)
296
+ },
297
+ })
298
+
299
+ // The surface a pinned cell paints is read from the page, so a scheme flip must re-read it.
300
+ const remeasureRef = useRef(remeasure)
301
+ useLayoutEffect(() => {
302
+ remeasureRef.current = remeasure
303
+ })
304
+ useLayoutEffect(() => {
305
+ if (!active || typeof MutationObserver === 'undefined') return
306
+ const root = document.documentElement
307
+ let scheme = root.getAttribute('data-mantine-color-scheme')
308
+ let frame = 0
309
+ const observer = new MutationObserver(() => {
310
+ const next = root.getAttribute('data-mantine-color-scheme')
311
+ if (next === scheme) return
312
+ scheme = next
313
+ cancelAnimationFrame(frame)
314
+ frame = requestAnimationFrame(() => remeasureRef.current())
315
+ })
316
+ observer.observe(root, { attributes: true, attributeFilter: ['data-mantine-color-scheme'] })
317
+ return () => {
318
+ cancelAnimationFrame(frame)
319
+ observer.disconnect()
320
+ }
321
+ }, [active])
322
+
323
+ return {
324
+ wrapperRef,
325
+ folded: active ? folded : EMPTY_FOLD_SET,
326
+ pinId: active ? pinId : undefined,
327
+ overflowing: active && overflowing,
328
+ widths: measuredWidths,
329
+ }
330
+ }
331
+
332
+ // ── Sticky cells ──────────────────────────────────────────────────────────────
333
+
334
+ /** What every sticky cell of a render shares — built once, read by each header, skeleton and body
335
+ * site through {@link pinnedCellProps} so none of them can drift. */
336
+ export type PinContext<T extends RowData> = {
337
+ table: TanstackTable<BasaltTableFeatures, T>
338
+ /** The room the fold toggle column takes ahead of the first start-pinned cell; 0 without one. */
339
+ startOffset: number
340
+ /** The auto-pinned identifier: content width bounded by `autoPinMinWidth` and the `.pinnedFluid` cap. */
341
+ autoPinId: string | undefined
342
+ autoPinMinWidth: number | undefined
343
+ }
344
+
345
+ /** `getStart` / `getAfter` sum `getSize()`, so a sticky cell states its width in px and the offsets
346
+ * stay true. The panel is only the fallback: the surface behind the table is measured, unless a sticky
347
+ * header paints its own fill, which `--basalt-pin-fill` hands the header's pinned cells. */
348
+ const STICKY_BASE: CSSProperties = {
349
+ position: 'sticky',
350
+ zIndex: 1,
351
+ backgroundColor: `var(--basalt-pin-fill, var(--basalt-table-surface, ${VX.surface.panel}))`,
352
+ }
353
+
354
+ /**
355
+ * The class and inline style of one column's cell when it pins (`{}` when it does not): the opaque
356
+ * sticky base with the row's own tint layered over it (`.pinnedLayer`), the logical inset of its
357
+ * start/end offset (`dir=rtl` mirrors it) and, on the edge cell touching the scrolling center, the
358
+ * hairline shadow (a physical offset, which does not mirror). The auto-pinned column takes its
359
+ * content width, not the fixed `getSize()` — a 150px default would waste a 360px table's room on a
360
+ * short date.
361
+ */
362
+ export function pinnedCellProps<T extends RowData>(
363
+ ctx: PinContext<T>,
364
+ column: Column<BasaltTableFeatures, T, unknown>,
365
+ ): { className?: string; style?: CSSProperties } {
366
+ const pinned = column.getIsPinned()
367
+ if (!pinned) return {}
368
+ const fluid = column.id === ctx.autoPinId && ctx.autoPinMinWidth !== undefined
369
+ const size = column.getSize()
370
+ const shared: CSSProperties = {
371
+ ...STICKY_BASE,
372
+ ...(fluid
373
+ ? { minWidth: ctx.autoPinMinWidth }
374
+ : { width: size, minWidth: size, maxWidth: size }),
375
+ }
376
+ const className = fluid ? `${classes.pinnedLayer} ${classes.pinnedFluid}` : classes.pinnedLayer
377
+ if (pinned === 'start') {
378
+ const isEdge = column.getPinnedIndex() === ctx.table.getStartLeafColumns().length - 1
379
+ return {
380
+ className,
381
+ style: {
382
+ ...shared,
383
+ insetInlineStart: column.getStart('start') + ctx.startOffset,
384
+ boxShadow: isEdge ? `4px 0 6px -4px ${alpha(VX.ink, 0.18)}` : undefined,
385
+ },
386
+ }
387
+ }
388
+ const isEdge = column.getPinnedIndex() === 0
389
+ return {
390
+ className,
391
+ style: {
392
+ ...shared,
393
+ insetInlineEnd: column.getAfter('end'),
394
+ boxShadow: isEdge ? `-4px 0 6px -4px ${alpha(VX.ink, 0.18)}` : undefined,
395
+ },
396
+ }
397
+ }
398
+
399
+ /** The fold toggle column's cell: one `HIT_COARSE` px wide, and sticky at the start edge — the same
400
+ * base, unit and layer as a pinned column — whenever a start pin follows it. */
401
+ export function foldToggleCellProps<T extends RowData>(
402
+ ctx: PinContext<T>,
403
+ ): { className: string; style: CSSProperties } {
404
+ const sticky = ctx.startOffset > 0
405
+ return {
406
+ className: sticky ? `${classes.foldToggleCell} ${classes.pinnedLayer}` : classes.foldToggleCell,
407
+ style: {
408
+ width: HIT_COARSE,
409
+ minWidth: HIT_COARSE,
410
+ maxWidth: HIT_COARSE,
411
+ ...(sticky && { ...STICKY_BASE, insetInlineStart: 0 }),
412
+ },
413
+ }
414
+ }
415
+
416
+ // ── Disclosure ────────────────────────────────────────────────────────────────
417
+
418
+ /** A folded column's name for the toggle, the header count and the disclosure row: its own header
419
+ * when that is a non-empty string, else the column id — a function/`ReactNode` header has no header
420
+ * CONTEXT to render with here (this is a body row, not the `<thead>`). */
421
+ export function columnLabel<T extends RowData>(
422
+ column: Column<BasaltTableFeatures, T, unknown>,
423
+ ): string {
424
+ const header = column.columnDef.header
425
+ return typeof header === 'string' && header.trim() !== '' ? header : column.id
426
+ }
427
+
428
+ /** One row's folded columns as label/value pairs, directly under it. `row.getAllCells()` returns
429
+ * every leaf cell regardless of visibility (unlike `getVisibleCells()`), so a folded column's own
430
+ * `cell` renderer still draws here exactly as it would in the `<td>` it no longer occupies. */
431
+ export function RowDisclosure<T extends RowData>({
432
+ row,
433
+ folded,
434
+ }: {
435
+ row: Row<BasaltTableFeatures, T>
436
+ folded: ReadonlySet<string>
437
+ }): ReactNode {
438
+ const cells: Cell<BasaltTableFeatures, T, unknown>[] = row
439
+ .getAllCells()
440
+ .filter((cell) => folded.has(cell.column.id))
441
+ return (
442
+ <div className={classes.foldDisclosure}>
443
+ {cells.map((cell) => (
444
+ <div key={cell.id} className={classes.foldDisclosureRow}>
445
+ <Text className={classes.foldDisclosureLabel}>{columnLabel(cell.column)}</Text>
446
+ <div className={classes.foldDisclosureValue}>
447
+ <CellContent cell={cell} />
448
+ </div>
449
+ </div>
450
+ ))}
451
+ </div>
452
+ )
453
+ }
454
+
455
+ /** The header cell above the toggles: a micro count of what folded, with the names in `title` and
456
+ * for a screen reader (F102 — a hidden column must be announced, not merely reachable). */
457
+ export function FoldHeaderLabel({
458
+ count,
459
+ foldedLabel,
460
+ }: {
461
+ count: number
462
+ foldedLabel: string
463
+ }): ReactNode {
464
+ return (
465
+ <span className={classes.foldCount} title={foldedLabel}>
466
+ <span aria-hidden>+{count}</span>
467
+ <span className={classes.srOnly}>
468
+ {count} {count === 1 ? 'column' : 'columns'} folded: {foldedLabel}
469
+ </span>
470
+ </span>
471
+ )
472
+ }
473
+
474
+ /** The per-row expand/collapse control the fold column renders — a ghost chevron whose accessible
475
+ * name says WHAT folded ("Show Volume, Duration"), its 44px hit area carried by the hit overlay
476
+ * (`docs/CONTROLS-SPEC.md` §2; basalt ships no icon set, so the chevron is inline). */
477
+ export function FoldToggle({
478
+ expanded,
479
+ controlsId,
480
+ foldedLabel,
481
+ onToggle,
482
+ }: {
483
+ expanded: boolean
484
+ controlsId: string
485
+ foldedLabel: string
486
+ onToggle: () => void
487
+ }): ReactNode {
488
+ return (
489
+ <button
490
+ type="button"
491
+ className={classes.foldToggle}
492
+ data-basalt-hit
493
+ aria-expanded={expanded}
494
+ aria-controls={controlsId}
495
+ aria-label={`${expanded ? 'Hide' : 'Show'} ${foldedLabel}`}
496
+ // A row carrying `onRowActivate` reads a bubbled click as "activate the row" — the toggle
497
+ // would open/close its disclosure AND fire the row's own action underneath it.
498
+ onClick={(event) => {
499
+ event.stopPropagation()
500
+ onToggle()
501
+ }}
502
+ >
503
+ <svg
504
+ className={classes.foldChevron}
505
+ data-expanded={expanded ? 'true' : 'false'}
506
+ viewBox="0 0 16 16"
507
+ aria-hidden
508
+ focusable="false"
509
+ >
510
+ <path d="M5.5 3.5 10.5 8l-5 4.5" />
511
+ </svg>
512
+ </button>
513
+ )
514
+ }
@@ -101,6 +101,7 @@ export type DataTableStateProps = {
101
101
  onSortingChange?: ((sorting: SortingState) => void) | undefined
102
102
  initialGlobalFilter?: string | undefined
103
103
  onGlobalFilterChange?: ((value: string) => void) | undefined
104
+ initialColumnFilters?: ColumnFiltersState | undefined
104
105
  onColumnFiltersChange?: ((filters: ColumnFiltersState) => void) | undefined
105
106
  initialPagination?: PaginationState | undefined
106
107
  onPaginationChange?: ((pagination: PaginationState) => void) | undefined
@@ -123,7 +124,7 @@ export function useDataTableState(props: DataTableStateProps, defaultPageSize: n
123
124
  props.onGlobalFilterChange,
124
125
  )
125
126
  const [columnFilters, onColumnFiltersChange] = useReportedState<ColumnFiltersState>(
126
- [],
127
+ props.initialColumnFilters ?? [],
127
128
  props.onColumnFiltersChange,
128
129
  )
129
130
  const [pagination, onPaginationChange] = useReportedState(
@@ -173,27 +174,37 @@ export function useDataTableState(props: DataTableStateProps, defaultPageSize: n
173
174
  }
174
175
  }
175
176
 
176
- /** Whether the table renders as `renderCard` projections: its own root measured below the `regular`
177
- * container class. A zero width is an un-laid-out ancestor, not a narrow table, so it moves nothing
178
- * — the default (and the SSR answer) is the table. The root's width never depends on which body it
179
- * holds, so the swap cannot oscillate. */
180
- export function useCardProjection(enabled: boolean): {
181
- rootRef: RefObject<HTMLDivElement | null>
182
- cards: boolean
183
- } {
184
- const rootRef = useRef<HTMLDivElement>(null)
177
+ /** Whether an element's own width is below `px`, measured on a ResizeObserver — never the viewport.
178
+ * A zero width is an un-laid-out ancestor, not a narrow one, so it moves nothing; the default (and
179
+ * the SSR answer) is `false`. */
180
+ export function useNarrowerThan(
181
+ px: number,
182
+ enabled: boolean,
183
+ ): { ref: RefObject<HTMLDivElement | null>; narrow: boolean } {
184
+ const ref = useRef<HTMLDivElement>(null)
185
185
  const [narrow, setNarrow] = useState(false)
186
186
  useMeasuredWidths({
187
- resolveRoot: () => rootRef.current,
187
+ resolveRoot: () => ref.current,
188
188
  signature: '',
189
189
  enabled,
190
190
  onMeasure: (root) => {
191
191
  if (root.clientWidth === 0) return
192
- const next = root.clientWidth < CONTAINER_CLASSES.regular
192
+ const next = root.clientWidth < px
193
193
  setNarrow((current) => (current === next ? current : next))
194
194
  },
195
195
  })
196
- return { rootRef, cards: enabled && narrow }
196
+ return { ref, narrow: enabled && narrow }
197
+ }
198
+
199
+ /** Whether the table renders as `renderCard` projections: its own root measured below the `regular`
200
+ * container class. The root's width never depends on which body it holds, so the swap cannot
201
+ * oscillate. */
202
+ export function useCardProjection(enabled: boolean): {
203
+ rootRef: RefObject<HTMLDivElement | null>
204
+ cards: boolean
205
+ } {
206
+ const { ref, narrow } = useNarrowerThan(CONTAINER_CLASSES.regular, enabled)
207
+ return { rootRef: ref, cards: narrow }
197
208
  }
198
209
 
199
210
  /** Click + Enter activation, shared by a row and its card. Enter only: Space is the browser's own