@dxos/plugin-sheet 0.6.14-main.7bd9c89 → 0.6.14-staging.9e90729

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 (208) hide show
  1. package/dist/lib/browser/{SheetContainer-AKWROARP.mjs → SheetContainer-JBB7W52Y.mjs} +42 -52
  2. package/dist/lib/browser/SheetContainer-JBB7W52Y.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-GSV5QNLD.mjs → chunk-2ZK3YMZG.mjs} +248 -33
  4. package/dist/lib/browser/{chunk-GSV5QNLD.mjs.map → chunk-2ZK3YMZG.mjs.map} +4 -4
  5. package/dist/lib/browser/{chunk-BWN5DZWZ.mjs → chunk-3QWIMZZJ.mjs} +2 -11
  6. package/dist/lib/browser/chunk-3QWIMZZJ.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-FGMFOW6U.mjs → chunk-XXDHBYZQ.mjs} +553 -668
  8. package/dist/lib/browser/chunk-XXDHBYZQ.mjs.map +7 -0
  9. package/dist/lib/browser/{graph-M4IQ76QX.mjs → compute-graph-ZQKB6QVP.mjs} +4 -2
  10. package/dist/lib/browser/index.mjs +57 -14
  11. package/dist/lib/browser/index.mjs.map +4 -4
  12. package/dist/lib/browser/meta.json +1 -1
  13. package/dist/lib/browser/types.mjs +1 -1
  14. package/dist/lib/node/{SheetContainer-N5IQGEFL.cjs → SheetContainer-L37HUFCF.cjs} +44 -58
  15. package/dist/lib/node/SheetContainer-L37HUFCF.cjs.map +7 -0
  16. package/dist/lib/node/{chunk-53BMSUIK.cjs → chunk-7AWAC3R3.cjs} +517 -645
  17. package/dist/lib/node/chunk-7AWAC3R3.cjs.map +7 -0
  18. package/dist/lib/node/{chunk-5XPK2V4A.cjs → chunk-QNFMTK3X.cjs} +252 -28
  19. package/dist/lib/node/{chunk-5XPK2V4A.cjs.map → chunk-QNFMTK3X.cjs.map} +4 -4
  20. package/dist/lib/node/{chunk-NZARD7UP.cjs → chunk-V7E5JZBD.cjs} +5 -14
  21. package/dist/lib/node/chunk-V7E5JZBD.cjs.map +7 -0
  22. package/dist/lib/node/{graph-Q3N2X26H.cjs → compute-graph-RJB6OVW6.cjs} +21 -19
  23. package/dist/lib/node/compute-graph-RJB6OVW6.cjs.map +7 -0
  24. package/dist/lib/node/index.cjs +66 -27
  25. package/dist/lib/node/index.cjs.map +4 -4
  26. package/dist/lib/node/meta.json +1 -1
  27. package/dist/lib/node/types.cjs +6 -6
  28. package/dist/lib/node/types.cjs.map +1 -1
  29. package/dist/lib/node-esm/{SheetContainer-46PBMF2E.mjs → SheetContainer-CLKFEM35.mjs} +42 -52
  30. package/dist/lib/node-esm/SheetContainer-CLKFEM35.mjs.map +7 -0
  31. package/dist/lib/node-esm/{chunk-T3PRH7QS.mjs → chunk-3JYJEOCF.mjs} +553 -668
  32. package/dist/lib/node-esm/chunk-3JYJEOCF.mjs.map +7 -0
  33. package/dist/lib/node-esm/{chunk-5WPZCXNS.mjs → chunk-JBTORSST.mjs} +247 -33
  34. package/dist/lib/node-esm/{chunk-5WPZCXNS.mjs.map → chunk-JBTORSST.mjs.map} +4 -4
  35. package/dist/lib/node-esm/{chunk-WFDTY3IC.mjs → chunk-SPQFLYC2.mjs} +2 -11
  36. package/dist/lib/node-esm/chunk-SPQFLYC2.mjs.map +7 -0
  37. package/dist/lib/node-esm/{graph-SMPUMOV2.mjs → compute-graph-VKRG526N.mjs} +4 -2
  38. package/dist/lib/node-esm/index.mjs +57 -14
  39. package/dist/lib/node-esm/index.mjs.map +4 -4
  40. package/dist/lib/node-esm/meta.json +1 -1
  41. package/dist/lib/node-esm/types.mjs +1 -1
  42. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  43. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +3 -1
  44. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -1
  45. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  46. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  47. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  48. package/dist/types/src/components/RangeList/RangeList.d.ts +9 -0
  49. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -0
  50. package/dist/types/src/components/RangeList/index.d.ts +2 -0
  51. package/dist/types/src/components/RangeList/index.d.ts.map +1 -0
  52. package/dist/types/src/components/SheetContext/SheetContext.d.ts +7 -5
  53. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
  54. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  55. package/dist/types/src/components/index.d.ts +1 -0
  56. package/dist/types/src/components/index.d.ts.map +1 -1
  57. package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +1 -0
  58. package/dist/types/src/{graph → compute-graph}/compute-graph.d.ts +1 -1
  59. package/dist/types/src/compute-graph/compute-graph.d.ts.map +1 -0
  60. package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +1 -0
  61. package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +1 -0
  62. package/dist/types/src/compute-graph/compute-node.d.ts.map +1 -0
  63. package/dist/types/src/compute-graph/functions/async-function.d.ts.map +1 -0
  64. package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +1 -0
  65. package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +1 -0
  66. package/dist/types/src/compute-graph/functions/index.d.ts.map +1 -0
  67. package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +1 -0
  68. package/dist/types/src/compute-graph/index.d.ts.map +1 -0
  69. package/dist/types/src/compute-graph/testing/index.d.ts.map +1 -0
  70. package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +1 -0
  71. package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +1 -0
  72. package/dist/types/src/compute-graph/util.d.ts.map +1 -0
  73. package/dist/types/src/defs/index.d.ts +1 -1
  74. package/dist/types/src/defs/index.d.ts.map +1 -1
  75. package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -1
  76. package/dist/types/src/defs/types.d.ts +6 -0
  77. package/dist/types/src/defs/types.d.ts.map +1 -1
  78. package/dist/types/src/defs/util.d.ts +2 -6
  79. package/dist/types/src/defs/util.d.ts.map +1 -1
  80. package/dist/types/src/extensions/compute.d.ts +1 -1
  81. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  82. package/dist/types/src/extensions/editor/extension.d.ts +23 -3
  83. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -1
  84. package/dist/types/src/index.d.ts +1 -1
  85. package/dist/types/src/index.d.ts.map +1 -1
  86. package/dist/types/src/integrations/index.d.ts +2 -0
  87. package/dist/types/src/integrations/index.d.ts.map +1 -0
  88. package/dist/types/src/integrations/thread-ranges.d.ts +8 -0
  89. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -0
  90. package/dist/types/src/model/index.d.ts +1 -1
  91. package/dist/types/src/model/index.d.ts.map +1 -1
  92. package/dist/types/src/model/sheet-model.d.ts +1 -1
  93. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  94. package/dist/types/src/{hooks → model}/useSheetModel.d.ts +1 -1
  95. package/dist/types/src/model/useSheetModel.d.ts.map +1 -0
  96. package/dist/types/src/serializer.d.ts +4 -0
  97. package/dist/types/src/serializer.d.ts.map +1 -0
  98. package/dist/types/src/testing/testing.d.ts +1 -1
  99. package/dist/types/src/testing/testing.d.ts.map +1 -1
  100. package/dist/types/src/translations.d.ts +6 -0
  101. package/dist/types/src/translations.d.ts.map +1 -1
  102. package/dist/types/src/types.d.ts +4 -30
  103. package/dist/types/src/types.d.ts.map +1 -1
  104. package/package.json +43 -50
  105. package/src/SheetPlugin.tsx +23 -10
  106. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +19 -2
  107. package/src/components/FunctionEditor/FunctionEditor.tsx +5 -5
  108. package/src/components/GridSheet/GridSheet.stories.tsx +3 -1
  109. package/src/components/GridSheet/GridSheet.tsx +114 -19
  110. package/src/components/GridSheet/SheetCellEditor.stories.tsx +1 -1
  111. package/src/components/GridSheet/util.ts +17 -7
  112. package/src/components/RangeList/RangeList.tsx +38 -0
  113. package/src/components/RangeList/index.ts +5 -0
  114. package/src/components/SheetContainer/SheetContainer.stories.tsx +1 -1
  115. package/src/components/SheetContext/SheetContext.tsx +43 -20
  116. package/src/components/Toolbar/Toolbar.tsx +34 -35
  117. package/src/components/index.ts +1 -0
  118. package/src/{graph → compute-graph}/compute-graph.stories.tsx +2 -1
  119. package/src/{graph → compute-graph}/compute-graph.ts +5 -2
  120. package/src/{graph → compute-graph}/compute-node.ts +2 -3
  121. package/src/defs/index.ts +1 -1
  122. package/src/defs/sheet-range-types.ts +1 -0
  123. package/src/defs/types.ts +6 -1
  124. package/src/defs/util.ts +3 -19
  125. package/src/extensions/compute.stories.tsx +2 -2
  126. package/src/extensions/compute.ts +2 -2
  127. package/src/extensions/editor/extension.test.ts +1 -1
  128. package/src/extensions/editor/extension.ts +48 -23
  129. package/src/index.ts +2 -2
  130. package/src/integrations/index.ts +5 -0
  131. package/src/integrations/thread-ranges.ts +101 -0
  132. package/src/model/index.ts +1 -1
  133. package/src/model/sheet-model.test.ts +1 -1
  134. package/src/model/sheet-model.ts +13 -8
  135. package/src/{hooks → model}/useSheetModel.ts +1 -1
  136. package/src/serializer.ts +27 -0
  137. package/src/testing/testing.tsx +1 -1
  138. package/src/translations.ts +6 -0
  139. package/src/types.ts +3 -1
  140. package/dist/lib/browser/SheetContainer-AKWROARP.mjs.map +0 -7
  141. package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +0 -7
  142. package/dist/lib/browser/chunk-FGMFOW6U.mjs.map +0 -7
  143. package/dist/lib/node/SheetContainer-N5IQGEFL.cjs.map +0 -7
  144. package/dist/lib/node/chunk-53BMSUIK.cjs.map +0 -7
  145. package/dist/lib/node/chunk-NZARD7UP.cjs.map +0 -7
  146. package/dist/lib/node/graph-Q3N2X26H.cjs.map +0 -7
  147. package/dist/lib/node-esm/SheetContainer-46PBMF2E.mjs.map +0 -7
  148. package/dist/lib/node-esm/chunk-T3PRH7QS.mjs.map +0 -7
  149. package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +0 -7
  150. package/dist/types/src/graph/compute-graph-registry.d.ts.map +0 -1
  151. package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
  152. package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
  153. package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
  154. package/dist/types/src/graph/compute-node.d.ts.map +0 -1
  155. package/dist/types/src/graph/functions/async-function.d.ts.map +0 -1
  156. package/dist/types/src/graph/functions/edge-function.d.ts.map +0 -1
  157. package/dist/types/src/graph/functions/function-defs.d.ts.map +0 -1
  158. package/dist/types/src/graph/functions/index.d.ts.map +0 -1
  159. package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
  160. package/dist/types/src/graph/index.d.ts.map +0 -1
  161. package/dist/types/src/graph/testing/index.d.ts.map +0 -1
  162. package/dist/types/src/graph/testing/test-builder.d.ts.map +0 -1
  163. package/dist/types/src/graph/testing/test-plugin.d.ts.map +0 -1
  164. package/dist/types/src/graph/util.d.ts.map +0 -1
  165. package/dist/types/src/hooks/hooks.stories.d.ts +0 -6
  166. package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
  167. package/dist/types/src/hooks/index.d.ts +0 -4
  168. package/dist/types/src/hooks/index.d.ts.map +0 -1
  169. package/dist/types/src/hooks/threads.d.ts +0 -8
  170. package/dist/types/src/hooks/threads.d.ts.map +0 -1
  171. package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
  172. package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
  173. package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
  174. package/dist/types/src/model/decorations.d.ts +0 -26
  175. package/dist/types/src/model/decorations.d.ts.map +0 -1
  176. package/src/hooks/hooks.stories.tsx +0 -53
  177. package/src/hooks/index.ts +0 -7
  178. package/src/hooks/threads.ts +0 -147
  179. package/src/hooks/useComputeGraph.ts +0 -28
  180. package/src/model/decorations.ts +0 -66
  181. /package/dist/lib/browser/{graph-M4IQ76QX.mjs.map → compute-graph-ZQKB6QVP.mjs.map} +0 -0
  182. /package/dist/lib/node-esm/{graph-SMPUMOV2.mjs.map → compute-graph-VKRG526N.mjs.map} +0 -0
  183. /package/dist/types/src/{graph → compute-graph}/compute-graph-registry.d.ts +0 -0
  184. /package/dist/types/src/{graph → compute-graph}/compute-graph.stories.d.ts +0 -0
  185. /package/dist/types/src/{graph → compute-graph}/compute-graph.test.d.ts +0 -0
  186. /package/dist/types/src/{graph → compute-graph}/compute-node.d.ts +0 -0
  187. /package/dist/types/src/{graph → compute-graph}/functions/async-function.d.ts +0 -0
  188. /package/dist/types/src/{graph → compute-graph}/functions/edge-function.d.ts +0 -0
  189. /package/dist/types/src/{graph → compute-graph}/functions/function-defs.d.ts +0 -0
  190. /package/dist/types/src/{graph → compute-graph}/functions/index.d.ts +0 -0
  191. /package/dist/types/src/{graph → compute-graph}/hyperformula.test.d.ts +0 -0
  192. /package/dist/types/src/{graph → compute-graph}/index.d.ts +0 -0
  193. /package/dist/types/src/{graph → compute-graph}/testing/index.d.ts +0 -0
  194. /package/dist/types/src/{graph → compute-graph}/testing/test-builder.d.ts +0 -0
  195. /package/dist/types/src/{graph → compute-graph}/testing/test-plugin.d.ts +0 -0
  196. /package/dist/types/src/{graph → compute-graph}/util.d.ts +0 -0
  197. /package/src/{graph → compute-graph}/compute-graph-registry.ts +0 -0
  198. /package/src/{graph → compute-graph}/compute-graph.test.ts +0 -0
  199. /package/src/{graph → compute-graph}/functions/async-function.ts +0 -0
  200. /package/src/{graph → compute-graph}/functions/edge-function.ts +0 -0
  201. /package/src/{graph → compute-graph}/functions/function-defs.ts +0 -0
  202. /package/src/{graph → compute-graph}/functions/index.ts +0 -0
  203. /package/src/{graph → compute-graph}/hyperformula.test.ts +0 -0
  204. /package/src/{graph → compute-graph}/index.ts +0 -0
  205. /package/src/{graph → compute-graph}/testing/index.ts +0 -0
  206. /package/src/{graph → compute-graph}/testing/test-builder.ts +0 -0
  207. /package/src/{graph → compute-graph}/testing/test-plugin.ts +0 -0
  208. /package/src/{graph → compute-graph}/util.ts +0 -0
@@ -1,21 +1,215 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ import {
3
+ SheetType
4
+ } from "./chunk-SPQFLYC2.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";
6
9
  import { Resource as Resource2 } from "@dxos/context";
7
10
  import { getTypename } from "@dxos/echo-schema";
8
- import { invariant } from "@dxos/invariant";
11
+ import { invariant as invariant2 } from "@dxos/invariant";
9
12
  import { PublicKey } from "@dxos/keys";
10
13
  import { log as log3 } from "@dxos/log";
11
14
  import { FunctionType as FunctionType2 } from "@dxos/plugin-script/types";
12
15
  import { nonNullable as nonNullable2 } from "@dxos/util";
13
16
  import { ExportedCellChange } from "#hyperformula";
14
17
 
15
- // packages/plugins/plugin-sheet/src/graph/compute-node.ts
18
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-node.ts
16
19
  import { Event } from "@dxos/async";
17
20
  import { Resource } from "@dxos/context";
18
21
  import { DetailedCellError } from "#hyperformula";
22
+
23
+ // packages/plugins/plugin-sheet/src/defs/sheet-range-types.ts
24
+ var cellClassNameForRange = ({ key, value }) => {
25
+ switch (key) {
26
+ case "align":
27
+ switch (value) {
28
+ case "start":
29
+ return "text-start";
30
+ case "center":
31
+ return "text-center";
32
+ case "end":
33
+ return "text-end";
34
+ default:
35
+ return void 0;
36
+ }
37
+ case "comment":
38
+ return "bg-gridComment";
39
+ case "style":
40
+ switch (value) {
41
+ case "highlight":
42
+ return "bg-gridHighlight";
43
+ default:
44
+ return void 0;
45
+ }
46
+ default:
47
+ return void 0;
48
+ }
49
+ };
50
+
51
+ // packages/plugins/plugin-sheet/src/defs/types.ts
52
+ import { invariant } from "@dxos/invariant";
53
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/defs/types.ts";
54
+ var DEFAULT_ROWS = 50;
55
+ var DEFAULT_COLUMNS = 26;
56
+ var MAX_ROWS = 500;
57
+ var MAX_COLUMNS = 26 * 2;
58
+ var RANGE_NOTATION = /^[A-Z]+[0-9]+(:[A-Z]+[0-9]+)?$/;
59
+ var isFormula = (value) => typeof value === "string" && value.charAt(0) === "=";
60
+ var posEquals = (a, b) => {
61
+ return a?.col === b?.col && a?.row === b?.row;
62
+ };
63
+ var columnLetter = (col) => {
64
+ invariant(col < MAX_COLUMNS, `Invalid column: ${col}`, {
65
+ F: __dxlog_file,
66
+ L: 31,
67
+ S: void 0,
68
+ A: [
69
+ "col < MAX_COLUMNS",
70
+ "`Invalid column: ${col}`"
71
+ ]
72
+ });
73
+ return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
74
+ };
75
+ var addressToA1Notation = ({ col, row }) => {
76
+ return `${columnLetter(col)}${row + 1}`;
77
+ };
78
+ var addressFromA1Notation = (ref) => {
79
+ const match = ref.match(/([A-Z]+)(\d+)/);
80
+ invariant(match, `Invalid notation: ${ref}`, {
81
+ F: __dxlog_file,
82
+ L: 45,
83
+ S: void 0,
84
+ A: [
85
+ "match",
86
+ "`Invalid notation: ${ref}`"
87
+ ]
88
+ });
89
+ return {
90
+ row: parseInt(match[2], 10) - 1,
91
+ col: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
92
+ };
93
+ };
94
+ var rangeToA1Notation = (range) => {
95
+ return [
96
+ range?.from && addressToA1Notation(range?.from),
97
+ range?.to && addressToA1Notation(range?.to)
98
+ ].filter(Boolean).join(":");
99
+ };
100
+ var inRange = (range, cell) => {
101
+ if (!range) {
102
+ return false;
103
+ }
104
+ const { from, to } = range;
105
+ if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
106
+ return true;
107
+ }
108
+ if (!from || !to) {
109
+ return false;
110
+ }
111
+ const { col: c1, row: r1 } = from;
112
+ const { col: c2, row: r2 } = to;
113
+ const cMin = Math.min(c1, c2);
114
+ const cMax = Math.max(c1, c2);
115
+ const rMin = Math.min(r1, r2);
116
+ const rMax = Math.max(r1, r2);
117
+ const { col, row } = cell;
118
+ return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
119
+ };
120
+
121
+ // packages/plugins/plugin-sheet/src/defs/util.ts
122
+ import { randomBytes } from "@dxos/crypto";
123
+ import { create } from "@dxos/echo-schema";
124
+ var ApiError = class extends Error {
125
+ };
126
+ var ReadonlyException = class extends ApiError {
127
+ };
128
+ var RangeException = class extends ApiError {
129
+ constructor(n) {
130
+ super();
131
+ }
132
+ };
133
+ var createIndex = (length = 8) => {
134
+ const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
135
+ const charactersLength = characters.length;
136
+ const randomBuffer = randomBytes(length);
137
+ return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
138
+ };
139
+ var createIndices = (length) => Array.from({
140
+ length
141
+ }).map(() => createIndex());
142
+ var insertIndices = (indices, i, n, max) => {
143
+ if (i + n > max) {
144
+ throw new RangeException(i + n);
145
+ }
146
+ const idx = createIndices(n);
147
+ indices.splice(i, 0, ...idx);
148
+ };
149
+ var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS } = {}) => {
150
+ if (!sheet.rows.length) {
151
+ insertIndices(sheet.rows, 0, rows, MAX_ROWS);
152
+ }
153
+ if (!sheet.columns.length) {
154
+ insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
155
+ }
156
+ };
157
+ var createSheet = ({ name, cells, ...size } = {}) => {
158
+ const sheet = create(SheetType, {
159
+ name,
160
+ cells: {},
161
+ rows: [],
162
+ columns: [],
163
+ rowMeta: {},
164
+ columnMeta: {},
165
+ ranges: [],
166
+ threads: []
167
+ });
168
+ initialize(sheet, size);
169
+ if (cells) {
170
+ Object.entries(cells).forEach(([key, { value }]) => {
171
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
172
+ sheet.cells[idx] = {
173
+ value
174
+ };
175
+ });
176
+ }
177
+ return sheet;
178
+ };
179
+ var addressToIndex = (sheet, cell) => {
180
+ return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
181
+ };
182
+ var addressFromIndex = (sheet, idx) => {
183
+ const [column, row] = idx.split("@");
184
+ return {
185
+ col: sheet.columns.indexOf(column),
186
+ row: sheet.rows.indexOf(row)
187
+ };
188
+ };
189
+ var rangeToIndex = (sheet, range) => {
190
+ return [
191
+ range.from,
192
+ range.to ?? range.from
193
+ ].map((cell) => addressToIndex(sheet, cell)).join(":");
194
+ };
195
+ var rangeFromIndex = (sheet, idx) => {
196
+ const [from, to] = idx.split(":").map((index) => addressFromIndex(sheet, index));
197
+ return {
198
+ from,
199
+ to
200
+ };
201
+ };
202
+ var compareIndexPositions = (sheet, indexA, indexB) => {
203
+ const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
204
+ const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
205
+ if (rowA !== rowB) {
206
+ return rowA - rowB;
207
+ } else {
208
+ return columnA - columnB;
209
+ }
210
+ };
211
+
212
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-node.ts
19
213
  var ComputeNode = class extends Resource {
20
214
  constructor(_graph, sheetId) {
21
215
  super();
@@ -41,7 +235,7 @@ var ComputeNode = class extends Resource {
41
235
  return value;
42
236
  }
43
237
  setValue(cell, value) {
44
- const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
238
+ const mappedValue = isFormula(value) ? this._graph.mapFormulaToNative(value) : value;
45
239
  this._graph.hf.setCellContents({
46
240
  sheet: this.sheetId,
47
241
  row: cell.row,
@@ -57,12 +251,12 @@ var ComputeNode = class extends Resource {
57
251
  }
58
252
  };
59
253
 
60
- // packages/plugins/plugin-sheet/src/graph/functions/async-function.ts
254
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/async-function.ts
61
255
  import defaultsDeep from "lodash.defaultsdeep";
62
256
  import { debounce } from "@dxos/async";
63
257
  import { log } from "@dxos/log";
64
258
  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";
259
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/functions/async-function.ts";
66
260
  var defaultFunctionContextOptions = {
67
261
  defaultTtl: 5e3,
68
262
  debounceDelay: 200,
@@ -136,7 +330,7 @@ var FunctionContext = class _FunctionContext {
136
330
  cell,
137
331
  value: value2
138
332
  }, {
139
- F: __dxlog_file,
333
+ F: __dxlog_file2,
140
334
  L: 143,
141
335
  S: this,
142
336
  C: (f, a) => f(...a)
@@ -150,7 +344,7 @@ var FunctionContext = class _FunctionContext {
150
344
  cell,
151
345
  err
152
346
  }, {
153
- F: __dxlog_file,
347
+ F: __dxlog_file2,
154
348
  L: 147,
155
349
  S: this,
156
350
  C: (f, a) => f(...a)
@@ -170,7 +364,7 @@ var FunctionContext = class _FunctionContext {
170
364
  args,
171
365
  cache: value
172
366
  }, {
173
- F: __dxlog_file,
367
+ F: __dxlog_file2,
174
368
  L: 155,
175
369
  S: this,
176
370
  C: (f, a) => f(...a)
@@ -194,7 +388,7 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
194
388
  }
195
389
  };
196
390
 
197
- // packages/plugins/plugin-sheet/src/graph/functions/edge-function.ts
391
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/edge-function.ts
198
392
  import { effect } from "@preact/signals-core";
199
393
  import { Filter, getMeta } from "@dxos/client/echo";
200
394
  import { log as log2 } from "@dxos/log";
@@ -202,7 +396,7 @@ import { getUserFunctionUrlInMetadata } from "@dxos/plugin-script/edge";
202
396
  import { FunctionType } from "@dxos/plugin-script/types";
203
397
  import { nonNullable } from "@dxos/util";
204
398
  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";
399
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/functions/edge-function.ts";
206
400
  var EDGE_FUNCTION_NAME = "DX";
207
401
  var FUNCTION_TTL = 1e4;
208
402
  var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
@@ -219,7 +413,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
219
413
  log2.info("Function not found", {
220
414
  binding
221
415
  }, {
222
- F: __dxlog_file2,
416
+ F: __dxlog_file3,
223
417
  L: 41,
224
418
  S: this,
225
419
  C: (f, a) => f(...a)
@@ -231,7 +425,7 @@ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
231
425
  log2.info("function changed", {
232
426
  fn
233
427
  }, {
234
- F: __dxlog_file2,
428
+ F: __dxlog_file3,
235
429
  L: 47,
236
430
  S: this,
237
431
  C: (f, a) => f(...a)
@@ -314,7 +508,7 @@ var EdgeFunctionPluginTranslations = {
314
508
  }
315
509
  };
316
510
 
317
- // packages/plugins/plugin-sheet/src/graph/functions/function-defs.ts
511
+ // packages/plugins/plugin-sheet/src/compute-graph/functions/function-defs.ts
318
512
  var defaultFunctions = [
319
513
  // Array
320
514
  {
@@ -2688,8 +2882,8 @@ var defaultFunctions = [
2688
2882
  }
2689
2883
  ];
2690
2884
 
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";
2885
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-graph.ts
2886
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/compute-graph.ts";
2693
2887
  var OBJECT_ID_LENGTH = 60;
2694
2888
  var createSheetName = ({ type, id }) => `${type}@${id}`;
2695
2889
  var parseSheetName = (name) => {
@@ -2757,9 +2951,9 @@ var ComputeGraph = class extends Resource2 {
2757
2951
  // E.g., Cross-object reference would be stored as "ObjectId!A1"
2758
2952
  // The graph would then load the object and create a ComputeNode (model) of the appropriate type.
2759
2953
  getOrCreateNode(name) {
2760
- invariant(name.length, void 0, {
2761
- F: __dxlog_file3,
2762
- L: 117,
2954
+ invariant2(name.length, void 0, {
2955
+ F: __dxlog_file4,
2956
+ L: 120,
2763
2957
  S: this,
2764
2958
  A: [
2765
2959
  "name.length",
@@ -2767,21 +2961,21 @@ var ComputeGraph = class extends Resource2 {
2767
2961
  ]
2768
2962
  });
2769
2963
  if (!this._hf.doesSheetExist(name)) {
2770
- log3.info("created node", {
2964
+ log3("created node", {
2771
2965
  space: this._space?.id,
2772
2966
  sheet: name
2773
2967
  }, {
2774
- F: __dxlog_file3,
2775
- L: 119,
2968
+ F: __dxlog_file4,
2969
+ L: 122,
2776
2970
  S: this,
2777
2971
  C: (f, a) => f(...a)
2778
2972
  });
2779
2973
  this._hf.addSheet(name);
2780
2974
  }
2781
2975
  const sheetId = this._hf.getSheetId(name);
2782
- invariant(sheetId !== void 0, void 0, {
2783
- F: __dxlog_file3,
2784
- L: 124,
2976
+ invariant2(sheetId !== void 0, void 0, {
2977
+ F: __dxlog_file4,
2978
+ L: 127,
2785
2979
  S: this,
2786
2980
  A: [
2787
2981
  "sheetId !== undefined",
@@ -2794,7 +2988,7 @@ var ComputeGraph = class extends Resource2 {
2794
2988
  }
2795
2989
  /**
2796
2990
  * Map bound value to custom function invocation.
2797
- * E.g., "HELLO(...args)" => "EDGE("HELLO", ...args)".
2991
+ * E.g., "HELLO(...args)" => "DX("HELLO", ...args)".
2798
2992
  */
2799
2993
  mapFormulaToNative(formula) {
2800
2994
  return formula.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
@@ -2881,13 +3075,13 @@ var ComputeGraph = class extends Resource2 {
2881
3075
  }
2882
3076
  };
2883
3077
 
2884
- // packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts
3078
+ // packages/plugins/plugin-sheet/src/compute-graph/compute-graph-registry.ts
2885
3079
  import defaultsDeep2 from "lodash.defaultsdeep";
2886
3080
  import { Resource as Resource3 } from "@dxos/context";
2887
- import { invariant as invariant2 } from "@dxos/invariant";
3081
+ import { invariant as invariant3 } from "@dxos/invariant";
2888
3082
  import { log as log4 } from "@dxos/log";
2889
3083
  import { HyperFormula } from "#hyperformula";
2890
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts";
3084
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/compute-graph/compute-graph-registry.ts";
2891
3085
  var defaultOptions = {
2892
3086
  licenseKey: "gpl-v3"
2893
3087
  };
@@ -2917,7 +3111,7 @@ var ComputeGraphRegistry = class extends Resource3 {
2917
3111
  log4("create graph", {
2918
3112
  space: space.id
2919
3113
  }, {
2920
- F: __dxlog_file4,
3114
+ F: __dxlog_file5,
2921
3115
  L: 69,
2922
3116
  S: this,
2923
3117
  C: (f, a) => f(...a)
@@ -2927,8 +3121,8 @@ var ComputeGraphRegistry = class extends Resource3 {
2927
3121
  return graph;
2928
3122
  }
2929
3123
  createGraph(space) {
2930
- invariant2(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
2931
- F: __dxlog_file4,
3124
+ invariant3(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
3125
+ F: __dxlog_file5,
2932
3126
  L: 77,
2933
3127
  S: this,
2934
3128
  A: [
@@ -2950,6 +3144,26 @@ var ComputeGraphRegistry = class extends Resource3 {
2950
3144
  };
2951
3145
 
2952
3146
  export {
3147
+ cellClassNameForRange,
3148
+ DEFAULT_ROWS,
3149
+ DEFAULT_COLUMNS,
3150
+ MAX_ROWS,
3151
+ MAX_COLUMNS,
3152
+ RANGE_NOTATION,
3153
+ isFormula,
3154
+ addressToA1Notation,
3155
+ addressFromA1Notation,
3156
+ rangeToA1Notation,
3157
+ inRange,
3158
+ ReadonlyException,
3159
+ insertIndices,
3160
+ initialize,
3161
+ createSheet,
3162
+ addressToIndex,
3163
+ addressFromIndex,
3164
+ rangeToIndex,
3165
+ rangeFromIndex,
3166
+ compareIndexPositions,
2953
3167
  ComputeNode,
2954
3168
  defaultFunctionContextOptions,
2955
3169
  FunctionContext,
@@ -2965,4 +3179,4 @@ export {
2965
3179
  defaultPlugins,
2966
3180
  ComputeGraphRegistry
2967
3181
  };
2968
- //# sourceMappingURL=chunk-5WPZCXNS.mjs.map
3182
+ //# sourceMappingURL=chunk-JBTORSST.mjs.map