@dxos/plugin-sheet 0.6.12 → 0.6.13-main.548ca8d

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