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/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
|
|
|
@@ -3121,15 +3040,41 @@ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options)
|
|
|
3121
3040
|
options
|
|
3122
3041
|
);
|
|
3123
3042
|
}
|
|
3043
|
+
function writeTextWithExecCommand(text) {
|
|
3044
|
+
if (typeof document === "undefined") return false;
|
|
3045
|
+
const textarea = document.createElement("textarea");
|
|
3046
|
+
textarea.value = text;
|
|
3047
|
+
textarea.setAttribute("readonly", "");
|
|
3048
|
+
textarea.style.position = "fixed";
|
|
3049
|
+
textarea.style.top = "0";
|
|
3050
|
+
textarea.style.left = "0";
|
|
3051
|
+
textarea.style.opacity = "0";
|
|
3052
|
+
textarea.style.pointerEvents = "none";
|
|
3053
|
+
document.body.appendChild(textarea);
|
|
3054
|
+
const previouslyFocused = document.activeElement;
|
|
3055
|
+
try {
|
|
3056
|
+
textarea.focus();
|
|
3057
|
+
textarea.select();
|
|
3058
|
+
return document.execCommand("copy");
|
|
3059
|
+
} catch {
|
|
3060
|
+
return false;
|
|
3061
|
+
} finally {
|
|
3062
|
+
document.body.removeChild(textarea);
|
|
3063
|
+
previouslyFocused?.focus?.();
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3124
3066
|
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
3125
3067
|
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
3126
3068
|
if (!text) return false;
|
|
3069
|
+
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
3070
|
+
return writeTextWithExecCommand(text);
|
|
3071
|
+
}
|
|
3127
3072
|
try {
|
|
3128
3073
|
await navigator.clipboard.writeText(text);
|
|
3074
|
+
return true;
|
|
3129
3075
|
} catch {
|
|
3130
3076
|
return false;
|
|
3131
3077
|
}
|
|
3132
|
-
return true;
|
|
3133
3078
|
}
|
|
3134
3079
|
|
|
3135
3080
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
@@ -3188,6 +3133,87 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
3188
3133
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
3189
3134
|
}
|
|
3190
3135
|
|
|
3136
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
3137
|
+
function countLeadingEmptyCells(cells) {
|
|
3138
|
+
let depth = 0;
|
|
3139
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
3140
|
+
depth += 1;
|
|
3141
|
+
}
|
|
3142
|
+
return depth;
|
|
3143
|
+
}
|
|
3144
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
3145
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
3146
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
3147
|
+
if (firstDepth !== 0) return false;
|
|
3148
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
3149
|
+
}
|
|
3150
|
+
function parseClipboardTSVWithDepths(text) {
|
|
3151
|
+
if (!text) return { values: [], depths: [] };
|
|
3152
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
3153
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
3154
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
3155
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
3156
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
3157
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
3158
|
+
const values = [];
|
|
3159
|
+
const depths = [];
|
|
3160
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
3161
|
+
const cells = rows[index] ?? [];
|
|
3162
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
3163
|
+
if (treatAsDepth) {
|
|
3164
|
+
values.push(cells.slice(depth));
|
|
3165
|
+
depths.push(depth);
|
|
3166
|
+
} else {
|
|
3167
|
+
values.push(cells);
|
|
3168
|
+
depths.push(0);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
return { values, depths };
|
|
3172
|
+
}
|
|
3173
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
3174
|
+
if (width <= 0) return [];
|
|
3175
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
3176
|
+
const columnIds = [];
|
|
3177
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
3178
|
+
const cell = cells[startCol + offset];
|
|
3179
|
+
if (!cell) break;
|
|
3180
|
+
columnIds.push(cell.column.id);
|
|
3181
|
+
}
|
|
3182
|
+
return columnIds;
|
|
3183
|
+
}
|
|
3184
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
3185
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
3186
|
+
if (values.length === 0) return null;
|
|
3187
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
3188
|
+
if (width === 0) return null;
|
|
3189
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
3190
|
+
if (columnIds.length === 0) return null;
|
|
3191
|
+
const rowIds = [];
|
|
3192
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
3193
|
+
const row = rows[startRow + offset];
|
|
3194
|
+
if (!row) break;
|
|
3195
|
+
rowIds.push(row.id);
|
|
3196
|
+
}
|
|
3197
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
3198
|
+
return {
|
|
3199
|
+
mode,
|
|
3200
|
+
startRow,
|
|
3201
|
+
startCol,
|
|
3202
|
+
endRow,
|
|
3203
|
+
rowIds,
|
|
3204
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
3205
|
+
columnIds,
|
|
3206
|
+
values,
|
|
3207
|
+
depths
|
|
3208
|
+
};
|
|
3209
|
+
}
|
|
3210
|
+
function isEditablePasteTarget(target) {
|
|
3211
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
3212
|
+
const tag = target.tagName;
|
|
3213
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
3214
|
+
return Boolean(target.isContentEditable);
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3191
3217
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
3192
3218
|
function isFocusOutsideRoot(rootRef) {
|
|
3193
3219
|
const root = rootRef?.current;
|
|
@@ -3542,6 +3568,41 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
3542
3568
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
3543
3569
|
}
|
|
3544
3570
|
|
|
3571
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
3572
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
3573
|
+
var isListening = false;
|
|
3574
|
+
function handleEscape(event) {
|
|
3575
|
+
if (event.key !== "Escape") return;
|
|
3576
|
+
if (event.defaultPrevented) return;
|
|
3577
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3578
|
+
return;
|
|
3579
|
+
}
|
|
3580
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3581
|
+
return;
|
|
3582
|
+
}
|
|
3583
|
+
for (const clearAllSelections of [...clearAllByOwner.values()]) {
|
|
3584
|
+
try {
|
|
3585
|
+
clearAllSelections();
|
|
3586
|
+
} catch (error) {
|
|
3587
|
+
console.error("[react-glide-table] escape-dismiss callback failed", error);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
3592
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
3593
|
+
if (!isListening) {
|
|
3594
|
+
window.addEventListener("keydown", handleEscape);
|
|
3595
|
+
isListening = true;
|
|
3596
|
+
}
|
|
3597
|
+
return () => {
|
|
3598
|
+
clearAllByOwner.delete(owner);
|
|
3599
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
3600
|
+
window.removeEventListener("keydown", handleEscape);
|
|
3601
|
+
isListening = false;
|
|
3602
|
+
}
|
|
3603
|
+
};
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3545
3606
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
3546
3607
|
var import_react8 = require("react");
|
|
3547
3608
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
@@ -3953,6 +4014,7 @@ function useGlideTable(options) {
|
|
|
3953
4014
|
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react9.useState)(null);
|
|
3954
4015
|
const scrollRef = (0, import_react9.useRef)(null);
|
|
3955
4016
|
const rootRef = (0, import_react9.useRef)(null);
|
|
4017
|
+
const escapeDismissOwnerRef = (0, import_react9.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
3956
4018
|
const cellRendererRegistry = (0, import_react9.useMemo)(
|
|
3957
4019
|
() => createCellRendererRegistry(cellRenderers),
|
|
3958
4020
|
[cellRenderers]
|
|
@@ -4156,25 +4218,10 @@ function useGlideTable(options) {
|
|
|
4156
4218
|
setInternalRowSelection({});
|
|
4157
4219
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
4158
4220
|
(0, import_react9.useEffect)(() => {
|
|
4159
|
-
|
|
4221
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
4160
4222
|
clearCellSelection();
|
|
4161
4223
|
clearRowSelection();
|
|
4162
|
-
};
|
|
4163
|
-
const handleKeyDown = (event) => {
|
|
4164
|
-
if (event.key !== "Escape") return;
|
|
4165
|
-
if (event.defaultPrevented) return;
|
|
4166
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
4167
|
-
return;
|
|
4168
|
-
}
|
|
4169
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
4170
|
-
return;
|
|
4171
|
-
}
|
|
4172
|
-
clearAllSelections();
|
|
4173
|
-
};
|
|
4174
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
4175
|
-
return () => {
|
|
4176
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
4177
|
-
};
|
|
4224
|
+
});
|
|
4178
4225
|
}, [clearCellSelection, clearRowSelection]);
|
|
4179
4226
|
const {
|
|
4180
4227
|
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
|
|
|
@@ -3109,15 +3028,41 @@ function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options)
|
|
|
3109
3028
|
options
|
|
3110
3029
|
);
|
|
3111
3030
|
}
|
|
3031
|
+
function writeTextWithExecCommand(text) {
|
|
3032
|
+
if (typeof document === "undefined") return false;
|
|
3033
|
+
const textarea = document.createElement("textarea");
|
|
3034
|
+
textarea.value = text;
|
|
3035
|
+
textarea.setAttribute("readonly", "");
|
|
3036
|
+
textarea.style.position = "fixed";
|
|
3037
|
+
textarea.style.top = "0";
|
|
3038
|
+
textarea.style.left = "0";
|
|
3039
|
+
textarea.style.opacity = "0";
|
|
3040
|
+
textarea.style.pointerEvents = "none";
|
|
3041
|
+
document.body.appendChild(textarea);
|
|
3042
|
+
const previouslyFocused = document.activeElement;
|
|
3043
|
+
try {
|
|
3044
|
+
textarea.focus();
|
|
3045
|
+
textarea.select();
|
|
3046
|
+
return document.execCommand("copy");
|
|
3047
|
+
} catch {
|
|
3048
|
+
return false;
|
|
3049
|
+
} finally {
|
|
3050
|
+
document.body.removeChild(textarea);
|
|
3051
|
+
previouslyFocused?.focus?.();
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3112
3054
|
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
3113
3055
|
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
3114
3056
|
if (!text) return false;
|
|
3057
|
+
if (typeof navigator === "undefined" || !navigator.clipboard?.writeText) {
|
|
3058
|
+
return writeTextWithExecCommand(text);
|
|
3059
|
+
}
|
|
3115
3060
|
try {
|
|
3116
3061
|
await navigator.clipboard.writeText(text);
|
|
3062
|
+
return true;
|
|
3117
3063
|
} catch {
|
|
3118
3064
|
return false;
|
|
3119
3065
|
}
|
|
3120
|
-
return true;
|
|
3121
3066
|
}
|
|
3122
3067
|
|
|
3123
3068
|
// src/components/ui/table/features/cell-selection/fillData.ts
|
|
@@ -3176,6 +3121,87 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
3176
3121
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
3177
3122
|
}
|
|
3178
3123
|
|
|
3124
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
3125
|
+
function countLeadingEmptyCells(cells) {
|
|
3126
|
+
let depth = 0;
|
|
3127
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
3128
|
+
depth += 1;
|
|
3129
|
+
}
|
|
3130
|
+
return depth;
|
|
3131
|
+
}
|
|
3132
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
3133
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
3134
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
3135
|
+
if (firstDepth !== 0) return false;
|
|
3136
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
3137
|
+
}
|
|
3138
|
+
function parseClipboardTSVWithDepths(text) {
|
|
3139
|
+
if (!text) return { values: [], depths: [] };
|
|
3140
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
3141
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
3142
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
3143
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
3144
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
3145
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
3146
|
+
const values = [];
|
|
3147
|
+
const depths = [];
|
|
3148
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
3149
|
+
const cells = rows[index] ?? [];
|
|
3150
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
3151
|
+
if (treatAsDepth) {
|
|
3152
|
+
values.push(cells.slice(depth));
|
|
3153
|
+
depths.push(depth);
|
|
3154
|
+
} else {
|
|
3155
|
+
values.push(cells);
|
|
3156
|
+
depths.push(0);
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
return { values, depths };
|
|
3160
|
+
}
|
|
3161
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
3162
|
+
if (width <= 0) return [];
|
|
3163
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
3164
|
+
const columnIds = [];
|
|
3165
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
3166
|
+
const cell = cells[startCol + offset];
|
|
3167
|
+
if (!cell) break;
|
|
3168
|
+
columnIds.push(cell.column.id);
|
|
3169
|
+
}
|
|
3170
|
+
return columnIds;
|
|
3171
|
+
}
|
|
3172
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
3173
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
3174
|
+
if (values.length === 0) return null;
|
|
3175
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
3176
|
+
if (width === 0) return null;
|
|
3177
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
3178
|
+
if (columnIds.length === 0) return null;
|
|
3179
|
+
const rowIds = [];
|
|
3180
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
3181
|
+
const row = rows[startRow + offset];
|
|
3182
|
+
if (!row) break;
|
|
3183
|
+
rowIds.push(row.id);
|
|
3184
|
+
}
|
|
3185
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
3186
|
+
return {
|
|
3187
|
+
mode,
|
|
3188
|
+
startRow,
|
|
3189
|
+
startCol,
|
|
3190
|
+
endRow,
|
|
3191
|
+
rowIds,
|
|
3192
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
3193
|
+
columnIds,
|
|
3194
|
+
values,
|
|
3195
|
+
depths
|
|
3196
|
+
};
|
|
3197
|
+
}
|
|
3198
|
+
function isEditablePasteTarget(target) {
|
|
3199
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
3200
|
+
const tag = target.tagName;
|
|
3201
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
3202
|
+
return Boolean(target.isContentEditable);
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3179
3205
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
3180
3206
|
function isFocusOutsideRoot(rootRef) {
|
|
3181
3207
|
const root = rootRef?.current;
|
|
@@ -3530,6 +3556,41 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
3530
3556
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
3531
3557
|
}
|
|
3532
3558
|
|
|
3559
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
3560
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
3561
|
+
var isListening = false;
|
|
3562
|
+
function handleEscape(event) {
|
|
3563
|
+
if (event.key !== "Escape") return;
|
|
3564
|
+
if (event.defaultPrevented) return;
|
|
3565
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3569
|
+
return;
|
|
3570
|
+
}
|
|
3571
|
+
for (const clearAllSelections of [...clearAllByOwner.values()]) {
|
|
3572
|
+
try {
|
|
3573
|
+
clearAllSelections();
|
|
3574
|
+
} catch (error) {
|
|
3575
|
+
console.error("[react-glide-table] escape-dismiss callback failed", error);
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
3580
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
3581
|
+
if (!isListening) {
|
|
3582
|
+
window.addEventListener("keydown", handleEscape);
|
|
3583
|
+
isListening = true;
|
|
3584
|
+
}
|
|
3585
|
+
return () => {
|
|
3586
|
+
clearAllByOwner.delete(owner);
|
|
3587
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
3588
|
+
window.removeEventListener("keydown", handleEscape);
|
|
3589
|
+
isListening = false;
|
|
3590
|
+
}
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3533
3594
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
3534
3595
|
import {
|
|
3535
3596
|
useCallback as useCallback4,
|
|
@@ -3948,6 +4009,7 @@ function useGlideTable(options) {
|
|
|
3948
4009
|
const [hoveredRowIndex, setHoveredRowIndex] = useState5(null);
|
|
3949
4010
|
const scrollRef = useRef7(null);
|
|
3950
4011
|
const rootRef = useRef7(null);
|
|
4012
|
+
const escapeDismissOwnerRef = useRef7(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
3951
4013
|
const cellRendererRegistry = useMemo3(
|
|
3952
4014
|
() => createCellRendererRegistry(cellRenderers),
|
|
3953
4015
|
[cellRenderers]
|
|
@@ -4151,25 +4213,10 @@ function useGlideTable(options) {
|
|
|
4151
4213
|
setInternalRowSelection({});
|
|
4152
4214
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
4153
4215
|
useEffect7(() => {
|
|
4154
|
-
|
|
4216
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
4155
4217
|
clearCellSelection();
|
|
4156
4218
|
clearRowSelection();
|
|
4157
|
-
};
|
|
4158
|
-
const handleKeyDown = (event) => {
|
|
4159
|
-
if (event.key !== "Escape") return;
|
|
4160
|
-
if (event.defaultPrevented) return;
|
|
4161
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
4162
|
-
return;
|
|
4163
|
-
}
|
|
4164
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
4165
|
-
return;
|
|
4166
|
-
}
|
|
4167
|
-
clearAllSelections();
|
|
4168
|
-
};
|
|
4169
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
4170
|
-
return () => {
|
|
4171
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
4172
|
-
};
|
|
4219
|
+
});
|
|
4173
4220
|
}, [clearCellSelection, clearRowSelection]);
|
|
4174
4221
|
const {
|
|
4175
4222
|
editingCell,
|