@dxos/plugin-sheet 0.6.13-main.ed424a1 → 0.6.13

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 (323) hide show
  1. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +1772 -0
  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-5WPZCXNS.mjs → browser/chunk-D5AGLXJP.mjs} +678 -411
  6. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-FUAGSXA4.mjs +82 -0
  8. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-JRL5LGCE.mjs +18 -0
  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 +62 -93
  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 +12 -6
  20. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +1765 -0
  21. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-5XPK2V4A.cjs → chunk-5KKJ4NPP.cjs} +678 -418
  23. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +7 -0
  24. package/dist/lib/node/chunk-BJ6ZD7MN.cjs +51 -0
  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-NZARD7UP.cjs → chunk-DSYKOI4E.cjs} +51 -40
  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 +69 -105
  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 +15 -9
  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 +14 -0
  43. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -0
  44. package/dist/types/src/components/{GridSheet/SheetCellEditor.stories.d.ts → CellEditor/CellEditor.stories.d.ts} +4 -4
  45. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -0
  46. package/dist/types/src/{extensions/editor → components/CellEditor}/extension.d.ts +1 -1
  47. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -0
  48. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +1 -0
  49. package/dist/types/src/components/CellEditor/index.d.ts +3 -0
  50. package/dist/types/src/components/CellEditor/index.d.ts.map +1 -0
  51. package/dist/types/src/{graph/functions → components/ComputeGraph}/async-function.d.ts +5 -14
  52. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
  53. package/dist/types/src/components/ComputeGraph/custom.d.ts +21 -0
  54. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -0
  55. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +20 -0
  56. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -0
  57. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +12 -0
  58. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +1 -0
  59. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +2 -0
  60. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +1 -0
  61. package/dist/types/src/components/ComputeGraph/graph.d.ts +26 -0
  62. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +1 -0
  63. package/dist/types/src/components/ComputeGraph/index.d.ts +3 -1
  64. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  65. package/dist/types/src/components/Sheet/Sheet.d.ts +55 -0
  66. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
  67. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +54 -0
  68. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -0
  69. package/dist/types/src/components/Sheet/formatting.d.ts +14 -0
  70. package/dist/types/src/components/Sheet/formatting.d.ts.map +1 -0
  71. package/dist/types/src/components/Sheet/grid.d.ts +52 -0
  72. package/dist/types/src/components/Sheet/grid.d.ts.map +1 -0
  73. package/dist/types/src/components/Sheet/index.d.ts +2 -0
  74. package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
  75. package/dist/types/src/components/Sheet/nav.d.ts +29 -0
  76. package/dist/types/src/components/Sheet/nav.d.ts.map +1 -0
  77. package/dist/types/src/components/Sheet/sheet-context.d.ts +25 -0
  78. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -0
  79. package/dist/types/src/components/Sheet/util.d.ts +18 -0
  80. package/dist/types/src/components/Sheet/util.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContainer.d.ts +9 -0
  82. package/dist/types/src/components/SheetContainer.d.ts.map +1 -0
  83. package/dist/types/src/components/Toolbar/Toolbar.d.ts +9 -33
  84. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  85. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +15 -19
  86. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  87. package/dist/types/src/components/Toolbar/common.d.ts +20 -0
  88. package/dist/types/src/components/Toolbar/common.d.ts.map +1 -0
  89. package/dist/types/src/components/index.d.ts +2 -3
  90. package/dist/types/src/components/index.d.ts.map +1 -1
  91. package/dist/types/src/meta.d.ts +9 -3
  92. package/dist/types/src/meta.d.ts.map +1 -1
  93. package/dist/types/src/{graph/functions/function-defs.d.ts → model/functions.d.ts} +1 -1
  94. package/dist/types/src/model/functions.d.ts.map +1 -0
  95. package/dist/types/src/model/index.d.ts +3 -2
  96. package/dist/types/src/model/index.d.ts.map +1 -1
  97. package/dist/types/src/model/model.browser.test.d.ts +2 -0
  98. package/dist/types/src/model/model.browser.test.d.ts.map +1 -0
  99. package/dist/types/src/model/{sheet-model.d.ts → model.d.ts} +67 -13
  100. package/dist/types/src/model/model.d.ts.map +1 -0
  101. package/dist/types/src/{defs → model}/types.d.ts +3 -8
  102. package/dist/types/src/model/types.d.ts.map +1 -0
  103. package/dist/types/src/model/types.test.d.ts.map +1 -0
  104. package/dist/types/src/model/util.d.ts +15 -0
  105. package/dist/types/src/model/util.d.ts.map +1 -0
  106. package/dist/types/src/testing.d.ts +9 -0
  107. package/dist/types/src/testing.d.ts.map +1 -0
  108. package/dist/types/src/translations.d.ts +12 -17
  109. package/dist/types/src/translations.d.ts.map +1 -1
  110. package/dist/types/src/types.d.ts +40 -125
  111. package/dist/types/src/types.d.ts.map +1 -1
  112. package/package.json +52 -58
  113. package/src/SheetPlugin.tsx +74 -52
  114. package/src/components/{GridSheet/SheetCellEditor.stories.tsx → CellEditor/CellEditor.stories.tsx} +8 -8
  115. package/src/components/CellEditor/CellEditor.tsx +113 -0
  116. package/src/{extensions/editor → components/CellEditor}/extension.test.ts +6 -4
  117. package/src/{extensions/editor → components/CellEditor}/extension.ts +6 -5
  118. package/src/{extensions/editor → components/CellEditor}/index.ts +1 -0
  119. package/src/{graph/functions → components/ComputeGraph}/async-function.ts +15 -25
  120. package/src/{graph/testing/test-plugin.ts → components/ComputeGraph/custom.ts} +14 -44
  121. package/src/{graph/functions → components/ComputeGraph}/edge-function.ts +14 -16
  122. package/src/components/ComputeGraph/graph-context.tsx +50 -0
  123. package/src/components/ComputeGraph/graph.browser.test.ts +50 -0
  124. package/src/components/ComputeGraph/graph.ts +62 -0
  125. package/src/components/ComputeGraph/index.ts +3 -1
  126. package/src/components/Sheet/Sheet.stories.tsx +287 -0
  127. package/src/components/Sheet/Sheet.tsx +1160 -0
  128. package/src/components/Sheet/formatting.ts +106 -0
  129. package/src/components/Sheet/grid.ts +191 -0
  130. package/src/{testing → components/Sheet}/index.ts +1 -1
  131. package/src/components/Sheet/nav.ts +157 -0
  132. package/src/components/Sheet/sheet-context.tsx +150 -0
  133. package/src/components/Sheet/util.ts +56 -0
  134. package/src/components/SheetContainer.tsx +34 -0
  135. package/src/components/Toolbar/Toolbar.tsx +112 -242
  136. package/src/components/Toolbar/common.tsx +72 -0
  137. package/src/components/index.ts +0 -2
  138. package/src/meta.tsx +18 -0
  139. package/src/model/index.ts +3 -2
  140. package/src/model/model.browser.test.ts +100 -0
  141. package/src/model/model.ts +550 -0
  142. package/src/{defs → model}/types.test.ts +9 -8
  143. package/src/{defs → model}/types.ts +14 -24
  144. package/src/model/util.ts +36 -0
  145. package/src/testing.ts +50 -0
  146. package/src/translations.ts +1 -6
  147. package/src/types.ts +47 -40
  148. package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs +0 -290
  149. package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs.map +0 -7
  150. package/dist/lib/browser/chunk-BWN5DZWZ.mjs +0 -74
  151. package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +0 -7
  152. package/dist/lib/browser/chunk-D3QTX46O.mjs +0 -14
  153. package/dist/lib/browser/chunk-D3QTX46O.mjs.map +0 -7
  154. package/dist/lib/browser/chunk-GSV5QNLD.mjs +0 -2966
  155. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +0 -7
  156. package/dist/lib/browser/chunk-HOG37RYS.mjs +0 -1528
  157. package/dist/lib/browser/chunk-HOG37RYS.mjs.map +0 -7
  158. package/dist/lib/browser/graph-M4IQ76QX.mjs +0 -33
  159. package/dist/lib/browser/graph-M4IQ76QX.mjs.map +0 -7
  160. package/dist/lib/node/SheetContainer-J7XROAMN.cjs +0 -300
  161. package/dist/lib/node/SheetContainer-J7XROAMN.cjs.map +0 -7
  162. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +0 -7
  163. package/dist/lib/node/chunk-AXQZA2YS.cjs +0 -1527
  164. package/dist/lib/node/chunk-AXQZA2YS.cjs.map +0 -7
  165. package/dist/lib/node/chunk-NZARD7UP.cjs.map +0 -7
  166. package/dist/lib/node/chunk-QIFIGEKV.cjs +0 -37
  167. package/dist/lib/node/chunk-QIFIGEKV.cjs.map +0 -7
  168. package/dist/lib/node/graph-Q3N2X26H.cjs +0 -55
  169. package/dist/lib/node/graph-Q3N2X26H.cjs.map +0 -7
  170. package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs +0 -291
  171. package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs.map +0 -7
  172. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +0 -7
  173. package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs +0 -1529
  174. package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs.map +0 -7
  175. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +0 -16
  176. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +0 -7
  177. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs +0 -75
  178. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +0 -7
  179. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +0 -34
  180. package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +0 -7
  181. package/dist/lib/node-esm/index.mjs +0 -280
  182. package/dist/lib/node-esm/index.mjs.map +0 -7
  183. package/dist/lib/node-esm/meta.json +0 -1
  184. package/dist/lib/node-esm/meta.mjs +0 -10
  185. package/dist/lib/node-esm/meta.mjs.map +0 -7
  186. package/dist/lib/node-esm/types.mjs +0 -17
  187. package/dist/lib/node-esm/types.mjs.map +0 -7
  188. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +0 -11
  189. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +0 -1
  190. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +0 -3
  191. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +0 -1
  192. package/dist/types/src/components/FunctionEditor/index.d.ts +0 -2
  193. package/dist/types/src/components/FunctionEditor/index.d.ts.map +0 -1
  194. package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -3
  195. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
  196. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +0 -9
  197. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
  198. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +0 -1
  199. package/dist/types/src/components/GridSheet/index.d.ts +0 -2
  200. package/dist/types/src/components/GridSheet/index.d.ts.map +0 -1
  201. package/dist/types/src/components/GridSheet/util.d.ts +0 -16
  202. package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
  203. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +0 -6
  204. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +0 -1
  205. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +0 -11
  206. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +0 -1
  207. package/dist/types/src/components/SheetContainer/index.d.ts +0 -3
  208. package/dist/types/src/components/SheetContainer/index.d.ts.map +0 -1
  209. package/dist/types/src/components/SheetContext/SheetContext.d.ts +0 -26
  210. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +0 -1
  211. package/dist/types/src/components/SheetContext/index.d.ts +0 -2
  212. package/dist/types/src/components/SheetContext/index.d.ts.map +0 -1
  213. package/dist/types/src/defs/index.d.ts +0 -4
  214. package/dist/types/src/defs/index.d.ts.map +0 -1
  215. package/dist/types/src/defs/sheet-range-types.d.ts +0 -13
  216. package/dist/types/src/defs/sheet-range-types.d.ts.map +0 -1
  217. package/dist/types/src/defs/types.d.ts.map +0 -1
  218. package/dist/types/src/defs/types.test.d.ts.map +0 -1
  219. package/dist/types/src/defs/util.d.ts +0 -43
  220. package/dist/types/src/defs/util.d.ts.map +0 -1
  221. package/dist/types/src/extensions/compute.d.ts +0 -6
  222. package/dist/types/src/extensions/compute.d.ts.map +0 -1
  223. package/dist/types/src/extensions/compute.stories.d.ts +0 -26
  224. package/dist/types/src/extensions/compute.stories.d.ts.map +0 -1
  225. package/dist/types/src/extensions/editor/extension.d.ts.map +0 -1
  226. package/dist/types/src/extensions/editor/extension.test.d.ts.map +0 -1
  227. package/dist/types/src/extensions/editor/index.d.ts +0 -2
  228. package/dist/types/src/extensions/editor/index.d.ts.map +0 -1
  229. package/dist/types/src/extensions/index.d.ts +0 -3
  230. package/dist/types/src/extensions/index.d.ts.map +0 -1
  231. package/dist/types/src/graph/compute-graph-registry.d.ts +0 -34
  232. package/dist/types/src/graph/compute-graph-registry.d.ts.map +0 -1
  233. package/dist/types/src/graph/compute-graph.d.ts +0 -64
  234. package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
  235. package/dist/types/src/graph/compute-graph.stories.d.ts +0 -10
  236. package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
  237. package/dist/types/src/graph/compute-graph.test.d.ts +0 -2
  238. package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
  239. package/dist/types/src/graph/compute-node.d.ts +0 -26
  240. package/dist/types/src/graph/compute-node.d.ts.map +0 -1
  241. package/dist/types/src/graph/functions/async-function.d.ts.map +0 -1
  242. package/dist/types/src/graph/functions/edge-function.d.ts +0 -21
  243. package/dist/types/src/graph/functions/edge-function.d.ts.map +0 -1
  244. package/dist/types/src/graph/functions/function-defs.d.ts.map +0 -1
  245. package/dist/types/src/graph/functions/index.d.ts +0 -4
  246. package/dist/types/src/graph/functions/index.d.ts.map +0 -1
  247. package/dist/types/src/graph/hyperformula.test.d.ts +0 -2
  248. package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
  249. package/dist/types/src/graph/index.d.ts +0 -5
  250. package/dist/types/src/graph/index.d.ts.map +0 -1
  251. package/dist/types/src/graph/testing/index.d.ts +0 -3
  252. package/dist/types/src/graph/testing/index.d.ts.map +0 -1
  253. package/dist/types/src/graph/testing/test-builder.d.ts +0 -15
  254. package/dist/types/src/graph/testing/test-builder.d.ts.map +0 -1
  255. package/dist/types/src/graph/testing/test-plugin.d.ts +0 -36
  256. package/dist/types/src/graph/testing/test-plugin.d.ts.map +0 -1
  257. package/dist/types/src/graph/util.d.ts +0 -2
  258. package/dist/types/src/graph/util.d.ts.map +0 -1
  259. package/dist/types/src/hooks/hooks.stories.d.ts +0 -11
  260. package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
  261. package/dist/types/src/hooks/index.d.ts +0 -4
  262. package/dist/types/src/hooks/index.d.ts.map +0 -1
  263. package/dist/types/src/hooks/threads.d.ts +0 -8
  264. package/dist/types/src/hooks/threads.d.ts.map +0 -1
  265. package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
  266. package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
  267. package/dist/types/src/hooks/useSheetModel.d.ts +0 -8
  268. package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
  269. package/dist/types/src/model/decorations.d.ts +0 -25
  270. package/dist/types/src/model/decorations.d.ts.map +0 -1
  271. package/dist/types/src/model/sheet-model.d.ts.map +0 -1
  272. package/dist/types/src/model/sheet-model.test.d.ts +0 -2
  273. package/dist/types/src/model/sheet-model.test.d.ts.map +0 -1
  274. package/dist/types/src/sanity.test.d.ts +0 -2
  275. package/dist/types/src/sanity.test.d.ts.map +0 -1
  276. package/dist/types/src/testing/index.d.ts +0 -2
  277. package/dist/types/src/testing/index.d.ts.map +0 -1
  278. package/dist/types/src/testing/testing.d.ts +0 -8
  279. package/dist/types/src/testing/testing.d.ts.map +0 -1
  280. package/dist/vendor/hyperformula.mjs +0 -37145
  281. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +0 -20
  282. package/src/components/FunctionEditor/FunctionEditor.tsx +0 -45
  283. package/src/components/FunctionEditor/index.ts +0 -5
  284. package/src/components/GridSheet/GridSheet.stories.tsx +0 -41
  285. package/src/components/GridSheet/GridSheet.tsx +0 -163
  286. package/src/components/GridSheet/index.ts +0 -5
  287. package/src/components/GridSheet/util.ts +0 -158
  288. package/src/components/SheetContainer/SheetContainer.stories.tsx +0 -40
  289. package/src/components/SheetContainer/SheetContainer.tsx +0 -27
  290. package/src/components/SheetContainer/index.ts +0 -7
  291. package/src/components/SheetContext/SheetContext.tsx +0 -104
  292. package/src/components/SheetContext/index.ts +0 -5
  293. package/src/defs/index.ts +0 -7
  294. package/src/defs/sheet-range-types.ts +0 -46
  295. package/src/defs/util.ts +0 -151
  296. package/src/extensions/compute.stories.tsx +0 -151
  297. package/src/extensions/compute.ts +0 -147
  298. package/src/extensions/index.ts +0 -6
  299. package/src/graph/compute-graph-registry.ts +0 -90
  300. package/src/graph/compute-graph.stories.tsx +0 -93
  301. package/src/graph/compute-graph.test.ts +0 -87
  302. package/src/graph/compute-graph.ts +0 -242
  303. package/src/graph/compute-node.ts +0 -63
  304. package/src/graph/functions/index.ts +0 -7
  305. package/src/graph/hyperformula.test.ts +0 -14
  306. package/src/graph/index.ts +0 -8
  307. package/src/graph/testing/index.ts +0 -6
  308. package/src/graph/testing/test-builder.ts +0 -54
  309. package/src/graph/util.ts +0 -8
  310. package/src/hooks/hooks.stories.tsx +0 -50
  311. package/src/hooks/index.ts +0 -7
  312. package/src/hooks/threads.ts +0 -147
  313. package/src/hooks/useComputeGraph.ts +0 -28
  314. package/src/hooks/useSheetModel.ts +0 -40
  315. package/src/meta.ts +0 -14
  316. package/src/model/decorations.ts +0 -64
  317. package/src/model/sheet-model.test.ts +0 -57
  318. package/src/model/sheet-model.ts +0 -418
  319. package/src/sanity.test.ts +0 -40
  320. package/src/testing/testing.tsx +0 -68
  321. /package/dist/types/src/{extensions/editor → components/CellEditor}/extension.test.d.ts +0 -0
  322. /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
  323. /package/src/{graph/functions/function-defs.ts → model/functions.ts} +0 -0
@@ -1,1528 +0,0 @@
1
- import {
2
- SheetType
3
- } from "./chunk-BWN5DZWZ.mjs";
4
- import {
5
- SHEET_PLUGIN
6
- } from "./chunk-D3QTX46O.mjs";
7
- import {
8
- createSheetName
9
- } from "./chunk-GSV5QNLD.mjs";
10
-
11
- // packages/plugins/plugin-sheet/src/components/ComputeGraph/ComputeGraphContextProvider.tsx
12
- import React, { createContext } from "react";
13
- var ComputeGraphContext = /* @__PURE__ */ createContext(void 0);
14
- var ComputeGraphContextProvider = ({ registry, children }) => {
15
- return /* @__PURE__ */ React.createElement(ComputeGraphContext.Provider, {
16
- value: {
17
- registry
18
- }
19
- }, children);
20
- };
21
-
22
- // packages/plugins/plugin-sheet/src/defs/util.ts
23
- import { randomBytes } from "@dxos/crypto";
24
- import { create } from "@dxos/echo-schema";
25
-
26
- // packages/plugins/plugin-sheet/src/defs/types.ts
27
- import { invariant } from "@dxos/invariant";
28
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/defs/types.ts";
29
- var DEFAULT_ROWS = 50;
30
- var DEFAULT_COLUMNS = 26;
31
- var MAX_ROWS = 500;
32
- var MAX_COLUMNS = 26 * 2;
33
- var posEquals = (a, b) => {
34
- return a?.col === b?.col && a?.row === b?.row;
35
- };
36
- var columnLetter = (col) => {
37
- invariant(col < MAX_COLUMNS, `Invalid column: ${col}`, {
38
- F: __dxlog_file,
39
- L: 26,
40
- S: void 0,
41
- A: [
42
- "col < MAX_COLUMNS",
43
- "`Invalid column: ${col}`"
44
- ]
45
- });
46
- return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
47
- };
48
- var addressToA1Notation = ({ col, row }) => {
49
- return `${columnLetter(col)}${row + 1}`;
50
- };
51
- var addressFromA1Notation = (ref) => {
52
- const match = ref.match(/([A-Z]+)(\d+)/);
53
- invariant(match, `Invalid notation: ${ref}`, {
54
- F: __dxlog_file,
55
- L: 40,
56
- S: void 0,
57
- A: [
58
- "match",
59
- "`Invalid notation: ${ref}`"
60
- ]
61
- });
62
- return {
63
- row: parseInt(match[2], 10) - 1,
64
- col: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
65
- };
66
- };
67
- var rangeToA1Notation = (range) => {
68
- return [
69
- range?.from && addressToA1Notation(range?.from),
70
- range?.to && addressToA1Notation(range?.to)
71
- ].filter(Boolean).join(":");
72
- };
73
- var inRange = (range, cell) => {
74
- if (!range) {
75
- return false;
76
- }
77
- const { from, to } = range;
78
- if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
79
- return true;
80
- }
81
- if (!from || !to) {
82
- return false;
83
- }
84
- const { col: c1, row: r1 } = from;
85
- const { col: c2, row: r2 } = to;
86
- const cMin = Math.min(c1, c2);
87
- const cMax = Math.max(c1, c2);
88
- const rMin = Math.min(r1, r2);
89
- const rMax = Math.max(r1, r2);
90
- const { col, row } = cell;
91
- return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
92
- };
93
-
94
- // packages/plugins/plugin-sheet/src/defs/util.ts
95
- var ApiError = class extends Error {
96
- };
97
- var ReadonlyException = class extends ApiError {
98
- };
99
- var RangeException = class extends ApiError {
100
- constructor(n) {
101
- super();
102
- }
103
- };
104
- var createIndex = (length = 8) => {
105
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
106
- const charactersLength = characters.length;
107
- const randomBuffer = randomBytes(length);
108
- return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
109
- };
110
- var createIndices = (length) => Array.from({
111
- length
112
- }).map(() => createIndex());
113
- var insertIndices = (indices, i, n, max) => {
114
- if (i + n > max) {
115
- throw new RangeException(i + n);
116
- }
117
- const idx = createIndices(n);
118
- indices.splice(i, 0, ...idx);
119
- };
120
- var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}) => {
121
- if (!sheet.rows.length) {
122
- insertIndices(sheet.rows, 0, rows, MAX_ROWS);
123
- }
124
- if (!sheet.columns.length) {
125
- insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
126
- }
127
- };
128
- var createSheet = ({ name, cells, ...size } = {}) => {
129
- const sheet = create(SheetType, {
130
- name,
131
- cells: {},
132
- rows: [],
133
- columns: [],
134
- rowMeta: {},
135
- columnMeta: {},
136
- ranges: []
137
- });
138
- initialize(sheet, size);
139
- if (cells) {
140
- Object.entries(cells).forEach(([key, { value }]) => {
141
- const idx = addressToIndex(sheet, addressFromA1Notation(key));
142
- sheet.cells[idx] = {
143
- value
144
- };
145
- });
146
- }
147
- return sheet;
148
- };
149
- var addressToIndex = (sheet, cell) => {
150
- return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
151
- };
152
- var addressFromIndex = (sheet, idx) => {
153
- const [column, row] = idx.split("@");
154
- return {
155
- col: sheet.columns.indexOf(column),
156
- row: sheet.rows.indexOf(row)
157
- };
158
- };
159
- var closest = (cursor, cells) => {
160
- let closestCell2;
161
- let closestDistance = Number.MAX_SAFE_INTEGER;
162
- for (const cell of cells) {
163
- const distance = Math.abs(cell.row - cursor.row) + Math.abs(cell.col - cursor.col);
164
- if (distance < closestDistance) {
165
- closestCell2 = cell;
166
- closestDistance = distance;
167
- }
168
- }
169
- return closestCell2;
170
- };
171
- var compareIndexPositions = (sheet, indexA, indexB) => {
172
- const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
173
- const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
174
- if (rowA !== rowB) {
175
- return rowA - rowB;
176
- } else {
177
- return columnA - columnB;
178
- }
179
- };
180
-
181
- // packages/plugins/plugin-sheet/src/defs/sheet-range-types.ts
182
- var cellClassNameForRange = ({ key, value }) => {
183
- switch (key) {
184
- case "align":
185
- switch (value) {
186
- case "start":
187
- return "text-start";
188
- case "center":
189
- return "text-center";
190
- case "end":
191
- return "text-end";
192
- default:
193
- return void 0;
194
- }
195
- case "comment":
196
- return "bg-gridComment";
197
- case "style":
198
- switch (value) {
199
- case "highlight":
200
- return "bg-gridHighlight";
201
- default:
202
- return void 0;
203
- }
204
- default:
205
- return void 0;
206
- }
207
- };
208
-
209
- // packages/plugins/plugin-sheet/src/extensions/compute.ts
210
- import { syntaxTree } from "@codemirror/language";
211
- import { RangeSetBuilder, StateEffect, StateField } from "@codemirror/state";
212
- import { Decoration, EditorView, ViewPlugin, WidgetType } from "@codemirror/view";
213
- import { debounce } from "@dxos/async";
214
- import { invariant as invariant2 } from "@dxos/invariant";
215
- import { documentId, singleValueFacet } from "@dxos/react-ui-editor/state";
216
- var updateAllDecorations = StateEffect.define();
217
- var computeGraphFacet = singleValueFacet();
218
-
219
- // packages/plugins/plugin-sheet/src/extensions/editor/extension.ts
220
- import { acceptCompletion, autocompletion, completionStatus, startCompletion } from "@codemirror/autocomplete";
221
- import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
222
- import { ViewPlugin as ViewPlugin2, keymap } from "@codemirror/view";
223
- import { tags } from "@lezer/highlight";
224
- import { spreadsheet } from "codemirror-lang-spreadsheet";
225
- import { singleValueFacet as singleValueFacet2 } from "@dxos/react-ui-editor/state";
226
- import { mx } from "@dxos/react-ui-theme";
227
- var highlightStyles = HighlightStyle.define([
228
- // Function.
229
- {
230
- tag: tags.name,
231
- class: "text-accentText"
232
- },
233
- // Range.
234
- {
235
- tag: tags.tagName,
236
- class: "text-pinkText"
237
- },
238
- // Values.
239
- {
240
- tag: tags.number,
241
- class: "text-tealText"
242
- },
243
- {
244
- tag: tags.bool,
245
- class: "text-tealText"
246
- },
247
- {
248
- tag: tags.string,
249
- class: "text-tealText"
250
- },
251
- // Error.
252
- {
253
- tag: tags.invalid,
254
- class: "text-unAccent"
255
- }
256
- ]);
257
- var languageFacet = singleValueFacet2();
258
- var sheetExtension = ({ functions = [] }) => {
259
- const { extension, language } = spreadsheet({
260
- idiom: "en-US",
261
- decimalSeparator: "."
262
- });
263
- const createCompletion = (name) => {
264
- const { section = "Custom", description, syntax } = functions.find((value) => value.name === name) ?? {};
265
- return {
266
- section,
267
- label: name,
268
- info: () => {
269
- if (!description && !syntax) {
270
- return null;
271
- }
272
- const root = document.createElement("div");
273
- root.className = "flex flex-col gap-2 text-sm";
274
- const title = document.createElement("h2");
275
- title.innerText = name;
276
- title.className = "text-lg font-mono text-accentText";
277
- root.appendChild(title);
278
- if (description) {
279
- const info = document.createElement("p");
280
- info.innerText = description;
281
- info.className = "text-subdued";
282
- root.appendChild(info);
283
- }
284
- if (syntax) {
285
- const detail = document.createElement("pre");
286
- detail.innerText = syntax;
287
- detail.className = "whitespace-pre-wrap text-greenText";
288
- root.appendChild(detail);
289
- }
290
- return root;
291
- },
292
- apply: (view, completion, from, to) => {
293
- const insertParens = to === view.state.doc.toString().length;
294
- view.dispatch(view.state.update({
295
- changes: {
296
- from,
297
- to,
298
- insert: completion.label + (insertParens ? "()" : "")
299
- },
300
- selection: {
301
- anchor: from + completion.label.length + 1
302
- }
303
- }));
304
- }
305
- };
306
- };
307
- return [
308
- extension,
309
- languageFacet.of(language),
310
- language.data.of({
311
- autocomplete: (context) => {
312
- if (context.state.doc.toString()[0] !== "=") {
313
- return null;
314
- }
315
- const match = context.matchBefore(/\w*/);
316
- if (!match || match.from === match.to) {
317
- return null;
318
- }
319
- const text = match.text.toUpperCase();
320
- if (!context.explicit && match.text.length < 2) {
321
- return null;
322
- }
323
- return {
324
- from: match.from,
325
- options: functions?.filter(({ name }) => name.startsWith(text)).map(({ name }) => createCompletion(name)) ?? []
326
- };
327
- }
328
- }),
329
- syntaxHighlighting(highlightStyles),
330
- autocompletion({
331
- aboveCursor: false,
332
- defaultKeymap: true,
333
- activateOnTyping: true,
334
- // NOTE: Useful for debugging.
335
- closeOnBlur: false,
336
- icons: false,
337
- tooltipClass: () => mx("!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]", "[&>ul>li[aria-selected]]:!bg-accentSurface", "border-separator")
338
- }),
339
- keymap.of([
340
- {
341
- key: "Tab",
342
- run: (view) => {
343
- return completionStatus(view.state) === "active" ? acceptCompletion(view) : startCompletion(view);
344
- }
345
- }
346
- ])
347
- ];
348
- };
349
- var rangeExtension = (onInit) => {
350
- let view;
351
- let activeRange;
352
- const provider = (range) => {
353
- if (activeRange) {
354
- view.dispatch(view.state.update({
355
- changes: {
356
- ...activeRange,
357
- insert: range.toString()
358
- },
359
- selection: {
360
- anchor: activeRange.from + range.length
361
- }
362
- }));
363
- }
364
- view.focus();
365
- };
366
- return ViewPlugin2.fromClass(class {
367
- constructor(_view) {
368
- view = _view;
369
- onInit(provider);
370
- }
371
- update(view2) {
372
- const { anchor } = view2.state.selection.ranges[0];
373
- activeRange = void 0;
374
- const language = view2.state.facet(languageFacet);
375
- const { topNode } = language.parser.parse(view2.state.doc.toString());
376
- visitTree(topNode, ({ type, from, to }) => {
377
- if (from <= anchor && to >= anchor) {
378
- switch (type.name) {
379
- case "Function": {
380
- activeRange = {
381
- from: to,
382
- to
383
- };
384
- break;
385
- }
386
- case "CloseParen": {
387
- activeRange = {
388
- from,
389
- to: from
390
- };
391
- break;
392
- }
393
- case "RangeToken":
394
- case "CellToken":
395
- activeRange = {
396
- from,
397
- to
398
- };
399
- return true;
400
- }
401
- }
402
- return false;
403
- });
404
- if (!activeRange && view2.state.doc.toString()[0] === "=") {
405
- activeRange = {
406
- from: 1,
407
- to: view2.state.doc.toString().length
408
- };
409
- }
410
- }
411
- });
412
- };
413
- var visitTree = (node, callback) => {
414
- if (callback(node)) {
415
- return true;
416
- }
417
- for (let child = node.firstChild; child !== null; child = child.nextSibling) {
418
- if (visitTree(child, callback)) {
419
- return true;
420
- }
421
- }
422
- return false;
423
- };
424
-
425
- // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
426
- import { useContext as useContext2 } from "react";
427
- import { raise } from "@dxos/debug";
428
- import { useAsyncState } from "@dxos/react-hooks";
429
-
430
- // packages/plugins/plugin-sheet/src/components/index.ts
431
- import React4 from "react";
432
-
433
- // packages/plugins/plugin-sheet/src/components/GridSheet/GridSheet.tsx
434
- import React3, { useCallback as useCallback2, useMemo as useMemo3, useRef } from "react";
435
- import { useAttention } from "@dxos/react-ui-attention";
436
- import { Grid as Grid2, editorKeys, GridCellEditor, closestCell } from "@dxos/react-ui-grid";
437
-
438
- // packages/plugins/plugin-sheet/src/components/GridSheet/util.ts
439
- import { useEffect, useLayoutEffect, useState } from "react";
440
- import { createDocAccessor } from "@dxos/react-client/echo";
441
- import { parseValue, cellClassesForFieldType } from "@dxos/react-ui-data";
442
- import { colToA1Notation, rowToA1Notation } from "@dxos/react-ui-grid";
443
- import { mx as mx2 } from "@dxos/react-ui-theme";
444
- var dxGridCellIndexToSheetCellAddress = (index) => {
445
- const [colStr, rowStr] = index.split(",");
446
- return {
447
- col: parseInt(colStr),
448
- row: parseInt(rowStr)
449
- };
450
- };
451
- var createDxGridColumns = (model) => {
452
- return model.sheet.columns.reduce((acc, columnId, numericIndex) => {
453
- if (model.sheet.columnMeta[columnId] && model.sheet.columnMeta[columnId].size) {
454
- acc.grid[numericIndex] = {
455
- size: model.sheet.columnMeta[columnId].size,
456
- resizeable: true
457
- };
458
- }
459
- return acc;
460
- }, {
461
- grid: {}
462
- });
463
- };
464
- var createDxGridRows = (model) => {
465
- return model.sheet.rows.reduce((acc, rowId, numericIndex) => {
466
- if (model.sheet.rowMeta[rowId] && model.sheet.rowMeta[rowId].size) {
467
- acc.grid[numericIndex] = {
468
- size: model.sheet.rowMeta[rowId].size,
469
- resizeable: true
470
- };
471
- }
472
- return acc;
473
- }, {
474
- grid: {}
475
- });
476
- };
477
- var projectCellProps = (model, col, row) => {
478
- const address = {
479
- col,
480
- row
481
- };
482
- const rawValue = model.getValue(address);
483
- if (rawValue === void 0 || rawValue === null) {
484
- return {
485
- value: ""
486
- };
487
- }
488
- const ranges = model.sheet.ranges?.filter(({ range }) => inRange(range, address));
489
- const type = model.getValueType(address);
490
- const classNames = ranges?.map(cellClassNameForRange).reverse();
491
- return {
492
- value: parseValue(type, rawValue),
493
- className: mx2(cellClassesForFieldType(type), classNames)
494
- };
495
- };
496
- var gridCellGetter = (model) => {
497
- const cachedGridCells = {};
498
- return (nextBounds) => {
499
- [
500
- ...Array(nextBounds.end.col - nextBounds.start.col)
501
- ].forEach((_, c0) => {
502
- return [
503
- ...Array(nextBounds.end.row - nextBounds.start.row)
504
- ].forEach((_2, r0) => {
505
- const col = nextBounds.start.col + c0;
506
- const row = nextBounds.start.row + r0;
507
- const cell = projectCellProps(model, col, row);
508
- if (cell.value) {
509
- cachedGridCells;
510
- cachedGridCells[`${col},${row}`] = cell;
511
- }
512
- });
513
- });
514
- return cachedGridCells;
515
- };
516
- };
517
- var rowLabelCell = (row) => ({
518
- value: rowToA1Notation(row),
519
- className: "text-end !pie-1",
520
- resizeHandle: "row"
521
- });
522
- var colLabelCell = (col) => ({
523
- value: colToA1Notation(col),
524
- resizeHandle: "col"
525
- });
526
- var cellGetter = (model) => {
527
- const getGridCells = gridCellGetter(model);
528
- return (nextBounds, plane) => {
529
- switch (plane) {
530
- case "grid":
531
- return getGridCells(nextBounds);
532
- case "frozenColsStart":
533
- return [
534
- ...Array(nextBounds.end.row - nextBounds.start.row)
535
- ].reduce((acc, _, r0) => {
536
- const r = nextBounds.start.row + r0;
537
- acc[`0,${r}`] = rowLabelCell(r);
538
- return acc;
539
- }, {});
540
- case "frozenRowsStart":
541
- return [
542
- ...Array(nextBounds.end.col - nextBounds.start.col)
543
- ].reduce((acc, _, c0) => {
544
- const c = nextBounds.start.col + c0;
545
- acc[`${c},0`] = colLabelCell(c);
546
- return acc;
547
- }, {});
548
- default:
549
- return {};
550
- }
551
- };
552
- };
553
- var useSheetModelDxGridProps = (dxGridRef, model) => {
554
- const [columns, setColumns] = useState(createDxGridColumns(model));
555
- const [rows, setRows] = useState(createDxGridColumns(model));
556
- useLayoutEffect(() => {
557
- const cellsAccessor = createDocAccessor(model.sheet, [
558
- "cells"
559
- ]);
560
- if (dxGridRef.current) {
561
- dxGridRef.current.getCells = cellGetter(model);
562
- }
563
- const handleCellsUpdate = () => {
564
- dxGridRef.current?.requestUpdate("initialCells");
565
- };
566
- cellsAccessor.handle.addListener("change", handleCellsUpdate);
567
- return () => cellsAccessor.handle.removeListener("change", handleCellsUpdate);
568
- }, [
569
- model
570
- ]);
571
- useEffect(() => {
572
- const columnMetaAccessor = createDocAccessor(model.sheet, [
573
- "columnMeta"
574
- ]);
575
- const rowMetaAccessor = createDocAccessor(model.sheet, [
576
- "rowMeta"
577
- ]);
578
- const handleColumnMetaUpdate = () => {
579
- setColumns(createDxGridColumns(model));
580
- };
581
- const handleRowMetaUpdate = () => {
582
- setRows(createDxGridRows(model));
583
- };
584
- columnMetaAccessor.handle.addListener("change", handleColumnMetaUpdate);
585
- rowMetaAccessor.handle.addListener("change", handleRowMetaUpdate);
586
- return () => {
587
- columnMetaAccessor.handle.removeListener("change", handleColumnMetaUpdate);
588
- rowMetaAccessor.handle.removeListener("change", handleRowMetaUpdate);
589
- };
590
- }, [
591
- model
592
- ]);
593
- return {
594
- columns,
595
- rows
596
- };
597
- };
598
-
599
- // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
600
- import { useEffect as useEffect2, useState as useState2 } from "react";
601
-
602
- // packages/plugins/plugin-sheet/src/model/decorations.ts
603
- import { create as create2 } from "@dxos/echo-schema";
604
- var createDecorations = () => {
605
- const { decorations } = create2({
606
- decorations: {}
607
- });
608
- const addDecoration = (cellIndex, decorator) => {
609
- decorations[cellIndex] = [
610
- ...decorations[cellIndex] || [],
611
- decorator
612
- ];
613
- };
614
- const removeDecoration = (cellIndex, type) => {
615
- if (type) {
616
- decorations[cellIndex] = (decorations[cellIndex] || []).filter((d) => d.type !== type);
617
- } else {
618
- delete decorations[cellIndex];
619
- }
620
- };
621
- const getDecorationsForCell = (cellIndex) => {
622
- return decorations[cellIndex];
623
- };
624
- const getAllDecorations = () => {
625
- const result = [];
626
- for (const decoratorArray of Object.values(decorations)) {
627
- for (const decorator of decoratorArray) {
628
- result.push(decorator);
629
- }
630
- }
631
- return result;
632
- };
633
- return {
634
- addDecoration,
635
- removeDecoration,
636
- getDecorationsForCell,
637
- getAllDecorations
638
- };
639
- };
640
-
641
- // packages/plugins/plugin-sheet/src/model/sheet-model.ts
642
- import { Event } from "@dxos/async";
643
- import { Resource } from "@dxos/context";
644
- import { getTypename } from "@dxos/echo-schema";
645
- import { invariant as invariant3 } from "@dxos/invariant";
646
- import { PublicKey } from "@dxos/keys";
647
- import { log } from "@dxos/log";
648
- import { FieldValueType } from "@dxos/schema";
649
- import { DetailedCellError, ExportedCellChange } from "#hyperformula";
650
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
651
- var typeMap = {
652
- BOOLEAN: FieldValueType.Boolean,
653
- NUMBER_RAW: FieldValueType.Number,
654
- NUMBER_PERCENT: FieldValueType.Percent,
655
- NUMBER_CURRENCY: FieldValueType.Currency,
656
- NUMBER_DATETIME: FieldValueType.DateTime,
657
- NUMBER_DATE: FieldValueType.Date,
658
- NUMBER_TIME: FieldValueType.Time
659
- };
660
- var getTopLeft = (range) => {
661
- const to = range.to ?? range.from;
662
- return {
663
- row: Math.min(range.from.row, to.row),
664
- col: Math.min(range.from.col, to.col)
665
- };
666
- };
667
- var toSimpleCellAddress = (sheet, cell) => ({
668
- sheet,
669
- row: cell.row,
670
- col: cell.col
671
- });
672
- var toModelRange = (sheet, range) => ({
673
- start: toSimpleCellAddress(sheet, range.from),
674
- end: toSimpleCellAddress(sheet, range.to ?? range.from)
675
- });
676
- var SheetModel = class extends Resource {
677
- constructor(_graph, _sheet, _options = {}) {
678
- super();
679
- this._graph = _graph;
680
- this._sheet = _sheet;
681
- this._options = _options;
682
- this.id = `model-${PublicKey.random().truncate()}`;
683
- this.update = new Event();
684
- }
685
- get graph() {
686
- return this._graph;
687
- }
688
- get sheet() {
689
- return this._sheet;
690
- }
691
- get readonly() {
692
- return this._options.readonly;
693
- }
694
- get bounds() {
695
- return {
696
- rows: this._sheet.rows.length,
697
- columns: this._sheet.columns.length
698
- };
699
- }
700
- /**
701
- * Initialize sheet and engine.
702
- */
703
- async _open() {
704
- log("initialize", {
705
- id: this.id
706
- }, {
707
- F: __dxlog_file2,
708
- L: 106,
709
- S: this,
710
- C: (f, a) => f(...a)
711
- });
712
- initialize(this._sheet);
713
- this._node = this._graph.getOrCreateNode(createSheetName({
714
- type: getTypename(this._sheet),
715
- id: this._sheet.id
716
- }));
717
- await this._node.open();
718
- const unsubscribe = this._node.update.on((event) => this.update.emit(event));
719
- this._ctx.onDispose(unsubscribe);
720
- this.reset();
721
- }
722
- /**
723
- * Update engine.
724
- * NOTE: This resets the undo history.
725
- * @deprecated
726
- */
727
- reset() {
728
- invariant3(this._node, void 0, {
729
- F: __dxlog_file2,
730
- L: 126,
731
- S: this,
732
- A: [
733
- "this._node",
734
- ""
735
- ]
736
- });
737
- this._node.graph.hf.clearSheet(this._node.sheetId);
738
- Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
739
- invariant3(this._node, void 0, {
740
- F: __dxlog_file2,
741
- L: 129,
742
- S: this,
743
- A: [
744
- "this._node",
745
- ""
746
- ]
747
- });
748
- const { col, row } = addressFromIndex(this._sheet, key);
749
- if (typeof value === "string" && value.charAt(0) === "=") {
750
- value = this._graph.mapFormulaToNative(this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)));
751
- }
752
- this._node.graph.hf.setCellContents({
753
- sheet: this._node.sheetId,
754
- row,
755
- col
756
- }, value);
757
- });
758
- }
759
- /**
760
- * Recalculate formulas.
761
- * NOTE: This resets the undo history.
762
- * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
763
- * @deprecated
764
- */
765
- // TODO(burdon): Remove.
766
- recalculate() {
767
- this._node?.graph.hf.rebuildAndRecalculate();
768
- }
769
- insertRows(i, n = 1) {
770
- insertIndices(this._sheet.rows, i, n, MAX_ROWS);
771
- this.reset();
772
- }
773
- insertColumns(i, n = 1) {
774
- insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
775
- this.reset();
776
- }
777
- //
778
- // Undoable actions.
779
- // TODO(burdon): Group undoable methods; consistently update hf/sheet.
780
- //
781
- /**
782
- * Clear range of values.
783
- */
784
- clear(range) {
785
- invariant3(this._node, void 0, {
786
- F: __dxlog_file2,
787
- L: 171,
788
- S: this,
789
- A: [
790
- "this._node",
791
- ""
792
- ]
793
- });
794
- const topLeft = getTopLeft(range);
795
- const values = this._iterRange(range, () => null);
796
- this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
797
- this._iterRange(range, (cell) => {
798
- const idx = addressToIndex(this._sheet, cell);
799
- delete this._sheet.cells[idx];
800
- });
801
- }
802
- cut(range) {
803
- invariant3(this._node, void 0, {
804
- F: __dxlog_file2,
805
- L: 182,
806
- S: this,
807
- A: [
808
- "this._node",
809
- ""
810
- ]
811
- });
812
- this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
813
- this._iterRange(range, (cell) => {
814
- const idx = addressToIndex(this._sheet, cell);
815
- delete this._sheet.cells[idx];
816
- });
817
- }
818
- copy(range) {
819
- invariant3(this._node, void 0, {
820
- F: __dxlog_file2,
821
- L: 191,
822
- S: this,
823
- A: [
824
- "this._node",
825
- ""
826
- ]
827
- });
828
- this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
829
- }
830
- paste(cell) {
831
- invariant3(this._node, void 0, {
832
- F: __dxlog_file2,
833
- L: 196,
834
- S: this,
835
- A: [
836
- "this._node",
837
- ""
838
- ]
839
- });
840
- if (!this._node.graph.hf.isClipboardEmpty()) {
841
- const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
842
- for (const change of changes) {
843
- if (change instanceof ExportedCellChange) {
844
- const { address, newValue } = change;
845
- const idx = addressToIndex(this._sheet, {
846
- row: address.row,
847
- col: address.col
848
- });
849
- this._sheet.cells[idx] = {
850
- value: newValue
851
- };
852
- }
853
- }
854
- }
855
- }
856
- // TODO(burdon): Display undo/redo state.
857
- undo() {
858
- invariant3(this._node, void 0, {
859
- F: __dxlog_file2,
860
- L: 211,
861
- S: this,
862
- A: [
863
- "this._node",
864
- ""
865
- ]
866
- });
867
- if (this._node.graph.hf.isThereSomethingToUndo()) {
868
- this._node.graph.hf.undo();
869
- }
870
- }
871
- redo() {
872
- invariant3(this._node, void 0, {
873
- F: __dxlog_file2,
874
- L: 219,
875
- S: this,
876
- A: [
877
- "this._node",
878
- ""
879
- ]
880
- });
881
- if (this._node.graph.hf.isThereSomethingToRedo()) {
882
- this._node.graph.hf.redo();
883
- }
884
- }
885
- /**
886
- * Get value from sheet.
887
- */
888
- getCellValue(cell) {
889
- const idx = addressToIndex(this._sheet, cell);
890
- return this._sheet.cells[idx]?.value ?? null;
891
- }
892
- /**
893
- * Get value as a string for editing.
894
- */
895
- getCellText(cell) {
896
- const value = this.getCellValue(cell);
897
- if (value == null) {
898
- return void 0;
899
- }
900
- if (typeof value === "string" && value.charAt(0) === "=") {
901
- return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
902
- } else {
903
- return String(value);
904
- }
905
- }
906
- /**
907
- * Get array of raw values from sheet.
908
- */
909
- getCellValues(range) {
910
- return this._iterRange(range, (cell) => this.getCellValue(cell));
911
- }
912
- /**
913
- * Gets the regular or computed value from the engine.
914
- */
915
- getValue(cell) {
916
- invariant3(this._node, void 0, {
917
- F: __dxlog_file2,
918
- L: 262,
919
- S: this,
920
- A: [
921
- "this._node",
922
- ""
923
- ]
924
- });
925
- const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
926
- if (value instanceof DetailedCellError) {
927
- return value.toString();
928
- }
929
- return value;
930
- }
931
- /**
932
- * Get value type.
933
- */
934
- getValueType(cell) {
935
- invariant3(this._node, void 0, {
936
- F: __dxlog_file2,
937
- L: 275,
938
- S: this,
939
- A: [
940
- "this._node",
941
- ""
942
- ]
943
- });
944
- const addr = toSimpleCellAddress(this._node.sheetId, cell);
945
- const type = this._node.graph.hf.getCellValueDetailedType(addr);
946
- return typeMap[type];
947
- }
948
- /**
949
- * Sets the value, updating the sheet and engine.
950
- */
951
- setValue(cell, value) {
952
- invariant3(this._node, void 0, {
953
- F: __dxlog_file2,
954
- L: 285,
955
- S: this,
956
- A: [
957
- "this._node",
958
- ""
959
- ]
960
- });
961
- if (this._options.readonly) {
962
- throw new ReadonlyException();
963
- }
964
- let refresh = false;
965
- if (cell.row >= this._sheet.rows.length) {
966
- insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
967
- refresh = true;
968
- }
969
- if (cell.col >= this._sheet.columns.length) {
970
- insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
971
- refresh = true;
972
- }
973
- if (refresh) {
974
- this.reset();
975
- }
976
- this._node.graph.hf.setCellContents({
977
- sheet: this._node.sheetId,
978
- row: cell.row,
979
- col: cell.col
980
- }, [
981
- [
982
- typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value
983
- ]
984
- ]);
985
- const idx = addressToIndex(this._sheet, cell);
986
- if (value === void 0 || value === null) {
987
- delete this._sheet.cells[idx];
988
- } else {
989
- if (typeof value === "string" && value.charAt(0) === "=") {
990
- value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
991
- }
992
- this._sheet.cells[idx] = {
993
- value
994
- };
995
- }
996
- }
997
- /**
998
- * Sets values from a simple map.
999
- */
1000
- setValues(values) {
1001
- Object.entries(values).forEach(([key, { value }]) => {
1002
- this.setValue(addressFromA1Notation(key), value);
1003
- });
1004
- }
1005
- /**
1006
- * Iterate range.
1007
- */
1008
- _iterRange(range, cb) {
1009
- const to = range.to ?? range.from;
1010
- const rowRange = [
1011
- Math.min(range.from.row, to.row),
1012
- Math.max(range.from.row, to.row)
1013
- ];
1014
- const columnRange = [
1015
- Math.min(range.from.col, to.col),
1016
- Math.max(range.from.col, to.col)
1017
- ];
1018
- const rows = [];
1019
- for (let row = rowRange[0]; row <= rowRange[1]; row++) {
1020
- const rowCells = [];
1021
- for (let column = columnRange[0]; column <= columnRange[1]; column++) {
1022
- const value = cb({
1023
- row,
1024
- col: column
1025
- });
1026
- if (value !== void 0) {
1027
- rowCells.push(value);
1028
- }
1029
- }
1030
- rows.push(rowCells);
1031
- }
1032
- return rows;
1033
- }
1034
- // TODO(burdon): Delete index.
1035
- _deleteIndices(indices, i, n) {
1036
- throw new Error("Not implemented");
1037
- }
1038
- // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
1039
- _moveIndices(indices, i, j, n) {
1040
- throw new Error("Not implemented");
1041
- }
1042
- //
1043
- // Indices.
1044
- //
1045
- /**
1046
- * Map from A1 notation to indices.
1047
- */
1048
- mapFormulaRefsToIndices(formula) {
1049
- invariant3(formula.charAt(0) === "=", void 0, {
1050
- F: __dxlog_file2,
1051
- L: 374,
1052
- S: this,
1053
- A: [
1054
- "formula.charAt(0) === '='",
1055
- ""
1056
- ]
1057
- });
1058
- return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
1059
- return addressToIndex(this._sheet, addressFromA1Notation(match));
1060
- });
1061
- }
1062
- /**
1063
- * Map from indices to A1 notation.
1064
- */
1065
- mapFormulaIndicesToRefs(formula) {
1066
- invariant3(formula.charAt(0) === "=", void 0, {
1067
- F: __dxlog_file2,
1068
- L: 384,
1069
- S: this,
1070
- A: [
1071
- "formula.charAt(0) === '='",
1072
- ""
1073
- ]
1074
- });
1075
- return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
1076
- return addressToA1Notation(addressFromIndex(this._sheet, idx));
1077
- });
1078
- }
1079
- //
1080
- // Values
1081
- //
1082
- /**
1083
- * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
1084
- * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
1085
- * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
1086
- */
1087
- toLocalDate(num) {
1088
- const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
1089
- return new Date(year, month - 1, day, hours, minutes, seconds);
1090
- }
1091
- toDateTime(num) {
1092
- invariant3(this._node, void 0, {
1093
- F: __dxlog_file2,
1094
- L: 405,
1095
- S: this,
1096
- A: [
1097
- "this._node",
1098
- ""
1099
- ]
1100
- });
1101
- return this._node.graph.hf.numberToDateTime(num);
1102
- }
1103
- toDate(num) {
1104
- invariant3(this._node, void 0, {
1105
- F: __dxlog_file2,
1106
- L: 410,
1107
- S: this,
1108
- A: [
1109
- "this._node",
1110
- ""
1111
- ]
1112
- });
1113
- return this._node.graph.hf.numberToDate(num);
1114
- }
1115
- toTime(num) {
1116
- invariant3(this._node, void 0, {
1117
- F: __dxlog_file2,
1118
- L: 415,
1119
- S: this,
1120
- A: [
1121
- "this._node",
1122
- ""
1123
- ]
1124
- });
1125
- return this._node.graph.hf.numberToTime(num);
1126
- }
1127
- };
1128
-
1129
- // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
1130
- var useSheetModel = (graph, sheet, { readonly } = {}) => {
1131
- const [model, setModel] = useState2();
1132
- useEffect2(() => {
1133
- if (!graph || !sheet) {
1134
- return;
1135
- }
1136
- let model2;
1137
- const t = setTimeout(async () => {
1138
- model2 = new SheetModel(graph, sheet, {
1139
- readonly
1140
- });
1141
- await model2.open();
1142
- setModel(model2);
1143
- });
1144
- return () => {
1145
- clearTimeout(t);
1146
- void model2?.close();
1147
- };
1148
- }, [
1149
- graph,
1150
- sheet,
1151
- readonly
1152
- ]);
1153
- return model;
1154
- };
1155
-
1156
- // packages/plugins/plugin-sheet/src/hooks/threads.ts
1157
- import { effect } from "@preact/signals-core";
1158
- import { useCallback, useEffect as useEffect3, useMemo } from "react";
1159
- import { LayoutAction, useIntentDispatcher, useIntentResolver } from "@dxos/app-framework";
1160
- import { debounce as debounce2 } from "@dxos/async";
1161
- import { fullyQualifiedId } from "@dxos/react-client/echo";
1162
- var useUpdateFocusedCellOnThreadSelection = (model, grid) => {
1163
- const handleScrollIntoView = useCallback(({ action, data }) => {
1164
- switch (action) {
1165
- case LayoutAction.SCROLL_INTO_VIEW: {
1166
- if (!data?.id || data?.cursor === void 0 || data?.id !== fullyQualifiedId(model.sheet)) {
1167
- return;
1168
- }
1169
- const cellAddress = addressFromIndex(model.sheet, data.cursor);
1170
- grid.current?.setFocus({
1171
- ...cellAddress,
1172
- plane: "grid"
1173
- }, true);
1174
- }
1175
- }
1176
- }, [
1177
- model.sheet
1178
- ]);
1179
- useIntentResolver(SHEET_PLUGIN, handleScrollIntoView);
1180
- };
1181
- var useSelectThreadOnCellFocus = (model, cursor) => {
1182
- const dispatch = useIntentDispatcher();
1183
- const activeThreads = useMemo(() => model.sheet.threads?.filter((thread) => !!thread && thread.status === "active") ?? [], [
1184
- // TODO(thure): Surely we can find a better dependency for this…
1185
- JSON.stringify(model.sheet.threads)
1186
- ]);
1187
- const activeThreadAddresses = useMemo(() => activeThreads.map((thread) => thread.anchor).filter((anchor) => anchor !== void 0).map((anchor) => addressFromIndex(model.sheet, anchor)), [
1188
- activeThreads,
1189
- model.sheet
1190
- ]);
1191
- const selectClosestThread = useCallback((cellAddress) => {
1192
- if (!cellAddress || !activeThreads) {
1193
- return;
1194
- }
1195
- const closestThreadAnchor = closest(cellAddress, activeThreadAddresses);
1196
- if (closestThreadAnchor) {
1197
- const closestThread = activeThreads.find((thread) => thread && thread.anchor === addressToIndex(model.sheet, closestThreadAnchor));
1198
- if (closestThread) {
1199
- void dispatch([
1200
- {
1201
- action: "dxos.org/plugin/thread/action/select",
1202
- data: {
1203
- current: fullyQualifiedId(closestThread)
1204
- }
1205
- }
1206
- ]);
1207
- }
1208
- }
1209
- }, [
1210
- dispatch,
1211
- activeThreads,
1212
- activeThreadAddresses,
1213
- model.sheet
1214
- ]);
1215
- const debounced = useMemo(() => {
1216
- return debounce2((cellCoords) => requestAnimationFrame(() => selectClosestThread(cellCoords)), 50);
1217
- }, [
1218
- selectClosestThread
1219
- ]);
1220
- useEffect3(() => {
1221
- if (!cursor) {
1222
- return;
1223
- }
1224
- debounced(cursor);
1225
- }, [
1226
- cursor,
1227
- selectClosestThread
1228
- ]);
1229
- };
1230
- var createThreadDecoration = (cellIndex, threadId, sheetId) => {
1231
- return {
1232
- type: "comment",
1233
- classNames: [
1234
- "bg-greenFill"
1235
- ],
1236
- cellIndex
1237
- };
1238
- };
1239
- var useThreadDecorations = (model, decorations) => {
1240
- const sheet = useMemo(() => model.sheet, [
1241
- model.sheet
1242
- ]);
1243
- const sheetId = useMemo(() => fullyQualifiedId(sheet), [
1244
- sheet
1245
- ]);
1246
- useEffect3(() => {
1247
- const unsubscribe = effect(() => {
1248
- const activeThreadAnchors = /* @__PURE__ */ new Set();
1249
- if (!sheet.threads) {
1250
- return;
1251
- }
1252
- for (const thread of sheet.threads) {
1253
- if (!thread || thread.anchor === void 0 || thread.status === "resolved") {
1254
- continue;
1255
- }
1256
- activeThreadAnchors.add(thread.anchor);
1257
- const index = thread.anchor;
1258
- const existingDecorations = decorations.getDecorationsForCell(index);
1259
- if (!existingDecorations || !existingDecorations.some((d) => d.type === "comment")) {
1260
- decorations.addDecoration(index, createThreadDecoration(index, thread.id, sheetId));
1261
- }
1262
- }
1263
- for (const decoration of decorations.getAllDecorations()) {
1264
- if (decoration.type !== "comment") {
1265
- continue;
1266
- }
1267
- if (!activeThreadAnchors.has(decoration.cellIndex)) {
1268
- decorations.removeDecoration(decoration.cellIndex, "comment");
1269
- }
1270
- }
1271
- });
1272
- return () => unsubscribe();
1273
- });
1274
- };
1275
-
1276
- // packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx
1277
- import React2, { createContext as createContext2, useContext, useMemo as useMemo2, useState as useState3 } from "react";
1278
- import { invariant as invariant4 } from "@dxos/invariant";
1279
- import { fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
1280
- import { Grid, useGridContext } from "@dxos/react-ui-grid";
1281
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx";
1282
- var SheetContext = /* @__PURE__ */ createContext2(null);
1283
- var useSheetContext = () => {
1284
- const context = useContext(SheetContext);
1285
- invariant4(context, void 0, {
1286
- F: __dxlog_file3,
1287
- L: 45,
1288
- S: void 0,
1289
- A: [
1290
- "context",
1291
- ""
1292
- ]
1293
- });
1294
- return context;
1295
- };
1296
- var SheetProviderImpl = ({ model, onInfo, children, __gridScope }) => {
1297
- const { id, editing, setEditing } = useGridContext("SheetProvider", __gridScope);
1298
- const decorations = useMemo2(() => createDecorations(), []);
1299
- const [cursor, setCursor] = useState3();
1300
- const [range, setRange] = useState3();
1301
- useSelectThreadOnCellFocus(model, cursor);
1302
- useThreadDecorations(model, decorations);
1303
- return /* @__PURE__ */ React2.createElement(SheetContext.Provider, {
1304
- value: {
1305
- id,
1306
- model,
1307
- editing,
1308
- setEditing,
1309
- cursor,
1310
- setCursor,
1311
- range,
1312
- setRange,
1313
- // TODO(burdon): Change to event.
1314
- onInfo,
1315
- decorations
1316
- }
1317
- }, children);
1318
- };
1319
- var SheetProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1320
- const model = useSheetModel(graph, sheet, {
1321
- readonly
1322
- });
1323
- return !model ? null : /* @__PURE__ */ React2.createElement(Grid.Root, {
1324
- id: fullyQualifiedId2(sheet)
1325
- }, /* @__PURE__ */ React2.createElement(SheetProviderImpl, {
1326
- model,
1327
- onInfo
1328
- }, children));
1329
- };
1330
-
1331
- // packages/plugins/plugin-sheet/src/components/GridSheet/GridSheet.tsx
1332
- var initialCells = {
1333
- grid: {},
1334
- frozenColsStart: [
1335
- ...Array(64)
1336
- ].reduce((acc, _, i) => {
1337
- acc[`0,${i}`] = rowLabelCell(i);
1338
- return acc;
1339
- }, {}),
1340
- frozenRowsStart: [
1341
- ...Array(12)
1342
- ].reduce((acc, _, i) => {
1343
- acc[`${i},0`] = colLabelCell(i);
1344
- return acc;
1345
- }, {})
1346
- };
1347
- var frozen = {
1348
- frozenColsStart: 1,
1349
- frozenRowsStart: 1
1350
- };
1351
- var sheetRowDefault = {
1352
- grid: {
1353
- size: 32,
1354
- resizeable: true
1355
- }
1356
- };
1357
- var sheetColDefault = {
1358
- frozenColsStart: {
1359
- size: 48
1360
- },
1361
- grid: {
1362
- size: 180,
1363
- resizeable: true
1364
- }
1365
- };
1366
- var GridSheet = () => {
1367
- const { id, model, editing, setEditing, setCursor, setRange } = useSheetContext();
1368
- const dxGrid = useRef(null);
1369
- const rangeNotifier = useRef();
1370
- const { hasAttention } = useAttention(id);
1371
- const handleFocus = useCallback2((event) => {
1372
- if (!editing) {
1373
- const cell = closestCell(event.target);
1374
- if (cell && cell.plane === "grid") {
1375
- setCursor({
1376
- col: cell.col,
1377
- row: cell.row
1378
- });
1379
- }
1380
- }
1381
- }, [
1382
- editing
1383
- ]);
1384
- const handleClose = useCallback2((value, { key, shift }) => {
1385
- if (value !== void 0) {
1386
- model.setValue(dxGridCellIndexToSheetCellAddress(editing.index), value);
1387
- }
1388
- setEditing(null);
1389
- const axis = [
1390
- "Enter",
1391
- "ArrowUp",
1392
- "ArrowDown"
1393
- ].includes(key) ? "row" : [
1394
- "Tab",
1395
- "ArrowLeft",
1396
- "ArrowRight"
1397
- ].includes(key) ? "col" : void 0;
1398
- const delta = key.startsWith("Arrow") ? [
1399
- "ArrowUp",
1400
- "ArrowLeft"
1401
- ].includes(key) ? -1 : 1 : shift ? -1 : 1;
1402
- dxGrid.current?.refocus(axis, delta);
1403
- }, [
1404
- model,
1405
- editing,
1406
- setEditing
1407
- ]);
1408
- const handleAxisResize = useCallback2(({ axis, size, index: numericIndex }) => {
1409
- if (axis === "row") {
1410
- const rowId = model.sheet.rows[parseInt(numericIndex)];
1411
- model.sheet.rowMeta[rowId] ??= {};
1412
- model.sheet.rowMeta[rowId].size = size;
1413
- } else {
1414
- const columnId = model.sheet.columns[parseInt(numericIndex)];
1415
- model.sheet.columnMeta[columnId] ??= {};
1416
- model.sheet.columnMeta[columnId].size = size;
1417
- }
1418
- }, [
1419
- model
1420
- ]);
1421
- const handleSelect = useCallback2(({ minCol, maxCol, minRow, maxRow }) => {
1422
- const range = {
1423
- from: {
1424
- col: minCol,
1425
- row: minRow
1426
- }
1427
- };
1428
- if (minCol !== maxCol || minRow !== maxRow) {
1429
- range.to = {
1430
- col: maxCol,
1431
- row: maxRow
1432
- };
1433
- }
1434
- if (editing) {
1435
- rangeNotifier.current?.(rangeToA1Notation(range));
1436
- } else {
1437
- setRange(range.to ? range : void 0);
1438
- }
1439
- }, [
1440
- editing
1441
- ]);
1442
- const handleWheel = useCallback2((event) => {
1443
- if (!hasAttention) {
1444
- event.stopPropagation();
1445
- }
1446
- }, [
1447
- hasAttention
1448
- ]);
1449
- const { columns, rows } = useSheetModelDxGridProps(dxGrid, model);
1450
- const extension = useMemo3(() => [
1451
- editorKeys({
1452
- onClose: handleClose,
1453
- ...editing?.initialContent && {
1454
- onNav: handleClose
1455
- }
1456
- }),
1457
- sheetExtension({
1458
- functions: model.graph.getFunctions()
1459
- }),
1460
- rangeExtension((fn) => rangeNotifier.current = fn)
1461
- ], [
1462
- model,
1463
- handleClose,
1464
- editing
1465
- ]);
1466
- const getCellContent = useCallback2((index) => {
1467
- const cell = dxGridCellIndexToSheetCellAddress(index);
1468
- return model.getCellText(cell);
1469
- }, [
1470
- model
1471
- ]);
1472
- useUpdateFocusedCellOnThreadSelection(model, dxGrid);
1473
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(GridCellEditor, {
1474
- getCellContent,
1475
- extension
1476
- }), /* @__PURE__ */ React3.createElement(Grid2.Content, {
1477
- initialCells,
1478
- limitColumns: DEFAULT_COLUMNS,
1479
- limitRows: DEFAULT_ROWS,
1480
- columns,
1481
- rows,
1482
- onAxisResize: handleAxisResize,
1483
- onSelect: handleSelect,
1484
- rowDefault: sheetRowDefault,
1485
- columnDefault: sheetColDefault,
1486
- frozen,
1487
- onFocus: handleFocus,
1488
- onWheelCapture: handleWheel,
1489
- className: "[--dx-grid-base:var(--surface-bg)]",
1490
- ref: dxGrid
1491
- }));
1492
- };
1493
-
1494
- // packages/plugins/plugin-sheet/src/components/index.ts
1495
- var SheetContainer = React4.lazy(() => import("./SheetContainer-RVRACGCZ.mjs"));
1496
-
1497
- // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
1498
- var useComputeGraph = (space) => {
1499
- const { registry } = useContext2(ComputeGraphContext) ?? raise(new Error("Missing ComputeGraphContext"));
1500
- const [graph] = useAsyncState(async () => {
1501
- if (space) {
1502
- const graph2 = registry.getOrCreateGraph(space);
1503
- await graph2.open();
1504
- return graph2;
1505
- }
1506
- }, [
1507
- space,
1508
- registry
1509
- ]);
1510
- return graph;
1511
- };
1512
-
1513
- export {
1514
- ComputeGraphContextProvider,
1515
- addressToA1Notation,
1516
- rangeToA1Notation,
1517
- inRange,
1518
- createSheet,
1519
- addressToIndex,
1520
- compareIndexPositions,
1521
- computeGraphFacet,
1522
- useComputeGraph,
1523
- useSheetContext,
1524
- SheetProvider,
1525
- GridSheet,
1526
- SheetContainer
1527
- };
1528
- //# sourceMappingURL=chunk-HOG37RYS.mjs.map