@leafer-in/editor 1.7.0 → 1.8.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 CHANGED
@@ -64,6 +64,8 @@ function targetAttr(fn) {
64
64
  if (isSelect) {
65
65
  if (value instanceof Array && value.length > 1 && value[0].locked)
66
66
  value.splice(0, 1);
67
+ if (this.single)
68
+ this.element.syncEventer = null;
67
69
  const { beforeSelect } = this.config;
68
70
  if (beforeSelect) {
69
71
  const check = beforeSelect({ target: value });
@@ -87,9 +89,11 @@ function mergeConfigAttr() {
87
89
  return (target, key) => {
88
90
  draw.defineKey(target, key, {
89
91
  get() {
90
- const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
92
+ const { config, element, dragPoint, editBox } = this, mergeConfig = Object.assign({}, config);
91
93
  if (element && element.editConfig)
92
94
  Object.assign(mergeConfig, element.editConfig);
95
+ if (editBox.config)
96
+ Object.assign(mergeConfig, editBox.config);
93
97
  if (dragPoint) {
94
98
  if (dragPoint.editConfig)
95
99
  Object.assign(mergeConfig, dragPoint.editConfig);
@@ -121,14 +125,17 @@ class Stroker extends draw.UI {
121
125
  this.strokeAlign = 'center';
122
126
  }
123
127
  setTarget(target, style) {
124
- this.set(style);
128
+ if (style)
129
+ this.set(style);
125
130
  this.target = target;
126
131
  this.update();
127
132
  }
128
- update() {
133
+ update(style) {
129
134
  const { list } = this;
130
135
  if (list.length) {
131
136
  setListWithFn(bounds$1, list, worldBounds);
137
+ if (style)
138
+ this.set(style);
132
139
  this.set(bounds$1);
133
140
  this.visible = true;
134
141
  }
@@ -271,15 +278,14 @@ class EditSelect extends draw.Group {
271
278
  }
272
279
  onSelect() {
273
280
  if (this.running) {
274
- const { mergeConfig, list } = this.editor;
275
- const { stroke, strokeWidth, selectedStyle } = mergeConfig;
276
- this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
281
+ this.targetStroker.setTarget(this.editor.list);
277
282
  this.hoverStroker.target = null;
278
283
  }
279
284
  }
280
285
  update() {
281
286
  this.hoverStroker.update();
282
- this.targetStroker.update();
287
+ const { stroke, strokeWidth, selectedStyle } = this.editor.mergedConfig;
288
+ this.targetStroker.update(Object.assign({ stroke, strokeWidth: strokeWidth && Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
283
289
  }
284
290
  onPointerMove(e) {
285
291
  const { app, editor } = this;
@@ -555,15 +561,17 @@ const EditDataHelper = {
555
561
  toPoint(around || align, boxBounds, origin, true);
556
562
  if (dragBounds) {
557
563
  const allowBounds = dragBounds === 'parent' ? target.parent.boxBounds : dragBounds;
558
- const localBounds = new draw.Bounds(target.__localBoxBounds);
559
- localBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
560
- if (!draw.BoundsHelper.includes(allowBounds, localBounds)) {
561
- const realBounds = localBounds.getIntersect(allowBounds);
562
- const fitScaleX = realBounds.width / localBounds.width, fitScaleY = realBounds.height / localBounds.height;
563
- if (useScaleX)
564
- scaleX *= fitScaleX;
565
- if (useScaleY)
566
- scaleY *= fitScaleY;
564
+ const childBounds = new draw.Bounds(target.__localBoxBounds);
565
+ if (draw.BoundsHelper.includes(new draw.Bounds(allowBounds).spread(0.1), childBounds)) {
566
+ childBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
567
+ if (!draw.BoundsHelper.includes(allowBounds, childBounds)) {
568
+ const realBounds = childBounds.getIntersect(allowBounds);
569
+ const fitScaleX = realBounds.width / childBounds.width, fitScaleY = realBounds.height / childBounds.height;
570
+ if (useScaleX)
571
+ scaleX *= fitScaleX;
572
+ if (useScaleY)
573
+ scaleY *= fitScaleY;
574
+ }
567
575
  }
568
576
  }
569
577
  if (useScaleX && widthRange) {
@@ -698,9 +706,9 @@ const EditDataHelper = {
698
706
  };
699
707
 
700
708
  const cacheCursors = {};
701
- function updateCursor(editBox, e) {
702
- const { enterPoint: point } = editBox;
703
- if (!point || !editBox.editor.editing || !editBox.visible)
709
+ function updatePointCursor(editBox, e) {
710
+ const { enterPoint: point, dragging, skewing, resizing, flippedX, flippedY } = editBox;
711
+ if (!point || !editBox.editor.editing || !editBox.canUse)
704
712
  return;
705
713
  if (point.name === 'circle')
706
714
  return;
@@ -709,13 +717,15 @@ function updateCursor(editBox, e) {
709
717
  point.cursor = 'pointer';
710
718
  return;
711
719
  }
712
- let { rotation, flippedX, flippedY } = editBox;
720
+ let { rotation } = editBox;
713
721
  const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig;
714
722
  let showResize = pointType.includes('resize');
715
723
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
716
724
  showResize = false;
717
725
  const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew');
718
- const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
726
+ const cursor = dragging
727
+ ? (skewing ? skewCursor : (resizing ? resizeCursor : rotateCursor))
728
+ : (showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor));
719
729
  rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
720
730
  rotation = Math.round(draw.MathHelper.formatRotation(rotation, true) / 2) * 2;
721
731
  const { url, x, y } = cursor;
@@ -729,7 +739,8 @@ function updateCursor(editBox, e) {
729
739
  }
730
740
  function updateMoveCursor(editBox) {
731
741
  const { moveCursor, moveable } = editBox.mergeConfig;
732
- editBox.rect.cursor = moveable ? moveCursor : undefined;
742
+ if (editBox.canUse)
743
+ editBox.rect.cursor = moveable ? moveCursor : undefined;
733
744
  }
734
745
  function toDataURL(svg, rotation) {
735
746
  return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
@@ -745,8 +756,8 @@ class EditPoint extends draw.Box {
745
756
  const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
746
757
  class EditBox extends draw.Group {
747
758
  get mergeConfig() {
748
- const { config } = this, { mergeConfig } = this.editor;
749
- return this.mergedConfig = config ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
759
+ const { config } = this, { mergeConfig, editBox } = this.editor;
760
+ return this.mergedConfig = config && (editBox !== this) ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
750
761
  }
751
762
  get target() { return this._target || this.editor.element; }
752
763
  set target(target) { this._target = target; }
@@ -757,6 +768,13 @@ class EditBox extends draw.Group {
757
768
  get flippedX() { return this.scaleX < 0; }
758
769
  get flippedY() { return this.scaleY < 0; }
759
770
  get flippedOne() { return this.scaleX * this.scaleY < 0; }
771
+ get canUse() { return (this.visible && this.view.visible); }
772
+ get canGesture() {
773
+ if (!this.canUse)
774
+ return false;
775
+ const { moveable, resizeable, rotateable } = this.mergeConfig;
776
+ return typeof moveable === 'string' || typeof resizeable === 'string' || typeof rotateable === 'string';
777
+ }
760
778
  constructor(editor) {
761
779
  super();
762
780
  this.view = new draw.Group();
@@ -803,8 +821,7 @@ class EditBox extends draw.Group {
803
821
  for (let i = 0; i < 8; i++) {
804
822
  resizeP = resizePoints[i];
805
823
  resizeP.set(this.getPointStyle((i % 2) ? middlePointsStyle[((i - 1) / 2) % middlePointsStyle.length] : pointsStyle[(i / 2) % pointsStyle.length]));
806
- if (!(i % 2))
807
- resizeP.rotation = (i / 2) * 90;
824
+ resizeP.rotation = ((i - (i % 2 ? 1 : 0)) / 2) * 90;
808
825
  }
809
826
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
810
827
  rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
@@ -823,12 +840,19 @@ class EditBox extends draw.Group {
823
840
  this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
824
841
  this.updateBounds({ x: 0, y: 0, width, height });
825
842
  }
843
+ unload() {
844
+ this.visible = false;
845
+ if (this.app)
846
+ this.rect.syncEventer = this.app.interaction.bottomList = null;
847
+ }
826
848
  updateBounds(bounds) {
827
849
  const { editMask } = this.editor;
828
850
  const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
829
- const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
851
+ const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask, spread } = mergeConfig;
830
852
  this.visible = !this.target.locked;
831
853
  editMask.visible = mask ? true : 0;
854
+ if (spread)
855
+ draw.BoundsHelper.spread(bounds, spread);
832
856
  if (this.view.worldOpacity) {
833
857
  const { width, height } = bounds;
834
858
  const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
@@ -853,7 +877,6 @@ class EditBox extends draw.Group {
853
877
  }
854
878
  else {
855
879
  resizeL.height = height;
856
- resizeP.rotation = 90;
857
880
  if (hideOnSmall && resizeP.width * 2 > height)
858
881
  resizeP.visible = false;
859
882
  }
@@ -908,9 +931,6 @@ class EditBox extends draw.Group {
908
931
  buttons.y = point.y + margin;
909
932
  }
910
933
  }
911
- unload() {
912
- this.visible = false;
913
- }
914
934
  getPointStyle(userStyle) {
915
935
  const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig;
916
936
  const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
@@ -924,20 +944,26 @@ class EditBox extends draw.Group {
924
944
  const { middlePoint } = this.mergedConfig;
925
945
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
926
946
  }
927
- onSelect(e) {
928
- if (e.oldList.length === 1) {
929
- e.oldList[0].syncEventer = null;
930
- if (this.app)
931
- this.app.interaction.bottomList = null;
932
- }
933
- }
934
947
  onDragStart(e) {
935
948
  this.dragging = true;
936
949
  const point = this.dragPoint = e.current, { pointType } = point;
937
- const { editor, dragStartData } = this, { target } = this;
950
+ const { editor, dragStartData } = this, { target } = this, { moveable, resizeable, rotateable, skewable, hideOnMove } = this.mergeConfig;
938
951
  if (point.name === 'rect') {
939
- this.moving = true;
940
- editor.opacity = this.mergeConfig.hideOnMove ? 0 : 1;
952
+ moveable && (this.moving = true);
953
+ editor.opacity = hideOnMove ? 0 : 1;
954
+ }
955
+ else {
956
+ if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !resizeable) {
957
+ rotateable && (this.rotating = true);
958
+ if (pointType === 'resize-rotate')
959
+ resizeable && (this.resizing = true);
960
+ else if (point.name === 'resize-line')
961
+ skewable && (this.skewing = true), this.rotating = false;
962
+ }
963
+ else if (pointType === 'resize')
964
+ resizeable && (this.resizing = true);
965
+ if (pointType === 'skew')
966
+ skewable && (this.skewing = true);
941
967
  }
942
968
  dragStartData.x = e.x;
943
969
  dragStartData.y = e.y;
@@ -948,9 +974,8 @@ class EditBox extends draw.Group {
948
974
  draw.ResizeEvent.resizingKeys = editor.leafList.keys;
949
975
  }
950
976
  onDragEnd(e) {
951
- this.dragging = false;
952
977
  this.dragPoint = null;
953
- this.moving = false;
978
+ this.resetDoing();
954
979
  const { name, pointType } = e.current;
955
980
  if (name === 'rect')
956
981
  this.editor.opacity = 1;
@@ -958,31 +983,61 @@ class EditBox extends draw.Group {
958
983
  draw.ResizeEvent.resizingKeys = null;
959
984
  }
960
985
  onDrag(e) {
961
- const { transformTool } = this, point = e.current;
962
- if (point.name === 'rect') {
986
+ const { transformTool, moving, resizing, rotating, skewing } = this;
987
+ if (moving) {
963
988
  transformTool.onMove(e);
964
989
  updateMoveCursor(this);
965
990
  }
966
- else {
967
- const { pointType } = this.enterPoint = point;
968
- if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !this.mergeConfig.resizeable) {
991
+ else if (resizing || rotating || skewing) {
992
+ const point = e.current;
993
+ if (point.pointType)
994
+ this.enterPoint = point;
995
+ if (rotating)
969
996
  transformTool.onRotate(e);
970
- if (pointType === 'resize-rotate')
971
- transformTool.onScale(e);
972
- }
973
- else if (pointType === 'resize')
997
+ if (resizing)
974
998
  transformTool.onScale(e);
975
- if (pointType === 'skew')
999
+ if (skewing)
976
1000
  transformTool.onSkew(e);
977
- updateCursor(this, e);
1001
+ updatePointCursor(this, e);
1002
+ }
1003
+ }
1004
+ resetDoing() {
1005
+ if (this.canUse)
1006
+ this.dragging = this.gesturing = this.moving = this.resizing = this.rotating = this.skewing = false;
1007
+ }
1008
+ onMove(e) {
1009
+ if (this.canGesture && e.moveType !== 'drag') {
1010
+ e.stop();
1011
+ if (typeof this.mergeConfig.moveable === 'string') {
1012
+ this.gesturing = this.moving = true;
1013
+ this.transformTool.onMove(e);
1014
+ }
1015
+ }
1016
+ }
1017
+ onScale(e) {
1018
+ if (this.canGesture) {
1019
+ e.stop();
1020
+ if (typeof this.mergeConfig.resizeable === 'string') {
1021
+ this.gesturing = this.resizing = true;
1022
+ this.transformTool.onScale(e);
1023
+ }
1024
+ }
1025
+ }
1026
+ onRotate(e) {
1027
+ if (this.canGesture) {
1028
+ e.stop();
1029
+ if (typeof this.mergeConfig.rotateable === 'string') {
1030
+ this.gesturing = this.rotating = true;
1031
+ this.transformTool.onRotate(e);
1032
+ }
978
1033
  }
979
1034
  }
980
1035
  onKey(e) {
981
- updateCursor(this, e);
1036
+ updatePointCursor(this, e);
982
1037
  }
983
1038
  onArrow(e) {
984
- const { editor } = this;
985
- if (editor.editing && this.mergeConfig.keyEvent) {
1039
+ const { editor, transformTool } = this;
1040
+ if (this.canUse && editor.editing && this.mergeConfig.keyEvent) {
986
1041
  let x = 0, y = 0;
987
1042
  const distance = e.shiftKey ? 10 : 1;
988
1043
  switch (e.code) {
@@ -999,7 +1054,7 @@ class EditBox extends draw.Group {
999
1054
  x = distance;
1000
1055
  }
1001
1056
  if (x || y)
1002
- editor.move(x, y);
1057
+ transformTool.move(x, y);
1003
1058
  }
1004
1059
  }
1005
1060
  onDoubleTap(e) {
@@ -1042,12 +1097,12 @@ class EditBox extends draw.Group {
1042
1097
  [core.PointerEvent.LEAVE, () => { this.enterPoint = null; }],
1043
1098
  ];
1044
1099
  if (point.name !== 'circle')
1045
- events.push([core.PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(this, e); }]);
1100
+ events.push([core.PointerEvent.ENTER, (e) => { this.enterPoint = point, updatePointCursor(this, e); }]);
1046
1101
  this.__eventIds.push(point.on_(events));
1047
1102
  }
1048
1103
  __listenEvents() {
1049
1104
  const { rect, editor, __eventIds: events } = this;
1050
- events.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
1105
+ events.push(rect.on_([
1051
1106
  [core.DragEvent.START, this.onDragStart, this],
1052
1107
  [core.DragEvent.DRAG, this.onDrag, this],
1053
1108
  [core.DragEvent.END, this.onDragEnd, this],
@@ -1058,7 +1113,13 @@ class EditBox extends draw.Group {
1058
1113
  this.waitLeafer(() => {
1059
1114
  events.push(editor.app.on_([
1060
1115
  [[core.KeyEvent.HOLD, core.KeyEvent.UP], this.onKey, this],
1061
- [core.KeyEvent.DOWN, this.onArrow, this]
1116
+ [core.KeyEvent.DOWN, this.onArrow, this],
1117
+ [core.MoveEvent.BEFORE_MOVE, this.onMove, this, true],
1118
+ [core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
1119
+ [core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
1120
+ [core.MoveEvent.END, this.resetDoing, this],
1121
+ [core.ZoomEvent.END, this.resetDoing, this],
1122
+ [core.RotateEvent.END, this.resetDoing, this],
1062
1123
  ]));
1063
1124
  });
1064
1125
  }
@@ -1214,7 +1275,8 @@ function onTarget(editor, oldValue) {
1214
1275
  editor.simulateTarget.remove();
1215
1276
  editor.leafList.reset();
1216
1277
  }
1217
- editor.closeInnerEditor();
1278
+ editor.closeInnerEditor(true);
1279
+ editor.unloadEditTool();
1218
1280
  const data = { editor, value: target, oldValue };
1219
1281
  editor.emitEvent(new EditorEvent(EditorEvent.SELECT, data));
1220
1282
  editor.checkOpenedGroups();
@@ -1434,16 +1496,10 @@ EditorSkewEvent.SKEW = 'editor.skew';
1434
1496
 
1435
1497
  class TransformTool {
1436
1498
  onMove(e) {
1437
- const { target, mergeConfig, dragStartData } = this.editBox;
1499
+ const { target, dragStartData } = this.editBox;
1438
1500
  if (e instanceof core.MoveEvent) {
1439
- if (e.moveType !== 'drag') {
1440
- const { moveable, resizeable } = mergeConfig;
1441
- const move = e.getLocalMove(target);
1442
- if (moveable === 'move')
1443
- e.stop(), this.move(move.x, move.y);
1444
- else if (resizeable === 'zoom')
1445
- e.stop();
1446
- }
1501
+ const move = e.getLocalMove(target);
1502
+ this.move(move.x, move.y);
1447
1503
  }
1448
1504
  else {
1449
1505
  const total = { x: e.totalX, y: e.totalY };
@@ -1458,10 +1514,9 @@ class TransformTool {
1458
1514
  }
1459
1515
  onScale(e) {
1460
1516
  const { target, mergeConfig, single, dragStartData } = this.editBox;
1461
- let { around, lockRatio, resizeable, flipable, editSize } = mergeConfig;
1517
+ let { around, lockRatio, flipable, editSize } = mergeConfig;
1462
1518
  if (e instanceof core.ZoomEvent) {
1463
- if (resizeable === 'zoom')
1464
- e.stop(), this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
1519
+ this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
1465
1520
  }
1466
1521
  else {
1467
1522
  const { direction } = e.current;
@@ -1479,28 +1534,18 @@ class TransformTool {
1479
1534
  }
1480
1535
  onRotate(e) {
1481
1536
  const { target, mergeConfig, dragStartData } = this.editBox;
1482
- const { skewable, rotateable, around, rotateGap } = mergeConfig;
1483
- const { direction, name } = e.current;
1484
- if (skewable && name === 'resize-line')
1485
- return this.onSkew(e);
1537
+ const { around, rotateAround, rotateGap } = mergeConfig;
1538
+ const { direction } = e.current;
1486
1539
  let origin, rotation;
1487
1540
  if (e instanceof core.RotateEvent) {
1488
- if (rotateable === 'rotate')
1489
- e.stop(), rotation = e.rotation, origin = target.getBoxPoint(e);
1490
- else
1491
- return;
1492
- if (target.scaleX * target.scaleY < 0)
1493
- rotation = -rotation;
1541
+ rotation = e.rotation;
1542
+ origin = rotateAround ? draw.AroundHelper.getPoint(rotateAround, target.boxBounds) : target.getBoxPoint(e);
1494
1543
  }
1495
1544
  else {
1496
- const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (target.around || target.origin || around || 'center'));
1497
- rotation = data.rotation;
1545
+ const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (rotateAround || target.around || target.origin || around || 'center'));
1546
+ rotation = dragStartData.rotation + data.rotation - target.rotation;
1498
1547
  origin = data.origin;
1499
1548
  }
1500
- if (target.scaleX * target.scaleY < 0)
1501
- rotation = -rotation;
1502
- if (e instanceof core.DragEvent)
1503
- rotation = dragStartData.rotation + rotation - target.rotation;
1504
1549
  rotation = draw.MathHelper.float(draw.MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
1505
1550
  if (!rotation)
1506
1551
  return;
@@ -1666,9 +1711,13 @@ exports.Editor = class Editor extends draw.Group {
1666
1711
  get groupOpening() { return !!this.openedGroupList.length; }
1667
1712
  get multiple() { return this.list.length > 1; }
1668
1713
  get single() { return this.list.length === 1; }
1714
+ get dragPoint() { return this.editBox.dragPoint; }
1669
1715
  get dragging() { return this.editBox.dragging; }
1716
+ get gesturing() { return this.editBox.gesturing; }
1670
1717
  get moving() { return this.editBox.moving; }
1671
- get dragPoint() { return this.editBox.dragPoint; }
1718
+ get resizing() { return this.editBox.resizing; }
1719
+ get rotating() { return this.editBox.rotating; }
1720
+ get skewing() { return this.editBox.skewing; }
1672
1721
  get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1673
1722
  get buttons() { return this.editBox.buttons; }
1674
1723
  constructor(userConfig, data) {
@@ -1725,19 +1774,22 @@ exports.Editor = class Editor extends draw.Group {
1725
1774
  this.update();
1726
1775
  }
1727
1776
  updateEditTool() {
1777
+ this.unloadEditTool();
1778
+ if (this.editing) {
1779
+ const name = this.element.editOuter || 'EditTool';
1780
+ const tool = this.editTool = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
1781
+ this.editBox.load();
1782
+ tool.load();
1783
+ this.update();
1784
+ }
1785
+ }
1786
+ unloadEditTool() {
1728
1787
  let tool = this.editTool;
1729
1788
  if (tool) {
1730
1789
  this.editBox.unload();
1731
1790
  tool.unload();
1732
1791
  this.editTool = null;
1733
1792
  }
1734
- if (this.editing) {
1735
- const tag = this.element.editOuter || 'EditTool';
1736
- tool = this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
1737
- this.editBox.load();
1738
- tool.load();
1739
- this.update();
1740
- }
1741
1793
  }
1742
1794
  getEditSize(_ui) {
1743
1795
  return this.mergeConfig.editSize;
@@ -1811,16 +1863,21 @@ exports.Editor = class Editor extends draw.Group {
1811
1863
  if (group)
1812
1864
  group.emitEvent(event);
1813
1865
  }
1814
- openInnerEditor(target, select) {
1866
+ openInnerEditor(target, nameOrSelect, select) {
1867
+ let name;
1868
+ if (typeof nameOrSelect === 'string')
1869
+ name = nameOrSelect;
1870
+ else if (!select)
1871
+ select = nameOrSelect;
1815
1872
  if (target && select)
1816
1873
  this.target = target;
1817
1874
  if (this.single) {
1818
1875
  const editTarget = target || this.element;
1819
- const tag = editTarget.editInner;
1820
- if (tag && EditToolCreator.list[tag]) {
1876
+ name || (name = editTarget.editInner);
1877
+ if (name && EditToolCreator.list[name]) {
1821
1878
  this.editTool.unload();
1822
1879
  this.innerEditing = true;
1823
- this.innerEditor = this.editToolList[tag] || EditToolCreator.get(tag, this);
1880
+ this.innerEditor = this.editToolList[name] = this.editToolList[name] || EditToolCreator.get(name, this);
1824
1881
  this.innerEditor.editTarget = editTarget;
1825
1882
  this.emitInnerEvent(InnerEditorEvent.BEFORE_OPEN);
1826
1883
  this.innerEditor.load();
@@ -1828,13 +1885,14 @@ exports.Editor = class Editor extends draw.Group {
1828
1885
  }
1829
1886
  }
1830
1887
  }
1831
- closeInnerEditor() {
1888
+ closeInnerEditor(onlyInnerEditor) {
1832
1889
  if (this.innerEditing) {
1833
1890
  this.innerEditing = false;
1834
1891
  this.emitInnerEvent(InnerEditorEvent.BEFORE_CLOSE);
1835
1892
  this.innerEditor.unload();
1836
1893
  this.emitInnerEvent(InnerEditorEvent.CLOSE);
1837
- this.editTool.load();
1894
+ if (!onlyInnerEditor)
1895
+ this.updateEditTool();
1838
1896
  this.innerEditor = null;
1839
1897
  }
1840
1898
  }
@@ -1877,12 +1935,7 @@ exports.Editor = class Editor extends draw.Group {
1877
1935
  const { app, leafer, editMask } = this;
1878
1936
  this.targetEventIds = [
1879
1937
  leafer.on_(draw.RenderEvent.START, this.onRenderStart, this),
1880
- app.on_([
1881
- [draw.RenderEvent.CHILD_START, this.onAppRenderStart, this],
1882
- [core.MoveEvent.BEFORE_MOVE, this.onMove, this, true],
1883
- [core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
1884
- [core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
1885
- ])
1938
+ app.on_(draw.RenderEvent.CHILD_START, this.onAppRenderStart, this)
1886
1939
  ];
1887
1940
  if (editMask.visible)
1888
1941
  editMask.forceRender();
@@ -2153,7 +2206,7 @@ draw.Creator.editor = function (options, app) {
2153
2206
  };
2154
2207
  draw.Box.addAttr('textBox', false, draw.dataType);
2155
2208
  draw.UI.addAttr('editConfig', undefined, draw.dataType);
2156
- draw.UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', draw.dataType);
2209
+ draw.UI.addAttr('editOuter', (ui) => { ui.updateLayout(); return ui.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }, draw.dataType);
2157
2210
  draw.UI.addAttr('editInner', 'PathEditor', draw.dataType);
2158
2211
  draw.Group.addAttr('editInner', '', draw.dataType);
2159
2212
  draw.Text.addAttr('editInner', 'TextEditor', draw.dataType);