@knotx/core 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +27 -34
- package/dist/index.d.cts +16 -14
- package/dist/index.d.mts +16 -14
- package/dist/index.d.ts +16 -14
- package/dist/index.mjs +27 -34
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const core = require('@knotx/core');
|
|
4
3
|
const lodashEs = require('lodash-es');
|
|
5
4
|
const rxjs = require('rxjs');
|
|
5
|
+
const core = require('@knotx/core');
|
|
6
6
|
const utils = require('@knotx/utils');
|
|
7
7
|
const data = require('@knotx/data');
|
|
8
8
|
|
|
@@ -18,7 +18,7 @@ var Layer = /* @__PURE__ */ ((Layer2) => {
|
|
|
18
18
|
return Layer2;
|
|
19
19
|
})(Layer || {});
|
|
20
20
|
const _BasePlugin = class _BasePlugin {
|
|
21
|
-
constructor() {
|
|
21
|
+
constructor(__) {
|
|
22
22
|
__publicField$3(this, "_instanceId", _BasePlugin._instanceId++);
|
|
23
23
|
}
|
|
24
24
|
get pluginId() {
|
|
@@ -197,44 +197,33 @@ class Engine {
|
|
|
197
197
|
return this.plugins$.value;
|
|
198
198
|
}
|
|
199
199
|
init(options) {
|
|
200
|
-
const { plugins = [], nodes = [], edges = [] } = options;
|
|
201
|
-
for (const
|
|
202
|
-
|
|
203
|
-
if (
|
|
204
|
-
plugin
|
|
205
|
-
|
|
206
|
-
if (Object.is(Reflect.getPrototypeOf(def), core.BasePlugin)) {
|
|
207
|
-
plugin = new def();
|
|
208
|
-
} else {
|
|
209
|
-
plugin = def();
|
|
210
|
-
}
|
|
200
|
+
const { plugins = [], pluginConfig = {}, nodes = [], edges = [] } = options;
|
|
201
|
+
for (const Def of plugins) {
|
|
202
|
+
const plugin = new Def(void 0);
|
|
203
|
+
if (this._pluginDataContainer[plugin.name]) {
|
|
204
|
+
console.warn(`Plugin ${plugin.name} already registered, please check the plugin definition`);
|
|
205
|
+
continue;
|
|
211
206
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
this._pluginDataContainer[plugin.name] = {};
|
|
218
|
-
const engineSymbol = utils.getSymbol("engine");
|
|
219
|
-
if (!Reflect.has(plugin, engineSymbol)) {
|
|
220
|
-
Reflect.set(plugin, engineSymbol, new rxjs.BehaviorSubject(null));
|
|
221
|
-
}
|
|
222
|
-
Reflect.get(plugin, engineSymbol).next(this);
|
|
223
|
-
const currentPlugins = this.plugins$.value || [];
|
|
224
|
-
this.plugins$.next([...currentPlugins, plugin]);
|
|
225
|
-
const currentLayers = this.layers$.value;
|
|
226
|
-
getLayerRenders(plugin).forEach((component) => {
|
|
227
|
-
const effectiveLayer = this.calculateEffectiveLayer(component.layer, component.offset);
|
|
228
|
-
const layerComponents = currentLayers.get(effectiveLayer) || [];
|
|
229
|
-
currentLayers.set(effectiveLayer, [...layerComponents, component]);
|
|
230
|
-
});
|
|
231
|
-
this.layers$.next(currentLayers);
|
|
207
|
+
this._pluginDataContainer[plugin.name] = {};
|
|
208
|
+
const engineSymbol = utils.getSymbol("engine");
|
|
209
|
+
if (!Reflect.has(plugin, engineSymbol)) {
|
|
210
|
+
Reflect.set(plugin, engineSymbol, new rxjs.BehaviorSubject(null));
|
|
232
211
|
}
|
|
212
|
+
Reflect.get(plugin, engineSymbol).next(this);
|
|
213
|
+
const currentPlugins = this.plugins$.value || [];
|
|
214
|
+
this.plugins$.next([...currentPlugins, plugin]);
|
|
215
|
+
const currentLayers = this.layers$.value;
|
|
216
|
+
getLayerRenders(plugin).forEach((component) => {
|
|
217
|
+
const effectiveLayer = this.calculateEffectiveLayer(component.layer, component.offset);
|
|
218
|
+
const layerComponents = currentLayers.get(effectiveLayer) || [];
|
|
219
|
+
currentLayers.set(effectiveLayer, [...layerComponents, component]);
|
|
220
|
+
});
|
|
221
|
+
this.layers$.next(currentLayers);
|
|
233
222
|
}
|
|
234
223
|
this.plugins$.complete();
|
|
235
224
|
this.plugins$.value.forEach((plugin) => {
|
|
236
225
|
var _a;
|
|
237
|
-
return (_a = plugin.onInit) == null ? void 0 : _a.call(plugin);
|
|
226
|
+
return (_a = plugin.onInit) == null ? void 0 : _a.call(plugin, pluginConfig[plugin.name]);
|
|
238
227
|
});
|
|
239
228
|
this.nodesManager.init(nodes);
|
|
240
229
|
this.edgesManager.init(edges);
|
|
@@ -253,6 +242,10 @@ class Engine {
|
|
|
253
242
|
addEdgePipe(pipe) {
|
|
254
243
|
this.edgesManager.addDataOperationPipe(pipe);
|
|
255
244
|
}
|
|
245
|
+
changePluginConfig(pluginName, config) {
|
|
246
|
+
var _a, _b;
|
|
247
|
+
(_b = (_a = this.plugins$.value.find((plugin) => plugin.name === pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
|
|
248
|
+
}
|
|
256
249
|
dispatchNodeOperation(operation) {
|
|
257
250
|
this.nodesManager.dispatch(operation);
|
|
258
251
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
2
|
import { DataOperationPipe, DataOperation, DataManager } from '@knotx/data';
|
|
3
3
|
export * from '@knotx/data';
|
|
4
|
-
import { Container as Container$1,
|
|
4
|
+
import { Container as Container$1, Plugin as Plugin$1, NodeData as NodeData$1, EdgeData as EdgeData$1, IEngineRuntime as IEngineRuntime$1, RenderType as RenderType$1, LayerComponent as LayerComponent$1, IPlugin as IPlugin$1, Layer as Layer$1, NodeRenderType as NodeRenderType$1, EdgeRenderType as EdgeRenderType$1, PluginData as PluginData$1, InteractionPriority as InteractionPriority$1 } from '@knotx/core';
|
|
5
5
|
export * from '@knotx/utils';
|
|
6
6
|
|
|
7
7
|
type HorizontalAlignment = 'left' | 'right';
|
|
@@ -65,25 +65,25 @@ interface LayerComponent<TRenderType> {
|
|
|
65
65
|
*/
|
|
66
66
|
offset?: number;
|
|
67
67
|
}
|
|
68
|
-
interface IPlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> {
|
|
68
|
+
interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
|
|
69
69
|
name: TPluginName;
|
|
70
70
|
pluginId: string;
|
|
71
|
-
onInit?: () => void;
|
|
71
|
+
onInit?: (config: TPluginConfig) => void;
|
|
72
|
+
onConfigChange?: (config: TPluginConfig) => void;
|
|
72
73
|
onDestroy?: () => void;
|
|
73
74
|
render?: (...args: Parameters<TRenderType>) => ReturnType<TRenderType>;
|
|
74
75
|
}
|
|
75
|
-
declare abstract class BasePlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TRenderType> {
|
|
76
|
+
declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
|
|
76
77
|
abstract name: TPluginName;
|
|
78
|
+
constructor(__: TPluginConfig);
|
|
77
79
|
private static _instanceId;
|
|
78
80
|
private _instanceId;
|
|
79
81
|
get pluginId(): string;
|
|
80
82
|
}
|
|
81
|
-
type
|
|
82
|
-
type
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
...ConstructorParameters<T>
|
|
86
|
-
];
|
|
83
|
+
type Plugin<TName extends string = string, TConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
|
|
84
|
+
type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugin<infer T> ? {
|
|
85
|
+
[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;
|
|
86
|
+
} : {}));
|
|
87
87
|
/**
|
|
88
88
|
* plugin data host
|
|
89
89
|
* @example
|
|
@@ -193,7 +193,8 @@ declare class InteractionManager {
|
|
|
193
193
|
|
|
194
194
|
interface EngineOptions {
|
|
195
195
|
container: Container$1;
|
|
196
|
-
plugins?:
|
|
196
|
+
plugins?: Plugin$1[];
|
|
197
|
+
pluginConfig?: Record<string, any>;
|
|
197
198
|
nodes?: NodeData$1[];
|
|
198
199
|
edges?: EdgeData$1[];
|
|
199
200
|
runtime?: IEngineRuntime$1;
|
|
@@ -216,13 +217,14 @@ declare class Engine<TRenderType extends RenderType$1 = RenderType$1> {
|
|
|
216
217
|
get nodes(): NodeData$1<any>[];
|
|
217
218
|
get edges(): EdgeData$1<any>[];
|
|
218
219
|
get layers(): Map<number, LayerComponent$1<TRenderType>[]>;
|
|
219
|
-
get plugins(): IPlugin$1<string,
|
|
220
|
+
get plugins(): IPlugin$1<string, any, RenderType$1>[];
|
|
220
221
|
constructor(options: EngineOptions);
|
|
221
222
|
private init;
|
|
222
223
|
private calculateEffectiveLayer;
|
|
223
224
|
getLayerComponents(layer: Layer$1): LayerComponent$1<TRenderType>[];
|
|
224
225
|
addNodePipe(pipe: DataOperationPipe<NodeData$1>): void;
|
|
225
226
|
addEdgePipe(pipe: DataOperationPipe<EdgeData$1>): void;
|
|
227
|
+
changePluginConfig(pluginName: string, config: Record<string, any>): void;
|
|
226
228
|
dispatchNodeOperation(operation: DataOperation<NodeData$1>): void;
|
|
227
229
|
dispatchEdgeOperation(operation: DataOperation<EdgeData$1>): void;
|
|
228
230
|
getNode(id: string): NodeData$1 | undefined;
|
|
@@ -242,7 +244,7 @@ declare class Engine<TRenderType extends RenderType$1 = RenderType$1> {
|
|
|
242
244
|
destroy(): void;
|
|
243
245
|
}
|
|
244
246
|
|
|
245
|
-
declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1
|
|
247
|
+
declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1): LayerComponent$1<TRenderType>[];
|
|
246
248
|
|
|
247
249
|
/**
|
|
248
250
|
* Runtime 类
|
|
@@ -305,4 +307,4 @@ declare function use<T, TContext>(hook: () => {
|
|
|
305
307
|
__contextValue__: TContext;
|
|
306
308
|
}, context: TContext): T;
|
|
307
309
|
|
|
308
|
-
export { BasePlugin, type Container, type EdgeData, type EdgeOperation, type EdgeOperationPipe, type EdgeOperatorFunction, type EdgeProps, type EdgeRenderType, Engine, type EngineOptions, type HorizontalAlignment, type IEngineRuntime, type IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, type LayerComponent, type NodeData, type NodeMeasured, type NodeOperation, type NodeOperationPipe, type NodeOperatorFunction, type NodePosition, type NodeProps, type NodeRenderType, type
|
|
310
|
+
export { BasePlugin, type Container, type EdgeData, type EdgeOperation, type EdgeOperationPipe, type EdgeOperatorFunction, type EdgeProps, type EdgeRenderType, Engine, type EngineOptions, type HorizontalAlignment, type IEngineRuntime, type IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, type LayerComponent, type NodeData, type NodeMeasured, type NodeOperation, type NodeOperationPipe, type NodeOperatorFunction, type NodePosition, type NodeProps, type NodeRenderType, type Plugin, type PluginConfigs, type PluginData, type Position, type RenderType, Runtime, type VerticalAlignment, getLayerRenders, use };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
2
|
import { DataOperationPipe, DataOperation, DataManager } from '@knotx/data';
|
|
3
3
|
export * from '@knotx/data';
|
|
4
|
-
import { Container as Container$1,
|
|
4
|
+
import { Container as Container$1, Plugin as Plugin$1, NodeData as NodeData$1, EdgeData as EdgeData$1, IEngineRuntime as IEngineRuntime$1, RenderType as RenderType$1, LayerComponent as LayerComponent$1, IPlugin as IPlugin$1, Layer as Layer$1, NodeRenderType as NodeRenderType$1, EdgeRenderType as EdgeRenderType$1, PluginData as PluginData$1, InteractionPriority as InteractionPriority$1 } from '@knotx/core';
|
|
5
5
|
export * from '@knotx/utils';
|
|
6
6
|
|
|
7
7
|
type HorizontalAlignment = 'left' | 'right';
|
|
@@ -65,25 +65,25 @@ interface LayerComponent<TRenderType> {
|
|
|
65
65
|
*/
|
|
66
66
|
offset?: number;
|
|
67
67
|
}
|
|
68
|
-
interface IPlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> {
|
|
68
|
+
interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
|
|
69
69
|
name: TPluginName;
|
|
70
70
|
pluginId: string;
|
|
71
|
-
onInit?: () => void;
|
|
71
|
+
onInit?: (config: TPluginConfig) => void;
|
|
72
|
+
onConfigChange?: (config: TPluginConfig) => void;
|
|
72
73
|
onDestroy?: () => void;
|
|
73
74
|
render?: (...args: Parameters<TRenderType>) => ReturnType<TRenderType>;
|
|
74
75
|
}
|
|
75
|
-
declare abstract class BasePlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TRenderType> {
|
|
76
|
+
declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
|
|
76
77
|
abstract name: TPluginName;
|
|
78
|
+
constructor(__: TPluginConfig);
|
|
77
79
|
private static _instanceId;
|
|
78
80
|
private _instanceId;
|
|
79
81
|
get pluginId(): string;
|
|
80
82
|
}
|
|
81
|
-
type
|
|
82
|
-
type
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
...ConstructorParameters<T>
|
|
86
|
-
];
|
|
83
|
+
type Plugin<TName extends string = string, TConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
|
|
84
|
+
type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugin<infer T> ? {
|
|
85
|
+
[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;
|
|
86
|
+
} : {}));
|
|
87
87
|
/**
|
|
88
88
|
* plugin data host
|
|
89
89
|
* @example
|
|
@@ -193,7 +193,8 @@ declare class InteractionManager {
|
|
|
193
193
|
|
|
194
194
|
interface EngineOptions {
|
|
195
195
|
container: Container$1;
|
|
196
|
-
plugins?:
|
|
196
|
+
plugins?: Plugin$1[];
|
|
197
|
+
pluginConfig?: Record<string, any>;
|
|
197
198
|
nodes?: NodeData$1[];
|
|
198
199
|
edges?: EdgeData$1[];
|
|
199
200
|
runtime?: IEngineRuntime$1;
|
|
@@ -216,13 +217,14 @@ declare class Engine<TRenderType extends RenderType$1 = RenderType$1> {
|
|
|
216
217
|
get nodes(): NodeData$1<any>[];
|
|
217
218
|
get edges(): EdgeData$1<any>[];
|
|
218
219
|
get layers(): Map<number, LayerComponent$1<TRenderType>[]>;
|
|
219
|
-
get plugins(): IPlugin$1<string,
|
|
220
|
+
get plugins(): IPlugin$1<string, any, RenderType$1>[];
|
|
220
221
|
constructor(options: EngineOptions);
|
|
221
222
|
private init;
|
|
222
223
|
private calculateEffectiveLayer;
|
|
223
224
|
getLayerComponents(layer: Layer$1): LayerComponent$1<TRenderType>[];
|
|
224
225
|
addNodePipe(pipe: DataOperationPipe<NodeData$1>): void;
|
|
225
226
|
addEdgePipe(pipe: DataOperationPipe<EdgeData$1>): void;
|
|
227
|
+
changePluginConfig(pluginName: string, config: Record<string, any>): void;
|
|
226
228
|
dispatchNodeOperation(operation: DataOperation<NodeData$1>): void;
|
|
227
229
|
dispatchEdgeOperation(operation: DataOperation<EdgeData$1>): void;
|
|
228
230
|
getNode(id: string): NodeData$1 | undefined;
|
|
@@ -242,7 +244,7 @@ declare class Engine<TRenderType extends RenderType$1 = RenderType$1> {
|
|
|
242
244
|
destroy(): void;
|
|
243
245
|
}
|
|
244
246
|
|
|
245
|
-
declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1
|
|
247
|
+
declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1): LayerComponent$1<TRenderType>[];
|
|
246
248
|
|
|
247
249
|
/**
|
|
248
250
|
* Runtime 类
|
|
@@ -305,4 +307,4 @@ declare function use<T, TContext>(hook: () => {
|
|
|
305
307
|
__contextValue__: TContext;
|
|
306
308
|
}, context: TContext): T;
|
|
307
309
|
|
|
308
|
-
export { BasePlugin, type Container, type EdgeData, type EdgeOperation, type EdgeOperationPipe, type EdgeOperatorFunction, type EdgeProps, type EdgeRenderType, Engine, type EngineOptions, type HorizontalAlignment, type IEngineRuntime, type IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, type LayerComponent, type NodeData, type NodeMeasured, type NodeOperation, type NodeOperationPipe, type NodeOperatorFunction, type NodePosition, type NodeProps, type NodeRenderType, type
|
|
310
|
+
export { BasePlugin, type Container, type EdgeData, type EdgeOperation, type EdgeOperationPipe, type EdgeOperatorFunction, type EdgeProps, type EdgeRenderType, Engine, type EngineOptions, type HorizontalAlignment, type IEngineRuntime, type IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, type LayerComponent, type NodeData, type NodeMeasured, type NodeOperation, type NodeOperationPipe, type NodeOperatorFunction, type NodePosition, type NodeProps, type NodeRenderType, type Plugin, type PluginConfigs, type PluginData, type Position, type RenderType, Runtime, type VerticalAlignment, getLayerRenders, use };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BehaviorSubject } from 'rxjs';
|
|
2
2
|
import { DataOperationPipe, DataOperation, DataManager } from '@knotx/data';
|
|
3
3
|
export * from '@knotx/data';
|
|
4
|
-
import { Container as Container$1,
|
|
4
|
+
import { Container as Container$1, Plugin as Plugin$1, NodeData as NodeData$1, EdgeData as EdgeData$1, IEngineRuntime as IEngineRuntime$1, RenderType as RenderType$1, LayerComponent as LayerComponent$1, IPlugin as IPlugin$1, Layer as Layer$1, NodeRenderType as NodeRenderType$1, EdgeRenderType as EdgeRenderType$1, PluginData as PluginData$1, InteractionPriority as InteractionPriority$1 } from '@knotx/core';
|
|
5
5
|
export * from '@knotx/utils';
|
|
6
6
|
|
|
7
7
|
type HorizontalAlignment = 'left' | 'right';
|
|
@@ -65,25 +65,25 @@ interface LayerComponent<TRenderType> {
|
|
|
65
65
|
*/
|
|
66
66
|
offset?: number;
|
|
67
67
|
}
|
|
68
|
-
interface IPlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> {
|
|
68
|
+
interface IPlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> {
|
|
69
69
|
name: TPluginName;
|
|
70
70
|
pluginId: string;
|
|
71
|
-
onInit?: () => void;
|
|
71
|
+
onInit?: (config: TPluginConfig) => void;
|
|
72
|
+
onConfigChange?: (config: TPluginConfig) => void;
|
|
72
73
|
onDestroy?: () => void;
|
|
73
74
|
render?: (...args: Parameters<TRenderType>) => ReturnType<TRenderType>;
|
|
74
75
|
}
|
|
75
|
-
declare abstract class BasePlugin<TPluginName extends string = string, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TRenderType> {
|
|
76
|
+
declare abstract class BasePlugin<TPluginName extends string = string, TPluginConfig extends Record<string, any> | undefined = undefined, TRenderType extends RenderType = RenderType> implements IPlugin<TPluginName, TPluginConfig, TRenderType> {
|
|
76
77
|
abstract name: TPluginName;
|
|
78
|
+
constructor(__: TPluginConfig);
|
|
77
79
|
private static _instanceId;
|
|
78
80
|
private _instanceId;
|
|
79
81
|
get pluginId(): string;
|
|
80
82
|
}
|
|
81
|
-
type
|
|
82
|
-
type
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
...ConstructorParameters<T>
|
|
86
|
-
];
|
|
83
|
+
type Plugin<TName extends string = string, TConfig extends Record<string, any> | undefined = any, TRenderType extends RenderType = RenderType> = new (__: TConfig) => BasePlugin<TName, TConfig, TRenderType>;
|
|
84
|
+
type PluginConfigs<TPlugins extends Plugin[]> = ((TPlugins[number] extends Plugin<infer T> ? {
|
|
85
|
+
[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;
|
|
86
|
+
} : {}));
|
|
87
87
|
/**
|
|
88
88
|
* plugin data host
|
|
89
89
|
* @example
|
|
@@ -193,7 +193,8 @@ declare class InteractionManager {
|
|
|
193
193
|
|
|
194
194
|
interface EngineOptions {
|
|
195
195
|
container: Container$1;
|
|
196
|
-
plugins?:
|
|
196
|
+
plugins?: Plugin$1[];
|
|
197
|
+
pluginConfig?: Record<string, any>;
|
|
197
198
|
nodes?: NodeData$1[];
|
|
198
199
|
edges?: EdgeData$1[];
|
|
199
200
|
runtime?: IEngineRuntime$1;
|
|
@@ -216,13 +217,14 @@ declare class Engine<TRenderType extends RenderType$1 = RenderType$1> {
|
|
|
216
217
|
get nodes(): NodeData$1<any>[];
|
|
217
218
|
get edges(): EdgeData$1<any>[];
|
|
218
219
|
get layers(): Map<number, LayerComponent$1<TRenderType>[]>;
|
|
219
|
-
get plugins(): IPlugin$1<string,
|
|
220
|
+
get plugins(): IPlugin$1<string, any, RenderType$1>[];
|
|
220
221
|
constructor(options: EngineOptions);
|
|
221
222
|
private init;
|
|
222
223
|
private calculateEffectiveLayer;
|
|
223
224
|
getLayerComponents(layer: Layer$1): LayerComponent$1<TRenderType>[];
|
|
224
225
|
addNodePipe(pipe: DataOperationPipe<NodeData$1>): void;
|
|
225
226
|
addEdgePipe(pipe: DataOperationPipe<EdgeData$1>): void;
|
|
227
|
+
changePluginConfig(pluginName: string, config: Record<string, any>): void;
|
|
226
228
|
dispatchNodeOperation(operation: DataOperation<NodeData$1>): void;
|
|
227
229
|
dispatchEdgeOperation(operation: DataOperation<EdgeData$1>): void;
|
|
228
230
|
getNode(id: string): NodeData$1 | undefined;
|
|
@@ -242,7 +244,7 @@ declare class Engine<TRenderType extends RenderType$1 = RenderType$1> {
|
|
|
242
244
|
destroy(): void;
|
|
243
245
|
}
|
|
244
246
|
|
|
245
|
-
declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1
|
|
247
|
+
declare function getLayerRenders<TRenderType extends RenderType$1 = RenderType$1>(plugin: IPlugin$1): LayerComponent$1<TRenderType>[];
|
|
246
248
|
|
|
247
249
|
/**
|
|
248
250
|
* Runtime 类
|
|
@@ -305,4 +307,4 @@ declare function use<T, TContext>(hook: () => {
|
|
|
305
307
|
__contextValue__: TContext;
|
|
306
308
|
}, context: TContext): T;
|
|
307
309
|
|
|
308
|
-
export { BasePlugin, type Container, type EdgeData, type EdgeOperation, type EdgeOperationPipe, type EdgeOperatorFunction, type EdgeProps, type EdgeRenderType, Engine, type EngineOptions, type HorizontalAlignment, type IEngineRuntime, type IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, type LayerComponent, type NodeData, type NodeMeasured, type NodeOperation, type NodeOperationPipe, type NodeOperatorFunction, type NodePosition, type NodeProps, type NodeRenderType, type
|
|
310
|
+
export { BasePlugin, type Container, type EdgeData, type EdgeOperation, type EdgeOperationPipe, type EdgeOperatorFunction, type EdgeProps, type EdgeRenderType, Engine, type EngineOptions, type HorizontalAlignment, type IEngineRuntime, type IPlugin, type Interaction, InteractionManager, InteractionPriority, Layer, type LayerComponent, type NodeData, type NodeMeasured, type NodeOperation, type NodeOperationPipe, type NodeOperatorFunction, type NodePosition, type NodeProps, type NodeRenderType, type Plugin, type PluginConfigs, type PluginData, type Position, type RenderType, Runtime, type VerticalAlignment, getLayerRenders, use };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Layer as Layer$1, BasePlugin as BasePlugin$1 } from '@knotx/core';
|
|
2
1
|
import { set, get } from 'lodash-es';
|
|
3
2
|
import { BehaviorSubject, identity } from 'rxjs';
|
|
3
|
+
import { Layer as Layer$1 } from '@knotx/core';
|
|
4
4
|
import { getSymbol } from '@knotx/utils';
|
|
5
5
|
export * from '@knotx/utils';
|
|
6
6
|
import { DataManager } from '@knotx/data';
|
|
@@ -18,7 +18,7 @@ var Layer = /* @__PURE__ */ ((Layer2) => {
|
|
|
18
18
|
return Layer2;
|
|
19
19
|
})(Layer || {});
|
|
20
20
|
const _BasePlugin = class _BasePlugin {
|
|
21
|
-
constructor() {
|
|
21
|
+
constructor(__) {
|
|
22
22
|
__publicField$3(this, "_instanceId", _BasePlugin._instanceId++);
|
|
23
23
|
}
|
|
24
24
|
get pluginId() {
|
|
@@ -197,44 +197,33 @@ class Engine {
|
|
|
197
197
|
return this.plugins$.value;
|
|
198
198
|
}
|
|
199
199
|
init(options) {
|
|
200
|
-
const { plugins = [], nodes = [], edges = [] } = options;
|
|
201
|
-
for (const
|
|
202
|
-
|
|
203
|
-
if (
|
|
204
|
-
plugin
|
|
205
|
-
|
|
206
|
-
if (Object.is(Reflect.getPrototypeOf(def), BasePlugin$1)) {
|
|
207
|
-
plugin = new def();
|
|
208
|
-
} else {
|
|
209
|
-
plugin = def();
|
|
210
|
-
}
|
|
200
|
+
const { plugins = [], pluginConfig = {}, nodes = [], edges = [] } = options;
|
|
201
|
+
for (const Def of plugins) {
|
|
202
|
+
const plugin = new Def(void 0);
|
|
203
|
+
if (this._pluginDataContainer[plugin.name]) {
|
|
204
|
+
console.warn(`Plugin ${plugin.name} already registered, please check the plugin definition`);
|
|
205
|
+
continue;
|
|
211
206
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
this._pluginDataContainer[plugin.name] = {};
|
|
218
|
-
const engineSymbol = getSymbol("engine");
|
|
219
|
-
if (!Reflect.has(plugin, engineSymbol)) {
|
|
220
|
-
Reflect.set(plugin, engineSymbol, new BehaviorSubject(null));
|
|
221
|
-
}
|
|
222
|
-
Reflect.get(plugin, engineSymbol).next(this);
|
|
223
|
-
const currentPlugins = this.plugins$.value || [];
|
|
224
|
-
this.plugins$.next([...currentPlugins, plugin]);
|
|
225
|
-
const currentLayers = this.layers$.value;
|
|
226
|
-
getLayerRenders(plugin).forEach((component) => {
|
|
227
|
-
const effectiveLayer = this.calculateEffectiveLayer(component.layer, component.offset);
|
|
228
|
-
const layerComponents = currentLayers.get(effectiveLayer) || [];
|
|
229
|
-
currentLayers.set(effectiveLayer, [...layerComponents, component]);
|
|
230
|
-
});
|
|
231
|
-
this.layers$.next(currentLayers);
|
|
207
|
+
this._pluginDataContainer[plugin.name] = {};
|
|
208
|
+
const engineSymbol = getSymbol("engine");
|
|
209
|
+
if (!Reflect.has(plugin, engineSymbol)) {
|
|
210
|
+
Reflect.set(plugin, engineSymbol, new BehaviorSubject(null));
|
|
232
211
|
}
|
|
212
|
+
Reflect.get(plugin, engineSymbol).next(this);
|
|
213
|
+
const currentPlugins = this.plugins$.value || [];
|
|
214
|
+
this.plugins$.next([...currentPlugins, plugin]);
|
|
215
|
+
const currentLayers = this.layers$.value;
|
|
216
|
+
getLayerRenders(plugin).forEach((component) => {
|
|
217
|
+
const effectiveLayer = this.calculateEffectiveLayer(component.layer, component.offset);
|
|
218
|
+
const layerComponents = currentLayers.get(effectiveLayer) || [];
|
|
219
|
+
currentLayers.set(effectiveLayer, [...layerComponents, component]);
|
|
220
|
+
});
|
|
221
|
+
this.layers$.next(currentLayers);
|
|
233
222
|
}
|
|
234
223
|
this.plugins$.complete();
|
|
235
224
|
this.plugins$.value.forEach((plugin) => {
|
|
236
225
|
var _a;
|
|
237
|
-
return (_a = plugin.onInit) == null ? void 0 : _a.call(plugin);
|
|
226
|
+
return (_a = plugin.onInit) == null ? void 0 : _a.call(plugin, pluginConfig[plugin.name]);
|
|
238
227
|
});
|
|
239
228
|
this.nodesManager.init(nodes);
|
|
240
229
|
this.edgesManager.init(edges);
|
|
@@ -253,6 +242,10 @@ class Engine {
|
|
|
253
242
|
addEdgePipe(pipe) {
|
|
254
243
|
this.edgesManager.addDataOperationPipe(pipe);
|
|
255
244
|
}
|
|
245
|
+
changePluginConfig(pluginName, config) {
|
|
246
|
+
var _a, _b;
|
|
247
|
+
(_b = (_a = this.plugins$.value.find((plugin) => plugin.name === pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
|
|
248
|
+
}
|
|
256
249
|
dispatchNodeOperation(operation) {
|
|
257
250
|
this.nodesManager.dispatch(operation);
|
|
258
251
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.7",
|
|
5
5
|
"description": "Core for Knotx",
|
|
6
6
|
"author": "boenfu",
|
|
7
7
|
"license": "MIT",
|
|
@@ -41,14 +41,14 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"lodash-es": "^4.17.21",
|
|
43
43
|
"rxjs": "^7.8.1",
|
|
44
|
-
"@knotx/data": "0.0.
|
|
45
|
-
"@knotx/utils": "0.0.
|
|
44
|
+
"@knotx/data": "0.0.7",
|
|
45
|
+
"@knotx/utils": "0.0.7"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/lodash-es": "^4.17.12",
|
|
49
|
-
"@knotx/build-config": "0.0.
|
|
50
|
-
"@knotx/eslint-config": "0.0.
|
|
51
|
-
"@knotx/typescript-config": "0.0.
|
|
49
|
+
"@knotx/build-config": "0.0.7",
|
|
50
|
+
"@knotx/eslint-config": "0.0.7",
|
|
51
|
+
"@knotx/typescript-config": "0.0.7"
|
|
52
52
|
},
|
|
53
53
|
"scripts": {
|
|
54
54
|
"build": "unbuild --failOnWarn=false",
|