react-design-editor 0.0.38 → 0.0.42
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.
- package/dist/react-design-editor.js +921 -851
- package/dist/react-design-editor.min.js +1 -1
- package/lib/handlers/Handler.js +19 -5
- package/lib/objects/Svg.js +30 -6
- package/package.json +1 -1
package/lib/handlers/Handler.js
CHANGED
|
@@ -140,13 +140,11 @@ class Handler {
|
|
|
140
140
|
if (!activeObject) {
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
|
-
if (
|
|
143
|
+
if (activeObject.type === 'svg' && (key === 'fill' || key === 'stroke')) {
|
|
144
144
|
activeObject._objects.forEach(obj => obj.set(key, value));
|
|
145
145
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
activeObject.setCoords();
|
|
149
|
-
}
|
|
146
|
+
activeObject.set(key, value);
|
|
147
|
+
activeObject.setCoords();
|
|
150
148
|
this.canvas.requestRenderAll();
|
|
151
149
|
const { id, superType, type, player, width, height } = activeObject;
|
|
152
150
|
if (superType === 'element') {
|
|
@@ -224,6 +222,14 @@ class Handler {
|
|
|
224
222
|
if (!obj) {
|
|
225
223
|
return;
|
|
226
224
|
}
|
|
225
|
+
if (obj.type === 'svg') {
|
|
226
|
+
if (key === 'fill') {
|
|
227
|
+
obj.setFill(value);
|
|
228
|
+
}
|
|
229
|
+
else if (key === 'stroke') {
|
|
230
|
+
obj.setStroke(value);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
227
233
|
obj.set(key, value);
|
|
228
234
|
obj.setCoords();
|
|
229
235
|
this.canvas.renderAll();
|
|
@@ -271,6 +277,14 @@ class Handler {
|
|
|
271
277
|
if (!obj) {
|
|
272
278
|
return;
|
|
273
279
|
}
|
|
280
|
+
if (obj.type === 'svg') {
|
|
281
|
+
if (option.fill) {
|
|
282
|
+
obj.setFill(option.fill);
|
|
283
|
+
}
|
|
284
|
+
else if (option.stroke) {
|
|
285
|
+
obj.setStroke(option.stroke);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
274
288
|
obj.set(option);
|
|
275
289
|
obj.setCoords();
|
|
276
290
|
this.canvas.renderAll();
|
package/lib/objects/Svg.js
CHANGED
|
@@ -5,21 +5,38 @@ const utils_1 = require("../utils");
|
|
|
5
5
|
const Svg = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
6
6
|
type: 'svg',
|
|
7
7
|
initialize(option = {}) {
|
|
8
|
-
const { svg, loadType } = option;
|
|
9
8
|
this.callSuper('initialize', [], option);
|
|
10
|
-
this.loadSvg(
|
|
9
|
+
this.loadSvg(option);
|
|
11
10
|
},
|
|
12
11
|
addSvgElements(objects, options, path) {
|
|
13
12
|
const createdObj = fabric_1.fabric.util.groupSVGElements(objects, options, path);
|
|
14
13
|
this.set(options);
|
|
15
14
|
if (createdObj.getObjects) {
|
|
16
|
-
createdObj.getObjects().forEach(obj =>
|
|
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
|
+
});
|
|
17
24
|
}
|
|
18
25
|
else {
|
|
19
26
|
createdObj.set({
|
|
20
27
|
originX: 'center',
|
|
21
28
|
originY: 'center',
|
|
22
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
|
+
}
|
|
23
40
|
this.add(createdObj);
|
|
24
41
|
}
|
|
25
42
|
this.setCoords();
|
|
@@ -27,20 +44,27 @@ const Svg = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
|
27
44
|
this.canvas.requestRenderAll();
|
|
28
45
|
}
|
|
29
46
|
},
|
|
30
|
-
loadSvg(
|
|
47
|
+
loadSvg(option) {
|
|
48
|
+
const { svg, loadType, fill, stroke } = option;
|
|
31
49
|
return new Promise(resolve => {
|
|
32
50
|
if (loadType === 'svg') {
|
|
33
51
|
fabric_1.fabric.loadSVGFromString(svg, (objects, options) => {
|
|
34
|
-
resolve(this.addSvgElements(objects, options, svg));
|
|
52
|
+
resolve(this.addSvgElements(objects, { ...options, fill, stroke }, svg));
|
|
35
53
|
});
|
|
36
54
|
}
|
|
37
55
|
else {
|
|
38
56
|
fabric_1.fabric.loadSVGFromURL(svg, (objects, options) => {
|
|
39
|
-
resolve(this.addSvgElements(objects, options, svg));
|
|
57
|
+
resolve(this.addSvgElements(objects, { ...options, fill, stroke }, svg));
|
|
40
58
|
});
|
|
41
59
|
}
|
|
42
60
|
});
|
|
43
61
|
},
|
|
62
|
+
setFill(value) {
|
|
63
|
+
this.getObjects().forEach((obj) => obj.set('fill', value));
|
|
64
|
+
},
|
|
65
|
+
setStroke(value) {
|
|
66
|
+
this.getObjects().forEach((obj) => obj.set('stroke', value));
|
|
67
|
+
},
|
|
44
68
|
toObject(propertiesToInclude) {
|
|
45
69
|
return utils_1.toObject(this, propertiesToInclude, {
|
|
46
70
|
svg: this.get('svg'),
|