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