@dxos/plugin-sheet 0.8.4-main.67995b8 → 0.8.4-main.6fa680abb7

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