@dxos/plugin-sheet 0.8.4-main.f9ba587 → 0.8.4-staging.60fe92afc8

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 (395) hide show
  1. package/LICENSE +102 -5
  2. package/PLUGIN.mdl +359 -0
  3. package/dist/lib/neutral/RangeList-HYB5S6KQ.mjs +46 -0
  4. package/dist/lib/neutral/RangeList-HYB5S6KQ.mjs.map +7 -0
  5. package/dist/lib/neutral/SheetArticle-5AJRM3V3.mjs +33 -0
  6. package/dist/lib/neutral/SheetArticle-5AJRM3V3.mjs.map +7 -0
  7. package/dist/lib/neutral/SheetPlugin.mjs +63 -0
  8. package/dist/lib/neutral/SheetPlugin.mjs.map +7 -0
  9. package/dist/lib/neutral/SheetPlugin.node.mjs +27 -0
  10. package/dist/lib/neutral/SheetPlugin.node.mjs.map +7 -0
  11. package/dist/lib/neutral/SheetPlugin.workerd.mjs +21 -0
  12. package/dist/lib/neutral/SheetPlugin.workerd.mjs.map +7 -0
  13. package/dist/lib/neutral/anchor-sort-2POWTKTD.mjs +22 -0
  14. package/dist/lib/neutral/anchor-sort-2POWTKTD.mjs.map +7 -0
  15. package/dist/lib/neutral/app-graph-builder-2QP6GYB2.mjs +67 -0
  16. package/dist/lib/neutral/app-graph-builder-2QP6GYB2.mjs.map +7 -0
  17. package/dist/lib/neutral/capabilities/index.mjs +29 -0
  18. package/dist/lib/neutral/capabilities/index.mjs.map +7 -0
  19. package/dist/lib/neutral/chunk-BGR7FVNF.mjs +8 -0
  20. package/dist/lib/neutral/chunk-BGR7FVNF.mjs.map +7 -0
  21. package/dist/lib/{browser/chunk-7HQX4NQP.mjs → neutral/chunk-ERHMBRSU.mjs} +16 -16
  22. package/dist/lib/neutral/chunk-ERHMBRSU.mjs.map +7 -0
  23. package/dist/lib/neutral/chunk-FQHTXKMF.mjs +34 -0
  24. package/dist/lib/neutral/chunk-FQHTXKMF.mjs.map +7 -0
  25. package/dist/lib/neutral/chunk-HEN74ZWI.mjs +83 -0
  26. package/dist/lib/neutral/chunk-HEN74ZWI.mjs.map +7 -0
  27. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  28. package/dist/lib/neutral/chunk-KUWATEHB.mjs +374 -0
  29. package/dist/lib/neutral/chunk-KUWATEHB.mjs.map +7 -0
  30. package/dist/lib/neutral/chunk-S2UNH6VD.mjs +10 -0
  31. package/dist/lib/neutral/chunk-S2UNH6VD.mjs.map +7 -0
  32. package/dist/lib/neutral/comment-config-WGXXX5FG.mjs +22 -0
  33. package/dist/lib/neutral/comment-config-WGXXX5FG.mjs.map +7 -0
  34. package/dist/lib/neutral/components/index.mjs +1552 -0
  35. package/dist/lib/neutral/components/index.mjs.map +7 -0
  36. package/dist/lib/neutral/compute-graph-registry-YYINTFC2.mjs +26 -0
  37. package/dist/lib/neutral/compute-graph-registry-YYINTFC2.mjs.map +7 -0
  38. package/dist/lib/neutral/containers/index.mjs +11 -0
  39. package/dist/lib/neutral/containers/index.mjs.map +7 -0
  40. package/dist/lib/neutral/create-object-TDQQ24IB.mjs +31 -0
  41. package/dist/lib/neutral/create-object-TDQQ24IB.mjs.map +7 -0
  42. package/dist/lib/neutral/drop-axis-WSWFOLQN.mjs +23 -0
  43. package/dist/lib/neutral/drop-axis-WSWFOLQN.mjs.map +7 -0
  44. package/dist/lib/{node-esm/types → neutral}/index.mjs +22 -13
  45. package/dist/lib/neutral/insert-axis-6UQJTIWC.mjs +16 -0
  46. package/dist/lib/neutral/insert-axis-6UQJTIWC.mjs.map +7 -0
  47. package/dist/lib/neutral/markdown-extension-HTJDICGT.mjs +28 -0
  48. package/dist/lib/neutral/markdown-extension-HTJDICGT.mjs.map +7 -0
  49. package/dist/lib/neutral/meta.json +1 -0
  50. package/dist/lib/neutral/meta.mjs +8 -0
  51. package/dist/lib/neutral/meta.mjs.map +7 -0
  52. package/dist/lib/neutral/navigation-resolver-FXEZYO7G.mjs +14 -0
  53. package/dist/lib/neutral/navigation-resolver-FXEZYO7G.mjs.map +7 -0
  54. package/dist/lib/neutral/operation-handler-TB6LFV2H.mjs +13 -0
  55. package/dist/lib/neutral/operation-handler-TB6LFV2H.mjs.map +7 -0
  56. package/dist/lib/neutral/operations/index.mjs +8 -0
  57. package/dist/lib/neutral/operations/index.mjs.map +7 -0
  58. package/dist/lib/neutral/plugin.mjs +16 -0
  59. package/dist/lib/neutral/plugin.mjs.map +7 -0
  60. package/dist/lib/neutral/react-surface-4H3PC4WG.mjs +44 -0
  61. package/dist/lib/neutral/react-surface-4H3PC4WG.mjs.map +7 -0
  62. package/dist/lib/neutral/restore-axis-AMMVTPS3.mjs +16 -0
  63. package/dist/lib/neutral/restore-axis-AMMVTPS3.mjs.map +7 -0
  64. package/dist/lib/neutral/scroll-to-anchor-FK2CXCQR.mjs +33 -0
  65. package/dist/lib/neutral/scroll-to-anchor-FK2CXCQR.mjs.map +7 -0
  66. package/dist/lib/neutral/state-HPA27MX2.mjs +29 -0
  67. package/dist/lib/neutral/state-HPA27MX2.mjs.map +7 -0
  68. package/dist/lib/neutral/testing/index.mjs +103 -0
  69. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  70. package/dist/lib/neutral/translations.mjs +56 -0
  71. package/dist/lib/neutral/translations.mjs.map +7 -0
  72. package/dist/lib/{browser → neutral}/types/index.mjs +8 -12
  73. package/dist/lib/neutral/types/index.mjs.map +7 -0
  74. package/dist/lib/neutral/undo-mappings-3FQLSTCZ.mjs +31 -0
  75. package/dist/lib/neutral/undo-mappings-3FQLSTCZ.mjs.map +7 -0
  76. package/dist/types/src/SheetPlugin.d.ts +3 -1
  77. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  78. package/dist/types/src/SheetPlugin.node.d.ts +4 -0
  79. package/dist/types/src/SheetPlugin.node.d.ts.map +1 -0
  80. package/dist/types/src/SheetPlugin.test.d.ts +2 -0
  81. package/dist/types/src/SheetPlugin.test.d.ts.map +1 -0
  82. package/dist/types/src/SheetPlugin.workerd.d.ts +4 -0
  83. package/dist/types/src/SheetPlugin.workerd.d.ts.map +1 -0
  84. package/dist/types/src/capabilities/anchor-sort.d.ts +4 -4
  85. package/dist/types/src/capabilities/anchor-sort.d.ts.map +1 -1
  86. package/dist/types/src/capabilities/app-graph-builder.d.ts +6 -0
  87. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -0
  88. package/dist/types/src/capabilities/comment-config.d.ts +6 -0
  89. package/dist/types/src/capabilities/comment-config.d.ts.map +1 -0
  90. package/dist/types/src/capabilities/compute-graph-registry.d.ts +9 -2
  91. package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +1 -1
  92. package/dist/types/src/capabilities/create-object.d.ts +11 -0
  93. package/dist/types/src/capabilities/create-object.d.ts.map +1 -0
  94. package/dist/types/src/capabilities/index.d.ts +19 -11
  95. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  96. package/dist/types/src/capabilities/markdown-extension.d.ts +5 -0
  97. package/dist/types/src/capabilities/markdown-extension.d.ts.map +1 -0
  98. package/dist/types/src/capabilities/navigation-resolver.d.ts +6 -0
  99. package/dist/types/src/capabilities/navigation-resolver.d.ts.map +1 -0
  100. package/dist/types/src/capabilities/operation-handler.d.ts +6 -0
  101. package/dist/types/src/capabilities/operation-handler.d.ts.map +1 -0
  102. package/dist/types/src/capabilities/react-surface.d.ts +3 -2
  103. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  104. package/dist/types/src/capabilities/state.d.ts +6 -0
  105. package/dist/types/src/capabilities/state.d.ts.map +1 -0
  106. package/dist/types/src/capabilities/undo-mappings.d.ts +5 -0
  107. package/dist/types/src/capabilities/undo-mappings.d.ts.map +1 -0
  108. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +1 -1
  109. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -1
  110. package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts +9 -4
  111. package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts.map +1 -1
  112. package/dist/types/src/components/Sheet/Sheet.d.ts +17 -0
  113. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
  114. package/dist/types/src/components/Sheet/index.d.ts +2 -0
  115. package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
  116. package/dist/types/src/components/SheetContent/SheetCellEditor.stories.d.ts +16 -0
  117. package/dist/types/src/components/SheetContent/SheetCellEditor.stories.d.ts.map +1 -0
  118. package/dist/types/src/components/SheetContent/SheetContent.d.ts +6 -0
  119. package/dist/types/src/components/SheetContent/SheetContent.d.ts.map +1 -0
  120. package/dist/types/src/components/SheetContent/SheetContent.stories.d.ts +93 -0
  121. package/dist/types/src/components/SheetContent/SheetContent.stories.d.ts.map +1 -0
  122. package/dist/types/src/components/SheetContent/index.d.ts +2 -0
  123. package/dist/types/src/components/SheetContent/index.d.ts.map +1 -0
  124. package/dist/types/src/components/{GridSheet → SheetContent}/util.d.ts +2 -2
  125. package/dist/types/src/components/SheetContent/util.d.ts.map +1 -0
  126. package/dist/types/src/components/{SheetContext/SheetContext.d.ts → SheetRoot/SheetRoot.d.ts} +9 -7
  127. package/dist/types/src/components/SheetRoot/SheetRoot.d.ts.map +1 -0
  128. package/dist/types/src/components/SheetRoot/index.d.ts +2 -0
  129. package/dist/types/src/components/SheetRoot/index.d.ts.map +1 -0
  130. package/dist/types/src/components/SheetStatusbar/SheetStatusbar.d.ts +6 -0
  131. package/dist/types/src/components/SheetStatusbar/SheetStatusbar.d.ts.map +1 -0
  132. package/dist/types/src/components/SheetStatusbar/index.d.ts +2 -0
  133. package/dist/types/src/components/SheetStatusbar/index.d.ts.map +1 -0
  134. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts +5 -6
  135. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
  136. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +92 -4
  137. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -1
  138. package/dist/types/src/components/SheetToolbar/align.d.ts +14 -21
  139. package/dist/types/src/components/SheetToolbar/align.d.ts.map +1 -1
  140. package/dist/types/src/components/SheetToolbar/style.d.ts +14 -20
  141. package/dist/types/src/components/SheetToolbar/style.d.ts.map +1 -1
  142. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts +14 -1
  143. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts.map +1 -1
  144. package/dist/types/src/components/index.d.ts +1 -4
  145. package/dist/types/src/components/index.d.ts.map +1 -1
  146. package/dist/types/src/containers/RangeList/RangeList.d.ts +7 -0
  147. package/dist/types/src/containers/RangeList/RangeList.d.ts.map +1 -0
  148. package/dist/types/src/containers/RangeList/index.d.ts +2 -0
  149. package/dist/types/src/containers/RangeList/index.d.ts.map +1 -0
  150. package/dist/types/src/containers/SheetArticle/SheetArticle.d.ts +12 -0
  151. package/dist/types/src/containers/SheetArticle/SheetArticle.d.ts.map +1 -0
  152. package/dist/types/src/containers/SheetArticle/SheetArticle.stories.d.ts +92 -0
  153. package/dist/types/src/containers/SheetArticle/SheetArticle.stories.d.ts.map +1 -0
  154. package/dist/types/src/containers/SheetArticle/index.d.ts +2 -0
  155. package/dist/types/src/containers/SheetArticle/index.d.ts.map +1 -0
  156. package/dist/types/src/containers/index.d.ts +4 -0
  157. package/dist/types/src/containers/index.d.ts.map +1 -0
  158. package/dist/types/src/extensions/compute.d.ts +2 -2
  159. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  160. package/dist/types/src/extensions/compute.stories.d.ts +10 -13
  161. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  162. package/dist/types/src/extensions/editor/index.d.ts +1 -1
  163. package/dist/types/src/extensions/editor/index.d.ts.map +1 -1
  164. package/dist/types/src/extensions/editor/{extension.d.ts → sheet-extension.d.ts} +2 -2
  165. package/dist/types/src/extensions/editor/sheet-extension.d.ts.map +1 -0
  166. package/dist/types/src/extensions/editor/sheet-extension.test.d.ts +2 -0
  167. package/dist/types/src/extensions/editor/sheet-extension.test.d.ts.map +1 -0
  168. package/dist/types/src/index.d.ts +3 -2
  169. package/dist/types/src/index.d.ts.map +1 -1
  170. package/dist/types/src/integrations/thread-ranges.d.ts +1 -3
  171. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
  172. package/dist/types/src/meta.d.ts +2 -3
  173. package/dist/types/src/meta.d.ts.map +1 -1
  174. package/dist/types/src/model/sheet-model.d.ts +31 -7
  175. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  176. package/dist/types/src/model/testing.d.ts +2 -2
  177. package/dist/types/src/model/testing.d.ts.map +1 -1
  178. package/dist/types/src/model/useSheetModel.d.ts +3 -3
  179. package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
  180. package/dist/types/src/operations/drop-axis.d.ts +5 -0
  181. package/dist/types/src/operations/drop-axis.d.ts.map +1 -0
  182. package/dist/types/src/operations/index.d.ts +3 -0
  183. package/dist/types/src/operations/index.d.ts.map +1 -0
  184. package/dist/types/src/operations/insert-axis.d.ts +5 -0
  185. package/dist/types/src/operations/insert-axis.d.ts.map +1 -0
  186. package/dist/types/src/operations/restore-axis.d.ts +5 -0
  187. package/dist/types/src/operations/restore-axis.d.ts.map +1 -0
  188. package/dist/types/src/operations/scroll-to-anchor.d.ts +5 -0
  189. package/dist/types/src/operations/scroll-to-anchor.d.ts.map +1 -0
  190. package/dist/types/src/paths.d.ts +3 -0
  191. package/dist/types/src/paths.d.ts.map +1 -0
  192. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  193. package/dist/types/src/playwright/sheet-manager.d.ts +1 -1
  194. package/dist/types/src/playwright/sheet-manager.d.ts.map +1 -1
  195. package/dist/types/src/plugin.d.ts +4 -0
  196. package/dist/types/src/plugin.d.ts.map +1 -0
  197. package/dist/types/src/serializer.d.ts +3 -3
  198. package/dist/types/src/serializer.d.ts.map +1 -1
  199. package/dist/types/src/testing/data.d.ts +2 -2
  200. package/dist/types/src/testing/data.d.ts.map +1 -1
  201. package/dist/types/src/testing/testing.d.ts +28 -4
  202. package/dist/types/src/testing/testing.d.ts.map +1 -1
  203. package/dist/types/src/translations.d.ts +74 -36
  204. package/dist/types/src/translations.d.ts.map +1 -1
  205. package/dist/types/src/types/Sheet.d.ts +75 -0
  206. package/dist/types/src/types/Sheet.d.ts.map +1 -0
  207. package/dist/types/src/types/SheetCapabilities.d.ts +16 -0
  208. package/dist/types/src/types/SheetCapabilities.d.ts.map +1 -0
  209. package/dist/types/src/types/SheetOperation.d.ts +45 -0
  210. package/dist/types/src/types/SheetOperation.d.ts.map +1 -0
  211. package/dist/types/src/types/index.d.ts +3 -1
  212. package/dist/types/src/types/index.d.ts.map +1 -1
  213. package/dist/types/src/types/sheet-range-types.d.ts +2 -2
  214. package/dist/types/src/types/sheet-range-types.d.ts.map +1 -1
  215. package/dist/types/src/types/types.d.ts +3 -78
  216. package/dist/types/src/types/types.d.ts.map +1 -1
  217. package/dist/types/src/types/util.d.ts +11 -11
  218. package/dist/types/src/types/util.d.ts.map +1 -1
  219. package/dist/types/tsconfig.tsbuildinfo +1 -1
  220. package/package.json +133 -97
  221. package/src/SheetPlugin.node.ts +21 -0
  222. package/src/SheetPlugin.test.ts +30 -0
  223. package/src/SheetPlugin.tsx +55 -68
  224. package/src/SheetPlugin.workerd.ts +18 -0
  225. package/src/capabilities/anchor-sort.ts +20 -15
  226. package/src/capabilities/app-graph-builder.ts +63 -0
  227. package/src/capabilities/comment-config.ts +28 -0
  228. package/src/capabilities/compute-graph-registry.ts +34 -20
  229. package/src/capabilities/create-object.ts +33 -0
  230. package/src/capabilities/index.ts +22 -8
  231. package/src/capabilities/markdown-extension.ts +31 -0
  232. package/src/capabilities/navigation-resolver.ts +16 -0
  233. package/src/capabilities/operation-handler.ts +16 -0
  234. package/src/capabilities/react-surface.tsx +38 -28
  235. package/src/capabilities/state.ts +29 -0
  236. package/src/capabilities/undo-mappings.ts +30 -0
  237. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +2 -2
  238. package/src/components/ComputeGraph/compute-graph.stories.tsx +38 -29
  239. package/src/components/Sheet/Sheet.tsx +20 -0
  240. package/src/components/Sheet/index.ts +5 -0
  241. package/src/components/SheetContent/SheetCellEditor.stories.tsx +95 -0
  242. package/src/components/SheetContent/SheetContent.stories.tsx +60 -0
  243. package/src/components/{GridSheet/GridSheet.tsx → SheetContent/SheetContent.tsx} +100 -69
  244. package/src/components/{RangeList → SheetContent}/index.ts +1 -1
  245. package/src/components/{GridSheet → SheetContent}/util.ts +23 -16
  246. package/src/components/{SheetContext/SheetContext.tsx → SheetRoot/SheetRoot.tsx} +55 -42
  247. package/src/components/{GridSheet → SheetRoot}/index.ts +1 -1
  248. package/src/components/{FunctionEditor/FunctionEditor.tsx → SheetStatusbar/SheetStatusbar.tsx} +20 -7
  249. package/src/components/{FunctionEditor → SheetStatusbar}/index.ts +1 -1
  250. package/src/components/SheetToolbar/SheetToolbar.stories.tsx +20 -14
  251. package/src/components/SheetToolbar/SheetToolbar.tsx +62 -56
  252. package/src/components/SheetToolbar/align.ts +50 -24
  253. package/src/components/SheetToolbar/style.ts +52 -22
  254. package/src/components/SheetToolbar/useToolbarState.ts +22 -5
  255. package/src/components/index.ts +1 -7
  256. package/src/containers/RangeList/RangeList.tsx +65 -0
  257. package/src/containers/RangeList/index.ts +5 -0
  258. package/src/containers/SheetArticle/SheetArticle.stories.tsx +110 -0
  259. package/src/containers/SheetArticle/SheetArticle.tsx +57 -0
  260. package/src/containers/SheetArticle/index.ts +5 -0
  261. package/src/containers/index.ts +8 -0
  262. package/src/extensions/compute.stories.tsx +50 -36
  263. package/src/extensions/compute.ts +4 -5
  264. package/src/extensions/editor/index.ts +1 -1
  265. package/src/extensions/editor/{extension.test.ts → sheet-extension.test.ts} +2 -2
  266. package/src/extensions/editor/{extension.ts → sheet-extension.ts} +18 -15
  267. package/src/index.ts +3 -2
  268. package/src/integrations/thread-ranges.ts +22 -63
  269. package/src/meta.ts +22 -8
  270. package/src/model/sheet-model.test.ts +35 -6
  271. package/src/model/sheet-model.ts +89 -57
  272. package/src/model/testing.ts +5 -5
  273. package/src/model/useSheetModel.ts +4 -3
  274. package/src/operations/drop-axis.ts +26 -0
  275. package/src/operations/index.ts +12 -0
  276. package/src/operations/insert-axis.ts +19 -0
  277. package/src/operations/restore-axis.ts +19 -0
  278. package/src/operations/scroll-to-anchor.ts +30 -0
  279. package/src/paths.ts +11 -0
  280. package/src/playwright/playwright.config.ts +1 -1
  281. package/src/playwright/sheet-manager.ts +1 -1
  282. package/src/playwright/sheet.spec.ts +5 -4
  283. package/src/plugin.ts +11 -0
  284. package/src/sanity.test.ts +10 -4
  285. package/src/serializer.ts +4 -12
  286. package/src/testing/data.ts +2 -2
  287. package/src/testing/testing.tsx +13 -7
  288. package/src/translations.ts +43 -34
  289. package/src/types/Sheet.ts +97 -0
  290. package/src/types/SheetCapabilities.ts +26 -0
  291. package/src/types/SheetOperation.ts +84 -0
  292. package/src/types/index.ts +4 -1
  293. package/src/types/sheet-range-types.ts +5 -5
  294. package/src/types/types.ts +6 -51
  295. package/src/types/util.ts +18 -45
  296. package/src/vite-env.d.ts +10 -0
  297. package/dist/lib/browser/SheetContainer-6IWQKRJC.mjs +0 -351
  298. package/dist/lib/browser/SheetContainer-6IWQKRJC.mjs.map +0 -7
  299. package/dist/lib/browser/anchor-sort-VHURGBOY.mjs +0 -24
  300. package/dist/lib/browser/anchor-sort-VHURGBOY.mjs.map +0 -7
  301. package/dist/lib/browser/chunk-6AKBCBL4.mjs +0 -18
  302. package/dist/lib/browser/chunk-6AKBCBL4.mjs.map +0 -7
  303. package/dist/lib/browser/chunk-7HQX4NQP.mjs.map +0 -7
  304. package/dist/lib/browser/chunk-KJWZUQVA.mjs +0 -15
  305. package/dist/lib/browser/chunk-KJWZUQVA.mjs.map +0 -7
  306. package/dist/lib/browser/chunk-SI4X5GUR.mjs +0 -892
  307. package/dist/lib/browser/chunk-SI4X5GUR.mjs.map +0 -7
  308. package/dist/lib/browser/chunk-ULWNSP4B.mjs +0 -847
  309. package/dist/lib/browser/chunk-ULWNSP4B.mjs.map +0 -7
  310. package/dist/lib/browser/compute-graph-registry-VG7VP7IV.mjs +0 -30
  311. package/dist/lib/browser/compute-graph-registry-VG7VP7IV.mjs.map +0 -7
  312. package/dist/lib/browser/index.mjs +0 -153
  313. package/dist/lib/browser/index.mjs.map +0 -7
  314. package/dist/lib/browser/intent-resolver-WOJGZMSV.mjs +0 -56
  315. package/dist/lib/browser/intent-resolver-WOJGZMSV.mjs.map +0 -7
  316. package/dist/lib/browser/markdown-VXMIPUQC.mjs +0 -26
  317. package/dist/lib/browser/markdown-VXMIPUQC.mjs.map +0 -7
  318. package/dist/lib/browser/meta.json +0 -1
  319. package/dist/lib/browser/react-surface-DAHMBIQW.mjs +0 -53
  320. package/dist/lib/browser/react-surface-DAHMBIQW.mjs.map +0 -7
  321. package/dist/lib/node-esm/SheetContainer-SW55KKOT.mjs +0 -352
  322. package/dist/lib/node-esm/SheetContainer-SW55KKOT.mjs.map +0 -7
  323. package/dist/lib/node-esm/anchor-sort-CTJGOPET.mjs +0 -25
  324. package/dist/lib/node-esm/anchor-sort-CTJGOPET.mjs.map +0 -7
  325. package/dist/lib/node-esm/chunk-3K5VNYOF.mjs +0 -20
  326. package/dist/lib/node-esm/chunk-3K5VNYOF.mjs.map +0 -7
  327. package/dist/lib/node-esm/chunk-6SK5LJ5S.mjs +0 -16
  328. package/dist/lib/node-esm/chunk-6SK5LJ5S.mjs.map +0 -7
  329. package/dist/lib/node-esm/chunk-CADTJFAS.mjs +0 -893
  330. package/dist/lib/node-esm/chunk-CADTJFAS.mjs.map +0 -7
  331. package/dist/lib/node-esm/chunk-Q6UYC4G5.mjs +0 -236
  332. package/dist/lib/node-esm/chunk-Q6UYC4G5.mjs.map +0 -7
  333. package/dist/lib/node-esm/chunk-VEGX32AT.mjs +0 -848
  334. package/dist/lib/node-esm/chunk-VEGX32AT.mjs.map +0 -7
  335. package/dist/lib/node-esm/compute-graph-registry-3K3Q2A5T.mjs +0 -31
  336. package/dist/lib/node-esm/compute-graph-registry-3K3Q2A5T.mjs.map +0 -7
  337. package/dist/lib/node-esm/index.mjs +0 -154
  338. package/dist/lib/node-esm/index.mjs.map +0 -7
  339. package/dist/lib/node-esm/intent-resolver-PZRXBNIJ.mjs +0 -57
  340. package/dist/lib/node-esm/intent-resolver-PZRXBNIJ.mjs.map +0 -7
  341. package/dist/lib/node-esm/markdown-4VPQJZNZ.mjs +0 -27
  342. package/dist/lib/node-esm/markdown-4VPQJZNZ.mjs.map +0 -7
  343. package/dist/lib/node-esm/meta.json +0 -1
  344. package/dist/lib/node-esm/react-surface-Z7TVWQ4V.mjs +0 -54
  345. package/dist/lib/node-esm/react-surface-Z7TVWQ4V.mjs.map +0 -7
  346. package/dist/types/src/capabilities/capabilities.d.ts +0 -5
  347. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  348. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  349. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  350. package/dist/types/src/capabilities/markdown.d.ts +0 -6
  351. package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
  352. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +0 -3
  353. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +0 -1
  354. package/dist/types/src/components/FunctionEditor/index.d.ts +0 -2
  355. package/dist/types/src/components/FunctionEditor/index.d.ts.map +0 -1
  356. package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -3
  357. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
  358. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +0 -7
  359. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
  360. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts +0 -25
  361. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +0 -1
  362. package/dist/types/src/components/GridSheet/index.d.ts +0 -2
  363. package/dist/types/src/components/GridSheet/index.d.ts.map +0 -1
  364. package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
  365. package/dist/types/src/components/RangeList/RangeList.d.ts +0 -7
  366. package/dist/types/src/components/RangeList/RangeList.d.ts.map +0 -1
  367. package/dist/types/src/components/RangeList/index.d.ts +0 -2
  368. package/dist/types/src/components/RangeList/index.d.ts.map +0 -1
  369. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +0 -11
  370. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +0 -1
  371. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +0 -8
  372. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +0 -1
  373. package/dist/types/src/components/SheetContainer/index.d.ts +0 -3
  374. package/dist/types/src/components/SheetContainer/index.d.ts.map +0 -1
  375. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +0 -1
  376. package/dist/types/src/components/SheetContext/index.d.ts +0 -2
  377. package/dist/types/src/components/SheetContext/index.d.ts.map +0 -1
  378. package/dist/types/src/extensions/editor/extension.d.ts.map +0 -1
  379. package/dist/types/src/extensions/editor/extension.test.d.ts +0 -2
  380. package/dist/types/src/extensions/editor/extension.test.d.ts.map +0 -1
  381. package/dist/types/src/types/schema.d.ts +0 -37
  382. package/dist/types/src/types/schema.d.ts.map +0 -1
  383. package/src/capabilities/capabilities.ts +0 -14
  384. package/src/capabilities/intent-resolver.ts +0 -38
  385. package/src/capabilities/markdown.ts +0 -22
  386. package/src/components/GridSheet/GridSheet.stories.tsx +0 -53
  387. package/src/components/GridSheet/SheetCellEditor.stories.tsx +0 -93
  388. package/src/components/RangeList/RangeList.tsx +0 -60
  389. package/src/components/SheetContainer/SheetContainer.stories.tsx +0 -89
  390. package/src/components/SheetContainer/SheetContainer.tsx +0 -36
  391. package/src/components/SheetContainer/index.ts +0 -7
  392. package/src/components/SheetContext/index.ts +0 -5
  393. package/src/types/schema.ts +0 -61
  394. /package/dist/lib/{browser/types/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
  395. /package/dist/lib/{node-esm/types → neutral}/index.mjs.map +0 -0
@@ -0,0 +1,1552 @@
1
+ import {
2
+ useSelectThreadOnCellFocus
3
+ } from "../chunk-HEN74ZWI.mjs";
4
+ import {
5
+ rangeExtension,
6
+ sheetExtension
7
+ } from "../chunk-ERHMBRSU.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 { composable, composableProps } from "@dxos/react-ui";
45
+ import { useAttention } from "@dxos/react-ui-attention";
46
+ import { Grid as Grid2, GridCellEditor, closestCell, editorKeys, parseCellIndex } from "@dxos/react-ui-grid";
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/Format";
62
+ import { assertArgument, 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
+ assertArgument(isFormula(formula), "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-client";
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 } from "@dxos/react-ui";
1175
+ import { mx as mx2 } from "@dxos/ui-theme";
1176
+ import { mapFormulaIndicesToRefs as mapFormulaIndicesToRefs2 } from "#types";
1177
+ var SheetStatusbar = composable2((props, forwardedRef) => {
1178
+ const { className, ...rest } = composableProps2(props);
1179
+ const { model, cursor, range } = useSheetContext();
1180
+ let value;
1181
+ let formula = false;
1182
+ if (cursor) {
1183
+ value = model.getCellValue(cursor);
1184
+ if (isFormula2(value)) {
1185
+ value = model.graph.mapFunctionBindingFromId(mapFormulaIndicesToRefs2(model.sheet, value));
1186
+ formula = true;
1187
+ } else if (value != null) {
1188
+ value = String(value);
1189
+ }
1190
+ }
1191
+ return /* @__PURE__ */ React4.createElement("div", {
1192
+ ref: forwardedRef,
1193
+ ...rest,
1194
+ className: mx2("flex shrink-0 justify-between items-center px-4 py-1 text-sm bg-toolbar-surface border-y !border-subdued-separator", className)
1195
+ }, /* @__PURE__ */ React4.createElement("div", {
1196
+ className: "flex gap-4 items-center"
1197
+ }, /* @__PURE__ */ React4.createElement("div", {
1198
+ className: "flex w-16 items-center font-mono"
1199
+ }, range && rangeToA1Notation2(range) || cursor && addressToA1Notation2(cursor)), /* @__PURE__ */ React4.createElement("div", {
1200
+ className: "flex gap-2 items-center"
1201
+ }, /* @__PURE__ */ React4.createElement(Icon2, {
1202
+ icon: "ph--function--regular",
1203
+ classNames: [
1204
+ "text-green-text",
1205
+ formula ? "visible" : "invisible"
1206
+ ]
1207
+ }), /* @__PURE__ */ React4.createElement("span", {
1208
+ className: "font-mono"
1209
+ }, value))));
1210
+ });
1211
+
1212
+ // src/components/SheetToolbar/SheetToolbar.tsx
1213
+ import { Atom as Atom2, RegistryContext as RegistryContext4 } from "@effect-atom/atom-react";
1214
+ import React5, { useContext as useContext6, useMemo as useMemo3 } from "react";
1215
+ import { useAppGraph } from "@dxos/app-toolkit/ui";
1216
+ import { composable as composable3, composableProps as composableProps3 } from "@dxos/react-ui";
1217
+ import { Menu, createGapSeparator, useMenuActions } from "@dxos/react-ui-menu";
1218
+
1219
+ // src/components/SheetToolbar/align.ts
1220
+ import { RegistryContext } from "@effect-atom/atom-react";
1221
+ import { useContext as useContext3, useEffect as useEffect4 } from "react";
1222
+ import { inRange as inRange2 } from "@dxos/compute-hyperformula";
1223
+ import { Obj as Obj3 } from "@dxos/echo";
1224
+ import { createMenuAction, createMenuItemGroup } from "@dxos/react-ui-menu";
1225
+ import { meta as meta2 } from "#meta";
1226
+ import { alignKey, rangeFromIndex as rangeFromIndex2, rangeToIndex } from "#types";
1227
+ var aligns = {
1228
+ start: "ph--text-align-left--regular",
1229
+ center: "ph--text-align-center--regular",
1230
+ end: "ph--text-align-right--regular"
1231
+ };
1232
+ var useAlignState = (stateAtom) => {
1233
+ const registry = useContext3(RegistryContext);
1234
+ const { cursor, model } = useSheetContext();
1235
+ useEffect4(() => {
1236
+ const alignValue = cursor ? model.sheet.ranges?.findLast(({ range, key }) => key === alignKey && inRange2(rangeFromIndex2(model.sheet, range), cursor))?.value : void 0;
1237
+ const prev = registry.get(stateAtom);
1238
+ registry.set(stateAtom, {
1239
+ ...prev,
1240
+ [alignKey]: alignValue
1241
+ });
1242
+ }, [
1243
+ cursor,
1244
+ model.sheet,
1245
+ registry,
1246
+ stateAtom
1247
+ ]);
1248
+ };
1249
+ var createAlignGroupAction = (value) => createMenuItemGroup("align", {
1250
+ label: [
1251
+ "align.label",
1252
+ {
1253
+ ns: meta2.id
1254
+ }
1255
+ ],
1256
+ variant: "toggleGroup",
1257
+ selectCardinality: "single",
1258
+ value: `${alignKey}--${value}`
1259
+ });
1260
+ var createAlignActions = ({ model, state, stateAtom, registry, cursorFallbackRange }) => Object.entries(aligns).map(([alignValue, icon]) => {
1261
+ return createMenuAction(`${alignKey}--${alignValue}`, () => {
1262
+ if (!cursorFallbackRange) {
1263
+ return;
1264
+ }
1265
+ const index = model.sheet.ranges?.findIndex((range) => range.key === alignKey && inRange2(rangeFromIndex2(model.sheet, range.range), cursorFallbackRange.from)) ?? -1;
1266
+ const nextRangeEntity = {
1267
+ range: rangeToIndex(model.sheet, cursorFallbackRange),
1268
+ key: alignKey,
1269
+ value: alignValue
1270
+ };
1271
+ const currentState = registry.get(stateAtom);
1272
+ if (index < 0) {
1273
+ Obj3.update(model.sheet, (obj) => {
1274
+ obj.ranges?.push(nextRangeEntity);
1275
+ });
1276
+ registry.set(stateAtom, {
1277
+ ...currentState,
1278
+ [alignKey]: nextRangeEntity.value
1279
+ });
1280
+ } else if (model.sheet.ranges[index].value === nextRangeEntity.value) {
1281
+ Obj3.update(model.sheet, (obj) => {
1282
+ obj.ranges?.splice(index, 1);
1283
+ });
1284
+ registry.set(stateAtom, {
1285
+ ...currentState,
1286
+ [alignKey]: void 0
1287
+ });
1288
+ } else {
1289
+ Obj3.update(model.sheet, (obj) => {
1290
+ obj.ranges?.splice(index, 1, nextRangeEntity);
1291
+ });
1292
+ registry.set(stateAtom, {
1293
+ ...currentState,
1294
+ [alignKey]: nextRangeEntity.value
1295
+ });
1296
+ }
1297
+ }, {
1298
+ key: alignKey,
1299
+ value: alignValue,
1300
+ checked: state[alignKey] === alignValue,
1301
+ label: [
1302
+ `range-value.${alignValue}.label`,
1303
+ {
1304
+ ns: meta2.id
1305
+ }
1306
+ ],
1307
+ icon,
1308
+ testId: `grid.toolbar.${alignKey}.${alignValue}`
1309
+ });
1310
+ });
1311
+ var createAlign = (context) => {
1312
+ const alignGroup = createAlignGroupAction(context.state[alignKey]);
1313
+ const alignActions = createAlignActions(context);
1314
+ return {
1315
+ nodes: [
1316
+ alignGroup,
1317
+ ...alignActions
1318
+ ],
1319
+ edges: [
1320
+ {
1321
+ source: "root",
1322
+ target: "align",
1323
+ relation: "child"
1324
+ },
1325
+ ...alignActions.map(({ id }) => ({
1326
+ source: alignGroup.id,
1327
+ target: id,
1328
+ relation: "child"
1329
+ }))
1330
+ ]
1331
+ };
1332
+ };
1333
+
1334
+ // src/components/SheetToolbar/style.ts
1335
+ import { RegistryContext as RegistryContext2 } from "@effect-atom/atom-react";
1336
+ import { useContext as useContext4, useEffect as useEffect5 } from "react";
1337
+ import { inRange as inRange3 } from "@dxos/compute-hyperformula";
1338
+ import { Obj as Obj4 } from "@dxos/echo";
1339
+ import { createMenuAction as createMenuAction2, createMenuItemGroup as createMenuItemGroup2 } from "@dxos/react-ui-menu";
1340
+ import { meta as meta3 } from "#meta";
1341
+ import { rangeFromIndex as rangeFromIndex3, rangeToIndex as rangeToIndex2 } from "#types";
1342
+ var styles = {
1343
+ highlight: "ph--highlighter--regular",
1344
+ softwrap: "ph--paragraph--regular"
1345
+ };
1346
+ var useStyleState = (stateAtom) => {
1347
+ const registry = useContext4(RegistryContext2);
1348
+ const { cursorFallbackRange, model } = useSheetContext();
1349
+ useEffect5(() => {
1350
+ let highlight = false;
1351
+ let softwrap = false;
1352
+ if (cursorFallbackRange && model.sheet.ranges) {
1353
+ model.sheet.ranges.filter(({ range, key }) => key === "style" && inRange3(rangeFromIndex3(model.sheet, range), cursorFallbackRange.from)).forEach(({ value }) => {
1354
+ if (value === "highlight") {
1355
+ highlight = true;
1356
+ }
1357
+ if (value === "softwrap") {
1358
+ softwrap = true;
1359
+ }
1360
+ });
1361
+ }
1362
+ const prev = registry.get(stateAtom);
1363
+ registry.set(stateAtom, {
1364
+ ...prev,
1365
+ highlight,
1366
+ softwrap
1367
+ });
1368
+ }, [
1369
+ cursorFallbackRange,
1370
+ model.sheet,
1371
+ registry,
1372
+ stateAtom
1373
+ ]);
1374
+ };
1375
+ var createStyleGroup = (state) => {
1376
+ return createMenuItemGroup2("style", {
1377
+ variant: "toggleGroup",
1378
+ selectCardinality: "multiple",
1379
+ value: Object.keys(styles).filter((key) => !!state[key]).map((styleValue) => `style--${styleValue}`)
1380
+ });
1381
+ };
1382
+ var createStyleActions = ({ model, state, stateAtom, registry, cursorFallbackRange }) => Object.entries(styles).map(([styleValue, icon]) => {
1383
+ return createMenuAction2(`style--${styleValue}`, () => {
1384
+ if (!cursorFallbackRange) {
1385
+ return;
1386
+ }
1387
+ const index = model.sheet.ranges?.findIndex((range) => range.key === "style" && inRange3(rangeFromIndex3(model.sheet, range.range), cursorFallbackRange.from)) ?? -1;
1388
+ const nextRangeEntity = {
1389
+ range: rangeToIndex2(model.sheet, cursorFallbackRange),
1390
+ key: "style",
1391
+ value: styleValue
1392
+ };
1393
+ const currentState = registry.get(stateAtom);
1394
+ if (model.sheet.ranges.filter(({ range, key: rangeKey }) => rangeKey === "style" && inRange3(rangeFromIndex3(model.sheet, range), cursorFallbackRange.from)).some(({ value: rangeValue }) => rangeValue === styleValue)) {
1395
+ if (index >= 0) {
1396
+ Obj4.update(model.sheet, (obj) => {
1397
+ obj.ranges?.splice(index, 1);
1398
+ });
1399
+ }
1400
+ registry.set(stateAtom, {
1401
+ ...currentState,
1402
+ [nextRangeEntity.value]: false
1403
+ });
1404
+ } else {
1405
+ Obj4.update(model.sheet, (obj) => {
1406
+ obj.ranges?.push(nextRangeEntity);
1407
+ });
1408
+ registry.set(stateAtom, {
1409
+ ...currentState,
1410
+ [nextRangeEntity.value]: true
1411
+ });
1412
+ }
1413
+ }, {
1414
+ key: "style",
1415
+ value: styleValue,
1416
+ icon,
1417
+ label: [
1418
+ `range-value.${styleValue}.label`,
1419
+ {
1420
+ ns: meta3.id
1421
+ }
1422
+ ],
1423
+ checked: !!state[styleValue]
1424
+ });
1425
+ });
1426
+ var createStyle = (context) => {
1427
+ const styleGroupAction = createStyleGroup(context.state);
1428
+ const styleActions = createStyleActions(context);
1429
+ return {
1430
+ nodes: [
1431
+ styleGroupAction,
1432
+ ...styleActions
1433
+ ],
1434
+ edges: [
1435
+ {
1436
+ source: "root",
1437
+ target: "style",
1438
+ relation: "child"
1439
+ },
1440
+ ...styleActions.map(({ id }) => ({
1441
+ source: styleGroupAction.id,
1442
+ target: id,
1443
+ relation: "child"
1444
+ }))
1445
+ ]
1446
+ };
1447
+ };
1448
+
1449
+ // src/components/SheetToolbar/useToolbarState.ts
1450
+ import { Atom, RegistryContext as RegistryContext3, useAtomValue } from "@effect-atom/atom-react";
1451
+ import { useContext as useContext5, useMemo as useMemo2 } from "react";
1452
+ var useToolbarState = (initialState = {}) => {
1453
+ return useMemo2(() => Atom.make(initialState).pipe(Atom.keepAlive), []);
1454
+ };
1455
+
1456
+ // src/components/SheetToolbar/SheetToolbar.tsx
1457
+ var createToolbarActions = ({ model, stateAtom, registry, cursorFallbackRange, customActions }) => {
1458
+ return Atom2.make((get) => {
1459
+ const state = get(stateAtom);
1460
+ const context = {
1461
+ model,
1462
+ state,
1463
+ stateAtom,
1464
+ registry,
1465
+ cursorFallbackRange
1466
+ };
1467
+ const align = createAlign(context);
1468
+ const style = createStyle(context);
1469
+ const gap = createGapSeparator();
1470
+ const graph = {
1471
+ nodes: [
1472
+ ...align.nodes,
1473
+ ...style.nodes,
1474
+ ...gap.nodes
1475
+ ],
1476
+ edges: [
1477
+ ...align.edges,
1478
+ ...style.edges,
1479
+ ...gap.edges
1480
+ ]
1481
+ };
1482
+ if (customActions) {
1483
+ const custom = get(customActions);
1484
+ graph.nodes.push(...custom.nodes);
1485
+ graph.edges.push(...custom.edges);
1486
+ }
1487
+ return graph;
1488
+ });
1489
+ };
1490
+ var SheetToolbar = composable3((props, forwardedRef) => {
1491
+ const { attendableId, model, cursorFallbackRange } = useSheetContext();
1492
+ const stateAtom = useToolbarState({});
1493
+ const registry = useContext6(RegistryContext4);
1494
+ useAlignState(stateAtom);
1495
+ useStyleState(stateAtom);
1496
+ const { graph } = useAppGraph();
1497
+ const customActions = useMemo3(() => {
1498
+ return Atom2.make((get) => {
1499
+ const actions = get(graph.actions(attendableId));
1500
+ const nodes = actions.filter((action) => action.properties.disposition === "toolbar");
1501
+ return {
1502
+ nodes,
1503
+ edges: nodes.map((node) => ({
1504
+ source: "root",
1505
+ target: node.id,
1506
+ relation: "child"
1507
+ }))
1508
+ };
1509
+ });
1510
+ }, [
1511
+ graph,
1512
+ attendableId
1513
+ ]);
1514
+ const actionsCreator = useMemo3(() => createToolbarActions({
1515
+ model,
1516
+ stateAtom,
1517
+ registry,
1518
+ cursorFallbackRange,
1519
+ customActions
1520
+ }), [
1521
+ model,
1522
+ stateAtom,
1523
+ registry,
1524
+ cursorFallbackRange,
1525
+ customActions
1526
+ ]);
1527
+ const menuActions = useMenuActions(actionsCreator);
1528
+ return /* @__PURE__ */ React5.createElement(Menu.Root, {
1529
+ ...menuActions,
1530
+ attendableId
1531
+ }, /* @__PURE__ */ React5.createElement(Menu.Toolbar, {
1532
+ ...composableProps3(props),
1533
+ ref: forwardedRef
1534
+ }));
1535
+ });
1536
+ SheetToolbar.displayName = "SheetToolbar";
1537
+
1538
+ // src/components/Sheet/Sheet.tsx
1539
+ var Sheet = {
1540
+ Root: SheetRoot,
1541
+ Toolbar: SheetToolbar,
1542
+ Content: SheetContent,
1543
+ Statusbar: SheetStatusbar
1544
+ };
1545
+ export {
1546
+ ComputeGraphContext,
1547
+ ComputeGraphContextProvider,
1548
+ Sheet,
1549
+ useComputeGraph,
1550
+ useSheetContext
1551
+ };
1552
+ //# sourceMappingURL=index.mjs.map