@dxos/plugin-sheet 0.6.13 → 0.6.14-main.1366248

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 (330) hide show
  1. package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs +297 -0
  2. package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-BVUN7SHF.mjs +67 -0
  4. package/dist/lib/browser/chunk-BVUN7SHF.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-G2FUL6PK.mjs +1671 -0
  6. package/dist/lib/browser/chunk-G2FUL6PK.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-RABELMEQ.mjs +15 -0
  8. package/dist/lib/browser/chunk-RABELMEQ.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-D5AGLXJP.mjs → chunk-VMSX6Z4X.mjs} +659 -675
  10. package/dist/lib/browser/chunk-VMSX6Z4X.mjs.map +7 -0
  11. package/dist/lib/browser/compute-graph-GGWUX644.mjs +35 -0
  12. package/dist/lib/browser/compute-graph-GGWUX644.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +168 -67
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/meta.mjs +1 -1
  17. package/dist/lib/browser/types.mjs +6 -12
  18. package/dist/lib/node/SheetContainer-PJE74VO4.cjs +300 -0
  19. package/dist/lib/node/SheetContainer-PJE74VO4.cjs.map +7 -0
  20. package/dist/lib/node/chunk-2ZVZI2KJ.cjs +38 -0
  21. package/dist/lib/node/chunk-2ZVZI2KJ.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-AWKOWDMI.cjs} +34 -52
  23. package/dist/lib/node/chunk-AWKOWDMI.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-O7XR4R7Y.cjs} +678 -674
  25. package/dist/lib/node/chunk-O7XR4R7Y.cjs.map +7 -0
  26. package/dist/lib/node/chunk-STZ7S7RF.cjs +1656 -0
  27. package/dist/lib/node/chunk-STZ7S7RF.cjs.map +7 -0
  28. package/dist/lib/node/compute-graph-KGWA2QLE.cjs +57 -0
  29. package/dist/lib/node/compute-graph-KGWA2QLE.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +178 -75
  31. package/dist/lib/node/index.cjs.map +4 -4
  32. package/dist/lib/node/meta.cjs +3 -3
  33. package/dist/lib/node/meta.cjs.map +1 -1
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/types.cjs +9 -15
  36. package/dist/lib/node/types.cjs.map +2 -2
  37. package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs +298 -0
  38. package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs +17 -0
  40. package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-CR4K75EL.mjs +3220 -0
  42. package/dist/lib/node-esm/chunk-CR4K75EL.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-UIBWRHW7.mjs +68 -0
  44. package/dist/lib/node-esm/chunk-UIBWRHW7.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs +1672 -0
  46. package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs.map +7 -0
  47. package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs +36 -0
  48. package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs.map +7 -0
  49. package/dist/lib/node-esm/index.mjs +350 -0
  50. package/dist/lib/node-esm/index.mjs.map +7 -0
  51. package/dist/lib/node-esm/meta.json +1 -0
  52. package/dist/lib/node-esm/meta.mjs +10 -0
  53. package/dist/lib/node-esm/meta.mjs.map +7 -0
  54. package/dist/lib/node-esm/types.mjs +17 -0
  55. package/dist/lib/node-esm/types.mjs.map +7 -0
  56. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  57. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +13 -0
  58. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -0
  59. package/dist/types/src/components/ComputeGraph/index.d.ts +1 -3
  60. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  61. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +3 -0
  62. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -0
  63. package/dist/types/src/components/FunctionEditor/index.d.ts +2 -0
  64. package/dist/types/src/components/FunctionEditor/index.d.ts.map +1 -0
  65. package/dist/types/src/components/GridSheet/GridSheet.d.ts +3 -0
  66. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -0
  67. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +6 -0
  68. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -0
  69. package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +5 -9
  70. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/GridSheet/index.d.ts +2 -0
  72. package/dist/types/src/components/GridSheet/index.d.ts.map +1 -0
  73. package/dist/types/src/components/GridSheet/util.d.ts +15 -0
  74. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
  75. package/dist/types/src/components/RangeList/RangeList.d.ts +7 -0
  76. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -0
  77. package/dist/types/src/components/RangeList/index.d.ts +2 -0
  78. package/dist/types/src/components/RangeList/index.d.ts.map +1 -0
  79. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +9 -0
  80. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +6 -0
  82. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
  83. package/dist/types/src/components/SheetContainer/index.d.ts +3 -0
  84. package/dist/types/src/components/SheetContainer/index.d.ts.map +1 -0
  85. package/dist/types/src/components/SheetContext/SheetContext.d.ts +28 -0
  86. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -0
  87. package/dist/types/src/components/SheetContext/index.d.ts +2 -0
  88. package/dist/types/src/components/SheetContext/index.d.ts.map +1 -0
  89. package/dist/types/src/components/Toolbar/Toolbar.d.ts +36 -9
  90. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  91. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +4 -32
  92. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  93. package/dist/types/src/components/index.d.ts +7 -4
  94. package/dist/types/src/components/index.d.ts.map +1 -1
  95. package/dist/types/src/compute-graph/compute-graph-registry.d.ts +34 -0
  96. package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +1 -0
  97. package/dist/types/src/compute-graph/compute-graph.d.ts +64 -0
  98. package/dist/types/src/compute-graph/compute-graph.d.ts.map +1 -0
  99. package/dist/types/src/compute-graph/compute-graph.stories.d.ts +6 -0
  100. package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +1 -0
  101. package/dist/types/src/compute-graph/compute-graph.test.d.ts +2 -0
  102. package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +1 -0
  103. package/dist/types/src/compute-graph/compute-node.d.ts +26 -0
  104. package/dist/types/src/compute-graph/compute-node.d.ts.map +1 -0
  105. package/dist/types/src/{components/ComputeGraph → compute-graph/functions}/async-function.d.ts +14 -5
  106. package/dist/types/src/compute-graph/functions/async-function.d.ts.map +1 -0
  107. package/dist/types/src/compute-graph/functions/edge-function.d.ts +21 -0
  108. package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +1 -0
  109. package/dist/types/src/{model/functions.d.ts → compute-graph/functions/function-defs.d.ts} +1 -1
  110. package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +1 -0
  111. package/dist/types/src/compute-graph/functions/index.d.ts +4 -0
  112. package/dist/types/src/compute-graph/functions/index.d.ts.map +1 -0
  113. package/dist/types/src/compute-graph/hyperformula.test.d.ts +2 -0
  114. package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +1 -0
  115. package/dist/types/src/compute-graph/index.d.ts +5 -0
  116. package/dist/types/src/compute-graph/index.d.ts.map +1 -0
  117. package/dist/types/src/compute-graph/testing/index.d.ts +3 -0
  118. package/dist/types/src/compute-graph/testing/index.d.ts.map +1 -0
  119. package/dist/types/src/compute-graph/testing/test-builder.d.ts +15 -0
  120. package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +1 -0
  121. package/dist/types/src/compute-graph/testing/test-plugin.d.ts +36 -0
  122. package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +1 -0
  123. package/dist/types/src/compute-graph/util.d.ts +2 -0
  124. package/dist/types/src/compute-graph/util.d.ts.map +1 -0
  125. package/dist/types/src/defs/index.d.ts +4 -0
  126. package/dist/types/src/defs/index.d.ts.map +1 -0
  127. package/dist/types/src/defs/sheet-range-types.d.ts +13 -0
  128. package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -0
  129. package/dist/types/src/defs/types.d.ts +28 -0
  130. package/dist/types/src/defs/types.d.ts.map +1 -0
  131. package/dist/types/src/defs/types.test.d.ts.map +1 -0
  132. package/dist/types/src/defs/util.d.ts +39 -0
  133. package/dist/types/src/defs/util.d.ts.map +1 -0
  134. package/dist/types/src/extensions/compute.d.ts +6 -0
  135. package/dist/types/src/extensions/compute.d.ts.map +1 -0
  136. package/dist/types/src/extensions/compute.stories.d.ts +21 -0
  137. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
  138. package/dist/types/src/extensions/editor/extension.d.ts +39 -0
  139. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
  140. package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
  141. package/dist/types/src/extensions/editor/index.d.ts +2 -0
  142. package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
  143. package/dist/types/src/extensions/index.d.ts +3 -0
  144. package/dist/types/src/extensions/index.d.ts.map +1 -0
  145. package/dist/types/src/index.d.ts +1 -1
  146. package/dist/types/src/index.d.ts.map +1 -1
  147. package/dist/types/src/integrations/index.d.ts +2 -0
  148. package/dist/types/src/integrations/index.d.ts.map +1 -0
  149. package/dist/types/src/integrations/thread-ranges.d.ts +7 -0
  150. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -0
  151. package/dist/types/src/meta.d.ts +4 -9
  152. package/dist/types/src/meta.d.ts.map +1 -1
  153. package/dist/types/src/model/index.d.ts +2 -3
  154. package/dist/types/src/model/index.d.ts.map +1 -1
  155. package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +22 -69
  156. package/dist/types/src/model/sheet-model.d.ts.map +1 -0
  157. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  158. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  159. package/dist/types/src/model/useSheetModel.d.ts +8 -0
  160. package/dist/types/src/model/useSheetModel.d.ts.map +1 -0
  161. package/dist/types/src/sanity.test.d.ts +2 -0
  162. package/dist/types/src/sanity.test.d.ts.map +1 -0
  163. package/dist/types/src/serializer.d.ts +4 -0
  164. package/dist/types/src/serializer.d.ts.map +1 -0
  165. package/dist/types/src/testing/index.d.ts +2 -0
  166. package/dist/types/src/testing/index.d.ts.map +1 -0
  167. package/dist/types/src/testing/testing.d.ts +8 -0
  168. package/dist/types/src/testing/testing.d.ts.map +1 -0
  169. package/dist/types/src/translations.d.ts +32 -12
  170. package/dist/types/src/translations.d.ts.map +1 -1
  171. package/dist/types/src/types.d.ts +132 -43
  172. package/dist/types/src/types.d.ts.map +1 -1
  173. package/dist/vendor/hyperformula.mjs +37145 -0
  174. package/package.json +60 -61
  175. package/src/SheetPlugin.tsx +89 -78
  176. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +37 -0
  177. package/src/components/ComputeGraph/index.ts +1 -3
  178. package/src/components/FunctionEditor/FunctionEditor.tsx +45 -0
  179. package/src/components/FunctionEditor/index.ts +5 -0
  180. package/src/components/GridSheet/GridSheet.stories.tsx +46 -0
  181. package/src/components/GridSheet/GridSheet.tsx +358 -0
  182. package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +18 -15
  183. package/src/components/GridSheet/index.ts +5 -0
  184. package/src/components/GridSheet/util.ts +170 -0
  185. package/src/components/RangeList/RangeList.tsx +53 -0
  186. package/src/components/RangeList/index.ts +5 -0
  187. package/src/components/SheetContainer/SheetContainer.stories.tsx +45 -0
  188. package/src/components/SheetContainer/SheetContainer.tsx +33 -0
  189. package/src/components/SheetContainer/index.ts +7 -0
  190. package/src/components/SheetContext/SheetContext.tsx +127 -0
  191. package/src/components/SheetContext/index.ts +5 -0
  192. package/src/components/Toolbar/Toolbar.stories.tsx +9 -6
  193. package/src/components/Toolbar/Toolbar.tsx +265 -111
  194. package/src/components/index.ts +5 -3
  195. package/src/compute-graph/compute-graph-registry.ts +90 -0
  196. package/src/compute-graph/compute-graph.stories.tsx +97 -0
  197. package/src/compute-graph/compute-graph.test.ts +87 -0
  198. package/src/compute-graph/compute-graph.ts +260 -0
  199. package/src/compute-graph/compute-node.ts +62 -0
  200. package/src/{components/ComputeGraph → compute-graph/functions}/async-function.ts +26 -15
  201. package/src/{components/ComputeGraph → compute-graph/functions}/edge-function.ts +21 -17
  202. package/src/compute-graph/functions/index.ts +7 -0
  203. package/src/compute-graph/hyperformula.test.ts +14 -0
  204. package/src/compute-graph/index.ts +8 -0
  205. package/src/compute-graph/testing/index.ts +6 -0
  206. package/src/compute-graph/testing/test-builder.ts +54 -0
  207. package/src/{components/ComputeGraph/custom.ts → compute-graph/testing/test-plugin.ts} +44 -14
  208. package/src/compute-graph/util.ts +8 -0
  209. package/src/defs/index.ts +7 -0
  210. package/src/defs/sheet-range-types.ts +49 -0
  211. package/src/{model → defs}/types.test.ts +8 -9
  212. package/src/defs/types.ts +86 -0
  213. package/src/defs/util.ts +136 -0
  214. package/src/extensions/compute.stories.tsx +155 -0
  215. package/src/extensions/compute.ts +147 -0
  216. package/src/{components/CellEditor → extensions/editor}/extension.test.ts +4 -6
  217. package/src/{components/CellEditor → extensions/editor}/extension.ts +51 -27
  218. package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
  219. package/src/extensions/index.ts +6 -0
  220. package/src/index.ts +2 -2
  221. package/src/integrations/index.ts +5 -0
  222. package/src/integrations/thread-ranges.ts +101 -0
  223. package/src/meta.ts +15 -0
  224. package/src/model/index.ts +2 -3
  225. package/src/model/sheet-model.test.ts +59 -0
  226. package/src/model/sheet-model.ts +495 -0
  227. package/src/model/useSheetModel.ts +40 -0
  228. package/src/sanity.test.ts +40 -0
  229. package/src/serializer.ts +27 -0
  230. package/src/{components/Sheet → testing}/index.ts +1 -1
  231. package/src/testing/testing.tsx +68 -0
  232. package/src/translations.ts +24 -4
  233. package/src/types.ts +62 -47
  234. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +0 -1772
  235. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
  236. package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
  237. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
  238. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
  239. package/dist/lib/browser/chunk-FUAGSXA4.mjs +0 -82
  240. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
  241. package/dist/lib/browser/chunk-JRL5LGCE.mjs +0 -18
  242. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
  243. package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
  244. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
  245. package/dist/lib/browser/testing.mjs +0 -92
  246. package/dist/lib/browser/testing.mjs.map +0 -7
  247. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +0 -1765
  248. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
  249. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
  250. package/dist/lib/node/chunk-BJ6ZD7MN.cjs +0 -51
  251. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
  252. package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
  253. package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
  254. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
  255. package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
  256. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
  257. package/dist/lib/node/testing.cjs +0 -111
  258. package/dist/lib/node/testing.cjs.map +0 -7
  259. package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -14
  260. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
  261. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
  262. package/dist/types/src/components/CellEditor/extension.d.ts +0 -19
  263. package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
  264. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
  265. package/dist/types/src/components/CellEditor/index.d.ts +0 -3
  266. package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
  267. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
  268. package/dist/types/src/components/ComputeGraph/custom.d.ts +0 -21
  269. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
  270. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +0 -20
  271. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
  272. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
  273. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
  274. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
  275. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
  276. package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
  277. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
  278. package/dist/types/src/components/Sheet/Sheet.d.ts +0 -55
  279. package/dist/types/src/components/Sheet/Sheet.d.ts.map +0 -1
  280. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +0 -54
  281. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
  282. package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
  283. package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
  284. package/dist/types/src/components/Sheet/grid.d.ts +0 -52
  285. package/dist/types/src/components/Sheet/grid.d.ts.map +0 -1
  286. package/dist/types/src/components/Sheet/index.d.ts +0 -2
  287. package/dist/types/src/components/Sheet/index.d.ts.map +0 -1
  288. package/dist/types/src/components/Sheet/nav.d.ts +0 -29
  289. package/dist/types/src/components/Sheet/nav.d.ts.map +0 -1
  290. package/dist/types/src/components/Sheet/sheet-context.d.ts +0 -25
  291. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
  292. package/dist/types/src/components/Sheet/util.d.ts +0 -18
  293. package/dist/types/src/components/Sheet/util.d.ts.map +0 -1
  294. package/dist/types/src/components/SheetContainer.d.ts +0 -9
  295. package/dist/types/src/components/SheetContainer.d.ts.map +0 -1
  296. package/dist/types/src/components/Toolbar/common.d.ts +0 -20
  297. package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
  298. package/dist/types/src/model/functions.d.ts.map +0 -1
  299. package/dist/types/src/model/model.browser.test.d.ts +0 -2
  300. package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
  301. package/dist/types/src/model/model.d.ts.map +0 -1
  302. package/dist/types/src/model/types.d.ts +0 -17
  303. package/dist/types/src/model/types.d.ts.map +0 -1
  304. package/dist/types/src/model/types.test.d.ts.map +0 -1
  305. package/dist/types/src/model/util.d.ts +0 -15
  306. package/dist/types/src/model/util.d.ts.map +0 -1
  307. package/dist/types/src/testing.d.ts +0 -9
  308. package/dist/types/src/testing.d.ts.map +0 -1
  309. package/src/components/CellEditor/CellEditor.tsx +0 -113
  310. package/src/components/ComputeGraph/graph-context.tsx +0 -50
  311. package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
  312. package/src/components/ComputeGraph/graph.ts +0 -62
  313. package/src/components/Sheet/Sheet.stories.tsx +0 -287
  314. package/src/components/Sheet/Sheet.tsx +0 -1160
  315. package/src/components/Sheet/formatting.ts +0 -106
  316. package/src/components/Sheet/grid.ts +0 -191
  317. package/src/components/Sheet/nav.ts +0 -157
  318. package/src/components/Sheet/sheet-context.tsx +0 -150
  319. package/src/components/Sheet/util.ts +0 -56
  320. package/src/components/SheetContainer.tsx +0 -34
  321. package/src/components/Toolbar/common.tsx +0 -72
  322. package/src/meta.tsx +0 -18
  323. package/src/model/model.browser.test.ts +0 -100
  324. package/src/model/model.ts +0 -550
  325. package/src/model/types.ts +0 -71
  326. package/src/model/util.ts +0 -36
  327. package/src/testing.ts +0 -50
  328. /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
  329. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
  330. /package/src/{model/functions.ts → compute-graph/functions/function-defs.ts} +0 -0
@@ -0,0 +1,495 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type SimpleCellRange } from 'hyperformula/typings/AbsoluteCellRange';
6
+ import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
7
+ import { type SimpleDate, type SimpleDateTime } from 'hyperformula/typings/DateTimeHelper';
8
+
9
+ import { Event } from '@dxos/async';
10
+ import { Resource } from '@dxos/context';
11
+ import { getTypename, FormatEnum, TypeEnum } from '@dxos/echo-schema';
12
+ import { invariant } from '@dxos/invariant';
13
+ import { PublicKey } from '@dxos/keys';
14
+ import { log } from '@dxos/log';
15
+
16
+ import { DetailedCellError, ExportedCellChange } from '#hyperformula';
17
+ import { type ComputeGraph, type ComputeNode, type ComputeNodeEvent, createSheetName } from '../compute-graph';
18
+ import {
19
+ addressFromA1Notation,
20
+ addressFromIndex,
21
+ addressToA1Notation,
22
+ addressToIndex,
23
+ initialize,
24
+ insertIndices,
25
+ isFormula,
26
+ type CellAddress,
27
+ type CellRange,
28
+ ReadonlyException,
29
+ MAX_COLUMNS,
30
+ MAX_ROWS,
31
+ } from '../defs';
32
+ import { type CellScalarValue, type CellValue, type SheetType, type RestoreAxis } from '../types';
33
+
34
+ // Map sheet types to system types.
35
+ // https://hyperformula.handsontable.com/guide/types-of-values.html
36
+ // - https://github.com/handsontable/hyperformula/blob/master/src/Cell.ts (CellValueType)
37
+ // - https://github.com/handsontable/hyperformula/blob/master/src/interpreter/InterpreterValue.ts (NumberType)
38
+ const typeMap: Record<string, { type: TypeEnum; format?: FormatEnum }> = {
39
+ BOOLEAN: { type: TypeEnum.Boolean },
40
+ NUMBER_RAW: { type: TypeEnum.Number },
41
+ NUMBER_PERCENT: { type: TypeEnum.Number, format: FormatEnum.Percent },
42
+ NUMBER_CURRENCY: { type: TypeEnum.Number, format: FormatEnum.Currency },
43
+ NUMBER_DATETIME: { type: TypeEnum.String, format: FormatEnum.DateTime },
44
+ NUMBER_DATE: { type: TypeEnum.String, format: FormatEnum.Date },
45
+ NUMBER_TIME: { type: TypeEnum.String, format: FormatEnum.Time },
46
+ };
47
+
48
+ const getTopLeft = (range: CellRange): CellAddress => {
49
+ const to = range.to ?? range.from;
50
+ return { row: Math.min(range.from.row, to.row), col: Math.min(range.from.col, to.col) };
51
+ };
52
+
53
+ const toSimpleCellAddress = (sheet: number, cell: CellAddress): SimpleCellAddress => ({
54
+ sheet,
55
+ row: cell.row,
56
+ col: cell.col,
57
+ });
58
+
59
+ const toModelRange = (sheet: number, range: CellRange): SimpleCellRange => ({
60
+ start: toSimpleCellAddress(sheet, range.from),
61
+ end: toSimpleCellAddress(sheet, range.to ?? range.from),
62
+ });
63
+
64
+ export type SheetModelOptions = {
65
+ readonly?: boolean;
66
+ };
67
+
68
+ /**
69
+ * Spreadsheet data model.
70
+ *
71
+ * [ComputeGraphContext] > [SheetContext]:[SheetModel] > [Sheet.Root]
72
+ */
73
+ // TODO(burdon): Factor out commonality with ComputeNode. Factor out HF.
74
+ export class SheetModel extends Resource {
75
+ public readonly id = `model-${PublicKey.random().truncate()}`;
76
+
77
+ // Wraps compute node.
78
+ public readonly update = new Event<ComputeNodeEvent>();
79
+
80
+ private _node?: ComputeNode;
81
+
82
+ constructor(
83
+ private readonly _graph: ComputeGraph,
84
+ private readonly _sheet: SheetType,
85
+ private readonly _options: SheetModelOptions = {},
86
+ ) {
87
+ super();
88
+ }
89
+
90
+ get graph() {
91
+ return this._graph;
92
+ }
93
+
94
+ get sheet() {
95
+ return this._sheet;
96
+ }
97
+
98
+ get readonly() {
99
+ return this._options.readonly;
100
+ }
101
+
102
+ get bounds() {
103
+ return {
104
+ rows: this._sheet.rows.length,
105
+ columns: this._sheet.columns.length,
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Initialize sheet and engine.
111
+ */
112
+ protected override async _open() {
113
+ log('initialize', { id: this.id });
114
+ initialize(this._sheet);
115
+
116
+ this._graph.update.on((event) => {
117
+ if (event.type === 'functionsUpdated') {
118
+ this.reset();
119
+ }
120
+ });
121
+
122
+ // TODO(burdon): SheetModel should extend ComputeNode and be constructed via the graph.
123
+ this._node = this._graph.getOrCreateNode(createSheetName({ type: getTypename(this._sheet)!, id: this._sheet.id }));
124
+ await this._node.open();
125
+
126
+ // Listen for model updates (e.g., async calculations).
127
+ const unsubscribe = this._node.update.on((event) => this.update.emit(event));
128
+ this._ctx.onDispose(unsubscribe);
129
+
130
+ this.reset();
131
+ }
132
+
133
+ /**
134
+ * Update engine.
135
+ * NOTE: This resets the undo history.
136
+ * @deprecated
137
+ */
138
+ reset() {
139
+ invariant(this._node);
140
+ this._node.graph.hf.clearSheet(this._node.sheetId);
141
+ Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
142
+ invariant(this._node);
143
+ const { col, row } = addressFromIndex(this._sheet, key);
144
+ if (isFormula(value)) {
145
+ const binding = this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
146
+ if (binding) {
147
+ value = this._graph.mapFormulaToNative(binding);
148
+ } else {
149
+ // If binding is not found, render the cell as empty.
150
+ // This prevents the cell from momentarily rendering an error while the binding is being loaded.
151
+ value = '';
152
+ }
153
+ }
154
+
155
+ this._node.graph.hf.setCellContents({ sheet: this._node.sheetId, row, col }, value);
156
+ });
157
+ }
158
+
159
+ /**
160
+ * Recalculate formulas.
161
+ * NOTE: This resets the undo history.
162
+ * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
163
+ * @deprecated
164
+ */
165
+ // TODO(burdon): Remove.
166
+ recalculate() {
167
+ this._node?.graph.hf.rebuildAndRecalculate();
168
+ }
169
+
170
+ insertRows(i: number, n = 1) {
171
+ const idx = insertIndices(this._sheet.rows, i, n, MAX_ROWS);
172
+ this.reset();
173
+ return idx;
174
+ }
175
+
176
+ insertColumns(i: number, n = 1) {
177
+ const idx = insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
178
+ this.reset();
179
+ return idx;
180
+ }
181
+
182
+ dropRow(rowIndex: string): RestoreAxis {
183
+ const range = {
184
+ from: addressFromIndex(this._sheet, `${this._sheet.columns[0]}@${rowIndex}`),
185
+ to: addressFromIndex(this._sheet, `${this._sheet.columns[this._sheet.columns.length - 1]}@${rowIndex}`),
186
+ };
187
+ const values = this.getCellValues(range).flat();
188
+ const index = this._sheet.rows.indexOf(rowIndex);
189
+ this.clear(range);
190
+ this._sheet.rows.splice(index, 1);
191
+ delete this._sheet.rowMeta[rowIndex];
192
+ this.reset();
193
+ return { axis: 'row', index, axisIndex: rowIndex, axisMeta: this._sheet.rowMeta[rowIndex], values };
194
+ }
195
+
196
+ dropColumn(colIndex: string): RestoreAxis {
197
+ const range = {
198
+ from: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[0]}`),
199
+ to: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[this._sheet.rows.length - 1]}`),
200
+ };
201
+ const values = this.getCellValues(range).flat();
202
+ const index = this._sheet.columns.indexOf(colIndex);
203
+ this.clear(range);
204
+ this._sheet.columns.splice(index, 1);
205
+ delete this._sheet.columnMeta[colIndex];
206
+ this.reset();
207
+ return { axis: 'col', index, axisIndex: colIndex, axisMeta: this._sheet.rowMeta[colIndex], values };
208
+ }
209
+
210
+ restoreRow({ index, axisIndex, axisMeta, values }: RestoreAxis) {
211
+ this._sheet.rows.splice(index, 0, axisIndex);
212
+ values.forEach((value, col) => {
213
+ if (value) {
214
+ this._sheet.cells[`${this._sheet.columns[col]}@${axisIndex}`] = { value };
215
+ }
216
+ });
217
+ if (axisMeta) {
218
+ this._sheet.rowMeta[axisIndex] = axisMeta;
219
+ }
220
+ this.reset();
221
+ }
222
+
223
+ restoreColumn({ index, axisIndex, axisMeta, values }: RestoreAxis) {
224
+ this._sheet.columns.splice(index, 0, axisIndex);
225
+ values.forEach((value, row) => {
226
+ if (value) {
227
+ this._sheet.cells[`${axisIndex}@${this._sheet.rows[row]}`] = { value };
228
+ }
229
+ });
230
+ if (axisMeta) {
231
+ this._sheet.columnMeta[axisIndex] = axisMeta;
232
+ }
233
+ this.reset();
234
+ }
235
+
236
+ //
237
+ // Undoable actions.
238
+ // TODO(burdon): Group undoable methods; consistently update hf/sheet.
239
+ //
240
+
241
+ /**
242
+ * Clear range of values.
243
+ */
244
+ clear(range: CellRange) {
245
+ invariant(this._node);
246
+ const topLeft = getTopLeft(range);
247
+ const values = this._iterRange(range, () => null);
248
+ this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
249
+ this._iterRange(range, (cell) => {
250
+ const idx = addressToIndex(this._sheet, cell);
251
+ delete this._sheet.cells[idx];
252
+ });
253
+ }
254
+
255
+ cut(range: CellRange) {
256
+ invariant(this._node);
257
+ this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
258
+ this._iterRange(range, (cell) => {
259
+ const idx = addressToIndex(this._sheet, cell);
260
+ delete this._sheet.cells[idx];
261
+ });
262
+ }
263
+
264
+ copy(range: CellRange) {
265
+ invariant(this._node);
266
+ this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
267
+ }
268
+
269
+ paste(cell: CellAddress) {
270
+ invariant(this._node);
271
+ if (!this._node.graph.hf.isClipboardEmpty()) {
272
+ const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
273
+ for (const change of changes) {
274
+ if (change instanceof ExportedCellChange) {
275
+ const { address, newValue } = change;
276
+ const idx = addressToIndex(this._sheet, { row: address.row, col: address.col });
277
+ this._sheet.cells[idx] = { value: newValue };
278
+ }
279
+ }
280
+ }
281
+ }
282
+
283
+ // TODO(burdon): Display undo/redo state.
284
+ undo() {
285
+ invariant(this._node);
286
+ if (this._node.graph.hf.isThereSomethingToUndo()) {
287
+ this._node.graph.hf.undo();
288
+ // this.update.emit();
289
+ }
290
+ }
291
+
292
+ redo() {
293
+ invariant(this._node);
294
+ if (this._node.graph.hf.isThereSomethingToRedo()) {
295
+ this._node.graph.hf.redo();
296
+ // this.update.emit();
297
+ }
298
+ }
299
+
300
+ /**
301
+ * Get value from sheet.
302
+ */
303
+ getCellValue(cell: CellAddress): CellScalarValue {
304
+ const idx = addressToIndex(this._sheet, cell);
305
+ return this._sheet.cells[idx]?.value ?? null;
306
+ }
307
+
308
+ /**
309
+ * Get value as a string for editing.
310
+ */
311
+ getCellText(cell: CellAddress): string | undefined {
312
+ const value = this.getCellValue(cell);
313
+ if (value == null) {
314
+ return undefined;
315
+ }
316
+
317
+ if (isFormula(value)) {
318
+ return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
319
+ } else {
320
+ return String(value);
321
+ }
322
+ }
323
+
324
+ /**
325
+ * Get array of raw values from sheet.
326
+ */
327
+ getCellValues(range: CellRange): CellScalarValue[][] {
328
+ return this._iterRange(range, (cell) => this.getCellValue(cell));
329
+ }
330
+
331
+ /**
332
+ * Gets the regular or computed value from the engine.
333
+ */
334
+ getValue(cell: CellAddress): CellScalarValue {
335
+ // Applies rounding and post-processing.
336
+ invariant(this._node);
337
+ const address = toSimpleCellAddress(this._node.sheetId, cell);
338
+ const value = this._node.graph.hf.getCellValue(address);
339
+ if (value instanceof DetailedCellError) {
340
+ // TODO(wittjosiah): Error details should be shown in cell `title`.
341
+ log.info('cell error', { cell, error: value });
342
+ return value.toString();
343
+ }
344
+
345
+ return value;
346
+ }
347
+
348
+ /**
349
+ * Get value type.
350
+ */
351
+ getValueDescription(cell: CellAddress): { type: TypeEnum; format?: FormatEnum } | undefined {
352
+ invariant(this._node);
353
+ const addr = toSimpleCellAddress(this._node.sheetId, cell);
354
+ const type = this._node.graph.hf.getCellValueDetailedType(addr);
355
+ return typeMap[type];
356
+ }
357
+
358
+ /**
359
+ * Sets the value, updating the sheet and engine.
360
+ */
361
+ setValue(cell: CellAddress, value: CellScalarValue) {
362
+ invariant(this._node);
363
+ if (this._options.readonly) {
364
+ throw new ReadonlyException();
365
+ }
366
+
367
+ // Reallocate if > current bounds.
368
+ let refresh = false;
369
+ if (cell.row >= this._sheet.rows.length) {
370
+ insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
371
+ refresh = true;
372
+ }
373
+ if (cell.col >= this._sheet.columns.length) {
374
+ insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
375
+ refresh = true;
376
+ }
377
+
378
+ if (refresh) {
379
+ // TODO(burdon): Remove.
380
+ this.reset();
381
+ }
382
+
383
+ // Insert into engine.
384
+ this._node.graph.hf.setCellContents({ sheet: this._node.sheetId, row: cell.row, col: cell.col }, [
385
+ [isFormula(value) ? this._graph.mapFormulaToNative(value) : value],
386
+ ]);
387
+
388
+ // Insert into sheet.
389
+ const idx = addressToIndex(this._sheet, cell);
390
+ if (value === undefined || value === null) {
391
+ delete this._sheet.cells[idx];
392
+ } else {
393
+ if (isFormula(value)) {
394
+ value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
395
+ }
396
+
397
+ this._sheet.cells[idx] = { value };
398
+ }
399
+ }
400
+
401
+ /**
402
+ * Sets values from a simple map.
403
+ */
404
+ setValues(values: Record<string, CellValue>) {
405
+ Object.entries(values).forEach(([key, { value }]) => {
406
+ this.setValue(addressFromA1Notation(key), value);
407
+ });
408
+ }
409
+
410
+ /**
411
+ * Iterate range.
412
+ */
413
+ private _iterRange(range: CellRange, cb: (cell: CellAddress) => CellScalarValue | void): CellScalarValue[][] {
414
+ const to = range.to ?? range.from;
415
+ const rowRange = [Math.min(range.from.row, to.row), Math.max(range.from.row, to.row)];
416
+ const columnRange = [Math.min(range.from.col, to.col), Math.max(range.from.col, to.col)];
417
+ const rows: CellScalarValue[][] = [];
418
+ for (let row = rowRange[0]; row <= rowRange[1]; row++) {
419
+ const rowCells: CellScalarValue[] = [];
420
+ for (let column = columnRange[0]; column <= columnRange[1]; column++) {
421
+ const value = cb({ row, col: column });
422
+ if (value !== undefined) {
423
+ rowCells.push(value);
424
+ }
425
+ }
426
+
427
+ rows.push(rowCells);
428
+ }
429
+
430
+ return rows;
431
+ }
432
+
433
+ // TODO(burdon): Delete index.
434
+ private _deleteIndices(indices: string[], i: number, n: number) {
435
+ throw new Error('Not implemented');
436
+ }
437
+
438
+ // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
439
+ private _moveIndices(indices: string[], i: number, j: number, n: number) {
440
+ throw new Error('Not implemented');
441
+ }
442
+
443
+ //
444
+ // Indices.
445
+ //
446
+
447
+ /**
448
+ * Map from A1 notation to indices.
449
+ */
450
+ mapFormulaRefsToIndices(formula: string): string {
451
+ invariant(isFormula(formula));
452
+ return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
453
+ return addressToIndex(this._sheet, addressFromA1Notation(match));
454
+ });
455
+ }
456
+
457
+ /**
458
+ * Map from indices to A1 notation.
459
+ */
460
+ mapFormulaIndicesToRefs(formula: string): string {
461
+ invariant(isFormula(formula));
462
+ return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
463
+ return addressToA1Notation(addressFromIndex(this._sheet, idx));
464
+ });
465
+ }
466
+
467
+ //
468
+ // Values
469
+ //
470
+
471
+ /**
472
+ * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
473
+ * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
474
+ * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
475
+ */
476
+ toLocalDate(num: number): Date {
477
+ const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
478
+ return new Date(year, month - 1, day, hours, minutes, seconds);
479
+ }
480
+
481
+ toDateTime(num: number): SimpleDateTime {
482
+ invariant(this._node);
483
+ return this._node.graph.hf.numberToDateTime(num) as SimpleDateTime;
484
+ }
485
+
486
+ toDate(num: number): SimpleDate {
487
+ invariant(this._node);
488
+ return this._node.graph.hf.numberToDate(num) as SimpleDate;
489
+ }
490
+
491
+ toTime(num: number): SimpleDate {
492
+ invariant(this._node);
493
+ return this._node.graph.hf.numberToTime(num) as SimpleDate;
494
+ }
495
+ }
@@ -0,0 +1,40 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { useEffect, useState } from 'react';
6
+
7
+ import { type ComputeGraph } from '../compute-graph';
8
+ import { SheetModel } from '../model';
9
+ import { type SheetType } from '../types';
10
+
11
+ export type UseSheetModelOptions = {
12
+ readonly?: boolean;
13
+ };
14
+
15
+ export const useSheetModel = (
16
+ graph?: ComputeGraph,
17
+ sheet?: SheetType,
18
+ { readonly }: UseSheetModelOptions = {},
19
+ ): SheetModel | undefined => {
20
+ const [model, setModel] = useState<SheetModel>();
21
+ useEffect(() => {
22
+ if (!graph || !sheet) {
23
+ return;
24
+ }
25
+
26
+ let model: SheetModel | undefined;
27
+ const t = setTimeout(async () => {
28
+ model = new SheetModel(graph, sheet, { readonly });
29
+ await model.open();
30
+ setModel(model);
31
+ });
32
+
33
+ return () => {
34
+ clearTimeout(t);
35
+ void model?.close();
36
+ };
37
+ }, [graph, sheet, readonly]);
38
+
39
+ return model;
40
+ };
@@ -0,0 +1,40 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { describe, test, expect } from 'vitest';
6
+
7
+ // Part 2.
8
+ // TODO(burdon): Cannot test outside of browser.
9
+ // - Cannot test Hyperformula
10
+ // - throws "Cannot convert undefined or null to object" in vitest (no browser).
11
+ // - throws "process.nextTick is not a function" (if browser)
12
+
13
+ import { Client } from '@dxos/client';
14
+ import { create } from '@dxos/client/echo';
15
+ import { FunctionType } from '@dxos/plugin-script/types';
16
+
17
+ // TODO(burdon): Fix test infrastructure:
18
+ // - Need docs? esp. needed for config. need pristine example package?
19
+ // - NOTE for non browser tests, import types from x-plugin/types (otherwise will bring in react deps).
20
+ // - Can't add flags to our tools?
21
+ // - .only / .skip ignored (have to comment out tests)
22
+
23
+ describe('test', () => {
24
+ test('test', async () => {
25
+ const client = new Client();
26
+ client.addTypes([FunctionType]);
27
+ await client.initialize();
28
+ await client.halo.createIdentity();
29
+
30
+ // Part 1.
31
+ // Create script.
32
+ // VITEST_ENV=chromium p test
33
+ // TODO(burdon): Test after initialize.
34
+ // - ERROR "process.nextTick is not a function"
35
+ // - ERROR "Identifier 'Buffer' has already been declared" if { nodeExternal: true }
36
+ const space = await client.spaces.create();
37
+ const fn = space.db.add(create(FunctionType, { version: 1, binding: 'HELLO' }));
38
+ expect(fn).to.exist;
39
+ });
40
+ });
@@ -0,0 +1,27 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type TypedObjectSerializer } from '@dxos/plugin-space/types';
6
+ import { create, getObjectCore } from '@dxos/react-client/echo';
7
+
8
+ import { SheetType } from './types';
9
+
10
+ export const serializer: TypedObjectSerializer<SheetType> = {
11
+ serialize: async ({ object }): Promise<string> => {
12
+ const { threads: _threads, ...sheet } = object;
13
+ return JSON.stringify(sheet, null, 2);
14
+ },
15
+
16
+ deserialize: async ({ content, newId }) => {
17
+ const { id, ...parsed } = JSON.parse(content);
18
+ const sheet = create(SheetType, parsed);
19
+
20
+ if (!newId) {
21
+ const core = getObjectCore(sheet);
22
+ core.id = id;
23
+ }
24
+
25
+ return sheet;
26
+ },
27
+ };
@@ -2,4 +2,4 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './Sheet';
5
+ export * from './testing';
@@ -0,0 +1,68 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type Decorator } from '@storybook/react';
6
+ import React, { useState } from 'react';
7
+
8
+ import { type Space } from '@dxos/react-client/echo';
9
+ import { useAsyncState } from '@dxos/react-hooks';
10
+
11
+ import { ComputeGraphContextProvider } from '../components';
12
+ import { type ComputeGraph, type ComputeGraphOptions, ComputeGraphRegistry } from '../compute-graph';
13
+ import { createSheet } from '../defs';
14
+ import { type CellValue, type CreateSheetOptions } from '../types';
15
+
16
+ const testSheetName = 'test';
17
+
18
+ export const createTestCells = (): Record<string, CellValue> => ({
19
+ B1: { value: 'Qty2' },
20
+ B3: { value: 1 },
21
+ B4: { value: 2 },
22
+ B5: { value: 3 },
23
+ B7: { value: 'Total' },
24
+
25
+ C1: { value: 'Price' },
26
+ C3: { value: 2_000 },
27
+ C4: { value: 2_500 },
28
+ C5: { value: 3_000 },
29
+ C7: { value: '=SUMPRODUCT(B2:B6, C2:C6)' },
30
+ // C8: { value: '=C7*CRYPTO(D7)' },
31
+ C8: { value: '=C7*TEST()' },
32
+
33
+ D7: { value: 'USD' },
34
+ D8: { value: 'BTC' },
35
+
36
+ E3: { value: '=TODAY()' },
37
+ E4: { value: '=NOW()' },
38
+
39
+ F1: { value: `=${testSheetName}!A1` }, // Ref test sheet.
40
+ F3: { value: true },
41
+ F4: { value: false },
42
+ F5: { value: '8%' },
43
+ F6: { value: '$10000' },
44
+ });
45
+
46
+ export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: CreateSheetOptions) => {
47
+ const [sheet] = useAsyncState(async () => {
48
+ if (!space || !graph) {
49
+ return;
50
+ }
51
+
52
+ const sheet = createSheet(options);
53
+ space.db.add(sheet);
54
+ return sheet;
55
+ }, [space, graph]);
56
+ return sheet;
57
+ };
58
+
59
+ export const withComputeGraphDecorator =
60
+ (options?: ComputeGraphOptions): Decorator =>
61
+ (Story) => {
62
+ const [registry] = useState(new ComputeGraphRegistry(options));
63
+ return (
64
+ <ComputeGraphContextProvider registry={registry}>
65
+ <Story />
66
+ </ComputeGraphContextProvider>
67
+ );
68
+ };