@tmagic/stage 1.3.0 → 1.3.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 +35 -11
- package/dist/tmagic-stage.js.map +1 -1
- package/dist/tmagic-stage.umd.cjs +35 -10
- package/dist/tmagic-stage.umd.cjs.map +1 -1
- package/package.json +4 -4
- package/src/ActionManager.ts +4 -1
- package/src/DragResizeHelper.ts +20 -11
- package/src/util.ts +18 -0
- package/types/util.d.ts +4 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.1",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@scena/guides": "^0.29.2",
|
|
34
|
-
"@tmagic/core": "1.3.
|
|
35
|
-
"@tmagic/schema": "1.3.
|
|
36
|
-
"@tmagic/utils": "1.3.
|
|
34
|
+
"@tmagic/core": "1.3.1",
|
|
35
|
+
"@tmagic/schema": "1.3.1",
|
|
36
|
+
"@tmagic/utils": "1.3.1",
|
|
37
37
|
"events": "^3.3.0",
|
|
38
38
|
"keycon": "^1.4.0",
|
|
39
39
|
"lodash-es": "^4.17.21",
|
package/src/ActionManager.ts
CHANGED
|
@@ -83,6 +83,10 @@ export default class ActionManager extends EventEmitter {
|
|
|
83
83
|
private getRenderDocument: GetRenderDocument;
|
|
84
84
|
|
|
85
85
|
private mouseMoveHandler = throttle(async (event: MouseEvent): Promise<void> => {
|
|
86
|
+
if ((event.target as HTMLDivElement)?.classList?.contains('moveable-direction')) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
const el = await this.getElementFromPoint(event);
|
|
87
91
|
if (!el) {
|
|
88
92
|
this.clearHighlight();
|
|
@@ -90,7 +94,6 @@ export default class ActionManager extends EventEmitter {
|
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
this.emit('mousemove', event);
|
|
93
|
-
|
|
94
97
|
this.highlight(el);
|
|
95
98
|
}, throttleTime);
|
|
96
99
|
|
package/src/DragResizeHelper.ts
CHANGED
|
@@ -35,7 +35,7 @@ import MoveableHelper from 'moveable-helper';
|
|
|
35
35
|
import { DRAG_EL_ID_PREFIX, GHOST_EL_ID_PREFIX, Mode, ZIndex } from './const';
|
|
36
36
|
import TargetShadow from './TargetShadow';
|
|
37
37
|
import { DragResizeHelperConfig, Rect, TargetElement } from './types';
|
|
38
|
-
import { calcValueByFontsize, getAbsolutePosition, getOffset } from './util';
|
|
38
|
+
import { calcValueByFontsize, getAbsolutePosition, getMarginValue, getOffset } from './util';
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* 拖拽/改变大小等操作发生时,moveable会抛出各种状态事件,DragResizeHelper负责响应这些事件,对目标节点target和拖拽节点targetShadow进行修改;
|
|
@@ -126,8 +126,9 @@ export default class DragResizeHelper {
|
|
|
126
126
|
}
|
|
127
127
|
} else {
|
|
128
128
|
this.moveableHelper.onResize(e);
|
|
129
|
-
|
|
130
|
-
this.target.style.
|
|
129
|
+
const { marginLeft, marginTop } = getMarginValue(this.target);
|
|
130
|
+
this.target.style.left = `${this.frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
|
|
131
|
+
this.target.style.top = `${this.frameSnapShot.top + beforeTranslate[1] - marginTop} - marginToppx`;
|
|
131
132
|
}
|
|
132
133
|
|
|
133
134
|
this.target.style.width = `${width}px`;
|
|
@@ -154,8 +155,10 @@ export default class DragResizeHelper {
|
|
|
154
155
|
|
|
155
156
|
this.moveableHelper.onDrag(e);
|
|
156
157
|
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
const { marginLeft, marginTop } = getMarginValue(this.target);
|
|
159
|
+
|
|
160
|
+
this.target.style.left = `${this.frameSnapShot.left + e.beforeTranslate[0] - marginLeft}px`;
|
|
161
|
+
this.target.style.top = `${this.frameSnapShot.top + e.beforeTranslate[1] - marginTop}px`;
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
public onRotateStart(e: OnRotateStart): void {
|
|
@@ -241,8 +244,9 @@ export default class DragResizeHelper {
|
|
|
241
244
|
|
|
242
245
|
if (!isParentIncluded) {
|
|
243
246
|
// 更新页面元素位置
|
|
244
|
-
|
|
245
|
-
targeEl.style.
|
|
247
|
+
const { marginLeft, marginTop } = getMarginValue(targeEl);
|
|
248
|
+
targeEl.style.left = `${frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
|
|
249
|
+
targeEl.style.top = `${frameSnapShot.top + beforeTranslate[1] - marginTop}px`;
|
|
246
250
|
}
|
|
247
251
|
|
|
248
252
|
// 更新页面元素大小
|
|
@@ -275,8 +279,9 @@ export default class DragResizeHelper {
|
|
|
275
279
|
const isParentIncluded = this.targetList.find((targetItem) => targetItem.id === targeEl.parentElement?.id);
|
|
276
280
|
if (!isParentIncluded) {
|
|
277
281
|
// 更新页面元素位置
|
|
278
|
-
|
|
279
|
-
targeEl.style.
|
|
282
|
+
const { marginLeft, marginTop } = getMarginValue(targeEl);
|
|
283
|
+
targeEl.style.left = `${frameSnapShot.left + ev.beforeTranslate[0] - marginLeft}px`;
|
|
284
|
+
targeEl.style.top = `${frameSnapShot.top + ev.beforeTranslate[1] - marginTop}px`;
|
|
280
285
|
}
|
|
281
286
|
});
|
|
282
287
|
this.moveableHelper.onDragGroup(e);
|
|
@@ -285,8 +290,10 @@ export default class DragResizeHelper {
|
|
|
285
290
|
public getUpdatedElRect(el: HTMLElement, parentEl: HTMLElement | null, doc: Document): Rect {
|
|
286
291
|
const offset = this.mode === Mode.SORTABLE ? { left: 0, top: 0 } : { left: el.offsetLeft, top: el.offsetTop };
|
|
287
292
|
|
|
288
|
-
|
|
289
|
-
|
|
293
|
+
const { marginLeft, marginTop } = getMarginValue(el);
|
|
294
|
+
|
|
295
|
+
let left = calcValueByFontsize(doc, offset.left) - marginLeft;
|
|
296
|
+
let top = calcValueByFontsize(doc, offset.top) - marginTop;
|
|
290
297
|
const width = calcValueByFontsize(doc, el.clientWidth);
|
|
291
298
|
const height = calcValueByFontsize(doc, el.clientHeight);
|
|
292
299
|
|
|
@@ -358,6 +365,8 @@ export default class DragResizeHelper {
|
|
|
358
365
|
ghostEl.style.position = 'absolute';
|
|
359
366
|
ghostEl.style.left = `${left}px`;
|
|
360
367
|
ghostEl.style.top = `${top}px`;
|
|
368
|
+
ghostEl.style.marginLeft = '0';
|
|
369
|
+
ghostEl.style.marginTop = '0';
|
|
361
370
|
el.after(ghostEl);
|
|
362
371
|
return ghostEl;
|
|
363
372
|
}
|
package/src/util.ts
CHANGED
|
@@ -242,3 +242,21 @@ export const up = (deltaTop: number, target: TargetElement): SortEventData | voi
|
|
|
242
242
|
|
|
243
243
|
export const isMoveableButton = (target: Element) =>
|
|
244
244
|
target.classList.contains('moveable-button') || target.parentElement?.classList.contains('moveable-button');
|
|
245
|
+
|
|
246
|
+
export const getMarginValue = (el: Element) => {
|
|
247
|
+
if (!el)
|
|
248
|
+
return {
|
|
249
|
+
marginLeft: 0,
|
|
250
|
+
marginTop: 0,
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const { marginLeft, marginTop } = getComputedStyle(el);
|
|
254
|
+
|
|
255
|
+
const marginLeftValue = parseFloat(marginLeft) || 0;
|
|
256
|
+
const marginTopValue = parseFloat(marginTop) || 0;
|
|
257
|
+
|
|
258
|
+
return {
|
|
259
|
+
marginLeft: marginLeftValue,
|
|
260
|
+
marginTop: marginTopValue,
|
|
261
|
+
};
|
|
262
|
+
};
|
package/types/util.d.ts
CHANGED
|
@@ -31,3 +31,7 @@ export declare const down: (deltaTop: number, target: TargetElement) => SortEven
|
|
|
31
31
|
*/
|
|
32
32
|
export declare const up: (deltaTop: number, target: TargetElement) => SortEventData | void;
|
|
33
33
|
export declare const isMoveableButton: (target: Element) => boolean | undefined;
|
|
34
|
+
export declare const getMarginValue: (el: Element) => {
|
|
35
|
+
marginLeft: number;
|
|
36
|
+
marginTop: number;
|
|
37
|
+
};
|