UNPKG

@scalar/api-client

Version:

the open source API testing client

45 lines (44 loc) 1.15 kB
import { ref as f, computed as n, toValue as t } from "vue"; import { useRoute as h } from "vue-router"; import { getTabDetails as v } from "../../../helpers/get-tab-details.js"; const x = "x-scalar-tabs", y = "x-scalar-active-tab", C = ({ workspaceStore: o, getEntryByLocation: s, workspaceSlug: i, documentSlug: u, path: l, method: p }) => { const b = h(), d = f(!1), a = () => ({ ...v({ workspace: t(i), document: t(u), path: t(l), method: t(p), getEntryByLocation: s }), path: b.path }), r = n(() => o.value?.workspace[x] ?? [a()]), m = n(() => o.value?.workspace[y] ?? 0); return { tabs: r, activeTabIndex: m, copyTabUrl: async (e) => { const c = r.value[e]; if (!c) { console.warn(`Cannot copy URL: tab at index ${e} does not exist`); return; } const T = `${window.location.origin}${c.path}`; try { await navigator.clipboard.writeText(T); } catch (w) { console.error("Failed to copy URL to clipboard:", w); } }, isLoading: d, createTabFromCurrentRoute: a }; }; export { C as useTabs };