@knotx/core 0.2.14 → 0.3.1

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.ts CHANGED
@@ -1,169 +1,12 @@
1
- import { R as RenderType, I as IRecord, a as IEngineRuntime, N as Node, E as Edge, C as Container, L as LayerComponent, b as IPlugin, P as Plugin, c as Layer, d as NodeRenderType, e as EdgeRenderType, f as PluginData, g as PluginTools, h as EngineTools, i as IPluginInfo, j as IPluginToolInfo } from './shared/core.B-u2ysAC.js';
2
- export { B as BasePlugin, t as EdgeOperation, r as EdgeOperationPipe, v as EdgeOperatorFunction, n as EdgeProps, H as HorizontalAlignment, l as NodeMeasured, s as NodeOperation, q as NodeOperationPipe, u as NodeOperatorFunction, k as NodePosition, m as NodeProps, p as PluginConfigs, o as Position, V as VerticalAlignment } from './shared/core.B-u2ysAC.js';
3
- import { Schema } from 'jsonschema';
1
+ import { E as Engine } from './shared/core.CpyG0nWq.js';
2
+ export { D as BasePlugin, y as CallToolMethod, C as Container, d as Edge, t as EdgeOperation, r as EdgeOperationPipe, v as EdgeOperatorFunction, e as EdgeProps, g as EdgeRenderType, x as EngineOptions, n as EngineTools, H as HorizontalAlignment, w as IEngineRuntime, i as IPlugin, o as IPluginInfo, I as IRecord, p as IToolInfo, A as Interaction, B as InteractionManager, z as InteractionPriority, L as Layer, h as LayerComponent, b as Node, a as NodeMeasured, s as NodeOperation, q as NodeOperationPipe, u as NodeOperatorFunction, N as NodePosition, c as NodeProps, f as NodeRenderType, j as Plugin, k as PluginConfigs, l as PluginData, m as PluginTools, P as Position, R as RenderType, V as VerticalAlignment } from './shared/core.CpyG0nWq.js';
3
+ import { RenderType, IPlugin, LayerComponent } from '@knotx/core';
4
4
  import { BehaviorSubject } from 'rxjs';
5
- import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
6
5
  export * from '@knotx/data';
7
- import { RenderType as RenderType$1, IPlugin as IPlugin$1, LayerComponent as LayerComponent$1 } from '@knotx/core';
8
6
  export * from '@knotx/utils';
7
+ import 'jsonschema';
9
8
 
10
- /**
11
- * 用户交互优先级定义
12
- * 数值越大优先级越高
13
- */
14
- declare enum InteractionPriority {
15
- /** 文本输入框激活状态(输入中需独占) */
16
- InputActive = 2000,
17
- /** 实体连接拖拽 */
18
- EntityConnectDrag = 1930,
19
- /** 实体测量拖拽 */
20
- EntityMeasureDrag = 1920,
21
- /** 实体位置拖拽 */
22
- EntityPositionDrag = 1910,
23
- /** 连续操作:画布拖拽、缩放等进行中的动作 */
24
- ContinuousDrag = 1900,
25
- /** 右键菜单/上下文操作 */
26
- ContextMenu = 1800,
27
- /** 键盘快捷键(如 Delete/Ctrl+C) */
28
- KeyboardShortcut = 1700,
29
- /** 单击选中元素 */
30
- ClickSelection = 1600,
31
- /** 双击编辑元素 */
32
- DoubleClickEdit = 1500,
33
- /** 框选(多选)操作 */
34
- MarqueeSelection = 1300,
35
- /** 套索选择(Lasso Select) */
36
- LassoSelection = 1250,
37
- /** 长按操作(长按菜单/工具) */
38
- LongPress = 1100,
39
- /** 悬停提示(Hover Tooltip) */
40
- HoverTooltip = 1000,
41
- /** 画布平移(空格拖拽或手势) */
42
- CanvasPan = 900,
43
- /** 画布缩放(滚轮或双指) */
44
- CanvasZoom = 800,
45
- /** 多指手势(如三指滑动) */
46
- MultiTouchGesture = 700
47
- }
48
- interface Interaction {
49
- pluginId: string;
50
- type: string;
51
- priority: InteractionPriority;
52
- active?: boolean;
53
- }
54
- /**
55
- * 交互管理器
56
- */
57
- declare class InteractionManager {
58
- private interactions;
59
- /**
60
- * 获取当前活动的交互
61
- */
62
- get activeInteraction(): Interaction | undefined;
63
- /**
64
- * 检查是否可以交互
65
- * @param pluginId 插件ID
66
- * @param type 交互类型
67
- * @param autoStartPriority 自动启动优先级
68
- * @returns 是否可以交互
69
- */
70
- canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
71
- /**
72
- * 启动交互
73
- * @param pluginId 插件ID
74
- * @param type 交互类型
75
- * @param priority 优先级
76
- * @returns 取消交互的函数
77
- */
78
- startInteraction(pluginId: string, type: string, priority: InteractionPriority): () => void;
79
- /**
80
- * 结束交互
81
- * @param pluginId 插件ID
82
- * @param type 交互类型
83
- */
84
- endInteraction(pluginId: string, type: string): void;
85
- private updateActive;
86
- }
87
-
88
- interface EngineOptions<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
89
- container: Container;
90
- plugins?: Plugin[];
91
- pluginConfig?: IRecord;
92
- nodes?: Node<TNode>[];
93
- edges?: Edge<TEdge>[];
94
- runtime?: IEngineRuntime;
95
- }
96
- declare module '@knotx/core' {
97
- interface EngineTools {
98
- listPlugins: Engine['listPlugins'];
99
- listPluginTools: Engine['listPluginTools'];
100
- getNodes: Engine['getNodes'];
101
- getEdges: Engine['getEdges'];
102
- }
103
- }
104
- declare class Engine<TRenderType extends RenderType = RenderType, TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
105
- readonly runtime: IEngineRuntime;
106
- readonly interactionManager: InteractionManager;
107
- readonly nodesManager: DataManager<Node<TNode>>;
108
- readonly edgesManager: DataManager<Edge<TEdge>>;
109
- private container$;
110
- private nodes$;
111
- private edges$;
112
- private layers$;
113
- private plugins$;
114
- private nodeRenderers$;
115
- private edgeRenderers$;
116
- private _pluginDataContainer;
117
- private _pluginToolsContainer;
118
- private engineTools;
119
- private toolParametersValidator;
120
- get container(): Container;
121
- set container(value: Container);
122
- get nodes(): Node<TNode>[];
123
- get edges(): Edge<TEdge>[];
124
- get layers(): Map<number, LayerComponent<TRenderType>[]>;
125
- get plugins(): IPlugin<string, any, RenderType>[];
126
- constructor(options: EngineOptions<TNode, TEdge>);
127
- private init;
128
- getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
129
- addNodePipe(pipe: DataOperationPipe<Node<TNode>>): () => void;
130
- addEdgePipe(pipe: DataOperationPipe<Edge<TEdge>>): () => void;
131
- changePluginConfig(pluginName: string, config: IRecord): void;
132
- dispatchNodeOperation(operation: DataOperation<Node<TNode>>): void;
133
- dispatchEdgeOperation(operation: DataOperation<Edge<TEdge>>): void;
134
- getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
135
- getNode(id: string): Node<TNode> | undefined;
136
- getNodeDraft(id: string): Node<TNode> | undefined;
137
- getNodes(): Node<TNode>[];
138
- getNodeRenderer(type: string): NodeRenderType | undefined;
139
- getEdge(id: string): Edge<TEdge> | undefined;
140
- getEdgeDraft(id: string): Edge<TEdge> | undefined;
141
- getEdges(): Edge<TEdge>[];
142
- getEdgeRenderer(type: string): EdgeRenderType | undefined;
143
- registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
144
- resetPluginData<T extends keyof PluginData>(pluginName: T): void;
145
- registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
146
- description: string;
147
- parameters: Schema;
148
- func: PluginTools[T][TP];
149
- }): void;
150
- resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
151
- registerNodeRenderer(type: string, renderer: NodeRenderType): () => void;
152
- registerEdgeRenderer(type: string, renderer: EdgeRenderType): (() => void);
153
- canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
154
- startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
155
- endInteraction(pluginId: string, type: string): void;
156
- callTool<T extends keyof EngineTools>(engineToolName: T, ...args: Parameters<EngineTools[T]>): ReturnType<EngineTools[T]>;
157
- callTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, toolName: TP, ...args: Parameters<PluginTools[T][TP]>): ReturnType<PluginTools[T][TP]>;
158
- listPlugins(): IPluginInfo[];
159
- listPluginTools({ pluginName }: {
160
- pluginName: string;
161
- }): IPluginToolInfo[];
162
- listEngineTools(): IPluginToolInfo[];
163
- destroy(): void;
164
- }
165
-
166
- declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1): LayerComponent$1<TRenderType>[];
9
+ declare function getLayerRenders<TRenderType extends RenderType = RenderType>(plugin: IPlugin): LayerComponent<TRenderType>[];
167
10
 
168
11
  /**
169
12
  * Runtime 类
@@ -226,4 +69,4 @@ declare function use<T, TContext>(hook: () => {
226
69
  __contextValue__: TContext;
227
70
  }, context: TContext): T;
228
71
 
229
- export { Container, Edge, EdgeRenderType, Engine, type EngineOptions, type EngineTools, IEngineRuntime, IPlugin, IPluginInfo, IPluginToolInfo, IRecord, type Interaction, InteractionManager, InteractionPriority, Layer, LayerComponent, Node, NodeRenderType, Plugin, PluginData, PluginTools, RenderType, Runtime, getLayerRenders, use };
72
+ export { Engine, Runtime, getLayerRenders, use };
package/dist/index.js CHANGED
@@ -193,17 +193,62 @@ class Engine {
193
193
  {
194
194
  type: "function",
195
195
  name: "getNodes",
196
- description: "Get all nodes",
196
+ description: "Get all nodes data",
197
197
  parameters: {}
198
198
  },
199
199
  {
200
200
  type: "function",
201
201
  name: "getEdges",
202
- description: "Get all edges",
202
+ description: "Get all edges data",
203
203
  parameters: {}
204
+ },
205
+ {
206
+ type: "function",
207
+ name: "getNode",
208
+ description: "Get node data",
209
+ parameters: {
210
+ type: "object",
211
+ properties: {
212
+ id: { type: "string" }
213
+ },
214
+ required: ["id"]
215
+ }
216
+ },
217
+ {
218
+ type: "function",
219
+ name: "getEdge",
220
+ description: "Get edge data",
221
+ parameters: {
222
+ type: "object",
223
+ properties: {
224
+ id: { type: "string" }
225
+ },
226
+ required: ["id"]
227
+ }
204
228
  }
205
229
  ].map((tool) => [tool.name, tool])));
206
230
  __publicField$2(this, "toolParametersValidator", new Validator());
231
+ __publicField$2(this, "callTool", (pluginNameOrEngineToolName, ...args) => {
232
+ let toolDefinition;
233
+ let toolDisplayName;
234
+ if (this.engineTools.has(pluginNameOrEngineToolName)) {
235
+ toolDefinition = __spreadProps$1(__spreadValues$1({}, this.engineTools.get(pluginNameOrEngineToolName)), { func: this[pluginNameOrEngineToolName].bind(this) });
236
+ toolDisplayName = toolDefinition.name;
237
+ } else {
238
+ toolDefinition = get(this, ["_pluginToolsContainer", pluginNameOrEngineToolName, args == null ? void 0 : args[0]]);
239
+ toolDisplayName = `${pluginNameOrEngineToolName}.${args == null ? void 0 : args[0]}`;
240
+ }
241
+ const tool = toolDefinition == null ? void 0 : toolDefinition.func;
242
+ if (!tool || typeof tool !== "function") {
243
+ throw new Error(`Tool ${String(toolDisplayName)} not found`);
244
+ }
245
+ const parameters = args[args.length - 1];
246
+ const validator = this.toolParametersValidator.validate(parameters, toolDefinition.parameters);
247
+ if (validator.errors.length > 0) {
248
+ throw new Error(`Invalid tool parameters: ${validator.errors.map((e) => e.stack).join(", ")}`);
249
+ }
250
+ return tool(parameters);
251
+ });
207
252
  var _a;
208
253
  this.runtime = (_a = options.runtime) != null ? _a : {};
209
254
  this.container$.next(options.container);
@@ -274,7 +319,7 @@ class Engine {
274
319
  addEdgePipe(pipe) {
275
320
  return this.edgesManager.addDataOperationPipe(pipe);
276
321
  }
277
- changePluginConfig(pluginName, config) {
322
+ changePluginConfig({ pluginName, config }) {
278
323
  var _a, _b;
279
324
  (_b = (_a = this.plugins$.value.get(pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
280
325
  }
@@ -284,13 +329,13 @@ class Engine {
284
329
  dispatchEdgeOperation(operation) {
285
330
  this.edgesManager.dispatch(operation);
286
331
  }
287
- getPlugin(pluginName) {
332
+ getPlugin({ pluginName }) {
288
333
  return this.plugins$.value.get(pluginName);
289
334
  }
290
- getNode(id) {
335
+ getNode({ id }) {
291
336
  return this.nodesManager.getData(id);
292
337
  }
293
- getNodeDraft(id) {
338
+ getNodeDraft({ id }) {
294
339
  return this.nodesManager.getCurrentDraftData(id);
295
340
  }
296
341
  getNodes() {
@@ -299,10 +344,10 @@ class Engine {
299
344
  getNodeRenderer(type) {
300
345
  return this.nodeRenderers$.value.get(type);
301
346
  }
302
- getEdge(id) {
347
+ getEdge({ id }) {
303
348
  return this.edgesManager.getData(id);
304
349
  }
305
- getEdgeDraft(id) {
350
+ getEdgeDraft({ id }) {
306
351
  return this.edgesManager.getCurrentDraftData(id);
307
352
  }
308
353
  getEdges() {
@@ -352,27 +397,6 @@ class Engine {
352
397
  endInteraction(pluginId, type) {
353
398
  this.interactionManager.endInteraction(pluginId, type);
354
399
  }
355
- callTool(pluginNameOrEngineToolName, ...args) {
356
- let toolDefinition;
357
- let toolDisplayName;
358
- if (this.engineTools.has(pluginNameOrEngineToolName)) {
359
- toolDefinition = __spreadProps$1(__spreadValues$1({}, this.engineTools.get(pluginNameOrEngineToolName)), { func: this[pluginNameOrEngineToolName].bind(this) });
360
- toolDisplayName = toolDefinition.name;
361
- } else {
362
- toolDefinition = get(this, ["_pluginToolsContainer", pluginNameOrEngineToolName, args == null ? void 0 : args[0]]);
363
- toolDisplayName = `${pluginNameOrEngineToolName}.${args == null ? void 0 : args[0]}`;
364
- }
365
- const tool = toolDefinition == null ? void 0 : toolDefinition.func;
366
- if (!tool || typeof tool !== "function") {
367
- throw new Error(`Tool ${String(toolDisplayName)} not found`);
368
- }
369
- const parameters = args[args.length - 1];
370
- const validator = this.toolParametersValidator.validate(parameters, toolDefinition.parameters);
371
- if (validator.errors.length > 0) {
372
- throw new Error(`Invalid tool parameters: ${validator.errors.map((e) => e.stack).join(", ")}`);
373
- }
374
- return tool(parameters);
375
- }
376
400
  listPlugins() {
377
401
  return Array.from(this.plugins$.value.values()).map((plugin) => ({
378
402
  name: plugin.name,
@@ -418,6 +442,10 @@ const _BasePlugin = class _BasePlugin {
418
442
  * 可随时存入,销毁时会自动执行
419
443
  */
420
444
  __publicField$1(this, "subscriptions", []);
445
+ __publicField$1(this, "callTool", (...args) => {
446
+ var _a;
447
+ return (_a = Reflect.get(this, getSymbol("engine")).value) == null ? void 0 : _a.callTool(...args);
448
+ });
421
449
  Reflect.set(this, getSymbol("engine"), new BehaviorSubject(null));
422
450
  }
423
451
  get pluginId() {
@@ -0,0 +1,323 @@
1
+ import { Schema } from 'jsonschema';
2
+ import { BehaviorSubject, SubscriptionLike } from 'rxjs';
3
+ import { DataManager, DataOperationPipe, DataOperation } from '@knotx/data';
4
+
5
+ /**
6
+ * 用户交互优先级定义
7
+ * 数值越大优先级越高
8
+ */
9
+ declare enum InteractionPriority {
10
+ /** 文本输入框激活状态(输入中需独占) */
11
+ InputActive = 2000,
12
+ /** 实体连接拖拽 */
13
+ EntityConnectDrag = 1930,
14
+ /** 实体测量拖拽 */
15
+ EntityMeasureDrag = 1920,
16
+ /** 实体位置拖拽 */
17
+ EntityPositionDrag = 1910,
18
+ /** 连续操作:画布拖拽、缩放等进行中的动作 */
19
+ ContinuousDrag = 1900,
20
+ /** 右键菜单/上下文操作 */
21
+ ContextMenu = 1800,
22
+ /** 键盘快捷键(如 Delete/Ctrl+C) */
23
+ KeyboardShortcut = 1700,
24
+ /** 单击选中元素 */
25
+ ClickSelection = 1600,
26
+ /** 双击编辑元素 */
27
+ DoubleClickEdit = 1500,
28
+ /** 框选(多选)操作 */
29
+ MarqueeSelection = 1300,
30
+ /** 套索选择(Lasso Select) */
31
+ LassoSelection = 1250,
32
+ /** 长按操作(长按菜单/工具) */
33
+ LongPress = 1100,
34
+ /** 悬停提示(Hover Tooltip) */
35
+ HoverTooltip = 1000,
36
+ /** 画布平移(空格拖拽或手势) */
37
+ CanvasPan = 900,
38
+ /** 画布缩放(滚轮或双指) */
39
+ CanvasZoom = 800,
40
+ /** 多指手势(如三指滑动) */
41
+ MultiTouchGesture = 700
42
+ }
43
+ interface Interaction {
44
+ pluginId: string;
45
+ type: string;
46
+ priority: InteractionPriority;
47
+ active?: boolean;
48
+ }
49
+ /**
50
+ * 交互管理器
51
+ */
52
+ declare class InteractionManager {
53
+ private interactions;
54
+ /**
55
+ * 获取当前活动的交互
56
+ */
57
+ get activeInteraction(): Interaction | undefined;
58
+ /**
59
+ * 检查是否可以交互
60
+ * @param pluginId 插件ID
61
+ * @param type 交互类型
62
+ * @param autoStartPriority 自动启动优先级
63
+ * @returns 是否可以交互
64
+ */
65
+ canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
66
+ /**
67
+ * 启动交互
68
+ * @param pluginId 插件ID
69
+ * @param type 交互类型
70
+ * @param priority 优先级
71
+ * @returns 取消交互的函数
72
+ */
73
+ startInteraction(pluginId: string, type: string, priority: InteractionPriority): () => void;
74
+ /**
75
+ * 结束交互
76
+ * @param pluginId 插件ID
77
+ * @param type 交互类型
78
+ */
79
+ endInteraction(pluginId: string, type: string): void;
80
+ private updateActive;
81
+ }
82
+
83
+ interface EngineOptions<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
84
+ container: Container;
85
+ plugins?: Plugin[];
86
+ pluginConfig?: IRecord;
87
+ nodes?: Node<TNode>[];
88
+ edges?: Edge<TEdge>[];
89
+ runtime?: IEngineRuntime;
90
+ }
91
+ declare module '@knotx/core' {
92
+ interface EngineTools {
93
+ listPlugins: Engine['listPlugins'];
94
+ listPluginTools: Engine['listPluginTools'];
95
+ getNodes: Engine['getNodes'];
96
+ getEdges: Engine['getEdges'];
97
+ getNode: Engine['getNode'];
98
+ getEdge: Engine['getEdge'];
99
+ }
100
+ }
101
+ interface CallToolMethod {
102
+ <T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: Extract<T, keyof PluginTools>, toolName: Extract<TP, keyof PluginTools[T]>, ...args: Parameters<PluginTools[T][TP]>): ReturnType<PluginTools[T][TP]>;
103
+ <T extends keyof EngineTools>(engineToolName: Extract<T, keyof EngineTools>, ...args: Parameters<EngineTools[T]>): ReturnType<EngineTools[T]>;
104
+ }
105
+ declare class Engine<TRenderType extends RenderType = RenderType, TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
106
+ readonly runtime: IEngineRuntime;
107
+ readonly interactionManager: InteractionManager;
108
+ readonly nodesManager: DataManager<Node<TNode>>;
109
+ readonly edgesManager: DataManager<Edge<TEdge>>;
110
+ private container$;
111
+ private nodes$;
112
+ private edges$;
113
+ private layers$;
114
+ private plugins$;
115
+ private nodeRenderers$;
116
+ private edgeRenderers$;
117
+ private _pluginDataContainer;
118
+ private _pluginToolsContainer;
119
+ private engineTools;
120
+ private toolParametersValidator;
121
+ get container(): Container;
122
+ set container(value: Container);
123
+ get nodes(): Node<TNode>[];
124
+ get edges(): Edge<TEdge>[];
125
+ get layers(): Map<number, LayerComponent<TRenderType>[]>;
126
+ get plugins(): IPlugin<string, any, RenderType>[];
127
+ constructor(options: EngineOptions<TNode, TEdge>);
128
+ private init;
129
+ callTool: CallToolMethod;
130
+ getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
131
+ addNodePipe(pipe: DataOperationPipe<Node<TNode>>): () => void;
132
+ addEdgePipe(pipe: DataOperationPipe<Edge<TEdge>>): () => void;
133
+ changePluginConfig({ pluginName, config }: {
134
+ pluginName: string;
135
+ config: IRecord;
136
+ }): void;
137
+ dispatchNodeOperation(operation: DataOperation<Node<TNode>>): void;
138
+ dispatchEdgeOperation(operation: DataOperation<Edge<TEdge>>): void;
139
+ getPlugin<TPlugin extends IPlugin>({ pluginName }: {
140
+ pluginName: TPlugin['name'];
141
+ }): TPlugin | undefined;
142
+ getNode({ id }: {
143
+ id: string;
144
+ }): Node<TNode> | undefined;
145
+ getNodeDraft({ id }: {
146
+ id: string;
147
+ }): Node<TNode> | undefined;
148
+ getNodes(): Node<TNode>[];
149
+ getNodeRenderer(type: string): NodeRenderType | undefined;
150
+ getEdge({ id }: {
151
+ id: string;
152
+ }): Edge<TEdge> | undefined;
153
+ getEdgeDraft({ id }: {
154
+ id: string;
155
+ }): Edge<TEdge> | undefined;
156
+ getEdges(): Edge<TEdge>[];
157
+ getEdgeRenderer(type: string): EdgeRenderType | undefined;
158
+ registerPluginData<T extends keyof PluginData, TP extends keyof PluginData[T]>(pluginName: T, property: TP, data: BehaviorSubject<PluginData[T][TP]>): void;
159
+ resetPluginData<T extends keyof PluginData>(pluginName: T): void;
160
+ registerPluginTool<T extends keyof PluginTools, TP extends keyof PluginTools[T]>(pluginName: T, property: TP, data: {
161
+ description: string;
162
+ parameters: Schema;
163
+ func: PluginTools[T][TP];
164
+ }): void;
165
+ resetPluginTool<T extends keyof PluginTools>(pluginName: T): void;
166
+ registerNodeRenderer(type: string, renderer: NodeRenderType): () => void;
167
+ registerEdgeRenderer(type: string, renderer: EdgeRenderType): (() => void);
168
+ canInteract(pluginId: string, type: string, autoStartPriority?: InteractionPriority): boolean;
169
+ startInteraction(pluginId: string, type: string, priority: InteractionPriority): void;
170
+ endInteraction(pluginId: string, type: string): void;
171
+ listPlugins(): IPluginInfo[];
172
+ listPluginTools({ pluginName }: {
173
+ pluginName: string;
174
+ }): IToolInfo[];
175
+ listEngineTools(): IToolInfo[];
176
+ destroy(): void;
177
+ }
178
+
179
+ declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends IRecord | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
180
+ abstract name: TPluginName;
181
+ constructor(__: TPluginConfig);
182
+ private static _instanceId;
183
+ private _instanceId;
184
+ get pluginId(): string;
185
+ /**
186
+ * 插件生命周期中的订阅回调
187
+ * 可随时存入,销毁时会自动执行
188
+ */
189
+ protected subscriptions: (SubscriptionLike | (() => void))[];
190
+ protected callTool: Engine['callTool'];
191
+ onDestroy(): void;
192
+ }
193
+
194
+ type HorizontalAlignment = 'left' | 'right';
195
+ type VerticalAlignment = 'top' | 'bottom';
196
+ type IRecord = Record<string, any>;
197
+ interface NodePosition {
198
+ x: number;
199
+ y: number;
200
+ }
201
+ interface NodeMeasured {
202
+ width: number;
203
+ height: number;
204
+ }
205
+ interface Node<TData extends IRecord = IRecord> {
206
+ id: string;
207
+ type?: string;
208
+ position: NodePosition;
209
+ measured?: NodeMeasured;
210
+ data: TData;
211
+ }
212
+ interface NodeProps<TData extends IRecord = IRecord> {
213
+ node: Node<TData>;
214
+ }
215
+ interface Edge<TData extends IRecord = IRecord> {
216
+ id: string;
217
+ source: string;
218
+ target: string;
219
+ type?: string;
220
+ data?: TData;
221
+ }
222
+ interface EdgeProps<TData extends IRecord = IRecord> {
223
+ edge: Edge<TData>;
224
+ sourceX: number;
225
+ sourceY: number;
226
+ targetX: number;
227
+ targetY: number;
228
+ }
229
+ interface Container {
230
+ width: number;
231
+ height: number;
232
+ }
233
+ type Position = 'top' | 'right' | 'bottom' | 'left';
234
+ type RenderType = (...args: any[]) => any;
235
+ type NodeRenderType<TD extends IRecord = any, TR = any> = (props: NodeProps<TD>) => TR;
236
+ type EdgeRenderType<TD extends IRecord = any, TR = any> = (props: EdgeProps<TD>) => TR;
237
+ declare enum Layer {
238
+ Canvas = 0,
239
+ Background = 4,
240
+ Edges = 16,
241
+ Nodes = 64,
242
+ Foreground = 256
243
+ }
244
+ interface LayerComponent<TRenderType> {
245
+ plugin: string;
246
+ name: string;
247
+ layer: Layer;
248
+ render: TRenderType;
249
+ /**
250
+ * 层级偏移量
251
+ * @default 0
252
+ * (layer >> 1, layer << 1]
253
+ */
254
+ offset?: number;
255
+ }
256
+ interface IPlugin<TPluginName extends string = string, TPluginConfig extends IRecord | undefined = any, TRenderType extends RenderType = RenderType> {
257
+ name: TPluginName;
258
+ pluginId: string;
259
+ description?: string;
260
+ onInit?: (config: TPluginConfig) => void;
261
+ onConfigChange?: (config: TPluginConfig) => void;
262
+ onDestroy?: () => void;
263
+ render?: (...args: Parameters<TRenderType>) => ReturnType<TRenderType>;
264
+ }
265
+ type Plugin<TName extends string = string, TConfig extends IRecord | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
266
+ type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugin<infer T> ? {
267
+ [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;
268
+ } : {}));
269
+ /**
270
+ * plugin data host
271
+ * @example
272
+ * `declare module '@knotx/core' {
273
+ * interface PluginData {
274
+ * pluginName: {
275
+ * property: any
276
+ * }
277
+ * }
278
+ * }`
279
+ */
280
+ interface PluginData {
281
+ }
282
+ /**
283
+ * plugin tools host
284
+ * @example
285
+ * `declare module '@knotx/core' {
286
+ * interface PluginTools {
287
+ * pluginName: {
288
+ * toolName: (params: any) => any
289
+ * }
290
+ * }
291
+ * }`
292
+ */
293
+ interface PluginTools {
294
+ }
295
+ interface EngineTools {
296
+ }
297
+ interface IPluginInfo {
298
+ name: string;
299
+ description?: string;
300
+ }
301
+ interface IToolInfo {
302
+ type: 'function';
303
+ name: string;
304
+ description: string;
305
+ parameters: Schema;
306
+ }
307
+ type NodeOperationPipe<T extends IRecord = any> = DataOperationPipe<Node<T>>;
308
+ type EdgeOperationPipe<T extends IRecord = any> = DataOperationPipe<Edge<T>>;
309
+ type NodeOperation<T extends IRecord = any> = DataOperation<Node<T>>;
310
+ type EdgeOperation<T extends IRecord = any> = DataOperation<Edge<T>>;
311
+ type NodeOperatorFunction<T extends IRecord = any, TArgs extends any[] = any[]> = (...args: TArgs) => NodeOperation<T>[];
312
+ type EdgeOperatorFunction<T extends IRecord = any, TArgs extends any[] = any[]> = (...args: TArgs) => EdgeOperation<T>[];
313
+ interface IEngineRuntime {
314
+ render?: {
315
+ getValue: <T, R = T>(value: BehaviorSubject<T> | T, options: {
316
+ paths: string[];
317
+ selector?: (value: T, context?: any) => R;
318
+ context?: any;
319
+ }) => T | R;
320
+ };
321
+ }
322
+
323
+ export { type Interaction as A, InteractionManager as B, type Container as C, BasePlugin as D, Engine as E, type HorizontalAlignment as H, type IRecord as I, Layer as L, type NodePosition as N, type Position as P, type RenderType as R, type VerticalAlignment as V, type NodeMeasured as a, type Node as b, type NodeProps as c, type Edge as d, type EdgeProps as e, type NodeRenderType as f, type EdgeRenderType as g, type LayerComponent as h, type IPlugin as i, type Plugin as j, type PluginConfigs as k, type PluginData as l, type PluginTools as m, type EngineTools as n, type IPluginInfo as o, type IToolInfo as p, type NodeOperationPipe as q, type EdgeOperationPipe as r, type NodeOperation as s, type EdgeOperation as t, type NodeOperatorFunction as u, type EdgeOperatorFunction as v, type IEngineRuntime as w, type EngineOptions as x, type CallToolMethod as y, InteractionPriority as z };