@dxos/plugin-sheet 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae

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 (293) hide show
  1. package/dist/lib/browser/RangeList-S3SHV7T6.mjs +53 -0
  2. package/dist/lib/browser/RangeList-S3SHV7T6.mjs.map +7 -0
  3. package/dist/lib/browser/SheetContainer-I3NFVVDQ.mjs +1805 -0
  4. package/dist/lib/browser/SheetContainer-I3NFVVDQ.mjs.map +7 -0
  5. package/dist/lib/browser/anchor-sort-DZ3IHHJJ.mjs +24 -0
  6. package/dist/lib/browser/anchor-sort-DZ3IHHJJ.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-SSN4HYJL.mjs → chunk-NNWF7EKC.mjs} +17 -17
  8. package/dist/lib/browser/chunk-NNWF7EKC.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-S445OQGW.mjs +397 -0
  10. package/dist/lib/browser/chunk-S445OQGW.mjs.map +7 -0
  11. package/dist/lib/browser/compute-graph-registry-W6HO2G3P.mjs +21 -0
  12. package/dist/lib/browser/compute-graph-registry-W6HO2G3P.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +71 -80
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/markdown-S6GVLHB4.mjs +29 -0
  16. package/dist/lib/browser/markdown-S6GVLHB4.mjs.map +7 -0
  17. package/dist/lib/browser/meta.json +1 -1
  18. package/dist/lib/browser/operation-resolver-Z4X4UWNR.mjs +79 -0
  19. package/dist/lib/browser/operation-resolver-Z4X4UWNR.mjs.map +7 -0
  20. package/dist/lib/browser/react-surface-KIU6DGKW.mjs +51 -0
  21. package/dist/lib/browser/react-surface-KIU6DGKW.mjs.map +7 -0
  22. package/dist/lib/browser/types/index.mjs +7 -12
  23. package/dist/lib/node-esm/RangeList-IB23OJK2.mjs +54 -0
  24. package/dist/lib/node-esm/RangeList-IB23OJK2.mjs.map +7 -0
  25. package/dist/lib/node-esm/SheetContainer-KUXNCSFP.mjs +1806 -0
  26. package/dist/lib/node-esm/SheetContainer-KUXNCSFP.mjs.map +7 -0
  27. package/dist/lib/node-esm/anchor-sort-24OXMOSX.mjs +25 -0
  28. package/dist/lib/node-esm/anchor-sort-24OXMOSX.mjs.map +7 -0
  29. package/dist/lib/node-esm/{chunk-IK4O7FUJ.mjs → chunk-M52YLLWU.mjs} +17 -17
  30. package/dist/lib/node-esm/chunk-M52YLLWU.mjs.map +7 -0
  31. package/dist/lib/node-esm/chunk-NKZ3O4OR.mjs +398 -0
  32. package/dist/lib/node-esm/chunk-NKZ3O4OR.mjs.map +7 -0
  33. package/dist/lib/node-esm/compute-graph-registry-2C3Y2RPQ.mjs +22 -0
  34. package/dist/lib/node-esm/compute-graph-registry-2C3Y2RPQ.mjs.map +7 -0
  35. package/dist/lib/node-esm/index.mjs +71 -80
  36. package/dist/lib/node-esm/index.mjs.map +4 -4
  37. package/dist/lib/node-esm/markdown-YT5KJTQT.mjs +30 -0
  38. package/dist/lib/node-esm/markdown-YT5KJTQT.mjs.map +7 -0
  39. package/dist/lib/node-esm/meta.json +1 -1
  40. package/dist/lib/node-esm/operation-resolver-7VD2YXSQ.mjs +80 -0
  41. package/dist/lib/node-esm/operation-resolver-7VD2YXSQ.mjs.map +7 -0
  42. package/dist/lib/node-esm/react-surface-7FZAE3S7.mjs +52 -0
  43. package/dist/lib/node-esm/react-surface-7FZAE3S7.mjs.map +7 -0
  44. package/dist/lib/node-esm/types/index.mjs +7 -12
  45. package/dist/types/src/SheetPlugin.d.ts +2 -1
  46. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  47. package/dist/types/src/capabilities/anchor-sort/anchor-sort.d.ts +6 -0
  48. package/dist/types/src/capabilities/anchor-sort/anchor-sort.d.ts.map +1 -0
  49. package/dist/types/src/capabilities/anchor-sort/index.d.ts +3 -0
  50. package/dist/types/src/capabilities/anchor-sort/index.d.ts.map +1 -0
  51. package/dist/types/src/capabilities/compute-graph-registry/compute-graph-registry.d.ts +5 -0
  52. package/dist/types/src/capabilities/compute-graph-registry/compute-graph-registry.d.ts.map +1 -0
  53. package/dist/types/src/capabilities/compute-graph-registry/index.d.ts +3 -0
  54. package/dist/types/src/capabilities/compute-graph-registry/index.d.ts.map +1 -0
  55. package/dist/types/src/capabilities/index.d.ts +5 -9
  56. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  57. package/dist/types/src/capabilities/markdown/index.d.ts +3 -0
  58. package/dist/types/src/capabilities/markdown/index.d.ts.map +1 -0
  59. package/dist/types/src/capabilities/markdown/markdown.d.ts +5 -0
  60. package/dist/types/src/capabilities/markdown/markdown.d.ts.map +1 -0
  61. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  62. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  63. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  64. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  65. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  66. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  67. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  68. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  69. package/dist/types/src/components/Sheet/Sheet.d.ts +11 -0
  70. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
  71. package/dist/types/src/components/Sheet/index.d.ts +2 -0
  72. package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
  73. package/dist/types/src/components/{GridSheet → SheetContent}/SheetCellEditor.stories.d.ts +1 -1
  74. package/dist/types/src/components/SheetContent/SheetCellEditor.stories.d.ts.map +1 -0
  75. package/dist/types/src/components/SheetContent/SheetContent.d.ts +5 -0
  76. package/dist/types/src/components/SheetContent/SheetContent.d.ts.map +1 -0
  77. package/dist/types/src/components/{GridSheet/GridSheet.stories.d.ts → SheetContent/SheetContent.stories.d.ts} +5 -4
  78. package/dist/types/src/components/SheetContent/SheetContent.stories.d.ts.map +1 -0
  79. package/dist/types/src/components/SheetContent/index.d.ts +2 -0
  80. package/dist/types/src/components/SheetContent/index.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContent/util.d.ts.map +1 -0
  82. package/dist/types/src/components/{SheetContext/SheetContext.d.ts → SheetRoot/SheetRoot.d.ts} +6 -6
  83. package/dist/types/src/components/SheetRoot/SheetRoot.d.ts.map +1 -0
  84. package/dist/types/src/components/SheetRoot/index.d.ts +2 -0
  85. package/dist/types/src/components/SheetRoot/index.d.ts.map +1 -0
  86. package/dist/types/src/components/SheetStatusbar/SheetStatusbar.d.ts +5 -0
  87. package/dist/types/src/components/SheetStatusbar/SheetStatusbar.d.ts.map +1 -0
  88. package/dist/types/src/components/SheetStatusbar/index.d.ts +2 -0
  89. package/dist/types/src/components/SheetStatusbar/index.d.ts.map +1 -0
  90. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts +6 -4
  91. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
  92. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +2 -0
  93. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -1
  94. package/dist/types/src/components/SheetToolbar/align.d.ts +12 -19
  95. package/dist/types/src/components/SheetToolbar/align.d.ts.map +1 -1
  96. package/dist/types/src/components/SheetToolbar/style.d.ts +12 -18
  97. package/dist/types/src/components/SheetToolbar/style.d.ts.map +1 -1
  98. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts +14 -1
  99. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts.map +1 -1
  100. package/dist/types/src/components/index.d.ts +1 -4
  101. package/dist/types/src/components/index.d.ts.map +1 -1
  102. package/dist/types/src/{components → containers}/RangeList/RangeList.d.ts +2 -2
  103. package/dist/types/src/containers/RangeList/RangeList.d.ts.map +1 -0
  104. package/dist/types/src/containers/RangeList/index.d.ts +3 -0
  105. package/dist/types/src/containers/RangeList/index.d.ts.map +1 -0
  106. package/dist/types/src/containers/SheetContainer/SheetContainer.d.ts +12 -0
  107. package/dist/types/src/containers/SheetContainer/SheetContainer.d.ts.map +1 -0
  108. package/dist/types/src/{components → containers}/SheetContainer/SheetContainer.stories.d.ts +4 -3
  109. package/dist/types/src/containers/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
  110. package/dist/types/src/{components → containers}/SheetContainer/index.d.ts.map +1 -1
  111. package/dist/types/src/containers/index.d.ts +4 -0
  112. package/dist/types/src/containers/index.d.ts.map +1 -0
  113. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  114. package/dist/types/src/extensions/editor/sheet-extension.d.ts.map +1 -1
  115. package/dist/types/src/index.d.ts +1 -1
  116. package/dist/types/src/index.d.ts.map +1 -1
  117. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
  118. package/dist/types/src/meta.d.ts +2 -2
  119. package/dist/types/src/meta.d.ts.map +1 -1
  120. package/dist/types/src/model/sheet-model.d.ts +6 -6
  121. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  122. package/dist/types/src/model/testing.d.ts +2 -2
  123. package/dist/types/src/model/testing.d.ts.map +1 -1
  124. package/dist/types/src/model/useSheetModel.d.ts +2 -2
  125. package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
  126. package/dist/types/src/serializer.d.ts +2 -2
  127. package/dist/types/src/serializer.d.ts.map +1 -1
  128. package/dist/types/src/testing/data.d.ts +2 -2
  129. package/dist/types/src/testing/data.d.ts.map +1 -1
  130. package/dist/types/src/testing/testing.d.ts +26 -2
  131. package/dist/types/src/testing/testing.d.ts.map +1 -1
  132. package/dist/types/src/translations.d.ts +3 -2
  133. package/dist/types/src/translations.d.ts.map +1 -1
  134. package/dist/types/src/types/Sheet.d.ts +76 -0
  135. package/dist/types/src/types/Sheet.d.ts.map +1 -0
  136. package/dist/types/src/types/capabilities.d.ts +6 -0
  137. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  138. package/dist/types/src/types/index.d.ts +2 -1
  139. package/dist/types/src/types/index.d.ts.map +1 -1
  140. package/dist/types/src/types/sheet-range-types.d.ts +2 -2
  141. package/dist/types/src/types/sheet-range-types.d.ts.map +1 -1
  142. package/dist/types/src/types/types.d.ts +91 -74
  143. package/dist/types/src/types/types.d.ts.map +1 -1
  144. package/dist/types/src/types/util.d.ts +10 -10
  145. package/dist/types/src/types/util.d.ts.map +1 -1
  146. package/dist/types/tsconfig.tsbuildinfo +1 -1
  147. package/package.json +74 -67
  148. package/src/SheetPlugin.tsx +41 -61
  149. package/src/capabilities/anchor-sort/anchor-sort.ts +27 -0
  150. package/src/capabilities/anchor-sort/index.ts +7 -0
  151. package/src/capabilities/compute-graph-registry/compute-graph-registry.ts +27 -0
  152. package/src/capabilities/compute-graph-registry/index.ts +7 -0
  153. package/src/capabilities/index.ts +5 -9
  154. package/src/capabilities/markdown/index.ts +7 -0
  155. package/src/capabilities/markdown/markdown.ts +30 -0
  156. package/src/capabilities/operation-resolver/index.ts +7 -0
  157. package/src/capabilities/operation-resolver/operation-resolver.ts +77 -0
  158. package/src/capabilities/react-surface/index.ts +7 -0
  159. package/src/capabilities/react-surface/react-surface.tsx +46 -0
  160. package/src/components/ComputeGraph/compute-graph.stories.tsx +10 -10
  161. package/src/components/Sheet/Sheet.tsx +20 -0
  162. package/src/components/Sheet/index.ts +5 -0
  163. package/src/components/{GridSheet → SheetContent}/SheetCellEditor.stories.tsx +13 -10
  164. package/src/components/{GridSheet/GridSheet.stories.tsx → SheetContent/SheetContent.stories.tsx} +16 -15
  165. package/src/components/{GridSheet/GridSheet.tsx → SheetContent/SheetContent.tsx} +52 -39
  166. package/src/components/{RangeList → SheetContent}/index.ts +1 -1
  167. package/src/components/{GridSheet → SheetContent}/util.ts +14 -8
  168. package/src/components/{SheetContext/SheetContext.tsx → SheetRoot/SheetRoot.tsx} +42 -40
  169. package/src/components/{GridSheet → SheetRoot}/index.ts +1 -1
  170. package/src/components/{FunctionEditor/FunctionEditor.tsx → SheetStatusbar/SheetStatusbar.tsx} +10 -5
  171. package/src/components/{FunctionEditor → SheetStatusbar}/index.ts +1 -1
  172. package/src/components/SheetToolbar/SheetToolbar.stories.tsx +4 -4
  173. package/src/components/SheetToolbar/SheetToolbar.tsx +45 -35
  174. package/src/components/SheetToolbar/align.ts +44 -19
  175. package/src/components/SheetToolbar/style.ts +48 -18
  176. package/src/components/SheetToolbar/useToolbarState.ts +22 -5
  177. package/src/components/index.ts +1 -7
  178. package/src/{components → containers}/RangeList/RangeList.tsx +17 -12
  179. package/src/containers/RangeList/index.ts +7 -0
  180. package/src/containers/SheetContainer/SheetContainer.stories.tsx +94 -0
  181. package/src/containers/SheetContainer/SheetContainer.tsx +57 -0
  182. package/src/{components → containers}/SheetContainer/index.ts +1 -1
  183. package/src/containers/index.ts +8 -0
  184. package/src/extensions/compute.stories.tsx +24 -14
  185. package/src/extensions/compute.ts +1 -1
  186. package/src/extensions/editor/sheet-extension.ts +16 -13
  187. package/src/index.ts +1 -1
  188. package/src/integrations/thread-ranges.ts +38 -49
  189. package/src/meta.ts +8 -4
  190. package/src/model/sheet-model.test.ts +4 -4
  191. package/src/model/sheet-model.ts +80 -48
  192. package/src/model/testing.ts +4 -4
  193. package/src/model/useSheetModel.ts +2 -2
  194. package/src/playwright/playwright.config.ts +1 -1
  195. package/src/playwright/sheet.spec.ts +2 -1
  196. package/src/sanity.test.ts +3 -4
  197. package/src/serializer.ts +4 -4
  198. package/src/testing/data.ts +2 -2
  199. package/src/testing/testing.tsx +3 -3
  200. package/src/translations.ts +3 -2
  201. package/src/types/Sheet.ts +97 -0
  202. package/src/{capabilities → types}/capabilities.ts +2 -2
  203. package/src/types/index.ts +2 -1
  204. package/src/types/sheet-range-types.ts +5 -5
  205. package/src/types/types.ts +82 -48
  206. package/src/types/util.ts +11 -38
  207. package/dist/lib/browser/SheetContainer-VL34UND4.mjs +0 -351
  208. package/dist/lib/browser/SheetContainer-VL34UND4.mjs.map +0 -7
  209. package/dist/lib/browser/anchor-sort-3N44DS5F.mjs +0 -24
  210. package/dist/lib/browser/anchor-sort-3N44DS5F.mjs.map +0 -7
  211. package/dist/lib/browser/chunk-ADK2HW4A.mjs +0 -906
  212. package/dist/lib/browser/chunk-ADK2HW4A.mjs.map +0 -7
  213. package/dist/lib/browser/chunk-CSBSADPQ.mjs +0 -16
  214. package/dist/lib/browser/chunk-CSBSADPQ.mjs.map +0 -7
  215. package/dist/lib/browser/chunk-SSN4HYJL.mjs.map +0 -7
  216. package/dist/lib/browser/chunk-ZJWJMX4E.mjs +0 -852
  217. package/dist/lib/browser/chunk-ZJWJMX4E.mjs.map +0 -7
  218. package/dist/lib/browser/chunk-ZMPNHFIP.mjs +0 -15
  219. package/dist/lib/browser/chunk-ZMPNHFIP.mjs.map +0 -7
  220. package/dist/lib/browser/compute-graph-registry-MF65HGGM.mjs +0 -21
  221. package/dist/lib/browser/compute-graph-registry-MF65HGGM.mjs.map +0 -7
  222. package/dist/lib/browser/intent-resolver-BQLV6IAA.mjs +0 -56
  223. package/dist/lib/browser/intent-resolver-BQLV6IAA.mjs.map +0 -7
  224. package/dist/lib/browser/markdown-RMTMI237.mjs +0 -26
  225. package/dist/lib/browser/markdown-RMTMI237.mjs.map +0 -7
  226. package/dist/lib/browser/react-surface-7ZDMQDCT.mjs +0 -53
  227. package/dist/lib/browser/react-surface-7ZDMQDCT.mjs.map +0 -7
  228. package/dist/lib/node-esm/SheetContainer-NWJ7L6FC.mjs +0 -352
  229. package/dist/lib/node-esm/SheetContainer-NWJ7L6FC.mjs.map +0 -7
  230. package/dist/lib/node-esm/anchor-sort-YL2OZHYM.mjs +0 -25
  231. package/dist/lib/node-esm/anchor-sort-YL2OZHYM.mjs.map +0 -7
  232. package/dist/lib/node-esm/chunk-BZAPYBSH.mjs +0 -907
  233. package/dist/lib/node-esm/chunk-BZAPYBSH.mjs.map +0 -7
  234. package/dist/lib/node-esm/chunk-H3GSD33H.mjs +0 -18
  235. package/dist/lib/node-esm/chunk-H3GSD33H.mjs.map +0 -7
  236. package/dist/lib/node-esm/chunk-IK4O7FUJ.mjs.map +0 -7
  237. package/dist/lib/node-esm/chunk-LN6ZSAII.mjs +0 -16
  238. package/dist/lib/node-esm/chunk-LN6ZSAII.mjs.map +0 -7
  239. package/dist/lib/node-esm/chunk-YL7BVJPC.mjs +0 -853
  240. package/dist/lib/node-esm/chunk-YL7BVJPC.mjs.map +0 -7
  241. package/dist/lib/node-esm/compute-graph-registry-P2O5LDFZ.mjs +0 -22
  242. package/dist/lib/node-esm/compute-graph-registry-P2O5LDFZ.mjs.map +0 -7
  243. package/dist/lib/node-esm/intent-resolver-MV5ZFXAQ.mjs +0 -57
  244. package/dist/lib/node-esm/intent-resolver-MV5ZFXAQ.mjs.map +0 -7
  245. package/dist/lib/node-esm/markdown-EDIWHA3P.mjs +0 -27
  246. package/dist/lib/node-esm/markdown-EDIWHA3P.mjs.map +0 -7
  247. package/dist/lib/node-esm/react-surface-TUME5MM2.mjs +0 -54
  248. package/dist/lib/node-esm/react-surface-TUME5MM2.mjs.map +0 -7
  249. package/dist/types/src/capabilities/anchor-sort.d.ts +0 -6
  250. package/dist/types/src/capabilities/anchor-sort.d.ts.map +0 -1
  251. package/dist/types/src/capabilities/capabilities.d.ts +0 -5
  252. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  253. package/dist/types/src/capabilities/compute-graph-registry.d.ts +0 -4
  254. package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +0 -1
  255. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  256. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  257. package/dist/types/src/capabilities/markdown.d.ts +0 -4
  258. package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
  259. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  260. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  261. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +0 -3
  262. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +0 -1
  263. package/dist/types/src/components/FunctionEditor/index.d.ts +0 -2
  264. package/dist/types/src/components/FunctionEditor/index.d.ts.map +0 -1
  265. package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -3
  266. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
  267. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
  268. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +0 -1
  269. package/dist/types/src/components/GridSheet/index.d.ts +0 -2
  270. package/dist/types/src/components/GridSheet/index.d.ts.map +0 -1
  271. package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
  272. package/dist/types/src/components/RangeList/RangeList.d.ts.map +0 -1
  273. package/dist/types/src/components/RangeList/index.d.ts +0 -2
  274. package/dist/types/src/components/RangeList/index.d.ts.map +0 -1
  275. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +0 -11
  276. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +0 -1
  277. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +0 -1
  278. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +0 -1
  279. package/dist/types/src/components/SheetContext/index.d.ts +0 -2
  280. package/dist/types/src/components/SheetContext/index.d.ts.map +0 -1
  281. package/dist/types/src/types/schema.d.ts +0 -37
  282. package/dist/types/src/types/schema.d.ts.map +0 -1
  283. package/src/capabilities/anchor-sort.ts +0 -22
  284. package/src/capabilities/compute-graph-registry.ts +0 -23
  285. package/src/capabilities/intent-resolver.ts +0 -38
  286. package/src/capabilities/markdown.ts +0 -23
  287. package/src/capabilities/react-surface.tsx +0 -40
  288. package/src/components/SheetContainer/SheetContainer.stories.tsx +0 -90
  289. package/src/components/SheetContainer/SheetContainer.tsx +0 -40
  290. package/src/components/SheetContext/index.ts +0 -5
  291. package/src/types/schema.ts +0 -61
  292. /package/dist/types/src/components/{GridSheet → SheetContent}/util.d.ts +0 -0
  293. /package/dist/types/src/{components → containers}/SheetContainer/index.d.ts +0 -0
@@ -0,0 +1,1806 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ rangeExtension,
4
+ sheetExtension
5
+ } from "./chunk-M52YLLWU.mjs";
6
+ import {
7
+ DEFAULT_COLS,
8
+ DEFAULT_ROWS,
9
+ MAX_COLS,
10
+ MAX_ROWS,
11
+ ReadonlyException,
12
+ SheetOperation,
13
+ addressFromIndex,
14
+ addressToIndex,
15
+ alignKey,
16
+ cellClassNameForRange,
17
+ initialize,
18
+ insertIndices,
19
+ mapFormulaIndicesToRefs,
20
+ mapFormulaRefsToIndices,
21
+ meta,
22
+ rangeFromIndex,
23
+ rangeToIndex
24
+ } from "./chunk-NKZ3O4OR.mjs";
25
+
26
+ // src/containers/SheetContainer/SheetContainer.tsx
27
+ import React6 from "react";
28
+ import { Obj as Obj7 } from "@dxos/echo";
29
+ import { Panel } from "@dxos/react-ui";
30
+
31
+ // src/components/ComputeGraph/ComputeGraphContextProvider.tsx
32
+ import React, { createContext, useContext } from "react";
33
+ import { raise } from "@dxos/debug";
34
+ import { useAsyncState } from "@dxos/react-hooks";
35
+ var ComputeGraphContext = /* @__PURE__ */ createContext(void 0);
36
+ var ComputeGraphContextProvider = ({ registry, children }) => {
37
+ return /* @__PURE__ */ React.createElement(ComputeGraphContext.Provider, {
38
+ value: {
39
+ registry
40
+ }
41
+ }, children);
42
+ };
43
+ var useComputeGraph = (space) => {
44
+ const { registry } = useContext(ComputeGraphContext) ?? raise(new Error("Missing ComputeGraphContext"));
45
+ const [graph] = useAsyncState(async () => {
46
+ if (space) {
47
+ const graph2 = registry.getOrCreateGraph(space);
48
+ await graph2.open();
49
+ return graph2;
50
+ }
51
+ }, [
52
+ space,
53
+ registry
54
+ ]);
55
+ return graph;
56
+ };
57
+
58
+ // src/components/SheetContent/SheetContent.tsx
59
+ import React3, { useCallback as useCallback3, useMemo as useMemo2, useRef, useState as useState4 } from "react";
60
+ import { useOperationInvoker as useOperationInvoker2 } from "@dxos/app-framework/ui";
61
+ import { rangeToA1Notation } from "@dxos/compute";
62
+ import { Obj as Obj4 } from "@dxos/echo";
63
+ import { defaultColSize, defaultRowSize } from "@dxos/lit-grid";
64
+ import { DropdownMenu, Icon, useTranslation } from "@dxos/react-ui";
65
+ import { useAttention } from "@dxos/react-ui-attention";
66
+ import { Grid as Grid2, GridCellEditor, closestCell, editorKeys, parseCellIndex } from "@dxos/react-ui-grid";
67
+ import { mx as mx2, useComposableProps } from "@dxos/ui-theme";
68
+
69
+ // src/integrations/thread-ranges.ts
70
+ import * as Effect from "effect/Effect";
71
+ import { useCallback, useEffect, useMemo } from "react";
72
+ import { useOperationInvoker, useOperationResolver } from "@dxos/app-framework/ui";
73
+ import { LayoutOperation } from "@dxos/app-toolkit";
74
+ import { debounce } from "@dxos/async";
75
+ import { inRange } from "@dxos/compute";
76
+ import { Obj, Relation } from "@dxos/echo";
77
+ import { OperationResolver } from "@dxos/operation";
78
+ import { ATTENDABLE_PATH_SEPARATOR, DeckOperation } from "@dxos/plugin-deck/types";
79
+ import { ThreadOperation } from "@dxos/plugin-thread/types";
80
+ import { Filter, Query, useQuery } from "@dxos/react-client/echo";
81
+ import { AnchoredTo, Thread } from "@dxos/types";
82
+ var parseThreadAnchorAsCellRange = (cursor) => {
83
+ const coords = cursor.split(",");
84
+ if (coords.length !== 4) {
85
+ return null;
86
+ } else {
87
+ const [fromCol, fromRow, toCol, toRow] = coords;
88
+ return {
89
+ from: {
90
+ col: parseInt(fromCol),
91
+ row: parseInt(fromRow)
92
+ },
93
+ to: {
94
+ col: parseInt(toCol),
95
+ row: parseInt(toRow)
96
+ }
97
+ };
98
+ }
99
+ };
100
+ var useUpdateFocusedCellOnThreadSelection = (grid) => {
101
+ const { model, setActiveRefs } = useSheetContext();
102
+ const sheetId = Obj.getDXN(model.sheet).toString();
103
+ const scrollIntoViewHandler = useMemo(() => OperationResolver.make({
104
+ operation: LayoutOperation.ScrollIntoView,
105
+ position: "hoist",
106
+ filter: (input) => input.subject === sheetId && !!input.cursor,
107
+ handler: (input) => Effect.sync(() => {
108
+ const { cursor, ref } = input;
109
+ if (cursor) {
110
+ setActiveRefs(ref);
111
+ const range = parseThreadAnchorAsCellRange(cursor);
112
+ range && grid?.setFocus({
113
+ ...range.to,
114
+ plane: "grid"
115
+ }, true);
116
+ }
117
+ })
118
+ }), [
119
+ sheetId,
120
+ setActiveRefs,
121
+ grid
122
+ ]);
123
+ useOperationResolver(meta.id, scrollIntoViewHandler);
124
+ };
125
+ var useSelectThreadOnCellFocus = () => {
126
+ const { model, cursor } = useSheetContext();
127
+ const { invokePromise } = useOperationInvoker();
128
+ const db = Obj.getDatabase(model.sheet);
129
+ const anchors = useQuery(db, Query.select(Filter.id(model.sheet.id)).targetOf(AnchoredTo.AnchoredTo));
130
+ const selectClosestThread = useCallback((cellAddress) => {
131
+ if (!cellAddress) {
132
+ return;
133
+ }
134
+ const closestThread = anchors.find((anchor) => {
135
+ const source = Relation.getSource(anchor);
136
+ if (anchor.anchor && Obj.instanceOf(Thread.Thread, source)) {
137
+ const range = parseThreadAnchorAsCellRange(anchor.anchor);
138
+ return range ? inRange(range, cellAddress) : false;
139
+ } else {
140
+ return false;
141
+ }
142
+ });
143
+ if (closestThread) {
144
+ const primary = Obj.getDXN(model.sheet).toString();
145
+ void (async () => {
146
+ await invokePromise(ThreadOperation.Select, {
147
+ current: Relation.getDXN(closestThread).toString()
148
+ });
149
+ await invokePromise(DeckOperation.ChangeCompanion, {
150
+ companion: `${primary}${ATTENDABLE_PATH_SEPARATOR}comments`
151
+ });
152
+ })();
153
+ }
154
+ }, [
155
+ invokePromise,
156
+ anchors
157
+ ]);
158
+ const debounced = useMemo(() => {
159
+ return debounce((cellCoords) => requestAnimationFrame(() => selectClosestThread(cellCoords)), 50);
160
+ }, [
161
+ selectClosestThread
162
+ ]);
163
+ useEffect(() => {
164
+ if (!cursor) {
165
+ return;
166
+ }
167
+ debounced(cursor);
168
+ }, [
169
+ cursor,
170
+ debounced
171
+ ]);
172
+ };
173
+
174
+ // src/components/SheetRoot/SheetRoot.tsx
175
+ import React2, { createContext as createContext2, useCallback as useCallback2, useContext as useContext2, useState as useState2 } from "react";
176
+ import { raise as raise2 } from "@dxos/debug";
177
+ import { Obj as Obj3 } from "@dxos/echo";
178
+ import { Grid, useGridContext } from "@dxos/react-ui-grid";
179
+
180
+ // src/model/sheet-model.ts
181
+ import { Event } from "@dxos/async";
182
+ import { DetailedCellError, ExportedCellChange, addressFromA1Notation, addressToA1Notation, createSheetName, isFormula } from "@dxos/compute";
183
+ import { Resource } from "@dxos/context";
184
+ import { Obj as Obj2 } from "@dxos/echo";
185
+ import { Format, TypeEnum } from "@dxos/echo/internal";
186
+ import { invariant } from "@dxos/invariant";
187
+ import { PublicKey } from "@dxos/keys";
188
+ import { log } from "@dxos/log";
189
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
190
+ var typeMap = {
191
+ BOOLEAN: {
192
+ type: TypeEnum.Boolean
193
+ },
194
+ NUMBER_RAW: {
195
+ type: TypeEnum.Number
196
+ },
197
+ NUMBER_PERCENT: {
198
+ type: TypeEnum.Number,
199
+ format: Format.TypeFormat.Percent
200
+ },
201
+ NUMBER_CURRENCY: {
202
+ type: TypeEnum.Number,
203
+ format: Format.TypeFormat.Currency
204
+ },
205
+ NUMBER_DATETIME: {
206
+ type: TypeEnum.String,
207
+ format: Format.TypeFormat.DateTime
208
+ },
209
+ NUMBER_DATE: {
210
+ type: TypeEnum.String,
211
+ format: Format.TypeFormat.Date
212
+ },
213
+ NUMBER_TIME: {
214
+ type: TypeEnum.String,
215
+ format: Format.TypeFormat.Time
216
+ }
217
+ };
218
+ var getTopLeft = (range) => {
219
+ const to = range.to ?? range.from;
220
+ return {
221
+ row: Math.min(range.from.row, to.row),
222
+ col: Math.min(range.from.col, to.col)
223
+ };
224
+ };
225
+ var toSimpleCellAddress = (sheet, cell) => ({
226
+ sheet,
227
+ row: cell.row,
228
+ col: cell.col
229
+ });
230
+ var toModelRange = (sheet, range) => ({
231
+ start: toSimpleCellAddress(sheet, range.from),
232
+ end: toSimpleCellAddress(sheet, range.to ?? range.from)
233
+ });
234
+ var SheetModel = class extends Resource {
235
+ _graph;
236
+ _sheet;
237
+ _options;
238
+ id = `model-${PublicKey.random().truncate()}`;
239
+ // Wraps compute node.
240
+ update = new Event();
241
+ _node;
242
+ constructor(_graph, _sheet, _options = {}) {
243
+ super(), this._graph = _graph, this._sheet = _sheet, this._options = _options;
244
+ }
245
+ get graph() {
246
+ return this._graph;
247
+ }
248
+ get sheet() {
249
+ return this._sheet;
250
+ }
251
+ get readonly() {
252
+ return this._options.readonly;
253
+ }
254
+ get bounds() {
255
+ return {
256
+ rows: this._sheet.rows.length,
257
+ columns: this._sheet.columns.length
258
+ };
259
+ }
260
+ /**
261
+ * Initialize sheet and engine.
262
+ */
263
+ async _open() {
264
+ log("initialize", {
265
+ id: this.id
266
+ }, {
267
+ F: __dxlog_file,
268
+ L: 124,
269
+ S: this,
270
+ C: (f, a) => f(...a)
271
+ });
272
+ Obj2.change(this._sheet, (obj) => {
273
+ initialize(obj);
274
+ });
275
+ this._graph.update.on((event) => {
276
+ if (event.type === "functionsUpdated") {
277
+ this.reset();
278
+ }
279
+ });
280
+ this._node = this._graph.getOrCreateNode(createSheetName({
281
+ type: Obj2.getTypename(this._sheet),
282
+ id: this._sheet.id
283
+ }));
284
+ await this._node.open();
285
+ const unsubscribe = this._node.update.on((event) => this.update.emit(event));
286
+ this._ctx.onDispose(unsubscribe);
287
+ this.reset();
288
+ }
289
+ /**
290
+ * Update engine.
291
+ * NOTE: This resets the undo history.
292
+ * @deprecated
293
+ */
294
+ reset() {
295
+ invariant(this._node, void 0, {
296
+ F: __dxlog_file,
297
+ L: 154,
298
+ S: this,
299
+ A: [
300
+ "this._node",
301
+ ""
302
+ ]
303
+ });
304
+ this._node.graph.hf.clearSheet(this._node.sheetId);
305
+ Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
306
+ invariant(this._node, void 0, {
307
+ F: __dxlog_file,
308
+ L: 157,
309
+ S: this,
310
+ A: [
311
+ "this._node",
312
+ ""
313
+ ]
314
+ });
315
+ const { col, row } = addressFromIndex(this._sheet, key);
316
+ if (isFormula(value)) {
317
+ const binding = this._graph.mapFunctionBindingFromId(mapFormulaIndicesToRefs(this._sheet, value));
318
+ if (binding) {
319
+ value = this._graph.mapFormulaToNative(binding);
320
+ } else {
321
+ value = "";
322
+ }
323
+ }
324
+ this._node.graph.hf.setCellContents({
325
+ sheet: this._node.sheetId,
326
+ row,
327
+ col
328
+ }, value);
329
+ });
330
+ }
331
+ /**
332
+ * Recalculate formulas.
333
+ * NOTE: This resets the undo history.
334
+ * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
335
+ * @deprecated
336
+ */
337
+ // TODO(burdon): Remove.
338
+ recalculate() {
339
+ this._node?.graph.hf.rebuildAndRecalculate();
340
+ }
341
+ insertRows(i, n = 1) {
342
+ let idx = [];
343
+ Obj2.change(this._sheet, (obj) => {
344
+ idx = insertIndices(obj.rows, i, n, MAX_ROWS);
345
+ });
346
+ this.reset();
347
+ return idx;
348
+ }
349
+ insertColumns(i, n = 1) {
350
+ let idx = [];
351
+ Obj2.change(this._sheet, (obj) => {
352
+ idx = insertIndices(obj.columns, i, n, MAX_COLS);
353
+ });
354
+ this.reset();
355
+ return idx;
356
+ }
357
+ dropRow(rowIndex) {
358
+ const range = {
359
+ from: addressFromIndex(this._sheet, `${this._sheet.columns[0]}@${rowIndex}`),
360
+ to: addressFromIndex(this._sheet, `${this._sheet.columns[this._sheet.columns.length - 1]}@${rowIndex}`)
361
+ };
362
+ const values = this.getCellValues(range).flat();
363
+ const index = this._sheet.rows.indexOf(rowIndex);
364
+ this.clear(range);
365
+ Obj2.change(this._sheet, (obj) => {
366
+ obj.rows.splice(index, 1);
367
+ delete obj.rowMeta[rowIndex];
368
+ });
369
+ this.reset();
370
+ return {
371
+ axis: "row",
372
+ index,
373
+ axisIndex: rowIndex,
374
+ axisMeta: this._sheet.rowMeta[rowIndex],
375
+ values
376
+ };
377
+ }
378
+ dropColumn(colIndex) {
379
+ const range = {
380
+ from: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[0]}`),
381
+ to: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[this._sheet.rows.length - 1]}`)
382
+ };
383
+ const values = this.getCellValues(range).flat();
384
+ const index = this._sheet.columns.indexOf(colIndex);
385
+ this.clear(range);
386
+ Obj2.change(this._sheet, (obj) => {
387
+ obj.columns.splice(index, 1);
388
+ delete obj.columnMeta[colIndex];
389
+ });
390
+ this.reset();
391
+ return {
392
+ axis: "col",
393
+ index,
394
+ axisIndex: colIndex,
395
+ axisMeta: this._sheet.rowMeta[colIndex],
396
+ values
397
+ };
398
+ }
399
+ restoreRow({ index, axisIndex, axisMeta, values }) {
400
+ Obj2.change(this._sheet, (obj) => {
401
+ obj.rows.splice(index, 0, axisIndex);
402
+ values.forEach((value, col) => {
403
+ if (value) {
404
+ obj.cells[`${obj.columns[col]}@${axisIndex}`] = {
405
+ value
406
+ };
407
+ }
408
+ });
409
+ if (axisMeta) {
410
+ obj.rowMeta[axisIndex] = axisMeta;
411
+ }
412
+ });
413
+ this.reset();
414
+ }
415
+ restoreColumn({ index, axisIndex, axisMeta, values }) {
416
+ Obj2.change(this._sheet, (obj) => {
417
+ obj.columns.splice(index, 0, axisIndex);
418
+ values.forEach((value, row) => {
419
+ if (value) {
420
+ obj.cells[`${axisIndex}@${obj.rows[row]}`] = {
421
+ value
422
+ };
423
+ }
424
+ });
425
+ if (axisMeta) {
426
+ obj.columnMeta[axisIndex] = axisMeta;
427
+ }
428
+ });
429
+ this.reset();
430
+ }
431
+ //
432
+ // Undoable actions.
433
+ // TODO(burdon): Group undoable methods; consistently update hf/sheet.
434
+ //
435
+ /**
436
+ * Clear range of values.
437
+ */
438
+ clear(range) {
439
+ invariant(this._node, void 0, {
440
+ F: __dxlog_file,
441
+ L: 276,
442
+ S: this,
443
+ A: [
444
+ "this._node",
445
+ ""
446
+ ]
447
+ });
448
+ const topLeft = getTopLeft(range);
449
+ const values = this._iterRange(range, () => null);
450
+ this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
451
+ Obj2.change(this._sheet, (obj) => {
452
+ this._iterRange(range, (cell) => {
453
+ const idx = addressToIndex(this._sheet, cell);
454
+ delete obj.cells[idx];
455
+ });
456
+ });
457
+ }
458
+ cut(range) {
459
+ invariant(this._node, void 0, {
460
+ F: __dxlog_file,
461
+ L: 289,
462
+ S: this,
463
+ A: [
464
+ "this._node",
465
+ ""
466
+ ]
467
+ });
468
+ this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
469
+ Obj2.change(this._sheet, (obj) => {
470
+ this._iterRange(range, (cell) => {
471
+ const idx = addressToIndex(this._sheet, cell);
472
+ delete obj.cells[idx];
473
+ });
474
+ });
475
+ }
476
+ copy(range) {
477
+ invariant(this._node, void 0, {
478
+ F: __dxlog_file,
479
+ L: 300,
480
+ S: this,
481
+ A: [
482
+ "this._node",
483
+ ""
484
+ ]
485
+ });
486
+ this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
487
+ }
488
+ paste(cell) {
489
+ invariant(this._node, void 0, {
490
+ F: __dxlog_file,
491
+ L: 305,
492
+ S: this,
493
+ A: [
494
+ "this._node",
495
+ ""
496
+ ]
497
+ });
498
+ if (!this._node.graph.hf.isClipboardEmpty()) {
499
+ const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
500
+ Obj2.change(this._sheet, (obj) => {
501
+ for (const change of changes) {
502
+ if (change instanceof ExportedCellChange) {
503
+ const { address, newValue } = change;
504
+ const idx = addressToIndex(this._sheet, {
505
+ row: address.row,
506
+ col: address.col
507
+ });
508
+ obj.cells[idx] = {
509
+ value: newValue
510
+ };
511
+ }
512
+ }
513
+ });
514
+ }
515
+ }
516
+ // TODO(burdon): Display undo/redo state.
517
+ undo() {
518
+ invariant(this._node, void 0, {
519
+ F: __dxlog_file,
520
+ L: 322,
521
+ S: this,
522
+ A: [
523
+ "this._node",
524
+ ""
525
+ ]
526
+ });
527
+ if (this._node.graph.hf.isThereSomethingToUndo()) {
528
+ this._node.graph.hf.undo();
529
+ }
530
+ }
531
+ redo() {
532
+ invariant(this._node, void 0, {
533
+ F: __dxlog_file,
534
+ L: 330,
535
+ S: this,
536
+ A: [
537
+ "this._node",
538
+ ""
539
+ ]
540
+ });
541
+ if (this._node.graph.hf.isThereSomethingToRedo()) {
542
+ this._node.graph.hf.redo();
543
+ }
544
+ }
545
+ /**
546
+ * Get value from sheet.
547
+ */
548
+ getCellValue(cell) {
549
+ const idx = addressToIndex(this._sheet, cell);
550
+ return this._sheet.cells[idx]?.value ?? null;
551
+ }
552
+ /**
553
+ * Get value as a string for editing.
554
+ */
555
+ getCellText(cell) {
556
+ const value = this.getCellValue(cell);
557
+ if (value == null) {
558
+ return void 0;
559
+ }
560
+ if (isFormula(value)) {
561
+ return this._graph.mapFunctionBindingFromId(mapFormulaIndicesToRefs(this._sheet, value));
562
+ } else {
563
+ return String(value);
564
+ }
565
+ }
566
+ /**
567
+ * Get array of raw values from sheet.
568
+ */
569
+ getCellValues(range) {
570
+ return this._iterRange(range, (cell) => this.getCellValue(cell));
571
+ }
572
+ /**
573
+ * Gets the regular or computed value from the engine.
574
+ */
575
+ getValue(cell) {
576
+ invariant(this._node, void 0, {
577
+ F: __dxlog_file,
578
+ L: 373,
579
+ S: this,
580
+ A: [
581
+ "this._node",
582
+ ""
583
+ ]
584
+ });
585
+ const address = toSimpleCellAddress(this._node.sheetId, cell);
586
+ const value = this._node.graph.hf.getCellValue(address);
587
+ if (value instanceof DetailedCellError) {
588
+ log.warn("cell error", {
589
+ cell,
590
+ error: value
591
+ }, {
592
+ F: __dxlog_file,
593
+ L: 378,
594
+ S: this,
595
+ C: (f, a) => f(...a)
596
+ });
597
+ return value.toString();
598
+ }
599
+ return value;
600
+ }
601
+ /**
602
+ * Get value type.
603
+ */
604
+ getValueDescription(cell) {
605
+ invariant(this._node, void 0, {
606
+ F: __dxlog_file,
607
+ L: 389,
608
+ S: this,
609
+ A: [
610
+ "this._node",
611
+ ""
612
+ ]
613
+ });
614
+ const addr = toSimpleCellAddress(this._node.sheetId, cell);
615
+ const type = this._node.graph.hf.getCellValueDetailedType(addr);
616
+ return typeMap[type];
617
+ }
618
+ /**
619
+ * Sets the value, updating the sheet and engine.
620
+ */
621
+ setValue(cell, value) {
622
+ invariant(this._node, void 0, {
623
+ F: __dxlog_file,
624
+ L: 399,
625
+ S: this,
626
+ A: [
627
+ "this._node",
628
+ ""
629
+ ]
630
+ });
631
+ if (this._options.readonly) {
632
+ throw new ReadonlyException();
633
+ }
634
+ let refresh = false;
635
+ if (cell.row >= this._sheet.rows.length) {
636
+ Obj2.change(this._sheet, (obj) => {
637
+ insertIndices(obj.rows, cell.row, 1, MAX_ROWS);
638
+ });
639
+ refresh = true;
640
+ }
641
+ if (cell.col >= this._sheet.columns.length) {
642
+ Obj2.change(this._sheet, (obj) => {
643
+ insertIndices(obj.columns, cell.col, 1, MAX_COLS);
644
+ });
645
+ refresh = true;
646
+ }
647
+ if (refresh) {
648
+ this.reset();
649
+ }
650
+ this._node.graph.hf.setCellContents({
651
+ sheet: this._node.sheetId,
652
+ row: cell.row,
653
+ col: cell.col
654
+ }, [
655
+ [
656
+ isFormula(value) ? this._graph.mapFormulaToNative(value) : value
657
+ ]
658
+ ]);
659
+ const idx = addressToIndex(this._sheet, cell);
660
+ if (value === void 0 || value === null) {
661
+ Obj2.change(this._sheet, (obj) => {
662
+ delete obj.cells[idx];
663
+ });
664
+ } else {
665
+ if (isFormula(value)) {
666
+ value = this._graph.mapFunctionBindingToId(mapFormulaRefsToIndices(this._sheet, value));
667
+ }
668
+ Obj2.change(this._sheet, (obj) => {
669
+ obj.cells[idx] = {
670
+ value
671
+ };
672
+ });
673
+ }
674
+ }
675
+ /**
676
+ * Sets values from a simple map.
677
+ */
678
+ setValues(values) {
679
+ Object.entries(values).forEach(([key, { value }]) => {
680
+ this.setValue(addressFromA1Notation(key), value);
681
+ });
682
+ }
683
+ /**
684
+ * Iterate range.
685
+ */
686
+ _iterRange(range, cb) {
687
+ const to = range.to ?? range.from;
688
+ const rowRange = [
689
+ Math.min(range.from.row, to.row),
690
+ Math.max(range.from.row, to.row)
691
+ ];
692
+ const columnRange = [
693
+ Math.min(range.from.col, to.col),
694
+ Math.max(range.from.col, to.col)
695
+ ];
696
+ const rows = [];
697
+ for (let row = rowRange[0]; row <= rowRange[1]; row++) {
698
+ const rowCells = [];
699
+ for (let column = columnRange[0]; column <= columnRange[1]; column++) {
700
+ const value = cb({
701
+ row,
702
+ col: column
703
+ });
704
+ if (value !== void 0) {
705
+ rowCells.push(value);
706
+ }
707
+ }
708
+ rows.push(rowCells);
709
+ }
710
+ return rows;
711
+ }
712
+ // TODO(burdon): Delete index.
713
+ _deleteIndices(indices, i, n) {
714
+ throw new Error("Not implemented");
715
+ }
716
+ // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
717
+ _moveIndices(indices, i, j, n) {
718
+ throw new Error("Not implemented");
719
+ }
720
+ /**
721
+ * Map from indices to A1 notation.
722
+ */
723
+ mapFormulaIndicesToRefs(formula) {
724
+ invariant(isFormula(formula), void 0, {
725
+ F: __dxlog_file,
726
+ L: 492,
727
+ S: this,
728
+ A: [
729
+ "isFormula(formula)",
730
+ ""
731
+ ]
732
+ });
733
+ return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
734
+ return addressToA1Notation(addressFromIndex(this._sheet, idx));
735
+ });
736
+ }
737
+ //
738
+ // Values
739
+ //
740
+ /**
741
+ * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
742
+ * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
743
+ * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
744
+ */
745
+ toLocalDate(num) {
746
+ const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
747
+ return new Date(year, month - 1, day, hours, minutes, seconds);
748
+ }
749
+ toDateTime(num) {
750
+ invariant(this._node, void 0, {
751
+ F: __dxlog_file,
752
+ L: 513,
753
+ S: this,
754
+ A: [
755
+ "this._node",
756
+ ""
757
+ ]
758
+ });
759
+ return this._node.graph.hf.numberToDateTime(num);
760
+ }
761
+ toDate(num) {
762
+ invariant(this._node, void 0, {
763
+ F: __dxlog_file,
764
+ L: 518,
765
+ S: this,
766
+ A: [
767
+ "this._node",
768
+ ""
769
+ ]
770
+ });
771
+ return this._node.graph.hf.numberToDate(num);
772
+ }
773
+ toTime(num) {
774
+ invariant(this._node, void 0, {
775
+ F: __dxlog_file,
776
+ L: 523,
777
+ S: this,
778
+ A: [
779
+ "this._node",
780
+ ""
781
+ ]
782
+ });
783
+ return this._node.graph.hf.numberToTime(num);
784
+ }
785
+ };
786
+
787
+ // src/model/useSheetModel.ts
788
+ import { useEffect as useEffect2, useState } from "react";
789
+ var useSheetModel = (graph, sheet, { readonly } = {}) => {
790
+ const [model, setModel] = useState();
791
+ useEffect2(() => {
792
+ if (!graph || !sheet) {
793
+ return;
794
+ }
795
+ let model2;
796
+ const t = setTimeout(async () => {
797
+ model2 = new SheetModel(graph, sheet, {
798
+ readonly
799
+ });
800
+ await model2.open();
801
+ setModel(model2);
802
+ });
803
+ return () => {
804
+ clearTimeout(t);
805
+ void model2?.close();
806
+ };
807
+ }, [
808
+ graph,
809
+ sheet,
810
+ readonly
811
+ ]);
812
+ return model;
813
+ };
814
+
815
+ // src/components/SheetRoot/SheetRoot.tsx
816
+ var SheetContext = /* @__PURE__ */ createContext2(void 0);
817
+ var useSheetContext = () => {
818
+ return useContext2(SheetContext) ?? raise2(new Error("Missing SheetContext"));
819
+ };
820
+ var SheetRoot = ({ children, graph, sheet, readonly, ignoreAttention, onInfo }) => {
821
+ const model = useSheetModel(graph, sheet, {
822
+ readonly
823
+ });
824
+ if (!model) {
825
+ return null;
826
+ }
827
+ return /* @__PURE__ */ React2.createElement(Grid.Root, {
828
+ id: Obj3.getDXN(sheet).toString()
829
+ }, /* @__PURE__ */ React2.createElement(SheetProviderImpl, {
830
+ model,
831
+ onInfo,
832
+ ignoreAttention
833
+ }, children));
834
+ };
835
+ var SheetProviderImpl = ({ __gridScope, children, ignoreAttention, model, onInfo }) => {
836
+ const { id, editing, setEditing } = useGridContext("SheetProvider", __gridScope);
837
+ const [cursor, setCursorInternal] = useState2();
838
+ const [range, setRangeInternal] = useState2();
839
+ const [cursorFallbackRange, setCursorFallbackRange] = useState2();
840
+ const [activeRefs, setActiveRefs] = useState2("");
841
+ const setCursor = useCallback2((nextCursor) => {
842
+ setCursorInternal(nextCursor);
843
+ setCursorFallbackRange(range?.to ? range : nextCursor ? {
844
+ from: nextCursor,
845
+ to: nextCursor
846
+ } : void 0);
847
+ }, [
848
+ range
849
+ ]);
850
+ const setRange = useCallback2((nextRange) => {
851
+ setRangeInternal(nextRange);
852
+ setCursorFallbackRange(nextRange?.to ? nextRange : cursor ? {
853
+ from: cursor,
854
+ to: cursor
855
+ } : void 0);
856
+ }, [
857
+ cursor
858
+ ]);
859
+ return /* @__PURE__ */ React2.createElement(SheetContext.Provider, {
860
+ value: {
861
+ id,
862
+ model,
863
+ editing,
864
+ setEditing,
865
+ cursor,
866
+ setCursor,
867
+ range,
868
+ setRange,
869
+ cursorFallbackRange,
870
+ activeRefs,
871
+ setActiveRefs,
872
+ ignoreAttention,
873
+ // TODO(burdon): Change to event.
874
+ onInfo
875
+ }
876
+ }, children);
877
+ };
878
+
879
+ // src/components/SheetContent/util.ts
880
+ import { useEffect as useEffect3, useState as useState3 } from "react";
881
+ import { inRange as inRange2 } from "@dxos/compute";
882
+ import { createDocAccessor } from "@dxos/echo-db";
883
+ import { cellClassesForFieldType, parseValue } from "@dxos/react-ui-form";
884
+ import { colToA1Notation, commentedClassName, rowToA1Notation } from "@dxos/react-ui-grid";
885
+ import { mx } from "@dxos/ui-theme";
886
+ var createDxGridColumns = (model) => {
887
+ return model.sheet.columns.reduce((acc, columnId, numericIndex) => {
888
+ if (model.sheet.columnMeta[columnId] && model.sheet.columnMeta[columnId].size) {
889
+ acc.grid[numericIndex] = {
890
+ size: model.sheet.columnMeta[columnId].size,
891
+ resizeable: true
892
+ };
893
+ }
894
+ return acc;
895
+ }, {
896
+ grid: {}
897
+ });
898
+ };
899
+ var createDxGridRows = (model) => {
900
+ return model.sheet.rows.reduce((acc, rowId, numericIndex) => {
901
+ if (model.sheet.rowMeta[rowId] && model.sheet.rowMeta[rowId].size) {
902
+ acc.grid[numericIndex] = {
903
+ size: model.sheet.rowMeta[rowId].size,
904
+ resizeable: true
905
+ };
906
+ }
907
+ return acc;
908
+ }, {
909
+ grid: {}
910
+ });
911
+ };
912
+ var projectCellProps = (model, col, row) => {
913
+ const address = {
914
+ col,
915
+ row
916
+ };
917
+ const rawValue = model.getValue(address);
918
+ const ranges = model.sheet.ranges?.filter(({ range }) => inRange2(rangeFromIndex(model.sheet, range), address));
919
+ const threadRefs = void 0;
920
+ const description = model.getValueDescription(address);
921
+ const type = description?.type;
922
+ const format = description?.format;
923
+ const classNames = ranges?.map(cellClassNameForRange).reverse();
924
+ return {
925
+ value: parseValue({
926
+ type,
927
+ format,
928
+ value: rawValue
929
+ }),
930
+ className: mx(cellClassesForFieldType({
931
+ type,
932
+ format
933
+ }), threadRefs && commentedClassName, classNames),
934
+ dataRefs: threadRefs
935
+ };
936
+ };
937
+ var gridCellGetter = (model) => {
938
+ const cachedGridCells = {};
939
+ return (nextBounds) => {
940
+ [
941
+ ...Array(nextBounds.end.col - nextBounds.start.col)
942
+ ].forEach((_, c0) => {
943
+ return [
944
+ ...Array(nextBounds.end.row - nextBounds.start.row)
945
+ ].forEach((_2, r0) => {
946
+ const col = nextBounds.start.col + c0;
947
+ const row = nextBounds.start.row + r0;
948
+ cachedGridCells[`${col},${row}`] = projectCellProps(model, col, row);
949
+ });
950
+ });
951
+ return cachedGridCells;
952
+ };
953
+ };
954
+ var rowLabelCell = (row) => ({
955
+ value: rowToA1Notation(row),
956
+ className: "!bg-toolbar-surface text-subdued text-end pe-1",
957
+ resizeHandle: "row"
958
+ });
959
+ var colLabelCell = (col) => ({
960
+ value: colToA1Notation(col),
961
+ className: "!bg-toolbar-surface text-subdued",
962
+ resizeHandle: "col"
963
+ });
964
+ var cellGetter = (model) => {
965
+ const getGridCells = gridCellGetter(model);
966
+ return (nextBounds, plane) => {
967
+ switch (plane) {
968
+ case "grid":
969
+ return getGridCells(nextBounds);
970
+ case "fixedStartStart": {
971
+ return {
972
+ "0,0": {
973
+ className: "!bg-toolbar-surface"
974
+ }
975
+ };
976
+ }
977
+ case "frozenColsStart":
978
+ return [
979
+ ...Array(nextBounds.end.row - nextBounds.start.row)
980
+ ].reduce((acc, _, r0) => {
981
+ const r = nextBounds.start.row + r0;
982
+ acc[`0,${r}`] = rowLabelCell(r);
983
+ return acc;
984
+ }, {});
985
+ case "frozenRowsStart":
986
+ return [
987
+ ...Array(nextBounds.end.col - nextBounds.start.col)
988
+ ].reduce((acc, _, c0) => {
989
+ const c = nextBounds.start.col + c0;
990
+ acc[`${c},0`] = colLabelCell(c);
991
+ return acc;
992
+ }, {});
993
+ default:
994
+ return {};
995
+ }
996
+ };
997
+ };
998
+ var useSheetModelDxGridProps = (dxGrid, model) => {
999
+ const [columns, setColumns] = useState3(createDxGridColumns(model));
1000
+ const [rows, setRows] = useState3(createDxGridRows(model));
1001
+ useEffect3(() => {
1002
+ const cellsAccessor = createDocAccessor(model.sheet, [
1003
+ "cells"
1004
+ ]);
1005
+ if (dxGrid) {
1006
+ dxGrid.getCells = cellGetter(model);
1007
+ }
1008
+ const handleCellsUpdate = () => {
1009
+ dxGrid?.requestUpdate("initialCells");
1010
+ };
1011
+ cellsAccessor.handle.addListener("change", handleCellsUpdate);
1012
+ const unsubscribe = model.graph.update.on(handleCellsUpdate);
1013
+ return () => {
1014
+ cellsAccessor.handle.removeListener("change", handleCellsUpdate);
1015
+ unsubscribe();
1016
+ };
1017
+ }, [
1018
+ model,
1019
+ dxGrid
1020
+ ]);
1021
+ useEffect3(() => {
1022
+ const columnMetaAccessor = createDocAccessor(model.sheet, [
1023
+ "columnMeta"
1024
+ ]);
1025
+ const rowMetaAccessor = createDocAccessor(model.sheet, [
1026
+ "rowMeta"
1027
+ ]);
1028
+ const handleColumnMetaUpdate = () => {
1029
+ setColumns(createDxGridColumns(model));
1030
+ };
1031
+ const handleRowMetaUpdate = () => {
1032
+ setRows(createDxGridRows(model));
1033
+ };
1034
+ columnMetaAccessor.handle.addListener("change", handleColumnMetaUpdate);
1035
+ rowMetaAccessor.handle.addListener("change", handleRowMetaUpdate);
1036
+ return () => {
1037
+ columnMetaAccessor.handle.removeListener("change", handleColumnMetaUpdate);
1038
+ rowMetaAccessor.handle.removeListener("change", handleRowMetaUpdate);
1039
+ };
1040
+ }, [
1041
+ model,
1042
+ dxGrid
1043
+ ]);
1044
+ return {
1045
+ columns,
1046
+ rows
1047
+ };
1048
+ };
1049
+
1050
+ // src/components/SheetContent/SheetContent.tsx
1051
+ var inertPosition = {
1052
+ plane: "grid",
1053
+ col: 0,
1054
+ row: 0
1055
+ };
1056
+ var initialCells = {
1057
+ grid: {},
1058
+ frozenColsStart: [
1059
+ ...Array(64)
1060
+ ].reduce((acc, _, i) => {
1061
+ acc[`0,${i}`] = rowLabelCell(i);
1062
+ return acc;
1063
+ }, {}),
1064
+ frozenRowsStart: [
1065
+ ...Array(12)
1066
+ ].reduce((acc, _, i) => {
1067
+ acc[`${i},0`] = colLabelCell(i);
1068
+ return acc;
1069
+ }, {})
1070
+ };
1071
+ var frozen = {
1072
+ frozenColsStart: 1,
1073
+ frozenRowsStart: 1
1074
+ };
1075
+ var sheetColDefault = {
1076
+ frozenColsStart: {
1077
+ size: 48,
1078
+ readonly: true,
1079
+ focusUnfurl: false
1080
+ },
1081
+ grid: {
1082
+ size: defaultColSize,
1083
+ resizeable: true
1084
+ }
1085
+ };
1086
+ var sheetRowDefault = {
1087
+ frozenRowsStart: {
1088
+ size: defaultRowSize,
1089
+ readonly: true,
1090
+ focusUnfurl: false
1091
+ },
1092
+ grid: {
1093
+ size: defaultRowSize,
1094
+ resizeable: true
1095
+ }
1096
+ };
1097
+ var SheetContent = (props) => {
1098
+ const { t } = useTranslation(meta.id);
1099
+ const { id, model, editing, setCursor, setRange, cursor, cursorFallbackRange, activeRefs, ignoreAttention } = useSheetContext();
1100
+ const [dxGrid, setDxGrid] = useState4(null);
1101
+ const [extraplanarFocus, setExtraplanarFocus] = useState4(null);
1102
+ const { invokePromise } = useOperationInvoker2();
1103
+ const rangeController = useRef(null);
1104
+ const { hasAttention } = useAttention(id);
1105
+ const { className, ...rest } = useComposableProps(props);
1106
+ const handleFocus = useCallback3((event) => {
1107
+ if (!editing) {
1108
+ const cell = closestCell(event.target);
1109
+ if (cell) {
1110
+ if (cell.plane === "grid") {
1111
+ setCursor({
1112
+ col: cell.col,
1113
+ row: cell.row
1114
+ });
1115
+ setExtraplanarFocus(null);
1116
+ } else {
1117
+ setExtraplanarFocus(cell);
1118
+ }
1119
+ } else {
1120
+ setExtraplanarFocus(null);
1121
+ }
1122
+ }
1123
+ }, [
1124
+ editing
1125
+ ]);
1126
+ const handleClose = useCallback3((_value, event) => {
1127
+ if (event) {
1128
+ const { key, shift } = event;
1129
+ const axis = [
1130
+ "Enter",
1131
+ "ArrowUp",
1132
+ "ArrowDown"
1133
+ ].includes(key) ? "row" : [
1134
+ "Tab",
1135
+ "ArrowLeft",
1136
+ "ArrowRight"
1137
+ ].includes(key) ? "col" : void 0;
1138
+ const delta = key.startsWith("Arrow") ? [
1139
+ "ArrowUp",
1140
+ "ArrowLeft"
1141
+ ].includes(key) ? -1 : 1 : shift ? -1 : 1;
1142
+ dxGrid?.refocus(axis, delta);
1143
+ }
1144
+ }, [
1145
+ model,
1146
+ editing,
1147
+ dxGrid
1148
+ ]);
1149
+ const handleBlur = useCallback3((value) => {
1150
+ if (value !== void 0) {
1151
+ model.setValue(parseCellIndex(editing.index), value);
1152
+ }
1153
+ }, [
1154
+ model,
1155
+ editing
1156
+ ]);
1157
+ const handleAxisResize = useCallback3(({ axis, size, index: numericIndex }) => {
1158
+ Obj4.change(model.sheet, (sheet) => {
1159
+ if (axis === "row") {
1160
+ const rowId = sheet.rows[parseInt(numericIndex)];
1161
+ sheet.rowMeta[rowId] ??= {};
1162
+ sheet.rowMeta[rowId].size = size;
1163
+ } else {
1164
+ const columnId = sheet.columns[parseInt(numericIndex)];
1165
+ sheet.columnMeta[columnId] ??= {};
1166
+ sheet.columnMeta[columnId].size = size;
1167
+ }
1168
+ });
1169
+ }, [
1170
+ model
1171
+ ]);
1172
+ const handleSelect = useCallback3(({ minCol, maxCol, minRow, maxRow }) => {
1173
+ const range = {
1174
+ from: {
1175
+ col: minCol,
1176
+ row: minRow
1177
+ }
1178
+ };
1179
+ if (minCol !== maxCol || minRow !== maxRow) {
1180
+ range.to = {
1181
+ col: maxCol,
1182
+ row: maxRow
1183
+ };
1184
+ }
1185
+ if (editing) {
1186
+ rangeController.current?.setRange(rangeToA1Notation(range));
1187
+ } else {
1188
+ setRange(range.to ? range : void 0);
1189
+ }
1190
+ }, [
1191
+ editing
1192
+ ]);
1193
+ const handleWheel = useCallback3((event) => {
1194
+ if (!ignoreAttention && !hasAttention) {
1195
+ event.stopPropagation();
1196
+ }
1197
+ }, [
1198
+ hasAttention,
1199
+ ignoreAttention
1200
+ ]);
1201
+ const selectEntireAxis = useCallback3((pos) => {
1202
+ switch (pos.plane) {
1203
+ case "frozenRowsStart":
1204
+ return dxGrid?.setSelection({
1205
+ start: {
1206
+ col: pos.col,
1207
+ row: 0,
1208
+ plane: "grid"
1209
+ },
1210
+ end: {
1211
+ col: pos.col,
1212
+ row: model.sheet.rows.length - 1,
1213
+ plane: "grid"
1214
+ }
1215
+ });
1216
+ case "frozenColsStart":
1217
+ return dxGrid?.setSelection({
1218
+ start: {
1219
+ row: pos.row,
1220
+ col: 0,
1221
+ plane: "grid"
1222
+ },
1223
+ end: {
1224
+ row: pos.row,
1225
+ col: model.sheet.columns.length - 1,
1226
+ plane: "grid"
1227
+ }
1228
+ });
1229
+ }
1230
+ }, [
1231
+ dxGrid,
1232
+ model.sheet
1233
+ ]);
1234
+ const handleClick = useCallback3((event) => {
1235
+ const cell = closestCell(event.target);
1236
+ if (cell) {
1237
+ selectEntireAxis(cell);
1238
+ }
1239
+ }, [
1240
+ selectEntireAxis
1241
+ ]);
1242
+ const handleKeyDown = useCallback3((event) => {
1243
+ switch (event.key) {
1244
+ case "Backspace":
1245
+ case "Delete":
1246
+ event.preventDefault();
1247
+ return cursorFallbackRange && model.clear(cursorFallbackRange);
1248
+ case "Enter":
1249
+ case "Space":
1250
+ if (dxGrid && extraplanarFocus) {
1251
+ switch (extraplanarFocus.plane) {
1252
+ case "frozenRowsStart":
1253
+ case "frozenColsStart":
1254
+ event.preventDefault();
1255
+ return selectEntireAxis(extraplanarFocus);
1256
+ }
1257
+ }
1258
+ }
1259
+ if (event.metaKey || event.ctrlKey) {
1260
+ switch (event.key) {
1261
+ case "x":
1262
+ case "X":
1263
+ event.preventDefault();
1264
+ return cursorFallbackRange && model.cut(cursorFallbackRange);
1265
+ case "c":
1266
+ case "C":
1267
+ event.preventDefault();
1268
+ return cursorFallbackRange && model.copy(cursorFallbackRange);
1269
+ case "v":
1270
+ case "V":
1271
+ event.preventDefault();
1272
+ return cursor && model.paste(cursor);
1273
+ case "z":
1274
+ event.preventDefault();
1275
+ return event.shiftKey ? model.redo() : model.undo();
1276
+ case "Z":
1277
+ case "y":
1278
+ event.preventDefault();
1279
+ return model.redo();
1280
+ }
1281
+ }
1282
+ }, [
1283
+ cursorFallbackRange,
1284
+ model,
1285
+ cursor,
1286
+ extraplanarFocus,
1287
+ selectEntireAxis
1288
+ ]);
1289
+ const contextMenuAnchorRef = useRef(null);
1290
+ const [contextMenuOpen, setContextMenuOpen] = useState4(null);
1291
+ const contextMenuAxis = contextMenuOpen?.plane.startsWith("frozenRows") ? "col" : "row";
1292
+ const handleContextMenu = useCallback3((event) => {
1293
+ const cell = closestCell(event.target);
1294
+ if (cell && cell.plane.startsWith("frozen")) {
1295
+ event.preventDefault();
1296
+ contextMenuAnchorRef.current = event.target;
1297
+ setContextMenuOpen(cell);
1298
+ }
1299
+ }, []);
1300
+ const handleAxisMenuAction = useCallback3((operation) => {
1301
+ switch (operation) {
1302
+ case "insert-before":
1303
+ case "insert-after":
1304
+ return invokePromise(SheetOperation.InsertAxis, {
1305
+ model,
1306
+ axis: contextMenuAxis,
1307
+ index: contextMenuOpen[contextMenuAxis] + (operation === "insert-before" ? 0 : 1)
1308
+ });
1309
+ case "drop":
1310
+ return invokePromise(SheetOperation.DropAxis, {
1311
+ model,
1312
+ axis: contextMenuAxis,
1313
+ axisIndex: model.sheet[contextMenuAxis === "row" ? "rows" : "columns"][contextMenuOpen[contextMenuAxis]]
1314
+ });
1315
+ }
1316
+ }, [
1317
+ contextMenuAxis,
1318
+ contextMenuOpen,
1319
+ model,
1320
+ invokePromise
1321
+ ]);
1322
+ const { columns, rows } = useSheetModelDxGridProps(dxGrid, model);
1323
+ const extensions = useMemo2(() => [
1324
+ editorKeys({
1325
+ onClose: handleClose,
1326
+ ...editing?.initialContent && {
1327
+ onNav: handleClose
1328
+ }
1329
+ }),
1330
+ sheetExtension({
1331
+ functions: model.graph.getFunctions()
1332
+ }),
1333
+ rangeExtension({
1334
+ onInit: (fn) => rangeController.current = fn,
1335
+ onStateChange: (state) => {
1336
+ if (dxGrid) {
1337
+ dxGrid.mode = typeof state.activeRange === "undefined" ? "edit" : "edit-select";
1338
+ }
1339
+ }
1340
+ })
1341
+ ], [
1342
+ model,
1343
+ handleClose,
1344
+ editing
1345
+ ]);
1346
+ const getCellContent = useCallback3((index) => {
1347
+ return model.getCellText(parseCellIndex(index));
1348
+ }, [
1349
+ model
1350
+ ]);
1351
+ useUpdateFocusedCellOnThreadSelection(dxGrid);
1352
+ useSelectThreadOnCellFocus();
1353
+ return /* @__PURE__ */ React3.createElement("div", {
1354
+ ...rest,
1355
+ role: "none",
1356
+ className: mx2("relative min-h-0", className)
1357
+ }, /* @__PURE__ */ React3.createElement(GridCellEditor, {
1358
+ getCellContent,
1359
+ extensions,
1360
+ onBlur: handleBlur
1361
+ }), /* @__PURE__ */ React3.createElement(Grid2.Content, {
1362
+ className: "[--dx-grid-base:var(--base-surface)] [&_.dx-grid]:absolute [&_.dx-grid]:inset-0",
1363
+ initialCells,
1364
+ limitColumns: DEFAULT_COLS,
1365
+ limitRows: DEFAULT_ROWS,
1366
+ columns,
1367
+ rows,
1368
+ columnDefault: sheetColDefault,
1369
+ rowDefault: sheetRowDefault,
1370
+ activeRefs,
1371
+ frozen,
1372
+ overscroll: "trap",
1373
+ onAxisResize: handleAxisResize,
1374
+ onSelect: handleSelect,
1375
+ onFocus: handleFocus,
1376
+ onWheelCapture: handleWheel,
1377
+ onKeyDown: handleKeyDown,
1378
+ onContextMenu: handleContextMenu,
1379
+ onClick: handleClick,
1380
+ ref: setDxGrid
1381
+ }), /* @__PURE__ */ React3.createElement(DropdownMenu.Root, {
1382
+ modal: false,
1383
+ open: !!contextMenuOpen,
1384
+ onOpenChange: (nextOpen) => setContextMenuOpen(nextOpen ? inertPosition : null)
1385
+ }, /* @__PURE__ */ React3.createElement(DropdownMenu.VirtualTrigger, {
1386
+ virtualRef: contextMenuAnchorRef
1387
+ }), /* @__PURE__ */ React3.createElement(DropdownMenu.Content, {
1388
+ side: contextMenuAxis === "col" ? "bottom" : "right",
1389
+ sideOffset: 4,
1390
+ collisionPadding: 8
1391
+ }, /* @__PURE__ */ React3.createElement(DropdownMenu.Viewport, null, /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
1392
+ onClick: () => handleAxisMenuAction("insert-before"),
1393
+ "data-testid": `grid.${contextMenuAxis}.insert-before`
1394
+ }, /* @__PURE__ */ React3.createElement(Icon, {
1395
+ size: 5,
1396
+ icon: contextMenuAxis === "col" ? "ph--columns-plus-left--regular" : "ph--rows-plus-top--regular"
1397
+ }), /* @__PURE__ */ React3.createElement("span", null, t(`add ${contextMenuAxis} before label`))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
1398
+ onClick: () => handleAxisMenuAction("insert-after"),
1399
+ "data-testid": `grid.${contextMenuAxis}.insert-after`
1400
+ }, /* @__PURE__ */ React3.createElement(Icon, {
1401
+ size: 5,
1402
+ icon: contextMenuAxis === "col" ? "ph--columns-plus-right--regular" : "ph--rows-plus-bottom--regular"
1403
+ }), /* @__PURE__ */ React3.createElement("span", null, t(`add ${contextMenuAxis} after label`))), /* @__PURE__ */ React3.createElement(DropdownMenu.Item, {
1404
+ onClick: () => handleAxisMenuAction("drop"),
1405
+ "data-testid": `grid.${contextMenuAxis}.drop`
1406
+ }, /* @__PURE__ */ React3.createElement(Icon, {
1407
+ size: 5,
1408
+ icon: "ph--backspace--regular"
1409
+ }), /* @__PURE__ */ React3.createElement("span", null, t(`delete ${contextMenuAxis} label`)))), /* @__PURE__ */ React3.createElement(DropdownMenu.Arrow, null))));
1410
+ };
1411
+
1412
+ // src/components/SheetStatusbar/SheetStatusbar.tsx
1413
+ import React4 from "react";
1414
+ import { addressToA1Notation as addressToA1Notation2, isFormula as isFormula2, rangeToA1Notation as rangeToA1Notation2 } from "@dxos/compute";
1415
+ import { Icon as Icon2 } from "@dxos/react-ui";
1416
+ var SheetStatusbar = (props) => {
1417
+ const { model, cursor, range } = useSheetContext();
1418
+ let value;
1419
+ let formula = false;
1420
+ if (cursor) {
1421
+ value = model.getCellValue(cursor);
1422
+ if (isFormula2(value)) {
1423
+ value = model.graph.mapFunctionBindingFromId(mapFormulaIndicesToRefs(model.sheet, value));
1424
+ formula = true;
1425
+ } else if (value != null) {
1426
+ value = String(value);
1427
+ }
1428
+ }
1429
+ return /* @__PURE__ */ React4.createElement("div", {
1430
+ ...props,
1431
+ className: "flex shrink-0 justify-between items-center px-4 py-1 text-sm bg-toolbar-surface border-y !border-subdued-separator"
1432
+ }, /* @__PURE__ */ React4.createElement("div", {
1433
+ className: "flex gap-4 items-center"
1434
+ }, /* @__PURE__ */ React4.createElement("div", {
1435
+ className: "flex w-16 items-center font-mono"
1436
+ }, range && rangeToA1Notation2(range) || cursor && addressToA1Notation2(cursor)), /* @__PURE__ */ React4.createElement("div", {
1437
+ className: "flex gap-2 items-center"
1438
+ }, /* @__PURE__ */ React4.createElement(Icon2, {
1439
+ icon: "ph--function--regular",
1440
+ classNames: [
1441
+ "text-green-text",
1442
+ formula ? "visible" : "invisible"
1443
+ ]
1444
+ }), /* @__PURE__ */ React4.createElement("span", {
1445
+ className: "font-mono"
1446
+ }, value))));
1447
+ };
1448
+
1449
+ // src/components/SheetToolbar/SheetToolbar.tsx
1450
+ import { Atom as Atom2, RegistryContext as RegistryContext4 } from "@effect-atom/atom-react";
1451
+ import React5, { useContext as useContext6, useMemo as useMemo4 } from "react";
1452
+ import { useAppGraph } from "@dxos/app-toolkit/ui";
1453
+ import { Menu, createGapSeparator, useMenuActions } from "@dxos/react-ui-menu";
1454
+
1455
+ // src/components/SheetToolbar/align.ts
1456
+ import { RegistryContext } from "@effect-atom/atom-react";
1457
+ import { useContext as useContext3, useEffect as useEffect4 } from "react";
1458
+ import { inRange as inRange3 } from "@dxos/compute";
1459
+ import { Obj as Obj5 } from "@dxos/echo";
1460
+ import { createMenuAction, createMenuItemGroup } from "@dxos/react-ui-menu";
1461
+ var aligns = {
1462
+ start: "ph--text-align-left--regular",
1463
+ center: "ph--text-align-center--regular",
1464
+ end: "ph--text-align-right--regular"
1465
+ };
1466
+ var useAlignState = (stateAtom) => {
1467
+ const registry = useContext3(RegistryContext);
1468
+ const { cursor, model } = useSheetContext();
1469
+ useEffect4(() => {
1470
+ const alignValue = cursor ? model.sheet.ranges?.findLast(({ range, key }) => key === alignKey && inRange3(rangeFromIndex(model.sheet, range), cursor))?.value : void 0;
1471
+ const prev = registry.get(stateAtom);
1472
+ registry.set(stateAtom, {
1473
+ ...prev,
1474
+ [alignKey]: alignValue
1475
+ });
1476
+ }, [
1477
+ cursor,
1478
+ model.sheet,
1479
+ registry,
1480
+ stateAtom
1481
+ ]);
1482
+ };
1483
+ var createAlignGroupAction = (value) => createMenuItemGroup("align", {
1484
+ label: [
1485
+ "align label",
1486
+ {
1487
+ ns: meta.id
1488
+ }
1489
+ ],
1490
+ variant: "toggleGroup",
1491
+ selectCardinality: "single",
1492
+ value: `${alignKey}--${value}`
1493
+ });
1494
+ var createAlignActions = ({ model, state, stateAtom, registry, cursorFallbackRange }) => Object.entries(aligns).map(([alignValue, icon]) => {
1495
+ return createMenuAction(`${alignKey}--${alignValue}`, () => {
1496
+ if (!cursorFallbackRange) {
1497
+ return;
1498
+ }
1499
+ const index = model.sheet.ranges?.findIndex((range) => range.key === alignKey && inRange3(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from)) ?? -1;
1500
+ const nextRangeEntity = {
1501
+ range: rangeToIndex(model.sheet, cursorFallbackRange),
1502
+ key: alignKey,
1503
+ value: alignValue
1504
+ };
1505
+ const currentState = registry.get(stateAtom);
1506
+ if (index < 0) {
1507
+ Obj5.change(model.sheet, (obj) => {
1508
+ obj.ranges?.push(nextRangeEntity);
1509
+ });
1510
+ registry.set(stateAtom, {
1511
+ ...currentState,
1512
+ [alignKey]: nextRangeEntity.value
1513
+ });
1514
+ } else if (model.sheet.ranges[index].value === nextRangeEntity.value) {
1515
+ Obj5.change(model.sheet, (obj) => {
1516
+ obj.ranges?.splice(index, 1);
1517
+ });
1518
+ registry.set(stateAtom, {
1519
+ ...currentState,
1520
+ [alignKey]: void 0
1521
+ });
1522
+ } else {
1523
+ Obj5.change(model.sheet, (obj) => {
1524
+ obj.ranges?.splice(index, 1, nextRangeEntity);
1525
+ });
1526
+ registry.set(stateAtom, {
1527
+ ...currentState,
1528
+ [alignKey]: nextRangeEntity.value
1529
+ });
1530
+ }
1531
+ }, {
1532
+ key: alignKey,
1533
+ value: alignValue,
1534
+ checked: state[alignKey] === alignValue,
1535
+ label: [
1536
+ `range value ${alignValue} label`,
1537
+ {
1538
+ ns: meta.id
1539
+ }
1540
+ ],
1541
+ icon,
1542
+ testId: `grid.toolbar.${alignKey}.${alignValue}`
1543
+ });
1544
+ });
1545
+ var createAlign = (context) => {
1546
+ const alignGroup = createAlignGroupAction(context.state[alignKey]);
1547
+ const alignActions = createAlignActions(context);
1548
+ return {
1549
+ nodes: [
1550
+ alignGroup,
1551
+ ...alignActions
1552
+ ],
1553
+ edges: [
1554
+ {
1555
+ source: "root",
1556
+ target: "align",
1557
+ relation: "child"
1558
+ },
1559
+ ...alignActions.map(({ id }) => ({
1560
+ source: alignGroup.id,
1561
+ target: id,
1562
+ relation: "child"
1563
+ }))
1564
+ ]
1565
+ };
1566
+ };
1567
+
1568
+ // src/components/SheetToolbar/style.ts
1569
+ import { RegistryContext as RegistryContext2 } from "@effect-atom/atom-react";
1570
+ import { useContext as useContext4, useEffect as useEffect5 } from "react";
1571
+ import { inRange as inRange4 } from "@dxos/compute";
1572
+ import { Obj as Obj6 } from "@dxos/echo";
1573
+ import { createMenuAction as createMenuAction2, createMenuItemGroup as createMenuItemGroup2 } from "@dxos/react-ui-menu";
1574
+ var styles = {
1575
+ highlight: "ph--highlighter--regular",
1576
+ softwrap: "ph--paragraph--regular"
1577
+ };
1578
+ var useStyleState = (stateAtom) => {
1579
+ const registry = useContext4(RegistryContext2);
1580
+ const { cursorFallbackRange, model } = useSheetContext();
1581
+ useEffect5(() => {
1582
+ let highlight = false;
1583
+ let softwrap = false;
1584
+ if (cursorFallbackRange && model.sheet.ranges) {
1585
+ model.sheet.ranges.filter(({ range, key }) => key === "style" && inRange4(rangeFromIndex(model.sheet, range), cursorFallbackRange.from)).forEach(({ value }) => {
1586
+ if (value === "highlight") {
1587
+ highlight = true;
1588
+ }
1589
+ if (value === "softwrap") {
1590
+ softwrap = true;
1591
+ }
1592
+ });
1593
+ }
1594
+ const prev = registry.get(stateAtom);
1595
+ registry.set(stateAtom, {
1596
+ ...prev,
1597
+ highlight,
1598
+ softwrap
1599
+ });
1600
+ }, [
1601
+ cursorFallbackRange,
1602
+ model.sheet,
1603
+ registry,
1604
+ stateAtom
1605
+ ]);
1606
+ };
1607
+ var createStyleGroup = (state) => {
1608
+ return createMenuItemGroup2("style", {
1609
+ variant: "toggleGroup",
1610
+ selectCardinality: "multiple",
1611
+ value: Object.keys(styles).filter((key) => !!state[key]).map((styleValue) => `style--${styleValue}`)
1612
+ });
1613
+ };
1614
+ var createStyleActions = ({ model, state, stateAtom, registry, cursorFallbackRange }) => Object.entries(styles).map(([styleValue, icon]) => {
1615
+ return createMenuAction2(`style--${styleValue}`, () => {
1616
+ if (!cursorFallbackRange) {
1617
+ return;
1618
+ }
1619
+ const index = model.sheet.ranges?.findIndex((range) => range.key === "style" && inRange4(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from)) ?? -1;
1620
+ const nextRangeEntity = {
1621
+ range: rangeToIndex(model.sheet, cursorFallbackRange),
1622
+ key: "style",
1623
+ value: styleValue
1624
+ };
1625
+ const currentState = registry.get(stateAtom);
1626
+ if (model.sheet.ranges.filter(({ range, key: rangeKey }) => rangeKey === "style" && inRange4(rangeFromIndex(model.sheet, range), cursorFallbackRange.from)).some(({ value: rangeValue }) => rangeValue === styleValue)) {
1627
+ if (index >= 0) {
1628
+ Obj6.change(model.sheet, (obj) => {
1629
+ obj.ranges?.splice(index, 1);
1630
+ });
1631
+ }
1632
+ registry.set(stateAtom, {
1633
+ ...currentState,
1634
+ [nextRangeEntity.value]: false
1635
+ });
1636
+ } else {
1637
+ Obj6.change(model.sheet, (obj) => {
1638
+ obj.ranges?.push(nextRangeEntity);
1639
+ });
1640
+ registry.set(stateAtom, {
1641
+ ...currentState,
1642
+ [nextRangeEntity.value]: true
1643
+ });
1644
+ }
1645
+ }, {
1646
+ key: "style",
1647
+ value: styleValue,
1648
+ icon,
1649
+ label: [
1650
+ `range value ${styleValue} label`,
1651
+ {
1652
+ ns: meta.id
1653
+ }
1654
+ ],
1655
+ checked: !!state[styleValue]
1656
+ });
1657
+ });
1658
+ var createStyle = (context) => {
1659
+ const styleGroupAction = createStyleGroup(context.state);
1660
+ const styleActions = createStyleActions(context);
1661
+ return {
1662
+ nodes: [
1663
+ styleGroupAction,
1664
+ ...styleActions
1665
+ ],
1666
+ edges: [
1667
+ {
1668
+ source: "root",
1669
+ target: "style",
1670
+ relation: "child"
1671
+ },
1672
+ ...styleActions.map(({ id }) => ({
1673
+ source: styleGroupAction.id,
1674
+ target: id,
1675
+ relation: "child"
1676
+ }))
1677
+ ]
1678
+ };
1679
+ };
1680
+
1681
+ // src/components/SheetToolbar/useToolbarState.ts
1682
+ import { Atom, RegistryContext as RegistryContext3, useAtomValue } from "@effect-atom/atom-react";
1683
+ import { useContext as useContext5, useMemo as useMemo3 } from "react";
1684
+ var useToolbarState = (initialState = {}) => {
1685
+ return useMemo3(() => Atom.make(initialState).pipe(Atom.keepAlive), []);
1686
+ };
1687
+
1688
+ // src/components/SheetToolbar/SheetToolbar.tsx
1689
+ var createToolbarActions = ({ model, stateAtom, registry, cursorFallbackRange, customActions }) => {
1690
+ return Atom2.make((get) => {
1691
+ const state = get(stateAtom);
1692
+ const context = {
1693
+ model,
1694
+ state,
1695
+ stateAtom,
1696
+ registry,
1697
+ cursorFallbackRange
1698
+ };
1699
+ const align = createAlign(context);
1700
+ const style = createStyle(context);
1701
+ const gap = createGapSeparator();
1702
+ const graph = {
1703
+ nodes: [
1704
+ ...align.nodes,
1705
+ ...style.nodes,
1706
+ ...gap.nodes
1707
+ ],
1708
+ edges: [
1709
+ ...align.edges,
1710
+ ...style.edges,
1711
+ ...gap.edges
1712
+ ]
1713
+ };
1714
+ if (customActions) {
1715
+ const custom = get(customActions);
1716
+ graph.nodes.push(...custom.nodes);
1717
+ graph.edges.push(...custom.edges);
1718
+ }
1719
+ return graph;
1720
+ });
1721
+ };
1722
+ var SheetToolbar = ({ id, ...props }) => {
1723
+ const { model, cursorFallbackRange } = useSheetContext();
1724
+ const stateAtom = useToolbarState({});
1725
+ const registry = useContext6(RegistryContext4);
1726
+ useAlignState(stateAtom);
1727
+ useStyleState(stateAtom);
1728
+ const { graph } = useAppGraph();
1729
+ const customActions = useMemo4(() => {
1730
+ return Atom2.make((get) => {
1731
+ const actions = get(graph.actions(id));
1732
+ const nodes = actions.filter((action) => action.properties.disposition === "toolbar");
1733
+ return {
1734
+ nodes,
1735
+ edges: nodes.map((node) => ({
1736
+ source: "root",
1737
+ target: node.id,
1738
+ relation: "child"
1739
+ }))
1740
+ };
1741
+ });
1742
+ }, [
1743
+ graph,
1744
+ id
1745
+ ]);
1746
+ const actionsCreator = useMemo4(() => createToolbarActions({
1747
+ model,
1748
+ stateAtom,
1749
+ registry,
1750
+ cursorFallbackRange,
1751
+ customActions
1752
+ }), [
1753
+ model,
1754
+ stateAtom,
1755
+ registry,
1756
+ cursorFallbackRange,
1757
+ customActions
1758
+ ]);
1759
+ const menu = useMenuActions(actionsCreator);
1760
+ return /* @__PURE__ */ React5.createElement(Menu.Root, {
1761
+ ...props,
1762
+ ...menu,
1763
+ attendableId: id
1764
+ }, /* @__PURE__ */ React5.createElement(Menu.Toolbar, null));
1765
+ };
1766
+
1767
+ // src/components/Sheet/Sheet.tsx
1768
+ var Sheet = {
1769
+ Root: SheetRoot,
1770
+ Toolbar: SheetToolbar,
1771
+ Content: SheetContent,
1772
+ Statusbar: SheetStatusbar
1773
+ };
1774
+
1775
+ // src/containers/SheetContainer/SheetContainer.tsx
1776
+ var SheetContainer = ({ registry, ...props }) => /* @__PURE__ */ React6.createElement(ComputeGraphContextProvider, {
1777
+ registry
1778
+ }, /* @__PURE__ */ React6.createElement(SheetContainerInner, props));
1779
+ var SheetContainerInner = ({ role, subject: sheet, space, ignoreAttention }) => {
1780
+ const graph = useComputeGraph(space);
1781
+ if (!graph) {
1782
+ return null;
1783
+ }
1784
+ return /* @__PURE__ */ React6.createElement(Sheet.Root, {
1785
+ graph,
1786
+ sheet,
1787
+ ignoreAttention
1788
+ }, /* @__PURE__ */ React6.createElement(Panel.Root, {
1789
+ classNames: role === "section" && "aspect-aquare"
1790
+ }, /* @__PURE__ */ React6.createElement(Panel.Toolbar, {
1791
+ asChild: true
1792
+ }, /* @__PURE__ */ React6.createElement(Sheet.Toolbar, {
1793
+ id: Obj7.getDXN(sheet).toString()
1794
+ })), /* @__PURE__ */ React6.createElement(Panel.Content, {
1795
+ asChild: true
1796
+ }, /* @__PURE__ */ React6.createElement(Sheet.Content, null)), /* @__PURE__ */ React6.createElement(Panel.Statusbar, {
1797
+ asChild: true
1798
+ }, /* @__PURE__ */ React6.createElement(Sheet.Statusbar, null))));
1799
+ };
1800
+
1801
+ // src/containers/SheetContainer/index.ts
1802
+ var SheetContainer_default = SheetContainer;
1803
+ export {
1804
+ SheetContainer_default as default
1805
+ };
1806
+ //# sourceMappingURL=SheetContainer-KUXNCSFP.mjs.map