@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
149 lines (148 loc) • 6.02 kB
JavaScript
import { defineComponent as C, computed as B, provide as a, useId as O, ref as u, onBeforeMount as P, onMounted as k, onUnmounted as q, watch as c, createElementBlock as x, openBlock as F, Fragment as N, createElementVNode as Y, createVNode as d, unref as r } from "vue";
import { provideUseId as U } from "@headlessui/vue";
import { LAYOUT_SYMBOL as V } from "@scalar/api-client/hooks";
import { WORKSPACE_SYMBOL as $, ACTIVE_ENTITIES_SYMBOL as z } from "@scalar/api-client/store";
import { addScalarClassesToHeadless as G } from "@scalar/components";
import { sleep as H } from "@scalar/helpers/testing/sleep";
import { useBreakpoints as K } from "@scalar/use-hooks/useBreakpoints";
import { ScalarToasts as Q } from "@scalar/use-toasts";
import { useDebounceFn as W, useResizeObserver as j } from "@vueuse/core";
import { hasLazyLoaded as J } from "./Lazy/lazyBus.js";
import { useNavState as X } from "../hooks/useNavState.js";
import { useLegacyStoreEvents as Z } from "../v2/hooks/use-legacy-store-events.js";
import { useDocumentSource as _ } from "../features/document-source/hooks/useDocumentSource.js";
import { PLUGIN_MANAGER_SYMBOL as ee } from "../plugins/hooks/usePluginManager.js";
import { createPluginManager as oe } from "../plugins/plugin-manager.js";
import { useSidebar as te } from "../v2/blocks/scalar-sidebar-block/hooks/useSidebar.js";
import ne from "./Content/Content.vue.js";
/* empty css */
import ie from "../features/api-client-modal/ApiClientModal.vue.js";
const re = ["aria-label"], Te = /* @__PURE__ */ C({
inheritAttrs: !1,
__name: "ApiReferenceContent",
props: {
configuration: {},
dereferencedDocument: {},
originalDocument: {},
isDark: { type: Boolean },
rawSpec: {},
store: {}
},
emits: ["changeTheme", "updateContent", "loadSwaggerFile", "linkSwaggerFile", "toggleDarkMode"],
setup(t) {
const o = B(() => ({
...t.configuration,
hideClientButton: t.configuration.hideClientButton ?? !1,
showSidebar: t.configuration.showSidebar ?? !0,
theme: t.configuration.theme ?? "none",
layout: t.configuration.layout ?? "modern",
persistAuth: t.configuration.persistAuth ?? !1,
documentDownloadType: t.configuration.documentDownloadType ?? "both",
onBeforeRequest: t.configuration.onBeforeRequest
})), { dereferencedDocument: m, workspaceStore: f, activeEntitiesStore: p } = _({
configuration: o,
dereferencedDocument: t.dereferencedDocument,
originalDocument: t.originalDocument
});
a($, f), a(z, p), U(() => O()), a(V, "modal"), a(
ee,
oe({
plugins: o.value.plugins
})
);
const { isSidebarOpen: h, setCollapsedSidebarItem: v, scrollToOperation: D, items: l } = te(t.store), I = B(() => l.value.entries[0]?.id ?? ""), {
getReferenceId: T,
getPathRoutingId: A,
hash: s,
isIntersectionEnabled: g,
updateHash: w,
replaceUrlState: L
} = X(), M = u(0);
if (o.value.redirect && typeof window < "u") {
const e = o.value.redirect(
(o.value.pathRouting ? window.location.pathname : "") + window.location.hash
);
e && history.replaceState({}, "", e);
}
P(() => {
w(), G();
});
const S = async (e) => {
g.value = !1, w(), e ? D(e) : i.value?.scrollTo(0, 0), await H(100), g.value = !0;
};
k(() => {
history.scrollRestoration = "manual";
const e = i.value?.parentElement?.getBoundingClientRect(), n = i.value?.getBoundingClientRect();
if (e && n) {
const R = n.top - e.top;
M.value = R < 2 ? 0 : R;
}
window.onhashchange = () => {
S(T());
}, window.onpopstate = () => o.value.pathRouting && S(A(window.location.pathname)), window.addEventListener("scroll", y, { passive: !0 });
});
const y = W(() => {
window.scrollY < 50 && J.value && L("");
});
q(() => {
window.removeEventListener("scroll", y);
}), c(
() => t.store.workspace.activeDocument,
() => {
if (s.value) {
const e = l.value.entities.get(s.value), n = e?.parent?.id ?? e?.id;
n && v(n, !0);
} else {
const e = l.value.entries.find((n) => n.type === "tag");
e && v(e.id, !0);
}
}
);
const b = u("100dvh"), i = u(null);
j(i, (e) => {
b.value = e[0] ? e[0].contentRect.height + "px" : "100dvh";
});
const { mediaQueries: E } = K();
return c(E.lg, (e, n) => {
n && !e && (h.value = !1);
}), c(s, (e, n) => {
e && e !== n && (h.value = !1);
}), Z(t.store, f, p, i), (e, n) => (F(), x(N, null, [
Y("main", {
"aria-label": `Open API Documentation for ${r(m)?.info?.title}`,
class: "references-rendered"
}, [
d(r(ne), {
contentId: I.value,
options: {
isLoading: o.value.isLoading,
slug: o.value.slug,
hiddenClients: o.value.hiddenClients,
layout: o.value.layout,
onLoaded: o.value.onLoaded,
persistAuth: o.value.persistAuth,
showOperationId: o.value.showOperationId,
hideTestRequestButton: o.value.hideTestRequestButton,
expandAllResponses: o.value.expandAllResponses,
hideModels: o.value.hideModels,
expandAllModelSections: o.value.expandAllModelSections,
orderRequiredPropertiesFirst: o.value.orderRequiredPropertiesFirst,
orderSchemaPropertiesBy: o.value.orderSchemaPropertiesBy,
documentDownloadType: o.value.documentDownloadType,
url: o.value.url,
onShowMore: o.value.onShowMore
},
store: e.store
}, null, 8, ["contentId", "options", "store"])
], 8, re),
d(r(ie), {
configuration: o.value,
dereferencedDocument: r(m)
}, null, 8, ["configuration", "dereferencedDocument"]),
d(r(Q))
], 64));
}
});
export {
Te as default
};