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