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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (330) hide show
  1. package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs +297 -0
  2. package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-BVUN7SHF.mjs +67 -0
  4. package/dist/lib/browser/chunk-BVUN7SHF.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-G2FUL6PK.mjs +1671 -0
  6. package/dist/lib/browser/chunk-G2FUL6PK.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-RABELMEQ.mjs +15 -0
  8. package/dist/lib/browser/chunk-RABELMEQ.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-D5AGLXJP.mjs → chunk-VMSX6Z4X.mjs} +659 -675
  10. package/dist/lib/browser/chunk-VMSX6Z4X.mjs.map +7 -0
  11. package/dist/lib/browser/compute-graph-GGWUX644.mjs +35 -0
  12. package/dist/lib/browser/compute-graph-GGWUX644.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +168 -67
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/meta.mjs +1 -1
  17. package/dist/lib/browser/types.mjs +6 -12
  18. package/dist/lib/node/SheetContainer-PJE74VO4.cjs +300 -0
  19. package/dist/lib/node/SheetContainer-PJE74VO4.cjs.map +7 -0
  20. package/dist/lib/node/chunk-2ZVZI2KJ.cjs +38 -0
  21. package/dist/lib/node/chunk-2ZVZI2KJ.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-AWKOWDMI.cjs} +34 -52
  23. package/dist/lib/node/chunk-AWKOWDMI.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-O7XR4R7Y.cjs} +678 -674
  25. package/dist/lib/node/chunk-O7XR4R7Y.cjs.map +7 -0
  26. package/dist/lib/node/chunk-STZ7S7RF.cjs +1656 -0
  27. package/dist/lib/node/chunk-STZ7S7RF.cjs.map +7 -0
  28. package/dist/lib/node/compute-graph-KGWA2QLE.cjs +57 -0
  29. package/dist/lib/node/compute-graph-KGWA2QLE.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +178 -75
  31. package/dist/lib/node/index.cjs.map +4 -4
  32. package/dist/lib/node/meta.cjs +3 -3
  33. package/dist/lib/node/meta.cjs.map +1 -1
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/types.cjs +9 -15
  36. package/dist/lib/node/types.cjs.map +2 -2
  37. package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs +298 -0
  38. package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs +17 -0
  40. package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-CR4K75EL.mjs +3220 -0
  42. package/dist/lib/node-esm/chunk-CR4K75EL.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-UIBWRHW7.mjs +68 -0
  44. package/dist/lib/node-esm/chunk-UIBWRHW7.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs +1672 -0
  46. package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs.map +7 -0
  47. package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs +36 -0
  48. package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs.map +7 -0
  49. package/dist/lib/node-esm/index.mjs +350 -0
  50. package/dist/lib/node-esm/index.mjs.map +7 -0
  51. package/dist/lib/node-esm/meta.json +1 -0
  52. package/dist/lib/node-esm/meta.mjs +10 -0
  53. package/dist/lib/node-esm/meta.mjs.map +7 -0
  54. package/dist/lib/node-esm/types.mjs +17 -0
  55. package/dist/lib/node-esm/types.mjs.map +7 -0
  56. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  57. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +13 -0
  58. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -0
  59. package/dist/types/src/components/ComputeGraph/index.d.ts +1 -3
  60. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  61. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +3 -0
  62. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -0
  63. package/dist/types/src/components/FunctionEditor/index.d.ts +2 -0
  64. package/dist/types/src/components/FunctionEditor/index.d.ts.map +1 -0
  65. package/dist/types/src/components/GridSheet/GridSheet.d.ts +3 -0
  66. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -0
  67. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +6 -0
  68. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -0
  69. package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +5 -9
  70. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/GridSheet/index.d.ts +2 -0
  72. package/dist/types/src/components/GridSheet/index.d.ts.map +1 -0
  73. package/dist/types/src/components/GridSheet/util.d.ts +15 -0
  74. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
  75. package/dist/types/src/components/RangeList/RangeList.d.ts +7 -0
  76. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -0
  77. package/dist/types/src/components/RangeList/index.d.ts +2 -0
  78. package/dist/types/src/components/RangeList/index.d.ts.map +1 -0
  79. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +9 -0
  80. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +6 -0
  82. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
  83. package/dist/types/src/components/SheetContainer/index.d.ts +3 -0
  84. package/dist/types/src/components/SheetContainer/index.d.ts.map +1 -0
  85. package/dist/types/src/components/SheetContext/SheetContext.d.ts +28 -0
  86. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -0
  87. package/dist/types/src/components/SheetContext/index.d.ts +2 -0
  88. package/dist/types/src/components/SheetContext/index.d.ts.map +1 -0
  89. package/dist/types/src/components/Toolbar/Toolbar.d.ts +36 -9
  90. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  91. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +4 -32
  92. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  93. package/dist/types/src/components/index.d.ts +7 -4
  94. package/dist/types/src/components/index.d.ts.map +1 -1
  95. package/dist/types/src/compute-graph/compute-graph-registry.d.ts +34 -0
  96. package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +1 -0
  97. package/dist/types/src/compute-graph/compute-graph.d.ts +64 -0
  98. package/dist/types/src/compute-graph/compute-graph.d.ts.map +1 -0
  99. package/dist/types/src/compute-graph/compute-graph.stories.d.ts +6 -0
  100. package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +1 -0
  101. package/dist/types/src/compute-graph/compute-graph.test.d.ts +2 -0
  102. package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +1 -0
  103. package/dist/types/src/compute-graph/compute-node.d.ts +26 -0
  104. package/dist/types/src/compute-graph/compute-node.d.ts.map +1 -0
  105. package/dist/types/src/{components/ComputeGraph → compute-graph/functions}/async-function.d.ts +14 -5
  106. package/dist/types/src/compute-graph/functions/async-function.d.ts.map +1 -0
  107. package/dist/types/src/compute-graph/functions/edge-function.d.ts +21 -0
  108. package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +1 -0
  109. package/dist/types/src/{model/functions.d.ts → compute-graph/functions/function-defs.d.ts} +1 -1
  110. package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +1 -0
  111. package/dist/types/src/compute-graph/functions/index.d.ts +4 -0
  112. package/dist/types/src/compute-graph/functions/index.d.ts.map +1 -0
  113. package/dist/types/src/compute-graph/hyperformula.test.d.ts +2 -0
  114. package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +1 -0
  115. package/dist/types/src/compute-graph/index.d.ts +5 -0
  116. package/dist/types/src/compute-graph/index.d.ts.map +1 -0
  117. package/dist/types/src/compute-graph/testing/index.d.ts +3 -0
  118. package/dist/types/src/compute-graph/testing/index.d.ts.map +1 -0
  119. package/dist/types/src/compute-graph/testing/test-builder.d.ts +15 -0
  120. package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +1 -0
  121. package/dist/types/src/compute-graph/testing/test-plugin.d.ts +36 -0
  122. package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +1 -0
  123. package/dist/types/src/compute-graph/util.d.ts +2 -0
  124. package/dist/types/src/compute-graph/util.d.ts.map +1 -0
  125. package/dist/types/src/defs/index.d.ts +4 -0
  126. package/dist/types/src/defs/index.d.ts.map +1 -0
  127. package/dist/types/src/defs/sheet-range-types.d.ts +13 -0
  128. package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -0
  129. package/dist/types/src/defs/types.d.ts +28 -0
  130. package/dist/types/src/defs/types.d.ts.map +1 -0
  131. package/dist/types/src/defs/types.test.d.ts.map +1 -0
  132. package/dist/types/src/defs/util.d.ts +39 -0
  133. package/dist/types/src/defs/util.d.ts.map +1 -0
  134. package/dist/types/src/extensions/compute.d.ts +6 -0
  135. package/dist/types/src/extensions/compute.d.ts.map +1 -0
  136. package/dist/types/src/extensions/compute.stories.d.ts +21 -0
  137. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
  138. package/dist/types/src/extensions/editor/extension.d.ts +39 -0
  139. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
  140. package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
  141. package/dist/types/src/extensions/editor/index.d.ts +2 -0
  142. package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
  143. package/dist/types/src/extensions/index.d.ts +3 -0
  144. package/dist/types/src/extensions/index.d.ts.map +1 -0
  145. package/dist/types/src/index.d.ts +1 -1
  146. package/dist/types/src/index.d.ts.map +1 -1
  147. package/dist/types/src/integrations/index.d.ts +2 -0
  148. package/dist/types/src/integrations/index.d.ts.map +1 -0
  149. package/dist/types/src/integrations/thread-ranges.d.ts +7 -0
  150. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -0
  151. package/dist/types/src/meta.d.ts +4 -9
  152. package/dist/types/src/meta.d.ts.map +1 -1
  153. package/dist/types/src/model/index.d.ts +2 -3
  154. package/dist/types/src/model/index.d.ts.map +1 -1
  155. package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +22 -69
  156. package/dist/types/src/model/sheet-model.d.ts.map +1 -0
  157. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  158. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  159. package/dist/types/src/model/useSheetModel.d.ts +8 -0
  160. package/dist/types/src/model/useSheetModel.d.ts.map +1 -0
  161. package/dist/types/src/sanity.test.d.ts +2 -0
  162. package/dist/types/src/sanity.test.d.ts.map +1 -0
  163. package/dist/types/src/serializer.d.ts +4 -0
  164. package/dist/types/src/serializer.d.ts.map +1 -0
  165. package/dist/types/src/testing/index.d.ts +2 -0
  166. package/dist/types/src/testing/index.d.ts.map +1 -0
  167. package/dist/types/src/testing/testing.d.ts +8 -0
  168. package/dist/types/src/testing/testing.d.ts.map +1 -0
  169. package/dist/types/src/translations.d.ts +32 -12
  170. package/dist/types/src/translations.d.ts.map +1 -1
  171. package/dist/types/src/types.d.ts +132 -43
  172. package/dist/types/src/types.d.ts.map +1 -1
  173. package/dist/vendor/hyperformula.mjs +37145 -0
  174. package/package.json +60 -61
  175. package/src/SheetPlugin.tsx +89 -78
  176. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +37 -0
  177. package/src/components/ComputeGraph/index.ts +1 -3
  178. package/src/components/FunctionEditor/FunctionEditor.tsx +45 -0
  179. package/src/components/FunctionEditor/index.ts +5 -0
  180. package/src/components/GridSheet/GridSheet.stories.tsx +46 -0
  181. package/src/components/GridSheet/GridSheet.tsx +358 -0
  182. package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +18 -15
  183. package/src/components/GridSheet/index.ts +5 -0
  184. package/src/components/GridSheet/util.ts +170 -0
  185. package/src/components/RangeList/RangeList.tsx +53 -0
  186. package/src/components/RangeList/index.ts +5 -0
  187. package/src/components/SheetContainer/SheetContainer.stories.tsx +45 -0
  188. package/src/components/SheetContainer/SheetContainer.tsx +33 -0
  189. package/src/components/SheetContainer/index.ts +7 -0
  190. package/src/components/SheetContext/SheetContext.tsx +127 -0
  191. package/src/components/SheetContext/index.ts +5 -0
  192. package/src/components/Toolbar/Toolbar.stories.tsx +9 -6
  193. package/src/components/Toolbar/Toolbar.tsx +265 -111
  194. package/src/components/index.ts +5 -3
  195. package/src/compute-graph/compute-graph-registry.ts +90 -0
  196. package/src/compute-graph/compute-graph.stories.tsx +97 -0
  197. package/src/compute-graph/compute-graph.test.ts +87 -0
  198. package/src/compute-graph/compute-graph.ts +260 -0
  199. package/src/compute-graph/compute-node.ts +62 -0
  200. package/src/{components/ComputeGraph → compute-graph/functions}/async-function.ts +26 -15
  201. package/src/{components/ComputeGraph → compute-graph/functions}/edge-function.ts +21 -17
  202. package/src/compute-graph/functions/index.ts +7 -0
  203. package/src/compute-graph/hyperformula.test.ts +14 -0
  204. package/src/compute-graph/index.ts +8 -0
  205. package/src/compute-graph/testing/index.ts +6 -0
  206. package/src/compute-graph/testing/test-builder.ts +54 -0
  207. package/src/{components/ComputeGraph/custom.ts → compute-graph/testing/test-plugin.ts} +44 -14
  208. package/src/compute-graph/util.ts +8 -0
  209. package/src/defs/index.ts +7 -0
  210. package/src/defs/sheet-range-types.ts +49 -0
  211. package/src/{model → defs}/types.test.ts +8 -9
  212. package/src/defs/types.ts +86 -0
  213. package/src/defs/util.ts +136 -0
  214. package/src/extensions/compute.stories.tsx +155 -0
  215. package/src/extensions/compute.ts +147 -0
  216. package/src/{components/CellEditor → extensions/editor}/extension.test.ts +4 -6
  217. package/src/{components/CellEditor → extensions/editor}/extension.ts +51 -27
  218. package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
  219. package/src/extensions/index.ts +6 -0
  220. package/src/index.ts +2 -2
  221. package/src/integrations/index.ts +5 -0
  222. package/src/integrations/thread-ranges.ts +101 -0
  223. package/src/meta.ts +15 -0
  224. package/src/model/index.ts +2 -3
  225. package/src/model/sheet-model.test.ts +59 -0
  226. package/src/model/sheet-model.ts +495 -0
  227. package/src/model/useSheetModel.ts +40 -0
  228. package/src/sanity.test.ts +40 -0
  229. package/src/serializer.ts +27 -0
  230. package/src/{components/Sheet → testing}/index.ts +1 -1
  231. package/src/testing/testing.tsx +68 -0
  232. package/src/translations.ts +24 -4
  233. package/src/types.ts +62 -47
  234. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +0 -1772
  235. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
  236. package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
  237. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
  238. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
  239. package/dist/lib/browser/chunk-FUAGSXA4.mjs +0 -82
  240. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
  241. package/dist/lib/browser/chunk-JRL5LGCE.mjs +0 -18
  242. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
  243. package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
  244. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
  245. package/dist/lib/browser/testing.mjs +0 -92
  246. package/dist/lib/browser/testing.mjs.map +0 -7
  247. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +0 -1765
  248. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
  249. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
  250. package/dist/lib/node/chunk-BJ6ZD7MN.cjs +0 -51
  251. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
  252. package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
  253. package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
  254. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
  255. package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
  256. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
  257. package/dist/lib/node/testing.cjs +0 -111
  258. package/dist/lib/node/testing.cjs.map +0 -7
  259. package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -14
  260. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
  261. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
  262. package/dist/types/src/components/CellEditor/extension.d.ts +0 -19
  263. package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
  264. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
  265. package/dist/types/src/components/CellEditor/index.d.ts +0 -3
  266. package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
  267. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
  268. package/dist/types/src/components/ComputeGraph/custom.d.ts +0 -21
  269. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
  270. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +0 -20
  271. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
  272. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
  273. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
  274. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
  275. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
  276. package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
  277. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
  278. package/dist/types/src/components/Sheet/Sheet.d.ts +0 -55
  279. package/dist/types/src/components/Sheet/Sheet.d.ts.map +0 -1
  280. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +0 -54
  281. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
  282. package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
  283. package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
  284. package/dist/types/src/components/Sheet/grid.d.ts +0 -52
  285. package/dist/types/src/components/Sheet/grid.d.ts.map +0 -1
  286. package/dist/types/src/components/Sheet/index.d.ts +0 -2
  287. package/dist/types/src/components/Sheet/index.d.ts.map +0 -1
  288. package/dist/types/src/components/Sheet/nav.d.ts +0 -29
  289. package/dist/types/src/components/Sheet/nav.d.ts.map +0 -1
  290. package/dist/types/src/components/Sheet/sheet-context.d.ts +0 -25
  291. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
  292. package/dist/types/src/components/Sheet/util.d.ts +0 -18
  293. package/dist/types/src/components/Sheet/util.d.ts.map +0 -1
  294. package/dist/types/src/components/SheetContainer.d.ts +0 -9
  295. package/dist/types/src/components/SheetContainer.d.ts.map +0 -1
  296. package/dist/types/src/components/Toolbar/common.d.ts +0 -20
  297. package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
  298. package/dist/types/src/model/functions.d.ts.map +0 -1
  299. package/dist/types/src/model/model.browser.test.d.ts +0 -2
  300. package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
  301. package/dist/types/src/model/model.d.ts.map +0 -1
  302. package/dist/types/src/model/types.d.ts +0 -17
  303. package/dist/types/src/model/types.d.ts.map +0 -1
  304. package/dist/types/src/model/types.test.d.ts.map +0 -1
  305. package/dist/types/src/model/util.d.ts +0 -15
  306. package/dist/types/src/model/util.d.ts.map +0 -1
  307. package/dist/types/src/testing.d.ts +0 -9
  308. package/dist/types/src/testing.d.ts.map +0 -1
  309. package/src/components/CellEditor/CellEditor.tsx +0 -113
  310. package/src/components/ComputeGraph/graph-context.tsx +0 -50
  311. package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
  312. package/src/components/ComputeGraph/graph.ts +0 -62
  313. package/src/components/Sheet/Sheet.stories.tsx +0 -287
  314. package/src/components/Sheet/Sheet.tsx +0 -1160
  315. package/src/components/Sheet/formatting.ts +0 -106
  316. package/src/components/Sheet/grid.ts +0 -191
  317. package/src/components/Sheet/nav.ts +0 -157
  318. package/src/components/Sheet/sheet-context.tsx +0 -150
  319. package/src/components/Sheet/util.ts +0 -56
  320. package/src/components/SheetContainer.tsx +0 -34
  321. package/src/components/Toolbar/common.tsx +0 -72
  322. package/src/meta.tsx +0 -18
  323. package/src/model/model.browser.test.ts +0 -100
  324. package/src/model/model.ts +0 -550
  325. package/src/model/types.ts +0 -71
  326. package/src/model/util.ts +0 -36
  327. package/src/testing.ts +0 -50
  328. /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
  329. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
  330. /package/src/{model/functions.ts → compute-graph/functions/function-defs.ts} +0 -0
@@ -1,550 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { DetailedCellError, ExportedCellChange } from 'hyperformula';
6
- import { type SimpleCellRange } from 'hyperformula/typings/AbsoluteCellRange';
7
- import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
8
- import { type SimpleDate, type SimpleDateTime } from 'hyperformula/typings/DateTimeHelper';
9
-
10
- import { Event } from '@dxos/async';
11
- import { type Space } from '@dxos/client/echo';
12
- import { Context } from '@dxos/context';
13
- import { invariant } from '@dxos/invariant';
14
- import { PublicKey } from '@dxos/keys';
15
- import { log } from '@dxos/log';
16
- import { type FunctionType } from '@dxos/plugin-script/types';
17
-
18
- import { defaultFunctions, type FunctionDefinition } from './functions';
19
- import { addressFromA1Notation, addressToA1Notation, type CellAddress, type CellRange } from './types';
20
- import { createIndices, RangeException, ReadonlyException } from './util';
21
- import { type ComputeGraph } from '../components';
22
- import { type CellScalarValue, type CellValue, type SheetType, ValueTypeEnum } from '../types';
23
-
24
- const DEFAULT_ROWS = 100;
25
- const DEFAULT_COLUMNS = 26;
26
-
27
- export type CellIndex = string;
28
-
29
- export type CellContentValue = number | string | boolean | null;
30
-
31
- export type SheetModelOptions = {
32
- readonly?: boolean;
33
- rows: number;
34
- columns: number;
35
- mapFormulaBindingToId: (functions: FunctionType[]) => (formula: string) => string;
36
- mapFormulaBindingFromId: (functions: FunctionType[]) => (formula: string) => string;
37
- };
38
-
39
- const typeMap: Record<string, ValueTypeEnum> = {
40
- BOOLEAN: ValueTypeEnum.Boolean,
41
- NUMBER_RAW: ValueTypeEnum.Number,
42
- NUMBER_PERCENT: ValueTypeEnum.Percent,
43
- NUMBER_CURRENCY: ValueTypeEnum.Currency,
44
- NUMBER_DATETIME: ValueTypeEnum.DateTime,
45
- NUMBER_DATE: ValueTypeEnum.Date,
46
- NUMBER_TIME: ValueTypeEnum.Time,
47
- };
48
-
49
- export const defaultOptions: SheetModelOptions = {
50
- rows: 50,
51
- columns: 26,
52
- mapFormulaBindingFromId: () => (formula) => formula,
53
- mapFormulaBindingToId: () => (formula) => formula,
54
- };
55
-
56
- const getTopLeft = (range: CellRange) => {
57
- const to = range.to ?? range.from;
58
- return { row: Math.min(range.from.row, to.row), column: Math.min(range.from.column, to.column) };
59
- };
60
-
61
- const toSimpleCellAddress = (sheet: number, cell: CellAddress): SimpleCellAddress => ({
62
- sheet,
63
- row: cell.row,
64
- col: cell.column,
65
- });
66
-
67
- const toModelRange = (sheet: number, range: CellRange): SimpleCellRange => ({
68
- start: toSimpleCellAddress(sheet, range.from),
69
- end: toSimpleCellAddress(sheet, range.to ?? range.from),
70
- });
71
-
72
- /**
73
- * Spreadsheet data model.
74
- *
75
- * [ComputeGraphContext] > [SheetContext]:[SheetModel] > [Sheet.Root]
76
- */
77
- export class SheetModel {
78
- public readonly id = `model-${PublicKey.random().truncate()}`;
79
- private _ctx?: Context = undefined;
80
-
81
- /**
82
- * Formula engine.
83
- * Acts as a write through cache for scalar and computed values.
84
- */
85
- private readonly _sheetId: number;
86
- private readonly _options: SheetModelOptions;
87
- private _functions: FunctionType[] = [];
88
-
89
- public readonly update = new Event();
90
-
91
- constructor(
92
- private readonly _graph: ComputeGraph,
93
- private readonly _sheet: SheetType,
94
- private readonly _space?: Space,
95
- options: Partial<SheetModelOptions> = {},
96
- ) {
97
- // Sheet for this object.
98
- const name = this._sheet.id;
99
- if (!this._graph.hf.doesSheetExist(name)) {
100
- this._graph.hf.addSheet(name);
101
- }
102
- this._sheetId = this._graph.hf.getSheetId(name)!;
103
- this._options = { ...defaultOptions, ...options };
104
- this.reset();
105
- }
106
-
107
- get graph() {
108
- return this._graph;
109
- }
110
-
111
- get sheet() {
112
- return this._sheet;
113
- }
114
-
115
- get readonly() {
116
- return this._options.readonly;
117
- }
118
-
119
- get bounds() {
120
- return {
121
- rows: this._sheet.rows.length,
122
- columns: this._sheet.columns.length,
123
- };
124
- }
125
-
126
- get functions(): FunctionDefinition[] {
127
- const hfFunctions = this._graph.hf
128
- .getRegisteredFunctionNames()
129
- .map((name) => defaultFunctions.find((fn) => fn.name === name) ?? { name });
130
- const echoFunctions = this._functions.map((fn) => ({ name: fn.binding! }));
131
- return [...hfFunctions, ...echoFunctions];
132
- }
133
-
134
- get initialized(): boolean {
135
- return !!this._ctx;
136
- }
137
-
138
- /**
139
- * Initialize sheet and engine.
140
- */
141
- async initialize() {
142
- log('initialize', { id: this.id });
143
- invariant(!this.initialized, 'Already initialized.');
144
- this._ctx = new Context();
145
- if (!this._sheet.rows.length) {
146
- this._insertIndices(this._sheet.rows, 0, this._options.rows, DEFAULT_ROWS);
147
- }
148
- if (!this._sheet.columns.length) {
149
- this._insertIndices(this._sheet.columns, 0, this._options.columns, DEFAULT_COLUMNS);
150
- }
151
- this.reset();
152
-
153
- // Listen for model updates (e.g., async calculations).
154
- const unsubscribe = this._graph.update.on(() => this.update.emit());
155
- this._ctx.onDispose(unsubscribe);
156
-
157
- if (this._space) {
158
- const { Filter } = await import('@dxos/client/echo');
159
- const { FunctionType } = await import('@dxos/plugin-script/types');
160
-
161
- // Listen for function changes.
162
- const query = this._space?.db.query(Filter.schema(FunctionType));
163
- const unsubscribe = query.subscribe(({ objects }) => {
164
- this._functions = objects.filter((fn) => fn.binding);
165
- this.update.emit();
166
- });
167
- this._ctx.onDispose(unsubscribe);
168
- }
169
-
170
- return this;
171
- }
172
-
173
- async destroy() {
174
- log('destroy', { id: this.id });
175
- if (this._ctx) {
176
- await this._ctx.dispose();
177
- this._ctx = undefined;
178
- }
179
- }
180
-
181
- /**
182
- * Update engine.
183
- * NOTE: This resets the undo history.
184
- * @deprecated
185
- */
186
- reset() {
187
- this._graph.hf.clearSheet(this._sheetId);
188
- Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
189
- const { column, row } = this.addressFromIndex(key);
190
- if (typeof value === 'string' && value.charAt(0) === '=') {
191
- value = this.mapFormulaBindingToFormula(this.mapFormulaBindingFromId(this.mapFormulaIndicesToRefs(value)));
192
- }
193
-
194
- this._graph.hf.setCellContents({ sheet: this._sheetId, row, col: column }, value);
195
- });
196
- }
197
-
198
- /**
199
- * Recalculate formulas.
200
- * NOTE: This resets the undo history.
201
- * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
202
- * @deprecated
203
- */
204
- // TODO(burdon): Remove.
205
- recalculate() {
206
- this._graph.hf.rebuildAndRecalculate();
207
- }
208
-
209
- insertRows(i: number, n = 1) {
210
- this._insertIndices(this._sheet.rows, i, n, DEFAULT_ROWS);
211
- this.reset();
212
- }
213
-
214
- insertColumns(i: number, n = 1) {
215
- this._insertIndices(this._sheet.columns, i, n, DEFAULT_COLUMNS);
216
- this.reset();
217
- }
218
-
219
- //
220
- // Undoable actions.
221
- // TODO(burdon): Group undoable methods; consistently update hf/sheet.
222
- //
223
-
224
- /**
225
- * Clear range of values.
226
- */
227
- clear(range: CellRange) {
228
- const topLeft = getTopLeft(range);
229
- const values = this._iterRange(range, () => null);
230
- this._graph.hf.setCellContents(toSimpleCellAddress(this._sheetId, topLeft), values);
231
- this._iterRange(range, (cell) => {
232
- const idx = this.addressToIndex(cell);
233
- delete this._sheet.cells[idx];
234
- });
235
- }
236
-
237
- cut(range: CellRange) {
238
- this._graph.hf.cut(toModelRange(this._sheetId, range));
239
- this._iterRange(range, (cell) => {
240
- const idx = this.addressToIndex(cell);
241
- delete this._sheet.cells[idx];
242
- });
243
- }
244
-
245
- copy(range: CellRange) {
246
- this._graph.hf.copy(toModelRange(this._sheetId, range));
247
- }
248
-
249
- paste(cell: CellAddress) {
250
- if (!this._graph.hf.isClipboardEmpty()) {
251
- const changes = this._graph.hf.paste(toSimpleCellAddress(this._sheetId, cell));
252
- for (const change of changes) {
253
- if (change instanceof ExportedCellChange) {
254
- const { address, newValue } = change;
255
- const idx = this.addressToIndex({ row: address.row, column: address.col });
256
- this._sheet.cells[idx] = { value: newValue };
257
- }
258
- }
259
- }
260
- }
261
-
262
- // TODO(burdon): Display undo/redo state.
263
- undo() {
264
- if (this._graph.hf.isThereSomethingToUndo()) {
265
- this._graph.hf.undo();
266
- this.update.emit();
267
- }
268
- }
269
-
270
- redo() {
271
- if (this._graph.hf.isThereSomethingToRedo()) {
272
- this._graph.hf.redo();
273
- this.update.emit();
274
- }
275
- }
276
-
277
- /**
278
- * Get value from sheet.
279
- */
280
- getCellValue(cell: CellAddress): CellScalarValue {
281
- const idx = this.addressToIndex(cell);
282
- return this._sheet.cells[idx]?.value ?? null;
283
- }
284
-
285
- /**
286
- * Get value as a string for editing.
287
- */
288
- getCellText(cell: CellAddress): string | undefined {
289
- const value = this.getCellValue(cell);
290
- if (value == null) {
291
- return undefined;
292
- }
293
-
294
- if (typeof value === 'string' && value.charAt(0) === '=') {
295
- return this.mapFormulaBindingFromId(this.mapFormulaIndicesToRefs(value));
296
- } else {
297
- return String(value);
298
- }
299
- }
300
-
301
- /**
302
- * Get array of raw values from sheet.
303
- */
304
- getCellValues(range: CellRange): CellScalarValue[][] {
305
- return this._iterRange(range, (cell) => this.getCellValue(cell));
306
- }
307
-
308
- /**
309
- * Gets the regular or computed value from the engine.
310
- */
311
- getValue(cell: CellAddress): CellScalarValue {
312
- // Applies rounding and post-processing.
313
- const value = this._graph.hf.getCellValue(toSimpleCellAddress(this._sheetId, cell));
314
- if (value instanceof DetailedCellError) {
315
- return value.toString();
316
- }
317
-
318
- return value;
319
- }
320
-
321
- /**
322
- * Get value type.
323
- */
324
- getValueType(cell: CellAddress): ValueTypeEnum {
325
- const addr = toSimpleCellAddress(this._sheetId, cell);
326
- const type = this._graph.hf.getCellValueDetailedType(addr);
327
- return typeMap[type];
328
- }
329
-
330
- /**
331
- * Sets the value, updating the sheet and engine.
332
- */
333
- setValue(cell: CellAddress, value: CellScalarValue) {
334
- if (this._options.readonly) {
335
- throw new ReadonlyException();
336
- }
337
-
338
- // Reallocate if > current bounds.
339
- let refresh = false;
340
- if (cell.row >= this._sheet.rows.length) {
341
- this._insertIndices(this._sheet.rows, cell.row, 1, DEFAULT_ROWS);
342
- refresh = true;
343
- }
344
- if (cell.column >= this._sheet.columns.length) {
345
- this._insertIndices(this._sheet.columns, cell.column, 1, DEFAULT_COLUMNS);
346
- refresh = true;
347
- }
348
- if (refresh) {
349
- // TODO(burdon): Remove.
350
- this.reset();
351
- }
352
-
353
- // Insert into engine.
354
- this._graph.hf.setCellContents({ sheet: this._sheetId, row: cell.row, col: cell.column }, [
355
- [typeof value === 'string' && value.charAt(0) === '=' ? this.mapFormulaBindingToFormula(value) : value],
356
- ]);
357
-
358
- // Insert into sheet.
359
- const idx = this.addressToIndex(cell);
360
- if (value === undefined || value === null) {
361
- delete this._sheet.cells[idx];
362
- } else {
363
- if (typeof value === 'string' && value.charAt(0) === '=') {
364
- value = this.mapFormulaBindingToId(this.mapFormulaRefsToIndices(value));
365
- }
366
-
367
- this._sheet.cells[idx] = { value };
368
- }
369
- }
370
-
371
- /**
372
- * Sets values from a simple map.
373
- */
374
- setValues(values: Record<string, CellValue>) {
375
- Object.entries(values).forEach(([key, { value }]) => {
376
- this.setValue(addressFromA1Notation(key), value);
377
- });
378
- }
379
-
380
- /**
381
- * Iterate range.
382
- */
383
- private _iterRange(range: CellRange, cb: (cell: CellAddress) => CellScalarValue | void): CellScalarValue[][] {
384
- const to = range.to ?? range.from;
385
- const rowRange = [Math.min(range.from.row, to.row), Math.max(range.from.row, to.row)];
386
- const columnRange = [Math.min(range.from.column, to.column), Math.max(range.from.column, to.column)];
387
- const rows: CellScalarValue[][] = [];
388
- for (let row = rowRange[0]; row <= rowRange[1]; row++) {
389
- const rowCells: CellScalarValue[] = [];
390
- for (let column = columnRange[0]; column <= columnRange[1]; column++) {
391
- const value = cb({ row, column });
392
- if (value !== undefined) {
393
- rowCells.push(value);
394
- }
395
- }
396
- rows.push(rowCells);
397
- }
398
-
399
- return rows;
400
- }
401
-
402
- /**
403
- *
404
- */
405
- // TODO(burdon): Insert indices into sheet.
406
- private _insertIndices(indices: string[], i: number, n: number, max: number) {
407
- if (i + n > max) {
408
- throw new RangeException(i + n);
409
- }
410
-
411
- const idx = createIndices(n);
412
- indices.splice(i, 0, ...idx);
413
- }
414
-
415
- // TODO(burdon): Delete index.
416
- private _deleteIndices(indices: string[], i: number, n: number) {
417
- throw new Error('Not implemented');
418
- }
419
-
420
- // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
421
- private _moveIndices(indices: string[], i: number, j: number, n: number) {
422
- throw new Error('Not implemented');
423
- }
424
-
425
- //
426
- // Indices.
427
- //
428
-
429
- /**
430
- * E.g., "A1" => "x1@y1".
431
- */
432
- addressToIndex(cell: CellAddress): CellIndex {
433
- return `${this._sheet.columns[cell.column]}@${this._sheet.rows[cell.row]}`;
434
- }
435
-
436
- /**
437
- * E.g., "x1@y1" => "A1".
438
- */
439
- addressFromIndex(idx: CellIndex): CellAddress {
440
- const [column, row] = idx.split('@');
441
- return {
442
- column: this._sheet.columns.indexOf(column),
443
- row: this._sheet.rows.indexOf(row),
444
- };
445
- }
446
-
447
- /**
448
- * E.g., "A1:B2" => "x1@y1:x2@y2".
449
- */
450
- rangeToIndex(range: CellRange): string {
451
- return [range.from, range.to ?? range.from].map((cell) => this.addressToIndex(cell)).join(':');
452
- }
453
-
454
- /**
455
- * E.g., "x1@y1:x2@y2" => "A1:B2".
456
- */
457
- rangeFromIndex(idx: string): CellRange {
458
- const [from, to] = idx.split(':').map((idx) => this.addressFromIndex(idx));
459
- return { from, to };
460
- }
461
-
462
- /**
463
- * E.g., "HELLO()" => "EDGE("HELLO")".
464
- */
465
- mapFormulaBindingToFormula(formula: string): string {
466
- return formula.replace(/([a-zA-Z0-9]+)\((.*)\)/g, (match, binding, args) => {
467
- const fn = this._functions.find((fn) => fn.binding === binding);
468
- if (!fn) {
469
- return match;
470
- }
471
-
472
- if (args.trim() === '') {
473
- return `EDGE("${binding}")`;
474
- }
475
- return `EDGE("${binding}", ${args})`;
476
- });
477
- }
478
-
479
- /**
480
- * E.g., "EDGE("HELLO")" => "HELLO()".
481
- */
482
- mapFormulaBindingFromFormula(formula: string): string {
483
- return formula.replace(/EDGE\("([a-zA-Z0-9]+)"(.*)\)/, (_match, binding, args) => {
484
- if (args.trim() === '') {
485
- return `${binding}()`;
486
- }
487
- return `${binding}(${args.slice(2)})`;
488
- });
489
- }
490
-
491
- /**
492
- * Map from binding to fully qualified ECHO ID.
493
- */
494
- mapFormulaBindingToId(formula: string): string {
495
- return this._options.mapFormulaBindingToId(this._functions)(formula);
496
- }
497
-
498
- /**
499
- * Map from fully qualified ECHO ID to binding.
500
- */
501
- mapFormulaBindingFromId(formula: string): string {
502
- return this._options.mapFormulaBindingFromId(this._functions)(formula);
503
- }
504
-
505
- /**
506
- * Map from A1 notation to indices.
507
- */
508
- mapFormulaRefsToIndices(formula: string): string {
509
- invariant(formula.charAt(0) === '=');
510
- return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
511
- return this.addressToIndex(addressFromA1Notation(match));
512
- });
513
- }
514
-
515
- /**
516
- * Map from indices to A1 notation.
517
- */
518
- mapFormulaIndicesToRefs(formula: string): string {
519
- invariant(formula.charAt(0) === '=');
520
- return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
521
- return addressToA1Notation(this.addressFromIndex(idx));
522
- });
523
- }
524
-
525
- //
526
- // Values
527
- //
528
-
529
- /**
530
- * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
531
- * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
532
- * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
533
- */
534
- toLocalDate(num: number): Date {
535
- const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
536
- return new Date(year, month - 1, day, hours, minutes, seconds);
537
- }
538
-
539
- toDateTime(num: number): SimpleDateTime {
540
- return this._graph.hf.numberToDateTime(num) as SimpleDateTime;
541
- }
542
-
543
- toDate(num: number): SimpleDate {
544
- return this._graph.hf.numberToDate(num) as SimpleDate;
545
- }
546
-
547
- toTime(num: number): SimpleDate {
548
- return this._graph.hf.numberToTime(num) as SimpleDate;
549
- }
550
- }
@@ -1,71 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { invariant } from '@dxos/invariant';
6
-
7
- export const MAX_COLUMNS = 26 * 26;
8
-
9
- export type CellAddress = { column: number; row: number };
10
- export type CellRange = { from: CellAddress; to?: CellAddress };
11
-
12
- export const posEquals = (a: CellAddress | undefined, b: CellAddress | undefined) => {
13
- return a?.column === b?.column && a?.row === b?.row;
14
- };
15
-
16
- export const columnLetter = (column: number): string => {
17
- invariant(column < MAX_COLUMNS, `Invalid column: ${column}`);
18
- return (
19
- (column >= 26 ? String.fromCharCode('A'.charCodeAt(0) + Math.floor(column / 26) - 1) : '') +
20
- String.fromCharCode('A'.charCodeAt(0) + (column % 26))
21
- );
22
- };
23
-
24
- export const addressToA1Notation = ({ column, row }: CellAddress): string => {
25
- return `${columnLetter(column)}${row + 1}`;
26
- };
27
-
28
- export const addressFromA1Notation = (ref: string): CellAddress => {
29
- const match = ref.match(/([A-Z]+)(\d+)/);
30
- invariant(match, `Invalid notation: ${ref}`);
31
- return {
32
- row: parseInt(match[2], 10) - 1,
33
- column: match[1].split('').reduce((acc, c) => acc * 26 + c.charCodeAt(0) - 'A'.charCodeAt(0) + 1, 0) - 1,
34
- };
35
- };
36
-
37
- export const rangeToA1Notation = (range: CellRange) => {
38
- return [range?.from && addressToA1Notation(range?.from), range?.to && addressToA1Notation(range?.to)]
39
- .filter(Boolean)
40
- .join(':');
41
- };
42
-
43
- export const rangeFromA1Notation = (ref: string): CellRange => {
44
- const [from, to] = ref.split(':').map(addressFromA1Notation);
45
- return { from, to };
46
- };
47
-
48
- export const inRange = (range: CellRange | undefined, cell: CellAddress): boolean => {
49
- if (!range) {
50
- return false;
51
- }
52
-
53
- const { from, to } = range;
54
- if ((from && posEquals(from, cell)) || (to && posEquals(to, cell))) {
55
- return true;
56
- }
57
-
58
- if (!from || !to) {
59
- return false;
60
- }
61
-
62
- const { column: c1, row: r1 } = from;
63
- const { column: c2, row: r2 } = to;
64
- const cMin = Math.min(c1, c2);
65
- const cMax = Math.max(c1, c2);
66
- const rMin = Math.min(r1, r2);
67
- const rMax = Math.max(r1, r2);
68
-
69
- const { column, row } = cell;
70
- return column >= cMin && column <= cMax && row >= rMin && row <= rMax;
71
- };
package/src/model/util.ts DELETED
@@ -1,36 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { randomBytes } from '@dxos/crypto';
6
-
7
- // TODO(burdon): Factor out from dxos/protocols to new common package.
8
- export class ApiError extends Error {}
9
- export class ReadonlyException extends ApiError {}
10
- export class RangeException extends ApiError {
11
- constructor(n: number) {
12
- super();
13
- }
14
- }
15
-
16
- /**
17
- * With a string length of 8, the chance of a collision is 0.02% for a sheet with 10,000 strings.
18
- */
19
- export const createIndex = (length = 8): string => {
20
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
21
- const charactersLength = characters.length;
22
- const randomBuffer = randomBytes(length);
23
- return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join('');
24
- };
25
-
26
- export const createIndices = (length: number): string[] => Array.from({ length }).map(() => createIndex());
27
-
28
- // TODO(burdon): Factor out.
29
- export const pickOne = <T>(values: T[]): T => values[Math.floor(Math.random() * values.length)];
30
- export const pickSome = <T>(values: T[], n = 1): T[] => {
31
- const result = new Set<T>();
32
- while (result.size < n) {
33
- result.add(pickOne(values));
34
- }
35
- return Array.from(result.values());
36
- };
package/src/testing.ts DELETED
@@ -1,50 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type ComputeGraph, createComputeGraph } from './components';
6
- import { SheetModel } from './model';
7
- import { createSheet, type CellValue } from './types';
8
-
9
- export const testSheetName = 'test';
10
-
11
- export const createCells = (): Record<string, CellValue> => ({
12
- B1: { value: 'Qty' },
13
- B3: { value: 1 },
14
- B4: { value: 2 },
15
- B5: { value: 3 },
16
- B7: { value: 'Total' },
17
-
18
- C1: { value: 'Price' },
19
- C3: { value: 2_000 },
20
- C4: { value: 2_500 },
21
- C5: { value: 3_000 },
22
- C7: { value: '=SUMPRODUCT(B2:B6, C2:C6)' },
23
- // C8: { value: '=C7*CRYPTO(D7)' },
24
- C8: { value: '=C7*TEST()' },
25
-
26
- D7: { value: 'USD' },
27
- D8: { value: 'BTC' },
28
-
29
- E3: { value: '=TODAY()' },
30
- E4: { value: '=NOW()' },
31
-
32
- F1: { value: `=${testSheetName}!A1` }, // Ref test sheet.
33
- F3: { value: true },
34
- F4: { value: false },
35
- F5: { value: '8%' },
36
- F6: { value: '$10000' },
37
- });
38
-
39
- export const createTestSheet = async ({
40
- name,
41
- graph = createComputeGraph(),
42
- }: { name?: string; graph?: ComputeGraph } = {}) => {
43
- const sheet = createSheet(name);
44
- const model = new SheetModel(graph, sheet);
45
- await model.initialize();
46
- model.setValues(createCells());
47
- model.sheet.columnMeta[model.sheet.columns[0]] = { size: 100 };
48
- await model.destroy();
49
- return sheet;
50
- };
File without changes