@tmagic/stage 1.3.16 → 1.4.0-beta.2
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 +2 -2
- package/dist/tmagic-stage.js +155 -103
- package/dist/tmagic-stage.umd.cjs +155 -103
- package/package.json +6 -6
- package/src/ActionManager.ts +57 -24
- package/src/DragResizeHelper.ts +12 -8
- package/src/MoveableActionsAble.ts +1 -1
- package/src/StageCore.ts +41 -25
- package/src/StageDragResize.ts +50 -23
- package/src/StageMask.ts +12 -1
- package/src/StageMultiDragResize.ts +18 -3
- package/src/StageRender.ts +22 -26
- package/src/TargetShadow.ts +1 -1
- package/src/const.ts +31 -0
- package/src/types.ts +73 -37
- package/src/util.ts +2 -2
- package/types/ActionManager.d.ts +10 -8
- package/types/DragResizeHelper.d.ts +2 -2
- package/types/StageCore.d.ts +9 -7
- package/types/StageDragResize.d.ts +8 -6
- package/types/StageMask.d.ts +3 -1
- package/types/StageMultiDragResize.d.ts +5 -2
- package/types/StageRender.d.ts +5 -3
- package/types/const.d.ts +27 -0
- package/types/types.d.ts +67 -33
- package/types/util.d.ts +2 -2
package/src/ActionManager.ts
CHANGED
|
@@ -25,15 +25,25 @@ import { Env } from '@tmagic/core';
|
|
|
25
25
|
import type { Id } from '@tmagic/schema';
|
|
26
26
|
import { addClassName, getDocument, removeClassNameByClassName } from '@tmagic/utils';
|
|
27
27
|
|
|
28
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
AbleActionEventType,
|
|
30
|
+
CONTAINER_HIGHLIGHT_CLASS_NAME,
|
|
31
|
+
ContainerHighlightType,
|
|
32
|
+
GHOST_EL_ID_PREFIX,
|
|
33
|
+
GuidesType,
|
|
34
|
+
MouseButton,
|
|
35
|
+
PAGE_CLASS,
|
|
36
|
+
SelectStatus,
|
|
37
|
+
StageDragStatus,
|
|
38
|
+
} from './const';
|
|
29
39
|
import DragResizeHelper from './DragResizeHelper';
|
|
30
40
|
import StageDragResize from './StageDragResize';
|
|
31
41
|
import StageHighlight from './StageHighlight';
|
|
32
42
|
import StageMultiDragResize from './StageMultiDragResize';
|
|
33
|
-
import {
|
|
43
|
+
import type {
|
|
34
44
|
ActionManagerConfig,
|
|
45
|
+
ActionManagerEvents,
|
|
35
46
|
CanSelect,
|
|
36
|
-
ContainerHighlightType,
|
|
37
47
|
CustomizeMoveableOptions,
|
|
38
48
|
CustomizeMoveableOptionsCallbackConfig,
|
|
39
49
|
GetElementsFromPoint,
|
|
@@ -42,8 +52,7 @@ import {
|
|
|
42
52
|
IsContainer,
|
|
43
53
|
Point,
|
|
44
54
|
RemoveEventData,
|
|
45
|
-
|
|
46
|
-
StageDragStatus,
|
|
55
|
+
SortEventData,
|
|
47
56
|
UpdateEventData,
|
|
48
57
|
} from './types';
|
|
49
58
|
import { isMoveableButton } from './util';
|
|
@@ -62,7 +71,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
62
71
|
/** 单选、多选、高亮的容器(蒙层的content) */
|
|
63
72
|
private container: HTMLElement;
|
|
64
73
|
/** 当前选中的节点 */
|
|
65
|
-
private selectedEl: HTMLElement |
|
|
74
|
+
private selectedEl: HTMLElement | null = null;
|
|
66
75
|
/** 多选选中的节点组 */
|
|
67
76
|
private selectedElList: HTMLElement[] = [];
|
|
68
77
|
/** 当前高亮的节点 */
|
|
@@ -96,7 +105,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
96
105
|
}
|
|
97
106
|
|
|
98
107
|
this.emit('mousemove', event);
|
|
99
|
-
this.highlight(el);
|
|
108
|
+
this.highlight(el.id);
|
|
100
109
|
}, throttleTime);
|
|
101
110
|
|
|
102
111
|
constructor(config: ActionManagerConfig) {
|
|
@@ -181,11 +190,11 @@ export default class ActionManager extends EventEmitter {
|
|
|
181
190
|
return el.id === this.selectedEl?.id;
|
|
182
191
|
}
|
|
183
192
|
|
|
184
|
-
public setSelectedEl(el
|
|
193
|
+
public setSelectedEl(el: HTMLElement | null): void {
|
|
185
194
|
this.selectedEl = el;
|
|
186
195
|
}
|
|
187
196
|
|
|
188
|
-
public getSelectedEl(): HTMLElement |
|
|
197
|
+
public getSelectedEl(): HTMLElement | null {
|
|
189
198
|
return this.selectedEl;
|
|
190
199
|
}
|
|
191
200
|
|
|
@@ -207,7 +216,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
207
216
|
* @param event 鼠标事件
|
|
208
217
|
* @returns 鼠标下方第一个可选中元素
|
|
209
218
|
*/
|
|
210
|
-
public async getElementFromPoint(event: MouseEvent): Promise<HTMLElement |
|
|
219
|
+
public async getElementFromPoint(event: MouseEvent): Promise<HTMLElement | null> {
|
|
211
220
|
const els = this.getElementsFromPoint(event as Point);
|
|
212
221
|
|
|
213
222
|
this.emit('get-elements-from-point', els);
|
|
@@ -220,6 +229,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
220
229
|
return el;
|
|
221
230
|
}
|
|
222
231
|
}
|
|
232
|
+
return null;
|
|
223
233
|
}
|
|
224
234
|
|
|
225
235
|
/**
|
|
@@ -257,14 +267,20 @@ export default class ActionManager extends EventEmitter {
|
|
|
257
267
|
return this.multiDr?.canSelect(el, selectedEl) || false;
|
|
258
268
|
}
|
|
259
269
|
|
|
260
|
-
public select(el: HTMLElement, event
|
|
270
|
+
public select(el: HTMLElement | null, event?: MouseEvent): void {
|
|
261
271
|
this.setSelectedEl(el);
|
|
262
272
|
this.clearSelectStatus(SelectStatus.MULTI_SELECT);
|
|
263
273
|
this.dr.select(el, event);
|
|
264
274
|
}
|
|
265
275
|
|
|
266
|
-
public multiSelect(
|
|
267
|
-
this.selectedElList =
|
|
276
|
+
public multiSelect(ids: Id[]): void {
|
|
277
|
+
this.selectedElList = [];
|
|
278
|
+
ids.forEach((id) => {
|
|
279
|
+
const el = this.getTargetElement(id);
|
|
280
|
+
if (el) {
|
|
281
|
+
this.selectedElList.push(el);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
268
284
|
this.clearSelectStatus(SelectStatus.SELECT);
|
|
269
285
|
this.multiDr?.multiSelect(this.selectedElList);
|
|
270
286
|
}
|
|
@@ -277,10 +293,10 @@ export default class ActionManager extends EventEmitter {
|
|
|
277
293
|
this.highlightedEl = el;
|
|
278
294
|
}
|
|
279
295
|
|
|
280
|
-
public highlight(
|
|
296
|
+
public highlight(id: Id): void {
|
|
281
297
|
let el;
|
|
282
298
|
try {
|
|
283
|
-
el = this.getTargetElement(
|
|
299
|
+
el = this.getTargetElement(id);
|
|
284
300
|
} catch (error) {
|
|
285
301
|
this.clearHighlight();
|
|
286
302
|
return;
|
|
@@ -366,6 +382,20 @@ export default class ActionManager extends EventEmitter {
|
|
|
366
382
|
this.highlightLayer.destroy();
|
|
367
383
|
}
|
|
368
384
|
|
|
385
|
+
public on<Name extends keyof ActionManagerEvents, Param extends ActionManagerEvents[Name]>(
|
|
386
|
+
eventName: Name,
|
|
387
|
+
listener: (...args: Param) => void,
|
|
388
|
+
) {
|
|
389
|
+
return super.on(eventName, listener as any);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
public emit<Name extends keyof ActionManagerEvents, Param extends ActionManagerEvents[Name]>(
|
|
393
|
+
eventName: Name,
|
|
394
|
+
...args: Param
|
|
395
|
+
) {
|
|
396
|
+
return super.emit(eventName, ...args);
|
|
397
|
+
}
|
|
398
|
+
|
|
369
399
|
private createDr(config: ActionManagerConfig) {
|
|
370
400
|
const createDrHelper = () =>
|
|
371
401
|
new DragResizeHelper({
|
|
@@ -388,14 +418,14 @@ export default class ActionManager extends EventEmitter {
|
|
|
388
418
|
// 点击组件并立即拖动的场景,要保证select先被触发,延迟update通知
|
|
389
419
|
setTimeout(() => this.emit('update', data));
|
|
390
420
|
})
|
|
391
|
-
.on('sort', (data:
|
|
421
|
+
.on('sort', (data: SortEventData) => {
|
|
392
422
|
// 点击组件并立即拖动的场景,要保证select先被触发,延迟update通知
|
|
393
423
|
setTimeout(() => this.emit('sort', data));
|
|
394
424
|
})
|
|
395
|
-
.on(
|
|
425
|
+
.on(AbleActionEventType.SELECT_PARENT, () => {
|
|
396
426
|
this.emit('select-parent');
|
|
397
427
|
})
|
|
398
|
-
.on(
|
|
428
|
+
.on(AbleActionEventType.REMOVE, () => {
|
|
399
429
|
const drTarget = this.dr.getTarget();
|
|
400
430
|
if (!drTarget) return;
|
|
401
431
|
const data: RemoveEventData = {
|
|
@@ -430,11 +460,10 @@ export default class ActionManager extends EventEmitter {
|
|
|
430
460
|
?.on('update', (data: UpdateEventData) => {
|
|
431
461
|
this.emit('multi-update', data);
|
|
432
462
|
})
|
|
433
|
-
.on('change-to-select',
|
|
463
|
+
.on('change-to-select', (id: Id, e: MouseEvent) => {
|
|
434
464
|
// 如果还在多选状态,不触发切换到单选
|
|
435
|
-
if (this.isMultiSelectStatus) return
|
|
436
|
-
|
|
437
|
-
this.emit('change-to-select', el, e);
|
|
465
|
+
if (this.isMultiSelectStatus) return;
|
|
466
|
+
this.emit('change-to-select', id, e);
|
|
438
467
|
});
|
|
439
468
|
|
|
440
469
|
return multiDr;
|
|
@@ -474,13 +503,16 @@ export default class ActionManager extends EventEmitter {
|
|
|
474
503
|
// 如果已有单选选中元素,不是magic-ui-page就可以加入多选列表
|
|
475
504
|
if (this.selectedEl && !this.selectedEl.className.includes(PAGE_CLASS)) {
|
|
476
505
|
this.selectedElList.push(this.selectedEl as HTMLElement);
|
|
477
|
-
this.setSelectedEl(
|
|
506
|
+
this.setSelectedEl(null);
|
|
478
507
|
}
|
|
508
|
+
|
|
479
509
|
// 判断元素是否已在多选列表
|
|
480
510
|
const existIndex = this.selectedElList.findIndex((selectedDom) => selectedDom.id === el.id);
|
|
481
511
|
if (existIndex !== -1) {
|
|
482
512
|
// 再次点击取消选中
|
|
483
|
-
this.selectedElList.
|
|
513
|
+
if (this.selectedElList.length > 1) {
|
|
514
|
+
this.selectedElList.splice(existIndex, 1);
|
|
515
|
+
}
|
|
484
516
|
} else {
|
|
485
517
|
this.selectedElList.push(el);
|
|
486
518
|
}
|
|
@@ -580,6 +612,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
580
612
|
if (!el) return;
|
|
581
613
|
this.emit('before-select', el, event);
|
|
582
614
|
}
|
|
615
|
+
|
|
583
616
|
getDocument().addEventListener('mouseup', this.mouseUpHandler);
|
|
584
617
|
};
|
|
585
618
|
|
package/src/DragResizeHelper.ts
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import type {
|
|
20
20
|
OnDrag,
|
|
21
21
|
OnDragGroup,
|
|
22
22
|
OnDragGroupStart,
|
|
@@ -34,7 +34,7 @@ import MoveableHelper from 'moveable-helper';
|
|
|
34
34
|
|
|
35
35
|
import { DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, Mode, ZIndex } from './const';
|
|
36
36
|
import TargetShadow from './TargetShadow';
|
|
37
|
-
import { DragResizeHelperConfig, Rect, TargetElement } from './types';
|
|
37
|
+
import type { DragResizeHelperConfig, Rect, TargetElement } from './types';
|
|
38
38
|
import { calcValueByFontsize, getAbsolutePosition, getBorderWidth, getMarginValue, getOffset } from './util';
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -230,6 +230,9 @@ export default class DragResizeHelper {
|
|
|
230
230
|
*/
|
|
231
231
|
public onResizeGroup(e: OnResizeGroup): void {
|
|
232
232
|
const { events } = e;
|
|
233
|
+
|
|
234
|
+
this.moveableHelper.onResizeGroup(e);
|
|
235
|
+
|
|
233
236
|
// 拖动过程更新
|
|
234
237
|
events.forEach((ev) => {
|
|
235
238
|
const { width, height, beforeTranslate } = ev.drag;
|
|
@@ -255,26 +258,28 @@ export default class DragResizeHelper {
|
|
|
255
258
|
targeEl.style.width = `${width}px`;
|
|
256
259
|
targeEl.style.height = `${height}px`;
|
|
257
260
|
});
|
|
258
|
-
this.moveableHelper.onResizeGroup(e);
|
|
259
261
|
}
|
|
260
262
|
|
|
261
263
|
public onDragGroupStart(e: OnDragGroupStart): void {
|
|
262
|
-
const { events } = e;
|
|
263
264
|
this.moveableHelper.onDragGroupStart(e);
|
|
265
|
+
|
|
266
|
+
const { events } = e;
|
|
264
267
|
// 记录拖动前快照
|
|
265
268
|
this.setFramesSnapShot(events);
|
|
266
269
|
}
|
|
267
270
|
|
|
268
271
|
public onDragGroup(e: OnDragGroup): void {
|
|
272
|
+
this.moveableHelper.onDragGroup(e);
|
|
273
|
+
|
|
269
274
|
const { events } = e;
|
|
270
275
|
// 拖动过程更新
|
|
271
276
|
events.forEach((ev) => {
|
|
272
277
|
const frameSnapShot = this.framesSnapShot.find(
|
|
273
|
-
(frameItem) =>
|
|
278
|
+
(frameItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(frameItem.id),
|
|
274
279
|
);
|
|
275
280
|
if (!frameSnapShot) return;
|
|
276
281
|
const targeEl = this.targetList.find(
|
|
277
|
-
(targetItem) =>
|
|
282
|
+
(targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id),
|
|
278
283
|
);
|
|
279
284
|
if (!targeEl) return;
|
|
280
285
|
// 元素与其所属组同时加入多选列表时,只更新父元素
|
|
@@ -286,7 +291,6 @@ export default class DragResizeHelper {
|
|
|
286
291
|
targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1] - marginTop}px`;
|
|
287
292
|
}
|
|
288
293
|
});
|
|
289
|
-
this.moveableHelper.onDragGroup(e);
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
public getUpdatedElRect(el: HTMLElement, parentEl: HTMLElement | null, doc: Document): Rect {
|
|
@@ -342,7 +346,7 @@ export default class DragResizeHelper {
|
|
|
342
346
|
events.forEach((ev) => {
|
|
343
347
|
// 实际目标元素
|
|
344
348
|
const matchEventTarget = this.targetList.find(
|
|
345
|
-
(targetItem) =>
|
|
349
|
+
(targetItem) => ev.target.id.startsWith(DRAG_EL_ID_PREFIX) && ev.target.id.endsWith(targetItem.id),
|
|
346
350
|
);
|
|
347
351
|
if (!matchEventTarget) return;
|
|
348
352
|
this.framesSnapShot.push({
|
package/src/StageCore.ts
CHANGED
|
@@ -28,12 +28,14 @@ import StageMask from './StageMask';
|
|
|
28
28
|
import StageRender from './StageRender';
|
|
29
29
|
import type {
|
|
30
30
|
ActionManagerConfig,
|
|
31
|
+
CoreEvents,
|
|
31
32
|
CustomizeRender,
|
|
32
33
|
GuidesEventData,
|
|
33
34
|
Point,
|
|
34
35
|
RemoveData,
|
|
35
36
|
RemoveEventData,
|
|
36
37
|
Runtime,
|
|
38
|
+
SortEventData,
|
|
37
39
|
StageCoreConfig,
|
|
38
40
|
UpdateData,
|
|
39
41
|
UpdateEventData,
|
|
@@ -81,41 +83,41 @@ export default class StageCore extends EventEmitter {
|
|
|
81
83
|
|
|
82
84
|
/**
|
|
83
85
|
* 单选选中元素
|
|
84
|
-
* @param
|
|
86
|
+
* @param id 选中的id
|
|
85
87
|
*/
|
|
86
|
-
public async select(
|
|
87
|
-
const el = this.renderer.getTargetElement(
|
|
88
|
+
public async select(id: Id, event?: MouseEvent): Promise<void> {
|
|
89
|
+
const el = this.renderer.getTargetElement(id);
|
|
88
90
|
if (el === this.actionManager.getSelectedEl()) return;
|
|
89
91
|
|
|
90
|
-
await this.renderer.select([
|
|
92
|
+
await this.renderer.select([id]);
|
|
91
93
|
|
|
92
|
-
this.mask.setLayout(el);
|
|
94
|
+
el && this.mask.setLayout(el);
|
|
93
95
|
|
|
94
96
|
this.actionManager.select(el, event);
|
|
95
97
|
|
|
96
|
-
if (this.autoScrollIntoView || el.dataset.autoScrollIntoView) {
|
|
98
|
+
if (el && (this.autoScrollIntoView || el.dataset.autoScrollIntoView)) {
|
|
97
99
|
this.mask.observerIntersection(el);
|
|
98
100
|
}
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
/**
|
|
102
104
|
* 多选选中多个元素
|
|
103
|
-
* @param
|
|
105
|
+
* @param ids 选中元素的id列表
|
|
104
106
|
*/
|
|
105
|
-
public async multiSelect(
|
|
106
|
-
const els =
|
|
107
|
+
public async multiSelect(ids: Id[]): Promise<void> {
|
|
108
|
+
const els = ids.map((id) => this.renderer.getTargetElement(id)).filter((el) => Boolean(el));
|
|
107
109
|
if (els.length === 0) return;
|
|
108
110
|
|
|
109
111
|
const lastEl = els[els.length - 1];
|
|
110
112
|
// 是否减少了组件选择
|
|
111
113
|
const isReduceSelect = els.length < this.actionManager.getSelectedElList().length;
|
|
112
|
-
await this.renderer.select(
|
|
114
|
+
await this.renderer.select(ids);
|
|
113
115
|
|
|
114
|
-
this.mask.setLayout(lastEl);
|
|
116
|
+
lastEl && this.mask.setLayout(lastEl);
|
|
115
117
|
|
|
116
|
-
this.actionManager.multiSelect(
|
|
118
|
+
this.actionManager.multiSelect(ids);
|
|
117
119
|
|
|
118
|
-
if ((this.autoScrollIntoView || lastEl.dataset.autoScrollIntoView) && !isReduceSelect) {
|
|
120
|
+
if (lastEl && (this.autoScrollIntoView || lastEl.dataset.autoScrollIntoView) && !isReduceSelect) {
|
|
119
121
|
this.mask.observerIntersection(lastEl);
|
|
120
122
|
}
|
|
121
123
|
}
|
|
@@ -124,8 +126,8 @@ export default class StageCore extends EventEmitter {
|
|
|
124
126
|
* 高亮选中元素
|
|
125
127
|
* @param el 要高亮的元素
|
|
126
128
|
*/
|
|
127
|
-
public highlight(
|
|
128
|
-
this.actionManager.highlight(
|
|
129
|
+
public highlight(id: Id): void {
|
|
130
|
+
this.actionManager.highlight(id);
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
public clearHighlight(): void {
|
|
@@ -248,6 +250,17 @@ export default class StageCore extends EventEmitter {
|
|
|
248
250
|
this.container = undefined;
|
|
249
251
|
}
|
|
250
252
|
|
|
253
|
+
public on<Name extends keyof CoreEvents, Param extends CoreEvents[Name]>(
|
|
254
|
+
eventName: Name,
|
|
255
|
+
listener: (...args: Param) => void | Promise<void>,
|
|
256
|
+
) {
|
|
257
|
+
return super.on(eventName, listener as any);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
public emit<Name extends keyof CoreEvents, Param extends CoreEvents[Name]>(eventName: Name, ...args: Param) {
|
|
261
|
+
return super.emit(eventName, ...args);
|
|
262
|
+
}
|
|
263
|
+
|
|
251
264
|
/**
|
|
252
265
|
* 监听页面大小变化
|
|
253
266
|
*/
|
|
@@ -280,7 +293,7 @@ export default class StageCore extends EventEmitter {
|
|
|
280
293
|
updateDragEl: config.updateDragEl,
|
|
281
294
|
getRootContainer: () => this.container,
|
|
282
295
|
getRenderDocument: () => this.renderer.getDocument(),
|
|
283
|
-
getTargetElement: (
|
|
296
|
+
getTargetElement: (id: Id) => this.renderer.getTargetElement(id),
|
|
284
297
|
getElementsFromPoint: (point: Point) => this.renderer.getElementsFromPoint(point),
|
|
285
298
|
};
|
|
286
299
|
|
|
@@ -322,14 +335,14 @@ export default class StageCore extends EventEmitter {
|
|
|
322
335
|
*/
|
|
323
336
|
private initActionManagerEvent(): void {
|
|
324
337
|
this.actionManager
|
|
325
|
-
.on('before-select', (
|
|
326
|
-
this.select(
|
|
338
|
+
.on('before-select', (el: HTMLElement, event?: MouseEvent) => {
|
|
339
|
+
this.select(el.id, event);
|
|
327
340
|
})
|
|
328
341
|
.on('select', (selectedEl: HTMLElement, event: MouseEvent) => {
|
|
329
342
|
this.emit('select', selectedEl, event);
|
|
330
343
|
})
|
|
331
|
-
.on('before-multi-select', (
|
|
332
|
-
this.multiSelect(
|
|
344
|
+
.on('before-multi-select', (els: HTMLElement[]) => {
|
|
345
|
+
this.multiSelect(els.map((el) => el.id));
|
|
333
346
|
})
|
|
334
347
|
.on('multi-select', (selectedElList: HTMLElement[], event: MouseEvent) => {
|
|
335
348
|
this.emit('multi-select', selectedElList, event);
|
|
@@ -347,7 +360,7 @@ export default class StageCore extends EventEmitter {
|
|
|
347
360
|
.on('update', (data: UpdateEventData) => {
|
|
348
361
|
this.emit('update', data);
|
|
349
362
|
})
|
|
350
|
-
.on('sort', (data:
|
|
363
|
+
.on('sort', (data: SortEventData) => {
|
|
351
364
|
this.emit('sort', data);
|
|
352
365
|
})
|
|
353
366
|
.on('select-parent', () => {
|
|
@@ -364,10 +377,13 @@ export default class StageCore extends EventEmitter {
|
|
|
364
377
|
private initMulDrEvent(): void {
|
|
365
378
|
this.actionManager
|
|
366
379
|
// 多选切换到单选
|
|
367
|
-
.on('change-to-select', (
|
|
368
|
-
this.select(
|
|
380
|
+
.on('change-to-select', (id: Id, e: MouseEvent) => {
|
|
381
|
+
this.select(id);
|
|
369
382
|
// 先保证画布内完成渲染,再通知外部更新
|
|
370
|
-
setTimeout(() =>
|
|
383
|
+
setTimeout(() => {
|
|
384
|
+
const el = this.renderer.getTargetElement(id);
|
|
385
|
+
el && this.emit('select', el, e);
|
|
386
|
+
});
|
|
371
387
|
})
|
|
372
388
|
.on('multi-update', (data: UpdateEventData) => {
|
|
373
389
|
this.emit('update', data);
|
|
@@ -378,7 +394,7 @@ export default class StageCore extends EventEmitter {
|
|
|
378
394
|
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
379
395
|
*/
|
|
380
396
|
private initHighlightEvent(): void {
|
|
381
|
-
this.actionManager.on('highlight',
|
|
397
|
+
this.actionManager.on('highlight', (highlightEl: HTMLElement) => {
|
|
382
398
|
this.emit('highlight', highlightEl);
|
|
383
399
|
});
|
|
384
400
|
}
|
package/src/StageDragResize.ts
CHANGED
|
@@ -19,11 +19,16 @@
|
|
|
19
19
|
/* eslint-disable no-param-reassign */
|
|
20
20
|
import Moveable, { MoveableOptions } from 'moveable';
|
|
21
21
|
|
|
22
|
-
import { Mode } from './const';
|
|
22
|
+
import { Mode, StageDragStatus } from './const';
|
|
23
23
|
import DragResizeHelper from './DragResizeHelper';
|
|
24
24
|
import MoveableOptionsManager from './MoveableOptionsManager';
|
|
25
|
-
import type {
|
|
26
|
-
|
|
25
|
+
import type {
|
|
26
|
+
DelayedMarkContainer,
|
|
27
|
+
DrEvents,
|
|
28
|
+
GetRenderDocument,
|
|
29
|
+
MarkContainerEnd,
|
|
30
|
+
StageDragResizeConfig,
|
|
31
|
+
} from './types';
|
|
27
32
|
import { down, getMode, up } from './util';
|
|
28
33
|
|
|
29
34
|
/**
|
|
@@ -32,7 +37,7 @@ import { down, getMode, up } from './util';
|
|
|
32
37
|
*/
|
|
33
38
|
export default class StageDragResize extends MoveableOptionsManager {
|
|
34
39
|
/** 目标节点 */
|
|
35
|
-
private target
|
|
40
|
+
private target: HTMLElement | null = null;
|
|
36
41
|
/** Moveable拖拽类实例 */
|
|
37
42
|
private moveable?: Moveable;
|
|
38
43
|
/** 拖动状态 */
|
|
@@ -70,7 +75,12 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|
|
70
75
|
* @param el 选中组件的Dom节点元素
|
|
71
76
|
* @param event 鼠标事件
|
|
72
77
|
*/
|
|
73
|
-
public select(el: HTMLElement, event?: MouseEvent): void {
|
|
78
|
+
public select(el: HTMLElement | null, event?: MouseEvent): void {
|
|
79
|
+
if (!el) {
|
|
80
|
+
this.moveable?.destroy();
|
|
81
|
+
this.moveable = undefined;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
74
84
|
// 从不能拖动到能拖动的节点之间切换,要重新创建moveable,不然dragStart不生效
|
|
75
85
|
if (!this.moveable || el !== this.target) {
|
|
76
86
|
this.initMoveable(el);
|
|
@@ -119,6 +129,17 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|
|
119
129
|
this.removeAllListeners();
|
|
120
130
|
}
|
|
121
131
|
|
|
132
|
+
public on<Name extends keyof DrEvents, Param extends DrEvents[Name]>(
|
|
133
|
+
eventName: Name,
|
|
134
|
+
listener: (...args: Param) => void | Promise<void>,
|
|
135
|
+
) {
|
|
136
|
+
return super.on(eventName, listener as any);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public emit<Name extends keyof DrEvents, Param extends DrEvents[Name]>(eventName: Name, ...args: Param) {
|
|
140
|
+
return super.emit(eventName, ...args);
|
|
141
|
+
}
|
|
142
|
+
|
|
122
143
|
private init(el: HTMLElement): MoveableOptions {
|
|
123
144
|
// 如果有滚动条会导致resize时获取到width,height不准确
|
|
124
145
|
if (/(auto|scroll)/.test(el.style.overflow)) {
|
|
@@ -247,16 +268,19 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|
|
247
268
|
.on('rotateEnd', (e) => {
|
|
248
269
|
this.dragStatus = StageDragStatus.END;
|
|
249
270
|
const frame = this.dragResizeHelper?.getFrame(e.target);
|
|
250
|
-
this.
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
271
|
+
if (this.target && frame) {
|
|
272
|
+
this.emit('update', {
|
|
273
|
+
data: [
|
|
274
|
+
{
|
|
275
|
+
el: this.target,
|
|
276
|
+
style: {
|
|
277
|
+
transform: frame.get('transform'),
|
|
278
|
+
},
|
|
256
279
|
},
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
280
|
+
],
|
|
281
|
+
parentEl: null,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
260
284
|
});
|
|
261
285
|
}
|
|
262
286
|
|
|
@@ -276,16 +300,19 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|
|
276
300
|
.on('scaleEnd', (e) => {
|
|
277
301
|
this.dragStatus = StageDragStatus.END;
|
|
278
302
|
const frame = this.dragResizeHelper.getFrame(e.target);
|
|
279
|
-
this.
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
303
|
+
if (this.target && frame) {
|
|
304
|
+
this.emit('update', {
|
|
305
|
+
data: [
|
|
306
|
+
{
|
|
307
|
+
el: this.target,
|
|
308
|
+
style: {
|
|
309
|
+
transform: frame.get('transform'),
|
|
310
|
+
},
|
|
285
311
|
},
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
312
|
+
],
|
|
313
|
+
parentEl: null,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
289
316
|
});
|
|
290
317
|
}
|
|
291
318
|
|
package/src/StageMask.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { createDiv, getDocument, injectStyle } from '@tmagic/utils';
|
|
|
20
20
|
|
|
21
21
|
import { Mode, ZIndex } from './const';
|
|
22
22
|
import Rule from './Rule';
|
|
23
|
-
import type { RuleOptions } from './types';
|
|
23
|
+
import type { MaskEvents, RuleOptions } from './types';
|
|
24
24
|
import { getScrollParent, isFixedParent } from './util';
|
|
25
25
|
|
|
26
26
|
const wrapperClassName = 'editor-mask-wrapper';
|
|
@@ -178,6 +178,17 @@ export default class StageMask extends Rule {
|
|
|
178
178
|
super.destroy();
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
public on<Name extends keyof MaskEvents, Param extends MaskEvents[Name]>(
|
|
182
|
+
eventName: Name,
|
|
183
|
+
listener: (...args: Param) => void | Promise<void>,
|
|
184
|
+
) {
|
|
185
|
+
return super.on(eventName, listener as any);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
public emit<Name extends keyof MaskEvents, Param extends MaskEvents[Name]>(eventName: Name, ...args: Param) {
|
|
189
|
+
return super.emit(eventName, ...args);
|
|
190
|
+
}
|
|
191
|
+
|
|
181
192
|
/**
|
|
182
193
|
* 监听选中元素是否在画布可视区域内,如果目标元素不在可视区域内,通过滚动使该元素出现在可视区域
|
|
183
194
|
*/
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import Moveable from 'moveable';
|
|
20
20
|
|
|
21
|
-
import { DRAG_EL_ID_PREFIX, Mode } from './const';
|
|
21
|
+
import { DRAG_EL_ID_PREFIX, Mode, StageDragStatus } from './const';
|
|
22
22
|
import DragResizeHelper from './DragResizeHelper';
|
|
23
23
|
import MoveableOptionsManager from './MoveableOptionsManager';
|
|
24
24
|
import {
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
GetRenderDocument,
|
|
27
27
|
MarkContainerEnd,
|
|
28
28
|
MoveableOptionsManagerConfig,
|
|
29
|
-
|
|
29
|
+
MultiDrEvents,
|
|
30
30
|
StageMultiDragResizeConfig,
|
|
31
31
|
} from './types';
|
|
32
32
|
import { getMode } from './util';
|
|
@@ -120,6 +120,10 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
120
120
|
this.dragStatus = StageDragStatus.ING;
|
|
121
121
|
})
|
|
122
122
|
.on('dragGroupEnd', () => {
|
|
123
|
+
if (timeout) {
|
|
124
|
+
globalThis.clearTimeout(timeout);
|
|
125
|
+
timeout = undefined;
|
|
126
|
+
}
|
|
123
127
|
const parentEl = this.markContainerEnd();
|
|
124
128
|
this.update(false, parentEl);
|
|
125
129
|
this.dragStatus = StageDragStatus.END;
|
|
@@ -133,7 +137,7 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
133
137
|
});
|
|
134
138
|
}
|
|
135
139
|
|
|
136
|
-
public canSelect(el: HTMLElement, selectedEl: HTMLElement |
|
|
140
|
+
public canSelect(el: HTMLElement, selectedEl: HTMLElement | null): boolean {
|
|
137
141
|
const currentTargetMode = getMode(el);
|
|
138
142
|
let selectedElMode = '';
|
|
139
143
|
|
|
@@ -192,6 +196,17 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
192
196
|
this.dragResizeHelper.destroy();
|
|
193
197
|
}
|
|
194
198
|
|
|
199
|
+
public on<Name extends keyof MultiDrEvents, Param extends MultiDrEvents[Name]>(
|
|
200
|
+
eventName: Name,
|
|
201
|
+
listener: (...args: Param) => void | Promise<void>,
|
|
202
|
+
) {
|
|
203
|
+
return super.on(eventName, listener as any);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
public emit<Name extends keyof MultiDrEvents, Param extends MultiDrEvents[Name]>(eventName: Name, ...args: Param) {
|
|
207
|
+
return super.emit(eventName, ...args);
|
|
208
|
+
}
|
|
209
|
+
|
|
195
210
|
/**
|
|
196
211
|
* 拖拽完成后将更新的位置信息暴露给上层业务方,业务方可以接收事件进行保存
|
|
197
212
|
* @param isResize 是否进行大小缩放
|