react-glide-table 2.3.2 → 2.3.4

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.cjs CHANGED
@@ -538,90 +538,6 @@ function withCellUpdate(context, commitValue) {
538
538
  };
539
539
  }
540
540
 
541
- // src/components/ui/table/features/cell-selection/pasteData.ts
542
- function countLeadingEmptyCells(cells) {
543
- let depth = 0;
544
- while (depth < cells.length && cells[depth] === "") {
545
- depth += 1;
546
- }
547
- return depth;
548
- }
549
- function looksLikeSubtreeIndentation(leadingEmptyCounts) {
550
- if (leadingEmptyCounts.length === 0) return false;
551
- const firstDepth = leadingEmptyCounts[0] ?? 0;
552
- if (firstDepth !== 0) return false;
553
- return leadingEmptyCounts.some((depth) => depth > 0);
554
- }
555
- function parseClipboardTSV(text) {
556
- return parseClipboardTSVWithDepths(text).values;
557
- }
558
- function parseClipboardTSVWithDepths(text) {
559
- if (!text) return { values: [], depths: [] };
560
- const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
561
- const withoutTrailing = normalized.replace(/\n+$/, "");
562
- if (!withoutTrailing) return { values: [], depths: [] };
563
- const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
564
- const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
565
- const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
566
- const values = [];
567
- const depths = [];
568
- for (let index = 0; index < rows.length; index += 1) {
569
- const cells = rows[index] ?? [];
570
- const depth = leadingEmptyCounts[index] ?? 0;
571
- if (treatAsDepth) {
572
- values.push(cells.slice(depth));
573
- depths.push(depth);
574
- } else {
575
- values.push(cells);
576
- depths.push(0);
577
- }
578
- }
579
- return { values, depths };
580
- }
581
- function resolvePasteColumnIds(rows, startCol, width) {
582
- if (width <= 0) return [];
583
- const cells = rows[0]?.getVisibleCells() ?? [];
584
- const columnIds = [];
585
- for (let offset = 0; offset < width; offset += 1) {
586
- const cell = cells[startCol + offset];
587
- if (!cell) break;
588
- columnIds.push(cell.column.id);
589
- }
590
- return columnIds;
591
- }
592
- function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
593
- const { values, depths } = parseClipboardTSVWithDepths(text);
594
- if (values.length === 0) return null;
595
- const width = Math.max(...values.map((row) => row.length), 0);
596
- if (width === 0) return null;
597
- const columnIds = resolvePasteColumnIds(rows, startCol, width);
598
- if (columnIds.length === 0) return null;
599
- const rowIds = [];
600
- for (let offset = 0; offset < values.length; offset += 1) {
601
- const row = rows[startRow + offset];
602
- if (!row) break;
603
- rowIds.push(row.id);
604
- }
605
- const anchorRow = rows[endRow] ?? rows[startRow];
606
- return {
607
- mode,
608
- startRow,
609
- startCol,
610
- endRow,
611
- rowIds,
612
- anchorRowId: anchorRow?.id ?? "",
613
- columnIds,
614
- values,
615
- depths
616
- };
617
- }
618
- function isEditablePasteTarget(target) {
619
- if (!(target instanceof HTMLElement)) return false;
620
- const tag = target.tagName;
621
- if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
622
- return Boolean(target.isContentEditable);
623
- }
624
-
625
541
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
626
542
  var import_react3 = require("react");
627
543
 
@@ -1395,7 +1311,98 @@ function hasFillExtension(sourceBounds, fillBounds) {
1395
1311
  return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
1396
1312
  }
1397
1313
 
1314
+ // src/components/ui/table/features/cell-selection/pasteData.ts
1315
+ function countLeadingEmptyCells(cells) {
1316
+ let depth = 0;
1317
+ while (depth < cells.length && cells[depth] === "") {
1318
+ depth += 1;
1319
+ }
1320
+ return depth;
1321
+ }
1322
+ function looksLikeSubtreeIndentation(leadingEmptyCounts) {
1323
+ if (leadingEmptyCounts.length === 0) return false;
1324
+ const firstDepth = leadingEmptyCounts[0] ?? 0;
1325
+ if (firstDepth !== 0) return false;
1326
+ return leadingEmptyCounts.some((depth) => depth > 0);
1327
+ }
1328
+ function parseClipboardTSV(text) {
1329
+ return parseClipboardTSVWithDepths(text).values;
1330
+ }
1331
+ function parseClipboardTSVWithDepths(text) {
1332
+ if (!text) return { values: [], depths: [] };
1333
+ const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
1334
+ const withoutTrailing = normalized.replace(/\n+$/, "");
1335
+ if (!withoutTrailing) return { values: [], depths: [] };
1336
+ const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
1337
+ const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
1338
+ const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
1339
+ const values = [];
1340
+ const depths = [];
1341
+ for (let index = 0; index < rows.length; index += 1) {
1342
+ const cells = rows[index] ?? [];
1343
+ const depth = leadingEmptyCounts[index] ?? 0;
1344
+ if (treatAsDepth) {
1345
+ values.push(cells.slice(depth));
1346
+ depths.push(depth);
1347
+ } else {
1348
+ values.push(cells);
1349
+ depths.push(0);
1350
+ }
1351
+ }
1352
+ return { values, depths };
1353
+ }
1354
+ function resolvePasteColumnIds(rows, startCol, width) {
1355
+ if (width <= 0) return [];
1356
+ const cells = rows[0]?.getVisibleCells() ?? [];
1357
+ const columnIds = [];
1358
+ for (let offset = 0; offset < width; offset += 1) {
1359
+ const cell = cells[startCol + offset];
1360
+ if (!cell) break;
1361
+ columnIds.push(cell.column.id);
1362
+ }
1363
+ return columnIds;
1364
+ }
1365
+ function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
1366
+ const { values, depths } = parseClipboardTSVWithDepths(text);
1367
+ if (values.length === 0) return null;
1368
+ const width = Math.max(...values.map((row) => row.length), 0);
1369
+ if (width === 0) return null;
1370
+ const columnIds = resolvePasteColumnIds(rows, startCol, width);
1371
+ if (columnIds.length === 0) return null;
1372
+ const rowIds = [];
1373
+ for (let offset = 0; offset < values.length; offset += 1) {
1374
+ const row = rows[startRow + offset];
1375
+ if (!row) break;
1376
+ rowIds.push(row.id);
1377
+ }
1378
+ const anchorRow = rows[endRow] ?? rows[startRow];
1379
+ return {
1380
+ mode,
1381
+ startRow,
1382
+ startCol,
1383
+ endRow,
1384
+ rowIds,
1385
+ anchorRowId: anchorRow?.id ?? "",
1386
+ columnIds,
1387
+ values,
1388
+ depths
1389
+ };
1390
+ }
1391
+ function isEditablePasteTarget(target) {
1392
+ if (!(target instanceof HTMLElement)) return false;
1393
+ const tag = target.tagName;
1394
+ if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
1395
+ return Boolean(target.isContentEditable);
1396
+ }
1397
+
1398
1398
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
1399
+ function isFocusOutsideRoot(rootRef) {
1400
+ const root = rootRef?.current;
1401
+ if (!root) return false;
1402
+ const active = document.activeElement;
1403
+ if (!active || active === document.body) return false;
1404
+ return !root.contains(active);
1405
+ }
1399
1406
  function useCellSelection({
1400
1407
  data,
1401
1408
  rows,
@@ -1504,6 +1511,7 @@ function useCellSelection({
1504
1511
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1505
1512
  return;
1506
1513
  }
1514
+ if (isFocusOutsideRoot(rootRef)) return;
1507
1515
  const delta = getCellNavigationDelta(e.key);
1508
1516
  if (!delta) return;
1509
1517
  const prev = dragStateRef.current;
@@ -1571,6 +1579,7 @@ function useCellSelection({
1571
1579
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1572
1580
  return;
1573
1581
  }
1582
+ if (isFocusOutsideRoot(rootRef)) return;
1574
1583
  const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
1575
1584
  const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
1576
1585
  if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
@@ -1609,6 +1618,7 @@ function useCellSelection({
1609
1618
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1610
1619
  return;
1611
1620
  }
1621
+ if (isFocusOutsideRoot(rootRef)) return;
1612
1622
  if (e.shiftKey && !enableInsertPaste) {
1613
1623
  ignoreNextPasteRef.current = true;
1614
1624
  pendingPasteModeRef.current = null;
@@ -1638,6 +1648,7 @@ function useCellSelection({
1638
1648
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1639
1649
  return;
1640
1650
  }
1651
+ if (isFocusOutsideRoot(rootRef)) return;
1641
1652
  if (ignoreNextPasteRef.current) {
1642
1653
  ignoreNextPasteRef.current = false;
1643
1654
  pendingPasteModeRef.current = null;
@@ -1738,6 +1749,37 @@ function isOverlayDismissIgnoreTarget(target) {
1738
1749
  return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
1739
1750
  }
1740
1751
 
1752
+ // src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
1753
+ var clearAllByOwner = /* @__PURE__ */ new Map();
1754
+ var isListening = false;
1755
+ function handleEscape(event) {
1756
+ if (event.key !== "Escape") return;
1757
+ if (event.defaultPrevented) return;
1758
+ if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
1759
+ return;
1760
+ }
1761
+ if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
1762
+ return;
1763
+ }
1764
+ for (const clearAllSelections of clearAllByOwner.values()) {
1765
+ clearAllSelections();
1766
+ }
1767
+ }
1768
+ function registerEscapeDismiss(owner, clearAllSelections) {
1769
+ clearAllByOwner.set(owner, clearAllSelections);
1770
+ if (!isListening) {
1771
+ window.addEventListener("keydown", handleEscape);
1772
+ isListening = true;
1773
+ }
1774
+ return () => {
1775
+ clearAllByOwner.delete(owner);
1776
+ if (clearAllByOwner.size === 0 && isListening) {
1777
+ window.removeEventListener("keydown", handleEscape);
1778
+ isListening = false;
1779
+ }
1780
+ };
1781
+ }
1782
+
1741
1783
  // src/components/ui/table/features/column-reorder/columnReorder.ts
1742
1784
  function getColumnDefId(column) {
1743
1785
  if (column.id != null && column.id !== "") return column.id;
@@ -2841,6 +2883,7 @@ function useGlideTable(options) {
2841
2883
  const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
2842
2884
  const scrollRef = (0, import_react6.useRef)(null);
2843
2885
  const rootRef = (0, import_react6.useRef)(null);
2886
+ const escapeDismissOwnerRef = (0, import_react6.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
2844
2887
  const cellRendererRegistry = (0, import_react6.useMemo)(
2845
2888
  () => createCellRendererRegistry(cellRenderers),
2846
2889
  [cellRenderers]
@@ -3044,25 +3087,10 @@ function useGlideTable(options) {
3044
3087
  setInternalRowSelection({});
3045
3088
  }, [onRowSelectionChange, rowSelection, rowSelectionMode]);
3046
3089
  (0, import_react6.useEffect)(() => {
3047
- const clearAllSelections = () => {
3090
+ return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
3048
3091
  clearCellSelection();
3049
3092
  clearRowSelection();
3050
- };
3051
- const handleKeyDown = (event) => {
3052
- if (event.key !== "Escape") return;
3053
- if (event.defaultPrevented) return;
3054
- if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
3055
- return;
3056
- }
3057
- if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
3058
- return;
3059
- }
3060
- clearAllSelections();
3061
- };
3062
- window.addEventListener("keydown", handleKeyDown);
3063
- return () => {
3064
- window.removeEventListener("keydown", handleKeyDown);
3065
- };
3093
+ });
3066
3094
  }, [clearCellSelection, clearRowSelection]);
3067
3095
  const {
3068
3096
  editingCell,
package/dist/index.js CHANGED
@@ -441,90 +441,6 @@ function withCellUpdate(context, commitValue) {
441
441
  };
442
442
  }
443
443
 
444
- // src/components/ui/table/features/cell-selection/pasteData.ts
445
- function countLeadingEmptyCells(cells) {
446
- let depth = 0;
447
- while (depth < cells.length && cells[depth] === "") {
448
- depth += 1;
449
- }
450
- return depth;
451
- }
452
- function looksLikeSubtreeIndentation(leadingEmptyCounts) {
453
- if (leadingEmptyCounts.length === 0) return false;
454
- const firstDepth = leadingEmptyCounts[0] ?? 0;
455
- if (firstDepth !== 0) return false;
456
- return leadingEmptyCounts.some((depth) => depth > 0);
457
- }
458
- function parseClipboardTSV(text) {
459
- return parseClipboardTSVWithDepths(text).values;
460
- }
461
- function parseClipboardTSVWithDepths(text) {
462
- if (!text) return { values: [], depths: [] };
463
- const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
464
- const withoutTrailing = normalized.replace(/\n+$/, "");
465
- if (!withoutTrailing) return { values: [], depths: [] };
466
- const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
467
- const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
468
- const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
469
- const values = [];
470
- const depths = [];
471
- for (let index = 0; index < rows.length; index += 1) {
472
- const cells = rows[index] ?? [];
473
- const depth = leadingEmptyCounts[index] ?? 0;
474
- if (treatAsDepth) {
475
- values.push(cells.slice(depth));
476
- depths.push(depth);
477
- } else {
478
- values.push(cells);
479
- depths.push(0);
480
- }
481
- }
482
- return { values, depths };
483
- }
484
- function resolvePasteColumnIds(rows, startCol, width) {
485
- if (width <= 0) return [];
486
- const cells = rows[0]?.getVisibleCells() ?? [];
487
- const columnIds = [];
488
- for (let offset = 0; offset < width; offset += 1) {
489
- const cell = cells[startCol + offset];
490
- if (!cell) break;
491
- columnIds.push(cell.column.id);
492
- }
493
- return columnIds;
494
- }
495
- function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
496
- const { values, depths } = parseClipboardTSVWithDepths(text);
497
- if (values.length === 0) return null;
498
- const width = Math.max(...values.map((row) => row.length), 0);
499
- if (width === 0) return null;
500
- const columnIds = resolvePasteColumnIds(rows, startCol, width);
501
- if (columnIds.length === 0) return null;
502
- const rowIds = [];
503
- for (let offset = 0; offset < values.length; offset += 1) {
504
- const row = rows[startRow + offset];
505
- if (!row) break;
506
- rowIds.push(row.id);
507
- }
508
- const anchorRow = rows[endRow] ?? rows[startRow];
509
- return {
510
- mode,
511
- startRow,
512
- startCol,
513
- endRow,
514
- rowIds,
515
- anchorRowId: anchorRow?.id ?? "",
516
- columnIds,
517
- values,
518
- depths
519
- };
520
- }
521
- function isEditablePasteTarget(target) {
522
- if (!(target instanceof HTMLElement)) return false;
523
- const tag = target.tagName;
524
- if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
525
- return Boolean(target.isContentEditable);
526
- }
527
-
528
444
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
529
445
  import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
530
446
 
@@ -1298,7 +1214,98 @@ function hasFillExtension(sourceBounds, fillBounds) {
1298
1214
  return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
1299
1215
  }
1300
1216
 
1217
+ // src/components/ui/table/features/cell-selection/pasteData.ts
1218
+ function countLeadingEmptyCells(cells) {
1219
+ let depth = 0;
1220
+ while (depth < cells.length && cells[depth] === "") {
1221
+ depth += 1;
1222
+ }
1223
+ return depth;
1224
+ }
1225
+ function looksLikeSubtreeIndentation(leadingEmptyCounts) {
1226
+ if (leadingEmptyCounts.length === 0) return false;
1227
+ const firstDepth = leadingEmptyCounts[0] ?? 0;
1228
+ if (firstDepth !== 0) return false;
1229
+ return leadingEmptyCounts.some((depth) => depth > 0);
1230
+ }
1231
+ function parseClipboardTSV(text) {
1232
+ return parseClipboardTSVWithDepths(text).values;
1233
+ }
1234
+ function parseClipboardTSVWithDepths(text) {
1235
+ if (!text) return { values: [], depths: [] };
1236
+ const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
1237
+ const withoutTrailing = normalized.replace(/\n+$/, "");
1238
+ if (!withoutTrailing) return { values: [], depths: [] };
1239
+ const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
1240
+ const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
1241
+ const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
1242
+ const values = [];
1243
+ const depths = [];
1244
+ for (let index = 0; index < rows.length; index += 1) {
1245
+ const cells = rows[index] ?? [];
1246
+ const depth = leadingEmptyCounts[index] ?? 0;
1247
+ if (treatAsDepth) {
1248
+ values.push(cells.slice(depth));
1249
+ depths.push(depth);
1250
+ } else {
1251
+ values.push(cells);
1252
+ depths.push(0);
1253
+ }
1254
+ }
1255
+ return { values, depths };
1256
+ }
1257
+ function resolvePasteColumnIds(rows, startCol, width) {
1258
+ if (width <= 0) return [];
1259
+ const cells = rows[0]?.getVisibleCells() ?? [];
1260
+ const columnIds = [];
1261
+ for (let offset = 0; offset < width; offset += 1) {
1262
+ const cell = cells[startCol + offset];
1263
+ if (!cell) break;
1264
+ columnIds.push(cell.column.id);
1265
+ }
1266
+ return columnIds;
1267
+ }
1268
+ function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
1269
+ const { values, depths } = parseClipboardTSVWithDepths(text);
1270
+ if (values.length === 0) return null;
1271
+ const width = Math.max(...values.map((row) => row.length), 0);
1272
+ if (width === 0) return null;
1273
+ const columnIds = resolvePasteColumnIds(rows, startCol, width);
1274
+ if (columnIds.length === 0) return null;
1275
+ const rowIds = [];
1276
+ for (let offset = 0; offset < values.length; offset += 1) {
1277
+ const row = rows[startRow + offset];
1278
+ if (!row) break;
1279
+ rowIds.push(row.id);
1280
+ }
1281
+ const anchorRow = rows[endRow] ?? rows[startRow];
1282
+ return {
1283
+ mode,
1284
+ startRow,
1285
+ startCol,
1286
+ endRow,
1287
+ rowIds,
1288
+ anchorRowId: anchorRow?.id ?? "",
1289
+ columnIds,
1290
+ values,
1291
+ depths
1292
+ };
1293
+ }
1294
+ function isEditablePasteTarget(target) {
1295
+ if (!(target instanceof HTMLElement)) return false;
1296
+ const tag = target.tagName;
1297
+ if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
1298
+ return Boolean(target.isContentEditable);
1299
+ }
1300
+
1301
1301
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
1302
+ function isFocusOutsideRoot(rootRef) {
1303
+ const root = rootRef?.current;
1304
+ if (!root) return false;
1305
+ const active = document.activeElement;
1306
+ if (!active || active === document.body) return false;
1307
+ return !root.contains(active);
1308
+ }
1302
1309
  function useCellSelection({
1303
1310
  data,
1304
1311
  rows,
@@ -1407,6 +1414,7 @@ function useCellSelection({
1407
1414
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1408
1415
  return;
1409
1416
  }
1417
+ if (isFocusOutsideRoot(rootRef)) return;
1410
1418
  const delta = getCellNavigationDelta(e.key);
1411
1419
  if (!delta) return;
1412
1420
  const prev = dragStateRef.current;
@@ -1474,6 +1482,7 @@ function useCellSelection({
1474
1482
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1475
1483
  return;
1476
1484
  }
1485
+ if (isFocusOutsideRoot(rootRef)) return;
1477
1486
  const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
1478
1487
  const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
1479
1488
  if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
@@ -1512,6 +1521,7 @@ function useCellSelection({
1512
1521
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1513
1522
  return;
1514
1523
  }
1524
+ if (isFocusOutsideRoot(rootRef)) return;
1515
1525
  if (e.shiftKey && !enableInsertPaste) {
1516
1526
  ignoreNextPasteRef.current = true;
1517
1527
  pendingPasteModeRef.current = null;
@@ -1541,6 +1551,7 @@ function useCellSelection({
1541
1551
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1542
1552
  return;
1543
1553
  }
1554
+ if (isFocusOutsideRoot(rootRef)) return;
1544
1555
  if (ignoreNextPasteRef.current) {
1545
1556
  ignoreNextPasteRef.current = false;
1546
1557
  pendingPasteModeRef.current = null;
@@ -1641,6 +1652,37 @@ function isOverlayDismissIgnoreTarget(target) {
1641
1652
  return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
1642
1653
  }
1643
1654
 
1655
+ // src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
1656
+ var clearAllByOwner = /* @__PURE__ */ new Map();
1657
+ var isListening = false;
1658
+ function handleEscape(event) {
1659
+ if (event.key !== "Escape") return;
1660
+ if (event.defaultPrevented) return;
1661
+ if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
1662
+ return;
1663
+ }
1664
+ if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
1665
+ return;
1666
+ }
1667
+ for (const clearAllSelections of clearAllByOwner.values()) {
1668
+ clearAllSelections();
1669
+ }
1670
+ }
1671
+ function registerEscapeDismiss(owner, clearAllSelections) {
1672
+ clearAllByOwner.set(owner, clearAllSelections);
1673
+ if (!isListening) {
1674
+ window.addEventListener("keydown", handleEscape);
1675
+ isListening = true;
1676
+ }
1677
+ return () => {
1678
+ clearAllByOwner.delete(owner);
1679
+ if (clearAllByOwner.size === 0 && isListening) {
1680
+ window.removeEventListener("keydown", handleEscape);
1681
+ isListening = false;
1682
+ }
1683
+ };
1684
+ }
1685
+
1644
1686
  // src/components/ui/table/features/column-reorder/columnReorder.ts
1645
1687
  function getColumnDefId(column) {
1646
1688
  if (column.id != null && column.id !== "") return column.id;
@@ -2751,6 +2793,7 @@ function useGlideTable(options) {
2751
2793
  const [hoveredRowIndex, setHoveredRowIndex] = useState4(null);
2752
2794
  const scrollRef = useRef5(null);
2753
2795
  const rootRef = useRef5(null);
2796
+ const escapeDismissOwnerRef = useRef5(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
2754
2797
  const cellRendererRegistry = useMemo3(
2755
2798
  () => createCellRendererRegistry(cellRenderers),
2756
2799
  [cellRenderers]
@@ -2954,25 +2997,10 @@ function useGlideTable(options) {
2954
2997
  setInternalRowSelection({});
2955
2998
  }, [onRowSelectionChange, rowSelection, rowSelectionMode]);
2956
2999
  useEffect5(() => {
2957
- const clearAllSelections = () => {
3000
+ return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
2958
3001
  clearCellSelection();
2959
3002
  clearRowSelection();
2960
- };
2961
- const handleKeyDown = (event) => {
2962
- if (event.key !== "Escape") return;
2963
- if (event.defaultPrevented) return;
2964
- if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
2965
- return;
2966
- }
2967
- if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
2968
- return;
2969
- }
2970
- clearAllSelections();
2971
- };
2972
- window.addEventListener("keydown", handleKeyDown);
2973
- return () => {
2974
- window.removeEventListener("keydown", handleKeyDown);
2975
- };
3003
+ });
2976
3004
  }, [clearCellSelection, clearRowSelection]);
2977
3005
  const {
2978
3006
  editingCell,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-glide-table",
3
- "version": "2.3.2",
3
+ "version": "2.3.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/zpxlffjrm/react-glide-table.git"