@tmagic/stage 1.1.0-beta.5 → 1.1.0-beta.8
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 → tmagic-stage.mjs} +216 -158
- package/dist/tmagic-stage.mjs.map +1 -0
- package/dist/tmagic-stage.umd.js +228 -170
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/package.json +13 -11
- package/src/StageCore.ts +14 -5
- package/src/StageDragResize.ts +1 -1
- package/src/StageMask.ts +10 -3
- package/src/StageMultiDragResize.ts +12 -8
- package/src/types.ts +1 -1
- package/tsconfig.build.json +13 -0
- package/{dist/types/src → types}/Rule.d.ts +0 -0
- package/{dist/types/src → types}/StageCore.d.ts +6 -0
- package/{dist/types/src → types}/StageDragResize.d.ts +0 -0
- package/{dist/types/src → types}/StageHighlight.d.ts +0 -0
- package/{dist/types/src → types}/StageMask.d.ts +0 -0
- package/{dist/types/src → types}/StageMultiDragResize.d.ts +1 -1
- package/{dist/types/src → types}/StageRender.d.ts +0 -0
- package/{dist/types/src → types}/TargetCalibrate.d.ts +0 -0
- package/{dist/types/src → types}/const.d.ts +0 -0
- package/{dist/types/src → types}/index.d.ts +0 -0
- package/types/logger.d.ts +5 -0
- package/{dist/types/src → types}/types.d.ts +1 -1
- package/{dist/types/src → types}/util.d.ts +0 -0
- package/dist/tmagic-stage.es.js.map +0 -1
- package/dist/types/src/vite-env.d.ts +0 -1
- package/src/vite-env.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.1.0-beta.
|
|
2
|
+
"version": "1.1.0-beta.8",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*"
|
|
6
6
|
],
|
|
7
7
|
"main": "dist/tmagic-stage.umd.js",
|
|
8
|
-
"module": "dist/tmagic-stage.
|
|
9
|
-
"types": "
|
|
8
|
+
"module": "dist/tmagic-stage.mjs",
|
|
9
|
+
"types": "types/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"import": "./dist/tmagic-stage.
|
|
12
|
+
"import": "./dist/tmagic-stage.mjs",
|
|
13
13
|
"require": "./dist/tmagic-stage.umd.js"
|
|
14
14
|
},
|
|
15
15
|
"./*": "./*"
|
|
16
16
|
},
|
|
17
17
|
"license": "Apache-2.0",
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "vite build"
|
|
19
|
+
"build": "npm run build:type && vite build",
|
|
20
|
+
"build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
|
|
21
|
+
"clear:type": "rimraf ./types"
|
|
20
22
|
},
|
|
21
23
|
"engines": {
|
|
22
24
|
"node": ">=14"
|
|
@@ -27,9 +29,9 @@
|
|
|
27
29
|
},
|
|
28
30
|
"dependencies": {
|
|
29
31
|
"@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.
|
|
32
|
+
"@tmagic/core": "1.1.0-beta.8",
|
|
33
|
+
"@tmagic/schema": "1.1.0-beta.8",
|
|
34
|
+
"@tmagic/utils": "1.1.0-beta.8",
|
|
33
35
|
"events": "^3.3.0",
|
|
34
36
|
"keycon": "^1.1.2",
|
|
35
37
|
"lodash-es": "^4.17.21",
|
|
@@ -40,9 +42,9 @@
|
|
|
40
42
|
"@types/events": "^3.0.0",
|
|
41
43
|
"@types/lodash-es": "^4.17.4",
|
|
42
44
|
"@types/node": "^15.12.4",
|
|
45
|
+
"rimraf": "^3.0.2",
|
|
43
46
|
"sass": "^1.35.1",
|
|
44
|
-
"typescript": "^4.
|
|
45
|
-
"vite": "^
|
|
46
|
-
"vite-plugin-dts": "^0.9.6"
|
|
47
|
+
"typescript": "^4.7.4",
|
|
48
|
+
"vite": "^3.0.4"
|
|
47
49
|
}
|
|
48
50
|
}
|
package/src/StageCore.ts
CHANGED
|
@@ -114,7 +114,6 @@ export default class StageCore extends EventEmitter {
|
|
|
114
114
|
.on('beforeMultiSelect', async (event: MouseEvent) => {
|
|
115
115
|
const el = await this.getElementFromPoint(event);
|
|
116
116
|
if (!el) return;
|
|
117
|
-
this.clearSelectStatus('select');
|
|
118
117
|
// 如果已有单选选中元素,不是magic-ui-page就可以加入多选列表
|
|
119
118
|
if (this.selectedDom && !this.selectedDom.className.includes(PAGE_CLASS)) {
|
|
120
119
|
this.selectedDomList.push(this.selectedDom as HTMLElement);
|
|
@@ -128,8 +127,7 @@ export default class StageCore extends EventEmitter {
|
|
|
128
127
|
} else {
|
|
129
128
|
this.selectedDomList.push(el);
|
|
130
129
|
}
|
|
131
|
-
this.
|
|
132
|
-
this.emit('multiSelect', this.selectedDomList);
|
|
130
|
+
this.multiSelect(this.selectedDomList);
|
|
133
131
|
});
|
|
134
132
|
|
|
135
133
|
// 要先触发select,在触发update
|
|
@@ -182,7 +180,7 @@ export default class StageCore extends EventEmitter {
|
|
|
182
180
|
if (!canSelectByProp) return false;
|
|
183
181
|
// 多选规则
|
|
184
182
|
if (this.mask.isMultiSelectStatus) {
|
|
185
|
-
return this.multiDr.canSelect(el);
|
|
183
|
+
return this.multiDr.canSelect(el, stop);
|
|
186
184
|
}
|
|
187
185
|
return true;
|
|
188
186
|
}
|
|
@@ -222,6 +220,17 @@ export default class StageCore extends EventEmitter {
|
|
|
222
220
|
}
|
|
223
221
|
}
|
|
224
222
|
|
|
223
|
+
/**
|
|
224
|
+
* 多选
|
|
225
|
+
* @param domList 多选节点
|
|
226
|
+
*/
|
|
227
|
+
public async multiSelect(idOrElList: HTMLElement[] | Id[]): Promise<void> {
|
|
228
|
+
this.clearSelectStatus('select');
|
|
229
|
+
const elList = await Promise.all(idOrElList.map(async (idOrEl) => await this.getTargetElement(idOrEl)));
|
|
230
|
+
this.multiDr.multiSelect(elList);
|
|
231
|
+
this.emit('multiSelect', elList);
|
|
232
|
+
}
|
|
233
|
+
|
|
225
234
|
/**
|
|
226
235
|
* 更新选中的节点
|
|
227
236
|
* @param data 更新的数据
|
|
@@ -328,7 +337,7 @@ export default class StageCore extends EventEmitter {
|
|
|
328
337
|
}
|
|
329
338
|
}
|
|
330
339
|
|
|
331
|
-
public getAddContainerHighlightClassNameTimeout(event: MouseEvent, exclude: Element[] = []) {
|
|
340
|
+
public getAddContainerHighlightClassNameTimeout(event: MouseEvent, exclude: Element[] = []): NodeJS.Timeout {
|
|
332
341
|
return globalThis.setTimeout(() => {
|
|
333
342
|
this.addContainerHighlightClassName(event, exclude);
|
|
334
343
|
}, this.containerHighlightDuration);
|
package/src/StageDragResize.ts
CHANGED
|
@@ -484,7 +484,7 @@ export default class StageDragResize extends EventEmitter {
|
|
|
484
484
|
}
|
|
485
485
|
|
|
486
486
|
private setGhostElChildrenId(el: Element) {
|
|
487
|
-
for (const child of el.children) {
|
|
487
|
+
for (const child of Array.from(el.children)) {
|
|
488
488
|
if (child.id) {
|
|
489
489
|
child.id = `${GHOST_EL_ID_PREFIX}${child.id}`;
|
|
490
490
|
}
|
package/src/StageMask.ts
CHANGED
|
@@ -108,11 +108,16 @@ export default class StageMask extends Rule {
|
|
|
108
108
|
this.content.addEventListener('wheel', this.mouseWheelHandler);
|
|
109
109
|
this.content.addEventListener('mousemove', this.highlightHandler);
|
|
110
110
|
this.content.addEventListener('mouseleave', this.mouseLeaveHandler);
|
|
111
|
-
|
|
111
|
+
|
|
112
|
+
const isMac = /mac os x/.test(navigator.userAgent.toLowerCase());
|
|
113
|
+
|
|
114
|
+
const ctrl = isMac ? 'meta' : 'ctrl';
|
|
115
|
+
|
|
116
|
+
KeyController.global.keydown(ctrl, (e) => {
|
|
112
117
|
e.inputEvent.preventDefault();
|
|
113
118
|
this.isMultiSelectStatus = true;
|
|
114
119
|
});
|
|
115
|
-
KeyController.global.keyup(
|
|
120
|
+
KeyController.global.keyup(ctrl, (e) => {
|
|
116
121
|
e.inputEvent.preventDefault();
|
|
117
122
|
this.isMultiSelectStatus = false;
|
|
118
123
|
});
|
|
@@ -331,7 +336,9 @@ export default class StageMask extends Rule {
|
|
|
331
336
|
private mouseUpHandler = (): void => {
|
|
332
337
|
globalThis.document.removeEventListener('mouseup', this.mouseUpHandler);
|
|
333
338
|
this.content.addEventListener('mousemove', this.highlightHandler);
|
|
334
|
-
this.
|
|
339
|
+
if (!this.isMultiSelectStatus) {
|
|
340
|
+
this.emit('select');
|
|
341
|
+
}
|
|
335
342
|
};
|
|
336
343
|
|
|
337
344
|
private mouseWheelHandler = (event: WheelEvent) => {
|
|
@@ -70,7 +70,6 @@ export default class StageMultiDragResize extends EventEmitter {
|
|
|
70
70
|
});
|
|
71
71
|
this.moveableForMulti?.destroy();
|
|
72
72
|
this.multiMoveableHelper?.clear();
|
|
73
|
-
|
|
74
73
|
this.moveableForMulti = new Moveable(
|
|
75
74
|
this.container,
|
|
76
75
|
this.getOptions({
|
|
@@ -128,16 +127,20 @@ export default class StageMultiDragResize extends EventEmitter {
|
|
|
128
127
|
});
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
public canSelect(el: HTMLElement): Boolean {
|
|
132
|
-
//
|
|
130
|
+
public canSelect(el: HTMLElement, stop: () => boolean): Boolean {
|
|
131
|
+
// 多选状态下不可以选中magic-ui-page,并停止继续向上层选中
|
|
133
132
|
if (el.className.includes(PAGE_CLASS)) {
|
|
134
133
|
this.core.highlightedDom = undefined;
|
|
135
134
|
this.core.highlightLayer.clearHighlight();
|
|
135
|
+
stop();
|
|
136
136
|
return false;
|
|
137
137
|
}
|
|
138
138
|
const currentTargetMode = getMode(el);
|
|
139
139
|
let selectedDomMode = '';
|
|
140
|
-
|
|
140
|
+
if (this.core.selectedDom?.className.includes(PAGE_CLASS)) {
|
|
141
|
+
// 先单击选中了页面(magic-ui-page),再按住多选键多选时,任一元素均可选中
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
141
144
|
if (this.targetList.length === 0 && this.core.selectedDom) {
|
|
142
145
|
// 单选后添加到多选的情况
|
|
143
146
|
selectedDomMode = getMode(this.core.selectedDom);
|
|
@@ -208,11 +211,12 @@ export default class StageMultiDragResize extends EventEmitter {
|
|
|
208
211
|
* @return {MoveableOptions} moveable options参数
|
|
209
212
|
*/
|
|
210
213
|
private getOptions(options: MoveableOptions = {}): MoveableOptions {
|
|
211
|
-
let {
|
|
214
|
+
let { multiMoveableOptions = {} } = this.core.config;
|
|
212
215
|
|
|
213
|
-
if (typeof
|
|
214
|
-
|
|
216
|
+
if (typeof multiMoveableOptions === 'function') {
|
|
217
|
+
multiMoveableOptions = multiMoveableOptions(this.core);
|
|
215
218
|
}
|
|
219
|
+
|
|
216
220
|
return {
|
|
217
221
|
defaultGroupRotate: 0,
|
|
218
222
|
defaultGroupOrigin: '50% 50%',
|
|
@@ -225,7 +229,7 @@ export default class StageMultiDragResize extends EventEmitter {
|
|
|
225
229
|
origin: true,
|
|
226
230
|
padding: { left: 0, top: 0, right: 0, bottom: 0 },
|
|
227
231
|
...options,
|
|
228
|
-
...
|
|
232
|
+
...multiMoveableOptions,
|
|
229
233
|
};
|
|
230
234
|
}
|
|
231
235
|
}
|
package/src/types.ts
CHANGED
|
@@ -39,6 +39,7 @@ export type StageCoreConfig = {
|
|
|
39
39
|
containerHighlightClassName: string;
|
|
40
40
|
containerHighlightDuration: number;
|
|
41
41
|
moveableOptions?: ((core?: StageCore) => MoveableOptions) | MoveableOptions;
|
|
42
|
+
multiMoveableOptions?: ((core?: StageCore) => MoveableOptions) | MoveableOptions;
|
|
42
43
|
/** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
|
|
43
44
|
runtimeUrl?: string;
|
|
44
45
|
render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
|
|
@@ -111,7 +112,6 @@ export interface RemoveData {
|
|
|
111
112
|
export interface Runtime {
|
|
112
113
|
getApp?: () => Core;
|
|
113
114
|
beforeSelect?: (el: HTMLElement) => Promise<boolean> | boolean;
|
|
114
|
-
getSnapElements?: (el?: HTMLElement) => HTMLElement[];
|
|
115
115
|
updateRootConfig?: (config: MApp) => void;
|
|
116
116
|
updatePageId?: (id: Id) => void;
|
|
117
117
|
select?: (id: Id) => Promise<HTMLElement> | HTMLElement;
|
|
File without changes
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { EventEmitter } from 'events';
|
|
3
4
|
import type { Id } from '@tmagic/schema';
|
|
4
5
|
import StageDragResize from './StageDragResize';
|
|
@@ -32,6 +33,11 @@ export default class StageCore extends EventEmitter {
|
|
|
32
33
|
* @param idOrEl 组件Dom节点的id属性,或者Dom节点
|
|
33
34
|
*/
|
|
34
35
|
select(idOrEl: Id | HTMLElement, event?: MouseEvent): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* 多选
|
|
38
|
+
* @param domList 多选节点
|
|
39
|
+
*/
|
|
40
|
+
multiSelect(idOrElList: HTMLElement[] | Id[]): Promise<void>;
|
|
35
41
|
/**
|
|
36
42
|
* 更新选中的节点
|
|
37
43
|
* @param data 更新的数据
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const log: (...args: any[]) => void;
|
|
2
|
+
export declare const info: (...args: any[]) => void;
|
|
3
|
+
export declare const warn: (...args: any[]) => void;
|
|
4
|
+
export declare const debug: (...args: any[]) => void;
|
|
5
|
+
export declare const error: (...args: any[]) => void;
|
|
@@ -17,6 +17,7 @@ export declare type StageCoreConfig = {
|
|
|
17
17
|
containerHighlightClassName: string;
|
|
18
18
|
containerHighlightDuration: number;
|
|
19
19
|
moveableOptions?: ((core?: StageCore) => MoveableOptions) | MoveableOptions;
|
|
20
|
+
multiMoveableOptions?: ((core?: StageCore) => MoveableOptions) | MoveableOptions;
|
|
20
21
|
/** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
|
|
21
22
|
runtimeUrl?: string;
|
|
22
23
|
render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
|
|
@@ -78,7 +79,6 @@ export interface RemoveData {
|
|
|
78
79
|
export interface Runtime {
|
|
79
80
|
getApp?: () => Core;
|
|
80
81
|
beforeSelect?: (el: HTMLElement) => Promise<boolean> | boolean;
|
|
81
|
-
getSnapElements?: (el?: HTMLElement) => HTMLElement[];
|
|
82
82
|
updateRootConfig?: (config: MApp) => void;
|
|
83
83
|
updatePageId?: (id: Id) => void;
|
|
84
84
|
select?: (id: Id) => Promise<HTMLElement> | HTMLElement;
|
|
File without changes
|