react-glide-table 2.3.3 → 2.3.5
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 +146 -99
- package/dist/compound.js +146 -99
- package/dist/core.cjs +149 -102
- package/dist/core.js +149 -102
- package/dist/index.cjs +149 -102
- package/dist/index.js +149 -102
- 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
|
|
|
@@ -1316,15 +1232,41 @@ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options)
|
|
|
1316
1232
|
options
|
|
1317
1233
|
);
|
|
1318
1234
|
}
|
|
1235
|
+
function writeTextWithExecCommand(text) {
|
|
1236
|
+
if (typeof document === "undefined") return false;
|
|
1237
|
+
const textarea = document.createElement("textarea");
|
|
1238
|
+
textarea.value = text;
|
|
1239
|
+
textarea.setAttribute("readonly", "");
|
|
1240
|
+
textarea.style.position = "fixed";
|
|
1241
|
+
textarea.style.top = "0";
|
|
1242
|
+
textarea.style.left = "0";
|
|
1243
|
+
textarea.style.opacity = "0";
|
|
1244
|
+
textarea.style.pointerEvents = "none";
|
|
1245
|
+
document.body.appendChild(textarea);
|
|
1246
|
+
const previouslyFocused = document.activeElement;
|
|
1247
|
+
try {
|
|
1248
|
+
textarea.focus();
|
|
1249
|
+
textarea.select();
|
|
1250
|
+
return document.execCommand("copy");
|
|
1251
|
+
} catch {
|
|
1252
|
+
return false;
|
|
1253
|
+
} finally {
|
|
1254
|
+
document.body.removeChild(textarea);
|
|
1255
|
+
previouslyFocused?.focus?.();
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1319
1258
|
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
1320
1259
|
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
1321
1260
|
if (!text) return false;
|
|
1261
|
+
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
1262
|
+
return writeTextWithExecCommand(text);
|
|
1263
|
+
}
|
|
1322
1264
|
try {
|
|
1323
1265
|
await navigator.clipboard.writeText(text);
|
|
1266
|
+
return true;
|
|
1324
1267
|
} catch {
|
|
1325
1268
|
return false;
|
|
1326
1269
|
}
|
|
1327
|
-
return true;
|
|
1328
1270
|
}
|
|
1329
1271
|
|
|
1330
1272
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
@@ -1383,6 +1325,90 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1383
1325
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1384
1326
|
}
|
|
1385
1327
|
|
|
1328
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1329
|
+
function countLeadingEmptyCells(cells) {
|
|
1330
|
+
let depth = 0;
|
|
1331
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1332
|
+
depth += 1;
|
|
1333
|
+
}
|
|
1334
|
+
return depth;
|
|
1335
|
+
}
|
|
1336
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1337
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1338
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1339
|
+
if (firstDepth !== 0) return false;
|
|
1340
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1341
|
+
}
|
|
1342
|
+
function parseClipboardTSV(text) {
|
|
1343
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1344
|
+
}
|
|
1345
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1346
|
+
if (!text) return { values: [], depths: [] };
|
|
1347
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1348
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1349
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1350
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1351
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1352
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1353
|
+
const values = [];
|
|
1354
|
+
const depths = [];
|
|
1355
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1356
|
+
const cells = rows[index] ?? [];
|
|
1357
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1358
|
+
if (treatAsDepth) {
|
|
1359
|
+
values.push(cells.slice(depth));
|
|
1360
|
+
depths.push(depth);
|
|
1361
|
+
} else {
|
|
1362
|
+
values.push(cells);
|
|
1363
|
+
depths.push(0);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
return { values, depths };
|
|
1367
|
+
}
|
|
1368
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1369
|
+
if (width <= 0) return [];
|
|
1370
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1371
|
+
const columnIds = [];
|
|
1372
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1373
|
+
const cell = cells[startCol + offset];
|
|
1374
|
+
if (!cell) break;
|
|
1375
|
+
columnIds.push(cell.column.id);
|
|
1376
|
+
}
|
|
1377
|
+
return columnIds;
|
|
1378
|
+
}
|
|
1379
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1380
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1381
|
+
if (values.length === 0) return null;
|
|
1382
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1383
|
+
if (width === 0) return null;
|
|
1384
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1385
|
+
if (columnIds.length === 0) return null;
|
|
1386
|
+
const rowIds = [];
|
|
1387
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1388
|
+
const row = rows[startRow + offset];
|
|
1389
|
+
if (!row) break;
|
|
1390
|
+
rowIds.push(row.id);
|
|
1391
|
+
}
|
|
1392
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1393
|
+
return {
|
|
1394
|
+
mode,
|
|
1395
|
+
startRow,
|
|
1396
|
+
startCol,
|
|
1397
|
+
endRow,
|
|
1398
|
+
rowIds,
|
|
1399
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1400
|
+
columnIds,
|
|
1401
|
+
values,
|
|
1402
|
+
depths
|
|
1403
|
+
};
|
|
1404
|
+
}
|
|
1405
|
+
function isEditablePasteTarget(target) {
|
|
1406
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1407
|
+
const tag = target.tagName;
|
|
1408
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1409
|
+
return Boolean(target.isContentEditable);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1386
1412
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1387
1413
|
function isFocusOutsideRoot(rootRef) {
|
|
1388
1414
|
const root = rootRef?.current;
|
|
@@ -1737,6 +1763,41 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1737
1763
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1738
1764
|
}
|
|
1739
1765
|
|
|
1766
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1767
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1768
|
+
var isListening = false;
|
|
1769
|
+
function handleEscape(event) {
|
|
1770
|
+
if (event.key !== "Escape") return;
|
|
1771
|
+
if (event.defaultPrevented) return;
|
|
1772
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1773
|
+
return;
|
|
1774
|
+
}
|
|
1775
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
for (const clearAllSelections of [...clearAllByOwner.values()]) {
|
|
1779
|
+
try {
|
|
1780
|
+
clearAllSelections();
|
|
1781
|
+
} catch (error) {
|
|
1782
|
+
console.error("[react-glide-table] escape-dismiss callback failed", error);
|
|
1783
|
+
}
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1787
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1788
|
+
if (!isListening) {
|
|
1789
|
+
window.addEventListener("keydown", handleEscape);
|
|
1790
|
+
isListening = true;
|
|
1791
|
+
}
|
|
1792
|
+
return () => {
|
|
1793
|
+
clearAllByOwner.delete(owner);
|
|
1794
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1795
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1796
|
+
isListening = false;
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1740
1801
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1741
1802
|
function getColumnDefId(column) {
|
|
1742
1803
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2834,6 +2895,7 @@ function useGlideTable(options) {
|
|
|
2834
2895
|
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
|
|
2835
2896
|
const scrollRef = (0, import_react6.useRef)(null);
|
|
2836
2897
|
const rootRef = (0, import_react6.useRef)(null);
|
|
2898
|
+
const escapeDismissOwnerRef = (0, import_react6.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2837
2899
|
const cellRendererRegistry = (0, import_react6.useMemo)(
|
|
2838
2900
|
() => createCellRendererRegistry(cellRenderers),
|
|
2839
2901
|
[cellRenderers]
|
|
@@ -3037,25 +3099,10 @@ function useGlideTable(options) {
|
|
|
3037
3099
|
setInternalRowSelection({});
|
|
3038
3100
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
3039
3101
|
(0, import_react6.useEffect)(() => {
|
|
3040
|
-
|
|
3102
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
3041
3103
|
clearCellSelection();
|
|
3042
3104
|
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
|
-
};
|
|
3105
|
+
});
|
|
3059
3106
|
}, [clearCellSelection, clearRowSelection]);
|
|
3060
3107
|
const {
|
|
3061
3108
|
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
|
|
|
@@ -1222,15 +1138,41 @@ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options)
|
|
|
1222
1138
|
options
|
|
1223
1139
|
);
|
|
1224
1140
|
}
|
|
1141
|
+
function writeTextWithExecCommand(text) {
|
|
1142
|
+
if (typeof document === "undefined") return false;
|
|
1143
|
+
const textarea = document.createElement("textarea");
|
|
1144
|
+
textarea.value = text;
|
|
1145
|
+
textarea.setAttribute("readonly", "");
|
|
1146
|
+
textarea.style.position = "fixed";
|
|
1147
|
+
textarea.style.top = "0";
|
|
1148
|
+
textarea.style.left = "0";
|
|
1149
|
+
textarea.style.opacity = "0";
|
|
1150
|
+
textarea.style.pointerEvents = "none";
|
|
1151
|
+
document.body.appendChild(textarea);
|
|
1152
|
+
const previouslyFocused = document.activeElement;
|
|
1153
|
+
try {
|
|
1154
|
+
textarea.focus();
|
|
1155
|
+
textarea.select();
|
|
1156
|
+
return document.execCommand("copy");
|
|
1157
|
+
} catch {
|
|
1158
|
+
return false;
|
|
1159
|
+
} finally {
|
|
1160
|
+
document.body.removeChild(textarea);
|
|
1161
|
+
previouslyFocused?.focus?.();
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1225
1164
|
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
1226
1165
|
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
1227
1166
|
if (!text) return false;
|
|
1167
|
+
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
1168
|
+
return writeTextWithExecCommand(text);
|
|
1169
|
+
}
|
|
1228
1170
|
try {
|
|
1229
1171
|
await navigator.clipboard.writeText(text);
|
|
1172
|
+
return true;
|
|
1230
1173
|
} catch {
|
|
1231
1174
|
return false;
|
|
1232
1175
|
}
|
|
1233
|
-
return true;
|
|
1234
1176
|
}
|
|
1235
1177
|
|
|
1236
1178
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
@@ -1289,6 +1231,90 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1289
1231
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1290
1232
|
}
|
|
1291
1233
|
|
|
1234
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1235
|
+
function countLeadingEmptyCells(cells) {
|
|
1236
|
+
let depth = 0;
|
|
1237
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1238
|
+
depth += 1;
|
|
1239
|
+
}
|
|
1240
|
+
return depth;
|
|
1241
|
+
}
|
|
1242
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1243
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1244
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1245
|
+
if (firstDepth !== 0) return false;
|
|
1246
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1247
|
+
}
|
|
1248
|
+
function parseClipboardTSV(text) {
|
|
1249
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1250
|
+
}
|
|
1251
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1252
|
+
if (!text) return { values: [], depths: [] };
|
|
1253
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1254
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1255
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1256
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1257
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1258
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1259
|
+
const values = [];
|
|
1260
|
+
const depths = [];
|
|
1261
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1262
|
+
const cells = rows[index] ?? [];
|
|
1263
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1264
|
+
if (treatAsDepth) {
|
|
1265
|
+
values.push(cells.slice(depth));
|
|
1266
|
+
depths.push(depth);
|
|
1267
|
+
} else {
|
|
1268
|
+
values.push(cells);
|
|
1269
|
+
depths.push(0);
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
return { values, depths };
|
|
1273
|
+
}
|
|
1274
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1275
|
+
if (width <= 0) return [];
|
|
1276
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1277
|
+
const columnIds = [];
|
|
1278
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1279
|
+
const cell = cells[startCol + offset];
|
|
1280
|
+
if (!cell) break;
|
|
1281
|
+
columnIds.push(cell.column.id);
|
|
1282
|
+
}
|
|
1283
|
+
return columnIds;
|
|
1284
|
+
}
|
|
1285
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1286
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1287
|
+
if (values.length === 0) return null;
|
|
1288
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1289
|
+
if (width === 0) return null;
|
|
1290
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1291
|
+
if (columnIds.length === 0) return null;
|
|
1292
|
+
const rowIds = [];
|
|
1293
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1294
|
+
const row = rows[startRow + offset];
|
|
1295
|
+
if (!row) break;
|
|
1296
|
+
rowIds.push(row.id);
|
|
1297
|
+
}
|
|
1298
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1299
|
+
return {
|
|
1300
|
+
mode,
|
|
1301
|
+
startRow,
|
|
1302
|
+
startCol,
|
|
1303
|
+
endRow,
|
|
1304
|
+
rowIds,
|
|
1305
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1306
|
+
columnIds,
|
|
1307
|
+
values,
|
|
1308
|
+
depths
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1311
|
+
function isEditablePasteTarget(target) {
|
|
1312
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1313
|
+
const tag = target.tagName;
|
|
1314
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1315
|
+
return Boolean(target.isContentEditable);
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1292
1318
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1293
1319
|
function isFocusOutsideRoot(rootRef) {
|
|
1294
1320
|
const root = rootRef?.current;
|
|
@@ -1643,6 +1669,41 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1643
1669
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1644
1670
|
}
|
|
1645
1671
|
|
|
1672
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1673
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1674
|
+
var isListening = false;
|
|
1675
|
+
function handleEscape(event) {
|
|
1676
|
+
if (event.key !== "Escape") return;
|
|
1677
|
+
if (event.defaultPrevented) return;
|
|
1678
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1679
|
+
return;
|
|
1680
|
+
}
|
|
1681
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
for (const clearAllSelections of [...clearAllByOwner.values()]) {
|
|
1685
|
+
try {
|
|
1686
|
+
clearAllSelections();
|
|
1687
|
+
} catch (error) {
|
|
1688
|
+
console.error("[react-glide-table] escape-dismiss callback failed", error);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1693
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1694
|
+
if (!isListening) {
|
|
1695
|
+
window.addEventListener("keydown", handleEscape);
|
|
1696
|
+
isListening = true;
|
|
1697
|
+
}
|
|
1698
|
+
return () => {
|
|
1699
|
+
clearAllByOwner.delete(owner);
|
|
1700
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1701
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1702
|
+
isListening = false;
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1646
1707
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1647
1708
|
function getColumnDefId(column) {
|
|
1648
1709
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2747,6 +2808,7 @@ function useGlideTable(options) {
|
|
|
2747
2808
|
const [hoveredRowIndex, setHoveredRowIndex] = useState4(null);
|
|
2748
2809
|
const scrollRef = useRef5(null);
|
|
2749
2810
|
const rootRef = useRef5(null);
|
|
2811
|
+
const escapeDismissOwnerRef = useRef5(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2750
2812
|
const cellRendererRegistry = useMemo3(
|
|
2751
2813
|
() => createCellRendererRegistry(cellRenderers),
|
|
2752
2814
|
[cellRenderers]
|
|
@@ -2950,25 +3012,10 @@ function useGlideTable(options) {
|
|
|
2950
3012
|
setInternalRowSelection({});
|
|
2951
3013
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
2952
3014
|
useEffect5(() => {
|
|
2953
|
-
|
|
3015
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
2954
3016
|
clearCellSelection();
|
|
2955
3017
|
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
|
-
};
|
|
3018
|
+
});
|
|
2972
3019
|
}, [clearCellSelection, clearRowSelection]);
|
|
2973
3020
|
const {
|
|
2974
3021
|
editingCell,
|