File tree Expand file tree Collapse file tree 2 files changed +23
-17
lines changed Expand file tree Collapse file tree 2 files changed +23
-17
lines changed Original file line number Diff line number Diff line change @@ -401,15 +401,6 @@ export const Carousel = defineComponent({
401
401
*/
402
402
const isSliding = ref ( false )
403
403
404
- const { handleScroll } = useWheel ( {
405
- isVertical : isVertical . value ,
406
- isReversed : isReversed . value ,
407
- isSliding : isSliding . value ,
408
- config,
409
- next,
410
- prev,
411
- } )
412
-
413
404
const onDrag = ( {
414
405
delta,
415
406
isTouch,
@@ -443,15 +434,24 @@ export const Carousel = defineComponent({
443
434
444
435
emit ( 'drag' , delta )
445
436
}
446
- const onDragEnd = ( ) => {
447
- slideTo ( activeSlideIndex . value )
448
- }
437
+
438
+ const onDragEnd = ( ) => slideTo ( activeSlideIndex . value )
439
+
449
440
const { dragged, isDragging, handleDragStart } = useDragging ( {
450
- isSliding : isSliding . value ,
441
+ isSliding,
451
442
onDrag,
452
443
onDragEnd,
453
444
} )
454
445
446
+ const { handleScroll } = useWheel ( {
447
+ isVertical,
448
+ isReversed,
449
+ isSliding,
450
+ config,
451
+ next,
452
+ prev,
453
+ } )
454
+
455
455
function slideTo ( slideIndex : number , skipTransition = false ) : void {
456
456
if ( ! skipTransition && isSliding . value ) {
457
457
return
Original file line number Diff line number Diff line change 1
- import { ref , reactive } from 'vue'
1
+ import { ref , reactive , computed , Ref } from 'vue'
2
2
3
3
import { throttle } from '@/utils'
4
4
5
5
export interface UseDraggingOptions {
6
+ isSliding : boolean | Ref < boolean >
6
7
onDrag ?: ( data : { delta : { x : number ; y : number } ; isTouch : boolean } ) => void
7
8
onDragStart ?: ( ) => void
8
9
onDragEnd ?: ( ) => void
9
- isSliding ?: boolean
10
10
}
11
11
12
- export function useDragging ( options : UseDraggingOptions = { } ) {
12
+ export function useDragging ( options : UseDraggingOptions ) {
13
13
let isTouch = false
14
14
const startPosition = { x : 0 , y : 0 }
15
15
const dragged = reactive ( { x : 0 , y : 0 } )
16
16
const isDragging = ref ( false )
17
17
18
+ const { isSliding } = options
19
+
20
+ const sliding = computed ( ( ) => {
21
+ return typeof isSliding === 'boolean' ? isSliding : isSliding . value
22
+ } )
23
+
18
24
const handleDragStart = ( event : MouseEvent | TouchEvent ) : void => {
19
25
// Prevent drag initiation on input elements or if already sliding
20
26
const targetTagName = ( event . target as HTMLElement ) . tagName
21
- if ( [ 'INPUT' , 'TEXTAREA' , 'SELECT' ] . includes ( targetTagName ) || options . isSliding ) {
27
+ if ( [ 'INPUT' , 'TEXTAREA' , 'SELECT' ] . includes ( targetTagName ) || sliding . value ) {
22
28
return
23
29
}
24
30
You can’t perform that action at this time.
0 commit comments