Skip to content

Commit

Permalink
Updating formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgperry committed Nov 29, 2023
1 parent b568ed4 commit 72f6eed
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { mix } from "../../utils/mix"
import { percent } from "../../value/types/numbers/units"
import { animateMotionValue } from "../../animation/interfaces/motion-value"
import { frame } from "../../frameloop"
import { getContextWindow } from "../../utils/getContextWindow";
import { getContextWindow } from "../../utils/get-context-window"

export const elementDragControls = new WeakMap<
VisualElement,
Expand Down Expand Up @@ -215,7 +215,10 @@ export class VisualElementDragControls {
onMove,
onSessionEnd,
},
{ transformPagePoint: this.visualElement.getTransformPagePoint() , contextWindow: getContextWindow(this.visualElement) }
{
transformPagePoint: this.visualElement.getTransformPagePoint(),
contextWindow: getContextWindow(this.visualElement),
}
)
}

Expand Down
26 changes: 19 additions & 7 deletions packages/framer-motion/src/gestures/pan/PanSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ interface PanSessionHandlers {
}

interface PanSessionOptions {
transformPagePoint?: TransformPoint,
contextWindow?: (Window & typeof globalThis) | null;
transformPagePoint?: TransformPoint
contextWindow?: (Window & typeof globalThis) | null
}

interface TimestampedPoint extends Point {
Expand Down Expand Up @@ -147,7 +147,7 @@ export class PanSession {
/**
* @internal
*/
private contextWindow: PanSessionOptions['contextWindow'] = window;
private contextWindow: PanSessionOptions["contextWindow"] = window

constructor(
event: PointerEvent,
Expand All @@ -159,7 +159,7 @@ export class PanSession {

this.handlers = handlers
this.transformPagePoint = transformPagePoint
this.contextWindow = contextWindow || window;
this.contextWindow = contextWindow || window

const info = extractEventInfo(event)
const initialInfo = transformPoint(info, this.transformPagePoint)
Expand All @@ -174,9 +174,21 @@ export class PanSession {
onSessionStart(event, getPanInfo(initialInfo, this.history))

this.removeListeners = pipe(
addPointerEvent(this.contextWindow, "pointermove", this.handlePointerMove),
addPointerEvent(this.contextWindow, "pointerup", this.handlePointerUp),
addPointerEvent(this.contextWindow, "pointercancel", this.handlePointerUp)
addPointerEvent(
this.contextWindow,
"pointermove",
this.handlePointerMove
),
addPointerEvent(
this.contextWindow,
"pointerup",
this.handlePointerUp
),
addPointerEvent(
this.contextWindow,
"pointercancel",
this.handlePointerUp
)
)
}

Expand Down
7 changes: 5 additions & 2 deletions packages/framer-motion/src/gestures/pan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { addPointerEvent } from "../../events/add-pointer-event"
import { Feature } from "../../motion/features/Feature"
import { noop } from "../../utils/noop"
import { frame } from "../../frameloop"
import { getContextWindow } from "../../utils/getContextWindow";
import { getContextWindow } from "../../utils/get-context-window"

type PanEventHandler = (event: PointerEvent, info: PanInfo) => void
const asyncHandler =
Expand All @@ -22,7 +22,10 @@ export class PanGesture extends Feature<Element> {
this.session = new PanSession(
pointerDownEvent,
this.createPanHandlers(),
{ transformPagePoint: this.node.getTransformPagePoint(), contextWindow: getContextWindow(this.node) }
{
transformPagePoint: this.node.getTransformPagePoint(),
contextWindow: getContextWindow(this.node),
}
)
}

Expand Down
5 changes: 5 additions & 0 deletions packages/framer-motion/src/utils/get-context-window.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { VisualElement } from "../render/VisualElement"

export const getContextWindow = ({ current }: VisualElement<Element>) => {
return current ? current.ownerDocument.defaultView : null
}
8 changes: 0 additions & 8 deletions packages/framer-motion/src/utils/getContextWindow.ts

This file was deleted.

0 comments on commit 72f6eed

Please sign in to comment.