UNPKG

@scalar/api-client

Version:

the open source API testing client

128 lines (127 loc) 4.47 kB
import { defineComponent as h, computed as s, ref as S, watch as x, createBlock as g, openBlock as y, unref as t, withCtx as l, createVNode as n, createElementVNode as m, createTextVNode as u, toDisplayString as b, normalizeClass as w } from "vue"; import { ScalarErrorBoundary as B, ScalarCodeBlock as k, ScalarCombobox as V, ScalarButton as T } from "@scalar/components"; import { ScalarIconCaretDown as E } from "@scalar/icons"; import { generateCodeSnippet as N } from "../../operation-code-sample/helpers/generate-code-snippet.js"; import { getClients as D } from "../../operation-code-sample/helpers/get-clients.js"; import { getCustomCodeSamples as O } from "../../operation-code-sample/helpers/get-custom-code-samples.js"; import { getSecrets as z } from "../../operation-code-sample/helpers/get-secrets.js"; import { findClient as f } from "../../operation-code-sample/helpers/find-client.js"; import I from "../../../components/layout/CollapsibleSection.vue.js"; import R from "../../../components/data-table/DataTable.vue.js"; import W from "../../../components/data-table/DataTableRow.vue.js"; const $ = { class: "flex flex-1" }, q = { class: "overflow-hidden" }, Q = /* @__PURE__ */ h({ __name: "RequestCodeSnippet", props: { clientOptions: {}, selectedClient: {}, selectedServer: {}, selectedContentType: {}, selectedExample: {}, securitySchemes: {}, method: {}, path: {}, operation: {}, fallback: { type: Boolean }, generateLabel: { type: Function }, isWebhook: { type: Boolean }, eventBus: {} }, setup(e) { const d = s(() => O(e.operation)), c = s( () => D(d.value, e.clientOptions) ), i = S( f(c.value, e.selectedClient) ); x( () => e.selectedClient, (a) => { const o = f(c.value, a); o && (i.value = o); } ); const p = s(() => z(e.securitySchemes ?? [])), C = (a) => { i.value = a, a && !a.id.startsWith("custom") && e.eventBus.emit("workspace:update:selected-client", a.id); }, v = s( () => N({ clientId: i.value?.id, customCodeSamples: d.value, operation: e.operation, method: e.method, path: e.path, contentType: e.selectedContentType, server: e.selectedServer, securitySchemes: e.securitySchemes, example: e.selectedExample }) ); return (a, o) => (y(), g(t(I), { class: "group/preview w-full border-t", defaultOpen: !1 }, { title: l(() => [...o[1] || (o[1] = [ u("Code Snippet", -1) ])]), actions: l(() => [ m("div", $, [ n(t(V), { modelValue: i.value, options: c.value, placement: "bottom-end", "onUpdate:modelValue": o[0] || (o[0] = (r) => C(r)) }, { default: l(({ open: r }) => [ n(t(T), { class: "text-c-2 hover:text-c-1 flex h-full w-fit gap-1.5 px-0.5 py-0 text-base font-normal", "data-testid": "client-picker", variant: "ghost" }, { default: l(() => [ u(b(i.value?.title) + " ", 1), n(t(E), { class: w(["mt-0.25 size-3 transition-transform duration-100", r && "rotate-180"]), weight: "bold" }, null, 8, ["class"]) ]), _: 2 }, 1024) ]), _: 1 }, 8, ["modelValue", "options"]) ]) ]), default: l(() => [ n(t(B), null, { default: l(() => [ n(t(R), { columns: [""], presentational: "" }, { default: l(() => [ n(t(W), null, { default: l(() => [ m("div", q, [ n(t(k), { class: "text-base -outline-offset-2", content: v.value, hideCredentials: p.value, lang: i.value?.lang ?? "plaintext", lineNumbers: "" }, null, 8, ["content", "hideCredentials", "lang"]) ]) ]), _: 1 }) ]), _: 1 }) ]), _: 1 }) ]), _: 1 })); } }); export { Q as default };