react-design-editor 0.0.47 → 0.0.50

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.
@@ -314,7 +314,7 @@ class EventHandler {
314
314
  if (editable) {
315
315
  if (this.handler.prevTarget && this.handler.prevTarget.superType === 'link') {
316
316
  this.handler.prevTarget.set({
317
- stroke: this.handler.prevTarget.originStroke,
317
+ stroke: this.handler.prevTarget.originStroke || this.handler.prevTarget.stroke,
318
318
  });
319
319
  }
320
320
  if (target && target.type === 'fromPort') {
@@ -339,7 +339,7 @@ class EventHandler {
339
339
  if (this.handler.interactionMode === 'selection') {
340
340
  if (target && target.superType === 'link') {
341
341
  target.set({
342
- stroke: target.selectFill || 'green',
342
+ stroke: target.selectedStroke || 'green',
343
343
  });
344
344
  }
345
345
  this.handler.prevTarget = target;
@@ -320,13 +320,14 @@ declare class Handler implements HandlerOptions {
320
320
  * @param {(File | string)} [source]
321
321
  * @returns
322
322
  */
323
- setImage: (obj: FabricImage, source?: File | string) => void;
323
+ setImage: (obj: FabricImage, source?: File | string) => Promise<FabricImage>;
324
324
  /**
325
325
  * Set image by id
326
326
  * @param {string} id
327
327
  * @param {*} source
328
+ * @returns
328
329
  */
329
- setImageById: (id: string, source: any) => void;
330
+ setImageById: (id: string, source: any) => Promise<FabricImage>;
330
331
  /**
331
332
  * Set visible
332
333
  * @param {boolean} [visible]
@@ -345,9 +346,10 @@ declare class Handler implements HandlerOptions {
345
346
  * @param {FabricObjectOption} obj
346
347
  * @param {boolean} [centered=true]
347
348
  * @param {boolean} [loaded=false]
349
+ * @param {boolean} [group=false]
348
350
  * @returns
349
351
  */
350
- add: (obj: FabricObjectOption, centered?: boolean, loaded?: boolean) => FabricObject<fabric.Object>;
352
+ add: (obj: FabricObjectOption, centered?: boolean, loaded?: boolean, group?: boolean) => FabricObject<fabric.Object>;
351
353
  /**
352
354
  * Add group object
353
355
  *
@@ -356,7 +358,7 @@ declare class Handler implements HandlerOptions {
356
358
  * @param {boolean} [loaded=false]
357
359
  * @returns
358
360
  */
359
- addGroup: (obj: FabricGroup, centered?: boolean, loaded?: boolean) => FabricObject<fabric.Object>[];
361
+ addGroup: (obj: FabricGroup) => FabricGroup;
360
362
  /**
361
363
  * Add iamge object
362
364
  * @param {FabricImage} obj
@@ -413,12 +415,6 @@ declare class Handler implements HandlerOptions {
413
415
  * @returns
414
416
  */
415
417
  paste: () => boolean;
416
- /**
417
- * Load the image
418
- * @param {FabricImage} obj
419
- * @param {string} src
420
- */
421
- loadImage: (obj: FabricImage, src: string) => void;
422
418
  /**
423
419
  * Find object by object
424
420
  * @param {FabricObject} obj
@@ -332,35 +332,43 @@ class Handler {
332
332
  * @returns
333
333
  */
334
334
  this.setImage = (obj, source) => {
335
- if (!source) {
336
- this.loadImage(obj, null);
337
- obj.set('file', null);
338
- obj.set('src', null);
339
- return;
340
- }
341
- if (source instanceof File) {
342
- const reader = new FileReader();
343
- reader.onload = () => {
344
- this.loadImage(obj, reader.result);
345
- obj.set('file', source);
335
+ return new Promise(resolve => {
336
+ if (!source) {
337
+ obj.set('file', null);
346
338
  obj.set('src', null);
347
- };
348
- reader.readAsDataURL(source);
349
- }
350
- else {
351
- this.loadImage(obj, source);
352
- obj.set('file', null);
353
- obj.set('src', source);
354
- }
339
+ resolve(obj.setSrc('./images/sample/transparentBg.png', () => this.canvas.renderAll(), {
340
+ dirty: true,
341
+ }));
342
+ }
343
+ if (source instanceof File) {
344
+ const reader = new FileReader();
345
+ reader.onload = () => {
346
+ obj.set('file', source);
347
+ obj.set('src', null);
348
+ resolve(obj.setSrc(reader.result, () => this.canvas.renderAll(), {
349
+ dirty: true,
350
+ }));
351
+ };
352
+ reader.readAsDataURL(source);
353
+ }
354
+ else {
355
+ obj.set('file', null);
356
+ obj.set('src', source);
357
+ resolve(obj.setSrc(source, () => this.canvas.renderAll(), {
358
+ dirty: true,
359
+ }));
360
+ }
361
+ });
355
362
  };
356
363
  /**
357
364
  * Set image by id
358
365
  * @param {string} id
359
366
  * @param {*} source
367
+ * @returns
360
368
  */
361
369
  this.setImageById = (id, source) => {
362
370
  const findObject = this.findById(id);
363
- this.setImage(findObject, source);
371
+ return Promise.resolve(this.setImage(findObject, source));
364
372
  };
365
373
  /**
366
374
  * Set visible
@@ -412,9 +420,10 @@ class Handler {
412
420
  * @param {FabricObjectOption} obj
413
421
  * @param {boolean} [centered=true]
414
422
  * @param {boolean} [loaded=false]
423
+ * @param {boolean} [group=false]
415
424
  * @returns
416
425
  */
417
- this.add = (obj, centered = true, loaded = false) => {
426
+ this.add = (obj, centered = true, loaded = false, group = false) => {
418
427
  const { editable, onAdd, gridOption, objectOption } = this;
419
428
  const option = {
420
429
  hasControls: editable,
@@ -448,15 +457,14 @@ class Handler {
448
457
  createdObj = this.addImage(newOption);
449
458
  }
450
459
  else if (obj.type === 'group') {
451
- // TODO...
452
- // Group add function needs to be fixed
453
- const objects = this.addGroup(newOption, centered, loaded);
454
- const groupOption = Object.assign({}, newOption, { objects, name: 'New Group' });
455
- createdObj = this.fabricObjects[obj.type].create(groupOption);
460
+ createdObj = this.addGroup(newOption);
456
461
  }
457
462
  else {
458
463
  createdObj = this.fabricObjects[obj.type].create(newOption);
459
464
  }
465
+ if (group) {
466
+ return createdObj;
467
+ }
460
468
  this.canvas.add(createdObj);
461
469
  this.objects = this.getObjects();
462
470
  if (!editable && !(obj.superType === 'element')) {
@@ -507,10 +515,10 @@ class Handler {
507
515
  * @param {boolean} [loaded=false]
508
516
  * @returns
509
517
  */
510
- this.addGroup = (obj, centered = true, loaded = false) => {
511
- return obj.objects.map(child => {
512
- return this.add(child, centered, loaded);
513
- });
518
+ this.addGroup = (obj) => {
519
+ const { objects = [], ...other } = obj;
520
+ const _objects = objects.map(child => this.add(child, false, true, true));
521
+ return new fabric_1.fabric.Group(_objects, other);
514
522
  };
515
523
  /**
516
524
  * Add iamge object
@@ -519,11 +527,11 @@ class Handler {
519
527
  */
520
528
  this.addImage = (obj) => {
521
529
  const { objectOption } = this;
522
- const { filters = [], ...otherOption } = obj;
530
+ const { filters = [], src, file, ...otherOption } = obj;
523
531
  const image = new Image();
524
- if (obj.src) {
525
- image.src = obj.src;
526
- }
532
+ // if (typeof src === 'string') {
533
+ // image.src = src;
534
+ // }
527
535
  const createdObj = new fabric_1.fabric.Image(image, {
528
536
  ...objectOption,
529
537
  ...otherOption,
@@ -531,7 +539,7 @@ class Handler {
531
539
  createdObj.set({
532
540
  filters: this.imageHandler.createFilters(filters),
533
541
  });
534
- this.setImage(createdObj, obj.src || obj.file);
542
+ this.setImage(createdObj, src || file);
535
543
  return createdObj;
536
544
  };
537
545
  /**
@@ -1015,31 +1023,6 @@ class Handler {
1015
1023
  }, propertiesToInclude);
1016
1024
  return true;
1017
1025
  };
1018
- /**
1019
- * Load the image
1020
- * @param {FabricImage} obj
1021
- * @param {string} src
1022
- */
1023
- this.loadImage = (obj, src) => {
1024
- let url = src;
1025
- if (!url) {
1026
- url = './images/sample/transparentBg.png';
1027
- }
1028
- fabric_1.fabric.util.loadImage(url, source => {
1029
- if (obj.type !== 'image') {
1030
- obj.set('fill', new fabric_1.fabric.Pattern({
1031
- source,
1032
- repeat: 'repeat',
1033
- }));
1034
- obj.setCoords();
1035
- this.canvas.renderAll();
1036
- return;
1037
- }
1038
- obj.setElement(source);
1039
- obj.setCoords();
1040
- this.canvas.renderAll();
1041
- });
1042
- };
1043
1026
  /**
1044
1027
  * Find object by object
1045
1028
  * @param {FabricObject} obj
@@ -1479,7 +1462,7 @@ class Handler {
1479
1462
  const anchorEl = document.createElement('a');
1480
1463
  anchorEl.href = dataUrl;
1481
1464
  anchorEl.download = `${option.name}.png`;
1482
- document.body.appendChild(anchorEl); // required for firefox
1465
+ document.body.appendChild(anchorEl);
1483
1466
  anchorEl.click();
1484
1467
  anchorEl.remove();
1485
1468
  }
@@ -1489,12 +1472,23 @@ class Handler {
1489
1472
  * @param {string} [option={ name: 'New Image', format: 'png', quality: 1 }]
1490
1473
  */
1491
1474
  this.saveCanvasImage = (option = { name: 'New Image', format: 'png', quality: 1 }) => {
1492
- const dataUrl = this.canvas.toDataURL(option);
1475
+ // If it's zoomed out/in, the container will also include in the image
1476
+ // hence need to reset the zoom level.
1477
+ this.zoomHandler.zoomOneToOne();
1478
+ const { left, top, width, height } = this.workarea;
1479
+ const dataUrl = this.canvas.toDataURL({
1480
+ ...option,
1481
+ left,
1482
+ top,
1483
+ width,
1484
+ height,
1485
+ enableRetinaScaling: true,
1486
+ });
1493
1487
  if (dataUrl) {
1494
1488
  const anchorEl = document.createElement('a');
1495
1489
  anchorEl.href = dataUrl;
1496
1490
  anchorEl.download = `${option.name}.png`;
1497
- document.body.appendChild(anchorEl); // required for firefox
1491
+ document.body.appendChild(anchorEl);
1498
1492
  anchorEl.click();
1499
1493
  anchorEl.remove();
1500
1494
  }
@@ -141,7 +141,7 @@ class ImageHandler {
141
141
  * @param {IFilter[]} filters
142
142
  */
143
143
  this.createFilters = (filters) => {
144
- const createdFilters = filters.reduce((prev, filter) => {
144
+ return filters.reduce((prev, filter) => {
145
145
  let type = filter.type;
146
146
  if (type.toLowerCase() === 'convolute' && isEqual_1.default(filter.matrix, SHARPEN_MATRIX)) {
147
147
  type = 'sharpen';
@@ -158,7 +158,6 @@ class ImageHandler {
158
158
  }
159
159
  return prev;
160
160
  }, []);
161
- return createdFilters;
162
161
  };
163
162
  /**
164
163
  * Apply filter by type
@@ -1,6 +1,6 @@
1
- import Handler from './Handler';
2
- import { FabricObject } from '../utils';
3
1
  import { NodeObject } from '../objects/Node';
2
+ import { FabricObject } from '../utils';
3
+ import Handler from './Handler';
4
4
  declare class NodeHandler {
5
5
  handler: Handler;
6
6
  constructor(handler: Handler);
@@ -26,7 +26,7 @@ declare class NodeHandler {
26
26
  */
27
27
  deselect: () => void;
28
28
  /**
29
- * Highlight node path
29
+ * Highlight path by ids
30
30
  * @param {string[]} [path]
31
31
  */
32
32
  highlightingByPath: (path?: string[]) => void;
@@ -45,6 +45,6 @@ declare class NodeHandler {
45
45
  * @param {number} [minBlur=0]
46
46
  * @param {number} [maxBlur=50]
47
47
  */
48
- highlightingNode: (object: any, duration?: number, minBlur?: number, maxBlur?: number) => void;
48
+ highlightingNode: (object: FabricObject, duration?: number, minBlur?: number, maxBlur?: number) => void;
49
49
  }
50
50
  export default NodeHandler;
@@ -162,7 +162,7 @@ class NodeHandler {
162
162
  this.handler.canvas.renderAll();
163
163
  };
164
164
  /**
165
- * Highlight node path
165
+ * Highlight path by ids
166
166
  * @param {string[]} [path]
167
167
  */
168
168
  this.highlightingByPath = (path) => {
@@ -250,7 +250,7 @@ class NodeHandler {
250
250
  object.animating = false;
251
251
  if (object.superType === 'link') {
252
252
  object.set({
253
- stroke: object.originStroke,
253
+ stroke: object.originStroke || object.stroke,
254
254
  });
255
255
  }
256
256
  },
@@ -9,8 +9,7 @@ const Link = fabric_1.fabric.util.createClass(fabric_1.fabric.Line, {
9
9
  initialize(fromNode, fromPort, toNode, toPort, options) {
10
10
  options = options || {};
11
11
  const coords = [fromPort.left, fromPort.top, toPort.left, toPort.top];
12
- this.callSuper('initialize', coords, options);
13
- this.set({
12
+ Object.assign(options, {
14
13
  strokeWidth: 4,
15
14
  id: options.id || uuidv4_1.uuid(),
16
15
  originX: 'center',
@@ -29,7 +28,9 @@ const Link = fabric_1.fabric.util.createClass(fabric_1.fabric.Line, {
29
28
  fromPort,
30
29
  toNode,
31
30
  toPort,
31
+ hoverCursor: 'pointer',
32
32
  });
33
+ this.callSuper('initialize', coords, options);
33
34
  },
34
35
  setPort(fromNode, fromPort, _toNode, toPort) {
35
36
  if (fromNode.type === 'BroadcastNode') {
@@ -1,15 +1,15 @@
1
- export { default as Gif } from './Gif';
2
1
  export { default as Arrow } from './Arrow';
3
2
  export { default as Chart } from './Chart';
3
+ export { default as CirclePort } from './CirclePort';
4
+ export { default as Cube } from './Cube';
5
+ export { default as CurvedLink } from './CurvedLink';
4
6
  export { default as Element } from './Element';
7
+ export { default as Gif } from './Gif';
5
8
  export { default as Iframe } from './Iframe';
6
- export { default as Video } from './Video';
7
- export { default as Node } from './Node';
9
+ export { default as Line } from './Line';
8
10
  export { default as Link } from './Link';
9
- export { default as CurvedLink } from './CurvedLink';
11
+ export { default as Node } from './Node';
10
12
  export { default as OrthogonalLink } from './OrthogonalLink';
11
13
  export { default as Port } from './Port';
12
- export { default as Line } from './Line';
13
- export { default as CirclePort } from './CirclePort';
14
- export { default as Cube } from './Cube';
15
14
  export { default as Svg } from './Svg';
15
+ export { default as Video } from './Video';
@@ -1,32 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var Gif_1 = require("./Gif");
4
- Object.defineProperty(exports, "Gif", { enumerable: true, get: function () { return Gif_1.default; } });
5
3
  var Arrow_1 = require("./Arrow");
6
4
  Object.defineProperty(exports, "Arrow", { enumerable: true, get: function () { return Arrow_1.default; } });
7
5
  var Chart_1 = require("./Chart");
8
6
  Object.defineProperty(exports, "Chart", { enumerable: true, get: function () { return Chart_1.default; } });
7
+ var CirclePort_1 = require("./CirclePort");
8
+ Object.defineProperty(exports, "CirclePort", { enumerable: true, get: function () { return CirclePort_1.default; } });
9
+ var Cube_1 = require("./Cube");
10
+ Object.defineProperty(exports, "Cube", { enumerable: true, get: function () { return Cube_1.default; } });
11
+ var CurvedLink_1 = require("./CurvedLink");
12
+ Object.defineProperty(exports, "CurvedLink", { enumerable: true, get: function () { return CurvedLink_1.default; } });
9
13
  var Element_1 = require("./Element");
10
14
  Object.defineProperty(exports, "Element", { enumerable: true, get: function () { return Element_1.default; } });
15
+ var Gif_1 = require("./Gif");
16
+ Object.defineProperty(exports, "Gif", { enumerable: true, get: function () { return Gif_1.default; } });
11
17
  var Iframe_1 = require("./Iframe");
12
18
  Object.defineProperty(exports, "Iframe", { enumerable: true, get: function () { return Iframe_1.default; } });
13
- var Video_1 = require("./Video");
14
- Object.defineProperty(exports, "Video", { enumerable: true, get: function () { return Video_1.default; } });
15
- var Node_1 = require("./Node");
16
- Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return Node_1.default; } });
19
+ var Line_1 = require("./Line");
20
+ Object.defineProperty(exports, "Line", { enumerable: true, get: function () { return Line_1.default; } });
17
21
  var Link_1 = require("./Link");
18
22
  Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return Link_1.default; } });
19
- var CurvedLink_1 = require("./CurvedLink");
20
- Object.defineProperty(exports, "CurvedLink", { enumerable: true, get: function () { return CurvedLink_1.default; } });
23
+ var Node_1 = require("./Node");
24
+ Object.defineProperty(exports, "Node", { enumerable: true, get: function () { return Node_1.default; } });
21
25
  var OrthogonalLink_1 = require("./OrthogonalLink");
22
26
  Object.defineProperty(exports, "OrthogonalLink", { enumerable: true, get: function () { return OrthogonalLink_1.default; } });
23
27
  var Port_1 = require("./Port");
24
28
  Object.defineProperty(exports, "Port", { enumerable: true, get: function () { return Port_1.default; } });
25
- var Line_1 = require("./Line");
26
- Object.defineProperty(exports, "Line", { enumerable: true, get: function () { return Line_1.default; } });
27
- var CirclePort_1 = require("./CirclePort");
28
- Object.defineProperty(exports, "CirclePort", { enumerable: true, get: function () { return CirclePort_1.default; } });
29
- var Cube_1 = require("./Cube");
30
- Object.defineProperty(exports, "Cube", { enumerable: true, get: function () { return Cube_1.default; } });
31
29
  var Svg_1 = require("./Svg");
32
30
  Object.defineProperty(exports, "Svg", { enumerable: true, get: function () { return Svg_1.default; } });
31
+ var Video_1 = require("./Video");
32
+ Object.defineProperty(exports, "Video", { enumerable: true, get: function () { return Video_1.default; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-design-editor",
3
- "version": "0.0.47",
3
+ "version": "0.0.50",
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",
@@ -14,6 +14,7 @@
14
14
  "build:lib": "npm run tsc && webpack --node-env production --config webpack.lib.js",
15
15
  "start": "npm install && npm run start:dev",
16
16
  "start:dev": "webpack serve --config webpack.dev.js",
17
+ "serve": "http-server docs -p 4001",
17
18
  "ghpages": "npm run build && node scripts/ghpages",
18
19
  "deploy": "npm run build:lib && npm publish",
19
20
  "lint": "npm run tsc",
@@ -40,7 +41,7 @@
40
41
  "homepage": "https://salgum1114.github.io/react-design-editor",
41
42
  "peerDependencies": {
42
43
  "animejs": "^3.0.0",
43
- "fabric": "^3.6.6",
44
+ "fabric": "^4.6.0",
44
45
  "react": "^16.14.0",
45
46
  "react-dom": "^16.14.0"
46
47
  },
@@ -50,7 +51,7 @@
50
51
  "classnames": "^2.2.6",
51
52
  "color": "^3.1.2",
52
53
  "echarts": "^4.7.0",
53
- "fabric": "^3.6.6",
54
+ "fabric": "^4.6.0",
54
55
  "gifler": "^0.1.0",
55
56
  "honeycomb-grid": "^3.1.7",
56
57
  "i18next": "^19.0.0",
@@ -89,7 +90,7 @@
89
90
  "@types/animejs": "^3.1.0",
90
91
  "@types/color": "^3.0.1",
91
92
  "@types/echarts": "^4.4.6",
92
- "@types/fabric": "^4.2.6",
93
+ "@types/fabric": "^4.5.7",
93
94
  "@types/lodash": "^4.14.150",
94
95
  "@types/react": "^16.14.21",
95
96
  "@types/react-dom": "^16.9.14",
@@ -114,16 +115,16 @@
114
115
  "fs-extra": "^9.0.0",
115
116
  "gh-pages": "^2.2.0",
116
117
  "html-webpack-plugin": "^3.2.0",
118
+ "http-server": "^14.1.0",
117
119
  "less": "^2.7.3",
118
120
  "less-loader": "^5.0.0",
119
121
  "path": "^0.12.7",
120
- "serve": "^11.3.0",
121
122
  "style-loader": "^1.1.4",
122
123
  "terser-webpack-plugin": "^4.2.3",
123
124
  "tslint": "^6.1.1",
124
125
  "tslint-react": "^5.0.0",
125
126
  "typedoc": "^0.17.4",
126
- "typescript": "^3.9.3",
127
+ "typescript": "^3.9.10",
127
128
  "url-loader": "^4.1.0",
128
129
  "webpack": "^4.46.0",
129
130
  "webpack-cli": "^4.9.1",