@dxos/plugin-sheet 0.6.11 → 0.6.12-main.5a87ad5

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 (263) hide show
  1. package/dist/lib/browser/SheetContainer-VISF3VUB.mjs +261 -0
  2. package/dist/lib/browser/SheetContainer-VISF3VUB.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-JRL5LGCE.mjs → chunk-QILRZNE5.mjs} +2 -5
  4. package/dist/lib/browser/chunk-QILRZNE5.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-FUAGSXA4.mjs → chunk-WZMOZKQZ.mjs} +9 -16
  6. package/dist/lib/browser/chunk-WZMOZKQZ.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-D5AGLXJP.mjs → chunk-Z2XOOC2R.mjs} +385 -678
  8. package/dist/lib/browser/chunk-Z2XOOC2R.mjs.map +7 -0
  9. package/dist/lib/browser/{SheetContainer-U4H5D34A.mjs → chunk-ZLJ2GRE2.mjs} +1151 -240
  10. package/dist/lib/browser/chunk-ZLJ2GRE2.mjs.map +7 -0
  11. package/dist/lib/browser/graph-4XFKIHRL.mjs +21 -0
  12. package/dist/lib/browser/graph-4XFKIHRL.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +74 -60
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/meta.mjs +1 -1
  17. package/dist/lib/browser/types.mjs +4 -6
  18. package/dist/lib/node/SheetContainer-2MEALQWW.cjs +279 -0
  19. package/dist/lib/node/SheetContainer-2MEALQWW.cjs.map +7 -0
  20. package/dist/lib/node/{SheetContainer-AXQV3ZT5.cjs → chunk-6DQABRGJ.cjs} +1182 -279
  21. package/dist/lib/node/chunk-6DQABRGJ.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-AOP42UAA.cjs} +13 -21
  23. package/dist/lib/node/chunk-AOP42UAA.cjs.map +7 -0
  24. package/dist/lib/node/{chunk-BJ6ZD7MN.cjs → chunk-BNARJ5GM.cjs} +5 -18
  25. package/dist/lib/node/chunk-BNARJ5GM.cjs.map +7 -0
  26. package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-P5QYYEHQ.cjs} +388 -676
  27. package/dist/lib/node/chunk-P5QYYEHQ.cjs.map +7 -0
  28. package/dist/lib/node/graph-2LRDUXBZ.cjs +43 -0
  29. package/dist/lib/node/graph-2LRDUXBZ.cjs.map +7 -0
  30. package/dist/lib/node/index.cjs +86 -66
  31. package/dist/lib/node/index.cjs.map +3 -3
  32. package/dist/lib/node/meta.cjs +3 -3
  33. package/dist/lib/node/meta.cjs.map +1 -1
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/types.cjs +10 -12
  36. package/dist/lib/node/types.cjs.map +2 -2
  37. package/dist/lib/node-esm/SheetContainer-RPSUSXWS.mjs +262 -0
  38. package/dist/lib/node-esm/SheetContainer-RPSUSXWS.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-4MM7THJW.mjs +2944 -0
  40. package/dist/lib/node-esm/chunk-4MM7THJW.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-5RLTCIE2.mjs +2684 -0
  42. package/dist/lib/node-esm/chunk-5RLTCIE2.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-IU2L277A.mjs +17 -0
  44. package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-RR2AO4SM.mjs +76 -0
  46. package/dist/lib/node-esm/chunk-RR2AO4SM.mjs.map +7 -0
  47. package/dist/lib/node-esm/graph-WG5EKOMO.mjs +22 -0
  48. package/dist/lib/node-esm/graph-WG5EKOMO.mjs.map +7 -0
  49. package/dist/lib/node-esm/index.mjs +263 -0
  50. package/dist/lib/node-esm/index.mjs.map +7 -0
  51. package/dist/lib/node-esm/meta.json +1 -0
  52. package/dist/lib/node-esm/meta.mjs +10 -0
  53. package/dist/lib/node-esm/meta.mjs.map +7 -0
  54. package/dist/lib/node-esm/types.mjs +21 -0
  55. package/dist/lib/node-esm/types.mjs.map +7 -0
  56. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  57. package/dist/types/src/components/CellEditor/CellEditor.d.ts +23 -3
  58. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -1
  59. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts +2 -2
  60. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -1
  61. package/dist/types/src/components/CellEditor/extension.d.ts +1 -1
  62. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
  63. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +11 -0
  64. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -0
  65. package/dist/types/src/components/ComputeGraph/index.d.ts +1 -3
  66. package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
  67. package/dist/types/src/components/GridSheet/GridSheet.d.ts +10 -0
  68. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -0
  69. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +9 -0
  70. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/GridSheet/util.d.ts +7 -0
  72. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
  73. package/dist/types/src/components/Sheet/Sheet.d.ts +1 -1
  74. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
  75. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +5 -6
  76. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  77. package/dist/types/src/components/Sheet/decorations.d.ts +24 -0
  78. package/dist/types/src/components/Sheet/decorations.d.ts.map +1 -0
  79. package/dist/types/src/components/Sheet/grid.d.ts +2 -2
  80. package/dist/types/src/components/Sheet/grid.d.ts.map +1 -1
  81. package/dist/types/src/components/Sheet/nav.d.ts +3 -3
  82. package/dist/types/src/components/Sheet/nav.d.ts.map +1 -1
  83. package/dist/types/src/components/Sheet/sheet-context.d.ts +8 -7
  84. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
  85. package/dist/types/src/components/Sheet/threads.d.ts +2 -0
  86. package/dist/types/src/components/Sheet/threads.d.ts.map +1 -0
  87. package/dist/types/src/components/SheetContainer.d.ts +2 -3
  88. package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
  89. package/dist/types/src/components/Toolbar/Toolbar.d.ts +19 -3
  90. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  91. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +18 -13
  92. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
  93. package/dist/types/src/components/index.d.ts +2 -2
  94. package/dist/types/src/components/index.d.ts.map +1 -1
  95. package/dist/types/src/defs/index.d.ts +3 -0
  96. package/dist/types/src/defs/index.d.ts.map +1 -0
  97. package/dist/types/src/{model → defs}/types.d.ts +8 -3
  98. package/dist/types/src/defs/types.d.ts.map +1 -0
  99. package/dist/types/src/defs/types.test.d.ts.map +1 -0
  100. package/dist/types/src/defs/util.d.ts +43 -0
  101. package/dist/types/src/defs/util.d.ts.map +1 -0
  102. package/dist/types/src/extensions/compute.d.ts +9 -0
  103. package/dist/types/src/extensions/compute.d.ts.map +1 -0
  104. package/dist/types/src/extensions/compute.stories.d.ts +26 -0
  105. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
  106. package/dist/types/src/extensions/index.d.ts +2 -0
  107. package/dist/types/src/extensions/index.d.ts.map +1 -0
  108. package/dist/types/src/{components/ComputeGraph → graph}/async-function.d.ts +8 -2
  109. package/dist/types/src/graph/async-function.d.ts.map +1 -0
  110. package/dist/types/src/graph/compute-graph.d.ts +84 -0
  111. package/dist/types/src/graph/compute-graph.d.ts.map +1 -0
  112. package/dist/types/src/graph/compute-graph.stories.d.ts +10 -0
  113. package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -0
  114. package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
  115. package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
  116. package/dist/types/src/graph/compute-node.d.ts +26 -0
  117. package/dist/types/src/graph/compute-node.d.ts.map +1 -0
  118. package/dist/types/src/graph/edge-function.d.ts.map +1 -0
  119. package/dist/types/src/{model/functions.d.ts → graph/function-defs.d.ts} +1 -1
  120. package/dist/types/src/graph/function-defs.d.ts.map +1 -0
  121. package/dist/types/src/graph/hyperformula.test.d.ts +2 -0
  122. package/dist/types/src/graph/hyperformula.test.d.ts.map +1 -0
  123. package/dist/types/src/graph/index.d.ts +4 -0
  124. package/dist/types/src/graph/index.d.ts.map +1 -0
  125. package/dist/types/src/{components/ComputeGraph/custom.d.ts → graph/testing/custom-function.d.ts} +4 -2
  126. package/dist/types/src/graph/testing/custom-function.d.ts.map +1 -0
  127. package/dist/types/src/graph/testing/index.d.ts +2 -0
  128. package/dist/types/src/graph/testing/index.d.ts.map +1 -0
  129. package/dist/types/src/graph/util.d.ts +2 -0
  130. package/dist/types/src/graph/util.d.ts.map +1 -0
  131. package/dist/types/src/hooks/hooks.stories.d.ts +11 -0
  132. package/dist/types/src/hooks/hooks.stories.d.ts.map +1 -0
  133. package/dist/types/src/hooks/index.d.ts +4 -0
  134. package/dist/types/src/hooks/index.d.ts.map +1 -0
  135. package/dist/types/src/hooks/useComputeGraph.d.ts +7 -0
  136. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -0
  137. package/dist/types/src/hooks/useFormattingModel.d.ts +3 -0
  138. package/dist/types/src/hooks/useFormattingModel.d.ts.map +1 -0
  139. package/dist/types/src/hooks/useSheetModel.d.ts +8 -0
  140. package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -0
  141. package/dist/types/src/meta.d.ts +1 -4
  142. package/dist/types/src/meta.d.ts.map +1 -1
  143. package/dist/types/src/model/formatting-model.d.ts +16 -0
  144. package/dist/types/src/model/formatting-model.d.ts.map +1 -0
  145. package/dist/types/src/model/index.d.ts +2 -3
  146. package/dist/types/src/model/index.d.ts.map +1 -1
  147. package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +10 -65
  148. package/dist/types/src/model/sheet-model.d.ts.map +1 -0
  149. package/dist/types/src/sanity.test.d.ts +2 -0
  150. package/dist/types/src/sanity.test.d.ts.map +1 -0
  151. package/dist/types/src/testing/index.d.ts +2 -0
  152. package/dist/types/src/testing/index.d.ts.map +1 -0
  153. package/dist/types/src/testing/testing.d.ts +8 -0
  154. package/dist/types/src/testing/testing.d.ts.map +1 -0
  155. package/dist/types/src/translations.d.ts +17 -12
  156. package/dist/types/src/translations.d.ts.map +1 -1
  157. package/dist/types/src/types.d.ts +86 -5
  158. package/dist/types/src/types.d.ts.map +1 -1
  159. package/dist/vendor/hyperformula.mjs +37145 -0
  160. package/package.json +48 -41
  161. package/src/SheetPlugin.tsx +48 -73
  162. package/src/components/CellEditor/CellEditor.stories.tsx +5 -4
  163. package/src/components/CellEditor/CellEditor.tsx +59 -9
  164. package/src/components/CellEditor/extension.test.ts +4 -5
  165. package/src/components/CellEditor/extension.ts +1 -3
  166. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +20 -0
  167. package/src/components/ComputeGraph/index.ts +1 -3
  168. package/src/components/GridSheet/GridSheet.stories.tsx +36 -0
  169. package/src/components/GridSheet/GridSheet.tsx +153 -0
  170. package/src/components/GridSheet/util.ts +108 -0
  171. package/src/components/Sheet/Sheet.stories.tsx +52 -88
  172. package/src/components/Sheet/Sheet.tsx +57 -18
  173. package/src/components/Sheet/decorations.ts +62 -0
  174. package/src/components/Sheet/grid.ts +3 -3
  175. package/src/components/Sheet/nav.ts +19 -19
  176. package/src/components/Sheet/sheet-context.tsx +18 -80
  177. package/src/components/Sheet/threads.tsx +205 -0
  178. package/src/components/SheetContainer.tsx +73 -19
  179. package/src/components/Toolbar/Toolbar.tsx +53 -12
  180. package/src/components/index.ts +1 -0
  181. package/src/defs/index.ts +6 -0
  182. package/src/{model → defs}/types.test.ts +8 -9
  183. package/src/{model → defs}/types.ts +24 -14
  184. package/src/defs/util.ts +151 -0
  185. package/src/extensions/compute.stories.tsx +153 -0
  186. package/src/extensions/compute.ts +131 -0
  187. package/src/extensions/index.ts +5 -0
  188. package/src/{components/ComputeGraph → graph}/async-function.ts +15 -6
  189. package/src/graph/compute-graph.stories.tsx +93 -0
  190. package/src/graph/compute-graph.test.ts +127 -0
  191. package/src/graph/compute-graph.ts +313 -0
  192. package/src/graph/compute-node.ts +62 -0
  193. package/src/{components/ComputeGraph → graph}/edge-function.ts +3 -3
  194. package/src/graph/hyperformula.test.ts +15 -0
  195. package/src/graph/index.ts +7 -0
  196. package/src/{components/ComputeGraph/custom.ts → graph/testing/custom-function.ts} +11 -7
  197. package/src/graph/testing/index.ts +5 -0
  198. package/src/graph/util.ts +8 -0
  199. package/src/hooks/hooks.stories.tsx +50 -0
  200. package/src/hooks/index.ts +7 -0
  201. package/src/hooks/useComputeGraph.ts +21 -0
  202. package/src/hooks/useFormattingModel.ts +11 -0
  203. package/src/hooks/useSheetModel.ts +40 -0
  204. package/src/meta.tsx +1 -5
  205. package/src/{components/Sheet/formatting.ts → model/formatting-model.ts} +20 -13
  206. package/src/model/index.ts +2 -3
  207. package/src/model/sheet-model.ts +414 -0
  208. package/src/sanity.test.ts +40 -0
  209. package/src/testing/index.ts +5 -0
  210. package/src/testing/testing.tsx +68 -0
  211. package/src/translations.ts +6 -1
  212. package/src/types.ts +31 -6
  213. package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
  214. package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
  215. package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
  216. package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
  217. package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
  218. package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
  219. package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
  220. package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
  221. package/dist/lib/browser/testing.mjs +0 -92
  222. package/dist/lib/browser/testing.mjs.map +0 -7
  223. package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
  224. package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
  225. package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
  226. package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
  227. package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
  228. package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
  229. package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
  230. package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
  231. package/dist/lib/node/testing.cjs +0 -111
  232. package/dist/lib/node/testing.cjs.map +0 -7
  233. package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
  234. package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
  235. package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
  236. package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
  237. package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
  238. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
  239. package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
  240. package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
  241. package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
  242. package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
  243. package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
  244. package/dist/types/src/model/functions.d.ts.map +0 -1
  245. package/dist/types/src/model/model.browser.test.d.ts +0 -2
  246. package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
  247. package/dist/types/src/model/model.d.ts.map +0 -1
  248. package/dist/types/src/model/types.d.ts.map +0 -1
  249. package/dist/types/src/model/types.test.d.ts.map +0 -1
  250. package/dist/types/src/model/util.d.ts +0 -15
  251. package/dist/types/src/model/util.d.ts.map +0 -1
  252. package/dist/types/src/testing.d.ts +0 -9
  253. package/dist/types/src/testing.d.ts.map +0 -1
  254. package/src/components/ComputeGraph/graph-context.tsx +0 -50
  255. package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
  256. package/src/components/ComputeGraph/graph.ts +0 -62
  257. package/src/model/model.browser.test.ts +0 -100
  258. package/src/model/model.ts +0 -550
  259. package/src/model/util.ts +0 -36
  260. package/src/testing.ts +0 -50
  261. /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
  262. /package/dist/types/src/{components/ComputeGraph → graph}/edge-function.d.ts +0 -0
  263. /package/src/{model/functions.ts → graph/function-defs.ts} +0 -0
@@ -0,0 +1,2684 @@
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ SheetType,
4
+ ValueTypeEnum
5
+ } from "./chunk-RR2AO4SM.mjs";
6
+ import {
7
+ SHEET_PLUGIN
8
+ } from "./chunk-IU2L277A.mjs";
9
+ import {
10
+ createSheetName
11
+ } from "./chunk-4MM7THJW.mjs";
12
+
13
+ // packages/plugins/plugin-sheet/src/components/Sheet/Sheet.tsx
14
+ import { DndContext, DragOverlay, KeyboardSensor, MouseSensor, TouchSensor, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
15
+ import { restrictToHorizontalAxis, restrictToVerticalAxis } from "@dnd-kit/modifiers";
16
+ import { getEventCoordinates, useCombinedRefs } from "@dnd-kit/utilities";
17
+ import { Function as FunctionIcon } from "@phosphor-icons/react";
18
+ import { Resizable } from "re-resizable";
19
+ import React6, { forwardRef, useEffect as useEffect4, useImperativeHandle, useMemo as useMemo4, useRef, useState as useState5 } from "react";
20
+ import { createPortal } from "react-dom";
21
+ import { useResizeDetector } from "react-resize-detector";
22
+ import { debounce as debounce2 } from "@dxos/async";
23
+ import { fullyQualifiedId as fullyQualifiedId2, createDocAccessor } from "@dxos/client/echo";
24
+ import { log as log2 } from "@dxos/log";
25
+ import { createAttendableAttributes, useHasAttention } from "@dxos/react-ui-attention";
26
+ import { mx as mx2 } from "@dxos/react-ui-theme";
27
+
28
+ // packages/plugins/plugin-sheet/src/components/Sheet/grid.ts
29
+ import { useEffect, useState } from "react";
30
+
31
+ // packages/plugins/plugin-sheet/src/defs/types.ts
32
+ import { invariant } from "@dxos/invariant";
33
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/defs/types.ts";
34
+ var DEFAULT_ROWS = 50;
35
+ var DEFAULT_COLUMNS = 26;
36
+ var MAX_ROWS = 500;
37
+ var MAX_COLUMNS = 26 * 2;
38
+ var posEquals = (a, b) => {
39
+ return a?.col === b?.col && a?.row === b?.row;
40
+ };
41
+ var columnLetter = (col) => {
42
+ invariant(col < MAX_COLUMNS, `Invalid column: ${col}`, {
43
+ F: __dxlog_file,
44
+ L: 26,
45
+ S: void 0,
46
+ A: [
47
+ "col < MAX_COLUMNS",
48
+ "`Invalid column: ${col}`"
49
+ ]
50
+ });
51
+ return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
52
+ };
53
+ var addressToA1Notation = ({ col, row }) => {
54
+ return `${columnLetter(col)}${row + 1}`;
55
+ };
56
+ var addressFromA1Notation = (ref) => {
57
+ const match = ref.match(/([A-Z]+)(\d+)/);
58
+ invariant(match, `Invalid notation: ${ref}`, {
59
+ F: __dxlog_file,
60
+ L: 40,
61
+ S: void 0,
62
+ A: [
63
+ "match",
64
+ "`Invalid notation: ${ref}`"
65
+ ]
66
+ });
67
+ return {
68
+ row: parseInt(match[2], 10) - 1,
69
+ col: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
70
+ };
71
+ };
72
+ var rangeToA1Notation = (range) => {
73
+ return [
74
+ range?.from && addressToA1Notation(range?.from),
75
+ range?.to && addressToA1Notation(range?.to)
76
+ ].filter(Boolean).join(":");
77
+ };
78
+ var inRange = (range, cell) => {
79
+ if (!range) {
80
+ return false;
81
+ }
82
+ const { from, to } = range;
83
+ if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
84
+ return true;
85
+ }
86
+ if (!from || !to) {
87
+ return false;
88
+ }
89
+ const { col: c1, row: r1 } = from;
90
+ const { col: c2, row: r2 } = to;
91
+ const cMin = Math.min(c1, c2);
92
+ const cMax = Math.max(c1, c2);
93
+ const rMin = Math.min(r1, r2);
94
+ const rMax = Math.max(r1, r2);
95
+ const { col, row } = cell;
96
+ return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
97
+ };
98
+
99
+ // packages/plugins/plugin-sheet/src/defs/util.ts
100
+ import { randomBytes } from "@dxos/crypto";
101
+ import { create } from "@dxos/echo-schema";
102
+ var ApiError = class extends Error {
103
+ };
104
+ var ReadonlyException = class extends ApiError {
105
+ };
106
+ var RangeException = class extends ApiError {
107
+ constructor(n) {
108
+ super();
109
+ }
110
+ };
111
+ var createIndex = (length = 8) => {
112
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
113
+ const charactersLength = characters.length;
114
+ const randomBuffer = randomBytes(length);
115
+ return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
116
+ };
117
+ var createIndices = (length) => Array.from({
118
+ length
119
+ }).map(() => createIndex());
120
+ var insertIndices = (indices, i, n, max) => {
121
+ if (i + n > max) {
122
+ throw new RangeException(i + n);
123
+ }
124
+ const idx = createIndices(n);
125
+ indices.splice(i, 0, ...idx);
126
+ };
127
+ var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}) => {
128
+ if (!sheet.rows.length) {
129
+ insertIndices(sheet.rows, 0, rows, MAX_ROWS);
130
+ }
131
+ if (!sheet.columns.length) {
132
+ insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
133
+ }
134
+ };
135
+ var createSheet = ({ name, cells, ...size } = {}) => {
136
+ const sheet = create(SheetType, {
137
+ name,
138
+ cells: {},
139
+ rows: [],
140
+ columns: [],
141
+ rowMeta: {},
142
+ columnMeta: {},
143
+ formatting: {}
144
+ });
145
+ initialize(sheet, size);
146
+ if (cells) {
147
+ Object.entries(cells).forEach(([key, { value }]) => {
148
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
149
+ sheet.cells[idx] = {
150
+ value
151
+ };
152
+ });
153
+ }
154
+ return sheet;
155
+ };
156
+ var addressToIndex = (sheet, cell) => {
157
+ return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
158
+ };
159
+ var addressFromIndex = (sheet, idx) => {
160
+ const [column, row] = idx.split("@");
161
+ return {
162
+ col: sheet.columns.indexOf(column),
163
+ row: sheet.rows.indexOf(row)
164
+ };
165
+ };
166
+ var rangeFromIndex = (sheet, idx) => {
167
+ const [from, to] = idx.split(":").map((index) => addressFromIndex(sheet, index));
168
+ return {
169
+ from,
170
+ to
171
+ };
172
+ };
173
+ var closest = (cursor, cells) => {
174
+ let closestCell;
175
+ let closestDistance = Number.MAX_SAFE_INTEGER;
176
+ for (const cell of cells) {
177
+ const distance = Math.abs(cell.row - cursor.row) + Math.abs(cell.col - cursor.col);
178
+ if (distance < closestDistance) {
179
+ closestCell = cell;
180
+ closestDistance = distance;
181
+ }
182
+ }
183
+ return closestCell;
184
+ };
185
+ var compareIndexPositions = (sheet, indexA, indexB) => {
186
+ const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
187
+ const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
188
+ if (rowA !== rowB) {
189
+ return rowA - rowB;
190
+ } else {
191
+ return columnA - columnB;
192
+ }
193
+ };
194
+
195
+ // packages/plugins/plugin-sheet/src/components/Sheet/grid.ts
196
+ var axisWidth = "calc(var(--rail-size)-2px)";
197
+ var axisHeight = 34;
198
+ var minWidth = 40;
199
+ var maxWidth = 800;
200
+ var minHeight = axisHeight;
201
+ var maxHeight = 400;
202
+ var defaultWidth = 200;
203
+ var defaultHeight = minHeight;
204
+ var CELL_DATA_KEY = "cell";
205
+ var useGridLayout = ({ scroller, size, rows, columns, rowSizes, columnSizes }) => {
206
+ const [rowPositions, setRowPositions] = useState([]);
207
+ useEffect(() => {
208
+ if (!rowSizes) {
209
+ return;
210
+ }
211
+ let y = 0;
212
+ setRowPositions(rows.map((idx, i) => {
213
+ const height2 = rowSizes?.[idx] ?? defaultHeight;
214
+ const top = y;
215
+ y += height2 - 1;
216
+ return {
217
+ row: i,
218
+ top,
219
+ height: height2
220
+ };
221
+ }));
222
+ }, [
223
+ rows,
224
+ rowSizes
225
+ ]);
226
+ const [columnPositions, setColumnPositions] = useState([]);
227
+ useEffect(() => {
228
+ if (!columns) {
229
+ return;
230
+ }
231
+ let x = 0;
232
+ setColumnPositions(columns.map((idx, i) => {
233
+ const width2 = columnSizes?.[idx] ?? defaultWidth;
234
+ const left = x;
235
+ x += width2 - 1;
236
+ return {
237
+ col: i,
238
+ left,
239
+ width: width2
240
+ };
241
+ }));
242
+ }, [
243
+ columns,
244
+ columnSizes
245
+ ]);
246
+ const height = rowPositions.length ? rowPositions[rowPositions.length - 1].top + rowPositions[rowPositions.length - 1].height : 0;
247
+ const width = columnPositions.length ? columnPositions[columnPositions.length - 1].left + columnPositions[columnPositions.length - 1].width : 0;
248
+ const [{ rowRange, columnRange }, setWindow] = useState({
249
+ rowRange: [],
250
+ columnRange: []
251
+ });
252
+ useEffect(() => {
253
+ const handleScroll = () => {
254
+ if (!scroller) {
255
+ return;
256
+ }
257
+ const { scrollLeft: left, scrollTop: top, clientWidth: width2, clientHeight: height2 } = scroller;
258
+ let rowStart = 0;
259
+ let rowEnd = 0;
260
+ for (let i = 0; i < rowPositions.length; i++) {
261
+ const row = rowPositions[i];
262
+ if (row.top <= top) {
263
+ rowStart = i;
264
+ }
265
+ if (row.top + row.height >= top + height2) {
266
+ rowEnd = i;
267
+ break;
268
+ }
269
+ }
270
+ let columnStart = 0;
271
+ let columnEnd = 0;
272
+ for (let i = 0; i < columnPositions.length; i++) {
273
+ const column = columnPositions[i];
274
+ if (column.left <= left) {
275
+ columnStart = i;
276
+ }
277
+ if (column.left + column.width >= left + width2) {
278
+ columnEnd = i;
279
+ break;
280
+ }
281
+ }
282
+ const overscan = 5;
283
+ setWindow({
284
+ rowRange: rowPositions.slice(Math.max(0, rowStart - overscan), Math.min(rowPositions.length, rowEnd + overscan)),
285
+ columnRange: columnPositions.slice(Math.max(0, columnStart - overscan), Math.min(columnPositions.length, columnEnd + overscan))
286
+ });
287
+ };
288
+ scroller?.addEventListener("scroll", handleScroll);
289
+ handleScroll();
290
+ return () => {
291
+ scroller?.removeEventListener("scroll", handleScroll);
292
+ };
293
+ }, [
294
+ size.width,
295
+ size.height,
296
+ rowPositions,
297
+ columnPositions
298
+ ]);
299
+ return {
300
+ width,
301
+ height,
302
+ rowRange,
303
+ columnRange
304
+ };
305
+ };
306
+ var getCellAtPointer = (event) => {
307
+ const element = document.elementFromPoint(event.clientX, event.clientY);
308
+ const root = element?.closest(`[data-${CELL_DATA_KEY}]`);
309
+ if (root) {
310
+ const value = root.dataset[CELL_DATA_KEY];
311
+ if (value) {
312
+ return addressFromA1Notation(value);
313
+ }
314
+ }
315
+ };
316
+ var getCellElement = (root, cell) => {
317
+ const pos = addressToA1Notation(cell);
318
+ return root.querySelector(`[data-${CELL_DATA_KEY}="${pos}"]`);
319
+ };
320
+
321
+ // packages/plugins/plugin-sheet/src/components/Sheet/nav.ts
322
+ import { useState as useState2 } from "react";
323
+ var handleNav = (ev, cursor, range, size) => {
324
+ if (cursor && ev.shiftKey) {
325
+ const opposite = range?.to ?? {
326
+ ...cursor
327
+ };
328
+ switch (ev.key) {
329
+ case "ArrowUp": {
330
+ if (opposite.row > 0) {
331
+ opposite.row -= 1;
332
+ }
333
+ break;
334
+ }
335
+ case "ArrowDown": {
336
+ if (opposite.row < size.numRows - 1) {
337
+ opposite.row += 1;
338
+ }
339
+ break;
340
+ }
341
+ case "ArrowLeft": {
342
+ if (opposite.col > 0) {
343
+ opposite.col -= 1;
344
+ }
345
+ break;
346
+ }
347
+ case "ArrowRight": {
348
+ if (opposite.col < size.numCols - 1) {
349
+ opposite.col += 1;
350
+ }
351
+ break;
352
+ }
353
+ }
354
+ return {
355
+ cursor,
356
+ range: {
357
+ from: cursor,
358
+ to: opposite
359
+ }
360
+ };
361
+ }
362
+ const next = handleArrowNav(ev, cursor, size);
363
+ return {
364
+ cursor: next
365
+ };
366
+ };
367
+ var handleArrowNav = (ev, cursor, { numRows, numCols }) => {
368
+ switch (ev.key) {
369
+ case "ArrowUp":
370
+ if (cursor === void 0) {
371
+ return {
372
+ row: 0,
373
+ col: 0
374
+ };
375
+ } else if (cursor.row > 0) {
376
+ return {
377
+ row: ev.metaKey ? 0 : cursor.row - 1,
378
+ col: cursor.col
379
+ };
380
+ }
381
+ break;
382
+ case "ArrowDown":
383
+ if (cursor === void 0) {
384
+ return {
385
+ row: 0,
386
+ col: 0
387
+ };
388
+ } else if (cursor.row < numRows - 1) {
389
+ return {
390
+ row: ev.metaKey ? numRows - 1 : cursor.row + 1,
391
+ col: cursor.col
392
+ };
393
+ }
394
+ break;
395
+ case "ArrowLeft":
396
+ if (cursor === void 0) {
397
+ return {
398
+ row: 0,
399
+ col: 0
400
+ };
401
+ } else if (cursor.col > 0) {
402
+ return {
403
+ row: cursor.row,
404
+ col: ev.metaKey ? 0 : cursor.col - 1
405
+ };
406
+ }
407
+ break;
408
+ case "ArrowRight":
409
+ if (cursor === void 0) {
410
+ return {
411
+ row: 0,
412
+ col: 0
413
+ };
414
+ } else if (cursor.col < numCols - 1) {
415
+ return {
416
+ row: cursor.row,
417
+ col: ev.metaKey ? numCols - 1 : cursor.col + 1
418
+ };
419
+ }
420
+ break;
421
+ case "Home":
422
+ return {
423
+ row: 0,
424
+ col: 0
425
+ };
426
+ case "End":
427
+ return {
428
+ row: numRows - 1,
429
+ col: numCols - 1
430
+ };
431
+ }
432
+ };
433
+ var useRangeSelect = (cb) => {
434
+ const [from, setFrom] = useState2();
435
+ const [to, setTo] = useState2();
436
+ const onMouseDown = (ev) => {
437
+ const current = getCellAtPointer(ev);
438
+ setFrom(current);
439
+ if (current) {
440
+ setTimeout(() => cb("start", {
441
+ from: current
442
+ }));
443
+ }
444
+ };
445
+ const onMouseMove = (ev) => {
446
+ if (from) {
447
+ let current = getCellAtPointer(ev);
448
+ if (posEquals(current, from)) {
449
+ current = void 0;
450
+ }
451
+ setTo(current);
452
+ setTimeout(() => cb("move", {
453
+ from,
454
+ to: current
455
+ }));
456
+ }
457
+ };
458
+ const onMouseUp = (ev) => {
459
+ if (from) {
460
+ let current = getCellAtPointer(ev);
461
+ if (posEquals(current, from)) {
462
+ current = void 0;
463
+ }
464
+ setFrom(void 0);
465
+ setTo(void 0);
466
+ setTimeout(() => cb("end", current ? {
467
+ from,
468
+ to: current
469
+ } : void 0));
470
+ }
471
+ };
472
+ return {
473
+ range: from ? {
474
+ from,
475
+ to
476
+ } : void 0,
477
+ handlers: {
478
+ onMouseDown,
479
+ onMouseMove,
480
+ onMouseUp
481
+ }
482
+ };
483
+ };
484
+
485
+ // packages/plugins/plugin-sheet/src/components/Sheet/sheet-context.tsx
486
+ import React3, { createContext as createContext2, useContext as useContext2, useMemo as useMemo2, useState as useState4 } from "react";
487
+ import { invariant as invariant3 } from "@dxos/invariant";
488
+
489
+ // packages/plugins/plugin-sheet/src/components/Sheet/decorations.ts
490
+ import { create as create2 } from "@dxos/echo-schema";
491
+ var createDecorations = () => {
492
+ const { decorations } = create2({
493
+ decorations: {}
494
+ });
495
+ const addDecoration = (cellIndex, decorator) => {
496
+ decorations[cellIndex] = [
497
+ ...decorations[cellIndex] || [],
498
+ decorator
499
+ ];
500
+ };
501
+ const removeDecoration = (cellIndex, type) => {
502
+ if (type) {
503
+ decorations[cellIndex] = (decorations[cellIndex] || []).filter((d) => d.type !== type);
504
+ } else {
505
+ delete decorations[cellIndex];
506
+ }
507
+ };
508
+ const getDecorationsForCell = (cellIndex) => {
509
+ return decorations[cellIndex];
510
+ };
511
+ const getAllDecorations = () => {
512
+ const result = [];
513
+ for (const decoratorArray of Object.values(decorations)) {
514
+ for (const decorator of decoratorArray) {
515
+ result.push(decorator);
516
+ }
517
+ }
518
+ return result;
519
+ };
520
+ return {
521
+ addDecoration,
522
+ removeDecoration,
523
+ getDecorationsForCell,
524
+ getAllDecorations
525
+ };
526
+ };
527
+
528
+ // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
529
+ import { useContext } from "react";
530
+ import { raise } from "@dxos/debug";
531
+ import { useAsyncState } from "@dxos/react-hooks";
532
+
533
+ // packages/plugins/plugin-sheet/src/components/index.ts
534
+ import React2 from "react";
535
+
536
+ // packages/plugins/plugin-sheet/src/components/ComputeGraph/ComputeGraphContextProvider.tsx
537
+ import React, { createContext } from "react";
538
+ var ComputeGraphContext = /* @__PURE__ */ createContext(void 0);
539
+ var ComputeGraphContextProvider = ({ registry, children }) => {
540
+ return /* @__PURE__ */ React.createElement(ComputeGraphContext.Provider, {
541
+ value: {
542
+ registry
543
+ }
544
+ }, children);
545
+ };
546
+
547
+ // packages/plugins/plugin-sheet/src/components/index.ts
548
+ var SheetContainer = React2.lazy(() => import("./SheetContainer-RPSUSXWS.mjs"));
549
+
550
+ // packages/plugins/plugin-sheet/src/hooks/useComputeGraph.ts
551
+ var useComputeGraph = (space) => {
552
+ const { registry } = useContext(ComputeGraphContext) ?? raise(new Error("Missing ComputeGraphContext"));
553
+ const [graph] = useAsyncState(async () => space && registry.getOrCreateGraph(space), [
554
+ space,
555
+ registry
556
+ ]);
557
+ return graph;
558
+ };
559
+
560
+ // packages/plugins/plugin-sheet/src/hooks/useFormattingModel.ts
561
+ import { useMemo } from "react";
562
+
563
+ // packages/plugins/plugin-sheet/src/model/formatting-model.ts
564
+ var FormattingModel = class {
565
+ constructor(_model) {
566
+ this._model = _model;
567
+ }
568
+ /**
569
+ * Get formatted string value and className for cell.
570
+ */
571
+ getFormatting(cell) {
572
+ const value = this._model.getValue(cell);
573
+ if (value === void 0 || value === null) {
574
+ return {};
575
+ }
576
+ const locales = void 0;
577
+ const idx = addressToIndex(this._model.sheet, cell);
578
+ let formatting = this._model.sheet.formatting?.[idx] ?? {};
579
+ const classNames = [
580
+ ...formatting?.classNames ?? []
581
+ ];
582
+ for (const [idx2, _formatting] of Object.entries(this._model.sheet.formatting)) {
583
+ const range = rangeFromIndex(this._model.sheet, idx2);
584
+ if (inRange(range, cell)) {
585
+ if (_formatting.classNames) {
586
+ classNames.push(..._formatting.classNames);
587
+ }
588
+ if (_formatting.type) {
589
+ formatting = _formatting;
590
+ }
591
+ }
592
+ }
593
+ const defaultNumber = "justify-end font-mono";
594
+ const type = formatting?.type ?? this._model.getValueType(cell);
595
+ switch (type) {
596
+ case ValueTypeEnum.Boolean: {
597
+ return {
598
+ value: value.toLocaleString().toUpperCase(),
599
+ classNames: [
600
+ ...classNames,
601
+ value ? "!text-greenText" : "!text-orangeText"
602
+ ]
603
+ };
604
+ }
605
+ //
606
+ // Numbers.
607
+ //
608
+ case ValueTypeEnum.Number: {
609
+ return {
610
+ value: value.toLocaleString(locales),
611
+ classNames: [
612
+ ...classNames,
613
+ defaultNumber
614
+ ]
615
+ };
616
+ }
617
+ case ValueTypeEnum.Percent: {
618
+ return {
619
+ value: value * 100 + "%",
620
+ classNames: [
621
+ ...classNames,
622
+ defaultNumber
623
+ ]
624
+ };
625
+ }
626
+ case ValueTypeEnum.Currency: {
627
+ return {
628
+ value: value.toLocaleString(locales, {
629
+ style: "currency",
630
+ currency: "USD",
631
+ minimumFractionDigits: 2,
632
+ maximumFractionDigits: 2
633
+ }),
634
+ classNames: [
635
+ ...classNames,
636
+ defaultNumber
637
+ ]
638
+ };
639
+ }
640
+ //
641
+ // Dates.
642
+ //
643
+ case ValueTypeEnum.DateTime: {
644
+ const date = this._model.toLocalDate(value);
645
+ return {
646
+ value: date.toLocaleString(locales),
647
+ classNames
648
+ };
649
+ }
650
+ case ValueTypeEnum.Date: {
651
+ const date = this._model.toLocalDate(value);
652
+ return {
653
+ value: date.toLocaleDateString(locales),
654
+ classNames
655
+ };
656
+ }
657
+ case ValueTypeEnum.Time: {
658
+ const date = this._model.toLocalDate(value);
659
+ return {
660
+ value: date.toLocaleTimeString(locales),
661
+ classNames
662
+ };
663
+ }
664
+ default: {
665
+ return {
666
+ value: String(value),
667
+ classNames
668
+ };
669
+ }
670
+ }
671
+ }
672
+ };
673
+
674
+ // packages/plugins/plugin-sheet/src/model/sheet-model.ts
675
+ import { Event } from "@dxos/async";
676
+ import { Resource } from "@dxos/context";
677
+ import { invariant as invariant2 } from "@dxos/invariant";
678
+ import { PublicKey } from "@dxos/keys";
679
+ import { log } from "@dxos/log";
680
+ import { DetailedCellError, ExportedCellChange } from "#hyperformula";
681
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
682
+ var typeMap = {
683
+ BOOLEAN: ValueTypeEnum.Boolean,
684
+ NUMBER_RAW: ValueTypeEnum.Number,
685
+ NUMBER_PERCENT: ValueTypeEnum.Percent,
686
+ NUMBER_CURRENCY: ValueTypeEnum.Currency,
687
+ NUMBER_DATETIME: ValueTypeEnum.DateTime,
688
+ NUMBER_DATE: ValueTypeEnum.Date,
689
+ NUMBER_TIME: ValueTypeEnum.Time
690
+ };
691
+ var getTopLeft = (range) => {
692
+ const to = range.to ?? range.from;
693
+ return {
694
+ row: Math.min(range.from.row, to.row),
695
+ col: Math.min(range.from.col, to.col)
696
+ };
697
+ };
698
+ var toSimpleCellAddress = (sheet, cell) => ({
699
+ sheet,
700
+ row: cell.row,
701
+ col: cell.col
702
+ });
703
+ var toModelRange = (sheet, range) => ({
704
+ start: toSimpleCellAddress(sheet, range.from),
705
+ end: toSimpleCellAddress(sheet, range.to ?? range.from)
706
+ });
707
+ var SheetModel = class extends Resource {
708
+ constructor(_graph, _sheet, _options = {}) {
709
+ super();
710
+ this._graph = _graph;
711
+ this._sheet = _sheet;
712
+ this._options = _options;
713
+ this.id = `model-${PublicKey.random().truncate()}`;
714
+ this.update = new Event();
715
+ }
716
+ get graph() {
717
+ return this._graph;
718
+ }
719
+ get sheet() {
720
+ return this._sheet;
721
+ }
722
+ get readonly() {
723
+ return this._options.readonly;
724
+ }
725
+ get bounds() {
726
+ return {
727
+ rows: this._sheet.rows.length,
728
+ columns: this._sheet.columns.length
729
+ };
730
+ }
731
+ /**
732
+ * Initialize sheet and engine.
733
+ */
734
+ async _open() {
735
+ log("initialize", {
736
+ id: this.id
737
+ }, {
738
+ F: __dxlog_file2,
739
+ L: 103,
740
+ S: this,
741
+ C: (f, a) => f(...a)
742
+ });
743
+ initialize(this._sheet);
744
+ this._node = await this._graph.getOrCreateNode(createSheetName(this._sheet.id));
745
+ const unsubscribe = this._node.update.on((event) => this.update.emit(event));
746
+ this._ctx.onDispose(unsubscribe);
747
+ this.reset();
748
+ }
749
+ /**
750
+ * Update engine.
751
+ * NOTE: This resets the undo history.
752
+ * @deprecated
753
+ */
754
+ reset() {
755
+ invariant2(this._node, void 0, {
756
+ F: __dxlog_file2,
757
+ L: 122,
758
+ S: this,
759
+ A: [
760
+ "this._node",
761
+ ""
762
+ ]
763
+ });
764
+ this._node.graph.hf.clearSheet(this._node.sheetId);
765
+ Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
766
+ invariant2(this._node, void 0, {
767
+ F: __dxlog_file2,
768
+ L: 125,
769
+ S: this,
770
+ A: [
771
+ "this._node",
772
+ ""
773
+ ]
774
+ });
775
+ const { col, row } = addressFromIndex(this._sheet, key);
776
+ if (typeof value === "string" && value.charAt(0) === "=") {
777
+ value = this._graph.mapFormulaToNative(this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value)));
778
+ }
779
+ this._node.graph.hf.setCellContents({
780
+ sheet: this._node.sheetId,
781
+ row,
782
+ col
783
+ }, value);
784
+ });
785
+ }
786
+ /**
787
+ * Recalculate formulas.
788
+ * NOTE: This resets the undo history.
789
+ * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
790
+ * @deprecated
791
+ */
792
+ // TODO(burdon): Remove.
793
+ recalculate() {
794
+ this._node?.graph.hf.rebuildAndRecalculate();
795
+ }
796
+ insertRows(i, n = 1) {
797
+ insertIndices(this._sheet.rows, i, n, MAX_ROWS);
798
+ this.reset();
799
+ }
800
+ insertColumns(i, n = 1) {
801
+ insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
802
+ this.reset();
803
+ }
804
+ //
805
+ // Undoable actions.
806
+ // TODO(burdon): Group undoable methods; consistently update hf/sheet.
807
+ //
808
+ /**
809
+ * Clear range of values.
810
+ */
811
+ clear(range) {
812
+ invariant2(this._node, void 0, {
813
+ F: __dxlog_file2,
814
+ L: 167,
815
+ S: this,
816
+ A: [
817
+ "this._node",
818
+ ""
819
+ ]
820
+ });
821
+ const topLeft = getTopLeft(range);
822
+ const values = this._iterRange(range, () => null);
823
+ this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
824
+ this._iterRange(range, (cell) => {
825
+ const idx = addressToIndex(this._sheet, cell);
826
+ delete this._sheet.cells[idx];
827
+ });
828
+ }
829
+ cut(range) {
830
+ invariant2(this._node, void 0, {
831
+ F: __dxlog_file2,
832
+ L: 178,
833
+ S: this,
834
+ A: [
835
+ "this._node",
836
+ ""
837
+ ]
838
+ });
839
+ this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
840
+ this._iterRange(range, (cell) => {
841
+ const idx = addressToIndex(this._sheet, cell);
842
+ delete this._sheet.cells[idx];
843
+ });
844
+ }
845
+ copy(range) {
846
+ invariant2(this._node, void 0, {
847
+ F: __dxlog_file2,
848
+ L: 187,
849
+ S: this,
850
+ A: [
851
+ "this._node",
852
+ ""
853
+ ]
854
+ });
855
+ this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
856
+ }
857
+ paste(cell) {
858
+ invariant2(this._node, void 0, {
859
+ F: __dxlog_file2,
860
+ L: 192,
861
+ S: this,
862
+ A: [
863
+ "this._node",
864
+ ""
865
+ ]
866
+ });
867
+ if (!this._node.graph.hf.isClipboardEmpty()) {
868
+ const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
869
+ for (const change of changes) {
870
+ if (change instanceof ExportedCellChange) {
871
+ const { address, newValue } = change;
872
+ const idx = addressToIndex(this._sheet, {
873
+ row: address.row,
874
+ col: address.col
875
+ });
876
+ this._sheet.cells[idx] = {
877
+ value: newValue
878
+ };
879
+ }
880
+ }
881
+ }
882
+ }
883
+ // TODO(burdon): Display undo/redo state.
884
+ undo() {
885
+ invariant2(this._node, void 0, {
886
+ F: __dxlog_file2,
887
+ L: 207,
888
+ S: this,
889
+ A: [
890
+ "this._node",
891
+ ""
892
+ ]
893
+ });
894
+ if (this._node.graph.hf.isThereSomethingToUndo()) {
895
+ this._node.graph.hf.undo();
896
+ }
897
+ }
898
+ redo() {
899
+ invariant2(this._node, void 0, {
900
+ F: __dxlog_file2,
901
+ L: 215,
902
+ S: this,
903
+ A: [
904
+ "this._node",
905
+ ""
906
+ ]
907
+ });
908
+ if (this._node.graph.hf.isThereSomethingToRedo()) {
909
+ this._node.graph.hf.redo();
910
+ }
911
+ }
912
+ /**
913
+ * Get value from sheet.
914
+ */
915
+ getCellValue(cell) {
916
+ const idx = addressToIndex(this._sheet, cell);
917
+ return this._sheet.cells[idx]?.value ?? null;
918
+ }
919
+ /**
920
+ * Get value as a string for editing.
921
+ */
922
+ getCellText(cell) {
923
+ const value = this.getCellValue(cell);
924
+ if (value == null) {
925
+ return void 0;
926
+ }
927
+ if (typeof value === "string" && value.charAt(0) === "=") {
928
+ return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
929
+ } else {
930
+ return String(value);
931
+ }
932
+ }
933
+ /**
934
+ * Get array of raw values from sheet.
935
+ */
936
+ getCellValues(range) {
937
+ return this._iterRange(range, (cell) => this.getCellValue(cell));
938
+ }
939
+ /**
940
+ * Gets the regular or computed value from the engine.
941
+ */
942
+ getValue(cell) {
943
+ invariant2(this._node, void 0, {
944
+ F: __dxlog_file2,
945
+ L: 258,
946
+ S: this,
947
+ A: [
948
+ "this._node",
949
+ ""
950
+ ]
951
+ });
952
+ const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
953
+ if (value instanceof DetailedCellError) {
954
+ return value.toString();
955
+ }
956
+ return value;
957
+ }
958
+ /**
959
+ * Get value type.
960
+ */
961
+ getValueType(cell) {
962
+ invariant2(this._node, void 0, {
963
+ F: __dxlog_file2,
964
+ L: 271,
965
+ S: this,
966
+ A: [
967
+ "this._node",
968
+ ""
969
+ ]
970
+ });
971
+ const addr = toSimpleCellAddress(this._node.sheetId, cell);
972
+ const type = this._node.graph.hf.getCellValueDetailedType(addr);
973
+ return typeMap[type];
974
+ }
975
+ /**
976
+ * Sets the value, updating the sheet and engine.
977
+ */
978
+ setValue(cell, value) {
979
+ invariant2(this._node, void 0, {
980
+ F: __dxlog_file2,
981
+ L: 281,
982
+ S: this,
983
+ A: [
984
+ "this._node",
985
+ ""
986
+ ]
987
+ });
988
+ if (this._options.readonly) {
989
+ throw new ReadonlyException();
990
+ }
991
+ let refresh = false;
992
+ if (cell.row >= this._sheet.rows.length) {
993
+ insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
994
+ refresh = true;
995
+ }
996
+ if (cell.col >= this._sheet.columns.length) {
997
+ insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
998
+ refresh = true;
999
+ }
1000
+ if (refresh) {
1001
+ this.reset();
1002
+ }
1003
+ this._node.graph.hf.setCellContents({
1004
+ sheet: this._node.sheetId,
1005
+ row: cell.row,
1006
+ col: cell.col
1007
+ }, [
1008
+ [
1009
+ typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value
1010
+ ]
1011
+ ]);
1012
+ const idx = addressToIndex(this._sheet, cell);
1013
+ if (value === void 0 || value === null) {
1014
+ delete this._sheet.cells[idx];
1015
+ } else {
1016
+ if (typeof value === "string" && value.charAt(0) === "=") {
1017
+ value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
1018
+ }
1019
+ this._sheet.cells[idx] = {
1020
+ value
1021
+ };
1022
+ }
1023
+ }
1024
+ /**
1025
+ * Sets values from a simple map.
1026
+ */
1027
+ setValues(values) {
1028
+ Object.entries(values).forEach(([key, { value }]) => {
1029
+ this.setValue(addressFromA1Notation(key), value);
1030
+ });
1031
+ }
1032
+ /**
1033
+ * Iterate range.
1034
+ */
1035
+ _iterRange(range, cb) {
1036
+ const to = range.to ?? range.from;
1037
+ const rowRange = [
1038
+ Math.min(range.from.row, to.row),
1039
+ Math.max(range.from.row, to.row)
1040
+ ];
1041
+ const columnRange = [
1042
+ Math.min(range.from.col, to.col),
1043
+ Math.max(range.from.col, to.col)
1044
+ ];
1045
+ const rows = [];
1046
+ for (let row = rowRange[0]; row <= rowRange[1]; row++) {
1047
+ const rowCells = [];
1048
+ for (let column = columnRange[0]; column <= columnRange[1]; column++) {
1049
+ const value = cb({
1050
+ row,
1051
+ col: column
1052
+ });
1053
+ if (value !== void 0) {
1054
+ rowCells.push(value);
1055
+ }
1056
+ }
1057
+ rows.push(rowCells);
1058
+ }
1059
+ return rows;
1060
+ }
1061
+ // TODO(burdon): Delete index.
1062
+ _deleteIndices(indices, i, n) {
1063
+ throw new Error("Not implemented");
1064
+ }
1065
+ // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
1066
+ _moveIndices(indices, i, j, n) {
1067
+ throw new Error("Not implemented");
1068
+ }
1069
+ //
1070
+ // Indices.
1071
+ //
1072
+ /**
1073
+ * Map from A1 notation to indices.
1074
+ */
1075
+ mapFormulaRefsToIndices(formula) {
1076
+ invariant2(formula.charAt(0) === "=", void 0, {
1077
+ F: __dxlog_file2,
1078
+ L: 370,
1079
+ S: this,
1080
+ A: [
1081
+ "formula.charAt(0) === '='",
1082
+ ""
1083
+ ]
1084
+ });
1085
+ return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
1086
+ return addressToIndex(this._sheet, addressFromA1Notation(match));
1087
+ });
1088
+ }
1089
+ /**
1090
+ * Map from indices to A1 notation.
1091
+ */
1092
+ mapFormulaIndicesToRefs(formula) {
1093
+ invariant2(formula.charAt(0) === "=", void 0, {
1094
+ F: __dxlog_file2,
1095
+ L: 380,
1096
+ S: this,
1097
+ A: [
1098
+ "formula.charAt(0) === '='",
1099
+ ""
1100
+ ]
1101
+ });
1102
+ return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
1103
+ return addressToA1Notation(addressFromIndex(this._sheet, idx));
1104
+ });
1105
+ }
1106
+ //
1107
+ // Values
1108
+ //
1109
+ /**
1110
+ * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
1111
+ * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
1112
+ * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
1113
+ */
1114
+ toLocalDate(num) {
1115
+ const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
1116
+ return new Date(year, month - 1, day, hours, minutes, seconds);
1117
+ }
1118
+ toDateTime(num) {
1119
+ invariant2(this._node, void 0, {
1120
+ F: __dxlog_file2,
1121
+ L: 401,
1122
+ S: this,
1123
+ A: [
1124
+ "this._node",
1125
+ ""
1126
+ ]
1127
+ });
1128
+ return this._node.graph.hf.numberToDateTime(num);
1129
+ }
1130
+ toDate(num) {
1131
+ invariant2(this._node, void 0, {
1132
+ F: __dxlog_file2,
1133
+ L: 406,
1134
+ S: this,
1135
+ A: [
1136
+ "this._node",
1137
+ ""
1138
+ ]
1139
+ });
1140
+ return this._node.graph.hf.numberToDate(num);
1141
+ }
1142
+ toTime(num) {
1143
+ invariant2(this._node, void 0, {
1144
+ F: __dxlog_file2,
1145
+ L: 411,
1146
+ S: this,
1147
+ A: [
1148
+ "this._node",
1149
+ ""
1150
+ ]
1151
+ });
1152
+ return this._node.graph.hf.numberToTime(num);
1153
+ }
1154
+ };
1155
+
1156
+ // packages/plugins/plugin-sheet/src/hooks/useFormattingModel.ts
1157
+ var useFormattingModel = (model) => {
1158
+ return useMemo(() => model && new FormattingModel(model), [
1159
+ model
1160
+ ]);
1161
+ };
1162
+
1163
+ // packages/plugins/plugin-sheet/src/hooks/useSheetModel.ts
1164
+ import { useEffect as useEffect2, useState as useState3 } from "react";
1165
+ var useSheetModel = (graph, sheet, { readonly } = {}) => {
1166
+ const [model, setModel] = useState3();
1167
+ useEffect2(() => {
1168
+ if (!graph || !sheet) {
1169
+ return;
1170
+ }
1171
+ let model2;
1172
+ const t = setTimeout(async () => {
1173
+ model2 = new SheetModel(graph, sheet, {
1174
+ readonly
1175
+ });
1176
+ await model2.open();
1177
+ setModel(model2);
1178
+ });
1179
+ return () => {
1180
+ clearTimeout(t);
1181
+ void model2?.close();
1182
+ };
1183
+ }, [
1184
+ graph,
1185
+ sheet,
1186
+ readonly
1187
+ ]);
1188
+ return model;
1189
+ };
1190
+
1191
+ // packages/plugins/plugin-sheet/src/components/Sheet/sheet-context.tsx
1192
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/Sheet/sheet-context.tsx";
1193
+ var SheetContext = /* @__PURE__ */ createContext2(null);
1194
+ var useSheetContext = () => {
1195
+ const context = useContext2(SheetContext);
1196
+ invariant3(context, void 0, {
1197
+ F: __dxlog_file3,
1198
+ L: 43,
1199
+ S: void 0,
1200
+ A: [
1201
+ "context",
1202
+ ""
1203
+ ]
1204
+ });
1205
+ return context;
1206
+ };
1207
+ var SheetContextProvider = ({ children, graph, sheet, readonly, onInfo }) => {
1208
+ const model = useSheetModel(graph, sheet, {
1209
+ readonly
1210
+ });
1211
+ const formatting = useFormattingModel(model);
1212
+ const [cursor, setCursor] = useState4();
1213
+ const [range, setRange] = useState4();
1214
+ const [editing, setEditing] = useState4(false);
1215
+ const decorations = useMemo2(() => createDecorations(), []);
1216
+ return !model || !formatting ? null : /* @__PURE__ */ React3.createElement(SheetContext.Provider, {
1217
+ value: {
1218
+ model,
1219
+ formatting,
1220
+ cursor,
1221
+ setCursor,
1222
+ range,
1223
+ setRange,
1224
+ editing,
1225
+ setEditing,
1226
+ // TODO(burdon): Change to event.
1227
+ onInfo,
1228
+ decorations
1229
+ }
1230
+ }, children);
1231
+ };
1232
+
1233
+ // packages/plugins/plugin-sheet/src/components/Sheet/threads.tsx
1234
+ import { effect } from "@preact/signals-core";
1235
+ import React4, { useCallback, useEffect as useEffect3, useMemo as useMemo3 } from "react";
1236
+ import { LayoutAction, useIntentDispatcher, useIntentResolver } from "@dxos/app-framework";
1237
+ import { debounce } from "@dxos/async";
1238
+ import { fullyQualifiedId } from "@dxos/react-client/echo";
1239
+ import { Icon, useTranslation } from "@dxos/react-ui";
1240
+ var CommentIndicator = () => {
1241
+ return /* @__PURE__ */ React4.createElement("div", {
1242
+ role: "none",
1243
+ className: "absolute top-0 right-0 w-0 h-0 border-t-8 border-l-8 border-t-cmCommentSurface border-l-transparent"
1244
+ });
1245
+ };
1246
+ var ThreadedCellWrapper = ({ children }) => {
1247
+ const dispatch = useIntentDispatcher();
1248
+ const [isHovered, setIsHovered] = React4.useState(false);
1249
+ const { t } = useTranslation(SHEET_PLUGIN);
1250
+ const handleClick = React4.useCallback((_event) => {
1251
+ void dispatch({
1252
+ action: LayoutAction.SET_LAYOUT,
1253
+ data: {
1254
+ element: "complementary",
1255
+ state: true
1256
+ }
1257
+ });
1258
+ }, [
1259
+ dispatch
1260
+ ]);
1261
+ return /* @__PURE__ */ React4.createElement("div", {
1262
+ role: "none",
1263
+ className: "relative h-full is-full",
1264
+ onMouseEnter: () => {
1265
+ setIsHovered(true);
1266
+ },
1267
+ onMouseLeave: () => {
1268
+ setIsHovered(false);
1269
+ }
1270
+ }, /* @__PURE__ */ React4.createElement(CommentIndicator, null), isHovered && /* @__PURE__ */ React4.createElement("div", {
1271
+ className: "absolute inset-0 flex items-center justify-end pr-1"
1272
+ }, /* @__PURE__ */ React4.createElement("button", {
1273
+ className: "ch-button text-xs min-bs-0 p-1",
1274
+ onClick: handleClick,
1275
+ "aria-label": t("open comment for sheet cell")
1276
+ }, /* @__PURE__ */ React4.createElement(Icon, {
1277
+ icon: "ph--chat--regular",
1278
+ "aria-hidden": true
1279
+ }))), children);
1280
+ };
1281
+ var createThreadDecoration = (cellIndex, threadId, sheetId) => {
1282
+ return {
1283
+ type: "comment",
1284
+ cellIndex,
1285
+ decorate: (props) => /* @__PURE__ */ React4.createElement(ThreadedCellWrapper, props)
1286
+ };
1287
+ };
1288
+ var useUpdateCursorOnThreadSelection = () => {
1289
+ const { setCursor, model } = useSheetContext();
1290
+ const handleScrollIntoView = useCallback(({ action, data }) => {
1291
+ switch (action) {
1292
+ case LayoutAction.SCROLL_INTO_VIEW: {
1293
+ if (!data?.id || data?.cursor === void 0 || data?.id !== fullyQualifiedId(model.sheet)) {
1294
+ return;
1295
+ }
1296
+ const cellAddress = addressFromIndex(model.sheet, data.cursor);
1297
+ setCursor(cellAddress);
1298
+ }
1299
+ }
1300
+ }, [
1301
+ model.sheet,
1302
+ setCursor
1303
+ ]);
1304
+ useIntentResolver(SHEET_PLUGIN, handleScrollIntoView);
1305
+ };
1306
+ var useSelectThreadOnCursorChange = () => {
1307
+ const { cursor, model } = useSheetContext();
1308
+ const dispatch = useIntentDispatcher();
1309
+ const activeThreads = useMemo3(() => model.sheet.threads?.filter((thread) => !!thread && thread.status === "active") ?? [], [
1310
+ JSON.stringify(model.sheet.threads)
1311
+ ]);
1312
+ const activeThreadAddresses = useMemo3(() => activeThreads.map((thread) => thread.anchor).filter((anchor) => anchor !== void 0).map((anchor) => addressFromIndex(model.sheet, anchor)), [
1313
+ activeThreads,
1314
+ model.sheet
1315
+ ]);
1316
+ const selectClosestThread = useCallback((cellAddress) => {
1317
+ if (!cellAddress || !activeThreads) {
1318
+ return;
1319
+ }
1320
+ const closestThreadAnchor = closest(cellAddress, activeThreadAddresses);
1321
+ if (closestThreadAnchor) {
1322
+ const closestThread = activeThreads.find((thread) => thread && thread.anchor === addressToIndex(model.sheet, closestThreadAnchor));
1323
+ if (closestThread) {
1324
+ void dispatch([
1325
+ {
1326
+ action: "dxos.org/plugin/thread/action/select",
1327
+ data: {
1328
+ current: fullyQualifiedId(closestThread)
1329
+ }
1330
+ }
1331
+ ]);
1332
+ }
1333
+ }
1334
+ }, [
1335
+ dispatch,
1336
+ activeThreads,
1337
+ activeThreadAddresses,
1338
+ model.sheet
1339
+ ]);
1340
+ const debounced = useMemo3(() => {
1341
+ return debounce((cursor2) => requestAnimationFrame(() => selectClosestThread(cursor2)), 50);
1342
+ }, [
1343
+ selectClosestThread
1344
+ ]);
1345
+ useEffect3(() => {
1346
+ if (!cursor) {
1347
+ return;
1348
+ }
1349
+ debounced(cursor);
1350
+ }, [
1351
+ cursor,
1352
+ selectClosestThread
1353
+ ]);
1354
+ };
1355
+ var useThreadDecorations = () => {
1356
+ const { decorations, model } = useSheetContext();
1357
+ const sheet = useMemo3(() => model.sheet, [
1358
+ model.sheet
1359
+ ]);
1360
+ const sheetId = useMemo3(() => fullyQualifiedId(sheet), [
1361
+ sheet
1362
+ ]);
1363
+ useEffect3(() => {
1364
+ const unsubscribe = effect(() => {
1365
+ const activeThreadAnchors = /* @__PURE__ */ new Set();
1366
+ if (!sheet.threads) {
1367
+ return;
1368
+ }
1369
+ for (const thread of sheet.threads) {
1370
+ if (!thread || thread.anchor === void 0 || thread.status === "resolved") {
1371
+ continue;
1372
+ }
1373
+ activeThreadAnchors.add(thread.anchor);
1374
+ const index = thread.anchor;
1375
+ const existingDecorations = decorations.getDecorationsForCell(index);
1376
+ if (!existingDecorations || !existingDecorations.some((d) => d.type === "comment")) {
1377
+ decorations.addDecoration(index, createThreadDecoration(index, thread.id, sheetId));
1378
+ }
1379
+ }
1380
+ for (const decoration of decorations.getAllDecorations()) {
1381
+ if (decoration.type !== "comment") {
1382
+ continue;
1383
+ }
1384
+ if (!activeThreadAnchors.has(decoration.cellIndex)) {
1385
+ decorations.removeDecoration(decoration.cellIndex, "comment");
1386
+ }
1387
+ }
1388
+ });
1389
+ return () => unsubscribe();
1390
+ });
1391
+ };
1392
+ var useThreads = () => {
1393
+ useUpdateCursorOnThreadSelection();
1394
+ useSelectThreadOnCursorChange();
1395
+ useThreadDecorations();
1396
+ };
1397
+
1398
+ // packages/plugins/plugin-sheet/src/components/Sheet/util.ts
1399
+ var getRelativeClientRect = (root, element) => {
1400
+ const rootRect = root.getBoundingClientRect();
1401
+ const elementRect = element.getBoundingClientRect();
1402
+ return new DOMRect(elementRect.left - rootRect.left + root.scrollLeft, elementRect.top - rootRect.top + root.scrollTop, elementRect.width, elementRect.height);
1403
+ };
1404
+ var getRectUnion = (b1, b2) => {
1405
+ return {
1406
+ left: Math.min(b1.left, b2.left),
1407
+ top: Math.min(b1.top, b2.top),
1408
+ width: Math.abs(b1.left - b2.left) + (b1.left > b2.left ? b1.width : b2.width),
1409
+ height: Math.abs(b1.top - b2.top) + (b1.height > b2.height ? b1.height : b2.height)
1410
+ };
1411
+ };
1412
+ var scrollIntoView = (scrollContainer, el) => {
1413
+ el.scrollIntoView({
1414
+ block: "nearest",
1415
+ inline: "nearest"
1416
+ });
1417
+ const cellBounds = el.getBoundingClientRect();
1418
+ const scrollerBounds = scrollContainer.getBoundingClientRect();
1419
+ if (cellBounds.top < scrollerBounds.top) {
1420
+ scrollContainer.scrollTop -= scrollerBounds.top - cellBounds.top;
1421
+ } else if (cellBounds.bottom >= scrollerBounds.bottom - 1) {
1422
+ scrollContainer.scrollTop += 2 + scrollerBounds.bottom - cellBounds.bottom;
1423
+ }
1424
+ if (cellBounds.left < scrollerBounds.left) {
1425
+ scrollContainer.scrollLeft -= scrollerBounds.left - cellBounds.left;
1426
+ } else if (cellBounds.right >= scrollerBounds.right) {
1427
+ scrollContainer.scrollLeft += 2 + scrollerBounds.right - cellBounds.right;
1428
+ }
1429
+ };
1430
+
1431
+ // packages/plugins/plugin-sheet/src/components/CellEditor/CellEditor.tsx
1432
+ import { EditorView, keymap } from "@codemirror/view";
1433
+ import React5 from "react";
1434
+ import { useThemeContext } from "@dxos/react-ui";
1435
+ import { createBasicExtensions, createThemeExtensions, preventNewline, useTextEditor } from "@dxos/react-ui-editor";
1436
+ var editorKeys = ({ onNav, onClose }) => {
1437
+ return keymap.of([
1438
+ {
1439
+ key: "ArrowUp",
1440
+ run: (editor) => {
1441
+ const value = editor.state.doc.toString();
1442
+ onNav?.(value, {
1443
+ key: "ArrowUp"
1444
+ });
1445
+ return !!onNav;
1446
+ }
1447
+ },
1448
+ {
1449
+ key: "ArrowDown",
1450
+ run: (editor) => {
1451
+ const value = editor.state.doc.toString();
1452
+ onNav?.(value, {
1453
+ key: "ArrowDown"
1454
+ });
1455
+ return !!onNav;
1456
+ }
1457
+ },
1458
+ {
1459
+ key: "ArrowLeft",
1460
+ run: (editor) => {
1461
+ const value = editor.state.doc.toString();
1462
+ onNav?.(value, {
1463
+ key: "ArrowLeft"
1464
+ });
1465
+ return !!onNav;
1466
+ }
1467
+ },
1468
+ {
1469
+ key: "ArrowRight",
1470
+ run: (editor) => {
1471
+ const value = editor.state.doc.toString();
1472
+ onNav?.(value, {
1473
+ key: "ArrowRight"
1474
+ });
1475
+ return !!onNav;
1476
+ }
1477
+ },
1478
+ {
1479
+ key: "Enter",
1480
+ run: (editor) => {
1481
+ onClose(editor.state.doc.toString(), {
1482
+ key: "Enter"
1483
+ });
1484
+ return true;
1485
+ },
1486
+ shift: (editor) => {
1487
+ onClose(editor.state.doc.toString(), {
1488
+ key: "Enter",
1489
+ shift: true
1490
+ });
1491
+ return true;
1492
+ }
1493
+ },
1494
+ {
1495
+ key: "Tab",
1496
+ run: (editor) => {
1497
+ onClose(editor.state.doc.toString(), {
1498
+ key: "Tab"
1499
+ });
1500
+ return true;
1501
+ },
1502
+ shift: (editor) => {
1503
+ onClose(editor.state.doc.toString(), {
1504
+ key: "Tab",
1505
+ shift: true
1506
+ });
1507
+ return true;
1508
+ }
1509
+ },
1510
+ {
1511
+ key: "Escape",
1512
+ run: () => {
1513
+ onClose(void 0, {
1514
+ key: "Escape"
1515
+ });
1516
+ return true;
1517
+ }
1518
+ }
1519
+ ]);
1520
+ };
1521
+ var editorVariants = {
1522
+ // TODO(thure): remove when legacy is no longer used.
1523
+ legacy: {
1524
+ root: "flex w-full",
1525
+ editor: "flex w-full [&>.cm-scroller]:scrollbar-none",
1526
+ content: "!px-2 !py-1"
1527
+ },
1528
+ grid: {
1529
+ root: "absolute z-[1]",
1530
+ editor: "[&>.cm-scroller]:scrollbar-none tabular-nums",
1531
+ content: "!border !border-transparent !p-0.5"
1532
+ }
1533
+ };
1534
+ var CellEditor = ({ value, extension, autoFocus, onBlur, variant = "legacy", box, gridId }) => {
1535
+ const { themeMode } = useThemeContext();
1536
+ const { parentRef } = useTextEditor(() => {
1537
+ return {
1538
+ autoFocus,
1539
+ initialValue: value,
1540
+ selection: {
1541
+ anchor: value?.length ?? 0
1542
+ },
1543
+ extensions: [
1544
+ extension ?? [],
1545
+ preventNewline,
1546
+ EditorView.focusChangeEffect.of((_, focusing) => {
1547
+ if (!focusing) {
1548
+ onBlur?.({
1549
+ type: "blur"
1550
+ });
1551
+ }
1552
+ return null;
1553
+ }),
1554
+ createBasicExtensions({
1555
+ lineWrapping: false
1556
+ }),
1557
+ createThemeExtensions({
1558
+ themeMode,
1559
+ slots: {
1560
+ editor: {
1561
+ className: editorVariants[variant].editor
1562
+ },
1563
+ content: {
1564
+ className: editorVariants[variant].content
1565
+ }
1566
+ }
1567
+ })
1568
+ ]
1569
+ };
1570
+ }, [
1571
+ extension,
1572
+ autoFocus,
1573
+ value,
1574
+ variant,
1575
+ onBlur
1576
+ ]);
1577
+ return /* @__PURE__ */ React5.createElement("div", {
1578
+ ref: parentRef,
1579
+ className: editorVariants[variant].root,
1580
+ style: box,
1581
+ ...gridId && {
1582
+ "data-grid": gridId
1583
+ }
1584
+ });
1585
+ };
1586
+
1587
+ // packages/plugins/plugin-sheet/src/components/CellEditor/extension.ts
1588
+ import { acceptCompletion, autocompletion, completionStatus, startCompletion } from "@codemirror/autocomplete";
1589
+ import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
1590
+ import { Facet } from "@codemirror/state";
1591
+ import { ViewPlugin, keymap as keymap2 } from "@codemirror/view";
1592
+ import { tags } from "@lezer/highlight";
1593
+ import { spreadsheet } from "codemirror-lang-spreadsheet";
1594
+ import { mx } from "@dxos/react-ui-theme";
1595
+ var highlightStyles = HighlightStyle.define([
1596
+ // Function.
1597
+ {
1598
+ tag: tags.name,
1599
+ class: "text-accentText"
1600
+ },
1601
+ // Range.
1602
+ {
1603
+ tag: tags.tagName,
1604
+ class: "text-pinkText"
1605
+ },
1606
+ // Values.
1607
+ {
1608
+ tag: tags.number,
1609
+ class: "text-tealText"
1610
+ },
1611
+ {
1612
+ tag: tags.bool,
1613
+ class: "text-tealText"
1614
+ },
1615
+ {
1616
+ tag: tags.string,
1617
+ class: "text-tealText"
1618
+ },
1619
+ // Error.
1620
+ {
1621
+ tag: tags.invalid,
1622
+ class: "text-unAccent"
1623
+ }
1624
+ ]);
1625
+ var languageFacet = Facet.define();
1626
+ var sheetExtension = ({ functions = [] }) => {
1627
+ const { extension, language } = spreadsheet({
1628
+ idiom: "en-US",
1629
+ decimalSeparator: "."
1630
+ });
1631
+ const createCompletion = (name) => {
1632
+ const { section = "Custom", description, syntax } = functions.find((value) => value.name === name) ?? {};
1633
+ return {
1634
+ section,
1635
+ label: name,
1636
+ info: () => {
1637
+ if (!description && !syntax) {
1638
+ return null;
1639
+ }
1640
+ const root = document.createElement("div");
1641
+ root.className = "flex flex-col gap-2 text-sm";
1642
+ const title = document.createElement("h2");
1643
+ title.innerText = name;
1644
+ title.className = "text-lg font-mono text-accentText";
1645
+ root.appendChild(title);
1646
+ if (description) {
1647
+ const info = document.createElement("p");
1648
+ info.innerText = description;
1649
+ info.className = "text-subdued";
1650
+ root.appendChild(info);
1651
+ }
1652
+ if (syntax) {
1653
+ const detail = document.createElement("pre");
1654
+ detail.innerText = syntax;
1655
+ detail.className = "whitespace-pre-wrap text-greenText";
1656
+ root.appendChild(detail);
1657
+ }
1658
+ return root;
1659
+ },
1660
+ apply: (view, completion, from, to) => {
1661
+ const insertParens = to === view.state.doc.toString().length;
1662
+ view.dispatch(view.state.update({
1663
+ changes: {
1664
+ from,
1665
+ to,
1666
+ insert: completion.label + (insertParens ? "()" : "")
1667
+ },
1668
+ selection: {
1669
+ anchor: from + completion.label.length + 1
1670
+ }
1671
+ }));
1672
+ }
1673
+ };
1674
+ };
1675
+ return [
1676
+ extension,
1677
+ languageFacet.of(language),
1678
+ language.data.of({
1679
+ autocomplete: (context) => {
1680
+ if (context.state.doc.toString()[0] !== "=") {
1681
+ return null;
1682
+ }
1683
+ const match = context.matchBefore(/\w*/);
1684
+ if (!match || match.from === match.to) {
1685
+ return null;
1686
+ }
1687
+ const text = match.text.toUpperCase();
1688
+ if (!context.explicit && match.text.length < 2) {
1689
+ return null;
1690
+ }
1691
+ return {
1692
+ from: match.from,
1693
+ options: functions?.filter(({ name }) => name.startsWith(text)).map(({ name }) => createCompletion(name)) ?? []
1694
+ };
1695
+ }
1696
+ }),
1697
+ syntaxHighlighting(highlightStyles),
1698
+ autocompletion({
1699
+ aboveCursor: false,
1700
+ defaultKeymap: true,
1701
+ activateOnTyping: true,
1702
+ // NOTE: Useful for debugging.
1703
+ closeOnBlur: false,
1704
+ icons: false,
1705
+ tooltipClass: () => mx("!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]", "[&>ul>li[aria-selected]]:!bg-accentSurface", "border-separator")
1706
+ }),
1707
+ keymap2.of([
1708
+ {
1709
+ key: "Tab",
1710
+ run: (view) => {
1711
+ return completionStatus(view.state) === "active" ? acceptCompletion(view) : startCompletion(view);
1712
+ }
1713
+ }
1714
+ ])
1715
+ ];
1716
+ };
1717
+ var rangeExtension = (onInit) => {
1718
+ let view;
1719
+ let activeRange;
1720
+ const provider = (range) => {
1721
+ if (activeRange) {
1722
+ view.dispatch(view.state.update({
1723
+ changes: {
1724
+ ...activeRange,
1725
+ insert: range.toString()
1726
+ },
1727
+ selection: {
1728
+ anchor: activeRange.from + range.length
1729
+ }
1730
+ }));
1731
+ }
1732
+ view.focus();
1733
+ };
1734
+ return ViewPlugin.fromClass(class {
1735
+ constructor(_view) {
1736
+ view = _view;
1737
+ onInit(provider);
1738
+ }
1739
+ update(view2) {
1740
+ const { anchor } = view2.state.selection.ranges[0];
1741
+ activeRange = void 0;
1742
+ const [language] = view2.state.facet(languageFacet);
1743
+ const { topNode } = language.parser.parse(view2.state.doc.toString());
1744
+ visitTree(topNode, ({ type, from, to }) => {
1745
+ if (from <= anchor && to >= anchor) {
1746
+ switch (type.name) {
1747
+ case "Function": {
1748
+ activeRange = {
1749
+ from: to,
1750
+ to
1751
+ };
1752
+ break;
1753
+ }
1754
+ case "CloseParen": {
1755
+ activeRange = {
1756
+ from,
1757
+ to: from
1758
+ };
1759
+ break;
1760
+ }
1761
+ case "RangeToken":
1762
+ case "CellToken":
1763
+ activeRange = {
1764
+ from,
1765
+ to
1766
+ };
1767
+ return true;
1768
+ }
1769
+ }
1770
+ return false;
1771
+ });
1772
+ if (!activeRange && view2.state.doc.toString()[0] === "=") {
1773
+ activeRange = {
1774
+ from: 1,
1775
+ to: view2.state.doc.toString().length
1776
+ };
1777
+ }
1778
+ }
1779
+ });
1780
+ };
1781
+ var visitTree = (node, callback) => {
1782
+ if (callback(node)) {
1783
+ return true;
1784
+ }
1785
+ for (let child = node.firstChild; child !== null; child = child.nextSibling) {
1786
+ if (visitTree(child, callback)) {
1787
+ return true;
1788
+ }
1789
+ }
1790
+ return false;
1791
+ };
1792
+
1793
+ // packages/plugins/plugin-sheet/src/components/Sheet/Sheet.tsx
1794
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/Sheet/Sheet.tsx";
1795
+ var fragments = {
1796
+ axis: "bg-axisSurface text-axisText text-xs select-none",
1797
+ axisSelected: "bg-attention text-baseText",
1798
+ cell: "bg-gridCell",
1799
+ cellSelected: "bg-gridCellSelected text-baseText border !border-accentSurface"
1800
+ };
1801
+ var SheetRoot = ({ children, ...props }) => {
1802
+ return /* @__PURE__ */ React6.createElement(SheetContextProvider, props, children);
1803
+ };
1804
+ var SheetMain = /* @__PURE__ */ forwardRef(({ classNames, numRows, numCols }, forwardRef2) => {
1805
+ const { model, cursor, setCursor, setRange, setEditing } = useSheetContext();
1806
+ const { rowsRef, columnsRef, contentRef } = useScrollHandlers();
1807
+ useThreads();
1808
+ const [rows, setRows] = useState5([
1809
+ ...model.sheet.rows
1810
+ ]);
1811
+ const [columns, setColumns] = useState5([
1812
+ ...model.sheet.columns
1813
+ ]);
1814
+ useEffect4(() => {
1815
+ const rowsAccessor = createDocAccessor(model.sheet, [
1816
+ "rows"
1817
+ ]);
1818
+ const columnsAccessor = createDocAccessor(model.sheet, [
1819
+ "columns"
1820
+ ]);
1821
+ const handleUpdate = debounce2(() => {
1822
+ setRows([
1823
+ ...model.sheet.rows
1824
+ ]);
1825
+ setColumns([
1826
+ ...model.sheet.columns
1827
+ ]);
1828
+ }, 100);
1829
+ rowsAccessor.handle.addListener("change", handleUpdate);
1830
+ columnsAccessor.handle.addListener("change", handleUpdate);
1831
+ handleUpdate();
1832
+ return () => {
1833
+ rowsAccessor.handle.removeListener("change", handleUpdate);
1834
+ columnsAccessor.handle.removeListener("change", handleUpdate);
1835
+ };
1836
+ }, [
1837
+ model
1838
+ ]);
1839
+ useEffect4(() => {
1840
+ model.reset();
1841
+ }, [
1842
+ rows,
1843
+ columns
1844
+ ]);
1845
+ const handleMoveRows = (from, to, num = 1) => {
1846
+ const cursorIdx = cursor ? addressToIndex(model.sheet, cursor) : void 0;
1847
+ const [rows2] = model.sheet.rows.splice(from, num);
1848
+ model.sheet.rows.splice(to, 0, rows2);
1849
+ if (cursorIdx) {
1850
+ setCursor(addressFromIndex(model.sheet, cursorIdx));
1851
+ }
1852
+ setRows([
1853
+ ...model.sheet.rows
1854
+ ]);
1855
+ };
1856
+ const handleMoveColumns = (from, to, num = 1) => {
1857
+ const cursorIdx = cursor ? addressToIndex(model.sheet, cursor) : void 0;
1858
+ const columns2 = model.sheet.columns.splice(from, num);
1859
+ model.sheet.columns.splice(to, 0, ...columns2);
1860
+ if (cursorIdx) {
1861
+ setCursor(addressFromIndex(model.sheet, cursorIdx));
1862
+ }
1863
+ setColumns([
1864
+ ...model.sheet.columns
1865
+ ]);
1866
+ };
1867
+ const [rowSizes, setRowSizes] = useState5();
1868
+ const [columnSizes, setColumnSizes] = useState5();
1869
+ useEffect4(() => {
1870
+ const rowAccessor = createDocAccessor(model.sheet, [
1871
+ "rowMeta"
1872
+ ]);
1873
+ const columnAccessor = createDocAccessor(model.sheet, [
1874
+ "columnMeta"
1875
+ ]);
1876
+ const handleUpdate = debounce2(() => {
1877
+ const mapSizes = (values) => values.reduce((map, [idx, meta]) => {
1878
+ if (meta.size) {
1879
+ map[idx] = meta.size;
1880
+ }
1881
+ return map;
1882
+ }, {});
1883
+ setRowSizes(mapSizes(Object.entries(model.sheet.rowMeta)));
1884
+ setColumnSizes(mapSizes(Object.entries(model.sheet.columnMeta)));
1885
+ }, 100);
1886
+ rowAccessor.handle.addListener("change", handleUpdate);
1887
+ columnAccessor.handle.addListener("change", handleUpdate);
1888
+ handleUpdate();
1889
+ return () => {
1890
+ rowAccessor.handle.removeListener("change", handleUpdate);
1891
+ columnAccessor.handle.removeListener("change", handleUpdate);
1892
+ };
1893
+ }, [
1894
+ model
1895
+ ]);
1896
+ const handleResizeRow = (idx, size, save) => {
1897
+ if (save) {
1898
+ model.sheet.rowMeta[idx] ??= {};
1899
+ model.sheet.rowMeta[idx].size = size;
1900
+ } else {
1901
+ setRowSizes((sizes) => ({
1902
+ ...sizes,
1903
+ [idx]: size
1904
+ }));
1905
+ }
1906
+ };
1907
+ const handleResizeColumn = (idx, size, save) => {
1908
+ if (save) {
1909
+ model.sheet.columnMeta[idx] ??= {};
1910
+ model.sheet.columnMeta[idx].size = size;
1911
+ } else {
1912
+ setColumnSizes((sizes) => ({
1913
+ ...sizes,
1914
+ [idx]: size
1915
+ }));
1916
+ }
1917
+ };
1918
+ return /* @__PURE__ */ React6.createElement("div", {
1919
+ role: "none",
1920
+ className: mx2("grid grid-cols-[calc(var(--rail-size)-2px)_1fr] grid-rows-[32px_1fr_32px] bs-full is-full overflow-hidden", classNames)
1921
+ }, /* @__PURE__ */ React6.createElement(GridCorner, {
1922
+ onClick: () => {
1923
+ setCursor(void 0);
1924
+ setRange(void 0);
1925
+ setEditing(false);
1926
+ }
1927
+ }), /* @__PURE__ */ React6.createElement(SheetColumns, {
1928
+ ref: columnsRef,
1929
+ columns,
1930
+ sizes: columnSizes,
1931
+ selected: cursor?.col,
1932
+ onSelect: (col) => setCursor(cursor?.col === col ? void 0 : {
1933
+ row: -1,
1934
+ col
1935
+ }),
1936
+ onResize: handleResizeColumn,
1937
+ onMove: handleMoveColumns
1938
+ }), /* @__PURE__ */ React6.createElement(SheetRows, {
1939
+ ref: rowsRef,
1940
+ rows,
1941
+ sizes: rowSizes,
1942
+ selected: cursor?.row,
1943
+ onSelect: (row) => setCursor(cursor?.row === row ? void 0 : {
1944
+ row,
1945
+ col: -1
1946
+ }),
1947
+ onResize: handleResizeRow,
1948
+ onMove: handleMoveRows
1949
+ }), /* @__PURE__ */ React6.createElement(SheetGrid, {
1950
+ ref: contentRef,
1951
+ size: {
1952
+ numRows: numRows ?? rows.length,
1953
+ numCols: numCols ?? columns.length
1954
+ },
1955
+ rows,
1956
+ columns,
1957
+ rowSizes,
1958
+ columnSizes
1959
+ }), /* @__PURE__ */ React6.createElement(GridCorner, null), /* @__PURE__ */ React6.createElement(SheetStatusBar, null));
1960
+ });
1961
+ var useScrollHandlers = () => {
1962
+ const rowsRef = useRef(null);
1963
+ const columnsRef = useRef(null);
1964
+ const contentRef = useRef(null);
1965
+ useEffect4(() => {
1966
+ const handleRowsScroll = (ev) => {
1967
+ const { scrollTop } = ev.target;
1968
+ if (!rowsRef.current.dataset.locked) {
1969
+ contentRef.current.scrollTop = scrollTop;
1970
+ }
1971
+ };
1972
+ const handleColumnsScroll = (ev) => {
1973
+ const { scrollLeft } = ev.target;
1974
+ if (!columnsRef.current.dataset.locked) {
1975
+ contentRef.current.scrollLeft = scrollLeft;
1976
+ }
1977
+ };
1978
+ const handleContentScroll = (ev) => {
1979
+ const { scrollTop, scrollLeft } = ev.target;
1980
+ rowsRef.current.scrollTop = scrollTop;
1981
+ columnsRef.current.scrollLeft = scrollLeft;
1982
+ };
1983
+ const rows = rowsRef.current;
1984
+ const columns = columnsRef.current;
1985
+ const content = contentRef.current;
1986
+ rows.addEventListener("scroll", handleRowsScroll);
1987
+ columns.addEventListener("scroll", handleColumnsScroll);
1988
+ content.addEventListener("scroll", handleContentScroll);
1989
+ return () => {
1990
+ rows.removeEventListener("scroll", handleRowsScroll);
1991
+ columns.removeEventListener("scroll", handleColumnsScroll);
1992
+ content.removeEventListener("scroll", handleContentScroll);
1993
+ };
1994
+ }, []);
1995
+ return {
1996
+ rowsRef,
1997
+ columnsRef,
1998
+ contentRef
1999
+ };
2000
+ };
2001
+ var GridCorner = (props) => {
2002
+ return /* @__PURE__ */ React6.createElement("div", {
2003
+ className: fragments.axis,
2004
+ ...props
2005
+ });
2006
+ };
2007
+ var MovingOverlay = ({ label }) => {
2008
+ return /* @__PURE__ */ React6.createElement("div", {
2009
+ className: "flex w-full h-full justify-center items-center text-sm p-1 bg-gridOverlay cursor-pointer"
2010
+ }, label);
2011
+ };
2012
+ var mouseConstraints = {
2013
+ distance: 10
2014
+ };
2015
+ var touchConstraints = {
2016
+ delay: 250,
2017
+ tolerance: 5
2018
+ };
2019
+ var SheetRows = /* @__PURE__ */ forwardRef(({ rows, sizes, selected, onSelect, onResize, onMove }, forwardRef2) => {
2020
+ const mouseSensor = useSensor(MouseSensor, {
2021
+ activationConstraint: mouseConstraints
2022
+ });
2023
+ const touchSensor = useSensor(TouchSensor, {
2024
+ activationConstraint: touchConstraints
2025
+ });
2026
+ const keyboardSensor = useSensor(KeyboardSensor, {});
2027
+ const sensors = useSensors(mouseSensor, touchSensor, keyboardSensor);
2028
+ const [active, setActive] = useState5(null);
2029
+ const handleDragStart = ({ active: active2 }) => {
2030
+ setActive(active2);
2031
+ };
2032
+ const handleDragEnd = ({ over, active: active2 }) => {
2033
+ if (over && over.id !== active2.id) {
2034
+ setActive(null);
2035
+ onMove?.(active2.data.current.index, over.data.current.index);
2036
+ }
2037
+ };
2038
+ const snapToCenter = ({ activatorEvent, draggingNodeRect, transform }) => {
2039
+ if (draggingNodeRect && activatorEvent) {
2040
+ const activatorCoordinates = getEventCoordinates(activatorEvent);
2041
+ if (!activatorCoordinates) {
2042
+ return transform;
2043
+ }
2044
+ const offset = activatorCoordinates.y - draggingNodeRect.top;
2045
+ return {
2046
+ ...transform,
2047
+ y: transform.y + offset - draggingNodeRect.height / 2
2048
+ };
2049
+ }
2050
+ return transform;
2051
+ };
2052
+ return /* @__PURE__ */ React6.createElement("div", {
2053
+ className: "relative flex grow overflow-hidden"
2054
+ }, /* @__PURE__ */ React6.createElement("div", {
2055
+ className: mx2("z-20 absolute inset-0 border-y border-gridLine pointer-events-none"),
2056
+ style: {
2057
+ width: axisWidth
2058
+ }
2059
+ }), /* @__PURE__ */ React6.createElement("div", {
2060
+ ref: forwardRef2,
2061
+ role: "rowheader",
2062
+ className: "grow overflow-y-auto scrollbar-none"
2063
+ }, /* @__PURE__ */ React6.createElement(DndContext, {
2064
+ sensors,
2065
+ modifiers: [
2066
+ restrictToVerticalAxis,
2067
+ snapToCenter
2068
+ ],
2069
+ onDragStart: handleDragStart,
2070
+ onDragEnd: handleDragEnd
2071
+ }, /* @__PURE__ */ React6.createElement("div", {
2072
+ className: "flex flex-col",
2073
+ style: {
2074
+ width: axisWidth
2075
+ }
2076
+ }, rows.map((idx, index) => /* @__PURE__ */ React6.createElement(GridRowCell, {
2077
+ key: idx,
2078
+ idx,
2079
+ index,
2080
+ label: String(index + 1),
2081
+ size: sizes?.[idx] ?? defaultHeight,
2082
+ resize: index < rows.length - 1,
2083
+ selected: selected === index,
2084
+ onResize,
2085
+ onSelect
2086
+ }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(DragOverlay, null, active && /* @__PURE__ */ React6.createElement(MovingOverlay, {
2087
+ label: String(active.data.current.index + 1)
2088
+ })), document.body))));
2089
+ });
2090
+ var GridRowCell = ({ idx, index, label, size, resize, selected, onSelect, onResize }) => {
2091
+ const { setNodeRef: setDroppableNodeRef } = useDroppable({
2092
+ id: idx,
2093
+ data: {
2094
+ index
2095
+ }
2096
+ });
2097
+ const { setNodeRef: setDraggableNodeRef, attributes, listeners, isDragging, over } = useDraggable({
2098
+ id: idx,
2099
+ data: {
2100
+ index
2101
+ }
2102
+ });
2103
+ const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
2104
+ const [initialSize, setInitialSize] = useState5(size);
2105
+ const [resizing, setResizing] = useState5(false);
2106
+ const scrollHandler = useRef();
2107
+ const handleResizeStart = (_ev, _dir, elementRef) => {
2108
+ const scrollContainer = elementRef.closest('[role="rowheader"]');
2109
+ const scrollTop = scrollContainer.scrollTop;
2110
+ scrollHandler.current = (ev) => ev.target.scrollTop = scrollTop;
2111
+ scrollContainer.addEventListener("scroll", scrollHandler.current);
2112
+ scrollContainer.dataset.locked = "true";
2113
+ setResizing(true);
2114
+ };
2115
+ const handleResize = (_ev, _dir, _elementRef, { height }) => {
2116
+ onResize?.(idx, initialSize + height);
2117
+ };
2118
+ const handleResizeStop = (_ev, _dir, elementRef, { height }) => {
2119
+ const scrollContainer = elementRef.closest('[role="rowheader"]');
2120
+ scrollContainer.removeEventListener("scroll", scrollHandler.current);
2121
+ delete scrollContainer.dataset.locked;
2122
+ scrollHandler.current = void 0;
2123
+ setInitialSize(initialSize + height);
2124
+ onResize?.(idx, initialSize + height, true);
2125
+ setResizing(false);
2126
+ };
2127
+ return /* @__PURE__ */ React6.createElement(Resizable, {
2128
+ enable: {
2129
+ bottom: resize
2130
+ },
2131
+ size: {
2132
+ height: size - 1
2133
+ },
2134
+ minHeight: minHeight - 1,
2135
+ maxHeight,
2136
+ onResizeStart: handleResizeStart,
2137
+ onResize: handleResize,
2138
+ onResizeStop: handleResizeStop
2139
+ }, /* @__PURE__ */ React6.createElement("div", {
2140
+ ref: setNodeRef,
2141
+ ...attributes,
2142
+ ...listeners,
2143
+ 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),
2144
+ onClick: () => onSelect?.(index)
2145
+ }, /* @__PURE__ */ React6.createElement("span", {
2146
+ className: "flex w-full justify-center"
2147
+ }, label), over?.id === idx && !isDragging && /* @__PURE__ */ React6.createElement("div", {
2148
+ className: "z-20 absolute top-0 w-full min-h-[4px] border-b-4 border-accentSurface"
2149
+ }), resizing && /* @__PURE__ */ React6.createElement("div", {
2150
+ className: "z-20 absolute bottom-0 w-full min-h-[4px] border-b-4 border-accentSurface"
2151
+ })));
2152
+ };
2153
+ var SheetColumns = /* @__PURE__ */ forwardRef(({ columns, sizes, selected, onSelect, onResize, onMove }, forwardRef2) => {
2154
+ const mouseSensor = useSensor(MouseSensor, {
2155
+ activationConstraint: mouseConstraints
2156
+ });
2157
+ const touchSensor = useSensor(TouchSensor, {
2158
+ activationConstraint: touchConstraints
2159
+ });
2160
+ const keyboardSensor = useSensor(KeyboardSensor, {});
2161
+ const sensors = useSensors(mouseSensor, touchSensor, keyboardSensor);
2162
+ const [active, setActive] = useState5(null);
2163
+ const handleDragStart = ({ active: active2 }) => {
2164
+ setActive(active2);
2165
+ };
2166
+ const handleDragEnd = ({ active: active2, over }) => {
2167
+ if (over && over.id !== active2.id) {
2168
+ setActive(null);
2169
+ onMove?.(active2.data.current.index, over.data.current.index);
2170
+ }
2171
+ };
2172
+ const snapToCenter = ({ activatorEvent, draggingNodeRect, transform }) => {
2173
+ if (draggingNodeRect && activatorEvent) {
2174
+ const activatorCoordinates = getEventCoordinates(activatorEvent);
2175
+ if (!activatorCoordinates) {
2176
+ return transform;
2177
+ }
2178
+ const offset = activatorCoordinates.x - draggingNodeRect.left;
2179
+ return {
2180
+ ...transform,
2181
+ x: transform.x + offset - draggingNodeRect.width / 2
2182
+ };
2183
+ }
2184
+ return transform;
2185
+ };
2186
+ return /* @__PURE__ */ React6.createElement("div", {
2187
+ className: "relative flex grow overflow-hidden"
2188
+ }, /* @__PURE__ */ React6.createElement("div", {
2189
+ className: mx2("z-20 absolute inset-0 border-x border-gridLine pointer-events-none"),
2190
+ style: {
2191
+ height: axisHeight
2192
+ }
2193
+ }), /* @__PURE__ */ React6.createElement("div", {
2194
+ ref: forwardRef2,
2195
+ role: "columnheader",
2196
+ className: "grow overflow-x-auto scrollbar-none"
2197
+ }, /* @__PURE__ */ React6.createElement(DndContext, {
2198
+ autoScroll: {
2199
+ enabled: true
2200
+ },
2201
+ sensors,
2202
+ modifiers: [
2203
+ restrictToHorizontalAxis,
2204
+ snapToCenter
2205
+ ],
2206
+ onDragStart: handleDragStart,
2207
+ onDragEnd: handleDragEnd
2208
+ }, /* @__PURE__ */ React6.createElement("div", {
2209
+ className: "flex h-full",
2210
+ style: {
2211
+ height: axisHeight
2212
+ }
2213
+ }, columns.map((idx, index) => /* @__PURE__ */ React6.createElement(GridColumnCell, {
2214
+ key: idx,
2215
+ idx,
2216
+ index,
2217
+ label: columnLetter(index),
2218
+ size: sizes?.[idx] ?? defaultWidth,
2219
+ resize: index < columns.length - 1,
2220
+ selected: selected === index,
2221
+ onResize,
2222
+ onSelect
2223
+ }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement(DragOverlay, null, active && /* @__PURE__ */ React6.createElement(MovingOverlay, {
2224
+ label: columnLetter(active.data.current.index)
2225
+ })), document.body))));
2226
+ });
2227
+ var GridColumnCell = ({ idx, index, label, size, resize, selected, onSelect, onResize }) => {
2228
+ const { setNodeRef: setDroppableNodeRef } = useDroppable({
2229
+ id: idx,
2230
+ data: {
2231
+ index
2232
+ }
2233
+ });
2234
+ const { setNodeRef: setDraggableNodeRef, attributes, listeners, over, isDragging } = useDraggable({
2235
+ id: idx,
2236
+ data: {
2237
+ index
2238
+ }
2239
+ });
2240
+ const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
2241
+ const [initialSize, setInitialSize] = useState5(size);
2242
+ const [resizing, setResizing] = useState5(false);
2243
+ const scrollHandler = useRef();
2244
+ const handleResizeStart = (_ev, _dir, elementRef) => {
2245
+ const scrollContainer = elementRef.closest('[role="columnheader"]');
2246
+ const scrollLeft = scrollContainer.scrollLeft;
2247
+ scrollHandler.current = (ev) => ev.target.scrollLeft = scrollLeft;
2248
+ scrollContainer.addEventListener("scroll", scrollHandler.current);
2249
+ scrollContainer.dataset.locked = "true";
2250
+ setResizing(true);
2251
+ };
2252
+ const handleResize = (_ev, _dir, _elementRef, { width }) => {
2253
+ onResize?.(idx, initialSize + width);
2254
+ };
2255
+ const handleResizeStop = (_ev, _dir, elementRef, { width }) => {
2256
+ const scrollContainer = elementRef.closest('[role="columnheader"]');
2257
+ scrollContainer.removeEventListener("scroll", scrollHandler.current);
2258
+ delete scrollContainer.dataset.locked;
2259
+ scrollHandler.current = void 0;
2260
+ setInitialSize(initialSize + width);
2261
+ onResize?.(idx, initialSize + width, true);
2262
+ setResizing(false);
2263
+ };
2264
+ return /* @__PURE__ */ React6.createElement(Resizable, {
2265
+ enable: {
2266
+ right: resize
2267
+ },
2268
+ size: {
2269
+ width: size - 1
2270
+ },
2271
+ minWidth: minWidth - 1,
2272
+ maxWidth,
2273
+ onResizeStart: handleResizeStart,
2274
+ onResize: handleResize,
2275
+ onResizeStop: handleResizeStop
2276
+ }, /* @__PURE__ */ React6.createElement("div", {
2277
+ ref: setNodeRef,
2278
+ ...attributes,
2279
+ ...listeners,
2280
+ 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),
2281
+ onClick: () => onSelect?.(index)
2282
+ }, /* @__PURE__ */ React6.createElement("span", {
2283
+ className: "flex w-full justify-center"
2284
+ }, label), over?.id === idx && !isDragging && /* @__PURE__ */ React6.createElement("div", {
2285
+ className: "z-20 absolute left-0 h-full min-w-[4px] border-l-4 border-accentSurface"
2286
+ }), resizing && /* @__PURE__ */ React6.createElement("div", {
2287
+ className: "z-20 absolute right-0 h-full min-h-[4px] border-l-4 border-accentSurface"
2288
+ })));
2289
+ };
2290
+ var SheetGrid = /* @__PURE__ */ forwardRef(({ size, rows, columns, rowSizes, columnSizes }, forwardRef2) => {
2291
+ const { ref: containerRef, width: containerWidth = 0, height: containerHeight = 0 } = useResizeDetector({
2292
+ refreshRate: 200
2293
+ });
2294
+ const scrollerRef = useRef(null);
2295
+ useImperativeHandle(forwardRef2, () => scrollerRef.current);
2296
+ const { model, cursor, range, editing, setCursor, setRange, setEditing, onInfo } = useSheetContext();
2297
+ const initialText = useRef();
2298
+ const quickEdit = useRef(false);
2299
+ const [, forceUpdate] = useState5({});
2300
+ useEffect4(() => {
2301
+ const unsubscribe = model.update.on(() => {
2302
+ log2("updated", {
2303
+ id: model.id
2304
+ }, {
2305
+ F: __dxlog_file4,
2306
+ L: 737,
2307
+ S: void 0,
2308
+ C: (f, a) => f(...a)
2309
+ });
2310
+ forceUpdate({});
2311
+ });
2312
+ return () => {
2313
+ unsubscribe();
2314
+ };
2315
+ }, [
2316
+ model
2317
+ ]);
2318
+ const inputRef = useRef(null);
2319
+ const handleKeyDown = (ev) => {
2320
+ const isMacOS = /Mac|iPhone|iPod|iPad/.test(navigator.userAgent);
2321
+ if (cursor && (isMacOS && ev.metaKey || ev.ctrlKey)) {
2322
+ switch (ev.key) {
2323
+ case "x": {
2324
+ model.cut(range ?? {
2325
+ from: cursor
2326
+ });
2327
+ return;
2328
+ }
2329
+ case "c": {
2330
+ model.copy(range ?? {
2331
+ from: cursor
2332
+ });
2333
+ return;
2334
+ }
2335
+ case "v": {
2336
+ model.paste(cursor);
2337
+ return;
2338
+ }
2339
+ case "z": {
2340
+ if (ev.shiftKey) {
2341
+ model.redo();
2342
+ } else {
2343
+ model.undo();
2344
+ }
2345
+ return;
2346
+ }
2347
+ }
2348
+ }
2349
+ switch (ev.key) {
2350
+ case "ArrowUp":
2351
+ case "ArrowDown":
2352
+ case "ArrowLeft":
2353
+ case "ArrowRight":
2354
+ case "Home":
2355
+ case "End": {
2356
+ const next = handleNav(ev, cursor, range, size);
2357
+ setRange(next.range);
2358
+ if (next.cursor) {
2359
+ setCursor(next.cursor);
2360
+ const element = getCellElement(scrollerRef.current, next.cursor);
2361
+ if (element) {
2362
+ scrollIntoView(scrollerRef.current, element);
2363
+ }
2364
+ }
2365
+ break;
2366
+ }
2367
+ case "Backspace": {
2368
+ if (cursor) {
2369
+ if (range) {
2370
+ model.clear(range);
2371
+ } else {
2372
+ model.setValue(cursor, null);
2373
+ }
2374
+ }
2375
+ break;
2376
+ }
2377
+ case "Escape": {
2378
+ setRange(void 0);
2379
+ break;
2380
+ }
2381
+ case "Enter": {
2382
+ ev.stopPropagation();
2383
+ if (cursor) {
2384
+ setEditing(true);
2385
+ }
2386
+ break;
2387
+ }
2388
+ case "?": {
2389
+ onInfo?.();
2390
+ break;
2391
+ }
2392
+ default: {
2393
+ if (ev.key.length === 1) {
2394
+ initialText.current = ev.key;
2395
+ quickEdit.current = true;
2396
+ setEditing(true);
2397
+ }
2398
+ }
2399
+ }
2400
+ };
2401
+ const { handlers } = useRangeSelect((event, range2) => {
2402
+ switch (event) {
2403
+ case "start": {
2404
+ setRange(void 0);
2405
+ break;
2406
+ }
2407
+ default: {
2408
+ setRange(range2);
2409
+ }
2410
+ }
2411
+ });
2412
+ const { width, height, rowRange, columnRange } = useGridLayout({
2413
+ scroller: scrollerRef.current,
2414
+ size: {
2415
+ width: containerWidth,
2416
+ height: containerHeight
2417
+ },
2418
+ rows,
2419
+ columns,
2420
+ rowSizes,
2421
+ columnSizes
2422
+ });
2423
+ const id = fullyQualifiedId2(model.sheet);
2424
+ const attendableAttrs = createAttendableAttributes(id);
2425
+ const hasAttention = useHasAttention(id);
2426
+ return /* @__PURE__ */ React6.createElement("div", {
2427
+ ref: containerRef,
2428
+ role: "grid",
2429
+ className: "relative flex grow overflow-hidden"
2430
+ }, /* @__PURE__ */ React6.createElement("div", {
2431
+ className: mx2("z-20 absolute inset-0 border border-gridLine pointer-events-none")
2432
+ }), /* @__PURE__ */ React6.createElement("div", {
2433
+ ref: scrollerRef,
2434
+ className: mx2("grow", hasAttention && "overflow-auto scrollbar-thin")
2435
+ }, /* @__PURE__ */ React6.createElement("div", {
2436
+ className: "relative select-none",
2437
+ style: {
2438
+ width,
2439
+ height
2440
+ },
2441
+ onClick: () => inputRef.current?.focus(),
2442
+ ...handlers
2443
+ }, scrollerRef.current && /* @__PURE__ */ React6.createElement(SelectionOverlay, {
2444
+ root: scrollerRef.current
2445
+ }), rowRange.map(({ row, top, height: height2 }) => {
2446
+ return columnRange.map(({ col, left, width: width2 }) => {
2447
+ const style = {
2448
+ position: "absolute",
2449
+ top,
2450
+ left,
2451
+ width: width2,
2452
+ height: height2
2453
+ };
2454
+ const cell = {
2455
+ row,
2456
+ col
2457
+ };
2458
+ const id2 = addressToA1Notation(cell);
2459
+ const idx = addressToIndex(model.sheet, cell);
2460
+ const active = posEquals(cursor, cell);
2461
+ if (active && editing) {
2462
+ const value = initialText.current ?? model.getCellText(cell) ?? "";
2463
+ const handleClose = (value2) => {
2464
+ initialText.current = void 0;
2465
+ quickEdit.current = false;
2466
+ if (value2 !== void 0) {
2467
+ model.setValue(cell, value2);
2468
+ const next = handleArrowNav({
2469
+ key: "ArrowDown",
2470
+ metaKey: false
2471
+ }, cursor, size);
2472
+ if (next) {
2473
+ setCursor(next);
2474
+ }
2475
+ }
2476
+ inputRef.current?.focus();
2477
+ setEditing(false);
2478
+ };
2479
+ const handleNav2 = (value2, { key }) => {
2480
+ initialText.current = void 0;
2481
+ model.setValue(cell, value2 ?? null);
2482
+ const next = handleArrowNav({
2483
+ key,
2484
+ metaKey: false
2485
+ }, cursor, size);
2486
+ if (next) {
2487
+ setCursor(next);
2488
+ }
2489
+ inputRef.current?.focus();
2490
+ setEditing(false);
2491
+ };
2492
+ return /* @__PURE__ */ React6.createElement(GridCellEditor, {
2493
+ key: idx,
2494
+ value,
2495
+ style,
2496
+ onNav: quickEdit.current ? handleNav2 : void 0,
2497
+ onClose: handleClose
2498
+ });
2499
+ }
2500
+ return /* @__PURE__ */ React6.createElement(SheetCell, {
2501
+ key: id2,
2502
+ id: id2,
2503
+ cell,
2504
+ active,
2505
+ style,
2506
+ onSelect: (cell2, edit) => {
2507
+ setEditing(edit);
2508
+ setCursor(cell2);
2509
+ }
2510
+ });
2511
+ });
2512
+ }))), /* @__PURE__ */ createPortal(/* @__PURE__ */ React6.createElement("input", {
2513
+ ref: inputRef,
2514
+ autoFocus: true,
2515
+ className: "absolute w-[1px] h-[1px] bg-transparent outline-none border-none caret-transparent",
2516
+ onKeyDown: handleKeyDown,
2517
+ ...attendableAttrs
2518
+ }), document.body));
2519
+ });
2520
+ var SelectionOverlay = ({ root }) => {
2521
+ const { range } = useSheetContext();
2522
+ if (!range) {
2523
+ return null;
2524
+ }
2525
+ const c1 = getCellElement(root, range.from);
2526
+ const c2 = range.to ? getCellElement(root, range.to) : c1;
2527
+ if (!c1 || !c2) {
2528
+ return null;
2529
+ }
2530
+ const b1 = getRelativeClientRect(root, c1);
2531
+ const b2 = getRelativeClientRect(root, c2);
2532
+ const bounds = getRectUnion(b1, b2);
2533
+ return /* @__PURE__ */ React6.createElement("div", {
2534
+ role: "none",
2535
+ style: bounds,
2536
+ className: "z-10 absolute pointer-events-none bg-gridSelectionOverlay border border-gridOverlay"
2537
+ });
2538
+ };
2539
+ var SheetCell = ({ id, cell, style, active, onSelect }) => {
2540
+ const { formatting, editing, setRange, decorations, model: { sheet } } = useSheetContext();
2541
+ const { value, classNames } = formatting.getFormatting(cell);
2542
+ const decorationsForCell = decorations.getDecorationsForCell(addressToIndex(sheet, cell)) ?? [];
2543
+ const decorationAddedClasses = useMemo4(() => decorationsForCell.flatMap((d) => d.classNames ?? []), [
2544
+ decorationsForCell
2545
+ ]);
2546
+ const decoratedContent = decorationsForCell.reduce((children, { decorate }) => {
2547
+ if (!decorate) {
2548
+ return children;
2549
+ }
2550
+ const DecoratorComponent = decorate;
2551
+ return /* @__PURE__ */ React6.createElement(DecoratorComponent, null, children);
2552
+ }, /* @__PURE__ */ React6.createElement("div", {
2553
+ role: "none",
2554
+ className: mx2("flex flex-grow bs-full is-full px-2 items-center truncate cursor-pointer", ...decorationAddedClasses)
2555
+ }, value));
2556
+ return /* @__PURE__ */ React6.createElement("div", {
2557
+ [`data-${CELL_DATA_KEY}`]: id,
2558
+ role: "cell",
2559
+ style,
2560
+ className: mx2("border border-gridLine cursor-pointer", fragments.cell, active && [
2561
+ "z-20",
2562
+ fragments.cellSelected
2563
+ ], classNames),
2564
+ onClick: () => {
2565
+ if (editing) {
2566
+ setRange?.({
2567
+ from: cell
2568
+ });
2569
+ } else {
2570
+ onSelect?.(cell, false);
2571
+ }
2572
+ },
2573
+ onDoubleClick: () => onSelect?.(cell, true)
2574
+ }, decoratedContent);
2575
+ };
2576
+ var GridCellEditor = ({ style, value, onNav, onClose }) => {
2577
+ const { model, range } = useSheetContext();
2578
+ const notifier = useRef();
2579
+ useEffect4(() => {
2580
+ if (range) {
2581
+ notifier.current?.(rangeToA1Notation(range));
2582
+ }
2583
+ }, [
2584
+ range
2585
+ ]);
2586
+ const extension = useMemo4(() => [
2587
+ editorKeys({
2588
+ onNav,
2589
+ onClose
2590
+ }),
2591
+ sheetExtension({
2592
+ functions: model.graph.getFunctions()
2593
+ }),
2594
+ rangeExtension((fn) => notifier.current = fn)
2595
+ ], [
2596
+ model
2597
+ ]);
2598
+ return /* @__PURE__ */ React6.createElement("div", {
2599
+ role: "cell",
2600
+ style,
2601
+ className: mx2("z-20 flex", fragments.cellSelected),
2602
+ onClick: (ev) => ev.stopPropagation()
2603
+ }, /* @__PURE__ */ React6.createElement(CellEditor, {
2604
+ autoFocus: true,
2605
+ value,
2606
+ extension
2607
+ }));
2608
+ };
2609
+ var SheetStatusBar = () => {
2610
+ const { model, cursor, range } = useSheetContext();
2611
+ let value;
2612
+ let isFormula = false;
2613
+ if (cursor) {
2614
+ value = model.getCellValue(cursor);
2615
+ if (typeof value === "string" && value.charAt(0) === "=") {
2616
+ value = model.graph.mapFunctionBindingFromId(model.mapFormulaIndicesToRefs(value));
2617
+ isFormula = true;
2618
+ } else if (value != null) {
2619
+ value = String(value);
2620
+ }
2621
+ }
2622
+ return /* @__PURE__ */ React6.createElement("div", {
2623
+ className: mx2("flex shrink-0 justify-between items-center px-4 py-1 text-sm border-x border-gridLine")
2624
+ }, /* @__PURE__ */ React6.createElement("div", {
2625
+ className: "flex gap-4 items-center"
2626
+ }, /* @__PURE__ */ React6.createElement("div", {
2627
+ className: "flex w-16 items-center font-mono"
2628
+ }, range && rangeToA1Notation(range) || cursor && addressToA1Notation(cursor)), /* @__PURE__ */ React6.createElement("div", {
2629
+ className: "flex gap-2 items-center"
2630
+ }, /* @__PURE__ */ React6.createElement(FunctionIcon, {
2631
+ className: mx2("text-greenText", isFormula ? "visible" : "invisible")
2632
+ }), /* @__PURE__ */ React6.createElement("span", {
2633
+ className: "font-mono"
2634
+ }, value))));
2635
+ };
2636
+ var SheetDebug = () => {
2637
+ const { model, cursor, range } = useSheetContext();
2638
+ const [, forceUpdate] = useState5({});
2639
+ useEffect4(() => {
2640
+ const accessor = createDocAccessor(model.sheet, []);
2641
+ const handleUpdate = () => forceUpdate({});
2642
+ accessor.handle.addListener("change", handleUpdate);
2643
+ handleUpdate();
2644
+ return () => {
2645
+ accessor.handle.removeListener("change", handleUpdate);
2646
+ };
2647
+ }, [
2648
+ model
2649
+ ]);
2650
+ return /* @__PURE__ */ React6.createElement("div", {
2651
+ 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")
2652
+ }, /* @__PURE__ */ React6.createElement("pre", {
2653
+ className: "whitespace-pre-wrap"
2654
+ }, JSON.stringify({
2655
+ cursor,
2656
+ range,
2657
+ cells: model.sheet.cells,
2658
+ rowMeta: model.sheet.rowMeta,
2659
+ columnMeta: model.sheet.columnMeta,
2660
+ formatting: model.sheet.formatting
2661
+ }, void 0, 2)));
2662
+ };
2663
+ var Sheet = {
2664
+ Root: SheetRoot,
2665
+ Main: SheetMain,
2666
+ Rows: SheetRows,
2667
+ Columns: SheetColumns,
2668
+ Grid: SheetGrid,
2669
+ Cell: SheetCell,
2670
+ StatusBar: SheetStatusBar,
2671
+ Debug: SheetDebug
2672
+ };
2673
+
2674
+ export {
2675
+ ComputeGraphContextProvider,
2676
+ createSheet,
2677
+ addressToIndex,
2678
+ compareIndexPositions,
2679
+ useComputeGraph,
2680
+ useSheetContext,
2681
+ Sheet,
2682
+ SheetContainer
2683
+ };
2684
+ //# sourceMappingURL=chunk-5RLTCIE2.mjs.map