@tmagic/stage 1.3.0-alpha.2 → 1.3.0-alpha.21
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/tmagic-stage.js +91 -78
- package/dist/tmagic-stage.js.map +1 -1
- package/dist/tmagic-stage.umd.cjs +91 -78
- package/dist/tmagic-stage.umd.cjs.map +1 -1
- package/package.json +8 -8
- package/src/ActionManager.ts +18 -4
- package/src/MoveableActionsAble.ts +36 -54
- package/src/MoveableOptionsManager.ts +11 -5
- package/src/StageCore.ts +12 -3
- package/src/StageDragResize.ts +2 -2
- package/src/StageHighlight.ts +18 -11
- package/src/StageMultiDragResize.ts +2 -2
- package/src/moveable-able.css +108 -0
- package/src/types.ts +5 -3
- package/types/ActionManager.d.ts +3 -1
- package/types/MoveableActionsAble.d.ts +2 -4
- package/types/MoveableOptionsManager.d.ts +2 -0
- package/types/StageCore.d.ts +5 -2
- package/types/StageHighlight.d.ts +1 -1
- package/types/types.d.ts +5 -3
package/dist/tmagic-stage.js
CHANGED
|
@@ -559,6 +559,8 @@ class DragResizeHelper {
|
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
561
|
|
|
562
|
+
const ableCss = ".moveable-button {\n width: 20px;\n height: 20px;\n background: #4af;\n border-radius: 4px;\n appearance: none;\n border: 0;\n color: white;\n font-size: 12px;\n font-weight: bold;\n margin-left: 2px;\n position: relative;\n}\n.moveable-remove-button:before, .moveable-remove-button:after {\n content: \"\";\n position: absolute;\n left: 50%;\n top: 50%;\n transform: translate(-50%, -50%) rotate(45deg);\n width: 14px;\n height: 2px;\n background: #fff;\n border-radius: 1px;\n cursor: pointer;\n}\n.moveable-remove-button:after {\n transform: translate(-50%, -50%) rotate(-45deg);\n}\n\n.moveable-select-parent-arrow-top-icon {\n transform: rotateZ(-45deg);\n width: 4px;\n height: 4px;\n border-color: #fff;\n border-width: 2px 2px 0 0;\n border-style: solid;\n position: absolute;\n left: 4px;\n top: 4px;\n}\n\n.moveable-select-parent-arrow-body-icon {\n width: 7px;\n height: 11px;\n border-color: #fff;\n border-width: 0 0 2px 2px;\n border-style: solid;\n}\n\n.moveable-drag-area-button {\n cursor: move;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon {\n width: 2px;\n height: 2px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-top {\n transform: rotateZ(-45deg) translateX(-50%);\n left: 50%;\n top: 3px;\n transform-origin: left;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-bottom {\n transform: rotateZ(135deg) translateX(-50%);\n transform-origin: left;\n left: 50%;\n top: auto;\n bottom: 3px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-right {\n transform: rotateZ(45deg) translateY(-50%);\n transform-origin: top;\n right: 3px;\n left: auto;\n top: 50%;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-left {\n transform: rotateZ(235deg) translateY(-50%);\n transform-origin: top;\n left: 3px;\n top: 50%;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-body-icon-horizontal {\n width: 2px;\n height: 11px;\n background-color: #fff;\n position: absolute;\n transform: translateX(-50%);\n left: 50%;\n top: 4px;\n}\n\n.moveable-drag-area-button .moveable-select-parent-arrow-body-icon-vertical {\n width: 11px;\n height: 2px;\n background-color: #fff;\n position: absolute;\n transform: translateY(-50%);\n left: 4px;\n top: 50%;;\n}\n\n";
|
|
563
|
+
|
|
562
564
|
var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
|
|
563
565
|
ContainerHighlightType2["DEFAULT"] = "default";
|
|
564
566
|
ContainerHighlightType2["ALT"] = "alt";
|
|
@@ -583,10 +585,8 @@ var AbleActionEventType = /* @__PURE__ */ ((AbleActionEventType2) => {
|
|
|
583
585
|
|
|
584
586
|
const MoveableActionsAble = (handler) => ({
|
|
585
587
|
name: "actions",
|
|
586
|
-
props:
|
|
587
|
-
|
|
588
|
-
},
|
|
589
|
-
events: {},
|
|
588
|
+
props: [],
|
|
589
|
+
events: [],
|
|
590
590
|
render(moveable, React) {
|
|
591
591
|
const rect = moveable.getRect();
|
|
592
592
|
const { pos2 } = moveable.state;
|
|
@@ -601,34 +601,7 @@ const MoveableActionsAble = (handler) => ({
|
|
|
601
601
|
transform-origin: 0px 0px;
|
|
602
602
|
display: flex;
|
|
603
603
|
}
|
|
604
|
-
|
|
605
|
-
width: 20px;
|
|
606
|
-
height: 20px;
|
|
607
|
-
background: #4af;
|
|
608
|
-
border-radius: 4px;
|
|
609
|
-
appearance: none;
|
|
610
|
-
border: 0;
|
|
611
|
-
color: white;
|
|
612
|
-
font-size: 12px;
|
|
613
|
-
font-weight: bold;
|
|
614
|
-
margin-left: 2px;
|
|
615
|
-
position: relative;
|
|
616
|
-
}
|
|
617
|
-
.moveable-remove-button:before, .moveable-remove-button:after {
|
|
618
|
-
content: "";
|
|
619
|
-
position: absolute;
|
|
620
|
-
left: 50%;
|
|
621
|
-
top: 50%;
|
|
622
|
-
transform: translate(-50%, -50%) rotate(45deg);
|
|
623
|
-
width: 14px;
|
|
624
|
-
height: 2px;
|
|
625
|
-
background: #fff;
|
|
626
|
-
border-radius: 1px;
|
|
627
|
-
cursor: pointer;
|
|
628
|
-
}
|
|
629
|
-
.moveable-remove-button:after {
|
|
630
|
-
transform: translate(-50%, -50%) rotate(-45deg);
|
|
631
|
-
}
|
|
604
|
+
${ableCss}
|
|
632
605
|
`
|
|
633
606
|
);
|
|
634
607
|
return React.createElement(
|
|
@@ -636,7 +609,7 @@ const MoveableActionsAble = (handler) => ({
|
|
|
636
609
|
{
|
|
637
610
|
className: "moveable-editable",
|
|
638
611
|
style: {
|
|
639
|
-
transform: `translate(${pos2[0] -
|
|
612
|
+
transform: `translate(${pos2[0] - 60}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg)`
|
|
640
613
|
}
|
|
641
614
|
},
|
|
642
615
|
[
|
|
@@ -649,27 +622,12 @@ const MoveableActionsAble = (handler) => ({
|
|
|
649
622
|
handler(AbleActionEventType.SELECT_PARENT);
|
|
650
623
|
}
|
|
651
624
|
},
|
|
652
|
-
React.createElement(
|
|
653
|
-
"
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
fill: "none",
|
|
659
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
660
|
-
style: {
|
|
661
|
-
transform: "rotate(90deg)",
|
|
662
|
-
position: "absolute",
|
|
663
|
-
left: 0,
|
|
664
|
-
top: 0
|
|
665
|
-
}
|
|
666
|
-
},
|
|
667
|
-
React.createElement("path", {
|
|
668
|
-
d: "M13.0001 4V10H4.20718L5.85363 8.35355L5.14652 7.64645L2.64652 10.1464C2.45126 10.3417 2.45126 10.6583 2.64652 10.8536L5.14652 13.3536L5.85363 12.6464L4.20718 11H13.0001C13.5524 11 14.0001 10.5523 14.0001 10V4H13.0001Z",
|
|
669
|
-
fill: "currentColor",
|
|
670
|
-
fillOpacity: "0.9"
|
|
671
|
-
})
|
|
672
|
-
)
|
|
625
|
+
React.createElement("div", {
|
|
626
|
+
className: "moveable-select-parent-arrow-top-icon"
|
|
627
|
+
}),
|
|
628
|
+
React.createElement("div", {
|
|
629
|
+
className: "moveable-select-parent-arrow-body-icon"
|
|
630
|
+
})
|
|
673
631
|
),
|
|
674
632
|
React.createElement("button", {
|
|
675
633
|
className: "moveable-button moveable-remove-button",
|
|
@@ -677,7 +635,32 @@ const MoveableActionsAble = (handler) => ({
|
|
|
677
635
|
onClick: () => {
|
|
678
636
|
handler(AbleActionEventType.REMOVE);
|
|
679
637
|
}
|
|
680
|
-
})
|
|
638
|
+
}),
|
|
639
|
+
React.createElement(
|
|
640
|
+
"button",
|
|
641
|
+
{
|
|
642
|
+
className: "moveable-button moveable-drag-area-button",
|
|
643
|
+
title: "拖动"
|
|
644
|
+
},
|
|
645
|
+
React.createElement("div", {
|
|
646
|
+
className: "moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-top"
|
|
647
|
+
}),
|
|
648
|
+
React.createElement("div", {
|
|
649
|
+
className: "moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-bottom"
|
|
650
|
+
}),
|
|
651
|
+
React.createElement("div", {
|
|
652
|
+
className: "moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-left"
|
|
653
|
+
}),
|
|
654
|
+
React.createElement("div", {
|
|
655
|
+
className: " moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-right"
|
|
656
|
+
}),
|
|
657
|
+
React.createElement("div", {
|
|
658
|
+
className: "moveable-select-parent-arrow-body-icon-horizontal"
|
|
659
|
+
}),
|
|
660
|
+
React.createElement("div", {
|
|
661
|
+
className: "moveable-select-parent-arrow-body-icon-vertical"
|
|
662
|
+
})
|
|
663
|
+
)
|
|
681
664
|
]
|
|
682
665
|
);
|
|
683
666
|
}
|
|
@@ -688,6 +671,7 @@ class MoveableOptionsManager extends EventEmitter {
|
|
|
688
671
|
mode = Mode.ABSOLUTE;
|
|
689
672
|
/** 画布容器 */
|
|
690
673
|
container;
|
|
674
|
+
options = {};
|
|
691
675
|
/** 水平参考线 */
|
|
692
676
|
horizontalGuidelines = [];
|
|
693
677
|
/** 垂直参考线 */
|
|
@@ -704,6 +688,9 @@ class MoveableOptionsManager extends EventEmitter {
|
|
|
704
688
|
this.container = config.container;
|
|
705
689
|
this.getRootContainer = config.getRootContainer;
|
|
706
690
|
}
|
|
691
|
+
getOption(key) {
|
|
692
|
+
return this.options[key];
|
|
693
|
+
}
|
|
707
694
|
/**
|
|
708
695
|
* 设置水平/垂直参考线
|
|
709
696
|
* @param type 参考线类型
|
|
@@ -748,7 +735,8 @@ class MoveableOptionsManager extends EventEmitter {
|
|
|
748
735
|
getOptions(isMultiSelect, runtimeOptions = {}) {
|
|
749
736
|
const defaultOptions = this.getDefaultOptions(isMultiSelect);
|
|
750
737
|
const customizedOptions = this.getCustomizeOptions();
|
|
751
|
-
|
|
738
|
+
this.options = merge(defaultOptions, customizedOptions, runtimeOptions);
|
|
739
|
+
return this.options;
|
|
752
740
|
}
|
|
753
741
|
/**
|
|
754
742
|
* 获取单选和多选的moveable公共参数
|
|
@@ -768,9 +756,8 @@ class MoveableOptionsManager extends EventEmitter {
|
|
|
768
756
|
elementGuidelines: this.elementGuidelines,
|
|
769
757
|
bounds: {
|
|
770
758
|
top: 0,
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
right: this.container.clientWidth - 1,
|
|
759
|
+
left: 0,
|
|
760
|
+
right: this.container.clientWidth,
|
|
774
761
|
bottom: isSortable ? void 0 : this.container.clientHeight
|
|
775
762
|
}
|
|
776
763
|
};
|
|
@@ -808,6 +795,8 @@ class MoveableOptionsManager extends EventEmitter {
|
|
|
808
795
|
left: isAbsolute
|
|
809
796
|
},
|
|
810
797
|
isDisplayInnerSnapDigit: true,
|
|
798
|
+
dragTarget: ".moveable-drag-area-button",
|
|
799
|
+
dragTargetSelf: true,
|
|
811
800
|
props: {
|
|
812
801
|
actions: true
|
|
813
802
|
},
|
|
@@ -934,14 +923,14 @@ class StageDragResize extends MoveableOptionsManager {
|
|
|
934
923
|
Object.entries(options).forEach(([key, value]) => {
|
|
935
924
|
this.moveable[key] = value;
|
|
936
925
|
});
|
|
937
|
-
this.moveable.
|
|
926
|
+
this.moveable.updateRect();
|
|
938
927
|
}
|
|
939
928
|
clearSelectStatus() {
|
|
940
929
|
if (!this.moveable)
|
|
941
930
|
return;
|
|
942
931
|
this.dragResizeHelper.destroyShadowEl();
|
|
943
932
|
this.moveable.target = null;
|
|
944
|
-
this.moveable.
|
|
933
|
+
this.moveable.updateRect();
|
|
945
934
|
}
|
|
946
935
|
/**
|
|
947
936
|
* 销毁实例
|
|
@@ -1153,13 +1142,18 @@ class StageHighlight extends EventEmitter$1 {
|
|
|
1153
1142
|
if (!el || el === this.target)
|
|
1154
1143
|
return;
|
|
1155
1144
|
this.target = el;
|
|
1156
|
-
this.
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1145
|
+
this.targetShadow?.update(el);
|
|
1146
|
+
if (this.moveable) {
|
|
1147
|
+
this.moveable.zoom = 2;
|
|
1148
|
+
this.moveable.updateRect();
|
|
1149
|
+
} else {
|
|
1150
|
+
this.moveable = new Moveable(this.container, {
|
|
1151
|
+
target: this.targetShadow?.el,
|
|
1152
|
+
origin: false,
|
|
1153
|
+
rootContainer: this.getRootContainer(),
|
|
1154
|
+
zoom: 2
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1163
1157
|
}
|
|
1164
1158
|
/**
|
|
1165
1159
|
* 清空高亮
|
|
@@ -1167,16 +1161,18 @@ class StageHighlight extends EventEmitter$1 {
|
|
|
1167
1161
|
clearHighlight() {
|
|
1168
1162
|
if (!this.moveable || !this.target)
|
|
1169
1163
|
return;
|
|
1164
|
+
this.moveable.zoom = 0;
|
|
1165
|
+
this.moveable.updateRect();
|
|
1170
1166
|
this.target = void 0;
|
|
1171
|
-
this.moveable.target = null;
|
|
1172
|
-
this.moveable.updateTarget();
|
|
1173
1167
|
}
|
|
1174
1168
|
/**
|
|
1175
1169
|
* 销毁实例
|
|
1176
1170
|
*/
|
|
1177
1171
|
destroy() {
|
|
1178
1172
|
this.moveable?.destroy();
|
|
1179
|
-
this.targetShadow
|
|
1173
|
+
this.targetShadow?.destroy();
|
|
1174
|
+
this.moveable = void 0;
|
|
1175
|
+
this.targetShadow = void 0;
|
|
1180
1176
|
}
|
|
1181
1177
|
}
|
|
1182
1178
|
|
|
@@ -1195,7 +1191,7 @@ class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
1195
1191
|
constructor(config) {
|
|
1196
1192
|
const moveableOptionsManagerConfig = {
|
|
1197
1193
|
container: config.container,
|
|
1198
|
-
moveableOptions: config.
|
|
1194
|
+
moveableOptions: config.moveableOptions,
|
|
1199
1195
|
getRootContainer: config.getRootContainer
|
|
1200
1196
|
};
|
|
1201
1197
|
super(moveableOptionsManagerConfig);
|
|
@@ -1292,7 +1288,7 @@ class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
1292
1288
|
Object.entries(options).forEach(([key, value]) => {
|
|
1293
1289
|
this.moveableForMulti[key] = value;
|
|
1294
1290
|
});
|
|
1295
|
-
this.moveableForMulti.
|
|
1291
|
+
this.moveableForMulti.updateRect();
|
|
1296
1292
|
}
|
|
1297
1293
|
/**
|
|
1298
1294
|
* 清除多选状态
|
|
@@ -1387,7 +1383,7 @@ class ActionManager extends EventEmitter {
|
|
|
1387
1383
|
this.dr = new StageDragResize({
|
|
1388
1384
|
container: config.container,
|
|
1389
1385
|
disabledDragStart: config.disabledDragStart,
|
|
1390
|
-
moveableOptions: this.changeCallback(config.moveableOptions),
|
|
1386
|
+
moveableOptions: this.changeCallback(config.moveableOptions, false),
|
|
1391
1387
|
dragResizeHelper: createDrHelper(),
|
|
1392
1388
|
getRootContainer: config.getRootContainer,
|
|
1393
1389
|
getRenderDocument: config.getRenderDocument,
|
|
@@ -1396,7 +1392,7 @@ class ActionManager extends EventEmitter {
|
|
|
1396
1392
|
});
|
|
1397
1393
|
this.multiDr = new StageMultiDragResize({
|
|
1398
1394
|
container: config.container,
|
|
1399
|
-
|
|
1395
|
+
moveableOptions: this.changeCallback(config.moveableOptions, true),
|
|
1400
1396
|
dragResizeHelper: createDrHelper(),
|
|
1401
1397
|
getRootContainer: config.getRootContainer,
|
|
1402
1398
|
getRenderDocument: config.getRenderDocument,
|
|
@@ -1451,6 +1447,14 @@ class ActionManager extends EventEmitter {
|
|
|
1451
1447
|
getSelectedElList() {
|
|
1452
1448
|
return this.selectedElList;
|
|
1453
1449
|
}
|
|
1450
|
+
getMoveableOption(key) {
|
|
1451
|
+
if (this.dr.getTarget()) {
|
|
1452
|
+
return this.dr.getOption(key);
|
|
1453
|
+
}
|
|
1454
|
+
if (this.multiDr.targetList.length) {
|
|
1455
|
+
return this.multiDr.getOption(key);
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1454
1458
|
/**
|
|
1455
1459
|
* 获取鼠标下方第一个可选中元素,如果元素层叠,返回到是最上层元素
|
|
1456
1460
|
* @param event 鼠标事件
|
|
@@ -1589,12 +1593,16 @@ class ActionManager extends EventEmitter {
|
|
|
1589
1593
|
this.multiDr.destroy();
|
|
1590
1594
|
this.highlightLayer.destroy();
|
|
1591
1595
|
}
|
|
1592
|
-
changeCallback(options) {
|
|
1596
|
+
changeCallback(options, isMulti) {
|
|
1593
1597
|
if (typeof options === "function") {
|
|
1594
1598
|
return () => {
|
|
1595
1599
|
if (typeof options === "function") {
|
|
1596
1600
|
const cfg = {
|
|
1597
|
-
|
|
1601
|
+
targetEl: this.selectedEl,
|
|
1602
|
+
targetElId: this.selectedEl?.id,
|
|
1603
|
+
targetEls: this.selectedElList,
|
|
1604
|
+
targetElIds: this.selectedElList?.map((item) => item.id),
|
|
1605
|
+
isMulti
|
|
1598
1606
|
};
|
|
1599
1607
|
return options(cfg);
|
|
1600
1608
|
}
|
|
@@ -2370,6 +2378,9 @@ class StageCore extends EventEmitter$1 {
|
|
|
2370
2378
|
highlight(idOrEl) {
|
|
2371
2379
|
this.actionManager.highlight(idOrEl);
|
|
2372
2380
|
}
|
|
2381
|
+
clearHighlight() {
|
|
2382
|
+
this.actionManager.clearHighlight();
|
|
2383
|
+
}
|
|
2373
2384
|
/**
|
|
2374
2385
|
* 更新组件
|
|
2375
2386
|
* @param data 更新组件的数据
|
|
@@ -2437,6 +2448,9 @@ class StageCore extends EventEmitter$1 {
|
|
|
2437
2448
|
delayedMarkContainer(event, excludeElList = []) {
|
|
2438
2449
|
return this.actionManager.delayedMarkContainer(event, excludeElList);
|
|
2439
2450
|
}
|
|
2451
|
+
getMoveableOption(key) {
|
|
2452
|
+
return this.actionManager.getMoveableOption(key);
|
|
2453
|
+
}
|
|
2440
2454
|
/**
|
|
2441
2455
|
* 销毁实例
|
|
2442
2456
|
*/
|
|
@@ -2467,7 +2481,6 @@ class StageCore extends EventEmitter$1 {
|
|
|
2467
2481
|
containerHighlightDuration: config.containerHighlightDuration,
|
|
2468
2482
|
containerHighlightType: config.containerHighlightType,
|
|
2469
2483
|
moveableOptions: config.moveableOptions,
|
|
2470
|
-
multiMoveableOptions: config.multiMoveableOptions,
|
|
2471
2484
|
container: this.mask.content,
|
|
2472
2485
|
disabledDragStart: config.disabledDragStart,
|
|
2473
2486
|
canSelect: config.canSelect,
|