@knotx/plugins-canvas 0.2.5 → 0.2.7

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
@@ -75,8 +75,16 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
75
75
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
76
76
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
77
77
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
78
- var _init_dec, _render_dec, _transform_dec, _ref_dec, _a, _init;
79
- class Canvas extends (_a = core.BasePlugin, _ref_dec = [decorators.register("ref")], _transform_dec = [decorators.register("transform")], _render_dec = [decorators.layer(core.Layer.Canvas)], _init_dec = [decorators.OnInit], _a) {
78
+ var _init_dec, _render_dec, _scrollNodeIntoView_dec, _container_dec, _getNode_dec, _transform_dec, _ref_dec, _a, _init;
79
+ class Canvas extends (_a = core.BasePlugin, _ref_dec = [decorators.register("ref")], _transform_dec = [decorators.register("transform")], _getNode_dec = [decorators.inject.getNode()], _container_dec = [decorators.inject.container()], _scrollNodeIntoView_dec = [decorators.tool("Scroll node into viewport center", {
80
+ type: "object",
81
+ properties: {
82
+ nodeId: { type: "string" },
83
+ scale: { type: "number", description: "The scale of the canvas, default is current scale" },
84
+ animationTime: { type: "number", description: "The animation time(ms) of scroll behavior" }
85
+ },
86
+ required: ["nodeId"]
87
+ })], _render_dec = [decorators.layer(core.Layer.Canvas)], _init_dec = [decorators.OnInit], _a) {
80
88
  constructor() {
81
89
  super(...arguments);
82
90
  __runInitializers(_init, 5, this);
@@ -84,12 +92,20 @@ class Canvas extends (_a = core.BasePlugin, _ref_dec = [decorators.register("ref
84
92
  __publicField(this, "name", "canvas");
85
93
  __publicField(this, "ref", __runInitializers(_init, 8, this, null)), __runInitializers(_init, 11, this);
86
94
  __publicField(this, "transform", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
95
+ __publicField(this, "getNode", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
96
+ __publicField(this, "container", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
87
97
  }
88
- get classNames() {
89
- return {
90
- wrapper: core.bem(this.name, "wrapper"),
91
- content: core.bem(this.name, "content")
92
- };
98
+ scrollNodeIntoView({ nodeId, scale = this.transform.scale, animationTime }) {
99
+ var _a2, _b, _c, _d, _e;
100
+ const node = nodeId && this.getNode(nodeId);
101
+ if (!node) {
102
+ return;
103
+ }
104
+ const nodeCenterX = node.position.x + ((_b = (_a2 = node.measured) == null ? void 0 : _a2.width) != null ? _b : 0) / 2;
105
+ const nodeCenterY = node.position.y + ((_d = (_c = node.measured) == null ? void 0 : _c.height) != null ? _d : 0) / 2;
106
+ const positionX = nodeCenterX * scale - this.container.width / 2;
107
+ const positionY = nodeCenterY * scale - this.container.height / 2;
108
+ (_e = this.ref) == null ? void 0 : _e.setTransform(-positionX, -positionY, scale, animationTime);
93
109
  }
94
110
  render({ children } = { children: null }) {
95
111
  const [transform, setTransform] = react.useState(null);
@@ -108,7 +124,6 @@ class Canvas extends (_a = core.BasePlugin, _ref_dec = [decorators.register("ref
108
124
  }
109
125
  return [fixedLayers2, childrenLayers2];
110
126
  }, [children]);
111
- const { wrapper, content } = this.classNames;
112
127
  react.useEffect(() => {
113
128
  this.ref = transform;
114
129
  const wrapperElement = transform == null ? void 0 : transform.instance.wrapperComponent;
@@ -148,14 +163,14 @@ class Canvas extends (_a = core.BasePlugin, _ref_dec = [decorators.register("ref
148
163
  /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(
149
164
  reactZoomPanPinch.TransformComponent,
150
165
  {
151
- wrapperClass: wrapper,
166
+ wrapperClass: core.bem(this.name, "wrapper"),
152
167
  wrapperStyle: {
153
168
  width: "100%",
154
169
  height: "100%",
155
170
  zIndex: core.Layer.Nodes | core.Layer.Edges,
156
171
  contain: "strict"
157
172
  },
158
- contentClass: content,
173
+ contentClass: core.bem(this.name, "content"),
159
174
  contentStyle: {
160
175
  position: "relative",
161
176
  width: "100%",
@@ -184,10 +199,13 @@ class Canvas extends (_a = core.BasePlugin, _ref_dec = [decorators.register("ref
184
199
  }
185
200
  }
186
201
  _init = __decoratorStart(_a);
202
+ __decorateElement(_init, 1, "scrollNodeIntoView", _scrollNodeIntoView_dec, Canvas);
187
203
  __decorateElement(_init, 1, "render", _render_dec, Canvas);
188
204
  __decorateElement(_init, 1, "init", _init_dec, Canvas);
189
205
  __decorateElement(_init, 5, "ref", _ref_dec, Canvas);
190
206
  __decorateElement(_init, 5, "transform", _transform_dec, Canvas);
207
+ __decorateElement(_init, 5, "getNode", _getNode_dec, Canvas);
208
+ __decorateElement(_init, 5, "container", _container_dec, Canvas);
191
209
  __decoratorMetadata(_init, Canvas);
192
210
 
193
211
  exports.Canvas = Canvas;
package/dist/index.d.cts CHANGED
@@ -1,3 +1,4 @@
1
+ import { InferParamsFromSchema } from '@knotx/decorators';
1
2
  import { ReactNode } from 'react';
2
3
  import { ReactZoomPanPinchContentRef, ReactZoomPanPinchState, ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
3
4
  import { BasePlugin } from '@knotx/core';
@@ -12,16 +13,38 @@ declare module '@knotx/core' {
12
13
  transform: CanvasTransformState;
13
14
  };
14
15
  }
16
+ interface PluginTools {
17
+ canvas: {
18
+ scrollNodeIntoView: (params: {
19
+ nodeId: string;
20
+ scale?: number;
21
+ animationTime?: number;
22
+ }) => void;
23
+ };
24
+ }
15
25
  }
16
26
  declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
17
27
  private config;
18
28
  name: "canvas";
19
29
  ref: CanvasRef | null;
20
30
  transform: CanvasTransformState;
21
- get classNames(): {
22
- wrapper: string;
23
- content: string;
24
- };
31
+ private getNode;
32
+ private container;
33
+ scrollNodeIntoView({ nodeId, scale, animationTime }: InferParamsFromSchema<{
34
+ type: 'object';
35
+ properties: {
36
+ nodeId: {
37
+ type: 'string';
38
+ };
39
+ scale: {
40
+ type: 'number';
41
+ };
42
+ animationTime: {
43
+ type: 'number';
44
+ };
45
+ };
46
+ required: ['nodeId'];
47
+ }>): void;
25
48
  render({ children }?: {
26
49
  children: ReactNode;
27
50
  }): JSX.Element;
package/dist/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import { InferParamsFromSchema } from '@knotx/decorators';
1
2
  import { ReactNode } from 'react';
2
3
  import { ReactZoomPanPinchContentRef, ReactZoomPanPinchState, ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
3
4
  import { BasePlugin } from '@knotx/core';
@@ -12,16 +13,38 @@ declare module '@knotx/core' {
12
13
  transform: CanvasTransformState;
13
14
  };
14
15
  }
16
+ interface PluginTools {
17
+ canvas: {
18
+ scrollNodeIntoView: (params: {
19
+ nodeId: string;
20
+ scale?: number;
21
+ animationTime?: number;
22
+ }) => void;
23
+ };
24
+ }
15
25
  }
16
26
  declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
17
27
  private config;
18
28
  name: "canvas";
19
29
  ref: CanvasRef | null;
20
30
  transform: CanvasTransformState;
21
- get classNames(): {
22
- wrapper: string;
23
- content: string;
24
- };
31
+ private getNode;
32
+ private container;
33
+ scrollNodeIntoView({ nodeId, scale, animationTime }: InferParamsFromSchema<{
34
+ type: 'object';
35
+ properties: {
36
+ nodeId: {
37
+ type: 'string';
38
+ };
39
+ scale: {
40
+ type: 'number';
41
+ };
42
+ animationTime: {
43
+ type: 'number';
44
+ };
45
+ };
46
+ required: ['nodeId'];
47
+ }>): void;
25
48
  render({ children }?: {
26
49
  children: ReactNode;
27
50
  }): JSX.Element;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { InferParamsFromSchema } from '@knotx/decorators';
1
2
  import { ReactNode } from 'react';
2
3
  import { ReactZoomPanPinchContentRef, ReactZoomPanPinchState, ReactZoomPanPinchProps } from 'react-zoom-pan-pinch';
3
4
  import { BasePlugin } from '@knotx/core';
@@ -12,16 +13,38 @@ declare module '@knotx/core' {
12
13
  transform: CanvasTransformState;
13
14
  };
14
15
  }
16
+ interface PluginTools {
17
+ canvas: {
18
+ scrollNodeIntoView: (params: {
19
+ nodeId: string;
20
+ scale?: number;
21
+ animationTime?: number;
22
+ }) => void;
23
+ };
24
+ }
15
25
  }
16
26
  declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
17
27
  private config;
18
28
  name: "canvas";
19
29
  ref: CanvasRef | null;
20
30
  transform: CanvasTransformState;
21
- get classNames(): {
22
- wrapper: string;
23
- content: string;
24
- };
31
+ private getNode;
32
+ private container;
33
+ scrollNodeIntoView({ nodeId, scale, animationTime }: InferParamsFromSchema<{
34
+ type: 'object';
35
+ properties: {
36
+ nodeId: {
37
+ type: 'string';
38
+ };
39
+ scale: {
40
+ type: 'number';
41
+ };
42
+ animationTime: {
43
+ type: 'number';
44
+ };
45
+ };
46
+ required: ['nodeId'];
47
+ }>): void;
25
48
  render({ children }?: {
26
49
  children: ReactNode;
27
50
  }): JSX.Element;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsxs, jsx } from '@knotx/jsx/jsx-runtime';
2
2
  import { Layer, bem, BasePlugin } from '@knotx/core';
3
- import { register, layer, OnInit } from '@knotx/decorators';
3
+ import { register, inject, tool, layer, OnInit } from '@knotx/decorators';
4
4
  import { merge } from 'lodash-es';
5
5
  import { useState, useMemo, useEffect, Fragment } from 'react';
6
6
  import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch';
@@ -73,8 +73,16 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
73
73
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
74
74
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
75
75
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
76
- var _init_dec, _render_dec, _transform_dec, _ref_dec, _a, _init;
77
- class Canvas extends (_a = BasePlugin, _ref_dec = [register("ref")], _transform_dec = [register("transform")], _render_dec = [layer(Layer.Canvas)], _init_dec = [OnInit], _a) {
76
+ var _init_dec, _render_dec, _scrollNodeIntoView_dec, _container_dec, _getNode_dec, _transform_dec, _ref_dec, _a, _init;
77
+ class Canvas extends (_a = BasePlugin, _ref_dec = [register("ref")], _transform_dec = [register("transform")], _getNode_dec = [inject.getNode()], _container_dec = [inject.container()], _scrollNodeIntoView_dec = [tool("Scroll node into viewport center", {
78
+ type: "object",
79
+ properties: {
80
+ nodeId: { type: "string" },
81
+ scale: { type: "number", description: "The scale of the canvas, default is current scale" },
82
+ animationTime: { type: "number", description: "The animation time(ms) of scroll behavior" }
83
+ },
84
+ required: ["nodeId"]
85
+ })], _render_dec = [layer(Layer.Canvas)], _init_dec = [OnInit], _a) {
78
86
  constructor() {
79
87
  super(...arguments);
80
88
  __runInitializers(_init, 5, this);
@@ -82,12 +90,20 @@ class Canvas extends (_a = BasePlugin, _ref_dec = [register("ref")], _transform_
82
90
  __publicField(this, "name", "canvas");
83
91
  __publicField(this, "ref", __runInitializers(_init, 8, this, null)), __runInitializers(_init, 11, this);
84
92
  __publicField(this, "transform", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
93
+ __publicField(this, "getNode", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
94
+ __publicField(this, "container", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
85
95
  }
86
- get classNames() {
87
- return {
88
- wrapper: bem(this.name, "wrapper"),
89
- content: bem(this.name, "content")
90
- };
96
+ scrollNodeIntoView({ nodeId, scale = this.transform.scale, animationTime }) {
97
+ var _a2, _b, _c, _d, _e;
98
+ const node = nodeId && this.getNode(nodeId);
99
+ if (!node) {
100
+ return;
101
+ }
102
+ const nodeCenterX = node.position.x + ((_b = (_a2 = node.measured) == null ? void 0 : _a2.width) != null ? _b : 0) / 2;
103
+ const nodeCenterY = node.position.y + ((_d = (_c = node.measured) == null ? void 0 : _c.height) != null ? _d : 0) / 2;
104
+ const positionX = nodeCenterX * scale - this.container.width / 2;
105
+ const positionY = nodeCenterY * scale - this.container.height / 2;
106
+ (_e = this.ref) == null ? void 0 : _e.setTransform(-positionX, -positionY, scale, animationTime);
91
107
  }
92
108
  render({ children } = { children: null }) {
93
109
  const [transform, setTransform] = useState(null);
@@ -106,7 +122,6 @@ class Canvas extends (_a = BasePlugin, _ref_dec = [register("ref")], _transform_
106
122
  }
107
123
  return [fixedLayers2, childrenLayers2];
108
124
  }, [children]);
109
- const { wrapper, content } = this.classNames;
110
125
  useEffect(() => {
111
126
  this.ref = transform;
112
127
  const wrapperElement = transform == null ? void 0 : transform.instance.wrapperComponent;
@@ -146,14 +161,14 @@ class Canvas extends (_a = BasePlugin, _ref_dec = [register("ref")], _transform_
146
161
  /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
147
162
  TransformComponent,
148
163
  {
149
- wrapperClass: wrapper,
164
+ wrapperClass: bem(this.name, "wrapper"),
150
165
  wrapperStyle: {
151
166
  width: "100%",
152
167
  height: "100%",
153
168
  zIndex: Layer.Nodes | Layer.Edges,
154
169
  contain: "strict"
155
170
  },
156
- contentClass: content,
171
+ contentClass: bem(this.name, "content"),
157
172
  contentStyle: {
158
173
  position: "relative",
159
174
  width: "100%",
@@ -182,10 +197,13 @@ class Canvas extends (_a = BasePlugin, _ref_dec = [register("ref")], _transform_
182
197
  }
183
198
  }
184
199
  _init = __decoratorStart(_a);
200
+ __decorateElement(_init, 1, "scrollNodeIntoView", _scrollNodeIntoView_dec, Canvas);
185
201
  __decorateElement(_init, 1, "render", _render_dec, Canvas);
186
202
  __decorateElement(_init, 1, "init", _init_dec, Canvas);
187
203
  __decorateElement(_init, 5, "ref", _ref_dec, Canvas);
188
204
  __decorateElement(_init, 5, "transform", _transform_dec, Canvas);
205
+ __decorateElement(_init, 5, "getNode", _getNode_dec, Canvas);
206
+ __decorateElement(_init, 5, "container", _container_dec, Canvas);
189
207
  __decoratorMetadata(_init, Canvas);
190
208
 
191
209
  export { Canvas };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/plugins-canvas",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Canvas Plugin for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -30,14 +30,14 @@
30
30
  "peerDependencies": {
31
31
  "react": ">=17.0.0",
32
32
  "react-dom": ">=17.0.0",
33
- "@knotx/jsx": "0.2.5"
33
+ "@knotx/jsx": "0.2.7"
34
34
  },
35
35
  "dependencies": {
36
36
  "lodash-es": "^4.17.21",
37
37
  "react-zoom-pan-pinch": "^3.7.0",
38
38
  "rxjs": "^7.8.1",
39
- "@knotx/core": "0.2.5",
40
- "@knotx/decorators": "0.2.5"
39
+ "@knotx/core": "0.2.7",
40
+ "@knotx/decorators": "0.2.7"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/lodash-es": "^4.17.12",
@@ -45,10 +45,10 @@
45
45
  "@types/react-dom": "^17.0.0",
46
46
  "react": "^17.0.0",
47
47
  "react-dom": "^17.0.0",
48
- "@knotx/build-config": "0.2.5",
49
- "@knotx/eslint-config": "0.2.5",
50
- "@knotx/jsx": "0.2.5",
51
- "@knotx/typescript-config": "0.2.5"
48
+ "@knotx/build-config": "0.2.7",
49
+ "@knotx/eslint-config": "0.2.7",
50
+ "@knotx/jsx": "0.2.7",
51
+ "@knotx/typescript-config": "0.2.7"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "unbuild",