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