react-design-editor 0.0.37 → 0.0.41

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 (99) hide show
  1. package/dist/react-design-editor.js +773 -726
  2. package/dist/react-design-editor.min.js +1 -1
  3. package/lib/Canvas.d.ts +18 -0
  4. package/lib/Canvas.js +172 -0
  5. package/lib/CanvasObject.d.ts +10 -0
  6. package/lib/CanvasObject.js +96 -0
  7. package/lib/constants/code.d.ts +19 -0
  8. package/lib/constants/code.js +22 -0
  9. package/lib/constants/defaults.d.ts +38 -0
  10. package/lib/constants/defaults.js +69 -0
  11. package/lib/constants/index.d.ts +3 -0
  12. package/lib/constants/index.js +26 -0
  13. package/lib/handlers/AlignmentHandler.d.ts +18 -0
  14. package/lib/handlers/AlignmentHandler.js +58 -0
  15. package/lib/handlers/AnimationHandler.d.ts +50 -0
  16. package/lib/handlers/AnimationHandler.js +323 -0
  17. package/lib/handlers/ChartHandler.d.ts +8 -0
  18. package/lib/handlers/ChartHandler.js +8 -0
  19. package/lib/handlers/ContextmenuHandler.d.ts +28 -0
  20. package/lib/handlers/ContextmenuHandler.js +65 -0
  21. package/lib/handlers/CropHandler.d.ts +43 -0
  22. package/lib/handlers/CropHandler.js +261 -0
  23. package/lib/handlers/CustomHandler.d.ts +7 -0
  24. package/lib/handlers/CustomHandler.js +10 -0
  25. package/lib/handlers/DrawingHandler.d.ts +28 -0
  26. package/lib/handlers/DrawingHandler.js +318 -0
  27. package/lib/handlers/ElementHandler.d.ts +80 -0
  28. package/lib/handlers/ElementHandler.js +154 -0
  29. package/lib/handlers/EventHandler.d.ts +170 -0
  30. package/lib/handlers/EventHandler.js +880 -0
  31. package/lib/handlers/FiberHandler.d.ts +6 -0
  32. package/lib/handlers/FiberHandler.js +23 -0
  33. package/lib/handlers/GridHandler.d.ts +19 -0
  34. package/lib/handlers/GridHandler.js +77 -0
  35. package/lib/handlers/GuidelineHandler.d.ts +61 -0
  36. package/lib/handlers/GuidelineHandler.js +315 -0
  37. package/lib/handlers/Handler.d.ts +622 -0
  38. package/lib/handlers/Handler.js +1640 -0
  39. package/lib/handlers/ImageHandler.d.ts +307 -0
  40. package/lib/handlers/ImageHandler.js +529 -0
  41. package/lib/handlers/InteractionHandler.d.ts +45 -0
  42. package/lib/handlers/InteractionHandler.js +164 -0
  43. package/lib/handlers/LinkHandler.d.ts +115 -0
  44. package/lib/handlers/LinkHandler.js +247 -0
  45. package/lib/handlers/NodeHandler.d.ts +50 -0
  46. package/lib/handlers/NodeHandler.js +274 -0
  47. package/lib/handlers/PortHandler.d.ts +22 -0
  48. package/lib/handlers/PortHandler.js +179 -0
  49. package/lib/handlers/ShortcutHandler.d.ts +119 -0
  50. package/lib/handlers/ShortcutHandler.js +151 -0
  51. package/lib/handlers/TooltipHandler.d.ts +33 -0
  52. package/lib/handlers/TooltipHandler.js +91 -0
  53. package/lib/handlers/TransactionHandler.d.ts +59 -0
  54. package/lib/handlers/TransactionHandler.js +137 -0
  55. package/lib/handlers/WorkareaHandler.d.ts +43 -0
  56. package/lib/handlers/WorkareaHandler.js +354 -0
  57. package/lib/handlers/ZoomHandler.d.ts +48 -0
  58. package/lib/handlers/ZoomHandler.js +143 -0
  59. package/lib/handlers/index.d.ts +23 -0
  60. package/lib/handlers/index.js +48 -0
  61. package/lib/index.d.ts +6 -0
  62. package/lib/index.js +20 -0
  63. package/lib/objects/Arrow.d.ts +2 -0
  64. package/lib/objects/Arrow.js +40 -0
  65. package/lib/objects/Chart.d.ts +10 -0
  66. package/lib/objects/Chart.js +124 -0
  67. package/lib/objects/CirclePort.d.ts +2 -0
  68. package/lib/objects/CirclePort.js +28 -0
  69. package/lib/objects/Cube.d.ts +5 -0
  70. package/lib/objects/Cube.js +71 -0
  71. package/lib/objects/CurvedLink.d.ts +2 -0
  72. package/lib/objects/CurvedLink.js +51 -0
  73. package/lib/objects/Element.d.ts +13 -0
  74. package/lib/objects/Element.js +84 -0
  75. package/lib/objects/Gif.d.ts +3 -0
  76. package/lib/objects/Gif.js +41 -0
  77. package/lib/objects/Iframe.d.ts +9 -0
  78. package/lib/objects/Iframe.js +70 -0
  79. package/lib/objects/Line.d.ts +2 -0
  80. package/lib/objects/Line.js +24 -0
  81. package/lib/objects/Link.d.ts +15 -0
  82. package/lib/objects/Link.js +106 -0
  83. package/lib/objects/Node.d.ts +59 -0
  84. package/lib/objects/Node.js +271 -0
  85. package/lib/objects/OrthogonalLink.d.ts +2 -0
  86. package/lib/objects/OrthogonalLink.js +54 -0
  87. package/lib/objects/Port.d.ts +12 -0
  88. package/lib/objects/Port.js +28 -0
  89. package/lib/objects/Svg.d.ts +8 -0
  90. package/lib/objects/Svg.js +77 -0
  91. package/lib/objects/Video.d.ts +14 -0
  92. package/lib/objects/Video.js +120 -0
  93. package/lib/objects/index.d.ts +15 -0
  94. package/lib/objects/index.js +32 -0
  95. package/lib/utils/ObjectUtil.d.ts +407 -0
  96. package/lib/utils/ObjectUtil.js +13 -0
  97. package/lib/utils/index.d.ts +1 -0
  98. package/lib/utils/index.js +13 -0
  99. package/package.json +1 -1
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
4
+ /**
5
+ * Shortcut Handler Class
6
+ *
7
+ * @author salgum1114
8
+ * @class ShortcutHandler
9
+ */
10
+ class ShortcutHandler {
11
+ constructor(handler) {
12
+ /**
13
+ * Whether keydown Escape
14
+ *
15
+ * @param {KeyboardEvent} e
16
+ * @returns
17
+ */
18
+ this.isEscape = (e) => {
19
+ return e.code === constants_1.code.ESCAPE && this.keyEvent.esc;
20
+ };
21
+ /**
22
+ * Whether keydown Q
23
+ *
24
+ * @param {KeyboardEvent} e
25
+ * @returns
26
+ */
27
+ this.isQ = (e) => {
28
+ return e.code === constants_1.code.KEY_Q;
29
+ };
30
+ /**
31
+ * Whether keydown W
32
+ *
33
+ * @param {KeyboardEvent} e
34
+ * @returns
35
+ */
36
+ this.isW = (e) => {
37
+ return e.code === constants_1.code.KEY_W;
38
+ };
39
+ /**
40
+ * Whether keydown Delete or Backpsace
41
+ *
42
+ * @param {KeyboardEvent} e
43
+ * @returns
44
+ */
45
+ this.isDelete = (e) => {
46
+ return (e.code === constants_1.code.BACKSPACE || e.code === constants_1.code.DELETE) && this.keyEvent.del;
47
+ };
48
+ /**
49
+ * Whether keydown Arrow
50
+ *
51
+ * @param {KeyboardEvent} e
52
+ * @returns
53
+ */
54
+ this.isArrow = (e) => {
55
+ return e.code.includes('Arrow') && this.keyEvent.move;
56
+ };
57
+ /**
58
+ * Whether keydown Ctrl + A
59
+ *
60
+ * @param {KeyboardEvent} e
61
+ * @returns
62
+ */
63
+ this.isCtrlA = (e) => {
64
+ return (e.ctrlKey || e.metaKey) && e.code === constants_1.code.KEY_A && this.keyEvent.all;
65
+ };
66
+ /**
67
+ * Whether keydown Ctrl + C
68
+ *
69
+ * @param {KeyboardEvent} e
70
+ * @returns
71
+ */
72
+ this.isCtrlC = (e) => {
73
+ return (e.ctrlKey || e.metaKey) && e.code === constants_1.code.KEY_C && this.keyEvent.copy;
74
+ };
75
+ /**
76
+ * Whether keydown Ctrl + V
77
+ *
78
+ * @param {KeyboardEvent} e
79
+ * @returns
80
+ */
81
+ this.isCtrlV = (e) => {
82
+ return (e.ctrlKey || e.metaKey) && e.code === constants_1.code.KEY_V && this.keyEvent.paste;
83
+ };
84
+ /**
85
+ * Whether keydown Ctrl + Z
86
+ *
87
+ * @param {KeyboardEvent} e
88
+ * @returns
89
+ */
90
+ this.isCtrlZ = (e) => {
91
+ return (e.ctrlKey || e.metaKey) && e.code === constants_1.code.KEY_Z && this.keyEvent.transaction;
92
+ };
93
+ /**
94
+ * Whether keydown Ctrl + Y
95
+ *
96
+ * @param {KeyboardEvent} e
97
+ * @returns
98
+ */
99
+ this.isCtrlY = (e) => {
100
+ return (e.ctrlKey || e.metaKey) && e.code === constants_1.code.KEY_Y && this.keyEvent.transaction;
101
+ };
102
+ /**
103
+ * Whether keydown Plus Or Equal
104
+ *
105
+ * @param {KeyboardEvent} e
106
+ * @returns
107
+ */
108
+ this.isPlus = (e) => {
109
+ return e.code === constants_1.code.EQUAL && this.keyEvent.zoom;
110
+ };
111
+ /**
112
+ * Whether keydown Minus
113
+ *
114
+ * @param {KeyboardEvent} e
115
+ * @returns
116
+ */
117
+ this.isMinus = (e) => {
118
+ return e.code === constants_1.code.MINUS && this.keyEvent.zoom;
119
+ };
120
+ /**
121
+ * Whether keydown O
122
+ *
123
+ * @param {KeyboardEvent} e
124
+ * @returns
125
+ */
126
+ this.isO = (e) => {
127
+ return e.code === constants_1.code.KEY_O && this.keyEvent.zoom;
128
+ };
129
+ /**
130
+ * Whether keydown P
131
+ *
132
+ * @param {KeyboardEvent} e
133
+ * @returns
134
+ */
135
+ this.isP = (e) => {
136
+ return e.code === constants_1.code.KEY_P && this.keyEvent.zoom;
137
+ };
138
+ /**
139
+ * Whether keydown Ctrl + X
140
+ *
141
+ * @param {KeyboardEvent} e
142
+ * @returns
143
+ */
144
+ this.isCtrlX = (e) => {
145
+ return (e.ctrlKey || e.metaKey) && e.code === constants_1.code.KEY_X && this.keyEvent.cut;
146
+ };
147
+ this.handler = handler;
148
+ this.keyEvent = handler.keyEvent;
149
+ }
150
+ }
151
+ exports.default = ShortcutHandler;
@@ -0,0 +1,33 @@
1
+ /// <reference types="lodash" />
2
+ import Handler from './Handler';
3
+ import { FabricObject } from '../utils';
4
+ declare class TooltipHandler {
5
+ handler: Handler;
6
+ tooltipEl: HTMLDivElement;
7
+ target?: fabric.Object;
8
+ constructor(handler: Handler);
9
+ /**
10
+ * Initialize tooltip
11
+ *
12
+ * @author salgum1114
13
+ */
14
+ initialize(): void;
15
+ /**
16
+ * Destroy tooltip
17
+ *
18
+ * @author salgum1114
19
+ */
20
+ destroy(): void;
21
+ /**
22
+ * Show tooltip
23
+ *
24
+ * @param {FabricObject} [target]
25
+ */
26
+ show: import("lodash").DebouncedFunc<(target?: FabricObject) => Promise<void>>;
27
+ /**
28
+ * Hide tooltip
29
+ * @param {fabric.Object} [_target]
30
+ */
31
+ hide: import("lodash").DebouncedFunc<(_target?: fabric.Object) => void>;
32
+ }
33
+ export default TooltipHandler;
@@ -0,0 +1,91 @@
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 react_dom_1 = __importDefault(require("react-dom"));
7
+ const debounce_1 = __importDefault(require("lodash/debounce"));
8
+ class TooltipHandler {
9
+ constructor(handler) {
10
+ /**
11
+ * Show tooltip
12
+ *
13
+ * @param {FabricObject} [target]
14
+ */
15
+ this.show = debounce_1.default(async (target) => {
16
+ if (target.tooltip && target.tooltip.enabled) {
17
+ while (this.tooltipEl.hasChildNodes()) {
18
+ this.tooltipEl.removeChild(this.tooltipEl.firstChild);
19
+ }
20
+ const tooltip = document.createElement('div');
21
+ tooltip.className = 'rde-tooltip-right';
22
+ let element = target.name;
23
+ const { onTooltip } = this.handler;
24
+ if (onTooltip) {
25
+ element = await onTooltip(this.tooltipEl, target);
26
+ if (!element) {
27
+ return;
28
+ }
29
+ }
30
+ tooltip.innerHTML = element;
31
+ this.tooltipEl.appendChild(tooltip);
32
+ react_dom_1.default.render(element, tooltip);
33
+ this.tooltipEl.classList.remove('tooltip-hidden');
34
+ const zoom = this.handler.canvas.getZoom();
35
+ const { clientHeight } = this.tooltipEl;
36
+ const { width, height, scaleX, scaleY } = target;
37
+ const { left, top } = target.getBoundingRect();
38
+ const { _offset: offset } = this.handler.canvas.calcOffset();
39
+ const objWidthDiff = width * scaleX * zoom;
40
+ const objHeightDiff = (height * scaleY * zoom) / 2 - clientHeight / 2;
41
+ const calcLeft = offset.left + left + objWidthDiff;
42
+ const calcTop = offset.top + top + objHeightDiff;
43
+ if (document.body.clientWidth <= calcLeft + this.tooltipEl.offsetWidth) {
44
+ this.tooltipEl.style.left = `${left + offset.left - this.tooltipEl.offsetWidth}px`;
45
+ tooltip.className = 'rde-tooltip-left';
46
+ }
47
+ else {
48
+ this.tooltipEl.style.left = `${calcLeft}px`;
49
+ }
50
+ this.tooltipEl.style.top = `${calcTop}px`;
51
+ this.handler.target = target;
52
+ }
53
+ }, 100);
54
+ /**
55
+ * Hide tooltip
56
+ * @param {fabric.Object} [_target]
57
+ */
58
+ this.hide = debounce_1.default((_target) => {
59
+ this.handler.target = null;
60
+ if (this.tooltipEl) {
61
+ this.tooltipEl.classList.add('tooltip-hidden');
62
+ }
63
+ }, 100);
64
+ this.handler = handler;
65
+ if (!handler.editable) {
66
+ this.initialize();
67
+ }
68
+ }
69
+ /**
70
+ * Initialize tooltip
71
+ *
72
+ * @author salgum1114
73
+ */
74
+ initialize() {
75
+ this.tooltipEl = document.createElement('div');
76
+ this.tooltipEl.id = `${this.handler.id}_tooltip`;
77
+ this.tooltipEl.className = 'rde-tooltip tooltip-hidden';
78
+ document.body.appendChild(this.tooltipEl);
79
+ }
80
+ /**
81
+ * Destroy tooltip
82
+ *
83
+ * @author salgum1114
84
+ */
85
+ destroy() {
86
+ if (this.tooltipEl) {
87
+ document.body.removeChild(this.tooltipEl);
88
+ }
89
+ }
90
+ }
91
+ exports.default = TooltipHandler;
@@ -0,0 +1,59 @@
1
+ /// <reference types="lodash" />
2
+ import Handler from './Handler';
3
+ import { FabricObject } from '../utils';
4
+ export declare type TransactionType = 'add' | 'remove' | 'moved' | 'scaled' | 'rotated' | 'skewed' | 'group' | 'ungroup' | 'paste' | 'bringForward' | 'bringToFront' | 'sendBackwards' | 'sendToBack' | 'redo' | 'undo';
5
+ export interface TransactionTransform {
6
+ scaleX?: number;
7
+ scaleY?: number;
8
+ skewX?: number;
9
+ skewY?: number;
10
+ angle?: number;
11
+ left?: number;
12
+ top?: number;
13
+ flipX?: number;
14
+ flipY?: number;
15
+ originX?: string;
16
+ originY?: string;
17
+ }
18
+ export interface TransactionEvent {
19
+ json: string;
20
+ type: TransactionType;
21
+ }
22
+ declare class TransactionHandler {
23
+ handler: Handler;
24
+ redos: TransactionEvent[];
25
+ undos: TransactionEvent[];
26
+ active: boolean;
27
+ state: FabricObject[];
28
+ constructor(handler: Handler);
29
+ /**
30
+ * Initialize transaction handler
31
+ *
32
+ */
33
+ initialize: () => void;
34
+ /**
35
+ * Save transaction
36
+ *
37
+ * @param {TransactionType} type
38
+ * @param {*} [canvasJSON]
39
+ * @param {boolean} [isWorkarea=true]
40
+ */
41
+ save: (type: TransactionType, canvasJSON?: any, _isWorkarea?: boolean) => void;
42
+ /**
43
+ * Undo transaction
44
+ *
45
+ */
46
+ undo: import("lodash").DebouncedFunc<() => void>;
47
+ /**
48
+ * Redo transaction
49
+ *
50
+ */
51
+ redo: import("lodash").DebouncedFunc<() => void>;
52
+ /**
53
+ * Replay transaction
54
+ *
55
+ * @param {TransactionEvent} transaction
56
+ */
57
+ replay: (transaction: TransactionEvent) => void;
58
+ }
59
+ export default TransactionHandler;
@@ -0,0 +1,137 @@
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 throttle_1 = __importDefault(require("lodash/throttle"));
8
+ class TransactionHandler {
9
+ constructor(handler) {
10
+ this.active = false;
11
+ this.state = [];
12
+ /**
13
+ * Initialize transaction handler
14
+ *
15
+ */
16
+ this.initialize = () => {
17
+ this.redos = [];
18
+ this.undos = [];
19
+ this.state = [];
20
+ this.active = false;
21
+ };
22
+ /**
23
+ * Save transaction
24
+ *
25
+ * @param {TransactionType} type
26
+ * @param {*} [canvasJSON]
27
+ * @param {boolean} [isWorkarea=true]
28
+ */
29
+ this.save = (type, canvasJSON, _isWorkarea = true) => {
30
+ if (!this.handler.keyEvent.transaction) {
31
+ return;
32
+ }
33
+ try {
34
+ if (this.state) {
35
+ const json = JSON.stringify(this.state);
36
+ this.redos = [];
37
+ this.undos.push({
38
+ type,
39
+ json,
40
+ });
41
+ }
42
+ const { objects } = canvasJSON || this.handler.canvas.toJSON(this.handler.propertiesToInclude);
43
+ this.state = objects.filter(obj => {
44
+ if (obj.id === 'workarea') {
45
+ return false;
46
+ }
47
+ else if (obj.id === 'grid') {
48
+ return false;
49
+ }
50
+ else if (obj.superType === 'port') {
51
+ return false;
52
+ }
53
+ return true;
54
+ });
55
+ }
56
+ catch (error) {
57
+ console.error(error);
58
+ }
59
+ };
60
+ /**
61
+ * Undo transaction
62
+ *
63
+ */
64
+ this.undo = throttle_1.default(() => {
65
+ const undo = this.undos.pop();
66
+ if (!undo) {
67
+ return;
68
+ }
69
+ this.redos.push({
70
+ type: 'redo',
71
+ json: JSON.stringify(this.state),
72
+ });
73
+ this.replay(undo);
74
+ }, 100);
75
+ /**
76
+ * Redo transaction
77
+ *
78
+ */
79
+ this.redo = throttle_1.default(() => {
80
+ const redo = this.redos.pop();
81
+ if (!redo) {
82
+ return;
83
+ }
84
+ this.undos.push({
85
+ type: 'undo',
86
+ json: JSON.stringify(this.state),
87
+ });
88
+ this.replay(redo);
89
+ }, 100);
90
+ /**
91
+ * Replay transaction
92
+ *
93
+ * @param {TransactionEvent} transaction
94
+ */
95
+ this.replay = (transaction) => {
96
+ const objects = JSON.parse(transaction.json);
97
+ this.state = objects;
98
+ this.active = true;
99
+ this.handler.canvas.renderOnAddRemove = false;
100
+ this.handler.clear();
101
+ this.handler.canvas.discardActiveObject();
102
+ fabric_1.fabric.util.enlivenObjects(objects, (enlivenObjects) => {
103
+ enlivenObjects.forEach(obj => {
104
+ const targetIndex = this.handler.canvas._objects.length;
105
+ if (obj.superType === 'node') {
106
+ this.handler.canvas.insertAt(obj, targetIndex, false);
107
+ this.handler.portHandler.create(obj);
108
+ }
109
+ else if (obj.superType === 'link') {
110
+ const link = obj;
111
+ this.handler.objects = this.handler.getObjects();
112
+ this.handler.linkHandler.create({
113
+ type: 'curvedLink',
114
+ fromNodeId: link.fromNode?.id,
115
+ fromPortId: link.fromPort?.id,
116
+ toNodeId: link.toNode?.id,
117
+ toPortId: link.toPort?.id,
118
+ });
119
+ }
120
+ else {
121
+ this.handler.canvas.insertAt(obj, targetIndex, false);
122
+ }
123
+ });
124
+ this.handler.canvas.renderOnAddRemove = true;
125
+ this.active = false;
126
+ this.handler.canvas.renderAll();
127
+ this.handler.objects = this.handler.getObjects();
128
+ if (this.handler.onTransaction) {
129
+ this.handler.onTransaction(transaction);
130
+ }
131
+ }, null);
132
+ };
133
+ this.handler = handler;
134
+ this.initialize();
135
+ }
136
+ }
137
+ exports.default = TransactionHandler;
@@ -0,0 +1,43 @@
1
+ import { Handler } from '.';
2
+ import { WorkareaLayout, WorkareaObject, FabricImage } from '../utils';
3
+ declare class WorkareaHandler {
4
+ handler: Handler;
5
+ constructor(handler: Handler);
6
+ /**
7
+ * Initialize workarea
8
+ *
9
+ * @author salgum1114
10
+ */
11
+ initialize(): void;
12
+ /**
13
+ * Set the layout on workarea
14
+ * @param {WorkareaLayout} layout
15
+ * @returns
16
+ */
17
+ setLayout: (layout: WorkareaLayout) => void;
18
+ /**
19
+ * Set the responsive image on Workarea
20
+ * @param {string | File} [source]
21
+ * @param {boolean} [loaded]
22
+ * @returns
23
+ */
24
+ setResponsiveImage: (source: string | File, loaded?: boolean) => Promise<WorkareaObject>;
25
+ /**
26
+ * Set the image on Workarea
27
+ * @param {string | File} source
28
+ * @param {boolean} [loaded=false]
29
+ * @returns
30
+ */
31
+ setImage: (source: string | File, loaded?: boolean) => Promise<WorkareaObject>;
32
+ /**
33
+ * Calculate scale to the image
34
+ *
35
+ * @param {FabricImage} [image]
36
+ * @returns
37
+ */
38
+ calculateScale: (image?: FabricImage) => {
39
+ scaleX: number;
40
+ scaleY: number;
41
+ };
42
+ }
43
+ export default WorkareaHandler;