@dxos/plugin-sheet 0.6.12-main.15a606f → 0.6.12-main.2d19bf1

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