@aircall/ds 0.37.3 → 0.39.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.
@@ -2,12 +2,20 @@ import * as React from "react";
2
2
  import { ColumnDef, ColumnPinningState, OnChangeFn, RowData, SortingState, VisibilityState } from "@tanstack/react-table";
3
3
  //#region src/components/data-table.d.ts
4
4
  /**
5
- * Column definition for `DataTable`. A bound alias of TanStack Table's own
6
- * `ColumnDef`, owned by `@aircall/ds` — author against this type (not
5
+ * Column definition for `DataTable`. TanStack Table's own `ColumnDef` plus the `flex` field
6
+ * `DataTable` adds, owned by `@aircall/ds` — author against this type (not
7
7
  * `@tanstack/react-table` directly), since `@tanstack/react-table` is a
8
8
  * regular `@aircall/ds` dependency and not part of your own install.
9
9
  */
10
- type ColumnDef$1<TData extends RowData, TValue = unknown> = ColumnDef<TData, TValue>;
10
+ type ColumnDef$1<TData extends RowData, TValue = unknown> = ColumnDef<TData, TValue> & {
11
+ /**
12
+ * Share of the free space this column takes, relative to the other flexible columns.
13
+ * `2` grows twice as fast as the default of `1`. React Spectrum spells this `width="2fr"`.
14
+ *
15
+ * Ignored on a column that declares a `size`, which is static by definition.
16
+ */
17
+ flex?: number;
18
+ };
11
19
  /** Sorting state for `DataTable`'s `sorting` / `onSortingChange` props. Bound alias of TanStack Table's `SortingState`. */
12
20
  type SortingState$1 = SortingState;
13
21
  /** Change handler used by `DataTable`'s controlled props (e.g. `onSortingChange`). Bound alias of TanStack Table's `OnChangeFn`. */
@@ -25,6 +33,29 @@ interface DataTableProps<TData> {
25
33
  * footer cells aligned under their columns.
26
34
  *
27
35
  * Pin columns to the left/right edge with the `columnPinning` prop.
36
+ *
37
+ * ### Width
38
+ *
39
+ * A column is either static or flexible, and `size` is what decides which
40
+ * (mirroring React Spectrum's `TableView`):
41
+ *
42
+ * - **`size: 40`** — static. Exactly 40px, at every container width. It never
43
+ * grows to fill space and never shrinks to make room. Use it for columns
44
+ * whose content has a known width: a checkbox, an icon, a row-actions menu.
45
+ * - **no `size`** — flexible. Takes an equal share of whatever the static
46
+ * columns leave over (Spectrum's `1fr`). This is the default, so leave a
47
+ * column undeclared unless you mean a fixed width.
48
+ * - **`flex: 2`** — flexible with twice the share of a default column.
49
+ * - **`minSize`** — floor. On a flexible column it defaults to 75, and when the
50
+ * floors sum past the container the table keeps every column at its minimum
51
+ * and scrolls horizontally rather than crushing them. It also bounds a
52
+ * static column, so `{ size: 40, minSize: 100 }` renders at 100.
53
+ * - **`maxSize`** — cap; a flexible column's surplus goes to the others. This
54
+ * bounds a static column too, so `{ size: 400, maxSize: 300 }` renders at 300.
55
+ *
56
+ * Declaring `size` on *every* column leaves nothing to absorb the difference,
57
+ * so a table narrower than its container ends short of the right edge. Keep at
58
+ * least one column flexible.
28
59
  */
29
60
  columns: ColumnDef$1<TData, unknown>[];
30
61
  /** Data array to render. With server-side sorting/pagination, this is the already-prepared page. */
@@ -55,9 +86,19 @@ interface DataTableProps<TData> {
55
86
  onSortingChange?: OnChangeFn$1<SortingState$1>;
56
87
  /**
57
88
  * Enables interactive column resizing. Each resizable header gets a drag
58
- * handle on its right edge; column widths come from each column's `size`
59
- * (and are bounded by `minSize`/`maxSize`). Set `enableResizing: false` on a
60
- * column def to pin it (e.g. an actions column).
89
+ * handle on its right edge, bounded by the column's `minSize`/`maxSize`. Set
90
+ * `enableResizing: false` on a column def to pin it (e.g. an actions column).
91
+ *
92
+ * Dragging turns that column static at its new width. The columns before it
93
+ * freeze at their current widths and the ones after it stay flexible and
94
+ * absorb the change, so the drag reads as moving a divider rather than
95
+ * reflowing the whole table (as in React Spectrum's `resizeColumnWidth`).
96
+ *
97
+ * Because each drag freezes what is behind the handle, repeated resizing turns
98
+ * the table progressively static, and once nothing is left flexible it stops
99
+ * filling its container. That is inherent to the model rather than a bug:
100
+ * Spectrum notes the same, that resizing "will convert all columns to the left
101
+ * to static widths, so it will cut down on the number of FR columns".
61
102
  */
62
103
  enableColumnResizing?: boolean;
63
104
  /**
@@ -74,10 +115,10 @@ interface DataTableProps<TData> {
74
115
  /**
75
116
  * Controlled column pinning state — arrays of column ids stuck to the left
76
117
  * or right edge while the table scrolls horizontally, using the same
77
- * column ids passed via `columns`. Implies fixed column widths
78
- * (`table-layout: fixed`); set an explicit `size` on pinned columns. When
79
- * any column is pinned and selection is enabled, the built-in selection
80
- * column is also auto-pinned to the left.
118
+ * column ids passed via `columns`. Pin offsets are derived from the resolved
119
+ * column widths, so no special sizing setup is needed. When any column is
120
+ * pinned and selection is enabled, the built-in selection column is also
121
+ * auto-pinned to the left.
81
122
  *
82
123
  * Set once from wherever pinning is decided (e.g. hardcoded in the column
83
124
  * schema, or computed once from screen size) — `DataTable` has no
@@ -150,25 +191,16 @@ interface DataTableProps<TData> {
150
191
  * virtualizer can track scroll position. Without it, `scrollTop` stays 0 and
151
192
  * virtualization has no effect.
152
193
  *
153
- * Implies `fixedLayout` (`table-layout: fixed`): the virtualizer needs stable
154
- * column widths, so every column takes its `size` instead of sizing to
155
- * content. Columns with no `size` fall back to TanStack's 150px default — so
156
- * a content-sized table (e.g. a narrow icon column) will visibly snap to
157
- * 150px when you enable this. Set an explicit `size` on each column def to
158
- * preserve the intended widths.
194
+ * Needs no sizing setup: the virtualizer requires stable column widths, and
195
+ * widths are already resolved from the column defs in every mode.
159
196
  */
160
197
  virtualizeRows?: boolean;
161
198
  /**
162
- * Uses a fixed table layout (`table-layout: fixed`): column widths come from
163
- * each column's `size` (defaulting to 150) instead of the widest cell, so the
164
- * layout stays stable as different-length content loads. Long cell content
165
- * should be truncated by the cell (e.g. a `truncate` wrapper).
199
+ * @deprecated No longer does anything. Column widths are resolved from the column defs in every
200
+ * mode, so the layout is always stable — which is all this prop ever bought. Safe to remove; it
201
+ * is still accepted so existing call sites keep compiling.
166
202
  *
167
- * This is width-pinning WITHOUT interactivity — unlike `enableColumnResizing`
168
- * it adds no drag handles, and unlike `virtualizeRows` it needs no
169
- * `fillHeight`. Use it for content-stable lists where columns shouldn't
170
- * reflow. (`enableColumnResizing`, `virtualizeRows`, and `columnPinning`
171
- * imply this too.)
203
+ * See the `columns` prop for how widths are declared.
172
204
  */
173
205
  fixedLayout?: boolean;
174
206
  className?: string;
@@ -230,12 +230,15 @@ const de = {
230
230
  "dataTable.selectAllRows": "Alle Zeilen auswählen",
231
231
  "dataTable.selectRow": "Zeile auswählen",
232
232
  "dataCombobox.noResults": "Keine Ergebnisse",
233
+ "combobox.showOptions": "Optionen anzeigen",
233
234
  "tree.collapse": "Minimieren",
234
235
  "tree.expand": "Erweitern",
235
236
  "multiselect.remove": "Entfernen",
236
237
  "multiselect.clearAll": "Alles löschen",
237
238
  "multiselect.addItem": "Hinzufügen",
238
239
  "multiselect.search": "Suchen",
240
+ "combobox.toggleOptions": "Optionen umschalten",
241
+ "combobox.clear": "Löschen",
239
242
  "sidebar.toggle": "Seitenleiste umschalten",
240
243
  "drawer.close": "Schließen",
241
244
  "emojiPicker.emoji": "Emoji",
@@ -279,12 +282,15 @@ const en = {
279
282
  "dataTable.selectAllRows": "Select all rows",
280
283
  "dataTable.selectRow": "Select row",
281
284
  "dataCombobox.noResults": "No results found",
285
+ "combobox.showOptions": "Show options",
282
286
  "tree.collapse": "Collapse",
283
287
  "tree.expand": "Expand",
284
288
  "multiselect.remove": "Remove",
285
289
  "multiselect.clearAll": "Clear all",
286
290
  "multiselect.addItem": "Add item",
287
291
  "multiselect.search": "Search",
292
+ "combobox.toggleOptions": "Toggle options",
293
+ "combobox.clear": "Clear",
288
294
  "sidebar.toggle": "Toggle Sidebar",
289
295
  "drawer.close": "Close",
290
296
  "emojiPicker.emoji": "Emoji",
@@ -328,12 +334,15 @@ const es = {
328
334
  "dataTable.selectAllRows": "Seleccionar todas las filas",
329
335
  "dataTable.selectRow": "Seleccionar fila",
330
336
  "dataCombobox.noResults": "Sin resultados",
337
+ "combobox.showOptions": "Mostrar opciones",
331
338
  "tree.collapse": "Minimizar",
332
339
  "tree.expand": "Ampliar",
333
340
  "multiselect.remove": "Eliminar",
334
341
  "multiselect.clearAll": "Borrar todo",
335
342
  "multiselect.addItem": "Añadir",
336
343
  "multiselect.search": "Buscar",
344
+ "combobox.toggleOptions": "Alternar opciones",
345
+ "combobox.clear": "Borrar",
337
346
  "sidebar.toggle": "Alternar barra lateral",
338
347
  "drawer.close": "Cerrar",
339
348
  "emojiPicker.emoji": "Emoji",
@@ -377,12 +386,15 @@ const fr = {
377
386
  "dataTable.selectAllRows": "Sélectionner toutes les lignes",
378
387
  "dataTable.selectRow": "Sélectionner la ligne",
379
388
  "dataCombobox.noResults": "Aucun résultat",
389
+ "combobox.showOptions": "Afficher les options",
380
390
  "tree.collapse": "Réduire",
381
391
  "tree.expand": "Développer",
382
392
  "multiselect.remove": "Supprimer",
383
393
  "multiselect.clearAll": "Tout effacer",
384
394
  "multiselect.addItem": "Ajouter",
385
395
  "multiselect.search": "Rechercher",
396
+ "combobox.toggleOptions": "Afficher les options",
397
+ "combobox.clear": "Effacer",
386
398
  "sidebar.toggle": "Basculer la barre latérale",
387
399
  "drawer.close": "Fermer",
388
400
  "emojiPicker.emoji": "Émoji",
@@ -426,12 +438,15 @@ const it = {
426
438
  "dataTable.selectAllRows": "Seleziona tutte le righe",
427
439
  "dataTable.selectRow": "Seleziona riga",
428
440
  "dataCombobox.noResults": "Nessun risultato",
441
+ "combobox.showOptions": "Mostra opzioni",
429
442
  "tree.collapse": "Ridurre",
430
443
  "tree.expand": "Espandi",
431
444
  "multiselect.remove": "Rimuovi",
432
445
  "multiselect.clearAll": "Cancella tutto",
433
446
  "multiselect.addItem": "Aggiungi",
434
447
  "multiselect.search": "Cerca",
448
+ "combobox.toggleOptions": "Attiva/disattiva opzioni",
449
+ "combobox.clear": "Cancella",
435
450
  "sidebar.toggle": "Attiva/disattiva barra laterale",
436
451
  "drawer.close": "Chiudi",
437
452
  "emojiPicker.emoji": "Emoji",
@@ -841,13 +856,46 @@ const TableRow = React.forwardRef((componentProps, forwardRef) => {
841
856
  }, props));
842
857
  });
843
858
  TableRow.displayName = "TableRow";
859
+ /**
860
+ * Truncation for DATA cells only. Header cells deliberately do not clip - see below.
861
+ *
862
+ * Column widths are authoritative - `DataTable` solves them and renders the table at exactly their
863
+ * total under `table-layout: fixed` - so content that does not fit has to clip. Without
864
+ * `overflow-hidden` it spills across the next column instead of being cut off.
865
+ *
866
+ * `min-w-0` on the direct child is what lets a flex wrapper (`<div className="flex gap-2">`, the
867
+ * common cell shape) shrink below its content width; a flex item's `min-width: auto` would
868
+ * otherwise refuse to and push the overflow out.
869
+ *
870
+ * WHY NOT ON `TableHead`: the header row is where the interactive chrome lives, and clipping it
871
+ * cuts focus rings. `DataTable`'s sortable header renders a `Button` with `-ml-2` against this
872
+ * cell's `px-2`, and the DS focus ring is `focus-visible:ring-3`, drawn 3px OUTSIDE the border box.
873
+ * Measured headroom between the button's left edge and the clip boundary:
874
+ *
875
+ * - first column: 8px, because `first:pl-4` gives it 16px of padding. The ring clears.
876
+ * - every other column: 0px. The ring is cut.
877
+ *
878
+ * So it was every sortable column except the first, for keyboard users only. Stated precisely
879
+ * because the 0px figure was measured on a non-first column and does not generalise.
880
+ *
881
+ * React Spectrum solves this with `overflow: hidden` plus `padding: 4px; margin: -4px` so the ring
882
+ * escapes the clip, but that is not portable to a `display: table-cell`, where `margin` is inert.
883
+ * The alternatives all cost something visible: shrinking the negative margin misaligns sortable
884
+ * against non-sortable headers, dropping the button's padding changes the ghost hover rect, and an
885
+ * inset ring would make these the only focus rings in the DS drawn inwards.
886
+ *
887
+ * So headers keep the behaviour they had before column sizing existed: no clip. Header labels are
888
+ * short by nature, and a long one in a narrow column spills exactly as it always has. Data cells
889
+ * are where long content actually appears, and none of them carry a negative margin.
890
+ */
891
+ const truncatingCell = "overflow-hidden text-ellipsis [&>*]:min-w-0";
844
892
  /** A header cell. Renders a `<th>` with medium-weight, left-aligned text. */
845
893
  const TableHead = React.forwardRef((componentProps, forwardRef) => {
846
894
  const { className } = componentProps, props = _objectWithoutProperties(componentProps, _excluded6);
847
895
  return /* @__PURE__ */ jsx("th", _objectSpread2({
848
896
  ref: forwardRef,
849
897
  "data-slot": "table-head",
850
- className: cn("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0", className)
898
+ className: cn("h-10 px-2 first:pl-4 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0", className)
851
899
  }, props));
852
900
  });
853
901
  TableHead.displayName = "TableHead";
@@ -857,10 +905,130 @@ const TableCell = React.forwardRef((componentProps, forwardRef) => {
857
905
  return /* @__PURE__ */ jsx("td", _objectSpread2({
858
906
  ref: forwardRef,
859
907
  "data-slot": "table-cell",
860
- className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className)
908
+ className: cn("p-2 first:pl-4 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", truncatingCell, className)
861
909
  }, props));
862
910
  });
863
911
  TableCell.displayName = "TableCell";
912
+ /**
913
+ * Resolves every column to a whole-pixel width.
914
+ *
915
+ * Static columns are frozen at their `size`. The remaining space is distributed over the flexible
916
+ * columns in proportion to their weight, clamped to each column's `minSize` / `maxSize`; a column
917
+ * that hits a bound freezes there and the loop redistributes what is left over the rest.
918
+ *
919
+ * When the floors sum past `availableWidth` the total simply exceeds it - the caller renders a
920
+ * wider table inside a scrolling container. There is no separate overflow mode; it falls out of
921
+ * the min clamping, exactly as in React Spectrum.
922
+ *
923
+ * @param availableWidth Visible width the columns divide up, in px. Values `<= 0` (an unmeasured
924
+ * container) resolve every column to its floor, so the first paint is sane rather than collapsed.
925
+ * @param columns Declared sizing per column, in render order.
926
+ * @returns Widths in the same order as `columns`, summing to `max(availableWidth, sum of floors)`.
927
+ */
928
+ function resolveColumnWidths(availableWidth, columns) {
929
+ if (columns.length === 0) return [];
930
+ const available = Math.max(0, Math.floor(availableWidth));
931
+ let hasUnfrozen = false;
932
+ const items = columns.map((column) => {
933
+ var _column$minSize, _column$maxSize, _column$flex;
934
+ const isStatic = column.size != null;
935
+ const min = (_column$minSize = column.minSize) !== null && _column$minSize !== void 0 ? _column$minSize : isStatic ? 0 : 75;
936
+ const max = (_column$maxSize = column.maxSize) !== null && _column$maxSize !== void 0 ? _column$maxSize : Number.MAX_SAFE_INTEGER;
937
+ const baseSize = isStatic ? column.size : 0;
938
+ const flex = isStatic ? 0 : Math.max(0, (_column$flex = column.flex) !== null && _column$flex !== void 0 ? _column$flex : 1);
939
+ const frozen = isStatic || flex <= 0;
940
+ const item = {
941
+ frozen,
942
+ baseSize,
943
+ min,
944
+ max,
945
+ flex,
946
+ targetSize: frozen ? Math.max(min, Math.min(baseSize, max)) : 0,
947
+ violation: 0
948
+ };
949
+ if (!item.frozen) hasUnfrozen = true;
950
+ return item;
951
+ });
952
+ while (hasUnfrozen) {
953
+ let usedWidth = 0;
954
+ let flexTotal = 0;
955
+ for (const item of items) if (item.frozen) usedWidth += item.targetSize;
956
+ else {
957
+ usedWidth += item.baseSize;
958
+ flexTotal += item.flex;
959
+ }
960
+ const freeSpace = available - usedWidth;
961
+ if (freeSpace > 0 && flexTotal > 0) {
962
+ for (const item of items) if (!item.frozen) item.targetSize = item.baseSize + item.flex / flexTotal * freeSpace;
963
+ } else for (const item of items) if (!item.frozen) item.targetSize = item.baseSize;
964
+ let totalViolation = 0;
965
+ for (const item of items) {
966
+ item.violation = 0;
967
+ if (!item.frozen) {
968
+ const clamped = Math.max(item.min, Math.min(item.targetSize, item.max));
969
+ item.violation = clamped - item.targetSize;
970
+ item.targetSize = clamped;
971
+ totalViolation += item.violation;
972
+ }
973
+ }
974
+ hasUnfrozen = false;
975
+ for (const item of items) {
976
+ if (item.frozen) continue;
977
+ if (totalViolation === 0 || Math.sign(totalViolation) === Math.sign(item.violation)) item.frozen = true;
978
+ else hasUnfrozen = true;
979
+ }
980
+ }
981
+ return cascadeRound(items.map((item) => item.targetSize));
982
+ }
983
+ /**
984
+ * Rounds a list of fractional widths to integers whose sum equals the rounded sum of the input.
985
+ *
986
+ * Rounding each width on its own would lose or gain up to half a pixel per column, which shows up
987
+ * as a hairline gap at the right edge of the table. Carrying the running error into the next
988
+ * column keeps the total exact.
989
+ */
990
+ function cascadeRound(values) {
991
+ let floatTotal = 0;
992
+ let intTotal = 0;
993
+ return values.map((value) => {
994
+ const rounded = Math.round(value + floatTotal) - intTotal;
995
+ floatTotal += value;
996
+ intTotal += rounded;
997
+ return rounded;
998
+ });
999
+ }
1000
+ //#endregion
1001
+ //#region src/lib/use-available-width.ts
1002
+ /**
1003
+ * Tracks the inner width available to a container's content, in px.
1004
+ *
1005
+ * `clientWidth` rather than `getBoundingClientRect().width` on purpose: it excludes the border and
1006
+ * any scrollbar gutter, which is exactly the space child content can occupy. `DataTable` divides
1007
+ * this number up between its columns, so counting a vertical scrollbar's width would make the
1008
+ * table overflow horizontally by the width of that scrollbar.
1009
+ *
1010
+ * Measured in a layout effect so the first paint already has a real number - a `useEffect` here
1011
+ * would show one frame of collapsed columns before correcting itself.
1012
+ *
1013
+ * @returns The container's `clientWidth`, or `0` before the first measurement.
1014
+ */
1015
+ function useAvailableWidth(ref) {
1016
+ const [width, setWidth] = React.useState(0);
1017
+ React.useLayoutEffect(() => {
1018
+ const el = ref.current;
1019
+ if (!el) return;
1020
+ const measure = () => setWidth((previous) => previous === el.clientWidth ? previous : el.clientWidth);
1021
+ measure();
1022
+ if (typeof ResizeObserver === "undefined") {
1023
+ window.addEventListener("resize", measure);
1024
+ return () => window.removeEventListener("resize", measure);
1025
+ }
1026
+ const observer = new ResizeObserver(measure);
1027
+ observer.observe(el);
1028
+ return () => observer.disconnect();
1029
+ }, [ref]);
1030
+ return width;
1031
+ }
864
1032
  //#endregion
865
1033
  //#region src/lib/use-horizontal-scroll-edges.ts
866
1034
  /**
@@ -914,6 +1082,18 @@ function useHorizontalScrollEdges(containerRef, enabled, contentSizeKey) {
914
1082
  //#endregion
915
1083
  //#region src/components/data-table.tsx
916
1084
  const SELECT_COLUMN_ID = "__select";
1085
+ /**
1086
+ * Narrowest a column can be dragged to, in px, when it declares a `size` but no `minSize`.
1087
+ *
1088
+ * Separate from the solver's floor on purpose. For LAYOUT a static column has no minimum, because a
1089
+ * declared `size: 16` has to render as 16. For DRAGGING it needs one, or the column can be pulled to
1090
+ * nothing and vanish. TanStack's own default of 20 used to provide this by accident, until
1091
+ * `defaultColumn: { minSize: 0 }` removed it so that our solved widths stop being second-guessed.
1092
+ *
1093
+ * Applied as `min(declared size, this)`, so a column declaring less than 20 is floored at its own
1094
+ * width rather than jumping up to 20 the moment it is touched.
1095
+ */
1096
+ const MIN_RESIZE_WIDTH = 20;
917
1097
  const DEFAULT_SKELETON_COUNT = 5;
918
1098
  const EMPTY_KEYS = /* @__PURE__ */ new Set();
919
1099
  const EMPTY_COLUMN_PINNING = {
@@ -921,6 +1101,62 @@ const EMPTY_COLUMN_PINNING = {
921
1101
  right: []
922
1102
  };
923
1103
  /**
1104
+ * Resolves the id TanStack will give a leaf column, from the consumer's own def.
1105
+ *
1106
+ * Must stay identical to `createColumn` in `@tanstack/table-core`, which resolves
1107
+ * `id ?? accessorKey.replaceAll('.', '_') ?? (typeof header === 'string' ? header : undefined)`.
1108
+ * The dot replacement and the string-`header` fallback are both easy to miss and both matter: get
1109
+ * either wrong and the id here disagrees with the id on the table instance, so the column gets no
1110
+ * resolved width and every pin offset after it is computed from the wrong number.
1111
+ *
1112
+ * `assertEveryColumnSized` below is the backstop for exactly that.
1113
+ */
1114
+ function resolveLeafColumnId(def) {
1115
+ const accessorKey = def.accessorKey;
1116
+ if (def.id != null) return def.id;
1117
+ if (accessorKey != null) return accessorKey.replace(/\./g, "_");
1118
+ return typeof def.header === "string" ? def.header : void 0;
1119
+ }
1120
+ /**
1121
+ * Flattens column defs to their leaves and reads the declared sizing off each one.
1122
+ *
1123
+ * Reads the consumer's own defs rather than `column.columnDef` from the table instance, because
1124
+ * TanStack merges its defaults (`size: 150`, `minSize: 20`) into every column def - so by the time
1125
+ * a def reaches the table there is no way left to tell "the consumer asked for 150" from "the
1126
+ * consumer declared nothing". That distinction is the whole model: a declared `size` is static, an
1127
+ * absent one is flexible.
1128
+ */
1129
+ function collectSizingSpecs(defs, into = /* @__PURE__ */ new Map()) {
1130
+ for (const def of defs) {
1131
+ const groupChildren = def.columns;
1132
+ if (groupChildren === null || groupChildren === void 0 ? void 0 : groupChildren.length) {
1133
+ collectSizingSpecs(groupChildren, into);
1134
+ continue;
1135
+ }
1136
+ const id = resolveLeafColumnId(def);
1137
+ if (id == null) continue;
1138
+ into.set(id, {
1139
+ id,
1140
+ size: def.size,
1141
+ minSize: def.minSize,
1142
+ maxSize: def.maxSize,
1143
+ flex: def.flex
1144
+ });
1145
+ }
1146
+ return into;
1147
+ }
1148
+ /**
1149
+ * Dev-only check that the solve covered every column the table actually renders.
1150
+ *
1151
+ * A column missing from `columnSizing` silently falls back to TanStack's 150px default and throws
1152
+ * off the pin offsets of everything after it - a failure that is invisible in a passing test suite
1153
+ * and easy to introduce by drifting from `resolveLeafColumnId`.
1154
+ */
1155
+ function assertEveryColumnSized(table, columnSizing) {
1156
+ const diverged = table.getVisibleLeafColumns().filter((column) => columnSizing[column.id] !== column.getSize()).map((column) => `${column.id} (solved ${columnSizing[column.id]}, getSize ${column.getSize()})`);
1157
+ if (diverged.length > 0) console.warn(`DataTable: resolved width disagrees with getSize() for ${diverged.join(", ")}. The colgroup uses the resolved width and getTotalSize() uses getSize(), so the table renders wider or narrower than its own column tracks and every width gets rescaled. Usual causes: a column id derived from your \`columns\` prop that disagrees with the one on the table instance (set an explicit \`id\`), or a \`columnDef\` min/max clamping a width we own.`);
1158
+ }
1159
+ /**
924
1160
  * Data grid built on TanStack Table. Renders a `<div>` wrapper around a DS
925
1161
  * `<Table>` (`<table>`), driven by `columns` + `data`, with opt-in sorting,
926
1162
  * row selection, column resizing, column pinning (`columnPinning`), virtualization,
@@ -937,7 +1173,7 @@ const EMPTY_COLUMN_PINNING = {
937
1173
  */
938
1174
  function DataTable(componentProps) {
939
1175
  var _columnPinning$left$l, _columnPinning$left, _columnPinning$right$, _columnPinning$right, _resolvedColumnPinnin, _resolvedColumnPinnin2, _resolvedColumnPinnin3, _resolvedColumnPinnin4, _componentProps$virtu;
940
- const { columns, data, getRowId, loadingState = "idle", skeletonCount = DEFAULT_SKELETON_COUNT, emptyState, sorting, onSortingChange, columnVisibility, columnPinning, selectionMode = "none", selectedKeys, defaultSelectedKeys, onSelectionChange, disabledKeys, disabledBehavior = "all", actionBar, onFetchMore, hasMore = false, enableColumnResizing = false, fillHeight = false, fixedLayout = false, onRowClick, className } = componentProps;
1176
+ const { columns, data, getRowId, loadingState = "idle", skeletonCount = DEFAULT_SKELETON_COUNT, emptyState, sorting, onSortingChange, columnVisibility, columnPinning, selectionMode = "none", selectedKeys, defaultSelectedKeys, onSelectionChange, disabledKeys, disabledBehavior = "all", actionBar, onFetchMore, hasMore = false, enableColumnResizing = false, fillHeight = false, onRowClick, className } = componentProps;
941
1177
  const sortingEnabled = !!onSortingChange;
942
1178
  const selectionEnabled = selectionMode !== "none";
943
1179
  const multiSelect = selectionMode === "multiple";
@@ -977,6 +1213,70 @@ function DataTable(componentProps) {
977
1213
  const next = typeof updater === "function" ? updater(rowSelection) : updater;
978
1214
  setSelectionSet(new Set(Object.keys(next).filter((key) => next[key])));
979
1215
  }, [rowSelection, setSelectionSet]);
1216
+ const containerRef = React.useRef(null);
1217
+ const availableWidth = useAvailableWidth(containerRef);
1218
+ const sizingSpecs = React.useMemo(() => collectSizingSpecs(finalColumns), [finalColumns]);
1219
+ const [userSizing, setUserSizing] = React.useState({});
1220
+ const visibleLeafIds = React.useMemo(() => {
1221
+ var _resolvedColumnPinnin5, _resolvedColumnPinnin6;
1222
+ const all = [...sizingSpecs.keys()];
1223
+ const ids = columnVisibility ? all.filter((id) => columnVisibility[id] !== false) : all;
1224
+ const left = (_resolvedColumnPinnin5 = resolvedColumnPinning.left) !== null && _resolvedColumnPinnin5 !== void 0 ? _resolvedColumnPinnin5 : [];
1225
+ const right = (_resolvedColumnPinnin6 = resolvedColumnPinning.right) !== null && _resolvedColumnPinnin6 !== void 0 ? _resolvedColumnPinnin6 : [];
1226
+ if (left.length === 0 && right.length === 0) return ids;
1227
+ const isPinned = /* @__PURE__ */ new Set([...left, ...right]);
1228
+ return [
1229
+ ...left.filter((id) => ids.includes(id)),
1230
+ ...ids.filter((id) => !isPinned.has(id)),
1231
+ ...right.filter((id) => ids.includes(id))
1232
+ ];
1233
+ }, [
1234
+ sizingSpecs,
1235
+ columnVisibility,
1236
+ resolvedColumnPinning
1237
+ ]);
1238
+ const columnSizing = React.useMemo(() => {
1239
+ const specs = visibleLeafIds.map((id) => {
1240
+ var _sizingSpecs$get;
1241
+ const spec = (_sizingSpecs$get = sizingSpecs.get(id)) !== null && _sizingSpecs$get !== void 0 ? _sizingSpecs$get : { id };
1242
+ const dragged = userSizing[id];
1243
+ return dragged != null ? _objectSpread2(_objectSpread2({}, spec), {}, { size: dragged }) : spec;
1244
+ });
1245
+ const widths = resolveColumnWidths(availableWidth, specs);
1246
+ const resolved = {};
1247
+ visibleLeafIds.forEach((id, index) => {
1248
+ resolved[id] = widths[index];
1249
+ });
1250
+ return resolved;
1251
+ }, [
1252
+ visibleLeafIds,
1253
+ sizingSpecs,
1254
+ userSizing,
1255
+ availableWidth
1256
+ ]);
1257
+ const handleColumnSizingChange = React.useCallback((updater) => {
1258
+ const next = typeof updater === "function" ? updater(columnSizing) : updater;
1259
+ const changedIds = visibleLeafIds.filter((id) => next[id] != null && next[id] !== columnSizing[id]);
1260
+ if (changedIds.length === 0) return;
1261
+ const frozen = {};
1262
+ const firstChangedIndex = visibleLeafIds.indexOf(changedIds[0]);
1263
+ for (let index = 0; index < firstChangedIndex; index++) {
1264
+ const id = visibleLeafIds[index];
1265
+ frozen[id] = columnSizing[id];
1266
+ }
1267
+ for (const id of changedIds) {
1268
+ var _spec$minSize, _spec$maxSize;
1269
+ const spec = sizingSpecs.get(id);
1270
+ const floor = (_spec$minSize = spec === null || spec === void 0 ? void 0 : spec.minSize) !== null && _spec$minSize !== void 0 ? _spec$minSize : (spec === null || spec === void 0 ? void 0 : spec.size) != null ? Math.min(spec.size, MIN_RESIZE_WIDTH) : 75;
1271
+ const cap = (_spec$maxSize = spec === null || spec === void 0 ? void 0 : spec.maxSize) !== null && _spec$maxSize !== void 0 ? _spec$maxSize : Number.MAX_SAFE_INTEGER;
1272
+ frozen[id] = Math.max(floor, Math.min(next[id], cap));
1273
+ }
1274
+ setUserSizing((previous) => _objectSpread2(_objectSpread2({}, previous), frozen));
1275
+ }, [
1276
+ columnSizing,
1277
+ visibleLeafIds,
1278
+ sizingSpecs
1279
+ ]);
980
1280
  const table = useReactTable({
981
1281
  data,
982
1282
  columns: finalColumns,
@@ -989,9 +1289,14 @@ function DataTable(componentProps) {
989
1289
  enableColumnResizing,
990
1290
  enableColumnPinning: hasPinnedColumns,
991
1291
  columnResizeMode: "onChange",
1292
+ defaultColumn: { minSize: 0 },
992
1293
  onSortingChange,
993
1294
  onRowSelectionChange: handleRowSelectionChange,
994
- state: _objectSpread2(_objectSpread2(_objectSpread2({}, sorting !== void 0 && { sorting }), {}, { rowSelection }, hasPinnedColumns && { columnPinning: resolvedColumnPinning }), columnVisibility !== void 0 && { columnVisibility })
1295
+ onColumnSizingChange: handleColumnSizingChange,
1296
+ state: _objectSpread2(_objectSpread2(_objectSpread2({}, sorting !== void 0 && { sorting }), {}, {
1297
+ rowSelection,
1298
+ columnSizing
1299
+ }, hasPinnedColumns && { columnPinning: resolvedColumnPinning }), columnVisibility !== void 0 && { columnVisibility })
995
1300
  });
996
1301
  const rows = table.getRowModel().rows;
997
1302
  const selectedCount = table.getSelectedRowModel().rows.length;
@@ -1011,15 +1316,15 @@ function DataTable(componentProps) {
1011
1316
  } else if (onRowClick) onRowClick(row.original);
1012
1317
  };
1013
1318
  const virtualizeRows = ((_componentProps$virtu = componentProps.virtualizeRows) !== null && _componentProps$virtu !== void 0 ? _componentProps$virtu : false) && fillHeight;
1014
- const pinWidths = enableColumnResizing || virtualizeRows || fixedLayout || hasPinnedColumns;
1015
- const containerRef = React.useRef(null);
1016
- const { atLeftEdge, atRightEdge } = useHorizontalScrollEdges(containerRef, hasPinnedColumns, table.getTotalSize());
1017
- const getCellPinProps = (column, variant) => getPinnedCellProps(column, {
1018
- pinWidths,
1319
+ const totalSize = table.getTotalSize();
1320
+ assertEveryColumnSized(table, columnSizing);
1321
+ const { atLeftEdge, atRightEdge } = useHorizontalScrollEdges(containerRef, hasPinnedColumns, totalSize);
1322
+ const getCellPinProps = (column, variant, size) => getPinnedCellProps(column, {
1019
1323
  variant,
1020
1324
  fillHeight,
1021
1325
  showLeftEdgeShadow: !atLeftEdge,
1022
- showRightEdgeShadow: !atRightEdge
1326
+ showRightEdgeShadow: !atRightEdge,
1327
+ size
1023
1328
  });
1024
1329
  const rowVirtualizer = useVirtualizer({
1025
1330
  count: virtualizeRows ? rows.length : 0,
@@ -1041,19 +1346,21 @@ function DataTable(componentProps) {
1041
1346
  children: [
1042
1347
  /* @__PURE__ */ jsxs(Table, {
1043
1348
  containerRef,
1044
- className: cn(pinWidths && "table-fixed", hasPinnedColumns && cn("border-separate border-spacing-0", "[&_[data-slot=table-cell]]:border-b [&_[data-slot=table-cell]]:border-border", "[&_tbody_tr:last-child_[data-slot=table-cell]]:border-b-0", "[&_tfoot_[data-slot=table-cell]]:border-t [&_tfoot_tr:last-child_[data-slot=table-cell]]:border-b-0", !fillHeight && "[&_[data-slot=table-head]]:border-b [&_[data-slot=table-head]]:border-border"), fillHeight && "[&_[data-slot=table-head]]:sticky [&_[data-slot=table-head]]:top-0 [&_[data-slot=table-head]]:z-10 [&_[data-slot=table-head]]:bg-background [&_thead_tr]:border-b-0 [&_[data-slot=table-head]]:shadow-[inset_0_-1px_0_0_var(--border)]", fillHeight && showEmptyState && "h-full"),
1349
+ className: cn("table-fixed", hasPinnedColumns && cn("border-separate border-spacing-0", "[&_[data-slot=table-cell]]:border-b [&_[data-slot=table-cell]]:border-border", "[&_tbody_tr:last-child_[data-slot=table-cell]]:border-b-0", "[&_tfoot_[data-slot=table-cell]]:border-t [&_tfoot_tr:last-child_[data-slot=table-cell]]:border-b-0", !fillHeight && "[&_[data-slot=table-head]]:border-b [&_[data-slot=table-head]]:border-border"), fillHeight && "[&_[data-slot=table-head]]:sticky [&_[data-slot=table-head]]:top-0 [&_[data-slot=table-head]]:z-10 [&_[data-slot=table-head]]:bg-background [&_thead_tr]:border-b-0 [&_[data-slot=table-head]]:shadow-[inset_0_-1px_0_0_var(--border)]", fillHeight && showEmptyState && "h-full"),
1045
1350
  containerClassName: fillHeight ? "min-h-0 flex-1 overflow-y-auto" : void 0,
1046
1351
  containerStyle: reservedBottom ? {
1047
1352
  paddingBottom: reservedBottom,
1048
1353
  scrollPaddingBottom: reservedBottom
1049
1354
  } : void 0,
1050
- style: pinWidths ? { width: `max(100%, ${table.getTotalSize()}px)` } : void 0,
1355
+ style: { width: `${totalSize}px` },
1051
1356
  children: [
1357
+ /* @__PURE__ */ jsx("colgroup", { children: visibleLeafIds.map((id) => /* @__PURE__ */ jsx("col", { style: { width: `${columnSizing[id]}px` } }, id)) }),
1052
1358
  /* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, {
1053
1359
  className: enableColumnResizing ? "group/header-row" : void 0,
1054
1360
  children: headerGroup.headers.map((header) => {
1055
- const pinProps = getCellPinProps(header.column, "header");
1361
+ const pinProps = getCellPinProps(header.column, "header", header.getSize());
1056
1362
  return /* @__PURE__ */ jsxs(TableHead, {
1363
+ colSpan: header.colSpan,
1057
1364
  style: pinProps.style,
1058
1365
  className: cn(enableColumnResizing && "relative", pinProps.className),
1059
1366
  children: [header.isPlaceholder ? null : header.column.getCanSort() ? /* @__PURE__ */ jsx(SortableHeader, { header }) : flexRender(header.column.columnDef.header, header.getContext()), enableColumnResizing && header.column.getCanResize() ? /* @__PURE__ */ jsx(ResizeHandle, { header }) : null]
@@ -1124,7 +1431,7 @@ function DataTable(componentProps) {
1124
1431
  className: "hover:bg-transparent",
1125
1432
  children: /* @__PURE__ */ jsx(TableCell, {
1126
1433
  colSpan: leafColumnCount,
1127
- className: "py-3",
1434
+ className: "py-3 first:pl-2",
1128
1435
  children: /* @__PURE__ */ jsx("div", {
1129
1436
  className: "flex items-center justify-center text-muted-foreground",
1130
1437
  children: /* @__PURE__ */ jsx(Spinner, {})
@@ -1143,7 +1450,7 @@ function DataTable(componentProps) {
1143
1450
  className: "hover:bg-transparent",
1144
1451
  children: /* @__PURE__ */ jsx(TableCell, {
1145
1452
  colSpan: leafColumnCount,
1146
- className: "h-full p-0",
1453
+ className: "h-full p-0 first:pl-0",
1147
1454
  children: /* @__PURE__ */ jsx("div", {
1148
1455
  className: cn("flex h-full items-center justify-center", !fillHeight && "min-h-60"),
1149
1456
  children: emptyState
@@ -1151,8 +1458,9 @@ function DataTable(componentProps) {
1151
1458
  })
1152
1459
  }) : null }),
1153
1460
  hasFooter && !isInitialLoading ? /* @__PURE__ */ jsx(TableFooter, { children: table.getFooterGroups().map((footerGroup) => /* @__PURE__ */ jsx(TableRow, { children: footerGroup.headers.map((header) => {
1154
- const pinProps = getCellPinProps(header.column, "footer");
1461
+ const pinProps = getCellPinProps(header.column, "footer", header.getSize());
1155
1462
  return /* @__PURE__ */ jsx(TableCell, {
1463
+ colSpan: header.colSpan,
1156
1464
  style: pinProps.style,
1157
1465
  className: pinProps.className,
1158
1466
  children: header.isPlaceholder ? null : flexRender(header.column.columnDef.footer, header.getContext())
@@ -1250,8 +1558,8 @@ function SortableHeader({ header }) {
1250
1558
  * while horizontal scroll has moved away from that edge.
1251
1559
  */
1252
1560
  function getPinnedCellProps(column, options) {
1253
- const { pinWidths, variant, fillHeight, showLeftEdgeShadow, showRightEdgeShadow } = options;
1254
- const style = pinWidths ? { width: `${column.getSize()}px` } : {};
1561
+ const { variant, fillHeight, showLeftEdgeShadow, showRightEdgeShadow, size } = options;
1562
+ const style = { width: `${size !== null && size !== void 0 ? size : column.getSize()}px` };
1255
1563
  const isPinned = column.getIsPinned();
1256
1564
  if (!isPinned) return { style };
1257
1565
  style.position = "sticky";
@@ -1,2 +1,2 @@
1
- import { a as OnChangeFn, i as DataTableLoadingState, n as ColumnPinningState, o as SortingState, r as DataTable, s as VisibilityState, t as ColumnDef } from "./data-table-DdK-5YI9.js";
1
+ import { a as OnChangeFn, i as DataTableLoadingState, n as ColumnPinningState, o as SortingState, r as DataTable, s as VisibilityState, t as ColumnDef } from "./data-table-AHgs5bxe.js";
2
2
  export { type ColumnDef, type ColumnPinningState, DataTable, type DataTableLoadingState, type OnChangeFn, type SortingState, type VisibilityState };
@@ -1,2 +1,2 @@
1
- import { t as DataTable } from "./data-table-DZ2FDkmw.js";
1
+ import { t as DataTable } from "./data-table-DD7m3puW.js";
2
2
  export { DataTable };