@dxos/plugin-sheet 0.6.12-main.78ddbdf → 0.6.12-main.7907542

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 (160) hide show
  1. package/dist/lib/browser/{SheetContainer-V4GCCZTX.mjs → SheetContainer-T2QWJOFD.mjs} +14 -13
  2. package/dist/lib/browser/SheetContainer-T2QWJOFD.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-T3NJFTD4.mjs → chunk-5ZMVZYGB.mjs} +18 -6
  4. package/dist/lib/browser/{chunk-T3NJFTD4.mjs.map → chunk-5ZMVZYGB.mjs.map} +3 -3
  5. package/dist/lib/browser/{chunk-6ZMQVB4Z.mjs → chunk-GSV5QNLD.mjs} +220 -177
  6. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-U2JHW3L6.mjs → chunk-ZL2V5UJR.mjs} +206 -53
  8. package/dist/lib/browser/chunk-ZL2V5UJR.mjs.map +7 -0
  9. package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
  10. package/dist/lib/browser/index.mjs +45 -21
  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-3ZY7MPWJ.cjs → SheetContainer-PV5ET4UJ.cjs} +21 -20
  15. package/dist/lib/node/SheetContainer-PV5ET4UJ.cjs.map +7 -0
  16. package/dist/lib/node/{chunk-OTTD7FBK.cjs → chunk-2K53Z2TU.cjs} +224 -70
  17. package/dist/lib/node/chunk-2K53Z2TU.cjs.map +7 -0
  18. package/dist/lib/node/{chunk-DD6FIXWC.cjs → chunk-5XPK2V4A.cjs} +222 -175
  19. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
  20. package/dist/lib/node/{chunk-Q3HBHPRL.cjs → chunk-STAVQ2JE.cjs} +21 -9
  21. package/dist/lib/node/{chunk-Q3HBHPRL.cjs.map → chunk-STAVQ2JE.cjs.map} +3 -3
  22. package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
  23. package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
  24. package/dist/lib/node/index.cjs +51 -30
  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 +8 -8
  28. package/dist/lib/node/types.cjs.map +1 -1
  29. package/dist/lib/node-esm/{SheetContainer-PXSJX6XK.mjs → SheetContainer-FOZD2WLT.mjs} +14 -13
  30. package/dist/lib/node-esm/SheetContainer-FOZD2WLT.mjs.map +7 -0
  31. package/dist/lib/node-esm/{chunk-BMNA27EX.mjs → chunk-2HAM45RC.mjs} +18 -6
  32. package/dist/lib/node-esm/{chunk-BMNA27EX.mjs.map → chunk-2HAM45RC.mjs.map} +3 -3
  33. package/dist/lib/node-esm/{chunk-D6KU5MI7.mjs → chunk-5WPZCXNS.mjs} +220 -177
  34. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
  35. package/dist/lib/node-esm/{chunk-7HVSOTGA.mjs → chunk-QEUCIHIN.mjs} +206 -53
  36. package/dist/lib/node-esm/chunk-QEUCIHIN.mjs.map +7 -0
  37. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
  38. package/dist/lib/node-esm/index.mjs +45 -21
  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/CellEditor/CellEditor.stories.d.ts.map +1 -1
  44. package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
  45. package/dist/types/src/components/GridSheet/GridSheet.d.ts +3 -3
  46. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  47. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +1 -1
  48. package/dist/types/src/components/GridSheet/util.d.ts +9 -0
  49. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  50. package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
  51. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  52. package/dist/types/src/components/Sheet/sheet-context.d.ts +3 -3
  53. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
  54. package/dist/types/src/components/SheetContainer.d.ts +1 -1
  55. package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
  56. package/dist/types/src/components/index.d.ts +1 -1
  57. package/dist/types/src/components/index.d.ts.map +1 -1
  58. package/dist/types/src/defs/types.d.ts.map +1 -1
  59. package/dist/types/src/defs/util.d.ts +1 -1
  60. package/dist/types/src/defs/util.d.ts.map +1 -1
  61. package/dist/types/src/extensions/compute.d.ts +3 -2
  62. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  63. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  64. package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
  65. package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
  66. package/dist/types/src/graph/compute-graph.d.ts +17 -34
  67. package/dist/types/src/graph/compute-graph.d.ts.map +1 -1
  68. package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -1
  69. package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
  70. package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
  71. package/dist/types/src/graph/compute-node.d.ts +9 -2
  72. package/dist/types/src/graph/compute-node.d.ts.map +1 -1
  73. package/dist/types/src/graph/{async-function.d.ts → functions/async-function.d.ts} +13 -4
  74. package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
  75. package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
  76. package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
  77. package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
  78. package/dist/types/src/graph/functions/index.d.ts +4 -0
  79. package/dist/types/src/graph/functions/index.d.ts.map +1 -0
  80. package/dist/types/src/graph/index.d.ts +2 -1
  81. package/dist/types/src/graph/index.d.ts.map +1 -1
  82. package/dist/types/src/graph/testing/index.d.ts +3 -0
  83. package/dist/types/src/graph/testing/index.d.ts.map +1 -0
  84. package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
  85. package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
  86. package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
  87. package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
  88. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -1
  89. package/dist/types/src/hooks/useSheetModel.d.ts +2 -2
  90. package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -1
  91. package/dist/types/src/model/sheet-model.d.ts +3 -3
  92. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  93. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  94. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  95. package/dist/types/src/testing/testing.d.ts +4 -5
  96. package/dist/types/src/testing/testing.d.ts.map +1 -1
  97. package/dist/types/src/types.d.ts +4 -3
  98. package/dist/types/src/types.d.ts.map +1 -1
  99. package/package.json +40 -39
  100. package/src/SheetPlugin.tsx +19 -15
  101. package/src/components/CellEditor/CellEditor.stories.tsx +2 -3
  102. package/src/components/CellEditor/extension.test.ts +0 -1
  103. package/src/components/CellEditor/extension.ts +4 -3
  104. package/src/components/GridSheet/GridSheet.stories.tsx +3 -3
  105. package/src/components/GridSheet/GridSheet.tsx +26 -8
  106. package/src/components/GridSheet/util.ts +61 -21
  107. package/src/components/Sheet/Sheet.stories.tsx +21 -20
  108. package/src/components/Sheet/Sheet.tsx +30 -14
  109. package/src/components/Sheet/sheet-context.tsx +4 -4
  110. package/src/components/SheetContainer.tsx +13 -15
  111. package/src/defs/types.ts +1 -0
  112. package/src/defs/util.ts +19 -3
  113. package/src/extensions/compute.stories.tsx +20 -20
  114. package/src/extensions/compute.ts +91 -42
  115. package/src/graph/compute-graph-registry.ts +90 -0
  116. package/src/graph/compute-graph.stories.tsx +4 -3
  117. package/src/graph/compute-graph.test.ts +87 -0
  118. package/src/graph/compute-graph.ts +73 -121
  119. package/src/graph/compute-node.ts +17 -5
  120. package/src/graph/{async-function.ts → functions/async-function.ts} +23 -15
  121. package/src/graph/{edge-function.ts → functions/edge-function.ts} +14 -13
  122. package/src/graph/functions/index.ts +7 -0
  123. package/src/graph/hyperformula.test.ts +1 -2
  124. package/src/graph/index.ts +2 -1
  125. package/src/graph/testing/index.ts +6 -0
  126. package/src/graph/testing/test-builder.ts +54 -0
  127. package/src/graph/{custom-function.ts → testing/test-plugin.ts} +43 -9
  128. package/src/hooks/hooks.stories.tsx +3 -3
  129. package/src/hooks/useComputeGraph.ts +9 -1
  130. package/src/hooks/useSheetModel.ts +4 -7
  131. package/src/model/sheet-model.test.ts +57 -0
  132. package/src/model/sheet-model.ts +47 -30
  133. package/src/testing/testing.tsx +17 -15
  134. package/src/types.ts +7 -7
  135. package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs.map +0 -7
  136. package/dist/lib/browser/chunk-6ZMQVB4Z.mjs.map +0 -7
  137. package/dist/lib/browser/chunk-U2JHW3L6.mjs.map +0 -7
  138. package/dist/lib/browser/graph-T27BOBOV.mjs +0 -21
  139. package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs.map +0 -7
  140. package/dist/lib/node/chunk-DD6FIXWC.cjs.map +0 -7
  141. package/dist/lib/node/chunk-OTTD7FBK.cjs.map +0 -7
  142. package/dist/lib/node/graph-SPKGX7W4.cjs +0 -43
  143. package/dist/lib/node/graph-SPKGX7W4.cjs.map +0 -7
  144. package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs.map +0 -7
  145. package/dist/lib/node-esm/chunk-7HVSOTGA.mjs.map +0 -7
  146. package/dist/lib/node-esm/chunk-D6KU5MI7.mjs.map +0 -7
  147. package/dist/lib/node-esm/graph-U67IO4UC.mjs +0 -22
  148. package/dist/types/src/graph/async-function.d.ts.map +0 -1
  149. package/dist/types/src/graph/compute-graph.browser.test.d.ts +0 -2
  150. package/dist/types/src/graph/compute-graph.browser.test.d.ts.map +0 -1
  151. package/dist/types/src/graph/custom-function.d.ts +0 -21
  152. package/dist/types/src/graph/custom-function.d.ts.map +0 -1
  153. package/dist/types/src/graph/edge-function.d.ts +0 -20
  154. package/dist/types/src/graph/edge-function.d.ts.map +0 -1
  155. package/dist/types/src/graph/function-defs.d.ts.map +0 -1
  156. package/src/graph/compute-graph.browser.test.ts +0 -104
  157. /package/dist/lib/browser/{graph-T27BOBOV.mjs.map → graph-M4IQ76QX.mjs.map} +0 -0
  158. /package/dist/lib/node-esm/{graph-U67IO4UC.mjs.map → graph-SMPUMOV2.mjs.map} +0 -0
  159. /package/dist/types/src/graph/{function-defs.d.ts → functions/function-defs.d.ts} +0 -0
  160. /package/src/graph/{function-defs.ts → functions/function-defs.ts} +0 -0
@@ -4,22 +4,68 @@ import { createRequire } from 'node:module';const require = createRequire(import
4
4
  import { Event as Event2 } from "@dxos/async";
5
5
  import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
6
6
  import { Resource as Resource2 } from "@dxos/context";
7
+ import { getTypename } from "@dxos/echo-schema";
7
8
  import { invariant } from "@dxos/invariant";
8
9
  import { PublicKey } from "@dxos/keys";
9
10
  import { log as log3 } from "@dxos/log";
10
11
  import { FunctionType as FunctionType2 } from "@dxos/plugin-script/types";
11
12
  import { nonNullable as nonNullable2 } from "@dxos/util";
12
- import { HyperFormula } from "#hyperformula";
13
+ import { ExportedCellChange } from "#hyperformula";
14
+
15
+ // packages/plugins/plugin-sheet/src/graph/compute-node.ts
16
+ import { Event } from "@dxos/async";
17
+ import { Resource } from "@dxos/context";
18
+ import { DetailedCellError } from "#hyperformula";
19
+ var ComputeNode = class extends Resource {
20
+ constructor(_graph, sheetId) {
21
+ super();
22
+ this._graph = _graph;
23
+ this.sheetId = sheetId;
24
+ this.update = new Event();
25
+ }
26
+ get graph() {
27
+ return this._graph;
28
+ }
29
+ clear() {
30
+ this._graph.hf.clearSheet(this.sheetId);
31
+ }
32
+ getValue(cell) {
33
+ const value = this._graph.hf.getCellValue({
34
+ sheet: this.sheetId,
35
+ row: cell.row,
36
+ col: cell.col
37
+ });
38
+ if (value instanceof DetailedCellError) {
39
+ return null;
40
+ }
41
+ return value;
42
+ }
43
+ setValue(cell, value) {
44
+ const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
45
+ this._graph.hf.setCellContents({
46
+ sheet: this.sheetId,
47
+ row: cell.row,
48
+ col: cell.col
49
+ }, [
50
+ [
51
+ mappedValue
52
+ ]
53
+ ]);
54
+ }
55
+ // TODO(burdon): Load data into sheet.
56
+ async _open() {
57
+ }
58
+ };
13
59
 
14
- // packages/plugins/plugin-sheet/src/graph/async-function.ts
60
+ // packages/plugins/plugin-sheet/src/graph/functions/async-function.ts
15
61
  import defaultsDeep from "lodash.defaultsdeep";
16
62
  import { debounce } from "@dxos/async";
17
63
  import { log } from "@dxos/log";
18
64
  import { CellError, ErrorType, EmptyValue, FunctionPlugin } from "#hyperformula";
19
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/async-function.ts";
65
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/async-function.ts";
20
66
  var defaultFunctionContextOptions = {
21
67
  defaultTtl: 5e3,
22
- recalculationDelay: 200,
68
+ debounceDelay: 200,
23
69
  remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
24
70
  };
25
71
  var FunctionContext = class _FunctionContext {
@@ -30,7 +76,7 @@ var FunctionContext = class _FunctionContext {
30
76
  ...args
31
77
  });
32
78
  }
33
- constructor(_hf, _space, onUpdate, _options) {
79
+ constructor(_hf, _space, _options) {
34
80
  this._hf = _hf;
35
81
  this._space = _space;
36
82
  this._cache = /* @__PURE__ */ new Map();
@@ -38,12 +84,11 @@ var FunctionContext = class _FunctionContext {
38
84
  this._subscriptions = /* @__PURE__ */ new Map();
39
85
  this._invocations = {};
40
86
  this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
41
- this._onUpdate = debounce(() => {
87
+ this._onUpdate = debounce((update) => {
42
88
  this._hf.resumeEvaluation();
43
- onUpdate(this);
44
- }, this._options.recalculationDelay);
89
+ this._options.onUpdate?.(update);
90
+ }, this._options.debounceDelay);
45
91
  }
46
- // TODO(burdon): Remove?
47
92
  get space() {
48
93
  return this._space;
49
94
  }
@@ -92,18 +137,21 @@ var FunctionContext = class _FunctionContext {
92
137
  value: value2
93
138
  }, {
94
139
  F: __dxlog_file,
95
- L: 138,
140
+ L: 143,
96
141
  S: this,
97
142
  C: (f, a) => f(...a)
98
143
  });
99
- this._onUpdate();
144
+ this._onUpdate({
145
+ name,
146
+ cell
147
+ });
100
148
  } catch (err) {
101
149
  log.warn("failed", {
102
150
  cell,
103
151
  err
104
152
  }, {
105
153
  F: __dxlog_file,
106
- L: 142,
154
+ L: 147,
107
155
  S: this,
108
156
  C: (f, a) => f(...a)
109
157
  });
@@ -123,17 +171,20 @@ var FunctionContext = class _FunctionContext {
123
171
  cache: value
124
172
  }, {
125
173
  F: __dxlog_file,
126
- L: 150,
174
+ L: 155,
127
175
  S: this,
128
176
  C: (f, a) => f(...a)
129
177
  });
130
178
  return value;
131
179
  }
132
180
  };
133
- var FunctionPluginAsync = class extends FunctionPlugin {
181
+ var AsyncFunctionPlugin = class extends FunctionPlugin {
134
182
  get context() {
135
183
  return this.config.context;
136
184
  }
185
+ /**
186
+ * Immediately returns cached value then runs the async function.
187
+ */
137
188
  runAsyncFunction(ast, state, cb, options) {
138
189
  const { procedureName } = ast;
139
190
  const metadata = this.metadata(procedureName);
@@ -143,50 +194,7 @@ var FunctionPluginAsync = class extends FunctionPlugin {
143
194
  }
144
195
  };
145
196
 
146
- // packages/plugins/plugin-sheet/src/graph/compute-node.ts
147
- import { Event } from "@dxos/async";
148
- import { Resource } from "@dxos/context";
149
- import { DetailedCellError } from "#hyperformula";
150
- var ComputeNode = class extends Resource {
151
- constructor(_graph, sheetId) {
152
- super();
153
- this._graph = _graph;
154
- this.sheetId = sheetId;
155
- this.update = new Event();
156
- }
157
- // TODO(burdon): Remove?
158
- get graph() {
159
- return this._graph;
160
- }
161
- get hf() {
162
- return this._graph.hf;
163
- }
164
- getValue(cell) {
165
- const value = this._graph.hf.getCellValue({
166
- sheet: this.sheetId,
167
- row: cell.row,
168
- col: cell.col
169
- });
170
- if (value instanceof DetailedCellError) {
171
- return null;
172
- }
173
- return value;
174
- }
175
- setValue(cell, value) {
176
- const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
177
- this._graph.hf.setCellContents({
178
- sheet: this.sheetId,
179
- row: cell.row,
180
- col: cell.col
181
- }, [
182
- [
183
- mappedValue
184
- ]
185
- ]);
186
- }
187
- };
188
-
189
- // packages/plugins/plugin-sheet/src/graph/edge-function.ts
197
+ // packages/plugins/plugin-sheet/src/graph/functions/edge-function.ts
190
198
  import { effect } from "@preact/signals-core";
191
199
  import { Filter, getMeta } from "@dxos/client/echo";
192
200
  import { log as log2 } from "@dxos/log";
@@ -194,10 +202,11 @@ import { getUserFunctionUrlInMetadata } from "@dxos/plugin-script/edge";
194
202
  import { FunctionType } from "@dxos/plugin-script/types";
195
203
  import { nonNullable } from "@dxos/util";
196
204
  import { CellError as CellError2, ErrorType as ErrorType2, FunctionArgumentType } from "#hyperformula";
197
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/edge-function.ts";
198
- var EDGE_FUNCTION_TTL = 1e4;
199
- var EdgeFunctionPlugin = class extends FunctionPluginAsync {
200
- edge(ast, state) {
205
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/edge-function.ts";
206
+ var EDGE_FUNCTION_NAME = "DX";
207
+ var FUNCTION_TTL = 1e4;
208
+ var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
209
+ dx(ast, state) {
201
210
  const handler = (subscribe = false) => async (binding, ...args) => {
202
211
  const space = this.context.space;
203
212
  if (!space) {
@@ -211,7 +220,7 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
211
220
  binding
212
221
  }, {
213
222
  F: __dxlog_file2,
214
- L: 39,
223
+ L: 41,
215
224
  S: this,
216
225
  C: (f, a) => f(...a)
217
226
  });
@@ -223,13 +232,13 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
223
232
  fn
224
233
  }, {
225
234
  F: __dxlog_file2,
226
- L: 45,
235
+ L: 47,
227
236
  S: this,
228
237
  C: (f, a) => f(...a)
229
238
  });
230
239
  const _ = fn?.version;
231
240
  this.runAsyncFunction(ast, state, handler(false), {
232
- ttl: EDGE_FUNCTION_TTL
241
+ ttl: FUNCTION_TTL
233
242
  });
234
243
  });
235
244
  this.context.createSubscription(ast.procedureName, unsubscribe);
@@ -247,23 +256,19 @@ var EdgeFunctionPlugin = class extends FunctionPluginAsync {
247
256
  return await result.text();
248
257
  };
249
258
  return this.runAsyncFunction(ast, state, handler(true), {
250
- ttl: EDGE_FUNCTION_TTL
259
+ ttl: FUNCTION_TTL
251
260
  });
252
261
  }
253
262
  };
254
263
  EdgeFunctionPlugin.implementedFunctions = {
255
- EDGE: {
256
- method: "edge",
264
+ [EDGE_FUNCTION_NAME]: {
265
+ method: "dx",
257
266
  parameters: [
258
267
  // Binding
259
268
  {
260
269
  argumentType: FunctionArgumentType.STRING
261
270
  },
262
- // Remote function arguments (currently supporting up to 9).
263
- {
264
- argumentType: FunctionArgumentType.ANY,
265
- optionalArg: true
266
- },
271
+ // Remote function arguments (currently supporting up to 8).
267
272
  {
268
273
  argumentType: FunctionArgumentType.ANY,
269
274
  optionalArg: true
@@ -302,14 +307,14 @@ EdgeFunctionPlugin.implementedFunctions = {
302
307
  };
303
308
  var EdgeFunctionPluginTranslations = {
304
309
  enGB: {
305
- EDGE: "EDGE"
310
+ [EDGE_FUNCTION_NAME]: "Remote function"
306
311
  },
307
312
  enUS: {
308
- EDGE: "EDGE"
313
+ [EDGE_FUNCTION_NAME]: "Remote function"
309
314
  }
310
315
  };
311
316
 
312
- // packages/plugins/plugin-sheet/src/graph/function-defs.ts
317
+ // packages/plugins/plugin-sheet/src/graph/functions/function-defs.ts
313
318
  var defaultFunctions = [
314
319
  // Array
315
320
  {
@@ -2686,68 +2691,15 @@ var defaultFunctions = [
2686
2691
  // packages/plugins/plugin-sheet/src/graph/compute-graph.ts
2687
2692
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph.ts";
2688
2693
  var OBJECT_ID_LENGTH = 60;
2689
- var CUSTOM_FUNCTION = "ECHO";
2690
- var defaultOptions = {
2691
- licenseKey: "gpl-v3",
2692
- plugins: [
2693
- {
2694
- plugin: EdgeFunctionPlugin,
2695
- translations: EdgeFunctionPluginTranslations
2696
- }
2697
- ]
2698
- };
2699
- var PREFIX = "__";
2700
- var createSheetName = (id) => `${PREFIX}${id}`;
2701
- var getSheetId = (name) => name.startsWith(PREFIX) ? name.slice(PREFIX.length) : void 0;
2702
- var createComputeGraphRegistry = (options = {}) => {
2703
- return new ComputeGraphRegistry({
2704
- ...defaultOptions,
2705
- ...options
2706
- });
2707
- };
2708
- var ComputeGraphRegistry = class extends Resource2 {
2709
- constructor(_options = defaultOptions) {
2710
- super();
2711
- this._options = _options;
2712
- this._registry = /* @__PURE__ */ new Map();
2713
- this._options.plugins?.forEach(({ plugin, translations }) => {
2714
- HyperFormula.registerFunctionPlugin(plugin, translations);
2715
- });
2716
- }
2717
- getGraph(spaceId) {
2718
- return this._registry.get(spaceId);
2719
- }
2720
- async getOrCreateGraph(space) {
2721
- let graph = this.getGraph(space.id);
2722
- if (!graph) {
2723
- log3.info("create graph", {
2724
- space: space.id
2725
- }, {
2726
- F: __dxlog_file3,
2727
- L: 95,
2728
- S: this,
2729
- C: (f, a) => f(...a)
2730
- });
2731
- graph = await this.createGraph(space);
2732
- }
2733
- return graph;
2734
- }
2735
- async createGraph(space) {
2736
- invariant(!this._registry.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
2737
- F: __dxlog_file3,
2738
- L: 103,
2739
- S: this,
2740
- A: [
2741
- "!this._registry.has(space.id)",
2742
- "`ComputeGraph already exists for space: ${space.id}`"
2743
- ]
2744
- });
2745
- const hf = HyperFormula.buildEmpty(this._options);
2746
- const graph = new ComputeGraph(hf, space, this._options);
2747
- await graph.open(this._ctx);
2748
- this._registry.set(space.id, graph);
2749
- return graph;
2750
- }
2694
+ var createSheetName = ({ type, id }) => `${type}@${id}`;
2695
+ var parseSheetName = (name) => {
2696
+ const [type, id] = name.split("@");
2697
+ return id ? {
2698
+ type,
2699
+ id
2700
+ } : {
2701
+ id: type
2702
+ };
2751
2703
  };
2752
2704
  var ComputeGraph = class extends Resource2 {
2753
2705
  constructor(_hf, _space, _options) {
@@ -2757,34 +2709,41 @@ var ComputeGraph = class extends Resource2 {
2757
2709
  this._options = _options;
2758
2710
  this.id = `graph-${PublicKey.random().truncate()}`;
2759
2711
  this._nodes = /* @__PURE__ */ new Map();
2760
- this._functions = [];
2761
- this.context = new FunctionContext(this._hf, this._space, this.refresh.bind(this), this._options);
2712
+ this._remoteFunctions = [];
2762
2713
  this.update = new Event2();
2714
+ this.context = new FunctionContext(this._hf, this._space, this._options);
2763
2715
  this._hf.updateConfig({
2764
2716
  context: this.context
2765
2717
  });
2718
+ const onValuesUpdate = (changes) => {
2719
+ for (const change of changes) {
2720
+ if (change instanceof ExportedCellChange) {
2721
+ const { sheet } = change;
2722
+ const node = this._nodes.get(sheet);
2723
+ if (node) {
2724
+ node.update.emit({
2725
+ type: "valuesUpdated",
2726
+ change
2727
+ });
2728
+ }
2729
+ }
2730
+ }
2731
+ };
2732
+ this._hf.on("valuesUpdated", onValuesUpdate);
2733
+ this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
2766
2734
  }
2767
- // TODO(burdon): Remove.
2768
2735
  get hf() {
2769
2736
  return this._hf;
2770
2737
  }
2771
- refresh() {
2772
- log3("refresh", {
2773
- id: this.id
2774
- }, {
2775
- F: __dxlog_file3,
2776
- L: 152,
2777
- S: this,
2778
- C: (f, a) => f(...a)
2779
- });
2780
- this.update.emit();
2781
- }
2782
- getFunctions({ standard = true, echo = true } = {}) {
2738
+ getFunctions({ standard, echo } = {
2739
+ standard: true,
2740
+ echo: true
2741
+ }) {
2783
2742
  return [
2784
2743
  ...standard ? this._hf.getRegisteredFunctionNames().map((name) => defaultFunctions.find((fn) => fn.name === name) ?? {
2785
2744
  name
2786
2745
  }) : [],
2787
- ...echo ? this._functions.map((fn) => ({
2746
+ ...echo ? this._remoteFunctions.map((fn) => ({
2788
2747
  name: fn.binding
2789
2748
  })) : []
2790
2749
  ];
@@ -2800,7 +2759,7 @@ var ComputeGraph = class extends Resource2 {
2800
2759
  getOrCreateNode(name) {
2801
2760
  invariant(name.length, void 0, {
2802
2761
  F: __dxlog_file3,
2803
- L: 176,
2762
+ L: 117,
2804
2763
  S: this,
2805
2764
  A: [
2806
2765
  "name.length",
@@ -2810,20 +2769,19 @@ var ComputeGraph = class extends Resource2 {
2810
2769
  if (!this._hf.doesSheetExist(name)) {
2811
2770
  log3.info("created node", {
2812
2771
  space: this._space?.id,
2813
- name
2772
+ sheet: name
2814
2773
  }, {
2815
2774
  F: __dxlog_file3,
2816
- L: 178,
2775
+ L: 119,
2817
2776
  S: this,
2818
2777
  C: (f, a) => f(...a)
2819
2778
  });
2820
2779
  this._hf.addSheet(name);
2821
- this.update.emit();
2822
2780
  }
2823
2781
  const sheetId = this._hf.getSheetId(name);
2824
2782
  invariant(sheetId !== void 0, void 0, {
2825
2783
  F: __dxlog_file3,
2826
- L: 184,
2784
+ L: 124,
2827
2785
  S: this,
2828
2786
  A: [
2829
2787
  "sheetId !== undefined",
@@ -2842,25 +2800,29 @@ var ComputeGraph = class extends Resource2 {
2842
2800
  return formula.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
2843
2801
  if (name) {
2844
2802
  const objects = this._hf.getSheetNames().map((name2) => {
2845
- const id = getSheetId(name2);
2846
- return id ? this._space?.db.getObjectById(id) : void 0;
2803
+ const { type, id } = parseSheetName(name2);
2804
+ return type && id ? this._space?.db.getObjectById(id) : void 0;
2847
2805
  }).filter(nonNullable2);
2848
2806
  for (const obj of objects) {
2849
- if (obj.name === name || obj.title === name) {
2850
- return `${createSheetName(obj.id)}!`;
2807
+ if (obj.name === name) {
2808
+ const type = getTypename(obj);
2809
+ return `'${createSheetName({
2810
+ type,
2811
+ id: obj.id
2812
+ })}'!`;
2851
2813
  }
2852
2814
  }
2853
2815
  }
2854
2816
  return `${name}!`;
2855
2817
  }).replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
2856
- const fn = this._functions.find((fn2) => fn2.binding === binding);
2818
+ const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
2857
2819
  if (!fn) {
2858
2820
  return match;
2859
2821
  }
2860
2822
  if (args.trim() === "") {
2861
- return `${CUSTOM_FUNCTION}("${binding}")`;
2823
+ return `${EDGE_FUNCTION_NAME}("${binding}")`;
2862
2824
  } else {
2863
- return `${CUSTOM_FUNCTION}("${binding}", ${args})`;
2825
+ return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
2864
2826
  }
2865
2827
  });
2866
2828
  }
@@ -2870,10 +2832,10 @@ var ComputeGraph = class extends Resource2 {
2870
2832
  */
2871
2833
  mapFunctionBindingToId(formula) {
2872
2834
  return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
2873
- if (binding === CUSTOM_FUNCTION || defaultFunctions.find((fn2) => fn2.name === binding)) {
2835
+ if (binding === EDGE_FUNCTION_NAME || defaultFunctions.find((fn2) => fn2.name === binding)) {
2874
2836
  return match;
2875
2837
  }
2876
- const fn = this._functions.find((fn2) => fn2.binding === binding);
2838
+ const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
2877
2839
  if (fn) {
2878
2840
  const id = fullyQualifiedId(fn);
2879
2841
  return `${id}(${args})`;
@@ -2892,7 +2854,7 @@ var ComputeGraph = class extends Resource2 {
2892
2854
  if (id.length !== OBJECT_ID_LENGTH) {
2893
2855
  return match;
2894
2856
  }
2895
- const fn = this._functions.find((fn2) => fullyQualifiedId(fn2) === id);
2857
+ const fn = this._remoteFunctions.find((fn2) => fullyQualifiedId(fn2) === id);
2896
2858
  if (fn?.binding) {
2897
2859
  return `${fn.binding}(${args})`;
2898
2860
  } else {
@@ -2904,22 +2866,103 @@ var ComputeGraph = class extends Resource2 {
2904
2866
  if (this._space) {
2905
2867
  const query = this._space.db.query(Filter2.schema(FunctionType2));
2906
2868
  const unsubscribe = query.subscribe(({ objects }) => {
2907
- this._functions = objects.filter(({ binding }) => binding);
2908
- this.update.emit();
2869
+ this._remoteFunctions = objects.filter(({ binding }) => binding);
2870
+ this.update.emit({
2871
+ type: "functionsUpdated"
2872
+ });
2909
2873
  });
2910
2874
  this._ctx.onDispose(unsubscribe);
2911
2875
  }
2912
2876
  }
2877
+ async _close() {
2878
+ for (const node of this._nodes.values()) {
2879
+ await node.close();
2880
+ }
2881
+ }
2882
+ };
2883
+
2884
+ // packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts
2885
+ import defaultsDeep2 from "lodash.defaultsdeep";
2886
+ import { Resource as Resource3 } from "@dxos/context";
2887
+ import { invariant as invariant2 } from "@dxos/invariant";
2888
+ import { log as log4 } from "@dxos/log";
2889
+ import { HyperFormula } from "#hyperformula";
2890
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts";
2891
+ var defaultOptions = {
2892
+ licenseKey: "gpl-v3"
2893
+ };
2894
+ var defaultPlugins = [
2895
+ {
2896
+ plugin: EdgeFunctionPlugin,
2897
+ translations: EdgeFunctionPluginTranslations
2898
+ }
2899
+ ];
2900
+ var ComputeGraphRegistry = class extends Resource3 {
2901
+ constructor(options = {
2902
+ plugins: defaultPlugins
2903
+ }) {
2904
+ super();
2905
+ this._graphs = /* @__PURE__ */ new Map();
2906
+ this._options = defaultsDeep2({}, options, defaultOptions);
2907
+ this._options.plugins?.forEach(({ plugin, translations }) => {
2908
+ HyperFormula.registerFunctionPlugin(plugin, translations);
2909
+ });
2910
+ }
2911
+ getGraph(spaceId) {
2912
+ return this._graphs.get(spaceId);
2913
+ }
2914
+ getOrCreateGraph(space) {
2915
+ let graph = this._graphs.get(space.id);
2916
+ if (!graph) {
2917
+ log4("create graph", {
2918
+ space: space.id
2919
+ }, {
2920
+ F: __dxlog_file4,
2921
+ L: 69,
2922
+ S: this,
2923
+ C: (f, a) => f(...a)
2924
+ });
2925
+ graph = this.createGraph(space);
2926
+ }
2927
+ return graph;
2928
+ }
2929
+ createGraph(space) {
2930
+ invariant2(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
2931
+ F: __dxlog_file4,
2932
+ L: 77,
2933
+ S: this,
2934
+ A: [
2935
+ "!this._graphs.has(space.id)",
2936
+ "`ComputeGraph already exists for space: ${space.id}`"
2937
+ ]
2938
+ });
2939
+ const hf = HyperFormula.buildEmpty(this._options);
2940
+ const graph = new ComputeGraph(hf, space, this._options);
2941
+ this._graphs.set(space.id, graph);
2942
+ return graph;
2943
+ }
2944
+ async _close() {
2945
+ for (const graph of this._graphs.values()) {
2946
+ await graph.close();
2947
+ }
2948
+ this._graphs.clear();
2949
+ }
2913
2950
  };
2914
2951
 
2915
2952
  export {
2916
2953
  ComputeNode,
2954
+ defaultFunctionContextOptions,
2955
+ FunctionContext,
2956
+ AsyncFunctionPlugin,
2957
+ EDGE_FUNCTION_NAME,
2958
+ EdgeFunctionPlugin,
2959
+ EdgeFunctionPluginTranslations,
2917
2960
  defaultFunctions,
2918
- defaultOptions,
2919
2961
  createSheetName,
2920
- getSheetId,
2921
- createComputeGraphRegistry,
2922
- ComputeGraphRegistry,
2923
- ComputeGraph
2962
+ parseSheetName,
2963
+ ComputeGraph,
2964
+ defaultOptions,
2965
+ defaultPlugins,
2966
+ ComputeGraphRegistry
2924
2967
  };
2925
- //# sourceMappingURL=chunk-D6KU5MI7.mjs.map
2968
+ //# sourceMappingURL=chunk-5WPZCXNS.mjs.map