@tmagic/stage 1.2.6 → 1.2.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/dist/tmagic-stage.js +99 -50
- package/dist/tmagic-stage.js.map +1 -1
- package/dist/tmagic-stage.umd.cjs +99 -49
- package/dist/tmagic-stage.umd.cjs.map +1 -1
- package/package.json +4 -4
- package/src/ActionManager.ts +9 -0
- package/src/MoveableActionsAble.ts +109 -0
- package/src/MoveableOptionsManager.ts +6 -6
- package/src/StageCore.ts +4 -0
- package/src/StageDragResize.ts +4 -0
- package/src/types.ts +11 -0
- package/types/{MoveableSelectParentAble.d.ts → MoveableActionsAble.d.ts} +5 -2
- package/types/MoveableOptionsManager.d.ts +1 -1
- package/types/StageDragResize.d.ts +1 -0
- package/types/types.d.ts +9 -0
- package/src/MoveableSelectParentAble.ts +0 -76
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.2.
|
|
2
|
+
"version": "1.2.7",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@scena/guides": "^0.17.0",
|
|
33
|
-
"@tmagic/core": "1.2.
|
|
34
|
-
"@tmagic/schema": "1.2.
|
|
35
|
-
"@tmagic/utils": "1.2.
|
|
33
|
+
"@tmagic/core": "1.2.7",
|
|
34
|
+
"@tmagic/schema": "1.2.7",
|
|
35
|
+
"@tmagic/utils": "1.2.7",
|
|
36
36
|
"events": "^3.3.0",
|
|
37
37
|
"keycon": "^1.1.2",
|
|
38
38
|
"lodash-es": "^4.17.21",
|
package/src/ActionManager.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
GetTargetElement,
|
|
40
40
|
IsContainer,
|
|
41
41
|
Point,
|
|
42
|
+
RemoveEventData,
|
|
42
43
|
SelectStatus,
|
|
43
44
|
StageDragStatus,
|
|
44
45
|
UpdateEventData,
|
|
@@ -454,6 +455,14 @@ export default class ActionManager extends EventEmitter {
|
|
|
454
455
|
})
|
|
455
456
|
.on('select-parent', () => {
|
|
456
457
|
this.emit('select-parent');
|
|
458
|
+
})
|
|
459
|
+
.on('remove', () => {
|
|
460
|
+
const drTarget = this.dr.getTarget();
|
|
461
|
+
if (!drTarget) return;
|
|
462
|
+
const data: RemoveEventData = {
|
|
463
|
+
data: [{ el: drTarget }],
|
|
464
|
+
};
|
|
465
|
+
this.emit('remove', data);
|
|
457
466
|
});
|
|
458
467
|
|
|
459
468
|
this.multiDr
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { MoveableManagerInterface, Renderer } from 'moveable';
|
|
2
|
+
|
|
3
|
+
import { AbleActionEventType } from './types';
|
|
4
|
+
|
|
5
|
+
export default (handler: (type: AbleActionEventType) => void) => ({
|
|
6
|
+
name: 'actions',
|
|
7
|
+
props: {
|
|
8
|
+
selectParent: Boolean,
|
|
9
|
+
},
|
|
10
|
+
events: {},
|
|
11
|
+
render(moveable: MoveableManagerInterface<any, any>, React: Renderer) {
|
|
12
|
+
const rect = moveable.getRect();
|
|
13
|
+
const { pos2 } = moveable.state;
|
|
14
|
+
|
|
15
|
+
// use css for able
|
|
16
|
+
const editableViewer = moveable.useCSS(
|
|
17
|
+
'div',
|
|
18
|
+
`
|
|
19
|
+
{
|
|
20
|
+
position: absolute;
|
|
21
|
+
left: 0px;
|
|
22
|
+
top: 0px;
|
|
23
|
+
will-change: transform;
|
|
24
|
+
transform-origin: 0px 0px;
|
|
25
|
+
display: flex;
|
|
26
|
+
}
|
|
27
|
+
.moveable-button {
|
|
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
|
+
}
|
|
55
|
+
`,
|
|
56
|
+
);
|
|
57
|
+
// Add key (required)
|
|
58
|
+
// Add class prefix moveable-(required)
|
|
59
|
+
return React.createElement(
|
|
60
|
+
editableViewer,
|
|
61
|
+
{
|
|
62
|
+
className: 'moveable-editable',
|
|
63
|
+
style: {
|
|
64
|
+
transform: `translate(${pos2[0] - 48}px, ${pos2[1] - 28}px) rotate(${rect.rotation}deg) translate(10px)`,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
[
|
|
68
|
+
React.createElement(
|
|
69
|
+
'button',
|
|
70
|
+
{
|
|
71
|
+
className: 'moveable-button',
|
|
72
|
+
title: '选中父组件',
|
|
73
|
+
onClick: () => {
|
|
74
|
+
handler(AbleActionEventType.SELECT_PARENT);
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
React.createElement(
|
|
78
|
+
'svg',
|
|
79
|
+
{
|
|
80
|
+
width: '20px',
|
|
81
|
+
height: '20px',
|
|
82
|
+
viewBox: '0 0 16 16',
|
|
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
|
+
),
|
|
98
|
+
),
|
|
99
|
+
React.createElement('button', {
|
|
100
|
+
className: 'moveable-button moveable-remove-button',
|
|
101
|
+
title: '删除',
|
|
102
|
+
onClick: () => {
|
|
103
|
+
handler(AbleActionEventType.REMOVE);
|
|
104
|
+
},
|
|
105
|
+
}),
|
|
106
|
+
],
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
@@ -22,8 +22,8 @@ import { merge } from 'lodash-es';
|
|
|
22
22
|
import { MoveableOptions } from 'moveable';
|
|
23
23
|
|
|
24
24
|
import { GuidesType, Mode } from './const';
|
|
25
|
-
import
|
|
26
|
-
import { GetRootContainer, MoveableOptionsManagerConfig } from './types';
|
|
25
|
+
import MoveableActionsAble from './MoveableActionsAble';
|
|
26
|
+
import { AbleActionEventType, GetRootContainer, MoveableOptionsManagerConfig } from './types';
|
|
27
27
|
import { getOffset } from './util';
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -173,10 +173,10 @@ export default class MoveableOptionsManager extends EventEmitter {
|
|
|
173
173
|
isDisplayInnerSnapDigit: true,
|
|
174
174
|
|
|
175
175
|
props: {
|
|
176
|
-
|
|
176
|
+
actions: true,
|
|
177
177
|
},
|
|
178
178
|
|
|
179
|
-
ables: [
|
|
179
|
+
ables: [MoveableActionsAble(this.actionHandler.bind(this))],
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
182
|
|
|
@@ -208,8 +208,8 @@ export default class MoveableOptionsManager extends EventEmitter {
|
|
|
208
208
|
/**
|
|
209
209
|
* 这是给selectParentAbles的回调函数,用于触发选中父元素事件
|
|
210
210
|
*/
|
|
211
|
-
private
|
|
212
|
-
this.emit(
|
|
211
|
+
private actionHandler(type: AbleActionEventType): void {
|
|
212
|
+
this.emit(type);
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|
package/src/StageCore.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
GuidesEventData,
|
|
31
31
|
Point,
|
|
32
32
|
RemoveData,
|
|
33
|
+
RemoveEventData,
|
|
33
34
|
Runtime,
|
|
34
35
|
StageCoreConfig,
|
|
35
36
|
UpdateData,
|
|
@@ -313,6 +314,9 @@ export default class StageCore extends EventEmitter {
|
|
|
313
314
|
})
|
|
314
315
|
.on('select-parent', () => {
|
|
315
316
|
this.emit('select-parent');
|
|
317
|
+
})
|
|
318
|
+
.on('remove', (data: RemoveEventData) => {
|
|
319
|
+
this.emit('remove', data);
|
|
316
320
|
});
|
|
317
321
|
}
|
|
318
322
|
|
package/src/StageDragResize.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -190,6 +190,12 @@ export interface UpdateEventData {
|
|
|
190
190
|
parentEl: HTMLElement | null;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
+
export interface RemoveEventData {
|
|
194
|
+
data: {
|
|
195
|
+
el: HTMLElement;
|
|
196
|
+
}[];
|
|
197
|
+
}
|
|
198
|
+
|
|
193
199
|
export interface SortEventData {
|
|
194
200
|
src: Id;
|
|
195
201
|
dist: Id;
|
|
@@ -244,3 +250,8 @@ export interface TargetShadowConfig {
|
|
|
244
250
|
updateDragEl?: UpdateDragEl;
|
|
245
251
|
idPrefix?: string;
|
|
246
252
|
}
|
|
253
|
+
|
|
254
|
+
export enum AbleActionEventType {
|
|
255
|
+
SELECT_PARENT = 'select-parent',
|
|
256
|
+
REMOVE = 'remove',
|
|
257
|
+
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { MoveableManagerInterface, Renderer } from 'moveable';
|
|
2
|
-
|
|
2
|
+
import { AbleActionEventType } from './types';
|
|
3
|
+
declare const _default: (handler: (type: AbleActionEventType) => void) => {
|
|
3
4
|
name: string;
|
|
4
|
-
props: {
|
|
5
|
+
props: {
|
|
6
|
+
selectParent: BooleanConstructor;
|
|
7
|
+
};
|
|
5
8
|
events: {};
|
|
6
9
|
render(moveable: MoveableManagerInterface<any, any>, React: Renderer): any;
|
|
7
10
|
};
|
|
@@ -17,6 +17,7 @@ export default class StageDragResize extends MoveableOptionsManager {
|
|
|
17
17
|
private markContainerEnd;
|
|
18
18
|
private delayedMarkContainer;
|
|
19
19
|
constructor(config: StageDragResizeConfig);
|
|
20
|
+
getTarget(): HTMLElement | undefined;
|
|
20
21
|
/**
|
|
21
22
|
* 将选中框渲染并覆盖到选中的组件Dom节点上方
|
|
22
23
|
* 当选中的节点不是absolute时,会创建一个新的节点出来作为拖拽目标
|
package/types/types.d.ts
CHANGED
|
@@ -147,6 +147,11 @@ export interface UpdateEventData {
|
|
|
147
147
|
}[];
|
|
148
148
|
parentEl: HTMLElement | null;
|
|
149
149
|
}
|
|
150
|
+
export interface RemoveEventData {
|
|
151
|
+
data: {
|
|
152
|
+
el: HTMLElement;
|
|
153
|
+
}[];
|
|
154
|
+
}
|
|
150
155
|
export interface SortEventData {
|
|
151
156
|
src: Id;
|
|
152
157
|
dist: Id;
|
|
@@ -193,3 +198,7 @@ export interface TargetShadowConfig {
|
|
|
193
198
|
updateDragEl?: UpdateDragEl;
|
|
194
199
|
idPrefix?: string;
|
|
195
200
|
}
|
|
201
|
+
export declare enum AbleActionEventType {
|
|
202
|
+
SELECT_PARENT = "select-parent",
|
|
203
|
+
REMOVE = "remove"
|
|
204
|
+
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { MoveableManagerInterface, Renderer } from 'moveable';
|
|
2
|
-
|
|
3
|
-
export default (selectParentHandler: () => void) => ({
|
|
4
|
-
name: 'select-parent',
|
|
5
|
-
props: {},
|
|
6
|
-
events: {},
|
|
7
|
-
render(moveable: MoveableManagerInterface<any, any>, React: Renderer) {
|
|
8
|
-
const rect = moveable.getRect();
|
|
9
|
-
const { pos2 } = moveable.state;
|
|
10
|
-
|
|
11
|
-
// use css for able
|
|
12
|
-
const editableViewer = moveable.useCSS(
|
|
13
|
-
'div',
|
|
14
|
-
`
|
|
15
|
-
{
|
|
16
|
-
position: absolute;
|
|
17
|
-
left: 0px;
|
|
18
|
-
top: 0px;
|
|
19
|
-
will-change: transform;
|
|
20
|
-
transform-origin: 0px 0px;
|
|
21
|
-
display: flex;
|
|
22
|
-
}
|
|
23
|
-
.moveable-button {
|
|
24
|
-
width: 20px;
|
|
25
|
-
height: 20px;
|
|
26
|
-
background: #4af;
|
|
27
|
-
border-radius: 4px;
|
|
28
|
-
appearance: none;
|
|
29
|
-
border: 0;
|
|
30
|
-
color: white;
|
|
31
|
-
font-size: 12px;
|
|
32
|
-
font-weight: bold;
|
|
33
|
-
}
|
|
34
|
-
`,
|
|
35
|
-
);
|
|
36
|
-
// Add key (required)
|
|
37
|
-
// Add class prefix moveable-(required)
|
|
38
|
-
return React.createElement(
|
|
39
|
-
editableViewer,
|
|
40
|
-
{
|
|
41
|
-
className: 'moveable-editable',
|
|
42
|
-
style: {
|
|
43
|
-
transform: `translate(${pos2[0] - 25}px, ${pos2[1] - 30}px) rotate(${rect.rotation}deg) translate(10px)`,
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
React.createElement(
|
|
47
|
-
'button',
|
|
48
|
-
{
|
|
49
|
-
className: 'moveable-button',
|
|
50
|
-
title: '选中父组件',
|
|
51
|
-
onClick: () => {
|
|
52
|
-
selectParentHandler();
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
React.createElement(
|
|
56
|
-
'svg',
|
|
57
|
-
{
|
|
58
|
-
width: '1em',
|
|
59
|
-
height: '1em',
|
|
60
|
-
viewBox: '0 0 16 16',
|
|
61
|
-
fill: 'none',
|
|
62
|
-
xmlns: 'http://www.w3.org/2000/svg',
|
|
63
|
-
style: {
|
|
64
|
-
transform: 'rotate(90deg)',
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
React.createElement('path', {
|
|
68
|
-
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',
|
|
69
|
-
fill: 'currentColor',
|
|
70
|
-
fillOpacity: '0.9',
|
|
71
|
-
}),
|
|
72
|
-
),
|
|
73
|
-
),
|
|
74
|
-
);
|
|
75
|
-
},
|
|
76
|
-
});
|