@gridkitjs/react 0.16.0 → 0.17.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.
package/dist/index.js CHANGED
@@ -6,10 +6,12 @@ import {
6
6
  useId as useId2,
7
7
  useImperativeHandle as useImperativeHandle3,
8
8
  useMemo as useMemo5,
9
- useRef as useRef21,
9
+ useRef as useRef23,
10
10
  useState as useState18
11
11
  } from "react";
12
12
  import {
13
+ bodyFocus as bodyFocus3,
14
+ headerFocus as headerFocus3,
13
15
  moveColumnBefore,
14
16
  resolveColumnHeaderText as resolveColumnHeaderText2,
15
17
  resolveMessages,
@@ -27,6 +29,7 @@ function GridColgroup({ columns }) {
27
29
  import { createPortal } from "react-dom";
28
30
  import {
29
31
  buildKeyShortcuts,
32
+ headerFocus,
30
33
  intentOf,
31
34
  isColumnFiltered,
32
35
  KEYBOARD_STEP,
@@ -105,83 +108,6 @@ function isOwnEvent(event) {
105
108
  return event.target instanceof Node && event.currentTarget.contains(event.target);
106
109
  }
107
110
 
108
- // src/DataGrid/useGridNavigation.ts
109
- import {
110
- useEffect,
111
- useLayoutEffect,
112
- useState,
113
- useSyncExternalStore
114
- } from "react";
115
- import { HEADER_ROW } from "@gridkitjs/core";
116
- import {
117
- createGridFocus,
118
- findBodyRow,
119
- measurePageSize
120
- } from "@gridkitjs/dom";
121
- function tabIndexFor(columnIndex, focusedColumnIndex) {
122
- return columnIndex === focusedColumnIndex ? 0 : -1;
123
- }
124
- function useGridNavigation({
125
- gridRef,
126
- headerTableRef,
127
- bodyTableRef,
128
- rowCount,
129
- columnCount,
130
- isSkippableRow,
131
- virtualRange
132
- }) {
133
- const options = {
134
- rowCount,
135
- columnCount,
136
- isSkippableRow,
137
- virtualRange
138
- };
139
- const [gridFocus] = useState(() => createGridFocus(options));
140
- gridFocus.setOptions(options);
141
- const focus = useSyncExternalStore(
142
- gridFocus.subscribe,
143
- gridFocus.getFocus,
144
- gridFocus.getFocus
145
- );
146
- const [rows] = useState(() => ({
147
- getHeaderRow: () => headerTableRef.current?.tHead?.rows[0] ?? null,
148
- getBodyRow: (rowIndex) => findBodyRow(bodyTableRef.current, rowIndex)
149
- }));
150
- useLayoutEffect(
151
- () => gridFocus.attach(rows, gridRef.current),
152
- [gridFocus, rows, gridRef]
153
- );
154
- useEffect(() => {
155
- gridFocus.focusDrawnCell(focus);
156
- });
157
- return {
158
- focus,
159
- tabIndexFor: (rowIndex, columnIndex) => tabIndexFor(
160
- columnIndex,
161
- rowIndex === focus.rowIndex ? focus.columnIndex : null
162
- ),
163
- focusCell: gridFocus.focusCell,
164
- focusCellNow: (rowIndex, columnIndex) => {
165
- gridFocus.focusCell(rowIndex, columnIndex);
166
- gridFocus.focusDrawnCell(gridFocus.getFocus());
167
- },
168
- tabStopCell: () => {
169
- const { rowIndex, columnIndex } = gridFocus.getFocus();
170
- const cells = (rowIndex === HEADER_ROW ? rows.getHeaderRow() : rows.getBodyRow(rowIndex))?.cells;
171
- return cells?.[Math.min(columnIndex, cells.length - 1)] ?? null;
172
- },
173
- onKeyDown: (event) => {
174
- if (gridFocus.handleKey(
175
- event.key,
176
- event,
177
- measurePageSize(bodyTableRef.current)
178
- )) {
179
- event.preventDefault();
180
- }
181
- }
182
- };
183
- }
184
-
185
111
  // src/DataGrid/useGridSelection.ts
186
112
  import { useMemo } from "react";
187
113
  function keyboardSelectIntent(event) {
@@ -281,14 +207,14 @@ function GridHeader({
281
207
  role: "columnheader",
282
208
  "data-gridkit-column": entry.id,
283
209
  "aria-colindex": index + 1,
284
- tabIndex: nav.tabIndexFor(HEADER_ROW, index),
210
+ tabIndex: nav.tabIndexFor(headerFocus(index)),
285
211
  ...ariaAttr(
286
212
  selection.columnMode !== false,
287
213
  "aria-selected",
288
214
  selected
289
215
  ),
290
216
  onFocus: () => {
291
- nav.focusCell(HEADER_ROW, index);
217
+ nav.focusCell(headerFocus(index));
292
218
  },
293
219
  onClick: (event) => {
294
220
  if (drag.justDragged(entry.id)) {
@@ -508,6 +434,7 @@ import {
508
434
  useState as useState2
509
435
  } from "react";
510
436
  import {
437
+ bodyFocus,
511
438
  groupRowId,
512
439
  intentOf as intentOf2
513
440
  } from "@gridkitjs/core";
@@ -517,6 +444,88 @@ import {
517
444
  groupRowFrom
518
445
  } from "@gridkitjs/dom";
519
446
 
447
+ // src/DataGrid/useGridNavigation.ts
448
+ import {
449
+ useEffect,
450
+ useLayoutEffect,
451
+ useState,
452
+ useSyncExternalStore
453
+ } from "react";
454
+ import {
455
+ createGridFocus,
456
+ findBodyRow,
457
+ measurePageSize
458
+ } from "@gridkitjs/dom";
459
+ function tabIndexFor(columnIndex, focusedColumnIndex) {
460
+ return columnIndex === focusedColumnIndex ? 0 : -1;
461
+ }
462
+ function focusedColumnInRow(focus, rowIndex) {
463
+ return focus.area === "body" && focus.rowIndex === rowIndex ? focus.columnIndex : null;
464
+ }
465
+ function sameCell(a, b) {
466
+ if (a.columnIndex !== b.columnIndex) {
467
+ return false;
468
+ }
469
+ return a.area === "header" ? b.area === "header" : focusedColumnInRow(b, a.rowIndex) !== null;
470
+ }
471
+ function useGridNavigation({
472
+ gridRef,
473
+ headerTableRef,
474
+ bodyTableRef,
475
+ rowCount,
476
+ columnCount,
477
+ isSkippableRow,
478
+ virtualRange
479
+ }) {
480
+ const options = {
481
+ rowCount,
482
+ columnCount,
483
+ isSkippableRow,
484
+ virtualRange
485
+ };
486
+ const [gridFocus] = useState(() => createGridFocus(options));
487
+ gridFocus.setOptions(options);
488
+ const focus = useSyncExternalStore(
489
+ gridFocus.subscribe,
490
+ gridFocus.getFocus,
491
+ gridFocus.getFocus
492
+ );
493
+ const [rows] = useState(() => ({
494
+ getHeaderRow: () => headerTableRef.current?.tHead?.rows[0] ?? null,
495
+ getBodyRow: (rowIndex) => findBodyRow(bodyTableRef.current, rowIndex)
496
+ }));
497
+ useLayoutEffect(
498
+ () => gridFocus.attach(rows, gridRef.current),
499
+ [gridFocus, rows, gridRef]
500
+ );
501
+ useEffect(() => {
502
+ gridFocus.focusDrawnCell(focus);
503
+ });
504
+ return {
505
+ focus,
506
+ tabIndexFor: (cell) => sameCell(cell, focus) ? 0 : -1,
507
+ focusCell: gridFocus.focusCell,
508
+ focusCellNow: (next) => {
509
+ gridFocus.focusCell(next);
510
+ gridFocus.focusDrawnCell(gridFocus.getFocus());
511
+ },
512
+ tabStopCell: () => {
513
+ const stop = gridFocus.getFocus();
514
+ const cells = (stop.area === "header" ? rows.getHeaderRow() : rows.getBodyRow(stop.rowIndex))?.cells;
515
+ return cells?.[Math.min(stop.columnIndex, cells.length - 1)] ?? null;
516
+ },
517
+ onKeyDown: (event) => {
518
+ if (gridFocus.handleKey(
519
+ event.key,
520
+ event,
521
+ measurePageSize(bodyTableRef.current)
522
+ )) {
523
+ event.preventDefault();
524
+ }
525
+ }
526
+ };
527
+ }
528
+
520
529
  // src/DataGrid/rowProps.ts
521
530
  var NO_ATTRIBUTES = {};
522
531
  var NO_ROW_PROPS = {
@@ -936,12 +945,14 @@ function GridBody({
936
945
  onFocus: (event) => {
937
946
  const group = groupRowFrom(event.target);
938
947
  if (group !== null) {
939
- nav.focusCell(group.rowIndex, 0);
948
+ nav.focusCell(bodyFocus(group.rowIndex, 0));
940
949
  return;
941
950
  }
942
951
  const found = targetOf(event.target);
943
952
  if (found === null) return;
944
- nav.focusCell(found.position.rowIndex, found.position.columnIndex);
953
+ nav.focusCell(
954
+ bodyFocus(found.position.rowIndex, found.position.columnIndex)
955
+ );
945
956
  },
946
957
  onClick: (event) => {
947
958
  const group = groupRowFrom(event.target);
@@ -1020,7 +1031,7 @@ function GridBody({
1020
1031
  selectedColumnIds: selection.selectedColumnIds,
1021
1032
  selected: selection.selectedRowIds.has(entry.rowId),
1022
1033
  selectedColumnId: selectedCell?.rowId === entry.rowId ? selectedCell.columnId : null,
1023
- focusedColumnIndex: nav.focus.rowIndex === entry.rowIndex ? nav.focus.columnIndex : null,
1034
+ focusedColumnIndex: focusedColumnInRow(nav.focus, entry.rowIndex),
1024
1035
  rowsSelectable: rowMode !== false,
1025
1036
  cellsSelectable: cellMode !== false,
1026
1037
  contextMenu: cellMenu,
@@ -1069,7 +1080,7 @@ function GridBody({
1069
1080
  definitions,
1070
1081
  locale,
1071
1082
  cellMessages,
1072
- focused: nav.focus.rowIndex === entry.rowIndex,
1083
+ focused: focusedColumnInRow(nav.focus, entry.rowIndex) !== null,
1073
1084
  contextMenu: groupMenu
1074
1085
  },
1075
1086
  entry.groupId
@@ -1302,6 +1313,7 @@ import {
1302
1313
 
1303
1314
  // src/DataGrid/useDragReorder.ts
1304
1315
  import {
1316
+ useLayoutEffect as useLayoutEffect2,
1305
1317
  useRef as useRef2,
1306
1318
  useState as useState3
1307
1319
  } from "react";
@@ -1346,6 +1358,10 @@ function useDragReorder({
1346
1358
  const [drag, setDrag] = useState3(NO_DRAG);
1347
1359
  const openedDragId = useRef2(null);
1348
1360
  const startGesture = useGestureSignal();
1361
+ const handlers = useRef2({ resolveTarget, onDrop });
1362
+ useLayoutEffect2(() => {
1363
+ handlers.current = { resolveTarget, onDrop };
1364
+ });
1349
1365
  function justDragged(id) {
1350
1366
  const answer = openedDragId.current === id;
1351
1367
  openedDragId.current = null;
@@ -1355,14 +1371,16 @@ function useDragReorder({
1355
1371
  const started = startGesture(
1356
1372
  grabElement,
1357
1373
  (signal) => startDragReorder(id, grabElement, event, {
1358
- resolveTarget,
1374
+ resolveTarget: (clientX, clientY, movedId) => handlers.current.resolveTarget(clientX, clientY, movedId),
1359
1375
  onState(state) {
1360
- if (state.draggedId !== null) {
1376
+ if (state.kind === "dragging") {
1361
1377
  openedDragId.current = state.draggedId;
1362
1378
  }
1363
1379
  setDrag(state);
1364
1380
  },
1365
- onDrop,
1381
+ onDrop: (target, movedId) => {
1382
+ handlers.current.onDrop(target, movedId);
1383
+ },
1366
1384
  signal
1367
1385
  })
1368
1386
  );
@@ -1370,10 +1388,11 @@ function useDragReorder({
1370
1388
  openedDragId.current = null;
1371
1389
  }
1372
1390
  }
1391
+ const dragging = drag.kind === "dragging" ? drag : null;
1373
1392
  return {
1374
- draggedId: drag.draggedId,
1375
- dropTarget: drag.dropTarget,
1376
- ghostTransform: drag.ghostTransform,
1393
+ draggedId: dragging?.draggedId ?? null,
1394
+ dropTarget: dragging?.dropTarget ?? null,
1395
+ ghostTransform: dragging?.ghostTransform ?? null,
1377
1396
  startDrag,
1378
1397
  justDragged
1379
1398
  };
@@ -1526,7 +1545,8 @@ function GroupByBar({
1526
1545
 
1527
1546
  // src/DataGrid/announcedCallbacks.ts
1528
1547
  import {
1529
- isColumnVisible
1548
+ isColumnVisible,
1549
+ isGroupExpanded
1530
1550
  } from "@gridkitjs/core";
1531
1551
  function announcedCallbacks({
1532
1552
  callbacks,
@@ -1617,20 +1637,21 @@ function announcedCallbacks({
1617
1637
  );
1618
1638
  },
1619
1639
  /**
1620
- * `groupId: null` marks `expandAll`/`collapseAll`, which touch every
1621
- * group in one call rather than one at a time — announced as a single
1622
- * summary instead of naming a group that doesn't apply.
1640
+ * `groupId: null` marks `expandAll`/`collapseAll` and
1641
+ * `setGroupExpansion`, which touch every group in one call rather than
1642
+ * one at a time — announced as a single summary of the mode the groups
1643
+ * now follow, instead of naming a group that doesn't apply.
1623
1644
  */
1624
1645
  onGroupExpansionChange: (event) => {
1625
1646
  callbacks.onGroupExpansionChange?.(event);
1626
1647
  if (event.groupId === null) {
1627
1648
  announce(
1628
- event.expansion.length === 0 ? messages.allGroupsExpanded : messages.allGroupsCollapsed
1649
+ event.expansion.mode === "allExpanded" ? messages.allGroupsExpanded : messages.allGroupsCollapsed
1629
1650
  );
1630
1651
  return;
1631
1652
  }
1632
1653
  announce(
1633
- event.expansion.includes(event.groupId) ? messages.groupCollapsed : messages.groupExpanded
1654
+ isGroupExpanded(event.expansion, event.groupId) ? messages.groupExpanded : messages.groupCollapsed
1634
1655
  );
1635
1656
  },
1636
1657
  onPaginationChange: (event) => {
@@ -1688,13 +1709,13 @@ function useGridCopy({
1688
1709
  return command !== void 0 && runCommand(command, commands.contextFor(target));
1689
1710
  }
1690
1711
  function focusedCell() {
1691
- const { rowIndex, columnIndex } = nav.focus;
1692
- if (rowIndex === HEADER_ROW) {
1712
+ const { focus } = nav;
1713
+ if (focus.area === "header") {
1693
1714
  return null;
1694
1715
  }
1695
1716
  const { pageRows, columns } = controller.getView();
1696
- const entry = pageRows[rowIndex];
1697
- const column = columns[columnIndex];
1717
+ const entry = pageRows[focus.rowIndex];
1718
+ const column = columns[focus.columnIndex];
1698
1719
  return entry === void 0 || "kind" in entry || column === void 0 ? null : { area: "cell", rowId: entry.rowId, columnId: column.id };
1699
1720
  }
1700
1721
  return (event) => {
@@ -1716,22 +1737,36 @@ import {
1716
1737
  runCommand as runCommand2
1717
1738
  } from "@gridkitjs/core";
1718
1739
 
1719
- // src/DataGrid/clipboard/copyToClipboard.ts
1740
+ // src/DataGrid/clipboard/useCopyToClipboard.ts
1741
+ import { useRef as useRef3 } from "react";
1720
1742
  import { writeClipboard } from "@gridkitjs/dom";
1721
- function copyToClipboard(content, { messages, announce }) {
1722
- writeClipboard(content).then(
1723
- () => {
1724
- announce(messages.copied(content.count, content.unit));
1725
- },
1726
- (error) => {
1727
- console.error("DataGrid: the clipboard could not be written.", error);
1728
- announce(messages.copyFailed);
1743
+ function useCopyToClipboard({
1744
+ messages,
1745
+ announce
1746
+ }) {
1747
+ const copies = useRef3(0);
1748
+ return (content) => {
1749
+ copies.current += 1;
1750
+ const copy = copies.current;
1751
+ function announceIfLatest(text) {
1752
+ if (copy === copies.current) {
1753
+ announce(text);
1754
+ }
1729
1755
  }
1730
- );
1756
+ writeClipboard(content).then(
1757
+ () => {
1758
+ announceIfLatest(messages.copied(content.count, content.unit));
1759
+ },
1760
+ (error) => {
1761
+ console.error("DataGrid: the clipboard could not be written.", error);
1762
+ announceIfLatest(messages.copyFailed);
1763
+ }
1764
+ );
1765
+ };
1731
1766
  }
1732
1767
 
1733
1768
  // src/DataGrid/export/useSaveFile.ts
1734
- import { useRef as useRef3 } from "react";
1769
+ import { useRef as useRef4 } from "react";
1735
1770
  import { downloadBlob } from "@gridkitjs/dom";
1736
1771
 
1737
1772
  // src/DataGrid/export/exportApi.ts
@@ -1773,7 +1808,16 @@ function useSaveFile({
1773
1808
  messages,
1774
1809
  announce
1775
1810
  }) {
1776
- const state = useRef3(IDLE);
1811
+ const state = useRef4(IDLE);
1812
+ function canSave() {
1813
+ if (state.current.kind === "writing") {
1814
+ console.error(
1815
+ "DataGrid: an export is still being written, so this one was dropped."
1816
+ );
1817
+ return false;
1818
+ }
1819
+ return true;
1820
+ }
1777
1821
  function fail(reason, error) {
1778
1822
  console.error(`DataGrid: ${reason}`, error);
1779
1823
  announce(messages.exportFailed);
@@ -1785,11 +1829,8 @@ function useSaveFile({
1785
1829
  fail("the export could not be saved.", error);
1786
1830
  }
1787
1831
  }
1788
- return (file) => {
1789
- if (state.current.kind === "writing") {
1790
- console.error(
1791
- "DataGrid: an export is still being written, so this one was dropped."
1792
- );
1832
+ function saveFile(file) {
1833
+ if (!canSave()) {
1793
1834
  return false;
1794
1835
  }
1795
1836
  if (!(file instanceof Promise)) {
@@ -1803,7 +1844,8 @@ function useSaveFile({
1803
1844
  state.current = IDLE;
1804
1845
  });
1805
1846
  return true;
1806
- };
1847
+ }
1848
+ return { saveFile, canSave };
1807
1849
  }
1808
1850
 
1809
1851
  // src/DataGrid/print/printApi.ts
@@ -1841,7 +1883,8 @@ function useGridCommands({
1841
1883
  openPanel
1842
1884
  }) {
1843
1885
  const commands = useMemo3(() => resolveCommands(appCommands), [appCommands]);
1844
- const saveFile = useSaveFile({ messages, announce });
1886
+ const { saveFile, canSave } = useSaveFile({ messages, announce });
1887
+ const writeClipboard2 = useCopyToClipboard({ messages, announce });
1845
1888
  const host = {
1846
1889
  autoFitColumns: (columnIds) => {
1847
1890
  const { columns } = controller.getView();
@@ -1859,9 +1902,8 @@ function useGridCommands({
1859
1902
  openPanel,
1860
1903
  announce,
1861
1904
  saveFile,
1862
- writeClipboard: (content) => {
1863
- copyToClipboard(content, { messages, announce });
1864
- },
1905
+ canSave,
1906
+ writeClipboard: writeClipboard2,
1865
1907
  print: (document2, options) => {
1866
1908
  printGrid(document2, options).catch((error) => {
1867
1909
  console.error("DataGrid: the print failed.", error);
@@ -1896,13 +1938,13 @@ function useGridCommands({
1896
1938
  }
1897
1939
 
1898
1940
  // src/DataGrid/menu/GridMenu.tsx
1899
- import { useLayoutEffect as useLayoutEffect3, useRef as useRef5, useState as useState4 } from "react";
1941
+ import { useLayoutEffect as useLayoutEffect4, useRef as useRef6, useState as useState4 } from "react";
1900
1942
  import {
1901
1943
  attachMenu
1902
1944
  } from "@gridkitjs/dom";
1903
1945
 
1904
1946
  // src/DataGrid/overlay/Overlay.tsx
1905
- import { useLayoutEffect as useLayoutEffect2, useRef as useRef4 } from "react";
1947
+ import { useLayoutEffect as useLayoutEffect3, useRef as useRef5 } from "react";
1906
1948
  import { createPortal as createPortal3 } from "react-dom";
1907
1949
  import {
1908
1950
  attachOverlay
@@ -1933,14 +1975,14 @@ function Overlay({
1933
1975
  onDismiss,
1934
1976
  children
1935
1977
  }) {
1936
- const panelRef = useRef4(null);
1937
- const onDismissRef = useRef4(onDismiss);
1938
- const returnFocusFallbackRef = useRef4(returnFocusFallback);
1939
- useLayoutEffect2(() => {
1978
+ const panelRef = useRef5(null);
1979
+ const onDismissRef = useRef5(onDismiss);
1980
+ const returnFocusFallbackRef = useRef5(returnFocusFallback);
1981
+ useLayoutEffect3(() => {
1940
1982
  onDismissRef.current = onDismiss;
1941
1983
  returnFocusFallbackRef.current = returnFocusFallback;
1942
1984
  });
1943
- useLayoutEffect2(() => {
1985
+ useLayoutEffect3(() => {
1944
1986
  const panel = panelRef.current;
1945
1987
  if (panel === null) {
1946
1988
  return void 0;
@@ -2040,6 +2082,8 @@ function ChevronRightIcon2() {
2040
2082
 
2041
2083
  // src/DataGrid/menu/GridMenu.tsx
2042
2084
  import { Fragment as Fragment2, jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
2085
+ var CLOSED = { kind: "closed" };
2086
+ var ENTRY_GONE = { kind: "entryGone" };
2043
2087
  function itemElement(menu, id) {
2044
2088
  return Array.from(
2045
2089
  menu.querySelectorAll("[data-gridkit-menu-item]")
@@ -2085,15 +2129,15 @@ function GridMenu({
2085
2129
  onCloseSubmenu,
2086
2130
  behaviourRef
2087
2131
  }) {
2088
- const menuRef = useRef5(null);
2089
- const submenuBehaviourRef = useRef5(null);
2090
- const [submenu, setSubmenu] = useState4(null);
2132
+ const menuRef = useRef6(null);
2133
+ const submenuBehaviourRef = useRef6(null);
2134
+ const [submenu, setSubmenu] = useState4(CLOSED);
2091
2135
  const isSubmenu = onCloseSubmenu !== void 0;
2092
- const latest = useRef5({ entries, submenu, onRun, onClose, onCloseSubmenu });
2093
- useLayoutEffect3(() => {
2136
+ const latest = useRef6({ entries, submenu, onRun, onClose, onCloseSubmenu });
2137
+ useLayoutEffect4(() => {
2094
2138
  latest.current = { entries, submenu, onRun, onClose, onCloseSubmenu };
2095
2139
  });
2096
- useLayoutEffect3(() => {
2140
+ useLayoutEffect4(() => {
2097
2141
  const menu = menuRef.current;
2098
2142
  if (menu === null) {
2099
2143
  return void 0;
@@ -2108,7 +2152,8 @@ function GridMenu({
2108
2152
  }
2109
2153
  },
2110
2154
  onOpenSubmenu: (id, { focus }) => {
2111
- if (latest.current.submenu?.id === id) {
2155
+ const open = latest.current.submenu;
2156
+ if (open.kind === "open" && open.id === id) {
2112
2157
  if (focus === "first") {
2113
2158
  submenuBehaviourRef.current?.focusItem(0);
2114
2159
  }
@@ -2116,11 +2161,17 @@ function GridMenu({
2116
2161
  }
2117
2162
  const anchor = itemElement(menu, id);
2118
2163
  if (anchor !== null) {
2119
- setSubmenu({ id, anchor, focus, offset: -topInset(menu) });
2164
+ setSubmenu({
2165
+ kind: "open",
2166
+ id,
2167
+ anchor,
2168
+ focus,
2169
+ offset: -topInset(menu)
2170
+ });
2120
2171
  }
2121
2172
  },
2122
2173
  onCollapseSubmenu: () => {
2123
- setSubmenu(null);
2174
+ setSubmenu(CLOSED);
2124
2175
  },
2125
2176
  onCloseSubmenu: isSubmenu ? () => {
2126
2177
  latest.current.onCloseSubmenu?.();
@@ -2139,14 +2190,24 @@ function GridMenu({
2139
2190
  behaviour.detach();
2140
2191
  };
2141
2192
  }, [isSubmenu, behaviourRef]);
2193
+ useLayoutEffect4(() => {
2194
+ const menu = menuRef.current;
2195
+ if (submenu.kind !== "entryGone" || menu === null || document.activeElement !== document.body) {
2196
+ return;
2197
+ }
2198
+ const item = menu.querySelector(
2199
+ '[data-gridkit-menu-item][tabindex="0"]'
2200
+ ) ?? menu.querySelector("[data-gridkit-menu-item]");
2201
+ item?.focus();
2202
+ }, [submenu]);
2142
2203
  function closeSubmenu() {
2143
- setSubmenu(null);
2204
+ setSubmenu(CLOSED);
2144
2205
  }
2145
- const openEntry = submenu === null ? void 0 : entries.find(
2206
+ const openEntry = submenu.kind === "open" ? entries.find(
2146
2207
  (entry) => entry.type === "submenu" && entry.id === submenu.id
2147
- );
2148
- if (submenu !== null && openEntry === void 0) {
2149
- setSubmenu(null);
2208
+ ) : void 0;
2209
+ if (submenu.kind === "open" && openEntry === void 0) {
2210
+ setSubmenu(ENTRY_GONE);
2150
2211
  }
2151
2212
  return /* @__PURE__ */ jsxs9(Fragment2, { children: [
2152
2213
  /* @__PURE__ */ jsx13(
@@ -2161,14 +2222,14 @@ function GridMenu({
2161
2222
  MenuItem,
2162
2223
  {
2163
2224
  entry,
2164
- expanded: entry.id === submenu?.id
2225
+ expanded: submenu.kind === "open" && entry.id === submenu.id
2165
2226
  },
2166
2227
  entry.id
2167
2228
  )
2168
2229
  )
2169
2230
  }
2170
2231
  ),
2171
- submenu !== null && openEntry !== void 0 && /* @__PURE__ */ jsx13(
2232
+ submenu.kind === "open" && openEntry !== void 0 && /* @__PURE__ */ jsx13(
2172
2233
  Overlay,
2173
2234
  {
2174
2235
  anchor: submenu.anchor,
@@ -2232,8 +2293,8 @@ function GridContextMenu({
2232
2293
  import {
2233
2294
  useCallback,
2234
2295
  useEffect as useEffect3,
2235
- useLayoutEffect as useLayoutEffect4,
2236
- useRef as useRef6
2296
+ useLayoutEffect as useLayoutEffect5,
2297
+ useRef as useRef7
2237
2298
  } from "react";
2238
2299
  import {
2239
2300
  contextMenuEntries,
@@ -2247,7 +2308,8 @@ import {
2247
2308
 
2248
2309
  // src/DataGrid/contextMenu/contextMenuPlaces.ts
2249
2310
  import {
2250
- HEADER_ROW as HEADER_ROW2
2311
+ bodyFocus as bodyFocus2,
2312
+ headerFocus as headerFocus2
2251
2313
  } from "@gridkitjs/core";
2252
2314
  import {
2253
2315
  bodyCellFrom as bodyCellFrom2,
@@ -2257,11 +2319,11 @@ import {
2257
2319
  } from "@gridkitjs/dom";
2258
2320
  function headerCell(parts, columnIndex) {
2259
2321
  const element = parts.headerTable?.tHead?.rows[0]?.cells[columnIndex];
2260
- return element === void 0 ? null : { element, rowIndex: HEADER_ROW2, columnIndex };
2322
+ return element === void 0 ? null : { element, focus: headerFocus2(columnIndex) };
2261
2323
  }
2262
2324
  function bodyCell(parts, rowIndex, columnIndex) {
2263
2325
  const element = findBodyRow2(parts.bodyTable, rowIndex)?.cells[columnIndex];
2264
- return element === void 0 ? null : { element, rowIndex, columnIndex };
2326
+ return element === void 0 ? null : { element, focus: bodyFocus2(rowIndex, columnIndex) };
2265
2327
  }
2266
2328
  function viewOf(element, parts) {
2267
2329
  const root = parts.root?.getBoundingClientRect();
@@ -2391,7 +2453,7 @@ function useContextMenu({
2391
2453
  columnName
2392
2454
  }) {
2393
2455
  const { drawn, close: closeOverlay } = overlay;
2394
- const openings = useRef6(0);
2456
+ const openings = useRef7(0);
2395
2457
  const enabled = contextMenu !== void 0 && contextMenu !== false;
2396
2458
  function parts() {
2397
2459
  const { columns, pageRows } = controller.getView();
@@ -2456,7 +2518,7 @@ function useContextMenu({
2456
2518
  }
2457
2519
  if (cell !== null && document.activeElement !== cell.element) {
2458
2520
  cell.element.focus({ preventScroll: true });
2459
- nav.focusCellNow(cell.rowIndex, cell.columnIndex);
2521
+ nav.focusCellNow(cell.focus);
2460
2522
  }
2461
2523
  openings.current += 1;
2462
2524
  overlay.open({
@@ -2477,8 +2539,8 @@ function useContextMenu({
2477
2539
  const place = placeAt(target, parts());
2478
2540
  return place !== null && openAt(place, point);
2479
2541
  }
2480
- const latestRequest = useRef6(handleRequest);
2481
- useLayoutEffect4(() => {
2542
+ const latestRequest = useRef7(handleRequest);
2543
+ useLayoutEffect5(() => {
2482
2544
  latestRequest.current = handleRequest;
2483
2545
  });
2484
2546
  useEffect3(() => {
@@ -2514,16 +2576,16 @@ function useContextMenu({
2514
2576
  }
2515
2577
 
2516
2578
  // src/DataGrid/overlay/useGridOverlay.ts
2517
- import { useCallback as useCallback2, useLayoutEffect as useLayoutEffect5, useRef as useRef7, useState as useState5 } from "react";
2518
- var CLOSED = { kind: "closed" };
2579
+ import { useCallback as useCallback2, useLayoutEffect as useLayoutEffect6, useRef as useRef8, useState as useState5 } from "react";
2580
+ var CLOSED2 = { kind: "closed" };
2519
2581
  function useGridOverlay({
2520
2582
  nav,
2521
2583
  onContextMenuOpenChange
2522
2584
  }) {
2523
- const [drawn, setDrawn] = useState5(CLOSED);
2524
- const current = useRef7(CLOSED);
2525
- const reportOpenChange = useRef7(onContextMenuOpenChange);
2526
- useLayoutEffect5(() => {
2585
+ const [drawn, setDrawn] = useState5(CLOSED2);
2586
+ const current = useRef8(CLOSED2);
2587
+ const reportOpenChange = useRef8(onContextMenuOpenChange);
2588
+ useLayoutEffect6(() => {
2527
2589
  reportOpenChange.current = onContextMenuOpenChange;
2528
2590
  });
2529
2591
  const show = useCallback2((next) => {
@@ -2540,7 +2602,7 @@ function useGridOverlay({
2540
2602
  const close = useCallback2(
2541
2603
  (kind) => {
2542
2604
  if (current.current.kind === kind) {
2543
- show(CLOSED);
2605
+ show(CLOSED2);
2544
2606
  }
2545
2607
  },
2546
2608
  [show]
@@ -2555,10 +2617,10 @@ function useGridOverlay({
2555
2617
  }
2556
2618
 
2557
2619
  // src/DataGrid/panels/GridPanels.tsx
2558
- import { useRef as useRef14 } from "react";
2620
+ import { useRef as useRef15 } from "react";
2559
2621
 
2560
2622
  // src/DataGrid/columnChooser/ColumnChooser.tsx
2561
- import { useLayoutEffect as useLayoutEffect6, useRef as useRef8, useState as useState6 } from "react";
2623
+ import { useLayoutEffect as useLayoutEffect7, useRef as useRef9, useState as useState6 } from "react";
2562
2624
  import { resolveColumnChooser } from "@gridkitjs/core";
2563
2625
  import { Fragment as Fragment3, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
2564
2626
  function ColumnChooser({
@@ -2566,13 +2628,13 @@ function ColumnChooser({
2566
2628
  messages
2567
2629
  }) {
2568
2630
  const [search, setSearch] = useState6("");
2569
- const showAllRef = useRef8(null);
2631
+ const showAllRef = useRef9(null);
2570
2632
  const { entries, selectAll, toggleAll } = resolveColumnChooser({
2571
2633
  columns: controller.getView().dataColumns,
2572
2634
  visibility: controller.getState().columnVisibility,
2573
2635
  search
2574
2636
  });
2575
- useLayoutEffect6(() => {
2637
+ useLayoutEffect7(() => {
2576
2638
  if (showAllRef.current !== null) {
2577
2639
  showAllRef.current.indeterminate = selectAll === "mixed";
2578
2640
  }
@@ -2643,7 +2705,7 @@ function ColumnChooser({
2643
2705
  }
2644
2706
 
2645
2707
  // src/DataGrid/filterMenu/FilterMenu.tsx
2646
- import { useEffect as useEffect4, useRef as useRef13 } from "react";
2708
+ import { useEffect as useEffect4, useRef as useRef14 } from "react";
2647
2709
  import {
2648
2710
  resolveColumnFilterMenu as resolveColumnFilterMenu2,
2649
2711
  resolveColumnHeaderText,
@@ -2653,10 +2715,10 @@ import {
2653
2715
  // src/DataGrid/filterMenu/ExcelFilterEditor.tsx
2654
2716
  import {
2655
2717
  useImperativeHandle as useImperativeHandle2,
2656
- useLayoutEffect as useLayoutEffect10,
2718
+ useLayoutEffect as useLayoutEffect11,
2657
2719
  useMemo as useMemo4,
2658
2720
  useReducer as useReducer2,
2659
- useRef as useRef12,
2721
+ useRef as useRef13,
2660
2722
  useState as useState9
2661
2723
  } from "react";
2662
2724
  import {
@@ -2671,7 +2733,8 @@ import {
2671
2733
  describeColumnFilter,
2672
2734
  filterDraftChanged,
2673
2735
  filterEditorReducer,
2674
- initialFilterEditorDraft
2736
+ initialFilterEditorDraft,
2737
+ toValuesDraft
2675
2738
  } from "@gridkitjs/core";
2676
2739
  function openValues(filter, columnId, values) {
2677
2740
  const shape = describeColumnFilter(filter, columnId);
@@ -2682,7 +2745,7 @@ function openValues(filter, columnId, values) {
2682
2745
  };
2683
2746
  }
2684
2747
  function initialExcelEditorState(opened) {
2685
- return { opened, draft: opened.draft };
2748
+ return { opened, draft: toValuesDraft(opened.draft) };
2686
2749
  }
2687
2750
  function showsAlike(a, b) {
2688
2751
  return a.shape.kind === b.shape.kind && a.draft.options === b.draft.options && !filterDraftChanged(a.draft, b.draft);
@@ -2691,23 +2754,26 @@ function excelEditorReducer(state, action) {
2691
2754
  if (action.type === "filterChanged") {
2692
2755
  return showsAlike(state.opened, action.opened) ? { ...state, opened: action.opened } : initialExcelEditorState(action.opened);
2693
2756
  }
2694
- return { ...state, draft: filterEditorReducer(state.draft, action) };
2757
+ return {
2758
+ ...state,
2759
+ draft: toValuesDraft(filterEditorReducer(state.draft, action))
2760
+ };
2695
2761
  }
2696
2762
 
2697
2763
  // src/DataGrid/menu/useMenuButton.ts
2698
2764
  import {
2699
- useLayoutEffect as useLayoutEffect7,
2700
- useRef as useRef9,
2765
+ useLayoutEffect as useLayoutEffect8,
2766
+ useRef as useRef10,
2701
2767
  useState as useState7
2702
2768
  } from "react";
2703
- var CLOSED2 = { kind: "closed" };
2769
+ var CLOSED3 = { kind: "closed" };
2704
2770
  function useMenuButton({
2705
2771
  itemCount,
2706
2772
  gap = () => ANCHOR_GAP
2707
2773
  }) {
2708
- const [state, setState] = useState7(CLOSED2);
2709
- const behaviourRef = useRef9(null);
2710
- useLayoutEffect7(() => {
2774
+ const [state, setState] = useState7(CLOSED3);
2775
+ const behaviourRef = useRef10(null);
2776
+ useLayoutEffect8(() => {
2711
2777
  if (state.kind === "open" && state.focusItem > 0) {
2712
2778
  behaviourRef.current?.focusItem(state.focusItem);
2713
2779
  }
@@ -2722,7 +2788,7 @@ function useMenuButton({
2722
2788
  });
2723
2789
  }
2724
2790
  function close() {
2725
- setState(CLOSED2);
2791
+ setState(CLOSED3);
2726
2792
  }
2727
2793
  return {
2728
2794
  state,
@@ -2825,15 +2891,15 @@ import {
2825
2891
  Fragment as Fragment5,
2826
2892
  useId,
2827
2893
  useImperativeHandle,
2828
- useLayoutEffect as useLayoutEffect8,
2894
+ useLayoutEffect as useLayoutEffect9,
2829
2895
  useReducer,
2830
- useRef as useRef10
2896
+ useRef as useRef11
2831
2897
  } from "react";
2832
2898
  import {
2833
2899
  conditionsFromRows as conditionsFromRows2,
2834
2900
  draftToFilter,
2835
2901
  filterDraftChanged as filterDraftChanged2,
2836
- filterEditorReducer as filterEditorReducer3
2902
+ filterEditorReducer as filterEditorReducer2
2837
2903
  } from "@gridkitjs/core";
2838
2904
 
2839
2905
  // src/DataGrid/filterMenu/ConditionRow.tsx
@@ -2959,7 +3025,6 @@ import {
2959
3025
  conditionRowsFrom,
2960
3026
  conditionsFromRows,
2961
3027
  describeColumnFilter as describeColumnFilter2,
2962
- filterEditorReducer as filterEditorReducer2,
2963
3028
  initialFilterEditorDraft as initialFilterEditorDraft2
2964
3029
  } from "@gridkitjs/core";
2965
3030
  var NO_ROWS = [];
@@ -2974,14 +3039,11 @@ function filterDraftShown(shape, rows, columnId, type) {
2974
3039
  ...NO_VALUES,
2975
3040
  columnType: type
2976
3041
  });
2977
- if (shape.kind !== "conditions") {
3042
+ if (draft.kind !== "conditions") {
2978
3043
  return draft;
2979
3044
  }
2980
3045
  const shown = conditionsFromRows(rows, columnId, type);
2981
- return shown.invalid.length > 0 ? draft : filterEditorReducer2(draft, {
2982
- type: "setConditions",
2983
- conditions: shown.conditions
2984
- });
3046
+ return shown.invalid.length > 0 ? draft : { ...draft, conditions: shown.conditions };
2985
3047
  }
2986
3048
  function openConditions(filter, columnId, operators, type, operator) {
2987
3049
  const shape = describeColumnFilter2(filter, columnId);
@@ -3002,14 +3064,14 @@ function openConditions(filter, columnId, operators, type, operator) {
3002
3064
  function initialSimpleEditorState(opened) {
3003
3065
  return { opened, draft: opened.draft, invalid: NO_ROWS };
3004
3066
  }
3005
- function sameConditionsDraft(a, b) {
3067
+ function sameConditionRows(a, b) {
3006
3068
  return a.combinator === b.combinator && a.rows.length === b.rows.length && a.rows.every((row, index) => {
3007
3069
  const other = b.rows[index];
3008
3070
  return other !== void 0 && row.operator === other.operator && row.text === other.text && row.textTo === other.textTo;
3009
3071
  });
3010
3072
  }
3011
3073
  function showsAlike2(a, b) {
3012
- return a.custom === b.custom && sameConditionsDraft(a.draft, b.draft);
3074
+ return a.custom === b.custom && sameConditionRows(a.draft, b.draft);
3013
3075
  }
3014
3076
  function simpleEditorReducer(state, action) {
3015
3077
  switch (action.type) {
@@ -3095,11 +3157,11 @@ function SimpleFilterEditor({
3095
3157
  if (filter !== opened.over) {
3096
3158
  dispatch({ type: "filterChanged", opened: open(filter) });
3097
3159
  }
3098
- const rowElements = useRef10([]);
3160
+ const rowElements = useRef11([]);
3099
3161
  const invalidMessageId = useId();
3100
3162
  const combinatorName = useId();
3101
3163
  function applyConditions(conditions) {
3102
- const applied = filterEditorReducer3(opened.filterDraft, {
3164
+ const applied = filterEditorReducer2(opened.filterDraft, {
3103
3165
  type: "setConditions",
3104
3166
  conditions,
3105
3167
  combinator: draft.combinator
@@ -3123,14 +3185,14 @@ function SimpleFilterEditor({
3123
3185
  applyConditions(parsed.conditions);
3124
3186
  return true;
3125
3187
  }
3126
- if (sameConditionsDraft(draft, opened.draft) && !unreadable.includes(true)) {
3188
+ if (sameConditionRows(draft, opened.draft) && !unreadable.includes(true)) {
3127
3189
  return true;
3128
3190
  }
3129
3191
  dispatch({ type: "markInvalid", rows: marked });
3130
3192
  return false;
3131
3193
  }
3132
3194
  }));
3133
- useLayoutEffect8(() => {
3195
+ useLayoutEffect9(() => {
3134
3196
  const [first] = invalid;
3135
3197
  if (first !== void 0) {
3136
3198
  rowElements.current[first]?.querySelector('[aria-invalid="true"]')?.focus();
@@ -3177,7 +3239,7 @@ function SimpleFilterEditor({
3177
3239
  }
3178
3240
 
3179
3241
  // src/DataGrid/filterMenu/ValueChecklist.tsx
3180
- import { useLayoutEffect as useLayoutEffect9, useRef as useRef11, useState as useState8 } from "react";
3242
+ import { useLayoutEffect as useLayoutEffect10, useRef as useRef12, useState as useState8 } from "react";
3181
3243
  import {
3182
3244
  attachChecklist,
3183
3245
  createRowVirtualizer
@@ -3197,15 +3259,15 @@ function ValueChecklist({
3197
3259
  label,
3198
3260
  onToggle
3199
3261
  }) {
3200
- const listRef = useRef11(null);
3201
- const checklistRef = useRef11(null);
3262
+ const listRef = useRef12(null);
3263
+ const checklistRef = useRef12(null);
3202
3264
  const [virtualizer, setVirtualizer] = useState8(null);
3203
3265
  const [range, setRange] = useState8(NO_RANGE);
3204
- const latest = useRef11({ items, onToggle });
3205
- useLayoutEffect9(() => {
3266
+ const latest = useRef12({ items, onToggle });
3267
+ useLayoutEffect10(() => {
3206
3268
  latest.current = { items, onToggle };
3207
3269
  });
3208
- useLayoutEffect9(() => {
3270
+ useLayoutEffect10(() => {
3209
3271
  const list = listRef.current;
3210
3272
  if (list === null) {
3211
3273
  return void 0;
@@ -3234,7 +3296,7 @@ function ValueChecklist({
3234
3296
  rows.destroy();
3235
3297
  };
3236
3298
  }, []);
3237
- useLayoutEffect9(() => {
3299
+ useLayoutEffect10(() => {
3238
3300
  virtualizer?.setRowCount(items.length);
3239
3301
  checklistRef.current?.setCount(items.length);
3240
3302
  }, [virtualizer, items.length]);
@@ -3310,10 +3372,10 @@ function ExcelFilterEditor({
3310
3372
  dispatch({ type: "filterChanged", opened: open(filter) });
3311
3373
  }
3312
3374
  const [mode, setMode] = useState9(OPENED_ON_VALUES);
3313
- const conditions = useRef12(null);
3314
- const conditionsFocus = useRef12(null);
3315
- const operatorButton = useRef12(null);
3316
- const selectAllRef = useRef12(null);
3375
+ const conditions = useRef13(null);
3376
+ const conditionsFocus = useRef13(null);
3377
+ const operatorButton = useRef13(null);
3378
+ const selectAllRef = useRef13(null);
3317
3379
  const selectAll = useMemo4(() => selectAllState(draft), [draft]);
3318
3380
  const checklist = useMemo4(
3319
3381
  () => filterChecklist(draft, {
@@ -3322,12 +3384,12 @@ function ExcelFilterEditor({
3322
3384
  }),
3323
3385
  [draft, menu.valueLimit, messages.filterBlanks]
3324
3386
  );
3325
- useLayoutEffect10(() => {
3387
+ useLayoutEffect11(() => {
3326
3388
  if (selectAllRef.current !== null) {
3327
3389
  selectAllRef.current.indeterminate = selectAll === "mixed";
3328
3390
  }
3329
3391
  });
3330
- useLayoutEffect10(() => {
3392
+ useLayoutEffect11(() => {
3331
3393
  if (mode.kind === "condition") {
3332
3394
  conditionsFocus.current?.focus();
3333
3395
  } else if (mode.focusOnMount) {
@@ -3459,7 +3521,7 @@ function FilterMenu({
3459
3521
  applyFilter,
3460
3522
  columnValues
3461
3523
  }) {
3462
- const editor = useRef13(null);
3524
+ const editor = useRef14(null);
3463
3525
  const column = target.area === "header" ? controller.getView().dataColumns.find((entry) => entry.id === target.columnId) : void 0;
3464
3526
  const menu = column === void 0 ? null : resolveColumnFilterMenu2(controller.getOptions(), column.column);
3465
3527
  useEffect4(() => {
@@ -3622,7 +3684,7 @@ function GridPanels({
3622
3684
  commands,
3623
3685
  messages
3624
3686
  }) {
3625
- const initialFocus = useRef14(null);
3687
+ const initialFocus = useRef15(null);
3626
3688
  const applyFilter = useApplyFilter(
3627
3689
  controller,
3628
3690
  messages,
@@ -3691,7 +3753,7 @@ function panelApi(panels, controller) {
3691
3753
  }
3692
3754
 
3693
3755
  // src/DataGrid/panels/useGridPanels.ts
3694
- import { useRef as useRef15 } from "react";
3756
+ import { useRef as useRef16 } from "react";
3695
3757
  function toolbarItem(root, itemId) {
3696
3758
  const items = root.querySelectorAll(
3697
3759
  ":scope > .gridkit-toolbar > [data-gridkit-toolbar-item]"
@@ -3717,7 +3779,7 @@ function useGridPanels({
3717
3779
  headerTableRef,
3718
3780
  overlay
3719
3781
  }) {
3720
- const openings = useRef15(0);
3782
+ const openings = useRef16(0);
3721
3783
  function placeFor(root, target) {
3722
3784
  const element = target.area === "toolbar" ? toolbarItem(root, target.itemId) : target.area === "header" ? headerCell2(headerTableRef.current, target.columnId) : null;
3723
3785
  if (element !== null) {
@@ -3763,7 +3825,7 @@ function useGridPanels({
3763
3825
  }
3764
3826
 
3765
3827
  // src/DataGrid/toolbar/GridToolbar.tsx
3766
- import { useLayoutEffect as useLayoutEffect12, useRef as useRef18 } from "react";
3828
+ import { useLayoutEffect as useLayoutEffect13, useRef as useRef19 } from "react";
3767
3829
  import {
3768
3830
  resolveToolbar,
3769
3831
  splitToolbarItems,
@@ -3832,7 +3894,7 @@ function ToolbarMenuButton({
3832
3894
  }
3833
3895
 
3834
3896
  // src/DataGrid/toolbar/ToolbarSearch.tsx
3835
- import { useEffect as useEffect6, useRef as useRef16, useState as useState12 } from "react";
3897
+ import { useEffect as useEffect6, useRef as useRef17, useState as useState12 } from "react";
3836
3898
  import {
3837
3899
  searchTextOf,
3838
3900
  setSearchText
@@ -3848,7 +3910,7 @@ function ToolbarSearch({
3848
3910
  }) {
3849
3911
  const applied = searchTextOf(controller.getState().filter);
3850
3912
  const [draft, setDraft] = useState12(null);
3851
- const timer = useRef16(void 0);
3913
+ const timer = useRef17(void 0);
3852
3914
  const announceWhenDrawn = useAnnounceWhenDrawn(announce);
3853
3915
  const text = draft !== null && draft.over === applied ? draft.text : applied;
3854
3916
  function apply(next, over) {
@@ -3904,12 +3966,12 @@ function ToolbarSearch({
3904
3966
  }
3905
3967
 
3906
3968
  // src/DataGrid/toolbar/useToolbarOverflow.ts
3907
- import { useLayoutEffect as useLayoutEffect11, useRef as useRef17, useState as useState13 } from "react";
3969
+ import { useLayoutEffect as useLayoutEffect12, useRef as useRef18, useState as useState13 } from "react";
3908
3970
  import { observeToolbarOverflow } from "@gridkitjs/dom";
3909
3971
  function useToolbarOverflow(toolbarRef, items) {
3910
3972
  const [fit, setFit] = useState13(items.length);
3911
- const overflow = useRef17(null);
3912
- const measuredLayout = useRef17("");
3973
+ const overflow = useRef18(null);
3974
+ const measuredLayout = useRef18("");
3913
3975
  const layout = JSON.stringify(
3914
3976
  items.map((item) => [
3915
3977
  item.type,
@@ -3917,7 +3979,7 @@ function useToolbarOverflow(toolbarRef, items) {
3917
3979
  "label" in item ? item.label : null
3918
3980
  ])
3919
3981
  );
3920
- useLayoutEffect11(() => {
3982
+ useLayoutEffect12(() => {
3921
3983
  const toolbar = toolbarRef.current;
3922
3984
  if (toolbar === null || layout === measuredLayout.current) {
3923
3985
  return;
@@ -3930,7 +3992,7 @@ function useToolbarOverflow(toolbarRef, items) {
3930
3992
  overflow.current.update(options);
3931
3993
  }
3932
3994
  }, [toolbarRef, layout, items]);
3933
- useLayoutEffect11(
3995
+ useLayoutEffect12(
3934
3996
  () => () => {
3935
3997
  overflow.current?.detach();
3936
3998
  overflow.current = null;
@@ -4016,7 +4078,7 @@ function Toolbar({
4016
4078
  messages,
4017
4079
  announce
4018
4080
  }) {
4019
- const toolbarRef = useRef18(null);
4081
+ const toolbarRef = useRef19(null);
4020
4082
  const items = resolveToolbar(entries, {
4021
4083
  commands: commands.commands,
4022
4084
  contextFor: commands.contextFor,
@@ -4028,7 +4090,7 @@ function Toolbar({
4028
4090
  );
4029
4091
  const fit = useToolbarOverflow(toolbarRef, items);
4030
4092
  const { shown, overflow } = splitToolbarItems(items, fit);
4031
- useLayoutEffect12(() => {
4093
+ useLayoutEffect13(() => {
4032
4094
  const toolbar = toolbarRef.current;
4033
4095
  return toolbar === null ? void 0 : attachToolbar(toolbar);
4034
4096
  }, []);
@@ -4284,11 +4346,11 @@ function useColumnResize({
4284
4346
  }
4285
4347
 
4286
4348
  // src/DataGrid/useElementWidth.ts
4287
- import { useLayoutEffect as useLayoutEffect13, useState as useState15 } from "react";
4349
+ import { useLayoutEffect as useLayoutEffect14, useState as useState15 } from "react";
4288
4350
  import { observeElementWidth } from "@gridkitjs/dom";
4289
4351
  function useElementWidth(ref, enabled) {
4290
4352
  const [width, setWidth] = useState15(null);
4291
- useLayoutEffect13(() => {
4353
+ useLayoutEffect14(() => {
4292
4354
  const element = ref.current;
4293
4355
  if (element === null || !enabled) {
4294
4356
  return void 0;
@@ -4317,14 +4379,14 @@ function useGridController(options) {
4317
4379
  }
4318
4380
 
4319
4381
  // src/DataGrid/useInfiniteScroll.ts
4320
- import { useEffect as useEffect7, useRef as useRef19 } from "react";
4382
+ import { useEffect as useEffect7, useRef as useRef20 } from "react";
4321
4383
  import { attachInfiniteScroll } from "@gridkitjs/dom";
4322
4384
  function useInfiniteScroll({
4323
4385
  rootRef,
4324
4386
  sentinelRef,
4325
4387
  config
4326
4388
  }) {
4327
- const scroll = useRef19(null);
4389
+ const scroll = useRef20(null);
4328
4390
  useEffect7(() => {
4329
4391
  const root = rootRef.current;
4330
4392
  if (root === null) {
@@ -4352,11 +4414,11 @@ function useInfiniteScroll({
4352
4414
  }
4353
4415
 
4354
4416
  // src/DataGrid/useLiveAnnouncer.ts
4355
- import { useCallback as useCallback3, useLayoutEffect as useLayoutEffect14, useRef as useRef20 } from "react";
4417
+ import { useCallback as useCallback3, useLayoutEffect as useLayoutEffect15, useRef as useRef21 } from "react";
4356
4418
  import { createLiveAnnouncer } from "@gridkitjs/dom";
4357
4419
  function useLiveAnnouncer(containerRef) {
4358
- const announcer = useRef20(null);
4359
- useLayoutEffect14(() => {
4420
+ const announcer = useRef21(null);
4421
+ useLayoutEffect15(() => {
4360
4422
  const container = containerRef.current;
4361
4423
  if (container === null) {
4362
4424
  return void 0;
@@ -4374,14 +4436,24 @@ function useLiveAnnouncer(containerRef) {
4374
4436
  }
4375
4437
 
4376
4438
  // src/DataGrid/useRowVirtualizer.ts
4377
- import { useLayoutEffect as useLayoutEffect15, useState as useState17 } from "react";
4439
+ import { useLayoutEffect as useLayoutEffect16, useRef as useRef22, useState as useState17 } from "react";
4378
4440
  import { createRowVirtualizer as createRowVirtualizer2 } from "@gridkitjs/dom";
4379
- var EMPTY_RANGE = {
4380
- startIndex: 0,
4381
- endIndex: -1,
4382
- offsetBefore: 0,
4383
- offsetAfter: 0
4441
+ var ALL_ROWS = { kind: "allRows" };
4442
+ var NO_ROWS3 = {
4443
+ kind: "range",
4444
+ range: { startIndex: 0, endIndex: -1, offsetBefore: 0, offsetAfter: 0 }
4384
4445
  };
4446
+ function rangeOf(rowWindow, rowCount) {
4447
+ if (rowWindow.kind === "range") {
4448
+ return rowWindow.range;
4449
+ }
4450
+ return {
4451
+ startIndex: 0,
4452
+ endIndex: rowCount - 1,
4453
+ offsetBefore: 0,
4454
+ offsetAfter: 0
4455
+ };
4456
+ }
4385
4457
  function ignoreRow() {
4386
4458
  return () => void 0;
4387
4459
  }
@@ -4393,8 +4465,18 @@ function useRowVirtualizer({
4393
4465
  overscan
4394
4466
  }) {
4395
4467
  const [virtualizer, setVirtualizer] = useState17(null);
4396
- const [range, setRange] = useState17(EMPTY_RANGE);
4397
- useLayoutEffect15(() => {
4468
+ const instance = useRef22(null);
4469
+ const rowCount = useRef22(rows.length);
4470
+ const [rowWindow, setRowWindow] = useState17(enabled ? NO_ROWS3 : ALL_ROWS);
4471
+ if (!enabled && rowWindow.kind !== "allRows") {
4472
+ setRowWindow(ALL_ROWS);
4473
+ }
4474
+ useLayoutEffect16(() => {
4475
+ rowCount.current = rows.length;
4476
+ instance.current?.setRowCount(rows.length);
4477
+ instance.current?.resetHeights();
4478
+ }, [rows]);
4479
+ useLayoutEffect16(() => {
4398
4480
  const element = bodyScrollRef.current;
4399
4481
  if (!enabled || element === null) {
4400
4482
  return void 0;
@@ -4402,17 +4484,18 @@ function useRowVirtualizer({
4402
4484
  const created = createRowVirtualizer2(element, {
4403
4485
  estimatedRowHeight,
4404
4486
  overscan,
4405
- onRange: setRange
4487
+ onRange: (range2) => {
4488
+ setRowWindow({ kind: "range", range: range2 });
4489
+ }
4406
4490
  });
4491
+ created.setRowCount(rowCount.current);
4492
+ instance.current = created;
4407
4493
  setVirtualizer(created);
4408
4494
  return () => {
4409
4495
  created.destroy();
4410
4496
  };
4411
4497
  }, [enabled, bodyScrollRef, estimatedRowHeight, overscan]);
4412
- useLayoutEffect15(() => {
4413
- virtualizer?.setRowCount(rows.length);
4414
- virtualizer?.resetHeights();
4415
- }, [virtualizer, rows]);
4498
+ const range = rangeOf(rowWindow, rows.length);
4416
4499
  return {
4417
4500
  startIndex: range.startIndex,
4418
4501
  endIndex: range.endIndex,
@@ -4420,7 +4503,7 @@ function useRowVirtualizer({
4420
4503
  offsetAfter: range.offsetAfter,
4421
4504
  measureRow: virtualizer?.measureRow ?? ignoreRow,
4422
4505
  scrollToIndex: (index, options) => {
4423
- virtualizer?.scrollToIndex(index, options);
4506
+ instance.current?.scrollToIndex(index, options);
4424
4507
  }
4425
4508
  };
4426
4509
  }
@@ -4451,6 +4534,19 @@ function selectedRowsReader(controller) {
4451
4534
  return last.selected;
4452
4535
  };
4453
4536
  }
4537
+ function focusAt(rowIndex, columnIndex) {
4538
+ return rowIndex < 0 ? headerFocus3(columnIndex) : bodyFocus3(rowIndex, columnIndex);
4539
+ }
4540
+ function focusedCellReader() {
4541
+ let last;
4542
+ return (focus) => {
4543
+ if (last?.focus !== focus) {
4544
+ const rowIndex = focus.area === "header" ? -1 : focus.rowIndex;
4545
+ last = { focus, cell: { rowIndex, columnIndex: focus.columnIndex } };
4546
+ }
4547
+ return last.cell;
4548
+ };
4549
+ }
4454
4550
  function DataGrid(props) {
4455
4551
  const {
4456
4552
  borders,
@@ -4483,14 +4579,14 @@ function DataGrid(props) {
4483
4579
  const hoverRows = hoverable?.rows ?? true;
4484
4580
  const hoverColumns = hoverable?.columns ?? true;
4485
4581
  const hoverCells = hoverable?.cells ?? true;
4486
- const viewportRef = useRef21(null);
4487
- const gridRef = useRef21(null);
4488
- const headerTableRef = useRef21(null);
4489
- const bodyTableRef = useRef21(null);
4490
- const bodyScrollRef = useRef21(null);
4491
- const sentinelRef = useRef21(null);
4582
+ const viewportRef = useRef23(null);
4583
+ const gridRef = useRef23(null);
4584
+ const headerTableRef = useRef23(null);
4585
+ const bodyTableRef = useRef23(null);
4586
+ const bodyScrollRef = useRef23(null);
4587
+ const sentinelRef = useRef23(null);
4492
4588
  const viewportWidth = useElementWidth(viewportRef, resizeMode === "fit");
4493
- const subscribersRef = useRef21(/* @__PURE__ */ new Set());
4589
+ const subscribersRef = useRef23(/* @__PURE__ */ new Set());
4494
4590
  const gridId = useId2();
4495
4591
  const announce = useLiveAnnouncer(viewportRef);
4496
4592
  const messages = useMemo5(
@@ -4510,6 +4606,7 @@ function DataGrid(props) {
4510
4606
  });
4511
4607
  const [readPagination] = useState18(() => paginationReader(controller));
4512
4608
  const [readSelectedRows] = useState18(() => selectedRowsReader(controller));
4609
+ const [readFocusedCell] = useState18(focusedCellReader);
4513
4610
  const virtualizer = useRowVirtualizer({
4514
4611
  enabled: virtualized,
4515
4612
  rows: view.pageRows,
@@ -4629,7 +4726,7 @@ function DataGrid(props) {
4629
4726
  announce(
4630
4727
  messages.columnMoved(columnName(movedId), position + 1, shown.length)
4631
4728
  );
4632
- nav.focusCell(HEADER_ROW, position);
4729
+ nav.focusCell(headerFocus3(position));
4633
4730
  }
4634
4731
  const drag = useColumnDrag({
4635
4732
  order: displayedIds,
@@ -4701,10 +4798,12 @@ function DataGrid(props) {
4701
4798
  getSelectedRows: readSelectedRows,
4702
4799
  getColumnSelection: () => controller.getState().columnSelection,
4703
4800
  getCellSelection: () => controller.getState().cellSelection,
4704
- getFocusedCell: () => nav.focus,
4801
+ getFocusedCell: () => readFocusedCell(nav.focus),
4705
4802
  getState: controller.getState,
4706
4803
  restoreState: controller.restoreState,
4707
- focusCell: nav.focusCell,
4804
+ focusCell: (rowIndex, columnIndex) => {
4805
+ nav.focusCell(focusAt(rowIndex, columnIndex));
4806
+ },
4708
4807
  clearSelection: controller.clearSelection,
4709
4808
  selectAllRows: controller.selectAllRows,
4710
4809
  selectRows: controller.selectRows,
@@ -4969,7 +5068,7 @@ import { useCallback as useCallback5 } from "react";
4969
5068
  import {
4970
5069
  useCallback as useCallback4,
4971
5070
  useEffect as useEffect9,
4972
- useRef as useRef22,
5071
+ useRef as useRef24,
4973
5072
  useSyncExternalStore as useSyncExternalStore3
4974
5073
  } from "react";
4975
5074
  function subscribeTo(api, listener) {
@@ -4986,7 +5085,7 @@ function unsubscribe(subscription) {
4986
5085
  }
4987
5086
  }
4988
5087
  function useGridSnapshot(gridRef, getSnapshot, fallback) {
4989
- const subscription = useRef22(null);
5088
+ const subscription = useRef24(null);
4990
5089
  const subscribe = useCallback4(
4991
5090
  (listener) => {
4992
5091
  subscription.current = subscribeTo(gridRef.current, listener);
@@ -5054,8 +5153,11 @@ function usePaginationState(gridRef) {
5054
5153
 
5055
5154
  // src/DataGrid/hooks/useGroupByState.ts
5056
5155
  import { useCallback as useCallback6 } from "react";
5156
+ import {
5157
+ ALL_EXPANDED
5158
+ } from "@gridkitjs/core";
5057
5159
  var FALLBACK_GROUP_BY = [];
5058
- var FALLBACK_EXPANSION = [];
5160
+ var FALLBACK_EXPANSION = ALL_EXPANDED;
5059
5161
  function useGroupByState(gridRef) {
5060
5162
  const groupBy = useGridSnapshot(
5061
5163
  gridRef,