react-glide-table 2.3.0 → 2.3.2
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/README.md +27 -0
- package/dist/compound.cjs +219 -105
- package/dist/compound.d.cts +2 -2
- package/dist/compound.d.ts +2 -2
- package/dist/compound.js +219 -105
- package/dist/core.cjs +219 -107
- package/dist/core.d.cts +3 -2
- package/dist/core.d.ts +3 -2
- package/dist/core.js +219 -107
- package/dist/index.cjs +222 -108
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +222 -108
- package/dist/{types-DdeVn-9s.d.cts → types-hf2ruVdu.d.cts} +25 -1
- package/dist/{types-DdeVn-9s.d.ts → types-hf2ruVdu.d.ts} +25 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -538,9 +538,126 @@ 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
|
+
|
|
541
625
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
542
626
|
var import_react3 = require("react");
|
|
543
627
|
|
|
628
|
+
// src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
|
|
629
|
+
var activeOwner = null;
|
|
630
|
+
var clearByOwner = /* @__PURE__ */ new Map();
|
|
631
|
+
function createCellSelectionOwner() {
|
|
632
|
+
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
633
|
+
}
|
|
634
|
+
function registerCellSelectionOwner(owner, clearSelection) {
|
|
635
|
+
clearByOwner.set(owner, clearSelection);
|
|
636
|
+
return () => {
|
|
637
|
+
clearByOwner.delete(owner);
|
|
638
|
+
if (activeOwner === owner) {
|
|
639
|
+
activeOwner = null;
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function claimCellSelectionOwner(owner) {
|
|
644
|
+
if (activeOwner === owner) return;
|
|
645
|
+
activeOwner = owner;
|
|
646
|
+
for (const [id, clearSelection] of clearByOwner) {
|
|
647
|
+
if (id !== owner) {
|
|
648
|
+
clearSelection();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
function isActiveCellSelectionOwner(owner) {
|
|
653
|
+
return activeOwner === owner;
|
|
654
|
+
}
|
|
655
|
+
function releaseCellSelectionOwner(owner) {
|
|
656
|
+
if (activeOwner === owner) {
|
|
657
|
+
activeOwner = null;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
544
661
|
// src/components/ui/table/features/cell-selection/cellSelection.ts
|
|
545
662
|
var INITIAL_DRAG_STATE = {
|
|
546
663
|
isSelecting: false,
|
|
@@ -1018,19 +1135,31 @@ function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
|
1018
1135
|
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
1019
1136
|
const meta = columnDef.meta;
|
|
1020
1137
|
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
1138
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1139
|
+
const ctx = {
|
|
1140
|
+
value,
|
|
1141
|
+
row,
|
|
1142
|
+
index: row.index,
|
|
1143
|
+
columnId,
|
|
1144
|
+
cellProps: meta?.cellProps,
|
|
1145
|
+
update: () => {
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
const copyValue = meta?.copyValue;
|
|
1149
|
+
if (typeof copyValue === "function") {
|
|
1150
|
+
try {
|
|
1151
|
+
return sanitizeClipboardCell(copyValue(ctx));
|
|
1152
|
+
} catch {
|
|
1153
|
+
return formatCellValue(value);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (copyValue === "value") {
|
|
1157
|
+
return formatCellValue(value);
|
|
1158
|
+
}
|
|
1021
1159
|
const cellRender = meta?.cellRender;
|
|
1022
1160
|
if (typeof cellRender === "function") {
|
|
1023
1161
|
try {
|
|
1024
|
-
const
|
|
1025
|
-
const node = cellRender({
|
|
1026
|
-
value,
|
|
1027
|
-
row,
|
|
1028
|
-
index: row.index,
|
|
1029
|
-
columnId,
|
|
1030
|
-
cellProps: meta?.cellProps,
|
|
1031
|
-
update: () => {
|
|
1032
|
-
}
|
|
1033
|
-
});
|
|
1162
|
+
const node = cellRender(ctx);
|
|
1034
1163
|
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
1035
1164
|
} catch {
|
|
1036
1165
|
return formatCellValue(value);
|
|
@@ -1038,16 +1167,6 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
|
|
|
1038
1167
|
}
|
|
1039
1168
|
if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
|
|
1040
1169
|
try {
|
|
1041
|
-
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1042
|
-
const ctx = {
|
|
1043
|
-
value,
|
|
1044
|
-
row,
|
|
1045
|
-
index: row.index,
|
|
1046
|
-
columnId,
|
|
1047
|
-
cellProps: meta.cellProps,
|
|
1048
|
-
update: () => {
|
|
1049
|
-
}
|
|
1050
|
-
};
|
|
1051
1170
|
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
1052
1171
|
if (renderer) {
|
|
1053
1172
|
const node = renderer.render(ctx);
|
|
@@ -1173,11 +1292,16 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
|
|
|
1173
1292
|
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
1174
1293
|
const minDepth = Math.min(...resolvedDepths);
|
|
1175
1294
|
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
1295
|
+
const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
|
|
1296
|
+
const meta = templateCell.column.columnDef.meta;
|
|
1297
|
+
if (meta?.copyValue === "omit") return [];
|
|
1298
|
+
return [{ templateCell, colOffset }];
|
|
1299
|
+
});
|
|
1176
1300
|
return copyRows.map((rowData, index) => {
|
|
1177
1301
|
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
1178
1302
|
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
1179
1303
|
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
1180
|
-
const line =
|
|
1304
|
+
const line = copyableColumns.map(({ templateCell, colOffset }) => {
|
|
1181
1305
|
const sourceCell = matchingCells?.[colOffset];
|
|
1182
1306
|
const column = sourceCell?.column ?? templateCell.column;
|
|
1183
1307
|
return formatCopyCellText(
|
|
@@ -1271,90 +1395,6 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1271
1395
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1272
1396
|
}
|
|
1273
1397
|
|
|
1274
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1275
|
-
function countLeadingEmptyCells(cells) {
|
|
1276
|
-
let depth = 0;
|
|
1277
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
1278
|
-
depth += 1;
|
|
1279
|
-
}
|
|
1280
|
-
return depth;
|
|
1281
|
-
}
|
|
1282
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1283
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
1284
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1285
|
-
if (firstDepth !== 0) return false;
|
|
1286
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1287
|
-
}
|
|
1288
|
-
function parseClipboardTSV(text) {
|
|
1289
|
-
return parseClipboardTSVWithDepths(text).values;
|
|
1290
|
-
}
|
|
1291
|
-
function parseClipboardTSVWithDepths(text) {
|
|
1292
|
-
if (!text) return { values: [], depths: [] };
|
|
1293
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1294
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1295
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1296
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1297
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1298
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1299
|
-
const values = [];
|
|
1300
|
-
const depths = [];
|
|
1301
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
1302
|
-
const cells = rows[index] ?? [];
|
|
1303
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1304
|
-
if (treatAsDepth) {
|
|
1305
|
-
values.push(cells.slice(depth));
|
|
1306
|
-
depths.push(depth);
|
|
1307
|
-
} else {
|
|
1308
|
-
values.push(cells);
|
|
1309
|
-
depths.push(0);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
return { values, depths };
|
|
1313
|
-
}
|
|
1314
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1315
|
-
if (width <= 0) return [];
|
|
1316
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1317
|
-
const columnIds = [];
|
|
1318
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
1319
|
-
const cell = cells[startCol + offset];
|
|
1320
|
-
if (!cell) break;
|
|
1321
|
-
columnIds.push(cell.column.id);
|
|
1322
|
-
}
|
|
1323
|
-
return columnIds;
|
|
1324
|
-
}
|
|
1325
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1326
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1327
|
-
if (values.length === 0) return null;
|
|
1328
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1329
|
-
if (width === 0) return null;
|
|
1330
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1331
|
-
if (columnIds.length === 0) return null;
|
|
1332
|
-
const rowIds = [];
|
|
1333
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1334
|
-
const row = rows[startRow + offset];
|
|
1335
|
-
if (!row) break;
|
|
1336
|
-
rowIds.push(row.id);
|
|
1337
|
-
}
|
|
1338
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1339
|
-
return {
|
|
1340
|
-
mode,
|
|
1341
|
-
startRow,
|
|
1342
|
-
startCol,
|
|
1343
|
-
endRow,
|
|
1344
|
-
rowIds,
|
|
1345
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
1346
|
-
columnIds,
|
|
1347
|
-
values,
|
|
1348
|
-
depths
|
|
1349
|
-
};
|
|
1350
|
-
}
|
|
1351
|
-
function isEditablePasteTarget(target) {
|
|
1352
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
1353
|
-
const tag = target.tagName;
|
|
1354
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1355
|
-
return Boolean(target.isContentEditable);
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
1398
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1359
1399
|
function useCellSelection({
|
|
1360
1400
|
data,
|
|
@@ -1370,6 +1410,7 @@ function useCellSelection({
|
|
|
1370
1410
|
cellRendererRegistry,
|
|
1371
1411
|
rootRef
|
|
1372
1412
|
}) {
|
|
1413
|
+
const ownerRef = (0, import_react3.useRef)(createCellSelectionOwner());
|
|
1373
1414
|
const [dragState, setDragState] = (0, import_react3.useState)(INITIAL_DRAG_STATE);
|
|
1374
1415
|
const pendingPasteModeRef = (0, import_react3.useRef)(null);
|
|
1375
1416
|
const dragStateRef = (0, import_react3.useRef)(dragState);
|
|
@@ -1381,6 +1422,7 @@ function useCellSelection({
|
|
|
1381
1422
|
const handleCellMouseDown = (0, import_react3.useCallback)(
|
|
1382
1423
|
(rowIndex, colIndex, options) => {
|
|
1383
1424
|
if (!enabled) return;
|
|
1425
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
1384
1426
|
setDragState((prev) => {
|
|
1385
1427
|
if (options?.shiftKey && prev.start) {
|
|
1386
1428
|
return {
|
|
@@ -1422,6 +1464,7 @@ function useCellSelection({
|
|
|
1422
1464
|
const handleFillHandleMouseDown = (0, import_react3.useCallback)(
|
|
1423
1465
|
(rowIndex, colIndex) => {
|
|
1424
1466
|
if (!enabled) return;
|
|
1467
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
1425
1468
|
setDragState((prev) => {
|
|
1426
1469
|
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
1427
1470
|
if (!bounds) return prev;
|
|
@@ -1436,14 +1479,27 @@ function useCellSelection({
|
|
|
1436
1479
|
},
|
|
1437
1480
|
[enabled]
|
|
1438
1481
|
);
|
|
1482
|
+
const clearSelection = (0, import_react3.useCallback)(() => {
|
|
1483
|
+
const prev = dragStateRef.current;
|
|
1484
|
+
if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
releaseCellSelectionOwner(ownerRef.current);
|
|
1488
|
+
dragStateRef.current = INITIAL_DRAG_STATE;
|
|
1489
|
+
setDragState(INITIAL_DRAG_STATE);
|
|
1490
|
+
}, []);
|
|
1439
1491
|
(0, import_react3.useEffect)(() => {
|
|
1440
1492
|
if (!enabled) {
|
|
1441
|
-
|
|
1493
|
+
clearSelection();
|
|
1442
1494
|
}
|
|
1443
|
-
}, [enabled]);
|
|
1495
|
+
}, [clearSelection, enabled]);
|
|
1496
|
+
(0, import_react3.useEffect)(() => {
|
|
1497
|
+
return registerCellSelectionOwner(ownerRef.current, clearSelection);
|
|
1498
|
+
}, [clearSelection]);
|
|
1444
1499
|
(0, import_react3.useEffect)(() => {
|
|
1445
1500
|
if (!enabled) return;
|
|
1446
1501
|
const handleKeyDown = (e) => {
|
|
1502
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1447
1503
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
1448
1504
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1449
1505
|
return;
|
|
@@ -1509,6 +1565,7 @@ function useCellSelection({
|
|
|
1509
1565
|
(0, import_react3.useEffect)(() => {
|
|
1510
1566
|
if (!enabled) return;
|
|
1511
1567
|
const handleKeyDown = (e) => {
|
|
1568
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1512
1569
|
if (!activeSelectionBounds) return;
|
|
1513
1570
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
1514
1571
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
@@ -1545,6 +1602,7 @@ function useCellSelection({
|
|
|
1545
1602
|
const pasteHandledRef = { current: false };
|
|
1546
1603
|
const ignoreNextPasteRef = { current: false };
|
|
1547
1604
|
const handleKeyDown = (e) => {
|
|
1605
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1548
1606
|
if (!activeSelectionBounds) return;
|
|
1549
1607
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
1550
1608
|
if (e.key.toLowerCase() !== "v") return;
|
|
@@ -1565,6 +1623,7 @@ function useCellSelection({
|
|
|
1565
1623
|
const text = await navigator.clipboard.readText();
|
|
1566
1624
|
if (pasteHandledRef.current) return;
|
|
1567
1625
|
if (pendingPasteModeRef.current !== mode) return;
|
|
1626
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1568
1627
|
if (!text) return;
|
|
1569
1628
|
pasteHandledRef.current = true;
|
|
1570
1629
|
emitRowsPaste(text, mode);
|
|
@@ -1574,6 +1633,7 @@ function useCellSelection({
|
|
|
1574
1633
|
})();
|
|
1575
1634
|
};
|
|
1576
1635
|
const handlePaste = (e) => {
|
|
1636
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1577
1637
|
if (!activeSelectionBounds) return;
|
|
1578
1638
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1579
1639
|
return;
|
|
@@ -1654,10 +1714,30 @@ function useCellSelection({
|
|
|
1654
1714
|
handleCellMouseDown,
|
|
1655
1715
|
handleCellMouseEnter,
|
|
1656
1716
|
handleFillHandleMouseDown,
|
|
1717
|
+
clearSelection,
|
|
1657
1718
|
copySelection
|
|
1658
1719
|
};
|
|
1659
1720
|
}
|
|
1660
1721
|
|
|
1722
|
+
// src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
|
|
1723
|
+
var OVERLAY_DISMISS_IGNORE_SELECTOR = [
|
|
1724
|
+
'[role="dialog"]',
|
|
1725
|
+
'[role="alertdialog"]',
|
|
1726
|
+
'[role="menu"]',
|
|
1727
|
+
'[role="listbox"]',
|
|
1728
|
+
'[role="tooltip"]',
|
|
1729
|
+
'[aria-modal="true"]',
|
|
1730
|
+
"[data-radix-portal]",
|
|
1731
|
+
"[data-radix-popper-content-wrapper]",
|
|
1732
|
+
"[data-floating-ui-portal]",
|
|
1733
|
+
"[data-table-ignore-outside-dismiss]"
|
|
1734
|
+
].join(",");
|
|
1735
|
+
function isOverlayDismissIgnoreTarget(target) {
|
|
1736
|
+
const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
|
|
1737
|
+
if (!element) return false;
|
|
1738
|
+
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1661
1741
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1662
1742
|
function getColumnDefId(column) {
|
|
1663
1743
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2937,6 +3017,7 @@ function useGlideTable(options) {
|
|
|
2937
3017
|
handleCellMouseDown,
|
|
2938
3018
|
handleCellMouseEnter,
|
|
2939
3019
|
handleFillHandleMouseDown,
|
|
3020
|
+
clearSelection: clearCellSelection,
|
|
2940
3021
|
copySelection
|
|
2941
3022
|
} = useCellSelection({
|
|
2942
3023
|
data: tableData,
|
|
@@ -2952,6 +3033,37 @@ function useGlideTable(options) {
|
|
|
2952
3033
|
cellRendererRegistry,
|
|
2953
3034
|
rootRef
|
|
2954
3035
|
});
|
|
3036
|
+
const clearRowSelection = (0, import_react6.useCallback)(() => {
|
|
3037
|
+
if (rowSelectionMode === "none") return;
|
|
3038
|
+
const hasSelection = Object.values(rowSelection).some(Boolean);
|
|
3039
|
+
if (!hasSelection) return;
|
|
3040
|
+
if (onRowSelectionChange) {
|
|
3041
|
+
onRowSelectionChange(() => ({}));
|
|
3042
|
+
return;
|
|
3043
|
+
}
|
|
3044
|
+
setInternalRowSelection({});
|
|
3045
|
+
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
3046
|
+
(0, import_react6.useEffect)(() => {
|
|
3047
|
+
const clearAllSelections = () => {
|
|
3048
|
+
clearCellSelection();
|
|
3049
|
+
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
|
+
};
|
|
3066
|
+
}, [clearCellSelection, clearRowSelection]);
|
|
2955
3067
|
const {
|
|
2956
3068
|
editingCell,
|
|
2957
3069
|
draftValue,
|
|
@@ -5041,7 +5153,8 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5041
5153
|
cellProps,
|
|
5042
5154
|
className,
|
|
5043
5155
|
headerClassName,
|
|
5044
|
-
render
|
|
5156
|
+
render,
|
|
5157
|
+
copyValue
|
|
5045
5158
|
} = props;
|
|
5046
5159
|
return {
|
|
5047
5160
|
id: field,
|
|
@@ -5075,6 +5188,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5075
5188
|
kind,
|
|
5076
5189
|
cellProps,
|
|
5077
5190
|
cellRender: render,
|
|
5191
|
+
copyValue,
|
|
5078
5192
|
frozen,
|
|
5079
5193
|
reorderable,
|
|
5080
5194
|
width,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as
|
|
1
|
+
export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as ColumnCopyValue, e as ColumnFreezeColumnInput, f as ColumnFreezeEdgeSide, g as ColumnFreezeMeta, h as ColumnFreezeOffset, i as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, j as DataTableClassNames, k as DataTableCopyActions, l as DataTableLabels, m as DataTableProps, n as DataTableScrollSlotProps, o as DataTableSlots, I as INLINE_SEARCH_MAX_RESULTS, P as PasteMode, R as RowSelectionMode, p as RowsPastePayload, S as SearchCorpusRow, q as SearchResultItem, r as SearchStatus, T as TableColumnGroupProps, s as TableColumnProps, t as TableProps, u as buildColumnFreezeOffsets, v as buildFlatSearchCorpus, w as buildSearchMatchKey, x as buildSearchMatchKeys, y as buildTreeSearchCorpus, z as cellValueToSearchText, A as collectAncestorKeysToExpand, E as collectSearchMatchesInRange, F as createSearchRegex, G as escapeSearchRegex, H as formatSearchResultLabel, J as getColumnFreezeEdgeAttr, K as getColumnFreezeStyle, L as mapSearchResultToVisibleItem, M as mapSearchResultsToVisibleKeys, N as nextSearchIndex, O as nextSearchStride, Q as previousSearchIndex, U as resolveColumnFreezeSide, V as resolveDataTableLabels, W as resolveHeaderFreezeOffset } from './types-hf2ruVdu.cjs';
|
|
2
2
|
export { BUILTIN_CELL_RENDERERS, CELL_SELECTION_EDGES_CLASS, CellContextWithUpdate, CellRendererRegistry, CellSelectionBounds, ColumnDropEdge, ColumnLayoutInput, ColumnRowSpanMap, CopyRowEntry, CopySelectionMode, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DragState, EditingCell, ResolvedTableCell, RowSpanColumnSpec, RowSpanInfo, TreeRow, UseConvertTreeDataParams, UseGlideTableOptions, UseGlideTableResult, UseInlineSearchOptions, UseInlineSearchResult, applyCellEdit, applyFillData, applyLeafColumnOrder, applySelectionUpdater, buildColumnRowSpanMap, buildRowsPastePayload, canExpandRow, collectCopyRowEntries, collectCopyRows, collectFillChanges, collectLeafColumnIds, collectRowSpanColumns, commitCellValue, createCellRendererRegistry, flattenSubtreeRows, formatCellValue, formatDefaultCellValue, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getColumnSizeStyle, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, isEditablePasteTarget, measureMergedSpanRowHeights, moveColumnIds, parseCellEditValue, parseClipboardTSV, parseClipboardTSVWithDepths, resolveCellRenderer, resolveColumnLayoutWidths, resolveDropEdge, resolveLeafColumnOrder, resolvePasteColumnIds, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, serializeCopyRowsToTSV, serializeSelectionToTSV, toggleExpandedRowId, useCellEdit, useCellSelection, useColumnReorder, useConvertTreeData, useGlideTable, useInlineSearch, withCellUpdate, writeSelectionToClipboard } from './core.cjs';
|
|
3
3
|
export { DataTable, Table, TableCompoundComponent, createTable } from './compound.cjs';
|
|
4
4
|
export { ColumnDef, ColumnOrderState, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as
|
|
1
|
+
export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as ColumnCopyValue, e as ColumnFreezeColumnInput, f as ColumnFreezeEdgeSide, g as ColumnFreezeMeta, h as ColumnFreezeOffset, i as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, j as DataTableClassNames, k as DataTableCopyActions, l as DataTableLabels, m as DataTableProps, n as DataTableScrollSlotProps, o as DataTableSlots, I as INLINE_SEARCH_MAX_RESULTS, P as PasteMode, R as RowSelectionMode, p as RowsPastePayload, S as SearchCorpusRow, q as SearchResultItem, r as SearchStatus, T as TableColumnGroupProps, s as TableColumnProps, t as TableProps, u as buildColumnFreezeOffsets, v as buildFlatSearchCorpus, w as buildSearchMatchKey, x as buildSearchMatchKeys, y as buildTreeSearchCorpus, z as cellValueToSearchText, A as collectAncestorKeysToExpand, E as collectSearchMatchesInRange, F as createSearchRegex, G as escapeSearchRegex, H as formatSearchResultLabel, J as getColumnFreezeEdgeAttr, K as getColumnFreezeStyle, L as mapSearchResultToVisibleItem, M as mapSearchResultsToVisibleKeys, N as nextSearchIndex, O as nextSearchStride, Q as previousSearchIndex, U as resolveColumnFreezeSide, V as resolveDataTableLabels, W as resolveHeaderFreezeOffset } from './types-hf2ruVdu.js';
|
|
2
2
|
export { BUILTIN_CELL_RENDERERS, CELL_SELECTION_EDGES_CLASS, CellContextWithUpdate, CellRendererRegistry, CellSelectionBounds, ColumnDropEdge, ColumnLayoutInput, ColumnRowSpanMap, CopyRowEntry, CopySelectionMode, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DragState, EditingCell, ResolvedTableCell, RowSpanColumnSpec, RowSpanInfo, TreeRow, UseConvertTreeDataParams, UseGlideTableOptions, UseGlideTableResult, UseInlineSearchOptions, UseInlineSearchResult, applyCellEdit, applyFillData, applyLeafColumnOrder, applySelectionUpdater, buildColumnRowSpanMap, buildRowsPastePayload, canExpandRow, collectCopyRowEntries, collectCopyRows, collectFillChanges, collectLeafColumnIds, collectRowSpanColumns, commitCellValue, createCellRendererRegistry, flattenSubtreeRows, formatCellValue, formatDefaultCellValue, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getColumnSizeStyle, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, isEditablePasteTarget, measureMergedSpanRowHeights, moveColumnIds, parseCellEditValue, parseClipboardTSV, parseClipboardTSVWithDepths, resolveCellRenderer, resolveColumnLayoutWidths, resolveDropEdge, resolveLeafColumnOrder, resolvePasteColumnIds, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, serializeCopyRowsToTSV, serializeSelectionToTSV, toggleExpandedRowId, useCellEdit, useCellSelection, useColumnReorder, useConvertTreeData, useGlideTable, useInlineSearch, withCellUpdate, writeSelectionToClipboard } from './core.js';
|
|
3
3
|
export { DataTable, Table, TableCompoundComponent, createTable } from './compound.js';
|
|
4
4
|
export { ColumnDef, ColumnOrderState, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
|