File tree Expand file tree Collapse file tree 2 files changed +42
-30
lines changed
valaxy-addon-algolia/components
valaxy-theme-press/components Expand file tree Collapse file tree 2 files changed +42
-30
lines changed Original file line number Diff line number Diff line change @@ -44,35 +44,6 @@ async function update() {
4444 })
4545}
4646
47- onMounted (() => {
48- const options = {
49- ... algolia .value .options ,
50- ... algolia .value .options ?.locales ?.[locale .value ],
51- }
52-
53- // now only lang:en
54- // const rawFacetFilters = options.searchParameters?.facetFilters ?? []
55- // const facetFilters = [
56- // ...(Array.isArray(rawFacetFilters)
57- // ? rawFacetFilters
58- // : [rawFacetFilters]
59- // ).filter(f => !f.startsWith('lang:')),
60- // `lang:${locale.value}`,
61- // ]
62-
63- if (options && options .apiKey && options .appId && options .indexName ) {
64- if (! document .querySelector (' .DocSearch-Container' )) {
65- initialize ({
66- ... options as AlgoliaSearchOptions ,
67- searchParameters: {
68- ... options .searchParameters ,
69- // facetFilters,
70- },
71- })
72- }
73- }
74- })
75-
7647function initialize(userOptions : AlgoliaSearchOptions ) {
7748 // note: multi-lang search support is removed since the theme
7849 // doesn't support multiple locales as of now.
Original file line number Diff line number Diff line change 11<script lang="ts" setup>
22import { useAddonAlgolia } from ' valaxy-addon-algolia'
3+ import { onMounted , onUnmounted } from ' vue'
34import { useI18n } from ' vue-i18n'
45
56const { t } = useI18n ()
67
7- const { loaded, load } = useAddonAlgolia ()
8+ const { loaded, load, dispatchEvent } = useAddonAlgolia ()
9+
10+ defineExpose ({
11+ loaded ,
12+ load ,
13+ dispatchEvent ,
14+ })
15+
16+ function isEditingContent(event : KeyboardEvent ): boolean {
17+ const element = event .target as HTMLElement
18+ const tagName = element .tagName
19+
20+ return (
21+ element .isContentEditable
22+ || tagName === ' INPUT'
23+ || tagName === ' SELECT'
24+ || tagName === ' TEXTAREA'
25+ )
26+ }
27+
28+ onMounted (() => {
29+ const handleSearchHotKey = (event : KeyboardEvent ) => {
30+ if (
31+ (event .key ?.toLowerCase () === ' k' && (event .metaKey || event .ctrlKey ))
32+ || (! isEditingContent (event ) && event .key === ' /' )
33+ ) {
34+ event .preventDefault ()
35+ load ()
36+ // eslint-disable-next-line ts/no-use-before-define
37+ remove ()
38+ }
39+ }
40+
41+ const remove = () => {
42+ window .removeEventListener (' keydown' , handleSearchHotKey )
43+ }
44+
45+ window .addEventListener (' keydown' , handleSearchHotKey )
46+
47+ onUnmounted (remove )
48+ })
849 </script >
950
1051<template >
You can’t perform that action at this time.
0 commit comments