react-glide-table 2.3.3 → 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 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,6 +3107,87 @@ 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
3192
  function isFocusOutsideRoot(rootRef) {
3193
3193
  const root = rootRef?.current;
@@ -3542,6 +3542,37 @@ function isOverlayDismissIgnoreTarget(target) {
3542
3542
  return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
3543
3543
  }
3544
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
+
3545
3576
  // src/components/ui/table/features/inline-search/useInlineSearch.ts
3546
3577
  var import_react8 = require("react");
3547
3578
  var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
@@ -3953,6 +3984,7 @@ function useGlideTable(options) {
3953
3984
  const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react9.useState)(null);
3954
3985
  const scrollRef = (0, import_react9.useRef)(null);
3955
3986
  const rootRef = (0, import_react9.useRef)(null);
3987
+ const escapeDismissOwnerRef = (0, import_react9.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
3956
3988
  const cellRendererRegistry = (0, import_react9.useMemo)(
3957
3989
  () => createCellRendererRegistry(cellRenderers),
3958
3990
  [cellRenderers]
@@ -4156,25 +4188,10 @@ function useGlideTable(options) {
4156
4188
  setInternalRowSelection({});
4157
4189
  }, [onRowSelectionChange, rowSelection, rowSelectionMode]);
4158
4190
  (0, import_react9.useEffect)(() => {
4159
- const clearAllSelections = () => {
4191
+ return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
4160
4192
  clearCellSelection();
4161
4193
  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
- };
4194
+ });
4178
4195
  }, [clearCellSelection, clearRowSelection]);
4179
4196
  const {
4180
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,6 +3095,87 @@ 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
3180
  function isFocusOutsideRoot(rootRef) {
3181
3181
  const root = rootRef?.current;
@@ -3530,6 +3530,37 @@ function isOverlayDismissIgnoreTarget(target) {
3530
3530
  return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
3531
3531
  }
3532
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
+
3533
3564
  // src/components/ui/table/features/inline-search/useInlineSearch.ts
3534
3565
  import {
3535
3566
  useCallback as useCallback4,
@@ -3948,6 +3979,7 @@ function useGlideTable(options) {
3948
3979
  const [hoveredRowIndex, setHoveredRowIndex] = useState5(null);
3949
3980
  const scrollRef = useRef7(null);
3950
3981
  const rootRef = useRef7(null);
3982
+ const escapeDismissOwnerRef = useRef7(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
3951
3983
  const cellRendererRegistry = useMemo3(
3952
3984
  () => createCellRendererRegistry(cellRenderers),
3953
3985
  [cellRenderers]
@@ -4151,25 +4183,10 @@ function useGlideTable(options) {
4151
4183
  setInternalRowSelection({});
4152
4184
  }, [onRowSelectionChange, rowSelection, rowSelectionMode]);
4153
4185
  useEffect7(() => {
4154
- const clearAllSelections = () => {
4186
+ return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
4155
4187
  clearCellSelection();
4156
4188
  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
- };
4189
+ });
4173
4190
  }, [clearCellSelection, clearRowSelection]);
4174
4191
  const {
4175
4192
  editingCell,