@knotx/react 0.2.11 → 0.2.13
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 +10 -3
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +11 -4
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -61,9 +61,10 @@ function useLayerContent(engineRef) {
|
|
|
61
61
|
|
|
62
62
|
function useEngineRef() {
|
|
63
63
|
const engineRef = react.useRef(null);
|
|
64
|
-
react.
|
|
64
|
+
react.useLayoutEffect(() => () => {
|
|
65
65
|
var _a;
|
|
66
|
-
|
|
66
|
+
(_a = engineRef.current) == null ? void 0 : _a.destroy();
|
|
67
|
+
engineRef.current = null;
|
|
67
68
|
}, []);
|
|
68
69
|
return engineRef;
|
|
69
70
|
}
|
|
@@ -115,8 +116,10 @@ const Knotx = react.memo(react.forwardRef(({
|
|
|
115
116
|
edges,
|
|
116
117
|
plugins: _plugins,
|
|
117
118
|
pluginConfig,
|
|
118
|
-
disablePresetPlugins = false
|
|
119
|
+
disablePresetPlugins = false,
|
|
120
|
+
onInit
|
|
119
121
|
}, ref) => {
|
|
122
|
+
const initRef = react.useRef(false);
|
|
120
123
|
const engineRef = useEngineRef();
|
|
121
124
|
const plugins = useMergedPlugins(_plugins, disablePresetPlugins);
|
|
122
125
|
const setContainer = useContainerRef((containerSize) => {
|
|
@@ -129,6 +132,10 @@ const Knotx = react.memo(react.forwardRef(({
|
|
|
129
132
|
react.useImperativeHandle(ref, () => ({ engineRef }));
|
|
130
133
|
usePluginConfigUpdate(engineRef, pluginConfig);
|
|
131
134
|
const content = useLayerContent(engineRef);
|
|
135
|
+
if (!initRef.current && engineRef.current && content) {
|
|
136
|
+
initRef.current = true;
|
|
137
|
+
onInit == null ? void 0 : onInit(engineRef.current);
|
|
138
|
+
}
|
|
132
139
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
133
140
|
"div",
|
|
134
141
|
{
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Engine, Plugin, NodeData, EdgeData } from '@knotx/core';
|
|
2
|
-
export { EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, Position } from '@knotx/core';
|
|
2
|
+
export { EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, 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
5
|
type ReactEngine = Engine<FC<any>>;
|
|
@@ -20,6 +20,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
20
20
|
* @default false
|
|
21
21
|
*/
|
|
22
22
|
disablePresetPlugins?: boolean;
|
|
23
|
+
onInit?: (engine: ReactEngine) => void;
|
|
23
24
|
} & ((TPlugins[number] extends Plugin<infer T> ? {
|
|
24
25
|
[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;
|
|
25
26
|
} : {}) extends infer PluginConfig ? {} extends PluginConfig ? {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Engine, Plugin, NodeData, EdgeData } from '@knotx/core';
|
|
2
|
-
export { EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, Position } from '@knotx/core';
|
|
2
|
+
export { EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, 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
5
|
type ReactEngine = Engine<FC<any>>;
|
|
@@ -20,6 +20,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
20
20
|
* @default false
|
|
21
21
|
*/
|
|
22
22
|
disablePresetPlugins?: boolean;
|
|
23
|
+
onInit?: (engine: ReactEngine) => void;
|
|
23
24
|
} & ((TPlugins[number] extends Plugin<infer T> ? {
|
|
24
25
|
[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;
|
|
25
26
|
} : {}) extends infer PluginConfig ? {} extends PluginConfig ? {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Engine, Plugin, NodeData, EdgeData } from '@knotx/core';
|
|
2
|
-
export { EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, NodeMeasured, NodeOperation, NodeOperationPipe, NodeOperatorFunction, NodePosition, NodeProps, NodeRenderType, Plugin, PluginConfigs, PluginData, Position } from '@knotx/core';
|
|
2
|
+
export { EdgeData, EdgeOperation, EdgeOperationPipe, EdgeOperatorFunction, EdgeProps, EdgeRenderType, EngineOptions, IData, IEngineRuntime, IPlugin, Layer, LayerComponent, NodeData, 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
5
|
type ReactEngine = Engine<FC<any>>;
|
|
@@ -20,6 +20,7 @@ type KnotxProps<TPlugins extends Plugin[] = Plugin[]> = {
|
|
|
20
20
|
* @default false
|
|
21
21
|
*/
|
|
22
22
|
disablePresetPlugins?: boolean;
|
|
23
|
+
onInit?: (engine: ReactEngine) => void;
|
|
23
24
|
} & ((TPlugins[number] extends Plugin<infer T> ? {
|
|
24
25
|
[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;
|
|
25
26
|
} : {}) extends infer PluginConfig ? {} extends PluginConfig ? {
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { Layer, Engine } from '@knotx/core';
|
|
3
|
-
import { useState, useLayoutEffect, useRef,
|
|
3
|
+
import { useState, useLayoutEffect, useRef, useMemo, memo, forwardRef, useImperativeHandle, useEffect } 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';
|
|
@@ -59,9 +59,10 @@ function useLayerContent(engineRef) {
|
|
|
59
59
|
|
|
60
60
|
function useEngineRef() {
|
|
61
61
|
const engineRef = useRef(null);
|
|
62
|
-
|
|
62
|
+
useLayoutEffect(() => () => {
|
|
63
63
|
var _a;
|
|
64
|
-
|
|
64
|
+
(_a = engineRef.current) == null ? void 0 : _a.destroy();
|
|
65
|
+
engineRef.current = null;
|
|
65
66
|
}, []);
|
|
66
67
|
return engineRef;
|
|
67
68
|
}
|
|
@@ -113,8 +114,10 @@ const Knotx = memo(forwardRef(({
|
|
|
113
114
|
edges,
|
|
114
115
|
plugins: _plugins,
|
|
115
116
|
pluginConfig,
|
|
116
|
-
disablePresetPlugins = false
|
|
117
|
+
disablePresetPlugins = false,
|
|
118
|
+
onInit
|
|
117
119
|
}, ref) => {
|
|
120
|
+
const initRef = useRef(false);
|
|
118
121
|
const engineRef = useEngineRef();
|
|
119
122
|
const plugins = useMergedPlugins(_plugins, disablePresetPlugins);
|
|
120
123
|
const setContainer = useContainerRef((containerSize) => {
|
|
@@ -127,6 +130,10 @@ const Knotx = memo(forwardRef(({
|
|
|
127
130
|
useImperativeHandle(ref, () => ({ engineRef }));
|
|
128
131
|
usePluginConfigUpdate(engineRef, pluginConfig);
|
|
129
132
|
const content = useLayerContent(engineRef);
|
|
133
|
+
if (!initRef.current && engineRef.current && content) {
|
|
134
|
+
initRef.current = true;
|
|
135
|
+
onInit == null ? void 0 : onInit(engineRef.current);
|
|
136
|
+
}
|
|
130
137
|
return /* @__PURE__ */ jsx(
|
|
131
138
|
"div",
|
|
132
139
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
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.10",
|
|
37
|
+
"@knotx/jsx": "0.2.10",
|
|
38
|
+
"@knotx/plugins-base-render": "0.2.12"
|
|
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.10",
|
|
46
|
+
"@knotx/eslint-config": "0.2.10",
|
|
47
|
+
"@knotx/jsx": "0.2.10",
|
|
48
|
+
"@knotx/typescript-config": "0.2.10"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "unbuild",
|