@dxos/plugin-sheet 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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