@dxos/plugin-sheet 0.6.14-main.7bd9c89 → 0.6.14-staging.0f558a0

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