UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

84 lines (83 loc) 2.83 kB
import { defineComponent as v, ref as p, onMounted as h, onBeforeUnmount as S, createElementBlock as g, openBlock as b } from "vue"; import { useActiveEntities as B, useWorkspace as E } from "@scalar/api-client/store"; import { mutateSecuritySchemeDiff as R } from "@scalar/api-client/views/Request/libs"; import { getServersFromDocument as k } from "@scalar/oas-utils/helpers"; import { emitCustomEvent as q } from "@scalar/workspace-store/events"; import { watchDebounced as f } from "@vueuse/core"; import l from "microdiff"; import { useNavState as D } from "../../hooks/useNavState.js"; import { useApiClient as U } from "./useApiClient.js"; const N = /* @__PURE__ */ v({ __name: "ApiClientModal", props: { configuration: {}, dereferencedDocument: {} }, setup(r) { const n = p(null), { client: a, init: m } = U(), i = B(), u = E(), { isIntersectionEnabled: s } = D(), d = () => ({ name: "on-before-request", hooks: { onBeforeRequest: r.configuration.onBeforeRequest } }); return h(() => { n.value && m({ el: n.value, configuration: { ...r.configuration, // If the onBeforeRequest hook is configured, we add the plugin to the API client. plugins: typeof r.configuration.onBeforeRequest == "function" ? [d] : [] }, store: u }); }), f( () => r.dereferencedDocument, (e, o) => { !e || !l(e, o || {})?.length || (i.activeCollection.value && a.value?.resetStore(), u.importSpecFile(void 0, "default", { dereferencedDocument: e, shouldLoad: !1, documentUrl: r.configuration?.url, useCollectionSecurity: !0, ...r.configuration })); } ), f( () => r.configuration, (e, o) => { if (!o || !i.activeCollection.value) return; const c = l(o, e); if (!c.some( (t) => t.path[0] === "url" || t.path[0] === "content" || t.path[1] === "url" || t.path[1] === "content" )) { if (c.forEach((t) => { t.path[0] === "authentication" && R(t, i, u); }), e.servers || o.servers) { const t = k( e.servers ?? r.dereferencedDocument.servers, { baseServerURL: e.baseServerURL } ); q(n.value, "scalar-replace-servers", { servers: t, options: { disableOldStoreUpdate: !0 } }); } } s.value = !1, setTimeout(() => { s.value = !0; }, 1e3); }, { deep: !0, debounce: 300 } ), S(() => a.value?.app.unmount()), (e, o) => (b(), g("div", { ref_key: "el", ref: n }, null, 512)); } }); export { N as default };