11import { isFunction } from '@vuepress/helper/client'
22import type { PhotoSwipeOptions as OriginalPhotoSwipeOptions } from 'photoswipe'
3- import type { App , MaybeRefOrGetter , Ref } from 'vue'
4- import { inject , isRef , ref , watch } from 'vue'
3+ import type { App , InjectionKey , MaybeRefOrGetter , Ref } from 'vue'
4+ import { computed , inject , isRef , ref , watch } from 'vue'
55
66export type PhotoSwipeOptions = Omit <
77 OriginalPhotoSwipeOptions ,
88 // These are handled internally
99 'dataSource' | 'index'
1010>
1111
12+ export type PhotoSwipeOptionsRef = Ref < PhotoSwipeOptions >
13+
1214declare const __VUEPRESS_DEV__ : boolean
1315
14- const photoswipeOptions : Ref < PhotoSwipeOptions > = ref ( { } )
16+ const photoswipeOptions : PhotoSwipeOptionsRef = ref ( { } )
1517
16- const photoswipeSymbol = Symbol ( __VUEPRESS_DEV__ ? 'photoswipe' : '' )
18+ const photoswipeSymbol : InjectionKey < PhotoSwipeOptionsRef > = Symbol (
19+ __VUEPRESS_DEV__ ? 'photoswipe' : '' ,
20+ )
1721
1822export const definePhotoSwipeConfig = (
1923 options : MaybeRefOrGetter < PhotoSwipeOptions > ,
@@ -24,17 +28,18 @@ export const definePhotoSwipeConfig = (
2428 ( value ) => {
2529 photoswipeOptions . value = value
2630 } ,
31+ { immediate : true } ,
2732 )
2833 } else if ( isFunction ( options ) ) {
29- watch ( options , ( value ) => {
34+ watch ( computed ( options ) , ( value ) => {
3035 photoswipeOptions . value = value
3136 } )
3237 } else {
3338 photoswipeOptions . value = options
3439 }
3540}
3641
37- export const usePhotoSwipeOptions = ( ) : Ref < PhotoSwipeOptions > =>
42+ export const usePhotoSwipeOptions = ( ) : PhotoSwipeOptionsRef =>
3843 inject ( photoswipeSymbol ) !
3944
4045export const injectPhotoSwipeConfig = ( app : App ) : void => {
0 commit comments