@dxos/plugin-sheet 0.6.13-main.ed424a1 → 0.6.13

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 (323) hide show
  1. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +1772 -0
  2. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-APHOLYUB.mjs +175 -0
  4. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +7 -0
  5. package/dist/lib/{node-esm/chunk-5WPZCXNS.mjs → browser/chunk-D5AGLXJP.mjs} +678 -411
  6. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-FUAGSXA4.mjs +82 -0
  8. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-JRL5LGCE.mjs +18 -0
  10. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-NU4PBN33.mjs +8 -0
  12. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +62 -93
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/meta.mjs +1 -1
  17. package/dist/lib/browser/testing.mjs +92 -0
  18. package/dist/lib/browser/testing.mjs.map +7 -0
  19. package/dist/lib/browser/types.mjs +12 -6
  20. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +1765 -0
  21. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-5XPK2V4A.cjs → chunk-5KKJ4NPP.cjs} +678 -418
  23. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +7 -0
  24. package/dist/lib/node/chunk-BJ6ZD7MN.cjs +51 -0
  25. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +7 -0
  26. package/dist/lib/node/chunk-CN3RPESU.cjs +202 -0
  27. package/dist/lib/node/chunk-CN3RPESU.cjs.map +7 -0
  28. package/dist/lib/node/{chunk-NZARD7UP.cjs → chunk-DSYKOI4E.cjs} +51 -40
  29. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +7 -0
  30. package/dist/lib/node/chunk-PYXHNAAK.cjs +40 -0
  31. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +7 -0
  32. package/dist/lib/node/index.cjs +69 -105
  33. package/dist/lib/node/index.cjs.map +3 -3
  34. package/dist/lib/node/meta.cjs +3 -3
  35. package/dist/lib/node/meta.cjs.map +1 -1
  36. package/dist/lib/node/meta.json +1 -1
  37. package/dist/lib/node/testing.cjs +111 -0
  38. package/dist/lib/node/testing.cjs.map +7 -0
  39. package/dist/lib/node/types.cjs +15 -9
  40. package/dist/lib/node/types.cjs.map +2 -2
  41. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  42. package/dist/types/src/components/CellEditor/CellEditor.d.ts +14 -0
  43. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -0
  44. package/dist/types/src/components/{GridSheet/SheetCellEditor.stories.d.ts → CellEditor/CellEditor.stories.d.ts} +4 -4
  45. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -0
  46. package/dist/types/src/{extensions/editor → components/CellEditor}/extension.d.ts +1 -1
  47. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -0
  48. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +1 -0
  49. package/dist/types/src/components/CellEditor/index.d.ts +3 -0
  50. package/dist/types/src/components/CellEditor/index.d.ts.map +1 -0
  51. package/dist/types/src/{graph/functions → components/ComputeGraph}/async-function.d.ts +5 -14
  52. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
  53. package/dist/types/src/components/ComputeGraph/custom.d.ts +21 -0
  54. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -0
  55. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +20 -0
  56. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -0
  57. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +12 -0
  58. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +1 -0
  59. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +2 -0
  60. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +1 -0
  61. package/dist/types/src/components/ComputeGraph/graph.d.ts +26 -0
  62. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +1 -0
  63. package/dist/types/src/components/ComputeGraph/index.d.ts +3 -1
  64. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  65. package/dist/types/src/components/Sheet/Sheet.d.ts +55 -0
  66. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
  67. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +54 -0
  68. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -0
  69. package/dist/types/src/components/Sheet/formatting.d.ts +14 -0
  70. package/dist/types/src/components/Sheet/formatting.d.ts.map +1 -0
  71. package/dist/types/src/components/Sheet/grid.d.ts +52 -0
  72. package/dist/types/src/components/Sheet/grid.d.ts.map +1 -0
  73. package/dist/types/src/components/Sheet/index.d.ts +2 -0
  74. package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
  75. package/dist/types/src/components/Sheet/nav.d.ts +29 -0
  76. package/dist/types/src/components/Sheet/nav.d.ts.map +1 -0
  77. package/dist/types/src/components/Sheet/sheet-context.d.ts +25 -0
  78. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -0
  79. package/dist/types/src/components/Sheet/util.d.ts +18 -0
  80. package/dist/types/src/components/Sheet/util.d.ts.map +1 -0
  81. package/dist/types/src/components/SheetContainer.d.ts +9 -0
  82. package/dist/types/src/components/SheetContainer.d.ts.map +1 -0
  83. package/dist/types/src/components/Toolbar/Toolbar.d.ts +9 -33
  84. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  85. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +15 -19
  86. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  87. package/dist/types/src/components/Toolbar/common.d.ts +20 -0
  88. package/dist/types/src/components/Toolbar/common.d.ts.map +1 -0
  89. package/dist/types/src/components/index.d.ts +2 -3
  90. package/dist/types/src/components/index.d.ts.map +1 -1
  91. package/dist/types/src/meta.d.ts +9 -3
  92. package/dist/types/src/meta.d.ts.map +1 -1
  93. package/dist/types/src/{graph/functions/function-defs.d.ts → model/functions.d.ts} +1 -1
  94. package/dist/types/src/model/functions.d.ts.map +1 -0
  95. package/dist/types/src/model/index.d.ts +3 -2
  96. package/dist/types/src/model/index.d.ts.map +1 -1
  97. package/dist/types/src/model/model.browser.test.d.ts +2 -0
  98. package/dist/types/src/model/model.browser.test.d.ts.map +1 -0
  99. package/dist/types/src/model/{sheet-model.d.ts → model.d.ts} +67 -13
  100. package/dist/types/src/model/model.d.ts.map +1 -0
  101. package/dist/types/src/{defs → model}/types.d.ts +3 -8
  102. package/dist/types/src/model/types.d.ts.map +1 -0
  103. package/dist/types/src/model/types.test.d.ts.map +1 -0
  104. package/dist/types/src/model/util.d.ts +15 -0
  105. package/dist/types/src/model/util.d.ts.map +1 -0
  106. package/dist/types/src/testing.d.ts +9 -0
  107. package/dist/types/src/testing.d.ts.map +1 -0
  108. package/dist/types/src/translations.d.ts +12 -17
  109. package/dist/types/src/translations.d.ts.map +1 -1
  110. package/dist/types/src/types.d.ts +40 -125
  111. package/dist/types/src/types.d.ts.map +1 -1
  112. package/package.json +52 -58
  113. package/src/SheetPlugin.tsx +74 -52
  114. package/src/components/{GridSheet/SheetCellEditor.stories.tsx → CellEditor/CellEditor.stories.tsx} +8 -8
  115. package/src/components/CellEditor/CellEditor.tsx +113 -0
  116. package/src/{extensions/editor → components/CellEditor}/extension.test.ts +6 -4
  117. package/src/{extensions/editor → components/CellEditor}/extension.ts +6 -5
  118. package/src/{extensions/editor → components/CellEditor}/index.ts +1 -0
  119. package/src/{graph/functions → components/ComputeGraph}/async-function.ts +15 -25
  120. package/src/{graph/testing/test-plugin.ts → components/ComputeGraph/custom.ts} +14 -44
  121. package/src/{graph/functions → components/ComputeGraph}/edge-function.ts +14 -16
  122. package/src/components/ComputeGraph/graph-context.tsx +50 -0
  123. package/src/components/ComputeGraph/graph.browser.test.ts +50 -0
  124. package/src/components/ComputeGraph/graph.ts +62 -0
  125. package/src/components/ComputeGraph/index.ts +3 -1
  126. package/src/components/Sheet/Sheet.stories.tsx +287 -0
  127. package/src/components/Sheet/Sheet.tsx +1160 -0
  128. package/src/components/Sheet/formatting.ts +106 -0
  129. package/src/components/Sheet/grid.ts +191 -0
  130. package/src/{testing → components/Sheet}/index.ts +1 -1
  131. package/src/components/Sheet/nav.ts +157 -0
  132. package/src/components/Sheet/sheet-context.tsx +150 -0
  133. package/src/components/Sheet/util.ts +56 -0
  134. package/src/components/SheetContainer.tsx +34 -0
  135. package/src/components/Toolbar/Toolbar.tsx +112 -242
  136. package/src/components/Toolbar/common.tsx +72 -0
  137. package/src/components/index.ts +0 -2
  138. package/src/meta.tsx +18 -0
  139. package/src/model/index.ts +3 -2
  140. package/src/model/model.browser.test.ts +100 -0
  141. package/src/model/model.ts +550 -0
  142. package/src/{defs → model}/types.test.ts +9 -8
  143. package/src/{defs → model}/types.ts +14 -24
  144. package/src/model/util.ts +36 -0
  145. package/src/testing.ts +50 -0
  146. package/src/translations.ts +1 -6
  147. package/src/types.ts +47 -40
  148. package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs +0 -290
  149. package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs.map +0 -7
  150. package/dist/lib/browser/chunk-BWN5DZWZ.mjs +0 -74
  151. package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +0 -7
  152. package/dist/lib/browser/chunk-D3QTX46O.mjs +0 -14
  153. package/dist/lib/browser/chunk-D3QTX46O.mjs.map +0 -7
  154. package/dist/lib/browser/chunk-GSV5QNLD.mjs +0 -2966
  155. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +0 -7
  156. package/dist/lib/browser/chunk-HOG37RYS.mjs +0 -1528
  157. package/dist/lib/browser/chunk-HOG37RYS.mjs.map +0 -7
  158. package/dist/lib/browser/graph-M4IQ76QX.mjs +0 -33
  159. package/dist/lib/browser/graph-M4IQ76QX.mjs.map +0 -7
  160. package/dist/lib/node/SheetContainer-J7XROAMN.cjs +0 -300
  161. package/dist/lib/node/SheetContainer-J7XROAMN.cjs.map +0 -7
  162. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +0 -7
  163. package/dist/lib/node/chunk-AXQZA2YS.cjs +0 -1527
  164. package/dist/lib/node/chunk-AXQZA2YS.cjs.map +0 -7
  165. package/dist/lib/node/chunk-NZARD7UP.cjs.map +0 -7
  166. package/dist/lib/node/chunk-QIFIGEKV.cjs +0 -37
  167. package/dist/lib/node/chunk-QIFIGEKV.cjs.map +0 -7
  168. package/dist/lib/node/graph-Q3N2X26H.cjs +0 -55
  169. package/dist/lib/node/graph-Q3N2X26H.cjs.map +0 -7
  170. package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs +0 -291
  171. package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs.map +0 -7
  172. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +0 -7
  173. package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs +0 -1529
  174. package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs.map +0 -7
  175. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +0 -16
  176. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +0 -7
  177. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs +0 -75
  178. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +0 -7
  179. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +0 -34
  180. package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +0 -7
  181. package/dist/lib/node-esm/index.mjs +0 -280
  182. package/dist/lib/node-esm/index.mjs.map +0 -7
  183. package/dist/lib/node-esm/meta.json +0 -1
  184. package/dist/lib/node-esm/meta.mjs +0 -10
  185. package/dist/lib/node-esm/meta.mjs.map +0 -7
  186. package/dist/lib/node-esm/types.mjs +0 -17
  187. package/dist/lib/node-esm/types.mjs.map +0 -7
  188. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +0 -11
  189. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +0 -1
  190. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +0 -3
  191. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +0 -1
  192. package/dist/types/src/components/FunctionEditor/index.d.ts +0 -2
  193. package/dist/types/src/components/FunctionEditor/index.d.ts.map +0 -1
  194. package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -3
  195. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
  196. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +0 -9
  197. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
  198. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +0 -1
  199. package/dist/types/src/components/GridSheet/index.d.ts +0 -2
  200. package/dist/types/src/components/GridSheet/index.d.ts.map +0 -1
  201. package/dist/types/src/components/GridSheet/util.d.ts +0 -16
  202. package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
  203. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +0 -6
  204. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +0 -1
  205. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +0 -11
  206. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +0 -1
  207. package/dist/types/src/components/SheetContainer/index.d.ts +0 -3
  208. package/dist/types/src/components/SheetContainer/index.d.ts.map +0 -1
  209. package/dist/types/src/components/SheetContext/SheetContext.d.ts +0 -26
  210. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +0 -1
  211. package/dist/types/src/components/SheetContext/index.d.ts +0 -2
  212. package/dist/types/src/components/SheetContext/index.d.ts.map +0 -1
  213. package/dist/types/src/defs/index.d.ts +0 -4
  214. package/dist/types/src/defs/index.d.ts.map +0 -1
  215. package/dist/types/src/defs/sheet-range-types.d.ts +0 -13
  216. package/dist/types/src/defs/sheet-range-types.d.ts.map +0 -1
  217. package/dist/types/src/defs/types.d.ts.map +0 -1
  218. package/dist/types/src/defs/types.test.d.ts.map +0 -1
  219. package/dist/types/src/defs/util.d.ts +0 -43
  220. package/dist/types/src/defs/util.d.ts.map +0 -1
  221. package/dist/types/src/extensions/compute.d.ts +0 -6
  222. package/dist/types/src/extensions/compute.d.ts.map +0 -1
  223. package/dist/types/src/extensions/compute.stories.d.ts +0 -26
  224. package/dist/types/src/extensions/compute.stories.d.ts.map +0 -1
  225. package/dist/types/src/extensions/editor/extension.d.ts.map +0 -1
  226. package/dist/types/src/extensions/editor/extension.test.d.ts.map +0 -1
  227. package/dist/types/src/extensions/editor/index.d.ts +0 -2
  228. package/dist/types/src/extensions/editor/index.d.ts.map +0 -1
  229. package/dist/types/src/extensions/index.d.ts +0 -3
  230. package/dist/types/src/extensions/index.d.ts.map +0 -1
  231. package/dist/types/src/graph/compute-graph-registry.d.ts +0 -34
  232. package/dist/types/src/graph/compute-graph-registry.d.ts.map +0 -1
  233. package/dist/types/src/graph/compute-graph.d.ts +0 -64
  234. package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
  235. package/dist/types/src/graph/compute-graph.stories.d.ts +0 -10
  236. package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
  237. package/dist/types/src/graph/compute-graph.test.d.ts +0 -2
  238. package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
  239. package/dist/types/src/graph/compute-node.d.ts +0 -26
  240. package/dist/types/src/graph/compute-node.d.ts.map +0 -1
  241. package/dist/types/src/graph/functions/async-function.d.ts.map +0 -1
  242. package/dist/types/src/graph/functions/edge-function.d.ts +0 -21
  243. package/dist/types/src/graph/functions/edge-function.d.ts.map +0 -1
  244. package/dist/types/src/graph/functions/function-defs.d.ts.map +0 -1
  245. package/dist/types/src/graph/functions/index.d.ts +0 -4
  246. package/dist/types/src/graph/functions/index.d.ts.map +0 -1
  247. package/dist/types/src/graph/hyperformula.test.d.ts +0 -2
  248. package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
  249. package/dist/types/src/graph/index.d.ts +0 -5
  250. package/dist/types/src/graph/index.d.ts.map +0 -1
  251. package/dist/types/src/graph/testing/index.d.ts +0 -3
  252. package/dist/types/src/graph/testing/index.d.ts.map +0 -1
  253. package/dist/types/src/graph/testing/test-builder.d.ts +0 -15
  254. package/dist/types/src/graph/testing/test-builder.d.ts.map +0 -1
  255. package/dist/types/src/graph/testing/test-plugin.d.ts +0 -36
  256. package/dist/types/src/graph/testing/test-plugin.d.ts.map +0 -1
  257. package/dist/types/src/graph/util.d.ts +0 -2
  258. package/dist/types/src/graph/util.d.ts.map +0 -1
  259. package/dist/types/src/hooks/hooks.stories.d.ts +0 -11
  260. package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
  261. package/dist/types/src/hooks/index.d.ts +0 -4
  262. package/dist/types/src/hooks/index.d.ts.map +0 -1
  263. package/dist/types/src/hooks/threads.d.ts +0 -8
  264. package/dist/types/src/hooks/threads.d.ts.map +0 -1
  265. package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
  266. package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
  267. package/dist/types/src/hooks/useSheetModel.d.ts +0 -8
  268. package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
  269. package/dist/types/src/model/decorations.d.ts +0 -25
  270. package/dist/types/src/model/decorations.d.ts.map +0 -1
  271. package/dist/types/src/model/sheet-model.d.ts.map +0 -1
  272. package/dist/types/src/model/sheet-model.test.d.ts +0 -2
  273. package/dist/types/src/model/sheet-model.test.d.ts.map +0 -1
  274. package/dist/types/src/sanity.test.d.ts +0 -2
  275. package/dist/types/src/sanity.test.d.ts.map +0 -1
  276. package/dist/types/src/testing/index.d.ts +0 -2
  277. package/dist/types/src/testing/index.d.ts.map +0 -1
  278. package/dist/types/src/testing/testing.d.ts +0 -8
  279. package/dist/types/src/testing/testing.d.ts.map +0 -1
  280. package/dist/vendor/hyperformula.mjs +0 -37145
  281. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +0 -20
  282. package/src/components/FunctionEditor/FunctionEditor.tsx +0 -45
  283. package/src/components/FunctionEditor/index.ts +0 -5
  284. package/src/components/GridSheet/GridSheet.stories.tsx +0 -41
  285. package/src/components/GridSheet/GridSheet.tsx +0 -163
  286. package/src/components/GridSheet/index.ts +0 -5
  287. package/src/components/GridSheet/util.ts +0 -158
  288. package/src/components/SheetContainer/SheetContainer.stories.tsx +0 -40
  289. package/src/components/SheetContainer/SheetContainer.tsx +0 -27
  290. package/src/components/SheetContainer/index.ts +0 -7
  291. package/src/components/SheetContext/SheetContext.tsx +0 -104
  292. package/src/components/SheetContext/index.ts +0 -5
  293. package/src/defs/index.ts +0 -7
  294. package/src/defs/sheet-range-types.ts +0 -46
  295. package/src/defs/util.ts +0 -151
  296. package/src/extensions/compute.stories.tsx +0 -151
  297. package/src/extensions/compute.ts +0 -147
  298. package/src/extensions/index.ts +0 -6
  299. package/src/graph/compute-graph-registry.ts +0 -90
  300. package/src/graph/compute-graph.stories.tsx +0 -93
  301. package/src/graph/compute-graph.test.ts +0 -87
  302. package/src/graph/compute-graph.ts +0 -242
  303. package/src/graph/compute-node.ts +0 -63
  304. package/src/graph/functions/index.ts +0 -7
  305. package/src/graph/hyperformula.test.ts +0 -14
  306. package/src/graph/index.ts +0 -8
  307. package/src/graph/testing/index.ts +0 -6
  308. package/src/graph/testing/test-builder.ts +0 -54
  309. package/src/graph/util.ts +0 -8
  310. package/src/hooks/hooks.stories.tsx +0 -50
  311. package/src/hooks/index.ts +0 -7
  312. package/src/hooks/threads.ts +0 -147
  313. package/src/hooks/useComputeGraph.ts +0 -28
  314. package/src/hooks/useSheetModel.ts +0 -40
  315. package/src/meta.ts +0 -14
  316. package/src/model/decorations.ts +0 -64
  317. package/src/model/sheet-model.test.ts +0 -57
  318. package/src/model/sheet-model.ts +0 -418
  319. package/src/sanity.test.ts +0 -40
  320. package/src/testing/testing.tsx +0 -68
  321. /package/dist/types/src/{extensions/editor → components/CellEditor}/extension.test.d.ts +0 -0
  322. /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
  323. /package/src/{graph/functions/function-defs.ts → model/functions.ts} +0 -0
@@ -1,1527 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_AXQZA2YS_exports = {};
30
- __export(chunk_AXQZA2YS_exports, {
31
- ComputeGraphContextProvider: () => ComputeGraphContextProvider,
32
- GridSheet: () => GridSheet,
33
- SheetContainer: () => SheetContainer,
34
- SheetProvider: () => SheetProvider,
35
- addressToA1Notation: () => addressToA1Notation,
36
- addressToIndex: () => addressToIndex,
37
- compareIndexPositions: () => compareIndexPositions,
38
- computeGraphFacet: () => computeGraphFacet,
39
- createSheet: () => createSheet,
40
- inRange: () => inRange,
41
- rangeToA1Notation: () => rangeToA1Notation,
42
- useComputeGraph: () => useComputeGraph,
43
- useSheetContext: () => useSheetContext
44
- });
45
- module.exports = __toCommonJS(chunk_AXQZA2YS_exports);
46
- var import_chunk_NZARD7UP = require("./chunk-NZARD7UP.cjs");
47
- var import_chunk_QIFIGEKV = require("./chunk-QIFIGEKV.cjs");
48
- var import_chunk_5XPK2V4A = require("./chunk-5XPK2V4A.cjs");
49
- var import_react = __toESM(require("react"));
50
- var import_crypto = require("@dxos/crypto");
51
- var import_echo_schema = require("@dxos/echo-schema");
52
- var import_invariant = require("@dxos/invariant");
53
- var import_language = require("@codemirror/language");
54
- var import_state = require("@codemirror/state");
55
- var import_view = require("@codemirror/view");
56
- var import_async = require("@dxos/async");
57
- var import_invariant2 = require("@dxos/invariant");
58
- var import_state2 = require("@dxos/react-ui-editor/state");
59
- var import_autocomplete = require("@codemirror/autocomplete");
60
- var import_language2 = require("@codemirror/language");
61
- var import_view2 = require("@codemirror/view");
62
- var import_highlight = require("@lezer/highlight");
63
- var import_codemirror_lang_spreadsheet = require("codemirror-lang-spreadsheet");
64
- var import_state3 = require("@dxos/react-ui-editor/state");
65
- var import_react_ui_theme = require("@dxos/react-ui-theme");
66
- var import_react2 = require("react");
67
- var import_debug = require("@dxos/debug");
68
- var import_react_hooks = require("@dxos/react-hooks");
69
- var import_react3 = __toESM(require("react"));
70
- var import_react4 = __toESM(require("react"));
71
- var import_react_ui_attention = require("@dxos/react-ui-attention");
72
- var import_react_ui_grid = require("@dxos/react-ui-grid");
73
- var import_react5 = require("react");
74
- var import_echo = require("@dxos/react-client/echo");
75
- var import_react_ui_data = require("@dxos/react-ui-data");
76
- var import_react_ui_grid2 = require("@dxos/react-ui-grid");
77
- var import_react_ui_theme2 = require("@dxos/react-ui-theme");
78
- var import_react6 = require("react");
79
- var import_echo_schema2 = require("@dxos/echo-schema");
80
- var import_async2 = require("@dxos/async");
81
- var import_context = require("@dxos/context");
82
- var import_echo_schema3 = require("@dxos/echo-schema");
83
- var import_invariant3 = require("@dxos/invariant");
84
- var import_keys = require("@dxos/keys");
85
- var import_log = require("@dxos/log");
86
- var import_schema = require("@dxos/schema");
87
- var import_hyperformula = require("#hyperformula");
88
- var import_signals_core = require("@preact/signals-core");
89
- var import_react7 = require("react");
90
- var import_app_framework = require("@dxos/app-framework");
91
- var import_async3 = require("@dxos/async");
92
- var import_echo2 = require("@dxos/react-client/echo");
93
- var import_react8 = __toESM(require("react"));
94
- var import_invariant4 = require("@dxos/invariant");
95
- var import_echo3 = require("@dxos/react-client/echo");
96
- var import_react_ui_grid3 = require("@dxos/react-ui-grid");
97
- var ComputeGraphContext = /* @__PURE__ */ (0, import_react.createContext)(void 0);
98
- var ComputeGraphContextProvider = ({ registry, children }) => {
99
- return /* @__PURE__ */ import_react.default.createElement(ComputeGraphContext.Provider, {
100
- value: {
101
- registry
102
- }
103
- }, children);
104
- };
105
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/defs/types.ts";
106
- var DEFAULT_ROWS = 50;
107
- var DEFAULT_COLUMNS = 26;
108
- var MAX_ROWS = 500;
109
- var MAX_COLUMNS = 26 * 2;
110
- var posEquals = (a, b) => {
111
- return a?.col === b?.col && a?.row === b?.row;
112
- };
113
- var columnLetter = (col) => {
114
- (0, import_invariant.invariant)(col < MAX_COLUMNS, `Invalid column: ${col}`, {
115
- F: __dxlog_file,
116
- L: 26,
117
- S: void 0,
118
- A: [
119
- "col < MAX_COLUMNS",
120
- "`Invalid column: ${col}`"
121
- ]
122
- });
123
- return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
124
- };
125
- var addressToA1Notation = ({ col, row }) => {
126
- return `${columnLetter(col)}${row + 1}`;
127
- };
128
- var addressFromA1Notation = (ref) => {
129
- const match = ref.match(/([A-Z]+)(\d+)/);
130
- (0, import_invariant.invariant)(match, `Invalid notation: ${ref}`, {
131
- F: __dxlog_file,
132
- L: 40,
133
- S: void 0,
134
- A: [
135
- "match",
136
- "`Invalid notation: ${ref}`"
137
- ]
138
- });
139
- return {
140
- row: parseInt(match[2], 10) - 1,
141
- col: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
142
- };
143
- };
144
- var rangeToA1Notation = (range) => {
145
- return [
146
- range?.from && addressToA1Notation(range?.from),
147
- range?.to && addressToA1Notation(range?.to)
148
- ].filter(Boolean).join(":");
149
- };
150
- var inRange = (range, cell) => {
151
- if (!range) {
152
- return false;
153
- }
154
- const { from, to } = range;
155
- if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
156
- return true;
157
- }
158
- if (!from || !to) {
159
- return false;
160
- }
161
- const { col: c1, row: r1 } = from;
162
- const { col: c2, row: r2 } = to;
163
- const cMin = Math.min(c1, c2);
164
- const cMax = Math.max(c1, c2);
165
- const rMin = Math.min(r1, r2);
166
- const rMax = Math.max(r1, r2);
167
- const { col, row } = cell;
168
- return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
169
- };
170
- var ApiError = class extends Error {
171
- };
172
- var ReadonlyException = class extends ApiError {
173
- };
174
- var RangeException = class extends ApiError {
175
- constructor(n) {
176
- super();
177
- }
178
- };
179
- var createIndex = (length = 8) => {
180
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
181
- const charactersLength = characters.length;
182
- const randomBuffer = (0, import_crypto.randomBytes)(length);
183
- return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
184
- };
185
- var createIndices = (length) => Array.from({
186
- length
187
- }).map(() => createIndex());
188
- var insertIndices = (indices, i, n, max) => {
189
- if (i + n > max) {
190
- throw new RangeException(i + n);
191
- }
192
- const idx = createIndices(n);
193
- indices.splice(i, 0, ...idx);
194
- };
195
- var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}) => {
196
- if (!sheet.rows.length) {
197
- insertIndices(sheet.rows, 0, rows, MAX_ROWS);
198
- }
199
- if (!sheet.columns.length) {
200
- insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
201
- }
202
- };
203
- var createSheet = ({ name, cells, ...size } = {}) => {
204
- const sheet = (0, import_echo_schema.create)(import_chunk_NZARD7UP.SheetType, {
205
- name,
206
- cells: {},
207
- rows: [],
208
- columns: [],
209
- rowMeta: {},
210
- columnMeta: {},
211
- ranges: []
212
- });
213
- initialize(sheet, size);
214
- if (cells) {
215
- Object.entries(cells).forEach(([key, { value }]) => {
216
- const idx = addressToIndex(sheet, addressFromA1Notation(key));
217
- sheet.cells[idx] = {
218
- value
219
- };
220
- });
221
- }
222
- return sheet;
223
- };
224
- var addressToIndex = (sheet, cell) => {
225
- return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
226
- };
227
- var addressFromIndex = (sheet, idx) => {
228
- const [column, row] = idx.split("@");
229
- return {
230
- col: sheet.columns.indexOf(column),
231
- row: sheet.rows.indexOf(row)
232
- };
233
- };
234
- var closest = (cursor, cells) => {
235
- let closestCell2;
236
- let closestDistance = Number.MAX_SAFE_INTEGER;
237
- for (const cell of cells) {
238
- const distance = Math.abs(cell.row - cursor.row) + Math.abs(cell.col - cursor.col);
239
- if (distance < closestDistance) {
240
- closestCell2 = cell;
241
- closestDistance = distance;
242
- }
243
- }
244
- return closestCell2;
245
- };
246
- var compareIndexPositions = (sheet, indexA, indexB) => {
247
- const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
248
- const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
249
- if (rowA !== rowB) {
250
- return rowA - rowB;
251
- } else {
252
- return columnA - columnB;
253
- }
254
- };
255
- var cellClassNameForRange = ({ key, value }) => {
256
- switch (key) {
257
- case "align":
258
- switch (value) {
259
- case "start":
260
- return "text-start";
261
- case "center":
262
- return "text-center";
263
- case "end":
264
- return "text-end";
265
- default:
266
- return void 0;
267
- }
268
- case "comment":
269
- return "bg-gridComment";
270
- case "style":
271
- switch (value) {
272
- case "highlight":
273
- return "bg-gridHighlight";
274
- default:
275
- return void 0;
276
- }
277
- default:
278
- return void 0;
279
- }
280
- };
281
- var updateAllDecorations = import_state.StateEffect.define();
282
- var computeGraphFacet = (0, import_state2.singleValueFacet)();
283
- var highlightStyles = import_language2.HighlightStyle.define([
284
- // Function.
285
- {
286
- tag: import_highlight.tags.name,
287
- class: "text-accentText"
288
- },
289
- // Range.
290
- {
291
- tag: import_highlight.tags.tagName,
292
- class: "text-pinkText"
293
- },
294
- // Values.
295
- {
296
- tag: import_highlight.tags.number,
297
- class: "text-tealText"
298
- },
299
- {
300
- tag: import_highlight.tags.bool,
301
- class: "text-tealText"
302
- },
303
- {
304
- tag: import_highlight.tags.string,
305
- class: "text-tealText"
306
- },
307
- // Error.
308
- {
309
- tag: import_highlight.tags.invalid,
310
- class: "text-unAccent"
311
- }
312
- ]);
313
- var languageFacet = (0, import_state3.singleValueFacet)();
314
- var sheetExtension = ({ functions = [] }) => {
315
- const { extension, language } = (0, import_codemirror_lang_spreadsheet.spreadsheet)({
316
- idiom: "en-US",
317
- decimalSeparator: "."
318
- });
319
- const createCompletion = (name) => {
320
- const { section = "Custom", description, syntax } = functions.find((value) => value.name === name) ?? {};
321
- return {
322
- section,
323
- label: name,
324
- info: () => {
325
- if (!description && !syntax) {
326
- return null;
327
- }
328
- const root = document.createElement("div");
329
- root.className = "flex flex-col gap-2 text-sm";
330
- const title = document.createElement("h2");
331
- title.innerText = name;
332
- title.className = "text-lg font-mono text-accentText";
333
- root.appendChild(title);
334
- if (description) {
335
- const info = document.createElement("p");
336
- info.innerText = description;
337
- info.className = "text-subdued";
338
- root.appendChild(info);
339
- }
340
- if (syntax) {
341
- const detail = document.createElement("pre");
342
- detail.innerText = syntax;
343
- detail.className = "whitespace-pre-wrap text-greenText";
344
- root.appendChild(detail);
345
- }
346
- return root;
347
- },
348
- apply: (view, completion, from, to) => {
349
- const insertParens = to === view.state.doc.toString().length;
350
- view.dispatch(view.state.update({
351
- changes: {
352
- from,
353
- to,
354
- insert: completion.label + (insertParens ? "()" : "")
355
- },
356
- selection: {
357
- anchor: from + completion.label.length + 1
358
- }
359
- }));
360
- }
361
- };
362
- };
363
- return [
364
- extension,
365
- languageFacet.of(language),
366
- language.data.of({
367
- autocomplete: (context) => {
368
- if (context.state.doc.toString()[0] !== "=") {
369
- return null;
370
- }
371
- const match = context.matchBefore(/\w*/);
372
- if (!match || match.from === match.to) {
373
- return null;
374
- }
375
- const text = match.text.toUpperCase();
376
- if (!context.explicit && match.text.length < 2) {
377
- return null;
378
- }
379
- return {
380
- from: match.from,
381
- options: functions?.filter(({ name }) => name.startsWith(text)).map(({ name }) => createCompletion(name)) ?? []
382
- };
383
- }
384
- }),
385
- (0, import_language2.syntaxHighlighting)(highlightStyles),
386
- (0, import_autocomplete.autocompletion)({
387
- aboveCursor: false,
388
- defaultKeymap: true,
389
- activateOnTyping: true,
390
- // NOTE: Useful for debugging.
391
- closeOnBlur: false,
392
- icons: false,
393
- tooltipClass: () => (0, import_react_ui_theme.mx)("!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]", "[&>ul>li[aria-selected]]:!bg-accentSurface", "border-separator")
394
- }),
395
- import_view2.keymap.of([
396
- {
397
- key: "Tab",
398
- run: (view) => {
399
- return (0, import_autocomplete.completionStatus)(view.state) === "active" ? (0, import_autocomplete.acceptCompletion)(view) : (0, import_autocomplete.startCompletion)(view);
400
- }
401
- }
402
- ])
403
- ];
404
- };
405
- var rangeExtension = (onInit) => {
406
- let view;
407
- let activeRange;
408
- const provider = (range) => {
409
- if (activeRange) {
410
- view.dispatch(view.state.update({
411
- changes: {
412
- ...activeRange,
413
- insert: range.toString()
414
- },
415
- selection: {
416
- anchor: activeRange.from + range.length
417
- }
418
- }));
419
- }
420
- view.focus();
421
- };
422
- return import_view2.ViewPlugin.fromClass(class {
423
- constructor(_view) {
424
- view = _view;
425
- onInit(provider);
426
- }
427
- update(view2) {
428
- const { anchor } = view2.state.selection.ranges[0];
429
- activeRange = void 0;
430
- const language = view2.state.facet(languageFacet);
431
- const { topNode } = language.parser.parse(view2.state.doc.toString());
432
- visitTree(topNode, ({ type, from, to }) => {
433
- if (from <= anchor && to >= anchor) {
434
- switch (type.name) {
435
- case "Function": {
436
- activeRange = {
437
- from: to,
438
- to
439
- };
440
- break;
441
- }
442
- case "CloseParen": {
443
- activeRange = {
444
- from,
445
- to: from
446
- };
447
- break;
448
- }
449
- case "RangeToken":
450
- case "CellToken":
451
- activeRange = {
452
- from,
453
- to
454
- };
455
- return true;
456
- }
457
- }
458
- return false;
459
- });
460
- if (!activeRange && view2.state.doc.toString()[0] === "=") {
461
- activeRange = {
462
- from: 1,
463
- to: view2.state.doc.toString().length
464
- };
465
- }
466
- }
467
- });
468
- };
469
- var visitTree = (node, callback) => {
470
- if (callback(node)) {
471
- return true;
472
- }
473
- for (let child = node.firstChild; child !== null; child = child.nextSibling) {
474
- if (visitTree(child, callback)) {
475
- return true;
476
- }
477
- }
478
- return false;
479
- };
480
- var dxGridCellIndexToSheetCellAddress = (index) => {
481
- const [colStr, rowStr] = index.split(",");
482
- return {
483
- col: parseInt(colStr),
484
- row: parseInt(rowStr)
485
- };
486
- };
487
- var createDxGridColumns = (model) => {
488
- return model.sheet.columns.reduce((acc, columnId, numericIndex) => {
489
- if (model.sheet.columnMeta[columnId] && model.sheet.columnMeta[columnId].size) {
490
- acc.grid[numericIndex] = {
491
- size: model.sheet.columnMeta[columnId].size,
492
- resizeable: true
493
- };
494
- }
495
- return acc;
496
- }, {
497
- grid: {}
498
- });
499
- };
500
- var createDxGridRows = (model) => {
501
- return model.sheet.rows.reduce((acc, rowId, numericIndex) => {
502
- if (model.sheet.rowMeta[rowId] && model.sheet.rowMeta[rowId].size) {
503
- acc.grid[numericIndex] = {
504
- size: model.sheet.rowMeta[rowId].size,
505
- resizeable: true
506
- };
507
- }
508
- return acc;
509
- }, {
510
- grid: {}
511
- });
512
- };
513
- var projectCellProps = (model, col, row) => {
514
- const address = {
515
- col,
516
- row
517
- };
518
- const rawValue = model.getValue(address);
519
- if (rawValue === void 0 || rawValue === null) {
520
- return {
521
- value: ""
522
- };
523
- }
524
- const ranges = model.sheet.ranges?.filter(({ range }) => inRange(range, address));
525
- const type = model.getValueType(address);
526
- const classNames = ranges?.map(cellClassNameForRange).reverse();
527
- return {
528
- value: (0, import_react_ui_data.parseValue)(type, rawValue),
529
- className: (0, import_react_ui_theme2.mx)((0, import_react_ui_data.cellClassesForFieldType)(type), classNames)
530
- };
531
- };
532
- var gridCellGetter = (model) => {
533
- const cachedGridCells = {};
534
- return (nextBounds) => {
535
- [
536
- ...Array(nextBounds.end.col - nextBounds.start.col)
537
- ].forEach((_, c0) => {
538
- return [
539
- ...Array(nextBounds.end.row - nextBounds.start.row)
540
- ].forEach((_2, r0) => {
541
- const col = nextBounds.start.col + c0;
542
- const row = nextBounds.start.row + r0;
543
- const cell = projectCellProps(model, col, row);
544
- if (cell.value) {
545
- cachedGridCells;
546
- cachedGridCells[`${col},${row}`] = cell;
547
- }
548
- });
549
- });
550
- return cachedGridCells;
551
- };
552
- };
553
- var rowLabelCell = (row) => ({
554
- value: (0, import_react_ui_grid2.rowToA1Notation)(row),
555
- className: "text-end !pie-1",
556
- resizeHandle: "row"
557
- });
558
- var colLabelCell = (col) => ({
559
- value: (0, import_react_ui_grid2.colToA1Notation)(col),
560
- resizeHandle: "col"
561
- });
562
- var cellGetter = (model) => {
563
- const getGridCells = gridCellGetter(model);
564
- return (nextBounds, plane) => {
565
- switch (plane) {
566
- case "grid":
567
- return getGridCells(nextBounds);
568
- case "frozenColsStart":
569
- return [
570
- ...Array(nextBounds.end.row - nextBounds.start.row)
571
- ].reduce((acc, _, r0) => {
572
- const r = nextBounds.start.row + r0;
573
- acc[`0,${r}`] = rowLabelCell(r);
574
- return acc;
575
- }, {});
576
- case "frozenRowsStart":
577
- return [
578
- ...Array(nextBounds.end.col - nextBounds.start.col)
579
- ].reduce((acc, _, c0) => {
580
- const c = nextBounds.start.col + c0;
581
- acc[`${c},0`] = colLabelCell(c);
582
- return acc;
583
- }, {});
584
- default:
585
- return {};
586
- }
587
- };
588
- };
589
- var useSheetModelDxGridProps = (dxGridRef, model) => {
590
- const [columns, setColumns] = (0, import_react5.useState)(createDxGridColumns(model));
591
- const [rows, setRows] = (0, import_react5.useState)(createDxGridColumns(model));
592
- (0, import_react5.useLayoutEffect)(() => {
593
- const cellsAccessor = (0, import_echo.createDocAccessor)(model.sheet, [
594
- "cells"
595
- ]);
596
- if (dxGridRef.current) {
597
- dxGridRef.current.getCells = cellGetter(model);
598
- }
599
- const handleCellsUpdate = () => {
600
- dxGridRef.current?.requestUpdate("initialCells");
601
- };
602
- cellsAccessor.handle.addListener("change", handleCellsUpdate);
603
- return () => cellsAccessor.handle.removeListener("change", handleCellsUpdate);
604
- }, [
605
- model
606
- ]);
607
- (0, import_react5.useEffect)(() => {
608
- const columnMetaAccessor = (0, import_echo.createDocAccessor)(model.sheet, [
609
- "columnMeta"
610
- ]);
611
- const rowMetaAccessor = (0, import_echo.createDocAccessor)(model.sheet, [
612
- "rowMeta"
613
- ]);
614
- const handleColumnMetaUpdate = () => {
615
- setColumns(createDxGridColumns(model));
616
- };
617
- const handleRowMetaUpdate = () => {
618
- setRows(createDxGridRows(model));
619
- };
620
- columnMetaAccessor.handle.addListener("change", handleColumnMetaUpdate);
621
- rowMetaAccessor.handle.addListener("change", handleRowMetaUpdate);
622
- return () => {
623
- columnMetaAccessor.handle.removeListener("change", handleColumnMetaUpdate);
624
- rowMetaAccessor.handle.removeListener("change", handleRowMetaUpdate);
625
- };
626
- }, [
627
- model
628
- ]);
629
- return {
630
- columns,
631
- rows
632
- };
633
- };
634
- var createDecorations = () => {
635
- const { decorations } = (0, import_echo_schema2.create)({
636
- decorations: {}
637
- });
638
- const addDecoration = (cellIndex, decorator) => {
639
- decorations[cellIndex] = [
640
- ...decorations[cellIndex] || [],
641
- decorator
642
- ];
643
- };
644
- const removeDecoration = (cellIndex, type) => {
645
- if (type) {
646
- decorations[cellIndex] = (decorations[cellIndex] || []).filter((d) => d.type !== type);
647
- } else {
648
- delete decorations[cellIndex];
649
- }
650
- };
651
- const getDecorationsForCell = (cellIndex) => {
652
- return decorations[cellIndex];
653
- };
654
- const getAllDecorations = () => {
655
- const result = [];
656
- for (const decoratorArray of Object.values(decorations)) {
657
- for (const decorator of decoratorArray) {
658
- result.push(decorator);
659
- }
660
- }
661
- return result;
662
- };
663
- return {
664
- addDecoration,
665
- removeDecoration,
666
- getDecorationsForCell,
667
- getAllDecorations
668
- };
669
- };
670
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
671
- var typeMap = {
672
- BOOLEAN: import_schema.FieldValueType.Boolean,
673
- NUMBER_RAW: import_schema.FieldValueType.Number,
674
- NUMBER_PERCENT: import_schema.FieldValueType.Percent,
675
- NUMBER_CURRENCY: import_schema.FieldValueType.Currency,
676
- NUMBER_DATETIME: import_schema.FieldValueType.DateTime,
677
- NUMBER_DATE: import_schema.FieldValueType.Date,
678
- NUMBER_TIME: import_schema.FieldValueType.Time
679
- };
680
- var getTopLeft = (range) => {
681
- const to = range.to ?? range.from;
682
- return {
683
- row: Math.min(range.from.row, to.row),
684
- col: Math.min(range.from.col, to.col)
685
- };
686
- };
687
- var toSimpleCellAddress = (sheet, cell) => ({
688
- sheet,
689
- row: cell.row,
690
- col: cell.col
691
- });
692
- var toModelRange = (sheet, range) => ({
693
- start: toSimpleCellAddress(sheet, range.from),
694
- end: toSimpleCellAddress(sheet, range.to ?? range.from)
695
- });
696
- var SheetModel = class extends import_context.Resource {
697
- constructor(_graph, _sheet, _options = {}) {
698
- super();
699
- this._graph = _graph;
700
- this._sheet = _sheet;
701
- this._options = _options;
702
- this.id = `model-${import_keys.PublicKey.random().truncate()}`;
703
- this.update = new import_async2.Event();
704
- }
705
- get graph() {
706
- return this._graph;
707
- }
708
- get sheet() {
709
- return this._sheet;
710
- }
711
- get readonly() {
712
- return this._options.readonly;
713
- }
714
- get bounds() {
715
- return {
716
- rows: this._sheet.rows.length,
717
- columns: this._sheet.columns.length
718
- };
719
- }
720
- /**
721
- * Initialize sheet and engine.
722
- */
723
- async _open() {
724
- (0, import_log.log)("initialize", {
725
- id: this.id
726
- }, {
727
- F: __dxlog_file2,
728
- L: 106,
729
- S: this,
730
- C: (f, a) => f(...a)
731
- });
732
- initialize(this._sheet);
733
- this._node = this._graph.getOrCreateNode((0, import_chunk_5XPK2V4A.createSheetName)({
734
- type: (0, import_echo_schema3.getTypename)(this._sheet),
735
- id: this._sheet.id
736
- }));
737
- await this._node.open();
738
- const unsubscribe = this._node.update.on((event) => this.update.emit(event));
739
- this._ctx.onDispose(unsubscribe);
740
- this.reset();
741
- }
742
- /**
743
- * Update engine.
744
- * NOTE: This resets the undo history.
745
- * @deprecated
746
- */
747
- reset() {
748
- (0, import_invariant3.invariant)(this._node, void 0, {
749
- F: __dxlog_file2,
750
- L: 126,
751
- S: this,
752
- A: [
753
- "this._node",
754
- ""
755
- ]
756
- });
757
- this._node.graph.hf.clearSheet(this._node.sheetId);
758
- Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
759
- (0, import_invariant3.invariant)(this._node, void 0, {
760
- F: __dxlog_file2,
761
- L: 129,
762
- S: this,
763
- A: [
764
- "this._node",
765
- ""
766
- ]
767
- });
768
- const { col, row } = addressFromIndex(this._sheet, key);
769
- if (typeof value === "string" && value.charAt(0) === "=") {
770
- value = this._graph.mapFormulaToNative(this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)));
771
- }
772
- this._node.graph.hf.setCellContents({
773
- sheet: this._node.sheetId,
774
- row,
775
- col
776
- }, value);
777
- });
778
- }
779
- /**
780
- * Recalculate formulas.
781
- * NOTE: This resets the undo history.
782
- * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
783
- * @deprecated
784
- */
785
- // TODO(burdon): Remove.
786
- recalculate() {
787
- this._node?.graph.hf.rebuildAndRecalculate();
788
- }
789
- insertRows(i, n = 1) {
790
- insertIndices(this._sheet.rows, i, n, MAX_ROWS);
791
- this.reset();
792
- }
793
- insertColumns(i, n = 1) {
794
- insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
795
- this.reset();
796
- }
797
- //
798
- // Undoable actions.
799
- // TODO(burdon): Group undoable methods; consistently update hf/sheet.
800
- //
801
- /**
802
- * Clear range of values.
803
- */
804
- clear(range) {
805
- (0, import_invariant3.invariant)(this._node, void 0, {
806
- F: __dxlog_file2,
807
- L: 171,
808
- S: this,
809
- A: [
810
- "this._node",
811
- ""
812
- ]
813
- });
814
- const topLeft = getTopLeft(range);
815
- const values = this._iterRange(range, () => null);
816
- this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
817
- this._iterRange(range, (cell) => {
818
- const idx = addressToIndex(this._sheet, cell);
819
- delete this._sheet.cells[idx];
820
- });
821
- }
822
- cut(range) {
823
- (0, import_invariant3.invariant)(this._node, void 0, {
824
- F: __dxlog_file2,
825
- L: 182,
826
- S: this,
827
- A: [
828
- "this._node",
829
- ""
830
- ]
831
- });
832
- this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
833
- this._iterRange(range, (cell) => {
834
- const idx = addressToIndex(this._sheet, cell);
835
- delete this._sheet.cells[idx];
836
- });
837
- }
838
- copy(range) {
839
- (0, import_invariant3.invariant)(this._node, void 0, {
840
- F: __dxlog_file2,
841
- L: 191,
842
- S: this,
843
- A: [
844
- "this._node",
845
- ""
846
- ]
847
- });
848
- this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
849
- }
850
- paste(cell) {
851
- (0, import_invariant3.invariant)(this._node, void 0, {
852
- F: __dxlog_file2,
853
- L: 196,
854
- S: this,
855
- A: [
856
- "this._node",
857
- ""
858
- ]
859
- });
860
- if (!this._node.graph.hf.isClipboardEmpty()) {
861
- const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
862
- for (const change of changes) {
863
- if (change instanceof import_hyperformula.ExportedCellChange) {
864
- const { address, newValue } = change;
865
- const idx = addressToIndex(this._sheet, {
866
- row: address.row,
867
- col: address.col
868
- });
869
- this._sheet.cells[idx] = {
870
- value: newValue
871
- };
872
- }
873
- }
874
- }
875
- }
876
- // TODO(burdon): Display undo/redo state.
877
- undo() {
878
- (0, import_invariant3.invariant)(this._node, void 0, {
879
- F: __dxlog_file2,
880
- L: 211,
881
- S: this,
882
- A: [
883
- "this._node",
884
- ""
885
- ]
886
- });
887
- if (this._node.graph.hf.isThereSomethingToUndo()) {
888
- this._node.graph.hf.undo();
889
- }
890
- }
891
- redo() {
892
- (0, import_invariant3.invariant)(this._node, void 0, {
893
- F: __dxlog_file2,
894
- L: 219,
895
- S: this,
896
- A: [
897
- "this._node",
898
- ""
899
- ]
900
- });
901
- if (this._node.graph.hf.isThereSomethingToRedo()) {
902
- this._node.graph.hf.redo();
903
- }
904
- }
905
- /**
906
- * Get value from sheet.
907
- */
908
- getCellValue(cell) {
909
- const idx = addressToIndex(this._sheet, cell);
910
- return this._sheet.cells[idx]?.value ?? null;
911
- }
912
- /**
913
- * Get value as a string for editing.
914
- */
915
- getCellText(cell) {
916
- const value = this.getCellValue(cell);
917
- if (value == null) {
918
- return void 0;
919
- }
920
- if (typeof value === "string" && value.charAt(0) === "=") {
921
- return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
922
- } else {
923
- return String(value);
924
- }
925
- }
926
- /**
927
- * Get array of raw values from sheet.
928
- */
929
- getCellValues(range) {
930
- return this._iterRange(range, (cell) => this.getCellValue(cell));
931
- }
932
- /**
933
- * Gets the regular or computed value from the engine.
934
- */
935
- getValue(cell) {
936
- (0, import_invariant3.invariant)(this._node, void 0, {
937
- F: __dxlog_file2,
938
- L: 262,
939
- S: this,
940
- A: [
941
- "this._node",
942
- ""
943
- ]
944
- });
945
- const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
946
- if (value instanceof import_hyperformula.DetailedCellError) {
947
- return value.toString();
948
- }
949
- return value;
950
- }
951
- /**
952
- * Get value type.
953
- */
954
- getValueType(cell) {
955
- (0, import_invariant3.invariant)(this._node, void 0, {
956
- F: __dxlog_file2,
957
- L: 275,
958
- S: this,
959
- A: [
960
- "this._node",
961
- ""
962
- ]
963
- });
964
- const addr = toSimpleCellAddress(this._node.sheetId, cell);
965
- const type = this._node.graph.hf.getCellValueDetailedType(addr);
966
- return typeMap[type];
967
- }
968
- /**
969
- * Sets the value, updating the sheet and engine.
970
- */
971
- setValue(cell, value) {
972
- (0, import_invariant3.invariant)(this._node, void 0, {
973
- F: __dxlog_file2,
974
- L: 285,
975
- S: this,
976
- A: [
977
- "this._node",
978
- ""
979
- ]
980
- });
981
- if (this._options.readonly) {
982
- throw new ReadonlyException();
983
- }
984
- let refresh = false;
985
- if (cell.row >= this._sheet.rows.length) {
986
- insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
987
- refresh = true;
988
- }
989
- if (cell.col >= this._sheet.columns.length) {
990
- insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
991
- refresh = true;
992
- }
993
- if (refresh) {
994
- this.reset();
995
- }
996
- this._node.graph.hf.setCellContents({
997
- sheet: this._node.sheetId,
998
- row: cell.row,
999
- col: cell.col
1000
- }, [
1001
- [
1002
- typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value
1003
- ]
1004
- ]);
1005
- const idx = addressToIndex(this._sheet, cell);
1006
- if (value === void 0 || value === null) {
1007
- delete this._sheet.cells[idx];
1008
- } else {
1009
- if (typeof value === "string" && value.charAt(0) === "=") {
1010
- value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
1011
- }
1012
- this._sheet.cells[idx] = {
1013
- value
1014
- };
1015
- }
1016
- }
1017
- /**
1018
- * Sets values from a simple map.
1019
- */
1020
- setValues(values) {
1021
- Object.entries(values).forEach(([key, { value }]) => {
1022
- this.setValue(addressFromA1Notation(key), value);
1023
- });
1024
- }
1025
- /**
1026
- * Iterate range.
1027
- */
1028
- _iterRange(range, cb) {
1029
- const to = range.to ?? range.from;
1030
- const rowRange = [
1031
- Math.min(range.from.row, to.row),
1032
- Math.max(range.from.row, to.row)
1033
- ];
1034
- const columnRange = [
1035
- Math.min(range.from.col, to.col),
1036
- Math.max(range.from.col, to.col)
1037
- ];
1038
- const rows = [];
1039
- for (let row = rowRange[0]; row <= rowRange[1]; row++) {
1040
- const rowCells = [];
1041
- for (let column = columnRange[0]; column <= columnRange[1]; column++) {
1042
- const value = cb({
1043
- row,
1044
- col: column
1045
- });
1046
- if (value !== void 0) {
1047
- rowCells.push(value);
1048
- }
1049
- }
1050
- rows.push(rowCells);
1051
- }
1052
- return rows;
1053
- }
1054
- // TODO(burdon): Delete index.
1055
- _deleteIndices(indices, i, n) {
1056
- throw new Error("Not implemented");
1057
- }
1058
- // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
1059
- _moveIndices(indices, i, j, n) {
1060
- throw new Error("Not implemented");
1061
- }
1062
- //
1063
- // Indices.
1064
- //
1065
- /**
1066
- * Map from A1 notation to indices.
1067
- */
1068
- mapFormulaRefsToIndices(formula) {
1069
- (0, import_invariant3.invariant)(formula.charAt(0) === "=", void 0, {
1070
- F: __dxlog_file2,
1071
- L: 374,
1072
- S: this,
1073
- A: [
1074
- "formula.charAt(0) === '='",
1075
- ""
1076
- ]
1077
- });
1078
- return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
1079
- return addressToIndex(this._sheet, addressFromA1Notation(match));
1080
- });
1081
- }
1082
- /**
1083
- * Map from indices to A1 notation.
1084
- */
1085
- mapFormulaIndicesToRefs(formula) {
1086
- (0, import_invariant3.invariant)(formula.charAt(0) === "=", void 0, {
1087
- F: __dxlog_file2,
1088
- L: 384,
1089
- S: this,
1090
- A: [
1091
- "formula.charAt(0) === '='",
1092
- ""
1093
- ]
1094
- });
1095
- return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
1096
- return addressToA1Notation(addressFromIndex(this._sheet, idx));
1097
- });
1098
- }
1099
- //
1100
- // Values
1101
- //
1102
- /**
1103
- * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
1104
- * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
1105
- * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
1106
- */
1107
- toLocalDate(num) {
1108
- const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
1109
- return new Date(year, month - 1, day, hours, minutes, seconds);
1110
- }
1111
- toDateTime(num) {
1112
- (0, import_invariant3.invariant)(this._node, void 0, {
1113
- F: __dxlog_file2,
1114
- L: 405,
1115
- S: this,
1116
- A: [
1117
- "this._node",
1118
- ""
1119
- ]
1120
- });
1121
- return this._node.graph.hf.numberToDateTime(num);
1122
- }
1123
- toDate(num) {
1124
- (0, import_invariant3.invariant)(this._node, void 0, {
1125
- F: __dxlog_file2,
1126
- L: 410,
1127
- S: this,
1128
- A: [
1129
- "this._node",
1130
- ""
1131
- ]
1132
- });
1133
- return this._node.graph.hf.numberToDate(num);
1134
- }
1135
- toTime(num) {
1136
- (0, import_invariant3.invariant)(this._node, void 0, {
1137
- F: __dxlog_file2,
1138
- L: 415,
1139
- S: this,
1140
- A: [
1141
- "this._node",
1142
- ""
1143
- ]
1144
- });
1145
- return this._node.graph.hf.numberToTime(num);
1146
- }
1147
- };
1148
- var useSheetModel = (graph, sheet, { readonly } = {}) => {
1149
- const [model, setModel] = (0, import_react6.useState)();
1150
- (0, import_react6.useEffect)(() => {
1151
- if (!graph || !sheet) {
1152
- return;
1153
- }
1154
- let model2;
1155
- const t = setTimeout(async () => {
1156
- model2 = new SheetModel(graph, sheet, {
1157
- readonly
1158
- });
1159
- await model2.open();
1160
- setModel(model2);
1161
- });
1162
- return () => {
1163
- clearTimeout(t);
1164
- void model2?.close();
1165
- };
1166
- }, [
1167
- graph,
1168
- sheet,
1169
- readonly
1170
- ]);
1171
- return model;
1172
- };
1173
- var useUpdateFocusedCellOnThreadSelection = (model, grid) => {
1174
- const handleScrollIntoView = (0, import_react7.useCallback)(({ action, data }) => {
1175
- switch (action) {
1176
- case import_app_framework.LayoutAction.SCROLL_INTO_VIEW: {
1177
- if (!data?.id || data?.cursor === void 0 || data?.id !== (0, import_echo2.fullyQualifiedId)(model.sheet)) {
1178
- return;
1179
- }
1180
- const cellAddress = addressFromIndex(model.sheet, data.cursor);
1181
- grid.current?.setFocus({
1182
- ...cellAddress,
1183
- plane: "grid"
1184
- }, true);
1185
- }
1186
- }
1187
- }, [
1188
- model.sheet
1189
- ]);
1190
- (0, import_app_framework.useIntentResolver)(import_chunk_QIFIGEKV.SHEET_PLUGIN, handleScrollIntoView);
1191
- };
1192
- var useSelectThreadOnCellFocus = (model, cursor) => {
1193
- const dispatch = (0, import_app_framework.useIntentDispatcher)();
1194
- const activeThreads = (0, import_react7.useMemo)(() => model.sheet.threads?.filter((thread) => !!thread && thread.status === "active") ?? [], [
1195
- // TODO(thure): Surely we can find a better dependency for this…
1196
- JSON.stringify(model.sheet.threads)
1197
- ]);
1198
- const activeThreadAddresses = (0, import_react7.useMemo)(() => activeThreads.map((thread) => thread.anchor).filter((anchor) => anchor !== void 0).map((anchor) => addressFromIndex(model.sheet, anchor)), [
1199
- activeThreads,
1200
- model.sheet
1201
- ]);
1202
- const selectClosestThread = (0, import_react7.useCallback)((cellAddress) => {
1203
- if (!cellAddress || !activeThreads) {
1204
- return;
1205
- }
1206
- const closestThreadAnchor = closest(cellAddress, activeThreadAddresses);
1207
- if (closestThreadAnchor) {
1208
- const closestThread = activeThreads.find((thread) => thread && thread.anchor === addressToIndex(model.sheet, closestThreadAnchor));
1209
- if (closestThread) {
1210
- void dispatch([
1211
- {
1212
- action: "dxos.org/plugin/thread/action/select",
1213
- data: {
1214
- current: (0, import_echo2.fullyQualifiedId)(closestThread)
1215
- }
1216
- }
1217
- ]);
1218
- }
1219
- }
1220
- }, [
1221
- dispatch,
1222
- activeThreads,
1223
- activeThreadAddresses,
1224
- model.sheet
1225
- ]);
1226
- const debounced = (0, import_react7.useMemo)(() => {
1227
- return (0, import_async3.debounce)((cellCoords) => requestAnimationFrame(() => selectClosestThread(cellCoords)), 50);
1228
- }, [
1229
- selectClosestThread
1230
- ]);
1231
- (0, import_react7.useEffect)(() => {
1232
- if (!cursor) {
1233
- return;
1234
- }
1235
- debounced(cursor);
1236
- }, [
1237
- cursor,
1238
- selectClosestThread
1239
- ]);
1240
- };
1241
- var createThreadDecoration = (cellIndex, threadId, sheetId) => {
1242
- return {
1243
- type: "comment",
1244
- classNames: [
1245
- "bg-greenFill"
1246
- ],
1247
- cellIndex
1248
- };
1249
- };
1250
- var useThreadDecorations = (model, decorations) => {
1251
- const sheet = (0, import_react7.useMemo)(() => model.sheet, [
1252
- model.sheet
1253
- ]);
1254
- const sheetId = (0, import_react7.useMemo)(() => (0, import_echo2.fullyQualifiedId)(sheet), [
1255
- sheet
1256
- ]);
1257
- (0, import_react7.useEffect)(() => {
1258
- const unsubscribe = (0, import_signals_core.effect)(() => {
1259
- const activeThreadAnchors = /* @__PURE__ */ new Set();
1260
- if (!sheet.threads) {
1261
- return;
1262
- }
1263
- for (const thread of sheet.threads) {
1264
- if (!thread || thread.anchor === void 0 || thread.status === "resolved") {
1265
- continue;
1266
- }
1267
- activeThreadAnchors.add(thread.anchor);
1268
- const index = thread.anchor;
1269
- const existingDecorations = decorations.getDecorationsForCell(index);
1270
- if (!existingDecorations || !existingDecorations.some((d) => d.type === "comment")) {
1271
- decorations.addDecoration(index, createThreadDecoration(index, thread.id, sheetId));
1272
- }
1273
- }
1274
- for (const decoration of decorations.getAllDecorations()) {
1275
- if (decoration.type !== "comment") {
1276
- continue;
1277
- }
1278
- if (!activeThreadAnchors.has(decoration.cellIndex)) {
1279
- decorations.removeDecoration(decoration.cellIndex, "comment");
1280
- }
1281
- }
1282
- });
1283
- return () => unsubscribe();
1284
- });
1285
- };
1286
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx";
1287
- var SheetContext = /* @__PURE__ */ (0, import_react8.createContext)(null);
1288
- var useSheetContext = () => {
1289
- const context = (0, import_react8.useContext)(SheetContext);
1290
- (0, import_invariant4.invariant)(context, void 0, {
1291
- F: __dxlog_file3,
1292
- L: 45,
1293
- S: void 0,
1294
- A: [
1295
- "context",
1296
- ""
1297
- ]
1298
- });
1299
- return context;
1300
- };
1301
- var SheetProviderImpl = ({ model, onInfo, children, __gridScope }) => {
1302
- const { id, editing, setEditing } = (0, import_react_ui_grid3.useGridContext)("SheetProvider", __gridScope);
1303
- const decorations = (0, import_react8.useMemo)(() => createDecorations(), []);
1304
- const [cursor, setCursor] = (0, import_react8.useState)();
1305
- const [range, setRange] = (0, import_react8.useState)();
1306
- useSelectThreadOnCellFocus(model, cursor);
1307
- useThreadDecorations(model, decorations);
1308
- return /* @__PURE__ */ import_react8.default.createElement(SheetContext.Provider, {
1309
- value: {
1310
- id,
1311
- model,
1312
- editing,
1313
- setEditing,
1314
- cursor,
1315
- setCursor,
1316
- range,
1317
- setRange,
1318
- // TODO(burdon): Change to event.
1319
- onInfo,
1320
- decorations
1321
- }
1322
- }, children);
1323
- };
1324
- var SheetProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1325
- const model = useSheetModel(graph, sheet, {
1326
- readonly
1327
- });
1328
- return !model ? null : /* @__PURE__ */ import_react8.default.createElement(import_react_ui_grid3.Grid.Root, {
1329
- id: (0, import_echo3.fullyQualifiedId)(sheet)
1330
- }, /* @__PURE__ */ import_react8.default.createElement(SheetProviderImpl, {
1331
- model,
1332
- onInfo
1333
- }, children));
1334
- };
1335
- var initialCells = {
1336
- grid: {},
1337
- frozenColsStart: [
1338
- ...Array(64)
1339
- ].reduce((acc, _, i) => {
1340
- acc[`0,${i}`] = rowLabelCell(i);
1341
- return acc;
1342
- }, {}),
1343
- frozenRowsStart: [
1344
- ...Array(12)
1345
- ].reduce((acc, _, i) => {
1346
- acc[`${i},0`] = colLabelCell(i);
1347
- return acc;
1348
- }, {})
1349
- };
1350
- var frozen = {
1351
- frozenColsStart: 1,
1352
- frozenRowsStart: 1
1353
- };
1354
- var sheetRowDefault = {
1355
- grid: {
1356
- size: 32,
1357
- resizeable: true
1358
- }
1359
- };
1360
- var sheetColDefault = {
1361
- frozenColsStart: {
1362
- size: 48
1363
- },
1364
- grid: {
1365
- size: 180,
1366
- resizeable: true
1367
- }
1368
- };
1369
- var GridSheet = () => {
1370
- const { id, model, editing, setEditing, setCursor, setRange } = useSheetContext();
1371
- const dxGrid = (0, import_react4.useRef)(null);
1372
- const rangeNotifier = (0, import_react4.useRef)();
1373
- const { hasAttention } = (0, import_react_ui_attention.useAttention)(id);
1374
- const handleFocus = (0, import_react4.useCallback)((event) => {
1375
- if (!editing) {
1376
- const cell = (0, import_react_ui_grid.closestCell)(event.target);
1377
- if (cell && cell.plane === "grid") {
1378
- setCursor({
1379
- col: cell.col,
1380
- row: cell.row
1381
- });
1382
- }
1383
- }
1384
- }, [
1385
- editing
1386
- ]);
1387
- const handleClose = (0, import_react4.useCallback)((value, { key, shift }) => {
1388
- if (value !== void 0) {
1389
- model.setValue(dxGridCellIndexToSheetCellAddress(editing.index), value);
1390
- }
1391
- setEditing(null);
1392
- const axis = [
1393
- "Enter",
1394
- "ArrowUp",
1395
- "ArrowDown"
1396
- ].includes(key) ? "row" : [
1397
- "Tab",
1398
- "ArrowLeft",
1399
- "ArrowRight"
1400
- ].includes(key) ? "col" : void 0;
1401
- const delta = key.startsWith("Arrow") ? [
1402
- "ArrowUp",
1403
- "ArrowLeft"
1404
- ].includes(key) ? -1 : 1 : shift ? -1 : 1;
1405
- dxGrid.current?.refocus(axis, delta);
1406
- }, [
1407
- model,
1408
- editing,
1409
- setEditing
1410
- ]);
1411
- const handleAxisResize = (0, import_react4.useCallback)(({ axis, size, index: numericIndex }) => {
1412
- if (axis === "row") {
1413
- const rowId = model.sheet.rows[parseInt(numericIndex)];
1414
- model.sheet.rowMeta[rowId] ??= {};
1415
- model.sheet.rowMeta[rowId].size = size;
1416
- } else {
1417
- const columnId = model.sheet.columns[parseInt(numericIndex)];
1418
- model.sheet.columnMeta[columnId] ??= {};
1419
- model.sheet.columnMeta[columnId].size = size;
1420
- }
1421
- }, [
1422
- model
1423
- ]);
1424
- const handleSelect = (0, import_react4.useCallback)(({ minCol, maxCol, minRow, maxRow }) => {
1425
- const range = {
1426
- from: {
1427
- col: minCol,
1428
- row: minRow
1429
- }
1430
- };
1431
- if (minCol !== maxCol || minRow !== maxRow) {
1432
- range.to = {
1433
- col: maxCol,
1434
- row: maxRow
1435
- };
1436
- }
1437
- if (editing) {
1438
- rangeNotifier.current?.(rangeToA1Notation(range));
1439
- } else {
1440
- setRange(range.to ? range : void 0);
1441
- }
1442
- }, [
1443
- editing
1444
- ]);
1445
- const handleWheel = (0, import_react4.useCallback)((event) => {
1446
- if (!hasAttention) {
1447
- event.stopPropagation();
1448
- }
1449
- }, [
1450
- hasAttention
1451
- ]);
1452
- const { columns, rows } = useSheetModelDxGridProps(dxGrid, model);
1453
- const extension = (0, import_react4.useMemo)(() => [
1454
- (0, import_react_ui_grid.editorKeys)({
1455
- onClose: handleClose,
1456
- ...editing?.initialContent && {
1457
- onNav: handleClose
1458
- }
1459
- }),
1460
- sheetExtension({
1461
- functions: model.graph.getFunctions()
1462
- }),
1463
- rangeExtension((fn) => rangeNotifier.current = fn)
1464
- ], [
1465
- model,
1466
- handleClose,
1467
- editing
1468
- ]);
1469
- const getCellContent = (0, import_react4.useCallback)((index) => {
1470
- const cell = dxGridCellIndexToSheetCellAddress(index);
1471
- return model.getCellText(cell);
1472
- }, [
1473
- model
1474
- ]);
1475
- useUpdateFocusedCellOnThreadSelection(model, dxGrid);
1476
- return /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui_grid.GridCellEditor, {
1477
- getCellContent,
1478
- extension
1479
- }), /* @__PURE__ */ import_react4.default.createElement(import_react_ui_grid.Grid.Content, {
1480
- initialCells,
1481
- limitColumns: DEFAULT_COLUMNS,
1482
- limitRows: DEFAULT_ROWS,
1483
- columns,
1484
- rows,
1485
- onAxisResize: handleAxisResize,
1486
- onSelect: handleSelect,
1487
- rowDefault: sheetRowDefault,
1488
- columnDefault: sheetColDefault,
1489
- frozen,
1490
- onFocus: handleFocus,
1491
- onWheelCapture: handleWheel,
1492
- className: "[--dx-grid-base:var(--surface-bg)]",
1493
- ref: dxGrid
1494
- }));
1495
- };
1496
- var SheetContainer = import_react3.default.lazy(() => import("./SheetContainer-J7XROAMN.cjs"));
1497
- var useComputeGraph = (space) => {
1498
- const { registry } = (0, import_react2.useContext)(ComputeGraphContext) ?? (0, import_debug.raise)(new Error("Missing ComputeGraphContext"));
1499
- const [graph] = (0, import_react_hooks.useAsyncState)(async () => {
1500
- if (space) {
1501
- const graph2 = registry.getOrCreateGraph(space);
1502
- await graph2.open();
1503
- return graph2;
1504
- }
1505
- }, [
1506
- space,
1507
- registry
1508
- ]);
1509
- return graph;
1510
- };
1511
- // Annotate the CommonJS export names for ESM import in node:
1512
- 0 && (module.exports = {
1513
- ComputeGraphContextProvider,
1514
- GridSheet,
1515
- SheetContainer,
1516
- SheetProvider,
1517
- addressToA1Notation,
1518
- addressToIndex,
1519
- compareIndexPositions,
1520
- computeGraphFacet,
1521
- createSheet,
1522
- inRange,
1523
- rangeToA1Notation,
1524
- useComputeGraph,
1525
- useSheetContext
1526
- });
1527
- //# sourceMappingURL=chunk-AXQZA2YS.cjs.map