@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.
@@ -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
- selectParent: Boolean
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
- .moveable-button {
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] - 48}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg) translate(10px)`
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
- "svg",
654
- {
655
- width: "20px",
656
- height: "20px",
657
- viewBox: "0 0 16 16",
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
- return merge(defaultOptions, customizedOptions, runtimeOptions);
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
- // 设置0的话无法移动到left为0,所以只能设置为-1
772
- left: -1,
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,17 @@ class StageDragResize extends MoveableOptionsManager {
934
923
  Object.entries(options).forEach(([key, value]) => {
935
924
  this.moveable[key] = value;
936
925
  });
937
- this.moveable.updateTarget();
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.updateTarget();
933
+ this.moveable.updateRect();
934
+ }
935
+ getDragStatus() {
936
+ return this.dragStatus;
945
937
  }
946
938
  /**
947
939
  * 销毁实例
@@ -1005,6 +997,7 @@ class StageDragResize extends MoveableOptionsManager {
1005
997
  throw new Error("未选中组件");
1006
998
  this.dragStatus = StageDragStatus.START;
1007
999
  this.dragResizeHelper.onDragStart(e);
1000
+ this.emit("drag-start", e);
1008
1001
  }).on("drag", (e) => {
1009
1002
  if (!this.target || !this.dragResizeHelper.getShadowEl())
1010
1003
  return;
@@ -1153,13 +1146,18 @@ class StageHighlight extends EventEmitter$1 {
1153
1146
  if (!el || el === this.target)
1154
1147
  return;
1155
1148
  this.target = el;
1156
- this.moveable?.destroy();
1157
- this.moveable = new Moveable(this.container, {
1158
- target: this.targetShadow.update(el),
1159
- origin: false,
1160
- rootContainer: this.getRootContainer(),
1161
- zoom: 2
1162
- });
1149
+ this.targetShadow?.update(el);
1150
+ if (this.moveable) {
1151
+ this.moveable.zoom = 2;
1152
+ this.moveable.updateRect();
1153
+ } else {
1154
+ this.moveable = new Moveable(this.container, {
1155
+ target: this.targetShadow?.el,
1156
+ origin: false,
1157
+ rootContainer: this.getRootContainer(),
1158
+ zoom: 2
1159
+ });
1160
+ }
1163
1161
  }
1164
1162
  /**
1165
1163
  * 清空高亮
@@ -1167,16 +1165,18 @@ class StageHighlight extends EventEmitter$1 {
1167
1165
  clearHighlight() {
1168
1166
  if (!this.moveable || !this.target)
1169
1167
  return;
1168
+ this.moveable.zoom = 0;
1169
+ this.moveable.updateRect();
1170
1170
  this.target = void 0;
1171
- this.moveable.target = null;
1172
- this.moveable.updateTarget();
1173
1171
  }
1174
1172
  /**
1175
1173
  * 销毁实例
1176
1174
  */
1177
1175
  destroy() {
1178
1176
  this.moveable?.destroy();
1179
- this.targetShadow.destroy();
1177
+ this.targetShadow?.destroy();
1178
+ this.moveable = void 0;
1179
+ this.targetShadow = void 0;
1180
1180
  }
1181
1181
  }
1182
1182
 
@@ -1195,7 +1195,7 @@ class StageMultiDragResize extends MoveableOptionsManager {
1195
1195
  constructor(config) {
1196
1196
  const moveableOptionsManagerConfig = {
1197
1197
  container: config.container,
1198
- moveableOptions: config.multiMoveableOptions,
1198
+ moveableOptions: config.moveableOptions,
1199
1199
  getRootContainer: config.getRootContainer
1200
1200
  };
1201
1201
  super(moveableOptionsManagerConfig);
@@ -1292,7 +1292,7 @@ class StageMultiDragResize extends MoveableOptionsManager {
1292
1292
  Object.entries(options).forEach(([key, value]) => {
1293
1293
  this.moveableForMulti[key] = value;
1294
1294
  });
1295
- this.moveableForMulti.updateTarget();
1295
+ this.moveableForMulti.updateRect();
1296
1296
  }
1297
1297
  /**
1298
1298
  * 清除多选状态
@@ -1367,6 +1367,7 @@ class ActionManager extends EventEmitter {
1367
1367
  this.clearHighlight();
1368
1368
  return;
1369
1369
  }
1370
+ this.emit("mousemove", event);
1370
1371
  this.highlight(el);
1371
1372
  }, throttleTime);
1372
1373
  constructor(config) {
@@ -1387,7 +1388,7 @@ class ActionManager extends EventEmitter {
1387
1388
  this.dr = new StageDragResize({
1388
1389
  container: config.container,
1389
1390
  disabledDragStart: config.disabledDragStart,
1390
- moveableOptions: this.changeCallback(config.moveableOptions),
1391
+ moveableOptions: this.changeCallback(config.moveableOptions, false),
1391
1392
  dragResizeHelper: createDrHelper(),
1392
1393
  getRootContainer: config.getRootContainer,
1393
1394
  getRenderDocument: config.getRenderDocument,
@@ -1396,7 +1397,7 @@ class ActionManager extends EventEmitter {
1396
1397
  });
1397
1398
  this.multiDr = new StageMultiDragResize({
1398
1399
  container: config.container,
1399
- multiMoveableOptions: config.multiMoveableOptions,
1400
+ moveableOptions: this.changeCallback(config.moveableOptions, true),
1400
1401
  dragResizeHelper: createDrHelper(),
1401
1402
  getRootContainer: config.getRootContainer,
1402
1403
  getRenderDocument: config.getRenderDocument,
@@ -1451,6 +1452,14 @@ class ActionManager extends EventEmitter {
1451
1452
  getSelectedElList() {
1452
1453
  return this.selectedElList;
1453
1454
  }
1455
+ getMoveableOption(key) {
1456
+ if (this.dr.getTarget()) {
1457
+ return this.dr.getOption(key);
1458
+ }
1459
+ if (this.multiDr.targetList.length) {
1460
+ return this.multiDr.getOption(key);
1461
+ }
1462
+ }
1454
1463
  /**
1455
1464
  * 获取鼠标下方第一个可选中元素,如果元素层叠,返回到是最上层元素
1456
1465
  * @param event 鼠标事件
@@ -1458,6 +1467,7 @@ class ActionManager extends EventEmitter {
1458
1467
  */
1459
1468
  async getElementFromPoint(event) {
1460
1469
  const els = this.getElementsFromPoint(event);
1470
+ this.emit("get-elements-from-point", els);
1461
1471
  let stopped = false;
1462
1472
  const stop = () => stopped = true;
1463
1473
  for (const el of els) {
@@ -1580,6 +1590,9 @@ class ActionManager extends EventEmitter {
1580
1590
  }
1581
1591
  return void 0;
1582
1592
  }
1593
+ getDragStatus() {
1594
+ return this.dr.getDragStatus();
1595
+ }
1583
1596
  destroy() {
1584
1597
  this.container.removeEventListener("mousedown", this.mouseDownHandler);
1585
1598
  this.container.removeEventListener("mousemove", this.mouseMoveHandler);
@@ -1589,12 +1602,16 @@ class ActionManager extends EventEmitter {
1589
1602
  this.multiDr.destroy();
1590
1603
  this.highlightLayer.destroy();
1591
1604
  }
1592
- changeCallback(options) {
1605
+ changeCallback(options, isMulti) {
1593
1606
  if (typeof options === "function") {
1594
1607
  return () => {
1595
1608
  if (typeof options === "function") {
1596
1609
  const cfg = {
1597
- targetElId: this.selectedEl?.id
1610
+ targetEl: this.selectedEl,
1611
+ targetElId: this.selectedEl?.id,
1612
+ targetEls: this.selectedElList,
1613
+ targetElIds: this.selectedElList?.map((item) => item.id),
1614
+ isMulti
1598
1615
  };
1599
1616
  return options(cfg);
1600
1617
  }
@@ -1691,6 +1708,8 @@ class ActionManager extends EventEmitter {
1691
1708
  data: [{ el: drTarget }]
1692
1709
  };
1693
1710
  this.emit("remove", data);
1711
+ }).on("drag-start", (e) => {
1712
+ this.emit("drag-start", e);
1694
1713
  });
1695
1714
  this.multiDr.on("update", (data) => {
1696
1715
  this.emit("multi-update", data);
@@ -2370,6 +2389,9 @@ class StageCore extends EventEmitter$1 {
2370
2389
  highlight(idOrEl) {
2371
2390
  this.actionManager.highlight(idOrEl);
2372
2391
  }
2392
+ clearHighlight() {
2393
+ this.actionManager.clearHighlight();
2394
+ }
2373
2395
  /**
2374
2396
  * 更新组件
2375
2397
  * @param data 更新组件的数据
@@ -2437,6 +2459,12 @@ class StageCore extends EventEmitter$1 {
2437
2459
  delayedMarkContainer(event, excludeElList = []) {
2438
2460
  return this.actionManager.delayedMarkContainer(event, excludeElList);
2439
2461
  }
2462
+ getMoveableOption(key) {
2463
+ return this.actionManager.getMoveableOption(key);
2464
+ }
2465
+ getDragStatus() {
2466
+ return this.actionManager.getDragStatus();
2467
+ }
2440
2468
  /**
2441
2469
  * 销毁实例
2442
2470
  */
@@ -2467,7 +2495,6 @@ class StageCore extends EventEmitter$1 {
2467
2495
  containerHighlightDuration: config.containerHighlightDuration,
2468
2496
  containerHighlightType: config.containerHighlightType,
2469
2497
  moveableOptions: config.moveableOptions,
2470
- multiMoveableOptions: config.multiMoveableOptions,
2471
2498
  container: this.mask.content,
2472
2499
  disabledDragStart: config.disabledDragStart,
2473
2500
  canSelect: config.canSelect,
@@ -2503,6 +2530,7 @@ class StageCore extends EventEmitter$1 {
2503
2530
  this.initDrEvent();
2504
2531
  this.initMulDrEvent();
2505
2532
  this.initHighlightEvent();
2533
+ this.initMouseEvent();
2506
2534
  }
2507
2535
  /**
2508
2536
  * 初始化ActionManager类本身抛出来的事件监听
@@ -2551,6 +2579,18 @@ class StageCore extends EventEmitter$1 {
2551
2579
  this.emit("highlight", highlightEl);
2552
2580
  });
2553
2581
  }
2582
+ /**
2583
+ * 初始化Highlight类通过ActionManager抛出来的事件监听
2584
+ */
2585
+ initMouseEvent() {
2586
+ this.actionManager.on("mousemove", async (event) => {
2587
+ this.emit("mousemove", event);
2588
+ }).on("mouseleave", async (event) => {
2589
+ this.emit("mouseleave", event);
2590
+ }).on("drag-start", (e) => {
2591
+ this.emit("drag-start", e);
2592
+ });
2593
+ }
2554
2594
  }
2555
2595
 
2556
2596
  export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, SELECTED_CLASS, SelectStatus, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, calcValueByFontsize, StageCore as default, down, getAbsolutePosition, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };