@tmagic/stage 1.4.0-beta.1 → 1.4.0
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.js +143 -95
- package/dist/tmagic-stage.umd.cjs +143 -95
- package/package.json +4 -4
- package/src/ActionManager.ts +57 -24
- package/src/DragResizeHelper.ts +2 -2
- package/src/StageCore.ts +41 -25
- package/src/StageDragResize.ts +50 -23
- package/src/StageMask.ts +12 -1
- package/src/StageMultiDragResize.ts +14 -3
- package/src/StageRender.ts +22 -26
- 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/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';
|
|
@@ -137,7 +137,7 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
public canSelect(el: HTMLElement, selectedEl: HTMLElement |
|
|
140
|
+
public canSelect(el: HTMLElement, selectedEl: HTMLElement | null): boolean {
|
|
141
141
|
const currentTargetMode = getMode(el);
|
|
142
142
|
let selectedElMode = '';
|
|
143
143
|
|
|
@@ -196,6 +196,17 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
196
196
|
this.dragResizeHelper.destroy();
|
|
197
197
|
}
|
|
198
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
|
+
|
|
199
210
|
/**
|
|
200
211
|
* 拖拽完成后将更新的位置信息暴露给上层业务方,业务方可以接收事件进行保存
|
|
201
212
|
* @param isResize 是否进行大小缩放
|
package/src/StageRender.ts
CHANGED
|
@@ -21,17 +21,9 @@ import { EventEmitter } from 'events';
|
|
|
21
21
|
import { Id } from '@tmagic/schema';
|
|
22
22
|
import { getHost, injectStyle, isSameDomain } from '@tmagic/utils';
|
|
23
23
|
|
|
24
|
-
import { DEFAULT_ZOOM } from './const';
|
|
24
|
+
import { DEFAULT_ZOOM, RenderType } from './const';
|
|
25
25
|
import style from './style.css?raw';
|
|
26
|
-
import {
|
|
27
|
-
type Point,
|
|
28
|
-
type RemoveData,
|
|
29
|
-
RenderType,
|
|
30
|
-
type Runtime,
|
|
31
|
-
type RuntimeWindow,
|
|
32
|
-
type StageRenderConfig,
|
|
33
|
-
type UpdateData,
|
|
34
|
-
} from './types';
|
|
26
|
+
import type { Point, RemoveData, RenderEvents, Runtime, RuntimeWindow, StageRenderConfig, UpdateData } from './types';
|
|
35
27
|
import { addSelectedClassName, removeSelectedClassName } from './util';
|
|
36
28
|
|
|
37
29
|
export default class StageRender extends EventEmitter {
|
|
@@ -87,15 +79,13 @@ export default class StageRender extends EventEmitter {
|
|
|
87
79
|
runtime?.update?.(data);
|
|
88
80
|
}
|
|
89
81
|
|
|
90
|
-
public async select(
|
|
82
|
+
public async select(ids: Id[]): Promise<void> {
|
|
91
83
|
const runtime = await this.getRuntime();
|
|
92
84
|
|
|
93
|
-
for (const
|
|
94
|
-
await runtime?.select?.(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
this.flagSelectedEl(el);
|
|
85
|
+
for (const id of ids) {
|
|
86
|
+
await runtime?.select?.(id);
|
|
87
|
+
|
|
88
|
+
this.flagSelectedEl(this.getTargetElement(id));
|
|
99
89
|
}
|
|
100
90
|
}
|
|
101
91
|
|
|
@@ -161,13 +151,8 @@ export default class StageRender extends EventEmitter {
|
|
|
161
151
|
return this.getDocument()?.elementsFromPoint(x / this.zoom, y / this.zoom) as HTMLElement[];
|
|
162
152
|
}
|
|
163
153
|
|
|
164
|
-
public getTargetElement(
|
|
165
|
-
|
|
166
|
-
const el = this.getDocument()?.getElementById(`${idOrEl}`);
|
|
167
|
-
if (!el) throw new Error(`不存在ID为${idOrEl}的元素`);
|
|
168
|
-
return el;
|
|
169
|
-
}
|
|
170
|
-
return idOrEl;
|
|
154
|
+
public getTargetElement(id: Id): HTMLElement | null {
|
|
155
|
+
return this.getDocument()?.getElementById(`${id}`) || null;
|
|
171
156
|
}
|
|
172
157
|
|
|
173
158
|
/**
|
|
@@ -181,6 +166,17 @@ export default class StageRender extends EventEmitter {
|
|
|
181
166
|
this.removeAllListeners();
|
|
182
167
|
}
|
|
183
168
|
|
|
169
|
+
public on<Name extends keyof RenderEvents, Param extends RenderEvents[Name]>(
|
|
170
|
+
eventName: Name,
|
|
171
|
+
listener: (...args: Param) => void | Promise<void>,
|
|
172
|
+
) {
|
|
173
|
+
return super.on(eventName, listener as any);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public emit<Name extends keyof RenderEvents, Param extends RenderEvents[Name]>(eventName: Name, ...args: Param) {
|
|
177
|
+
return super.emit(eventName, ...args);
|
|
178
|
+
}
|
|
179
|
+
|
|
184
180
|
private createIframe(): HTMLIFrameElement {
|
|
185
181
|
this.iframe = globalThis.document.createElement('iframe');
|
|
186
182
|
// 同源,直接加载
|
|
@@ -214,11 +210,11 @@ export default class StageRender extends EventEmitter {
|
|
|
214
210
|
* 在runtime中对被选中的元素进行标记,部分组件有对选中态进行特殊显示的需求
|
|
215
211
|
* @param el 被选中的元素
|
|
216
212
|
*/
|
|
217
|
-
private flagSelectedEl(el: HTMLElement): void {
|
|
213
|
+
private flagSelectedEl(el: HTMLElement | null): void {
|
|
218
214
|
const doc = this.getDocument();
|
|
219
215
|
if (doc) {
|
|
220
216
|
removeSelectedClassName(doc);
|
|
221
|
-
addSelectedClassName(el, doc);
|
|
217
|
+
el && addSelectedClassName(el, doc);
|
|
222
218
|
}
|
|
223
219
|
}
|
|
224
220
|
|
package/src/const.ts
CHANGED
|
@@ -78,3 +78,34 @@ export enum AbleActionEventType {
|
|
|
78
78
|
SELECT_PARENT = 'select-parent',
|
|
79
79
|
REMOVE = 'remove',
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
/** 将组件添加到容器的方式 */
|
|
83
|
+
export enum ContainerHighlightType {
|
|
84
|
+
/** 默认方式:组件在容器上方悬停一段时间后加入 */
|
|
85
|
+
DEFAULT = 'default',
|
|
86
|
+
/** 按住alt键,并在容器上方悬停一段时间后加入 */
|
|
87
|
+
ALT = 'alt',
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export enum RenderType {
|
|
91
|
+
IFRAME = 'iframe',
|
|
92
|
+
NATIVE = 'native',
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** 选择状态 */
|
|
96
|
+
export enum SelectStatus {
|
|
97
|
+
/** 单选 */
|
|
98
|
+
SELECT = 'select',
|
|
99
|
+
/** 多选 */
|
|
100
|
+
MULTI_SELECT = 'multiSelect',
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** 拖动状态 */
|
|
104
|
+
export enum StageDragStatus {
|
|
105
|
+
/** 开始拖动 */
|
|
106
|
+
START = 'start',
|
|
107
|
+
/** 拖动中 */
|
|
108
|
+
ING = 'ing',
|
|
109
|
+
/** 拖动结束 */
|
|
110
|
+
END = 'end',
|
|
111
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import type { GuidesOptions } from '@scena/guides';
|
|
20
|
-
import type { MoveableOptions } from 'moveable';
|
|
20
|
+
import type { MoveableOptions, OnDragStart } from 'moveable';
|
|
21
21
|
|
|
22
22
|
import Core from '@tmagic/core';
|
|
23
23
|
import type { Id, MApp, MContainer, MNode } from '@tmagic/schema';
|
|
24
24
|
|
|
25
|
-
import { GuidesType, ZIndex } from './const';
|
|
25
|
+
import { AbleActionEventType, ContainerHighlightType, GuidesType, RenderType, ZIndex } from './const';
|
|
26
26
|
import DragResizeHelper from './DragResizeHelper';
|
|
27
27
|
import StageCore from './StageCore';
|
|
28
28
|
|
|
@@ -36,8 +36,8 @@ export type CustomizeMoveableOptions =
|
|
|
36
36
|
| ((config?: CustomizeMoveableOptionsCallbackConfig) => MoveableOptions)
|
|
37
37
|
| MoveableOptions
|
|
38
38
|
| undefined;
|
|
39
|
-
/** render
|
|
40
|
-
export type GetTargetElement = (
|
|
39
|
+
/** render提供给的接口,id转成el */
|
|
40
|
+
export type GetTargetElement = (id: Id) => HTMLElement | null;
|
|
41
41
|
/** render提供的接口,通过坐标获得坐标下所有HTML元素数组 */
|
|
42
42
|
export type GetElementsFromPoint = (point: Point) => HTMLElement[];
|
|
43
43
|
export type GetRenderDocument = () => Document | undefined;
|
|
@@ -45,19 +45,6 @@ export type DelayedMarkContainer = (event: MouseEvent, exclude: Element[]) => No
|
|
|
45
45
|
export type MarkContainerEnd = () => HTMLElement | null;
|
|
46
46
|
export type GetRootContainer = () => HTMLDivElement | undefined;
|
|
47
47
|
|
|
48
|
-
/** 将组件添加到容器的方式 */
|
|
49
|
-
export enum ContainerHighlightType {
|
|
50
|
-
/** 默认方式:组件在容器上方悬停一段时间后加入 */
|
|
51
|
-
DEFAULT = 'default',
|
|
52
|
-
/** 按住alt键,并在容器上方悬停一段时间后加入 */
|
|
53
|
-
ALT = 'alt',
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export enum RenderType {
|
|
57
|
-
IFRAME = 'iframe',
|
|
58
|
-
NATIVE = 'native',
|
|
59
|
-
}
|
|
60
|
-
|
|
61
48
|
export type UpdateDragEl = (el: TargetElement, target: TargetElement, container: HTMLElement) => void;
|
|
62
49
|
|
|
63
50
|
export interface StageCoreConfig {
|
|
@@ -106,7 +93,7 @@ export interface MoveableOptionsManagerConfig {
|
|
|
106
93
|
}
|
|
107
94
|
|
|
108
95
|
export interface CustomizeMoveableOptionsCallbackConfig {
|
|
109
|
-
targetEl
|
|
96
|
+
targetEl: HTMLElement | null;
|
|
110
97
|
targetElId?: string;
|
|
111
98
|
targetEls?: HTMLElement[];
|
|
112
99
|
targetElIds?: string[];
|
|
@@ -151,24 +138,6 @@ export interface DragResizeHelperConfig {
|
|
|
151
138
|
updateDragEl?: UpdateDragEl;
|
|
152
139
|
}
|
|
153
140
|
|
|
154
|
-
/** 选择状态 */
|
|
155
|
-
export enum SelectStatus {
|
|
156
|
-
/** 单选 */
|
|
157
|
-
SELECT = 'select',
|
|
158
|
-
/** 多选 */
|
|
159
|
-
MULTI_SELECT = 'multiSelect',
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** 拖动状态 */
|
|
163
|
-
export enum StageDragStatus {
|
|
164
|
-
/** 开始拖动 */
|
|
165
|
-
START = 'start',
|
|
166
|
-
/** 拖动中 */
|
|
167
|
-
ING = 'ing',
|
|
168
|
-
/** 拖动结束 */
|
|
169
|
-
END = 'end',
|
|
170
|
-
}
|
|
171
|
-
|
|
172
141
|
export type Rect = {
|
|
173
142
|
width: number;
|
|
174
143
|
height: number;
|
|
@@ -234,7 +203,6 @@ export interface RemoveData {
|
|
|
234
203
|
|
|
235
204
|
export interface Runtime {
|
|
236
205
|
getApp?: () => Core | undefined;
|
|
237
|
-
beforeSelect?: (el: HTMLElement) => Promise<boolean> | boolean;
|
|
238
206
|
updateRootConfig?: (config: MApp) => void;
|
|
239
207
|
updatePageId?: (id: Id) => void;
|
|
240
208
|
select?: (id: Id) => Promise<HTMLElement> | HTMLElement;
|
|
@@ -271,3 +239,71 @@ export interface TargetShadowConfig {
|
|
|
271
239
|
export interface RuleOptions {
|
|
272
240
|
guidesOptions?: Partial<GuidesOptions>;
|
|
273
241
|
}
|
|
242
|
+
|
|
243
|
+
export interface CoreEvents {
|
|
244
|
+
mounted: [];
|
|
245
|
+
'runtime-ready': [runtime: Runtime];
|
|
246
|
+
'page-el-update': [el: HTMLElement];
|
|
247
|
+
'change-guides': [data: GuidesEventData];
|
|
248
|
+
select: [selectedEl: HTMLElement, event: MouseEvent];
|
|
249
|
+
'multi-select': [selectedElList: HTMLElement[], event: MouseEvent];
|
|
250
|
+
dblclick: [event: MouseEvent];
|
|
251
|
+
update: [data: UpdateEventData];
|
|
252
|
+
sort: [data: SortEventData];
|
|
253
|
+
'select-parent': [];
|
|
254
|
+
remove: [data: RemoveEventData];
|
|
255
|
+
highlight: [highlightEl: HTMLElement];
|
|
256
|
+
mousemove: [event: MouseEvent];
|
|
257
|
+
mouseleave: [event: MouseEvent];
|
|
258
|
+
'drag-start': [event: OnDragStart];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface RenderEvents {
|
|
262
|
+
onload: [];
|
|
263
|
+
'page-el-update': [el: HTMLElement];
|
|
264
|
+
'runtime-ready': [runtime: Runtime];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface MaskEvents {
|
|
268
|
+
scroll: [event: WheelEvent];
|
|
269
|
+
'change-guides': [
|
|
270
|
+
data: {
|
|
271
|
+
type: GuidesType.HORIZONTAL;
|
|
272
|
+
guides: number[];
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface ActionManagerEvents {
|
|
278
|
+
dblclick: [event: MouseEvent];
|
|
279
|
+
mousemove: [event: MouseEvent];
|
|
280
|
+
mouseleave: [event: MouseEvent];
|
|
281
|
+
highlight: [el: HTMLElement];
|
|
282
|
+
update: [data: UpdateEventData];
|
|
283
|
+
sort: [data: SortEventData];
|
|
284
|
+
remove: [data: RemoveEventData];
|
|
285
|
+
select: [selectedEl: HTMLElement | null, event: MouseEvent];
|
|
286
|
+
'select-parent': [];
|
|
287
|
+
'drag-start': [event: OnDragStart];
|
|
288
|
+
'multi-update': [data: UpdateEventData];
|
|
289
|
+
'change-to-select': [id: Id, event: MouseEvent];
|
|
290
|
+
'before-multi-select': [selectedElList: HTMLElement[]];
|
|
291
|
+
'before-select': [el: HTMLElement, event: MouseEvent];
|
|
292
|
+
'multi-select': [selectedElList: HTMLElement[], event: MouseEvent];
|
|
293
|
+
'get-elements-from-point': [els: HTMLElement[]];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface DrEvents {
|
|
297
|
+
'update-moveable': [];
|
|
298
|
+
[AbleActionEventType.REMOVE]: [];
|
|
299
|
+
[AbleActionEventType.SELECT_PARENT]: [];
|
|
300
|
+
'drag-start': [event: OnDragStart];
|
|
301
|
+
update: [data: UpdateEventData];
|
|
302
|
+
sort: [data: SortEventData];
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export interface MultiDrEvents {
|
|
306
|
+
'update-moveable': [];
|
|
307
|
+
'change-to-select': [id: Id, event: MouseEvent];
|
|
308
|
+
update: [data: UpdateEventData];
|
|
309
|
+
}
|
package/src/util.ts
CHANGED
|
@@ -177,7 +177,7 @@ export const calcValueByFontsize = (doc: Document, value: number) => {
|
|
|
177
177
|
* @param {number} deltaTop 偏移量
|
|
178
178
|
* @param {Object} detail 当前选中的组件配置
|
|
179
179
|
*/
|
|
180
|
-
export const down = (deltaTop: number, target: TargetElement): SortEventData
|
|
180
|
+
export const down = (deltaTop: number, target: TargetElement): SortEventData => {
|
|
181
181
|
let swapIndex = 0;
|
|
182
182
|
let addUpH = target.clientHeight;
|
|
183
183
|
const brothers = Array.from(target.parentNode?.children || []).filter(
|
|
@@ -213,7 +213,7 @@ export const down = (deltaTop: number, target: TargetElement): SortEventData | v
|
|
|
213
213
|
* @param {number} deltaTop 偏移量
|
|
214
214
|
* @param {Object} detail 当前选中的组件配置
|
|
215
215
|
*/
|
|
216
|
-
export const up = (deltaTop: number, target: TargetElement): SortEventData
|
|
216
|
+
export const up = (deltaTop: number, target: TargetElement): SortEventData => {
|
|
217
217
|
const brothers = Array.from(target.parentNode?.children || []).filter(
|
|
218
218
|
(node) => !node.id.startsWith(GHOST_EL_ID_PREFIX),
|
|
219
219
|
);
|