@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
@@ -0,0 +1,62 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { type FunctionPluginDefinition, HyperFormula } from 'hyperformula';
6
+ import { type FunctionTranslationsPackage } from 'hyperformula/typings/interpreter';
7
+
8
+ import { Event } from '@dxos/async';
9
+ import { type Space } from '@dxos/client/echo';
10
+ import { PublicKey } from '@dxos/keys';
11
+ import { log } from '@dxos/log';
12
+
13
+ import { FunctionContext, type FunctionContextOptions } from './async-function';
14
+
15
+ /**
16
+ * Create root graph for space.
17
+ */
18
+ export const createComputeGraph = (
19
+ // TODO(wittjosiah): Factor out this type to make these easier to define.
20
+ functionPlugins: { plugin: FunctionPluginDefinition; translations: FunctionTranslationsPackage }[] = [],
21
+ space?: Space,
22
+ options?: Partial<FunctionContextOptions>,
23
+ ): ComputeGraph => {
24
+ functionPlugins.forEach(({ plugin, translations }) => {
25
+ HyperFormula.registerFunctionPlugin(plugin, translations);
26
+ });
27
+
28
+ const hf = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' });
29
+ return new ComputeGraph(hf, space, options);
30
+ };
31
+
32
+ /**
33
+ * Per-space compute and dependency graph.
34
+ */
35
+ // TODO(burdon): Create instance for each space.
36
+ export class ComputeGraph {
37
+ public readonly id = `graph-${PublicKey.random().truncate()}`;
38
+ public readonly update = new Event();
39
+
40
+ // The context is passed to all functions.
41
+ public readonly context = new FunctionContext(
42
+ this.hf,
43
+ this._space,
44
+ () => {
45
+ this.refresh();
46
+ },
47
+ this._options,
48
+ );
49
+
50
+ constructor(
51
+ public readonly hf: HyperFormula,
52
+ private readonly _space?: Space,
53
+ private readonly _options?: Partial<FunctionContextOptions>,
54
+ ) {
55
+ this.hf.updateConfig({ context: this.context });
56
+ }
57
+
58
+ refresh() {
59
+ log('refresh', { id: this.id });
60
+ this.update.emit();
61
+ }
62
+ }
@@ -2,4 +2,6 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './ComputeGraphContextProvider';
5
+ export * from './async-function';
6
+ export * from './custom';
7
+ export * from './graph';
@@ -4,34 +4,31 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import React, { useState } from 'react';
7
+ import { type Decorator } from '@storybook/react';
8
+ import React, { useContext, useEffect, useState } from 'react';
8
9
 
10
+ import { Client } from '@dxos/client';
11
+ import { type EchoReactiveObject } from '@dxos/echo-schema';
9
12
  import { log } from '@dxos/log';
10
- import { useSpace } from '@dxos/react-client/echo';
11
- import { withClientProvider } from '@dxos/react-client/testing';
13
+ import { getSpace, type Space } from '@dxos/react-client/echo';
12
14
  import { Button } from '@dxos/react-ui';
13
15
  import { mx } from '@dxos/react-ui-theme';
14
- import { withLayout, withTheme } from '@dxos/storybook-utils';
16
+ import { withTheme, withLayout } from '@dxos/storybook-utils';
15
17
 
16
18
  import { Sheet } from './Sheet';
17
19
  import { type SizeMap } from './grid';
18
20
  import { useSheetContext } from './sheet-context';
19
- import { addressToIndex, rangeToIndex } from '../../defs';
20
- import { type ComputeGraph } from '../../graph';
21
- import { testPlugins } from '../../graph/testing';
22
- import { useComputeGraph } from '../../hooks';
23
- import { createTestCells, useTestSheet, withComputeGraphDecorator } from '../../testing';
24
- import { SheetType, ValueTypeEnum } from '../../types';
21
+ import { createTestSheet, testSheetName } from '../../testing';
22
+ import { ValueTypeEnum, SheetType } from '../../types';
23
+ import { type ComputeGraph, createComputeGraph } from '../ComputeGraph';
24
+ // TODO(wittjosiah): Refactor. This is not exported from ./components due to depending on ECHO.
25
+ import { ComputeGraphContext, ComputeGraphContextProvider, useComputeGraph } from '../ComputeGraph/graph-context';
25
26
  import { Toolbar, type ToolbarActionHandler } from '../Toolbar';
26
27
 
27
28
  // TODO(burdon): Allow toolbar to access sheet context; provide state for current cursor/range.
28
- const SheetWithToolbar = ({ graph, debug }: { graph: ComputeGraph; debug?: boolean }) => {
29
+ const SheetWithToolbar = ({ debug, space }: { debug?: boolean; space: Space }) => {
29
30
  const { model, cursor, range } = useSheetContext();
30
31
 
31
- const handleRefresh = () => {
32
- // graph?.refresh(); // TODO(burdon): ???
33
- };
34
-
35
32
  // TODO(burdon): Factor out.
36
33
  const handleAction: ToolbarActionHandler = ({ type }) => {
37
34
  log.info('action', { type, cursor, range });
@@ -39,7 +36,7 @@ const SheetWithToolbar = ({ graph, debug }: { graph: ComputeGraph; debug?: boole
39
36
  return;
40
37
  }
41
38
 
42
- const idx = range ? rangeToIndex(model.sheet, range) : addressToIndex(model.sheet, cursor);
39
+ const idx = range ? model.rangeToIndex(range) : model.addressToIndex(cursor);
43
40
  model.sheet.formatting[idx] ??= {};
44
41
  const format = model.sheet.formatting[idx];
45
42
 
@@ -78,12 +75,14 @@ const SheetWithToolbar = ({ graph, debug }: { graph: ComputeGraph; debug?: boole
78
75
  format.precision = 2;
79
76
  break;
80
77
  }
81
- case 'comment': {
82
- break;
83
- }
84
78
  }
85
79
  };
86
80
 
81
+ const graph = useComputeGraph(space);
82
+ const handleRefresh = () => {
83
+ graph.refresh();
84
+ };
85
+
87
86
  return (
88
87
  <div className='flex flex-col overflow-hidden'>
89
88
  <Toolbar.Root onAction={handleAction}>
@@ -100,43 +99,56 @@ const SheetWithToolbar = ({ graph, debug }: { graph: ComputeGraph; debug?: boole
100
99
  );
101
100
  };
102
101
 
102
+ const withGraphDecorator: Decorator = (Story) => {
103
+ const [graphs, setGraphs] = useState<Record<string, ComputeGraph>>({});
104
+
105
+ const setGraph = (key: string, graph: ComputeGraph) => {
106
+ if (!graph.hf.doesSheetExist(testSheetName)) {
107
+ const sheetName = graph.hf.addSheet(testSheetName);
108
+ const sheet = graph.hf.getSheetId(sheetName)!;
109
+ graph.hf.setCellContents({ sheet, col: 0, row: 0 }, Math.random());
110
+ }
111
+
112
+ setGraphs((graphs) => ({ ...graphs, [key]: graph }));
113
+ };
114
+
115
+ return (
116
+ <ComputeGraphContextProvider graphs={graphs} setGraph={setGraph}>
117
+ <Story />
118
+ </ComputeGraphContextProvider>
119
+ );
120
+ };
121
+
103
122
  export default {
104
123
  title: 'plugin-sheet/Sheet',
105
124
  component: Sheet,
106
- decorators: [
107
- withClientProvider({ types: [SheetType], createIdentity: true }),
108
- withComputeGraphDecorator({ plugins: testPlugins }),
109
- withTheme,
110
- withLayout({ fullscreen: true, tooltips: true, classNames: 'inset-4' }),
111
- ],
125
+ decorators: [withTheme, withLayout({ fullscreen: true, tooltips: true, classNames: 'inset-4' }), withGraphDecorator],
112
126
  };
113
127
 
114
128
  export const Default = () => {
115
129
  const [debug, setDebug] = useState(false);
116
- const space = useSpace();
117
- const graph = useComputeGraph(space);
118
- const sheet = useTestSheet(space, graph, { cells: createTestCells() });
119
- if (!graph || !sheet) {
130
+ const sheet = useTestSheet();
131
+ const space = getSpace(sheet);
132
+ if (!sheet || !space) {
120
133
  return null;
121
134
  }
122
135
 
123
136
  return (
124
- <Sheet.Root graph={graph} sheet={sheet} onInfo={() => setDebug((debug) => !debug)}>
125
- <SheetWithToolbar graph={graph} debug={debug} />
137
+ <Sheet.Root sheet={sheet} space={space} onInfo={() => setDebug((debug) => !debug)}>
138
+ <SheetWithToolbar debug={debug} space={space} />
126
139
  </Sheet.Root>
127
140
  );
128
141
  };
129
142
 
130
143
  export const Debug = () => {
131
- const space = useSpace();
132
- const graph = useComputeGraph(space);
133
- const sheet = useTestSheet(space, graph, { cells: createTestCells() });
134
- if (!graph || !sheet) {
144
+ const sheet = useTestSheet();
145
+ const space = getSpace(sheet);
146
+ if (!sheet || !space) {
135
147
  return null;
136
148
  }
137
149
 
138
150
  return (
139
- <Sheet.Root graph={graph} sheet={sheet}>
151
+ <Sheet.Root sheet={sheet} space={space}>
140
152
  <Sheet.Main />
141
153
  <Sheet.Debug />
142
154
  </Sheet.Root>
@@ -145,15 +157,14 @@ export const Debug = () => {
145
157
 
146
158
  export const Rows = () => {
147
159
  const [rowSizes, setRowSizes] = useState<SizeMap>({});
148
- const space = useSpace();
149
- const graph = useComputeGraph(space);
150
- const sheet = useTestSheet(space, graph);
151
- if (!graph || !sheet) {
160
+ const sheet = useTestSheet();
161
+ const space = getSpace(sheet);
162
+ if (!sheet || !space) {
152
163
  return null;
153
164
  }
154
165
 
155
166
  return (
156
- <Sheet.Root graph={graph} sheet={sheet}>
167
+ <Sheet.Root sheet={sheet} space={space}>
157
168
  <Sheet.Rows
158
169
  rows={sheet.rows}
159
170
  sizes={rowSizes}
@@ -165,15 +176,14 @@ export const Rows = () => {
165
176
 
166
177
  export const Columns = () => {
167
178
  const [columnSizes, setColumnSizes] = useState<SizeMap>({});
168
- const space = useSpace();
169
- const graph = useComputeGraph(space);
170
- const sheet = useTestSheet(space, graph);
171
- if (!graph || !sheet) {
179
+ const sheet = useTestSheet();
180
+ const space = getSpace(sheet);
181
+ if (!sheet || !space) {
172
182
  return null;
173
183
  }
174
184
 
175
185
  return (
176
- <Sheet.Root graph={graph} sheet={sheet}>
186
+ <Sheet.Root sheet={sheet} space={space}>
177
187
  <Sheet.Columns
178
188
  columns={sheet.columns}
179
189
  sizes={columnSizes}
@@ -184,19 +194,18 @@ export const Columns = () => {
184
194
  };
185
195
 
186
196
  export const Main = () => {
187
- const space = useSpace();
188
- const graph = useComputeGraph(space);
189
- const sheet = useTestSheet(space, graph, { cells: createTestCells() });
190
- if (!graph || !sheet) {
197
+ const sheet = useTestSheet();
198
+ const space = getSpace(sheet);
199
+ if (!sheet || !space) {
191
200
  return null;
192
201
  }
193
202
 
194
203
  return (
195
- <Sheet.Root graph={graph} sheet={sheet}>
204
+ <Sheet.Root sheet={sheet} space={space}>
196
205
  <Sheet.Grid
197
206
  size={{
198
207
  numRows: 50,
199
- numCols: 26,
208
+ numColumns: 26,
200
209
  }}
201
210
  rows={sheet.rows}
202
211
  columns={sheet.columns}
@@ -249,3 +258,30 @@ export const GridLayout = () => {
249
258
  const Cell = ({ className, label }: { className?: string; label: string }) => (
250
259
  <div className={mx('flex items-center justify-center border', className)}>{label}</div>
251
260
  );
261
+
262
+ const useTestSheet = () => {
263
+ const { graphs, setGraph } = useContext(ComputeGraphContext);
264
+ const [sheet, setSheet] = useState<EchoReactiveObject<SheetType>>();
265
+ useEffect(() => {
266
+ const t = setTimeout(async () => {
267
+ const client = new Client();
268
+ await client.initialize();
269
+ await client.halo.createIdentity();
270
+ const space = await client.spaces.create();
271
+ client.addTypes([SheetType]);
272
+
273
+ const graph = graphs[space.id] ?? createComputeGraph();
274
+ if (!graphs[space.id]) {
275
+ setGraph(space.id, graph);
276
+ }
277
+
278
+ const sheet = await createTestSheet({ graph });
279
+ space.db.add(sheet);
280
+ setSheet(sheet);
281
+ });
282
+
283
+ return () => clearTimeout(t);
284
+ }, []);
285
+
286
+ return sheet;
287
+ };
@@ -60,7 +60,6 @@ import {
60
60
  } from './grid';
61
61
  import { type GridSize, handleArrowNav, handleNav, useRangeSelect } from './nav';
62
62
  import { type SheetContextProps, SheetContextProvider, useSheetContext } from './sheet-context';
63
- import { useThreads } from './threads';
64
63
  import { getRectUnion, getRelativeClientRect, scrollIntoView } from './util';
65
64
  import {
66
65
  type CellIndex,
@@ -69,9 +68,7 @@ import {
69
68
  columnLetter,
70
69
  posEquals,
71
70
  rangeToA1Notation,
72
- addressToIndex,
73
- addressFromIndex,
74
- } from '../../defs';
71
+ } from '../../model';
75
72
  import {
76
73
  CellEditor,
77
74
  type CellRangeNotifier,
@@ -138,16 +135,12 @@ const SheetRoot = ({ children, ...props }: PropsWithChildren<SheetContextProps>)
138
135
 
139
136
  type SheetMainProps = ThemedClassName<Partial<GridSize>>;
140
137
 
141
- const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numRows, numCols }, forwardRef) => {
138
+ const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numRows, numColumns }, forwardRef) => {
142
139
  const { model, cursor, setCursor, setRange, setEditing } = useSheetContext();
143
140
 
144
141
  // Scrolling.
145
142
  const { rowsRef, columnsRef, contentRef } = useScrollHandlers();
146
143
 
147
- // Threads.
148
- // TODO(Zan): Move this to an extension once we have an extension model.
149
- useThreads();
150
-
151
144
  //
152
145
  // Order of Row/columns.
153
146
  //
@@ -177,21 +170,21 @@ const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numR
177
170
  }, [rows, columns]);
178
171
 
179
172
  const handleMoveRows: SheetRowsProps['onMove'] = (from, to, num = 1) => {
180
- const cursorIdx = cursor ? addressToIndex(model.sheet, cursor) : undefined;
173
+ const cursorIdx = cursor ? model.addressToIndex(cursor) : undefined;
181
174
  const [rows] = model.sheet.rows.splice(from, num);
182
175
  model.sheet.rows.splice(to, 0, rows);
183
176
  if (cursorIdx) {
184
- setCursor(addressFromIndex(model.sheet, cursorIdx));
177
+ setCursor(model.addressFromIndex(cursorIdx));
185
178
  }
186
179
  setRows([...model.sheet.rows]);
187
180
  };
188
181
 
189
182
  const handleMoveColumns: SheetColumnsProps['onMove'] = (from, to, num = 1) => {
190
- const cursorIdx = cursor ? addressToIndex(model.sheet, cursor) : undefined;
183
+ const cursorIdx = cursor ? model.addressToIndex(cursor) : undefined;
191
184
  const columns = model.sheet.columns.splice(from, num);
192
185
  model.sheet.columns.splice(to, 0, ...columns);
193
186
  if (cursorIdx) {
194
- setCursor(addressFromIndex(model.sheet, cursorIdx));
187
+ setCursor(model.addressFromIndex(cursorIdx));
195
188
  }
196
189
  setColumns([...model.sheet.columns]);
197
190
  };
@@ -263,8 +256,8 @@ const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numR
263
256
  ref={columnsRef}
264
257
  columns={columns}
265
258
  sizes={columnSizes}
266
- selected={cursor?.col}
267
- onSelect={(col) => setCursor(cursor?.col === col ? undefined : { row: -1, col })}
259
+ selected={cursor?.column}
260
+ onSelect={(column) => setCursor(cursor?.column === column ? undefined : { row: -1, column })}
268
261
  onResize={handleResizeColumn}
269
262
  onMove={handleMoveColumns}
270
263
  />
@@ -274,13 +267,13 @@ const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numR
274
267
  rows={rows}
275
268
  sizes={rowSizes}
276
269
  selected={cursor?.row}
277
- onSelect={(row) => setCursor(cursor?.row === row ? undefined : { row, col: -1 })}
270
+ onSelect={(row) => setCursor(cursor?.row === row ? undefined : { row, column: -1 })}
278
271
  onResize={handleResizeRow}
279
272
  onMove={handleMoveRows}
280
273
  />
281
274
  <SheetGrid
282
275
  ref={contentRef}
283
- size={{ numRows: numRows ?? rows.length, numCols: numCols ?? columns.length }}
276
+ size={{ numRows: numRows ?? rows.length, numColumns: numColumns ?? columns.length }}
284
277
  rows={rows}
285
278
  columns={columns}
286
279
  rowSizes={rowSizes}
@@ -885,11 +878,11 @@ const SheetGrid = forwardRef<HTMLDivElement, SheetGridProps>(
885
878
 
886
879
  {/* Grid cells. */}
887
880
  {rowRange.map(({ row, top, height }) => {
888
- return columnRange.map(({ col, left, width }) => {
881
+ return columnRange.map(({ column, left, width }) => {
889
882
  const style: CSSProperties = { position: 'absolute', top, left, width, height };
890
- const cell: CellAddress = { row, col };
883
+ const cell = { row, column };
891
884
  const id = addressToA1Notation(cell);
892
- const idx = addressToIndex(model.sheet, cell);
885
+ const idx = model.addressToIndex(cell);
893
886
  const active = posEquals(cursor, cell);
894
887
  if (active && editing) {
895
888
  const value = initialText.current ?? model.getCellText(cell) ?? '';
@@ -1010,46 +1003,16 @@ type SheetCellProps = {
1010
1003
  };
1011
1004
 
1012
1005
  const SheetCell = ({ id, cell, style, active, onSelect }: SheetCellProps) => {
1013
- const {
1014
- formatting,
1015
- editing,
1016
- setRange,
1017
- decorations,
1018
- model: { sheet },
1019
- } = useSheetContext();
1006
+ const { formatting, editing, setRange } = useSheetContext();
1020
1007
  const { value, classNames } = formatting.getFormatting(cell);
1021
1008
 
1022
- const decorationsForCell = decorations.getDecorationsForCell(addressToIndex(sheet, cell)) ?? [];
1023
- const decorationAddedClasses = useMemo(
1024
- () => decorationsForCell.flatMap((d) => d.classNames ?? []),
1025
- [decorationsForCell],
1026
- );
1027
- const decoratedContent = decorationsForCell.reduce(
1028
- (children, { decorate }) => {
1029
- if (!decorate) {
1030
- return children;
1031
- }
1032
- const DecoratorComponent = decorate;
1033
- return <DecoratorComponent>{children}</DecoratorComponent>;
1034
- },
1035
- <div
1036
- role='none'
1037
- className={mx(
1038
- 'flex flex-grow bs-full is-full px-2 items-center truncate cursor-pointer',
1039
- ...decorationAddedClasses,
1040
- )}
1041
- >
1042
- {value}
1043
- </div>,
1044
- );
1045
-
1046
1009
  return (
1047
1010
  <div
1048
1011
  {...{ [`data-${CELL_DATA_KEY}`]: id }}
1049
1012
  role='cell'
1050
1013
  style={style}
1051
1014
  className={mx(
1052
- 'border border-gridLine cursor-pointer',
1015
+ 'flex w-full h-full px-2 py-1 truncate items-center border border-gridLine cursor-pointer',
1053
1016
  fragments.cell,
1054
1017
  active && ['z-20', fragments.cellSelected],
1055
1018
  classNames,
@@ -1063,7 +1026,7 @@ const SheetCell = ({ id, cell, style, active, onSelect }: SheetCellProps) => {
1063
1026
  }}
1064
1027
  onDoubleClick={() => onSelect?.(cell, true)}
1065
1028
  >
1066
- {decoratedContent}
1029
+ {value}
1067
1030
  </div>
1068
1031
  );
1069
1032
  };
@@ -1082,11 +1045,10 @@ const GridCellEditor = ({ style, value, onNav, onClose }: GridCellEditorProps) =
1082
1045
  notifier.current?.(rangeToA1Notation(range));
1083
1046
  }
1084
1047
  }, [range]);
1085
-
1086
1048
  const extension = useMemo(
1087
1049
  () => [
1088
1050
  editorKeys({ onNav, onClose }),
1089
- sheetExtension({ functions: model.graph.getFunctions() }),
1051
+ sheetExtension({ functions: model.functions }),
1090
1052
  rangeExtension((fn) => (notifier.current = fn)),
1091
1053
  ],
1092
1054
  [model],
@@ -1110,13 +1072,12 @@ const GridCellEditor = ({ style, value, onNav, onClose }: GridCellEditorProps) =
1110
1072
 
1111
1073
  const SheetStatusBar = () => {
1112
1074
  const { model, cursor, range } = useSheetContext();
1113
-
1114
1075
  let value;
1115
1076
  let isFormula = false;
1116
1077
  if (cursor) {
1117
1078
  value = model.getCellValue(cursor);
1118
1079
  if (typeof value === 'string' && value.charAt(0) === '=') {
1119
- value = model.graph.mapFunctionBindingFromId(model.mapFormulaIndicesToRefs(value));
1080
+ value = model.mapFormulaBindingFromId(model.mapFormulaIndicesToRefs(value));
1120
1081
  isFormula = true;
1121
1082
  } else if (value != null) {
1122
1083
  value = String(value);
@@ -4,24 +4,17 @@
4
4
 
5
5
  import { type ClassNameValue } from '@dxos/react-ui-types';
6
6
 
7
- import { type SheetModel } from './sheet-model';
8
- import { type CellAddress, inRange } from '../defs';
9
- import { addressToIndex, rangeFromIndex } from '../defs';
10
- import { ValueTypeEnum } from '../types';
11
-
12
- export type CellFormat = {
13
- value?: string;
14
- classNames?: ClassNameValue;
15
- };
7
+ import { type SheetModel, type CellAddress, inRange } from '../../model';
8
+ import { ValueTypeEnum } from '../../types';
16
9
 
17
10
  export class FormattingModel {
18
- constructor(private readonly _model: SheetModel) {}
11
+ constructor(private readonly model: SheetModel) {}
19
12
 
20
13
  /**
21
14
  * Get formatted string value and className for cell.
22
15
  */
23
- getFormatting(cell: CellAddress): CellFormat {
24
- const value = this._model.getValue(cell);
16
+ getFormatting(cell: CellAddress): { value?: string; classNames?: ClassNameValue } {
17
+ const value = this.model.getValue(cell);
25
18
  if (value === undefined || value === null) {
26
19
  return {};
27
20
  }
@@ -30,15 +23,15 @@ export class FormattingModel {
30
23
  const locales = undefined;
31
24
 
32
25
  // Cell-specific formatting.
33
- const idx = addressToIndex(this._model.sheet, cell);
34
- let formatting = this._model.sheet.formatting?.[idx] ?? {};
26
+ const idx = this.model.addressToIndex(cell);
27
+ let formatting = this.model.sheet.formatting?.[idx] ?? {};
35
28
  const classNames = [...(formatting?.classNames ?? [])];
36
29
 
37
30
  // Range formatting.
38
31
  // TODO(burdon): NOTE: D0 means the D column.
39
32
  // TODO(burdon): Cache model formatting (e.g., for ranges). Create class out of this function.
40
- for (const [idx, _formatting] of Object.entries(this._model.sheet.formatting)) {
41
- const range = rangeFromIndex(this._model.sheet, idx);
33
+ for (const [idx, _formatting] of Object.entries(this.model.sheet.formatting)) {
34
+ const range = this.model.rangeFromIndex(idx);
42
35
  if (inRange(range, cell)) {
43
36
  if (_formatting.classNames) {
44
37
  classNames.push(..._formatting.classNames);
@@ -53,7 +46,7 @@ export class FormattingModel {
53
46
 
54
47
  const defaultNumber = 'justify-end font-mono';
55
48
 
56
- const type = formatting?.type ?? this._model.getValueType(cell);
49
+ const type = formatting?.type ?? this.model.getValueType(cell);
57
50
  switch (type) {
58
51
  case ValueTypeEnum.Boolean: {
59
52
  return {
@@ -91,17 +84,17 @@ export class FormattingModel {
91
84
  //
92
85
 
93
86
  case ValueTypeEnum.DateTime: {
94
- const date = this._model.toLocalDate(value as number);
87
+ const date = this.model.toLocalDate(value as number);
95
88
  return { value: date.toLocaleString(locales), classNames };
96
89
  }
97
90
 
98
91
  case ValueTypeEnum.Date: {
99
- const date = this._model.toLocalDate(value as number);
92
+ const date = this.model.toLocalDate(value as number);
100
93
  return { value: date.toLocaleDateString(locales), classNames };
101
94
  }
102
95
 
103
96
  case ValueTypeEnum.Time: {
104
- const date = this._model.toLocalDate(value as number);
97
+ const date = this.model.toLocalDate(value as number);
105
98
  return { value: date.toLocaleTimeString(locales), classNames };
106
99
  }
107
100
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { type MouseEvent, useEffect, useState } from 'react';
6
6
 
7
- import { type CellAddress, type CellIndex, addressFromA1Notation, addressToA1Notation } from '../../defs';
7
+ import { type CellAddress, type CellIndex, addressFromA1Notation, addressToA1Notation } from '../../model';
8
8
 
9
9
  // export type Bounds = Pick<DOMRect, 'left' | 'top' | 'width' | 'height'>;
10
10
  // export type Dimension = Pick<DOMRect, 'width' | 'height'>;
@@ -12,7 +12,7 @@ import { type CellAddress, type CellIndex, addressFromA1Notation, addressToA1Not
12
12
  export type SizeMap = Record<string, number>;
13
13
 
14
14
  export type RowPosition = { row: number } & Pick<DOMRect, 'top' | 'height'>;
15
- export type ColumnPosition = { col: number } & Pick<DOMRect, 'left' | 'width'>;
15
+ export type ColumnPosition = { column: number } & Pick<DOMRect, 'left' | 'width'>;
16
16
 
17
17
  export const axisWidth = 'calc(var(--rail-size)-2px)';
18
18
  export const axisHeight = 34;
@@ -88,7 +88,7 @@ export const useGridLayout = ({
88
88
  const width = columnSizes?.[idx] ?? defaultWidth;
89
89
  const left = x;
90
90
  x += width - 1;
91
- return { col: i, left, width };
91
+ return { column: i, left, width };
92
92
  }),
93
93
  );
94
94
  }, [columns, columnSizes]);