@tmagic/stage 1.8.0-beta.1 → 1.8.0-beta.10

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.
@@ -1,5 +1,6 @@
1
1
  import "./const.js";
2
2
  import ActionManager from "./ActionManager.js";
3
+ import StageFlashHighlight from "./StageFlashHighlight.js";
3
4
  import StageMask from "./StageMask.js";
4
5
  import StageRender from "./StageRender.js";
5
6
  import { EventEmitter } from "events";
@@ -13,13 +14,17 @@ var StageCore = class extends EventEmitter {
13
14
  renderer = null;
14
15
  mask = null;
15
16
  actionManager = null;
17
+ flashHighlight = null;
16
18
  pageResizeObserver = null;
17
19
  autoScrollIntoView;
18
20
  customizedRender;
21
+ /** 非点击画布选中组件时,是否对选中区域做高亮闪烁提示,默认开启 */
22
+ disabledFlashTip;
19
23
  constructor(config) {
20
24
  super();
21
25
  this.autoScrollIntoView = config.autoScrollIntoView;
22
26
  this.customizedRender = config.render;
27
+ this.disabledFlashTip = config.disabledFlashTip ?? false;
23
28
  this.renderer = new StageRender({
24
29
  runtimeUrl: config.runtimeUrl,
25
30
  zoom: config.zoom,
@@ -34,6 +39,10 @@ var StageCore = class extends EventEmitter {
34
39
  disabledRule: config.disabledRule
35
40
  });
36
41
  this.actionManager = new ActionManager(this.getActionManagerConfig(config));
42
+ this.flashHighlight = new StageFlashHighlight({
43
+ container: this.mask.content,
44
+ updateDragEl: config.updateDragEl
45
+ });
37
46
  this.initRenderEvent();
38
47
  this.initActionEvent();
39
48
  this.initMaskEvent();
@@ -42,7 +51,7 @@ var StageCore = class extends EventEmitter {
42
51
  * 单选选中元素
43
52
  * @param id 选中的id
44
53
  */
45
- async select(id, event) {
54
+ async select(id, event, options = {}) {
46
55
  if (!this.renderer) return;
47
56
  let el = this.renderer.getTargetElement(id) || null;
48
57
  if (!el) el = await new Promise((resolve) => {
@@ -73,6 +82,8 @@ var StageCore = class extends EventEmitter {
73
82
  if (el) this.mask?.setLayout(el);
74
83
  this.actionManager?.select(el, event);
75
84
  if (el && (this.autoScrollIntoView || el.dataset.autoScrollIntoView)) this.mask?.observerIntersection(el);
85
+ const isPage = el === this.mask?.page || el?.className.includes("magic-ui-page");
86
+ if (el && !event && options.flash !== false && !this.disabledFlashTip && !isPage) this.flashHighlight?.flash(el);
76
87
  }
77
88
  /**
78
89
  * 多选选中多个元素
@@ -198,16 +209,18 @@ var StageCore = class extends EventEmitter {
198
209
  * 销毁实例
199
210
  */
200
211
  destroy() {
201
- const { mask, renderer, actionManager, pageResizeObserver } = this;
212
+ const { mask, renderer, actionManager, flashHighlight, pageResizeObserver } = this;
202
213
  renderer?.destroy();
203
214
  mask?.destroy();
204
215
  actionManager?.destroy();
216
+ flashHighlight?.destroy();
205
217
  pageResizeObserver?.disconnect();
206
218
  this.removeAllListeners();
207
219
  this.container = void 0;
208
220
  this.renderer = null;
209
221
  this.mask = null;
210
222
  this.actionManager = null;
223
+ this.flashHighlight = null;
211
224
  this.pageResizeObserver = null;
212
225
  }
213
226
  on(eventName, listener) {
@@ -0,0 +1,102 @@
1
+ import { FLASH_EL_ID_PREFIX, ZIndex } from "./const.js";
2
+ import TargetShadow from "./TargetShadow.js";
3
+ import { getDocument, injectStyle } from "@tmagic/core";
4
+ //#region packages/stage/src/StageFlashHighlight.ts
5
+ /** 闪烁提示节点的 class name */
6
+ var FLASH_TIP_CLASS_NAME = "tmagic-stage-flash-tip";
7
+ /** 闪烁动画名称 */
8
+ var FLASH_ANIMATION_NAME = "tmagic-stage-flash";
9
+ /** 闪烁动画时长(ms) */
10
+ var FLASH_DURATION = 1500;
11
+ /**
12
+ * 选中区域闪烁提示
13
+ * @description 当组件不是通过点击画布选中(如从图层树、面包屑等外部选中)时,在画布上对选中区域做一次高亮闪烁,
14
+ * 帮助用户快速定位组件在画布中的位置。
15
+ */
16
+ var StageFlashHighlight = class {
17
+ /** 复用 TargetShadow 负责节点的定位校准(updateDragEl、fixed、滚动偏移等) */
18
+ targetShadow;
19
+ timer;
20
+ styleEl;
21
+ constructor(config) {
22
+ this.targetShadow = new TargetShadow({
23
+ container: config.container,
24
+ updateDragEl: config.updateDragEl,
25
+ zIndex: ZIndex.SELECTED_EL,
26
+ idPrefix: FLASH_EL_ID_PREFIX
27
+ });
28
+ }
29
+ /**
30
+ * 在目标元素所在区域做一次高亮闪烁
31
+ * @param el 选中组件的Dom节点元素
32
+ */
33
+ flash(el) {
34
+ if (!el) return;
35
+ this.injectStyle();
36
+ this.clear();
37
+ const flashEl = this.targetShadow.update(el);
38
+ flashEl.classList.add(FLASH_TIP_CLASS_NAME);
39
+ flashEl.style.boxSizing = "border-box";
40
+ flashEl.style.pointerEvents = "none";
41
+ flashEl.style.border = "";
42
+ this.timer = globalThis.setTimeout(() => {
43
+ this.clear();
44
+ }, FLASH_DURATION);
45
+ }
46
+ /**
47
+ * 清除闪烁节点
48
+ */
49
+ clear() {
50
+ if (this.timer) {
51
+ globalThis.clearTimeout(this.timer);
52
+ this.timer = void 0;
53
+ }
54
+ this.targetShadow.destroyEl();
55
+ }
56
+ /**
57
+ * 销毁实例
58
+ */
59
+ destroy() {
60
+ this.clear();
61
+ this.targetShadow.destroy();
62
+ this.styleEl?.remove();
63
+ this.styleEl = void 0;
64
+ }
65
+ /**
66
+ * 注入闪烁动画样式(仅注入一次)
67
+ */
68
+ injectStyle() {
69
+ if (this.styleEl) return;
70
+ this.styleEl = injectStyle(getDocument(), `
71
+ @keyframes ${FLASH_ANIMATION_NAME} {
72
+ 0% {
73
+ opacity: 0;
74
+ background-color: rgba(146, 84, 222, 0);
75
+ }
76
+ 20% {
77
+ opacity: 1;
78
+ background-color: rgba(146, 84, 222, 0.7);
79
+ }
80
+ 45% {
81
+ opacity: 0.6;
82
+ background-color: rgba(146, 84, 222, 0.4);
83
+ }
84
+ 70% {
85
+ opacity: 1;
86
+ background-color: rgba(146, 84, 222, 0.7);
87
+ }
88
+ 100% {
89
+ opacity: 0;
90
+ background-color: rgba(146, 84, 222, 0);
91
+ }
92
+ }
93
+ .${FLASH_TIP_CLASS_NAME} {
94
+ border: 2px solid #9254de;
95
+ border-radius: 2px;
96
+ animation: ${FLASH_ANIMATION_NAME} ${FLASH_DURATION}ms cubic-bezier(0.4, 0, 0.2, 1) both;
97
+ }
98
+ `);
99
+ }
100
+ };
101
+ //#endregion
102
+ export { StageFlashHighlight as default };
package/dist/es/const.js CHANGED
@@ -5,6 +5,8 @@ var GHOST_EL_ID_PREFIX = "ghost_el_";
5
5
  var DRAG_EL_ID_PREFIX = "drag_el_";
6
6
  /** 高亮时需要在蒙层中创建一个占位节点,该节点的id前缀 */
7
7
  var HIGHLIGHT_EL_ID_PREFIX = "highlight_el_";
8
+ /** 闪烁提示时需要在蒙层中创建一个占位节点,该节点的id前缀 */
9
+ var FLASH_EL_ID_PREFIX = "flash_el_";
8
10
  var CONTAINER_HIGHLIGHT_CLASS_NAME = "tmagic-stage-container-highlight";
9
11
  var PAGE_CLASS = "magic-ui-page";
10
12
  /** 默认放到缩小倍数 */
@@ -88,4 +90,4 @@ var StageDragStatus = /* @__PURE__ */ function(StageDragStatus) {
88
90
  return StageDragStatus;
89
91
  }({});
90
92
  //#endregion
91
- 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, RenderType, SELECTED_CLASS, SelectStatus, StageDragStatus, ZIndex };
93
+ export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, FLASH_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, RenderType, SELECTED_CLASS, SelectStatus, StageDragStatus, ZIndex };
package/dist/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { 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, RenderType, SELECTED_CLASS, SelectStatus, StageDragStatus, ZIndex } from "./const.js";
1
+ import { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, FLASH_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, PAGE_CLASS, RenderType, SELECTED_CLASS, SelectStatus, StageDragStatus, ZIndex } from "./const.js";
2
2
  import { addSelectedClassName, down, getAbsolutePosition, getBorderWidth, getMarginValue, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up } from "./util.js";
3
3
  import MoveableActionsAble_default from "./MoveableActionsAble.js";
4
4
  import StageDragResize from "./StageDragResize.js";
@@ -9,4 +9,4 @@ export * from "moveable";
9
9
  //#region packages/stage/src/index.ts
10
10
  var src_default = StageCore;
11
11
  //#endregion
12
- export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, MoveableActionsAble_default as MoveableActionsAble, PAGE_CLASS, RenderType, SELECTED_CLASS, SelectStatus, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, src_default as default, down, getAbsolutePosition, getBorderWidth, getMarginValue, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };
12
+ export { AbleActionEventType, CONTAINER_HIGHLIGHT_CLASS_NAME, ContainerHighlightType, DEFAULT_ZOOM, DRAG_EL_ID_PREFIX, FLASH_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, GuidesType, HIGHLIGHT_EL_ID_PREFIX, Mode, MouseButton, MoveableActionsAble_default as MoveableActionsAble, PAGE_CLASS, RenderType, SELECTED_CLASS, SelectStatus, StageDragResize, StageDragStatus, StageMask, StageRender, ZIndex, addSelectedClassName, src_default as default, down, getAbsolutePosition, getBorderWidth, getMarginValue, getMode, getOffset, getScrollParent, getTargetElStyle, isAbsolute, isFixed, isFixedParent, isMoveableButton, isRelative, isStatic, removeSelectedClassName, up };