@dxos/plugin-sheet 0.6.12-main.f9d0246 → 0.6.12-staging.0b4bb48

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 (263) hide show
  1. package/dist/lib/browser/{chunk-ZLJ2GRE2.mjs → SheetContainer-U4H5D34A.mjs} +240 -1151
  2. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-APHOLYUB.mjs +175 -0
  4. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-Z2XOOC2R.mjs → chunk-D5AGLXJP.mjs} +678 -385
  6. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-WZMOZKQZ.mjs → chunk-FUAGSXA4.mjs} +16 -9
  8. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
  9. package/dist/lib/{node-esm/chunk-IU2L277A.mjs → browser/chunk-JRL5LGCE.mjs} +5 -4
  10. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-NU4PBN33.mjs +8 -0
  12. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +60 -74
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/meta.mjs +1 -1
  17. package/dist/lib/browser/testing.mjs +92 -0
  18. package/dist/lib/browser/testing.mjs.map +7 -0
  19. package/dist/lib/browser/types.mjs +6 -4
  20. package/dist/lib/node/{chunk-6DQABRGJ.cjs → SheetContainer-AXQV3ZT5.cjs} +279 -1182
  21. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-P5QYYEHQ.cjs → chunk-5KKJ4NPP.cjs} +676 -388
  23. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-BNARJ5GM.cjs → chunk-BJ6ZD7MN.cjs} +18 -5
  25. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +7 -0
  26. package/dist/lib/node/chunk-CN3RPESU.cjs +202 -0
  27. package/dist/lib/node/chunk-CN3RPESU.cjs.map +7 -0
  28. package/dist/lib/node/{chunk-AOP42UAA.cjs → chunk-DSYKOI4E.cjs} +21 -13
  29. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +7 -0
  30. package/dist/lib/node/chunk-PYXHNAAK.cjs +40 -0
  31. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +7 -0
  32. package/dist/lib/node/index.cjs +66 -86
  33. package/dist/lib/node/index.cjs.map +3 -3
  34. package/dist/lib/node/meta.cjs +3 -3
  35. package/dist/lib/node/meta.cjs.map +1 -1
  36. package/dist/lib/node/meta.json +1 -1
  37. package/dist/lib/node/testing.cjs +111 -0
  38. package/dist/lib/node/testing.cjs.map +7 -0
  39. package/dist/lib/node/types.cjs +12 -10
  40. package/dist/lib/node/types.cjs.map +2 -2
  41. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  42. package/dist/types/src/components/CellEditor/CellEditor.d.ts +3 -23
  43. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -1
  44. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts +2 -2
  45. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -1
  46. package/dist/types/src/components/CellEditor/extension.d.ts +1 -1
  47. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
  48. package/dist/types/src/{graph → components/ComputeGraph}/async-function.d.ts +2 -8
  49. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
  50. package/dist/types/src/{graph/testing/custom-function.d.ts → components/ComputeGraph/custom.d.ts} +2 -4
  51. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -0
  52. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -0
  53. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +12 -0
  54. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +1 -0
  55. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +2 -0
  56. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +1 -0
  57. package/dist/types/src/components/ComputeGraph/graph.d.ts +26 -0
  58. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +1 -0
  59. package/dist/types/src/components/ComputeGraph/index.d.ts +3 -1
  60. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  61. package/dist/types/src/components/Sheet/Sheet.d.ts +1 -1
  62. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
  63. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +6 -5
  64. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  65. package/dist/types/src/components/Sheet/formatting.d.ts +14 -0
  66. package/dist/types/src/components/Sheet/formatting.d.ts.map +1 -0
  67. package/dist/types/src/components/Sheet/grid.d.ts +2 -2
  68. package/dist/types/src/components/Sheet/grid.d.ts.map +1 -1
  69. package/dist/types/src/components/Sheet/nav.d.ts +3 -3
  70. package/dist/types/src/components/Sheet/nav.d.ts.map +1 -1
  71. package/dist/types/src/components/Sheet/sheet-context.d.ts +7 -8
  72. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
  73. package/dist/types/src/components/SheetContainer.d.ts +3 -2
  74. package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
  75. package/dist/types/src/components/Toolbar/Toolbar.d.ts +3 -19
  76. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  77. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +13 -18
  78. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  79. package/dist/types/src/components/index.d.ts +2 -2
  80. package/dist/types/src/components/index.d.ts.map +1 -1
  81. package/dist/types/src/meta.d.ts +4 -1
  82. package/dist/types/src/meta.d.ts.map +1 -1
  83. package/dist/types/src/{graph/function-defs.d.ts → model/functions.d.ts} +1 -1
  84. package/dist/types/src/model/functions.d.ts.map +1 -0
  85. package/dist/types/src/model/index.d.ts +3 -2
  86. package/dist/types/src/model/index.d.ts.map +1 -1
  87. package/dist/types/src/model/model.browser.test.d.ts +2 -0
  88. package/dist/types/src/model/model.browser.test.d.ts.map +1 -0
  89. package/dist/types/src/model/{sheet-model.d.ts → model.d.ts} +65 -10
  90. package/dist/types/src/model/model.d.ts.map +1 -0
  91. package/dist/types/src/{defs → model}/types.d.ts +3 -8
  92. package/dist/types/src/model/types.d.ts.map +1 -0
  93. package/dist/types/src/model/types.test.d.ts.map +1 -0
  94. package/dist/types/src/model/util.d.ts +15 -0
  95. package/dist/types/src/model/util.d.ts.map +1 -0
  96. package/dist/types/src/testing.d.ts +9 -0
  97. package/dist/types/src/testing.d.ts.map +1 -0
  98. package/dist/types/src/translations.d.ts +12 -17
  99. package/dist/types/src/translations.d.ts.map +1 -1
  100. package/dist/types/src/types.d.ts +5 -86
  101. package/dist/types/src/types.d.ts.map +1 -1
  102. package/package.json +41 -48
  103. package/src/SheetPlugin.tsx +73 -48
  104. package/src/components/CellEditor/CellEditor.stories.tsx +4 -5
  105. package/src/components/CellEditor/CellEditor.tsx +9 -59
  106. package/src/components/CellEditor/extension.test.ts +5 -4
  107. package/src/components/CellEditor/extension.ts +3 -1
  108. package/src/{graph → components/ComputeGraph}/async-function.ts +6 -15
  109. package/src/{graph/testing/custom-function.ts → components/ComputeGraph/custom.ts} +7 -11
  110. package/src/{graph → components/ComputeGraph}/edge-function.ts +3 -3
  111. package/src/components/ComputeGraph/graph-context.tsx +50 -0
  112. package/src/components/ComputeGraph/graph.browser.test.ts +50 -0
  113. package/src/components/ComputeGraph/graph.ts +62 -0
  114. package/src/components/ComputeGraph/index.ts +3 -1
  115. package/src/components/Sheet/Sheet.stories.tsx +88 -52
  116. package/src/components/Sheet/Sheet.tsx +18 -57
  117. package/src/{model/formatting-model.ts → components/Sheet/formatting.ts} +13 -20
  118. package/src/components/Sheet/grid.ts +3 -3
  119. package/src/components/Sheet/nav.ts +19 -19
  120. package/src/components/Sheet/sheet-context.tsx +80 -18
  121. package/src/components/SheetContainer.tsx +19 -73
  122. package/src/components/Toolbar/Toolbar.tsx +12 -53
  123. package/src/components/index.ts +0 -1
  124. package/src/meta.tsx +5 -1
  125. package/src/model/index.ts +3 -2
  126. package/src/model/model.browser.test.ts +100 -0
  127. package/src/model/model.ts +550 -0
  128. package/src/{defs → model}/types.test.ts +9 -8
  129. package/src/{defs → model}/types.ts +14 -24
  130. package/src/model/util.ts +36 -0
  131. package/src/testing.ts +50 -0
  132. package/src/translations.ts +1 -6
  133. package/src/types.ts +6 -31
  134. package/dist/lib/browser/SheetContainer-VISF3VUB.mjs +0 -261
  135. package/dist/lib/browser/SheetContainer-VISF3VUB.mjs.map +0 -7
  136. package/dist/lib/browser/chunk-QILRZNE5.mjs +0 -15
  137. package/dist/lib/browser/chunk-QILRZNE5.mjs.map +0 -7
  138. package/dist/lib/browser/chunk-WZMOZKQZ.mjs.map +0 -7
  139. package/dist/lib/browser/chunk-Z2XOOC2R.mjs.map +0 -7
  140. package/dist/lib/browser/chunk-ZLJ2GRE2.mjs.map +0 -7
  141. package/dist/lib/browser/graph-4XFKIHRL.mjs +0 -21
  142. package/dist/lib/browser/graph-4XFKIHRL.mjs.map +0 -7
  143. package/dist/lib/node/SheetContainer-2MEALQWW.cjs +0 -279
  144. package/dist/lib/node/SheetContainer-2MEALQWW.cjs.map +0 -7
  145. package/dist/lib/node/chunk-6DQABRGJ.cjs.map +0 -7
  146. package/dist/lib/node/chunk-AOP42UAA.cjs.map +0 -7
  147. package/dist/lib/node/chunk-BNARJ5GM.cjs.map +0 -7
  148. package/dist/lib/node/chunk-P5QYYEHQ.cjs.map +0 -7
  149. package/dist/lib/node/graph-2LRDUXBZ.cjs +0 -43
  150. package/dist/lib/node/graph-2LRDUXBZ.cjs.map +0 -7
  151. package/dist/lib/node-esm/SheetContainer-RPSUSXWS.mjs +0 -262
  152. package/dist/lib/node-esm/SheetContainer-RPSUSXWS.mjs.map +0 -7
  153. package/dist/lib/node-esm/chunk-4MM7THJW.mjs +0 -2944
  154. package/dist/lib/node-esm/chunk-4MM7THJW.mjs.map +0 -7
  155. package/dist/lib/node-esm/chunk-5RLTCIE2.mjs +0 -2684
  156. package/dist/lib/node-esm/chunk-5RLTCIE2.mjs.map +0 -7
  157. package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +0 -7
  158. package/dist/lib/node-esm/chunk-RR2AO4SM.mjs +0 -76
  159. package/dist/lib/node-esm/chunk-RR2AO4SM.mjs.map +0 -7
  160. package/dist/lib/node-esm/graph-WG5EKOMO.mjs +0 -22
  161. package/dist/lib/node-esm/graph-WG5EKOMO.mjs.map +0 -7
  162. package/dist/lib/node-esm/index.mjs +0 -263
  163. package/dist/lib/node-esm/index.mjs.map +0 -7
  164. package/dist/lib/node-esm/meta.json +0 -1
  165. package/dist/lib/node-esm/meta.mjs +0 -10
  166. package/dist/lib/node-esm/meta.mjs.map +0 -7
  167. package/dist/lib/node-esm/types.mjs +0 -21
  168. package/dist/lib/node-esm/types.mjs.map +0 -7
  169. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +0 -11
  170. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +0 -1
  171. package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -10
  172. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
  173. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +0 -9
  174. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
  175. package/dist/types/src/components/GridSheet/util.d.ts +0 -7
  176. package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
  177. package/dist/types/src/components/Sheet/decorations.d.ts +0 -24
  178. package/dist/types/src/components/Sheet/decorations.d.ts.map +0 -1
  179. package/dist/types/src/components/Sheet/threads.d.ts +0 -2
  180. package/dist/types/src/components/Sheet/threads.d.ts.map +0 -1
  181. package/dist/types/src/defs/index.d.ts +0 -3
  182. package/dist/types/src/defs/index.d.ts.map +0 -1
  183. package/dist/types/src/defs/types.d.ts.map +0 -1
  184. package/dist/types/src/defs/types.test.d.ts.map +0 -1
  185. package/dist/types/src/defs/util.d.ts +0 -43
  186. package/dist/types/src/defs/util.d.ts.map +0 -1
  187. package/dist/types/src/extensions/compute.d.ts +0 -9
  188. package/dist/types/src/extensions/compute.d.ts.map +0 -1
  189. package/dist/types/src/extensions/compute.stories.d.ts +0 -26
  190. package/dist/types/src/extensions/compute.stories.d.ts.map +0 -1
  191. package/dist/types/src/extensions/index.d.ts +0 -2
  192. package/dist/types/src/extensions/index.d.ts.map +0 -1
  193. package/dist/types/src/graph/async-function.d.ts.map +0 -1
  194. package/dist/types/src/graph/compute-graph.d.ts +0 -84
  195. package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
  196. package/dist/types/src/graph/compute-graph.stories.d.ts +0 -10
  197. package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
  198. package/dist/types/src/graph/compute-graph.test.d.ts +0 -2
  199. package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
  200. package/dist/types/src/graph/compute-node.d.ts +0 -26
  201. package/dist/types/src/graph/compute-node.d.ts.map +0 -1
  202. package/dist/types/src/graph/edge-function.d.ts.map +0 -1
  203. package/dist/types/src/graph/function-defs.d.ts.map +0 -1
  204. package/dist/types/src/graph/hyperformula.test.d.ts +0 -2
  205. package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
  206. package/dist/types/src/graph/index.d.ts +0 -4
  207. package/dist/types/src/graph/index.d.ts.map +0 -1
  208. package/dist/types/src/graph/testing/custom-function.d.ts.map +0 -1
  209. package/dist/types/src/graph/testing/index.d.ts +0 -2
  210. package/dist/types/src/graph/testing/index.d.ts.map +0 -1
  211. package/dist/types/src/graph/util.d.ts +0 -2
  212. package/dist/types/src/graph/util.d.ts.map +0 -1
  213. package/dist/types/src/hooks/hooks.stories.d.ts +0 -11
  214. package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
  215. package/dist/types/src/hooks/index.d.ts +0 -4
  216. package/dist/types/src/hooks/index.d.ts.map +0 -1
  217. package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
  218. package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
  219. package/dist/types/src/hooks/useFormattingModel.d.ts +0 -3
  220. package/dist/types/src/hooks/useFormattingModel.d.ts.map +0 -1
  221. package/dist/types/src/hooks/useSheetModel.d.ts +0 -8
  222. package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
  223. package/dist/types/src/model/formatting-model.d.ts +0 -16
  224. package/dist/types/src/model/formatting-model.d.ts.map +0 -1
  225. package/dist/types/src/model/sheet-model.d.ts.map +0 -1
  226. package/dist/types/src/sanity.test.d.ts +0 -2
  227. package/dist/types/src/sanity.test.d.ts.map +0 -1
  228. package/dist/types/src/testing/index.d.ts +0 -2
  229. package/dist/types/src/testing/index.d.ts.map +0 -1
  230. package/dist/types/src/testing/testing.d.ts +0 -8
  231. package/dist/types/src/testing/testing.d.ts.map +0 -1
  232. package/dist/vendor/hyperformula.mjs +0 -37145
  233. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +0 -20
  234. package/src/components/GridSheet/GridSheet.stories.tsx +0 -36
  235. package/src/components/GridSheet/GridSheet.tsx +0 -153
  236. package/src/components/GridSheet/util.ts +0 -108
  237. package/src/components/Sheet/decorations.ts +0 -62
  238. package/src/components/Sheet/threads.tsx +0 -205
  239. package/src/defs/index.ts +0 -6
  240. package/src/defs/util.ts +0 -151
  241. package/src/extensions/compute.stories.tsx +0 -153
  242. package/src/extensions/compute.ts +0 -131
  243. package/src/extensions/index.ts +0 -5
  244. package/src/graph/compute-graph.stories.tsx +0 -93
  245. package/src/graph/compute-graph.test.ts +0 -127
  246. package/src/graph/compute-graph.ts +0 -313
  247. package/src/graph/compute-node.ts +0 -62
  248. package/src/graph/hyperformula.test.ts +0 -15
  249. package/src/graph/index.ts +0 -7
  250. package/src/graph/testing/index.ts +0 -5
  251. package/src/graph/util.ts +0 -8
  252. package/src/hooks/hooks.stories.tsx +0 -50
  253. package/src/hooks/index.ts +0 -7
  254. package/src/hooks/useComputeGraph.ts +0 -21
  255. package/src/hooks/useFormattingModel.ts +0 -11
  256. package/src/hooks/useSheetModel.ts +0 -40
  257. package/src/model/sheet-model.ts +0 -414
  258. package/src/sanity.test.ts +0 -40
  259. package/src/testing/index.ts +0 -5
  260. package/src/testing/testing.tsx +0 -68
  261. /package/dist/types/src/{graph → components/ComputeGraph}/edge-function.d.ts +0 -0
  262. /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
  263. /package/src/{graph/function-defs.ts → model/functions.ts} +0 -0
@@ -2,70 +2,84 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { GridNine } from '@phosphor-icons/react';
5
+ import { type IconProps, GridNine } from '@phosphor-icons/react';
6
6
  import React from 'react';
7
7
 
8
- import { NavigationAction, parseIntentPlugin, resolvePlugin, type PluginDefinition } from '@dxos/app-framework';
9
- import { invariant } from '@dxos/invariant';
8
+ import {
9
+ NavigationAction,
10
+ parseIntentPlugin,
11
+ resolvePlugin,
12
+ type PluginDefinition,
13
+ type LayoutCoordinate,
14
+ } from '@dxos/app-framework';
15
+ import { create } from '@dxos/echo-schema';
10
16
  import { parseClientPlugin } from '@dxos/plugin-client';
11
- import { createExtension, isActionGroup, type ActionGroup } from '@dxos/plugin-graph';
17
+ import { type ActionGroup, createExtension, isActionGroup } from '@dxos/plugin-graph';
12
18
  import { FunctionType } from '@dxos/plugin-script/types';
13
19
  import { SpaceAction } from '@dxos/plugin-space';
14
20
  import { getSpace, isEchoObject } from '@dxos/react-client/echo';
15
21
 
16
- import { ComputeGraphContextProvider, SheetContainer } from './components';
17
- import { compareIndexPositions, createSheet } from './defs';
18
- import { type ComputeGraphRegistry } from './graph';
19
- import { useComputeGraph } from './hooks';
22
+ import {
23
+ createComputeGraph,
24
+ CustomPlugin,
25
+ CustomPluginTranslations,
26
+ SheetContainer,
27
+ type ComputeGraph,
28
+ } from './components';
29
+ // TODO(wittjosiah): Refactor. These are not exported from ./components due to depending on ECHO.
30
+ import { EdgeFunctionPlugin, EdgeFunctionPluginTranslations } from './components/ComputeGraph/edge-function';
31
+ import { ComputeGraphContextProvider } from './components/ComputeGraph/graph-context';
20
32
  import meta, { SHEET_PLUGIN } from './meta';
33
+ import { SheetModel } from './model';
21
34
  import translations from './translations';
22
- import { SheetAction, SheetType, type SheetPluginProvides } from './types';
35
+ import { createSheet, SheetAction, type SheetPluginProvides, SheetType } from './types';
23
36
 
24
37
  export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
25
- let graphRegistry: ComputeGraphRegistry | undefined;
38
+ let remoteFunctionUrl: string | undefined;
39
+
40
+ const graphs = create<Record<string, ComputeGraph>>({});
41
+ const setGraph = (key: string, graph: ComputeGraph) => {
42
+ graphs[key] = graph;
43
+ };
26
44
 
27
45
  return {
28
46
  meta,
29
47
  ready: async (plugins) => {
30
48
  const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
31
- invariant(client);
32
- let remoteFunctionUrl: string | undefined;
49
+ if (!client) {
50
+ return;
51
+ }
52
+
33
53
  if (client.config.values.runtime?.services?.edge?.url) {
34
54
  const url = new URL('/functions', client.config.values.runtime?.services?.edge?.url);
35
55
  url.protocol = 'https';
36
56
  remoteFunctionUrl = url.toString();
37
57
  }
38
-
39
- // Async import removes direct dependency on hyperformula.
40
- const { ComputeGraphRegistry } = await import('./graph');
41
- graphRegistry = new ComputeGraphRegistry({ remoteFunctionUrl });
42
58
  },
43
59
  provides: {
44
60
  context: ({ children }) => {
45
- invariant(graphRegistry);
46
- return <ComputeGraphContextProvider registry={graphRegistry}>{children}</ComputeGraphContextProvider>;
61
+ return (
62
+ <ComputeGraphContextProvider graphs={graphs} setGraph={setGraph}>
63
+ {children}
64
+ </ComputeGraphContextProvider>
65
+ );
47
66
  },
48
67
  metadata: {
49
68
  records: {
50
69
  [SheetType.typename]: {
51
- label: (object: any) => (object instanceof SheetType ? object.name : undefined),
70
+ label: (object: any) => (object instanceof SheetType ? object.title : undefined),
52
71
  placeholder: ['sheet title placeholder', { ns: SHEET_PLUGIN }],
53
- icon: 'ph--grid-nine--regular',
72
+ icon: (props: IconProps) => <GridNine {...props} />,
73
+ iconSymbol: 'ph--grid-nine--regular',
54
74
  },
55
75
  },
56
76
  },
57
77
  translations,
58
78
  echo: {
59
79
  // TODO(wittjosiah): Factor out to common package/plugin.
60
- // FunctionType is currently registered here in case script plugin isn't enabled.
80
+ // FunctionType is currently registered here in case script plugin isn't enabled.
61
81
  schema: [SheetType, FunctionType],
62
82
  },
63
- space: {
64
- onSpaceCreate: {
65
- label: ['create sheet label', { ns: SHEET_PLUGIN }],
66
- action: SheetAction.CREATE,
67
- },
68
- },
69
83
  graph: {
70
84
  builder: (plugins) => {
71
85
  const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
@@ -99,7 +113,8 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
99
113
  },
100
114
  properties: {
101
115
  label: ['create sheet label', { ns: SHEET_PLUGIN }],
102
- icon: 'ph--grid-nine--regular',
116
+ icon: (props: IconProps) => <GridNine {...props} />,
117
+ iconSymbol: 'ph--grid-nine--regular',
103
118
  testId: 'sheetPlugin.createObject',
104
119
  },
105
120
  },
@@ -108,15 +123,6 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
108
123
  });
109
124
  },
110
125
  },
111
- markdown: {
112
- // TODO(burdon): Facet to get current space/compute graph.
113
- extensions: ({ document }) => {
114
- return undefined;
115
- // return [
116
- // compute(document)
117
- // ];
118
- },
119
- },
120
126
  stack: {
121
127
  creators: [
122
128
  {
@@ -132,20 +138,23 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
132
138
  },
133
139
  ],
134
140
  },
135
- thread: {
136
- predicate: (data) => data instanceof SheetType,
137
- createSort: (sheet) => (indexA, indexB) =>
138
- !indexA || !indexB ? 0 : compareIndexPositions(sheet, indexA, indexB),
139
- },
140
141
  surface: {
141
- component: ({ data, role }) => {
142
- const space = isEchoObject(data.object) ? getSpace(data.object) : undefined;
143
- const graph = useComputeGraph(space);
144
- if (graph && data.object instanceof SheetType) {
142
+ component: ({ data, role = 'never' }) => {
143
+ // TODO(burdon): Standardize wrapper (with room for toolbar).
144
+ const space = isEchoObject(data.object) && getSpace(data.object);
145
+ if (space && data.object instanceof SheetType) {
145
146
  switch (role) {
146
147
  case 'article':
147
148
  case 'section': {
148
- return <SheetContainer graph={graph} sheet={data.object} role={role} />;
149
+ return (
150
+ <SheetContainer
151
+ sheet={data.object}
152
+ space={space}
153
+ role={role}
154
+ coordinate={data.coordinate as LayoutCoordinate}
155
+ remoteFunctionUrl={remoteFunctionUrl}
156
+ />
157
+ );
149
158
  }
150
159
  }
151
160
  }
@@ -157,7 +166,23 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
157
166
  resolver: async (intent) => {
158
167
  switch (intent.action) {
159
168
  case SheetAction.CREATE: {
160
- return { data: createSheet() };
169
+ const space = intent.data?.space;
170
+ const sheet = createSheet();
171
+ const graph =
172
+ graphs[space.id] ??
173
+ createComputeGraph(
174
+ [
175
+ { plugin: EdgeFunctionPlugin, translations: EdgeFunctionPluginTranslations },
176
+ // TODO(wittjosiah): Remove. Needed for current test sheet generated data.
177
+ { plugin: CustomPlugin, translations: CustomPluginTranslations },
178
+ ],
179
+ space,
180
+ { remoteFunctionUrl },
181
+ );
182
+ const model = new SheetModel(graph, sheet);
183
+ await model.initialize();
184
+ await model.destroy();
185
+ return { data: sheet };
161
186
  }
162
187
  }
163
188
  },
@@ -4,6 +4,7 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
+ import { HyperFormula } from 'hyperformula';
7
8
  import React, { useEffect, useMemo, useState } from 'react';
8
9
 
9
10
  import { Client } from '@dxos/client';
@@ -11,12 +12,10 @@ import { createDocAccessor, type EchoReactiveObject } from '@dxos/client/echo';
11
12
  import { automerge } from '@dxos/react-ui-editor';
12
13
  import { withTheme } from '@dxos/storybook-utils';
13
14
 
14
- import { HyperFormula } from '#hyperformula';
15
15
  import { CellEditor, type CellEditorProps } from './CellEditor';
16
16
  import { sheetExtension } from './extension';
17
- import { createSheet } from '../../defs';
18
- import { defaultFunctions } from '../../graph';
19
- import { SheetType } from '../../types';
17
+ import { defaultFunctions } from '../../model';
18
+ import { createSheet, SheetType } from '../../types';
20
19
 
21
20
  export default {
22
21
  title: 'plugin-sheet/CellEditor',
@@ -49,7 +48,7 @@ const AutomergeStory = ({ value, ...props }: StoryProps) => {
49
48
  client.addTypes([SheetType]);
50
49
 
51
50
  const sheet = createSheet();
52
- sheet.name = 'Test';
51
+ sheet.title = 'Test';
53
52
  sheet.cells[cell] = { value };
54
53
  space.db.add(sheet);
55
54
  setObject(sheet);
@@ -14,13 +14,10 @@ import {
14
14
  preventNewline,
15
15
  useTextEditor,
16
16
  } from '@dxos/react-ui-editor';
17
- import { type GridEditBox } from '@dxos/react-ui-grid';
18
-
19
- type EditorKeyEvent = Pick<KeyboardEvent<HTMLInputElement>, 'key'> & { shift?: boolean };
20
17
 
21
18
  export type EditorKeysProps = {
22
- onClose: (value: string | undefined, event: EditorKeyEvent) => void;
23
- onNav?: (value: string | undefined, event: EditorKeyEvent) => void;
19
+ onClose: (value: string | undefined) => void;
20
+ onNav?: (value: string | undefined, ev: Pick<KeyboardEvent<HTMLInputElement>, 'key'>) => void;
24
21
  };
25
22
 
26
23
  export const editorKeys = ({ onNav, onClose }: EditorKeysProps): Extension => {
@@ -60,29 +57,14 @@ export const editorKeys = ({ onNav, onClose }: EditorKeysProps): Extension => {
60
57
  {
61
58
  key: 'Enter',
62
59
  run: (editor) => {
63
- onClose(editor.state.doc.toString(), { key: 'Enter' });
64
- return true;
65
- },
66
- shift: (editor) => {
67
- onClose(editor.state.doc.toString(), { key: 'Enter', shift: true });
68
- return true;
69
- },
70
- },
71
- {
72
- key: 'Tab',
73
- run: (editor) => {
74
- onClose(editor.state.doc.toString(), { key: 'Tab' });
75
- return true;
76
- },
77
- shift: (editor) => {
78
- onClose(editor.state.doc.toString(), { key: 'Tab', shift: true });
60
+ onClose(editor.state.doc.toString());
79
61
  return true;
80
62
  },
81
63
  },
82
64
  {
83
65
  key: 'Escape',
84
66
  run: () => {
85
- onClose(undefined, { key: 'Escape' });
67
+ onClose(undefined);
86
68
  return true;
87
69
  },
88
70
  },
@@ -92,35 +74,10 @@ export const editorKeys = ({ onNav, onClose }: EditorKeysProps): Extension => {
92
74
  export type CellEditorProps = {
93
75
  value?: string;
94
76
  extension?: Extension;
95
- variant?: keyof typeof editorVariants;
96
- box?: GridEditBox;
97
- gridId?: string;
98
77
  } & Pick<UseTextEditorProps, 'autoFocus'> &
99
78
  Pick<DOMAttributes<HTMLInputElement>, 'onBlur' | 'onKeyDown'>;
100
79
 
101
- const editorVariants = {
102
- // TODO(thure): remove when legacy is no longer used.
103
- legacy: {
104
- root: 'flex w-full',
105
- editor: 'flex w-full [&>.cm-scroller]:scrollbar-none',
106
- content: '!px-2 !py-1',
107
- },
108
- grid: {
109
- root: 'absolute z-[1]',
110
- editor: '[&>.cm-scroller]:scrollbar-none tabular-nums',
111
- content: '!border !border-transparent !p-0.5',
112
- },
113
- };
114
-
115
- export const CellEditor = ({
116
- value,
117
- extension,
118
- autoFocus,
119
- onBlur,
120
- variant = 'legacy',
121
- box,
122
- gridId,
123
- }: CellEditorProps) => {
80
+ export const CellEditor = ({ value, extension, autoFocus, onBlur }: CellEditorProps) => {
124
81
  const { themeMode } = useThemeContext();
125
82
  const { parentRef } = useTextEditor(() => {
126
83
  return {
@@ -141,23 +98,16 @@ export const CellEditor = ({
141
98
  themeMode,
142
99
  slots: {
143
100
  editor: {
144
- className: editorVariants[variant].editor,
101
+ className: 'flex w-full [&>.cm-scroller]:scrollbar-none',
145
102
  },
146
103
  content: {
147
- className: editorVariants[variant].content,
104
+ className: '!px-2 !py-1',
148
105
  },
149
106
  },
150
107
  }),
151
108
  ],
152
109
  };
153
- }, [extension, autoFocus, value, variant, onBlur]);
110
+ }, [extension]);
154
111
 
155
- return (
156
- <div
157
- ref={parentRef}
158
- className={editorVariants[variant].root}
159
- style={box}
160
- {...(gridId && { 'data-grid': gridId })}
161
- />
162
- );
112
+ return <div ref={parentRef} className='flex w-full' />;
163
113
  };
@@ -6,11 +6,12 @@ import { CompletionContext, type CompletionSource } from '@codemirror/autocomple
6
6
  import { EditorState } from '@codemirror/state';
7
7
  // @ts-ignore
8
8
  import { testTree } from '@lezer/generator/test';
9
+ import { expect } from 'chai';
9
10
  import { spreadsheet } from 'codemirror-lang-spreadsheet';
10
- import { describe, expect, test } from 'vitest';
11
+ import { describe, test } from 'vitest';
11
12
 
12
13
  import { sheetExtension } from './extension';
13
- import { defaultFunctions } from '../../graph';
14
+ import { defaultFunctions } from '../../model/functions';
14
15
 
15
16
  describe('formula parser', () => {
16
17
  const {
@@ -36,8 +37,8 @@ describe('formula parser', () => {
36
37
  extensions: sheetExtension({ functions }),
37
38
  });
38
39
 
39
- const [fn] = state.languageDataAt<CompletionSource>('autocomplete', text.length);
40
- const result = await fn(new CompletionContext(state, text.length, true));
40
+ const [f] = state.languageDataAt<CompletionSource>('autocomplete', text.length);
41
+ const result = await f(new CompletionContext(state, text.length, true));
41
42
  expect(result?.options).to.have.length(1);
42
43
  });
43
44
  });
@@ -20,7 +20,7 @@ import { spreadsheet } from 'codemirror-lang-spreadsheet';
20
20
 
21
21
  import { mx } from '@dxos/react-ui-theme';
22
22
 
23
- import { type FunctionDefinition } from '../../graph';
23
+ import { type FunctionDefinition } from '../../model';
24
24
 
25
25
  /**
26
26
  * https://codemirror.net/examples/styling
@@ -165,6 +165,8 @@ export const sheetExtension = ({ functions = [] }: SheetExtensionOptions): Exten
165
165
  icons: false,
166
166
  tooltipClass: () =>
167
167
  mx(
168
+ // TODO(burdon): Factor out fragments.
169
+ // TODO(burdon): Size to make width same as column.
168
170
  '!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]',
169
171
  '[&>ul>li[aria-selected]]:!bg-accentSurface',
170
172
  'border-separator',
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
5
+ import { CellError, ErrorType, EmptyValue, FunctionPlugin, type HyperFormula } from 'hyperformula';
6
6
  import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
7
7
  import { type InterpreterValue } from 'hyperformula/typings/interpreter/InterpreterValue';
8
8
  import { type ProcedureAst } from 'hyperformula/typings/parser';
@@ -12,8 +12,6 @@ import { debounce, type UnsubscribeCallback } from '@dxos/async';
12
12
  import { type Space } from '@dxos/client/echo';
13
13
  import { log } from '@dxos/log';
14
14
 
15
- import { CellError, ErrorType, EmptyValue, FunctionPlugin, type HyperFormula } from '#hyperformula';
16
-
17
15
  // TODO(burdon): API gateways!
18
16
  // https://publicapis.io
19
17
  // https://api-ninjas.com/api/cryptoprice
@@ -23,11 +21,6 @@ import { CellError, ErrorType, EmptyValue, FunctionPlugin, type HyperFormula } f
23
21
  // TODO(burdon): Create wrapper.
24
22
  export type AsyncFunction = (...args: any) => Promise<InterpreterValue>;
25
23
 
26
- export type FunctionUpdateEvent = {
27
- name: string;
28
- cell: SimpleCellAddress;
29
- };
30
-
31
24
  export type FunctionOptions = {
32
25
  ttl?: number;
33
26
  };
@@ -36,7 +29,6 @@ export type FunctionContextOptions = {
36
29
  defaultTtl: number;
37
30
  recalculationDelay: number;
38
31
  remoteFunctionUrl: string;
39
- onUpdate?: (update: FunctionUpdateEvent) => void;
40
32
  };
41
33
 
42
34
  export const defaultFunctionContextOptions: FunctionContextOptions = {
@@ -73,21 +65,20 @@ export class FunctionContext {
73
65
  private _invocations: Record<string, number> = {};
74
66
 
75
67
  private readonly _options: FunctionContextOptions;
76
-
77
- // Debounced update handler.
78
- private readonly _onUpdate: (update: FunctionUpdateEvent) => void;
68
+ private readonly _onUpdate: () => void;
79
69
 
80
70
  constructor(
81
71
  private readonly _hf: HyperFormula,
82
72
  private readonly _space: Space | undefined,
73
+ onUpdate: (context: FunctionContext) => void,
83
74
  _options?: Partial<FunctionContextOptions>,
84
75
  ) {
85
76
  this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
86
- this._onUpdate = debounce((update) => {
77
+ this._onUpdate = debounce(() => {
87
78
  // TODO(burdon): Better way to trigger recalculation?
88
79
  // NOTE: rebuildAndRecalculate resets the undo history.
89
80
  this._hf.resumeEvaluation();
90
- this._options.onUpdate?.(update);
81
+ onUpdate(this);
91
82
  }, this._options.recalculationDelay);
92
83
  }
93
84
 
@@ -143,7 +134,7 @@ export class FunctionContext {
143
134
  const value = await cb(...args);
144
135
  this._cache.set(invocationKey, { value, ts: Date.now() });
145
136
  log('set', { cell, value });
146
- this._onUpdate({ name, cell });
137
+ this._onUpdate();
147
138
  } catch (err) {
148
139
  // TODO(burdon): Show error to user.
149
140
  log.warn('failed', { cell, err });
@@ -2,15 +2,18 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { FunctionArgumentType } from 'hyperformula';
5
6
  import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
6
7
  import { type ProcedureAst } from 'hyperformula/typings/parser';
7
8
 
8
9
  import { getDeep } from '@dxos/util';
9
10
 
10
- import { FunctionArgumentType } from '#hyperformula';
11
- import { type AsyncFunction, FunctionPluginAsync } from '../async-function';
12
- import { type ComputeGraphPlugin } from '../compute-graph';
13
- import { parseNumberString } from '../util';
11
+ import { type AsyncFunction, FunctionPluginAsync } from './async-function';
12
+
13
+ // TODO(burdon): Factor out.
14
+ const parseNumberString = (str: string): number => {
15
+ return parseFloat(str.replace(/[^\d.]/g, ''));
16
+ };
14
17
 
15
18
  /**
16
19
  * https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
@@ -65,10 +68,3 @@ export const CustomPluginTranslations = {
65
68
  CRYPTO: 'CRYPTO',
66
69
  },
67
70
  };
68
-
69
- export const testPlugins: ComputeGraphPlugin[] = [
70
- {
71
- plugin: CustomPlugin,
72
- translations: CustomPluginTranslations,
73
- },
74
- ];
@@ -3,6 +3,7 @@
3
3
  //
4
4
 
5
5
  import { effect } from '@preact/signals-core';
6
+ import { CellError, ErrorType, FunctionArgumentType } from 'hyperformula';
6
7
  import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
7
8
  import { type ProcedureAst } from 'hyperformula/typings/parser';
8
9
 
@@ -12,7 +13,6 @@ import { getUserFunctionUrlInMetadata } from '@dxos/plugin-script/edge';
12
13
  import { FunctionType } from '@dxos/plugin-script/types';
13
14
  import { nonNullable } from '@dxos/util';
14
15
 
15
- import { CellError, ErrorType, FunctionArgumentType } from '#hyperformula';
16
16
  import { type AsyncFunction, FunctionPluginAsync } from './async-function';
17
17
 
18
18
  const EDGE_FUNCTION_TTL = 10_000;
@@ -59,7 +59,6 @@ export class EdgeFunctionPlugin extends FunctionPluginAsync {
59
59
  headers: { 'Content-Type': 'application/json' },
60
60
  body: JSON.stringify({ args: args.filter(nonNullable) }),
61
61
  });
62
-
63
62
  return await result.text();
64
63
  };
65
64
 
@@ -74,7 +73,8 @@ EdgeFunctionPlugin.implementedFunctions = {
74
73
  // Binding
75
74
  { argumentType: FunctionArgumentType.STRING },
76
75
 
77
- // Remote function arguments (currently supporting up to 8).
76
+ // Remote function arguments (currently supporting up to 9).
77
+ { argumentType: FunctionArgumentType.ANY, optionalArg: true },
78
78
  { argumentType: FunctionArgumentType.ANY, optionalArg: true },
79
79
  { argumentType: FunctionArgumentType.ANY, optionalArg: true },
80
80
  { argumentType: FunctionArgumentType.ANY, optionalArg: true },
@@ -0,0 +1,50 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import React, { createContext, type PropsWithChildren, useContext, useEffect } from 'react';
6
+
7
+ import { type Space } from '@dxos/react-client/echo';
8
+
9
+ import { type FunctionContextOptions } from './async-function';
10
+ import { CustomPlugin, CustomPluginTranslations } from './custom';
11
+ import { EdgeFunctionPlugin, EdgeFunctionPluginTranslations } from './edge-function';
12
+ import { createComputeGraph, type ComputeGraph } from './graph';
13
+
14
+ export type ComputeGraphContextType = {
15
+ graphs: Record<string, ComputeGraph>;
16
+ setGraph: (key: string, graph: ComputeGraph) => void;
17
+ };
18
+
19
+ export const ComputeGraphContext = createContext<ComputeGraphContextType>({ graphs: {}, setGraph: () => {} });
20
+
21
+ export const ComputeGraphContextProvider = ({
22
+ children,
23
+ graphs,
24
+ setGraph,
25
+ }: PropsWithChildren<ComputeGraphContextType>) => {
26
+ return <ComputeGraphContext.Provider value={{ graphs, setGraph }}>{children}</ComputeGraphContext.Provider>;
27
+ };
28
+
29
+ export const useComputeGraph = (space: Space, options?: Partial<FunctionContextOptions>): ComputeGraph => {
30
+ const { graphs, setGraph } = useContext(ComputeGraphContext);
31
+ const graph =
32
+ graphs[space.id] ??
33
+ createComputeGraph(
34
+ [
35
+ { plugin: EdgeFunctionPlugin, translations: EdgeFunctionPluginTranslations },
36
+ // TODO(wittjosiah): Remove. Needed for current test sheet generated data.
37
+ { plugin: CustomPlugin, translations: CustomPluginTranslations },
38
+ ],
39
+ space,
40
+ options,
41
+ );
42
+
43
+ useEffect(() => {
44
+ if (!graphs[space.id]) {
45
+ setGraph(space.id, graph);
46
+ }
47
+ }, [space]);
48
+
49
+ return graph;
50
+ };
@@ -0,0 +1,50 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { expect } from 'chai';
6
+ import { describe, test } from 'vitest';
7
+
8
+ import { Trigger } from '@dxos/async';
9
+
10
+ import { CustomPlugin, CustomPluginTranslations } from './custom';
11
+ import { createComputeGraph } from './graph';
12
+ import { addressFromA1Notation, SheetModel } from '../../model';
13
+ import { type CellScalarValue, createSheet } from '../../types';
14
+
15
+ /**
16
+ * VITEST_ENV=chrome p vitest --watch
17
+ * NOTE: Browser test required for hyperformula due to raw translation files.
18
+ */
19
+ describe('compute graph', () => {
20
+ const createModel = async () => {
21
+ const graph = createComputeGraph([{ plugin: CustomPlugin, translations: CustomPluginTranslations }]);
22
+ const sheet = createSheet();
23
+ const model = new SheetModel(graph, sheet, undefined, { rows: 5, columns: 5 });
24
+ graph.update.on(() => model.update.emit());
25
+ return { graph, model };
26
+ };
27
+
28
+ test('async function', async () => {
29
+ const { graph, model } = await createModel();
30
+
31
+ // Triggers function.
32
+ model.setValue(addressFromA1Notation('A1'), '=TEST()');
33
+
34
+ const trigger = new Trigger<CellScalarValue>();
35
+ model.update.on(() => {
36
+ const value = model.getValue(addressFromA1Notation('A1'));
37
+ trigger.wake(value);
38
+ });
39
+
40
+ // Get initial value (i.e., null).
41
+ const v1 = model.getValue(addressFromA1Notation('A1'));
42
+ expect(v1).to.be.null;
43
+ expect(graph.context.info.invocations.TEST).to.eq(undefined);
44
+
45
+ // Wait until async update triggered.
46
+ const v2 = await trigger.wait();
47
+ expect(v2).not.to.be.null;
48
+ expect(graph.context.info.invocations.TEST).to.eq(1);
49
+ });
50
+ });