@dxos/plugin-sheet 0.6.14-main.7bd9c89 → 0.6.14-main.8b352a0

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