@tmagic/stage 1.2.0-beta.17 → 1.2.0-beta.19
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 +1389 -1060
- package/dist/tmagic-stage.mjs.map +1 -1
- package/dist/tmagic-stage.umd.js +1387 -1058
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/package.json +4 -4
- package/src/ActionManager.ts +534 -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 +202 -275
- package/src/StageDragResize.ts +83 -347
- package/src/StageHighlight.ts +17 -16
- package/src/StageMask.ts +19 -102
- package/src/StageMultiDragResize.ts +97 -198
- package/src/StageRender.ts +85 -10
- package/src/TargetShadow.ts +120 -0
- package/src/const.ts +1 -1
- package/src/types.ts +95 -18
- package/src/util.ts +18 -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 +1 -2
- package/types/StageCore.d.ts +58 -41
- package/types/StageDragResize.d.ts +11 -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 +83 -17
- package/types/util.d.ts +8 -8
- package/src/TargetCalibrate.ts +0 -119
- package/types/TargetCalibrate.d.ts +0 -20
package/types/types.d.ts
CHANGED
|
@@ -1,17 +1,32 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
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,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;
|
|
34
|
-
|
|
72
|
+
zoom: number | undefined;
|
|
73
|
+
customizedRender?: () => Promise<HTMLElement | null>;
|
|
35
74
|
}
|
|
36
75
|
export interface StageMaskConfig {
|
|
37
76
|
core: StageCore;
|
|
38
77
|
}
|
|
39
78
|
export interface StageDragResizeConfig {
|
|
40
|
-
core: StageCore;
|
|
41
79
|
container: HTMLElement;
|
|
42
|
-
|
|
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"
|
|
43
104
|
}
|
|
44
105
|
/** 拖动状态 */
|
|
45
106
|
export declare enum StageDragStatus {
|
|
@@ -58,6 +119,10 @@ export interface Offset {
|
|
|
58
119
|
left: number;
|
|
59
120
|
top: number;
|
|
60
121
|
}
|
|
122
|
+
export interface Point {
|
|
123
|
+
clientX: number;
|
|
124
|
+
clientY: number;
|
|
125
|
+
}
|
|
61
126
|
export interface GuidesEventData {
|
|
62
127
|
type: GuidesType;
|
|
63
128
|
guides: number[];
|
|
@@ -115,12 +180,13 @@ export interface RuntimeWindow extends Window {
|
|
|
115
180
|
magic: Magic;
|
|
116
181
|
}
|
|
117
182
|
export interface StageHighlightConfig {
|
|
118
|
-
core: StageCore;
|
|
119
183
|
container: HTMLElement;
|
|
184
|
+
updateDragEl?: UpdateDragEl;
|
|
185
|
+
getRootContainer: GetRootContainer;
|
|
120
186
|
}
|
|
121
|
-
export interface
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
187
|
+
export interface TargetShadowConfig {
|
|
188
|
+
container: HTMLElement;
|
|
189
|
+
zIndex?: ZIndex;
|
|
190
|
+
updateDragEl?: UpdateDragEl;
|
|
191
|
+
idPrefix?: string;
|
|
126
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,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;
|
package/src/TargetCalibrate.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
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 { Mode, ZIndex } from './const';
|
|
22
|
-
import StageCore from './StageCore';
|
|
23
|
-
import StageDragResize from './StageDragResize';
|
|
24
|
-
import StageMask from './StageMask';
|
|
25
|
-
import type { Offset, TargetCalibrateConfig } from './types';
|
|
26
|
-
import { getMode } from './util';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 将选中的节点修正定位后,添加一个操作节点到蒙层上
|
|
30
|
-
*/
|
|
31
|
-
export default class TargetCalibrate extends EventEmitter {
|
|
32
|
-
public parent: HTMLElement;
|
|
33
|
-
public mask: StageMask;
|
|
34
|
-
public dr: StageDragResize;
|
|
35
|
-
public core: StageCore;
|
|
36
|
-
public operationEl: HTMLDivElement;
|
|
37
|
-
|
|
38
|
-
constructor(config: TargetCalibrateConfig) {
|
|
39
|
-
super();
|
|
40
|
-
|
|
41
|
-
this.parent = config.parent;
|
|
42
|
-
this.mask = config.mask;
|
|
43
|
-
this.dr = config.dr;
|
|
44
|
-
this.core = config.core;
|
|
45
|
-
|
|
46
|
-
this.operationEl = globalThis.document.createElement('div');
|
|
47
|
-
this.parent.append(this.operationEl);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public update(el: HTMLElement, prefix: String): HTMLElement {
|
|
51
|
-
const { left, top } = this.getOffset(el);
|
|
52
|
-
const { transform } = getComputedStyle(el);
|
|
53
|
-
this.operationEl.style.cssText = `
|
|
54
|
-
position: absolute;
|
|
55
|
-
transform: ${transform};
|
|
56
|
-
left: ${left}px;
|
|
57
|
-
top: ${top}px;
|
|
58
|
-
width: ${el.clientWidth}px;
|
|
59
|
-
height: ${el.clientHeight}px;
|
|
60
|
-
z-index: ${ZIndex.HIGHLIGHT_EL};
|
|
61
|
-
`;
|
|
62
|
-
|
|
63
|
-
this.operationEl.id = `${prefix}${el.id}`;
|
|
64
|
-
|
|
65
|
-
if (typeof this.core.config.updateDragEl === 'function') {
|
|
66
|
-
this.core.config.updateDragEl(this.operationEl, el);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return this.operationEl;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public destroy(): void {
|
|
73
|
-
this.operationEl?.remove();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private getOffset(el: HTMLElement): Offset {
|
|
77
|
-
const { offsetParent } = el;
|
|
78
|
-
|
|
79
|
-
const left = el.offsetLeft;
|
|
80
|
-
const top = el.offsetTop;
|
|
81
|
-
|
|
82
|
-
if (offsetParent) {
|
|
83
|
-
const parentOffset = this.getOffset(offsetParent as HTMLElement);
|
|
84
|
-
return {
|
|
85
|
-
left: left + parentOffset.left,
|
|
86
|
-
top: top + parentOffset.top,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 选中固定定位元素后editor-mask高度被置为视窗大小
|
|
91
|
-
if (this.dr.mode === Mode.FIXED) {
|
|
92
|
-
// 弹窗的情况
|
|
93
|
-
if (getMode(el) === Mode.FIXED) {
|
|
94
|
-
return {
|
|
95
|
-
left,
|
|
96
|
-
top,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
left: left - this.mask.scrollLeft,
|
|
102
|
-
top: top - this.mask.scrollTop,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// 无父元素的固定定位需按滚动值计算
|
|
107
|
-
if (getMode(el) === Mode.FIXED) {
|
|
108
|
-
return {
|
|
109
|
-
left: left + this.mask.scrollLeft,
|
|
110
|
-
top: top + this.mask.scrollTop,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
left,
|
|
116
|
-
top,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from 'events';
|
|
3
|
-
import StageCore from './StageCore';
|
|
4
|
-
import StageDragResize from './StageDragResize';
|
|
5
|
-
import StageMask from './StageMask';
|
|
6
|
-
import type { TargetCalibrateConfig } from './types';
|
|
7
|
-
/**
|
|
8
|
-
* 将选中的节点修正定位后,添加一个操作节点到蒙层上
|
|
9
|
-
*/
|
|
10
|
-
export default class TargetCalibrate extends EventEmitter {
|
|
11
|
-
parent: HTMLElement;
|
|
12
|
-
mask: StageMask;
|
|
13
|
-
dr: StageDragResize;
|
|
14
|
-
core: StageCore;
|
|
15
|
-
operationEl: HTMLDivElement;
|
|
16
|
-
constructor(config: TargetCalibrateConfig);
|
|
17
|
-
update(el: HTMLElement, prefix: String): HTMLElement;
|
|
18
|
-
destroy(): void;
|
|
19
|
-
private getOffset;
|
|
20
|
-
}
|