mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-16 14:18:29 +00:00
chore(docs): upgrade to VitePress 2
- Bump vitepress to 2.0.0-alpha.21 - Drop direct @docsearch/js and @docsearch/css deps; VitePress 2 ships DocSearch v4 and imports its styles itself - VPNavBarSearch override: use the new VPAlgoliaSearchBox props (algoliaOptions + openRequest) instead of dispatching synthetic keydown events - VPCarbonAds override: replace removed useAside composable with a media query, matching upstream - VPFooter override: use useLayout from vitepress/theme instead of the removed useSidebar().hasSidebar Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G9u8FhZukDbCKe1ZFByn43
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import type { DefaultTheme } from 'vitepress/theme'
|
||||
import { ref, watch, onMounted } from 'vue'
|
||||
import { useAside } from 'vitepress/dist/client/theme-default/composables/aside.js'
|
||||
import { useMediaQuery } from '@vueuse/core'
|
||||
import { useData } from 'vitepress/dist/client/theme-default/composables/data.js'
|
||||
|
||||
const { page } = useData()
|
||||
@@ -12,7 +12,7 @@ const props = defineProps<{
|
||||
|
||||
const carbonOptions = props.carbonAds
|
||||
|
||||
const { isAsideEnabled } = useAside()
|
||||
const isAsideEnabled = useMediaQuery('(min-width: 80rem)')
|
||||
const container = ref()
|
||||
|
||||
let isInitialized = false
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { useData } from 'vitepress';
|
||||
import { useSidebar } from 'vitepress/dist/client/theme-default/composables/sidebar.js';
|
||||
import { useLayout } from 'vitepress/theme';
|
||||
import VPLink from 'vitepress/dist/client/theme-default/components/VPLink.vue';
|
||||
import { computed } from 'vue';
|
||||
import SurveyAskOverlay from '../SurveyAskOverlay.vue';
|
||||
|
||||
const { theme } = useData();
|
||||
const { hasSidebar } = useSidebar();
|
||||
const { hasSidebar } = useLayout();
|
||||
|
||||
const githubLink = computed(
|
||||
() => theme.value.socialLinks.find(({ icon }) => icon === 'github').link,
|
||||
|
||||
@@ -2,31 +2,33 @@
|
||||
import { ref } from 'vue'
|
||||
|
||||
// This component can be rendered more than once on a page (e.g. a hidden
|
||||
// copy inside `.content-body`). DocSearch mounts into the first `#docsearch`
|
||||
// in the document, so only a single instance may ever render the search box.
|
||||
// copy inside `.content-body`). DocSearch mounts into `#vp-docsearch`, so only
|
||||
// a single instance may ever render the search box.
|
||||
const loaded = ref(false)
|
||||
// Shared so that any instance (e.g. the visible input) can open the modal
|
||||
// rendered by the owning instance.
|
||||
const openRequest = ref<{ target: 'search'; nonce: number } | null>(null)
|
||||
let openNonce = 0
|
||||
// Every instance registers the hotkeys; only handle each event once.
|
||||
let lastHandledEvent: KeyboardEvent | null = null
|
||||
</script>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import '@docsearch/css/dist/style.css'
|
||||
import {
|
||||
computed,
|
||||
defineAsyncComponent,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
} from 'vue'
|
||||
import { computed, defineAsyncComponent, onMounted } from 'vue'
|
||||
import { onKeyStroke } from '@vueuse/core'
|
||||
import type { DefaultTheme } from 'vitepress/theme'
|
||||
|
||||
import { useData } from 'vitepress'
|
||||
import FakeInput from '../base/FakeInput.vue'
|
||||
|
||||
const VPAlgoliaSearchBox = defineAsyncComponent(() => import('vitepress/dist/client/theme-default/components/VPAlgoliaSearchBox.vue'));
|
||||
const VPAlgoliaSearchBox = defineAsyncComponent(
|
||||
() => import('vitepress/dist/client/theme-default/components/VPAlgoliaSearchBox.vue'),
|
||||
)
|
||||
|
||||
const { theme } = useData<DefaultTheme.Config>()
|
||||
|
||||
const algolia = computed(
|
||||
() =>
|
||||
(theme.value.search?.options ?? theme.value.algolia) as DefaultTheme.AlgoliaSearchOptions,
|
||||
const algoliaOptions = computed(
|
||||
() => (theme.value.search?.options ?? {}) as DefaultTheme.AlgoliaSearchOptions,
|
||||
)
|
||||
|
||||
// whether this instance is the one rendering the (hidden) search box
|
||||
@@ -36,47 +38,39 @@ const shortcutText = ref('')
|
||||
// to avoid loading the docsearch js upfront (which is more than 1/3 of the
|
||||
// payload), we delay initializing it until the user has actually clicked or
|
||||
// hit the hotkey to invoke it.
|
||||
const preconnect = () => {
|
||||
onMounted(() => {
|
||||
shortcutText.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) ? '⌘K' : 'Ctrl+K'
|
||||
|
||||
const id = 'VPAlgoliaPreconnect'
|
||||
if (document.getElementById(id)) return
|
||||
if (document.getElementById(id) || !algoliaOptions.value.appId) return
|
||||
|
||||
const rIC = window.requestIdleCallback || setTimeout
|
||||
rIC(() => {
|
||||
const preconnect = document.createElement('link')
|
||||
preconnect.id = id
|
||||
preconnect.rel = 'preconnect'
|
||||
preconnect.href = `https://${algolia.value.appId}-dsn.algolia.net`
|
||||
preconnect.href = `https://${algoliaOptions.value.appId}-dsn.algolia.net`
|
||||
preconnect.crossOrigin = ''
|
||||
document.head.appendChild(preconnect)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
preconnect()
|
||||
|
||||
shortcutText.value = /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform) ? '⌘K' : 'Ctrl+K'
|
||||
|
||||
// once docsearch is initialized it handles the hotkey itself
|
||||
const handleSearchHotKey = (event: KeyboardEvent) => {
|
||||
if (loaded.value) return remove()
|
||||
|
||||
if (
|
||||
(event.key.toLowerCase() === 'k' && (event.metaKey || event.ctrlKey)) ||
|
||||
(!isEditingContent(event) && event.key === '/')
|
||||
) {
|
||||
event.preventDefault()
|
||||
open()
|
||||
remove()
|
||||
}
|
||||
onKeyStroke('k', (event) => {
|
||||
if (event === lastHandledEvent) return
|
||||
if (event.ctrlKey || event.metaKey) {
|
||||
lastHandledEvent = event
|
||||
event.preventDefault()
|
||||
open()
|
||||
}
|
||||
})
|
||||
|
||||
const remove = () => {
|
||||
window.removeEventListener('keydown', handleSearchHotKey)
|
||||
onKeyStroke('/', (event) => {
|
||||
if (event === lastHandledEvent) return
|
||||
if (!isEditingContent(event)) {
|
||||
lastHandledEvent = event
|
||||
event.preventDefault()
|
||||
open()
|
||||
}
|
||||
|
||||
window.addEventListener('keydown', handleSearchHotKey)
|
||||
|
||||
onUnmounted(remove)
|
||||
})
|
||||
|
||||
function open() {
|
||||
@@ -84,23 +78,8 @@ function open() {
|
||||
loaded.value = true
|
||||
isOwner.value = true
|
||||
}
|
||||
setTimeout(poll, 16)
|
||||
}
|
||||
|
||||
function poll() {
|
||||
// programmatically open the search box after initialize
|
||||
const e = new Event('keydown') as any
|
||||
|
||||
e.key = 'k'
|
||||
e.metaKey = true
|
||||
|
||||
window.dispatchEvent(e)
|
||||
|
||||
setTimeout(() => {
|
||||
if (!document.querySelector('.DocSearch-Modal')) {
|
||||
poll()
|
||||
}
|
||||
}, 16)
|
||||
// The search box queues the request until DocSearch is ready.
|
||||
openRequest.value = { target: 'search', nonce: ++openNonce }
|
||||
}
|
||||
|
||||
function isEditingContent(event: KeyboardEvent): boolean {
|
||||
@@ -129,7 +108,7 @@ function isEditingContent(event: KeyboardEvent): boolean {
|
||||
|
||||
<!-- docsearch renders its own button here; we only need its modal -->
|
||||
<div v-if="isOwner" class="docsearch-host">
|
||||
<VPAlgoliaSearchBox :algolia="algolia" />
|
||||
<VPAlgoliaSearchBox :algolia-options="algoliaOptions" :open-request="openRequest" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+1
-3
@@ -31,7 +31,6 @@
|
||||
"author": "Eric Fennis",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"@docsearch/js": "3.8.2",
|
||||
"@lucide/build-icons": "workspace:*",
|
||||
"@lucide/helpers": "workspace:*",
|
||||
"@lucide/shared": "workspace:*",
|
||||
@@ -53,13 +52,12 @@
|
||||
"svg-pathdata": "^9.0.0",
|
||||
"svgson": "^5.3.1",
|
||||
"typescript": "^6.0.3",
|
||||
"vitepress": "^1.6.4",
|
||||
"vitepress": "2.0.0-alpha.21",
|
||||
"vitepress-plugin-group-icons": "^1.7.6",
|
||||
"vitepress-plugin-llms": "^1.13.5",
|
||||
"vue-tsc": "^3.3.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docsearch/css": "3.8.2",
|
||||
"@floating-ui/vue": "^2.0.1",
|
||||
"@headlessui/vue": "^1.7.23",
|
||||
"@lucide/vue": "workspace:*",
|
||||
|
||||
Generated
+112
-529
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user