@knotx/react 0.4.4 → 0.4.6
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 +42 -36
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +43 -37
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,53 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
const core = require('@knotx/core');
|
|
5
4
|
const react = require('react');
|
|
5
|
+
const core = require('@knotx/core');
|
|
6
6
|
const rxjs = require('rxjs');
|
|
7
7
|
const operators = require('rxjs/operators');
|
|
8
8
|
const pluginsBaseRender = require('@knotx/plugins-base-render');
|
|
9
9
|
|
|
10
|
+
function initReactEngine({
|
|
11
|
+
container,
|
|
12
|
+
nodes = [],
|
|
13
|
+
edges = [],
|
|
14
|
+
plugins = [],
|
|
15
|
+
pluginConfig = {}
|
|
16
|
+
}) {
|
|
17
|
+
return new core.Engine({
|
|
18
|
+
container,
|
|
19
|
+
nodes,
|
|
20
|
+
edges,
|
|
21
|
+
plugins,
|
|
22
|
+
pluginConfig,
|
|
23
|
+
runtime: {
|
|
24
|
+
render: {
|
|
25
|
+
getValue: (subject, { selector, context }) => {
|
|
26
|
+
const contextRef = react.useRef(context);
|
|
27
|
+
contextRef.current = context;
|
|
28
|
+
const [state, setState] = react.useState(
|
|
29
|
+
() => selector ? selector(
|
|
30
|
+
subject instanceof rxjs.BehaviorSubject ? subject.value : subject,
|
|
31
|
+
contextRef.current
|
|
32
|
+
) : subject instanceof rxjs.BehaviorSubject ? subject.value : subject
|
|
33
|
+
);
|
|
34
|
+
react.useEffect(() => {
|
|
35
|
+
if (!(subject instanceof rxjs.BehaviorSubject)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const subscription = subject.pipe(
|
|
39
|
+
operators.map((value) => selector ? selector(value, contextRef.current) : value),
|
|
40
|
+
operators.distinctUntilChanged()
|
|
41
|
+
).subscribe((value) => setState(() => value));
|
|
42
|
+
return () => subscription.unsubscribe();
|
|
43
|
+
}, [subject, selector]);
|
|
44
|
+
return state;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
10
51
|
function useContainerRef(onResize) {
|
|
11
52
|
const [container, setContainer] = react.useState();
|
|
12
53
|
const [_, setSize] = react.useState();
|
|
@@ -189,40 +230,5 @@ const Knotx = react.memo(react.forwardRef(({
|
|
|
189
230
|
);
|
|
190
231
|
}));
|
|
191
232
|
Knotx.displayName = "Knotx";
|
|
192
|
-
function initReactEngine({
|
|
193
|
-
container,
|
|
194
|
-
nodes = [],
|
|
195
|
-
edges = [],
|
|
196
|
-
plugins = [],
|
|
197
|
-
pluginConfig = {}
|
|
198
|
-
}) {
|
|
199
|
-
return new core.Engine({
|
|
200
|
-
container,
|
|
201
|
-
nodes,
|
|
202
|
-
edges,
|
|
203
|
-
plugins,
|
|
204
|
-
pluginConfig,
|
|
205
|
-
runtime: {
|
|
206
|
-
render: {
|
|
207
|
-
getValue: (subject, { selector, context }) => {
|
|
208
|
-
const contextRef = react.useRef(context);
|
|
209
|
-
contextRef.current = context;
|
|
210
|
-
const [state, setState] = react.useState(() => selector ? selector(subject instanceof rxjs.BehaviorSubject ? subject.value : subject, contextRef.current) : subject instanceof rxjs.BehaviorSubject ? subject.value : subject);
|
|
211
|
-
react.useEffect(() => {
|
|
212
|
-
if (!(subject instanceof rxjs.BehaviorSubject)) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const subscription = subject.pipe(
|
|
216
|
-
operators.map((value) => selector ? selector(value, contextRef.current) : value),
|
|
217
|
-
operators.distinctUntilChanged()
|
|
218
|
-
).subscribe((value) => setState(() => value));
|
|
219
|
-
return () => subscription.unsubscribe();
|
|
220
|
-
}, [subject, selector]);
|
|
221
|
-
return state;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
233
|
|
|
228
234
|
exports.Knotx = Knotx;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
export { Direction, 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
5
|
type ReactEngine<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = Engine<FC<any>, TNode, TEdge>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
export { Direction, 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
5
|
type ReactEngine<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = Engine<FC<any>, TNode, TEdge>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
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';
|
|
2
|
+
export { Direction, 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
5
|
type ReactEngine<TNode extends IRecord = IRecord, TEdge extends IRecord = IRecord> = Engine<FC<any>, TNode, TEdge>;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,51 @@
|
|
|
1
1
|
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useRef, useState, useEffect, useLayoutEffect, useMemo, memo, forwardRef, useImperativeHandle } from 'react';
|
|
3
|
+
import { Engine, Layer, buildDiffOperation } from '@knotx/core';
|
|
4
4
|
import { BehaviorSubject } from 'rxjs';
|
|
5
5
|
import { map, distinctUntilChanged } from 'rxjs/operators';
|
|
6
6
|
import { BaseRender } from '@knotx/plugins-base-render';
|
|
7
7
|
|
|
8
|
+
function initReactEngine({
|
|
9
|
+
container,
|
|
10
|
+
nodes = [],
|
|
11
|
+
edges = [],
|
|
12
|
+
plugins = [],
|
|
13
|
+
pluginConfig = {}
|
|
14
|
+
}) {
|
|
15
|
+
return new Engine({
|
|
16
|
+
container,
|
|
17
|
+
nodes,
|
|
18
|
+
edges,
|
|
19
|
+
plugins,
|
|
20
|
+
pluginConfig,
|
|
21
|
+
runtime: {
|
|
22
|
+
render: {
|
|
23
|
+
getValue: (subject, { selector, context }) => {
|
|
24
|
+
const contextRef = useRef(context);
|
|
25
|
+
contextRef.current = context;
|
|
26
|
+
const [state, setState] = useState(
|
|
27
|
+
() => selector ? selector(
|
|
28
|
+
subject instanceof BehaviorSubject ? subject.value : subject,
|
|
29
|
+
contextRef.current
|
|
30
|
+
) : subject instanceof BehaviorSubject ? subject.value : subject
|
|
31
|
+
);
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!(subject instanceof BehaviorSubject)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const subscription = subject.pipe(
|
|
37
|
+
map((value) => selector ? selector(value, contextRef.current) : value),
|
|
38
|
+
distinctUntilChanged()
|
|
39
|
+
).subscribe((value) => setState(() => value));
|
|
40
|
+
return () => subscription.unsubscribe();
|
|
41
|
+
}, [subject, selector]);
|
|
42
|
+
return state;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
8
49
|
function useContainerRef(onResize) {
|
|
9
50
|
const [container, setContainer] = useState();
|
|
10
51
|
const [_, setSize] = useState();
|
|
@@ -187,40 +228,5 @@ const Knotx = memo(forwardRef(({
|
|
|
187
228
|
);
|
|
188
229
|
}));
|
|
189
230
|
Knotx.displayName = "Knotx";
|
|
190
|
-
function initReactEngine({
|
|
191
|
-
container,
|
|
192
|
-
nodes = [],
|
|
193
|
-
edges = [],
|
|
194
|
-
plugins = [],
|
|
195
|
-
pluginConfig = {}
|
|
196
|
-
}) {
|
|
197
|
-
return new Engine({
|
|
198
|
-
container,
|
|
199
|
-
nodes,
|
|
200
|
-
edges,
|
|
201
|
-
plugins,
|
|
202
|
-
pluginConfig,
|
|
203
|
-
runtime: {
|
|
204
|
-
render: {
|
|
205
|
-
getValue: (subject, { selector, context }) => {
|
|
206
|
-
const contextRef = useRef(context);
|
|
207
|
-
contextRef.current = context;
|
|
208
|
-
const [state, setState] = useState(() => selector ? selector(subject instanceof BehaviorSubject ? subject.value : subject, contextRef.current) : subject instanceof BehaviorSubject ? subject.value : subject);
|
|
209
|
-
useEffect(() => {
|
|
210
|
-
if (!(subject instanceof BehaviorSubject)) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const subscription = subject.pipe(
|
|
214
|
-
map((value) => selector ? selector(value, contextRef.current) : value),
|
|
215
|
-
distinctUntilChanged()
|
|
216
|
-
).subscribe((value) => setState(() => value));
|
|
217
|
-
return () => subscription.unsubscribe();
|
|
218
|
-
}, [subject, selector]);
|
|
219
|
-
return state;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
231
|
|
|
226
232
|
export { Knotx };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/react",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.6",
|
|
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.4.
|
|
37
|
-
"@knotx/jsx": "0.4.
|
|
38
|
-
"@knotx/plugins-base-render": "0.4.
|
|
36
|
+
"@knotx/core": "0.4.6",
|
|
37
|
+
"@knotx/jsx": "0.4.6",
|
|
38
|
+
"@knotx/plugins-base-render": "0.4.6"
|
|
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.4.
|
|
46
|
-
"@knotx/eslint-config": "0.4.
|
|
47
|
-
"@knotx/jsx": "0.4.
|
|
48
|
-
"@knotx/typescript-config": "0.4.
|
|
45
|
+
"@knotx/build-config": "0.4.6",
|
|
46
|
+
"@knotx/eslint-config": "0.4.6",
|
|
47
|
+
"@knotx/jsx": "0.4.6",
|
|
48
|
+
"@knotx/typescript-config": "0.4.6"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "unbuild",
|