@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,1571 @@
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 { lazy } 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
+ cachedGridCells[`${col},${row}`] = projectCellProps(model, col, row);
509
+ });
510
+ });
511
+ return cachedGridCells;
512
+ };
513
+ };
514
+ var rowLabelCell = (row) => ({
515
+ value: rowToA1Notation(row),
516
+ className: "text-end !pie-1",
517
+ resizeHandle: "row"
518
+ });
519
+ var colLabelCell = (col) => ({
520
+ value: colToA1Notation(col),
521
+ resizeHandle: "col"
522
+ });
523
+ var cellGetter = (model) => {
524
+ const getGridCells = gridCellGetter(model);
525
+ return (nextBounds, plane) => {
526
+ switch (plane) {
527
+ case "grid":
528
+ return getGridCells(nextBounds);
529
+ case "frozenColsStart":
530
+ return [
531
+ ...Array(nextBounds.end.row - nextBounds.start.row)
532
+ ].reduce((acc, _, r0) => {
533
+ const r = nextBounds.start.row + r0;
534
+ acc[`0,${r}`] = rowLabelCell(r);
535
+ return acc;
536
+ }, {});
537
+ case "frozenRowsStart":
538
+ return [
539
+ ...Array(nextBounds.end.col - nextBounds.start.col)
540
+ ].reduce((acc, _, c0) => {
541
+ const c = nextBounds.start.col + c0;
542
+ acc[`${c},0`] = colLabelCell(c);
543
+ return acc;
544
+ }, {});
545
+ default:
546
+ return {};
547
+ }
548
+ };
549
+ };
550
+ var useSheetModelDxGridProps = (dxGridRef, model) => {
551
+ const [columns, setColumns] = useState(createDxGridColumns(model));
552
+ const [rows, setRows] = useState(createDxGridColumns(model));
553
+ useLayoutEffect(() => {
554
+ const cellsAccessor = createDocAccessor(model.sheet, [
555
+ "cells"
556
+ ]);
557
+ if (dxGridRef.current) {
558
+ dxGridRef.current.getCells = cellGetter(model);
559
+ }
560
+ const handleCellsUpdate = () => {
561
+ dxGridRef.current?.requestUpdate("initialCells");
562
+ };
563
+ cellsAccessor.handle.addListener("change", handleCellsUpdate);
564
+ return () => cellsAccessor.handle.removeListener("change", handleCellsUpdate);
565
+ }, [
566
+ model
567
+ ]);
568
+ useEffect(() => {
569
+ const columnMetaAccessor = createDocAccessor(model.sheet, [
570
+ "columnMeta"
571
+ ]);
572
+ const rowMetaAccessor = createDocAccessor(model.sheet, [
573
+ "rowMeta"
574
+ ]);
575
+ const handleColumnMetaUpdate = () => {
576
+ setColumns(createDxGridColumns(model));
577
+ };
578
+ const handleRowMetaUpdate = () => {
579
+ setRows(createDxGridRows(model));
580
+ };
581
+ columnMetaAccessor.handle.addListener("change", handleColumnMetaUpdate);
582
+ rowMetaAccessor.handle.addListener("change", handleRowMetaUpdate);
583
+ return () => {
584
+ columnMetaAccessor.handle.removeListener("change", handleColumnMetaUpdate);
585
+ rowMetaAccessor.handle.removeListener("change", handleRowMetaUpdate);
586
+ };
587
+ }, [
588
+ model
589
+ ]);
590
+ return {
591
+ columns,
592
+ rows
593
+ };
594
+ };
595
+
596
+ // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
597
+ import { useEffect as useEffect2, useState as useState2 } from "react";
598
+
599
+ // packages/plugins/plugin-sheet/src/model/decorations.ts
600
+ import { create as create2 } from "@dxos/echo-schema";
601
+ var createDecorations = () => {
602
+ const { decorations } = create2({
603
+ decorations: {}
604
+ });
605
+ const addDecoration = (cellIndex, decorator) => {
606
+ decorations[cellIndex] = [
607
+ ...decorations[cellIndex] || [],
608
+ decorator
609
+ ];
610
+ };
611
+ const removeDecoration = (cellIndex, type) => {
612
+ if (type) {
613
+ decorations[cellIndex] = (decorations[cellIndex] || []).filter((d) => d.type !== type);
614
+ } else {
615
+ delete decorations[cellIndex];
616
+ }
617
+ };
618
+ const getDecorationsForCell = (cellIndex) => {
619
+ return decorations[cellIndex];
620
+ };
621
+ const getAllDecorations = () => {
622
+ const result = [];
623
+ for (const decoratorArray of Object.values(decorations)) {
624
+ for (const decorator of decoratorArray) {
625
+ result.push(decorator);
626
+ }
627
+ }
628
+ return result;
629
+ };
630
+ return {
631
+ addDecoration,
632
+ removeDecoration,
633
+ getDecorationsForCell,
634
+ getAllDecorations
635
+ };
636
+ };
637
+
638
+ // packages/plugins/plugin-sheet/src/model/sheet-model.ts
639
+ import { Event } from "@dxos/async";
640
+ import { Resource } from "@dxos/context";
641
+ import { getTypename } from "@dxos/echo-schema";
642
+ import { invariant as invariant3 } from "@dxos/invariant";
643
+ import { PublicKey } from "@dxos/keys";
644
+ import { log } from "@dxos/log";
645
+ import { FieldValueType } from "@dxos/schema";
646
+ import { DetailedCellError, ExportedCellChange } from "#hyperformula";
647
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
648
+ var typeMap = {
649
+ BOOLEAN: FieldValueType.Boolean,
650
+ NUMBER_RAW: FieldValueType.Number,
651
+ NUMBER_PERCENT: FieldValueType.Percent,
652
+ NUMBER_CURRENCY: FieldValueType.Currency,
653
+ NUMBER_DATETIME: FieldValueType.DateTime,
654
+ NUMBER_DATE: FieldValueType.Date,
655
+ NUMBER_TIME: FieldValueType.Time
656
+ };
657
+ var getTopLeft = (range) => {
658
+ const to = range.to ?? range.from;
659
+ return {
660
+ row: Math.min(range.from.row, to.row),
661
+ col: Math.min(range.from.col, to.col)
662
+ };
663
+ };
664
+ var toSimpleCellAddress = (sheet, cell) => ({
665
+ sheet,
666
+ row: cell.row,
667
+ col: cell.col
668
+ });
669
+ var toModelRange = (sheet, range) => ({
670
+ start: toSimpleCellAddress(sheet, range.from),
671
+ end: toSimpleCellAddress(sheet, range.to ?? range.from)
672
+ });
673
+ var SheetModel = class extends Resource {
674
+ constructor(_graph, _sheet, _options = {}) {
675
+ super();
676
+ this._graph = _graph;
677
+ this._sheet = _sheet;
678
+ this._options = _options;
679
+ this.id = `model-${PublicKey.random().truncate()}`;
680
+ this.update = new Event();
681
+ }
682
+ get graph() {
683
+ return this._graph;
684
+ }
685
+ get sheet() {
686
+ return this._sheet;
687
+ }
688
+ get readonly() {
689
+ return this._options.readonly;
690
+ }
691
+ get bounds() {
692
+ return {
693
+ rows: this._sheet.rows.length,
694
+ columns: this._sheet.columns.length
695
+ };
696
+ }
697
+ /**
698
+ * Initialize sheet and engine.
699
+ */
700
+ async _open() {
701
+ log("initialize", {
702
+ id: this.id
703
+ }, {
704
+ F: __dxlog_file2,
705
+ L: 106,
706
+ S: this,
707
+ C: (f, a) => f(...a)
708
+ });
709
+ initialize(this._sheet);
710
+ this._node = this._graph.getOrCreateNode(createSheetName({
711
+ type: getTypename(this._sheet),
712
+ id: this._sheet.id
713
+ }));
714
+ await this._node.open();
715
+ const unsubscribe = this._node.update.on((event) => this.update.emit(event));
716
+ this._ctx.onDispose(unsubscribe);
717
+ this.reset();
718
+ }
719
+ /**
720
+ * Update engine.
721
+ * NOTE: This resets the undo history.
722
+ * @deprecated
723
+ */
724
+ reset() {
725
+ invariant3(this._node, void 0, {
726
+ F: __dxlog_file2,
727
+ L: 126,
728
+ S: this,
729
+ A: [
730
+ "this._node",
731
+ ""
732
+ ]
733
+ });
734
+ this._node.graph.hf.clearSheet(this._node.sheetId);
735
+ Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
736
+ invariant3(this._node, void 0, {
737
+ F: __dxlog_file2,
738
+ L: 129,
739
+ S: this,
740
+ A: [
741
+ "this._node",
742
+ ""
743
+ ]
744
+ });
745
+ const { col, row } = addressFromIndex(this._sheet, key);
746
+ if (typeof value === "string" && value.charAt(0) === "=") {
747
+ value = this._graph.mapFormulaToNative(this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)));
748
+ }
749
+ this._node.graph.hf.setCellContents({
750
+ sheet: this._node.sheetId,
751
+ row,
752
+ col
753
+ }, value);
754
+ });
755
+ }
756
+ /**
757
+ * Recalculate formulas.
758
+ * NOTE: This resets the undo history.
759
+ * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
760
+ * @deprecated
761
+ */
762
+ // TODO(burdon): Remove.
763
+ recalculate() {
764
+ this._node?.graph.hf.rebuildAndRecalculate();
765
+ }
766
+ insertRows(i, n = 1) {
767
+ insertIndices(this._sheet.rows, i, n, MAX_ROWS);
768
+ this.reset();
769
+ }
770
+ insertColumns(i, n = 1) {
771
+ insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
772
+ this.reset();
773
+ }
774
+ //
775
+ // Undoable actions.
776
+ // TODO(burdon): Group undoable methods; consistently update hf/sheet.
777
+ //
778
+ /**
779
+ * Clear range of values.
780
+ */
781
+ clear(range) {
782
+ invariant3(this._node, void 0, {
783
+ F: __dxlog_file2,
784
+ L: 171,
785
+ S: this,
786
+ A: [
787
+ "this._node",
788
+ ""
789
+ ]
790
+ });
791
+ const topLeft = getTopLeft(range);
792
+ const values = this._iterRange(range, () => null);
793
+ this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
794
+ this._iterRange(range, (cell) => {
795
+ const idx = addressToIndex(this._sheet, cell);
796
+ delete this._sheet.cells[idx];
797
+ });
798
+ }
799
+ cut(range) {
800
+ invariant3(this._node, void 0, {
801
+ F: __dxlog_file2,
802
+ L: 182,
803
+ S: this,
804
+ A: [
805
+ "this._node",
806
+ ""
807
+ ]
808
+ });
809
+ this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
810
+ this._iterRange(range, (cell) => {
811
+ const idx = addressToIndex(this._sheet, cell);
812
+ delete this._sheet.cells[idx];
813
+ });
814
+ }
815
+ copy(range) {
816
+ invariant3(this._node, void 0, {
817
+ F: __dxlog_file2,
818
+ L: 191,
819
+ S: this,
820
+ A: [
821
+ "this._node",
822
+ ""
823
+ ]
824
+ });
825
+ this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
826
+ }
827
+ paste(cell) {
828
+ invariant3(this._node, void 0, {
829
+ F: __dxlog_file2,
830
+ L: 196,
831
+ S: this,
832
+ A: [
833
+ "this._node",
834
+ ""
835
+ ]
836
+ });
837
+ if (!this._node.graph.hf.isClipboardEmpty()) {
838
+ const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
839
+ for (const change of changes) {
840
+ if (change instanceof ExportedCellChange) {
841
+ const { address, newValue } = change;
842
+ const idx = addressToIndex(this._sheet, {
843
+ row: address.row,
844
+ col: address.col
845
+ });
846
+ this._sheet.cells[idx] = {
847
+ value: newValue
848
+ };
849
+ }
850
+ }
851
+ }
852
+ }
853
+ // TODO(burdon): Display undo/redo state.
854
+ undo() {
855
+ invariant3(this._node, void 0, {
856
+ F: __dxlog_file2,
857
+ L: 211,
858
+ S: this,
859
+ A: [
860
+ "this._node",
861
+ ""
862
+ ]
863
+ });
864
+ if (this._node.graph.hf.isThereSomethingToUndo()) {
865
+ this._node.graph.hf.undo();
866
+ }
867
+ }
868
+ redo() {
869
+ invariant3(this._node, void 0, {
870
+ F: __dxlog_file2,
871
+ L: 219,
872
+ S: this,
873
+ A: [
874
+ "this._node",
875
+ ""
876
+ ]
877
+ });
878
+ if (this._node.graph.hf.isThereSomethingToRedo()) {
879
+ this._node.graph.hf.redo();
880
+ }
881
+ }
882
+ /**
883
+ * Get value from sheet.
884
+ */
885
+ getCellValue(cell) {
886
+ const idx = addressToIndex(this._sheet, cell);
887
+ return this._sheet.cells[idx]?.value ?? null;
888
+ }
889
+ /**
890
+ * Get value as a string for editing.
891
+ */
892
+ getCellText(cell) {
893
+ const value = this.getCellValue(cell);
894
+ if (value == null) {
895
+ return void 0;
896
+ }
897
+ if (typeof value === "string" && value.charAt(0) === "=") {
898
+ return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
899
+ } else {
900
+ return String(value);
901
+ }
902
+ }
903
+ /**
904
+ * Get array of raw values from sheet.
905
+ */
906
+ getCellValues(range) {
907
+ return this._iterRange(range, (cell) => this.getCellValue(cell));
908
+ }
909
+ /**
910
+ * Gets the regular or computed value from the engine.
911
+ */
912
+ getValue(cell) {
913
+ invariant3(this._node, void 0, {
914
+ F: __dxlog_file2,
915
+ L: 262,
916
+ S: this,
917
+ A: [
918
+ "this._node",
919
+ ""
920
+ ]
921
+ });
922
+ const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
923
+ if (value instanceof DetailedCellError) {
924
+ return value.toString();
925
+ }
926
+ return value;
927
+ }
928
+ /**
929
+ * Get value type.
930
+ */
931
+ getValueType(cell) {
932
+ invariant3(this._node, void 0, {
933
+ F: __dxlog_file2,
934
+ L: 275,
935
+ S: this,
936
+ A: [
937
+ "this._node",
938
+ ""
939
+ ]
940
+ });
941
+ const addr = toSimpleCellAddress(this._node.sheetId, cell);
942
+ const type = this._node.graph.hf.getCellValueDetailedType(addr);
943
+ return typeMap[type];
944
+ }
945
+ /**
946
+ * Sets the value, updating the sheet and engine.
947
+ */
948
+ setValue(cell, value) {
949
+ invariant3(this._node, void 0, {
950
+ F: __dxlog_file2,
951
+ L: 285,
952
+ S: this,
953
+ A: [
954
+ "this._node",
955
+ ""
956
+ ]
957
+ });
958
+ if (this._options.readonly) {
959
+ throw new ReadonlyException();
960
+ }
961
+ let refresh = false;
962
+ if (cell.row >= this._sheet.rows.length) {
963
+ insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
964
+ refresh = true;
965
+ }
966
+ if (cell.col >= this._sheet.columns.length) {
967
+ insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
968
+ refresh = true;
969
+ }
970
+ if (refresh) {
971
+ this.reset();
972
+ }
973
+ this._node.graph.hf.setCellContents({
974
+ sheet: this._node.sheetId,
975
+ row: cell.row,
976
+ col: cell.col
977
+ }, [
978
+ [
979
+ typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value
980
+ ]
981
+ ]);
982
+ const idx = addressToIndex(this._sheet, cell);
983
+ if (value === void 0 || value === null) {
984
+ delete this._sheet.cells[idx];
985
+ } else {
986
+ if (typeof value === "string" && value.charAt(0) === "=") {
987
+ value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
988
+ }
989
+ this._sheet.cells[idx] = {
990
+ value
991
+ };
992
+ }
993
+ }
994
+ /**
995
+ * Sets values from a simple map.
996
+ */
997
+ setValues(values) {
998
+ Object.entries(values).forEach(([key, { value }]) => {
999
+ this.setValue(addressFromA1Notation(key), value);
1000
+ });
1001
+ }
1002
+ /**
1003
+ * Iterate range.
1004
+ */
1005
+ _iterRange(range, cb) {
1006
+ const to = range.to ?? range.from;
1007
+ const rowRange = [
1008
+ Math.min(range.from.row, to.row),
1009
+ Math.max(range.from.row, to.row)
1010
+ ];
1011
+ const columnRange = [
1012
+ Math.min(range.from.col, to.col),
1013
+ Math.max(range.from.col, to.col)
1014
+ ];
1015
+ const rows = [];
1016
+ for (let row = rowRange[0]; row <= rowRange[1]; row++) {
1017
+ const rowCells = [];
1018
+ for (let column = columnRange[0]; column <= columnRange[1]; column++) {
1019
+ const value = cb({
1020
+ row,
1021
+ col: column
1022
+ });
1023
+ if (value !== void 0) {
1024
+ rowCells.push(value);
1025
+ }
1026
+ }
1027
+ rows.push(rowCells);
1028
+ }
1029
+ return rows;
1030
+ }
1031
+ // TODO(burdon): Delete index.
1032
+ _deleteIndices(indices, i, n) {
1033
+ throw new Error("Not implemented");
1034
+ }
1035
+ // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
1036
+ _moveIndices(indices, i, j, n) {
1037
+ throw new Error("Not implemented");
1038
+ }
1039
+ //
1040
+ // Indices.
1041
+ //
1042
+ /**
1043
+ * Map from A1 notation to indices.
1044
+ */
1045
+ mapFormulaRefsToIndices(formula) {
1046
+ invariant3(formula.charAt(0) === "=", void 0, {
1047
+ F: __dxlog_file2,
1048
+ L: 374,
1049
+ S: this,
1050
+ A: [
1051
+ "formula.charAt(0) === '='",
1052
+ ""
1053
+ ]
1054
+ });
1055
+ return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
1056
+ return addressToIndex(this._sheet, addressFromA1Notation(match));
1057
+ });
1058
+ }
1059
+ /**
1060
+ * Map from indices to A1 notation.
1061
+ */
1062
+ mapFormulaIndicesToRefs(formula) {
1063
+ invariant3(formula.charAt(0) === "=", void 0, {
1064
+ F: __dxlog_file2,
1065
+ L: 384,
1066
+ S: this,
1067
+ A: [
1068
+ "formula.charAt(0) === '='",
1069
+ ""
1070
+ ]
1071
+ });
1072
+ return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
1073
+ return addressToA1Notation(addressFromIndex(this._sheet, idx));
1074
+ });
1075
+ }
1076
+ //
1077
+ // Values
1078
+ //
1079
+ /**
1080
+ * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
1081
+ * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
1082
+ * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
1083
+ */
1084
+ toLocalDate(num) {
1085
+ const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
1086
+ return new Date(year, month - 1, day, hours, minutes, seconds);
1087
+ }
1088
+ toDateTime(num) {
1089
+ invariant3(this._node, void 0, {
1090
+ F: __dxlog_file2,
1091
+ L: 405,
1092
+ S: this,
1093
+ A: [
1094
+ "this._node",
1095
+ ""
1096
+ ]
1097
+ });
1098
+ return this._node.graph.hf.numberToDateTime(num);
1099
+ }
1100
+ toDate(num) {
1101
+ invariant3(this._node, void 0, {
1102
+ F: __dxlog_file2,
1103
+ L: 410,
1104
+ S: this,
1105
+ A: [
1106
+ "this._node",
1107
+ ""
1108
+ ]
1109
+ });
1110
+ return this._node.graph.hf.numberToDate(num);
1111
+ }
1112
+ toTime(num) {
1113
+ invariant3(this._node, void 0, {
1114
+ F: __dxlog_file2,
1115
+ L: 415,
1116
+ S: this,
1117
+ A: [
1118
+ "this._node",
1119
+ ""
1120
+ ]
1121
+ });
1122
+ return this._node.graph.hf.numberToTime(num);
1123
+ }
1124
+ };
1125
+
1126
+ // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
1127
+ var useSheetModel = (graph, sheet, { readonly } = {}) => {
1128
+ const [model, setModel] = useState2();
1129
+ useEffect2(() => {
1130
+ if (!graph || !sheet) {
1131
+ return;
1132
+ }
1133
+ let model2;
1134
+ const t = setTimeout(async () => {
1135
+ model2 = new SheetModel(graph, sheet, {
1136
+ readonly
1137
+ });
1138
+ await model2.open();
1139
+ setModel(model2);
1140
+ });
1141
+ return () => {
1142
+ clearTimeout(t);
1143
+ void model2?.close();
1144
+ };
1145
+ }, [
1146
+ graph,
1147
+ sheet,
1148
+ readonly
1149
+ ]);
1150
+ return model;
1151
+ };
1152
+
1153
+ // packages/plugins/plugin-sheet/src/hooks/threads.ts
1154
+ import { effect } from "@preact/signals-core";
1155
+ import { useCallback, useEffect as useEffect3, useMemo } from "react";
1156
+ import { LayoutAction, useIntentDispatcher, useIntentResolver } from "@dxos/app-framework";
1157
+ import { debounce as debounce2 } from "@dxos/async";
1158
+ import { fullyQualifiedId } from "@dxos/react-client/echo";
1159
+ var useUpdateFocusedCellOnThreadSelection = (model, grid) => {
1160
+ const handleScrollIntoView = useCallback(({ action, data }) => {
1161
+ switch (action) {
1162
+ case LayoutAction.SCROLL_INTO_VIEW: {
1163
+ if (!data?.id || data?.cursor === void 0 || data?.id !== fullyQualifiedId(model.sheet)) {
1164
+ return;
1165
+ }
1166
+ const cellAddress = addressFromIndex(model.sheet, data.cursor);
1167
+ grid.current?.setFocus({
1168
+ ...cellAddress,
1169
+ plane: "grid"
1170
+ }, true);
1171
+ }
1172
+ }
1173
+ }, [
1174
+ model.sheet
1175
+ ]);
1176
+ useIntentResolver(SHEET_PLUGIN, handleScrollIntoView);
1177
+ };
1178
+ var useSelectThreadOnCellFocus = (model, cursor) => {
1179
+ const dispatch = useIntentDispatcher();
1180
+ const activeThreads = useMemo(() => model.sheet.threads?.filter((thread) => !!thread && thread.status === "active") ?? [], [
1181
+ // TODO(thure): Surely we can find a better dependency for this…
1182
+ JSON.stringify(model.sheet.threads)
1183
+ ]);
1184
+ const activeThreadAddresses = useMemo(() => activeThreads.map((thread) => thread.anchor).filter((anchor) => anchor !== void 0).map((anchor) => addressFromIndex(model.sheet, anchor)), [
1185
+ activeThreads,
1186
+ model.sheet
1187
+ ]);
1188
+ const selectClosestThread = useCallback((cellAddress) => {
1189
+ if (!cellAddress || !activeThreads) {
1190
+ return;
1191
+ }
1192
+ const closestThreadAnchor = closest(cellAddress, activeThreadAddresses);
1193
+ if (closestThreadAnchor) {
1194
+ const closestThread = activeThreads.find((thread) => thread && thread.anchor === addressToIndex(model.sheet, closestThreadAnchor));
1195
+ if (closestThread) {
1196
+ void dispatch([
1197
+ {
1198
+ action: "dxos.org/plugin/thread/action/select",
1199
+ data: {
1200
+ current: fullyQualifiedId(closestThread)
1201
+ }
1202
+ }
1203
+ ]);
1204
+ }
1205
+ }
1206
+ }, [
1207
+ dispatch,
1208
+ activeThreads,
1209
+ activeThreadAddresses,
1210
+ model.sheet
1211
+ ]);
1212
+ const debounced = useMemo(() => {
1213
+ return debounce2((cellCoords) => requestAnimationFrame(() => selectClosestThread(cellCoords)), 50);
1214
+ }, [
1215
+ selectClosestThread
1216
+ ]);
1217
+ useEffect3(() => {
1218
+ if (!cursor) {
1219
+ return;
1220
+ }
1221
+ debounced(cursor);
1222
+ }, [
1223
+ cursor,
1224
+ selectClosestThread
1225
+ ]);
1226
+ };
1227
+ var createThreadDecoration = (cellIndex, threadId, sheetId) => {
1228
+ return {
1229
+ type: "comment",
1230
+ classNames: [
1231
+ "bg-greenFill"
1232
+ ],
1233
+ cellIndex
1234
+ };
1235
+ };
1236
+ var useThreadDecorations = (model, decorations) => {
1237
+ const sheet = useMemo(() => model.sheet, [
1238
+ model.sheet
1239
+ ]);
1240
+ const sheetId = useMemo(() => fullyQualifiedId(sheet), [
1241
+ sheet
1242
+ ]);
1243
+ useEffect3(() => {
1244
+ const unsubscribe = effect(() => {
1245
+ const activeThreadAnchors = /* @__PURE__ */ new Set();
1246
+ if (!sheet.threads) {
1247
+ return;
1248
+ }
1249
+ for (const thread of sheet.threads) {
1250
+ if (!thread || thread.anchor === void 0 || thread.status === "resolved") {
1251
+ continue;
1252
+ }
1253
+ activeThreadAnchors.add(thread.anchor);
1254
+ const index = thread.anchor;
1255
+ const existingDecorations = decorations.getDecorationsForCell(index);
1256
+ if (!existingDecorations || !existingDecorations.some((d) => d.type === "comment")) {
1257
+ decorations.addDecoration(index, createThreadDecoration(index, thread.id, sheetId));
1258
+ }
1259
+ }
1260
+ for (const decoration of decorations.getAllDecorations()) {
1261
+ if (decoration.type !== "comment") {
1262
+ continue;
1263
+ }
1264
+ if (!activeThreadAnchors.has(decoration.cellIndex)) {
1265
+ decorations.removeDecoration(decoration.cellIndex, "comment");
1266
+ }
1267
+ }
1268
+ });
1269
+ return () => unsubscribe();
1270
+ });
1271
+ };
1272
+
1273
+ // packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx
1274
+ import React2, { createContext as createContext2, useContext, useMemo as useMemo2, useState as useState3 } from "react";
1275
+ import { invariant as invariant4 } from "@dxos/invariant";
1276
+ import { fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
1277
+ import { Grid, useGridContext } from "@dxos/react-ui-grid";
1278
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx";
1279
+ var SheetContext = /* @__PURE__ */ createContext2(void 0);
1280
+ var useSheetContext = () => {
1281
+ const context = useContext(SheetContext);
1282
+ invariant4(context, void 0, {
1283
+ F: __dxlog_file3,
1284
+ L: 45,
1285
+ S: void 0,
1286
+ A: [
1287
+ "context",
1288
+ ""
1289
+ ]
1290
+ });
1291
+ return context;
1292
+ };
1293
+ var SheetProviderImpl = ({ model, onInfo, children, __gridScope }) => {
1294
+ const { id, editing, setEditing } = useGridContext("SheetProvider", __gridScope);
1295
+ const decorations = useMemo2(() => createDecorations(), []);
1296
+ const [cursor, setCursor] = useState3();
1297
+ const [range, setRange] = useState3();
1298
+ useSelectThreadOnCellFocus(model, cursor);
1299
+ useThreadDecorations(model, decorations);
1300
+ return /* @__PURE__ */ React2.createElement(SheetContext.Provider, {
1301
+ value: {
1302
+ id,
1303
+ model,
1304
+ editing,
1305
+ setEditing,
1306
+ cursor,
1307
+ setCursor,
1308
+ range,
1309
+ setRange,
1310
+ // TODO(burdon): Change to event.
1311
+ onInfo,
1312
+ decorations
1313
+ }
1314
+ }, children);
1315
+ };
1316
+ var SheetProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1317
+ const model = useSheetModel(graph, sheet, {
1318
+ readonly
1319
+ });
1320
+ return !model ? null : /* @__PURE__ */ React2.createElement(Grid.Root, {
1321
+ id: fullyQualifiedId2(sheet)
1322
+ }, /* @__PURE__ */ React2.createElement(SheetProviderImpl, {
1323
+ model,
1324
+ onInfo
1325
+ }, children));
1326
+ };
1327
+
1328
+ // packages/plugins/plugin-sheet/src/components/GridSheet/GridSheet.tsx
1329
+ var initialCells = {
1330
+ grid: {},
1331
+ frozenColsStart: [
1332
+ ...Array(64)
1333
+ ].reduce((acc, _, i) => {
1334
+ acc[`0,${i}`] = rowLabelCell(i);
1335
+ return acc;
1336
+ }, {}),
1337
+ frozenRowsStart: [
1338
+ ...Array(12)
1339
+ ].reduce((acc, _, i) => {
1340
+ acc[`${i},0`] = colLabelCell(i);
1341
+ return acc;
1342
+ }, {})
1343
+ };
1344
+ var frozen = {
1345
+ frozenColsStart: 1,
1346
+ frozenRowsStart: 1
1347
+ };
1348
+ var sheetRowDefault = {
1349
+ frozenRowsStart: {
1350
+ size: 32,
1351
+ readonly: true
1352
+ },
1353
+ grid: {
1354
+ size: 32,
1355
+ resizeable: true
1356
+ }
1357
+ };
1358
+ var sheetColDefault = {
1359
+ frozenColsStart: {
1360
+ size: 48,
1361
+ readonly: true
1362
+ },
1363
+ grid: {
1364
+ size: 180,
1365
+ resizeable: true
1366
+ }
1367
+ };
1368
+ var GridSheet = () => {
1369
+ const { id, model, editing, setEditing, setCursor, setRange, range, cursor } = useSheetContext();
1370
+ const dxGrid = useRef(null);
1371
+ const rangeNotifier = useRef();
1372
+ const { hasAttention } = useAttention(id);
1373
+ const handleFocus = useCallback2((event) => {
1374
+ if (!editing) {
1375
+ const cell = closestCell(event.target);
1376
+ if (cell && cell.plane === "grid") {
1377
+ setCursor({
1378
+ col: cell.col,
1379
+ row: cell.row
1380
+ });
1381
+ }
1382
+ }
1383
+ }, [
1384
+ editing
1385
+ ]);
1386
+ const handleClose = useCallback2((value, { key, shift }) => {
1387
+ if (value !== void 0) {
1388
+ model.setValue(dxGridCellIndexToSheetCellAddress(editing.index), value);
1389
+ }
1390
+ setEditing(null);
1391
+ const axis = [
1392
+ "Enter",
1393
+ "ArrowUp",
1394
+ "ArrowDown"
1395
+ ].includes(key) ? "row" : [
1396
+ "Tab",
1397
+ "ArrowLeft",
1398
+ "ArrowRight"
1399
+ ].includes(key) ? "col" : void 0;
1400
+ const delta = key.startsWith("Arrow") ? [
1401
+ "ArrowUp",
1402
+ "ArrowLeft"
1403
+ ].includes(key) ? -1 : 1 : shift ? -1 : 1;
1404
+ dxGrid.current?.refocus(axis, delta);
1405
+ }, [
1406
+ model,
1407
+ editing,
1408
+ setEditing
1409
+ ]);
1410
+ const handleAxisResize = useCallback2(({ axis, size, index: numericIndex }) => {
1411
+ if (axis === "row") {
1412
+ const rowId = model.sheet.rows[parseInt(numericIndex)];
1413
+ model.sheet.rowMeta[rowId] ??= {};
1414
+ model.sheet.rowMeta[rowId].size = size;
1415
+ } else {
1416
+ const columnId = model.sheet.columns[parseInt(numericIndex)];
1417
+ model.sheet.columnMeta[columnId] ??= {};
1418
+ model.sheet.columnMeta[columnId].size = size;
1419
+ }
1420
+ }, [
1421
+ model
1422
+ ]);
1423
+ const handleSelect = useCallback2(({ minCol, maxCol, minRow, maxRow }) => {
1424
+ const range2 = {
1425
+ from: {
1426
+ col: minCol,
1427
+ row: minRow
1428
+ }
1429
+ };
1430
+ if (minCol !== maxCol || minRow !== maxRow) {
1431
+ range2.to = {
1432
+ col: maxCol,
1433
+ row: maxRow
1434
+ };
1435
+ }
1436
+ if (editing) {
1437
+ rangeNotifier.current?.(rangeToA1Notation(range2));
1438
+ } else {
1439
+ setRange(range2.to ? range2 : void 0);
1440
+ }
1441
+ }, [
1442
+ editing
1443
+ ]);
1444
+ const handleWheel = useCallback2((event) => {
1445
+ if (!hasAttention) {
1446
+ event.stopPropagation();
1447
+ }
1448
+ }, [
1449
+ hasAttention
1450
+ ]);
1451
+ const handleKeyDown = useCallback2((event) => {
1452
+ const cursorFallbackRange = range ?? cursor ? {
1453
+ from: cursor,
1454
+ to: cursor
1455
+ } : null;
1456
+ switch (event.key) {
1457
+ case "Backspace":
1458
+ case "Delete":
1459
+ event.preventDefault();
1460
+ return cursorFallbackRange && model.clear(cursorFallbackRange);
1461
+ }
1462
+ if (event.metaKey || event.ctrlKey) {
1463
+ switch (event.key) {
1464
+ case "x":
1465
+ case "X":
1466
+ event.preventDefault();
1467
+ return cursorFallbackRange && model.cut(cursorFallbackRange);
1468
+ case "c":
1469
+ case "C":
1470
+ event.preventDefault();
1471
+ return cursorFallbackRange && model.copy(cursorFallbackRange);
1472
+ case "v":
1473
+ case "V":
1474
+ event.preventDefault();
1475
+ return cursor && model.paste(cursor);
1476
+ case "z":
1477
+ event.preventDefault();
1478
+ return event.shiftKey ? model.redo() : model.undo();
1479
+ case "Z":
1480
+ case "y":
1481
+ event.preventDefault();
1482
+ return model.redo();
1483
+ }
1484
+ }
1485
+ }, [
1486
+ range,
1487
+ model,
1488
+ cursor
1489
+ ]);
1490
+ const { columns, rows } = useSheetModelDxGridProps(dxGrid, model);
1491
+ const extension = useMemo3(() => [
1492
+ editorKeys({
1493
+ onClose: handleClose,
1494
+ ...editing?.initialContent && {
1495
+ onNav: handleClose
1496
+ }
1497
+ }),
1498
+ sheetExtension({
1499
+ functions: model.graph.getFunctions()
1500
+ }),
1501
+ rangeExtension((fn) => rangeNotifier.current = fn)
1502
+ ], [
1503
+ model,
1504
+ handleClose,
1505
+ editing
1506
+ ]);
1507
+ const getCellContent = useCallback2((index) => {
1508
+ const cell = dxGridCellIndexToSheetCellAddress(index);
1509
+ return model.getCellText(cell);
1510
+ }, [
1511
+ model
1512
+ ]);
1513
+ useUpdateFocusedCellOnThreadSelection(model, dxGrid);
1514
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(GridCellEditor, {
1515
+ getCellContent,
1516
+ extension
1517
+ }), /* @__PURE__ */ React3.createElement(Grid2.Content, {
1518
+ initialCells,
1519
+ limitColumns: DEFAULT_COLUMNS,
1520
+ limitRows: DEFAULT_ROWS,
1521
+ columns,
1522
+ rows,
1523
+ onAxisResize: handleAxisResize,
1524
+ onSelect: handleSelect,
1525
+ rowDefault: sheetRowDefault,
1526
+ columnDefault: sheetColDefault,
1527
+ frozen,
1528
+ onFocus: handleFocus,
1529
+ onWheelCapture: handleWheel,
1530
+ onKeyDown: handleKeyDown,
1531
+ overscroll: "inline",
1532
+ className: "[--dx-grid-base:var(--surface-bg)]",
1533
+ ref: dxGrid
1534
+ }));
1535
+ };
1536
+
1537
+ // packages/plugins/plugin-sheet/src/components/index.ts
1538
+ var SheetContainer = lazy(() => import("./SheetContainer-46PBMF2E.mjs"));
1539
+
1540
+ // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
1541
+ var useComputeGraph = (space) => {
1542
+ const { registry } = useContext2(ComputeGraphContext) ?? raise(new Error("Missing ComputeGraphContext"));
1543
+ const [graph] = useAsyncState(async () => {
1544
+ if (space) {
1545
+ const graph2 = registry.getOrCreateGraph(space);
1546
+ await graph2.open();
1547
+ return graph2;
1548
+ }
1549
+ }, [
1550
+ space,
1551
+ registry
1552
+ ]);
1553
+ return graph;
1554
+ };
1555
+
1556
+ export {
1557
+ ComputeGraphContextProvider,
1558
+ addressToA1Notation,
1559
+ rangeToA1Notation,
1560
+ inRange,
1561
+ createSheet,
1562
+ addressToIndex,
1563
+ compareIndexPositions,
1564
+ computeGraphFacet,
1565
+ useComputeGraph,
1566
+ useSheetContext,
1567
+ SheetProvider,
1568
+ GridSheet,
1569
+ SheetContainer
1570
+ };
1571
+ //# sourceMappingURL=chunk-T3PRH7QS.mjs.map