@knotx/core 0.2.4 → 0.2.6

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.d.cts CHANGED
@@ -1,8 +1,10 @@
1
- export { BasePlugin, Container, EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, HorizontalAlignment, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, Position, RenderType, VerticalAlignment } from './definition.cjs';
2
- import { Container, Plugin, NodeData, EdgeData, IEngineRuntime, RenderType, LayerComponent, IPlugin, Layer, NodeRenderType, EdgeRenderType, PluginData, InteractionPriority as InteractionPriority$1 } from '@knotx/core';
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';
3
+ import { Schema } from 'jsonschema';
3
4
  import { BehaviorSubject } from 'rxjs';
4
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
5
6
  export * from '@knotx/data';
7
+ import { RenderType as RenderType$1, IPlugin as IPlugin$1, LayerComponent as LayerComponent$1 } from '@knotx/core';
6
8
  export * from '@knotx/utils';
7
9
 
8
10
  /**
@@ -104,6 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
104
106
  private nodeRenderers$;
105
107
  private edgeRenderers$;
106
108
  private _pluginDataContainer;
109
+ private toolParamsValidator;
110
+ private _pluginToolsContainer;
107
111
  get container(): Container;
108
112
  set container(value: Container);
109
113
  get nodes(): NodeData<any>[];
@@ -114,8 +118,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
114
118
  private init;
115
119
  private calculateEffectiveLayer;
116
120
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
117
- addNodePipe(pipe: DataOperationPipe<NodeData>): void;
118
- addEdgePipe(pipe: DataOperationPipe<EdgeData>): void;
121
+ addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
+ addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
119
123
  changePluginConfig(pluginName: string, config: Record<string, any>): void;
120
124
  dispatchNodeOperation(operation: DataOperation<NodeData>): void;
121
125
  dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
@@ -128,15 +132,26 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
128
132
  getEdges(): EdgeData[];
129
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
130
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
131
- registerNodeRenderer(type: string, renderer: NodeRenderType): void;
132
- registerEdgeRenderer(type: string, renderer: EdgeRenderType): void;
133
- canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority$1): boolean;
134
- startInteraction(pluginId: string, type: string, priority: InteractionPriority$1): void;
135
+ resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
+ registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
+ description: string;
138
+ params: Schema;
139
+ func: PluginTools[T][TP];
140
+ }): void;
141
+ resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
142
+ registerNodeRenderer(type: string, renderer: NodeRenderType): () => void;
143
+ registerEdgeRenderer(type: string, renderer: EdgeRenderType): (() => void);
144
+ canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
+ startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
135
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;
148
+ listPlugins(): IPluginInfo[];
149
+ listPluginTools(pluginName: string): IPluginToolInfo[];
150
+ listEngineTools(): IPluginToolInfo[];
136
151
  destroy(): void;
137
152
  }
138
153
 
139
- declare function getLayerRenders<TRenderType extends RenderType = RenderType>(plugin: IPlugin): LayerComponent<TRenderType>[];
154
+ declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1): LayerComponent$1<TRenderType>[];
140
155
 
141
156
  /**
142
157
  * Runtime 类
@@ -199,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
199
214
  __contextValue__: TContext;
200
215
  }, context: TContext): T;
201
216
 
202
- export { Engine, type EngineOptions, type Interaction, InteractionManager, InteractionPriority, Runtime, getLayerRenders, use };
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 };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,10 @@
1
- export { BasePlugin, Container, EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, HorizontalAlignment, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, Position, RenderType, VerticalAlignment } from './definition.mjs';
2
- import { Container, Plugin, NodeData, EdgeData, IEngineRuntime, RenderType, LayerComponent, IPlugin, Layer, NodeRenderType, EdgeRenderType, PluginData, InteractionPriority as InteractionPriority$1 } from '@knotx/core';
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';
3
+ import { Schema } from 'jsonschema';
3
4
  import { BehaviorSubject } from 'rxjs';
4
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
5
6
  export * from '@knotx/data';
7
+ import { RenderType as RenderType$1, IPlugin as IPlugin$1, LayerComponent as LayerComponent$1 } from '@knotx/core';
6
8
  export * from '@knotx/utils';
7
9
 
8
10
  /**
@@ -104,6 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
104
106
  private nodeRenderers$;
105
107
  private edgeRenderers$;
106
108
  private _pluginDataContainer;
109
+ private toolParamsValidator;
110
+ private _pluginToolsContainer;
107
111
  get container(): Container;
108
112
  set container(value: Container);
109
113
  get nodes(): NodeData<any>[];
@@ -114,8 +118,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
114
118
  private init;
115
119
  private calculateEffectiveLayer;
116
120
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
117
- addNodePipe(pipe: DataOperationPipe<NodeData>): void;
118
- addEdgePipe(pipe: DataOperationPipe<EdgeData>): void;
121
+ addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
+ addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
119
123
  changePluginConfig(pluginName: string, config: Record<string, any>): void;
120
124
  dispatchNodeOperation(operation: DataOperation<NodeData>): void;
121
125
  dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
@@ -128,15 +132,26 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
128
132
  getEdges(): EdgeData[];
129
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
130
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
131
- registerNodeRenderer(type: string, renderer: NodeRenderType): void;
132
- registerEdgeRenderer(type: string, renderer: EdgeRenderType): void;
133
- canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority$1): boolean;
134
- startInteraction(pluginId: string, type: string, priority: InteractionPriority$1): void;
135
+ resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
+ registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
+ description: string;
138
+ params: Schema;
139
+ func: PluginTools[T][TP];
140
+ }): void;
141
+ resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
142
+ registerNodeRenderer(type: string, renderer: NodeRenderType): () => void;
143
+ registerEdgeRenderer(type: string, renderer: EdgeRenderType): (() => void);
144
+ canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
+ startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
135
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;
148
+ listPlugins(): IPluginInfo[];
149
+ listPluginTools(pluginName: string): IPluginToolInfo[];
150
+ listEngineTools(): IPluginToolInfo[];
136
151
  destroy(): void;
137
152
  }
138
153
 
139
- declare function getLayerRenders<TRenderType extends RenderType = RenderType>(plugin: IPlugin): LayerComponent<TRenderType>[];
154
+ declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1): LayerComponent$1<TRenderType>[];
140
155
 
141
156
  /**
142
157
  * Runtime 类
@@ -199,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
199
214
  __contextValue__: TContext;
200
215
  }, context: TContext): T;
201
216
 
202
- export { Engine, type EngineOptions, type Interaction, InteractionManager, InteractionPriority, Runtime, getLayerRenders, use };
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 };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- export { BasePlugin, Container, EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, HorizontalAlignment, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, Position, RenderType, VerticalAlignment } from './definition.js';
2
- import { Container, Plugin, NodeData, EdgeData, IEngineRuntime, RenderType, LayerComponent, IPlugin, Layer, NodeRenderType, EdgeRenderType, PluginData, InteractionPriority as InteractionPriority$1 } from '@knotx/core';
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';
3
+ import { Schema } from 'jsonschema';
3
4
  import { BehaviorSubject } from 'rxjs';
4
5
  import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
5
6
  export * from '@knotx/data';
7
+ import { RenderType as RenderType$1, IPlugin as IPlugin$1, LayerComponent as LayerComponent$1 } from '@knotx/core';
6
8
  export * from '@knotx/utils';
7
9
 
8
10
  /**
@@ -104,6 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
104
106
  private nodeRenderers$;
105
107
  private edgeRenderers$;
106
108
  private _pluginDataContainer;
109
+ private toolParamsValidator;
110
+ private _pluginToolsContainer;
107
111
  get container(): Container;
108
112
  set container(value: Container);
109
113
  get nodes(): NodeData<any>[];
@@ -114,8 +118,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
114
118
  private init;
115
119
  private calculateEffectiveLayer;
116
120
  getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
117
- addNodePipe(pipe: DataOperationPipe<NodeData>): void;
118
- addEdgePipe(pipe: DataOperationPipe<EdgeData>): void;
121
+ addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
122
+ addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
119
123
  changePluginConfig(pluginName: string, config: Record<string, any>): void;
120
124
  dispatchNodeOperation(operation: DataOperation<NodeData>): void;
121
125
  dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
@@ -128,15 +132,26 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
128
132
  getEdges(): EdgeData[];
129
133
  getEdgeRenderer(type: string): EdgeRenderType | undefined;
130
134
  registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
131
- registerNodeRenderer(type: string, renderer: NodeRenderType): void;
132
- registerEdgeRenderer(type: string, renderer: EdgeRenderType): void;
133
- canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority$1): boolean;
134
- startInteraction(pluginId: string, type: string, priority: InteractionPriority$1): void;
135
+ resetPluginData<T extends keyof PluginData>(pluginName: T): void;
136
+ registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
137
+ description: string;
138
+ params: Schema;
139
+ func: PluginTools[T][TP];
140
+ }): void;
141
+ resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
142
+ registerNodeRenderer(type: string, renderer: NodeRenderType): () => void;
143
+ registerEdgeRenderer(type: string, renderer: EdgeRenderType): (() => void);
144
+ canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
145
+ startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
135
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;
148
+ listPlugins(): IPluginInfo[];
149
+ listPluginTools(pluginName: string): IPluginToolInfo[];
150
+ listEngineTools(): IPluginToolInfo[];
136
151
  destroy(): void;
137
152
  }
138
153
 
139
- declare function getLayerRenders<TRenderType extends RenderType = RenderType>(plugin: IPlugin): LayerComponent<TRenderType>[];
154
+ declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1): LayerComponent$1<TRenderType>[];
140
155
 
141
156
  /**
142
157
  * Runtime 类
@@ -199,4 +214,4 @@ declare function use<T, TContext>(hook: () => {
199
214
  __contextValue__: TContext;
200
215
  }, context: TContext): T;
201
216
 
202
- export { Engine, type EngineOptions, type Interaction, InteractionManager, InteractionPriority, Runtime, getLayerRenders, use };
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 };
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- export { BasePlugin, Layer } from './definition.js';
1
+ export { Layer } from './definition.js';
2
+ import { Validator } from 'jsonschema';
2
3
  import { set, get } from 'lodash-es';
3
4
  import { BehaviorSubject, identity } from 'rxjs';
4
5
  import { Layer } from '@knotx/core';
@@ -7,9 +8,9 @@ export * from '@knotx/utils';
7
8
  import { DataManager } from '@knotx/data';
8
9
  export * from '@knotx/data';
9
10
 
10
- var __defProp$3 = Object.defineProperty;
11
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __publicField$2 = (obj, key, value) => __defNormalProp$3(obj, key + "" , value);
11
+ var __defProp$4 = Object.defineProperty;
12
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __publicField$3 = (obj, key, value) => __defNormalProp$4(obj, key + "" , value);
13
14
  var InteractionPriority = /* @__PURE__ */ ((InteractionPriority2) => {
14
15
  InteractionPriority2[InteractionPriority2["InputActive"] = 2e3] = "InputActive";
15
16
  InteractionPriority2[InteractionPriority2["EntityConnectDrag"] = 1930] = "EntityConnectDrag";
@@ -31,7 +32,7 @@ var InteractionPriority = /* @__PURE__ */ ((InteractionPriority2) => {
31
32
  })(InteractionPriority || {});
32
33
  class InteractionManager {
33
34
  constructor() {
34
- __publicField$2(this, "interactions", /* @__PURE__ */ new Map());
35
+ __publicField$3(this, "interactions", /* @__PURE__ */ new Map());
35
36
  }
36
37
  /**
37
38
  * 获取当前活动的交互
@@ -90,19 +91,19 @@ class InteractionManager {
90
91
  }
91
92
  }
92
93
 
93
- var __defProp$2 = Object.defineProperty;
94
+ var __defProp$3 = Object.defineProperty;
94
95
  var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
95
96
  var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
96
97
  var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
97
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
98
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
98
99
  var __spreadValues$1 = (a, b) => {
99
100
  for (var prop in b || (b = {}))
100
101
  if (__hasOwnProp$1.call(b, prop))
101
- __defNormalProp$2(a, prop, b[prop]);
102
+ __defNormalProp$3(a, prop, b[prop]);
102
103
  if (__getOwnPropSymbols$1)
103
104
  for (var prop of __getOwnPropSymbols$1(b)) {
104
105
  if (__propIsEnum$1.call(b, prop))
105
- __defNormalProp$2(a, prop, b[prop]);
106
+ __defNormalProp$3(a, prop, b[prop]);
106
107
  }
107
108
  return a;
108
109
  };
@@ -131,23 +132,25 @@ function getLayerRenders(plugin) {
131
132
  return components;
132
133
  }
133
134
 
134
- var __defProp$1 = Object.defineProperty;
135
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
136
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
135
+ var __defProp$2 = Object.defineProperty;
136
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
137
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
137
138
  class Engine {
138
139
  constructor(options) {
139
- __publicField$1(this, "runtime");
140
- __publicField$1(this, "interactionManager", new InteractionManager());
141
- __publicField$1(this, "nodesManager");
142
- __publicField$1(this, "edgesManager");
143
- __publicField$1(this, "container$", new BehaviorSubject(null));
144
- __publicField$1(this, "nodes$", new BehaviorSubject([]));
145
- __publicField$1(this, "edges$", new BehaviorSubject([]));
146
- __publicField$1(this, "layers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
147
- __publicField$1(this, "plugins$", new BehaviorSubject([]));
148
- __publicField$1(this, "nodeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
149
- __publicField$1(this, "edgeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
150
- __publicField$1(this, "_pluginDataContainer", {});
140
+ __publicField$2(this, "runtime");
141
+ __publicField$2(this, "interactionManager", new InteractionManager());
142
+ __publicField$2(this, "nodesManager");
143
+ __publicField$2(this, "edgesManager");
144
+ __publicField$2(this, "container$", new BehaviorSubject(null));
145
+ __publicField$2(this, "nodes$", new BehaviorSubject([]));
146
+ __publicField$2(this, "edges$", new BehaviorSubject([]));
147
+ __publicField$2(this, "layers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
148
+ __publicField$2(this, "plugins$", new BehaviorSubject([]));
149
+ __publicField$2(this, "nodeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
150
+ __publicField$2(this, "edgeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
151
+ __publicField$2(this, "_pluginDataContainer", {});
152
+ __publicField$2(this, "toolParamsValidator", new Validator());
153
+ __publicField$2(this, "_pluginToolsContainer", {});
151
154
  var _a;
152
155
  this.runtime = (_a = options.runtime) != null ? _a : {};
153
156
  this.container$.next(options.container);
@@ -184,6 +187,7 @@ class Engine {
184
187
  continue;
185
188
  }
186
189
  this._pluginDataContainer[plugin.name] = {};
190
+ this._pluginToolsContainer[plugin.name] = {};
187
191
  const engineSymbol = getSymbol("engine");
188
192
  if (!Reflect.has(plugin, engineSymbol)) {
189
193
  Reflect.set(plugin, engineSymbol, new BehaviorSubject(null));
@@ -216,10 +220,10 @@ class Engine {
216
220
  return this.layers$.value.get(layer) || [];
217
221
  }
218
222
  addNodePipe(pipe) {
219
- this.nodesManager.addDataOperationPipe(pipe);
223
+ return this.nodesManager.addDataOperationPipe(pipe);
220
224
  }
221
225
  addEdgePipe(pipe) {
222
- this.edgesManager.addDataOperationPipe(pipe);
226
+ return this.edgesManager.addDataOperationPipe(pipe);
223
227
  }
224
228
  changePluginConfig(pluginName, config) {
225
229
  var _a, _b;
@@ -258,15 +262,34 @@ class Engine {
258
262
  registerPluginData(pluginName, property, data) {
259
263
  set(this, ["_pluginDataContainer", pluginName, property], data);
260
264
  }
265
+ resetPluginData(pluginName) {
266
+ set(this, ["_pluginDataContainer", pluginName], void 0);
267
+ }
268
+ registerPluginTool(pluginName, property, data) {
269
+ set(this, ["_pluginToolsContainer", pluginName, property], data);
270
+ }
271
+ resetPluginTool(pluginName) {
272
+ set(this, ["_pluginToolsContainer", pluginName], void 0);
273
+ }
261
274
  registerNodeRenderer(type, renderer) {
262
275
  const nodeRenderers = this.nodeRenderers$.value;
263
276
  nodeRenderers.set(type, renderer);
264
277
  this.nodeRenderers$.next(nodeRenderers);
278
+ return () => {
279
+ const nodeRenderers2 = this.nodeRenderers$.value;
280
+ nodeRenderers2.delete(type);
281
+ this.nodeRenderers$.next(nodeRenderers2);
282
+ };
265
283
  }
266
284
  registerEdgeRenderer(type, renderer) {
267
285
  const edgeRenderers = this.edgeRenderers$.value;
268
286
  edgeRenderers.set(type, renderer);
269
287
  this.edgeRenderers$.next(edgeRenderers);
288
+ return () => {
289
+ const edgeRenderers2 = this.edgeRenderers$.value;
290
+ edgeRenderers2.delete(type);
291
+ this.edgeRenderers$.next(edgeRenderers2);
292
+ };
270
293
  }
271
294
  canInteract(pluginId, type, autoStartPriority) {
272
295
  return this.interactionManager.canInteract(pluginId, type, autoStartPriority);
@@ -277,6 +300,54 @@ class Engine {
277
300
  endInteraction(pluginId, type) {
278
301
  this.interactionManager.endInteraction(pluginId, type);
279
302
  }
303
+ callTool(pluginName, toolName, params) {
304
+ const toolDefinition = get(this, ["_pluginToolsContainer", pluginName, toolName]);
305
+ const tool = toolDefinition == null ? void 0 : toolDefinition.func;
306
+ if (!tool || typeof tool !== "function") {
307
+ throw new Error(`Tool ${String(toolName)} not found in plugin ${pluginName}`);
308
+ }
309
+ const validator = this.toolParamsValidator.validate(params, toolDefinition.params);
310
+ if (validator.errors.length > 0) {
311
+ throw new Error(`Invalid tool params: ${validator.errors.map((e) => e.stack).join(", ")}`);
312
+ }
313
+ return tool(params);
314
+ }
315
+ listPlugins() {
316
+ return this.plugins$.value.map((plugin) => ({
317
+ name: plugin.name,
318
+ description: plugin.description
319
+ }));
320
+ }
321
+ listPluginTools(pluginName) {
322
+ return Object.entries(get(this, ["_pluginToolsContainer", pluginName]) || {}).map(([toolName, toolDefinition]) => ({
323
+ type: "function",
324
+ name: toolName,
325
+ description: toolDefinition.description,
326
+ parameters: toolDefinition.params
327
+ }));
328
+ }
329
+ listEngineTools() {
330
+ return [
331
+ {
332
+ type: "function",
333
+ name: "listPlugins",
334
+ description: "List all plugins",
335
+ parameters: {}
336
+ },
337
+ {
338
+ type: "function",
339
+ name: "listPluginTools",
340
+ description: "List all tools of a plugin",
341
+ parameters: {
342
+ type: "object",
343
+ properties: {
344
+ pluginName: { type: "string" }
345
+ },
346
+ required: ["pluginName"]
347
+ }
348
+ }
349
+ ];
350
+ }
280
351
  destroy() {
281
352
  this.plugins$.value.forEach((plugin) => {
282
353
  var _a;
@@ -289,9 +360,44 @@ class Engine {
289
360
  this.edges$.complete();
290
361
  this.nodeRenderers$.complete();
291
362
  this.edgeRenderers$.complete();
363
+ this._pluginToolsContainer = {};
364
+ this._pluginDataContainer = {};
292
365
  }
293
366
  }
294
367
 
368
+ var __defProp$1 = Object.defineProperty;
369
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
370
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
371
+ const _BasePlugin = class _BasePlugin {
372
+ constructor(__) {
373
+ __publicField$1(this, "_instanceId", _BasePlugin._instanceId++);
374
+ /**
375
+ * 插件生命周期中的订阅回调
376
+ * 可随时存入,销毁时会自动执行
377
+ */
378
+ __publicField$1(this, "subscriptions", []);
379
+ Reflect.set(this, getSymbol("engine"), new BehaviorSubject(null));
380
+ }
381
+ get pluginId() {
382
+ return `${this.name}:${this._instanceId}`;
383
+ }
384
+ onDestroy() {
385
+ this.subscriptions.forEach((subscription) => {
386
+ if (typeof subscription === "function") {
387
+ subscription();
388
+ } else {
389
+ subscription.unsubscribe();
390
+ }
391
+ });
392
+ const engin$ = Reflect.get(this, getSymbol("engine"));
393
+ engin$.value.resetPluginData(this.name);
394
+ engin$.value.resetPluginTool(this.name);
395
+ engin$.complete();
396
+ }
397
+ };
398
+ __publicField$1(_BasePlugin, "_instanceId", 0);
399
+ let BasePlugin = _BasePlugin;
400
+
295
401
  var __defProp = Object.defineProperty;
296
402
  var __defProps = Object.defineProperties;
297
403
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
@@ -370,4 +476,4 @@ function use(hook, context) {
370
476
  return Runtime.getInstance().runInContext("render", hook, context);
371
477
  }
372
478
 
373
- export { Engine, InteractionManager, InteractionPriority, Runtime, getLayerRenders, use };
479
+ export { BasePlugin, Engine, InteractionManager, InteractionPriority, Runtime, getLayerRenders, use };
@@ -0,0 +1,145 @@
1
+ import { Schema } from 'jsonschema';
2
+ import { SubscriptionLike, BehaviorSubject } from 'rxjs';
3
+ import { DataOperationPipe, DataOperation } from '@knotx/data';
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> {
6
+ abstract name: TPluginName;
7
+ constructor(__: TPluginConfig);
8
+ private static _instanceId;
9
+ private _instanceId;
10
+ get pluginId(): string;
11
+ /**
12
+ * 插件生命周期中的订阅回调
13
+ * 可随时存入,销毁时会自动执行
14
+ */
15
+ protected subscriptions: (SubscriptionLike | (() => void))[];
16
+ onDestroy(): void;
17
+ }
18
+
19
+ type HorizontalAlignment = 'left' | 'right';
20
+ type VerticalAlignment = 'top' | 'bottom';
21
+ interface NodePosition {
22
+ x: number;
23
+ y: number;
24
+ }
25
+ interface NodeMeasured {
26
+ width: number;
27
+ height: number;
28
+ }
29
+ interface NodeData<TData = any> {
30
+ id: string;
31
+ type?: string;
32
+ position: NodePosition;
33
+ measured?: NodeMeasured;
34
+ data: TData;
35
+ }
36
+ interface NodeProps<T = any> {
37
+ node: NodeData<T>;
38
+ }
39
+ interface EdgeData<TData = any> {
40
+ id: string;
41
+ source: string;
42
+ target: string;
43
+ type?: string;
44
+ data?: TData;
45
+ }
46
+ interface EdgeProps<T = any> {
47
+ edge: EdgeData<T>;
48
+ sourceX: number;
49
+ sourceY: number;
50
+ targetX: number;
51
+ targetY: number;
52
+ }
53
+ interface Container {
54
+ width: number;
55
+ height: number;
56
+ }
57
+ type Position = 'top' | 'right' | 'bottom' | 'left';
58
+ 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;
61
+ declare enum Layer {
62
+ Canvas = 0,
63
+ Background = 4,
64
+ Edges = 16,
65
+ Nodes = 64,
66
+ Foreground = 256
67
+ }
68
+ interface LayerComponent<TRenderType> {
69
+ plugin: string;
70
+ name: string;
71
+ layer: Layer;
72
+ render: TRenderType;
73
+ /**
74
+ * 层级偏移量
75
+ * @default 0
76
+ * (layer >> 1, layer << 1]
77
+ */
78
+ offset?: number;
79
+ }
80
+ interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
81
+ name: TPluginName;
82
+ pluginId: string;
83
+ description?: string;
84
+ onInit?: (config: TPluginConfig) => void;
85
+ onConfigChange?: (config: TPluginConfig) => void;
86
+ onDestroy?: () => void;
87
+ render?: (...args: Parameters<TRenderType>) => ReturnType<TRenderType>;
88
+ }
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 PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugin<infer T> ? {
91
+ [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
+ /**
94
+ * plugin data host
95
+ * @example
96
+ * `declare module '@knotx/core' {
97
+ * interface PluginData {
98
+ * pluginName: {
99
+ * property: any
100
+ * }
101
+ * }
102
+ * }`
103
+ */
104
+ interface PluginData {
105
+ }
106
+ /**
107
+ * plugin tools host
108
+ * @example
109
+ * `declare module '@knotx/core' {
110
+ * interface PluginTools {
111
+ * pluginName: {
112
+ * toolName: (params: any) => any
113
+ * }
114
+ * }
115
+ * }`
116
+ */
117
+ interface PluginTools {
118
+ }
119
+ interface IPluginInfo {
120
+ name: string;
121
+ description?: string;
122
+ }
123
+ interface IPluginToolInfo {
124
+ type: 'function';
125
+ name: string;
126
+ description: string;
127
+ parameters: Schema;
128
+ }
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>[];
135
+ interface IEngineRuntime {
136
+ render?: {
137
+ getValue: <T, R = T>(value: BehaviorSubject<T> | T, options: {
138
+ paths: string[];
139
+ selector?: (value: T, context?: any) => R;
140
+ context?: any;
141
+ }) => T | R;
142
+ };
143
+ }
144
+
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 };