@leafer-in/editor 1.4.2 → 1.5.1
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/editor.cjs +116 -83
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.esm.js +117 -84
- package/dist/editor.esm.js.map +1 -1
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +116 -83
- package/dist/editor.js.map +1 -1
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +5 -5
- package/src/Editor.ts +49 -26
- package/src/config.ts +1 -0
- package/src/decorator/data.ts +10 -2
- package/src/display/EditBox.ts +28 -27
- package/src/display/EditSelect.ts +3 -3
- package/src/display/Stroker.ts +1 -1
- package/src/editor/cursor.ts +1 -1
- package/src/editor/target.ts +10 -2
- package/src/event/EditorEvent.ts +3 -0
- package/src/event/EditorGroupEvent.ts +6 -0
- package/src/event/EditorMoveEvent.ts +1 -0
- package/src/event/EditorRotateEvent.ts +1 -0
- package/src/event/EditorScaleEvent.ts +1 -0
- package/src/event/EditorSkewEvent.ts +1 -0
- package/src/helper/EditDataHelper.ts +5 -7
- package/src/index.ts +10 -36
- package/types/index.d.ts +16 -6
package/dist/editor.cjs
CHANGED
|
@@ -45,7 +45,9 @@ class EditorEvent extends draw.Event {
|
|
|
45
45
|
Object.assign(this, data);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
EditorEvent.BEFORE_SELECT = 'editor.before_select';
|
|
48
49
|
EditorEvent.SELECT = 'editor.select';
|
|
50
|
+
EditorEvent.BEFORE_HOVER = 'editor.before_hover';
|
|
49
51
|
EditorEvent.HOVER = 'editor.hover';
|
|
50
52
|
|
|
51
53
|
class EditorMoveEvent extends EditorEvent {
|
|
@@ -53,6 +55,7 @@ class EditorMoveEvent extends EditorEvent {
|
|
|
53
55
|
super(type, data);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
58
|
+
EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
|
|
56
59
|
EditorMoveEvent.MOVE = 'editor.move';
|
|
57
60
|
|
|
58
61
|
class EditorScaleEvent extends EditorEvent {
|
|
@@ -60,6 +63,7 @@ class EditorScaleEvent extends EditorEvent {
|
|
|
60
63
|
super(type, data);
|
|
61
64
|
}
|
|
62
65
|
}
|
|
66
|
+
EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
|
|
63
67
|
EditorScaleEvent.SCALE = 'editor.scale';
|
|
64
68
|
|
|
65
69
|
class EditorRotateEvent extends EditorEvent {
|
|
@@ -67,6 +71,7 @@ class EditorRotateEvent extends EditorEvent {
|
|
|
67
71
|
super(type, data);
|
|
68
72
|
}
|
|
69
73
|
}
|
|
74
|
+
EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
|
|
70
75
|
EditorRotateEvent.ROTATE = 'editor.rotate';
|
|
71
76
|
|
|
72
77
|
class EditorSkewEvent extends EditorEvent {
|
|
@@ -74,6 +79,7 @@ class EditorSkewEvent extends EditorEvent {
|
|
|
74
79
|
super(type, data);
|
|
75
80
|
}
|
|
76
81
|
}
|
|
82
|
+
EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
|
|
77
83
|
EditorSkewEvent.SKEW = 'editor.skew';
|
|
78
84
|
|
|
79
85
|
function targetAttr(fn) {
|
|
@@ -83,8 +89,12 @@ function targetAttr(fn) {
|
|
|
83
89
|
get() { return this[privateKey]; },
|
|
84
90
|
set(value) {
|
|
85
91
|
const old = this[privateKey];
|
|
86
|
-
if (old !== value)
|
|
92
|
+
if (old !== value) {
|
|
93
|
+
const type = key === 'target' ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
|
|
94
|
+
if (this.hasEvent(type))
|
|
95
|
+
this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
|
|
87
96
|
this[privateKey] = value, fn(this, old);
|
|
97
|
+
}
|
|
88
98
|
}
|
|
89
99
|
});
|
|
90
100
|
};
|
|
@@ -126,7 +136,7 @@ class Stroker extends draw.UI {
|
|
|
126
136
|
for (let i = 0; i < list.length; i++) {
|
|
127
137
|
leaf = list[i];
|
|
128
138
|
const { worldTransform, worldRenderBounds } = leaf;
|
|
129
|
-
if (!bounds || bounds.hit(worldRenderBounds, options.matrix)) {
|
|
139
|
+
if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
|
|
130
140
|
const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
|
|
131
141
|
if (aScaleX !== aScaleY) {
|
|
132
142
|
copy$1(matrix, worldTransform);
|
|
@@ -252,9 +262,9 @@ class EditSelect extends draw.Group {
|
|
|
252
262
|
}
|
|
253
263
|
onSelect() {
|
|
254
264
|
if (this.running) {
|
|
255
|
-
const { mergeConfig
|
|
256
|
-
const { stroke, strokeWidth } =
|
|
257
|
-
this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) });
|
|
265
|
+
const { mergeConfig, list } = this.editor;
|
|
266
|
+
const { stroke, strokeWidth, selectedStyle } = mergeConfig;
|
|
267
|
+
this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
|
|
258
268
|
this.hoverStroker.target = null;
|
|
259
269
|
}
|
|
260
270
|
}
|
|
@@ -441,7 +451,7 @@ const { within } = draw.MathHelper;
|
|
|
441
451
|
const EditDataHelper = {
|
|
442
452
|
getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
|
|
443
453
|
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
444
|
-
const { boxBounds, widthRange, heightRange, dragBounds } = element;
|
|
454
|
+
const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
|
|
445
455
|
const { width, height } = startBounds;
|
|
446
456
|
if (around) {
|
|
447
457
|
totalMove.x *= 2;
|
|
@@ -455,10 +465,6 @@ const EditDataHelper = {
|
|
|
455
465
|
const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
|
|
456
466
|
totalMove.x *= scaleMode ? originChangedScaleX : signX;
|
|
457
467
|
totalMove.y *= scaleMode ? originChangedScaleY : signY;
|
|
458
|
-
if (Math.abs(totalMove.x) === width)
|
|
459
|
-
totalMove.x += 0.1;
|
|
460
|
-
if (Math.abs(totalMove.y) === height)
|
|
461
|
-
totalMove.y += 0.1;
|
|
462
468
|
const topScale = (-totalMove.y + height) / height;
|
|
463
469
|
const rightScale = (totalMove.x + width) / width;
|
|
464
470
|
const bottomScale = (totalMove.y + height) / height;
|
|
@@ -548,6 +554,10 @@ const EditDataHelper = {
|
|
|
548
554
|
const nowHeight = boxBounds.height * element.scaleY;
|
|
549
555
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
|
|
550
556
|
}
|
|
557
|
+
if (Math.abs(scaleX * worldBoxBounds.width) < 1)
|
|
558
|
+
scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
|
|
559
|
+
if (Math.abs(scaleY * worldBoxBounds.height) < 1)
|
|
560
|
+
scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
|
|
551
561
|
return { origin, scaleX, scaleY, direction, lockRatio, around };
|
|
552
562
|
},
|
|
553
563
|
getRotateData(bounds, direction, current, last, around) {
|
|
@@ -676,7 +686,7 @@ function updateCursor(editor, e) {
|
|
|
676
686
|
let { rotation } = editBox;
|
|
677
687
|
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
|
|
678
688
|
const { pointType } = point, { flippedX, flippedY } = editBox;
|
|
679
|
-
let showResize = pointType
|
|
689
|
+
let showResize = pointType.includes('resize');
|
|
680
690
|
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
|
|
681
691
|
showResize = false;
|
|
682
692
|
const showSkew = skewable && !showResize && point.name === 'resize-line';
|
|
@@ -703,7 +713,7 @@ function toDataURL(svg, rotation) {
|
|
|
703
713
|
class EditPoint extends draw.Box {
|
|
704
714
|
}
|
|
705
715
|
|
|
706
|
-
const fourDirection = ['top', 'right', 'bottom', 'left'];
|
|
716
|
+
const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
|
|
707
717
|
class EditBox extends draw.Group {
|
|
708
718
|
get flipped() { return this.flippedX || this.flippedY; }
|
|
709
719
|
get flippedX() { return this.scaleX < 0; }
|
|
@@ -718,6 +728,7 @@ class EditBox extends draw.Group {
|
|
|
718
728
|
this.resizePoints = [];
|
|
719
729
|
this.rotatePoints = [];
|
|
720
730
|
this.resizeLines = [];
|
|
731
|
+
this.dragStartData = {};
|
|
721
732
|
this.__eventIds = [];
|
|
722
733
|
this.editor = editor;
|
|
723
734
|
this.visible = false;
|
|
@@ -759,7 +770,7 @@ class EditBox extends draw.Group {
|
|
|
759
770
|
resizeP.rotation = (i / 2) * 90;
|
|
760
771
|
}
|
|
761
772
|
circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
|
|
762
|
-
rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
|
|
773
|
+
rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
|
|
763
774
|
rect.hittable = !single;
|
|
764
775
|
rect.syncEventer = single && this.editor;
|
|
765
776
|
if (single) {
|
|
@@ -768,14 +779,14 @@ class EditBox extends draw.Group {
|
|
|
768
779
|
}
|
|
769
780
|
}
|
|
770
781
|
update(bounds) {
|
|
771
|
-
|
|
782
|
+
const { mergeConfig, element, multiple } = this.editor;
|
|
783
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox } = mergeConfig;
|
|
784
|
+
this.visible = !element.locked;
|
|
772
785
|
if (this.view.worldOpacity) {
|
|
773
|
-
const { mergeConfig } = this.editor;
|
|
774
786
|
const { width, height } = bounds;
|
|
775
787
|
const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
|
|
776
|
-
const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
|
|
777
788
|
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
|
|
778
|
-
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
|
|
789
|
+
const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
|
|
779
790
|
let point = {}, rotateP, resizeP, resizeL;
|
|
780
791
|
for (let i = 0; i < 8; i++) {
|
|
781
792
|
draw.AroundHelper.toPoint(draw.AroundHelper.directionData[i], bounds, point);
|
|
@@ -791,13 +802,13 @@ class EditBox extends draw.Group {
|
|
|
791
802
|
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
792
803
|
if (((i + 1) / 2) % 2) {
|
|
793
804
|
resizeL.width = width;
|
|
794
|
-
if (resizeP.width > width
|
|
805
|
+
if (hideOnSmall && resizeP.width * 2 > width)
|
|
795
806
|
resizeP.visible = false;
|
|
796
807
|
}
|
|
797
808
|
else {
|
|
798
809
|
resizeL.height = height;
|
|
799
810
|
resizeP.rotation = 90;
|
|
800
|
-
if (resizeP.width > height
|
|
811
|
+
if (hideOnSmall && resizeP.width * 2 > height)
|
|
801
812
|
resizeP.visible = false;
|
|
802
813
|
}
|
|
803
814
|
}
|
|
@@ -807,7 +818,7 @@ class EditBox extends draw.Group {
|
|
|
807
818
|
this.layoutCircle(mergeConfig);
|
|
808
819
|
if (rect.path)
|
|
809
820
|
rect.path = null;
|
|
810
|
-
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
821
|
+
rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
|
|
811
822
|
buttons.visible = showPoints && buttons.children.length > 0;
|
|
812
823
|
if (buttons.visible)
|
|
813
824
|
this.layoutButtons(mergeConfig);
|
|
@@ -854,7 +865,7 @@ class EditBox extends draw.Group {
|
|
|
854
865
|
}
|
|
855
866
|
getPointStyle(userStyle) {
|
|
856
867
|
const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
|
|
857
|
-
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0 };
|
|
868
|
+
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
|
|
858
869
|
return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
|
|
859
870
|
}
|
|
860
871
|
getPointsStyle() {
|
|
@@ -874,34 +885,32 @@ class EditBox extends draw.Group {
|
|
|
874
885
|
}
|
|
875
886
|
onDragStart(e) {
|
|
876
887
|
this.dragging = true;
|
|
877
|
-
const
|
|
878
|
-
|
|
888
|
+
const point = this.dragPoint = e.current;
|
|
889
|
+
const { editor, dragStartData } = this, { element } = editor;
|
|
890
|
+
if (point.name === 'rect') {
|
|
879
891
|
this.moving = true;
|
|
880
|
-
editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
|
|
881
892
|
editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
|
|
882
893
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
894
|
+
dragStartData.x = e.x;
|
|
895
|
+
dragStartData.y = e.y;
|
|
896
|
+
dragStartData.point = { x: element.x, y: element.y };
|
|
897
|
+
dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
|
|
898
|
+
dragStartData.rotation = element.rotation;
|
|
887
899
|
}
|
|
888
900
|
onDragEnd(e) {
|
|
889
901
|
this.dragging = false;
|
|
902
|
+
this.dragPoint = null;
|
|
890
903
|
this.moving = false;
|
|
891
904
|
if (e.current.name === 'rect')
|
|
892
905
|
this.editor.opacity = 1;
|
|
893
|
-
this.editor.resizeDirection = undefined;
|
|
894
906
|
}
|
|
895
907
|
onDrag(e) {
|
|
896
908
|
const { editor } = this;
|
|
897
|
-
const
|
|
898
|
-
if (
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
else if (point.pointType === 'resize') {
|
|
909
|
+
const { pointType } = this.enterPoint = e.current;
|
|
910
|
+
if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable)
|
|
911
|
+
editor.onRotate(e);
|
|
912
|
+
if (pointType.includes('resize'))
|
|
903
913
|
editor.onScale(e);
|
|
904
|
-
}
|
|
905
914
|
updateCursor(editor, e);
|
|
906
915
|
}
|
|
907
916
|
onArrow(e) {
|
|
@@ -1079,6 +1088,7 @@ const config = {
|
|
|
1079
1088
|
rotateCursor: { url: rotateSVG, x: 12, y: 12 },
|
|
1080
1089
|
skewCursor: { url: skewSVG, x: 12, y: 12 },
|
|
1081
1090
|
selector: true,
|
|
1091
|
+
editBox: true,
|
|
1082
1092
|
hover: true,
|
|
1083
1093
|
select: 'press',
|
|
1084
1094
|
openInner: 'double',
|
|
@@ -1108,7 +1118,11 @@ function simulate(editor) {
|
|
|
1108
1118
|
function onTarget(editor, oldValue) {
|
|
1109
1119
|
const { target } = editor;
|
|
1110
1120
|
if (target) {
|
|
1111
|
-
editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
|
|
1121
|
+
const { list } = editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
|
|
1122
|
+
if (!list.every(checkEditable)) {
|
|
1123
|
+
editor.target = list.filter(checkEditable);
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1112
1126
|
if (editor.multiple)
|
|
1113
1127
|
simulate(editor);
|
|
1114
1128
|
}
|
|
@@ -1135,6 +1149,9 @@ function onTarget(editor, oldValue) {
|
|
|
1135
1149
|
function onHover(editor, oldValue) {
|
|
1136
1150
|
editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
|
|
1137
1151
|
}
|
|
1152
|
+
function checkEditable(item) {
|
|
1153
|
+
return item.editable && !item.locked;
|
|
1154
|
+
}
|
|
1138
1155
|
|
|
1139
1156
|
const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
|
|
1140
1157
|
const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
|
|
@@ -1232,10 +1249,13 @@ class EditorGroupEvent extends EditorEvent {
|
|
|
1232
1249
|
super(type, data);
|
|
1233
1250
|
}
|
|
1234
1251
|
}
|
|
1252
|
+
EditorGroupEvent.BEFORE_GROUP = 'editor.before_group';
|
|
1235
1253
|
EditorGroupEvent.GROUP = 'editor.group';
|
|
1236
1254
|
EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
|
|
1237
1255
|
EditorGroupEvent.UNGROUP = 'editor.ungroup';
|
|
1256
|
+
EditorGroupEvent.BEFORE_OPEN = 'editor.before_open_group';
|
|
1238
1257
|
EditorGroupEvent.OPEN = 'editor.open_group';
|
|
1258
|
+
EditorGroupEvent.BEFORE_CLOSE = 'editor.before_close_group';
|
|
1239
1259
|
EditorGroupEvent.CLOSE = 'editor.close_group';
|
|
1240
1260
|
|
|
1241
1261
|
const { updateMatrix } = draw.LeafHelper;
|
|
@@ -1298,8 +1318,20 @@ class SimulateElement extends draw.Rect {
|
|
|
1298
1318
|
|
|
1299
1319
|
class Editor extends draw.Group {
|
|
1300
1320
|
get mergeConfig() {
|
|
1301
|
-
const { element,
|
|
1302
|
-
|
|
1321
|
+
const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
|
|
1322
|
+
if (element && element.editConfig)
|
|
1323
|
+
Object.assign(mergeConfig, element.editConfig);
|
|
1324
|
+
if (dragPoint) {
|
|
1325
|
+
if (dragPoint.editConfig)
|
|
1326
|
+
Object.assign(mergeConfig, dragPoint.editConfig);
|
|
1327
|
+
if (mergeConfig.editSize === 'font-size')
|
|
1328
|
+
mergeConfig.lockRatio = true;
|
|
1329
|
+
if (dragPoint.pointType === 'resize-rotate') {
|
|
1330
|
+
mergeConfig.around || (mergeConfig.around = 'center');
|
|
1331
|
+
draw.isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
return mergeConfig;
|
|
1303
1335
|
}
|
|
1304
1336
|
get list() { return this.leafList.list; }
|
|
1305
1337
|
get dragHoverExclude() { return [this.editBox.rect]; }
|
|
@@ -1309,6 +1341,7 @@ class Editor extends draw.Group {
|
|
|
1309
1341
|
get single() { return this.list.length === 1; }
|
|
1310
1342
|
get dragging() { return this.editBox.dragging; }
|
|
1311
1343
|
get moving() { return this.editBox.moving; }
|
|
1344
|
+
get dragPoint() { return this.editBox.dragPoint; }
|
|
1312
1345
|
get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
|
|
1313
1346
|
get buttons() { return this.editBox.buttons; }
|
|
1314
1347
|
constructor(userConfig, data) {
|
|
@@ -1399,7 +1432,7 @@ class Editor extends draw.Group {
|
|
|
1399
1432
|
else
|
|
1400
1433
|
total.x = 0;
|
|
1401
1434
|
}
|
|
1402
|
-
this.move(core.DragEvent.getValidMove(this.element, this.
|
|
1435
|
+
this.move(core.DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
|
|
1403
1436
|
}
|
|
1404
1437
|
}
|
|
1405
1438
|
onScale(e) {
|
|
@@ -1413,7 +1446,7 @@ class Editor extends draw.Group {
|
|
|
1413
1446
|
const { direction } = e.current;
|
|
1414
1447
|
if (e.shiftKey || element.lockRatio)
|
|
1415
1448
|
lockRatio = true;
|
|
1416
|
-
const data = EditDataHelper.getScaleData(element, this.
|
|
1449
|
+
const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
|
|
1417
1450
|
if (this.editTool.onScaleWithDrag) {
|
|
1418
1451
|
data.drag = e;
|
|
1419
1452
|
this.scaleWithDrag(data);
|
|
@@ -1428,26 +1461,29 @@ class Editor extends draw.Group {
|
|
|
1428
1461
|
const { direction, name } = e.current;
|
|
1429
1462
|
if (skewable && name === 'resize-line')
|
|
1430
1463
|
return this.onSkew(e);
|
|
1431
|
-
const { element } = this;
|
|
1464
|
+
const { element } = this, { dragStartData } = this.editBox;
|
|
1432
1465
|
let origin, rotation;
|
|
1433
1466
|
if (e instanceof core.RotateEvent) {
|
|
1434
1467
|
if (rotateable === 'rotate')
|
|
1435
1468
|
e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
|
|
1436
1469
|
else
|
|
1437
1470
|
return;
|
|
1471
|
+
if (element.scaleX * element.scaleY < 0)
|
|
1472
|
+
rotation = -rotation;
|
|
1438
1473
|
}
|
|
1439
1474
|
else {
|
|
1440
|
-
const
|
|
1441
|
-
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(last), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
|
|
1475
|
+
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
|
|
1442
1476
|
rotation = data.rotation;
|
|
1443
1477
|
origin = data.origin;
|
|
1444
1478
|
}
|
|
1445
|
-
rotation = draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
|
|
1446
|
-
if (!rotation)
|
|
1447
|
-
return;
|
|
1448
1479
|
if (element.scaleX * element.scaleY < 0)
|
|
1449
1480
|
rotation = -rotation;
|
|
1450
|
-
|
|
1481
|
+
if (e instanceof core.DragEvent)
|
|
1482
|
+
rotation = dragStartData.rotation + rotation - element.rotation;
|
|
1483
|
+
rotation = draw.MathHelper.float(draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
|
|
1484
|
+
if (!rotation)
|
|
1485
|
+
return;
|
|
1486
|
+
this.rotateOf(origin, rotation);
|
|
1451
1487
|
}
|
|
1452
1488
|
onSkew(e) {
|
|
1453
1489
|
const { element } = this;
|
|
@@ -1464,7 +1500,9 @@ class Editor extends draw.Group {
|
|
|
1464
1500
|
const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
|
|
1465
1501
|
if (this.multiple)
|
|
1466
1502
|
element.safeChange(() => element.move(x, y));
|
|
1467
|
-
const
|
|
1503
|
+
const data = { target: element, editor: this, moveX: world.x, moveY: world.y };
|
|
1504
|
+
this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
|
|
1505
|
+
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
|
|
1468
1506
|
this.editTool.onMove(event);
|
|
1469
1507
|
this.emitEvent(event);
|
|
1470
1508
|
}
|
|
@@ -1472,7 +1510,9 @@ class Editor extends draw.Group {
|
|
|
1472
1510
|
if (!this.checkTransform('resizeable'))
|
|
1473
1511
|
return;
|
|
1474
1512
|
const { element } = this;
|
|
1475
|
-
|
|
1513
|
+
data = Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) });
|
|
1514
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1515
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1476
1516
|
this.editTool.onScaleWithDrag(event);
|
|
1477
1517
|
this.emitEvent(event);
|
|
1478
1518
|
}
|
|
@@ -1482,7 +1522,9 @@ class Editor extends draw.Group {
|
|
|
1482
1522
|
const { element } = this;
|
|
1483
1523
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1484
1524
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
|
|
1485
|
-
const
|
|
1525
|
+
const data = { target: element, editor: this, worldOrigin, scaleX, scaleY, transform };
|
|
1526
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1527
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1486
1528
|
this.editTool.onScale(event);
|
|
1487
1529
|
this.emitEvent(event);
|
|
1488
1530
|
}
|
|
@@ -1492,7 +1534,9 @@ class Editor extends draw.Group {
|
|
|
1492
1534
|
const { element } = this;
|
|
1493
1535
|
const worldOrigin = this.getWorldOrigin('center');
|
|
1494
1536
|
const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new draw.Matrix(draw.LeafHelper.getFlipTransform(element, axis));
|
|
1495
|
-
const
|
|
1537
|
+
const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
|
|
1538
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1539
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1496
1540
|
this.editTool.onScale(event);
|
|
1497
1541
|
this.emitEvent(event);
|
|
1498
1542
|
}
|
|
@@ -1502,7 +1546,9 @@ class Editor extends draw.Group {
|
|
|
1502
1546
|
const { element } = this;
|
|
1503
1547
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1504
1548
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
|
|
1505
|
-
const
|
|
1549
|
+
const data = { target: element, editor: this, worldOrigin, rotation, transform };
|
|
1550
|
+
this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
|
|
1551
|
+
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
|
|
1506
1552
|
this.editTool.onRotate(event);
|
|
1507
1553
|
this.emitEvent(event);
|
|
1508
1554
|
}
|
|
@@ -1512,7 +1558,9 @@ class Editor extends draw.Group {
|
|
|
1512
1558
|
const { element } = this;
|
|
1513
1559
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1514
1560
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
|
|
1515
|
-
const
|
|
1561
|
+
const data = { target: element, editor: this, worldOrigin, skewX, skewY, transform };
|
|
1562
|
+
this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
|
|
1563
|
+
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
|
|
1516
1564
|
this.editTool.onSkew(event);
|
|
1517
1565
|
this.emitEvent(event);
|
|
1518
1566
|
}
|
|
@@ -1530,6 +1578,7 @@ class Editor extends draw.Group {
|
|
|
1530
1578
|
}
|
|
1531
1579
|
group(userGroup) {
|
|
1532
1580
|
if (this.multiple) {
|
|
1581
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
|
|
1533
1582
|
this.target = EditorHelper.group(this.list, this.element, userGroup);
|
|
1534
1583
|
this.emitGroupEvent(EditorGroupEvent.GROUP, this.target);
|
|
1535
1584
|
}
|
|
@@ -1545,11 +1594,13 @@ class Editor extends draw.Group {
|
|
|
1545
1594
|
return this.list;
|
|
1546
1595
|
}
|
|
1547
1596
|
openGroup(group) {
|
|
1597
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_OPEN, group);
|
|
1548
1598
|
this.openedGroupList.add(group);
|
|
1549
1599
|
group.hitChildren = true;
|
|
1550
1600
|
this.emitGroupEvent(EditorGroupEvent.OPEN, group);
|
|
1551
1601
|
}
|
|
1552
1602
|
closeGroup(group) {
|
|
1603
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_CLOSE, group);
|
|
1553
1604
|
this.openedGroupList.remove(group);
|
|
1554
1605
|
group.hitChildren = false;
|
|
1555
1606
|
this.emitGroupEvent(EditorGroupEvent.CLOSE, group);
|
|
@@ -1578,7 +1629,8 @@ class Editor extends draw.Group {
|
|
|
1578
1629
|
emitGroupEvent(type, group) {
|
|
1579
1630
|
const event = new EditorGroupEvent(type, { editTarget: group });
|
|
1580
1631
|
this.emitEvent(event);
|
|
1581
|
-
group
|
|
1632
|
+
if (group)
|
|
1633
|
+
group.emitEvent(event);
|
|
1582
1634
|
}
|
|
1583
1635
|
openInnerEditor(target, select) {
|
|
1584
1636
|
if (target && select)
|
|
@@ -1908,34 +1960,15 @@ exports.LineEditTool = __decorate([
|
|
|
1908
1960
|
|
|
1909
1961
|
draw.Plugin.add('editor', 'resize');
|
|
1910
1962
|
draw.Creator.editor = function (options) { return new Editor(options); };
|
|
1911
|
-
draw.
|
|
1912
|
-
draw.
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
draw.
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
draw.
|
|
1919
|
-
|
|
1920
|
-
});
|
|
1921
|
-
draw.defineKey(draw.Text.prototype, 'editInner', {
|
|
1922
|
-
get() { return 'TextEditor'; }
|
|
1923
|
-
});
|
|
1924
|
-
draw.UI.setEditConfig = function (config) {
|
|
1925
|
-
draw.defineKey(this.prototype, 'editConfig', {
|
|
1926
|
-
get() { return typeof config === 'function' ? config(this) : config; }
|
|
1927
|
-
});
|
|
1928
|
-
};
|
|
1929
|
-
draw.UI.setEditOuter = function (toolName) {
|
|
1930
|
-
draw.defineKey(this.prototype, 'editOuter', {
|
|
1931
|
-
get() { return typeof toolName === 'string' ? toolName : toolName(this); }
|
|
1932
|
-
});
|
|
1933
|
-
};
|
|
1934
|
-
draw.UI.setEditInner = function (editorName) {
|
|
1935
|
-
draw.defineKey(this.prototype, 'editInner', {
|
|
1936
|
-
get() { return typeof editorName === 'string' ? editorName : editorName(this); }
|
|
1937
|
-
});
|
|
1938
|
-
};
|
|
1963
|
+
draw.Box.addAttr('textBox', false, draw.dataType);
|
|
1964
|
+
draw.UI.addAttr('editConfig', undefined, draw.dataType);
|
|
1965
|
+
draw.UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', draw.dataType);
|
|
1966
|
+
draw.UI.addAttr('editInner', 'PathEditor', draw.dataType);
|
|
1967
|
+
draw.Group.addAttr('editInner', '', draw.dataType);
|
|
1968
|
+
draw.Text.addAttr('editInner', 'TextEditor', draw.dataType);
|
|
1969
|
+
draw.UI.setEditConfig = function (config) { this.changeAttr('editConfig', config); };
|
|
1970
|
+
draw.UI.setEditOuter = function (toolName) { this.changeAttr('editOuter', toolName); };
|
|
1971
|
+
draw.UI.setEditInner = function (editorName) { this.changeAttr('editInner', editorName); };
|
|
1939
1972
|
|
|
1940
1973
|
exports.EditBox = EditBox;
|
|
1941
1974
|
exports.EditDataHelper = EditDataHelper;
|