@dxos/plugin-sheet 0.6.13 → 0.6.14-staging.9e90729

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-JBB7W52Y.mjs +280 -0
  2. package/dist/lib/browser/SheetContainer-JBB7W52Y.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-D5AGLXJP.mjs → chunk-2ZK3YMZG.mjs} +621 -675
  4. package/dist/lib/browser/chunk-2ZK3YMZG.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-3QWIMZZJ.mjs +65 -0
  6. package/dist/lib/browser/chunk-3QWIMZZJ.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-D3QTX46O.mjs +14 -0
  8. package/dist/lib/browser/chunk-D3QTX46O.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-XXDHBYZQ.mjs +1455 -0
  10. package/dist/lib/browser/chunk-XXDHBYZQ.mjs.map +7 -0
  11. package/dist/lib/browser/compute-graph-ZQKB6QVP.mjs +35 -0
  12. package/dist/lib/browser/compute-graph-ZQKB6QVP.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +139 -65
  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-L37HUFCF.cjs +286 -0
  19. package/dist/lib/node/SheetContainer-L37HUFCF.cjs.map +7 -0
  20. package/dist/lib/node/chunk-7AWAC3R3.cjs +1441 -0
  21. package/dist/lib/node/chunk-7AWAC3R3.cjs.map +7 -0
  22. package/dist/lib/node/chunk-QIFIGEKV.cjs +37 -0
  23. package/dist/lib/node/chunk-QIFIGEKV.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-QNFMTK3X.cjs} +638 -674
  25. package/dist/lib/node/chunk-QNFMTK3X.cjs.map +7 -0
  26. package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-V7E5JZBD.cjs} +31 -51
  27. package/dist/lib/node/chunk-V7E5JZBD.cjs.map +7 -0
  28. package/dist/lib/node/compute-graph-RJB6OVW6.cjs +57 -0
  29. package/dist/lib/node/compute-graph-RJB6OVW6.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +148 -73
  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-CLKFEM35.mjs +281 -0
  38. package/dist/lib/node-esm/SheetContainer-CLKFEM35.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-3JYJEOCF.mjs +1456 -0
  40. package/dist/lib/node-esm/chunk-3JYJEOCF.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-JBTORSST.mjs +3182 -0
  42. package/dist/lib/node-esm/chunk-JBTORSST.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-SPQFLYC2.mjs +66 -0
  44. package/dist/lib/node-esm/chunk-SPQFLYC2.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +16 -0
  46. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +7 -0
  47. package/dist/lib/node-esm/compute-graph-VKRG526N.mjs +36 -0
  48. package/dist/lib/node-esm/compute-graph-VKRG526N.mjs.map +7 -0
  49. package/dist/lib/node-esm/index.mjs +323 -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 +16 -0
  74. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
  75. package/dist/types/src/components/RangeList/RangeList.d.ts +9 -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 +6 -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 +33 -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 +5 -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 +8 -0
  150. package/dist/types/src/integrations/thread-ranges.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/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} +13 -67
  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 +23 -12
  170. package/dist/types/src/translations.d.ts.map +1 -1
  171. package/dist/types/src/types.d.ts +100 -41
  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 +69 -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 +296 -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 +164 -0
  185. package/src/components/RangeList/RangeList.tsx +38 -0
  186. package/src/components/RangeList/index.ts +5 -0
  187. package/src/components/SheetContainer/SheetContainer.stories.tsx +43 -0
  188. package/src/components/SheetContainer/SheetContainer.tsx +27 -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 +240 -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 +245 -0
  199. package/src/compute-graph/compute-node.ts +62 -0
  200. package/src/{components/ComputeGraph → compute-graph/functions}/async-function.ts +25 -15
  201. package/src/{components/ComputeGraph → compute-graph/functions}/edge-function.ts +16 -14
  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 +47 -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 +135 -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 +14 -0
  224. package/src/model/index.ts +2 -3
  225. package/src/model/sheet-model.test.ts +57 -0
  226. package/src/model/sheet-model.ts +423 -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 +12 -1
  233. package/src/types.ts +41 -46
  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,90 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import type { FunctionPluginDefinition } from 'hyperformula';
6
+ import type { ConfigParams } from 'hyperformula/typings/ConfigParams';
7
+ import type { FunctionTranslationsPackage } from 'hyperformula/typings/interpreter';
8
+ import defaultsDeep from 'lodash.defaultsdeep';
9
+
10
+ import { type SpaceId, type Space } from '@dxos/client/echo';
11
+ import { Resource } from '@dxos/context';
12
+ import { invariant } from '@dxos/invariant';
13
+ import { log } from '@dxos/log';
14
+
15
+ import { HyperFormula } from '#hyperformula';
16
+ import { ComputeGraph } from './compute-graph';
17
+ import { EdgeFunctionPlugin, EdgeFunctionPluginTranslations, type FunctionContextOptions } from './functions';
18
+
19
+ export type ComputeGraphPlugin = {
20
+ plugin: FunctionPluginDefinition;
21
+ translations: FunctionTranslationsPackage;
22
+ };
23
+
24
+ export type ComputeGraphOptions = {
25
+ plugins?: ComputeGraphPlugin[];
26
+ } & Partial<FunctionContextOptions> &
27
+ Partial<ConfigParams>;
28
+
29
+ export const defaultOptions: ComputeGraphOptions = {
30
+ licenseKey: 'gpl-v3',
31
+ };
32
+
33
+ export const defaultPlugins: ComputeGraphPlugin[] = [
34
+ {
35
+ plugin: EdgeFunctionPlugin,
36
+ translations: EdgeFunctionPluginTranslations,
37
+ },
38
+ ];
39
+
40
+ /**
41
+ * Manages a collection of ComputeGraph instances for each space.
42
+ *
43
+ * [ComputePlugin] => [ComputeGraphRegistry] => [ComputeGraph(Space)] => [ComputeNode(Object)]
44
+ *
45
+ * NOTE: The ComputeGraphRegistry manages the hierarchy of resources via its root Context.
46
+ * NOTE: The package.json file defines the packaged #hyperformula module.
47
+ */
48
+ // TODO(burdon): Move graph into separate plugin; isolate HF deps.
49
+ export class ComputeGraphRegistry extends Resource {
50
+ private readonly _graphs = new Map<SpaceId, ComputeGraph>();
51
+
52
+ private readonly _options: ComputeGraphOptions;
53
+
54
+ constructor(options: ComputeGraphOptions = { plugins: defaultPlugins }) {
55
+ super();
56
+ this._options = defaultsDeep({}, options, defaultOptions);
57
+ this._options.plugins?.forEach(({ plugin, translations }) => {
58
+ HyperFormula.registerFunctionPlugin(plugin, translations);
59
+ });
60
+ }
61
+
62
+ getGraph(spaceId: SpaceId): ComputeGraph | undefined {
63
+ return this._graphs.get(spaceId);
64
+ }
65
+
66
+ getOrCreateGraph(space: Space): ComputeGraph {
67
+ let graph = this._graphs.get(space.id);
68
+ if (!graph) {
69
+ log('create graph', { space: space.id });
70
+ graph = this.createGraph(space);
71
+ }
72
+
73
+ return graph;
74
+ }
75
+
76
+ createGraph(space: Space): ComputeGraph {
77
+ invariant(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`);
78
+ const hf = HyperFormula.buildEmpty(this._options);
79
+ const graph = new ComputeGraph(hf, space, this._options);
80
+ this._graphs.set(space.id, graph);
81
+ return graph;
82
+ }
83
+
84
+ protected override async _close() {
85
+ for (const graph of this._graphs.values()) {
86
+ await graph.close();
87
+ }
88
+ this._graphs.clear();
89
+ }
90
+ }
@@ -0,0 +1,97 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import '@dxos-theme';
6
+
7
+ import { type Meta } from '@storybook/react';
8
+ import React, { useEffect, useRef, useState } from 'react';
9
+
10
+ import { FunctionType } from '@dxos/plugin-script/types';
11
+ import { create, useSpace, Filter } from '@dxos/react-client/echo';
12
+ import { withClientProvider } from '@dxos/react-client/testing';
13
+ import { Toolbar, Button, Input } from '@dxos/react-ui';
14
+ import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
15
+ import { withTheme } from '@dxos/storybook-utils';
16
+
17
+ import { testFunctionPlugins } from './testing';
18
+ import { useComputeGraph } from '../components';
19
+ import { createSheet } from '../defs';
20
+ import { useSheetModel } from '../model';
21
+ import { withComputeGraphDecorator } from '../testing';
22
+ import { SheetType } from '../types';
23
+
24
+ const FUNCTION_NAME = 'TEST';
25
+
26
+ const Story = () => {
27
+ const space = useSpace();
28
+ const graph = useComputeGraph(space);
29
+ const [sheet, setSheet] = useState<SheetType>();
30
+ const [text, setText] = useState(`${FUNCTION_NAME}(100)`);
31
+ const [result, setResult] = useState<any>();
32
+ const model = useSheetModel(graph, sheet);
33
+ useEffect(() => {
34
+ if (space) {
35
+ const sheet = space.db.add(createSheet());
36
+ setSheet(sheet);
37
+ }
38
+ }, [space]);
39
+
40
+ useEffect(() => {
41
+ if (space && graph) {
42
+ graph.update.on(() => {
43
+ const f1 = graph.getFunctions({ standard: true, echo: false });
44
+ const f2 = graph.getFunctions({ standard: false, echo: true });
45
+ setResult({ functions: { standard: f1.length, echo: f2.length } });
46
+ });
47
+
48
+ space.db.add(create(FunctionType, { version: 1, binding: FUNCTION_NAME }));
49
+ }
50
+ }, [space, graph]);
51
+
52
+ const inputRef = useRef<HTMLInputElement | null>(null);
53
+ const handleTest = async () => {
54
+ if (space && graph) {
55
+ const { objects } = await space.db.query(Filter.schema(FunctionType)).run();
56
+ const mapped = graph.mapFunctionBindingToId(text);
57
+ const unmapped = graph.mapFunctionBindingFromId(mapped);
58
+ const internal = graph.mapFormulaToNative(text);
59
+ setResult({ mapped, unmapped, internal, functions: objects.map((object) => object.id) });
60
+ }
61
+
62
+ inputRef.current?.focus();
63
+ };
64
+
65
+ return (
66
+ <div className='flex flex-col gap-2 '>
67
+ <Toolbar.Root>
68
+ <Input.Root>
69
+ <Input.TextInput
70
+ ref={inputRef}
71
+ placeholder='Formula'
72
+ value={text}
73
+ onChange={(ev) => setText(ev.target.value)}
74
+ />
75
+ </Input.Root>
76
+ <Button onClick={handleTest}>Test</Button>
77
+ </Toolbar.Root>
78
+ <SyntaxHighlighter language='json'>
79
+ {JSON.stringify({ space: space?.id, graph: graph?.id, sheet: sheet?.id, model: model?.id, result }, null, 2)}
80
+ </SyntaxHighlighter>
81
+ </div>
82
+ );
83
+ };
84
+
85
+ export const Default = {};
86
+
87
+ const meta: Meta = {
88
+ title: 'plugins/plugin-sheet/functions',
89
+ decorators: [
90
+ withClientProvider({ types: [FunctionType, SheetType], createIdentity: true, createSpace: true }),
91
+ withComputeGraphDecorator({ plugins: testFunctionPlugins }),
92
+ withTheme,
93
+ ],
94
+ render: (args: any) => <Story {...args} />,
95
+ };
96
+
97
+ export default meta;
@@ -0,0 +1,87 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type CellValue } from 'hyperformula';
6
+ import { afterEach, beforeEach, describe, expect, test } from 'vitest';
7
+
8
+ import { Trigger } from '@dxos/async';
9
+ import { create, fullyQualifiedId } from '@dxos/client/echo';
10
+ import { FunctionType } from '@dxos/plugin-script/types';
11
+
12
+ import { DetailedCellError } from '#hyperformula';
13
+ import { TestBuilder } from './testing';
14
+
15
+ describe('ComputeGraph', () => {
16
+ let testBuilder: TestBuilder;
17
+ beforeEach(async () => {
18
+ testBuilder = new TestBuilder({ types: [FunctionType] });
19
+ await testBuilder.open();
20
+ });
21
+ afterEach(async () => {
22
+ await testBuilder.close();
23
+ });
24
+
25
+ test('map functions', async () => {
26
+ const space = await testBuilder.client.spaces.create();
27
+ const graph = testBuilder.registry.createGraph(space);
28
+ await graph.open();
29
+
30
+ // Create script.
31
+ const trigger = new Trigger();
32
+ graph.update.once(() => trigger.wake());
33
+ const functionObject = space.db.add(create(FunctionType, { version: 1, binding: 'TEST' }));
34
+ await trigger.wait();
35
+ const functions = graph.getFunctions({ echo: true });
36
+ expect(functions).to.toHaveLength(1);
37
+
38
+ const id = graph.mapFunctionBindingToId('TEST()');
39
+ expect(id).to.eq(`${fullyQualifiedId(functionObject)}()`);
40
+ });
41
+
42
+ test('cross-node references', async () => {
43
+ const space = await testBuilder.client.spaces.create();
44
+ const graph = testBuilder.registry.createGraph(space);
45
+
46
+ // Create nodes.
47
+ const node1 = await graph.getOrCreateNode('node-1').open();
48
+ const node2 = await graph.getOrCreateNode('node-2').open();
49
+ expect(graph.hf.getSheetNames()).to.toHaveLength(2);
50
+
51
+ {
52
+ node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, [[100, 200, 300, '=SUM(A1:C1)']]);
53
+ node2.graph.hf.setCellContents({ sheet: node2.sheetId, row: 0, col: 0 }, "='node-1'!D1");
54
+ const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 3, row: 0 });
55
+ const value2 = node2.graph.hf.getCellValue({ sheet: node2.sheetId, col: 0, row: 0 });
56
+ expect(value1).to.eq(value2);
57
+ }
58
+
59
+ // Get updated event.
60
+ const trigger = new Trigger<CellValue>();
61
+ node2.update.on(({ change }) => {
62
+ const value = node2.graph.hf.getCellValue({ sheet: node2.sheetId, col: 0, row: 0 });
63
+ expect(value).to.eq(change?.newValue);
64
+ trigger.wake(value);
65
+ });
66
+
67
+ {
68
+ node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, 400);
69
+ const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 3, row: 0 });
70
+ const value2 = await trigger.wait();
71
+ expect(value1).to.eq(value2);
72
+ }
73
+ });
74
+
75
+ // TODO(burdon): Dynamically load node/model based on dependencies.
76
+ // - Create dependency then close model.
77
+ test('dynamic loading', async () => {
78
+ const space = await testBuilder.client.spaces.create();
79
+ const graph = testBuilder.registry.createGraph(space);
80
+
81
+ const node1 = await graph.getOrCreateNode('node-1').open();
82
+ node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, "='node-2'!A1");
83
+ const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 0, row: 0 });
84
+ expect(value1).to.be.instanceof(DetailedCellError);
85
+ expect((value1 as DetailedCellError).type).to.eq('REF');
86
+ });
87
+ });
@@ -0,0 +1,245 @@
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(burdon): Factor out compute-graph.
28
+
29
+ // TODO(wittjosiah): Factor out.
30
+ const OBJECT_ID_LENGTH = 60; // 33 (space id) + 1 (separator) + 26 (object id).
31
+
32
+ // TODO(burdon): Factory.
33
+ // export type ComputeNodeGenerator = <T>(obj: T) => ComputeNode;
34
+
35
+ type ObjectRef = { type: string; id: string };
36
+
37
+ /**
38
+ * Marker for sheets that are managed by an ECHO object.
39
+ * Sheet ID: `dxos.org/type/SheetType@1234`
40
+ */
41
+ export const createSheetName = ({ type, id }: ObjectRef) => `${type}@${id}`;
42
+ export const parseSheetName = (name: string): Partial<ObjectRef> => {
43
+ const [type, id] = name.split('@');
44
+ return id ? { type, id } : { id: type };
45
+ };
46
+
47
+ export type ComputeGraphEvent = 'functionsUpdated';
48
+
49
+ /**
50
+ * Per-space compute and dependency graph.
51
+ * Consists of multiple ComputeNode (corresponding to a HyperFormula sheet).
52
+ * Manages the set of custom functions.
53
+ * HyperFormula manages the dependency graph.
54
+ */
55
+ export class ComputeGraph extends Resource {
56
+ public readonly id = `graph-${PublicKey.random().truncate()}`;
57
+
58
+ // Map of nodes indexed by sheet number.
59
+ private readonly _nodes = new Map<number, ComputeNode>();
60
+
61
+ // Cached function objects.
62
+ private _remoteFunctions: FunctionType[] = [];
63
+
64
+ public readonly update = new Event<{ type: ComputeGraphEvent }>();
65
+
66
+ // The context is passed to all functions.
67
+ public readonly context = new FunctionContext(this._hf, this._space, this._options);
68
+
69
+ constructor(
70
+ private readonly _hf: HyperFormula,
71
+ private readonly _space?: Space,
72
+ private readonly _options?: Partial<FunctionContextOptions>,
73
+ ) {
74
+ super();
75
+ this._hf.updateConfig({ context: this.context });
76
+
77
+ // TODO(burdon): If debounce then aggregate changes.
78
+ const onValuesUpdate: Listeners['valuesUpdated'] = (changes) => {
79
+ for (const change of changes) {
80
+ if (change instanceof ExportedCellChange) {
81
+ const { sheet } = change;
82
+ const node = this._nodes.get(sheet);
83
+ if (node) {
84
+ node.update.emit({ type: 'valuesUpdated', change });
85
+ }
86
+ }
87
+ }
88
+ };
89
+
90
+ this._hf.on('valuesUpdated', onValuesUpdate);
91
+ this._ctx.onDispose(() => this._hf.off('valuesUpdated', onValuesUpdate));
92
+ }
93
+
94
+ get hf() {
95
+ return this._hf;
96
+ }
97
+
98
+ getFunctions(
99
+ { standard, echo }: { standard?: boolean; echo?: boolean } = { standard: true, echo: true },
100
+ ): FunctionDefinition[] {
101
+ return [
102
+ ...(standard
103
+ ? this._hf
104
+ .getRegisteredFunctionNames()
105
+ .map((name) => defaultFunctions.find((fn) => fn.name === name) ?? { name })
106
+ : []),
107
+ ...(echo ? this._remoteFunctions.map((fn) => ({ name: fn.binding! })) : []),
108
+ ];
109
+ }
110
+
111
+ /**
112
+ * Get or create cell representing a sheet.
113
+ */
114
+ // TODO(burdon): Async (open node).
115
+ // The graph should be an extensible factory that plugins extend with model constructors.
116
+ // This would enable on-the-fly instantiation of new models when then are referenced.
117
+ // E.g., Cross-object reference would be stored as "ObjectId!A1"
118
+ // The graph would then load the object and create a ComputeNode (model) of the appropriate type.
119
+ getOrCreateNode(name: string): ComputeNode {
120
+ invariant(name.length);
121
+ if (!this._hf.doesSheetExist(name)) {
122
+ log('created node', { space: this._space?.id, sheet: name });
123
+ this._hf.addSheet(name);
124
+ }
125
+
126
+ const sheetId = this._hf.getSheetId(name);
127
+ invariant(sheetId !== undefined);
128
+
129
+ const node = new ComputeNode(this, sheetId);
130
+ this._nodes.set(sheetId, node);
131
+ return node;
132
+ }
133
+
134
+ /**
135
+ * Map bound value to custom function invocation.
136
+ * E.g., "HELLO(...args)" => "DX("HELLO", ...args)".
137
+ */
138
+ mapFormulaToNative(formula: string): string {
139
+ return (
140
+ formula
141
+ //
142
+ // Map cross-sheet references by name onto sheet stored by ECHO object/model.
143
+ // Example: "Test Sheet"!A0 => "dxos.org/type/SheetType@1234"!A0
144
+ // https://hyperformula.handsontable.com/guide/cell-references.html#cell-references
145
+ //
146
+ .replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
147
+ if (name) {
148
+ // TODO(burdon): Cache map.
149
+ const objects = this._hf
150
+ .getSheetNames()
151
+ .map((name) => {
152
+ const { type, id } = parseSheetName(name);
153
+ return type && id ? this._space?.db.getObjectById(id) : undefined;
154
+ })
155
+ .filter(nonNullable);
156
+
157
+ for (const obj of objects) {
158
+ if (obj.name === name) {
159
+ const type = getTypename(obj)!;
160
+ // NOTE: Names must be single quoted.
161
+ return `'${createSheetName({ type, id: obj.id })}'!`;
162
+ }
163
+ }
164
+ }
165
+
166
+ return `${name}!`;
167
+ })
168
+
169
+ //
170
+ // Map remote function references (i.e., to remote DX function invocation).
171
+ //
172
+ .replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
173
+ const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
174
+ if (!fn) {
175
+ return match;
176
+ }
177
+
178
+ if (args.trim() === '') {
179
+ return `${EDGE_FUNCTION_NAME}("${binding}")`;
180
+ } else {
181
+ return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
182
+ }
183
+ })
184
+ );
185
+ }
186
+
187
+ /**
188
+ * Map from binding to fully qualified ECHO ID (to store).
189
+ * E.g., HELLO() => spaceId:objectId()
190
+ */
191
+ mapFunctionBindingToId(formula: string) {
192
+ return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
193
+ if (binding === EDGE_FUNCTION_NAME || defaultFunctions.find((fn) => fn.name === binding)) {
194
+ return match;
195
+ }
196
+
197
+ const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
198
+ if (fn) {
199
+ const id = fullyQualifiedId(fn);
200
+ return `${id}(${args})`;
201
+ } else {
202
+ return match;
203
+ }
204
+ });
205
+ }
206
+
207
+ /**
208
+ * Map from fully qualified ECHO ID to binding (from store).
209
+ * E.g., spaceId:objectId() => HELLO()
210
+ */
211
+ mapFunctionBindingFromId(formula: string) {
212
+ return formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
213
+ const id = `${spaceId}:${objectId}`;
214
+ if (id.length !== OBJECT_ID_LENGTH) {
215
+ return match;
216
+ }
217
+
218
+ const fn = this._remoteFunctions.find((fn) => fullyQualifiedId(fn) === id);
219
+ if (fn?.binding) {
220
+ return `${fn.binding}(${args})`;
221
+ } else {
222
+ return match;
223
+ }
224
+ });
225
+ }
226
+
227
+ protected override async _open() {
228
+ if (this._space) {
229
+ // Subscribe to remote function definitions.
230
+ const query = this._space.db.query(Filter.schema(FunctionType));
231
+ const unsubscribe = query.subscribe(({ objects }) => {
232
+ this._remoteFunctions = objects.filter(({ binding }) => binding);
233
+ this.update.emit({ type: 'functionsUpdated' });
234
+ });
235
+
236
+ this._ctx.onDispose(unsubscribe);
237
+ }
238
+ }
239
+
240
+ protected override async _close() {
241
+ for (const node of this._nodes.values()) {
242
+ await node.close();
243
+ }
244
+ }
245
+ }
@@ -0,0 +1,62 @@
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, isFormula } 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 = isFormula(value) ? this._graph.mapFormulaToNative(value) : value;
54
+ this._graph.hf.setCellContents({ sheet: this.sheetId, row: cell.row, col: cell.col }, [[mappedValue]]);
55
+ }
56
+
57
+ // TODO(burdon): Load data into sheet.
58
+ protected override async _open() {
59
+ // const unsubscribe = this._graph.update.on(this.update.emit);
60
+ // this._ctx.onDispose(unsubscribe);
61
+ }
62
+ }
@@ -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) => {