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