@knotx/core 0.2.9 → 0.2.11

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.
@@ -1,4 +1,4 @@
1
1
  import 'jsonschema';
2
2
  import 'rxjs';
3
- export { C as Container, E as EdgeData, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, g as IPluginInfo, h as IPluginToolInfo, b as Layer, L as LayerComponent, N as NodeData, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, c as NodeRenderType, P as Plugin, n as PluginConfigs, e as PluginData, f as PluginTools, m as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BUBec6Va.cjs';
3
+ export { C as Container, E as Edge, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, e as EdgeRenderType, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, h as IPluginInfo, i as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, d as NodeRenderType, P as Plugin, o as PluginConfigs, f as PluginData, g as PluginTools, n as Position, R as RenderType, V as VerticalAlignment } from './shared/core.CgVCXkyd.cjs';
4
4
  import '@knotx/data';
@@ -1,4 +1,4 @@
1
1
  import 'jsonschema';
2
2
  import 'rxjs';
3
- export { C as Container, E as EdgeData, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, g as IPluginInfo, h as IPluginToolInfo, b as Layer, L as LayerComponent, N as NodeData, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, c as NodeRenderType, P as Plugin, n as PluginConfigs, e as PluginData, f as PluginTools, m as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BUBec6Va.mjs';
3
+ export { C as Container, E as Edge, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, e as EdgeRenderType, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, h as IPluginInfo, i as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, d as NodeRenderType, P as Plugin, o as PluginConfigs, f as PluginData, g as PluginTools, n as Position, R as RenderType, V as VerticalAlignment } from './shared/core.CgVCXkyd.mjs';
4
4
  import '@knotx/data';
@@ -1,4 +1,4 @@
1
1
  import 'jsonschema';
2
2
  import 'rxjs';
3
- export { C as Container, E as EdgeData, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, d as EdgeRenderType, H as HorizontalAlignment, I as IEngineRuntime, a as IPlugin, g as IPluginInfo, h as IPluginToolInfo, b as Layer, L as LayerComponent, N as NodeData, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, c as NodeRenderType, P as Plugin, n as PluginConfigs, e as PluginData, f as PluginTools, m as Position, R as RenderType, V as VerticalAlignment } from './shared/core.BUBec6Va.js';
3
+ export { C as Container, E as Edge, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, e as EdgeRenderType, H as HorizontalAlignment, a as IEngineRuntime, b as IPlugin, h as IPluginInfo, i as IPluginToolInfo, I as IRecord, c as Layer, L as LayerComponent, N as Node, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, d as NodeRenderType, P as Plugin, o as PluginConfigs, f as PluginData, g as PluginTools, n as Position, R as RenderType, V as VerticalAlignment } from './shared/core.CgVCXkyd.js';
4
4
  import '@knotx/data';
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
  }
@@ -304,12 +303,13 @@ class Engine {
304
303
  endInteraction(pluginId, type) {
305
304
  this.interactionManager.endInteraction(pluginId, type);
306
305
  }
307
- callTool(pluginName, toolName, params) {
306
+ callTool(pluginName, toolName, ...args) {
308
307
  const toolDefinition = lodashEs.get(this, ["_pluginToolsContainer", pluginName, toolName]);
309
308
  const tool = toolDefinition == null ? void 0 : toolDefinition.func;
310
309
  if (!tool || typeof tool !== "function") {
311
310
  throw new Error(`Tool ${String(toolName)} not found in plugin ${pluginName}`);
312
311
  }
312
+ const params = args[0];
313
313
  const validator = this.toolParamsValidator.validate(params, toolDefinition.params);
314
314
  if (validator.errors.length > 0) {
315
315
  throw new Error(`Invalid tool params: ${validator.errors.map((e) => e.stack).join(", ")}`);
@@ -317,7 +317,7 @@ class Engine {
317
317
  return tool(params);
318
318
  }
319
319
  listPlugins() {
320
- return this.plugins$.value.map((plugin) => ({
320
+ return Array.from(this.plugins$.value.values()).map((plugin) => ({
321
321
  name: plugin.name,
322
322
  description: plugin.description
323
323
  }));
@@ -357,7 +357,7 @@ class Engine {
357
357
  var _a;
358
358
  (_a = plugin.onDestroy) == null ? void 0 : _a.call(plugin);
359
359
  });
360
- this.plugins$.next([]);
360
+ this.plugins$.next(/* @__PURE__ */ new Map());
361
361
  this.container$.complete();
362
362
  this.layers$.complete();
363
363
  this.nodes$.complete();
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData, f as PluginTools, g as IPluginInfo, h as IPluginToolInfo } from './shared/core.BUBec6Va.cjs';
2
- export { B as BasePlugin, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, H as HorizontalAlignment, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, n as PluginConfigs, m as Position, V as VerticalAlignment } from './shared/core.BUBec6Va.cjs';
1
+ import { I as IRecord, C as Container, P as Plugin, N as Node, E as Edge, a as IEngineRuntime, R as RenderType, L as LayerComponent, b as IPlugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as IPluginInfo, i as IPluginToolInfo } from './shared/core.CgVCXkyd.cjs';
2
+ export { B as BasePlugin, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, H as HorizontalAlignment, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, o as PluginConfigs, n as Position, V as VerticalAlignment } from './shared/core.CgVCXkyd.cjs';
3
3
  import { Schema } from 'jsonschema';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
@@ -85,19 +85,19 @@ declare class InteractionManager {
85
85
  private updateActive;
86
86
  }
87
87
 
88
- interface EngineOptions {
88
+ interface EngineOptions<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
89
89
  container: Container;
90
90
  plugins?: Plugin[];
91
- pluginConfig?: Record<string, any>;
92
- nodes?: NodeData[];
93
- edges?: EdgeData[];
91
+ pluginConfig?: IRecord;
92
+ nodes?: Node<TNode>[];
93
+ edges?: Edge<TEdge>[];
94
94
  runtime?: IEngineRuntime;
95
95
  }
96
- declare class Engine<TRenderType extends RenderType = RenderType> {
96
+ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
97
97
  readonly runtime: IEngineRuntime;
98
98
  readonly interactionManager: InteractionManager;
99
- readonly nodesManager: DataManager<NodeData>;
100
- readonly edgesManager: DataManager<EdgeData>;
99
+ readonly nodesManager: DataManager<Node<TNode>>;
100
+ readonly edgesManager: DataManager<Edge<TEdge>>;
101
101
  private container$;
102
102
  private nodes$;
103
103
  private edges$;
@@ -106,30 +106,30 @@ 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
- get nodes(): NodeData<any>[];
114
- get edges(): EdgeData<any>[];
113
+ get nodes(): Node<TNode>[];
114
+ get edges(): Edge<TEdge>[];
115
115
  get layers(): Map<number, LayerComponent<TRenderType>[]>;
116
116
  get plugins(): IPlugin<string, any, RenderType>[];
117
- constructor(options: EngineOptions);
117
+ constructor(options: EngineOptions<TNode, TEdge>);
118
118
  private init;
119
- private calculateEffectiveLayer;
120
119
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
121
- addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
- addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
123
- changePluginConfig(pluginName: string, config: Record<string, any>): void;
124
- dispatchNodeOperation(operation: DataOperation<NodeData>): void;
125
- dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
126
- getNode(id: string): NodeData | undefined;
127
- getNodeDraft(id: string): NodeData | undefined;
128
- getNodes(): NodeData[];
120
+ addNodePipe(pipe: DataOperationPipe<Node<TNode>>): () => void;
121
+ addEdgePipe(pipe: DataOperationPipe<Edge<TEdge>>): () => void;
122
+ changePluginConfig(pluginName: string, config: IRecord): void;
123
+ dispatchNodeOperation(operation: DataOperation<Node<TNode>>): void;
124
+ dispatchEdgeOperation(operation: DataOperation<Edge<TEdge>>): void;
125
+ getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
126
+ getNode(id: string): Node<TNode> | undefined;
127
+ getNodeDraft(id: string): Node<TNode> | undefined;
128
+ getNodes(): Node<TNode>[];
129
129
  getNodeRenderer(type: string): NodeRenderType | undefined;
130
- getEdge(id: string): EdgeData | undefined;
131
- getEdgeDraft(id: string): EdgeData | undefined;
132
- getEdges(): EdgeData[];
130
+ getEdge(id: string): Edge<TEdge> | undefined;
131
+ getEdgeDraft(id: string): Edge<TEdge> | undefined;
132
+ getEdges(): Edge<TEdge>[];
133
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
134
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
135
135
  resetPluginData<T extends keyof PluginData>(pluginName: T): void;
@@ -144,7 +144,7 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
144
144
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
145
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
146
146
  endInteraction(pluginId: string, type: string): void;
147
- callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, params: any): any;
147
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): any;
148
148
  listPlugins(): IPluginInfo[];
149
149
  listPluginTools(pluginName: string): IPluginToolInfo[];
150
150
  listEngineTools(): IPluginToolInfo[];
@@ -214,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
214
214
  __contextValue__: TContext;
215
215
  }, context: TContext): T;
216
216
 
217
- export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
217
+ export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData, f as PluginTools, g as IPluginInfo, h as IPluginToolInfo } from './shared/core.BUBec6Va.mjs';
2
- export { B as BasePlugin, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, H as HorizontalAlignment, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, n as PluginConfigs, m as Position, V as VerticalAlignment } from './shared/core.BUBec6Va.mjs';
1
+ import { I as IRecord, C as Container, P as Plugin, N as Node, E as Edge, a as IEngineRuntime, R as RenderType, L as LayerComponent, b as IPlugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as IPluginInfo, i as IPluginToolInfo } from './shared/core.CgVCXkyd.mjs';
2
+ export { B as BasePlugin, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, H as HorizontalAlignment, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, o as PluginConfigs, n as Position, V as VerticalAlignment } from './shared/core.CgVCXkyd.mjs';
3
3
  import { Schema } from 'jsonschema';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
@@ -85,19 +85,19 @@ declare class InteractionManager {
85
85
  private updateActive;
86
86
  }
87
87
 
88
- interface EngineOptions {
88
+ interface EngineOptions<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
89
89
  container: Container;
90
90
  plugins?: Plugin[];
91
- pluginConfig?: Record<string, any>;
92
- nodes?: NodeData[];
93
- edges?: EdgeData[];
91
+ pluginConfig?: IRecord;
92
+ nodes?: Node<TNode>[];
93
+ edges?: Edge<TEdge>[];
94
94
  runtime?: IEngineRuntime;
95
95
  }
96
- declare class Engine<TRenderType extends RenderType = RenderType> {
96
+ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
97
97
  readonly runtime: IEngineRuntime;
98
98
  readonly interactionManager: InteractionManager;
99
- readonly nodesManager: DataManager<NodeData>;
100
- readonly edgesManager: DataManager<EdgeData>;
99
+ readonly nodesManager: DataManager<Node<TNode>>;
100
+ readonly edgesManager: DataManager<Edge<TEdge>>;
101
101
  private container$;
102
102
  private nodes$;
103
103
  private edges$;
@@ -106,30 +106,30 @@ 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
- get nodes(): NodeData<any>[];
114
- get edges(): EdgeData<any>[];
113
+ get nodes(): Node<TNode>[];
114
+ get edges(): Edge<TEdge>[];
115
115
  get layers(): Map<number, LayerComponent<TRenderType>[]>;
116
116
  get plugins(): IPlugin<string, any, RenderType>[];
117
- constructor(options: EngineOptions);
117
+ constructor(options: EngineOptions<TNode, TEdge>);
118
118
  private init;
119
- private calculateEffectiveLayer;
120
119
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
121
- addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
- addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
123
- changePluginConfig(pluginName: string, config: Record<string, any>): void;
124
- dispatchNodeOperation(operation: DataOperation<NodeData>): void;
125
- dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
126
- getNode(id: string): NodeData | undefined;
127
- getNodeDraft(id: string): NodeData | undefined;
128
- getNodes(): NodeData[];
120
+ addNodePipe(pipe: DataOperationPipe<Node<TNode>>): () => void;
121
+ addEdgePipe(pipe: DataOperationPipe<Edge<TEdge>>): () => void;
122
+ changePluginConfig(pluginName: string, config: IRecord): void;
123
+ dispatchNodeOperation(operation: DataOperation<Node<TNode>>): void;
124
+ dispatchEdgeOperation(operation: DataOperation<Edge<TEdge>>): void;
125
+ getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
126
+ getNode(id: string): Node<TNode> | undefined;
127
+ getNodeDraft(id: string): Node<TNode> | undefined;
128
+ getNodes(): Node<TNode>[];
129
129
  getNodeRenderer(type: string): NodeRenderType | undefined;
130
- getEdge(id: string): EdgeData | undefined;
131
- getEdgeDraft(id: string): EdgeData | undefined;
132
- getEdges(): EdgeData[];
130
+ getEdge(id: string): Edge<TEdge> | undefined;
131
+ getEdgeDraft(id: string): Edge<TEdge> | undefined;
132
+ getEdges(): Edge<TEdge>[];
133
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
134
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
135
135
  resetPluginData<T extends keyof PluginData>(pluginName: T): void;
@@ -144,7 +144,7 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
144
144
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
145
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
146
146
  endInteraction(pluginId: string, type: string): void;
147
- callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, params: any): any;
147
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): any;
148
148
  listPlugins(): IPluginInfo[];
149
149
  listPluginTools(pluginName: string): IPluginToolInfo[];
150
150
  listEngineTools(): IPluginToolInfo[];
@@ -214,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
214
214
  __contextValue__: TContext;
215
215
  }, context: TContext): T;
216
216
 
217
- export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
217
+ export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as Container, P as Plugin, N as NodeData, E as EdgeData, I as IEngineRuntime, R as RenderType, L as LayerComponent, a as IPlugin, b as Layer, c as NodeRenderType, d as EdgeRenderType, e as PluginData, f as PluginTools, g as IPluginInfo, h as IPluginToolInfo } from './shared/core.BUBec6Va.js';
2
- export { B as BasePlugin, r as EdgeOperation, p as EdgeOperationPipe, t as EdgeOperatorFunction, l as EdgeProps, H as HorizontalAlignment, j as NodeMeasured, q as NodeOperation, o as NodeOperationPipe, s as NodeOperatorFunction, i as NodePosition, k as NodeProps, n as PluginConfigs, m as Position, V as VerticalAlignment } from './shared/core.BUBec6Va.js';
1
+ import { I as IRecord, C as Container, P as Plugin, N as Node, E as Edge, a as IEngineRuntime, R as RenderType, L as LayerComponent, b as IPlugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as IPluginInfo, i as IPluginToolInfo } from './shared/core.CgVCXkyd.js';
2
+ export { B as BasePlugin, s as EdgeOperation, q as EdgeOperationPipe, u as EdgeOperatorFunction, m as EdgeProps, H as HorizontalAlignment, k as NodeMeasured, r as NodeOperation, p as NodeOperationPipe, t as NodeOperatorFunction, j as NodePosition, l as NodeProps, o as PluginConfigs, n as Position, V as VerticalAlignment } from './shared/core.CgVCXkyd.js';
3
3
  import { Schema } from 'jsonschema';
4
4
  import { BehaviorSubject } from 'rxjs';
5
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
@@ -85,19 +85,19 @@ declare class InteractionManager {
85
85
  private updateActive;
86
86
  }
87
87
 
88
- interface EngineOptions {
88
+ interface EngineOptions<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
89
89
  container: Container;
90
90
  plugins?: Plugin[];
91
- pluginConfig?: Record<string, any>;
92
- nodes?: NodeData[];
93
- edges?: EdgeData[];
91
+ pluginConfig?: IRecord;
92
+ nodes?: Node<TNode>[];
93
+ edges?: Edge<TEdge>[];
94
94
  runtime?: IEngineRuntime;
95
95
  }
96
- declare class Engine<TRenderType extends RenderType = RenderType> {
96
+ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
97
97
  readonly runtime: IEngineRuntime;
98
98
  readonly interactionManager: InteractionManager;
99
- readonly nodesManager: DataManager<NodeData>;
100
- readonly edgesManager: DataManager<EdgeData>;
99
+ readonly nodesManager: DataManager<Node<TNode>>;
100
+ readonly edgesManager: DataManager<Edge<TEdge>>;
101
101
  private container$;
102
102
  private nodes$;
103
103
  private edges$;
@@ -106,30 +106,30 @@ 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
- get nodes(): NodeData<any>[];
114
- get edges(): EdgeData<any>[];
113
+ get nodes(): Node<TNode>[];
114
+ get edges(): Edge<TEdge>[];
115
115
  get layers(): Map<number, LayerComponent<TRenderType>[]>;
116
116
  get plugins(): IPlugin<string, any, RenderType>[];
117
- constructor(options: EngineOptions);
117
+ constructor(options: EngineOptions<TNode, TEdge>);
118
118
  private init;
119
- private calculateEffectiveLayer;
120
119
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
121
- addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
- addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
123
- changePluginConfig(pluginName: string, config: Record<string, any>): void;
124
- dispatchNodeOperation(operation: DataOperation<NodeData>): void;
125
- dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
126
- getNode(id: string): NodeData | undefined;
127
- getNodeDraft(id: string): NodeData | undefined;
128
- getNodes(): NodeData[];
120
+ addNodePipe(pipe: DataOperationPipe<Node<TNode>>): () => void;
121
+ addEdgePipe(pipe: DataOperationPipe<Edge<TEdge>>): () => void;
122
+ changePluginConfig(pluginName: string, config: IRecord): void;
123
+ dispatchNodeOperation(operation: DataOperation<Node<TNode>>): void;
124
+ dispatchEdgeOperation(operation: DataOperation<Edge<TEdge>>): void;
125
+ getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
126
+ getNode(id: string): Node<TNode> | undefined;
127
+ getNodeDraft(id: string): Node<TNode> | undefined;
128
+ getNodes(): Node<TNode>[];
129
129
  getNodeRenderer(type: string): NodeRenderType | undefined;
130
- getEdge(id: string): EdgeData | undefined;
131
- getEdgeDraft(id: string): EdgeData | undefined;
132
- getEdges(): EdgeData[];
130
+ getEdge(id: string): Edge<TEdge> | undefined;
131
+ getEdgeDraft(id: string): Edge<TEdge> | undefined;
132
+ getEdges(): Edge<TEdge>[];
133
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
134
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
135
135
  resetPluginData<T extends keyof PluginData>(pluginName: T): void;
@@ -144,7 +144,7 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
144
144
  canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
145
  startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
146
146
  endInteraction(pluginId: string, type: string): void;
147
- callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, params: any): any;
147
+ callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): any;
148
148
  listPlugins(): IPluginInfo[];
149
149
  listPluginTools(pluginName: string): IPluginToolInfo[];
150
150
  listEngineTools(): IPluginToolInfo[];
@@ -214,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
214
214
  __contextValue__: TContext;
215
215
  }, context: TContext): T;
216
216
 
217
- export { Container, EdgeData, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, NodeData, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
217
+ export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
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
  }
@@ -304,12 +303,13 @@ class Engine {
304
303
  endInteraction(pluginId, type) {
305
304
  this.interactionManager.endInteraction(pluginId, type);
306
305
  }
307
- callTool(pluginName, toolName, params) {
306
+ callTool(pluginName, toolName, ...args) {
308
307
  const toolDefinition = get(this, ["_pluginToolsContainer", pluginName, toolName]);
309
308
  const tool = toolDefinition == null ? void 0 : toolDefinition.func;
310
309
  if (!tool || typeof tool !== "function") {
311
310
  throw new Error(`Tool ${String(toolName)} not found in plugin ${pluginName}`);
312
311
  }
312
+ const params = args[0];
313
313
  const validator = this.toolParamsValidator.validate(params, toolDefinition.params);
314
314
  if (validator.errors.length > 0) {
315
315
  throw new Error(`Invalid tool params: ${validator.errors.map((e) => e.stack).join(", ")}`);
@@ -317,7 +317,7 @@ class Engine {
317
317
  return tool(params);
318
318
  }
319
319
  listPlugins() {
320
- return this.plugins$.value.map((plugin) => ({
320
+ return Array.from(this.plugins$.value.values()).map((plugin) => ({
321
321
  name: plugin.name,
322
322
  description: plugin.description
323
323
  }));
@@ -357,7 +357,7 @@ class Engine {
357
357
  var _a;
358
358
  (_a = plugin.onDestroy) == null ? void 0 : _a.call(plugin);
359
359
  });
360
- this.plugins$.next([]);
360
+ this.plugins$.next(/* @__PURE__ */ new Map());
361
361
  this.container$.complete();
362
362
  this.layers$.complete();
363
363
  this.nodes$.complete();
@@ -2,7 +2,7 @@ import { Schema } from 'jsonschema';
2
2
  import { SubscriptionLike, BehaviorSubject } from 'rxjs';
3
3
  import { DataOperationPipe, DataOperation } from '@knotx/data';
4
4
 
5
- declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
5
+ declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends IRecord | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
6
6
  abstract name: TPluginName;
7
7
  constructor(__: TPluginConfig);
8
8
  private static _instanceId;
@@ -18,6 +18,7 @@ declare abstract class BasePlugin<TPluginName extends string = string, TPluginCo
18
18
 
19
19
  type HorizontalAlignment = 'left' | 'right';
20
20
  type VerticalAlignment = 'top' | 'bottom';
21
+ type IRecord = Record<string, any>;
21
22
  interface NodePosition {
22
23
  x: number;
23
24
  y: number;
@@ -26,25 +27,25 @@ interface NodeMeasured {
26
27
  width: number;
27
28
  height: number;
28
29
  }
29
- interface NodeData<TData = any> {
30
+ interface Node<TData extends IRecord = IRecord> {
30
31
  id: string;
31
32
  type?: string;
32
33
  position: NodePosition;
33
34
  measured?: NodeMeasured;
34
35
  data: TData;
35
36
  }
36
- interface NodeProps<T = any> {
37
- node: NodeData<T>;
37
+ interface NodeProps<TData extends IRecord = IRecord> {
38
+ node: Node<TData>;
38
39
  }
39
- interface EdgeData<TData = any> {
40
+ interface Edge<TData extends IRecord = IRecord> {
40
41
  id: string;
41
42
  source: string;
42
43
  target: string;
43
44
  type?: string;
44
45
  data?: TData;
45
46
  }
46
- interface EdgeProps<T = any> {
47
- edge: EdgeData<T>;
47
+ interface EdgeProps<TData extends IRecord = IRecord> {
48
+ edge: Edge<TData>;
48
49
  sourceX: number;
49
50
  sourceY: number;
50
51
  targetX: number;
@@ -56,8 +57,8 @@ interface Container {
56
57
  }
57
58
  type Position = 'top' | 'right' | 'bottom' | 'left';
58
59
  type RenderType = (...args: any[]) => any;
59
- type NodeRenderType<TD extends Record<string, any> = any, TR = any> = (props: NodeProps<TD>) => TR;
60
- type EdgeRenderType<TD extends Record<string, any> = any, TR = any> = (props: EdgeProps<TD>) => TR;
60
+ type NodeRenderType<TD extends IRecord = any, TR = any> = (props: NodeProps<TD>) => TR;
61
+ type EdgeRenderType<TD extends IRecord = any, TR = any> = (props: EdgeProps<TD>) => TR;
61
62
  declare enum Layer {
62
63
  Canvas = 0,
63
64
  Background = 4,
@@ -77,7 +78,7 @@ interface LayerComponent<TRenderType> {
77
78
  */
78
79
  offset?: number;
79
80
  }
80
- interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
81
+ interface IPlugin<TPluginName extends string = string, TPluginConfig extends IRecord | undefined = any, TRenderType extends RenderType = RenderType> {
81
82
  name: TPluginName;
82
83
  pluginId: string;
83
84
  description?: string;
@@ -86,7 +87,7 @@ interface IPlugin<TPluginName extends string = string, TPluginConfig extends Rec
86
87
  onDestroy?: () => void;
87
88
  render?: (...args: Parameters<TRenderType>) => ReturnType<TRenderType>;
88
89
  }
89
- type Plugin<TName extends string = string, TConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
90
+ type Plugin<TName extends string = string, TConfig extends IRecord | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
90
91
  type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugin<infer T> ? {
91
92
  [TName in T as Extract<TPlugins[number], Plugin<TName>> extends Plugin<TName, undefined> ? never : TName]: Extract<TPlugins[number], Plugin<TName>> extends infer T ? T extends Plugin<TName, infer TConfig> ? TConfig : never : never;
92
93
  } : {}));
@@ -126,12 +127,12 @@ interface IPluginToolInfo {
126
127
  description: string;
127
128
  parameters: Schema;
128
129
  }
129
- type NodeOperationPipe<T = any> = DataOperationPipe<NodeData<T>>;
130
- type EdgeOperationPipe<T = any> = DataOperationPipe<EdgeData<T>>;
131
- type NodeOperation<T = any> = DataOperation<NodeData<T>>;
132
- type EdgeOperation<T = any> = DataOperation<EdgeData<T>>;
133
- type NodeOperatorFunction<T = any, Args extends any[] = any[]> = (...args: Args) => NodeOperation<T>[];
134
- type EdgeOperatorFunction<T = any, Args extends any[] = any[]> = (...args: Args) => EdgeOperation<T>[];
130
+ type NodeOperationPipe<T extends IRecord = IRecord> = DataOperationPipe<Node<T>>;
131
+ type EdgeOperationPipe<T extends IRecord = IRecord> = DataOperationPipe<Edge<T>>;
132
+ type NodeOperation<T extends IRecord = IRecord> = DataOperation<Node<T>>;
133
+ type EdgeOperation<T extends IRecord = IRecord> = DataOperation<Edge<T>>;
134
+ type NodeOperatorFunction<T extends IRecord = IRecord, TArgs extends any[] = any[]> = (...args: TArgs) => NodeOperation<T>[];
135
+ type EdgeOperatorFunction<T extends IRecord = IRecord, TArgs extends any[] = any[]> = (...args: TArgs) => EdgeOperation<T>[];
135
136
  interface IEngineRuntime {
136
137
  render?: {
137
138
  getValue: <T, R = T>(value: BehaviorSubject<T> | T, options: {
@@ -142,4 +143,4 @@ interface IEngineRuntime {
142
143
  };
143
144
  }
144
145
 
145
- export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type PluginTools as f, type IPluginInfo as g, type IPluginToolInfo as h, type NodePosition as i, type NodeMeasured as j, type NodeProps as k, type EdgeProps as l, type Position as m, type PluginConfigs as n, type NodeOperationPipe as o, type EdgeOperationPipe as p, type NodeOperation as q, type EdgeOperation as r, type NodeOperatorFunction as s, type EdgeOperatorFunction as t };
146
+ export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type IPluginInfo as h, type IPluginToolInfo as i, type NodePosition as j, type NodeMeasured as k, type NodeProps as l, type EdgeProps as m, type Position as n, type PluginConfigs as o, type NodeOperationPipe as p, type EdgeOperationPipe as q, type NodeOperation as r, type EdgeOperation as s, type NodeOperatorFunction as t, type EdgeOperatorFunction as u };
@@ -2,7 +2,7 @@ import { Schema } from 'jsonschema';
2
2
  import { SubscriptionLike, BehaviorSubject } from 'rxjs';
3
3
  import { DataOperationPipe, DataOperation } from '@knotx/data';
4
4
 
5
- declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
5
+ declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends IRecord | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
6
6
  abstract name: TPluginName;
7
7
  constructor(__: TPluginConfig);
8
8
  private static _instanceId;
@@ -18,6 +18,7 @@ declare abstract class BasePlugin<TPluginName extends string = string, TPluginCo
18
18
 
19
19
  type HorizontalAlignment = 'left' | 'right';
20
20
  type VerticalAlignment = 'top' | 'bottom';
21
+ type IRecord = Record<string, any>;
21
22
  interface NodePosition {
22
23
  x: number;
23
24
  y: number;
@@ -26,25 +27,25 @@ interface NodeMeasured {
26
27
  width: number;
27
28
  height: number;
28
29
  }
29
- interface NodeData<TData = any> {
30
+ interface Node<TData extends IRecord = IRecord> {
30
31
  id: string;
31
32
  type?: string;
32
33
  position: NodePosition;
33
34
  measured?: NodeMeasured;
34
35
  data: TData;
35
36
  }
36
- interface NodeProps<T = any> {
37
- node: NodeData<T>;
37
+ interface NodeProps<TData extends IRecord = IRecord> {
38
+ node: Node<TData>;
38
39
  }
39
- interface EdgeData<TData = any> {
40
+ interface Edge<TData extends IRecord = IRecord> {
40
41
  id: string;
41
42
  source: string;
42
43
  target: string;
43
44
  type?: string;
44
45
  data?: TData;
45
46
  }
46
- interface EdgeProps<T = any> {
47
- edge: EdgeData<T>;
47
+ interface EdgeProps<TData extends IRecord = IRecord> {
48
+ edge: Edge<TData>;
48
49
  sourceX: number;
49
50
  sourceY: number;
50
51
  targetX: number;
@@ -56,8 +57,8 @@ interface Container {
56
57
  }
57
58
  type Position = 'top' | 'right' | 'bottom' | 'left';
58
59
  type RenderType = (...args: any[]) => any;
59
- type NodeRenderType<TD extends Record<string, any> = any, TR = any> = (props: NodeProps<TD>) => TR;
60
- type EdgeRenderType<TD extends Record<string, any> = any, TR = any> = (props: EdgeProps<TD>) => TR;
60
+ type NodeRenderType<TD extends IRecord = any, TR = any> = (props: NodeProps<TD>) => TR;
61
+ type EdgeRenderType<TD extends IRecord = any, TR = any> = (props: EdgeProps<TD>) => TR;
61
62
  declare enum Layer {
62
63
  Canvas = 0,
63
64
  Background = 4,
@@ -77,7 +78,7 @@ interface LayerComponent<TRenderType> {
77
78
  */
78
79
  offset?: number;
79
80
  }
80
- interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
81
+ interface IPlugin<TPluginName extends string = string, TPluginConfig extends IRecord | undefined = any, TRenderType extends RenderType = RenderType> {
81
82
  name: TPluginName;
82
83
  pluginId: string;
83
84
  description?: string;
@@ -86,7 +87,7 @@ interface IPlugin<TPluginName extends string = string, TPluginConfig extends Rec
86
87
  onDestroy?: () => void;
87
88
  render?: (...args: Parameters<TRenderType>) => ReturnType<TRenderType>;
88
89
  }
89
- type Plugin<TName extends string = string, TConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
90
+ type Plugin<TName extends string = string, TConfig extends IRecord | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
90
91
  type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugin<infer T> ? {
91
92
  [TName in T as Extract<TPlugins[number], Plugin<TName>> extends Plugin<TName, undefined> ? never : TName]: Extract<TPlugins[number], Plugin<TName>> extends infer T ? T extends Plugin<TName, infer TConfig> ? TConfig : never : never;
92
93
  } : {}));
@@ -126,12 +127,12 @@ interface IPluginToolInfo {
126
127
  description: string;
127
128
  parameters: Schema;
128
129
  }
129
- type NodeOperationPipe<T = any> = DataOperationPipe<NodeData<T>>;
130
- type EdgeOperationPipe<T = any> = DataOperationPipe<EdgeData<T>>;
131
- type NodeOperation<T = any> = DataOperation<NodeData<T>>;
132
- type EdgeOperation<T = any> = DataOperation<EdgeData<T>>;
133
- type NodeOperatorFunction<T = any, Args extends any[] = any[]> = (...args: Args) => NodeOperation<T>[];
134
- type EdgeOperatorFunction<T = any, Args extends any[] = any[]> = (...args: Args) => EdgeOperation<T>[];
130
+ type NodeOperationPipe<T extends IRecord = IRecord> = DataOperationPipe<Node<T>>;
131
+ type EdgeOperationPipe<T extends IRecord = IRecord> = DataOperationPipe<Edge<T>>;
132
+ type NodeOperation<T extends IRecord = IRecord> = DataOperation<Node<T>>;
133
+ type EdgeOperation<T extends IRecord = IRecord> = DataOperation<Edge<T>>;
134
+ type NodeOperatorFunction<T extends IRecord = IRecord, TArgs extends any[] = any[]> = (...args: TArgs) => NodeOperation<T>[];
135
+ type EdgeOperatorFunction<T extends IRecord = IRecord, TArgs extends any[] = any[]> = (...args: TArgs) => EdgeOperation<T>[];
135
136
  interface IEngineRuntime {
136
137
  render?: {
137
138
  getValue: <T, R = T>(value: BehaviorSubject<T> | T, options: {
@@ -142,4 +143,4 @@ interface IEngineRuntime {
142
143
  };
143
144
  }
144
145
 
145
- export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type PluginTools as f, type IPluginInfo as g, type IPluginToolInfo as h, type NodePosition as i, type NodeMeasured as j, type NodeProps as k, type EdgeProps as l, type Position as m, type PluginConfigs as n, type NodeOperationPipe as o, type EdgeOperationPipe as p, type NodeOperation as q, type EdgeOperation as r, type NodeOperatorFunction as s, type EdgeOperatorFunction as t };
146
+ export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type IPluginInfo as h, type IPluginToolInfo as i, type NodePosition as j, type NodeMeasured as k, type NodeProps as l, type EdgeProps as m, type Position as n, type PluginConfigs as o, type NodeOperationPipe as p, type EdgeOperationPipe as q, type NodeOperation as r, type EdgeOperation as s, type NodeOperatorFunction as t, type EdgeOperatorFunction as u };
@@ -2,7 +2,7 @@ import { Schema } from 'jsonschema';
2
2
  import { SubscriptionLike, BehaviorSubject } from 'rxjs';
3
3
  import { DataOperationPipe, DataOperation } from '@knotx/data';
4
4
 
5
- declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
5
+ declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends IRecord | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
6
6
  abstract name: TPluginName;
7
7
  constructor(__: TPluginConfig);
8
8
  private static _instanceId;
@@ -18,6 +18,7 @@ declare abstract class BasePlugin<TPluginName extends string = string, TPluginCo
18
18
 
19
19
  type HorizontalAlignment = 'left' | 'right';
20
20
  type VerticalAlignment = 'top' | 'bottom';
21
+ type IRecord = Record<string, any>;
21
22
  interface NodePosition {
22
23
  x: number;
23
24
  y: number;
@@ -26,25 +27,25 @@ interface NodeMeasured {
26
27
  width: number;
27
28
  height: number;
28
29
  }
29
- interface NodeData<TData = any> {
30
+ interface Node<TData extends IRecord = IRecord> {
30
31
  id: string;
31
32
  type?: string;
32
33
  position: NodePosition;
33
34
  measured?: NodeMeasured;
34
35
  data: TData;
35
36
  }
36
- interface NodeProps<T = any> {
37
- node: NodeData<T>;
37
+ interface NodeProps<TData extends IRecord = IRecord> {
38
+ node: Node<TData>;
38
39
  }
39
- interface EdgeData<TData = any> {
40
+ interface Edge<TData extends IRecord = IRecord> {
40
41
  id: string;
41
42
  source: string;
42
43
  target: string;
43
44
  type?: string;
44
45
  data?: TData;
45
46
  }
46
- interface EdgeProps<T = any> {
47
- edge: EdgeData<T>;
47
+ interface EdgeProps<TData extends IRecord = IRecord> {
48
+ edge: Edge<TData>;
48
49
  sourceX: number;
49
50
  sourceY: number;
50
51
  targetX: number;
@@ -56,8 +57,8 @@ interface Container {
56
57
  }
57
58
  type Position = 'top' | 'right' | 'bottom' | 'left';
58
59
  type RenderType = (...args: any[]) => any;
59
- type NodeRenderType<TD extends Record<string, any> = any, TR = any> = (props: NodeProps<TD>) => TR;
60
- type EdgeRenderType<TD extends Record<string, any> = any, TR = any> = (props: EdgeProps<TD>) => TR;
60
+ type NodeRenderType<TD extends IRecord = any, TR = any> = (props: NodeProps<TD>) => TR;
61
+ type EdgeRenderType<TD extends IRecord = any, TR = any> = (props: EdgeProps<TD>) => TR;
61
62
  declare enum Layer {
62
63
  Canvas = 0,
63
64
  Background = 4,
@@ -77,7 +78,7 @@ interface LayerComponent<TRenderType> {
77
78
  */
78
79
  offset?: number;
79
80
  }
80
- interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
81
+ interface IPlugin<TPluginName extends string = string, TPluginConfig extends IRecord | undefined = any, TRenderType extends RenderType = RenderType> {
81
82
  name: TPluginName;
82
83
  pluginId: string;
83
84
  description?: string;
@@ -86,7 +87,7 @@ interface IPlugin<TPluginName extends string = string, TPluginConfig extends Rec
86
87
  onDestroy?: () => void;
87
88
  render?: (...args: Parameters<TRenderType>) => ReturnType<TRenderType>;
88
89
  }
89
- type Plugin<TName extends string = string, TConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
90
+ type Plugin<TName extends string = string, TConfig extends IRecord | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
90
91
  type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugin<infer T> ? {
91
92
  [TName in T as Extract<TPlugins[number], Plugin<TName>> extends Plugin<TName, undefined> ? never : TName]: Extract<TPlugins[number], Plugin<TName>> extends infer T ? T extends Plugin<TName, infer TConfig> ? TConfig : never : never;
92
93
  } : {}));
@@ -126,12 +127,12 @@ interface IPluginToolInfo {
126
127
  description: string;
127
128
  parameters: Schema;
128
129
  }
129
- type NodeOperationPipe<T = any> = DataOperationPipe<NodeData<T>>;
130
- type EdgeOperationPipe<T = any> = DataOperationPipe<EdgeData<T>>;
131
- type NodeOperation<T = any> = DataOperation<NodeData<T>>;
132
- type EdgeOperation<T = any> = DataOperation<EdgeData<T>>;
133
- type NodeOperatorFunction<T = any, Args extends any[] = any[]> = (...args: Args) => NodeOperation<T>[];
134
- type EdgeOperatorFunction<T = any, Args extends any[] = any[]> = (...args: Args) => EdgeOperation<T>[];
130
+ type NodeOperationPipe<T extends IRecord = IRecord> = DataOperationPipe<Node<T>>;
131
+ type EdgeOperationPipe<T extends IRecord = IRecord> = DataOperationPipe<Edge<T>>;
132
+ type NodeOperation<T extends IRecord = IRecord> = DataOperation<Node<T>>;
133
+ type EdgeOperation<T extends IRecord = IRecord> = DataOperation<Edge<T>>;
134
+ type NodeOperatorFunction<T extends IRecord = IRecord, TArgs extends any[] = any[]> = (...args: TArgs) => NodeOperation<T>[];
135
+ type EdgeOperatorFunction<T extends IRecord = IRecord, TArgs extends any[] = any[]> = (...args: TArgs) => EdgeOperation<T>[];
135
136
  interface IEngineRuntime {
136
137
  render?: {
137
138
  getValue: <T, R = T>(value: BehaviorSubject<T> | T, options: {
@@ -142,4 +143,4 @@ interface IEngineRuntime {
142
143
  };
143
144
  }
144
145
 
145
- export { BasePlugin as B, type Container as C, type EdgeData as E, type HorizontalAlignment as H, type IEngineRuntime as I, type LayerComponent as L, type NodeData as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IPlugin as a, Layer as b, type NodeRenderType as c, type EdgeRenderType as d, type PluginData as e, type PluginTools as f, type IPluginInfo as g, type IPluginToolInfo as h, type NodePosition as i, type NodeMeasured as j, type NodeProps as k, type EdgeProps as l, type Position as m, type PluginConfigs as n, type NodeOperationPipe as o, type EdgeOperationPipe as p, type NodeOperation as q, type EdgeOperation as r, type NodeOperatorFunction as s, type EdgeOperatorFunction as t };
146
+ export { BasePlugin as B, type Container as C, type Edge as E, type HorizontalAlignment as H, type IRecord as I, type LayerComponent as L, type Node as N, type Plugin as P, type RenderType as R, type VerticalAlignment as V, type IEngineRuntime as a, type IPlugin as b, Layer as c, type NodeRenderType as d, type EdgeRenderType as e, type PluginData as f, type PluginTools as g, type IPluginInfo as h, type IPluginToolInfo as i, type NodePosition as j, type NodeMeasured as k, type NodeProps as l, type EdgeProps as m, type Position as n, type PluginConfigs as o, type NodeOperationPipe as p, type EdgeOperationPipe as q, type NodeOperation as r, type EdgeOperation as s, type NodeOperatorFunction as t, type EdgeOperatorFunction as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/core",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
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.11",
50
+ "@knotx/utils": "0.2.11"
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.11",
55
+ "@knotx/eslint-config": "0.2.11",
56
+ "@knotx/typescript-config": "0.2.11"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "unbuild",