@rowsncolumns/spreadsheet-state 28.0.75 → 29.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/dist/cjs/api/anchored-objects.d.ts +66 -0
  2. package/dist/cjs/api/anchored-objects.d.ts.map +1 -0
  3. package/dist/cjs/api/anchored-objects.js +259 -0
  4. package/dist/cjs/api/copy-paste.d.ts +8 -1
  5. package/dist/cjs/api/copy-paste.d.ts.map +1 -1
  6. package/dist/cjs/api/copy-paste.js +4 -2
  7. package/dist/cjs/api/dependency.d.ts +13 -2
  8. package/dist/cjs/api/dependency.d.ts.map +1 -1
  9. package/dist/cjs/api/dependency.js +11 -5
  10. package/dist/cjs/api/formula.d.ts +61 -4
  11. package/dist/cjs/api/formula.d.ts.map +1 -1
  12. package/dist/cjs/api/formula.js +250 -61
  13. package/dist/cjs/api/immer-utils.d.ts +11 -1
  14. package/dist/cjs/api/immer-utils.d.ts.map +1 -1
  15. package/dist/cjs/api/immer-utils.js +17 -1
  16. package/dist/cjs/api/insert-cut-cells.d.ts +35 -0
  17. package/dist/cjs/api/insert-cut-cells.d.ts.map +1 -0
  18. package/dist/cjs/api/insert-cut-cells.js +60 -0
  19. package/dist/cjs/api/merges.d.ts +16 -0
  20. package/dist/cjs/api/merges.d.ts.map +1 -1
  21. package/dist/cjs/api/merges.js +75 -1
  22. package/dist/cjs/api/named-range-structural.d.ts +62 -0
  23. package/dist/cjs/api/named-range-structural.d.ts.map +1 -0
  24. package/dist/cjs/api/named-range-structural.js +197 -0
  25. package/dist/cjs/api/range-rule-helpers.d.ts +45 -1
  26. package/dist/cjs/api/range-rule-helpers.d.ts.map +1 -1
  27. package/dist/cjs/api/range-rule-helpers.js +159 -6
  28. package/dist/cjs/api/structural-formula-update.d.ts.map +1 -1
  29. package/dist/cjs/api/structural-formula-update.js +24 -6
  30. package/dist/cjs/api/structural-guards.d.ts +78 -0
  31. package/dist/cjs/api/structural-guards.d.ts.map +1 -0
  32. package/dist/cjs/api/structural-guards.js +202 -0
  33. package/dist/cjs/api/structural-table-refs.d.ts +94 -0
  34. package/dist/cjs/api/structural-table-refs.d.ts.map +1 -0
  35. package/dist/cjs/api/structural-table-refs.js +313 -0
  36. package/dist/cjs/api/subtotal.d.ts +20 -13
  37. package/dist/cjs/api/subtotal.d.ts.map +1 -1
  38. package/dist/cjs/api/subtotal.js +26 -19
  39. package/dist/cjs/commands.d.ts +9 -0
  40. package/dist/cjs/commands.d.ts.map +1 -1
  41. package/dist/cjs/constants.d.ts +25 -0
  42. package/dist/cjs/constants.d.ts.map +1 -0
  43. package/dist/cjs/constants.js +26 -0
  44. package/dist/cjs/hooks/use-calculation-worker.d.ts.map +1 -1
  45. package/dist/cjs/hooks/use-calculation-worker.js +64 -6
  46. package/dist/cjs/hooks/use-calculation.d.ts +7 -0
  47. package/dist/cjs/hooks/use-calculation.d.ts.map +1 -1
  48. package/dist/cjs/hooks/use-calculation.js +15 -0
  49. package/dist/cjs/hooks/use-on-calculation-success.d.ts +7 -0
  50. package/dist/cjs/hooks/use-on-calculation-success.d.ts.map +1 -1
  51. package/dist/cjs/hooks/use-on-calculation-success.js +7 -1
  52. package/dist/cjs/hooks/use-on-copy.d.ts +1 -1
  53. package/dist/cjs/hooks/use-on-copy.d.ts.map +1 -1
  54. package/dist/cjs/hooks/use-on-copy.js +2 -3
  55. package/dist/cjs/hooks/use-on-delete-cells-shift-left.d.ts +13 -3
  56. package/dist/cjs/hooks/use-on-delete-cells-shift-left.d.ts.map +1 -1
  57. package/dist/cjs/hooks/use-on-delete-cells-shift-left.js +27 -2
  58. package/dist/cjs/hooks/use-on-delete-cells-shift-up.d.ts +13 -3
  59. package/dist/cjs/hooks/use-on-delete-cells-shift-up.d.ts.map +1 -1
  60. package/dist/cjs/hooks/use-on-delete-cells-shift-up.js +27 -2
  61. package/dist/cjs/hooks/use-on-delete-column.d.ts +13 -4
  62. package/dist/cjs/hooks/use-on-delete-column.d.ts.map +1 -1
  63. package/dist/cjs/hooks/use-on-delete-column.js +14 -2
  64. package/dist/cjs/hooks/use-on-delete-row.d.ts +13 -4
  65. package/dist/cjs/hooks/use-on-delete-row.d.ts.map +1 -1
  66. package/dist/cjs/hooks/use-on-delete-row.js +14 -2
  67. package/dist/cjs/hooks/use-on-insert-cells-shift-down.d.ts +13 -3
  68. package/dist/cjs/hooks/use-on-insert-cells-shift-down.d.ts.map +1 -1
  69. package/dist/cjs/hooks/use-on-insert-cells-shift-down.js +27 -2
  70. package/dist/cjs/hooks/use-on-insert-cells-shift-right.d.ts +13 -3
  71. package/dist/cjs/hooks/use-on-insert-cells-shift-right.d.ts.map +1 -1
  72. package/dist/cjs/hooks/use-on-insert-cells-shift-right.js +27 -2
  73. package/dist/cjs/hooks/use-on-insert-column.d.ts +10 -3
  74. package/dist/cjs/hooks/use-on-insert-column.d.ts.map +1 -1
  75. package/dist/cjs/hooks/use-on-insert-column.js +33 -7
  76. package/dist/cjs/hooks/use-on-insert-row.d.ts +10 -3
  77. package/dist/cjs/hooks/use-on-insert-row.d.ts.map +1 -1
  78. package/dist/cjs/hooks/use-on-insert-row.js +32 -7
  79. package/dist/cjs/hooks/use-on-move-columns.d.ts +2 -1
  80. package/dist/cjs/hooks/use-on-move-columns.d.ts.map +1 -1
  81. package/dist/cjs/hooks/use-on-move-columns.js +14 -5
  82. package/dist/cjs/hooks/use-on-move-rows.d.ts +16 -1
  83. package/dist/cjs/hooks/use-on-move-rows.d.ts.map +1 -1
  84. package/dist/cjs/hooks/use-on-move-rows.js +30 -5
  85. package/dist/cjs/hooks/use-on-move-selection.d.ts +7 -2
  86. package/dist/cjs/hooks/use-on-move-selection.d.ts.map +1 -1
  87. package/dist/cjs/hooks/use-on-move-selection.js +14 -1
  88. package/dist/cjs/hooks/use-on-paste.d.ts +12 -2
  89. package/dist/cjs/hooks/use-on-paste.d.ts.map +1 -1
  90. package/dist/cjs/hooks/use-on-paste.js +56 -8
  91. package/dist/cjs/hooks/use-spreadsheet-state.d.ts +16 -5
  92. package/dist/cjs/hooks/use-spreadsheet-state.d.ts.map +1 -1
  93. package/dist/cjs/hooks/use-spreadsheet-state.js +141 -18
  94. package/dist/cjs/hooks/use-structured-reference.d.ts.map +1 -1
  95. package/dist/cjs/hooks/use-structured-reference.js +10 -6
  96. package/dist/cjs/index.d.ts +4 -0
  97. package/dist/cjs/index.d.ts.map +1 -1
  98. package/dist/cjs/index.js +4 -0
  99. package/dist/cjs/interface/calculation-interface.d.ts +9 -0
  100. package/dist/cjs/interface/calculation-interface.d.ts.map +1 -1
  101. package/dist/cjs/interface/calculation-interface.js +31 -2
  102. package/dist/cjs/interface/delete-cells-shift-left.d.ts +8 -1
  103. package/dist/cjs/interface/delete-cells-shift-left.d.ts.map +1 -1
  104. package/dist/cjs/interface/delete-cells-shift-left.js +158 -80
  105. package/dist/cjs/interface/delete-cells-shift-up.d.ts +9 -1
  106. package/dist/cjs/interface/delete-cells-shift-up.d.ts.map +1 -1
  107. package/dist/cjs/interface/delete-cells-shift-up.js +155 -73
  108. package/dist/cjs/interface/delete-column.d.ts +1 -1
  109. package/dist/cjs/interface/delete-column.d.ts.map +1 -1
  110. package/dist/cjs/interface/delete-column.js +109 -50
  111. package/dist/cjs/interface/delete-row.d.ts +1 -1
  112. package/dist/cjs/interface/delete-row.d.ts.map +1 -1
  113. package/dist/cjs/interface/delete-row.js +105 -46
  114. package/dist/cjs/interface/insert-cells-shift-down.d.ts +10 -1
  115. package/dist/cjs/interface/insert-cells-shift-down.d.ts.map +1 -1
  116. package/dist/cjs/interface/insert-cells-shift-down.js +147 -52
  117. package/dist/cjs/interface/insert-cells-shift-right.d.ts +10 -1
  118. package/dist/cjs/interface/insert-cells-shift-right.d.ts.map +1 -1
  119. package/dist/cjs/interface/insert-cells-shift-right.js +154 -58
  120. package/dist/cjs/interface/insert-column.d.ts +1 -1
  121. package/dist/cjs/interface/insert-column.d.ts.map +1 -1
  122. package/dist/cjs/interface/insert-column.js +80 -26
  123. package/dist/cjs/interface/insert-row.d.ts +1 -1
  124. package/dist/cjs/interface/insert-row.d.ts.map +1 -1
  125. package/dist/cjs/interface/insert-row.js +63 -15
  126. package/dist/cjs/interface/spreadsheet-interface.d.ts.map +1 -1
  127. package/dist/cjs/interface/spreadsheet-interface.js +33 -0
  128. package/dist/cjs/sheet-cell.d.ts.map +1 -1
  129. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  130. package/dist/esm/api/anchored-objects.d.ts +66 -0
  131. package/dist/esm/api/anchored-objects.d.ts.map +1 -0
  132. package/dist/esm/api/anchored-objects.js +212 -0
  133. package/dist/esm/api/copy-paste.d.ts +8 -1
  134. package/dist/esm/api/copy-paste.d.ts.map +1 -1
  135. package/dist/esm/api/copy-paste.js +4 -2
  136. package/dist/esm/api/dependency.d.ts +13 -2
  137. package/dist/esm/api/dependency.d.ts.map +1 -1
  138. package/dist/esm/api/dependency.js +10 -4
  139. package/dist/esm/api/formula.d.ts +61 -4
  140. package/dist/esm/api/formula.d.ts.map +1 -1
  141. package/dist/esm/api/formula.js +238 -60
  142. package/dist/esm/api/immer-utils.d.ts +11 -1
  143. package/dist/esm/api/immer-utils.d.ts.map +1 -1
  144. package/dist/esm/api/immer-utils.js +16 -0
  145. package/dist/esm/api/insert-cut-cells.d.ts +35 -0
  146. package/dist/esm/api/insert-cut-cells.d.ts.map +1 -0
  147. package/dist/esm/api/insert-cut-cells.js +67 -0
  148. package/dist/esm/api/merges.d.ts +16 -0
  149. package/dist/esm/api/merges.d.ts.map +1 -1
  150. package/dist/esm/api/merges.js +60 -0
  151. package/dist/esm/api/named-range-structural.d.ts +62 -0
  152. package/dist/esm/api/named-range-structural.d.ts.map +1 -0
  153. package/dist/esm/api/named-range-structural.js +176 -0
  154. package/dist/esm/api/range-rule-helpers.d.ts +45 -1
  155. package/dist/esm/api/range-rule-helpers.d.ts.map +1 -1
  156. package/dist/esm/api/range-rule-helpers.js +153 -1
  157. package/dist/esm/api/structural-formula-update.d.ts.map +1 -1
  158. package/dist/esm/api/structural-formula-update.js +24 -6
  159. package/dist/esm/api/structural-guards.d.ts +78 -0
  160. package/dist/esm/api/structural-guards.d.ts.map +1 -0
  161. package/dist/esm/api/structural-guards.js +186 -0
  162. package/dist/esm/api/structural-table-refs.d.ts +94 -0
  163. package/dist/esm/api/structural-table-refs.d.ts.map +1 -0
  164. package/dist/esm/api/structural-table-refs.js +219 -0
  165. package/dist/esm/api/subtotal.d.ts +20 -13
  166. package/dist/esm/api/subtotal.d.ts.map +1 -1
  167. package/dist/esm/api/subtotal.js +15 -8
  168. package/dist/esm/commands.d.ts +9 -0
  169. package/dist/esm/commands.d.ts.map +1 -1
  170. package/dist/esm/constants.d.ts +25 -0
  171. package/dist/esm/constants.d.ts.map +1 -0
  172. package/dist/esm/constants.js +26 -0
  173. package/dist/esm/hooks/use-calculation-worker.d.ts.map +1 -1
  174. package/dist/esm/hooks/use-calculation-worker.js +45 -0
  175. package/dist/esm/hooks/use-calculation.d.ts +7 -0
  176. package/dist/esm/hooks/use-calculation.d.ts.map +1 -1
  177. package/dist/esm/hooks/use-calculation.js +15 -0
  178. package/dist/esm/hooks/use-on-calculation-success.d.ts +7 -0
  179. package/dist/esm/hooks/use-on-calculation-success.d.ts.map +1 -1
  180. package/dist/esm/hooks/use-on-calculation-success.js +7 -1
  181. package/dist/esm/hooks/use-on-copy.d.ts +1 -1
  182. package/dist/esm/hooks/use-on-copy.d.ts.map +1 -1
  183. package/dist/esm/hooks/use-on-copy.js +2 -3
  184. package/dist/esm/hooks/use-on-delete-cells-shift-left.d.ts +13 -3
  185. package/dist/esm/hooks/use-on-delete-cells-shift-left.d.ts.map +1 -1
  186. package/dist/esm/hooks/use-on-delete-cells-shift-left.js +26 -2
  187. package/dist/esm/hooks/use-on-delete-cells-shift-up.d.ts +13 -3
  188. package/dist/esm/hooks/use-on-delete-cells-shift-up.d.ts.map +1 -1
  189. package/dist/esm/hooks/use-on-delete-cells-shift-up.js +26 -2
  190. package/dist/esm/hooks/use-on-delete-column.d.ts +13 -4
  191. package/dist/esm/hooks/use-on-delete-column.d.ts.map +1 -1
  192. package/dist/esm/hooks/use-on-delete-column.js +14 -2
  193. package/dist/esm/hooks/use-on-delete-row.d.ts +13 -4
  194. package/dist/esm/hooks/use-on-delete-row.d.ts.map +1 -1
  195. package/dist/esm/hooks/use-on-delete-row.js +14 -2
  196. package/dist/esm/hooks/use-on-insert-cells-shift-down.d.ts +13 -3
  197. package/dist/esm/hooks/use-on-insert-cells-shift-down.d.ts.map +1 -1
  198. package/dist/esm/hooks/use-on-insert-cells-shift-down.js +26 -2
  199. package/dist/esm/hooks/use-on-insert-cells-shift-right.d.ts +13 -3
  200. package/dist/esm/hooks/use-on-insert-cells-shift-right.d.ts.map +1 -1
  201. package/dist/esm/hooks/use-on-insert-cells-shift-right.js +26 -2
  202. package/dist/esm/hooks/use-on-insert-column.d.ts +10 -3
  203. package/dist/esm/hooks/use-on-insert-column.d.ts.map +1 -1
  204. package/dist/esm/hooks/use-on-insert-column.js +33 -7
  205. package/dist/esm/hooks/use-on-insert-row.d.ts +10 -3
  206. package/dist/esm/hooks/use-on-insert-row.d.ts.map +1 -1
  207. package/dist/esm/hooks/use-on-insert-row.js +32 -7
  208. package/dist/esm/hooks/use-on-move-columns.d.ts +2 -1
  209. package/dist/esm/hooks/use-on-move-columns.d.ts.map +1 -1
  210. package/dist/esm/hooks/use-on-move-columns.js +14 -5
  211. package/dist/esm/hooks/use-on-move-rows.d.ts +16 -1
  212. package/dist/esm/hooks/use-on-move-rows.d.ts.map +1 -1
  213. package/dist/esm/hooks/use-on-move-rows.js +30 -5
  214. package/dist/esm/hooks/use-on-move-selection.d.ts +7 -2
  215. package/dist/esm/hooks/use-on-move-selection.d.ts.map +1 -1
  216. package/dist/esm/hooks/use-on-move-selection.js +14 -1
  217. package/dist/esm/hooks/use-on-paste.d.ts +12 -2
  218. package/dist/esm/hooks/use-on-paste.d.ts.map +1 -1
  219. package/dist/esm/hooks/use-on-paste.js +41 -2
  220. package/dist/esm/hooks/use-spreadsheet-state.d.ts +16 -5
  221. package/dist/esm/hooks/use-spreadsheet-state.d.ts.map +1 -1
  222. package/dist/esm/hooks/use-spreadsheet-state.js +141 -17
  223. package/dist/esm/hooks/use-structured-reference.d.ts.map +1 -1
  224. package/dist/esm/hooks/use-structured-reference.js +10 -6
  225. package/dist/esm/index.d.ts +4 -0
  226. package/dist/esm/index.d.ts.map +1 -1
  227. package/dist/esm/index.js +4 -0
  228. package/dist/esm/interface/calculation-interface.d.ts +9 -0
  229. package/dist/esm/interface/calculation-interface.d.ts.map +1 -1
  230. package/dist/esm/interface/calculation-interface.js +33 -2
  231. package/dist/esm/interface/delete-cells-shift-left.d.ts +8 -1
  232. package/dist/esm/interface/delete-cells-shift-left.d.ts.map +1 -1
  233. package/dist/esm/interface/delete-cells-shift-left.js +135 -59
  234. package/dist/esm/interface/delete-cells-shift-up.d.ts +9 -1
  235. package/dist/esm/interface/delete-cells-shift-up.d.ts.map +1 -1
  236. package/dist/esm/interface/delete-cells-shift-up.js +133 -53
  237. package/dist/esm/interface/delete-column.d.ts +1 -1
  238. package/dist/esm/interface/delete-column.d.ts.map +1 -1
  239. package/dist/esm/interface/delete-column.js +96 -38
  240. package/dist/esm/interface/delete-row.d.ts +1 -1
  241. package/dist/esm/interface/delete-row.d.ts.map +1 -1
  242. package/dist/esm/interface/delete-row.js +98 -39
  243. package/dist/esm/interface/insert-cells-shift-down.d.ts +10 -1
  244. package/dist/esm/interface/insert-cells-shift-down.d.ts.map +1 -1
  245. package/dist/esm/interface/insert-cells-shift-down.js +116 -47
  246. package/dist/esm/interface/insert-cells-shift-right.d.ts +10 -1
  247. package/dist/esm/interface/insert-cells-shift-right.d.ts.map +1 -1
  248. package/dist/esm/interface/insert-cells-shift-right.js +120 -51
  249. package/dist/esm/interface/insert-column.d.ts +1 -1
  250. package/dist/esm/interface/insert-column.d.ts.map +1 -1
  251. package/dist/esm/interface/insert-column.js +68 -18
  252. package/dist/esm/interface/insert-row.d.ts +1 -1
  253. package/dist/esm/interface/insert-row.d.ts.map +1 -1
  254. package/dist/esm/interface/insert-row.js +60 -14
  255. package/dist/esm/interface/spreadsheet-interface.d.ts.map +1 -1
  256. package/dist/esm/interface/spreadsheet-interface.js +29 -0
  257. package/dist/esm/sheet-cell.d.ts.map +1 -1
  258. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  259. package/package.json +18 -18
@@ -89,6 +89,11 @@ export var updateFormulasForStructuralChange = function (params) {
89
89
  startColumnIndex: isInsert ? referenceIndex : referenceIndex + count,
90
90
  endColumnIndex: columnCount,
91
91
  };
92
+ // The cells a delete removes: any reference into them (that Pass 1 did not
93
+ // already contract) is broken to `#REF!` instead of sliding onto the cell
94
+ // that moves into its place.
95
+ var deletedRange = isInsert ? undefined : pass1Range;
96
+ var editedSheetName = getSheetName(sheetId);
92
97
  // ---- PASS 1 ----
93
98
  var pass1Formulas = collectUniqueDependentsForRange({
94
99
  draft: draft,
@@ -109,10 +114,15 @@ export var updateFormulasForStructuralChange = function (params) {
109
114
  var formulaValue = sheetCell.formula;
110
115
  if (!formulaValue)
111
116
  continue;
112
- var activeSheetName = getSheetName(pos.sheetId);
117
+ // Scope to the EDITED sheet: a qualified `Sheet1!A1:A3` on another
118
+ // sheet expands like a local range, while that other sheet's own bare
119
+ // `A1:A3` (which resolves to ITS sheet) is left alone.
120
+ var rangeOptions = {
121
+ includeUnqualifiedReferences: pos.sheetId === sheetId,
122
+ };
113
123
  var updatedFormula = isInsert
114
- ? expandRangesInFormula(formulaValue, referenceIndex, count, axis, activeSheetName)
115
- : contractRangesInFormula(formulaValue, referenceIndex, count, axis, activeSheetName);
124
+ ? expandRangesInFormula(formulaValue, referenceIndex, count, axis, editedSheetName, rangeOptions)
125
+ : contractRangesInFormula(formulaValue, referenceIndex, count, axis, editedSheetName, rangeOptions);
116
126
  if (!updatedFormula || updatedFormula === formulaValue)
117
127
  continue;
118
128
  sheetCell.setFormulaValue(updatedFormula, false);
@@ -180,7 +190,7 @@ export var updateFormulasForStructuralChange = function (params) {
180
190
  shiftExternalDependentFormulaReferences({
181
191
  draft: draft,
182
192
  position: pos,
183
- editedSheetName: getSheetName(sheetId),
193
+ editedSheetName: editedSheetName,
184
194
  enqueueCalculation: enqueueCalculation,
185
195
  enqueueGraphOperation: enqueueGraphOperation,
186
196
  recalcCells: recalcCells,
@@ -188,6 +198,7 @@ export var updateFormulasForStructuralChange = function (params) {
188
198
  rowDelta: rowDelta,
189
199
  columnDelta: columnDelta,
190
200
  sourceRange: pass2SourceRange,
201
+ deletedRange: deletedRange,
191
202
  locale: locale,
192
203
  rowCount: rowCount,
193
204
  columnCount: columnCount,
@@ -207,6 +218,7 @@ export var updateFormulasForStructuralChange = function (params) {
207
218
  rowDelta: rowDelta,
208
219
  columnDelta: columnDelta,
209
220
  sourceRange: pass2SourceRange,
221
+ deletedRange: deletedRange,
210
222
  locale: locale,
211
223
  rowCount: rowCount,
212
224
  columnCount: columnCount,
@@ -231,7 +243,7 @@ export var updateFormulasForStructuralChange = function (params) {
231
243
  shiftExternalDependentFormulaReferences({
232
244
  draft: draft,
233
245
  position: position,
234
- editedSheetName: getSheetName(sheetId),
246
+ editedSheetName: editedSheetName,
235
247
  enqueueCalculation: enqueueCalculation,
236
248
  enqueueGraphOperation: enqueueGraphOperation,
237
249
  recalcCells: recalcCells,
@@ -239,6 +251,7 @@ export var updateFormulasForStructuralChange = function (params) {
239
251
  rowDelta: rowDelta,
240
252
  columnDelta: columnDelta,
241
253
  sourceRange: pass2SourceRange,
254
+ deletedRange: deletedRange,
242
255
  locale: locale,
243
256
  rowCount: rowCount,
244
257
  columnCount: columnCount,
@@ -284,6 +297,7 @@ export var updateFormulasForStructuralChange = function (params) {
284
297
  rowIndex: pos.rowIndex,
285
298
  columnIndex: pos.columnIndex,
286
299
  },
300
+ activeSheetName: editedSheetName,
287
301
  enqueueCalculation: enqueueCalculation,
288
302
  enqueueGraphOperation: enqueueGraphOperation,
289
303
  recalcCells: recalcCells,
@@ -291,6 +305,7 @@ export var updateFormulasForStructuralChange = function (params) {
291
305
  rowDelta: rowDelta,
292
306
  columnDelta: columnDelta,
293
307
  sourceRange: pass2SourceRange,
308
+ deletedRange: deletedRange,
294
309
  locale: locale,
295
310
  rowCount: rowCount,
296
311
  columnCount: columnCount,
@@ -328,6 +343,7 @@ export var updateFormulasForStructuralChange = function (params) {
328
343
  moveFormulaAtPosition({
329
344
  draft: draft,
330
345
  position: { sheetId: sheetId, rowIndex: rowIndex, columnIndex: columnIndex },
346
+ activeSheetName: editedSheetName,
331
347
  enqueueCalculation: enqueueCalculation,
332
348
  enqueueGraphOperation: enqueueGraphOperation,
333
349
  recalcCells: recalcCells,
@@ -335,6 +351,7 @@ export var updateFormulasForStructuralChange = function (params) {
335
351
  rowDelta: rowDelta,
336
352
  columnDelta: columnDelta,
337
353
  sourceRange: pass2SourceRange,
354
+ deletedRange: deletedRange,
338
355
  locale: locale,
339
356
  rowCount: rowCount,
340
357
  columnCount: columnCount,
@@ -347,7 +364,7 @@ export var updateFormulasForStructuralChange = function (params) {
347
364
  };
348
365
  var shiftExternalDependentFormulaReferences = function (_a) {
349
366
  var _b, _c;
350
- var draft = _a.draft, position = _a.position, editedSheetName = _a.editedSheetName, enqueueCalculation = _a.enqueueCalculation, enqueueGraphOperation = _a.enqueueGraphOperation, recalcCells = _a.recalcCells, movedKeys = _a.movedKeys, rowDelta = _a.rowDelta, columnDelta = _a.columnDelta, sourceRange = _a.sourceRange, locale = _a.locale, rowCount = _a.rowCount, columnCount = _a.columnCount, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry;
367
+ var draft = _a.draft, position = _a.position, editedSheetName = _a.editedSheetName, enqueueCalculation = _a.enqueueCalculation, enqueueGraphOperation = _a.enqueueGraphOperation, recalcCells = _a.recalcCells, movedKeys = _a.movedKeys, rowDelta = _a.rowDelta, columnDelta = _a.columnDelta, sourceRange = _a.sourceRange, deletedRange = _a.deletedRange, locale = _a.locale, rowCount = _a.rowCount, columnCount = _a.columnCount, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry;
351
368
  var sheetCell = new SheetCell();
352
369
  var currentSheet = createSheetDraft(draft, position.sheetId, position.rowIndex);
353
370
  var cellData = (_c = (_b = currentSheet[position.rowIndex]) === null || _b === void 0 ? void 0 : _b.values) === null || _c === void 0 ? void 0 : _c[position.columnIndex];
@@ -362,6 +379,7 @@ var shiftExternalDependentFormulaReferences = function (_a) {
362
379
  columnIndex: position.columnIndex + columnDelta,
363
380
  }, editedSheetName, {
364
381
  exclusionRange: sourceRange,
382
+ deletedRange: deletedRange,
365
383
  rowCount: rowCount,
366
384
  columnCount: columnCount,
367
385
  referenceSheetName: editedSheetName,
@@ -0,0 +1,78 @@
1
+ import type { CellData, CellInterface, GridRange, SelectionArea } from "@rowsncolumns/common-types";
2
+ import type { SelectionAttributes, TableView } from "@rowsncolumns/spreadsheet";
3
+ import { type StructuralRefusal } from "../constants";
4
+ import type { SheetData } from "../hooks/use-spreadsheet-state";
5
+ /**
6
+ * Pure predicates behind Excel's structural-edit refusals. The hooks run them BEFORE the interface
7
+ * function touches any state and `showError` the Excel message on refusal, so a refused edit leaves
8
+ * sheetData / merges / tables / selection exactly as they were.
9
+ *
10
+ * A "band" is the rectangle of cells an edit relocates. Shift cells down at `B2:B3` moves
11
+ * `B2:B∞` — an open end is expressed with `Number.POSITIVE_INFINITY`.
12
+ */
13
+ export type StructuralBand = GridRange;
14
+ export type ShiftDirection = "down" | "right" | "up" | "left";
15
+ /** The selection a cell shift operates on — the LAST selection, or the active cell as a 1×1. The
16
+ * hooks' guards and the interface functions must agree on it, so both resolve it here. */
17
+ export declare const resolveShiftSelection: (activeCell: CellInterface, selections: SelectionArea<SelectionAttributes>[]) => SelectionArea<SelectionAttributes>;
18
+ /** The cells a shift relocates: the selection's rows/columns from its leading edge to the sheet edge. */
19
+ export declare const shiftBand: (direction: ShiftDirection, range: GridRange) => StructuralBand;
20
+ export declare const isNonBlankCell: (cell: CellData | null | undefined) => boolean;
21
+ /**
22
+ * INS-06 / INS-09 / SHF-10 — the first non-blank cell that a shift of `count` rows (axis `row`) or
23
+ * columns (axis `column`) would push past `limit` (the last valid row/column index). Only cells
24
+ * inside `band` move. `undefined` when the edit is safe.
25
+ */
26
+ export declare const findOffSheetPush: <T extends CellData>({ rows, axis, count, limit, band, }: {
27
+ rows: SheetData<T>[number] | undefined;
28
+ axis: "row" | "column";
29
+ count: number;
30
+ limit: number | undefined;
31
+ band: StructuralBand;
32
+ }) => CellInterface | undefined;
33
+ /**
34
+ * A range the band reaches but does not contain whole is TORN by the shift. For a delete, a range
35
+ * that touches the deleted block must lie wholly inside it (it is removed with the block) — one
36
+ * straddling the block's edge is torn too.
37
+ */
38
+ export declare const findTornRange: (ranges: readonly GridRange[] | undefined | null, band: StructuralBand, deletedBlock?: GridRange) => GridRange | undefined;
39
+ /** SHF-05 / MRG-07 — a merge the band covers only partially. */
40
+ export declare const findTornMerge: (merges: readonly GridRange[] | undefined | null, band: StructuralBand, deletedBlock?: GridRange) => GridRange | undefined;
41
+ /** TBL-05 — a table the band covers only partially (a table wholly inside the band moves intact). */
42
+ export declare const findTornTable: (tables: readonly TableView[] | undefined | null, sheetId: number, band: StructuralBand, deletedBlock?: GridRange) => TableView | undefined;
43
+ /** ANC-14 — a CSE / dynamic-array range the band covers only partially. */
44
+ export declare const findTornArray: (arrayRanges: readonly GridRange[] | undefined | null, band: StructuralBand, deletedBlock?: GridRange) => GridRange | undefined;
45
+ /** Ranges (merges / tables) that travel with the band: wholly inside it and, for a delete, not
46
+ * inside the deleted block. */
47
+ export declare const isRangeInsideBand: (range: GridRange, band: StructuralBand) => boolean;
48
+ export declare const isRangeInsideBlock: (outer: GridRange, inner: GridRange) => boolean;
49
+ /**
50
+ * The Excel refusal (if any) for an insert/delete-cells shift of `range`. Checks run in Excel's
51
+ * order: array tear, merge tear, table tear, off-sheet push. `undefined` means the edit may proceed.
52
+ */
53
+ export declare const getShiftCellsRefusal: <T extends CellData>({ direction, range, sheetId, rows, rowCount, columnCount, merges, tables, arrayRanges, }: {
54
+ direction: ShiftDirection;
55
+ range: GridRange;
56
+ sheetId: number;
57
+ rows: SheetData<T>[number] | undefined;
58
+ /** Last valid row index for a vertical shift (the grid does not grow on a cell shift). */
59
+ rowCount?: number;
60
+ /** Last valid column index for a horizontal shift. */
61
+ columnCount?: number;
62
+ merges?: readonly GridRange[] | null;
63
+ tables?: readonly TableView[] | null;
64
+ arrayRanges?: readonly GridRange[] | null;
65
+ }) => StructuralRefusal | undefined;
66
+ /**
67
+ * INS-06 / INS-09 — the refusal for a whole-row (`axis: "row"`) or whole-column insert of `count`
68
+ * lines before `referenceIndex`, given the hard grid cap (`maxRowCount` / `maxColumnCount`). Blank
69
+ * trailing lines may fall off the end; a non-blank one refuses the insert.
70
+ */
71
+ export declare const getInsertLinesRefusal: <T extends CellData>({ axis, referenceIndex, count, rows, limit, }: {
72
+ axis: "row" | "column";
73
+ referenceIndex: number;
74
+ count: number;
75
+ rows: SheetData<T>[number] | undefined;
76
+ limit: number | undefined;
77
+ }) => StructuralRefusal | undefined;
78
+ //# sourceMappingURL=structural-guards.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural-guards.d.ts","sourceRoot":"","sources":["../../../api/structural-guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,SAAS,EACT,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGhF,OAAO,EACL,KAAK,iBAAiB,EAEvB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,CAAC;AAEvC,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,GAAG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sncolumns/utils";
3
+ import { structuralRefusal, } from "../constants";
4
+ /** The selection a cell shift operates on — the LAST selection, or the active cell as a 1×1. The
5
+ * hooks' guards and the interface functions must agree on it, so both resolve it here. */
6
+ export var resolveShiftSelection = function (activeCell, selections) {
7
+ var finalSelections = selections.length
8
+ ? selections
9
+ : selectionFromActiveCell(activeCell);
10
+ return finalSelections[finalSelections.length - 1];
11
+ };
12
+ var rangesIntersect = function (a, b) {
13
+ return a.startRowIndex <= b.endRowIndex &&
14
+ a.endRowIndex >= b.startRowIndex &&
15
+ a.startColumnIndex <= b.endColumnIndex &&
16
+ a.endColumnIndex >= b.startColumnIndex;
17
+ };
18
+ var rangeContains = function (outer, inner) {
19
+ return inner.startRowIndex >= outer.startRowIndex &&
20
+ inner.endRowIndex <= outer.endRowIndex &&
21
+ inner.startColumnIndex >= outer.startColumnIndex &&
22
+ inner.endColumnIndex <= outer.endColumnIndex;
23
+ };
24
+ /** The cells a shift relocates: the selection's rows/columns from its leading edge to the sheet edge. */
25
+ export var shiftBand = function (direction, range) {
26
+ switch (direction) {
27
+ case "down":
28
+ case "up":
29
+ return {
30
+ startRowIndex: range.startRowIndex,
31
+ endRowIndex: Number.POSITIVE_INFINITY,
32
+ startColumnIndex: range.startColumnIndex,
33
+ endColumnIndex: range.endColumnIndex,
34
+ };
35
+ case "right":
36
+ case "left":
37
+ return {
38
+ startRowIndex: range.startRowIndex,
39
+ endRowIndex: range.endRowIndex,
40
+ startColumnIndex: range.startColumnIndex,
41
+ endColumnIndex: Number.POSITIVE_INFINITY,
42
+ };
43
+ }
44
+ };
45
+ /**
46
+ * A cell counts as non-blank when it carries a value, a formula, a format, a note, a link or a
47
+ * citation — Excel's "might appear empty but have blank values, some formatting, or a formula".
48
+ * Derived render results (CF / DV results) don't count.
49
+ */
50
+ var DERIVED_CELL_KEYS = new Set([
51
+ "conditionalFormattingResultById",
52
+ "dataValidationResult",
53
+ ]);
54
+ export var isNonBlankCell = function (cell) {
55
+ if (!cell)
56
+ return false;
57
+ return Object.entries(cell).some(function (_a) {
58
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
59
+ return !DERIVED_CELL_KEYS.has(key) && value !== undefined && value !== null;
60
+ });
61
+ };
62
+ /**
63
+ * INS-06 / INS-09 / SHF-10 — the first non-blank cell that a shift of `count` rows (axis `row`) or
64
+ * columns (axis `column`) would push past `limit` (the last valid row/column index). Only cells
65
+ * inside `band` move. `undefined` when the edit is safe.
66
+ */
67
+ export var findOffSheetPush = function (_a) {
68
+ var _b, _c;
69
+ var rows = _a.rows, axis = _a.axis, count = _a.count, limit = _a.limit, band = _a.band;
70
+ if (!rows || limit === undefined || count <= 0)
71
+ return undefined;
72
+ var firstPushed = limit - count + 1;
73
+ if (axis === "row") {
74
+ var startRow_1 = Math.max(band.startRowIndex, firstPushed, 1);
75
+ for (var rowIndex = startRow_1; rowIndex < rows.length; rowIndex++) {
76
+ var values = (_b = rows[rowIndex]) === null || _b === void 0 ? void 0 : _b.values;
77
+ if (!values)
78
+ continue;
79
+ var startCol = Math.max(band.startColumnIndex, 1);
80
+ var endCol = Math.min(band.endColumnIndex, values.length - 1);
81
+ for (var columnIndex = startCol; columnIndex <= endCol; columnIndex++) {
82
+ if (isNonBlankCell(values[columnIndex])) {
83
+ return { rowIndex: rowIndex, columnIndex: columnIndex };
84
+ }
85
+ }
86
+ }
87
+ return undefined;
88
+ }
89
+ var startRow = Math.max(band.startRowIndex, 1);
90
+ var endRow = Math.min(band.endRowIndex, rows.length - 1);
91
+ for (var rowIndex = startRow; rowIndex <= endRow; rowIndex++) {
92
+ var values = (_c = rows[rowIndex]) === null || _c === void 0 ? void 0 : _c.values;
93
+ if (!values)
94
+ continue;
95
+ var startCol = Math.max(band.startColumnIndex, firstPushed, 1);
96
+ for (var columnIndex = startCol; columnIndex < values.length; columnIndex++) {
97
+ if (isNonBlankCell(values[columnIndex])) {
98
+ return { rowIndex: rowIndex, columnIndex: columnIndex };
99
+ }
100
+ }
101
+ }
102
+ return undefined;
103
+ };
104
+ /**
105
+ * A range the band reaches but does not contain whole is TORN by the shift. For a delete, a range
106
+ * that touches the deleted block must lie wholly inside it (it is removed with the block) — one
107
+ * straddling the block's edge is torn too.
108
+ */
109
+ export var findTornRange = function (ranges, band, deletedBlock) {
110
+ if (!ranges)
111
+ return undefined;
112
+ return ranges.find(function (range) {
113
+ if (rangesIntersect(range, band) && !rangeContains(band, range)) {
114
+ return true;
115
+ }
116
+ if (deletedBlock &&
117
+ rangesIntersect(range, deletedBlock) &&
118
+ !rangeContains(deletedBlock, range)) {
119
+ return true;
120
+ }
121
+ return false;
122
+ });
123
+ };
124
+ /** SHF-05 / MRG-07 — a merge the band covers only partially. */
125
+ export var findTornMerge = function (merges, band, deletedBlock) { return findTornRange(merges, band, deletedBlock); };
126
+ /** TBL-05 — a table the band covers only partially (a table wholly inside the band moves intact). */
127
+ export var findTornTable = function (tables, sheetId, band, deletedBlock) {
128
+ if (!tables)
129
+ return undefined;
130
+ return tables.find(function (table) {
131
+ return table.sheetId === sheetId &&
132
+ !!findTornRange([table.range], band, deletedBlock);
133
+ });
134
+ };
135
+ /** ANC-14 — a CSE / dynamic-array range the band covers only partially. */
136
+ export var findTornArray = function (arrayRanges, band, deletedBlock) { return findTornRange(arrayRanges, band, deletedBlock); };
137
+ /** Ranges (merges / tables) that travel with the band: wholly inside it and, for a delete, not
138
+ * inside the deleted block. */
139
+ export var isRangeInsideBand = function (range, band) {
140
+ return rangeContains(band, range);
141
+ };
142
+ export var isRangeInsideBlock = rangeContains;
143
+ /**
144
+ * The Excel refusal (if any) for an insert/delete-cells shift of `range`. Checks run in Excel's
145
+ * order: array tear, merge tear, table tear, off-sheet push. `undefined` means the edit may proceed.
146
+ */
147
+ export var getShiftCellsRefusal = function (_a) {
148
+ var direction = _a.direction, range = _a.range, sheetId = _a.sheetId, rows = _a.rows, rowCount = _a.rowCount, columnCount = _a.columnCount, merges = _a.merges, tables = _a.tables, arrayRanges = _a.arrayRanges;
149
+ var band = shiftBand(direction, range);
150
+ var isDelete = direction === "up" || direction === "left";
151
+ var deletedBlock = isDelete ? range : undefined;
152
+ if (findTornArray(arrayRanges, band, deletedBlock)) {
153
+ return structuralRefusal("torn-array");
154
+ }
155
+ if (findTornMerge(merges, band, deletedBlock)) {
156
+ return structuralRefusal("torn-merge");
157
+ }
158
+ if (findTornTable(tables, sheetId, band, deletedBlock)) {
159
+ return structuralRefusal("torn-table");
160
+ }
161
+ if (!isDelete) {
162
+ var vertical = direction === "down";
163
+ var count = vertical
164
+ ? range.endRowIndex - range.startRowIndex + 1
165
+ : range.endColumnIndex - range.startColumnIndex + 1;
166
+ var pushed = findOffSheetPush({
167
+ rows: rows,
168
+ axis: vertical ? "row" : "column",
169
+ count: count,
170
+ limit: vertical ? rowCount : columnCount,
171
+ band: band,
172
+ });
173
+ if (pushed) {
174
+ return structuralRefusal("off-sheet-push");
175
+ }
176
+ }
177
+ return undefined;
178
+ };
179
+ /**
180
+ * INS-06 / INS-09 — the refusal for a whole-row (`axis: "row"`) or whole-column insert of `count`
181
+ * lines before `referenceIndex`, given the hard grid cap (`maxRowCount` / `maxColumnCount`). Blank
182
+ * trailing lines may fall off the end; a non-blank one refuses the insert.
183
+ */
184
+ export var getInsertLinesRefusal = function (_a) {
185
+ var axis = _a.axis, referenceIndex = _a.referenceIndex, count = _a.count, rows = _a.rows, limit = _a.limit;
186
+ var band = axis === "row"
187
+ ? {
188
+ startRowIndex: referenceIndex,
189
+ endRowIndex: Number.POSITIVE_INFINITY,
190
+ startColumnIndex: 1,
191
+ endColumnIndex: Number.POSITIVE_INFINITY,
192
+ }
193
+ : {
194
+ startRowIndex: 1,
195
+ endRowIndex: Number.POSITIVE_INFINITY,
196
+ startColumnIndex: referenceIndex,
197
+ endColumnIndex: Number.POSITIVE_INFINITY,
198
+ };
199
+ return findOffSheetPush({ rows: rows, axis: axis, count: count, limit: limit, band: band })
200
+ ? structuralRefusal("off-sheet-push")
201
+ : undefined;
202
+ };
@@ -0,0 +1,94 @@
1
+ import type { GridRange } from "@rowsncolumns/common-types";
2
+ import type { CellData, TableView } from "@rowsncolumns/spreadsheet";
3
+ import type { Draft } from "immer";
4
+ import type { useCalculation } from "../hooks/use-calculation";
5
+ import type { CellXfsRegistry } from "../hooks/use-cellxfs-registry";
6
+ import type { SheetData } from "../hooks/use-spreadsheet-state";
7
+ import type { SharedStringRegistry } from "../hooks/use-ss-registry";
8
+ import type { RecalcCellCoordinate } from "../types";
9
+ type StructuralAxis = "row" | "column";
10
+ /**
11
+ * The table parts a row/column delete takes away, computed from the PRE-edit
12
+ * table definitions: tables the delete removes entirely, and — for a column
13
+ * delete — the named columns it drops out of the tables that survive. Excel
14
+ * breaks the structured references into them: `=SUM(Table1[Price])` →
15
+ * `=SUM(#REF!)` once Table1 is gone, `=Table1[@Qty]*2` → `=Table1[@#REF!]*2`
16
+ * once the `Qty` column is deleted, so the cell shows `#REF!` rather than a
17
+ * stale value, `#NAME?` or `#VALUE!`.
18
+ */
19
+ export type RemovedTableParts = {
20
+ tables: string[];
21
+ columns: Array<{
22
+ table: string;
23
+ sheetId: number;
24
+ /** Pre-edit range, to attribute bare `[@Col]` references to this table. */
25
+ range: GridRange;
26
+ columns: string[];
27
+ }>;
28
+ };
29
+ /**
30
+ * Which tables / table columns `deleteRow` (a table goes with its header row)
31
+ * or `deleteColumn` (a table goes when every column is deleted; otherwise the
32
+ * covered columns are spliced out) removes for the band
33
+ * `[minIndex, maxIndex]` on `sheetId`. Mirrors the table updates those
34
+ * interfaces apply to `tables`.
35
+ */
36
+ export declare const collectRemovedTableParts: (tables: TableView[] | undefined, sheetId: number, axis: StructuralAxis, minIndex: number, maxIndex: number) => RemovedTableParts;
37
+ export type BreakStructuredRefsParams<T extends CellData> = {
38
+ draft: Draft<SheetData<T>>;
39
+ /** The edited sheet. */
40
+ sheetId: number;
41
+ axis: StructuralAxis;
42
+ /** Smallest deleted index and the number of deleted rows/columns. */
43
+ referenceIndex: number;
44
+ count: number;
45
+ removed: RemovedTableParts;
46
+ getGraphNodes?: ReturnType<typeof useCalculation>["getGraphNodes"];
47
+ enqueueCalculation?: ReturnType<typeof useCalculation>["enqueueCalculation"];
48
+ enqueueGraphOperation?: ReturnType<typeof useCalculation>["enqueueGraphOperation"];
49
+ recalcCells: Map<string, RecalcCellCoordinate>;
50
+ locale?: string;
51
+ cellXfsRegistry?: CellXfsRegistry;
52
+ sharedStringRegistry?: SharedStringRegistry;
53
+ };
54
+ /**
55
+ * Rewrite, across every sheet, the structured references that point at the
56
+ * table parts a delete removes (see `RemovedTableParts`). Runs BEFORE the
57
+ * splice, so bare `[@Col]` references are attributed to the table by the
58
+ * formula's pre-edit position. Formula cells come from the dependency graph
59
+ * when it is available (cost O(formula cells)); without one the draft is swept.
60
+ */
61
+ export declare const breakStructuredRefsForRemovedTableParts: <T extends CellData>({ draft, sheetId, axis, referenceIndex, count, removed, getGraphNodes, enqueueCalculation, enqueueGraphOperation, recalcCells, locale, cellXfsRegistry, sharedStringRegistry, }: BreakStructuredRefsParams<T>) => void;
62
+ /**
63
+ * Drop the materialised spill cells of every dynamic-array anchor that sits
64
+ * inside the deleted band `[minIndex, maxIndex]` (rows or columns) of
65
+ * `sheetId`. Spilled values live in the sheet data as computed-only cells (no
66
+ * `ue`); once the anchor goes with its row/column they would otherwise slide
67
+ * into place as orphan plain values (Excel: the whole spill disappears).
68
+ * Runs BEFORE the splice. The anchor records its spill as an A1 range in `af`.
69
+ */
70
+ export type SpillRange = {
71
+ startRowIndex: number;
72
+ startColumnIndex: number;
73
+ endRowIndex: number;
74
+ endColumnIndex: number;
75
+ };
76
+ /** The calculator's live spill rectangle for an anchor cell, if it spills. */
77
+ export type GetArrayRange = (position: {
78
+ sheetId: number;
79
+ rowIndex: number;
80
+ columnIndex: number;
81
+ }) => SpillRange | undefined;
82
+ export declare const removeSpillsOfDeletedAnchors: <T extends CellData>({ draft, sheetId, axis, minIndex, maxIndex, getArrayRange, locale, cellXfsRegistry, sharedStringRegistry, }: {
83
+ draft: Draft<SheetData<T>>;
84
+ sheetId: number;
85
+ axis: StructuralAxis;
86
+ minIndex: number;
87
+ maxIndex: number;
88
+ getArrayRange?: GetArrayRange;
89
+ locale?: string;
90
+ cellXfsRegistry?: CellXfsRegistry;
91
+ sharedStringRegistry?: SharedStringRegistry;
92
+ }) => void;
93
+ export {};
94
+ //# sourceMappingURL=structural-table-refs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"structural-table-refs.d.ts","sourceRoot":"","sources":["../../../api/structural-table-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAMrE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAQrD,KAAK,cAAc,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEvC;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,KAAK,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,EAAE,MAAM,CAAC;QAChB,2EAA2E;QAC3E,KAAK,EAAE,SAAS,CAAC;QACjB,OAAO,EAAE,MAAM,EAAE,CAAC;KACnB,CAAC,CAAC;CACJ,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,GACnC,QAAQ,SAAS,EAAE,GAAG,SAAS,EAC/B,S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