@scalar/api-client
Version:
the open source API testing client
66 lines (65 loc) • 1.93 kB
JavaScript
import { useModal as M } from "@scalar/components";
import { reactive as b, computed as t, createApp as P } from "vue";
import { resolveRouteParameters as A } from "./resolve-route-parameters.js";
import { useModalSidebar as C } from "../hooks/use-modal-sidebar.js";
import I from "../Modal.vue.js";
const N = ({
el: f,
workspaceStore: a,
mountOnInitialize: v = !0,
plugins: h
}) => {
const r = {
path: "default",
method: "default",
example: "default",
documentSlug: a.workspace["x-scalar-active-document"] || "default"
}, m = b({ ...r }), c = (e) => {
Object.assign(m, r, e);
}, o = t(() => A(a, m)), s = t(() => o.value.documentSlug), u = t(() => o.value.path), d = t(() => o.value.method), i = t(() => o.value.example), g = t(() => a.workspace.documents[s.value ?? ""] ?? null), x = C({
workspaceStore: a,
documentSlug: s,
path: u,
method: d,
exampleName: i,
route: c
}), l = M(), n = P(I, {
workspaceStore: a,
document: g,
modalState: l,
sidebarState: x,
path: u,
method: d,
exampleName: i,
plugins: h
});
n.config.idPrefix = "scalar-client";
const p = (e = f) => {
if (!e) {
console.error(
"[@scalar/api-client] Could not create the API client Modal.",
"Invalid HTML element provided.",
"Read more: https://github.com/scalar/scalar/tree/main/packages/api-client"
);
return;
}
n.mount(e);
};
return v && p(), {
/** The Vue app instance for the modal. Use with caution. */
app: n,
/** Open the modal and optionally navigate to a specific route. */
open: (e) => {
l.open = !0, e && c(e);
},
/** Mount the modal to a given element. */
mount: p,
/** Navigate to the specified path, method, and example. */
route: c,
/** Controls the visibility of the modal. */
modalState: l
};
};
export {
N as createApiClientModal
};