@dxos/plugin-sheet 0.6.13-main.ed424a1 → 0.6.13

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 (323) hide show
  1. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +1772 -0
  2. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-APHOLYUB.mjs +175 -0
  4. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +7 -0
  5. package/dist/lib/{node-esm/chunk-5WPZCXNS.mjs → browser/chunk-D5AGLXJP.mjs} +678 -411
  6. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-FUAGSXA4.mjs +82 -0
  8. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-JRL5LGCE.mjs +18 -0
  10. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-NU4PBN33.mjs +8 -0
  12. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +62 -93
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/meta.mjs +1 -1
  17. package/dist/lib/browser/testing.mjs +92 -0
  18. package/dist/lib/browser/testing.mjs.map +7 -0
  19. package/dist/lib/browser/types.mjs +12 -6
  20. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +1765 -0
  21. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-5XPK2V4A.cjs → chunk-5KKJ4NPP.cjs} +678 -418
  23. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +7 -0
  24. package/dist/lib/node/chunk-BJ6ZD7MN.cjs +51 -0
  25. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +7 -0
  26. package/dist/lib/node/chunk-CN3RPESU.cjs +202 -0
  27. package/dist/lib/node/chunk-CN3RPESU.cjs.map +7 -0
  28. package/dist/lib/node/{chunk-NZARD7UP.cjs → chunk-DSYKOI4E.cjs} +51 -40
  29. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +7 -0
  30. package/dist/lib/node/chunk-PYXHNAAK.cjs +40 -0
  31. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +7 -0
  32. package/dist/lib/node/index.cjs +69 -105
  33. package/dist/lib/node/index.cjs.map +3 -3
  34. package/dist/lib/node/meta.cjs +3 -3
  35. package/dist/lib/node/meta.cjs.map +1 -1
  36. package/dist/lib/node/meta.json +1 -1
  37. package/dist/lib/node/testing.cjs +111 -0
  38. package/dist/lib/node/testing.cjs.map +7 -0
  39. package/dist/lib/node/types.cjs +15 -9
  40. package/dist/lib/node/types.cjs.map +2 -2
  41. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  42. package/dist/types/src/components/CellEditor/CellEditor.d.ts +14 -0
  43. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -0
  44. package/dist/types/src/components/{GridSheet/SheetCellEditor.stories.d.ts → CellEditor/CellEditor.stories.d.ts} +4 -4
  45. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -0
  46. package/dist/types/src/{extensions/editor → components/CellEditor}/extension.d.ts +1 -1
  47. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -0
  48. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +1 -0
  49. package/dist/types/src/components/CellEditor/index.d.ts +3 -0
  50. package/dist/types/src/components/CellEditor/index.d.ts.map +1 -0
  51. package/dist/types/src/{graph/functions → components/ComputeGraph}/async-function.d.ts +5 -14
  52. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
  53. package/dist/types/src/components/ComputeGraph/custom.d.ts +21 -0
  54. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -0
  55. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +20 -0
  56. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -0
  57. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +12 -0
  58. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +1 -0
  59. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +2 -0
  60. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +1 -0
  61. package/dist/types/src/components/ComputeGraph/graph.d.ts +26 -0
  62. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +1 -0
  63. package/dist/types/src/components/ComputeGraph/index.d.ts +3 -1
  64. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  65. package/dist/types/src/components/Sheet/Sheet.d.ts +55 -0
  66. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
  67. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +54 -0
  68. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -0
  69. package/dist/types/src/components/Sheet/formatting.d.ts +14 -0
  70. package/dist/types/src/components/Sheet/formatting.d.ts.map +1 -0
  71. package/dist/types/src/components/Sheet/grid.d.ts +52 -0
  72. package/dist/types/src/components/Sheet/grid.d.ts.map +1 -0
  73. package/dist/types/src/components/Sheet/index.d.ts +2 -0
  74. package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
  75. package/dist/types/src/components/Sheet/nav.d.ts +29 -0
  76. package/dist/types/src/components/Sheet/nav.d.ts.map +1 -0
  77. package/dist/types/src/components/Sheet/sheet-context.d.ts +25 -0
  78. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -0
  79. package/dist/types/src/components/Sheet/util.d.ts +18 -0
  80. package/dist/types/src/components/Sheet/util.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContainer.d.ts +9 -0
  82. package/dist/types/src/components/SheetContainer.d.ts.map +1 -0
  83. package/dist/types/src/components/Toolbar/Toolbar.d.ts +9 -33
  84. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  85. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +15 -19
  86. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  87. package/dist/types/src/components/Toolbar/common.d.ts +20 -0
  88. package/dist/types/src/components/Toolbar/common.d.ts.map +1 -0
  89. package/dist/types/src/components/index.d.ts +2 -3
  90. package/dist/types/src/components/index.d.ts.map +1 -1
  91. package/dist/types/src/meta.d.ts +9 -3
  92. package/dist/types/src/meta.d.ts.map +1 -1
  93. package/dist/types/src/{graph/functions/function-defs.d.ts → model/functions.d.ts} +1 -1
  94. package/dist/types/src/model/functions.d.ts.map +1 -0
  95. package/dist/types/src/model/index.d.ts +3 -2
  96. package/dist/types/src/model/index.d.ts.map +1 -1
  97. package/dist/types/src/model/model.browser.test.d.ts +2 -0
  98. package/dist/types/src/model/model.browser.test.d.ts.map +1 -0
  99. package/dist/types/src/model/{sheet-model.d.ts → model.d.ts} +67 -13
  100. package/dist/types/src/model/model.d.ts.map +1 -0
  101. package/dist/types/src/{defs → model}/types.d.ts +3 -8
  102. package/dist/types/src/model/types.d.ts.map +1 -0
  103. package/dist/types/src/model/types.test.d.ts.map +1 -0
  104. package/dist/types/src/model/util.d.ts +15 -0
  105. package/dist/types/src/model/util.d.ts.map +1 -0
  106. package/dist/types/src/testing.d.ts +9 -0
  107. package/dist/types/src/testing.d.ts.map +1 -0
  108. package/dist/types/src/translations.d.ts +12 -17
  109. package/dist/types/src/translations.d.ts.map +1 -1
  110. package/dist/types/src/types.d.ts +40 -125
  111. package/dist/types/src/types.d.ts.map +1 -1
  112. package/package.json +52 -58
  113. package/src/SheetPlugin.tsx +74 -52
  114. package/src/components/{GridSheet/SheetCellEditor.stories.tsx → CellEditor/CellEditor.stories.tsx} +8 -8
  115. package/src/components/CellEditor/CellEditor.tsx +113 -0
  116. package/src/{extensions/editor → components/CellEditor}/extension.test.ts +6 -4
  117. package/src/{extensions/editor → components/CellEditor}/extension.ts +6 -5
  118. package/src/{extensions/editor → components/CellEditor}/index.ts +1 -0
  119. package/src/{graph/functions → components/ComputeGraph}/async-function.ts +15 -25
  120. package/src/{graph/testing/test-plugin.ts → components/ComputeGraph/custom.ts} +14 -44
  121. package/src/{graph/functions → components/ComputeGraph}/edge-function.ts +14 -16
  122. package/src/components/ComputeGraph/graph-context.tsx +50 -0
  123. package/src/components/ComputeGraph/graph.browser.test.ts +50 -0
  124. package/src/components/ComputeGraph/graph.ts +62 -0
  125. package/src/components/ComputeGraph/index.ts +3 -1
  126. package/src/components/Sheet/Sheet.stories.tsx +287 -0
  127. package/src/components/Sheet/Sheet.tsx +1160 -0
  128. package/src/components/Sheet/formatting.ts +106 -0
  129. package/src/components/Sheet/grid.ts +191 -0
  130. package/src/{testing → components/Sheet}/index.ts +1 -1
  131. package/src/components/Sheet/nav.ts +157 -0
  132. package/src/components/Sheet/sheet-context.tsx +150 -0
  133. package/src/components/Sheet/util.ts +56 -0
  134. package/src/components/SheetContainer.tsx +34 -0
  135. package/src/components/Toolbar/Toolbar.tsx +112 -242
  136. package/src/components/Toolbar/common.tsx +72 -0
  137. package/src/components/index.ts +0 -2
  138. package/src/meta.tsx +18 -0
  139. package/src/model/index.ts +3 -2
  140. package/src/model/model.browser.test.ts +100 -0
  141. package/src/model/model.ts +550 -0
  142. package/src/{defs → model}/types.test.ts +9 -8
  143. package/src/{defs → model}/types.ts +14 -24
  144. package/src/model/util.ts +36 -0
  145. package/src/testing.ts +50 -0
  146. package/src/translations.ts +1 -6
  147. package/src/types.ts +47 -40
  148. package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs +0 -290
  149. package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs.map +0 -7
  150. package/dist/lib/browser/chunk-BWN5DZWZ.mjs +0 -74
  151. package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +0 -7
  152. package/dist/lib/browser/chunk-D3QTX46O.mjs +0 -14
  153. package/dist/lib/browser/chunk-D3QTX46O.mjs.map +0 -7
  154. package/dist/lib/browser/chunk-GSV5QNLD.mjs +0 -2966
  155. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +0 -7
  156. package/dist/lib/browser/chunk-HOG37RYS.mjs +0 -1528
  157. package/dist/lib/browser/chunk-HOG37RYS.mjs.map +0 -7
  158. package/dist/lib/browser/graph-M4IQ76QX.mjs +0 -33
  159. package/dist/lib/browser/graph-M4IQ76QX.mjs.map +0 -7
  160. package/dist/lib/node/SheetContainer-J7XROAMN.cjs +0 -300
  161. package/dist/lib/node/SheetContainer-J7XROAMN.cjs.map +0 -7
  162. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +0 -7
  163. package/dist/lib/node/chunk-AXQZA2YS.cjs +0 -1527
  164. package/dist/lib/node/chunk-AXQZA2YS.cjs.map +0 -7
  165. package/dist/lib/node/chunk-NZARD7UP.cjs.map +0 -7
  166. package/dist/lib/node/chunk-QIFIGEKV.cjs +0 -37
  167. package/dist/lib/node/chunk-QIFIGEKV.cjs.map +0 -7
  168. package/dist/lib/node/graph-Q3N2X26H.cjs +0 -55
  169. package/dist/lib/node/graph-Q3N2X26H.cjs.map +0 -7
  170. package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs +0 -291
  171. package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs.map +0 -7
  172. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +0 -7
  173. package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs +0 -1529
  174. package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs.map +0 -7
  175. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +0 -16
  176. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +0 -7
  177. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs +0 -75
  178. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +0 -7
  179. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +0 -34
  180. package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +0 -7
  181. package/dist/lib/node-esm/index.mjs +0 -280
  182. package/dist/lib/node-esm/index.mjs.map +0 -7
  183. package/dist/lib/node-esm/meta.json +0 -1
  184. package/dist/lib/node-esm/meta.mjs +0 -10
  185. package/dist/lib/node-esm/meta.mjs.map +0 -7
  186. package/dist/lib/node-esm/types.mjs +0 -17
  187. package/dist/lib/node-esm/types.mjs.map +0 -7
  188. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +0 -11
  189. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +0 -1
  190. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +0 -3
  191. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +0 -1
  192. package/dist/types/src/components/FunctionEditor/index.d.ts +0 -2
  193. package/dist/types/src/components/FunctionEditor/index.d.ts.map +0 -1
  194. package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -3
  195. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
  196. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +0 -9
  197. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
  198. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +0 -1
  199. package/dist/types/src/components/GridSheet/index.d.ts +0 -2
  200. package/dist/types/src/components/GridSheet/index.d.ts.map +0 -1
  201. package/dist/types/src/components/GridSheet/util.d.ts +0 -16
  202. package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
  203. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +0 -6
  204. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +0 -1
  205. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +0 -11
  206. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +0 -1
  207. package/dist/types/src/components/SheetContainer/index.d.ts +0 -3
  208. package/dist/types/src/components/SheetContainer/index.d.ts.map +0 -1
  209. package/dist/types/src/components/SheetContext/SheetContext.d.ts +0 -26
  210. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +0 -1
  211. package/dist/types/src/components/SheetContext/index.d.ts +0 -2
  212. package/dist/types/src/components/SheetContext/index.d.ts.map +0 -1
  213. package/dist/types/src/defs/index.d.ts +0 -4
  214. package/dist/types/src/defs/index.d.ts.map +0 -1
  215. package/dist/types/src/defs/sheet-range-types.d.ts +0 -13
  216. package/dist/types/src/defs/sheet-range-types.d.ts.map +0 -1
  217. package/dist/types/src/defs/types.d.ts.map +0 -1
  218. package/dist/types/src/defs/types.test.d.ts.map +0 -1
  219. package/dist/types/src/defs/util.d.ts +0 -43
  220. package/dist/types/src/defs/util.d.ts.map +0 -1
  221. package/dist/types/src/extensions/compute.d.ts +0 -6
  222. package/dist/types/src/extensions/compute.d.ts.map +0 -1
  223. package/dist/types/src/extensions/compute.stories.d.ts +0 -26
  224. package/dist/types/src/extensions/compute.stories.d.ts.map +0 -1
  225. package/dist/types/src/extensions/editor/extension.d.ts.map +0 -1
  226. package/dist/types/src/extensions/editor/extension.test.d.ts.map +0 -1
  227. package/dist/types/src/extensions/editor/index.d.ts +0 -2
  228. package/dist/types/src/extensions/editor/index.d.ts.map +0 -1
  229. package/dist/types/src/extensions/index.d.ts +0 -3
  230. package/dist/types/src/extensions/index.d.ts.map +0 -1
  231. package/dist/types/src/graph/compute-graph-registry.d.ts +0 -34
  232. package/dist/types/src/graph/compute-graph-registry.d.ts.map +0 -1
  233. package/dist/types/src/graph/compute-graph.d.ts +0 -64
  234. package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
  235. package/dist/types/src/graph/compute-graph.stories.d.ts +0 -10
  236. package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
  237. package/dist/types/src/graph/compute-graph.test.d.ts +0 -2
  238. package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
  239. package/dist/types/src/graph/compute-node.d.ts +0 -26
  240. package/dist/types/src/graph/compute-node.d.ts.map +0 -1
  241. package/dist/types/src/graph/functions/async-function.d.ts.map +0 -1
  242. package/dist/types/src/graph/functions/edge-function.d.ts +0 -21
  243. package/dist/types/src/graph/functions/edge-function.d.ts.map +0 -1
  244. package/dist/types/src/graph/functions/function-defs.d.ts.map +0 -1
  245. package/dist/types/src/graph/functions/index.d.ts +0 -4
  246. package/dist/types/src/graph/functions/index.d.ts.map +0 -1
  247. package/dist/types/src/graph/hyperformula.test.d.ts +0 -2
  248. package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
  249. package/dist/types/src/graph/index.d.ts +0 -5
  250. package/dist/types/src/graph/index.d.ts.map +0 -1
  251. package/dist/types/src/graph/testing/index.d.ts +0 -3
  252. package/dist/types/src/graph/testing/index.d.ts.map +0 -1
  253. package/dist/types/src/graph/testing/test-builder.d.ts +0 -15
  254. package/dist/types/src/graph/testing/test-builder.d.ts.map +0 -1
  255. package/dist/types/src/graph/testing/test-plugin.d.ts +0 -36
  256. package/dist/types/src/graph/testing/test-plugin.d.ts.map +0 -1
  257. package/dist/types/src/graph/util.d.ts +0 -2
  258. package/dist/types/src/graph/util.d.ts.map +0 -1
  259. package/dist/types/src/hooks/hooks.stories.d.ts +0 -11
  260. package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
  261. package/dist/types/src/hooks/index.d.ts +0 -4
  262. package/dist/types/src/hooks/index.d.ts.map +0 -1
  263. package/dist/types/src/hooks/threads.d.ts +0 -8
  264. package/dist/types/src/hooks/threads.d.ts.map +0 -1
  265. package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
  266. package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
  267. package/dist/types/src/hooks/useSheetModel.d.ts +0 -8
  268. package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
  269. package/dist/types/src/model/decorations.d.ts +0 -25
  270. package/dist/types/src/model/decorations.d.ts.map +0 -1
  271. package/dist/types/src/model/sheet-model.d.ts.map +0 -1
  272. package/dist/types/src/model/sheet-model.test.d.ts +0 -2
  273. package/dist/types/src/model/sheet-model.test.d.ts.map +0 -1
  274. package/dist/types/src/sanity.test.d.ts +0 -2
  275. package/dist/types/src/sanity.test.d.ts.map +0 -1
  276. package/dist/types/src/testing/index.d.ts +0 -2
  277. package/dist/types/src/testing/index.d.ts.map +0 -1
  278. package/dist/types/src/testing/testing.d.ts +0 -8
  279. package/dist/types/src/testing/testing.d.ts.map +0 -1
  280. package/dist/vendor/hyperformula.mjs +0 -37145
  281. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +0 -20
  282. package/src/components/FunctionEditor/FunctionEditor.tsx +0 -45
  283. package/src/components/FunctionEditor/index.ts +0 -5
  284. package/src/components/GridSheet/GridSheet.stories.tsx +0 -41
  285. package/src/components/GridSheet/GridSheet.tsx +0 -163
  286. package/src/components/GridSheet/index.ts +0 -5
  287. package/src/components/GridSheet/util.ts +0 -158
  288. package/src/components/SheetContainer/SheetContainer.stories.tsx +0 -40
  289. package/src/components/SheetContainer/SheetContainer.tsx +0 -27
  290. package/src/components/SheetContainer/index.ts +0 -7
  291. package/src/components/SheetContext/SheetContext.tsx +0 -104
  292. package/src/components/SheetContext/index.ts +0 -5
  293. package/src/defs/index.ts +0 -7
  294. package/src/defs/sheet-range-types.ts +0 -46
  295. package/src/defs/util.ts +0 -151
  296. package/src/extensions/compute.stories.tsx +0 -151
  297. package/src/extensions/compute.ts +0 -147
  298. package/src/extensions/index.ts +0 -6
  299. package/src/graph/compute-graph-registry.ts +0 -90
  300. package/src/graph/compute-graph.stories.tsx +0 -93
  301. package/src/graph/compute-graph.test.ts +0 -87
  302. package/src/graph/compute-graph.ts +0 -242
  303. package/src/graph/compute-node.ts +0 -63
  304. package/src/graph/functions/index.ts +0 -7
  305. package/src/graph/hyperformula.test.ts +0 -14
  306. package/src/graph/index.ts +0 -8
  307. package/src/graph/testing/index.ts +0 -6
  308. package/src/graph/testing/test-builder.ts +0 -54
  309. package/src/graph/util.ts +0 -8
  310. package/src/hooks/hooks.stories.tsx +0 -50
  311. package/src/hooks/index.ts +0 -7
  312. package/src/hooks/threads.ts +0 -147
  313. package/src/hooks/useComputeGraph.ts +0 -28
  314. package/src/hooks/useSheetModel.ts +0 -40
  315. package/src/meta.ts +0 -14
  316. package/src/model/decorations.ts +0 -64
  317. package/src/model/sheet-model.test.ts +0 -57
  318. package/src/model/sheet-model.ts +0 -418
  319. package/src/sanity.test.ts +0 -40
  320. package/src/testing/testing.tsx +0 -68
  321. /package/dist/types/src/{extensions/editor → components/CellEditor}/extension.test.d.ts +0 -0
  322. /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
  323. /package/src/{graph/functions/function-defs.ts → model/functions.ts} +0 -0
@@ -2,265 +2,167 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import {
6
+ type Icon,
7
+ Calendar,
8
+ ChatText,
9
+ CurrencyDollar,
10
+ Eraser,
11
+ HighlighterCircle,
12
+ TextAlignCenter,
13
+ TextAlignLeft,
14
+ TextAlignRight,
15
+ } from '@phosphor-icons/react';
5
16
  import { createContext } from '@radix-ui/react-context';
6
- import React, { type PropsWithChildren, useCallback, useMemo } from 'react';
17
+ import React, { type PropsWithChildren } from 'react';
7
18
 
8
- import { useIntentDispatcher } from '@dxos/app-framework';
9
19
  import {
10
- Icon,
20
+ DensityProvider,
21
+ ElevationProvider,
11
22
  Toolbar as NaturalToolbar,
12
- useTranslation,
13
- Tooltip,
14
- type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
15
- type ToolbarButtonProps as NaturalToolbarButtonProps,
16
- type ToolbarToggleProps as NaturalToolbarToggleProps,
17
23
  type ThemedClassName,
24
+ useTranslation,
18
25
  } from '@dxos/react-ui';
19
- import { useAttention } from '@dxos/react-ui-attention';
20
- import { nonNullable } from '@dxos/util';
21
26
 
22
- import {
23
- addressToIndex,
24
- type AlignKey,
25
- type AlignValue,
26
- type CommentKey,
27
- type CommentValue,
28
- inRange,
29
- type StyleKey,
30
- type StyleValue,
31
- } from '../../defs';
27
+ import { ToolbarButton, ToolbarSeparator, ToolbarToggleButton } from './common';
32
28
  import { SHEET_PLUGIN } from '../../meta';
33
- import { type SheetType } from '../../types';
34
- import { useSheetContext } from '../SheetContext';
35
-
36
- //
37
- // Buttons
38
- //
39
-
40
- const buttonStyles = 'min-bs-0 p-2';
41
- const tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };
42
-
43
- const ToolbarSeparator = () => <div role='separator' className='grow' />;
44
-
45
- //
46
- // ToolbarItem
47
- //
48
-
49
- type ToolbarItemProps =
50
- | (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })
51
- | (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })
52
- | (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });
53
-
54
- export const ToolbarItem = ({ itemType, icon, children, ...props }: ToolbarItemProps) => {
55
- const Invoker =
56
- itemType === 'toggleGroupItem'
57
- ? NaturalToolbar.ToggleGroupItem
58
- : itemType === 'toggle'
59
- ? NaturalToolbar.Toggle
60
- : NaturalToolbar.Button;
61
- return (
62
- <Tooltip.Root>
63
- <Tooltip.Trigger asChild>
64
- {/* TODO(thure): type the props spread better. */}
65
- <Invoker variant='ghost' {...(props as any)} classNames={buttonStyles}>
66
- <Icon icon={icon} size={5} />
67
- <span className='sr-only'>{children}</span>
68
- </Invoker>
69
- </Tooltip.Trigger>
70
- <Tooltip.Portal>
71
- <Tooltip.Content {...tooltipProps}>
72
- {children}
73
- <Tooltip.Arrow />
74
- </Tooltip.Content>
75
- </Tooltip.Portal>
76
- </Tooltip.Root>
77
- );
78
- };
29
+ import { type Formatting } from '../../types';
79
30
 
80
31
  //
81
32
  // Root
82
33
  //
83
34
 
84
- type AlignAction = { key: AlignKey; value: AlignValue };
85
- type CommentAction = { key: CommentKey; value: CommentValue; cellContent?: string };
86
- type StyleAction = { key: StyleKey; value: StyleValue };
87
-
88
- export type ToolbarAction = StyleAction | AlignAction | CommentAction;
35
+ export type ToolbarActionType = 'clear' | 'highlight' | 'left' | 'center' | 'right' | 'date' | 'currency';
89
36
 
90
- export type ToolbarActionType = ToolbarAction['key'];
37
+ export type ToolbarAction = {
38
+ type: ToolbarActionType;
39
+ };
91
40
 
92
- export type ToolbarActionHandler = (action: ToolbarAction) => void;
41
+ export type ToolbarActionHandler = ({ type }: ToolbarAction) => void;
93
42
 
94
43
  export type ToolbarProps = ThemedClassName<
95
44
  PropsWithChildren<{
96
- role?: string;
45
+ onAction?: ToolbarActionHandler;
97
46
  }>
98
47
  >;
99
48
 
100
- const [ToolbarContextProvider, useToolbarContext] = createContext<{ onAction: (action: ToolbarAction) => void }>(
101
- 'Toolbar',
102
- );
103
-
104
- // TODO(Zan): Factor out, copied this from MarkdownPlugin.
105
- const sectionToolbarLayout =
106
- 'bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity';
107
-
108
- type Range = SheetType['ranges'][number];
109
-
110
- const ToolbarRoot = ({ children, role, classNames }: ToolbarProps) => {
111
- const { id, model, range, cursor } = useSheetContext();
112
- const { hasAttention } = useAttention(id);
113
- const dispatch = useIntentDispatcher();
114
-
115
- // TODO(Zan): Centralise the toolbar action handler. Current implementation in stories.
116
- const handleAction = useCallback(
117
- (action: ToolbarAction) => {
118
- switch (action.key) {
119
- case 'align':
120
- if (cursor) {
121
- const index = model.sheet.ranges?.findIndex(
122
- (range) => range.key === action.key && inRange(range.range, cursor),
123
- );
124
- const nextRange = range ? { from: range.from, to: range.to ?? range.from } : { from: cursor, to: cursor };
125
- const nextRangeEntity = {
126
- range: nextRange as Range['range'],
127
- key: action.key,
128
- value: action.value,
129
- };
130
- if (index < 0) {
131
- model.sheet.ranges?.push(nextRangeEntity);
132
- } else {
133
- model.sheet.ranges?.splice(index, 1, nextRangeEntity);
134
- }
135
- }
136
- break;
137
- case 'style':
138
- if (action.value === 'unset') {
139
- const index = model.sheet.ranges?.findIndex((range) => range.key === action.key);
140
- if (index >= 0) {
141
- model.sheet.ranges?.splice(index, 1);
142
- }
143
- } else if (range || cursor) {
144
- const nextRange = range ? { from: range.from, to: range.to ?? range.from } : { from: cursor, to: cursor };
145
- model.sheet.ranges?.push({
146
- range: nextRange as Range['range'],
147
- key: action.key,
148
- value: action.value,
149
- });
150
- }
151
- break;
152
- case 'comment': {
153
- // TODO(Zan): We shouldn't hardcode the action ID.
154
- void dispatch({
155
- action: 'dxos.org/plugin/thread/action/create',
156
- data: {
157
- cursor: action.value,
158
- name: action.cellContent,
159
- subject: model.sheet,
160
- },
161
- });
162
- }
163
- }
164
- },
165
- [model.sheet, range, cursor, dispatch],
166
- );
49
+ const [ToolbarContextProvider, useToolbarContext] = createContext<ToolbarProps>('Toolbar');
167
50
 
51
+ const ToolbarRoot = ({ children, onAction, classNames }: ToolbarProps) => {
168
52
  return (
169
- <ToolbarContextProvider onAction={handleAction}>
170
- <NaturalToolbar.Root
171
- classNames={[
172
- ...(role === 'section'
173
- ? ['z-[2] group-focus-within/section:visible', !hasAttention && 'invisible', sectionToolbarLayout]
174
- : ['attention-surface']),
175
- classNames,
176
- ]}
177
- >
178
- {children}
179
- </NaturalToolbar.Root>
53
+ <ToolbarContextProvider onAction={onAction}>
54
+ <DensityProvider density='fine'>
55
+ <ElevationProvider elevation='chrome'>
56
+ <NaturalToolbar.Root classNames={['is-full shrink-0 overflow-x-auto overflow-y-hidden p-1', classNames]}>
57
+ {children}
58
+ </NaturalToolbar.Root>
59
+ </ElevationProvider>
60
+ </DensityProvider>
180
61
  </ToolbarContextProvider>
181
62
  );
182
63
  };
183
64
 
184
65
  // TODO(burdon): Generalize.
185
66
  // TODO(burdon): Detect and display current state.
186
- type ButtonProps<T> = {
187
- value: T;
188
- icon: string;
189
- disabled?: (state: Range) => boolean;
67
+ type ButtonProps = {
68
+ type: ToolbarActionType;
69
+ Icon: Icon;
70
+ getState: (state: Formatting) => boolean;
71
+ disabled?: (state: Formatting) => boolean;
190
72
  };
191
73
 
192
74
  //
193
75
  // Alignment
194
76
  //
195
77
 
196
- const alignmentOptions: ButtonProps<AlignValue>[] = [
197
- { value: 'start', icon: 'ph--text-align-left--regular' },
198
- { value: 'center', icon: 'ph--text-align-center--regular' },
199
- { value: 'end', icon: 'ph--text-align-right--regular' },
78
+ const formatOptions: ButtonProps[] = [
79
+ { type: 'date', Icon: Calendar, getState: (state) => false },
80
+ { type: 'currency', Icon: CurrencyDollar, getState: (state) => false },
200
81
  ];
201
82
 
202
- const Alignment = () => {
203
- const { cursor, model } = useSheetContext();
204
- const { onAction } = useToolbarContext('Alignment');
83
+ const Format = () => {
84
+ const { onAction } = useToolbarContext('Format');
205
85
  const { t } = useTranslation(SHEET_PLUGIN);
206
86
 
207
- const value = useMemo(
208
- () =>
209
- cursor
210
- ? model.sheet.ranges?.find(({ range, key }) => key === 'alignment' && inRange(range, cursor))?.value
211
- : undefined,
212
- [cursor, model.sheet.ranges],
87
+ return (
88
+ <NaturalToolbar.ToggleGroup
89
+ type='single'
90
+ // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
91
+ >
92
+ {formatOptions.map(({ type, getState, Icon }) => (
93
+ <ToolbarToggleButton
94
+ key={type}
95
+ value={type}
96
+ Icon={Icon}
97
+ // disabled={state?.blockType === 'codeblock'}
98
+ // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
99
+ onClick={() => onAction?.({ type })}
100
+ >
101
+ {t(`toolbar ${type} label`)}
102
+ </ToolbarToggleButton>
103
+ ))}
104
+ </NaturalToolbar.ToggleGroup>
213
105
  );
106
+ };
107
+
108
+ const alignmentOptions: ButtonProps[] = [
109
+ { type: 'left', Icon: TextAlignLeft, getState: (state) => false },
110
+ { type: 'center', Icon: TextAlignCenter, getState: (state) => false },
111
+ { type: 'right', Icon: TextAlignRight, getState: (state) => false },
112
+ ];
113
+
114
+ const Alignment = () => {
115
+ const { onAction } = useToolbarContext('Alignment');
116
+ const { t } = useTranslation(SHEET_PLUGIN);
214
117
 
215
118
  return (
216
119
  <NaturalToolbar.ToggleGroup
217
120
  type='single'
218
- value={value}
219
- onValueChange={(value: AlignValue) => onAction?.({ key: 'align', value })}
121
+ // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
220
122
  >
221
- {alignmentOptions.map(({ value, icon }) => (
222
- <ToolbarItem itemType='toggleGroupItem' key={value} value={value} icon={icon}>
223
- {t(`toolbar ${value} label`)}
224
- </ToolbarItem>
123
+ {alignmentOptions.map(({ type, getState, Icon }) => (
124
+ <ToolbarToggleButton
125
+ key={type}
126
+ value={type}
127
+ Icon={Icon}
128
+ // disabled={state?.blockType === 'codeblock'}
129
+ // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
130
+ onClick={() => onAction?.({ type })}
131
+ >
132
+ {t(`toolbar ${type} label`)}
133
+ </ToolbarToggleButton>
225
134
  ))}
226
135
  </NaturalToolbar.ToggleGroup>
227
136
  );
228
137
  };
229
138
 
230
- const styleOptions: ButtonProps<StyleValue>[] = [{ value: 'highlight', icon: 'ph--highlighter--regular' }];
139
+ const styleOptions: ButtonProps[] = [
140
+ { type: 'clear', Icon: Eraser, getState: (state) => false },
141
+ { type: 'highlight', Icon: HighlighterCircle, getState: (state) => false },
142
+ ];
231
143
 
232
144
  const Styles = () => {
233
- const { cursor, model } = useSheetContext();
234
- const { onAction } = useToolbarContext('Styles');
145
+ const { onAction } = useToolbarContext('Alignment');
235
146
  const { t } = useTranslation(SHEET_PLUGIN);
236
147
 
237
- const activeValues = useMemo(
238
- () =>
239
- cursor
240
- ? model.sheet.ranges
241
- ?.filter(({ range, key }) => key === 'style' && inRange(range, cursor))
242
- .reduce((acc, { value }) => {
243
- acc.add(value);
244
- return acc;
245
- }, new Set())
246
- : undefined,
247
- [cursor, model.sheet.ranges],
248
- );
249
-
250
148
  return (
251
- <>
252
- {styleOptions.map(({ value, icon }) => (
253
- <ToolbarItem
254
- itemType='toggle'
255
- key={value}
256
- pressed={activeValues?.has(value)}
257
- onPressedChange={(nextPressed: boolean) => onAction?.({ key: 'style', value: nextPressed ? value : 'unset' })}
258
- icon={icon}
149
+ <NaturalToolbar.ToggleGroup
150
+ type='single'
151
+ // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
152
+ >
153
+ {styleOptions.map(({ type, getState, Icon }) => (
154
+ <ToolbarToggleButton
155
+ key={type}
156
+ value={type}
157
+ Icon={Icon}
158
+ // disabled={state?.blockType === 'codeblock'}
159
+ // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
160
+ onClick={() => onAction?.({ type })}
259
161
  >
260
- {t(`toolbar ${value} label`)}
261
- </ToolbarItem>
162
+ {t(`toolbar ${type} label`)}
163
+ </ToolbarToggleButton>
262
164
  ))}
263
- </>
165
+ </NaturalToolbar.ToggleGroup>
264
166
  );
265
167
  };
266
168
 
@@ -269,51 +171,18 @@ const Styles = () => {
269
171
  //
270
172
 
271
173
  const Actions = () => {
272
- const { onAction } = useToolbarContext('Actions');
273
- const { cursor, range, model } = useSheetContext();
174
+ // const { onAction } = useToolbarContext('Actions');
274
175
  const { t } = useTranslation(SHEET_PLUGIN);
275
-
276
- const overlapsCommentAnchor = (model.sheet.threads ?? [])
277
- .filter(nonNullable)
278
- .filter((thread) => thread.status !== 'resolved')
279
- .some((thread) => {
280
- if (!cursor) {
281
- return false;
282
- }
283
- return addressToIndex(model.sheet, cursor) === thread.anchor;
284
- });
285
-
286
- const hasCursor = !!cursor;
287
- const cursorOnly = hasCursor && !range && !overlapsCommentAnchor;
288
-
289
- const tooltipLabelKey = !hasCursor
290
- ? 'no cursor label'
291
- : overlapsCommentAnchor
292
- ? 'selection overlaps existing comment label'
293
- : range
294
- ? 'comment ranges not supported label'
295
- : 'comment label';
296
-
297
176
  return (
298
- <ToolbarItem
299
- itemType='button'
177
+ <ToolbarButton
300
178
  value='comment'
301
- icon='ph--chat-text--regular'
179
+ Icon={ChatText}
302
180
  data-testid='editor.toolbar.comment'
303
- onClick={() => {
304
- if (!cursor) {
305
- return;
306
- }
307
- return onAction?.({
308
- key: 'comment',
309
- value: addressToIndex(model.sheet, cursor),
310
- cellContent: model.getCellText(cursor),
311
- });
312
- }}
313
- disabled={!cursorOnly || overlapsCommentAnchor}
181
+ // onClick={() => onAction?.({ type: 'comment' })}
182
+ // disabled={!state || state.comment || !state.selection}
314
183
  >
315
- {t(tooltipLabelKey)}
316
- </ToolbarItem>
184
+ {t('comment label')}
185
+ </ToolbarButton>
317
186
  );
318
187
  };
319
188
 
@@ -321,6 +190,7 @@ export const Toolbar = {
321
190
  Root: ToolbarRoot,
322
191
  Separator: ToolbarSeparator,
323
192
  Alignment,
193
+ Format,
324
194
  Styles,
325
195
  Actions,
326
196
  };
@@ -0,0 +1,72 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type Icon } from '@phosphor-icons/react';
6
+ import React from 'react';
7
+
8
+ import {
9
+ Toolbar as NaturalToolbar,
10
+ Tooltip,
11
+ type ToolbarButtonProps as NaturalToolbarButtonProps,
12
+ type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
13
+ } from '@dxos/react-ui';
14
+ import { getSize } from '@dxos/react-ui-theme';
15
+
16
+ // TODO(burdon): Factor out in common with react-ui-editor.
17
+
18
+ export const iconStyles = getSize(5);
19
+ export const buttonStyles = 'min-bs-0 p-2';
20
+ export const tooltipProps = { side: 'top' as const, classNames: 'z-10' };
21
+
22
+ export const ToolbarSeparator = () => <div role='separator' className='grow' />;
23
+
24
+ //
25
+ // ToolbarButton
26
+ //
27
+
28
+ type ToolbarButtonProps = NaturalToolbarButtonProps & { Icon: Icon };
29
+
30
+ export const ToolbarButton = ({ Icon, children, ...props }: ToolbarButtonProps) => {
31
+ return (
32
+ <Tooltip.Root>
33
+ <Tooltip.Trigger asChild>
34
+ <NaturalToolbar.Button variant='ghost' {...props} classNames={buttonStyles}>
35
+ <Icon className={iconStyles} />
36
+ <span className='sr-only'>{children}</span>
37
+ </NaturalToolbar.Button>
38
+ </Tooltip.Trigger>
39
+ <Tooltip.Portal>
40
+ <Tooltip.Content {...tooltipProps}>
41
+ {children}
42
+ <Tooltip.Arrow />
43
+ </Tooltip.Content>
44
+ </Tooltip.Portal>
45
+ </Tooltip.Root>
46
+ );
47
+ };
48
+
49
+ //
50
+ // ToolbarToggleButton
51
+ //
52
+
53
+ export type ToolbarToggleButtonProps = NaturalToolbarToggleGroupItemProps & { Icon: Icon };
54
+
55
+ export const ToolbarToggleButton = ({ Icon, children, ...props }: ToolbarToggleButtonProps) => {
56
+ return (
57
+ <Tooltip.Root>
58
+ <Tooltip.Trigger asChild>
59
+ <NaturalToolbar.ToggleGroupItem variant='ghost' {...props} classNames={buttonStyles}>
60
+ <Icon className={iconStyles} />
61
+ <span className='sr-only'>{children}</span>
62
+ </NaturalToolbar.ToggleGroupItem>
63
+ </Tooltip.Trigger>
64
+ <Tooltip.Portal>
65
+ <Tooltip.Content {...tooltipProps}>
66
+ {children}
67
+ <Tooltip.Arrow />
68
+ </Tooltip.Content>
69
+ </Tooltip.Portal>
70
+ </Tooltip.Root>
71
+ );
72
+ };
@@ -5,8 +5,6 @@
5
5
  import React from 'react';
6
6
 
7
7
  export * from './ComputeGraph';
8
- export * from './GridSheet';
9
- export * from './SheetContext';
10
8
 
11
9
  // Lazily load components for content surfaces.
12
10
  export const SheetContainer = React.lazy(() => import('./SheetContainer'));
package/src/meta.tsx ADDED
@@ -0,0 +1,18 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import { GridNine, type IconProps } from '@phosphor-icons/react';
6
+ import React from 'react';
7
+
8
+ import { pluginMeta } from '@dxos/app-framework';
9
+
10
+ export const SHEET_PLUGIN = 'dxos.org/plugin/sheet';
11
+
12
+ export default pluginMeta({
13
+ id: SHEET_PLUGIN,
14
+ name: 'Sheet',
15
+ description: 'A simple spreadsheet plugin.',
16
+ iconComponent: (props: IconProps) => <GridNine {...props} />,
17
+ iconSymbol: 'ph--grid-nine--regular',
18
+ });
@@ -2,5 +2,6 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './decorations';
6
- export * from './sheet-model';
5
+ export * from './functions';
6
+ export * from './model';
7
+ export * from './types';
@@ -0,0 +1,100 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { expect } from 'chai';
6
+ import { describe, test } from 'vitest';
7
+
8
+ import { SheetModel } from './model';
9
+ import { addressFromA1Notation, rangeFromA1Notation } from './types';
10
+ import { createComputeGraph } from '../components';
11
+ import { createSheet, ValueTypeEnum } from '../types';
12
+
13
+ // TODO(burdon): Test undo (e.g., clear cells).
14
+
15
+ /**
16
+ * VITEST_ENV=chrome p vitest --watch
17
+ * NOTE: Browser test required for hyperformula due to raw translation files.
18
+ */
19
+ describe('model', () => {
20
+ const createModel = async () => {
21
+ const graph = createComputeGraph();
22
+ const sheet = createSheet();
23
+ const model = new SheetModel(graph, sheet, undefined, { rows: 5, columns: 5 });
24
+ await model.initialize();
25
+ return model;
26
+ };
27
+
28
+ test('create', async () => {
29
+ const model = await createModel();
30
+ expect(model.bounds).to.deep.eq({ rows: 5, columns: 5 });
31
+ model.setValue(addressFromA1Notation('A1'), 100);
32
+ const value = model.getValue(addressFromA1Notation('A1'));
33
+ expect(value).to.eq(100);
34
+ });
35
+
36
+ test('map formula', async () => {
37
+ const model = await createModel();
38
+ const x1 = model.mapFormulaRefsToIndices('=SUM(A1:A3)');
39
+ const x2 = model.mapFormulaIndicesToRefs(x1);
40
+ expect(x2).to.eq('=SUM(A1:A3)');
41
+ });
42
+
43
+ test('dates', async () => {
44
+ const model = await createModel();
45
+ const cell = addressFromA1Notation('A1');
46
+ model.setValue(cell, '=NOW()');
47
+ const type = model.getValueType(cell);
48
+ expect(type).to.eq(ValueTypeEnum.DateTime);
49
+ const value = model.getValue(cell);
50
+ const date = model.toLocalDate(value as number);
51
+ const now = new Date();
52
+ expect(date.getUTCFullYear()).to.eq(now.getUTCFullYear());
53
+ expect(date.getUTCMonth()).to.eq(now.getUTCMonth());
54
+ expect(date.getUTCDate()).to.eq(now.getUTCDate());
55
+ });
56
+
57
+ test('formula', async () => {
58
+ const model = await createModel();
59
+
60
+ // Nested formula.
61
+ {
62
+ model.setValue(addressFromA1Notation('A1'), 100);
63
+ model.setValue(addressFromA1Notation('A2'), 200);
64
+ model.setValue(addressFromA1Notation('A3'), '=SUM(A1:A2)');
65
+ model.setValue(addressFromA1Notation('A4'), '=SUM(A1:A3)');
66
+ const value = model.getValue(addressFromA1Notation('A4'));
67
+ expect(value).to.eq(600);
68
+ // console.log(JSON.stringify(model.sheet.cells, undefined, 2));
69
+
70
+ const cells = model.getCellValues(rangeFromA1Notation('A1:A4'));
71
+ expect(cells).to.deep.eq([
72
+ [100],
73
+ [200],
74
+ [model.mapFormulaRefsToIndices('=SUM(A1:A2)')],
75
+ [model.mapFormulaRefsToIndices('=SUM(A1:A3)')],
76
+ ]);
77
+ // console.log(JSON.stringify(model.sheet.cells, undefined, 2));
78
+ // console.log(cells);
79
+ }
80
+
81
+ // Insert row.
82
+ {
83
+ model.insertRows(2, 1);
84
+ model.setValue(addressFromA1Notation('A3'), 400);
85
+ const value = model.getValue(addressFromA1Notation('A5'));
86
+ expect(value).to.eq(1000);
87
+
88
+ const cells = model.getCellValues(rangeFromA1Notation('A1:A5'));
89
+ expect(cells).to.deep.eq([
90
+ [100],
91
+ [200],
92
+ [400],
93
+ [model.mapFormulaRefsToIndices('=SUM(A1:A2)')],
94
+ [model.mapFormulaRefsToIndices('=SUM(A1:A4)')],
95
+ ]);
96
+ // console.log(JSON.stringify(model.sheet.cells, undefined, 2));
97
+ // console.log(cells);
98
+ }
99
+ });
100
+ });