@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,399 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type SimpleCellRange } from 'hyperformula/typings/AbsoluteCellRange';
6
- import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
7
- import { type SimpleDate, type SimpleDateTime } from 'hyperformula/typings/DateTimeHelper';
8
-
9
- import { Event } from '@dxos/async';
10
- import { Resource } from '@dxos/context';
11
- import { invariant } from '@dxos/invariant';
12
- import { PublicKey } from '@dxos/keys';
13
- import { log } from '@dxos/log';
14
-
15
- import { DetailedCellError, ExportedCellChange } from '#hyperformula';
16
- import {
17
- addressFromA1Notation,
18
- addressToA1Notation,
19
- type CellAddress,
20
- type CellRange,
21
- MAX_COLUMNS,
22
- MAX_ROWS,
23
- } from '../defs';
24
- import { addressFromIndex, addressToIndex, initialize, insertIndices, ReadonlyException } from '../defs';
25
- import { type ComputeNode, type ComputeGraph, createSheetName } from '../graph';
26
- import { type CellScalarValue, type CellValue, type SheetType, ValueTypeEnum } from '../types';
27
-
28
- const typeMap: Record<string, ValueTypeEnum> = {
29
- BOOLEAN: ValueTypeEnum.Boolean,
30
- NUMBER_RAW: ValueTypeEnum.Number,
31
- NUMBER_PERCENT: ValueTypeEnum.Percent,
32
- NUMBER_CURRENCY: ValueTypeEnum.Currency,
33
- NUMBER_DATETIME: ValueTypeEnum.DateTime,
34
- NUMBER_DATE: ValueTypeEnum.Date,
35
- NUMBER_TIME: ValueTypeEnum.Time,
36
- };
37
-
38
- const getTopLeft = (range: CellRange): CellAddress => {
39
- const to = range.to ?? range.from;
40
- return { row: Math.min(range.from.row, to.row), col: Math.min(range.from.col, to.col) };
41
- };
42
-
43
- const toSimpleCellAddress = (sheet: number, cell: CellAddress): SimpleCellAddress => ({
44
- sheet,
45
- row: cell.row,
46
- col: cell.col,
47
- });
48
-
49
- const toModelRange = (sheet: number, range: CellRange): SimpleCellRange => ({
50
- start: toSimpleCellAddress(sheet, range.from),
51
- end: toSimpleCellAddress(sheet, range.to ?? range.from),
52
- });
53
-
54
- export type SheetModelOptions = {
55
- readonly?: boolean;
56
- };
57
-
58
- /**
59
- * Spreadsheet data model.
60
- *
61
- * [ComputeGraphContext] > [SheetContext]:[SheetModel] > [Sheet.Root]
62
- */
63
- // TODO(burdon): Factor out commonality with ComputeNode.
64
- export class SheetModel extends Resource {
65
- public readonly id = `model-${PublicKey.random().truncate()}`;
66
-
67
- public readonly update = new Event();
68
-
69
- private readonly _node: ComputeNode;
70
-
71
- constructor(
72
- private readonly _graph: ComputeGraph,
73
- private readonly _sheet: SheetType,
74
- private readonly _options: SheetModelOptions = {},
75
- ) {
76
- super();
77
- // TODO(burdon): SheetModel should extend ComputeNode and be constructed via the graph.
78
- this._node = this._graph.getOrCreateNode(createSheetName(this._sheet.id));
79
- this.reset();
80
- }
81
-
82
- get graph() {
83
- return this._graph;
84
- }
85
-
86
- get sheet() {
87
- return this._sheet;
88
- }
89
-
90
- get readonly() {
91
- return this._options.readonly;
92
- }
93
-
94
- get bounds() {
95
- return {
96
- rows: this._sheet.rows.length,
97
- columns: this._sheet.columns.length,
98
- };
99
- }
100
-
101
- /**
102
- * Initialize sheet and engine.
103
- */
104
- protected override async _open() {
105
- log('initialize', { id: this.id });
106
- initialize(this._sheet);
107
- this.reset();
108
-
109
- // TODO(burdon): Event hierarchy?
110
- // Listen for model updates (e.g., async calculations).
111
- const unsubscribe = this._graph.update.on(() => this.update.emit());
112
- this._ctx.onDispose(unsubscribe);
113
- }
114
-
115
- /**
116
- * Update engine.
117
- * NOTE: This resets the undo history.
118
- * @deprecated
119
- */
120
- reset() {
121
- this._node.hf.clearSheet(this._node.sheetId);
122
- Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
123
- const { col, row } = addressFromIndex(this._sheet, key);
124
- if (typeof value === 'string' && value.charAt(0) === '=') {
125
- value = this._graph.mapFormulaToNative(
126
- this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)),
127
- );
128
- }
129
-
130
- this._node.hf.setCellContents({ sheet: this._node.sheetId, row, col }, value);
131
- });
132
- }
133
-
134
- /**
135
- * Recalculate formulas.
136
- * NOTE: This resets the undo history.
137
- * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
138
- * @deprecated
139
- */
140
- // TODO(burdon): Remove.
141
- recalculate() {
142
- this._node.hf.rebuildAndRecalculate();
143
- }
144
-
145
- insertRows(i: number, n = 1) {
146
- insertIndices(this._sheet.rows, i, n, MAX_ROWS);
147
- this.reset();
148
- }
149
-
150
- insertColumns(i: number, n = 1) {
151
- insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
152
- this.reset();
153
- }
154
-
155
- //
156
- // Undoable actions.
157
- // TODO(burdon): Group undoable methods; consistently update hf/sheet.
158
- //
159
-
160
- /**
161
- * Clear range of values.
162
- */
163
- clear(range: CellRange) {
164
- const topLeft = getTopLeft(range);
165
- const values = this._iterRange(range, () => null);
166
- this._node.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
167
- this._iterRange(range, (cell) => {
168
- const idx = addressToIndex(this._sheet, cell);
169
- delete this._sheet.cells[idx];
170
- });
171
- }
172
-
173
- cut(range: CellRange) {
174
- this._node.hf.cut(toModelRange(this._node.sheetId, range));
175
- this._iterRange(range, (cell) => {
176
- const idx = addressToIndex(this._sheet, cell);
177
- delete this._sheet.cells[idx];
178
- });
179
- }
180
-
181
- copy(range: CellRange) {
182
- this._node.hf.copy(toModelRange(this._node.sheetId, range));
183
- }
184
-
185
- paste(cell: CellAddress) {
186
- if (!this._node.hf.isClipboardEmpty()) {
187
- const changes = this._node.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
188
- for (const change of changes) {
189
- if (change instanceof ExportedCellChange) {
190
- const { address, newValue } = change;
191
- const idx = addressToIndex(this._sheet, { row: address.row, col: address.col });
192
- this._sheet.cells[idx] = { value: newValue };
193
- }
194
- }
195
- }
196
- }
197
-
198
- // TODO(burdon): Display undo/redo state.
199
- undo() {
200
- if (this._node.hf.isThereSomethingToUndo()) {
201
- this._node.hf.undo();
202
- this.update.emit();
203
- }
204
- }
205
-
206
- redo() {
207
- if (this._node.hf.isThereSomethingToRedo()) {
208
- this._node.hf.redo();
209
- this.update.emit();
210
- }
211
- }
212
-
213
- /**
214
- * Get value from sheet.
215
- */
216
- getCellValue(cell: CellAddress): CellScalarValue {
217
- const idx = addressToIndex(this._sheet, cell);
218
- return this._sheet.cells[idx]?.value ?? null;
219
- }
220
-
221
- /**
222
- * Get value as a string for editing.
223
- */
224
- getCellText(cell: CellAddress): string | undefined {
225
- const value = this.getCellValue(cell);
226
- if (value == null) {
227
- return undefined;
228
- }
229
-
230
- if (typeof value === 'string' && value.charAt(0) === '=') {
231
- return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
232
- } else {
233
- return String(value);
234
- }
235
- }
236
-
237
- /**
238
- * Get array of raw values from sheet.
239
- */
240
- getCellValues(range: CellRange): CellScalarValue[][] {
241
- return this._iterRange(range, (cell) => this.getCellValue(cell));
242
- }
243
-
244
- /**
245
- * Gets the regular or computed value from the engine.
246
- */
247
- getValue(cell: CellAddress): CellScalarValue {
248
- // Applies rounding and post-processing.
249
- const value = this._node.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
250
- if (value instanceof DetailedCellError) {
251
- return value.toString();
252
- }
253
-
254
- return value;
255
- }
256
-
257
- /**
258
- * Get value type.
259
- */
260
- getValueType(cell: CellAddress): ValueTypeEnum {
261
- const addr = toSimpleCellAddress(this._node.sheetId, cell);
262
- const type = this._node.hf.getCellValueDetailedType(addr);
263
- return typeMap[type];
264
- }
265
-
266
- /**
267
- * Sets the value, updating the sheet and engine.
268
- */
269
- setValue(cell: CellAddress, value: CellScalarValue) {
270
- if (this._options.readonly) {
271
- throw new ReadonlyException();
272
- }
273
-
274
- // Reallocate if > current bounds.
275
- let refresh = false;
276
- if (cell.row >= this._sheet.rows.length) {
277
- insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
278
- refresh = true;
279
- }
280
- if (cell.col >= this._sheet.columns.length) {
281
- insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
282
- refresh = true;
283
- }
284
-
285
- if (refresh) {
286
- // TODO(burdon): Remove.
287
- this.reset();
288
- }
289
-
290
- // Insert into engine.
291
- this._node.hf.setCellContents({ sheet: this._node.sheetId, row: cell.row, col: cell.col }, [
292
- [typeof value === 'string' && value.charAt(0) === '=' ? this._graph.mapFormulaToNative(value) : value],
293
- ]);
294
-
295
- // Insert into sheet.
296
- const idx = addressToIndex(this._sheet, cell);
297
- if (value === undefined || value === null) {
298
- delete this._sheet.cells[idx];
299
- } else {
300
- if (typeof value === 'string' && value.charAt(0) === '=') {
301
- value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
302
- }
303
-
304
- this._sheet.cells[idx] = { value };
305
- }
306
- }
307
-
308
- /**
309
- * Sets values from a simple map.
310
- */
311
- setValues(values: Record<string, CellValue>) {
312
- Object.entries(values).forEach(([key, { value }]) => {
313
- this.setValue(addressFromA1Notation(key), value);
314
- });
315
- }
316
-
317
- /**
318
- * Iterate range.
319
- */
320
- private _iterRange(range: CellRange, cb: (cell: CellAddress) => CellScalarValue | void): CellScalarValue[][] {
321
- const to = range.to ?? range.from;
322
- const rowRange = [Math.min(range.from.row, to.row), Math.max(range.from.row, to.row)];
323
- const columnRange = [Math.min(range.from.col, to.col), Math.max(range.from.col, to.col)];
324
- const rows: CellScalarValue[][] = [];
325
- for (let row = rowRange[0]; row <= rowRange[1]; row++) {
326
- const rowCells: CellScalarValue[] = [];
327
- for (let column = columnRange[0]; column <= columnRange[1]; column++) {
328
- const value = cb({ row, col: column });
329
- if (value !== undefined) {
330
- rowCells.push(value);
331
- }
332
- }
333
-
334
- rows.push(rowCells);
335
- }
336
-
337
- return rows;
338
- }
339
-
340
- // TODO(burdon): Delete index.
341
- private _deleteIndices(indices: string[], i: number, n: number) {
342
- throw new Error('Not implemented');
343
- }
344
-
345
- // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
346
- private _moveIndices(indices: string[], i: number, j: number, n: number) {
347
- throw new Error('Not implemented');
348
- }
349
-
350
- //
351
- // Indices.
352
- //
353
-
354
- /**
355
- * Map from A1 notation to indices.
356
- */
357
- mapFormulaRefsToIndices(formula: string): string {
358
- invariant(formula.charAt(0) === '=');
359
- return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
360
- return addressToIndex(this._sheet, addressFromA1Notation(match));
361
- });
362
- }
363
-
364
- /**
365
- * Map from indices to A1 notation.
366
- */
367
- mapFormulaIndicesToRefs(formula: string): string {
368
- invariant(formula.charAt(0) === '=');
369
- return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
370
- return addressToA1Notation(addressFromIndex(this._sheet, idx));
371
- });
372
- }
373
-
374
- //
375
- // Values
376
- //
377
-
378
- /**
379
- * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
380
- * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
381
- * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
382
- */
383
- toLocalDate(num: number): Date {
384
- const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
385
- return new Date(year, month - 1, day, hours, minutes, seconds);
386
- }
387
-
388
- toDateTime(num: number): SimpleDateTime {
389
- return this._node.hf.numberToDateTime(num) as SimpleDateTime;
390
- }
391
-
392
- toDate(num: number): SimpleDate {
393
- return this._node.hf.numberToDate(num) as SimpleDate;
394
- }
395
-
396
- toTime(num: number): SimpleDate {
397
- return this._node.hf.numberToTime(num) as SimpleDate;
398
- }
399
- }
@@ -1,40 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { describe, test, expect } from 'vitest';
6
-
7
- // Part 2.
8
- // TODO(burdon): Cannot test outside of browser.
9
- // - Cannot test Hyperformula
10
- // - throws "Cannot convert undefined or null to object" in vitest (no browser).
11
- // - throws "process.nextTick is not a function" (if browser)
12
-
13
- import { Client } from '@dxos/client';
14
- import { create } from '@dxos/client/echo';
15
- import { FunctionType } from '@dxos/plugin-script/types';
16
-
17
- // TODO(burdon): Fix test infrastructure:
18
- // - Need docs? esp. needed for config. need pristine example package?
19
- // - NOTE for non browser tests, import types from x-plugin/types (otherwise will bring in react deps).
20
- // - Can't add flags to our tools?
21
- // - .only / .skip ignored (have to comment out tests)
22
-
23
- describe('test', () => {
24
- test('test', async () => {
25
- const client = new Client();
26
- client.addTypes([FunctionType]);
27
- await client.initialize();
28
- await client.halo.createIdentity();
29
-
30
- // Part 1.
31
- // Create script.
32
- // VITEST_ENV=chromium p test
33
- // TODO(burdon): Test after initialize.
34
- // - ERROR "process.nextTick is not a function"
35
- // - ERROR "Identifier 'Buffer' has already been declared" if { nodeExternal: true }
36
- const space = await client.spaces.create();
37
- const fn = space.db.add(create(FunctionType, { version: 1, binding: 'HELLO' }));
38
- expect(fn).to.exist;
39
- });
40
- });
@@ -1,5 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- export * from './testing';
@@ -1,66 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import type { Decorator } from '@storybook/react';
6
- import React, { useState } from 'react';
7
-
8
- import { type Space } from '@dxos/react-client/echo';
9
- import { useAsyncState } from '@dxos/react-hooks';
10
-
11
- import { ComputeGraphContextProvider } from '../components';
12
- import { createSheet } from '../defs';
13
- import { type ComputeGraph, ComputeGraphRegistry } from '../graph';
14
- import { type CellValue, type CreateSheetOptions } from '../types';
15
-
16
- export const testSheetName = 'test';
17
-
18
- // TODO(thure): Remove this from the `/testing` entrypoint.
19
- export const createCells = (): Record<string, CellValue> => ({
20
- B1: { value: 'Qty' },
21
- B3: { value: 1 },
22
- B4: { value: 2 },
23
- B5: { value: 3 },
24
- B7: { value: 'Total' },
25
-
26
- C1: { value: 'Price' },
27
- C3: { value: 2_000 },
28
- C4: { value: 2_500 },
29
- C5: { value: 3_000 },
30
- C7: { value: '=SUMPRODUCT(B2:B6, C2:C6)' },
31
- // C8: { value: '=C7*CRYPTO(D7)' },
32
- C8: { value: '=C7*TEST()' },
33
-
34
- D7: { value: 'USD' },
35
- D8: { value: 'BTC' },
36
-
37
- E3: { value: '=TODAY()' },
38
- E4: { value: '=NOW()' },
39
-
40
- F1: { value: `=${testSheetName}!A1` }, // Ref test sheet.
41
- F3: { value: true },
42
- F4: { value: false },
43
- F5: { value: '8%' },
44
- F6: { value: '$10000' },
45
- });
46
-
47
- export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: CreateSheetOptions) => {
48
- return useAsyncState(async () => {
49
- if (!space || !graph) {
50
- return;
51
- }
52
-
53
- const sheet = createSheet(options);
54
- space.db.add(sheet);
55
- return sheet;
56
- }, [space, graph]);
57
- };
58
-
59
- export const withGraphDecorator: Decorator = (Story) => {
60
- const [registry] = useState(new ComputeGraphRegistry());
61
- return (
62
- <ComputeGraphContextProvider registry={registry}>
63
- <Story />
64
- </ComputeGraphContextProvider>
65
- );
66
- };
File without changes