react-design-editor 0.0.33 → 0.0.37

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.
Files changed (95) hide show
  1. package/README.md +37 -33
  2. package/dist/react-design-editor.js +20849 -11309
  3. package/dist/react-design-editor.min.js +1 -1
  4. package/dist/react-design-editor.min.js.LICENSE.txt +3 -10
  5. package/package.json +35 -31
  6. package/lib/Canvas.d.ts +0 -32
  7. package/lib/Canvas.js +0 -162
  8. package/lib/CanvasObject.d.ts +0 -10
  9. package/lib/CanvasObject.js +0 -96
  10. package/lib/constants/defaults.d.ts +0 -37
  11. package/lib/constants/defaults.js +0 -68
  12. package/lib/constants/index.d.ts +0 -2
  13. package/lib/constants/index.js +0 -24
  14. package/lib/handlers/AlignmentHandler.d.ts +0 -18
  15. package/lib/handlers/AlignmentHandler.js +0 -58
  16. package/lib/handlers/AnimationHandler.d.ts +0 -50
  17. package/lib/handlers/AnimationHandler.js +0 -320
  18. package/lib/handlers/ChartHandler.d.ts +0 -8
  19. package/lib/handlers/ChartHandler.js +0 -8
  20. package/lib/handlers/ContextmenuHandler.d.ts +0 -28
  21. package/lib/handlers/ContextmenuHandler.js +0 -65
  22. package/lib/handlers/CropHandler.d.ts +0 -43
  23. package/lib/handlers/CropHandler.js +0 -261
  24. package/lib/handlers/DrawingHandler.d.ts +0 -28
  25. package/lib/handlers/DrawingHandler.js +0 -318
  26. package/lib/handlers/ElementHandler.d.ts +0 -80
  27. package/lib/handlers/ElementHandler.js +0 -154
  28. package/lib/handlers/EventHandler.d.ts +0 -170
  29. package/lib/handlers/EventHandler.js +0 -877
  30. package/lib/handlers/GridHandler.d.ts +0 -19
  31. package/lib/handlers/GridHandler.js +0 -77
  32. package/lib/handlers/GuidelineHandler.d.ts +0 -61
  33. package/lib/handlers/GuidelineHandler.js +0 -314
  34. package/lib/handlers/Handler.d.ts +0 -603
  35. package/lib/handlers/Handler.js +0 -1612
  36. package/lib/handlers/ImageHandler.d.ts +0 -307
  37. package/lib/handlers/ImageHandler.js +0 -529
  38. package/lib/handlers/InteractionHandler.d.ts +0 -45
  39. package/lib/handlers/InteractionHandler.js +0 -159
  40. package/lib/handlers/LinkHandler.d.ts +0 -115
  41. package/lib/handlers/LinkHandler.js +0 -247
  42. package/lib/handlers/NodeHandler.d.ts +0 -50
  43. package/lib/handlers/NodeHandler.js +0 -274
  44. package/lib/handlers/PortHandler.d.ts +0 -22
  45. package/lib/handlers/PortHandler.js +0 -179
  46. package/lib/handlers/ShortcutHandler.d.ts +0 -119
  47. package/lib/handlers/ShortcutHandler.js +0 -150
  48. package/lib/handlers/TooltipHandler.d.ts +0 -33
  49. package/lib/handlers/TooltipHandler.js +0 -91
  50. package/lib/handlers/TransactionHandler.d.ts +0 -59
  51. package/lib/handlers/TransactionHandler.js +0 -139
  52. package/lib/handlers/WorkareaHandler.d.ts +0 -43
  53. package/lib/handlers/WorkareaHandler.js +0 -354
  54. package/lib/handlers/ZoomHandler.d.ts +0 -48
  55. package/lib/handlers/ZoomHandler.js +0 -143
  56. package/lib/handlers/index.d.ts +0 -21
  57. package/lib/handlers/index.js +0 -44
  58. package/lib/index.d.ts +0 -5
  59. package/lib/index.js +0 -19
  60. package/lib/objects/Arrow.d.ts +0 -2
  61. package/lib/objects/Arrow.js +0 -39
  62. package/lib/objects/Chart.d.ts +0 -10
  63. package/lib/objects/Chart.js +0 -123
  64. package/lib/objects/CirclePort.d.ts +0 -2
  65. package/lib/objects/CirclePort.js +0 -28
  66. package/lib/objects/Cube.d.ts +0 -5
  67. package/lib/objects/Cube.js +0 -71
  68. package/lib/objects/CurvedLink.d.ts +0 -2
  69. package/lib/objects/CurvedLink.js +0 -49
  70. package/lib/objects/Element.d.ts +0 -13
  71. package/lib/objects/Element.js +0 -83
  72. package/lib/objects/Gif.d.ts +0 -3
  73. package/lib/objects/Gif.js +0 -38
  74. package/lib/objects/Iframe.d.ts +0 -9
  75. package/lib/objects/Iframe.js +0 -69
  76. package/lib/objects/Line.d.ts +0 -2
  77. package/lib/objects/Line.js +0 -24
  78. package/lib/objects/Link.d.ts +0 -15
  79. package/lib/objects/Link.js +0 -104
  80. package/lib/objects/Node.d.ts +0 -59
  81. package/lib/objects/Node.js +0 -271
  82. package/lib/objects/OrthogonalLink.d.ts +0 -2
  83. package/lib/objects/OrthogonalLink.js +0 -52
  84. package/lib/objects/Port.d.ts +0 -12
  85. package/lib/objects/Port.js +0 -28
  86. package/lib/objects/Svg.d.ts +0 -8
  87. package/lib/objects/Svg.js +0 -59
  88. package/lib/objects/Video.d.ts +0 -14
  89. package/lib/objects/Video.js +0 -119
  90. package/lib/objects/index.d.ts +0 -15
  91. package/lib/objects/index.js +0 -32
  92. package/lib/utils/ObjectUtil.d.ts +0 -400
  93. package/lib/utils/ObjectUtil.js +0 -13
  94. package/lib/utils/index.d.ts +0 -1
  95. package/lib/utils/index.js +0 -13
@@ -1,877 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const fabric_1 = require("fabric");
7
- const animejs_1 = __importDefault(require("animejs"));
8
- /**
9
- * Event Handler Class
10
- * @author salgum1114
11
- * @class EventHandler
12
- */
13
- class EventHandler {
14
- constructor(handler) {
15
- /**
16
- * Detach event on document
17
- *
18
- */
19
- this.destroy = () => {
20
- if (this.handler.editable) {
21
- this.handler.canvas.off({
22
- 'object:modified': this.modified,
23
- 'object:scaling': this.scaling,
24
- 'object:moving': this.moving,
25
- 'object:moved': this.moved,
26
- 'object:rotating': this.rotating,
27
- 'mouse:wheel': this.mousewheel,
28
- 'mouse:down': this.mousedown,
29
- 'mouse:move': this.mousemove,
30
- 'mouse:up': this.mouseup,
31
- 'selection:cleared': this.selection,
32
- 'selection:created': this.selection,
33
- 'selection:updated': this.selection,
34
- });
35
- }
36
- else {
37
- this.handler.canvas.off({
38
- 'mouse:down': this.mousedown,
39
- 'mouse:move': this.mousemove,
40
- 'mouse:out': this.mouseout,
41
- 'mouse:up': this.mouseup,
42
- 'mouse:wheel': this.mousewheel,
43
- });
44
- this.handler.getObjects().forEach(object => {
45
- object.off('mousedown', this.handler.eventHandler.object.mousedown);
46
- if (object.anime) {
47
- animejs_1.default.remove(object);
48
- }
49
- });
50
- }
51
- this.handler.canvas.wrapperEl.removeEventListener('keydown', this.keydown);
52
- this.handler.canvas.wrapperEl.removeEventListener('keyup', this.keyup);
53
- this.handler.canvas.wrapperEl.removeEventListener('mousedown', this.onmousedown);
54
- this.handler.canvas.wrapperEl.removeEventListener('contextmenu', this.contextmenu);
55
- if (this.handler.keyEvent.clipboard) {
56
- this.handler.canvas.wrapperEl.removeEventListener('paste', this.paste);
57
- }
58
- };
59
- /**
60
- * Individual object event
61
- *
62
- */
63
- this.object = {
64
- /**
65
- * Mouse down event on object
66
- * @param {FabricEvent} opt
67
- */
68
- mousedown: (opt) => {
69
- const { target } = opt;
70
- if (target && target.link && target.link.enabled) {
71
- const { onClick } = this.handler;
72
- if (onClick) {
73
- onClick(this.handler.canvas, target);
74
- }
75
- }
76
- },
77
- /**
78
- * Mouse double click event on object
79
- * @param {FabricEvent} opt
80
- */
81
- mousedblclick: (opt) => {
82
- const { target } = opt;
83
- if (target) {
84
- const { onDblClick } = this.handler;
85
- if (onDblClick) {
86
- onDblClick(this.handler.canvas, target);
87
- }
88
- }
89
- },
90
- };
91
- /**
92
- * Modified event object
93
- *
94
- * @param {FabricEvent} opt
95
- * @returns
96
- */
97
- this.modified = (opt) => {
98
- const { target } = opt;
99
- if (!target) {
100
- return;
101
- }
102
- if (target.type === 'circle' && target.parentId) {
103
- return;
104
- }
105
- const { onModified } = this.handler;
106
- if (onModified) {
107
- onModified(target);
108
- }
109
- };
110
- /**
111
- * Moving event object
112
- *
113
- * @param {FabricEvent} opt
114
- * @returns
115
- */
116
- this.moving = (opt) => {
117
- const { target } = opt;
118
- if (this.handler.interactionMode === 'crop') {
119
- this.handler.cropHandler.moving(opt);
120
- }
121
- else {
122
- if (this.handler.editable && this.handler.guidelineOption.enabled) {
123
- this.handler.guidelineHandler.movingGuidelines(target);
124
- }
125
- if (target.type === 'activeSelection') {
126
- const activeSelection = target;
127
- activeSelection.getObjects().forEach((obj) => {
128
- const left = target.left + obj.left + target.width / 2;
129
- const top = target.top + obj.top + target.height / 2;
130
- if (obj.superType === 'node') {
131
- this.handler.portHandler.setCoords({ ...obj, left, top });
132
- }
133
- else if (obj.superType === 'element') {
134
- const { id } = obj;
135
- const el = this.handler.elementHandler.findById(id);
136
- // TODO... Element object incorrect position
137
- this.handler.elementHandler.setPositionByOrigin(el, obj, left, top);
138
- }
139
- });
140
- return;
141
- }
142
- if (target.superType === 'node') {
143
- this.handler.portHandler.setCoords(target);
144
- }
145
- else if (target.superType === 'element') {
146
- const { id } = target;
147
- const el = this.handler.elementHandler.findById(id);
148
- this.handler.elementHandler.setPosition(el, target);
149
- }
150
- }
151
- };
152
- /**
153
- * Moved event object
154
- *
155
- * @param {FabricEvent} opt
156
- */
157
- this.moved = (opt) => {
158
- const { target } = opt;
159
- this.handler.gridHandler.setCoords(target);
160
- if (!this.handler.transactionHandler.active) {
161
- this.handler.transactionHandler.save('moved');
162
- }
163
- if (target.superType === 'element') {
164
- const { id } = target;
165
- const el = this.handler.elementHandler.findById(id);
166
- this.handler.elementHandler.setPosition(el, target);
167
- }
168
- };
169
- /**
170
- * Scaling event object
171
- *
172
- * @param {FabricEvent} opt
173
- */
174
- this.scaling = (opt) => {
175
- const { target } = opt;
176
- if (this.handler.interactionMode === 'crop') {
177
- this.handler.cropHandler.resize(opt);
178
- }
179
- // TODO...this.handler.guidelineHandler.scalingGuidelines(target);
180
- if (target.superType === 'element') {
181
- const { id, width, height } = target;
182
- const el = this.handler.elementHandler.findById(id);
183
- // update the element
184
- this.handler.elementHandler.setScaleOrAngle(el, target);
185
- this.handler.elementHandler.setSize(el, target);
186
- this.handler.elementHandler.setPosition(el, target);
187
- const video = target;
188
- if (video.type === 'video' && video.player) {
189
- video.player.setPlayerSize(width, height);
190
- }
191
- }
192
- };
193
- /**
194
- * Scaled event object
195
- *
196
- * @param {FabricEvent} opt
197
- */
198
- this.scaled = (_opt) => {
199
- if (!this.handler.transactionHandler.active) {
200
- this.handler.transactionHandler.save('scaled');
201
- }
202
- };
203
- /**
204
- * Rotating event object
205
- *
206
- * @param {FabricEvent} opt
207
- */
208
- this.rotating = (opt) => {
209
- const { target } = opt;
210
- if (target.superType === 'element') {
211
- const { id } = target;
212
- const el = this.handler.elementHandler.findById(id);
213
- // update the element
214
- this.handler.elementHandler.setScaleOrAngle(el, target);
215
- }
216
- };
217
- /**
218
- * Rotated event object
219
- *
220
- * @param {FabricEvent} opt
221
- */
222
- this.rotated = (_opt) => {
223
- if (!this.handler.transactionHandler.active) {
224
- this.handler.transactionHandler.save('rotated');
225
- }
226
- };
227
- /**
228
- * Moing object at keyboard arrow key down event
229
- *
230
- * @param {KeyboardEvent} e
231
- * @returns
232
- */
233
- this.arrowmoving = (e) => {
234
- const activeObject = this.handler.canvas.getActiveObject();
235
- if (!activeObject) {
236
- return false;
237
- }
238
- if (activeObject.id === 'workarea') {
239
- return false;
240
- }
241
- if (e.keyCode === 38) {
242
- activeObject.set('top', activeObject.top - 2);
243
- activeObject.setCoords();
244
- this.handler.canvas.renderAll();
245
- return true;
246
- }
247
- else if (e.keyCode === 40) {
248
- activeObject.set('top', activeObject.top + 2);
249
- activeObject.setCoords();
250
- this.handler.canvas.renderAll();
251
- return true;
252
- }
253
- else if (e.keyCode === 37) {
254
- activeObject.set('left', activeObject.left - 2);
255
- activeObject.setCoords();
256
- this.handler.canvas.renderAll();
257
- return true;
258
- }
259
- else if (e.keyCode === 39) {
260
- activeObject.set('left', activeObject.left + 2);
261
- activeObject.setCoords();
262
- this.handler.canvas.renderAll();
263
- return true;
264
- }
265
- if (this.handler.onModified) {
266
- this.handler.onModified(activeObject);
267
- }
268
- return true;
269
- };
270
- /**
271
- * Zoom at mouse wheel event
272
- *
273
- * @param {FabricEvent<WheelEvent>} opt
274
- * @returns
275
- */
276
- this.mousewheel = (opt) => {
277
- const event = opt;
278
- const { zoomEnabled } = this.handler;
279
- if (!zoomEnabled) {
280
- return;
281
- }
282
- const delta = event.e.deltaY;
283
- let zoomRatio = this.handler.canvas.getZoom();
284
- if (delta > 0) {
285
- zoomRatio -= 0.05;
286
- }
287
- else {
288
- zoomRatio += 0.05;
289
- }
290
- this.handler.zoomHandler.zoomToPoint(new fabric_1.fabric.Point(this.handler.canvas.getWidth() / 2, this.handler.canvas.getHeight() / 2), zoomRatio);
291
- event.e.preventDefault();
292
- event.e.stopPropagation();
293
- };
294
- /**
295
- * Mouse down event on object
296
- *
297
- * @param {FabricEvent<MouseEvent>} opt
298
- * @returns
299
- */
300
- this.mousedown = (opt) => {
301
- const event = opt;
302
- const { editable } = this.handler;
303
- if (event.e.altKey && editable && !this.handler.interactionHandler.isDrawingMode()) {
304
- this.handler.interactionHandler.grab();
305
- this.panning = true;
306
- return;
307
- }
308
- if (this.handler.interactionMode === 'grab') {
309
- this.panning = true;
310
- return;
311
- }
312
- const { target } = event;
313
- if (editable) {
314
- if (this.handler.prevTarget && this.handler.prevTarget.superType === 'link') {
315
- this.handler.prevTarget.set({
316
- stroke: this.handler.prevTarget.originStroke,
317
- });
318
- }
319
- if (target && target.type === 'fromPort') {
320
- this.handler.linkHandler.init(target);
321
- return;
322
- }
323
- if (target &&
324
- this.handler.interactionMode === 'link' &&
325
- (target.type === 'toPort' || target.superType === 'node')) {
326
- let toPort;
327
- if (target.superType === 'node') {
328
- toPort = target.toPort;
329
- }
330
- else {
331
- toPort = target;
332
- }
333
- this.handler.linkHandler.generate(toPort);
334
- return;
335
- }
336
- this.handler.guidelineHandler.viewportTransform = this.handler.canvas.viewportTransform;
337
- this.handler.guidelineHandler.zoom = this.handler.canvas.getZoom();
338
- if (this.handler.interactionMode === 'selection') {
339
- if (target && target.superType === 'link') {
340
- target.set({
341
- stroke: target.selectFill || 'green',
342
- });
343
- }
344
- this.handler.prevTarget = target;
345
- return;
346
- }
347
- if (this.handler.interactionMode === 'polygon') {
348
- if (target && this.handler.pointArray.length && target.id === this.handler.pointArray[0].id) {
349
- this.handler.drawingHandler.polygon.generate(this.handler.pointArray);
350
- }
351
- else {
352
- this.handler.drawingHandler.polygon.addPoint(event);
353
- }
354
- }
355
- else if (this.handler.interactionMode === 'line') {
356
- if (this.handler.pointArray.length && this.handler.activeLine) {
357
- this.handler.drawingHandler.line.generate(event);
358
- }
359
- else {
360
- this.handler.drawingHandler.line.addPoint(event);
361
- }
362
- }
363
- else if (this.handler.interactionMode === 'arrow') {
364
- if (this.handler.pointArray.length && this.handler.activeLine) {
365
- this.handler.drawingHandler.arrow.generate(event);
366
- }
367
- else {
368
- this.handler.drawingHandler.arrow.addPoint(event);
369
- }
370
- }
371
- }
372
- };
373
- /**
374
- * Mouse move event on canvas
375
- *
376
- * @param {FabricEvent<MouseEvent>} opt
377
- * @returns
378
- */
379
- this.mousemove = (opt) => {
380
- const event = opt;
381
- if (this.handler.interactionMode === 'grab' && this.panning) {
382
- this.handler.interactionHandler.moving(event.e);
383
- this.handler.canvas.requestRenderAll();
384
- }
385
- if (!this.handler.editable && event.target) {
386
- if (event.target.superType === 'element') {
387
- return;
388
- }
389
- if (event.target.id !== 'workarea') {
390
- if (event.target !== this.handler.target) {
391
- this.handler.tooltipHandler.show(event.target);
392
- }
393
- }
394
- else {
395
- this.handler.tooltipHandler.hide(event.target);
396
- }
397
- }
398
- if (this.handler.interactionMode === 'polygon') {
399
- if (this.handler.activeLine && this.handler.activeLine.class === 'line') {
400
- const pointer = this.handler.canvas.getPointer(event.e);
401
- this.handler.activeLine.set({ x2: pointer.x, y2: pointer.y });
402
- const points = this.handler.activeShape.get('points');
403
- points[this.handler.pointArray.length] = {
404
- x: pointer.x,
405
- y: pointer.y,
406
- };
407
- this.handler.activeShape.set({
408
- points,
409
- });
410
- this.handler.canvas.requestRenderAll();
411
- }
412
- }
413
- else if (this.handler.interactionMode === 'line') {
414
- if (this.handler.activeLine && this.handler.activeLine.class === 'line') {
415
- const pointer = this.handler.canvas.getPointer(event.e);
416
- this.handler.activeLine.set({ x2: pointer.x, y2: pointer.y });
417
- }
418
- this.handler.canvas.requestRenderAll();
419
- }
420
- else if (this.handler.interactionMode === 'arrow') {
421
- if (this.handler.activeLine && this.handler.activeLine.class === 'line') {
422
- const pointer = this.handler.canvas.getPointer(event.e);
423
- this.handler.activeLine.set({ x2: pointer.x, y2: pointer.y });
424
- }
425
- this.handler.canvas.requestRenderAll();
426
- }
427
- else if (this.handler.interactionMode === 'link') {
428
- if (this.handler.activeLine && this.handler.activeLine.class === 'line') {
429
- const pointer = this.handler.canvas.getPointer(event.e);
430
- this.handler.activeLine.set({ x2: pointer.x, y2: pointer.y });
431
- }
432
- this.handler.canvas.requestRenderAll();
433
- }
434
- return;
435
- };
436
- /**
437
- * Mouse up event on canvas
438
- *
439
- * @param {FabricEvent<MouseEvent>} opt
440
- * @returns
441
- */
442
- this.mouseup = (opt) => {
443
- const event = opt;
444
- if (this.handler.interactionMode === 'grab') {
445
- this.panning = false;
446
- return;
447
- }
448
- const { target, e } = event;
449
- if (this.handler.interactionMode === 'selection') {
450
- if (target && e.shiftKey && target.superType === 'node') {
451
- const node = target;
452
- this.handler.canvas.discardActiveObject();
453
- const nodes = [];
454
- this.handler.nodeHandler.getNodePath(node, nodes);
455
- const activeSelection = new fabric_1.fabric.ActiveSelection(nodes, {
456
- canvas: this.handler.canvas,
457
- ...this.handler.activeSelectionOption,
458
- });
459
- this.handler.canvas.setActiveObject(activeSelection);
460
- this.handler.canvas.requestRenderAll();
461
- }
462
- }
463
- if (this.handler.editable && this.handler.guidelineOption.enabled) {
464
- this.handler.guidelineHandler.verticalLines.length = 0;
465
- this.handler.guidelineHandler.horizontalLines.length = 0;
466
- }
467
- this.handler.canvas.renderAll();
468
- };
469
- /**
470
- * Mouse out event on canvas
471
- *
472
- * @param {FabricEvent<MouseEvent>} opt
473
- */
474
- this.mouseout = (opt) => {
475
- const event = opt;
476
- if (!event.target) {
477
- this.handler.tooltipHandler.hide();
478
- }
479
- };
480
- /**
481
- * Selection event event on canvas
482
- *
483
- * @param {FabricEvent} opt
484
- */
485
- this.selection = (opt) => {
486
- const { onSelect, activeSelectionOption } = this.handler;
487
- const target = opt.target;
488
- if (target && target.type === 'activeSelection') {
489
- target.set({
490
- ...activeSelectionOption,
491
- });
492
- }
493
- if (onSelect) {
494
- onSelect(target);
495
- }
496
- };
497
- /**
498
- * Called resize event on canvas
499
- *
500
- * @param {number} nextWidth
501
- * @param {number} nextHeight
502
- * @returns
503
- */
504
- this.resize = (nextWidth, nextHeight) => {
505
- this.handler.canvas.setWidth(nextWidth).setHeight(nextHeight);
506
- this.handler.canvas.setBackgroundColor(this.handler.canvasOption.backgroundColor, this.handler.canvas.renderAll.bind(this.handler.canvas));
507
- if (!this.handler.workarea) {
508
- return;
509
- }
510
- const diffWidth = nextWidth / 2 - this.handler.width / 2;
511
- const diffHeight = nextHeight / 2 - this.handler.height / 2;
512
- this.handler.width = nextWidth;
513
- this.handler.height = nextHeight;
514
- if (this.handler.workarea.layout === 'fixed') {
515
- this.handler.canvas.centerObject(this.handler.workarea);
516
- this.handler.workarea.setCoords();
517
- if (this.handler.gridOption.enabled) {
518
- return;
519
- }
520
- this.handler.canvas.getObjects().forEach((obj) => {
521
- if (obj.id !== 'workarea') {
522
- const left = obj.left + diffWidth;
523
- const top = obj.top + diffHeight;
524
- obj.set({
525
- left,
526
- top,
527
- });
528
- obj.setCoords();
529
- if (obj.superType === 'element') {
530
- const { id } = obj;
531
- const el = this.handler.elementHandler.findById(id);
532
- // update the element
533
- this.handler.elementHandler.setPosition(el, obj);
534
- }
535
- }
536
- });
537
- this.handler.canvas.requestRenderAll();
538
- return;
539
- }
540
- if (this.handler.workarea.layout === 'responsive') {
541
- const { scaleX } = this.handler.workareaHandler.calculateScale();
542
- const center = this.handler.canvas.getCenter();
543
- const deltaPoint = new fabric_1.fabric.Point(diffWidth, diffHeight);
544
- this.handler.canvas.relativePan(deltaPoint);
545
- this.handler.zoomHandler.zoomToPoint(new fabric_1.fabric.Point(center.left, center.top), scaleX);
546
- return;
547
- }
548
- const scaleX = nextWidth / this.handler.workarea.width;
549
- const scaleY = nextHeight / this.handler.workarea.height;
550
- const diffScaleX = nextWidth / (this.handler.workarea.width * this.handler.workarea.scaleX);
551
- const diffScaleY = nextHeight / (this.handler.workarea.height * this.handler.workarea.scaleY);
552
- this.handler.workarea.set({
553
- scaleX,
554
- scaleY,
555
- });
556
- this.handler.canvas.getObjects().forEach((obj) => {
557
- const { id } = obj;
558
- if (obj.id !== 'workarea') {
559
- const left = obj.left * diffScaleX;
560
- const top = obj.top * diffScaleY;
561
- const newScaleX = obj.scaleX * diffScaleX;
562
- const newScaleY = obj.scaleY * diffScaleY;
563
- obj.set({
564
- scaleX: newScaleX,
565
- scaleY: newScaleY,
566
- left,
567
- top,
568
- });
569
- obj.setCoords();
570
- if (obj.superType === 'element') {
571
- const video = obj;
572
- const { width, height } = obj;
573
- const el = this.handler.elementHandler.findById(id);
574
- this.handler.elementHandler.setSize(el, obj);
575
- if (video.player) {
576
- video.player.setPlayerSize(width, height);
577
- }
578
- this.handler.elementHandler.setPosition(el, obj);
579
- }
580
- }
581
- });
582
- this.handler.canvas.renderAll();
583
- };
584
- /**
585
- * Paste event on canvas
586
- *
587
- * @param {ClipboardEvent} e
588
- * @returns
589
- */
590
- this.paste = (e) => {
591
- if (this.handler.canvas.wrapperEl !== document.activeElement) {
592
- return false;
593
- }
594
- if (e.preventDefault) {
595
- e.preventDefault();
596
- }
597
- if (e.stopPropagation) {
598
- e.stopPropagation();
599
- }
600
- const clipboardData = e.clipboardData;
601
- if (clipboardData.types.length) {
602
- clipboardData.types.forEach((clipboardType) => {
603
- if (clipboardType === 'text/plain') {
604
- const textPlain = clipboardData.getData('text/plain');
605
- try {
606
- const objects = JSON.parse(textPlain);
607
- const { gridOption: { grid = 10 }, isCut, } = this.handler;
608
- const padding = isCut ? 0 : grid;
609
- if (objects && Array.isArray(objects)) {
610
- const filteredObjects = objects.filter(obj => obj !== null);
611
- if (filteredObjects.length === 1) {
612
- const obj = filteredObjects[0];
613
- if (typeof obj.cloneable !== 'undefined' && !obj.cloneable) {
614
- return;
615
- }
616
- obj.left = obj.properties.left + padding;
617
- obj.top = obj.properties.top + padding;
618
- const createdObj = this.handler.add(obj, false, true);
619
- this.handler.canvas.setActiveObject(createdObj);
620
- this.handler.canvas.requestRenderAll();
621
- }
622
- else {
623
- const nodes = [];
624
- const targets = [];
625
- objects.forEach(obj => {
626
- if (!obj) {
627
- return;
628
- }
629
- if (obj.superType === 'link') {
630
- obj.fromNodeId = nodes[obj.fromNodeIndex].id;
631
- obj.toNodeId = nodes[obj.toNodeIndex].id;
632
- }
633
- else {
634
- obj.left = obj.properties.left + padding;
635
- obj.top = obj.properties.top + padding;
636
- }
637
- const createdObj = this.handler.add(obj, false, true);
638
- if (obj.superType === 'node') {
639
- nodes.push(createdObj);
640
- }
641
- else {
642
- targets.push(createdObj);
643
- }
644
- });
645
- const activeSelection = new fabric_1.fabric.ActiveSelection(nodes.length ? nodes : targets, {
646
- canvas: this.handler.canvas,
647
- ...this.handler.activeSelectionOption,
648
- });
649
- this.handler.canvas.setActiveObject(activeSelection);
650
- this.handler.canvas.requestRenderAll();
651
- }
652
- if (!this.handler.transactionHandler.active) {
653
- this.handler.transactionHandler.save('paste');
654
- }
655
- this.handler.isCut = false;
656
- this.handler.copy();
657
- }
658
- }
659
- catch (error) {
660
- console.error(error);
661
- // const item = {
662
- // id: uuv4id(),
663
- // type: 'textbox',
664
- // text: textPlain,
665
- // };
666
- // this.handler.add(item, true);
667
- }
668
- }
669
- else if (clipboardType === 'text/html') {
670
- // Todo ...
671
- // const textHtml = clipboardData.getData('text/html');
672
- // console.log(textHtml);
673
- }
674
- else if (clipboardType === 'Files') {
675
- // Array.from(clipboardData.files).forEach((file) => {
676
- // const { type } = file;
677
- // if (type === 'image/png' || type === 'image/jpeg' || type === 'image/jpg') {
678
- // const item = {
679
- // id: v4(),
680
- // type: 'image',
681
- // file,
682
- // superType: 'image',
683
- // };
684
- // this.handler.add(item, true);
685
- // } else {
686
- // console.error('Not supported file type');
687
- // }
688
- // });
689
- }
690
- });
691
- }
692
- return true;
693
- };
694
- /**
695
- * Keydown event on document
696
- *
697
- * @param {KeyboardEvent} e
698
- */
699
- this.keydown = (e) => {
700
- const { keyEvent, editable } = this.handler;
701
- if (!Object.keys(keyEvent).length) {
702
- return;
703
- }
704
- const { clipboard } = keyEvent;
705
- if (this.handler.interactionHandler.isDrawingMode()) {
706
- if (this.handler.shortcutHandler.isEscape(e)) {
707
- if (this.handler.interactionMode === 'polygon') {
708
- this.handler.drawingHandler.polygon.finish();
709
- }
710
- else if (this.handler.interactionMode === 'line') {
711
- this.handler.drawingHandler.line.finish();
712
- }
713
- else if (this.handler.interactionMode === 'arrow') {
714
- this.handler.drawingHandler.arrow.finish();
715
- }
716
- else if (this.handler.interactionMode === 'link') {
717
- this.handler.linkHandler.finish();
718
- }
719
- }
720
- return;
721
- }
722
- if (this.handler.shortcutHandler.isW(e)) {
723
- this.keyCode = e.keyCode;
724
- this.handler.interactionHandler.grab();
725
- return;
726
- }
727
- if (e.altKey && editable) {
728
- this.handler.interactionHandler.grab();
729
- return;
730
- }
731
- if (this.handler.shortcutHandler.isEscape(e)) {
732
- if (this.handler.interactionMode === 'selection') {
733
- this.handler.canvas.discardActiveObject();
734
- this.handler.canvas.renderAll();
735
- }
736
- this.handler.tooltipHandler.hide();
737
- }
738
- if (this.handler.canvas.wrapperEl !== document.activeElement) {
739
- return;
740
- }
741
- if (editable) {
742
- if (this.handler.shortcutHandler.isQ(e)) {
743
- this.keyCode = e.keyCode;
744
- }
745
- else if (this.handler.shortcutHandler.isDelete(e)) {
746
- this.handler.remove();
747
- }
748
- else if (this.handler.shortcutHandler.isArrow(e)) {
749
- this.arrowmoving(e);
750
- }
751
- else if (this.handler.shortcutHandler.isCtrlA(e)) {
752
- e.preventDefault();
753
- this.handler.selectAll();
754
- }
755
- else if (this.handler.shortcutHandler.isCtrlC(e)) {
756
- e.preventDefault();
757
- this.handler.copy();
758
- }
759
- else if (this.handler.shortcutHandler.isCtrlV(e) && !clipboard) {
760
- e.preventDefault();
761
- this.handler.paste();
762
- }
763
- else if (this.handler.shortcutHandler.isCtrlX(e)) {
764
- e.preventDefault();
765
- this.handler.cut();
766
- }
767
- else if (this.handler.shortcutHandler.isCtrlZ(e)) {
768
- e.preventDefault();
769
- this.handler.transactionHandler.undo();
770
- }
771
- else if (this.handler.shortcutHandler.isCtrlY(e)) {
772
- e.preventDefault();
773
- this.handler.transactionHandler.redo();
774
- }
775
- else if (this.handler.shortcutHandler.isPlus(e)) {
776
- e.preventDefault();
777
- this.handler.zoomHandler.zoomIn();
778
- }
779
- else if (this.handler.shortcutHandler.isMinus(e)) {
780
- e.preventDefault();
781
- this.handler.zoomHandler.zoomOut();
782
- }
783
- else if (this.handler.shortcutHandler.isO(e)) {
784
- e.preventDefault();
785
- this.handler.zoomHandler.zoomOneToOne();
786
- }
787
- else if (this.handler.shortcutHandler.isP(e)) {
788
- e.preventDefault();
789
- this.handler.zoomHandler.zoomToFit();
790
- }
791
- return;
792
- }
793
- return;
794
- };
795
- /**
796
- * Key up event on canvas
797
- *
798
- * @param {KeyboardEvent} _e
799
- */
800
- this.keyup = (e) => {
801
- if (this.handler.interactionHandler.isDrawingMode()) {
802
- return;
803
- }
804
- if (!this.handler.shortcutHandler.isW(e)) {
805
- this.handler.interactionHandler.selection();
806
- }
807
- };
808
- /**
809
- * Context menu event on canvas
810
- *
811
- * @param {MouseEvent} e
812
- */
813
- this.contextmenu = (e) => {
814
- e.preventDefault();
815
- const { editable, onContext } = this.handler;
816
- if (editable && onContext) {
817
- const target = this.handler.canvas.findTarget(e, false);
818
- if (target && target.type !== 'activeSelection') {
819
- this.handler.select(target);
820
- }
821
- this.handler.contextmenuHandler.show(e, target);
822
- }
823
- };
824
- /**
825
- * Mouse down event on canvas
826
- *
827
- * @param {MouseEvent} _e
828
- */
829
- this.onmousedown = (_e) => {
830
- this.handler.contextmenuHandler.hide();
831
- };
832
- this.handler = handler;
833
- this.initialize();
834
- }
835
- /**
836
- * Attch event on document
837
- *
838
- */
839
- initialize() {
840
- if (this.handler.editable) {
841
- this.handler.canvas.on({
842
- 'object:modified': this.modified,
843
- 'object:scaling': this.scaling,
844
- 'object:scaled': this.scaled,
845
- 'object:moving': this.moving,
846
- 'object:moved': this.moved,
847
- 'object:rotating': this.rotating,
848
- 'object:rotated': this.rotated,
849
- 'mouse:wheel': this.mousewheel,
850
- 'mouse:down': this.mousedown,
851
- 'mouse:move': this.mousemove,
852
- 'mouse:up': this.mouseup,
853
- 'selection:cleared': this.selection,
854
- 'selection:created': this.selection,
855
- 'selection:updated': this.selection,
856
- });
857
- }
858
- else {
859
- this.handler.canvas.on({
860
- 'mouse:down': this.mousedown,
861
- 'mouse:move': this.mousemove,
862
- 'mouse:out': this.mouseout,
863
- 'mouse:up': this.mouseup,
864
- 'mouse:wheel': this.mousewheel,
865
- });
866
- }
867
- this.handler.canvas.wrapperEl.tabIndex = 1000;
868
- this.handler.canvas.wrapperEl.addEventListener('keydown', this.keydown, false);
869
- this.handler.canvas.wrapperEl.addEventListener('keyup', this.keyup, false);
870
- this.handler.canvas.wrapperEl.addEventListener('mousedown', this.onmousedown, false);
871
- this.handler.canvas.wrapperEl.addEventListener('contextmenu', this.contextmenu, false);
872
- if (this.handler.keyEvent.clipboard) {
873
- document.addEventListener('paste', this.paste, false);
874
- }
875
- }
876
- }
877
- exports.default = EventHandler;