Skip to content

Commit 91651b2

Browse files
authoredApr 28, 2022
Fix config types (#487)
* chore: removes patch package * types: fix config types not being inferred
1 parent e07cbf2 commit 91651b2

21 files changed

+60
-99
lines changed
 

‎.changeset/pretty-turtles-walk.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@use-gesture/react': patch
3+
'@use-gesture/vanilla': patch
4+
'@use-gesture/core': patch
5+
---
6+
7+
Fix config types

‎demo/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"version": "1.0.0",
44
"private": true,
55
"scripts": {
6-
"postinstall": "patch-package",
76
"dev": "vite --port 4000 --host",
87
"build": "vite build",
98
"serve": "vite preview"

‎demo/src/sandboxes/gesture-simplest/src/App.tsx

+7-10
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@ import styles from './styles.module.css'
66

77
export default function App() {
88
const [style, api] = useSpring(() => ({ x: 0, y: 0, scale: 1 }))
9-
const bind = useDrag(
10-
({ active, offset: [x, y] }) => {
11-
api.start({
12-
x: active ? x : 0,
13-
y: active ? y : 0,
14-
scale: active ? 1.2 : 1
15-
})
16-
},
17-
{ bounds: { left: -30 } }
18-
)
9+
const bind = useDrag(({ active, offset: [x, y] }) => {
10+
api.start({
11+
x: active ? x : 0,
12+
y: active ? y : 0,
13+
scale: active ? 1.2 : 1
14+
})
15+
})
1916

2017
return (
2118
<div className="flex fill center">

‎package.json

-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
"eslint-plugin-testing-library": "^5.3.1",
100100
"husky": "^7.0.4",
101101
"jest": "^27.5.1",
102-
"patch-package": "^6.4.7",
103102
"pnpm": "^6.32.6",
104103
"postinstall-postinstall": "^2.1.0",
105104
"prettier": "^2.6.2",

‎packages/react/src/createUseGesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export function createUseGesture(actions: Action[]) {
88

99
return function useGesture<Config extends UserGestureConfig = UserGestureConfig>(
1010
_handlers: GestureHandlers,
11-
_config: Config | {} = {}
11+
_config?: Config
1212
) {
13-
const { handlers, nativeHandlers, config } = parseMergedHandlers(_handlers, _config)
13+
const { handlers, nativeHandlers, config } = parseMergedHandlers(_handlers, _config || {})
1414
return useRecognizers<Config>(handlers, config, undefined, nativeHandlers)
1515
}
1616
}

‎packages/react/src/useDrag.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { useRecognizers } from './useRecognizers'
66
* Drag hook.
77
*
88
* @param {Handler<'drag'>} handler - the function fired every time the drag gesture updates
9-
* @param {UserDragConfig} [config={}] - the config object including generic options and drag options
9+
* @param {UserDragConfig} config - the config object including generic options and drag options
1010
*/
1111
export function useDrag<EventType = EventTypes['drag'], Config extends UserDragConfig = UserDragConfig>(
1212
handler: Handler<'drag', EventType>,
13-
config: Config | {} = {}
13+
config?: Config
1414
) {
1515
registerAction(dragAction)
16-
return useRecognizers({ drag: handler }, config, 'drag')
16+
return useRecognizers({ drag: handler }, config || {}, 'drag')
1717
}

‎packages/react/src/useGesture.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import { createUseGesture } from './createUseGesture'
88
* The most complete gesture hook, allowing support for multiple gestures.
99
*
1010
* @param {GestureHandlers} handlers - an object with on[Gesture] keys containg gesture handlers
11-
* @param {UseGestureConfig} [config={}] - the full config object
11+
* @param {UseGestureConfig} config - the full config object
1212
*/
1313
export function useGesture<
1414
HandlerTypes extends AnyHandlerEventTypes = EventTypes,
1515
Config extends UserGestureConfig = UserGestureConfig
16-
>(handlers: GestureHandlers<HandlerTypes>, config: Config | {} = {}) {
16+
>(handlers: GestureHandlers<HandlerTypes>, config?: Config) {
1717
const hook = createUseGesture([dragAction, pinchAction, scrollAction, wheelAction, moveAction, hoverAction])
18-
return hook(handlers, config)
18+
return hook(handlers, config || ({} as Config))
1919
}

‎packages/react/src/useHover.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { useRecognizers } from './useRecognizers'
66
* Hover hook.
77
*
88
* @param {Handler<'hover'>} handler - the function fired every time the hover gesture updates
9-
* @param {UserHoverConfig} [config={}] - the config object including generic options and hover options
9+
* @param {UserHoverConfig} config - the config object including generic options and hover options
1010
*/
1111
export function useHover<EventType = EventTypes['hover'], Config extends UserHoverConfig = UserHoverConfig>(
1212
handler: Handler<'hover', EventType>,
13-
config: Config | {} = {}
13+
config?: Config
1414
) {
1515
registerAction(hoverAction)
16-
return useRecognizers({ hover: handler }, config, 'hover')
16+
return useRecognizers({ hover: handler }, config || {}, 'hover')
1717
}

‎packages/react/src/useMove.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { useRecognizers } from './useRecognizers'
66
* Move hook.
77
*
88
* @param {Handler<'move'>} handler - the function fired every time the move gesture updates
9-
* @param {UserMoveConfig} [config={}] - the config object including generic options and move options
9+
* @param {UserMoveConfig} config - the config object including generic options and move options
1010
*/
1111
export function useMove<EventType = EventTypes['move'], Config extends UserMoveConfig = UserMoveConfig>(
1212
handler: Handler<'move', EventType>,
13-
config: Config | {} = {}
13+
config?: Config
1414
) {
1515
registerAction(moveAction)
16-
return useRecognizers({ move: handler }, config, 'move')
16+
return useRecognizers({ move: handler }, config || {}, 'move')
1717
}

‎packages/react/src/usePinch.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { useRecognizers } from './useRecognizers'
66
* Pinch hook.
77
*
88
* @param {Handler<'pinch'>} handler - the function fired every time the pinch gesture updates
9-
* @param {UserPinchConfig} [config={}] - the config object including generic options and pinch options
9+
* @param {UserPinchConfig} config - the config object including generic options and pinch options
1010
*/
1111
export function usePinch<EventType = EventTypes['pinch'], Config extends UserPinchConfig = UserPinchConfig>(
1212
handler: Handler<'pinch', EventType>,
13-
config: Config | {} = {}
13+
config?: Config
1414
) {
1515
registerAction(pinchAction)
16-
return useRecognizers({ pinch: handler }, config, 'pinch')
16+
return useRecognizers({ pinch: handler }, config || {}, 'pinch')
1717
}

‎packages/react/src/useScroll.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { useRecognizers } from './useRecognizers'
66
* Scroll hook.
77
*
88
* @param {Handler<'scroll'>} handler - the function fired every time the scroll gesture updates
9-
* @param {UserScrollConfig} [config={}] - the config object including generic options and scroll options
9+
* @param {UserScrollConfig} config - the config object including generic options and scroll options
1010
*/
1111
export function useScroll<EventType = EventTypes['scroll'], Config extends UserScrollConfig = UserScrollConfig>(
1212
handler: Handler<'scroll', EventType>,
13-
config: Config | {} = {}
13+
config?: Config
1414
) {
1515
registerAction(scrollAction)
16-
return useRecognizers({ scroll: handler }, config, 'scroll')
16+
return useRecognizers({ scroll: handler }, config || {}, 'scroll')
1717
}

‎packages/react/src/useWheel.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { useRecognizers } from './useRecognizers'
66
* Wheel hook.
77
*
88
* @param {Handler<'wheel'>} handler - the function fired every time the wheel gesture updates
9-
* @param {UserWheelConfig} [config={}] - the config object including generic options and wheel options
9+
* @param {UserWheelConfig} config - the config object including generic options and wheel options
1010
*/
1111
export function useWheel<EventType = EventTypes['wheel'], Config extends UserWheelConfig = UserWheelConfig>(
1212
handler: Handler<'wheel', EventType>,
13-
config: Config | {} = {}
13+
config?: Config
1414
) {
1515
registerAction(wheelAction)
16-
return useRecognizers({ wheel: handler }, config, 'wheel')
16+
return useRecognizers({ wheel: handler }, config || {}, 'wheel')
1717
}

‎packages/vanilla/src/DragGesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export interface DragGesture extends Recognizer {}
1515
export const DragGesture: DragGestureConstructor = function <EventType = EventTypes['drag']>(
1616
target: EventTarget,
1717
handler: Handler<'drag', EventType>,
18-
config: UserDragConfig | {} = {}
18+
config?: UserDragConfig
1919
) {
2020
registerAction(dragAction)
21-
return new Recognizer(target, { drag: handler }, config, 'drag')
21+
return new Recognizer(target, { drag: handler }, config || {}, 'drag')
2222
} as any

‎packages/vanilla/src/Gesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export interface Gesture extends Recognizer {}
1616
export const Gesture: GestureConstructor = function <HandlerTypes extends AnyHandlerEventTypes = EventTypes>(
1717
target: EventTarget,
1818
handlers: GestureHandlers<HandlerTypes>,
19-
config: UserGestureConfig | {} = {}
19+
config?: UserGestureConfig
2020
) {
2121
const gestureFunction = createGesture([dragAction, pinchAction, scrollAction, wheelAction, moveAction, hoverAction])
22-
return gestureFunction(target, handlers, config)
22+
return gestureFunction(target, handlers, config || ({} as UserGestureConfig))
2323
} as any

‎packages/vanilla/src/HoverGesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export interface HoverGesture extends Recognizer {}
1515
export const HoverGesture: HoverGestureConstructor = function <EventType = EventTypes['hover']>(
1616
target: EventTarget,
1717
handler: Handler<'hover', EventType>,
18-
config: UserHoverConfig | {} = {}
18+
config?: UserHoverConfig
1919
) {
2020
registerAction(hoverAction)
21-
return new Recognizer(target, { hover: handler }, config, 'hover')
21+
return new Recognizer(target, { hover: handler }, config || {}, 'hover')
2222
} as any

‎packages/vanilla/src/MoveGesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export interface MoveGesture extends Recognizer {}
1515
export const MoveGesture: MoveGestureConstructor = function <EventType = EventTypes['move']>(
1616
target: EventTarget,
1717
handler: Handler<'move', EventType>,
18-
config: UserMoveConfig | {} = {}
18+
config?: UserMoveConfig
1919
) {
2020
registerAction(moveAction)
21-
return new Recognizer(target, { move: handler }, config, 'move')
21+
return new Recognizer(target, { move: handler }, config || {}, 'move')
2222
} as any

‎packages/vanilla/src/PinchGesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export interface PinchGesture extends Recognizer {}
1515
export const PinchGesture: PinchGestureConstructor = function <EventType = EventTypes['pinch']>(
1616
target: EventTarget,
1717
handler: Handler<'pinch', EventType>,
18-
config: UserPinchConfig | {} = {}
18+
config?: UserPinchConfig
1919
) {
2020
registerAction(pinchAction)
21-
return new Recognizer(target, { pinch: handler }, config, 'pinch')
21+
return new Recognizer(target, { pinch: handler }, config || {}, 'pinch')
2222
} as any

‎packages/vanilla/src/ScrollGesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export interface ScrollGesture extends Recognizer {}
1515
export const ScrollGesture: ScrollGestureConstructor = function <EventType = EventTypes['scroll']>(
1616
target: EventTarget,
1717
handler: Handler<'scroll', EventType>,
18-
config: UserScrollConfig | {} = {}
18+
config?: UserScrollConfig
1919
) {
2020
registerAction(scrollAction)
21-
return new Recognizer(target, { scroll: handler }, config, 'scroll')
21+
return new Recognizer(target, { scroll: handler }, config || {}, 'scroll')
2222
} as any

‎packages/vanilla/src/WheelGesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export interface WheelGesture extends Recognizer {}
1515
export const WheelGesture: WheelGestureConstructor = function <EventType = EventTypes['wheel']>(
1616
target: EventTarget,
1717
handler: Handler<'wheel', EventType>,
18-
config: UserWheelConfig | {} = {}
18+
config?: UserWheelConfig
1919
) {
2020
registerAction(wheelAction)
21-
return new Recognizer(target, { wheel: handler }, config, 'wheel')
21+
return new Recognizer(target, { wheel: handler }, config || {}, 'wheel')
2222
} as any

‎packages/vanilla/src/createGesture.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { Recognizer } from './Recognizer'
66
export function createGesture(actions: Action[]) {
77
actions.forEach(registerAction)
88

9-
return function (target: EventTarget, _handlers: GestureHandlers, _config: UserGestureConfig | {} = {}) {
10-
const { handlers, nativeHandlers, config } = parseMergedHandlers(_handlers, _config)
9+
return function (target: EventTarget, _handlers: GestureHandlers, _config?: UserGestureConfig) {
10+
const { handlers, nativeHandlers, config } = parseMergedHandlers(_handlers, _config || {})
1111
return new Recognizer(target, handlers, config, undefined, nativeHandlers)
1212
}
1313
}

‎pnpm-lock.yaml

+7-48
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.