@tmagic/stage 1.3.0-alpha.9 → 1.3.0-beta.1
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 +118 -78
- package/dist/tmagic-stage.js.map +1 -1
- package/dist/tmagic-stage.umd.cjs +118 -78
- package/dist/tmagic-stage.umd.cjs.map +1 -1
- package/package.json +8 -8
- package/src/ActionManager.ts +30 -4
- package/src/MoveableActionsAble.ts +36 -54
- package/src/MoveableOptionsManager.ts +11 -5
- package/src/StageCore.ts +33 -3
- package/src/StageDragResize.ts +7 -2
- package/src/StageHighlight.ts +18 -11
- package/src/StageMultiDragResize.ts +2 -2
- package/src/index.ts +1 -1
- package/src/moveable-able.css +108 -0
- package/src/types.ts +5 -3
- package/types/ActionManager.d.ts +5 -2
- package/types/MoveableActionsAble.d.ts +2 -4
- package/types/MoveableOptionsManager.d.ts +2 -0
- package/types/StageCore.d.ts +10 -2
- package/types/StageDragResize.d.ts +2 -0
- package/types/StageHighlight.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/types.d.ts +5 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.0-
|
|
2
|
+
"version": "1.3.0-beta.1",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"url": "https://github.com/Tencent/tmagic-editor.git"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@scena/guides": "^0.
|
|
33
|
-
"@tmagic/core": "1.3.0-
|
|
34
|
-
"@tmagic/schema": "1.3.0-
|
|
35
|
-
"@tmagic/utils": "1.3.0-
|
|
32
|
+
"@scena/guides": "^0.29.2",
|
|
33
|
+
"@tmagic/core": "1.3.0-beta.1",
|
|
34
|
+
"@tmagic/schema": "1.3.0-beta.1",
|
|
35
|
+
"@tmagic/utils": "1.3.0-beta.1",
|
|
36
36
|
"events": "^3.3.0",
|
|
37
|
-
"keycon": "^1.
|
|
37
|
+
"keycon": "^1.4.0",
|
|
38
38
|
"lodash-es": "^4.17.21",
|
|
39
|
-
"moveable": "^0.
|
|
39
|
+
"moveable": "^0.51.1",
|
|
40
40
|
"moveable-helper": "^0.4.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
@@ -46,6 +46,6 @@
|
|
|
46
46
|
"rimraf": "^3.0.2",
|
|
47
47
|
"sass": "^1.35.1",
|
|
48
48
|
"typescript": "^5.0.4",
|
|
49
|
-
"vite": "^4.
|
|
49
|
+
"vite": "^4.4.4"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/ActionManager.ts
CHANGED
|
@@ -19,9 +19,10 @@ import EventEmitter from 'events';
|
|
|
19
19
|
|
|
20
20
|
import KeyController from 'keycon';
|
|
21
21
|
import { throttle } from 'lodash-es';
|
|
22
|
+
import type { MoveableOptions, OnDragStart } from 'moveable';
|
|
22
23
|
|
|
23
24
|
import { Env } from '@tmagic/core';
|
|
24
|
-
import { Id } from '@tmagic/schema';
|
|
25
|
+
import type { Id } from '@tmagic/schema';
|
|
25
26
|
import { addClassName, getDocument, removeClassNameByClassName } from '@tmagic/utils';
|
|
26
27
|
|
|
27
28
|
import { CONTAINER_HIGHLIGHT_CLASS_NAME, GHOST_EL_ID_PREFIX, GuidesType, MouseButton, PAGE_CLASS } from './const';
|
|
@@ -87,6 +88,9 @@ export default class ActionManager extends EventEmitter {
|
|
|
87
88
|
this.clearHighlight();
|
|
88
89
|
return;
|
|
89
90
|
}
|
|
91
|
+
|
|
92
|
+
this.emit('mousemove', event);
|
|
93
|
+
|
|
90
94
|
this.highlight(el);
|
|
91
95
|
}, throttleTime);
|
|
92
96
|
|
|
@@ -111,7 +115,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
111
115
|
this.dr = new StageDragResize({
|
|
112
116
|
container: config.container,
|
|
113
117
|
disabledDragStart: config.disabledDragStart,
|
|
114
|
-
moveableOptions: this.changeCallback(config.moveableOptions),
|
|
118
|
+
moveableOptions: this.changeCallback(config.moveableOptions, false),
|
|
115
119
|
dragResizeHelper: createDrHelper(),
|
|
116
120
|
getRootContainer: config.getRootContainer,
|
|
117
121
|
getRenderDocument: config.getRenderDocument,
|
|
@@ -120,7 +124,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
120
124
|
});
|
|
121
125
|
this.multiDr = new StageMultiDragResize({
|
|
122
126
|
container: config.container,
|
|
123
|
-
|
|
127
|
+
moveableOptions: this.changeCallback(config.moveableOptions, true),
|
|
124
128
|
dragResizeHelper: createDrHelper(),
|
|
125
129
|
getRootContainer: config.getRootContainer,
|
|
126
130
|
getRenderDocument: config.getRenderDocument,
|
|
@@ -186,6 +190,15 @@ export default class ActionManager extends EventEmitter {
|
|
|
186
190
|
return this.selectedElList;
|
|
187
191
|
}
|
|
188
192
|
|
|
193
|
+
public getMoveableOption<K extends keyof MoveableOptions>(key: K): MoveableOptions[K] | undefined {
|
|
194
|
+
if (this.dr.getTarget()) {
|
|
195
|
+
return this.dr.getOption(key);
|
|
196
|
+
}
|
|
197
|
+
if (this.multiDr.targetList.length) {
|
|
198
|
+
return this.multiDr.getOption(key);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
189
202
|
/**
|
|
190
203
|
* 获取鼠标下方第一个可选中元素,如果元素层叠,返回到是最上层元素
|
|
191
204
|
* @param event 鼠标事件
|
|
@@ -194,6 +207,8 @@ export default class ActionManager extends EventEmitter {
|
|
|
194
207
|
public async getElementFromPoint(event: MouseEvent): Promise<HTMLElement | undefined> {
|
|
195
208
|
const els = this.getElementsFromPoint(event as Point);
|
|
196
209
|
|
|
210
|
+
this.emit('get-elements-from-point', els);
|
|
211
|
+
|
|
197
212
|
let stopped = false;
|
|
198
213
|
const stop = () => (stopped = true);
|
|
199
214
|
for (const el of els) {
|
|
@@ -333,6 +348,10 @@ export default class ActionManager extends EventEmitter {
|
|
|
333
348
|
return undefined;
|
|
334
349
|
}
|
|
335
350
|
|
|
351
|
+
public getDragStatus() {
|
|
352
|
+
return this.dr.getDragStatus();
|
|
353
|
+
}
|
|
354
|
+
|
|
336
355
|
public destroy(): void {
|
|
337
356
|
this.container.removeEventListener('mousedown', this.mouseDownHandler);
|
|
338
357
|
this.container.removeEventListener('mousemove', this.mouseMoveHandler);
|
|
@@ -343,14 +362,18 @@ export default class ActionManager extends EventEmitter {
|
|
|
343
362
|
this.highlightLayer.destroy();
|
|
344
363
|
}
|
|
345
364
|
|
|
346
|
-
private changeCallback(options: CustomizeMoveableOptions): CustomizeMoveableOptions {
|
|
365
|
+
private changeCallback(options: CustomizeMoveableOptions, isMulti: boolean): CustomizeMoveableOptions {
|
|
347
366
|
// 在actionManager才能获取到各种参数,在这里传好参数有比较好的扩展性
|
|
348
367
|
if (typeof options === 'function') {
|
|
349
368
|
return () => {
|
|
350
369
|
// 要再判断一次,不然过不了ts检查
|
|
351
370
|
if (typeof options === 'function') {
|
|
352
371
|
const cfg: CustomizeMoveableOptionsCallbackConfig = {
|
|
372
|
+
targetEl: this.selectedEl,
|
|
353
373
|
targetElId: this.selectedEl?.id,
|
|
374
|
+
targetEls: this.selectedElList,
|
|
375
|
+
targetElIds: this.selectedElList?.map((item) => item.id),
|
|
376
|
+
isMulti,
|
|
354
377
|
};
|
|
355
378
|
return options(cfg);
|
|
356
379
|
}
|
|
@@ -470,6 +493,9 @@ export default class ActionManager extends EventEmitter {
|
|
|
470
493
|
data: [{ el: drTarget }],
|
|
471
494
|
};
|
|
472
495
|
this.emit('remove', data);
|
|
496
|
+
})
|
|
497
|
+
.on('drag-start', (e: OnDragStart) => {
|
|
498
|
+
this.emit('drag-start', e);
|
|
473
499
|
});
|
|
474
500
|
|
|
475
501
|
this.multiDr
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { MoveableManagerInterface, Renderer } from 'moveable';
|
|
2
2
|
|
|
3
|
+
import ableCss from './moveable-able.css?raw';
|
|
3
4
|
import { AbleActionEventType } from './types';
|
|
4
5
|
|
|
5
6
|
export default (handler: (type: AbleActionEventType) => void) => ({
|
|
6
7
|
name: 'actions',
|
|
7
|
-
props:
|
|
8
|
-
|
|
9
|
-
},
|
|
10
|
-
events: {},
|
|
8
|
+
props: [],
|
|
9
|
+
events: [],
|
|
11
10
|
render(moveable: MoveableManagerInterface<any, any>, React: Renderer) {
|
|
12
11
|
const rect = moveable.getRect();
|
|
13
12
|
const { pos2 } = moveable.state;
|
|
@@ -24,34 +23,7 @@ export default (handler: (type: AbleActionEventType) => void) => ({
|
|
|
24
23
|
transform-origin: 0px 0px;
|
|
25
24
|
display: flex;
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
width: 20px;
|
|
29
|
-
height: 20px;
|
|
30
|
-
background: #4af;
|
|
31
|
-
border-radius: 4px;
|
|
32
|
-
appearance: none;
|
|
33
|
-
border: 0;
|
|
34
|
-
color: white;
|
|
35
|
-
font-size: 12px;
|
|
36
|
-
font-weight: bold;
|
|
37
|
-
margin-left: 2px;
|
|
38
|
-
position: relative;
|
|
39
|
-
}
|
|
40
|
-
.moveable-remove-button:before, .moveable-remove-button:after {
|
|
41
|
-
content: "";
|
|
42
|
-
position: absolute;
|
|
43
|
-
left: 50%;
|
|
44
|
-
top: 50%;
|
|
45
|
-
transform: translate(-50%, -50%) rotate(45deg);
|
|
46
|
-
width: 14px;
|
|
47
|
-
height: 2px;
|
|
48
|
-
background: #fff;
|
|
49
|
-
border-radius: 1px;
|
|
50
|
-
cursor: pointer;
|
|
51
|
-
}
|
|
52
|
-
.moveable-remove-button:after {
|
|
53
|
-
transform: translate(-50%, -50%) rotate(-45deg);
|
|
54
|
-
}
|
|
26
|
+
${ableCss}
|
|
55
27
|
`,
|
|
56
28
|
);
|
|
57
29
|
// Add key (required)
|
|
@@ -61,7 +33,7 @@ export default (handler: (type: AbleActionEventType) => void) => ({
|
|
|
61
33
|
{
|
|
62
34
|
className: 'moveable-editable',
|
|
63
35
|
style: {
|
|
64
|
-
transform: `translate(${pos2[0] -
|
|
36
|
+
transform: `translate(${pos2[0] - 60}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg)`,
|
|
65
37
|
},
|
|
66
38
|
},
|
|
67
39
|
[
|
|
@@ -74,27 +46,12 @@ export default (handler: (type: AbleActionEventType) => void) => ({
|
|
|
74
46
|
handler(AbleActionEventType.SELECT_PARENT);
|
|
75
47
|
},
|
|
76
48
|
},
|
|
77
|
-
React.createElement(
|
|
78
|
-
'
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
fill: 'none',
|
|
84
|
-
xmlns: 'http://www.w3.org/2000/svg',
|
|
85
|
-
style: {
|
|
86
|
-
transform: 'rotate(90deg)',
|
|
87
|
-
position: 'absolute',
|
|
88
|
-
left: 0,
|
|
89
|
-
top: 0,
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
React.createElement('path', {
|
|
93
|
-
d: 'M13.0001 4V10H4.20718L5.85363 8.35355L5.14652 7.64645L2.64652 10.1464C2.45126 10.3417 2.45126 10.6583 2.64652 10.8536L5.14652 13.3536L5.85363 12.6464L4.20718 11H13.0001C13.5524 11 14.0001 10.5523 14.0001 10V4H13.0001Z',
|
|
94
|
-
fill: 'currentColor',
|
|
95
|
-
fillOpacity: '0.9',
|
|
96
|
-
}),
|
|
97
|
-
),
|
|
49
|
+
React.createElement('div', {
|
|
50
|
+
className: 'moveable-select-parent-arrow-top-icon',
|
|
51
|
+
}),
|
|
52
|
+
React.createElement('div', {
|
|
53
|
+
className: 'moveable-select-parent-arrow-body-icon',
|
|
54
|
+
}),
|
|
98
55
|
),
|
|
99
56
|
React.createElement('button', {
|
|
100
57
|
className: 'moveable-button moveable-remove-button',
|
|
@@ -103,6 +60,31 @@ export default (handler: (type: AbleActionEventType) => void) => ({
|
|
|
103
60
|
handler(AbleActionEventType.REMOVE);
|
|
104
61
|
},
|
|
105
62
|
}),
|
|
63
|
+
React.createElement(
|
|
64
|
+
'button',
|
|
65
|
+
{
|
|
66
|
+
className: 'moveable-button moveable-drag-area-button',
|
|
67
|
+
title: '拖动',
|
|
68
|
+
},
|
|
69
|
+
React.createElement('div', {
|
|
70
|
+
className: 'moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-top',
|
|
71
|
+
}),
|
|
72
|
+
React.createElement('div', {
|
|
73
|
+
className: 'moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-bottom',
|
|
74
|
+
}),
|
|
75
|
+
React.createElement('div', {
|
|
76
|
+
className: 'moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-left',
|
|
77
|
+
}),
|
|
78
|
+
React.createElement('div', {
|
|
79
|
+
className: ' moveable-select-parent-arrow-top-icon moveable-select-parent-arrow-top-icon-right',
|
|
80
|
+
}),
|
|
81
|
+
React.createElement('div', {
|
|
82
|
+
className: 'moveable-select-parent-arrow-body-icon-horizontal',
|
|
83
|
+
}),
|
|
84
|
+
React.createElement('div', {
|
|
85
|
+
className: 'moveable-select-parent-arrow-body-icon-vertical',
|
|
86
|
+
}),
|
|
87
|
+
),
|
|
106
88
|
],
|
|
107
89
|
);
|
|
108
90
|
},
|
|
@@ -36,6 +36,7 @@ export default class MoveableOptionsManager extends EventEmitter {
|
|
|
36
36
|
|
|
37
37
|
/** 画布容器 */
|
|
38
38
|
protected container: HTMLElement;
|
|
39
|
+
protected options: MoveableOptions = {};
|
|
39
40
|
|
|
40
41
|
/** 水平参考线 */
|
|
41
42
|
private horizontalGuidelines: number[] = [];
|
|
@@ -55,6 +56,10 @@ export default class MoveableOptionsManager extends EventEmitter {
|
|
|
55
56
|
this.getRootContainer = config.getRootContainer;
|
|
56
57
|
}
|
|
57
58
|
|
|
59
|
+
public getOption<K extends keyof MoveableOptions>(key: K): MoveableOptions[K] {
|
|
60
|
+
return this.options[key];
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
/**
|
|
59
64
|
* 设置水平/垂直参考线
|
|
60
65
|
* @param type 参考线类型
|
|
@@ -106,7 +111,8 @@ export default class MoveableOptionsManager extends EventEmitter {
|
|
|
106
111
|
const defaultOptions = this.getDefaultOptions(isMultiSelect);
|
|
107
112
|
const customizedOptions = this.getCustomizeOptions();
|
|
108
113
|
|
|
109
|
-
|
|
114
|
+
this.options = merge(defaultOptions, customizedOptions, runtimeOptions);
|
|
115
|
+
return this.options;
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
/**
|
|
@@ -128,9 +134,8 @@ export default class MoveableOptionsManager extends EventEmitter {
|
|
|
128
134
|
elementGuidelines: this.elementGuidelines,
|
|
129
135
|
bounds: {
|
|
130
136
|
top: 0,
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
right: this.container.clientWidth - 1,
|
|
137
|
+
left: 0,
|
|
138
|
+
right: this.container.clientWidth,
|
|
134
139
|
bottom: isSortable ? undefined : this.container.clientHeight,
|
|
135
140
|
},
|
|
136
141
|
};
|
|
@@ -171,7 +176,8 @@ export default class MoveableOptionsManager extends EventEmitter {
|
|
|
171
176
|
left: isAbsolute,
|
|
172
177
|
},
|
|
173
178
|
isDisplayInnerSnapDigit: true,
|
|
174
|
-
|
|
179
|
+
dragTarget: '.moveable-drag-area-button',
|
|
180
|
+
dragTargetSelf: true,
|
|
175
181
|
props: {
|
|
176
182
|
actions: true,
|
|
177
183
|
},
|
package/src/StageCore.ts
CHANGED
|
@@ -18,13 +18,15 @@
|
|
|
18
18
|
|
|
19
19
|
import { EventEmitter } from 'events';
|
|
20
20
|
|
|
21
|
-
import {
|
|
21
|
+
import type { MoveableOptions, OnDragStart } from 'moveable';
|
|
22
|
+
|
|
23
|
+
import type { Id } from '@tmagic/schema';
|
|
22
24
|
|
|
23
25
|
import ActionManager from './ActionManager';
|
|
24
26
|
import { DEFAULT_ZOOM } from './const';
|
|
25
27
|
import StageMask from './StageMask';
|
|
26
28
|
import StageRender from './StageRender';
|
|
27
|
-
import {
|
|
29
|
+
import type {
|
|
28
30
|
ActionManagerConfig,
|
|
29
31
|
CustomizeRender,
|
|
30
32
|
GuidesEventData,
|
|
@@ -123,6 +125,10 @@ export default class StageCore extends EventEmitter {
|
|
|
123
125
|
this.actionManager.highlight(idOrEl);
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
public clearHighlight(): void {
|
|
129
|
+
this.actionManager.clearHighlight();
|
|
130
|
+
}
|
|
131
|
+
|
|
126
132
|
/**
|
|
127
133
|
* 更新组件
|
|
128
134
|
* @param data 更新组件的数据
|
|
@@ -207,6 +213,14 @@ export default class StageCore extends EventEmitter {
|
|
|
207
213
|
return this.actionManager.delayedMarkContainer(event, excludeElList);
|
|
208
214
|
}
|
|
209
215
|
|
|
216
|
+
public getMoveableOption<K extends keyof MoveableOptions>(key: K): MoveableOptions[K] | undefined {
|
|
217
|
+
return this.actionManager.getMoveableOption(key);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public getDragStatus() {
|
|
221
|
+
return this.actionManager.getDragStatus();
|
|
222
|
+
}
|
|
223
|
+
|
|
210
224
|
/**
|
|
211
225
|
* 销毁实例
|
|
212
226
|
*/
|
|
@@ -243,7 +257,6 @@ export default class StageCore extends EventEmitter {
|
|
|
243
257
|
containerHighlightDuration: config.containerHighlightDuration,
|
|
244
258
|
containerHighlightType: config.containerHighlightType,
|
|
245
259
|
moveableOptions: config.moveableOptions,
|
|
246
|
-
multiMoveableOptions: config.multiMoveableOptions,
|
|
247
260
|
container: this.mask.content,
|
|
248
261
|
disabledDragStart: config.disabledDragStart,
|
|
249
262
|
canSelect: config.canSelect,
|
|
@@ -283,6 +296,7 @@ export default class StageCore extends EventEmitter {
|
|
|
283
296
|
this.initDrEvent();
|
|
284
297
|
this.initMulDrEvent();
|
|
285
298
|
this.initHighlightEvent();
|
|
299
|
+
this.initMouseEvent();
|
|
286
300
|
}
|
|
287
301
|
|
|
288
302
|
/**
|
|
@@ -347,4 +361,20 @@ export default class StageCore extends EventEmitter {
|
|
|
347
361
|
this.emit('highlight', highlightEl);
|
|
348
362
|
});
|
|
349
363
|
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* 初始化Highlight类通过ActionManager抛出来的事件监听
|
|
367
|
+
*/
|
|
368
|
+
private initMouseEvent(): void {
|
|
369
|
+
this.actionManager
|
|
370
|
+
.on('mousemove', async (event: MouseEvent) => {
|
|
371
|
+
this.emit('mousemove', event);
|
|
372
|
+
})
|
|
373
|
+
.on('mouseleave', async (event: MouseEvent) => {
|
|
374
|
+
this.emit('mouseleave', event);
|
|
375
|
+
})
|
|
376
|
+
.on('drag-start', (e: OnDragStart) => {
|
|
377
|
+
this.emit('drag-start', e);
|
|
378
|
+
});
|
|
379
|
+
}
|
|
350
380
|
}
|
package/src/StageDragResize.ts
CHANGED
|
@@ -95,14 +95,18 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|
|
95
95
|
Object.entries(options).forEach(([key, value]) => {
|
|
96
96
|
(this.moveable as any)[key] = value;
|
|
97
97
|
});
|
|
98
|
-
this.moveable.
|
|
98
|
+
this.moveable.updateRect();
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
public clearSelectStatus(): void {
|
|
102
102
|
if (!this.moveable) return;
|
|
103
103
|
this.dragResizeHelper.destroyShadowEl();
|
|
104
104
|
this.moveable.target = null;
|
|
105
|
-
this.moveable.
|
|
105
|
+
this.moveable.updateRect();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public getDragStatus(): StageDragStatus {
|
|
109
|
+
return this.dragStatus;
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
/**
|
|
@@ -187,6 +191,7 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|
|
187
191
|
this.dragStatus = StageDragStatus.START;
|
|
188
192
|
|
|
189
193
|
this.dragResizeHelper.onDragStart(e);
|
|
194
|
+
this.emit('drag-start', e);
|
|
190
195
|
})
|
|
191
196
|
.on('drag', (e) => {
|
|
192
197
|
if (!this.target || !this.dragResizeHelper.getShadowEl()) return;
|
package/src/StageHighlight.ts
CHANGED
|
@@ -28,7 +28,7 @@ export default class StageHighlight extends EventEmitter {
|
|
|
28
28
|
public container: HTMLElement;
|
|
29
29
|
public target?: HTMLElement;
|
|
30
30
|
public moveable?: Moveable;
|
|
31
|
-
public targetShadow
|
|
31
|
+
public targetShadow?: TargetShadow;
|
|
32
32
|
private getRootContainer: GetRootContainer;
|
|
33
33
|
|
|
34
34
|
constructor(config: StageHighlightConfig) {
|
|
@@ -52,14 +52,19 @@ export default class StageHighlight extends EventEmitter {
|
|
|
52
52
|
public highlight(el: HTMLElement): void {
|
|
53
53
|
if (!el || el === this.target) return;
|
|
54
54
|
this.target = el;
|
|
55
|
-
this.moveable?.destroy();
|
|
56
55
|
|
|
57
|
-
this.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
this.targetShadow?.update(el);
|
|
57
|
+
if (this.moveable) {
|
|
58
|
+
this.moveable.zoom = 2;
|
|
59
|
+
this.moveable.updateRect();
|
|
60
|
+
} else {
|
|
61
|
+
this.moveable = new Moveable(this.container, {
|
|
62
|
+
target: this.targetShadow?.el,
|
|
63
|
+
origin: false,
|
|
64
|
+
rootContainer: this.getRootContainer(),
|
|
65
|
+
zoom: 2,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
/**
|
|
@@ -67,9 +72,9 @@ export default class StageHighlight extends EventEmitter {
|
|
|
67
72
|
*/
|
|
68
73
|
public clearHighlight(): void {
|
|
69
74
|
if (!this.moveable || !this.target) return;
|
|
75
|
+
this.moveable.zoom = 0;
|
|
76
|
+
this.moveable.updateRect();
|
|
70
77
|
this.target = undefined;
|
|
71
|
-
this.moveable.target = null;
|
|
72
|
-
this.moveable.updateTarget();
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
/**
|
|
@@ -77,6 +82,8 @@ export default class StageHighlight extends EventEmitter {
|
|
|
77
82
|
*/
|
|
78
83
|
public destroy(): void {
|
|
79
84
|
this.moveable?.destroy();
|
|
80
|
-
this.targetShadow
|
|
85
|
+
this.targetShadow?.destroy();
|
|
86
|
+
this.moveable = undefined;
|
|
87
|
+
this.targetShadow = undefined;
|
|
81
88
|
}
|
|
82
89
|
}
|
|
@@ -47,7 +47,7 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
47
47
|
constructor(config: StageMultiDragResizeConfig) {
|
|
48
48
|
const moveableOptionsManagerConfig: MoveableOptionsManagerConfig = {
|
|
49
49
|
container: config.container,
|
|
50
|
-
moveableOptions: config.
|
|
50
|
+
moveableOptions: config.moveableOptions,
|
|
51
51
|
getRootContainer: config.getRootContainer,
|
|
52
52
|
};
|
|
53
53
|
super(moveableOptionsManagerConfig);
|
|
@@ -173,7 +173,7 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
173
173
|
Object.entries(options).forEach(([key, value]) => {
|
|
174
174
|
(this.moveableForMulti as any)[key] = value;
|
|
175
175
|
});
|
|
176
|
-
this.moveableForMulti.
|
|
176
|
+
this.moveableForMulti.updateRect();
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
/**
|
package/src/index.ts
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import StageCore from './StageCore';
|
|
20
20
|
|
|
21
|
-
export type { MoveableOptions } from 'moveable';
|
|
21
|
+
export type { MoveableOptions, OnDragStart } from 'moveable';
|
|
22
22
|
export { default as StageRender } from './StageRender';
|
|
23
23
|
export { default as StageMask } from './StageMask';
|
|
24
24
|
export { default as StageDragResize } from './StageDragResize';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
.moveable-button {
|
|
2
|
+
width: 20px;
|
|
3
|
+
height: 20px;
|
|
4
|
+
background: #4af;
|
|
5
|
+
border-radius: 4px;
|
|
6
|
+
appearance: none;
|
|
7
|
+
border: 0;
|
|
8
|
+
color: white;
|
|
9
|
+
font-size: 12px;
|
|
10
|
+
font-weight: bold;
|
|
11
|
+
margin-left: 2px;
|
|
12
|
+
position: relative;
|
|
13
|
+
}
|
|
14
|
+
.moveable-remove-button:before, .moveable-remove-button:after {
|
|
15
|
+
content: "";
|
|
16
|
+
position: absolute;
|
|
17
|
+
left: 50%;
|
|
18
|
+
top: 50%;
|
|
19
|
+
transform: translate(-50%, -50%) rotate(45deg);
|
|
20
|
+
width: 14px;
|
|
21
|
+
height: 2px;
|
|
22
|
+
background: #fff;
|
|
23
|
+
border-radius: 1px;
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
}
|
|
26
|
+
.moveable-remove-button:after {
|
|
27
|
+
transform: translate(-50%, -50%) rotate(-45deg);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.moveable-select-parent-arrow-top-icon {
|
|
31
|
+
transform: rotateZ(-45deg);
|
|
32
|
+
width: 4px;
|
|
33
|
+
height: 4px;
|
|
34
|
+
border-color: #fff;
|
|
35
|
+
border-width: 2px 2px 0 0;
|
|
36
|
+
border-style: solid;
|
|
37
|
+
position: absolute;
|
|
38
|
+
left: 4px;
|
|
39
|
+
top: 4px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.moveable-select-parent-arrow-body-icon {
|
|
43
|
+
width: 7px;
|
|
44
|
+
height: 11px;
|
|
45
|
+
border-color: #fff;
|
|
46
|
+
border-width: 0 0 2px 2px;
|
|
47
|
+
border-style: solid;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.moveable-drag-area-button {
|
|
51
|
+
cursor: move;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.moveable-drag-area-button .moveable-select-parent-arrow-top-icon {
|
|
55
|
+
width: 2px;
|
|
56
|
+
height: 2px;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-top {
|
|
60
|
+
transform: rotateZ(-45deg) translateX(-50%);
|
|
61
|
+
left: 50%;
|
|
62
|
+
top: 3px;
|
|
63
|
+
transform-origin: left;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-bottom {
|
|
67
|
+
transform: rotateZ(135deg) translateX(-50%);
|
|
68
|
+
transform-origin: left;
|
|
69
|
+
left: 50%;
|
|
70
|
+
top: auto;
|
|
71
|
+
bottom: 3px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-right {
|
|
75
|
+
transform: rotateZ(45deg) translateY(-50%);
|
|
76
|
+
transform-origin: top;
|
|
77
|
+
right: 3px;
|
|
78
|
+
left: auto;
|
|
79
|
+
top: 50%;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.moveable-drag-area-button .moveable-select-parent-arrow-top-icon-left {
|
|
83
|
+
transform: rotateZ(235deg) translateY(-50%);
|
|
84
|
+
transform-origin: top;
|
|
85
|
+
left: 3px;
|
|
86
|
+
top: 50%;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.moveable-drag-area-button .moveable-select-parent-arrow-body-icon-horizontal {
|
|
90
|
+
width: 2px;
|
|
91
|
+
height: 11px;
|
|
92
|
+
background-color: #fff;
|
|
93
|
+
position: absolute;
|
|
94
|
+
transform: translateX(-50%);
|
|
95
|
+
left: 50%;
|
|
96
|
+
top: 4px;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.moveable-drag-area-button .moveable-select-parent-arrow-body-icon-vertical {
|
|
100
|
+
width: 11px;
|
|
101
|
+
height: 2px;
|
|
102
|
+
background-color: #fff;
|
|
103
|
+
position: absolute;
|
|
104
|
+
transform: translateY(-50%);
|
|
105
|
+
left: 4px;
|
|
106
|
+
top: 50%;;
|
|
107
|
+
}
|
|
108
|
+
|
package/src/types.ts
CHANGED
|
@@ -65,7 +65,6 @@ export interface StageCoreConfig {
|
|
|
65
65
|
containerHighlightDuration?: number;
|
|
66
66
|
containerHighlightType?: ContainerHighlightType;
|
|
67
67
|
moveableOptions?: CustomizeMoveableOptions;
|
|
68
|
-
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
69
68
|
/** runtime 的HTML地址,可以是一个HTTP地址,如果和编辑器不同域,需要设置跨域,也可以是一个相对或绝对路径 */
|
|
70
69
|
runtimeUrl?: string;
|
|
71
70
|
render?: (renderer: StageCore) => Promise<HTMLElement> | HTMLElement;
|
|
@@ -80,7 +79,6 @@ export interface ActionManagerConfig {
|
|
|
80
79
|
containerHighlightDuration?: number;
|
|
81
80
|
containerHighlightType?: ContainerHighlightType;
|
|
82
81
|
moveableOptions?: CustomizeMoveableOptions;
|
|
83
|
-
multiMoveableOptions?: CustomizeMoveableOptions;
|
|
84
82
|
disabledDragStart?: boolean;
|
|
85
83
|
canSelect?: CanSelect;
|
|
86
84
|
isContainer: IsContainer;
|
|
@@ -98,7 +96,11 @@ export interface MoveableOptionsManagerConfig {
|
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
export interface CustomizeMoveableOptionsCallbackConfig {
|
|
99
|
+
targetEl?: HTMLElement;
|
|
101
100
|
targetElId?: string;
|
|
101
|
+
targetEls?: HTMLElement[];
|
|
102
|
+
targetElIds?: string[];
|
|
103
|
+
isMulti: boolean;
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
export interface StageRenderConfig {
|
|
@@ -125,7 +127,7 @@ export interface StageDragResizeConfig {
|
|
|
125
127
|
export interface StageMultiDragResizeConfig {
|
|
126
128
|
container: HTMLElement;
|
|
127
129
|
dragResizeHelper: DragResizeHelper;
|
|
128
|
-
|
|
130
|
+
moveableOptions?: CustomizeMoveableOptions;
|
|
129
131
|
getRootContainer: GetRootContainer;
|
|
130
132
|
getRenderDocument: GetRenderDocument;
|
|
131
133
|
markContainerEnd: MarkContainerEnd;
|
package/types/ActionManager.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import EventEmitter from 'events';
|
|
4
|
-
import {
|
|
4
|
+
import type { MoveableOptions } from 'moveable';
|
|
5
|
+
import type { Id } from '@tmagic/schema';
|
|
5
6
|
import { GuidesType } from './const';
|
|
6
|
-
import { ActionManagerConfig, SelectStatus } from './types';
|
|
7
|
+
import { ActionManagerConfig, SelectStatus, StageDragStatus } from './types';
|
|
7
8
|
/**
|
|
8
9
|
* 管理蒙层mask之上的操作:1、监听键盘鼠标事件,判断形成单选、多选、高亮操作;2、管理单选、多选、高亮三个类协同工作。
|
|
9
10
|
* @extends EventEmitter
|
|
@@ -58,6 +59,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
58
59
|
setSelectedEl(el: HTMLElement): void;
|
|
59
60
|
getSelectedEl(): HTMLElement | undefined;
|
|
60
61
|
getSelectedElList(): HTMLElement[];
|
|
62
|
+
getMoveableOption<K extends keyof MoveableOptions>(key: K): MoveableOptions[K] | undefined;
|
|
61
63
|
/**
|
|
62
64
|
* 获取鼠标下方第一个可选中元素,如果元素层叠,返回到是最上层元素
|
|
63
65
|
* @param event 鼠标事件
|
|
@@ -101,6 +103,7 @@ export default class ActionManager extends EventEmitter {
|
|
|
101
103
|
* @returns timeoutId,调用方在鼠标移走时要取消该timeout,阻止标记
|
|
102
104
|
*/
|
|
103
105
|
delayedMarkContainer(event: MouseEvent, excludeElList?: Element[]): NodeJS.Timeout | undefined;
|
|
106
|
+
getDragStatus(): StageDragStatus;
|
|
104
107
|
destroy(): void;
|
|
105
108
|
private changeCallback;
|
|
106
109
|
/**
|