@rowsncolumns/spreadsheet-state 28.0.76 → 29.1.0

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 (633) hide show
  1. package/dist/cjs/api/anchored-objects.d.ts +122 -6
  2. package/dist/cjs/api/anchored-objects.d.ts.map +1 -1
  3. package/dist/cjs/api/anchored-objects.js +464 -43
  4. package/dist/cjs/api/copy-paste.d.ts +8 -2
  5. package/dist/cjs/api/copy-paste.d.ts.map +1 -1
  6. package/dist/cjs/api/copy-paste.js +4 -4
  7. package/dist/cjs/api/filter.d.ts +15 -1
  8. package/dist/cjs/api/filter.d.ts.map +1 -1
  9. package/dist/cjs/api/filter.js +32 -2
  10. package/dist/cjs/api/formula.d.ts +63 -0
  11. package/dist/cjs/api/formula.d.ts.map +1 -1
  12. package/dist/cjs/api/formula.js +278 -8
  13. package/dist/cjs/api/immer-utils.d.ts +11 -1
  14. package/dist/cjs/api/immer-utils.d.ts.map +1 -1
  15. package/dist/cjs/api/immer-utils.js +17 -1
  16. package/dist/cjs/api/insert-cut-cells.d.ts +35 -0
  17. package/dist/cjs/api/insert-cut-cells.d.ts.map +1 -0
  18. package/dist/cjs/api/insert-cut-cells.js +60 -0
  19. package/dist/cjs/api/merges.d.ts +8 -0
  20. package/dist/cjs/api/merges.d.ts.map +1 -1
  21. package/dist/cjs/api/merges.js +11 -0
  22. package/dist/cjs/api/paint-format.d.ts +22 -1
  23. package/dist/cjs/api/paint-format.d.ts.map +1 -1
  24. package/dist/cjs/api/paint-format.js +57 -1
  25. package/dist/cjs/api/sort.d.ts +23 -1
  26. package/dist/cjs/api/sort.d.ts.map +1 -1
  27. package/dist/cjs/api/sort.js +52 -6
  28. package/dist/cjs/api/structural-guards.d.ts +57 -0
  29. package/dist/cjs/api/structural-guards.d.ts.map +1 -1
  30. package/dist/cjs/api/structural-guards.js +93 -1
  31. package/dist/cjs/api/structural-table-refs.d.ts +58 -3
  32. package/dist/cjs/api/structural-table-refs.d.ts.map +1 -1
  33. package/dist/cjs/api/structural-table-refs.js +177 -16
  34. package/dist/cjs/api/subtotal.d.ts +20 -13
  35. package/dist/cjs/api/subtotal.d.ts.map +1 -1
  36. package/dist/cjs/api/subtotal.js +26 -19
  37. package/dist/cjs/api/table.d.ts +26 -2
  38. package/dist/cjs/api/table.d.ts.map +1 -1
  39. package/dist/cjs/api/table.js +93 -60
  40. package/dist/cjs/api/validation.d.ts.map +1 -1
  41. package/dist/cjs/api/validation.js +53 -8
  42. package/dist/cjs/atoms/creating-table.atom.d.ts +22 -0
  43. package/dist/cjs/atoms/creating-table.atom.d.ts.map +1 -0
  44. package/dist/cjs/atoms/creating-table.atom.js +4 -0
  45. package/dist/cjs/atoms/dialog-state.atom.d.ts +8 -0
  46. package/dist/cjs/atoms/dialog-state.atom.d.ts.map +1 -1
  47. package/dist/cjs/atoms/dialog-state.atom.js +28 -0
  48. package/dist/cjs/atoms/editing-slicer.atom.d.ts +9 -0
  49. package/dist/cjs/atoms/editing-slicer.atom.d.ts.map +1 -0
  50. package/dist/cjs/atoms/editing-slicer.atom.js +6 -0
  51. package/dist/cjs/atoms/index.d.ts +4 -0
  52. package/dist/cjs/atoms/index.d.ts.map +1 -1
  53. package/dist/cjs/atoms/index.js +4 -0
  54. package/dist/cjs/atoms/inserting-slicer.atom.d.ts +8 -0
  55. package/dist/cjs/atoms/inserting-slicer.atom.d.ts.map +1 -0
  56. package/dist/cjs/atoms/inserting-slicer.atom.js +5 -0
  57. package/dist/cjs/atoms/resizing-table.atom.d.ts +8 -0
  58. package/dist/cjs/atoms/resizing-table.atom.d.ts.map +1 -0
  59. package/dist/cjs/atoms/resizing-table.atom.js +5 -0
  60. package/dist/cjs/commands.d.ts +138 -2
  61. package/dist/cjs/commands.d.ts.map +1 -1
  62. package/dist/cjs/components/editors/embed-editor.d.ts +4 -2
  63. package/dist/cjs/components/editors/embed-editor.d.ts.map +1 -1
  64. package/dist/cjs/components/editors/embed-editor.js +38 -9
  65. package/dist/cjs/components/editors/slicer-editor.d.ts +15 -0
  66. package/dist/cjs/components/editors/slicer-editor.d.ts.map +1 -0
  67. package/dist/cjs/components/editors/slicer-editor.js +87 -0
  68. package/dist/cjs/components/editors/table-editor.d.ts +58 -2
  69. package/dist/cjs/components/editors/table-editor.d.ts.map +1 -1
  70. package/dist/cjs/components/editors/table-editor.js +261 -20
  71. package/dist/cjs/components/index.d.ts +1 -0
  72. package/dist/cjs/components/index.d.ts.map +1 -1
  73. package/dist/cjs/components/index.js +1 -0
  74. package/dist/cjs/constants.d.ts +9 -1
  75. package/dist/cjs/constants.d.ts.map +1 -1
  76. package/dist/cjs/constants.js +12 -0
  77. package/dist/cjs/generated-names.d.ts +13 -3
  78. package/dist/cjs/generated-names.d.ts.map +1 -1
  79. package/dist/cjs/generated-names.js +3 -1
  80. package/dist/cjs/helpers.d.ts +5 -0
  81. package/dist/cjs/helpers.d.ts.map +1 -1
  82. package/dist/cjs/helpers.js +10 -1
  83. package/dist/cjs/hooks/use-on-change-batch.d.ts +19 -2
  84. package/dist/cjs/hooks/use-on-change-batch.d.ts.map +1 -1
  85. package/dist/cjs/hooks/use-on-change-batch.js +43 -35
  86. package/dist/cjs/hooks/use-on-change-calculated-column.d.ts +10 -1
  87. package/dist/cjs/hooks/use-on-change-calculated-column.d.ts.map +1 -1
  88. package/dist/cjs/hooks/use-on-change-calculated-column.js +17 -5
  89. package/dist/cjs/hooks/use-on-change-table-column.d.ts +6 -1
  90. package/dist/cjs/hooks/use-on-change-table-column.d.ts.map +1 -1
  91. package/dist/cjs/hooks/use-on-change-table-column.js +17 -5
  92. package/dist/cjs/hooks/use-on-change.d.ts +36 -3
  93. package/dist/cjs/hooks/use-on-change.d.ts.map +1 -1
  94. package/dist/cjs/hooks/use-on-change.js +218 -136
  95. package/dist/cjs/hooks/use-on-copy.d.ts +1 -1
  96. package/dist/cjs/hooks/use-on-copy.d.ts.map +1 -1
  97. package/dist/cjs/hooks/use-on-copy.js +2 -3
  98. package/dist/cjs/hooks/use-on-create-custom-table-style.d.ts +17 -0
  99. package/dist/cjs/hooks/use-on-create-custom-table-style.d.ts.map +1 -0
  100. package/dist/cjs/hooks/use-on-create-custom-table-style.js +28 -0
  101. package/dist/cjs/hooks/use-on-create-named-range.d.ts +4 -2
  102. package/dist/cjs/hooks/use-on-create-named-range.d.ts.map +1 -1
  103. package/dist/cjs/hooks/use-on-create-named-range.js +11 -1
  104. package/dist/cjs/hooks/use-on-delete-cells-shift-left.d.ts +2 -1
  105. package/dist/cjs/hooks/use-on-delete-cells-shift-left.d.ts.map +1 -1
  106. package/dist/cjs/hooks/use-on-delete-cells-shift-left.js +3 -1
  107. package/dist/cjs/hooks/use-on-delete-cells-shift-up.d.ts +2 -1
  108. package/dist/cjs/hooks/use-on-delete-cells-shift-up.d.ts.map +1 -1
  109. package/dist/cjs/hooks/use-on-delete-cells-shift-up.js +3 -1
  110. package/dist/cjs/hooks/use-on-delete-column.d.ts +2 -1
  111. package/dist/cjs/hooks/use-on-delete-column.d.ts.map +1 -1
  112. package/dist/cjs/hooks/use-on-delete-column.js +3 -1
  113. package/dist/cjs/hooks/use-on-delete-row.d.ts +2 -1
  114. package/dist/cjs/hooks/use-on-delete-row.d.ts.map +1 -1
  115. package/dist/cjs/hooks/use-on-delete-row.js +3 -1
  116. package/dist/cjs/hooks/use-on-delete-sheet.d.ts +9 -1
  117. package/dist/cjs/hooks/use-on-delete-sheet.d.ts.map +1 -1
  118. package/dist/cjs/hooks/use-on-delete-sheet.js +17 -1
  119. package/dist/cjs/hooks/use-on-delete-table-row.d.ts +4 -1
  120. package/dist/cjs/hooks/use-on-delete-table-row.d.ts.map +1 -1
  121. package/dist/cjs/hooks/use-on-delete-table-row.js +19 -1
  122. package/dist/cjs/hooks/use-on-delete.d.ts +5 -2
  123. package/dist/cjs/hooks/use-on-delete.d.ts.map +1 -1
  124. package/dist/cjs/hooks/use-on-delete.js +5 -1
  125. package/dist/cjs/hooks/use-on-embeds.d.ts +7 -4
  126. package/dist/cjs/hooks/use-on-embeds.d.ts.map +1 -1
  127. package/dist/cjs/hooks/use-on-embeds.js +26 -24
  128. package/dist/cjs/hooks/use-on-fill.d.ts +17 -2
  129. package/dist/cjs/hooks/use-on-fill.d.ts.map +1 -1
  130. package/dist/cjs/hooks/use-on-fill.js +29 -15
  131. package/dist/cjs/hooks/use-on-filter-table.d.ts.map +1 -1
  132. package/dist/cjs/hooks/use-on-filter-table.js +209 -103
  133. package/dist/cjs/hooks/use-on-import-excel.d.ts +2 -1
  134. package/dist/cjs/hooks/use-on-import-excel.d.ts.map +1 -1
  135. package/dist/cjs/hooks/use-on-import-excel.js +22 -19
  136. package/dist/cjs/hooks/use-on-insert-cells-shift-down.d.ts +2 -1
  137. package/dist/cjs/hooks/use-on-insert-cells-shift-down.d.ts.map +1 -1
  138. package/dist/cjs/hooks/use-on-insert-cells-shift-down.js +3 -1
  139. package/dist/cjs/hooks/use-on-insert-cells-shift-right.d.ts +2 -1
  140. package/dist/cjs/hooks/use-on-insert-cells-shift-right.d.ts.map +1 -1
  141. package/dist/cjs/hooks/use-on-insert-cells-shift-right.js +3 -1
  142. package/dist/cjs/hooks/use-on-insert-column.d.ts +2 -1
  143. package/dist/cjs/hooks/use-on-insert-column.d.ts.map +1 -1
  144. package/dist/cjs/hooks/use-on-insert-column.js +3 -1
  145. package/dist/cjs/hooks/use-on-insert-row.d.ts +2 -1
  146. package/dist/cjs/hooks/use-on-insert-row.d.ts.map +1 -1
  147. package/dist/cjs/hooks/use-on-insert-row.js +3 -1
  148. package/dist/cjs/hooks/use-on-insert-table-row.d.ts +5 -2
  149. package/dist/cjs/hooks/use-on-insert-table-row.d.ts.map +1 -1
  150. package/dist/cjs/hooks/use-on-insert-table-row.js +19 -1
  151. package/dist/cjs/hooks/use-on-merge-unmerge-cells.d.ts +3 -2
  152. package/dist/cjs/hooks/use-on-merge-unmerge-cells.d.ts.map +1 -1
  153. package/dist/cjs/hooks/use-on-merge-unmerge-cells.js +14 -1
  154. package/dist/cjs/hooks/use-on-move-columns.d.ts +4 -1
  155. package/dist/cjs/hooks/use-on-move-columns.d.ts.map +1 -1
  156. package/dist/cjs/hooks/use-on-move-columns.js +28 -6
  157. package/dist/cjs/hooks/use-on-move-rows.d.ts +18 -1
  158. package/dist/cjs/hooks/use-on-move-rows.d.ts.map +1 -1
  159. package/dist/cjs/hooks/use-on-move-rows.js +44 -6
  160. package/dist/cjs/hooks/use-on-move-selection.d.ts +9 -2
  161. package/dist/cjs/hooks/use-on-move-selection.d.ts.map +1 -1
  162. package/dist/cjs/hooks/use-on-move-selection.js +101 -25
  163. package/dist/cjs/hooks/use-on-paste.d.ts +33 -2
  164. package/dist/cjs/hooks/use-on-paste.d.ts.map +1 -1
  165. package/dist/cjs/hooks/use-on-paste.js +1005 -740
  166. package/dist/cjs/hooks/use-on-remove-duplicates.d.ts +5 -2
  167. package/dist/cjs/hooks/use-on-remove-duplicates.d.ts.map +1 -1
  168. package/dist/cjs/hooks/use-on-remove-duplicates.js +5 -1
  169. package/dist/cjs/hooks/use-on-request-create-table.d.ts +13 -0
  170. package/dist/cjs/hooks/use-on-request-create-table.d.ts.map +1 -0
  171. package/dist/cjs/hooks/use-on-request-create-table.js +44 -0
  172. package/dist/cjs/hooks/use-on-request-insert-slicer.d.ts +7 -0
  173. package/dist/cjs/hooks/use-on-request-insert-slicer.d.ts.map +1 -0
  174. package/dist/cjs/hooks/use-on-request-insert-slicer.js +15 -0
  175. package/dist/cjs/hooks/use-on-request-resize-table.d.ts +7 -0
  176. package/dist/cjs/hooks/use-on-request-resize-table.d.ts.map +1 -0
  177. package/dist/cjs/hooks/use-on-request-resize-table.js +15 -0
  178. package/dist/cjs/hooks/use-on-resize-table.d.ts +5 -1
  179. package/dist/cjs/hooks/use-on-resize-table.d.ts.map +1 -1
  180. package/dist/cjs/hooks/use-on-resize-table.js +110 -33
  181. package/dist/cjs/hooks/use-on-sort-column.d.ts +28 -3
  182. package/dist/cjs/hooks/use-on-sort-column.d.ts.map +1 -1
  183. package/dist/cjs/hooks/use-on-sort-column.js +136 -90
  184. package/dist/cjs/hooks/use-on-sort-range.d.ts +26 -3
  185. package/dist/cjs/hooks/use-on-sort-range.d.ts.map +1 -1
  186. package/dist/cjs/hooks/use-on-sort-range.js +113 -67
  187. package/dist/cjs/hooks/use-on-sort-table.d.ts +18 -1
  188. package/dist/cjs/hooks/use-on-sort-table.d.ts.map +1 -1
  189. package/dist/cjs/hooks/use-on-sort-table.js +128 -98
  190. package/dist/cjs/hooks/use-on-subtotal.d.ts +10 -3
  191. package/dist/cjs/hooks/use-on-subtotal.d.ts.map +1 -1
  192. package/dist/cjs/hooks/use-on-subtotal.js +13 -9
  193. package/dist/cjs/hooks/use-on-table.d.ts +39 -7
  194. package/dist/cjs/hooks/use-on-table.d.ts.map +1 -1
  195. package/dist/cjs/hooks/use-on-table.js +257 -49
  196. package/dist/cjs/hooks/use-on-undo-calculated-column.d.ts +23 -0
  197. package/dist/cjs/hooks/use-on-undo-calculated-column.d.ts.map +1 -0
  198. package/dist/cjs/hooks/use-on-undo-calculated-column.js +70 -0
  199. package/dist/cjs/hooks/use-on-undo-table-auto-expansion.d.ts +28 -0
  200. package/dist/cjs/hooks/use-on-undo-table-auto-expansion.d.ts.map +1 -0
  201. package/dist/cjs/hooks/use-on-undo-table-auto-expansion.js +96 -0
  202. package/dist/cjs/hooks/use-on-update-named-range.d.ts +4 -2
  203. package/dist/cjs/hooks/use-on-update-named-range.d.ts.map +1 -1
  204. package/dist/cjs/hooks/use-on-update-named-range.js +13 -1
  205. package/dist/cjs/hooks/use-sheet-properties.d.ts +1 -0
  206. package/dist/cjs/hooks/use-sheet-properties.d.ts.map +1 -1
  207. package/dist/cjs/hooks/use-sheet-properties.js +54 -34
  208. package/dist/cjs/hooks/use-slicers.d.ts +2 -2
  209. package/dist/cjs/hooks/use-slicers.d.ts.map +1 -1
  210. package/dist/cjs/hooks/use-slicers.js +17 -26
  211. package/dist/cjs/hooks/use-sparkline-groups.d.ts +50 -0
  212. package/dist/cjs/hooks/use-sparkline-groups.d.ts.map +1 -0
  213. package/dist/cjs/hooks/use-sparkline-groups.js +192 -0
  214. package/dist/cjs/hooks/use-spreadsheet-state.d.ts +69 -12
  215. package/dist/cjs/hooks/use-spreadsheet-state.d.ts.map +1 -1
  216. package/dist/cjs/hooks/use-spreadsheet-state.js +383 -84
  217. package/dist/cjs/hooks/use-structured-reference.d.ts.map +1 -1
  218. package/dist/cjs/hooks/use-structured-reference.js +17 -0
  219. package/dist/cjs/hooks/use-undo-redo-actions.d.ts +2 -1
  220. package/dist/cjs/hooks/use-undo-redo-actions.d.ts.map +1 -1
  221. package/dist/cjs/hooks/use-undo-redo-actions.js +10 -2
  222. package/dist/cjs/hooks/use-undo-redo.d.ts +12 -0
  223. package/dist/cjs/hooks/use-undo-redo.d.ts.map +1 -1
  224. package/dist/cjs/hooks/use-undo-redo.js +169 -10
  225. package/dist/cjs/hooks/utils/sort-rows.d.ts.map +1 -1
  226. package/dist/cjs/hooks/utils/sort-rows.js +4 -3
  227. package/dist/cjs/index.d.ts +8 -0
  228. package/dist/cjs/index.d.ts.map +1 -1
  229. package/dist/cjs/index.js +9 -0
  230. package/dist/cjs/interface/apply-fill.d.ts +26 -3
  231. package/dist/cjs/interface/apply-fill.d.ts.map +1 -1
  232. package/dist/cjs/interface/apply-fill.js +207 -98
  233. package/dist/cjs/interface/change-batch.d.ts +1 -1
  234. package/dist/cjs/interface/change-batch.d.ts.map +1 -1
  235. package/dist/cjs/interface/change-batch.js +112 -15
  236. package/dist/cjs/interface/change-calculated-column.d.ts +6 -2
  237. package/dist/cjs/interface/change-calculated-column.d.ts.map +1 -1
  238. package/dist/cjs/interface/change-calculated-column.js +87 -17
  239. package/dist/cjs/interface/change-table-column.d.ts +81 -7
  240. package/dist/cjs/interface/change-table-column.d.ts.map +1 -1
  241. package/dist/cjs/interface/change-table-column.js +336 -76
  242. package/dist/cjs/interface/create-table.d.ts +15 -3
  243. package/dist/cjs/interface/create-table.d.ts.map +1 -1
  244. package/dist/cjs/interface/create-table.js +100 -25
  245. package/dist/cjs/interface/delete-cells-shift-left.d.ts +1 -1
  246. package/dist/cjs/interface/delete-cells-shift-left.d.ts.map +1 -1
  247. package/dist/cjs/interface/delete-cells-shift-left.js +10 -1
  248. package/dist/cjs/interface/delete-cells-shift-up.d.ts +1 -1
  249. package/dist/cjs/interface/delete-cells-shift-up.d.ts.map +1 -1
  250. package/dist/cjs/interface/delete-cells-shift-up.js +10 -1
  251. package/dist/cjs/interface/delete-cells.d.ts +1 -1
  252. package/dist/cjs/interface/delete-cells.d.ts.map +1 -1
  253. package/dist/cjs/interface/delete-cells.js +81 -25
  254. package/dist/cjs/interface/delete-column.d.ts +1 -1
  255. package/dist/cjs/interface/delete-column.d.ts.map +1 -1
  256. package/dist/cjs/interface/delete-column.js +29 -22
  257. package/dist/cjs/interface/delete-row.d.ts +1 -1
  258. package/dist/cjs/interface/delete-row.d.ts.map +1 -1
  259. package/dist/cjs/interface/delete-row.js +244 -39
  260. package/dist/cjs/interface/delete-sheet.d.ts +2 -2
  261. package/dist/cjs/interface/delete-sheet.d.ts.map +1 -1
  262. package/dist/cjs/interface/delete-sheet.js +118 -1
  263. package/dist/cjs/interface/delete-table-column.d.ts +1 -1
  264. package/dist/cjs/interface/delete-table-column.d.ts.map +1 -1
  265. package/dist/cjs/interface/delete-table-column.js +11 -1
  266. package/dist/cjs/interface/delete-table-row.d.ts +1 -1
  267. package/dist/cjs/interface/delete-table-row.d.ts.map +1 -1
  268. package/dist/cjs/interface/delete-table-row.js +361 -275
  269. package/dist/cjs/interface/duplicate-sheet.d.ts.map +1 -1
  270. package/dist/cjs/interface/duplicate-sheet.js +83 -31
  271. package/dist/cjs/interface/embeds.d.ts +10 -1
  272. package/dist/cjs/interface/embeds.d.ts.map +1 -1
  273. package/dist/cjs/interface/embeds.js +120 -6
  274. package/dist/cjs/interface/insert-cells-shift-down.d.ts +1 -1
  275. package/dist/cjs/interface/insert-cells-shift-down.d.ts.map +1 -1
  276. package/dist/cjs/interface/insert-cells-shift-down.js +10 -1
  277. package/dist/cjs/interface/insert-cells-shift-right.d.ts +1 -1
  278. package/dist/cjs/interface/insert-cells-shift-right.d.ts.map +1 -1
  279. package/dist/cjs/interface/insert-cells-shift-right.js +10 -1
  280. package/dist/cjs/interface/insert-column.d.ts +2 -2
  281. package/dist/cjs/interface/insert-column.d.ts.map +1 -1
  282. package/dist/cjs/interface/insert-column.js +101 -56
  283. package/dist/cjs/interface/insert-row.d.ts +1 -1
  284. package/dist/cjs/interface/insert-row.d.ts.map +1 -1
  285. package/dist/cjs/interface/insert-row.js +25 -7
  286. package/dist/cjs/interface/insert-table-row.d.ts +2 -1
  287. package/dist/cjs/interface/insert-table-row.d.ts.map +1 -1
  288. package/dist/cjs/interface/insert-table-row.js +70 -19
  289. package/dist/cjs/interface/remove-duplicates.d.ts +1 -1
  290. package/dist/cjs/interface/remove-duplicates.d.ts.map +1 -1
  291. package/dist/cjs/interface/remove-duplicates.js +46 -6
  292. package/dist/cjs/interface/remove-table.d.ts +1 -1
  293. package/dist/cjs/interface/remove-table.d.ts.map +1 -1
  294. package/dist/cjs/interface/remove-table.js +72 -16
  295. package/dist/cjs/interface/slicers.d.ts +12 -1
  296. package/dist/cjs/interface/slicers.d.ts.map +1 -1
  297. package/dist/cjs/interface/slicers.js +47 -2
  298. package/dist/cjs/interface/spreadsheet-interface.d.ts +1 -1
  299. package/dist/cjs/interface/spreadsheet-interface.d.ts.map +1 -1
  300. package/dist/cjs/interface/spreadsheet-interface.js +64 -1
  301. package/dist/cjs/interface/table-totalrow.d.ts +13 -1
  302. package/dist/cjs/interface/table-totalrow.d.ts.map +1 -1
  303. package/dist/cjs/interface/table-totalrow.js +107 -73
  304. package/dist/cjs/interface/table-utils.d.ts +59 -6
  305. package/dist/cjs/interface/table-utils.d.ts.map +1 -1
  306. package/dist/cjs/interface/table-utils.js +211 -15
  307. package/dist/cjs/interface/update-table.d.ts +16 -1
  308. package/dist/cjs/interface/update-table.d.ts.map +1 -1
  309. package/dist/cjs/interface/update-table.js +190 -44
  310. package/dist/cjs/sheet-cell.d.ts.map +1 -1
  311. package/dist/cjs/test-setup.d.ts.map +1 -1
  312. package/dist/cjs/test-setup.js +6 -0
  313. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  314. package/dist/cjs/validation-schema/table.schema.d.ts +11 -0
  315. package/dist/cjs/validation-schema/table.schema.d.ts.map +1 -1
  316. package/dist/cjs/validation-schema/table.schema.js +20 -3
  317. package/dist/esm/api/anchored-objects.d.ts +122 -6
  318. package/dist/esm/api/anchored-objects.d.ts.map +1 -1
  319. package/dist/esm/api/anchored-objects.js +375 -15
  320. package/dist/esm/api/copy-paste.d.ts +8 -2
  321. package/dist/esm/api/copy-paste.d.ts.map +1 -1
  322. package/dist/esm/api/copy-paste.js +4 -4
  323. package/dist/esm/api/filter.d.ts +15 -1
  324. package/dist/esm/api/filter.d.ts.map +1 -1
  325. package/dist/esm/api/filter.js +28 -0
  326. package/dist/esm/api/formula.d.ts +63 -0
  327. package/dist/esm/api/formula.d.ts.map +1 -1
  328. package/dist/esm/api/formula.js +235 -8
  329. package/dist/esm/api/immer-utils.d.ts +11 -1
  330. package/dist/esm/api/immer-utils.d.ts.map +1 -1
  331. package/dist/esm/api/immer-utils.js +16 -0
  332. package/dist/esm/api/insert-cut-cells.d.ts +35 -0
  333. package/dist/esm/api/insert-cut-cells.d.ts.map +1 -0
  334. package/dist/esm/api/insert-cut-cells.js +67 -0
  335. package/dist/esm/api/merges.d.ts +8 -0
  336. package/dist/esm/api/merges.d.ts.map +1 -1
  337. package/dist/esm/api/merges.js +9 -0
  338. package/dist/esm/api/paint-format.d.ts +22 -1
  339. package/dist/esm/api/paint-format.d.ts.map +1 -1
  340. package/dist/esm/api/paint-format.js +44 -1
  341. package/dist/esm/api/sort.d.ts +23 -1
  342. package/dist/esm/api/sort.d.ts.map +1 -1
  343. package/dist/esm/api/sort.js +45 -6
  344. package/dist/esm/api/structural-guards.d.ts +57 -0
  345. package/dist/esm/api/structural-guards.d.ts.map +1 -1
  346. package/dist/esm/api/structural-guards.js +85 -0
  347. package/dist/esm/api/structural-table-refs.d.ts +58 -3
  348. package/dist/esm/api/structural-table-refs.d.ts.map +1 -1
  349. package/dist/esm/api/structural-table-refs.js +126 -6
  350. package/dist/esm/api/subtotal.d.ts +20 -13
  351. package/dist/esm/api/subtotal.d.ts.map +1 -1
  352. package/dist/esm/api/subtotal.js +15 -8
  353. package/dist/esm/api/table.d.ts +26 -2
  354. package/dist/esm/api/table.d.ts.map +1 -1
  355. package/dist/esm/api/table.js +70 -48
  356. package/dist/esm/api/validation.d.ts.map +1 -1
  357. package/dist/esm/api/validation.js +53 -8
  358. package/dist/esm/atoms/creating-table.atom.d.ts +22 -0
  359. package/dist/esm/atoms/creating-table.atom.d.ts.map +1 -0
  360. package/dist/esm/atoms/creating-table.atom.js +4 -0
  361. package/dist/esm/atoms/dialog-state.atom.d.ts +8 -0
  362. package/dist/esm/atoms/dialog-state.atom.d.ts.map +1 -1
  363. package/dist/esm/atoms/dialog-state.atom.js +12 -0
  364. package/dist/esm/atoms/editing-slicer.atom.d.ts +9 -0
  365. package/dist/esm/atoms/editing-slicer.atom.d.ts.map +1 -0
  366. package/dist/esm/atoms/editing-slicer.atom.js +6 -0
  367. package/dist/esm/atoms/index.d.ts +4 -0
  368. package/dist/esm/atoms/index.d.ts.map +1 -1
  369. package/dist/esm/atoms/index.js +4 -0
  370. package/dist/esm/atoms/inserting-slicer.atom.d.ts +8 -0
  371. package/dist/esm/atoms/inserting-slicer.atom.d.ts.map +1 -0
  372. package/dist/esm/atoms/inserting-slicer.atom.js +5 -0
  373. package/dist/esm/atoms/resizing-table.atom.d.ts +8 -0
  374. package/dist/esm/atoms/resizing-table.atom.d.ts.map +1 -0
  375. package/dist/esm/atoms/resizing-table.atom.js +5 -0
  376. package/dist/esm/commands.d.ts +138 -2
  377. package/dist/esm/commands.d.ts.map +1 -1
  378. package/dist/esm/components/editors/embed-editor.d.ts +4 -2
  379. package/dist/esm/components/editors/embed-editor.d.ts.map +1 -1
  380. package/dist/esm/components/editors/embed-editor.js +40 -6
  381. package/dist/esm/components/editors/slicer-editor.d.ts +15 -0
  382. package/dist/esm/components/editors/slicer-editor.d.ts.map +1 -0
  383. package/dist/esm/components/editors/slicer-editor.js +85 -0
  384. package/dist/esm/components/editors/table-editor.d.ts +58 -2
  385. package/dist/esm/components/editors/table-editor.d.ts.map +1 -1
  386. package/dist/esm/components/editors/table-editor.js +243 -19
  387. package/dist/esm/components/index.d.ts +1 -0
  388. package/dist/esm/components/index.d.ts.map +1 -1
  389. package/dist/esm/components/index.js +1 -0
  390. package/dist/esm/constants.d.ts +9 -1
  391. package/dist/esm/constants.d.ts.map +1 -1
  392. package/dist/esm/constants.js +12 -0
  393. package/dist/esm/generated-names.d.ts +13 -3
  394. package/dist/esm/generated-names.d.ts.map +1 -1
  395. package/dist/esm/generated-names.js +3 -1
  396. package/dist/esm/helpers.d.ts +5 -0
  397. package/dist/esm/helpers.d.ts.map +1 -1
  398. package/dist/esm/helpers.js +7 -1
  399. package/dist/esm/hooks/use-on-change-batch.d.ts +19 -2
  400. package/dist/esm/hooks/use-on-change-batch.d.ts.map +1 -1
  401. package/dist/esm/hooks/use-on-change-batch.js +19 -3
  402. package/dist/esm/hooks/use-on-change-calculated-column.d.ts +10 -1
  403. package/dist/esm/hooks/use-on-change-calculated-column.d.ts.map +1 -1
  404. package/dist/esm/hooks/use-on-change-calculated-column.js +17 -5
  405. package/dist/esm/hooks/use-on-change-table-column.d.ts +6 -1
  406. package/dist/esm/hooks/use-on-change-table-column.d.ts.map +1 -1
  407. package/dist/esm/hooks/use-on-change-table-column.js +17 -5
  408. package/dist/esm/hooks/use-on-change.d.ts +36 -3
  409. package/dist/esm/hooks/use-on-change.d.ts.map +1 -1
  410. package/dist/esm/hooks/use-on-change.js +214 -124
  411. package/dist/esm/hooks/use-on-copy.d.ts +1 -1
  412. package/dist/esm/hooks/use-on-copy.d.ts.map +1 -1
  413. package/dist/esm/hooks/use-on-copy.js +2 -3
  414. package/dist/esm/hooks/use-on-create-custom-table-style.d.ts +17 -0
  415. package/dist/esm/hooks/use-on-create-custom-table-style.d.ts.map +1 -0
  416. package/dist/esm/hooks/use-on-create-custom-table-style.js +26 -0
  417. package/dist/esm/hooks/use-on-create-named-range.d.ts +4 -2
  418. package/dist/esm/hooks/use-on-create-named-range.d.ts.map +1 -1
  419. package/dist/esm/hooks/use-on-create-named-range.js +11 -1
  420. package/dist/esm/hooks/use-on-delete-cells-shift-left.d.ts +2 -1
  421. package/dist/esm/hooks/use-on-delete-cells-shift-left.d.ts.map +1 -1
  422. package/dist/esm/hooks/use-on-delete-cells-shift-left.js +3 -1
  423. package/dist/esm/hooks/use-on-delete-cells-shift-up.d.ts +2 -1
  424. package/dist/esm/hooks/use-on-delete-cells-shift-up.d.ts.map +1 -1
  425. package/dist/esm/hooks/use-on-delete-cells-shift-up.js +3 -1
  426. package/dist/esm/hooks/use-on-delete-column.d.ts +2 -1
  427. package/dist/esm/hooks/use-on-delete-column.d.ts.map +1 -1
  428. package/dist/esm/hooks/use-on-delete-column.js +3 -1
  429. package/dist/esm/hooks/use-on-delete-row.d.ts +2 -1
  430. package/dist/esm/hooks/use-on-delete-row.d.ts.map +1 -1
  431. package/dist/esm/hooks/use-on-delete-row.js +3 -1
  432. package/dist/esm/hooks/use-on-delete-sheet.d.ts +9 -1
  433. package/dist/esm/hooks/use-on-delete-sheet.d.ts.map +1 -1
  434. package/dist/esm/hooks/use-on-delete-sheet.js +17 -1
  435. package/dist/esm/hooks/use-on-delete-table-row.d.ts +4 -1
  436. package/dist/esm/hooks/use-on-delete-table-row.d.ts.map +1 -1
  437. package/dist/esm/hooks/use-on-delete-table-row.js +19 -1
  438. package/dist/esm/hooks/use-on-delete.d.ts +5 -2
  439. package/dist/esm/hooks/use-on-delete.d.ts.map +1 -1
  440. package/dist/esm/hooks/use-on-delete.js +5 -1
  441. package/dist/esm/hooks/use-on-embeds.d.ts +7 -4
  442. package/dist/esm/hooks/use-on-embeds.d.ts.map +1 -1
  443. package/dist/esm/hooks/use-on-embeds.js +23 -6
  444. package/dist/esm/hooks/use-on-fill.d.ts +17 -2
  445. package/dist/esm/hooks/use-on-fill.d.ts.map +1 -1
  446. package/dist/esm/hooks/use-on-fill.js +27 -1
  447. package/dist/esm/hooks/use-on-filter-table.d.ts.map +1 -1
  448. package/dist/esm/hooks/use-on-filter-table.js +97 -26
  449. package/dist/esm/hooks/use-on-import-excel.d.ts +2 -1
  450. package/dist/esm/hooks/use-on-import-excel.d.ts.map +1 -1
  451. package/dist/esm/hooks/use-on-import-excel.js +4 -1
  452. package/dist/esm/hooks/use-on-insert-cells-shift-down.d.ts +2 -1
  453. package/dist/esm/hooks/use-on-insert-cells-shift-down.d.ts.map +1 -1
  454. package/dist/esm/hooks/use-on-insert-cells-shift-down.js +3 -1
  455. package/dist/esm/hooks/use-on-insert-cells-shift-right.d.ts +2 -1
  456. package/dist/esm/hooks/use-on-insert-cells-shift-right.d.ts.map +1 -1
  457. package/dist/esm/hooks/use-on-insert-cells-shift-right.js +3 -1
  458. package/dist/esm/hooks/use-on-insert-column.d.ts +2 -1
  459. package/dist/esm/hooks/use-on-insert-column.d.ts.map +1 -1
  460. package/dist/esm/hooks/use-on-insert-column.js +3 -1
  461. package/dist/esm/hooks/use-on-insert-row.d.ts +2 -1
  462. package/dist/esm/hooks/use-on-insert-row.d.ts.map +1 -1
  463. package/dist/esm/hooks/use-on-insert-row.js +3 -1
  464. package/dist/esm/hooks/use-on-insert-table-row.d.ts +5 -2
  465. package/dist/esm/hooks/use-on-insert-table-row.d.ts.map +1 -1
  466. package/dist/esm/hooks/use-on-insert-table-row.js +19 -1
  467. package/dist/esm/hooks/use-on-merge-unmerge-cells.d.ts +3 -2
  468. package/dist/esm/hooks/use-on-merge-unmerge-cells.d.ts.map +1 -1
  469. package/dist/esm/hooks/use-on-merge-unmerge-cells.js +12 -1
  470. package/dist/esm/hooks/use-on-move-columns.d.ts +4 -1
  471. package/dist/esm/hooks/use-on-move-columns.d.ts.map +1 -1
  472. package/dist/esm/hooks/use-on-move-columns.js +28 -6
  473. package/dist/esm/hooks/use-on-move-rows.d.ts +18 -1
  474. package/dist/esm/hooks/use-on-move-rows.d.ts.map +1 -1
  475. package/dist/esm/hooks/use-on-move-rows.js +44 -6
  476. package/dist/esm/hooks/use-on-move-selection.d.ts +9 -2
  477. package/dist/esm/hooks/use-on-move-selection.d.ts.map +1 -1
  478. package/dist/esm/hooks/use-on-move-selection.js +57 -1
  479. package/dist/esm/hooks/use-on-paste.d.ts +33 -2
  480. package/dist/esm/hooks/use-on-paste.d.ts.map +1 -1
  481. package/dist/esm/hooks/use-on-paste.js +825 -643
  482. package/dist/esm/hooks/use-on-remove-duplicates.d.ts +5 -2
  483. package/dist/esm/hooks/use-on-remove-duplicates.d.ts.map +1 -1
  484. package/dist/esm/hooks/use-on-remove-duplicates.js +5 -1
  485. package/dist/esm/hooks/use-on-request-create-table.d.ts +13 -0
  486. package/dist/esm/hooks/use-on-request-create-table.d.ts.map +1 -0
  487. package/dist/esm/hooks/use-on-request-create-table.js +43 -0
  488. package/dist/esm/hooks/use-on-request-insert-slicer.d.ts +7 -0
  489. package/dist/esm/hooks/use-on-request-insert-slicer.d.ts.map +1 -0
  490. package/dist/esm/hooks/use-on-request-insert-slicer.js +15 -0
  491. package/dist/esm/hooks/use-on-request-resize-table.d.ts +7 -0
  492. package/dist/esm/hooks/use-on-request-resize-table.d.ts.map +1 -0
  493. package/dist/esm/hooks/use-on-request-resize-table.js +15 -0
  494. package/dist/esm/hooks/use-on-resize-table.d.ts +5 -1
  495. package/dist/esm/hooks/use-on-resize-table.d.ts.map +1 -1
  496. package/dist/esm/hooks/use-on-resize-table.js +107 -27
  497. package/dist/esm/hooks/use-on-sort-column.d.ts +28 -3
  498. package/dist/esm/hooks/use-on-sort-column.d.ts.map +1 -1
  499. package/dist/esm/hooks/use-on-sort-column.js +105 -68
  500. package/dist/esm/hooks/use-on-sort-range.d.ts +26 -3
  501. package/dist/esm/hooks/use-on-sort-range.d.ts.map +1 -1
  502. package/dist/esm/hooks/use-on-sort-range.js +100 -64
  503. package/dist/esm/hooks/use-on-sort-table.d.ts +18 -1
  504. package/dist/esm/hooks/use-on-sort-table.d.ts.map +1 -1
  505. package/dist/esm/hooks/use-on-sort-table.js +107 -86
  506. package/dist/esm/hooks/use-on-subtotal.d.ts +10 -3
  507. package/dist/esm/hooks/use-on-subtotal.d.ts.map +1 -1
  508. package/dist/esm/hooks/use-on-subtotal.js +7 -5
  509. package/dist/esm/hooks/use-on-table.d.ts +39 -7
  510. package/dist/esm/hooks/use-on-table.d.ts.map +1 -1
  511. package/dist/esm/hooks/use-on-table.js +234 -26
  512. package/dist/esm/hooks/use-on-undo-calculated-column.d.ts +23 -0
  513. package/dist/esm/hooks/use-on-undo-calculated-column.d.ts.map +1 -0
  514. package/dist/esm/hooks/use-on-undo-calculated-column.js +62 -0
  515. package/dist/esm/hooks/use-on-undo-table-auto-expansion.d.ts +28 -0
  516. package/dist/esm/hooks/use-on-undo-table-auto-expansion.d.ts.map +1 -0
  517. package/dist/esm/hooks/use-on-undo-table-auto-expansion.js +75 -0
  518. package/dist/esm/hooks/use-on-update-named-range.d.ts +4 -2
  519. package/dist/esm/hooks/use-on-update-named-range.d.ts.map +1 -1
  520. package/dist/esm/hooks/use-on-update-named-range.js +13 -1
  521. package/dist/esm/hooks/use-sheet-properties.d.ts +1 -0
  522. package/dist/esm/hooks/use-sheet-properties.d.ts.map +1 -1
  523. package/dist/esm/hooks/use-sheet-properties.js +38 -19
  524. package/dist/esm/hooks/use-slicers.d.ts +2 -2
  525. package/dist/esm/hooks/use-slicers.d.ts.map +1 -1
  526. package/dist/esm/hooks/use-slicers.js +16 -8
  527. package/dist/esm/hooks/use-sparkline-groups.d.ts +50 -0
  528. package/dist/esm/hooks/use-sparkline-groups.d.ts.map +1 -0
  529. package/dist/esm/hooks/use-sparkline-groups.js +146 -0
  530. package/dist/esm/hooks/use-spreadsheet-state.d.ts +69 -12
  531. package/dist/esm/hooks/use-spreadsheet-state.d.ts.map +1 -1
  532. package/dist/esm/hooks/use-spreadsheet-state.js +321 -14
  533. package/dist/esm/hooks/use-structured-reference.d.ts.map +1 -1
  534. package/dist/esm/hooks/use-structured-reference.js +17 -0
  535. package/dist/esm/hooks/use-undo-redo-actions.d.ts +2 -1
  536. package/dist/esm/hooks/use-undo-redo-actions.d.ts.map +1 -1
  537. package/dist/esm/hooks/use-undo-redo-actions.js +8 -2
  538. package/dist/esm/hooks/use-undo-redo.d.ts +12 -0
  539. package/dist/esm/hooks/use-undo-redo.d.ts.map +1 -1
  540. package/dist/esm/hooks/use-undo-redo.js +158 -7
  541. package/dist/esm/hooks/utils/sort-rows.d.ts.map +1 -1
  542. package/dist/esm/hooks/utils/sort-rows.js +4 -3
  543. package/dist/esm/index.d.ts +8 -0
  544. package/dist/esm/index.d.ts.map +1 -1
  545. package/dist/esm/index.js +9 -0
  546. package/dist/esm/interface/apply-fill.d.ts +26 -3
  547. package/dist/esm/interface/apply-fill.d.ts.map +1 -1
  548. package/dist/esm/interface/apply-fill.js +188 -88
  549. package/dist/esm/interface/change-batch.d.ts +1 -1
  550. package/dist/esm/interface/change-batch.d.ts.map +1 -1
  551. package/dist/esm/interface/change-batch.js +89 -8
  552. package/dist/esm/interface/change-calculated-column.d.ts +6 -2
  553. package/dist/esm/interface/change-calculated-column.d.ts.map +1 -1
  554. package/dist/esm/interface/change-calculated-column.js +81 -16
  555. package/dist/esm/interface/change-table-column.d.ts +81 -7
  556. package/dist/esm/interface/change-table-column.d.ts.map +1 -1
  557. package/dist/esm/interface/change-table-column.js +295 -67
  558. package/dist/esm/interface/create-table.d.ts +15 -3
  559. package/dist/esm/interface/create-table.d.ts.map +1 -1
  560. package/dist/esm/interface/create-table.js +103 -27
  561. package/dist/esm/interface/delete-cells-shift-left.d.ts +1 -1
  562. package/dist/esm/interface/delete-cells-shift-left.d.ts.map +1 -1
  563. package/dist/esm/interface/delete-cells-shift-left.js +10 -1
  564. package/dist/esm/interface/delete-cells-shift-up.d.ts +1 -1
  565. package/dist/esm/interface/delete-cells-shift-up.d.ts.map +1 -1
  566. package/dist/esm/interface/delete-cells-shift-up.js +10 -1
  567. package/dist/esm/interface/delete-cells.d.ts +1 -1
  568. package/dist/esm/interface/delete-cells.d.ts.map +1 -1
  569. package/dist/esm/interface/delete-cells.js +47 -14
  570. package/dist/esm/interface/delete-column.d.ts +1 -1
  571. package/dist/esm/interface/delete-column.d.ts.map +1 -1
  572. package/dist/esm/interface/delete-column.js +26 -30
  573. package/dist/esm/interface/delete-row.d.ts +1 -1
  574. package/dist/esm/interface/delete-row.d.ts.map +1 -1
  575. package/dist/esm/interface/delete-row.js +191 -44
  576. package/dist/esm/interface/delete-sheet.d.ts +2 -2
  577. package/dist/esm/interface/delete-sheet.d.ts.map +1 -1
  578. package/dist/esm/interface/delete-sheet.js +113 -1
  579. package/dist/esm/interface/delete-table-column.d.ts +1 -1
  580. package/dist/esm/interface/delete-table-column.d.ts.map +1 -1
  581. package/dist/esm/interface/delete-table-column.js +11 -1
  582. package/dist/esm/interface/delete-table-row.d.ts +1 -1
  583. package/dist/esm/interface/delete-table-row.d.ts.map +1 -1
  584. package/dist/esm/interface/delete-table-row.js +312 -232
  585. package/dist/esm/interface/duplicate-sheet.d.ts.map +1 -1
  586. package/dist/esm/interface/duplicate-sheet.js +73 -26
  587. package/dist/esm/interface/embeds.d.ts +10 -1
  588. package/dist/esm/interface/embeds.d.ts.map +1 -1
  589. package/dist/esm/interface/embeds.js +84 -5
  590. package/dist/esm/interface/insert-cells-shift-down.d.ts +1 -1
  591. package/dist/esm/interface/insert-cells-shift-down.d.ts.map +1 -1
  592. package/dist/esm/interface/insert-cells-shift-down.js +10 -1
  593. package/dist/esm/interface/insert-cells-shift-right.d.ts +1 -1
  594. package/dist/esm/interface/insert-cells-shift-right.d.ts.map +1 -1
  595. package/dist/esm/interface/insert-cells-shift-right.js +10 -1
  596. package/dist/esm/interface/insert-column.d.ts +2 -2
  597. package/dist/esm/interface/insert-column.d.ts.map +1 -1
  598. package/dist/esm/interface/insert-column.js +70 -33
  599. package/dist/esm/interface/insert-row.d.ts +1 -1
  600. package/dist/esm/interface/insert-row.d.ts.map +1 -1
  601. package/dist/esm/interface/insert-row.js +22 -6
  602. package/dist/esm/interface/insert-table-row.d.ts +2 -1
  603. package/dist/esm/interface/insert-table-row.d.ts.map +1 -1
  604. package/dist/esm/interface/insert-table-row.js +67 -12
  605. package/dist/esm/interface/remove-duplicates.d.ts +1 -1
  606. package/dist/esm/interface/remove-duplicates.d.ts.map +1 -1
  607. package/dist/esm/interface/remove-duplicates.js +41 -6
  608. package/dist/esm/interface/remove-table.d.ts +1 -1
  609. package/dist/esm/interface/remove-table.d.ts.map +1 -1
  610. package/dist/esm/interface/remove-table.js +58 -10
  611. package/dist/esm/interface/slicers.d.ts +12 -1
  612. package/dist/esm/interface/slicers.d.ts.map +1 -1
  613. package/dist/esm/interface/slicers.js +44 -2
  614. package/dist/esm/interface/spreadsheet-interface.d.ts +1 -1
  615. package/dist/esm/interface/spreadsheet-interface.d.ts.map +1 -1
  616. package/dist/esm/interface/spreadsheet-interface.js +73 -1
  617. package/dist/esm/interface/table-totalrow.d.ts +13 -1
  618. package/dist/esm/interface/table-totalrow.d.ts.map +1 -1
  619. package/dist/esm/interface/table-totalrow.js +98 -68
  620. package/dist/esm/interface/table-utils.d.ts +59 -6
  621. package/dist/esm/interface/table-utils.d.ts.map +1 -1
  622. package/dist/esm/interface/table-utils.js +155 -14
  623. package/dist/esm/interface/update-table.d.ts +16 -1
  624. package/dist/esm/interface/update-table.d.ts.map +1 -1
  625. package/dist/esm/interface/update-table.js +203 -42
  626. package/dist/esm/sheet-cell.d.ts.map +1 -1
  627. package/dist/esm/test-setup.d.ts.map +1 -1
  628. package/dist/esm/test-setup.js +6 -0
  629. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  630. package/dist/esm/validation-schema/table.schema.d.ts +11 -0
  631. package/dist/esm/validation-schema/table.schema.d.ts.map +1 -1
  632. package/dist/esm/validation-schema/table.schema.js +15 -2
  633. package/package.json +25 -17
@@ -1,19 +1,26 @@
1
1
  import { __assign, __awaiter, __generator, __read, __rest, __spreadArray, __values } from "tslib";
2
2
  import { isStaticNode } from "@rowsncolumns/dag";
3
- import { areaIntersects, isAreasEqual } from "@rowsncolumns/grid";
3
+ import { areaInsideArea, areaIntersects, isAreasEqual } from "@rowsncolumns/grid";
4
4
  import { selectionFromActiveCell } from "@rowsncolumns/grid";
5
5
  import { DEFAULT_COLUMN_COUNT, DEFAULT_ROW_COUNT, findActiveTableWithinCell, loadWebFont, MAX_COLUMN_COUNT, MAX_ROW_COUNT, useFocusEmbedOrChart, useGetFinalRowHeight, useRedrawGrid, } from "@rowsncolumns/spreadsheet";
6
6
  import { isSelectionACell, useGetEffectiveValuesFromRange, } from "@rowsncolumns/spreadsheet";
7
7
  import { error, getCellFormattedValue, getCellUserEnteredFormat, getCellUserEnteredValue, getExtendedValueBool, getExtendedValueFormula, getExtendedValueNumber, getExtendedValueString, isNil, iterateCellsInRange, uuidString, } from "@rowsncolumns/utils";
8
8
  import { produceWithPatches } from "immer";
9
9
  import { useCallback } from "react";
10
+ import { moveChartsOnRangeMove } from "../api/anchored-objects";
10
11
  import { processSideEffectDependentCells } from "../api/dependency";
11
12
  import { createSheetCellIdentifier } from "../api/formula";
12
13
  import { createSheetDraft } from "../api/immer-utils";
14
+ import { findPartiallyCoveredMerge, MERGED_CELL_MOVE_ERROR } from "../api/merges";
15
+ import { moveRange } from "../api/selection";
16
+ import { useShowError } from "../atoms/error-state.atom";
13
17
  import { applyPasteOperation, isBlankClipboardCell, resolvePasteSpecialOptions, } from "../api/paste-special";
14
- import { findAdjacentTable, findTableColumnIndex } from "../api/table";
15
- import { addCalculatedColumnsForRowExpansion } from "../interface/change-table-column";
18
+ import { getMoveRangeRefusal } from "../api/structural-guards";
19
+ import { renameHeaderCellsInFormulas } from "../api/structural-table-refs";
20
+ import { findAdjacentTable } from "../api/table";
21
+ import { getNextTableTitle } from "../helpers";
16
22
  import { collectDataValidationTarget, extendDataValidationRanges, } from "../interface/data-validation-utils";
23
+ import { planHeaderCellRenames } from "../interface/change-table-column";
17
24
  import { SheetCell } from "../sheet-cell";
18
25
  import { extractFontFamily, generateDataFromClipboard, pickFormatting, pickFormula, pickValue, transpose, } from "./../api/copy-paste";
19
26
  import { useCalculationQueue } from "./use-calculation-queue";
@@ -35,8 +42,9 @@ export var buildDestinationRowAssignments = function (sheetId, startRowIndex, en
35
42
  return assignments;
36
43
  };
37
44
  export var useOnPaste = function (_a) {
38
- var rowCount = _a.rowCount, columnCount = _a.columnCount, locale = _a.locale, sheetData = _a.sheetData, currentTables = _a.tables, _b = _a.maxRowCount, maxRowCount = _b === void 0 ? MAX_ROW_COUNT : _b, _c = _a.maxColumnCount, maxColumnCount = _c === void 0 ? MAX_COLUMN_COUNT : _c, isHiddenByFilterRow = _a.isHiddenByFilterRow, onRequestFonts = _a.onRequestFonts, idCreationStrategy = _a.idCreationStrategy, createHistory = _a.createHistory, enqueueCalculation = _a.enqueueCalculation, enqueueStructureChange = _a.enqueueStructureChange, enqueueGraphOperation = _a.enqueueGraphOperation, onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeTables = _a.onChangeTables, onChangeEmbeds = _a.onChangeEmbeds, onChangeSelections = _a.onChangeSelections, onChangeActiveCell = _a.onChangeActiveCell, getDependents = _a.getDependents, getActiveCell = _a.getActiveCell, getUserEnteredValue = _a.getUserEnteredValue, onChangeDataValidations = _a.onChangeDataValidations, _d = _a.preserveFormatting, preserveFormatting = _d === void 0 ? true : _d, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry, getDataValidationById = _a.getDataValidationById, getSheetName = _a.getSheetName, onError = _a.onError, citations = _a.citations, onChangeCitations = _a.onChangeCitations, sanitizeHtml = _a.sanitizeHtml, onCommand = _a.onCommand, generatedNames = _a.generatedNames;
45
+ var rowCount = _a.rowCount, columnCount = _a.columnCount, locale = _a.locale, sheetData = _a.sheetData, currentTables = _a.tables, _b = _a.maxRowCount, maxRowCount = _b === void 0 ? MAX_ROW_COUNT : _b, _c = _a.maxColumnCount, maxColumnCount = _c === void 0 ? MAX_COLUMN_COUNT : _c, isHiddenByFilterRow = _a.isHiddenByFilterRow, onRequestFonts = _a.onRequestFonts, idCreationStrategy = _a.idCreationStrategy, createHistory = _a.createHistory, enqueueCalculation = _a.enqueueCalculation, enqueueStructureChange = _a.enqueueStructureChange, enqueueGraphOperation = _a.enqueueGraphOperation, onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeTables = _a.onChangeTables, onChangeEmbeds = _a.onChangeEmbeds, onChangeSelections = _a.onChangeSelections, onChangeActiveCell = _a.onChangeActiveCell, getDependents = _a.getDependents, getActiveCell = _a.getActiveCell, getUserEnteredValue = _a.getUserEnteredValue, onChangeDataValidations = _a.onChangeDataValidations, onChangeNamedRanges = _a.onChangeNamedRanges, onChangeCharts = _a.onChangeCharts, getSheetMerges = _a.getSheetMerges, _d = _a.preserveFormatting, preserveFormatting = _d === void 0 ? true : _d, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry, getDataValidationById = _a.getDataValidationById, getSheetName = _a.getSheetName, onError = _a.onError, citations = _a.citations, onChangeCitations = _a.onChangeCitations, sanitizeHtml = _a.sanitizeHtml, onCommand = _a.onCommand, generatedNames = _a.generatedNames, _e = _a.batchHistory, batchHistory = _e === void 0 ? function (action) { return action(); } : _e, _f = _a.autoExpandTables, autoExpandTables = _f === void 0 ? true : _f, _g = _a.autoCalculatedColumns, autoCalculatedColumns = _g === void 0 ? true : _g;
39
46
  var canEditCellRange = useCanEditCellRange();
47
+ var showError = useShowError();
40
48
  // Allowed values
41
49
  var getEffectiveValuesFromRange = useGetEffectiveValuesFromRange();
42
50
  var focusEmbedOrChart = useFocusEmbedOrChart();
@@ -49,6 +57,7 @@ export var useOnPaste = function (_a) {
49
57
  onChangeTables: onChangeTables,
50
58
  getSheetName: getSheetName,
51
59
  onCommand: onCommand,
60
+ autoCalculatedColumns: autoCalculatedColumns,
52
61
  });
53
62
  var onChangeTableColumn = useOnChangeTableColumn({
54
63
  locale: locale,
@@ -57,19 +66,20 @@ export var useOnPaste = function (_a) {
57
66
  enqueueGraphOperation: enqueueGraphOperation,
58
67
  onChangeSheetData: onChangeSheetData,
59
68
  onChangeTables: onChangeTables,
69
+ onChangeCharts: onChangeCharts,
60
70
  getDependents: getDependents,
61
71
  onCommand: onCommand,
62
72
  generatedNames: generatedNames,
73
+ tables: currentTables,
63
74
  });
64
75
  var redrawGrid = useRedrawGrid();
65
76
  var getFinalRowHeight = useGetFinalRowHeight();
66
- var _e = useCalculationQueue({ enqueueCalculation: enqueueCalculation }), enqueue = _e.enqueue, processQueue = _e.processQueue;
77
+ var _h = useCalculationQueue({ enqueueCalculation: enqueueCalculation }), enqueue = _h.enqueue, processQueue = _h.processQueue;
67
78
  return useCallback(function (e, sourceSheetId, destinationSheetId, copiedSelections, activeCell, selections, finalSelections, isCutOperation) { return __awaiter(void 0, void 0, void 0, function () {
68
- var pasteSpecial, pasteMode, pasteOperation, pasteEvent, forcePlainText, activeSheetName, from, merges, embeds, tables, columnWidths, rowHeights, selectedRowValues, rowIndex, start, end, pasteResults, saveHistory, dataValidationTargets, fontFamilies, fontFamiliesWithWeights, err_1, _a, rowSpan, colSpan, to, rowDelta, columnDelta, _b, adjacentTable, isRowExpansion, isColumnExpansion, currentTable, nextSelections, existingTable, destinationRows, visibleRowIndexes, tableHeaderColumnIndex, cellValue, formattedValue, sharedStrings, sharedStringValue, activeCellValue, recalcCells, newEndRowIndex_1, pastedSheetData, values, rowIndex, row, columnIndex, cell, ue, firstEmbedId_1, citationIdMap_1, dataRowIndex, rowData, dataColumnIndex, cellValue_1, newCitations_1, citationIdRemap_1, _loop_1, _c, _d, _e, oldCitationId, _f, sourceRowIndex, sourceColumnIndex;
69
- var e_1, _g;
70
- var _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
71
- return __generator(this, function (_0) {
72
- switch (_0.label) {
79
+ var pasteSpecial, pasteMode, pasteOperation, pasteEvent, forcePlainText, activeSheetName, from, merges, embeds, tables, columnWidths, rowHeights, selectedRowValues, rowIndex, start, end, pasteResults, fontFamilies, fontFamiliesWithWeights, err_1;
80
+ var _a, _b, _c, _d, _e;
81
+ return __generator(this, function (_f) {
82
+ switch (_f.label) {
73
83
  case 0:
74
84
  pasteSpecial = resolvePasteSpecialOptions(e === null || e === void 0 ? void 0 : e.clipboardData);
75
85
  pasteMode = pasteSpecial.paste;
@@ -85,19 +95,19 @@ export var useOnPaste = function (_a) {
85
95
  for (rowIndex = from.range.startRowIndex; rowIndex <= from.range.endRowIndex; rowIndex++) {
86
96
  start = from.range.startColumnIndex;
87
97
  end = start + from.range.endColumnIndex - from.range.startColumnIndex + 1;
88
- selectedRowValues.push((_l = (_k = (_j = (_h = sheetData === null || sheetData === void 0 ? void 0 : sheetData[sourceSheetId]) === null || _h === void 0 ? void 0 : _h[rowIndex]) === null || _j === void 0 ? void 0 : _j.values) === null || _k === void 0 ? void 0 : _k.slice(start, end)) !== null && _l !== void 0 ? _l : []);
98
+ selectedRowValues.push((_d = (_c = (_b = (_a = sheetData === null || sheetData === void 0 ? void 0 : sheetData[sourceSheetId]) === null || _a === void 0 ? void 0 : _a[rowIndex]) === null || _b === void 0 ? void 0 : _b.values) === null || _c === void 0 ? void 0 : _c.slice(start, end)) !== null && _d !== void 0 ? _d : []);
89
99
  }
90
100
  return [3 /*break*/, 3];
91
- case 1: return [4 /*yield*/, generateDataFromClipboard(e, activeCell, destinationSheetId, activeSheetName, preserveFormatting, locale, idCreationStrategy, forcePlainText, sanitizeHtml, generatedNames)];
101
+ case 1: return [4 /*yield*/, generateDataFromClipboard(e, activeCell, destinationSheetId, activeSheetName, preserveFormatting, locale, idCreationStrategy, forcePlainText, sanitizeHtml)];
92
102
  case 2:
93
- pasteResults = _0.sent();
94
- selectedRowValues = (_m = pasteResults === null || pasteResults === void 0 ? void 0 : pasteResults.results) !== null && _m !== void 0 ? _m : [];
103
+ pasteResults = _f.sent();
104
+ selectedRowValues = (_e = pasteResults === null || pasteResults === void 0 ? void 0 : pasteResults.results) !== null && _e !== void 0 ? _e : [];
95
105
  merges = pasteResults === null || pasteResults === void 0 ? void 0 : pasteResults.merges;
96
106
  embeds = pasteResults === null || pasteResults === void 0 ? void 0 : pasteResults.embeds;
97
107
  tables = pasteResults === null || pasteResults === void 0 ? void 0 : pasteResults.tables;
98
108
  rowHeights = pasteResults === null || pasteResults === void 0 ? void 0 : pasteResults.rowHeights;
99
109
  columnWidths = pasteResults === null || pasteResults === void 0 ? void 0 : pasteResults.columnWidths;
100
- _0.label = 3;
110
+ _f.label = 3;
101
111
  case 3:
102
112
  // No data,
103
113
  if (isNil(selectedRowValues)) {
@@ -115,857 +125,1105 @@ export var useOnPaste = function (_a) {
115
125
  else if (pasteMode === "values") {
116
126
  selectedRowValues = pickValue(selectedRowValues, destinationSheetId, locale);
117
127
  }
118
- saveHistory = createHistory();
119
- dataValidationTargets = new Map();
120
128
  fontFamilies = extractFontFamily(selectedRowValues);
121
129
  if (!(fontFamilies.length && preserveFormatting)) return [3 /*break*/, 10];
122
130
  fontFamiliesWithWeights = fontFamilies
123
131
  .map(function (family) { return ["".concat(family, ":400"), "".concat(family, ":700")]; })
124
132
  .flat();
125
- _0.label = 4;
133
+ _f.label = 4;
126
134
  case 4:
127
- _0.trys.push([4, 9, , 10]);
135
+ _f.trys.push([4, 9, , 10]);
128
136
  if (!onRequestFonts) return [3 /*break*/, 6];
129
137
  return [4 /*yield*/, onRequestFonts(fontFamilies)];
130
138
  case 5:
131
- _0.sent();
139
+ _f.sent();
132
140
  return [3 /*break*/, 8];
133
141
  case 6: return [4 /*yield*/, loadWebFont(fontFamiliesWithWeights)];
134
142
  case 7:
135
- _0.sent();
136
- _0.label = 8;
143
+ _f.sent();
144
+ _f.label = 8;
137
145
  case 8:
138
146
  redrawGrid === null || redrawGrid === void 0 ? void 0 : redrawGrid();
139
147
  return [3 /*break*/, 10];
140
148
  case 9:
141
- err_1 = _0.sent();
149
+ err_1 = _f.sent();
142
150
  error("Error loading webfonts", fontFamilies, err_1);
143
151
  return [3 /*break*/, 10];
144
152
  case 10:
145
- _a = __read([
146
- (_o = selectedRowValues === null || selectedRowValues === void 0 ? void 0 : selectedRowValues.length) !== null && _o !== void 0 ? _o : 0,
147
- // For cut operations, use range dimensions since data may be sparse
148
- isCutOperation && from
149
- ? from.range.endColumnIndex - from.range.startColumnIndex + 1
150
- : (_q = (_p = selectedRowValues[0]) === null || _p === void 0 ? void 0 : _p.length) !== null && _q !== void 0 ? _q : 0,
151
- ], 2), rowSpan = _a[0], colSpan = _a[1];
152
- to = (_r = selections === null || selections === void 0 ? void 0 : selections[(selections === null || selections === void 0 ? void 0 : selections.length) - 1]) !== null && _r !== void 0 ? _r : selectionFromActiveCell(activeCell)[0];
153
- rowDelta = from && to ? to.range.startRowIndex - from.range.startRowIndex : -1;
154
- columnDelta = from && to
155
- ? to.range.startColumnIndex - from.range.startColumnIndex
156
- : -1;
157
- _b = __read(findAdjacentTable(destinationSheetId, activeCell, currentTables, getUserEnteredValue), 3), adjacentTable = _b[0], isRowExpansion = _b[1], isColumnExpansion = _b[2];
158
- currentTable = isColumnExpansion && adjacentTable
159
- ? adjacentTable
160
- : findActiveTableWithinCell(destinationSheetId, activeCell, currentTables);
161
- nextSelections = (finalSelections === null || finalSelections === void 0 ? void 0 : finalSelections.length) ? finalSelections : [to];
162
- // Update range based on length of data
163
- to.range.endRowIndex = Math.min(maxRowCount, Math.max(to.range.endRowIndex, to.range.startRowIndex + rowSpan - 1));
164
- to.range.endColumnIndex = Math.min(maxColumnCount, Math.max(to.range.endColumnIndex, to.range.startColumnIndex + colSpan - 1));
165
- // Check for protected range
166
- if (!canEditCellRange(destinationSheetId, to.range)) {
167
- console.debug("Protected range, You cannot paste on to protected cells.");
168
- return [2 /*return*/];
169
- }
170
- // Check if pasting a table would overlap with an existing table
171
- if (tables === null || tables === void 0 ? void 0 : tables.length) {
172
- existingTable = currentTables === null || currentTables === void 0 ? void 0 : currentTables.find(function (table) {
173
- return table.sheetId === destinationSheetId &&
174
- areaIntersects(to.range, table.range);
175
- });
176
- if (existingTable) {
177
- onError === null || onError === void 0 ? void 0 : onError("Cannot paste a table over another table. The paste range overlaps with an existing table.");
178
- return [2 /*return*/];
153
+ // From here on the paste is synchronous: its writes and the table growth / calculated-column
154
+ // fill they trigger open ONE undo entry.
155
+ batchHistory(function () {
156
+ var e_1, _a;
157
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
158
+ var saveHistory = createHistory();
159
+ var dataValidationTargets = new Map();
160
+ var _r = __read([
161
+ (_b = selectedRowValues === null || selectedRowValues === void 0 ? void 0 : selectedRowValues.length) !== null && _b !== void 0 ? _b : 0,
162
+ // For cut operations, use range dimensions since data may be sparse
163
+ isCutOperation && from
164
+ ? from.range.endColumnIndex - from.range.startColumnIndex + 1
165
+ : (_d = (_c = selectedRowValues[0]) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0,
166
+ ], 2), rowSpan = _r[0], colSpan = _r[1];
167
+ var to = (_e = selections === null || selections === void 0 ? void 0 : selections[(selections === null || selections === void 0 ? void 0 : selections.length) - 1]) !== null && _e !== void 0 ? _e : selectionFromActiveCell(activeCell)[0];
168
+ var rowDelta = from && to ? to.range.startRowIndex - from.range.startRowIndex : -1;
169
+ var columnDelta = from && to
170
+ ? to.range.startColumnIndex - from.range.startColumnIndex
171
+ : -1;
172
+ // A cut is a move: a table the cut block covers whole travels with it (Excel; the rnc
173
+ // engine's `move-range` does the same), so it is neither the table the paste writes into
174
+ // nor one the paste grows.
175
+ var movedTables = isCutOperation && from && !isNil(sourceSheetId)
176
+ ? (_f = currentTables === null || currentTables === void 0 ? void 0 : currentTables.filter(function (table) {
177
+ return table.sheetId === sourceSheetId &&
178
+ areaInsideArea(table.range, from.range);
179
+ })) !== null && _f !== void 0 ? _f : []
180
+ : [];
181
+ var stayingTables = movedTables.length
182
+ ? currentTables === null || currentTables === void 0 ? void 0 : currentTables.filter(function (table) { return !movedTables.includes(table); })
183
+ : currentTables;
184
+ // When user enters a value in the last row of a
185
+ // table and if the entire row is empty
186
+ var _s = __read(autoExpandTables
187
+ ? findAdjacentTable(destinationSheetId, activeCell, stayingTables, getUserEnteredValue)
188
+ : [undefined, false, false], 3), adjacentTable = _s[0], isRowExpansion = _s[1], isColumnExpansion = _s[2];
189
+ var currentTable = isColumnExpansion && adjacentTable
190
+ ? adjacentTable
191
+ : findActiveTableWithinCell(destinationSheetId, activeCell, stayingTables);
192
+ // Next selections
193
+ var nextSelections = (finalSelections === null || finalSelections === void 0 ? void 0 : finalSelections.length) ? finalSelections : [to];
194
+ // Update range based on length of data
195
+ to.range.endRowIndex = Math.min(maxRowCount, Math.max(to.range.endRowIndex, to.range.startRowIndex + rowSpan - 1));
196
+ to.range.endColumnIndex = Math.min(maxColumnCount, Math.max(to.range.endColumnIndex, to.range.startColumnIndex + colSpan - 1));
197
+ // Check for protected range
198
+ if (!canEditCellRange(destinationSheetId, to.range)) {
199
+ console.debug("Protected range, You cannot paste on to protected cells.");
200
+ return;
179
201
  }
180
- }
181
- destinationRows = buildDestinationRowAssignments(destinationSheetId, to.range.startRowIndex, to.range.endRowIndex, rowSpan, isHiddenByFilterRow);
182
- if (!destinationRows.length) {
183
- return [2 /*return*/];
184
- }
185
- // Paste writes through `onChangeSheetData` directly, so the
186
- // calculator's per-cell invalidation never fires for the
187
- // destination cells. Invalidate the destination rect — and the
188
- // source on cut, since those cells are cleared too.
189
- enqueueStructureChange === null || enqueueStructureChange === void 0 ? void 0 : enqueueStructureChange({
190
- kind: "invalidate-range",
191
- sheetId: destinationSheetId,
192
- startRowIndex: to.range.startRowIndex,
193
- endRowIndex: to.range.endRowIndex,
194
- startColumnIndex: to.range.startColumnIndex,
195
- endColumnIndex: to.range.endColumnIndex,
196
- });
197
- if (isCutOperation && from && !isNil(sourceSheetId)) {
202
+ // A cut is a move: Excel refuses it when the destination (or the source) covers a merged
203
+ // cell only partially — writing into a non-anchor cell of a merge would tear it.
204
+ if (isCutOperation &&
205
+ from &&
206
+ !isNil(sourceSheetId) &&
207
+ (findPartiallyCoveredMerge(to.range, getSheetMerges === null || getSheetMerges === void 0 ? void 0 : getSheetMerges(destinationSheetId)) ||
208
+ findPartiallyCoveredMerge(from.range, getSheetMerges === null || getSheetMerges === void 0 ? void 0 : getSheetMerges(sourceSheetId)))) {
209
+ showError({ message: MERGED_CELL_MOVE_ERROR });
210
+ return;
211
+ }
212
+ // …and Excel never moves PART of a table, nor lands a block on another table's cells — the
213
+ // drag-move refusals (T-46) apply to a cut + paste too, across sheets (T-79).
214
+ if (isCutOperation && from && !isNil(sourceSheetId)) {
215
+ var tableRefusal = getMoveRangeRefusal({
216
+ sheetId: sourceSheetId,
217
+ from: from.range,
218
+ to: to.range,
219
+ toSheetId: destinationSheetId,
220
+ tables: currentTables,
221
+ });
222
+ if (tableRefusal) {
223
+ showError({ title: tableRefusal.title, message: tableRefusal.message });
224
+ return;
225
+ }
226
+ }
227
+ // Check if pasting a table would overlap with an existing table
228
+ if (tables === null || tables === void 0 ? void 0 : tables.length) {
229
+ var existingTable = currentTables === null || currentTables === void 0 ? void 0 : currentTables.find(function (table) {
230
+ return table.sheetId === destinationSheetId &&
231
+ areaIntersects(to.range, table.range);
232
+ });
233
+ if (existingTable) {
234
+ onError === null || onError === void 0 ? void 0 : onError("Cannot paste a table over another table. The paste range overlaps with an existing table.");
235
+ return;
236
+ }
237
+ }
238
+ var destinationRows = buildDestinationRowAssignments(destinationSheetId, to.range.startRowIndex, to.range.endRowIndex, rowSpan, isHiddenByFilterRow);
239
+ if (!destinationRows.length) {
240
+ return;
241
+ }
242
+ // Paste writes through `onChangeSheetData` directly, so the
243
+ // calculator's per-cell invalidation never fires for the
244
+ // destination cells. Invalidate the destination rect — and the
245
+ // source on cut, since those cells are cleared too.
198
246
  enqueueStructureChange === null || enqueueStructureChange === void 0 ? void 0 : enqueueStructureChange({
199
247
  kind: "invalidate-range",
200
- sheetId: sourceSheetId,
201
- startRowIndex: from.range.startRowIndex,
202
- endRowIndex: from.range.endRowIndex,
203
- startColumnIndex: from.range.startColumnIndex,
204
- endColumnIndex: from.range.endColumnIndex,
248
+ sheetId: destinationSheetId,
249
+ startRowIndex: to.range.startRowIndex,
250
+ endRowIndex: to.range.endRowIndex,
251
+ startColumnIndex: to.range.startColumnIndex,
252
+ endColumnIndex: to.range.endColumnIndex,
205
253
  });
206
- }
207
- visibleRowIndexes = destinationRows.map(function (_a) {
208
- var rowIndex = _a.rowIndex;
209
- return rowIndex;
210
- });
211
- tableHeaderColumnIndex = findTableColumnIndex(destinationSheetId, activeCell, currentTables);
212
- cellValue = (_s = selectedRowValues === null || selectedRowValues === void 0 ? void 0 : selectedRowValues[0]) === null || _s === void 0 ? void 0 : _s[0];
213
- formattedValue = getCellFormattedValue(cellValue);
214
- sharedStrings = sharedStringRegistry === null || sharedStringRegistry === void 0 ? void 0 : sharedStringRegistry.getSharedStrings();
215
- sharedStringValue = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.ss) == null || !sharedStrings
216
- ? undefined
217
- : sharedStrings.get(String(cellValue.ss));
218
- activeCellValue = typeof formattedValue === "string"
219
- ? formattedValue
220
- : typeof sharedStringValue === "string"
221
- ? sharedStringValue
254
+ if (isCutOperation && from && !isNil(sourceSheetId)) {
255
+ enqueueStructureChange === null || enqueueStructureChange === void 0 ? void 0 : enqueueStructureChange({
256
+ kind: "invalidate-range",
257
+ sheetId: sourceSheetId,
258
+ startRowIndex: from.range.startRowIndex,
259
+ endRowIndex: from.range.endRowIndex,
260
+ startColumnIndex: from.range.startColumnIndex,
261
+ endColumnIndex: from.range.endColumnIndex,
262
+ });
263
+ }
264
+ var visibleRowIndexes = destinationRows.map(function (_a) {
265
+ var rowIndex = _a.rowIndex;
266
+ return rowIndex;
267
+ });
268
+ // Adds new column to table and cell to sheet
269
+ var sharedStrings = sharedStringRegistry === null || sharedStringRegistry === void 0 ? void 0 : sharedStringRegistry.getSharedStrings();
270
+ var pastedCellText = function (cellValue) {
271
+ var formattedValue = getCellFormattedValue(cellValue);
272
+ var sharedStringValue = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.ss) == null || !sharedStrings
273
+ ? undefined
274
+ : sharedStrings.get(String(cellValue.ss));
275
+ return typeof formattedValue === "string"
276
+ ? formattedValue
277
+ : typeof sharedStringValue === "string"
278
+ ? sharedStringValue
279
+ : undefined;
280
+ };
281
+ var activeCellValue = pastedCellText((_g = selectedRowValues === null || selectedRowValues === void 0 ? void 0 : selectedRowValues[0]) === null || _g === void 0 ? void 0 : _g[0]);
282
+ // A block pasted right of the table names every new column from its own header cell.
283
+ var pastedHeaderValues = isColumnExpansion &&
284
+ adjacentTable &&
285
+ activeCell.rowIndex === adjacentTable.range.startRowIndex
286
+ ? (_h = selectedRowValues === null || selectedRowValues === void 0 ? void 0 : selectedRowValues[0]) === null || _h === void 0 ? void 0 : _h.map(pastedCellText)
222
287
  : undefined;
223
- recalcCells = new Map();
224
- // Expand table if user is pasting
225
- // table data
226
- // Same undo history
227
- if (!isNil(currentTable) && !isRowExpansion) {
228
- newEndRowIndex_1 = Math.max(currentTable.range.endRowIndex, activeCell.rowIndex + rowSpan - 1 + (currentTable.totalRow ? 1 : 0));
229
- // Update table range
230
- onChangeTables === null || onChangeTables === void 0 ? void 0 : onChangeTables(function (prevTableData) {
231
- var _a = __read(produceWithPatches(prevTableData, function (draft) {
232
- var _a;
233
- var table = draft.find(function (table) { return (currentTable === null || currentTable === void 0 ? void 0 : currentTable.id) === table.id; });
234
- if (table) {
235
- table.range.endRowIndex = newEndRowIndex_1;
236
- // Update table name
237
- if (!isNil(tableHeaderColumnIndex)) {
238
- if ((_a = table.columns) === null || _a === void 0 ? void 0 : _a.length) {
239
- if (!table.columns[tableHeaderColumnIndex]) {
240
- table.columns[tableHeaderColumnIndex] = {
241
- name: String(activeCellValue),
242
- };
243
- }
244
- else {
245
- // Update name
246
- table.columns[tableHeaderColumnIndex].name =
247
- String(activeCellValue);
248
- }
249
- }
250
- }
288
+ // Header cells of existing tables the paste lands on take the typed-header
289
+ // rule (text, de-duplicated, structured references following); a cut moves
290
+ // cells as they are and a formats-only paste writes no values.
291
+ var headerRenames = !isCutOperation && pasteMode !== "formats"
292
+ ? planHeaderCellRenames({
293
+ sheetId: destinationSheetId,
294
+ tables: stayingTables,
295
+ generatedNames: generatedNames,
296
+ cells: destinationRows.flatMap(function (_a) {
297
+ var rowIndex = _a.rowIndex, dataRowIndex = _a.dataRowIndex;
298
+ return Array.from({
299
+ length: to.range.endColumnIndex - to.range.startColumnIndex + 1,
300
+ }, function (_, cursor) {
301
+ var _a;
302
+ return ({
303
+ rowIndex: rowIndex,
304
+ columnIndex: to.range.startColumnIndex + cursor,
305
+ value: pastedCellText((_a = selectedRowValues[dataRowIndex]) === null || _a === void 0 ? void 0 : _a[colSpan > 0 ? cursor % colSpan : 0]),
306
+ });
307
+ });
308
+ }),
309
+ })
310
+ : [];
311
+ var headerRenameAt = new Map(headerRenames.map(function (rename) { return [
312
+ "".concat(rename.rowIndex, ":").concat(rename.columnIndex),
313
+ rename,
314
+ ]; }));
315
+ // We need to track this for history. Precedent cells
316
+ var recalcCells = new Map();
317
+ // Expand table if user is pasting
318
+ // table data
319
+ // Same undo history
320
+ if (!isNil(currentTable) && !isRowExpansion) {
321
+ // The overflow grows the table row by row and stops at the first row another table
322
+ // occupies (Excel; same rule as the adjacent-row growth in `changeTableColumn`). Cells
323
+ // pasted past that row stay plain cells.
324
+ var newEndRowIndex_1 = currentTable.range.endRowIndex;
325
+ var lastOverflowRowIndex = activeCell.rowIndex + rowSpan - 1 + (currentTable.totalRow ? 1 : 0);
326
+ var _loop_1 = function (rowIndex) {
327
+ var line = __assign(__assign({}, currentTable.range), { startRowIndex: rowIndex, endRowIndex: rowIndex });
328
+ if (stayingTables === null || stayingTables === void 0 ? void 0 : stayingTables.some(function (other) {
329
+ return other.id !== currentTable.id &&
330
+ other.sheetId === destinationSheetId &&
331
+ areaIntersects(other.range, line);
332
+ })) {
333
+ return "break";
251
334
  }
252
- }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
253
- saveHistory({
254
- tables: { patches: patches, inversePatches: inversePatches },
335
+ newEndRowIndex_1 = rowIndex;
336
+ };
337
+ for (var rowIndex = currentTable.range.endRowIndex + 1; rowIndex <= lastOverflowRowIndex; rowIndex++) {
338
+ var state_1 = _loop_1(rowIndex);
339
+ if (state_1 === "break")
340
+ break;
341
+ }
342
+ // Update table range
343
+ onChangeTables === null || onChangeTables === void 0 ? void 0 : onChangeTables(function (prevTableData) {
344
+ var _a = __read(produceWithPatches(prevTableData, function (draft) {
345
+ var table = draft.find(function (table) { return (currentTable === null || currentTable === void 0 ? void 0 : currentTable.id) === table.id; });
346
+ if (table) {
347
+ table.range.endRowIndex = newEndRowIndex_1;
348
+ }
349
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
350
+ saveHistory({
351
+ tables: { patches: patches, inversePatches: inversePatches },
352
+ });
353
+ return nextState;
255
354
  });
256
- return nextState;
257
- });
258
- }
259
- if (selectedRowValues.length) {
260
- onChangeSheetData === null || onChangeSheetData === void 0 ? void 0 : onChangeSheetData(function (prevSheetData) {
261
- var _a = __read(produceWithPatches(prevSheetData, function (draft) {
262
- var e_2, _a, e_3, _b, e_4, _c, e_5, _d, e_6, _e;
263
- var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
264
- // For cut operation
265
- var movedKeys = new Set();
266
- /**
267
- * If user is deleting source cells,
268
- * let update its dependents and mark it as dirty
269
- */
270
- if (isCutOperation && from && to && !isNil(sourceSheetId)) {
271
- var sheetId = sourceSheetId;
355
+ }
356
+ if (headerRenames.length) {
357
+ onChangeTables === null || onChangeTables === void 0 ? void 0 : onChangeTables(function (prevTables) {
358
+ var _a = __read(produceWithPatches(prevTables, function (draft) {
359
+ var e_2, _a;
360
+ var _b;
361
+ var _loop_3 = function (table, dimensionIndex, newName) {
362
+ var current = draft.find(function (candidate) { return candidate.id === table.id; });
363
+ if (!current)
364
+ return "continue";
365
+ (_b = current.columns) !== null && _b !== void 0 ? _b : (current.columns = []);
366
+ if (current.columns[dimensionIndex]) {
367
+ current.columns[dimensionIndex].name = newName;
368
+ }
369
+ else {
370
+ current.columns[dimensionIndex] = { name: newName };
371
+ }
372
+ };
272
373
  try {
273
- for (var _1 = __values(iterateCellsInRange(from.range)), _2 = _1.next(); !_2.done; _2 = _1.next()) {
274
- var _3 = __read(_2.value, 2), rowIndex = _3[0], columnIndex = _3[1];
275
- // Process dependents
276
- processSideEffectDependentCells({
277
- draft: draft,
278
- rowIndex: rowIndex,
279
- columnIndex: columnIndex,
280
- sheetId: sheetId,
281
- destinationSheetId: destinationSheetId,
282
- columnDelta: columnDelta,
283
- enqueueGraphOperation: enqueueGraphOperation,
284
- enqueueCalculation: enqueue,
285
- getDependents: getDependents,
286
- recalcCells: recalcCells,
287
- rowDelta: rowDelta,
288
- sourceRange: from.range,
289
- movedKeys: movedKeys,
290
- locale: locale,
291
- rowCount: rowCount,
292
- columnCount: columnCount,
293
- });
374
+ for (var headerRenames_1 = __values(headerRenames), headerRenames_1_1 = headerRenames_1.next(); !headerRenames_1_1.done; headerRenames_1_1 = headerRenames_1.next()) {
375
+ var _c = headerRenames_1_1.value, table = _c.table, dimensionIndex = _c.dimensionIndex, newName = _c.newName;
376
+ _loop_3(table, dimensionIndex, newName);
294
377
  }
295
378
  }
296
379
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
297
380
  finally {
298
381
  try {
299
- if (_2 && !_2.done && (_a = _1.return)) _a.call(_1);
382
+ if (headerRenames_1_1 && !headerRenames_1_1.done && (_a = headerRenames_1.return)) _a.call(headerRenames_1);
300
383
  }
301
384
  finally { if (e_2) throw e_2.error; }
302
385
  }
303
- // Snapshot source after dependent/formula rewrites, before
304
- // clearing it. The pre-cut clipboard snapshot still contains
305
- // stale formulas, so writing that snapshot would discard the
306
- // reference updates performed above.
307
- var movedRowValues = [];
308
- var sourceStartColumn = from.range.startColumnIndex;
309
- var sourceEndColumn = from.range.endColumnIndex + 1;
310
- for (var rowIndex = from.range.startRowIndex; rowIndex <= from.range.endRowIndex; rowIndex++) {
311
- movedRowValues.push(((_j = (_h = (_g = (_f = draft[sheetId]) === null || _f === void 0 ? void 0 : _f[rowIndex]) === null || _g === void 0 ? void 0 : _g.values) === null || _h === void 0 ? void 0 : _h.slice(sourceStartColumn, sourceEndColumn)) !== null && _j !== void 0 ? _j : []));
312
- }
313
- // Delete source if required
314
- // Move values
315
- for (var rowIndex = from.range.startRowIndex; rowIndex <= from.range.endRowIndex; rowIndex++) {
316
- for (var columnIndex = from.range.startColumnIndex; columnIndex <= from.range.endColumnIndex; columnIndex++) {
317
- if (!((_l = (_k = draft[sheetId][rowIndex]) === null || _k === void 0 ? void 0 : _k.values) === null || _l === void 0 ? void 0 : _l[columnIndex])) {
318
- continue;
386
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
387
+ saveHistory({ tables: { patches: patches, inversePatches: inversePatches } });
388
+ return nextState;
389
+ });
390
+ }
391
+ // Update sheetdata
392
+ // Capture the produced state so we can stream the exact written cells to an engine
393
+ // consumer afterwards (branch-agnostic across cut / pure-paste / paste-special).
394
+ var pastedSheetData;
395
+ if (selectedRowValues.length) {
396
+ onChangeSheetData === null || onChangeSheetData === void 0 ? void 0 : onChangeSheetData(function (prevSheetData) {
397
+ var _a = __read(produceWithPatches(prevSheetData, function (draft) {
398
+ var e_3, _a, e_4, _b, e_5, _c, e_6, _d, e_7, _e;
399
+ var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
400
+ // For cut operation
401
+ var movedKeys = new Set();
402
+ /**
403
+ * If user is deleting source cells,
404
+ * let update its dependents and mark it as dirty
405
+ */
406
+ if (isCutOperation && from && to && !isNil(sourceSheetId)) {
407
+ var sheetId = sourceSheetId;
408
+ try {
409
+ for (var _1 = __values(iterateCellsInRange(from.range)), _2 = _1.next(); !_2.done; _2 = _1.next()) {
410
+ var _3 = __read(_2.value, 2), rowIndex = _3[0], columnIndex = _3[1];
411
+ // Process dependents
412
+ processSideEffectDependentCells({
413
+ draft: draft,
414
+ rowIndex: rowIndex,
415
+ columnIndex: columnIndex,
416
+ sheetId: sheetId,
417
+ destinationSheetId: destinationSheetId,
418
+ columnDelta: columnDelta,
419
+ enqueueGraphOperation: enqueueGraphOperation,
420
+ enqueueCalculation: enqueue,
421
+ getDependents: getDependents,
422
+ recalcCells: recalcCells,
423
+ rowDelta: rowDelta,
424
+ sourceRange: from.range,
425
+ movedKeys: movedKeys,
426
+ locale: locale,
427
+ rowCount: rowCount,
428
+ columnCount: columnCount,
429
+ });
319
430
  }
320
- draft[sheetId][rowIndex].values[columnIndex] =
321
- {};
322
431
  }
323
- }
324
- try {
325
- for (var destinationRows_1 = __values(destinationRows), destinationRows_1_1 = destinationRows_1.next(); !destinationRows_1_1.done; destinationRows_1_1 = destinationRows_1.next()) {
326
- var _4 = destinationRows_1_1.value, rowIndex = _4.rowIndex, dataRowIndex = _4.dataRowIndex;
327
- var currentSheet = createSheetDraft(draft, destinationSheetId, rowIndex);
328
- var columnCursor = 0;
329
- for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++, columnCursor++) {
330
- var dataColumnIndex = colSpan > 0 ? columnCursor % colSpan : 0;
331
- currentSheet[rowIndex].values[columnIndex] =
332
- (_m = movedRowValues[dataRowIndex]) === null || _m === void 0 ? void 0 : _m[dataColumnIndex];
333
- try {
334
- for (var _5 = (e_4 = void 0, __values(getDependents({
335
- rowIndex: rowIndex,
336
- columnIndex: columnIndex,
337
- sheetId: destinationSheetId,
338
- }))), _6 = _5.next(); !_6.done; _6 = _5.next()) {
339
- var dependent = _6.value;
340
- if (isStaticNode(dependent)) {
341
- continue;
342
- }
343
- var position = dependent.position;
344
- enqueue({
345
- type: "add",
346
- position: position,
347
- force: true,
348
- });
349
- recalcCells.set(createSheetCellIdentifier(position.sheetId, position.rowIndex, position.columnIndex), position);
350
- }
432
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
433
+ finally {
434
+ try {
435
+ if (_2 && !_2.done && (_a = _1.return)) _a.call(_1);
436
+ }
437
+ finally { if (e_3) throw e_3.error; }
438
+ }
439
+ // Snapshot source after dependent/formula rewrites, before
440
+ // clearing it. The pre-cut clipboard snapshot still contains
441
+ // stale formulas, so writing that snapshot would discard the
442
+ // reference updates performed above.
443
+ var movedRowValues = [];
444
+ var sourceStartColumn = from.range.startColumnIndex;
445
+ var sourceEndColumn = from.range.endColumnIndex + 1;
446
+ for (var rowIndex = from.range.startRowIndex; rowIndex <= from.range.endRowIndex; rowIndex++) {
447
+ movedRowValues.push(((_j = (_h = (_g = (_f = draft[sheetId]) === null || _f === void 0 ? void 0 : _f[rowIndex]) === null || _g === void 0 ? void 0 : _g.values) === null || _h === void 0 ? void 0 : _h.slice(sourceStartColumn, sourceEndColumn)) !== null && _j !== void 0 ? _j : []));
448
+ }
449
+ // Delete source if required
450
+ // Move values
451
+ for (var rowIndex = from.range.startRowIndex; rowIndex <= from.range.endRowIndex; rowIndex++) {
452
+ for (var columnIndex = from.range.startColumnIndex; columnIndex <= from.range.endColumnIndex; columnIndex++) {
453
+ if (!((_l = (_k = draft[sheetId][rowIndex]) === null || _k === void 0 ? void 0 : _k.values) === null || _l === void 0 ? void 0 : _l[columnIndex])) {
454
+ continue;
351
455
  }
352
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
353
- finally {
456
+ draft[sheetId][rowIndex].values[columnIndex] =
457
+ {};
458
+ }
459
+ }
460
+ try {
461
+ for (var destinationRows_1 = __values(destinationRows), destinationRows_1_1 = destinationRows_1.next(); !destinationRows_1_1.done; destinationRows_1_1 = destinationRows_1.next()) {
462
+ var _4 = destinationRows_1_1.value, rowIndex = _4.rowIndex, dataRowIndex = _4.dataRowIndex;
463
+ var currentSheet = createSheetDraft(draft, destinationSheetId, rowIndex);
464
+ var columnCursor = 0;
465
+ for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++, columnCursor++) {
466
+ var dataColumnIndex = colSpan > 0 ? columnCursor % colSpan : 0;
467
+ currentSheet[rowIndex].values[columnIndex] =
468
+ (_m = movedRowValues[dataRowIndex]) === null || _m === void 0 ? void 0 : _m[dataColumnIndex];
354
469
  try {
355
- if (_6 && !_6.done && (_c = _5.return)) _c.call(_5);
470
+ for (var _5 = (e_5 = void 0, __values(getDependents({
471
+ rowIndex: rowIndex,
472
+ columnIndex: columnIndex,
473
+ sheetId: destinationSheetId,
474
+ }))), _6 = _5.next(); !_6.done; _6 = _5.next()) {
475
+ var dependent = _6.value;
476
+ if (isStaticNode(dependent)) {
477
+ continue;
478
+ }
479
+ var position = dependent.position;
480
+ enqueue({
481
+ type: "add",
482
+ position: position,
483
+ force: true,
484
+ });
485
+ recalcCells.set(createSheetCellIdentifier(position.sheetId, position.rowIndex, position.columnIndex), position);
486
+ }
356
487
  }
357
- finally { if (e_4) throw e_4.error; }
488
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
489
+ finally {
490
+ try {
491
+ if (_6 && !_6.done && (_c = _5.return)) _c.call(_5);
492
+ }
493
+ finally { if (e_5) throw e_5.error; }
494
+ }
495
+ collectDataValidationTarget(dataValidationTargets, destinationSheetId, rowIndex, columnIndex, currentSheet[rowIndex].values[columnIndex]);
358
496
  }
359
- collectDataValidationTarget(dataValidationTargets, destinationSheetId, rowIndex, columnIndex, currentSheet[rowIndex].values[columnIndex]);
360
497
  }
361
498
  }
362
- }
363
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
364
- finally {
365
- try {
366
- if (destinationRows_1_1 && !destinationRows_1_1.done && (_b = destinationRows_1.return)) _b.call(destinationRows_1);
499
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
500
+ finally {
501
+ try {
502
+ if (destinationRows_1_1 && !destinationRows_1_1.done && (_b = destinationRows_1.return)) _b.call(destinationRows_1);
503
+ }
504
+ finally { if (e_4) throw e_4.error; }
367
505
  }
368
- finally { if (e_3) throw e_3.error; }
369
506
  }
370
- }
371
- if (currentTable && !isRowExpansion) {
372
- addCalculatedColumnsForRowExpansion({
373
- sheetId: destinationSheetId,
374
- currentTable: currentTable,
375
- draft: draft,
376
- enqueueCalculation: enqueue,
377
- recalcCells: recalcCells,
378
- locale: locale,
379
- range: to.range,
380
- getDependents: getDependents,
381
- });
382
- }
383
- // TBD: Move totalrow for tables
384
- // We are doing pure paste operation
385
- if (!isCutOperation) {
386
- var sheetCell = new SheetCell();
387
- var sourceCell = {
388
- rowIndex: to.range.startRowIndex,
389
- columnIndex: to.range.startColumnIndex,
390
- };
391
- try {
392
- for (var destinationRows_2 = __values(destinationRows), destinationRows_2_1 = destinationRows_2.next(); !destinationRows_2_1.done; destinationRows_2_1 = destinationRows_2.next()) {
393
- var _7 = destinationRows_2_1.value, rowIndex = _7.rowIndex, dataRowIndex = _7.dataRowIndex;
394
- var currentSheet = createSheetDraft(draft, destinationSheetId, rowIndex);
395
- var columnCursor = 0;
396
- for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++, columnCursor++) {
397
- var dataColumnIndex = colSpan > 0 ? columnCursor % colSpan : 0;
398
- var cellValue_2 = (_o = selectedRowValues[dataRowIndex]) === null || _o === void 0 ? void 0 : _o[dataColumnIndex];
399
- // Skip blanks: an empty clipboard cell leaves the
400
- // destination (value and format) untouched.
401
- if (pasteSpecial.skipBlanks &&
402
- isBlankClipboardCell(cellValue_2)) {
403
- continue;
404
- }
405
- // Operation: combine the pasted cell with the cell it
406
- // lands on. The clipboard is anchored at the FIRST tile,
407
- // so a source formula is relocated to the tile it lands
408
- // on first (the same `moveFormula` shift the plain paste
409
- // applies below); the composed `=(dest)op(source)` is
410
- // then anchored at the destination and must not be moved
411
- // again (that would shift the destination fragment too).
412
- if (pasteOperation) {
413
- var sourceFormula = getExtendedValueFormula(getCellUserEnteredValue(cellValue_2));
414
- if (!isNil(sourceFormula) &&
415
- dataRowIndex === 0 &&
416
- dataColumnIndex === 0 &&
417
- (rowIndex !== sourceCell.rowIndex ||
418
- columnIndex !== sourceCell.columnIndex)) {
419
- var tileCell = new SheetCell();
420
- tileCell.setLocale(locale);
421
- tileCell.assign(destinationSheetId, sourceCell, cellValue_2);
422
- tileCell.moveFormula(sourceCell, { rowIndex: rowIndex, columnIndex: columnIndex }, activeSheetName, { preserveAbsolutes: true });
423
- cellValue_2 = __assign(__assign({}, cellValue_2), { ue: __assign(__assign({}, cellValue_2 === null || cellValue_2 === void 0 ? void 0 : cellValue_2.ue), { fv: tileCell.formula }) });
507
+ // TBD: Move totalrow for tables
508
+ // We are doing pure paste operation
509
+ if (!isCutOperation) {
510
+ renameHeaderCellsInFormulas({
511
+ draft: draft,
512
+ headerRenames: headerRenames,
513
+ enqueueCalculation: enqueue,
514
+ enqueueGraphOperation: enqueueGraphOperation,
515
+ recalcCells: recalcCells,
516
+ locale: locale,
517
+ cellXfsRegistry: cellXfsRegistry,
518
+ sharedStringRegistry: sharedStringRegistry,
519
+ });
520
+ var sheetCell = new SheetCell();
521
+ var sourceCell = {
522
+ rowIndex: to.range.startRowIndex,
523
+ columnIndex: to.range.startColumnIndex,
524
+ };
525
+ try {
526
+ for (var destinationRows_2 = __values(destinationRows), destinationRows_2_1 = destinationRows_2.next(); !destinationRows_2_1.done; destinationRows_2_1 = destinationRows_2.next()) {
527
+ var _7 = destinationRows_2_1.value, rowIndex = _7.rowIndex, dataRowIndex = _7.dataRowIndex;
528
+ var currentSheet = createSheetDraft(draft, destinationSheetId, rowIndex);
529
+ var columnCursor = 0;
530
+ for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++, columnCursor++) {
531
+ var dataColumnIndex = colSpan > 0 ? columnCursor % colSpan : 0;
532
+ var cellValue = (_o = selectedRowValues[dataRowIndex]) === null || _o === void 0 ? void 0 : _o[dataColumnIndex];
533
+ // Skip blanks: an empty clipboard cell leaves the
534
+ // destination (value and format) untouched.
535
+ if (pasteSpecial.skipBlanks &&
536
+ isBlankClipboardCell(cellValue)) {
537
+ continue;
424
538
  }
425
- cellValue_2 = applyPasteOperation(cellValue_2, (_r = (_q = (_p = prevSheetData[destinationSheetId]) === null || _p === void 0 ? void 0 : _p[rowIndex]) === null || _q === void 0 ? void 0 : _q.values) === null || _r === void 0 ? void 0 : _r[columnIndex], pasteOperation, destinationSheetId, locale);
426
- }
427
- if (pasteMode === "formats") {
428
- var existingCellData = (_u = (_t = (_s = prevSheetData[destinationSheetId]) === null || _s === void 0 ? void 0 : _s[rowIndex]) === null || _t === void 0 ? void 0 : _t.values) === null || _u === void 0 ? void 0 : _u[columnIndex];
429
- cellValue_2 = __assign(__assign({}, existingCellData), cellValue_2);
430
- sheetCell.extendCellData(cellValue_2);
431
- }
432
- if (pasteMode === "values" || forcePlainText) {
433
- var existingCellData = (_x = (_w = (_v = prevSheetData[destinationSheetId]) === null || _v === void 0 ? void 0 : _v[rowIndex]) === null || _w === void 0 ? void 0 : _w.values) === null || _x === void 0 ? void 0 : _x[columnIndex];
434
- // Remove ss from existingCellData since we're replacing the value
435
- var _8 = existingCellData !== null && existingCellData !== void 0 ? existingCellData : {}, _ss = _8.ss, existingWithoutSs = __rest(_8, ["ss"]);
436
- cellValue_2 = __assign(__assign({}, existingWithoutSs), cellValue_2);
437
- sheetCell.extendCellData(cellValue_2);
438
- }
439
- if (pasteSpecial.transpose && pasteMode === "all") {
440
- sheetCell.assign(destinationSheetId, { rowIndex: rowIndex, columnIndex: columnIndex }, (_0 = (_z = (_y = prevSheetData[destinationSheetId]) === null || _y === void 0 ? void 0 : _y[rowIndex]) === null || _z === void 0 ? void 0 : _z.values) === null || _0 === void 0 ? void 0 : _0[columnIndex], {
441
- locale: locale,
442
- cellXfsRegistry: cellXfsRegistry,
443
- getDataValidationById: getDataValidationById,
444
- sharedStringRegistry: sharedStringRegistry,
445
- });
446
- var existingCellData = sheetCell.getUserCellData();
447
- cellValue_2 = __assign(__assign({}, existingCellData), cellValue_2);
448
- sheetCell.extendCellData(cellValue_2);
449
- }
450
- else {
451
- sheetCell.assign(destinationSheetId, { rowIndex: rowIndex, columnIndex: columnIndex }, typeof cellValue_2 === "object"
452
- ? cellValue_2
453
- : undefined, {
454
- getRangeValues: getEffectiveValuesFromRange,
455
- locale: locale,
456
- cellXfsRegistry: cellXfsRegistry,
457
- getDataValidationById: getDataValidationById,
458
- sharedStringRegistry: sharedStringRegistry,
459
- });
460
- }
461
- if (pasteMode === "formats") {
462
- sheetCell.refreshFormattedValue();
463
- }
464
- if (sheetCell.isFormula()) {
465
- if (dataRowIndex === 0 &&
466
- dataColumnIndex === 0 &&
467
- !pasteOperation) {
468
- sheetCell.moveFormula(sourceCell, {
539
+ // Operation: combine the pasted cell with the cell it
540
+ // lands on. The clipboard is anchored at the FIRST tile,
541
+ // so a source formula is relocated to the tile it lands
542
+ // on first (the same `moveFormula` shift the plain paste
543
+ // applies below); the composed `=(dest)op(source)` is
544
+ // then anchored at the destination and must not be moved
545
+ // again (that would shift the destination fragment too).
546
+ if (pasteOperation) {
547
+ var sourceFormula = getExtendedValueFormula(getCellUserEnteredValue(cellValue));
548
+ if (!isNil(sourceFormula) &&
549
+ dataRowIndex === 0 &&
550
+ dataColumnIndex === 0 &&
551
+ (rowIndex !== sourceCell.rowIndex ||
552
+ columnIndex !== sourceCell.columnIndex)) {
553
+ var tileCell = new SheetCell();
554
+ tileCell.setLocale(locale);
555
+ tileCell.assign(destinationSheetId, sourceCell, cellValue);
556
+ tileCell.moveFormula(sourceCell, { rowIndex: rowIndex, columnIndex: columnIndex }, activeSheetName, { preserveAbsolutes: true });
557
+ cellValue = __assign(__assign({}, cellValue), { ue: __assign(__assign({}, cellValue === null || cellValue === void 0 ? void 0 : cellValue.ue), { fv: tileCell.formula }) });
558
+ }
559
+ cellValue = applyPasteOperation(cellValue, (_r = (_q = (_p = prevSheetData[destinationSheetId]) === null || _p === void 0 ? void 0 : _p[rowIndex]) === null || _q === void 0 ? void 0 : _q.values) === null || _r === void 0 ? void 0 : _r[columnIndex], pasteOperation, destinationSheetId, locale);
560
+ }
561
+ if (pasteMode === "formats") {
562
+ var existingCellData = (_u = (_t = (_s = prevSheetData[destinationSheetId]) === null || _s === void 0 ? void 0 : _s[rowIndex]) === null || _t === void 0 ? void 0 : _t.values) === null || _u === void 0 ? void 0 : _u[columnIndex];
563
+ cellValue = __assign(__assign({}, existingCellData), cellValue);
564
+ sheetCell.extendCellData(cellValue);
565
+ }
566
+ if (pasteMode === "values" || forcePlainText) {
567
+ var existingCellData = (_x = (_w = (_v = prevSheetData[destinationSheetId]) === null || _v === void 0 ? void 0 : _v[rowIndex]) === null || _w === void 0 ? void 0 : _w.values) === null || _x === void 0 ? void 0 : _x[columnIndex];
568
+ // Remove ss from existingCellData since we're replacing the value
569
+ var _8 = existingCellData !== null && existingCellData !== void 0 ? existingCellData : {}, _ss = _8.ss, existingWithoutSs = __rest(_8, ["ss"]);
570
+ cellValue = __assign(__assign({}, existingWithoutSs), cellValue);
571
+ sheetCell.extendCellData(cellValue);
572
+ }
573
+ if (pasteSpecial.transpose && pasteMode === "all") {
574
+ sheetCell.assign(destinationSheetId, { rowIndex: rowIndex, columnIndex: columnIndex }, (_0 = (_z = (_y = prevSheetData[destinationSheetId]) === null || _y === void 0 ? void 0 : _y[rowIndex]) === null || _z === void 0 ? void 0 : _z.values) === null || _0 === void 0 ? void 0 : _0[columnIndex], {
575
+ locale: locale,
576
+ cellXfsRegistry: cellXfsRegistry,
577
+ getDataValidationById: getDataValidationById,
578
+ sharedStringRegistry: sharedStringRegistry,
579
+ });
580
+ var existingCellData = sheetCell.getUserCellData();
581
+ cellValue = __assign(__assign({}, existingCellData), cellValue);
582
+ sheetCell.extendCellData(cellValue);
583
+ }
584
+ else {
585
+ sheetCell.assign(destinationSheetId, { rowIndex: rowIndex, columnIndex: columnIndex }, typeof cellValue === "object"
586
+ ? cellValue
587
+ : undefined, {
588
+ getRangeValues: getEffectiveValuesFromRange,
589
+ locale: locale,
590
+ cellXfsRegistry: cellXfsRegistry,
591
+ getDataValidationById: getDataValidationById,
592
+ sharedStringRegistry: sharedStringRegistry,
593
+ });
594
+ }
595
+ if (pasteMode === "formats") {
596
+ sheetCell.refreshFormattedValue();
597
+ }
598
+ if (sheetCell.isFormula()) {
599
+ if (dataRowIndex === 0 &&
600
+ dataColumnIndex === 0 &&
601
+ !pasteOperation) {
602
+ sheetCell.moveFormula(sourceCell, {
603
+ rowIndex: rowIndex,
604
+ columnIndex: columnIndex,
605
+ }, activeSheetName, { preserveAbsolutes: true });
606
+ }
607
+ sheetCell.setLoading();
608
+ enqueue({
609
+ type: "add",
610
+ position: {
611
+ rowIndex: rowIndex,
612
+ columnIndex: columnIndex,
613
+ sheetId: destinationSheetId,
614
+ },
615
+ force: true,
616
+ });
617
+ recalcCells.set(createSheetCellIdentifier(destinationSheetId, rowIndex, columnIndex), {
469
618
  rowIndex: rowIndex,
470
619
  columnIndex: columnIndex,
471
- }, activeSheetName, { preserveAbsolutes: true });
620
+ sheetId: destinationSheetId,
621
+ });
472
622
  }
473
- sheetCell.setLoading();
474
- enqueue({
475
- type: "add",
476
- position: {
623
+ try {
624
+ for (var _9 = (e_7 = void 0, __values(getDependents({
477
625
  rowIndex: rowIndex,
478
626
  columnIndex: columnIndex,
479
627
  sheetId: destinationSheetId,
480
- },
481
- force: true,
482
- });
483
- recalcCells.set(createSheetCellIdentifier(destinationSheetId, rowIndex, columnIndex), {
484
- rowIndex: rowIndex,
485
- columnIndex: columnIndex,
486
- sheetId: destinationSheetId,
487
- });
628
+ }))), _10 = _9.next(); !_10.done; _10 = _9.next()) {
629
+ var dependent = _10.value;
630
+ if (isStaticNode(dependent)) {
631
+ continue;
632
+ }
633
+ var position = dependent.position;
634
+ enqueue({
635
+ type: "add",
636
+ position: position,
637
+ force: true,
638
+ });
639
+ recalcCells.set(createSheetCellIdentifier(position.sheetId, position.rowIndex, position.columnIndex), position);
640
+ }
641
+ }
642
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
643
+ finally {
644
+ try {
645
+ if (_10 && !_10.done && (_e = _9.return)) _e.call(_9);
646
+ }
647
+ finally { if (e_7) throw e_7.error; }
648
+ }
649
+ var headerRename = headerRenameAt.get("".concat(rowIndex, ":").concat(columnIndex));
650
+ if (headerRename) {
651
+ // A table header cell holds its column name as text.
652
+ sheetCell.setUserEnteredValue(headerRename.newName, undefined, { disableTypeInference: true });
653
+ }
654
+ sharedStringRegistry === null || sharedStringRegistry === void 0 ? void 0 : sharedStringRegistry.registerCell(sheetCell);
655
+ currentSheet[rowIndex].values[columnIndex] =
656
+ sheetCell.getCellData();
657
+ collectDataValidationTarget(dataValidationTargets, destinationSheetId, rowIndex, columnIndex, currentSheet[rowIndex].values[columnIndex]);
658
+ cellXfsRegistry === null || cellXfsRegistry === void 0 ? void 0 : cellXfsRegistry.registerCellXfs(sheetCell);
488
659
  }
660
+ }
661
+ }
662
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
663
+ finally {
664
+ try {
665
+ if (destinationRows_2_1 && !destinationRows_2_1.done && (_d = destinationRows_2.return)) _d.call(destinationRows_2);
666
+ }
667
+ finally { if (e_6) throw e_6.error; }
668
+ }
669
+ }
670
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
671
+ saveHistory({
672
+ sheetData: { patches: patches, inversePatches: inversePatches },
673
+ recalcCells: { undo: recalcCells, redo: recalcCells },
674
+ activeCell: {
675
+ undo: getActiveCell(),
676
+ redo: getActiveCell(),
677
+ },
678
+ selections: {
679
+ undo: undefined,
680
+ redo: isSelectionACell(nextSelections) ? undefined : [to],
681
+ },
682
+ });
683
+ extendDataValidationRanges(dataValidationTargets, onChangeDataValidations, saveHistory);
684
+ processQueue();
685
+ pastedSheetData = nextState;
686
+ return nextState;
687
+ });
688
+ // Save registries
689
+ cellXfsRegistry === null || cellXfsRegistry === void 0 ? void 0 : cellXfsRegistry.getPatches(saveHistory);
690
+ sharedStringRegistry === null || sharedStringRegistry === void 0 ? void 0 : sharedStringRegistry.getPatches(saveHistory);
691
+ // Update row or column count
692
+ // Change sheets
693
+ onChangeSheets === null || onChangeSheets === void 0 ? void 0 : onChangeSheets(function (prevSheets) {
694
+ var _a = __read(produceWithPatches(prevSheets, function (draft) {
695
+ var e_8, _a, e_9, _b, e_10, _c;
696
+ var _d, _e, _f, _g, _h;
697
+ var sheet = draft.find(function (sheet) { return sheet.sheetId === destinationSheetId; });
698
+ if (sheet) {
699
+ sheet.rowCount = Math.min(maxRowCount, Math.max((_d = sheet.rowCount) !== null && _d !== void 0 ? _d : DEFAULT_ROW_COUNT, to.range.endRowIndex));
700
+ sheet.columnCount = Math.min(maxColumnCount, Math.max((_e = sheet.columnCount) !== null && _e !== void 0 ? _e : DEFAULT_COLUMN_COUNT, to.range.endColumnIndex));
701
+ // Handle merges for cut operations
702
+ var mergesToAdd = merges;
703
+ if (isCutOperation && from && !isNil(sourceSheetId)) {
704
+ var sourceSheet = prevSheets.find(function (s) { return s.sheetId === sourceSheetId; });
705
+ if (sourceSheet === null || sourceSheet === void 0 ? void 0 : sourceSheet.merges) {
706
+ // Extract merged cells from source range
707
+ var cutMerges = [];
489
708
  try {
490
- for (var _9 = (e_6 = void 0, __values(getDependents({
491
- rowIndex: rowIndex,
492
- columnIndex: columnIndex,
493
- sheetId: destinationSheetId,
494
- }))), _10 = _9.next(); !_10.done; _10 = _9.next()) {
495
- var dependent = _10.value;
496
- if (isStaticNode(dependent)) {
497
- continue;
709
+ for (var _j = __values(sourceSheet.merges), _k = _j.next(); !_k.done; _k = _j.next()) {
710
+ var merge = _k.value;
711
+ // Check if merge intersects with the cut range
712
+ if (areaIntersects(merge, from.range)) {
713
+ // Calculate new merge coordinates relative to destination
714
+ cutMerges.push({
715
+ startRowIndex: merge.startRowIndex + rowDelta,
716
+ startColumnIndex: merge.startColumnIndex + columnDelta,
717
+ endRowIndex: merge.endRowIndex + rowDelta,
718
+ endColumnIndex: merge.endColumnIndex + columnDelta,
719
+ });
498
720
  }
499
- var position = dependent.position;
500
- enqueue({
501
- type: "add",
502
- position: position,
503
- force: true,
504
- });
505
- recalcCells.set(createSheetCellIdentifier(position.sheetId, position.rowIndex, position.columnIndex), position);
506
721
  }
507
722
  }
508
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
723
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
509
724
  finally {
510
725
  try {
511
- if (_10 && !_10.done && (_e = _9.return)) _e.call(_9);
726
+ if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
512
727
  }
513
- finally { if (e_6) throw e_6.error; }
728
+ finally { if (e_8) throw e_8.error; }
729
+ }
730
+ if (cutMerges.length > 0) {
731
+ mergesToAdd = cutMerges;
732
+ }
733
+ // Remove merges from source sheet
734
+ var sourceSheetDraft = draft.find(function (s) { return s.sheetId === sourceSheetId; });
735
+ if (sourceSheetDraft === null || sourceSheetDraft === void 0 ? void 0 : sourceSheetDraft.merges) {
736
+ sourceSheetDraft.merges = sourceSheetDraft.merges.filter(function (merge) { return !areaIntersects(merge, from.range); });
514
737
  }
515
- sharedStringRegistry === null || sharedStringRegistry === void 0 ? void 0 : sharedStringRegistry.registerCell(sheetCell);
516
- currentSheet[rowIndex].values[columnIndex] =
517
- sheetCell.getCellData();
518
- collectDataValidationTarget(dataValidationTargets, destinationSheetId, rowIndex, columnIndex, currentSheet[rowIndex].values[columnIndex]);
519
- cellXfsRegistry === null || cellXfsRegistry === void 0 ? void 0 : cellXfsRegistry.registerCellXfs(sheetCell);
520
738
  }
521
739
  }
522
- }
523
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
524
- finally {
525
- try {
526
- if (destinationRows_2_1 && !destinationRows_2_1.done && (_d = destinationRows_2.return)) _d.call(destinationRows_2);
527
- }
528
- finally { if (e_5) throw e_5.error; }
529
- }
530
- }
531
- }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
532
- saveHistory({
533
- sheetData: { patches: patches, inversePatches: inversePatches },
534
- recalcCells: { undo: recalcCells, redo: recalcCells },
535
- activeCell: {
536
- undo: getActiveCell(),
537
- redo: getActiveCell(),
538
- },
539
- selections: {
540
- undo: undefined,
541
- redo: isSelectionACell(nextSelections) ? undefined : [to],
542
- },
543
- });
544
- extendDataValidationRanges(dataValidationTargets, onChangeDataValidations, saveHistory);
545
- processQueue();
546
- pastedSheetData = nextState;
547
- return nextState;
548
- });
549
- // Save registries
550
- cellXfsRegistry === null || cellXfsRegistry === void 0 ? void 0 : cellXfsRegistry.getPatches(saveHistory);
551
- sharedStringRegistry === null || sharedStringRegistry === void 0 ? void 0 : sharedStringRegistry.getPatches(saveHistory);
552
- // Update row or column count
553
- // Change sheets
554
- onChangeSheets === null || onChangeSheets === void 0 ? void 0 : onChangeSheets(function (prevSheets) {
555
- var _a = __read(produceWithPatches(prevSheets, function (draft) {
556
- var e_7, _a, e_8, _b, e_9, _c;
557
- var _d, _e, _f, _g, _h;
558
- var sheet = draft.find(function (sheet) { return sheet.sheetId === destinationSheetId; });
559
- if (sheet) {
560
- sheet.rowCount = Math.min(maxRowCount, Math.max((_d = sheet.rowCount) !== null && _d !== void 0 ? _d : DEFAULT_ROW_COUNT, to.range.endRowIndex));
561
- sheet.columnCount = Math.min(maxColumnCount, Math.max((_e = sheet.columnCount) !== null && _e !== void 0 ? _e : DEFAULT_COLUMN_COUNT, to.range.endColumnIndex));
562
- // Handle merges for cut operations
563
- var mergesToAdd = merges;
564
- if (isCutOperation && from && !isNil(sourceSheetId)) {
565
- var sourceSheet = prevSheets.find(function (s) { return s.sheetId === sourceSheetId; });
566
- if (sourceSheet === null || sourceSheet === void 0 ? void 0 : sourceSheet.merges) {
567
- // Extract merged cells from source range
568
- var cutMerges = [];
740
+ // Update merges
741
+ if (mergesToAdd) {
742
+ sheet.merges = (_f = sheet.merges) !== null && _f !== void 0 ? _f : [];
743
+ var _loop_4 = function (merge) {
744
+ var exists = sheet.merges.find(function (range) {
745
+ return isAreasEqual(range, merge);
746
+ });
747
+ if (!exists) {
748
+ sheet.merges.push(merge);
749
+ }
750
+ };
569
751
  try {
570
- for (var _j = __values(sourceSheet.merges), _k = _j.next(); !_k.done; _k = _j.next()) {
571
- var merge = _k.value;
572
- // Check if merge intersects with the cut range
573
- if (areaIntersects(merge, from.range)) {
574
- // Calculate new merge coordinates relative to destination
575
- cutMerges.push({
576
- startRowIndex: merge.startRowIndex + rowDelta,
577
- startColumnIndex: merge.startColumnIndex + columnDelta,
578
- endRowIndex: merge.endRowIndex + rowDelta,
579
- endColumnIndex: merge.endColumnIndex + columnDelta,
580
- });
581
- }
752
+ for (var mergesToAdd_1 = __values(mergesToAdd), mergesToAdd_1_1 = mergesToAdd_1.next(); !mergesToAdd_1_1.done; mergesToAdd_1_1 = mergesToAdd_1.next()) {
753
+ var merge = mergesToAdd_1_1.value;
754
+ _loop_4(merge);
582
755
  }
583
756
  }
584
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
757
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
585
758
  finally {
586
759
  try {
587
- if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
760
+ if (mergesToAdd_1_1 && !mergesToAdd_1_1.done && (_b = mergesToAdd_1.return)) _b.call(mergesToAdd_1);
588
761
  }
589
- finally { if (e_7) throw e_7.error; }
590
- }
591
- if (cutMerges.length > 0) {
592
- mergesToAdd = cutMerges;
593
- }
594
- // Remove merges from source sheet
595
- var sourceSheetDraft = draft.find(function (s) { return s.sheetId === sourceSheetId; });
596
- if (sourceSheetDraft === null || sourceSheetDraft === void 0 ? void 0 : sourceSheetDraft.merges) {
597
- sourceSheetDraft.merges = sourceSheetDraft.merges.filter(function (merge) { return !areaIntersects(merge, from.range); });
762
+ finally { if (e_9) throw e_9.error; }
598
763
  }
599
764
  }
600
- }
601
- // Update merges
602
- if (mergesToAdd) {
603
- sheet.merges = (_f = sheet.merges) !== null && _f !== void 0 ? _f : [];
604
- var _loop_2 = function (merge) {
605
- var exists = sheet.merges.find(function (range) {
606
- return isAreasEqual(range, merge);
607
- });
608
- if (!exists) {
609
- sheet.merges.push(merge);
765
+ // Row heights
766
+ var clipboardSizedRows = new Set();
767
+ if (rowHeights) {
768
+ if (!sheet.rowMetadata) {
769
+ sheet.rowMetadata = [];
610
770
  }
611
- };
612
- try {
613
- for (var mergesToAdd_1 = __values(mergesToAdd), mergesToAdd_1_1 = mergesToAdd_1.next(); !mergesToAdd_1_1.done; mergesToAdd_1_1 = mergesToAdd_1.next()) {
614
- var merge = mergesToAdd_1_1.value;
615
- _loop_2(merge);
771
+ for (var index = 0; index < rowHeights.length; index++) {
772
+ var curHeight = rowHeights[index];
773
+ if (isNil(curHeight) || curHeight === 0) {
774
+ continue;
775
+ }
776
+ var rowIndex = visibleRowIndexes[index];
777
+ if (isNil(rowIndex)) {
778
+ break;
779
+ }
780
+ if (!sheet.rowMetadata[rowIndex]) {
781
+ sheet.rowMetadata[rowIndex] = {};
782
+ }
783
+ sheet.rowMetadata[rowIndex].size = curHeight;
784
+ clipboardSizedRows.add(rowIndex);
616
785
  }
617
786
  }
618
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
619
- finally {
787
+ // Auto-resize rows whose pasted content needs more room
788
+ // (multi-line text or wrap). Mirrors use-on-change's
789
+ // adjustRowHeight, but batched into this immer pass so the
790
+ // whole paste collapses to one undo entry. Skip conditions
791
+ // make the common single-line-text paste do zero work.
792
+ // Skipped for paste-special variants since the destination
793
+ // cell ends up as a merge of existing + pasted data, not
794
+ // the raw pasted value we can read from selectedRowValues.
795
+ var skipAutoResize = pasteSpecial.isSpecial;
796
+ if (!skipAutoResize &&
797
+ getFinalRowHeight &&
798
+ selectedRowValues.length &&
799
+ colSpan > 0) {
620
800
  try {
621
- if (mergesToAdd_1_1 && !mergesToAdd_1_1.done && (_b = mergesToAdd_1.return)) _b.call(mergesToAdd_1);
622
- }
623
- finally { if (e_8) throw e_8.error; }
624
- }
625
- }
626
- // Row heights
627
- var clipboardSizedRows = new Set();
628
- if (rowHeights) {
629
- if (!sheet.rowMetadata) {
630
- sheet.rowMetadata = [];
631
- }
632
- for (var index = 0; index < rowHeights.length; index++) {
633
- var curHeight = rowHeights[index];
634
- if (isNil(curHeight) || curHeight === 0) {
635
- continue;
636
- }
637
- var rowIndex = visibleRowIndexes[index];
638
- if (isNil(rowIndex)) {
639
- break;
640
- }
641
- if (!sheet.rowMetadata[rowIndex]) {
642
- sheet.rowMetadata[rowIndex] = {};
643
- }
644
- sheet.rowMetadata[rowIndex].size = curHeight;
645
- clipboardSizedRows.add(rowIndex);
646
- }
647
- }
648
- // Auto-resize rows whose pasted content needs more room
649
- // (multi-line text or wrap). Mirrors use-on-change's
650
- // adjustRowHeight, but batched into this immer pass so the
651
- // whole paste collapses to one undo entry. Skip conditions
652
- // make the common single-line-text paste do zero work.
653
- // Skipped for paste-special variants since the destination
654
- // cell ends up as a merge of existing + pasted data, not
655
- // the raw pasted value we can read from selectedRowValues.
656
- var skipAutoResize = pasteSpecial.isSpecial;
657
- if (!skipAutoResize &&
658
- getFinalRowHeight &&
659
- selectedRowValues.length &&
660
- colSpan > 0) {
661
- try {
662
- for (var destinationRows_3 = __values(destinationRows), destinationRows_3_1 = destinationRows_3.next(); !destinationRows_3_1.done; destinationRows_3_1 = destinationRows_3.next()) {
663
- var _l = destinationRows_3_1.value, rowIndex = _l.rowIndex, dataRowIndex = _l.dataRowIndex;
664
- // Clipboard-provided row heights win.
665
- if (clipboardSizedRows.has(rowIndex))
666
- continue;
667
- var rowData = selectedRowValues[dataRowIndex];
668
- if (!rowData)
669
- continue;
670
- // Find the cell most likely to drive row height —
671
- // most lines first, then any wrap. If no cell in
672
- // the row needs more than one line and no cell is
673
- // wrapped, the row's existing height already fits.
674
- var bestLines = 1;
675
- var bestColumnIndex = void 0;
676
- var bestCell = void 0;
677
- var bestHasWrap = false;
678
- var columnCursor = 0;
679
- for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++, columnCursor++) {
680
- var dataColumnIndex = columnCursor % colSpan;
681
- var cellValue_3 = rowData[dataColumnIndex];
682
- if (!cellValue_3 || typeof cellValue_3 !== "object")
801
+ for (var destinationRows_3 = __values(destinationRows), destinationRows_3_1 = destinationRows_3.next(); !destinationRows_3_1.done; destinationRows_3_1 = destinationRows_3.next()) {
802
+ var _l = destinationRows_3_1.value, rowIndex = _l.rowIndex, dataRowIndex = _l.dataRowIndex;
803
+ // Clipboard-provided row heights win.
804
+ if (clipboardSizedRows.has(rowIndex))
805
+ continue;
806
+ var rowData = selectedRowValues[dataRowIndex];
807
+ if (!rowData)
683
808
  continue;
684
- var ue_1 = getCellUserEnteredValue(cellValue_3);
685
- var text = getExtendedValueString(ue_1);
686
- var lines = typeof text === "string" && text.includes("\n")
687
- ? text.split("\n").length
688
- : 1;
689
- var uf_1 = getCellUserEnteredFormat(cellValue_3);
690
- var wrap = (uf_1 === null || uf_1 === void 0 ? void 0 : uf_1.wrapStrategy) === "wrap";
691
- if (lines > bestLines ||
692
- (lines === bestLines && wrap && !bestHasWrap)) {
693
- bestLines = lines;
694
- bestCell = cellValue_3;
695
- bestColumnIndex = columnIndex;
696
- bestHasWrap = wrap;
809
+ // Find the cell most likely to drive row height —
810
+ // most lines first, then any wrap. If no cell in
811
+ // the row needs more than one line and no cell is
812
+ // wrapped, the row's existing height already fits.
813
+ var bestLines = 1;
814
+ var bestColumnIndex = void 0;
815
+ var bestCell = void 0;
816
+ var bestHasWrap = false;
817
+ var columnCursor = 0;
818
+ for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++, columnCursor++) {
819
+ var dataColumnIndex = columnCursor % colSpan;
820
+ var cellValue = rowData[dataColumnIndex];
821
+ if (!cellValue || typeof cellValue !== "object")
822
+ continue;
823
+ var ue_1 = getCellUserEnteredValue(cellValue);
824
+ var text = getExtendedValueString(ue_1);
825
+ var lines = typeof text === "string" && text.includes("\n")
826
+ ? text.split("\n").length
827
+ : 1;
828
+ var uf_1 = getCellUserEnteredFormat(cellValue);
829
+ var wrap = (uf_1 === null || uf_1 === void 0 ? void 0 : uf_1.wrapStrategy) === "wrap";
830
+ if (lines > bestLines ||
831
+ (lines === bestLines && wrap && !bestHasWrap)) {
832
+ bestLines = lines;
833
+ bestCell = cellValue;
834
+ bestColumnIndex = columnIndex;
835
+ bestHasWrap = wrap;
836
+ }
697
837
  }
698
- }
699
- if (!bestCell ||
700
- bestColumnIndex === undefined ||
701
- (bestLines === 1 && !bestHasWrap)) {
702
- continue;
703
- }
704
- var ue = getCellUserEnteredValue(bestCell);
705
- var overrideText = (_g = getExtendedValueString(ue)) !== null && _g !== void 0 ? _g : "";
706
- var uf = getCellUserEnteredFormat(bestCell);
707
- var height = getFinalRowHeight(destinationSheetId, rowIndex, bestColumnIndex, {
708
- textOverride: String(overrideText),
709
- textFormatOverride: uf === null || uf === void 0 ? void 0 : uf.textFormat,
710
- shouldWrapOverride: bestHasWrap,
711
- });
712
- if (typeof height === "number" && height > 0) {
713
- if (!sheet.rowMetadata)
714
- sheet.rowMetadata = [];
715
- if (!sheet.rowMetadata[rowIndex]) {
716
- sheet.rowMetadata[rowIndex] = {};
838
+ if (!bestCell ||
839
+ bestColumnIndex === undefined ||
840
+ (bestLines === 1 && !bestHasWrap)) {
841
+ continue;
842
+ }
843
+ var ue = getCellUserEnteredValue(bestCell);
844
+ var overrideText = (_g = getExtendedValueString(ue)) !== null && _g !== void 0 ? _g : "";
845
+ var uf = getCellUserEnteredFormat(bestCell);
846
+ var height = getFinalRowHeight(destinationSheetId, rowIndex, bestColumnIndex, {
847
+ textOverride: String(overrideText),
848
+ textFormatOverride: uf === null || uf === void 0 ? void 0 : uf.textFormat,
849
+ shouldWrapOverride: bestHasWrap,
850
+ });
851
+ if (typeof height === "number" && height > 0) {
852
+ if (!sheet.rowMetadata)
853
+ sheet.rowMetadata = [];
854
+ if (!sheet.rowMetadata[rowIndex]) {
855
+ sheet.rowMetadata[rowIndex] = {};
856
+ }
857
+ sheet.rowMetadata[rowIndex].size = height;
858
+ sheet.rowMetadata[rowIndex].resizedByUser = false;
717
859
  }
718
- sheet.rowMetadata[rowIndex].size = height;
719
- sheet.rowMetadata[rowIndex].resizedByUser = false;
720
860
  }
721
861
  }
722
- }
723
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
724
- finally {
725
- try {
726
- if (destinationRows_3_1 && !destinationRows_3_1.done && (_c = destinationRows_3.return)) _c.call(destinationRows_3);
862
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
863
+ finally {
864
+ try {
865
+ if (destinationRows_3_1 && !destinationRows_3_1.done && (_c = destinationRows_3.return)) _c.call(destinationRows_3);
866
+ }
867
+ finally { if (e_10) throw e_10.error; }
727
868
  }
728
- finally { if (e_9) throw e_9.error; }
729
869
  }
730
- }
731
- // column widths
732
- if (columnWidths) {
733
- if (!sheet.columnMetadata) {
734
- sheet.columnMetadata = [];
735
- }
736
- for (var index = 0; index < columnWidths.length; index++) {
737
- var curWidth = columnWidths[index];
738
- if (isNil(curWidth) || curWidth === 0) {
739
- continue;
870
+ // column widths
871
+ if (columnWidths) {
872
+ if (!sheet.columnMetadata) {
873
+ sheet.columnMetadata = [];
740
874
  }
741
- var columnIndex = to.range.startColumnIndex + index;
742
- if (!((_h = sheet.columnMetadata) === null || _h === void 0 ? void 0 : _h[columnIndex])) {
743
- sheet.columnMetadata[columnIndex] = {};
875
+ for (var index = 0; index < columnWidths.length; index++) {
876
+ var curWidth = columnWidths[index];
877
+ if (isNil(curWidth) || curWidth === 0) {
878
+ continue;
879
+ }
880
+ var columnIndex = to.range.startColumnIndex + index;
881
+ if (!((_h = sheet.columnMetadata) === null || _h === void 0 ? void 0 : _h[columnIndex])) {
882
+ sheet.columnMetadata[columnIndex] = {};
883
+ }
884
+ sheet.columnMetadata[columnIndex].size =
885
+ columnWidths[index];
744
886
  }
745
- sheet.columnMetadata[columnIndex].size =
746
- columnWidths[index];
747
887
  }
748
888
  }
749
- }
750
- }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
751
- saveHistory({
752
- sheets: { patches: patches, inversePatches: inversePatches },
753
- });
754
- return nextState;
755
- });
756
- // For row expansions, add columns
757
- onChangeTableColumn(destinationSheetId, activeCell, activeCellValue !== null && activeCellValue !== void 0 ? activeCellValue : undefined, adjacentTable, isRowExpansion, isColumnExpansion, to.range);
758
- // Add calculated column
759
- onChangeCalculatedColumn(destinationSheetId, activeCell, activeCellValue !== null && activeCellValue !== void 0 ? activeCellValue : undefined, currentTable);
760
- // Update new selections
761
- if (!isSelectionACell(nextSelections)) {
762
- onChangeSelections === null || onChangeSelections === void 0 ? void 0 : onChangeSelections(destinationSheetId, [to]);
763
- }
764
- // Update active cell
765
- onChangeActiveCell(destinationSheetId, __assign({}, getActiveCell()));
766
- // Stream the paste to an engine consumer. The clipboard is a bounded payload (not
767
- // windowed), so paste can resolve the destination cells UI-side; we read back the
768
- // user-entered values the paste actually produced — relocated formulas, paste-special
769
- // merges, shared-string text — and replay them as a `change-batch` the engine recomputes
770
- // from. Reading the produced state (rather than re-deriving) keeps this correct across the
771
- // cut / pure-paste / paste-special branches without duplicating their logic.
772
- if (onCommand && pastedSheetData) {
773
- values = [];
774
- for (rowIndex = to.range.startRowIndex; rowIndex <= to.range.endRowIndex; rowIndex++) {
775
- row = [];
776
- for (columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++) {
777
- cell = (_v = (_u = (_t = pastedSheetData[destinationSheetId]) === null || _t === void 0 ? void 0 : _t[rowIndex]) === null || _u === void 0 ? void 0 : _u.values) === null || _v === void 0 ? void 0 : _v[columnIndex];
778
- ue = cell ? getCellUserEnteredValue(cell) : undefined;
779
- // Formula text wins (e.g. "=SUM(A1:A2)"), else the literal string / number / bool.
780
- // `??` (not `||`) so 0 and false survive; `null` clears the cell.
781
- row.push((_z = (_y = (_x = (_w = getExtendedValueFormula(ue)) !== null && _w !== void 0 ? _w : getExtendedValueString(ue)) !== null && _x !== void 0 ? _x : getExtendedValueNumber(ue)) !== null && _y !== void 0 ? _y : getExtendedValueBool(ue)) !== null && _z !== void 0 ? _z : null);
782
- }
783
- values.push(row);
784
- }
785
- onCommand({
786
- command: "change-batch",
787
- sheetId: destinationSheetId,
788
- ranges: to.range,
789
- values: values,
790
- });
791
- // On cut, the source cells were cleared — mirror that so the engine drops them too.
792
- if (isCutOperation && from && !isNil(sourceSheetId)) {
793
- onCommand({
794
- command: "delete-cells",
795
- sheetId: sourceSheetId,
796
- activeCell: {
797
- rowIndex: from.range.startRowIndex,
798
- columnIndex: from.range.startColumnIndex,
799
- },
800
- selections: [{ range: from.range }],
889
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
890
+ saveHistory({
891
+ sheets: { patches: patches, inversePatches: inversePatches },
801
892
  });
802
- }
803
- }
804
- }
805
- // Embeds
806
- if (embeds === null || embeds === void 0 ? void 0 : embeds.length) {
807
- firstEmbedId_1 = embeds[0].embedId;
808
- onChangeEmbeds === null || onChangeEmbeds === void 0 ? void 0 : onChangeEmbeds(function (prevEmbeds) {
809
- var _a = __read(produceWithPatches(prevEmbeds, function (draft) {
810
- draft.push.apply(draft, __spreadArray([], __read(embeds), false));
811
- }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
812
- saveHistory({
813
- embeds: { patches: patches, inversePatches: inversePatches },
814
- selectedEmbedOrChart: { redo: firstEmbedId_1, undo: undefined },
893
+ return nextState;
815
894
  });
816
- return nextState;
817
- });
818
- // Selected first embed
819
- focusEmbedOrChart(embeds[0].embedId);
820
- }
821
- // Tables
822
- if (tables === null || tables === void 0 ? void 0 : tables.length) {
823
- onChangeTables === null || onChangeTables === void 0 ? void 0 : onChangeTables(function (prevTables) {
824
- var _a = __read(produceWithPatches(prevTables, function (draft) {
825
- draft.push.apply(draft, __spreadArray([], __read(tables), false));
826
- }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
827
- saveHistory({
828
- tables: { patches: patches, inversePatches: inversePatches },
829
- });
830
- return nextState;
831
- });
832
- }
833
- // Handle citations
834
- if (selectedRowValues.length && onChangeCitations) {
835
- citationIdMap_1 = new Map();
836
- for (dataRowIndex = 0; dataRowIndex < rowSpan; dataRowIndex++) {
837
- rowData = selectedRowValues[dataRowIndex];
838
- if (!rowData)
839
- continue;
840
- for (dataColumnIndex = 0; dataColumnIndex < colSpan; dataColumnIndex++) {
841
- cellValue_1 = rowData[dataColumnIndex];
842
- if (cellValue_1 &&
843
- typeof cellValue_1 === "object" &&
844
- "citationId" in cellValue_1 &&
845
- cellValue_1.citationId) {
846
- citationIdMap_1.set(cellValue_1.citationId, {
847
- sourceRowIndex: dataRowIndex,
848
- sourceColumnIndex: dataColumnIndex,
895
+ // For row expansions, add columns
896
+ onChangeTableColumn(destinationSheetId, activeCell, activeCellValue !== null && activeCellValue !== void 0 ? activeCellValue : undefined, adjacentTable, isRowExpansion, isColumnExpansion, to.range, pastedHeaderValues);
897
+ // Add calculated column
898
+ onChangeCalculatedColumn(destinationSheetId, activeCell, activeCellValue !== null && activeCellValue !== void 0 ? activeCellValue : undefined, currentTable);
899
+ // Update new selections
900
+ if (!isSelectionACell(nextSelections)) {
901
+ onChangeSelections === null || onChangeSelections === void 0 ? void 0 : onChangeSelections(destinationSheetId, [to]);
902
+ }
903
+ // Update active cell
904
+ onChangeActiveCell(destinationSheetId, __assign({}, getActiveCell()));
905
+ // Stream the paste to an engine consumer. The clipboard is a bounded payload (not
906
+ // windowed), so paste can resolve the destination cells UI-side; we read back the
907
+ // user-entered values the paste actually produced — relocated formulas, paste-special
908
+ // merges, shared-string text — and replay them as a `change-batch` the engine recomputes
909
+ // from. Reading the produced state (rather than re-deriving) keeps this correct across the
910
+ // cut / pure-paste / paste-special branches without duplicating their logic.
911
+ if (onCommand && pastedSheetData) {
912
+ var values = [];
913
+ for (var rowIndex = to.range.startRowIndex; rowIndex <= to.range.endRowIndex; rowIndex++) {
914
+ var row = [];
915
+ for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++) {
916
+ var cell = (_l = (_k = (_j = pastedSheetData[destinationSheetId]) === null || _j === void 0 ? void 0 : _j[rowIndex]) === null || _k === void 0 ? void 0 : _k.values) === null || _l === void 0 ? void 0 : _l[columnIndex];
917
+ var ue = cell ? getCellUserEnteredValue(cell) : undefined;
918
+ // Formula text wins (e.g. "=SUM(A1:A2)"), else the literal string / number / bool.
919
+ // `??` (not `||`) so 0 and false survive; `null` clears the cell.
920
+ row.push((_q = (_p = (_o = (_m = getExtendedValueFormula(ue)) !== null && _m !== void 0 ? _m : getExtendedValueString(ue)) !== null && _o !== void 0 ? _o : getExtendedValueNumber(ue)) !== null && _p !== void 0 ? _p : getExtendedValueBool(ue)) !== null && _q !== void 0 ? _q : null);
921
+ }
922
+ values.push(row);
923
+ }
924
+ onCommand(__assign(__assign({ command: "change-batch", sheetId: destinationSheetId, ranges: to.range, values: values }, (autoExpandTables ? {} : { autoExpandTables: autoExpandTables })), (autoCalculatedColumns ? {} : { autoCalculatedColumns: autoCalculatedColumns })));
925
+ // On cut, the source cells were cleared — mirror that so the engine drops them too.
926
+ if (isCutOperation && from && !isNil(sourceSheetId)) {
927
+ onCommand({
928
+ command: "delete-cells",
929
+ sheetId: sourceSheetId,
930
+ activeCell: {
931
+ rowIndex: from.range.startRowIndex,
932
+ columnIndex: from.range.startColumnIndex,
933
+ },
934
+ selections: [{ range: from.range }],
849
935
  });
850
936
  }
851
937
  }
852
938
  }
853
- if (citationIdMap_1.size > 0) {
854
- if (isCutOperation && from && !isNil(sourceSheetId)) {
855
- // For cut operation: Move citations to new position
856
- onChangeCitations(function (prevCitations) {
857
- var _a = __read(produceWithPatches(prevCitations, function (draft) {
858
- var e_10, _a;
859
- var _loop_3 = function (citationId) {
860
- var citation = draft.find(function (c) { return c.id === citationId; });
861
- if (citation) {
862
- // Update citation range to new position
863
- citation.range.sheetId = destinationSheetId;
864
- citation.range.startRowIndex += rowDelta;
865
- citation.range.endRowIndex += rowDelta;
866
- citation.range.startColumnIndex += columnDelta;
867
- citation.range.endColumnIndex += columnDelta;
939
+ // Defined names wholly inside the cut block follow it (Excel move semantics); a name the
940
+ // block covers only partially keeps referring to its original area.
941
+ if (isCutOperation && from && !isNil(sourceSheetId)) {
942
+ onChangeNamedRanges === null || onChangeNamedRanges === void 0 ? void 0 : onChangeNamedRanges(function (prevNamedRanges) {
943
+ var _a = __read(produceWithPatches(prevNamedRanges, function (draft) {
944
+ var e_11, _a;
945
+ var _b;
946
+ try {
947
+ for (var draft_1 = __values(draft), draft_1_1 = draft_1.next(); !draft_1_1.done; draft_1_1 = draft_1.next()) {
948
+ var namedRange = draft_1_1.value;
949
+ if (((_b = namedRange.range) === null || _b === void 0 ? void 0 : _b.sheetId) === sourceSheetId &&
950
+ areaInsideArea(namedRange.range, from.range)) {
951
+ namedRange.range = __assign(__assign({}, moveRange(namedRange.range, from.range, to.range)), { sheetId: destinationSheetId });
952
+ }
953
+ }
954
+ }
955
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
956
+ finally {
957
+ try {
958
+ if (draft_1_1 && !draft_1_1.done && (_a = draft_1.return)) _a.call(draft_1);
959
+ }
960
+ finally { if (e_11) throw e_11.error; }
961
+ }
962
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
963
+ if (!patches.length) {
964
+ return prevNamedRanges;
965
+ }
966
+ saveHistory({ namedRanges: { patches: patches, inversePatches: inversePatches } });
967
+ return nextState;
968
+ });
969
+ onChangeCharts === null || onChangeCharts === void 0 ? void 0 : onChangeCharts(function (prevCharts) {
970
+ var _a = __read(produceWithPatches(prevCharts, function (draft) {
971
+ moveChartsOnRangeMove(draft, sourceSheetId, from.range, destinationSheetId, to.range);
972
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
973
+ if (!patches.length) {
974
+ return prevCharts;
975
+ }
976
+ saveHistory({ charts: { patches: patches, inversePatches: inversePatches } });
977
+ return nextState;
978
+ });
979
+ // The tables the cut block covers whole move with their cells (same history step): the
980
+ // range lands at the destination — on another sheet too — and the column-indexed filter
981
+ // and sort specs follow it, so the table's filters and its structured references keep
982
+ // resolving there.
983
+ if (movedTables.length) {
984
+ var columnDelta_1 = to.range.startColumnIndex - from.range.startColumnIndex;
985
+ onChangeTables === null || onChangeTables === void 0 ? void 0 : onChangeTables(function (prevTables) {
986
+ var _a = __read(produceWithPatches(prevTables, function (draft) {
987
+ var e_12, _a;
988
+ var _b, _c;
989
+ var _loop_5 = function (table) {
990
+ var e_13, _d, e_14, _e;
991
+ if (!movedTables.some(function (moved) { return moved.id === table.id; })) {
992
+ return "continue";
993
+ }
994
+ table.sheetId = destinationSheetId;
995
+ var range = moveRange(table.range, from.range, to.range);
996
+ table.range =
997
+ "sheetId" in range
998
+ ? __assign(__assign({}, range), { sheetId: destinationSheetId }) : range;
999
+ try {
1000
+ for (var _f = (e_13 = void 0, __values((_b = table.filterSpecs) !== null && _b !== void 0 ? _b : [])), _g = _f.next(); !_g.done; _g = _f.next()) {
1001
+ var spec = _g.value;
1002
+ spec.columnIndex += columnDelta_1;
1003
+ }
1004
+ }
1005
+ catch (e_13_1) { e_13 = { error: e_13_1 }; }
1006
+ finally {
1007
+ try {
1008
+ if (_g && !_g.done && (_d = _f.return)) _d.call(_f);
1009
+ }
1010
+ finally { if (e_13) throw e_13.error; }
1011
+ }
1012
+ try {
1013
+ for (var _h = (e_14 = void 0, __values((_c = table.sortSpecs) !== null && _c !== void 0 ? _c : [])), _j = _h.next(); !_j.done; _j = _h.next()) {
1014
+ var spec = _j.value;
1015
+ spec.dimensionIndex += columnDelta_1;
1016
+ }
1017
+ }
1018
+ catch (e_14_1) { e_14 = { error: e_14_1 }; }
1019
+ finally {
1020
+ try {
1021
+ if (_j && !_j.done && (_e = _h.return)) _e.call(_h);
1022
+ }
1023
+ finally { if (e_14) throw e_14.error; }
868
1024
  }
869
1025
  };
870
1026
  try {
871
- for (var _b = __values(citationIdMap_1.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
872
- var citationId = _c.value;
873
- _loop_3(citationId);
1027
+ for (var draft_2 = __values(draft), draft_2_1 = draft_2.next(); !draft_2_1.done; draft_2_1 = draft_2.next()) {
1028
+ var table = draft_2_1.value;
1029
+ _loop_5(table);
874
1030
  }
875
1031
  }
876
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
1032
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
877
1033
  finally {
878
1034
  try {
879
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1035
+ if (draft_2_1 && !draft_2_1.done && (_a = draft_2.return)) _a.call(draft_2);
880
1036
  }
881
- finally { if (e_10) throw e_10.error; }
1037
+ finally { if (e_12) throw e_12.error; }
882
1038
  }
883
1039
  }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
884
- saveHistory({
885
- citations: { patches: patches, inversePatches: inversePatches },
886
- });
1040
+ saveHistory({ tables: { patches: patches, inversePatches: inversePatches } });
887
1041
  return nextState;
888
1042
  });
889
1043
  }
890
- else if (!isCutOperation) {
891
- newCitations_1 = [];
892
- citationIdRemap_1 = new Map();
893
- _loop_1 = function (oldCitationId, sourceRowIndex, sourceColumnIndex) {
894
- var originalCitation = citations === null || citations === void 0 ? void 0 : citations.find(function (c) { return c.id === oldCitationId; });
895
- if (originalCitation) {
896
- var newId = uuidString();
897
- citationIdRemap_1.set(oldCitationId, newId);
898
- // Calculate the new range based on paste destination
899
- var newCitation = __assign(__assign({}, originalCitation), { id: newId, range: {
900
- sheetId: destinationSheetId,
901
- startRowIndex: to.range.startRowIndex + sourceRowIndex,
902
- endRowIndex: to.range.startRowIndex + sourceRowIndex,
903
- startColumnIndex: to.range.startColumnIndex + sourceColumnIndex,
904
- endColumnIndex: to.range.startColumnIndex + sourceColumnIndex,
905
- } });
906
- newCitations_1.push(newCitation);
1044
+ }
1045
+ // Embeds
1046
+ if (embeds === null || embeds === void 0 ? void 0 : embeds.length) {
1047
+ var firstEmbedId_1 = embeds[0].embedId;
1048
+ onChangeEmbeds === null || onChangeEmbeds === void 0 ? void 0 : onChangeEmbeds(function (prevEmbeds) {
1049
+ var _a = __read(produceWithPatches(prevEmbeds, function (draft) {
1050
+ draft.push.apply(draft, __spreadArray([], __read(embeds), false));
1051
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
1052
+ saveHistory({
1053
+ embeds: { patches: patches, inversePatches: inversePatches },
1054
+ selectedEmbedOrChart: { redo: firstEmbedId_1, undo: undefined },
1055
+ });
1056
+ return nextState;
1057
+ });
1058
+ // Selected first embed
1059
+ focusEmbedOrChart(embeds[0].embedId);
1060
+ }
1061
+ // Tables
1062
+ if (tables === null || tables === void 0 ? void 0 : tables.length) {
1063
+ onChangeTables === null || onChangeTables === void 0 ? void 0 : onChangeTables(function (prevTables) {
1064
+ var _a = __read(produceWithPatches(prevTables, function (draft) {
1065
+ var e_15, _a;
1066
+ try {
1067
+ // Excel names a pasted table like a new one — the next free `TableN` — never
1068
+ // `Copy of <title>`, which is not a valid table name (it has a space).
1069
+ for (var tables_1 = __values(tables), tables_1_1 = tables_1.next(); !tables_1_1.done; tables_1_1 = tables_1.next()) {
1070
+ var table = tables_1_1.value;
1071
+ draft.push(__assign(__assign({}, table), { title: getNextTableTitle(draft, generatedNames) }));
1072
+ }
907
1073
  }
908
- };
909
- try {
910
- for (_c = __values(citationIdMap_1.entries()), _d = _c.next(); !_d.done; _d = _c.next()) {
911
- _e = __read(_d.value, 2), oldCitationId = _e[0], _f = _e[1], sourceRowIndex = _f.sourceRowIndex, sourceColumnIndex = _f.sourceColumnIndex;
912
- _loop_1(oldCitationId, sourceRowIndex, sourceColumnIndex);
1074
+ catch (e_15_1) { e_15 = { error: e_15_1 }; }
1075
+ finally {
1076
+ try {
1077
+ if (tables_1_1 && !tables_1_1.done && (_a = tables_1.return)) _a.call(tables_1);
1078
+ }
1079
+ finally { if (e_15) throw e_15.error; }
913
1080
  }
914
- }
915
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
916
- finally {
917
- try {
918
- if (_d && !_d.done && (_g = _c.return)) _g.call(_c);
1081
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
1082
+ saveHistory({
1083
+ tables: { patches: patches, inversePatches: inversePatches },
1084
+ });
1085
+ return nextState;
1086
+ });
1087
+ }
1088
+ // Handle citations
1089
+ if (selectedRowValues.length && onChangeCitations) {
1090
+ // Collect citationIds from pasted cells
1091
+ var citationIdMap_1 = new Map();
1092
+ for (var dataRowIndex = 0; dataRowIndex < rowSpan; dataRowIndex++) {
1093
+ var rowData = selectedRowValues[dataRowIndex];
1094
+ if (!rowData)
1095
+ continue;
1096
+ for (var dataColumnIndex = 0; dataColumnIndex < colSpan; dataColumnIndex++) {
1097
+ var cellValue = rowData[dataColumnIndex];
1098
+ if (cellValue &&
1099
+ typeof cellValue === "object" &&
1100
+ "citationId" in cellValue &&
1101
+ cellValue.citationId) {
1102
+ citationIdMap_1.set(cellValue.citationId, {
1103
+ sourceRowIndex: dataRowIndex,
1104
+ sourceColumnIndex: dataColumnIndex,
1105
+ });
919
1106
  }
920
- finally { if (e_1) throw e_1.error; }
921
1107
  }
922
- if (newCitations_1.length > 0) {
923
- // Add new citations
1108
+ }
1109
+ if (citationIdMap_1.size > 0) {
1110
+ if (isCutOperation && from && !isNil(sourceSheetId)) {
1111
+ // For cut operation: Move citations to new position
924
1112
  onChangeCitations(function (prevCitations) {
925
1113
  var _a = __read(produceWithPatches(prevCitations, function (draft) {
926
- draft.push.apply(draft, __spreadArray([], __read(newCitations_1), false));
927
- }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
928
- saveHistory({
929
- citations: { patches: patches, inversePatches: inversePatches },
930
- });
931
- return nextState;
932
- });
933
- // Update cell citationIds to point to new citations
934
- onChangeSheetData === null || onChangeSheetData === void 0 ? void 0 : onChangeSheetData(function (prevSheetData) {
935
- var _a = __read(produceWithPatches(prevSheetData, function (draft) {
936
- var e_11, _a;
937
- var _b, _c, _d;
1114
+ var e_16, _a;
1115
+ var _loop_6 = function (citationId) {
1116
+ var citation = draft.find(function (c) { return c.id === citationId; });
1117
+ if (citation) {
1118
+ // Update citation range to new position
1119
+ citation.range.sheetId = destinationSheetId;
1120
+ citation.range.startRowIndex += rowDelta;
1121
+ citation.range.endRowIndex += rowDelta;
1122
+ citation.range.startColumnIndex += columnDelta;
1123
+ citation.range.endColumnIndex += columnDelta;
1124
+ }
1125
+ };
938
1126
  try {
939
- for (var destinationRows_4 = __values(destinationRows), destinationRows_4_1 = destinationRows_4.next(); !destinationRows_4_1.done; destinationRows_4_1 = destinationRows_4.next()) {
940
- var rowIndex = destinationRows_4_1.value.rowIndex;
941
- for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++) {
942
- var cellData = (_d = (_c = (_b = draft[destinationSheetId]) === null || _b === void 0 ? void 0 : _b[rowIndex]) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d[columnIndex];
943
- if (cellData === null || cellData === void 0 ? void 0 : cellData.citationId) {
944
- var newCitationId = citationIdRemap_1.get(cellData.citationId);
945
- if (newCitationId) {
946
- cellData.citationId = newCitationId;
947
- }
948
- }
949
- }
1127
+ for (var _b = __values(citationIdMap_1.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
1128
+ var citationId = _c.value;
1129
+ _loop_6(citationId);
950
1130
  }
951
1131
  }
952
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
1132
+ catch (e_16_1) { e_16 = { error: e_16_1 }; }
953
1133
  finally {
954
1134
  try {
955
- if (destinationRows_4_1 && !destinationRows_4_1.done && (_a = destinationRows_4.return)) _a.call(destinationRows_4);
1135
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
956
1136
  }
957
- finally { if (e_11) throw e_11.error; }
1137
+ finally { if (e_16) throw e_16.error; }
958
1138
  }
959
1139
  }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
960
1140
  saveHistory({
961
- sheetData: { patches: patches, inversePatches: inversePatches },
1141
+ citations: { patches: patches, inversePatches: inversePatches },
962
1142
  });
963
1143
  return nextState;
964
1144
  });
965
1145
  }
1146
+ else if (!isCutOperation) {
1147
+ // For paste (copy) operation: Create new citations with new IDs
1148
+ var newCitations_1 = [];
1149
+ var citationIdRemap_1 = new Map();
1150
+ var _loop_2 = function (oldCitationId, sourceRowIndex, sourceColumnIndex) {
1151
+ var originalCitation = citations === null || citations === void 0 ? void 0 : citations.find(function (c) { return c.id === oldCitationId; });
1152
+ if (originalCitation) {
1153
+ var newId = uuidString();
1154
+ citationIdRemap_1.set(oldCitationId, newId);
1155
+ // Calculate the new range based on paste destination
1156
+ var newCitation = __assign(__assign({}, originalCitation), { id: newId, range: {
1157
+ sheetId: destinationSheetId,
1158
+ startRowIndex: to.range.startRowIndex + sourceRowIndex,
1159
+ endRowIndex: to.range.startRowIndex + sourceRowIndex,
1160
+ startColumnIndex: to.range.startColumnIndex + sourceColumnIndex,
1161
+ endColumnIndex: to.range.startColumnIndex + sourceColumnIndex,
1162
+ } });
1163
+ newCitations_1.push(newCitation);
1164
+ }
1165
+ };
1166
+ try {
1167
+ for (var _t = __values(citationIdMap_1.entries()), _u = _t.next(); !_u.done; _u = _t.next()) {
1168
+ var _v = __read(_u.value, 2), oldCitationId = _v[0], _w = _v[1], sourceRowIndex = _w.sourceRowIndex, sourceColumnIndex = _w.sourceColumnIndex;
1169
+ _loop_2(oldCitationId, sourceRowIndex, sourceColumnIndex);
1170
+ }
1171
+ }
1172
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1173
+ finally {
1174
+ try {
1175
+ if (_u && !_u.done && (_a = _t.return)) _a.call(_t);
1176
+ }
1177
+ finally { if (e_1) throw e_1.error; }
1178
+ }
1179
+ if (newCitations_1.length > 0) {
1180
+ // Add new citations
1181
+ onChangeCitations(function (prevCitations) {
1182
+ var _a = __read(produceWithPatches(prevCitations, function (draft) {
1183
+ draft.push.apply(draft, __spreadArray([], __read(newCitations_1), false));
1184
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
1185
+ saveHistory({
1186
+ citations: { patches: patches, inversePatches: inversePatches },
1187
+ });
1188
+ return nextState;
1189
+ });
1190
+ // Update cell citationIds to point to new citations
1191
+ onChangeSheetData === null || onChangeSheetData === void 0 ? void 0 : onChangeSheetData(function (prevSheetData) {
1192
+ var _a = __read(produceWithPatches(prevSheetData, function (draft) {
1193
+ var e_17, _a;
1194
+ var _b, _c, _d;
1195
+ try {
1196
+ for (var destinationRows_4 = __values(destinationRows), destinationRows_4_1 = destinationRows_4.next(); !destinationRows_4_1.done; destinationRows_4_1 = destinationRows_4.next()) {
1197
+ var rowIndex = destinationRows_4_1.value.rowIndex;
1198
+ for (var columnIndex = to.range.startColumnIndex; columnIndex <= to.range.endColumnIndex; columnIndex++) {
1199
+ var cellData = (_d = (_c = (_b = draft[destinationSheetId]) === null || _b === void 0 ? void 0 : _b[rowIndex]) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d[columnIndex];
1200
+ if (cellData === null || cellData === void 0 ? void 0 : cellData.citationId) {
1201
+ var newCitationId = citationIdRemap_1.get(cellData.citationId);
1202
+ if (newCitationId) {
1203
+ cellData.citationId = newCitationId;
1204
+ }
1205
+ }
1206
+ }
1207
+ }
1208
+ }
1209
+ catch (e_17_1) { e_17 = { error: e_17_1 }; }
1210
+ finally {
1211
+ try {
1212
+ if (destinationRows_4_1 && !destinationRows_4_1.done && (_a = destinationRows_4.return)) _a.call(destinationRows_4);
1213
+ }
1214
+ finally { if (e_17) throw e_17.error; }
1215
+ }
1216
+ }), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
1217
+ saveHistory({
1218
+ sheetData: { patches: patches, inversePatches: inversePatches },
1219
+ });
1220
+ return nextState;
1221
+ });
1222
+ }
1223
+ }
966
1224
  }
967
1225
  }
968
- }
1226
+ });
969
1227
  return [2 /*return*/];
970
1228
  }
971
1229
  });
@@ -985,6 +1243,9 @@ export var useOnPaste = function (_a) {
985
1243
  onRequestFonts,
986
1244
  idCreationStrategy,
987
1245
  createHistory,
1246
+ batchHistory,
1247
+ autoExpandTables,
1248
+ autoCalculatedColumns,
988
1249
  enqueueStructureChange,
989
1250
  enqueueGraphOperation,
990
1251
  onChangeCalculatedColumn,
@@ -1011,5 +1272,9 @@ export var useOnPaste = function (_a) {
1011
1272
  getFinalRowHeight,
1012
1273
  onCommand,
1013
1274
  generatedNames,
1275
+ onChangeNamedRanges,
1276
+ onChangeCharts,
1277
+ getSheetMerges,
1278
+ showError,
1014
1279
  ]);
1015
1280
  };