@knotx/core 0.2.9 → 0.2.10

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.
package/dist/index.cjs CHANGED
@@ -149,12 +149,12 @@ class Engine {
149
149
  __publicField$2(this, "nodes$", new rxjs.BehaviorSubject([]));
150
150
  __publicField$2(this, "edges$", new rxjs.BehaviorSubject([]));
151
151
  __publicField$2(this, "layers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
152
- __publicField$2(this, "plugins$", new rxjs.BehaviorSubject([]));
152
+ __publicField$2(this, "plugins$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
153
153
  __publicField$2(this, "nodeRenderers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
154
154
  __publicField$2(this, "edgeRenderers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
155
155
  __publicField$2(this, "_pluginDataContainer", {});
156
- __publicField$2(this, "toolParamsValidator", new jsonschema.Validator());
157
156
  __publicField$2(this, "_pluginToolsContainer", {});
157
+ __publicField$2(this, "toolParamsValidator", new jsonschema.Validator());
158
158
  var _a;
159
159
  this.runtime = (_a = options.runtime) != null ? _a : {};
160
160
  this.container$.next(options.container);
@@ -180,12 +180,12 @@ class Engine {
180
180
  return this.layers$.value;
181
181
  }
182
182
  get plugins() {
183
- return this.plugins$.value;
183
+ return Array.from(this.plugins$.value.values());
184
184
  }
185
185
  init(options) {
186
186
  const { plugins = [], pluginConfig = {}, nodes = [], edges = [] } = options;
187
- for (const Def of plugins) {
188
- const plugin = new Def(void 0);
187
+ for (const Plugin of plugins) {
188
+ const plugin = new Plugin(void 0);
189
189
  if (this._pluginDataContainer[plugin.name]) {
190
190
  console.warn(`Plugin ${plugin.name} already registered, please check the plugin definition`);
191
191
  continue;
@@ -197,11 +197,12 @@ class Engine {
197
197
  Reflect.set(plugin, engineSymbol, new rxjs.BehaviorSubject(null));
198
198
  }
199
199
  Reflect.get(plugin, engineSymbol).next(this);
200
- const currentPlugins = this.plugins$.value || [];
201
- this.plugins$.next([...currentPlugins, plugin]);
200
+ const pluginsMap = this.plugins$.value;
201
+ pluginsMap.set(plugin.name, plugin);
202
+ this.plugins$.next(pluginsMap);
202
203
  const currentLayers = this.layers$.value;
203
204
  getLayerRenders(plugin).forEach((component) => {
204
- const effectiveLayer = this.calculateEffectiveLayer(component.layer, component.offset);
205
+ const effectiveLayer = component.offset === void 0 ? component.layer : Math.max((component.layer >> 1) + 1, Math.min(component.layer << 1, component.layer + component.offset));
205
206
  const layerComponents = currentLayers.get(effectiveLayer) || [];
206
207
  currentLayers.set(effectiveLayer, [...layerComponents, component]);
207
208
  });
@@ -215,11 +216,6 @@ class Engine {
215
216
  this.nodesManager.init(nodes);
216
217
  this.edgesManager.init(edges);
217
218
  }
218
- calculateEffectiveLayer(layer, offset) {
219
- if (offset === void 0)
220
- return layer;
221
- return Math.max((layer >> 1) + 1, Math.min(layer << 1, layer + offset));
222
- }
223
219
  getLayerComponents(layer) {
224
220
  return this.layers$.value.get(layer) || [];
225
221
  }
@@ -231,7 +227,7 @@ class Engine {
231
227
  }
232
228
  changePluginConfig(pluginName, config) {
233
229
  var _a, _b;
234
- (_b = (_a = this.plugins$.value.find((plugin) => plugin.name === pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
230
+ (_b = (_a = this.plugins$.value.get(pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
235
231
  }
236
232
  dispatchNodeOperation(operation) {
237
233
  this.nodesManager.dispatch(operation);
@@ -239,6 +235,9 @@ class Engine {
239
235
  dispatchEdgeOperation(operation) {
240
236
  this.edgesManager.dispatch(operation);
241
237
  }
238
+ getPlugin(pluginName) {
239
+ return this.plugins$.value.get(pluginName);
240
+ }
242
241
  getNode(id) {
243
242
  return this.nodesManager.getData(id);
244
243
  }
@@ -317,7 +316,7 @@ class Engine {
317
316
  return tool(params);
318
317
  }
319
318
  listPlugins() {
320
- return this.plugins$.value.map((plugin) => ({
319
+ return Array.from(this.plugins$.value.values()).map((plugin) => ({
321
320
  name: plugin.name,
322
321
  description: plugin.description
323
322
  }));
@@ -357,7 +356,7 @@ class Engine {
357
356
  var _a;
358
357
  (_a = plugin.onDestroy) == null ? void 0 : _a.call(plugin);
359
358
  });
360
- this.plugins$.next([]);
359
+ this.plugins$.next(/* @__PURE__ */ new Map());
361
360
  this.container$.complete();
362
361
  this.layers$.complete();
363
362
  this.nodes$.complete();
package/dist/index.d.cts CHANGED
@@ -106,8 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
106
106
  private nodeRenderers$;
107
107
  private edgeRenderers$;
108
108
  private _pluginDataContainer;
109
- private toolParamsValidator;
110
109
  private _pluginToolsContainer;
110
+ private toolParamsValidator;
111
111
  get container(): Container;
112
112
  set container(value: Container);
113
113
  get nodes(): NodeData<any>[];
@@ -116,13 +116,13 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
116
116
  get plugins(): IPlugin<string, any, RenderType>[];
117
117
  constructor(options: EngineOptions);
118
118
  private init;
119
- private calculateEffectiveLayer;
120
119
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
121
120
  addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
121
  addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
123
122
  changePluginConfig(pluginName: string, config: Record<string, any>): void;
124
123
  dispatchNodeOperation(operation: DataOperation<NodeData>): void;
125
124
  dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
125
+ getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
126
126
  getNode(id: string): NodeData | undefined;
127
127
  getNodeDraft(id: string): NodeData | undefined;
128
128
  getNodes(): NodeData[];
package/dist/index.d.mts CHANGED
@@ -106,8 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
106
106
  private nodeRenderers$;
107
107
  private edgeRenderers$;
108
108
  private _pluginDataContainer;
109
- private toolParamsValidator;
110
109
  private _pluginToolsContainer;
110
+ private toolParamsValidator;
111
111
  get container(): Container;
112
112
  set container(value: Container);
113
113
  get nodes(): NodeData<any>[];
@@ -116,13 +116,13 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
116
116
  get plugins(): IPlugin<string, any, RenderType>[];
117
117
  constructor(options: EngineOptions);
118
118
  private init;
119
- private calculateEffectiveLayer;
120
119
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
121
120
  addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
121
  addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
123
122
  changePluginConfig(pluginName: string, config: Record<string, any>): void;
124
123
  dispatchNodeOperation(operation: DataOperation<NodeData>): void;
125
124
  dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
125
+ getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
126
126
  getNode(id: string): NodeData | undefined;
127
127
  getNodeDraft(id: string): NodeData | undefined;
128
128
  getNodes(): NodeData[];
package/dist/index.d.ts CHANGED
@@ -106,8 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
106
106
  private nodeRenderers$;
107
107
  private edgeRenderers$;
108
108
  private _pluginDataContainer;
109
- private toolParamsValidator;
110
109
  private _pluginToolsContainer;
110
+ private toolParamsValidator;
111
111
  get container(): Container;
112
112
  set container(value: Container);
113
113
  get nodes(): NodeData<any>[];
@@ -116,13 +116,13 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
116
116
  get plugins(): IPlugin<string, any, RenderType>[];
117
117
  constructor(options: EngineOptions);
118
118
  private init;
119
- private calculateEffectiveLayer;
120
119
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
121
120
  addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
121
  addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
123
122
  changePluginConfig(pluginName: string, config: Record<string, any>): void;
124
123
  dispatchNodeOperation(operation: DataOperation<NodeData>): void;
125
124
  dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
125
+ getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
126
126
  getNode(id: string): NodeData | undefined;
127
127
  getNodeDraft(id: string): NodeData | undefined;
128
128
  getNodes(): NodeData[];
package/dist/index.js CHANGED
@@ -149,12 +149,12 @@ class Engine {
149
149
  __publicField$2(this, "nodes$", new BehaviorSubject([]));
150
150
  __publicField$2(this, "edges$", new BehaviorSubject([]));
151
151
  __publicField$2(this, "layers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
152
- __publicField$2(this, "plugins$", new BehaviorSubject([]));
152
+ __publicField$2(this, "plugins$", new BehaviorSubject(/* @__PURE__ */ new Map()));
153
153
  __publicField$2(this, "nodeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
154
154
  __publicField$2(this, "edgeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
155
155
  __publicField$2(this, "_pluginDataContainer", {});
156
- __publicField$2(this, "toolParamsValidator", new Validator());
157
156
  __publicField$2(this, "_pluginToolsContainer", {});
157
+ __publicField$2(this, "toolParamsValidator", new Validator());
158
158
  var _a;
159
159
  this.runtime = (_a = options.runtime) != null ? _a : {};
160
160
  this.container$.next(options.container);
@@ -180,12 +180,12 @@ class Engine {
180
180
  return this.layers$.value;
181
181
  }
182
182
  get plugins() {
183
- return this.plugins$.value;
183
+ return Array.from(this.plugins$.value.values());
184
184
  }
185
185
  init(options) {
186
186
  const { plugins = [], pluginConfig = {}, nodes = [], edges = [] } = options;
187
- for (const Def of plugins) {
188
- const plugin = new Def(void 0);
187
+ for (const Plugin of plugins) {
188
+ const plugin = new Plugin(void 0);
189
189
  if (this._pluginDataContainer[plugin.name]) {
190
190
  console.warn(`Plugin ${plugin.name} already registered, please check the plugin definition`);
191
191
  continue;
@@ -197,11 +197,12 @@ class Engine {
197
197
  Reflect.set(plugin, engineSymbol, new BehaviorSubject(null));
198
198
  }
199
199
  Reflect.get(plugin, engineSymbol).next(this);
200
- const currentPlugins = this.plugins$.value || [];
201
- this.plugins$.next([...currentPlugins, plugin]);
200
+ const pluginsMap = this.plugins$.value;
201
+ pluginsMap.set(plugin.name, plugin);
202
+ this.plugins$.next(pluginsMap);
202
203
  const currentLayers = this.layers$.value;
203
204
  getLayerRenders(plugin).forEach((component) => {
204
- const effectiveLayer = this.calculateEffectiveLayer(component.layer, component.offset);
205
+ const effectiveLayer = component.offset === void 0 ? component.layer : Math.max((component.layer >> 1) + 1, Math.min(component.layer << 1, component.layer + component.offset));
205
206
  const layerComponents = currentLayers.get(effectiveLayer) || [];
206
207
  currentLayers.set(effectiveLayer, [...layerComponents, component]);
207
208
  });
@@ -215,11 +216,6 @@ class Engine {
215
216
  this.nodesManager.init(nodes);
216
217
  this.edgesManager.init(edges);
217
218
  }
218
- calculateEffectiveLayer(layer, offset) {
219
- if (offset === void 0)
220
- return layer;
221
- return Math.max((layer >> 1) + 1, Math.min(layer << 1, layer + offset));
222
- }
223
219
  getLayerComponents(layer) {
224
220
  return this.layers$.value.get(layer) || [];
225
221
  }
@@ -231,7 +227,7 @@ class Engine {
231
227
  }
232
228
  changePluginConfig(pluginName, config) {
233
229
  var _a, _b;
234
- (_b = (_a = this.plugins$.value.find((plugin) => plugin.name === pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
230
+ (_b = (_a = this.plugins$.value.get(pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
235
231
  }
236
232
  dispatchNodeOperation(operation) {
237
233
  this.nodesManager.dispatch(operation);
@@ -239,6 +235,9 @@ class Engine {
239
235
  dispatchEdgeOperation(operation) {
240
236
  this.edgesManager.dispatch(operation);
241
237
  }
238
+ getPlugin(pluginName) {
239
+ return this.plugins$.value.get(pluginName);
240
+ }
242
241
  getNode(id) {
243
242
  return this.nodesManager.getData(id);
244
243
  }
@@ -317,7 +316,7 @@ class Engine {
317
316
  return tool(params);
318
317
  }
319
318
  listPlugins() {
320
- return this.plugins$.value.map((plugin) => ({
319
+ return Array.from(this.plugins$.value.values()).map((plugin) => ({
321
320
  name: plugin.name,
322
321
  description: plugin.description
323
322
  }));
@@ -357,7 +356,7 @@ class Engine {
357
356
  var _a;
358
357
  (_a = plugin.onDestroy) == null ? void 0 : _a.call(plugin);
359
358
  });
360
- this.plugins$.next([]);
359
+ this.plugins$.next(/* @__PURE__ */ new Map());
361
360
  this.container$.complete();
362
361
  this.layers$.complete();
363
362
  this.nodes$.complete();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/core",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Core for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -46,14 +46,14 @@
46
46
  "jsonschema": "^1.5.0",
47
47
  "lodash-es": "^4.17.21",
48
48
  "rxjs": "^7.8.1",
49
- "@knotx/data": "0.2.9",
50
- "@knotx/utils": "0.2.9"
49
+ "@knotx/data": "0.2.10",
50
+ "@knotx/utils": "0.2.10"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/lodash-es": "^4.17.12",
54
- "@knotx/build-config": "0.2.9",
55
- "@knotx/eslint-config": "0.2.9",
56
- "@knotx/typescript-config": "0.2.9"
54
+ "@knotx/build-config": "0.2.10",
55
+ "@knotx/eslint-config": "0.2.10",
56
+ "@knotx/typescript-config": "0.2.10"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "unbuild",