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