@leafer-in/editor 1.5.1 → 1.5.3
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 +87 -31
- package/dist/editor.cjs.map +1 -1
- package/dist/editor.esm.js +87 -31
- 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 +87 -31
- 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 +20 -4
- package/src/display/EditBox.ts +1 -0
- package/src/display/EditSelect.ts +4 -2
- package/src/editor/cursor.ts +1 -1
- package/src/editor/target.ts +2 -11
- package/src/helper/EditDataHelper.ts +4 -0
- package/src/helper/EditorHelper.ts +3 -2
package/dist/editor.esm.js
CHANGED
|
@@ -88,9 +88,24 @@ function targetAttr(fn) {
|
|
|
88
88
|
set(value) {
|
|
89
89
|
const old = this[privateKey];
|
|
90
90
|
if (old !== value) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
if (this.config) {
|
|
92
|
+
const isSelect = key === 'target';
|
|
93
|
+
if (isSelect) {
|
|
94
|
+
if (value instanceof Array && value.length > 1 && value[0].locked)
|
|
95
|
+
value.splice(0, 1);
|
|
96
|
+
const { beforeSelect } = this.config;
|
|
97
|
+
if (beforeSelect) {
|
|
98
|
+
const check = beforeSelect({ target: value });
|
|
99
|
+
if (typeof check === 'object')
|
|
100
|
+
value = check;
|
|
101
|
+
else if (check === false)
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const type = isSelect ? EditorEvent.BEFORE_SELECT : EditorEvent.BEFORE_HOVER;
|
|
106
|
+
if (this.hasEvent(type))
|
|
107
|
+
this.emitEvent(new EditorEvent(type, { editor: this, value: value, oldValue: old }));
|
|
108
|
+
}
|
|
94
109
|
this[privateKey] = value, fn(this, old);
|
|
95
110
|
}
|
|
96
111
|
}
|
|
@@ -391,7 +406,8 @@ class EditSelect extends Group {
|
|
|
391
406
|
return target.leafer !== this.editor.leafer;
|
|
392
407
|
}
|
|
393
408
|
allowDrag(e) {
|
|
394
|
-
|
|
409
|
+
const { boxSelect, multipleSelect } = this.editor.mergeConfig;
|
|
410
|
+
if (this.running && (multipleSelect && boxSelect) && !e.target.draggable) {
|
|
395
411
|
return (!this.editor.editing && this.allow(e.target)) || (e.shiftKey && !findOne(e.path));
|
|
396
412
|
}
|
|
397
413
|
else {
|
|
@@ -409,7 +425,8 @@ class EditSelect extends Group {
|
|
|
409
425
|
return this.isMultipleSelect(e) ? this.findDeepOne(e) : findOne(e.path);
|
|
410
426
|
}
|
|
411
427
|
isMultipleSelect(e) {
|
|
412
|
-
|
|
428
|
+
const { multipleSelect, continuousSelect } = this.editor.mergeConfig;
|
|
429
|
+
return multipleSelect && (e.shiftKey || continuousSelect);
|
|
413
430
|
}
|
|
414
431
|
__listenEvents() {
|
|
415
432
|
const { editor } = this;
|
|
@@ -584,21 +601,25 @@ const EditDataHelper = {
|
|
|
584
601
|
let last;
|
|
585
602
|
switch (direction) {
|
|
586
603
|
case top:
|
|
604
|
+
case topLeft:
|
|
587
605
|
last = { x: 0.5, y: 0 };
|
|
588
606
|
align = 'bottom';
|
|
589
607
|
skewX = 1;
|
|
590
608
|
break;
|
|
591
609
|
case bottom:
|
|
610
|
+
case bottomRight:
|
|
592
611
|
last = { x: 0.5, y: 1 };
|
|
593
612
|
align = 'top';
|
|
594
613
|
skewX = 1;
|
|
595
614
|
break;
|
|
596
615
|
case left$1:
|
|
616
|
+
case bottomLeft:
|
|
597
617
|
last = { x: 0, y: 0.5 };
|
|
598
618
|
align = 'right';
|
|
599
619
|
skewY = 1;
|
|
600
620
|
break;
|
|
601
621
|
case right$1:
|
|
622
|
+
case topRight:
|
|
602
623
|
last = { x: 1, y: 0.5 };
|
|
603
624
|
align = 'left';
|
|
604
625
|
skewY = 1;
|
|
@@ -687,7 +708,7 @@ function updateCursor(editor, e) {
|
|
|
687
708
|
let showResize = pointType.includes('resize');
|
|
688
709
|
if (showResize && rotateable && (e.metaKey || e.ctrlKey || !resizeable))
|
|
689
710
|
showResize = false;
|
|
690
|
-
const showSkew = skewable && !showResize && point.name === 'resize-line';
|
|
711
|
+
const showSkew = skewable && !showResize && (point.name === 'resize-line' || pointType === 'skew');
|
|
691
712
|
const cursor = showSkew ? skewCursor : (showResize ? resizeCursor : rotateCursor);
|
|
692
713
|
rotation += (EditDataHelper.getFlipDirection(point.direction, flippedX, flippedY) + 1) * 45;
|
|
693
714
|
rotation = Math.round(MathHelper.formatRotation(rotation, true) / 2) * 2;
|
|
@@ -909,6 +930,8 @@ class EditBox extends Group {
|
|
|
909
930
|
editor.onRotate(e);
|
|
910
931
|
if (pointType.includes('resize'))
|
|
911
932
|
editor.onScale(e);
|
|
933
|
+
if (pointType === 'skew')
|
|
934
|
+
editor.onSkew(e);
|
|
912
935
|
updateCursor(editor, e);
|
|
913
936
|
}
|
|
914
937
|
onArrow(e) {
|
|
@@ -1090,6 +1113,7 @@ const config = {
|
|
|
1090
1113
|
hover: true,
|
|
1091
1114
|
select: 'press',
|
|
1092
1115
|
openInner: 'double',
|
|
1116
|
+
multipleSelect: true,
|
|
1093
1117
|
boxSelect: true,
|
|
1094
1118
|
moveable: true,
|
|
1095
1119
|
resizeable: true,
|
|
@@ -1116,11 +1140,7 @@ function simulate(editor) {
|
|
|
1116
1140
|
function onTarget(editor, oldValue) {
|
|
1117
1141
|
const { target } = editor;
|
|
1118
1142
|
if (target) {
|
|
1119
|
-
|
|
1120
|
-
if (!list.every(checkEditable)) {
|
|
1121
|
-
editor.target = list.filter(checkEditable);
|
|
1122
|
-
return;
|
|
1123
|
-
}
|
|
1143
|
+
editor.leafList = target instanceof LeafList ? target : new LeafList(target);
|
|
1124
1144
|
if (editor.multiple)
|
|
1125
1145
|
simulate(editor);
|
|
1126
1146
|
}
|
|
@@ -1147,9 +1167,6 @@ function onTarget(editor, oldValue) {
|
|
|
1147
1167
|
function onHover(editor, oldValue) {
|
|
1148
1168
|
editor.emitEvent(new EditorEvent(EditorEvent.HOVER, { editor, value: editor.hoverTarget, oldValue }));
|
|
1149
1169
|
}
|
|
1150
|
-
function checkEditable(item) {
|
|
1151
|
-
return item.editable && !item.locked;
|
|
1152
|
-
}
|
|
1153
1170
|
|
|
1154
1171
|
const order = (a, b) => a.parent.children.indexOf(a) - b.parent.children.indexOf(b);
|
|
1155
1172
|
const reverseOrder = (a, b) => b.parent.children.indexOf(b) - a.parent.children.indexOf(a);
|
|
@@ -1181,13 +1198,16 @@ const EditorHelper = {
|
|
|
1181
1198
|
const ungroupList = [];
|
|
1182
1199
|
app.lockLayout();
|
|
1183
1200
|
list.forEach(leaf => {
|
|
1184
|
-
if (leaf.isBranch
|
|
1201
|
+
if (leaf.isBranch) {
|
|
1185
1202
|
const { parent, children } = leaf;
|
|
1186
1203
|
while (children.length) {
|
|
1187
1204
|
ungroupList.push(children[0]);
|
|
1188
1205
|
children[0].dropTo(parent, parent.children.indexOf(leaf));
|
|
1189
1206
|
}
|
|
1190
|
-
leaf.
|
|
1207
|
+
if (leaf.isBranchLeaf)
|
|
1208
|
+
ungroupList.push(leaf);
|
|
1209
|
+
else
|
|
1210
|
+
leaf.remove();
|
|
1191
1211
|
}
|
|
1192
1212
|
else {
|
|
1193
1213
|
ungroupList.push(leaf);
|
|
@@ -1492,13 +1512,22 @@ class Editor extends Group {
|
|
|
1492
1512
|
this.skewOf(origin, skewX, skewY);
|
|
1493
1513
|
}
|
|
1494
1514
|
move(x, y = 0) {
|
|
1495
|
-
const { element } = this;
|
|
1496
1515
|
if (!this.checkTransform('moveable'))
|
|
1497
1516
|
return;
|
|
1498
|
-
|
|
1517
|
+
if (typeof x === 'object')
|
|
1518
|
+
y = x.y, x = x.x;
|
|
1519
|
+
const { element: target } = this, { beforeMove } = this.mergeConfig;
|
|
1520
|
+
if (beforeMove) {
|
|
1521
|
+
const check = beforeMove({ target, x, y });
|
|
1522
|
+
if (typeof check === 'object')
|
|
1523
|
+
x = check.x, y = check.y;
|
|
1524
|
+
else if (check === false)
|
|
1525
|
+
return;
|
|
1526
|
+
}
|
|
1527
|
+
const world = target.getWorldPointByLocal({ x, y }, null, true);
|
|
1499
1528
|
if (this.multiple)
|
|
1500
|
-
|
|
1501
|
-
const data = { target
|
|
1529
|
+
target.safeChange(() => target.move(x, y));
|
|
1530
|
+
const data = { target, editor: this, moveX: world.x, moveY: world.y };
|
|
1502
1531
|
this.emitEvent(new EditorMoveEvent(EditorMoveEvent.BEFORE_MOVE, data));
|
|
1503
1532
|
const event = new EditorMoveEvent(EditorMoveEvent.MOVE, data);
|
|
1504
1533
|
this.editTool.onMove(event);
|
|
@@ -1507,8 +1536,14 @@ class Editor extends Group {
|
|
|
1507
1536
|
scaleWithDrag(data) {
|
|
1508
1537
|
if (!this.checkTransform('resizeable'))
|
|
1509
1538
|
return;
|
|
1510
|
-
const { element } = this;
|
|
1511
|
-
|
|
1539
|
+
const { element: target } = this, { beforeScale } = this.mergeConfig;
|
|
1540
|
+
if (beforeScale) {
|
|
1541
|
+
const { origin, scaleX, scaleY, drag } = data;
|
|
1542
|
+
const check = beforeScale({ target, drag, origin, scaleX, scaleY });
|
|
1543
|
+
if (check === false)
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
1546
|
+
data = Object.assign(Object.assign({}, data), { target, editor: this, worldOrigin: target.getWorldPoint(data.origin) });
|
|
1512
1547
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1513
1548
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1514
1549
|
this.editTool.onScaleWithDrag(event);
|
|
@@ -1517,10 +1552,17 @@ class Editor extends Group {
|
|
|
1517
1552
|
scaleOf(origin, scaleX, scaleY = scaleX, _resize) {
|
|
1518
1553
|
if (!this.checkTransform('resizeable'))
|
|
1519
1554
|
return;
|
|
1520
|
-
const { element } = this;
|
|
1555
|
+
const { element: target } = this, { beforeScale } = this.mergeConfig;
|
|
1556
|
+
if (beforeScale) {
|
|
1557
|
+
const check = beforeScale({ target, origin, scaleX, scaleY });
|
|
1558
|
+
if (typeof check === 'object')
|
|
1559
|
+
scaleX = check.scaleX, scaleY = check.scaleY;
|
|
1560
|
+
else if (check === false)
|
|
1561
|
+
return;
|
|
1562
|
+
}
|
|
1521
1563
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1522
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
1523
|
-
const data = { target
|
|
1564
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.scaleOf(origin, scaleX, scaleY)));
|
|
1565
|
+
const data = { target, editor: this, worldOrigin, scaleX, scaleY, transform };
|
|
1524
1566
|
this.emitEvent(new EditorScaleEvent(EditorScaleEvent.BEFORE_SCALE, data));
|
|
1525
1567
|
const event = new EditorScaleEvent(EditorScaleEvent.SCALE, data);
|
|
1526
1568
|
this.editTool.onScale(event);
|
|
@@ -1541,10 +1583,17 @@ class Editor extends Group {
|
|
|
1541
1583
|
rotateOf(origin, rotation) {
|
|
1542
1584
|
if (!this.checkTransform('rotateable'))
|
|
1543
1585
|
return;
|
|
1544
|
-
const { element } = this;
|
|
1586
|
+
const { element: target } = this, { beforeRotate } = this.mergeConfig;
|
|
1587
|
+
if (beforeRotate) {
|
|
1588
|
+
const check = beforeRotate({ target, origin, rotation });
|
|
1589
|
+
if (typeof check === 'number')
|
|
1590
|
+
rotation = check;
|
|
1591
|
+
else if (check === false)
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1545
1594
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1546
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
1547
|
-
const data = { target
|
|
1595
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.rotateOf(origin, rotation)));
|
|
1596
|
+
const data = { target, editor: this, worldOrigin, rotation, transform };
|
|
1548
1597
|
this.emitEvent(new EditorRotateEvent(EditorRotateEvent.BEFORE_ROTATE, data));
|
|
1549
1598
|
const event = new EditorRotateEvent(EditorRotateEvent.ROTATE, data);
|
|
1550
1599
|
this.editTool.onRotate(event);
|
|
@@ -1553,10 +1602,17 @@ class Editor extends Group {
|
|
|
1553
1602
|
skewOf(origin, skewX, skewY = 0, _resize) {
|
|
1554
1603
|
if (!this.checkTransform('skewable'))
|
|
1555
1604
|
return;
|
|
1556
|
-
const { element } = this;
|
|
1605
|
+
const { element: target } = this, { beforeSkew } = this.mergeConfig;
|
|
1606
|
+
if (beforeSkew) {
|
|
1607
|
+
const check = beforeSkew({ target, origin, skewX, skewY });
|
|
1608
|
+
if (typeof check === 'object')
|
|
1609
|
+
skewX = check.skewX, skewY = check.skewY;
|
|
1610
|
+
else if (check === false)
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1557
1613
|
const worldOrigin = this.getWorldOrigin(origin);
|
|
1558
|
-
const transform = this.multiple && this.getChangedTransform(() =>
|
|
1559
|
-
const data = { target
|
|
1614
|
+
const transform = this.multiple && this.getChangedTransform(() => target.safeChange(() => target.skewOf(origin, skewX, skewY)));
|
|
1615
|
+
const data = { target, editor: this, worldOrigin, skewX, skewY, transform };
|
|
1560
1616
|
this.emitEvent(new EditorSkewEvent(EditorSkewEvent.BEFORE_SKEW, data));
|
|
1561
1617
|
const event = new EditorSkewEvent(EditorSkewEvent.SKEW, data);
|
|
1562
1618
|
this.editTool.onSkew(event);
|