@tmagic/stage 1.5.0-beta.1 → 1.5.0-beta.11

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.
@@ -175,7 +175,7 @@
175
175
  let swapIndex = 0;
176
176
  let addUpH = target.clientHeight;
177
177
  const brothers = Array.from(target.parentNode?.children || []).filter(
178
- (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX)
178
+ (child) => !utils.getIdFromEl()(child)?.startsWith(GHOST_EL_ID_PREFIX)
179
179
  );
180
180
  const index = brothers.indexOf(target);
181
181
  const downEls = brothers.slice(index + 1);
@@ -191,14 +191,15 @@
191
191
  addUpH += ele.clientHeight / 2;
192
192
  swapIndex = i;
193
193
  }
194
+ const src = utils.getIdFromEl()(target) || "";
194
195
  return {
195
- src: target.id,
196
- dist: downEls.length && swapIndex > -1 ? downEls[swapIndex].id : target.id
196
+ src,
197
+ dist: downEls.length && swapIndex > -1 ? utils.getIdFromEl()(downEls[swapIndex]) || "" : src
197
198
  };
198
199
  };
199
200
  const up = (deltaTop, target) => {
200
201
  const brothers = Array.from(target.parentNode?.children || []).filter(
201
- (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX)
202
+ (child) => !utils.getIdFromEl()(child)?.startsWith(GHOST_EL_ID_PREFIX)
202
203
  );
203
204
  const index = brothers.indexOf(target);
204
205
  const upEls = brothers.slice(0, index);
@@ -213,9 +214,10 @@
213
214
  addUpH += ele.clientHeight / 2;
214
215
  swapIndex = i;
215
216
  }
217
+ const src = utils.getIdFromEl()(target) || "";
216
218
  return {
217
- src: target.id,
218
- dist: upEls.length && swapIndex > -1 ? upEls[swapIndex].id : target.id
219
+ src,
220
+ dist: upEls.length && swapIndex > -1 ? utils.getIdFromEl()(upEls[swapIndex]) || "" : src
219
221
  };
220
222
  };
221
223
  const isMoveableButton = (target) => target.classList.contains("moveable-button") || target.parentElement?.classList.contains("moveable-button");
@@ -325,12 +327,11 @@
325
327
  };
326
328
  }
327
329
 
328
- const getId = utils.getIdFromEl();
329
330
  class DragResizeHelper {
330
331
  /** 目标节点在蒙层上的占位节点,用于跟鼠标交互,避免鼠标事件直接作用到目标节点 */
331
332
  targetShadow;
332
333
  /** 要操作的原始目标节点 */
333
- target;
334
+ target = null;
334
335
  /** 多选:目标节点组 */
335
336
  targetList = [];
336
337
  /** 响应拖拽的状态事件,修改绝对定位布局下targetShadow的dom。
@@ -361,6 +362,8 @@
361
362
  });
362
363
  }
363
364
  destroy() {
365
+ this.target = null;
366
+ this.targetList = [];
364
367
  this.targetShadow.destroy();
365
368
  this.destroyGhostEl();
366
369
  this.moveableHelper.clear();
@@ -483,14 +486,16 @@
483
486
  events.forEach((ev) => {
484
487
  const { width, height, beforeTranslate } = ev.drag;
485
488
  const frameSnapShot = this.framesSnapShot.find(
486
- (frameItem) => frameItem.id === getId(ev.target)?.replace(DRAG_EL_ID_PREFIX, "")
489
+ (frameItem) => frameItem.id === utils.getIdFromEl()(ev.target)?.replace(DRAG_EL_ID_PREFIX, "")
487
490
  );
488
491
  if (!frameSnapShot) return;
489
492
  const targeEl = this.targetList.find(
490
- (targetItem) => targetItem.id === getId(ev.target)?.replace(DRAG_EL_ID_PREFIX, "")
493
+ (targetItem) => utils.getIdFromEl()(targetItem) === utils.getIdFromEl()(ev.target)?.replace(DRAG_EL_ID_PREFIX, "")
491
494
  );
492
495
  if (!targeEl) return;
493
- const isParentIncluded = this.targetList.find((targetItem) => getId(targetItem) === getId(targeEl.parentElement));
496
+ const isParentIncluded = this.targetList.find(
497
+ (targetItem) => utils.getIdFromEl()(targetItem) === utils.getIdFromEl()(targeEl.parentElement)
498
+ );
494
499
  if (!isParentIncluded) {
495
500
  const { marginLeft, marginTop } = getMarginValue(targeEl);
496
501
  targeEl.style.left = `${frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
@@ -510,14 +515,16 @@
510
515
  const { events } = e;
511
516
  events.forEach((ev) => {
512
517
  const frameSnapShot = this.framesSnapShot.find(
513
- (frameItem) => getId(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getId(ev.target)?.endsWith(frameItem.id)
518
+ (frameItem) => utils.getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && utils.getIdFromEl()(ev.target)?.endsWith(frameItem.id)
514
519
  );
515
520
  if (!frameSnapShot) return;
516
521
  const targeEl = this.targetList.find(
517
- (targetItem) => getId(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getId(targetItem) && getId(ev.target)?.endsWith(getId(targetItem))
522
+ (targetItem) => utils.getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && utils.getIdFromEl()(targetItem) && utils.getIdFromEl()(ev.target)?.endsWith(utils.getIdFromEl()(targetItem))
518
523
  );
519
524
  if (!targeEl) return;
520
- const isParentIncluded = this.targetList.find((targetItem) => getId(targetItem) === getId(targeEl.parentElement));
525
+ const isParentIncluded = this.targetList.find(
526
+ (targetItem) => utils.getIdFromEl()(targetItem) === utils.getIdFromEl()(targeEl.parentElement)
527
+ );
521
528
  if (!isParentIncluded) {
522
529
  const { marginLeft, marginTop } = getMarginValue(targeEl);
523
530
  targeEl.style.left = `${frameSnapShot.left + ev.beforeTranslate[0] - marginLeft}px`;
@@ -536,7 +543,7 @@
536
543
  let shadowEl = this.getShadowEl();
537
544
  const shadowEls = this.getShadowEls();
538
545
  if (shadowEls.length) {
539
- shadowEl = shadowEls.find((item) => getId(item)?.endsWith(getId(el) || ""));
546
+ shadowEl = shadowEls.find((item) => utils.getIdFromEl()(item)?.endsWith(utils.getIdFromEl()(el) || ""));
540
547
  }
541
548
  if (parentEl && this.mode === Mode.ABSOLUTE && shadowEl) {
542
549
  const targetShadowHtmlEl = shadowEl;
@@ -557,10 +564,10 @@
557
564
  if (this.framesSnapShot.length > 0) return;
558
565
  events.forEach((ev) => {
559
566
  const matchEventTarget = this.targetList.find(
560
- (targetItem) => getId(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && getId(ev.target)?.endsWith(getId(targetItem) || "")
567
+ (targetItem) => utils.getIdFromEl()(ev.target)?.startsWith(DRAG_EL_ID_PREFIX) && utils.getIdFromEl()(ev.target)?.endsWith(utils.getIdFromEl()(targetItem) || "")
561
568
  );
562
569
  if (!matchEventTarget) return;
563
- const id = getId(matchEventTarget);
570
+ const id = utils.getIdFromEl()(matchEventTarget);
564
571
  id && this.framesSnapShot.push({
565
572
  left: matchEventTarget.offsetLeft,
566
573
  top: matchEventTarget.offsetTop,
@@ -575,24 +582,27 @@
575
582
  if (this.ghostEl) {
576
583
  this.destroyGhostEl();
577
584
  }
578
- const ghostEl = el.cloneNode(true);
579
- this.setGhostElChildrenId(ghostEl);
585
+ const ghostEl = document.createElement("div");
580
586
  const { top, left } = getAbsolutePosition(el, getOffset(el));
581
- utils.setIdToEl()(ghostEl, `${GHOST_EL_ID_PREFIX}${getId(el)}`);
582
- ghostEl.style.zIndex = ZIndex.GHOST_EL;
583
- ghostEl.style.opacity = ".5";
584
- ghostEl.style.position = "absolute";
585
- ghostEl.style.left = `${left}px`;
586
- ghostEl.style.top = `${top}px`;
587
- ghostEl.style.marginLeft = "0";
588
- ghostEl.style.marginTop = "0";
587
+ utils.setIdToEl()(ghostEl, `${GHOST_EL_ID_PREFIX}${utils.getIdFromEl()(el)}`);
588
+ ghostEl.style.cssText = `
589
+ z-index: ${ZIndex.GHOST_EL};
590
+ opacity: .6;
591
+ position: absolute;
592
+ left: ${left}px;
593
+ top: ${top}px;
594
+ margin: 0;
595
+ background: blue;
596
+ width: ${el.clientWidth}px;
597
+ height: ${el.clientHeight}px;
598
+ `;
589
599
  el.after(ghostEl);
590
600
  return ghostEl;
591
601
  }
592
602
  setGhostElChildrenId(el) {
593
603
  for (const child of Array.from(el.children)) {
594
604
  const el2 = child;
595
- const id = getId(el2);
605
+ const id = utils.getIdFromEl()(el2);
596
606
  if (id) {
597
607
  utils.setIdToEl()(el2, `${GHOST_EL_ID_PREFIX}${id}`);
598
608
  }
@@ -605,9 +615,10 @@
605
615
 
606
616
  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";
607
617
 
608
- const MoveableActionsAble = (handler) => ({
618
+ const MoveableActionsAble = (handler, customizedButton = []) => ({
609
619
  name: "actions",
610
620
  props: [],
621
+ always: true,
611
622
  events: [],
612
623
  render(moveable, React) {
613
624
  const rect = moveable.getRect();
@@ -631,10 +642,14 @@
631
642
  {
632
643
  className: "moveable-editable",
633
644
  style: {
634
- transform: `translate(${pos2[0] - 60}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg)`
645
+ transform: `translate(${pos2[0] - (customizedButton.length + 3) * 20}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg)`
635
646
  }
636
647
  },
637
648
  [
649
+ ...customizedButton.map((buttonRenderer) => {
650
+ const options = buttonRenderer(React);
651
+ return React.createElement("button", options.props || {}, ...options.children || []);
652
+ }),
638
653
  React.createElement(
639
654
  "button",
640
655
  {
@@ -756,7 +771,7 @@
756
771
  */
757
772
  getOptions(isMultiSelect, runtimeOptions = {}) {
758
773
  const defaultOptions = this.getDefaultOptions(isMultiSelect);
759
- const customizedOptions = this.getCustomizeOptions();
774
+ const customizedOptions = this.getCustomizeOptions() || {};
760
775
  this.options = lodashEs.merge(defaultOptions, customizedOptions, runtimeOptions);
761
776
  return this.options;
762
777
  }
@@ -967,6 +982,7 @@
967
982
  * 销毁实例
968
983
  */
969
984
  destroy() {
985
+ this.target = null;
970
986
  this.moveable?.destroy();
971
987
  this.dragResizeHelper.destroy();
972
988
  this.dragStatus = StageDragStatus.END;
@@ -1198,6 +1214,7 @@
1198
1214
  * 销毁实例
1199
1215
  */
1200
1216
  destroy() {
1217
+ this.target = void 0;
1201
1218
  this.moveable?.destroy();
1202
1219
  this.targetShadow?.destroy();
1203
1220
  this.moveable = void 0;
@@ -1366,9 +1383,9 @@
1366
1383
  const throttleTime = 100;
1367
1384
  const defaultContainerHighlightDuration = 800;
1368
1385
  class ActionManager extends EventEmitter {
1369
- dr;
1370
- multiDr;
1371
- highlightLayer;
1386
+ dr = null;
1387
+ multiDr = null;
1388
+ highlightLayer = null;
1372
1389
  /** 单选、多选、高亮的容器(蒙层的content) */
1373
1390
  container;
1374
1391
  /** 当前选中的节点 */
@@ -1435,7 +1452,7 @@
1435
1452
  this.disabledMultiSelect = true;
1436
1453
  if (this.multiDr) {
1437
1454
  this.multiDr.destroy();
1438
- this.multiDr = void 0;
1455
+ this.multiDr = null;
1439
1456
  }
1440
1457
  }
1441
1458
  enableMultiSelect() {
@@ -1450,14 +1467,14 @@
1450
1467
  * @param guidelines 参考线坐标数组
1451
1468
  */
1452
1469
  setGuidelines(type, guidelines) {
1453
- this.dr.setGuidelines(type, guidelines);
1470
+ this.dr?.setGuidelines(type, guidelines);
1454
1471
  this.multiDr?.setGuidelines(type, guidelines);
1455
1472
  }
1456
1473
  /**
1457
1474
  * 清空所有参考线
1458
1475
  */
1459
1476
  clearGuides() {
1460
- this.dr.clearGuides();
1477
+ this.dr?.clearGuides();
1461
1478
  this.multiDr?.clearGuides();
1462
1479
  }
1463
1480
  /**
@@ -1465,7 +1482,7 @@
1465
1482
  * @param el 变更的元素
1466
1483
  */
1467
1484
  updateMoveable(el) {
1468
- this.dr.updateMoveable(el);
1485
+ this.dr?.updateMoveable(el);
1469
1486
  this.multiDr?.updateMoveable();
1470
1487
  }
1471
1488
  /**
@@ -1484,7 +1501,7 @@
1484
1501
  return this.selectedElList;
1485
1502
  }
1486
1503
  getMoveableOption(key) {
1487
- if (this.dr.getTarget()) {
1504
+ if (this.dr?.getTarget()) {
1488
1505
  return this.dr.getOption(key);
1489
1506
  }
1490
1507
  if (this.multiDr?.targetList.length) {
@@ -1541,7 +1558,7 @@
1541
1558
  select(el, event) {
1542
1559
  this.setSelectedEl(el);
1543
1560
  this.clearSelectStatus(SelectStatus.MULTI_SELECT);
1544
- this.dr.select(el, event);
1561
+ this.dr?.select(el, event);
1545
1562
  }
1546
1563
  multiSelect(ids) {
1547
1564
  this.selectedElList = [];
@@ -1573,13 +1590,13 @@
1573
1590
  return;
1574
1591
  }
1575
1592
  if (el === this.highlightedEl || !el) return;
1576
- this.highlightLayer.highlight(el);
1593
+ this.highlightLayer?.highlight(el);
1577
1594
  this.highlightedEl = el;
1578
1595
  this.emit("highlight", el);
1579
1596
  }
1580
1597
  clearHighlight() {
1581
1598
  this.setHighlightEl(void 0);
1582
- this.highlightLayer.clearHighlight();
1599
+ this.highlightLayer?.clearHighlight();
1583
1600
  }
1584
1601
  /**
1585
1602
  * 用于在切换选择模式时清除上一次的状态
@@ -1590,7 +1607,7 @@
1590
1607
  this.multiDr?.clearSelectStatus();
1591
1608
  this.selectedElList = [];
1592
1609
  } else {
1593
- this.dr.clearSelectStatus();
1610
+ this.dr?.clearSelectStatus();
1594
1611
  }
1595
1612
  }
1596
1613
  /**
@@ -1625,7 +1642,7 @@
1625
1642
  return void 0;
1626
1643
  }
1627
1644
  getDragStatus() {
1628
- return this.dr.getDragStatus();
1645
+ return this.dr?.getDragStatus();
1629
1646
  }
1630
1647
  destroy() {
1631
1648
  this.container.removeEventListener("mousedown", this.mouseDownHandler);
@@ -1633,9 +1650,14 @@
1633
1650
  this.container.removeEventListener("mouseleave", this.mouseLeaveHandler);
1634
1651
  this.container.removeEventListener("wheel", this.mouseWheelHandler);
1635
1652
  this.container.removeEventListener("dblclick", this.dblclickHandler);
1636
- this.dr.destroy();
1653
+ this.selectedEl = null;
1654
+ this.selectedElList = [];
1655
+ this.dr?.destroy();
1637
1656
  this.multiDr?.destroy();
1638
- this.highlightLayer.destroy();
1657
+ this.highlightLayer?.destroy();
1658
+ this.dr = null;
1659
+ this.multiDr = null;
1660
+ this.highlightLayer = null;
1639
1661
  }
1640
1662
  on(eventName, listener) {
1641
1663
  return super.on(eventName, listener);
@@ -1665,7 +1687,7 @@
1665
1687
  }).on(AbleActionEventType.SELECT_PARENT, () => {
1666
1688
  this.emit("select-parent");
1667
1689
  }).on(AbleActionEventType.REMOVE, () => {
1668
- const drTarget = this.dr.getTarget();
1690
+ const drTarget = this.dr?.getTarget();
1669
1691
  if (!drTarget) return;
1670
1692
  const data = {
1671
1693
  data: [{ el: drTarget }]
@@ -2358,6 +2380,16 @@
2358
2380
  getTargetElement(id) {
2359
2381
  return utils.getElById()(this.getDocument(), id);
2360
2382
  }
2383
+ postTmagicRuntimeReady() {
2384
+ this.contentWindow = this.iframe?.contentWindow;
2385
+ this.contentWindow.magic = this.getMagicApi();
2386
+ this.contentWindow.postMessage(
2387
+ {
2388
+ tmagicRuntimeReady: true
2389
+ },
2390
+ "*"
2391
+ );
2392
+ }
2361
2393
  /**
2362
2394
  * 销毁实例
2363
2395
  */
@@ -2421,23 +2453,13 @@
2421
2453
  this.emit("onload");
2422
2454
  utils.injectStyle(this.contentWindow.document, style);
2423
2455
  };
2424
- postTmagicRuntimeReady() {
2425
- this.contentWindow = this.iframe?.contentWindow;
2426
- this.contentWindow.magic = this.getMagicApi();
2427
- this.contentWindow.postMessage(
2428
- {
2429
- tmagicRuntimeReady: true
2430
- },
2431
- "*"
2432
- );
2433
- }
2434
2456
  }
2435
2457
 
2436
2458
  class StageCore extends EventEmitter.EventEmitter {
2437
2459
  container;
2438
- renderer;
2439
- mask;
2440
- actionManager;
2460
+ renderer = null;
2461
+ mask = null;
2462
+ actionManager = null;
2441
2463
  pageResizeObserver = null;
2442
2464
  autoScrollIntoView;
2443
2465
  customizedRender;
@@ -2469,13 +2491,15 @@
2469
2491
  * @param id 选中的id
2470
2492
  */
2471
2493
  async select(id, event) {
2472
- const el = this.renderer.getTargetElement(id);
2473
- if (el === this.actionManager.getSelectedEl()) return;
2474
- await this.renderer.select([id]);
2475
- el && this.mask.setLayout(el);
2476
- this.actionManager.select(el, event);
2494
+ const el = this.renderer?.getTargetElement(id) || null;
2495
+ if (el === this.actionManager?.getSelectedEl()) return;
2496
+ await this.renderer?.select([id]);
2497
+ if (el) {
2498
+ this.mask?.setLayout(el);
2499
+ }
2500
+ this.actionManager?.select(el, event);
2477
2501
  if (el && (this.autoScrollIntoView || el.dataset.autoScrollIntoView)) {
2478
- this.mask.observerIntersection(el);
2502
+ this.mask?.observerIntersection(el);
2479
2503
  }
2480
2504
  }
2481
2505
  /**
@@ -2483,15 +2507,15 @@
2483
2507
  * @param ids 选中元素的id列表
2484
2508
  */
2485
2509
  async multiSelect(ids) {
2486
- const els = ids.map((id) => this.renderer.getTargetElement(id)).filter((el) => Boolean(el));
2510
+ const els = ids.map((id) => this.renderer?.getTargetElement(id)).filter((el) => Boolean(el));
2487
2511
  if (els.length === 0) return;
2488
2512
  const lastEl = els[els.length - 1];
2489
2513
  const isReduceSelect = els.length < this.actionManager.getSelectedElList().length;
2490
- await this.renderer.select(ids);
2491
- lastEl && this.mask.setLayout(lastEl);
2492
- this.actionManager.multiSelect(ids);
2514
+ await this.renderer?.select(ids);
2515
+ lastEl && this.mask?.setLayout(lastEl);
2516
+ this.actionManager?.multiSelect(ids);
2493
2517
  if (lastEl && (this.autoScrollIntoView || lastEl.dataset.autoScrollIntoView) && !isReduceSelect) {
2494
- this.mask.observerIntersection(lastEl);
2518
+ this.mask?.observerIntersection(lastEl);
2495
2519
  }
2496
2520
  }
2497
2521
  /**
@@ -2499,10 +2523,10 @@
2499
2523
  * @param el 要高亮的元素
2500
2524
  */
2501
2525
  highlight(id) {
2502
- this.actionManager.highlight(id);
2526
+ this.actionManager?.highlight(id);
2503
2527
  }
2504
2528
  clearHighlight() {
2505
- this.actionManager.clearHighlight();
2529
+ this.actionManager?.clearHighlight();
2506
2530
  }
2507
2531
  /**
2508
2532
  * 更新组件
@@ -2510,11 +2534,11 @@
2510
2534
  */
2511
2535
  async update(data) {
2512
2536
  const { config } = data;
2513
- await this.renderer.update(data);
2537
+ await this.renderer?.update(data);
2514
2538
  setTimeout(() => {
2515
- const el = this.renderer.getTargetElement(`${config.id}`);
2516
- if (el && this.actionManager.isSelectedEl(el)) {
2517
- this.mask.setLayout(el);
2539
+ const el = this.renderer?.getTargetElement(`${config.id}`);
2540
+ if (el && this.actionManager?.isSelectedEl(el)) {
2541
+ this.mask?.setLayout(el);
2518
2542
  this.actionManager.setSelectedEl(el);
2519
2543
  this.actionManager.updateMoveable(el);
2520
2544
  }
@@ -2525,17 +2549,17 @@
2525
2549
  * @param data 组件信息数据
2526
2550
  */
2527
2551
  async add(data) {
2528
- return await this.renderer.add(data);
2552
+ return await this.renderer?.add(data);
2529
2553
  }
2530
2554
  /**
2531
2555
  * 从画布删除一个组件
2532
2556
  * @param data 组件信息数据
2533
2557
  */
2534
2558
  async remove(data) {
2535
- return await this.renderer.remove(data);
2559
+ return await this.renderer?.remove(data);
2536
2560
  }
2537
2561
  setZoom(zoom = DEFAULT_ZOOM) {
2538
- this.renderer.setZoom(zoom);
2562
+ this.renderer?.setZoom(zoom);
2539
2563
  }
2540
2564
  /**
2541
2565
  * 挂载Dom节点
@@ -2544,16 +2568,16 @@
2544
2568
  async mount(el) {
2545
2569
  this.container = el;
2546
2570
  const { mask, renderer } = this;
2547
- await renderer.mount(el);
2548
- mask.mount(el);
2571
+ await renderer?.mount(el);
2572
+ mask?.mount(el);
2549
2573
  this.emit("mounted");
2550
2574
  }
2551
2575
  /**
2552
2576
  * 清空所有参考线
2553
2577
  */
2554
2578
  clearGuides() {
2555
- this.mask.clearGuides();
2556
- this.actionManager.clearGuides();
2579
+ this.mask?.clearGuides();
2580
+ this.actionManager?.clearGuides();
2557
2581
  }
2558
2582
  /**
2559
2583
  * @deprecated 废弃接口,建议用delayedMarkContainer代替
@@ -2569,31 +2593,35 @@
2569
2593
  * @returns timeoutId,调用方在鼠标移走时要取消该timeout,阻止标记
2570
2594
  */
2571
2595
  delayedMarkContainer(event, excludeElList = []) {
2572
- return this.actionManager.delayedMarkContainer(event, excludeElList);
2596
+ return this.actionManager?.delayedMarkContainer(event, excludeElList);
2573
2597
  }
2574
2598
  getMoveableOption(key) {
2575
- return this.actionManager.getMoveableOption(key);
2599
+ return this.actionManager?.getMoveableOption(key);
2576
2600
  }
2577
2601
  getDragStatus() {
2578
- return this.actionManager.getDragStatus();
2602
+ return this.actionManager?.getDragStatus();
2579
2603
  }
2580
2604
  disableMultiSelect() {
2581
- this.actionManager.disableMultiSelect();
2605
+ this.actionManager?.disableMultiSelect();
2582
2606
  }
2583
2607
  enableMultiSelect() {
2584
- this.actionManager.enableMultiSelect();
2608
+ this.actionManager?.enableMultiSelect();
2585
2609
  }
2586
2610
  /**
2587
2611
  * 销毁实例
2588
2612
  */
2589
2613
  destroy() {
2590
2614
  const { mask, renderer, actionManager, pageResizeObserver } = this;
2591
- renderer.destroy();
2592
- mask.destroy();
2593
- actionManager.destroy();
2615
+ renderer?.destroy();
2616
+ mask?.destroy();
2617
+ actionManager?.destroy();
2594
2618
  pageResizeObserver?.disconnect();
2595
2619
  this.removeAllListeners();
2596
2620
  this.container = void 0;
2621
+ this.renderer = null;
2622
+ this.mask = null;
2623
+ this.actionManager = null;
2624
+ this.pageResizeObserver = null;
2597
2625
  }
2598
2626
  on(eventName, listener) {
2599
2627
  return super.on(eventName, listener);
@@ -2610,8 +2638,8 @@
2610
2638
  }
2611
2639
  if (typeof ResizeObserver !== "undefined") {
2612
2640
  this.pageResizeObserver = new ResizeObserver((entries) => {
2613
- this.mask.pageResize(entries);
2614
- this.actionManager.updateMoveable();
2641
+ this.mask?.pageResize(entries);
2642
+ this.actionManager?.updateMoveable();
2615
2643
  });
2616
2644
  this.pageResizeObserver.observe(page);
2617
2645
  }
@@ -2636,18 +2664,18 @@
2636
2664
  return actionManagerConfig;
2637
2665
  }
2638
2666
  initRenderEvent() {
2639
- this.renderer.on("runtime-ready", (runtime) => {
2667
+ this.renderer?.on("runtime-ready", (runtime) => {
2640
2668
  this.emit("runtime-ready", runtime);
2641
2669
  });
2642
- this.renderer.on("page-el-update", (el) => {
2670
+ this.renderer?.on("page-el-update", (el) => {
2643
2671
  this.mask?.observe(el);
2644
2672
  this.observePageResize(el);
2645
2673
  this.emit("page-el-update", el);
2646
2674
  });
2647
2675
  }
2648
2676
  initMaskEvent() {
2649
- this.mask.on("change-guides", (data) => {
2650
- this.actionManager.setGuidelines(data.type, data.guides);
2677
+ this.mask?.on("change-guides", (data) => {
2678
+ this.actionManager?.setGuidelines(data.type, data.guides);
2651
2679
  this.emit("change-guides", data);
2652
2680
  });
2653
2681
  }
@@ -2665,7 +2693,7 @@
2665
2693
  * 初始化ActionManager类本身抛出来的事件监听
2666
2694
  */
2667
2695
  initActionManagerEvent() {
2668
- this.actionManager.on("before-select", (el, event) => {
2696
+ this.actionManager?.on("before-select", (el, event) => {
2669
2697
  const id = utils.getIdFromEl()(el);
2670
2698
  id && this.select(id, event);
2671
2699
  }).on("select", (selectedEl, event) => {
@@ -2682,7 +2710,7 @@
2682
2710
  * 初始化DragResize类通过ActionManager抛出来的事件监听
2683
2711
  */
2684
2712
  initDrEvent() {
2685
- this.actionManager.on("update", (data) => {
2713
+ this.actionManager?.on("update", (data) => {
2686
2714
  this.emit("update", data);
2687
2715
  }).on("sort", (data) => {
2688
2716
  this.emit("sort", data);
@@ -2696,10 +2724,10 @@
2696
2724
  * 初始化MultiDragResize类通过ActionManager抛出来的事件监听
2697
2725
  */
2698
2726
  initMulDrEvent() {
2699
- this.actionManager.on("change-to-select", (id, e) => {
2727
+ this.actionManager?.on("change-to-select", (id, e) => {
2700
2728
  this.select(id);
2701
2729
  setTimeout(() => {
2702
- const el = this.renderer.getTargetElement(id);
2730
+ const el = this.renderer?.getTargetElement(id);
2703
2731
  el && this.emit("select", el, e);
2704
2732
  });
2705
2733
  }).on("multi-update", (data) => {
@@ -2710,7 +2738,7 @@
2710
2738
  * 初始化Highlight类通过ActionManager抛出来的事件监听
2711
2739
  */
2712
2740
  initHighlightEvent() {
2713
- this.actionManager.on("highlight", (highlightEl) => {
2741
+ this.actionManager?.on("highlight", (highlightEl) => {
2714
2742
  this.emit("highlight", highlightEl);
2715
2743
  });
2716
2744
  }
@@ -2718,7 +2746,7 @@
2718
2746
  * 初始化Highlight类通过ActionManager抛出来的事件监听
2719
2747
  */
2720
2748
  initMouseEvent() {
2721
- this.actionManager.on("mousemove", (event) => {
2749
+ this.actionManager?.on("mousemove", (event) => {
2722
2750
  this.emit("mousemove", event);
2723
2751
  }).on("mouseleave", (event) => {
2724
2752
  this.emit("mouseleave", event);
@@ -2738,6 +2766,7 @@
2738
2766
  exports.HIGHLIGHT_EL_ID_PREFIX = HIGHLIGHT_EL_ID_PREFIX;
2739
2767
  exports.Mode = Mode;
2740
2768
  exports.MouseButton = MouseButton;
2769
+ exports.MoveableActionsAble = MoveableActionsAble;
2741
2770
  exports.PAGE_CLASS = PAGE_CLASS;
2742
2771
  exports.RenderType = RenderType;
2743
2772
  exports.SELECTED_CLASS = SELECTED_CLASS;
@@ -2765,6 +2794,12 @@
2765
2794
  exports.isStatic = isStatic;
2766
2795
  exports.removeSelectedClassName = removeSelectedClassName;
2767
2796
  exports.up = up;
2797
+ Object.keys(Moveable).forEach(k => {
2798
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
2799
+ enumerable: true,
2800
+ get: () => Moveable[k]
2801
+ });
2802
+ });
2768
2803
 
2769
2804
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2770
2805
 
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.0-beta.1",
2
+ "version": "1.5.0-beta.11",
3
3
  "name": "@tmagic/stage",
4
4
  "type": "module",
5
5
  "main": "dist/tmagic-stage.umd.cjs",
@@ -40,14 +40,14 @@
40
40
  "@types/lodash-es": "^4.17.4",
41
41
  "@types/node": "^18.19.0",
42
42
  "rimraf": "^3.0.2",
43
- "sass": "^1.77.0",
44
- "vite": "^5.3.5"
43
+ "sass": "^1.78.0",
44
+ "vite": "^5.4.3"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "typescript": "*",
48
- "@tmagic/utils": "1.5.0-beta.1",
49
- "@tmagic/core": "1.5.0-beta.1",
50
- "@tmagic/schema": "1.5.0-beta.1"
48
+ "@tmagic/core": "1.5.0-beta.11",
49
+ "@tmagic/utils": "1.5.0-beta.11",
50
+ "@tmagic/schema": "1.5.0-beta.11"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "typescript": {