@dxos/plugin-sheet 0.6.12-main.ed7cda7 → 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 (260) hide show
  1. package/dist/lib/browser/{chunk-U2JHW3L6.mjs → SheetContainer-U4H5D34A.mjs} +240 -1020
  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/{node-esm/chunk-D6KU5MI7.mjs → browser/chunk-D5AGLXJP.mjs} +670 -360
  6. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-T3NJFTD4.mjs → chunk-FUAGSXA4.mjs} +15 -8
  8. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-QILRZNE5.mjs → chunk-JRL5LGCE.mjs} +5 -2
  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 +56 -68
  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-OTTD7FBK.cjs → SheetContainer-AXQV3ZT5.cjs} +279 -1050
  21. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-DD6FIXWC.cjs → chunk-5KKJ4NPP.cjs} +667 -360
  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-Q3HBHPRL.cjs → chunk-DSYKOI4E.cjs} +20 -12
  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 +64 -83
  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 +1 -1
  49. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
  50. package/dist/types/src/{graph/custom-function.d.ts → components/ComputeGraph/custom.d.ts} +1 -1
  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 +5 -6
  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} +64 -9
  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 +3 -83
  101. package/dist/types/src/types.d.ts.map +1 -1
  102. package/package.json +41 -48
  103. package/src/SheetPlugin.tsx +70 -43
  104. package/src/components/CellEditor/CellEditor.stories.tsx +3 -4
  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 +1 -3
  109. package/src/{graph/custom-function.ts → components/ComputeGraph/custom.ts} +6 -2
  110. package/src/{graph → components/ComputeGraph}/edge-function.ts +1 -2
  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 +82 -45
  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 +78 -16
  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 -23
  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 +5 -30
  134. package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs +0 -261
  135. package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs.map +0 -7
  136. package/dist/lib/browser/chunk-6ZMQVB4Z.mjs +0 -2923
  137. package/dist/lib/browser/chunk-6ZMQVB4Z.mjs.map +0 -7
  138. package/dist/lib/browser/chunk-QILRZNE5.mjs.map +0 -7
  139. package/dist/lib/browser/chunk-T3NJFTD4.mjs.map +0 -7
  140. package/dist/lib/browser/chunk-U2JHW3L6.mjs.map +0 -7
  141. package/dist/lib/browser/graph-T27BOBOV.mjs +0 -21
  142. package/dist/lib/browser/graph-T27BOBOV.mjs.map +0 -7
  143. package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs +0 -279
  144. package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs.map +0 -7
  145. package/dist/lib/node/chunk-BNARJ5GM.cjs.map +0 -7
  146. package/dist/lib/node/chunk-DD6FIXWC.cjs.map +0 -7
  147. package/dist/lib/node/chunk-OTTD7FBK.cjs.map +0 -7
  148. package/dist/lib/node/chunk-Q3HBHPRL.cjs.map +0 -7
  149. package/dist/lib/node/graph-SPKGX7W4.cjs +0 -43
  150. package/dist/lib/node/graph-SPKGX7W4.cjs.map +0 -7
  151. package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs +0 -262
  152. package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs.map +0 -7
  153. package/dist/lib/node-esm/chunk-7HVSOTGA.mjs +0 -2553
  154. package/dist/lib/node-esm/chunk-7HVSOTGA.mjs.map +0 -7
  155. package/dist/lib/node-esm/chunk-BMNA27EX.mjs +0 -76
  156. package/dist/lib/node-esm/chunk-BMNA27EX.mjs.map +0 -7
  157. package/dist/lib/node-esm/chunk-D6KU5MI7.mjs.map +0 -7
  158. package/dist/lib/node-esm/chunk-IU2L277A.mjs +0 -17
  159. package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +0 -7
  160. package/dist/lib/node-esm/graph-U67IO4UC.mjs +0 -22
  161. package/dist/lib/node-esm/graph-U67IO4UC.mjs.map +0 -7
  162. package/dist/lib/node-esm/index.mjs +0 -261
  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 -5
  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.browser.test.d.ts +0 -2
  195. package/dist/types/src/graph/compute-graph.browser.test.d.ts.map +0 -1
  196. package/dist/types/src/graph/compute-graph.d.ts +0 -81
  197. package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
  198. package/dist/types/src/graph/compute-graph.stories.d.ts +0 -10
  199. package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
  200. package/dist/types/src/graph/compute-node.d.ts +0 -19
  201. package/dist/types/src/graph/compute-node.d.ts.map +0 -1
  202. package/dist/types/src/graph/custom-function.d.ts.map +0 -1
  203. package/dist/types/src/graph/edge-function.d.ts.map +0 -1
  204. package/dist/types/src/graph/function-defs.d.ts.map +0 -1
  205. package/dist/types/src/graph/hyperformula.test.d.ts +0 -2
  206. package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
  207. package/dist/types/src/graph/index.d.ts +0 -4
  208. package/dist/types/src/graph/index.d.ts.map +0 -1
  209. package/dist/types/src/graph/util.d.ts +0 -2
  210. package/dist/types/src/graph/util.d.ts.map +0 -1
  211. package/dist/types/src/hooks/hooks.stories.d.ts +0 -11
  212. package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
  213. package/dist/types/src/hooks/index.d.ts +0 -4
  214. package/dist/types/src/hooks/index.d.ts.map +0 -1
  215. package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
  216. package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
  217. package/dist/types/src/hooks/useFormattingModel.d.ts +0 -3
  218. package/dist/types/src/hooks/useFormattingModel.d.ts.map +0 -1
  219. package/dist/types/src/hooks/useSheetModel.d.ts +0 -8
  220. package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
  221. package/dist/types/src/model/formatting-model.d.ts +0 -16
  222. package/dist/types/src/model/formatting-model.d.ts.map +0 -1
  223. package/dist/types/src/model/sheet-model.d.ts.map +0 -1
  224. package/dist/types/src/sanity.test.d.ts +0 -2
  225. package/dist/types/src/sanity.test.d.ts.map +0 -1
  226. package/dist/types/src/testing/index.d.ts +0 -2
  227. package/dist/types/src/testing/index.d.ts.map +0 -1
  228. package/dist/types/src/testing/testing.d.ts +0 -9
  229. package/dist/types/src/testing/testing.d.ts.map +0 -1
  230. package/dist/vendor/hyperformula.mjs +0 -37145
  231. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +0 -20
  232. package/src/components/GridSheet/GridSheet.stories.tsx +0 -35
  233. package/src/components/GridSheet/GridSheet.tsx +0 -153
  234. package/src/components/GridSheet/util.ts +0 -108
  235. package/src/components/Sheet/decorations.ts +0 -62
  236. package/src/components/Sheet/threads.tsx +0 -205
  237. package/src/defs/index.ts +0 -6
  238. package/src/defs/util.ts +0 -135
  239. package/src/extensions/compute.stories.tsx +0 -151
  240. package/src/extensions/compute.ts +0 -98
  241. package/src/extensions/index.ts +0 -5
  242. package/src/graph/compute-graph.browser.test.ts +0 -104
  243. package/src/graph/compute-graph.stories.tsx +0 -92
  244. package/src/graph/compute-graph.ts +0 -290
  245. package/src/graph/compute-node.ts +0 -51
  246. package/src/graph/hyperformula.test.ts +0 -15
  247. package/src/graph/index.ts +0 -7
  248. package/src/graph/util.ts +0 -8
  249. package/src/hooks/hooks.stories.tsx +0 -50
  250. package/src/hooks/index.ts +0 -7
  251. package/src/hooks/useComputeGraph.ts +0 -20
  252. package/src/hooks/useFormattingModel.ts +0 -11
  253. package/src/hooks/useSheetModel.ts +0 -43
  254. package/src/model/sheet-model.ts +0 -399
  255. package/src/sanity.test.ts +0 -40
  256. package/src/testing/index.ts +0 -5
  257. package/src/testing/testing.tsx +0 -66
  258. /package/dist/types/src/{graph → components/ComputeGraph}/edge-function.d.ts +0 -0
  259. /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
  260. /package/src/{graph/function-defs.ts → model/functions.ts} +0 -0
@@ -1,290 +0,0 @@
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
-
9
- import { Event } from '@dxos/async';
10
- import { type SpaceId, type Space, Filter, fullyQualifiedId } from '@dxos/client/echo';
11
- import { Resource } from '@dxos/context';
12
- import { invariant } from '@dxos/invariant';
13
- import { PublicKey } from '@dxos/keys';
14
- import { log } from '@dxos/log';
15
- import { FunctionType } from '@dxos/plugin-script/types';
16
- import { nonNullable } from '@dxos/util';
17
-
18
- import { HyperFormula } from '#hyperformula';
19
- import { FunctionContext, type FunctionContextOptions } from './async-function';
20
- import { ComputeNode } from './compute-node';
21
- import { EdgeFunctionPlugin, EdgeFunctionPluginTranslations } from './edge-function';
22
- import { defaultFunctions, type FunctionDefinition } from './function-defs';
23
-
24
- //
25
- // NOTE: The package.json file defines the packaged #hyperformula module.
26
- //
27
-
28
- // TODO(wittjosiah): Factor out.
29
- const OBJECT_ID_LENGTH = 60; // 33 (space id) + 26 (object id) + 1 (separator).
30
-
31
- // TODO(burdon): Change to "DX".
32
- const CUSTOM_FUNCTION = 'ECHO';
33
-
34
- export type ComputeGraphPlugin = {
35
- plugin: FunctionPluginDefinition;
36
- translations: FunctionTranslationsPackage;
37
- };
38
-
39
- export type ComputeGraphOptions = {
40
- plugins?: ComputeGraphPlugin[];
41
- } & Partial<FunctionContextOptions> &
42
- Partial<ConfigParams>;
43
-
44
- export const defaultOptions: ComputeGraphOptions = {
45
- licenseKey: 'gpl-v3',
46
- plugins: [
47
- {
48
- plugin: EdgeFunctionPlugin,
49
- translations: EdgeFunctionPluginTranslations,
50
- },
51
- ],
52
- };
53
-
54
- /**
55
- * Marker for sheets that are managed by an ECHO object.
56
- */
57
- const PREFIX = '__';
58
- export const createSheetName = (id: string) => `${PREFIX}${id}`;
59
- export const getSheetId = (name: string): string | undefined =>
60
- name.startsWith(PREFIX) ? name.slice(PREFIX.length) : undefined;
61
-
62
- /**
63
- * NOTE: Async imports to decouple hyperformula deps.
64
- */
65
- export const createComputeGraphRegistry = (options: Partial<FunctionContextOptions> = {}) => {
66
- return new ComputeGraphRegistry({
67
- ...defaultOptions,
68
- ...options,
69
- });
70
- };
71
-
72
- /**
73
- * Manages a collection of ComputeGraph instances for each space.
74
- *
75
- * [ComputePlugin] => [ComputeGraphRegistry] => [ComputeGraph(Space)] => [ComputeNode(Object)]
76
- */
77
- // TODO(burdon): Move graph into separate plugin; isolate HF deps.
78
- export class ComputeGraphRegistry extends Resource {
79
- private readonly _registry = new Map<SpaceId, ComputeGraph>();
80
-
81
- constructor(private readonly _options: ComputeGraphOptions = defaultOptions) {
82
- super();
83
- this._options.plugins?.forEach(({ plugin, translations }) => {
84
- HyperFormula.registerFunctionPlugin(plugin, translations);
85
- });
86
- }
87
-
88
- getGraph(spaceId: SpaceId): ComputeGraph | undefined {
89
- return this._registry.get(spaceId);
90
- }
91
-
92
- async getOrCreateGraph(space: Space): Promise<ComputeGraph> {
93
- let graph = this.getGraph(space.id);
94
- if (!graph) {
95
- log.info('create graph', { space: space.id });
96
- graph = await this.createGraph(space);
97
- }
98
-
99
- return graph;
100
- }
101
-
102
- async createGraph(space: Space): Promise<ComputeGraph> {
103
- invariant(!this._registry.has(space.id), `ComputeGraph already exists for space: ${space.id}`);
104
- const hf = HyperFormula.buildEmpty(this._options);
105
- const graph = new ComputeGraph(hf, space, this._options);
106
- await graph.open(this._ctx);
107
- this._registry.set(space.id, graph);
108
- return graph;
109
- }
110
- }
111
-
112
- /**
113
- * Per-space compute and dependency graph.
114
- * Consists of multiple ComputeNode (corresponding to a HyperFormula sheet).
115
- * Manages the set of custom functions.
116
- * HyperFormula manages the dependency graph.
117
- */
118
- // TODO(burdon): Tests.
119
- export class ComputeGraph extends Resource {
120
- public readonly id = `graph-${PublicKey.random().truncate()}`;
121
-
122
- // Map of nodes indexed by sheet number.
123
- private readonly _nodes = new Map<number, ComputeNode>();
124
-
125
- // Cached function objects.
126
- private _functions: FunctionType[] = [];
127
-
128
- // The context is passed to all functions.
129
- public readonly context = new FunctionContext(this._hf, this._space, this.refresh.bind(this), this._options);
130
-
131
- // TODO(burdon): Typed events.
132
- // TODO(burdon): Tie into HyperFormula dependency graph.
133
- // TODO(burdon): Event propagation.
134
- public readonly update = new Event();
135
-
136
- constructor(
137
- private readonly _hf: HyperFormula,
138
- private readonly _space?: Space,
139
- private readonly _options?: Partial<FunctionContextOptions>,
140
- ) {
141
- super();
142
-
143
- this._hf.updateConfig({ context: this.context });
144
- }
145
-
146
- // TODO(burdon): Remove.
147
- get hf() {
148
- return this._hf;
149
- }
150
-
151
- refresh() {
152
- log('refresh', { id: this.id });
153
- this.update.emit();
154
- }
155
-
156
- getFunctions({ standard = true, echo = true }: { standard?: boolean; echo?: boolean } = {}): FunctionDefinition[] {
157
- return [
158
- ...(standard
159
- ? this._hf
160
- .getRegisteredFunctionNames()
161
- .map((name) => defaultFunctions.find((fn) => fn.name === name) ?? { name })
162
- : []),
163
- ...(echo ? this._functions.map((fn) => ({ name: fn.binding! })) : []),
164
- ];
165
- }
166
-
167
- /**
168
- * Get or create cell representing a sheet.
169
- */
170
- // TODO(burdon): Async (open node).
171
- // The graph should be an extensible factory that plugins extend with model constructors.
172
- // This would enable on-the-fly instantiation of new models when then are referenced.
173
- // E.g., Cross-object reference would be stored as "ObjectId!A1"
174
- // The graph would then load the object and create a ComputeNode (model) of the appropriate type.
175
- getOrCreateNode(name: string): ComputeNode {
176
- invariant(name.length);
177
- if (!this._hf.doesSheetExist(name)) {
178
- log.info('created node', { space: this._space?.id, name });
179
- this._hf.addSheet(name);
180
- this.update.emit();
181
- }
182
-
183
- const sheetId = this._hf.getSheetId(name);
184
- invariant(sheetId !== undefined);
185
-
186
- // TODO(burdon): Chain context?
187
- const node = new ComputeNode(this, sheetId);
188
- this._nodes.set(sheetId, node);
189
- return node;
190
- }
191
-
192
- /**
193
- * Map bound value to custom function invocation.
194
- * E.g., "HELLO(...args)" => "EDGE("HELLO", ...args)".
195
- */
196
- mapFormulaToNative(formula: string): string {
197
- return (
198
- formula
199
- // Sheet references.
200
- // https://hyperformula.handsontable.com/guide/cell-references.html#cell-references
201
- .replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
202
- if (name) {
203
- // TODO(burdon): What if not loaded?
204
- const objects = this._hf
205
- .getSheetNames()
206
- .map((name) => {
207
- const id = getSheetId(name);
208
- return id ? this._space?.db.getObjectById(id) : undefined;
209
- })
210
- .filter(nonNullable);
211
-
212
- for (const obj of objects) {
213
- if (obj.name === name || obj.title === name) {
214
- return `${createSheetName(obj.id)}!`;
215
- }
216
- }
217
- }
218
-
219
- return `${name}!`;
220
- })
221
-
222
- // Functions.
223
- .replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
224
- const fn = this._functions.find((fn) => fn.binding === binding);
225
- if (!fn) {
226
- return match;
227
- }
228
-
229
- if (args.trim() === '') {
230
- return `${CUSTOM_FUNCTION}("${binding}")`;
231
- } else {
232
- return `${CUSTOM_FUNCTION}("${binding}", ${args})`;
233
- }
234
- })
235
- );
236
- }
237
-
238
- /**
239
- * Map from binding to fully qualified ECHO ID (to store).
240
- * E.g., HELLO() => spaceId:objectId()
241
- */
242
- mapFunctionBindingToId(formula: string) {
243
- return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
244
- if (binding === CUSTOM_FUNCTION || defaultFunctions.find((fn) => fn.name === binding)) {
245
- return match;
246
- }
247
-
248
- const fn = this._functions.find((fn) => fn.binding === binding);
249
- if (fn) {
250
- const id = fullyQualifiedId(fn);
251
- return `${id}(${args})`;
252
- } else {
253
- return match;
254
- }
255
- });
256
- }
257
-
258
- /**
259
- * Map from fully qualified ECHO ID to binding (from store).
260
- * E.g., spaceId:objectId() => HELLO()
261
- */
262
- mapFunctionBindingFromId(formula: string) {
263
- return formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
264
- const id = `${spaceId}:${objectId}`;
265
- if (id.length !== OBJECT_ID_LENGTH) {
266
- return match;
267
- }
268
-
269
- const fn = this._functions.find((fn) => fullyQualifiedId(fn) === id);
270
- if (fn?.binding) {
271
- return `${fn.binding}(${args})`;
272
- } else {
273
- return match;
274
- }
275
- });
276
- }
277
-
278
- protected override async _open() {
279
- if (this._space) {
280
- // Subscribe to remote function definitions.
281
- const query = this._space.db.query(Filter.schema(FunctionType));
282
- const unsubscribe = query.subscribe(({ objects }) => {
283
- this._functions = objects.filter(({ binding }) => binding);
284
- this.update.emit();
285
- });
286
-
287
- this._ctx.onDispose(unsubscribe);
288
- }
289
- }
290
- }
@@ -1,51 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { Event } from '@dxos/async';
6
- import { Resource } from '@dxos/context';
7
-
8
- import { DetailedCellError } from '#hyperformula';
9
- import { type ComputeGraph } from './compute-graph';
10
- import { type CellAddress } from '../defs';
11
- import { type CellScalarValue } from '../types';
12
-
13
- /**
14
- * Individual "sheet" (typically corresponds to an ECHO object).
15
- */
16
- // TODO(burdon): Factor out common HF wrapper from from SheetModel.
17
- export class ComputeNode extends Resource {
18
- // TODO(burdon): Chaing events.
19
- public readonly update = new Event();
20
-
21
- constructor(
22
- private readonly _graph: ComputeGraph,
23
- public readonly sheetId: number,
24
- ) {
25
- super();
26
- }
27
-
28
- // TODO(burdon): Remove?
29
- get graph() {
30
- return this._graph;
31
- }
32
-
33
- get hf() {
34
- return this._graph.hf;
35
- }
36
-
37
- getValue(cell: CellAddress): CellScalarValue {
38
- const value = this._graph.hf.getCellValue({ sheet: this.sheetId, row: cell.row, col: cell.col });
39
- if (value instanceof DetailedCellError) {
40
- return null;
41
- }
42
-
43
- return value;
44
- }
45
-
46
- setValue(cell: CellAddress, value: CellScalarValue) {
47
- const mappedValue =
48
- typeof value === 'string' && value.charAt(0) === '=' ? this._graph.mapFormulaToNative(value) : value;
49
- this._graph.hf.setCellContents({ sheet: this.sheetId, row: cell.row, col: cell.col }, [[mappedValue]]);
50
- }
51
- }
@@ -1,15 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { describe, test, expect } from 'vitest';
6
-
7
- import { HyperFormula } from '#hyperformula';
8
-
9
- describe('hyperformula', () => {
10
- test('sanity', async () => {
11
- // TODO(burdon): Throws "Cannot convert undefined or null to object" in vitest (without browser).
12
- const hf = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' });
13
- expect(hf).to.exist;
14
- });
15
- });
@@ -1,7 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './compute-graph';
6
- export * from './compute-node';
7
- export * from './function-defs';
package/src/graph/util.ts DELETED
@@ -1,8 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- // TODO(burdon): Factor out.
6
- export const parseNumberString = (str: string): number => {
7
- return parseFloat(str.replace(/[^\d.]/g, ''));
8
- };
@@ -1,50 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import React, { useEffect, useState } from 'react';
8
-
9
- import { useSpace } from '@dxos/react-client/echo';
10
- import { withClientProvider } from '@dxos/react-client/testing';
11
- import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
12
- import { withTheme } from '@dxos/storybook-utils';
13
-
14
- import { ComputeGraphContextProvider } from '../components';
15
- import { createSheet } from '../defs';
16
- import { useComputeGraph, useSheetModel } from '../hooks';
17
- import { withGraphDecorator } from '../testing';
18
- import { SheetType } from '../types';
19
-
20
- const Story = () => {
21
- const space = useSpace();
22
- const graph = useComputeGraph(space);
23
- const [sheet, setSheet] = useState<SheetType>();
24
- const model = useSheetModel(space, sheet);
25
- useEffect(() => {
26
- if (space) {
27
- const sheet = space.db.add(createSheet());
28
- setSheet(sheet);
29
- }
30
- }, [space]);
31
-
32
- return (
33
- <SyntaxHighlighter language='json'>
34
- {JSON.stringify({ space: space?.id, graph: graph?.id, sheet: sheet?.id, model: model?.id }, null, 2)}
35
- </SyntaxHighlighter>
36
- );
37
- };
38
-
39
- export default {
40
- title: 'plugin-sheet/hooks',
41
- component: ComputeGraphContextProvider,
42
- decorators: [
43
- withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
44
- withGraphDecorator,
45
- withTheme,
46
- ],
47
- render: (args: any) => <Story {...args} />,
48
- };
49
-
50
- export const Default = {};
@@ -1,7 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './useComputeGraph';
6
- export * from './useFormattingModel';
7
- export * from './useSheetModel';
@@ -1,20 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { useContext } from 'react';
6
-
7
- import { raise } from '@dxos/debug';
8
- import { type Space } from '@dxos/react-client/echo';
9
- import { useAsyncState } from '@dxos/react-hooks';
10
-
11
- import { ComputeGraphContext } from '../components';
12
- import { type ComputeGraph } from '../graph';
13
-
14
- /**
15
- * Get existing or create new compute graph for the given space.
16
- */
17
- export const useComputeGraph = (space?: Space): ComputeGraph | undefined => {
18
- const { registry } = useContext(ComputeGraphContext) ?? raise(new Error('Missing ComputeGraphContext'));
19
- return useAsyncState(async () => space && registry.getOrCreateGraph(space), [space, registry]);
20
- };
@@ -1,11 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { useMemo } from 'react';
6
-
7
- import { type SheetModel, FormattingModel } from '../model';
8
-
9
- export const useFormattingModel = (model: SheetModel | undefined): FormattingModel | undefined => {
10
- return useMemo(() => model && new FormattingModel(model), [model]);
11
- };
@@ -1,43 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { useEffect, useState } from 'react';
6
-
7
- import { type Space } from '@dxos/react-client/echo';
8
-
9
- import { useComputeGraph } from './useComputeGraph';
10
- import { SheetModel } from '../model';
11
- import { type SheetType } from '../types';
12
-
13
- export type UseSheetModelOptions = {
14
- readonly?: boolean;
15
- };
16
-
17
- export const useSheetModel = (
18
- space?: Space,
19
- sheet?: SheetType,
20
- { readonly }: UseSheetModelOptions = {},
21
- ): SheetModel | undefined => {
22
- const graph = useComputeGraph(space);
23
- const [model, setModel] = useState<SheetModel>();
24
- useEffect(() => {
25
- if (!space || !graph || !sheet) {
26
- return;
27
- }
28
-
29
- let model: SheetModel | undefined;
30
- const t = setTimeout(async () => {
31
- model = new SheetModel(graph, sheet, { readonly });
32
- await model.open();
33
- setModel(model);
34
- });
35
-
36
- return () => {
37
- clearTimeout(t);
38
- void model?.close();
39
- };
40
- }, [space, sheet, graph, readonly]);
41
-
42
- return model;
43
- };