1
1
import type { DocSearchProps } from '@docsearch/react'
2
2
import { deepAssign , isFunction } from '@vuepress/helper/client'
3
3
import type { App , ComputedRef , InjectionKey , MaybeRefOrGetter , Ref } from 'vue'
4
- import { computed , inject , isRef , ref , watch } from 'vue'
4
+ import { computed , inject , isRef , readonly , ref , watch } from 'vue'
5
5
import { useRouteLocale } from 'vuepress/client'
6
6
import type { DocSearchOptions } from '../../shared/index.js'
7
7
8
8
declare const __VUEPRESS_DEV__ : boolean
9
9
declare const __DOCSEARCH_OPTIONS__ : DocSearchOptions
10
10
11
- const docSearchOptions : Partial < DocSearchProps > = __DOCSEARCH_OPTIONS__
11
+ const docSearchDefineOptions : Partial < DocSearchProps > = __DOCSEARCH_OPTIONS__
12
12
13
- const docsearch = ref ( docSearchOptions as DocSearchProps )
13
+ const docsearchOptions = ref ( docSearchDefineOptions as DocSearchProps )
14
14
15
15
const docsearchSymbol : InjectionKey <
16
16
Ref <
@@ -33,16 +33,17 @@ export const defineDocSearchConfig = (
33
33
watch (
34
34
( ) => options . value ,
35
35
( value ) => {
36
- docsearch . value = deepAssign ( { } , docSearchOptions , value )
36
+ docsearchOptions . value = deepAssign ( { } , docSearchDefineOptions , value )
37
37
} ,
38
+ { immediate : true } ,
38
39
)
39
40
} else if ( isFunction ( options ) ) {
40
- watch ( options , ( value ) => {
41
- docsearch . value = deepAssign ( { } , docSearchOptions , value )
41
+ watch ( computed ( options ) , ( value ) => {
42
+ docsearchOptions . value = deepAssign ( { } , docSearchDefineOptions , value )
42
43
} )
43
44
} else {
44
45
// @ts -expect-error: Types loop back
45
- docsearch . value = deepAssign ( { } , docSearchOptions , options )
46
+ docsearchOptions . value = deepAssign ( { } , docSearchDefineOptions , options )
46
47
}
47
48
}
48
49
@@ -57,5 +58,5 @@ export const useDocSearchOptions = (): ComputedRef<DocSearchProps> => {
57
58
}
58
59
59
60
export const injectDocSearchConfig = ( app : App ) : void => {
60
- app . provide ( docsearchSymbol , docsearch )
61
+ app . provide ( docsearchSymbol , readonly ( docsearchOptions ) )
61
62
}
0 commit comments