@dxos/plugin-sheet 0.6.12 → 0.6.13-main.548ca8d

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 (325) hide show
  1. package/dist/lib/browser/SheetContainer-NDNIS44E.mjs +265 -0
  2. package/dist/lib/browser/SheetContainer-NDNIS44E.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-AQSGDA4X.mjs +1614 -0
  4. package/dist/lib/browser/chunk-AQSGDA4X.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-D3QTX46O.mjs +14 -0
  6. package/dist/lib/browser/chunk-D3QTX46O.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-GKI67SEF.mjs +69 -0
  8. package/dist/lib/browser/chunk-GKI67SEF.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-GSV5QNLD.mjs +2966 -0
  10. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
  11. package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
  12. package/dist/lib/browser/graph-M4IQ76QX.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +93 -62
  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/types.mjs +4 -10
  18. package/dist/lib/node/SheetContainer-YSQGJD7K.cjs +276 -0
  19. package/dist/lib/node/SheetContainer-YSQGJD7K.cjs.map +7 -0
  20. package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-5XPK2V4A.cjs} +418 -678
  21. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
  22. package/dist/lib/node/chunk-6F43RV45.cjs +1610 -0
  23. package/dist/lib/node/chunk-6F43RV45.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-ER3PM7GD.cjs} +29 -45
  25. package/dist/lib/node/chunk-ER3PM7GD.cjs.map +7 -0
  26. package/dist/lib/node/chunk-QIFIGEKV.cjs +37 -0
  27. package/dist/lib/node/chunk-QIFIGEKV.cjs.map +7 -0
  28. package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
  29. package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +105 -69
  31. package/dist/lib/node/index.cjs.map +3 -3
  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 +8 -14
  36. package/dist/lib/node/types.cjs.map +2 -2
  37. package/dist/lib/node-esm/SheetContainer-M7WRMZDU.mjs +266 -0
  38. package/dist/lib/node-esm/SheetContainer-M7WRMZDU.mjs.map +7 -0
  39. package/dist/lib/{browser/chunk-D5AGLXJP.mjs → node-esm/chunk-5WPZCXNS.mjs} +411 -678
  40. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-ELTFPX5B.mjs +1615 -0
  42. package/dist/lib/node-esm/chunk-ELTFPX5B.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +16 -0
  44. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-ZVLLQ2PJ.mjs +70 -0
  46. package/dist/lib/node-esm/chunk-ZVLLQ2PJ.mjs.map +7 -0
  47. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
  48. package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +7 -0
  49. package/dist/lib/node-esm/index.mjs +280 -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 +11 -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 +9 -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} +4 -4
  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 +16 -0
  74. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
  75. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +6 -0
  76. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
  77. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +11 -0
  78. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
  79. package/dist/types/src/components/SheetContainer/index.d.ts +3 -0
  80. package/dist/types/src/components/SheetContainer/index.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContext/SheetContext.d.ts +27 -0
  82. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -0
  83. package/dist/types/src/components/SheetContext/index.d.ts +2 -0
  84. package/dist/types/src/components/SheetContext/index.d.ts.map +1 -0
  85. package/dist/types/src/components/Toolbar/Toolbar.d.ts +36 -6
  86. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  87. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +19 -14
  88. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  89. package/dist/types/src/components/index.d.ts +3 -2
  90. package/dist/types/src/components/index.d.ts.map +1 -1
  91. package/dist/types/src/defs/index.d.ts +3 -0
  92. package/dist/types/src/defs/index.d.ts.map +1 -0
  93. package/dist/types/src/{model → defs}/types.d.ts +8 -3
  94. package/dist/types/src/defs/types.d.ts.map +1 -0
  95. package/dist/types/src/defs/types.test.d.ts.map +1 -0
  96. package/dist/types/src/defs/util.d.ts +43 -0
  97. package/dist/types/src/defs/util.d.ts.map +1 -0
  98. package/dist/types/src/extensions/compute.d.ts +6 -0
  99. package/dist/types/src/extensions/compute.d.ts.map +1 -0
  100. package/dist/types/src/extensions/compute.stories.d.ts +26 -0
  101. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
  102. package/dist/types/src/{components/CellEditor → extensions/editor}/extension.d.ts +1 -1
  103. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
  104. package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
  105. package/dist/types/src/extensions/editor/index.d.ts +2 -0
  106. package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
  107. package/dist/types/src/extensions/index.d.ts +3 -0
  108. package/dist/types/src/extensions/index.d.ts.map +1 -0
  109. package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
  110. package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
  111. package/dist/types/src/graph/compute-graph.d.ts +64 -0
  112. package/dist/types/src/graph/compute-graph.d.ts.map +1 -0
  113. package/dist/types/src/graph/compute-graph.stories.d.ts +10 -0
  114. package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -0
  115. package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
  116. package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
  117. package/dist/types/src/graph/compute-node.d.ts +26 -0
  118. package/dist/types/src/graph/compute-node.d.ts.map +1 -0
  119. package/dist/types/src/{components/ComputeGraph → graph/functions}/async-function.d.ts +14 -5
  120. package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
  121. package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
  122. package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
  123. package/dist/types/src/{model/functions.d.ts → graph/functions/function-defs.d.ts} +1 -1
  124. package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
  125. package/dist/types/src/graph/functions/index.d.ts +4 -0
  126. package/dist/types/src/graph/functions/index.d.ts.map +1 -0
  127. package/dist/types/src/graph/hyperformula.test.d.ts +2 -0
  128. package/dist/types/src/graph/hyperformula.test.d.ts.map +1 -0
  129. package/dist/types/src/graph/index.d.ts +5 -0
  130. package/dist/types/src/graph/index.d.ts.map +1 -0
  131. package/dist/types/src/graph/testing/index.d.ts +3 -0
  132. package/dist/types/src/graph/testing/index.d.ts.map +1 -0
  133. package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
  134. package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
  135. package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
  136. package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
  137. package/dist/types/src/graph/util.d.ts +2 -0
  138. package/dist/types/src/graph/util.d.ts.map +1 -0
  139. package/dist/types/src/hooks/hooks.stories.d.ts +11 -0
  140. package/dist/types/src/hooks/hooks.stories.d.ts.map +1 -0
  141. package/dist/types/src/hooks/index.d.ts +5 -0
  142. package/dist/types/src/hooks/index.d.ts.map +1 -0
  143. package/dist/types/src/hooks/threads.d.ts +8 -0
  144. package/dist/types/src/hooks/threads.d.ts.map +1 -0
  145. package/dist/types/src/hooks/useComputeGraph.d.ts +7 -0
  146. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -0
  147. package/dist/types/src/hooks/useFormattingModel.d.ts +3 -0
  148. package/dist/types/src/hooks/useFormattingModel.d.ts.map +1 -0
  149. package/dist/types/src/hooks/useSheetModel.d.ts +8 -0
  150. package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -0
  151. package/dist/types/src/meta.d.ts +3 -9
  152. package/dist/types/src/meta.d.ts.map +1 -1
  153. package/dist/types/src/model/decorations.d.ts +25 -0
  154. package/dist/types/src/model/decorations.d.ts.map +1 -0
  155. package/dist/types/src/model/formatting-model.d.ts +19 -0
  156. package/dist/types/src/model/formatting-model.d.ts.map +1 -0
  157. package/dist/types/src/model/index.d.ts +3 -3
  158. package/dist/types/src/model/index.d.ts.map +1 -1
  159. package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +13 -67
  160. package/dist/types/src/model/sheet-model.d.ts.map +1 -0
  161. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  162. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  163. package/dist/types/src/sanity.test.d.ts +2 -0
  164. package/dist/types/src/sanity.test.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 +17 -12
  170. package/dist/types/src/translations.d.ts.map +1 -1
  171. package/dist/types/src/types.d.ts +98 -32
  172. package/dist/types/src/types.d.ts.map +1 -1
  173. package/dist/vendor/hyperformula.mjs +37145 -0
  174. package/package.json +57 -52
  175. package/src/SheetPlugin.tsx +52 -74
  176. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +20 -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 +41 -0
  181. package/src/components/GridSheet/GridSheet.tsx +161 -0
  182. package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +8 -8
  183. package/src/components/GridSheet/index.ts +5 -0
  184. package/src/components/GridSheet/util.ts +144 -0
  185. package/src/components/SheetContainer/SheetContainer.stories.tsx +40 -0
  186. package/src/components/SheetContainer/SheetContainer.tsx +52 -0
  187. package/src/components/SheetContainer/index.ts +7 -0
  188. package/src/components/SheetContext/SheetContext.tsx +108 -0
  189. package/src/components/SheetContext/index.ts +5 -0
  190. package/src/components/Toolbar/Toolbar.tsx +167 -85
  191. package/src/components/index.ts +2 -0
  192. package/src/defs/index.ts +6 -0
  193. package/src/{model → defs}/types.test.ts +8 -9
  194. package/src/{model → defs}/types.ts +24 -14
  195. package/src/defs/util.ts +151 -0
  196. package/src/extensions/compute.stories.tsx +151 -0
  197. package/src/extensions/compute.ts +147 -0
  198. package/src/{components/CellEditor → extensions/editor}/extension.test.ts +4 -6
  199. package/src/{components/CellEditor → extensions/editor}/extension.ts +5 -6
  200. package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
  201. package/src/extensions/index.ts +6 -0
  202. package/src/graph/compute-graph-registry.ts +90 -0
  203. package/src/graph/compute-graph.stories.tsx +93 -0
  204. package/src/graph/compute-graph.test.ts +87 -0
  205. package/src/graph/compute-graph.ts +242 -0
  206. package/src/graph/compute-node.ts +63 -0
  207. package/src/{components/ComputeGraph → graph/functions}/async-function.ts +25 -15
  208. package/src/{components/ComputeGraph → graph/functions}/edge-function.ts +16 -14
  209. package/src/graph/functions/index.ts +7 -0
  210. package/src/graph/hyperformula.test.ts +14 -0
  211. package/src/graph/index.ts +8 -0
  212. package/src/graph/testing/index.ts +6 -0
  213. package/src/graph/testing/test-builder.ts +54 -0
  214. package/src/{components/ComputeGraph/custom.ts → graph/testing/test-plugin.ts} +44 -14
  215. package/src/graph/util.ts +8 -0
  216. package/src/hooks/hooks.stories.tsx +50 -0
  217. package/src/hooks/index.ts +8 -0
  218. package/src/hooks/threads.ts +147 -0
  219. package/src/hooks/useComputeGraph.ts +28 -0
  220. package/src/hooks/useFormattingModel.ts +11 -0
  221. package/src/hooks/useSheetModel.ts +40 -0
  222. package/src/meta.ts +14 -0
  223. package/src/model/decorations.ts +64 -0
  224. package/src/{components/Sheet/formatting.ts → model/formatting-model.ts} +30 -20
  225. package/src/model/index.ts +3 -3
  226. package/src/model/sheet-model.test.ts +57 -0
  227. package/src/model/sheet-model.ts +418 -0
  228. package/src/sanity.test.ts +40 -0
  229. package/src/{components/Sheet → testing}/index.ts +1 -1
  230. package/src/testing/testing.tsx +68 -0
  231. package/src/translations.ts +6 -1
  232. package/src/types.ts +40 -41
  233. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +0 -1772
  234. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
  235. package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
  236. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
  237. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
  238. package/dist/lib/browser/chunk-FUAGSXA4.mjs +0 -82
  239. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
  240. package/dist/lib/browser/chunk-JRL5LGCE.mjs +0 -18
  241. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
  242. package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
  243. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
  244. package/dist/lib/browser/testing.mjs +0 -92
  245. package/dist/lib/browser/testing.mjs.map +0 -7
  246. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +0 -1765
  247. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
  248. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
  249. package/dist/lib/node/chunk-BJ6ZD7MN.cjs +0 -51
  250. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
  251. package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
  252. package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
  253. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
  254. package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
  255. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
  256. package/dist/lib/node/testing.cjs +0 -111
  257. package/dist/lib/node/testing.cjs.map +0 -7
  258. package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -14
  259. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
  260. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
  261. package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
  262. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
  263. package/dist/types/src/components/CellEditor/index.d.ts +0 -3
  264. package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
  265. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
  266. package/dist/types/src/components/ComputeGraph/custom.d.ts +0 -21
  267. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
  268. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +0 -20
  269. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
  270. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
  271. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
  272. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
  273. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
  274. package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
  275. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
  276. package/dist/types/src/components/Sheet/Sheet.d.ts +0 -55
  277. package/dist/types/src/components/Sheet/Sheet.d.ts.map +0 -1
  278. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +0 -54
  279. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
  280. package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
  281. package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
  282. package/dist/types/src/components/Sheet/grid.d.ts +0 -52
  283. package/dist/types/src/components/Sheet/grid.d.ts.map +0 -1
  284. package/dist/types/src/components/Sheet/index.d.ts +0 -2
  285. package/dist/types/src/components/Sheet/index.d.ts.map +0 -1
  286. package/dist/types/src/components/Sheet/nav.d.ts +0 -29
  287. package/dist/types/src/components/Sheet/nav.d.ts.map +0 -1
  288. package/dist/types/src/components/Sheet/sheet-context.d.ts +0 -25
  289. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
  290. package/dist/types/src/components/Sheet/util.d.ts +0 -18
  291. package/dist/types/src/components/Sheet/util.d.ts.map +0 -1
  292. package/dist/types/src/components/SheetContainer.d.ts +0 -9
  293. package/dist/types/src/components/SheetContainer.d.ts.map +0 -1
  294. package/dist/types/src/components/Toolbar/common.d.ts +0 -20
  295. package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
  296. package/dist/types/src/model/functions.d.ts.map +0 -1
  297. package/dist/types/src/model/model.browser.test.d.ts +0 -2
  298. package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
  299. package/dist/types/src/model/model.d.ts.map +0 -1
  300. package/dist/types/src/model/types.d.ts.map +0 -1
  301. package/dist/types/src/model/types.test.d.ts.map +0 -1
  302. package/dist/types/src/model/util.d.ts +0 -15
  303. package/dist/types/src/model/util.d.ts.map +0 -1
  304. package/dist/types/src/testing.d.ts +0 -9
  305. package/dist/types/src/testing.d.ts.map +0 -1
  306. package/src/components/CellEditor/CellEditor.tsx +0 -113
  307. package/src/components/ComputeGraph/graph-context.tsx +0 -50
  308. package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
  309. package/src/components/ComputeGraph/graph.ts +0 -62
  310. package/src/components/Sheet/Sheet.stories.tsx +0 -287
  311. package/src/components/Sheet/Sheet.tsx +0 -1160
  312. package/src/components/Sheet/grid.ts +0 -191
  313. package/src/components/Sheet/nav.ts +0 -157
  314. package/src/components/Sheet/sheet-context.tsx +0 -150
  315. package/src/components/Sheet/util.ts +0 -56
  316. package/src/components/SheetContainer.tsx +0 -34
  317. package/src/components/Toolbar/common.tsx +0 -72
  318. package/src/meta.tsx +0 -18
  319. package/src/model/model.browser.test.ts +0 -100
  320. package/src/model/model.ts +0 -550
  321. package/src/model/util.ts +0 -36
  322. package/src/testing.ts +0 -50
  323. /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
  324. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
  325. /package/src/{model/functions.ts → graph/functions/function-defs.ts} +0 -0
@@ -0,0 +1,242 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type Listeners } from 'hyperformula/typings/Emitter';
6
+
7
+ import { Event } from '@dxos/async';
8
+ import { type Space, Filter, fullyQualifiedId } from '@dxos/client/echo';
9
+ import { Resource } from '@dxos/context';
10
+ import { getTypename } from '@dxos/echo-schema';
11
+ import { invariant } from '@dxos/invariant';
12
+ import { PublicKey } from '@dxos/keys';
13
+ import { log } from '@dxos/log';
14
+ import { FunctionType } from '@dxos/plugin-script/types';
15
+ import { nonNullable } from '@dxos/util';
16
+
17
+ import { ExportedCellChange, type HyperFormula } from '#hyperformula';
18
+ import { ComputeNode } from './compute-node';
19
+ import {
20
+ defaultFunctions,
21
+ FunctionContext,
22
+ type FunctionContextOptions,
23
+ type FunctionDefinition,
24
+ EDGE_FUNCTION_NAME,
25
+ } from './functions';
26
+
27
+ // TODO(wittjosiah): Factor out.
28
+ const OBJECT_ID_LENGTH = 60; // 33 (space id) + 1 (separator) + 26 (object id).
29
+
30
+ // TODO(burdon): Factory.
31
+ // export type ComputeNodeGenerator = <T>(obj: T) => ComputeNode;
32
+
33
+ type ObjectRef = { type: string; id: string };
34
+
35
+ /**
36
+ * Marker for sheets that are managed by an ECHO object.
37
+ * Sheet ID: `dxos.org/type/SheetType@1234`
38
+ */
39
+ export const createSheetName = ({ type, id }: ObjectRef) => `${type}@${id}`;
40
+ export const parseSheetName = (name: string): Partial<ObjectRef> => {
41
+ const [type, id] = name.split('@');
42
+ return id ? { type, id } : { id: type };
43
+ };
44
+
45
+ export type ComputeGraphEvent = 'functionsUpdated';
46
+
47
+ /**
48
+ * Per-space compute and dependency graph.
49
+ * Consists of multiple ComputeNode (corresponding to a HyperFormula sheet).
50
+ * Manages the set of custom functions.
51
+ * HyperFormula manages the dependency graph.
52
+ */
53
+ export class ComputeGraph extends Resource {
54
+ public readonly id = `graph-${PublicKey.random().truncate()}`;
55
+
56
+ // Map of nodes indexed by sheet number.
57
+ private readonly _nodes = new Map<number, ComputeNode>();
58
+
59
+ // Cached function objects.
60
+ private _remoteFunctions: FunctionType[] = [];
61
+
62
+ public readonly update = new Event<{ type: ComputeGraphEvent }>();
63
+
64
+ // The context is passed to all functions.
65
+ public readonly context = new FunctionContext(this._hf, this._space, this._options);
66
+
67
+ constructor(
68
+ private readonly _hf: HyperFormula,
69
+ private readonly _space?: Space,
70
+ private readonly _options?: Partial<FunctionContextOptions>,
71
+ ) {
72
+ super();
73
+ this._hf.updateConfig({ context: this.context });
74
+ // TODO(burdon): If debounce then aggregate changes.
75
+ const onValuesUpdate: Listeners['valuesUpdated'] = (changes) => {
76
+ for (const change of changes) {
77
+ if (change instanceof ExportedCellChange) {
78
+ const { sheet } = change;
79
+ const node = this._nodes.get(sheet);
80
+ if (node) {
81
+ node.update.emit({ type: 'valuesUpdated', change });
82
+ }
83
+ }
84
+ }
85
+ };
86
+
87
+ this._hf.on('valuesUpdated', onValuesUpdate);
88
+ this._ctx.onDispose(() => this._hf.off('valuesUpdated', onValuesUpdate));
89
+ }
90
+
91
+ get hf() {
92
+ return this._hf;
93
+ }
94
+
95
+ getFunctions(
96
+ { standard, echo }: { standard?: boolean; echo?: boolean } = { standard: true, echo: true },
97
+ ): FunctionDefinition[] {
98
+ return [
99
+ ...(standard
100
+ ? this._hf
101
+ .getRegisteredFunctionNames()
102
+ .map((name) => defaultFunctions.find((fn) => fn.name === name) ?? { name })
103
+ : []),
104
+ ...(echo ? this._remoteFunctions.map((fn) => ({ name: fn.binding! })) : []),
105
+ ];
106
+ }
107
+
108
+ /**
109
+ * Get or create cell representing a sheet.
110
+ */
111
+ // TODO(burdon): Async (open node).
112
+ // The graph should be an extensible factory that plugins extend with model constructors.
113
+ // This would enable on-the-fly instantiation of new models when then are referenced.
114
+ // E.g., Cross-object reference would be stored as "ObjectId!A1"
115
+ // The graph would then load the object and create a ComputeNode (model) of the appropriate type.
116
+ getOrCreateNode(name: string): ComputeNode {
117
+ invariant(name.length);
118
+ if (!this._hf.doesSheetExist(name)) {
119
+ log.info('created node', { space: this._space?.id, sheet: name });
120
+ this._hf.addSheet(name);
121
+ }
122
+
123
+ const sheetId = this._hf.getSheetId(name);
124
+ invariant(sheetId !== undefined);
125
+
126
+ const node = new ComputeNode(this, sheetId);
127
+ this._nodes.set(sheetId, node);
128
+ return node;
129
+ }
130
+
131
+ /**
132
+ * Map bound value to custom function invocation.
133
+ * E.g., "HELLO(...args)" => "EDGE("HELLO", ...args)".
134
+ */
135
+ mapFormulaToNative(formula: string): string {
136
+ return (
137
+ formula
138
+ //
139
+ // Map cross-sheet references by name onto sheet stored by ECHO object/model.
140
+ // Example: "Test Sheet"!A0 => "dxos.org/type/SheetType@1234"!A0
141
+ // https://hyperformula.handsontable.com/guide/cell-references.html#cell-references
142
+ //
143
+ .replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
144
+ if (name) {
145
+ // TODO(burdon): Cache map.
146
+ const objects = this._hf
147
+ .getSheetNames()
148
+ .map((name) => {
149
+ const { type, id } = parseSheetName(name);
150
+ return type && id ? this._space?.db.getObjectById(id) : undefined;
151
+ })
152
+ .filter(nonNullable);
153
+
154
+ for (const obj of objects) {
155
+ if (obj.name === name) {
156
+ const type = getTypename(obj)!;
157
+ // NOTE: Names must be single quoted.
158
+ return `'${createSheetName({ type, id: obj.id })}'!`;
159
+ }
160
+ }
161
+ }
162
+
163
+ return `${name}!`;
164
+ })
165
+
166
+ //
167
+ // Map remote function references (i.e., to remote DX function invocation).
168
+ //
169
+ .replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
170
+ const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
171
+ if (!fn) {
172
+ return match;
173
+ }
174
+
175
+ if (args.trim() === '') {
176
+ return `${EDGE_FUNCTION_NAME}("${binding}")`;
177
+ } else {
178
+ return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
179
+ }
180
+ })
181
+ );
182
+ }
183
+
184
+ /**
185
+ * Map from binding to fully qualified ECHO ID (to store).
186
+ * E.g., HELLO() => spaceId:objectId()
187
+ */
188
+ mapFunctionBindingToId(formula: string) {
189
+ return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
190
+ if (binding === EDGE_FUNCTION_NAME || defaultFunctions.find((fn) => fn.name === binding)) {
191
+ return match;
192
+ }
193
+
194
+ const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
195
+ if (fn) {
196
+ const id = fullyQualifiedId(fn);
197
+ return `${id}(${args})`;
198
+ } else {
199
+ return match;
200
+ }
201
+ });
202
+ }
203
+
204
+ /**
205
+ * Map from fully qualified ECHO ID to binding (from store).
206
+ * E.g., spaceId:objectId() => HELLO()
207
+ */
208
+ mapFunctionBindingFromId(formula: string) {
209
+ return formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
210
+ const id = `${spaceId}:${objectId}`;
211
+ if (id.length !== OBJECT_ID_LENGTH) {
212
+ return match;
213
+ }
214
+
215
+ const fn = this._remoteFunctions.find((fn) => fullyQualifiedId(fn) === id);
216
+ if (fn?.binding) {
217
+ return `${fn.binding}(${args})`;
218
+ } else {
219
+ return match;
220
+ }
221
+ });
222
+ }
223
+
224
+ protected override async _open() {
225
+ if (this._space) {
226
+ // Subscribe to remote function definitions.
227
+ const query = this._space.db.query(Filter.schema(FunctionType));
228
+ const unsubscribe = query.subscribe(({ objects }) => {
229
+ this._remoteFunctions = objects.filter(({ binding }) => binding);
230
+ this.update.emit({ type: 'functionsUpdated' });
231
+ });
232
+
233
+ this._ctx.onDispose(unsubscribe);
234
+ }
235
+ }
236
+
237
+ protected override async _close() {
238
+ for (const node of this._nodes.values()) {
239
+ await node.close();
240
+ }
241
+ }
242
+ }
@@ -0,0 +1,63 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type Listeners } from 'hyperformula/typings/Emitter';
6
+ import { type ExportedCellChange } from 'hyperformula/typings/Exporter';
7
+
8
+ import { Event } from '@dxos/async';
9
+ import { Resource } from '@dxos/context';
10
+
11
+ import { DetailedCellError } from '#hyperformula';
12
+ import { type ComputeGraph } from './compute-graph';
13
+ import { type CellAddress } from '../defs';
14
+ import { type CellScalarValue } from '../types';
15
+
16
+ export type ComputeNodeEvent = {
17
+ type: keyof Listeners;
18
+ change?: ExportedCellChange;
19
+ };
20
+
21
+ /**
22
+ * Individual "sheet" (typically corresponds to an ECHO object).
23
+ */
24
+ // TODO(burdon): Factor out common HF wrapper from from SheetModel.
25
+ export class ComputeNode extends Resource {
26
+ public readonly update = new Event<ComputeNodeEvent>();
27
+
28
+ constructor(
29
+ private readonly _graph: ComputeGraph,
30
+ public readonly sheetId: number,
31
+ ) {
32
+ super();
33
+ }
34
+
35
+ get graph() {
36
+ return this._graph;
37
+ }
38
+
39
+ clear() {
40
+ this._graph.hf.clearSheet(this.sheetId);
41
+ }
42
+
43
+ getValue(cell: CellAddress): CellScalarValue {
44
+ const value = this._graph.hf.getCellValue({ sheet: this.sheetId, row: cell.row, col: cell.col });
45
+ if (value instanceof DetailedCellError) {
46
+ return null;
47
+ }
48
+
49
+ return value;
50
+ }
51
+
52
+ setValue(cell: CellAddress, value: CellScalarValue) {
53
+ const mappedValue =
54
+ typeof value === 'string' && value.charAt(0) === '=' ? this._graph.mapFormulaToNative(value) : value;
55
+ this._graph.hf.setCellContents({ sheet: this.sheetId, row: cell.row, col: cell.col }, [[mappedValue]]);
56
+ }
57
+
58
+ // TODO(burdon): Load data into sheet.
59
+ protected override async _open() {
60
+ // const unsubscribe = this._graph.update.on(this.update.emit);
61
+ // this._ctx.onDispose(unsubscribe);
62
+ }
63
+ }
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { CellError, ErrorType, EmptyValue, FunctionPlugin, type HyperFormula } from 'hyperformula';
5
+ import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
6
6
  import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
7
7
  import { type InterpreterValue } from 'hyperformula/typings/interpreter/InterpreterValue';
8
8
  import { type ProcedureAst } from 'hyperformula/typings/parser';
@@ -12,28 +12,35 @@ import { debounce, type UnsubscribeCallback } from '@dxos/async';
12
12
  import { type Space } from '@dxos/client/echo';
13
13
  import { log } from '@dxos/log';
14
14
 
15
- // TODO(burdon): API gateways!
15
+ import { CellError, ErrorType, EmptyValue, FunctionPlugin, type HyperFormula } from '#hyperformula';
16
+
17
+ // TODO(burdon): Create API gateways:
16
18
  // https://publicapis.io
17
19
  // https://api-ninjas.com/api/cryptoprice
18
20
  // https://developers.google.com/apis-explorer
19
21
  // https://publicapis.io/coin-desk-api
20
22
 
21
- // TODO(burdon): Create wrapper.
22
23
  export type AsyncFunction = (...args: any) => Promise<InterpreterValue>;
23
24
 
25
+ export type FunctionUpdateEvent = {
26
+ name: string;
27
+ cell: SimpleCellAddress;
28
+ };
29
+
24
30
  export type FunctionOptions = {
25
31
  ttl?: number;
26
32
  };
27
33
 
28
34
  export type FunctionContextOptions = {
29
35
  defaultTtl: number;
30
- recalculationDelay: number;
36
+ debounceDelay: number;
31
37
  remoteFunctionUrl: string;
38
+ onUpdate?: (update: FunctionUpdateEvent) => void;
32
39
  };
33
40
 
34
41
  export const defaultFunctionContextOptions: FunctionContextOptions = {
35
42
  defaultTtl: 5_000,
36
- recalculationDelay: 200,
43
+ debounceDelay: 200,
37
44
  remoteFunctionUrl: 'https://edge.dxos.workers.dev/functions', // TODO(burdon): Config.
38
45
  };
39
46
 
@@ -65,21 +72,21 @@ export class FunctionContext {
65
72
  private _invocations: Record<string, number> = {};
66
73
 
67
74
  private readonly _options: FunctionContextOptions;
68
- private readonly _onUpdate: () => void;
75
+
76
+ // Debounced update handler.
77
+ private readonly _onUpdate: (update: FunctionUpdateEvent) => void;
69
78
 
70
79
  constructor(
71
80
  private readonly _hf: HyperFormula,
72
81
  private readonly _space: Space | undefined,
73
- onUpdate: (context: FunctionContext) => void,
74
82
  _options?: Partial<FunctionContextOptions>,
75
83
  ) {
76
84
  this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
77
- this._onUpdate = debounce(() => {
78
- // TODO(burdon): Better way to trigger recalculation?
79
- // NOTE: rebuildAndRecalculate resets the undo history.
85
+ this._onUpdate = debounce((update) => {
86
+ // TODO(burdon): Better way to trigger recalculation? (NOTE: rebuildAndRecalculate resets the undo history.)
80
87
  this._hf.resumeEvaluation();
81
- onUpdate(this);
82
- }, this._options.recalculationDelay);
88
+ this._options.onUpdate?.(update);
89
+ }, this._options.debounceDelay);
83
90
  }
84
91
 
85
92
  get space() {
@@ -134,7 +141,7 @@ export class FunctionContext {
134
141
  const value = await cb(...args);
135
142
  this._cache.set(invocationKey, { value, ts: Date.now() });
136
143
  log('set', { cell, value });
137
- this._onUpdate();
144
+ this._onUpdate({ name, cell });
138
145
  } catch (err) {
139
146
  // TODO(burdon): Show error to user.
140
147
  log.warn('failed', { cell, err });
@@ -153,12 +160,15 @@ export class FunctionContext {
153
160
  /**
154
161
  * Base class for async functions.
155
162
  */
156
- export class FunctionPluginAsync extends FunctionPlugin {
163
+ export class AsyncFunctionPlugin extends FunctionPlugin {
157
164
  get context() {
158
165
  return this.config.context as FunctionContext;
159
166
  }
160
167
 
161
- runAsyncFunction(ast: ProcedureAst, state: InterpreterState, cb: AsyncFunction, options?: FunctionOptions) {
168
+ /**
169
+ * Immediately returns cached value then runs the async function.
170
+ */
171
+ protected runAsyncFunction(ast: ProcedureAst, state: InterpreterState, cb: AsyncFunction, options?: FunctionOptions) {
162
172
  const { procedureName } = ast;
163
173
  const metadata = this.metadata(procedureName);
164
174
  return this.runFunction(ast.args, state, metadata, (...args: any) => {
@@ -3,7 +3,6 @@
3
3
  //
4
4
 
5
5
  import { effect } from '@preact/signals-core';
6
- import { CellError, ErrorType, FunctionArgumentType } from 'hyperformula';
7
6
  import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
8
7
  import { type ProcedureAst } from 'hyperformula/typings/parser';
9
8
 
@@ -13,17 +12,20 @@ import { getUserFunctionUrlInMetadata } from '@dxos/plugin-script/edge';
13
12
  import { FunctionType } from '@dxos/plugin-script/types';
14
13
  import { nonNullable } from '@dxos/util';
15
14
 
16
- import { type AsyncFunction, FunctionPluginAsync } from './async-function';
15
+ import { CellError, ErrorType, FunctionArgumentType } from '#hyperformula';
16
+ import { type AsyncFunction, AsyncFunctionPlugin } from './async-function';
17
17
 
18
- const EDGE_FUNCTION_TTL = 10_000;
18
+ export const EDGE_FUNCTION_NAME = 'DX';
19
+
20
+ const FUNCTION_TTL = 10_000;
19
21
 
20
22
  /**
21
- * A hyperformula function plugin for calling EDGE functions.
23
+ * A hyperformula function plugin for calling remote (EDGE) functions.
22
24
  *
23
25
  * https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
24
26
  */
25
- export class EdgeFunctionPlugin extends FunctionPluginAsync {
26
- edge(ast: ProcedureAst, state: InterpreterState) {
27
+ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
28
+ dx(ast: ProcedureAst, state: InterpreterState) {
27
29
  const handler =
28
30
  (subscribe = false): AsyncFunction =>
29
31
  async (binding: string, ...args: any) => {
@@ -47,7 +49,7 @@ export class EdgeFunctionPlugin extends FunctionPluginAsync {
47
49
 
48
50
  // TODO(wittjosiah): `ttl` should be 0 to force a recalculation when a new version is deployed.
49
51
  // This needs a ttl to prevent a binding change from causing the function not to be found.
50
- this.runAsyncFunction(ast, state, handler(false), { ttl: EDGE_FUNCTION_TTL });
52
+ this.runAsyncFunction(ast, state, handler(false), { ttl: FUNCTION_TTL });
51
53
  });
52
54
 
53
55
  this.context.createSubscription(ast.procedureName, unsubscribe);
@@ -59,22 +61,22 @@ export class EdgeFunctionPlugin extends FunctionPluginAsync {
59
61
  headers: { 'Content-Type': 'application/json' },
60
62
  body: JSON.stringify({ args: args.filter(nonNullable) }),
61
63
  });
64
+
62
65
  return await result.text();
63
66
  };
64
67
 
65
- return this.runAsyncFunction(ast, state, handler(true), { ttl: EDGE_FUNCTION_TTL });
68
+ return this.runAsyncFunction(ast, state, handler(true), { ttl: FUNCTION_TTL });
66
69
  }
67
70
  }
68
71
 
69
72
  EdgeFunctionPlugin.implementedFunctions = {
70
- EDGE: {
71
- method: 'edge',
73
+ [EDGE_FUNCTION_NAME]: {
74
+ method: 'dx',
72
75
  parameters: [
73
76
  // Binding
74
77
  { argumentType: FunctionArgumentType.STRING },
75
78
 
76
- // Remote function arguments (currently supporting up to 9).
77
- { argumentType: FunctionArgumentType.ANY, optionalArg: true },
79
+ // Remote function arguments (currently supporting up to 8).
78
80
  { argumentType: FunctionArgumentType.ANY, optionalArg: true },
79
81
  { argumentType: FunctionArgumentType.ANY, optionalArg: true },
80
82
  { argumentType: FunctionArgumentType.ANY, optionalArg: true },
@@ -90,9 +92,9 @@ EdgeFunctionPlugin.implementedFunctions = {
90
92
 
91
93
  export const EdgeFunctionPluginTranslations = {
92
94
  enGB: {
93
- EDGE: 'EDGE',
95
+ [EDGE_FUNCTION_NAME]: 'Remote function',
94
96
  },
95
97
  enUS: {
96
- EDGE: 'EDGE',
98
+ [EDGE_FUNCTION_NAME]: 'Remote function',
97
99
  },
98
100
  };
@@ -0,0 +1,7 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './async-function';
6
+ export * from './edge-function';
7
+ export * from './function-defs';
@@ -0,0 +1,14 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { describe, test, expect } from 'vitest';
6
+
7
+ import { HyperFormula } from '#hyperformula';
8
+
9
+ describe('hyperformula', () => {
10
+ test('sanity test', async () => {
11
+ const hf = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' });
12
+ expect(hf).to.exist;
13
+ });
14
+ });
@@ -0,0 +1,8 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './compute-graph';
6
+ export * from './compute-graph-registry';
7
+ export * from './compute-node';
8
+ export * from './functions';
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ export * from './test-builder';
6
+ export * from './test-plugin';
@@ -0,0 +1,54 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Client, type ClientOptions } from '@dxos/client';
6
+ import { type Context, Resource } from '@dxos/context';
7
+ import { invariant } from '@dxos/invariant';
8
+
9
+ import { type ComputeGraphOptions, ComputeGraphRegistry } from '../compute-graph-registry';
10
+
11
+ export type TestBuilderOptions = ClientOptions & ComputeGraphOptions;
12
+
13
+ // TODO(burdon): Reconcile with @dxos/client/testing.
14
+ export class TestBuilder extends Resource {
15
+ private _client?: Client;
16
+ private _registry?: ComputeGraphRegistry;
17
+
18
+ constructor(private readonly _options: TestBuilderOptions = {}) {
19
+ super();
20
+ }
21
+
22
+ get ctx(): Context {
23
+ return this._ctx;
24
+ }
25
+
26
+ get client(): Client {
27
+ invariant(this._client);
28
+ return this._client;
29
+ }
30
+
31
+ get registry(): ComputeGraphRegistry {
32
+ invariant(this._registry);
33
+ return this._registry;
34
+ }
35
+
36
+ override async _open() {
37
+ const client = new Client(this._options);
38
+ await client.initialize();
39
+ await client.halo.createIdentity();
40
+ this._client = client;
41
+ this._ctx.onDispose(async () => {
42
+ await client.destroy();
43
+ this._client = undefined;
44
+ });
45
+
46
+ const registry = new ComputeGraphRegistry(this._options);
47
+ await registry.open();
48
+ this._registry = registry;
49
+ this._ctx.onDispose(async () => {
50
+ await registry.close();
51
+ this._registry = undefined;
52
+ });
53
+ }
54
+ }
@@ -2,24 +2,36 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { FunctionArgumentType } from 'hyperformula';
6
5
  import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
7
6
  import { type ProcedureAst } from 'hyperformula/typings/parser';
8
7
 
9
8
  import { getDeep } from '@dxos/util';
10
9
 
11
- import { type AsyncFunction, FunctionPluginAsync } from './async-function';
12
-
13
- // TODO(burdon): Factor out.
14
- const parseNumberString = (str: string): number => {
15
- return parseFloat(str.replace(/[^\d.]/g, ''));
16
- };
10
+ import { FunctionArgumentType } from '#hyperformula';
11
+ import { type ComputeGraphPlugin } from '../compute-graph-registry';
12
+ import { type AsyncFunction, AsyncFunctionPlugin } from '../functions';
13
+ import { parseNumberString } from '../util';
17
14
 
18
15
  /**
16
+ * Testing functions run locally (not run via EDGE).
19
17
  * https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
20
18
  */
21
- export class CustomPlugin extends FunctionPluginAsync {
19
+ export class TestPlugin extends AsyncFunctionPlugin {
20
+ /**
21
+ * Simple local function returns input value.
22
+ */
22
23
  test(ast: ProcedureAst, state: InterpreterState) {
24
+ const handler: AsyncFunction = async (_value) => {
25
+ return _value;
26
+ };
27
+
28
+ return this.runAsyncFunction(ast, state, handler);
29
+ }
30
+
31
+ /**
32
+ * Simple local function returns random number.
33
+ */
34
+ random(ast: ProcedureAst, state: InterpreterState) {
23
35
  const handler: AsyncFunction = async () => {
24
36
  return Math.random();
25
37
  };
@@ -27,6 +39,9 @@ export class CustomPlugin extends FunctionPluginAsync {
27
39
  return this.runAsyncFunction(ast, state, handler);
28
40
  }
29
41
 
42
+ /**
43
+ * Async HTTP function.
44
+ */
30
45
  crypto(ast: ProcedureAst, state: InterpreterState) {
31
46
  const handler: AsyncFunction = async (_currency) => {
32
47
  const currency = (_currency || 'USD').toUpperCase();
@@ -44,9 +59,15 @@ export class CustomPlugin extends FunctionPluginAsync {
44
59
  }
45
60
  }
46
61
 
47
- CustomPlugin.implementedFunctions = {
62
+ TestPlugin.implementedFunctions = {
48
63
  TEST: {
49
64
  method: 'test',
65
+ parameters: [{ argumentType: FunctionArgumentType.NUMBER, optionalArg: false }],
66
+ isVolatile: true,
67
+ },
68
+
69
+ RANDOM: {
70
+ method: 'random',
50
71
  parameters: [],
51
72
  isVolatile: true,
52
73
  },
@@ -58,13 +79,22 @@ CustomPlugin.implementedFunctions = {
58
79
  },
59
80
  };
60
81
 
61
- export const CustomPluginTranslations = {
82
+ export const TestPluginTranslations = {
62
83
  enGB: {
63
- TEST: 'TEST',
64
- CRYPTO: 'CRYPTO',
84
+ TEST: 'Returns input value',
85
+ RANDOM: 'Random number',
86
+ CRYPTO: 'Crypto token value',
65
87
  },
66
88
  enUS: {
67
- TEST: 'TEST',
68
- CRYPTO: 'CRYPTO',
89
+ TEST: 'Returns input value',
90
+ RANDOM: 'Random number',
91
+ CRYPTO: 'Crypto token value',
69
92
  },
70
93
  };
94
+
95
+ export const testFunctionPlugins: ComputeGraphPlugin[] = [
96
+ {
97
+ plugin: TestPlugin,
98
+ translations: TestPluginTranslations,
99
+ },
100
+ ];