@tmagic/stage 1.1.0-beta.9 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tmagic-stage.mjs +41 -7
- package/dist/tmagic-stage.mjs.map +1 -1
- package/dist/tmagic-stage.umd.js +41 -7
- package/dist/tmagic-stage.umd.js.map +1 -1
- package/package.json +4 -4
- package/src/StageDragResize.ts +5 -3
- package/src/StageMultiDragResize.ts +57 -13
- package/src/style.css +4 -0
- package/src/types.ts +2 -0
- package/types/types.d.ts +2 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.1.
|
|
2
|
+
"version": "1.1.2",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"dist/*"
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@scena/guides": "^0.17.0",
|
|
32
|
-
"@tmagic/core": "1.1.
|
|
33
|
-
"@tmagic/schema": "1.1.
|
|
34
|
-
"@tmagic/utils": "1.1.
|
|
32
|
+
"@tmagic/core": "1.1.2",
|
|
33
|
+
"@tmagic/schema": "1.1.2",
|
|
34
|
+
"@tmagic/utils": "1.1.2",
|
|
35
35
|
"events": "^3.3.0",
|
|
36
36
|
"keycon": "^1.1.2",
|
|
37
37
|
"lodash-es": "^4.17.21",
|
package/src/StageDragResize.ts
CHANGED
|
@@ -263,12 +263,13 @@ export default class StageDragResize extends EventEmitter {
|
|
|
263
263
|
const { beforeTranslate } = drag;
|
|
264
264
|
this.dragStatus = StageDragStatus.ING;
|
|
265
265
|
|
|
266
|
-
this.moveableHelper?.onResize(e);
|
|
267
|
-
|
|
268
266
|
// 流式布局
|
|
269
267
|
if (this.mode === Mode.SORTABLE) {
|
|
270
268
|
this.target.style.top = '0px';
|
|
269
|
+
this.dragEl.style.width = `${width}px`;
|
|
270
|
+
this.dragEl.style.height = `${height}px`;
|
|
271
271
|
} else {
|
|
272
|
+
this.moveableHelper?.onResize(e);
|
|
272
273
|
this.target.style.left = `${frame.left + beforeTranslate[0]}px`;
|
|
273
274
|
this.target.style.top = `${frame.top + beforeTranslate[1]}px`;
|
|
274
275
|
}
|
|
@@ -518,6 +519,7 @@ export default class StageDragResize extends EventEmitter {
|
|
|
518
519
|
|
|
519
520
|
const isAbsolute = this.mode === Mode.ABSOLUTE;
|
|
520
521
|
const isFixed = this.mode === Mode.FIXED;
|
|
522
|
+
const isSortable = this.mode === Mode.SORTABLE;
|
|
521
523
|
|
|
522
524
|
let { moveableOptions = {} } = this.core.config;
|
|
523
525
|
|
|
@@ -572,7 +574,7 @@ export default class StageDragResize extends EventEmitter {
|
|
|
572
574
|
// 设置0的话无法移动到left为0,所以只能设置为-1
|
|
573
575
|
left: -1,
|
|
574
576
|
right: this.container.clientWidth - 1,
|
|
575
|
-
bottom: this.container.clientHeight,
|
|
577
|
+
bottom: isSortable ? undefined : this.container.clientHeight,
|
|
576
578
|
...(moveableOptions.bounds || {}),
|
|
577
579
|
},
|
|
578
580
|
...options,
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
|
|
19
19
|
import { EventEmitter } from 'events';
|
|
20
20
|
|
|
21
|
-
import type { MoveableOptions } from 'moveable';
|
|
21
|
+
import type { MoveableOptions, OnDragStart, OnResizeStart } from 'moveable';
|
|
22
22
|
import Moveable from 'moveable';
|
|
23
23
|
import MoveableHelper from 'moveable-helper';
|
|
24
24
|
|
|
@@ -85,23 +85,67 @@ export default class StageMultiDragResize extends EventEmitter {
|
|
|
85
85
|
createAuto: true,
|
|
86
86
|
});
|
|
87
87
|
const frames: { left: number; top: number; id: string }[] = [];
|
|
88
|
+
|
|
89
|
+
const setFrames = (events: OnDragStart[] | OnResizeStart[]) => {
|
|
90
|
+
// 记录拖动前快照
|
|
91
|
+
events.forEach((ev) => {
|
|
92
|
+
// 实际目标元素
|
|
93
|
+
const matchEventTarget = this.targetList.find(
|
|
94
|
+
(targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
|
|
95
|
+
);
|
|
96
|
+
if (!matchEventTarget) return;
|
|
97
|
+
frames.push({
|
|
98
|
+
left: matchEventTarget.offsetLeft,
|
|
99
|
+
top: matchEventTarget.offsetTop,
|
|
100
|
+
id: matchEventTarget.id,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
|
|
88
105
|
this.moveableForMulti
|
|
89
|
-
.on('
|
|
106
|
+
.on('resizeGroupStart', (params) => {
|
|
90
107
|
const { events } = params;
|
|
91
|
-
this.multiMoveableHelper?.
|
|
92
|
-
|
|
108
|
+
this.multiMoveableHelper?.onResizeGroupStart(params);
|
|
109
|
+
setFrames(events);
|
|
110
|
+
this.dragStatus = StageDragStatus.START;
|
|
111
|
+
})
|
|
112
|
+
.on('resizeGroup', (params) => {
|
|
113
|
+
const { events } = params;
|
|
114
|
+
// 拖动过程更新
|
|
93
115
|
events.forEach((ev) => {
|
|
94
|
-
|
|
95
|
-
const
|
|
116
|
+
const { width, height, beforeTranslate } = ev.drag;
|
|
117
|
+
const frameSnapShot = frames.find(
|
|
118
|
+
(frameItem) => frameItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
|
|
119
|
+
);
|
|
120
|
+
if (!frameSnapShot) return;
|
|
121
|
+
const targeEl = this.targetList.find(
|
|
96
122
|
(targetItem) => targetItem.id === ev.target.id.replace(DRAG_EL_ID_PREFIX, ''),
|
|
97
123
|
);
|
|
98
|
-
if (!
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
124
|
+
if (!targeEl) return;
|
|
125
|
+
// 元素与其所属组同时加入多选列表时,只更新父元素
|
|
126
|
+
const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
|
|
127
|
+
if (!isParentIncluded) {
|
|
128
|
+
// 更新页面元素位置
|
|
129
|
+
targeEl.style.left = `${frameSnapShot.left + beforeTranslate[0]}px`;
|
|
130
|
+
targeEl.style.top = `${frameSnapShot.top + beforeTranslate[1]}px`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 更新页面元素位置
|
|
134
|
+
targeEl.style.width = `${width}px`;
|
|
135
|
+
targeEl.style.height = `${height}px`;
|
|
104
136
|
});
|
|
137
|
+
this.multiMoveableHelper?.onResizeGroup(params);
|
|
138
|
+
this.dragStatus = StageDragStatus.ING;
|
|
139
|
+
})
|
|
140
|
+
.on('resizeGroupEnd', () => {
|
|
141
|
+
this.update(true);
|
|
142
|
+
this.dragStatus = StageDragStatus.END;
|
|
143
|
+
})
|
|
144
|
+
.on('dragGroupStart', (params) => {
|
|
145
|
+
const { events } = params;
|
|
146
|
+
this.multiMoveableHelper?.onDragGroupStart(params);
|
|
147
|
+
// 记录拖动前快照
|
|
148
|
+
setFrames(events);
|
|
105
149
|
this.dragStatus = StageDragStatus.START;
|
|
106
150
|
})
|
|
107
151
|
.on('dragGroup', (params) => {
|
|
@@ -237,7 +281,7 @@ export default class StageMultiDragResize extends EventEmitter {
|
|
|
237
281
|
defaultGroupRotate: 0,
|
|
238
282
|
defaultGroupOrigin: '50% 50%',
|
|
239
283
|
draggable: true,
|
|
240
|
-
resizable:
|
|
284
|
+
resizable: true,
|
|
241
285
|
throttleDrag: 0,
|
|
242
286
|
startDragRotate: 0,
|
|
243
287
|
throttleDragRotate: 0,
|
package/src/style.css
CHANGED
package/src/types.ts
CHANGED
|
@@ -119,11 +119,13 @@ export interface SortEventData {
|
|
|
119
119
|
export interface UpdateData {
|
|
120
120
|
config: MNode;
|
|
121
121
|
parent?: MContainer;
|
|
122
|
+
parentId?: Id;
|
|
122
123
|
root: MApp;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
export interface RemoveData {
|
|
126
127
|
id: Id;
|
|
128
|
+
parentId: Id;
|
|
127
129
|
root: MApp;
|
|
128
130
|
}
|
|
129
131
|
|
package/types/types.d.ts
CHANGED
|
@@ -86,10 +86,12 @@ export interface SortEventData {
|
|
|
86
86
|
export interface UpdateData {
|
|
87
87
|
config: MNode;
|
|
88
88
|
parent?: MContainer;
|
|
89
|
+
parentId?: Id;
|
|
89
90
|
root: MApp;
|
|
90
91
|
}
|
|
91
92
|
export interface RemoveData {
|
|
92
93
|
id: Id;
|
|
94
|
+
parentId: Id;
|
|
93
95
|
root: MApp;
|
|
94
96
|
}
|
|
95
97
|
export interface Runtime {
|