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,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fabric_1 = require("fabric");
4
+ const uuidv4_1 = require("uuidv4");
5
+ const Node_1 = require("./Node");
6
+ const Link = fabric_1.fabric.util.createClass(fabric_1.fabric.Line, {
7
+ type: 'link',
8
+ superType: 'link',
9
+ initialize(fromNode, fromPort, toNode, toPort, options) {
10
+ options = options || {};
11
+ const coords = [fromPort.left, fromPort.top, toPort.left, toPort.top];
12
+ this.callSuper('initialize', coords, options);
13
+ this.set({
14
+ strokeWidth: 4,
15
+ id: options.id || uuidv4_1.uuid(),
16
+ originX: 'center',
17
+ originY: 'center',
18
+ lockScalingX: true,
19
+ lockScalingY: true,
20
+ lockRotation: true,
21
+ hasRotatingPoint: false,
22
+ hasControls: false,
23
+ hasBorders: false,
24
+ perPixelTargetFind: true,
25
+ lockMovementX: true,
26
+ lockMovementY: true,
27
+ selectable: false,
28
+ fromNode,
29
+ fromPort,
30
+ toNode,
31
+ toPort,
32
+ });
33
+ },
34
+ setPort(fromNode, fromPort, _toNode, toPort) {
35
+ if (fromNode.type === 'BroadcastNode') {
36
+ fromPort = fromNode.fromPort[0];
37
+ }
38
+ fromPort.links.push(this);
39
+ toPort.links.push(this);
40
+ this.setPortEnabled(fromNode, fromPort, false);
41
+ },
42
+ setPortEnabled(node, port, enabled) {
43
+ if (node.descriptor.outPortType !== Node_1.OUT_PORT_TYPE.BROADCAST) {
44
+ port.set({
45
+ enabled,
46
+ fill: enabled ? port.originFill : port.selectFill,
47
+ });
48
+ }
49
+ else {
50
+ if (node.toPort.id === port.id) {
51
+ return;
52
+ }
53
+ port.links.forEach((link, index) => {
54
+ link.set({
55
+ fromPort: port,
56
+ fromPortIndex: index,
57
+ });
58
+ });
59
+ node.set({
60
+ configuration: {
61
+ outputCount: port.links.length,
62
+ },
63
+ });
64
+ }
65
+ },
66
+ toObject() {
67
+ return fabric_1.fabric.util.object.extend(this.callSuper('toObject'), {
68
+ id: this.get('id'),
69
+ name: this.get('name'),
70
+ superType: this.get('superType'),
71
+ configuration: this.get('configuration'),
72
+ fromNode: this.get('fromNode'),
73
+ fromPort: this.get('fromPort'),
74
+ toNode: this.get('toNode'),
75
+ toPort: this.get('toPort'),
76
+ });
77
+ },
78
+ _render(ctx) {
79
+ this.callSuper('_render', ctx);
80
+ ctx.save();
81
+ const xDiff = this.x2 - this.x1;
82
+ const yDiff = this.y2 - this.y1;
83
+ const angle = Math.atan2(yDiff, xDiff);
84
+ ctx.translate((this.x2 - this.x1) / 2, (this.y2 - this.y1) / 2);
85
+ ctx.rotate(angle);
86
+ ctx.beginPath();
87
+ if (this.arrow) {
88
+ // Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
89
+ ctx.moveTo(5, 0);
90
+ ctx.lineTo(-5, 5);
91
+ ctx.lineTo(-5, -5);
92
+ }
93
+ ctx.closePath();
94
+ ctx.lineWidth = this.strokeWidth;
95
+ ctx.fillStyle = this.stroke;
96
+ ctx.fill();
97
+ ctx.restore();
98
+ },
99
+ });
100
+ Link.fromObject = (options, callback) => {
101
+ const { fromNode, fromPort, toNode, toPort } = options;
102
+ return callback(new Link(fromNode, fromPort, toNode, toPort, options));
103
+ };
104
+ // @ts-ignore
105
+ window.fabric.Link = Link;
106
+ exports.default = Link;
@@ -0,0 +1,59 @@
1
+ import { fabric } from 'fabric';
2
+ import { FabricObject } from '../utils';
3
+ import { PortObject } from './Port';
4
+ export declare const NODE_COLORS: {
5
+ TRIGGER: {
6
+ fill: string;
7
+ border: string;
8
+ };
9
+ LOGIC: {
10
+ fill: string;
11
+ border: string;
12
+ };
13
+ DATA: {
14
+ fill: string;
15
+ border: string;
16
+ };
17
+ ACTION: {
18
+ fill: string;
19
+ border: string;
20
+ };
21
+ };
22
+ export declare const OUT_PORT_TYPE: {
23
+ SINGLE: string;
24
+ STATIC: string;
25
+ DYNAMIC: string;
26
+ BROADCAST: string;
27
+ NONE: string;
28
+ };
29
+ export declare const DESCRIPTIONS: {
30
+ script: string;
31
+ template: string;
32
+ json: string;
33
+ cron: string;
34
+ };
35
+ export declare const getEllipsis: (text: string, length: number) => string;
36
+ export declare type NodeType = 'TRIGGER' | 'LOGIC' | 'DATA' | 'ACTION';
37
+ export interface NodeObject extends FabricObject<fabric.Group> {
38
+ errorFlag?: fabric.IText;
39
+ label?: fabric.Text;
40
+ toPort?: PortObject;
41
+ errors?: any;
42
+ fromPort?: PortObject[];
43
+ descriptor?: Record<string, any>;
44
+ nodeClazz?: string;
45
+ configuration?: Record<string, any>;
46
+ defaultPortOption?: () => Partial<PortObject>;
47
+ toPortOption?: () => Partial<PortObject>;
48
+ fromPortOption?: () => Partial<PortObject>;
49
+ createToPort?: (left: number, top: number) => PortObject;
50
+ createFromPort?: (left: number, top: number) => PortObject[];
51
+ singlePort?: (portOption: Partial<PortObject>) => PortObject[];
52
+ staticPort?: (portOption: Partial<PortObject>) => PortObject[];
53
+ dynamicPort?: (portOption: Partial<PortObject>) => PortObject[];
54
+ broadcastPort?: (portOption: Partial<PortObject>) => PortObject[];
55
+ setErrors?: (errors: any) => void;
56
+ duplicate?: () => NodeObject;
57
+ }
58
+ declare const Node: any;
59
+ export default Node;
@@ -0,0 +1,271 @@
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
+ exports.getEllipsis = exports.DESCRIPTIONS = exports.OUT_PORT_TYPE = exports.NODE_COLORS = void 0;
7
+ const fabric_1 = require("fabric");
8
+ const i18next_1 = __importDefault(require("i18next"));
9
+ const uuidv4_1 = require("uuidv4");
10
+ const Port_1 = __importDefault(require("./Port"));
11
+ exports.NODE_COLORS = {
12
+ TRIGGER: {
13
+ fill: '#48C9B0',
14
+ border: '#1ABC9C',
15
+ },
16
+ LOGIC: {
17
+ fill: '#AF7AC5',
18
+ border: '#9B59B6',
19
+ },
20
+ DATA: {
21
+ fill: '#5DADE2',
22
+ border: '#3498DB',
23
+ },
24
+ ACTION: {
25
+ fill: '#F5B041',
26
+ border: 'rgb(243, 156, 18)',
27
+ },
28
+ };
29
+ exports.OUT_PORT_TYPE = {
30
+ SINGLE: 'SINGLE',
31
+ STATIC: 'STATIC',
32
+ DYNAMIC: 'DYNAMIC',
33
+ BROADCAST: 'BROADCAST',
34
+ NONE: 'NONE',
35
+ };
36
+ exports.DESCRIPTIONS = {
37
+ script: i18next_1.default.t('common.name'),
38
+ template: i18next_1.default.t('common.name'),
39
+ json: i18next_1.default.t('common.name'),
40
+ cron: i18next_1.default.t('common.name'),
41
+ };
42
+ exports.getEllipsis = (text, length) => {
43
+ if (!length) {
44
+ return /[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/.test(text)
45
+ ? text.length > 8
46
+ ? text.substring(0, 8).concat('...')
47
+ : text
48
+ : text.length > 15
49
+ ? text.substring(0, 15).concat('...')
50
+ : text;
51
+ }
52
+ return /[ㄱ-ㅎ|ㅏ-ㅣ|가-힣]/.test(text)
53
+ ? text.length > length / 2
54
+ ? text.substring(0, length / 2).concat('...')
55
+ : text
56
+ : text.length > length
57
+ ? text.substring(0, length).concat('...')
58
+ : text;
59
+ };
60
+ const Node = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
61
+ type: 'node',
62
+ superType: 'node',
63
+ initialize(options) {
64
+ options = options || {};
65
+ const icon = new fabric_1.fabric.IText(options.icon || '\uE174', {
66
+ fontFamily: 'Font Awesome 5 Free',
67
+ fontWeight: 900,
68
+ fontSize: 20,
69
+ fill: 'rgba(255, 255, 255, 0.8)',
70
+ });
71
+ let name = 'Default Node';
72
+ if (options.name) {
73
+ name = exports.getEllipsis(options.name, 18);
74
+ }
75
+ this.label = new fabric_1.fabric.Text(name || 'Default Node', {
76
+ fontSize: 16,
77
+ fontFamily: 'polestar',
78
+ fontWeight: 500,
79
+ fill: 'rgba(255, 255, 255, 0.8)',
80
+ });
81
+ const rect = new fabric_1.fabric.Rect({
82
+ rx: 10,
83
+ ry: 10,
84
+ width: 200,
85
+ height: 40,
86
+ fill: options.fill || 'rgba(0, 0, 0, 0.3)',
87
+ stroke: options.stroke || 'rgba(0, 0, 0, 0)',
88
+ strokeWidth: 2,
89
+ });
90
+ this.errorFlag = new fabric_1.fabric.IText('\uf071', {
91
+ fontFamily: 'Font Awesome 5 Free',
92
+ fontWeight: 900,
93
+ fontSize: 14,
94
+ fill: 'rgba(255, 0, 0, 0.8)',
95
+ visible: options.errors,
96
+ });
97
+ const node = [rect, icon, this.label, this.errorFlag];
98
+ const option = Object.assign({}, options, {
99
+ id: options.id || uuidv4_1.uuid(),
100
+ width: 200,
101
+ height: 40,
102
+ originX: 'left',
103
+ originY: 'top',
104
+ hasRotatingPoint: false,
105
+ hasControls: false,
106
+ });
107
+ this.callSuper('initialize', node, option);
108
+ icon.set({
109
+ top: icon.top + 10,
110
+ left: icon.left + 10,
111
+ });
112
+ this.label.set({
113
+ top: this.label.top + this.label.height / 2 + 4,
114
+ left: this.label.left + 35,
115
+ });
116
+ this.errorFlag.set({
117
+ left: rect.left,
118
+ top: rect.top,
119
+ visible: options.errors,
120
+ });
121
+ },
122
+ toObject() {
123
+ return fabric_1.fabric.util.object.extend(this.callSuper('toObject'), {
124
+ id: this.get('id'),
125
+ name: this.get('name'),
126
+ icon: this.get('icon'),
127
+ description: this.get('description'),
128
+ superType: this.get('superType'),
129
+ configuration: this.get('configuration'),
130
+ nodeClazz: this.get('nodeClazz'),
131
+ descriptor: this.get('descriptor'),
132
+ borderColor: this.get('borderColor'),
133
+ borderScaleFactor: this.get('borderScaleFactor'),
134
+ dblclick: this.get('dblclick'),
135
+ deletable: this.get('deletable'),
136
+ cloneable: this.get('cloneable'),
137
+ fromPort: this.get('fromPort'),
138
+ toPort: this.get('toPort'),
139
+ });
140
+ },
141
+ defaultPortOption() {
142
+ const { type } = this.descriptor;
143
+ return {
144
+ nodeId: this.id,
145
+ hasBorders: false,
146
+ hasControls: false,
147
+ hasRotatingPoint: false,
148
+ selectable: false,
149
+ originX: 'center',
150
+ originY: 'center',
151
+ lockScalingX: true,
152
+ lockScalingY: true,
153
+ superType: 'port',
154
+ originFill: 'rgba(0, 0, 0, 0.1)',
155
+ hoverFill: 'rgba(0, 0, 0, 0.1)',
156
+ selectFill: 'rgba(0, 0, 0, 0.1)',
157
+ fill: 'rgba(0, 0, 0, 0.1)',
158
+ hoverCursor: 'pointer',
159
+ strokeWidth: 2,
160
+ stroke: this.descriptor ? exports.NODE_COLORS[type].border : 'rgba(0, 0, 0, 1)',
161
+ width: 10,
162
+ height: 10,
163
+ links: [],
164
+ enabled: true,
165
+ };
166
+ },
167
+ toPortOption() {
168
+ return {
169
+ ...this.defaultPortOption(),
170
+ };
171
+ },
172
+ fromPortOption() {
173
+ return {
174
+ ...this.defaultPortOption(),
175
+ angle: 45,
176
+ };
177
+ },
178
+ createToPort(left, top) {
179
+ if (this.descriptor.inEnabled) {
180
+ this.toPort = new Port_1.default({
181
+ id: 'defaultInPort',
182
+ type: 'toPort',
183
+ ...this.toPortOption(),
184
+ left,
185
+ top,
186
+ });
187
+ }
188
+ return this.toPort;
189
+ },
190
+ createFromPort(left, top) {
191
+ if (this.descriptor.outPortType === exports.OUT_PORT_TYPE.BROADCAST) {
192
+ this.fromPort = this.broadcastPort({ ...this.fromPortOption(), left, top });
193
+ }
194
+ else if (this.descriptor.outPortType === exports.OUT_PORT_TYPE.STATIC) {
195
+ this.fromPort = this.staticPort({ ...this.fromPortOption(), left, top });
196
+ }
197
+ else if (this.descriptor.outPortType === exports.OUT_PORT_TYPE.DYNAMIC) {
198
+ this.fromPort = this.dynamicPort({ ...this.fromPortOption(), left, top });
199
+ }
200
+ else if (this.descriptor.outPortType === exports.OUT_PORT_TYPE.NONE) {
201
+ this.fromPort = [];
202
+ }
203
+ else {
204
+ this.fromPort = this.singlePort({ ...this.fromPortOption(), left, top });
205
+ }
206
+ return this.fromPort;
207
+ },
208
+ singlePort(portOption) {
209
+ const fromPort = new Port_1.default({
210
+ id: 'defaultFromPort',
211
+ type: 'fromPort',
212
+ ...portOption,
213
+ });
214
+ return [fromPort];
215
+ },
216
+ staticPort(portOption) {
217
+ return this.descriptor.outPorts.map((outPort, i) => {
218
+ return new Port_1.default({
219
+ id: outPort,
220
+ type: 'fromPort',
221
+ ...portOption,
222
+ left: i === 0 ? portOption.left - 20 : portOption.left + 20,
223
+ top: portOption.top,
224
+ leftDiff: i === 0 ? -20 : 20,
225
+ fill: i === 0 ? 'rgba(0, 255, 0, 0.3)' : 'rgba(255, 0, 0, 0.3)',
226
+ originFill: i === 0 ? 'rgba(0, 255, 0, 0.3)' : 'rgba(255, 0, 0, 0.3)',
227
+ hoverFill: i === 0 ? 'rgba(0, 255, 0, 1)' : 'rgba(255, 0, 0, 1)',
228
+ });
229
+ });
230
+ },
231
+ dynamicPort(_portOption) {
232
+ return [];
233
+ },
234
+ broadcastPort(portOption) {
235
+ return this.singlePort(portOption);
236
+ },
237
+ setErrors(errors) {
238
+ this.set({
239
+ errors,
240
+ });
241
+ if (errors) {
242
+ this.errorFlag.set({
243
+ visible: true,
244
+ });
245
+ }
246
+ else {
247
+ this.errorFlag.set({
248
+ visible: false,
249
+ });
250
+ }
251
+ },
252
+ duplicate() {
253
+ const options = this.toObject();
254
+ options.id = uuidv4_1.uuid();
255
+ options.name = `${options.name}_clone`;
256
+ return new Node(options);
257
+ },
258
+ _render(ctx) {
259
+ this.callSuper('_render', ctx);
260
+ },
261
+ });
262
+ Node.fromObject = (options, callback) => {
263
+ return callback(new Node(options));
264
+ };
265
+ // @ts-ignore
266
+ window.fabric.FromPort = Port_1.default;
267
+ // @ts-ignore
268
+ window.fabric.ToPort = Port_1.default;
269
+ // @ts-ignore
270
+ window.fabric.Node = Node;
271
+ exports.default = Node;
@@ -0,0 +1,2 @@
1
+ declare const OrthogonalLink: any;
2
+ export default OrthogonalLink;
@@ -0,0 +1,54 @@
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 Link_1 = __importDefault(require("./Link"));
8
+ const OrthogonalLink = fabric_1.fabric.util.createClass(Link_1.default, {
9
+ type: 'OrthogonalLink',
10
+ superType: 'link',
11
+ initialize(fromNode, fromPort, toNode, toPort, options) {
12
+ options = options || {};
13
+ this.callSuper('initialize', fromNode, fromPort, toNode, toPort, options);
14
+ },
15
+ _render(ctx) {
16
+ // Drawing orthogonal link
17
+ const { x1, y1, x2, y2 } = this;
18
+ ctx.lineWidth = this.strokeWidth;
19
+ ctx.strokeStyle = this.stroke;
20
+ const fp = { x: (x1 - x2) / 2, y: (y1 - y2) / 2 };
21
+ const sp = { x: (x2 - x1) / 2, y: (y2 - y1) / 2 };
22
+ ctx.lineJoin = 'round';
23
+ ctx.beginPath();
24
+ ctx.moveTo(fp.x, fp.y);
25
+ ctx.lineTo(fp.x, sp.y / 2);
26
+ ctx.lineTo(sp.x, sp.y / 2);
27
+ ctx.lineTo(sp.x, sp.y);
28
+ ctx.stroke();
29
+ ctx.save();
30
+ const xDiff = this.x2 - this.x1;
31
+ const yDiff = this.y2 - this.y1;
32
+ const angle = Math.atan2(yDiff, xDiff);
33
+ ctx.translate((this.x2 - this.x1) / 2, (this.y2 - this.y1) / 2);
34
+ ctx.rotate(angle >= 0 ? 1.57 : -1.57);
35
+ ctx.beginPath();
36
+ if (this.arrow) {
37
+ // Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
38
+ ctx.moveTo(5, 0);
39
+ ctx.lineTo(-5, 5);
40
+ ctx.lineTo(-5, -5);
41
+ }
42
+ ctx.closePath();
43
+ ctx.fillStyle = this.stroke;
44
+ ctx.fill();
45
+ ctx.restore();
46
+ },
47
+ });
48
+ OrthogonalLink.fromObject = (options, callback) => {
49
+ const { fromNode, fromPort, toNode, toPort } = options;
50
+ return callback(new OrthogonalLink(fromNode, fromPort, toNode, toPort, options));
51
+ };
52
+ // @ts-ignore
53
+ window.fabric.OrthogonalLink = OrthogonalLink;
54
+ exports.default = OrthogonalLink;
@@ -0,0 +1,12 @@
1
+ import { fabric } from 'fabric';
2
+ import { FabricObject } from '../utils';
3
+ import { LinkObject } from './Link';
4
+ export interface PortObject extends FabricObject<fabric.Rect> {
5
+ links?: LinkObject[];
6
+ nodeId?: string;
7
+ enabled?: boolean;
8
+ hoverFill?: string;
9
+ selectFill?: string;
10
+ }
11
+ declare const Port: any;
12
+ export default Port;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fabric_1 = require("fabric");
4
+ const Port = fabric_1.fabric.util.createClass(fabric_1.fabric.Rect, {
5
+ type: 'port',
6
+ superType: 'port',
7
+ initialize(options) {
8
+ options = options || {};
9
+ this.callSuper('initialize', options);
10
+ },
11
+ toObject() {
12
+ return fabric_1.fabric.util.object.extend(this.callSuper('toObject'), {
13
+ id: this.get('id'),
14
+ superType: this.get('superType'),
15
+ enabled: this.get('enabled'),
16
+ nodeId: this.get('nodeId'),
17
+ });
18
+ },
19
+ _render(ctx) {
20
+ this.callSuper('_render', ctx);
21
+ },
22
+ });
23
+ Port.fromObject = (options, callback) => {
24
+ return callback(new Port(options));
25
+ };
26
+ // @ts-ignore
27
+ window.fabric.Port = Port;
28
+ exports.default = Port;
@@ -0,0 +1,8 @@
1
+ import { FabricGroup, FabricObject, FabricObjectOption } from '../utils';
2
+ export declare type SvgObject = FabricGroup | FabricObject;
3
+ export interface SvgOption extends FabricObjectOption {
4
+ svg?: string;
5
+ loadType?: 'file' | 'svg';
6
+ }
7
+ declare const Svg: any;
8
+ export default Svg;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fabric_1 = require("fabric");
4
+ const utils_1 = require("../utils");
5
+ const Svg = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
6
+ type: 'svg',
7
+ initialize(option = {}) {
8
+ this.callSuper('initialize', [], option);
9
+ this.loadSvg(option);
10
+ },
11
+ addSvgElements(objects, options, path) {
12
+ const createdObj = fabric_1.fabric.util.groupSVGElements(objects, options, path);
13
+ this.set(options);
14
+ if (createdObj.getObjects) {
15
+ createdObj.getObjects().forEach(obj => {
16
+ this.add(obj);
17
+ if (options.fill) {
18
+ obj.set('fill', options.fill);
19
+ }
20
+ if (options.stroke) {
21
+ obj.set('stroke', options.stroke);
22
+ }
23
+ });
24
+ }
25
+ else {
26
+ createdObj.set({
27
+ originX: 'center',
28
+ originY: 'center',
29
+ });
30
+ if (options.fill) {
31
+ createdObj.set({
32
+ fill: options.fill,
33
+ });
34
+ }
35
+ if (options.stroke) {
36
+ createdObj.set({
37
+ stroke: options.stroke,
38
+ });
39
+ }
40
+ this.add(createdObj);
41
+ }
42
+ this.setCoords();
43
+ if (this.canvas) {
44
+ this.canvas.requestRenderAll();
45
+ }
46
+ },
47
+ loadSvg(option) {
48
+ const { svg, loadType, fill, stroke } = option;
49
+ return new Promise(resolve => {
50
+ if (loadType === 'svg') {
51
+ fabric_1.fabric.loadSVGFromString(svg, (objects, options) => {
52
+ resolve(this.addSvgElements(objects, { ...options, fill, stroke }, svg));
53
+ });
54
+ }
55
+ else {
56
+ fabric_1.fabric.loadSVGFromURL(svg, (objects, options) => {
57
+ resolve(this.addSvgElements(objects, { ...options, fill, stroke }, svg));
58
+ });
59
+ }
60
+ });
61
+ },
62
+ toObject(propertiesToInclude) {
63
+ return utils_1.toObject(this, propertiesToInclude, {
64
+ svg: this.get('svg'),
65
+ loadType: this.get('loadType'),
66
+ });
67
+ },
68
+ _render(ctx) {
69
+ this.callSuper('_render', ctx);
70
+ },
71
+ });
72
+ Svg.fromObject = (option, callback) => {
73
+ return callback(new Svg(option));
74
+ };
75
+ // @ts-ignore
76
+ window.fabric.Svg = Svg;
77
+ exports.default = Svg;
@@ -0,0 +1,14 @@
1
+ import 'mediaelement';
2
+ import 'mediaelement/build/mediaelementplayer.min.css';
3
+ import { FabricElement } from '../utils';
4
+ export interface VideoObject extends FabricElement {
5
+ setSource: (source: string | File) => void;
6
+ setFile: (file: File) => void;
7
+ setSrc: (src: string) => void;
8
+ file?: File;
9
+ src?: string;
10
+ videoElement?: HTMLVideoElement;
11
+ player?: any;
12
+ }
13
+ declare const Video: any;
14
+ export default Video;