react-design-editor 0.0.32 → 0.0.36

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 (101) hide show
  1. package/README.md +37 -33
  2. package/dist/react-design-editor.js +33723 -13736
  3. package/dist/react-design-editor.min.js +1 -1
  4. package/dist/react-design-editor.min.js.LICENSE.txt +13 -2
  5. package/lib/Canvas.d.ts +18 -32
  6. package/lib/Canvas.js +172 -245
  7. package/lib/CanvasObject.d.ts +10 -10
  8. package/lib/CanvasObject.js +96 -89
  9. package/lib/constants/code.d.ts +19 -0
  10. package/lib/constants/code.js +22 -0
  11. package/lib/constants/defaults.d.ts +38 -0
  12. package/lib/constants/defaults.js +69 -0
  13. package/lib/constants/index.d.ts +3 -0
  14. package/lib/constants/index.js +26 -0
  15. package/lib/handlers/AlignmentHandler.d.ts +18 -18
  16. package/lib/handlers/AlignmentHandler.js +58 -58
  17. package/lib/handlers/AnimationHandler.d.ts +50 -48
  18. package/lib/handlers/AnimationHandler.js +323 -298
  19. package/lib/handlers/ChartHandler.d.ts +8 -8
  20. package/lib/handlers/ChartHandler.js +8 -8
  21. package/lib/handlers/ContextmenuHandler.d.ts +28 -23
  22. package/lib/handlers/ContextmenuHandler.js +65 -56
  23. package/lib/handlers/CropHandler.d.ts +43 -37
  24. package/lib/handlers/CropHandler.js +261 -243
  25. package/lib/handlers/CustomHandler.d.ts +7 -0
  26. package/lib/handlers/CustomHandler.js +10 -0
  27. package/lib/handlers/DrawingHandler.d.ts +28 -28
  28. package/lib/handlers/DrawingHandler.js +318 -318
  29. package/lib/handlers/ElementHandler.d.ts +80 -80
  30. package/lib/handlers/ElementHandler.js +154 -154
  31. package/lib/handlers/EventHandler.d.ts +170 -182
  32. package/lib/handlers/EventHandler.js +880 -904
  33. package/lib/handlers/FiberHandler.d.ts +6 -0
  34. package/lib/handlers/FiberHandler.js +23 -0
  35. package/lib/handlers/GridHandler.d.ts +19 -18
  36. package/lib/handlers/GridHandler.js +77 -76
  37. package/lib/handlers/GuidelineHandler.d.ts +61 -39
  38. package/lib/handlers/GuidelineHandler.js +315 -266
  39. package/lib/handlers/Handler.d.ts +622 -543
  40. package/lib/handlers/Handler.js +1638 -1510
  41. package/lib/handlers/ImageHandler.d.ts +307 -307
  42. package/lib/handlers/ImageHandler.js +529 -484
  43. package/lib/handlers/InteractionHandler.d.ts +45 -45
  44. package/lib/handlers/InteractionHandler.js +164 -159
  45. package/lib/handlers/LinkHandler.d.ts +115 -116
  46. package/lib/handlers/LinkHandler.js +247 -246
  47. package/lib/handlers/NodeHandler.d.ts +50 -50
  48. package/lib/handlers/NodeHandler.js +274 -274
  49. package/lib/handlers/PortHandler.d.ts +22 -22
  50. package/lib/handlers/PortHandler.js +179 -179
  51. package/lib/handlers/ShortcutHandler.d.ts +119 -119
  52. package/lib/handlers/ShortcutHandler.js +151 -150
  53. package/lib/handlers/TooltipHandler.d.ts +33 -24
  54. package/lib/handlers/TooltipHandler.js +91 -78
  55. package/lib/handlers/TransactionHandler.d.ts +59 -54
  56. package/lib/handlers/TransactionHandler.js +137 -132
  57. package/lib/handlers/WorkareaHandler.d.ts +43 -41
  58. package/lib/handlers/WorkareaHandler.js +354 -352
  59. package/lib/handlers/ZoomHandler.d.ts +48 -48
  60. package/lib/handlers/ZoomHandler.js +143 -143
  61. package/lib/handlers/index.d.ts +23 -21
  62. package/lib/handlers/index.js +48 -44
  63. package/lib/index.d.ts +6 -5
  64. package/lib/index.js +20 -19
  65. package/lib/objects/Arrow.d.ts +2 -2
  66. package/lib/objects/Arrow.js +40 -39
  67. package/lib/objects/Chart.d.ts +10 -10
  68. package/lib/objects/Chart.js +117 -116
  69. package/lib/objects/CirclePort.d.ts +2 -2
  70. package/lib/objects/CirclePort.js +28 -28
  71. package/lib/objects/Cube.d.ts +5 -5
  72. package/lib/objects/Cube.js +71 -71
  73. package/lib/objects/CurvedLink.d.ts +2 -2
  74. package/lib/objects/CurvedLink.js +51 -49
  75. package/lib/objects/Element.d.ts +13 -13
  76. package/lib/objects/Element.js +77 -76
  77. package/lib/objects/Gif.d.ts +3 -3
  78. package/lib/objects/Gif.js +41 -38
  79. package/lib/objects/Iframe.d.ts +9 -9
  80. package/lib/objects/Iframe.js +63 -62
  81. package/lib/objects/Line.d.ts +2 -2
  82. package/lib/objects/Line.js +24 -24
  83. package/lib/objects/Link.d.ts +15 -15
  84. package/lib/objects/Link.js +106 -104
  85. package/lib/objects/Node.d.ts +59 -59
  86. package/lib/objects/Node.js +271 -268
  87. package/lib/objects/OrthogonalLink.d.ts +2 -2
  88. package/lib/objects/OrthogonalLink.js +54 -52
  89. package/lib/objects/Port.d.ts +12 -12
  90. package/lib/objects/Port.js +28 -28
  91. package/lib/objects/Svg.d.ts +8 -0
  92. package/lib/objects/Svg.js +59 -0
  93. package/lib/objects/Video.d.ts +14 -14
  94. package/lib/objects/Video.js +113 -112
  95. package/lib/objects/index.d.ts +15 -14
  96. package/lib/objects/index.js +32 -30
  97. package/lib/utils/ObjectUtil.d.ts +407 -413
  98. package/lib/utils/ObjectUtil.js +13 -13
  99. package/lib/utils/index.d.ts +1 -1
  100. package/lib/utils/index.js +13 -13
  101. package/package.json +20 -17
@@ -1,132 +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
- * Init transaction
14
- */
15
- this.init = () => {
16
- this.redos = [];
17
- this.undos = [];
18
- };
19
- /**
20
- * Save transaction
21
- * @param {TransactionType} type
22
- * @param {*} [canvasJSON]
23
- * @param {boolean} [isWorkarea=true]
24
- */
25
- this.save = (type, canvasJSON, _isWorkarea = true) => {
26
- if (!this.handler.keyEvent.transaction) {
27
- return;
28
- }
29
- try {
30
- if (this.state) {
31
- const json = JSON.stringify(this.state);
32
- this.redos = [];
33
- this.undos.push({
34
- type,
35
- json,
36
- });
37
- }
38
- const { objects } = canvasJSON || this.handler.canvas.toJSON(this.handler.propertiesToInclude);
39
- this.state = objects.filter(obj => {
40
- if (obj.id === 'workarea') {
41
- return false;
42
- }
43
- else if (obj.id === 'grid') {
44
- return false;
45
- }
46
- else if (obj.superType === 'port') {
47
- return false;
48
- }
49
- return true;
50
- });
51
- }
52
- catch (error) {
53
- console.error(error);
54
- }
55
- };
56
- /**
57
- * Undo transaction
58
- */
59
- this.undo = throttle_1.default(() => {
60
- const undo = this.undos.pop();
61
- if (!undo) {
62
- return;
63
- }
64
- this.redos.push({
65
- type: 'redo',
66
- json: JSON.stringify(this.state),
67
- });
68
- this.replay(undo);
69
- }, 100);
70
- /**
71
- * Redo transaction
72
- */
73
- this.redo = throttle_1.default(() => {
74
- const redo = this.redos.pop();
75
- if (!redo) {
76
- return;
77
- }
78
- this.undos.push({
79
- type: 'undo',
80
- json: JSON.stringify(this.state),
81
- });
82
- this.replay(redo);
83
- }, 100);
84
- /**
85
- * Replay transaction
86
- * @param {TransactionEvent} transaction
87
- */
88
- this.replay = (transaction) => {
89
- const objects = JSON.parse(transaction.json);
90
- this.state = objects;
91
- this.active = true;
92
- this.handler.canvas.renderOnAddRemove = false;
93
- this.handler.clear();
94
- this.handler.canvas.discardActiveObject();
95
- fabric_1.fabric.util.enlivenObjects(objects, (enlivenObjects) => {
96
- enlivenObjects.forEach(obj => {
97
- const targetIndex = this.handler.canvas._objects.length;
98
- if (obj.superType === 'node') {
99
- this.handler.canvas.insertAt(obj, targetIndex, false);
100
- this.handler.portHandler.create(obj);
101
- }
102
- else if (obj.superType === 'link') {
103
- const link = obj;
104
- this.handler.objects = this.handler.getObjects();
105
- this.handler.linkHandler.create({
106
- type: 'curvedLink',
107
- fromNodeId: link.fromNode.id,
108
- fromPortId: link.fromPort.id,
109
- toNodeId: link.toNode.id,
110
- toPortId: link.toPort.id,
111
- });
112
- }
113
- else {
114
- this.handler.canvas.insertAt(obj, targetIndex, false);
115
- }
116
- });
117
- this.handler.canvas.renderOnAddRemove = true;
118
- this.active = false;
119
- this.handler.canvas.renderAll();
120
- this.handler.objects = this.handler.getObjects();
121
- if (this.handler.onTransaction) {
122
- this.handler.onTransaction(transaction);
123
- }
124
- }, null);
125
- };
126
- this.handler = handler;
127
- if (this.handler.editable) {
128
- this.init();
129
- }
130
- }
131
- }
132
- exports.default = TransactionHandler;
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;
@@ -1,41 +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
- * Init workarea
8
- */
9
- init: () => void;
10
- /**
11
- * Set the layout on workarea
12
- * @param {WorkareaLayout} layout
13
- * @returns
14
- */
15
- setLayout: (layout: WorkareaLayout) => void;
16
- /**
17
- * Set the responsive image on Workarea
18
- * @param {string | File} [source]
19
- * @param {boolean} [loaded]
20
- * @returns
21
- */
22
- setResponsiveImage: (source: string | File, loaded?: boolean) => Promise<WorkareaObject>;
23
- /**
24
- * Set the image on Workarea
25
- * @param {string | File} source
26
- * @param {boolean} [loaded=false]
27
- * @returns
28
- */
29
- setImage: (source: string | File, loaded?: boolean) => Promise<WorkareaObject>;
30
- /**
31
- * Calculate scale to the image
32
- *
33
- * @param {FabricImage} [image]
34
- * @returns
35
- */
36
- calculateScale: (image?: FabricImage) => {
37
- scaleX: number;
38
- scaleY: number;
39
- };
40
- }
41
- export default WorkareaHandler;
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;