@tmagic/stage 1.2.0-beta.9 → 1.2.1
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.mjs → tmagic-stage.js} +1395 -1062
- package/dist/tmagic-stage.js.map +1 -0
- package/dist/{tmagic-stage.umd.js → tmagic-stage.umd.cjs} +1393 -1060
- package/dist/tmagic-stage.umd.cjs.map +1 -0
- package/package.json +9 -8
- package/src/ActionManager.ts +535 -0
- package/src/DragResizeHelper.ts +338 -0
- package/src/MoveableOptionsManager.ts +249 -0
- package/src/MoveableSelectParentAble.ts +3 -5
- package/src/Rule.ts +4 -4
- package/src/StageCore.ts +204 -276
- package/src/StageDragResize.ts +87 -349
- package/src/StageHighlight.ts +18 -17
- package/src/StageMask.ts +20 -103
- package/src/StageMultiDragResize.ts +98 -199
- package/src/StageRender.ts +86 -11
- package/src/TargetShadow.ts +120 -0
- package/src/const.ts +2 -2
- package/src/index.ts +1 -1
- package/src/logger.ts +1 -1
- package/src/types.ts +100 -20
- package/src/util.ts +19 -12
- 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 +1 -2
- package/types/StageCore.d.ts +58 -41
- package/types/StageDragResize.d.ts +12 -40
- package/types/StageHighlight.d.ts +3 -4
- package/types/StageMask.d.ts +0 -21
- package/types/StageMultiDragResize.d.ts +8 -24
- package/types/StageRender.d.ts +23 -4
- package/types/TargetShadow.d.ts +22 -0
- package/types/const.d.ts +1 -1
- package/types/types.d.ts +87 -18
- package/types/util.d.ts +8 -8
- 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/StageRender.d.ts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import
|
|
3
|
+
import { Id } from '@tmagic/schema';
|
|
4
|
+
import type { Point, RemoveData, Runtime, RuntimeWindow, StageRenderConfig, UpdateData } from './types';
|
|
4
5
|
export default class StageRender extends EventEmitter {
|
|
5
6
|
/** 组件的js、css执行的环境,直接渲染为当前window,iframe渲染则为iframe.contentWindow */
|
|
6
7
|
contentWindow: RuntimeWindow | null;
|
|
7
8
|
runtime: Runtime | null;
|
|
8
9
|
iframe?: HTMLIFrameElement;
|
|
9
|
-
runtimeUrl
|
|
10
|
-
private
|
|
11
|
-
|
|
10
|
+
private runtimeUrl?;
|
|
11
|
+
private zoom;
|
|
12
|
+
private customizedRender?;
|
|
13
|
+
constructor({ runtimeUrl, zoom, customizedRender }: StageRenderConfig);
|
|
12
14
|
getMagicApi: () => {
|
|
13
15
|
onPageElUpdate: (el: HTMLElement) => boolean;
|
|
14
16
|
onRuntimeReady: (runtime: Runtime) => void;
|
|
15
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;
|
|
16
23
|
/**
|
|
17
24
|
* 挂载Dom节点
|
|
18
25
|
* @param el 将页面挂载到该Dom节点上
|
|
@@ -20,10 +27,22 @@ export default class StageRender extends EventEmitter {
|
|
|
20
27
|
mount(el: HTMLDivElement): Promise<void>;
|
|
21
28
|
getRuntime: () => Promise<Runtime>;
|
|
22
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;
|
|
23
37
|
/**
|
|
24
38
|
* 销毁实例
|
|
25
39
|
*/
|
|
26
40
|
destroy(): void;
|
|
41
|
+
/**
|
|
42
|
+
* 在runtime中对被选中的元素进行标记,部分组件有对选中态进行特殊显示的需求
|
|
43
|
+
* @param el 被选中的元素
|
|
44
|
+
*/
|
|
45
|
+
private flagSelectedEl;
|
|
27
46
|
private loadHandler;
|
|
28
47
|
private postTmagicRuntimeReady;
|
|
29
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,25 +36,74 @@ 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
|
+
disabledDragStart?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface ActionManagerConfig {
|
|
49
|
+
container: HTMLElement;
|
|
50
|
+
containerHighlightClassName?: string;
|
|
51
|
+
containerHighlightDuration?: number;
|
|
52
|
+
containerHighlightType?: ContainerHighlightType;
|
|
53
|
+
moveableOptions?: CustomizeMoveableOptions;
|
|
54
|
+
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
55
|
+
disabledDragStart?: boolean;
|
|
56
|
+
canSelect?: CanSelect;
|
|
57
|
+
isContainer: IsContainer;
|
|
58
|
+
getRootContainer: GetRootContainer;
|
|
59
|
+
getRenderDocument: GetRenderDocument;
|
|
60
|
+
updateDragEl?: UpdateDragEl;
|
|
61
|
+
getTargetElement: GetTargetElement;
|
|
62
|
+
getElementsFromPoint: GetElementsFromPoint;
|
|
63
|
+
}
|
|
64
|
+
export interface MoveableOptionsManagerConfig {
|
|
65
|
+
container: HTMLElement;
|
|
66
|
+
moveableOptions?: CustomizeMoveableOptions;
|
|
67
|
+
getRootContainer: GetRootContainer;
|
|
68
|
+
}
|
|
69
|
+
export interface CustomizeMoveableOptionsCallbackConfig {
|
|
70
|
+
targetElId?: string;
|
|
71
|
+
}
|
|
32
72
|
export interface StageRenderConfig {
|
|
33
73
|
runtimeUrl?: string;
|
|
34
|
-
|
|
74
|
+
zoom: number | undefined;
|
|
75
|
+
customizedRender?: () => Promise<HTMLElement | null>;
|
|
35
76
|
}
|
|
36
77
|
export interface StageMaskConfig {
|
|
37
78
|
core: StageCore;
|
|
38
79
|
}
|
|
39
80
|
export interface StageDragResizeConfig {
|
|
40
|
-
core: StageCore;
|
|
41
81
|
container: HTMLElement;
|
|
42
|
-
|
|
82
|
+
moveableOptions?: CustomizeMoveableOptions;
|
|
83
|
+
disabledDragStart?: boolean;
|
|
84
|
+
getRootContainer: GetRootContainer;
|
|
85
|
+
getRenderDocument: GetRenderDocument;
|
|
86
|
+
markContainerEnd: MarkContainerEnd;
|
|
87
|
+
delayedMarkContainer: DelayedMarkContainer;
|
|
88
|
+
updateDragEl?: UpdateDragEl;
|
|
89
|
+
}
|
|
90
|
+
export interface StageMultiDragResizeConfig {
|
|
91
|
+
container: HTMLElement;
|
|
92
|
+
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
93
|
+
getRootContainer: GetRootContainer;
|
|
94
|
+
getRenderDocument: GetRenderDocument;
|
|
95
|
+
updateDragEl?: UpdateDragEl;
|
|
96
|
+
}
|
|
97
|
+
export interface DragResizeHelperConfig {
|
|
98
|
+
container: HTMLElement;
|
|
99
|
+
updateDragEl?: UpdateDragEl;
|
|
100
|
+
}
|
|
101
|
+
/** 选择状态 */
|
|
102
|
+
export declare enum SelectStatus {
|
|
103
|
+
/** 单选 */
|
|
104
|
+
SELECT = "select",
|
|
105
|
+
/** 多选 */
|
|
106
|
+
MULTI_SELECT = "multiSelect"
|
|
43
107
|
}
|
|
44
108
|
/** 拖动状态 */
|
|
45
109
|
export declare enum StageDragStatus {
|
|
@@ -58,6 +122,10 @@ export interface Offset {
|
|
|
58
122
|
left: number;
|
|
59
123
|
top: number;
|
|
60
124
|
}
|
|
125
|
+
export interface Point {
|
|
126
|
+
clientX: number;
|
|
127
|
+
clientY: number;
|
|
128
|
+
}
|
|
61
129
|
export interface GuidesEventData {
|
|
62
130
|
type: GuidesType;
|
|
63
131
|
guides: number[];
|
|
@@ -115,12 +183,13 @@ export interface RuntimeWindow extends Window {
|
|
|
115
183
|
magic: Magic;
|
|
116
184
|
}
|
|
117
185
|
export interface StageHighlightConfig {
|
|
118
|
-
core: StageCore;
|
|
119
186
|
container: HTMLElement;
|
|
187
|
+
updateDragEl?: UpdateDragEl;
|
|
188
|
+
getRootContainer: GetRootContainer;
|
|
120
189
|
}
|
|
121
|
-
export interface
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
190
|
+
export interface TargetShadowConfig {
|
|
191
|
+
container: HTMLElement;
|
|
192
|
+
zIndex?: ZIndex;
|
|
193
|
+
updateDragEl?: UpdateDragEl;
|
|
194
|
+
idPrefix?: string;
|
|
126
195
|
}
|
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,5 +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
33
|
export declare const isMoveableButton: (target: Element) => boolean | undefined;
|