@knotx/core 0.2.8 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +21 -18
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +21 -18
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -115,7 +115,7 @@ function getLayerRenders(plugin) {
|
|
|
115
115
|
components.push(__spreadValues$1({
|
|
116
116
|
plugin: plugin.name,
|
|
117
117
|
name: `${plugin.name}:${name}`,
|
|
118
|
-
render: Reflect.get(plugin, name)
|
|
118
|
+
render: wrapRender(Reflect.get(plugin, name), plugin)
|
|
119
119
|
}, layer));
|
|
120
120
|
if (name === "render") {
|
|
121
121
|
isRenderConsumed = true;
|
|
@@ -126,11 +126,15 @@ function getLayerRenders(plugin) {
|
|
|
126
126
|
plugin: plugin.name,
|
|
127
127
|
name: `${plugin.name}:render`,
|
|
128
128
|
layer: core.Layer.Foreground,
|
|
129
|
-
render: plugin.render
|
|
129
|
+
render: wrapRender(plugin.render, plugin)
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
return components;
|
|
133
133
|
}
|
|
134
|
+
function wrapRender(render, plugin) {
|
|
135
|
+
const wrapped = "bind" in render ? render.bind(plugin) : render;
|
|
136
|
+
return wrapped;
|
|
137
|
+
}
|
|
134
138
|
|
|
135
139
|
var __defProp$2 = Object.defineProperty;
|
|
136
140
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -145,12 +149,12 @@ class Engine {
|
|
|
145
149
|
__publicField$2(this, "nodes$", new rxjs.BehaviorSubject([]));
|
|
146
150
|
__publicField$2(this, "edges$", new rxjs.BehaviorSubject([]));
|
|
147
151
|
__publicField$2(this, "layers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
148
|
-
__publicField$2(this, "plugins$", new rxjs.BehaviorSubject(
|
|
152
|
+
__publicField$2(this, "plugins$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
149
153
|
__publicField$2(this, "nodeRenderers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
150
154
|
__publicField$2(this, "edgeRenderers$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
151
155
|
__publicField$2(this, "_pluginDataContainer", {});
|
|
152
|
-
__publicField$2(this, "toolParamsValidator", new jsonschema.Validator());
|
|
153
156
|
__publicField$2(this, "_pluginToolsContainer", {});
|
|
157
|
+
__publicField$2(this, "toolParamsValidator", new jsonschema.Validator());
|
|
154
158
|
var _a;
|
|
155
159
|
this.runtime = (_a = options.runtime) != null ? _a : {};
|
|
156
160
|
this.container$.next(options.container);
|
|
@@ -176,12 +180,12 @@ class Engine {
|
|
|
176
180
|
return this.layers$.value;
|
|
177
181
|
}
|
|
178
182
|
get plugins() {
|
|
179
|
-
return this.plugins$.value;
|
|
183
|
+
return Array.from(this.plugins$.value.values());
|
|
180
184
|
}
|
|
181
185
|
init(options) {
|
|
182
186
|
const { plugins = [], pluginConfig = {}, nodes = [], edges = [] } = options;
|
|
183
|
-
for (const
|
|
184
|
-
const plugin = new
|
|
187
|
+
for (const Plugin of plugins) {
|
|
188
|
+
const plugin = new Plugin(void 0);
|
|
185
189
|
if (this._pluginDataContainer[plugin.name]) {
|
|
186
190
|
console.warn(`Plugin ${plugin.name} already registered, please check the plugin definition`);
|
|
187
191
|
continue;
|
|
@@ -193,11 +197,12 @@ class Engine {
|
|
|
193
197
|
Reflect.set(plugin, engineSymbol, new rxjs.BehaviorSubject(null));
|
|
194
198
|
}
|
|
195
199
|
Reflect.get(plugin, engineSymbol).next(this);
|
|
196
|
-
const
|
|
197
|
-
|
|
200
|
+
const pluginsMap = this.plugins$.value;
|
|
201
|
+
pluginsMap.set(plugin.name, plugin);
|
|
202
|
+
this.plugins$.next(pluginsMap);
|
|
198
203
|
const currentLayers = this.layers$.value;
|
|
199
204
|
getLayerRenders(plugin).forEach((component) => {
|
|
200
|
-
const effectiveLayer =
|
|
205
|
+
const effectiveLayer = component.offset === void 0 ? component.layer : Math.max((component.layer >> 1) + 1, Math.min(component.layer << 1, component.layer + component.offset));
|
|
201
206
|
const layerComponents = currentLayers.get(effectiveLayer) || [];
|
|
202
207
|
currentLayers.set(effectiveLayer, [...layerComponents, component]);
|
|
203
208
|
});
|
|
@@ -211,11 +216,6 @@ class Engine {
|
|
|
211
216
|
this.nodesManager.init(nodes);
|
|
212
217
|
this.edgesManager.init(edges);
|
|
213
218
|
}
|
|
214
|
-
calculateEffectiveLayer(layer, offset) {
|
|
215
|
-
if (offset === void 0)
|
|
216
|
-
return layer;
|
|
217
|
-
return Math.max((layer >> 1) + 1, Math.min(layer << 1, layer + offset));
|
|
218
|
-
}
|
|
219
219
|
getLayerComponents(layer) {
|
|
220
220
|
return this.layers$.value.get(layer) || [];
|
|
221
221
|
}
|
|
@@ -227,7 +227,7 @@ class Engine {
|
|
|
227
227
|
}
|
|
228
228
|
changePluginConfig(pluginName, config) {
|
|
229
229
|
var _a, _b;
|
|
230
|
-
(_b = (_a = this.plugins$.value.
|
|
230
|
+
(_b = (_a = this.plugins$.value.get(pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
|
|
231
231
|
}
|
|
232
232
|
dispatchNodeOperation(operation) {
|
|
233
233
|
this.nodesManager.dispatch(operation);
|
|
@@ -235,6 +235,9 @@ class Engine {
|
|
|
235
235
|
dispatchEdgeOperation(operation) {
|
|
236
236
|
this.edgesManager.dispatch(operation);
|
|
237
237
|
}
|
|
238
|
+
getPlugin(pluginName) {
|
|
239
|
+
return this.plugins$.value.get(pluginName);
|
|
240
|
+
}
|
|
238
241
|
getNode(id) {
|
|
239
242
|
return this.nodesManager.getData(id);
|
|
240
243
|
}
|
|
@@ -313,7 +316,7 @@ class Engine {
|
|
|
313
316
|
return tool(params);
|
|
314
317
|
}
|
|
315
318
|
listPlugins() {
|
|
316
|
-
return this.plugins$.value.map((plugin) => ({
|
|
319
|
+
return Array.from(this.plugins$.value.values()).map((plugin) => ({
|
|
317
320
|
name: plugin.name,
|
|
318
321
|
description: plugin.description
|
|
319
322
|
}));
|
|
@@ -353,7 +356,7 @@ class Engine {
|
|
|
353
356
|
var _a;
|
|
354
357
|
(_a = plugin.onDestroy) == null ? void 0 : _a.call(plugin);
|
|
355
358
|
});
|
|
356
|
-
this.plugins$.next(
|
|
359
|
+
this.plugins$.next(/* @__PURE__ */ new Map());
|
|
357
360
|
this.container$.complete();
|
|
358
361
|
this.layers$.complete();
|
|
359
362
|
this.nodes$.complete();
|
package/dist/index.d.cts
CHANGED
|
@@ -106,8 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
|
|
|
106
106
|
private nodeRenderers$;
|
|
107
107
|
private edgeRenderers$;
|
|
108
108
|
private _pluginDataContainer;
|
|
109
|
-
private toolParamsValidator;
|
|
110
109
|
private _pluginToolsContainer;
|
|
110
|
+
private toolParamsValidator;
|
|
111
111
|
get container(): Container;
|
|
112
112
|
set container(value: Container);
|
|
113
113
|
get nodes(): NodeData<any>[];
|
|
@@ -116,13 +116,13 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
|
|
|
116
116
|
get plugins(): IPlugin<string, any, RenderType>[];
|
|
117
117
|
constructor(options: EngineOptions);
|
|
118
118
|
private init;
|
|
119
|
-
private calculateEffectiveLayer;
|
|
120
119
|
getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
|
|
121
120
|
addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
|
|
122
121
|
addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
|
|
123
122
|
changePluginConfig(pluginName: string, config: Record<string, any>): void;
|
|
124
123
|
dispatchNodeOperation(operation: DataOperation<NodeData>): void;
|
|
125
124
|
dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
|
|
125
|
+
getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
|
|
126
126
|
getNode(id: string): NodeData | undefined;
|
|
127
127
|
getNodeDraft(id: string): NodeData | undefined;
|
|
128
128
|
getNodes(): NodeData[];
|
package/dist/index.d.mts
CHANGED
|
@@ -106,8 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
|
|
|
106
106
|
private nodeRenderers$;
|
|
107
107
|
private edgeRenderers$;
|
|
108
108
|
private _pluginDataContainer;
|
|
109
|
-
private toolParamsValidator;
|
|
110
109
|
private _pluginToolsContainer;
|
|
110
|
+
private toolParamsValidator;
|
|
111
111
|
get container(): Container;
|
|
112
112
|
set container(value: Container);
|
|
113
113
|
get nodes(): NodeData<any>[];
|
|
@@ -116,13 +116,13 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
|
|
|
116
116
|
get plugins(): IPlugin<string, any, RenderType>[];
|
|
117
117
|
constructor(options: EngineOptions);
|
|
118
118
|
private init;
|
|
119
|
-
private calculateEffectiveLayer;
|
|
120
119
|
getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
|
|
121
120
|
addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
|
|
122
121
|
addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
|
|
123
122
|
changePluginConfig(pluginName: string, config: Record<string, any>): void;
|
|
124
123
|
dispatchNodeOperation(operation: DataOperation<NodeData>): void;
|
|
125
124
|
dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
|
|
125
|
+
getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
|
|
126
126
|
getNode(id: string): NodeData | undefined;
|
|
127
127
|
getNodeDraft(id: string): NodeData | undefined;
|
|
128
128
|
getNodes(): NodeData[];
|
package/dist/index.d.ts
CHANGED
|
@@ -106,8 +106,8 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
|
|
|
106
106
|
private nodeRenderers$;
|
|
107
107
|
private edgeRenderers$;
|
|
108
108
|
private _pluginDataContainer;
|
|
109
|
-
private toolParamsValidator;
|
|
110
109
|
private _pluginToolsContainer;
|
|
110
|
+
private toolParamsValidator;
|
|
111
111
|
get container(): Container;
|
|
112
112
|
set container(value: Container);
|
|
113
113
|
get nodes(): NodeData<any>[];
|
|
@@ -116,13 +116,13 @@ declare class Engine<TRenderType extends RenderType = RenderType> {
|
|
|
116
116
|
get plugins(): IPlugin<string, any, RenderType>[];
|
|
117
117
|
constructor(options: EngineOptions);
|
|
118
118
|
private init;
|
|
119
|
-
private calculateEffectiveLayer;
|
|
120
119
|
getLayerComponents(layer: Layer): LayerComponent<TRenderType>[];
|
|
121
120
|
addNodePipe(pipe: DataOperationPipe<NodeData>): () => void;
|
|
122
121
|
addEdgePipe(pipe: DataOperationPipe<EdgeData>): () => void;
|
|
123
122
|
changePluginConfig(pluginName: string, config: Record<string, any>): void;
|
|
124
123
|
dispatchNodeOperation(operation: DataOperation<NodeData>): void;
|
|
125
124
|
dispatchEdgeOperation(operation: DataOperation<EdgeData>): void;
|
|
125
|
+
getPlugin<TPlugin extends IPlugin>(pluginName: TPlugin['name']): TPlugin | undefined;
|
|
126
126
|
getNode(id: string): NodeData | undefined;
|
|
127
127
|
getNodeDraft(id: string): NodeData | undefined;
|
|
128
128
|
getNodes(): NodeData[];
|
package/dist/index.js
CHANGED
|
@@ -115,7 +115,7 @@ function getLayerRenders(plugin) {
|
|
|
115
115
|
components.push(__spreadValues$1({
|
|
116
116
|
plugin: plugin.name,
|
|
117
117
|
name: `${plugin.name}:${name}`,
|
|
118
|
-
render: Reflect.get(plugin, name)
|
|
118
|
+
render: wrapRender(Reflect.get(plugin, name), plugin)
|
|
119
119
|
}, layer));
|
|
120
120
|
if (name === "render") {
|
|
121
121
|
isRenderConsumed = true;
|
|
@@ -126,11 +126,15 @@ function getLayerRenders(plugin) {
|
|
|
126
126
|
plugin: plugin.name,
|
|
127
127
|
name: `${plugin.name}:render`,
|
|
128
128
|
layer: Layer.Foreground,
|
|
129
|
-
render: plugin.render
|
|
129
|
+
render: wrapRender(plugin.render, plugin)
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
return components;
|
|
133
133
|
}
|
|
134
|
+
function wrapRender(render, plugin) {
|
|
135
|
+
const wrapped = "bind" in render ? render.bind(plugin) : render;
|
|
136
|
+
return wrapped;
|
|
137
|
+
}
|
|
134
138
|
|
|
135
139
|
var __defProp$2 = Object.defineProperty;
|
|
136
140
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -145,12 +149,12 @@ class Engine {
|
|
|
145
149
|
__publicField$2(this, "nodes$", new BehaviorSubject([]));
|
|
146
150
|
__publicField$2(this, "edges$", new BehaviorSubject([]));
|
|
147
151
|
__publicField$2(this, "layers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
148
|
-
__publicField$2(this, "plugins$", new BehaviorSubject(
|
|
152
|
+
__publicField$2(this, "plugins$", new BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
149
153
|
__publicField$2(this, "nodeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
150
154
|
__publicField$2(this, "edgeRenderers$", new BehaviorSubject(/* @__PURE__ */ new Map()));
|
|
151
155
|
__publicField$2(this, "_pluginDataContainer", {});
|
|
152
|
-
__publicField$2(this, "toolParamsValidator", new Validator());
|
|
153
156
|
__publicField$2(this, "_pluginToolsContainer", {});
|
|
157
|
+
__publicField$2(this, "toolParamsValidator", new Validator());
|
|
154
158
|
var _a;
|
|
155
159
|
this.runtime = (_a = options.runtime) != null ? _a : {};
|
|
156
160
|
this.container$.next(options.container);
|
|
@@ -176,12 +180,12 @@ class Engine {
|
|
|
176
180
|
return this.layers$.value;
|
|
177
181
|
}
|
|
178
182
|
get plugins() {
|
|
179
|
-
return this.plugins$.value;
|
|
183
|
+
return Array.from(this.plugins$.value.values());
|
|
180
184
|
}
|
|
181
185
|
init(options) {
|
|
182
186
|
const { plugins = [], pluginConfig = {}, nodes = [], edges = [] } = options;
|
|
183
|
-
for (const
|
|
184
|
-
const plugin = new
|
|
187
|
+
for (const Plugin of plugins) {
|
|
188
|
+
const plugin = new Plugin(void 0);
|
|
185
189
|
if (this._pluginDataContainer[plugin.name]) {
|
|
186
190
|
console.warn(`Plugin ${plugin.name} already registered, please check the plugin definition`);
|
|
187
191
|
continue;
|
|
@@ -193,11 +197,12 @@ class Engine {
|
|
|
193
197
|
Reflect.set(plugin, engineSymbol, new BehaviorSubject(null));
|
|
194
198
|
}
|
|
195
199
|
Reflect.get(plugin, engineSymbol).next(this);
|
|
196
|
-
const
|
|
197
|
-
|
|
200
|
+
const pluginsMap = this.plugins$.value;
|
|
201
|
+
pluginsMap.set(plugin.name, plugin);
|
|
202
|
+
this.plugins$.next(pluginsMap);
|
|
198
203
|
const currentLayers = this.layers$.value;
|
|
199
204
|
getLayerRenders(plugin).forEach((component) => {
|
|
200
|
-
const effectiveLayer =
|
|
205
|
+
const effectiveLayer = component.offset === void 0 ? component.layer : Math.max((component.layer >> 1) + 1, Math.min(component.layer << 1, component.layer + component.offset));
|
|
201
206
|
const layerComponents = currentLayers.get(effectiveLayer) || [];
|
|
202
207
|
currentLayers.set(effectiveLayer, [...layerComponents, component]);
|
|
203
208
|
});
|
|
@@ -211,11 +216,6 @@ class Engine {
|
|
|
211
216
|
this.nodesManager.init(nodes);
|
|
212
217
|
this.edgesManager.init(edges);
|
|
213
218
|
}
|
|
214
|
-
calculateEffectiveLayer(layer, offset) {
|
|
215
|
-
if (offset === void 0)
|
|
216
|
-
return layer;
|
|
217
|
-
return Math.max((layer >> 1) + 1, Math.min(layer << 1, layer + offset));
|
|
218
|
-
}
|
|
219
219
|
getLayerComponents(layer) {
|
|
220
220
|
return this.layers$.value.get(layer) || [];
|
|
221
221
|
}
|
|
@@ -227,7 +227,7 @@ class Engine {
|
|
|
227
227
|
}
|
|
228
228
|
changePluginConfig(pluginName, config) {
|
|
229
229
|
var _a, _b;
|
|
230
|
-
(_b = (_a = this.plugins$.value.
|
|
230
|
+
(_b = (_a = this.plugins$.value.get(pluginName)) == null ? void 0 : _a.onConfigChange) == null ? void 0 : _b.call(_a, config);
|
|
231
231
|
}
|
|
232
232
|
dispatchNodeOperation(operation) {
|
|
233
233
|
this.nodesManager.dispatch(operation);
|
|
@@ -235,6 +235,9 @@ class Engine {
|
|
|
235
235
|
dispatchEdgeOperation(operation) {
|
|
236
236
|
this.edgesManager.dispatch(operation);
|
|
237
237
|
}
|
|
238
|
+
getPlugin(pluginName) {
|
|
239
|
+
return this.plugins$.value.get(pluginName);
|
|
240
|
+
}
|
|
238
241
|
getNode(id) {
|
|
239
242
|
return this.nodesManager.getData(id);
|
|
240
243
|
}
|
|
@@ -313,7 +316,7 @@ class Engine {
|
|
|
313
316
|
return tool(params);
|
|
314
317
|
}
|
|
315
318
|
listPlugins() {
|
|
316
|
-
return this.plugins$.value.map((plugin) => ({
|
|
319
|
+
return Array.from(this.plugins$.value.values()).map((plugin) => ({
|
|
317
320
|
name: plugin.name,
|
|
318
321
|
description: plugin.description
|
|
319
322
|
}));
|
|
@@ -353,7 +356,7 @@ class Engine {
|
|
|
353
356
|
var _a;
|
|
354
357
|
(_a = plugin.onDestroy) == null ? void 0 : _a.call(plugin);
|
|
355
358
|
});
|
|
356
|
-
this.plugins$.next(
|
|
359
|
+
this.plugins$.next(/* @__PURE__ */ new Map());
|
|
357
360
|
this.container$.complete();
|
|
358
361
|
this.layers$.complete();
|
|
359
362
|
this.nodes$.complete();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Core for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"jsonschema": "^1.5.0",
|
|
47
47
|
"lodash-es": "^4.17.21",
|
|
48
48
|
"rxjs": "^7.8.1",
|
|
49
|
-
"@knotx/data": "0.2.
|
|
50
|
-
"@knotx/utils": "0.2.
|
|
49
|
+
"@knotx/data": "0.2.10",
|
|
50
|
+
"@knotx/utils": "0.2.10"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/lodash-es": "^4.17.12",
|
|
54
|
-
"@knotx/build-config": "0.2.
|
|
55
|
-
"@knotx/eslint-config": "0.2.
|
|
56
|
-
"@knotx/typescript-config": "0.2.
|
|
54
|
+
"@knotx/build-config": "0.2.10",
|
|
55
|
+
"@knotx/eslint-config": "0.2.10",
|
|
56
|
+
"@knotx/typescript-config": "0.2.10"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "unbuild",
|