|
| 1 | +import { defineComponent, onMounted, watch, nextTick, mergeProps, useSSRContext } from "vue"; |
| 2 | +import { ssrRenderAttrs } from "vue/server-renderer"; |
| 3 | +import docsearch from "@docsearch/js"; |
| 4 | +import { u as useRouter, a as useRoute, b as useData } from "./app.js"; |
| 5 | +import "@vueuse/core"; |
| 6 | +import "./plugin-vue_export-helper.1tPrXgE0.js"; |
| 7 | +const _sfc_main = /* @__PURE__ */ defineComponent({ |
| 8 | + __name: "VPAlgoliaSearchBox", |
| 9 | + __ssrInlineRender: true, |
| 10 | + props: { |
| 11 | + algolia: {} |
| 12 | + }, |
| 13 | + setup(__props) { |
| 14 | + const props = __props; |
| 15 | + const router = useRouter(); |
| 16 | + const route = useRoute(); |
| 17 | + const { site, localeIndex, lang } = useData(); |
| 18 | + onMounted(update); |
| 19 | + watch(localeIndex, update); |
| 20 | + async function update() { |
| 21 | + var _a, _b; |
| 22 | + await nextTick(); |
| 23 | + const options = { |
| 24 | + ...props.algolia, |
| 25 | + ...(_a = props.algolia.locales) == null ? void 0 : _a[localeIndex.value] |
| 26 | + }; |
| 27 | + const rawFacetFilters = ((_b = options.searchParameters) == null ? void 0 : _b.facetFilters) ?? []; |
| 28 | + const facetFilters = [ |
| 29 | + ...(Array.isArray(rawFacetFilters) ? rawFacetFilters : [rawFacetFilters]).filter((f) => !f.startsWith("lang:")), |
| 30 | + `lang:${lang.value}` |
| 31 | + ]; |
| 32 | + initialize({ |
| 33 | + ...options, |
| 34 | + searchParameters: { |
| 35 | + ...options.searchParameters, |
| 36 | + facetFilters |
| 37 | + } |
| 38 | + }); |
| 39 | + } |
| 40 | + function initialize(userOptions) { |
| 41 | + const options = Object.assign({}, userOptions, { |
| 42 | + container: "#docsearch", |
| 43 | + navigator: { |
| 44 | + navigate({ itemUrl }) { |
| 45 | + const { pathname: hitPathname } = new URL( |
| 46 | + window.location.origin + itemUrl |
| 47 | + ); |
| 48 | + if (route.path === hitPathname) { |
| 49 | + window.location.assign(window.location.origin + itemUrl); |
| 50 | + } else { |
| 51 | + router.go(itemUrl); |
| 52 | + } |
| 53 | + } |
| 54 | + }, |
| 55 | + transformItems(items) { |
| 56 | + return items.map((item) => { |
| 57 | + return Object.assign({}, item, { |
| 58 | + url: getRelativePath(item.url) |
| 59 | + }); |
| 60 | + }); |
| 61 | + }, |
| 62 | + hitComponent({ hit, children }) { |
| 63 | + return { |
| 64 | + __v: null, |
| 65 | + type: "a", |
| 66 | + ref: void 0, |
| 67 | + constructor: void 0, |
| 68 | + key: void 0, |
| 69 | + props: { href: hit.url, children } |
| 70 | + }; |
| 71 | + } |
| 72 | + }); |
| 73 | + docsearch(options); |
| 74 | + } |
| 75 | + function getRelativePath(url) { |
| 76 | + const { pathname, hash } = new URL(url, location.origin); |
| 77 | + return pathname.replace(/\.html$/, site.value.cleanUrls ? "" : ".html") + hash; |
| 78 | + } |
| 79 | + return (_ctx, _push, _parent, _attrs) => { |
| 80 | + _push(`<div${ssrRenderAttrs(mergeProps({ id: "docsearch" }, _attrs))}></div>`); |
| 81 | + }; |
| 82 | + } |
| 83 | +}); |
| 84 | +const _sfc_setup = _sfc_main.setup; |
| 85 | +_sfc_main.setup = (props, ctx) => { |
| 86 | + const ssrContext = useSSRContext(); |
| 87 | + (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("../node_modules/vitepress/dist/client/theme-default/components/VPAlgoliaSearchBox.vue"); |
| 88 | + return _sfc_setup ? _sfc_setup(props, ctx) : void 0; |
| 89 | +}; |
| 90 | +export { |
| 91 | + _sfc_main as default |
| 92 | +}; |
0 commit comments