react-design-editor 0.0.52 → 0.0.55

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.
@@ -10,6 +10,10 @@ declare class AlignmentHandler {
10
10
  * Align center at selection
11
11
  */
12
12
  center: () => void;
13
+ /**
14
+ * Align center at selection
15
+ */
16
+ middle: () => void;
13
17
  /**
14
18
  * Align right at selection
15
19
  */
@@ -28,7 +28,23 @@ class AlignmentHandler {
28
28
  const activeSelection = activeObject;
29
29
  activeSelection.forEachObject(obj => {
30
30
  obj.set({
31
- left: 0 - ((obj.width * obj.scaleX) / 2),
31
+ left: 0 - (obj.width * obj.scaleX) / 2,
32
+ });
33
+ obj.setCoords();
34
+ this.handler.canvas.renderAll();
35
+ });
36
+ }
37
+ };
38
+ /**
39
+ * Align center at selection
40
+ */
41
+ this.middle = () => {
42
+ const activeObject = this.handler.canvas.getActiveObject();
43
+ if (activeObject && activeObject.type === 'activeSelection') {
44
+ const activeSelection = activeObject;
45
+ activeSelection.forEachObject(obj => {
46
+ obj.set({
47
+ top: 0 - (obj.width * obj.scaleX) / 2,
32
48
  });
33
49
  obj.setCoords();
34
50
  this.handler.canvas.renderAll();
@@ -42,10 +58,10 @@ class AlignmentHandler {
42
58
  const activeObject = this.handler.canvas.getActiveObject();
43
59
  if (activeObject && activeObject.type === 'activeSelection') {
44
60
  const activeSelection = activeObject;
45
- const activeObjectLeft = (activeObject.width / 2);
61
+ const activeObjectLeft = activeObject.width / 2;
46
62
  activeSelection.forEachObject(obj => {
47
63
  obj.set({
48
- left: activeObjectLeft - (obj.width * obj.scaleX),
64
+ left: activeObjectLeft - obj.width * obj.scaleX,
49
65
  });
50
66
  obj.setCoords();
51
67
  this.handler.canvas.renderAll();
@@ -283,10 +283,10 @@ class EventHandler {
283
283
  const delta = event.e.deltaY;
284
284
  let zoomRatio = this.handler.canvas.getZoom();
285
285
  if (delta > 0) {
286
- zoomRatio -= 0.05;
286
+ zoomRatio -= this.handler.zoomStep;
287
287
  }
288
288
  else {
289
- zoomRatio += 0.05;
289
+ zoomRatio += this.handler.zoomStep;
290
290
  }
291
291
  this.handler.zoomHandler.zoomToPoint(new fabric_1.fabric.Point(this.handler.canvas.getWidth() / 2, this.handler.canvas.getHeight() / 2), zoomRatio);
292
292
  event.e.preventDefault();
@@ -619,6 +619,7 @@ class EventHandler {
619
619
  const createdObj = this.handler.add(obj, false, true);
620
620
  this.handler.canvas.setActiveObject(createdObj);
621
621
  this.handler.canvas.requestRenderAll();
622
+ this.handler.onAdd?.(createdObj);
622
623
  }
623
624
  else {
624
625
  const nodes = [];
@@ -649,6 +650,7 @@ class EventHandler {
649
650
  });
650
651
  this.handler.canvas.setActiveObject(activeSelection);
651
652
  this.handler.canvas.requestRenderAll();
653
+ this.handler.onAdd?.(activeSelection);
652
654
  }
653
655
  if (!this.handler.transactionHandler.active) {
654
656
  this.handler.transactionHandler.save('paste');
@@ -104,6 +104,11 @@ export interface HandlerOption {
104
104
  * @type {number}
105
105
  */
106
106
  maxZoom?: number;
107
+ /**
108
+ * Zoom ratio step
109
+ * @type {number}
110
+ */
111
+ zoomStep?: number;
107
112
  /**
108
113
  * Workarea option
109
114
  * @type {WorkareaOption}
@@ -179,6 +184,7 @@ declare class Handler implements HandlerOptions {
179
184
  interactionMode: InteractionMode;
180
185
  minZoom: number;
181
186
  maxZoom: number;
187
+ zoomStep: number;
182
188
  propertiesToInclude?: string[];
183
189
  workareaOption?: WorkareaOption;
184
190
  canvasOption?: CanvasOption;
@@ -17,6 +17,7 @@ const constants_1 = require("../constants");
17
17
  */
18
18
  class Handler {
19
19
  constructor(options) {
20
+ this.zoomStep = 0.05;
20
21
  this.propertiesToInclude = constants_1.defaults.propertiesToInclude;
21
22
  this.workareaOption = constants_1.defaults.workareaOption;
22
23
  this.canvasOption = constants_1.defaults.canvasOption;
@@ -43,6 +44,7 @@ class Handler {
43
44
  this.interactionMode = options.interactionMode;
44
45
  this.minZoom = options.minZoom;
45
46
  this.maxZoom = options.maxZoom;
47
+ this.zoomStep = options.zoomStep || 0.05;
46
48
  this.zoomEnabled = options.zoomEnabled;
47
49
  this.width = options.width;
48
50
  this.height = options.height;
@@ -88,7 +90,7 @@ class Handler {
88
90
  this.animationHandler = new _1.AnimationHandler(this);
89
91
  this.contextmenuHandler = new _1.ContextmenuHandler(this);
90
92
  this.tooltipHandler = new _1.TooltipHandler(this);
91
- this.zoomHandler = new _1.ZoomHandler(this);
93
+ this.zoomHandler = new _1.ZoomHandler(this, this.zoomStep);
92
94
  this.interactionHandler = new _1.InteractionHandler(this);
93
95
  this.transactionHandler = new _1.TransactionHandler(this);
94
96
  this.gridHandler = new _1.GridHandler(this);
@@ -356,6 +358,7 @@ class Handler {
356
358
  obj.set('src', source);
357
359
  resolve(obj.setSrc(source, () => this.canvas.renderAll(), {
358
360
  dirty: true,
361
+ crossOrigin: "anonymous"
359
362
  }));
360
363
  }
361
364
  });
@@ -1474,8 +1477,13 @@ class Handler {
1474
1477
  this.saveCanvasImage = (option = { name: 'New Image', format: 'png', quality: 1 }) => {
1475
1478
  // If it's zoomed out/in, the container will also include in the image
1476
1479
  // hence need to reset the zoom level.
1477
- this.zoomHandler.zoomOneToOne();
1478
- const { left, top, width, height } = this.workarea;
1480
+ let { left, top, width, height, scaleX, scaleY } = this.workarea;
1481
+ width = Math.ceil(width * scaleX);
1482
+ height = Math.ceil(height * scaleY);
1483
+ // cachedVT is used to reset the viewportTransform after the image is saved.
1484
+ const cachedVT = this.canvas.viewportTransform;
1485
+ // reset the viewportTransform to default (no zoom)
1486
+ this.canvas.viewportTransform = [1, 0, 0, 1, 0, 0];
1479
1487
  const dataUrl = this.canvas.toDataURL({
1480
1488
  ...option,
1481
1489
  left,
@@ -1492,6 +1500,8 @@ class Handler {
1492
1500
  anchorEl.click();
1493
1501
  anchorEl.remove();
1494
1502
  }
1503
+ // reset the viewportTransform to previous value.
1504
+ this.canvas.viewportTransform = cachedVT;
1495
1505
  };
1496
1506
  /**
1497
1507
  * Sets "angle" of an instance with centered rotation
@@ -274,7 +274,7 @@ class WorkareaHandler {
274
274
  this.handler.zoomHandler.zoomToPoint(new fabric_1.fabric.Point(center.left, center.top), zoom);
275
275
  canvas.renderAll();
276
276
  resolve(workarea);
277
- });
277
+ }, { crossOrigin: 'anonymous' });
278
278
  });
279
279
  };
280
280
  if (!source) {
@@ -1,9 +1,10 @@
1
1
  import { fabric } from 'fabric';
2
- import Handler from './Handler';
3
2
  import { FabricObject } from '../utils';
3
+ import Handler from './Handler';
4
4
  declare class ZoomHandler {
5
5
  handler?: Handler;
6
- constructor(handler: Handler);
6
+ private _zoomStep?;
7
+ constructor(handler: Handler, zoomStep?: number);
7
8
  /**
8
9
  * Zoom to point
9
10
  *
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const fabric_1 = require("fabric");
4
4
  class ZoomHandler {
5
- constructor(handler) {
5
+ constructor(handler, zoomStep = 0.05) {
6
6
  /**
7
7
  * Zoom to point
8
8
  *
@@ -74,7 +74,7 @@ class ZoomHandler {
74
74
  */
75
75
  this.zoomIn = () => {
76
76
  let zoomRatio = this.handler.canvas.getZoom();
77
- zoomRatio += 0.05;
77
+ zoomRatio += this._zoomStep;
78
78
  const center = this.handler.canvas.getCenter();
79
79
  this.zoomToPoint(new fabric_1.fabric.Point(center.left, center.top), zoomRatio);
80
80
  };
@@ -84,7 +84,7 @@ class ZoomHandler {
84
84
  */
85
85
  this.zoomOut = () => {
86
86
  let zoomRatio = this.handler.canvas.getZoom();
87
- zoomRatio -= 0.05;
87
+ zoomRatio -= this._zoomStep;
88
88
  const center = this.handler.canvas.getCenter();
89
89
  this.zoomToPoint(new fabric_1.fabric.Point(center.left, center.top), zoomRatio);
90
90
  };
@@ -138,6 +138,7 @@ class ZoomHandler {
138
138
  this.zoomToCenterWithObject(activeObject, zoomFit);
139
139
  };
140
140
  this.handler = handler;
141
+ this._zoomStep = zoomStep;
141
142
  }
142
143
  }
143
144
  exports.default = ZoomHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-design-editor",
3
- "version": "0.0.52",
3
+ "version": "0.0.55",
4
4
  "description": "Design Editor Tools with React.js + ant.design + fabric.js",
5
5
  "main": "dist/react-design-editor.min.js",
6
6
  "typings": "lib/index.d.ts",