@dxos/plugin-sheet 0.6.14-main.7bd9c89 → 0.6.14-staging.027949b

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 (232) hide show
  1. package/dist/lib/browser/{SheetContainer-AKWROARP.mjs → SheetContainer-P3NF5KEI.mjs} +90 -88
  2. package/dist/lib/browser/SheetContainer-P3NF5KEI.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-FGMFOW6U.mjs → chunk-4LKIURJA.mjs} +917 -817
  4. package/dist/lib/browser/chunk-4LKIURJA.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-BWN5DZWZ.mjs → chunk-BVUN7SHF.mjs} +6 -13
  6. package/dist/lib/browser/chunk-BVUN7SHF.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-D3QTX46O.mjs → chunk-RABELMEQ.mjs} +3 -2
  8. package/dist/lib/browser/{chunk-D3QTX46O.mjs.map → chunk-RABELMEQ.mjs.map} +3 -3
  9. package/dist/lib/browser/{chunk-GSV5QNLD.mjs → chunk-VMSX6Z4X.mjs} +297 -44
  10. package/dist/lib/browser/chunk-VMSX6Z4X.mjs.map +7 -0
  11. package/dist/lib/browser/{graph-M4IQ76QX.mjs → compute-graph-GGWUX644.mjs} +4 -2
  12. package/dist/lib/browser/index.mjs +91 -21
  13. package/dist/lib/browser/index.mjs.map +4 -4
  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 +2 -2
  17. package/dist/lib/node/{SheetContainer-N5IQGEFL.cjs → SheetContainer-MPFKXY26.cjs} +88 -93
  18. package/dist/lib/node/SheetContainer-MPFKXY26.cjs.map +7 -0
  19. package/dist/lib/node/{chunk-QIFIGEKV.cjs → chunk-2ZVZI2KJ.cjs} +6 -5
  20. package/dist/lib/node/{chunk-QIFIGEKV.cjs.map → chunk-2ZVZI2KJ.cjs.map} +3 -3
  21. package/dist/lib/node/{chunk-NZARD7UP.cjs → chunk-AWKOWDMI.cjs} +10 -17
  22. package/dist/lib/node/chunk-AWKOWDMI.cjs.map +7 -0
  23. package/dist/lib/node/{chunk-5XPK2V4A.cjs → chunk-O7XR4R7Y.cjs} +306 -42
  24. package/dist/lib/node/chunk-O7XR4R7Y.cjs.map +7 -0
  25. package/dist/lib/node/{chunk-53BMSUIK.cjs → chunk-OO24XJBV.cjs} +853 -767
  26. package/dist/lib/node/chunk-OO24XJBV.cjs.map +7 -0
  27. package/dist/lib/node/{graph-Q3N2X26H.cjs → compute-graph-KGWA2QLE.cjs} +21 -19
  28. package/dist/lib/node/compute-graph-KGWA2QLE.cjs.map +7 -0
  29. package/dist/lib/node/index.cjs +109 -42
  30. package/dist/lib/node/index.cjs.map +4 -4
  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 +7 -7
  35. package/dist/lib/node/types.cjs.map +1 -1
  36. package/dist/lib/node-esm/{SheetContainer-46PBMF2E.mjs → SheetContainer-22IOAW3B.mjs} +90 -88
  37. package/dist/lib/node-esm/SheetContainer-22IOAW3B.mjs.map +7 -0
  38. package/dist/lib/node-esm/{chunk-VCYJWE3O.mjs → chunk-BM2Q3FFC.mjs} +3 -2
  39. package/dist/lib/node-esm/{chunk-VCYJWE3O.mjs.map → chunk-BM2Q3FFC.mjs.map} +3 -3
  40. package/dist/lib/node-esm/{chunk-T3PRH7QS.mjs → chunk-BW36PM2Y.mjs} +917 -817
  41. package/dist/lib/node-esm/chunk-BW36PM2Y.mjs.map +7 -0
  42. package/dist/lib/node-esm/{chunk-5WPZCXNS.mjs → chunk-CR4K75EL.mjs} +296 -44
  43. package/dist/lib/node-esm/chunk-CR4K75EL.mjs.map +7 -0
  44. package/dist/lib/node-esm/{chunk-WFDTY3IC.mjs → chunk-UIBWRHW7.mjs} +6 -13
  45. package/dist/lib/node-esm/chunk-UIBWRHW7.mjs.map +7 -0
  46. package/dist/lib/node-esm/{graph-SMPUMOV2.mjs → compute-graph-2SCZT7N5.mjs} +4 -2
  47. package/dist/lib/node-esm/index.mjs +91 -21
  48. package/dist/lib/node-esm/index.mjs.map +4 -4
  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 +2 -2
  52. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  53. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +3 -1
  54. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -1
  55. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -1
  56. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  57. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  58. package/dist/types/src/components/GridSheet/util.d.ts +2 -2
  59. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  60. package/dist/types/src/components/RangeList/RangeList.d.ts +7 -0
  61. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -0
  62. package/dist/types/src/components/RangeList/index.d.ts +2 -0
  63. package/dist/types/src/components/RangeList/index.d.ts.map +1 -0
  64. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +6 -3
  65. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
  66. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
  67. package/dist/types/src/components/SheetContext/SheetContext.d.ts +7 -5
  68. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
  69. package/dist/types/src/components/Toolbar/Toolbar.d.ts +6 -3
  70. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  71. package/dist/types/src/components/index.d.ts +5 -2
  72. package/dist/types/src/components/index.d.ts.map +1 -1
  73. package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +1 -0
  74. package/dist/types/src/{graph → compute-graph}/compute-graph.d.ts +3 -3
  75. package/dist/types/src/compute-graph/compute-graph.d.ts.map +1 -0
  76. package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +1 -0
  77. package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +1 -0
  78. package/dist/types/src/compute-graph/compute-node.d.ts.map +1 -0
  79. package/dist/types/src/compute-graph/functions/async-function.d.ts.map +1 -0
  80. package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +1 -0
  81. package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +1 -0
  82. package/dist/types/src/compute-graph/functions/index.d.ts.map +1 -0
  83. package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +1 -0
  84. package/dist/types/src/compute-graph/index.d.ts.map +1 -0
  85. package/dist/types/src/compute-graph/testing/index.d.ts.map +1 -0
  86. package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +1 -0
  87. package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +1 -0
  88. package/dist/types/src/compute-graph/util.d.ts.map +1 -0
  89. package/dist/types/src/defs/index.d.ts +1 -1
  90. package/dist/types/src/defs/index.d.ts.map +1 -1
  91. package/dist/types/src/defs/sheet-range-types.d.ts +2 -2
  92. package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -1
  93. package/dist/types/src/defs/types.d.ts +6 -0
  94. package/dist/types/src/defs/types.d.ts.map +1 -1
  95. package/dist/types/src/defs/util.d.ts +3 -7
  96. package/dist/types/src/defs/util.d.ts.map +1 -1
  97. package/dist/types/src/extensions/compute.d.ts +1 -1
  98. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  99. package/dist/types/src/extensions/editor/extension.d.ts +23 -3
  100. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -1
  101. package/dist/types/src/index.d.ts +1 -1
  102. package/dist/types/src/index.d.ts.map +1 -1
  103. package/dist/types/src/integrations/index.d.ts +2 -0
  104. package/dist/types/src/integrations/index.d.ts.map +1 -0
  105. package/dist/types/src/integrations/thread-ranges.d.ts +7 -0
  106. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -0
  107. package/dist/types/src/meta.d.ts +1 -0
  108. package/dist/types/src/meta.d.ts.map +1 -1
  109. package/dist/types/src/model/index.d.ts +1 -1
  110. package/dist/types/src/model/index.d.ts.map +1 -1
  111. package/dist/types/src/model/sheet-model.d.ts +13 -6
  112. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  113. package/dist/types/src/{hooks → model}/useSheetModel.d.ts +1 -1
  114. package/dist/types/src/model/useSheetModel.d.ts.map +1 -0
  115. package/dist/types/src/serializer.d.ts +4 -0
  116. package/dist/types/src/serializer.d.ts.map +1 -0
  117. package/dist/types/src/testing/testing.d.ts +1 -1
  118. package/dist/types/src/testing/testing.d.ts.map +1 -1
  119. package/dist/types/src/translations.d.ts +18 -3
  120. package/dist/types/src/translations.d.ts.map +1 -1
  121. package/dist/types/src/types.d.ts +37 -33
  122. package/dist/types/src/types.d.ts.map +1 -1
  123. package/package.json +44 -50
  124. package/src/SheetPlugin.tsx +45 -12
  125. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +19 -2
  126. package/src/components/FunctionEditor/FunctionEditor.tsx +6 -10
  127. package/src/components/GridSheet/GridSheet.stories.tsx +3 -1
  128. package/src/components/GridSheet/GridSheet.tsx +196 -36
  129. package/src/components/GridSheet/SheetCellEditor.stories.tsx +1 -1
  130. package/src/components/GridSheet/util.ts +41 -21
  131. package/src/components/RangeList/RangeList.tsx +53 -0
  132. package/src/components/RangeList/index.ts +5 -0
  133. package/src/components/SheetContainer/SheetContainer.stories.tsx +5 -3
  134. package/src/components/SheetContainer/SheetContainer.tsx +19 -12
  135. package/src/components/SheetContext/SheetContext.tsx +43 -20
  136. package/src/components/Toolbar/Toolbar.tsx +98 -86
  137. package/src/components/index.ts +1 -0
  138. package/src/{graph → compute-graph}/compute-graph.stories.tsx +2 -1
  139. package/src/{graph → compute-graph}/compute-graph.ts +27 -9
  140. package/src/{graph → compute-graph}/compute-node.ts +2 -3
  141. package/src/{graph → compute-graph}/functions/async-function.ts +1 -0
  142. package/src/{graph → compute-graph}/functions/edge-function.ts +5 -3
  143. package/src/defs/index.ts +1 -1
  144. package/src/defs/sheet-range-types.ts +9 -6
  145. package/src/defs/types.ts +6 -1
  146. package/src/defs/util.ts +4 -19
  147. package/src/extensions/compute.stories.tsx +2 -2
  148. package/src/extensions/compute.ts +2 -2
  149. package/src/extensions/editor/extension.test.ts +1 -1
  150. package/src/extensions/editor/extension.ts +48 -23
  151. package/src/index.ts +2 -2
  152. package/src/integrations/index.ts +5 -0
  153. package/src/integrations/thread-ranges.ts +101 -0
  154. package/src/meta.ts +1 -0
  155. package/src/model/index.ts +1 -1
  156. package/src/model/sheet-model.test.ts +6 -4
  157. package/src/model/sheet-model.ts +103 -26
  158. package/src/{hooks → model}/useSheetModel.ts +1 -1
  159. package/src/serializer.ts +27 -0
  160. package/src/testing/testing.tsx +1 -1
  161. package/src/translations.ts +18 -3
  162. package/src/types.ts +24 -2
  163. package/dist/lib/browser/SheetContainer-AKWROARP.mjs.map +0 -7
  164. package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +0 -7
  165. package/dist/lib/browser/chunk-FGMFOW6U.mjs.map +0 -7
  166. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +0 -7
  167. package/dist/lib/node/SheetContainer-N5IQGEFL.cjs.map +0 -7
  168. package/dist/lib/node/chunk-53BMSUIK.cjs.map +0 -7
  169. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +0 -7
  170. package/dist/lib/node/chunk-NZARD7UP.cjs.map +0 -7
  171. package/dist/lib/node/graph-Q3N2X26H.cjs.map +0 -7
  172. package/dist/lib/node-esm/SheetContainer-46PBMF2E.mjs.map +0 -7
  173. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +0 -7
  174. package/dist/lib/node-esm/chunk-T3PRH7QS.mjs.map +0 -7
  175. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +0 -7
  176. package/dist/types/src/graph/compute-graph-registry.d.ts.map +0 -1
  177. package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
  178. package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
  179. package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
  180. package/dist/types/src/graph/compute-node.d.ts.map +0 -1
  181. package/dist/types/src/graph/functions/async-function.d.ts.map +0 -1
  182. package/dist/types/src/graph/functions/edge-function.d.ts.map +0 -1
  183. package/dist/types/src/graph/functions/function-defs.d.ts.map +0 -1
  184. package/dist/types/src/graph/functions/index.d.ts.map +0 -1
  185. package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
  186. package/dist/types/src/graph/index.d.ts.map +0 -1
  187. package/dist/types/src/graph/testing/index.d.ts.map +0 -1
  188. package/dist/types/src/graph/testing/test-builder.d.ts.map +0 -1
  189. package/dist/types/src/graph/testing/test-plugin.d.ts.map +0 -1
  190. package/dist/types/src/graph/util.d.ts.map +0 -1
  191. package/dist/types/src/hooks/hooks.stories.d.ts +0 -6
  192. package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
  193. package/dist/types/src/hooks/index.d.ts +0 -4
  194. package/dist/types/src/hooks/index.d.ts.map +0 -1
  195. package/dist/types/src/hooks/threads.d.ts +0 -8
  196. package/dist/types/src/hooks/threads.d.ts.map +0 -1
  197. package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
  198. package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
  199. package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
  200. package/dist/types/src/model/decorations.d.ts +0 -26
  201. package/dist/types/src/model/decorations.d.ts.map +0 -1
  202. package/src/hooks/hooks.stories.tsx +0 -53
  203. package/src/hooks/index.ts +0 -7
  204. package/src/hooks/threads.ts +0 -147
  205. package/src/hooks/useComputeGraph.ts +0 -28
  206. package/src/model/decorations.ts +0 -66
  207. /package/dist/lib/browser/{graph-M4IQ76QX.mjs.map → compute-graph-GGWUX644.mjs.map} +0 -0
  208. /package/dist/lib/node-esm/{graph-SMPUMOV2.mjs.map → compute-graph-2SCZT7N5.mjs.map} +0 -0
  209. /package/dist/types/src/{graph → compute-graph}/compute-graph-registry.d.ts +0 -0
  210. /package/dist/types/src/{graph → compute-graph}/compute-graph.stories.d.ts +0 -0
  211. /package/dist/types/src/{graph → compute-graph}/compute-graph.test.d.ts +0 -0
  212. /package/dist/types/src/{graph → compute-graph}/compute-node.d.ts +0 -0
  213. /package/dist/types/src/{graph → compute-graph}/functions/async-function.d.ts +0 -0
  214. /package/dist/types/src/{graph → compute-graph}/functions/edge-function.d.ts +0 -0
  215. /package/dist/types/src/{graph → compute-graph}/functions/function-defs.d.ts +0 -0
  216. /package/dist/types/src/{graph → compute-graph}/functions/index.d.ts +0 -0
  217. /package/dist/types/src/{graph → compute-graph}/hyperformula.test.d.ts +0 -0
  218. /package/dist/types/src/{graph → compute-graph}/index.d.ts +0 -0
  219. /package/dist/types/src/{graph → compute-graph}/testing/index.d.ts +0 -0
  220. /package/dist/types/src/{graph → compute-graph}/testing/test-builder.d.ts +0 -0
  221. /package/dist/types/src/{graph → compute-graph}/testing/test-plugin.d.ts +0 -0
  222. /package/dist/types/src/{graph → compute-graph}/util.d.ts +0 -0
  223. /package/src/{graph → compute-graph}/compute-graph-registry.ts +0 -0
  224. /package/src/{graph → compute-graph}/compute-graph.test.ts +0 -0
  225. /package/src/{graph → compute-graph}/functions/function-defs.ts +0 -0
  226. /package/src/{graph → compute-graph}/functions/index.ts +0 -0
  227. /package/src/{graph → compute-graph}/hyperformula.test.ts +0 -0
  228. /package/src/{graph → compute-graph}/index.ts +0 -0
  229. /package/src/{graph → compute-graph}/testing/index.ts +0 -0
  230. /package/src/{graph → compute-graph}/testing/test-builder.ts +0 -0
  231. /package/src/{graph → compute-graph}/testing/test-plugin.ts +0 -0
  232. /package/src/{graph → compute-graph}/util.ts +0 -0
@@ -1,19 +1,221 @@
1
- // packages/plugins/plugin-sheet/src/graph/compute-graph.ts
1
+ import {
2
+ SheetType
3
+ } from "./chunk-BVUN7SHF.mjs";
4
+
5
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-graph.ts
2
6
  import { Event as Event2 } from "@dxos/async";
3
7
  import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
8
+ import { FQ_ID_LENGTH } from "@dxos/client/echo";
4
9
  import { Resource as Resource2 } from "@dxos/context";
5
10
  import { getTypename } from "@dxos/echo-schema";
6
- import { invariant } from "@dxos/invariant";
11
+ import { invariant as invariant2 } from "@dxos/invariant";
7
12
  import { PublicKey } from "@dxos/keys";
8
13
  import { log as log3 } from "@dxos/log";
9
14
  import { FunctionType as FunctionType2 } from "@dxos/plugin-script/types";
10
15
  import { nonNullable as nonNullable2 } from "@dxos/util";
11
16
  import { ExportedCellChange } from "#hyperformula";
12
17
 
13
- // packages/plugins/plugin-sheet/src/graph/compute-node.ts
18
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-node.ts
14
19
  import { Event } from "@dxos/async";
15
20
  import { Resource } from "@dxos/context";
16
21
  import { DetailedCellError } from "#hyperformula";
22
+
23
+ // packages/plugins/plugin-sheet/src/defs/sheet-range-types.ts
24
+ var alignKey = "alignment";
25
+ var commentKey = "comment";
26
+ var styleKey = "style";
27
+ var cellClassNameForRange = ({ key, value }) => {
28
+ switch (key) {
29
+ case alignKey:
30
+ switch (value) {
31
+ case "start":
32
+ return "text-start";
33
+ case "center":
34
+ return "text-center";
35
+ case "end":
36
+ return "text-end";
37
+ default:
38
+ return void 0;
39
+ }
40
+ case commentKey:
41
+ return "bg-gridComment";
42
+ case styleKey:
43
+ switch (value) {
44
+ case "highlight":
45
+ return "!bg-gridHighlight";
46
+ case "softwrap":
47
+ return "!whitespace-normal";
48
+ default:
49
+ return void 0;
50
+ }
51
+ default:
52
+ return void 0;
53
+ }
54
+ };
55
+
56
+ // packages/plugins/plugin-sheet/src/defs/types.ts
57
+ import { invariant } from "@dxos/invariant";
58
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/defs/types.ts";
59
+ var DEFAULT_ROWS = 50;
60
+ var DEFAULT_COLUMNS = 26;
61
+ var MAX_ROWS = 500;
62
+ var MAX_COLUMNS = 26 * 2;
63
+ var RANGE_NOTATION = /^[A-Z]+[0-9]+(:[A-Z]+[0-9]+)?$/;
64
+ var isFormula = (value) => typeof value === "string" && value.charAt(0) === "=";
65
+ var posEquals = (a, b) => {
66
+ return a?.col === b?.col && a?.row === b?.row;
67
+ };
68
+ var columnLetter = (col) => {
69
+ invariant(col < MAX_COLUMNS, `Invalid column: ${col}`, {
70
+ F: __dxlog_file,
71
+ L: 31,
72
+ S: void 0,
73
+ A: [
74
+ "col < MAX_COLUMNS",
75
+ "`Invalid column: ${col}`"
76
+ ]
77
+ });
78
+ return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
79
+ };
80
+ var addressToA1Notation = ({ col, row }) => {
81
+ return `${columnLetter(col)}${row + 1}`;
82
+ };
83
+ var addressFromA1Notation = (ref) => {
84
+ const match = ref.match(/([A-Z]+)(\d+)/);
85
+ invariant(match, `Invalid notation: ${ref}`, {
86
+ F: __dxlog_file,
87
+ L: 45,
88
+ S: void 0,
89
+ A: [
90
+ "match",
91
+ "`Invalid notation: ${ref}`"
92
+ ]
93
+ });
94
+ return {
95
+ row: parseInt(match[2], 10) - 1,
96
+ col: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
97
+ };
98
+ };
99
+ var rangeToA1Notation = (range) => {
100
+ return [
101
+ range?.from && addressToA1Notation(range?.from),
102
+ range?.to && addressToA1Notation(range?.to)
103
+ ].filter(Boolean).join(":");
104
+ };
105
+ var inRange = (range, cell) => {
106
+ if (!range) {
107
+ return false;
108
+ }
109
+ const { from, to } = range;
110
+ if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
111
+ return true;
112
+ }
113
+ if (!from || !to) {
114
+ return false;
115
+ }
116
+ const { col: c1, row: r1 } = from;
117
+ const { col: c2, row: r2 } = to;
118
+ const cMin = Math.min(c1, c2);
119
+ const cMax = Math.max(c1, c2);
120
+ const rMin = Math.min(r1, r2);
121
+ const rMax = Math.max(r1, r2);
122
+ const { col, row } = cell;
123
+ return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
124
+ };
125
+
126
+ // packages/plugins/plugin-sheet/src/defs/util.ts
127
+ import { randomBytes } from "@dxos/crypto";
128
+ import { create } from "@dxos/echo-schema";
129
+ var ApiError = class extends Error {
130
+ };
131
+ var ReadonlyException = class extends ApiError {
132
+ };
133
+ var RangeException = class extends ApiError {
134
+ constructor(n) {
135
+ super();
136
+ }
137
+ };
138
+ var createIndex = (length = 8) => {
139
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
140
+ const charactersLength = characters.length;
141
+ const randomBuffer = randomBytes(length);
142
+ return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
143
+ };
144
+ var createIndices = (length) => Array.from({
145
+ length
146
+ }).map(() => createIndex());
147
+ var insertIndices = (indices, i, n, max) => {
148
+ if (i + n > max) {
149
+ throw new RangeException(i + n);
150
+ }
151
+ const idx = createIndices(n);
152
+ indices.splice(i, 0, ...idx);
153
+ return idx;
154
+ };
155
+ var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}) => {
156
+ if (!sheet.rows.length) {
157
+ insertIndices(sheet.rows, 0, rows, MAX_ROWS);
158
+ }
159
+ if (!sheet.columns.length) {
160
+ insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
161
+ }
162
+ };
163
+ var createSheet = ({ name, cells, ...size } = {}) => {
164
+ const sheet = create(SheetType, {
165
+ name,
166
+ cells: {},
167
+ rows: [],
168
+ columns: [],
169
+ rowMeta: {},
170
+ columnMeta: {},
171
+ ranges: [],
172
+ threads: []
173
+ });
174
+ initialize(sheet, size);
175
+ if (cells) {
176
+ Object.entries(cells).forEach(([key, { value }]) => {
177
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
178
+ sheet.cells[idx] = {
179
+ value
180
+ };
181
+ });
182
+ }
183
+ return sheet;
184
+ };
185
+ var addressToIndex = (sheet, cell) => {
186
+ return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
187
+ };
188
+ var addressFromIndex = (sheet, idx) => {
189
+ const [column, row] = idx.split("@");
190
+ return {
191
+ col: sheet.columns.indexOf(column),
192
+ row: sheet.rows.indexOf(row)
193
+ };
194
+ };
195
+ var rangeToIndex = (sheet, range) => {
196
+ return [
197
+ range.from,
198
+ range.to ?? range.from
199
+ ].map((cell) => addressToIndex(sheet, cell)).join(":");
200
+ };
201
+ var rangeFromIndex = (sheet, idx) => {
202
+ const [from, to] = idx.split(":").map((index) => addressFromIndex(sheet, index));
203
+ return {
204
+ from,
205
+ to
206
+ };
207
+ };
208
+ var compareIndexPositions = (sheet, indexA, indexB) => {
209
+ const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
210
+ const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
211
+ if (rowA !== rowB) {
212
+ return rowA - rowB;
213
+ } else {
214
+ return columnA - columnB;
215
+ }
216
+ };
217
+
218
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-node.ts
17
219
  var ComputeNode = class extends Resource {
18
220
  constructor(_graph, sheetId) {
19
221
  super();
@@ -39,7 +241,7 @@ var ComputeNode = class extends Resource {
39
241
  return value;
40
242
  }
41
243
  setValue(cell, value) {
42
- const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
244
+ const mappedValue = isFormula(value) ? this._graph.mapFormulaToNative(value) : value;
43
245
  this._graph.hf.setCellContents({
44
246
  sheet: this.sheetId,
45
247
  row: cell.row,
@@ -55,12 +257,12 @@ var ComputeNode = class extends Resource {
55
257
  }
56
258
  };
57
259
 
58
- // packages/plugins/plugin-sheet/src/graph/functions/async-function.ts
260
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/async-function.ts
59
261
  import defaultsDeep from "lodash.defaultsdeep";
60
262
  import { debounce } from "@dxos/async";
61
263
  import { log } from "@dxos/log";
62
264
  import { CellError, ErrorType, EmptyValue, FunctionPlugin } from "#hyperformula";
63
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/async-function.ts";
265
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/functions/async-function.ts";
64
266
  var defaultFunctionContextOptions = {
65
267
  defaultTtl: 5e3,
66
268
  debounceDelay: 200,
@@ -83,6 +285,12 @@ var FunctionContext = class _FunctionContext {
83
285
  this._invocations = {};
84
286
  this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
85
287
  this._onUpdate = debounce((update) => {
288
+ log("update", update, {
289
+ F: __dxlog_file2,
290
+ L: 86,
291
+ S: this,
292
+ C: (f, a) => f(...a)
293
+ });
86
294
  this._hf.resumeEvaluation();
87
295
  this._options.onUpdate?.(update);
88
296
  }, this._options.debounceDelay);
@@ -134,8 +342,8 @@ var FunctionContext = class _FunctionContext {
134
342
  cell,
135
343
  value: value2
136
344
  }, {
137
- F: __dxlog_file,
138
- L: 143,
345
+ F: __dxlog_file2,
346
+ L: 144,
139
347
  S: this,
140
348
  C: (f, a) => f(...a)
141
349
  });
@@ -148,8 +356,8 @@ var FunctionContext = class _FunctionContext {
148
356
  cell,
149
357
  err
150
358
  }, {
151
- F: __dxlog_file,
152
- L: 147,
359
+ F: __dxlog_file2,
360
+ L: 148,
153
361
  S: this,
154
362
  C: (f, a) => f(...a)
155
363
  });
@@ -168,8 +376,8 @@ var FunctionContext = class _FunctionContext {
168
376
  args,
169
377
  cache: value
170
378
  }, {
171
- F: __dxlog_file,
172
- L: 155,
379
+ F: __dxlog_file2,
380
+ L: 156,
173
381
  S: this,
174
382
  C: (f, a) => f(...a)
175
383
  });
@@ -192,7 +400,7 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
192
400
  }
193
401
  };
194
402
 
195
- // packages/plugins/plugin-sheet/src/graph/functions/edge-function.ts
403
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/edge-function.ts
196
404
  import { effect } from "@preact/signals-core";
197
405
  import { Filter, getMeta } from "@dxos/client/echo";
198
406
  import { log as log2 } from "@dxos/log";
@@ -200,7 +408,7 @@ import { getUserFunctionUrlInMetadata } from "@dxos/plugin-script/edge";
200
408
  import { FunctionType } from "@dxos/plugin-script/types";
201
409
  import { nonNullable } from "@dxos/util";
202
410
  import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "#hyperformula";
203
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/edge-function.ts";
411
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/functions/edge-function.ts";
204
412
  var EDGE_FUNCTION_NAME = "DX";
205
413
  var FUNCTION_TTL = 1e4;
206
414
  var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
@@ -217,7 +425,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
217
425
  log2.info("Function not found", {
218
426
  binding
219
427
  }, {
220
- F: __dxlog_file2,
428
+ F: __dxlog_file3,
221
429
  L: 41,
222
430
  S: this,
223
431
  C: (f, a) => f(...a)
@@ -226,10 +434,10 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
226
434
  }
227
435
  if (subscribe) {
228
436
  const unsubscribe = effect(() => {
229
- log2.info("function changed", {
437
+ log2("function changed", {
230
438
  fn
231
439
  }, {
232
- F: __dxlog_file2,
440
+ F: __dxlog_file3,
233
441
  L: 47,
234
442
  S: this,
235
443
  C: (f, a) => f(...a)
@@ -242,7 +450,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
242
450
  this.context.createSubscription(ast.procedureName, unsubscribe);
243
451
  }
244
452
  const path = getUserFunctionUrlInMetadata(getMeta(fn));
245
- const result = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
453
+ const response = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
246
454
  method: "POST",
247
455
  headers: {
248
456
  "Content-Type": "application/json"
@@ -251,7 +459,16 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
251
459
  args: args.filter(nonNullable)
252
460
  })
253
461
  });
254
- return await result.text();
462
+ const result = await response.text();
463
+ log2("function executed", {
464
+ result
465
+ }, {
466
+ F: __dxlog_file3,
467
+ L: 65,
468
+ S: this,
469
+ C: (f, a) => f(...a)
470
+ });
471
+ return result;
255
472
  };
256
473
  return this.runAsyncFunction(ast, state, handler(true), {
257
474
  ttl: FUNCTION_TTL
@@ -312,7 +529,7 @@ var EdgeFunctionPluginTranslations = {
312
529
  }
313
530
  };
314
531
 
315
- // packages/plugins/plugin-sheet/src/graph/functions/function-defs.ts
532
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/function-defs.ts
316
533
  var defaultFunctions = [
317
534
  // Array
318
535
  {
@@ -2686,9 +2903,9 @@ var defaultFunctions = [
2686
2903
  }
2687
2904
  ];
2688
2905
 
2689
- // packages/plugins/plugin-sheet/src/graph/compute-graph.ts
2690
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph.ts";
2691
- var OBJECT_ID_LENGTH = 60;
2906
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-graph.ts
2907
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/compute-graph.ts";
2908
+ var UNKNOWN_BINDING = "__UNKNOWN__";
2692
2909
  var createSheetName = ({ type, id }) => `${type}@${id}`;
2693
2910
  var parseSheetName = (name) => {
2694
2911
  const [type, id] = name.split("@");
@@ -2709,7 +2926,16 @@ var ComputeGraph = class extends Resource2 {
2709
2926
  this._nodes = /* @__PURE__ */ new Map();
2710
2927
  this._remoteFunctions = [];
2711
2928
  this.update = new Event2();
2712
- this.context = new FunctionContext(this._hf, this._space, this._options);
2929
+ const contextOptions = {
2930
+ ...this._options,
2931
+ onUpdate: (update) => {
2932
+ this._options?.onUpdate?.(update);
2933
+ this.update.emit({
2934
+ type: "valuesUpdated"
2935
+ });
2936
+ }
2937
+ };
2938
+ this.context = new FunctionContext(this._hf, this._space, contextOptions);
2713
2939
  this._hf.updateConfig({
2714
2940
  context: this.context
2715
2941
  });
@@ -2755,9 +2981,9 @@ var ComputeGraph = class extends Resource2 {
2755
2981
  // E.g., Cross-object reference would be stored as "ObjectId!A1"
2756
2982
  // The graph would then load the object and create a ComputeNode (model) of the appropriate type.
2757
2983
  getOrCreateNode(name) {
2758
- invariant(name.length, void 0, {
2759
- F: __dxlog_file3,
2760
- L: 117,
2984
+ invariant2(name.length, void 0, {
2985
+ F: __dxlog_file4,
2986
+ L: 129,
2761
2987
  S: this,
2762
2988
  A: [
2763
2989
  "name.length",
@@ -2765,21 +2991,21 @@ var ComputeGraph = class extends Resource2 {
2765
2991
  ]
2766
2992
  });
2767
2993
  if (!this._hf.doesSheetExist(name)) {
2768
- log3.info("created node", {
2994
+ log3("created node", {
2769
2995
  space: this._space?.id,
2770
2996
  sheet: name
2771
2997
  }, {
2772
- F: __dxlog_file3,
2773
- L: 119,
2998
+ F: __dxlog_file4,
2999
+ L: 131,
2774
3000
  S: this,
2775
3001
  C: (f, a) => f(...a)
2776
3002
  });
2777
3003
  this._hf.addSheet(name);
2778
3004
  }
2779
3005
  const sheetId = this._hf.getSheetId(name);
2780
- invariant(sheetId !== void 0, void 0, {
2781
- F: __dxlog_file3,
2782
- L: 124,
3006
+ invariant2(sheetId !== void 0, void 0, {
3007
+ F: __dxlog_file4,
3008
+ L: 136,
2783
3009
  S: this,
2784
3010
  A: [
2785
3011
  "sheetId !== undefined",
@@ -2792,7 +3018,7 @@ var ComputeGraph = class extends Resource2 {
2792
3018
  }
2793
3019
  /**
2794
3020
  * Map bound value to custom function invocation.
2795
- * E.g., "HELLO(...args)" => "EDGE("HELLO", ...args)".
3021
+ * E.g., "HELLO(...args)" => "DX("HELLO", ...args)".
2796
3022
  */
2797
3023
  mapFormulaToNative(formula) {
2798
3024
  return formula.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
@@ -2847,18 +3073,23 @@ var ComputeGraph = class extends Resource2 {
2847
3073
  * E.g., spaceId:objectId() => HELLO()
2848
3074
  */
2849
3075
  mapFunctionBindingFromId(formula) {
2850
- return formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
3076
+ const binding = formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
2851
3077
  const id = `${spaceId}:${objectId}`;
2852
- if (id.length !== OBJECT_ID_LENGTH) {
3078
+ if (id.length !== FQ_ID_LENGTH) {
2853
3079
  return match;
2854
3080
  }
2855
3081
  const fn = this._remoteFunctions.find((fn2) => fullyQualifiedId(fn2) === id);
2856
3082
  if (fn?.binding) {
2857
3083
  return `${fn.binding}(${args})`;
2858
3084
  } else {
2859
- return match;
3085
+ return UNKNOWN_BINDING;
2860
3086
  }
2861
3087
  });
3088
+ if (binding.startsWith(`=${UNKNOWN_BINDING}`)) {
3089
+ return void 0;
3090
+ } else {
3091
+ return binding;
3092
+ }
2862
3093
  }
2863
3094
  async _open() {
2864
3095
  if (this._space) {
@@ -2879,13 +3110,13 @@ var ComputeGraph = class extends Resource2 {
2879
3110
  }
2880
3111
  };
2881
3112
 
2882
- // packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts
3113
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-graph-registry.ts
2883
3114
  import defaultsDeep2 from "lodash.defaultsdeep";
2884
3115
  import { Resource as Resource3 } from "@dxos/context";
2885
- import { invariant as invariant2 } from "@dxos/invariant";
3116
+ import { invariant as invariant3 } from "@dxos/invariant";
2886
3117
  import { log as log4 } from "@dxos/log";
2887
3118
  import { HyperFormula } from "#hyperformula";
2888
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts";
3119
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/compute-graph-registry.ts";
2889
3120
  var defaultOptions = {
2890
3121
  licenseKey: "gpl-v3"
2891
3122
  };
@@ -2915,7 +3146,7 @@ var ComputeGraphRegistry = class extends Resource3 {
2915
3146
  log4("create graph", {
2916
3147
  space: space.id
2917
3148
  }, {
2918
- F: __dxlog_file4,
3149
+ F: __dxlog_file5,
2919
3150
  L: 69,
2920
3151
  S: this,
2921
3152
  C: (f, a) => f(...a)
@@ -2925,8 +3156,8 @@ var ComputeGraphRegistry = class extends Resource3 {
2925
3156
  return graph;
2926
3157
  }
2927
3158
  createGraph(space) {
2928
- invariant2(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
2929
- F: __dxlog_file4,
3159
+ invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
3160
+ F: __dxlog_file5,
2930
3161
  L: 77,
2931
3162
  S: this,
2932
3163
  A: [
@@ -2948,6 +3179,28 @@ var ComputeGraphRegistry = class extends Resource3 {
2948
3179
  };
2949
3180
 
2950
3181
  export {
3182
+ alignKey,
3183
+ styleKey,
3184
+ cellClassNameForRange,
3185
+ DEFAULT_ROWS,
3186
+ DEFAULT_COLUMNS,
3187
+ MAX_ROWS,
3188
+ MAX_COLUMNS,
3189
+ RANGE_NOTATION,
3190
+ isFormula,
3191
+ addressToA1Notation,
3192
+ addressFromA1Notation,
3193
+ rangeToA1Notation,
3194
+ inRange,
3195
+ ReadonlyException,
3196
+ insertIndices,
3197
+ initialize,
3198
+ createSheet,
3199
+ addressToIndex,
3200
+ addressFromIndex,
3201
+ rangeToIndex,
3202
+ rangeFromIndex,
3203
+ compareIndexPositions,
2951
3204
  ComputeNode,
2952
3205
  defaultFunctionContextOptions,
2953
3206
  FunctionContext,
@@ -2963,4 +3216,4 @@ export {
2963
3216
  defaultPlugins,
2964
3217
  ComputeGraphRegistry
2965
3218
  };
2966
- //# sourceMappingURL=chunk-GSV5QNLD.mjs.map
3219
+ //# sourceMappingURL=chunk-VMSX6Z4X.mjs.map