@dxos/plugin-sheet 0.6.13 → 0.6.14-main.7bd9c89

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 (324) hide show
  1. package/dist/lib/browser/SheetContainer-AKWROARP.mjs +290 -0
  2. package/dist/lib/browser/SheetContainer-AKWROARP.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-BWN5DZWZ.mjs +74 -0
  4. package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-D3QTX46O.mjs +14 -0
  6. package/dist/lib/browser/chunk-D3QTX46O.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-FGMFOW6U.mjs +1570 -0
  8. package/dist/lib/browser/chunk-FGMFOW6U.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-GSV5QNLD.mjs +2966 -0
  10. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
  11. package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
  12. package/dist/lib/browser/graph-M4IQ76QX.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +93 -62
  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/types.mjs +6 -12
  18. package/dist/lib/node/SheetContainer-N5IQGEFL.cjs +300 -0
  19. package/dist/lib/node/SheetContainer-N5IQGEFL.cjs.map +7 -0
  20. package/dist/lib/node/chunk-53BMSUIK.cjs +1569 -0
  21. package/dist/lib/node/chunk-53BMSUIK.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-5XPK2V4A.cjs} +418 -678
  23. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-NZARD7UP.cjs} +40 -51
  25. package/dist/lib/node/chunk-NZARD7UP.cjs.map +7 -0
  26. package/dist/lib/node/chunk-QIFIGEKV.cjs +37 -0
  27. package/dist/lib/node/chunk-QIFIGEKV.cjs.map +7 -0
  28. package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
  29. package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +105 -69
  31. package/dist/lib/node/index.cjs.map +3 -3
  32. package/dist/lib/node/meta.cjs +3 -3
  33. package/dist/lib/node/meta.cjs.map +1 -1
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/types.cjs +9 -15
  36. package/dist/lib/node/types.cjs.map +2 -2
  37. package/dist/lib/node-esm/SheetContainer-46PBMF2E.mjs +291 -0
  38. package/dist/lib/node-esm/SheetContainer-46PBMF2E.mjs.map +7 -0
  39. package/dist/lib/{browser/chunk-D5AGLXJP.mjs → node-esm/chunk-5WPZCXNS.mjs} +411 -678
  40. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-T3PRH7QS.mjs +1571 -0
  42. package/dist/lib/node-esm/chunk-T3PRH7QS.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +16 -0
  44. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs +75 -0
  46. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +7 -0
  47. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
  48. package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +7 -0
  49. package/dist/lib/node-esm/index.mjs +280 -0
  50. package/dist/lib/node-esm/index.mjs.map +7 -0
  51. package/dist/lib/node-esm/meta.json +1 -0
  52. package/dist/lib/node-esm/meta.mjs +10 -0
  53. package/dist/lib/node-esm/meta.mjs.map +7 -0
  54. package/dist/lib/node-esm/types.mjs +17 -0
  55. package/dist/lib/node-esm/types.mjs.map +7 -0
  56. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  57. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +11 -0
  58. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -0
  59. package/dist/types/src/components/ComputeGraph/index.d.ts +1 -3
  60. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  61. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +3 -0
  62. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -0
  63. package/dist/types/src/components/FunctionEditor/index.d.ts +2 -0
  64. package/dist/types/src/components/FunctionEditor/index.d.ts.map +1 -0
  65. package/dist/types/src/components/GridSheet/GridSheet.d.ts +3 -0
  66. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -0
  67. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +6 -0
  68. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -0
  69. package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +5 -9
  70. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/GridSheet/index.d.ts +2 -0
  72. package/dist/types/src/components/GridSheet/index.d.ts.map +1 -0
  73. package/dist/types/src/components/GridSheet/util.d.ts +16 -0
  74. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
  75. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +6 -0
  76. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
  77. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +6 -0
  78. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
  79. package/dist/types/src/components/SheetContainer/index.d.ts +3 -0
  80. package/dist/types/src/components/SheetContainer/index.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContext/SheetContext.d.ts +26 -0
  82. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -0
  83. package/dist/types/src/components/SheetContext/index.d.ts +2 -0
  84. package/dist/types/src/components/SheetContext/index.d.ts.map +1 -0
  85. package/dist/types/src/components/Toolbar/Toolbar.d.ts +33 -9
  86. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  87. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +4 -32
  88. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  89. package/dist/types/src/components/index.d.ts +4 -4
  90. package/dist/types/src/components/index.d.ts.map +1 -1
  91. package/dist/types/src/defs/index.d.ts +4 -0
  92. package/dist/types/src/defs/index.d.ts.map +1 -0
  93. package/dist/types/src/defs/sheet-range-types.d.ts +13 -0
  94. package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -0
  95. package/dist/types/src/{model → defs}/types.d.ts +8 -3
  96. package/dist/types/src/defs/types.d.ts.map +1 -0
  97. package/dist/types/src/defs/types.test.d.ts.map +1 -0
  98. package/dist/types/src/defs/util.d.ts +43 -0
  99. package/dist/types/src/defs/util.d.ts.map +1 -0
  100. package/dist/types/src/extensions/compute.d.ts +6 -0
  101. package/dist/types/src/extensions/compute.d.ts.map +1 -0
  102. package/dist/types/src/extensions/compute.stories.d.ts +21 -0
  103. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
  104. package/dist/types/src/{components/CellEditor → extensions/editor}/extension.d.ts +1 -1
  105. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
  106. package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
  107. package/dist/types/src/extensions/editor/index.d.ts +2 -0
  108. package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
  109. package/dist/types/src/extensions/index.d.ts +3 -0
  110. package/dist/types/src/extensions/index.d.ts.map +1 -0
  111. package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
  112. package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
  113. package/dist/types/src/graph/compute-graph.d.ts +64 -0
  114. package/dist/types/src/graph/compute-graph.d.ts.map +1 -0
  115. package/dist/types/src/graph/compute-graph.stories.d.ts +6 -0
  116. package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -0
  117. package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
  118. package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
  119. package/dist/types/src/graph/compute-node.d.ts +26 -0
  120. package/dist/types/src/graph/compute-node.d.ts.map +1 -0
  121. package/dist/types/src/{components/ComputeGraph → graph/functions}/async-function.d.ts +14 -5
  122. package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
  123. package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
  124. package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
  125. package/dist/types/src/{model/functions.d.ts → graph/functions/function-defs.d.ts} +1 -1
  126. package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
  127. package/dist/types/src/graph/functions/index.d.ts +4 -0
  128. package/dist/types/src/graph/functions/index.d.ts.map +1 -0
  129. package/dist/types/src/graph/hyperformula.test.d.ts +2 -0
  130. package/dist/types/src/graph/hyperformula.test.d.ts.map +1 -0
  131. package/dist/types/src/graph/index.d.ts +5 -0
  132. package/dist/types/src/graph/index.d.ts.map +1 -0
  133. package/dist/types/src/graph/testing/index.d.ts +3 -0
  134. package/dist/types/src/graph/testing/index.d.ts.map +1 -0
  135. package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
  136. package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
  137. package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
  138. package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
  139. package/dist/types/src/graph/util.d.ts +2 -0
  140. package/dist/types/src/graph/util.d.ts.map +1 -0
  141. package/dist/types/src/hooks/hooks.stories.d.ts +6 -0
  142. package/dist/types/src/hooks/hooks.stories.d.ts.map +1 -0
  143. package/dist/types/src/hooks/index.d.ts +4 -0
  144. package/dist/types/src/hooks/index.d.ts.map +1 -0
  145. package/dist/types/src/hooks/threads.d.ts +8 -0
  146. package/dist/types/src/hooks/threads.d.ts.map +1 -0
  147. package/dist/types/src/hooks/useComputeGraph.d.ts +7 -0
  148. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -0
  149. package/dist/types/src/hooks/useSheetModel.d.ts +8 -0
  150. package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -0
  151. package/dist/types/src/meta.d.ts +3 -9
  152. package/dist/types/src/meta.d.ts.map +1 -1
  153. package/dist/types/src/model/decorations.d.ts +26 -0
  154. package/dist/types/src/model/decorations.d.ts.map +1 -0
  155. package/dist/types/src/model/index.d.ts +2 -3
  156. package/dist/types/src/model/index.d.ts.map +1 -1
  157. package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +13 -67
  158. package/dist/types/src/model/sheet-model.d.ts.map +1 -0
  159. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  160. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  161. package/dist/types/src/sanity.test.d.ts +2 -0
  162. package/dist/types/src/sanity.test.d.ts.map +1 -0
  163. package/dist/types/src/testing/index.d.ts +2 -0
  164. package/dist/types/src/testing/index.d.ts.map +1 -0
  165. package/dist/types/src/testing/testing.d.ts +8 -0
  166. package/dist/types/src/testing/testing.d.ts.map +1 -0
  167. package/dist/types/src/translations.d.ts +17 -12
  168. package/dist/types/src/translations.d.ts.map +1 -1
  169. package/dist/types/src/types.d.ts +125 -40
  170. package/dist/types/src/types.d.ts.map +1 -1
  171. package/dist/vendor/hyperformula.mjs +37145 -0
  172. package/package.json +58 -52
  173. package/src/SheetPlugin.tsx +52 -74
  174. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +20 -0
  175. package/src/components/ComputeGraph/index.ts +1 -3
  176. package/src/components/FunctionEditor/FunctionEditor.tsx +45 -0
  177. package/src/components/FunctionEditor/index.ts +5 -0
  178. package/src/components/GridSheet/GridSheet.stories.tsx +44 -0
  179. package/src/components/GridSheet/GridSheet.tsx +201 -0
  180. package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +18 -15
  181. package/src/components/GridSheet/index.ts +5 -0
  182. package/src/components/GridSheet/util.ts +154 -0
  183. package/src/components/SheetContainer/SheetContainer.stories.tsx +43 -0
  184. package/src/components/SheetContainer/SheetContainer.tsx +27 -0
  185. package/src/components/SheetContainer/index.ts +7 -0
  186. package/src/components/SheetContext/SheetContext.tsx +104 -0
  187. package/src/components/SheetContext/index.ts +5 -0
  188. package/src/components/Toolbar/Toolbar.stories.tsx +9 -6
  189. package/src/components/Toolbar/Toolbar.tsx +242 -112
  190. package/src/components/index.ts +4 -3
  191. package/src/defs/index.ts +7 -0
  192. package/src/defs/sheet-range-types.ts +46 -0
  193. package/src/{model → defs}/types.test.ts +8 -9
  194. package/src/{model → defs}/types.ts +24 -14
  195. package/src/defs/util.ts +151 -0
  196. package/src/extensions/compute.stories.tsx +155 -0
  197. package/src/extensions/compute.ts +147 -0
  198. package/src/{components/CellEditor → extensions/editor}/extension.test.ts +4 -6
  199. package/src/{components/CellEditor → extensions/editor}/extension.ts +5 -6
  200. package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
  201. package/src/extensions/index.ts +6 -0
  202. package/src/graph/compute-graph-registry.ts +90 -0
  203. package/src/graph/compute-graph.stories.tsx +96 -0
  204. package/src/graph/compute-graph.test.ts +87 -0
  205. package/src/graph/compute-graph.ts +242 -0
  206. package/src/graph/compute-node.ts +63 -0
  207. package/src/{components/ComputeGraph → graph/functions}/async-function.ts +25 -15
  208. package/src/{components/ComputeGraph → graph/functions}/edge-function.ts +16 -14
  209. package/src/graph/functions/index.ts +7 -0
  210. package/src/graph/hyperformula.test.ts +14 -0
  211. package/src/graph/index.ts +8 -0
  212. package/src/graph/testing/index.ts +6 -0
  213. package/src/graph/testing/test-builder.ts +54 -0
  214. package/src/{components/ComputeGraph/custom.ts → graph/testing/test-plugin.ts} +44 -14
  215. package/src/graph/util.ts +8 -0
  216. package/src/hooks/hooks.stories.tsx +53 -0
  217. package/src/hooks/index.ts +7 -0
  218. package/src/hooks/threads.ts +147 -0
  219. package/src/hooks/useComputeGraph.ts +28 -0
  220. package/src/hooks/useSheetModel.ts +40 -0
  221. package/src/meta.ts +14 -0
  222. package/src/model/decorations.ts +66 -0
  223. package/src/model/index.ts +2 -3
  224. package/src/model/sheet-model.test.ts +57 -0
  225. package/src/model/sheet-model.ts +418 -0
  226. package/src/sanity.test.ts +40 -0
  227. package/src/{components/Sheet → testing}/index.ts +1 -1
  228. package/src/testing/testing.tsx +68 -0
  229. package/src/translations.ts +6 -1
  230. package/src/types.ts +40 -47
  231. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +0 -1772
  232. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
  233. package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
  234. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
  235. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
  236. package/dist/lib/browser/chunk-FUAGSXA4.mjs +0 -82
  237. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
  238. package/dist/lib/browser/chunk-JRL5LGCE.mjs +0 -18
  239. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
  240. package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
  241. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
  242. package/dist/lib/browser/testing.mjs +0 -92
  243. package/dist/lib/browser/testing.mjs.map +0 -7
  244. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +0 -1765
  245. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
  246. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
  247. package/dist/lib/node/chunk-BJ6ZD7MN.cjs +0 -51
  248. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
  249. package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
  250. package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
  251. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
  252. package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
  253. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
  254. package/dist/lib/node/testing.cjs +0 -111
  255. package/dist/lib/node/testing.cjs.map +0 -7
  256. package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -14
  257. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
  258. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
  259. package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
  260. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
  261. package/dist/types/src/components/CellEditor/index.d.ts +0 -3
  262. package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
  263. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
  264. package/dist/types/src/components/ComputeGraph/custom.d.ts +0 -21
  265. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
  266. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +0 -20
  267. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
  268. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
  269. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
  270. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
  271. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
  272. package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
  273. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
  274. package/dist/types/src/components/Sheet/Sheet.d.ts +0 -55
  275. package/dist/types/src/components/Sheet/Sheet.d.ts.map +0 -1
  276. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +0 -54
  277. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
  278. package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
  279. package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
  280. package/dist/types/src/components/Sheet/grid.d.ts +0 -52
  281. package/dist/types/src/components/Sheet/grid.d.ts.map +0 -1
  282. package/dist/types/src/components/Sheet/index.d.ts +0 -2
  283. package/dist/types/src/components/Sheet/index.d.ts.map +0 -1
  284. package/dist/types/src/components/Sheet/nav.d.ts +0 -29
  285. package/dist/types/src/components/Sheet/nav.d.ts.map +0 -1
  286. package/dist/types/src/components/Sheet/sheet-context.d.ts +0 -25
  287. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
  288. package/dist/types/src/components/Sheet/util.d.ts +0 -18
  289. package/dist/types/src/components/Sheet/util.d.ts.map +0 -1
  290. package/dist/types/src/components/SheetContainer.d.ts +0 -9
  291. package/dist/types/src/components/SheetContainer.d.ts.map +0 -1
  292. package/dist/types/src/components/Toolbar/common.d.ts +0 -20
  293. package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
  294. package/dist/types/src/model/functions.d.ts.map +0 -1
  295. package/dist/types/src/model/model.browser.test.d.ts +0 -2
  296. package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
  297. package/dist/types/src/model/model.d.ts.map +0 -1
  298. package/dist/types/src/model/types.d.ts.map +0 -1
  299. package/dist/types/src/model/types.test.d.ts.map +0 -1
  300. package/dist/types/src/model/util.d.ts +0 -15
  301. package/dist/types/src/model/util.d.ts.map +0 -1
  302. package/dist/types/src/testing.d.ts +0 -9
  303. package/dist/types/src/testing.d.ts.map +0 -1
  304. package/src/components/CellEditor/CellEditor.tsx +0 -113
  305. package/src/components/ComputeGraph/graph-context.tsx +0 -50
  306. package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
  307. package/src/components/ComputeGraph/graph.ts +0 -62
  308. package/src/components/Sheet/Sheet.stories.tsx +0 -287
  309. package/src/components/Sheet/Sheet.tsx +0 -1160
  310. package/src/components/Sheet/formatting.ts +0 -106
  311. package/src/components/Sheet/grid.ts +0 -191
  312. package/src/components/Sheet/nav.ts +0 -157
  313. package/src/components/Sheet/sheet-context.tsx +0 -150
  314. package/src/components/Sheet/util.ts +0 -56
  315. package/src/components/SheetContainer.tsx +0 -34
  316. package/src/components/Toolbar/common.tsx +0 -72
  317. package/src/meta.tsx +0 -18
  318. package/src/model/model.browser.test.ts +0 -100
  319. package/src/model/model.ts +0 -550
  320. package/src/model/util.ts +0 -36
  321. package/src/testing.ts +0 -50
  322. /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
  323. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
  324. /package/src/{model/functions.ts → graph/functions/function-defs.ts} +0 -0
@@ -0,0 +1,1570 @@
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 { lazy } 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
+ cachedGridCells[`${col},${row}`] = projectCellProps(model, col, row);
508
+ });
509
+ });
510
+ return cachedGridCells;
511
+ };
512
+ };
513
+ var rowLabelCell = (row) => ({
514
+ value: rowToA1Notation(row),
515
+ className: "text-end !pie-1",
516
+ resizeHandle: "row"
517
+ });
518
+ var colLabelCell = (col) => ({
519
+ value: colToA1Notation(col),
520
+ resizeHandle: "col"
521
+ });
522
+ var cellGetter = (model) => {
523
+ const getGridCells = gridCellGetter(model);
524
+ return (nextBounds, plane) => {
525
+ switch (plane) {
526
+ case "grid":
527
+ return getGridCells(nextBounds);
528
+ case "frozenColsStart":
529
+ return [
530
+ ...Array(nextBounds.end.row - nextBounds.start.row)
531
+ ].reduce((acc, _, r0) => {
532
+ const r = nextBounds.start.row + r0;
533
+ acc[`0,${r}`] = rowLabelCell(r);
534
+ return acc;
535
+ }, {});
536
+ case "frozenRowsStart":
537
+ return [
538
+ ...Array(nextBounds.end.col - nextBounds.start.col)
539
+ ].reduce((acc, _, c0) => {
540
+ const c = nextBounds.start.col + c0;
541
+ acc[`${c},0`] = colLabelCell(c);
542
+ return acc;
543
+ }, {});
544
+ default:
545
+ return {};
546
+ }
547
+ };
548
+ };
549
+ var useSheetModelDxGridProps = (dxGridRef, model) => {
550
+ const [columns, setColumns] = useState(createDxGridColumns(model));
551
+ const [rows, setRows] = useState(createDxGridColumns(model));
552
+ useLayoutEffect(() => {
553
+ const cellsAccessor = createDocAccessor(model.sheet, [
554
+ "cells"
555
+ ]);
556
+ if (dxGridRef.current) {
557
+ dxGridRef.current.getCells = cellGetter(model);
558
+ }
559
+ const handleCellsUpdate = () => {
560
+ dxGridRef.current?.requestUpdate("initialCells");
561
+ };
562
+ cellsAccessor.handle.addListener("change", handleCellsUpdate);
563
+ return () => cellsAccessor.handle.removeListener("change", handleCellsUpdate);
564
+ }, [
565
+ model
566
+ ]);
567
+ useEffect(() => {
568
+ const columnMetaAccessor = createDocAccessor(model.sheet, [
569
+ "columnMeta"
570
+ ]);
571
+ const rowMetaAccessor = createDocAccessor(model.sheet, [
572
+ "rowMeta"
573
+ ]);
574
+ const handleColumnMetaUpdate = () => {
575
+ setColumns(createDxGridColumns(model));
576
+ };
577
+ const handleRowMetaUpdate = () => {
578
+ setRows(createDxGridRows(model));
579
+ };
580
+ columnMetaAccessor.handle.addListener("change", handleColumnMetaUpdate);
581
+ rowMetaAccessor.handle.addListener("change", handleRowMetaUpdate);
582
+ return () => {
583
+ columnMetaAccessor.handle.removeListener("change", handleColumnMetaUpdate);
584
+ rowMetaAccessor.handle.removeListener("change", handleRowMetaUpdate);
585
+ };
586
+ }, [
587
+ model
588
+ ]);
589
+ return {
590
+ columns,
591
+ rows
592
+ };
593
+ };
594
+
595
+ // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
596
+ import { useEffect as useEffect2, useState as useState2 } from "react";
597
+
598
+ // packages/plugins/plugin-sheet/src/model/decorations.ts
599
+ import { create as create2 } from "@dxos/echo-schema";
600
+ var createDecorations = () => {
601
+ const { decorations } = create2({
602
+ decorations: {}
603
+ });
604
+ const addDecoration = (cellIndex, decorator) => {
605
+ decorations[cellIndex] = [
606
+ ...decorations[cellIndex] || [],
607
+ decorator
608
+ ];
609
+ };
610
+ const removeDecoration = (cellIndex, type) => {
611
+ if (type) {
612
+ decorations[cellIndex] = (decorations[cellIndex] || []).filter((d) => d.type !== type);
613
+ } else {
614
+ delete decorations[cellIndex];
615
+ }
616
+ };
617
+ const getDecorationsForCell = (cellIndex) => {
618
+ return decorations[cellIndex];
619
+ };
620
+ const getAllDecorations = () => {
621
+ const result = [];
622
+ for (const decoratorArray of Object.values(decorations)) {
623
+ for (const decorator of decoratorArray) {
624
+ result.push(decorator);
625
+ }
626
+ }
627
+ return result;
628
+ };
629
+ return {
630
+ addDecoration,
631
+ removeDecoration,
632
+ getDecorationsForCell,
633
+ getAllDecorations
634
+ };
635
+ };
636
+
637
+ // packages/plugins/plugin-sheet/src/model/sheet-model.ts
638
+ import { Event } from "@dxos/async";
639
+ import { Resource } from "@dxos/context";
640
+ import { getTypename } from "@dxos/echo-schema";
641
+ import { invariant as invariant3 } from "@dxos/invariant";
642
+ import { PublicKey } from "@dxos/keys";
643
+ import { log } from "@dxos/log";
644
+ import { FieldValueType } from "@dxos/schema";
645
+ import { DetailedCellError, ExportedCellChange } from "#hyperformula";
646
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
647
+ var typeMap = {
648
+ BOOLEAN: FieldValueType.Boolean,
649
+ NUMBER_RAW: FieldValueType.Number,
650
+ NUMBER_PERCENT: FieldValueType.Percent,
651
+ NUMBER_CURRENCY: FieldValueType.Currency,
652
+ NUMBER_DATETIME: FieldValueType.DateTime,
653
+ NUMBER_DATE: FieldValueType.Date,
654
+ NUMBER_TIME: FieldValueType.Time
655
+ };
656
+ var getTopLeft = (range) => {
657
+ const to = range.to ?? range.from;
658
+ return {
659
+ row: Math.min(range.from.row, to.row),
660
+ col: Math.min(range.from.col, to.col)
661
+ };
662
+ };
663
+ var toSimpleCellAddress = (sheet, cell) => ({
664
+ sheet,
665
+ row: cell.row,
666
+ col: cell.col
667
+ });
668
+ var toModelRange = (sheet, range) => ({
669
+ start: toSimpleCellAddress(sheet, range.from),
670
+ end: toSimpleCellAddress(sheet, range.to ?? range.from)
671
+ });
672
+ var SheetModel = class extends Resource {
673
+ constructor(_graph, _sheet, _options = {}) {
674
+ super();
675
+ this._graph = _graph;
676
+ this._sheet = _sheet;
677
+ this._options = _options;
678
+ this.id = `model-${PublicKey.random().truncate()}`;
679
+ this.update = new Event();
680
+ }
681
+ get graph() {
682
+ return this._graph;
683
+ }
684
+ get sheet() {
685
+ return this._sheet;
686
+ }
687
+ get readonly() {
688
+ return this._options.readonly;
689
+ }
690
+ get bounds() {
691
+ return {
692
+ rows: this._sheet.rows.length,
693
+ columns: this._sheet.columns.length
694
+ };
695
+ }
696
+ /**
697
+ * Initialize sheet and engine.
698
+ */
699
+ async _open() {
700
+ log("initialize", {
701
+ id: this.id
702
+ }, {
703
+ F: __dxlog_file2,
704
+ L: 106,
705
+ S: this,
706
+ C: (f, a) => f(...a)
707
+ });
708
+ initialize(this._sheet);
709
+ this._node = this._graph.getOrCreateNode(createSheetName({
710
+ type: getTypename(this._sheet),
711
+ id: this._sheet.id
712
+ }));
713
+ await this._node.open();
714
+ const unsubscribe = this._node.update.on((event) => this.update.emit(event));
715
+ this._ctx.onDispose(unsubscribe);
716
+ this.reset();
717
+ }
718
+ /**
719
+ * Update engine.
720
+ * NOTE: This resets the undo history.
721
+ * @deprecated
722
+ */
723
+ reset() {
724
+ invariant3(this._node, void 0, {
725
+ F: __dxlog_file2,
726
+ L: 126,
727
+ S: this,
728
+ A: [
729
+ "this._node",
730
+ ""
731
+ ]
732
+ });
733
+ this._node.graph.hf.clearSheet(this._node.sheetId);
734
+ Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
735
+ invariant3(this._node, void 0, {
736
+ F: __dxlog_file2,
737
+ L: 129,
738
+ S: this,
739
+ A: [
740
+ "this._node",
741
+ ""
742
+ ]
743
+ });
744
+ const { col, row } = addressFromIndex(this._sheet, key);
745
+ if (typeof value === "string" && value.charAt(0) === "=") {
746
+ value = this._graph.mapFormulaToNative(this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)));
747
+ }
748
+ this._node.graph.hf.setCellContents({
749
+ sheet: this._node.sheetId,
750
+ row,
751
+ col
752
+ }, value);
753
+ });
754
+ }
755
+ /**
756
+ * Recalculate formulas.
757
+ * NOTE: This resets the undo history.
758
+ * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
759
+ * @deprecated
760
+ */
761
+ // TODO(burdon): Remove.
762
+ recalculate() {
763
+ this._node?.graph.hf.rebuildAndRecalculate();
764
+ }
765
+ insertRows(i, n = 1) {
766
+ insertIndices(this._sheet.rows, i, n, MAX_ROWS);
767
+ this.reset();
768
+ }
769
+ insertColumns(i, n = 1) {
770
+ insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
771
+ this.reset();
772
+ }
773
+ //
774
+ // Undoable actions.
775
+ // TODO(burdon): Group undoable methods; consistently update hf/sheet.
776
+ //
777
+ /**
778
+ * Clear range of values.
779
+ */
780
+ clear(range) {
781
+ invariant3(this._node, void 0, {
782
+ F: __dxlog_file2,
783
+ L: 171,
784
+ S: this,
785
+ A: [
786
+ "this._node",
787
+ ""
788
+ ]
789
+ });
790
+ const topLeft = getTopLeft(range);
791
+ const values = this._iterRange(range, () => null);
792
+ this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
793
+ this._iterRange(range, (cell) => {
794
+ const idx = addressToIndex(this._sheet, cell);
795
+ delete this._sheet.cells[idx];
796
+ });
797
+ }
798
+ cut(range) {
799
+ invariant3(this._node, void 0, {
800
+ F: __dxlog_file2,
801
+ L: 182,
802
+ S: this,
803
+ A: [
804
+ "this._node",
805
+ ""
806
+ ]
807
+ });
808
+ this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
809
+ this._iterRange(range, (cell) => {
810
+ const idx = addressToIndex(this._sheet, cell);
811
+ delete this._sheet.cells[idx];
812
+ });
813
+ }
814
+ copy(range) {
815
+ invariant3(this._node, void 0, {
816
+ F: __dxlog_file2,
817
+ L: 191,
818
+ S: this,
819
+ A: [
820
+ "this._node",
821
+ ""
822
+ ]
823
+ });
824
+ this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
825
+ }
826
+ paste(cell) {
827
+ invariant3(this._node, void 0, {
828
+ F: __dxlog_file2,
829
+ L: 196,
830
+ S: this,
831
+ A: [
832
+ "this._node",
833
+ ""
834
+ ]
835
+ });
836
+ if (!this._node.graph.hf.isClipboardEmpty()) {
837
+ const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
838
+ for (const change of changes) {
839
+ if (change instanceof ExportedCellChange) {
840
+ const { address, newValue } = change;
841
+ const idx = addressToIndex(this._sheet, {
842
+ row: address.row,
843
+ col: address.col
844
+ });
845
+ this._sheet.cells[idx] = {
846
+ value: newValue
847
+ };
848
+ }
849
+ }
850
+ }
851
+ }
852
+ // TODO(burdon): Display undo/redo state.
853
+ undo() {
854
+ invariant3(this._node, void 0, {
855
+ F: __dxlog_file2,
856
+ L: 211,
857
+ S: this,
858
+ A: [
859
+ "this._node",
860
+ ""
861
+ ]
862
+ });
863
+ if (this._node.graph.hf.isThereSomethingToUndo()) {
864
+ this._node.graph.hf.undo();
865
+ }
866
+ }
867
+ redo() {
868
+ invariant3(this._node, void 0, {
869
+ F: __dxlog_file2,
870
+ L: 219,
871
+ S: this,
872
+ A: [
873
+ "this._node",
874
+ ""
875
+ ]
876
+ });
877
+ if (this._node.graph.hf.isThereSomethingToRedo()) {
878
+ this._node.graph.hf.redo();
879
+ }
880
+ }
881
+ /**
882
+ * Get value from sheet.
883
+ */
884
+ getCellValue(cell) {
885
+ const idx = addressToIndex(this._sheet, cell);
886
+ return this._sheet.cells[idx]?.value ?? null;
887
+ }
888
+ /**
889
+ * Get value as a string for editing.
890
+ */
891
+ getCellText(cell) {
892
+ const value = this.getCellValue(cell);
893
+ if (value == null) {
894
+ return void 0;
895
+ }
896
+ if (typeof value === "string" && value.charAt(0) === "=") {
897
+ return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
898
+ } else {
899
+ return String(value);
900
+ }
901
+ }
902
+ /**
903
+ * Get array of raw values from sheet.
904
+ */
905
+ getCellValues(range) {
906
+ return this._iterRange(range, (cell) => this.getCellValue(cell));
907
+ }
908
+ /**
909
+ * Gets the regular or computed value from the engine.
910
+ */
911
+ getValue(cell) {
912
+ invariant3(this._node, void 0, {
913
+ F: __dxlog_file2,
914
+ L: 262,
915
+ S: this,
916
+ A: [
917
+ "this._node",
918
+ ""
919
+ ]
920
+ });
921
+ const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
922
+ if (value instanceof DetailedCellError) {
923
+ return value.toString();
924
+ }
925
+ return value;
926
+ }
927
+ /**
928
+ * Get value type.
929
+ */
930
+ getValueType(cell) {
931
+ invariant3(this._node, void 0, {
932
+ F: __dxlog_file2,
933
+ L: 275,
934
+ S: this,
935
+ A: [
936
+ "this._node",
937
+ ""
938
+ ]
939
+ });
940
+ const addr = toSimpleCellAddress(this._node.sheetId, cell);
941
+ const type = this._node.graph.hf.getCellValueDetailedType(addr);
942
+ return typeMap[type];
943
+ }
944
+ /**
945
+ * Sets the value, updating the sheet and engine.
946
+ */
947
+ setValue(cell, value) {
948
+ invariant3(this._node, void 0, {
949
+ F: __dxlog_file2,
950
+ L: 285,
951
+ S: this,
952
+ A: [
953
+ "this._node",
954
+ ""
955
+ ]
956
+ });
957
+ if (this._options.readonly) {
958
+ throw new ReadonlyException();
959
+ }
960
+ let refresh = false;
961
+ if (cell.row >= this._sheet.rows.length) {
962
+ insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
963
+ refresh = true;
964
+ }
965
+ if (cell.col >= this._sheet.columns.length) {
966
+ insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
967
+ refresh = true;
968
+ }
969
+ if (refresh) {
970
+ this.reset();
971
+ }
972
+ this._node.graph.hf.setCellContents({
973
+ sheet: this._node.sheetId,
974
+ row: cell.row,
975
+ col: cell.col
976
+ }, [
977
+ [
978
+ typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value
979
+ ]
980
+ ]);
981
+ const idx = addressToIndex(this._sheet, cell);
982
+ if (value === void 0 || value === null) {
983
+ delete this._sheet.cells[idx];
984
+ } else {
985
+ if (typeof value === "string" && value.charAt(0) === "=") {
986
+ value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
987
+ }
988
+ this._sheet.cells[idx] = {
989
+ value
990
+ };
991
+ }
992
+ }
993
+ /**
994
+ * Sets values from a simple map.
995
+ */
996
+ setValues(values) {
997
+ Object.entries(values).forEach(([key, { value }]) => {
998
+ this.setValue(addressFromA1Notation(key), value);
999
+ });
1000
+ }
1001
+ /**
1002
+ * Iterate range.
1003
+ */
1004
+ _iterRange(range, cb) {
1005
+ const to = range.to ?? range.from;
1006
+ const rowRange = [
1007
+ Math.min(range.from.row, to.row),
1008
+ Math.max(range.from.row, to.row)
1009
+ ];
1010
+ const columnRange = [
1011
+ Math.min(range.from.col, to.col),
1012
+ Math.max(range.from.col, to.col)
1013
+ ];
1014
+ const rows = [];
1015
+ for (let row = rowRange[0]; row <= rowRange[1]; row++) {
1016
+ const rowCells = [];
1017
+ for (let column = columnRange[0]; column <= columnRange[1]; column++) {
1018
+ const value = cb({
1019
+ row,
1020
+ col: column
1021
+ });
1022
+ if (value !== void 0) {
1023
+ rowCells.push(value);
1024
+ }
1025
+ }
1026
+ rows.push(rowCells);
1027
+ }
1028
+ return rows;
1029
+ }
1030
+ // TODO(burdon): Delete index.
1031
+ _deleteIndices(indices, i, n) {
1032
+ throw new Error("Not implemented");
1033
+ }
1034
+ // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
1035
+ _moveIndices(indices, i, j, n) {
1036
+ throw new Error("Not implemented");
1037
+ }
1038
+ //
1039
+ // Indices.
1040
+ //
1041
+ /**
1042
+ * Map from A1 notation to indices.
1043
+ */
1044
+ mapFormulaRefsToIndices(formula) {
1045
+ invariant3(formula.charAt(0) === "=", void 0, {
1046
+ F: __dxlog_file2,
1047
+ L: 374,
1048
+ S: this,
1049
+ A: [
1050
+ "formula.charAt(0) === '='",
1051
+ ""
1052
+ ]
1053
+ });
1054
+ return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
1055
+ return addressToIndex(this._sheet, addressFromA1Notation(match));
1056
+ });
1057
+ }
1058
+ /**
1059
+ * Map from indices to A1 notation.
1060
+ */
1061
+ mapFormulaIndicesToRefs(formula) {
1062
+ invariant3(formula.charAt(0) === "=", void 0, {
1063
+ F: __dxlog_file2,
1064
+ L: 384,
1065
+ S: this,
1066
+ A: [
1067
+ "formula.charAt(0) === '='",
1068
+ ""
1069
+ ]
1070
+ });
1071
+ return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
1072
+ return addressToA1Notation(addressFromIndex(this._sheet, idx));
1073
+ });
1074
+ }
1075
+ //
1076
+ // Values
1077
+ //
1078
+ /**
1079
+ * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
1080
+ * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
1081
+ * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
1082
+ */
1083
+ toLocalDate(num) {
1084
+ const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
1085
+ return new Date(year, month - 1, day, hours, minutes, seconds);
1086
+ }
1087
+ toDateTime(num) {
1088
+ invariant3(this._node, void 0, {
1089
+ F: __dxlog_file2,
1090
+ L: 405,
1091
+ S: this,
1092
+ A: [
1093
+ "this._node",
1094
+ ""
1095
+ ]
1096
+ });
1097
+ return this._node.graph.hf.numberToDateTime(num);
1098
+ }
1099
+ toDate(num) {
1100
+ invariant3(this._node, void 0, {
1101
+ F: __dxlog_file2,
1102
+ L: 410,
1103
+ S: this,
1104
+ A: [
1105
+ "this._node",
1106
+ ""
1107
+ ]
1108
+ });
1109
+ return this._node.graph.hf.numberToDate(num);
1110
+ }
1111
+ toTime(num) {
1112
+ invariant3(this._node, void 0, {
1113
+ F: __dxlog_file2,
1114
+ L: 415,
1115
+ S: this,
1116
+ A: [
1117
+ "this._node",
1118
+ ""
1119
+ ]
1120
+ });
1121
+ return this._node.graph.hf.numberToTime(num);
1122
+ }
1123
+ };
1124
+
1125
+ // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
1126
+ var useSheetModel = (graph, sheet, { readonly } = {}) => {
1127
+ const [model, setModel] = useState2();
1128
+ useEffect2(() => {
1129
+ if (!graph || !sheet) {
1130
+ return;
1131
+ }
1132
+ let model2;
1133
+ const t = setTimeout(async () => {
1134
+ model2 = new SheetModel(graph, sheet, {
1135
+ readonly
1136
+ });
1137
+ await model2.open();
1138
+ setModel(model2);
1139
+ });
1140
+ return () => {
1141
+ clearTimeout(t);
1142
+ void model2?.close();
1143
+ };
1144
+ }, [
1145
+ graph,
1146
+ sheet,
1147
+ readonly
1148
+ ]);
1149
+ return model;
1150
+ };
1151
+
1152
+ // packages/plugins/plugin-sheet/src/hooks/threads.ts
1153
+ import { effect } from "@preact/signals-core";
1154
+ import { useCallback, useEffect as useEffect3, useMemo } from "react";
1155
+ import { LayoutAction, useIntentDispatcher, useIntentResolver } from "@dxos/app-framework";
1156
+ import { debounce as debounce2 } from "@dxos/async";
1157
+ import { fullyQualifiedId } from "@dxos/react-client/echo";
1158
+ var useUpdateFocusedCellOnThreadSelection = (model, grid) => {
1159
+ const handleScrollIntoView = useCallback(({ action, data }) => {
1160
+ switch (action) {
1161
+ case LayoutAction.SCROLL_INTO_VIEW: {
1162
+ if (!data?.id || data?.cursor === void 0 || data?.id !== fullyQualifiedId(model.sheet)) {
1163
+ return;
1164
+ }
1165
+ const cellAddress = addressFromIndex(model.sheet, data.cursor);
1166
+ grid.current?.setFocus({
1167
+ ...cellAddress,
1168
+ plane: "grid"
1169
+ }, true);
1170
+ }
1171
+ }
1172
+ }, [
1173
+ model.sheet
1174
+ ]);
1175
+ useIntentResolver(SHEET_PLUGIN, handleScrollIntoView);
1176
+ };
1177
+ var useSelectThreadOnCellFocus = (model, cursor) => {
1178
+ const dispatch = useIntentDispatcher();
1179
+ const activeThreads = useMemo(() => model.sheet.threads?.filter((thread) => !!thread && thread.status === "active") ?? [], [
1180
+ // TODO(thure): Surely we can find a better dependency for this…
1181
+ JSON.stringify(model.sheet.threads)
1182
+ ]);
1183
+ const activeThreadAddresses = useMemo(() => activeThreads.map((thread) => thread.anchor).filter((anchor) => anchor !== void 0).map((anchor) => addressFromIndex(model.sheet, anchor)), [
1184
+ activeThreads,
1185
+ model.sheet
1186
+ ]);
1187
+ const selectClosestThread = useCallback((cellAddress) => {
1188
+ if (!cellAddress || !activeThreads) {
1189
+ return;
1190
+ }
1191
+ const closestThreadAnchor = closest(cellAddress, activeThreadAddresses);
1192
+ if (closestThreadAnchor) {
1193
+ const closestThread = activeThreads.find((thread) => thread && thread.anchor === addressToIndex(model.sheet, closestThreadAnchor));
1194
+ if (closestThread) {
1195
+ void dispatch([
1196
+ {
1197
+ action: "dxos.org/plugin/thread/action/select",
1198
+ data: {
1199
+ current: fullyQualifiedId(closestThread)
1200
+ }
1201
+ }
1202
+ ]);
1203
+ }
1204
+ }
1205
+ }, [
1206
+ dispatch,
1207
+ activeThreads,
1208
+ activeThreadAddresses,
1209
+ model.sheet
1210
+ ]);
1211
+ const debounced = useMemo(() => {
1212
+ return debounce2((cellCoords) => requestAnimationFrame(() => selectClosestThread(cellCoords)), 50);
1213
+ }, [
1214
+ selectClosestThread
1215
+ ]);
1216
+ useEffect3(() => {
1217
+ if (!cursor) {
1218
+ return;
1219
+ }
1220
+ debounced(cursor);
1221
+ }, [
1222
+ cursor,
1223
+ selectClosestThread
1224
+ ]);
1225
+ };
1226
+ var createThreadDecoration = (cellIndex, threadId, sheetId) => {
1227
+ return {
1228
+ type: "comment",
1229
+ classNames: [
1230
+ "bg-greenFill"
1231
+ ],
1232
+ cellIndex
1233
+ };
1234
+ };
1235
+ var useThreadDecorations = (model, decorations) => {
1236
+ const sheet = useMemo(() => model.sheet, [
1237
+ model.sheet
1238
+ ]);
1239
+ const sheetId = useMemo(() => fullyQualifiedId(sheet), [
1240
+ sheet
1241
+ ]);
1242
+ useEffect3(() => {
1243
+ const unsubscribe = effect(() => {
1244
+ const activeThreadAnchors = /* @__PURE__ */ new Set();
1245
+ if (!sheet.threads) {
1246
+ return;
1247
+ }
1248
+ for (const thread of sheet.threads) {
1249
+ if (!thread || thread.anchor === void 0 || thread.status === "resolved") {
1250
+ continue;
1251
+ }
1252
+ activeThreadAnchors.add(thread.anchor);
1253
+ const index = thread.anchor;
1254
+ const existingDecorations = decorations.getDecorationsForCell(index);
1255
+ if (!existingDecorations || !existingDecorations.some((d) => d.type === "comment")) {
1256
+ decorations.addDecoration(index, createThreadDecoration(index, thread.id, sheetId));
1257
+ }
1258
+ }
1259
+ for (const decoration of decorations.getAllDecorations()) {
1260
+ if (decoration.type !== "comment") {
1261
+ continue;
1262
+ }
1263
+ if (!activeThreadAnchors.has(decoration.cellIndex)) {
1264
+ decorations.removeDecoration(decoration.cellIndex, "comment");
1265
+ }
1266
+ }
1267
+ });
1268
+ return () => unsubscribe();
1269
+ });
1270
+ };
1271
+
1272
+ // packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx
1273
+ import React2, { createContext as createContext2, useContext, useMemo as useMemo2, useState as useState3 } from "react";
1274
+ import { invariant as invariant4 } from "@dxos/invariant";
1275
+ import { fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
1276
+ import { Grid, useGridContext } from "@dxos/react-ui-grid";
1277
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx";
1278
+ var SheetContext = /* @__PURE__ */ createContext2(void 0);
1279
+ var useSheetContext = () => {
1280
+ const context = useContext(SheetContext);
1281
+ invariant4(context, void 0, {
1282
+ F: __dxlog_file3,
1283
+ L: 45,
1284
+ S: void 0,
1285
+ A: [
1286
+ "context",
1287
+ ""
1288
+ ]
1289
+ });
1290
+ return context;
1291
+ };
1292
+ var SheetProviderImpl = ({ model, onInfo, children, __gridScope }) => {
1293
+ const { id, editing, setEditing } = useGridContext("SheetProvider", __gridScope);
1294
+ const decorations = useMemo2(() => createDecorations(), []);
1295
+ const [cursor, setCursor] = useState3();
1296
+ const [range, setRange] = useState3();
1297
+ useSelectThreadOnCellFocus(model, cursor);
1298
+ useThreadDecorations(model, decorations);
1299
+ return /* @__PURE__ */ React2.createElement(SheetContext.Provider, {
1300
+ value: {
1301
+ id,
1302
+ model,
1303
+ editing,
1304
+ setEditing,
1305
+ cursor,
1306
+ setCursor,
1307
+ range,
1308
+ setRange,
1309
+ // TODO(burdon): Change to event.
1310
+ onInfo,
1311
+ decorations
1312
+ }
1313
+ }, children);
1314
+ };
1315
+ var SheetProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1316
+ const model = useSheetModel(graph, sheet, {
1317
+ readonly
1318
+ });
1319
+ return !model ? null : /* @__PURE__ */ React2.createElement(Grid.Root, {
1320
+ id: fullyQualifiedId2(sheet)
1321
+ }, /* @__PURE__ */ React2.createElement(SheetProviderImpl, {
1322
+ model,
1323
+ onInfo
1324
+ }, children));
1325
+ };
1326
+
1327
+ // packages/plugins/plugin-sheet/src/components/GridSheet/GridSheet.tsx
1328
+ var initialCells = {
1329
+ grid: {},
1330
+ frozenColsStart: [
1331
+ ...Array(64)
1332
+ ].reduce((acc, _, i) => {
1333
+ acc[`0,${i}`] = rowLabelCell(i);
1334
+ return acc;
1335
+ }, {}),
1336
+ frozenRowsStart: [
1337
+ ...Array(12)
1338
+ ].reduce((acc, _, i) => {
1339
+ acc[`${i},0`] = colLabelCell(i);
1340
+ return acc;
1341
+ }, {})
1342
+ };
1343
+ var frozen = {
1344
+ frozenColsStart: 1,
1345
+ frozenRowsStart: 1
1346
+ };
1347
+ var sheetRowDefault = {
1348
+ frozenRowsStart: {
1349
+ size: 32,
1350
+ readonly: true
1351
+ },
1352
+ grid: {
1353
+ size: 32,
1354
+ resizeable: true
1355
+ }
1356
+ };
1357
+ var sheetColDefault = {
1358
+ frozenColsStart: {
1359
+ size: 48,
1360
+ readonly: true
1361
+ },
1362
+ grid: {
1363
+ size: 180,
1364
+ resizeable: true
1365
+ }
1366
+ };
1367
+ var GridSheet = () => {
1368
+ const { id, model, editing, setEditing, setCursor, setRange, range, cursor } = 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 range2 = {
1424
+ from: {
1425
+ col: minCol,
1426
+ row: minRow
1427
+ }
1428
+ };
1429
+ if (minCol !== maxCol || minRow !== maxRow) {
1430
+ range2.to = {
1431
+ col: maxCol,
1432
+ row: maxRow
1433
+ };
1434
+ }
1435
+ if (editing) {
1436
+ rangeNotifier.current?.(rangeToA1Notation(range2));
1437
+ } else {
1438
+ setRange(range2.to ? range2 : 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 handleKeyDown = useCallback2((event) => {
1451
+ const cursorFallbackRange = range ?? cursor ? {
1452
+ from: cursor,
1453
+ to: cursor
1454
+ } : null;
1455
+ switch (event.key) {
1456
+ case "Backspace":
1457
+ case "Delete":
1458
+ event.preventDefault();
1459
+ return cursorFallbackRange && model.clear(cursorFallbackRange);
1460
+ }
1461
+ if (event.metaKey || event.ctrlKey) {
1462
+ switch (event.key) {
1463
+ case "x":
1464
+ case "X":
1465
+ event.preventDefault();
1466
+ return cursorFallbackRange && model.cut(cursorFallbackRange);
1467
+ case "c":
1468
+ case "C":
1469
+ event.preventDefault();
1470
+ return cursorFallbackRange && model.copy(cursorFallbackRange);
1471
+ case "v":
1472
+ case "V":
1473
+ event.preventDefault();
1474
+ return cursor && model.paste(cursor);
1475
+ case "z":
1476
+ event.preventDefault();
1477
+ return event.shiftKey ? model.redo() : model.undo();
1478
+ case "Z":
1479
+ case "y":
1480
+ event.preventDefault();
1481
+ return model.redo();
1482
+ }
1483
+ }
1484
+ }, [
1485
+ range,
1486
+ model,
1487
+ cursor
1488
+ ]);
1489
+ const { columns, rows } = useSheetModelDxGridProps(dxGrid, model);
1490
+ const extension = useMemo3(() => [
1491
+ editorKeys({
1492
+ onClose: handleClose,
1493
+ ...editing?.initialContent && {
1494
+ onNav: handleClose
1495
+ }
1496
+ }),
1497
+ sheetExtension({
1498
+ functions: model.graph.getFunctions()
1499
+ }),
1500
+ rangeExtension((fn) => rangeNotifier.current = fn)
1501
+ ], [
1502
+ model,
1503
+ handleClose,
1504
+ editing
1505
+ ]);
1506
+ const getCellContent = useCallback2((index) => {
1507
+ const cell = dxGridCellIndexToSheetCellAddress(index);
1508
+ return model.getCellText(cell);
1509
+ }, [
1510
+ model
1511
+ ]);
1512
+ useUpdateFocusedCellOnThreadSelection(model, dxGrid);
1513
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(GridCellEditor, {
1514
+ getCellContent,
1515
+ extension
1516
+ }), /* @__PURE__ */ React3.createElement(Grid2.Content, {
1517
+ initialCells,
1518
+ limitColumns: DEFAULT_COLUMNS,
1519
+ limitRows: DEFAULT_ROWS,
1520
+ columns,
1521
+ rows,
1522
+ onAxisResize: handleAxisResize,
1523
+ onSelect: handleSelect,
1524
+ rowDefault: sheetRowDefault,
1525
+ columnDefault: sheetColDefault,
1526
+ frozen,
1527
+ onFocus: handleFocus,
1528
+ onWheelCapture: handleWheel,
1529
+ onKeyDown: handleKeyDown,
1530
+ overscroll: "inline",
1531
+ className: "[--dx-grid-base:var(--surface-bg)]",
1532
+ ref: dxGrid
1533
+ }));
1534
+ };
1535
+
1536
+ // packages/plugins/plugin-sheet/src/components/index.ts
1537
+ var SheetContainer = lazy(() => import("./SheetContainer-AKWROARP.mjs"));
1538
+
1539
+ // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
1540
+ var useComputeGraph = (space) => {
1541
+ const { registry } = useContext2(ComputeGraphContext) ?? raise(new Error("Missing ComputeGraphContext"));
1542
+ const [graph] = useAsyncState(async () => {
1543
+ if (space) {
1544
+ const graph2 = registry.getOrCreateGraph(space);
1545
+ await graph2.open();
1546
+ return graph2;
1547
+ }
1548
+ }, [
1549
+ space,
1550
+ registry
1551
+ ]);
1552
+ return graph;
1553
+ };
1554
+
1555
+ export {
1556
+ ComputeGraphContextProvider,
1557
+ addressToA1Notation,
1558
+ rangeToA1Notation,
1559
+ inRange,
1560
+ createSheet,
1561
+ addressToIndex,
1562
+ compareIndexPositions,
1563
+ computeGraphFacet,
1564
+ useComputeGraph,
1565
+ useSheetContext,
1566
+ SheetProvider,
1567
+ GridSheet,
1568
+ SheetContainer
1569
+ };
1570
+ //# sourceMappingURL=chunk-FGMFOW6U.mjs.map