@tmagic/stage 1.3.0-alpha.9 → 1.3.0-beta.1

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.
@@ -556,6 +556,8 @@
556
556
  }
557
557
  }
558
558
 
559
+ 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";
560
+
559
561
  var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
560
562
  ContainerHighlightType2["DEFAULT"] = "default";
561
563
  ContainerHighlightType2["ALT"] = "alt";
@@ -580,10 +582,8 @@
580
582
 
581
583
  const MoveableActionsAble = (handler) => ({
582
584
  name: "actions",
583
- props: {
584
- selectParent: Boolean
585
- },
586
- events: {},
585
+ props: [],
586
+ events: [],
587
587
  render(moveable, React) {
588
588
  const rect = moveable.getRect();
589
589
  const { pos2 } = moveable.state;
@@ -598,34 +598,7 @@
598
598
  transform-origin: 0px 0px;
599
599
  display: flex;
600
600
  }
601
- .moveable-button {
602
- width: 20px;
603
- height: 20px;
604
- background: #4af;
605
- border-radius: 4px;
606
- appearance: none;
607
- border: 0;
608
- color: white;
609
- font-size: 12px;
610
- font-weight: bold;
611
- margin-left: 2px;
612
- position: relative;
613
- }
614
- .moveable-remove-button:before, .moveable-remove-button:after {
615
- content: "";
616
- position: absolute;
617
- left: 50%;
618
- top: 50%;
619
- transform: translate(-50%, -50%) rotate(45deg);
620
- width: 14px;
621
- height: 2px;
622
- background: #fff;
623
- border-radius: 1px;
624
- cursor: pointer;
625
- }
626
- .moveable-remove-button:after {
627
- transform: translate(-50%, -50%) rotate(-45deg);
628
- }
601
+ ${ableCss}
629
602
  `
630
603
  );
631
604
  return React.createElement(
@@ -633,7 +606,7 @@
633
606
  {
634
607
  className: "moveable-editable",
635
608
  style: {
636
- transform: `translate(${pos2[0] - 48}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg) translate(10px)`
609
+ transform: `translate(${pos2[0] - 60}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg)`
637
610
  }
638
611
  },
639
612
  [
@@ -646,27 +619,12 @@
646
619
  handler(AbleActionEventType.SELECT_PARENT);
647
620
  }
648
621
  },
649
- React.createElement(
650
- "svg",
651
- {
652
- width: "20px",
653
- height: "20px",
654
- viewBox: "0 0 16 16",
655
- fill: "none",
656
- xmlns: "http://www.w3.org/2000/svg",
657
- style: {
658
- transform: "rotate(90deg)",
659
- position: "absolute",
660
- left: 0,
661
- top: 0
662
- }
663
- },
664
- React.createElement("path", {
665
- 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",
666
- fill: "currentColor",
667
- fillOpacity: "0.9"
668
- })
669
- )
622
+ React.createElement("div", {
623
+ className: "moveable-select-parent-arrow-top-icon"
624
+ }),
625
+ React.createElement("div", {
626
+ className: "moveable-select-parent-arrow-body-icon"
627
+ })
670
628
  ),
671
629
  React.createElement("button", {
672
630
  className: "moveable-button moveable-remove-button",
@@ -674,7 +632,32 @@
674
632
  onClick: () => {
675
633
  handler(AbleActionEventType.REMOVE);
676
634
  }
677
- })
635
+ }),
636
+ React.createElement(
637
+ "button",
638
+ {
639
+ className: "moveable-button moveable-drag-area-button",
640
+ title: "拖动"
641
+ },
642
+ React.createElement("div", {
643
+ className: "moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-top"
644
+ }),
645
+ React.createElement("div", {
646
+ className: "moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-bottom"
647
+ }),
648
+ React.createElement("div", {
649
+ className: "moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-left"
650
+ }),
651
+ React.createElement("div", {
652
+ className: " moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-right"
653
+ }),
654
+ React.createElement("div", {
655
+ className: "moveable-select-parent-arrow-body-icon-horizontal"
656
+ }),
657
+ React.createElement("div", {
658
+ className: "moveable-select-parent-arrow-body-icon-vertical"
659
+ })
660
+ )
678
661
  ]
679
662
  );
680
663
  }
@@ -685,6 +668,7 @@
685
668
  mode = Mode.ABSOLUTE;
686
669
  /** 画布容器 */
687
670
  container;
671
+ options = {};
688
672
  /** 水平参考线 */
689
673
  horizontalGuidelines = [];
690
674
  /** 垂直参考线 */
@@ -701,6 +685,9 @@
701
685
  this.container = config.container;
702
686
  this.getRootContainer = config.getRootContainer;
703
687
  }
688
+ getOption(key) {
689
+ return this.options[key];
690
+ }
704
691
  /**
705
692
  * 设置水平/垂直参考线
706
693
  * @param type 参考线类型
@@ -745,7 +732,8 @@
745
732
  getOptions(isMultiSelect, runtimeOptions = {}) {
746
733
  const defaultOptions = this.getDefaultOptions(isMultiSelect);
747
734
  const customizedOptions = this.getCustomizeOptions();
748
- return lodashEs.merge(defaultOptions, customizedOptions, runtimeOptions);
735
+ this.options = lodashEs.merge(defaultOptions, customizedOptions, runtimeOptions);
736
+ return this.options;
749
737
  }
750
738
  /**
751
739
  * 获取单选和多选的moveable公共参数
@@ -765,9 +753,8 @@
765
753
  elementGuidelines: this.elementGuidelines,
766
754
  bounds: {
767
755
  top: 0,
768
- // 设置0的话无法移动到left为0,所以只能设置为-1
769
- left: -1,
770
- right: this.container.clientWidth - 1,
756
+ left: 0,
757
+ right: this.container.clientWidth,
771
758
  bottom: isSortable ? void 0 : this.container.clientHeight
772
759
  }
773
760
  };
@@ -805,6 +792,8 @@
805
792
  left: isAbsolute
806
793
  },
807
794
  isDisplayInnerSnapDigit: true,
795
+ dragTarget: ".moveable-drag-area-button",
796
+ dragTargetSelf: true,
808
797
  props: {
809
798
  actions: true
810
799
  },
@@ -931,14 +920,17 @@
931
920
  Object.entries(options).forEach(([key, value]) => {
932
921
  this.moveable[key] = value;
933
922
  });
934
- this.moveable.updateTarget();
923
+ this.moveable.updateRect();
935
924
  }
936
925
  clearSelectStatus() {
937
926
  if (!this.moveable)
938
927
  return;
939
928
  this.dragResizeHelper.destroyShadowEl();
940
929
  this.moveable.target = null;
941
- this.moveable.updateTarget();
930
+ this.moveable.updateRect();
931
+ }
932
+ getDragStatus() {
933
+ return this.dragStatus;
942
934
  }
943
935
  /**
944
936
  * 销毁实例
@@ -1002,6 +994,7 @@
1002
994
  throw new Error("未选中组件");
1003
995
  this.dragStatus = StageDragStatus.START;
1004
996
  this.dragResizeHelper.onDragStart(e);
997
+ this.emit("drag-start", e);
1005
998
  }).on("drag", (e) => {
1006
999
  if (!this.target || !this.dragResizeHelper.getShadowEl())
1007
1000
  return;
@@ -1150,13 +1143,18 @@
1150
1143
  if (!el || el === this.target)
1151
1144
  return;
1152
1145
  this.target = el;
1153
- this.moveable?.destroy();
1154
- this.moveable = new Moveable(this.container, {
1155
- target: this.targetShadow.update(el),
1156
- origin: false,
1157
- rootContainer: this.getRootContainer(),
1158
- zoom: 2
1159
- });
1146
+ this.targetShadow?.update(el);
1147
+ if (this.moveable) {
1148
+ this.moveable.zoom = 2;
1149
+ this.moveable.updateRect();
1150
+ } else {
1151
+ this.moveable = new Moveable(this.container, {
1152
+ target: this.targetShadow?.el,
1153
+ origin: false,
1154
+ rootContainer: this.getRootContainer(),
1155
+ zoom: 2
1156
+ });
1157
+ }
1160
1158
  }
1161
1159
  /**
1162
1160
  * 清空高亮
@@ -1164,16 +1162,18 @@
1164
1162
  clearHighlight() {
1165
1163
  if (!this.moveable || !this.target)
1166
1164
  return;
1165
+ this.moveable.zoom = 0;
1166
+ this.moveable.updateRect();
1167
1167
  this.target = void 0;
1168
- this.moveable.target = null;
1169
- this.moveable.updateTarget();
1170
1168
  }
1171
1169
  /**
1172
1170
  * 销毁实例
1173
1171
  */
1174
1172
  destroy() {
1175
1173
  this.moveable?.destroy();
1176
- this.targetShadow.destroy();
1174
+ this.targetShadow?.destroy();
1175
+ this.moveable = void 0;
1176
+ this.targetShadow = void 0;
1177
1177
  }
1178
1178
  }
1179
1179
 
@@ -1192,7 +1192,7 @@
1192
1192
  constructor(config) {
1193
1193
  const moveableOptionsManagerConfig = {
1194
1194
  container: config.container,
1195
- moveableOptions: config.multiMoveableOptions,
1195
+ moveableOptions: config.moveableOptions,
1196
1196
  getRootContainer: config.getRootContainer
1197
1197
  };
1198
1198
  super(moveableOptionsManagerConfig);
@@ -1289,7 +1289,7 @@
1289
1289
  Object.entries(options).forEach(([key, value]) => {
1290
1290
  this.moveableForMulti[key] = value;
1291
1291
  });
1292
- this.moveableForMulti.updateTarget();
1292
+ this.moveableForMulti.updateRect();
1293
1293
  }
1294
1294
  /**
1295
1295
  * 清除多选状态
@@ -1364,6 +1364,7 @@
1364
1364
  this.clearHighlight();
1365
1365
  return;
1366
1366
  }
1367
+ this.emit("mousemove", event);
1367
1368
  this.highlight(el);
1368
1369
  }, throttleTime);
1369
1370
  constructor(config) {
@@ -1384,7 +1385,7 @@
1384
1385
  this.dr = new StageDragResize({
1385
1386
  container: config.container,
1386
1387
  disabledDragStart: config.disabledDragStart,
1387
- moveableOptions: this.changeCallback(config.moveableOptions),
1388
+ moveableOptions: this.changeCallback(config.moveableOptions, false),
1388
1389
  dragResizeHelper: createDrHelper(),
1389
1390
  getRootContainer: config.getRootContainer,
1390
1391
  getRenderDocument: config.getRenderDocument,
@@ -1393,7 +1394,7 @@
1393
1394
  });
1394
1395
  this.multiDr = new StageMultiDragResize({
1395
1396
  container: config.container,
1396
- multiMoveableOptions: config.multiMoveableOptions,
1397
+ moveableOptions: this.changeCallback(config.moveableOptions, true),
1397
1398
  dragResizeHelper: createDrHelper(),
1398
1399
  getRootContainer: config.getRootContainer,
1399
1400
  getRenderDocument: config.getRenderDocument,
@@ -1448,6 +1449,14 @@
1448
1449
  getSelectedElList() {
1449
1450
  return this.selectedElList;
1450
1451
  }
1452
+ getMoveableOption(key) {
1453
+ if (this.dr.getTarget()) {
1454
+ return this.dr.getOption(key);
1455
+ }
1456
+ if (this.multiDr.targetList.length) {
1457
+ return this.multiDr.getOption(key);
1458
+ }
1459
+ }
1451
1460
  /**
1452
1461
  * 获取鼠标下方第一个可选中元素,如果元素层叠,返回到是最上层元素
1453
1462
  * @param event 鼠标事件
@@ -1455,6 +1464,7 @@
1455
1464
  */
1456
1465
  async getElementFromPoint(event) {
1457
1466
  const els = this.getElementsFromPoint(event);
1467
+ this.emit("get-elements-from-point", els);
1458
1468
  let stopped = false;
1459
1469
  const stop = () => stopped = true;
1460
1470
  for (const el of els) {
@@ -1577,6 +1587,9 @@
1577
1587
  }
1578
1588
  return void 0;
1579
1589
  }
1590
+ getDragStatus() {
1591
+ return this.dr.getDragStatus();
1592
+ }
1580
1593
  destroy() {
1581
1594
  this.container.removeEventListener("mousedown", this.mouseDownHandler);
1582
1595
  this.container.removeEventListener("mousemove", this.mouseMoveHandler);
@@ -1586,12 +1599,16 @@
1586
1599
  this.multiDr.destroy();
1587
1600
  this.highlightLayer.destroy();
1588
1601
  }
1589
- changeCallback(options) {
1602
+ changeCallback(options, isMulti) {
1590
1603
  if (typeof options === "function") {
1591
1604
  return () => {
1592
1605
  if (typeof options === "function") {
1593
1606
  const cfg = {
1594
- targetElId: this.selectedEl?.id
1607
+ targetEl: this.selectedEl,
1608
+ targetElId: this.selectedEl?.id,
1609
+ targetEls: this.selectedElList,
1610
+ targetElIds: this.selectedElList?.map((item) => item.id),
1611
+ isMulti
1595
1612
  };
1596
1613
  return options(cfg);
1597
1614
  }
@@ -1688,6 +1705,8 @@
1688
1705
  data: [{ el: drTarget }]
1689
1706
  };
1690
1707
  this.emit("remove", data);
1708
+ }).on("drag-start", (e) => {
1709
+ this.emit("drag-start", e);
1691
1710
  });
1692
1711
  this.multiDr.on("update", (data) => {
1693
1712
  this.emit("multi-update", data);
@@ -2367,6 +2386,9 @@
2367
2386
  highlight(idOrEl) {
2368
2387
  this.actionManager.highlight(idOrEl);
2369
2388
  }
2389
+ clearHighlight() {
2390
+ this.actionManager.clearHighlight();
2391
+ }
2370
2392
  /**
2371
2393
  * 更新组件
2372
2394
  * @param data 更新组件的数据
@@ -2434,6 +2456,12 @@
2434
2456
  delayedMarkContainer(event, excludeElList = []) {
2435
2457
  return this.actionManager.delayedMarkContainer(event, excludeElList);
2436
2458
  }
2459
+ getMoveableOption(key) {
2460
+ return this.actionManager.getMoveableOption(key);
2461
+ }
2462
+ getDragStatus() {
2463
+ return this.actionManager.getDragStatus();
2464
+ }
2437
2465
  /**
2438
2466
  * 销毁实例
2439
2467
  */
@@ -2464,7 +2492,6 @@
2464
2492
  containerHighlightDuration: config.containerHighlightDuration,
2465
2493
  containerHighlightType: config.containerHighlightType,
2466
2494
  moveableOptions: config.moveableOptions,
2467
- multiMoveableOptions: config.multiMoveableOptions,
2468
2495
  container: this.mask.content,
2469
2496
  disabledDragStart: config.disabledDragStart,
2470
2497
  canSelect: config.canSelect,
@@ -2500,6 +2527,7 @@
2500
2527
  this.initDrEvent();
2501
2528
  this.initMulDrEvent();
2502
2529
  this.initHighlightEvent();
2530
+ this.initMouseEvent();
2503
2531
  }
2504
2532
  /**
2505
2533
  * 初始化ActionManager类本身抛出来的事件监听
@@ -2548,6 +2576,18 @@
2548
2576
  this.emit("highlight", highlightEl);
2549
2577
  });
2550
2578
  }
2579
+ /**
2580
+ * 初始化Highlight类通过ActionManager抛出来的事件监听
2581
+ */
2582
+ initMouseEvent() {
2583
+ this.actionManager.on("mousemove", async (event) => {
2584
+ this.emit("mousemove", event);
2585
+ }).on("mouseleave", async (event) => {
2586
+ this.emit("mouseleave", event);
2587
+ }).on("drag-start", (e) => {
2588
+ this.emit("drag-start", e);
2589
+ });
2590
+ }
2551
2591
  }
2552
2592
 
2553
2593
  exports.AbleActionEventType = AbleActionEventType;