@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
@@ -1,22 +1,264 @@
1
1
  import {
2
- ValueTypeEnum
3
- } from "./chunk-FUAGSXA4.mjs";
2
+ SheetType
3
+ } from "./chunk-3QWIMZZJ.mjs";
4
4
 
5
- // packages/plugins/plugin-sheet/src/components/ComputeGraph/graph.ts
6
- import { HyperFormula } from "hyperformula";
7
- import { Event } from "@dxos/async";
5
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-graph.ts
6
+ import { Event as Event2 } from "@dxos/async";
7
+ import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
8
+ import { Resource as Resource2 } from "@dxos/context";
9
+ import { getTypename } from "@dxos/echo-schema";
10
+ import { invariant as invariant2 } from "@dxos/invariant";
8
11
  import { PublicKey } from "@dxos/keys";
9
- import { log as log2 } from "@dxos/log";
12
+ import { log as log3 } from "@dxos/log";
13
+ import { FunctionType as FunctionType2 } from "@dxos/plugin-script/types";
14
+ import { nonNullable as nonNullable2 } from "@dxos/util";
15
+ import { ExportedCellChange } from "#hyperformula";
16
+
17
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-node.ts
18
+ import { Event } from "@dxos/async";
19
+ import { Resource } from "@dxos/context";
20
+ import { DetailedCellError } from "#hyperformula";
21
+
22
+ // packages/plugins/plugin-sheet/src/defs/sheet-range-types.ts
23
+ var cellClassNameForRange = ({ key, value }) => {
24
+ switch (key) {
25
+ case "align":
26
+ switch (value) {
27
+ case "start":
28
+ return "text-start";
29
+ case "center":
30
+ return "text-center";
31
+ case "end":
32
+ return "text-end";
33
+ default:
34
+ return void 0;
35
+ }
36
+ case "comment":
37
+ return "bg-gridComment";
38
+ case "style":
39
+ switch (value) {
40
+ case "highlight":
41
+ return "bg-gridHighlight";
42
+ default:
43
+ return void 0;
44
+ }
45
+ default:
46
+ return void 0;
47
+ }
48
+ };
49
+
50
+ // packages/plugins/plugin-sheet/src/defs/types.ts
51
+ import { invariant } from "@dxos/invariant";
52
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/defs/types.ts";
53
+ var DEFAULT_ROWS = 50;
54
+ var DEFAULT_COLUMNS = 26;
55
+ var MAX_ROWS = 500;
56
+ var MAX_COLUMNS = 26 * 2;
57
+ var RANGE_NOTATION = /^[A-Z]+[0-9]+(:[A-Z]+[0-9]+)?$/;
58
+ var isFormula = (value) => typeof value === "string" && value.charAt(0) === "=";
59
+ var posEquals = (a, b) => {
60
+ return a?.col === b?.col && a?.row === b?.row;
61
+ };
62
+ var columnLetter = (col) => {
63
+ invariant(col < MAX_COLUMNS, `Invalid column: ${col}`, {
64
+ F: __dxlog_file,
65
+ L: 31,
66
+ S: void 0,
67
+ A: [
68
+ "col < MAX_COLUMNS",
69
+ "`Invalid column: ${col}`"
70
+ ]
71
+ });
72
+ return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
73
+ };
74
+ var addressToA1Notation = ({ col, row }) => {
75
+ return `${columnLetter(col)}${row + 1}`;
76
+ };
77
+ var addressFromA1Notation = (ref) => {
78
+ const match = ref.match(/([A-Z]+)(\d+)/);
79
+ invariant(match, `Invalid notation: ${ref}`, {
80
+ F: __dxlog_file,
81
+ L: 45,
82
+ S: void 0,
83
+ A: [
84
+ "match",
85
+ "`Invalid notation: ${ref}`"
86
+ ]
87
+ });
88
+ return {
89
+ row: parseInt(match[2], 10) - 1,
90
+ col: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
91
+ };
92
+ };
93
+ var rangeToA1Notation = (range) => {
94
+ return [
95
+ range?.from && addressToA1Notation(range?.from),
96
+ range?.to && addressToA1Notation(range?.to)
97
+ ].filter(Boolean).join(":");
98
+ };
99
+ var inRange = (range, cell) => {
100
+ if (!range) {
101
+ return false;
102
+ }
103
+ const { from, to } = range;
104
+ if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
105
+ return true;
106
+ }
107
+ if (!from || !to) {
108
+ return false;
109
+ }
110
+ const { col: c1, row: r1 } = from;
111
+ const { col: c2, row: r2 } = to;
112
+ const cMin = Math.min(c1, c2);
113
+ const cMax = Math.max(c1, c2);
114
+ const rMin = Math.min(r1, r2);
115
+ const rMax = Math.max(r1, r2);
116
+ const { col, row } = cell;
117
+ return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
118
+ };
119
+
120
+ // packages/plugins/plugin-sheet/src/defs/util.ts
121
+ import { randomBytes } from "@dxos/crypto";
122
+ import { create } from "@dxos/echo-schema";
123
+ var ApiError = class extends Error {
124
+ };
125
+ var ReadonlyException = class extends ApiError {
126
+ };
127
+ var RangeException = class extends ApiError {
128
+ constructor(n) {
129
+ super();
130
+ }
131
+ };
132
+ var createIndex = (length = 8) => {
133
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
134
+ const charactersLength = characters.length;
135
+ const randomBuffer = randomBytes(length);
136
+ return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
137
+ };
138
+ var createIndices = (length) => Array.from({
139
+ length
140
+ }).map(() => createIndex());
141
+ var insertIndices = (indices, i, n, max) => {
142
+ if (i + n > max) {
143
+ throw new RangeException(i + n);
144
+ }
145
+ const idx = createIndices(n);
146
+ indices.splice(i, 0, ...idx);
147
+ };
148
+ var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}) => {
149
+ if (!sheet.rows.length) {
150
+ insertIndices(sheet.rows, 0, rows, MAX_ROWS);
151
+ }
152
+ if (!sheet.columns.length) {
153
+ insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
154
+ }
155
+ };
156
+ var createSheet = ({ name, cells, ...size } = {}) => {
157
+ const sheet = create(SheetType, {
158
+ name,
159
+ cells: {},
160
+ rows: [],
161
+ columns: [],
162
+ rowMeta: {},
163
+ columnMeta: {},
164
+ ranges: [],
165
+ threads: []
166
+ });
167
+ initialize(sheet, size);
168
+ if (cells) {
169
+ Object.entries(cells).forEach(([key, { value }]) => {
170
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
171
+ sheet.cells[idx] = {
172
+ value
173
+ };
174
+ });
175
+ }
176
+ return sheet;
177
+ };
178
+ var addressToIndex = (sheet, cell) => {
179
+ return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
180
+ };
181
+ var addressFromIndex = (sheet, idx) => {
182
+ const [column, row] = idx.split("@");
183
+ return {
184
+ col: sheet.columns.indexOf(column),
185
+ row: sheet.rows.indexOf(row)
186
+ };
187
+ };
188
+ var rangeToIndex = (sheet, range) => {
189
+ return [
190
+ range.from,
191
+ range.to ?? range.from
192
+ ].map((cell) => addressToIndex(sheet, cell)).join(":");
193
+ };
194
+ var rangeFromIndex = (sheet, idx) => {
195
+ const [from, to] = idx.split(":").map((index) => addressFromIndex(sheet, index));
196
+ return {
197
+ from,
198
+ to
199
+ };
200
+ };
201
+ var compareIndexPositions = (sheet, indexA, indexB) => {
202
+ const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
203
+ const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
204
+ if (rowA !== rowB) {
205
+ return rowA - rowB;
206
+ } else {
207
+ return columnA - columnB;
208
+ }
209
+ };
210
+
211
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-node.ts
212
+ var ComputeNode = class extends Resource {
213
+ constructor(_graph, sheetId) {
214
+ super();
215
+ this._graph = _graph;
216
+ this.sheetId = sheetId;
217
+ this.update = new Event();
218
+ }
219
+ get graph() {
220
+ return this._graph;
221
+ }
222
+ clear() {
223
+ this._graph.hf.clearSheet(this.sheetId);
224
+ }
225
+ getValue(cell) {
226
+ const value = this._graph.hf.getCellValue({
227
+ sheet: this.sheetId,
228
+ row: cell.row,
229
+ col: cell.col
230
+ });
231
+ if (value instanceof DetailedCellError) {
232
+ return null;
233
+ }
234
+ return value;
235
+ }
236
+ setValue(cell, value) {
237
+ const mappedValue = isFormula(value) ? this._graph.mapFormulaToNative(value) : value;
238
+ this._graph.hf.setCellContents({
239
+ sheet: this.sheetId,
240
+ row: cell.row,
241
+ col: cell.col
242
+ }, [
243
+ [
244
+ mappedValue
245
+ ]
246
+ ]);
247
+ }
248
+ // TODO(burdon): Load data into sheet.
249
+ async _open() {
250
+ }
251
+ };
10
252
 
11
- // packages/plugins/plugin-sheet/src/components/ComputeGraph/async-function.ts
12
- import { CellError, ErrorType, EmptyValue, FunctionPlugin } from "hyperformula";
253
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/async-function.ts
13
254
  import defaultsDeep from "lodash.defaultsdeep";
14
255
  import { debounce } from "@dxos/async";
15
256
  import { log } from "@dxos/log";
16
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/ComputeGraph/async-function.ts";
257
+ import { CellError, ErrorType, EmptyValue, FunctionPlugin } from "#hyperformula";
258
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/functions/async-function.ts";
17
259
  var defaultFunctionContextOptions = {
18
260
  defaultTtl: 5e3,
19
- recalculationDelay: 200,
261
+ debounceDelay: 200,
20
262
  remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
21
263
  };
22
264
  var FunctionContext = class _FunctionContext {
@@ -27,7 +269,7 @@ var FunctionContext = class _FunctionContext {
27
269
  ...args
28
270
  });
29
271
  }
30
- constructor(_hf, _space, onUpdate, _options) {
272
+ constructor(_hf, _space, _options) {
31
273
  this._hf = _hf;
32
274
  this._space = _space;
33
275
  this._cache = /* @__PURE__ */ new Map();
@@ -35,10 +277,10 @@ var FunctionContext = class _FunctionContext {
35
277
  this._subscriptions = /* @__PURE__ */ new Map();
36
278
  this._invocations = {};
37
279
  this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
38
- this._onUpdate = debounce(() => {
280
+ this._onUpdate = debounce((update) => {
39
281
  this._hf.resumeEvaluation();
40
- onUpdate(this);
41
- }, this._options.recalculationDelay);
282
+ this._options.onUpdate?.(update);
283
+ }, this._options.debounceDelay);
42
284
  }
43
285
  get space() {
44
286
  return this._space;
@@ -87,19 +329,22 @@ var FunctionContext = class _FunctionContext {
87
329
  cell,
88
330
  value: value2
89
331
  }, {
90
- F: __dxlog_file,
91
- L: 136,
332
+ F: __dxlog_file2,
333
+ L: 143,
92
334
  S: this,
93
335
  C: (f, a) => f(...a)
94
336
  });
95
- this._onUpdate();
337
+ this._onUpdate({
338
+ name,
339
+ cell
340
+ });
96
341
  } catch (err) {
97
342
  log.warn("failed", {
98
343
  cell,
99
344
  err
100
345
  }, {
101
- F: __dxlog_file,
102
- L: 140,
346
+ F: __dxlog_file2,
347
+ L: 147,
103
348
  S: this,
104
349
  C: (f, a) => f(...a)
105
350
  });
@@ -118,18 +363,21 @@ var FunctionContext = class _FunctionContext {
118
363
  args,
119
364
  cache: value
120
365
  }, {
121
- F: __dxlog_file,
122
- L: 148,
366
+ F: __dxlog_file2,
367
+ L: 155,
123
368
  S: this,
124
369
  C: (f, a) => f(...a)
125
370
  });
126
371
  return value;
127
372
  }
128
373
  };
129
- var FunctionPluginAsync = class extends FunctionPlugin {
374
+ var AsyncFunctionPlugin = class extends FunctionPlugin {
130
375
  get context() {
131
376
  return this.config.context;
132
377
  }
378
+ /**
379
+ * Immediately returns cached value then runs the async function.
380
+ */
133
381
  runAsyncFunction(ast, state, cb, options) {
134
382
  const { procedureName } = ast;
135
383
  const metadata = this.metadata(procedureName);
@@ -139,53 +387,127 @@ var FunctionPluginAsync = class extends FunctionPlugin {
139
387
  }
140
388
  };
141
389
 
142
- // packages/plugins/plugin-sheet/src/components/ComputeGraph/graph.ts
143
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/ComputeGraph/graph.ts";
144
- var createComputeGraph = (functionPlugins = [], space, options) => {
145
- functionPlugins.forEach(({ plugin, translations }) => {
146
- HyperFormula.registerFunctionPlugin(plugin, translations);
147
- });
148
- const hf = HyperFormula.buildEmpty({
149
- licenseKey: "gpl-v3"
150
- });
151
- return new ComputeGraph(hf, space, options);
152
- };
153
- var ComputeGraph = class {
154
- constructor(hf, _space, _options) {
155
- this.hf = hf;
156
- this._space = _space;
157
- this._options = _options;
158
- this.id = `graph-${PublicKey.random().truncate()}`;
159
- this.update = new Event();
160
- this.context = new FunctionContext(this.hf, this._space, () => {
161
- this.refresh();
162
- }, this._options);
163
- this.hf.updateConfig({
164
- context: this.context
390
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/edge-function.ts
391
+ import { effect } from "@preact/signals-core";
392
+ import { Filter, getMeta } from "@dxos/client/echo";
393
+ import { log as log2 } from "@dxos/log";
394
+ import { getUserFunctionUrlInMetadata } from "@dxos/plugin-script/edge";
395
+ import { FunctionType } from "@dxos/plugin-script/types";
396
+ import { nonNullable } from "@dxos/util";
397
+ import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "#hyperformula";
398
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/functions/edge-function.ts";
399
+ var EDGE_FUNCTION_NAME = "DX";
400
+ var FUNCTION_TTL = 1e4;
401
+ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
402
+ dx(ast, state) {
403
+ const handler = (subscribe = false) => async (binding, ...args) => {
404
+ const space = this.context.space;
405
+ if (!space) {
406
+ return new CellError2(ErrorType2.REF, "Missing space");
407
+ }
408
+ const { objects: [fn] } = await space.db.query(Filter.schema(FunctionType, {
409
+ binding
410
+ })).run();
411
+ if (!fn) {
412
+ log2.info("Function not found", {
413
+ binding
414
+ }, {
415
+ F: __dxlog_file3,
416
+ L: 41,
417
+ S: this,
418
+ C: (f, a) => f(...a)
419
+ });
420
+ return new CellError2(ErrorType2.REF, "Function not found");
421
+ }
422
+ if (subscribe) {
423
+ const unsubscribe = effect(() => {
424
+ log2.info("function changed", {
425
+ fn
426
+ }, {
427
+ F: __dxlog_file3,
428
+ L: 47,
429
+ S: this,
430
+ C: (f, a) => f(...a)
431
+ });
432
+ const _ = fn?.version;
433
+ this.runAsyncFunction(ast, state, handler(false), {
434
+ ttl: FUNCTION_TTL
435
+ });
436
+ });
437
+ this.context.createSubscription(ast.procedureName, unsubscribe);
438
+ }
439
+ const path = getUserFunctionUrlInMetadata(getMeta(fn));
440
+ const result = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
441
+ method: "POST",
442
+ headers: {
443
+ "Content-Type": "application/json"
444
+ },
445
+ body: JSON.stringify({
446
+ args: args.filter(nonNullable)
447
+ })
448
+ });
449
+ return await result.text();
450
+ };
451
+ return this.runAsyncFunction(ast, state, handler(true), {
452
+ ttl: FUNCTION_TTL
165
453
  });
166
454
  }
167
- refresh() {
168
- log2("refresh", {
169
- id: this.id
170
- }, {
171
- F: __dxlog_file2,
172
- L: 59,
173
- S: this,
174
- C: (f, a) => f(...a)
175
- });
176
- this.update.emit();
455
+ };
456
+ EdgeFunctionPlugin.implementedFunctions = {
457
+ [EDGE_FUNCTION_NAME]: {
458
+ method: "dx",
459
+ parameters: [
460
+ // Binding
461
+ {
462
+ argumentType: FunctionArgumentType.STRING
463
+ },
464
+ // Remote function arguments (currently supporting up to 8).
465
+ {
466
+ argumentType: FunctionArgumentType.ANY,
467
+ optionalArg: true
468
+ },
469
+ {
470
+ argumentType: FunctionArgumentType.ANY,
471
+ optionalArg: true
472
+ },
473
+ {
474
+ argumentType: FunctionArgumentType.ANY,
475
+ optionalArg: true
476
+ },
477
+ {
478
+ argumentType: FunctionArgumentType.ANY,
479
+ optionalArg: true
480
+ },
481
+ {
482
+ argumentType: FunctionArgumentType.ANY,
483
+ optionalArg: true
484
+ },
485
+ {
486
+ argumentType: FunctionArgumentType.ANY,
487
+ optionalArg: true
488
+ },
489
+ {
490
+ argumentType: FunctionArgumentType.ANY,
491
+ optionalArg: true
492
+ },
493
+ {
494
+ argumentType: FunctionArgumentType.ANY,
495
+ optionalArg: true
496
+ }
497
+ ],
498
+ isVolatile: true
499
+ }
500
+ };
501
+ var EdgeFunctionPluginTranslations = {
502
+ enGB: {
503
+ [EDGE_FUNCTION_NAME]: "Remote function"
504
+ },
505
+ enUS: {
506
+ [EDGE_FUNCTION_NAME]: "Remote function"
177
507
  }
178
508
  };
179
509
 
180
- // packages/plugins/plugin-sheet/src/model/model.ts
181
- import { DetailedCellError, ExportedCellChange } from "hyperformula";
182
- import { Event as Event2 } from "@dxos/async";
183
- import { Context } from "@dxos/context";
184
- import { invariant as invariant2 } from "@dxos/invariant";
185
- import { PublicKey as PublicKey2 } from "@dxos/keys";
186
- import { log as log3 } from "@dxos/log";
187
-
188
- // packages/plugins/plugin-sheet/src/model/functions.ts
510
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/function-defs.ts
189
511
  var defaultFunctions = [
190
512
  // Array
191
513
  {
@@ -2559,677 +2881,301 @@ var defaultFunctions = [
2559
2881
  }
2560
2882
  ];
2561
2883
 
2562
- // packages/plugins/plugin-sheet/src/model/types.ts
2563
- import { invariant } from "@dxos/invariant";
2564
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/types.ts";
2565
- var MAX_COLUMNS = 26 * 26;
2566
- var posEquals = (a, b) => {
2567
- return a?.column === b?.column && a?.row === b?.row;
2568
- };
2569
- var columnLetter = (column) => {
2570
- invariant(column < MAX_COLUMNS, `Invalid column: ${column}`, {
2571
- F: __dxlog_file3,
2572
- L: 17,
2573
- S: void 0,
2574
- A: [
2575
- "column < MAX_COLUMNS",
2576
- "`Invalid column: ${column}`"
2577
- ]
2578
- });
2579
- return (column >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(column / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + column % 26);
2580
- };
2581
- var addressToA1Notation = ({ column, row }) => {
2582
- return `${columnLetter(column)}${row + 1}`;
2583
- };
2584
- var addressFromA1Notation = (ref) => {
2585
- const match = ref.match(/([A-Z]+)(\d+)/);
2586
- invariant(match, `Invalid notation: ${ref}`, {
2587
- F: __dxlog_file3,
2588
- L: 30,
2589
- S: void 0,
2590
- A: [
2591
- "match",
2592
- "`Invalid notation: ${ref}`"
2593
- ]
2594
- });
2595
- return {
2596
- row: parseInt(match[2], 10) - 1,
2597
- column: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
2884
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-graph.ts
2885
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/compute-graph.ts";
2886
+ var OBJECT_ID_LENGTH = 60;
2887
+ var createSheetName = ({ type, id }) => `${type}@${id}`;
2888
+ var parseSheetName = (name) => {
2889
+ const [type, id] = name.split("@");
2890
+ return id ? {
2891
+ type,
2892
+ id
2893
+ } : {
2894
+ id: type
2598
2895
  };
2599
2896
  };
2600
- var rangeToA1Notation = (range) => {
2601
- return [
2602
- range?.from && addressToA1Notation(range?.from),
2603
- range?.to && addressToA1Notation(range?.to)
2604
- ].filter(Boolean).join(":");
2605
- };
2606
- var inRange = (range, cell) => {
2607
- if (!range) {
2608
- return false;
2609
- }
2610
- const { from, to } = range;
2611
- if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
2612
- return true;
2613
- }
2614
- if (!from || !to) {
2615
- return false;
2616
- }
2617
- const { column: c1, row: r1 } = from;
2618
- const { column: c2, row: r2 } = to;
2619
- const cMin = Math.min(c1, c2);
2620
- const cMax = Math.max(c1, c2);
2621
- const rMin = Math.min(r1, r2);
2622
- const rMax = Math.max(r1, r2);
2623
- const { column, row } = cell;
2624
- return column >= cMin && column <= cMax && row >= rMin && row <= rMax;
2625
- };
2626
-
2627
- // packages/plugins/plugin-sheet/src/model/util.ts
2628
- import { randomBytes } from "@dxos/crypto";
2629
- var ApiError = class extends Error {
2630
- };
2631
- var ReadonlyException = class extends ApiError {
2632
- };
2633
- var RangeException = class extends ApiError {
2634
- constructor(n) {
2897
+ var ComputeGraph = class extends Resource2 {
2898
+ constructor(_hf, _space, _options) {
2635
2899
  super();
2636
- }
2637
- };
2638
- var createIndex = (length = 8) => {
2639
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
2640
- const charactersLength = characters.length;
2641
- const randomBuffer = randomBytes(length);
2642
- return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
2643
- };
2644
- var createIndices = (length) => Array.from({
2645
- length
2646
- }).map(() => createIndex());
2647
-
2648
- // packages/plugins/plugin-sheet/src/model/model.ts
2649
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/model.ts";
2650
- var DEFAULT_ROWS = 100;
2651
- var DEFAULT_COLUMNS = 26;
2652
- var typeMap = {
2653
- BOOLEAN: ValueTypeEnum.Boolean,
2654
- NUMBER_RAW: ValueTypeEnum.Number,
2655
- NUMBER_PERCENT: ValueTypeEnum.Percent,
2656
- NUMBER_CURRENCY: ValueTypeEnum.Currency,
2657
- NUMBER_DATETIME: ValueTypeEnum.DateTime,
2658
- NUMBER_DATE: ValueTypeEnum.Date,
2659
- NUMBER_TIME: ValueTypeEnum.Time
2660
- };
2661
- var defaultOptions = {
2662
- rows: 50,
2663
- columns: 26,
2664
- mapFormulaBindingFromId: () => (formula) => formula,
2665
- mapFormulaBindingToId: () => (formula) => formula
2666
- };
2667
- var getTopLeft = (range) => {
2668
- const to = range.to ?? range.from;
2669
- return {
2670
- row: Math.min(range.from.row, to.row),
2671
- column: Math.min(range.from.column, to.column)
2672
- };
2673
- };
2674
- var toSimpleCellAddress = (sheet, cell) => ({
2675
- sheet,
2676
- row: cell.row,
2677
- col: cell.column
2678
- });
2679
- var toModelRange = (sheet, range) => ({
2680
- start: toSimpleCellAddress(sheet, range.from),
2681
- end: toSimpleCellAddress(sheet, range.to ?? range.from)
2682
- });
2683
- var SheetModel = class {
2684
- constructor(_graph, _sheet, _space, options = {}) {
2685
- this._graph = _graph;
2686
- this._sheet = _sheet;
2900
+ this._hf = _hf;
2687
2901
  this._space = _space;
2688
- this.id = `model-${PublicKey2.random().truncate()}`;
2689
- this._ctx = void 0;
2690
- this._functions = [];
2902
+ this._options = _options;
2903
+ this.id = `graph-${PublicKey.random().truncate()}`;
2904
+ this._nodes = /* @__PURE__ */ new Map();
2905
+ this._remoteFunctions = [];
2691
2906
  this.update = new Event2();
2692
- const name = this._sheet.id;
2693
- if (!this._graph.hf.doesSheetExist(name)) {
2694
- this._graph.hf.addSheet(name);
2695
- }
2696
- this._sheetId = this._graph.hf.getSheetId(name);
2697
- this._options = {
2698
- ...defaultOptions,
2699
- ...options
2907
+ this.context = new FunctionContext(this._hf, this._space, this._options);
2908
+ this._hf.updateConfig({
2909
+ context: this.context
2910
+ });
2911
+ const onValuesUpdate = (changes) => {
2912
+ for (const change of changes) {
2913
+ if (change instanceof ExportedCellChange) {
2914
+ const { sheet } = change;
2915
+ const node = this._nodes.get(sheet);
2916
+ if (node) {
2917
+ node.update.emit({
2918
+ type: "valuesUpdated",
2919
+ change
2920
+ });
2921
+ }
2922
+ }
2923
+ }
2700
2924
  };
2701
- this.reset();
2925
+ this._hf.on("valuesUpdated", onValuesUpdate);
2926
+ this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
2702
2927
  }
2703
- get graph() {
2704
- return this._graph;
2705
- }
2706
- get sheet() {
2707
- return this._sheet;
2708
- }
2709
- get readonly() {
2710
- return this._options.readonly;
2711
- }
2712
- get bounds() {
2713
- return {
2714
- rows: this._sheet.rows.length,
2715
- columns: this._sheet.columns.length
2716
- };
2928
+ get hf() {
2929
+ return this._hf;
2717
2930
  }
2718
- get functions() {
2719
- const hfFunctions = this._graph.hf.getRegisteredFunctionNames().map((name) => defaultFunctions.find((fn) => fn.name === name) ?? {
2720
- name
2721
- });
2722
- const echoFunctions = this._functions.map((fn) => ({
2723
- name: fn.binding
2724
- }));
2931
+ getFunctions({ standard, echo } = {
2932
+ standard: true,
2933
+ echo: true
2934
+ }) {
2725
2935
  return [
2726
- ...hfFunctions,
2727
- ...echoFunctions
2936
+ ...standard ? this._hf.getRegisteredFunctionNames().map((name) => defaultFunctions.find((fn) => fn.name === name) ?? {
2937
+ name
2938
+ }) : [],
2939
+ ...echo ? this._remoteFunctions.map((fn) => ({
2940
+ name: fn.binding
2941
+ })) : []
2728
2942
  ];
2729
2943
  }
2730
- get initialized() {
2731
- return !!this._ctx;
2732
- }
2733
2944
  /**
2734
- * Initialize sheet and engine.
2945
+ * Get or create cell representing a sheet.
2735
2946
  */
2736
- async initialize() {
2737
- log3("initialize", {
2738
- id: this.id
2739
- }, {
2740
- F: __dxlog_file4,
2741
- L: 142,
2742
- S: this,
2743
- C: (f, a) => f(...a)
2744
- });
2745
- invariant2(!this.initialized, "Already initialized.", {
2947
+ // TODO(burdon): Async (open node).
2948
+ // The graph should be an extensible factory that plugins extend with model constructors.
2949
+ // This would enable on-the-fly instantiation of new models when then are referenced.
2950
+ // E.g., Cross-object reference would be stored as "ObjectId!A1"
2951
+ // The graph would then load the object and create a ComputeNode (model) of the appropriate type.
2952
+ getOrCreateNode(name) {
2953
+ invariant2(name.length, void 0, {
2746
2954
  F: __dxlog_file4,
2747
- L: 143,
2955
+ L: 120,
2748
2956
  S: this,
2749
2957
  A: [
2750
- "!this.initialized",
2751
- "'Already initialized.'"
2958
+ "name.length",
2959
+ ""
2752
2960
  ]
2753
2961
  });
2754
- this._ctx = new Context(void 0, {
2755
- F: __dxlog_file4,
2756
- L: 144
2757
- });
2758
- if (!this._sheet.rows.length) {
2759
- this._insertIndices(this._sheet.rows, 0, this._options.rows, DEFAULT_ROWS);
2760
- }
2761
- if (!this._sheet.columns.length) {
2762
- this._insertIndices(this._sheet.columns, 0, this._options.columns, DEFAULT_COLUMNS);
2763
- }
2764
- this.reset();
2765
- const unsubscribe = this._graph.update.on(() => this.update.emit());
2766
- this._ctx.onDispose(unsubscribe);
2767
- if (this._space) {
2768
- const { Filter } = await import("@dxos/client/echo");
2769
- const { FunctionType } = await import("@dxos/plugin-script/types");
2770
- const query = this._space?.db.query(Filter.schema(FunctionType));
2771
- const unsubscribe2 = query.subscribe(({ objects }) => {
2772
- this._functions = objects.filter((fn) => fn.binding);
2773
- this.update.emit();
2962
+ if (!this._hf.doesSheetExist(name)) {
2963
+ log3("created node", {
2964
+ space: this._space?.id,
2965
+ sheet: name
2966
+ }, {
2967
+ F: __dxlog_file4,
2968
+ L: 122,
2969
+ S: this,
2970
+ C: (f, a) => f(...a)
2774
2971
  });
2775
- this._ctx.onDispose(unsubscribe2);
2972
+ this._hf.addSheet(name);
2776
2973
  }
2777
- return this;
2778
- }
2779
- async destroy() {
2780
- log3("destroy", {
2781
- id: this.id
2782
- }, {
2974
+ const sheetId = this._hf.getSheetId(name);
2975
+ invariant2(sheetId !== void 0, void 0, {
2783
2976
  F: __dxlog_file4,
2784
- L: 174,
2977
+ L: 127,
2785
2978
  S: this,
2786
- C: (f, a) => f(...a)
2787
- });
2788
- if (this._ctx) {
2789
- await this._ctx.dispose();
2790
- this._ctx = void 0;
2791
- }
2792
- }
2793
- /**
2794
- * Update engine.
2795
- * NOTE: This resets the undo history.
2796
- * @deprecated
2797
- */
2798
- reset() {
2799
- this._graph.hf.clearSheet(this._sheetId);
2800
- Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
2801
- const { column, row } = this.addressFromIndex(key);
2802
- if (typeof value === "string" && value.charAt(0) === "=") {
2803
- value = this.mapFormulaBindingToFormula(this.mapFormulaBindingFromId(this.mapFormulaIndicesToRefs(value)));
2804
- }
2805
- this._graph.hf.setCellContents({
2806
- sheet: this._sheetId,
2807
- row,
2808
- col: column
2809
- }, value);
2810
- });
2811
- }
2812
- /**
2813
- * Recalculate formulas.
2814
- * NOTE: This resets the undo history.
2815
- * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
2816
- * @deprecated
2817
- */
2818
- // TODO(burdon): Remove.
2819
- recalculate() {
2820
- this._graph.hf.rebuildAndRecalculate();
2821
- }
2822
- insertRows(i, n = 1) {
2823
- this._insertIndices(this._sheet.rows, i, n, DEFAULT_ROWS);
2824
- this.reset();
2825
- }
2826
- insertColumns(i, n = 1) {
2827
- this._insertIndices(this._sheet.columns, i, n, DEFAULT_COLUMNS);
2828
- this.reset();
2829
- }
2830
- //
2831
- // Undoable actions.
2832
- // TODO(burdon): Group undoable methods; consistently update hf/sheet.
2833
- //
2834
- /**
2835
- * Clear range of values.
2836
- */
2837
- clear(range) {
2838
- const topLeft = getTopLeft(range);
2839
- const values = this._iterRange(range, () => null);
2840
- this._graph.hf.setCellContents(toSimpleCellAddress(this._sheetId, topLeft), values);
2841
- this._iterRange(range, (cell) => {
2842
- const idx = this.addressToIndex(cell);
2843
- delete this._sheet.cells[idx];
2844
- });
2845
- }
2846
- cut(range) {
2847
- this._graph.hf.cut(toModelRange(this._sheetId, range));
2848
- this._iterRange(range, (cell) => {
2849
- const idx = this.addressToIndex(cell);
2850
- delete this._sheet.cells[idx];
2851
- });
2852
- }
2853
- copy(range) {
2854
- this._graph.hf.copy(toModelRange(this._sheetId, range));
2855
- }
2856
- paste(cell) {
2857
- if (!this._graph.hf.isClipboardEmpty()) {
2858
- const changes = this._graph.hf.paste(toSimpleCellAddress(this._sheetId, cell));
2859
- for (const change of changes) {
2860
- if (change instanceof ExportedCellChange) {
2861
- const { address, newValue } = change;
2862
- const idx = this.addressToIndex({
2863
- row: address.row,
2864
- column: address.col
2865
- });
2866
- this._sheet.cells[idx] = {
2867
- value: newValue
2868
- };
2869
- }
2870
- }
2871
- }
2872
- }
2873
- // TODO(burdon): Display undo/redo state.
2874
- undo() {
2875
- if (this._graph.hf.isThereSomethingToUndo()) {
2876
- this._graph.hf.undo();
2877
- this.update.emit();
2878
- }
2879
- }
2880
- redo() {
2881
- if (this._graph.hf.isThereSomethingToRedo()) {
2882
- this._graph.hf.redo();
2883
- this.update.emit();
2884
- }
2885
- }
2886
- /**
2887
- * Get value from sheet.
2888
- */
2889
- getCellValue(cell) {
2890
- const idx = this.addressToIndex(cell);
2891
- return this._sheet.cells[idx]?.value ?? null;
2892
- }
2893
- /**
2894
- * Get value as a string for editing.
2895
- */
2896
- getCellText(cell) {
2897
- const value = this.getCellValue(cell);
2898
- if (value == null) {
2899
- return void 0;
2900
- }
2901
- if (typeof value === "string" && value.charAt(0) === "=") {
2902
- return this.mapFormulaBindingFromId(this.mapFormulaIndicesToRefs(value));
2903
- } else {
2904
- return String(value);
2905
- }
2906
- }
2907
- /**
2908
- * Get array of raw values from sheet.
2909
- */
2910
- getCellValues(range) {
2911
- return this._iterRange(range, (cell) => this.getCellValue(cell));
2912
- }
2913
- /**
2914
- * Gets the regular or computed value from the engine.
2915
- */
2916
- getValue(cell) {
2917
- const value = this._graph.hf.getCellValue(toSimpleCellAddress(this._sheetId, cell));
2918
- if (value instanceof DetailedCellError) {
2919
- return value.toString();
2920
- }
2921
- return value;
2922
- }
2923
- /**
2924
- * Get value type.
2925
- */
2926
- getValueType(cell) {
2927
- const addr = toSimpleCellAddress(this._sheetId, cell);
2928
- const type = this._graph.hf.getCellValueDetailedType(addr);
2929
- return typeMap[type];
2930
- }
2931
- /**
2932
- * Sets the value, updating the sheet and engine.
2933
- */
2934
- setValue(cell, value) {
2935
- if (this._options.readonly) {
2936
- throw new ReadonlyException();
2937
- }
2938
- let refresh = false;
2939
- if (cell.row >= this._sheet.rows.length) {
2940
- this._insertIndices(this._sheet.rows, cell.row, 1, DEFAULT_ROWS);
2941
- refresh = true;
2942
- }
2943
- if (cell.column >= this._sheet.columns.length) {
2944
- this._insertIndices(this._sheet.columns, cell.column, 1, DEFAULT_COLUMNS);
2945
- refresh = true;
2946
- }
2947
- if (refresh) {
2948
- this.reset();
2949
- }
2950
- this._graph.hf.setCellContents({
2951
- sheet: this._sheetId,
2952
- row: cell.row,
2953
- col: cell.column
2954
- }, [
2955
- [
2956
- typeof value === "string" && value.charAt(0) === "=" ? this.mapFormulaBindingToFormula(value) : value
2979
+ A: [
2980
+ "sheetId !== undefined",
2981
+ ""
2957
2982
  ]
2958
- ]);
2959
- const idx = this.addressToIndex(cell);
2960
- if (value === void 0 || value === null) {
2961
- delete this._sheet.cells[idx];
2962
- } else {
2963
- if (typeof value === "string" && value.charAt(0) === "=") {
2964
- value = this.mapFormulaBindingToId(this.mapFormulaRefsToIndices(value));
2965
- }
2966
- this._sheet.cells[idx] = {
2967
- value
2968
- };
2969
- }
2970
- }
2971
- /**
2972
- * Sets values from a simple map.
2973
- */
2974
- setValues(values) {
2975
- Object.entries(values).forEach(([key, { value }]) => {
2976
- this.setValue(addressFromA1Notation(key), value);
2977
2983
  });
2984
+ const node = new ComputeNode(this, sheetId);
2985
+ this._nodes.set(sheetId, node);
2986
+ return node;
2978
2987
  }
2979
2988
  /**
2980
- * Iterate range.
2989
+ * Map bound value to custom function invocation.
2990
+ * E.g., "HELLO(...args)" => "DX("HELLO", ...args)".
2981
2991
  */
2982
- _iterRange(range, cb) {
2983
- const to = range.to ?? range.from;
2984
- const rowRange = [
2985
- Math.min(range.from.row, to.row),
2986
- Math.max(range.from.row, to.row)
2987
- ];
2988
- const columnRange = [
2989
- Math.min(range.from.column, to.column),
2990
- Math.max(range.from.column, to.column)
2991
- ];
2992
- const rows = [];
2993
- for (let row = rowRange[0]; row <= rowRange[1]; row++) {
2994
- const rowCells = [];
2995
- for (let column = columnRange[0]; column <= columnRange[1]; column++) {
2996
- const value = cb({
2997
- row,
2998
- column
2999
- });
3000
- if (value !== void 0) {
3001
- rowCells.push(value);
2992
+ mapFormulaToNative(formula) {
2993
+ return formula.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
2994
+ if (name) {
2995
+ const objects = this._hf.getSheetNames().map((name2) => {
2996
+ const { type, id } = parseSheetName(name2);
2997
+ return type && id ? this._space?.db.getObjectById(id) : void 0;
2998
+ }).filter(nonNullable2);
2999
+ for (const obj of objects) {
3000
+ if (obj.name === name) {
3001
+ const type = getTypename(obj);
3002
+ return `'${createSheetName({
3003
+ type,
3004
+ id: obj.id
3005
+ })}'!`;
3006
+ }
3002
3007
  }
3003
3008
  }
3004
- rows.push(rowCells);
3005
- }
3006
- return rows;
3007
- }
3008
- /**
3009
- *
3010
- */
3011
- // TODO(burdon): Insert indices into sheet.
3012
- _insertIndices(indices, i, n, max) {
3013
- if (i + n > max) {
3014
- throw new RangeException(i + n);
3015
- }
3016
- const idx = createIndices(n);
3017
- indices.splice(i, 0, ...idx);
3018
- }
3019
- // TODO(burdon): Delete index.
3020
- _deleteIndices(indices, i, n) {
3021
- throw new Error("Not implemented");
3022
- }
3023
- // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
3024
- _moveIndices(indices, i, j, n) {
3025
- throw new Error("Not implemented");
3026
- }
3027
- //
3028
- // Indices.
3029
- //
3030
- /**
3031
- * E.g., "A1" => "x1@y1".
3032
- */
3033
- addressToIndex(cell) {
3034
- return `${this._sheet.columns[cell.column]}@${this._sheet.rows[cell.row]}`;
3035
- }
3036
- /**
3037
- * E.g., "x1@y1" => "A1".
3038
- */
3039
- addressFromIndex(idx) {
3040
- const [column, row] = idx.split("@");
3041
- return {
3042
- column: this._sheet.columns.indexOf(column),
3043
- row: this._sheet.rows.indexOf(row)
3044
- };
3045
- }
3046
- /**
3047
- * E.g., "A1:B2" => "x1@y1:x2@y2".
3048
- */
3049
- rangeToIndex(range) {
3050
- return [
3051
- range.from,
3052
- range.to ?? range.from
3053
- ].map((cell) => this.addressToIndex(cell)).join(":");
3054
- }
3055
- /**
3056
- * E.g., "x1@y1:x2@y2" => "A1:B2".
3057
- */
3058
- rangeFromIndex(idx) {
3059
- const [from, to] = idx.split(":").map((idx2) => this.addressFromIndex(idx2));
3060
- return {
3061
- from,
3062
- to
3063
- };
3064
- }
3065
- /**
3066
- * E.g., "HELLO()" => "EDGE("HELLO")".
3067
- */
3068
- mapFormulaBindingToFormula(formula) {
3069
- return formula.replace(/([a-zA-Z0-9]+)\((.*)\)/g, (match, binding, args) => {
3070
- const fn = this._functions.find((fn2) => fn2.binding === binding);
3009
+ return `${name}!`;
3010
+ }).replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
3011
+ const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
3071
3012
  if (!fn) {
3072
3013
  return match;
3073
3014
  }
3074
3015
  if (args.trim() === "") {
3075
- return `EDGE("${binding}")`;
3016
+ return `${EDGE_FUNCTION_NAME}("${binding}")`;
3017
+ } else {
3018
+ return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
3076
3019
  }
3077
- return `EDGE("${binding}", ${args})`;
3078
3020
  });
3079
3021
  }
3080
3022
  /**
3081
- * E.g., "EDGE("HELLO")" => "HELLO()".
3023
+ * Map from binding to fully qualified ECHO ID (to store).
3024
+ * E.g., HELLO() => spaceId:objectId()
3082
3025
  */
3083
- mapFormulaBindingFromFormula(formula) {
3084
- return formula.replace(/EDGE\("([a-zA-Z0-9]+)"(.*)\)/, (_match, binding, args) => {
3085
- if (args.trim() === "") {
3086
- return `${binding}()`;
3026
+ mapFunctionBindingToId(formula) {
3027
+ return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
3028
+ if (binding === EDGE_FUNCTION_NAME || defaultFunctions.find((fn2) => fn2.name === binding)) {
3029
+ return match;
3030
+ }
3031
+ const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
3032
+ if (fn) {
3033
+ const id = fullyQualifiedId(fn);
3034
+ return `${id}(${args})`;
3035
+ } else {
3036
+ return match;
3087
3037
  }
3088
- return `${binding}(${args.slice(2)})`;
3089
- });
3090
- }
3091
- /**
3092
- * Map from binding to fully qualified ECHO ID.
3093
- */
3094
- mapFormulaBindingToId(formula) {
3095
- return this._options.mapFormulaBindingToId(this._functions)(formula);
3096
- }
3097
- /**
3098
- * Map from fully qualified ECHO ID to binding.
3099
- */
3100
- mapFormulaBindingFromId(formula) {
3101
- return this._options.mapFormulaBindingFromId(this._functions)(formula);
3102
- }
3103
- /**
3104
- * Map from A1 notation to indices.
3105
- */
3106
- mapFormulaRefsToIndices(formula) {
3107
- invariant2(formula.charAt(0) === "=", void 0, {
3108
- F: __dxlog_file4,
3109
- L: 509,
3110
- S: this,
3111
- A: [
3112
- "formula.charAt(0) === '='",
3113
- ""
3114
- ]
3115
- });
3116
- return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
3117
- return this.addressToIndex(addressFromA1Notation(match));
3118
3038
  });
3119
3039
  }
3120
3040
  /**
3121
- * Map from indices to A1 notation.
3041
+ * Map from fully qualified ECHO ID to binding (from store).
3042
+ * E.g., spaceId:objectId() => HELLO()
3122
3043
  */
3123
- mapFormulaIndicesToRefs(formula) {
3124
- invariant2(formula.charAt(0) === "=", void 0, {
3125
- F: __dxlog_file4,
3126
- L: 519,
3127
- S: this,
3128
- A: [
3129
- "formula.charAt(0) === '='",
3130
- ""
3131
- ]
3132
- });
3133
- return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
3134
- return addressToA1Notation(this.addressFromIndex(idx));
3044
+ mapFunctionBindingFromId(formula) {
3045
+ return formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
3046
+ const id = `${spaceId}:${objectId}`;
3047
+ if (id.length !== OBJECT_ID_LENGTH) {
3048
+ return match;
3049
+ }
3050
+ const fn = this._remoteFunctions.find((fn2) => fullyQualifiedId(fn2) === id);
3051
+ if (fn?.binding) {
3052
+ return `${fn.binding}(${args})`;
3053
+ } else {
3054
+ return match;
3055
+ }
3135
3056
  });
3136
3057
  }
3137
- //
3138
- // Values
3139
- //
3140
- /**
3141
- * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
3142
- * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
3143
- * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
3144
- */
3145
- toLocalDate(num) {
3146
- const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
3147
- return new Date(year, month - 1, day, hours, minutes, seconds);
3148
- }
3149
- toDateTime(num) {
3150
- return this._graph.hf.numberToDateTime(num);
3151
- }
3152
- toDate(num) {
3153
- return this._graph.hf.numberToDate(num);
3058
+ async _open() {
3059
+ if (this._space) {
3060
+ const query = this._space.db.query(Filter2.schema(FunctionType2));
3061
+ const unsubscribe = query.subscribe(({ objects }) => {
3062
+ this._remoteFunctions = objects.filter(({ binding }) => binding);
3063
+ this.update.emit({
3064
+ type: "functionsUpdated"
3065
+ });
3066
+ });
3067
+ this._ctx.onDispose(unsubscribe);
3068
+ }
3154
3069
  }
3155
- toTime(num) {
3156
- return this._graph.hf.numberToTime(num);
3070
+ async _close() {
3071
+ for (const node of this._nodes.values()) {
3072
+ await node.close();
3073
+ }
3157
3074
  }
3158
3075
  };
3159
3076
 
3160
- // packages/plugins/plugin-sheet/src/components/ComputeGraph/custom.ts
3161
- import { FunctionArgumentType } from "hyperformula";
3162
- import { getDeep } from "@dxos/util";
3163
- var parseNumberString = (str) => {
3164
- return parseFloat(str.replace(/[^\d.]/g, ""));
3077
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-graph-registry.ts
3078
+ import defaultsDeep2 from "lodash.defaultsdeep";
3079
+ import { Resource as Resource3 } from "@dxos/context";
3080
+ import { invariant as invariant3 } from "@dxos/invariant";
3081
+ import { log as log4 } from "@dxos/log";
3082
+ import { HyperFormula } from "#hyperformula";
3083
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/compute-graph-registry.ts";
3084
+ var defaultOptions = {
3085
+ licenseKey: "gpl-v3"
3165
3086
  };
3166
- var CustomPlugin = class extends FunctionPluginAsync {
3167
- test(ast, state) {
3168
- const handler = async () => {
3169
- return Math.random();
3170
- };
3171
- return this.runAsyncFunction(ast, state, handler);
3087
+ var defaultPlugins = [
3088
+ {
3089
+ plugin: EdgeFunctionPlugin,
3090
+ translations: EdgeFunctionPluginTranslations
3172
3091
  }
3173
- crypto(ast, state) {
3174
- const handler = async (_currency) => {
3175
- const currency = (_currency || "USD").toUpperCase();
3176
- const result = await fetch(`https://api.coindesk.com/v1/bpi/currentprice/${currency}.json`);
3177
- const data = await result.json();
3178
- const rate = getDeep(data, [
3179
- "bpi",
3180
- currency,
3181
- "rate"
3182
- ]);
3183
- if (!rate) {
3184
- return NaN;
3185
- }
3186
- return parseNumberString(rate);
3187
- };
3188
- return this.runAsyncFunction(ast, state, handler, {
3189
- ttl: 1e4
3092
+ ];
3093
+ var ComputeGraphRegistry = class extends Resource3 {
3094
+ constructor(options = {
3095
+ plugins: defaultPlugins
3096
+ }) {
3097
+ super();
3098
+ this._graphs = /* @__PURE__ */ new Map();
3099
+ this._options = defaultsDeep2({}, options, defaultOptions);
3100
+ this._options.plugins?.forEach(({ plugin, translations }) => {
3101
+ HyperFormula.registerFunctionPlugin(plugin, translations);
3190
3102
  });
3191
3103
  }
3192
- };
3193
- CustomPlugin.implementedFunctions = {
3194
- TEST: {
3195
- method: "test",
3196
- parameters: [],
3197
- isVolatile: true
3198
- },
3199
- CRYPTO: {
3200
- method: "crypto",
3201
- parameters: [
3202
- {
3203
- argumentType: FunctionArgumentType.STRING,
3204
- optionalArg: true
3205
- }
3206
- ],
3207
- isVolatile: true
3104
+ getGraph(spaceId) {
3105
+ return this._graphs.get(spaceId);
3106
+ }
3107
+ getOrCreateGraph(space) {
3108
+ let graph = this._graphs.get(space.id);
3109
+ if (!graph) {
3110
+ log4("create graph", {
3111
+ space: space.id
3112
+ }, {
3113
+ F: __dxlog_file5,
3114
+ L: 69,
3115
+ S: this,
3116
+ C: (f, a) => f(...a)
3117
+ });
3118
+ graph = this.createGraph(space);
3119
+ }
3120
+ return graph;
3208
3121
  }
3209
- };
3210
- var CustomPluginTranslations = {
3211
- enGB: {
3212
- TEST: "TEST",
3213
- CRYPTO: "CRYPTO"
3214
- },
3215
- enUS: {
3216
- TEST: "TEST",
3217
- CRYPTO: "CRYPTO"
3122
+ createGraph(space) {
3123
+ invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
3124
+ F: __dxlog_file5,
3125
+ L: 77,
3126
+ S: this,
3127
+ A: [
3128
+ "!this._graphs.has(space.id)",
3129
+ "`ComputeGraph already exists for space: ${space.id}`"
3130
+ ]
3131
+ });
3132
+ const hf = HyperFormula.buildEmpty(this._options);
3133
+ const graph = new ComputeGraph(hf, space, this._options);
3134
+ this._graphs.set(space.id, graph);
3135
+ return graph;
3136
+ }
3137
+ async _close() {
3138
+ for (const graph of this._graphs.values()) {
3139
+ await graph.close();
3140
+ }
3141
+ this._graphs.clear();
3218
3142
  }
3219
3143
  };
3220
3144
 
3221
3145
  export {
3222
- FunctionPluginAsync,
3223
- CustomPlugin,
3224
- CustomPluginTranslations,
3225
- createComputeGraph,
3226
- defaultFunctions,
3227
- posEquals,
3228
- columnLetter,
3146
+ cellClassNameForRange,
3147
+ DEFAULT_ROWS,
3148
+ DEFAULT_COLUMNS,
3149
+ MAX_ROWS,
3150
+ MAX_COLUMNS,
3151
+ RANGE_NOTATION,
3152
+ isFormula,
3229
3153
  addressToA1Notation,
3230
3154
  addressFromA1Notation,
3231
3155
  rangeToA1Notation,
3232
3156
  inRange,
3233
- SheetModel
3157
+ ReadonlyException,
3158
+ insertIndices,
3159
+ initialize,
3160
+ createSheet,
3161
+ addressToIndex,
3162
+ addressFromIndex,
3163
+ rangeToIndex,
3164
+ rangeFromIndex,
3165
+ compareIndexPositions,
3166
+ ComputeNode,
3167
+ defaultFunctionContextOptions,
3168
+ FunctionContext,
3169
+ AsyncFunctionPlugin,
3170
+ EDGE_FUNCTION_NAME,
3171
+ EdgeFunctionPlugin,
3172
+ EdgeFunctionPluginTranslations,
3173
+ defaultFunctions,
3174
+ createSheetName,
3175
+ parseSheetName,
3176
+ ComputeGraph,
3177
+ defaultOptions,
3178
+ defaultPlugins,
3179
+ ComputeGraphRegistry
3234
3180
  };
3235
- //# sourceMappingURL=chunk-D5AGLXJP.mjs.map
3181
+ //# sourceMappingURL=chunk-2ZK3YMZG.mjs.map