@tmagic/stage 1.3.5 → 1.3.7

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.
@@ -36,6 +36,11 @@
36
36
  return Mode2;
37
37
  })(Mode || {});
38
38
  const SELECTED_CLASS = "tmagic-stage-selected-area";
39
+ var AbleActionEventType = /* @__PURE__ */ ((AbleActionEventType2) => {
40
+ AbleActionEventType2["SELECT_PARENT"] = "select-parent";
41
+ AbleActionEventType2["REMOVE"] = "remove";
42
+ return AbleActionEventType2;
43
+ })(AbleActionEventType || {});
39
44
 
40
45
  const getParents = (el, relative) => {
41
46
  let cur = el.parentElement;
@@ -279,7 +284,7 @@
279
284
  el.id = `${this.idPrefix}${target.id}`;
280
285
  el.style.cssText = getTargetElStyle(target, this.zIndex);
281
286
  if (typeof this.updateDragEl === "function") {
282
- this.updateDragEl(el, target);
287
+ this.updateDragEl(el, target, this.container);
283
288
  }
284
289
  const isFixed = isFixedParent(target);
285
290
  const mode = this.container.dataset.mode || Mode.ABSOLUTE;
@@ -579,28 +584,6 @@
579
584
 
580
585
  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";
581
586
 
582
- var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
583
- ContainerHighlightType2["DEFAULT"] = "default";
584
- ContainerHighlightType2["ALT"] = "alt";
585
- return ContainerHighlightType2;
586
- })(ContainerHighlightType || {});
587
- var SelectStatus = /* @__PURE__ */ ((SelectStatus2) => {
588
- SelectStatus2["SELECT"] = "select";
589
- SelectStatus2["MULTI_SELECT"] = "multiSelect";
590
- return SelectStatus2;
591
- })(SelectStatus || {});
592
- var StageDragStatus = /* @__PURE__ */ ((StageDragStatus2) => {
593
- StageDragStatus2["START"] = "start";
594
- StageDragStatus2["ING"] = "ing";
595
- StageDragStatus2["END"] = "end";
596
- return StageDragStatus2;
597
- })(StageDragStatus || {});
598
- var AbleActionEventType = /* @__PURE__ */ ((AbleActionEventType2) => {
599
- AbleActionEventType2["SELECT_PARENT"] = "select-parent";
600
- AbleActionEventType2["REMOVE"] = "remove";
601
- return AbleActionEventType2;
602
- })(AbleActionEventType || {});
603
-
604
587
  const MoveableActionsAble = (handler) => ({
605
588
  name: "actions",
606
589
  props: [],
@@ -893,6 +876,28 @@
893
876
  }
894
877
  }
895
878
 
879
+ var ContainerHighlightType = /* @__PURE__ */ ((ContainerHighlightType2) => {
880
+ ContainerHighlightType2["DEFAULT"] = "default";
881
+ ContainerHighlightType2["ALT"] = "alt";
882
+ return ContainerHighlightType2;
883
+ })(ContainerHighlightType || {});
884
+ var RenderType = /* @__PURE__ */ ((RenderType2) => {
885
+ RenderType2["IFRAME"] = "iframe";
886
+ RenderType2["NATIVE"] = "native";
887
+ return RenderType2;
888
+ })(RenderType || {});
889
+ var SelectStatus = /* @__PURE__ */ ((SelectStatus2) => {
890
+ SelectStatus2["SELECT"] = "select";
891
+ SelectStatus2["MULTI_SELECT"] = "multiSelect";
892
+ return SelectStatus2;
893
+ })(SelectStatus || {});
894
+ var StageDragStatus = /* @__PURE__ */ ((StageDragStatus2) => {
895
+ StageDragStatus2["START"] = "start";
896
+ StageDragStatus2["ING"] = "ing";
897
+ StageDragStatus2["END"] = "end";
898
+ return StageDragStatus2;
899
+ })(StageDragStatus || {});
900
+
896
901
  class StageDragResize extends MoveableOptionsManager {
897
902
  /** 目标节点 */
898
903
  target;
@@ -1385,6 +1390,8 @@
1385
1390
  canSelect;
1386
1391
  isContainer;
1387
1392
  getRenderDocument;
1393
+ disabledMultiSelect = false;
1394
+ config;
1388
1395
  mouseMoveHandler = lodashEs.throttle(async (event) => {
1389
1396
  if (event.target?.classList?.contains("moveable-direction")) {
1390
1397
  return;
@@ -1399,38 +1406,21 @@
1399
1406
  }, throttleTime);
1400
1407
  constructor(config) {
1401
1408
  super();
1409
+ this.config = config;
1402
1410
  this.container = config.container;
1403
1411
  this.containerHighlightClassName = config.containerHighlightClassName || CONTAINER_HIGHLIGHT_CLASS_NAME;
1404
1412
  this.containerHighlightDuration = config.containerHighlightDuration || defaultContainerHighlightDuration;
1405
1413
  this.containerHighlightType = config.containerHighlightType;
1414
+ this.disabledMultiSelect = config.disabledMultiSelect ?? false;
1406
1415
  this.getTargetElement = config.getTargetElement;
1407
1416
  this.getElementsFromPoint = config.getElementsFromPoint;
1408
1417
  this.canSelect = config.canSelect || ((el) => !!el.id);
1409
1418
  this.getRenderDocument = config.getRenderDocument;
1410
1419
  this.isContainer = config.isContainer;
1411
- const createDrHelper = () => new DragResizeHelper({
1412
- container: config.container,
1413
- updateDragEl: config.updateDragEl
1414
- });
1415
- this.dr = new StageDragResize({
1416
- container: config.container,
1417
- disabledDragStart: config.disabledDragStart,
1418
- moveableOptions: this.changeCallback(config.moveableOptions, false),
1419
- dragResizeHelper: createDrHelper(),
1420
- getRootContainer: config.getRootContainer,
1421
- getRenderDocument: config.getRenderDocument,
1422
- markContainerEnd: this.markContainerEnd.bind(this),
1423
- delayedMarkContainer: this.delayedMarkContainer.bind(this)
1424
- });
1425
- this.multiDr = new StageMultiDragResize({
1426
- container: config.container,
1427
- moveableOptions: this.changeCallback(config.moveableOptions, true),
1428
- dragResizeHelper: createDrHelper(),
1429
- getRootContainer: config.getRootContainer,
1430
- getRenderDocument: config.getRenderDocument,
1431
- markContainerEnd: this.markContainerEnd.bind(this),
1432
- delayedMarkContainer: this.delayedMarkContainer.bind(this)
1433
- });
1420
+ this.dr = this.createDr(config);
1421
+ if (!this.disabledMultiSelect) {
1422
+ this.multiDr = this.createMultiDr(config);
1423
+ }
1434
1424
  this.highlightLayer = new StageHighlight({
1435
1425
  container: config.container,
1436
1426
  updateDragEl: config.updateDragEl,
@@ -1438,7 +1428,19 @@
1438
1428
  });
1439
1429
  this.initMouseEvent();
1440
1430
  this.initKeyEvent();
1441
- this.initActionEvent();
1431
+ }
1432
+ disableMultiSelect() {
1433
+ this.disabledMultiSelect = true;
1434
+ if (this.multiDr) {
1435
+ this.multiDr.destroy();
1436
+ this.multiDr = void 0;
1437
+ }
1438
+ }
1439
+ enableMultiSelect() {
1440
+ this.disabledMultiSelect = false;
1441
+ if (!this.multiDr) {
1442
+ this.multiDr = this.createMultiDr(this.config);
1443
+ }
1442
1444
  }
1443
1445
  /**
1444
1446
  * 设置水平/垂直参考线
@@ -1447,14 +1449,14 @@
1447
1449
  */
1448
1450
  setGuidelines(type, guidelines) {
1449
1451
  this.dr.setGuidelines(type, guidelines);
1450
- this.multiDr.setGuidelines(type, guidelines);
1452
+ this.multiDr?.setGuidelines(type, guidelines);
1451
1453
  }
1452
1454
  /**
1453
1455
  * 清空所有参考线
1454
1456
  */
1455
1457
  clearGuides() {
1456
1458
  this.dr.clearGuides();
1457
- this.multiDr.clearGuides();
1459
+ this.multiDr?.clearGuides();
1458
1460
  }
1459
1461
  /**
1460
1462
  * 更新moveable,外部主要调用场景是元素配置变更、页面大小变更
@@ -1462,7 +1464,7 @@
1462
1464
  */
1463
1465
  updateMoveable(el) {
1464
1466
  this.dr.updateMoveable(el);
1465
- this.multiDr.updateMoveable();
1467
+ this.multiDr?.updateMoveable();
1466
1468
  }
1467
1469
  /**
1468
1470
  * 判断是否单选选中的元素
@@ -1483,7 +1485,7 @@
1483
1485
  if (this.dr.getTarget()) {
1484
1486
  return this.dr.getOption(key);
1485
1487
  }
1486
- if (this.multiDr.targetList.length) {
1488
+ if (this.multiDr?.targetList.length) {
1487
1489
  return this.multiDr.getOption(key);
1488
1490
  }
1489
1491
  }
@@ -1533,17 +1535,17 @@
1533
1535
  if (selectedEl?.className.includes(PAGE_CLASS)) {
1534
1536
  return true;
1535
1537
  }
1536
- return this.multiDr.canSelect(el, selectedEl);
1538
+ return this.multiDr?.canSelect(el, selectedEl) || false;
1537
1539
  }
1538
1540
  select(el, event) {
1539
- this.selectedEl = el;
1541
+ this.setSelectedEl(el);
1540
1542
  this.clearSelectStatus(SelectStatus.MULTI_SELECT);
1541
1543
  this.dr.select(el, event);
1542
1544
  }
1543
1545
  multiSelect(idOrElList) {
1544
1546
  this.selectedElList = idOrElList.map((idOrEl) => this.getTargetElement(idOrEl));
1545
1547
  this.clearSelectStatus(SelectStatus.SELECT);
1546
- this.multiDr.multiSelect(this.selectedElList);
1548
+ this.multiDr?.multiSelect(this.selectedElList);
1547
1549
  }
1548
1550
  getHighlightEl() {
1549
1551
  return this.highlightedEl;
@@ -1559,7 +1561,7 @@
1559
1561
  this.clearHighlight();
1560
1562
  return;
1561
1563
  }
1562
- if (el === this.getSelectedEl() || this.multiDr.dragStatus === StageDragStatus.ING) {
1564
+ if (el === this.getSelectedEl() || this.multiDr?.dragStatus === StageDragStatus.ING) {
1563
1565
  this.clearHighlight();
1564
1566
  return;
1565
1567
  }
@@ -1579,7 +1581,7 @@
1579
1581
  */
1580
1582
  clearSelectStatus(selectType) {
1581
1583
  if (selectType === SelectStatus.MULTI_SELECT) {
1582
- this.multiDr.clearSelectStatus();
1584
+ this.multiDr?.clearSelectStatus();
1583
1585
  this.selectedElList = [];
1584
1586
  } else {
1585
1587
  this.dr.clearSelectStatus();
@@ -1626,9 +1628,67 @@
1626
1628
  this.container.removeEventListener("mouseleave", this.mouseLeaveHandler);
1627
1629
  this.container.removeEventListener("wheel", this.mouseWheelHandler);
1628
1630
  this.dr.destroy();
1629
- this.multiDr.destroy();
1631
+ this.multiDr?.destroy();
1630
1632
  this.highlightLayer.destroy();
1631
1633
  }
1634
+ createDr(config) {
1635
+ const createDrHelper = () => new DragResizeHelper({
1636
+ container: config.container,
1637
+ updateDragEl: config.updateDragEl
1638
+ });
1639
+ const dr = new StageDragResize({
1640
+ container: config.container,
1641
+ disabledDragStart: config.disabledDragStart,
1642
+ moveableOptions: this.changeCallback(config.moveableOptions, false),
1643
+ dragResizeHelper: createDrHelper(),
1644
+ getRootContainer: config.getRootContainer,
1645
+ getRenderDocument: config.getRenderDocument,
1646
+ markContainerEnd: this.markContainerEnd.bind(this),
1647
+ delayedMarkContainer: this.delayedMarkContainer.bind(this)
1648
+ });
1649
+ dr.on("update", (data) => {
1650
+ setTimeout(() => this.emit("update", data));
1651
+ }).on("sort", (data) => {
1652
+ setTimeout(() => this.emit("sort", data));
1653
+ }).on("select-parent", () => {
1654
+ this.emit("select-parent");
1655
+ }).on("remove", () => {
1656
+ const drTarget = this.dr.getTarget();
1657
+ if (!drTarget)
1658
+ return;
1659
+ const data = {
1660
+ data: [{ el: drTarget }]
1661
+ };
1662
+ this.emit("remove", data);
1663
+ }).on("drag-start", (e) => {
1664
+ this.emit("drag-start", e);
1665
+ });
1666
+ return dr;
1667
+ }
1668
+ createMultiDr(config) {
1669
+ const createDrHelper = () => new DragResizeHelper({
1670
+ container: config.container,
1671
+ updateDragEl: config.updateDragEl
1672
+ });
1673
+ const multiDr = new StageMultiDragResize({
1674
+ container: config.container,
1675
+ moveableOptions: this.changeCallback(config.moveableOptions, true),
1676
+ dragResizeHelper: createDrHelper(),
1677
+ getRootContainer: config.getRootContainer,
1678
+ getRenderDocument: config.getRenderDocument,
1679
+ markContainerEnd: this.markContainerEnd.bind(this),
1680
+ delayedMarkContainer: this.delayedMarkContainer.bind(this)
1681
+ });
1682
+ multiDr?.on("update", (data) => {
1683
+ this.emit("multi-update", data);
1684
+ }).on("change-to-select", async (id) => {
1685
+ if (this.isMultiSelectStatus)
1686
+ return false;
1687
+ const el = this.getTargetElement(id);
1688
+ this.emit("change-to-select", el);
1689
+ });
1690
+ return multiDr;
1691
+ }
1632
1692
  changeCallback(options, isMulti) {
1633
1693
  if (typeof options === "function") {
1634
1694
  return () => {
@@ -1659,7 +1719,7 @@
1659
1719
  return;
1660
1720
  if (this.selectedEl && !this.selectedEl.className.includes(PAGE_CLASS)) {
1661
1721
  this.selectedElList.push(this.selectedEl);
1662
- this.selectedEl = void 0;
1722
+ this.setSelectedEl(void 0);
1663
1723
  }
1664
1724
  const existIndex = this.selectedElList.findIndex((selectedDom) => selectedDom.id === el.id);
1665
1725
  if (existIndex !== -1) {
@@ -1699,14 +1759,20 @@
1699
1759
  const ctrl = isMac ? "meta" : "ctrl";
1700
1760
  KeyController.global.keydown(ctrl, (e) => {
1701
1761
  e.inputEvent.preventDefault();
1702
- this.isMultiSelectStatus = true;
1762
+ if (!this.disabledMultiSelect) {
1763
+ this.isMultiSelectStatus = true;
1764
+ }
1703
1765
  });
1704
1766
  KeyController.global.on("blur", () => {
1705
- this.isMultiSelectStatus = false;
1767
+ if (!this.disabledMultiSelect) {
1768
+ this.isMultiSelectStatus = false;
1769
+ }
1706
1770
  });
1707
1771
  KeyController.global.keyup(ctrl, (e) => {
1708
1772
  e.inputEvent.preventDefault();
1709
- this.isMultiSelectStatus = false;
1773
+ if (!this.disabledMultiSelect) {
1774
+ this.isMultiSelectStatus = false;
1775
+ }
1710
1776
  });
1711
1777
  KeyController.global.keydown("alt", (e) => {
1712
1778
  e.inputEvent.preventDefault();
@@ -1718,36 +1784,6 @@
1718
1784
  this.isAltKeydown = false;
1719
1785
  });
1720
1786
  }
1721
- /**
1722
- * 处理单选、多选抛出来的事件
1723
- */
1724
- initActionEvent() {
1725
- this.dr.on("update", (data) => {
1726
- setTimeout(() => this.emit("update", data));
1727
- }).on("sort", (data) => {
1728
- setTimeout(() => this.emit("sort", data));
1729
- }).on("select-parent", () => {
1730
- this.emit("select-parent");
1731
- }).on("remove", () => {
1732
- const drTarget = this.dr.getTarget();
1733
- if (!drTarget)
1734
- return;
1735
- const data = {
1736
- data: [{ el: drTarget }]
1737
- };
1738
- this.emit("remove", data);
1739
- }).on("drag-start", (e) => {
1740
- this.emit("drag-start", e);
1741
- });
1742
- this.multiDr.on("update", (data) => {
1743
- this.emit("multi-update", data);
1744
- }).on("change-to-select", async (id) => {
1745
- if (this.isMultiSelectStatus)
1746
- return false;
1747
- const el = this.getTargetElement(id);
1748
- this.emit("change-to-select", el);
1749
- });
1750
- }
1751
1787
  /**
1752
1788
  * 在down事件中集中cpu处理画布中选中操作渲染,在up事件中再通知外面的编辑器更新
1753
1789
  */
@@ -1788,13 +1824,13 @@
1788
1824
  /**
1789
1825
  * 在up事件中负责对外通知选中事件,通知画布之外的编辑器更新
1790
1826
  */
1791
- mouseUpHandler = () => {
1827
+ mouseUpHandler = (event) => {
1792
1828
  utils.getDocument().removeEventListener("mouseup", this.mouseUpHandler);
1793
1829
  this.container.addEventListener("mousemove", this.mouseMoveHandler);
1794
1830
  if (this.isMultiSelectStatus) {
1795
- this.emit("multi-select", this.selectedElList);
1831
+ this.emit("multi-select", this.selectedElList, event);
1796
1832
  } else {
1797
- this.emit("select", this.selectedEl);
1833
+ this.emit("select", this.selectedEl, event);
1798
1834
  }
1799
1835
  };
1800
1836
  mouseLeaveHandler = (event) => {
@@ -1814,8 +1850,10 @@
1814
1850
  container;
1815
1851
  containerResizeObserver;
1816
1852
  isShowGuides = true;
1817
- constructor(container) {
1853
+ guidesOptions;
1854
+ constructor(container, options) {
1818
1855
  super();
1856
+ this.guidesOptions = options?.guidesOptions || {};
1819
1857
  this.container = container;
1820
1858
  this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
1821
1859
  this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
@@ -1914,7 +1952,8 @@
1914
1952
  lineColor: "#000",
1915
1953
  textColor: "#000",
1916
1954
  style: this.getGuidesStyle(type),
1917
- showGuides: this.isShowGuides
1955
+ showGuides: this.isShowGuides,
1956
+ ...this.guidesOptions
1918
1957
  });
1919
1958
  const changEventHandler = {
1920
1959
  [GuidesType.HORIZONTAL]: this.hGuidesChangeGuidesHandler,
@@ -1986,9 +2025,9 @@
1986
2025
  pageScrollParent = null;
1987
2026
  intersectionObserver = null;
1988
2027
  wrapperResizeObserver = null;
1989
- constructor() {
2028
+ constructor(options) {
1990
2029
  const wrapper = createWrapper();
1991
- super(wrapper);
2030
+ super(wrapper, options);
1992
2031
  this.wrapper = wrapper;
1993
2032
  this.content.addEventListener("wheel", this.mouseWheelHandler);
1994
2033
  this.wrapper.appendChild(this.content);
@@ -2203,22 +2242,22 @@
2203
2242
  contentWindow = null;
2204
2243
  runtime = null;
2205
2244
  iframe;
2245
+ nativeContainer;
2206
2246
  runtimeUrl;
2207
2247
  zoom = DEFAULT_ZOOM;
2248
+ renderType;
2208
2249
  customizedRender;
2209
- constructor({ runtimeUrl, zoom, customizedRender }) {
2250
+ constructor({ runtimeUrl, zoom, customizedRender, renderType = RenderType.IFRAME }) {
2210
2251
  super();
2252
+ this.renderType = renderType;
2211
2253
  this.runtimeUrl = runtimeUrl || "";
2212
2254
  this.customizedRender = customizedRender;
2213
2255
  this.setZoom(zoom);
2214
- this.iframe = globalThis.document.createElement("iframe");
2215
- this.iframe.src = utils.isSameDomain(this.runtimeUrl) ? this.runtimeUrl : "";
2216
- this.iframe.style.cssText = `
2217
- border: 0;
2218
- width: 100%;
2219
- height: 100%;
2220
- `;
2221
- this.iframe.addEventListener("load", this.loadHandler);
2256
+ if (this.renderType === RenderType.IFRAME) {
2257
+ this.createIframe();
2258
+ } else if (this.renderType === RenderType.NATIVE) {
2259
+ this.createNativeContainer();
2260
+ }
2222
2261
  }
2223
2262
  getMagicApi = () => ({
2224
2263
  onPageElUpdate: (el) => this.emit("page-el-update", el),
@@ -2258,18 +2297,19 @@
2258
2297
  * @param el 将页面挂载到该Dom节点上
2259
2298
  */
2260
2299
  async mount(el) {
2261
- if (!this.iframe) {
2262
- throw Error("mount 失败");
2263
- }
2264
- if (!utils.isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
2265
- let html = await fetch(this.runtimeUrl).then((res) => res.text());
2266
- const base = `${location.protocol}//${utils.getHost(this.runtimeUrl)}`;
2267
- html = html.replace("<head>", `<head>
2300
+ if (this.iframe) {
2301
+ if (!utils.isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
2302
+ let html = await fetch(this.runtimeUrl).then((res) => res.text());
2303
+ const base = `${location.protocol}//${utils.getHost(this.runtimeUrl)}`;
2304
+ html = html.replace("<head>", `<head>
2268
2305
  <base href="${base}">`);
2269
- this.iframe.srcdoc = html;
2306
+ this.iframe.srcdoc = html;
2307
+ }
2308
+ el.appendChild(this.iframe);
2309
+ this.postTmagicRuntimeReady();
2310
+ } else if (this.nativeContainer) {
2311
+ el.appendChild(this.nativeContainer);
2270
2312
  }
2271
- el.appendChild(this.iframe);
2272
- this.postTmagicRuntimeReady();
2273
2313
  }
2274
2314
  getRuntime = () => {
2275
2315
  if (this.runtime)
@@ -2315,12 +2355,34 @@
2315
2355
  * 销毁实例
2316
2356
  */
2317
2357
  destroy() {
2318
- this.iframe?.removeEventListener("load", this.loadHandler);
2358
+ this.iframe?.removeEventListener("load", this.iframeLoadHandler);
2319
2359
  this.contentWindow = null;
2320
2360
  this.iframe?.remove();
2321
2361
  this.iframe = void 0;
2322
2362
  this.removeAllListeners();
2323
2363
  }
2364
+ createIframe() {
2365
+ this.iframe = globalThis.document.createElement("iframe");
2366
+ this.iframe.src = this.runtimeUrl && utils.isSameDomain(this.runtimeUrl) ? this.runtimeUrl : "";
2367
+ this.iframe.style.cssText = `
2368
+ border: 0;
2369
+ width: 100%;
2370
+ height: 100%;
2371
+ `;
2372
+ this.iframe.addEventListener("load", this.iframeLoadHandler);
2373
+ return this.iframe;
2374
+ }
2375
+ async createNativeContainer() {
2376
+ this.contentWindow = globalThis;
2377
+ this.nativeContainer = globalThis.document.createElement("div");
2378
+ this.contentWindow.magic = this.getMagicApi();
2379
+ if (this.customizedRender) {
2380
+ const el = await this.customizedRender();
2381
+ if (el) {
2382
+ this.nativeContainer.appendChild(el);
2383
+ }
2384
+ }
2385
+ }
2324
2386
  /**
2325
2387
  * 在runtime中对被选中的元素进行标记,部分组件有对选中态进行特殊显示的需求
2326
2388
  * @param el 被选中的元素
@@ -2332,7 +2394,7 @@
2332
2394
  addSelectedClassName(el, doc);
2333
2395
  }
2334
2396
  }
2335
- loadHandler = async () => {
2397
+ iframeLoadHandler = async () => {
2336
2398
  if (!this.contentWindow?.magic) {
2337
2399
  this.postTmagicRuntimeReady();
2338
2400
  }
@@ -2374,6 +2436,7 @@
2374
2436
  this.renderer = new StageRender({
2375
2437
  runtimeUrl: config.runtimeUrl,
2376
2438
  zoom: config.zoom,
2439
+ renderType: config.renderType,
2377
2440
  customizedRender: async () => {
2378
2441
  if (this?.customizedRender) {
2379
2442
  return await this.customizedRender(this);
@@ -2381,7 +2444,9 @@
2381
2444
  return null;
2382
2445
  }
2383
2446
  });
2384
- this.mask = new StageMask();
2447
+ this.mask = new StageMask({
2448
+ guidesOptions: config.guidesOptions
2449
+ });
2385
2450
  this.actionManager = new ActionManager(this.getActionManagerConfig(config));
2386
2451
  this.initRenderEvent();
2387
2452
  this.initActionEvent();
@@ -2502,6 +2567,12 @@
2502
2567
  getDragStatus() {
2503
2568
  return this.actionManager.getDragStatus();
2504
2569
  }
2570
+ disableMultiSelect() {
2571
+ this.actionManager.disableMultiSelect();
2572
+ }
2573
+ enableMultiSelect() {
2574
+ this.actionManager.enableMultiSelect();
2575
+ }
2505
2576
  /**
2506
2577
  * 销毁实例
2507
2578
  */
@@ -2534,6 +2605,7 @@
2534
2605
  moveableOptions: config.moveableOptions,
2535
2606
  container: this.mask.content,
2536
2607
  disabledDragStart: config.disabledDragStart,
2608
+ disabledMultiSelect: config.disabledMultiSelect,
2537
2609
  canSelect: config.canSelect,
2538
2610
  isContainer: config.isContainer,
2539
2611
  updateDragEl: config.updateDragEl,
@@ -2551,6 +2623,7 @@
2551
2623
  this.renderer.on("page-el-update", (el) => {
2552
2624
  this.mask?.observe(el);
2553
2625
  this.observePageResize(el);
2626
+ this.emit("page-el-update", el);
2554
2627
  });
2555
2628
  }
2556
2629
  initMaskEvent() {
@@ -2575,12 +2648,12 @@
2575
2648
  initActionManagerEvent() {
2576
2649
  this.actionManager.on("before-select", (idOrEl, event) => {
2577
2650
  this.select(idOrEl, event);
2578
- }).on("select", (selectedEl) => {
2579
- this.emit("select", selectedEl);
2651
+ }).on("select", (selectedEl, event) => {
2652
+ this.emit("select", selectedEl, event);
2580
2653
  }).on("before-multi-select", (idOrElList) => {
2581
2654
  this.multiSelect(idOrElList);
2582
- }).on("multi-select", (selectedElList) => {
2583
- this.emit("multi-select", selectedElList);
2655
+ }).on("multi-select", (selectedElList, event) => {
2656
+ this.emit("multi-select", selectedElList, event);
2584
2657
  });
2585
2658
  }
2586
2659
  /**
@@ -2641,6 +2714,7 @@
2641
2714
  exports.Mode = Mode;
2642
2715
  exports.MouseButton = MouseButton;
2643
2716
  exports.PAGE_CLASS = PAGE_CLASS;
2717
+ exports.RenderType = RenderType;
2644
2718
  exports.SELECTED_CLASS = SELECTED_CLASS;
2645
2719
  exports.SelectStatus = SelectStatus;
2646
2720
  exports.StageDragResize = StageDragResize;