@leafer-in/editor 1.5.0 → 1.5.2
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 +75 -21
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.esm.js +75 -21
- package/dist/editor.esm.js.map +1 -1
- package/dist/editor.esm.min.js +1 -1
- package/dist/editor.esm.min.js.map +1 -1
- package/dist/editor.js +75 -21
- package/dist/editor.js.map +1 -1
- package/dist/editor.min.cjs +1 -1
- package/dist/editor.min.cjs.map +1 -1
- package/dist/editor.min.js +1 -1
- package/dist/editor.min.js.map +1 -1
- package/package.json +5 -5
- package/src/Editor.ts +46 -18
- package/src/config.ts +1 -0
- package/src/decorator/data.ts +10 -2
- package/src/display/EditBox.ts +1 -0
- package/src/display/EditSelect.ts +4 -2
- package/src/editor/cursor.ts +1 -1
- package/src/event/EditorEvent.ts +3 -0
- package/src/helper/EditDataHelper.ts +4 -0
- package/src/helper/EditorHelper.ts +3 -2
- package/types/index.d.ts +2 -0
package/dist/editor.esm.js
CHANGED
|
@@ -43,7 +43,9 @@ class EditorEvent extends Event {
|
|
|
43
43
|
Object.assign(this, data);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
EditorEvent.BEFORE_SELECT = 'editor.before_select';
|
|
46
47
|
EditorEvent.SELECT = 'editor.select';
|
|
48
|
+
EditorEvent.BEFORE_HOVER = 'editor.before_hover';
|
|
47
49
|
EditorEvent.HOVER = 'editor.hover';
|
|
48
50
|
|
|
49
51
|
class EditorMoveEvent extends EditorEvent {
|
|
@@ -85,8 +87,12 @@ function targetAttr(fn) {
|
|
|
85
87
|
get() { return this[privateKey]; },
|
|
86
88
|
set(value) {
|
|
87
89
|
const old = this[privateKey];
|
|
88
|
-
if (old !== value)
|
|
90
|
+
if (old !== value) {
|
|
91
|
+
const type = key === 'target' ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
|
|
92
|
+
if (this.hasEvent(type))
|
|
93
|
+
this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
|
|
89
94
|
this[privateKey] = value, fn(this, old);
|
|
95
|
+
}
|
|
90
96
|
}
|
|
91
97
|
});
|
|
92
98
|
};
|
|
@@ -385,7 +391,8 @@ class EditSelect extends Group {
|
|
|
385
391
|
return target.leafer !== this.editor.leafer;
|
|
386
392
|
}
|
|
387
393
|
allowDrag(e) {
|
|
388
|
-
|
|
394
|
+
const { boxSelect, multipleSelect } = this.editor.mergeConfig;
|
|
395
|
+
if (this.running && (multipleSelect && boxSelect) && !e.target.draggable) {
|
|
389
396
|
return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
|
|
390
397
|
}
|
|
391
398
|
else {
|
|
@@ -403,7 +410,8 @@ class EditSelect extends Group {
|
|
|
403
410
|
return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
|
|
404
411
|
}
|
|
405
412
|
isMultipleSelect(e) {
|
|
406
|
-
|
|
413
|
+
const { multipleSelect, continuousSelect } = this.editor.mergeConfig;
|
|
414
|
+
return multipleSelect && (e.shiftKey || continuousSelect);
|
|
407
415
|
}
|
|
408
416
|
__listenEvents() {
|
|
409
417
|
const { editor } = this;
|
|
@@ -578,21 +586,25 @@ const EditDataHelper = {
|
|
|
578
586
|
let last;
|
|
579
587
|
switch (direction) {
|
|
580
588
|
case top:
|
|
589
|
+
case topLeft:
|
|
581
590
|
last = { x: 0.5, y: 0 };
|
|
582
591
|
align = 'bottom';
|
|
583
592
|
skewX = 1;
|
|
584
593
|
break;
|
|
585
594
|
case bottom:
|
|
595
|
+
case bottomRight:
|
|
586
596
|
last = { x: 0.5, y: 1 };
|
|
587
597
|
align = 'top';
|
|
588
598
|
skewX = 1;
|
|
589
599
|
break;
|
|
590
600
|
case left$1:
|
|
601
|
+
case bottomLeft:
|
|
591
602
|
last = { x: 0, y: 0.5 };
|
|
592
603
|
align = 'right';
|
|
593
604
|
skewY = 1;
|
|
594
605
|
break;
|
|
595
606
|
case right$1:
|
|
607
|
+
case topRight:
|
|
596
608
|
last = { x: 1, y: 0.5 };
|
|
597
609
|
align = 'left';
|
|
598
610
|
skewY = 1;
|
|
@@ -681,7 +693,7 @@ function updateCursor(editor, e) {
|
|
|
681
693
|
let showResize = pointType.includes('resize');
|
|
682
694
|
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
|
|
683
695
|
showResize = false;
|
|
684
|
-
const showSkew = skewable && !showResize && point.name === 'resize-line';
|
|
696
|
+
const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew');
|
|
685
697
|
const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
|
|
686
698
|
rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
|
|
687
699
|
rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2;
|
|
@@ -903,6 +915,8 @@ class EditBox extends Group {
|
|
|
903
915
|
editor.onRotate(e);
|
|
904
916
|
if (pointType.includes('resize'))
|
|
905
917
|
editor.onScale(e);
|
|
918
|
+
if (pointType === 'skew')
|
|
919
|
+
editor.onSkew(e);
|
|
906
920
|
updateCursor(editor, e);
|
|
907
921
|
}
|
|
908
922
|
onArrow(e) {
|
|
@@ -1084,6 +1098,7 @@ const config = {
|
|
|
1084
1098
|
hover: true,
|
|
1085
1099
|
select: 'press',
|
|
1086
1100
|
openInner: 'double',
|
|
1101
|
+
multipleSelect: true,
|
|
1087
1102
|
boxSelect: true,
|
|
1088
1103
|
moveable: true,
|
|
1089
1104
|
resizeable: true,
|
|
@@ -1175,13 +1190,16 @@ const EditorHelper = {
|
|
|
1175
1190
|
const ungroupList = [];
|
|
1176
1191
|
app.lockLayout();
|
|
1177
1192
|
list.forEach(leaf => {
|
|
1178
|
-
if (leaf.isBranch
|
|
1193
|
+
if (leaf.isBranch) {
|
|
1179
1194
|
const { parent, children } = leaf;
|
|
1180
1195
|
while (children.length) {
|
|
1181
1196
|
ungroupList.push(children[0]);
|
|
1182
1197
|
children[0].dropTo(parent, parent.children.indexOf(leaf));
|
|
1183
1198
|
}
|
|
1184
|
-
leaf.
|
|
1199
|
+
if (leaf.isBranchLeaf)
|
|
1200
|
+
ungroupList.push(leaf);
|
|
1201
|
+
else
|
|
1202
|
+
leaf.remove();
|
|
1185
1203
|
}
|
|
1186
1204
|
else {
|
|
1187
1205
|
ungroupList.push(leaf);
|
|
@@ -1486,13 +1504,22 @@ class Editor extends Group {
|
|
|
1486
1504
|
this.skewOf(origin, skewX, skewY);
|
|
1487
1505
|
}
|
|
1488
1506
|
move(x, y = 0) {
|
|
1489
|
-
const { element } = this;
|
|
1490
1507
|
if (!this.checkTransform('moveable'))
|
|
1491
1508
|
return;
|
|
1492
|
-
|
|
1509
|
+
if (typeof x === 'object')
|
|
1510
|
+
y = x.y, x = x.x;
|
|
1511
|
+
const { element: target } = this, { beforeMove } = this.mergeConfig;
|
|
1512
|
+
if (beforeMove) {
|
|
1513
|
+
const check = beforeMove({ target, x, y });
|
|
1514
|
+
if (typeof check === 'object')
|
|
1515
|
+
x = check.x, y = check.y;
|
|
1516
|
+
else if (check === false)
|
|
1517
|
+
return;
|
|
1518
|
+
}
|
|
1519
|
+
const world = target.getWorldPointByLocal({ x, y }, null, true);
|
|
1493
1520
|
if (this.multiple)
|
|
1494
|
-
|
|
1495
|
-
const data = { target
|
|
1521
|
+
target.safeChange(() => target.move(x, y));
|
|
1522
|
+
const data = { target, editor: this, moveX: world.x, moveY: world.y };
|
|
1496
1523
|
this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
|
|
1497
1524
|
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
|
|
1498
1525
|
this.editTool.onMove(event);
|
|
@@ -1501,8 +1528,14 @@ class Editor extends Group {
|
|
|
1501
1528
|
scaleWithDrag(data) {
|
|
1502
1529
|
if (!this.checkTransform('resizeable'))
|
|
1503
1530
|
return;
|
|
1504
|
-
const { element } = this;
|
|
1505
|
-
|
|
1531
|
+
const { element: target } = this, { beforeScale } = this.mergeConfig;
|
|
1532
|
+
if (beforeScale) {
|
|
1533
|
+
const { origin, scaleX, scaleY, drag } = data;
|
|
1534
|
+
const check = beforeScale({ target, drag, origin, scaleX, scaleY });
|
|
1535
|
+
if (check === false)
|
|
1536
|
+
return;
|
|
1537
|
+
}
|
|
1538
|
+
data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
|
|
1506
1539
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1507
1540
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1508
1541
|
this.editTool.onScaleWithDrag(event);
|
|
@@ -1511,10 +1544,17 @@ class Editor extends Group {
|
|
|
1511
1544
|
scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
|
|
1512
1545
|
if (!this.checkTransform('resizeable'))
|
|
1513
1546
|
return;
|
|
1514
|
-
const { element } = this;
|
|
1547
|
+
const { element: target } = this, { beforeScale } = this.mergeConfig;
|
|
1548
|
+
if (beforeScale) {
|
|
1549
|
+
const check = beforeScale({ target, origin, scaleX, scaleY });
|
|
1550
|
+
if (typeof check === 'object')
|
|
1551
|
+
scaleX = check.scaleX, scaleY = check.scaleY;
|
|
1552
|
+
else if (check === false)
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1515
1555
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1516
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
1517
|
-
const data = { target
|
|
1556
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
|
|
1557
|
+
const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
|
|
1518
1558
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1519
1559
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1520
1560
|
this.editTool.onScale(event);
|
|
@@ -1535,10 +1575,17 @@ class Editor extends Group {
|
|
|
1535
1575
|
rotateOf(origin, rotation) {
|
|
1536
1576
|
if (!this.checkTransform('rotateable'))
|
|
1537
1577
|
return;
|
|
1538
|
-
const { element } = this;
|
|
1578
|
+
const { element: target } = this, { beforeRotate } = this.mergeConfig;
|
|
1579
|
+
if (beforeRotate) {
|
|
1580
|
+
const check = beforeRotate({ target, origin, rotation });
|
|
1581
|
+
if (typeof check === 'number')
|
|
1582
|
+
rotation = check;
|
|
1583
|
+
else if (check === false)
|
|
1584
|
+
return;
|
|
1585
|
+
}
|
|
1539
1586
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1540
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
1541
|
-
const data = { target
|
|
1587
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
|
|
1588
|
+
const data = { target, editor: this, worldOrigin, rotation, transform };
|
|
1542
1589
|
this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
|
|
1543
1590
|
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
|
|
1544
1591
|
this.editTool.onRotate(event);
|
|
@@ -1547,10 +1594,17 @@ class Editor extends Group {
|
|
|
1547
1594
|
skewOf(origin, skewX, skewY = 0, _resize) {
|
|
1548
1595
|
if (!this.checkTransform('skewable'))
|
|
1549
1596
|
return;
|
|
1550
|
-
const { element } = this;
|
|
1597
|
+
const { element: target } = this, { beforeSkew } = this.mergeConfig;
|
|
1598
|
+
if (beforeSkew) {
|
|
1599
|
+
const check = beforeSkew({ target, origin, skewX, skewY });
|
|
1600
|
+
if (typeof check === 'object')
|
|
1601
|
+
skewX = check.skewX, skewY = check.skewY;
|
|
1602
|
+
else if (check === false)
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1551
1605
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1552
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
1553
|
-
const data = { target
|
|
1606
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
|
|
1607
|
+
const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
|
|
1554
1608
|
this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
|
|
1555
1609
|
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
|
|
1556
1610
|
this.editTool.onSkew(event);
|