@gridkitjs/react 0.0.0-dev-20261107212842 → 0.0.0-dev-20261108231045

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
@@ -2,12 +2,12 @@
2
2
 
3
3
  // src/DataGrid/DataGrid.tsx
4
4
  import {
5
- useEffect as useEffect7,
5
+ useEffect as useEffect8,
6
6
  useId as useId2,
7
7
  useImperativeHandle as useImperativeHandle3,
8
8
  useMemo as useMemo5,
9
- useRef as useRef21,
10
- useState as useState20
9
+ useRef as useRef22,
10
+ useState as useState18
11
11
  } from "react";
12
12
  import {
13
13
  moveColumnBefore,
@@ -122,6 +122,7 @@ function tabIndexFor(columnIndex, focusedColumnIndex) {
122
122
  return columnIndex === focusedColumnIndex ? 0 : -1;
123
123
  }
124
124
  function useGridNavigation({
125
+ gridRef,
125
126
  headerTableRef,
126
127
  bodyTableRef,
127
128
  rowCount,
@@ -146,7 +147,10 @@ function useGridNavigation({
146
147
  getHeaderRow: () => headerTableRef.current?.tHead?.rows[0] ?? null,
147
148
  getBodyRow: (rowIndex) => findBodyRow(bodyTableRef.current, rowIndex)
148
149
  }));
149
- useLayoutEffect(() => gridFocus.attach(rows), [gridFocus, rows]);
150
+ useLayoutEffect(
151
+ () => gridFocus.attach(rows, gridRef.current),
152
+ [gridFocus, rows, gridRef]
153
+ );
150
154
  useEffect(() => {
151
155
  gridFocus.focusDrawnCell(focus);
152
156
  });
@@ -161,9 +165,10 @@ function useGridNavigation({
161
165
  gridFocus.focusCell(rowIndex, columnIndex);
162
166
  gridFocus.focusDrawnCell(gridFocus.getFocus());
163
167
  },
164
- focusTabStop: () => {
165
- const cells = (focus.rowIndex === HEADER_ROW ? rows.getHeaderRow() : rows.getBodyRow(focus.rowIndex))?.cells;
166
- cells?.[Math.min(focus.columnIndex, cells.length - 1)]?.focus();
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;
167
172
  },
168
173
  onKeyDown: (event) => {
169
174
  if (gridFocus.handleKey(
@@ -236,7 +241,7 @@ function GridHeader({
236
241
  const beforeId = drag.dropTarget?.kind === "column-order" ? drag.dropTarget.beforeId : void 0;
237
242
  const draggedEntry = columns.find((entry) => entry.id === drag.draggedColumnId) ?? null;
238
243
  function toggleFilterMenu(columnId) {
239
- const { panel } = panels;
244
+ const panel = panels.current();
240
245
  if (panel?.kind === "filter" && panel.target.area === "header" && panel.target.columnId === columnId) {
241
246
  panels.close();
242
247
  } else {
@@ -286,7 +291,7 @@ function GridHeader({
286
291
  nav.focusCell(HEADER_ROW, index);
287
292
  },
288
293
  onClick: (event) => {
289
- if (drag.justDragged()) {
294
+ if (drag.justDragged(entry.id)) {
290
295
  return;
291
296
  }
292
297
  if (event.target instanceof Element && (event.target.closest(".header-resize-handle") !== null || event.target.closest(".header-sort-toggle") !== null || event.target.closest(".header-group-toggle") !== null || event.target.closest(".header-filter-toggle") !== null)) {
@@ -1297,35 +1302,73 @@ import {
1297
1302
 
1298
1303
  // src/DataGrid/useDragReorder.ts
1299
1304
  import {
1300
- useRef,
1305
+ useRef as useRef2,
1301
1306
  useState as useState3
1302
1307
  } from "react";
1303
1308
  import {
1304
1309
  NO_DRAG,
1305
1310
  startDragReorder
1306
1311
  } from "@gridkitjs/dom";
1312
+
1313
+ // src/DataGrid/useGestureSignal.ts
1314
+ import { useEffect as useEffect2, useRef } from "react";
1315
+ function useGestureSignal() {
1316
+ const gesture = useRef(null);
1317
+ useEffect2(() => {
1318
+ const current = gesture.current;
1319
+ if (current !== null && !current.element.isConnected) {
1320
+ gesture.current = null;
1321
+ current.controller.abort();
1322
+ }
1323
+ });
1324
+ useEffect2(
1325
+ () => () => {
1326
+ gesture.current?.controller.abort();
1327
+ },
1328
+ []
1329
+ );
1330
+ return function startGesture(element, start) {
1331
+ const controller = new AbortController();
1332
+ if (!start(controller.signal)) {
1333
+ return false;
1334
+ }
1335
+ gesture.current?.controller.abort();
1336
+ gesture.current = { element, controller };
1337
+ return true;
1338
+ };
1339
+ }
1340
+
1341
+ // src/DataGrid/useDragReorder.ts
1307
1342
  function useDragReorder({
1308
1343
  resolveTarget,
1309
1344
  onDrop
1310
1345
  }) {
1311
1346
  const [drag, setDrag] = useState3(NO_DRAG);
1312
- const dragged = useRef(false);
1313
- function justDragged() {
1314
- const answer = dragged.current;
1315
- dragged.current = false;
1347
+ const openedDragId = useRef2(null);
1348
+ const startGesture = useGestureSignal();
1349
+ function justDragged(id) {
1350
+ const answer = openedDragId.current === id;
1351
+ openedDragId.current = null;
1316
1352
  return answer;
1317
1353
  }
1318
1354
  function startDrag(id, grabElement, event) {
1319
- startDragReorder(id, grabElement, event, {
1320
- resolveTarget,
1321
- onState(state) {
1322
- if (state.draggedId !== null) {
1323
- dragged.current = true;
1324
- }
1325
- setDrag(state);
1326
- },
1327
- onDrop
1328
- });
1355
+ const started = startGesture(
1356
+ grabElement,
1357
+ (signal) => startDragReorder(id, grabElement, event, {
1358
+ resolveTarget,
1359
+ onState(state) {
1360
+ if (state.draggedId !== null) {
1361
+ openedDragId.current = state.draggedId;
1362
+ }
1363
+ setDrag(state);
1364
+ },
1365
+ onDrop,
1366
+ signal
1367
+ })
1368
+ );
1369
+ if (started) {
1370
+ openedDragId.current = null;
1371
+ }
1329
1372
  }
1330
1373
  return {
1331
1374
  draggedId: drag.draggedId,
@@ -1353,8 +1396,7 @@ function useGroupByDrag({
1353
1396
  ghostTransform: drag.ghostTransform,
1354
1397
  startDrag: (columnId, event) => {
1355
1398
  drag.startDrag(columnId, event.currentTarget, event);
1356
- },
1357
- justDragged: drag.justDragged
1399
+ }
1358
1400
  };
1359
1401
  }
1360
1402
 
@@ -1689,7 +1731,7 @@ function copyToClipboard(content, { messages, announce }) {
1689
1731
  }
1690
1732
 
1691
1733
  // src/DataGrid/export/useSaveFile.ts
1692
- import { useRef as useRef2 } from "react";
1734
+ import { useRef as useRef3 } from "react";
1693
1735
  import { downloadBlob } from "@gridkitjs/dom";
1694
1736
 
1695
1737
  // src/DataGrid/export/exportApi.ts
@@ -1732,7 +1774,7 @@ function useSaveFile({
1732
1774
  messages,
1733
1775
  announce
1734
1776
  }) {
1735
- const writingRef = useRef2(false);
1777
+ const writingRef = useRef3(false);
1736
1778
  return (file) => {
1737
1779
  if (writingRef.current) {
1738
1780
  console.error(
@@ -1843,13 +1885,13 @@ function useGridCommands({
1843
1885
  }
1844
1886
 
1845
1887
  // src/DataGrid/menu/GridMenu.tsx
1846
- import { useLayoutEffect as useLayoutEffect3, useRef as useRef4, useState as useState4 } from "react";
1888
+ import { useLayoutEffect as useLayoutEffect3, useRef as useRef5, useState as useState4 } from "react";
1847
1889
  import {
1848
1890
  attachMenu
1849
1891
  } from "@gridkitjs/dom";
1850
1892
 
1851
1893
  // src/DataGrid/overlay/Overlay.tsx
1852
- import { useLayoutEffect as useLayoutEffect2, useRef as useRef3 } from "react";
1894
+ import { useLayoutEffect as useLayoutEffect2, useRef as useRef4 } from "react";
1853
1895
  import { createPortal as createPortal3 } from "react-dom";
1854
1896
  import {
1855
1897
  attachOverlay
@@ -1873,16 +1915,19 @@ function Overlay({
1873
1915
  offset,
1874
1916
  initialFocus,
1875
1917
  returnFocusTo,
1918
+ returnFocusFallback,
1876
1919
  ignoreScrollAfterInput,
1877
1920
  trapFocus,
1878
1921
  themeClassName,
1879
1922
  onDismiss,
1880
1923
  children
1881
1924
  }) {
1882
- const panelRef = useRef3(null);
1883
- const onDismissRef = useRef3(onDismiss);
1925
+ const panelRef = useRef4(null);
1926
+ const onDismissRef = useRef4(onDismiss);
1927
+ const returnFocusFallbackRef = useRef4(returnFocusFallback);
1884
1928
  useLayoutEffect2(() => {
1885
1929
  onDismissRef.current = onDismiss;
1930
+ returnFocusFallbackRef.current = returnFocusFallback;
1886
1931
  });
1887
1932
  useLayoutEffect2(() => {
1888
1933
  const panel = panelRef.current;
@@ -1895,6 +1940,7 @@ function Overlay({
1895
1940
  offset,
1896
1941
  initialFocus: attachedFocus(initialFocus),
1897
1942
  returnFocusTo,
1943
+ returnFocusFallback: () => returnFocusFallbackRef.current?.() ?? null,
1898
1944
  ignoreScrollAfterInput,
1899
1945
  trapFocus,
1900
1946
  onDismiss: (reason) => {
@@ -2028,11 +2074,11 @@ function GridMenu({
2028
2074
  onCloseSubmenu,
2029
2075
  behaviourRef
2030
2076
  }) {
2031
- const menuRef = useRef4(null);
2032
- const submenuBehaviourRef = useRef4(null);
2077
+ const menuRef = useRef5(null);
2078
+ const submenuBehaviourRef = useRef5(null);
2033
2079
  const [submenu, setSubmenu] = useState4(null);
2034
2080
  const isSubmenu = onCloseSubmenu !== void 0;
2035
- const latest = useRef4({ entries, submenu, onRun, onClose, onCloseSubmenu });
2081
+ const latest = useRef5({ entries, submenu, onRun, onClose, onCloseSubmenu });
2036
2082
  useLayoutEffect3(() => {
2037
2083
  latest.current = { entries, submenu, onRun, onClose, onCloseSubmenu };
2038
2084
  });
@@ -2088,6 +2134,9 @@ function GridMenu({
2088
2134
  const openEntry = submenu === null ? void 0 : entries.find(
2089
2135
  (entry) => entry.type === "submenu" && entry.id === submenu.id
2090
2136
  );
2137
+ if (submenu !== null && openEntry === void 0) {
2138
+ setSubmenu(null);
2139
+ }
2091
2140
  return /* @__PURE__ */ jsxs9(Fragment2, { children: [
2092
2141
  /* @__PURE__ */ jsx13(
2093
2142
  "div",
@@ -2140,7 +2189,7 @@ import { jsx as jsx14 } from "react/jsx-runtime";
2140
2189
  function GridContextMenu({
2141
2190
  contextMenu
2142
2191
  }) {
2143
- const { menu, run, close } = contextMenu;
2192
+ const { menu, returnFocusFallback, run, close } = contextMenu;
2144
2193
  if (menu === null) {
2145
2194
  return null;
2146
2195
  }
@@ -2150,6 +2199,7 @@ function GridContextMenu({
2150
2199
  anchor: menu.anchor,
2151
2200
  gap: menu.anchor instanceof Element ? ANCHOR_GAP : 0,
2152
2201
  returnFocusTo: menu.cell ?? void 0,
2202
+ returnFocusFallback,
2153
2203
  themeClassName: menu.themeClassName,
2154
2204
  onDismiss: close,
2155
2205
  children: /* @__PURE__ */ jsx14(
@@ -2169,10 +2219,10 @@ function GridContextMenu({
2169
2219
 
2170
2220
  // src/DataGrid/contextMenu/useContextMenu.ts
2171
2221
  import {
2172
- useEffect as useEffect2,
2222
+ useCallback,
2223
+ useEffect as useEffect3,
2173
2224
  useLayoutEffect as useLayoutEffect4,
2174
- useRef as useRef5,
2175
- useState as useState5
2225
+ useRef as useRef6
2176
2226
  } from "react";
2177
2227
  import {
2178
2228
  contextMenuEntries,
@@ -2321,7 +2371,7 @@ function useContextMenu({
2321
2371
  bodyTableRef,
2322
2372
  bodyScrollRef,
2323
2373
  contextMenu,
2324
- onContextMenuOpenChange,
2374
+ overlay,
2325
2375
  controller,
2326
2376
  commands,
2327
2377
  nav,
@@ -2329,9 +2379,8 @@ function useContextMenu({
2329
2379
  messages,
2330
2380
  columnName
2331
2381
  }) {
2332
- const [menu, setMenu] = useState5(null);
2333
- const current = useRef5(null);
2334
- const openings = useRef5(0);
2382
+ const { drawn, close: closeOverlay } = overlay;
2383
+ const openings = useRef6(0);
2335
2384
  const enabled = contextMenu !== void 0 && contextMenu !== false;
2336
2385
  function parts() {
2337
2386
  const { columns, pageRows } = controller.getView();
@@ -2386,20 +2435,6 @@ function useContextMenu({
2386
2435
  context
2387
2436
  });
2388
2437
  }
2389
- function show(next) {
2390
- const previous = current.current;
2391
- if (previous === next) {
2392
- return;
2393
- }
2394
- current.current = next;
2395
- setMenu(next);
2396
- if (previous !== null) {
2397
- onContextMenuOpenChange?.({ open: false, target: previous.target });
2398
- }
2399
- if (next !== null) {
2400
- onContextMenuOpenChange?.({ open: true, target: next.target });
2401
- }
2402
- }
2403
2438
  function openAt({ target, cell, anchor }, point) {
2404
2439
  let resolved = resolveFor(target);
2405
2440
  if (resolved.length === 0) {
@@ -2413,14 +2448,17 @@ function useContextMenu({
2413
2448
  nav.focusCellNow(cell.rowIndex, cell.columnIndex);
2414
2449
  }
2415
2450
  openings.current += 1;
2416
- show({
2417
- key: openings.current,
2418
- target,
2419
- entries: resolved,
2420
- label: labelOf(target),
2421
- anchor: point ?? anchor,
2422
- cell: cell?.element ?? null,
2423
- themeClassName: overlayThemeClassName(rootRef.current)
2451
+ overlay.open({
2452
+ kind: "contextMenu",
2453
+ menu: {
2454
+ key: openings.current,
2455
+ target,
2456
+ entries: resolved,
2457
+ label: labelOf(target),
2458
+ anchor: point ?? anchor,
2459
+ cell: cell?.element ?? null,
2460
+ themeClassName: overlayThemeClassName(rootRef.current)
2461
+ }
2424
2462
  });
2425
2463
  return true;
2426
2464
  }
@@ -2428,11 +2466,11 @@ function useContextMenu({
2428
2466
  const place = placeAt(target, parts());
2429
2467
  return place !== null && openAt(place, point);
2430
2468
  }
2431
- const latestRequest = useRef5(handleRequest);
2469
+ const latestRequest = useRef6(handleRequest);
2432
2470
  useLayoutEffect4(() => {
2433
2471
  latestRequest.current = handleRequest;
2434
2472
  });
2435
- useEffect2(() => {
2473
+ useEffect3(() => {
2436
2474
  const root = rootRef.current;
2437
2475
  if (!enabled || root === null) {
2438
2476
  return void 0;
@@ -2441,28 +2479,22 @@ function useContextMenu({
2441
2479
  onRequest: (request) => latestRequest.current(request)
2442
2480
  });
2443
2481
  }, [rootRef, enabled]);
2444
- const shown = useRef5(null);
2445
- useLayoutEffect4(() => {
2446
- const closed = shown.current;
2447
- shown.current = menu;
2448
- if (menu === null && closed !== null && closed.cell !== null && !closed.cell.isConnected && document.activeElement === document.body) {
2449
- nav.focusTabStop();
2450
- }
2451
- });
2452
- function close() {
2453
- show(null);
2454
- }
2482
+ const close = useCallback(() => {
2483
+ closeOverlay("contextMenu");
2484
+ }, [closeOverlay]);
2485
+ useEffect3(() => enabled ? close : void 0, [enabled, close]);
2455
2486
  return {
2456
- menu,
2487
+ menu: drawn.kind === "contextMenu" ? drawn.menu : null,
2457
2488
  opens: (area) => hasContextMenu(contextMenu, area),
2458
2489
  open: (target, anchor) => {
2459
2490
  const place = placeOf(target, parts());
2460
2491
  return place !== null && openAt(place, anchor ?? null);
2461
2492
  },
2493
+ returnFocusFallback: overlay.returnFocusFallback,
2462
2494
  run: (item) => {
2463
- const open = current.current;
2464
- if (item.run() && open !== null) {
2465
- commands.report(item.id, open.target, "contextMenu");
2495
+ const open = overlay.current();
2496
+ if (item.run() && open.kind === "contextMenu") {
2497
+ commands.report(item.id, open.menu.target, "contextMenu");
2466
2498
  }
2467
2499
  close();
2468
2500
  },
@@ -2470,11 +2502,52 @@ function useContextMenu({
2470
2502
  };
2471
2503
  }
2472
2504
 
2505
+ // src/DataGrid/overlay/useGridOverlay.ts
2506
+ import { useCallback as useCallback2, useLayoutEffect as useLayoutEffect5, useRef as useRef7, useState as useState5 } from "react";
2507
+ var CLOSED = { kind: "closed" };
2508
+ function useGridOverlay({
2509
+ nav,
2510
+ onContextMenuOpenChange
2511
+ }) {
2512
+ const [drawn, setDrawn] = useState5(CLOSED);
2513
+ const current = useRef7(CLOSED);
2514
+ const reportOpenChange = useRef7(onContextMenuOpenChange);
2515
+ useLayoutEffect5(() => {
2516
+ reportOpenChange.current = onContextMenuOpenChange;
2517
+ });
2518
+ const show = useCallback2((next) => {
2519
+ const previous = current.current;
2520
+ current.current = next;
2521
+ setDrawn(next);
2522
+ if (previous.kind === "contextMenu") {
2523
+ reportOpenChange.current?.({ open: false, target: previous.menu.target });
2524
+ }
2525
+ if (next.kind === "contextMenu") {
2526
+ reportOpenChange.current?.({ open: true, target: next.menu.target });
2527
+ }
2528
+ }, []);
2529
+ const close = useCallback2(
2530
+ (kind) => {
2531
+ if (current.current.kind === kind) {
2532
+ show(CLOSED);
2533
+ }
2534
+ },
2535
+ [show]
2536
+ );
2537
+ return {
2538
+ drawn,
2539
+ current: () => current.current,
2540
+ open: show,
2541
+ close,
2542
+ returnFocusFallback: nav.tabStopCell
2543
+ };
2544
+ }
2545
+
2473
2546
  // src/DataGrid/panels/GridPanels.tsx
2474
- import { useRef as useRef13 } from "react";
2547
+ import { useRef as useRef15 } from "react";
2475
2548
 
2476
2549
  // src/DataGrid/columnChooser/ColumnChooser.tsx
2477
- import { useLayoutEffect as useLayoutEffect5, useRef as useRef6, useState as useState6 } from "react";
2550
+ import { useLayoutEffect as useLayoutEffect6, useRef as useRef8, useState as useState6 } from "react";
2478
2551
  import { resolveColumnChooser } from "@gridkitjs/core";
2479
2552
  import { Fragment as Fragment3, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
2480
2553
  function ColumnChooser({
@@ -2482,13 +2555,13 @@ function ColumnChooser({
2482
2555
  messages
2483
2556
  }) {
2484
2557
  const [search, setSearch] = useState6("");
2485
- const showAllRef = useRef6(null);
2558
+ const showAllRef = useRef8(null);
2486
2559
  const { entries, selectAll, toggleAll } = resolveColumnChooser({
2487
2560
  columns: controller.getView().dataColumns,
2488
2561
  visibility: controller.getState().columnVisibility,
2489
2562
  search
2490
2563
  });
2491
- useLayoutEffect5(() => {
2564
+ useLayoutEffect6(() => {
2492
2565
  if (showAllRef.current !== null) {
2493
2566
  showAllRef.current.indeterminate = selectAll === "mixed";
2494
2567
  }
@@ -2559,7 +2632,7 @@ function ColumnChooser({
2559
2632
  }
2560
2633
 
2561
2634
  // src/DataGrid/filterMenu/FilterMenu.tsx
2562
- import { useEffect as useEffect3, useRef as useRef11 } from "react";
2635
+ import { useEffect as useEffect4, useRef as useRef13 } from "react";
2563
2636
  import {
2564
2637
  resolveColumnFilterMenu as resolveColumnFilterMenu2,
2565
2638
  resolveColumnHeaderText,
@@ -2569,10 +2642,10 @@ import {
2569
2642
  // src/DataGrid/filterMenu/ExcelFilterEditor.tsx
2570
2643
  import {
2571
2644
  useImperativeHandle as useImperativeHandle2,
2572
- useLayoutEffect as useLayoutEffect9,
2645
+ useLayoutEffect as useLayoutEffect10,
2573
2646
  useMemo as useMemo4,
2574
2647
  useReducer,
2575
- useRef as useRef10,
2648
+ useRef as useRef12,
2576
2649
  useState as useState10
2577
2650
  } from "react";
2578
2651
  import {
@@ -2584,8 +2657,61 @@ import {
2584
2657
  selectAllState
2585
2658
  } from "@gridkitjs/core";
2586
2659
 
2660
+ // src/DataGrid/menu/useMenuButton.ts
2661
+ import {
2662
+ useLayoutEffect as useLayoutEffect7,
2663
+ useRef as useRef9,
2664
+ useState as useState7
2665
+ } from "react";
2666
+ var CLOSED2 = { kind: "closed" };
2667
+ function useMenuButton({
2668
+ itemCount,
2669
+ gap = () => ANCHOR_GAP
2670
+ }) {
2671
+ const [state, setState] = useState7(CLOSED2);
2672
+ const behaviourRef = useRef9(null);
2673
+ useLayoutEffect7(() => {
2674
+ if (state.kind === "open" && state.focusItem > 0) {
2675
+ behaviourRef.current?.focusItem(state.focusItem);
2676
+ }
2677
+ }, [state]);
2678
+ function open(button, onLast) {
2679
+ setState({
2680
+ kind: "open",
2681
+ anchor: button,
2682
+ themeClassName: overlayThemeClassName(button),
2683
+ gap: gap(button),
2684
+ focusItem: onLast ? itemCount - 1 : 0
2685
+ });
2686
+ }
2687
+ function close() {
2688
+ setState(CLOSED2);
2689
+ }
2690
+ return {
2691
+ state,
2692
+ close,
2693
+ buttonProps: {
2694
+ "aria-haspopup": "menu",
2695
+ "aria-expanded": state.kind === "open",
2696
+ onClick: (event) => {
2697
+ if (state.kind === "closed") {
2698
+ open(event.currentTarget, false);
2699
+ } else {
2700
+ close();
2701
+ }
2702
+ },
2703
+ onKeyDown: (event) => {
2704
+ if ((event.key === "ArrowDown" || event.key === "ArrowUp") && state.kind === "closed") {
2705
+ event.preventDefault();
2706
+ open(event.currentTarget, event.key === "ArrowUp");
2707
+ }
2708
+ }
2709
+ },
2710
+ behaviourRef
2711
+ };
2712
+ }
2713
+
2587
2714
  // src/DataGrid/filterMenu/OperatorMenuButton.tsx
2588
- import { useLayoutEffect as useLayoutEffect6, useRef as useRef7, useState as useState7 } from "react";
2589
2715
  import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs11 } from "react/jsx-runtime";
2590
2716
  function gapBeside(button) {
2591
2717
  const dialog = button.closest('[role="dialog"]') ?? button;
@@ -2598,25 +2724,11 @@ function OperatorMenuButton({
2598
2724
  onChoose,
2599
2725
  ref
2600
2726
  }) {
2601
- const [open, setOpen] = useState7(null);
2602
- const menuBehaviourRef = useRef7(null);
2727
+ const { state, close, buttonProps, behaviourRef } = useMenuButton({
2728
+ itemCount: menu.operators.length,
2729
+ gap: gapBeside
2730
+ });
2603
2731
  const label = messages.filterOperatorMenu(menu.family);
2604
- useLayoutEffect6(() => {
2605
- if (open !== null && open.focusItem > 0) {
2606
- menuBehaviourRef.current?.focusItem(open.focusItem);
2607
- }
2608
- }, [open]);
2609
- function show(button, onLast = false) {
2610
- setOpen({
2611
- anchor: button,
2612
- themeClassName: overlayThemeClassName(button),
2613
- gap: gapBeside(button),
2614
- focusItem: onLast ? menu.operators.length - 1 : 0
2615
- });
2616
- }
2617
- function close() {
2618
- setOpen(null);
2619
- }
2620
2732
  const entries = menu.operators.map((operator) => ({
2621
2733
  type: "item",
2622
2734
  id: operator,
@@ -2636,21 +2748,7 @@ function OperatorMenuButton({
2636
2748
  ref,
2637
2749
  type: "button",
2638
2750
  className: "filter-menu-submenu",
2639
- "aria-haspopup": "menu",
2640
- "aria-expanded": open !== null,
2641
- onClick: (event) => {
2642
- if (open === null) {
2643
- show(event.currentTarget);
2644
- } else {
2645
- close();
2646
- }
2647
- },
2648
- onKeyDown: (event) => {
2649
- if ((event.key === "ArrowDown" || event.key === "ArrowUp") && open === null) {
2650
- event.preventDefault();
2651
- show(event.currentTarget, event.key === "ArrowUp");
2652
- }
2653
- },
2751
+ ...buttonProps,
2654
2752
  children: [
2655
2753
  /* @__PURE__ */ jsx16("span", { className: "filter-menu-submenu-icon", "aria-hidden": "true", children: active !== void 0 && /* @__PURE__ */ jsx16(CheckIcon, {}) }),
2656
2754
  label,
@@ -2658,22 +2756,22 @@ function OperatorMenuButton({
2658
2756
  ]
2659
2757
  }
2660
2758
  ),
2661
- open !== null && /* @__PURE__ */ jsx16(
2759
+ state.kind === "open" && /* @__PURE__ */ jsx16(
2662
2760
  Overlay,
2663
2761
  {
2664
- anchor: open.anchor,
2762
+ anchor: state.anchor,
2665
2763
  placement: "right-start",
2666
- gap: open.gap,
2667
- returnFocusTo: open.anchor,
2668
- themeClassName: open.themeClassName,
2764
+ gap: state.gap,
2765
+ returnFocusTo: state.anchor,
2766
+ themeClassName: state.themeClassName,
2669
2767
  onDismiss: close,
2670
2768
  children: /* @__PURE__ */ jsx16(
2671
2769
  GridMenu,
2672
2770
  {
2673
2771
  entries,
2674
2772
  label,
2675
- themeClassName: open.themeClassName,
2676
- behaviourRef: menuBehaviourRef,
2773
+ themeClassName: state.themeClassName,
2774
+ behaviourRef,
2677
2775
  onRun: (item) => {
2678
2776
  item.run();
2679
2777
  },
@@ -2690,8 +2788,8 @@ import {
2690
2788
  Fragment as Fragment5,
2691
2789
  useId,
2692
2790
  useImperativeHandle,
2693
- useLayoutEffect as useLayoutEffect7,
2694
- useRef as useRef8,
2791
+ useLayoutEffect as useLayoutEffect8,
2792
+ useRef as useRef10,
2695
2793
  useState as useState8
2696
2794
  } from "react";
2697
2795
  import {
@@ -2893,7 +2991,7 @@ function SimpleFilterEditor({
2893
2991
  });
2894
2992
  const [draft, setDraft] = useState8(opened.draft);
2895
2993
  const [invalid, setInvalid] = useState8(NO_ROWS);
2896
- const rowElements = useRef8([]);
2994
+ const rowElements = useRef10([]);
2897
2995
  const invalidMessageId = useId();
2898
2996
  const combinatorName = useId();
2899
2997
  function update(next) {
@@ -2929,7 +3027,7 @@ function SimpleFilterEditor({
2929
3027
  return false;
2930
3028
  }
2931
3029
  }));
2932
- useLayoutEffect7(() => {
3030
+ useLayoutEffect8(() => {
2933
3031
  const [first] = invalid;
2934
3032
  if (first !== void 0) {
2935
3033
  rowElements.current[first]?.querySelector('[aria-invalid="true"]')?.focus();
@@ -2981,7 +3079,7 @@ function SimpleFilterEditor({
2981
3079
  }
2982
3080
 
2983
3081
  // src/DataGrid/filterMenu/ValueChecklist.tsx
2984
- import { useLayoutEffect as useLayoutEffect8, useRef as useRef9, useState as useState9 } from "react";
3082
+ import { useLayoutEffect as useLayoutEffect9, useRef as useRef11, useState as useState9 } from "react";
2985
3083
  import {
2986
3084
  attachChecklist,
2987
3085
  createRowVirtualizer
@@ -3001,15 +3099,15 @@ function ValueChecklist({
3001
3099
  label,
3002
3100
  onToggle
3003
3101
  }) {
3004
- const listRef = useRef9(null);
3005
- const checklistRef = useRef9(null);
3102
+ const listRef = useRef11(null);
3103
+ const checklistRef = useRef11(null);
3006
3104
  const [virtualizer, setVirtualizer] = useState9(null);
3007
3105
  const [range, setRange] = useState9(NO_RANGE);
3008
- const latest = useRef9({ items, onToggle });
3009
- useLayoutEffect8(() => {
3106
+ const latest = useRef11({ items, onToggle });
3107
+ useLayoutEffect9(() => {
3010
3108
  latest.current = { items, onToggle };
3011
3109
  });
3012
- useLayoutEffect8(() => {
3110
+ useLayoutEffect9(() => {
3013
3111
  const list = listRef.current;
3014
3112
  if (list === null) {
3015
3113
  return void 0;
@@ -3038,7 +3136,7 @@ function ValueChecklist({
3038
3136
  rows.destroy();
3039
3137
  };
3040
3138
  }, []);
3041
- useLayoutEffect8(() => {
3139
+ useLayoutEffect9(() => {
3042
3140
  virtualizer?.setRowCount(items.length);
3043
3141
  checklistRef.current?.setCount(items.length);
3044
3142
  }, [virtualizer, items.length]);
@@ -3108,11 +3206,11 @@ function ExcelFilterEditor({
3108
3206
  });
3109
3207
  const [draft, dispatch] = useReducer(filterEditorReducer2, opened.draft);
3110
3208
  const [operator, setOperator] = useState10(null);
3111
- const conditions = useRef10(null);
3112
- const conditionsFocus = useRef10(null);
3113
- const operatorButton = useRef10(null);
3114
- const switched = useRef10(false);
3115
- const selectAllRef = useRef10(null);
3209
+ const conditions = useRef12(null);
3210
+ const conditionsFocus = useRef12(null);
3211
+ const operatorButton = useRef12(null);
3212
+ const switched = useRef12(false);
3213
+ const selectAllRef = useRef12(null);
3116
3214
  const selectAll = useMemo4(() => selectAllState(draft), [draft]);
3117
3215
  const checklist = useMemo4(
3118
3216
  () => filterChecklist(draft, {
@@ -3121,12 +3219,12 @@ function ExcelFilterEditor({
3121
3219
  }),
3122
3220
  [draft, menu.valueLimit, messages.filterBlanks]
3123
3221
  );
3124
- useLayoutEffect9(() => {
3222
+ useLayoutEffect10(() => {
3125
3223
  if (selectAllRef.current !== null) {
3126
3224
  selectAllRef.current.indeterminate = selectAll === "mixed";
3127
3225
  }
3128
3226
  });
3129
- useLayoutEffect9(() => {
3227
+ useLayoutEffect10(() => {
3130
3228
  if (switched.current) {
3131
3229
  switched.current = false;
3132
3230
  (operator === null ? operatorButton.current : conditionsFocus.current)?.focus();
@@ -3260,10 +3358,10 @@ function FilterMenu({
3260
3358
  applyFilter,
3261
3359
  columnValues
3262
3360
  }) {
3263
- const editor = useRef11(null);
3361
+ const editor = useRef13(null);
3264
3362
  const column = target.area === "header" ? controller.getView().dataColumns.find((entry) => entry.id === target.columnId) : void 0;
3265
3363
  const menu = column === void 0 ? null : resolveColumnFilterMenu2(controller.getOptions(), column.column);
3266
- useEffect3(() => {
3364
+ useEffect4(() => {
3267
3365
  if (menu === null) {
3268
3366
  close();
3269
3367
  }
@@ -3365,10 +3463,10 @@ function FilterMenu({
3365
3463
  }
3366
3464
 
3367
3465
  // src/DataGrid/filterMenu/useApplyFilter.ts
3368
- import { useEffect as useEffect4, useRef as useRef12 } from "react";
3466
+ import { useEffect as useEffect5, useRef as useRef14 } from "react";
3369
3467
  function useApplyFilter(controller, messages, announce) {
3370
- const unannounced = useRef12(null);
3371
- useEffect4(() => {
3468
+ const unannounced = useRef14(null);
3469
+ useEffect5(() => {
3372
3470
  if (unannounced.current === controller.getState().filter) {
3373
3471
  unannounced.current = null;
3374
3472
  announce(
@@ -3417,14 +3515,14 @@ function GridPanels({
3417
3515
  commands,
3418
3516
  messages
3419
3517
  }) {
3420
- const initialFocus = useRef13(null);
3518
+ const initialFocus = useRef15(null);
3421
3519
  const applyFilter = useApplyFilter(
3422
3520
  controller,
3423
3521
  messages,
3424
3522
  commands.host.announce
3425
3523
  );
3426
3524
  const columnValues = useFilterValueCache(controller, messages);
3427
- const { panel, close } = panels;
3525
+ const { panel, close, returnFocusFallback } = panels;
3428
3526
  if (panel === null) {
3429
3527
  return null;
3430
3528
  }
@@ -3437,6 +3535,7 @@ function GridPanels({
3437
3535
  gap: panel.anchor instanceof Element ? ANCHOR_GAP : 0,
3438
3536
  initialFocus,
3439
3537
  returnFocusTo: panel.returnFocusTo,
3538
+ returnFocusFallback,
3440
3539
  ignoreScrollAfterInput: true,
3441
3540
  trapFocus,
3442
3541
  themeClassName: panel.themeClassName,
@@ -3477,7 +3576,7 @@ function panelApi(panels, controller) {
3477
3576
  return true;
3478
3577
  },
3479
3578
  closeFilterMenu: () => {
3480
- if (panels.panel?.kind === "filter") {
3579
+ if (panels.current()?.kind === "filter") {
3481
3580
  panels.close();
3482
3581
  }
3483
3582
  }
@@ -3485,7 +3584,7 @@ function panelApi(panels, controller) {
3485
3584
  }
3486
3585
 
3487
3586
  // src/DataGrid/panels/useGridPanels.ts
3488
- import { useLayoutEffect as useLayoutEffect10, useRef as useRef14, useState as useState12 } from "react";
3587
+ import { useRef as useRef16 } from "react";
3489
3588
  function toolbarItem(root, itemId) {
3490
3589
  const items = root.querySelectorAll(
3491
3590
  ":scope > .gridkit-toolbar > [data-gridkit-toolbar-item]"
@@ -3497,6 +3596,9 @@ function toolbarItem(root, itemId) {
3497
3596
  (item) => item.hasAttribute("data-gridkit-toolbar-more")
3498
3597
  ) ?? null;
3499
3598
  }
3599
+ function panelOf(overlay) {
3600
+ return overlay.kind === "panel" ? overlay.panel : null;
3601
+ }
3500
3602
  function headerCell2(headerTable, columnId) {
3501
3603
  const cells = headerTable?.tHead?.rows[0]?.cells;
3502
3604
  return cells === void 0 ? null : Array.from(cells).find(
@@ -3506,10 +3608,9 @@ function headerCell2(headerTable, columnId) {
3506
3608
  function useGridPanels({
3507
3609
  rootRef,
3508
3610
  headerTableRef,
3509
- nav
3611
+ overlay
3510
3612
  }) {
3511
- const [panel, setPanel] = useState12(null);
3512
- const openings = useRef14(0);
3613
+ const openings = useRef16(0);
3513
3614
  function placeFor(root, target) {
3514
3615
  const element = target.area === "toolbar" ? toolbarItem(root, target.itemId) : target.area === "header" ? headerCell2(headerTableRef.current, target.columnId) : null;
3515
3616
  if (element !== null) {
@@ -3527,38 +3628,35 @@ function useGridPanels({
3527
3628
  returnFocusTo: void 0
3528
3629
  };
3529
3630
  }
3530
- const shown = useRef14(null);
3531
- useLayoutEffect10(() => {
3532
- const closed = shown.current;
3533
- shown.current = panel;
3534
- if (panel === null && closed?.returnFocusTo?.isConnected === false && document.activeElement === document.body) {
3535
- nav.focusTabStop();
3536
- }
3537
- });
3538
3631
  return {
3539
- panel,
3632
+ panel: panelOf(overlay.drawn),
3633
+ current: () => panelOf(overlay.current()),
3540
3634
  open: (kind, target) => {
3541
3635
  const root = rootRef.current;
3542
3636
  if (root === null) {
3543
3637
  return;
3544
3638
  }
3545
3639
  openings.current += 1;
3546
- setPanel({
3547
- key: openings.current,
3548
- kind,
3549
- target,
3550
- ...placeFor(root, target),
3551
- themeClassName: overlayThemeClassName(root)
3640
+ overlay.open({
3641
+ kind: "panel",
3642
+ panel: {
3643
+ key: openings.current,
3644
+ kind,
3645
+ target,
3646
+ ...placeFor(root, target),
3647
+ themeClassName: overlayThemeClassName(root)
3648
+ }
3552
3649
  });
3553
3650
  },
3554
3651
  close: () => {
3555
- setPanel(null);
3556
- }
3652
+ overlay.close("panel");
3653
+ },
3654
+ returnFocusFallback: overlay.returnFocusFallback
3557
3655
  };
3558
3656
  }
3559
3657
 
3560
3658
  // src/DataGrid/toolbar/GridToolbar.tsx
3561
- import { useLayoutEffect as useLayoutEffect13, useRef as useRef18 } from "react";
3659
+ import { useLayoutEffect as useLayoutEffect12, useRef as useRef19 } from "react";
3562
3660
  import {
3563
3661
  resolveToolbar,
3564
3662
  splitToolbarItems,
@@ -3567,7 +3665,6 @@ import {
3567
3665
  import { attachToolbar } from "@gridkitjs/dom";
3568
3666
 
3569
3667
  // src/DataGrid/toolbar/ToolbarMenuButton.tsx
3570
- import { useLayoutEffect as useLayoutEffect11, useRef as useRef15, useState as useState13 } from "react";
3571
3668
  import { Fragment as Fragment8, jsx as jsx23, jsxs as jsxs17 } from "react/jsx-runtime";
3572
3669
  function ToolbarMenuButton({
3573
3670
  itemKey,
@@ -3576,26 +3673,11 @@ function ToolbarMenuButton({
3576
3673
  icon,
3577
3674
  entries,
3578
3675
  more = false,
3579
- onMenuClose
3676
+ returnFocusFallback
3580
3677
  }) {
3581
- const [menu, setMenu] = useState13(null);
3582
- const menuBehaviourRef = useRef15(null);
3583
- useLayoutEffect11(() => {
3584
- if (menu !== null && menu.focusItem > 0) {
3585
- menuBehaviourRef.current?.focusItem(menu.focusItem);
3586
- }
3587
- }, [menu]);
3588
- function open(button, onLast = false) {
3589
- setMenu({
3590
- anchor: button,
3591
- themeClassName: overlayThemeClassName(button),
3592
- focusItem: onLast ? entries.filter((entry) => entry.type !== "separator").length - 1 : 0
3593
- });
3594
- }
3595
- function close() {
3596
- setMenu(null);
3597
- onMenuClose();
3598
- }
3678
+ const { state, close, buttonProps, behaviourRef } = useMenuButton({
3679
+ itemCount: entries.filter((entry) => entry.type !== "separator").length
3680
+ });
3599
3681
  return /* @__PURE__ */ jsxs17(Fragment8, { children: [
3600
3682
  /* @__PURE__ */ jsxs17(
3601
3683
  "button",
@@ -3605,21 +3687,7 @@ function ToolbarMenuButton({
3605
3687
  className: classNames("toolbar-button", more && "toolbar-more"),
3606
3688
  "data-gridkit-toolbar-item": itemKey,
3607
3689
  ...ariaAttr(more, "data-gridkit-toolbar-more", ""),
3608
- "aria-haspopup": "menu",
3609
- "aria-expanded": menu !== null,
3610
- onClick: (event) => {
3611
- if (menu === null) {
3612
- open(event.currentTarget);
3613
- } else {
3614
- close();
3615
- }
3616
- },
3617
- onKeyDown: (event) => {
3618
- if ((event.key === "ArrowDown" || event.key === "ArrowUp") && menu === null) {
3619
- event.preventDefault();
3620
- open(event.currentTarget, event.key === "ArrowUp");
3621
- }
3622
- },
3690
+ ...buttonProps,
3623
3691
  children: [
3624
3692
  icon !== void 0 && /* @__PURE__ */ jsx23("span", { className: "toolbar-button-icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx23(MenuIcon, { name: icon }) }),
3625
3693
  label,
@@ -3627,22 +3695,23 @@ function ToolbarMenuButton({
3627
3695
  ]
3628
3696
  }
3629
3697
  ),
3630
- menu !== null && /* @__PURE__ */ jsx23(
3698
+ state.kind === "open" && /* @__PURE__ */ jsx23(
3631
3699
  Overlay,
3632
3700
  {
3633
- anchor: menu.anchor,
3701
+ anchor: state.anchor,
3634
3702
  placement: "bottom-start",
3635
- gap: ANCHOR_GAP,
3636
- returnFocusTo: menu.anchor,
3637
- themeClassName: menu.themeClassName,
3703
+ gap: state.gap,
3704
+ returnFocusTo: state.anchor,
3705
+ returnFocusFallback,
3706
+ themeClassName: state.themeClassName,
3638
3707
  onDismiss: close,
3639
3708
  children: /* @__PURE__ */ jsx23(
3640
3709
  GridMenu,
3641
3710
  {
3642
3711
  entries,
3643
3712
  label,
3644
- themeClassName: menu.themeClassName,
3645
- behaviourRef: menuBehaviourRef,
3713
+ themeClassName: state.themeClassName,
3714
+ behaviourRef,
3646
3715
  onRun: (item) => {
3647
3716
  item.run();
3648
3717
  close();
@@ -3656,7 +3725,7 @@ function ToolbarMenuButton({
3656
3725
  }
3657
3726
 
3658
3727
  // src/DataGrid/toolbar/ToolbarSearch.tsx
3659
- import { useEffect as useEffect5, useRef as useRef16, useState as useState14 } from "react";
3728
+ import { useEffect as useEffect6, useRef as useRef17, useState as useState12 } from "react";
3660
3729
  import {
3661
3730
  searchTextOf,
3662
3731
  setSearchText
@@ -3671,9 +3740,9 @@ function ToolbarSearch({
3671
3740
  announce
3672
3741
  }) {
3673
3742
  const applied = searchTextOf(controller.getState().filter);
3674
- const [draft, setDraft] = useState14(null);
3675
- const timer = useRef16(void 0);
3676
- const unannounced = useRef16(null);
3743
+ const [draft, setDraft] = useState12(null);
3744
+ const timer = useRef17(void 0);
3745
+ const unannounced = useRef17(null);
3677
3746
  const text = draft !== null && draft.over === applied ? draft.text : applied;
3678
3747
  function apply(next, over) {
3679
3748
  clearTimeout(timer.current);
@@ -3688,13 +3757,13 @@ function ToolbarSearch({
3688
3757
  controller.setFilter(searched);
3689
3758
  }
3690
3759
  }
3691
- useEffect5(() => {
3760
+ useEffect6(() => {
3692
3761
  if (unannounced.current === applied) {
3693
3762
  unannounced.current = null;
3694
3763
  announce(messages.searchResults(controller.getView().rows.length));
3695
3764
  }
3696
3765
  });
3697
- useEffect5(
3766
+ useEffect6(
3698
3767
  () => () => {
3699
3768
  clearTimeout(timer.current);
3700
3769
  },
@@ -3731,12 +3800,12 @@ function ToolbarSearch({
3731
3800
  }
3732
3801
 
3733
3802
  // src/DataGrid/toolbar/useToolbarOverflow.ts
3734
- import { useLayoutEffect as useLayoutEffect12, useRef as useRef17, useState as useState15 } from "react";
3803
+ import { useLayoutEffect as useLayoutEffect11, useRef as useRef18, useState as useState13 } from "react";
3735
3804
  import { observeToolbarOverflow } from "@gridkitjs/dom";
3736
3805
  function useToolbarOverflow(toolbarRef, items) {
3737
- const [fit, setFit] = useState15(items.length);
3738
- const overflow = useRef17(null);
3739
- const measuredLayout = useRef17("");
3806
+ const [fit, setFit] = useState13(items.length);
3807
+ const overflow = useRef18(null);
3808
+ const measuredLayout = useRef18("");
3740
3809
  const layout = JSON.stringify(
3741
3810
  items.map((item) => [
3742
3811
  item.type,
@@ -3744,7 +3813,7 @@ function useToolbarOverflow(toolbarRef, items) {
3744
3813
  "label" in item ? item.label : null
3745
3814
  ])
3746
3815
  );
3747
- useLayoutEffect12(() => {
3816
+ useLayoutEffect11(() => {
3748
3817
  const toolbar = toolbarRef.current;
3749
3818
  if (toolbar === null || layout === measuredLayout.current) {
3750
3819
  return;
@@ -3757,7 +3826,7 @@ function useToolbarOverflow(toolbarRef, items) {
3757
3826
  overflow.current.update(options);
3758
3827
  }
3759
3828
  }, [toolbarRef, layout, items]);
3760
- useLayoutEffect12(
3829
+ useLayoutEffect11(
3761
3830
  () => () => {
3762
3831
  overflow.current?.detach();
3763
3832
  overflow.current = null;
@@ -3843,8 +3912,7 @@ function Toolbar({
3843
3912
  messages,
3844
3913
  announce
3845
3914
  }) {
3846
- const toolbarRef = useRef18(null);
3847
- const menuClosed = useRef18(false);
3915
+ const toolbarRef = useRef19(null);
3848
3916
  const items = resolveToolbar(entries, {
3849
3917
  commands: commands.commands,
3850
3918
  contextFor: commands.contextFor,
@@ -3856,22 +3924,13 @@ function Toolbar({
3856
3924
  );
3857
3925
  const fit = useToolbarOverflow(toolbarRef, items);
3858
3926
  const { shown, overflow } = splitToolbarItems(items, fit);
3859
- useLayoutEffect13(() => {
3927
+ useLayoutEffect12(() => {
3860
3928
  const toolbar = toolbarRef.current;
3861
3929
  return toolbar === null ? void 0 : attachToolbar(toolbar);
3862
3930
  }, []);
3863
- useLayoutEffect13(() => {
3864
- if (!menuClosed.current) {
3865
- return;
3866
- }
3867
- menuClosed.current = false;
3931
+ function toolbarTabStop() {
3868
3932
  const toolbar = toolbarRef.current;
3869
- if (toolbar !== null && document.activeElement === document.body) {
3870
- (toolbar.querySelector('[tabindex="0"]') ?? toolbar.querySelector("button, input"))?.focus();
3871
- }
3872
- });
3873
- function onMenuClose() {
3874
- menuClosed.current = true;
3933
+ return toolbar?.querySelector('[tabindex="0"]') ?? toolbar?.querySelector("button, input") ?? null;
3875
3934
  }
3876
3935
  function draw(item) {
3877
3936
  switch (item.type) {
@@ -3913,7 +3972,7 @@ function Toolbar({
3913
3972
  label: item.label,
3914
3973
  icon: item.icon,
3915
3974
  entries: item.items,
3916
- onMenuClose
3975
+ returnFocusFallback: toolbarTabStop
3917
3976
  },
3918
3977
  item.key
3919
3978
  );
@@ -3979,7 +4038,7 @@ function Toolbar({
3979
4038
  label: messages.moreToolbarItems,
3980
4039
  entries: overflow,
3981
4040
  more: true,
3982
- onMenuClose
4041
+ returnFocusFallback: toolbarTabStop
3983
4042
  }
3984
4043
  )
3985
4044
  ]
@@ -4028,7 +4087,7 @@ function useColumnDrag({
4028
4087
 
4029
4088
  // src/DataGrid/useColumnResize.ts
4030
4089
  import {
4031
- useState as useState16
4090
+ useState as useState14
4032
4091
  } from "react";
4033
4092
  import {
4034
4093
  beginColumnResize,
@@ -4042,7 +4101,8 @@ function useColumnResize({
4042
4101
  controller,
4043
4102
  columnSizeDefaults
4044
4103
  }) {
4045
- const [activeColumnId, setActiveColumnId] = useState16(null);
4104
+ const [activeColumnId, setActiveColumnId] = useState14(null);
4105
+ const startGesture = useGestureSignal();
4046
4106
  function startResize(entry, event) {
4047
4107
  event.stopPropagation();
4048
4108
  const session = beginColumnResize(
@@ -4052,11 +4112,10 @@ function useColumnResize({
4052
4112
  columnSizeDefaults
4053
4113
  );
4054
4114
  const base = controller.getState().columnSizing;
4055
- const started = startColumnResizeGesture(
4056
- event.currentTarget,
4057
- event,
4058
- session,
4059
- {
4115
+ const handle = event.currentTarget;
4116
+ const started = startGesture(
4117
+ handle,
4118
+ (signal) => startColumnResizeGesture(handle, event, session, {
4060
4119
  onMove(width) {
4061
4120
  controller.resizeColumn(session.columnId, width, "move");
4062
4121
  },
@@ -4080,8 +4139,9 @@ function useColumnResize({
4080
4139
  base,
4081
4140
  session.startWidth
4082
4141
  );
4083
- }
4084
- }
4142
+ },
4143
+ signal
4144
+ })
4085
4145
  );
4086
4146
  if (started) {
4087
4147
  setActiveColumnId(session.columnId);
@@ -4120,11 +4180,11 @@ function useColumnResize({
4120
4180
  }
4121
4181
 
4122
4182
  // src/DataGrid/useElementWidth.ts
4123
- import { useLayoutEffect as useLayoutEffect14, useState as useState17 } from "react";
4183
+ import { useLayoutEffect as useLayoutEffect13, useState as useState15 } from "react";
4124
4184
  import { observeElementWidth } from "@gridkitjs/dom";
4125
4185
  function useElementWidth(ref, enabled) {
4126
- const [width, setWidth] = useState17(null);
4127
- useLayoutEffect14(() => {
4186
+ const [width, setWidth] = useState15(null);
4187
+ useLayoutEffect13(() => {
4128
4188
  const element = ref.current;
4129
4189
  if (element === null || !enabled) {
4130
4190
  return void 0;
@@ -4135,12 +4195,12 @@ function useElementWidth(ref, enabled) {
4135
4195
  }
4136
4196
 
4137
4197
  // src/DataGrid/useGridController.ts
4138
- import { useState as useState18, useSyncExternalStore as useSyncExternalStore2 } from "react";
4198
+ import { useState as useState16, useSyncExternalStore as useSyncExternalStore2 } from "react";
4139
4199
  import {
4140
4200
  createGridController
4141
4201
  } from "@gridkitjs/core";
4142
4202
  function useGridController(options) {
4143
- const [controller] = useState18(
4203
+ const [controller] = useState16(
4144
4204
  () => createGridController(options)
4145
4205
  );
4146
4206
  controller.setOptions(options);
@@ -4153,15 +4213,15 @@ function useGridController(options) {
4153
4213
  }
4154
4214
 
4155
4215
  // src/DataGrid/useInfiniteScroll.ts
4156
- import { useEffect as useEffect6, useRef as useRef19 } from "react";
4216
+ import { useEffect as useEffect7, useRef as useRef20 } from "react";
4157
4217
  import { attachInfiniteScroll } from "@gridkitjs/dom";
4158
4218
  function useInfiniteScroll({
4159
4219
  rootRef,
4160
4220
  sentinelRef,
4161
4221
  config
4162
4222
  }) {
4163
- const scroll = useRef19(null);
4164
- useEffect6(() => {
4223
+ const scroll = useRef20(null);
4224
+ useEffect7(() => {
4165
4225
  const root = rootRef.current;
4166
4226
  if (root === null) {
4167
4227
  return void 0;
@@ -4176,7 +4236,7 @@ function useInfiniteScroll({
4176
4236
  scroll.current = null;
4177
4237
  };
4178
4238
  }, [rootRef]);
4179
- useEffect6(() => {
4239
+ useEffect7(() => {
4180
4240
  scroll.current?.update({
4181
4241
  sentinel: sentinelRef.current,
4182
4242
  hasMore: config?.hasMore ?? false,
@@ -4188,11 +4248,11 @@ function useInfiniteScroll({
4188
4248
  }
4189
4249
 
4190
4250
  // src/DataGrid/useLiveAnnouncer.ts
4191
- import { useCallback, useLayoutEffect as useLayoutEffect15, useRef as useRef20 } from "react";
4251
+ import { useCallback as useCallback3, useLayoutEffect as useLayoutEffect14, useRef as useRef21 } from "react";
4192
4252
  import { createLiveAnnouncer } from "@gridkitjs/dom";
4193
4253
  function useLiveAnnouncer(containerRef) {
4194
- const announcer = useRef20(null);
4195
- useLayoutEffect15(() => {
4254
+ const announcer = useRef21(null);
4255
+ useLayoutEffect14(() => {
4196
4256
  const container = containerRef.current;
4197
4257
  if (container === null) {
4198
4258
  return void 0;
@@ -4204,13 +4264,13 @@ function useLiveAnnouncer(containerRef) {
4204
4264
  announcer.current = null;
4205
4265
  };
4206
4266
  }, [containerRef]);
4207
- return useCallback((text) => {
4267
+ return useCallback3((text) => {
4208
4268
  announcer.current?.announce(text);
4209
4269
  }, []);
4210
4270
  }
4211
4271
 
4212
4272
  // src/DataGrid/useRowVirtualizer.ts
4213
- import { useLayoutEffect as useLayoutEffect16, useState as useState19 } from "react";
4273
+ import { useLayoutEffect as useLayoutEffect15, useState as useState17 } from "react";
4214
4274
  import { createRowVirtualizer as createRowVirtualizer2 } from "@gridkitjs/dom";
4215
4275
  var EMPTY_RANGE = {
4216
4276
  startIndex: 0,
@@ -4228,9 +4288,9 @@ function useRowVirtualizer({
4228
4288
  estimatedRowHeight,
4229
4289
  overscan
4230
4290
  }) {
4231
- const [virtualizer, setVirtualizer] = useState19(null);
4232
- const [range, setRange] = useState19(EMPTY_RANGE);
4233
- useLayoutEffect16(() => {
4291
+ const [virtualizer, setVirtualizer] = useState17(null);
4292
+ const [range, setRange] = useState17(EMPTY_RANGE);
4293
+ useLayoutEffect15(() => {
4234
4294
  const element = bodyScrollRef.current;
4235
4295
  if (!enabled || element === null) {
4236
4296
  return void 0;
@@ -4245,7 +4305,7 @@ function useRowVirtualizer({
4245
4305
  created.destroy();
4246
4306
  };
4247
4307
  }, [enabled, bodyScrollRef, estimatedRowHeight, overscan]);
4248
- useLayoutEffect16(() => {
4308
+ useLayoutEffect15(() => {
4249
4309
  virtualizer?.setRowCount(rows.length);
4250
4310
  virtualizer?.resetHeights();
4251
4311
  }, [virtualizer, rows]);
@@ -4319,13 +4379,14 @@ function DataGrid(props) {
4319
4379
  const hoverRows = hoverable?.rows ?? true;
4320
4380
  const hoverColumns = hoverable?.columns ?? true;
4321
4381
  const hoverCells = hoverable?.cells ?? true;
4322
- const viewportRef = useRef21(null);
4323
- const headerTableRef = useRef21(null);
4324
- const bodyTableRef = useRef21(null);
4325
- const bodyScrollRef = useRef21(null);
4326
- const sentinelRef = useRef21(null);
4382
+ const viewportRef = useRef22(null);
4383
+ const gridRef = useRef22(null);
4384
+ const headerTableRef = useRef22(null);
4385
+ const bodyTableRef = useRef22(null);
4386
+ const bodyScrollRef = useRef22(null);
4387
+ const sentinelRef = useRef22(null);
4327
4388
  const viewportWidth = useElementWidth(viewportRef, resizeMode === "fit");
4328
- const subscribersRef = useRef21(/* @__PURE__ */ new Set());
4389
+ const subscribersRef = useRef22(/* @__PURE__ */ new Set());
4329
4390
  const gridId = useId2();
4330
4391
  const announce = useLiveAnnouncer(viewportRef);
4331
4392
  const messages = useMemo5(
@@ -4343,8 +4404,8 @@ function DataGrid(props) {
4343
4404
  columnOf
4344
4405
  })
4345
4406
  });
4346
- const [readPagination] = useState20(() => paginationReader(controller));
4347
- const [readSelectedRows] = useState20(() => selectedRowsReader(controller));
4407
+ const [readPagination] = useState18(() => paginationReader(controller));
4408
+ const [readSelectedRows] = useState18(() => selectedRowsReader(controller));
4348
4409
  const virtualizer = useRowVirtualizer({
4349
4410
  enabled: virtualized,
4350
4411
  rows: view.pageRows,
@@ -4352,7 +4413,7 @@ function DataGrid(props) {
4352
4413
  estimatedRowHeight,
4353
4414
  overscan
4354
4415
  });
4355
- useEffect7(() => {
4416
+ useEffect8(() => {
4356
4417
  if (virtualized && height === void 0) {
4357
4418
  console.error(
4358
4419
  "DataGrid: `virtualized` has no effect without `height` \u2014 a body with no bounded height has no viewport to window rows against."
@@ -4360,7 +4421,7 @@ function DataGrid(props) {
4360
4421
  }
4361
4422
  }, [virtualized, height]);
4362
4423
  const hasInfiniteScroll = infiniteScroll !== void 0;
4363
- useEffect7(() => {
4424
+ useEffect8(() => {
4364
4425
  if (paginated && hasInfiniteScroll) {
4365
4426
  console.error(
4366
4427
  "DataGrid: `paginated` and `infiniteScroll` are mutually exclusive \u2014 only `paginated` takes effect while both are set."
@@ -4389,6 +4450,7 @@ function DataGrid(props) {
4389
4450
  columnSizeDefaults
4390
4451
  });
4391
4452
  const nav = useGridNavigation({
4453
+ gridRef,
4392
4454
  headerTableRef,
4393
4455
  bodyTableRef,
4394
4456
  // `null` when virtualization is off, in which case behavior is
@@ -4411,7 +4473,15 @@ function DataGrid(props) {
4411
4473
  return entry !== void 0 && "kind" in entry && entry.kind === "group-summary";
4412
4474
  }
4413
4475
  });
4414
- const panels = useGridPanels({ rootRef: viewportRef, headerTableRef, nav });
4476
+ const overlay = useGridOverlay({
4477
+ nav,
4478
+ onContextMenuOpenChange: props.onContextMenuOpenChange
4479
+ });
4480
+ const panels = useGridPanels({
4481
+ rootRef: viewportRef,
4482
+ headerTableRef,
4483
+ overlay
4484
+ });
4415
4485
  const commands = useGridCommands({
4416
4486
  controller,
4417
4487
  commands: props.commands,
@@ -4485,7 +4555,7 @@ function DataGrid(props) {
4485
4555
  bodyTableRef,
4486
4556
  bodyScrollRef,
4487
4557
  contextMenu: props.contextMenu,
4488
- onContextMenuOpenChange: props.onContextMenuOpenChange,
4558
+ overlay,
4489
4559
  controller,
4490
4560
  commands,
4491
4561
  nav,
@@ -4493,7 +4563,7 @@ function DataGrid(props) {
4493
4563
  messages,
4494
4564
  columnName
4495
4565
  });
4496
- useEffect7(() => {
4566
+ useEffect8(() => {
4497
4567
  for (const listener of subscribersRef.current) {
4498
4568
  listener();
4499
4569
  }
@@ -4638,6 +4708,7 @@ function DataGrid(props) {
4638
4708
  /* @__PURE__ */ jsxs19(
4639
4709
  "div",
4640
4710
  {
4711
+ ref: gridRef,
4641
4712
  id: gridId,
4642
4713
  className: "gridkit-data-grid-tables",
4643
4714
  role: state.groupBy.length > 0 ? "treegrid" : "grid",
@@ -4788,12 +4859,12 @@ function DataGrid(props) {
4788
4859
  import { serializeGridState } from "@gridkitjs/core";
4789
4860
 
4790
4861
  // src/DataGrid/hooks/usePaginationState.ts
4791
- import { useCallback as useCallback3 } from "react";
4862
+ import { useCallback as useCallback5 } from "react";
4792
4863
 
4793
4864
  // src/DataGrid/hooks/useGridSnapshot.ts
4794
- import { useCallback as useCallback2, useSyncExternalStore as useSyncExternalStore3 } from "react";
4865
+ import { useCallback as useCallback4, useSyncExternalStore as useSyncExternalStore3 } from "react";
4795
4866
  function useGridSnapshot(gridRef, getSnapshot, fallback) {
4796
- const subscribe = useCallback2(
4867
+ const subscribe = useCallback4(
4797
4868
  (listener) => {
4798
4869
  const api = gridRef.current;
4799
4870
  if (api === null) {
@@ -4819,12 +4890,12 @@ var FALLBACK_PAGINATION = { pageIndex: 0, pageSize: 0 };
4819
4890
  function usePaginationState(gridRef) {
4820
4891
  const pagination = useGridSnapshot(
4821
4892
  gridRef,
4822
- useCallback3((api) => api.getPagination(), []),
4893
+ useCallback5((api) => api.getPagination(), []),
4823
4894
  FALLBACK_PAGINATION
4824
4895
  );
4825
4896
  const pageCount = useGridSnapshot(
4826
4897
  gridRef,
4827
- useCallback3((api) => api.getPageCount(), []),
4898
+ useCallback5((api) => api.getPageCount(), []),
4828
4899
  0
4829
4900
  );
4830
4901
  return {
@@ -4846,18 +4917,18 @@ function usePaginationState(gridRef) {
4846
4917
  }
4847
4918
 
4848
4919
  // src/DataGrid/hooks/useGroupByState.ts
4849
- import { useCallback as useCallback4 } from "react";
4920
+ import { useCallback as useCallback6 } from "react";
4850
4921
  var FALLBACK_GROUP_BY = [];
4851
4922
  var FALLBACK_EXPANSION = [];
4852
4923
  function useGroupByState(gridRef) {
4853
4924
  const groupBy = useGridSnapshot(
4854
4925
  gridRef,
4855
- useCallback4((api) => api.getGroupBy(), []),
4926
+ useCallback6((api) => api.getGroupBy(), []),
4856
4927
  FALLBACK_GROUP_BY
4857
4928
  );
4858
4929
  const groupExpansion = useGridSnapshot(
4859
4930
  gridRef,
4860
- useCallback4((api) => api.getGroupExpansion(), []),
4931
+ useCallback6((api) => api.getGroupExpansion(), []),
4861
4932
  FALLBACK_EXPANSION
4862
4933
  );
4863
4934
  return {
@@ -4873,34 +4944,34 @@ function useGroupByState(gridRef) {
4873
4944
  }
4874
4945
 
4875
4946
  // src/DataGrid/hooks/useColumnSortState.ts
4876
- import { useCallback as useCallback5 } from "react";
4947
+ import { useCallback as useCallback7 } from "react";
4877
4948
  var FALLBACK_SORT = [];
4878
4949
  function useColumnSortState(gridRef) {
4879
4950
  return useGridSnapshot(
4880
4951
  gridRef,
4881
- useCallback5((api) => api.getColumnSort(), []),
4952
+ useCallback7((api) => api.getColumnSort(), []),
4882
4953
  FALLBACK_SORT
4883
4954
  );
4884
4955
  }
4885
4956
 
4886
4957
  // src/DataGrid/hooks/useSelectionState.ts
4887
- import { useCallback as useCallback6 } from "react";
4958
+ import { useCallback as useCallback8 } from "react";
4888
4959
  var FALLBACK_SELECTION = [];
4889
4960
  var FALLBACK_CELL_SELECTION = null;
4890
4961
  function useSelectionState(gridRef) {
4891
4962
  const rowSelection = useGridSnapshot(
4892
4963
  gridRef,
4893
- useCallback6((api) => api.getRowSelection(), []),
4964
+ useCallback8((api) => api.getRowSelection(), []),
4894
4965
  FALLBACK_SELECTION
4895
4966
  );
4896
4967
  const columnSelection = useGridSnapshot(
4897
4968
  gridRef,
4898
- useCallback6((api) => api.getColumnSelection(), []),
4969
+ useCallback8((api) => api.getColumnSelection(), []),
4899
4970
  FALLBACK_SELECTION
4900
4971
  );
4901
4972
  const cellSelection = useGridSnapshot(
4902
4973
  gridRef,
4903
- useCallback6((api) => api.getCellSelection(), []),
4974
+ useCallback8((api) => api.getCellSelection(), []),
4904
4975
  FALLBACK_CELL_SELECTION
4905
4976
  );
4906
4977
  return {
@@ -4917,56 +4988,56 @@ function useSelectionState(gridRef) {
4917
4988
  }
4918
4989
 
4919
4990
  // src/DataGrid/hooks/useAggregateState.ts
4920
- import { useCallback as useCallback7 } from "react";
4991
+ import { useCallback as useCallback9 } from "react";
4921
4992
  var FALLBACK_AGGREGATES = /* @__PURE__ */ new Map();
4922
4993
  function useAggregateState(gridRef) {
4923
4994
  return useGridSnapshot(
4924
4995
  gridRef,
4925
- useCallback7((api) => api.getAggregates(), []),
4996
+ useCallback9((api) => api.getAggregates(), []),
4926
4997
  FALLBACK_AGGREGATES
4927
4998
  );
4928
4999
  }
4929
5000
 
4930
5001
  // src/DataGrid/hooks/useColumnSizingState.ts
4931
- import { useCallback as useCallback8 } from "react";
5002
+ import { useCallback as useCallback10 } from "react";
4932
5003
  var FALLBACK_SIZING = {};
4933
5004
  function useColumnSizingState(gridRef) {
4934
5005
  return useGridSnapshot(
4935
5006
  gridRef,
4936
- useCallback8((api) => api.getColumnSizing(), []),
5007
+ useCallback10((api) => api.getColumnSizing(), []),
4937
5008
  FALLBACK_SIZING
4938
5009
  );
4939
5010
  }
4940
5011
 
4941
5012
  // src/DataGrid/hooks/useColumnOrderState.ts
4942
- import { useCallback as useCallback9 } from "react";
5013
+ import { useCallback as useCallback11 } from "react";
4943
5014
  var FALLBACK_ORDER = [];
4944
5015
  function useColumnOrderState(gridRef) {
4945
5016
  return useGridSnapshot(
4946
5017
  gridRef,
4947
- useCallback9((api) => api.getColumnOrder(), []),
5018
+ useCallback11((api) => api.getColumnOrder(), []),
4948
5019
  FALLBACK_ORDER
4949
5020
  );
4950
5021
  }
4951
5022
 
4952
5023
  // src/DataGrid/hooks/useColumnVisibilityState.ts
4953
- import { useCallback as useCallback10 } from "react";
5024
+ import { useCallback as useCallback12 } from "react";
4954
5025
  var FALLBACK_VISIBILITY = {};
4955
5026
  function useColumnVisibilityState(gridRef) {
4956
5027
  return useGridSnapshot(
4957
5028
  gridRef,
4958
- useCallback10((api) => api.getColumnVisibility(), []),
5029
+ useCallback12((api) => api.getColumnVisibility(), []),
4959
5030
  FALLBACK_VISIBILITY
4960
5031
  );
4961
5032
  }
4962
5033
 
4963
5034
  // src/DataGrid/hooks/useFilterState.ts
4964
- import { useCallback as useCallback11, useState as useState21 } from "react";
5035
+ import { useCallback as useCallback13, useState as useState19 } from "react";
4965
5036
  function useFilterState(gridRef) {
4966
- const [fallback] = useState21(() => []);
5037
+ const [fallback] = useState19(() => []);
4967
5038
  const filter = useGridSnapshot(
4968
5039
  gridRef,
4969
- useCallback11((api) => api.getFilter(), []),
5040
+ useCallback13((api) => api.getFilter(), []),
4970
5041
  fallback
4971
5042
  );
4972
5043
  return {