@tmagic/stage 1.1.0-beta.1 → 1.1.0-beta.12

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.
@@ -0,0 +1,260 @@
1
+ /*
2
+ * Tencent is pleased to support the open source community by making TMagicEditor available.
3
+ *
4
+ * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ import { EventEmitter } from 'events';
20
+
21
+ import type { MoveableOptions } from 'moveable';
22
+ import Moveable from 'moveable';
23
+ import MoveableHelper from 'moveable-helper';
24
+
25
+ import { DRAG_EL_ID_PREFIX, PAGE_CLASS } from './const';
26
+ import StageCore from './StageCore';
27
+ import StageMask from './StageMask';
28
+ import { StageDragResizeConfig, StageDragStatus } from './types';
29
+ import { calcValueByFontsize, getMode, getTargetElStyle } from './util';
30
+
31
+ export default class StageMultiDragResize extends EventEmitter {
32
+ public core: StageCore;
33
+ public mask: StageMask;
34
+ /** 画布容器 */
35
+ public container: HTMLElement;
36
+ /** 多选:目标节点组 */
37
+ public targetList: HTMLElement[] = [];
38
+ /** 多选:目标节点在蒙层中的占位节点组 */
39
+ public dragElList: HTMLDivElement[] = [];
40
+ /** Moveable多选拖拽类实例 */
41
+ public moveableForMulti?: Moveable;
42
+ /** 拖动状态 */
43
+ public dragStatus: StageDragStatus = StageDragStatus.END;
44
+ private multiMoveableHelper?: MoveableHelper;
45
+
46
+ constructor(config: StageDragResizeConfig) {
47
+ super();
48
+
49
+ this.core = config.core;
50
+ this.container = config.container;
51
+ this.mask = config.mask;
52
+ }
53
+
54
+ /**
55
+ * 多选
56
+ * @param els
57
+ */
58
+ public multiSelect(els: HTMLElement[]): void {
59
+ this.targetList = els;
60
+ this.core.dr.destroyDragEl();
61
+ this.destroyDragElList();
62
+ // 生成虚拟多选节点
63
+ this.dragElList = els.map((elItem) => {
64
+ const dragElDiv = globalThis.document.createElement('div');
65
+ this.container.append(dragElDiv);
66
+ dragElDiv.style.cssText = getTargetElStyle(elItem);
67
+ dragElDiv.id = `${DRAG_EL_ID_PREFIX}${elItem.id}`;
68
+ // 业务方校准
69
+ if (typeof this.core.config.updateDragEl === 'function') {
70
+ this.core.config.updateDragEl(dragElDiv, elItem);
71
+ }
72
+ return dragElDiv;
73
+ });
74
+ this.moveableForMulti?.destroy();
75
+ this.multiMoveableHelper?.clear();
76
+ this.moveableForMulti = new Moveable(
77
+ this.container,
78
+ this.getOptions({
79
+ target: this.dragElList,
80
+ }),
81
+ );
82
+ this.multiMoveableHelper = MoveableHelper.create({
83
+ useBeforeRender: true,
84
+ useRender: false,
85
+ createAuto: true,
86
+ });
87
+ const frames: { left: number; top: number; id: string }[] = [];
88
+ this.moveableForMulti
89
+ .on('dragGroupStart', (params) => {
90
+ const { events } = params;
91
+ this.multiMoveableHelper?.onDragGroupStart(params);
92
+ // 记录拖动前快照
93
+ events.forEach((ev) => {
94
+ // 实际目标元素
95
+ const matchEventTarget = this.targetList.find(
96
+ (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
97
+ );
98
+ if (!matchEventTarget) return;
99
+ frames.push({
100
+ left: matchEventTarget.offsetLeft,
101
+ top: matchEventTarget.offsetTop,
102
+ id: matchEventTarget.id,
103
+ });
104
+ });
105
+ this.dragStatus = StageDragStatus.START;
106
+ })
107
+ .on('dragGroup', (params) => {
108
+ const { events } = params;
109
+ // 拖动过程更新
110
+ events.forEach((ev) => {
111
+ const frameSnapShot = frames.find(
112
+ (frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
113
+ );
114
+ if (!frameSnapShot) return;
115
+ const targeEl = this.targetList.find(
116
+ (targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
117
+ );
118
+ if (!targeEl) return;
119
+ // 元素与其所属组同时加入多选列表时,只更新父元素
120
+ const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
121
+ if (!isParentIncluded) {
122
+ // 更新页面元素位置
123
+ targeEl.style.left = `${frameSnapShot.left + ev.beforeTranslate[0]}px`;
124
+ targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1]}px`;
125
+ }
126
+ });
127
+ this.multiMoveableHelper?.onDragGroup(params);
128
+ this.dragStatus = StageDragStatus.ING;
129
+ })
130
+ .on('dragGroupEnd', () => {
131
+ this.update();
132
+ this.dragStatus = StageDragStatus.END;
133
+ })
134
+ .on('clickGroup', (params) => {
135
+ const { inputTarget, targets } = params;
136
+ // 如果此时mask不处于多选状态下,且有多个元素被选中,同时点击的元素在选中元素中的其中一项,代表多选态切换为该元素的单选态
137
+ if (!this.mask.isMultiSelectStatus && targets.length > 1 && targets.includes(inputTarget)) {
138
+ this.emit('select', inputTarget.id.replace(DRAG_EL_ID_PREFIX, ''));
139
+ }
140
+ });
141
+ }
142
+
143
+ public canSelect(el: HTMLElement, stop: () => boolean): Boolean {
144
+ // 多选状态下不可以选中magic-ui-page,并停止继续向上层选中
145
+ if (el.className.includes(PAGE_CLASS)) {
146
+ this.core.highlightedDom = undefined;
147
+ this.core.highlightLayer.clearHighlight();
148
+ stop();
149
+ return false;
150
+ }
151
+ const currentTargetMode = getMode(el);
152
+ let selectedDomMode = '';
153
+ if (this.core.selectedDom?.className.includes(PAGE_CLASS)) {
154
+ // 先单击选中了页面(magic-ui-page),再按住多选键多选时,任一元素均可选中
155
+ return true;
156
+ }
157
+ if (this.targetList.length === 0 && this.core.selectedDom) {
158
+ // 单选后添加到多选的情况
159
+ selectedDomMode = getMode(this.core.selectedDom);
160
+ } else if (this.targetList.length > 0) {
161
+ // 已加入多选列表的布局模式是一样的,取第一个判断
162
+ selectedDomMode = getMode(this.targetList[0]);
163
+ }
164
+ // 定位模式不同,不可混选
165
+ if (currentTargetMode !== selectedDomMode) {
166
+ return false;
167
+ }
168
+ return true;
169
+ }
170
+
171
+ /**
172
+ * 清除多选状态
173
+ */
174
+ public clearSelectStatus(): void {
175
+ if (!this.moveableForMulti) return;
176
+ this.destroyDragElList();
177
+ this.moveableForMulti.target = null;
178
+ this.moveableForMulti.updateTarget();
179
+ this.targetList = [];
180
+ }
181
+
182
+ /**
183
+ * 销毁实例
184
+ */
185
+ public destroy(): void {
186
+ this.moveableForMulti?.destroy();
187
+ this.destroyDragElList();
188
+ }
189
+
190
+ /**
191
+ * 清除蒙层占位节点
192
+ */
193
+ public destroyDragElList(): void {
194
+ this.dragElList.forEach((dragElItem) => dragElItem?.remove());
195
+ }
196
+
197
+ /**
198
+ * 拖拽完成后将更新的位置信息暴露给上层业务方,业务方可以接收事件进行保存
199
+ * @param isResize 是否进行大小缩放
200
+ */
201
+ private update(isResize = false): void {
202
+ if (this.targetList.length === 0) return;
203
+
204
+ const { contentWindow } = this.core.renderer;
205
+ const doc = contentWindow?.document;
206
+ if (!doc) return;
207
+
208
+ this.emit('update', {
209
+ data: this.targetList.map((targetItem) => {
210
+ const offset = { left: targetItem.offsetLeft, top: targetItem.offsetTop };
211
+ const left = calcValueByFontsize(doc, offset.left);
212
+ const top = calcValueByFontsize(doc, offset.top);
213
+ const width = calcValueByFontsize(doc, targetItem.clientWidth);
214
+ const height = calcValueByFontsize(doc, targetItem.clientHeight);
215
+ return {
216
+ el: targetItem,
217
+ style: isResize ? { left, top, width, height } : { left, top },
218
+ };
219
+ }),
220
+ parentEl: null,
221
+ });
222
+ }
223
+
224
+ /**
225
+ * 获取moveable options参数
226
+ * @param {MoveableOptions} options
227
+ * @return {MoveableOptions} moveable options参数
228
+ */
229
+ private getOptions(options: MoveableOptions = {}): MoveableOptions {
230
+ let { multiMoveableOptions = {} } = this.core.config;
231
+
232
+ if (typeof multiMoveableOptions === 'function') {
233
+ multiMoveableOptions = multiMoveableOptions(this.core);
234
+ }
235
+
236
+ return {
237
+ defaultGroupRotate: 0,
238
+ defaultGroupOrigin: '50% 50%',
239
+ draggable: true,
240
+ resizable: false,
241
+ throttleDrag: 0,
242
+ startDragRotate: 0,
243
+ throttleDragRotate: 0,
244
+ zoom: 1,
245
+ origin: true,
246
+ padding: { left: 0, top: 0, right: 0, bottom: 0 },
247
+ snappable: true,
248
+ bounds: {
249
+ top: 0,
250
+ // 设置0的话无法移动到left为0,所以只能设置为-1
251
+ left: -1,
252
+ right: this.container.clientWidth - 1,
253
+ bottom: this.container.clientHeight,
254
+ ...(multiMoveableOptions.bounds || {}),
255
+ },
256
+ ...options,
257
+ ...multiMoveableOptions,
258
+ };
259
+ }
260
+ }
@@ -72,20 +72,22 @@ export default class StageRender extends EventEmitter {
72
72
  * @param el 将页面挂载到该Dom节点上
73
73
  */
74
74
  public async mount(el: HTMLDivElement) {
75
- if (this.iframe) {
76
- if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
77
- // 不同域,使用srcdoc发起异步请求,需要目标地址支持跨域
78
- let html = await fetch(this.runtimeUrl).then((res) => res.text());
79
- // 使用base, 解决相对路径或绝对路径的问题
80
- const base = `${location.protocol}//${getHost(this.runtimeUrl)}`;
81
- html = html.replace('<head>', `<head>\n<base href="${base}">`);
82
- this.iframe.srcdoc = html;
83
- }
84
-
85
- el.appendChild<HTMLIFrameElement>(this.iframe);
86
- } else {
75
+ if (!this.iframe) {
87
76
  throw Error('mount 失败');
88
77
  }
78
+
79
+ if (!isSameDomain(this.runtimeUrl) && this.runtimeUrl) {
80
+ // 不同域,使用srcdoc发起异步请求,需要目标地址支持跨域
81
+ let html = await fetch(this.runtimeUrl).then((res) => res.text());
82
+ // 使用base, 解决相对路径或绝对路径的问题
83
+ const base = `${location.protocol}//${getHost(this.runtimeUrl)}`;
84
+ html = html.replace('<head>', `<head>\n<base href="${base}">`);
85
+ this.iframe.srcdoc = html;
86
+ }
87
+
88
+ el.appendChild<HTMLIFrameElement>(this.iframe);
89
+
90
+ this.postTmagicRuntimeReady();
89
91
  }
90
92
 
91
93
  public getRuntime = (): Promise<Runtime> => {
@@ -111,26 +113,34 @@ export default class StageRender extends EventEmitter {
111
113
  }
112
114
 
113
115
  private loadHandler = async () => {
114
- this.contentWindow = this.iframe?.contentWindow as RuntimeWindow;
116
+ if (!this.contentWindow?.magic) {
117
+ this.postTmagicRuntimeReady();
118
+ }
115
119
 
116
- this.contentWindow.magic = this.getMagicApi();
120
+ if (!this.contentWindow) return;
117
121
 
118
122
  if (this.render) {
119
123
  const el = await this.render(this.core);
120
124
  if (el) {
121
- this.iframe?.contentDocument?.body?.appendChild(el);
125
+ this.contentWindow.document?.body?.appendChild(el);
122
126
  }
123
127
  }
124
128
 
125
129
  this.emit('onload');
126
130
 
131
+ injectStyle(this.contentWindow.document, style);
132
+ };
133
+
134
+ private postTmagicRuntimeReady() {
135
+ this.contentWindow = this.iframe?.contentWindow as RuntimeWindow;
136
+
137
+ this.contentWindow.magic = this.getMagicApi();
138
+
127
139
  this.contentWindow.postMessage(
128
140
  {
129
141
  tmagicRuntimeReady: true,
130
142
  },
131
143
  '*',
132
144
  );
133
-
134
- injectStyle(this.contentWindow.document, style);
135
- };
145
+ }
136
146
  }
@@ -18,7 +18,7 @@
18
18
 
19
19
  import { EventEmitter } from 'events';
20
20
 
21
- import { Mode } from './const';
21
+ import { Mode, ZIndex } from './const';
22
22
  import StageCore from './StageCore';
23
23
  import StageDragResize from './StageDragResize';
24
24
  import StageMask from './StageMask';
@@ -57,6 +57,7 @@ export default class TargetCalibrate extends EventEmitter {
57
57
  top: ${top}px;
58
58
  width: ${el.clientWidth}px;
59
59
  height: ${el.clientHeight}px;
60
+ z-index: ${ZIndex.DRAG_EL};
60
61
  `;
61
62
 
62
63
  this.operationEl.id = `${prefix}${el.id}`;
package/src/const.ts CHANGED
@@ -27,6 +27,8 @@ export const HIGHLIGHT_EL_ID_PREFIX = 'highlight_el_';
27
27
 
28
28
  export const CONTAINER_HIGHLIGHT_CLASS = 'tmagic-stage-container-highlight';
29
29
 
30
+ export const PAGE_CLASS = 'magic-ui-page';
31
+
30
32
  /** 默认放到缩小倍数 */
31
33
  export const DEFAULT_ZOOM = 1;
32
34
 
package/src/style.css CHANGED
@@ -7,4 +7,5 @@
7
7
  left: 0;
8
8
  background-color: #000;
9
9
  opacity: .1;
10
+ pointer-events: none;
10
11
  }
package/src/types.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  import { MoveableOptions } from 'moveable';
20
20
 
21
21
  import Core from '@tmagic/core';
22
- import type { Id, MApp, MNode } from '@tmagic/schema';
22
+ import type { Id, MApp, MContainer, MNode } from '@tmagic/schema';
23
23
 
24
24
  import { GuidesType } from './const';
25
25
  import StageCore from './StageCore';
@@ -29,6 +29,11 @@ import StageMask from './StageMask';
29
29
  export type CanSelect = (el: HTMLElement, event: MouseEvent, stop: () => boolean) => boolean | Promise<boolean>;
30
30
  export type IsContainer = (el: HTMLElement) => boolean | Promise<boolean>;
31
31
 
32
+ export enum ContainerHighlightType {
33
+ DEFAULT = 'default',
34
+ ALT = 'alt',
35
+ }
36
+
32
37
  export type StageCoreConfig = {
33
38
  /** 需要对齐的dom节点的CSS选择器字符串 */
34
39
  snapElementQuerySelector?: string;
@@ -36,9 +41,11 @@ export type StageCoreConfig = {
36
41
  zoom?: number;
37
42
  canSelect?: CanSelect;
38
43
  isContainer: IsContainer;
39
- containerHighlightClassName: string;
40
- containerHighlightDuration: number;
44
+ containerHighlightClassName?: string;
45
+ containerHighlightDuration?: number;
46
+ containerHighlightType?: ContainerHighlightType;
41
47
  moveableOptions?: ((core?: StageCore) => MoveableOptions) | MoveableOptions;
48
+ multiMoveableOptions?: ((core?: StageCore) => MoveableOptions) | MoveableOptions;
42
49
  /** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
43
50
  runtimeUrl?: string;
44
51
  render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
@@ -57,6 +64,17 @@ export interface StageMaskConfig {
57
64
  export interface StageDragResizeConfig {
58
65
  core: StageCore;
59
66
  container: HTMLElement;
67
+ mask: StageMask;
68
+ }
69
+
70
+ /** 拖动状态 */
71
+ export enum StageDragStatus {
72
+ /** 开始拖动 */
73
+ START = 'start',
74
+ /** 拖动中 */
75
+ ING = 'ing',
76
+ /** 拖动结束 */
77
+ END = 'end',
60
78
  }
61
79
 
62
80
  export type Rect = {
@@ -75,19 +93,21 @@ export interface GuidesEventData {
75
93
  }
76
94
 
77
95
  export interface UpdateEventData {
78
- el: HTMLElement;
79
- parentEl: HTMLElement | null;
80
- ghostEl: HTMLElement;
81
- style: {
82
- width?: number;
83
- height?: number;
84
- left?: number;
85
- top?: number;
86
- transform?: {
87
- rotate?: string;
88
- scale?: string;
96
+ data: {
97
+ el: HTMLElement;
98
+ style: {
99
+ width?: number;
100
+ height?: number;
101
+ left?: number;
102
+ top?: number;
103
+ transform?: {
104
+ rotate?: string;
105
+ scale?: string;
106
+ };
89
107
  };
90
- };
108
+ ghostEl?: HTMLElement;
109
+ }[];
110
+ parentEl: HTMLElement | null;
91
111
  }
92
112
 
93
113
  export interface SortEventData {
@@ -98,18 +118,20 @@ export interface SortEventData {
98
118
 
99
119
  export interface UpdateData {
100
120
  config: MNode;
121
+ parent?: MContainer;
122
+ parentId?: Id;
101
123
  root: MApp;
102
124
  }
103
125
 
104
126
  export interface RemoveData {
105
127
  id: Id;
128
+ parentId: Id;
106
129
  root: MApp;
107
130
  }
108
131
 
109
132
  export interface Runtime {
110
133
  getApp?: () => Core;
111
134
  beforeSelect?: (el: HTMLElement) => Promise<boolean> | boolean;
112
- getSnapElements?: (el?: HTMLElement) => HTMLElement[];
113
135
  updateRootConfig?: (config: MApp) => void;
114
136
  updatePageId?: (id: Id) => void;
115
137
  select?: (id: Id) => Promise<HTMLElement> | HTMLElement;
package/src/util.ts CHANGED
@@ -17,8 +17,8 @@
17
17
  */
18
18
  import { removeClassName } from '@tmagic/utils';
19
19
 
20
- import { Mode, SELECTED_CLASS } from './const';
21
- import type { Offset } from './types';
20
+ import { GHOST_EL_ID_PREFIX, Mode, SELECTED_CLASS, ZIndex } from './const';
21
+ import type { Offset, SortEventData } from './types';
22
22
 
23
23
  const getParents = (el: Element, relative: Element) => {
24
24
  let cur: Element | null = el.parentElement;
@@ -50,6 +50,21 @@ export const getOffset = (el: HTMLElement): Offset => {
50
50
  };
51
51
  };
52
52
 
53
+ // 将蒙层占位节点覆盖在原节点上方
54
+ export const getTargetElStyle = (el: HTMLElement) => {
55
+ const offset = getOffset(el);
56
+ const { transform } = getComputedStyle(el);
57
+ return `
58
+ position: absolute;
59
+ transform: ${transform};
60
+ left: ${offset.left}px;
61
+ top: ${offset.top}px;
62
+ width: ${el.clientWidth}px;
63
+ height: ${el.clientHeight}px;
64
+ z-index: ${ZIndex.DRAG_EL};
65
+ `;
66
+ };
67
+
53
68
  export const getAbsolutePosition = (el: HTMLElement, { top, left }: Offset) => {
54
69
  const { offsetParent } = el;
55
70
 
@@ -144,3 +159,73 @@ export const calcValueByFontsize = (doc: Document, value: number) => {
144
159
 
145
160
  return value;
146
161
  };
162
+
163
+ /**
164
+ * 下移组件位置
165
+ * @param {number} deltaTop 偏移量
166
+ * @param {Object} detail 当前选中的组件配置
167
+ */
168
+ export const down = (deltaTop: number, target: HTMLElement | SVGElement): SortEventData | void => {
169
+ let swapIndex = 0;
170
+ let addUpH = target.clientHeight;
171
+ const brothers = Array.from(target.parentNode?.children || []).filter(
172
+ (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX),
173
+ );
174
+ const index = brothers.indexOf(target);
175
+ // 往下移动
176
+ const downEls = brothers.slice(index + 1) as HTMLElement[];
177
+
178
+ for (let i = 0; i < downEls.length; i++) {
179
+ const ele = downEls[i];
180
+ // 是 fixed 不做处理
181
+ if (ele.style?.position === 'fixed') {
182
+ continue;
183
+ }
184
+ addUpH += ele.clientHeight / 2;
185
+ if (deltaTop <= addUpH) {
186
+ break;
187
+ }
188
+ addUpH += ele.clientHeight / 2;
189
+ swapIndex = i;
190
+ }
191
+ return {
192
+ src: target.id,
193
+ dist: downEls.length && swapIndex > -1 ? downEls[swapIndex].id : target.id,
194
+ };
195
+ };
196
+
197
+ /**
198
+ * 上移组件位置
199
+ * @param {Array} brothers 处于同一容器下的所有子组件配置
200
+ * @param {number} index 当前组件所处的位置
201
+ * @param {number} deltaTop 偏移量
202
+ * @param {Object} detail 当前选中的组件配置
203
+ */
204
+ export const up = (deltaTop: number, target: HTMLElement | SVGElement): SortEventData | void => {
205
+ const brothers = Array.from(target.parentNode?.children || []).filter(
206
+ (node) => !node.id.startsWith(GHOST_EL_ID_PREFIX),
207
+ );
208
+ const index = brothers.indexOf(target);
209
+ // 往上移动
210
+ const upEls = brothers.slice(0, index) as HTMLElement[];
211
+
212
+ let addUpH = target.clientHeight;
213
+ let swapIndex = upEls.length - 1;
214
+
215
+ for (let i = upEls.length - 1; i >= 0; i--) {
216
+ const ele = upEls[i];
217
+ if (!ele) continue;
218
+ // 是 fixed 不做处理
219
+ if (ele.style.position === 'fixed') continue;
220
+
221
+ addUpH += ele.clientHeight / 2;
222
+ if (-deltaTop <= addUpH) break;
223
+ addUpH += ele.clientHeight / 2;
224
+
225
+ swapIndex = i;
226
+ }
227
+ return {
228
+ src: target.id,
229
+ dist: upEls.length && swapIndex > -1 ? upEls[swapIndex].id : target.id,
230
+ };
231
+ };
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "declaration": true,
6
+ "declarationDir": "types",
7
+ "forceConsistentCasingInFileNames": true,
8
+ "paths": {},
9
+ },
10
+ "include": [
11
+ "src"
12
+ ],
13
+ }
File without changes
@@ -1,33 +1,44 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { EventEmitter } from 'events';
3
4
  import type { Id } from '@tmagic/schema';
4
5
  import StageDragResize from './StageDragResize';
5
6
  import StageHighlight from './StageHighlight';
6
7
  import StageMask from './StageMask';
8
+ import StageMultiDragResize from './StageMultiDragResize';
7
9
  import StageRender from './StageRender';
8
- import { IsContainer, RemoveData, SortEventData, StageCoreConfig, UpdateData } from './types';
10
+ import { ContainerHighlightType, IsContainer, RemoveData, SortEventData, StageCoreConfig, UpdateData } from './types';
9
11
  export default class StageCore extends EventEmitter {
10
12
  container?: HTMLDivElement;
11
- selectedDom: Element | undefined;
13
+ selectedDom: HTMLElement | undefined;
14
+ selectedDomList: HTMLElement[];
12
15
  highlightedDom: Element | undefined;
13
16
  renderer: StageRender;
14
17
  mask: StageMask;
15
18
  dr: StageDragResize;
19
+ multiDr: StageMultiDragResize;
16
20
  highlightLayer: StageHighlight;
17
21
  config: StageCoreConfig;
18
22
  zoom: number;
19
23
  containerHighlightClassName: string;
20
24
  containerHighlightDuration: number;
25
+ containerHighlightType?: ContainerHighlightType;
21
26
  isContainer: IsContainer;
22
27
  private canSelect;
23
28
  constructor(config: StageCoreConfig);
24
29
  getElementsFromPoint(event: MouseEvent): HTMLElement[];
25
- setElementFromPoint(event: MouseEvent): Promise<void>;
30
+ getElementFromPoint(event: MouseEvent): Promise<HTMLElement | undefined>;
31
+ isElCanSelect(el: HTMLElement, event: MouseEvent, stop: () => boolean): Promise<Boolean>;
26
32
  /**
27
33
  * 选中组件
28
34
  * @param idOrEl 组件Dom节点的id属性,或者Dom节点
29
35
  */
30
36
  select(idOrEl: Id | HTMLElement, event?: MouseEvent): Promise<void>;
37
+ /**
38
+ * 多选
39
+ * @param domList 多选节点
40
+ */
41
+ multiSelect(idOrElList: HTMLElement[] | Id[]): Promise<void>;
31
42
  /**
32
43
  * 更新选中的节点
33
44
  * @param data 更新的数据
@@ -42,6 +53,11 @@ export default class StageCore extends EventEmitter {
42
53
  add(data: UpdateData): Promise<void>;
43
54
  remove(data: RemoveData): Promise<void>;
44
55
  setZoom(zoom?: number): void;
56
+ /**
57
+ * 用于在切换选择模式时清除上一次的状态
58
+ * @param selectType 需要清理的选择模式 多选:multiSelect,单选:select
59
+ */
60
+ clearSelectStatus(selectType: String): void;
45
61
  /**
46
62
  * 挂载Dom节点
47
63
  * @param el 将stage挂载到该Dom节点上
@@ -51,6 +67,8 @@ export default class StageCore extends EventEmitter {
51
67
  * 清空所有参考线
52
68
  */
53
69
  clearGuides(): void;
70
+ addContainerHighlightClassName(event: MouseEvent, exclude: Element[]): Promise<void>;
71
+ getAddContainerHighlightClassNameTimeout(event: MouseEvent, exclude?: Element[]): NodeJS.Timeout;
54
72
  /**
55
73
  * 销毁实例
56
74
  */