@tmagic/stage 1.3.8 → 1.3.10
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 +31 -12
- package/dist/tmagic-stage.js.map +1 -1
- package/dist/tmagic-stage.umd.cjs +31 -11
- package/dist/tmagic-stage.umd.cjs.map +1 -1
- package/package.json +4 -4
- package/src/ActionManager.ts +2 -2
- package/src/DragResizeHelper.ts +11 -6
- package/src/StageCore.ts +2 -2
- package/src/StageMultiDragResize.ts +1 -1
- package/src/util.ts +21 -1
- package/types/util.d.ts +6 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.10",
|
|
3
3
|
"name": "@tmagic/stage",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@scena/guides": "^0.29.2",
|
|
29
|
-
"@tmagic/core": "1.3.
|
|
30
|
-
"@tmagic/schema": "1.3.
|
|
31
|
-
"@tmagic/utils": "1.3.
|
|
29
|
+
"@tmagic/core": "1.3.10",
|
|
30
|
+
"@tmagic/schema": "1.3.10",
|
|
31
|
+
"@tmagic/utils": "1.3.10",
|
|
32
32
|
"events": "^3.3.0",
|
|
33
33
|
"keycon": "^1.4.0",
|
|
34
34
|
"lodash-es": "^4.17.21",
|
package/src/ActionManager.ts
CHANGED
|
@@ -429,11 +429,11 @@ export default class ActionManager extends EventEmitter {
|
|
|
429
429
|
?.on('update', (data: UpdateEventData) => {
|
|
430
430
|
this.emit('multi-update', data);
|
|
431
431
|
})
|
|
432
|
-
.on('change-to-select', async (id: Id) => {
|
|
432
|
+
.on('change-to-select', async (id: Id, e: MouseEvent) => {
|
|
433
433
|
// 如果还在多选状态,不触发切换到单选
|
|
434
434
|
if (this.isMultiSelectStatus) return false;
|
|
435
435
|
const el = this.getTargetElement(id);
|
|
436
|
-
this.emit('change-to-select', el);
|
|
436
|
+
this.emit('change-to-select', el, e);
|
|
437
437
|
});
|
|
438
438
|
|
|
439
439
|
return multiDr;
|
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, getMarginValue, getOffset } from './util';
|
|
38
|
+
import { calcValueByFontsize, getAbsolutePosition, getBorderWidth, getMarginValue, getOffset } from './util';
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* 拖拽/改变大小等操作发生时,moveable会抛出各种状态事件,DragResizeHelper负责响应这些事件,对目标节点target和拖拽节点targetShadow进行修改;
|
|
@@ -128,11 +128,13 @@ export default class DragResizeHelper {
|
|
|
128
128
|
this.moveableHelper.onResize(e);
|
|
129
129
|
const { marginLeft, marginTop } = getMarginValue(this.target);
|
|
130
130
|
this.target.style.left = `${this.frameSnapShot.left + beforeTranslate[0] - marginLeft}px`;
|
|
131
|
-
this.target.style.top = `${this.frameSnapShot.top + beforeTranslate[1] - marginTop}
|
|
131
|
+
this.target.style.top = `${this.frameSnapShot.top + beforeTranslate[1] - marginTop}px`;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
this.target
|
|
135
|
-
|
|
134
|
+
const { borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth } = getBorderWidth(this.target);
|
|
135
|
+
|
|
136
|
+
this.target.style.width = `${width + borderLeftWidth + borderRightWidth}px`;
|
|
137
|
+
this.target.style.height = `${height + borderTopWidth + borderBottomWidth}px`;
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
public onDragStart(e: OnDragStart): void {
|
|
@@ -294,8 +296,11 @@ export default class DragResizeHelper {
|
|
|
294
296
|
|
|
295
297
|
let left = calcValueByFontsize(doc, offset.left) - marginLeft;
|
|
296
298
|
let top = calcValueByFontsize(doc, offset.top) - marginTop;
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
+
|
|
300
|
+
const { borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth } = getBorderWidth(el);
|
|
301
|
+
|
|
302
|
+
const width = calcValueByFontsize(doc, el.clientWidth + borderLeftWidth + borderRightWidth);
|
|
303
|
+
const height = calcValueByFontsize(doc, el.clientHeight + borderTopWidth + borderBottomWidth);
|
|
299
304
|
|
|
300
305
|
let shadowEl = this.getShadowEl();
|
|
301
306
|
const shadowEls = this.getShadowEls();
|
package/src/StageCore.ts
CHANGED
|
@@ -357,10 +357,10 @@ export default class StageCore extends EventEmitter {
|
|
|
357
357
|
private initMulDrEvent(): void {
|
|
358
358
|
this.actionManager
|
|
359
359
|
// 多选切换到单选
|
|
360
|
-
.on('change-to-select', (el: HTMLElement) => {
|
|
360
|
+
.on('change-to-select', (el: HTMLElement, e: MouseEvent) => {
|
|
361
361
|
this.select(el);
|
|
362
362
|
// 先保证画布内完成渲染,再通知外部更新
|
|
363
|
-
setTimeout(() => this.emit('select', el));
|
|
363
|
+
setTimeout(() => this.emit('select', el, e));
|
|
364
364
|
})
|
|
365
365
|
.on('multi-update', (data: UpdateEventData) => {
|
|
366
366
|
this.emit('update', data);
|
|
@@ -128,7 +128,7 @@ export default class StageMultiDragResize extends MoveableOptionsManager {
|
|
|
128
128
|
const { inputTarget, targets } = e;
|
|
129
129
|
// 如果有多个元素被选中,同时点击的元素在选中元素中的其中一项,可能是多选态切换为该元素的单选态,抛事件给上一层继续判断是否切换
|
|
130
130
|
if (targets.length > 1 && targets.includes(inputTarget)) {
|
|
131
|
-
this.emit('change-to-select', inputTarget.id.replace(DRAG_EL_ID_PREFIX, ''));
|
|
131
|
+
this.emit('change-to-select', inputTarget.id.replace(DRAG_EL_ID_PREFIX, ''), e.inputEvent);
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
}
|
package/src/util.ts
CHANGED
|
@@ -57,7 +57,7 @@ export const getOffset = (el: Element): Offset => {
|
|
|
57
57
|
// 将蒙层占位节点覆盖在原节点上方
|
|
58
58
|
export const getTargetElStyle = (el: TargetElement, zIndex?: ZIndex) => {
|
|
59
59
|
const offset = getOffset(el);
|
|
60
|
-
const { transform } = getComputedStyle(el);
|
|
60
|
+
const { transform, border } = getComputedStyle(el);
|
|
61
61
|
return `
|
|
62
62
|
position: absolute;
|
|
63
63
|
transform: ${transform};
|
|
@@ -65,6 +65,7 @@ export const getTargetElStyle = (el: TargetElement, zIndex?: ZIndex) => {
|
|
|
65
65
|
top: ${offset.top}px;
|
|
66
66
|
width: ${el.clientWidth}px;
|
|
67
67
|
height: ${el.clientHeight}px;
|
|
68
|
+
border: ${border};
|
|
68
69
|
${typeof zIndex !== 'undefined' ? `z-index: ${zIndex};` : ''}
|
|
69
70
|
`;
|
|
70
71
|
};
|
|
@@ -260,3 +261,22 @@ export const getMarginValue = (el: Element) => {
|
|
|
260
261
|
marginTop: marginTopValue,
|
|
261
262
|
};
|
|
262
263
|
};
|
|
264
|
+
|
|
265
|
+
export const getBorderWidth = (el: Element) => {
|
|
266
|
+
if (!el)
|
|
267
|
+
return {
|
|
268
|
+
borderLeftWidth: 0,
|
|
269
|
+
borderRightWidth: 0,
|
|
270
|
+
borderTopWidth: 0,
|
|
271
|
+
borderBottomWidth: 0,
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const { borderLeftWidth, borderRightWidth, borderTopWidth, borderBottomWidth } = getComputedStyle(el);
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
borderLeftWidth: parseFloat(borderLeftWidth) || 0,
|
|
278
|
+
borderRightWidth: parseFloat(borderRightWidth) || 0,
|
|
279
|
+
borderTopWidth: parseFloat(borderTopWidth) || 0,
|
|
280
|
+
borderBottomWidth: parseFloat(borderBottomWidth) || 0,
|
|
281
|
+
};
|
|
282
|
+
};
|
package/types/util.d.ts
CHANGED
|
@@ -35,3 +35,9 @@ export declare const getMarginValue: (el: Element) => {
|
|
|
35
35
|
marginLeft: number;
|
|
36
36
|
marginTop: number;
|
|
37
37
|
};
|
|
38
|
+
export declare const getBorderWidth: (el: Element) => {
|
|
39
|
+
borderLeftWidth: number;
|
|
40
|
+
borderRightWidth: number;
|
|
41
|
+
borderTopWidth: number;
|
|
42
|
+
borderBottomWidth: number;
|
|
43
|
+
};
|