Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Vue and Svelte target #512

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
05f61e1
feat: add Svelte target
wobsoriano Jun 29, 2022
aaa1c85
chore: update deps
dbismut Jul 2, 2022
fbfc5e1
chore: fix versions
dbismut Jul 2, 2022
b20de9d
ci: changeset
dbismut Jul 2, 2022
cae986d
demo: add svelte demo
dbismut Jul 2, 2022
e7f20a7
feat: add vue target
wobsoriano Aug 5, 2022
32c18c4
demo: add vue
dbismut Aug 28, 2022
e059b1f
chore: toast update
dbismut Aug 28, 2022
19946d0
ts: swap NonNullable<State[Key]>['event'] with UIEvent
dbismut Aug 28, 2022
cd776f8
Update package.json
dbismut Aug 28, 2022
e63651d
fix: rollback ts to 4.7.4 inside lock file
dbismut Aug 28, 2022
562bc51
ts: enable strictNullChecks
dbismut Aug 28, 2022
1893719
chore: remove vue from package dev dependency and put it in workspace
dbismut Aug 28, 2022
c92d259
Merge branch 'main' into pr/wobsoriano/512
dbismut Aug 28, 2022
0f97c17
ts: trying stuff to fix types
dbismut Aug 28, 2022
cb3f1a8
fix: versions for new package
dbismut Aug 28, 2022
dd7d7c5
Merge branch 'main' into pr/512
dbismut Aug 30, 2022
159c0d8
fix: various fixes to update from main
dbismut Aug 30, 2022
a3a8e1e
chore: merge `import from '../types'` statements
dbismut Sep 9, 2022
2f5cab4
feat: add normalizeProp function which defaults to React style props …
dbismut Sep 9, 2022
22255d2
feat: remove the need for normalizing props in Vue package
dbismut Sep 9, 2022
a5bc721
fix: add support for customizing native props
dbismut Sep 12, 2022
fe412cd
Merge branch 'main' into pr/512
dbismut Feb 21, 2023
5d022fa
chore: update deps
dbismut Feb 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: remove the need for normalizing props in Vue package
dbismut committed Sep 9, 2022
commit 22255d24a519b3df5373a282670a0cbd1c0c9601
4 changes: 2 additions & 2 deletions demo/src/sandboxes/gesture-vue/src/VueApp.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useSpring } from 'vue-use-spring'
import { normalizeProps, useDrag } from '@use-gesture/vue'
import { useDrag } from '@use-gesture/vue'
const position = useSpring({ x: 0, y: 0 })
@@ -13,7 +13,7 @@ const bind = useDrag(({ down, movement: [mx, my] }) => {
<template>
<div
className="drag"
v-bind="normalizeProps(bind())"
v-on="bind()"
:style="{
touchAction: 'none',
transform: `translate(${position.x}px, ${position.y}px)`
2 changes: 0 additions & 2 deletions packages/vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export { normalizeProps } from './useRecognizers'

export { useDrag } from './useDrag'
export { usePinch } from './usePinch'
export { useWheel } from './useWheel'
39 changes: 11 additions & 28 deletions packages/vue/src/useRecognizers.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
import { Controller } from '@use-gesture/core'
import type { DOMHandlers, GenericOptions, GestureKey, InternalHandlers, NativeHandlers } from '@use-gesture/core/types'
import type {
DOMHandlers,
GenericOptions,
GestureKey,
InternalHandlers,
NativeHandlers,
NormalizePropFunction
} from '@use-gesture/core/types'
import { watchEffect } from 'vue'
import type { Events as VueEvents } from 'vue'

type Dict = Record<string, any>

const eventMap: Dict = {
onKeyDown: 'onKeydown',
onKeyup: 'onKeyup',
onPointerCancel: 'onPointercancel',
onPointerDown: 'onPointerdown',
onPointerMove: 'onPointermove',
onPointerEnter: 'onPointerenter',
onPointerLeave: 'onPointerleave',
onPointerUp: 'onPointerup',
onWheel: 'onWheel',
onScroll: 'onScroll'
}

function toVueProp(prop: string) {
if (prop in eventMap) return eventMap[prop]

return prop
}

export const normalizeProps = (props: Dict = {}) => {
const normalized: Dict = {}
for (const key in props) normalized[toVueProp(key)] = props[key]

return normalized
const normalizeProp: NormalizePropFunction = (device, actionKey, capture) => {
return device + actionKey
}

type CombinedEventHandlers = VueEvents & DOMHandlers
@@ -53,7 +36,7 @@ export function useRecognizers<Config extends GenericOptions>(
gestureKey?: GestureKey,
nativeHandlers?: NativeHandlers
): HookReturnType<Config> {
const ctrl = new Controller(handlers)
const ctrl = new Controller(handlers, normalizeProp)
ctrl.applyHandlers(handlers, nativeHandlers)
ctrl.applyConfig(config, gestureKey)