Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion example/docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ module.exports = {
* Apply plugins,ref:https://v1.vuepress.vuejs.org/zh/plugin/
*/
plugins: [
[require.resolve("../../../"), {}],
[require.resolve("../../../"), {
hooks: {
onSearch: (query) => {
console.info(`Search initiated! Query = ${query}`);
}
}
}],
],
};
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ module.exports = (options) => ({
alias: {
"@SearchBox": path.resolve(__dirname, "src", "SearchBox.vue"),
},
clientDynamicModules: () => {
const hooks = options.hooks || {};
const nullHook = () => {};
return {
name: "search-hooks.js",
content: `export default {
onSearch: ${hooks.onSearch || nullHook}
}`,
};
},
define: {
SEARCH_OPTIONS: options.search_options || defaultSearchOptions,
SEARCH_MAX_SUGGESTIONS: options.maxSuggestions || 10,
Expand Down
8 changes: 7 additions & 1 deletion src/SearchBox.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="search-box">
<input
@input="query = $event.target.value"
@input="onInput"
aria-label="Search"
:value="query"
:class="{ focused: focused }"
Expand Down Expand Up @@ -44,6 +44,7 @@
<script>
import Flexsearch from "flexsearch";
import { highlightText } from "./utils";
import hooks from '@dynamic/search-hooks'

/* global
SEARCH_MAX_SUGGESTIONS
Expand Down Expand Up @@ -135,6 +136,11 @@ export default {
);
},

onInput(event) {
this.query = event.target.value;
hooks.onSearch(this.query);
},

onHotkey(event) {
if (
event.srcElement === document.body &&
Expand Down