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

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