@rowsncolumns/spreadsheet-state 29.0.0 → 29.1.1

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