@knotx/react 0.2.10 → 0.2.12

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 CHANGED
@@ -43,29 +43,28 @@ function createLayer({ engine, layer }) {
43
43
  }
44
44
 
45
45
  function useLayerContent(engineRef) {
46
- const content = react.useMemo(() => {
47
- const engine = engineRef.current;
48
- if (!engine)
49
- return null;
50
- const layers = Array.from(engine.layers.keys()).sort((a, b) => a - b).filter((layer) => layer > core.Layer.Canvas);
51
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: engine.getLayerComponents(core.Layer.Canvas).reduce(
52
- (children, { name, render: CanvasComponent }) => /* @__PURE__ */ jsxRuntime.jsx(CanvasComponent, { children }, name),
53
- layers.map(
54
- (layer) => createLayer({
55
- engine,
56
- layer
57
- })
58
- )
59
- ) });
60
- }, [engineRef.current]);
61
- return content;
46
+ const engine = engineRef.current;
47
+ if (!engine) {
48
+ return null;
49
+ }
50
+ const layers = Array.from(engine.layers.keys()).sort((a, b) => a - b).filter((layer) => layer > core.Layer.Canvas);
51
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: engine.getLayerComponents(core.Layer.Canvas).reduce(
52
+ (children, { name, render: CanvasComponent }) => /* @__PURE__ */ jsxRuntime.jsx(CanvasComponent, { children }, name),
53
+ layers.map(
54
+ (layer) => createLayer({
55
+ engine,
56
+ layer
57
+ })
58
+ )
59
+ ) });
62
60
  }
63
61
 
64
62
  function useEngineRef() {
65
63
  const engineRef = react.useRef(null);
66
- react.useEffect(() => () => {
64
+ react.useLayoutEffect(() => () => {
67
65
  var _a;
68
- return (_a = engineRef.current) == null ? void 0 : _a.destroy();
66
+ (_a = engineRef.current) == null ? void 0 : _a.destroy();
67
+ engineRef.current = null;
69
68
  }, []);
70
69
  return engineRef;
71
70
  }
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>>;
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>>;
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>>;
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, useMemo, useRef, useEffect, memo, forwardRef, useImperativeHandle } from 'react';
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';
@@ -41,29 +41,28 @@ function createLayer({ engine, layer }) {
41
41
  }
42
42
 
43
43
  function useLayerContent(engineRef) {
44
- const content = useMemo(() => {
45
- const engine = engineRef.current;
46
- if (!engine)
47
- return null;
48
- const layers = Array.from(engine.layers.keys()).sort((a, b) => a - b).filter((layer) => layer > Layer.Canvas);
49
- return /* @__PURE__ */ jsx(Fragment, { children: engine.getLayerComponents(Layer.Canvas).reduce(
50
- (children, { name, render: CanvasComponent }) => /* @__PURE__ */ jsx(CanvasComponent, { children }, name),
51
- layers.map(
52
- (layer) => createLayer({
53
- engine,
54
- layer
55
- })
56
- )
57
- ) });
58
- }, [engineRef.current]);
59
- return content;
44
+ const engine = engineRef.current;
45
+ if (!engine) {
46
+ return null;
47
+ }
48
+ const layers = Array.from(engine.layers.keys()).sort((a, b) => a - b).filter((layer) => layer > Layer.Canvas);
49
+ return /* @__PURE__ */ jsx(Fragment, { children: engine.getLayerComponents(Layer.Canvas).reduce(
50
+ (children, { name, render: CanvasComponent }) => /* @__PURE__ */ jsx(CanvasComponent, { children }, name),
51
+ layers.map(
52
+ (layer) => createLayer({
53
+ engine,
54
+ layer
55
+ })
56
+ )
57
+ ) });
60
58
  }
61
59
 
62
60
  function useEngineRef() {
63
61
  const engineRef = useRef(null);
64
- useEffect(() => () => {
62
+ useLayoutEffect(() => () => {
65
63
  var _a;
66
- return (_a = engineRef.current) == null ? void 0 : _a.destroy();
64
+ (_a = engineRef.current) == null ? void 0 : _a.destroy();
65
+ engineRef.current = null;
67
66
  }, []);
68
67
  return engineRef;
69
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/react",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "React for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "rxjs": "^7.8.1",
36
36
  "@knotx/core": "0.2.9",
37
37
  "@knotx/jsx": "0.2.9",
38
- "@knotx/plugins-base-render": "0.2.10"
38
+ "@knotx/plugins-base-render": "0.2.11"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/react": "^17.0.0",