@scalar/api-reference
Version: 
Generate beautiful API references from OpenAPI documents
47 lines (46 loc) • 1.07 kB
JavaScript
import { ref as a, watch as i, toValue as p, computed as h } from "vue";
import { createFuseInstance as x } from "../helpers/create-fuse-instance.js";
import { createSearchIndex as I } from "../helpers/create-search-index.js";
const d = 25;
function g(l, v) {
  const n = x(), e = a();
  i(
    l,
    () => {
      const { entries: r } = p(l), c = I(r, v);
      n.setCollection(c);
    },
    { immediate: !0 }
  );
  const t = a("");
  i(t, (r) => {
    if (r.length) {
      f();
      return;
    }
    o();
  });
  function o() {
    t.value = "", e.value = void 0, s.value = [];
  }
  const s = a([]), f = () => {
    e.value = 0, s.value = n.search(t.value, {
      limit: d
    });
  }, u = h(() => t.value.length !== 0 ? s.value : n._docs.slice(0, d).map((c, S) => ({
    item: c,
    refIndex: S
  }))), m = h(
    () => typeof e.value == "number" ? u.value[e.value] : void 0
  );
  return {
    resetSearch: o,
    selectedIndex: e,
    selectedSearchResult: m,
    searchResultsWithPlaceholderResults: u,
    query: t
  };
}
export {
  g as useSearchIndex
};