@knotx/plugins-canvas 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 CHANGED
@@ -3,9 +3,9 @@
3
3
  const jsxRuntime = require('@knotx/jsx/jsx-runtime');
4
4
  const core = require('@knotx/core');
5
5
  const decorators = require('@knotx/decorators');
6
+ const reactZoomPanPinch = require('@knotx/react-zoom-pan-pinch');
6
7
  const lodashEs = require('lodash-es');
7
8
  const react = require('react');
8
- const reactZoomPanPinch = require('react-zoom-pan-pinch');
9
9
 
10
10
  function calculateTransform({
11
11
  node,
@@ -235,7 +235,9 @@ class Canvas extends (_a = core.BasePlugin, _transform_dec = [decorators.registe
235
235
  __publicField(this, "interaction", __runInitializers(_init, 36, this)), __runInitializers(_init, 39, this);
236
236
  __publicField(this, "listeners", {
237
237
  click: /* @__PURE__ */ new Set(),
238
- contextmenu: /* @__PURE__ */ new Set()
238
+ contextmenu: /* @__PURE__ */ new Set(),
239
+ mouseenter: /* @__PURE__ */ new Set(),
240
+ mouseleave: /* @__PURE__ */ new Set()
239
241
  });
240
242
  __publicField(this, "edgeScrollAnimationFrame", null);
241
243
  __publicField(this, "mousePosition", null);
@@ -245,6 +247,55 @@ class Canvas extends (_a = core.BasePlugin, _transform_dec = [decorators.registe
245
247
  __publicField(this, "removeListener", __runInitializers(_init, 44, this, (type, listener) => {
246
248
  this.listeners[type].delete(listener);
247
249
  })), __runInitializers(_init, 47, this);
250
+ __publicField(this, "onClick", (e) => {
251
+ if (!this.isCanvasEvent(e)) {
252
+ return;
253
+ }
254
+ if (!this.interaction.canInteract(core.InteractionPriority.CanvasClick)) {
255
+ return;
256
+ }
257
+ this.listeners.click.forEach((listener) => {
258
+ listener(e);
259
+ });
260
+ });
261
+ __publicField(this, "onContextMenu", (e) => {
262
+ if (!this.isCanvasEvent(e)) {
263
+ return;
264
+ }
265
+ if (!this.interaction.canInteract(core.InteractionPriority.CanvasContextMenu)) {
266
+ return;
267
+ }
268
+ this.listeners.contextmenu.forEach((listener) => {
269
+ listener(e);
270
+ });
271
+ });
272
+ __publicField(this, "onMouseMove", (e) => {
273
+ if (this.edgeScroll.config.enabled) {
274
+ const rect = e.currentTarget.getBoundingClientRect();
275
+ this.mousePosition = {
276
+ x: e.clientX - rect.left,
277
+ y: e.clientY - rect.top
278
+ };
279
+ if (this.edgeScrollAnimationFrame === null) {
280
+ this.edgeScrollAnimationFrame = requestAnimationFrame(this.handleEdgeScroll);
281
+ }
282
+ }
283
+ });
284
+ __publicField(this, "onMouseLeave", (e) => {
285
+ this.mousePosition = null;
286
+ if (this.edgeScrollAnimationFrame !== null) {
287
+ cancelAnimationFrame(this.edgeScrollAnimationFrame);
288
+ this.edgeScrollAnimationFrame = null;
289
+ }
290
+ this.listeners.mouseleave.forEach((listener) => {
291
+ listener(e);
292
+ });
293
+ });
294
+ __publicField(this, "onMouseEnter", (e) => {
295
+ this.listeners.mouseenter.forEach((listener) => {
296
+ listener(e);
297
+ });
298
+ });
248
299
  __publicField(this, "handleEdgeScroll", () => {
249
300
  if (!this.edgeScroll.config.enabled || !this.mousePosition || !this.ref) {
250
301
  return;
@@ -323,30 +374,7 @@ class Canvas extends (_a = core.BasePlugin, _transform_dec = [decorators.registe
323
374
  }
324
375
  render({ children } = { children: null }) {
325
376
  var _a2, _b, _c, _d;
326
- const defaultTransform = react.useMemo(() => {
327
- const defaultLocated = __spreadValues({}, this.config.defaultLocated);
328
- if (!(defaultLocated == null ? void 0 : defaultLocated.nodeId) && !defaultLocated.limitToBounds) {
329
- return this.transform;
330
- }
331
- const node = defaultLocated.nodeId ? this.getNode({ id: defaultLocated.nodeId }) : void 0;
332
- defaultLocated.inline || (defaultLocated.inline = "center");
333
- defaultLocated.block || (defaultLocated.block = "center");
334
- defaultLocated.scale || (defaultLocated.scale = this.transform.scale);
335
- const { positionX, positionY, scale: newScale } = calculateTransform(__spreadValues({
336
- node,
337
- container: this.container,
338
- transform: this.transform,
339
- contentSize: this.contentSize
340
- }, defaultLocated));
341
- const newTransform = {
342
- previousScale: this.transform.scale,
343
- scale: newScale,
344
- positionX: -positionX,
345
- positionY: -positionY
346
- };
347
- this.transform = newTransform;
348
- return newTransform;
349
- }, []);
377
+ const defaultTransform = react.useMemo(() => this.getDefaultTransform(), []);
350
378
  const [transformRef, setTransformRef] = react.useReducer((_, ref) => {
351
379
  var _a3;
352
380
  const dom = ref.instance.wrapperComponent;
@@ -358,21 +386,7 @@ class Canvas extends (_a = core.BasePlugin, _transform_dec = [decorators.registe
358
386
  }
359
387
  return ref;
360
388
  }, null);
361
- const [fixedLayers, childrenLayers] = react.useMemo(() => {
362
- const fixedLayers2 = [];
363
- const childrenLayers2 = [];
364
- for (const child of Array.isArray(children) ? children : [children]) {
365
- if (!(child == null ? void 0 : child.key)) {
366
- continue;
367
- }
368
- if (child.key <= core.Layer.Background << 1 || child.key > core.Layer.Foreground >> 1) {
369
- fixedLayers2.push(child);
370
- } else {
371
- childrenLayers2.push(child);
372
- }
373
- }
374
- return [fixedLayers2, childrenLayers2];
375
- }, [children]);
389
+ const [fixedLayers, childrenLayers] = react.useMemo(() => this.groupLayers(children), [children]);
376
390
  react.useLayoutEffect(() => {
377
391
  const wrapperElement = transformRef == null ? void 0 : transformRef.instance.wrapperComponent;
378
392
  const onScroll = (event) => {
@@ -413,47 +427,6 @@ class Canvas extends (_a = core.BasePlugin, _transform_dec = [decorators.registe
413
427
  wrapperElement == null ? void 0 : wrapperElement.removeEventListener("scroll", onScroll, { capture: true });
414
428
  };
415
429
  }, [transformRef]);
416
- const onClick = react.useCallback((e) => {
417
- if (!this.isCanvasEvent(e)) {
418
- return;
419
- }
420
- if (!this.interaction.canInteract(core.InteractionPriority.CanvasClick)) {
421
- return;
422
- }
423
- this.listeners.click.forEach((listener) => {
424
- listener(e);
425
- });
426
- }, []);
427
- const onContextMenu = react.useCallback((e) => {
428
- if (!this.isCanvasEvent(e)) {
429
- return;
430
- }
431
- if (!this.interaction.canInteract(core.InteractionPriority.CanvasContextMenu)) {
432
- return;
433
- }
434
- this.listeners.contextmenu.forEach((listener) => {
435
- listener(e);
436
- });
437
- }, []);
438
- const onMouseMove = react.useCallback((e) => {
439
- if (this.edgeScroll.config.enabled) {
440
- const rect = e.currentTarget.getBoundingClientRect();
441
- this.mousePosition = {
442
- x: e.clientX - rect.left,
443
- y: e.clientY - rect.top
444
- };
445
- if (this.edgeScrollAnimationFrame === null) {
446
- this.edgeScrollAnimationFrame = requestAnimationFrame(this.handleEdgeScroll);
447
- }
448
- }
449
- }, []);
450
- const onMouseLeave = react.useCallback(() => {
451
- this.mousePosition = null;
452
- if (this.edgeScrollAnimationFrame !== null) {
453
- cancelAnimationFrame(this.edgeScrollAnimationFrame);
454
- this.edgeScrollAnimationFrame = null;
455
- }
456
- }, []);
457
430
  return /* @__PURE__ */ jsxRuntime.jsxs(
458
431
  reactZoomPanPinch.TransformWrapper,
459
432
  __spreadProps(__spreadValues({}, this.config), {
@@ -470,15 +443,16 @@ class Canvas extends (_a = core.BasePlugin, _transform_dec = [decorators.registe
470
443
  wrapperStyle: {
471
444
  width: "100%",
472
445
  height: "100%",
473
- zIndex: core.Layer.Nodes | core.Layer.Edges,
446
+ zIndex: core.Layer.Nodes,
474
447
  contain: "strict"
475
448
  },
476
449
  wrapperProps: {
477
450
  id: this.pluginId,
478
- onClick,
479
- onContextMenu,
480
- onMouseMove,
481
- onMouseLeave
451
+ onClick: this.onClick,
452
+ onContextMenu: this.onContextMenu,
453
+ onMouseMove: this.onMouseMove,
454
+ onMouseLeave: this.onMouseLeave,
455
+ onMouseEnter: this.onMouseEnter
482
456
  },
483
457
  contentClass: core.bem(this.name, "content"),
484
458
  contentStyle: {
@@ -515,6 +489,45 @@ class Canvas extends (_a = core.BasePlugin, _transform_dec = [decorators.registe
515
489
  this.rootElement = null;
516
490
  });
517
491
  }
492
+ groupLayers(children) {
493
+ const fixedLayers = [];
494
+ const childrenLayers = [];
495
+ for (const child of Array.isArray(children) ? children : [children]) {
496
+ if (!(child == null ? void 0 : child.key)) {
497
+ continue;
498
+ }
499
+ if (child.key <= core.Layer.Background << 1 || child.key > core.Layer.Foreground >> 1) {
500
+ fixedLayers.push(child);
501
+ } else {
502
+ childrenLayers.push(child);
503
+ }
504
+ }
505
+ return [fixedLayers, childrenLayers];
506
+ }
507
+ getDefaultTransform() {
508
+ const defaultLocated = __spreadValues({}, this.config.defaultLocated);
509
+ if (!(defaultLocated == null ? void 0 : defaultLocated.nodeId) && !defaultLocated.limitToBounds) {
510
+ return this.transform;
511
+ }
512
+ const node = defaultLocated.nodeId ? this.getNode({ id: defaultLocated.nodeId }) : void 0;
513
+ defaultLocated.inline || (defaultLocated.inline = "center");
514
+ defaultLocated.block || (defaultLocated.block = "center");
515
+ defaultLocated.scale || (defaultLocated.scale = this.transform.scale);
516
+ const { positionX, positionY, scale: newScale } = calculateTransform(__spreadValues({
517
+ node,
518
+ container: this.container,
519
+ transform: this.transform,
520
+ contentSize: this.contentSize
521
+ }, defaultLocated));
522
+ const newTransform = {
523
+ previousScale: this.transform.scale,
524
+ scale: newScale,
525
+ positionX: -positionX,
526
+ positionY: -positionY
527
+ };
528
+ this.transform = newTransform;
529
+ return newTransform;
530
+ }
518
531
  isCanvasEvent(e) {
519
532
  return e.target === e.currentTarget || e.target.classList.contains(core.bem(this.name, "content"));
520
533
  }
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Element, BasePlugin, DOMElement, Engine } from '@knotx/core';
2
2
  import { InferParamsFromSchema } from '@knotx/decorators';
3
+ import { ReactZoomPanPinchProps, ReactZoomPanPinchContentRef } from '@knotx/react-zoom-pan-pinch';
3
4
  import { MouseEvent, ReactNode } from 'react';
4
- import { ReactZoomPanPinchProps, ReactZoomPanPinchContentRef } from 'react-zoom-pan-pinch';
5
5
 
6
6
  interface CanvasTransformState {
7
7
  previousScale: number;
@@ -76,7 +76,7 @@ declare module '@knotx/core' {
76
76
  };
77
77
  }
78
78
  }
79
- type CanvasEventType = 'click' | 'contextmenu';
79
+ type CanvasEventType = 'click' | 'contextmenu' | 'mouseenter' | 'mouseleave';
80
80
  type CanvasEventListener = (event: MouseEvent<HTMLElement>) => void;
81
81
  declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
82
82
  private config;
@@ -179,11 +179,18 @@ declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
179
179
  };
180
180
  };
181
181
  }>): void;
182
- private handleEdgeScroll;
183
182
  render({ children }?: {
184
183
  children: ReactNode;
185
184
  }): JSX.Element;
186
185
  init(config: CanvasConfig): void;
186
+ private groupLayers;
187
+ private getDefaultTransform;
188
+ private onClick;
189
+ private onContextMenu;
190
+ private onMouseMove;
191
+ private onMouseLeave;
192
+ private onMouseEnter;
193
+ private handleEdgeScroll;
187
194
  private isCanvasEvent;
188
195
  }
189
196
 
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Element, BasePlugin, DOMElement, Engine } from '@knotx/core';
2
2
  import { InferParamsFromSchema } from '@knotx/decorators';
3
+ import { ReactZoomPanPinchProps, ReactZoomPanPinchContentRef } from '@knotx/react-zoom-pan-pinch';
3
4
  import { MouseEvent, ReactNode } from 'react';
4
- import { ReactZoomPanPinchProps, ReactZoomPanPinchContentRef } from 'react-zoom-pan-pinch';
5
5
 
6
6
  interface CanvasTransformState {
7
7
  previousScale: number;
@@ -76,7 +76,7 @@ declare module '@knotx/core' {
76
76
  };
77
77
  }
78
78
  }
79
- type CanvasEventType = 'click' | 'contextmenu';
79
+ type CanvasEventType = 'click' | 'contextmenu' | 'mouseenter' | 'mouseleave';
80
80
  type CanvasEventListener = (event: MouseEvent<HTMLElement>) => void;
81
81
  declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
82
82
  private config;
@@ -179,11 +179,18 @@ declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
179
179
  };
180
180
  };
181
181
  }>): void;
182
- private handleEdgeScroll;
183
182
  render({ children }?: {
184
183
  children: ReactNode;
185
184
  }): JSX.Element;
186
185
  init(config: CanvasConfig): void;
186
+ private groupLayers;
187
+ private getDefaultTransform;
188
+ private onClick;
189
+ private onContextMenu;
190
+ private onMouseMove;
191
+ private onMouseLeave;
192
+ private onMouseEnter;
193
+ private handleEdgeScroll;
187
194
  private isCanvasEvent;
188
195
  }
189
196
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Element, BasePlugin, DOMElement, Engine } from '@knotx/core';
2
2
  import { InferParamsFromSchema } from '@knotx/decorators';
3
+ import { ReactZoomPanPinchProps, ReactZoomPanPinchContentRef } from '@knotx/react-zoom-pan-pinch';
3
4
  import { MouseEvent, ReactNode } from 'react';
4
- import { ReactZoomPanPinchProps, ReactZoomPanPinchContentRef } from 'react-zoom-pan-pinch';
5
5
 
6
6
  interface CanvasTransformState {
7
7
  previousScale: number;
@@ -76,7 +76,7 @@ declare module '@knotx/core' {
76
76
  };
77
77
  }
78
78
  }
79
- type CanvasEventType = 'click' | 'contextmenu';
79
+ type CanvasEventType = 'click' | 'contextmenu' | 'mouseenter' | 'mouseleave';
80
80
  type CanvasEventListener = (event: MouseEvent<HTMLElement>) => void;
81
81
  declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
82
82
  private config;
@@ -179,11 +179,18 @@ declare class Canvas extends BasePlugin<'canvas', CanvasConfig> {
179
179
  };
180
180
  };
181
181
  }>): void;
182
- private handleEdgeScroll;
183
182
  render({ children }?: {
184
183
  children: ReactNode;
185
184
  }): JSX.Element;
186
185
  init(config: CanvasConfig): void;
186
+ private groupLayers;
187
+ private getDefaultTransform;
188
+ private onClick;
189
+ private onContextMenu;
190
+ private onMouseMove;
191
+ private onMouseLeave;
192
+ private onMouseEnter;
193
+ private handleEdgeScroll;
187
194
  private isCanvasEvent;
188
195
  }
189
196
 
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { jsxs, jsx } from '@knotx/jsx/jsx-runtime';
2
- import { Layer, DOMElement, InteractionPriority, bem, BasePlugin } from '@knotx/core';
2
+ import { Layer, DOMElement, bem, BasePlugin, InteractionPriority } from '@knotx/core';
3
3
  import { register, inject, tool, layer, OnInit } from '@knotx/decorators';
4
+ import { TransformWrapper, TransformComponent } from '@knotx/react-zoom-pan-pinch';
4
5
  import { isEqual, merge } from 'lodash-es';
5
- import { useMemo, useReducer, useLayoutEffect, useCallback, Fragment } from 'react';
6
- import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch';
6
+ import { useMemo, useReducer, useLayoutEffect, Fragment } from 'react';
7
7
 
8
8
  function calculateTransform({
9
9
  node,
@@ -233,7 +233,9 @@ class Canvas extends (_a = BasePlugin, _transform_dec = [register("transform")],
233
233
  __publicField(this, "interaction", __runInitializers(_init, 36, this)), __runInitializers(_init, 39, this);
234
234
  __publicField(this, "listeners", {
235
235
  click: /* @__PURE__ */ new Set(),
236
- contextmenu: /* @__PURE__ */ new Set()
236
+ contextmenu: /* @__PURE__ */ new Set(),
237
+ mouseenter: /* @__PURE__ */ new Set(),
238
+ mouseleave: /* @__PURE__ */ new Set()
237
239
  });
238
240
  __publicField(this, "edgeScrollAnimationFrame", null);
239
241
  __publicField(this, "mousePosition", null);
@@ -243,6 +245,55 @@ class Canvas extends (_a = BasePlugin, _transform_dec = [register("transform")],
243
245
  __publicField(this, "removeListener", __runInitializers(_init, 44, this, (type, listener) => {
244
246
  this.listeners[type].delete(listener);
245
247
  })), __runInitializers(_init, 47, this);
248
+ __publicField(this, "onClick", (e) => {
249
+ if (!this.isCanvasEvent(e)) {
250
+ return;
251
+ }
252
+ if (!this.interaction.canInteract(InteractionPriority.CanvasClick)) {
253
+ return;
254
+ }
255
+ this.listeners.click.forEach((listener) => {
256
+ listener(e);
257
+ });
258
+ });
259
+ __publicField(this, "onContextMenu", (e) => {
260
+ if (!this.isCanvasEvent(e)) {
261
+ return;
262
+ }
263
+ if (!this.interaction.canInteract(InteractionPriority.CanvasContextMenu)) {
264
+ return;
265
+ }
266
+ this.listeners.contextmenu.forEach((listener) => {
267
+ listener(e);
268
+ });
269
+ });
270
+ __publicField(this, "onMouseMove", (e) => {
271
+ if (this.edgeScroll.config.enabled) {
272
+ const rect = e.currentTarget.getBoundingClientRect();
273
+ this.mousePosition = {
274
+ x: e.clientX - rect.left,
275
+ y: e.clientY - rect.top
276
+ };
277
+ if (this.edgeScrollAnimationFrame === null) {
278
+ this.edgeScrollAnimationFrame = requestAnimationFrame(this.handleEdgeScroll);
279
+ }
280
+ }
281
+ });
282
+ __publicField(this, "onMouseLeave", (e) => {
283
+ this.mousePosition = null;
284
+ if (this.edgeScrollAnimationFrame !== null) {
285
+ cancelAnimationFrame(this.edgeScrollAnimationFrame);
286
+ this.edgeScrollAnimationFrame = null;
287
+ }
288
+ this.listeners.mouseleave.forEach((listener) => {
289
+ listener(e);
290
+ });
291
+ });
292
+ __publicField(this, "onMouseEnter", (e) => {
293
+ this.listeners.mouseenter.forEach((listener) => {
294
+ listener(e);
295
+ });
296
+ });
246
297
  __publicField(this, "handleEdgeScroll", () => {
247
298
  if (!this.edgeScroll.config.enabled || !this.mousePosition || !this.ref) {
248
299
  return;
@@ -321,30 +372,7 @@ class Canvas extends (_a = BasePlugin, _transform_dec = [register("transform")],
321
372
  }
322
373
  render({ children } = { children: null }) {
323
374
  var _a2, _b, _c, _d;
324
- const defaultTransform = useMemo(() => {
325
- const defaultLocated = __spreadValues({}, this.config.defaultLocated);
326
- if (!(defaultLocated == null ? void 0 : defaultLocated.nodeId) && !defaultLocated.limitToBounds) {
327
- return this.transform;
328
- }
329
- const node = defaultLocated.nodeId ? this.getNode({ id: defaultLocated.nodeId }) : void 0;
330
- defaultLocated.inline || (defaultLocated.inline = "center");
331
- defaultLocated.block || (defaultLocated.block = "center");
332
- defaultLocated.scale || (defaultLocated.scale = this.transform.scale);
333
- const { positionX, positionY, scale: newScale } = calculateTransform(__spreadValues({
334
- node,
335
- container: this.container,
336
- transform: this.transform,
337
- contentSize: this.contentSize
338
- }, defaultLocated));
339
- const newTransform = {
340
- previousScale: this.transform.scale,
341
- scale: newScale,
342
- positionX: -positionX,
343
- positionY: -positionY
344
- };
345
- this.transform = newTransform;
346
- return newTransform;
347
- }, []);
375
+ const defaultTransform = useMemo(() => this.getDefaultTransform(), []);
348
376
  const [transformRef, setTransformRef] = useReducer((_, ref) => {
349
377
  var _a3;
350
378
  const dom = ref.instance.wrapperComponent;
@@ -356,21 +384,7 @@ class Canvas extends (_a = BasePlugin, _transform_dec = [register("transform")],
356
384
  }
357
385
  return ref;
358
386
  }, null);
359
- const [fixedLayers, childrenLayers] = useMemo(() => {
360
- const fixedLayers2 = [];
361
- const childrenLayers2 = [];
362
- for (const child of Array.isArray(children) ? children : [children]) {
363
- if (!(child == null ? void 0 : child.key)) {
364
- continue;
365
- }
366
- if (child.key <= Layer.Background << 1 || child.key > Layer.Foreground >> 1) {
367
- fixedLayers2.push(child);
368
- } else {
369
- childrenLayers2.push(child);
370
- }
371
- }
372
- return [fixedLayers2, childrenLayers2];
373
- }, [children]);
387
+ const [fixedLayers, childrenLayers] = useMemo(() => this.groupLayers(children), [children]);
374
388
  useLayoutEffect(() => {
375
389
  const wrapperElement = transformRef == null ? void 0 : transformRef.instance.wrapperComponent;
376
390
  const onScroll = (event) => {
@@ -411,47 +425,6 @@ class Canvas extends (_a = BasePlugin, _transform_dec = [register("transform")],
411
425
  wrapperElement == null ? void 0 : wrapperElement.removeEventListener("scroll", onScroll, { capture: true });
412
426
  };
413
427
  }, [transformRef]);
414
- const onClick = useCallback((e) => {
415
- if (!this.isCanvasEvent(e)) {
416
- return;
417
- }
418
- if (!this.interaction.canInteract(InteractionPriority.CanvasClick)) {
419
- return;
420
- }
421
- this.listeners.click.forEach((listener) => {
422
- listener(e);
423
- });
424
- }, []);
425
- const onContextMenu = useCallback((e) => {
426
- if (!this.isCanvasEvent(e)) {
427
- return;
428
- }
429
- if (!this.interaction.canInteract(InteractionPriority.CanvasContextMenu)) {
430
- return;
431
- }
432
- this.listeners.contextmenu.forEach((listener) => {
433
- listener(e);
434
- });
435
- }, []);
436
- const onMouseMove = useCallback((e) => {
437
- if (this.edgeScroll.config.enabled) {
438
- const rect = e.currentTarget.getBoundingClientRect();
439
- this.mousePosition = {
440
- x: e.clientX - rect.left,
441
- y: e.clientY - rect.top
442
- };
443
- if (this.edgeScrollAnimationFrame === null) {
444
- this.edgeScrollAnimationFrame = requestAnimationFrame(this.handleEdgeScroll);
445
- }
446
- }
447
- }, []);
448
- const onMouseLeave = useCallback(() => {
449
- this.mousePosition = null;
450
- if (this.edgeScrollAnimationFrame !== null) {
451
- cancelAnimationFrame(this.edgeScrollAnimationFrame);
452
- this.edgeScrollAnimationFrame = null;
453
- }
454
- }, []);
455
428
  return /* @__PURE__ */ jsxs(
456
429
  TransformWrapper,
457
430
  __spreadProps(__spreadValues({}, this.config), {
@@ -468,15 +441,16 @@ class Canvas extends (_a = BasePlugin, _transform_dec = [register("transform")],
468
441
  wrapperStyle: {
469
442
  width: "100%",
470
443
  height: "100%",
471
- zIndex: Layer.Nodes | Layer.Edges,
444
+ zIndex: Layer.Nodes,
472
445
  contain: "strict"
473
446
  },
474
447
  wrapperProps: {
475
448
  id: this.pluginId,
476
- onClick,
477
- onContextMenu,
478
- onMouseMove,
479
- onMouseLeave
449
+ onClick: this.onClick,
450
+ onContextMenu: this.onContextMenu,
451
+ onMouseMove: this.onMouseMove,
452
+ onMouseLeave: this.onMouseLeave,
453
+ onMouseEnter: this.onMouseEnter
480
454
  },
481
455
  contentClass: bem(this.name, "content"),
482
456
  contentStyle: {
@@ -513,6 +487,45 @@ class Canvas extends (_a = BasePlugin, _transform_dec = [register("transform")],
513
487
  this.rootElement = null;
514
488
  });
515
489
  }
490
+ groupLayers(children) {
491
+ const fixedLayers = [];
492
+ const childrenLayers = [];
493
+ for (const child of Array.isArray(children) ? children : [children]) {
494
+ if (!(child == null ? void 0 : child.key)) {
495
+ continue;
496
+ }
497
+ if (child.key <= Layer.Background << 1 || child.key > Layer.Foreground >> 1) {
498
+ fixedLayers.push(child);
499
+ } else {
500
+ childrenLayers.push(child);
501
+ }
502
+ }
503
+ return [fixedLayers, childrenLayers];
504
+ }
505
+ getDefaultTransform() {
506
+ const defaultLocated = __spreadValues({}, this.config.defaultLocated);
507
+ if (!(defaultLocated == null ? void 0 : defaultLocated.nodeId) && !defaultLocated.limitToBounds) {
508
+ return this.transform;
509
+ }
510
+ const node = defaultLocated.nodeId ? this.getNode({ id: defaultLocated.nodeId }) : void 0;
511
+ defaultLocated.inline || (defaultLocated.inline = "center");
512
+ defaultLocated.block || (defaultLocated.block = "center");
513
+ defaultLocated.scale || (defaultLocated.scale = this.transform.scale);
514
+ const { positionX, positionY, scale: newScale } = calculateTransform(__spreadValues({
515
+ node,
516
+ container: this.container,
517
+ transform: this.transform,
518
+ contentSize: this.contentSize
519
+ }, defaultLocated));
520
+ const newTransform = {
521
+ previousScale: this.transform.scale,
522
+ scale: newScale,
523
+ positionX: -positionX,
524
+ positionY: -positionY
525
+ };
526
+ this.transform = newTransform;
527
+ return newTransform;
528
+ }
516
529
  isCanvasEvent(e) {
517
530
  return e.target === e.currentTarget || e.target.classList.contains(bem(this.name, "content"));
518
531
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knotx/plugins-canvas",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Canvas Plugin for Knotx",
5
5
  "author": "boenfu",
6
6
  "license": "MIT",
@@ -29,23 +29,23 @@
29
29
  ],
30
30
  "peerDependencies": {
31
31
  "react": ">=17.0.0",
32
- "@knotx/jsx": "0.4.4"
32
+ "@knotx/jsx": "0.4.6"
33
33
  },
34
34
  "dependencies": {
35
+ "@knotx/react-zoom-pan-pinch": "^3.9.8",
35
36
  "lodash-es": "^4.17.21",
36
- "react-zoom-pan-pinch": "^3.7.0",
37
37
  "rxjs": "^7.8.1",
38
- "@knotx/core": "0.4.4",
39
- "@knotx/decorators": "0.4.4"
38
+ "@knotx/core": "0.4.6",
39
+ "@knotx/decorators": "0.4.6"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/lodash-es": "^4.17.12",
43
43
  "@types/react": "^17.0.0",
44
44
  "react": "^17.0.0",
45
- "@knotx/build-config": "0.4.4",
46
- "@knotx/eslint-config": "0.4.4",
47
- "@knotx/jsx": "0.4.4",
48
- "@knotx/typescript-config": "0.4.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",