react-glide-table 2.3.3 → 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/compound.cjs +115 -98
- package/dist/compound.js +115 -98
- package/dist/core.cjs +118 -101
- package/dist/core.js +118 -101
- package/dist/index.cjs +118 -101
- package/dist/index.js +118 -101
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -526,90 +526,6 @@ function withCellUpdate(context, commitValue) {
|
|
|
526
526
|
};
|
|
527
527
|
}
|
|
528
528
|
|
|
529
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
530
|
-
function countLeadingEmptyCells(cells) {
|
|
531
|
-
let depth = 0;
|
|
532
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
533
|
-
depth += 1;
|
|
534
|
-
}
|
|
535
|
-
return depth;
|
|
536
|
-
}
|
|
537
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
538
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
539
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
540
|
-
if (firstDepth !== 0) return false;
|
|
541
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
542
|
-
}
|
|
543
|
-
function parseClipboardTSV(text) {
|
|
544
|
-
return parseClipboardTSVWithDepths(text).values;
|
|
545
|
-
}
|
|
546
|
-
function parseClipboardTSVWithDepths(text) {
|
|
547
|
-
if (!text) return { values: [], depths: [] };
|
|
548
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
549
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
550
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
551
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
552
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
553
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
554
|
-
const values = [];
|
|
555
|
-
const depths = [];
|
|
556
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
557
|
-
const cells = rows[index] ?? [];
|
|
558
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
559
|
-
if (treatAsDepth) {
|
|
560
|
-
values.push(cells.slice(depth));
|
|
561
|
-
depths.push(depth);
|
|
562
|
-
} else {
|
|
563
|
-
values.push(cells);
|
|
564
|
-
depths.push(0);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return { values, depths };
|
|
568
|
-
}
|
|
569
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
570
|
-
if (width <= 0) return [];
|
|
571
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
572
|
-
const columnIds = [];
|
|
573
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
574
|
-
const cell = cells[startCol + offset];
|
|
575
|
-
if (!cell) break;
|
|
576
|
-
columnIds.push(cell.column.id);
|
|
577
|
-
}
|
|
578
|
-
return columnIds;
|
|
579
|
-
}
|
|
580
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
581
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
582
|
-
if (values.length === 0) return null;
|
|
583
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
584
|
-
if (width === 0) return null;
|
|
585
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
586
|
-
if (columnIds.length === 0) return null;
|
|
587
|
-
const rowIds = [];
|
|
588
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
589
|
-
const row = rows[startRow + offset];
|
|
590
|
-
if (!row) break;
|
|
591
|
-
rowIds.push(row.id);
|
|
592
|
-
}
|
|
593
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
594
|
-
return {
|
|
595
|
-
mode,
|
|
596
|
-
startRow,
|
|
597
|
-
startCol,
|
|
598
|
-
endRow,
|
|
599
|
-
rowIds,
|
|
600
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
601
|
-
columnIds,
|
|
602
|
-
values,
|
|
603
|
-
depths
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
function isEditablePasteTarget(target) {
|
|
607
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
608
|
-
const tag = target.tagName;
|
|
609
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
610
|
-
return Boolean(target.isContentEditable);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
529
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
614
530
|
var import_react3 = require("react");
|
|
615
531
|
|
|
@@ -1383,6 +1299,90 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1383
1299
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1384
1300
|
}
|
|
1385
1301
|
|
|
1302
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1303
|
+
function countLeadingEmptyCells(cells) {
|
|
1304
|
+
let depth = 0;
|
|
1305
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1306
|
+
depth += 1;
|
|
1307
|
+
}
|
|
1308
|
+
return depth;
|
|
1309
|
+
}
|
|
1310
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1311
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1312
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1313
|
+
if (firstDepth !== 0) return false;
|
|
1314
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1315
|
+
}
|
|
1316
|
+
function parseClipboardTSV(text) {
|
|
1317
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1318
|
+
}
|
|
1319
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1320
|
+
if (!text) return { values: [], depths: [] };
|
|
1321
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1322
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1323
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1324
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1325
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1326
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1327
|
+
const values = [];
|
|
1328
|
+
const depths = [];
|
|
1329
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1330
|
+
const cells = rows[index] ?? [];
|
|
1331
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1332
|
+
if (treatAsDepth) {
|
|
1333
|
+
values.push(cells.slice(depth));
|
|
1334
|
+
depths.push(depth);
|
|
1335
|
+
} else {
|
|
1336
|
+
values.push(cells);
|
|
1337
|
+
depths.push(0);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
return { values, depths };
|
|
1341
|
+
}
|
|
1342
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1343
|
+
if (width <= 0) return [];
|
|
1344
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1345
|
+
const columnIds = [];
|
|
1346
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1347
|
+
const cell = cells[startCol + offset];
|
|
1348
|
+
if (!cell) break;
|
|
1349
|
+
columnIds.push(cell.column.id);
|
|
1350
|
+
}
|
|
1351
|
+
return columnIds;
|
|
1352
|
+
}
|
|
1353
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1354
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1355
|
+
if (values.length === 0) return null;
|
|
1356
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1357
|
+
if (width === 0) return null;
|
|
1358
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1359
|
+
if (columnIds.length === 0) return null;
|
|
1360
|
+
const rowIds = [];
|
|
1361
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1362
|
+
const row = rows[startRow + offset];
|
|
1363
|
+
if (!row) break;
|
|
1364
|
+
rowIds.push(row.id);
|
|
1365
|
+
}
|
|
1366
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1367
|
+
return {
|
|
1368
|
+
mode,
|
|
1369
|
+
startRow,
|
|
1370
|
+
startCol,
|
|
1371
|
+
endRow,
|
|
1372
|
+
rowIds,
|
|
1373
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1374
|
+
columnIds,
|
|
1375
|
+
values,
|
|
1376
|
+
depths
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
function isEditablePasteTarget(target) {
|
|
1380
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1381
|
+
const tag = target.tagName;
|
|
1382
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1383
|
+
return Boolean(target.isContentEditable);
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
1386
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1387
1387
|
function isFocusOutsideRoot(rootRef) {
|
|
1388
1388
|
const root = rootRef?.current;
|
|
@@ -1737,6 +1737,37 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1737
1737
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1738
1738
|
}
|
|
1739
1739
|
|
|
1740
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1741
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1742
|
+
var isListening = false;
|
|
1743
|
+
function handleEscape(event) {
|
|
1744
|
+
if (event.key !== "Escape") return;
|
|
1745
|
+
if (event.defaultPrevented) return;
|
|
1746
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1747
|
+
return;
|
|
1748
|
+
}
|
|
1749
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
1753
|
+
clearAllSelections();
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1757
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1758
|
+
if (!isListening) {
|
|
1759
|
+
window.addEventListener("keydown", handleEscape);
|
|
1760
|
+
isListening = true;
|
|
1761
|
+
}
|
|
1762
|
+
return () => {
|
|
1763
|
+
clearAllByOwner.delete(owner);
|
|
1764
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1765
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1766
|
+
isListening = false;
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1740
1771
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1741
1772
|
function getColumnDefId(column) {
|
|
1742
1773
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2834,6 +2865,7 @@ function useGlideTable(options) {
|
|
|
2834
2865
|
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
|
|
2835
2866
|
const scrollRef = (0, import_react6.useRef)(null);
|
|
2836
2867
|
const rootRef = (0, import_react6.useRef)(null);
|
|
2868
|
+
const escapeDismissOwnerRef = (0, import_react6.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2837
2869
|
const cellRendererRegistry = (0, import_react6.useMemo)(
|
|
2838
2870
|
() => createCellRendererRegistry(cellRenderers),
|
|
2839
2871
|
[cellRenderers]
|
|
@@ -3037,25 +3069,10 @@ function useGlideTable(options) {
|
|
|
3037
3069
|
setInternalRowSelection({});
|
|
3038
3070
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
3039
3071
|
(0, import_react6.useEffect)(() => {
|
|
3040
|
-
|
|
3072
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
3041
3073
|
clearCellSelection();
|
|
3042
3074
|
clearRowSelection();
|
|
3043
|
-
};
|
|
3044
|
-
const handleKeyDown = (event) => {
|
|
3045
|
-
if (event.key !== "Escape") return;
|
|
3046
|
-
if (event.defaultPrevented) return;
|
|
3047
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3048
|
-
return;
|
|
3049
|
-
}
|
|
3050
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3051
|
-
return;
|
|
3052
|
-
}
|
|
3053
|
-
clearAllSelections();
|
|
3054
|
-
};
|
|
3055
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
3056
|
-
return () => {
|
|
3057
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
3058
|
-
};
|
|
3075
|
+
});
|
|
3059
3076
|
}, [clearCellSelection, clearRowSelection]);
|
|
3060
3077
|
const {
|
|
3061
3078
|
editingCell,
|
package/dist/core.js
CHANGED
|
@@ -432,90 +432,6 @@ function withCellUpdate(context, commitValue) {
|
|
|
432
432
|
};
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
436
|
-
function countLeadingEmptyCells(cells) {
|
|
437
|
-
let depth = 0;
|
|
438
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
439
|
-
depth += 1;
|
|
440
|
-
}
|
|
441
|
-
return depth;
|
|
442
|
-
}
|
|
443
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
444
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
445
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
446
|
-
if (firstDepth !== 0) return false;
|
|
447
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
448
|
-
}
|
|
449
|
-
function parseClipboardTSV(text) {
|
|
450
|
-
return parseClipboardTSVWithDepths(text).values;
|
|
451
|
-
}
|
|
452
|
-
function parseClipboardTSVWithDepths(text) {
|
|
453
|
-
if (!text) return { values: [], depths: [] };
|
|
454
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
455
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
456
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
457
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
458
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
459
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
460
|
-
const values = [];
|
|
461
|
-
const depths = [];
|
|
462
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
463
|
-
const cells = rows[index] ?? [];
|
|
464
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
465
|
-
if (treatAsDepth) {
|
|
466
|
-
values.push(cells.slice(depth));
|
|
467
|
-
depths.push(depth);
|
|
468
|
-
} else {
|
|
469
|
-
values.push(cells);
|
|
470
|
-
depths.push(0);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return { values, depths };
|
|
474
|
-
}
|
|
475
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
476
|
-
if (width <= 0) return [];
|
|
477
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
478
|
-
const columnIds = [];
|
|
479
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
480
|
-
const cell = cells[startCol + offset];
|
|
481
|
-
if (!cell) break;
|
|
482
|
-
columnIds.push(cell.column.id);
|
|
483
|
-
}
|
|
484
|
-
return columnIds;
|
|
485
|
-
}
|
|
486
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
487
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
488
|
-
if (values.length === 0) return null;
|
|
489
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
490
|
-
if (width === 0) return null;
|
|
491
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
492
|
-
if (columnIds.length === 0) return null;
|
|
493
|
-
const rowIds = [];
|
|
494
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
495
|
-
const row = rows[startRow + offset];
|
|
496
|
-
if (!row) break;
|
|
497
|
-
rowIds.push(row.id);
|
|
498
|
-
}
|
|
499
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
500
|
-
return {
|
|
501
|
-
mode,
|
|
502
|
-
startRow,
|
|
503
|
-
startCol,
|
|
504
|
-
endRow,
|
|
505
|
-
rowIds,
|
|
506
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
507
|
-
columnIds,
|
|
508
|
-
values,
|
|
509
|
-
depths
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
function isEditablePasteTarget(target) {
|
|
513
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
514
|
-
const tag = target.tagName;
|
|
515
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
516
|
-
return Boolean(target.isContentEditable);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
435
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
520
436
|
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
521
437
|
|
|
@@ -1289,6 +1205,90 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1289
1205
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1290
1206
|
}
|
|
1291
1207
|
|
|
1208
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1209
|
+
function countLeadingEmptyCells(cells) {
|
|
1210
|
+
let depth = 0;
|
|
1211
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1212
|
+
depth += 1;
|
|
1213
|
+
}
|
|
1214
|
+
return depth;
|
|
1215
|
+
}
|
|
1216
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1217
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1218
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1219
|
+
if (firstDepth !== 0) return false;
|
|
1220
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1221
|
+
}
|
|
1222
|
+
function parseClipboardTSV(text) {
|
|
1223
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1224
|
+
}
|
|
1225
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1226
|
+
if (!text) return { values: [], depths: [] };
|
|
1227
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1228
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1229
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1230
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1231
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1232
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1233
|
+
const values = [];
|
|
1234
|
+
const depths = [];
|
|
1235
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1236
|
+
const cells = rows[index] ?? [];
|
|
1237
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1238
|
+
if (treatAsDepth) {
|
|
1239
|
+
values.push(cells.slice(depth));
|
|
1240
|
+
depths.push(depth);
|
|
1241
|
+
} else {
|
|
1242
|
+
values.push(cells);
|
|
1243
|
+
depths.push(0);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return { values, depths };
|
|
1247
|
+
}
|
|
1248
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1249
|
+
if (width <= 0) return [];
|
|
1250
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1251
|
+
const columnIds = [];
|
|
1252
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1253
|
+
const cell = cells[startCol + offset];
|
|
1254
|
+
if (!cell) break;
|
|
1255
|
+
columnIds.push(cell.column.id);
|
|
1256
|
+
}
|
|
1257
|
+
return columnIds;
|
|
1258
|
+
}
|
|
1259
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1260
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1261
|
+
if (values.length === 0) return null;
|
|
1262
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1263
|
+
if (width === 0) return null;
|
|
1264
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1265
|
+
if (columnIds.length === 0) return null;
|
|
1266
|
+
const rowIds = [];
|
|
1267
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1268
|
+
const row = rows[startRow + offset];
|
|
1269
|
+
if (!row) break;
|
|
1270
|
+
rowIds.push(row.id);
|
|
1271
|
+
}
|
|
1272
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1273
|
+
return {
|
|
1274
|
+
mode,
|
|
1275
|
+
startRow,
|
|
1276
|
+
startCol,
|
|
1277
|
+
endRow,
|
|
1278
|
+
rowIds,
|
|
1279
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1280
|
+
columnIds,
|
|
1281
|
+
values,
|
|
1282
|
+
depths
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
function isEditablePasteTarget(target) {
|
|
1286
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1287
|
+
const tag = target.tagName;
|
|
1288
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1289
|
+
return Boolean(target.isContentEditable);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
1292
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1293
1293
|
function isFocusOutsideRoot(rootRef) {
|
|
1294
1294
|
const root = rootRef?.current;
|
|
@@ -1643,6 +1643,37 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1643
1643
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1644
1644
|
}
|
|
1645
1645
|
|
|
1646
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1647
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1648
|
+
var isListening = false;
|
|
1649
|
+
function handleEscape(event) {
|
|
1650
|
+
if (event.key !== "Escape") return;
|
|
1651
|
+
if (event.defaultPrevented) return;
|
|
1652
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
1659
|
+
clearAllSelections();
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1663
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1664
|
+
if (!isListening) {
|
|
1665
|
+
window.addEventListener("keydown", handleEscape);
|
|
1666
|
+
isListening = true;
|
|
1667
|
+
}
|
|
1668
|
+
return () => {
|
|
1669
|
+
clearAllByOwner.delete(owner);
|
|
1670
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1671
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1672
|
+
isListening = false;
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1646
1677
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1647
1678
|
function getColumnDefId(column) {
|
|
1648
1679
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2747,6 +2778,7 @@ function useGlideTable(options) {
|
|
|
2747
2778
|
const [hoveredRowIndex, setHoveredRowIndex] = useState4(null);
|
|
2748
2779
|
const scrollRef = useRef5(null);
|
|
2749
2780
|
const rootRef = useRef5(null);
|
|
2781
|
+
const escapeDismissOwnerRef = useRef5(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2750
2782
|
const cellRendererRegistry = useMemo3(
|
|
2751
2783
|
() => createCellRendererRegistry(cellRenderers),
|
|
2752
2784
|
[cellRenderers]
|
|
@@ -2950,25 +2982,10 @@ function useGlideTable(options) {
|
|
|
2950
2982
|
setInternalRowSelection({});
|
|
2951
2983
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
2952
2984
|
useEffect5(() => {
|
|
2953
|
-
|
|
2985
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
2954
2986
|
clearCellSelection();
|
|
2955
2987
|
clearRowSelection();
|
|
2956
|
-
};
|
|
2957
|
-
const handleKeyDown = (event) => {
|
|
2958
|
-
if (event.key !== "Escape") return;
|
|
2959
|
-
if (event.defaultPrevented) return;
|
|
2960
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
2961
|
-
return;
|
|
2962
|
-
}
|
|
2963
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
2964
|
-
return;
|
|
2965
|
-
}
|
|
2966
|
-
clearAllSelections();
|
|
2967
|
-
};
|
|
2968
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
2969
|
-
return () => {
|
|
2970
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
2971
|
-
};
|
|
2988
|
+
});
|
|
2972
2989
|
}, [clearCellSelection, clearRowSelection]);
|
|
2973
2990
|
const {
|
|
2974
2991
|
editingCell,
|