Initial project import
This commit is contained in:
16
node_modules/@use-gesture/react/src/createUseGesture.ts
generated
vendored
Normal file
16
node_modules/@use-gesture/react/src/createUseGesture.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { parseMergedHandlers } from '@use-gesture/core'
|
||||
import { registerAction } from '@use-gesture/core/actions'
|
||||
import { Action, GestureHandlers, UserGestureConfig } from '@use-gesture/core/types'
|
||||
import { useRecognizers } from './useRecognizers'
|
||||
|
||||
export function createUseGesture(actions: Action[]) {
|
||||
actions.forEach(registerAction)
|
||||
|
||||
return function useGesture<Config extends UserGestureConfig = UserGestureConfig>(
|
||||
_handlers: GestureHandlers,
|
||||
_config?: Config
|
||||
) {
|
||||
const { handlers, nativeHandlers, config } = parseMergedHandlers(_handlers, _config || {})
|
||||
return useRecognizers<Config>(handlers, config, undefined, nativeHandlers)
|
||||
}
|
||||
}
|
||||
12
node_modules/@use-gesture/react/src/index.ts
generated
vendored
Normal file
12
node_modules/@use-gesture/react/src/index.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
export { useDrag } from './useDrag'
|
||||
export { usePinch } from './usePinch'
|
||||
export { useWheel } from './useWheel'
|
||||
export { useScroll } from './useScroll'
|
||||
export { useMove } from './useMove'
|
||||
export { useHover } from './useHover'
|
||||
export { useGesture } from './useGesture'
|
||||
export { createUseGesture } from './createUseGesture'
|
||||
|
||||
export * from '@use-gesture/core/utils'
|
||||
export * from '@use-gesture/core/actions'
|
||||
export * from '@use-gesture/core/types'
|
||||
36
node_modules/@use-gesture/react/src/types.test.ts
generated
vendored
Normal file
36
node_modules/@use-gesture/react/src/types.test.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/* eslint-disable react-hooks/rules-of-hooks */
|
||||
/* Type tests for @use-gesture/react */
|
||||
|
||||
import { useRef } from 'react'
|
||||
import { expectType } from 'tsd'
|
||||
import { useDrag, useGesture } from '.'
|
||||
import { ReactDOMAttributes } from './types'
|
||||
|
||||
/* Checks that gesture hooks return event props handlers */
|
||||
expectType<(...args: any[]) => ReactDOMAttributes>(useDrag(() => {}))
|
||||
|
||||
/* Checks that gesture hooks don't return any value when used with config option `target` */
|
||||
expectType<void>(useDrag(() => {}, { target: window }))
|
||||
|
||||
/* Checks that hooks accept generics to cast event type */
|
||||
useDrag<MouseEvent>(({ event }) => expectType<MouseEvent>(event))
|
||||
|
||||
const fakeDiv = 'fake' as any as HTMLDivElement
|
||||
const fakeRef = useRef<HTMLDivElement>(null)
|
||||
/* Checks config.bounds type for useDrag */
|
||||
useDrag(() => {}, { bounds: { left: 0 } })
|
||||
useDrag(() => {}, { bounds: fakeDiv })
|
||||
useDrag(() => {}, { bounds: fakeRef })
|
||||
|
||||
/* Checks that useGesture returns event props handler */
|
||||
expectType<(...args: any[]) => ReactDOMAttributes>(useGesture({ onPinch: () => {} }))
|
||||
|
||||
/* Checks that useGesture doesn't return any value when used with config option `target` */
|
||||
expectType<void>(useGesture({ onPinch: () => {} }, { target: window }))
|
||||
|
||||
/* Checks that useGesture accepts generics to cast event type */
|
||||
useGesture<{ drag: MouseEvent; pinch: WheelEvent; onClick: PointerEvent }>({
|
||||
onDrag: ({ event }) => expectType<MouseEvent>(event),
|
||||
onPinch: ({ event }) => expectType<WheelEvent>(event),
|
||||
onClick: ({ event }) => expectType<PointerEvent>(event)
|
||||
})
|
||||
5
node_modules/@use-gesture/react/src/types.ts
generated
vendored
Normal file
5
node_modules/@use-gesture/react/src/types.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { DOMHandlers } from '@use-gesture/core/types'
|
||||
|
||||
export type ReactDOMAttributes = {
|
||||
[Key in keyof DOMHandlers]: React.DOMAttributes<EventTarget>[Key]
|
||||
}
|
||||
17
node_modules/@use-gesture/react/src/useDrag.ts
generated
vendored
Normal file
17
node_modules/@use-gesture/react/src/useDrag.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { registerAction, dragAction } from '@use-gesture/core/actions'
|
||||
import { EventTypes, Handler, UserDragConfig } from '@use-gesture/core/types'
|
||||
import { useRecognizers } from './useRecognizers'
|
||||
|
||||
/**
|
||||
* Drag hook.
|
||||
*
|
||||
* @param {Handler<'drag'>} handler - the function fired every time the drag gesture updates
|
||||
* @param {UserDragConfig} config - the config object including generic options and drag options
|
||||
*/
|
||||
export function useDrag<EventType = EventTypes['drag'], Config extends UserDragConfig = UserDragConfig>(
|
||||
handler: Handler<'drag', EventType>,
|
||||
config?: Config
|
||||
) {
|
||||
registerAction(dragAction)
|
||||
return useRecognizers({ drag: handler }, config || {}, 'drag')
|
||||
}
|
||||
19
node_modules/@use-gesture/react/src/useGesture.ts
generated
vendored
Normal file
19
node_modules/@use-gesture/react/src/useGesture.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { dragAction, pinchAction, scrollAction, wheelAction, moveAction, hoverAction } from '@use-gesture/core/actions'
|
||||
import { GestureHandlers, UserGestureConfig, EventTypes, AnyHandlerEventTypes } from '@use-gesture/core/types'
|
||||
import { createUseGesture } from './createUseGesture'
|
||||
|
||||
/**
|
||||
* @public
|
||||
*
|
||||
* The most complete gesture hook, allowing support for multiple gestures.
|
||||
*
|
||||
* @param {GestureHandlers} handlers - an object with on[Gesture] keys containg gesture handlers
|
||||
* @param {UserGestureConfig} config - the full config object
|
||||
*/
|
||||
export function useGesture<
|
||||
HandlerTypes extends AnyHandlerEventTypes = EventTypes,
|
||||
Config extends UserGestureConfig = UserGestureConfig
|
||||
>(handlers: GestureHandlers<HandlerTypes>, config?: Config) {
|
||||
const hook = createUseGesture([dragAction, pinchAction, scrollAction, wheelAction, moveAction, hoverAction])
|
||||
return hook(handlers, config || ({} as Config))
|
||||
}
|
||||
17
node_modules/@use-gesture/react/src/useHover.ts
generated
vendored
Normal file
17
node_modules/@use-gesture/react/src/useHover.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { registerAction, hoverAction } from '@use-gesture/core/actions'
|
||||
import { EventTypes, UserHoverConfig, Handler } from '@use-gesture/core/types'
|
||||
import { useRecognizers } from './useRecognizers'
|
||||
|
||||
/**
|
||||
* Hover hook.
|
||||
*
|
||||
* @param {Handler<'hover'>} handler - the function fired every time the hover gesture updates
|
||||
* @param {UserHoverConfig} config - the config object including generic options and hover options
|
||||
*/
|
||||
export function useHover<EventType = EventTypes['hover'], Config extends UserHoverConfig = UserHoverConfig>(
|
||||
handler: Handler<'hover', EventType>,
|
||||
config?: Config
|
||||
) {
|
||||
registerAction(hoverAction)
|
||||
return useRecognizers({ hover: handler }, config || {}, 'hover')
|
||||
}
|
||||
17
node_modules/@use-gesture/react/src/useMove.ts
generated
vendored
Normal file
17
node_modules/@use-gesture/react/src/useMove.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { registerAction, moveAction } from '@use-gesture/core/actions'
|
||||
import { UserMoveConfig, Handler, EventTypes } from '@use-gesture/core/types'
|
||||
import { useRecognizers } from './useRecognizers'
|
||||
|
||||
/**
|
||||
* Move hook.
|
||||
*
|
||||
* @param {Handler<'move'>} handler - the function fired every time the move gesture updates
|
||||
* @param {UserMoveConfig} config - the config object including generic options and move options
|
||||
*/
|
||||
export function useMove<EventType = EventTypes['move'], Config extends UserMoveConfig = UserMoveConfig>(
|
||||
handler: Handler<'move', EventType>,
|
||||
config?: Config
|
||||
) {
|
||||
registerAction(moveAction)
|
||||
return useRecognizers({ move: handler }, config || {}, 'move')
|
||||
}
|
||||
17
node_modules/@use-gesture/react/src/usePinch.ts
generated
vendored
Normal file
17
node_modules/@use-gesture/react/src/usePinch.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { registerAction, pinchAction } from '@use-gesture/core/actions'
|
||||
import { UserPinchConfig, Handler, EventTypes } from '@use-gesture/core/types'
|
||||
import { useRecognizers } from './useRecognizers'
|
||||
|
||||
/**
|
||||
* Pinch hook.
|
||||
*
|
||||
* @param {Handler<'pinch'>} handler - the function fired every time the pinch gesture updates
|
||||
* @param {UserPinchConfig} config - the config object including generic options and pinch options
|
||||
*/
|
||||
export function usePinch<EventType = EventTypes['pinch'], Config extends UserPinchConfig = UserPinchConfig>(
|
||||
handler: Handler<'pinch', EventType>,
|
||||
config?: Config
|
||||
) {
|
||||
registerAction(pinchAction)
|
||||
return useRecognizers({ pinch: handler }, config || {}, 'pinch')
|
||||
}
|
||||
44
node_modules/@use-gesture/react/src/useRecognizers.ts
generated
vendored
Normal file
44
node_modules/@use-gesture/react/src/useRecognizers.ts
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import React from 'react'
|
||||
import { Controller } from '@use-gesture/core'
|
||||
import { GenericOptions, GestureKey, InternalHandlers, NativeHandlers } from '@use-gesture/core/types'
|
||||
import { ReactDOMAttributes } from './types'
|
||||
|
||||
type HookReturnType<Config extends GenericOptions> = Config['target'] extends object
|
||||
? void
|
||||
: (...args: any[]) => ReactDOMAttributes
|
||||
|
||||
/**
|
||||
* Utility hook called by all gesture hooks and that will be responsible for
|
||||
* the internals.
|
||||
*
|
||||
* @param {InternalHandlers} handlers
|
||||
* @param {GenericOptions} config
|
||||
* @param {GestureKey} gestureKey
|
||||
* @param {NativeHandler} nativeHandlers
|
||||
* @returns nothing when config.target is set, a binding function when not.
|
||||
*/
|
||||
export function useRecognizers<Config extends GenericOptions>(
|
||||
handlers: InternalHandlers,
|
||||
config: Config | {} = {},
|
||||
gestureKey?: GestureKey,
|
||||
nativeHandlers?: NativeHandlers
|
||||
): HookReturnType<Config> {
|
||||
const ctrl = React.useMemo(() => new Controller(handlers), [])
|
||||
ctrl.applyHandlers(handlers, nativeHandlers)
|
||||
ctrl.applyConfig(config, gestureKey)
|
||||
|
||||
React.useEffect(ctrl.effect.bind(ctrl))
|
||||
|
||||
React.useEffect(() => {
|
||||
return ctrl.clean.bind(ctrl)
|
||||
}, [])
|
||||
|
||||
// When target is undefined we return the bind function of the controller which
|
||||
// returns prop handlers.
|
||||
// @ts-ignore
|
||||
if (config.target === undefined) {
|
||||
return ctrl.bind.bind(ctrl) as any
|
||||
}
|
||||
return undefined as any
|
||||
}
|
||||
17
node_modules/@use-gesture/react/src/useScroll.ts
generated
vendored
Normal file
17
node_modules/@use-gesture/react/src/useScroll.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { registerAction, scrollAction } from '@use-gesture/core/actions'
|
||||
import { UserScrollConfig, Handler, EventTypes } from '@use-gesture/core/types'
|
||||
import { useRecognizers } from './useRecognizers'
|
||||
|
||||
/**
|
||||
* Scroll hook.
|
||||
*
|
||||
* @param {Handler<'scroll'>} handler - the function fired every time the scroll gesture updates
|
||||
* @param {UserScrollConfig} config - the config object including generic options and scroll options
|
||||
*/
|
||||
export function useScroll<EventType = EventTypes['scroll'], Config extends UserScrollConfig = UserScrollConfig>(
|
||||
handler: Handler<'scroll', EventType>,
|
||||
config?: Config
|
||||
) {
|
||||
registerAction(scrollAction)
|
||||
return useRecognizers({ scroll: handler }, config || {}, 'scroll')
|
||||
}
|
||||
17
node_modules/@use-gesture/react/src/useWheel.ts
generated
vendored
Normal file
17
node_modules/@use-gesture/react/src/useWheel.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { registerAction, wheelAction } from '@use-gesture/core/actions'
|
||||
import { UserWheelConfig, Handler, EventTypes } from '@use-gesture/core/types'
|
||||
import { useRecognizers } from './useRecognizers'
|
||||
|
||||
/**
|
||||
* Wheel hook.
|
||||
*
|
||||
* @param {Handler<'wheel'>} handler - the function fired every time the wheel gesture updates
|
||||
* @param {UserWheelConfig} config - the config object including generic options and wheel options
|
||||
*/
|
||||
export function useWheel<EventType = EventTypes['wheel'], Config extends UserWheelConfig = UserWheelConfig>(
|
||||
handler: Handler<'wheel', EventType>,
|
||||
config?: Config
|
||||
) {
|
||||
registerAction(wheelAction)
|
||||
return useRecognizers({ wheel: handler }, config || {}, 'wheel')
|
||||
}
|
||||
Reference in New Issue
Block a user