valaxy-theme-press 0.28.5 → 0.28.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import type { DocSearchInstance, DocSearchProps } from '@docsearch/js'
|
|
3
3
|
import type { SidepanelInstance, SidepanelProps } from '@docsearch/sidepanel-js'
|
|
4
4
|
import type { AlgoliaSearchOptions } from '../types/algolia'
|
|
5
|
-
import {
|
|
5
|
+
import { useAddonConfig } from 'valaxy'
|
|
6
|
+
import { nextTick, onUnmounted, watch } from 'vue'
|
|
6
7
|
import { useRouter } from 'vue-router'
|
|
7
8
|
|
|
8
9
|
import '../styles/docsearch.css'
|
|
@@ -16,14 +17,7 @@ const props = defineProps<{
|
|
|
16
17
|
|
|
17
18
|
const router = useRouter()
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
const algoliaConfig = ref<{ options?: AlgoliaSearchOptions }>()
|
|
21
|
-
import('valaxy-addon-algolia').then(({ useAddonAlgoliaConfig }) => {
|
|
22
|
-
// Direct assignment — the synchronous watcher below will react to this change
|
|
23
|
-
algoliaConfig.value = useAddonAlgoliaConfig().value
|
|
24
|
-
}).catch(() => {
|
|
25
|
-
console.warn('[valaxy-theme-press] valaxy-addon-algolia is not installed. Algolia search will not work.')
|
|
26
|
-
})
|
|
20
|
+
const algoliaConfig = useAddonConfig<AlgoliaSearchOptions>('valaxy-addon-algolia')
|
|
27
21
|
|
|
28
22
|
let cleanup = () => {}
|
|
29
23
|
let docsearchInstance: DocSearchInstance | undefined
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import type { AlgoliaSearchOptions } from '../types/algolia'
|
|
3
3
|
import { onKeyStroke } from '@vueuse/core'
|
|
4
|
-
import { useSiteConfig } from 'valaxy'
|
|
5
|
-
import { computed, defineAsyncComponent, onMounted, ref } from 'vue'
|
|
4
|
+
import { useAddonConfig, useSiteConfig } from 'valaxy'
|
|
5
|
+
import { computed, defineAsyncComponent, hydrateOnInteraction, onMounted, ref } from 'vue'
|
|
6
6
|
import PressNavBarAskAiButton from './PressNavBarAskAiButton.vue'
|
|
7
7
|
import PressNavBarSearchButton from './PressNavBarSearchButton.vue'
|
|
8
8
|
|
|
@@ -13,27 +13,37 @@ const isFuse = computed(() => siteConfig.value.search.provider === 'fuse')
|
|
|
13
13
|
const isLocal = computed(() => siteConfig.value.search.provider === 'local')
|
|
14
14
|
|
|
15
15
|
// Whether to show the Ask AI button (requires askAi config in addon-algolia)
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
if (isAlgolia.value)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}).catch(() => {})
|
|
24
|
-
}
|
|
16
|
+
const algoliaAddonConfig = useAddonConfig<AlgoliaSearchOptions>('valaxy-addon-algolia')
|
|
17
|
+
const showAskAi = computed(() => {
|
|
18
|
+
if (!isAlgolia.value)
|
|
19
|
+
return false
|
|
20
|
+
const askAi = algoliaAddonConfig.value?.options?.askAi
|
|
21
|
+
return !!askAi
|
|
22
|
+
})
|
|
25
23
|
|
|
26
24
|
const PressAlgoliaSearch = isAlgolia.value
|
|
27
25
|
? defineAsyncComponent(() => import('./PressAlgoliaSearch.vue'))
|
|
28
26
|
: () => null
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Use lazy hydration (Vue 3.5+) to avoid hydration mismatch.
|
|
30
|
+
*
|
|
31
|
+
* `defineAsyncComponent` without a hydration strategy causes mismatch because
|
|
32
|
+
* the SSR bundle resolves async components synchronously (real DOM), while the
|
|
33
|
+
* client hasn't loaded the chunk yet during hydration (comment placeholder).
|
|
34
|
+
*
|
|
35
|
+
* `hydrateOnInteraction` keeps code-splitting benefits and defers hydration
|
|
36
|
+
* until the user actually interacts with the search button.
|
|
37
|
+
*/
|
|
38
|
+
const PressFuseSearch = defineAsyncComponent({
|
|
39
|
+
loader: () => import('./PressFuseSearch.vue'),
|
|
40
|
+
hydrate: hydrateOnInteraction(['click', 'focusin']),
|
|
41
|
+
})
|
|
33
42
|
|
|
34
|
-
const PressLocalSearch =
|
|
35
|
-
|
|
36
|
-
: ()
|
|
43
|
+
const PressLocalSearch = defineAsyncComponent({
|
|
44
|
+
loader: () => import('./PressLocalSearch.vue'),
|
|
45
|
+
hydrate: hydrateOnInteraction(['click', 'focusin']),
|
|
46
|
+
})
|
|
37
47
|
|
|
38
48
|
// #region Algolia lazy loading
|
|
39
49
|
|
|
@@ -46,7 +56,7 @@ const loaded = ref(false)
|
|
|
46
56
|
const actuallyLoaded = ref(false)
|
|
47
57
|
|
|
48
58
|
// Preconnect to Algolia DSN on idle
|
|
49
|
-
onMounted(
|
|
59
|
+
onMounted(() => {
|
|
50
60
|
if (!isAlgolia.value)
|
|
51
61
|
return
|
|
52
62
|
|
|
@@ -54,28 +64,19 @@ onMounted(async () => {
|
|
|
54
64
|
if (document.getElementById(id))
|
|
55
65
|
return
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
preconnect.rel = 'preconnect'
|
|
71
|
-
preconnect.href = `https://${appId}-dsn.algolia.net`
|
|
72
|
-
preconnect.crossOrigin = ''
|
|
73
|
-
document.head.appendChild(preconnect)
|
|
74
|
-
})
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
// valaxy-addon-algolia not installed, skip preconnect
|
|
78
|
-
}
|
|
67
|
+
const appId = algoliaAddonConfig.value?.options?.appId
|
|
68
|
+
if (!appId)
|
|
69
|
+
return
|
|
70
|
+
|
|
71
|
+
const rIC = window.requestIdleCallback || setTimeout
|
|
72
|
+
rIC(() => {
|
|
73
|
+
const preconnect = document.createElement('link')
|
|
74
|
+
preconnect.id = id
|
|
75
|
+
preconnect.rel = 'preconnect'
|
|
76
|
+
preconnect.href = `https://${appId}-dsn.algolia.net`
|
|
77
|
+
preconnect.crossOrigin = ''
|
|
78
|
+
document.head.appendChild(preconnect)
|
|
79
|
+
})
|
|
79
80
|
})
|
|
80
81
|
|
|
81
82
|
// Keyboard shortcuts for Algolia
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valaxy-theme-press",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.7",
|
|
4
4
|
"description": "Docs Theme for Valaxy",
|
|
5
5
|
"author": {
|
|
6
6
|
"email": "me@yunyoujun.cn",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"main": "node/index.ts",
|
|
23
23
|
"types": "types/index.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@docsearch/css": "^4.6.
|
|
26
|
-
"@docsearch/js": "^4.6.
|
|
27
|
-
"@docsearch/sidepanel-js": "^4.6.
|
|
28
|
-
"reka-ui": "^2.9.
|
|
25
|
+
"@docsearch/css": "^4.6.3",
|
|
26
|
+
"@docsearch/js": "^4.6.3",
|
|
27
|
+
"@docsearch/sidepanel-js": "^4.6.3",
|
|
28
|
+
"reka-ui": "^2.9.7",
|
|
29
29
|
"vitepress": "^2.0.0-alpha.17"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"valaxy": "0.28.
|
|
32
|
+
"valaxy": "0.28.7"
|
|
33
33
|
}
|
|
34
34
|
}
|