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/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
|
|
|
@@ -1328,15 +1244,41 @@ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options)
|
|
|
1328
1244
|
options
|
|
1329
1245
|
);
|
|
1330
1246
|
}
|
|
1247
|
+
function writeTextWithExecCommand(text) {
|
|
1248
|
+
if (typeof document === "undefined") return false;
|
|
1249
|
+
const textarea = document.createElement("textarea");
|
|
1250
|
+
textarea.value = text;
|
|
1251
|
+
textarea.setAttribute("readonly", "");
|
|
1252
|
+
textarea.style.position = "fixed";
|
|
1253
|
+
textarea.style.top = "0";
|
|
1254
|
+
textarea.style.left = "0";
|
|
1255
|
+
textarea.style.opacity = "0";
|
|
1256
|
+
textarea.style.pointerEvents = "none";
|
|
1257
|
+
document.body.appendChild(textarea);
|
|
1258
|
+
const previouslyFocused = document.activeElement;
|
|
1259
|
+
try {
|
|
1260
|
+
textarea.focus();
|
|
1261
|
+
textarea.select();
|
|
1262
|
+
return document.execCommand("copy");
|
|
1263
|
+
} catch {
|
|
1264
|
+
return false;
|
|
1265
|
+
} finally {
|
|
1266
|
+
document.body.removeChild(textarea);
|
|
1267
|
+
previouslyFocused?.focus?.();
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1331
1270
|
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
1332
1271
|
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
1333
1272
|
if (!text) return false;
|
|
1273
|
+
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
1274
|
+
return writeTextWithExecCommand(text);
|
|
1275
|
+
}
|
|
1334
1276
|
try {
|
|
1335
1277
|
await navigator.clipboard.writeText(text);
|
|
1278
|
+
return true;
|
|
1336
1279
|
} catch {
|
|
1337
1280
|
return false;
|
|
1338
1281
|
}
|
|
1339
|
-
return true;
|
|
1340
1282
|
}
|
|
1341
1283
|
|
|
1342
1284
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
@@ -1395,6 +1337,90 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1395
1337
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1396
1338
|
}
|
|
1397
1339
|
|
|
1340
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1341
|
+
function countLeadingEmptyCells(cells) {
|
|
1342
|
+
let depth = 0;
|
|
1343
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1344
|
+
depth += 1;
|
|
1345
|
+
}
|
|
1346
|
+
return depth;
|
|
1347
|
+
}
|
|
1348
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1349
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1350
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1351
|
+
if (firstDepth !== 0) return false;
|
|
1352
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1353
|
+
}
|
|
1354
|
+
function parseClipboardTSV(text) {
|
|
1355
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1356
|
+
}
|
|
1357
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1358
|
+
if (!text) return { values: [], depths: [] };
|
|
1359
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1360
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1361
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1362
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1363
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1364
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1365
|
+
const values = [];
|
|
1366
|
+
const depths = [];
|
|
1367
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1368
|
+
const cells = rows[index] ?? [];
|
|
1369
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1370
|
+
if (treatAsDepth) {
|
|
1371
|
+
values.push(cells.slice(depth));
|
|
1372
|
+
depths.push(depth);
|
|
1373
|
+
} else {
|
|
1374
|
+
values.push(cells);
|
|
1375
|
+
depths.push(0);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return { values, depths };
|
|
1379
|
+
}
|
|
1380
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1381
|
+
if (width <= 0) return [];
|
|
1382
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1383
|
+
const columnIds = [];
|
|
1384
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1385
|
+
const cell = cells[startCol + offset];
|
|
1386
|
+
if (!cell) break;
|
|
1387
|
+
columnIds.push(cell.column.id);
|
|
1388
|
+
}
|
|
1389
|
+
return columnIds;
|
|
1390
|
+
}
|
|
1391
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1392
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1393
|
+
if (values.length === 0) return null;
|
|
1394
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1395
|
+
if (width === 0) return null;
|
|
1396
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1397
|
+
if (columnIds.length === 0) return null;
|
|
1398
|
+
const rowIds = [];
|
|
1399
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1400
|
+
const row = rows[startRow + offset];
|
|
1401
|
+
if (!row) break;
|
|
1402
|
+
rowIds.push(row.id);
|
|
1403
|
+
}
|
|
1404
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1405
|
+
return {
|
|
1406
|
+
mode,
|
|
1407
|
+
startRow,
|
|
1408
|
+
startCol,
|
|
1409
|
+
endRow,
|
|
1410
|
+
rowIds,
|
|
1411
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1412
|
+
columnIds,
|
|
1413
|
+
values,
|
|
1414
|
+
depths
|
|
1415
|
+
};
|
|
1416
|
+
}
|
|
1417
|
+
function isEditablePasteTarget(target) {
|
|
1418
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1419
|
+
const tag = target.tagName;
|
|
1420
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1421
|
+
return Boolean(target.isContentEditable);
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1398
1424
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1399
1425
|
function isFocusOutsideRoot(rootRef) {
|
|
1400
1426
|
const root = rootRef?.current;
|
|
@@ -1749,6 +1775,41 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1749
1775
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1750
1776
|
}
|
|
1751
1777
|
|
|
1778
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1779
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1780
|
+
var isListening = false;
|
|
1781
|
+
function handleEscape(event) {
|
|
1782
|
+
if (event.key !== "Escape") return;
|
|
1783
|
+
if (event.defaultPrevented) return;
|
|
1784
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1788
|
+
return;
|
|
1789
|
+
}
|
|
1790
|
+
for (const clearAllSelections of [...clearAllByOwner.values()]) {
|
|
1791
|
+
try {
|
|
1792
|
+
clearAllSelections();
|
|
1793
|
+
} catch (error) {
|
|
1794
|
+
console.error("[react-glide-table] escape-dismiss callback failed", error);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1799
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1800
|
+
if (!isListening) {
|
|
1801
|
+
window.addEventListener("keydown", handleEscape);
|
|
1802
|
+
isListening = true;
|
|
1803
|
+
}
|
|
1804
|
+
return () => {
|
|
1805
|
+
clearAllByOwner.delete(owner);
|
|
1806
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1807
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1808
|
+
isListening = false;
|
|
1809
|
+
}
|
|
1810
|
+
};
|
|
1811
|
+
}
|
|
1812
|
+
|
|
1752
1813
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1753
1814
|
function getColumnDefId(column) {
|
|
1754
1815
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2852,6 +2913,7 @@ function useGlideTable(options) {
|
|
|
2852
2913
|
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
|
|
2853
2914
|
const scrollRef = (0, import_react6.useRef)(null);
|
|
2854
2915
|
const rootRef = (0, import_react6.useRef)(null);
|
|
2916
|
+
const escapeDismissOwnerRef = (0, import_react6.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2855
2917
|
const cellRendererRegistry = (0, import_react6.useMemo)(
|
|
2856
2918
|
() => createCellRendererRegistry(cellRenderers),
|
|
2857
2919
|
[cellRenderers]
|
|
@@ -3055,25 +3117,10 @@ function useGlideTable(options) {
|
|
|
3055
3117
|
setInternalRowSelection({});
|
|
3056
3118
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
3057
3119
|
(0, import_react6.useEffect)(() => {
|
|
3058
|
-
|
|
3120
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
3059
3121
|
clearCellSelection();
|
|
3060
3122
|
clearRowSelection();
|
|
3061
|
-
};
|
|
3062
|
-
const handleKeyDown = (event) => {
|
|
3063
|
-
if (event.key !== "Escape") return;
|
|
3064
|
-
if (event.defaultPrevented) return;
|
|
3065
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3066
|
-
return;
|
|
3067
|
-
}
|
|
3068
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3069
|
-
return;
|
|
3070
|
-
}
|
|
3071
|
-
clearAllSelections();
|
|
3072
|
-
};
|
|
3073
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
3074
|
-
return () => {
|
|
3075
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
3076
|
-
};
|
|
3123
|
+
});
|
|
3077
3124
|
}, [clearCellSelection, clearRowSelection]);
|
|
3078
3125
|
const {
|
|
3079
3126
|
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
|
|
|
@@ -1231,15 +1147,41 @@ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options)
|
|
|
1231
1147
|
options
|
|
1232
1148
|
);
|
|
1233
1149
|
}
|
|
1150
|
+
function writeTextWithExecCommand(text) {
|
|
1151
|
+
if (typeof document === "undefined") return false;
|
|
1152
|
+
const textarea = document.createElement("textarea");
|
|
1153
|
+
textarea.value = text;
|
|
1154
|
+
textarea.setAttribute("readonly", "");
|
|
1155
|
+
textarea.style.position = "fixed";
|
|
1156
|
+
textarea.style.top = "0";
|
|
1157
|
+
textarea.style.left = "0";
|
|
1158
|
+
textarea.style.opacity = "0";
|
|
1159
|
+
textarea.style.pointerEvents = "none";
|
|
1160
|
+
document.body.appendChild(textarea);
|
|
1161
|
+
const previouslyFocused = document.activeElement;
|
|
1162
|
+
try {
|
|
1163
|
+
textarea.focus();
|
|
1164
|
+
textarea.select();
|
|
1165
|
+
return document.execCommand("copy");
|
|
1166
|
+
} catch {
|
|
1167
|
+
return false;
|
|
1168
|
+
} finally {
|
|
1169
|
+
document.body.removeChild(textarea);
|
|
1170
|
+
previouslyFocused?.focus?.();
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1234
1173
|
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
1235
1174
|
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
1236
1175
|
if (!text) return false;
|
|
1176
|
+
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
1177
|
+
return writeTextWithExecCommand(text);
|
|
1178
|
+
}
|
|
1237
1179
|
try {
|
|
1238
1180
|
await navigator.clipboard.writeText(text);
|
|
1181
|
+
return true;
|
|
1239
1182
|
} catch {
|
|
1240
1183
|
return false;
|
|
1241
1184
|
}
|
|
1242
|
-
return true;
|
|
1243
1185
|
}
|
|
1244
1186
|
|
|
1245
1187
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
@@ -1298,6 +1240,90 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1298
1240
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1299
1241
|
}
|
|
1300
1242
|
|
|
1243
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1244
|
+
function countLeadingEmptyCells(cells) {
|
|
1245
|
+
let depth = 0;
|
|
1246
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1247
|
+
depth += 1;
|
|
1248
|
+
}
|
|
1249
|
+
return depth;
|
|
1250
|
+
}
|
|
1251
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1252
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1253
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1254
|
+
if (firstDepth !== 0) return false;
|
|
1255
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1256
|
+
}
|
|
1257
|
+
function parseClipboardTSV(text) {
|
|
1258
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1259
|
+
}
|
|
1260
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1261
|
+
if (!text) return { values: [], depths: [] };
|
|
1262
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1263
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1264
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1265
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1266
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1267
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1268
|
+
const values = [];
|
|
1269
|
+
const depths = [];
|
|
1270
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1271
|
+
const cells = rows[index] ?? [];
|
|
1272
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1273
|
+
if (treatAsDepth) {
|
|
1274
|
+
values.push(cells.slice(depth));
|
|
1275
|
+
depths.push(depth);
|
|
1276
|
+
} else {
|
|
1277
|
+
values.push(cells);
|
|
1278
|
+
depths.push(0);
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
return { values, depths };
|
|
1282
|
+
}
|
|
1283
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1284
|
+
if (width <= 0) return [];
|
|
1285
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1286
|
+
const columnIds = [];
|
|
1287
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1288
|
+
const cell = cells[startCol + offset];
|
|
1289
|
+
if (!cell) break;
|
|
1290
|
+
columnIds.push(cell.column.id);
|
|
1291
|
+
}
|
|
1292
|
+
return columnIds;
|
|
1293
|
+
}
|
|
1294
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1295
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1296
|
+
if (values.length === 0) return null;
|
|
1297
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1298
|
+
if (width === 0) return null;
|
|
1299
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1300
|
+
if (columnIds.length === 0) return null;
|
|
1301
|
+
const rowIds = [];
|
|
1302
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1303
|
+
const row = rows[startRow + offset];
|
|
1304
|
+
if (!row) break;
|
|
1305
|
+
rowIds.push(row.id);
|
|
1306
|
+
}
|
|
1307
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1308
|
+
return {
|
|
1309
|
+
mode,
|
|
1310
|
+
startRow,
|
|
1311
|
+
startCol,
|
|
1312
|
+
endRow,
|
|
1313
|
+
rowIds,
|
|
1314
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1315
|
+
columnIds,
|
|
1316
|
+
values,
|
|
1317
|
+
depths
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
function isEditablePasteTarget(target) {
|
|
1321
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1322
|
+
const tag = target.tagName;
|
|
1323
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1324
|
+
return Boolean(target.isContentEditable);
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1301
1327
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1302
1328
|
function isFocusOutsideRoot(rootRef) {
|
|
1303
1329
|
const root = rootRef?.current;
|
|
@@ -1652,6 +1678,41 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1652
1678
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1653
1679
|
}
|
|
1654
1680
|
|
|
1681
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1682
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1683
|
+
var isListening = false;
|
|
1684
|
+
function handleEscape(event) {
|
|
1685
|
+
if (event.key !== "Escape") return;
|
|
1686
|
+
if (event.defaultPrevented) return;
|
|
1687
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1688
|
+
return;
|
|
1689
|
+
}
|
|
1690
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
for (const clearAllSelections of [...clearAllByOwner.values()]) {
|
|
1694
|
+
try {
|
|
1695
|
+
clearAllSelections();
|
|
1696
|
+
} catch (error) {
|
|
1697
|
+
console.error("[react-glide-table] escape-dismiss callback failed", error);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1702
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1703
|
+
if (!isListening) {
|
|
1704
|
+
window.addEventListener("keydown", handleEscape);
|
|
1705
|
+
isListening = true;
|
|
1706
|
+
}
|
|
1707
|
+
return () => {
|
|
1708
|
+
clearAllByOwner.delete(owner);
|
|
1709
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1710
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1711
|
+
isListening = false;
|
|
1712
|
+
}
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1655
1716
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1656
1717
|
function getColumnDefId(column) {
|
|
1657
1718
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2762,6 +2823,7 @@ function useGlideTable(options) {
|
|
|
2762
2823
|
const [hoveredRowIndex, setHoveredRowIndex] = useState4(null);
|
|
2763
2824
|
const scrollRef = useRef5(null);
|
|
2764
2825
|
const rootRef = useRef5(null);
|
|
2826
|
+
const escapeDismissOwnerRef = useRef5(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2765
2827
|
const cellRendererRegistry = useMemo3(
|
|
2766
2828
|
() => createCellRendererRegistry(cellRenderers),
|
|
2767
2829
|
[cellRenderers]
|
|
@@ -2965,25 +3027,10 @@ function useGlideTable(options) {
|
|
|
2965
3027
|
setInternalRowSelection({});
|
|
2966
3028
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
2967
3029
|
useEffect5(() => {
|
|
2968
|
-
|
|
3030
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
2969
3031
|
clearCellSelection();
|
|
2970
3032
|
clearRowSelection();
|
|
2971
|
-
};
|
|
2972
|
-
const handleKeyDown = (event) => {
|
|
2973
|
-
if (event.key !== "Escape") return;
|
|
2974
|
-
if (event.defaultPrevented) return;
|
|
2975
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
2976
|
-
return;
|
|
2977
|
-
}
|
|
2978
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
2979
|
-
return;
|
|
2980
|
-
}
|
|
2981
|
-
clearAllSelections();
|
|
2982
|
-
};
|
|
2983
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
2984
|
-
return () => {
|
|
2985
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
2986
|
-
};
|
|
3033
|
+
});
|
|
2987
3034
|
}, [clearCellSelection, clearRowSelection]);
|
|
2988
3035
|
const {
|
|
2989
3036
|
editingCell,
|