@dxos/plugin-sheet 0.6.12-main.ed7cda7 → 0.6.12-main.f9d0246

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 (119) hide show
  1. package/dist/lib/browser/{SheetContainer-V4GCCZTX.mjs → SheetContainer-VISF3VUB.mjs} +6 -6
  2. package/dist/lib/browser/{SheetContainer-V4GCCZTX.mjs.map → SheetContainer-VISF3VUB.mjs.map} +3 -3
  3. package/dist/lib/browser/{chunk-T3NJFTD4.mjs → chunk-WZMOZKQZ.mjs} +2 -2
  4. package/dist/lib/browser/{chunk-T3NJFTD4.mjs.map → chunk-WZMOZKQZ.mjs.map} +3 -3
  5. package/dist/lib/browser/{chunk-6ZMQVB4Z.mjs → chunk-Z2XOOC2R.mjs} +81 -62
  6. package/dist/lib/browser/chunk-Z2XOOC2R.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-U2JHW3L6.mjs → chunk-ZLJ2GRE2.mjs} +173 -42
  8. package/dist/lib/browser/chunk-ZLJ2GRE2.mjs.map +7 -0
  9. package/dist/lib/browser/{graph-T27BOBOV.mjs → graph-4XFKIHRL.mjs} +4 -4
  10. package/dist/lib/browser/index.mjs +15 -13
  11. package/dist/lib/browser/index.mjs.map +3 -3
  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-2MEALQWW.cjs} +14 -14
  15. package/dist/lib/node/{SheetContainer-3ZY7MPWJ.cjs.map → SheetContainer-2MEALQWW.cjs.map} +3 -3
  16. package/dist/lib/node/{chunk-OTTD7FBK.cjs → chunk-6DQABRGJ.cjs} +192 -60
  17. package/dist/lib/node/chunk-6DQABRGJ.cjs.map +7 -0
  18. package/dist/lib/node/{chunk-Q3HBHPRL.cjs → chunk-AOP42UAA.cjs} +5 -5
  19. package/dist/lib/node/{chunk-Q3HBHPRL.cjs.map → chunk-AOP42UAA.cjs.map} +3 -3
  20. package/dist/lib/node/{chunk-DD6FIXWC.cjs → chunk-P5QYYEHQ.cjs} +86 -67
  21. package/dist/lib/node/chunk-P5QYYEHQ.cjs.map +7 -0
  22. package/dist/lib/node/{graph-SPKGX7W4.cjs → graph-2LRDUXBZ.cjs} +14 -14
  23. package/dist/lib/node/graph-2LRDUXBZ.cjs.map +7 -0
  24. package/dist/lib/node/index.cjs +25 -24
  25. package/dist/lib/node/index.cjs.map +3 -3
  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-RPSUSXWS.mjs} +6 -6
  30. package/dist/lib/node-esm/{SheetContainer-PXSJX6XK.mjs.map → SheetContainer-RPSUSXWS.mjs.map} +3 -3
  31. package/dist/lib/node-esm/{chunk-D6KU5MI7.mjs → chunk-4MM7THJW.mjs} +81 -62
  32. package/dist/lib/node-esm/chunk-4MM7THJW.mjs.map +7 -0
  33. package/dist/lib/node-esm/{chunk-7HVSOTGA.mjs → chunk-5RLTCIE2.mjs} +173 -42
  34. package/dist/lib/node-esm/chunk-5RLTCIE2.mjs.map +7 -0
  35. package/dist/lib/node-esm/{chunk-BMNA27EX.mjs → chunk-RR2AO4SM.mjs} +2 -2
  36. package/dist/lib/node-esm/{chunk-BMNA27EX.mjs.map → chunk-RR2AO4SM.mjs.map} +3 -3
  37. package/dist/lib/node-esm/{graph-U67IO4UC.mjs → graph-WG5EKOMO.mjs} +4 -4
  38. package/dist/lib/node-esm/index.mjs +15 -13
  39. package/dist/lib/node-esm/index.mjs.map +3 -3
  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/GridSheet/GridSheet.d.ts +3 -3
  44. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  45. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +1 -1
  46. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  47. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
  48. package/dist/types/src/components/Sheet/sheet-context.d.ts +3 -3
  49. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
  50. package/dist/types/src/components/SheetContainer.d.ts +1 -1
  51. package/dist/types/src/components/index.d.ts +1 -1
  52. package/dist/types/src/defs/types.d.ts.map +1 -1
  53. package/dist/types/src/defs/util.d.ts +1 -1
  54. package/dist/types/src/defs/util.d.ts.map +1 -1
  55. package/dist/types/src/extensions/compute.d.ts +5 -1
  56. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  57. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  58. package/dist/types/src/graph/async-function.d.ts +7 -1
  59. package/dist/types/src/graph/async-function.d.ts.map +1 -1
  60. package/dist/types/src/graph/compute-graph.d.ts +12 -9
  61. package/dist/types/src/graph/compute-graph.d.ts.map +1 -1
  62. package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -1
  63. package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
  64. package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
  65. package/dist/types/src/graph/compute-node.d.ts +9 -2
  66. package/dist/types/src/graph/compute-node.d.ts.map +1 -1
  67. package/dist/types/src/graph/edge-function.d.ts.map +1 -1
  68. package/dist/types/src/graph/{custom-function.d.ts → testing/custom-function.d.ts} +3 -1
  69. package/dist/types/src/graph/testing/custom-function.d.ts.map +1 -0
  70. package/dist/types/src/graph/testing/index.d.ts +2 -0
  71. package/dist/types/src/graph/testing/index.d.ts.map +1 -0
  72. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -1
  73. package/dist/types/src/hooks/useSheetModel.d.ts +2 -2
  74. package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -1
  75. package/dist/types/src/model/sheet-model.d.ts +3 -3
  76. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  77. package/dist/types/src/testing/testing.d.ts +4 -5
  78. package/dist/types/src/testing/testing.d.ts.map +1 -1
  79. package/dist/types/src/types.d.ts +4 -3
  80. package/dist/types/src/types.d.ts.map +1 -1
  81. package/package.json +33 -33
  82. package/src/SheetPlugin.tsx +9 -7
  83. package/src/components/CellEditor/CellEditor.stories.tsx +1 -1
  84. package/src/components/GridSheet/GridSheet.stories.tsx +5 -4
  85. package/src/components/GridSheet/GridSheet.tsx +4 -4
  86. package/src/components/Sheet/Sheet.stories.tsx +21 -20
  87. package/src/components/Sheet/sheet-context.tsx +4 -4
  88. package/src/components/SheetContainer.tsx +2 -2
  89. package/src/defs/types.ts +1 -0
  90. package/src/defs/util.ts +19 -3
  91. package/src/extensions/compute.stories.tsx +18 -16
  92. package/src/extensions/compute.ts +72 -39
  93. package/src/graph/async-function.ts +13 -6
  94. package/src/graph/compute-graph.stories.tsx +4 -3
  95. package/src/graph/compute-graph.test.ts +127 -0
  96. package/src/graph/compute-graph.ts +64 -41
  97. package/src/graph/compute-node.ts +16 -5
  98. package/src/graph/edge-function.ts +1 -2
  99. package/src/graph/{custom-function.ts → testing/custom-function.ts} +10 -2
  100. package/src/graph/testing/index.ts +5 -0
  101. package/src/hooks/hooks.stories.tsx +3 -3
  102. package/src/hooks/useComputeGraph.ts +2 -1
  103. package/src/hooks/useSheetModel.ts +4 -7
  104. package/src/model/sheet-model.ts +44 -29
  105. package/src/testing/testing.tsx +17 -15
  106. package/src/types.ts +3 -3
  107. package/dist/lib/browser/chunk-6ZMQVB4Z.mjs.map +0 -7
  108. package/dist/lib/browser/chunk-U2JHW3L6.mjs.map +0 -7
  109. package/dist/lib/node/chunk-DD6FIXWC.cjs.map +0 -7
  110. package/dist/lib/node/chunk-OTTD7FBK.cjs.map +0 -7
  111. package/dist/lib/node/graph-SPKGX7W4.cjs.map +0 -7
  112. package/dist/lib/node-esm/chunk-7HVSOTGA.mjs.map +0 -7
  113. package/dist/lib/node-esm/chunk-D6KU5MI7.mjs.map +0 -7
  114. package/dist/types/src/graph/compute-graph.browser.test.d.ts +0 -2
  115. package/dist/types/src/graph/compute-graph.browser.test.d.ts.map +0 -1
  116. package/dist/types/src/graph/custom-function.d.ts.map +0 -1
  117. package/src/graph/compute-graph.browser.test.ts +0 -104
  118. /package/dist/lib/browser/{graph-T27BOBOV.mjs.map → graph-4XFKIHRL.mjs.map} +0 -0
  119. /package/dist/lib/node-esm/{graph-U67IO4UC.mjs.map → graph-WG5EKOMO.mjs.map} +0 -0
@@ -1,6 +1,7 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // packages/plugins/plugin-sheet/src/graph/compute-graph.ts
4
+ import defaultsDeep2 from "lodash.defaultsdeep";
4
5
  import { Event as Event2 } from "@dxos/async";
5
6
  import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
6
7
  import { Resource as Resource2 } from "@dxos/context";
@@ -9,7 +10,7 @@ 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, HyperFormula } from "#hyperformula";
13
14
 
14
15
  // packages/plugins/plugin-sheet/src/graph/async-function.ts
15
16
  import defaultsDeep from "lodash.defaultsdeep";
@@ -30,7 +31,7 @@ var FunctionContext = class _FunctionContext {
30
31
  ...args
31
32
  });
32
33
  }
33
- constructor(_hf, _space, onUpdate, _options) {
34
+ constructor(_hf, _space, _options) {
34
35
  this._hf = _hf;
35
36
  this._space = _space;
36
37
  this._cache = /* @__PURE__ */ new Map();
@@ -38,12 +39,11 @@ var FunctionContext = class _FunctionContext {
38
39
  this._subscriptions = /* @__PURE__ */ new Map();
39
40
  this._invocations = {};
40
41
  this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
41
- this._onUpdate = debounce(() => {
42
+ this._onUpdate = debounce((update) => {
42
43
  this._hf.resumeEvaluation();
43
- onUpdate(this);
44
+ this._options.onUpdate?.(update);
44
45
  }, this._options.recalculationDelay);
45
46
  }
46
- // TODO(burdon): Remove?
47
47
  get space() {
48
48
  return this._space;
49
49
  }
@@ -92,18 +92,21 @@ var FunctionContext = class _FunctionContext {
92
92
  value: value2
93
93
  }, {
94
94
  F: __dxlog_file,
95
- L: 138,
95
+ L: 145,
96
96
  S: this,
97
97
  C: (f, a) => f(...a)
98
98
  });
99
- this._onUpdate();
99
+ this._onUpdate({
100
+ name,
101
+ cell
102
+ });
100
103
  } catch (err) {
101
104
  log.warn("failed", {
102
105
  cell,
103
106
  err
104
107
  }, {
105
108
  F: __dxlog_file,
106
- L: 142,
109
+ L: 149,
107
110
  S: this,
108
111
  C: (f, a) => f(...a)
109
112
  });
@@ -123,7 +126,7 @@ var FunctionContext = class _FunctionContext {
123
126
  cache: value
124
127
  }, {
125
128
  F: __dxlog_file,
126
- L: 150,
129
+ L: 157,
127
130
  S: this,
128
131
  C: (f, a) => f(...a)
129
132
  });
@@ -154,12 +157,11 @@ var ComputeNode = class extends Resource {
154
157
  this.sheetId = sheetId;
155
158
  this.update = new Event();
156
159
  }
157
- // TODO(burdon): Remove?
158
160
  get graph() {
159
161
  return this._graph;
160
162
  }
161
- get hf() {
162
- return this._graph.hf;
163
+ clear() {
164
+ this._graph.hf.clearSheet(this.sheetId);
163
165
  }
164
166
  getValue(cell) {
165
167
  const value = this._graph.hf.getCellValue({
@@ -184,6 +186,8 @@ var ComputeNode = class extends Resource {
184
186
  ]
185
187
  ]);
186
188
  }
189
+ async _open() {
190
+ }
187
191
  };
188
192
 
189
193
  // packages/plugins/plugin-sheet/src/graph/edge-function.ts
@@ -259,11 +263,7 @@ EdgeFunctionPlugin.implementedFunctions = {
259
263
  {
260
264
  argumentType: FunctionArgumentType.STRING
261
265
  },
262
- // Remote function arguments (currently supporting up to 9).
263
- {
264
- argumentType: FunctionArgumentType.ANY,
265
- optionalArg: true
266
- },
266
+ // Remote function arguments (currently supporting up to 8).
267
267
  {
268
268
  argumentType: FunctionArgumentType.ANY,
269
269
  optionalArg: true
@@ -2688,34 +2688,30 @@ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/s
2688
2688
  var OBJECT_ID_LENGTH = 60;
2689
2689
  var CUSTOM_FUNCTION = "ECHO";
2690
2690
  var defaultOptions = {
2691
- licenseKey: "gpl-v3",
2692
- plugins: [
2693
- {
2694
- plugin: EdgeFunctionPlugin,
2695
- translations: EdgeFunctionPluginTranslations
2696
- }
2697
- ]
2691
+ licenseKey: "gpl-v3"
2698
2692
  };
2693
+ var defaultPlugins = [
2694
+ {
2695
+ plugin: EdgeFunctionPlugin,
2696
+ translations: EdgeFunctionPluginTranslations
2697
+ }
2698
+ ];
2699
2699
  var PREFIX = "__";
2700
2700
  var createSheetName = (id) => `${PREFIX}${id}`;
2701
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
2702
  var ComputeGraphRegistry = class extends Resource2 {
2709
- constructor(_options = defaultOptions) {
2703
+ constructor(options = {
2704
+ plugins: defaultPlugins
2705
+ }) {
2710
2706
  super();
2711
- this._options = _options;
2712
- this._registry = /* @__PURE__ */ new Map();
2707
+ this._graphs = /* @__PURE__ */ new Map();
2708
+ this._options = defaultsDeep2({}, options, defaultOptions);
2713
2709
  this._options.plugins?.forEach(({ plugin, translations }) => {
2714
2710
  HyperFormula.registerFunctionPlugin(plugin, translations);
2715
2711
  });
2716
2712
  }
2717
2713
  getGraph(spaceId) {
2718
- return this._registry.get(spaceId);
2714
+ return this._graphs.get(spaceId);
2719
2715
  }
2720
2716
  async getOrCreateGraph(space) {
2721
2717
  let graph = this.getGraph(space.id);
@@ -2724,7 +2720,7 @@ var ComputeGraphRegistry = class extends Resource2 {
2724
2720
  space: space.id
2725
2721
  }, {
2726
2722
  F: __dxlog_file3,
2727
- L: 95,
2723
+ L: 93,
2728
2724
  S: this,
2729
2725
  C: (f, a) => f(...a)
2730
2726
  });
@@ -2733,21 +2729,26 @@ var ComputeGraphRegistry = class extends Resource2 {
2733
2729
  return graph;
2734
2730
  }
2735
2731
  async createGraph(space) {
2736
- invariant(!this._registry.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
2732
+ invariant(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`, {
2737
2733
  F: __dxlog_file3,
2738
- L: 103,
2734
+ L: 101,
2739
2735
  S: this,
2740
2736
  A: [
2741
- "!this._registry.has(space.id)",
2737
+ "!this._graphs.has(space.id)",
2742
2738
  "`ComputeGraph already exists for space: ${space.id}`"
2743
2739
  ]
2744
2740
  });
2745
2741
  const hf = HyperFormula.buildEmpty(this._options);
2746
2742
  const graph = new ComputeGraph(hf, space, this._options);
2747
- await graph.open(this._ctx);
2748
- this._registry.set(space.id, graph);
2743
+ this._graphs.set(space.id, graph);
2744
+ await graph.open();
2749
2745
  return graph;
2750
2746
  }
2747
+ async _close() {
2748
+ for (const graph of this._graphs.values()) {
2749
+ await graph.close();
2750
+ }
2751
+ }
2751
2752
  };
2752
2753
  var ComputeGraph = class extends Resource2 {
2753
2754
  constructor(_hf, _space, _options) {
@@ -2758,28 +2759,39 @@ var ComputeGraph = class extends Resource2 {
2758
2759
  this.id = `graph-${PublicKey.random().truncate()}`;
2759
2760
  this._nodes = /* @__PURE__ */ new Map();
2760
2761
  this._functions = [];
2761
- this.context = new FunctionContext(this._hf, this._space, this.refresh.bind(this), this._options);
2762
2762
  this.update = new Event2();
2763
+ this.context = new FunctionContext(this._hf, this._space, this._options);
2763
2764
  this._hf.updateConfig({
2764
2765
  context: this.context
2765
2766
  });
2767
+ const onValuesUpdate = (changes) => {
2768
+ for (const change of changes) {
2769
+ if (change instanceof ExportedCellChange) {
2770
+ const { sheet } = change;
2771
+ const node = this._nodes.get(sheet);
2772
+ if (node) {
2773
+ node.update.emit({
2774
+ type: "valuesUpdated",
2775
+ change
2776
+ });
2777
+ }
2778
+ }
2779
+ }
2780
+ };
2781
+ this._hf.on("valuesUpdated", onValuesUpdate);
2782
+ this._ctx.onDispose(() => this._hf.off("valuesUpdated", onValuesUpdate));
2766
2783
  }
2767
- // TODO(burdon): Remove.
2768
2784
  get hf() {
2769
2785
  return this._hf;
2770
2786
  }
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 } = {}) {
2787
+ // refresh() {
2788
+ // log('refresh', { id: this.id });
2789
+ // this.update.emit();
2790
+ // }
2791
+ getFunctions({ standard, echo } = {
2792
+ standard: true,
2793
+ echo: true
2794
+ }) {
2783
2795
  return [
2784
2796
  ...standard ? this._hf.getRegisteredFunctionNames().map((name) => defaultFunctions.find((fn) => fn.name === name) ?? {
2785
2797
  name
@@ -2797,10 +2809,10 @@ var ComputeGraph = class extends Resource2 {
2797
2809
  // This would enable on-the-fly instantiation of new models when then are referenced.
2798
2810
  // E.g., Cross-object reference would be stored as "ObjectId!A1"
2799
2811
  // The graph would then load the object and create a ComputeNode (model) of the appropriate type.
2800
- getOrCreateNode(name) {
2812
+ async getOrCreateNode(name) {
2801
2813
  invariant(name.length, void 0, {
2802
2814
  F: __dxlog_file3,
2803
- L: 176,
2815
+ L: 193,
2804
2816
  S: this,
2805
2817
  A: [
2806
2818
  "name.length",
@@ -2813,17 +2825,16 @@ var ComputeGraph = class extends Resource2 {
2813
2825
  name
2814
2826
  }, {
2815
2827
  F: __dxlog_file3,
2816
- L: 178,
2828
+ L: 195,
2817
2829
  S: this,
2818
2830
  C: (f, a) => f(...a)
2819
2831
  });
2820
2832
  this._hf.addSheet(name);
2821
- this.update.emit();
2822
2833
  }
2823
2834
  const sheetId = this._hf.getSheetId(name);
2824
2835
  invariant(sheetId !== void 0, void 0, {
2825
2836
  F: __dxlog_file3,
2826
- L: 184,
2837
+ L: 201,
2827
2838
  S: this,
2828
2839
  A: [
2829
2840
  "sheetId !== undefined",
@@ -2831,6 +2842,7 @@ var ComputeGraph = class extends Resource2 {
2831
2842
  ]
2832
2843
  });
2833
2844
  const node = new ComputeNode(this, sheetId);
2845
+ await node.open();
2834
2846
  this._nodes.set(sheetId, node);
2835
2847
  return node;
2836
2848
  }
@@ -2905,21 +2917,28 @@ var ComputeGraph = class extends Resource2 {
2905
2917
  const query = this._space.db.query(Filter2.schema(FunctionType2));
2906
2918
  const unsubscribe = query.subscribe(({ objects }) => {
2907
2919
  this._functions = objects.filter(({ binding }) => binding);
2908
- this.update.emit();
2920
+ this.update.emit({
2921
+ type: "functionsUpdated"
2922
+ });
2909
2923
  });
2910
2924
  this._ctx.onDispose(unsubscribe);
2911
2925
  }
2912
2926
  }
2927
+ async _close() {
2928
+ for (const node of this._nodes.values()) {
2929
+ await node.close();
2930
+ }
2931
+ }
2913
2932
  };
2914
2933
 
2915
2934
  export {
2916
2935
  ComputeNode,
2917
2936
  defaultFunctions,
2918
2937
  defaultOptions,
2938
+ defaultPlugins,
2919
2939
  createSheetName,
2920
2940
  getSheetId,
2921
- createComputeGraphRegistry,
2922
2941
  ComputeGraphRegistry,
2923
2942
  ComputeGraph
2924
2943
  };
2925
- //# sourceMappingURL=chunk-D6KU5MI7.mjs.map
2944
+ //# sourceMappingURL=chunk-4MM7THJW.mjs.map