@scalar/blocks 0.1.19 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/dist/code-example/components/CodeExample.vue.d.ts.map +1 -1
- package/dist/code-example/components/CodeExample.vue.js +1 -1
- package/dist/code-example/components/CodeExample.vue.js.map +1 -1
- package/dist/code-example/components/CodeExample.vue.script.js +125 -111
- package/dist/code-example/components/CodeExample.vue.script.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/operation-to-har.js +16 -11
- package/dist/code-example/helpers/operation-to-har/operation-to-har.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-body.js +89 -68
- package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts +2 -0
- package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts.map +1 -1
- package/dist/code-example/helpers/operation-to-har/process-parameters.js +71 -53
- package/dist/code-example/helpers/operation-to-har/process-parameters.js.map +1 -1
- package/dist/code-example/mount.d.ts.map +1 -1
- package/dist/code-example/mount.js +30 -29
- package/dist/code-example/mount.js.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/style.css +1 -1
- package/dist/vue-styles.css +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @scalar/blocks
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#10178](https://github.com/scalar/scalar/pull/10178): Support OpenAPI 3.2 streaming item schemas in the workspace store, request body examples, and API reference schema views. Frame generated and structured examples as JSON Lines, JSON Sequence, or server-sent events while preserving explicit wire-format strings.
|
|
8
|
+
|
|
9
|
+
Preserve generated falsy request examples (`0`, `false`, and empty strings) for non-streaming bodies as well.
|
|
10
|
+
|
|
11
|
+
Use cURL `--data-binary` for supported streaming media types, making framed body handling explicit. Authored arrays and objects are framed as stream records; authored wire-format strings remain unchanged. SSE records with no valid fields are safely omitted with one console warning per serialization call reporting the omitted count, including when all records are omitted.
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#10201](https://github.com/scalar/scalar/pull/10201): Support positional and nested multipart request encoding with prefixEncoding, itemEncoding, and nested encoding objects. Keep generated code snippets in sync with multipart request bodies.
|
|
16
|
+
|
|
17
|
+
Reject ambiguous named positional items and multipart nesting beyond eight levels. Use a stable fallback root for XML parts.
|
|
18
|
+
|
|
19
|
+
Document multipart content-type defaults and wildcard selection policies. Route structured XML parts through a shared adapter while retaining legacy root-name behavior.
|
|
20
|
+
|
|
21
|
+
Regenerate multipart boundaries that collide with resolved text or nested delimiters, keeping binary payload bytes intact.
|
|
22
|
+
|
|
23
|
+
- [#10208](https://github.com/scalar/scalar/pull/10208): Share OpenAPI 3.2 example-value selection across request bodies, response examples, and code snippets. Preserve serialized payloads verbatim, serialize structured JSON strings correctly, retain falsy values, and replace original example sources after body edits. Keep dataValue and serializedValue during document ingestion.
|
|
24
|
+
|
|
25
|
+
Editing a request body, including form fields, discards its authored `externalValue` URL and replaces it with the edited inline value in the workspace and exported API description. Rendering or focusing a form field preserves the external source.
|
|
26
|
+
|
|
27
|
+
Form editors prefer structured `dataValue` when both example fields exist, while raw editors, requests, and code snippets preserve `serializedValue` as wire text. Structured examples now affect generated request payloads and snippets; XML remains raw-only in the request editor.
|
|
28
|
+
|
|
29
|
+
- [#10198](https://github.com/scalar/scalar/pull/10198): Support OpenAPI 3.2 cookie serialization with semicolon-separated entries and no percent-encoding in requests and code examples.
|
|
30
|
+
|
|
31
|
+
Browser XHR and jQuery code examples now set explicit Cookie header values through `document.cookie` and enable credentialed requests, including when no structured HAR cookies are supplied. Run the cookie setup on the request origin. Requests without cookie-style parameters retain structured HAR cookies alongside explicit Cookie headers.
|
|
32
|
+
|
|
33
|
+
Warn once per parameter name in the developer console when cookie-style parameters declare invalid `explode: false`, then use the expanded fallback consistently for requests and snippets. Browser cookie setup cannot assign cookies to an unrelated API domain; credentialed cross-origin responses require the appropriate CORS configuration and eligible stored cookies.
|
|
34
|
+
|
|
35
|
+
## 0.1.20
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- [#10240](https://github.com/scalar/scalar/pull/10240): Load external examples on demand when their selected preview is visible or Test Request opens, instead of downloading every payload while loading the API description. Share and cache downloads, preserve relative URL origins, and show loading and retry states while preventing incomplete requests from being sent.
|
|
40
|
+
|
|
3
41
|
## 0.1.19
|
|
4
42
|
|
|
5
43
|
## 0.1.18
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExample.vue.d.ts","sourceRoot":"","sources":["../../../src/code-example/components/CodeExample.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CodeExample.vue.d.ts","sourceRoot":"","sources":["../../../src/code-example/components/CodeExample.vue"],"names":[],"mappings":"AA4mBA,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAErF,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAUvE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAA;AACzF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACb,MAAM,8DAA8D,CAAA;AAkBrE,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,UAAU,CAAA;AAKjB,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;IACpC;;OAEG;IACH,aAAa,EAAE,iBAAiB,EAAE,CAAA;IAClC;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,cAAc,CAAC,EAAE,YAAY,GAAG,IAAI,CAAA;IACpC;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;OAEG;IACH,QAAQ,EAAE,iBAAiB,CAAA;IAC3B;;OAEG;IACH,eAAe,EAAE,0BAA0B,EAAE,CAAA;IAC7C;;OAEG;IACH,MAAM,EAAE,cAAc,CAAA;IACtB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,SAAS,EAAE,eAAe,CAAA;IAC1B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,MAAM,CAAA;IAC5B;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,aAAa,EAAE,CAAA;IAC/B;;;OAGG;IACH,+BAA+B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACzD,CAAA;AAED;;;;;;;;GAQG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;;;;;YAkCR,MAAM,OAAO;YACb,CAAC,EAAE,WAAW,EAAE,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO;EA4pB3D,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
|
@@ -2,7 +2,7 @@ import e from "./CodeExample.vue.script.js";
|
|
|
2
2
|
/* empty css */
|
|
3
3
|
import t from "../../_virtual/_plugin-vue_export-helper.js";
|
|
4
4
|
//#region src/code-example/components/CodeExample.vue
|
|
5
|
-
var n = /*#__PURE__*/ t(e, [["__scopeId", "data-v-
|
|
5
|
+
var n = /*#__PURE__*/ t(e, [["__scopeId", "data-v-8b0cd212"]]);
|
|
6
6
|
//#endregion
|
|
7
7
|
export { n as default };
|
|
8
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeExample.vue.js","names":[],"sources":["../../../src/code-example/components/CodeExample.vue"],"sourcesContent":["<script lang=\"ts\">\nexport type CodeExampleProps = {\n /**\n * Integration type: determines if the code sample is displayed in a client environment\n * or in an API reference environment.\n */\n integration?: 'client' | 'reference'\n /**\n * List of all http clients formatted into option groups for the client selector\n */\n clientOptions: ClientOptionGroup[]\n /**\n * Pre-selected client, this will determine which client is initially selected in the dropdown.\n * Either a built-in client id (e.g. `js/fetch`) or a custom sample id (e.g. `custom/python`).\n *\n * Typed as a plain string: unioning the (large) client-id union with the `custom/...`\n * ids overflows TypeScript's union-complexity limit inside this component's `defineProps`.\n *\n * @defaults to a custom sample if one is available, otherwise shell/curl\n */\n selectedClient?: string\n /**\n * Which server from the spec to use for the code example\n */\n selectedServer?: ServerObject | null\n /**\n * The selected content type from the requestBody.content, this will determine which examples are available\n * as well as the content type of the code example\n *\n * @defaults to the first content type if not provided\n */\n selectedContentType?: string\n /**\n * Example name to use for resolving example values for parameters AND requestBody.\n *\n * This is the document-wide selection: it is honored only when this operation defines an example\n * with the same key, so picking an example on one operation syncs the rest without blanking out\n * operations that do not share that key.\n *\n * @example \"limited\"\n * ```ts\n * parameters: {\n * name: 'foobar',\n * in: 'query',\n * examples: {\n * limited: {\n * dataValue: 10,\n * }\n * }\n * },\n * body: {\n * content: {\n * 'application/json': {\n * examples: {\n * limited: {\n * dataValue: { foo: 'bar' },\n * }\n * }\n * }\n * }\n * }\n *\n * ```\n */\n selectedExample?: string\n /**\n * Event bus\n */\n eventBus: WorkspaceEventBus\n /**\n * The security schemes which are applicable to this operation\n */\n securitySchemes: SecuritySchemeObjectSecret[]\n /**\n * HTTP method of the operation\n */\n method: HttpMethodType\n /**\n * Path of the operation\n */\n path: string\n /**\n * De-referenced OpenAPI Operation object\n */\n operation: OperationObject\n /**\n * If true and there's no example, we will display a small card with the method and path only\n */\n fallback?: boolean\n /**\n * A method to generate the label of the block, should return an html string\n */\n generateLabel?: () => string\n /**\n * If true, render this as a webhook request example\n */\n isWebhook?: boolean\n /**\n * Workspace + document cookies\n */\n globalCookies?: XScalarCookie[]\n /**\n * When the request body schema uses oneOf/anyOf, use these selected variants\n * for the example snippet (e.g. from the schema dropdowns in the API reference).\n */\n requestBodyCompositionSelection?: Record<string, number>\n}\n\n/**\n * Request Example\n *\n * The core component for rendering a request example block,\n * this component does not have much of its own state but operates on props and custom events\n *\n * @event workspace:update:selected-client - Emitted when the selected client changes\n * @event workspace:update:selected-example - Emitted when the selected example changes, so other operations can sync\n */\nexport default {}\n</script>\n\n<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport {\n ScalarCard,\n ScalarCardFooter,\n ScalarCardHeader,\n ScalarCardSection,\n} from '@scalar/components/card'\nimport { ScalarCodeBlock } from '@scalar/components/code-block'\nimport { ScalarCombobox } from '@scalar/components/combobox'\nimport { ScalarVirtualText } from '@scalar/components/virtual-text'\nimport { freezeElement } from '@scalar/helpers/dom/freeze-element'\nimport type { HttpMethod as HttpMethodType } from '@scalar/helpers/http/http-methods'\nimport { ScalarIconCaretDown } from '@scalar/icons'\nimport { type WorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type {\n OperationObject,\n ServerObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport {\n computed,\n onBeforeMount,\n ref,\n useId,\n watch,\n watchEffect,\n type ComponentPublicInstance,\n} from 'vue'\n\nimport { filterClientsByQuery } from '../helpers/filter-clients-by-query'\nimport { findClient } from '../helpers/find-client'\nimport { generateCodeSnippet } from '../helpers/generate-code-snippet'\nimport { getClients } from '../helpers/get-clients'\nimport { getCustomCodeSamples } from '../helpers/get-custom-code-samples'\nimport { getSecrets } from '../helpers/get-secrets'\nimport { operationToHar } from '../helpers/operation-to-har/operation-to-har'\nimport type {\n ClientOption,\n ClientOptionGroup,\n CustomClientOption,\n} from '../types'\nimport ExamplePicker from './ExamplePicker.vue'\nimport HttpMethod from './HttpMethod.vue'\n\nconst {\n integration,\n clientOptions,\n selectedClient,\n selectedServer = null,\n selectedContentType,\n selectedExample,\n securitySchemes = [],\n method,\n eventBus,\n path,\n operation,\n isWebhook,\n generateLabel,\n globalCookies,\n requestBodyCompositionSelection,\n} = defineProps<CodeExampleProps>()\n\nconst emit = defineEmits<{\n /**\n * Emitted whenever the example key actually shown for this operation changes.\n *\n * This is the resolved local key (not the raw document-wide selection), so layouts that render\n * the test-request button outside this component can open the client with the same example the\n * snippet displays.\n */\n (e: 'update:exampleKey', value: string): void\n}>()\n\ndefineSlots<{\n header: () => unknown\n footer: ({ exampleName }: { exampleName: string }) => unknown\n}>()\n\n/** Grab the examples for the given content type */\nconst requestBodyExamples = computed(() => {\n const content = getResolvedRef(operation.requestBody)?.content ?? {}\n const contentType = selectedContentType || Object.keys(content)[0]\n if (!contentType) return {}\n\n const examples = content[contentType]?.examples ?? {}\n\n return examples\n})\n\n/**\n * The example key actually shown for this operation.\n *\n * `selectedExample` is the document-wide selection that syncs across operations. We honor it only\n * when this operation actually defines that key, otherwise we keep the local example: a selection\n * on one operation should never blank out an operation that does not share the same example.\n */\nconst localExampleKey = ref('')\n\n/** Resolve the key to display, preferring the document-wide selection when this operation has it */\nconst resolveExampleKey = (preferred: string | undefined): string => {\n const keys = Object.keys(requestBodyExamples.value)\n if (preferred && keys.includes(preferred)) {\n return preferred\n }\n // Keep the current local example when it is still valid, otherwise fall back to the first one\n if (localExampleKey.value && keys.includes(localExampleKey.value)) {\n return localExampleKey.value\n }\n return keys[0] ?? ''\n}\n\n// Set the initial example from the document-wide selection, falling back to the first example\nonBeforeMount(() => {\n localExampleKey.value = resolveExampleKey(selectedExample)\n})\n\n// Follow the document-wide selection when it changes and this operation has that example\nwatch(\n () => selectedExample,\n (preferred) => {\n localExampleKey.value = resolveExampleKey(preferred)\n },\n)\n\n/** Reset the selected example key if the content type changes and the new content type doesn't have the previously selected example */\nwatch(\n () => selectedContentType,\n () => {\n if (\n !Object.keys(requestBodyExamples.value).includes(localExampleKey.value)\n ) {\n // Re-resolve so the new content type still follows the document-wide selection when it has\n // that key, instead of always snapping back to the first example\n localExampleKey.value = resolveExampleKey(selectedExample)\n }\n },\n)\n\n// Keep the parent informed of the resolved key so a test-request button rendered outside this\n// component (e.g. the classic layout header) opens the client with the example the snippet shows\nwatchEffect(() => {\n emit('update:exampleKey', localExampleKey.value)\n})\n\n/** Select an example locally and sync the choice across the document */\nconst selectExample = (key: string) => {\n localExampleKey.value = key\n eventBus.emit('workspace:update:selected-example', key)\n}\n\n/** Grab any custom code samples from the operation */\nconst customCodeSamples = computed(() => getCustomCodeSamples(operation))\n\n/** Merge custom code samples with the client options */\nconst clients = computed(() =>\n getClients(\n customCodeSamples.value.samples,\n clientOptions,\n customCodeSamples.value.label,\n ),\n)\n\n/** Total number of available clients across all option groups */\nconst clientCount = computed(() =>\n clients.value.reduce((total, group) => total + group.options.length, 0),\n)\n\n/** The locally selected client which would include code samples from this operation only */\nconst localSelectedClient = ref<ClientOption | CustomClientOption | undefined>(\n findClient(clients.value, selectedClient),\n)\n\n/**\n * Re-resolve the local client whenever the global selection or the available\n * clients change. Watching `clients` matters when navigating between operations:\n * the stored id stays the same, but the matching option (e.g. a custom sample)\n * differs per operation, so without this the snippet could go stale.\n */\nwatch([() => selectedClient, clients], ([newClient]) => {\n const client = findClient(clients.value, newClient)\n if (client) {\n localSelectedClient.value = client\n }\n})\n\n/** Generate HAR data for webhook requests */\nconst webhookHar = computed(() => {\n if (!isWebhook) return null\n\n try {\n return operationToHar({\n operation,\n method,\n path,\n example: localExampleKey.value,\n requestBodyCompositionSelection,\n // Only required parameters are shown in code examples; optional parameters\n // are omitted unless explicitly enabled via `x-disabled: false`.\n defaultDisabledParameters: true,\n })\n } catch (error) {\n console.error('[webhookHar]', error)\n return null\n }\n})\n\n/** Generate the code snippet for the selected example */\nconst generatedCode = computed<string>(() => {\n if (isWebhook) {\n return webhookHar.value?.postData?.text ?? ''\n }\n\n return generateCodeSnippet({\n // Only required parameters are shown in code examples; optional parameters\n // are omitted unless explicitly enabled via `x-disabled: false`.\n defaultDisabledParameters: true,\n includeDefaultHeaders: integration === 'client',\n clientId: localSelectedClient.value?.id,\n customCodeSamples: customCodeSamples.value.samples,\n operation,\n method,\n path,\n contentType: selectedContentType,\n server: selectedServer,\n securitySchemes,\n example: localExampleKey.value,\n globalCookies,\n requestBodyCompositionSelection,\n })\n})\n\n/** The language for the code block, used for syntax highlighting */\nconst codeBlockLanguage = computed(() => {\n if (isWebhook) {\n return webhookLanguage.value\n }\n\n return localSelectedClient.value?.lang\n})\n\n/** Determine the language for webhook content based on MIME type */\nconst webhookLanguage = computed<string>(() => {\n if (!webhookHar.value?.postData) return 'json'\n\n const contentType = webhookHar.value.postData.mimeType\n if (contentType?.includes('json')) return 'json'\n if (contentType?.includes('xml')) return 'xml'\n if (contentType?.includes('yaml') || contentType?.includes('yml'))\n return 'yaml'\n if (contentType?.includes('text/plain')) return 'text'\n\n return 'json'\n})\n\n/** Block secrets from being shown in the code block */\nconst secretCredentials = computed(() => getSecrets(securitySchemes))\n\n/** Grab the ref to freeze the ui as the clients change so there's no jump as the size of the dom changes */\nconst elem = ref<ComponentPublicInstance | null>(null)\n\n/** Set custom example, or update the selected HTTP client globally */\nconst selectClient = (option: ClientOption) => {\n // We need to freeze the ui to prevent scrolling as the clients change\n if (elem.value) {\n const unfreeze = freezeElement(elem.value.$el)\n setTimeout(() => {\n unfreeze()\n }, 300)\n }\n // Update to the local example\n localSelectedClient.value = option\n\n // Sync the selection globally so other operations follow along. Custom samples\n // sync too (keyed by language), so picking e.g. the Python SDK example here\n // shows the Python example on every operation that ships one.\n if (option) {\n eventBus.emit('workspace:update:selected-client', option.id)\n }\n}\n\n// Virtualize the code block if it's too large\n// This prevents the entire app from freezing up if there's a massive example\n// We set a lower threshold here as code examples can get quite large\nconst VIRTUALIZATION_THRESHOLD = 20_000\n\nconst shouldVirtualize = computed(\n () => (generatedCode.value.length ?? 0) > VIRTUALIZATION_THRESHOLD,\n)\n\nconst id = useId()\n</script>\n<template>\n <ScalarCard\n v-if=\"generatedCode\"\n ref=\"elem\"\n class=\"request-card dark-mode\">\n <!-- Header -->\n <ScalarCardHeader class=\"pr-2.5\">\n <span class=\"sr-only\">Request Example for</span>\n <HttpMethod\n as=\"span\"\n class=\"request-method\"\n :method=\"method\" />\n <span\n v-if=\"generateLabel\"\n v-html=\"generateLabel()\" />\n <slot name=\"header\" />\n <!-- Client picker -->\n <template\n v-if=\"!isWebhook && clientCount\"\n #actions>\n <!-- Multiple clients: render a dropdown to switch between them -->\n <ScalarCombobox\n v-if=\"clientCount > 1\"\n class=\"max-h-80\"\n :filterFn=\"filterClientsByQuery\"\n :modelValue=\"localSelectedClient\"\n :options=\"clients\"\n placement=\"bottom-end\"\n teleport\n @update:modelValue=\"selectClient($event as ClientOption)\">\n <ScalarButton\n 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\"\n data-testid=\"client-picker\"\n variant=\"ghost\">\n {{ localSelectedClient?.title }}\n <ScalarIconCaretDown\n class=\"ui-open:rotate-180 mt-px size-3 transition-transform duration-100\"\n weight=\"bold\" />\n </ScalarButton>\n </ScalarCombobox>\n <!-- Single client: just show its label, no need for a dropdown -->\n <span\n v-else\n class=\"text-c-2 flex h-full w-fit items-center px-0.5 py-0 text-base font-normal\"\n data-testid=\"client-picker\">\n {{ localSelectedClient?.title }}\n </span>\n </template>\n </ScalarCardHeader>\n\n <!-- Code snippet -->\n <ScalarCardSection class=\"request-editor-section custom-scroll p-0\">\n <div\n :id=\"`${id}-example`\"\n class=\"code-snippet\">\n <ScalarCodeBlock\n v-if=\"!shouldVirtualize\"\n class=\"bg-b-2 h-full\"\n :content=\"generatedCode\"\n :hideCredentials=\"secretCredentials\"\n :lang=\"codeBlockLanguage\"\n lineNumbers />\n <ScalarVirtualText\n v-else\n containerClass=\"custom-scroll scalar-code-block border rounded-b flex flex-1 max-h-screen\"\n contentClass=\"language-plaintext whitespace-pre font-code text-base p-2\"\n :lineHeight=\"20\"\n :text=\"generatedCode\" />\n </div>\n </ScalarCardSection>\n\n <!-- Footer -->\n <ScalarCardFooter\n v-if=\"Object.keys(requestBodyExamples).length > 1 || $slots.footer\"\n class=\"request-card-footer bg-b-3\">\n <!-- Example picker -->\n <div\n v-if=\"Object.keys(requestBodyExamples).length > 1\"\n class=\"request-card-footer-addon\">\n <template v-if=\"Object.keys(requestBodyExamples).length\">\n <ExamplePicker\n :examples=\"requestBodyExamples\"\n :modelValue=\"localExampleKey\"\n @update:modelValue=\"selectExample\" />\n </template>\n </div>\n\n <!-- Footer -->\n <slot\n :exampleName=\"localExampleKey\"\n name=\"footer\" />\n </ScalarCardFooter>\n </ScalarCard>\n\n <!-- Fallback card with just method and path in the case of no examples -->\n <ScalarCard\n v-else-if=\"fallback\"\n class=\"request-card dark-mode\">\n <ScalarCardSection class=\"request-card-simple\">\n <div class=\"request-header\">\n <HttpMethod\n as=\"span\"\n class=\"request-method\"\n :method=\"method\" />\n <slot name=\"header\" />\n </div>\n <slot\n :exampleName=\"localExampleKey\"\n name=\"footer\" />\n </ScalarCardSection>\n </ScalarCard>\n</template>\n<style scoped>\n.request-card {\n color: var(--scalar-color-1);\n font-size: var(--scalar-font-size-3);\n}\n.request-method {\n font-family: var(--scalar-font-code);\n text-transform: uppercase;\n margin-right: 6px;\n}\n.request-card-footer {\n display: flex;\n justify-content: flex-end;\n padding: 6px;\n flex-shrink: 0;\n position: relative;\n}\n.request-card-footer-addon {\n display: flex;\n align-items: center;\n\n flex: 1;\n min-width: 0;\n}\n.request-editor-section {\n display: flex;\n flex: 1;\n}\n.request-card-simple {\n display: flex;\n align-items: center;\n justify-content: space-between;\n\n padding: 8px 8px 8px 12px;\n\n font-size: var(--scalar-small);\n}\n.code-snippet {\n display: flex;\n flex-direction: column;\n width: 100%;\n}\n</style>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"CodeExample.vue.js","names":[],"sources":["../../../src/code-example/components/CodeExample.vue"],"sourcesContent":["<script lang=\"ts\">\nexport type CodeExampleProps = {\n /**\n * Integration type: determines if the code sample is displayed in a client environment\n * or in an API reference environment.\n */\n integration?: 'client' | 'reference'\n /**\n * List of all http clients formatted into option groups for the client selector\n */\n clientOptions: ClientOptionGroup[]\n /**\n * Pre-selected client, this will determine which client is initially selected in the dropdown.\n * Either a built-in client id (e.g. `js/fetch`) or a custom sample id (e.g. `custom/python`).\n *\n * Typed as a plain string: unioning the (large) client-id union with the `custom/...`\n * ids overflows TypeScript's union-complexity limit inside this component's `defineProps`.\n *\n * @defaults to a custom sample if one is available, otherwise shell/curl\n */\n selectedClient?: string\n /**\n * Which server from the spec to use for the code example\n */\n selectedServer?: ServerObject | null\n /**\n * The selected content type from the requestBody.content, this will determine which examples are available\n * as well as the content type of the code example\n *\n * @defaults to the first content type if not provided\n */\n selectedContentType?: string\n /**\n * Example name to use for resolving example values for parameters AND requestBody.\n *\n * This is the document-wide selection: it is honored only when this operation defines an example\n * with the same key, so picking an example on one operation syncs the rest without blanking out\n * operations that do not share that key.\n *\n * @example \"limited\"\n * ```ts\n * parameters: {\n * name: 'foobar',\n * in: 'query',\n * examples: {\n * limited: {\n * dataValue: 10,\n * }\n * }\n * },\n * body: {\n * content: {\n * 'application/json': {\n * examples: {\n * limited: {\n * dataValue: { foo: 'bar' },\n * }\n * }\n * }\n * }\n * }\n *\n * ```\n */\n selectedExample?: string\n /**\n * Event bus\n */\n eventBus: WorkspaceEventBus\n /**\n * The security schemes which are applicable to this operation\n */\n securitySchemes: SecuritySchemeObjectSecret[]\n /**\n * HTTP method of the operation\n */\n method: HttpMethodType\n /**\n * Path of the operation\n */\n path: string\n /**\n * De-referenced OpenAPI Operation object\n */\n operation: OperationObject\n /**\n * If true and there's no example, we will display a small card with the method and path only\n */\n fallback?: boolean\n /**\n * A method to generate the label of the block, should return an html string\n */\n generateLabel?: () => string\n /**\n * If true, render this as a webhook request example\n */\n isWebhook?: boolean\n /**\n * Workspace + document cookies\n */\n globalCookies?: XScalarCookie[]\n /**\n * When the request body schema uses oneOf/anyOf, use these selected variants\n * for the example snippet (e.g. from the schema dropdowns in the API reference).\n */\n requestBodyCompositionSelection?: Record<string, number>\n}\n\n/**\n * Request Example\n *\n * The core component for rendering a request example block,\n * this component does not have much of its own state but operates on props and custom events\n *\n * @event workspace:update:selected-client - Emitted when the selected client changes\n * @event workspace:update:selected-example - Emitted when the selected example changes, so other operations can sync\n */\nexport default {}\n</script>\n\n<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport {\n ScalarCard,\n ScalarCardFooter,\n ScalarCardHeader,\n ScalarCardSection,\n} from '@scalar/components/card'\nimport { ScalarCodeBlock } from '@scalar/components/code-block'\nimport { ScalarCombobox } from '@scalar/components/combobox'\nimport { ScalarVirtualText } from '@scalar/components/virtual-text'\nimport { freezeElement } from '@scalar/helpers/dom/freeze-element'\nimport type { HttpMethod as HttpMethodType } from '@scalar/helpers/http/http-methods'\nimport { ScalarIconCaretDown } from '@scalar/icons'\nimport { type WorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport {\n getOperationExamples,\n resolveOperationExamples,\n} from '@scalar/workspace-store/helpers/operation-examples'\nimport {\n useExampleVisibility,\n useExternalExamples,\n} from '@scalar/workspace-store/helpers/use-external-examples'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { XScalarCookie } from '@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies'\nimport type {\n OperationObject,\n ServerObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport {\n computed,\n onBeforeMount,\n ref,\n useId,\n watch,\n watchEffect,\n type ComponentPublicInstance,\n} from 'vue'\n\nimport { filterClientsByQuery } from '../helpers/filter-clients-by-query'\nimport { findClient } from '../helpers/find-client'\nimport { generateCodeSnippet } from '../helpers/generate-code-snippet'\nimport { getClients } from '../helpers/get-clients'\nimport { getCustomCodeSamples } from '../helpers/get-custom-code-samples'\nimport { getSecrets } from '../helpers/get-secrets'\nimport { operationToHar } from '../helpers/operation-to-har/operation-to-har'\nimport type {\n ClientOption,\n ClientOptionGroup,\n CustomClientOption,\n} from '../types'\nimport ExamplePicker from './ExamplePicker.vue'\nimport HttpMethod from './HttpMethod.vue'\n\nconst {\n integration,\n clientOptions,\n selectedClient,\n selectedServer = null,\n selectedContentType,\n selectedExample,\n securitySchemes = [],\n method,\n eventBus,\n path,\n operation,\n isWebhook,\n generateLabel,\n globalCookies,\n requestBodyCompositionSelection,\n} = defineProps<CodeExampleProps>()\n\nconst emit = defineEmits<{\n /**\n * Emitted whenever the example key actually shown for this operation changes.\n *\n * This is the resolved local key (not the raw document-wide selection), so layouts that render\n * the test-request button outside this component can open the client with the same example the\n * snippet displays.\n */\n (e: 'update:exampleKey', value: string): void\n}>()\n\ndefineSlots<{\n header: () => unknown\n footer: ({ exampleName }: { exampleName: string }) => unknown\n}>()\n\n/** Grab the examples for the given content type */\nconst requestBodyExamples = computed(() => {\n const content = getResolvedRef(operation.requestBody)?.content ?? {}\n const contentType = selectedContentType || Object.keys(content)[0]\n if (!contentType) return {}\n\n const examples = content[contentType]?.examples ?? {}\n\n return examples\n})\n\n/**\n * The example key actually shown for this operation.\n *\n * `selectedExample` is the document-wide selection that syncs across operations. We honor it only\n * when this operation actually defines that key, otherwise we keep the local example: a selection\n * on one operation should never blank out an operation that does not share the same example.\n */\nconst localExampleKey = ref('')\n\n/** Resolve the key to display, preferring the document-wide selection when this operation has it */\nconst resolveExampleKey = (preferred: string | undefined): string => {\n const keys = Object.keys(requestBodyExamples.value)\n if (preferred && keys.includes(preferred)) {\n return preferred\n }\n // Keep the current local example when it is still valid, otherwise fall back to the first one\n if (localExampleKey.value && keys.includes(localExampleKey.value)) {\n return localExampleKey.value\n }\n return keys[0] ?? ''\n}\n\n// Set the initial example from the document-wide selection, falling back to the first example\nonBeforeMount(() => {\n localExampleKey.value = resolveExampleKey(selectedExample)\n})\n\n// Follow the document-wide selection when it changes and this operation has that example\nwatch(\n () => selectedExample,\n (preferred) => {\n localExampleKey.value = resolveExampleKey(preferred)\n },\n)\n\n/** Reset the selected example key if the content type changes and the new content type doesn't have the previously selected example */\nwatch(\n () => selectedContentType,\n () => {\n if (\n !Object.keys(requestBodyExamples.value).includes(localExampleKey.value)\n ) {\n // Re-resolve so the new content type still follows the document-wide selection when it has\n // that key, instead of always snapping back to the first example\n localExampleKey.value = resolveExampleKey(selectedExample)\n }\n },\n)\n\n// Keep the parent informed of the resolved key so a test-request button rendered outside this\n// component (e.g. the classic layout header) opens the client with the example the snippet shows\nwatchEffect(() => {\n emit('update:exampleKey', localExampleKey.value)\n})\n\n/** Select an example locally and sync the choice across the document */\nconst selectExample = (key: string) => {\n localExampleKey.value = key\n eventBus.emit('workspace:update:selected-example', key)\n}\n\n/** Grab any custom code samples from the operation */\nconst customCodeSamples = computed(() => getCustomCodeSamples(operation))\n\n/** Merge custom code samples with the client options */\nconst clients = computed(() =>\n getClients(\n customCodeSamples.value.samples,\n clientOptions,\n customCodeSamples.value.label,\n ),\n)\n\n/** Total number of available clients across all option groups */\nconst clientCount = computed(() =>\n clients.value.reduce((total, group) => total + group.options.length, 0),\n)\n\n/** The locally selected client which would include code samples from this operation only */\nconst localSelectedClient = ref<ClientOption | CustomClientOption | undefined>(\n findClient(clients.value, selectedClient),\n)\n\n/**\n * Re-resolve the local client whenever the global selection or the available\n * clients change. Watching `clients` matters when navigating between operations:\n * the stored id stays the same, but the matching option (e.g. a custom sample)\n * differs per operation, so without this the snippet could go stale.\n */\nwatch([() => selectedClient, clients], ([newClient]) => {\n const client = findClient(clients.value, newClient)\n if (client) {\n localSelectedClient.value = client\n }\n})\n\nconst elem = ref<ComponentPublicInstance | null>(null)\nconst visible = useExampleVisibility(elem)\nconst externalExamples = useExternalExamples(\n () =>\n getOperationExamples(operation, localExampleKey.value, selectedContentType),\n () => visible.value,\n)\nconst resolvedOperation = computed(() =>\n resolveOperationExamples(\n operation,\n localExampleKey.value,\n selectedContentType,\n externalExamples.resolve,\n ),\n)\n\n/** Generate HAR data for webhook requests */\nconst webhookHar = computed(() => {\n if (!isWebhook) return null\n\n try {\n return operationToHar({\n operation: resolvedOperation.value,\n method,\n path,\n example: localExampleKey.value,\n requestBodyCompositionSelection,\n // Only required parameters are shown in code examples; optional parameters\n // are omitted unless explicitly enabled via `x-disabled: false`.\n defaultDisabledParameters: true,\n })\n } catch (error) {\n console.error('[webhookHar]', error)\n return null\n }\n})\n\n/** Generate the code snippet for the selected example */\nconst generatedCode = computed<string>(() => {\n if (isWebhook) {\n return webhookHar.value?.postData?.text ?? ''\n }\n\n return generateCodeSnippet({\n // Only required parameters are shown in code examples; optional parameters\n // are omitted unless explicitly enabled via `x-disabled: false`.\n defaultDisabledParameters: true,\n includeDefaultHeaders: integration === 'client',\n clientId: localSelectedClient.value?.id,\n customCodeSamples: customCodeSamples.value.samples,\n operation: resolvedOperation.value,\n method,\n path,\n contentType: selectedContentType,\n server: selectedServer,\n securitySchemes,\n example: localExampleKey.value,\n globalCookies,\n requestBodyCompositionSelection,\n })\n})\n\n/** The language for the code block, used for syntax highlighting */\nconst codeBlockLanguage = computed(() => {\n if (isWebhook) {\n return webhookLanguage.value\n }\n\n return localSelectedClient.value?.lang\n})\n\n/** Determine the language for webhook content based on MIME type */\nconst webhookLanguage = computed<string>(() => {\n if (!webhookHar.value?.postData) return 'json'\n\n const contentType = webhookHar.value.postData.mimeType\n if (contentType?.includes('json')) return 'json'\n if (contentType?.includes('xml')) return 'xml'\n if (contentType?.includes('yaml') || contentType?.includes('yml'))\n return 'yaml'\n if (contentType?.includes('text/plain')) return 'text'\n\n return 'json'\n})\n\n/** Block secrets from being shown in the code block */\nconst secretCredentials = computed(() => getSecrets(securitySchemes))\n\n/** Set custom example, or update the selected HTTP client globally */\nconst selectClient = (option: ClientOption) => {\n // We need to freeze the ui to prevent scrolling as the clients change\n if (elem.value) {\n const unfreeze = freezeElement(elem.value.$el)\n setTimeout(() => {\n unfreeze()\n }, 300)\n }\n // Update to the local example\n localSelectedClient.value = option\n\n // Sync the selection globally so other operations follow along. Custom samples\n // sync too (keyed by language), so picking e.g. the Python SDK example here\n // shows the Python example on every operation that ships one.\n if (option) {\n eventBus.emit('workspace:update:selected-client', option.id)\n }\n}\n\n// Virtualize the code block if it's too large\n// This prevents the entire app from freezing up if there's a massive example\n// We set a lower threshold here as code examples can get quite large\nconst VIRTUALIZATION_THRESHOLD = 20_000\n\nconst shouldVirtualize = computed(\n () => (generatedCode.value.length ?? 0) > VIRTUALIZATION_THRESHOLD,\n)\n\nconst id = useId()\n</script>\n<template>\n <ScalarCard\n v-if=\"generatedCode || externalExamples.pending.value\"\n ref=\"elem\"\n class=\"request-card dark-mode\">\n <!-- Header -->\n <ScalarCardHeader class=\"pr-2.5\">\n <span class=\"sr-only\">Request Example for</span>\n <HttpMethod\n as=\"span\"\n class=\"request-method\"\n :method=\"method\" />\n <span\n v-if=\"generateLabel\"\n v-html=\"generateLabel()\" />\n <slot name=\"header\" />\n <!-- Client picker -->\n <template\n v-if=\"!isWebhook && clientCount\"\n #actions>\n <!-- Multiple clients: render a dropdown to switch between them -->\n <ScalarCombobox\n v-if=\"clientCount > 1\"\n class=\"max-h-80\"\n :filterFn=\"filterClientsByQuery\"\n :modelValue=\"localSelectedClient\"\n :options=\"clients\"\n placement=\"bottom-end\"\n teleport\n @update:modelValue=\"selectClient($event as ClientOption)\">\n <ScalarButton\n 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\"\n data-testid=\"client-picker\"\n variant=\"ghost\">\n {{ localSelectedClient?.title }}\n <ScalarIconCaretDown\n class=\"ui-open:rotate-180 mt-px size-3 transition-transform duration-100\"\n weight=\"bold\" />\n </ScalarButton>\n </ScalarCombobox>\n <!-- Single client: just show its label, no need for a dropdown -->\n <span\n v-else\n class=\"text-c-2 flex h-full w-fit items-center px-0.5 py-0 text-base font-normal\"\n data-testid=\"client-picker\">\n {{ localSelectedClient?.title }}\n </span>\n </template>\n </ScalarCardHeader>\n\n <!-- Code snippet -->\n <ScalarCardSection class=\"request-editor-section custom-scroll p-0\">\n <div\n v-if=\"externalExamples.pending.value\"\n class=\"text-c-2 p-4\"\n role=\"status\">\n <template v-if=\"externalExamples.failed.value\">\n Could not load this example.\n <ScalarButton\n size=\"sm\"\n variant=\"ghost\"\n @click=\"externalExamples.retry\">\n Retry\n </ScalarButton>\n </template>\n <template v-else>Loading example…</template>\n </div>\n <div\n v-else\n :id=\"`${id}-example`\"\n class=\"code-snippet\">\n <ScalarCodeBlock\n v-if=\"!shouldVirtualize\"\n class=\"bg-b-2 h-full\"\n :content=\"generatedCode\"\n :hideCredentials=\"secretCredentials\"\n :lang=\"codeBlockLanguage\"\n lineNumbers />\n <ScalarVirtualText\n v-else\n containerClass=\"custom-scroll scalar-code-block border rounded-b flex flex-1 max-h-screen\"\n contentClass=\"language-plaintext whitespace-pre font-code text-base p-2\"\n :lineHeight=\"20\"\n :text=\"generatedCode\" />\n </div>\n </ScalarCardSection>\n\n <!-- Footer -->\n <ScalarCardFooter\n v-if=\"Object.keys(requestBodyExamples).length > 1 || $slots.footer\"\n class=\"request-card-footer bg-b-3\">\n <!-- Example picker -->\n <div\n v-if=\"Object.keys(requestBodyExamples).length > 1\"\n class=\"request-card-footer-addon\">\n <template v-if=\"Object.keys(requestBodyExamples).length\">\n <ExamplePicker\n :examples=\"requestBodyExamples\"\n :modelValue=\"localExampleKey\"\n @update:modelValue=\"selectExample\" />\n </template>\n </div>\n\n <!-- Footer -->\n <slot\n :exampleName=\"localExampleKey\"\n name=\"footer\" />\n </ScalarCardFooter>\n </ScalarCard>\n\n <!-- Fallback card with just method and path in the case of no examples -->\n <ScalarCard\n v-else-if=\"fallback\"\n class=\"request-card dark-mode\">\n <ScalarCardSection class=\"request-card-simple\">\n <div class=\"request-header\">\n <HttpMethod\n as=\"span\"\n class=\"request-method\"\n :method=\"method\" />\n <slot name=\"header\" />\n </div>\n <slot\n :exampleName=\"localExampleKey\"\n name=\"footer\" />\n </ScalarCardSection>\n </ScalarCard>\n</template>\n<style scoped>\n.request-card {\n color: var(--scalar-color-1);\n font-size: var(--scalar-font-size-3);\n}\n.request-method {\n font-family: var(--scalar-font-code);\n text-transform: uppercase;\n margin-right: 6px;\n}\n.request-card-footer {\n display: flex;\n justify-content: flex-end;\n padding: 6px;\n flex-shrink: 0;\n position: relative;\n}\n.request-card-footer-addon {\n display: flex;\n align-items: center;\n\n flex: 1;\n min-width: 0;\n}\n.request-editor-section {\n display: flex;\n flex: 1;\n}\n.request-card-simple {\n display: flex;\n align-items: center;\n justify-content: space-between;\n\n padding: 8px 8px 8px 12px;\n\n font-size: var(--scalar-small);\n}\n.code-snippet {\n display: flex;\n flex-direction: column;\n width: 100%;\n}\n</style>\n"],"mappings":""}
|
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import { filterClientsByQuery as e } from "../helpers/filter-clients-by-query.js";
|
|
2
2
|
import { findClient as t } from "../helpers/find-client.js";
|
|
3
3
|
import { operationToHar as n } from "../helpers/operation-to-har/operation-to-har.js";
|
|
4
|
-
import { generateCodeSnippet as
|
|
5
|
-
import { getCustomCodeSamples as
|
|
6
|
-
import { getClients as
|
|
7
|
-
import { getSecrets as
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import { computed as
|
|
11
|
-
import { ScalarButton as
|
|
12
|
-
import { ScalarCard as
|
|
13
|
-
import { ScalarCodeBlock as
|
|
14
|
-
import { ScalarCombobox as
|
|
15
|
-
import { ScalarVirtualText as
|
|
16
|
-
import { freezeElement as
|
|
17
|
-
import { ScalarIconCaretDown as
|
|
18
|
-
import { getResolvedRef as
|
|
4
|
+
import { generateCodeSnippet as ee } from "../helpers/generate-code-snippet.js";
|
|
5
|
+
import { getCustomCodeSamples as te } from "../helpers/get-custom-code-samples.js";
|
|
6
|
+
import { getClients as r } from "../helpers/get-clients.js";
|
|
7
|
+
import { getSecrets as i } from "../helpers/get-secrets.js";
|
|
8
|
+
import ne from "./ExamplePicker.vue.js";
|
|
9
|
+
import a from "./HttpMethod.vue.js";
|
|
10
|
+
import { Fragment as o, computed as s, createBlock as c, createCommentVNode as l, createElementBlock as u, createElementVNode as d, createSlots as re, createTextVNode as f, createVNode as p, defineComponent as m, onBeforeMount as ie, openBlock as h, ref as g, renderSlot as _, toDisplayString as v, unref as y, useId as b, watch as x, watchEffect as S, withCtx as C } from "vue";
|
|
11
|
+
import { ScalarButton as w } from "@scalar/components/button";
|
|
12
|
+
import { ScalarCard as T, ScalarCardFooter as ae, ScalarCardHeader as oe, ScalarCardSection as E } from "@scalar/components/card";
|
|
13
|
+
import { ScalarCodeBlock as se } from "@scalar/components/code-block";
|
|
14
|
+
import { ScalarCombobox as ce } from "@scalar/components/combobox";
|
|
15
|
+
import { ScalarVirtualText as le } from "@scalar/components/virtual-text";
|
|
16
|
+
import { freezeElement as D } from "@scalar/helpers/dom/freeze-element";
|
|
17
|
+
import { ScalarIconCaretDown as O } from "@scalar/icons";
|
|
18
|
+
import { getResolvedRef as k } from "@scalar/workspace-store/helpers/get-resolved-ref";
|
|
19
|
+
import { getOperationExamples as A, resolveOperationExamples as j } from "@scalar/workspace-store/helpers/operation-examples";
|
|
20
|
+
import { useExampleVisibility as M, useExternalExamples as N } from "@scalar/workspace-store/helpers/use-external-examples";
|
|
19
21
|
//#region src/code-example/components/CodeExample.vue?vue&type=script&setup=true&lang.ts
|
|
20
|
-
var
|
|
22
|
+
var P = ["innerHTML"], F = {
|
|
21
23
|
key: 1,
|
|
22
24
|
class: "text-c-2 flex h-full w-fit items-center px-0.5 py-0 text-base font-normal",
|
|
23
25
|
"data-testid": "client-picker"
|
|
24
|
-
},
|
|
26
|
+
}, I = {
|
|
27
|
+
key: 0,
|
|
28
|
+
class: "text-c-2 p-4",
|
|
29
|
+
role: "status"
|
|
30
|
+
}, L = ["id"], R = {
|
|
25
31
|
key: 0,
|
|
26
32
|
class: "request-card-footer-addon"
|
|
27
|
-
},
|
|
33
|
+
}, z = { class: "request-header" }, B = /*@__PURE__*/ m({
|
|
28
34
|
__name: "CodeExample",
|
|
29
35
|
props: {
|
|
30
36
|
integration: {},
|
|
@@ -45,111 +51,111 @@ var I = ["innerHTML"], L = {
|
|
|
45
51
|
requestBodyCompositionSelection: {}
|
|
46
52
|
},
|
|
47
53
|
emits: ["update:exampleKey"],
|
|
48
|
-
setup(
|
|
49
|
-
let
|
|
50
|
-
let e =
|
|
54
|
+
setup(m, { emit: B }) {
|
|
55
|
+
let V = B, H = s(() => {
|
|
56
|
+
let e = k(m.operation.requestBody)?.content ?? {}, t = m.selectedContentType || Object.keys(e)[0];
|
|
51
57
|
return t ? e[t]?.examples ?? {} : {};
|
|
52
|
-
}),
|
|
53
|
-
let t = Object.keys(
|
|
54
|
-
return e && t.includes(e) ? e :
|
|
58
|
+
}), U = g(""), W = (e) => {
|
|
59
|
+
let t = Object.keys(H.value);
|
|
60
|
+
return e && t.includes(e) ? e : U.value && t.includes(U.value) ? U.value : t[0] ?? "";
|
|
55
61
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}),
|
|
59
|
-
|
|
60
|
-
}),
|
|
61
|
-
Object.keys(
|
|
62
|
-
}),
|
|
63
|
-
|
|
62
|
+
ie(() => {
|
|
63
|
+
U.value = W(m.selectedExample);
|
|
64
|
+
}), x(() => m.selectedExample, (e) => {
|
|
65
|
+
U.value = W(e);
|
|
66
|
+
}), x(() => m.selectedContentType, () => {
|
|
67
|
+
Object.keys(H.value).includes(U.value) || (U.value = W(m.selectedExample));
|
|
68
|
+
}), S(() => {
|
|
69
|
+
V("update:exampleKey", U.value);
|
|
64
70
|
});
|
|
65
|
-
let
|
|
66
|
-
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
let n = t(
|
|
70
|
-
n && (
|
|
71
|
+
let ue = (e) => {
|
|
72
|
+
U.value = e, m.eventBus.emit("workspace:update:selected-example", e);
|
|
73
|
+
}, G = s(() => te(m.operation)), K = s(() => r(G.value.samples, m.clientOptions, G.value.label)), q = s(() => K.value.reduce((e, t) => e + t.options.length, 0)), J = g(t(K.value, m.selectedClient));
|
|
74
|
+
x([() => m.selectedClient, K], ([e]) => {
|
|
75
|
+
let n = t(K.value, e);
|
|
76
|
+
n && (J.value = n);
|
|
71
77
|
});
|
|
72
|
-
let Z =
|
|
73
|
-
if (!
|
|
78
|
+
let Y = g(null), de = M(Y), X = N(() => A(m.operation, U.value, m.selectedContentType), () => de.value), Z = s(() => j(m.operation, U.value, m.selectedContentType, X.resolve)), Q = s(() => {
|
|
79
|
+
if (!m.isWebhook) return null;
|
|
74
80
|
try {
|
|
75
81
|
return n({
|
|
76
|
-
operation:
|
|
77
|
-
method:
|
|
78
|
-
path:
|
|
79
|
-
example:
|
|
80
|
-
requestBodyCompositionSelection:
|
|
82
|
+
operation: Z.value,
|
|
83
|
+
method: m.method,
|
|
84
|
+
path: m.path,
|
|
85
|
+
example: U.value,
|
|
86
|
+
requestBodyCompositionSelection: m.requestBodyCompositionSelection,
|
|
81
87
|
defaultDisabledParameters: !0
|
|
82
88
|
});
|
|
83
89
|
} catch (e) {
|
|
84
90
|
return console.error("[webhookHar]", e), null;
|
|
85
91
|
}
|
|
86
|
-
}),
|
|
92
|
+
}), $ = s(() => m.isWebhook ? Q.value?.postData?.text ?? "" : ee({
|
|
87
93
|
defaultDisabledParameters: !0,
|
|
88
|
-
includeDefaultHeaders:
|
|
89
|
-
clientId:
|
|
90
|
-
customCodeSamples:
|
|
91
|
-
operation:
|
|
92
|
-
method:
|
|
93
|
-
path:
|
|
94
|
-
contentType:
|
|
95
|
-
server:
|
|
96
|
-
securitySchemes:
|
|
97
|
-
example:
|
|
98
|
-
globalCookies:
|
|
99
|
-
requestBodyCompositionSelection:
|
|
100
|
-
})),
|
|
101
|
-
if (!
|
|
102
|
-
let e =
|
|
94
|
+
includeDefaultHeaders: m.integration === "client",
|
|
95
|
+
clientId: J.value?.id,
|
|
96
|
+
customCodeSamples: G.value.samples,
|
|
97
|
+
operation: Z.value,
|
|
98
|
+
method: m.method,
|
|
99
|
+
path: m.path,
|
|
100
|
+
contentType: m.selectedContentType,
|
|
101
|
+
server: m.selectedServer,
|
|
102
|
+
securitySchemes: m.securitySchemes,
|
|
103
|
+
example: U.value,
|
|
104
|
+
globalCookies: m.globalCookies,
|
|
105
|
+
requestBodyCompositionSelection: m.requestBodyCompositionSelection
|
|
106
|
+
})), fe = s(() => m.isWebhook ? pe.value : J.value?.lang), pe = s(() => {
|
|
107
|
+
if (!Q.value?.postData) return "json";
|
|
108
|
+
let e = Q.value.postData.mimeType;
|
|
103
109
|
return e?.includes("json") ? "json" : e?.includes("xml") ? "xml" : e?.includes("yaml") || e?.includes("yml") ? "yaml" : e?.includes("text/plain") ? "text" : "json";
|
|
104
|
-
}),
|
|
105
|
-
if (
|
|
106
|
-
let e =
|
|
110
|
+
}), me = s(() => i(m.securitySchemes)), he = (e) => {
|
|
111
|
+
if (Y.value) {
|
|
112
|
+
let e = D(Y.value.$el);
|
|
107
113
|
setTimeout(() => {
|
|
108
114
|
e();
|
|
109
115
|
}, 300);
|
|
110
116
|
}
|
|
111
|
-
|
|
112
|
-
},
|
|
113
|
-
return (t, n) =>
|
|
117
|
+
J.value = e, e && m.eventBus.emit("workspace:update:selected-client", e.id);
|
|
118
|
+
}, ge = s(() => ($.value.length ?? 0) > 2e4), _e = b();
|
|
119
|
+
return (t, n) => $.value || y(X).pending.value ? (h(), c(y(T), {
|
|
114
120
|
key: 0,
|
|
115
121
|
ref_key: "elem",
|
|
116
|
-
ref:
|
|
122
|
+
ref: Y,
|
|
117
123
|
class: "request-card dark-mode"
|
|
118
124
|
}, {
|
|
119
|
-
default:
|
|
120
|
-
|
|
121
|
-
default:
|
|
122
|
-
n[1] ||=
|
|
123
|
-
|
|
125
|
+
default: C(() => [
|
|
126
|
+
p(y(oe), { class: "pr-2.5" }, re({
|
|
127
|
+
default: C(() => [
|
|
128
|
+
n[1] ||= d("span", { class: "sr-only" }, "Request Example for", -1),
|
|
129
|
+
p(a, {
|
|
124
130
|
as: "span",
|
|
125
131
|
class: "request-method",
|
|
126
|
-
method:
|
|
132
|
+
method: m.method
|
|
127
133
|
}, null, 8, ["method"]),
|
|
128
|
-
|
|
134
|
+
m.generateLabel ? (h(), u("span", {
|
|
129
135
|
key: 0,
|
|
130
|
-
innerHTML:
|
|
131
|
-
}, null, 8,
|
|
132
|
-
|
|
136
|
+
innerHTML: m.generateLabel()
|
|
137
|
+
}, null, 8, P)) : l("", !0),
|
|
138
|
+
_(t.$slots, "header", {}, void 0, !0)
|
|
133
139
|
]),
|
|
134
140
|
_: 2
|
|
135
|
-
}, [!
|
|
141
|
+
}, [!m.isWebhook && q.value ? {
|
|
136
142
|
name: "actions",
|
|
137
|
-
fn:
|
|
143
|
+
fn: C(() => [q.value > 1 ? (h(), c(y(ce), {
|
|
138
144
|
key: 0,
|
|
139
145
|
class: "max-h-80",
|
|
140
|
-
filterFn:
|
|
141
|
-
modelValue:
|
|
142
|
-
options:
|
|
146
|
+
filterFn: y(e),
|
|
147
|
+
modelValue: J.value,
|
|
148
|
+
options: K.value,
|
|
143
149
|
placement: "bottom-end",
|
|
144
150
|
teleport: "",
|
|
145
|
-
"onUpdate:modelValue": n[0] ||= (e) =>
|
|
151
|
+
"onUpdate:modelValue": n[0] ||= (e) => he(e)
|
|
146
152
|
}, {
|
|
147
|
-
default:
|
|
153
|
+
default: C(() => [p(y(w), {
|
|
148
154
|
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",
|
|
149
155
|
"data-testid": "client-picker",
|
|
150
156
|
variant: "ghost"
|
|
151
157
|
}, {
|
|
152
|
-
default:
|
|
158
|
+
default: C(() => [f(v(J.value?.title) + " ", 1), p(y(O), {
|
|
153
159
|
class: "ui-open:rotate-180 mt-px size-3 transition-transform duration-100",
|
|
154
160
|
weight: "bold"
|
|
155
161
|
})]),
|
|
@@ -160,64 +166,72 @@ var I = ["innerHTML"], L = {
|
|
|
160
166
|
"filterFn",
|
|
161
167
|
"modelValue",
|
|
162
168
|
"options"
|
|
163
|
-
])) : (
|
|
169
|
+
])) : (h(), u("span", F, v(J.value?.title), 1))]),
|
|
164
170
|
key: "0"
|
|
165
171
|
} : void 0]), 1024),
|
|
166
|
-
|
|
167
|
-
default:
|
|
168
|
-
|
|
172
|
+
p(y(E), { class: "request-editor-section custom-scroll p-0" }, {
|
|
173
|
+
default: C(() => [y(X).pending.value ? (h(), u("div", I, [y(X).failed.value ? (h(), u(o, { key: 0 }, [n[3] ||= f(" Could not load this example. ", -1), p(y(w), {
|
|
174
|
+
size: "sm",
|
|
175
|
+
variant: "ghost",
|
|
176
|
+
onClick: y(X).retry
|
|
177
|
+
}, {
|
|
178
|
+
default: C(() => [...n[2] ||= [f(" Retry ", -1)]]),
|
|
179
|
+
_: 1
|
|
180
|
+
}, 8, ["onClick"])], 64)) : (h(), u(o, { key: 1 }, [f("Loading example…")], 64))])) : (h(), u("div", {
|
|
181
|
+
key: 1,
|
|
182
|
+
id: `${y(_e)}-example`,
|
|
169
183
|
class: "code-snippet"
|
|
170
|
-
}, [
|
|
184
|
+
}, [ge.value ? (h(), c(y(le), {
|
|
171
185
|
key: 1,
|
|
172
186
|
containerClass: "custom-scroll scalar-code-block border rounded-b flex flex-1 max-h-screen",
|
|
173
187
|
contentClass: "language-plaintext whitespace-pre font-code text-base p-2",
|
|
174
188
|
lineHeight: 20,
|
|
175
|
-
text:
|
|
176
|
-
}, null, 8, ["text"])) : (
|
|
189
|
+
text: $.value
|
|
190
|
+
}, null, 8, ["text"])) : (h(), c(y(se), {
|
|
177
191
|
key: 0,
|
|
178
192
|
class: "bg-b-2 h-full",
|
|
179
|
-
content:
|
|
180
|
-
hideCredentials:
|
|
181
|
-
lang:
|
|
193
|
+
content: $.value,
|
|
194
|
+
hideCredentials: me.value,
|
|
195
|
+
lang: fe.value,
|
|
182
196
|
lineNumbers: ""
|
|
183
197
|
}, null, 8, [
|
|
184
198
|
"content",
|
|
185
199
|
"hideCredentials",
|
|
186
200
|
"lang"
|
|
187
|
-
]))], 8,
|
|
201
|
+
]))], 8, L))]),
|
|
188
202
|
_: 1
|
|
189
203
|
}),
|
|
190
|
-
Object.keys(
|
|
204
|
+
Object.keys(H.value).length > 1 || t.$slots.footer ? (h(), c(y(ae), {
|
|
191
205
|
key: 0,
|
|
192
206
|
class: "request-card-footer bg-b-3"
|
|
193
207
|
}, {
|
|
194
|
-
default:
|
|
208
|
+
default: C(() => [Object.keys(H.value).length > 1 ? (h(), u("div", R, [Object.keys(H.value).length ? (h(), c(ne, {
|
|
195
209
|
key: 0,
|
|
196
|
-
examples:
|
|
197
|
-
modelValue:
|
|
198
|
-
"onUpdate:modelValue":
|
|
199
|
-
}, null, 8, ["examples", "modelValue"])) :
|
|
210
|
+
examples: H.value,
|
|
211
|
+
modelValue: U.value,
|
|
212
|
+
"onUpdate:modelValue": ue
|
|
213
|
+
}, null, 8, ["examples", "modelValue"])) : l("", !0)])) : l("", !0), _(t.$slots, "footer", { exampleName: U.value }, void 0, !0)]),
|
|
200
214
|
_: 3
|
|
201
|
-
})) :
|
|
215
|
+
})) : l("", !0)
|
|
202
216
|
]),
|
|
203
217
|
_: 3
|
|
204
|
-
}, 512)) :
|
|
218
|
+
}, 512)) : m.fallback ? (h(), c(y(T), {
|
|
205
219
|
key: 1,
|
|
206
220
|
class: "request-card dark-mode"
|
|
207
221
|
}, {
|
|
208
|
-
default:
|
|
209
|
-
default:
|
|
222
|
+
default: C(() => [p(y(E), { class: "request-card-simple" }, {
|
|
223
|
+
default: C(() => [d("div", z, [p(a, {
|
|
210
224
|
as: "span",
|
|
211
225
|
class: "request-method",
|
|
212
|
-
method:
|
|
213
|
-
}, null, 8, ["method"]),
|
|
226
|
+
method: m.method
|
|
227
|
+
}, null, 8, ["method"]), _(t.$slots, "header", {}, void 0, !0)]), _(t.$slots, "footer", { exampleName: U.value }, void 0, !0)]),
|
|
214
228
|
_: 3
|
|
215
229
|
})]),
|
|
216
230
|
_: 3
|
|
217
|
-
})) :
|
|
231
|
+
})) : l("", !0);
|
|
218
232
|
}
|
|
219
233
|
});
|
|
220
234
|
//#endregion
|
|
221
|
-
export {
|
|
235
|
+
export { B as default };
|
|
222
236
|
|
|
223
237
|
//# sourceMappingURL=CodeExample.vue.script.js.map
|