UNPKG

@scalar/api-reference

Version:

Generate beautiful API references from OpenAPI documents

59 lines (58 loc) 1.84 kB
import { defineComponent as l, mergeModels as d, useModel as m, createBlock as f, openBlock as p, unref as c, withCtx as g, renderSlot as k, createTextVNode as w, nextTick as v } from "vue"; import { useLoadingState as R, ScalarButton as L } from "@scalar/components"; import { useToasts as x } from "@scalar/use-toasts"; import { DASHBOARD_REGISTER_URL as S } from "../../consts/urls.js"; import { uploadTempDocument as T } from "./uploadTempDocument.js"; const U = /* @__PURE__ */ l({ __name: "ApiReferenceToolbarRegisterButton", props: /* @__PURE__ */ d({ workspace: {}, sdks: { default: () => [] } }, { url: {}, urlModifiers: {} }), emits: ["update:url"], setup(o) { const a = m(o, "url"), { toast: s } = x(), t = R(); function i(r) { const e = new URL(S); e.searchParams.set("url", r), o.sdks.forEach((n) => e.searchParams.append("sdk", n)), window.open(e.toString(), "_blank"); } async function u() { if (t.isLoading || !o.workspace) return; if (a.value) { i(a.value); return; } t.startLoading(); const r = o.workspace.exportActiveDocument("json"); if (!r) { s("Unable to export active document", "error"), t.invalidate(); return; } try { a.value = await T(r), await t.validate(600), i(a.value), await v(), t.clear(); } catch (e) { const n = e instanceof Error ? e.message : "An unknown error occurred"; s(n, "error"), t.invalidate(); } } return (r, e) => (p(), f(c(L), { class: "h-auto p-2.5", loading: c(t), onClick: u }, { default: g(() => [ k(r.$slots, "default", {}, () => [ e[0] || (e[0] = w("Generate")) ]) ]), _: 3 }, 8, ["loading"])); } }); export { U as default };