@tmagic/stage 1.0.0-beta.3 → 1.0.0-beta.6
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 +18056 -0
- package/dist/tmagic-stage.es.js.map +1 -0
- package/dist/tmagic-stage.umd.js +18073 -0
- package/dist/tmagic-stage.umd.js.map +1 -0
- package/dist/types/src/StageCore.d.ts +44 -0
- package/dist/types/src/StageDragResize.d.ts +63 -0
- package/dist/types/src/StageMask.d.ts +80 -0
- package/dist/types/src/StageRender.d.ts +28 -0
- package/dist/types/src/const.d.ts +2 -0
- package/dist/types/src/index.d.ts +7 -0
- package/dist/types/src/types.d.ts +84 -0
- package/dist/types/src/util.d.ts +18 -0
- package/package.json +4 -4
- package/src/StageCore.ts +1 -2
- package/src/StageDragResize.ts +7 -12
- package/src/StageMask.ts +36 -15
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { Id } from '@tmagic/schema';
|
|
4
|
+
import StageDragResize from './StageDragResize';
|
|
5
|
+
import StageMask from './StageMask';
|
|
6
|
+
import StageRender from './StageRender';
|
|
7
|
+
import { RemoveData, SortEventData, StageCoreConfig, UpdateData } from './types';
|
|
8
|
+
export default class StageCore extends EventEmitter {
|
|
9
|
+
selectedDom: Element | undefined;
|
|
10
|
+
renderer: StageRender;
|
|
11
|
+
mask: StageMask;
|
|
12
|
+
dr: StageDragResize;
|
|
13
|
+
config: StageCoreConfig;
|
|
14
|
+
zoom: number;
|
|
15
|
+
constructor(config: StageCoreConfig);
|
|
16
|
+
/**
|
|
17
|
+
* 选中组件
|
|
18
|
+
* @param idOrEl 组件Dom节点的id属性,或者Dom节点
|
|
19
|
+
*/
|
|
20
|
+
select(idOrEl: Id | HTMLElement): Promise<void>;
|
|
21
|
+
update(data: UpdateData): void;
|
|
22
|
+
sortNode(data: SortEventData): void;
|
|
23
|
+
add(data: UpdateData): void;
|
|
24
|
+
remove(data: RemoveData): void;
|
|
25
|
+
setZoom(zoom?: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* 挂载Dom节点
|
|
28
|
+
* @param el 将stage挂载到该Dom节点上
|
|
29
|
+
*/
|
|
30
|
+
mount(el: HTMLDivElement): void;
|
|
31
|
+
/**
|
|
32
|
+
* 清空所有参考线
|
|
33
|
+
*/
|
|
34
|
+
clearGuides(): void;
|
|
35
|
+
/**
|
|
36
|
+
* 销毁实例
|
|
37
|
+
*/
|
|
38
|
+
destroy(): void;
|
|
39
|
+
private maskScrollHandler;
|
|
40
|
+
private hGuidesChangeGuidesHandler;
|
|
41
|
+
private vGuidesChangeGuidesHandler;
|
|
42
|
+
private setMaskLayout;
|
|
43
|
+
private beforeSelect;
|
|
44
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import Moveable from 'moveable';
|
|
4
|
+
import StageCore from './StageCore';
|
|
5
|
+
import type { SortEventData, StageDragResizeConfig } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* 选中框
|
|
8
|
+
*/
|
|
9
|
+
export default class StageDragResize extends EventEmitter {
|
|
10
|
+
core: StageCore;
|
|
11
|
+
container: HTMLElement;
|
|
12
|
+
target?: HTMLElement;
|
|
13
|
+
moveable?: Moveable;
|
|
14
|
+
horizontalGuidelines: number[];
|
|
15
|
+
verticalGuidelines: number[];
|
|
16
|
+
private dragStatus;
|
|
17
|
+
private elObserver?;
|
|
18
|
+
private ghostEl;
|
|
19
|
+
private mode;
|
|
20
|
+
constructor(config: StageDragResizeConfig);
|
|
21
|
+
/**
|
|
22
|
+
* 将选中框渲染并覆盖到选中的组件Dom节点上方
|
|
23
|
+
* @param el 选中组件的Dom节点元素
|
|
24
|
+
*/
|
|
25
|
+
select(el: HTMLElement): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* 初始化选中框并渲染出来
|
|
28
|
+
* @param param0
|
|
29
|
+
*/
|
|
30
|
+
refresh(): Promise<void>;
|
|
31
|
+
setVGuidelines(verticalGuidelines: number[]): Promise<void>;
|
|
32
|
+
setHGuidelines(horizontalGuidelines: number[]): Promise<void>;
|
|
33
|
+
updateMoveableTarget(target?: HTMLElement): void;
|
|
34
|
+
/**
|
|
35
|
+
* 销毁实例
|
|
36
|
+
*/
|
|
37
|
+
destroy(): void;
|
|
38
|
+
private bindResizeEvent;
|
|
39
|
+
private bindDragEvent;
|
|
40
|
+
private getSnapElements;
|
|
41
|
+
private sort;
|
|
42
|
+
private drag;
|
|
43
|
+
private generateGhostEl;
|
|
44
|
+
private destroyGhostEl;
|
|
45
|
+
private getOptions;
|
|
46
|
+
private initObserver;
|
|
47
|
+
private syncRect;
|
|
48
|
+
private calcValueByFontsize;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 下移组件位置
|
|
52
|
+
* @param {number} deltaTop 偏移量
|
|
53
|
+
* @param {Object} detail 当前选中的组件配置
|
|
54
|
+
*/
|
|
55
|
+
export declare const down: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
|
|
56
|
+
/**
|
|
57
|
+
* 上移组件位置
|
|
58
|
+
* @param {Array} brothers 处于同一容器下的所有子组件配置
|
|
59
|
+
* @param {number} index 当前组件所处的位置
|
|
60
|
+
* @param {number} deltaTop 偏移量
|
|
61
|
+
* @param {Object} detail 当前选中的组件配置
|
|
62
|
+
*/
|
|
63
|
+
export declare const up: (deltaTop: number, target: HTMLElement | SVGElement) => SortEventData | void;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import Guides from '@scena/guides';
|
|
4
|
+
import type StageCore from './StageCore';
|
|
5
|
+
import type { StageMaskConfig } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* 蒙层
|
|
8
|
+
* @description 用于拦截页面的点击动作,避免点击时触发组件自身动作;在编辑器中点击组件应当是选中组件;
|
|
9
|
+
*/
|
|
10
|
+
export default class StageMask extends EventEmitter {
|
|
11
|
+
content: HTMLDivElement;
|
|
12
|
+
wrapper: HTMLDivElement;
|
|
13
|
+
core: StageCore;
|
|
14
|
+
page: HTMLElement | null;
|
|
15
|
+
hGuides: Guides;
|
|
16
|
+
vGuides: Guides;
|
|
17
|
+
private target;
|
|
18
|
+
private resizeObserver;
|
|
19
|
+
private parentResizeObserver;
|
|
20
|
+
private canSelect;
|
|
21
|
+
constructor(config: StageMaskConfig);
|
|
22
|
+
/**
|
|
23
|
+
* 设置成固定定位模式
|
|
24
|
+
*/
|
|
25
|
+
setFixed(): void;
|
|
26
|
+
/**
|
|
27
|
+
* 设置成绝对定位模式
|
|
28
|
+
*/
|
|
29
|
+
setAbsolute(): void;
|
|
30
|
+
/**
|
|
31
|
+
* 监听页面大小变化
|
|
32
|
+
* @description 同步页面与mask的大小
|
|
33
|
+
* @param page 页面Dom节点
|
|
34
|
+
*/
|
|
35
|
+
observe(page: HTMLElement): void;
|
|
36
|
+
/**
|
|
37
|
+
* 挂载Dom节点
|
|
38
|
+
* @param el 将蒙层挂载到该Dom节点上
|
|
39
|
+
*/
|
|
40
|
+
mount(el: HTMLDivElement): void;
|
|
41
|
+
/**
|
|
42
|
+
* 销毁实例
|
|
43
|
+
*/
|
|
44
|
+
destroy(): void;
|
|
45
|
+
/**
|
|
46
|
+
* 是否显示标尺
|
|
47
|
+
* @param show 是否显示
|
|
48
|
+
*/
|
|
49
|
+
showGuides(show?: boolean): void;
|
|
50
|
+
/**
|
|
51
|
+
* 是否显示标尺
|
|
52
|
+
* @param show 是否显示
|
|
53
|
+
*/
|
|
54
|
+
showRule(show?: boolean): void;
|
|
55
|
+
/**
|
|
56
|
+
* 清空所有参考线
|
|
57
|
+
*/
|
|
58
|
+
clearGuides(): void;
|
|
59
|
+
/**
|
|
60
|
+
* 设置蒙层高度
|
|
61
|
+
* @param height 高度
|
|
62
|
+
*/
|
|
63
|
+
private setHeight;
|
|
64
|
+
/**
|
|
65
|
+
* 设置蒙层宽度
|
|
66
|
+
* @param width 宽度
|
|
67
|
+
*/
|
|
68
|
+
private setWidth;
|
|
69
|
+
/**
|
|
70
|
+
* 点击事件处理函数
|
|
71
|
+
* @param event 事件对象
|
|
72
|
+
*/
|
|
73
|
+
private mouseDownHandler;
|
|
74
|
+
private mouseUpHandler;
|
|
75
|
+
private mouseMoveHandler;
|
|
76
|
+
private contextmenuHandler;
|
|
77
|
+
private select;
|
|
78
|
+
private getGuidesStyle;
|
|
79
|
+
private createGuides;
|
|
80
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import StageCore from './StageCore';
|
|
4
|
+
import type { Runtime, RuntimeWindow, StageRenderConfig } from './types';
|
|
5
|
+
export default class StageRender extends EventEmitter {
|
|
6
|
+
/** 组件的js、css执行的环境,直接渲染为当前window,iframe渲染则为iframe.contentWindow */
|
|
7
|
+
contentWindow: RuntimeWindow | null;
|
|
8
|
+
runtime: Runtime | null;
|
|
9
|
+
iframe?: HTMLIFrameElement;
|
|
10
|
+
runtimeUrl?: string;
|
|
11
|
+
core: StageCore;
|
|
12
|
+
private render?;
|
|
13
|
+
constructor({ core }: StageRenderConfig);
|
|
14
|
+
getMagicApi: () => {
|
|
15
|
+
onPageElUpdate: (el: HTMLElement) => boolean;
|
|
16
|
+
onRuntimeReady: (runtime: Runtime) => void;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* 挂载Dom节点
|
|
20
|
+
* @param el 将页面挂载到该Dom节点上
|
|
21
|
+
*/
|
|
22
|
+
mount(el: HTMLDivElement): Promise<void>;
|
|
23
|
+
getRuntime: () => Promise<Runtime>;
|
|
24
|
+
/**
|
|
25
|
+
* 销毁实例
|
|
26
|
+
*/
|
|
27
|
+
destroy(): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import StageCore from './StageCore';
|
|
2
|
+
export type { MoveableOptions } from 'moveable';
|
|
3
|
+
export { default as StageRender } from './StageRender';
|
|
4
|
+
export { default as StageMask } from './StageMask';
|
|
5
|
+
export { default as StageDragResize } from './StageDragResize';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export default StageCore;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MoveableOptions } from 'react-moveable/declaration/types';
|
|
2
|
+
import { Id, MApp, MNode } from '@tmagic/schema';
|
|
3
|
+
import StageCore from './StageCore';
|
|
4
|
+
export declare type CanSelect = (el: HTMLElement, stop: () => boolean) => boolean | Promise<boolean>;
|
|
5
|
+
export declare type StageCoreConfig = {
|
|
6
|
+
/** 需要对齐的dom节点的CSS选择器字符串 */
|
|
7
|
+
snapElementQuerySelector?: string;
|
|
8
|
+
/** 放大倍数,默认1倍 */
|
|
9
|
+
zoom?: number;
|
|
10
|
+
canSelect?: CanSelect;
|
|
11
|
+
moveableOptions?: ((core?: StageCore) => MoveableOptions) | MoveableOptions;
|
|
12
|
+
/** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
|
|
13
|
+
runtimeUrl?: string;
|
|
14
|
+
render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
|
|
15
|
+
};
|
|
16
|
+
export interface StageRenderConfig {
|
|
17
|
+
core: StageCore;
|
|
18
|
+
}
|
|
19
|
+
export interface StageMaskConfig {
|
|
20
|
+
core: StageCore;
|
|
21
|
+
}
|
|
22
|
+
export interface StageDragResizeConfig {
|
|
23
|
+
core: StageCore;
|
|
24
|
+
container: HTMLElement;
|
|
25
|
+
}
|
|
26
|
+
export declare type Rect = {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
} & Offset;
|
|
30
|
+
export interface Offset {
|
|
31
|
+
left: number;
|
|
32
|
+
top: number;
|
|
33
|
+
}
|
|
34
|
+
export interface UpdateEventData {
|
|
35
|
+
el: HTMLElement;
|
|
36
|
+
ghostEl: HTMLElement;
|
|
37
|
+
style: {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
left?: number;
|
|
41
|
+
top?: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface SortEventData {
|
|
45
|
+
src: Id;
|
|
46
|
+
dist: Id;
|
|
47
|
+
root?: MApp;
|
|
48
|
+
}
|
|
49
|
+
export interface UpdateData {
|
|
50
|
+
config: MNode;
|
|
51
|
+
root: MApp;
|
|
52
|
+
}
|
|
53
|
+
export interface RemoveData {
|
|
54
|
+
id: Id;
|
|
55
|
+
root: MApp;
|
|
56
|
+
}
|
|
57
|
+
export interface Runtime {
|
|
58
|
+
beforeSelect?: (el: HTMLElement) => Promise<boolean> | boolean;
|
|
59
|
+
getSnapElements?: (el: HTMLElement) => HTMLElement[];
|
|
60
|
+
updateRootConfig: (config: MApp) => void;
|
|
61
|
+
updatePageId?: (id: Id) => void;
|
|
62
|
+
select?: (id: Id) => Promise<HTMLElement> | HTMLElement;
|
|
63
|
+
add?: (data: UpdateData) => void;
|
|
64
|
+
update?: (data: UpdateData) => void;
|
|
65
|
+
sortNode?: (data: SortEventData) => void;
|
|
66
|
+
remove?: (data: RemoveData) => void;
|
|
67
|
+
}
|
|
68
|
+
export interface Magic {
|
|
69
|
+
/** 当前页面的根节点变化时调用该方法,编辑器会同步该el和stage的大小,该方法由stage注入到iframe.contentWindow中 */
|
|
70
|
+
onPageElUpdate: (el: HTMLElement) => void;
|
|
71
|
+
onRuntimeReady: (runtime: Runtime) => void;
|
|
72
|
+
}
|
|
73
|
+
export interface RuntimeWindow extends Window {
|
|
74
|
+
magic: Magic;
|
|
75
|
+
}
|
|
76
|
+
export declare enum ZIndex {
|
|
77
|
+
MASK = "99999",
|
|
78
|
+
GHOST_EL = "99998"
|
|
79
|
+
}
|
|
80
|
+
export declare enum MouseButton {
|
|
81
|
+
LEFT = 0,
|
|
82
|
+
MIDDLE = 1,
|
|
83
|
+
RIGHT = 2
|
|
84
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Offset } from './types';
|
|
2
|
+
export declare enum Mode {
|
|
3
|
+
ABSOLUTE = "absolute",
|
|
4
|
+
FIXED = "fixed",
|
|
5
|
+
SORTABLE = "sortable"
|
|
6
|
+
}
|
|
7
|
+
export declare const getOffset: (el: HTMLElement) => Offset;
|
|
8
|
+
export declare const getAbsolutePosition: (el: HTMLElement, { top, left }: Offset) => {
|
|
9
|
+
left: number;
|
|
10
|
+
top: number;
|
|
11
|
+
};
|
|
12
|
+
export declare const getHost: (targetUrl: string) => string | undefined;
|
|
13
|
+
export declare const isSameDomain: (targetUrl?: string, source?: string) => boolean;
|
|
14
|
+
export declare const isAbsolute: (el?: HTMLElement | undefined) => boolean;
|
|
15
|
+
export declare const isRelative: (el?: HTMLElement | undefined) => boolean;
|
|
16
|
+
export declare const isStatic: (el?: HTMLElement | undefined) => boolean;
|
|
17
|
+
export declare const isFixed: (el?: HTMLElement | undefined) => boolean;
|
|
18
|
+
export declare const getMode: (el: HTMLElement) => Mode;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0-beta.
|
|
2
|
+
"version": "1.0.0-beta.6",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"main": "dist/tmagic-stage.umd.js",
|
|
@@ -23,11 +23,11 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@scena/guides": "^0.17.0",
|
|
26
|
-
"@tmagic/schema": "^1.0.0-beta.
|
|
27
|
-
"@tmagic/utils": "^1.0.0-beta.
|
|
26
|
+
"@tmagic/schema": "^1.0.0-beta.6",
|
|
27
|
+
"@tmagic/utils": "^1.0.0-beta.6",
|
|
28
28
|
"events": "^3.3.0",
|
|
29
29
|
"lodash-es": "^4.17.21",
|
|
30
|
-
"moveable": "^0.
|
|
30
|
+
"moveable": "^0.28.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/events": "^3.0.0",
|
package/src/StageCore.ts
CHANGED
|
@@ -52,9 +52,8 @@ export default class StageCore extends EventEmitter {
|
|
|
52
52
|
this.renderer.on('runtime-ready', (runtime: Runtime) => this.emit('runtime-ready', runtime));
|
|
53
53
|
this.renderer.on('page-el-update', (el: HTMLElement) => this.mask?.observe(el));
|
|
54
54
|
|
|
55
|
-
this.mask.on('select', async (el: Element
|
|
55
|
+
this.mask.on('select', async (el: Element) => {
|
|
56
56
|
await this.dr?.select(el as HTMLElement);
|
|
57
|
-
setTimeout(() => this.dr?.moveable?.dragStart(event));
|
|
58
57
|
});
|
|
59
58
|
this.mask.on('selected', (el: Element) => {
|
|
60
59
|
this.select(el as HTMLElement);
|
package/src/StageDragResize.ts
CHANGED
|
@@ -41,12 +41,12 @@ export default class StageDragResize extends EventEmitter {
|
|
|
41
41
|
public container: HTMLElement;
|
|
42
42
|
public target?: HTMLElement;
|
|
43
43
|
public moveable?: Moveable;
|
|
44
|
+
public horizontalGuidelines: number[] = [];
|
|
45
|
+
public verticalGuidelines: number[] = [];
|
|
44
46
|
|
|
45
47
|
private dragStatus: ActionStatus = ActionStatus.END;
|
|
46
48
|
private elObserver?: ResizeObserver;
|
|
47
49
|
private ghostEl: HTMLElement | undefined;
|
|
48
|
-
private horizontalGuidelines: number[] = [];
|
|
49
|
-
private verticalGuidelines: number[] = [];
|
|
50
50
|
private mode: Mode = Mode.ABSOLUTE;
|
|
51
51
|
|
|
52
52
|
constructor(config: StageDragResizeConfig) {
|
|
@@ -246,12 +246,10 @@ export default class StageDragResize extends EventEmitter {
|
|
|
246
246
|
(await renderer.getRuntime())?.getSnapElements ||
|
|
247
247
|
(() => {
|
|
248
248
|
const doc = renderer.contentWindow?.document;
|
|
249
|
-
|
|
250
|
-
// 排除掉当前组件本身
|
|
251
|
-
.filter((element) => element !== this.target && !this.target?.contains(element));
|
|
252
|
-
return elementGuidelines as HTMLElement[];
|
|
249
|
+
return (doc ? Array.from(doc.querySelectorAll('[id]')) : []) as HTMLElement[];
|
|
253
250
|
});
|
|
254
|
-
|
|
251
|
+
// 排除掉当前组件本身
|
|
252
|
+
return getSnapElements(el).filter((element) => element !== this.target && !this.target?.contains(element));
|
|
255
253
|
}
|
|
256
254
|
|
|
257
255
|
private sort(): void {
|
|
@@ -341,11 +339,8 @@ export default class StageDragResize extends EventEmitter {
|
|
|
341
339
|
resizable: true,
|
|
342
340
|
snappable: !isSortable,
|
|
343
341
|
snapGap: !isSortable,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
snapHorizontal: !isSortable,
|
|
347
|
-
snapCenter: !isSortable,
|
|
348
|
-
container: renderer.contentWindow?.document.body,
|
|
342
|
+
snapDirections: { center: !isSortable, middle: !isSortable },
|
|
343
|
+
elementSnapDirections: { center: !isSortable, middle: !isSortable },
|
|
349
344
|
|
|
350
345
|
elementGuidelines: isSortable ? [] : await this.getSnapElements(this.target),
|
|
351
346
|
horizontalGuidelines: this.horizontalGuidelines,
|
package/src/StageMask.ts
CHANGED
|
@@ -91,8 +91,8 @@ export default class StageMask extends EventEmitter {
|
|
|
91
91
|
const { config: coreConfig } = config.core;
|
|
92
92
|
|
|
93
93
|
this.canSelect = coreConfig.canSelect || ((el: HTMLElement) => !!el.id);
|
|
94
|
-
this.content.addEventListener('mousedown', this.mouseDownHandler
|
|
95
|
-
this.content.addEventListener('contextmenu', this.contextmenuHandler
|
|
94
|
+
this.content.addEventListener('mousedown', this.mouseDownHandler);
|
|
95
|
+
this.content.addEventListener('contextmenu', this.contextmenuHandler);
|
|
96
96
|
this.wrapper.appendChild(this.content);
|
|
97
97
|
|
|
98
98
|
this.hGuides = this.createGuides('horizontal');
|
|
@@ -189,17 +189,26 @@ export default class StageMask extends EventEmitter {
|
|
|
189
189
|
* @param show 是否显示
|
|
190
190
|
*/
|
|
191
191
|
public showRule(show = true) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
192
|
+
// 当尺子隐藏时发现大小变化,显示后会变形,所以这里做重新初始化处理
|
|
193
|
+
if (show) {
|
|
194
|
+
this.hGuides.destroy();
|
|
195
|
+
this.hGuides = this.createGuides('horizontal', this.core.dr.horizontalGuidelines);
|
|
196
|
+
|
|
197
|
+
this.vGuides.destroy();
|
|
198
|
+
this.vGuides = this.createGuides('vertical', this.core.dr.verticalGuidelines);
|
|
199
|
+
} else {
|
|
200
|
+
this.hGuides.setState({
|
|
201
|
+
rulerStyle: {
|
|
202
|
+
visibility: 'hidden',
|
|
203
|
+
},
|
|
204
|
+
});
|
|
197
205
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
this.vGuides.setState({
|
|
207
|
+
rulerStyle: {
|
|
208
|
+
visibility: 'hidden',
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
}
|
|
203
212
|
}
|
|
204
213
|
|
|
205
214
|
/**
|
|
@@ -242,15 +251,26 @@ export default class StageMask extends EventEmitter {
|
|
|
242
251
|
return;
|
|
243
252
|
}
|
|
244
253
|
|
|
254
|
+
this.content.addEventListener('mousemove', this.mouseMoveHandler);
|
|
255
|
+
|
|
245
256
|
this.select(event);
|
|
246
257
|
};
|
|
247
258
|
|
|
248
259
|
private mouseUpHandler = (): void => {
|
|
249
|
-
this.content
|
|
260
|
+
this.content.removeEventListener('mousemove', this.mouseMoveHandler);
|
|
261
|
+
this.content.removeEventListener('mouseup', this.mouseUpHandler);
|
|
250
262
|
this.emit('selected', this.target);
|
|
251
263
|
this.target = null;
|
|
252
264
|
};
|
|
253
265
|
|
|
266
|
+
private mouseMoveHandler = (event: MouseEvent): void => {
|
|
267
|
+
// 避免触摸板轻触移动拖动组件
|
|
268
|
+
if (event.buttons) {
|
|
269
|
+
this.core.dr.moveable?.dragStart(event);
|
|
270
|
+
}
|
|
271
|
+
this.content.removeEventListener('mousemove', this.mouseMoveHandler);
|
|
272
|
+
};
|
|
273
|
+
|
|
254
274
|
private contextmenuHandler = async (event: MouseEvent): Promise<void> => {
|
|
255
275
|
await this.select(event);
|
|
256
276
|
this.mouseUpHandler();
|
|
@@ -282,7 +302,7 @@ export default class StageMask extends EventEmitter {
|
|
|
282
302
|
this.emit('select', el, event);
|
|
283
303
|
this.target = el;
|
|
284
304
|
// 如果是右键点击,这里的mouseup事件监听没有效果
|
|
285
|
-
this.content
|
|
305
|
+
this.content.addEventListener('mouseup', this.mouseUpHandler);
|
|
286
306
|
break;
|
|
287
307
|
}
|
|
288
308
|
}
|
|
@@ -296,9 +316,10 @@ export default class StageMask extends EventEmitter {
|
|
|
296
316
|
height: type === 'horizontal' ? '30px' : '100%',
|
|
297
317
|
});
|
|
298
318
|
|
|
299
|
-
private createGuides = (type: 'horizontal' | 'vertical'): Guides =>
|
|
319
|
+
private createGuides = (type: 'horizontal' | 'vertical', defaultGuides: number[] = []): Guides =>
|
|
300
320
|
new Guides(this.wrapper, {
|
|
301
321
|
type,
|
|
322
|
+
defaultGuides,
|
|
302
323
|
displayDragPos: true,
|
|
303
324
|
backgroundColor: '#fff',
|
|
304
325
|
lineColor: '#000',
|