react-design-editor 0.0.42 → 0.0.46

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.
@@ -1,9 +1,3 @@
1
- /*
2
- object-assign
3
- (c) Sindre Sorhus
4
- @license MIT
5
- */
6
-
7
1
  /*!
8
2
  * MediaElement.js
9
3
  * http://www.mediaelementjs.com/
@@ -35,21 +29,3 @@ object-assign
35
29
  * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
36
30
  * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
37
31
  */
38
-
39
- /** @license React v0.19.1
40
- * scheduler.production.min.js
41
- *
42
- * Copyright (c) Facebook, Inc. and its affiliates.
43
- *
44
- * This source code is licensed under the MIT license found in the
45
- * LICENSE file in the root directory of this source tree.
46
- */
47
-
48
- /** @license React v16.14.0
49
- * react-dom.production.min.js
50
- *
51
- * Copyright (c) Facebook, Inc. and its affiliates.
52
- *
53
- * This source code is licensed under the MIT license found in the
54
- * LICENSE file in the root directory of this source tree.
55
- */
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const animejs_1 = __importDefault(require("animejs"));
7
+ const warning_1 = __importDefault(require("warning"));
7
8
  class AnimationHandler {
8
9
  constructor(handler) {
9
10
  /**
@@ -164,6 +165,14 @@ class AnimationHandler {
164
165
  });
165
166
  }
166
167
  else if (type === 'flash') {
168
+ if (obj.type === 'svg') {
169
+ obj._objects.forEach(child => this.handler.setByPartial(child, {
170
+ fill: child.originFill,
171
+ stroke: child.originStroke,
172
+ originFill: null,
173
+ originStroke: null,
174
+ }));
175
+ }
167
176
  Object.assign(option, {
168
177
  fill: obj.originFill,
169
178
  stroke: obj.originStroke,
@@ -205,11 +214,19 @@ class AnimationHandler {
205
214
  update: (instance) => {
206
215
  if (type === 'flash') {
207
216
  // I don't know why it works. Magic code...
208
- const fill = instance.animations[0].currentValue;
209
- const stroke = instance.animations[1].currentValue;
210
- obj.set('fill', '');
211
- obj.set('fill', fill);
212
- obj.set('stroke', stroke);
217
+ warning_1.default(instance.animations[0], 'instance.animations[0] undefined.');
218
+ warning_1.default(instance.animations[1], 'instance.animations[1] undefined.');
219
+ const fill = instance.animations[0]?.currentValue;
220
+ const stroke = instance.animations[1]?.currentValue;
221
+ if (obj.type === 'svg') {
222
+ obj.setFill(fill);
223
+ obj.setStroke(stroke);
224
+ }
225
+ else {
226
+ obj.set('fill', '');
227
+ obj.set('fill', fill);
228
+ obj.set('stroke', stroke);
229
+ }
213
230
  }
214
231
  else if (type === 'rotation') {
215
232
  let angle = instance.animations[0].currentValue;
@@ -303,6 +320,12 @@ class AnimationHandler {
303
320
  }
304
321
  else if (type === 'flash') {
305
322
  const { fill = obj.fill, stroke = obj.stroke } = other;
323
+ if (obj.type === 'svg') {
324
+ obj._objects.forEach(child => this.handler.setByPartial(child, {
325
+ originFill: child.fill,
326
+ originStroke: child.stroke,
327
+ }));
328
+ }
306
329
  obj.set('originFill', obj.fill);
307
330
  obj.set('originStroke', obj.stroke);
308
331
  Object.assign(option, {
@@ -1227,24 +1227,23 @@ class Handler {
1227
1227
  let prevLeft = 0;
1228
1228
  let prevTop = 0;
1229
1229
  this.canvas.setBackgroundColor(this.canvasOption.backgroundColor, this.canvas.renderAll.bind(this.canvas));
1230
- const workareaExist = json.filter((obj) => obj.id === 'workarea');
1230
+ const workarea = json.find((obj) => obj.id === 'workarea');
1231
1231
  if (!this.workarea) {
1232
1232
  this.workareaHandler.initialize();
1233
1233
  }
1234
- if (!workareaExist.length) {
1235
- this.canvas.centerObject(this.workarea);
1236
- this.workarea.setCoords();
1237
- prevLeft = this.workarea.left;
1238
- prevTop = this.workarea.top;
1239
- }
1240
- else {
1241
- const workarea = workareaExist[0];
1234
+ if (workarea) {
1242
1235
  prevLeft = workarea.left;
1243
1236
  prevTop = workarea.top;
1244
1237
  this.workarea.set(workarea);
1245
1238
  await this.workareaHandler.setImage(workarea.src, true);
1246
1239
  this.workarea.setCoords();
1247
1240
  }
1241
+ else {
1242
+ this.canvas.centerObject(this.workarea);
1243
+ this.workarea.setCoords();
1244
+ prevLeft = this.workarea.left;
1245
+ prevTop = this.workarea.top;
1246
+ }
1248
1247
  json.forEach((obj) => {
1249
1248
  if (obj.id === 'workarea') {
1250
1249
  return;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="lodash" />
2
- import Handler from './Handler';
3
2
  import { FabricObject } from '../utils';
3
+ import Handler from './Handler';
4
4
  declare class TooltipHandler {
5
5
  handler: Handler;
6
6
  tooltipEl: HTMLDivElement;
@@ -3,8 +3,8 @@ 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
- const react_dom_1 = __importDefault(require("react-dom"));
7
6
  const debounce_1 = __importDefault(require("lodash/debounce"));
7
+ const react_dom_1 = __importDefault(require("react-dom"));
8
8
  class TooltipHandler {
9
9
  constructor(handler) {
10
10
  /**
@@ -22,7 +22,7 @@ class TooltipHandler {
22
22
  let element = target.name;
23
23
  const { onTooltip } = this.handler;
24
24
  if (onTooltip) {
25
- element = await onTooltip(this.tooltipEl, target);
25
+ element = await onTooltip(tooltip, target);
26
26
  if (!element) {
27
27
  return;
28
28
  }
@@ -1,5 +1,9 @@
1
1
  import { FabricGroup, FabricObject, FabricObjectOption } from '../utils';
2
- export declare type SvgObject = FabricGroup | FabricObject;
2
+ export declare type SvgObject = (FabricGroup | FabricObject) & {
3
+ loadSvg(option: SvgOption): Promise<SvgObject>;
4
+ setFill(value: string): SvgObject;
5
+ setStroke(value: string): SvgObject;
6
+ };
3
7
  export interface SvgOption extends FabricObjectOption {
4
8
  svg?: string;
5
9
  loadType?: 'file' | 'svg';
@@ -37,12 +37,20 @@ const Svg = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
37
37
  stroke: options.stroke,
38
38
  });
39
39
  }
40
+ // if (this._objects?.length) {
41
+ // (this as FabricGroup)._objects.forEach(obj => this.remove(obj));
42
+ // }
40
43
  this.add(createdObj);
41
44
  }
45
+ this.set({
46
+ fill: options.fill || 'rgba(0, 0, 0, 1)',
47
+ stroke: options.stroke || 'rgba(255, 255, 255, 0)',
48
+ });
42
49
  this.setCoords();
43
50
  if (this.canvas) {
44
51
  this.canvas.requestRenderAll();
45
52
  }
53
+ return this;
46
54
  },
47
55
  loadSvg(option) {
48
56
  const { svg, loadType, fill, stroke } = option;
@@ -61,9 +69,11 @@ const Svg = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
61
69
  },
62
70
  setFill(value) {
63
71
  this.getObjects().forEach((obj) => obj.set('fill', value));
72
+ return this;
64
73
  },
65
74
  setStroke(value) {
66
75
  this.getObjects().forEach((obj) => obj.set('stroke', value));
76
+ return this;
67
77
  },
68
78
  toObject(propertiesToInclude) {
69
79
  return utils_1.toObject(this, propertiesToInclude, {
@@ -81,9 +81,10 @@ export declare type FabricObjectOption<T extends any = fabric.IObjectOptions> =
81
81
  originAngle?: number;
82
82
  /**
83
83
  * Original fill color
84
- * @type {(string | fabric.Pattern)}
84
+ *
85
+ * @type {(string | fabric.Pattern | fabric.Gradient)}
85
86
  */
86
- originFill?: string | fabric.Pattern;
87
+ originFill?: string | fabric.Pattern | fabric.Gradient;
87
88
  /**
88
89
  * Original stroke color
89
90
  * @type {string}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-design-editor",
3
- "version": "0.0.42",
3
+ "version": "0.0.46",
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",