@tmagic/stage 1.1.0-beta.2 → 1.1.0-beta.5
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.
- package/dist/tmagic-stage.es.js +352 -114
- package/dist/tmagic-stage.es.js.map +1 -1
- package/dist/tmagic-stage.umd.js +358 -116
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/dist/types/src/StageCore.d.ts +13 -2
- package/dist/types/src/StageDragResize.d.ts +7 -18
- package/dist/types/src/StageMask.d.ts +1 -0
- package/dist/types/src/StageMultiDragResize.d.ts +49 -0
- package/dist/types/src/StageRender.d.ts +1 -0
- package/dist/types/src/const.d.ts +1 -0
- package/dist/types/src/types.d.ts +3 -1
- package/dist/types/src/util.d.ts +16 -1
- package/package.json +5 -4
- package/src/StageCore.ts +92 -18
- package/src/StageDragResize.ts +40 -118
- package/src/StageHighlight.ts +1 -1
- package/src/StageMask.ts +21 -4
- package/src/StageMultiDragResize.ts +231 -0
- package/src/StageRender.ts +28 -18
- package/src/TargetCalibrate.ts +2 -1
- package/src/const.ts +2 -0
- package/src/style.css +1 -0
- package/src/types.ts +3 -1
- package/src/util.ts +87 -2
|
@@ -4,15 +4,18 @@ import type { Id } from '@tmagic/schema';
|
|
|
4
4
|
import StageDragResize from './StageDragResize';
|
|
5
5
|
import StageHighlight from './StageHighlight';
|
|
6
6
|
import StageMask from './StageMask';
|
|
7
|
+
import StageMultiDragResize from './StageMultiDragResize';
|
|
7
8
|
import StageRender from './StageRender';
|
|
8
9
|
import { IsContainer, RemoveData, SortEventData, StageCoreConfig, UpdateData } from './types';
|
|
9
10
|
export default class StageCore extends EventEmitter {
|
|
10
11
|
container?: HTMLDivElement;
|
|
11
|
-
selectedDom:
|
|
12
|
+
selectedDom: HTMLElement | undefined;
|
|
13
|
+
selectedDomList: HTMLElement[];
|
|
12
14
|
highlightedDom: Element | undefined;
|
|
13
15
|
renderer: StageRender;
|
|
14
16
|
mask: StageMask;
|
|
15
17
|
dr: StageDragResize;
|
|
18
|
+
multiDr: StageMultiDragResize;
|
|
16
19
|
highlightLayer: StageHighlight;
|
|
17
20
|
config: StageCoreConfig;
|
|
18
21
|
zoom: number;
|
|
@@ -22,7 +25,8 @@ export default class StageCore extends EventEmitter {
|
|
|
22
25
|
private canSelect;
|
|
23
26
|
constructor(config: StageCoreConfig);
|
|
24
27
|
getElementsFromPoint(event: MouseEvent): HTMLElement[];
|
|
25
|
-
|
|
28
|
+
getElementFromPoint(event: MouseEvent): Promise<HTMLElement | undefined>;
|
|
29
|
+
isElCanSelect(el: HTMLElement, event: MouseEvent, stop: () => boolean): Promise<Boolean>;
|
|
26
30
|
/**
|
|
27
31
|
* 选中组件
|
|
28
32
|
* @param idOrEl 组件Dom节点的id属性,或者Dom节点
|
|
@@ -42,6 +46,11 @@ export default class StageCore extends EventEmitter {
|
|
|
42
46
|
add(data: UpdateData): Promise<void>;
|
|
43
47
|
remove(data: RemoveData): Promise<void>;
|
|
44
48
|
setZoom(zoom?: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* 用于在切换选择模式时清除上一次的状态
|
|
51
|
+
* @param selectType 需要清理的选择模式 多选:multiSelect,单选:select
|
|
52
|
+
*/
|
|
53
|
+
clearSelectStatus(selectType: String): void;
|
|
45
54
|
/**
|
|
46
55
|
* 挂载Dom节点
|
|
47
56
|
* @param el 将stage挂载到该Dom节点上
|
|
@@ -51,6 +60,8 @@ export default class StageCore extends EventEmitter {
|
|
|
51
60
|
* 清空所有参考线
|
|
52
61
|
*/
|
|
53
62
|
clearGuides(): void;
|
|
63
|
+
addContainerHighlightClassName(event: MouseEvent, exclude: Element[]): Promise<void>;
|
|
64
|
+
getAddContainerHighlightClassNameTimeout(event: MouseEvent, exclude?: Element[]): NodeJS.Timeout;
|
|
54
65
|
/**
|
|
55
66
|
* 销毁实例
|
|
56
67
|
*/
|
|
@@ -3,18 +3,20 @@ import { EventEmitter } from 'events';
|
|
|
3
3
|
import Moveable from 'moveable';
|
|
4
4
|
import { GuidesType, Mode } from './const';
|
|
5
5
|
import StageCore from './StageCore';
|
|
6
|
-
import
|
|
6
|
+
import StageMask from './StageMask';
|
|
7
|
+
import type { StageDragResizeConfig } from './types';
|
|
7
8
|
/**
|
|
8
9
|
* 选中框
|
|
9
10
|
*/
|
|
10
11
|
export default class StageDragResize extends EventEmitter {
|
|
11
12
|
core: StageCore;
|
|
13
|
+
mask: StageMask;
|
|
12
14
|
/** 画布容器 */
|
|
13
15
|
container: HTMLElement;
|
|
14
16
|
/** 目标节点 */
|
|
15
17
|
target?: HTMLElement;
|
|
16
18
|
/** 目标节点在蒙层中的占位节点 */
|
|
17
|
-
dragEl
|
|
19
|
+
dragEl?: HTMLDivElement;
|
|
18
20
|
/** Moveable拖拽类实例 */
|
|
19
21
|
moveable?: Moveable;
|
|
20
22
|
/** 水平参考线 */
|
|
@@ -45,6 +47,8 @@ export default class StageDragResize extends EventEmitter {
|
|
|
45
47
|
updateMoveable(el?: HTMLElement | undefined): void;
|
|
46
48
|
setGuidelines(type: GuidesType, guidelines: number[]): void;
|
|
47
49
|
clearGuides(): void;
|
|
50
|
+
clearSelectStatus(): void;
|
|
51
|
+
destroyDragEl(): void;
|
|
48
52
|
/**
|
|
49
53
|
* 销毁实例
|
|
50
54
|
*/
|
|
@@ -60,22 +64,7 @@ export default class StageDragResize extends EventEmitter {
|
|
|
60
64
|
private sort;
|
|
61
65
|
private update;
|
|
62
66
|
private generateGhostEl;
|
|
67
|
+
private setGhostElChildrenId;
|
|
63
68
|
private destroyGhostEl;
|
|
64
|
-
private updateDragEl;
|
|
65
|
-
private destroyDragEl;
|
|
66
69
|
private getOptions;
|
|
67
70
|
}
|
|
68
|
-
/**
|
|
69
|
-
* 下移组件位置
|
|
70
|
-
* @param {number} deltaTop 偏移量
|
|
71
|
-
* @param {Object} detail 当前选中的组件配置
|
|
72
|
-
*/
|
|
73
|
-
export declare const down: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
|
|
74
|
-
/**
|
|
75
|
-
* 上移组件位置
|
|
76
|
-
* @param {Array} brothers 处于同一容器下的所有子组件配置
|
|
77
|
-
* @param {number} index 当前组件所处的位置
|
|
78
|
-
* @param {number} deltaTop 偏移量
|
|
79
|
-
* @param {Object} detail 当前选中的组件配置
|
|
80
|
-
*/
|
|
81
|
-
export declare const up: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
|
|
@@ -21,6 +21,7 @@ export default class StageMask extends Rule {
|
|
|
21
21
|
maxScrollTop: number;
|
|
22
22
|
maxScrollLeft: number;
|
|
23
23
|
intersectionObserver: IntersectionObserver | null;
|
|
24
|
+
isMultiSelectStatus: Boolean;
|
|
24
25
|
private mode;
|
|
25
26
|
private pageResizeObserver;
|
|
26
27
|
private wrapperResizeObserver;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import Moveable from 'moveable';
|
|
4
|
+
import StageCore from './StageCore';
|
|
5
|
+
import StageMask from './StageMask';
|
|
6
|
+
import { StageDragResizeConfig } from './types';
|
|
7
|
+
export default class StageMultiDragResize extends EventEmitter {
|
|
8
|
+
core: StageCore;
|
|
9
|
+
mask: StageMask;
|
|
10
|
+
/** 画布容器 */
|
|
11
|
+
container: HTMLElement;
|
|
12
|
+
/** 多选:目标节点组 */
|
|
13
|
+
targetList: HTMLElement[];
|
|
14
|
+
/** 多选:目标节点在蒙层中的占位节点组 */
|
|
15
|
+
dragElList: HTMLDivElement[];
|
|
16
|
+
/** Moveable多选拖拽类实例 */
|
|
17
|
+
moveableForMulti?: Moveable;
|
|
18
|
+
private multiMoveableHelper?;
|
|
19
|
+
constructor(config: StageDragResizeConfig);
|
|
20
|
+
/**
|
|
21
|
+
* 多选
|
|
22
|
+
* @param els
|
|
23
|
+
*/
|
|
24
|
+
multiSelect(els: HTMLElement[]): void;
|
|
25
|
+
canSelect(el: HTMLElement): Boolean;
|
|
26
|
+
/**
|
|
27
|
+
* 清除多选状态
|
|
28
|
+
*/
|
|
29
|
+
clearSelectStatus(): void;
|
|
30
|
+
/**
|
|
31
|
+
* 销毁实例
|
|
32
|
+
*/
|
|
33
|
+
destroy(): void;
|
|
34
|
+
/**
|
|
35
|
+
* 清除蒙层占位节点
|
|
36
|
+
*/
|
|
37
|
+
destroyDragElList(): void;
|
|
38
|
+
/**
|
|
39
|
+
* 拖拽完成后将更新的位置信息暴露给上层业务方,业务方可以接收事件进行保存
|
|
40
|
+
* @param isResize 是否进行大小缩放
|
|
41
|
+
*/
|
|
42
|
+
private update;
|
|
43
|
+
/**
|
|
44
|
+
* 获取moveable options参数
|
|
45
|
+
* @param {MoveableOptions} options
|
|
46
|
+
* @return {MoveableOptions} moveable options参数
|
|
47
|
+
*/
|
|
48
|
+
private getOptions;
|
|
49
|
+
}
|
|
@@ -5,6 +5,7 @@ export declare const DRAG_EL_ID_PREFIX = "drag_el_";
|
|
|
5
5
|
/** 高亮时需要在蒙层中创建一个占位节点,该节点的id前缀 */
|
|
6
6
|
export declare const HIGHLIGHT_EL_ID_PREFIX = "highlight_el_";
|
|
7
7
|
export declare const CONTAINER_HIGHLIGHT_CLASS = "tmagic-stage-container-highlight";
|
|
8
|
+
export declare const PAGE_CLASS = "magic-ui-page";
|
|
8
9
|
/** 默认放到缩小倍数 */
|
|
9
10
|
export declare const DEFAULT_ZOOM = 1;
|
|
10
11
|
/** 参考线类型 */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MoveableOptions } from 'moveable';
|
|
2
2
|
import Core from '@tmagic/core';
|
|
3
|
-
import type { Id, MApp, MNode } from '@tmagic/schema';
|
|
3
|
+
import type { Id, MApp, MContainer, MNode } from '@tmagic/schema';
|
|
4
4
|
import { GuidesType } from './const';
|
|
5
5
|
import StageCore from './StageCore';
|
|
6
6
|
import StageDragResize from './StageDragResize';
|
|
@@ -32,6 +32,7 @@ export interface StageMaskConfig {
|
|
|
32
32
|
export interface StageDragResizeConfig {
|
|
33
33
|
core: StageCore;
|
|
34
34
|
container: HTMLElement;
|
|
35
|
+
mask: StageMask;
|
|
35
36
|
}
|
|
36
37
|
export declare type Rect = {
|
|
37
38
|
width: number;
|
|
@@ -67,6 +68,7 @@ export interface SortEventData {
|
|
|
67
68
|
}
|
|
68
69
|
export interface UpdateData {
|
|
69
70
|
config: MNode;
|
|
71
|
+
parent?: MContainer;
|
|
70
72
|
root: MApp;
|
|
71
73
|
}
|
|
72
74
|
export interface RemoveData {
|
package/dist/types/src/util.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Mode } from './const';
|
|
2
|
-
import type { Offset } from './types';
|
|
2
|
+
import type { Offset, SortEventData } from './types';
|
|
3
3
|
export declare const getOffset: (el: HTMLElement) => Offset;
|
|
4
|
+
export declare const getTargetElStyle: (el: HTMLElement) => string;
|
|
4
5
|
export declare const getAbsolutePosition: (el: HTMLElement, { top, left }: Offset) => {
|
|
5
6
|
left: number;
|
|
6
7
|
top: number;
|
|
@@ -15,3 +16,17 @@ export declare const getScrollParent: (element: HTMLElement, includeHidden?: boo
|
|
|
15
16
|
export declare const removeSelectedClassName: (doc: Document) => void;
|
|
16
17
|
export declare const addSelectedClassName: (el: Element, doc: Document) => void;
|
|
17
18
|
export declare const calcValueByFontsize: (doc: Document, value: number) => number;
|
|
19
|
+
/**
|
|
20
|
+
* 下移组件位置
|
|
21
|
+
* @param {number} deltaTop 偏移量
|
|
22
|
+
* @param {Object} detail 当前选中的组件配置
|
|
23
|
+
*/
|
|
24
|
+
export declare const down: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
|
|
25
|
+
/**
|
|
26
|
+
* 上移组件位置
|
|
27
|
+
* @param {Array} brothers 处于同一容器下的所有子组件配置
|
|
28
|
+
* @param {number} index 当前组件所处的位置
|
|
29
|
+
* @param {number} deltaTop 偏移量
|
|
30
|
+
* @param {Object} detail 当前选中的组件配置
|
|
31
|
+
*/
|
|
32
|
+
export declare const up: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.1.0-beta.
|
|
2
|
+
"version": "1.1.0-beta.5",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*"
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@scena/guides": "^0.17.0",
|
|
30
|
-
"@tmagic/core": "1.1.0-beta.
|
|
31
|
-
"@tmagic/schema": "1.1.0-beta.
|
|
32
|
-
"@tmagic/utils": "1.1.0-beta.
|
|
30
|
+
"@tmagic/core": "1.1.0-beta.5",
|
|
31
|
+
"@tmagic/schema": "1.1.0-beta.5",
|
|
32
|
+
"@tmagic/utils": "1.1.0-beta.5",
|
|
33
33
|
"events": "^3.3.0",
|
|
34
|
+
"keycon": "^1.1.2",
|
|
34
35
|
"lodash-es": "^4.17.21",
|
|
35
36
|
"moveable": "^0.30.0",
|
|
36
37
|
"moveable-helper": "^0.4.0"
|
package/src/StageCore.ts
CHANGED
|
@@ -19,11 +19,13 @@
|
|
|
19
19
|
import { EventEmitter } from 'events';
|
|
20
20
|
|
|
21
21
|
import type { Id } from '@tmagic/schema';
|
|
22
|
+
import { addClassName } from '@tmagic/utils';
|
|
22
23
|
|
|
23
|
-
import { DEFAULT_ZOOM, GHOST_EL_ID_PREFIX } from './const';
|
|
24
|
+
import { DEFAULT_ZOOM, GHOST_EL_ID_PREFIX, PAGE_CLASS } from './const';
|
|
24
25
|
import StageDragResize from './StageDragResize';
|
|
25
26
|
import StageHighlight from './StageHighlight';
|
|
26
27
|
import StageMask from './StageMask';
|
|
28
|
+
import StageMultiDragResize from './StageMultiDragResize';
|
|
27
29
|
import StageRender from './StageRender';
|
|
28
30
|
import {
|
|
29
31
|
CanSelect,
|
|
@@ -40,12 +42,15 @@ import { addSelectedClassName, removeSelectedClassName } from './util';
|
|
|
40
42
|
|
|
41
43
|
export default class StageCore extends EventEmitter {
|
|
42
44
|
public container?: HTMLDivElement;
|
|
43
|
-
|
|
44
|
-
public selectedDom:
|
|
45
|
+
// 当前选中的节点
|
|
46
|
+
public selectedDom: HTMLElement | undefined;
|
|
47
|
+
// 多选选中的节点组
|
|
48
|
+
public selectedDomList: HTMLElement[] = [];
|
|
45
49
|
public highlightedDom: Element | undefined;
|
|
46
50
|
public renderer: StageRender;
|
|
47
51
|
public mask: StageMask;
|
|
48
52
|
public dr: StageDragResize;
|
|
53
|
+
public multiDr: StageMultiDragResize;
|
|
49
54
|
public highlightLayer: StageHighlight;
|
|
50
55
|
public config: StageCoreConfig;
|
|
51
56
|
public zoom = DEFAULT_ZOOM;
|
|
@@ -68,7 +73,8 @@ export default class StageCore extends EventEmitter {
|
|
|
68
73
|
|
|
69
74
|
this.renderer = new StageRender({ core: this });
|
|
70
75
|
this.mask = new StageMask({ core: this });
|
|
71
|
-
this.dr = new StageDragResize({ core: this, container: this.mask.content });
|
|
76
|
+
this.dr = new StageDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
|
77
|
+
this.multiDr = new StageMultiDragResize({ core: this, container: this.mask.content, mask: this.mask });
|
|
72
78
|
this.highlightLayer = new StageHighlight({ core: this, container: this.mask.wrapper });
|
|
73
79
|
|
|
74
80
|
this.renderer.on('runtime-ready', (runtime: Runtime) => {
|
|
@@ -79,8 +85,11 @@ export default class StageCore extends EventEmitter {
|
|
|
79
85
|
});
|
|
80
86
|
|
|
81
87
|
this.mask
|
|
82
|
-
.on('beforeSelect', (event: MouseEvent) => {
|
|
83
|
-
this.
|
|
88
|
+
.on('beforeSelect', async (event: MouseEvent) => {
|
|
89
|
+
this.clearSelectStatus('multiSelect');
|
|
90
|
+
const el = await this.getElementFromPoint(event);
|
|
91
|
+
if (!el) return;
|
|
92
|
+
this.select(el, event);
|
|
84
93
|
})
|
|
85
94
|
.on('select', () => {
|
|
86
95
|
this.emit('select', this.selectedDom);
|
|
@@ -90,16 +99,37 @@ export default class StageCore extends EventEmitter {
|
|
|
90
99
|
this.emit('changeGuides', data);
|
|
91
100
|
})
|
|
92
101
|
.on('highlight', async (event: MouseEvent) => {
|
|
93
|
-
await this.
|
|
102
|
+
const el = await this.getElementFromPoint(event);
|
|
103
|
+
if (!el) return;
|
|
104
|
+
await this.highlight(el);
|
|
94
105
|
if (this.highlightedDom === this.selectedDom) {
|
|
95
106
|
this.highlightLayer.clearHighlight();
|
|
96
107
|
return;
|
|
97
108
|
}
|
|
98
|
-
this.highlightLayer.highlight(this.highlightedDom as HTMLElement);
|
|
99
109
|
this.emit('highlight', this.highlightedDom);
|
|
100
110
|
})
|
|
101
111
|
.on('clearHighlight', async () => {
|
|
102
112
|
this.highlightLayer.clearHighlight();
|
|
113
|
+
})
|
|
114
|
+
.on('beforeMultiSelect', async (event: MouseEvent) => {
|
|
115
|
+
const el = await this.getElementFromPoint(event);
|
|
116
|
+
if (!el) return;
|
|
117
|
+
this.clearSelectStatus('select');
|
|
118
|
+
// 如果已有单选选中元素,不是magic-ui-page就可以加入多选列表
|
|
119
|
+
if (this.selectedDom && !this.selectedDom.className.includes(PAGE_CLASS)) {
|
|
120
|
+
this.selectedDomList.push(this.selectedDom as HTMLElement);
|
|
121
|
+
this.selectedDom = undefined;
|
|
122
|
+
}
|
|
123
|
+
// 判断元素是否已在多选列表
|
|
124
|
+
const existIndex = this.selectedDomList.findIndex((selectedDom) => selectedDom.id === el.id);
|
|
125
|
+
if (existIndex !== -1) {
|
|
126
|
+
// 再次点击取消选中
|
|
127
|
+
this.selectedDomList.splice(existIndex, 1);
|
|
128
|
+
} else {
|
|
129
|
+
this.selectedDomList.push(el);
|
|
130
|
+
}
|
|
131
|
+
this.multiDr.multiSelect(this.selectedDomList);
|
|
132
|
+
this.emit('multiSelect', this.selectedDomList);
|
|
103
133
|
});
|
|
104
134
|
|
|
105
135
|
// 要先触发select,在触发update
|
|
@@ -110,6 +140,10 @@ export default class StageCore extends EventEmitter {
|
|
|
110
140
|
.on('sort', (data: UpdateEventData) => {
|
|
111
141
|
setTimeout(() => this.emit('sort', data));
|
|
112
142
|
});
|
|
143
|
+
|
|
144
|
+
this.multiDr.on('update', (data: UpdateEventData) => {
|
|
145
|
+
setTimeout(() => this.emit('update', data));
|
|
146
|
+
});
|
|
113
147
|
}
|
|
114
148
|
|
|
115
149
|
public getElementsFromPoint(event: MouseEvent) {
|
|
@@ -130,29 +164,35 @@ export default class StageCore extends EventEmitter {
|
|
|
130
164
|
return doc?.elementsFromPoint(x / zoom, y / zoom) as HTMLElement[];
|
|
131
165
|
}
|
|
132
166
|
|
|
133
|
-
public async
|
|
167
|
+
public async getElementFromPoint(event: MouseEvent) {
|
|
134
168
|
const els = this.getElementsFromPoint(event);
|
|
135
|
-
|
|
136
169
|
let stopped = false;
|
|
137
170
|
const stop = () => (stopped = true);
|
|
138
171
|
for (const el of els) {
|
|
139
|
-
if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && (await this.
|
|
172
|
+
if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && (await this.isElCanSelect(el, event, stop))) {
|
|
140
173
|
if (stopped) break;
|
|
141
|
-
|
|
142
|
-
this.highlight(el);
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
this.select(el, event);
|
|
146
|
-
break;
|
|
174
|
+
return el;
|
|
147
175
|
}
|
|
148
176
|
}
|
|
149
177
|
}
|
|
150
178
|
|
|
179
|
+
public async isElCanSelect(el: HTMLElement, event: MouseEvent, stop: () => boolean): Promise<Boolean> {
|
|
180
|
+
// 执行业务方传入的判断逻辑
|
|
181
|
+
const canSelectByProp = await this.canSelect(el, event, stop);
|
|
182
|
+
if (!canSelectByProp) return false;
|
|
183
|
+
// 多选规则
|
|
184
|
+
if (this.mask.isMultiSelectStatus) {
|
|
185
|
+
return this.multiDr.canSelect(el);
|
|
186
|
+
}
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
|
|
151
190
|
/**
|
|
152
191
|
* 选中组件
|
|
153
192
|
* @param idOrEl 组件Dom节点的id属性,或者Dom节点
|
|
154
193
|
*/
|
|
155
194
|
public async select(idOrEl: Id | HTMLElement, event?: MouseEvent): Promise<void> {
|
|
195
|
+
this.clearSelectStatus('multiSelect');
|
|
156
196
|
const el = await this.getTargetElement(idOrEl);
|
|
157
197
|
|
|
158
198
|
if (el === this.selectedDom) return;
|
|
@@ -217,7 +257,7 @@ export default class StageCore extends EventEmitter {
|
|
|
217
257
|
this.highlightLayer.clearHighlight();
|
|
218
258
|
return;
|
|
219
259
|
}
|
|
220
|
-
if (el === this.highlightedDom) return;
|
|
260
|
+
if (el === this.highlightedDom || !el) return;
|
|
221
261
|
this.highlightLayer.highlight(el);
|
|
222
262
|
this.highlightedDom = el;
|
|
223
263
|
}
|
|
@@ -238,6 +278,19 @@ export default class StageCore extends EventEmitter {
|
|
|
238
278
|
this.zoom = zoom;
|
|
239
279
|
}
|
|
240
280
|
|
|
281
|
+
/**
|
|
282
|
+
* 用于在切换选择模式时清除上一次的状态
|
|
283
|
+
* @param selectType 需要清理的选择模式 多选:multiSelect,单选:select
|
|
284
|
+
*/
|
|
285
|
+
public clearSelectStatus(selectType: String) {
|
|
286
|
+
if (selectType === 'multiSelect') {
|
|
287
|
+
this.multiDr.clearSelectStatus();
|
|
288
|
+
this.selectedDomList = [];
|
|
289
|
+
} else {
|
|
290
|
+
this.dr.clearSelectStatus();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
241
294
|
/**
|
|
242
295
|
* 挂载Dom节点
|
|
243
296
|
* @param el 将stage挂载到该Dom节点上
|
|
@@ -260,6 +313,27 @@ export default class StageCore extends EventEmitter {
|
|
|
260
313
|
this.dr.clearGuides();
|
|
261
314
|
}
|
|
262
315
|
|
|
316
|
+
public async addContainerHighlightClassName(event: MouseEvent, exclude: Element[]) {
|
|
317
|
+
const els = this.getElementsFromPoint(event);
|
|
318
|
+
const { renderer } = this;
|
|
319
|
+
const doc = renderer.contentWindow?.document;
|
|
320
|
+
|
|
321
|
+
if (!doc) return;
|
|
322
|
+
|
|
323
|
+
for (const el of els) {
|
|
324
|
+
if (!el.id.startsWith(GHOST_EL_ID_PREFIX) && (await this.isContainer(el)) && !exclude.includes(el)) {
|
|
325
|
+
addClassName(el, doc, this.containerHighlightClassName);
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
public getAddContainerHighlightClassNameTimeout(event: MouseEvent, exclude: Element[] = []) {
|
|
332
|
+
return globalThis.setTimeout(() => {
|
|
333
|
+
this.addContainerHighlightClassName(event, exclude);
|
|
334
|
+
}, this.containerHighlightDuration);
|
|
335
|
+
}
|
|
336
|
+
|
|
263
337
|
/**
|
|
264
338
|
* 销毁实例
|
|
265
339
|
*/
|