@leafer-in/editor 1.6.7 → 1.7.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
@@ -47,41 +47,10 @@ class EditorEvent extends draw.Event {
47
47
  }
48
48
  EditorEvent.BEFORE_SELECT = 'editor.before_select';
49
49
  EditorEvent.SELECT = 'editor.select';
50
+ EditorEvent.AFTER_SELECT = 'editor.after_select';
50
51
  EditorEvent.BEFORE_HOVER = 'editor.before_hover';
51
52
  EditorEvent.HOVER = 'editor.hover';
52
53
 
53
- class EditorMoveEvent extends EditorEvent {
54
- constructor(type, data) {
55
- super(type, data);
56
- }
57
- }
58
- EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
59
- EditorMoveEvent.MOVE = 'editor.move';
60
-
61
- class EditorScaleEvent extends EditorEvent {
62
- constructor(type, data) {
63
- super(type, data);
64
- }
65
- }
66
- EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
67
- EditorScaleEvent.SCALE = 'editor.scale';
68
-
69
- class EditorRotateEvent extends EditorEvent {
70
- constructor(type, data) {
71
- super(type, data);
72
- }
73
- }
74
- EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
75
- EditorRotateEvent.ROTATE = 'editor.rotate';
76
-
77
- class EditorSkewEvent extends EditorEvent {
78
- constructor(type, data) {
79
- super(type, data);
80
- }
81
- }
82
- EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
83
- EditorSkewEvent.SKEW = 'editor.skew';
84
-
85
54
  function targetAttr(fn) {
86
55
  return (target, key) => {
87
56
  const privateKey = '_' + key;
@@ -492,16 +461,16 @@ const { topLeft, top, topRight, right: right$1, bottomRight, bottom, bottomLeft,
492
461
  const { toPoint } = draw.AroundHelper;
493
462
  const { within } = draw.MathHelper;
494
463
  const EditDataHelper = {
495
- getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
464
+ getScaleData(target, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
496
465
  let align, origin = {}, scaleX = 1, scaleY = 1;
497
- const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
466
+ const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = target;
498
467
  const { width, height } = startBounds;
499
468
  if (around) {
500
469
  totalMove.x *= 2;
501
470
  totalMove.y *= 2;
502
471
  }
503
- const originChangedScaleX = element.scaleX / startBounds.scaleX;
504
- const originChangedScaleY = element.scaleY / startBounds.scaleY;
472
+ const originChangedScaleX = target.scaleX / startBounds.scaleX;
473
+ const originChangedScaleY = target.scaleY / startBounds.scaleY;
505
474
  const signX = originChangedScaleX < 0 ? -1 : 1;
506
475
  const signY = originChangedScaleY < 0 ? -1 : 1;
507
476
  const changedScaleX = scaleMode ? originChangedScaleX : signX * boxBounds.width / width;
@@ -577,7 +546,7 @@ const EditDataHelper = {
577
546
  if (useScaleY)
578
547
  scaleY /= changedScaleY;
579
548
  if (!flipable) {
580
- const { worldTransform } = element;
549
+ const { worldTransform } = target;
581
550
  if (scaleX < 0)
582
551
  scaleX = 1 / boxBounds.width / worldTransform.scaleX;
583
552
  if (scaleY < 0)
@@ -585,9 +554,9 @@ const EditDataHelper = {
585
554
  }
586
555
  toPoint(around || align, boxBounds, origin, true);
587
556
  if (dragBounds) {
588
- const allowBounds = dragBounds === 'parent' ? element.parent.boxBounds : dragBounds;
589
- const localBounds = new draw.Bounds(element.__localBoxBounds);
590
- localBounds.scaleOf(element.getLocalPointByInner(origin), scaleX, scaleY);
557
+ const allowBounds = dragBounds === 'parent' ? target.parent.boxBounds : dragBounds;
558
+ const localBounds = new draw.Bounds(target.__localBoxBounds);
559
+ localBounds.scaleOf(target.getLocalPointByInner(origin), scaleX, scaleY);
591
560
  if (!draw.BoundsHelper.includes(allowBounds, localBounds)) {
592
561
  const realBounds = localBounds.getIntersect(allowBounds);
593
562
  const fitScaleX = realBounds.width / localBounds.width, fitScaleY = realBounds.height / localBounds.height;
@@ -598,11 +567,11 @@ const EditDataHelper = {
598
567
  }
599
568
  }
600
569
  if (useScaleX && widthRange) {
601
- const nowWidth = boxBounds.width * element.scaleX;
570
+ const nowWidth = boxBounds.width * target.scaleX;
602
571
  scaleX = within(nowWidth * scaleX, widthRange) / nowWidth;
603
572
  }
604
573
  if (useScaleY && heightRange) {
605
- const nowHeight = boxBounds.height * element.scaleY;
574
+ const nowHeight = boxBounds.height * target.scaleY;
606
575
  scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
607
576
  }
608
577
  if (useScaleX && Math.abs(scaleX * worldBoxBounds.width) < 1)
@@ -613,7 +582,7 @@ const EditDataHelper = {
613
582
  scaleY = scaleX = Math.min(scaleX, scaleY);
614
583
  return { origin, scaleX, scaleY, direction, lockRatio, around };
615
584
  },
616
- getRotateData(bounds, direction, current, last, around) {
585
+ getRotateData(target, direction, current, last, around) {
617
586
  let align, origin = {};
618
587
  switch (direction) {
619
588
  case topLeft:
@@ -631,8 +600,8 @@ const EditDataHelper = {
631
600
  default:
632
601
  align = 'center';
633
602
  }
634
- toPoint(around || align, bounds, origin, true);
635
- return { origin, rotation: draw.PointHelper.getRotation(last, origin, current) };
603
+ toPoint(around || align, target.boxBounds, origin, true);
604
+ return { origin, rotation: draw.PointHelper.getRotation(last, target.getWorldPointByBox(origin), current) };
636
605
  },
637
606
  getSkewData(bounds, direction, move, around) {
638
607
  let align, origin = {}, skewX = 0, skewY = 0;
@@ -729,9 +698,9 @@ const EditDataHelper = {
729
698
  };
730
699
 
731
700
  const cacheCursors = {};
732
- function updateCursor(editor, e) {
733
- const { editBox } = editor, point = editBox.enterPoint;
734
- if (!point || !editor.editing || !editBox.visible)
701
+ function updateCursor(editBox, e) {
702
+ const { enterPoint: point } = editBox;
703
+ if (!point || !editBox.editor.editing || !editBox.visible)
735
704
  return;
736
705
  if (point.name === 'circle')
737
706
  return;
@@ -740,9 +709,8 @@ function updateCursor(editor, e) {
740
709
  point.cursor = 'pointer';
741
710
  return;
742
711
  }
743
- let { rotation } = editBox;
744
- const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
745
- const { pointType } = point, { flippedX, flippedY } = editBox;
712
+ let { rotation, flippedX, flippedY } = editBox;
713
+ const { pointType } = point, { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editBox.mergeConfig;
746
714
  let showResize = pointType.includes('resize');
747
715
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
748
716
  showResize = false;
@@ -759,9 +727,9 @@ function updateCursor(editor, e) {
759
727
  cacheCursors[key] = point.cursor = { url: toDataURL(url, rotation), x, y };
760
728
  }
761
729
  }
762
- function updateMoveCursor(editor) {
763
- const { moveCursor, moveable } = editor.mergeConfig;
764
- editor.editBox.rect.cursor = moveable ? moveCursor : undefined;
730
+ function updateMoveCursor(editBox) {
731
+ const { moveCursor, moveable } = editBox.mergeConfig;
732
+ editBox.rect.cursor = moveable ? moveCursor : undefined;
765
733
  }
766
734
  function toDataURL(svg, rotation) {
767
735
  return '"data:image/svg+xml,' + encodeURIComponent(svg.replace('{{rotation}}', rotation.toString())) + '"';
@@ -776,6 +744,15 @@ class EditPoint extends draw.Box {
776
744
 
777
745
  const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
778
746
  class EditBox extends draw.Group {
747
+ get mergeConfig() {
748
+ const { config } = this, { mergeConfig } = this.editor;
749
+ return this.mergedConfig = config ? Object.assign(Object.assign({}, mergeConfig), config) : mergeConfig;
750
+ }
751
+ get target() { return this._target || this.editor.element; }
752
+ set target(target) { this._target = target; }
753
+ get single() { return !!this._target || this.editor.single; }
754
+ get transformTool() { return this._transformTool || this.editor; }
755
+ set transformTool(tool) { this._transformTool = tool; }
779
756
  get flipped() { return this.flippedX || this.flippedY; }
780
757
  get flippedX() { return this.scaleX < 0; }
781
758
  get flippedY() { return this.scaleY < 0; }
@@ -818,8 +795,7 @@ class EditBox extends draw.Group {
818
795
  this.add(view);
819
796
  }
820
797
  load() {
821
- const { mergeConfig, element, single } = this.editor;
822
- const { rect, circle, resizePoints } = this;
798
+ const { target, mergeConfig, single, rect, circle, resizePoints } = this;
823
799
  const { stroke, strokeWidth } = mergeConfig;
824
800
  const pointsStyle = this.getPointsStyle();
825
801
  const middlePointsStyle = this.getMiddlePointsStyle();
@@ -832,18 +808,26 @@ class EditBox extends draw.Group {
832
808
  }
833
809
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
834
810
  rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
835
- rect.hittable = !single;
836
- rect.syncEventer = single && this.editor;
837
- if (single) {
838
- element.syncEventer = rect;
839
- this.app.interaction.bottomList = [{ target: rect, proxy: element }];
811
+ const syncEventer = single && this.transformTool.editTool;
812
+ rect.hittable = !syncEventer;
813
+ rect.syncEventer = syncEventer && this.editor;
814
+ if (syncEventer) {
815
+ target.syncEventer = rect;
816
+ this.app.interaction.bottomList = [{ target: rect, proxy: target }];
840
817
  }
818
+ updateMoveCursor(this);
819
+ }
820
+ update() {
821
+ const { editor } = this;
822
+ const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = this.target.getLayoutBounds('box', editor, true);
823
+ this.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
824
+ this.updateBounds({ x: 0, y: 0, width, height });
841
825
  }
842
- update(bounds) {
843
- const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines, editor } = this;
844
- const { mergeConfig, element, multiple, editMask } = editor;
826
+ updateBounds(bounds) {
827
+ const { editMask } = this.editor;
828
+ const { mergeConfig, single, rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
845
829
  const { middlePoint, resizeable, rotateable, hideOnSmall, editBox, mask } = mergeConfig;
846
- this.visible = !element.locked;
830
+ this.visible = !this.target.locked;
847
831
  editMask.visible = mask ? true : 0;
848
832
  if (this.view.worldOpacity) {
849
833
  const { width, height } = bounds;
@@ -877,25 +861,25 @@ class EditBox extends draw.Group {
877
861
  }
878
862
  circle.visible = showPoints && rotateable && !!(mergeConfig.circle || mergeConfig.rotatePoint);
879
863
  if (circle.visible)
880
- this.layoutCircle(mergeConfig);
864
+ this.layoutCircle();
881
865
  if (rect.path)
882
866
  rect.path = null;
883
- rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
867
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: single ? editBox : true }));
884
868
  buttons.visible = showPoints && buttons.children.length > 0 || 0;
885
869
  if (buttons.visible)
886
- this.layoutButtons(mergeConfig);
870
+ this.layoutButtons();
887
871
  }
888
872
  else
889
873
  rect.set(bounds);
890
874
  }
891
- layoutCircle(config) {
892
- const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = config;
875
+ layoutCircle() {
876
+ const { circleDirection, circleMargin, buttonsMargin, buttonsDirection, middlePoint } = this.mergedConfig;
893
877
  const direction = fourDirection.indexOf(circleDirection || ((this.buttons.children.length && buttonsDirection === 'bottom') ? 'top' : 'bottom'));
894
878
  this.setButtonPosition(this.circle, direction, circleMargin || buttonsMargin, !!middlePoint);
895
879
  }
896
- layoutButtons(config) {
880
+ layoutButtons() {
897
881
  const { buttons } = this;
898
- const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = config;
882
+ const { buttonsDirection, buttonsFixed, buttonsMargin, middlePoint } = this.mergedConfig;
899
883
  const { flippedX, flippedY } = this;
900
884
  let index = fourDirection.indexOf(buttonsDirection);
901
885
  if ((index % 2 && flippedX) || ((index + 1) % 2 && flippedY)) {
@@ -928,16 +912,16 @@ class EditBox extends draw.Group {
928
912
  this.visible = false;
929
913
  }
930
914
  getPointStyle(userStyle) {
931
- const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
915
+ const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.mergedConfig;
932
916
  const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
933
917
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
934
918
  }
935
919
  getPointsStyle() {
936
- const { point } = this.editor.mergeConfig;
920
+ const { point } = this.mergedConfig;
937
921
  return point instanceof Array ? point : [point];
938
922
  }
939
923
  getMiddlePointsStyle() {
940
- const { middlePoint } = this.editor.mergeConfig;
924
+ const { middlePoint } = this.mergedConfig;
941
925
  return middlePoint instanceof Array ? middlePoint : (middlePoint ? [middlePoint] : this.getPointsStyle());
942
926
  }
943
927
  onSelect(e) {
@@ -950,16 +934,16 @@ class EditBox extends draw.Group {
950
934
  onDragStart(e) {
951
935
  this.dragging = true;
952
936
  const point = this.dragPoint = e.current, { pointType } = point;
953
- const { editor, dragStartData } = this, { element } = editor;
937
+ const { editor, dragStartData } = this, { target } = this;
954
938
  if (point.name === 'rect') {
955
939
  this.moving = true;
956
- editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
940
+ editor.opacity = this.mergeConfig.hideOnMove ? 0 : 1;
957
941
  }
958
942
  dragStartData.x = e.x;
959
943
  dragStartData.y = e.y;
960
- dragStartData.point = { x: element.x, y: element.y };
961
- dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
962
- dragStartData.rotation = element.rotation;
944
+ dragStartData.point = { x: target.x, y: target.y };
945
+ dragStartData.bounds = Object.assign({}, target.getLayoutBounds('box', 'local'));
946
+ dragStartData.rotation = target.rotation;
963
947
  if (pointType && pointType.includes('resize'))
964
948
  draw.ResizeEvent.resizingKeys = editor.leafList.keys;
965
949
  }
@@ -974,22 +958,31 @@ class EditBox extends draw.Group {
974
958
  draw.ResizeEvent.resizingKeys = null;
975
959
  }
976
960
  onDrag(e) {
977
- const { editor } = this;
978
- const { pointType } = this.enterPoint = e.current;
979
- if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
980
- editor.onRotate(e);
981
- if (pointType === 'resize-rotate')
982
- editor.onScale(e);
983
- }
984
- else if (pointType === 'resize')
985
- editor.onScale(e);
986
- if (pointType === 'skew')
987
- editor.onSkew(e);
988
- updateCursor(editor, e);
961
+ const { transformTool } = this, point = e.current;
962
+ if (point.name === 'rect') {
963
+ transformTool.onMove(e);
964
+ updateMoveCursor(this);
965
+ }
966
+ else {
967
+ const { pointType } = this.enterPoint = point;
968
+ if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !this.mergeConfig.resizeable) {
969
+ transformTool.onRotate(e);
970
+ if (pointType === 'resize-rotate')
971
+ transformTool.onScale(e);
972
+ }
973
+ else if (pointType === 'resize')
974
+ transformTool.onScale(e);
975
+ if (pointType === 'skew')
976
+ transformTool.onSkew(e);
977
+ updateCursor(this, e);
978
+ }
979
+ }
980
+ onKey(e) {
981
+ updateCursor(this, e);
989
982
  }
990
983
  onArrow(e) {
991
984
  const { editor } = this;
992
- if (editor.editing && editor.mergeConfig.keyEvent) {
985
+ if (editor.editing && this.mergeConfig.keyEvent) {
993
986
  let x = 0, y = 0;
994
987
  const distance = e.shiftKey ? 10 : 1;
995
988
  switch (e.code) {
@@ -1010,27 +1003,28 @@ class EditBox extends draw.Group {
1010
1003
  }
1011
1004
  }
1012
1005
  onDoubleTap(e) {
1013
- if (this.editor.mergeConfig.openInner === 'double')
1006
+ const { openInner, preventEditInner } = this.mergeConfig;
1007
+ if (openInner === 'double' && !preventEditInner)
1014
1008
  this.openInner(e);
1015
1009
  }
1016
1010
  onLongPress(e) {
1017
- if (this.editor.mergeConfig.openInner === 'long')
1011
+ const { openInner, preventEditInner } = this.mergeConfig;
1012
+ if (openInner === 'long' && preventEditInner)
1018
1013
  this.openInner(e);
1019
1014
  }
1020
1015
  openInner(e) {
1021
- const { editor } = this;
1022
- if (editor.single) {
1023
- const { element } = editor;
1024
- if (element.locked)
1016
+ const { editor, target } = this;
1017
+ if (this.single) {
1018
+ if (target.locked)
1025
1019
  return;
1026
- if (element.isBranch && !element.editInner) {
1027
- if (element.textBox) {
1028
- const { children } = element;
1020
+ if (target.isBranch && !target.editInner) {
1021
+ if (target.textBox) {
1022
+ const { children } = target;
1029
1023
  const find = children.find(item => item.editable && item instanceof draw.Text) || children.find(item => item instanceof draw.Text);
1030
1024
  if (find)
1031
1025
  return editor.openInnerEditor(find);
1032
1026
  }
1033
- editor.openGroup(element);
1027
+ editor.openGroup(target);
1034
1028
  editor.target = editor.selector.findDeepOne(e);
1035
1029
  }
1036
1030
  else {
@@ -1039,7 +1033,6 @@ class EditBox extends draw.Group {
1039
1033
  }
1040
1034
  }
1041
1035
  listenPointEvents(point, type, direction) {
1042
- const { editor } = this;
1043
1036
  point.direction = direction;
1044
1037
  point.pointType = type;
1045
1038
  const events = [
@@ -1049,19 +1042,25 @@ class EditBox extends draw.Group {
1049
1042
  [core.PointerEvent.LEAVE, () => { this.enterPoint = null; }],
1050
1043
  ];
1051
1044
  if (point.name !== 'circle')
1052
- events.push([core.PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(editor, e); }]);
1045
+ events.push([core.PointerEvent.ENTER, (e) => { this.enterPoint = point, updateCursor(this, e); }]);
1053
1046
  this.__eventIds.push(point.on_(events));
1054
1047
  }
1055
1048
  __listenEvents() {
1056
- const { rect, editor } = this;
1057
- this.__eventIds.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
1049
+ const { rect, editor, __eventIds: events } = this;
1050
+ events.push(editor.on_(EditorEvent.SELECT, this.onSelect, this), rect.on_([
1058
1051
  [core.DragEvent.START, this.onDragStart, this],
1059
- [core.DragEvent.DRAG, editor.onMove, editor],
1052
+ [core.DragEvent.DRAG, this.onDrag, this],
1060
1053
  [core.DragEvent.END, this.onDragEnd, this],
1061
- [core.PointerEvent.ENTER, () => updateMoveCursor(editor)],
1054
+ [core.PointerEvent.ENTER, () => updateMoveCursor(this)],
1062
1055
  [core.PointerEvent.DOUBLE_TAP, this.onDoubleTap, this],
1063
1056
  [core.PointerEvent.LONG_PRESS, this.onLongPress, this]
1064
1057
  ]));
1058
+ this.waitLeafer(() => {
1059
+ events.push(editor.app.on_([
1060
+ [[core.KeyEvent.HOLD, core.KeyEvent.UP], this.onKey, this],
1061
+ [core.KeyEvent.DOWN, this.onArrow, this]
1062
+ ]));
1063
+ });
1065
1064
  }
1066
1065
  __removeListenEvents() {
1067
1066
  this.off_(this.__eventIds);
@@ -1092,11 +1091,12 @@ class EditMask extends draw.UI {
1092
1091
  if (options.bounds && !options.bounds.hit(editor.editBox.rect.__world, options.matrix))
1093
1092
  return;
1094
1093
  canvas.saveBlendMode('destination-out');
1094
+ options = Object.assign(Object.assign({}, options), { shape: true });
1095
1095
  editor.list.forEach(item => {
1096
- item.__renderShape(canvas, options);
1097
- const { __box, parent } = item;
1098
- if ((item = __box) || ((item = parent) && parent.textBox))
1099
- item.__renderShape(canvas, options);
1096
+ item.__render(canvas, options);
1097
+ const { parent } = item;
1098
+ if (parent && parent.textBox)
1099
+ parent.__renderShape(canvas, options);
1100
1100
  });
1101
1101
  canvas.restoreBlendMode();
1102
1102
  }
@@ -1191,7 +1191,7 @@ const config = {
1191
1191
  const bounds = new draw.Bounds();
1192
1192
  function simulate(editor) {
1193
1193
  const { simulateTarget, list } = editor;
1194
- const { zoomLayer } = list[0].leafer.zoomLayer;
1194
+ const { zoomLayer } = list[0].leafer;
1195
1195
  simulateTarget.safeChange(() => {
1196
1196
  bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
1197
1197
  if (bounds.width === 0)
@@ -1213,15 +1213,14 @@ function onTarget(editor, oldValue) {
1213
1213
  else {
1214
1214
  editor.simulateTarget.remove();
1215
1215
  editor.leafList.reset();
1216
- editor.closeInnerEditor();
1217
1216
  }
1218
- editor.emitEvent(new EditorEvent(EditorEvent.SELECT, { editor, value: target, oldValue }));
1217
+ editor.closeInnerEditor();
1218
+ const data = { editor, value: target, oldValue };
1219
+ editor.emitEvent(new EditorEvent(EditorEvent.SELECT, data));
1219
1220
  editor.checkOpenedGroups();
1220
1221
  if (editor.editing) {
1221
1222
  editor.waitLeafer(() => {
1222
- updateMoveCursor(editor);
1223
1223
  editor.updateEditTool();
1224
- editor.update();
1225
1224
  editor.listenTargetEvents();
1226
1225
  });
1227
1226
  }
@@ -1229,6 +1228,7 @@ function onTarget(editor, oldValue) {
1229
1228
  editor.updateEditTool();
1230
1229
  editor.removeTargetEvents();
1231
1230
  }
1231
+ editor.emitEvent(new EditorEvent(EditorEvent.AFTER_SELECT, data));
1232
1232
  }
1233
1233
  function onHover(editor, oldValue) {
1234
1234
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
@@ -1400,93 +1400,45 @@ class SimulateElement extends draw.Rect {
1400
1400
  }
1401
1401
  }
1402
1402
 
1403
- class Editor extends draw.Group {
1404
- get list() { return this.leafList.list; }
1405
- get dragHoverExclude() { return [this.editBox.rect]; }
1406
- get editing() { return !!this.list.length; }
1407
- get groupOpening() { return !!this.openedGroupList.length; }
1408
- get multiple() { return this.list.length > 1; }
1409
- get single() { return this.list.length === 1; }
1410
- get dragging() { return this.editBox.dragging; }
1411
- get moving() { return this.editBox.moving; }
1412
- get dragPoint() { return this.editBox.dragPoint; }
1413
- get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1414
- get buttons() { return this.editBox.buttons; }
1415
- constructor(userConfig, data) {
1416
- super(data);
1417
- this.leafList = new draw.LeafList();
1418
- this.openedGroupList = new draw.LeafList();
1419
- this.simulateTarget = new SimulateElement(this);
1420
- this.editBox = new EditBox(this);
1421
- this.editToolList = {};
1422
- this.selector = new EditSelect(this);
1423
- this.editMask = new EditMask(this);
1424
- this.targetEventIds = [];
1425
- let mergedConfig = draw.DataHelper.clone(config);
1426
- if (userConfig)
1427
- mergedConfig = draw.DataHelper.default(userConfig, mergedConfig);
1428
- this.mergedConfig = this.config = mergedConfig;
1429
- this.addMany(this.editMask, this.selector, this.editBox);
1430
- if (!draw.Plugin.has('resize'))
1431
- this.config.editSize = 'scale';
1432
- }
1433
- select(target) {
1434
- this.target = target;
1435
- }
1436
- cancel() {
1437
- this.target = null;
1438
- }
1439
- hasItem(item) {
1440
- return this.leafList.has(item);
1441
- }
1442
- addItem(item) {
1443
- if (!this.hasItem(item) && !item.locked)
1444
- this.leafList.add(item), this.target = this.leafList.list;
1445
- }
1446
- removeItem(item) {
1447
- if (this.hasItem(item))
1448
- this.leafList.remove(item), this.target = this.leafList.list;
1449
- }
1450
- shiftItem(item) {
1451
- this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
1452
- }
1453
- update() {
1454
- if (this.editing) {
1455
- if (!this.element.parent)
1456
- return this.cancel();
1457
- if (this.innerEditing)
1458
- this.innerEditor.update();
1459
- this.editTool.update();
1460
- this.selector.update();
1461
- }
1403
+ class EditorMoveEvent extends EditorEvent {
1404
+ constructor(type, data) {
1405
+ super(type, data);
1462
1406
  }
1463
- updateEditBox() {
1464
- if (this.multiple)
1465
- simulate(this);
1466
- this.update();
1407
+ }
1408
+ EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
1409
+ EditorMoveEvent.MOVE = 'editor.move';
1410
+
1411
+ class EditorScaleEvent extends EditorEvent {
1412
+ constructor(type, data) {
1413
+ super(type, data);
1467
1414
  }
1468
- updateEditTool() {
1469
- const tool = this.editTool;
1470
- if (tool) {
1471
- this.editBox.unload();
1472
- tool.unload();
1473
- this.editTool = null;
1474
- }
1475
- if (this.editing) {
1476
- const tag = this.single ? this.list[0].editOuter : 'EditTool';
1477
- this.editTool = this.editToolList[tag] = this.editToolList[tag] || EditToolCreator.get(tag, this);
1478
- this.editBox.load();
1479
- this.editTool.load();
1480
- }
1415
+ }
1416
+ EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
1417
+ EditorScaleEvent.SCALE = 'editor.scale';
1418
+
1419
+ class EditorRotateEvent extends EditorEvent {
1420
+ constructor(type, data) {
1421
+ super(type, data);
1481
1422
  }
1482
- getEditSize(_ui) {
1483
- return this.mergeConfig.editSize;
1423
+ }
1424
+ EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
1425
+ EditorRotateEvent.ROTATE = 'editor.rotate';
1426
+
1427
+ class EditorSkewEvent extends EditorEvent {
1428
+ constructor(type, data) {
1429
+ super(type, data);
1484
1430
  }
1431
+ }
1432
+ EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
1433
+ EditorSkewEvent.SKEW = 'editor.skew';
1434
+
1435
+ class TransformTool {
1485
1436
  onMove(e) {
1437
+ const { target, mergeConfig, dragStartData } = this.editBox;
1486
1438
  if (e instanceof core.MoveEvent) {
1487
1439
  if (e.moveType !== 'drag') {
1488
- const { moveable, resizeable } = this.mergeConfig;
1489
- const move = e.getLocalMove(this.element);
1440
+ const { moveable, resizeable } = mergeConfig;
1441
+ const move = e.getLocalMove(target);
1490
1442
  if (moveable === 'move')
1491
1443
  e.stop(), this.move(move.x, move.y);
1492
1444
  else if (resizeable === 'zoom')
@@ -1501,22 +1453,22 @@ class Editor extends draw.Group {
1501
1453
  else
1502
1454
  total.x = 0;
1503
1455
  }
1504
- this.move(core.DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
1456
+ this.move(core.DragEvent.getValidMove(target, dragStartData.point, total));
1505
1457
  }
1506
1458
  }
1507
1459
  onScale(e) {
1508
- const { element } = this;
1509
- let { around, lockRatio, resizeable, flipable, editSize } = this.mergeConfig;
1460
+ const { target, mergeConfig, single, dragStartData } = this.editBox;
1461
+ let { around, lockRatio, resizeable, flipable, editSize } = mergeConfig;
1510
1462
  if (e instanceof core.ZoomEvent) {
1511
1463
  if (resizeable === 'zoom')
1512
- e.stop(), this.scaleOf(element.getBoxPoint(e), e.scale, e.scale);
1464
+ e.stop(), this.scaleOf(target.getBoxPoint(e), e.scale, e.scale);
1513
1465
  }
1514
1466
  else {
1515
1467
  const { direction } = e.current;
1516
- if (e.shiftKey || element.lockRatio)
1468
+ if (e.shiftKey || target.lockRatio)
1517
1469
  lockRatio = true;
1518
- const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
1519
- if (this.editTool.onScaleWithDrag) {
1470
+ const data = EditDataHelper.getScaleData(target, dragStartData.bounds, direction, e.getInnerTotal(target), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, !single || editSize === 'scale');
1471
+ if (this.editTool && this.editTool.onScaleWithDrag) {
1520
1472
  data.drag = e;
1521
1473
  this.scaleWithDrag(data);
1522
1474
  }
@@ -1526,38 +1478,38 @@ class Editor extends draw.Group {
1526
1478
  }
1527
1479
  }
1528
1480
  onRotate(e) {
1529
- const { skewable, rotateable, around, rotateGap } = this.mergeConfig;
1481
+ const { target, mergeConfig, dragStartData } = this.editBox;
1482
+ const { skewable, rotateable, around, rotateGap } = mergeConfig;
1530
1483
  const { direction, name } = e.current;
1531
1484
  if (skewable && name === 'resize-line')
1532
1485
  return this.onSkew(e);
1533
- const { element } = this, { dragStartData } = this.editBox;
1534
1486
  let origin, rotation;
1535
1487
  if (e instanceof core.RotateEvent) {
1536
1488
  if (rotateable === 'rotate')
1537
- e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
1489
+ e.stop(), rotation = e.rotation, origin = target.getBoxPoint(e);
1538
1490
  else
1539
1491
  return;
1540
- if (element.scaleX * element.scaleY < 0)
1492
+ if (target.scaleX * target.scaleY < 0)
1541
1493
  rotation = -rotation;
1542
1494
  }
1543
1495
  else {
1544
- const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
1496
+ const data = EditDataHelper.getRotateData(target, direction, e, dragStartData, e.shiftKey ? null : (target.around || target.origin || around || 'center'));
1545
1497
  rotation = data.rotation;
1546
1498
  origin = data.origin;
1547
1499
  }
1548
- if (element.scaleX * element.scaleY < 0)
1500
+ if (target.scaleX * target.scaleY < 0)
1549
1501
  rotation = -rotation;
1550
1502
  if (e instanceof core.DragEvent)
1551
- rotation = dragStartData.rotation + rotation - element.rotation;
1552
- rotation = draw.MathHelper.float(draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
1503
+ rotation = dragStartData.rotation + rotation - target.rotation;
1504
+ rotation = draw.MathHelper.float(draw.MathHelper.getGapRotation(rotation, rotateGap, target.rotation), 2);
1553
1505
  if (!rotation)
1554
1506
  return;
1555
1507
  this.rotateOf(origin, rotation);
1556
1508
  }
1557
1509
  onSkew(e) {
1558
- const { element } = this;
1559
- const { around } = this.mergeConfig;
1560
- const { origin, skewX, skewY } = EditDataHelper.getSkewData(element.boxBounds, e.current.direction, e.getInnerMove(element), EditDataHelper.getAround(around, e.altKey));
1510
+ const { target, mergeConfig } = this.editBox;
1511
+ const { around } = mergeConfig;
1512
+ const { origin, skewX, skewY } = EditDataHelper.getSkewData(target.boxBounds, e.current.direction, e.getInnerMove(target), EditDataHelper.getAround(around, e.altKey));
1561
1513
  if (!skewX && !skewY)
1562
1514
  return;
1563
1515
  this.skewOf(origin, skewX, skewY);
@@ -1567,7 +1519,8 @@ class Editor extends draw.Group {
1567
1519
  return;
1568
1520
  if (typeof x === 'object')
1569
1521
  y = x.y, x = x.x;
1570
- const { element: target } = this, { beforeMove } = this.mergeConfig;
1522
+ const { target, mergeConfig, single, editor } = this.editBox;
1523
+ const { beforeMove } = mergeConfig;
1571
1524
  if (beforeMove) {
1572
1525
  const check = beforeMove({ target, x, y });
1573
1526
  if (typeof check === 'object')
@@ -1576,25 +1529,26 @@ class Editor extends draw.Group {
1576
1529
  return;
1577
1530
  }
1578
1531
  const world = target.getWorldPointByLocal({ x, y }, null, true);
1579
- if (this.multiple)
1532
+ if (!single)
1580
1533
  target.safeChange(() => target.move(x, y));
1581
- const data = { target, editor: this, moveX: world.x, moveY: world.y };
1534
+ const data = { target, editor, moveX: world.x, moveY: world.y };
1582
1535
  this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
1583
1536
  const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
1584
- this.editTool.onMove(event);
1537
+ this.doMove(event);
1585
1538
  this.emitEvent(event);
1586
1539
  }
1587
1540
  scaleWithDrag(data) {
1588
1541
  if (!this.checkTransform('resizeable'))
1589
1542
  return;
1590
- const { element: target } = this, { beforeScale } = this.mergeConfig;
1543
+ const { target, mergeConfig, editor } = this.editBox;
1544
+ const { beforeScale } = mergeConfig;
1591
1545
  if (beforeScale) {
1592
1546
  const { origin, scaleX, scaleY, drag } = data;
1593
1547
  const check = beforeScale({ target, drag, origin, scaleX, scaleY });
1594
1548
  if (check === false)
1595
1549
  return;
1596
1550
  }
1597
- data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
1551
+ data = Object.assign(Object.assign({}, data), { target, editor, worldOrigin: target.getWorldPoint(data.origin) });
1598
1552
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1599
1553
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1600
1554
  this.editTool.onScaleWithDrag(event);
@@ -1603,7 +1557,8 @@ class Editor extends draw.Group {
1603
1557
  scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
1604
1558
  if (!this.checkTransform('resizeable'))
1605
1559
  return;
1606
- const { element: target } = this, { beforeScale } = this.mergeConfig;
1560
+ const { target, mergeConfig, single, editor } = this.editBox;
1561
+ const { beforeScale } = mergeConfig;
1607
1562
  if (beforeScale) {
1608
1563
  const check = beforeScale({ target, origin, scaleX, scaleY });
1609
1564
  if (typeof check === 'object')
@@ -1612,29 +1567,30 @@ class Editor extends draw.Group {
1612
1567
  return;
1613
1568
  }
1614
1569
  const worldOrigin = this.getWorldOrigin(origin);
1615
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
1616
- const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
1570
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
1571
+ const data = { target, editor, worldOrigin, scaleX, scaleY, transform };
1617
1572
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1618
1573
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1619
- this.editTool.onScale(event);
1574
+ this.doScale(event);
1620
1575
  this.emitEvent(event);
1621
1576
  }
1622
1577
  flip(axis) {
1623
1578
  if (!this.checkTransform('resizeable'))
1624
1579
  return;
1625
- const { element } = this;
1580
+ const { target, single, editor } = this.editBox;
1626
1581
  const worldOrigin = this.getWorldOrigin('center');
1627
- const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new draw.Matrix(draw.LeafHelper.getFlipTransform(element, axis));
1628
- const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
1582
+ const transform = !single ? this.getChangedTransform(() => target.safeChange(() => target.flip(axis))) : new draw.Matrix(draw.LeafHelper.getFlipTransform(target, axis));
1583
+ const data = { target, editor, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
1629
1584
  this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1630
1585
  const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1631
- this.editTool.onScale(event);
1586
+ this.doScale(event);
1632
1587
  this.emitEvent(event);
1633
1588
  }
1634
1589
  rotateOf(origin, rotation) {
1635
1590
  if (!this.checkTransform('rotateable'))
1636
1591
  return;
1637
- const { element: target } = this, { beforeRotate } = this.mergeConfig;
1592
+ const { target, mergeConfig, single, editor } = this.editBox;
1593
+ const { beforeRotate } = mergeConfig;
1638
1594
  if (beforeRotate) {
1639
1595
  const check = beforeRotate({ target, origin, rotation });
1640
1596
  if (typeof check === 'number')
@@ -1643,17 +1599,18 @@ class Editor extends draw.Group {
1643
1599
  return;
1644
1600
  }
1645
1601
  const worldOrigin = this.getWorldOrigin(origin);
1646
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
1647
- const data = { target, editor: this, worldOrigin, rotation, transform };
1602
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
1603
+ const data = { target, editor, worldOrigin, rotation, transform };
1648
1604
  this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
1649
1605
  const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
1650
- this.editTool.onRotate(event);
1606
+ this.doRotate(event);
1651
1607
  this.emitEvent(event);
1652
1608
  }
1653
1609
  skewOf(origin, skewX, skewY = 0, _resize) {
1654
1610
  if (!this.checkTransform('skewable'))
1655
1611
  return;
1656
- const { element: target } = this, { beforeSkew } = this.mergeConfig;
1612
+ const { target, mergeConfig, single, editor } = this.editBox;
1613
+ const { beforeSkew } = mergeConfig;
1657
1614
  if (beforeSkew) {
1658
1615
  const check = beforeSkew({ target, origin, skewX, skewY });
1659
1616
  if (typeof check === 'object')
@@ -1662,25 +1619,142 @@ class Editor extends draw.Group {
1662
1619
  return;
1663
1620
  }
1664
1621
  const worldOrigin = this.getWorldOrigin(origin);
1665
- const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
1666
- const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
1622
+ const transform = !single && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
1623
+ const data = { target, editor, worldOrigin, skewX, skewY, transform };
1667
1624
  this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
1668
1625
  const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
1669
- this.editTool.onSkew(event);
1626
+ this.doSkew(event);
1670
1627
  this.emitEvent(event);
1671
1628
  }
1672
- checkTransform(type) { return this.element && !this.element.locked && this.mergeConfig[type]; }
1629
+ doMove(event) {
1630
+ this.editTool.onMove(event);
1631
+ }
1632
+ doScale(event) {
1633
+ this.editTool.onScale(event);
1634
+ }
1635
+ doRotate(event) {
1636
+ this.editTool.onRotate(event);
1637
+ }
1638
+ doSkew(event) {
1639
+ this.editTool.onSkew(event);
1640
+ }
1641
+ checkTransform(type) {
1642
+ const { target, mergeConfig } = this.editBox;
1643
+ return target && !target.locked && mergeConfig[type];
1644
+ }
1673
1645
  getWorldOrigin(origin) {
1674
- return this.element.getWorldPoint(draw.LeafHelper.getInnerOrigin(this.element, origin));
1646
+ const { target } = this.editBox;
1647
+ return target.getWorldPoint(draw.LeafHelper.getInnerOrigin(target, origin));
1675
1648
  }
1676
1649
  getChangedTransform(func) {
1677
- const { element } = this;
1678
- if (this.multiple && !element.canChange)
1679
- return element.changedTransform;
1680
- const oldMatrix = new draw.Matrix(element.worldTransform);
1650
+ const { target, single } = this.editBox;
1651
+ if (!single && !target.canChange)
1652
+ return target.changedTransform;
1653
+ const oldMatrix = new draw.Matrix(target.worldTransform);
1681
1654
  func();
1682
- return new draw.Matrix(element.worldTransform).divide(oldMatrix);
1655
+ return new draw.Matrix(target.worldTransform).divide(oldMatrix);
1656
+ }
1657
+ emitEvent(event, capture) {
1658
+ this.editBox.editor.emitEvent(event, capture);
1659
+ }
1660
+ }
1661
+
1662
+ exports.Editor = class Editor extends draw.Group {
1663
+ get list() { return this.leafList.list; }
1664
+ get dragHoverExclude() { return [this.editBox.rect]; }
1665
+ get editing() { return !!this.list.length; }
1666
+ get groupOpening() { return !!this.openedGroupList.length; }
1667
+ get multiple() { return this.list.length > 1; }
1668
+ get single() { return this.list.length === 1; }
1669
+ get dragging() { return this.editBox.dragging; }
1670
+ get moving() { return this.editBox.moving; }
1671
+ get dragPoint() { return this.editBox.dragPoint; }
1672
+ get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1673
+ get buttons() { return this.editBox.buttons; }
1674
+ constructor(userConfig, data) {
1675
+ super(data);
1676
+ this.leafList = new draw.LeafList();
1677
+ this.openedGroupList = new draw.LeafList();
1678
+ this.simulateTarget = new SimulateElement(this);
1679
+ this.editBox = new EditBox(this);
1680
+ this.editToolList = {};
1681
+ this.selector = new EditSelect(this);
1682
+ this.editMask = new EditMask(this);
1683
+ this.targetEventIds = [];
1684
+ let mergedConfig = draw.DataHelper.clone(config);
1685
+ if (userConfig)
1686
+ mergedConfig = draw.DataHelper.default(userConfig, mergedConfig);
1687
+ this.mergedConfig = this.config = mergedConfig;
1688
+ this.addMany(this.editMask, this.selector, this.editBox);
1689
+ if (!draw.Plugin.has('resize'))
1690
+ this.config.editSize = 'scale';
1691
+ }
1692
+ select(target) {
1693
+ this.target = target;
1694
+ }
1695
+ cancel() {
1696
+ this.target = null;
1697
+ }
1698
+ hasItem(item) {
1699
+ return this.leafList.has(item);
1700
+ }
1701
+ addItem(item) {
1702
+ if (!this.hasItem(item) && !item.locked)
1703
+ this.leafList.add(item), this.target = this.leafList.list;
1704
+ }
1705
+ removeItem(item) {
1706
+ if (this.hasItem(item))
1707
+ this.leafList.remove(item), this.target = this.leafList.list;
1708
+ }
1709
+ shiftItem(item) {
1710
+ this.hasItem(item) ? this.removeItem(item) : this.addItem(item);
1683
1711
  }
1712
+ update() {
1713
+ if (this.editing) {
1714
+ if (!this.element.parent)
1715
+ return this.cancel();
1716
+ if (this.innerEditing)
1717
+ this.innerEditor.update();
1718
+ this.editTool.update();
1719
+ this.selector.update();
1720
+ }
1721
+ }
1722
+ updateEditBox() {
1723
+ if (this.multiple)
1724
+ simulate(this);
1725
+ this.update();
1726
+ }
1727
+ updateEditTool() {
1728
+ let tool = this.editTool;
1729
+ if (tool) {
1730
+ this.editBox.unload();
1731
+ tool.unload();
1732
+ this.editTool = null;
1733
+ }
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
+ }
1742
+ getEditSize(_ui) {
1743
+ return this.mergeConfig.editSize;
1744
+ }
1745
+ onMove(_e) { }
1746
+ onScale(_e) { }
1747
+ onRotate(_e) { }
1748
+ onSkew(_e) { }
1749
+ move(_x, _y = 0) { }
1750
+ scaleWithDrag(_data) { }
1751
+ scaleOf(_origin, scaleX, _scaleY = scaleX, _resize) { }
1752
+ flip(_axis) { }
1753
+ rotateOf(_origin, _rotation) { }
1754
+ skewOf(_origin, _skewX, _skewY = 0, _resize) { }
1755
+ checkTransform(_type) { return undefined; }
1756
+ getWorldOrigin(_origin) { return undefined; }
1757
+ getChangedTransform(_func) { return undefined; }
1684
1758
  group(userGroup) {
1685
1759
  if (this.multiple) {
1686
1760
  this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
@@ -1798,12 +1872,9 @@ class Editor extends draw.Group {
1798
1872
  if (this.targetChanged)
1799
1873
  this.update();
1800
1874
  }
1801
- onKey(e) {
1802
- updateCursor(this, e);
1803
- }
1804
1875
  listenTargetEvents() {
1805
1876
  if (!this.targetEventIds.length) {
1806
- const { app, leafer, editBox, editMask } = this;
1877
+ const { app, leafer, editMask } = this;
1807
1878
  this.targetEventIds = [
1808
1879
  leafer.on_(draw.RenderEvent.START, this.onRenderStart, this),
1809
1880
  app.on_([
@@ -1811,8 +1882,6 @@ class Editor extends draw.Group {
1811
1882
  [core.MoveEvent.BEFORE_MOVE, this.onMove, this, true],
1812
1883
  [core.ZoomEvent.BEFORE_ZOOM, this.onScale, this, true],
1813
1884
  [core.RotateEvent.BEFORE_ROTATE, this.onRotate, this, true],
1814
- [[core.KeyEvent.HOLD, core.KeyEvent.UP], this.onKey, this],
1815
- [core.KeyEvent.DOWN, editBox.onArrow, editBox]
1816
1885
  ])
1817
1886
  ];
1818
1887
  if (editMask.visible)
@@ -1837,24 +1906,29 @@ class Editor extends draw.Group {
1837
1906
  super.destroy();
1838
1907
  }
1839
1908
  }
1840
- }
1909
+ };
1841
1910
  __decorate([
1842
1911
  mergeConfigAttr()
1843
- ], Editor.prototype, "mergeConfig", void 0);
1912
+ ], exports.Editor.prototype, "mergeConfig", void 0);
1844
1913
  __decorate([
1845
1914
  targetAttr(onHover)
1846
- ], Editor.prototype, "hoverTarget", void 0);
1915
+ ], exports.Editor.prototype, "hoverTarget", void 0);
1847
1916
  __decorate([
1848
1917
  targetAttr(onTarget)
1849
- ], Editor.prototype, "target", void 0);
1918
+ ], exports.Editor.prototype, "target", void 0);
1919
+ exports.Editor = __decorate([
1920
+ core.useModule(TransformTool, ['editBox', 'editTool', 'emitEvent'])
1921
+ ], exports.Editor);
1850
1922
 
1851
1923
  class InnerEditor {
1852
1924
  static registerInnerEditor() {
1853
1925
  EditToolCreator.register(this);
1854
1926
  }
1855
1927
  get tag() { return 'InnerEditor'; }
1928
+ get mode() { return 'focus'; }
1856
1929
  get editBox() { return this.editor.editBox; }
1857
1930
  constructor(editor) {
1931
+ this.eventIds = [];
1858
1932
  this.editor = editor;
1859
1933
  this.create();
1860
1934
  }
@@ -1867,7 +1941,7 @@ class InnerEditor {
1867
1941
  load() {
1868
1942
  const { editor } = this;
1869
1943
  if (editor) {
1870
- if (editor.app)
1944
+ if (editor.app && this.mode === 'focus')
1871
1945
  editor.selector.hittable = editor.app.tree.hitChildren = false;
1872
1946
  this.onLoad();
1873
1947
  }
@@ -1878,7 +1952,7 @@ class InnerEditor {
1878
1952
  unload() {
1879
1953
  const { editor } = this;
1880
1954
  if (editor) {
1881
- if (editor.app)
1955
+ if (editor.app && this.mode === 'focus')
1882
1956
  editor.selector.hittable = editor.app.tree.hitChildren = true;
1883
1957
  this.onUnload();
1884
1958
  }
@@ -1952,10 +2026,7 @@ exports.EditTool = class EditTool extends InnerEditor {
1952
2026
  this.onLoad();
1953
2027
  }
1954
2028
  update() {
1955
- const { editor, editBox } = this;
1956
- const { x, y, scaleX, scaleY, rotation, skewX, skewY, width, height } = editor.element.getLayoutBounds('box', editor, true);
1957
- editBox.set({ x, y, scaleX, scaleY, rotation, skewX, skewY });
1958
- editBox.update({ x: 0, y: 0, width, height });
2029
+ this.editBox.update();
1959
2030
  this.onUpdate();
1960
2031
  }
1961
2032
  unload() {
@@ -2075,7 +2146,7 @@ exports.LineEditTool = __decorate([
2075
2146
 
2076
2147
  draw.Plugin.add('editor', 'resize');
2077
2148
  draw.Creator.editor = function (options, app) {
2078
- const editor = new Editor(options);
2149
+ const editor = new exports.Editor(options);
2079
2150
  if (app)
2080
2151
  app.sky.add(app.editor = editor);
2081
2152
  return editor;
@@ -2096,7 +2167,6 @@ exports.EditPoint = EditPoint;
2096
2167
  exports.EditSelect = EditSelect;
2097
2168
  exports.EditSelectHelper = EditSelectHelper;
2098
2169
  exports.EditToolCreator = EditToolCreator;
2099
- exports.Editor = Editor;
2100
2170
  exports.EditorEvent = EditorEvent;
2101
2171
  exports.EditorGroupEvent = EditorGroupEvent;
2102
2172
  exports.EditorHelper = EditorHelper;
@@ -2108,5 +2178,6 @@ exports.InnerEditor = InnerEditor;
2108
2178
  exports.InnerEditorEvent = InnerEditorEvent;
2109
2179
  exports.SelectArea = SelectArea;
2110
2180
  exports.Stroker = Stroker;
2181
+ exports.TransformTool = TransformTool;
2111
2182
  exports.registerEditTool = registerEditTool;
2112
2183
  exports.registerInnerEditor = registerInnerEditor;