Skip to content

Commit

Permalink
fix: fix snapGrid's offset #897
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Apr 20, 2023
1 parent e3f4067 commit 97d89de
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions packages/react-moveable/src/ables/snappable/getTotalGuidelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,6 @@ export function getTotalGuidelines(
moveable, targetRect, snapThreshold,
));
}
totalGuidelines.push(...getGridGuidelines(
snapGridWidth,
snapGridHeight,
overflow ? containerWidth! : containerClientWidth!,
overflow ? containerHeight! : containerClientHeight!,
clientLeft,
clientTop,
));
const snapOffset = {
...(state.snapOffset || {
left: 0,
Expand All @@ -66,6 +58,16 @@ export function getTotalGuidelines(
}),
};

totalGuidelines.push(...getGridGuidelines(
snapGridWidth,
snapGridHeight,
overflow ? containerWidth! : containerClientWidth!,
overflow ? containerHeight! : containerClientHeight!,
clientLeft,
clientTop,
snapOffset,
));


if (hasFixed) {
const { left, top } = containerClientRect;
Expand Down Expand Up @@ -245,14 +247,21 @@ export function getGridGuidelines(
containerHeight: number,
clientLeft = 0,
clientTop = 0,
snapOffset: { left: number, top: number, right: number, bottom: number },
): SnapGuideline[] {
const guidelines: SnapGuideline[] = [];

const {
left: snapOffsetLeft,
top: snapOffsetTop,
} = snapOffset;
if (snapGridHeight) {
for (let pos = 0; pos <= containerHeight; pos += snapGridHeight) {
guidelines.push({
type: "horizontal",
pos: [0, throttle(pos - clientTop, 0.1)],
pos: [
snapOffsetLeft,
throttle(pos - clientTop + snapOffsetTop, 0.1),
],
size: containerWidth!,
hide: true,
});
Expand All @@ -262,7 +271,10 @@ export function getGridGuidelines(
for (let pos = 0; pos <= containerWidth; pos += snapGridWidth) {
guidelines.push({
type: "vertical",
pos: [throttle(pos - clientLeft, 0.1), 0],
pos: [
throttle(pos - clientLeft + snapOffsetLeft, 0.1),
snapOffsetTop,
],
size: containerHeight!,
hide: true,
});
Expand Down

0 comments on commit 97d89de

Please sign in to comment.