@knotx/plugins-minimap 0.4.1 → 0.4.2

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
@@ -79,7 +79,7 @@ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use
79
79
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
80
80
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
81
81
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
82
- var _render_dec, _destroy_dec, _init_dec, _nodes_dec, _canvasRef_dec, _transform_dec, _container_dec, _a, _init;
82
+ var _render_dec, _destroy_dec, _init_dec, _nodes_dec, _transform_dec, _container_dec, _a, _init;
83
83
  const defaultProps = {
84
84
  width: 200,
85
85
  height: 150,
@@ -129,7 +129,7 @@ function getBoundsOfRects(bounds1, bounds2) {
129
129
  height: maxY - minY
130
130
  };
131
131
  }
132
- class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject.container()], _transform_dec = [decorators.inject.canvas.transform()], _canvasRef_dec = [decorators.inject.canvas.ref()], _nodes_dec = [decorators.inject.nodes()], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _render_dec = [decorators.panel("right-bottom")], _a) {
132
+ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject.container()], _transform_dec = [decorators.inject.canvas.transform()], _nodes_dec = [decorators.inject.nodes()], _init_dec = [decorators.OnInit], _destroy_dec = [decorators.OnDestroy], _render_dec = [decorators.panel("right-bottom")], _a) {
133
133
  constructor() {
134
134
  super(...arguments);
135
135
  __runInitializers(_init, 5, this);
@@ -142,13 +142,12 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
142
142
  __publicField(this, "dragEnd$", new rxjs.Subject());
143
143
  __publicField(this, "container", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
144
144
  __publicField(this, "transform", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
145
- __publicField(this, "canvasRef", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
146
- __publicField(this, "nodes", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
145
+ __publicField(this, "nodes", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
147
146
  /**
148
147
  * 处理小地图上的点击事件,移动视图
149
148
  */
150
149
  __publicField(this, "handleMinimapClick", (event) => {
151
- if (!this.config.pannable || !this.canvasRef)
150
+ if (!this.config.pannable)
152
151
  return;
153
152
  const svg = event.currentTarget;
154
153
  const svgRect = svg.getBoundingClientRect();
@@ -161,28 +160,34 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
161
160
  const { scale } = this.transform;
162
161
  const newPositionX = -pointX * scale + this.container.width / 2;
163
162
  const newPositionY = -pointY * scale + this.container.height / 2;
164
- this.canvasRef.setTransform(newPositionX, newPositionY, scale, 300);
163
+ this.callTool("canvas", "setTransform", {
164
+ positionX: newPositionX,
165
+ positionY: newPositionY,
166
+ scale
167
+ });
165
168
  });
166
169
  /**
167
170
  * 处理缩放按钮点击事件
168
171
  */
169
172
  __publicField(this, "handleZoom", (isZoomIn) => {
170
- if (!this.config.zoomable || !this.canvasRef)
173
+ if (!this.config.zoomable)
171
174
  return;
172
175
  const step = this.config.zoomStep;
173
176
  if (isZoomIn) {
174
- this.canvasRef.zoomIn(step, 300);
177
+ this.callTool("canvas", "zoomIn", {
178
+ step
179
+ });
175
180
  } else {
176
- this.canvasRef.zoomOut(step, 300);
181
+ this.callTool("canvas", "zoomOut", {
182
+ step
183
+ });
177
184
  }
178
185
  });
179
186
  /**
180
187
  * 重置视图
181
188
  */
182
189
  __publicField(this, "handleReset", () => {
183
- if (!this.canvasRef)
184
- return;
185
- this.canvasRef.resetTransform(300);
190
+ this.callTool("canvas", "resetTransform", {});
186
191
  });
187
192
  }
188
193
  get classNames() {
@@ -290,9 +295,12 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
290
295
  }),
291
296
  // 实时更新位置
292
297
  operators.tap(({ newPositionX: newPositionX2, newPositionY: newPositionY2 }) => {
293
- if (!this.canvasRef)
294
- return;
295
- this.canvasRef.setTransform(newPositionX2, newPositionY2, this.transform.scale, 0);
298
+ this.callTool("canvas", "setTransform", {
299
+ positionX: newPositionX2,
300
+ positionY: newPositionY2,
301
+ scale: this.transform.scale,
302
+ animationTime: 0
303
+ });
296
304
  }),
297
305
  // 直到拖拽结束
298
306
  operators.takeUntil(this.dragEnd$)
@@ -306,12 +314,10 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
306
314
  setupInteractable() {
307
315
  if (this.currentInteractable)
308
316
  return;
309
- this.currentInteractable = interact__default(`.${this.classNames.viewBox}[data-plugin-id="${this.pluginId}"]`).draggable({
317
+ this.currentInteractable = interact__default(`.${this.classNames.viewBox}[data-${this.pluginId}]`).draggable({
310
318
  listeners: {
311
319
  // 开始拖拽时,记录初始状态
312
320
  start: (event) => {
313
- if (!this.canvasRef)
314
- return;
315
321
  this.dragStart$.next({
316
322
  x: event.clientX,
317
323
  y: event.clientY,
@@ -424,9 +430,8 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
424
430
  ),
425
431
  /* @__PURE__ */ jsxRuntime.jsx(
426
432
  "rect",
427
- {
433
+ __spreadValues({
428
434
  className: viewBox,
429
- "data-plugin-id": this.pluginId,
430
435
  x: viewRect.x,
431
436
  y: viewRect.y,
432
437
  width: viewRect.width,
@@ -438,7 +443,7 @@ class Minimap extends (_a = core.BasePlugin, _container_dec = [decorators.inject
438
443
  cursor: "move",
439
444
  pointerEvents: "all"
440
445
  }
441
- }
446
+ }, { [`data-${this.pluginId}`]: "" })
442
447
  )
443
448
  ]
444
449
  }
@@ -519,7 +524,6 @@ __decorateElement(_init, 1, "destroy", _destroy_dec, Minimap);
519
524
  __decorateElement(_init, 1, "render", _render_dec, Minimap);
520
525
  __decorateElement(_init, 5, "container", _container_dec, Minimap);
521
526
  __decorateElement(_init, 5, "transform", _transform_dec, Minimap);
522
- __decorateElement(_init, 5, "canvasRef", _canvasRef_dec, Minimap);
523
527
  __decorateElement(_init, 5, "nodes", _nodes_dec, Minimap);
524
528
  __decoratorMetadata(_init, Minimap);
525
529
 
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Node, BasePlugin, Container } from '@knotx/core';
2
- import { CanvasTransformState, CanvasRef } from '@knotx/plugins-canvas';
2
+ import { CanvasTransformState } from '@knotx/plugins-canvas';
3
3
 
4
4
  interface MinimapConfig {
5
5
  /**
@@ -81,7 +81,6 @@ declare class Minimap extends BasePlugin<'minimap', MinimapConfig> {
81
81
  private dragEnd$;
82
82
  container: Container;
83
83
  transform: CanvasTransformState;
84
- canvasRef: CanvasRef | null;
85
84
  nodes: Node[];
86
85
  get classNames(): {
87
86
  wrapper: string;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Node, BasePlugin, Container } from '@knotx/core';
2
- import { CanvasTransformState, CanvasRef } from '@knotx/plugins-canvas';
2
+ import { CanvasTransformState } from '@knotx/plugins-canvas';
3
3
 
4
4
  interface MinimapConfig {
5
5
  /**
@@ -81,7 +81,6 @@ declare class Minimap extends BasePlugin<'minimap', MinimapConfig> {
81
81
  private dragEnd$;
82
82
  container: Container;
83
83
  transform: CanvasTransformState;
84
- canvasRef: CanvasRef | null;
85
84
  nodes: Node[];
86
85
  get classNames(): {
87
86
  wrapper: string;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Node, BasePlugin, Container } from '@knotx/core';
2
- import { CanvasTransformState, CanvasRef } from '@knotx/plugins-canvas';
2
+ import { CanvasTransformState } from '@knotx/plugins-canvas';
3
3
 
4
4
  interface MinimapConfig {
5
5
  /**
@@ -81,7 +81,6 @@ declare class Minimap extends BasePlugin<'minimap', MinimapConfig> {
81
81
  private dragEnd$;
82
82
  container: Container;
83
83
  transform: CanvasTransformState;
84
- canvasRef: CanvasRef | null;
85
84
  nodes: Node[];
86
85
  get classNames(): {
87
86
  wrapper: string;
package/dist/index.js CHANGED
@@ -73,7 +73,7 @@ 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 _render_dec, _destroy_dec, _init_dec, _nodes_dec, _canvasRef_dec, _transform_dec, _container_dec, _a, _init;
76
+ var _render_dec, _destroy_dec, _init_dec, _nodes_dec, _transform_dec, _container_dec, _a, _init;
77
77
  const defaultProps = {
78
78
  width: 200,
79
79
  height: 150,
@@ -123,7 +123,7 @@ function getBoundsOfRects(bounds1, bounds2) {
123
123
  height: maxY - minY
124
124
  };
125
125
  }
126
- class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _transform_dec = [inject.canvas.transform()], _canvasRef_dec = [inject.canvas.ref()], _nodes_dec = [inject.nodes()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _render_dec = [panel("right-bottom")], _a) {
126
+ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _transform_dec = [inject.canvas.transform()], _nodes_dec = [inject.nodes()], _init_dec = [OnInit], _destroy_dec = [OnDestroy], _render_dec = [panel("right-bottom")], _a) {
127
127
  constructor() {
128
128
  super(...arguments);
129
129
  __runInitializers(_init, 5, this);
@@ -136,13 +136,12 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
136
136
  __publicField(this, "dragEnd$", new Subject());
137
137
  __publicField(this, "container", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
138
138
  __publicField(this, "transform", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
139
- __publicField(this, "canvasRef", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
140
- __publicField(this, "nodes", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
139
+ __publicField(this, "nodes", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
141
140
  /**
142
141
  * 处理小地图上的点击事件,移动视图
143
142
  */
144
143
  __publicField(this, "handleMinimapClick", (event) => {
145
- if (!this.config.pannable || !this.canvasRef)
144
+ if (!this.config.pannable)
146
145
  return;
147
146
  const svg = event.currentTarget;
148
147
  const svgRect = svg.getBoundingClientRect();
@@ -155,28 +154,34 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
155
154
  const { scale } = this.transform;
156
155
  const newPositionX = -pointX * scale + this.container.width / 2;
157
156
  const newPositionY = -pointY * scale + this.container.height / 2;
158
- this.canvasRef.setTransform(newPositionX, newPositionY, scale, 300);
157
+ this.callTool("canvas", "setTransform", {
158
+ positionX: newPositionX,
159
+ positionY: newPositionY,
160
+ scale
161
+ });
159
162
  });
160
163
  /**
161
164
  * 处理缩放按钮点击事件
162
165
  */
163
166
  __publicField(this, "handleZoom", (isZoomIn) => {
164
- if (!this.config.zoomable || !this.canvasRef)
167
+ if (!this.config.zoomable)
165
168
  return;
166
169
  const step = this.config.zoomStep;
167
170
  if (isZoomIn) {
168
- this.canvasRef.zoomIn(step, 300);
171
+ this.callTool("canvas", "zoomIn", {
172
+ step
173
+ });
169
174
  } else {
170
- this.canvasRef.zoomOut(step, 300);
175
+ this.callTool("canvas", "zoomOut", {
176
+ step
177
+ });
171
178
  }
172
179
  });
173
180
  /**
174
181
  * 重置视图
175
182
  */
176
183
  __publicField(this, "handleReset", () => {
177
- if (!this.canvasRef)
178
- return;
179
- this.canvasRef.resetTransform(300);
184
+ this.callTool("canvas", "resetTransform", {});
180
185
  });
181
186
  }
182
187
  get classNames() {
@@ -284,9 +289,12 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
284
289
  }),
285
290
  // 实时更新位置
286
291
  tap(({ newPositionX: newPositionX2, newPositionY: newPositionY2 }) => {
287
- if (!this.canvasRef)
288
- return;
289
- this.canvasRef.setTransform(newPositionX2, newPositionY2, this.transform.scale, 0);
292
+ this.callTool("canvas", "setTransform", {
293
+ positionX: newPositionX2,
294
+ positionY: newPositionY2,
295
+ scale: this.transform.scale,
296
+ animationTime: 0
297
+ });
290
298
  }),
291
299
  // 直到拖拽结束
292
300
  takeUntil(this.dragEnd$)
@@ -300,12 +308,10 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
300
308
  setupInteractable() {
301
309
  if (this.currentInteractable)
302
310
  return;
303
- this.currentInteractable = interact(`.${this.classNames.viewBox}[data-plugin-id="${this.pluginId}"]`).draggable({
311
+ this.currentInteractable = interact(`.${this.classNames.viewBox}[data-${this.pluginId}]`).draggable({
304
312
  listeners: {
305
313
  // 开始拖拽时,记录初始状态
306
314
  start: (event) => {
307
- if (!this.canvasRef)
308
- return;
309
315
  this.dragStart$.next({
310
316
  x: event.clientX,
311
317
  y: event.clientY,
@@ -418,9 +424,8 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
418
424
  ),
419
425
  /* @__PURE__ */ jsx(
420
426
  "rect",
421
- {
427
+ __spreadValues({
422
428
  className: viewBox,
423
- "data-plugin-id": this.pluginId,
424
429
  x: viewRect.x,
425
430
  y: viewRect.y,
426
431
  width: viewRect.width,
@@ -432,7 +437,7 @@ class Minimap extends (_a = BasePlugin, _container_dec = [inject.container()], _
432
437
  cursor: "move",
433
438
  pointerEvents: "all"
434
439
  }
435
- }
440
+ }, { [`data-${this.pluginId}`]: "" })
436
441
  )
437
442
  ]
438
443
  }
@@ -513,7 +518,6 @@ __decorateElement(_init, 1, "destroy", _destroy_dec, Minimap);
513
518
  __decorateElement(_init, 1, "render", _render_dec, Minimap);
514
519
  __decorateElement(_init, 5, "container", _container_dec, Minimap);
515
520
  __decorateElement(_init, 5, "transform", _transform_dec, Minimap);
516
- __decorateElement(_init, 5, "canvasRef", _canvasRef_dec, Minimap);
517
521
  __decorateElement(_init, 5, "nodes", _nodes_dec, Minimap);
518
522
  __decoratorMetadata(_init, Minimap);
519
523
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/plugins-minimap",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Minimap Plugin for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -29,8 +29,8 @@
29
29
  ],
30
30
  "peerDependencies": {
31
31
  "interactjs": "^1.10.27",
32
- "@knotx/jsx": "0.4.1",
33
- "@knotx/plugins-canvas": "0.4.1"
32
+ "@knotx/jsx": "0.4.2",
33
+ "@knotx/plugins-canvas": "0.4.2"
34
34
  },
35
35
  "dependencies": {
36
36
  "@interactjs/actions": "^1.10.27",
@@ -38,16 +38,16 @@
38
38
  "@interactjs/modifiers": "^1.10.27",
39
39
  "@interactjs/types": "^1.10.27",
40
40
  "rxjs": "^7.8.1",
41
- "@knotx/core": "0.4.1",
42
- "@knotx/decorators": "0.4.1"
41
+ "@knotx/core": "0.4.2",
42
+ "@knotx/decorators": "0.4.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "interactjs": "^1.10.27",
46
- "@knotx/build-config": "0.4.1",
47
- "@knotx/eslint-config": "0.4.1",
48
- "@knotx/jsx": "0.4.1",
49
- "@knotx/plugins-canvas": "0.4.1",
50
- "@knotx/typescript-config": "0.4.1"
46
+ "@knotx/build-config": "0.4.2",
47
+ "@knotx/eslint-config": "0.4.2",
48
+ "@knotx/jsx": "0.4.2",
49
+ "@knotx/plugins-canvas": "0.4.2",
50
+ "@knotx/typescript-config": "0.4.2"
51
51
  },
52
52
  "scripts": {
53
53
  "build": "unbuild",