@dxos/plugin-sheet 0.6.12-staging.e11e696 → 0.6.12

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 (277) hide show
  1. package/dist/lib/browser/{chunk-CHQAW4F4.mjs → SheetContainer-U4H5D34A.mjs} +249 -1182
  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-WZMOZKQZ.mjs → chunk-FUAGSXA4.mjs} +16 -9
  8. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-QILRZNE5.mjs → chunk-JRL5LGCE.mjs} +5 -2
  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 +60 -96
  14. package/dist/lib/browser/index.mjs.map +4 -4
  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 +6 -4
  20. package/dist/lib/node/{chunk-5FTFZL5W.cjs → SheetContainer-AXQV3ZT5.cjs} +287 -1212
  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-BNARJ5GM.cjs → chunk-BJ6ZD7MN.cjs} +18 -5
  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-AOP42UAA.cjs → chunk-DSYKOI4E.cjs} +21 -13
  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 +66 -106
  33. package/dist/lib/node/index.cjs.map +4 -4
  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 +12 -10
  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 +3 -23
  43. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -1
  44. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts +2 -2
  45. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -1
  46. package/dist/types/src/components/CellEditor/extension.d.ts +1 -1
  47. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
  48. package/dist/types/src/{graph/functions → components/ComputeGraph}/async-function.d.ts +5 -14
  49. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
  50. package/dist/types/src/components/ComputeGraph/custom.d.ts +21 -0
  51. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -0
  52. package/dist/types/src/components/ComputeGraph/edge-function.d.ts +20 -0
  53. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -0
  54. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +12 -0
  55. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +1 -0
  56. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +2 -0
  57. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +1 -0
  58. package/dist/types/src/components/ComputeGraph/graph.d.ts +26 -0
  59. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +1 -0
  60. package/dist/types/src/components/ComputeGraph/index.d.ts +3 -1
  61. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  62. package/dist/types/src/components/Sheet/Sheet.d.ts +1 -1
  63. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
  64. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +6 -5
  65. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  66. package/dist/types/src/components/Sheet/formatting.d.ts +14 -0
  67. package/dist/types/src/components/Sheet/formatting.d.ts.map +1 -0
  68. package/dist/types/src/components/Sheet/grid.d.ts +2 -2
  69. package/dist/types/src/components/Sheet/grid.d.ts.map +1 -1
  70. package/dist/types/src/components/Sheet/nav.d.ts +3 -3
  71. package/dist/types/src/components/Sheet/nav.d.ts.map +1 -1
  72. package/dist/types/src/components/Sheet/sheet-context.d.ts +7 -8
  73. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
  74. package/dist/types/src/components/SheetContainer.d.ts +3 -2
  75. package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
  76. package/dist/types/src/components/Toolbar/Toolbar.d.ts +3 -19
  77. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  78. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +13 -18
  79. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  80. package/dist/types/src/components/index.d.ts +2 -2
  81. package/dist/types/src/components/index.d.ts.map +1 -1
  82. package/dist/types/src/meta.d.ts +4 -1
  83. package/dist/types/src/meta.d.ts.map +1 -1
  84. package/dist/types/src/{graph/functions/function-defs.d.ts → model/functions.d.ts} +1 -1
  85. package/dist/types/src/model/functions.d.ts.map +1 -0
  86. package/dist/types/src/model/index.d.ts +3 -2
  87. package/dist/types/src/model/index.d.ts.map +1 -1
  88. package/dist/types/src/model/model.browser.test.d.ts +2 -0
  89. package/dist/types/src/model/model.browser.test.d.ts.map +1 -0
  90. package/dist/types/src/model/{sheet-model.d.ts → model.d.ts} +65 -10
  91. package/dist/types/src/model/model.d.ts.map +1 -0
  92. package/dist/types/src/{defs → model}/types.d.ts +3 -8
  93. package/dist/types/src/model/types.d.ts.map +1 -0
  94. package/dist/types/src/model/types.test.d.ts.map +1 -0
  95. package/dist/types/src/model/util.d.ts +15 -0
  96. package/dist/types/src/model/util.d.ts.map +1 -0
  97. package/dist/types/src/testing.d.ts +9 -0
  98. package/dist/types/src/testing.d.ts.map +1 -0
  99. package/dist/types/src/translations.d.ts +12 -17
  100. package/dist/types/src/translations.d.ts.map +1 -1
  101. package/dist/types/src/types.d.ts +5 -86
  102. package/dist/types/src/types.d.ts.map +1 -1
  103. package/package.json +47 -55
  104. package/src/SheetPlugin.tsx +73 -50
  105. package/src/components/CellEditor/CellEditor.stories.tsx +6 -6
  106. package/src/components/CellEditor/CellEditor.tsx +9 -59
  107. package/src/components/CellEditor/extension.test.ts +6 -4
  108. package/src/components/CellEditor/extension.ts +6 -5
  109. package/src/{graph/functions → components/ComputeGraph}/async-function.ts +15 -25
  110. package/src/{graph/testing/test-plugin.ts → components/ComputeGraph/custom.ts} +14 -44
  111. package/src/{graph/functions → components/ComputeGraph}/edge-function.ts +14 -16
  112. package/src/components/ComputeGraph/graph-context.tsx +50 -0
  113. package/src/components/ComputeGraph/graph.browser.test.ts +50 -0
  114. package/src/components/ComputeGraph/graph.ts +62 -0
  115. package/src/components/ComputeGraph/index.ts +3 -1
  116. package/src/components/Sheet/Sheet.stories.tsx +88 -52
  117. package/src/components/Sheet/Sheet.tsx +32 -87
  118. package/src/{model/formatting-model.ts → components/Sheet/formatting.ts} +13 -20
  119. package/src/components/Sheet/grid.ts +3 -3
  120. package/src/components/Sheet/nav.ts +19 -19
  121. package/src/components/Sheet/sheet-context.tsx +80 -18
  122. package/src/components/SheetContainer.tsx +16 -68
  123. package/src/components/Toolbar/Toolbar.tsx +12 -53
  124. package/src/components/index.ts +0 -1
  125. package/src/meta.tsx +5 -1
  126. package/src/model/index.ts +3 -2
  127. package/src/model/model.browser.test.ts +100 -0
  128. package/src/model/model.ts +550 -0
  129. package/src/{defs → model}/types.test.ts +9 -8
  130. package/src/{defs → model}/types.ts +14 -24
  131. package/src/model/util.ts +36 -0
  132. package/src/testing.ts +50 -0
  133. package/src/translations.ts +1 -6
  134. package/src/types.ts +6 -31
  135. package/dist/lib/browser/SheetContainer-LG77O4RM.mjs +0 -262
  136. package/dist/lib/browser/SheetContainer-LG77O4RM.mjs.map +0 -7
  137. package/dist/lib/browser/chunk-CHQAW4F4.mjs.map +0 -7
  138. package/dist/lib/browser/chunk-GSV5QNLD.mjs +0 -2966
  139. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +0 -7
  140. package/dist/lib/browser/chunk-QILRZNE5.mjs.map +0 -7
  141. package/dist/lib/browser/chunk-WZMOZKQZ.mjs.map +0 -7
  142. package/dist/lib/browser/graph-M4IQ76QX.mjs +0 -33
  143. package/dist/lib/browser/graph-M4IQ76QX.mjs.map +0 -7
  144. package/dist/lib/node/SheetContainer-OZ7DHH4L.cjs +0 -280
  145. package/dist/lib/node/SheetContainer-OZ7DHH4L.cjs.map +0 -7
  146. package/dist/lib/node/chunk-5FTFZL5W.cjs.map +0 -7
  147. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +0 -7
  148. package/dist/lib/node/chunk-AOP42UAA.cjs.map +0 -7
  149. package/dist/lib/node/chunk-BNARJ5GM.cjs.map +0 -7
  150. package/dist/lib/node/graph-Q3N2X26H.cjs +0 -55
  151. package/dist/lib/node/graph-Q3N2X26H.cjs.map +0 -7
  152. package/dist/lib/node-esm/SheetContainer-4XS2G25Z.mjs +0 -263
  153. package/dist/lib/node-esm/SheetContainer-4XS2G25Z.mjs.map +0 -7
  154. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +0 -7
  155. package/dist/lib/node-esm/chunk-IU2L277A.mjs +0 -17
  156. package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +0 -7
  157. package/dist/lib/node-esm/chunk-KK3XL37M.mjs +0 -2706
  158. package/dist/lib/node-esm/chunk-KK3XL37M.mjs.map +0 -7
  159. package/dist/lib/node-esm/chunk-RR2AO4SM.mjs +0 -76
  160. package/dist/lib/node-esm/chunk-RR2AO4SM.mjs.map +0 -7
  161. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +0 -34
  162. package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +0 -7
  163. package/dist/lib/node-esm/index.mjs +0 -285
  164. package/dist/lib/node-esm/index.mjs.map +0 -7
  165. package/dist/lib/node-esm/meta.json +0 -1
  166. package/dist/lib/node-esm/meta.mjs +0 -10
  167. package/dist/lib/node-esm/meta.mjs.map +0 -7
  168. package/dist/lib/node-esm/types.mjs +0 -21
  169. package/dist/lib/node-esm/types.mjs.map +0 -7
  170. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +0 -11
  171. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +0 -1
  172. package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -10
  173. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
  174. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +0 -9
  175. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
  176. package/dist/types/src/components/GridSheet/util.d.ts +0 -7
  177. package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
  178. package/dist/types/src/components/Sheet/decorations.d.ts +0 -24
  179. package/dist/types/src/components/Sheet/decorations.d.ts.map +0 -1
  180. package/dist/types/src/components/Sheet/threads.d.ts +0 -2
  181. package/dist/types/src/components/Sheet/threads.d.ts.map +0 -1
  182. package/dist/types/src/defs/index.d.ts +0 -3
  183. package/dist/types/src/defs/index.d.ts.map +0 -1
  184. package/dist/types/src/defs/types.d.ts.map +0 -1
  185. package/dist/types/src/defs/types.test.d.ts.map +0 -1
  186. package/dist/types/src/defs/util.d.ts +0 -43
  187. package/dist/types/src/defs/util.d.ts.map +0 -1
  188. package/dist/types/src/extensions/compute.d.ts +0 -6
  189. package/dist/types/src/extensions/compute.d.ts.map +0 -1
  190. package/dist/types/src/extensions/compute.stories.d.ts +0 -26
  191. package/dist/types/src/extensions/compute.stories.d.ts.map +0 -1
  192. package/dist/types/src/extensions/index.d.ts +0 -2
  193. package/dist/types/src/extensions/index.d.ts.map +0 -1
  194. package/dist/types/src/graph/compute-graph-registry.d.ts +0 -34
  195. package/dist/types/src/graph/compute-graph-registry.d.ts.map +0 -1
  196. package/dist/types/src/graph/compute-graph.d.ts +0 -64
  197. package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
  198. package/dist/types/src/graph/compute-graph.stories.d.ts +0 -10
  199. package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
  200. package/dist/types/src/graph/compute-graph.test.d.ts +0 -2
  201. package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
  202. package/dist/types/src/graph/compute-node.d.ts +0 -26
  203. package/dist/types/src/graph/compute-node.d.ts.map +0 -1
  204. package/dist/types/src/graph/functions/async-function.d.ts.map +0 -1
  205. package/dist/types/src/graph/functions/edge-function.d.ts +0 -21
  206. package/dist/types/src/graph/functions/edge-function.d.ts.map +0 -1
  207. package/dist/types/src/graph/functions/function-defs.d.ts.map +0 -1
  208. package/dist/types/src/graph/functions/index.d.ts +0 -4
  209. package/dist/types/src/graph/functions/index.d.ts.map +0 -1
  210. package/dist/types/src/graph/hyperformula.test.d.ts +0 -2
  211. package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
  212. package/dist/types/src/graph/index.d.ts +0 -5
  213. package/dist/types/src/graph/index.d.ts.map +0 -1
  214. package/dist/types/src/graph/testing/index.d.ts +0 -3
  215. package/dist/types/src/graph/testing/index.d.ts.map +0 -1
  216. package/dist/types/src/graph/testing/test-builder.d.ts +0 -15
  217. package/dist/types/src/graph/testing/test-builder.d.ts.map +0 -1
  218. package/dist/types/src/graph/testing/test-plugin.d.ts +0 -36
  219. package/dist/types/src/graph/testing/test-plugin.d.ts.map +0 -1
  220. package/dist/types/src/graph/util.d.ts +0 -2
  221. package/dist/types/src/graph/util.d.ts.map +0 -1
  222. package/dist/types/src/hooks/hooks.stories.d.ts +0 -11
  223. package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
  224. package/dist/types/src/hooks/index.d.ts +0 -4
  225. package/dist/types/src/hooks/index.d.ts.map +0 -1
  226. package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
  227. package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
  228. package/dist/types/src/hooks/useFormattingModel.d.ts +0 -3
  229. package/dist/types/src/hooks/useFormattingModel.d.ts.map +0 -1
  230. package/dist/types/src/hooks/useSheetModel.d.ts +0 -8
  231. package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
  232. package/dist/types/src/model/formatting-model.d.ts +0 -16
  233. package/dist/types/src/model/formatting-model.d.ts.map +0 -1
  234. package/dist/types/src/model/sheet-model.d.ts.map +0 -1
  235. package/dist/types/src/model/sheet-model.test.d.ts +0 -2
  236. package/dist/types/src/model/sheet-model.test.d.ts.map +0 -1
  237. package/dist/types/src/sanity.test.d.ts +0 -2
  238. package/dist/types/src/sanity.test.d.ts.map +0 -1
  239. package/dist/types/src/testing/index.d.ts +0 -2
  240. package/dist/types/src/testing/index.d.ts.map +0 -1
  241. package/dist/types/src/testing/testing.d.ts +0 -8
  242. package/dist/types/src/testing/testing.d.ts.map +0 -1
  243. package/dist/vendor/hyperformula.mjs +0 -37145
  244. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +0 -20
  245. package/src/components/GridSheet/GridSheet.stories.tsx +0 -36
  246. package/src/components/GridSheet/GridSheet.tsx +0 -153
  247. package/src/components/GridSheet/util.ts +0 -108
  248. package/src/components/Sheet/decorations.ts +0 -62
  249. package/src/components/Sheet/threads.tsx +0 -205
  250. package/src/defs/index.ts +0 -6
  251. package/src/defs/util.ts +0 -151
  252. package/src/extensions/compute.stories.tsx +0 -151
  253. package/src/extensions/compute.ts +0 -147
  254. package/src/extensions/index.ts +0 -5
  255. package/src/graph/compute-graph-registry.ts +0 -90
  256. package/src/graph/compute-graph.stories.tsx +0 -93
  257. package/src/graph/compute-graph.test.ts +0 -87
  258. package/src/graph/compute-graph.ts +0 -242
  259. package/src/graph/compute-node.ts +0 -63
  260. package/src/graph/functions/index.ts +0 -7
  261. package/src/graph/hyperformula.test.ts +0 -14
  262. package/src/graph/index.ts +0 -8
  263. package/src/graph/testing/index.ts +0 -6
  264. package/src/graph/testing/test-builder.ts +0 -54
  265. package/src/graph/util.ts +0 -8
  266. package/src/hooks/hooks.stories.tsx +0 -50
  267. package/src/hooks/index.ts +0 -7
  268. package/src/hooks/useComputeGraph.ts +0 -28
  269. package/src/hooks/useFormattingModel.ts +0 -11
  270. package/src/hooks/useSheetModel.ts +0 -40
  271. package/src/model/sheet-model.test.ts +0 -59
  272. package/src/model/sheet-model.ts +0 -416
  273. package/src/sanity.test.ts +0 -40
  274. package/src/testing/index.ts +0 -5
  275. package/src/testing/testing.tsx +0 -68
  276. /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
  277. /package/src/{graph/functions/function-defs.ts → model/functions.ts} +0 -0
@@ -1,13 +1,24 @@
1
1
  import {
2
- SheetType,
3
- ValueTypeEnum
4
- } from "./chunk-WZMOZKQZ.mjs";
2
+ useComputeGraph
3
+ } from "./chunk-APHOLYUB.mjs";
5
4
  import {
6
- SHEET_PLUGIN
7
- } from "./chunk-QILRZNE5.mjs";
5
+ SheetModel,
6
+ addressFromA1Notation,
7
+ addressToA1Notation,
8
+ columnLetter,
9
+ defaultFunctions,
10
+ inRange,
11
+ posEquals,
12
+ rangeToA1Notation
13
+ } from "./chunk-D5AGLXJP.mjs";
8
14
  import {
9
- createSheetName
10
- } from "./chunk-GSV5QNLD.mjs";
15
+ ValueTypeEnum
16
+ } from "./chunk-FUAGSXA4.mjs";
17
+ import "./chunk-JRL5LGCE.mjs";
18
+
19
+ // packages/plugins/plugin-sheet/src/components/SheetContainer.tsx
20
+ import React4 from "react";
21
+ import { mx as mx3 } from "@dxos/react-ui-theme";
11
22
 
12
23
  // packages/plugins/plugin-sheet/src/components/Sheet/Sheet.tsx
13
24
  import { DndContext, DragOverlay, KeyboardSensor, MouseSensor, TouchSensor, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
@@ -15,183 +26,17 @@ import { restrictToHorizontalAxis, restrictToVerticalAxis } from "@dnd-kit/modif
15
26
  import { getEventCoordinates, useCombinedRefs } from "@dnd-kit/utilities";
16
27
  import { Function as FunctionIcon } from "@phosphor-icons/react";
17
28
  import { Resizable } from "re-resizable";
18
- import React6, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo as useMemo4, useRef, useState as useState5 } from "react";
29
+ import React3, { forwardRef, useEffect as useEffect3, useImperativeHandle, useMemo, useRef, useState as useState4 } from "react";
19
30
  import { createPortal } from "react-dom";
20
31
  import { useResizeDetector } from "react-resize-detector";
21
- import { debounce as debounce2 } from "@dxos/async";
32
+ import { debounce } from "@dxos/async";
22
33
  import { fullyQualifiedId as fullyQualifiedId2, createDocAccessor } from "@dxos/client/echo";
23
- import { log as log2 } from "@dxos/log";
24
- import { ATTENABLE_ATTRIBUTE, useAttendableAttributes, useAttention, useAttentionPath } from "@dxos/react-ui-attention";
34
+ import { log } from "@dxos/log";
35
+ import { createAttendableAttributes, useHasAttention } from "@dxos/react-ui-attention";
25
36
  import { mx as mx2 } from "@dxos/react-ui-theme";
26
37
 
27
38
  // packages/plugins/plugin-sheet/src/components/Sheet/grid.ts
28
39
  import { useEffect, useState } from "react";
29
-
30
- // packages/plugins/plugin-sheet/src/defs/types.ts
31
- import { invariant } from "@dxos/invariant";
32
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/defs/types.ts";
33
- var DEFAULT_ROWS = 50;
34
- var DEFAULT_COLUMNS = 26;
35
- var MAX_ROWS = 500;
36
- var MAX_COLUMNS = 26 * 2;
37
- var posEquals = (a, b) => {
38
- return a?.col === b?.col && a?.row === b?.row;
39
- };
40
- var columnLetter = (col) => {
41
- invariant(col < MAX_COLUMNS, `Invalid column: ${col}`, {
42
- F: __dxlog_file,
43
- L: 26,
44
- S: void 0,
45
- A: [
46
- "col < MAX_COLUMNS",
47
- "`Invalid column: ${col}`"
48
- ]
49
- });
50
- return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
51
- };
52
- var addressToA1Notation = ({ col, row }) => {
53
- return `${columnLetter(col)}${row + 1}`;
54
- };
55
- var addressFromA1Notation = (ref) => {
56
- const match = ref.match(/([A-Z]+)(\d+)/);
57
- invariant(match, `Invalid notation: ${ref}`, {
58
- F: __dxlog_file,
59
- L: 40,
60
- S: void 0,
61
- A: [
62
- "match",
63
- "`Invalid notation: ${ref}`"
64
- ]
65
- });
66
- return {
67
- row: parseInt(match[2], 10) - 1,
68
- col: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
69
- };
70
- };
71
- var rangeToA1Notation = (range) => {
72
- return [
73
- range?.from && addressToA1Notation(range?.from),
74
- range?.to && addressToA1Notation(range?.to)
75
- ].filter(Boolean).join(":");
76
- };
77
- var inRange = (range, cell) => {
78
- if (!range) {
79
- return false;
80
- }
81
- const { from, to } = range;
82
- if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
83
- return true;
84
- }
85
- if (!from || !to) {
86
- return false;
87
- }
88
- const { col: c1, row: r1 } = from;
89
- const { col: c2, row: r2 } = to;
90
- const cMin = Math.min(c1, c2);
91
- const cMax = Math.max(c1, c2);
92
- const rMin = Math.min(r1, r2);
93
- const rMax = Math.max(r1, r2);
94
- const { col, row } = cell;
95
- return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
96
- };
97
-
98
- // packages/plugins/plugin-sheet/src/defs/util.ts
99
- import { randomBytes } from "@dxos/crypto";
100
- import { create } from "@dxos/echo-schema";
101
- var ApiError = class extends Error {
102
- };
103
- var ReadonlyException = class extends ApiError {
104
- };
105
- var RangeException = class extends ApiError {
106
- constructor(n) {
107
- super();
108
- }
109
- };
110
- var createIndex = (length = 8) => {
111
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
112
- const charactersLength = characters.length;
113
- const randomBuffer = randomBytes(length);
114
- return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
115
- };
116
- var createIndices = (length) => Array.from({
117
- length
118
- }).map(() => createIndex());
119
- var insertIndices = (indices, i, n, max) => {
120
- if (i + n > max) {
121
- throw new RangeException(i + n);
122
- }
123
- const idx = createIndices(n);
124
- indices.splice(i, 0, ...idx);
125
- };
126
- var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}) => {
127
- if (!sheet.rows.length) {
128
- insertIndices(sheet.rows, 0, rows, MAX_ROWS);
129
- }
130
- if (!sheet.columns.length) {
131
- insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
132
- }
133
- };
134
- var createSheet = ({ name, cells, ...size } = {}) => {
135
- const sheet = create(SheetType, {
136
- name,
137
- cells: {},
138
- rows: [],
139
- columns: [],
140
- rowMeta: {},
141
- columnMeta: {},
142
- formatting: {}
143
- });
144
- initialize(sheet, size);
145
- if (cells) {
146
- Object.entries(cells).forEach(([key, { value }]) => {
147
- const idx = addressToIndex(sheet, addressFromA1Notation(key));
148
- sheet.cells[idx] = {
149
- value
150
- };
151
- });
152
- }
153
- return sheet;
154
- };
155
- var addressToIndex = (sheet, cell) => {
156
- return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
157
- };
158
- var addressFromIndex = (sheet, idx) => {
159
- const [column, row] = idx.split("@");
160
- return {
161
- col: sheet.columns.indexOf(column),
162
- row: sheet.rows.indexOf(row)
163
- };
164
- };
165
- var rangeFromIndex = (sheet, idx) => {
166
- const [from, to] = idx.split(":").map((index) => addressFromIndex(sheet, index));
167
- return {
168
- from,
169
- to
170
- };
171
- };
172
- var closest = (cursor, cells) => {
173
- let closestCell;
174
- let closestDistance = Number.MAX_SAFE_INTEGER;
175
- for (const cell of cells) {
176
- const distance = Math.abs(cell.row - cursor.row) + Math.abs(cell.col - cursor.col);
177
- if (distance < closestDistance) {
178
- closestCell = cell;
179
- closestDistance = distance;
180
- }
181
- }
182
- return closestCell;
183
- };
184
- var compareIndexPositions = (sheet, indexA, indexB) => {
185
- const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
186
- const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
187
- if (rowA !== rowB) {
188
- return rowA - rowB;
189
- } else {
190
- return columnA - columnB;
191
- }
192
- };
193
-
194
- // packages/plugins/plugin-sheet/src/components/Sheet/grid.ts
195
40
  var axisWidth = "calc(var(--rail-size)-2px)";
196
41
  var axisHeight = 34;
197
42
  var minWidth = 40;
@@ -233,7 +78,7 @@ var useGridLayout = ({ scroller, size, rows, columns, rowSizes, columnSizes }) =
233
78
  const left = x;
234
79
  x += width2 - 1;
235
80
  return {
236
- col: i,
81
+ column: i,
237
82
  left,
238
83
  width: width2
239
84
  };
@@ -338,14 +183,14 @@ var handleNav = (ev, cursor, range, size) => {
338
183
  break;
339
184
  }
340
185
  case "ArrowLeft": {
341
- if (opposite.col > 0) {
342
- opposite.col -= 1;
186
+ if (opposite.column > 0) {
187
+ opposite.column -= 1;
343
188
  }
344
189
  break;
345
190
  }
346
191
  case "ArrowRight": {
347
- if (opposite.col < size.numCols - 1) {
348
- opposite.col += 1;
192
+ if (opposite.column < size.numColumns - 1) {
193
+ opposite.column += 1;
349
194
  }
350
195
  break;
351
196
  }
@@ -363,18 +208,18 @@ var handleNav = (ev, cursor, range, size) => {
363
208
  cursor: next
364
209
  };
365
210
  };
366
- var handleArrowNav = (ev, cursor, { numRows, numCols }) => {
211
+ var handleArrowNav = (ev, cursor, { numRows, numColumns }) => {
367
212
  switch (ev.key) {
368
213
  case "ArrowUp":
369
214
  if (cursor === void 0) {
370
215
  return {
371
216
  row: 0,
372
- col: 0
217
+ column: 0
373
218
  };
374
219
  } else if (cursor.row > 0) {
375
220
  return {
376
221
  row: ev.metaKey ? 0 : cursor.row - 1,
377
- col: cursor.col
222
+ column: cursor.column
378
223
  };
379
224
  }
380
225
  break;
@@ -382,12 +227,12 @@ var handleArrowNav = (ev, cursor, { numRows, numCols }) => {
382
227
  if (cursor === void 0) {
383
228
  return {
384
229
  row: 0,
385
- col: 0
230
+ column: 0
386
231
  };
387
232
  } else if (cursor.row < numRows - 1) {
388
233
  return {
389
234
  row: ev.metaKey ? numRows - 1 : cursor.row + 1,
390
- col: cursor.col
235
+ column: cursor.column
391
236
  };
392
237
  }
393
238
  break;
@@ -395,12 +240,12 @@ var handleArrowNav = (ev, cursor, { numRows, numCols }) => {
395
240
  if (cursor === void 0) {
396
241
  return {
397
242
  row: 0,
398
- col: 0
243
+ column: 0
399
244
  };
400
- } else if (cursor.col > 0) {
245
+ } else if (cursor.column > 0) {
401
246
  return {
402
247
  row: cursor.row,
403
- col: ev.metaKey ? 0 : cursor.col - 1
248
+ column: ev.metaKey ? 0 : cursor.column - 1
404
249
  };
405
250
  }
406
251
  break;
@@ -408,24 +253,24 @@ var handleArrowNav = (ev, cursor, { numRows, numCols }) => {
408
253
  if (cursor === void 0) {
409
254
  return {
410
255
  row: 0,
411
- col: 0
256
+ column: 0
412
257
  };
413
- } else if (cursor.col < numCols - 1) {
258
+ } else if (cursor.column < numColumns - 1) {
414
259
  return {
415
260
  row: cursor.row,
416
- col: ev.metaKey ? numCols - 1 : cursor.col + 1
261
+ column: ev.metaKey ? numColumns - 1 : cursor.column + 1
417
262
  };
418
263
  }
419
264
  break;
420
265
  case "Home":
421
266
  return {
422
267
  row: 0,
423
- col: 0
268
+ column: 0
424
269
  };
425
270
  case "End":
426
271
  return {
427
272
  row: numRows - 1,
428
- col: numCols - 1
273
+ column: numColumns - 1
429
274
  };
430
275
  }
431
276
  };
@@ -482,110 +327,31 @@ var useRangeSelect = (cb) => {
482
327
  };
483
328
 
484
329
  // packages/plugins/plugin-sheet/src/components/Sheet/sheet-context.tsx
485
- import React3, { createContext as createContext2, useContext as useContext2, useMemo as useMemo2, useState as useState4 } from "react";
486
- import { invariant as invariant3 } from "@dxos/invariant";
487
-
488
- // packages/plugins/plugin-sheet/src/components/Sheet/decorations.ts
489
- import { create as create2 } from "@dxos/echo-schema";
490
- var createDecorations = () => {
491
- const { decorations } = create2({
492
- decorations: {}
493
- });
494
- const addDecoration = (cellIndex, decorator) => {
495
- decorations[cellIndex] = [
496
- ...decorations[cellIndex] || [],
497
- decorator
498
- ];
499
- };
500
- const removeDecoration = (cellIndex, type) => {
501
- if (type) {
502
- decorations[cellIndex] = (decorations[cellIndex] || []).filter((d) => d.type !== type);
503
- } else {
504
- delete decorations[cellIndex];
505
- }
506
- };
507
- const getDecorationsForCell = (cellIndex) => {
508
- return decorations[cellIndex];
509
- };
510
- const getAllDecorations = () => {
511
- const result = [];
512
- for (const decoratorArray of Object.values(decorations)) {
513
- for (const decorator of decoratorArray) {
514
- result.push(decorator);
515
- }
516
- }
517
- return result;
518
- };
519
- return {
520
- addDecoration,
521
- removeDecoration,
522
- getDecorationsForCell,
523
- getAllDecorations
524
- };
525
- };
526
-
527
- // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
528
- import { useContext } from "react";
529
- import { raise } from "@dxos/debug";
530
- import { useAsyncState } from "@dxos/react-hooks";
531
-
532
- // packages/plugins/plugin-sheet/src/components/index.ts
533
- import React2 from "react";
534
-
535
- // packages/plugins/plugin-sheet/src/components/ComputeGraph/ComputeGraphContextProvider.tsx
536
- import React, { createContext } from "react";
537
- var ComputeGraphContext = /* @__PURE__ */ createContext(void 0);
538
- var ComputeGraphContextProvider = ({ registry, children }) => {
539
- return /* @__PURE__ */ React.createElement(ComputeGraphContext.Provider, {
540
- value: {
541
- registry
542
- }
543
- }, children);
544
- };
545
-
546
- // packages/plugins/plugin-sheet/src/components/index.ts
547
- var SheetContainer = React2.lazy(() => import("./SheetContainer-LG77O4RM.mjs"));
548
-
549
- // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
550
- var useComputeGraph = (space) => {
551
- const { registry } = useContext(ComputeGraphContext) ?? raise(new Error("Missing ComputeGraphContext"));
552
- const [graph] = useAsyncState(async () => {
553
- if (space) {
554
- const graph2 = registry.getOrCreateGraph(space);
555
- await graph2.open();
556
- return graph2;
557
- }
558
- }, [
559
- space,
560
- registry
561
- ]);
562
- return graph;
563
- };
564
-
565
- // packages/plugins/plugin-sheet/src/hooks/useFormattingModel.ts
566
- import { useMemo } from "react";
330
+ import React, { createContext, useContext, useState as useState3, useEffect as useEffect2 } from "react";
331
+ import { invariant } from "@dxos/invariant";
332
+ import { fullyQualifiedId } from "@dxos/react-client/echo";
567
333
 
568
- // packages/plugins/plugin-sheet/src/model/formatting-model.ts
334
+ // packages/plugins/plugin-sheet/src/components/Sheet/formatting.ts
569
335
  var FormattingModel = class {
570
- constructor(_model) {
571
- this._model = _model;
336
+ constructor(model) {
337
+ this.model = model;
572
338
  }
573
339
  /**
574
340
  * Get formatted string value and className for cell.
575
341
  */
576
342
  getFormatting(cell) {
577
- const value = this._model.getValue(cell);
343
+ const value = this.model.getValue(cell);
578
344
  if (value === void 0 || value === null) {
579
345
  return {};
580
346
  }
581
347
  const locales = void 0;
582
- const idx = addressToIndex(this._model.sheet, cell);
583
- let formatting = this._model.sheet.formatting?.[idx] ?? {};
348
+ const idx = this.model.addressToIndex(cell);
349
+ let formatting = this.model.sheet.formatting?.[idx] ?? {};
584
350
  const classNames = [
585
351
  ...formatting?.classNames ?? []
586
352
  ];
587
- for (const [idx2, _formatting] of Object.entries(this._model.sheet.formatting)) {
588
- const range = rangeFromIndex(this._model.sheet, idx2);
353
+ for (const [idx2, _formatting] of Object.entries(this.model.sheet.formatting)) {
354
+ const range = this.model.rangeFromIndex(idx2);
589
355
  if (inRange(range, cell)) {
590
356
  if (_formatting.classNames) {
591
357
  classNames.push(..._formatting.classNames);
@@ -596,7 +362,7 @@ var FormattingModel = class {
596
362
  }
597
363
  }
598
364
  const defaultNumber = "justify-end font-mono";
599
- const type = formatting?.type ?? this._model.getValueType(cell);
365
+ const type = formatting?.type ?? this.model.getValueType(cell);
600
366
  switch (type) {
601
367
  case ValueTypeEnum.Boolean: {
602
368
  return {
@@ -646,21 +412,21 @@ var FormattingModel = class {
646
412
  // Dates.
647
413
  //
648
414
  case ValueTypeEnum.DateTime: {
649
- const date = this._model.toLocalDate(value);
415
+ const date = this.model.toLocalDate(value);
650
416
  return {
651
417
  value: date.toLocaleString(locales),
652
418
  classNames
653
419
  };
654
420
  }
655
421
  case ValueTypeEnum.Date: {
656
- const date = this._model.toLocalDate(value);
422
+ const date = this.model.toLocalDate(value);
657
423
  return {
658
424
  value: date.toLocaleDateString(locales),
659
425
  classNames
660
426
  };
661
427
  }
662
428
  case ValueTypeEnum.Time: {
663
- const date = this._model.toLocalDate(value);
429
+ const date = this.model.toLocalDate(value);
664
430
  return {
665
431
  value: date.toLocaleTimeString(locales),
666
432
  classNames
@@ -676,554 +442,84 @@ var FormattingModel = class {
676
442
  }
677
443
  };
678
444
 
679
- // packages/plugins/plugin-sheet/src/model/sheet-model.ts
680
- import { Event } from "@dxos/async";
681
- import { Resource } from "@dxos/context";
682
- import { getTypename } from "@dxos/echo-schema";
683
- import { invariant as invariant2 } from "@dxos/invariant";
684
- import { PublicKey } from "@dxos/keys";
685
- import { log } from "@dxos/log";
686
- import { DetailedCellError, ExportedCellChange } from "#hyperformula";
687
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
688
- var typeMap = {
689
- BOOLEAN: ValueTypeEnum.Boolean,
690
- NUMBER_RAW: ValueTypeEnum.Number,
691
- NUMBER_PERCENT: ValueTypeEnum.Percent,
692
- NUMBER_CURRENCY: ValueTypeEnum.Currency,
693
- NUMBER_DATETIME: ValueTypeEnum.DateTime,
694
- NUMBER_DATE: ValueTypeEnum.Date,
695
- NUMBER_TIME: ValueTypeEnum.Time
696
- };
697
- var getTopLeft = (range) => {
698
- const to = range.to ?? range.from;
699
- return {
700
- row: Math.min(range.from.row, to.row),
701
- col: Math.min(range.from.col, to.col)
702
- };
445
+ // packages/plugins/plugin-sheet/src/components/Sheet/sheet-context.tsx
446
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/Sheet/sheet-context.tsx";
447
+ var OBJECT_ID_LENGTH = 60;
448
+ var SheetContext = /* @__PURE__ */ createContext(null);
449
+ var useSheetContext = () => {
450
+ const context = useContext(SheetContext);
451
+ invariant(context, void 0, {
452
+ F: __dxlog_file,
453
+ L: 45,
454
+ S: void 0,
455
+ A: [
456
+ "context",
457
+ ""
458
+ ]
459
+ });
460
+ return context;
703
461
  };
704
- var toSimpleCellAddress = (sheet, cell) => ({
705
- sheet,
706
- row: cell.row,
707
- col: cell.col
708
- });
709
- var toModelRange = (sheet, range) => ({
710
- start: toSimpleCellAddress(sheet, range.from),
711
- end: toSimpleCellAddress(sheet, range.to ?? range.from)
712
- });
713
- var SheetModel = class extends Resource {
714
- constructor(_graph, _sheet, _options = {}) {
715
- super();
716
- this._graph = _graph;
717
- this._sheet = _sheet;
718
- this._options = _options;
719
- this.id = `model-${PublicKey.random().truncate()}`;
720
- this.update = new Event();
721
- }
722
- get graph() {
723
- return this._graph;
724
- }
725
- get sheet() {
726
- return this._sheet;
727
- }
728
- get readonly() {
729
- return this._options.readonly;
730
- }
731
- get bounds() {
732
- return {
733
- rows: this._sheet.rows.length,
734
- columns: this._sheet.columns.length
735
- };
736
- }
737
- /**
738
- * Initialize sheet and engine.
739
- */
740
- async _open() {
741
- log("initialize", {
742
- id: this.id
743
- }, {
744
- F: __dxlog_file2,
745
- L: 104,
746
- S: this,
747
- C: (f, a) => f(...a)
748
- });
749
- initialize(this._sheet);
750
- this._node = this._graph.getOrCreateNode(createSheetName({
751
- type: getTypename(this._sheet),
752
- id: this._sheet.id
753
- }));
754
- await this._node.open();
755
- const unsubscribe = this._node.update.on((event) => this.update.emit(event));
756
- this._ctx.onDispose(unsubscribe);
757
- this.reset();
758
- }
759
- /**
760
- * Update engine.
761
- * NOTE: This resets the undo history.
762
- * @deprecated
763
- */
764
- reset() {
765
- invariant2(this._node, void 0, {
766
- F: __dxlog_file2,
767
- L: 124,
768
- S: this,
769
- A: [
770
- "this._node",
771
- ""
772
- ]
773
- });
774
- this._node.graph.hf.clearSheet(this._node.sheetId);
775
- Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
776
- invariant2(this._node, void 0, {
777
- F: __dxlog_file2,
778
- L: 127,
779
- S: this,
780
- A: [
781
- "this._node",
782
- ""
783
- ]
784
- });
785
- const { col, row } = addressFromIndex(this._sheet, key);
786
- if (typeof value === "string" && value.charAt(0) === "=") {
787
- value = this._graph.mapFormulaToNative(this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)));
788
- }
789
- this._node.graph.hf.setCellContents({
790
- sheet: this._node.sheetId,
791
- row,
792
- col
793
- }, value);
794
- });
795
- }
796
- /**
797
- * Recalculate formulas.
798
- * NOTE: This resets the undo history.
799
- * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
800
- * @deprecated
801
- */
802
- // TODO(burdon): Remove.
803
- recalculate() {
804
- this._node?.graph.hf.rebuildAndRecalculate();
805
- }
806
- insertRows(i, n = 1) {
807
- insertIndices(this._sheet.rows, i, n, MAX_ROWS);
808
- this.reset();
809
- }
810
- insertColumns(i, n = 1) {
811
- insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
812
- this.reset();
813
- }
814
- //
815
- // Undoable actions.
816
- // TODO(burdon): Group undoable methods; consistently update hf/sheet.
817
- //
818
- /**
819
- * Clear range of values.
820
- */
821
- clear(range) {
822
- invariant2(this._node, void 0, {
823
- F: __dxlog_file2,
824
- L: 169,
825
- S: this,
826
- A: [
827
- "this._node",
828
- ""
829
- ]
830
- });
831
- const topLeft = getTopLeft(range);
832
- const values = this._iterRange(range, () => null);
833
- this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
834
- this._iterRange(range, (cell) => {
835
- const idx = addressToIndex(this._sheet, cell);
836
- delete this._sheet.cells[idx];
837
- });
838
- }
839
- cut(range) {
840
- invariant2(this._node, void 0, {
841
- F: __dxlog_file2,
842
- L: 180,
843
- S: this,
844
- A: [
845
- "this._node",
846
- ""
847
- ]
848
- });
849
- this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
850
- this._iterRange(range, (cell) => {
851
- const idx = addressToIndex(this._sheet, cell);
852
- delete this._sheet.cells[idx];
853
- });
854
- }
855
- copy(range) {
856
- invariant2(this._node, void 0, {
857
- F: __dxlog_file2,
858
- L: 189,
859
- S: this,
860
- A: [
861
- "this._node",
862
- ""
863
- ]
864
- });
865
- this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
866
- }
867
- paste(cell) {
868
- invariant2(this._node, void 0, {
869
- F: __dxlog_file2,
870
- L: 194,
871
- S: this,
872
- A: [
873
- "this._node",
874
- ""
875
- ]
876
- });
877
- if (!this._node.graph.hf.isClipboardEmpty()) {
878
- const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
879
- for (const change of changes) {
880
- if (change instanceof ExportedCellChange) {
881
- const { address, newValue } = change;
882
- const idx = addressToIndex(this._sheet, {
883
- row: address.row,
884
- col: address.col
885
- });
886
- this._sheet.cells[idx] = {
887
- value: newValue
888
- };
889
- }
890
- }
891
- }
892
- }
893
- // TODO(burdon): Display undo/redo state.
894
- undo() {
895
- invariant2(this._node, void 0, {
896
- F: __dxlog_file2,
897
- L: 209,
898
- S: this,
899
- A: [
900
- "this._node",
901
- ""
902
- ]
903
- });
904
- if (this._node.graph.hf.isThereSomethingToUndo()) {
905
- this._node.graph.hf.undo();
906
- }
907
- }
908
- redo() {
909
- invariant2(this._node, void 0, {
910
- F: __dxlog_file2,
911
- L: 217,
912
- S: this,
913
- A: [
914
- "this._node",
915
- ""
916
- ]
917
- });
918
- if (this._node.graph.hf.isThereSomethingToRedo()) {
919
- this._node.graph.hf.redo();
920
- }
921
- }
922
- /**
923
- * Get value from sheet.
924
- */
925
- getCellValue(cell) {
926
- const idx = addressToIndex(this._sheet, cell);
927
- return this._sheet.cells[idx]?.value ?? null;
928
- }
929
- /**
930
- * Get value as a string for editing.
931
- */
932
- getCellText(cell) {
933
- const value = this.getCellValue(cell);
934
- if (value == null) {
935
- return void 0;
462
+ var mapFormulaBindingToId = (functions) => (formula) => {
463
+ return formula.replace(/([a-zA-Z0-9]+)\((.*)\)/g, (match, binding, args) => {
464
+ if (defaultFunctions.find((fn2) => fn2.name === binding) || binding === "EDGE") {
465
+ return match;
936
466
  }
937
- if (typeof value === "string" && value.charAt(0) === "=") {
938
- return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
467
+ const fn = functions.find((fn2) => fn2.binding === binding);
468
+ if (fn) {
469
+ return `${fullyQualifiedId(fn)}(${args})`;
939
470
  } else {
940
- return String(value);
941
- }
942
- }
943
- /**
944
- * Get array of raw values from sheet.
945
- */
946
- getCellValues(range) {
947
- return this._iterRange(range, (cell) => this.getCellValue(cell));
948
- }
949
- /**
950
- * Gets the regular or computed value from the engine.
951
- */
952
- getValue(cell) {
953
- invariant2(this._node, void 0, {
954
- F: __dxlog_file2,
955
- L: 260,
956
- S: this,
957
- A: [
958
- "this._node",
959
- ""
960
- ]
961
- });
962
- const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
963
- if (value instanceof DetailedCellError) {
964
- return value.toString();
965
- }
966
- return value;
967
- }
968
- /**
969
- * Get value type.
970
- */
971
- getValueType(cell) {
972
- invariant2(this._node, void 0, {
973
- F: __dxlog_file2,
974
- L: 273,
975
- S: this,
976
- A: [
977
- "this._node",
978
- ""
979
- ]
980
- });
981
- const addr = toSimpleCellAddress(this._node.sheetId, cell);
982
- const type = this._node.graph.hf.getCellValueDetailedType(addr);
983
- return typeMap[type];
984
- }
985
- /**
986
- * Sets the value, updating the sheet and engine.
987
- */
988
- setValue(cell, value) {
989
- invariant2(this._node, void 0, {
990
- F: __dxlog_file2,
991
- L: 283,
992
- S: this,
993
- A: [
994
- "this._node",
995
- ""
996
- ]
997
- });
998
- if (this._options.readonly) {
999
- throw new ReadonlyException();
471
+ return match;
1000
472
  }
1001
- let refresh = false;
1002
- if (cell.row >= this._sheet.rows.length) {
1003
- insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
1004
- refresh = true;
1005
- }
1006
- if (cell.col >= this._sheet.columns.length) {
1007
- insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
1008
- refresh = true;
1009
- }
1010
- if (refresh) {
1011
- this.reset();
473
+ });
474
+ };
475
+ var mapFormulaBindingFromId = (functions) => (formula) => {
476
+ return formula.replace(/([a-zA-Z0-9]+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
477
+ const id = `${spaceId}:${objectId}`;
478
+ if (id.length !== OBJECT_ID_LENGTH) {
479
+ return match;
1012
480
  }
1013
- this._node.graph.hf.setCellContents({
1014
- sheet: this._node.sheetId,
1015
- row: cell.row,
1016
- col: cell.col
1017
- }, [
1018
- [
1019
- typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value
1020
- ]
1021
- ]);
1022
- const idx = addressToIndex(this._sheet, cell);
1023
- if (value === void 0 || value === null) {
1024
- delete this._sheet.cells[idx];
481
+ const fn = functions.find((fn2) => fullyQualifiedId(fn2) === id);
482
+ if (fn?.binding) {
483
+ return `${fn.binding}(${args})`;
1025
484
  } else {
1026
- if (typeof value === "string" && value.charAt(0) === "=") {
1027
- value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
1028
- }
1029
- this._sheet.cells[idx] = {
1030
- value
1031
- };
1032
- }
1033
- }
1034
- /**
1035
- * Sets values from a simple map.
1036
- */
1037
- setValues(values) {
1038
- Object.entries(values).forEach(([key, { value }]) => {
1039
- this.setValue(addressFromA1Notation(key), value);
1040
- });
1041
- }
1042
- /**
1043
- * Iterate range.
1044
- */
1045
- _iterRange(range, cb) {
1046
- const to = range.to ?? range.from;
1047
- const rowRange = [
1048
- Math.min(range.from.row, to.row),
1049
- Math.max(range.from.row, to.row)
1050
- ];
1051
- const columnRange = [
1052
- Math.min(range.from.col, to.col),
1053
- Math.max(range.from.col, to.col)
1054
- ];
1055
- const rows = [];
1056
- for (let row = rowRange[0]; row <= rowRange[1]; row++) {
1057
- const rowCells = [];
1058
- for (let column = columnRange[0]; column <= columnRange[1]; column++) {
1059
- const value = cb({
1060
- row,
1061
- col: column
1062
- });
1063
- if (value !== void 0) {
1064
- rowCells.push(value);
1065
- }
1066
- }
1067
- rows.push(rowCells);
485
+ return match;
1068
486
  }
1069
- return rows;
1070
- }
1071
- // TODO(burdon): Delete index.
1072
- _deleteIndices(indices, i, n) {
1073
- throw new Error("Not implemented");
1074
- }
1075
- // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
1076
- _moveIndices(indices, i, j, n) {
1077
- throw new Error("Not implemented");
1078
- }
1079
- //
1080
- // Indices.
1081
- //
1082
- /**
1083
- * Map from A1 notation to indices.
1084
- */
1085
- mapFormulaRefsToIndices(formula) {
1086
- invariant2(formula.charAt(0) === "=", void 0, {
1087
- F: __dxlog_file2,
1088
- L: 372,
1089
- S: this,
1090
- A: [
1091
- "formula.charAt(0) === '='",
1092
- ""
1093
- ]
1094
- });
1095
- return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
1096
- return addressToIndex(this._sheet, addressFromA1Notation(match));
1097
- });
1098
- }
1099
- /**
1100
- * Map from indices to A1 notation.
1101
- */
1102
- mapFormulaIndicesToRefs(formula) {
1103
- invariant2(formula.charAt(0) === "=", void 0, {
1104
- F: __dxlog_file2,
1105
- L: 382,
1106
- S: this,
1107
- A: [
1108
- "formula.charAt(0) === '='",
1109
- ""
1110
- ]
1111
- });
1112
- return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
1113
- return addressToA1Notation(addressFromIndex(this._sheet, idx));
1114
- });
1115
- }
1116
- //
1117
- // Values
1118
- //
1119
- /**
1120
- * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
1121
- * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
1122
- * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
1123
- */
1124
- toLocalDate(num) {
1125
- const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
1126
- return new Date(year, month - 1, day, hours, minutes, seconds);
1127
- }
1128
- toDateTime(num) {
1129
- invariant2(this._node, void 0, {
1130
- F: __dxlog_file2,
1131
- L: 403,
1132
- S: this,
1133
- A: [
1134
- "this._node",
1135
- ""
1136
- ]
1137
- });
1138
- return this._node.graph.hf.numberToDateTime(num);
1139
- }
1140
- toDate(num) {
1141
- invariant2(this._node, void 0, {
1142
- F: __dxlog_file2,
1143
- L: 408,
1144
- S: this,
1145
- A: [
1146
- "this._node",
1147
- ""
1148
- ]
1149
- });
1150
- return this._node.graph.hf.numberToDate(num);
1151
- }
1152
- toTime(num) {
1153
- invariant2(this._node, void 0, {
1154
- F: __dxlog_file2,
1155
- L: 413,
1156
- S: this,
1157
- A: [
1158
- "this._node",
1159
- ""
1160
- ]
1161
- });
1162
- return this._node.graph.hf.numberToTime(num);
1163
- }
1164
- };
1165
-
1166
- // packages/plugins/plugin-sheet/src/hooks/useFormattingModel.ts
1167
- var useFormattingModel = (model) => {
1168
- return useMemo(() => model && new FormattingModel(model), [
1169
- model
1170
- ]);
487
+ });
1171
488
  };
1172
-
1173
- // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
1174
- import { useEffect as useEffect2, useState as useState3 } from "react";
1175
- var useSheetModel = (graph, sheet, { readonly } = {}) => {
1176
- const [model, setModel] = useState3();
489
+ var SheetContextProvider = ({ children, sheet, space, readonly, onInfo, ...options }) => {
490
+ const graph = useComputeGraph(space, options);
491
+ const [cursor, setCursor] = useState3();
492
+ const [range, setRange] = useState3();
493
+ const [editing, setEditing] = useState3(false);
494
+ const [[model, formatting] = [], setModels] = useState3(void 0);
1177
495
  useEffect2(() => {
1178
- if (!graph || !sheet) {
1179
- return;
1180
- }
1181
496
  let model2;
497
+ let formatting2;
1182
498
  const t = setTimeout(async () => {
1183
- model2 = new SheetModel(graph, sheet, {
1184
- readonly
499
+ model2 = new SheetModel(graph, sheet, space, {
500
+ readonly,
501
+ mapFormulaBindingToId,
502
+ mapFormulaBindingFromId
1185
503
  });
1186
- await model2.open();
1187
- setModel(model2);
504
+ await model2.initialize();
505
+ formatting2 = new FormattingModel(model2);
506
+ setModels([
507
+ model2,
508
+ formatting2
509
+ ]);
1188
510
  });
1189
511
  return () => {
1190
512
  clearTimeout(t);
1191
- void model2?.close();
513
+ void model2?.destroy();
1192
514
  };
1193
515
  }, [
1194
516
  graph,
1195
- sheet,
1196
517
  readonly
1197
518
  ]);
1198
- return model;
1199
- };
1200
-
1201
- // packages/plugins/plugin-sheet/src/components/Sheet/sheet-context.tsx
1202
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/Sheet/sheet-context.tsx";
1203
- var SheetContext = /* @__PURE__ */ createContext2(null);
1204
- var useSheetContext = () => {
1205
- const context = useContext2(SheetContext);
1206
- invariant3(context, void 0, {
1207
- F: __dxlog_file3,
1208
- L: 43,
1209
- S: void 0,
1210
- A: [
1211
- "context",
1212
- ""
1213
- ]
1214
- });
1215
- return context;
1216
- };
1217
- var SheetContextProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1218
- const model = useSheetModel(graph, sheet, {
1219
- readonly
1220
- });
1221
- const formatting = useFormattingModel(model);
1222
- const [cursor, setCursor] = useState4();
1223
- const [range, setRange] = useState4();
1224
- const [editing, setEditing] = useState4(false);
1225
- const decorations = useMemo2(() => createDecorations(), []);
1226
- return !model || !formatting ? null : /* @__PURE__ */ React3.createElement(SheetContext.Provider, {
519
+ if (!model || !formatting) {
520
+ return null;
521
+ }
522
+ return /* @__PURE__ */ React.createElement(SheetContext.Provider, {
1227
523
  value: {
1228
524
  model,
1229
525
  formatting,
@@ -1234,177 +530,11 @@ var SheetContextProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1234
530
  editing,
1235
531
  setEditing,
1236
532
  // TODO(burdon): Change to event.
1237
- onInfo,
1238
- decorations
533
+ onInfo
1239
534
  }
1240
535
  }, children);
1241
536
  };
1242
537
 
1243
- // packages/plugins/plugin-sheet/src/components/Sheet/threads.tsx
1244
- import { effect } from "@preact/signals-core";
1245
- import React4, { useCallback, useEffect as useEffect3, useMemo as useMemo3 } from "react";
1246
- import { LayoutAction, useIntentDispatcher, useIntentResolver } from "@dxos/app-framework";
1247
- import { debounce } from "@dxos/async";
1248
- import { fullyQualifiedId } from "@dxos/react-client/echo";
1249
- import { Icon, useTranslation } from "@dxos/react-ui";
1250
- var CommentIndicator = () => {
1251
- return /* @__PURE__ */ React4.createElement("div", {
1252
- role: "none",
1253
- className: "absolute top-0 right-0 w-0 h-0 border-t-8 border-l-8 border-t-cmCommentSurface border-l-transparent"
1254
- });
1255
- };
1256
- var ThreadedCellWrapper = ({ children }) => {
1257
- const dispatch = useIntentDispatcher();
1258
- const [isHovered, setIsHovered] = React4.useState(false);
1259
- const { t } = useTranslation(SHEET_PLUGIN);
1260
- const handleClick = React4.useCallback((_event) => {
1261
- void dispatch({
1262
- action: LayoutAction.SET_LAYOUT,
1263
- data: {
1264
- element: "complementary",
1265
- state: true
1266
- }
1267
- });
1268
- }, [
1269
- dispatch
1270
- ]);
1271
- return /* @__PURE__ */ React4.createElement("div", {
1272
- role: "none",
1273
- className: "relative h-full is-full",
1274
- onMouseEnter: () => {
1275
- setIsHovered(true);
1276
- },
1277
- onMouseLeave: () => {
1278
- setIsHovered(false);
1279
- }
1280
- }, /* @__PURE__ */ React4.createElement(CommentIndicator, null), isHovered && /* @__PURE__ */ React4.createElement("div", {
1281
- className: "absolute inset-0 flex items-center justify-end pr-1"
1282
- }, /* @__PURE__ */ React4.createElement("button", {
1283
- className: "ch-button text-xs min-bs-0 p-1",
1284
- onClick: handleClick,
1285
- "aria-label": t("open comment for sheet cell")
1286
- }, /* @__PURE__ */ React4.createElement(Icon, {
1287
- icon: "ph--chat--regular",
1288
- "aria-hidden": true
1289
- }))), children);
1290
- };
1291
- var createThreadDecoration = (cellIndex, threadId, sheetId) => {
1292
- return {
1293
- type: "comment",
1294
- cellIndex,
1295
- decorate: (props) => /* @__PURE__ */ React4.createElement(ThreadedCellWrapper, props)
1296
- };
1297
- };
1298
- var useUpdateCursorOnThreadSelection = () => {
1299
- const { setCursor, model } = useSheetContext();
1300
- const handleScrollIntoView = useCallback(({ action, data }) => {
1301
- switch (action) {
1302
- case LayoutAction.SCROLL_INTO_VIEW: {
1303
- if (!data?.id || data?.cursor === void 0 || data?.id !== fullyQualifiedId(model.sheet)) {
1304
- return;
1305
- }
1306
- const cellAddress = addressFromIndex(model.sheet, data.cursor);
1307
- setCursor(cellAddress);
1308
- }
1309
- }
1310
- }, [
1311
- model.sheet,
1312
- setCursor
1313
- ]);
1314
- useIntentResolver(SHEET_PLUGIN, handleScrollIntoView);
1315
- };
1316
- var useSelectThreadOnCursorChange = () => {
1317
- const { cursor, model } = useSheetContext();
1318
- const dispatch = useIntentDispatcher();
1319
- const activeThreads = useMemo3(() => model.sheet.threads?.filter((thread) => !!thread && thread.status === "active") ?? [], [
1320
- JSON.stringify(model.sheet.threads)
1321
- ]);
1322
- const activeThreadAddresses = useMemo3(() => activeThreads.map((thread) => thread.anchor).filter((anchor) => anchor !== void 0).map((anchor) => addressFromIndex(model.sheet, anchor)), [
1323
- activeThreads,
1324
- model.sheet
1325
- ]);
1326
- const selectClosestThread = useCallback((cellAddress) => {
1327
- if (!cellAddress || !activeThreads) {
1328
- return;
1329
- }
1330
- const closestThreadAnchor = closest(cellAddress, activeThreadAddresses);
1331
- if (closestThreadAnchor) {
1332
- const closestThread = activeThreads.find((thread) => thread && thread.anchor === addressToIndex(model.sheet, closestThreadAnchor));
1333
- if (closestThread) {
1334
- void dispatch([
1335
- {
1336
- action: "dxos.org/plugin/thread/action/select",
1337
- data: {
1338
- current: fullyQualifiedId(closestThread)
1339
- }
1340
- }
1341
- ]);
1342
- }
1343
- }
1344
- }, [
1345
- dispatch,
1346
- activeThreads,
1347
- activeThreadAddresses,
1348
- model.sheet
1349
- ]);
1350
- const debounced = useMemo3(() => {
1351
- return debounce((cursor2) => requestAnimationFrame(() => selectClosestThread(cursor2)), 50);
1352
- }, [
1353
- selectClosestThread
1354
- ]);
1355
- useEffect3(() => {
1356
- if (!cursor) {
1357
- return;
1358
- }
1359
- debounced(cursor);
1360
- }, [
1361
- cursor,
1362
- selectClosestThread
1363
- ]);
1364
- };
1365
- var useThreadDecorations = () => {
1366
- const { decorations, model } = useSheetContext();
1367
- const sheet = useMemo3(() => model.sheet, [
1368
- model.sheet
1369
- ]);
1370
- const sheetId = useMemo3(() => fullyQualifiedId(sheet), [
1371
- sheet
1372
- ]);
1373
- useEffect3(() => {
1374
- const unsubscribe = effect(() => {
1375
- const activeThreadAnchors = /* @__PURE__ */ new Set();
1376
- if (!sheet.threads) {
1377
- return;
1378
- }
1379
- for (const thread of sheet.threads) {
1380
- if (!thread || thread.anchor === void 0 || thread.status === "resolved") {
1381
- continue;
1382
- }
1383
- activeThreadAnchors.add(thread.anchor);
1384
- const index = thread.anchor;
1385
- const existingDecorations = decorations.getDecorationsForCell(index);
1386
- if (!existingDecorations || !existingDecorations.some((d) => d.type === "comment")) {
1387
- decorations.addDecoration(index, createThreadDecoration(index, thread.id, sheetId));
1388
- }
1389
- }
1390
- for (const decoration of decorations.getAllDecorations()) {
1391
- if (decoration.type !== "comment") {
1392
- continue;
1393
- }
1394
- if (!activeThreadAnchors.has(decoration.cellIndex)) {
1395
- decorations.removeDecoration(decoration.cellIndex, "comment");
1396
- }
1397
- }
1398
- });
1399
- return () => unsubscribe();
1400
- });
1401
- };
1402
- var useThreads = () => {
1403
- useUpdateCursorOnThreadSelection();
1404
- useSelectThreadOnCursorChange();
1405
- useThreadDecorations();
1406
- };
1407
-
1408
538
  // packages/plugins/plugin-sheet/src/components/Sheet/util.ts
1409
539
  var getRelativeClientRect = (root, element) => {
1410
540
  const rootRect = root.getBoundingClientRect();
@@ -1440,7 +570,7 @@ var scrollIntoView = (scrollContainer, el) => {
1440
570
 
1441
571
  // packages/plugins/plugin-sheet/src/components/CellEditor/CellEditor.tsx
1442
572
  import { EditorView, keymap } from "@codemirror/view";
1443
- import React5 from "react";
573
+ import React2 from "react";
1444
574
  import { useThemeContext } from "@dxos/react-ui";
1445
575
  import { createBasicExtensions, createThemeExtensions, preventNewline, useTextEditor } from "@dxos/react-ui-editor";
1446
576
  var editorKeys = ({ onNav, onClose }) => {
@@ -1488,60 +618,20 @@ var editorKeys = ({ onNav, onClose }) => {
1488
618
  {
1489
619
  key: "Enter",
1490
620
  run: (editor) => {
1491
- onClose(editor.state.doc.toString(), {
1492
- key: "Enter"
1493
- });
1494
- return true;
1495
- },
1496
- shift: (editor) => {
1497
- onClose(editor.state.doc.toString(), {
1498
- key: "Enter",
1499
- shift: true
1500
- });
1501
- return true;
1502
- }
1503
- },
1504
- {
1505
- key: "Tab",
1506
- run: (editor) => {
1507
- onClose(editor.state.doc.toString(), {
1508
- key: "Tab"
1509
- });
1510
- return true;
1511
- },
1512
- shift: (editor) => {
1513
- onClose(editor.state.doc.toString(), {
1514
- key: "Tab",
1515
- shift: true
1516
- });
621
+ onClose(editor.state.doc.toString());
1517
622
  return true;
1518
623
  }
1519
624
  },
1520
625
  {
1521
626
  key: "Escape",
1522
627
  run: () => {
1523
- onClose(void 0, {
1524
- key: "Escape"
1525
- });
628
+ onClose(void 0);
1526
629
  return true;
1527
630
  }
1528
631
  }
1529
632
  ]);
1530
633
  };
1531
- var editorVariants = {
1532
- // TODO(thure): remove when legacy is no longer used.
1533
- legacy: {
1534
- root: "flex w-full",
1535
- editor: "flex w-full [&>.cm-scroller]:scrollbar-none",
1536
- content: "!px-2 !py-1"
1537
- },
1538
- grid: {
1539
- root: "absolute z-[1]",
1540
- editor: "[&>.cm-scroller]:scrollbar-none tabular-nums",
1541
- content: "!border !border-transparent !p-0.5"
1542
- }
1543
- };
1544
- var CellEditor = ({ value, extension, autoFocus, onBlur, variant = "legacy", box, gridId }) => {
634
+ var CellEditor = ({ value, extension, autoFocus, onBlur }) => {
1545
635
  const { themeMode } = useThemeContext();
1546
636
  const { parentRef } = useTextEditor(() => {
1547
637
  return {
@@ -1568,39 +658,31 @@ var CellEditor = ({ value, extension, autoFocus, onBlur, variant = "legacy", box
1568
658
  themeMode,
1569
659
  slots: {
1570
660
  editor: {
1571
- className: editorVariants[variant].editor
661
+ className: "flex w-full [&>.cm-scroller]:scrollbar-none"
1572
662
  },
1573
663
  content: {
1574
- className: editorVariants[variant].content
664
+ className: "!px-2 !py-1"
1575
665
  }
1576
666
  }
1577
667
  })
1578
668
  ]
1579
669
  };
1580
670
  }, [
1581
- extension,
1582
- autoFocus,
1583
- value,
1584
- variant,
1585
- onBlur
671
+ extension
1586
672
  ]);
1587
- return /* @__PURE__ */ React5.createElement("div", {
673
+ return /* @__PURE__ */ React2.createElement("div", {
1588
674
  ref: parentRef,
1589
- className: editorVariants[variant].root,
1590
- style: box,
1591
- ...gridId && {
1592
- "data-grid": gridId
1593
- }
675
+ className: "flex w-full"
1594
676
  });
1595
677
  };
1596
678
 
1597
679
  // packages/plugins/plugin-sheet/src/components/CellEditor/extension.ts
1598
680
  import { acceptCompletion, autocompletion, completionStatus, startCompletion } from "@codemirror/autocomplete";
1599
681
  import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
682
+ import { Facet } from "@codemirror/state";
1600
683
  import { ViewPlugin, keymap as keymap2 } from "@codemirror/view";
1601
684
  import { tags } from "@lezer/highlight";
1602
685
  import { spreadsheet } from "codemirror-lang-spreadsheet";
1603
- import { singleValueFacet } from "@dxos/react-ui-editor/state";
1604
686
  import { mx } from "@dxos/react-ui-theme";
1605
687
  var highlightStyles = HighlightStyle.define([
1606
688
  // Function.
@@ -1632,7 +714,7 @@ var highlightStyles = HighlightStyle.define([
1632
714
  class: "text-unAccent"
1633
715
  }
1634
716
  ]);
1635
- var languageFacet = singleValueFacet();
717
+ var languageFacet = Facet.define();
1636
718
  var sheetExtension = ({ functions = [] }) => {
1637
719
  const { extension, language } = spreadsheet({
1638
720
  idiom: "en-US",
@@ -1712,7 +794,13 @@ var sheetExtension = ({ functions = [] }) => {
1712
794
  // NOTE: Useful for debugging.
1713
795
  closeOnBlur: false,
1714
796
  icons: false,
1715
- tooltipClass: () => mx("!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]", "[&>ul>li[aria-selected]]:!bg-accentSurface", "border-separator")
797
+ tooltipClass: () => mx(
798
+ // TODO(burdon): Factor out fragments.
799
+ // TODO(burdon): Size to make width same as column.
800
+ "!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]",
801
+ "[&>ul>li[aria-selected]]:!bg-accentSurface",
802
+ "border-separator"
803
+ )
1716
804
  }),
1717
805
  keymap2.of([
1718
806
  {
@@ -1749,7 +837,7 @@ var rangeExtension = (onInit) => {
1749
837
  update(view2) {
1750
838
  const { anchor } = view2.state.selection.ranges[0];
1751
839
  activeRange = void 0;
1752
- const language = view2.state.facet(languageFacet);
840
+ const [language] = view2.state.facet(languageFacet);
1753
841
  const { topNode } = language.parser.parse(view2.state.doc.toString());
1754
842
  visitTree(topNode, ({ type, from, to }) => {
1755
843
  if (from <= anchor && to >= anchor) {
@@ -1801,7 +889,7 @@ var visitTree = (node, callback) => {
1801
889
  };
1802
890
 
1803
891
  // packages/plugins/plugin-sheet/src/components/Sheet/Sheet.tsx
1804
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/Sheet/Sheet.tsx";
892
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/Sheet/Sheet.tsx";
1805
893
  var fragments = {
1806
894
  axis: "bg-axisSurface text-axisText text-xs select-none",
1807
895
  axisSelected: "bg-attention text-baseText",
@@ -1809,26 +897,25 @@ var fragments = {
1809
897
  cellSelected: "bg-gridCellSelected text-baseText border !border-accentSurface"
1810
898
  };
1811
899
  var SheetRoot = ({ children, ...props }) => {
1812
- return /* @__PURE__ */ React6.createElement(SheetContextProvider, props, children);
900
+ return /* @__PURE__ */ React3.createElement(SheetContextProvider, props, children);
1813
901
  };
1814
- var SheetMain = /* @__PURE__ */ forwardRef(({ classNames, numRows, numCols }, forwardRef2) => {
902
+ var SheetMain = /* @__PURE__ */ forwardRef(({ classNames, numRows, numColumns }, forwardRef2) => {
1815
903
  const { model, cursor, setCursor, setRange, setEditing } = useSheetContext();
1816
904
  const { rowsRef, columnsRef, contentRef } = useScrollHandlers();
1817
- useThreads();
1818
- const [rows, setRows] = useState5([
905
+ const [rows, setRows] = useState4([
1819
906
  ...model.sheet.rows
1820
907
  ]);
1821
- const [columns, setColumns] = useState5([
908
+ const [columns, setColumns] = useState4([
1822
909
  ...model.sheet.columns
1823
910
  ]);
1824
- useEffect4(() => {
911
+ useEffect3(() => {
1825
912
  const rowsAccessor = createDocAccessor(model.sheet, [
1826
913
  "rows"
1827
914
  ]);
1828
915
  const columnsAccessor = createDocAccessor(model.sheet, [
1829
916
  "columns"
1830
917
  ]);
1831
- const handleUpdate = debounce2(() => {
918
+ const handleUpdate = debounce(() => {
1832
919
  setRows([
1833
920
  ...model.sheet.rows
1834
921
  ]);
@@ -1846,44 +933,44 @@ var SheetMain = /* @__PURE__ */ forwardRef(({ classNames, numRows, numCols }, fo
1846
933
  }, [
1847
934
  model
1848
935
  ]);
1849
- useEffect4(() => {
936
+ useEffect3(() => {
1850
937
  model.reset();
1851
938
  }, [
1852
939
  rows,
1853
940
  columns
1854
941
  ]);
1855
942
  const handleMoveRows = (from, to, num = 1) => {
1856
- const cursorIdx = cursor ? addressToIndex(model.sheet, cursor) : void 0;
943
+ const cursorIdx = cursor ? model.addressToIndex(cursor) : void 0;
1857
944
  const [rows2] = model.sheet.rows.splice(from, num);
1858
945
  model.sheet.rows.splice(to, 0, rows2);
1859
946
  if (cursorIdx) {
1860
- setCursor(addressFromIndex(model.sheet, cursorIdx));
947
+ setCursor(model.addressFromIndex(cursorIdx));
1861
948
  }
1862
949
  setRows([
1863
950
  ...model.sheet.rows
1864
951
  ]);
1865
952
  };
1866
953
  const handleMoveColumns = (from, to, num = 1) => {
1867
- const cursorIdx = cursor ? addressToIndex(model.sheet, cursor) : void 0;
954
+ const cursorIdx = cursor ? model.addressToIndex(cursor) : void 0;
1868
955
  const columns2 = model.sheet.columns.splice(from, num);
1869
956
  model.sheet.columns.splice(to, 0, ...columns2);
1870
957
  if (cursorIdx) {
1871
- setCursor(addressFromIndex(model.sheet, cursorIdx));
958
+ setCursor(model.addressFromIndex(cursorIdx));
1872
959
  }
1873
960
  setColumns([
1874
961
  ...model.sheet.columns
1875
962
  ]);
1876
963
  };
1877
- const [rowSizes, setRowSizes] = useState5();
1878
- const [columnSizes, setColumnSizes] = useState5();
1879
- useEffect4(() => {
964
+ const [rowSizes, setRowSizes] = useState4();
965
+ const [columnSizes, setColumnSizes] = useState4();
966
+ useEffect3(() => {
1880
967
  const rowAccessor = createDocAccessor(model.sheet, [
1881
968
  "rowMeta"
1882
969
  ]);
1883
970
  const columnAccessor = createDocAccessor(model.sheet, [
1884
971
  "columnMeta"
1885
972
  ]);
1886
- const handleUpdate = debounce2(() => {
973
+ const handleUpdate = debounce(() => {
1887
974
  const mapSizes = (values) => values.reduce((map, [idx, meta]) => {
1888
975
  if (meta.size) {
1889
976
  map[idx] = meta.size;
@@ -1925,54 +1012,54 @@ var SheetMain = /* @__PURE__ */ forwardRef(({ classNames, numRows, numCols }, fo
1925
1012
  }));
1926
1013
  }
1927
1014
  };
1928
- return /* @__PURE__ */ React6.createElement("div", {
1015
+ return /* @__PURE__ */ React3.createElement("div", {
1929
1016
  role: "none",
1930
1017
  className: mx2("grid grid-cols-[calc(var(--rail-size)-2px)_1fr] grid-rows-[32px_1fr_32px] bs-full is-full overflow-hidden", classNames)
1931
- }, /* @__PURE__ */ React6.createElement(GridCorner, {
1018
+ }, /* @__PURE__ */ React3.createElement(GridCorner, {
1932
1019
  onClick: () => {
1933
1020
  setCursor(void 0);
1934
1021
  setRange(void 0);
1935
1022
  setEditing(false);
1936
1023
  }
1937
- }), /* @__PURE__ */ React6.createElement(SheetColumns, {
1024
+ }), /* @__PURE__ */ React3.createElement(SheetColumns, {
1938
1025
  ref: columnsRef,
1939
1026
  columns,
1940
1027
  sizes: columnSizes,
1941
- selected: cursor?.col,
1942
- onSelect: (col) => setCursor(cursor?.col === col ? void 0 : {
1028
+ selected: cursor?.column,
1029
+ onSelect: (column) => setCursor(cursor?.column === column ? void 0 : {
1943
1030
  row: -1,
1944
- col
1031
+ column
1945
1032
  }),
1946
1033
  onResize: handleResizeColumn,
1947
1034
  onMove: handleMoveColumns
1948
- }), /* @__PURE__ */ React6.createElement(SheetRows, {
1035
+ }), /* @__PURE__ */ React3.createElement(SheetRows, {
1949
1036
  ref: rowsRef,
1950
1037
  rows,
1951
1038
  sizes: rowSizes,
1952
1039
  selected: cursor?.row,
1953
1040
  onSelect: (row) => setCursor(cursor?.row === row ? void 0 : {
1954
1041
  row,
1955
- col: -1
1042
+ column: -1
1956
1043
  }),
1957
1044
  onResize: handleResizeRow,
1958
1045
  onMove: handleMoveRows
1959
- }), /* @__PURE__ */ React6.createElement(SheetGrid, {
1046
+ }), /* @__PURE__ */ React3.createElement(SheetGrid, {
1960
1047
  ref: contentRef,
1961
1048
  size: {
1962
1049
  numRows: numRows ?? rows.length,
1963
- numCols: numCols ?? columns.length
1050
+ numColumns: numColumns ?? columns.length
1964
1051
  },
1965
1052
  rows,
1966
1053
  columns,
1967
1054
  rowSizes,
1968
1055
  columnSizes
1969
- }), /* @__PURE__ */ React6.createElement(GridCorner, null), /* @__PURE__ */ React6.createElement(SheetStatusBar, null));
1056
+ }), /* @__PURE__ */ React3.createElement(GridCorner, null), /* @__PURE__ */ React3.createElement(SheetStatusBar, null));
1970
1057
  });
1971
1058
  var useScrollHandlers = () => {
1972
1059
  const rowsRef = useRef(null);
1973
1060
  const columnsRef = useRef(null);
1974
1061
  const contentRef = useRef(null);
1975
- useEffect4(() => {
1062
+ useEffect3(() => {
1976
1063
  const handleRowsScroll = (ev) => {
1977
1064
  const { scrollTop } = ev.target;
1978
1065
  if (!rowsRef.current.dataset.locked) {
@@ -2009,13 +1096,13 @@ var useScrollHandlers = () => {
2009
1096
  };
2010
1097
  };
2011
1098
  var GridCorner = (props) => {
2012
- return /* @__PURE__ */ React6.createElement("div", {
1099
+ return /* @__PURE__ */ React3.createElement("div", {
2013
1100
  className: fragments.axis,
2014
1101
  ...props
2015
1102
  });
2016
1103
  };
2017
1104
  var MovingOverlay = ({ label }) => {
2018
- return /* @__PURE__ */ React6.createElement("div", {
1105
+ return /* @__PURE__ */ React3.createElement("div", {
2019
1106
  className: "flex w-full h-full justify-center items-center text-sm p-1 bg-gridOverlay cursor-pointer"
2020
1107
  }, label);
2021
1108
  };
@@ -2035,7 +1122,7 @@ var SheetRows = /* @__PURE__ */ forwardRef(({ rows, sizes, selected, onSelect, o
2035
1122
  });
2036
1123
  const keyboardSensor = useSensor(KeyboardSensor, {});
2037
1124
  const sensors = useSensors(mouseSensor, touchSensor, keyboardSensor);
2038
- const [active, setActive] = useState5(null);
1125
+ const [active, setActive] = useState4(null);
2039
1126
  const handleDragStart = ({ active: active2 }) => {
2040
1127
  setActive(active2);
2041
1128
  };
@@ -2059,18 +1146,18 @@ var SheetRows = /* @__PURE__ */ forwardRef(({ rows, sizes, selected, onSelect, o
2059
1146
  }
2060
1147
  return transform;
2061
1148
  };
2062
- return /* @__PURE__ */ React6.createElement("div", {
1149
+ return /* @__PURE__ */ React3.createElement("div", {
2063
1150
  className: "relative flex grow overflow-hidden"
2064
- }, /* @__PURE__ */ React6.createElement("div", {
1151
+ }, /* @__PURE__ */ React3.createElement("div", {
2065
1152
  className: mx2("z-20 absolute inset-0 border-y border-gridLine pointer-events-none"),
2066
1153
  style: {
2067
1154
  width: axisWidth
2068
1155
  }
2069
- }), /* @__PURE__ */ React6.createElement("div", {
1156
+ }), /* @__PURE__ */ React3.createElement("div", {
2070
1157
  ref: forwardRef2,
2071
1158
  role: "rowheader",
2072
1159
  className: "grow overflow-y-auto scrollbar-none"
2073
- }, /* @__PURE__ */ React6.createElement(DndContext, {
1160
+ }, /* @__PURE__ */ React3.createElement(DndContext, {
2074
1161
  sensors,
2075
1162
  modifiers: [
2076
1163
  restrictToVerticalAxis,
@@ -2078,12 +1165,12 @@ var SheetRows = /* @__PURE__ */ forwardRef(({ rows, sizes, selected, onSelect, o
2078
1165
  ],
2079
1166
  onDragStart: handleDragStart,
2080
1167
  onDragEnd: handleDragEnd
2081
- }, /* @__PURE__ */ React6.createElement("div", {
1168
+ }, /* @__PURE__ */ React3.createElement("div", {
2082
1169
  className: "flex flex-col",
2083
1170
  style: {
2084
1171
  width: axisWidth
2085
1172
  }
2086
- }, rows.map((idx, index) => /* @__PURE__ */ React6.createElement(GridRowCell, {
1173
+ }, rows.map((idx, index) => /* @__PURE__ */ React3.createElement(GridRowCell, {
2087
1174
  key: idx,
2088
1175
  idx,
2089
1176
  index,
@@ -2093,7 +1180,7 @@ var SheetRows = /* @__PURE__ */ forwardRef(({ rows, sizes, selected, onSelect, o
2093
1180
  selected: selected === index,
2094
1181
  onResize,
2095
1182
  onSelect
2096
- }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(DragOverlay, null, active && /* @__PURE__ */ React6.createElement(MovingOverlay, {
1183
+ }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React3.createElement(DragOverlay, null, active && /* @__PURE__ */ React3.createElement(MovingOverlay, {
2097
1184
  label: String(active.data.current.index + 1)
2098
1185
  })), document.body))));
2099
1186
  });
@@ -2111,8 +1198,8 @@ var GridRowCell = ({ idx, index, label, size, resize, selected, onSelect, onResi
2111
1198
  }
2112
1199
  });
2113
1200
  const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
2114
- const [initialSize, setInitialSize] = useState5(size);
2115
- const [resizing, setResizing] = useState5(false);
1201
+ const [initialSize, setInitialSize] = useState4(size);
1202
+ const [resizing, setResizing] = useState4(false);
2116
1203
  const scrollHandler = useRef();
2117
1204
  const handleResizeStart = (_ev, _dir, elementRef) => {
2118
1205
  const scrollContainer = elementRef.closest('[role="rowheader"]');
@@ -2134,7 +1221,7 @@ var GridRowCell = ({ idx, index, label, size, resize, selected, onSelect, onResi
2134
1221
  onResize?.(idx, initialSize + height, true);
2135
1222
  setResizing(false);
2136
1223
  };
2137
- return /* @__PURE__ */ React6.createElement(Resizable, {
1224
+ return /* @__PURE__ */ React3.createElement(Resizable, {
2138
1225
  enable: {
2139
1226
  bottom: resize
2140
1227
  },
@@ -2146,17 +1233,17 @@ var GridRowCell = ({ idx, index, label, size, resize, selected, onSelect, onResi
2146
1233
  onResizeStart: handleResizeStart,
2147
1234
  onResize: handleResize,
2148
1235
  onResizeStop: handleResizeStop
2149
- }, /* @__PURE__ */ React6.createElement("div", {
1236
+ }, /* @__PURE__ */ React3.createElement("div", {
2150
1237
  ref: setNodeRef,
2151
1238
  ...attributes,
2152
1239
  ...listeners,
2153
1240
  className: mx2("flex h-full items-center justify-center cursor-pointer", "border-t border-gridLine focus-visible:outline-none", fragments.axis, selected && fragments.axisSelected, isDragging && fragments.axisSelected),
2154
1241
  onClick: () => onSelect?.(index)
2155
- }, /* @__PURE__ */ React6.createElement("span", {
1242
+ }, /* @__PURE__ */ React3.createElement("span", {
2156
1243
  className: "flex w-full justify-center"
2157
- }, label), over?.id === idx && !isDragging && /* @__PURE__ */ React6.createElement("div", {
1244
+ }, label), over?.id === idx && !isDragging && /* @__PURE__ */ React3.createElement("div", {
2158
1245
  className: "z-20 absolute top-0 w-full min-h-[4px] border-b-4 border-accentSurface"
2159
- }), resizing && /* @__PURE__ */ React6.createElement("div", {
1246
+ }), resizing && /* @__PURE__ */ React3.createElement("div", {
2160
1247
  className: "z-20 absolute bottom-0 w-full min-h-[4px] border-b-4 border-accentSurface"
2161
1248
  })));
2162
1249
  };
@@ -2169,7 +1256,7 @@ var SheetColumns = /* @__PURE__ */ forwardRef(({ columns, sizes, selected, onSel
2169
1256
  });
2170
1257
  const keyboardSensor = useSensor(KeyboardSensor, {});
2171
1258
  const sensors = useSensors(mouseSensor, touchSensor, keyboardSensor);
2172
- const [active, setActive] = useState5(null);
1259
+ const [active, setActive] = useState4(null);
2173
1260
  const handleDragStart = ({ active: active2 }) => {
2174
1261
  setActive(active2);
2175
1262
  };
@@ -2193,18 +1280,18 @@ var SheetColumns = /* @__PURE__ */ forwardRef(({ columns, sizes, selected, onSel
2193
1280
  }
2194
1281
  return transform;
2195
1282
  };
2196
- return /* @__PURE__ */ React6.createElement("div", {
1283
+ return /* @__PURE__ */ React3.createElement("div", {
2197
1284
  className: "relative flex grow overflow-hidden"
2198
- }, /* @__PURE__ */ React6.createElement("div", {
1285
+ }, /* @__PURE__ */ React3.createElement("div", {
2199
1286
  className: mx2("z-20 absolute inset-0 border-x border-gridLine pointer-events-none"),
2200
1287
  style: {
2201
1288
  height: axisHeight
2202
1289
  }
2203
- }), /* @__PURE__ */ React6.createElement("div", {
1290
+ }), /* @__PURE__ */ React3.createElement("div", {
2204
1291
  ref: forwardRef2,
2205
1292
  role: "columnheader",
2206
1293
  className: "grow overflow-x-auto scrollbar-none"
2207
- }, /* @__PURE__ */ React6.createElement(DndContext, {
1294
+ }, /* @__PURE__ */ React3.createElement(DndContext, {
2208
1295
  autoScroll: {
2209
1296
  enabled: true
2210
1297
  },
@@ -2215,12 +1302,12 @@ var SheetColumns = /* @__PURE__ */ forwardRef(({ columns, sizes, selected, onSel
2215
1302
  ],
2216
1303
  onDragStart: handleDragStart,
2217
1304
  onDragEnd: handleDragEnd
2218
- }, /* @__PURE__ */ React6.createElement("div", {
1305
+ }, /* @__PURE__ */ React3.createElement("div", {
2219
1306
  className: "flex h-full",
2220
1307
  style: {
2221
1308
  height: axisHeight
2222
1309
  }
2223
- }, columns.map((idx, index) => /* @__PURE__ */ React6.createElement(GridColumnCell, {
1310
+ }, columns.map((idx, index) => /* @__PURE__ */ React3.createElement(GridColumnCell, {
2224
1311
  key: idx,
2225
1312
  idx,
2226
1313
  index,
@@ -2230,7 +1317,7 @@ var SheetColumns = /* @__PURE__ */ forwardRef(({ columns, sizes, selected, onSel
2230
1317
  selected: selected === index,
2231
1318
  onResize,
2232
1319
  onSelect
2233
- }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(DragOverlay, null, active && /* @__PURE__ */ React6.createElement(MovingOverlay, {
1320
+ }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React3.createElement(DragOverlay, null, active && /* @__PURE__ */ React3.createElement(MovingOverlay, {
2234
1321
  label: columnLetter(active.data.current.index)
2235
1322
  })), document.body))));
2236
1323
  });
@@ -2248,8 +1335,8 @@ var GridColumnCell = ({ idx, index, label, size, resize, selected, onSelect, onR
2248
1335
  }
2249
1336
  });
2250
1337
  const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
2251
- const [initialSize, setInitialSize] = useState5(size);
2252
- const [resizing, setResizing] = useState5(false);
1338
+ const [initialSize, setInitialSize] = useState4(size);
1339
+ const [resizing, setResizing] = useState4(false);
2253
1340
  const scrollHandler = useRef();
2254
1341
  const handleResizeStart = (_ev, _dir, elementRef) => {
2255
1342
  const scrollContainer = elementRef.closest('[role="columnheader"]');
@@ -2271,7 +1358,7 @@ var GridColumnCell = ({ idx, index, label, size, resize, selected, onSelect, onR
2271
1358
  onResize?.(idx, initialSize + width, true);
2272
1359
  setResizing(false);
2273
1360
  };
2274
- return /* @__PURE__ */ React6.createElement(Resizable, {
1361
+ return /* @__PURE__ */ React3.createElement(Resizable, {
2275
1362
  enable: {
2276
1363
  right: resize
2277
1364
  },
@@ -2283,17 +1370,17 @@ var GridColumnCell = ({ idx, index, label, size, resize, selected, onSelect, onR
2283
1370
  onResizeStart: handleResizeStart,
2284
1371
  onResize: handleResize,
2285
1372
  onResizeStop: handleResizeStop
2286
- }, /* @__PURE__ */ React6.createElement("div", {
1373
+ }, /* @__PURE__ */ React3.createElement("div", {
2287
1374
  ref: setNodeRef,
2288
1375
  ...attributes,
2289
1376
  ...listeners,
2290
1377
  className: mx2("flex h-full items-center justify-center cursor-pointer", "border-l border-gridLine focus-visible:outline-none", fragments.axis, selected && fragments.axisSelected, isDragging && fragments.axisSelected),
2291
1378
  onClick: () => onSelect?.(index)
2292
- }, /* @__PURE__ */ React6.createElement("span", {
1379
+ }, /* @__PURE__ */ React3.createElement("span", {
2293
1380
  className: "flex w-full justify-center"
2294
- }, label), over?.id === idx && !isDragging && /* @__PURE__ */ React6.createElement("div", {
1381
+ }, label), over?.id === idx && !isDragging && /* @__PURE__ */ React3.createElement("div", {
2295
1382
  className: "z-20 absolute left-0 h-full min-w-[4px] border-l-4 border-accentSurface"
2296
- }), resizing && /* @__PURE__ */ React6.createElement("div", {
1383
+ }), resizing && /* @__PURE__ */ React3.createElement("div", {
2297
1384
  className: "z-20 absolute right-0 h-full min-h-[4px] border-l-4 border-accentSurface"
2298
1385
  })));
2299
1386
  };
@@ -2306,14 +1393,14 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2306
1393
  const { model, cursor, range, editing, setCursor, setRange, setEditing, onInfo } = useSheetContext();
2307
1394
  const initialText = useRef();
2308
1395
  const quickEdit = useRef(false);
2309
- const [, forceUpdate] = useState5({});
2310
- useEffect4(() => {
1396
+ const [, forceUpdate] = useState4({});
1397
+ useEffect3(() => {
2311
1398
  const unsubscribe = model.update.on(() => {
2312
- log2("updated", {
1399
+ log("updated", {
2313
1400
  id: model.id
2314
1401
  }, {
2315
- F: __dxlog_file4,
2316
- L: 738,
1402
+ F: __dxlog_file2,
1403
+ L: 730,
2317
1404
  S: void 0,
2318
1405
  C: (f, a) => f(...a)
2319
1406
  });
@@ -2431,17 +1518,18 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2431
1518
  columnSizes
2432
1519
  });
2433
1520
  const id = fullyQualifiedId2(model.sheet);
2434
- const { hasAttention } = useAttention(id);
2435
- return /* @__PURE__ */ React6.createElement("div", {
1521
+ const attendableAttrs = createAttendableAttributes(id);
1522
+ const hasAttention = useHasAttention(id);
1523
+ return /* @__PURE__ */ React3.createElement("div", {
2436
1524
  ref: containerRef,
2437
1525
  role: "grid",
2438
1526
  className: "relative flex grow overflow-hidden"
2439
- }, /* @__PURE__ */ React6.createElement("div", {
1527
+ }, /* @__PURE__ */ React3.createElement("div", {
2440
1528
  className: mx2("z-20 absolute inset-0 border border-gridLine pointer-events-none")
2441
- }), /* @__PURE__ */ React6.createElement("div", {
1529
+ }), /* @__PURE__ */ React3.createElement("div", {
2442
1530
  ref: scrollerRef,
2443
1531
  className: mx2("grow", hasAttention && "overflow-auto scrollbar-thin")
2444
- }, /* @__PURE__ */ React6.createElement("div", {
1532
+ }, /* @__PURE__ */ React3.createElement("div", {
2445
1533
  className: "relative select-none",
2446
1534
  style: {
2447
1535
  width,
@@ -2449,10 +1537,10 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2449
1537
  },
2450
1538
  onClick: () => inputRef.current?.focus(),
2451
1539
  ...handlers
2452
- }, scrollerRef.current && /* @__PURE__ */ React6.createElement(SelectionOverlay, {
1540
+ }, scrollerRef.current && /* @__PURE__ */ React3.createElement(SelectionOverlay, {
2453
1541
  root: scrollerRef.current
2454
1542
  }), rowRange.map(({ row, top, height: height2 }) => {
2455
- return columnRange.map(({ col, left, width: width2 }) => {
1543
+ return columnRange.map(({ column, left, width: width2 }) => {
2456
1544
  const style = {
2457
1545
  position: "absolute",
2458
1546
  top,
@@ -2462,10 +1550,10 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2462
1550
  };
2463
1551
  const cell = {
2464
1552
  row,
2465
- col
1553
+ column
2466
1554
  };
2467
1555
  const id2 = addressToA1Notation(cell);
2468
- const idx = addressToIndex(model.sheet, cell);
1556
+ const idx = model.addressToIndex(cell);
2469
1557
  const active = posEquals(cursor, cell);
2470
1558
  if (active && editing) {
2471
1559
  const value = initialText.current ?? model.getCellText(cell) ?? "";
@@ -2498,7 +1586,7 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2498
1586
  inputRef.current?.focus();
2499
1587
  setEditing(false);
2500
1588
  };
2501
- return /* @__PURE__ */ React6.createElement(GridCellEditor, {
1589
+ return /* @__PURE__ */ React3.createElement(GridCellEditor, {
2502
1590
  key: idx,
2503
1591
  value,
2504
1592
  style,
@@ -2506,7 +1594,7 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2506
1594
  onClose: handleClose
2507
1595
  });
2508
1596
  }
2509
- return /* @__PURE__ */ React6.createElement(SheetCell, {
1597
+ return /* @__PURE__ */ React3.createElement(SheetCell, {
2510
1598
  key: id2,
2511
1599
  id: id2,
2512
1600
  cell,
@@ -2518,25 +1606,13 @@ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, col
2518
1606
  }
2519
1607
  });
2520
1608
  });
2521
- }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(SheetInput, {
1609
+ }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React3.createElement("input", {
2522
1610
  ref: inputRef,
2523
- id,
2524
- onKeyDown: handleKeyDown
2525
- }), document.body));
2526
- });
2527
- var SheetInput = /* @__PURE__ */ forwardRef(({ id, onKeyDown }, forwardedRef) => {
2528
- const path = useAttentionPath();
2529
- const attendableAttrs = useAttendableAttributes(id);
2530
- return path.toReversed().reduce((acc, part) => {
2531
- return /* @__PURE__ */ React6.createElement("div", {
2532
- [ATTENABLE_ATTRIBUTE]: part
2533
- }, acc);
2534
- }, /* @__PURE__ */ React6.createElement("input", {
2535
- ref: forwardedRef,
1611
+ autoFocus: true,
2536
1612
  className: "absolute w-[1px] h-[1px] bg-transparent outline-none border-none caret-transparent",
2537
- onKeyDown,
1613
+ onKeyDown: handleKeyDown,
2538
1614
  ...attendableAttrs
2539
- }));
1615
+ }), document.body));
2540
1616
  });
2541
1617
  var SelectionOverlay = ({ root }) => {
2542
1618
  const { range } = useSheetContext();
@@ -2551,34 +1627,20 @@ var SelectionOverlay = ({ root }) => {
2551
1627
  const b1 = getRelativeClientRect(root, c1);
2552
1628
  const b2 = getRelativeClientRect(root, c2);
2553
1629
  const bounds = getRectUnion(b1, b2);
2554
- return /* @__PURE__ */ React6.createElement("div", {
1630
+ return /* @__PURE__ */ React3.createElement("div", {
2555
1631
  role: "none",
2556
1632
  style: bounds,
2557
1633
  className: "z-10 absolute pointer-events-none bg-gridSelectionOverlay border border-gridOverlay"
2558
1634
  });
2559
1635
  };
2560
1636
  var SheetCell = ({ id, cell, style, active, onSelect }) => {
2561
- const { formatting, editing, setRange, decorations, model: { sheet } } = useSheetContext();
1637
+ const { formatting, editing, setRange } = useSheetContext();
2562
1638
  const { value, classNames } = formatting.getFormatting(cell);
2563
- const decorationsForCell = decorations.getDecorationsForCell(addressToIndex(sheet, cell)) ?? [];
2564
- const decorationAddedClasses = useMemo4(() => decorationsForCell.flatMap((d) => d.classNames ?? []), [
2565
- decorationsForCell
2566
- ]);
2567
- const decoratedContent = decorationsForCell.reduce((children, { decorate }) => {
2568
- if (!decorate) {
2569
- return children;
2570
- }
2571
- const DecoratorComponent = decorate;
2572
- return /* @__PURE__ */ React6.createElement(DecoratorComponent, null, children);
2573
- }, /* @__PURE__ */ React6.createElement("div", {
2574
- role: "none",
2575
- className: mx2("flex flex-grow bs-full is-full px-2 items-center truncate cursor-pointer", ...decorationAddedClasses)
2576
- }, value));
2577
- return /* @__PURE__ */ React6.createElement("div", {
1639
+ return /* @__PURE__ */ React3.createElement("div", {
2578
1640
  [`data-${CELL_DATA_KEY}`]: id,
2579
1641
  role: "cell",
2580
1642
  style,
2581
- className: mx2("border border-gridLine cursor-pointer", fragments.cell, active && [
1643
+ className: mx2("flex w-full h-full px-2 py-1 truncate items-center border border-gridLine cursor-pointer", fragments.cell, active && [
2582
1644
  "z-20",
2583
1645
  fragments.cellSelected
2584
1646
  ], classNames),
@@ -2592,36 +1654,36 @@ var SheetCell = ({ id, cell, style, active, onSelect }) => {
2592
1654
  }
2593
1655
  },
2594
1656
  onDoubleClick: () => onSelect?.(cell, true)
2595
- }, decoratedContent);
1657
+ }, value);
2596
1658
  };
2597
1659
  var GridCellEditor = ({ style, value, onNav, onClose }) => {
2598
1660
  const { model, range } = useSheetContext();
2599
1661
  const notifier = useRef();
2600
- useEffect4(() => {
1662
+ useEffect3(() => {
2601
1663
  if (range) {
2602
1664
  notifier.current?.(rangeToA1Notation(range));
2603
1665
  }
2604
1666
  }, [
2605
1667
  range
2606
1668
  ]);
2607
- const extension = useMemo4(() => [
1669
+ const extension = useMemo(() => [
2608
1670
  editorKeys({
2609
1671
  onNav,
2610
1672
  onClose
2611
1673
  }),
2612
1674
  sheetExtension({
2613
- functions: model.graph.getFunctions()
1675
+ functions: model.functions
2614
1676
  }),
2615
1677
  rangeExtension((fn) => notifier.current = fn)
2616
1678
  ], [
2617
1679
  model
2618
1680
  ]);
2619
- return /* @__PURE__ */ React6.createElement("div", {
1681
+ return /* @__PURE__ */ React3.createElement("div", {
2620
1682
  role: "cell",
2621
1683
  style,
2622
1684
  className: mx2("z-20 flex", fragments.cellSelected),
2623
1685
  onClick: (ev) => ev.stopPropagation()
2624
- }, /* @__PURE__ */ React6.createElement(CellEditor, {
1686
+ }, /* @__PURE__ */ React3.createElement(CellEditor, {
2625
1687
  autoFocus: true,
2626
1688
  value,
2627
1689
  extension
@@ -2634,30 +1696,30 @@ var SheetStatusBar = () => {
2634
1696
  if (cursor) {
2635
1697
  value = model.getCellValue(cursor);
2636
1698
  if (typeof value === "string" && value.charAt(0) === "=") {
2637
- value = model.graph.mapFunctionBindingFromId(model.mapFormulaIndicesToRefs(value));
1699
+ value = model.mapFormulaBindingFromId(model.mapFormulaIndicesToRefs(value));
2638
1700
  isFormula = true;
2639
1701
  } else if (value != null) {
2640
1702
  value = String(value);
2641
1703
  }
2642
1704
  }
2643
- return /* @__PURE__ */ React6.createElement("div", {
1705
+ return /* @__PURE__ */ React3.createElement("div", {
2644
1706
  className: mx2("flex shrink-0 justify-between items-center px-4 py-1 text-sm border-x border-gridLine")
2645
- }, /* @__PURE__ */ React6.createElement("div", {
1707
+ }, /* @__PURE__ */ React3.createElement("div", {
2646
1708
  className: "flex gap-4 items-center"
2647
- }, /* @__PURE__ */ React6.createElement("div", {
1709
+ }, /* @__PURE__ */ React3.createElement("div", {
2648
1710
  className: "flex w-16 items-center font-mono"
2649
- }, range && rangeToA1Notation(range) || cursor && addressToA1Notation(cursor)), /* @__PURE__ */ React6.createElement("div", {
1711
+ }, range && rangeToA1Notation(range) || cursor && addressToA1Notation(cursor)), /* @__PURE__ */ React3.createElement("div", {
2650
1712
  className: "flex gap-2 items-center"
2651
- }, /* @__PURE__ */ React6.createElement(FunctionIcon, {
1713
+ }, /* @__PURE__ */ React3.createElement(FunctionIcon, {
2652
1714
  className: mx2("text-greenText", isFormula ? "visible" : "invisible")
2653
- }), /* @__PURE__ */ React6.createElement("span", {
1715
+ }), /* @__PURE__ */ React3.createElement("span", {
2654
1716
  className: "font-mono"
2655
1717
  }, value))));
2656
1718
  };
2657
1719
  var SheetDebug = () => {
2658
1720
  const { model, cursor, range } = useSheetContext();
2659
- const [, forceUpdate] = useState5({});
2660
- useEffect4(() => {
1721
+ const [, forceUpdate] = useState4({});
1722
+ useEffect3(() => {
2661
1723
  const accessor = createDocAccessor(model.sheet, []);
2662
1724
  const handleUpdate = () => forceUpdate({});
2663
1725
  accessor.handle.addListener("change", handleUpdate);
@@ -2668,9 +1730,9 @@ var SheetDebug = () => {
2668
1730
  }, [
2669
1731
  model
2670
1732
  ]);
2671
- return /* @__PURE__ */ React6.createElement("div", {
1733
+ return /* @__PURE__ */ React3.createElement("div", {
2672
1734
  className: mx2("z-20 absolute right-0 top-20 bottom-20 w-[30rem] overflow-auto scrollbar-thin", "border border-gridLine text-xs bg-neutral-50 dark:bg-black text-cyan-500 font-mono p-1 opacity-80")
2673
- }, /* @__PURE__ */ React6.createElement("pre", {
1735
+ }, /* @__PURE__ */ React3.createElement("pre", {
2674
1736
  className: "whitespace-pre-wrap"
2675
1737
  }, JSON.stringify({
2676
1738
  cursor,
@@ -2692,14 +1754,19 @@ var Sheet = {
2692
1754
  Debug: SheetDebug
2693
1755
  };
2694
1756
 
1757
+ // packages/plugins/plugin-sheet/src/components/SheetContainer.tsx
1758
+ var SheetContainer = ({ sheet, space, role, remoteFunctionUrl }) => {
1759
+ return /* @__PURE__ */ React4.createElement("div", {
1760
+ role: "none",
1761
+ className: mx3("flex", role === "article" && "row-span-2", role === "section" && "aspect-square border-y border-is border-separator")
1762
+ }, /* @__PURE__ */ React4.createElement(Sheet.Root, {
1763
+ sheet,
1764
+ space,
1765
+ remoteFunctionUrl
1766
+ }, /* @__PURE__ */ React4.createElement(Sheet.Main, null)));
1767
+ };
1768
+ var SheetContainer_default = SheetContainer;
2695
1769
  export {
2696
- ComputeGraphContextProvider,
2697
- createSheet,
2698
- addressToIndex,
2699
- compareIndexPositions,
2700
- useComputeGraph,
2701
- useSheetContext,
2702
- Sheet,
2703
- SheetContainer
1770
+ SheetContainer_default as default
2704
1771
  };
2705
- //# sourceMappingURL=chunk-CHQAW4F4.mjs.map
1772
+ //# sourceMappingURL=SheetContainer-U4H5D34A.mjs.map