@leafer-in/editor 1.5.2 → 1.6.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 +149 -91
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.esm.js +150 -92
- 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 +149 -91
- 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 +34 -27
- package/src/decorator/data.ts +45 -6
- package/src/display/EditBox.ts +26 -19
- package/src/display/EditMask.ts +19 -10
- package/src/display/EditSelect.ts +1 -1
- package/src/display/SelectArea.ts +2 -1
- package/src/display/Stroker.ts +9 -8
- package/src/editor/target.ts +2 -11
- package/src/helper/EditDataHelper.ts +12 -9
- package/src/tool/EditTool.ts +7 -18
- package/types/index.d.ts +9 -3
package/dist/editor.cjs
CHANGED
|
@@ -90,15 +90,52 @@ function targetAttr(fn) {
|
|
|
90
90
|
set(value) {
|
|
91
91
|
const old = this[privateKey];
|
|
92
92
|
if (old !== value) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
if (this.config) {
|
|
94
|
+
const isSelect = key === 'target';
|
|
95
|
+
if (isSelect) {
|
|
96
|
+
if (value instanceof Array && value.length > 1 && value[0].locked)
|
|
97
|
+
value.splice(0, 1);
|
|
98
|
+
const { beforeSelect } = this.config;
|
|
99
|
+
if (beforeSelect) {
|
|
100
|
+
const check = beforeSelect({ target: value });
|
|
101
|
+
if (typeof check === 'object')
|
|
102
|
+
value = check;
|
|
103
|
+
else if (check === false)
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
|
|
108
|
+
if (this.hasEvent(type))
|
|
109
|
+
this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
|
|
110
|
+
}
|
|
96
111
|
this[privateKey] = value, fn(this, old);
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
114
|
});
|
|
100
115
|
};
|
|
101
116
|
}
|
|
117
|
+
function mergeConfigAttr() {
|
|
118
|
+
return (target, key) => {
|
|
119
|
+
draw.defineKey(target, key, {
|
|
120
|
+
get() {
|
|
121
|
+
const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
|
|
122
|
+
if (element && element.editConfig)
|
|
123
|
+
Object.assign(mergeConfig, element.editConfig);
|
|
124
|
+
if (dragPoint) {
|
|
125
|
+
if (dragPoint.editConfig)
|
|
126
|
+
Object.assign(mergeConfig, dragPoint.editConfig);
|
|
127
|
+
if (mergeConfig.editSize === 'font-size')
|
|
128
|
+
mergeConfig.lockRatio = true;
|
|
129
|
+
if (dragPoint.pointType === 'resize-rotate') {
|
|
130
|
+
mergeConfig.around || (mergeConfig.around = 'center');
|
|
131
|
+
draw.isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return this.mergedConfig = mergeConfig;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
}
|
|
102
139
|
|
|
103
140
|
const { abs } = Math;
|
|
104
141
|
const { copy: copy$1, scale } = draw.MatrixHelper;
|
|
@@ -110,6 +147,7 @@ class Stroker extends draw.UI {
|
|
|
110
147
|
constructor() {
|
|
111
148
|
super();
|
|
112
149
|
this.list = [];
|
|
150
|
+
this.visible = 0;
|
|
113
151
|
this.hittable = false;
|
|
114
152
|
this.strokeAlign = 'center';
|
|
115
153
|
}
|
|
@@ -123,10 +161,10 @@ class Stroker extends draw.UI {
|
|
|
123
161
|
if (list.length) {
|
|
124
162
|
setListWithFn(bounds$1, list, worldBounds);
|
|
125
163
|
this.set(bounds$1);
|
|
164
|
+
this.visible = true;
|
|
126
165
|
}
|
|
127
|
-
else
|
|
128
|
-
this.
|
|
129
|
-
}
|
|
166
|
+
else
|
|
167
|
+
this.visible = 0;
|
|
130
168
|
}
|
|
131
169
|
__draw(canvas, options) {
|
|
132
170
|
const { list } = this;
|
|
@@ -138,8 +176,9 @@ class Stroker extends draw.UI {
|
|
|
138
176
|
const { worldTransform, worldRenderBounds } = leaf;
|
|
139
177
|
if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
|
|
140
178
|
const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
|
|
179
|
+
copy$1(matrix, worldTransform);
|
|
180
|
+
matrix.half = strokeWidth % 2;
|
|
141
181
|
if (aScaleX !== aScaleY) {
|
|
142
|
-
copy$1(matrix, worldTransform);
|
|
143
182
|
scale(matrix, 1 / aScaleX, 1 / aScaleY);
|
|
144
183
|
canvas.setWorld(matrix, options.matrix);
|
|
145
184
|
canvas.beginPath();
|
|
@@ -148,7 +187,7 @@ class Stroker extends draw.UI {
|
|
|
148
187
|
canvas.rect(x * aScaleX, y * aScaleY, width * aScaleX, height * aScaleY);
|
|
149
188
|
}
|
|
150
189
|
else {
|
|
151
|
-
canvas.setWorld(
|
|
190
|
+
canvas.setWorld(matrix, options.matrix);
|
|
152
191
|
canvas.beginPath();
|
|
153
192
|
if (leaf.__.__useArrow)
|
|
154
193
|
leaf.__drawPath(canvas);
|
|
@@ -183,7 +222,8 @@ class SelectArea extends draw.Group {
|
|
|
183
222
|
super(data);
|
|
184
223
|
this.strokeArea = new draw.Rect({ strokeAlign: 'center' });
|
|
185
224
|
this.fillArea = new draw.Rect();
|
|
186
|
-
this.visible =
|
|
225
|
+
this.visible = 0;
|
|
226
|
+
this.hittable = false;
|
|
187
227
|
this.addMany(this.fillArea, this.strokeArea);
|
|
188
228
|
}
|
|
189
229
|
setStyle(style, userStyle) {
|
|
@@ -380,7 +420,7 @@ class EditSelect extends draw.Group {
|
|
|
380
420
|
if (e.multiTouch)
|
|
381
421
|
return;
|
|
382
422
|
if (this.dragging)
|
|
383
|
-
this.originList = null, this.selectArea.visible =
|
|
423
|
+
this.originList = null, this.selectArea.visible = 0;
|
|
384
424
|
}
|
|
385
425
|
onAutoMove(e) {
|
|
386
426
|
if (this.dragging) {
|
|
@@ -528,8 +568,11 @@ const EditDataHelper = {
|
|
|
528
568
|
scaleY = scaleY < 0 ? -scale : scale;
|
|
529
569
|
}
|
|
530
570
|
}
|
|
531
|
-
scaleX
|
|
532
|
-
|
|
571
|
+
const useScaleX = scaleX !== 1, useScaleY = scaleY !== 1;
|
|
572
|
+
if (useScaleX)
|
|
573
|
+
scaleX /= changedScaleX;
|
|
574
|
+
if (useScaleY)
|
|
575
|
+
scaleY /= changedScaleY;
|
|
533
576
|
if (!flipable) {
|
|
534
577
|
const { worldTransform } = element;
|
|
535
578
|
if (scaleX < 0)
|
|
@@ -544,22 +587,27 @@ const EditDataHelper = {
|
|
|
544
587
|
localBounds.scaleOf(element.getLocalPointByInner(origin), scaleX, scaleY);
|
|
545
588
|
if (!draw.BoundsHelper.includes(allowBounds, localBounds)) {
|
|
546
589
|
const realBounds = localBounds.getIntersect(allowBounds);
|
|
547
|
-
|
|
548
|
-
|
|
590
|
+
const fitScaleX = realBounds.width / localBounds.width, fitScaleY = realBounds.height / localBounds.height;
|
|
591
|
+
if (useScaleX)
|
|
592
|
+
scaleX *= fitScaleX;
|
|
593
|
+
if (useScaleY)
|
|
594
|
+
scaleY *= fitScaleY;
|
|
549
595
|
}
|
|
550
596
|
}
|
|
551
|
-
if (widthRange) {
|
|
597
|
+
if (useScaleX && widthRange) {
|
|
552
598
|
const nowWidth = boxBounds.width * element.scaleX;
|
|
553
599
|
scaleX = within(nowWidth * scaleX, widthRange) / nowWidth;
|
|
554
600
|
}
|
|
555
|
-
if (heightRange) {
|
|
601
|
+
if (useScaleY && heightRange) {
|
|
556
602
|
const nowHeight = boxBounds.height * element.scaleY;
|
|
557
603
|
scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
|
|
558
604
|
}
|
|
559
|
-
if (Math.abs(scaleX * worldBoxBounds.width) < 1)
|
|
605
|
+
if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1)
|
|
560
606
|
scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
|
|
561
|
-
if (Math.abs(scaleY * worldBoxBounds.height) < 1)
|
|
607
|
+
if (useScaleY && Math.abs(scaleY * worldBoxBounds.height) < 1)
|
|
562
608
|
scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
|
|
609
|
+
if (lockRatio && scaleX !== scaleY)
|
|
610
|
+
scaleY = scaleX = Math.min(scaleX, scaleY);
|
|
563
611
|
return { origin, scaleX, scaleY, direction, lockRatio, around };
|
|
564
612
|
},
|
|
565
613
|
getRotateData(bounds, direction, current, last, around) {
|
|
@@ -730,7 +778,7 @@ class EditBox extends draw.Group {
|
|
|
730
778
|
this.view = new draw.Group();
|
|
731
779
|
this.rect = new draw.Box({ name: 'rect', hitFill: 'all', hitStroke: 'none', strokeAlign: 'center', hitRadius: 5 });
|
|
732
780
|
this.circle = new EditPoint({ name: 'circle', strokeAlign: 'center', around: 'center', cursor: 'crosshair', hitRadius: 5 });
|
|
733
|
-
this.buttons = new draw.Group({ around: 'center', hitSelf: false });
|
|
781
|
+
this.buttons = new draw.Group({ around: 'center', hitSelf: false, visible: 0 });
|
|
734
782
|
this.resizePoints = [];
|
|
735
783
|
this.rotatePoints = [];
|
|
736
784
|
this.resizeLines = [];
|
|
@@ -785,12 +833,13 @@ class EditBox extends draw.Group {
|
|
|
785
833
|
}
|
|
786
834
|
}
|
|
787
835
|
update(bounds) {
|
|
788
|
-
const {
|
|
789
|
-
const {
|
|
836
|
+
const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines, editor } = this;
|
|
837
|
+
const { mergeConfig, element, multiple, editMask } = editor;
|
|
838
|
+
const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
|
|
790
839
|
this.visible = !element.locked;
|
|
840
|
+
editMask.visible = mask ? true : 0;
|
|
791
841
|
if (this.view.worldOpacity) {
|
|
792
842
|
const { width, height } = bounds;
|
|
793
|
-
const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
|
|
794
843
|
const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
|
|
795
844
|
const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
|
|
796
845
|
let point = {}, rotateP, resizeP, resizeL;
|
|
@@ -825,10 +874,12 @@ class EditBox extends draw.Group {
|
|
|
825
874
|
if (rect.path)
|
|
826
875
|
rect.path = null;
|
|
827
876
|
rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
|
|
828
|
-
buttons.visible = showPoints && buttons.children.length > 0;
|
|
877
|
+
buttons.visible = showPoints && buttons.children.length > 0 || 0;
|
|
829
878
|
if (buttons.visible)
|
|
830
879
|
this.layoutButtons(mergeConfig);
|
|
831
880
|
}
|
|
881
|
+
else
|
|
882
|
+
rect.set(bounds);
|
|
832
883
|
}
|
|
833
884
|
layoutCircle(config) {
|
|
834
885
|
const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = config;
|
|
@@ -891,7 +942,7 @@ class EditBox extends draw.Group {
|
|
|
891
942
|
}
|
|
892
943
|
onDragStart(e) {
|
|
893
944
|
this.dragging = true;
|
|
894
|
-
const point = this.dragPoint = e.current;
|
|
945
|
+
const point = this.dragPoint = e.current, { pointType } = point;
|
|
895
946
|
const { editor, dragStartData } = this, { element } = editor;
|
|
896
947
|
if (point.name === 'rect') {
|
|
897
948
|
this.moving = true;
|
|
@@ -902,43 +953,53 @@ class EditBox extends draw.Group {
|
|
|
902
953
|
dragStartData.point = { x: element.x, y: element.y };
|
|
903
954
|
dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
|
|
904
955
|
dragStartData.rotation = element.rotation;
|
|
956
|
+
if (pointType && pointType.includes('resize'))
|
|
957
|
+
draw.ResizeEvent.resizingKeys = editor.leafList.keys;
|
|
905
958
|
}
|
|
906
959
|
onDragEnd(e) {
|
|
907
960
|
this.dragging = false;
|
|
908
961
|
this.dragPoint = null;
|
|
909
962
|
this.moving = false;
|
|
910
|
-
|
|
963
|
+
const { name, pointType } = e.current;
|
|
964
|
+
if (name === 'rect')
|
|
911
965
|
this.editor.opacity = 1;
|
|
966
|
+
if (pointType && pointType.includes('resize'))
|
|
967
|
+
draw.ResizeEvent.resizingKeys = null;
|
|
912
968
|
}
|
|
913
969
|
onDrag(e) {
|
|
914
970
|
const { editor } = this;
|
|
915
971
|
const { pointType } = this.enterPoint = e.current;
|
|
916
|
-
if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable)
|
|
972
|
+
if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
|
|
917
973
|
editor.onRotate(e);
|
|
918
|
-
|
|
974
|
+
if (pointType === 'resize-rotate')
|
|
975
|
+
editor.onScale(e);
|
|
976
|
+
}
|
|
977
|
+
else if (pointType === 'resize')
|
|
919
978
|
editor.onScale(e);
|
|
920
979
|
if (pointType === 'skew')
|
|
921
980
|
editor.onSkew(e);
|
|
922
981
|
updateCursor(editor, e);
|
|
923
982
|
}
|
|
924
983
|
onArrow(e) {
|
|
925
|
-
|
|
926
|
-
|
|
984
|
+
const { editor } = this;
|
|
985
|
+
if (editor.editing && editor.mergeConfig.keyEvent) {
|
|
986
|
+
let x = 0, y = 0;
|
|
927
987
|
const distance = e.shiftKey ? 10 : 1;
|
|
928
988
|
switch (e.code) {
|
|
929
989
|
case 'ArrowDown':
|
|
930
|
-
|
|
990
|
+
y = distance;
|
|
931
991
|
break;
|
|
932
992
|
case 'ArrowUp':
|
|
933
|
-
|
|
993
|
+
y = -distance;
|
|
934
994
|
break;
|
|
935
995
|
case 'ArrowLeft':
|
|
936
|
-
|
|
996
|
+
x = -distance;
|
|
937
997
|
break;
|
|
938
998
|
case 'ArrowRight':
|
|
939
|
-
|
|
999
|
+
x = distance;
|
|
940
1000
|
}
|
|
941
|
-
|
|
1001
|
+
if (x || y)
|
|
1002
|
+
editor.move(x, y);
|
|
942
1003
|
}
|
|
943
1004
|
}
|
|
944
1005
|
onDoubleTap(e) {
|
|
@@ -1004,22 +1065,32 @@ class EditBox extends draw.Group {
|
|
|
1004
1065
|
}
|
|
1005
1066
|
}
|
|
1006
1067
|
|
|
1068
|
+
const bigBounds = { x: 0, y: 0, width: 100000, height: 100000 };
|
|
1007
1069
|
class EditMask extends draw.UI {
|
|
1008
1070
|
constructor(editor) {
|
|
1009
1071
|
super();
|
|
1010
1072
|
this.editor = editor;
|
|
1011
1073
|
this.hittable = false;
|
|
1074
|
+
this.visible = 0;
|
|
1075
|
+
}
|
|
1076
|
+
__updateWorldBounds() {
|
|
1077
|
+
Object.assign(this.__local, bigBounds);
|
|
1078
|
+
Object.assign(this.__world, bigBounds);
|
|
1012
1079
|
}
|
|
1013
1080
|
__draw(canvas, options) {
|
|
1014
|
-
const { editor } = this;
|
|
1015
|
-
|
|
1016
|
-
if (mask && editor.list.length) {
|
|
1017
|
-
const { rect } = editor.editBox;
|
|
1018
|
-
const { width, height } = rect.__;
|
|
1019
|
-
canvas.resetTransform();
|
|
1081
|
+
const { editor } = this, { mask } = editor.mergedConfig;
|
|
1082
|
+
if (mask && editor.editing) {
|
|
1020
1083
|
canvas.fillWorld(canvas.bounds, mask === true ? 'rgba(0,0,0,0.8)' : mask);
|
|
1021
|
-
|
|
1022
|
-
|
|
1084
|
+
if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix))
|
|
1085
|
+
return;
|
|
1086
|
+
canvas.saveBlendMode('destination-out');
|
|
1087
|
+
editor.list.forEach(item => {
|
|
1088
|
+
item.__renderShape(canvas, options);
|
|
1089
|
+
const { __box, parent } = item;
|
|
1090
|
+
if ((item = __box) || ((item = parent) && parent.textBox))
|
|
1091
|
+
item.__renderShape(canvas, options);
|
|
1092
|
+
});
|
|
1093
|
+
canvas.restoreBlendMode();
|
|
1023
1094
|
}
|
|
1024
1095
|
}
|
|
1025
1096
|
destroy() {
|
|
@@ -1127,11 +1198,7 @@ function simulate(editor) {
|
|
|
1127
1198
|
function onTarget(editor, oldValue) {
|
|
1128
1199
|
const { target } = editor;
|
|
1129
1200
|
if (target) {
|
|
1130
|
-
|
|
1131
|
-
if (!list.every(checkEditable)) {
|
|
1132
|
-
editor.target = list.filter(checkEditable);
|
|
1133
|
-
return;
|
|
1134
|
-
}
|
|
1201
|
+
editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target);
|
|
1135
1202
|
if (editor.multiple)
|
|
1136
1203
|
simulate(editor);
|
|
1137
1204
|
}
|
|
@@ -1158,9 +1225,6 @@ function onTarget(editor, oldValue) {
|
|
|
1158
1225
|
function onHover(editor, oldValue) {
|
|
1159
1226
|
editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
|
|
1160
1227
|
}
|
|
1161
|
-
function checkEditable(item) {
|
|
1162
|
-
return item.editable && !item.locked;
|
|
1163
|
-
}
|
|
1164
1228
|
|
|
1165
1229
|
const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
|
|
1166
1230
|
const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
|
|
@@ -1329,22 +1393,6 @@ class SimulateElement extends draw.Rect {
|
|
|
1329
1393
|
}
|
|
1330
1394
|
|
|
1331
1395
|
class Editor extends draw.Group {
|
|
1332
|
-
get mergeConfig() {
|
|
1333
|
-
const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
|
|
1334
|
-
if (element && element.editConfig)
|
|
1335
|
-
Object.assign(mergeConfig, element.editConfig);
|
|
1336
|
-
if (dragPoint) {
|
|
1337
|
-
if (dragPoint.editConfig)
|
|
1338
|
-
Object.assign(mergeConfig, dragPoint.editConfig);
|
|
1339
|
-
if (mergeConfig.editSize === 'font-size')
|
|
1340
|
-
mergeConfig.lockRatio = true;
|
|
1341
|
-
if (dragPoint.pointType === 'resize-rotate') {
|
|
1342
|
-
mergeConfig.around || (mergeConfig.around = 'center');
|
|
1343
|
-
draw.isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
return mergeConfig;
|
|
1347
|
-
}
|
|
1348
1396
|
get list() { return this.leafList.list; }
|
|
1349
1397
|
get dragHoverExclude() { return [this.editBox.rect]; }
|
|
1350
1398
|
get editing() { return !!this.list.length; }
|
|
@@ -1358,7 +1406,6 @@ class Editor extends draw.Group {
|
|
|
1358
1406
|
get buttons() { return this.editBox.buttons; }
|
|
1359
1407
|
constructor(userConfig, data) {
|
|
1360
1408
|
super(data);
|
|
1361
|
-
this.config = draw.DataHelper.clone(config);
|
|
1362
1409
|
this.leafList = new draw.LeafList();
|
|
1363
1410
|
this.openedGroupList = new draw.LeafList();
|
|
1364
1411
|
this.simulateTarget = new SimulateElement(this);
|
|
@@ -1367,8 +1414,10 @@ class Editor extends draw.Group {
|
|
|
1367
1414
|
this.selector = new EditSelect(this);
|
|
1368
1415
|
this.editMask = new EditMask(this);
|
|
1369
1416
|
this.targetEventIds = [];
|
|
1417
|
+
let mergedConfig = draw.DataHelper.clone(config);
|
|
1370
1418
|
if (userConfig)
|
|
1371
|
-
|
|
1419
|
+
mergedConfig = draw.DataHelper.default(userConfig, mergedConfig);
|
|
1420
|
+
this.mergedConfig = this.config = mergedConfig;
|
|
1372
1421
|
this.addMany(this.editMask, this.selector, this.editBox);
|
|
1373
1422
|
if (!core.Plugin.has('resize'))
|
|
1374
1423
|
this.config.editSize = 'scale';
|
|
@@ -1708,8 +1757,7 @@ class Editor extends draw.Group {
|
|
|
1708
1757
|
}
|
|
1709
1758
|
}
|
|
1710
1759
|
emitInnerEvent(type) {
|
|
1711
|
-
const { innerEditor } = this;
|
|
1712
|
-
const { editTarget } = innerEditor;
|
|
1760
|
+
const { innerEditor } = this, { editTarget } = innerEditor;
|
|
1713
1761
|
const event = new InnerEditorEvent(type, { editTarget, innerEditor });
|
|
1714
1762
|
this.emitEvent(event);
|
|
1715
1763
|
editTarget.emitEvent(event);
|
|
@@ -1734,25 +1782,40 @@ class Editor extends draw.Group {
|
|
|
1734
1782
|
this.leafList.update();
|
|
1735
1783
|
}
|
|
1736
1784
|
}
|
|
1785
|
+
onAppRenderStart(app) {
|
|
1786
|
+
if (this.targetChanged = app.children.some(leafer => leafer !== this.leafer && leafer.renderer.changed))
|
|
1787
|
+
this.editBox.forceRender();
|
|
1788
|
+
}
|
|
1789
|
+
onRenderStart() {
|
|
1790
|
+
if (this.targetChanged)
|
|
1791
|
+
this.update();
|
|
1792
|
+
}
|
|
1793
|
+
onKey(e) {
|
|
1794
|
+
updateCursor(this, e);
|
|
1795
|
+
}
|
|
1737
1796
|
listenTargetEvents() {
|
|
1738
1797
|
if (!this.targetEventIds.length) {
|
|
1739
|
-
const { app, leafer } = this;
|
|
1798
|
+
const { app, leafer, editBox, editMask } = this;
|
|
1740
1799
|
this.targetEventIds = [
|
|
1741
|
-
leafer.on_(draw.RenderEvent.START, this.
|
|
1742
|
-
app.on_(draw.RenderEvent.CHILD_START, this.
|
|
1800
|
+
leafer.on_(draw.RenderEvent.START, this.onRenderStart, this),
|
|
1801
|
+
app.on_(draw.RenderEvent.CHILD_START, this.onAppRenderStart, this),
|
|
1743
1802
|
app.on_(core.MoveEvent.BEFORE_MOVE, this.onMove, this, true),
|
|
1744
1803
|
app.on_(core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true),
|
|
1745
1804
|
app.on_(core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true),
|
|
1746
|
-
app.on_([core.KeyEvent.HOLD, core.KeyEvent.UP],
|
|
1747
|
-
app.on_(core.KeyEvent.DOWN,
|
|
1805
|
+
app.on_([core.KeyEvent.HOLD, core.KeyEvent.UP], this.onKey, this),
|
|
1806
|
+
app.on_(core.KeyEvent.DOWN, editBox.onArrow, editBox)
|
|
1748
1807
|
];
|
|
1808
|
+
if (editMask.visible)
|
|
1809
|
+
editMask.forceRender();
|
|
1749
1810
|
}
|
|
1750
1811
|
}
|
|
1751
1812
|
removeTargetEvents() {
|
|
1752
|
-
const { targetEventIds } = this;
|
|
1813
|
+
const { targetEventIds, editMask } = this;
|
|
1753
1814
|
if (targetEventIds.length) {
|
|
1754
1815
|
this.off_(targetEventIds);
|
|
1755
1816
|
targetEventIds.length = 0;
|
|
1817
|
+
if (editMask.visible)
|
|
1818
|
+
editMask.forceRender();
|
|
1756
1819
|
}
|
|
1757
1820
|
}
|
|
1758
1821
|
destroy() {
|
|
@@ -1766,6 +1829,9 @@ class Editor extends draw.Group {
|
|
|
1766
1829
|
}
|
|
1767
1830
|
}
|
|
1768
1831
|
}
|
|
1832
|
+
__decorate([
|
|
1833
|
+
mergeConfigAttr()
|
|
1834
|
+
], Editor.prototype, "mergeConfig", void 0);
|
|
1769
1835
|
__decorate([
|
|
1770
1836
|
targetAttr(onHover)
|
|
1771
1837
|
], Editor.prototype, "hoverTarget", void 0);
|
|
@@ -1830,9 +1896,7 @@ exports.EditTool = class EditTool extends InnerEditor {
|
|
|
1830
1896
|
const { moveX, moveY, editor } = e;
|
|
1831
1897
|
const { app, list } = editor;
|
|
1832
1898
|
app.lockLayout();
|
|
1833
|
-
list.forEach(target => {
|
|
1834
|
-
target.moveWorld(moveX, moveY);
|
|
1835
|
-
});
|
|
1899
|
+
list.forEach(target => { target.moveWorld(moveX, moveY); });
|
|
1836
1900
|
app.unlockLayout();
|
|
1837
1901
|
}
|
|
1838
1902
|
onScale(e) {
|
|
@@ -1841,12 +1905,10 @@ exports.EditTool = class EditTool extends InnerEditor {
|
|
|
1841
1905
|
app.lockLayout();
|
|
1842
1906
|
list.forEach(target => {
|
|
1843
1907
|
const resize = editor.getEditSize(target) !== 'scale';
|
|
1844
|
-
if (transform)
|
|
1908
|
+
if (transform)
|
|
1845
1909
|
target.transformWorld(transform, resize);
|
|
1846
|
-
|
|
1847
|
-
else {
|
|
1910
|
+
else
|
|
1848
1911
|
target.scaleOfWorld(worldOrigin, scaleX, scaleY, resize);
|
|
1849
|
-
}
|
|
1850
1912
|
});
|
|
1851
1913
|
app.unlockLayout();
|
|
1852
1914
|
}
|
|
@@ -1856,12 +1918,10 @@ exports.EditTool = class EditTool extends InnerEditor {
|
|
|
1856
1918
|
app.lockLayout();
|
|
1857
1919
|
list.forEach(target => {
|
|
1858
1920
|
const resize = editor.getEditSize(target) !== 'scale';
|
|
1859
|
-
if (transform)
|
|
1921
|
+
if (transform)
|
|
1860
1922
|
target.transformWorld(transform, resize);
|
|
1861
|
-
|
|
1862
|
-
else {
|
|
1923
|
+
else
|
|
1863
1924
|
target.rotateOfWorld(worldOrigin, rotation);
|
|
1864
|
-
}
|
|
1865
1925
|
});
|
|
1866
1926
|
app.unlockLayout();
|
|
1867
1927
|
}
|
|
@@ -1871,12 +1931,10 @@ exports.EditTool = class EditTool extends InnerEditor {
|
|
|
1871
1931
|
app.lockLayout();
|
|
1872
1932
|
list.forEach(target => {
|
|
1873
1933
|
const resize = editor.getEditSize(target) !== 'scale';
|
|
1874
|
-
if (transform)
|
|
1934
|
+
if (transform)
|
|
1875
1935
|
target.transformWorld(transform, resize);
|
|
1876
|
-
|
|
1877
|
-
else {
|
|
1936
|
+
else
|
|
1878
1937
|
target.skewOfWorld(worldOrigin, skewX, skewY, resize);
|
|
1879
|
-
}
|
|
1880
1938
|
});
|
|
1881
1939
|
app.unlockLayout();
|
|
1882
1940
|
}
|