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