@rowsncolumns/spreadsheet 10.2.73 → 10.2.75

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 (270) hide show
  1. package/dist/cjs/api/evaluate-formula.d.ts +17 -0
  2. package/dist/cjs/api/evaluate-formula.d.ts.map +1 -0
  3. package/dist/cjs/api/evaluate-formula.js +141 -0
  4. package/dist/cjs/api/excel-validation-kinds.d.ts +71 -0
  5. package/dist/cjs/api/excel-validation-kinds.d.ts.map +1 -0
  6. package/dist/cjs/api/excel-validation-kinds.js +304 -0
  7. package/dist/cjs/api/go-to-special.d.ts +32 -0
  8. package/dist/cjs/api/go-to-special.d.ts.map +1 -0
  9. package/dist/cjs/api/go-to-special.js +111 -0
  10. package/dist/cjs/api/go-to.d.ts +19 -0
  11. package/dist/cjs/api/go-to.d.ts.map +1 -0
  12. package/dist/cjs/api/go-to.js +49 -0
  13. package/dist/cjs/api/validation-tooltip.d.ts +17 -0
  14. package/dist/cjs/api/validation-tooltip.d.ts.map +1 -0
  15. package/dist/cjs/api/validation-tooltip.js +42 -0
  16. package/dist/cjs/atoms/advanced-filter-dialog.atom.d.ts +28 -0
  17. package/dist/cjs/atoms/advanced-filter-dialog.atom.d.ts.map +1 -0
  18. package/dist/cjs/atoms/advanced-filter-dialog.atom.js +32 -0
  19. package/dist/cjs/atoms/evaluate-formula-dialog.atom.d.ts +36 -0
  20. package/dist/cjs/atoms/evaluate-formula-dialog.atom.d.ts.map +1 -0
  21. package/dist/cjs/atoms/evaluate-formula-dialog.atom.js +36 -0
  22. package/dist/cjs/atoms/go-to-dialog.atom.d.ts +46 -0
  23. package/dist/cjs/atoms/go-to-dialog.atom.d.ts.map +1 -0
  24. package/dist/cjs/atoms/go-to-dialog.atom.js +34 -0
  25. package/dist/cjs/atoms/goal-seek-dialog.atom.d.ts +29 -0
  26. package/dist/cjs/atoms/goal-seek-dialog.atom.d.ts.map +1 -0
  27. package/dist/cjs/atoms/goal-seek-dialog.atom.js +30 -0
  28. package/dist/cjs/atoms/index.d.ts +5 -0
  29. package/dist/cjs/atoms/index.d.ts.map +1 -1
  30. package/dist/cjs/atoms/index.js +5 -0
  31. package/dist/cjs/atoms/paste-special-dialog.atom.d.ts +29 -0
  32. package/dist/cjs/atoms/paste-special-dialog.atom.d.ts.map +1 -0
  33. package/dist/cjs/atoms/paste-special-dialog.atom.js +34 -0
  34. package/dist/cjs/atoms/remove-duplicates-dialog.atom.d.ts +45 -0
  35. package/dist/cjs/atoms/remove-duplicates-dialog.atom.d.ts.map +1 -0
  36. package/dist/cjs/atoms/remove-duplicates-dialog.atom.js +37 -0
  37. package/dist/cjs/atoms/subtotal-dialog.atom.d.ts +39 -0
  38. package/dist/cjs/atoms/subtotal-dialog.atom.d.ts.map +1 -0
  39. package/dist/cjs/atoms/subtotal-dialog.atom.js +30 -0
  40. package/dist/cjs/atoms/text-to-columns-dialog.atom.d.ts +34 -0
  41. package/dist/cjs/atoms/text-to-columns-dialog.atom.d.ts.map +1 -0
  42. package/dist/cjs/atoms/text-to-columns-dialog.atom.js +36 -0
  43. package/dist/cjs/atoms/watch-window.atom.d.ts +37 -0
  44. package/dist/cjs/atoms/watch-window.atom.d.ts.map +1 -0
  45. package/dist/cjs/atoms/watch-window.atom.js +61 -0
  46. package/dist/cjs/components/advanced-filter-dialog/index.d.ts +28 -0
  47. package/dist/cjs/components/advanced-filter-dialog/index.d.ts.map +1 -0
  48. package/dist/cjs/components/advanced-filter-dialog/index.js +134 -0
  49. package/dist/cjs/components/calculation-options-dialog/index.d.ts +33 -0
  50. package/dist/cjs/components/calculation-options-dialog/index.d.ts.map +1 -0
  51. package/dist/cjs/components/calculation-options-dialog/index.js +69 -0
  52. package/dist/cjs/components/canvas-grid/index.d.ts.map +1 -1
  53. package/dist/cjs/components/canvas-grid/index.js +208 -19
  54. package/dist/cjs/components/canvas-grid/typings.d.ts +72 -9
  55. package/dist/cjs/components/canvas-grid/typings.d.ts.map +1 -1
  56. package/dist/cjs/components/cell/alignment.d.ts +30 -0
  57. package/dist/cjs/components/cell/alignment.d.ts.map +1 -1
  58. package/dist/cjs/components/cell/alignment.js +56 -1
  59. package/dist/cjs/components/cell/index.d.ts.map +1 -1
  60. package/dist/cjs/components/cell/index.js +15 -7
  61. package/dist/cjs/components/cell-diff/index.d.ts +3 -2
  62. package/dist/cjs/components/cell-diff/index.d.ts.map +1 -1
  63. package/dist/cjs/components/cell-editor/index.d.ts.map +1 -1
  64. package/dist/cjs/components/cell-editor/index.js +2 -1
  65. package/dist/cjs/components/context-menu/index.d.ts +21 -3
  66. package/dist/cjs/components/context-menu/index.d.ts.map +1 -1
  67. package/dist/cjs/components/context-menu/index.js +256 -6
  68. package/dist/cjs/components/context-menu/total-row-functions.d.ts +32 -0
  69. package/dist/cjs/components/context-menu/total-row-functions.d.ts.map +1 -0
  70. package/dist/cjs/components/context-menu/total-row-functions.js +62 -0
  71. package/dist/cjs/components/embeds/embed-component.d.ts.map +1 -1
  72. package/dist/cjs/components/embeds/embed-component.js +16 -1
  73. package/dist/cjs/components/evaluate-formula-dialog/index.d.ts +34 -0
  74. package/dist/cjs/components/evaluate-formula-dialog/index.d.ts.map +1 -0
  75. package/dist/cjs/components/evaluate-formula-dialog/index.js +106 -0
  76. package/dist/cjs/components/go-to-dialog/index.d.ts +45 -0
  77. package/dist/cjs/components/go-to-dialog/index.d.ts.map +1 -0
  78. package/dist/cjs/components/go-to-dialog/index.js +136 -0
  79. package/dist/cjs/components/goal-seek-dialog/index.d.ts +32 -0
  80. package/dist/cjs/components/goal-seek-dialog/index.d.ts.map +1 -0
  81. package/dist/cjs/components/goal-seek-dialog/index.js +149 -0
  82. package/dist/cjs/components/paste-special-dialog/index.d.ts +29 -0
  83. package/dist/cjs/components/paste-special-dialog/index.d.ts.map +1 -0
  84. package/dist/cjs/components/paste-special-dialog/index.js +99 -0
  85. package/dist/cjs/components/remove-duplicates-dialog/index.d.ts +37 -0
  86. package/dist/cjs/components/remove-duplicates-dialog/index.d.ts.map +1 -0
  87. package/dist/cjs/components/remove-duplicates-dialog/index.js +91 -0
  88. package/dist/cjs/components/subtotal-dialog/index.d.ts +30 -0
  89. package/dist/cjs/components/subtotal-dialog/index.d.ts.map +1 -0
  90. package/dist/cjs/components/subtotal-dialog/index.js +126 -0
  91. package/dist/cjs/components/text-to-columns-dialog/index.d.ts +37 -0
  92. package/dist/cjs/components/text-to-columns-dialog/index.d.ts.map +1 -0
  93. package/dist/cjs/components/text-to-columns-dialog/index.js +166 -0
  94. package/dist/cjs/components/toolbar/background-color-selector.d.ts +13 -1
  95. package/dist/cjs/components/toolbar/background-color-selector.d.ts.map +1 -1
  96. package/dist/cjs/components/toolbar/background-color-selector.js +57 -11
  97. package/dist/cjs/components/toolbar/cell-style-selector.d.ts +15 -2
  98. package/dist/cjs/components/toolbar/cell-style-selector.d.ts.map +1 -1
  99. package/dist/cjs/components/toolbar/cell-style-selector.js +56 -3
  100. package/dist/cjs/components/toolbar/fill-selectors.d.ts +49 -0
  101. package/dist/cjs/components/toolbar/fill-selectors.d.ts.map +1 -0
  102. package/dist/cjs/components/toolbar/fill-selectors.js +196 -0
  103. package/dist/cjs/components/toolbar/index.d.ts +2 -0
  104. package/dist/cjs/components/toolbar/index.d.ts.map +1 -1
  105. package/dist/cjs/components/toolbar/index.js +2 -0
  106. package/dist/cjs/components/toolbar/text-horizontal-align-selector.d.ts +8 -0
  107. package/dist/cjs/components/toolbar/text-horizontal-align-selector.d.ts.map +1 -1
  108. package/dist/cjs/components/toolbar/text-horizontal-align-selector.js +23 -4
  109. package/dist/cjs/components/toolbar/text-rotation-selector.d.ts +29 -0
  110. package/dist/cjs/components/toolbar/text-rotation-selector.d.ts.map +1 -0
  111. package/dist/cjs/components/toolbar/text-rotation-selector.js +78 -0
  112. package/dist/cjs/components/toolbar/text-wrap-selector.d.ts +7 -1
  113. package/dist/cjs/components/toolbar/text-wrap-selector.d.ts.map +1 -1
  114. package/dist/cjs/components/toolbar/text-wrap-selector.js +10 -3
  115. package/dist/cjs/components/watch-window/index.d.ts +25 -0
  116. package/dist/cjs/components/watch-window/index.d.ts.map +1 -0
  117. package/dist/cjs/components/watch-window/index.js +63 -0
  118. package/dist/cjs/hooks/use-cell-renderer.d.ts.map +1 -1
  119. package/dist/cjs/hooks/use-cell-renderer.js +17 -6
  120. package/dist/cjs/hooks/use-copy-paste-cut.d.ts +20 -1
  121. package/dist/cjs/hooks/use-copy-paste-cut.d.ts.map +1 -1
  122. package/dist/cjs/hooks/use-copy-paste-cut.js +25 -20
  123. package/dist/cjs/hooks/use-get-tooltip.d.ts.map +1 -1
  124. package/dist/cjs/hooks/use-get-tooltip.js +7 -2
  125. package/dist/cjs/hooks/use-keyboard-handler.d.ts +17 -2
  126. package/dist/cjs/hooks/use-keyboard-handler.d.ts.map +1 -1
  127. package/dist/cjs/hooks/use-keyboard-handler.js +206 -31
  128. package/dist/cjs/index.d.ts +14 -1
  129. package/dist/cjs/index.d.ts.map +1 -1
  130. package/dist/cjs/index.js +15 -1
  131. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  132. package/dist/cjs/types.d.ts +289 -4
  133. package/dist/cjs/types.d.ts.map +1 -1
  134. package/dist/cjs/types.js +19 -1
  135. package/dist/esm/api/evaluate-formula.d.ts +17 -0
  136. package/dist/esm/api/evaluate-formula.d.ts.map +1 -0
  137. package/dist/esm/api/evaluate-formula.js +109 -0
  138. package/dist/esm/api/excel-validation-kinds.d.ts +71 -0
  139. package/dist/esm/api/excel-validation-kinds.d.ts.map +1 -0
  140. package/dist/esm/api/excel-validation-kinds.js +287 -0
  141. package/dist/esm/api/go-to-special.d.ts +32 -0
  142. package/dist/esm/api/go-to-special.d.ts.map +1 -0
  143. package/dist/esm/api/go-to-special.js +96 -0
  144. package/dist/esm/api/go-to.d.ts +19 -0
  145. package/dist/esm/api/go-to.d.ts.map +1 -0
  146. package/dist/esm/api/go-to.js +41 -0
  147. package/dist/esm/api/validation-tooltip.d.ts +17 -0
  148. package/dist/esm/api/validation-tooltip.d.ts.map +1 -0
  149. package/dist/esm/api/validation-tooltip.js +34 -0
  150. package/dist/esm/atoms/advanced-filter-dialog.atom.d.ts +28 -0
  151. package/dist/esm/atoms/advanced-filter-dialog.atom.d.ts.map +1 -0
  152. package/dist/esm/atoms/advanced-filter-dialog.atom.js +21 -0
  153. package/dist/esm/atoms/evaluate-formula-dialog.atom.d.ts +36 -0
  154. package/dist/esm/atoms/evaluate-formula-dialog.atom.d.ts.map +1 -0
  155. package/dist/esm/atoms/evaluate-formula-dialog.atom.js +25 -0
  156. package/dist/esm/atoms/go-to-dialog.atom.d.ts +46 -0
  157. package/dist/esm/atoms/go-to-dialog.atom.d.ts.map +1 -0
  158. package/dist/esm/atoms/go-to-dialog.atom.js +25 -0
  159. package/dist/esm/atoms/goal-seek-dialog.atom.d.ts +29 -0
  160. package/dist/esm/atoms/goal-seek-dialog.atom.d.ts.map +1 -0
  161. package/dist/esm/atoms/goal-seek-dialog.atom.js +21 -0
  162. package/dist/esm/atoms/index.d.ts +5 -0
  163. package/dist/esm/atoms/index.d.ts.map +1 -1
  164. package/dist/esm/atoms/index.js +5 -0
  165. package/dist/esm/atoms/paste-special-dialog.atom.d.ts +29 -0
  166. package/dist/esm/atoms/paste-special-dialog.atom.d.ts.map +1 -0
  167. package/dist/esm/atoms/paste-special-dialog.atom.js +25 -0
  168. package/dist/esm/atoms/remove-duplicates-dialog.atom.d.ts +45 -0
  169. package/dist/esm/atoms/remove-duplicates-dialog.atom.d.ts.map +1 -0
  170. package/dist/esm/atoms/remove-duplicates-dialog.atom.js +26 -0
  171. package/dist/esm/atoms/subtotal-dialog.atom.d.ts +39 -0
  172. package/dist/esm/atoms/subtotal-dialog.atom.d.ts.map +1 -0
  173. package/dist/esm/atoms/subtotal-dialog.atom.js +21 -0
  174. package/dist/esm/atoms/text-to-columns-dialog.atom.d.ts +34 -0
  175. package/dist/esm/atoms/text-to-columns-dialog.atom.d.ts.map +1 -0
  176. package/dist/esm/atoms/text-to-columns-dialog.atom.js +25 -0
  177. package/dist/esm/atoms/watch-window.atom.d.ts +37 -0
  178. package/dist/esm/atoms/watch-window.atom.d.ts.map +1 -0
  179. package/dist/esm/atoms/watch-window.atom.js +37 -0
  180. package/dist/esm/components/advanced-filter-dialog/index.d.ts +28 -0
  181. package/dist/esm/components/advanced-filter-dialog/index.d.ts.map +1 -0
  182. package/dist/esm/components/advanced-filter-dialog/index.js +125 -0
  183. package/dist/esm/components/calculation-options-dialog/index.d.ts +33 -0
  184. package/dist/esm/components/calculation-options-dialog/index.d.ts.map +1 -0
  185. package/dist/esm/components/calculation-options-dialog/index.js +61 -0
  186. package/dist/esm/components/canvas-grid/index.d.ts.map +1 -1
  187. package/dist/esm/components/canvas-grid/index.js +202 -19
  188. package/dist/esm/components/canvas-grid/typings.d.ts +72 -9
  189. package/dist/esm/components/canvas-grid/typings.d.ts.map +1 -1
  190. package/dist/esm/components/cell/alignment.d.ts +30 -0
  191. package/dist/esm/components/cell/alignment.d.ts.map +1 -1
  192. package/dist/esm/components/cell/alignment.js +51 -0
  193. package/dist/esm/components/cell/index.d.ts.map +1 -1
  194. package/dist/esm/components/cell/index.js +16 -8
  195. package/dist/esm/components/cell-diff/index.d.ts +3 -2
  196. package/dist/esm/components/cell-diff/index.d.ts.map +1 -1
  197. package/dist/esm/components/cell-editor/index.d.ts.map +1 -1
  198. package/dist/esm/components/cell-editor/index.js +2 -1
  199. package/dist/esm/components/context-menu/index.d.ts +21 -3
  200. package/dist/esm/components/context-menu/index.d.ts.map +1 -1
  201. package/dist/esm/components/context-menu/index.js +251 -9
  202. package/dist/esm/components/context-menu/total-row-functions.d.ts +32 -0
  203. package/dist/esm/components/context-menu/total-row-functions.d.ts.map +1 -0
  204. package/dist/esm/components/context-menu/total-row-functions.js +50 -0
  205. package/dist/esm/components/embeds/embed-component.d.ts.map +1 -1
  206. package/dist/esm/components/embeds/embed-component.js +17 -1
  207. package/dist/esm/components/evaluate-formula-dialog/index.d.ts +34 -0
  208. package/dist/esm/components/evaluate-formula-dialog/index.d.ts.map +1 -0
  209. package/dist/esm/components/evaluate-formula-dialog/index.js +86 -0
  210. package/dist/esm/components/go-to-dialog/index.d.ts +45 -0
  211. package/dist/esm/components/go-to-dialog/index.d.ts.map +1 -0
  212. package/dist/esm/components/go-to-dialog/index.js +124 -0
  213. package/dist/esm/components/goal-seek-dialog/index.d.ts +32 -0
  214. package/dist/esm/components/goal-seek-dialog/index.d.ts.map +1 -0
  215. package/dist/esm/components/goal-seek-dialog/index.js +125 -0
  216. package/dist/esm/components/paste-special-dialog/index.d.ts +29 -0
  217. package/dist/esm/components/paste-special-dialog/index.d.ts.map +1 -0
  218. package/dist/esm/components/paste-special-dialog/index.js +90 -0
  219. package/dist/esm/components/remove-duplicates-dialog/index.d.ts +37 -0
  220. package/dist/esm/components/remove-duplicates-dialog/index.d.ts.map +1 -0
  221. package/dist/esm/components/remove-duplicates-dialog/index.js +82 -0
  222. package/dist/esm/components/subtotal-dialog/index.d.ts +30 -0
  223. package/dist/esm/components/subtotal-dialog/index.d.ts.map +1 -0
  224. package/dist/esm/components/subtotal-dialog/index.js +115 -0
  225. package/dist/esm/components/text-to-columns-dialog/index.d.ts +37 -0
  226. package/dist/esm/components/text-to-columns-dialog/index.d.ts.map +1 -0
  227. package/dist/esm/components/text-to-columns-dialog/index.js +147 -0
  228. package/dist/esm/components/toolbar/background-color-selector.d.ts +13 -1
  229. package/dist/esm/components/toolbar/background-color-selector.d.ts.map +1 -1
  230. package/dist/esm/components/toolbar/background-color-selector.js +61 -11
  231. package/dist/esm/components/toolbar/cell-style-selector.d.ts +15 -2
  232. package/dist/esm/components/toolbar/cell-style-selector.d.ts.map +1 -1
  233. package/dist/esm/components/toolbar/cell-style-selector.js +46 -2
  234. package/dist/esm/components/toolbar/fill-selectors.d.ts +49 -0
  235. package/dist/esm/components/toolbar/fill-selectors.d.ts.map +1 -0
  236. package/dist/esm/components/toolbar/fill-selectors.js +162 -0
  237. package/dist/esm/components/toolbar/index.d.ts +2 -0
  238. package/dist/esm/components/toolbar/index.d.ts.map +1 -1
  239. package/dist/esm/components/toolbar/index.js +2 -0
  240. package/dist/esm/components/toolbar/text-horizontal-align-selector.d.ts +8 -0
  241. package/dist/esm/components/toolbar/text-horizontal-align-selector.d.ts.map +1 -1
  242. package/dist/esm/components/toolbar/text-horizontal-align-selector.js +21 -5
  243. package/dist/esm/components/toolbar/text-rotation-selector.d.ts +29 -0
  244. package/dist/esm/components/toolbar/text-rotation-selector.d.ts.map +1 -0
  245. package/dist/esm/components/toolbar/text-rotation-selector.js +71 -0
  246. package/dist/esm/components/toolbar/text-wrap-selector.d.ts +7 -1
  247. package/dist/esm/components/toolbar/text-wrap-selector.d.ts.map +1 -1
  248. package/dist/esm/components/toolbar/text-wrap-selector.js +10 -3
  249. package/dist/esm/components/watch-window/index.d.ts +25 -0
  250. package/dist/esm/components/watch-window/index.d.ts.map +1 -0
  251. package/dist/esm/components/watch-window/index.js +54 -0
  252. package/dist/esm/hooks/use-cell-renderer.d.ts.map +1 -1
  253. package/dist/esm/hooks/use-cell-renderer.js +17 -6
  254. package/dist/esm/hooks/use-copy-paste-cut.d.ts +20 -1
  255. package/dist/esm/hooks/use-copy-paste-cut.d.ts.map +1 -1
  256. package/dist/esm/hooks/use-copy-paste-cut.js +8 -3
  257. package/dist/esm/hooks/use-get-tooltip.d.ts.map +1 -1
  258. package/dist/esm/hooks/use-get-tooltip.js +7 -2
  259. package/dist/esm/hooks/use-keyboard-handler.d.ts +17 -2
  260. package/dist/esm/hooks/use-keyboard-handler.d.ts.map +1 -1
  261. package/dist/esm/hooks/use-keyboard-handler.js +193 -31
  262. package/dist/esm/index.d.ts +14 -1
  263. package/dist/esm/index.d.ts.map +1 -1
  264. package/dist/esm/index.js +13 -0
  265. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  266. package/dist/esm/types.d.ts +289 -4
  267. package/dist/esm/types.d.ts.map +1 -1
  268. package/dist/esm/types.js +18 -0
  269. package/dist/spreadsheet.min.css +1 -1
  270. package/package.json +6 -6
@@ -0,0 +1,109 @@
1
+ /** `ERROR.TYPE` result → Excel error literal. */
2
+ export const ERROR_TYPE_CODES = {
3
+ 1: "#NULL!",
4
+ 2: "#DIV/0!",
5
+ 3: "#VALUE!",
6
+ 4: "#REF!",
7
+ 5: "#NAME?",
8
+ 6: "#NUM!",
9
+ 7: "#N/A",
10
+ 8: "#GETTING_DATA",
11
+ };
12
+ /**
13
+ * The error code of a `FormulaError`-shaped result (the unwrapped reference
14
+ * `useCalculation().onRequestCalculate` returns the error instance rather
15
+ * than throwing; the wrapped calculators return `undefined`). Duck-typed like
16
+ * the wrapper's `isFormulaErrorLike` so no parser import is needed here.
17
+ */
18
+ const formulaErrorCode = (value) => {
19
+ if (!(value instanceof Error))
20
+ return undefined;
21
+ const code = value.error;
22
+ return typeof code === "string" && code.startsWith("#") ? code : undefined;
23
+ };
24
+ const toEvaluationValue = (result) => {
25
+ const error = formulaErrorCode(result);
26
+ if (error)
27
+ return { error };
28
+ if (Array.isArray(result)) {
29
+ return result.map((row) => Array.isArray(row)
30
+ ? row.map((cell) => toEvaluationValue(cell))
31
+ : [toEvaluationValue(row)]);
32
+ }
33
+ if (result === null ||
34
+ result === undefined ||
35
+ typeof result === "string" ||
36
+ typeof result === "number" ||
37
+ typeof result === "boolean" ||
38
+ result instanceof Date) {
39
+ return result;
40
+ }
41
+ return String(result);
42
+ };
43
+ /**
44
+ * `onRequestCalculate` is the cell editor's live preview, so it reports
45
+ * DISPLAY text: the rnc engine stringifies numbers and booleans, the
46
+ * reference wrapper returns the formatted value (`1,234.50`, `$5.00`,
47
+ * `TRUE`). Substituting that text verbatim would turn `=A1=15` into
48
+ * `"15"=15` (FALSE) or `"1,234.50"*2` (#VALUE!), so the text is re-typed
49
+ * through the engine itself: `TYPE(expression)` says number / text /
50
+ * boolean, and a number is re-read as General text (`&""` keeps both probes
51
+ * clear of the cell's number format) so it parses back to a number.
52
+ */
53
+ const retypeDisplayText = async (text, expression, calculate) => {
54
+ const typeCode = await calculate(`=TYPE(${expression})&""`);
55
+ switch (typeof typeCode === "string" ? typeCode.trim() : typeCode) {
56
+ case "1":
57
+ case 1: {
58
+ const direct = Number(text);
59
+ if (Number.isFinite(direct) && text.trim() !== "")
60
+ return direct;
61
+ const general = await calculate(`=(${expression})&""`);
62
+ const parsed = Number(typeof general === "string" ? general : NaN);
63
+ return Number.isFinite(parsed) ? parsed : text;
64
+ }
65
+ case "4":
66
+ case 4: {
67
+ const upper = text.trim().toUpperCase();
68
+ if (upper === "TRUE")
69
+ return true;
70
+ if (upper === "FALSE")
71
+ return false;
72
+ const numeric = await calculate(`=--(${expression})&""`);
73
+ return typeof numeric === "string" ? numeric.trim() === "1" : text;
74
+ }
75
+ default:
76
+ return text;
77
+ }
78
+ };
79
+ /**
80
+ * Build the Evaluate Formula stepper's `evaluate` from the grid's
81
+ * `onRequestCalculate` (the cell editor's live-preview calculator — a
82
+ * read-only scratch evaluation in both engines). A string result is
83
+ * re-typed through the engine (see `retypeDisplayText`); a `FormulaError`
84
+ * instance (unwrapped reference calculator) becomes the error literal; the
85
+ * wrapped calculators report a formula error as an empty result, so a blank
86
+ * answer is re-asked as `ERROR.TYPE(expression)` to recover the error
87
+ * literal and a genuine blank stays `null`.
88
+ */
89
+ export const createExpressionEvaluator = (onRequestCalculate, sheetId, cell) => {
90
+ const calculate = (formula) => onRequestCalculate(formula, sheetId, cell.rowIndex, cell.columnIndex);
91
+ return async (expression) => {
92
+ const value = toEvaluationValue(await calculate(`=${expression}`));
93
+ if (typeof value === "string") {
94
+ return retypeDisplayText(value, expression, calculate);
95
+ }
96
+ if (value !== null && value !== undefined)
97
+ return value;
98
+ const errorType = await calculate(`=ERROR.TYPE(${expression})&""`);
99
+ const code = typeof errorType === "number"
100
+ ? errorType
101
+ : typeof errorType === "string"
102
+ ? Number(errorType)
103
+ : NaN;
104
+ if (ERROR_TYPE_CODES[code]) {
105
+ return { error: ERROR_TYPE_CODES[code] };
106
+ }
107
+ return null;
108
+ };
109
+ };
@@ -0,0 +1,71 @@
1
+ import type { DataValidationRule, SheetRange } from "../types";
2
+ /**
3
+ * Excel's data-validation "Allow" kinds that have no `ConditionType` of
4
+ * their own. Each is authored as Excel's `type` + `operator` + up to two
5
+ * formulas and stored two ways at once:
6
+ *
7
+ * - `condition` — what both engines evaluate for the red Invalid marker:
8
+ * `whole` and `textLength` compose a `CUSTOM_FORMULA` over the range
9
+ * anchor (the same shape both importers synthesize), `time` is a plain
10
+ * `NUMBER_*` comparison over day-fraction serials;
11
+ * - `xlsxSource` — the Excel-native description both xlsx exporters replay
12
+ * verbatim (`type="whole"` …), so the rule round-trips as what the user
13
+ * picked instead of a decimal / custom rule.
14
+ *
15
+ * Imported rules already carry `xlsxSource`, so the editor reads them back
16
+ * as "Whole number between 1 and 10" rather than a custom formula.
17
+ */
18
+ export type ExcelValidationKind = "whole" | "time" | "textLength";
19
+ export type ExcelValidationOperator = "between" | "notBetween" | "equal" | "notEqual" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual";
20
+ export type ExcelValidationSpec = {
21
+ kind: ExcelValidationKind;
22
+ operator: ExcelValidationOperator;
23
+ /** Bound(s) as the user typed them: a literal (`10`, `9:30 AM`) or `=ref`. */
24
+ formula1?: string;
25
+ formula2?: string;
26
+ };
27
+ export declare const EXCEL_VALIDATION_KIND_LABELS: ReadonlyArray<{
28
+ kind: ExcelValidationKind;
29
+ label: string;
30
+ }>;
31
+ export declare const EXCEL_VALIDATION_OPERATOR_LABELS: ReadonlyArray<{
32
+ operator: ExcelValidationOperator;
33
+ label: string;
34
+ }>;
35
+ /** Two-sided operators need both bounds. */
36
+ export declare const isTwoSidedOperator: (operator: ExcelValidationOperator) => operator is "between" | "notBetween";
37
+ /**
38
+ * Parse a typed time (`9:30`, `9:30 AM`, `21:05:10`, `24:00`, `0.5`) to
39
+ * Excel's serial. A bare non-negative number is taken as a serial already and
40
+ * kept whole (Excel's Time validation compares the full serial, so a
41
+ * date-time is out of a same-day range). `undefined` when unparsable.
42
+ */
43
+ export declare const parseTimeToSerial: (text: string | undefined) => number | undefined;
44
+ /** Render a day-fraction serial as `h:mm AM/PM` (seconds when non-zero). */
45
+ export declare const formatTimeSerial: (serial: number) => string;
46
+ /** The A1 anchor (range top-left) a relative custom formula is written against. */
47
+ export declare const getValidationAnchor: (range: SheetRange | undefined) => string;
48
+ /**
49
+ * Build the `condition` + `xlsxSource` pair for an Excel kind. Returns
50
+ * `undefined` when a required bound is missing (the editor keeps the form
51
+ * open in that case).
52
+ */
53
+ export declare const buildExcelValidationRule: (spec: ExcelValidationSpec, anchor: string) => Pick<DataValidationRule, "condition" | "xlsxSource"> | undefined;
54
+ /**
55
+ * Read an Excel kind back from a rule's `xlsxSource` (imported or authored
56
+ * here); `undefined` for every other rule. Time bounds come back as
57
+ * `h:mm AM/PM` text so the editor shows what the user would type.
58
+ */
59
+ export declare const readExcelValidationSpec: (rule: Pick<DataValidationRule, "xlsxSource"> | undefined | null) => ExcelValidationSpec | undefined;
60
+ /** A typed value that is a formula (`=…`) — validated on its result, not its text. */
61
+ export declare const isFormulaEntry: (value: unknown) => value is string;
62
+ /**
63
+ * Decide an Excel-kind rule for a freshly typed value without the
64
+ * calculator — the commit-time enforcement Excel applies (`stop` blocks a
65
+ * decimal in a whole-number cell). `undefined` when the bounds are
66
+ * formulas / references, or when the typed value is itself a formula
67
+ * (Excel validates the formula's RESULT after the recalc, so `=5` is a
68
+ * valid whole number), so the caller falls back to the flag-only marker.
69
+ */
70
+ export declare const checkExcelValidationValue: (rule: Pick<DataValidationRule, "xlsxSource"> | undefined | null, value: string | boolean) => boolean | undefined;
71
+ //# sourceMappingURL=excel-validation-kinds.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excel-validation-kinds.d.ts","sourceRoot":"","sources":["../../../api/excel-validation-kinds.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,kBAAkB,EAClB,UAAU,EACX,MAAM,UAAU,CAAC;AAElB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,MAAM,GAAG,YAAY,CAAC;AAElE,MAAM,MAAM,uBAAuB,GAC/B,SAAS,GACT,YAAY,GACZ,OAAO,GACP,UAAU,GACV,aAAa,GACb,UAAU,GACV,oBAAoB,GACpB,iBAAiB,CAAC;AAEtB,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,EAAE,uBAAuB,CAAC;IAClC,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,4BAA4B,EAAE,aAAa,CAAC;IACvD,IAAI,EAAE,mBAAmB,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;CACf,CAIA,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,aAAa,CAAC;IAC3D,QAAQ,EAAE,uBAAuB,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;CACf,CASA,CAAC;AAOF,4CAA4C;AAC5C,eAAO,MAAM,kBAAkB,GAAI,UAAU,uBAAuB,yCACf,CAAC;AAwBtD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,GAAG,SAAS,KACvB,MAAM,GAAG,SAuBX,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MAUjD,CAAC;AAoBF,mFAAmF;AACnF,eAAO,MAAM,mBAAmB,GAAI,OAAO,UAAU,GAAG,SAAS,KAAG,MAKzD,CAAC;AAgCZ;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,GACnC,MAAM,mBAAmB,EACzB,QAAQ,MAAM,KACb,IAAI,CAAC,kBAAkB,EAAE,WAAW,GAAG,YAAY,CAAC,GAAG,SAiDzD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,MAAM,IAAI,CAAC,kBAAkB,EAAE,YAAY,CAAC,GAAG,SAAS,GAAG,IAAI,KAC9D,mBAAmB,GAAG,SAuBxB,CAAC;AAmCF,sFAAsF;AACtF,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACE,CAAC;AAE5D;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GACpC,MAAM,IAAI,CAAC,kBAAkB,EAAE,YAAY,CAAC,GAAG,SAAS,GAAG,IAAI,EAC/D,OAAO,MAAM,GAAG,OAAO,KACtB,OAAO,GAAG,SAmCZ,CAAC"}
@@ -0,0 +1,287 @@
1
+ import { cellToAddress } from "@rowsncolumns/utils";
2
+ export const EXCEL_VALIDATION_KIND_LABELS = [
3
+ { kind: "whole", label: "Whole number" },
4
+ { kind: "time", label: "Time" },
5
+ { kind: "textLength", label: "Text length" },
6
+ ];
7
+ export const EXCEL_VALIDATION_OPERATOR_LABELS = [
8
+ { operator: "between", label: "between" },
9
+ { operator: "notBetween", label: "not between" },
10
+ { operator: "equal", label: "equal to" },
11
+ { operator: "notEqual", label: "not equal to" },
12
+ { operator: "greaterThan", label: "greater than" },
13
+ { operator: "lessThan", label: "less than" },
14
+ { operator: "greaterThanOrEqual", label: "greater than or equal to" },
15
+ { operator: "lessThanOrEqual", label: "less than or equal to" },
16
+ ];
17
+ const EXCEL_KINDS = new Set(["whole", "time", "textLength"]);
18
+ const EXCEL_OPERATORS = new Set(EXCEL_VALIDATION_OPERATOR_LABELS.map((entry) => entry.operator));
19
+ /** Two-sided operators need both bounds. */
20
+ export const isTwoSidedOperator = (operator) => operator === "between" || operator === "notBetween";
21
+ const NUMBER_CONDITION_BY_OPERATOR = {
22
+ between: "NUMBER_BETWEEN",
23
+ notBetween: "NUMBER_NOT_BETWEEN",
24
+ equal: "NUMBER_EQ",
25
+ notEqual: "NUMBER_NOT_EQ",
26
+ greaterThan: "NUMBER_GREATER",
27
+ lessThan: "NUMBER_LESS",
28
+ greaterThanOrEqual: "NUMBER_GREATER_THAN_EQ",
29
+ lessThanOrEqual: "NUMBER_LESS_THAN_EQ",
30
+ };
31
+ const stripEquals = (text) => {
32
+ const trimmed = text?.trim() ?? "";
33
+ return trimmed.startsWith("=") ? trimmed.slice(1).trim() : trimmed;
34
+ };
35
+ const TIME_PATTERN = /^(\d{1,2})(?::(\d{1,2}))?(?::(\d{1,2}))?\s*([AaPp][Mm]?)?$/;
36
+ /**
37
+ * Parse a typed time (`9:30`, `9:30 AM`, `21:05:10`, `24:00`, `0.5`) to
38
+ * Excel's serial. A bare non-negative number is taken as a serial already and
39
+ * kept whole (Excel's Time validation compares the full serial, so a
40
+ * date-time is out of a same-day range). `undefined` when unparsable.
41
+ */
42
+ export const parseTimeToSerial = (text) => {
43
+ const trimmed = text?.trim() ?? "";
44
+ if (!trimmed)
45
+ return undefined;
46
+ const asNumber = Number(trimmed);
47
+ if (Number.isFinite(asNumber)) {
48
+ return asNumber >= 0 ? asNumber : undefined;
49
+ }
50
+ const match = TIME_PATTERN.exec(trimmed);
51
+ if (!match)
52
+ return undefined;
53
+ let hours = Number(match[1]);
54
+ const minutes = Number(match[2] ?? 0);
55
+ const seconds = Number(match[3] ?? 0);
56
+ const meridiem = match[4]?.toLowerCase();
57
+ if (minutes > 59 || seconds > 59)
58
+ return undefined;
59
+ if (meridiem) {
60
+ if (hours < 1 || hours > 12)
61
+ return undefined;
62
+ if (meridiem.startsWith("p") && hours !== 12)
63
+ hours += 12;
64
+ if (meridiem.startsWith("a") && hours === 12)
65
+ hours = 0;
66
+ }
67
+ else if (hours > 24 || (hours === 24 && (minutes > 0 || seconds > 0))) {
68
+ // Excel accepts `24:00` as exactly 1.0 (midnight at the end of the day).
69
+ return undefined;
70
+ }
71
+ return (hours * 3600 + minutes * 60 + seconds) / 86400;
72
+ };
73
+ /** Render a day-fraction serial as `h:mm AM/PM` (seconds when non-zero). */
74
+ export const formatTimeSerial = (serial) => {
75
+ const total = Math.round((serial - Math.floor(serial)) * 86400) % 86400;
76
+ const hours24 = Math.floor(total / 3600);
77
+ const minutes = Math.floor((total % 3600) / 60);
78
+ const seconds = total % 60;
79
+ const meridiem = hours24 >= 12 ? "PM" : "AM";
80
+ const hours12 = hours24 % 12 === 0 ? 12 : hours24 % 12;
81
+ const mm = String(minutes).padStart(2, "0");
82
+ const ss = seconds ? `:${String(seconds).padStart(2, "0")}` : "";
83
+ return `${hours12}:${mm}${ss} ${meridiem}`;
84
+ };
85
+ /**
86
+ * A bound as it goes into a formula / `xlsxSource`: references and formulas
87
+ * verbatim (no `=`), times as serials, numbers as typed.
88
+ */
89
+ const toBoundFormula = (kind, text) => {
90
+ const raw = text?.trim() ?? "";
91
+ if (!raw)
92
+ return undefined;
93
+ if (raw.startsWith("="))
94
+ return stripEquals(raw);
95
+ if (kind === "time") {
96
+ const serial = parseTimeToSerial(raw);
97
+ return serial === undefined ? raw : String(serial);
98
+ }
99
+ return raw;
100
+ };
101
+ /** The A1 anchor (range top-left) a relative custom formula is written against. */
102
+ export const getValidationAnchor = (range) => cellToAddress(range
103
+ ? { rowIndex: range.startRowIndex, columnIndex: range.startColumnIndex }
104
+ : { rowIndex: 1, columnIndex: 1 }) ?? "A1";
105
+ const comparison = (subject, operator, a, b) => {
106
+ switch (operator) {
107
+ case "between":
108
+ return b === undefined
109
+ ? undefined
110
+ : `AND(${subject}>=${a},${subject}<=${b})`;
111
+ case "notBetween":
112
+ return b === undefined
113
+ ? undefined
114
+ : `OR(${subject}<${a},${subject}>${b})`;
115
+ case "equal":
116
+ return `${subject}=${a}`;
117
+ case "notEqual":
118
+ return `${subject}<>${a}`;
119
+ case "greaterThan":
120
+ return `${subject}>${a}`;
121
+ case "lessThan":
122
+ return `${subject}<${a}`;
123
+ case "greaterThanOrEqual":
124
+ return `${subject}>=${a}`;
125
+ case "lessThanOrEqual":
126
+ return `${subject}<=${a}`;
127
+ }
128
+ };
129
+ /**
130
+ * Build the `condition` + `xlsxSource` pair for an Excel kind. Returns
131
+ * `undefined` when a required bound is missing (the editor keeps the form
132
+ * open in that case).
133
+ */
134
+ export const buildExcelValidationRule = (spec, anchor) => {
135
+ const formula1 = toBoundFormula(spec.kind, spec.formula1);
136
+ const formula2 = toBoundFormula(spec.kind, spec.formula2);
137
+ if (!formula1)
138
+ return undefined;
139
+ if (isTwoSidedOperator(spec.operator) && !formula2)
140
+ return undefined;
141
+ const xlsxSource = {
142
+ type: spec.kind,
143
+ operator: spec.operator,
144
+ formula1,
145
+ ...(isTwoSidedOperator(spec.operator) ? { formula2 } : {}),
146
+ };
147
+ if (spec.kind === "time") {
148
+ const condition = {
149
+ type: NUMBER_CONDITION_BY_OPERATOR[spec.operator],
150
+ values: [
151
+ {
152
+ userEnteredValue: /^[A-Za-z$'!]/.test(formula1)
153
+ ? `=${formula1}`
154
+ : formula1,
155
+ },
156
+ ...(isTwoSidedOperator(spec.operator) && formula2
157
+ ? [
158
+ {
159
+ userEnteredValue: /^[A-Za-z$'!]/.test(formula2)
160
+ ? `=${formula2}`
161
+ : formula2,
162
+ },
163
+ ]
164
+ : []),
165
+ ],
166
+ };
167
+ return { condition, xlsxSource };
168
+ }
169
+ const subject = spec.kind === "textLength" ? `LEN(${anchor})` : anchor;
170
+ const body = comparison(subject, spec.operator, formula1, formula2);
171
+ if (!body)
172
+ return undefined;
173
+ const formula = spec.kind === "whole"
174
+ ? `=AND(ISNUMBER(${anchor}),${anchor}=INT(${anchor}),${body})`
175
+ : `=${body}`;
176
+ return {
177
+ condition: {
178
+ type: "CUSTOM_FORMULA",
179
+ values: [{ userEnteredValue: formula }],
180
+ },
181
+ xlsxSource,
182
+ };
183
+ };
184
+ /**
185
+ * Read an Excel kind back from a rule's `xlsxSource` (imported or authored
186
+ * here); `undefined` for every other rule. Time bounds come back as
187
+ * `h:mm AM/PM` text so the editor shows what the user would type.
188
+ */
189
+ export const readExcelValidationSpec = (rule) => {
190
+ const source = rule?.xlsxSource;
191
+ if (!source || !EXCEL_KINDS.has(source.type))
192
+ return undefined;
193
+ const operator = (source.operator && EXCEL_OPERATORS.has(source.operator)
194
+ ? source.operator
195
+ : "between");
196
+ const kind = source.type;
197
+ const display = (formula) => {
198
+ if (formula === undefined || formula === "")
199
+ return undefined;
200
+ const asNumber = Number(formula);
201
+ if (Number.isFinite(asNumber)) {
202
+ return kind === "time" ? formatTimeSerial(asNumber) : formula;
203
+ }
204
+ return `=${formula}`;
205
+ };
206
+ return {
207
+ kind,
208
+ operator,
209
+ formula1: display(source.formula1),
210
+ formula2: display(source.formula2),
211
+ };
212
+ };
213
+ const compare = (subject, operator, a, b) => {
214
+ switch (operator) {
215
+ case "between":
216
+ return (b !== undefined &&
217
+ subject >= Math.min(a, b) &&
218
+ subject <= Math.max(a, b));
219
+ case "notBetween":
220
+ return (b !== undefined &&
221
+ (subject < Math.min(a, b) || subject > Math.max(a, b)));
222
+ case "equal":
223
+ return subject === a;
224
+ case "notEqual":
225
+ return subject !== a;
226
+ case "greaterThan":
227
+ return subject > a;
228
+ case "lessThan":
229
+ return subject < a;
230
+ case "greaterThanOrEqual":
231
+ return subject >= a;
232
+ case "lessThanOrEqual":
233
+ return subject <= a;
234
+ }
235
+ };
236
+ /** A typed value that is a formula (`=…`) — validated on its result, not its text. */
237
+ export const isFormulaEntry = (value) => typeof value === "string" && value.trim().startsWith("=");
238
+ /**
239
+ * Decide an Excel-kind rule for a freshly typed value without the
240
+ * calculator — the commit-time enforcement Excel applies (`stop` blocks a
241
+ * decimal in a whole-number cell). `undefined` when the bounds are
242
+ * formulas / references, or when the typed value is itself a formula
243
+ * (Excel validates the formula's RESULT after the recalc, so `=5` is a
244
+ * valid whole number), so the caller falls back to the flag-only marker.
245
+ */
246
+ export const checkExcelValidationValue = (rule, value) => {
247
+ const source = rule?.xlsxSource;
248
+ if (!source || !EXCEL_KINDS.has(source.type))
249
+ return undefined;
250
+ if (isFormulaEntry(value))
251
+ return undefined;
252
+ const operator = (source.operator ?? "between");
253
+ if (!EXCEL_OPERATORS.has(operator))
254
+ return undefined;
255
+ const a = Number(source.formula1);
256
+ const b = source.formula2 === undefined ? undefined : Number(source.formula2);
257
+ if (!Number.isFinite(a))
258
+ return undefined;
259
+ if (isTwoSidedOperator(operator) &&
260
+ !(b !== undefined && Number.isFinite(b))) {
261
+ return undefined;
262
+ }
263
+ const text = typeof value === "boolean" ? (value ? "TRUE" : "FALSE") : value;
264
+ switch (source.type) {
265
+ case "textLength":
266
+ return compare(Array.from(text).length, operator, a, b);
267
+ case "whole": {
268
+ if (typeof value === "boolean")
269
+ return false;
270
+ const num = Number(text.trim());
271
+ if (!Number.isFinite(num) || !Number.isInteger(num))
272
+ return false;
273
+ return compare(num, operator, a, b);
274
+ }
275
+ case "time": {
276
+ if (typeof value === "boolean")
277
+ return false;
278
+ // Excel compares the cell's full serial against the bounds (a
279
+ // date-time such as 45292.5 is NOT between 9:00 and 12:00) — the same
280
+ // comparison the composed `NUMBER_*` condition makes for the marker.
281
+ const serial = parseTimeToSerial(text);
282
+ if (serial === undefined)
283
+ return false;
284
+ return compare(serial, operator, a, b);
285
+ }
286
+ }
287
+ };
@@ -0,0 +1,32 @@
1
+ import type { GridRange } from "@rowsncolumns/grid";
2
+ import type { CellData } from "../types";
3
+ /**
4
+ * Excel's Go To Special categories that can be decided from cell data alone.
5
+ * (Row / column differences, precedents / dependents and objects are served
6
+ * by the trace arrows and the drawing layer, not by this dialog.)
7
+ */
8
+ export type GoToSpecialKind = "blanks" | "constants" | "formulas" | "errors" | "notes" | "visible";
9
+ export declare const GO_TO_SPECIAL_OPTIONS: ReadonlyArray<{
10
+ kind: GoToSpecialKind;
11
+ label: string;
12
+ }>;
13
+ export type GoToSpecialContext<T extends CellData = CellData> = {
14
+ sheetId: number;
15
+ /** The area to scan — the current selection, or the used range for a single cell. */
16
+ range: GridRange;
17
+ getCellData(sheetId: number, rowIndex: number, columnIndex: number): T | null | undefined;
18
+ isRowHidden?(rowIndex: number): boolean;
19
+ isColumnHidden?(columnIndex: number): boolean;
20
+ /** Scan guard — Excel refuses huge Go To Special selections as well. */
21
+ maxCells?: number;
22
+ };
23
+ /** Cells scanned before the search gives up (returns what it found so far). */
24
+ export declare const GO_TO_SPECIAL_MAX_CELLS = 250000;
25
+ /**
26
+ * Resolve a Go To Special category to the matching cells of `range`, packed
27
+ * into per-row runs of adjacent columns (what the selection layer paints).
28
+ * Hidden rows / columns are skipped for every kind — Excel never selects
29
+ * into a hidden cell from Go To Special. Returns `[]` when nothing matches.
30
+ */
31
+ export declare const resolveGoToSpecial: <T extends CellData>(kind: GoToSpecialKind, context: GoToSpecialContext<T>) => GridRange[];
32
+ //# sourceMappingURL=go-to-special.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"go-to-special.d.ts","sourceRoot":"","sources":["../../../api/go-to-special.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC;;;;GAIG;AACH,MAAM,MAAM,eAAe,GACvB,QAAQ,GACR,WAAW,GACX,UAAU,GACV,QAAQ,GACR,OAAO,GACP,SAAS,CAAC;AAEd,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC;IAChD,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf,CAOA,CAAC;AAEF,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI;IAC9D,OAAO,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,KAAK,EAAE,SAAS,CAAC;IACjB,WAAW,CACT,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACxB,WAAW,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC,cAAc,CAAC,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;IAC9C,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAmD/C;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,QAAQ,EACnD,MAAM,eAAe,EACrB,SAAS,kBAAkB,CAAC,CAAC,CAAC,KAC7B,SAAS,EAoCX,CAAC"}
@@ -0,0 +1,96 @@
1
+ export const GO_TO_SPECIAL_OPTIONS = [
2
+ { kind: "notes", label: "Notes" },
3
+ { kind: "constants", label: "Constants" },
4
+ { kind: "formulas", label: "Formulas" },
5
+ { kind: "errors", label: "Errors" },
6
+ { kind: "blanks", label: "Blanks" },
7
+ { kind: "visible", label: "Visible cells only" },
8
+ ];
9
+ /** Cells scanned before the search gives up (returns what it found so far). */
10
+ export const GO_TO_SPECIAL_MAX_CELLS = 250_000;
11
+ const hasContent = (cell) => {
12
+ const ue = cell?.ue ?? cell?.userEnteredValue;
13
+ if (!ue)
14
+ return false;
15
+ return (ue.fv != null ||
16
+ ue.formulaValue != null ||
17
+ ue.sv != null ||
18
+ ue.stringValue != null ||
19
+ ue.nv != null ||
20
+ ue.numberValue != null ||
21
+ ue.bv != null ||
22
+ ue.boolValue != null);
23
+ };
24
+ const isFormula = (cell) => {
25
+ const ue = cell?.ue ?? cell?.userEnteredValue;
26
+ return typeof (ue?.fv ?? ue?.formulaValue) === "string";
27
+ };
28
+ const isError = (cell) => {
29
+ const ev = cell?.ev ?? cell?.effectiveValue;
30
+ const error = ev?.ev ?? ev?.errorValue;
31
+ return !!error && error.type === "Error";
32
+ };
33
+ const hasNote = (cell) => typeof cell?.note === "string" && cell.note.trim().length > 0;
34
+ const matches = (kind, cell) => {
35
+ switch (kind) {
36
+ case "blanks":
37
+ return !hasContent(cell);
38
+ case "constants":
39
+ return hasContent(cell) && !isFormula(cell);
40
+ case "formulas":
41
+ return isFormula(cell);
42
+ case "errors":
43
+ return isError(cell);
44
+ case "notes":
45
+ return hasNote(cell);
46
+ case "visible":
47
+ return true;
48
+ }
49
+ };
50
+ /**
51
+ * Resolve a Go To Special category to the matching cells of `range`, packed
52
+ * into per-row runs of adjacent columns (what the selection layer paints).
53
+ * Hidden rows / columns are skipped for every kind — Excel never selects
54
+ * into a hidden cell from Go To Special. Returns `[]` when nothing matches.
55
+ */
56
+ export const resolveGoToSpecial = (kind, context) => {
57
+ const { sheetId, range, getCellData, isRowHidden, isColumnHidden } = context;
58
+ const maxCells = context.maxCells ?? GO_TO_SPECIAL_MAX_CELLS;
59
+ const runs = [];
60
+ let scanned = 0;
61
+ for (let row = range.startRowIndex; row <= range.endRowIndex; row++) {
62
+ if (isRowHidden?.(row))
63
+ continue;
64
+ let runStart;
65
+ const flush = (endColumn) => {
66
+ if (runStart === undefined)
67
+ return;
68
+ runs.push({
69
+ startRowIndex: row,
70
+ endRowIndex: row,
71
+ startColumnIndex: runStart,
72
+ endColumnIndex: endColumn,
73
+ });
74
+ runStart = undefined;
75
+ };
76
+ for (let col = range.startColumnIndex; col <= range.endColumnIndex; col++) {
77
+ if (++scanned > maxCells) {
78
+ flush(col - 1);
79
+ return runs;
80
+ }
81
+ if (isColumnHidden?.(col)) {
82
+ flush(col - 1);
83
+ continue;
84
+ }
85
+ if (matches(kind, getCellData(sheetId, row, col))) {
86
+ if (runStart === undefined)
87
+ runStart = col;
88
+ }
89
+ else {
90
+ flush(col - 1);
91
+ }
92
+ }
93
+ flush(range.endColumnIndex);
94
+ }
95
+ return runs;
96
+ };
@@ -0,0 +1,19 @@
1
+ import type { NamedRange, SheetRange } from "../types";
2
+ export type GoToResolverContext = {
3
+ /** The sheet an unqualified reference (`A1`, `B2:C4`) is resolved against. */
4
+ sheetId: number;
5
+ namedRanges?: NamedRange[] | null;
6
+ /** Resolves `Sheet2!A1` / `'My Sheet'!A1`. Sheet-qualified input fails without it. */
7
+ getSheetId?: (sheetName: string) => number | undefined;
8
+ rowCount?: number;
9
+ columnCount?: number;
10
+ };
11
+ /**
12
+ * Resolve what the user typed into Excel's Go To box: a defined name (case
13
+ * insensitive), an A1 reference (`A1`, `$B$2:C4`, `A:A`, `3:3`) or a
14
+ * sheet-qualified reference (`Sheet2!A1`, `'My Sheet'!B2:C3`). A leading `=`
15
+ * is tolerated. Returns `undefined` when nothing matches — the dialog shows
16
+ * Excel's "Reference is not valid." then.
17
+ */
18
+ export declare const resolveGoToReference: (input: string, context: GoToResolverContext) => SheetRange | undefined;
19
+ //# sourceMappingURL=go-to.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"go-to.d.ts","sourceRoot":"","sources":["../../../api/go-to.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEvD,MAAM,MAAM,mBAAmB,GAAG;IAChC,8EAA8E;IAC9E,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IAClC,sFAAsF;IACtF,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IACvD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAiBF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAO,MAAM,EACb,SAAS,mBAAmB,KAC3B,UAAU,GAAG,SA6Bf,CAAC"}
@@ -0,0 +1,41 @@
1
+ import { addressToSheetRange } from "@rowsncolumns/utils";
2
+ // Rows are 1-based: `A0` / `0:0` are "Reference is not valid." in Excel (on
3
+ // this grid row 0 is the column header).
4
+ const CELL = "\\$?[A-Za-z]{1,3}\\$?[1-9]\\d*";
5
+ const COLUMN = "\\$?[A-Za-z]{1,3}";
6
+ const ROW = "\\$?[1-9]\\d*";
7
+ const A1_REFERENCE = new RegExp(`^(?:${CELL}(?::${CELL})?|${COLUMN}:${COLUMN}|${ROW}:${ROW})$`);
8
+ /** `'My Sheet'` → `My Sheet` (doubled quotes unescaped); bare names pass through. */
9
+ const unquoteSheetName = (name) => name.startsWith("'") && name.endsWith("'") && name.length >= 2
10
+ ? name.slice(1, -1).replace(/''/g, "'")
11
+ : name;
12
+ /**
13
+ * Resolve what the user typed into Excel's Go To box: a defined name (case
14
+ * insensitive), an A1 reference (`A1`, `$B$2:C4`, `A:A`, `3:3`) or a
15
+ * sheet-qualified reference (`Sheet2!A1`, `'My Sheet'!B2:C3`). A leading `=`
16
+ * is tolerated. Returns `undefined` when nothing matches — the dialog shows
17
+ * Excel's "Reference is not valid." then.
18
+ */
19
+ export const resolveGoToReference = (input, context) => {
20
+ const text = input.trim().replace(/^=/, "").trim();
21
+ if (!text)
22
+ return undefined;
23
+ const named = context.namedRanges?.find((range) => range.name.toLowerCase() === text.toLowerCase());
24
+ if (named?.range) {
25
+ return { ...named.range };
26
+ }
27
+ let sheetId = context.sheetId;
28
+ let reference = text;
29
+ const bang = text.lastIndexOf("!");
30
+ if (bang !== -1) {
31
+ const sheetName = unquoteSheetName(text.slice(0, bang).trim());
32
+ reference = text.slice(bang + 1).trim();
33
+ const resolved = context.getSheetId?.(sheetName);
34
+ if (resolved === undefined)
35
+ return undefined;
36
+ sheetId = resolved;
37
+ }
38
+ if (!A1_REFERENCE.test(reference))
39
+ return undefined;
40
+ return addressToSheetRange(reference.toUpperCase(), sheetId, context.rowCount, context.columnCount);
41
+ };