@leafer-in/editor 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/editor.js CHANGED
@@ -51,6 +51,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
51
51
  super(type, data);
52
52
  }
53
53
  }
54
+ EditorMoveEvent.BEFORE_MOVE = 'editor.before_move';
54
55
  EditorMoveEvent.MOVE = 'editor.move';
55
56
 
56
57
  class EditorScaleEvent extends EditorEvent {
@@ -58,6 +59,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
58
59
  super(type, data);
59
60
  }
60
61
  }
62
+ EditorScaleEvent.BEFORE_SCALE = 'editor.before_scale';
61
63
  EditorScaleEvent.SCALE = 'editor.scale';
62
64
 
63
65
  class EditorRotateEvent extends EditorEvent {
@@ -65,6 +67,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
65
67
  super(type, data);
66
68
  }
67
69
  }
70
+ EditorRotateEvent.BEFORE_ROTATE = 'editor.before_rotate';
68
71
  EditorRotateEvent.ROTATE = 'editor.rotate';
69
72
 
70
73
  class EditorSkewEvent extends EditorEvent {
@@ -72,6 +75,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
72
75
  super(type, data);
73
76
  }
74
77
  }
78
+ EditorSkewEvent.BEFORE_SKEW = 'editor.before_skew';
75
79
  EditorSkewEvent.SKEW = 'editor.skew';
76
80
 
77
81
  function targetAttr(fn) {
@@ -124,7 +128,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
124
128
  for (let i = 0; i < list.length; i++) {
125
129
  leaf = list[i];
126
130
  const { worldTransform, worldRenderBounds } = leaf;
127
- if (!bounds || bounds.hit(worldRenderBounds, options.matrix)) {
131
+ if (worldRenderBounds.width && worldRenderBounds.height && (!bounds || bounds.hit(worldRenderBounds, options.matrix))) {
128
132
  const aScaleX = abs(worldTransform.scaleX), aScaleY = abs(worldTransform.scaleY);
129
133
  if (aScaleX !== aScaleY) {
130
134
  copy$1(matrix, worldTransform);
@@ -250,9 +254,9 @@ this.LeaferIN.editor = (function (exports, draw, core) {
250
254
  }
251
255
  onSelect() {
252
256
  if (this.running) {
253
- const { mergeConfig: config, list } = this.editor;
254
- const { stroke, strokeWidth } = config;
255
- this.targetStroker.setTarget(list, { stroke, strokeWidth: Math.max(1, strokeWidth / 2) });
257
+ const { mergeConfig, list } = this.editor;
258
+ const { stroke, strokeWidth, selectedStyle } = mergeConfig;
259
+ this.targetStroker.setTarget(list, Object.assign({ stroke, strokeWidth: Math.max(1, strokeWidth / 2) }, (selectedStyle || {})));
256
260
  this.hoverStroker.target = null;
257
261
  }
258
262
  }
@@ -439,7 +443,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
439
443
  const EditDataHelper = {
440
444
  getScaleData(element, startBounds, direction, totalMove, lockRatio, around, flipable, scaleMode) {
441
445
  let align, origin = {}, scaleX = 1, scaleY = 1;
442
- const { boxBounds, widthRange, heightRange, dragBounds } = element;
446
+ const { boxBounds, widthRange, heightRange, dragBounds, worldBoxBounds } = element;
443
447
  const { width, height } = startBounds;
444
448
  if (around) {
445
449
  totalMove.x *= 2;
@@ -453,10 +457,6 @@ this.LeaferIN.editor = (function (exports, draw, core) {
453
457
  const changedScaleY = scaleMode ? originChangedScaleY : signY * boxBounds.height / height;
454
458
  totalMove.x *= scaleMode ? originChangedScaleX : signX;
455
459
  totalMove.y *= scaleMode ? originChangedScaleY : signY;
456
- if (Math.abs(totalMove.x) === width)
457
- totalMove.x += 0.1;
458
- if (Math.abs(totalMove.y) === height)
459
- totalMove.y += 0.1;
460
460
  const topScale = (-totalMove.y + height) / height;
461
461
  const rightScale = (totalMove.x + width) / width;
462
462
  const bottomScale = (totalMove.y + height) / height;
@@ -546,6 +546,10 @@ this.LeaferIN.editor = (function (exports, draw, core) {
546
546
  const nowHeight = boxBounds.height * element.scaleY;
547
547
  scaleY = within(nowHeight * scaleY, heightRange) / nowHeight;
548
548
  }
549
+ if (Math.abs(scaleX * worldBoxBounds.width) < 1)
550
+ scaleX = (scaleX < 0 ? -1 : 1) / worldBoxBounds.width;
551
+ if (Math.abs(scaleY * worldBoxBounds.height) < 1)
552
+ scaleY = (scaleY < 0 ? -1 : 1) / worldBoxBounds.height;
549
553
  return { origin, scaleX, scaleY, direction, lockRatio, around };
550
554
  },
551
555
  getRotateData(bounds, direction, current, last, around) {
@@ -674,7 +678,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
674
678
  let { rotation } = editBox;
675
679
  const { resizeCursor, rotateCursor, skewCursor, resizeable, rotateable, skewable } = editor.mergeConfig;
676
680
  const { pointType } = point, { flippedX, flippedY } = editBox;
677
- let showResize = pointType === 'resize';
681
+ let showResize = pointType.includes('resize');
678
682
  if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
679
683
  showResize = false;
680
684
  const showSkew = skewable && !showResize && point.name === 'resize-line';
@@ -701,7 +705,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
701
705
  class EditPoint extends draw.Box {
702
706
  }
703
707
 
704
- const fourDirection = ['top', 'right', 'bottom', 'left'];
708
+ const fourDirection = ['top', 'right', 'bottom', 'left'], editConfig = undefined;
705
709
  class EditBox extends draw.Group {
706
710
  get flipped() { return this.flippedX || this.flippedY; }
707
711
  get flippedX() { return this.scaleX < 0; }
@@ -716,6 +720,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
716
720
  this.resizePoints = [];
717
721
  this.rotatePoints = [];
718
722
  this.resizeLines = [];
723
+ this.dragStartData = {};
719
724
  this.__eventIds = [];
720
725
  this.editor = editor;
721
726
  this.visible = false;
@@ -757,7 +762,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
757
762
  resizeP.rotation = (i / 2) * 90;
758
763
  }
759
764
  circle.set(this.getPointStyle(mergeConfig.circle || mergeConfig.rotatePoint || pointsStyle[0]));
760
- rect.set(Object.assign({ stroke, strokeWidth }, (mergeConfig.rect || {})));
765
+ rect.set(Object.assign({ stroke, strokeWidth, editConfig }, (mergeConfig.rect || {})));
761
766
  rect.hittable = !single;
762
767
  rect.syncEventer = single && this.editor;
763
768
  if (single) {
@@ -766,14 +771,14 @@ this.LeaferIN.editor = (function (exports, draw, core) {
766
771
  }
767
772
  }
768
773
  update(bounds) {
769
- this.visible = !this.editor.element.locked;
774
+ const { mergeConfig, element, multiple } = this.editor;
775
+ const { middlePoint, resizeable, rotateable, hideOnSmall, editBox } = mergeConfig;
776
+ this.visible = !element.locked;
770
777
  if (this.view.worldOpacity) {
771
- const { mergeConfig } = this.editor;
772
778
  const { width, height } = bounds;
773
779
  const { rect, circle, buttons, resizePoints, rotatePoints, resizeLines } = this;
774
- const { middlePoint, resizeable, rotateable, hideOnSmall } = mergeConfig;
775
780
  const smallSize = typeof hideOnSmall === 'number' ? hideOnSmall : 10;
776
- const showPoints = !(hideOnSmall && width < smallSize && height < smallSize);
781
+ const showPoints = editBox && !(hideOnSmall && width < smallSize && height < smallSize);
777
782
  let point = {}, rotateP, resizeP, resizeL;
778
783
  for (let i = 0; i < 8; i++) {
779
784
  draw.AroundHelper.toPoint(draw.AroundHelper.directionData[i], bounds, point);
@@ -789,13 +794,13 @@ this.LeaferIN.editor = (function (exports, draw, core) {
789
794
  resizeP.visible = rotateP.visible = showPoints && !!middlePoint;
790
795
  if (((i + 1) / 2) % 2) {
791
796
  resizeL.width = width;
792
- if (resizeP.width > width - 30)
797
+ if (hideOnSmall && resizeP.width * 2 > width)
793
798
  resizeP.visible = false;
794
799
  }
795
800
  else {
796
801
  resizeL.height = height;
797
802
  resizeP.rotation = 90;
798
- if (resizeP.width > height - 30)
803
+ if (hideOnSmall && resizeP.width * 2 > height)
799
804
  resizeP.visible = false;
800
805
  }
801
806
  }
@@ -805,7 +810,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
805
810
  this.layoutCircle(mergeConfig);
806
811
  if (rect.path)
807
812
  rect.path = null;
808
- rect.set(Object.assign(Object.assign({}, bounds), { visible: true }));
813
+ rect.set(Object.assign(Object.assign({}, bounds), { visible: multiple ? true : editBox }));
809
814
  buttons.visible = showPoints && buttons.children.length > 0;
810
815
  if (buttons.visible)
811
816
  this.layoutButtons(mergeConfig);
@@ -852,7 +857,7 @@ this.LeaferIN.editor = (function (exports, draw, core) {
852
857
  }
853
858
  getPointStyle(userStyle) {
854
859
  const { stroke, strokeWidth, pointFill, pointSize, pointRadius } = this.editor.mergeConfig;
855
- const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0 };
860
+ const defaultStyle = { fill: pointFill, stroke, strokeWidth, around: 'center', strokeAlign: 'center', width: pointSize, height: pointSize, cornerRadius: pointRadius, offsetX: 0, offsetY: 0, editConfig };
856
861
  return userStyle ? Object.assign(defaultStyle, userStyle) : defaultStyle;
857
862
  }
858
863
  getPointsStyle() {
@@ -872,34 +877,32 @@ this.LeaferIN.editor = (function (exports, draw, core) {
872
877
  }
873
878
  onDragStart(e) {
874
879
  this.dragging = true;
875
- const { editor } = this;
876
- if (e.current.name === 'rect') {
880
+ const point = this.dragPoint = e.current;
881
+ const { editor, dragStartData } = this, { element } = editor;
882
+ if (point.name === 'rect') {
877
883
  this.moving = true;
878
- editor.dragStartPoint = { x: editor.element.x, y: editor.element.y };
879
884
  editor.opacity = editor.mergeConfig.hideOnMove ? 0 : 1;
880
885
  }
881
- else if (e.current.pointType === 'resize') {
882
- editor.dragStartBounds = Object.assign({}, editor.element.getLayoutBounds('box', 'local'));
883
- editor.resizeDirection = e.current.direction;
884
- }
886
+ dragStartData.x = e.x;
887
+ dragStartData.y = e.y;
888
+ dragStartData.point = { x: element.x, y: element.y };
889
+ dragStartData.bounds = Object.assign({}, element.getLayoutBounds('box', 'local'));
890
+ dragStartData.rotation = element.rotation;
885
891
  }
886
892
  onDragEnd(e) {
887
893
  this.dragging = false;
894
+ this.dragPoint = null;
888
895
  this.moving = false;
889
896
  if (e.current.name === 'rect')
890
897
  this.editor.opacity = 1;
891
- this.editor.resizeDirection = undefined;
892
898
  }
893
899
  onDrag(e) {
894
900
  const { editor } = this;
895
- const point = this.enterPoint = e.current;
896
- if (point.pointType === 'rotate' || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable) {
897
- if (editor.mergeConfig.rotateable)
898
- editor.onRotate(e);
899
- }
900
- else if (point.pointType === 'resize') {
901
+ const { pointType } = this.enterPoint = e.current;
902
+ if (pointType.includes('rotate') || e.metaKey || e.ctrlKey || !editor.mergeConfig.resizeable)
903
+ editor.onRotate(e);
904
+ if (pointType.includes('resize'))
901
905
  editor.onScale(e);
902
- }
903
906
  updateCursor(editor, e);
904
907
  }
905
908
  onArrow(e) {
@@ -1077,6 +1080,7 @@ ${filterStyle}
1077
1080
  rotateCursor: { url: rotateSVG, x: 12, y: 12 },
1078
1081
  skewCursor: { url: skewSVG, x: 12, y: 12 },
1079
1082
  selector: true,
1083
+ editBox: true,
1080
1084
  hover: true,
1081
1085
  select: 'press',
1082
1086
  openInner: 'double',
@@ -1092,14 +1096,25 @@ ${filterStyle}
1092
1096
  function simulate(editor) {
1093
1097
  const { simulateTarget, list } = editor;
1094
1098
  const { zoomLayer } = list[0].leafer.zoomLayer;
1095
- simulateTarget.safeChange(() => simulateTarget.reset(bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page')).get()));
1099
+ simulateTarget.safeChange(() => {
1100
+ bounds.setListWithFn(list, (leaf) => leaf.getBounds('box', 'page'));
1101
+ if (bounds.width === 0)
1102
+ bounds.width = 0.1;
1103
+ if (bounds.height === 0)
1104
+ bounds.height = 0.1;
1105
+ simulateTarget.reset(bounds.get());
1106
+ });
1096
1107
  zoomLayer.add(simulateTarget);
1097
1108
  }
1098
1109
 
1099
1110
  function onTarget(editor, oldValue) {
1100
1111
  const { target } = editor;
1101
1112
  if (target) {
1102
- editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
1113
+ const { list } = editor.leafList = target instanceof draw.LeafList ? target : new draw.LeafList(target instanceof Array ? target : target);
1114
+ if (!list.every(checkEditable)) {
1115
+ editor.target = list.filter(checkEditable);
1116
+ return;
1117
+ }
1103
1118
  if (editor.multiple)
1104
1119
  simulate(editor);
1105
1120
  }
@@ -1126,6 +1141,9 @@ ${filterStyle}
1126
1141
  function onHover(editor, oldValue) {
1127
1142
  editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
1128
1143
  }
1144
+ function checkEditable(item) {
1145
+ return item.editable && !item.locked;
1146
+ }
1129
1147
 
1130
1148
  const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
1131
1149
  const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
@@ -1223,10 +1241,13 @@ ${filterStyle}
1223
1241
  super(type, data);
1224
1242
  }
1225
1243
  }
1244
+ EditorGroupEvent.BEFORE_GROUP = 'editor.before_group';
1226
1245
  EditorGroupEvent.GROUP = 'editor.group';
1227
1246
  EditorGroupEvent.BEFORE_UNGROUP = 'editor.before_ungroup';
1228
1247
  EditorGroupEvent.UNGROUP = 'editor.ungroup';
1248
+ EditorGroupEvent.BEFORE_OPEN = 'editor.before_open_group';
1229
1249
  EditorGroupEvent.OPEN = 'editor.open_group';
1250
+ EditorGroupEvent.BEFORE_CLOSE = 'editor.before_close_group';
1230
1251
  EditorGroupEvent.CLOSE = 'editor.close_group';
1231
1252
 
1232
1253
  const { updateMatrix } = draw.LeafHelper;
@@ -1289,8 +1310,20 @@ ${filterStyle}
1289
1310
 
1290
1311
  class Editor extends draw.Group {
1291
1312
  get mergeConfig() {
1292
- const { element, config } = this;
1293
- return this.single && element.editConfig ? Object.assign(Object.assign({}, config), element.editConfig) : config;
1313
+ const { config, element, dragPoint } = this, mergeConfig = Object.assign({}, config);
1314
+ if (element && element.editConfig)
1315
+ Object.assign(mergeConfig, element.editConfig);
1316
+ if (dragPoint) {
1317
+ if (dragPoint.editConfig)
1318
+ Object.assign(mergeConfig, dragPoint.editConfig);
1319
+ if (mergeConfig.editSize === 'font-size')
1320
+ mergeConfig.lockRatio = true;
1321
+ if (dragPoint.pointType === 'resize-rotate') {
1322
+ mergeConfig.around || (mergeConfig.around = 'center');
1323
+ draw.isNull(mergeConfig.lockRatio) && (mergeConfig.lockRatio = true);
1324
+ }
1325
+ }
1326
+ return mergeConfig;
1294
1327
  }
1295
1328
  get list() { return this.leafList.list; }
1296
1329
  get dragHoverExclude() { return [this.editBox.rect]; }
@@ -1300,6 +1333,7 @@ ${filterStyle}
1300
1333
  get single() { return this.list.length === 1; }
1301
1334
  get dragging() { return this.editBox.dragging; }
1302
1335
  get moving() { return this.editBox.moving; }
1336
+ get dragPoint() { return this.editBox.dragPoint; }
1303
1337
  get element() { return this.multiple ? this.simulateTarget : this.list[0]; }
1304
1338
  get buttons() { return this.editBox.buttons; }
1305
1339
  constructor(userConfig, data) {
@@ -1390,7 +1424,7 @@ ${filterStyle}
1390
1424
  else
1391
1425
  total.x = 0;
1392
1426
  }
1393
- this.move(core.DragEvent.getValidMove(this.element, this.dragStartPoint, total));
1427
+ this.move(core.DragEvent.getValidMove(this.element, this.editBox.dragStartData.point, total));
1394
1428
  }
1395
1429
  }
1396
1430
  onScale(e) {
@@ -1404,7 +1438,7 @@ ${filterStyle}
1404
1438
  const { direction } = e.current;
1405
1439
  if (e.shiftKey || element.lockRatio)
1406
1440
  lockRatio = true;
1407
- const data = EditDataHelper.getScaleData(element, this.dragStartBounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
1441
+ const data = EditDataHelper.getScaleData(element, this.editBox.dragStartData.bounds, direction, e.getInnerTotal(element), lockRatio, EditDataHelper.getAround(around, e.altKey), flipable, this.multiple || editSize === 'scale');
1408
1442
  if (this.editTool.onScaleWithDrag) {
1409
1443
  data.drag = e;
1410
1444
  this.scaleWithDrag(data);
@@ -1419,26 +1453,29 @@ ${filterStyle}
1419
1453
  const { direction, name } = e.current;
1420
1454
  if (skewable && name === 'resize-line')
1421
1455
  return this.onSkew(e);
1422
- const { element } = this;
1456
+ const { element } = this, { dragStartData } = this.editBox;
1423
1457
  let origin, rotation;
1424
1458
  if (e instanceof core.RotateEvent) {
1425
1459
  if (rotateable === 'rotate')
1426
1460
  e.stop(), rotation = e.rotation, origin = element.getBoxPoint(e);
1427
1461
  else
1428
1462
  return;
1463
+ if (element.scaleX * element.scaleY < 0)
1464
+ rotation = -rotation;
1429
1465
  }
1430
1466
  else {
1431
- const last = { x: e.x - e.moveX, y: e.y - e.moveY };
1432
- const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(last), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
1467
+ const data = EditDataHelper.getRotateData(element.boxBounds, direction, e.getBoxPoint(element), element.getBoxPoint(dragStartData), e.shiftKey ? null : (element.around || element.origin || around || 'center'));
1433
1468
  rotation = data.rotation;
1434
1469
  origin = data.origin;
1435
1470
  }
1436
- rotation = draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation);
1437
- if (!rotation)
1438
- return;
1439
1471
  if (element.scaleX * element.scaleY < 0)
1440
1472
  rotation = -rotation;
1441
- this.rotateOf(origin, draw.MathHelper.float(rotation, 2));
1473
+ if (e instanceof core.DragEvent)
1474
+ rotation = dragStartData.rotation + rotation - element.rotation;
1475
+ rotation = draw.MathHelper.float(draw.MathHelper.getGapRotation(rotation, rotateGap, element.rotation), 2);
1476
+ if (!rotation)
1477
+ return;
1478
+ this.rotateOf(origin, rotation);
1442
1479
  }
1443
1480
  onSkew(e) {
1444
1481
  const { element } = this;
@@ -1455,7 +1492,9 @@ ${filterStyle}
1455
1492
  const world = element.getWorldPointByLocal(typeof x === 'object' ? Object.assign({}, x) : { x, y }, null, true);
1456
1493
  if (this.multiple)
1457
1494
  element.safeChange(() => element.move(x, y));
1458
- const event = new EditorMoveEvent(EditorMoveEvent.MOVE, { target: element, editor: this, moveX: world.x, moveY: world.y });
1495
+ const data = { target: element, editor: this, moveX: world.x, moveY: world.y };
1496
+ this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
1497
+ const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
1459
1498
  this.editTool.onMove(event);
1460
1499
  this.emitEvent(event);
1461
1500
  }
@@ -1463,7 +1502,9 @@ ${filterStyle}
1463
1502
  if (!this.checkTransform('resizeable'))
1464
1503
  return;
1465
1504
  const { element } = this;
1466
- const event = new EditorScaleEvent(EditorScaleEvent.SCALE, Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) }));
1505
+ data = Object.assign(Object.assign({}, data), { target: element, editor: this, worldOrigin: element.getWorldPoint(data.origin) });
1506
+ this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1507
+ const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1467
1508
  this.editTool.onScaleWithDrag(event);
1468
1509
  this.emitEvent(event);
1469
1510
  }
@@ -1473,7 +1514,9 @@ ${filterStyle}
1473
1514
  const { element } = this;
1474
1515
  const worldOrigin = this.getWorldOrigin(origin);
1475
1516
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.scaleOf(origin, scaleX, scaleY)));
1476
- const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX, scaleY, transform });
1517
+ const data = { target: element, editor: this, worldOrigin, scaleX, scaleY, transform };
1518
+ this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1519
+ const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1477
1520
  this.editTool.onScale(event);
1478
1521
  this.emitEvent(event);
1479
1522
  }
@@ -1483,7 +1526,9 @@ ${filterStyle}
1483
1526
  const { element } = this;
1484
1527
  const worldOrigin = this.getWorldOrigin('center');
1485
1528
  const transform = this.multiple ? this.getChangedTransform(() => element.safeChange(() => element.flip(axis))) : new draw.Matrix(draw.LeafHelper.getFlipTransform(element, axis));
1486
- const event = new EditorScaleEvent(EditorScaleEvent.SCALE, { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform });
1529
+ const data = { target: element, editor: this, worldOrigin, scaleX: axis === 'x' ? -1 : 1, scaleY: axis === 'y' ? -1 : 1, transform };
1530
+ this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
1531
+ const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
1487
1532
  this.editTool.onScale(event);
1488
1533
  this.emitEvent(event);
1489
1534
  }
@@ -1493,7 +1538,9 @@ ${filterStyle}
1493
1538
  const { element } = this;
1494
1539
  const worldOrigin = this.getWorldOrigin(origin);
1495
1540
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.rotateOf(origin, rotation)));
1496
- const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, { target: element, editor: this, worldOrigin, rotation, transform });
1541
+ const data = { target: element, editor: this, worldOrigin, rotation, transform };
1542
+ this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
1543
+ const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
1497
1544
  this.editTool.onRotate(event);
1498
1545
  this.emitEvent(event);
1499
1546
  }
@@ -1503,7 +1550,9 @@ ${filterStyle}
1503
1550
  const { element } = this;
1504
1551
  const worldOrigin = this.getWorldOrigin(origin);
1505
1552
  const transform = this.multiple && this.getChangedTransform(() => element.safeChange(() => element.skewOf(origin, skewX, skewY)));
1506
- const event = new EditorSkewEvent(EditorSkewEvent.SKEW, { target: element, editor: this, worldOrigin, skewX, skewY, transform });
1553
+ const data = { target: element, editor: this, worldOrigin, skewX, skewY, transform };
1554
+ this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
1555
+ const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
1507
1556
  this.editTool.onSkew(event);
1508
1557
  this.emitEvent(event);
1509
1558
  }
@@ -1521,6 +1570,7 @@ ${filterStyle}
1521
1570
  }
1522
1571
  group(userGroup) {
1523
1572
  if (this.multiple) {
1573
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_GROUP);
1524
1574
  this.target = EditorHelper.group(this.list, this.element, userGroup);
1525
1575
  this.emitGroupEvent(EditorGroupEvent.GROUP, this.target);
1526
1576
  }
@@ -1536,11 +1586,13 @@ ${filterStyle}
1536
1586
  return this.list;
1537
1587
  }
1538
1588
  openGroup(group) {
1589
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_OPEN, group);
1539
1590
  this.openedGroupList.add(group);
1540
1591
  group.hitChildren = true;
1541
1592
  this.emitGroupEvent(EditorGroupEvent.OPEN, group);
1542
1593
  }
1543
1594
  closeGroup(group) {
1595
+ this.emitGroupEvent(EditorGroupEvent.BEFORE_CLOSE, group);
1544
1596
  this.openedGroupList.remove(group);
1545
1597
  group.hitChildren = false;
1546
1598
  this.emitGroupEvent(EditorGroupEvent.CLOSE, group);
@@ -1569,7 +1621,8 @@ ${filterStyle}
1569
1621
  emitGroupEvent(type, group) {
1570
1622
  const event = new EditorGroupEvent(type, { editTarget: group });
1571
1623
  this.emitEvent(event);
1572
- group.emitEvent(event);
1624
+ if (group)
1625
+ group.emitEvent(event);
1573
1626
  }
1574
1627
  openInnerEditor(target, select) {
1575
1628
  if (target && select)
@@ -1899,34 +1952,15 @@ ${filterStyle}
1899
1952
 
1900
1953
  draw.Plugin.add('editor', 'resize');
1901
1954
  draw.Creator.editor = function (options) { return new Editor(options); };
1902
- draw.dataType(false)(draw.Box.prototype, 'textBox');
1903
- draw.defineKey(draw.UI.prototype, 'editOuter', {
1904
- get() { return this.__.__isLinePath ? 'LineEditTool' : 'EditTool'; }
1905
- });
1906
- draw.defineKey(draw.UI.prototype, 'editInner', {
1907
- get() { return 'PathEditor'; }
1908
- });
1909
- draw.defineKey(draw.Group.prototype, 'editInner', {
1910
- get() { return ''; }
1911
- });
1912
- draw.defineKey(draw.Text.prototype, 'editInner', {
1913
- get() { return 'TextEditor'; }
1914
- });
1915
- draw.UI.setEditConfig = function (config) {
1916
- draw.defineKey(this.prototype, 'editConfig', {
1917
- get() { return typeof config === 'function' ? config(this) : config; }
1918
- });
1919
- };
1920
- draw.UI.setEditOuter = function (toolName) {
1921
- draw.defineKey(this.prototype, 'editOuter', {
1922
- get() { return typeof toolName === 'string' ? toolName : toolName(this); }
1923
- });
1924
- };
1925
- draw.UI.setEditInner = function (editorName) {
1926
- draw.defineKey(this.prototype, 'editInner', {
1927
- get() { return typeof editorName === 'string' ? editorName : editorName(this); }
1928
- });
1929
- };
1955
+ draw.Box.addAttr('textBox', false, draw.dataType);
1956
+ draw.UI.addAttr('editConfig', undefined, draw.dataType);
1957
+ draw.UI.addAttr('editOuter', (ui) => ui.__.__isLinePath ? 'LineEditTool' : 'EditTool', draw.dataType);
1958
+ draw.UI.addAttr('editInner', 'PathEditor', draw.dataType);
1959
+ draw.Group.addAttr('editInner', '', draw.dataType);
1960
+ draw.Text.addAttr('editInner', 'TextEditor', draw.dataType);
1961
+ draw.UI.setEditConfig = function (config) { this.changeAttr('editConfig', config); };
1962
+ draw.UI.setEditOuter = function (toolName) { this.changeAttr('editOuter', toolName); };
1963
+ draw.UI.setEditInner = function (editorName) { this.changeAttr('editInner', editorName); };
1930
1964
 
1931
1965
  exports.EditBox = EditBox;
1932
1966
  exports.EditDataHelper = EditDataHelper;