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