Skip to content

Commit e45b92a

Browse files
committed
fix: fix tangent's tiny x value #806
1 parent ec8e162 commit e45b92a

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

packages/react-moveable/src/ables/Snappable.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export function recheckSizeByTwoDirection(
202202
horizontal: [snapPos[1]],
203203
});
204204

205-
if (verticalOffset || horizontalOffset) {
205+
if (throttle(verticalOffset, FLOAT_POINT_NUM) || throttle(horizontalOffset, FLOAT_POINT_NUM)) {
206206
const [nextWidthOffset, nextHeightOffset] = getDragDist({
207207
datas,
208208
distX: -verticalOffset,
@@ -256,6 +256,7 @@ export function checkSizeDist(
256256
let nextWidthOffset = widthOffsetInfo.offset;
257257
let nextHeightOffset = heightOffsetInfo.offset;
258258

259+
259260
if (i === 1) {
260261
if (!isWidthBound) {
261262
nextWidthOffset = 0;
@@ -309,6 +310,7 @@ export function checkSizeDist(
309310
isRequest,
310311
datas
311312
);
313+
312314
widthOffset += nextWidthOffset;
313315
heightOffset += nextHeightOffset;
314316
}

packages/react-moveable/stories/99-Tests/Deafult.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,11 @@ group.add("Test css zoomed target", {
9696
app: require("./ReactZoomedTargetApp").default,
9797
path: require.resolve("./ReactZoomedTargetApp"),
9898
});
99+
100+
101+
102+
103+
group.add("Test snap for scaled target", {
104+
app: require("./ReactZoomedSnapApp").default,
105+
path: require.resolve("./ReactZoomedSnapApp"),
106+
});
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import * as React from "react";
2+
import Moveable from "@/react-moveable";
3+
import { useEffect, useState } from "react";
4+
5+
export default function App() {
6+
const [elementGuidelines, setElementGuideliens] = useState<HTMLElement[]>([]);
7+
8+
useEffect(() => {
9+
setElementGuideliens([].slice.call(document.querySelectorAll(".moveable")));
10+
}, []);
11+
return (
12+
<div className="root">
13+
<div className="container" style={{
14+
width: "1000px",
15+
height: "1600px",
16+
transform: "scale(0.47845)",
17+
transformOrigin: "top left",
18+
background: "#faa",
19+
}}>
20+
<div className="target box-1" style={{
21+
top: 0,
22+
left: 0,
23+
}}>Target</div>
24+
<div className="target moveable box-2" style={{
25+
"width": "600px",
26+
"height": "50px",
27+
"top": "1400px",
28+
"left": "150px",
29+
}}>
30+
<p>Moveable 2</p>
31+
</div>
32+
<div className="target moveable box-3" style={{
33+
"width": "250px",
34+
"height": "50px",
35+
"top": "1300px",
36+
"left": "350px",
37+
}}>
38+
<p>Moveable 3</p>
39+
</div>
40+
<div className="target moveable box-4" style={{
41+
"width": "250px",
42+
"height": "50px",
43+
"top": "1200px",
44+
"left": "200px",
45+
}}>
46+
<p>Moveable 4</p>
47+
</div>
48+
<div className="target moveable box-5" style={{
49+
"width": "250px",
50+
"height": "50px",
51+
"top": "1200px",
52+
"left": "500px",
53+
}}>
54+
<p>Moveable 5</p>
55+
</div>
56+
</div>
57+
<Moveable
58+
target={".box-1"}
59+
draggable={true}
60+
resizable={true}
61+
snappable={true}
62+
zoom={1}
63+
elementGuidelines={elementGuidelines}
64+
bounds={{
65+
top: 0,
66+
left: 0,
67+
right: 500,
68+
bottom: 800,
69+
}}
70+
onRender={e => {
71+
e.target.style.cssText += e.cssText;
72+
}}
73+
/>
74+
</div>
75+
);
76+
}

0 commit comments

Comments
 (0)