@tmagic/stage 1.3.6 → 1.3.7
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/LICENSE +5432 -0
- package/dist/tmagic-stage.js +144 -106
- package/dist/tmagic-stage.js.map +1 -1
- package/dist/tmagic-stage.umd.cjs +144 -106
- package/dist/tmagic-stage.umd.cjs.map +1 -1
- package/package.json +10 -10
- package/src/ActionManager.ts +121 -81
- package/src/MoveableActionsAble.ts +1 -1
- package/src/MoveableOptionsManager.ts +2 -2
- package/src/Rule.ts +7 -2
- package/src/StageCore.ts +14 -1
- package/src/StageMask.ts +3 -2
- package/src/StageRender.ts +0 -6
- package/src/const.ts +5 -0
- package/src/index.ts +1 -0
- package/src/types.ts +6 -3
- package/types/ActionManager.d.ts +8 -6
- package/types/MoveableActionsAble.d.ts +1 -1
- package/types/MoveableOptionsManager.d.ts +1 -1
- package/types/Rule.d.ts +3 -1
- package/types/StageCore.d.ts +2 -0
- package/types/StageMask.d.ts +2 -1
- package/types/const.d.ts +4 -0
- package/types/index.d.ts +1 -0
- package/types/types.d.ts +6 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.7",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -17,11 +17,6 @@
|
|
|
17
17
|
"./*": "./*"
|
|
18
18
|
},
|
|
19
19
|
"license": "Apache-2.0",
|
|
20
|
-
"scripts": {
|
|
21
|
-
"build": "npm run build:type && vite build",
|
|
22
|
-
"build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
|
|
23
|
-
"clear:type": "rimraf ./types"
|
|
24
|
-
},
|
|
25
20
|
"engines": {
|
|
26
21
|
"node": ">=18"
|
|
27
22
|
},
|
|
@@ -31,9 +26,9 @@
|
|
|
31
26
|
},
|
|
32
27
|
"dependencies": {
|
|
33
28
|
"@scena/guides": "^0.29.2",
|
|
34
|
-
"@tmagic/core": "1.3.
|
|
35
|
-
"@tmagic/schema": "1.3.
|
|
36
|
-
"@tmagic/utils": "1.3.
|
|
29
|
+
"@tmagic/core": "1.3.7",
|
|
30
|
+
"@tmagic/schema": "1.3.7",
|
|
31
|
+
"@tmagic/utils": "1.3.7",
|
|
37
32
|
"events": "^3.3.0",
|
|
38
33
|
"keycon": "^1.4.0",
|
|
39
34
|
"lodash-es": "^4.17.21",
|
|
@@ -48,5 +43,10 @@
|
|
|
48
43
|
"sass": "^1.35.1",
|
|
49
44
|
"typescript": "^5.0.4",
|
|
50
45
|
"vite": "^5.0.7"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "npm run build:type && vite build",
|
|
49
|
+
"build:type": "npm run clear:type && tsc --declaration --emitDeclarationOnly --project tsconfig.build.json",
|
|
50
|
+
"clear:type": "rimraf ./types"
|
|
51
51
|
}
|
|
52
|
-
}
|
|
52
|
+
}
|
package/src/ActionManager.ts
CHANGED
|
@@ -57,7 +57,7 @@ const defaultContainerHighlightDuration = 800;
|
|
|
57
57
|
*/
|
|
58
58
|
export default class ActionManager extends EventEmitter {
|
|
59
59
|
private dr: StageDragResize;
|
|
60
|
-
private multiDr
|
|
60
|
+
private multiDr?: StageMultiDragResize;
|
|
61
61
|
private highlightLayer: StageHighlight;
|
|
62
62
|
/** 单选、多选、高亮的容器(蒙层的content) */
|
|
63
63
|
private container: HTMLElement;
|
|
@@ -81,6 +81,8 @@ export default class ActionManager extends EventEmitter {
|
|
|
81
81
|
private canSelect: CanSelect;
|
|
82
82
|
private isContainer: IsContainer;
|
|
83
83
|
private getRenderDocument: GetRenderDocument;
|
|
84
|
+
private disabledMultiSelect = false;
|
|
85
|
+
private config: ActionManagerConfig;
|
|
84
86
|
|
|
85
87
|
private mouseMoveHandler = throttle(async (event: MouseEvent): Promise<void> => {
|
|
86
88
|
if ((event.target as HTMLDivElement)?.classList?.contains('moveable-direction')) {
|
|
@@ -99,41 +101,24 @@ export default class ActionManager extends EventEmitter {
|
|
|
99
101
|
|
|
100
102
|
constructor(config: ActionManagerConfig) {
|
|
101
103
|
super();
|
|
104
|
+
this.config = config;
|
|
102
105
|
this.container = config.container;
|
|
103
106
|
this.containerHighlightClassName = config.containerHighlightClassName || CONTAINER_HIGHLIGHT_CLASS_NAME;
|
|
104
107
|
this.containerHighlightDuration = config.containerHighlightDuration || defaultContainerHighlightDuration;
|
|
105
108
|
this.containerHighlightType = config.containerHighlightType;
|
|
109
|
+
this.disabledMultiSelect = config.disabledMultiSelect ?? false;
|
|
106
110
|
this.getTargetElement = config.getTargetElement;
|
|
107
111
|
this.getElementsFromPoint = config.getElementsFromPoint;
|
|
108
112
|
this.canSelect = config.canSelect || ((el: HTMLElement) => !!el.id);
|
|
109
113
|
this.getRenderDocument = config.getRenderDocument;
|
|
110
114
|
this.isContainer = config.isContainer;
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
116
|
+
this.dr = this.createDr(config);
|
|
117
|
+
|
|
118
|
+
if (!this.disabledMultiSelect) {
|
|
119
|
+
this.multiDr = this.createMultiDr(config);
|
|
120
|
+
}
|
|
117
121
|
|
|
118
|
-
this.dr = new StageDragResize({
|
|
119
|
-
container: config.container,
|
|
120
|
-
disabledDragStart: config.disabledDragStart,
|
|
121
|
-
moveableOptions: this.changeCallback(config.moveableOptions, false),
|
|
122
|
-
dragResizeHelper: createDrHelper(),
|
|
123
|
-
getRootContainer: config.getRootContainer,
|
|
124
|
-
getRenderDocument: config.getRenderDocument,
|
|
125
|
-
markContainerEnd: this.markContainerEnd.bind(this),
|
|
126
|
-
delayedMarkContainer: this.delayedMarkContainer.bind(this),
|
|
127
|
-
});
|
|
128
|
-
this.multiDr = new StageMultiDragResize({
|
|
129
|
-
container: config.container,
|
|
130
|
-
moveableOptions: this.changeCallback(config.moveableOptions, true),
|
|
131
|
-
dragResizeHelper: createDrHelper(),
|
|
132
|
-
getRootContainer: config.getRootContainer,
|
|
133
|
-
getRenderDocument: config.getRenderDocument,
|
|
134
|
-
markContainerEnd: this.markContainerEnd.bind(this),
|
|
135
|
-
delayedMarkContainer: this.delayedMarkContainer.bind(this),
|
|
136
|
-
});
|
|
137
122
|
this.highlightLayer = new StageHighlight({
|
|
138
123
|
container: config.container,
|
|
139
124
|
updateDragEl: config.updateDragEl,
|
|
@@ -142,7 +127,22 @@ export default class ActionManager extends EventEmitter {
|
|
|
142
127
|
|
|
143
128
|
this.initMouseEvent();
|
|
144
129
|
this.initKeyEvent();
|
|
145
|
-
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public disableMultiSelect() {
|
|
133
|
+
this.disabledMultiSelect = true;
|
|
134
|
+
if (this.multiDr) {
|
|
135
|
+
this.multiDr.destroy();
|
|
136
|
+
this.multiDr = undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
public enableMultiSelect() {
|
|
141
|
+
this.disabledMultiSelect = false;
|
|
142
|
+
|
|
143
|
+
if (!this.multiDr) {
|
|
144
|
+
this.multiDr = this.createMultiDr(this.config);
|
|
145
|
+
}
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
/**
|
|
@@ -152,7 +152,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
152
152
|
*/
|
|
153
153
|
public setGuidelines(type: GuidesType, guidelines: number[]): void {
|
|
154
154
|
this.dr.setGuidelines(type, guidelines);
|
|
155
|
-
this.multiDr
|
|
155
|
+
this.multiDr?.setGuidelines(type, guidelines);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
/**
|
|
@@ -160,7 +160,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
160
160
|
*/
|
|
161
161
|
public clearGuides(): void {
|
|
162
162
|
this.dr.clearGuides();
|
|
163
|
-
this.multiDr
|
|
163
|
+
this.multiDr?.clearGuides();
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
/**
|
|
@@ -170,7 +170,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
170
170
|
public updateMoveable(el?: HTMLElement): void {
|
|
171
171
|
this.dr.updateMoveable(el);
|
|
172
172
|
// 多选时不可配置元素,因此不存在多选元素变更,不需要传el
|
|
173
|
-
this.multiDr
|
|
173
|
+
this.multiDr?.updateMoveable();
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
/**
|
|
@@ -181,7 +181,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
181
181
|
return el.id === this.selectedEl?.id;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
public setSelectedEl(el
|
|
184
|
+
public setSelectedEl(el?: HTMLElement): void {
|
|
185
185
|
this.selectedEl = el;
|
|
186
186
|
}
|
|
187
187
|
|
|
@@ -197,7 +197,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
197
197
|
if (this.dr.getTarget()) {
|
|
198
198
|
return this.dr.getOption(key);
|
|
199
199
|
}
|
|
200
|
-
if (this.multiDr
|
|
200
|
+
if (this.multiDr?.targetList.length) {
|
|
201
201
|
return this.multiDr.getOption(key);
|
|
202
202
|
}
|
|
203
203
|
}
|
|
@@ -254,11 +254,11 @@ export default class ActionManager extends EventEmitter {
|
|
|
254
254
|
if (selectedEl?.className.includes(PAGE_CLASS)) {
|
|
255
255
|
return true;
|
|
256
256
|
}
|
|
257
|
-
return this.multiDr
|
|
257
|
+
return this.multiDr?.canSelect(el, selectedEl) || false;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
public select(el: HTMLElement, event: MouseEvent | undefined): void {
|
|
261
|
-
this.
|
|
261
|
+
this.setSelectedEl(el);
|
|
262
262
|
this.clearSelectStatus(SelectStatus.MULTI_SELECT);
|
|
263
263
|
this.dr.select(el, event);
|
|
264
264
|
}
|
|
@@ -266,7 +266,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
266
266
|
public multiSelect(idOrElList: HTMLElement[] | Id[]): void {
|
|
267
267
|
this.selectedElList = idOrElList.map((idOrEl) => this.getTargetElement(idOrEl));
|
|
268
268
|
this.clearSelectStatus(SelectStatus.SELECT);
|
|
269
|
-
this.multiDr
|
|
269
|
+
this.multiDr?.multiSelect(this.selectedElList);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
public getHighlightEl(): HTMLElement | undefined {
|
|
@@ -287,7 +287,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
// 选中组件不高亮、多选拖拽状态不高亮
|
|
290
|
-
if (el === this.getSelectedEl() || this.multiDr
|
|
290
|
+
if (el === this.getSelectedEl() || this.multiDr?.dragStatus === StageDragStatus.ING) {
|
|
291
291
|
this.clearHighlight();
|
|
292
292
|
return;
|
|
293
293
|
}
|
|
@@ -309,7 +309,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
309
309
|
*/
|
|
310
310
|
public clearSelectStatus(selectType: SelectStatus): void {
|
|
311
311
|
if (selectType === SelectStatus.MULTI_SELECT) {
|
|
312
|
-
this.multiDr
|
|
312
|
+
this.multiDr?.clearSelectStatus();
|
|
313
313
|
this.selectedElList = [];
|
|
314
314
|
} else {
|
|
315
315
|
this.dr.clearSelectStatus();
|
|
@@ -361,10 +361,84 @@ export default class ActionManager extends EventEmitter {
|
|
|
361
361
|
this.container.removeEventListener('mouseleave', this.mouseLeaveHandler);
|
|
362
362
|
this.container.removeEventListener('wheel', this.mouseWheelHandler);
|
|
363
363
|
this.dr.destroy();
|
|
364
|
-
this.multiDr
|
|
364
|
+
this.multiDr?.destroy();
|
|
365
365
|
this.highlightLayer.destroy();
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
+
private createDr(config: ActionManagerConfig) {
|
|
369
|
+
const createDrHelper = () =>
|
|
370
|
+
new DragResizeHelper({
|
|
371
|
+
container: config.container,
|
|
372
|
+
updateDragEl: config.updateDragEl,
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
const dr = new StageDragResize({
|
|
376
|
+
container: config.container,
|
|
377
|
+
disabledDragStart: config.disabledDragStart,
|
|
378
|
+
moveableOptions: this.changeCallback(config.moveableOptions, false),
|
|
379
|
+
dragResizeHelper: createDrHelper(),
|
|
380
|
+
getRootContainer: config.getRootContainer,
|
|
381
|
+
getRenderDocument: config.getRenderDocument,
|
|
382
|
+
markContainerEnd: this.markContainerEnd.bind(this),
|
|
383
|
+
delayedMarkContainer: this.delayedMarkContainer.bind(this),
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
dr.on('update', (data: UpdateEventData) => {
|
|
387
|
+
// 点击组件并立即拖动的场景,要保证select先被触发,延迟update通知
|
|
388
|
+
setTimeout(() => this.emit('update', data));
|
|
389
|
+
})
|
|
390
|
+
.on('sort', (data: UpdateEventData) => {
|
|
391
|
+
// 点击组件并立即拖动的场景,要保证select先被触发,延迟update通知
|
|
392
|
+
setTimeout(() => this.emit('sort', data));
|
|
393
|
+
})
|
|
394
|
+
.on('select-parent', () => {
|
|
395
|
+
this.emit('select-parent');
|
|
396
|
+
})
|
|
397
|
+
.on('remove', () => {
|
|
398
|
+
const drTarget = this.dr.getTarget();
|
|
399
|
+
if (!drTarget) return;
|
|
400
|
+
const data: RemoveEventData = {
|
|
401
|
+
data: [{ el: drTarget }],
|
|
402
|
+
};
|
|
403
|
+
this.emit('remove', data);
|
|
404
|
+
})
|
|
405
|
+
.on('drag-start', (e: OnDragStart) => {
|
|
406
|
+
this.emit('drag-start', e);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
return dr;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private createMultiDr(config: ActionManagerConfig) {
|
|
413
|
+
const createDrHelper = () =>
|
|
414
|
+
new DragResizeHelper({
|
|
415
|
+
container: config.container,
|
|
416
|
+
updateDragEl: config.updateDragEl,
|
|
417
|
+
});
|
|
418
|
+
const multiDr = new StageMultiDragResize({
|
|
419
|
+
container: config.container,
|
|
420
|
+
moveableOptions: this.changeCallback(config.moveableOptions, true),
|
|
421
|
+
dragResizeHelper: createDrHelper(),
|
|
422
|
+
getRootContainer: config.getRootContainer,
|
|
423
|
+
getRenderDocument: config.getRenderDocument,
|
|
424
|
+
markContainerEnd: this.markContainerEnd.bind(this),
|
|
425
|
+
delayedMarkContainer: this.delayedMarkContainer.bind(this),
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
multiDr
|
|
429
|
+
?.on('update', (data: UpdateEventData) => {
|
|
430
|
+
this.emit('multi-update', data);
|
|
431
|
+
})
|
|
432
|
+
.on('change-to-select', async (id: Id) => {
|
|
433
|
+
// 如果还在多选状态,不触发切换到单选
|
|
434
|
+
if (this.isMultiSelectStatus) return false;
|
|
435
|
+
const el = this.getTargetElement(id);
|
|
436
|
+
this.emit('change-to-select', el);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
return multiDr;
|
|
440
|
+
}
|
|
441
|
+
|
|
368
442
|
private changeCallback(options: CustomizeMoveableOptions, isMulti: boolean): CustomizeMoveableOptions {
|
|
369
443
|
// 在actionManager才能获取到各种参数,在这里传好参数有比较好的扩展性
|
|
370
444
|
if (typeof options === 'function') {
|
|
@@ -399,7 +473,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
399
473
|
// 如果已有单选选中元素,不是magic-ui-page就可以加入多选列表
|
|
400
474
|
if (this.selectedEl && !this.selectedEl.className.includes(PAGE_CLASS)) {
|
|
401
475
|
this.selectedElList.push(this.selectedEl as HTMLElement);
|
|
402
|
-
this.
|
|
476
|
+
this.setSelectedEl(undefined);
|
|
403
477
|
}
|
|
404
478
|
// 判断元素是否已在多选列表
|
|
405
479
|
const existIndex = this.selectedElList.findIndex((selectedDom) => selectedDom.id === el.id);
|
|
@@ -450,15 +524,21 @@ export default class ActionManager extends EventEmitter {
|
|
|
450
524
|
// 多选启用状态监听
|
|
451
525
|
KeyController.global.keydown(ctrl, (e) => {
|
|
452
526
|
e.inputEvent.preventDefault();
|
|
453
|
-
this.
|
|
527
|
+
if (!this.disabledMultiSelect) {
|
|
528
|
+
this.isMultiSelectStatus = true;
|
|
529
|
+
}
|
|
454
530
|
});
|
|
455
531
|
// ctrl+tab切到其他窗口,需要将多选状态置为false
|
|
456
532
|
KeyController.global.on('blur', () => {
|
|
457
|
-
this.
|
|
533
|
+
if (!this.disabledMultiSelect) {
|
|
534
|
+
this.isMultiSelectStatus = false;
|
|
535
|
+
}
|
|
458
536
|
});
|
|
459
537
|
KeyController.global.keyup(ctrl, (e) => {
|
|
460
538
|
e.inputEvent.preventDefault();
|
|
461
|
-
this.
|
|
539
|
+
if (!this.disabledMultiSelect) {
|
|
540
|
+
this.isMultiSelectStatus = false;
|
|
541
|
+
}
|
|
462
542
|
});
|
|
463
543
|
|
|
464
544
|
// alt健监听,用于启用拖拽组件加入容器状态
|
|
@@ -474,46 +554,6 @@ export default class ActionManager extends EventEmitter {
|
|
|
474
554
|
});
|
|
475
555
|
}
|
|
476
556
|
|
|
477
|
-
/**
|
|
478
|
-
* 处理单选、多选抛出来的事件
|
|
479
|
-
*/
|
|
480
|
-
private initActionEvent(): void {
|
|
481
|
-
this.dr
|
|
482
|
-
.on('update', (data: UpdateEventData) => {
|
|
483
|
-
// 点击组件并立即拖动的场景,要保证select先被触发,延迟update通知
|
|
484
|
-
setTimeout(() => this.emit('update', data));
|
|
485
|
-
})
|
|
486
|
-
.on('sort', (data: UpdateEventData) => {
|
|
487
|
-
// 点击组件并立即拖动的场景,要保证select先被触发,延迟update通知
|
|
488
|
-
setTimeout(() => this.emit('sort', data));
|
|
489
|
-
})
|
|
490
|
-
.on('select-parent', () => {
|
|
491
|
-
this.emit('select-parent');
|
|
492
|
-
})
|
|
493
|
-
.on('remove', () => {
|
|
494
|
-
const drTarget = this.dr.getTarget();
|
|
495
|
-
if (!drTarget) return;
|
|
496
|
-
const data: RemoveEventData = {
|
|
497
|
-
data: [{ el: drTarget }],
|
|
498
|
-
};
|
|
499
|
-
this.emit('remove', data);
|
|
500
|
-
})
|
|
501
|
-
.on('drag-start', (e: OnDragStart) => {
|
|
502
|
-
this.emit('drag-start', e);
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
this.multiDr
|
|
506
|
-
.on('update', (data: UpdateEventData) => {
|
|
507
|
-
this.emit('multi-update', data);
|
|
508
|
-
})
|
|
509
|
-
.on('change-to-select', async (id: Id) => {
|
|
510
|
-
// 如果还在多选状态,不触发切换到单选
|
|
511
|
-
if (this.isMultiSelectStatus) return false;
|
|
512
|
-
const el = this.getTargetElement(id);
|
|
513
|
-
this.emit('change-to-select', el);
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
|
|
517
557
|
/**
|
|
518
558
|
* 在down事件中集中cpu处理画布中选中操作渲染,在up事件中再通知外面的编辑器更新
|
|
519
559
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MoveableManagerInterface, Renderer } from 'moveable';
|
|
2
2
|
|
|
3
|
+
import { AbleActionEventType } from './const';
|
|
3
4
|
import ableCss from './moveable-able.css?raw';
|
|
4
|
-
import { AbleActionEventType } from './types';
|
|
5
5
|
|
|
6
6
|
export default (handler: (type: AbleActionEventType) => void) => ({
|
|
7
7
|
name: 'actions',
|
|
@@ -21,9 +21,9 @@ import EventEmitter from 'events';
|
|
|
21
21
|
import { merge } from 'lodash-es';
|
|
22
22
|
import type { ElementGuidelineValueOption, MoveableOptions, MoveableRefType } from 'moveable';
|
|
23
23
|
|
|
24
|
-
import { GuidesType, Mode } from './const';
|
|
24
|
+
import { AbleActionEventType, GuidesType, Mode } from './const';
|
|
25
25
|
import MoveableActionsAble from './MoveableActionsAble';
|
|
26
|
-
import {
|
|
26
|
+
import type { GetRootContainer, MoveableOptionsManagerConfig } from './types';
|
|
27
27
|
import { getOffset } from './util';
|
|
28
28
|
|
|
29
29
|
/**
|
package/src/Rule.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
2
|
|
|
3
|
-
import Guides, { GuidesEvents } from '@scena/guides';
|
|
3
|
+
import Guides, { type GuidesEvents, type GuidesOptions } from '@scena/guides';
|
|
4
4
|
|
|
5
5
|
import { GuidesType } from './const';
|
|
6
|
+
import type { RuleOptions } from './types';
|
|
6
7
|
|
|
7
8
|
export default class Rule extends EventEmitter {
|
|
8
9
|
public hGuides: Guides;
|
|
@@ -13,10 +14,13 @@ export default class Rule extends EventEmitter {
|
|
|
13
14
|
private container: HTMLDivElement;
|
|
14
15
|
private containerResizeObserver: ResizeObserver;
|
|
15
16
|
private isShowGuides = true;
|
|
17
|
+
private guidesOptions?: Partial<GuidesOptions>;
|
|
16
18
|
|
|
17
|
-
constructor(container: HTMLDivElement) {
|
|
19
|
+
constructor(container: HTMLDivElement, options?: RuleOptions) {
|
|
18
20
|
super();
|
|
19
21
|
|
|
22
|
+
this.guidesOptions = options?.guidesOptions || {};
|
|
23
|
+
|
|
20
24
|
this.container = container;
|
|
21
25
|
this.hGuides = this.createGuides(GuidesType.HORIZONTAL, this.horizontalGuidelines);
|
|
22
26
|
this.vGuides = this.createGuides(GuidesType.VERTICAL, this.verticalGuidelines);
|
|
@@ -136,6 +140,7 @@ export default class Rule extends EventEmitter {
|
|
|
136
140
|
textColor: '#000',
|
|
137
141
|
style: this.getGuidesStyle(type),
|
|
138
142
|
showGuides: this.isShowGuides,
|
|
143
|
+
...this.guidesOptions,
|
|
139
144
|
});
|
|
140
145
|
|
|
141
146
|
const changEventHandler = {
|
package/src/StageCore.ts
CHANGED
|
@@ -69,7 +69,9 @@ export default class StageCore extends EventEmitter {
|
|
|
69
69
|
return null;
|
|
70
70
|
},
|
|
71
71
|
});
|
|
72
|
-
this.mask = new StageMask(
|
|
72
|
+
this.mask = new StageMask({
|
|
73
|
+
guidesOptions: config.guidesOptions,
|
|
74
|
+
});
|
|
73
75
|
this.actionManager = new ActionManager(this.getActionManagerConfig(config));
|
|
74
76
|
|
|
75
77
|
this.initRenderEvent();
|
|
@@ -222,6 +224,14 @@ export default class StageCore extends EventEmitter {
|
|
|
222
224
|
return this.actionManager.getDragStatus();
|
|
223
225
|
}
|
|
224
226
|
|
|
227
|
+
public disableMultiSelect() {
|
|
228
|
+
this.actionManager.disableMultiSelect();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
public enableMultiSelect() {
|
|
232
|
+
this.actionManager.enableMultiSelect();
|
|
233
|
+
}
|
|
234
|
+
|
|
225
235
|
/**
|
|
226
236
|
* 销毁实例
|
|
227
237
|
*/
|
|
@@ -260,6 +270,7 @@ export default class StageCore extends EventEmitter {
|
|
|
260
270
|
moveableOptions: config.moveableOptions,
|
|
261
271
|
container: this.mask.content,
|
|
262
272
|
disabledDragStart: config.disabledDragStart,
|
|
273
|
+
disabledMultiSelect: config.disabledMultiSelect,
|
|
263
274
|
canSelect: config.canSelect,
|
|
264
275
|
isContainer: config.isContainer,
|
|
265
276
|
updateDragEl: config.updateDragEl,
|
|
@@ -279,6 +290,8 @@ export default class StageCore extends EventEmitter {
|
|
|
279
290
|
this.renderer.on('page-el-update', (el: HTMLElement) => {
|
|
280
291
|
this.mask?.observe(el);
|
|
281
292
|
this.observePageResize(el);
|
|
293
|
+
|
|
294
|
+
this.emit('page-el-update', el);
|
|
282
295
|
});
|
|
283
296
|
}
|
|
284
297
|
|
package/src/StageMask.ts
CHANGED
|
@@ -20,6 +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
24
|
import { getScrollParent, isFixedParent } from './util';
|
|
24
25
|
|
|
25
26
|
const wrapperClassName = 'editor-mask-wrapper';
|
|
@@ -80,9 +81,9 @@ export default class StageMask extends Rule {
|
|
|
80
81
|
private intersectionObserver: IntersectionObserver | null = null;
|
|
81
82
|
private wrapperResizeObserver: ResizeObserver | null = null;
|
|
82
83
|
|
|
83
|
-
constructor() {
|
|
84
|
+
constructor(options?: RuleOptions) {
|
|
84
85
|
const wrapper = createWrapper();
|
|
85
|
-
super(wrapper);
|
|
86
|
+
super(wrapper, options);
|
|
86
87
|
|
|
87
88
|
this.wrapper = wrapper;
|
|
88
89
|
|
package/src/StageRender.ts
CHANGED
|
@@ -156,12 +156,6 @@ export default class StageRender extends EventEmitter {
|
|
|
156
156
|
x = x - rect.left;
|
|
157
157
|
y = y - rect.top;
|
|
158
158
|
}
|
|
159
|
-
} else if (this.nativeContainer) {
|
|
160
|
-
const rect = this.nativeContainer.getClientRects()[0];
|
|
161
|
-
if (rect) {
|
|
162
|
-
x = x - rect.left;
|
|
163
|
-
y = y - rect.top;
|
|
164
|
-
}
|
|
165
159
|
}
|
|
166
160
|
|
|
167
161
|
return this.getDocument()?.elementsFromPoint(x / this.zoom, y / this.zoom) as HTMLElement[];
|
package/src/const.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import StageCore from './StageCore';
|
|
20
20
|
|
|
21
21
|
export type { MoveableOptions, OnDragStart } from 'moveable';
|
|
22
|
+
export type { GuidesOptions } from '@scena/guides';
|
|
22
23
|
export { default as StageRender } from './StageRender';
|
|
23
24
|
export { default as StageMask } from './StageMask';
|
|
24
25
|
export { default as StageDragResize } from './StageDragResize';
|
package/src/types.ts
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import type { GuidesOptions } from '@scena/guides';
|
|
19
20
|
import type { MoveableOptions } from 'moveable';
|
|
20
21
|
|
|
21
22
|
import Core from '@tmagic/core';
|
|
@@ -77,6 +78,8 @@ export interface StageCoreConfig {
|
|
|
77
78
|
updateDragEl?: UpdateDragEl;
|
|
78
79
|
disabledDragStart?: boolean;
|
|
79
80
|
renderType?: RenderType;
|
|
81
|
+
guidesOptions?: Partial<GuidesOptions>;
|
|
82
|
+
disabledMultiSelect?: boolean;
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
export interface ActionManagerConfig {
|
|
@@ -86,6 +89,7 @@ export interface ActionManagerConfig {
|
|
|
86
89
|
containerHighlightType?: ContainerHighlightType;
|
|
87
90
|
moveableOptions?: CustomizeMoveableOptions;
|
|
88
91
|
disabledDragStart?: boolean;
|
|
92
|
+
disabledMultiSelect?: boolean;
|
|
89
93
|
canSelect?: CanSelect;
|
|
90
94
|
isContainer: IsContainer;
|
|
91
95
|
getRootContainer: GetRootContainer;
|
|
@@ -264,7 +268,6 @@ export interface TargetShadowConfig {
|
|
|
264
268
|
idPrefix?: string;
|
|
265
269
|
}
|
|
266
270
|
|
|
267
|
-
export
|
|
268
|
-
|
|
269
|
-
REMOVE = 'remove',
|
|
271
|
+
export interface RuleOptions {
|
|
272
|
+
guidesOptions?: Partial<GuidesOptions>;
|
|
270
273
|
}
|
package/types/ActionManager.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { ActionManagerConfig, SelectStatus, StageDragStatus } from './types';
|
|
|
11
11
|
*/
|
|
12
12
|
export default class ActionManager extends EventEmitter {
|
|
13
13
|
private dr;
|
|
14
|
-
private multiDr
|
|
14
|
+
private multiDr?;
|
|
15
15
|
private highlightLayer;
|
|
16
16
|
/** 单选、多选、高亮的容器(蒙层的content) */
|
|
17
17
|
private container;
|
|
@@ -35,8 +35,12 @@ export default class ActionManager extends EventEmitter {
|
|
|
35
35
|
private canSelect;
|
|
36
36
|
private isContainer;
|
|
37
37
|
private getRenderDocument;
|
|
38
|
+
private disabledMultiSelect;
|
|
39
|
+
private config;
|
|
38
40
|
private mouseMoveHandler;
|
|
39
41
|
constructor(config: ActionManagerConfig);
|
|
42
|
+
disableMultiSelect(): void;
|
|
43
|
+
enableMultiSelect(): void;
|
|
40
44
|
/**
|
|
41
45
|
* 设置水平/垂直参考线
|
|
42
46
|
* @param type 参考线类型
|
|
@@ -56,7 +60,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
56
60
|
* 判断是否单选选中的元素
|
|
57
61
|
*/
|
|
58
62
|
isSelectedEl(el: HTMLElement): boolean;
|
|
59
|
-
setSelectedEl(el
|
|
63
|
+
setSelectedEl(el?: HTMLElement): void;
|
|
60
64
|
getSelectedEl(): HTMLElement | undefined;
|
|
61
65
|
getSelectedElList(): HTMLElement[];
|
|
62
66
|
getMoveableOption<K extends keyof MoveableOptions>(key: K): MoveableOptions[K] | undefined;
|
|
@@ -105,6 +109,8 @@ export default class ActionManager extends EventEmitter {
|
|
|
105
109
|
delayedMarkContainer(event: MouseEvent, excludeElList?: Element[]): NodeJS.Timeout | undefined;
|
|
106
110
|
getDragStatus(): StageDragStatus;
|
|
107
111
|
destroy(): void;
|
|
112
|
+
private createDr;
|
|
113
|
+
private createMultiDr;
|
|
108
114
|
private changeCallback;
|
|
109
115
|
/**
|
|
110
116
|
* 在执行多选逻辑前,先准备好多选选中元素
|
|
@@ -126,10 +132,6 @@ export default class ActionManager extends EventEmitter {
|
|
|
126
132
|
* 初始化键盘事件监听
|
|
127
133
|
*/
|
|
128
134
|
private initKeyEvent;
|
|
129
|
-
/**
|
|
130
|
-
* 处理单选、多选抛出来的事件
|
|
131
|
-
*/
|
|
132
|
-
private initActionEvent;
|
|
133
135
|
/**
|
|
134
136
|
* 在down事件中集中cpu处理画布中选中操作渲染,在up事件中再通知外面的编辑器更新
|
|
135
137
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MoveableManagerInterface, Renderer } from 'moveable';
|
|
2
|
-
import { AbleActionEventType } from './
|
|
2
|
+
import { AbleActionEventType } from './const';
|
|
3
3
|
declare const _default: (handler: (type: AbleActionEventType) => void) => {
|
|
4
4
|
name: string;
|
|
5
5
|
props: never[];
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
3
|
import type { MoveableOptions } from 'moveable';
|
|
4
4
|
import { GuidesType, Mode } from './const';
|
|
5
|
-
import { MoveableOptionsManagerConfig } from './types';
|
|
5
|
+
import type { MoveableOptionsManagerConfig } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* 单选和多选的父类,用于管理moveableOptions
|
|
8
8
|
* @extends EventEmitter
|
package/types/Rule.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
3
|
import Guides from '@scena/guides';
|
|
4
|
+
import type { RuleOptions } from './types';
|
|
4
5
|
export default class Rule extends EventEmitter {
|
|
5
6
|
hGuides: Guides;
|
|
6
7
|
vGuides: Guides;
|
|
@@ -9,7 +10,8 @@ export default class Rule extends EventEmitter {
|
|
|
9
10
|
private container;
|
|
10
11
|
private containerResizeObserver;
|
|
11
12
|
private isShowGuides;
|
|
12
|
-
|
|
13
|
+
private guidesOptions?;
|
|
14
|
+
constructor(container: HTMLDivElement, options?: RuleOptions);
|
|
13
15
|
/**
|
|
14
16
|
* 是否显示辅助线
|
|
15
17
|
* @param isShowGuides 是否显示
|
package/types/StageCore.d.ts
CHANGED
|
@@ -73,6 +73,8 @@ export default class StageCore extends EventEmitter {
|
|
|
73
73
|
delayedMarkContainer(event: MouseEvent, excludeElList?: Element[]): NodeJS.Timeout | undefined;
|
|
74
74
|
getMoveableOption<K extends keyof MoveableOptions>(key: K): MoveableOptions[K] | undefined;
|
|
75
75
|
getDragStatus(): import("./types").StageDragStatus;
|
|
76
|
+
disableMultiSelect(): void;
|
|
77
|
+
enableMultiSelect(): void;
|
|
76
78
|
/**
|
|
77
79
|
* 销毁实例
|
|
78
80
|
*/
|