@leafer-in/editor 1.4.2 → 1.5.0
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 +109 -82
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.esm.js +110 -83
- 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 +109 -82
- 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/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/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 +14 -6
package/dist/editor.cjs
CHANGED
|
@@ -53,6 +53,7 @@ class EditorMoveEvent extends EditorEvent {
|
|
|
53
53
|
super(type, data);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
|
|
56
57
|
EditorMoveEvent.MOVE = 'editor.move';
|
|
57
58
|
|
|
58
59
|
class EditorScaleEvent extends EditorEvent {
|
|
@@ -60,6 +61,7 @@ class EditorScaleEvent extends EditorEvent {
|
|
|
60
61
|
super(type, data);
|
|
61
62
|
}
|
|
62
63
|
}
|
|
64
|
+
EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
|
|
63
65
|
EditorScaleEvent.SCALE = 'editor.scale';
|
|
64
66
|
|
|
65
67
|
class EditorRotateEvent extends EditorEvent {
|
|
@@ -67,6 +69,7 @@ class EditorRotateEvent extends EditorEvent {
|
|
|
67
69
|
super(type, data);
|
|
68
70
|
}
|
|
69
71
|
}
|
|
72
|
+
EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
|
|
70
73
|
EditorRotateEvent.ROTATE = 'editor.rotate';
|
|
71
74
|
|
|
72
75
|
class EditorSkewEvent extends EditorEvent {
|
|
@@ -74,6 +77,7 @@ class EditorSkewEvent extends EditorEvent {
|
|
|
74
77
|
super(type, data);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
80
|
+
EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
|
|
77
81
|
EditorSkewEvent.SKEW = 'editor.skew';
|
|
78
82
|
|
|
79
83
|
function targetAttr(fn) {
|
|
@@ -126,7 +130,7 @@ class Stroker extends draw.UI {
|
|
|
126
130
|
for (let i = 0; i < list.length; i++) {
|
|
127
131
|
leaf = list[i];
|
|
128
132
|
const { worldTransform, worldRenderBounds } = leaf;
|
|
129
|
-
if (!bounds || bounds.hit(worldRenderBounds, options.matrix)) {
|
|
133
|
+
if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
|
|
130
134
|
const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
|
|
131
135
|
if (aScaleX !== aScaleY) {
|
|
132
136
|
copy$1(matrix, worldTransform);
|
|
@@ -252,9 +256,9 @@ class EditSelect extends draw.Group {
|
|
|
252
256
|
}
|
|
253
257
|
onSelect() {
|
|
254
258
|
if (this.running) {
|
|
255
|
-
const { mergeConfig
|
|
256
|
-
const { stroke, strokeWidth } =
|
|
257
|
-
this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) });
|
|
259
|
+
const { mergeConfig, list } = this.editor;
|
|
260
|
+
const { stroke, strokeWidth, selectedStyle } = mergeConfig;
|
|
261
|
+
this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
|
|
258
262
|
this.hoverStroker.target = null;
|
|
259
263
|
}
|
|
260
264
|
}
|
|
@@ -441,7 +445,7 @@ const { within } = draw.MathHelper;
|
|
|
441
445
|
const EditDataHelper = {
|
|
442
446
|
getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
|
|
443
447
|
let align, origin = {}, scaleX = 1, scaleY = 1;
|
|
444
|
-
const { boxBounds, widthRange, heightRange, dragBounds } = element;
|
|
448
|
+
const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
|
|
445
449
|
const { width, height } = startBounds;
|
|
446
450
|
if (around) {
|
|
447
451
|
totalMove.x *= 2;
|
|
@@ -455,10 +459,6 @@ const EditDataHelper = {
|
|
|
455
459
|
const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
|
|
456
460
|
totalMove.x *= scaleMode ? originChangedScaleX : signX;
|
|
457
461
|
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
462
|
const topScale = (-totalMove.y + height) / height;
|
|
463
463
|
const rightScale = (totalMove.x + width) / width;
|
|
464
464
|
const bottomScale = (totalMove.y + height) / height;
|
|
@@ -548,6 +548,10 @@ const EditDataHelper = {
|
|
|
548
548
|
const nowHeight = boxBounds.height * element.scaleY;
|
|
549
549
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
|
|
550
550
|
}
|
|
551
|
+
if (Math.abs(scaleX * worldBoxBounds.width) < 1)
|
|
552
|
+
scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
|
|
553
|
+
if (Math.abs(scaleY * worldBoxBounds.height) < 1)
|
|
554
|
+
scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
|
|
551
555
|
return { origin, scaleX, scaleY, direction, lockRatio, around };
|
|
552
556
|
},
|
|
553
557
|
getRotateData(bounds, direction, current, last, around) {
|
|
@@ -676,7 +680,7 @@ function updateCursor(editor, e) {
|
|
|
676
680
|
let { rotation } = editBox;
|
|
677
681
|
const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
|
|
678
682
|
const { pointType } = point, { flippedX, flippedY } = editBox;
|
|
679
|
-
let showResize = pointType
|
|
683
|
+
let showResize = pointType.includes('resize');
|
|
680
684
|
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
|
|
681
685
|
showResize = false;
|
|
682
686
|
const showSkew = skewable && !showResize && point.name === 'resize-line';
|
|
@@ -703,7 +707,7 @@ function toDataURL(svg, rotation) {
|
|
|
703
707
|
class EditPoint extends draw.Box {
|
|
704
708
|
}
|
|
705
709
|
|
|
706
|
-
const fourDirection = ['top', 'right', 'bottom', 'left'];
|
|
710
|
+
const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
|
|
707
711
|
class EditBox extends draw.Group {
|
|
708
712
|
get flipped() { return this.flippedX || this.flippedY; }
|
|
709
713
|
get flippedX() { return this.scaleX < 0; }
|
|
@@ -718,6 +722,7 @@ class EditBox extends draw.Group {
|
|
|
718
722
|
this.resizePoints = [];
|
|
719
723
|
this.rotatePoints = [];
|
|
720
724
|
this.resizeLines = [];
|
|
725
|
+
this.dragStartData = {};
|
|
721
726
|
this.__eventIds = [];
|
|
722
727
|
this.editor = editor;
|
|
723
728
|
this.visible = false;
|
|
@@ -759,7 +764,7 @@ class EditBox extends draw.Group {
|
|
|
759
764
|
resizeP.rotation = (i / 2) * 90;
|
|
760
765
|
}
|
|
761
766
|
circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
|
|
762
|
-
rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
|
|
767
|
+
rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
|
|
763
768
|
rect.hittable = !single;
|
|
764
769
|
rect.syncEventer = single && this.editor;
|
|
765
770
|
if (single) {
|
|
@@ -768,14 +773,14 @@ class EditBox extends draw.Group {
|
|
|
768
773
|
}
|
|
769
774
|
}
|
|
770
775
|
update(bounds) {
|
|
771
|
-
|
|
776
|
+
const { mergeConfig, element, multiple } = this.editor;
|
|
777
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox } = mergeConfig;
|
|
778
|
+
this.visible = !element.locked;
|
|
772
779
|
if (this.view.worldOpacity) {
|
|
773
|
-
const { mergeConfig } = this.editor;
|
|
774
780
|
const { width, height } = bounds;
|
|
775
781
|
const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
|
|
776
|
-
const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
|
|
777
782
|
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
|
|
778
|
-
const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
|
|
783
|
+
const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
|
|
779
784
|
let point = {}, rotateP, resizeP, resizeL;
|
|
780
785
|
for (let i = 0; i < 8; i++) {
|
|
781
786
|
draw.AroundHelper.toPoint(draw.AroundHelper.directionData[i], bounds, point);
|
|
@@ -791,13 +796,13 @@ class EditBox extends draw.Group {
|
|
|
791
796
|
resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
|
|
792
797
|
if (((i + 1) / 2) % 2) {
|
|
793
798
|
resizeL.width = width;
|
|
794
|
-
if (resizeP.width > width
|
|
799
|
+
if (hideOnSmall && resizeP.width * 2 > width)
|
|
795
800
|
resizeP.visible = false;
|
|
796
801
|
}
|
|
797
802
|
else {
|
|
798
803
|
resizeL.height = height;
|
|
799
804
|
resizeP.rotation = 90;
|
|
800
|
-
if (resizeP.width > height
|
|
805
|
+
if (hideOnSmall && resizeP.width * 2 > height)
|
|
801
806
|
resizeP.visible = false;
|
|
802
807
|
}
|
|
803
808
|
}
|
|
@@ -807,7 +812,7 @@ class EditBox extends draw.Group {
|
|
|
807
812
|
this.layoutCircle(mergeConfig);
|
|
808
813
|
if (rect.path)
|
|
809
814
|
rect.path = null;
|
|
810
|
-
rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
|
|
815
|
+
rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
|
|
811
816
|
buttons.visible = showPoints && buttons.children.length > 0;
|
|
812
817
|
if (buttons.visible)
|
|
813
818
|
this.layoutButtons(mergeConfig);
|
|
@@ -854,7 +859,7 @@ class EditBox extends draw.Group {
|
|
|
854
859
|
}
|
|
855
860
|
getPointStyle(userStyle) {
|
|
856
861
|
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 };
|
|
862
|
+
const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
|
|
858
863
|
return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
|
|
859
864
|
}
|
|
860
865
|
getPointsStyle() {
|
|
@@ -874,34 +879,32 @@ class EditBox extends draw.Group {
|
|
|
874
879
|
}
|
|
875
880
|
onDragStart(e) {
|
|
876
881
|
this.dragging = true;
|
|
877
|
-
const
|
|
878
|
-
|
|
882
|
+
const point = this.dragPoint = e.current;
|
|
883
|
+
const { editor, dragStartData } = this, { element } = editor;
|
|
884
|
+
if (point.name === 'rect') {
|
|
879
885
|
this.moving = true;
|
|
880
|
-
editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
|
|
881
886
|
editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
|
|
882
887
|
}
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
888
|
+
dragStartData.x = e.x;
|
|
889
|
+
dragStartData.y = e.y;
|
|
890
|
+
dragStartData.point = { x: element.x, y: element.y };
|
|
891
|
+
dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
|
|
892
|
+
dragStartData.rotation = element.rotation;
|
|
887
893
|
}
|
|
888
894
|
onDragEnd(e) {
|
|
889
895
|
this.dragging = false;
|
|
896
|
+
this.dragPoint = null;
|
|
890
897
|
this.moving = false;
|
|
891
898
|
if (e.current.name === 'rect')
|
|
892
899
|
this.editor.opacity = 1;
|
|
893
|
-
this.editor.resizeDirection = undefined;
|
|
894
900
|
}
|
|
895
901
|
onDrag(e) {
|
|
896
902
|
const { editor } = this;
|
|
897
|
-
const
|
|
898
|
-
if (
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
}
|
|
902
|
-
else if (point.pointType === 'resize') {
|
|
903
|
+
const { pointType } = this.enterPoint = e.current;
|
|
904
|
+
if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable)
|
|
905
|
+
editor.onRotate(e);
|
|
906
|
+
if (pointType.includes('resize'))
|
|
903
907
|
editor.onScale(e);
|
|
904
|
-
}
|
|
905
908
|
updateCursor(editor, e);
|
|
906
909
|
}
|
|
907
910
|
onArrow(e) {
|
|
@@ -1079,6 +1082,7 @@ const config = {
|
|
|
1079
1082
|
rotateCursor: { url: rotateSVG, x: 12, y: 12 },
|
|
1080
1083
|
skewCursor: { url: skewSVG, x: 12, y: 12 },
|
|
1081
1084
|
selector: true,
|
|
1085
|
+
editBox: true,
|
|
1082
1086
|
hover: true,
|
|
1083
1087
|
select: 'press',
|
|
1084
1088
|
openInner: 'double',
|
|
@@ -1108,7 +1112,11 @@ function simulate(editor) {
|
|
|
1108
1112
|
function onTarget(editor, oldValue) {
|
|
1109
1113
|
const { target } = editor;
|
|
1110
1114
|
if (target) {
|
|
1111
|
-
editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
|
|
1115
|
+
const { list } = editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
|
|
1116
|
+
if (!list.every(checkEditable)) {
|
|
1117
|
+
editor.target = list.filter(checkEditable);
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1112
1120
|
if (editor.multiple)
|
|
1113
1121
|
simulate(editor);
|
|
1114
1122
|
}
|
|
@@ -1135,6 +1143,9 @@ function onTarget(editor, oldValue) {
|
|
|
1135
1143
|
function onHover(editor, oldValue) {
|
|
1136
1144
|
editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
|
|
1137
1145
|
}
|
|
1146
|
+
function checkEditable(item) {
|
|
1147
|
+
return item.editable && !item.locked;
|
|
1148
|
+
}
|
|
1138
1149
|
|
|
1139
1150
|
const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
|
|
1140
1151
|
const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
|
|
@@ -1232,10 +1243,13 @@ class EditorGroupEvent extends EditorEvent {
|
|
|
1232
1243
|
super(type, data);
|
|
1233
1244
|
}
|
|
1234
1245
|
}
|
|
1246
|
+
EditorGroupEvent.BEFORE_GROUP = 'editor.before_group';
|
|
1235
1247
|
EditorGroupEvent.GROUP = 'editor.group';
|
|
1236
1248
|
EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
|
|
1237
1249
|
EditorGroupEvent.UNGROUP = 'editor.ungroup';
|
|
1250
|
+
EditorGroupEvent.BEFORE_OPEN = 'editor.before_open_group';
|
|
1238
1251
|
EditorGroupEvent.OPEN = 'editor.open_group';
|
|
1252
|
+
EditorGroupEvent.BEFORE_CLOSE = 'editor.before_close_group';
|
|
1239
1253
|
EditorGroupEvent.CLOSE = 'editor.close_group';
|
|
1240
1254
|
|
|
1241
1255
|
const { updateMatrix } = draw.LeafHelper;
|
|
@@ -1298,8 +1312,20 @@ class SimulateElement extends draw.Rect {
|
|
|
1298
1312
|
|
|
1299
1313
|
class Editor extends draw.Group {
|
|
1300
1314
|
get mergeConfig() {
|
|
1301
|
-
const { element,
|
|
1302
|
-
|
|
1315
|
+
const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
|
|
1316
|
+
if (element && element.editConfig)
|
|
1317
|
+
Object.assign(mergeConfig, element.editConfig);
|
|
1318
|
+
if (dragPoint) {
|
|
1319
|
+
if (dragPoint.editConfig)
|
|
1320
|
+
Object.assign(mergeConfig, dragPoint.editConfig);
|
|
1321
|
+
if (mergeConfig.editSize === 'font-size')
|
|
1322
|
+
mergeConfig.lockRatio = true;
|
|
1323
|
+
if (dragPoint.pointType === 'resize-rotate') {
|
|
1324
|
+
mergeConfig.around || (mergeConfig.around = 'center');
|
|
1325
|
+
draw.isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return mergeConfig;
|
|
1303
1329
|
}
|
|
1304
1330
|
get list() { return this.leafList.list; }
|
|
1305
1331
|
get dragHoverExclude() { return [this.editBox.rect]; }
|
|
@@ -1309,6 +1335,7 @@ class Editor extends draw.Group {
|
|
|
1309
1335
|
get single() { return this.list.length === 1; }
|
|
1310
1336
|
get dragging() { return this.editBox.dragging; }
|
|
1311
1337
|
get moving() { return this.editBox.moving; }
|
|
1338
|
+
get dragPoint() { return this.editBox.dragPoint; }
|
|
1312
1339
|
get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
|
|
1313
1340
|
get buttons() { return this.editBox.buttons; }
|
|
1314
1341
|
constructor(userConfig, data) {
|
|
@@ -1399,7 +1426,7 @@ class Editor extends draw.Group {
|
|
|
1399
1426
|
else
|
|
1400
1427
|
total.x = 0;
|
|
1401
1428
|
}
|
|
1402
|
-
this.move(core.DragEvent.getValidMove(this.element, this.
|
|
1429
|
+
this.move(core.DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
|
|
1403
1430
|
}
|
|
1404
1431
|
}
|
|
1405
1432
|
onScale(e) {
|
|
@@ -1413,7 +1440,7 @@ class Editor extends draw.Group {
|
|
|
1413
1440
|
const { direction } = e.current;
|
|
1414
1441
|
if (e.shiftKey || element.lockRatio)
|
|
1415
1442
|
lockRatio = true;
|
|
1416
|
-
const data = EditDataHelper.getScaleData(element, this.
|
|
1443
|
+
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
1444
|
if (this.editTool.onScaleWithDrag) {
|
|
1418
1445
|
data.drag = e;
|
|
1419
1446
|
this.scaleWithDrag(data);
|
|
@@ -1428,26 +1455,29 @@ class Editor extends draw.Group {
|
|
|
1428
1455
|
const { direction, name } = e.current;
|
|
1429
1456
|
if (skewable && name === 'resize-line')
|
|
1430
1457
|
return this.onSkew(e);
|
|
1431
|
-
const { element } = this;
|
|
1458
|
+
const { element } = this, { dragStartData } = this.editBox;
|
|
1432
1459
|
let origin, rotation;
|
|
1433
1460
|
if (e instanceof core.RotateEvent) {
|
|
1434
1461
|
if (rotateable === 'rotate')
|
|
1435
1462
|
e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
|
|
1436
1463
|
else
|
|
1437
1464
|
return;
|
|
1465
|
+
if (element.scaleX * element.scaleY < 0)
|
|
1466
|
+
rotation = -rotation;
|
|
1438
1467
|
}
|
|
1439
1468
|
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'));
|
|
1469
|
+
const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
|
|
1442
1470
|
rotation = data.rotation;
|
|
1443
1471
|
origin = data.origin;
|
|
1444
1472
|
}
|
|
1445
|
-
rotation = draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
|
|
1446
|
-
if (!rotation)
|
|
1447
|
-
return;
|
|
1448
1473
|
if (element.scaleX * element.scaleY < 0)
|
|
1449
1474
|
rotation = -rotation;
|
|
1450
|
-
|
|
1475
|
+
if (e instanceof core.DragEvent)
|
|
1476
|
+
rotation = dragStartData.rotation + rotation - element.rotation;
|
|
1477
|
+
rotation = draw.MathHelper.float(draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
|
|
1478
|
+
if (!rotation)
|
|
1479
|
+
return;
|
|
1480
|
+
this.rotateOf(origin, rotation);
|
|
1451
1481
|
}
|
|
1452
1482
|
onSkew(e) {
|
|
1453
1483
|
const { element } = this;
|
|
@@ -1464,7 +1494,9 @@ class Editor extends draw.Group {
|
|
|
1464
1494
|
const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
|
|
1465
1495
|
if (this.multiple)
|
|
1466
1496
|
element.safeChange(() => element.move(x, y));
|
|
1467
|
-
const
|
|
1497
|
+
const data = { target: element, editor: this, moveX: world.x, moveY: world.y };
|
|
1498
|
+
this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
|
|
1499
|
+
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
|
|
1468
1500
|
this.editTool.onMove(event);
|
|
1469
1501
|
this.emitEvent(event);
|
|
1470
1502
|
}
|
|
@@ -1472,7 +1504,9 @@ class Editor extends draw.Group {
|
|
|
1472
1504
|
if (!this.checkTransform('resizeable'))
|
|
1473
1505
|
return;
|
|
1474
1506
|
const { element } = this;
|
|
1475
|
-
|
|
1507
|
+
data = Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) });
|
|
1508
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1509
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1476
1510
|
this.editTool.onScaleWithDrag(event);
|
|
1477
1511
|
this.emitEvent(event);
|
|
1478
1512
|
}
|
|
@@ -1482,7 +1516,9 @@ class Editor extends draw.Group {
|
|
|
1482
1516
|
const { element } = this;
|
|
1483
1517
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1484
1518
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
|
|
1485
|
-
const
|
|
1519
|
+
const data = { target: element, editor: this, worldOrigin, scaleX, scaleY, transform };
|
|
1520
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1521
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1486
1522
|
this.editTool.onScale(event);
|
|
1487
1523
|
this.emitEvent(event);
|
|
1488
1524
|
}
|
|
@@ -1492,7 +1528,9 @@ class Editor extends draw.Group {
|
|
|
1492
1528
|
const { element } = this;
|
|
1493
1529
|
const worldOrigin = this.getWorldOrigin('center');
|
|
1494
1530
|
const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new draw.Matrix(draw.LeafHelper.getFlipTransform(element, axis));
|
|
1495
|
-
const
|
|
1531
|
+
const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
|
|
1532
|
+
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1533
|
+
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1496
1534
|
this.editTool.onScale(event);
|
|
1497
1535
|
this.emitEvent(event);
|
|
1498
1536
|
}
|
|
@@ -1502,7 +1540,9 @@ class Editor extends draw.Group {
|
|
|
1502
1540
|
const { element } = this;
|
|
1503
1541
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1504
1542
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
|
|
1505
|
-
const
|
|
1543
|
+
const data = { target: element, editor: this, worldOrigin, rotation, transform };
|
|
1544
|
+
this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
|
|
1545
|
+
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
|
|
1506
1546
|
this.editTool.onRotate(event);
|
|
1507
1547
|
this.emitEvent(event);
|
|
1508
1548
|
}
|
|
@@ -1512,7 +1552,9 @@ class Editor extends draw.Group {
|
|
|
1512
1552
|
const { element } = this;
|
|
1513
1553
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1514
1554
|
const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
|
|
1515
|
-
const
|
|
1555
|
+
const data = { target: element, editor: this, worldOrigin, skewX, skewY, transform };
|
|
1556
|
+
this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
|
|
1557
|
+
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
|
|
1516
1558
|
this.editTool.onSkew(event);
|
|
1517
1559
|
this.emitEvent(event);
|
|
1518
1560
|
}
|
|
@@ -1530,6 +1572,7 @@ class Editor extends draw.Group {
|
|
|
1530
1572
|
}
|
|
1531
1573
|
group(userGroup) {
|
|
1532
1574
|
if (this.multiple) {
|
|
1575
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
|
|
1533
1576
|
this.target = EditorHelper.group(this.list, this.element, userGroup);
|
|
1534
1577
|
this.emitGroupEvent(EditorGroupEvent.GROUP, this.target);
|
|
1535
1578
|
}
|
|
@@ -1545,11 +1588,13 @@ class Editor extends draw.Group {
|
|
|
1545
1588
|
return this.list;
|
|
1546
1589
|
}
|
|
1547
1590
|
openGroup(group) {
|
|
1591
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_OPEN, group);
|
|
1548
1592
|
this.openedGroupList.add(group);
|
|
1549
1593
|
group.hitChildren = true;
|
|
1550
1594
|
this.emitGroupEvent(EditorGroupEvent.OPEN, group);
|
|
1551
1595
|
}
|
|
1552
1596
|
closeGroup(group) {
|
|
1597
|
+
this.emitGroupEvent(EditorGroupEvent.BEFORE_CLOSE, group);
|
|
1553
1598
|
this.openedGroupList.remove(group);
|
|
1554
1599
|
group.hitChildren = false;
|
|
1555
1600
|
this.emitGroupEvent(EditorGroupEvent.CLOSE, group);
|
|
@@ -1578,7 +1623,8 @@ class Editor extends draw.Group {
|
|
|
1578
1623
|
emitGroupEvent(type, group) {
|
|
1579
1624
|
const event = new EditorGroupEvent(type, { editTarget: group });
|
|
1580
1625
|
this.emitEvent(event);
|
|
1581
|
-
group
|
|
1626
|
+
if (group)
|
|
1627
|
+
group.emitEvent(event);
|
|
1582
1628
|
}
|
|
1583
1629
|
openInnerEditor(target, select) {
|
|
1584
1630
|
if (target && select)
|
|
@@ -1908,34 +1954,15 @@ exports.LineEditTool = __decorate([
|
|
|
1908
1954
|
|
|
1909
1955
|
draw.Plugin.add('editor', 'resize');
|
|
1910
1956
|
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
|
-
};
|
|
1957
|
+
draw.Box.addAttr('textBox', false, draw.dataType);
|
|
1958
|
+
draw.UI.addAttr('editConfig', undefined, draw.dataType);
|
|
1959
|
+
draw.UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', draw.dataType);
|
|
1960
|
+
draw.UI.addAttr('editInner', 'PathEditor', draw.dataType);
|
|
1961
|
+
draw.Group.addAttr('editInner', '', draw.dataType);
|
|
1962
|
+
draw.Text.addAttr('editInner', 'TextEditor', draw.dataType);
|
|
1963
|
+
draw.UI.setEditConfig = function (config) { this.changeAttr('editConfig', config); };
|
|
1964
|
+
draw.UI.setEditOuter = function (toolName) { this.changeAttr('editOuter', toolName); };
|
|
1965
|
+
draw.UI.setEditInner = function (editorName) { this.changeAttr('editInner', editorName); };
|
|
1939
1966
|
|
|
1940
1967
|
exports.EditBox = EditBox;
|
|
1941
1968
|
exports.EditDataHelper = EditDataHelper;
|