fix: fix select demo and search (#14)

This commit is contained in:
Justineo 2021-12-27 13:15:01 +08:00
parent a3ba44e690
commit b22b1cf9e0
No known key found for this signature in database
GPG Key ID: B73F0979CF18A0EA
4 changed files with 9847 additions and 14064 deletions

View File

@ -1,6 +1,7 @@
<template> <template>
<div class="one-search"> <div class="one-search">
<veui-search-box <veui-search-box
ref="search"
v-model="query" v-model="query"
class="input" class="input"
:placeholder="searchPlaceholder" :placeholder="searchPlaceholder"
@ -36,6 +37,12 @@ function normalizeURL (url) {
return url.replace(/\/([#?])/, '$1') return url.replace(/\/([#?])/, '$1')
} }
function wait (time) {
return new Promise(resolve => {
setTimeout(resolve, time)
})
}
export default { export default {
name: 'one-search', name: 'one-search',
components: { components: {
@ -44,6 +51,7 @@ export default {
mixins: [i18n], mixins: [i18n],
data () { data () {
return { return {
preparing: true,
query: '' query: ''
} }
}, },
@ -65,11 +73,20 @@ export default {
const { pathname, hash } = new URL(absoluteUrl) const { pathname, hash } = new URL(absoluteUrl)
return `${pathname}/${hash}` return `${pathname}/${hash}`
}, },
triggerFocus (e) {
if (e.key === 'k' && (e.metaKey || e.ctrlKey)) {
this.$refs.search.focus()
}
},
initialize (locale) { initialize (locale) {
document.addEventListener('keydown', this.triggerFocus)
Promise.all([ Promise.all([
import(/* webpackChunkName: "docsearch" */ '@docsearch/js'), import(/* webpackChunkName: "docsearch" */ '@docsearch/js'),
import(/* webpackChunkName: "docsearch" */ '@docsearch/css') import(/* webpackChunkName: "docsearch" */ '@docsearch/css')
]).then(([docsearch]) => { ]).then(([docsearch]) => {
document.removeEventListener('keydown', this.triggerFocus)
docsearch = docsearch.default docsearch = docsearch.default
docsearch({ docsearch({
appId: 'WW5G10K3KO', appId: 'WW5G10K3KO',
@ -130,6 +147,12 @@ export default {
) )
} }
}) })
this.preparing = false
if (this.query) {
this.teleportQuery(this.query)
}
}) })
}, },
update (locale) { update (locale) {
@ -137,7 +160,7 @@ export default {
this.initialize(locale) this.initialize(locale)
}, },
handleInput (value) { handleInput (value) {
if (!value) { if (!value || this.preparing) {
return return
} }

View File

@ -117,7 +117,6 @@ module.exports = {
}) })
config.resolve.alias.vue$ = 'vue/dist/vue.esm.js' config.resolve.alias.vue$ = 'vue/dist/vue.esm.js'
config.resolve.alias['vue-inbrowser-compiler-utils'] = '@justfork/vue-inbrowser-compiler-utils'
config.resolve.alias['vue-monaco'] = '@justfork/vue-monaco' config.resolve.alias['vue-monaco'] = '@justfork/vue-monaco'
}, },

23846
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,6 @@
"devDependencies": { "devDependencies": {
"@docsearch/css": "^3.0.0-alpha.39", "@docsearch/css": "^3.0.0-alpha.39",
"@docsearch/js": "^3.0.0-alpha.39", "@docsearch/js": "^3.0.0-alpha.39",
"@justfork/vue-inbrowser-compiler-utils": "^4.42.0",
"@justfork/vue-monaco": "^0.3.1", "@justfork/vue-monaco": "^0.3.1",
"@stackblitz/sdk": "^1.5.2", "@stackblitz/sdk": "^1.5.2",
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",
@ -88,7 +87,7 @@
"veui-loader": "^2.3.4", "veui-loader": "^2.3.4",
"veui-theme-dls": "^2.3.4", "veui-theme-dls": "^2.3.4",
"veui-theme-dls-icons": "^2.3.4", "veui-theme-dls-icons": "^2.3.4",
"vue-awesome": "^4.1.0", "vue-awesome": "^4.5.0",
"vue-i18n": "^8.16.0", "vue-i18n": "^8.16.0",
"vue-live": "^1.17.2", "vue-live": "^1.17.2",
"vue-windows": "^0.2.4" "vue-windows": "^0.2.4"