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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (330) hide show
  1. package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs +297 -0
  2. package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-BVUN7SHF.mjs +67 -0
  4. package/dist/lib/browser/chunk-BVUN7SHF.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-G2FUL6PK.mjs +1671 -0
  6. package/dist/lib/browser/chunk-G2FUL6PK.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-RABELMEQ.mjs +15 -0
  8. package/dist/lib/browser/chunk-RABELMEQ.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-D5AGLXJP.mjs → chunk-VMSX6Z4X.mjs} +659 -675
  10. package/dist/lib/browser/chunk-VMSX6Z4X.mjs.map +7 -0
  11. package/dist/lib/browser/compute-graph-GGWUX644.mjs +35 -0
  12. package/dist/lib/browser/compute-graph-GGWUX644.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +168 -67
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/meta.mjs +1 -1
  17. package/dist/lib/browser/types.mjs +6 -12
  18. package/dist/lib/node/SheetContainer-PJE74VO4.cjs +300 -0
  19. package/dist/lib/node/SheetContainer-PJE74VO4.cjs.map +7 -0
  20. package/dist/lib/node/chunk-2ZVZI2KJ.cjs +38 -0
  21. package/dist/lib/node/chunk-2ZVZI2KJ.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-AWKOWDMI.cjs} +34 -52
  23. package/dist/lib/node/chunk-AWKOWDMI.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-O7XR4R7Y.cjs} +678 -674
  25. package/dist/lib/node/chunk-O7XR4R7Y.cjs.map +7 -0
  26. package/dist/lib/node/chunk-STZ7S7RF.cjs +1656 -0
  27. package/dist/lib/node/chunk-STZ7S7RF.cjs.map +7 -0
  28. package/dist/lib/node/compute-graph-KGWA2QLE.cjs +57 -0
  29. package/dist/lib/node/compute-graph-KGWA2QLE.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +178 -75
  31. package/dist/lib/node/index.cjs.map +4 -4
  32. package/dist/lib/node/meta.cjs +3 -3
  33. package/dist/lib/node/meta.cjs.map +1 -1
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/types.cjs +9 -15
  36. package/dist/lib/node/types.cjs.map +2 -2
  37. package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs +298 -0
  38. package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs +17 -0
  40. package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-CR4K75EL.mjs +3220 -0
  42. package/dist/lib/node-esm/chunk-CR4K75EL.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-UIBWRHW7.mjs +68 -0
  44. package/dist/lib/node-esm/chunk-UIBWRHW7.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs +1672 -0
  46. package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs.map +7 -0
  47. package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs +36 -0
  48. package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs.map +7 -0
  49. package/dist/lib/node-esm/index.mjs +350 -0
  50. package/dist/lib/node-esm/index.mjs.map +7 -0
  51. package/dist/lib/node-esm/meta.json +1 -0
  52. package/dist/lib/node-esm/meta.mjs +10 -0
  53. package/dist/lib/node-esm/meta.mjs.map +7 -0
  54. package/dist/lib/node-esm/types.mjs +17 -0
  55. package/dist/lib/node-esm/types.mjs.map +7 -0
  56. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  57. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +13 -0
  58. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -0
  59. package/dist/types/src/components/ComputeGraph/index.d.ts +1 -3
  60. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  61. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +3 -0
  62. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -0
  63. package/dist/types/src/components/FunctionEditor/index.d.ts +2 -0
  64. package/dist/types/src/components/FunctionEditor/index.d.ts.map +1 -0
  65. package/dist/types/src/components/GridSheet/GridSheet.d.ts +3 -0
  66. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -0
  67. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +6 -0
  68. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -0
  69. package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +5 -9
  70. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/GridSheet/index.d.ts +2 -0
  72. package/dist/types/src/components/GridSheet/index.d.ts.map +1 -0
  73. package/dist/types/src/components/GridSheet/util.d.ts +15 -0
  74. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
  75. package/dist/types/src/components/RangeList/RangeList.d.ts +7 -0
  76. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -0
  77. package/dist/types/src/components/RangeList/index.d.ts +2 -0
  78. package/dist/types/src/components/RangeList/index.d.ts.map +1 -0
  79. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +9 -0
  80. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +6 -0
  82. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
  83. package/dist/types/src/components/SheetContainer/index.d.ts +3 -0
  84. package/dist/types/src/components/SheetContainer/index.d.ts.map +1 -0
  85. package/dist/types/src/components/SheetContext/SheetContext.d.ts +28 -0
  86. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -0
  87. package/dist/types/src/components/SheetContext/index.d.ts +2 -0
  88. package/dist/types/src/components/SheetContext/index.d.ts.map +1 -0
  89. package/dist/types/src/components/Toolbar/Toolbar.d.ts +36 -9
  90. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  91. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +4 -32
  92. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  93. package/dist/types/src/components/index.d.ts +7 -4
  94. package/dist/types/src/components/index.d.ts.map +1 -1
  95. package/dist/types/src/compute-graph/compute-graph-registry.d.ts +34 -0
  96. package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +1 -0
  97. package/dist/types/src/compute-graph/compute-graph.d.ts +64 -0
  98. package/dist/types/src/compute-graph/compute-graph.d.ts.map +1 -0
  99. package/dist/types/src/compute-graph/compute-graph.stories.d.ts +6 -0
  100. package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +1 -0
  101. package/dist/types/src/compute-graph/compute-graph.test.d.ts +2 -0
  102. package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +1 -0
  103. package/dist/types/src/compute-graph/compute-node.d.ts +26 -0
  104. package/dist/types/src/compute-graph/compute-node.d.ts.map +1 -0
  105. package/dist/types/src/{components/ComputeGraph → compute-graph/functions}/async-function.d.ts +14 -5
  106. package/dist/types/src/compute-graph/functions/async-function.d.ts.map +1 -0
  107. package/dist/types/src/compute-graph/functions/edge-function.d.ts +21 -0
  108. package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +1 -0
  109. package/dist/types/src/{model/functions.d.ts → compute-graph/functions/function-defs.d.ts} +1 -1
  110. package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +1 -0
  111. package/dist/types/src/compute-graph/functions/index.d.ts +4 -0
  112. package/dist/types/src/compute-graph/functions/index.d.ts.map +1 -0
  113. package/dist/types/src/compute-graph/hyperformula.test.d.ts +2 -0
  114. package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +1 -0
  115. package/dist/types/src/compute-graph/index.d.ts +5 -0
  116. package/dist/types/src/compute-graph/index.d.ts.map +1 -0
  117. package/dist/types/src/compute-graph/testing/index.d.ts +3 -0
  118. package/dist/types/src/compute-graph/testing/index.d.ts.map +1 -0
  119. package/dist/types/src/compute-graph/testing/test-builder.d.ts +15 -0
  120. package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +1 -0
  121. package/dist/types/src/compute-graph/testing/test-plugin.d.ts +36 -0
  122. package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +1 -0
  123. package/dist/types/src/compute-graph/util.d.ts +2 -0
  124. package/dist/types/src/compute-graph/util.d.ts.map +1 -0
  125. package/dist/types/src/defs/index.d.ts +4 -0
  126. package/dist/types/src/defs/index.d.ts.map +1 -0
  127. package/dist/types/src/defs/sheet-range-types.d.ts +13 -0
  128. package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -0
  129. package/dist/types/src/defs/types.d.ts +28 -0
  130. package/dist/types/src/defs/types.d.ts.map +1 -0
  131. package/dist/types/src/defs/types.test.d.ts.map +1 -0
  132. package/dist/types/src/defs/util.d.ts +39 -0
  133. package/dist/types/src/defs/util.d.ts.map +1 -0
  134. package/dist/types/src/extensions/compute.d.ts +6 -0
  135. package/dist/types/src/extensions/compute.d.ts.map +1 -0
  136. package/dist/types/src/extensions/compute.stories.d.ts +21 -0
  137. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
  138. package/dist/types/src/extensions/editor/extension.d.ts +39 -0
  139. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
  140. package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
  141. package/dist/types/src/extensions/editor/index.d.ts +2 -0
  142. package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
  143. package/dist/types/src/extensions/index.d.ts +3 -0
  144. package/dist/types/src/extensions/index.d.ts.map +1 -0
  145. package/dist/types/src/index.d.ts +1 -1
  146. package/dist/types/src/index.d.ts.map +1 -1
  147. package/dist/types/src/integrations/index.d.ts +2 -0
  148. package/dist/types/src/integrations/index.d.ts.map +1 -0
  149. package/dist/types/src/integrations/thread-ranges.d.ts +7 -0
  150. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -0
  151. package/dist/types/src/meta.d.ts +4 -9
  152. package/dist/types/src/meta.d.ts.map +1 -1
  153. package/dist/types/src/model/index.d.ts +2 -3
  154. package/dist/types/src/model/index.d.ts.map +1 -1
  155. package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +22 -69
  156. package/dist/types/src/model/sheet-model.d.ts.map +1 -0
  157. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  158. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  159. package/dist/types/src/model/useSheetModel.d.ts +8 -0
  160. package/dist/types/src/model/useSheetModel.d.ts.map +1 -0
  161. package/dist/types/src/sanity.test.d.ts +2 -0
  162. package/dist/types/src/sanity.test.d.ts.map +1 -0
  163. package/dist/types/src/serializer.d.ts +4 -0
  164. package/dist/types/src/serializer.d.ts.map +1 -0
  165. package/dist/types/src/testing/index.d.ts +2 -0
  166. package/dist/types/src/testing/index.d.ts.map +1 -0
  167. package/dist/types/src/testing/testing.d.ts +8 -0
  168. package/dist/types/src/testing/testing.d.ts.map +1 -0
  169. package/dist/types/src/translations.d.ts +32 -12
  170. package/dist/types/src/translations.d.ts.map +1 -1
  171. package/dist/types/src/types.d.ts +132 -43
  172. package/dist/types/src/types.d.ts.map +1 -1
  173. package/dist/vendor/hyperformula.mjs +37145 -0
  174. package/package.json +60 -61
  175. package/src/SheetPlugin.tsx +89 -78
  176. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +37 -0
  177. package/src/components/ComputeGraph/index.ts +1 -3
  178. package/src/components/FunctionEditor/FunctionEditor.tsx +45 -0
  179. package/src/components/FunctionEditor/index.ts +5 -0
  180. package/src/components/GridSheet/GridSheet.stories.tsx +46 -0
  181. package/src/components/GridSheet/GridSheet.tsx +358 -0
  182. package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +18 -15
  183. package/src/components/GridSheet/index.ts +5 -0
  184. package/src/components/GridSheet/util.ts +170 -0
  185. package/src/components/RangeList/RangeList.tsx +53 -0
  186. package/src/components/RangeList/index.ts +5 -0
  187. package/src/components/SheetContainer/SheetContainer.stories.tsx +45 -0
  188. package/src/components/SheetContainer/SheetContainer.tsx +33 -0
  189. package/src/components/SheetContainer/index.ts +7 -0
  190. package/src/components/SheetContext/SheetContext.tsx +127 -0
  191. package/src/components/SheetContext/index.ts +5 -0
  192. package/src/components/Toolbar/Toolbar.stories.tsx +9 -6
  193. package/src/components/Toolbar/Toolbar.tsx +265 -111
  194. package/src/components/index.ts +5 -3
  195. package/src/compute-graph/compute-graph-registry.ts +90 -0
  196. package/src/compute-graph/compute-graph.stories.tsx +97 -0
  197. package/src/compute-graph/compute-graph.test.ts +87 -0
  198. package/src/compute-graph/compute-graph.ts +260 -0
  199. package/src/compute-graph/compute-node.ts +62 -0
  200. package/src/{components/ComputeGraph → compute-graph/functions}/async-function.ts +26 -15
  201. package/src/{components/ComputeGraph → compute-graph/functions}/edge-function.ts +21 -17
  202. package/src/compute-graph/functions/index.ts +7 -0
  203. package/src/compute-graph/hyperformula.test.ts +14 -0
  204. package/src/compute-graph/index.ts +8 -0
  205. package/src/compute-graph/testing/index.ts +6 -0
  206. package/src/compute-graph/testing/test-builder.ts +54 -0
  207. package/src/{components/ComputeGraph/custom.ts → compute-graph/testing/test-plugin.ts} +44 -14
  208. package/src/compute-graph/util.ts +8 -0
  209. package/src/defs/index.ts +7 -0
  210. package/src/defs/sheet-range-types.ts +49 -0
  211. package/src/{model → defs}/types.test.ts +8 -9
  212. package/src/defs/types.ts +86 -0
  213. package/src/defs/util.ts +136 -0
  214. package/src/extensions/compute.stories.tsx +155 -0
  215. package/src/extensions/compute.ts +147 -0
  216. package/src/{components/CellEditor → extensions/editor}/extension.test.ts +4 -6
  217. package/src/{components/CellEditor → extensions/editor}/extension.ts +51 -27
  218. package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
  219. package/src/extensions/index.ts +6 -0
  220. package/src/index.ts +2 -2
  221. package/src/integrations/index.ts +5 -0
  222. package/src/integrations/thread-ranges.ts +101 -0
  223. package/src/meta.ts +15 -0
  224. package/src/model/index.ts +2 -3
  225. package/src/model/sheet-model.test.ts +59 -0
  226. package/src/model/sheet-model.ts +495 -0
  227. package/src/model/useSheetModel.ts +40 -0
  228. package/src/sanity.test.ts +40 -0
  229. package/src/serializer.ts +27 -0
  230. package/src/{components/Sheet → testing}/index.ts +1 -1
  231. package/src/testing/testing.tsx +68 -0
  232. package/src/translations.ts +24 -4
  233. package/src/types.ts +62 -47
  234. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +0 -1772
  235. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
  236. package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
  237. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
  238. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
  239. package/dist/lib/browser/chunk-FUAGSXA4.mjs +0 -82
  240. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
  241. package/dist/lib/browser/chunk-JRL5LGCE.mjs +0 -18
  242. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
  243. package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
  244. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
  245. package/dist/lib/browser/testing.mjs +0 -92
  246. package/dist/lib/browser/testing.mjs.map +0 -7
  247. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +0 -1765
  248. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
  249. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
  250. package/dist/lib/node/chunk-BJ6ZD7MN.cjs +0 -51
  251. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
  252. package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
  253. package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
  254. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
  255. package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
  256. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
  257. package/dist/lib/node/testing.cjs +0 -111
  258. package/dist/lib/node/testing.cjs.map +0 -7
  259. package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -14
  260. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
  261. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
  262. package/dist/types/src/components/CellEditor/extension.d.ts +0 -19
  263. package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
  264. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
  265. package/dist/types/src/components/CellEditor/index.d.ts +0 -3
  266. package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
  267. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
  268. package/dist/types/src/components/ComputeGraph/custom.d.ts +0 -21
  269. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
  270. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +0 -20
  271. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
  272. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
  273. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
  274. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
  275. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
  276. package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
  277. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
  278. package/dist/types/src/components/Sheet/Sheet.d.ts +0 -55
  279. package/dist/types/src/components/Sheet/Sheet.d.ts.map +0 -1
  280. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +0 -54
  281. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
  282. package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
  283. package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
  284. package/dist/types/src/components/Sheet/grid.d.ts +0 -52
  285. package/dist/types/src/components/Sheet/grid.d.ts.map +0 -1
  286. package/dist/types/src/components/Sheet/index.d.ts +0 -2
  287. package/dist/types/src/components/Sheet/index.d.ts.map +0 -1
  288. package/dist/types/src/components/Sheet/nav.d.ts +0 -29
  289. package/dist/types/src/components/Sheet/nav.d.ts.map +0 -1
  290. package/dist/types/src/components/Sheet/sheet-context.d.ts +0 -25
  291. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
  292. package/dist/types/src/components/Sheet/util.d.ts +0 -18
  293. package/dist/types/src/components/Sheet/util.d.ts.map +0 -1
  294. package/dist/types/src/components/SheetContainer.d.ts +0 -9
  295. package/dist/types/src/components/SheetContainer.d.ts.map +0 -1
  296. package/dist/types/src/components/Toolbar/common.d.ts +0 -20
  297. package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
  298. package/dist/types/src/model/functions.d.ts.map +0 -1
  299. package/dist/types/src/model/model.browser.test.d.ts +0 -2
  300. package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
  301. package/dist/types/src/model/model.d.ts.map +0 -1
  302. package/dist/types/src/model/types.d.ts +0 -17
  303. package/dist/types/src/model/types.d.ts.map +0 -1
  304. package/dist/types/src/model/types.test.d.ts.map +0 -1
  305. package/dist/types/src/model/util.d.ts +0 -15
  306. package/dist/types/src/model/util.d.ts.map +0 -1
  307. package/dist/types/src/testing.d.ts +0 -9
  308. package/dist/types/src/testing.d.ts.map +0 -1
  309. package/src/components/CellEditor/CellEditor.tsx +0 -113
  310. package/src/components/ComputeGraph/graph-context.tsx +0 -50
  311. package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
  312. package/src/components/ComputeGraph/graph.ts +0 -62
  313. package/src/components/Sheet/Sheet.stories.tsx +0 -287
  314. package/src/components/Sheet/Sheet.tsx +0 -1160
  315. package/src/components/Sheet/formatting.ts +0 -106
  316. package/src/components/Sheet/grid.ts +0 -191
  317. package/src/components/Sheet/nav.ts +0 -157
  318. package/src/components/Sheet/sheet-context.tsx +0 -150
  319. package/src/components/Sheet/util.ts +0 -56
  320. package/src/components/SheetContainer.tsx +0 -34
  321. package/src/components/Toolbar/common.tsx +0 -72
  322. package/src/meta.tsx +0 -18
  323. package/src/model/model.browser.test.ts +0 -100
  324. package/src/model/model.ts +0 -550
  325. package/src/model/types.ts +0 -71
  326. package/src/model/util.ts +0 -36
  327. package/src/testing.ts +0 -50
  328. /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
  329. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
  330. /package/src/{model/functions.ts → compute-graph/functions/function-defs.ts} +0 -0
@@ -2,167 +2,293 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import {
6
- type Icon,
7
- Calendar,
8
- ChatText,
9
- CurrencyDollar,
10
- Eraser,
11
- HighlighterCircle,
12
- TextAlignCenter,
13
- TextAlignLeft,
14
- TextAlignRight,
15
- } from '@phosphor-icons/react';
16
5
  import { createContext } from '@radix-ui/react-context';
17
- import React, { type PropsWithChildren } from 'react';
6
+ import React, { type PropsWithChildren, useCallback } from 'react';
18
7
 
8
+ import { useIntentDispatcher } from '@dxos/app-framework';
19
9
  import {
20
- DensityProvider,
21
- ElevationProvider,
22
- Toolbar as NaturalToolbar,
10
+ Icon,
23
11
  type ThemedClassName,
12
+ Toolbar as NaturalToolbar,
13
+ type ToolbarButtonProps as NaturalToolbarButtonProps,
14
+ type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
15
+ type ToolbarToggleProps as NaturalToolbarToggleProps,
16
+ Tooltip,
24
17
  useTranslation,
25
18
  } from '@dxos/react-ui';
19
+ import { useAttention } from '@dxos/react-ui-attention';
20
+ import { nonNullable } from '@dxos/util';
26
21
 
27
- import { ToolbarButton, ToolbarSeparator, ToolbarToggleButton } from './common';
22
+ import {
23
+ alignKey,
24
+ type AlignKey,
25
+ type AlignValue,
26
+ type CommentKey,
27
+ type CommentValue,
28
+ inRange,
29
+ rangeFromIndex,
30
+ rangeToIndex,
31
+ styleKey,
32
+ type StyleKey,
33
+ type StyleValue,
34
+ } from '../../defs';
35
+ import { completeCellRangeToThreadCursor } from '../../integrations';
28
36
  import { SHEET_PLUGIN } from '../../meta';
29
- import { type Formatting } from '../../types';
37
+ import { type SheetType } from '../../types';
38
+ import { useSheetContext } from '../SheetContext';
30
39
 
31
40
  //
32
- // Root
41
+ // Buttons
33
42
  //
34
43
 
35
- export type ToolbarActionType = 'clear' | 'highlight' | 'left' | 'center' | 'right' | 'date' | 'currency';
44
+ const buttonStyles = 'min-bs-0 p-2';
45
+ const tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };
46
+
47
+ const ToolbarSeparator = () => <div role='separator' className='grow' />;
36
48
 
37
- export type ToolbarAction = {
38
- type: ToolbarActionType;
49
+ //
50
+ // ToolbarItem
51
+ //
52
+
53
+ type ToolbarItemProps =
54
+ | (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })
55
+ | (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })
56
+ | (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });
57
+
58
+ export const ToolbarItem = ({ itemType, icon, children, ...props }: ToolbarItemProps) => {
59
+ const Invoker =
60
+ itemType === 'toggleGroupItem'
61
+ ? NaturalToolbar.ToggleGroupItem
62
+ : itemType === 'toggle'
63
+ ? NaturalToolbar.Toggle
64
+ : NaturalToolbar.Button;
65
+ return (
66
+ <Tooltip.Root>
67
+ <Tooltip.Trigger asChild>
68
+ {/* TODO(thure): type the props spread better. */}
69
+ <Invoker variant='ghost' {...(props as any)} classNames={buttonStyles}>
70
+ <Icon icon={icon} size={5} />
71
+ <span className='sr-only'>{children}</span>
72
+ </Invoker>
73
+ </Tooltip.Trigger>
74
+ <Tooltip.Portal>
75
+ <Tooltip.Content {...tooltipProps}>
76
+ {children}
77
+ <Tooltip.Arrow />
78
+ </Tooltip.Content>
79
+ </Tooltip.Portal>
80
+ </Tooltip.Root>
81
+ );
39
82
  };
40
83
 
41
- export type ToolbarActionHandler = ({ type }: ToolbarAction) => void;
84
+ //
85
+ // Root
86
+ //
87
+
88
+ type AlignAction = { key: AlignKey; value: AlignValue };
89
+ type CommentAction = { key: CommentKey; value: CommentValue; cellContent?: string };
90
+ type StyleAction = { key: StyleKey; value: StyleValue };
91
+
92
+ export type ToolbarAction = StyleAction | AlignAction | CommentAction;
93
+ export type ToolbarActionAnnotated = ToolbarAction & { unset?: boolean };
94
+
95
+ export type ToolbarActionType = ToolbarAction['key'];
96
+
97
+ export type ToolbarActionHandler = (action: ToolbarActionAnnotated) => void;
42
98
 
43
99
  export type ToolbarProps = ThemedClassName<
44
100
  PropsWithChildren<{
45
- onAction?: ToolbarActionHandler;
101
+ role?: string;
46
102
  }>
47
103
  >;
48
104
 
49
- const [ToolbarContextProvider, useToolbarContext] = createContext<ToolbarProps>('Toolbar');
105
+ const [ToolbarContextProvider, useToolbarContext] = createContext<{
106
+ onAction: (action: ToolbarActionAnnotated) => void;
107
+ }>('Toolbar');
108
+
109
+ // TODO(Zan): Factor out, copied this from MarkdownPlugin.
110
+ const sectionToolbarLayout =
111
+ 'bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity';
112
+
113
+ type Range = SheetType['ranges'][number];
114
+
115
+ const ToolbarRoot = ({ children, role, classNames }: ToolbarProps) => {
116
+ const { id, model, cursorFallbackRange, cursor } = useSheetContext();
117
+ const { hasAttention } = useAttention(id);
118
+ const dispatch = useIntentDispatcher();
119
+
120
+ // TODO(Zan): Externalize the toolbar action handler. E.g., Toolbar/keys should both fire events.
121
+ const handleAction = useCallback(
122
+ (action: ToolbarActionAnnotated) => {
123
+ switch (action.key) {
124
+ case 'alignment':
125
+ if (cursorFallbackRange) {
126
+ const index =
127
+ model.sheet.ranges?.findIndex(
128
+ (range) =>
129
+ range.key === action.key &&
130
+ inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),
131
+ ) ?? -1;
132
+ const nextRangeEntity = {
133
+ range: rangeToIndex(model.sheet, cursorFallbackRange),
134
+ key: action.key,
135
+ value: action.value,
136
+ };
137
+ if (index < 0) {
138
+ model.sheet.ranges?.push(nextRangeEntity);
139
+ } else if (model.sheet.ranges![index].value === action.value) {
140
+ model.sheet.ranges?.splice(index, 1);
141
+ } else {
142
+ model.sheet.ranges?.splice(index, 1, nextRangeEntity);
143
+ }
144
+ }
145
+ break;
146
+ case 'style':
147
+ if (action.unset) {
148
+ const index = model.sheet.ranges?.findIndex(
149
+ (range) =>
150
+ range.key === action.key &&
151
+ cursorFallbackRange &&
152
+ inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),
153
+ );
154
+ if (index >= 0) {
155
+ model.sheet.ranges?.splice(index, 1);
156
+ }
157
+ } else if (cursorFallbackRange) {
158
+ model.sheet.ranges?.push({
159
+ range: rangeToIndex(model.sheet, cursorFallbackRange),
160
+ key: action.key,
161
+ value: action.value,
162
+ });
163
+ }
164
+ break;
165
+ case 'comment': {
166
+ // TODO(Zan): We shouldn't hardcode the action ID.
167
+ if (cursorFallbackRange) {
168
+ void dispatch({
169
+ action: 'dxos.org/plugin/thread/action/create',
170
+ data: {
171
+ cursor: completeCellRangeToThreadCursor(cursorFallbackRange),
172
+ name: action.cellContent,
173
+ subject: model.sheet,
174
+ },
175
+ });
176
+ }
177
+ }
178
+ }
179
+ },
180
+ [model.sheet, cursorFallbackRange, cursor, dispatch],
181
+ );
50
182
 
51
- const ToolbarRoot = ({ children, onAction, classNames }: ToolbarProps) => {
52
183
  return (
53
- <ToolbarContextProvider onAction={onAction}>
54
- <DensityProvider density='fine'>
55
- <ElevationProvider elevation='chrome'>
56
- <NaturalToolbar.Root classNames={['is-full shrink-0 overflow-x-auto overflow-y-hidden p-1', classNames]}>
57
- {children}
58
- </NaturalToolbar.Root>
59
- </ElevationProvider>
60
- </DensityProvider>
184
+ <ToolbarContextProvider onAction={handleAction}>
185
+ <NaturalToolbar.Root
186
+ classNames={[
187
+ 'pli-0.5',
188
+ ...(role === 'section'
189
+ ? ['z-[2] group-focus-within/section:visible', !hasAttention && 'invisible', sectionToolbarLayout]
190
+ : ['attention-surface']),
191
+ classNames,
192
+ ]}
193
+ >
194
+ {children}
195
+ </NaturalToolbar.Root>
61
196
  </ToolbarContextProvider>
62
197
  );
63
198
  };
64
199
 
65
200
  // TODO(burdon): Generalize.
66
201
  // TODO(burdon): Detect and display current state.
67
- type ButtonProps = {
68
- type: ToolbarActionType;
69
- Icon: Icon;
70
- getState: (state: Formatting) => boolean;
71
- disabled?: (state: Formatting) => boolean;
202
+ type ButtonProps<T> = {
203
+ value: T;
204
+ icon: string;
205
+ disabled?: (state: Range) => boolean;
72
206
  };
73
207
 
74
208
  //
75
209
  // Alignment
76
210
  //
77
211
 
78
- const formatOptions: ButtonProps[] = [
79
- { type: 'date', Icon: Calendar, getState: (state) => false },
80
- { type: 'currency', Icon: CurrencyDollar, getState: (state) => false },
81
- ];
82
-
83
- const Format = () => {
84
- const { onAction } = useToolbarContext('Format');
85
- const { t } = useTranslation(SHEET_PLUGIN);
86
-
87
- return (
88
- <NaturalToolbar.ToggleGroup
89
- type='single'
90
- // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
91
- >
92
- {formatOptions.map(({ type, getState, Icon }) => (
93
- <ToolbarToggleButton
94
- key={type}
95
- value={type}
96
- Icon={Icon}
97
- // disabled={state?.blockType === 'codeblock'}
98
- // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
99
- onClick={() => onAction?.({ type })}
100
- >
101
- {t(`toolbar ${type} label`)}
102
- </ToolbarToggleButton>
103
- ))}
104
- </NaturalToolbar.ToggleGroup>
105
- );
106
- };
107
-
108
- const alignmentOptions: ButtonProps[] = [
109
- { type: 'left', Icon: TextAlignLeft, getState: (state) => false },
110
- { type: 'center', Icon: TextAlignCenter, getState: (state) => false },
111
- { type: 'right', Icon: TextAlignRight, getState: (state) => false },
212
+ const alignmentOptions: ButtonProps<AlignValue>[] = [
213
+ { value: 'start', icon: 'ph--text-align-left--regular' },
214
+ { value: 'center', icon: 'ph--text-align-center--regular' },
215
+ { value: 'end', icon: 'ph--text-align-right--regular' },
112
216
  ];
113
217
 
114
218
  const Alignment = () => {
219
+ const { cursor, model } = useSheetContext();
115
220
  const { onAction } = useToolbarContext('Alignment');
116
221
  const { t } = useTranslation(SHEET_PLUGIN);
117
222
 
223
+ // TODO(thure): Can this O(n) call be memoized?
224
+ const value = cursor
225
+ ? model.sheet.ranges?.findLast(
226
+ ({ range, key }) => key === alignKey && inRange(rangeFromIndex(model.sheet, range), cursor),
227
+ )?.value
228
+ : undefined;
229
+
118
230
  return (
119
231
  <NaturalToolbar.ToggleGroup
120
232
  type='single'
121
- // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
233
+ value={
234
+ // TODO(thure): providing `undefined` leaves the last item active which was active rather than showing none.
235
+ value ?? 'never'
236
+ }
237
+ onValueChange={(value: AlignValue) => onAction?.({ key: alignKey, value })}
122
238
  >
123
- {alignmentOptions.map(({ type, getState, Icon }) => (
124
- <ToolbarToggleButton
125
- key={type}
126
- value={type}
127
- Icon={Icon}
128
- // disabled={state?.blockType === 'codeblock'}
129
- // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
130
- onClick={() => onAction?.({ type })}
131
- >
132
- {t(`toolbar ${type} label`)}
133
- </ToolbarToggleButton>
239
+ {alignmentOptions.map(({ value, icon }) => (
240
+ <ToolbarItem itemType='toggleGroupItem' key={value} value={value} icon={icon}>
241
+ {t('toolbar action label', {
242
+ key: t(`range key ${alignKey} label`),
243
+ value: t(`range value ${value} label`),
244
+ })}
245
+ </ToolbarItem>
134
246
  ))}
135
247
  </NaturalToolbar.ToggleGroup>
136
248
  );
137
249
  };
138
250
 
139
- const styleOptions: ButtonProps[] = [
140
- { type: 'clear', Icon: Eraser, getState: (state) => false },
141
- { type: 'highlight', Icon: HighlighterCircle, getState: (state) => false },
251
+ const styleOptions: ButtonProps<StyleValue>[] = [
252
+ { value: 'highlight', icon: 'ph--highlighter--regular' },
253
+ { value: 'softwrap', icon: 'ph--paragraph--regular' },
142
254
  ];
143
255
 
144
256
  const Styles = () => {
145
- const { onAction } = useToolbarContext('Alignment');
257
+ const { cursorFallbackRange, model } = useSheetContext();
258
+ const { onAction } = useToolbarContext('Styles');
146
259
  const { t } = useTranslation(SHEET_PLUGIN);
147
260
 
261
+ // TODO(thure): Can this O(n) call be memoized?
262
+ const activeValues = cursorFallbackRange
263
+ ? model.sheet.ranges
264
+ ?.filter(
265
+ ({ range, key }) => key === 'style' && inRange(rangeFromIndex(model.sheet, range), cursorFallbackRange.from),
266
+ )
267
+ .reduce((acc, { value }) => {
268
+ acc.add(value);
269
+ return acc;
270
+ }, new Set())
271
+ : undefined;
272
+
148
273
  return (
149
- <NaturalToolbar.ToggleGroup
150
- type='single'
151
- // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
152
- >
153
- {styleOptions.map(({ type, getState, Icon }) => (
154
- <ToolbarToggleButton
155
- key={type}
156
- value={type}
157
- Icon={Icon}
158
- // disabled={state?.blockType === 'codeblock'}
159
- // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
160
- onClick={() => onAction?.({ type })}
274
+ <>
275
+ {styleOptions.map(({ value, icon }) => (
276
+ <ToolbarItem
277
+ itemType='toggle'
278
+ key={value}
279
+ pressed={activeValues?.has(value)}
280
+ onPressedChange={(nextPressed: boolean) => {
281
+ onAction?.({ key: 'style', value, unset: !nextPressed });
282
+ }}
283
+ icon={icon}
161
284
  >
162
- {t(`toolbar ${type} label`)}
163
- </ToolbarToggleButton>
285
+ {t('toolbar action label', {
286
+ key: t(`range key ${styleKey} label`),
287
+ value: t(`range value ${value} label`),
288
+ })}
289
+ </ToolbarItem>
164
290
  ))}
165
- </NaturalToolbar.ToggleGroup>
291
+ </>
166
292
  );
167
293
  };
168
294
 
@@ -171,18 +297,47 @@ const Styles = () => {
171
297
  //
172
298
 
173
299
  const Actions = () => {
174
- // const { onAction } = useToolbarContext('Actions');
300
+ const { onAction } = useToolbarContext('Actions');
301
+ const { cursorFallbackRange, cursor, model } = useSheetContext();
175
302
  const { t } = useTranslation(SHEET_PLUGIN);
303
+
304
+ // TODO(thure): Can this O(n) call be memoized?
305
+ const overlapsCommentAnchor = (model.sheet.threads ?? [])
306
+ .filter(nonNullable)
307
+ .filter((thread) => thread.status !== 'resolved')
308
+ .some((thread) => {
309
+ if (!cursorFallbackRange) {
310
+ return false;
311
+ }
312
+ return rangeToIndex(model.sheet, cursorFallbackRange) === thread.anchor;
313
+ });
314
+
315
+ const tooltipLabelKey = !cursor
316
+ ? 'no cursor label'
317
+ : overlapsCommentAnchor
318
+ ? 'selection overlaps existing comment label'
319
+ : 'comment label';
320
+
176
321
  return (
177
- <ToolbarButton
322
+ <ToolbarItem
323
+ itemType='button'
178
324
  value='comment'
179
- Icon={ChatText}
325
+ icon='ph--chat-text--regular'
180
326
  data-testid='editor.toolbar.comment'
181
- // onClick={() => onAction?.({ type: 'comment' })}
182
- // disabled={!state || state.comment || !state.selection}
327
+ onClick={() => {
328
+ if (!cursorFallbackRange) {
329
+ return;
330
+ }
331
+ return onAction?.({
332
+ key: 'comment',
333
+ value: rangeToIndex(model.sheet, cursorFallbackRange),
334
+ cellContent: model.getCellText(cursorFallbackRange.from),
335
+ });
336
+ }}
337
+ disabled={!cursorFallbackRange || overlapsCommentAnchor}
183
338
  >
184
- {t('comment label')}
185
- </ToolbarButton>
339
+ {t(tooltipLabelKey)}
340
+ </ToolbarItem>
186
341
  );
187
342
  };
188
343
 
@@ -190,7 +345,6 @@ export const Toolbar = {
190
345
  Root: ToolbarRoot,
191
346
  Separator: ToolbarSeparator,
192
347
  Alignment,
193
- Format,
194
348
  Styles,
195
349
  Actions,
196
350
  };
@@ -2,9 +2,11 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import React from 'react';
5
+ import { lazy } from 'react';
6
6
 
7
7
  export * from './ComputeGraph';
8
+ export * from './GridSheet';
9
+ export * from './RangeList';
10
+ export * from './SheetContext';
8
11
 
9
- // Lazily load components for content surfaces.
10
- export const SheetContainer = React.lazy(() => import('./SheetContainer'));
12
+ export const SheetContainer = lazy(() => import('./SheetContainer'));
@@ -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;