@rowsncolumns/spreadsheet 10.2.77 → 10.3.1

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.
Files changed (210) hide show
  1. package/dist/cjs/api/insert-options.d.ts +67 -0
  2. package/dist/cjs/api/insert-options.d.ts.map +1 -0
  3. package/dist/cjs/api/insert-options.js +104 -0
  4. package/dist/cjs/api/move-overwrite.d.ts +14 -0
  5. package/dist/cjs/api/move-overwrite.d.ts.map +1 -0
  6. package/dist/cjs/api/move-overwrite.js +29 -0
  7. package/dist/cjs/api/multi-selection.d.ts +59 -0
  8. package/dist/cjs/api/multi-selection.d.ts.map +1 -0
  9. package/dist/cjs/api/multi-selection.js +166 -0
  10. package/dist/cjs/atoms/index.d.ts +3 -0
  11. package/dist/cjs/atoms/index.d.ts.map +1 -1
  12. package/dist/cjs/atoms/index.js +3 -0
  13. package/dist/cjs/atoms/insert-cells-dialog.atom.d.ts +36 -0
  14. package/dist/cjs/atoms/insert-cells-dialog.atom.d.ts.map +1 -0
  15. package/dist/cjs/atoms/insert-cells-dialog.atom.js +34 -0
  16. package/dist/cjs/atoms/insert-options.atom.d.ts +21 -0
  17. package/dist/cjs/atoms/insert-options.atom.d.ts.map +1 -0
  18. package/dist/cjs/atoms/insert-options.atom.js +11 -0
  19. package/dist/cjs/atoms/move-overwrite-confirm.atom.d.ts +24 -0
  20. package/dist/cjs/atoms/move-overwrite-confirm.atom.d.ts.map +1 -0
  21. package/dist/cjs/atoms/move-overwrite-confirm.atom.js +42 -0
  22. package/dist/cjs/atoms/sheet-context.atom.d.ts +2 -0
  23. package/dist/cjs/atoms/sheet-context.atom.d.ts.map +1 -1
  24. package/dist/cjs/atoms/sheet-context.atom.js +15 -2
  25. package/dist/cjs/components/canvas-grid/index.d.ts.map +1 -1
  26. package/dist/cjs/components/canvas-grid/index.js +298 -68
  27. package/dist/cjs/components/canvas-grid/typings.d.ts +47 -5
  28. package/dist/cjs/components/canvas-grid/typings.d.ts.map +1 -1
  29. package/dist/cjs/components/cell-editor/formula-result-preview.d.ts +4 -1
  30. package/dist/cjs/components/cell-editor/formula-result-preview.d.ts.map +1 -1
  31. package/dist/cjs/components/cell-editor/formula-result-preview.js +2 -2
  32. package/dist/cjs/components/cell-editor/index.d.ts +7 -1
  33. package/dist/cjs/components/cell-editor/index.d.ts.map +1 -1
  34. package/dist/cjs/components/cell-editor/index.js +3 -3
  35. package/dist/cjs/components/cell-input/cell-input.d.ts +13 -0
  36. package/dist/cjs/components/cell-input/cell-input.d.ts.map +1 -1
  37. package/dist/cjs/components/cell-input/cell-input.js +8 -3
  38. package/dist/cjs/components/cell-input/formula-bar-cell-input.d.ts.map +1 -1
  39. package/dist/cjs/components/cell-input/formula-bar-cell-input.js +3 -1
  40. package/dist/cjs/components/context-menu/index.d.ts +16 -1
  41. package/dist/cjs/components/context-menu/index.d.ts.map +1 -1
  42. package/dist/cjs/components/context-menu/index.js +245 -24
  43. package/dist/cjs/components/embeds/embed-draggable.d.ts.map +1 -1
  44. package/dist/cjs/components/embeds/embed-draggable.js +4 -3
  45. package/dist/cjs/components/floating-cell-editor/index.d.ts.map +1 -1
  46. package/dist/cjs/components/floating-cell-editor/index.js +13 -5
  47. package/dist/cjs/components/insert-cells-dialog/index.d.ts +35 -0
  48. package/dist/cjs/components/insert-cells-dialog/index.d.ts.map +1 -0
  49. package/dist/cjs/components/insert-cells-dialog/index.js +84 -0
  50. package/dist/cjs/components/insert-options-smart-tag/index.d.ts +25 -0
  51. package/dist/cjs/components/insert-options-smart-tag/index.d.ts.map +1 -0
  52. package/dist/cjs/components/insert-options-smart-tag/index.js +41 -0
  53. package/dist/cjs/components/move-overwrite-confirm-dialog/index.d.ts +8 -0
  54. package/dist/cjs/components/move-overwrite-confirm-dialog/index.d.ts.map +1 -0
  55. package/dist/cjs/components/move-overwrite-confirm-dialog/index.js +34 -0
  56. package/dist/cjs/components/resizer/index.d.ts.map +1 -1
  57. package/dist/cjs/components/resizer/index.js +10 -5
  58. package/dist/cjs/components/selection/index.d.ts +1 -1
  59. package/dist/cjs/components/selection/index.d.ts.map +1 -1
  60. package/dist/cjs/components/selection/index.js +4 -2
  61. package/dist/cjs/components/selection/types.d.ts +8 -0
  62. package/dist/cjs/components/selection/types.d.ts.map +1 -1
  63. package/dist/cjs/components/sheet-search/index.d.ts.map +1 -1
  64. package/dist/cjs/components/sheet-search/index.js +6 -2
  65. package/dist/cjs/config.d.ts +6 -0
  66. package/dist/cjs/config.d.ts.map +1 -1
  67. package/dist/cjs/config.js +7 -1
  68. package/dist/cjs/hooks/use-cell-renderer.d.ts +7 -1
  69. package/dist/cjs/hooks/use-cell-renderer.d.ts.map +1 -1
  70. package/dist/cjs/hooks/use-cell-renderer.js +8 -3
  71. package/dist/cjs/hooks/use-context-setter.d.ts.map +1 -1
  72. package/dist/cjs/hooks/use-context-setter.js +5 -1
  73. package/dist/cjs/hooks/use-copy-paste-cut.d.ts +5 -0
  74. package/dist/cjs/hooks/use-copy-paste-cut.d.ts.map +1 -1
  75. package/dist/cjs/hooks/use-copy-paste-cut.js +25 -3
  76. package/dist/cjs/hooks/use-editor-change.d.ts +4 -1
  77. package/dist/cjs/hooks/use-editor-change.d.ts.map +1 -1
  78. package/dist/cjs/hooks/use-editor-change.js +4 -3
  79. package/dist/cjs/hooks/use-editor-submit.d.ts +8 -1
  80. package/dist/cjs/hooks/use-editor-submit.d.ts.map +1 -1
  81. package/dist/cjs/hooks/use-editor-submit.js +9 -1
  82. package/dist/cjs/hooks/use-header-actions.d.ts.map +1 -1
  83. package/dist/cjs/hooks/use-header-actions.js +17 -10
  84. package/dist/cjs/hooks/use-move-columns-rows.d.ts.map +1 -1
  85. package/dist/cjs/hooks/use-move-columns-rows.js +27 -15
  86. package/dist/cjs/hooks/use-selection-move.d.ts.map +1 -1
  87. package/dist/cjs/hooks/use-selection-move.js +14 -6
  88. package/dist/cjs/hooks/use-selection-renderer.d.ts +9 -1
  89. package/dist/cjs/hooks/use-selection-renderer.d.ts.map +1 -1
  90. package/dist/cjs/hooks/use-selection-renderer.js +26 -2
  91. package/dist/cjs/hooks/use-selection-resize.d.ts.map +1 -1
  92. package/dist/cjs/hooks/use-selection-resize.js +13 -6
  93. package/dist/cjs/hooks/use-selection.d.ts +13 -5
  94. package/dist/cjs/hooks/use-selection.d.ts.map +1 -1
  95. package/dist/cjs/hooks/use-selection.js +107 -31
  96. package/dist/cjs/hooks/use-table-resizer.d.ts.map +1 -1
  97. package/dist/cjs/hooks/use-table-resizer.js +16 -8
  98. package/dist/cjs/hooks/use-touch.d.ts.map +1 -1
  99. package/dist/cjs/hooks/use-touch.js +16 -8
  100. package/dist/cjs/index.d.ts +7 -0
  101. package/dist/cjs/index.d.ts.map +1 -1
  102. package/dist/cjs/index.js +7 -0
  103. package/dist/cjs/release-date.js +1 -1
  104. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  105. package/dist/esm/api/insert-options.d.ts +67 -0
  106. package/dist/esm/api/insert-options.d.ts.map +1 -0
  107. package/dist/esm/api/insert-options.js +91 -0
  108. package/dist/esm/api/move-overwrite.d.ts +14 -0
  109. package/dist/esm/api/move-overwrite.d.ts.map +1 -0
  110. package/dist/esm/api/move-overwrite.js +25 -0
  111. package/dist/esm/api/multi-selection.d.ts +59 -0
  112. package/dist/esm/api/multi-selection.d.ts.map +1 -0
  113. package/dist/esm/api/multi-selection.js +92 -0
  114. package/dist/esm/atoms/index.d.ts +3 -0
  115. package/dist/esm/atoms/index.d.ts.map +1 -1
  116. package/dist/esm/atoms/index.js +3 -0
  117. package/dist/esm/atoms/insert-cells-dialog.atom.d.ts +36 -0
  118. package/dist/esm/atoms/insert-cells-dialog.atom.d.ts.map +1 -0
  119. package/dist/esm/atoms/insert-cells-dialog.atom.js +25 -0
  120. package/dist/esm/atoms/insert-options.atom.d.ts +21 -0
  121. package/dist/esm/atoms/insert-options.atom.d.ts.map +1 -0
  122. package/dist/esm/atoms/insert-options.atom.js +5 -0
  123. package/dist/esm/atoms/move-overwrite-confirm.atom.d.ts +24 -0
  124. package/dist/esm/atoms/move-overwrite-confirm.atom.d.ts.map +1 -0
  125. package/dist/esm/atoms/move-overwrite-confirm.atom.js +29 -0
  126. package/dist/esm/atoms/sheet-context.atom.d.ts +2 -0
  127. package/dist/esm/atoms/sheet-context.atom.d.ts.map +1 -1
  128. package/dist/esm/atoms/sheet-context.atom.js +10 -0
  129. package/dist/esm/components/canvas-grid/index.d.ts.map +1 -1
  130. package/dist/esm/components/canvas-grid/index.js +250 -24
  131. package/dist/esm/components/canvas-grid/typings.d.ts +47 -5
  132. package/dist/esm/components/canvas-grid/typings.d.ts.map +1 -1
  133. package/dist/esm/components/cell-editor/formula-result-preview.d.ts +4 -1
  134. package/dist/esm/components/cell-editor/formula-result-preview.d.ts.map +1 -1
  135. package/dist/esm/components/cell-editor/formula-result-preview.js +3 -3
  136. package/dist/esm/components/cell-editor/index.d.ts +7 -1
  137. package/dist/esm/components/cell-editor/index.d.ts.map +1 -1
  138. package/dist/esm/components/cell-editor/index.js +3 -3
  139. package/dist/esm/components/cell-input/cell-input.d.ts +13 -0
  140. package/dist/esm/components/cell-input/cell-input.d.ts.map +1 -1
  141. package/dist/esm/components/cell-input/cell-input.js +10 -5
  142. package/dist/esm/components/cell-input/formula-bar-cell-input.d.ts.map +1 -1
  143. package/dist/esm/components/cell-input/formula-bar-cell-input.js +3 -1
  144. package/dist/esm/components/context-menu/index.d.ts +16 -1
  145. package/dist/esm/components/context-menu/index.d.ts.map +1 -1
  146. package/dist/esm/components/context-menu/index.js +193 -16
  147. package/dist/esm/components/embeds/embed-draggable.d.ts.map +1 -1
  148. package/dist/esm/components/embeds/embed-draggable.js +3 -2
  149. package/dist/esm/components/floating-cell-editor/index.d.ts.map +1 -1
  150. package/dist/esm/components/floating-cell-editor/index.js +12 -6
  151. package/dist/esm/components/insert-cells-dialog/index.d.ts +35 -0
  152. package/dist/esm/components/insert-cells-dialog/index.d.ts.map +1 -0
  153. package/dist/esm/components/insert-cells-dialog/index.js +79 -0
  154. package/dist/esm/components/insert-options-smart-tag/index.d.ts +25 -0
  155. package/dist/esm/components/insert-options-smart-tag/index.d.ts.map +1 -0
  156. package/dist/esm/components/insert-options-smart-tag/index.js +35 -0
  157. package/dist/esm/components/move-overwrite-confirm-dialog/index.d.ts +8 -0
  158. package/dist/esm/components/move-overwrite-confirm-dialog/index.d.ts.map +1 -0
  159. package/dist/esm/components/move-overwrite-confirm-dialog/index.js +30 -0
  160. package/dist/esm/components/resizer/index.d.ts.map +1 -1
  161. package/dist/esm/components/resizer/index.js +8 -4
  162. package/dist/esm/components/selection/index.d.ts +1 -1
  163. package/dist/esm/components/selection/index.d.ts.map +1 -1
  164. package/dist/esm/components/selection/index.js +4 -2
  165. package/dist/esm/components/selection/types.d.ts +8 -0
  166. package/dist/esm/components/selection/types.d.ts.map +1 -1
  167. package/dist/esm/components/sheet-search/index.d.ts.map +1 -1
  168. package/dist/esm/components/sheet-search/index.js +5 -2
  169. package/dist/esm/config.d.ts +6 -0
  170. package/dist/esm/config.d.ts.map +1 -1
  171. package/dist/esm/config.js +6 -0
  172. package/dist/esm/hooks/use-cell-renderer.d.ts +7 -1
  173. package/dist/esm/hooks/use-cell-renderer.d.ts.map +1 -1
  174. package/dist/esm/hooks/use-cell-renderer.js +9 -4
  175. package/dist/esm/hooks/use-context-setter.d.ts.map +1 -1
  176. package/dist/esm/hooks/use-context-setter.js +5 -1
  177. package/dist/esm/hooks/use-copy-paste-cut.d.ts +5 -0
  178. package/dist/esm/hooks/use-copy-paste-cut.d.ts.map +1 -1
  179. package/dist/esm/hooks/use-copy-paste-cut.js +25 -4
  180. package/dist/esm/hooks/use-editor-change.d.ts +4 -1
  181. package/dist/esm/hooks/use-editor-change.d.ts.map +1 -1
  182. package/dist/esm/hooks/use-editor-change.js +5 -4
  183. package/dist/esm/hooks/use-editor-submit.d.ts +8 -1
  184. package/dist/esm/hooks/use-editor-submit.d.ts.map +1 -1
  185. package/dist/esm/hooks/use-editor-submit.js +10 -2
  186. package/dist/esm/hooks/use-header-actions.d.ts.map +1 -1
  187. package/dist/esm/hooks/use-header-actions.js +11 -4
  188. package/dist/esm/hooks/use-move-columns-rows.d.ts.map +1 -1
  189. package/dist/esm/hooks/use-move-columns-rows.js +18 -6
  190. package/dist/esm/hooks/use-selection-move.d.ts.map +1 -1
  191. package/dist/esm/hooks/use-selection-move.js +11 -4
  192. package/dist/esm/hooks/use-selection-renderer.d.ts +9 -1
  193. package/dist/esm/hooks/use-selection-renderer.d.ts.map +1 -1
  194. package/dist/esm/hooks/use-selection-renderer.js +26 -2
  195. package/dist/esm/hooks/use-selection-resize.d.ts.map +1 -1
  196. package/dist/esm/hooks/use-selection-resize.js +11 -5
  197. package/dist/esm/hooks/use-selection.d.ts +13 -5
  198. package/dist/esm/hooks/use-selection.d.ts.map +1 -1
  199. package/dist/esm/hooks/use-selection.js +89 -27
  200. package/dist/esm/hooks/use-table-resizer.d.ts.map +1 -1
  201. package/dist/esm/hooks/use-table-resizer.js +15 -9
  202. package/dist/esm/hooks/use-touch.d.ts.map +1 -1
  203. package/dist/esm/hooks/use-touch.js +15 -7
  204. package/dist/esm/index.d.ts +7 -0
  205. package/dist/esm/index.d.ts.map +1 -1
  206. package/dist/esm/index.js +7 -0
  207. package/dist/esm/release-date.js +1 -1
  208. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  209. package/dist/spreadsheet.min.css +1 -1
  210. package/package.json +6 -6
@@ -1,3 +1,4 @@
1
+ import { getOwnerDocument } from "@rowsncolumns/grid";
1
2
  import React, { useCallback, useMemo, useRef, useState } from "react";
2
3
  import { scheduleLowPriorityCallback } from "../api/scheduler";
3
4
  import { Headermenu } from "../components/header-menu";
@@ -12,6 +13,8 @@ export const useHeaderActions = ({ activeCell, getScrollPosition, getCellOffsetF
12
13
  const [dimension, setDimension] = useState(0);
13
14
  const [isDragging, setIsDragging] = useState(false);
14
15
  const dragStartPos = useRef(0);
16
+ /** Document the in-flight gesture listens on (the grid may live in a popout window) */
17
+ const gestureDocumentRef = useRef(null);
15
18
  const activeCellRef = useRef(undefined);
16
19
  const axisRef = useRef(undefined);
17
20
  const dimensionRef = useRef(0);
@@ -129,8 +132,10 @@ export const useHeaderActions = ({ activeCell, getScrollPosition, getCellOffsetF
129
132
  * Called when user finishes dragging the component
130
133
  */
131
134
  const handleMouseUp = useCallback(() => {
132
- document.removeEventListener("mousemove", handleMouseMove);
133
- document.removeEventListener("mouseup", handleMouseUp);
135
+ const ownerDocument = gestureDocumentRef.current ?? document;
136
+ gestureDocumentRef.current = null;
137
+ ownerDocument.removeEventListener("mousemove", handleMouseMove);
138
+ ownerDocument.removeEventListener("mouseup", handleMouseUp);
134
139
  // Header resizer does not update otherwise.. @Vinay TODO Fix this later
135
140
  scheduleLowPriorityCallback(() => {
136
141
  setDimension(0);
@@ -172,8 +177,10 @@ export const useHeaderActions = ({ activeCell, getScrollPosition, getCellOffsetF
172
177
  dragStartPos.current =
173
178
  axisRef.current === "x" ? relativePosition.y : relativePosition.x;
174
179
  initialDimensionRef.current = axisRef.current === "x" ? height : width;
175
- document.addEventListener("mousemove", handleMouseMove);
176
- document.addEventListener("mouseup", handleMouseUp);
180
+ const ownerDocument = getOwnerDocument(e.currentTarget) ?? document;
181
+ gestureDocumentRef.current = ownerDocument;
182
+ ownerDocument.addEventListener("mousemove", handleMouseMove);
183
+ ownerDocument.addEventListener("mouseup", handleMouseUp);
177
184
  }, [
178
185
  activeCell,
179
186
  handleMouseMove,
@@ -1 +1 @@
1
- {"version":3,"file":"use-move-columns-rows.d.ts","sourceRoot":"","sources":["../../../hooks/use-move-columns-rows.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,aAAa,EACb,YAAY,EACb,MAAM,oBAAoB,CAAC;AAQ5B,OAAO,KAAiD,MAAM,OAAO,CAAC;AAEtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACL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,aAAa,EAAE,eAAe,CAAC,eAAe,CAAC,CAAC;IAChD,UAAU,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC1C;;OAEG;IACH,iBAAiB,EAAE,MAAM,YAAY,GAAG,SAAS,CAAC;IAClD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,KAAK,IAAI,CAAC;IAChE,kBAAkB,EAAE,eAAe,CAAC,oBAAoB,CAAC,CAAC;IAC1D,kBAAkB,EAAE,eAAe,CAAC,oBAAoB,CAAC,CAAC;IAC1D,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,aAAa,CAAC;IAC1B,uBAAuB,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC;CACnE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,GAAI,8YAwBnC,oBAAoB;;;;CAmatB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Direction } from "@rowsncolumns/grid";
2
- import { MouseButtonCodes } from "@rowsncolumns/grid";
2
+ import { getOwnerDocument, MouseButtonCodes } from "@rowsncolumns/grid";
3
3
  import { getMinMaxArray, isNil, selectionBoundsFromCells, } from "@rowsncolumns/utils";
4
4
  import React, { useCallback, useMemo, useRef, useState } from "react";
5
5
  import { HeaderMoveDragComponent as DefaultHeaderMoveDragComponent, } from "../components/header-move";
@@ -14,6 +14,8 @@ export const useMoveColumnsAndRows = ({ getCellOffsetFromCoords, getCellCoordsFr
14
14
  const [offset, setOffset] = useState(0);
15
15
  const [dragOffset, setDragOffset] = useState(0);
16
16
  const gapRef = useRef(0);
17
+ /** Document the in-flight gesture listens on (the grid may live in a popout window) */
18
+ const gestureDocumentRef = useRef(null);
17
19
  const startCellRef = useRef(undefined);
18
20
  const startRef = useRef(0);
19
21
  const endRef = useRef(0);
@@ -83,8 +85,10 @@ export const useMoveColumnsAndRows = ({ getCellOffsetFromCoords, getCellCoordsFr
83
85
  */
84
86
  const handleMouseUp = useCallback((e) => {
85
87
  setIsDragging(false);
86
- document.removeEventListener("mousemove", handleMouseMove);
87
- document.removeEventListener("mouseup", handleMouseUp);
88
+ const ownerDocument = gestureDocumentRef.current ?? document;
89
+ gestureDocumentRef.current = null;
90
+ ownerDocument.removeEventListener("mousemove", handleMouseMove);
91
+ ownerDocument.removeEventListener("mouseup", handleMouseUp);
88
92
  const dimensions = dragDimensions.current;
89
93
  if (!dragAxis.current || !dimensions) {
90
94
  return;
@@ -127,6 +131,12 @@ export const useMoveColumnsAndRows = ({ getCellOffsetFromCoords, getCellCoordsFr
127
131
  rowIndex = coords.rowIndex - (dragDimensions.current?.length ?? 0) + 1;
128
132
  }
129
133
  if (hasUserMovedDimensions) {
134
+ // Intentional deviation from Excel: a plain header drag DISPLACES the rows / columns it
135
+ // is dropped on (Excel plain-drags a header to overwrite and only Shift+drag inserts).
136
+ // Overwriting whole rows/columns by drag is destructive with no data prompt in this
137
+ // grid, so both plain and Shift+drag insert here; the landing index is already
138
+ // compensated above (`coords - length + 1` for a downward/rightward drop) so the block
139
+ // lands exactly where the drop indicator shows, as Excel's Insert Cut Cells does.
130
140
  // Blocking callback
131
141
  if (dragAxis.current === "x") {
132
142
  onMoveColumns?.(sheetId, dimensions, columnIndex);
@@ -220,10 +230,12 @@ export const useMoveColumnsAndRows = ({ getCellOffsetFromCoords, getCellCoordsFr
220
230
  setOffset(offset);
221
231
  setDragOffset(dragOffset);
222
232
  /**
223
- * Add mousemove and up listeners
233
+ * Add mousemove and up listeners on the document the gesture started on
224
234
  */
225
- document.addEventListener("mousemove", handleMouseMove);
226
- document.addEventListener("mouseup", handleMouseUp);
235
+ const ownerDocument = getOwnerDocument(e.currentTarget) ?? document;
236
+ gestureDocumentRef.current = ownerDocument;
237
+ ownerDocument.addEventListener("mousemove", handleMouseMove);
238
+ ownerDocument.addEventListener("mouseup", handleMouseUp);
227
239
  }, [
228
240
  columns,
229
241
  rows,
@@ -1 +1 @@
1
- {"version":3,"file":"use-selection-move.d.ts","sourceRoot":"","sources":["../../../hooks/use-selection-move.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EAEb,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAGhF,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;IACxD;;;;;OAKG;IACH,uBAAuB,CACrB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,GAClC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC;;;;OAIG;IACH,YAAY,CACV,IAAI,EAAE,qBAAqB,EAC3B,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,GACxB,IAAI,GAAG,SAAS,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,uDAI9B,qBAAqB;kCA2HhB,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC;;CAyCzC,CAAC"}
1
+ {"version":3,"file":"use-selection-move.d.ts","sourceRoot":"","sources":["../../../hooks/use-selection-move.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EAEb,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAGhF,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC;IACxD;;;;;OAKG;IACH,uBAAuB,CACrB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,GAClC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC;;;;OAIG;IACH,YAAY,CACV,IAAI,EAAE,qBAAqB,EAC3B,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,GACxB,IAAI,GAAG,SAAS,CAAC;CACrB,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,uDAI9B,qBAAqB;kCA+HhB,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC;;CA2CzC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import isNil from "lodash/isNil";
2
+ import { getOwnerDocument } from "@rowsncolumns/grid";
2
3
  import { useCallback, useRef, useState } from "react";
3
4
  import { useActiveEditor, useEditingCellCoordinate, useGetAddressFromSelection, useGetSelectionsFromFormula, } from "../atoms";
4
5
  import { detokenize } from "./use-selection-resize";
@@ -12,6 +13,8 @@ export const useSelectionMove = ({ tokenizer, getCellCoordsFromOffset, scrollToC
12
13
  const selectionIndexRef = useRef(undefined);
13
14
  const isDraggingRef = useRef(false);
14
15
  const startCell = useRef(undefined);
16
+ /** Document the in-flight gesture listens on (the grid may live in a popout window) */
17
+ const gestureDocumentRef = useRef(null);
15
18
  const initialRange = useRef(undefined);
16
19
  const activeEditor = useActiveEditor();
17
20
  const getSelectionToAddress = useGetAddressFromSelection();
@@ -95,8 +98,10 @@ export const useSelectionMove = ({ tokenizer, getCellCoordsFromOffset, scrollToC
95
98
  startCell.current = undefined;
96
99
  initialRange.current = undefined;
97
100
  setIsDragging(false);
98
- document.removeEventListener("pointermove", onMouseMove);
99
- document.removeEventListener("pointerup", onMouseUp);
101
+ const ownerDocument = gestureDocumentRef.current ?? document;
102
+ gestureDocumentRef.current = null;
103
+ ownerDocument.removeEventListener("pointermove", onMouseMove);
104
+ ownerDocument.removeEventListener("pointerup", onMouseUp);
100
105
  }, [activeEditor, onMouseMove]);
101
106
  // Mousedown
102
107
  const onMouseDownMoveSelection = useCallback((e) => {
@@ -126,8 +131,10 @@ export const useSelectionMove = ({ tokenizer, getCellCoordsFromOffset, scrollToC
126
131
  // jsdom / older browsers without pointer capture
127
132
  }
128
133
  setIsDragging(true);
129
- document.addEventListener("pointermove", onMouseMove);
130
- document.addEventListener("pointerup", onMouseUp);
134
+ const ownerDocument = getOwnerDocument(e.currentTarget) ?? document;
135
+ gestureDocumentRef.current = ownerDocument;
136
+ ownerDocument.addEventListener("pointermove", onMouseMove);
137
+ ownerDocument.addEventListener("pointerup", onMouseUp);
131
138
  }
132
139
  // Focus
133
140
  activeEditor?.focus();
@@ -1,6 +1,8 @@
1
1
  import { type CellInterface, type SelectionArea, type SelectionProps } from "@rowsncolumns/grid";
2
2
  import React from "react";
3
+ import type { InsertFormatOption } from "../api/insert-options";
3
4
  import type { FillOptionsRequest } from "../atoms/fill-options.atom";
5
+ import type { InsertOptionsRequest } from "../atoms/insert-options.atom";
4
6
  import type { CanvasGridProps, SelectionAttributes } from "../components/canvas-grid/typings";
5
7
  import type { SelectionNewProps } from "../components/selection/types";
6
8
  import type { AutoFillType, SheetRange } from "../types";
@@ -42,6 +44,12 @@ export type UseSelectionRendererProps = {
42
44
  onChooseFillType?(fillType: AutoFillType): void;
43
45
  onOpenFillSeriesDialog?(): void;
44
46
  onCloseFillOptions?(): void;
47
+ /**
48
+ * Pending Insert Options smart tag (rendered once, on the first selection
49
+ * that overlaps the inserted band — or the lone active cell).
50
+ */
51
+ insertOptions?: InsertOptionsRequest | null;
52
+ onChooseInsertOption?(option: InsertFormatOption): void;
45
53
  onSplitTextToColumns: CanvasGridProps["onSplitTextToColumns"];
46
54
  hoveredCell?: CellInterface | null;
47
55
  onRemoveQuickEdit(range: SheetRange): void;
@@ -53,5 +61,5 @@ export type UseSelectionRendererProps = {
53
61
  */
54
62
  isFillShrink?: boolean;
55
63
  };
56
- export declare const useSelectionRenderer: ({ sheetId, selectionCount, selectionBackgroundColor, selectionBorderColor, onSelectionMouseDown, onChangeActiveCell, onChangeSelections, onRequestEditTable, onRequestEditPivotTable, onMouseDownResizeHandle, onMouseDownMoveSelection, isDraggingMoveSelection, onFlashEnd, getSheetName, resizeHandleSize, showSelectionResizeHandles, resizeHandleBorderColor, SelectionTitleComponent, isResizingTable, fillHandleSize, showFillHandle, enableMagicFill, MagicFillComponent, MagicFillContent, readonly, showPasteMenu, fillOptions, onChooseFillType, onOpenFillSeriesDialog, onCloseFillOptions, hoveredCell, onSplitTextToColumns, onRemoveQuickEdit, onAddQuickEdit, QuickEdit, PasteMenu, SuggestionAction, cachedHoveredSelectionIds, isFillShrink, }: UseSelectionRendererProps) => (props: SelectionProps<SelectionAttributes>) => React.JSX.Element | null;
64
+ export declare const useSelectionRenderer: ({ sheetId, selectionCount, selectionBackgroundColor, selectionBorderColor, onSelectionMouseDown, onChangeActiveCell, onChangeSelections, onRequestEditTable, onRequestEditPivotTable, onMouseDownResizeHandle, onMouseDownMoveSelection, isDraggingMoveSelection, onFlashEnd, getSheetName, resizeHandleSize, showSelectionResizeHandles, resizeHandleBorderColor, SelectionTitleComponent, isResizingTable, fillHandleSize, showFillHandle, enableMagicFill, MagicFillComponent, MagicFillContent, readonly, showPasteMenu, fillOptions, onChooseFillType, onOpenFillSeriesDialog, onCloseFillOptions, insertOptions, onChooseInsertOption, hoveredCell, onSplitTextToColumns, onRemoveQuickEdit, onAddQuickEdit, QuickEdit, PasteMenu, SuggestionAction, cachedHoveredSelectionIds, isFillShrink, }: UseSelectionRendererProps) => (props: SelectionProps<SelectionAttributes>) => React.JSX.Element | null;
57
65
  //# sourceMappingURL=use-selection-renderer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-selection-renderer.d.ts","sourceRoot":"","sources":["../../../hooks/use-selection-renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAIlB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,oB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AO,CAAC;IACnB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gGAAgG;IAChG,WAAW,CAAC,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxC,gBAAgB,CAAC,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAAC;IAChD,sBAAsB,CAAC,IAAI,IAAI,CAAC;IAChC,kBAAkB,CAAC,IAAI,IAAI,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC5C,oBAAoB,CAAC,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACxD,oBAAoB,EAAE,eAAe,CAAC,sBAAsB,CAAC,CAAC;IAC9D,WAAW,CAAC,EAAE,aAAa,GAAG,IAAI,CAAC;IACnC,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAC3C,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IACxC,yBAAyB,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAChD;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAyBF,eAAO,MAAM,oBAAoB,GAAI,uwBA0ClC,yBAAyB,aAOhB,cAAc,CAAC,mBAAmB,CAAC,6BAyP9C,CAAC"}
@@ -8,7 +8,24 @@ import { Selection } from "./../components/selection";
8
8
  /** Excel greys the cells a fill-handle drag-back is about to clear. */
9
9
  const FILL_SHRINK_COLOR = "#808080";
10
10
  const FILL_SHRINK_OPACITY = 0.25;
11
- export const useSelectionRenderer = ({ sheetId, selectionCount, selectionBackgroundColor, selectionBorderColor, onSelectionMouseDown, onChangeActiveCell, onChangeSelections, onRequestEditTable, onRequestEditPivotTable, onMouseDownResizeHandle, onMouseDownMoveSelection, isDraggingMoveSelection, onFlashEnd, getSheetName, resizeHandleSize = 6, showSelectionResizeHandles, resizeHandleBorderColor, SelectionTitleComponent, isResizingTable, fillHandleSize, showFillHandle, enableMagicFill, MagicFillComponent, MagicFillContent, readonly, showPasteMenu, fillOptions, onChooseFillType, onOpenFillSeriesDialog, onCloseFillOptions, hoveredCell, onSplitTextToColumns, onRemoveQuickEdit, onAddQuickEdit, QuickEdit, PasteMenu, SuggestionAction, cachedHoveredSelectionIds, isFillShrink = false, }) => {
11
+ /**
12
+ * The Insert Options smart tag renders once: on the first drag-selection that
13
+ * overlaps the inserted band, or on the active cell when there is no
14
+ * drag-selection at all (a lone cell that became part of the band).
15
+ */
16
+ const anchorsInsertOptions = (insertOptions, range, type, index, isEmptySelections) => {
17
+ if (type !== "selection" && !(type === "activeCell" && isEmptySelections)) {
18
+ return false;
19
+ }
20
+ if (type === "selection" && index !== 0)
21
+ return false;
22
+ const bandEnd = insertOptions.start + insertOptions.count - 1;
23
+ return insertOptions.axis === "row"
24
+ ? range.startRowIndex <= bandEnd && range.endRowIndex >= insertOptions.start
25
+ : range.startColumnIndex <= bandEnd &&
26
+ range.endColumnIndex >= insertOptions.start;
27
+ };
28
+ export const useSelectionRenderer = ({ sheetId, selectionCount, selectionBackgroundColor, selectionBorderColor, onSelectionMouseDown, onChangeActiveCell, onChangeSelections, onRequestEditTable, onRequestEditPivotTable, onMouseDownResizeHandle, onMouseDownMoveSelection, isDraggingMoveSelection, onFlashEnd, getSheetName, resizeHandleSize = 6, showSelectionResizeHandles, resizeHandleBorderColor, SelectionTitleComponent, isResizingTable, fillHandleSize, showFillHandle, enableMagicFill, MagicFillComponent, MagicFillContent, readonly, showPasteMenu, fillOptions, onChooseFillType, onOpenFillSeriesDialog, onCloseFillOptions, insertOptions, onChooseInsertOption, hoveredCell, onSplitTextToColumns, onRemoveQuickEdit, onAddQuickEdit, QuickEdit, PasteMenu, SuggestionAction, cachedHoveredSelectionIds, isFillShrink = false, }) => {
12
29
  const formulaMode = useFormulaModeValue();
13
30
  const selectionIndex = useFormulaSelectionIndex();
14
31
  const hoveredCellRef = useRef(hoveredCell);
@@ -98,7 +115,12 @@ export const useSelectionRenderer = ({ sheetId, selectionCount, selectionBackgro
98
115
  fillOptions.sheetId === sheetId &&
99
116
  isAreasEqual(fillOptions.fillSelection.range, range)
100
117
  ? fillOptions
101
- : undefined, onChooseFillType: onChooseFillType, onOpenFillSeriesDialog: onOpenFillSeriesDialog, onCloseFillOptions: onCloseFillOptions, sheetId: sheetId, MagicFillContent: MagicFillContent, QuickEdit: QuickEdit, PasteMenu: PasteMenu, SuggestionAction: SuggestionAction, onSplitTextToColumns: (delimiter) => {
118
+ : undefined, onChooseFillType: onChooseFillType, onOpenFillSeriesDialog: onOpenFillSeriesDialog, onCloseFillOptions: onCloseFillOptions, insertOptions: insertOptions &&
119
+ range &&
120
+ insertOptions.sheetId === sheetId &&
121
+ anchorsInsertOptions(insertOptions, range, type, index, isEmptySelections)
122
+ ? insertOptions
123
+ : undefined, onChooseInsertOption: onChooseInsertOption, sheetId: sheetId, MagicFillContent: MagicFillContent, QuickEdit: QuickEdit, PasteMenu: PasteMenu, SuggestionAction: SuggestionAction, onSplitTextToColumns: (delimiter) => {
102
124
  // Active cell
103
125
  const newActiveCell = range
104
126
  ? {
@@ -143,6 +165,8 @@ export const useSelectionRenderer = ({ sheetId, selectionCount, selectionBackgro
143
165
  onChooseFillType,
144
166
  onOpenFillSeriesDialog,
145
167
  onCloseFillOptions,
168
+ insertOptions,
169
+ onChooseInsertOption,
146
170
  onSplitTextToColumns,
147
171
  MagicFillContent,
148
172
  QuickEdit,
@@ -1 +1 @@
1
- {"version":3,"file":"use-selection-resize.d.ts","sourceRoot":"","sources":["../../../hooks/use-selection-resize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EACb,SAAS,EACT,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAA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OAAO,GAAG,SAAS,GAClC,aAAa,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC,aAAa,CAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAC9C;;;;OAIG;IACH,YAAY,CACV,IAAI,EAAE,qBAAqB,EAC3B,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,GACxB,IAAI,GAAG,SAAS,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,WAAW,EAAE,WAU/C,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,wFAMhC,uBAAuB,SAmIlB,KAAK,CAAC,YAAY,CAAC,cAAc,CAAC,SAmDzC,CAAC"}
@@ -1,4 +1,4 @@
1
- import { cellRangeToBounds } from "@rowsncolumns/grid";
1
+ import { cellRangeToBounds, getOwnerDocument } from "@rowsncolumns/grid";
2
2
  import isNil from "lodash/isNil";
3
3
  import { useCallback, useRef } from "react";
4
4
  import { useActiveEditor, useEditingCellCoordinate, useGetAddressFromSelection, useGetSelectionsFromFormula, } from "../atoms";
@@ -22,6 +22,8 @@ export const useSelectionResize = ({ resizeHandleSize = 6, tokenizer, getCellCoo
22
22
  const selectionIndexRef = useRef(undefined);
23
23
  const isDraggingRef = useRef(false);
24
24
  const anchorCell = useRef(undefined);
25
+ /** Document the in-flight gesture listens on (the grid may live in a popout window) */
26
+ const gestureDocumentRef = useRef(null);
25
27
  const activeEditor = useActiveEditor();
26
28
  const getSelectionToAddress = useGetAddressFromSelection();
27
29
  const getSelectionsFromFormula = useGetSelectionsFromFormula();
@@ -115,8 +117,10 @@ export const useSelectionResize = ({ resizeHandleSize = 6, tokenizer, getCellCoo
115
117
  activeEditor?.focus();
116
118
  isDraggingRef.current = false;
117
119
  anchorCell.current = undefined;
118
- document.removeEventListener("pointermove", onMouseMove);
119
- document.removeEventListener("pointerup", onMouseUp);
120
+ const ownerDocument = gestureDocumentRef.current ?? document;
121
+ gestureDocumentRef.current = null;
122
+ ownerDocument.removeEventListener("pointermove", onMouseMove);
123
+ ownerDocument.removeEventListener("pointerup", onMouseUp);
120
124
  }, [activeEditor, onMouseMove]);
121
125
  // Mousedown
122
126
  const onMouseDownResizeHandle = useCallback((e) => {
@@ -144,8 +148,10 @@ export const useSelectionResize = ({ resizeHandleSize = 6, tokenizer, getCellCoo
144
148
  catch {
145
149
  // jsdom / older browsers without pointer capture
146
150
  }
147
- document.addEventListener("pointermove", onMouseMove);
148
- document.addEventListener("pointerup", onMouseUp);
151
+ const ownerDocument = getOwnerDocument(e.currentTarget) ?? document;
152
+ gestureDocumentRef.current = ownerDocument;
153
+ ownerDocument.addEventListener("pointermove", onMouseMove);
154
+ ownerDocument.addEventListener("pointerup", onMouseUp);
149
155
  }
150
156
  // Focus
151
157
  activeEditor?.focus();
@@ -144,6 +144,18 @@ export type UseSelectionOptions<T extends AreaStyle = AreaStyle> = {
144
144
  * When selection is moved
145
145
  */
146
146
  onMoveSelection?: (sheetId: number, from: SelectionArea<T>, to: SelectionArea<T>) => void;
147
+ /**
148
+ * Shift+drag of the selection border (Excel's I-beam insert): the destination
149
+ * band is displaced and the block inserted, never overwriting. Falls back to
150
+ * `onMoveSelection` when absent.
151
+ */
152
+ onInsertCutCells?: (sheetId: number, from: SelectionArea<T>, to: SelectionArea<T>) => void;
153
+ /**
154
+ * Asks the user before a plain drag-move overwrites non-empty destination
155
+ * cells (Excel: "There's already data here. Do you want to replace it?").
156
+ * Resolves `false` to cancel the move. Defaults to `window.confirm`.
157
+ */
158
+ confirmMoveOverwrite?: (message: string) => boolean | Promise<boolean>;
147
159
  /**
148
160
  * Get cell coords from x, y
149
161
  * @param x
@@ -195,11 +207,7 @@ export type UseSelectionOptions<T extends AreaStyle = AreaStyle> = {
195
207
  isColumnHeader(index: number): boolean;
196
208
  };
197
209
  export type NewSelectionMode = "clear" | "modify" | "append";
198
- /**
199
- * Hook to enable selection in datagrid
200
- * @param initialSelection
201
- */
202
- export declare const useSelection: <T extends AreaStyle>({ sheetId, activeCell, onChangeActiveCell, selections, onChangeSelections, columnCount, rowCount, selectionPolicy, newSelectionMode, allowDeselectSelection, onFill, onFillHandleRelease, onFillShrink, isHiddenRow, isHiddenColumn, alwaysScrollToActiveCell, selectionTopBound, selectionBottomBound, selectionLeftBound, selectionRightBound, mouseDownInterceptor, mouseMoveInterceptor, mergedCells, canSelectionSpanMergedCells, getValue, onMoveSelection, getCellCoordsFromOffset, getCellBounds, getViewPort, focus, scrollToCell, isMergedCell, enableSelectOnEnterKey, formulaMode, isTouchDevice, getDataRowCount, isRowHeader, isColumnHeader, enableDataBoundaryNavigation, }: UseSelectionOptions<T>) => {
210
+ export declare const useSelection: <T extends AreaStyle>({ sheetId, activeCell, onChangeActiveCell, selections, onChangeSelections, columnCount, rowCount, selectionPolicy, newSelectionMode, allowDeselectSelection, onFill, onFillHandleRelease, onFillShrink, onInsertCutCells, confirmMoveOverwrite, isHiddenRow, isHiddenColumn, alwaysScrollToActiveCell, selectionTopBound, selectionBottomBound, selectionLeftBound, selectionRightBound, mouseDownInterceptor, mouseMoveInterceptor, mergedCells, canSelectionSpanMergedCells, getValue, onMoveSelection, getCellCoordsFromOffset, getCellBounds, getViewPort, focus, scrollToCell, isMergedCell, enableSelectOnEnterKey, formulaMode, isTouchDevice, getDataRowCount, isRowHeader, isColumnHeader, enableDataBoundaryNavigation, }: UseSelectionOptions<T>) => {
203
211
  isDragging: boolean;
204
212
  draggedSelection: SelectionArea<T> | undefined;
205
213
  initialDraggedSelection: SelectionArea<T> | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"use-selection.d.ts","sourceRoot":"","sources":["../../../hooks/use-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,SAAS,EACT,UAAU,EACV,qBAAqB,EACrB,aAAa,EACb,eAAe,EACf,aAAa,EACd,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EACL,KAAK,EAcN,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAA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AU,CAAC,YAAY;mBAsL1D,KAAK,CAAC,aAAa,GAAG,UAAU,CAAC,aAAa;0BAv9B1C,aAAa,QAAO,aAAa;+BAq2CrC,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC;iCA4ahC,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC;;;;8BA73D3B,aAAa,kBAAkB,OAAO;;6BA+DvC,aAAa,QAAO,aAAa;;;6BAoL5B,MAAM,UACP,aAAa,kCAEb,KAAK;;6CAq/CT,aAAa,GAAG,SAAS,cACnB,aAAa,EAAE,GAAG,SAAS;mCAtxDjC,aAAa,OAAO,aAAa;;;;;;gCAisB3B,MAAM,GAAG,SAAS;gDA4pCpB,MAAM,aAAa,aAAa,KAAG,SAAS;CAgP3D,CAAC"}
@@ -1,9 +1,10 @@
1
1
  import { findLastContentfulCell, isNull } from "@rowsncolumns/grid";
2
2
  import { cellToArea } from "@rowsncolumns/grid";
3
- import { useIsomorphicLayoutEffect } from "@rowsncolumns/grid";
3
+ import { getOwnerDocument, useIsomorphicLayoutEffect } from "@rowsncolumns/grid";
4
4
  import { Align, cellIdentifier, cellRangeToBounds, clampCellCoords, clampIndex, Direction, findNextCellInDataRegion, findNextCellWithinBounds, getBoundedCells, isAreasEqual, isEqualCells, MouseButtonCodes, newSelectionFromDrag, selectionSpansCells, } from "@rowsncolumns/grid";
5
5
  import { useCallback, useReducer, useRef, useState } from "react";
6
6
  import { scheduleImmediatePriorityCallback, scheduleNormalPriorityCallback, } from "../api/scheduler";
7
+ import { MOVE_OVERWRITE_PROMPT, needsOverwritePrompt } from "../api/move-overwrite";
7
8
  import { DEFAULT_ARRAY } from "../config";
8
9
  import { isMac } from "../helpers";
9
10
  import { useCallbackRef } from "./use-callback-ref";
@@ -80,7 +81,11 @@ const fillShrinkFor = (selection, coords) => {
80
81
  * Hook to enable selection in datagrid
81
82
  * @param initialSelection
82
83
  */
83
- export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selections, onChangeSelections, columnCount = 0, rowCount = 0, selectionPolicy = "multiple", newSelectionMode = "clear", allowDeselectSelection = true, onFill, onFillHandleRelease, onFillShrink, isHiddenRow = defaultIsHidden, isHiddenColumn = defaultIsHidden, alwaysScrollToActiveCell = true, selectionTopBound = 0, selectionBottomBound = rowCount, selectionLeftBound = 0, selectionRightBound = columnCount, mouseDownInterceptor, mouseMoveInterceptor, mergedCells = DEFAULT_ARRAY, canSelectionSpanMergedCells = defaultSelectionSpan, getValue, onMoveSelection, getCellCoordsFromOffset, getCellBounds, getViewPort, focus, scrollToCell, isMergedCell, enableSelectOnEnterKey, formulaMode, isTouchDevice, getDataRowCount, isRowHeader, isColumnHeader, enableDataBoundaryNavigation = false, }) => {
84
+ /** Overwrite prompt used when the host mounts no `MoveOverwriteConfirmDialogHost`. */
85
+ const defaultConfirmMoveOverwrite = (message) => typeof window === "undefined" || typeof window.confirm !== "function"
86
+ ? true
87
+ : window.confirm(message);
88
+ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selections, onChangeSelections, columnCount = 0, rowCount = 0, selectionPolicy = "multiple", newSelectionMode = "clear", allowDeselectSelection = true, onFill, onFillHandleRelease, onFillShrink, onInsertCutCells, confirmMoveOverwrite = defaultConfirmMoveOverwrite, isHiddenRow = defaultIsHidden, isHiddenColumn = defaultIsHidden, alwaysScrollToActiveCell = true, selectionTopBound = 0, selectionBottomBound = rowCount, selectionLeftBound = 0, selectionRightBound = columnCount, mouseDownInterceptor, mouseMoveInterceptor, mergedCells = DEFAULT_ARRAY, canSelectionSpanMergedCells = defaultSelectionSpan, getValue, onMoveSelection, getCellCoordsFromOffset, getCellBounds, getViewPort, focus, scrollToCell, isMergedCell, enableSelectOnEnterKey, formulaMode, isTouchDevice, getDataRowCount, isRowHeader, isColumnHeader, enableDataBoundaryNavigation = false, }) => {
84
89
  const [fillSelection, setFillSelection] = useState();
85
90
  const [fillShrink, setFillShrink] = useState();
86
91
  const fillShrinkRef = useRef(undefined);
@@ -100,24 +105,35 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
100
105
  * release always fires `contextmenu`; neither may reach the grid's cell
101
106
  * context menu while the user is dragging the fill handle.
102
107
  */
108
+ /**
109
+ * Documents the in-flight gestures listen on. The grid may render into a
110
+ * popout window, whose document is not the bundle's global `document`; a
111
+ * gesture binds its move/up listeners to the document of the element it
112
+ * started on and unbinds from that same document.
113
+ */
114
+ const selectionDocumentRef = useRef(null);
115
+ const fillDocumentRef = useRef(null);
116
+ const dragSelectionDocumentRef = useRef(null);
117
+ const tapDocumentRef = useRef(null);
103
118
  const contextMenuSuppressorRef = useRef(null);
104
119
  const releaseContextMenuSuppressor = useCallback(() => {
105
- const handler = contextMenuSuppressorRef.current;
106
- if (!handler)
120
+ const suppressor = contextMenuSuppressorRef.current;
121
+ if (!suppressor)
107
122
  return;
108
123
  contextMenuSuppressorRef.current = null;
109
- document.removeEventListener("contextmenu", handler, true);
124
+ suppressor.ownerDocument.removeEventListener("contextmenu", suppressor.handler, true);
110
125
  }, []);
111
126
  const suppressNextContextMenu = useCallback(() => {
112
127
  if (contextMenuSuppressorRef.current)
113
128
  return;
129
+ const ownerDocument = fillDocumentRef.current ?? document;
114
130
  const handler = (e) => {
115
131
  e.preventDefault();
116
132
  e.stopPropagation();
117
133
  releaseContextMenuSuppressor();
118
134
  };
119
- contextMenuSuppressorRef.current = handler;
120
- document.addEventListener("contextmenu", handler, true);
135
+ contextMenuSuppressorRef.current = { handler, ownerDocument };
136
+ ownerDocument.addEventListener("contextmenu", handler, true);
121
137
  }, [releaseContextMenuSuppressor]);
122
138
  const selectionsRef = useRef([]);
123
139
  const fillSelectionRef = useRef(undefined);
@@ -344,9 +360,11 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
344
360
  const handleMouseUp = useCallback(() => {
345
361
  /* Reset selection mode */
346
362
  isSelecting.current = false;
347
- /* Remove listener */
348
- document.removeEventListener("mousemove", handleMouseMove);
349
- document.removeEventListener("mouseup", handleMouseUp);
363
+ /* Remove listener from the document the gesture started on */
364
+ const ownerDocument = selectionDocumentRef.current ?? document;
365
+ selectionDocumentRef.current = null;
366
+ ownerDocument.removeEventListener("mousemove", handleMouseMove);
367
+ ownerDocument.removeEventListener("mouseup", handleMouseUp);
350
368
  /* Update last selection */
351
369
  const curSelections = selectionsRef.current;
352
370
  const len = curSelections.length;
@@ -876,8 +894,10 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
876
894
  const hasSelections = selectionsRef.current.length > 0;
877
895
  const isDeselecting = isMetaKey && allowDeselect;
878
896
  if (!isContextMenuClick && selectionPolicy !== "single") {
879
- document.addEventListener("mouseup", handleMouseUp);
880
- document.addEventListener("mousemove", handleMouseMove);
897
+ const ownerDocument = getOwnerDocument(e.currentTarget ?? e.target) ?? document;
898
+ selectionDocumentRef.current = ownerDocument;
899
+ ownerDocument.addEventListener("mouseup", handleMouseUp);
900
+ ownerDocument.addEventListener("mousemove", handleMouseMove);
881
901
  }
882
902
  /* Activate selection mode */
883
903
  // Disable flag for context menu
@@ -1240,9 +1260,10 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
1240
1260
  isFilling.current = false;
1241
1261
  const toggle = isFillToggleModifier(e);
1242
1262
  const button = fillButtonRef.current;
1243
- /* Remove listener */
1244
- document.removeEventListener("mousemove", handleFillMouseMove);
1245
- document.removeEventListener("mouseup", handleFillMouseUp);
1263
+ /* Remove listener from the document the gesture started on */
1264
+ const ownerDocument = fillDocumentRef.current ?? document;
1265
+ ownerDocument.removeEventListener("mousemove", handleFillMouseMove);
1266
+ ownerDocument.removeEventListener("mouseup", handleFillMouseUp);
1246
1267
  // The right-button (or macOS Ctrl+click) `contextmenu` event follows this
1247
1268
  // mouseup; keep swallowing it for one tick, then drop the suppressor so a
1248
1269
  // later, unrelated right-click still opens the cell context menu.
@@ -1336,6 +1357,8 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
1336
1357
  const handleFillMouseDown = useCallback((e) => {
1337
1358
  e.stopPropagation();
1338
1359
  e.preventDefault();
1360
+ const ownerDocument = getOwnerDocument(e.currentTarget) ?? document;
1361
+ fillDocumentRef.current = ownerDocument;
1339
1362
  const isRightButton = e.button === MouseButtonCodes.right;
1340
1363
  fillButtonRef.current = isRightButton ? "right" : "left";
1341
1364
  // Ctrl+drag on the handle must never become the macOS Ctrl+click
@@ -1345,8 +1368,8 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
1345
1368
  suppressNextContextMenu();
1346
1369
  }
1347
1370
  isFilling.current = true;
1348
- document.addEventListener("mousemove", handleFillMouseMove);
1349
- document.addEventListener("mouseup", handleFillMouseUp);
1371
+ ownerDocument.addEventListener("mousemove", handleFillMouseMove);
1372
+ ownerDocument.addEventListener("mouseup", handleFillMouseUp);
1350
1373
  }, [handleFillMouseMove, handleFillMouseUp, suppressNextContextMenu]);
1351
1374
  /**
1352
1375
  * Remove the last selection from state
@@ -1398,9 +1421,12 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
1398
1421
  /**
1399
1422
  * When drag/drop is complete
1400
1423
  */
1401
- const handleSelectionMouseUp = useCallback(() => {
1424
+ const handleSelectionMouseUp = useCallback((e) => {
1402
1425
  const fromSelection = initialDraggedSelection.current;
1403
1426
  const toSelection = draggedSelection.current;
1427
+ // Excel reads the modifier at RELEASE: Shift → insert between existing cells (I-beam),
1428
+ // no modifier → overwrite (after the data prompt).
1429
+ const insertMode = e.shiftKey;
1404
1430
  /**
1405
1431
  * If the from and to selection area
1406
1432
  */
@@ -1436,7 +1462,32 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
1436
1462
  if (fromSelection &&
1437
1463
  toSelection &&
1438
1464
  !isAreasEqual(fromSelection.range, toSelection.range)) {
1439
- onMoveSelection?.(sheetId, fromSelection, toSelection);
1465
+ if (insertMode && onInsertCutCells) {
1466
+ // Shift+drag inserts (displaces the destination band) — Excel shows no prompt.
1467
+ onInsertCutCells(sheetId, fromSelection, toSelection);
1468
+ }
1469
+ else if (needsOverwritePrompt(fromSelection.range, toSelection.range, (rowIndex, columnIndex) => !isNull(getValue(sheetId, rowIndex, columnIndex)))) {
1470
+ // The destination holds data the block would overwrite: Excel asks first. The
1471
+ // selection has already followed the drop; Cancel puts it back on the source.
1472
+ const previousSelections = selectionsRef.current;
1473
+ Promise.resolve(confirmMoveOverwrite(MOVE_OVERWRITE_PROMPT)).then((replace) => {
1474
+ if (replace) {
1475
+ onMoveSelection?.(sheetId, fromSelection, toSelection);
1476
+ return;
1477
+ }
1478
+ onChangeActiveCell?.(sheetId, {
1479
+ rowIndex: fromSelection.range.startRowIndex,
1480
+ columnIndex: fromSelection.range.startColumnIndex,
1481
+ });
1482
+ onChangeSelections?.(selectionSpansCells(fromSelection.range)
1483
+ ? previousSelections.map((cur) => isAreasEqual(cur.range, toSelection.range) ? fromSelection : cur)
1484
+ : previousSelections.filter((cur) => !isAreasEqual(cur.range, toSelection.range)));
1485
+ focus();
1486
+ });
1487
+ }
1488
+ else {
1489
+ onMoveSelection?.(sheetId, fromSelection, toSelection);
1490
+ }
1440
1491
  }
1441
1492
  /* Focus on the grid */
1442
1493
  focus();
@@ -1445,14 +1496,19 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
1445
1496
  draggedSelection.current = void 0;
1446
1497
  draggedSelectionIndex.current = void 0;
1447
1498
  hasUserMovedSelection.current = false;
1448
- /* Remove event handlers */
1449
- document.removeEventListener("mouseup", handleSelectionMouseUp);
1450
- document.removeEventListener("mousemove", handleSelectionMouseMove);
1499
+ /* Remove event handlers from the document the gesture started on */
1500
+ const ownerDocument = dragSelectionDocumentRef.current ?? document;
1501
+ dragSelectionDocumentRef.current = null;
1502
+ ownerDocument.removeEventListener("mouseup", handleSelectionMouseUp);
1503
+ ownerDocument.removeEventListener("mousemove", handleSelectionMouseMove);
1451
1504
  /* Force render */
1452
1505
  forceRender();
1453
1506
  }, [
1454
1507
  sheetId,
1455
1508
  onMoveSelection,
1509
+ onInsertCutCells,
1510
+ confirmMoveOverwrite,
1511
+ getValue,
1456
1512
  handleSelectionMouseMove,
1457
1513
  focus,
1458
1514
  onChangeActiveCell,
@@ -1492,9 +1548,11 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
1492
1548
  }
1493
1549
  /* Set dragging flag */
1494
1550
  isDragging.current = true;
1495
- /* Listen to mousemove and mousedown events */
1496
- document.addEventListener("mouseup", handleSelectionMouseUp);
1497
- document.addEventListener("mousemove", handleSelectionMouseMove);
1551
+ /* Listen on the document the gesture started on */
1552
+ const ownerDocument = getOwnerDocument(e.currentTarget) ?? document;
1553
+ dragSelectionDocumentRef.current = ownerDocument;
1554
+ ownerDocument.addEventListener("mouseup", handleSelectionMouseUp);
1555
+ ownerDocument.addEventListener("mousemove", handleSelectionMouseMove);
1498
1556
  /* Force a re-render */
1499
1557
  forceRender();
1500
1558
  }, [
@@ -1583,12 +1641,16 @@ export const useSelection = ({ sheetId, activeCell, onChangeActiveCell, selectio
1583
1641
  handleMouseDown(event);
1584
1642
  handleMouseUp();
1585
1643
  }
1586
- document.removeEventListener("pointerup", onPointerUp);
1644
+ const ownerDocument = tapDocumentRef.current ?? document;
1645
+ tapDocumentRef.current = null;
1646
+ ownerDocument.removeEventListener("pointerup", onPointerUp);
1587
1647
  }, [handleMouseDown, handleMouseUp]);
1588
1648
  const onPointerDown = useCallback((event) => {
1589
1649
  startTimeRef.current = Date.now();
1590
1650
  startPosRef.current = { x: event.clientX, y: event.clientY };
1591
- document.addEventListener("pointerup", onPointerUp);
1651
+ const ownerDocument = getOwnerDocument(event.currentTarget) ?? document;
1652
+ tapDocumentRef.current = ownerDocument;
1653
+ ownerDocument.addEventListener("pointerup", onPointerUp);
1592
1654
  }, [onPointerUp]);
1593
1655
  // Add a ref. makeEditable renders way too often
1594
1656
  const handleKeyDownRef = useCallbackRef(handleKeyDown);
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-resizer.d.ts","sourceRoot":"","sources":["../../../hooks/use-table-resizer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EACb,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAK5B,OAAO,KAAiD,MAAM,OAAO,CAAC;AAEtE,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE1C,KAAK,oBAAoB,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC;IACrB,KAAK,EAAE,gBAAgB,CAAC;IACxB,YAAY,EAAE,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAClE,eAAe,EAAE,CACf,MAAM,EAAE,aAAa,EACrB,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,KAChC,IAAI,CAAC;IACV,eAAe,IAAI,IAAI,CAAC;IACxB,uBAAuB,EAAE,CACvB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,aAAa,CAAC,EAAE,OAAO,KACpB,aAAa,GAAG,SAAS,CAAC;IAC/B,aAAa,CAAC,EAAE,eAAe,CAAC,eAAe,CAAC,CAAC;IACjD,YAAY,EAAE,CACZ,IAAI,EAAE,qBAAqB,EAC3B,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,KACtB,IAAI,GAAG,SAAS,CAAC;IACtB,UAAU,IAAI,IAAI,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,+IAW7B,oBAAoB;;;CAyHtB,CAAC;AAYF,eAAO,MAAM,kBAAkB,wKAa7B,CAAC"}
1
+ {"version":3,"file":"use-table-resizer.d.ts","sourceRoot":"","sources":["../../../hooks/use-table-resizer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EACb,qBAAqB,EACtB,MAAM,oBAAoB,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