@scalar/blocks 0.1.19 → 0.1.20

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scalar/blocks
2
2
 
3
+ ## 0.1.20
4
+
5
+ ### Patch Changes
6
+
7
+ - [#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.
8
+
3
9
  ## 0.1.19
4
10
 
5
11
  ## 0.1.18
@@ -1 +1 @@
1
- {"version":3,"file":"CodeExample.vue.d.ts","sourceRoot":"","sources":["../../../src/code-example/components/CodeExample.vue"],"names":[],"mappings":"AAukBA,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAErF,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAEvE,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;EAwmB3D,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
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;AAC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,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-82b2d155"]]);
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 r } from "../helpers/generate-code-snippet.js";
5
- import { getCustomCodeSamples as i } from "../helpers/get-custom-code-samples.js";
6
- import { getClients as a } from "../helpers/get-clients.js";
7
- import { getSecrets as o } from "../helpers/get-secrets.js";
8
- import s from "./ExamplePicker.vue.js";
9
- import c from "./HttpMethod.vue.js";
10
- import { computed as l, createBlock as u, createCommentVNode as d, createElementBlock as f, createElementVNode as p, createSlots as m, createTextVNode as h, createVNode as g, defineComponent as _, onBeforeMount as ee, openBlock as v, ref as y, renderSlot as b, toDisplayString as x, unref as S, useId as C, watch as w, watchEffect as T, withCtx as E } from "vue";
11
- import { ScalarButton as D } from "@scalar/components/button";
12
- import { ScalarCard as O, ScalarCardFooter as te, ScalarCardHeader as ne, ScalarCardSection as k } from "@scalar/components/card";
13
- import { ScalarCodeBlock as A } from "@scalar/components/code-block";
14
- import { ScalarCombobox as j } from "@scalar/components/combobox";
15
- import { ScalarVirtualText as M } from "@scalar/components/virtual-text";
16
- import { freezeElement as N } from "@scalar/helpers/dom/freeze-element";
17
- import { ScalarIconCaretDown as P } from "@scalar/icons";
18
- import { getResolvedRef as F } from "@scalar/workspace-store/helpers/get-resolved-ref";
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 I = ["innerHTML"], L = {
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
- }, R = ["id"], z = {
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
- }, B = { class: "request-header" }, V = /*@__PURE__*/ _({
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(_, { emit: V }) {
49
- let H = V, U = l(() => {
50
- let e = F(_.operation.requestBody)?.content ?? {}, t = _.selectedContentType || Object.keys(e)[0];
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
- }), W = y(""), G = (e) => {
53
- let t = Object.keys(U.value);
54
- return e && t.includes(e) ? e : W.value && t.includes(W.value) ? W.value : t[0] ?? "";
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
- ee(() => {
57
- W.value = G(_.selectedExample);
58
- }), w(() => _.selectedExample, (e) => {
59
- W.value = G(e);
60
- }), w(() => _.selectedContentType, () => {
61
- Object.keys(U.value).includes(W.value) || (W.value = G(_.selectedExample));
62
- }), T(() => {
63
- H("update:exampleKey", W.value);
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 K = (e) => {
66
- W.value = e, _.eventBus.emit("workspace:update:selected-example", e);
67
- }, q = l(() => i(_.operation)), J = l(() => a(q.value.samples, _.clientOptions, q.value.label)), Y = l(() => J.value.reduce((e, t) => e + t.options.length, 0)), X = y(t(J.value, _.selectedClient));
68
- w([() => _.selectedClient, J], ([e]) => {
69
- let n = t(J.value, e);
70
- n && (X.value = 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 = l(() => {
73
- if (!_.isWebhook) return null;
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: _.operation,
77
- method: _.method,
78
- path: _.path,
79
- example: W.value,
80
- requestBodyCompositionSelection: _.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
- }), Q = l(() => _.isWebhook ? Z.value?.postData?.text ?? "" : r({
92
+ }), $ = s(() => m.isWebhook ? Q.value?.postData?.text ?? "" : ee({
87
93
  defaultDisabledParameters: !0,
88
- includeDefaultHeaders: _.integration === "client",
89
- clientId: X.value?.id,
90
- customCodeSamples: q.value.samples,
91
- operation: _.operation,
92
- method: _.method,
93
- path: _.path,
94
- contentType: _.selectedContentType,
95
- server: _.selectedServer,
96
- securitySchemes: _.securitySchemes,
97
- example: W.value,
98
- globalCookies: _.globalCookies,
99
- requestBodyCompositionSelection: _.requestBodyCompositionSelection
100
- })), re = l(() => _.isWebhook ? ie.value : X.value?.lang), ie = l(() => {
101
- if (!Z.value?.postData) return "json";
102
- let e = Z.value.postData.mimeType;
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
- }), ae = l(() => o(_.securitySchemes)), $ = y(null), oe = (e) => {
105
- if ($.value) {
106
- let e = N($.value.$el);
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
- X.value = e, e && _.eventBus.emit("workspace:update:selected-client", e.id);
112
- }, se = l(() => (Q.value.length ?? 0) > 2e4), ce = C();
113
- return (t, n) => Q.value ? (v(), u(S(O), {
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: E(() => [
120
- g(S(ne), { class: "pr-2.5" }, m({
121
- default: E(() => [
122
- n[1] ||= p("span", { class: "sr-only" }, "Request Example for", -1),
123
- g(c, {
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: _.method
132
+ method: m.method
127
133
  }, null, 8, ["method"]),
128
- _.generateLabel ? (v(), f("span", {
134
+ m.generateLabel ? (h(), u("span", {
129
135
  key: 0,
130
- innerHTML: _.generateLabel()
131
- }, null, 8, I)) : d("", !0),
132
- b(t.$slots, "header", {}, void 0, !0)
136
+ innerHTML: m.generateLabel()
137
+ }, null, 8, P)) : l("", !0),
138
+ _(t.$slots, "header", {}, void 0, !0)
133
139
  ]),
134
140
  _: 2
135
- }, [!_.isWebhook && Y.value ? {
141
+ }, [!m.isWebhook && q.value ? {
136
142
  name: "actions",
137
- fn: E(() => [Y.value > 1 ? (v(), u(S(j), {
143
+ fn: C(() => [q.value > 1 ? (h(), c(y(ce), {
138
144
  key: 0,
139
145
  class: "max-h-80",
140
- filterFn: S(e),
141
- modelValue: X.value,
142
- options: J.value,
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) => oe(e)
151
+ "onUpdate:modelValue": n[0] ||= (e) => he(e)
146
152
  }, {
147
- default: E(() => [g(S(D), {
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: E(() => [h(x(X.value?.title) + " ", 1), g(S(P), {
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
- ])) : (v(), f("span", L, x(X.value?.title), 1))]),
169
+ ])) : (h(), u("span", F, v(J.value?.title), 1))]),
164
170
  key: "0"
165
171
  } : void 0]), 1024),
166
- g(S(k), { class: "request-editor-section custom-scroll p-0" }, {
167
- default: E(() => [p("div", {
168
- id: `${S(ce)}-example`,
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
- }, [se.value ? (v(), u(S(M), {
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: Q.value
176
- }, null, 8, ["text"])) : (v(), u(S(A), {
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: Q.value,
180
- hideCredentials: ae.value,
181
- lang: re.value,
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, R)]),
201
+ ]))], 8, L))]),
188
202
  _: 1
189
203
  }),
190
- Object.keys(U.value).length > 1 || t.$slots.footer ? (v(), u(S(te), {
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: E(() => [Object.keys(U.value).length > 1 ? (v(), f("div", z, [Object.keys(U.value).length ? (v(), u(s, {
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: U.value,
197
- modelValue: W.value,
198
- "onUpdate:modelValue": K
199
- }, null, 8, ["examples", "modelValue"])) : d("", !0)])) : d("", !0), b(t.$slots, "footer", { exampleName: W.value }, void 0, !0)]),
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
- })) : d("", !0)
215
+ })) : l("", !0)
202
216
  ]),
203
217
  _: 3
204
- }, 512)) : _.fallback ? (v(), u(S(O), {
218
+ }, 512)) : m.fallback ? (h(), c(y(T), {
205
219
  key: 1,
206
220
  class: "request-card dark-mode"
207
221
  }, {
208
- default: E(() => [g(S(k), { class: "request-card-simple" }, {
209
- default: E(() => [p("div", B, [g(c, {
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: _.method
213
- }, null, 8, ["method"]), b(t.$slots, "header", {}, void 0, !0)]), b(t.$slots, "footer", { exampleName: W.value }, void 0, !0)]),
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
- })) : d("", !0);
231
+ })) : l("", !0);
218
232
  }
219
233
  });
220
234
  //#endregion
221
- export { V as default };
235
+ export { B as default };
222
236
 
223
237
  //# sourceMappingURL=CodeExample.vue.script.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeExample.vue.script.js","names":["$slots"],"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyLA,IAAM,IAAO,GAiBP,IAAsB,QAAe;GACzC,IAAM,IAAU,EAAe,EAAA,UAAU,WAAW,CAAC,EAAE,WAAW,CAAC,GAC7D,IAAc,EAAA,uBAAuB,OAAO,KAAK,CAAO,CAAC,CAAC;GAKhE,OAJK,IAEY,EAAQ,EAAY,EAAE,YAAY,CAAC,IAF3B,CAAC;EAK5B,CAAC,GASK,IAAkB,EAAI,EAAE,GAGxB,KAAqB,MAA0C;GACnE,IAAM,IAAO,OAAO,KAAK,EAAoB,KAAK;GAQlD,OAPI,KAAa,EAAK,SAAS,CAAS,IAC/B,IAGL,EAAgB,SAAS,EAAK,SAAS,EAAgB,KAAK,IACvD,EAAgB,QAElB,EAAK,MAAM;EACpB;EA+BA,AA5BA,SAAoB;GAClB,EAAgB,QAAQ,EAAkB,EAAA,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,KAAK,EAAA,KAAmB,CAAA,CAAE,UAAA,EAAA,GAC/C,EAGuC,GAAA;;MAFpC,UAAU,EAAA;MACV,YAAY,EAAA;MACZ,uBAAmB;0EAK1B,EAEkB,EAAA,QAAA,UAAA,EADf,aAAa,EAAA,MAAe,GAAA,KAAA,GAAA,EAAA,CAAA,CAAA;;;;;aAOtB,EAAA,YAAA,EAAA,GADb,EAea,EAAA,CAAA,GAAA;;GAbX,OAAM;;oBAYc,CAXpB,EAWoB,EAAA,CAAA,GAAA,EAXD,OAAM,sBAAqB,GAAA;qBAOtC,CANN,EAMM,OANN,GAMM,CALJ,EAGqB,GAAA;KAFnB,IAAG;KACH,OAAM;KACL,QAAQ,EAAA;6BACX,EAAsB,EAAA,QAAA,UAAA,CAAA,GAAA,KAAA,GAAA,EAAA,CAAA,CAAA,GAExB,EAEkB,EAAA,QAAA,UAAA,EADf,aAAa,EAAA,MAAe,GAAA,KAAA,GAAA,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"CodeExample.vue.script.js","names":["$slots"],"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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,IAAI,WAAW,GAAG,MAAM,EAAE,SAAS,wBAAwB;;;CAsI5F,CAAA"}
@@ -3,59 +3,60 @@ import t from "./components/CodeExample.vue.js";
3
3
  import { createApp as n, h as r, reactive as i } from "vue";
4
4
  import { createWorkspaceEventBus as a } from "@scalar/workspace-store/events";
5
5
  import { getResolvedRef as o } from "@scalar/workspace-store/helpers/get-resolved-ref";
6
- import { ScalarTeleportRoot as s } from "@scalar/components/teleport";
7
- import { getFirstServer as c } from "@scalar/workspace-store/helpers/get-first-server";
8
- import { generateClientMutators as l } from "@scalar/workspace-store/mutators";
6
+ import { EXTERNAL_EXAMPLES as s } from "@scalar/workspace-store/helpers/use-external-examples";
7
+ import { ScalarTeleportRoot as c } from "@scalar/components/teleport";
8
+ import { getFirstServer as l } from "@scalar/workspace-store/helpers/get-first-server";
9
+ import { generateClientMutators as u } from "@scalar/workspace-store/mutators";
9
10
  //#region src/code-example/mount.ts
10
- var u = (e) => ["scalar-app", e === !0 ? "dark-mode" : e === !1 ? "light-mode" : ""].filter(Boolean).join(" "), d = (d, f) => {
11
- let p = typeof d == "string" ? document.querySelector(d) : d;
12
- if (!p) throw Error(`Element not found: ${d}`);
13
- let m = a(), h = e(), g = l(f.store), _ = m.on("workspace:update:selected-client", (e) => g.workspace().workspace.updateSelectedClient(e)), v = m.on("workspace:update:selected-example", (e) => g.workspace().workspace.updateSelectedExample(e)), y = () => {
14
- let e = f.store.workspace.activeDocument;
11
+ var d = (e) => ["scalar-app", e === !0 ? "dark-mode" : e === !1 ? "light-mode" : ""].filter(Boolean).join(" "), f = (f, p) => {
12
+ let m = typeof f == "string" ? document.querySelector(f) : f;
13
+ if (!m) throw Error(`Element not found: ${f}`);
14
+ let h = a(), g = e(), _ = u(p.store), v = h.on("workspace:update:selected-client", (e) => _.workspace().workspace.updateSelectedClient(e)), y = h.on("workspace:update:selected-example", (e) => _.workspace().workspace.updateSelectedExample(e)), b = () => {
15
+ let e = p.store.workspace.activeDocument;
15
16
  if (!e || !("paths" in e)) return;
16
- let t = o(e.paths?.[f.path]), n = o(t?.[f.method]);
17
+ let t = o(e.paths?.[p.path]), n = o(t?.[p.method]);
17
18
  if (n) return {
18
19
  operation: n,
19
- server: c(n.servers ?? null, t?.servers ?? null, e.servers ?? null)
20
+ server: l(n.servers ?? null, t?.servers ?? null, e.servers ?? null)
20
21
  };
21
22
  };
22
- if (!y()) throw Error(`Operation not found: ${f.method.toUpperCase()} ${f.path}`);
23
- let b, x = () => {
24
- let e = y();
25
- return e && (b = e), e ?? b;
26
- }, S = i({
23
+ if (!b()) throw Error(`Operation not found: ${p.method.toUpperCase()} ${p.path}`);
24
+ let x, S = () => {
25
+ let e = b();
26
+ return e && (x = e), e ?? x;
27
+ }, C = i({
27
28
  get operation() {
28
- return x().operation;
29
+ return S().operation;
29
30
  },
30
31
  get method() {
31
- return f.method;
32
+ return p.method;
32
33
  },
33
34
  get path() {
34
- return f.path;
35
+ return p.path;
35
36
  },
36
- clientOptions: h,
37
- eventBus: m,
37
+ clientOptions: g,
38
+ eventBus: h,
38
39
  get securitySchemes() {
39
- return f.securitySchemes ?? [];
40
+ return p.securitySchemes ?? [];
40
41
  },
41
42
  get selectedClient() {
42
- return f.store.workspace["x-scalar-default-client"] ?? f.selectedClient;
43
+ return p.store.workspace["x-scalar-default-client"] ?? p.selectedClient;
43
44
  },
44
45
  get selectedExample() {
45
- return f.store.workspace["x-scalar-default-example"] ?? f.selectedExample;
46
+ return p.store.workspace["x-scalar-default-example"] ?? p.selectedExample;
46
47
  },
47
48
  get selectedServer() {
48
- return f.selectedServer === void 0 ? x().server : f.selectedServer;
49
+ return p.selectedServer === void 0 ? S().server : p.selectedServer;
49
50
  }
50
- }), C = () => r("span", { class: "font-code text-c-2 min-w-0 truncate" }, f.path), w = n(() => r("div", { class: u(f.darkMode) }, [r(s, null, { default: () => r(t, S, { header: C }) })]));
51
- return w.mount(p), {
52
- app: w,
51
+ }), w = () => r("span", { class: "font-code text-c-2 min-w-0 truncate" }, p.path), T = n(() => r("div", { class: d(p.darkMode) }, [r(c, null, { default: () => r(t, C, { header: w }) })]));
52
+ return T.provide(s, () => p.store.externalExamples()), T.mount(m), {
53
+ app: T,
53
54
  destroy: () => {
54
- _(), v(), w.unmount();
55
+ v(), y(), T.unmount();
55
56
  }
56
57
  };
57
58
  };
58
59
  //#endregion
59
- export { d as createCodeExample };
60
+ export { f as createCodeExample };
60
61
 
61
62
  //# sourceMappingURL=mount.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mount.js","names":[],"sources":["../../src/code-example/mount.ts"],"sourcesContent":["import { ScalarTeleportRoot } from '@scalar/components/teleport'\nimport type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { AvailableClients } from '@scalar/snippetz'\nimport type { WorkspaceStore } from '@scalar/workspace-store/client'\nimport { createWorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { getFirstServer } from '@scalar/workspace-store/helpers/get-first-server'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { generateClientMutators } from '@scalar/workspace-store/mutators'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { createApp, h, reactive } from 'vue'\n\nimport CodeExample, { type CodeExampleProps } from './components/CodeExample.vue'\nimport { generateClientOptions } from './helpers/generate-client-options'\n\nexport type CreateCodeExampleOptions = {\n /** Workspace store that holds the OpenAPI document(s) to render from. */\n store: WorkspaceStore\n /** Path of the operation to render, e.g. '/users/{id}'. */\n path: string\n /** HTTP method of the operation to render. */\n method: HttpMethod\n /** Pre-selected client ID, e.g. 'shell/curl'. */\n selectedClient?: AvailableClients[number]\n /**\n * Server object override used to build the example request.\n *\n * When omitted, the server is derived from the active document (operation,\n * then path item, then document level), mirroring the API reference. Pass\n * `null` to force \"no server\".\n */\n selectedServer?: ServerObject | null\n /**\n * Pre-selected example key for parameters and the request body.\n *\n * The store is the source of truth once an example is picked, so\n * `x-scalar-default-example` wins over this initial seed and the selection\n * round-trips through the store like the client selection does.\n */\n selectedExample?: string\n /** Security schemes applicable to the operation. */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /**\n * Force a color mode on the rendered block.\n *\n * When omitted, the block inherits the ambient theme of the host page.\n * Pass `true` for dark mode or `false` for light mode.\n */\n darkMode?: boolean\n}\n\n/**\n * Builds the wrapper classes for the mounted block.\n *\n * The `.scalar-app` class scopes the Tailwind utilities, and the optional\n * color-mode class lets consumers pin the block to dark or light.\n */\nconst getWrapperClass = (darkMode: boolean | undefined): string =>\n ['scalar-app', darkMode === true ? 'dark-mode' : darkMode === false ? 'light-mode' : ''].filter(Boolean).join(' ')\n\n/**\n * Mount the CodeExample block to a DOM element without Vue.\n *\n * The consumer creates and controls their own workspace store,\n * then passes it in along with the path and method to render.\n */\nexport const createCodeExample = (el: HTMLElement | string, options: CreateCodeExampleOptions) => {\n const element = typeof el === 'string' ? document.querySelector(el) : el\n if (!element) {\n throw new Error(`Element not found: ${el}`)\n }\n\n const eventBus = createWorkspaceEventBus()\n const clientOptions = generateClientOptions()\n\n // Persist client changes back to the store. The block emits\n // `workspace:update:selected-client` on its private bus when the user picks a\n // client; without this subscription the choice would never reach the store\n // and `x-scalar-default-client` (the source of truth read below) would stay\n // stale, so the selection would not survive a re-render or be shared with\n // other blocks reading from the same store.\n const mutators = generateClientMutators(options.store)\n const unsubscribeClient = eventBus.on('workspace:update:selected-client', (payload) =>\n mutators.workspace().workspace.updateSelectedClient(payload),\n )\n\n // Persist example changes back to the store as well, mirroring the client\n // round-trip above. The block emits `workspace:update:selected-example` when\n // the user picks an example; without this the choice would never reach\n // `x-scalar-default-example` (read below) and would neither survive a\n // re-render nor sync to other blocks reading from the same store.\n const unsubscribeExample = eventBus.on('workspace:update:selected-example', (payload) =>\n mutators.workspace().workspace.updateSelectedExample(payload),\n )\n\n type OperationContext = { operation: OperationObject; server: ServerObject | null }\n\n /**\n * Resolve the operation and its effective server from the active document.\n *\n * The server is resolved from the same document the operation came from\n * (operation, then path item, then document level), so a snippet never pairs\n * an operation with a server URL from a different spec.\n */\n const resolveContext = (): OperationContext | undefined => {\n // The active document may be an AsyncAPI document, which has no `paths`.\n const activeDocument = options.store.workspace.activeDocument\n if (!activeDocument || !('paths' in activeDocument)) {\n return undefined\n }\n const pathItem = getResolvedRef(activeDocument.paths?.[options.path])\n const operation = getResolvedRef(pathItem?.[options.method])\n if (!operation) {\n return undefined\n }\n const server = getFirstServer(operation.servers ?? null, pathItem?.servers ?? null, activeDocument.servers ?? null)\n return { operation, server }\n }\n\n // Fail loudly if the path and method do not point at an operation in the store,\n // mirroring the \"element not found\" guard above.\n if (!resolveContext()) {\n throw new Error(`Operation not found: ${options.method.toUpperCase()} ${options.path}`)\n }\n\n // Remember the last context that resolved so a transient miss (e.g. the active\n // document is swapped to one without this path or method after mount) keeps\n // rendering the previous operation, paired with the server it actually came\n // from, instead of feeding `undefined` to the block.\n let lastContext: OperationContext | undefined\n\n /** Current operation + server, falling back to the last good resolution on a transient miss. */\n const currentContext = (): OperationContext => {\n const context = resolveContext()\n if (context) {\n lastContext = context\n }\n return (context ?? lastContext) as OperationContext\n }\n\n // Props are getters so the block tracks the reactive store (active document,\n // `x-scalar-default-client`, `x-scalar-default-example`) live. Change the\n // client, example, or server through the store to drive re-renders.\n const props = reactive<CodeExampleProps>({\n get operation(): OperationObject {\n return currentContext().operation\n },\n get method() {\n return options.method\n },\n get path() {\n return options.path\n },\n clientOptions,\n eventBus,\n get securitySchemes() {\n return options.securitySchemes ?? []\n },\n get selectedClient() {\n // The store is the source of truth once the user picks a client, so it\n // wins over the initial `options.selectedClient` seed and the selection\n // round-trips through the subscription above.\n return options.store.workspace['x-scalar-default-client'] ?? options.selectedClient\n },\n get selectedExample() {\n // Same as the client: the store wins over the initial seed so the example\n // selection survives re-renders and syncs across blocks.\n return options.store.workspace['x-scalar-default-example'] ?? options.selectedExample\n },\n get selectedServer() {\n // An explicit option wins (including an explicit `null` for \"no server\");\n // otherwise derive it from the same document the operation resolved from.\n return options.selectedServer !== undefined ? options.selectedServer : currentContext().server\n },\n })\n\n // Render the operation path in the header by default. The reference renders\n // this via the `#header` slot too, so the standalone block matches its look.\n const renderHeader = () => h('span', { class: 'font-code text-c-2 min-w-0 truncate' }, options.path)\n\n // Wrap the block in its own teleport root so floating UI (the client picker\n // popover) renders inside the themed `.scalar-app` wrapper instead of escaping\n // to `body`, where it would miss the color-mode variables and lose its styling.\n const app = createApp(() =>\n h('div', { class: getWrapperClass(options.darkMode) }, [\n h(ScalarTeleportRoot, null, { default: () => h(CodeExample, props, { header: renderHeader }) }),\n ]),\n )\n\n app.mount(element)\n\n return {\n app,\n destroy: () => {\n unsubscribeClient()\n unsubscribeExample()\n app.unmount()\n },\n }\n}\n"],"mappings":";;;;;;;;;AAyDA,IAAM,KAAmB,MACvB,CAAC,cAAc,MAAa,KAAO,cAAc,MAAa,KAAQ,eAAe,EAAE,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,GAQtG,KAAqB,GAA0B,MAAsC;CAChG,IAAM,IAAU,OAAO,KAAO,WAAW,SAAS,cAAc,CAAE,IAAI;CACtE,IAAI,CAAC,GACH,MAAU,MAAM,sBAAsB,GAAI;CAG5C,IAAM,IAAW,EAAwB,GACnC,IAAgB,EAAsB,GAQtC,IAAW,EAAuB,EAAQ,KAAK,GAC/C,IAAoB,EAAS,GAAG,qCAAqC,MACzE,EAAS,UAAU,CAAC,CAAC,UAAU,qBAAqB,CAAO,CAC7D,GAOM,IAAqB,EAAS,GAAG,sCAAsC,MAC3E,EAAS,UAAU,CAAC,CAAC,UAAU,sBAAsB,CAAO,CAC9D,GAWM,UAAqD;EAEzD,IAAM,IAAiB,EAAQ,MAAM,UAAU;EAC/C,IAAI,CAAC,KAAkB,EAAE,WAAW,IAClC;EAEF,IAAM,IAAW,EAAe,EAAe,QAAQ,EAAQ,KAAK,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-example/mount.ts"],"sourcesContent":["import { ScalarTeleportRoot } from '@scalar/components/teleport'\nimport type { HttpMethod } from '@scalar/helpers/http/http-methods'\nimport type { AvailableClients } from '@scalar/snippetz'\nimport type { WorkspaceStore } from '@scalar/workspace-store/client'\nimport { createWorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { getFirstServer } from '@scalar/workspace-store/helpers/get-first-server'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { EXTERNAL_EXAMPLES } from '@scalar/workspace-store/helpers/use-external-examples'\nimport { generateClientMutators } from '@scalar/workspace-store/mutators'\nimport type { SecuritySchemeObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { OperationObject, ServerObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { createApp, h, reactive } from 'vue'\n\nimport CodeExample, { type CodeExampleProps } from './components/CodeExample.vue'\nimport { generateClientOptions } from './helpers/generate-client-options'\n\nexport type CreateCodeExampleOptions = {\n /** Workspace store that holds the OpenAPI document(s) to render from. */\n store: WorkspaceStore\n /** Path of the operation to render, e.g. '/users/{id}'. */\n path: string\n /** HTTP method of the operation to render. */\n method: HttpMethod\n /** Pre-selected client ID, e.g. 'shell/curl'. */\n selectedClient?: AvailableClients[number]\n /**\n * Server object override used to build the example request.\n *\n * When omitted, the server is derived from the active document (operation,\n * then path item, then document level), mirroring the API reference. Pass\n * `null` to force \"no server\".\n */\n selectedServer?: ServerObject | null\n /**\n * Pre-selected example key for parameters and the request body.\n *\n * The store is the source of truth once an example is picked, so\n * `x-scalar-default-example` wins over this initial seed and the selection\n * round-trips through the store like the client selection does.\n */\n selectedExample?: string\n /** Security schemes applicable to the operation. */\n securitySchemes?: SecuritySchemeObjectSecret[]\n /**\n * Force a color mode on the rendered block.\n *\n * When omitted, the block inherits the ambient theme of the host page.\n * Pass `true` for dark mode or `false` for light mode.\n */\n darkMode?: boolean\n}\n\n/**\n * Builds the wrapper classes for the mounted block.\n *\n * The `.scalar-app` class scopes the Tailwind utilities, and the optional\n * color-mode class lets consumers pin the block to dark or light.\n */\nconst getWrapperClass = (darkMode: boolean | undefined): string =>\n ['scalar-app', darkMode === true ? 'dark-mode' : darkMode === false ? 'light-mode' : ''].filter(Boolean).join(' ')\n\n/**\n * Mount the CodeExample block to a DOM element without Vue.\n *\n * The consumer creates and controls their own workspace store,\n * then passes it in along with the path and method to render.\n */\nexport const createCodeExample = (el: HTMLElement | string, options: CreateCodeExampleOptions) => {\n const element = typeof el === 'string' ? document.querySelector(el) : el\n if (!element) {\n throw new Error(`Element not found: ${el}`)\n }\n\n const eventBus = createWorkspaceEventBus()\n const clientOptions = generateClientOptions()\n\n // Persist client changes back to the store. The block emits\n // `workspace:update:selected-client` on its private bus when the user picks a\n // client; without this subscription the choice would never reach the store\n // and `x-scalar-default-client` (the source of truth read below) would stay\n // stale, so the selection would not survive a re-render or be shared with\n // other blocks reading from the same store.\n const mutators = generateClientMutators(options.store)\n const unsubscribeClient = eventBus.on('workspace:update:selected-client', (payload) =>\n mutators.workspace().workspace.updateSelectedClient(payload),\n )\n\n // Persist example changes back to the store as well, mirroring the client\n // round-trip above. The block emits `workspace:update:selected-example` when\n // the user picks an example; without this the choice would never reach\n // `x-scalar-default-example` (read below) and would neither survive a\n // re-render nor sync to other blocks reading from the same store.\n const unsubscribeExample = eventBus.on('workspace:update:selected-example', (payload) =>\n mutators.workspace().workspace.updateSelectedExample(payload),\n )\n\n type OperationContext = { operation: OperationObject; server: ServerObject | null }\n\n /**\n * Resolve the operation and its effective server from the active document.\n *\n * The server is resolved from the same document the operation came from\n * (operation, then path item, then document level), so a snippet never pairs\n * an operation with a server URL from a different spec.\n */\n const resolveContext = (): OperationContext | undefined => {\n // The active document may be an AsyncAPI document, which has no `paths`.\n const activeDocument = options.store.workspace.activeDocument\n if (!activeDocument || !('paths' in activeDocument)) {\n return undefined\n }\n const pathItem = getResolvedRef(activeDocument.paths?.[options.path])\n const operation = getResolvedRef(pathItem?.[options.method])\n if (!operation) {\n return undefined\n }\n const server = getFirstServer(operation.servers ?? null, pathItem?.servers ?? null, activeDocument.servers ?? null)\n return { operation, server }\n }\n\n // Fail loudly if the path and method do not point at an operation in the store,\n // mirroring the \"element not found\" guard above.\n if (!resolveContext()) {\n throw new Error(`Operation not found: ${options.method.toUpperCase()} ${options.path}`)\n }\n\n // Remember the last context that resolved so a transient miss (e.g. the active\n // document is swapped to one without this path or method after mount) keeps\n // rendering the previous operation, paired with the server it actually came\n // from, instead of feeding `undefined` to the block.\n let lastContext: OperationContext | undefined\n\n /** Current operation + server, falling back to the last good resolution on a transient miss. */\n const currentContext = (): OperationContext => {\n const context = resolveContext()\n if (context) {\n lastContext = context\n }\n return (context ?? lastContext) as OperationContext\n }\n\n // Props are getters so the block tracks the reactive store (active document,\n // `x-scalar-default-client`, `x-scalar-default-example`) live. Change the\n // client, example, or server through the store to drive re-renders.\n const props = reactive<CodeExampleProps>({\n get operation(): OperationObject {\n return currentContext().operation\n },\n get method() {\n return options.method\n },\n get path() {\n return options.path\n },\n clientOptions,\n eventBus,\n get securitySchemes() {\n return options.securitySchemes ?? []\n },\n get selectedClient() {\n // The store is the source of truth once the user picks a client, so it\n // wins over the initial `options.selectedClient` seed and the selection\n // round-trips through the subscription above.\n return options.store.workspace['x-scalar-default-client'] ?? options.selectedClient\n },\n get selectedExample() {\n // Same as the client: the store wins over the initial seed so the example\n // selection survives re-renders and syncs across blocks.\n return options.store.workspace['x-scalar-default-example'] ?? options.selectedExample\n },\n get selectedServer() {\n // An explicit option wins (including an explicit `null` for \"no server\");\n // otherwise derive it from the same document the operation resolved from.\n return options.selectedServer !== undefined ? options.selectedServer : currentContext().server\n },\n })\n\n // Render the operation path in the header by default. The reference renders\n // this via the `#header` slot too, so the standalone block matches its look.\n const renderHeader = () => h('span', { class: 'font-code text-c-2 min-w-0 truncate' }, options.path)\n\n // Wrap the block in its own teleport root so floating UI (the client picker\n // popover) renders inside the themed `.scalar-app` wrapper instead of escaping\n // to `body`, where it would miss the color-mode variables and lose its styling.\n const app = createApp(() =>\n h('div', { class: getWrapperClass(options.darkMode) }, [\n h(ScalarTeleportRoot, null, { default: () => h(CodeExample, props, { header: renderHeader }) }),\n ]),\n )\n\n app.provide(EXTERNAL_EXAMPLES, () => options.store.externalExamples())\n app.mount(element)\n\n return {\n app,\n destroy: () => {\n unsubscribeClient()\n unsubscribeExample()\n app.unmount()\n },\n }\n}\n"],"mappings":";;;;;;;;;;AA0DA,IAAM,KAAmB,MACvB,CAAC,cAAc,MAAa,KAAO,cAAc,MAAa,KAAQ,eAAe,EAAE,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,GAQtG,KAAqB,GAA0B,MAAsC;CAChG,IAAM,IAAU,OAAO,KAAO,WAAW,SAAS,cAAc,CAAE,IAAI;CACtE,IAAI,CAAC,GACH,MAAU,MAAM,sBAAsB,GAAI;CAG5C,IAAM,IAAW,EAAwB,GACnC,IAAgB,EAAsB,GAQtC,IAAW,EAAuB,EAAQ,KAAK,GAC/C,IAAoB,EAAS,GAAG,qCAAqC,MACzE,EAAS,UAAU,CAAC,CAAC,UAAU,qBAAqB,CAAO,CAC7D,GAOM,IAAqB,EAAS,GAAG,sCAAsC,MAC3E,EAAS,UAAU,CAAC,CAAC,UAAU,sBAAsB,CAAO,CAC9D,GAWM,UAAqD;EAEzD,IAAM,IAAiB,EAAQ,MAAM,UAAU;EAC/C,IAAI,CAAC,KAAkB,EAAE,WAAW,IAClC;EAEF,IAAM,IAAW,EAAe,EAAe,QAAQ,EAAQ,KAAK,GAC9D,IAAY,EAAe,IAAW,EAAQ,OAAO;EACtD,OAIL,OAAO;GAAE;GAAW,QADL,EAAe,EAAU,WAAW,MAAM,GAAU,WAAW,MAAM,EAAe,WAAW,IAC1F;EAAO;CAC7B;CAIA,IAAI,CAAC,EAAe,GAClB,MAAU,MAAM,wBAAwB,EAAQ,OAAO,YAAY,EAAE,GAAG,EAAQ,MAAM;CAOxF,IAAI,GAGE,UAAyC;EAC7C,IAAM,IAAU,EAAe;EAI/B,OAHI,MACF,IAAc,IAER,KAAW;CACrB,GAKM,IAAQ,EAA2B;EACvC,IAAI,YAA6B;GAC/B,OAAO,EAAe,CAAC,CAAC;EAC1B;EACA,IAAI,SAAS;GACX,OAAO,EAAQ;EACjB;EACA,IAAI,OAAO;GACT,OAAO,EAAQ;EACjB;EACA;EACA;EACA,IAAI,kBAAkB;GACpB,OAAO,EAAQ,mBAAmB,CAAC;EACrC;EACA,IAAI,iBAAiB;GAInB,OAAO,EAAQ,MAAM,UAAU,8BAA8B,EAAQ;EACvE;EACA,IAAI,kBAAkB;GAGpB,OAAO,EAAQ,MAAM,UAAU,+BAA+B,EAAQ;EACxE;EACA,IAAI,iBAAiB;GAGnB,OAAO,EAAQ,mBAAmB,KAAA,IAAqC,EAAe,CAAC,CAAC,SAA1C,EAAQ;EACxD;CACF,CAAC,GAIK,UAAqB,EAAE,QAAQ,EAAE,OAAO,sCAAsC,GAAG,EAAQ,IAAI,GAK7F,IAAM,QACV,EAAE,OAAO,EAAE,OAAO,EAAgB,EAAQ,QAAQ,EAAE,GAAG,CACrD,EAAE,GAAoB,MAAM,EAAE,eAAe,EAAE,GAAa,GAAO,EAAE,QAAQ,EAAa,CAAC,EAAE,CAAC,CAChG,CAAC,CACH;CAKA,OAHA,EAAI,QAAQ,SAAyB,EAAQ,MAAM,iBAAiB,CAAC,GACrE,EAAI,MAAM,CAAO,GAEV;EACL;EACA,eAAe;GAGb,AAFA,EAAkB,GAClB,EAAmB,GACnB,EAAI,QAAQ;EACd;CACF;AACF"}
package/dist/constants.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/constants.ts
2
- var e = typeof OVERRIDE_PACKAGE_VERSION < "u" ? OVERRIDE_PACKAGE_VERSION : "0.1.19";
2
+ var e = typeof OVERRIDE_PACKAGE_VERSION < "u" ? OVERRIDE_PACKAGE_VERSION : "0.1.20";
3
3
  //#endregion
4
4
  export { e as APP_VERSION };
5
5
 
package/dist/style.css CHANGED
@@ -4463,5 +4463,5 @@
4463
4463
  opacity: .5;
4464
4464
  }
4465
4465
  }
4466
- .request-card[data-v-82b2d155]{color:var(--scalar-color-1);font-size:var(--scalar-font-size-3)}.request-method[data-v-82b2d155]{font-family:var(--scalar-font-code);text-transform:uppercase;margin-right:6px}.request-card-footer[data-v-82b2d155]{flex-shrink:0;justify-content:flex-end;padding:6px;display:flex;position:relative}.request-card-footer-addon[data-v-82b2d155]{flex:1;align-items:center;min-width:0;display:flex}.request-editor-section[data-v-82b2d155]{flex:1;display:flex}.request-card-simple[data-v-82b2d155]{font-size:var(--scalar-small);justify-content:space-between;align-items:center;padding:8px 8px 8px 12px;display:flex}.code-snippet[data-v-82b2d155]{flex-direction:column;width:100%;display:flex}
4466
+ .request-card[data-v-8b0cd212]{color:var(--scalar-color-1);font-size:var(--scalar-font-size-3)}.request-method[data-v-8b0cd212]{font-family:var(--scalar-font-code);text-transform:uppercase;margin-right:6px}.request-card-footer[data-v-8b0cd212]{flex-shrink:0;justify-content:flex-end;padding:6px;display:flex;position:relative}.request-card-footer-addon[data-v-8b0cd212]{flex:1;align-items:center;min-width:0;display:flex}.request-editor-section[data-v-8b0cd212]{flex:1;display:flex}.request-card-simple[data-v-8b0cd212]{font-size:var(--scalar-small);justify-content:space-between;align-items:center;padding:8px 8px 8px 12px;display:flex}.code-snippet[data-v-8b0cd212]{flex-direction:column;width:100%;display:flex}
4467
4467
  /*$vite$:1*/
@@ -1,2 +1,2 @@
1
- .request-card[data-v-82b2d155]{color:var(--scalar-color-1);font-size:var(--scalar-font-size-3)}.request-method[data-v-82b2d155]{font-family:var(--scalar-font-code);text-transform:uppercase;margin-right:6px}.request-card-footer[data-v-82b2d155]{flex-shrink:0;justify-content:flex-end;padding:6px;display:flex;position:relative}.request-card-footer-addon[data-v-82b2d155]{flex:1;align-items:center;min-width:0;display:flex}.request-editor-section[data-v-82b2d155]{flex:1;display:flex}.request-card-simple[data-v-82b2d155]{font-size:var(--scalar-small);justify-content:space-between;align-items:center;padding:8px 8px 8px 12px;display:flex}.code-snippet[data-v-82b2d155]{flex-direction:column;width:100%;display:flex}
1
+ .request-card[data-v-8b0cd212]{color:var(--scalar-color-1);font-size:var(--scalar-font-size-3)}.request-method[data-v-8b0cd212]{font-family:var(--scalar-font-code);text-transform:uppercase;margin-right:6px}.request-card-footer[data-v-8b0cd212]{flex-shrink:0;justify-content:flex-end;padding:6px;display:flex;position:relative}.request-card-footer-addon[data-v-8b0cd212]{flex:1;align-items:center;min-width:0;display:flex}.request-editor-section[data-v-8b0cd212]{flex:1;display:flex}.request-card-simple[data-v-8b0cd212]{font-size:var(--scalar-small);justify-content:space-between;align-items:center;padding:8px 8px 8px 12px;display:flex}.code-snippet[data-v-8b0cd212]{flex-direction:column;width:100%;display:flex}
2
2
  /*$vite$:1*/
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "blocks",
18
18
  "docs"
19
19
  ],
20
- "version": "0.1.19",
20
+ "version": "0.1.20",
21
21
  "engines": {
22
22
  "node": ">=22"
23
23
  },
@@ -37,13 +37,13 @@
37
37
  "CHANGELOG.md"
38
38
  ],
39
39
  "dependencies": {
40
- "@scalar/components": "0.29.3",
40
+ "@scalar/components": "0.30.0",
41
41
  "@scalar/helpers": "0.12.0",
42
42
  "@scalar/icons": "0.7.6",
43
- "@scalar/snippetz": "0.9.31",
43
+ "@scalar/snippetz": "0.9.32",
44
44
  "@scalar/themes": "0.18.0",
45
- "@scalar/types": "0.20.0",
46
- "@scalar/workspace-store": "0.63.0",
45
+ "@scalar/types": "0.20.1",
46
+ "@scalar/workspace-store": "0.64.0",
47
47
  "@types/har-format": "^1.2.16",
48
48
  "js-base64": "^3.9.2",
49
49
  "vue": "^3.5.40"