@tmagic/stage 1.2.0-beta.2 → 1.2.0-beta.21
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/README.md +62 -1
- package/dist/tmagic-stage.js +2157 -0
- package/dist/tmagic-stage.js.map +1 -0
- package/dist/{tmagic-stage.umd.js → tmagic-stage.umd.cjs} +1436 -993
- package/dist/tmagic-stage.umd.cjs.map +1 -0
- package/package.json +9 -8
- package/src/ActionManager.ts +534 -0
- package/src/DragResizeHelper.ts +338 -0
- package/src/MoveableOptionsManager.ts +249 -0
- package/src/MoveableSelectParentAble.ts +76 -0
- package/src/Rule.ts +13 -9
- package/src/StageCore.ts +220 -260
- package/src/StageDragResize.ts +83 -339
- package/src/StageHighlight.ts +17 -16
- package/src/StageMask.ts +88 -140
- package/src/StageMultiDragResize.ts +97 -198
- package/src/StageRender.ts +90 -15
- package/src/TargetShadow.ts +120 -0
- package/src/const.ts +1 -1
- package/src/types.ts +97 -19
- package/src/util.ts +24 -11
- package/types/ActionManager.d.ts +141 -0
- package/types/DragResizeHelper.d.ts +70 -0
- package/types/MoveableOptionsManager.d.ts +86 -0
- package/types/MoveableSelectParentAble.d.ts +8 -0
- package/types/Rule.d.ts +4 -3
- package/types/StageCore.d.ts +65 -39
- package/types/StageDragResize.d.ts +11 -40
- package/types/StageHighlight.d.ts +3 -4
- package/types/StageMask.d.ts +23 -22
- package/types/StageMultiDragResize.d.ts +8 -24
- package/types/StageRender.d.ts +24 -6
- package/types/TargetShadow.d.ts +22 -0
- package/types/const.d.ts +1 -1
- package/types/types.d.ts +85 -18
- package/types/util.d.ts +9 -8
- package/dist/tmagic-stage.mjs +0 -1715
- package/dist/tmagic-stage.mjs.map +0 -1
- package/dist/tmagic-stage.umd.js.map +0 -1
- package/src/TargetCalibrate.ts +0 -119
- package/types/TargetCalibrate.d.ts +0 -20
package/types/StageCore.d.ts
CHANGED
|
@@ -1,63 +1,53 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { EventEmitter } from 'events';
|
|
4
|
-
import
|
|
5
|
-
import StageDragResize from './StageDragResize';
|
|
6
|
-
import StageHighlight from './StageHighlight';
|
|
4
|
+
import { Id } from '@tmagic/schema';
|
|
7
5
|
import StageMask from './StageMask';
|
|
8
|
-
import StageMultiDragResize from './StageMultiDragResize';
|
|
9
6
|
import StageRender from './StageRender';
|
|
10
|
-
import {
|
|
7
|
+
import { RemoveData, StageCoreConfig, UpdateData } from './types';
|
|
8
|
+
/**
|
|
9
|
+
* 负责管理画布,管理renderer、mask、actionManager三个核心类,并负责统一对外通信,包括提供接口和抛事件
|
|
10
|
+
*/
|
|
11
11
|
export default class StageCore extends EventEmitter {
|
|
12
12
|
container?: HTMLDivElement;
|
|
13
|
-
selectedDom: HTMLElement | undefined;
|
|
14
|
-
selectedDomList: HTMLElement[];
|
|
15
|
-
highlightedDom: Element | undefined;
|
|
16
13
|
renderer: StageRender;
|
|
17
14
|
mask: StageMask;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
zoom: number;
|
|
23
|
-
containerHighlightClassName: string;
|
|
24
|
-
containerHighlightDuration: number;
|
|
25
|
-
containerHighlightType?: ContainerHighlightType;
|
|
26
|
-
isContainer: IsContainer;
|
|
27
|
-
private canSelect;
|
|
15
|
+
private actionManager;
|
|
16
|
+
private pageResizeObserver;
|
|
17
|
+
private autoScrollIntoView;
|
|
18
|
+
private customizedRender?;
|
|
28
19
|
constructor(config: StageCoreConfig);
|
|
29
|
-
getElementsFromPoint(event: MouseEvent): HTMLElement[];
|
|
30
|
-
getElementFromPoint(event: MouseEvent): Promise<HTMLElement | undefined>;
|
|
31
|
-
isElCanSelect(el: HTMLElement, event: MouseEvent, stop: () => boolean): Promise<Boolean>;
|
|
32
20
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @param idOrEl
|
|
21
|
+
* 单选选中元素
|
|
22
|
+
* @param idOrEl 选中的id或者元素
|
|
35
23
|
*/
|
|
36
24
|
select(idOrEl: Id | HTMLElement, event?: MouseEvent): Promise<void>;
|
|
37
25
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @param
|
|
26
|
+
* 多选选中多个元素
|
|
27
|
+
* @param idOrElList 选中元素的id或元素列表
|
|
40
28
|
*/
|
|
41
29
|
multiSelect(idOrElList: HTMLElement[] | Id[]): Promise<void>;
|
|
42
30
|
/**
|
|
43
|
-
*
|
|
44
|
-
* @param
|
|
31
|
+
* 高亮选中元素
|
|
32
|
+
* @param el 要高亮的元素
|
|
33
|
+
*/
|
|
34
|
+
highlight(idOrEl: Id | HTMLElement): void;
|
|
35
|
+
/**
|
|
36
|
+
* 更新组件
|
|
37
|
+
* @param data 更新组件的数据
|
|
45
38
|
*/
|
|
46
39
|
update(data: UpdateData): Promise<void>;
|
|
47
40
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @param
|
|
41
|
+
* 往画布增加一个组件
|
|
42
|
+
* @param data 组件信息数据
|
|
50
43
|
*/
|
|
51
|
-
highlight(idOrEl: HTMLElement | Id): Promise<void>;
|
|
52
|
-
sortNode(data: SortEventData): Promise<void>;
|
|
53
44
|
add(data: UpdateData): Promise<void>;
|
|
54
|
-
remove(data: RemoveData): Promise<void>;
|
|
55
|
-
setZoom(zoom?: number): void;
|
|
56
45
|
/**
|
|
57
|
-
*
|
|
58
|
-
* @param
|
|
46
|
+
* 从画布删除一个组件
|
|
47
|
+
* @param data 组件信息数据
|
|
59
48
|
*/
|
|
60
|
-
|
|
49
|
+
remove(data: RemoveData): Promise<void>;
|
|
50
|
+
setZoom(zoom?: number): void;
|
|
61
51
|
/**
|
|
62
52
|
* 挂载Dom节点
|
|
63
53
|
* @param el 将stage挂载到该Dom节点上
|
|
@@ -67,11 +57,47 @@ export default class StageCore extends EventEmitter {
|
|
|
67
57
|
* 清空所有参考线
|
|
68
58
|
*/
|
|
69
59
|
clearGuides(): void;
|
|
70
|
-
|
|
71
|
-
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated 废弃接口,建议用delayedMarkContainer代替
|
|
62
|
+
*/
|
|
63
|
+
getAddContainerHighlightClassNameTimeout(event: MouseEvent, excludeElList?: Element[]): NodeJS.Timeout;
|
|
64
|
+
/**
|
|
65
|
+
* 鼠标拖拽着元素,在容器上方悬停,延迟一段时间后,对容器进行标记,如果悬停时间够长将标记成功,悬停时间短,调用方通过返回的timeoutId取消标记
|
|
66
|
+
* 标记的作用:1、高亮容器,给用户一个加入容器的交互感知;2、释放鼠标后,通过标记的标志找到要加入的容器
|
|
67
|
+
* @param event 鼠标事件
|
|
68
|
+
* @param excludeElList 计算鼠标所在容器时要排除的元素列表
|
|
69
|
+
* @returns timeoutId,调用方在鼠标移走时要取消该timeout,阻止标记
|
|
70
|
+
*/
|
|
71
|
+
delayedMarkContainer(event: MouseEvent, excludeElList?: Element[]): NodeJS.Timeout;
|
|
72
72
|
/**
|
|
73
73
|
* 销毁实例
|
|
74
74
|
*/
|
|
75
75
|
destroy(): void;
|
|
76
|
-
|
|
76
|
+
/**
|
|
77
|
+
* 监听页面大小变化
|
|
78
|
+
*/
|
|
79
|
+
private observePageResize;
|
|
80
|
+
private getActionManagerConfig;
|
|
81
|
+
private initRenderEvent;
|
|
82
|
+
private initMaskEvent;
|
|
83
|
+
/**
|
|
84
|
+
* 初始化操作相关事件监听
|
|
85
|
+
*/
|
|
86
|
+
private initActionEvent;
|
|
87
|
+
/**
|
|
88
|
+
* 初始化ActionManager类本身抛出来的事件监听
|
|
89
|
+
*/
|
|
90
|
+
private initActionManagerEvent;
|
|
91
|
+
/**
|
|
92
|
+
* 初始化DragResize类通过ActionManager抛出来的事件监听
|
|
93
|
+
*/
|
|
94
|
+
private initDrEvent;
|
|
95
|
+
/**
|
|
96
|
+
* 初始化MultiDragResize类通过ActionManager抛出来的事件监听
|
|
97
|
+
*/
|
|
98
|
+
private initMulDrEvent;
|
|
99
|
+
/**
|
|
100
|
+
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
101
|
+
*/
|
|
102
|
+
private initHighlightEvent;
|
|
77
103
|
}
|
|
@@ -1,43 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
|
-
import Moveable from 'moveable';
|
|
4
|
-
import { GuidesType, Mode } from './const';
|
|
5
|
-
import StageCore from './StageCore';
|
|
6
|
-
import StageMask from './StageMask';
|
|
1
|
+
import MoveableOptionsManager from './MoveableOptionsManager';
|
|
7
2
|
import type { StageDragResizeConfig } from './types';
|
|
8
3
|
/**
|
|
9
|
-
*
|
|
4
|
+
* 管理单选操作,响应选中操作,初始化moveableOption参数并初始化moveable,处理moveable回调事件对组件进行更新
|
|
5
|
+
* @extends MoveableOptionsManager
|
|
10
6
|
*/
|
|
11
|
-
export default class StageDragResize extends
|
|
12
|
-
core: StageCore;
|
|
13
|
-
mask: StageMask;
|
|
14
|
-
/** 画布容器 */
|
|
15
|
-
container: HTMLElement;
|
|
7
|
+
export default class StageDragResize extends MoveableOptionsManager {
|
|
16
8
|
/** 目标节点 */
|
|
17
|
-
target
|
|
18
|
-
/** 目标节点在蒙层中的占位节点 */
|
|
19
|
-
dragEl?: HTMLDivElement;
|
|
9
|
+
private target?;
|
|
20
10
|
/** Moveable拖拽类实例 */
|
|
21
|
-
moveable
|
|
22
|
-
/** 水平参考线 */
|
|
23
|
-
horizontalGuidelines: number[];
|
|
24
|
-
/** 垂直参考线 */
|
|
25
|
-
verticalGuidelines: number[];
|
|
26
|
-
/** 对齐元素集合 */
|
|
27
|
-
elementGuidelines: HTMLElement[];
|
|
28
|
-
/** 布局方式:流式布局、绝对定位、固定定位 */
|
|
29
|
-
mode: Mode;
|
|
30
|
-
private moveableOptions;
|
|
11
|
+
private moveable?;
|
|
31
12
|
/** 拖动状态 */
|
|
32
13
|
private dragStatus;
|
|
33
|
-
|
|
34
|
-
private
|
|
35
|
-
private
|
|
36
|
-
private
|
|
14
|
+
private dragResizeHelper;
|
|
15
|
+
private getRenderDocument;
|
|
16
|
+
private markContainerEnd;
|
|
17
|
+
private delayedMarkContainer;
|
|
37
18
|
constructor(config: StageDragResizeConfig);
|
|
38
19
|
/**
|
|
39
20
|
* 将选中框渲染并覆盖到选中的组件Dom节点上方
|
|
40
|
-
*
|
|
21
|
+
* 当选中的节点不是absolute时,会创建一个新的节点出来作为拖拽目标
|
|
41
22
|
* @param el 选中组件的Dom节点元素
|
|
42
23
|
* @param event 鼠标事件
|
|
43
24
|
*/
|
|
@@ -46,17 +27,12 @@ export default class StageDragResize extends EventEmitter {
|
|
|
46
27
|
* 初始化选中框并渲染出来
|
|
47
28
|
*/
|
|
48
29
|
updateMoveable(el?: HTMLElement | undefined): void;
|
|
49
|
-
setGuidelines(type: GuidesType, guidelines: number[]): void;
|
|
50
|
-
clearGuides(): void;
|
|
51
30
|
clearSelectStatus(): void;
|
|
52
|
-
destroyDragEl(): void;
|
|
53
31
|
/**
|
|
54
32
|
* 销毁实例
|
|
55
33
|
*/
|
|
56
34
|
destroy(): void;
|
|
57
35
|
private init;
|
|
58
|
-
private setElementGuidelines;
|
|
59
|
-
private createGuidelineElements;
|
|
60
36
|
private initMoveable;
|
|
61
37
|
private bindResizeEvent;
|
|
62
38
|
private bindDragEvent;
|
|
@@ -64,9 +40,4 @@ export default class StageDragResize extends EventEmitter {
|
|
|
64
40
|
private bindScaleEvent;
|
|
65
41
|
private sort;
|
|
66
42
|
private update;
|
|
67
|
-
private generateGhostEl;
|
|
68
|
-
private setGhostElChildrenId;
|
|
69
|
-
private destroyGhostEl;
|
|
70
|
-
private getOptions;
|
|
71
|
-
private canContainerHighlight;
|
|
72
43
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
3
|
import Moveable from 'moveable';
|
|
4
|
-
import
|
|
5
|
-
import TargetCalibrate from './TargetCalibrate';
|
|
4
|
+
import TargetShadow from './TargetShadow';
|
|
6
5
|
import type { StageHighlightConfig } from './types';
|
|
7
6
|
export default class StageHighlight extends EventEmitter {
|
|
8
|
-
core: StageCore;
|
|
9
7
|
container: HTMLElement;
|
|
10
8
|
target?: HTMLElement;
|
|
11
9
|
moveable?: Moveable;
|
|
12
|
-
|
|
10
|
+
targetShadow: TargetShadow;
|
|
11
|
+
private getRootContainer;
|
|
13
12
|
constructor(config: StageHighlightConfig);
|
|
14
13
|
/**
|
|
15
14
|
* 高亮鼠标悬停的组件
|
package/types/StageMask.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Mode } from './const';
|
|
2
2
|
import Rule from './Rule';
|
|
3
|
-
import type StageCore from './StageCore';
|
|
4
|
-
import type { StageMaskConfig } from './types';
|
|
5
3
|
/**
|
|
6
4
|
* 蒙层
|
|
7
5
|
* @description 用于拦截页面的点击动作,避免点击时触发组件自身动作;在编辑器中点击组件应当是选中组件;
|
|
@@ -9,9 +7,7 @@ import type { StageMaskConfig } from './types';
|
|
|
9
7
|
export default class StageMask extends Rule {
|
|
10
8
|
content: HTMLDivElement;
|
|
11
9
|
wrapper: HTMLDivElement;
|
|
12
|
-
core: StageCore;
|
|
13
10
|
page: HTMLElement | null;
|
|
14
|
-
pageScrollParent: HTMLElement | null;
|
|
15
11
|
scrollTop: number;
|
|
16
12
|
scrollLeft: number;
|
|
17
13
|
width: number;
|
|
@@ -20,24 +16,28 @@ export default class StageMask extends Rule {
|
|
|
20
16
|
wrapperWidth: number;
|
|
21
17
|
maxScrollTop: number;
|
|
22
18
|
maxScrollLeft: number;
|
|
23
|
-
intersectionObserver: IntersectionObserver | null;
|
|
24
|
-
isMultiSelectStatus: Boolean;
|
|
25
19
|
private mode;
|
|
26
|
-
private
|
|
20
|
+
private pageScrollParent;
|
|
21
|
+
private intersectionObserver;
|
|
27
22
|
private wrapperResizeObserver;
|
|
28
|
-
|
|
29
|
-
* 高亮事件处理函数
|
|
30
|
-
* @param event 事件对象
|
|
31
|
-
*/
|
|
32
|
-
private highlightHandler;
|
|
33
|
-
constructor(config: StageMaskConfig);
|
|
23
|
+
constructor();
|
|
34
24
|
setMode(mode: Mode): void;
|
|
35
25
|
/**
|
|
36
|
-
*
|
|
37
|
-
* @description
|
|
26
|
+
* 初始化视窗和蒙层监听,监听元素是否在视窗区域、监听mask蒙层所在的wrapper大小变化
|
|
27
|
+
* @description 初始化视窗和蒙层监听
|
|
38
28
|
* @param page 页面Dom节点
|
|
39
29
|
*/
|
|
40
30
|
observe(page: HTMLElement): void;
|
|
31
|
+
/**
|
|
32
|
+
* 处理页面大小变更,同步页面和mask大小
|
|
33
|
+
* @param entries ResizeObserverEntry,获取页面最新大小
|
|
34
|
+
*/
|
|
35
|
+
pageResize(entries: ResizeObserverEntry[]): void;
|
|
36
|
+
/**
|
|
37
|
+
* 监听一个组件是否在画布可视区域内
|
|
38
|
+
* @param el 被选中的组件,可能是左侧目录树中选中的
|
|
39
|
+
*/
|
|
40
|
+
observerIntersection(el: HTMLElement): void;
|
|
41
41
|
/**
|
|
42
42
|
* 挂载Dom节点
|
|
43
43
|
* @param el 将蒙层挂载到该Dom节点上
|
|
@@ -49,6 +49,14 @@ export default class StageMask extends Rule {
|
|
|
49
49
|
* 销毁实例
|
|
50
50
|
*/
|
|
51
51
|
destroy(): void;
|
|
52
|
+
/**
|
|
53
|
+
* 监听选中元素是否在画布可视区域内,如果目标元素不在可视区域内,通过滚动使该元素出现在可视区域
|
|
54
|
+
*/
|
|
55
|
+
private initObserverIntersection;
|
|
56
|
+
/**
|
|
57
|
+
* 监听mask的容器大小变化
|
|
58
|
+
*/
|
|
59
|
+
private initObserverWrapper;
|
|
52
60
|
private scroll;
|
|
53
61
|
private scrollTo;
|
|
54
62
|
/**
|
|
@@ -74,12 +82,5 @@ export default class StageMask extends Rule {
|
|
|
74
82
|
* 由于滚动容器变化等因素,会导致当前滚动的距离不正确
|
|
75
83
|
*/
|
|
76
84
|
private fixScrollValue;
|
|
77
|
-
/**
|
|
78
|
-
* 点击事件处理函数
|
|
79
|
-
* @param event 事件对象
|
|
80
|
-
*/
|
|
81
|
-
private mouseDownHandler;
|
|
82
|
-
private mouseUpHandler;
|
|
83
85
|
private mouseWheelHandler;
|
|
84
|
-
private mouseLeaveHandler;
|
|
85
86
|
}
|
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
1
|
import Moveable from 'moveable';
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
export default class StageMultiDragResize extends EventEmitter {
|
|
8
|
-
core: StageCore;
|
|
9
|
-
mask: StageMask;
|
|
2
|
+
import MoveableOptionsManager from './MoveableOptionsManager';
|
|
3
|
+
import { StageDragStatus, StageMultiDragResizeConfig } from './types';
|
|
4
|
+
export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
10
5
|
/** 画布容器 */
|
|
11
6
|
container: HTMLElement;
|
|
12
7
|
/** 多选:目标节点组 */
|
|
13
8
|
targetList: HTMLElement[];
|
|
14
|
-
/** 多选:目标节点在蒙层中的占位节点组 */
|
|
15
|
-
dragElList: HTMLDivElement[];
|
|
16
9
|
/** Moveable多选拖拽类实例 */
|
|
17
10
|
moveableForMulti?: Moveable;
|
|
18
|
-
/** 拖动状态 */
|
|
19
11
|
dragStatus: StageDragStatus;
|
|
20
|
-
private
|
|
21
|
-
|
|
12
|
+
private dragResizeHelper;
|
|
13
|
+
private getRenderDocument;
|
|
14
|
+
constructor(config: StageMultiDragResizeConfig);
|
|
22
15
|
/**
|
|
23
16
|
* 多选
|
|
24
17
|
* @param els
|
|
25
18
|
*/
|
|
26
19
|
multiSelect(els: HTMLElement[]): void;
|
|
27
|
-
canSelect(el: HTMLElement,
|
|
20
|
+
canSelect(el: HTMLElement, selectedEl: HTMLElement | undefined): boolean;
|
|
21
|
+
updateMoveable(eleList?: HTMLElement[]): void;
|
|
28
22
|
/**
|
|
29
23
|
* 清除多选状态
|
|
30
24
|
*/
|
|
@@ -33,19 +27,9 @@ export default class StageMultiDragResize extends EventEmitter {
|
|
|
33
27
|
* 销毁实例
|
|
34
28
|
*/
|
|
35
29
|
destroy(): void;
|
|
36
|
-
/**
|
|
37
|
-
* 清除蒙层占位节点
|
|
38
|
-
*/
|
|
39
|
-
destroyDragElList(): void;
|
|
40
30
|
/**
|
|
41
31
|
* 拖拽完成后将更新的位置信息暴露给上层业务方,业务方可以接收事件进行保存
|
|
42
32
|
* @param isResize 是否进行大小缩放
|
|
43
33
|
*/
|
|
44
34
|
private update;
|
|
45
|
-
/**
|
|
46
|
-
* 获取moveable options参数
|
|
47
|
-
* @param {MoveableOptions} options
|
|
48
|
-
* @return {MoveableOptions} moveable options参数
|
|
49
|
-
*/
|
|
50
|
-
private getOptions;
|
|
51
35
|
}
|
package/types/StageRender.d.ts
CHANGED
|
@@ -1,30 +1,48 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import
|
|
4
|
-
import type { Runtime, RuntimeWindow, StageRenderConfig } from './types';
|
|
3
|
+
import { Id } from '@tmagic/schema';
|
|
4
|
+
import type { Point, RemoveData, Runtime, RuntimeWindow, StageRenderConfig, UpdateData } from './types';
|
|
5
5
|
export default class StageRender extends EventEmitter {
|
|
6
6
|
/** 组件的js、css执行的环境,直接渲染为当前window,iframe渲染则为iframe.contentWindow */
|
|
7
7
|
contentWindow: RuntimeWindow | null;
|
|
8
8
|
runtime: Runtime | null;
|
|
9
9
|
iframe?: HTMLIFrameElement;
|
|
10
|
-
runtimeUrl
|
|
11
|
-
|
|
12
|
-
private
|
|
13
|
-
constructor({
|
|
10
|
+
private runtimeUrl?;
|
|
11
|
+
private zoom;
|
|
12
|
+
private customizedRender?;
|
|
13
|
+
constructor({ runtimeUrl, zoom, customizedRender }: StageRenderConfig);
|
|
14
14
|
getMagicApi: () => {
|
|
15
15
|
onPageElUpdate: (el: HTMLElement) => boolean;
|
|
16
16
|
onRuntimeReady: (runtime: Runtime) => void;
|
|
17
17
|
};
|
|
18
|
+
add(data: UpdateData): Promise<void>;
|
|
19
|
+
remove(data: RemoveData): Promise<void>;
|
|
20
|
+
update(data: UpdateData): Promise<void>;
|
|
21
|
+
select(els: HTMLElement[]): Promise<void>;
|
|
22
|
+
setZoom(zoom?: number): void;
|
|
18
23
|
/**
|
|
19
24
|
* 挂载Dom节点
|
|
20
25
|
* @param el 将页面挂载到该Dom节点上
|
|
21
26
|
*/
|
|
22
27
|
mount(el: HTMLDivElement): Promise<void>;
|
|
23
28
|
getRuntime: () => Promise<Runtime>;
|
|
29
|
+
getDocument(): Document | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* 通过坐标获得坐标下所有HTML元素数组
|
|
32
|
+
* @param point 坐标
|
|
33
|
+
* @returns 坐标下方所有HTML元素数组,会包含父元素直至html,元素层叠时返回顺序是从上到下
|
|
34
|
+
*/
|
|
35
|
+
getElementsFromPoint(point: Point): HTMLElement[];
|
|
36
|
+
getTargetElement(idOrEl: Id | HTMLElement): HTMLElement;
|
|
24
37
|
/**
|
|
25
38
|
* 销毁实例
|
|
26
39
|
*/
|
|
27
40
|
destroy(): void;
|
|
41
|
+
/**
|
|
42
|
+
* 在runtime中对被选中的元素进行标记,部分组件有对选中态进行特殊显示的需求
|
|
43
|
+
* @param el 被选中的元素
|
|
44
|
+
*/
|
|
45
|
+
private flagSelectedEl;
|
|
28
46
|
private loadHandler;
|
|
29
47
|
private postTmagicRuntimeReady;
|
|
30
48
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TargetElement as ShadowElement, TargetShadowConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 将选中的节点修正定位后,添加一个操作节点到蒙层上
|
|
4
|
+
*/
|
|
5
|
+
export default class TargetShadow {
|
|
6
|
+
el?: ShadowElement;
|
|
7
|
+
els: ShadowElement[];
|
|
8
|
+
private idPrefix;
|
|
9
|
+
private container;
|
|
10
|
+
private scrollLeft;
|
|
11
|
+
private scrollTop;
|
|
12
|
+
private zIndex?;
|
|
13
|
+
private updateDragEl?;
|
|
14
|
+
constructor(config: TargetShadowConfig);
|
|
15
|
+
update(target: ShadowElement): ShadowElement;
|
|
16
|
+
updateGroup(targetGroup: ShadowElement[]): ShadowElement[];
|
|
17
|
+
destroyEl(): void;
|
|
18
|
+
destroyEls(): void;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
private updateEl;
|
|
21
|
+
private scrollHandler;
|
|
22
|
+
}
|
package/types/const.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const GHOST_EL_ID_PREFIX = "ghost_el_";
|
|
|
4
4
|
export declare const DRAG_EL_ID_PREFIX = "drag_el_";
|
|
5
5
|
/** 高亮时需要在蒙层中创建一个占位节点,该节点的id前缀 */
|
|
6
6
|
export declare const HIGHLIGHT_EL_ID_PREFIX = "highlight_el_";
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const CONTAINER_HIGHLIGHT_CLASS_NAME = "tmagic-stage-container-highlight";
|
|
8
8
|
export declare const PAGE_CLASS = "magic-ui-page";
|
|
9
9
|
/** 默认放到缩小倍数 */
|
|
10
10
|
export declare const DEFAULT_ZOOM = 1;
|
package/types/types.d.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { MoveableOptions } from 'moveable';
|
|
2
3
|
import Core from '@tmagic/core';
|
|
3
4
|
import type { Id, MApp, MContainer, MNode } from '@tmagic/schema';
|
|
4
|
-
import { GuidesType } from './const';
|
|
5
|
+
import { GuidesType, ZIndex } from './const';
|
|
5
6
|
import StageCore from './StageCore';
|
|
6
|
-
|
|
7
|
-
import StageMask from './StageMask';
|
|
7
|
+
export declare type TargetElement = HTMLElement | SVGElement;
|
|
8
8
|
export declare type CanSelect = (el: HTMLElement, event: MouseEvent, stop: () => boolean) => boolean | Promise<boolean>;
|
|
9
9
|
export declare type IsContainer = (el: HTMLElement) => boolean | Promise<boolean>;
|
|
10
|
+
export declare type CustomizeRender = (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
|
|
11
|
+
/** 业务方自定义的moveableOptions,可以是配置,也可以是回调函数 */
|
|
12
|
+
export declare type CustomizeMoveableOptions = ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions) | MoveableOptions | undefined;
|
|
13
|
+
/** render提供给的接口,如果是id则转成el,如果是el则直接返回 */
|
|
14
|
+
export declare type GetTargetElement = (idOrEl: Id | HTMLElement) => HTMLElement;
|
|
15
|
+
/** render提供的接口,通过坐标获得坐标下所有HTML元素数组 */
|
|
16
|
+
export declare type GetElementsFromPoint = (point: Point) => HTMLElement[];
|
|
17
|
+
export declare type GetRenderDocument = () => Document | undefined;
|
|
18
|
+
export declare type DelayedMarkContainer = (event: MouseEvent, exclude: Element[]) => NodeJS.Timeout | undefined;
|
|
19
|
+
export declare type MarkContainerEnd = () => HTMLElement | null;
|
|
20
|
+
export declare type GetRootContainer = () => HTMLDivElement | undefined;
|
|
21
|
+
/** 将组件添加到容器的方式 */
|
|
10
22
|
export declare enum ContainerHighlightType {
|
|
23
|
+
/** 默认方式:组件在容器上方悬停一段时间后加入 */
|
|
11
24
|
DEFAULT = "default",
|
|
25
|
+
/** 按住alt键,并在容器上方悬停一段时间后加入 */
|
|
12
26
|
ALT = "alt"
|
|
13
27
|
}
|
|
14
|
-
export declare type
|
|
28
|
+
export declare type UpdateDragEl = (el: TargetElement, target: TargetElement) => void;
|
|
29
|
+
export interface StageCoreConfig {
|
|
15
30
|
/** 需要对齐的dom节点的CSS选择器字符串 */
|
|
16
31
|
snapElementQuerySelector?: string;
|
|
17
32
|
/** 放大倍数,默认1倍 */
|
|
@@ -21,24 +36,71 @@ export declare type StageCoreConfig = {
|
|
|
21
36
|
containerHighlightClassName?: string;
|
|
22
37
|
containerHighlightDuration?: number;
|
|
23
38
|
containerHighlightType?: ContainerHighlightType;
|
|
24
|
-
moveableOptions?:
|
|
25
|
-
multiMoveableOptions?:
|
|
39
|
+
moveableOptions?: CustomizeMoveableOptions;
|
|
40
|
+
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
26
41
|
/** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
|
|
27
42
|
runtimeUrl?: string;
|
|
28
43
|
render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
|
|
29
44
|
autoScrollIntoView?: boolean;
|
|
30
|
-
updateDragEl?:
|
|
31
|
-
}
|
|
45
|
+
updateDragEl?: UpdateDragEl;
|
|
46
|
+
}
|
|
47
|
+
export interface ActionManagerConfig {
|
|
48
|
+
container: HTMLElement;
|
|
49
|
+
containerHighlightClassName?: string;
|
|
50
|
+
containerHighlightDuration?: number;
|
|
51
|
+
containerHighlightType?: ContainerHighlightType;
|
|
52
|
+
moveableOptions?: CustomizeMoveableOptions;
|
|
53
|
+
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
54
|
+
canSelect?: CanSelect;
|
|
55
|
+
isContainer: IsContainer;
|
|
56
|
+
getRootContainer: GetRootContainer;
|
|
57
|
+
getRenderDocument: GetRenderDocument;
|
|
58
|
+
updateDragEl?: UpdateDragEl;
|
|
59
|
+
getTargetElement: GetTargetElement;
|
|
60
|
+
getElementsFromPoint: GetElementsFromPoint;
|
|
61
|
+
}
|
|
62
|
+
export interface MoveableOptionsManagerConfig {
|
|
63
|
+
container: HTMLElement;
|
|
64
|
+
moveableOptions?: CustomizeMoveableOptions;
|
|
65
|
+
getRootContainer: GetRootContainer;
|
|
66
|
+
}
|
|
67
|
+
export interface CustomizeMoveableOptionsCallbackConfig {
|
|
68
|
+
targetElId?: string;
|
|
69
|
+
}
|
|
32
70
|
export interface StageRenderConfig {
|
|
33
|
-
|
|
71
|
+
runtimeUrl?: string;
|
|
72
|
+
zoom: number | undefined;
|
|
73
|
+
customizedRender?: () => Promise<HTMLElement | null>;
|
|
34
74
|
}
|
|
35
75
|
export interface StageMaskConfig {
|
|
36
76
|
core: StageCore;
|
|
37
77
|
}
|
|
38
78
|
export interface StageDragResizeConfig {
|
|
39
|
-
core: StageCore;
|
|
40
79
|
container: HTMLElement;
|
|
41
|
-
|
|
80
|
+
moveableOptions?: CustomizeMoveableOptions;
|
|
81
|
+
getRootContainer: GetRootContainer;
|
|
82
|
+
getRenderDocument: GetRenderDocument;
|
|
83
|
+
markContainerEnd: MarkContainerEnd;
|
|
84
|
+
delayedMarkContainer: DelayedMarkContainer;
|
|
85
|
+
updateDragEl?: UpdateDragEl;
|
|
86
|
+
}
|
|
87
|
+
export interface StageMultiDragResizeConfig {
|
|
88
|
+
container: HTMLElement;
|
|
89
|
+
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
90
|
+
getRootContainer: GetRootContainer;
|
|
91
|
+
getRenderDocument: GetRenderDocument;
|
|
92
|
+
updateDragEl?: UpdateDragEl;
|
|
93
|
+
}
|
|
94
|
+
export interface DragResizeHelperConfig {
|
|
95
|
+
container: HTMLElement;
|
|
96
|
+
updateDragEl?: UpdateDragEl;
|
|
97
|
+
}
|
|
98
|
+
/** 选择状态 */
|
|
99
|
+
export declare enum SelectStatus {
|
|
100
|
+
/** 单选 */
|
|
101
|
+
SELECT = "select",
|
|
102
|
+
/** 多选 */
|
|
103
|
+
MULTI_SELECT = "multiSelect"
|
|
42
104
|
}
|
|
43
105
|
/** 拖动状态 */
|
|
44
106
|
export declare enum StageDragStatus {
|
|
@@ -57,6 +119,10 @@ export interface Offset {
|
|
|
57
119
|
left: number;
|
|
58
120
|
top: number;
|
|
59
121
|
}
|
|
122
|
+
export interface Point {
|
|
123
|
+
clientX: number;
|
|
124
|
+
clientY: number;
|
|
125
|
+
}
|
|
60
126
|
export interface GuidesEventData {
|
|
61
127
|
type: GuidesType;
|
|
62
128
|
guides: number[];
|
|
@@ -114,12 +180,13 @@ export interface RuntimeWindow extends Window {
|
|
|
114
180
|
magic: Magic;
|
|
115
181
|
}
|
|
116
182
|
export interface StageHighlightConfig {
|
|
117
|
-
core: StageCore;
|
|
118
183
|
container: HTMLElement;
|
|
184
|
+
updateDragEl?: UpdateDragEl;
|
|
185
|
+
getRootContainer: GetRootContainer;
|
|
119
186
|
}
|
|
120
|
-
export interface
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
187
|
+
export interface TargetShadowConfig {
|
|
188
|
+
container: HTMLElement;
|
|
189
|
+
zIndex?: ZIndex;
|
|
190
|
+
updateDragEl?: UpdateDragEl;
|
|
191
|
+
idPrefix?: string;
|
|
125
192
|
}
|
package/types/util.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Mode } from './const';
|
|
2
|
-
import type { Offset, SortEventData } from './types';
|
|
3
|
-
export declare const getOffset: (el:
|
|
4
|
-
export declare const getTargetElStyle: (el:
|
|
1
|
+
import { Mode, ZIndex } from './const';
|
|
2
|
+
import type { Offset, SortEventData, TargetElement } from './types';
|
|
3
|
+
export declare const getOffset: (el: TargetElement) => Offset;
|
|
4
|
+
export declare const getTargetElStyle: (el: TargetElement, zIndex?: ZIndex) => string;
|
|
5
5
|
export declare const getAbsolutePosition: (el: HTMLElement, { top, left }: Offset) => {
|
|
6
6
|
left: number;
|
|
7
7
|
top: number;
|
|
@@ -10,8 +10,8 @@ export declare const isAbsolute: (style: CSSStyleDeclaration) => boolean;
|
|
|
10
10
|
export declare const isRelative: (style: CSSStyleDeclaration) => boolean;
|
|
11
11
|
export declare const isStatic: (style: CSSStyleDeclaration) => boolean;
|
|
12
12
|
export declare const isFixed: (style: CSSStyleDeclaration) => boolean;
|
|
13
|
-
export declare const isFixedParent: (el:
|
|
14
|
-
export declare const getMode: (el:
|
|
13
|
+
export declare const isFixedParent: (el: Element) => boolean;
|
|
14
|
+
export declare const getMode: (el: Element) => Mode;
|
|
15
15
|
export declare const getScrollParent: (element: HTMLElement, includeHidden?: boolean) => HTMLElement | null;
|
|
16
16
|
export declare const removeSelectedClassName: (doc: Document) => void;
|
|
17
17
|
export declare const addSelectedClassName: (el: Element, doc: Document) => void;
|
|
@@ -21,7 +21,7 @@ export declare const calcValueByFontsize: (doc: Document, value: number) => numb
|
|
|
21
21
|
* @param {number} deltaTop 偏移量
|
|
22
22
|
* @param {Object} detail 当前选中的组件配置
|
|
23
23
|
*/
|
|
24
|
-
export declare const down: (deltaTop: number, target:
|
|
24
|
+
export declare const down: (deltaTop: number, target: TargetElement) => SortEventData | void;
|
|
25
25
|
/**
|
|
26
26
|
* 上移组件位置
|
|
27
27
|
* @param {Array} brothers 处于同一容器下的所有子组件配置
|
|
@@ -29,4 +29,5 @@ export declare const down: (deltaTop: number, target: HTMLElement | SVGElement)
|
|
|
29
29
|
* @param {number} deltaTop 偏移量
|
|
30
30
|
* @param {Object} detail 当前选中的组件配置
|
|
31
31
|
*/
|
|
32
|
-
export declare const up: (deltaTop: number, target:
|
|
32
|
+
export declare const up: (deltaTop: number, target: TargetElement) => SortEventData | void;
|
|
33
|
+
export declare const isMoveableButton: (target: Element) => boolean | undefined;
|