@knotx/react 0.2.13 → 0.2.15
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 +45 -6
- package/dist/index.d.cts +27 -11
- package/dist/index.d.mts +27 -11
- package/dist/index.d.ts +27 -11
- package/dist/index.js +47 -8
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -10,12 +10,15 @@ const pluginsBaseRender = require('@knotx/plugins-base-render');
|
|
|
10
10
|
function useContainerRef(onResize) {
|
|
11
11
|
const [container, setContainer] = react.useState();
|
|
12
12
|
const [_, setSize] = react.useState();
|
|
13
|
+
const onResizeRef = react.useRef(onResize);
|
|
14
|
+
onResizeRef.current = onResize;
|
|
13
15
|
react.useLayoutEffect(() => {
|
|
14
16
|
if (!container)
|
|
15
17
|
return;
|
|
16
18
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
19
|
+
var _a;
|
|
17
20
|
const { width, height } = entries[0].contentRect;
|
|
18
|
-
|
|
21
|
+
(_a = onResizeRef.current) == null ? void 0 : _a.call(onResizeRef, { width, height });
|
|
19
22
|
setSize({ width, height });
|
|
20
23
|
});
|
|
21
24
|
resizeObserver.observe(container);
|
|
@@ -59,6 +62,29 @@ function useLayerContent(engineRef) {
|
|
|
59
62
|
) });
|
|
60
63
|
}
|
|
61
64
|
|
|
65
|
+
function useDataUpdate(engineRef, { nodes, edges, initRef }) {
|
|
66
|
+
react.useEffect(() => {
|
|
67
|
+
const engine = engineRef.current;
|
|
68
|
+
if (!engine || !initRef.current) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const previousNodes = engine.nodesManager.dataMap$.value;
|
|
72
|
+
const currentNodes = new Map(nodes == null ? void 0 : nodes.map((node) => [node.id, node]));
|
|
73
|
+
const operation = core.buildDiffOperation(previousNodes, currentNodes);
|
|
74
|
+
engine.dispatchNodeOperation(operation);
|
|
75
|
+
}, [nodes, nodes == null ? void 0 : nodes.length]);
|
|
76
|
+
react.useEffect(() => {
|
|
77
|
+
const engine = engineRef.current;
|
|
78
|
+
if (!engine || !initRef.current) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const previousEdges = engine.edgesManager.dataMap$.value;
|
|
82
|
+
const currentEdges = new Map(edges == null ? void 0 : edges.map((edge) => [edge.id, edge]));
|
|
83
|
+
const operation = core.buildDiffOperation(previousEdges, currentEdges);
|
|
84
|
+
engine.dispatchEdgeOperation(operation);
|
|
85
|
+
}, [edges, edges == null ? void 0 : edges.length]);
|
|
86
|
+
}
|
|
87
|
+
|
|
62
88
|
function useEngineRef() {
|
|
63
89
|
const engineRef = react.useRef(null);
|
|
64
90
|
react.useLayoutEffect(() => () => {
|
|
@@ -76,10 +102,14 @@ function useMergedPlugins(plugins, disablePresetPlugins) {
|
|
|
76
102
|
return [pluginsBaseRender.BaseRender, ...plugins || []];
|
|
77
103
|
}, [disablePresetPlugins, plugins]);
|
|
78
104
|
}
|
|
79
|
-
function usePluginConfigUpdate(engineRef,
|
|
105
|
+
function usePluginConfigUpdate(engineRef, {
|
|
106
|
+
initRef,
|
|
107
|
+
pluginConfig = {}
|
|
108
|
+
}) {
|
|
80
109
|
const pluginConfigRef = react.useRef(pluginConfig);
|
|
81
110
|
react.useLayoutEffect(() => {
|
|
82
|
-
|
|
111
|
+
const engine = engineRef.current;
|
|
112
|
+
if (!engine || !initRef.current) {
|
|
83
113
|
return;
|
|
84
114
|
}
|
|
85
115
|
for (const pluginName in pluginConfig) {
|
|
@@ -88,7 +118,7 @@ function usePluginConfigUpdate(engineRef, pluginConfig = {}) {
|
|
|
88
118
|
continue;
|
|
89
119
|
}
|
|
90
120
|
pluginConfigRef.current[pluginName] = pluginConfigValue;
|
|
91
|
-
|
|
121
|
+
engine.changePluginConfig(pluginName, pluginConfigValue);
|
|
92
122
|
}
|
|
93
123
|
});
|
|
94
124
|
}
|
|
@@ -112,6 +142,8 @@ var __spreadValues = (a, b) => {
|
|
|
112
142
|
const Knotx = react.memo(react.forwardRef(({
|
|
113
143
|
className,
|
|
114
144
|
style,
|
|
145
|
+
initialNodes,
|
|
146
|
+
initialEdges,
|
|
115
147
|
nodes,
|
|
116
148
|
edges,
|
|
117
149
|
plugins: _plugins,
|
|
@@ -126,11 +158,18 @@ const Knotx = react.memo(react.forwardRef(({
|
|
|
126
158
|
if (engineRef.current) {
|
|
127
159
|
engineRef.current.container = containerSize;
|
|
128
160
|
} else {
|
|
129
|
-
engineRef.current = initReactEngine({
|
|
161
|
+
engineRef.current = initReactEngine({
|
|
162
|
+
container: containerSize,
|
|
163
|
+
nodes: nodes != null ? nodes : initialNodes,
|
|
164
|
+
edges: edges != null ? edges : initialEdges,
|
|
165
|
+
plugins,
|
|
166
|
+
pluginConfig
|
|
167
|
+
});
|
|
130
168
|
}
|
|
131
169
|
});
|
|
132
170
|
react.useImperativeHandle(ref, () => ({ engineRef }));
|
|
133
|
-
|
|
171
|
+
useDataUpdate(engineRef, { nodes, edges, initRef });
|
|
172
|
+
usePluginConfigUpdate(engineRef, { pluginConfig, initRef });
|
|
134
173
|
const content = useLayerContent(engineRef);
|
|
135
174
|
if (!initRef.current && engineRef.current && content) {
|
|
136
175
|
initRef.current = true;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
-
import { Engine, Plugin,
|
|
2
|
-
export {
|
|
1
|
+
import { IRecord, Engine, Plugin, Node, Edge } from '@knotx/core';
|
|
2
|
+
export { Edge, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, Node, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, PluginTools, Position } from '@knotx/core';
|
|
3
3
|
import { FC, MutableRefObject, Ref, CSSProperties, ForwardedRef, ReactElement } from 'react';
|
|
4
4
|
|
|
5
|
-
type ReactEngine = Engine<FC<any
|
|
6
|
-
interface KnotxInstance {
|
|
7
|
-
engineRef: MutableRefObject<ReactEngine | null>;
|
|
5
|
+
type ReactEngine<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = Engine<FC<any>, TNode, TEdge>;
|
|
6
|
+
interface KnotxInstance<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
|
|
7
|
+
engineRef: MutableRefObject<ReactEngine<TNode, TEdge> | null>;
|
|
8
8
|
}
|
|
9
|
-
type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
10
|
-
ref?: Ref<KnotxInstance
|
|
9
|
+
type KnotxProps<TPlugins extends Plugin[] = Plugin[], TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = {
|
|
10
|
+
ref?: Ref<KnotxInstance<TNode, TEdge>> | undefined;
|
|
11
11
|
className?: string;
|
|
12
12
|
style?: CSSProperties;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* initial nodes used to create engine
|
|
15
|
+
*/
|
|
16
|
+
initialNodes?: Node<TNode>[];
|
|
17
|
+
/**
|
|
18
|
+
* initial edges used to create engine
|
|
19
|
+
*/
|
|
20
|
+
initialEdges?: Edge<TEdge>[];
|
|
21
|
+
/**
|
|
22
|
+
* auto dispatch diff operation to engine when nodes changed
|
|
23
|
+
* if not provided , use initialNodes
|
|
24
|
+
*/
|
|
25
|
+
nodes?: Node<TNode>[];
|
|
26
|
+
/**
|
|
27
|
+
* auto dispatch diff operation to engine when edges changed
|
|
28
|
+
* if not provided, use initialEdges
|
|
29
|
+
*/
|
|
30
|
+
edges?: Edge<TEdge>[];
|
|
15
31
|
plugins?: TPlugins;
|
|
16
32
|
/**
|
|
17
33
|
* disable preset plugins
|
|
@@ -20,7 +36,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
20
36
|
* @default false
|
|
21
37
|
*/
|
|
22
38
|
disablePresetPlugins?: boolean;
|
|
23
|
-
onInit?: (engine: ReactEngine) => void;
|
|
39
|
+
onInit?: (engine: ReactEngine<TNode, TEdge>) => void;
|
|
24
40
|
} & ((TPlugins[number] extends Plugin<infer T> ? {
|
|
25
41
|
[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;
|
|
26
42
|
} : {}) extends infer PluginConfig ? {} extends PluginConfig ? {
|
|
@@ -30,7 +46,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
30
46
|
} : {});
|
|
31
47
|
|
|
32
48
|
declare const Knotx: {
|
|
33
|
-
<TPlugins extends Plugin[]>(props: KnotxProps<TPlugins>, ref: ForwardedRef<KnotxInstance
|
|
49
|
+
<TPlugins extends Plugin[], TNode extends IRecord, TEdge extends IRecord>(props: KnotxProps<TPlugins, TNode, TEdge>, ref: ForwardedRef<KnotxInstance<TNode, TEdge>>): ReactElement | null;
|
|
34
50
|
displayName?: string | undefined;
|
|
35
51
|
};
|
|
36
52
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
-
import { Engine, Plugin,
|
|
2
|
-
export {
|
|
1
|
+
import { IRecord, Engine, Plugin, Node, Edge } from '@knotx/core';
|
|
2
|
+
export { Edge, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, Node, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, PluginTools, Position } from '@knotx/core';
|
|
3
3
|
import { FC, MutableRefObject, Ref, CSSProperties, ForwardedRef, ReactElement } from 'react';
|
|
4
4
|
|
|
5
|
-
type ReactEngine = Engine<FC<any
|
|
6
|
-
interface KnotxInstance {
|
|
7
|
-
engineRef: MutableRefObject<ReactEngine | null>;
|
|
5
|
+
type ReactEngine<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = Engine<FC<any>, TNode, TEdge>;
|
|
6
|
+
interface KnotxInstance<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
|
|
7
|
+
engineRef: MutableRefObject<ReactEngine<TNode, TEdge> | null>;
|
|
8
8
|
}
|
|
9
|
-
type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
10
|
-
ref?: Ref<KnotxInstance
|
|
9
|
+
type KnotxProps<TPlugins extends Plugin[] = Plugin[], TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = {
|
|
10
|
+
ref?: Ref<KnotxInstance<TNode, TEdge>> | undefined;
|
|
11
11
|
className?: string;
|
|
12
12
|
style?: CSSProperties;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* initial nodes used to create engine
|
|
15
|
+
*/
|
|
16
|
+
initialNodes?: Node<TNode>[];
|
|
17
|
+
/**
|
|
18
|
+
* initial edges used to create engine
|
|
19
|
+
*/
|
|
20
|
+
initialEdges?: Edge<TEdge>[];
|
|
21
|
+
/**
|
|
22
|
+
* auto dispatch diff operation to engine when nodes changed
|
|
23
|
+
* if not provided , use initialNodes
|
|
24
|
+
*/
|
|
25
|
+
nodes?: Node<TNode>[];
|
|
26
|
+
/**
|
|
27
|
+
* auto dispatch diff operation to engine when edges changed
|
|
28
|
+
* if not provided, use initialEdges
|
|
29
|
+
*/
|
|
30
|
+
edges?: Edge<TEdge>[];
|
|
15
31
|
plugins?: TPlugins;
|
|
16
32
|
/**
|
|
17
33
|
* disable preset plugins
|
|
@@ -20,7 +36,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
20
36
|
* @default false
|
|
21
37
|
*/
|
|
22
38
|
disablePresetPlugins?: boolean;
|
|
23
|
-
onInit?: (engine: ReactEngine) => void;
|
|
39
|
+
onInit?: (engine: ReactEngine<TNode, TEdge>) => void;
|
|
24
40
|
} & ((TPlugins[number] extends Plugin<infer T> ? {
|
|
25
41
|
[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;
|
|
26
42
|
} : {}) extends infer PluginConfig ? {} extends PluginConfig ? {
|
|
@@ -30,7 +46,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
30
46
|
} : {});
|
|
31
47
|
|
|
32
48
|
declare const Knotx: {
|
|
33
|
-
<TPlugins extends Plugin[]>(props: KnotxProps<TPlugins>, ref: ForwardedRef<KnotxInstance
|
|
49
|
+
<TPlugins extends Plugin[], TNode extends IRecord, TEdge extends IRecord>(props: KnotxProps<TPlugins, TNode, TEdge>, ref: ForwardedRef<KnotxInstance<TNode, TEdge>>): ReactElement | null;
|
|
34
50
|
displayName?: string | undefined;
|
|
35
51
|
};
|
|
36
52
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
|
-
import { Engine, Plugin,
|
|
2
|
-
export {
|
|
1
|
+
import { IRecord, Engine, Plugin, Node, Edge } from '@knotx/core';
|
|
2
|
+
export { Edge, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, Node, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, PluginTools, Position } from '@knotx/core';
|
|
3
3
|
import { FC, MutableRefObject, Ref, CSSProperties, ForwardedRef, ReactElement } from 'react';
|
|
4
4
|
|
|
5
|
-
type ReactEngine = Engine<FC<any
|
|
6
|
-
interface KnotxInstance {
|
|
7
|
-
engineRef: MutableRefObject<ReactEngine | null>;
|
|
5
|
+
type ReactEngine<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = Engine<FC<any>, TNode, TEdge>;
|
|
6
|
+
interface KnotxInstance<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> {
|
|
7
|
+
engineRef: MutableRefObject<ReactEngine<TNode, TEdge> | null>;
|
|
8
8
|
}
|
|
9
|
-
type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
10
|
-
ref?: Ref<KnotxInstance
|
|
9
|
+
type KnotxProps<TPlugins extends Plugin[] = Plugin[], TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = {
|
|
10
|
+
ref?: Ref<KnotxInstance<TNode, TEdge>> | undefined;
|
|
11
11
|
className?: string;
|
|
12
12
|
style?: CSSProperties;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* initial nodes used to create engine
|
|
15
|
+
*/
|
|
16
|
+
initialNodes?: Node<TNode>[];
|
|
17
|
+
/**
|
|
18
|
+
* initial edges used to create engine
|
|
19
|
+
*/
|
|
20
|
+
initialEdges?: Edge<TEdge>[];
|
|
21
|
+
/**
|
|
22
|
+
* auto dispatch diff operation to engine when nodes changed
|
|
23
|
+
* if not provided , use initialNodes
|
|
24
|
+
*/
|
|
25
|
+
nodes?: Node<TNode>[];
|
|
26
|
+
/**
|
|
27
|
+
* auto dispatch diff operation to engine when edges changed
|
|
28
|
+
* if not provided, use initialEdges
|
|
29
|
+
*/
|
|
30
|
+
edges?: Edge<TEdge>[];
|
|
15
31
|
plugins?: TPlugins;
|
|
16
32
|
/**
|
|
17
33
|
* disable preset plugins
|
|
@@ -20,7 +36,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
20
36
|
* @default false
|
|
21
37
|
*/
|
|
22
38
|
disablePresetPlugins?: boolean;
|
|
23
|
-
onInit?: (engine: ReactEngine) => void;
|
|
39
|
+
onInit?: (engine: ReactEngine<TNode, TEdge>) => void;
|
|
24
40
|
} & ((TPlugins[number] extends Plugin<infer T> ? {
|
|
25
41
|
[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;
|
|
26
42
|
} : {}) extends infer PluginConfig ? {} extends PluginConfig ? {
|
|
@@ -30,7 +46,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
30
46
|
} : {});
|
|
31
47
|
|
|
32
48
|
declare const Knotx: {
|
|
33
|
-
<TPlugins extends Plugin[]>(props: KnotxProps<TPlugins>, ref: ForwardedRef<KnotxInstance
|
|
49
|
+
<TPlugins extends Plugin[], TNode extends IRecord, TEdge extends IRecord>(props: KnotxProps<TPlugins, TNode, TEdge>, ref: ForwardedRef<KnotxInstance<TNode, TEdge>>): ReactElement | null;
|
|
34
50
|
displayName?: string | undefined;
|
|
35
51
|
};
|
|
36
52
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { Layer, Engine } from '@knotx/core';
|
|
3
|
-
import { useState, useLayoutEffect,
|
|
2
|
+
import { Layer, buildDiffOperation, Engine } from '@knotx/core';
|
|
3
|
+
import { useState, useRef, useLayoutEffect, useEffect, useMemo, memo, forwardRef, useImperativeHandle } from 'react';
|
|
4
4
|
import { BehaviorSubject } from 'rxjs';
|
|
5
5
|
import { map, distinctUntilChanged } from 'rxjs/operators';
|
|
6
6
|
import { BaseRender } from '@knotx/plugins-base-render';
|
|
@@ -8,12 +8,15 @@ import { BaseRender } from '@knotx/plugins-base-render';
|
|
|
8
8
|
function useContainerRef(onResize) {
|
|
9
9
|
const [container, setContainer] = useState();
|
|
10
10
|
const [_, setSize] = useState();
|
|
11
|
+
const onResizeRef = useRef(onResize);
|
|
12
|
+
onResizeRef.current = onResize;
|
|
11
13
|
useLayoutEffect(() => {
|
|
12
14
|
if (!container)
|
|
13
15
|
return;
|
|
14
16
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
17
|
+
var _a;
|
|
15
18
|
const { width, height } = entries[0].contentRect;
|
|
16
|
-
|
|
19
|
+
(_a = onResizeRef.current) == null ? void 0 : _a.call(onResizeRef, { width, height });
|
|
17
20
|
setSize({ width, height });
|
|
18
21
|
});
|
|
19
22
|
resizeObserver.observe(container);
|
|
@@ -57,6 +60,29 @@ function useLayerContent(engineRef) {
|
|
|
57
60
|
) });
|
|
58
61
|
}
|
|
59
62
|
|
|
63
|
+
function useDataUpdate(engineRef, { nodes, edges, initRef }) {
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const engine = engineRef.current;
|
|
66
|
+
if (!engine || !initRef.current) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const previousNodes = engine.nodesManager.dataMap$.value;
|
|
70
|
+
const currentNodes = new Map(nodes == null ? void 0 : nodes.map((node) => [node.id, node]));
|
|
71
|
+
const operation = buildDiffOperation(previousNodes, currentNodes);
|
|
72
|
+
engine.dispatchNodeOperation(operation);
|
|
73
|
+
}, [nodes, nodes == null ? void 0 : nodes.length]);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const engine = engineRef.current;
|
|
76
|
+
if (!engine || !initRef.current) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const previousEdges = engine.edgesManager.dataMap$.value;
|
|
80
|
+
const currentEdges = new Map(edges == null ? void 0 : edges.map((edge) => [edge.id, edge]));
|
|
81
|
+
const operation = buildDiffOperation(previousEdges, currentEdges);
|
|
82
|
+
engine.dispatchEdgeOperation(operation);
|
|
83
|
+
}, [edges, edges == null ? void 0 : edges.length]);
|
|
84
|
+
}
|
|
85
|
+
|
|
60
86
|
function useEngineRef() {
|
|
61
87
|
const engineRef = useRef(null);
|
|
62
88
|
useLayoutEffect(() => () => {
|
|
@@ -74,10 +100,14 @@ function useMergedPlugins(plugins, disablePresetPlugins) {
|
|
|
74
100
|
return [BaseRender, ...plugins || []];
|
|
75
101
|
}, [disablePresetPlugins, plugins]);
|
|
76
102
|
}
|
|
77
|
-
function usePluginConfigUpdate(engineRef,
|
|
103
|
+
function usePluginConfigUpdate(engineRef, {
|
|
104
|
+
initRef,
|
|
105
|
+
pluginConfig = {}
|
|
106
|
+
}) {
|
|
78
107
|
const pluginConfigRef = useRef(pluginConfig);
|
|
79
108
|
useLayoutEffect(() => {
|
|
80
|
-
|
|
109
|
+
const engine = engineRef.current;
|
|
110
|
+
if (!engine || !initRef.current) {
|
|
81
111
|
return;
|
|
82
112
|
}
|
|
83
113
|
for (const pluginName in pluginConfig) {
|
|
@@ -86,7 +116,7 @@ function usePluginConfigUpdate(engineRef, pluginConfig = {}) {
|
|
|
86
116
|
continue;
|
|
87
117
|
}
|
|
88
118
|
pluginConfigRef.current[pluginName] = pluginConfigValue;
|
|
89
|
-
|
|
119
|
+
engine.changePluginConfig(pluginName, pluginConfigValue);
|
|
90
120
|
}
|
|
91
121
|
});
|
|
92
122
|
}
|
|
@@ -110,6 +140,8 @@ var __spreadValues = (a, b) => {
|
|
|
110
140
|
const Knotx = memo(forwardRef(({
|
|
111
141
|
className,
|
|
112
142
|
style,
|
|
143
|
+
initialNodes,
|
|
144
|
+
initialEdges,
|
|
113
145
|
nodes,
|
|
114
146
|
edges,
|
|
115
147
|
plugins: _plugins,
|
|
@@ -124,11 +156,18 @@ const Knotx = memo(forwardRef(({
|
|
|
124
156
|
if (engineRef.current) {
|
|
125
157
|
engineRef.current.container = containerSize;
|
|
126
158
|
} else {
|
|
127
|
-
engineRef.current = initReactEngine({
|
|
159
|
+
engineRef.current = initReactEngine({
|
|
160
|
+
container: containerSize,
|
|
161
|
+
nodes: nodes != null ? nodes : initialNodes,
|
|
162
|
+
edges: edges != null ? edges : initialEdges,
|
|
163
|
+
plugins,
|
|
164
|
+
pluginConfig
|
|
165
|
+
});
|
|
128
166
|
}
|
|
129
167
|
});
|
|
130
168
|
useImperativeHandle(ref, () => ({ engineRef }));
|
|
131
|
-
|
|
169
|
+
useDataUpdate(engineRef, { nodes, edges, initRef });
|
|
170
|
+
usePluginConfigUpdate(engineRef, { pluginConfig, initRef });
|
|
132
171
|
const content = useLayerContent(engineRef);
|
|
133
172
|
if (!initRef.current && engineRef.current && content) {
|
|
134
173
|
initRef.current = true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.15",
|
|
4
4
|
"description": "React for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,19 +33,19 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"rxjs": "^7.8.1",
|
|
36
|
-
"@knotx/core": "0.2.
|
|
37
|
-
"@knotx/jsx": "0.2.
|
|
38
|
-
"@knotx/plugins-base-render": "0.2.
|
|
36
|
+
"@knotx/core": "0.2.12",
|
|
37
|
+
"@knotx/jsx": "0.2.11",
|
|
38
|
+
"@knotx/plugins-base-render": "0.2.14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/react": "^17.0.0",
|
|
42
42
|
"@types/react-dom": "^17.0.0",
|
|
43
43
|
"react": "^17.0.0",
|
|
44
44
|
"react-dom": "^17.0.0",
|
|
45
|
-
"@knotx/build-config": "0.2.
|
|
46
|
-
"@knotx/eslint-config": "0.2.
|
|
47
|
-
"@knotx/jsx": "0.2.
|
|
48
|
-
"@knotx/typescript-config": "0.2.
|
|
45
|
+
"@knotx/build-config": "0.2.11",
|
|
46
|
+
"@knotx/eslint-config": "0.2.11",
|
|
47
|
+
"@knotx/jsx": "0.2.11",
|
|
48
|
+
"@knotx/typescript-config": "0.2.11"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "unbuild",
|