react-glide-table 2.3.2 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compound.cjs +126 -98
- package/dist/compound.js +126 -98
- package/dist/core.cjs +129 -101
- package/dist/core.js +129 -101
- package/dist/index.cjs +129 -101
- package/dist/index.js +129 -101
- package/package.json +1 -1
package/dist/compound.cjs
CHANGED
|
@@ -2658,87 +2658,6 @@ function formatDefaultCellValue(value) {
|
|
|
2658
2658
|
return String(value);
|
|
2659
2659
|
}
|
|
2660
2660
|
|
|
2661
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
2662
|
-
function countLeadingEmptyCells(cells) {
|
|
2663
|
-
let depth = 0;
|
|
2664
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
2665
|
-
depth += 1;
|
|
2666
|
-
}
|
|
2667
|
-
return depth;
|
|
2668
|
-
}
|
|
2669
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
2670
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
2671
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
2672
|
-
if (firstDepth !== 0) return false;
|
|
2673
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
2674
|
-
}
|
|
2675
|
-
function parseClipboardTSVWithDepths(text) {
|
|
2676
|
-
if (!text) return { values: [], depths: [] };
|
|
2677
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
2678
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
2679
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
2680
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
2681
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
2682
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
2683
|
-
const values = [];
|
|
2684
|
-
const depths = [];
|
|
2685
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
2686
|
-
const cells = rows[index] ?? [];
|
|
2687
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
2688
|
-
if (treatAsDepth) {
|
|
2689
|
-
values.push(cells.slice(depth));
|
|
2690
|
-
depths.push(depth);
|
|
2691
|
-
} else {
|
|
2692
|
-
values.push(cells);
|
|
2693
|
-
depths.push(0);
|
|
2694
|
-
}
|
|
2695
|
-
}
|
|
2696
|
-
return { values, depths };
|
|
2697
|
-
}
|
|
2698
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
2699
|
-
if (width <= 0) return [];
|
|
2700
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
2701
|
-
const columnIds = [];
|
|
2702
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
2703
|
-
const cell = cells[startCol + offset];
|
|
2704
|
-
if (!cell) break;
|
|
2705
|
-
columnIds.push(cell.column.id);
|
|
2706
|
-
}
|
|
2707
|
-
return columnIds;
|
|
2708
|
-
}
|
|
2709
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
2710
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
2711
|
-
if (values.length === 0) return null;
|
|
2712
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
2713
|
-
if (width === 0) return null;
|
|
2714
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
2715
|
-
if (columnIds.length === 0) return null;
|
|
2716
|
-
const rowIds = [];
|
|
2717
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
2718
|
-
const row = rows[startRow + offset];
|
|
2719
|
-
if (!row) break;
|
|
2720
|
-
rowIds.push(row.id);
|
|
2721
|
-
}
|
|
2722
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
2723
|
-
return {
|
|
2724
|
-
mode,
|
|
2725
|
-
startRow,
|
|
2726
|
-
startCol,
|
|
2727
|
-
endRow,
|
|
2728
|
-
rowIds,
|
|
2729
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
2730
|
-
columnIds,
|
|
2731
|
-
values,
|
|
2732
|
-
depths
|
|
2733
|
-
};
|
|
2734
|
-
}
|
|
2735
|
-
function isEditablePasteTarget(target) {
|
|
2736
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
2737
|
-
const tag = target.tagName;
|
|
2738
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
2739
|
-
return Boolean(target.isContentEditable);
|
|
2740
|
-
}
|
|
2741
|
-
|
|
2742
2661
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
2743
2662
|
var import_react7 = require("react");
|
|
2744
2663
|
|
|
@@ -3188,7 +3107,95 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
3188
3107
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
3189
3108
|
}
|
|
3190
3109
|
|
|
3110
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
3111
|
+
function countLeadingEmptyCells(cells) {
|
|
3112
|
+
let depth = 0;
|
|
3113
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
3114
|
+
depth += 1;
|
|
3115
|
+
}
|
|
3116
|
+
return depth;
|
|
3117
|
+
}
|
|
3118
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
3119
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
3120
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
3121
|
+
if (firstDepth !== 0) return false;
|
|
3122
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
3123
|
+
}
|
|
3124
|
+
function parseClipboardTSVWithDepths(text) {
|
|
3125
|
+
if (!text) return { values: [], depths: [] };
|
|
3126
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
3127
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
3128
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
3129
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
3130
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
3131
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
3132
|
+
const values = [];
|
|
3133
|
+
const depths = [];
|
|
3134
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
3135
|
+
const cells = rows[index] ?? [];
|
|
3136
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
3137
|
+
if (treatAsDepth) {
|
|
3138
|
+
values.push(cells.slice(depth));
|
|
3139
|
+
depths.push(depth);
|
|
3140
|
+
} else {
|
|
3141
|
+
values.push(cells);
|
|
3142
|
+
depths.push(0);
|
|
3143
|
+
}
|
|
3144
|
+
}
|
|
3145
|
+
return { values, depths };
|
|
3146
|
+
}
|
|
3147
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
3148
|
+
if (width <= 0) return [];
|
|
3149
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
3150
|
+
const columnIds = [];
|
|
3151
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
3152
|
+
const cell = cells[startCol + offset];
|
|
3153
|
+
if (!cell) break;
|
|
3154
|
+
columnIds.push(cell.column.id);
|
|
3155
|
+
}
|
|
3156
|
+
return columnIds;
|
|
3157
|
+
}
|
|
3158
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
3159
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
3160
|
+
if (values.length === 0) return null;
|
|
3161
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
3162
|
+
if (width === 0) return null;
|
|
3163
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
3164
|
+
if (columnIds.length === 0) return null;
|
|
3165
|
+
const rowIds = [];
|
|
3166
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
3167
|
+
const row = rows[startRow + offset];
|
|
3168
|
+
if (!row) break;
|
|
3169
|
+
rowIds.push(row.id);
|
|
3170
|
+
}
|
|
3171
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
3172
|
+
return {
|
|
3173
|
+
mode,
|
|
3174
|
+
startRow,
|
|
3175
|
+
startCol,
|
|
3176
|
+
endRow,
|
|
3177
|
+
rowIds,
|
|
3178
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
3179
|
+
columnIds,
|
|
3180
|
+
values,
|
|
3181
|
+
depths
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3184
|
+
function isEditablePasteTarget(target) {
|
|
3185
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
3186
|
+
const tag = target.tagName;
|
|
3187
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
3188
|
+
return Boolean(target.isContentEditable);
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3191
3191
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
3192
|
+
function isFocusOutsideRoot(rootRef) {
|
|
3193
|
+
const root = rootRef?.current;
|
|
3194
|
+
if (!root) return false;
|
|
3195
|
+
const active = document.activeElement;
|
|
3196
|
+
if (!active || active === document.body) return false;
|
|
3197
|
+
return !root.contains(active);
|
|
3198
|
+
}
|
|
3192
3199
|
function useCellSelection({
|
|
3193
3200
|
data,
|
|
3194
3201
|
rows,
|
|
@@ -3297,6 +3304,7 @@ function useCellSelection({
|
|
|
3297
3304
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3298
3305
|
return;
|
|
3299
3306
|
}
|
|
3307
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3300
3308
|
const delta = getCellNavigationDelta(e.key);
|
|
3301
3309
|
if (!delta) return;
|
|
3302
3310
|
const prev = dragStateRef.current;
|
|
@@ -3364,6 +3372,7 @@ function useCellSelection({
|
|
|
3364
3372
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3365
3373
|
return;
|
|
3366
3374
|
}
|
|
3375
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3367
3376
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
3368
3377
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
3369
3378
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -3402,6 +3411,7 @@ function useCellSelection({
|
|
|
3402
3411
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3403
3412
|
return;
|
|
3404
3413
|
}
|
|
3414
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3405
3415
|
if (e.shiftKey && !enableInsertPaste) {
|
|
3406
3416
|
ignoreNextPasteRef.current = true;
|
|
3407
3417
|
pendingPasteModeRef.current = null;
|
|
@@ -3431,6 +3441,7 @@ function useCellSelection({
|
|
|
3431
3441
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3432
3442
|
return;
|
|
3433
3443
|
}
|
|
3444
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3434
3445
|
if (ignoreNextPasteRef.current) {
|
|
3435
3446
|
ignoreNextPasteRef.current = false;
|
|
3436
3447
|
pendingPasteModeRef.current = null;
|
|
@@ -3531,6 +3542,37 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
3531
3542
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
3532
3543
|
}
|
|
3533
3544
|
|
|
3545
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
3546
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
3547
|
+
var isListening = false;
|
|
3548
|
+
function handleEscape(event) {
|
|
3549
|
+
if (event.key !== "Escape") return;
|
|
3550
|
+
if (event.defaultPrevented) return;
|
|
3551
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3552
|
+
return;
|
|
3553
|
+
}
|
|
3554
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3555
|
+
return;
|
|
3556
|
+
}
|
|
3557
|
+
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
3558
|
+
clearAllSelections();
|
|
3559
|
+
}
|
|
3560
|
+
}
|
|
3561
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
3562
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
3563
|
+
if (!isListening) {
|
|
3564
|
+
window.addEventListener("keydown", handleEscape);
|
|
3565
|
+
isListening = true;
|
|
3566
|
+
}
|
|
3567
|
+
return () => {
|
|
3568
|
+
clearAllByOwner.delete(owner);
|
|
3569
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
3570
|
+
window.removeEventListener("keydown", handleEscape);
|
|
3571
|
+
isListening = false;
|
|
3572
|
+
}
|
|
3573
|
+
};
|
|
3574
|
+
}
|
|
3575
|
+
|
|
3534
3576
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
3535
3577
|
var import_react8 = require("react");
|
|
3536
3578
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
@@ -3942,6 +3984,7 @@ function useGlideTable(options) {
|
|
|
3942
3984
|
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react9.useState)(null);
|
|
3943
3985
|
const scrollRef = (0, import_react9.useRef)(null);
|
|
3944
3986
|
const rootRef = (0, import_react9.useRef)(null);
|
|
3987
|
+
const escapeDismissOwnerRef = (0, import_react9.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
3945
3988
|
const cellRendererRegistry = (0, import_react9.useMemo)(
|
|
3946
3989
|
() => createCellRendererRegistry(cellRenderers),
|
|
3947
3990
|
[cellRenderers]
|
|
@@ -4145,25 +4188,10 @@ function useGlideTable(options) {
|
|
|
4145
4188
|
setInternalRowSelection({});
|
|
4146
4189
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
4147
4190
|
(0, import_react9.useEffect)(() => {
|
|
4148
|
-
|
|
4191
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
4149
4192
|
clearCellSelection();
|
|
4150
4193
|
clearRowSelection();
|
|
4151
|
-
};
|
|
4152
|
-
const handleKeyDown = (event) => {
|
|
4153
|
-
if (event.key !== "Escape") return;
|
|
4154
|
-
if (event.defaultPrevented) return;
|
|
4155
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
4156
|
-
return;
|
|
4157
|
-
}
|
|
4158
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
4159
|
-
return;
|
|
4160
|
-
}
|
|
4161
|
-
clearAllSelections();
|
|
4162
|
-
};
|
|
4163
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
4164
|
-
return () => {
|
|
4165
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
4166
|
-
};
|
|
4194
|
+
});
|
|
4167
4195
|
}, [clearCellSelection, clearRowSelection]);
|
|
4168
4196
|
const {
|
|
4169
4197
|
editingCell,
|
package/dist/compound.js
CHANGED
|
@@ -2646,87 +2646,6 @@ function formatDefaultCellValue(value) {
|
|
|
2646
2646
|
return String(value);
|
|
2647
2647
|
}
|
|
2648
2648
|
|
|
2649
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
2650
|
-
function countLeadingEmptyCells(cells) {
|
|
2651
|
-
let depth = 0;
|
|
2652
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
2653
|
-
depth += 1;
|
|
2654
|
-
}
|
|
2655
|
-
return depth;
|
|
2656
|
-
}
|
|
2657
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
2658
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
2659
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
2660
|
-
if (firstDepth !== 0) return false;
|
|
2661
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
2662
|
-
}
|
|
2663
|
-
function parseClipboardTSVWithDepths(text) {
|
|
2664
|
-
if (!text) return { values: [], depths: [] };
|
|
2665
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
2666
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
2667
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
2668
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
2669
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
2670
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
2671
|
-
const values = [];
|
|
2672
|
-
const depths = [];
|
|
2673
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
2674
|
-
const cells = rows[index] ?? [];
|
|
2675
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
2676
|
-
if (treatAsDepth) {
|
|
2677
|
-
values.push(cells.slice(depth));
|
|
2678
|
-
depths.push(depth);
|
|
2679
|
-
} else {
|
|
2680
|
-
values.push(cells);
|
|
2681
|
-
depths.push(0);
|
|
2682
|
-
}
|
|
2683
|
-
}
|
|
2684
|
-
return { values, depths };
|
|
2685
|
-
}
|
|
2686
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
2687
|
-
if (width <= 0) return [];
|
|
2688
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
2689
|
-
const columnIds = [];
|
|
2690
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
2691
|
-
const cell = cells[startCol + offset];
|
|
2692
|
-
if (!cell) break;
|
|
2693
|
-
columnIds.push(cell.column.id);
|
|
2694
|
-
}
|
|
2695
|
-
return columnIds;
|
|
2696
|
-
}
|
|
2697
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
2698
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
2699
|
-
if (values.length === 0) return null;
|
|
2700
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
2701
|
-
if (width === 0) return null;
|
|
2702
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
2703
|
-
if (columnIds.length === 0) return null;
|
|
2704
|
-
const rowIds = [];
|
|
2705
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
2706
|
-
const row = rows[startRow + offset];
|
|
2707
|
-
if (!row) break;
|
|
2708
|
-
rowIds.push(row.id);
|
|
2709
|
-
}
|
|
2710
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
2711
|
-
return {
|
|
2712
|
-
mode,
|
|
2713
|
-
startRow,
|
|
2714
|
-
startCol,
|
|
2715
|
-
endRow,
|
|
2716
|
-
rowIds,
|
|
2717
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
2718
|
-
columnIds,
|
|
2719
|
-
values,
|
|
2720
|
-
depths
|
|
2721
|
-
};
|
|
2722
|
-
}
|
|
2723
|
-
function isEditablePasteTarget(target) {
|
|
2724
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
2725
|
-
const tag = target.tagName;
|
|
2726
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
2727
|
-
return Boolean(target.isContentEditable);
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
2649
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
2731
2650
|
import { useCallback as useCallback3, useEffect as useEffect5, useRef as useRef5, useState as useState3 } from "react";
|
|
2732
2651
|
|
|
@@ -3176,7 +3095,95 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
3176
3095
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
3177
3096
|
}
|
|
3178
3097
|
|
|
3098
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
3099
|
+
function countLeadingEmptyCells(cells) {
|
|
3100
|
+
let depth = 0;
|
|
3101
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
3102
|
+
depth += 1;
|
|
3103
|
+
}
|
|
3104
|
+
return depth;
|
|
3105
|
+
}
|
|
3106
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
3107
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
3108
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
3109
|
+
if (firstDepth !== 0) return false;
|
|
3110
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
3111
|
+
}
|
|
3112
|
+
function parseClipboardTSVWithDepths(text) {
|
|
3113
|
+
if (!text) return { values: [], depths: [] };
|
|
3114
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
3115
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
3116
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
3117
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
3118
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
3119
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
3120
|
+
const values = [];
|
|
3121
|
+
const depths = [];
|
|
3122
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
3123
|
+
const cells = rows[index] ?? [];
|
|
3124
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
3125
|
+
if (treatAsDepth) {
|
|
3126
|
+
values.push(cells.slice(depth));
|
|
3127
|
+
depths.push(depth);
|
|
3128
|
+
} else {
|
|
3129
|
+
values.push(cells);
|
|
3130
|
+
depths.push(0);
|
|
3131
|
+
}
|
|
3132
|
+
}
|
|
3133
|
+
return { values, depths };
|
|
3134
|
+
}
|
|
3135
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
3136
|
+
if (width <= 0) return [];
|
|
3137
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
3138
|
+
const columnIds = [];
|
|
3139
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
3140
|
+
const cell = cells[startCol + offset];
|
|
3141
|
+
if (!cell) break;
|
|
3142
|
+
columnIds.push(cell.column.id);
|
|
3143
|
+
}
|
|
3144
|
+
return columnIds;
|
|
3145
|
+
}
|
|
3146
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
3147
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
3148
|
+
if (values.length === 0) return null;
|
|
3149
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
3150
|
+
if (width === 0) return null;
|
|
3151
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
3152
|
+
if (columnIds.length === 0) return null;
|
|
3153
|
+
const rowIds = [];
|
|
3154
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
3155
|
+
const row = rows[startRow + offset];
|
|
3156
|
+
if (!row) break;
|
|
3157
|
+
rowIds.push(row.id);
|
|
3158
|
+
}
|
|
3159
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
3160
|
+
return {
|
|
3161
|
+
mode,
|
|
3162
|
+
startRow,
|
|
3163
|
+
startCol,
|
|
3164
|
+
endRow,
|
|
3165
|
+
rowIds,
|
|
3166
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
3167
|
+
columnIds,
|
|
3168
|
+
values,
|
|
3169
|
+
depths
|
|
3170
|
+
};
|
|
3171
|
+
}
|
|
3172
|
+
function isEditablePasteTarget(target) {
|
|
3173
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
3174
|
+
const tag = target.tagName;
|
|
3175
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
3176
|
+
return Boolean(target.isContentEditable);
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
3179
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
3180
|
+
function isFocusOutsideRoot(rootRef) {
|
|
3181
|
+
const root = rootRef?.current;
|
|
3182
|
+
if (!root) return false;
|
|
3183
|
+
const active = document.activeElement;
|
|
3184
|
+
if (!active || active === document.body) return false;
|
|
3185
|
+
return !root.contains(active);
|
|
3186
|
+
}
|
|
3180
3187
|
function useCellSelection({
|
|
3181
3188
|
data,
|
|
3182
3189
|
rows,
|
|
@@ -3285,6 +3292,7 @@ function useCellSelection({
|
|
|
3285
3292
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3286
3293
|
return;
|
|
3287
3294
|
}
|
|
3295
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3288
3296
|
const delta = getCellNavigationDelta(e.key);
|
|
3289
3297
|
if (!delta) return;
|
|
3290
3298
|
const prev = dragStateRef.current;
|
|
@@ -3352,6 +3360,7 @@ function useCellSelection({
|
|
|
3352
3360
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3353
3361
|
return;
|
|
3354
3362
|
}
|
|
3363
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3355
3364
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
3356
3365
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
3357
3366
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -3390,6 +3399,7 @@ function useCellSelection({
|
|
|
3390
3399
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3391
3400
|
return;
|
|
3392
3401
|
}
|
|
3402
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3393
3403
|
if (e.shiftKey && !enableInsertPaste) {
|
|
3394
3404
|
ignoreNextPasteRef.current = true;
|
|
3395
3405
|
pendingPasteModeRef.current = null;
|
|
@@ -3419,6 +3429,7 @@ function useCellSelection({
|
|
|
3419
3429
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3420
3430
|
return;
|
|
3421
3431
|
}
|
|
3432
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3422
3433
|
if (ignoreNextPasteRef.current) {
|
|
3423
3434
|
ignoreNextPasteRef.current = false;
|
|
3424
3435
|
pendingPasteModeRef.current = null;
|
|
@@ -3519,6 +3530,37 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
3519
3530
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
3520
3531
|
}
|
|
3521
3532
|
|
|
3533
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
3534
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
3535
|
+
var isListening = false;
|
|
3536
|
+
function handleEscape(event) {
|
|
3537
|
+
if (event.key !== "Escape") return;
|
|
3538
|
+
if (event.defaultPrevented) return;
|
|
3539
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3540
|
+
return;
|
|
3541
|
+
}
|
|
3542
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3543
|
+
return;
|
|
3544
|
+
}
|
|
3545
|
+
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
3546
|
+
clearAllSelections();
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
3550
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
3551
|
+
if (!isListening) {
|
|
3552
|
+
window.addEventListener("keydown", handleEscape);
|
|
3553
|
+
isListening = true;
|
|
3554
|
+
}
|
|
3555
|
+
return () => {
|
|
3556
|
+
clearAllByOwner.delete(owner);
|
|
3557
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
3558
|
+
window.removeEventListener("keydown", handleEscape);
|
|
3559
|
+
isListening = false;
|
|
3560
|
+
}
|
|
3561
|
+
};
|
|
3562
|
+
}
|
|
3563
|
+
|
|
3522
3564
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
3523
3565
|
import {
|
|
3524
3566
|
useCallback as useCallback4,
|
|
@@ -3937,6 +3979,7 @@ function useGlideTable(options) {
|
|
|
3937
3979
|
const [hoveredRowIndex, setHoveredRowIndex] = useState5(null);
|
|
3938
3980
|
const scrollRef = useRef7(null);
|
|
3939
3981
|
const rootRef = useRef7(null);
|
|
3982
|
+
const escapeDismissOwnerRef = useRef7(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
3940
3983
|
const cellRendererRegistry = useMemo3(
|
|
3941
3984
|
() => createCellRendererRegistry(cellRenderers),
|
|
3942
3985
|
[cellRenderers]
|
|
@@ -4140,25 +4183,10 @@ function useGlideTable(options) {
|
|
|
4140
4183
|
setInternalRowSelection({});
|
|
4141
4184
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
4142
4185
|
useEffect7(() => {
|
|
4143
|
-
|
|
4186
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
4144
4187
|
clearCellSelection();
|
|
4145
4188
|
clearRowSelection();
|
|
4146
|
-
};
|
|
4147
|
-
const handleKeyDown = (event) => {
|
|
4148
|
-
if (event.key !== "Escape") return;
|
|
4149
|
-
if (event.defaultPrevented) return;
|
|
4150
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
4151
|
-
return;
|
|
4152
|
-
}
|
|
4153
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
4154
|
-
return;
|
|
4155
|
-
}
|
|
4156
|
-
clearAllSelections();
|
|
4157
|
-
};
|
|
4158
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
4159
|
-
return () => {
|
|
4160
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
4161
|
-
};
|
|
4189
|
+
});
|
|
4162
4190
|
}, [clearCellSelection, clearRowSelection]);
|
|
4163
4191
|
const {
|
|
4164
4192
|
editingCell,
|