react-design-editor 0.0.60 → 0.0.62

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 (39) hide show
  1. package/README.md +7 -0
  2. package/dist/react-design-editor.js +176487 -168262
  3. package/dist/react-design-editor.min.js +1 -1
  4. package/dist/react-design-editor.min.js.LICENSE.txt +0 -9
  5. package/lib/Canvas.js +3 -3
  6. package/lib/CanvasObject.js +3 -0
  7. package/lib/constants/code.d.ts +1 -0
  8. package/lib/constants/code.js +2 -1
  9. package/lib/handlers/AbstractHandler.d.ts +6 -0
  10. package/lib/handlers/AbstractHandler.js +10 -0
  11. package/lib/handlers/DrawingHandler.js +5 -5
  12. package/lib/handlers/EventHandler.d.ts +1 -1
  13. package/lib/handlers/EventHandler.js +4 -7
  14. package/lib/handlers/GridHandler.d.ts +1 -1
  15. package/lib/handlers/GridHandler.js +44 -24
  16. package/lib/handlers/GuidelineHandler.d.ts +1 -1
  17. package/lib/handlers/Handler.d.ts +23 -2
  18. package/lib/handlers/Handler.js +58 -40
  19. package/lib/handlers/LayoutHandler.d.ts +15 -0
  20. package/lib/handlers/LayoutHandler.js +110 -0
  21. package/lib/handlers/LinkHandler.d.ts +3 -12
  22. package/lib/handlers/LinkHandler.js +19 -40
  23. package/lib/handlers/PortHandler.d.ts +1 -1
  24. package/lib/handlers/PortHandler.js +12 -30
  25. package/lib/handlers/ShortcutHandler.d.ts +1 -1
  26. package/lib/handlers/TransactionHandler.js +8 -15
  27. package/lib/handlers/ZoomHandler.d.ts +1 -1
  28. package/lib/handlers/index.d.ts +2 -22
  29. package/lib/handlers/index.js +5 -45
  30. package/lib/objects/LineLink.d.ts +15 -0
  31. package/lib/objects/LineLink.js +107 -0
  32. package/lib/objects/Link.d.ts +8 -1
  33. package/lib/objects/Link.js +152 -44
  34. package/lib/objects/Node.js +3 -3
  35. package/lib/objects/index.d.ts +4 -0
  36. package/lib/objects/index.js +3 -1
  37. package/package.json +22 -15
  38. package/lib/handlers/FiberHandler.d.ts +0 -6
  39. package/lib/handlers/FiberHandler.js +0 -23
@@ -1,17 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const fabric_1 = require("fabric");
4
- const uuidv4_1 = require("uuidv4");
4
+ const svg_path_properties_1 = require("svg-path-properties");
5
+ const uuid_1 = require("uuid");
5
6
  const Node_1 = require("./Node");
6
- const Link = fabric_1.fabric.util.createClass(fabric_1.fabric.Line, {
7
+ const Link = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
7
8
  type: 'link',
8
9
  superType: 'link',
9
10
  initialize(fromNode, fromPort, toNode, toPort, options) {
10
- options = options || {};
11
- const coords = [fromPort.left, fromPort.top, toPort.left, toPort.top];
12
- Object.assign(options, {
13
- strokeWidth: 4,
14
- id: options.id || (0, uuidv4_1.uuid)(),
11
+ const { left, top, ...other } = options || {};
12
+ this.fromNode = fromNode;
13
+ this.fromPort = fromPort;
14
+ this.toNode = toNode;
15
+ this.toPort = toPort;
16
+ console.log(options);
17
+ const { line, arrow } = this.draw(fromPort, toPort, options);
18
+ this.line = line;
19
+ this.arrow = arrow;
20
+ Object.assign(other, {
21
+ id: options.id || (0, uuid_1.v4)(),
15
22
  originX: 'center',
16
23
  originY: 'center',
17
24
  lockScalingX: true,
@@ -29,8 +36,9 @@ const Link = fabric_1.fabric.util.createClass(fabric_1.fabric.Line, {
29
36
  toNode,
30
37
  toPort,
31
38
  hoverCursor: 'pointer',
39
+ objectCaching: false,
32
40
  });
33
- this.callSuper('initialize', coords, options);
41
+ this.callSuper('initialize', [line, arrow], other);
34
42
  },
35
43
  setPort(fromNode, fromPort, _toNode, toPort) {
36
44
  if (fromNode.type === 'BroadcastNode') {
@@ -42,28 +50,147 @@ const Link = fabric_1.fabric.util.createClass(fabric_1.fabric.Line, {
42
50
  },
43
51
  setPortEnabled(node, port, enabled) {
44
52
  if (node.descriptor.outPortType !== Node_1.OUT_PORT_TYPE.BROADCAST) {
45
- port.set({
46
- enabled,
47
- fill: enabled ? port.originFill : port.selectFill,
48
- });
53
+ port.set({ enabled, fill: enabled ? port.originFill : port.selectFill });
49
54
  }
50
55
  else {
51
56
  if (node.toPort.id === port.id) {
52
57
  return;
53
58
  }
54
- port.links.forEach((link, index) => {
55
- link.set({
56
- fromPort: port,
57
- fromPortIndex: index,
58
- });
59
- });
60
- node.set({
61
- configuration: {
62
- outputCount: port.links.length,
63
- },
64
- });
59
+ port.links.forEach((link, index) => link.set({ fromPort: port, fromPortIndex: index }));
60
+ node.set({ configuration: { outputCount: port.links.length } });
65
61
  }
66
62
  },
63
+ setColor(color) {
64
+ this.line.set({ stroke: color });
65
+ this.arrow.set({ fill: color });
66
+ },
67
+ /**
68
+ * fabric.Path용 setPath 헬퍼 (FabricJS v4.6.0)
69
+ * @param {string} pathStr - 새로운 SVG path 문자열
70
+ */
71
+ parsePath(pathStr) {
72
+ const tempPathObj = new fabric_1.fabric.Path(pathStr);
73
+ return tempPathObj.path;
74
+ },
75
+ getPortPosition(node, direction) {
76
+ const { left, top, width, height } = node || {};
77
+ switch (direction) {
78
+ case 'R':
79
+ return { x: left + width, y: top + height / 2 };
80
+ case 'L':
81
+ return { x: left, y: top + height / 2 };
82
+ case 'T':
83
+ return { x: width ? left + width / 2 : left, y: top };
84
+ case 'B':
85
+ return { x: left, y: top };
86
+ default:
87
+ return { x: 0, y: 0 };
88
+ }
89
+ },
90
+ draw(fromPort, toPort, options = {}) {
91
+ const { strokeWidth = 4, stroke = '#999' } = options;
92
+ const { path, midX, midY, angle } = this.calculatePath(fromPort, toPort);
93
+ const line = new fabric_1.fabric.Path(path, {
94
+ strokeWidth: strokeWidth || 4,
95
+ fill: '',
96
+ originX: 'center',
97
+ originY: 'center',
98
+ stroke: stroke || '#999',
99
+ selectable: false,
100
+ evented: false,
101
+ strokeLineJoin: 'round',
102
+ objectCaching: false,
103
+ });
104
+ const arrow = new fabric_1.fabric.Triangle({
105
+ left: midX,
106
+ top: midY,
107
+ originX: 'center',
108
+ originY: 'center',
109
+ angle: angle,
110
+ width: 13,
111
+ height: 13,
112
+ fill: stroke,
113
+ selectable: false,
114
+ evented: false,
115
+ });
116
+ return { line, arrow };
117
+ },
118
+ update(fromPort, toPort) {
119
+ const { path, midX, midY, angle } = this.calculatePath(fromPort, toPort);
120
+ this.removeWithUpdate(this.line);
121
+ this.line = new fabric_1.fabric.Path(path, {
122
+ strokeWidth: this.strokeWidth || 4,
123
+ fill: '',
124
+ originX: 'center',
125
+ originY: 'center',
126
+ stroke: this.stroke || '#999',
127
+ selectable: false,
128
+ evented: false,
129
+ strokeLineJoin: 'round',
130
+ objectCaching: false,
131
+ });
132
+ this.addWithUpdate(this.line);
133
+ this.arrow.set({ left: midX - this.left, top: midY - this.top, angle: angle });
134
+ this.arrow.setCoords();
135
+ this.canvas.requestRenderAll();
136
+ },
137
+ calculatePath(fromPort, toPort) {
138
+ const p1 = this.getPortPosition(fromPort, 'B');
139
+ const p2 = this.getPortPosition(toPort, 'T');
140
+ const width = this.fromNode?.width || 200;
141
+ const height = this.fromNode?.height || 40;
142
+ const offset = 40;
143
+ let x1 = p1.x;
144
+ let y1 = p1.y;
145
+ let x2 = x1;
146
+ let y2 = y1 + height / 2;
147
+ let x3 = x2 - fromPort.left + this.fromNode.left - offset;
148
+ let y3 = p2.y - height / 2;
149
+ let x4 = p2.x;
150
+ let y4 = p2.y;
151
+ const useCurve = p2.y > p1.y;
152
+ const diff = x3 - (x2 - width);
153
+ let path;
154
+ if (useCurve) {
155
+ path = `M ${p1.x} ${p1.y} C ${p1.x} ${p1.y + 40}, ${p2.x} ${p1.y === p2.y ? p2.y : p2.y - 40}, ${p2.x} ${p2.y}`;
156
+ }
157
+ else {
158
+ const baseRadius = 10;
159
+ const dx = p1.x - p2.x;
160
+ const isUpward = width - diff <= dx && dx >= 0;
161
+ const distance = Math.abs(width - diff - dx);
162
+ let ratio = Math.min(1, distance / offset);
163
+ let radius = baseRadius * ratio;
164
+ path = [
165
+ `M ${x1} ${y1}`,
166
+ `L ${x2} ${y2 - baseRadius}`,
167
+ `Q ${x2} ${y2} ${x2 - baseRadius} ${y2}`,
168
+ `L ${x3 + baseRadius} ${y2}`,
169
+ `Q ${x3} ${y2} ${x3} ${y2 - baseRadius}`,
170
+ `L ${x3} ${y3 + radius}`,
171
+ `Q ${x3} ${y3} ${isUpward ? x3 - radius : x3 + radius} ${y3}`,
172
+ `L ${isUpward ? x4 + radius : x4 - radius} ${y3}`,
173
+ `Q ${x4} ${y3} ${x4} ${y3 + radius}`,
174
+ `L ${x4} ${y4}`,
175
+ ].join(' ');
176
+ }
177
+ let midX = x3;
178
+ let midY = (y3 + y2) / 2;
179
+ let angle = 0;
180
+ if (useCurve) {
181
+ const properties = new svg_path_properties_1.svgPathProperties(path);
182
+ const totalLength = properties.getTotalLength();
183
+ const delta = 1;
184
+ const ahead = properties.getPointAtLength(totalLength / 2 + delta);
185
+ const behind = properties.getPointAtLength(totalLength / 2 - delta);
186
+ const dx = ahead.x - behind.x;
187
+ const dy = ahead.y - behind.y;
188
+ midX = (p1.x + p2.x) / 2;
189
+ midY = (p1.y + p2.y) / 2;
190
+ angle = Math.atan2(dy, dx) * (180 / Math.PI) + 90;
191
+ }
192
+ return { path, midX, midY, angle };
193
+ },
67
194
  toObject() {
68
195
  return fabric_1.fabric.util.object.extend(this.callSuper('toObject'), {
69
196
  id: this.get('id'),
@@ -71,32 +198,13 @@ const Link = fabric_1.fabric.util.createClass(fabric_1.fabric.Line, {
71
198
  superType: this.get('superType'),
72
199
  configuration: this.get('configuration'),
73
200
  fromNode: this.get('fromNode'),
201
+ fromNodeId: this.get('fromNodeId'),
74
202
  fromPort: this.get('fromPort'),
75
203
  toNode: this.get('toNode'),
204
+ toNodeId: this.get('toNodeId'),
76
205
  toPort: this.get('toPort'),
77
206
  });
78
207
  },
79
- _render(ctx) {
80
- this.callSuper('_render', ctx);
81
- ctx.save();
82
- const xDiff = this.x2 - this.x1;
83
- const yDiff = this.y2 - this.y1;
84
- const angle = Math.atan2(yDiff, xDiff);
85
- ctx.translate((this.x2 - this.x1) / 2, (this.y2 - this.y1) / 2);
86
- ctx.rotate(angle);
87
- ctx.beginPath();
88
- if (this.arrow) {
89
- // Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
90
- ctx.moveTo(5, 0);
91
- ctx.lineTo(-5, 5);
92
- ctx.lineTo(-5, -5);
93
- }
94
- ctx.closePath();
95
- ctx.lineWidth = this.strokeWidth;
96
- ctx.fillStyle = this.stroke;
97
- ctx.fill();
98
- ctx.restore();
99
- },
100
208
  });
101
209
  Link.fromObject = (options, callback) => {
102
210
  const { fromNode, fromPort, toNode, toPort } = options;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getEllipsis = exports.DESCRIPTIONS = exports.OUT_PORT_TYPE = exports.NODE_COLORS = void 0;
7
7
  const fabric_1 = require("fabric");
8
8
  const i18next_1 = __importDefault(require("i18next"));
9
- const uuidv4_1 = require("uuidv4");
9
+ const uuid_1 = require("uuid");
10
10
  const Port_1 = __importDefault(require("./Port"));
11
11
  exports.NODE_COLORS = {
12
12
  TRIGGER: {
@@ -97,7 +97,7 @@ const Node = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
97
97
  });
98
98
  const node = [rect, icon, this.label, this.errorFlag];
99
99
  const option = Object.assign({}, options, {
100
- id: options.id || (0, uuidv4_1.uuid)(),
100
+ id: options.id || (0, uuid_1.v4)(),
101
101
  width: 200,
102
102
  height: 40,
103
103
  originX: 'left',
@@ -252,7 +252,7 @@ const Node = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
252
252
  },
253
253
  duplicate() {
254
254
  const options = this.toObject();
255
- options.id = (0, uuidv4_1.uuid)();
255
+ options.id = (0, uuid_1.v4)();
256
256
  options.name = `${options.name}_clone`;
257
257
  return new Node(options);
258
258
  },
@@ -7,9 +7,13 @@ export { default as Element } from './Element';
7
7
  export { default as Gif } from './Gif';
8
8
  export { default as Iframe } from './Iframe';
9
9
  export { default as Line } from './Line';
10
+ export { default as LineLink } from './LineLink';
10
11
  export { default as Link } from './Link';
12
+ export type { LinkedNodePropeties, LinkObject } from './Link';
11
13
  export { default as Node } from './Node';
14
+ export type { NodeObject } from './Node';
12
15
  export { default as OrthogonalLink } from './OrthogonalLink';
13
16
  export { default as Port } from './Port';
17
+ export type { PortObject } from './Port';
14
18
  export { default as Svg } from './Svg';
15
19
  export { default as Video } from './Video';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Video = exports.Svg = exports.Port = exports.OrthogonalLink = exports.Node = exports.Link = exports.Line = exports.Iframe = exports.Gif = exports.Element = exports.CurvedLink = exports.Cube = exports.CirclePort = exports.Chart = exports.Arrow = void 0;
6
+ exports.Video = exports.Svg = exports.Port = exports.OrthogonalLink = exports.Node = exports.Link = exports.LineLink = exports.Line = exports.Iframe = exports.Gif = exports.Element = exports.CurvedLink = exports.Cube = exports.CirclePort = exports.Chart = exports.Arrow = void 0;
7
7
  var Arrow_1 = require("./Arrow");
8
8
  Object.defineProperty(exports, "Arrow", { enumerable: true, get: function () { return __importDefault(Arrow_1).default; } });
9
9
  var Chart_1 = require("./Chart");
@@ -22,6 +22,8 @@ var Iframe_1 = require("./Iframe");
22
22
  Object.defineProperty(exports, "Iframe", { enumerable: true, get: function () { return __importDefault(Iframe_1).default; } });
23
23
  var Line_1 = require("./Line");
24
24
  Object.defineProperty(exports, "Line", { enumerable: true, get: function () { return __importDefault(Line_1).default; } });
25
+ var LineLink_1 = require("./LineLink");
26
+ Object.defineProperty(exports, "LineLink", { enumerable: true, get: function () { return __importDefault(LineLink_1).default; } });
25
27
  var Link_1 = require("./Link");
26
28
  Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return __importDefault(Link_1).default; } });
27
29
  var Node_1 = require("./Node");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-design-editor",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
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",
@@ -46,11 +46,15 @@
46
46
  "react-dom": "^16.14.0"
47
47
  },
48
48
  "dependencies": {
49
+ "@dagrejs/dagre": "^1.1.4",
50
+ "@flomon-ui/icons": "^0.0.68",
49
51
  "animejs": "^3.0.0",
50
52
  "antd": "3.15.0",
51
53
  "classnames": "^2.2.6",
54
+ "clsx": "^2.1.1",
52
55
  "color": "^3.1.2",
53
56
  "echarts": "^4.7.0",
57
+ "elkjs": "^0.10.0",
54
58
  "fabric": "^4.6.0",
55
59
  "gifler": "^0.1.0",
56
60
  "honeycomb-grid": "^3.1.7",
@@ -65,16 +69,15 @@
65
69
  "react-custom-scrollbars": "^4.2.1",
66
70
  "react-dom": "^16.14.0",
67
71
  "react-helmet": "^5.2.0",
68
- "react-hot-loader": "^4.12.20",
69
72
  "react-json-view": "^1.19.1",
70
73
  "resize-observer-polyfill": "^1.5.1",
71
74
  "store": "^2.0.12",
72
- "uuid": "^7.0.3",
73
- "uuidv4": "^6.2.8",
75
+ "svg-path-properties": "^1.3.0",
76
+ "uuid": "^11.1.0",
74
77
  "warning": "^4.0.3"
75
78
  },
76
79
  "devDependencies": {
77
- "@babel/core": "^7.16.0",
80
+ "@babel/core": "^7.27.3",
78
81
  "@babel/plugin-proposal-class-properties": "^7.16.0",
79
82
  "@babel/plugin-proposal-decorators": "^7.16.4",
80
83
  "@babel/plugin-proposal-object-rest-spread": "^7.16.0",
@@ -98,6 +101,8 @@
98
101
  "@types/uuid": "^7.0.2",
99
102
  "@types/warning": "^3.0.0",
100
103
  "@types/webpack-env": "^1.16.0",
104
+ "@typescript-eslint/eslint-plugin": "^8.33.0",
105
+ "@typescript-eslint/parser": "^8.33.0",
101
106
  "babel-eslint": "^10.1.0",
102
107
  "babel-loader": "^8.1.0",
103
108
  "babel-plugin-dynamic-import-webpack": "^1.1.0",
@@ -106,30 +111,32 @@
106
111
  "css-loader": "^3.5.2",
107
112
  "del": "^5.1.0",
108
113
  "eslint": "^8.3.0",
109
- "eslint-config-airbnb": "^19.0.0",
114
+ "eslint-config-airbnb": "^19.0.4",
115
+ "eslint-config-airbnb-typescript": "^18.0.0",
116
+ "eslint-import-resolver-typescript": "^4.4.1",
110
117
  "eslint-loader": "^4.0.2",
111
118
  "eslint-plugin-import": "^2.20.2",
112
119
  "eslint-plugin-jsx-a11y": "^6.2.3",
113
120
  "eslint-plugin-react": "^7.19.0",
121
+ "eslint-plugin-react-hooks": "^5.2.0",
114
122
  "file-loader": "^6.0.0",
115
123
  "fs-extra": "^9.0.0",
116
124
  "gh-pages": "^2.2.0",
117
- "html-webpack-plugin": "^3.2.0",
125
+ "html-webpack-plugin": "^5.6.3",
118
126
  "http-server": "^14.1.0",
119
127
  "less": "^2.7.3",
120
128
  "less-loader": "^5.0.0",
121
129
  "path": "^0.12.7",
122
130
  "style-loader": "^1.1.4",
123
- "terser-webpack-plugin": "^4.2.3",
124
- "tslint": "^6.1.1",
125
- "tslint-react": "^5.0.0",
131
+ "terser-webpack-plugin": "^5.3.14",
132
+ "tslib": "^2.8.1",
126
133
  "typedoc": "^0.17.4",
127
134
  "typescript": "^4.7.4",
128
135
  "url-loader": "^4.1.0",
129
- "webpack": "^4.46.0",
130
- "webpack-cli": "^4.9.1",
131
- "webpack-dev-server": "^4.15.1",
132
- "webpack-merge": "^4.2.2",
133
- "workbox-webpack-plugin": "^5.1.2"
136
+ "webpack": "^5.99.9",
137
+ "webpack-cli": "^5.1.4",
138
+ "webpack-dev-server": "^5.2.1",
139
+ "webpack-merge": "^6.0.1",
140
+ "workbox-webpack-plugin": "^6.6.1"
134
141
  }
135
142
  }
@@ -1,6 +0,0 @@
1
- import CustomHandler from './CustomHandler';
2
- declare class FiberHandler extends CustomHandler {
3
- protected initialze(): void;
4
- private mousedown;
5
- }
6
- export default FiberHandler;
@@ -1,23 +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 CustomHandler_1 = __importDefault(require("./CustomHandler"));
7
- class FiberHandler extends CustomHandler_1.default {
8
- initialze() {
9
- this.handler.canvas.on('mouse:down', this.mousedown);
10
- }
11
- mousedown(opt) {
12
- const { subTargets } = opt;
13
- if (subTargets.length) {
14
- const target = subTargets[0];
15
- console.log(target);
16
- if (target.type === 'container') {
17
- }
18
- else if (target.type === 'coreContainer') {
19
- }
20
- }
21
- }
22
- }
23
- exports.default = FiberHandler;