Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec2b8c5

Browse files
feat: parent边界限制
1 parent a15fd6d commit ec2b8c5

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

‎src/views/common/drag/hooks/useMouse.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,32 @@ export default function useMouse(
3434
const isRight = /r/.test(point)
3535
const newHeight = itemAttrH + (isTop ? -currY : isBottom ? currY : 0)
3636
const newWidth = itemAttrW + (isLeft ? -currX : isRight ? currX : 0)
37-
let h = newHeight > 0 ? newHeight : 0
38-
let w = newWidth > 0 ? newWidth : 0
39-
let x = itemAttrX + (isLeft ? currX : 0)
40-
let y = itemAttrY + (isTop ? currY : 0)
41-
42-
// if (x > parentWidth - w) {
43-
// w = Math.abs(parentWidth - x)
44-
// x = parentWidth - w
45-
// }
46-
// if (x < 0) {
47-
// w = w - Math.abs(x)
48-
// x = 0
49-
// }
50-
// if (y > parentHeight - h) {
51-
// h = Math.abs(parentHeight - y)
52-
// y = parentHeight - h
53-
// }
54-
// if (y < 0) {
55-
// h = h - Math.abs(y)
56-
// y = 0
57-
// }
58-
37+
let h = Math.abs(newHeight)
38+
let w = Math.abs(newWidth)
39+
let x =
40+
newWidth > 0
41+
? itemAttrX + (isLeft ? currX : 0)
42+
: itemAttrX + (isLeft ? itemAttrW : newWidth)
43+
let y =
44+
newHeight > 0
45+
? itemAttrY + (isTop ? currY : 0)
46+
: itemAttrY + (isTop ? itemAttrH : newHeight)
47+
if (parent) {
48+
if (x < 0) {
49+
w = w + x
50+
x = 0
51+
}
52+
if (y < 0) {
53+
h = h + y
54+
y = 0
55+
}
56+
if (x + w > parentWidth) {
57+
w = parentWidth - x
58+
}
59+
if (y + h > parentHeight) {
60+
h = parentHeight - y
61+
}
62+
}
5963
setAttrs({ x, y, w, h })
6064
})
6165
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /