@scalar/blocks 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/_virtual/_plugin-vue_export-helper.js +1 -2
  3. package/dist/code-example/components/AsyncApiCodeExample.vue.js +1 -2
  4. package/dist/code-example/components/AsyncApiCodeExample.vue.js.map +1 -1
  5. package/dist/code-example/components/AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js +1 -2
  6. package/dist/code-example/components/AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js.map +1 -1
  7. package/dist/code-example/components/CodeExample.vue.d.ts +2 -0
  8. package/dist/code-example/components/CodeExample.vue.d.ts.map +1 -1
  9. package/dist/code-example/components/CodeExample.vue.js +4 -5
  10. package/dist/code-example/components/CodeExample.vue.js.map +1 -1
  11. package/dist/code-example/components/CodeExample.vue_vue_type_script_setup_true_lang.js +102 -100
  12. package/dist/code-example/components/CodeExample.vue_vue_type_script_setup_true_lang.js.map +1 -1
  13. package/dist/code-example/components/ExamplePicker.vue.js +1 -2
  14. package/dist/code-example/components/ExamplePicker.vue.js.map +1 -1
  15. package/dist/code-example/components/ExamplePicker.vue_vue_type_script_setup_true_lang.js +1 -2
  16. package/dist/code-example/components/HttpMethod.vue.js +1 -2
  17. package/dist/code-example/components/HttpMethod.vue.js.map +1 -1
  18. package/dist/code-example/components/HttpMethod.vue_vue_type_script_setup_true_lang.js +1 -2
  19. package/dist/code-example/helpers/filter-clients-by-query.js +1 -2
  20. package/dist/code-example/helpers/find-client.js +1 -2
  21. package/dist/code-example/helpers/format-language.js +1 -2
  22. package/dist/code-example/helpers/generate-client-options.js +1 -2
  23. package/dist/code-example/helpers/generate-code-snippet.d.ts +2 -1
  24. package/dist/code-example/helpers/generate-code-snippet.d.ts.map +1 -1
  25. package/dist/code-example/helpers/generate-code-snippet.js +11 -11
  26. package/dist/code-example/helpers/generate-code-snippet.js.map +1 -1
  27. package/dist/code-example/helpers/get-asyncapi-example-context.js +1 -2
  28. package/dist/code-example/helpers/get-clients.js +8 -9
  29. package/dist/code-example/helpers/get-custom-code-samples.js +1 -2
  30. package/dist/code-example/helpers/get-generated-payload-example.js +1 -2
  31. package/dist/code-example/helpers/get-message-example-content.js +1 -2
  32. package/dist/code-example/helpers/get-secrets.js +1 -2
  33. package/dist/code-example/helpers/get-snippet.js +1 -2
  34. package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts +2 -1
  35. package/dist/code-example/helpers/operation-to-har/operation-to-har.d.ts.map +1 -1
  36. package/dist/code-example/helpers/operation-to-har/operation-to-har.js +32 -31
  37. package/dist/code-example/helpers/operation-to-har/operation-to-har.js.map +1 -1
  38. package/dist/code-example/helpers/operation-to-har/process-body.d.ts +2 -2
  39. package/dist/code-example/helpers/operation-to-har/process-body.d.ts.map +1 -1
  40. package/dist/code-example/helpers/operation-to-har/process-body.js +80 -52
  41. package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -1
  42. package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts +2 -1
  43. package/dist/code-example/helpers/operation-to-har/process-parameters.d.ts.map +1 -1
  44. package/dist/code-example/helpers/operation-to-har/process-parameters.js +65 -58
  45. package/dist/code-example/helpers/operation-to-har/process-parameters.js.map +1 -1
  46. package/dist/code-example/helpers/operation-to-har/process-security-schemes.d.ts.map +1 -1
  47. package/dist/code-example/helpers/operation-to-har/process-security-schemes.js +31 -28
  48. package/dist/code-example/helpers/operation-to-har/process-security-schemes.js.map +1 -1
  49. package/dist/code-example/helpers/operation-to-har/process-server-url.js +1 -2
  50. package/dist/code-example/index.js +10 -10
  51. package/dist/code-example/mount-asyncapi.js +7 -8
  52. package/dist/code-example/mount.js +5 -6
  53. package/dist/constants.js +2 -3
  54. package/dist/schema/LinkButton.vue.js +1 -2
  55. package/dist/schema/RenderString.vue.js +1 -2
  56. package/dist/schema/RenderString.vue.js.map +1 -1
  57. package/dist/schema/RenderString.vue_vue_type_script_setup_true_lang.js +1 -2
  58. package/dist/schema/Schema.vue.js +4 -5
  59. package/dist/schema/Schema.vue.js.map +1 -1
  60. package/dist/schema/Schema.vue_vue_type_script_setup_true_lang.js +67 -68
  61. package/dist/schema/Schema.vue_vue_type_script_setup_true_lang.js.map +1 -1
  62. package/dist/schema/SchemaCollapsedPreview.vue.js +1 -2
  63. package/dist/schema/SchemaCollapsedPreview.vue.js.map +1 -1
  64. package/dist/schema/SchemaCollapsedPreview.vue_vue_type_script_setup_true_lang.js +1 -2
  65. package/dist/schema/SchemaCollapsedPreview.vue_vue_type_script_setup_true_lang.js.map +1 -1
  66. package/dist/schema/SchemaComposition.vue.js +4 -5
  67. package/dist/schema/SchemaComposition.vue.js.map +1 -1
  68. package/dist/schema/SchemaComposition.vue_vue_type_script_setup_true_lang.js +26 -27
  69. package/dist/schema/SchemaComposition.vue_vue_type_script_setup_true_lang.js.map +1 -1
  70. package/dist/schema/SchemaEnumPropertyItem.vue.js +1 -2
  71. package/dist/schema/SchemaEnumPropertyItem.vue.js.map +1 -1
  72. package/dist/schema/SchemaEnumPropertyItem.vue_vue_type_script_setup_true_lang.js +1 -2
  73. package/dist/schema/SchemaEnumPropertyItem.vue_vue_type_script_setup_true_lang.js.map +1 -1
  74. package/dist/schema/SchemaEnums.vue.js +4 -5
  75. package/dist/schema/SchemaEnums.vue.js.map +1 -1
  76. package/dist/schema/SchemaEnums.vue_vue_type_script_setup_true_lang.js +12 -13
  77. package/dist/schema/SchemaEnums.vue_vue_type_script_setup_true_lang.js.map +1 -1
  78. package/dist/schema/SchemaGlyphPuck.vue.js +1 -2
  79. package/dist/schema/SchemaGlyphPuck.vue.js.map +1 -1
  80. package/dist/schema/SchemaGlyphPuck.vue_vue_type_script_setup_true_lang.js +1 -2
  81. package/dist/schema/SchemaGutterToggle.vue.js +1 -2
  82. package/dist/schema/SchemaGutterToggle.vue.js.map +1 -1
  83. package/dist/schema/SchemaGutterToggle.vue_vue_type_script_setup_true_lang.js +1 -2
  84. package/dist/schema/SchemaHeading.vue.js +4 -5
  85. package/dist/schema/SchemaHeading.vue.js.map +1 -1
  86. package/dist/schema/SchemaHeading.vue_vue_type_script_setup_true_lang.js +1 -2
  87. package/dist/schema/SchemaHeading.vue_vue_type_script_setup_true_lang.js.map +1 -1
  88. package/dist/schema/SchemaObjectExampleCodeBlock.vue.js +1 -2
  89. package/dist/schema/SchemaObjectExampleCodeBlock.vue.js.map +1 -1
  90. package/dist/schema/SchemaObjectExampleCodeBlock.vue_vue_type_script_setup_true_lang.js +1 -2
  91. package/dist/schema/SchemaObjectExampleCodeBlock.vue_vue_type_script_setup_true_lang.js.map +1 -1
  92. package/dist/schema/SchemaObjectProperties.vue.js +1 -2
  93. package/dist/schema/SchemaObjectProperties.vue.js.map +1 -1
  94. package/dist/schema/SchemaObjectProperties.vue_vue_type_script_setup_true_lang.js +1 -2
  95. package/dist/schema/SchemaObjectProperties.vue_vue_type_script_setup_true_lang.js.map +1 -1
  96. package/dist/schema/SchemaProperty.vue.js +4 -5
  97. package/dist/schema/SchemaProperty.vue.js.map +1 -1
  98. package/dist/schema/SchemaProperty.vue_vue_type_script_setup_true_lang.js +48 -49
  99. package/dist/schema/SchemaProperty.vue_vue_type_script_setup_true_lang.js.map +1 -1
  100. package/dist/schema/SchemaPropertyDefault.vue.js +4 -5
  101. package/dist/schema/SchemaPropertyDefault.vue.js.map +1 -1
  102. package/dist/schema/SchemaPropertyDefault.vue_vue_type_script_setup_true_lang.js +9 -10
  103. package/dist/schema/SchemaPropertyDefault.vue_vue_type_script_setup_true_lang.js.map +1 -1
  104. package/dist/schema/SchemaPropertyDetail.vue.js +4 -5
  105. package/dist/schema/SchemaPropertyDetail.vue.js.map +1 -1
  106. package/dist/schema/SchemaPropertyDetail.vue_vue_type_script_setup_true_lang.js +1 -2
  107. package/dist/schema/SchemaPropertyDetail.vue_vue_type_script_setup_true_lang.js.map +1 -1
  108. package/dist/schema/SchemaPropertyExamples.vue.js +4 -5
  109. package/dist/schema/SchemaPropertyExamples.vue.js.map +1 -1
  110. package/dist/schema/SchemaPropertyExamples.vue_vue_type_script_setup_true_lang.js +18 -19
  111. package/dist/schema/SchemaPropertyExamples.vue_vue_type_script_setup_true_lang.js.map +1 -1
  112. package/dist/schema/SchemaPropertyHeading.vue.js +4 -5
  113. package/dist/schema/SchemaPropertyHeading.vue.js.map +1 -1
  114. package/dist/schema/SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js +101 -102
  115. package/dist/schema/SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js.map +1 -1
  116. package/dist/schema/SchemaPropertyPattern.vue.js +4 -5
  117. package/dist/schema/SchemaPropertyPattern.vue.js.map +1 -1
  118. package/dist/schema/SchemaPropertyPattern.vue_vue_type_script_setup_true_lang.js +1 -2
  119. package/dist/schema/SchemaRailPanel.vue.js +1 -2
  120. package/dist/schema/SchemaRailPanel.vue.js.map +1 -1
  121. package/dist/schema/SchemaRailPanel.vue_vue_type_script_setup_true_lang.js +1 -2
  122. package/dist/schema/SchemaRailPanel.vue_vue_type_script_setup_true_lang.js.map +1 -1
  123. package/dist/schema/components/CopyLinkButton.vue.js +1 -2
  124. package/dist/schema/components/CopyLinkButton.vue.js.map +1 -1
  125. package/dist/schema/components/CopyLinkButton.vue_vue_type_script_setup_true_lang.js +1 -2
  126. package/dist/schema/components/WithBreadcrumb.vue.js +1 -2
  127. package/dist/schema/components/WithBreadcrumb.vue.js.map +1 -1
  128. package/dist/schema/components/WithBreadcrumb.vue_vue_type_script_setup_true_lang.js +1 -2
  129. package/dist/schema/discriminator-metadata.js +1 -2
  130. package/dist/schema/helpers/dynamic-scope.js +1 -2
  131. package/dist/schema/helpers/format-example.js +1 -2
  132. package/dist/schema/helpers/format-value.js +1 -2
  133. package/dist/schema/helpers/get-compositions-to-render.js +19 -20
  134. package/dist/schema/helpers/get-discriminator-values.js +1 -2
  135. package/dist/schema/helpers/get-enum-values.js +1 -2
  136. package/dist/schema/helpers/get-property-description.js +1 -2
  137. package/dist/schema/helpers/get-ref-name.js +1 -2
  138. package/dist/schema/helpers/get-rendered-example.js +1 -2
  139. package/dist/schema/helpers/get-schema-type.js +1 -2
  140. package/dist/schema/helpers/get-type-signature-tokens.d.ts +2 -2
  141. package/dist/schema/helpers/get-type-signature-tokens.d.ts.map +1 -1
  142. package/dist/schema/helpers/get-type-signature-tokens.js +3 -4
  143. package/dist/schema/helpers/get-type-signature-tokens.js.map +1 -1
  144. package/dist/schema/helpers/has-complex-array-items.js +1 -2
  145. package/dist/schema/helpers/index.js +13 -13
  146. package/dist/schema/helpers/is-empty-schema-object.js +1 -2
  147. package/dist/schema/helpers/is-model-linkable.js +1 -2
  148. package/dist/schema/helpers/is-on-schema-target-path.js +1 -2
  149. package/dist/schema/helpers/is-type-object.js +1 -2
  150. package/dist/schema/helpers/merge-all-of-schemas.js +1 -2
  151. package/dist/schema/helpers/normalize-object-composition.js +1 -2
  152. package/dist/schema/helpers/optimize-value-for-display.js +1 -2
  153. package/dist/schema/helpers/partition-all-of-compositions.js +1 -2
  154. package/dist/schema/helpers/schema-composition.js +1 -2
  155. package/dist/schema/helpers/schema-cycle.js +1 -2
  156. package/dist/schema/helpers/schema-expansion.js +1 -2
  157. package/dist/schema/helpers/schema-keyboard-nav.js +1 -2
  158. package/dist/schema/helpers/schema-name.js +2 -3
  159. package/dist/schema/helpers/schema-name.js.map +1 -1
  160. package/dist/schema/helpers/should-display-description.js +1 -2
  161. package/dist/schema/helpers/should-display-heading.js +1 -2
  162. package/dist/schema/helpers/should-render-array-item-composition.js +1 -2
  163. package/dist/schema/helpers/sort-property-names.js +1 -2
  164. package/dist/schema/helpers/unwrap-for-read.js +1 -2
  165. package/dist/schema/index.js +8 -8
  166. package/dist/schema/localization/index.js +1 -2
  167. package/dist/schema/localization/locales/ar.js +1 -2
  168. package/dist/schema/localization/locales/de.js +1 -2
  169. package/dist/schema/localization/locales/en.js +1 -2
  170. package/dist/schema/localization/locales/es.js +1 -2
  171. package/dist/schema/localization/locales/fr.js +1 -2
  172. package/dist/schema/localization/locales/pt.js +1 -2
  173. package/dist/schema/localization/locales/ru.js +1 -2
  174. package/dist/schema/localization/locales/zh-cn.js +1 -2
  175. package/dist/schema/localization/locales/zh-tw.js +1 -2
  176. package/dist/schema/localization/translations.js +1 -2
  177. package/dist/schema/protobuf-metadata.js +1 -2
  178. package/dist/schema/recursive-metadata.js +1 -2
  179. package/dist/schema/request-body-composition-index.js +1 -2
  180. package/dist/shared/Badge.vue.d.ts.map +1 -1
  181. package/dist/shared/Badge.vue.js +4 -5
  182. package/dist/shared/Badge.vue.js.map +1 -1
  183. package/dist/shared/Badge.vue_vue_type_script_setup_true_lang.js +2 -3
  184. package/dist/shared/Badge.vue_vue_type_script_setup_true_lang.js.map +1 -1
  185. package/dist/shared/ExternalDocs.vue.js +1 -2
  186. package/dist/shared/ExternalDocs.vue.js.map +1 -1
  187. package/dist/shared/ExternalDocs.vue_vue_type_script_setup_true_lang.js +1 -2
  188. package/dist/shared/ExternalDocs.vue_vue_type_script_setup_true_lang.js.map +1 -1
  189. package/dist/shared/ScreenReader.vue.js +1 -2
  190. package/dist/shared/ScreenReader.vue.js.map +1 -1
  191. package/dist/shared/ScreenReader.vue_vue_type_script_setup_true_lang.js +1 -2
  192. package/dist/shared/index.js +4 -4
  193. package/dist/specification-extensions/ExtensionValue.vue.js +1 -2
  194. package/dist/specification-extensions/ExtensionValue.vue.js.map +1 -1
  195. package/dist/specification-extensions/ExtensionValue.vue_vue_type_script_setup_true_lang.js +5 -6
  196. package/dist/specification-extensions/ExtensionValue.vue_vue_type_script_setup_true_lang.js.map +1 -1
  197. package/dist/specification-extensions/SpecificationExtensions.vue.js +1 -2
  198. package/dist/specification-extensions/SpecificationExtensions.vue.js.map +1 -1
  199. package/dist/specification-extensions/SpecificationExtensions.vue_vue_type_script_setup_true_lang.js +1 -2
  200. package/dist/specification-extensions/SpecificationExtensions.vue_vue_type_script_setup_true_lang.js.map +1 -1
  201. package/dist/style.css +42 -22
  202. package/dist/vue-styles.css +1 -1
  203. package/package.json +24 -24
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @scalar/blocks
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#11103](https://github.com/scalar/scalar/pull/11103): Support `x-scalar-token-prefix` on header API keys. Generated code examples and outgoing requests add the configured prefix while stored credentials remain unchanged.
8
+
9
+ ### Patch Changes
10
+
11
+ - [#11123](https://github.com/scalar/scalar/pull/11123): Fix the API reference freezing on schemas with several recursive or cross-referencing `$ref`s. Generated examples that are too large to render at full depth are now rendered at the deepest depth that fits.
12
+
13
+ ## 0.7.4
14
+
15
+ ### Patch Changes
16
+
17
+ - [#11050](https://github.com/scalar/scalar/pull/11050): Include upgraded OpenAPI 3.0 and Swagger 2.0 file uploads, file arrays, and empty binary request bodies in generated code examples.
18
+ - [#11089](https://github.com/scalar/scalar/pull/11089): Resolve external RAML and Protobuf dependencies for structured AsyncAPI schema documentation, preserving source fallback when dependencies cannot be fully resolved.
19
+
20
+ Show RAML named types in schema headings instead of adding a "RAML type:" line to the description.
21
+
22
+ Show inline object item titles in array type signatures across all `@scalar/blocks` consumers, including OpenAPI documentation: an array with `items: { type: 'object', title: 'Pet' }` now displays `array of Pet` instead of `array of object`.
23
+ - [#11029](https://github.com/scalar/scalar/pull/11029): fix: respect contains match counts in simple array examples
24
+
25
+ Generate matching and nonmatching primitive items for direct contains constraints, counting tuple prefixes and respecting item schemas, length bounds, uniqueness, and the declared dialect. Authored examples remain authoritative. Candidate generation is bounded and may return a partial example for contradictory constraints.
26
+
27
+ Complex references and compositions, nested object or array candidate synthesis, and XML branch reconstruction retain existing best-effort behavior and are deferred to a follow-up.
28
+ - [#11029](https://github.com/scalar/scalar/pull/11029): fix: handle boolean array item schemas when looking up model names
29
+ - [#11099](https://github.com/scalar/scalar/pull/11099): Update compatible runtime and styling dependencies, align editor dependency versions, and preserve document-change comparisons with updated microdiff semantics.
30
+ - [#11110](https://github.com/scalar/scalar/pull/11110): Add a `text-auto-contrast-*` Tailwind utility that picks readable black or white text for any background color, and use it for colored badges and the environment color checkmark.
31
+
3
32
  ## 0.7.3
4
33
 
5
34
  ### Patch Changes
@@ -1,8 +1,7 @@
1
- //#region \0plugin-vue:export-helper
1
+ // \0plugin-vue:export-helper
2
2
  var e = (e, t) => {
3
3
  let n = e.__vccOpts || e;
4
4
  for (let [e, r] of t) n[e] = r;
5
5
  return n;
6
6
  };
7
- //#endregion
8
7
  export { e as default };
@@ -1,9 +1,8 @@
1
1
  import e from "./AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js";
2
2
  /* empty css */
3
3
  import t from "../../_virtual/_plugin-vue_export-helper.js";
4
- //#region src/code-example/components/AsyncApiCodeExample.vue
4
+ // src/code-example/components/AsyncApiCodeExample.vue
5
5
  var n = /*#__PURE__*/ t(e, [["__scopeId", "data-v-aaf1efda"]]);
6
- //#endregion
7
6
  export { n as default };
8
7
 
9
8
  //# sourceMappingURL=AsyncApiCodeExample.vue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AsyncApiCodeExample.vue.js","names":["_sfc_main","AsyncApiCodeExample_vue_vue_type_script_setup_true_lang_default","_plugin_vue_export_helper_default","AsyncApiCodeExample_default"],"sources":["../../../src/code-example/components/AsyncApiCodeExample.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ScalarCard,\n ScalarCardFooter,\n ScalarCardHeader,\n ScalarCardSection,\n} from '@scalar/components/card'\nimport { ScalarCodeBlock } from '@scalar/components/code-block'\nimport { ScalarWrappingText } from '@scalar/components/wrapping-text'\nimport type {\n AsyncApiDocument,\n AsyncApiMessageObject,\n} from '@scalar/types/asyncapi/3.1'\nimport { getResolvedAsyncApiRef } from '@scalar/workspace-store/helpers/get-resolved-async-api-ref'\nimport { computed, ref, watch } from 'vue'\n\nimport { getAsyncApiExampleContext } from '../helpers/get-asyncapi-example-context'\nimport { getGeneratedPayloadExample } from '../helpers/get-generated-payload-example'\nimport { getMessageExampleContent } from '../helpers/get-message-example-content'\nimport ExamplePicker from './ExamplePicker.vue'\n\nconst { document, operationName } = defineProps<{\n /** A workspace-resolved AsyncAPI 3.x document. */\n document: AsyncApiDocument\n /** Key in document.operations. */\n operationName: string\n}>()\n\ntype PickerOptions = Record<string, { summary: string }>\ntype MessageExample = Exclude<\n NonNullable<AsyncApiMessageObject['examples']>[number],\n { $ref: string }\n> & { key: string }\nconst context = computed<ReturnType<typeof getAsyncApiExampleContext>>(() =>\n getAsyncApiExampleContext(document, operationName),\n)\nconst channelPathParts = computed(() =>\n (context.value?.channel?.address ?? operationName).split(/({[^}]+})/),\n)\n\nconst selectedMessage = defineModel<string>('selectedMessage', { default: '' })\nconst selectedExample = ref<string>('')\nconst messages = computed<PickerOptions>(() =>\n Object.fromEntries(\n (context.value?.messages ?? []).map(({ name, message }) => [\n name,\n { summary: message.title || message.name || name },\n ]),\n ),\n)\nconst message = computed<AsyncApiMessageObject | undefined>(\n () =>\n context.value?.messages.find(({ name }) => name === selectedMessage.value)\n ?.message,\n)\nconst examples = computed<MessageExample[]>(() =>\n (message.value?.examples ?? []).flatMap((node, index) => {\n const example = getResolvedAsyncApiRef(node)\n return example?.payload !== undefined\n ? [{ key: String(index), ...example }]\n : []\n }),\n)\nconst exampleOptions = computed<PickerOptions>(() =>\n Object.fromEntries(\n examples.value.map((example, index) => [\n example.key,\n { summary: example.name || example.summary || `Example ${index + 1}` },\n ]),\n ),\n)\nconst example = computed<MessageExample | undefined>(() =>\n examples.value.find(({ key }) => key === selectedExample.value),\n)\nconst messageLabel = computed<string>(\n () =>\n `Message: ${messages.value[selectedMessage.value]?.summary ?? 'Select a message'}`,\n)\nconst exampleLabel = computed<string>(\n () =>\n `Message example: ${exampleOptions.value[selectedExample.value]?.summary ?? 'Select an example'}`,\n)\n\n// Keep selections valid when operations, messages, or the active document change.\nwatch(\n messages,\n (options) => {\n if (!Object.hasOwn(options, selectedMessage.value))\n selectedMessage.value = Object.keys(options)[0] ?? ''\n },\n { immediate: true },\n)\nwatch([selectedMessage, () => operationName], () => {\n selectedExample.value = Object.keys(exampleOptions.value)[0] ?? ''\n})\nwatch(\n exampleOptions,\n (options) => {\n if (!Object.hasOwn(options, selectedExample.value))\n selectedExample.value = Object.keys(options)[0] ?? ''\n },\n { immediate: true },\n)\nconst content = computed(() =>\n getMessageExampleContent(\n example.value\n ? example.value.payload\n : message.value\n ? getGeneratedPayloadExample(message.value)\n : undefined,\n message.value?.contentType ?? document.defaultContentType,\n ),\n)\n</script>\n\n<template>\n <ScalarCard\n class=\"request-card dark-mode min-w-0\"\n label=\"Message example\">\n <ScalarCardHeader\n class=\"flex-nowrap items-start gap-3 pr-2.5 [&_.scalar-card-header-title]:flex-1 [&_.scalar-card-header-title]:whitespace-normal [&>div:last-child]:shrink-0\">\n <span class=\"sr-only\">Message example for</span>\n <span\n class=\"font-code mr-1.5 uppercase\"\n :class=\"\n context?.operation.action === 'send' ? 'text-blue' : 'text-green'\n \"\n >{{ context?.operation.action }}</span\n >\n <span class=\"text-c-2 font-code min-w-0 font-semibold break-words\">\n <template\n v-for=\"(part, index) in channelPathParts\"\n :key=\"index\">\n <span\n v-if=\"part.startsWith('{') && part.endsWith('}')\"\n class=\"text-c-1 whitespace-nowrap\"\n >{{ part }}</span\n >\n <ScalarWrappingText\n v-else\n :text=\"part\" />\n </template>\n </span>\n </ScalarCardHeader>\n <ScalarCardSection class=\"custom-scroll flex flex-1 p-0\">\n <div class=\"flex w-full flex-col\">\n <p\n v-if=\"content?.structural\"\n class=\"text-c-2 px-3 py-2 text-sm\">\n Structure only; not encoded\n </p>\n <ScalarCodeBlock\n v-if=\"content\"\n class=\"h-full bg-transparent\"\n :content=\"content.content\"\n :lang=\"content.lang\"\n lineNumbers />\n <p\n v-else\n class=\"text-c-2 p-4\"\n role=\"status\">\n No message payload example available.\n </p>\n </div>\n </ScalarCardSection>\n <ScalarCardFooter\n v-if=\"Object.keys(messages).length || examples.length\"\n class=\"relative flex shrink-0 flex-wrap items-center justify-end gap-2 p-1.5\">\n <div class=\"flex min-w-0 flex-1 flex-wrap items-center gap-2\">\n <ExamplePicker\n v-if=\"examples.length > 1\"\n v-model=\"selectedExample\"\n :aria-label=\"exampleLabel\"\n :examples=\"exampleOptions\" />\n <span\n v-else-if=\"examples.length === 1\"\n class=\"text-c-2 min-w-0 truncate px-1.5 py-0.75 text-base\">\n {{ exampleOptions[selectedExample]?.summary }}\n </span>\n <div class=\"ml-auto flex min-w-0 items-center\">\n <ExamplePicker\n v-if=\"Object.keys(messages).length > 1\"\n v-model=\"selectedMessage\"\n :aria-label=\"messageLabel\"\n :examples=\"messages\" />\n <span\n v-else-if=\"Object.keys(messages).length === 1\"\n class=\"text-c-2 min-w-0 truncate px-1.5 py-0.75 text-base\">\n {{ messages[selectedMessage]?.summary }}\n </span>\n </div>\n </div>\n </ScalarCardFooter>\n </ScalarCard>\n</template>\n\n<style scoped>\n.request-card {\n color: var(--scalar-color-1);\n font-size: var(--scalar-font-size-3);\n}\n</style>\n"],"mappings":""}
1
+ {"version":3,"file":"AsyncApiCodeExample.vue.js","names":["AsyncApiCodeExample_vue_vue_type_script_setup_true_lang_default","_plugin_vue_export_helper_default","AsyncApiCodeExample_default"],"sources":[],"mappings":""}
@@ -7,7 +7,7 @@ import { ScalarCard as S, ScalarCardFooter as C, ScalarCardHeader as w, ScalarCa
7
7
  import { ScalarCodeBlock as E } from "@scalar/components/code-block";
8
8
  import { ScalarWrappingText as D } from "@scalar/components/wrapping-text";
9
9
  import { getResolvedAsyncApiRef as O } from "@scalar/workspace-store/helpers/get-resolved-async-api-ref";
10
- //#region src/code-example/components/AsyncApiCodeExample.vue?vue&type=script&setup=true&lang.ts
10
+ // src/code-example/components/AsyncApiCodeExample.vue?vue&type=script&setup=true&lang.ts
11
11
  var k = { class: "text-c-2 font-code min-w-0 font-semibold break-words" }, A = {
12
12
  key: 0,
13
13
  class: "text-c-1 whitespace-nowrap"
@@ -108,7 +108,6 @@ var k = { class: "text-c-2 font-code min-w-0 font-semibold break-words" }, A = {
108
108
  }));
109
109
  }
110
110
  });
111
- //#endregion
112
111
  export { R as default };
113
112
 
114
113
  //# sourceMappingURL=AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_openBlock","_createBlock","_unref","_withCtx","_createVNode","_createElementVNode","_normalizeClass","_toDisplayString","_createElementBlock","_Fragment","_renderList","_createCommentVNode","ExamplePicker","ExamplePicker_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","AsyncApiCodeExample_vue_vue_type_script_setup_true_lang_default","\"selectedMessage\"","\"selectedMessageModifiers\"","context","computed","getAsyncApiExampleContext","__props","channelPathParts","selectedMessage","useModel","selectedExample","ref","messages","name","message","examples","example","getResolvedAsyncApiRef","node","index","exampleOptions","key","messageLabel","exampleLabel","watch","options","content","getMessageExampleContent","getGeneratedPayloadExample","openBlock","createBlock","unref","ScalarCard","withCtx","createVNode","ScalarCardHeader","_cache","createElementVNode","normalizeClass","toDisplayString","createElementBlock","Fragment","renderList","part","ScalarWrappingText","ScalarCardSection","createCommentVNode","ScalarCodeBlock","ScalarCardFooter","$event"],"sources":["../../../src/code-example/components/AsyncApiCodeExample.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ScalarCard,\n ScalarCardFooter,\n ScalarCardHeader,\n ScalarCardSection,\n} from '@scalar/components/card'\nimport { ScalarCodeBlock } from '@scalar/components/code-block'\nimport { ScalarWrappingText } from '@scalar/components/wrapping-text'\nimport type {\n AsyncApiDocument,\n AsyncApiMessageObject,\n} from '@scalar/types/asyncapi/3.1'\nimport { getResolvedAsyncApiRef } from '@scalar/workspace-store/helpers/get-resolved-async-api-ref'\nimport { computed, ref, watch } from 'vue'\n\nimport { getAsyncApiExampleContext } from '../helpers/get-asyncapi-example-context'\nimport { getGeneratedPayloadExample } from '../helpers/get-generated-payload-example'\nimport { getMessageExampleContent } from '../helpers/get-message-example-content'\nimport ExamplePicker from './ExamplePicker.vue'\n\nconst { document, operationName } = defineProps<{\n /** A workspace-resolved AsyncAPI 3.x document. */\n document: AsyncApiDocument\n /** Key in document.operations. */\n operationName: string\n}>()\n\ntype PickerOptions = Record<string, { summary: string }>\ntype MessageExample = Exclude<\n NonNullable<AsyncApiMessageObject['examples']>[number],\n { $ref: string }\n> & { key: string }\nconst context = computed<ReturnType<typeof getAsyncApiExampleContext>>(() =>\n getAsyncApiExampleContext(document, operationName),\n)\nconst channelPathParts = computed(() =>\n (context.value?.channel?.address ?? operationName).split(/({[^}]+})/),\n)\n\nconst selectedMessage = defineModel<string>('selectedMessage', { default: '' })\nconst selectedExample = ref<string>('')\nconst messages = computed<PickerOptions>(() =>\n Object.fromEntries(\n (context.value?.messages ?? []).map(({ name, message }) => [\n name,\n { summary: message.title || message.name || name },\n ]),\n ),\n)\nconst message = computed<AsyncApiMessageObject | undefined>(\n () =>\n context.value?.messages.find(({ name }) => name === selectedMessage.value)\n ?.message,\n)\nconst examples = computed<MessageExample[]>(() =>\n (message.value?.examples ?? []).flatMap((node, index) => {\n const example = getResolvedAsyncApiRef(node)\n return example?.payload !== undefined\n ? [{ key: String(index), ...example }]\n : []\n }),\n)\nconst exampleOptions = computed<PickerOptions>(() =>\n Object.fromEntries(\n examples.value.map((example, index) => [\n example.key,\n { summary: example.name || example.summary || `Example ${index + 1}` },\n ]),\n ),\n)\nconst example = computed<MessageExample | undefined>(() =>\n examples.value.find(({ key }) => key === selectedExample.value),\n)\nconst messageLabel = computed<string>(\n () =>\n `Message: ${messages.value[selectedMessage.value]?.summary ?? 'Select a message'}`,\n)\nconst exampleLabel = computed<string>(\n () =>\n `Message example: ${exampleOptions.value[selectedExample.value]?.summary ?? 'Select an example'}`,\n)\n\n// Keep selections valid when operations, messages, or the active document change.\nwatch(\n messages,\n (options) => {\n if (!Object.hasOwn(options, selectedMessage.value))\n selectedMessage.value = Object.keys(options)[0] ?? ''\n },\n { immediate: true },\n)\nwatch([selectedMessage, () => operationName], () => {\n selectedExample.value = Object.keys(exampleOptions.value)[0] ?? ''\n})\nwatch(\n exampleOptions,\n (options) => {\n if (!Object.hasOwn(options, selectedExample.value))\n selectedExample.value = Object.keys(options)[0] ?? ''\n },\n { immediate: true },\n)\nconst content = computed(() =>\n getMessageExampleContent(\n example.value\n ? example.value.payload\n : message.value\n ? getGeneratedPayloadExample(message.value)\n : undefined,\n message.value?.contentType ?? document.defaultContentType,\n ),\n)\n</script>\n\n<template>\n <ScalarCard\n class=\"request-card dark-mode min-w-0\"\n label=\"Message example\">\n <ScalarCardHeader\n class=\"flex-nowrap items-start gap-3 pr-2.5 [&_.scalar-card-header-title]:flex-1 [&_.scalar-card-header-title]:whitespace-normal [&>div:last-child]:shrink-0\">\n <span class=\"sr-only\">Message example for</span>\n <span\n class=\"font-code mr-1.5 uppercase\"\n :class=\"\n context?.operation.action === 'send' ? 'text-blue' : 'text-green'\n \"\n >{{ context?.operation.action }}</span\n >\n <span class=\"text-c-2 font-code min-w-0 font-semibold break-words\">\n <template\n v-for=\"(part, index) in channelPathParts\"\n :key=\"index\">\n <span\n v-if=\"part.startsWith('{') && part.endsWith('}')\"\n class=\"text-c-1 whitespace-nowrap\"\n >{{ part }}</span\n >\n <ScalarWrappingText\n v-else\n :text=\"part\" />\n </template>\n </span>\n </ScalarCardHeader>\n <ScalarCardSection class=\"custom-scroll flex flex-1 p-0\">\n <div class=\"flex w-full flex-col\">\n <p\n v-if=\"content?.structural\"\n class=\"text-c-2 px-3 py-2 text-sm\">\n Structure only; not encoded\n </p>\n <ScalarCodeBlock\n v-if=\"content\"\n class=\"h-full bg-transparent\"\n :content=\"content.content\"\n :lang=\"content.lang\"\n lineNumbers />\n <p\n v-else\n class=\"text-c-2 p-4\"\n role=\"status\">\n No message payload example available.\n </p>\n </div>\n </ScalarCardSection>\n <ScalarCardFooter\n v-if=\"Object.keys(messages).length || examples.length\"\n class=\"relative flex shrink-0 flex-wrap items-center justify-end gap-2 p-1.5\">\n <div class=\"flex min-w-0 flex-1 flex-wrap items-center gap-2\">\n <ExamplePicker\n v-if=\"examples.length > 1\"\n v-model=\"selectedExample\"\n :aria-label=\"exampleLabel\"\n :examples=\"exampleOptions\" />\n <span\n v-else-if=\"examples.length === 1\"\n class=\"text-c-2 min-w-0 truncate px-1.5 py-0.75 text-base\">\n {{ exampleOptions[selectedExample]?.summary }}\n </span>\n <div class=\"ml-auto flex min-w-0 items-center\">\n <ExamplePicker\n v-if=\"Object.keys(messages).length > 1\"\n v-model=\"selectedMessage\"\n :aria-label=\"messageLabel\"\n :examples=\"messages\" />\n <span\n v-else-if=\"Object.keys(messages).length === 1\"\n class=\"text-c-2 min-w-0 truncate px-1.5 py-0.75 text-base\">\n {{ messages[selectedMessage]?.summary }}\n </span>\n </div>\n </div>\n </ScalarCardFooter>\n </ScalarCard>\n</template>\n\n<style scoped>\n.request-card {\n color: var(--scalar-color-1);\n font-size: var(--scalar-font-size-3);\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCA,IAAM2B,IAAUC,QACdC,EAA0BC,EAAA,UAAUA,EAAA,aAAa,CACnD,GACMC,IAAmBH,SACtBD,EAAQ,OAAO,SAAS,WAAWG,EAAA,cAAA,CAAe,MAAM,WAAW,CACtE,GAEME,IAAkBhC,EAAmB8B,GAAC,iBAAkC,GACxEI,IAAkBC,EAAY,EAAE,GAChCC,IAAWR,QACf,OAAO,aACJD,EAAQ,OAAO,YAAY,CAAC,EAAA,CAAG,KAAK,EAAE,SAAM,iBAAc,CACzDU,GACA,EAAE,SAASC,EAAQ,SAASA,EAAQ,QAAQD,EAAK,CACnD,CAAC,CACH,CACF,GACMC,IAAUV,QAEZD,EAAQ,OAAO,SAAS,MAAM,EAAE,cAAWU,MAASL,EAAgB,KAAK,CAAA,EACrE,OACR,GACMO,IAA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A,MAAS,UADjDtC,EAAA,GAAAC,EA2BmBC,EAAAqE,CAAA,GAAA;;KAzBjB,OAAM;;KACN,SAAApE,QAuBM,CAvBNE,EAuBM,OAvBNc,GAuBM,CArBImB,EAAA,MAAS,SAAM,KADvBtC,EAAA,GAAAC,EAI+BW,GAAA;;MAFpB,YAAAqB,EAAA;MAAA,uBAAA,AAAA0B,EAAA,QAAA,MAAA,EAAe,QAAAa;MACvB,cAAY1B,EAAA;MACZ,UAAUH,EAAA;;;;;K,MAEAL,EAAA,MAAS,WAAM,KAD5BtC,EAAA,GAAAQ,EAIO,QAJPY,GAIOb,EADFoC,EAAA,MAAeV,EAAA,MAAe,EAAG,OAAO,GAAA,CAAA,K,WAE7C5B,EAWM,OAXNgB,GAWM,CATI,OAAO,KAAKc,EAAA,KAAQ,CAAA,CAAE,SAAM,KADpCnC,EAAA,GAAAC,EAIyBW,GAAA;;MAFd,YAAAmB,EAAA;MAAA,uBAAA,AAAA4B,EAAA,QAAA,MAAA,EAAe,QAAAa;MACvB,cAAY3B,EAAA;MACZ,UAAUV,EAAA;;;;;K,MAEA,OAAO,KAAKA,EAAA,KAAQ,CAAA,CAAE,WAAM,KADzCnC,EAAA,GAAAQ,EAIO,QAJPc,GAIOf,EADF4B,EAAA,MAASJ,EAAA,MAAe,EAAG,OAAO,GAAA,CAAA,K"}
1
+ {"version":3,"file":"AsyncApiCodeExample.vue_vue_type_script_setup_true_lang.js","names":["_useModel","_openBlock","_createBlock","_unref","_withCtx","_createVNode","_createElementVNode","_normalizeClass","_toDisplayString","_createElementBlock","_Fragment","_renderList","ExamplePicker","ExamplePicker_default","_hoisted_1","_hoisted_2","_hoisted_3","_hoisted_4","_hoisted_5","_hoisted_6","_hoisted_7","_hoisted_8","_hoisted_9","AsyncApiCodeExample_vue_vue_type_script_setup_true_lang_default","\"selectedMessage\"","\"selectedMessageModifiers\"","context","computed","getAsyncApiExampleContext","__props","channelPathParts","selectedMessage","useModel","selectedExample","ref","messages","name","message","examples","example","getResolvedAsyncApiRef","node","index","exampleOptions","key","messageLabel","exampleLabel","watch","options","content","getMessageExampleContent","getGeneratedPayloadExample","openBlock","createBlock","unref","ScalarCard","withCtx","createVNode","ScalarCardHeader","_cache","createElementVNode","normalizeClass","toDisplayString","createElementBlock","Fragment","renderList","part","ScalarWrappingText","ScalarCardSection","createCommentVNode","ScalarCodeBlock","ScalarCardFooter","$event"],"sources":["../../../src/code-example/components/AsyncApiCodeExample.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ScalarCard,\n ScalarCardFooter,\n ScalarCardHeader,\n ScalarCardSection,\n} from '@scalar/components/card'\nimport { ScalarCodeBlock } from '@scalar/components/code-block'\nimport { ScalarWrappingText } from '@scalar/components/wrapping-text'\nimport type {\n AsyncApiDocument,\n AsyncApiMessageObject,\n} from '@scalar/types/asyncapi/3.1'\nimport { getResolvedAsyncApiRef } from '@scalar/workspace-store/helpers/get-resolved-async-api-ref'\nimport { computed, ref, watch } from 'vue'\n\nimport { getAsyncApiExampleContext } from '../helpers/get-asyncapi-example-context'\nimport { getGeneratedPayloadExample } from '../helpers/get-generated-payload-example'\nimport { getMessageExampleContent } from '../helpers/get-message-example-content'\nimport ExamplePicker from './ExamplePicker.vue'\n\nconst { document, operationName } = defineProps<{\n /** A workspace-resolved AsyncAPI 3.x document. */\n document: AsyncApiDocument\n /** Key in document.operations. */\n operationName: string\n}>()\n\ntype PickerOptions = Record<string, { summary: string }>\ntype MessageExample = Exclude<\n NonNullable<AsyncApiMessageObject['examples']>[number],\n { $ref: string }\n> & { key: string }\nconst context = computed<ReturnType<typeof getAsyncApiExampleContext>>(() =>\n getAsyncApiExampleContext(document, operationName),\n)\nconst channelPathParts = computed(() =>\n (context.value?.channel?.address ?? operationName).split(/({[^}]+})/),\n)\n\nconst selectedMessage = defineModel<string>('selectedMessage', { default: '' })\nconst selectedExample = ref<string>('')\nconst messages = computed<PickerOptions>(() =>\n Object.fromEntries(\n (context.value?.messages ?? []).map(({ name, message }) => [\n name,\n { summary: message.title || message.name || name },\n ]),\n ),\n)\nconst message = computed<AsyncApiMessageObject | undefined>(\n () =>\n context.value?.messages.find(({ name }) => name === selectedMessage.value)\n ?.message,\n)\nconst examples = computed<MessageExample[]>(() =>\n (message.value?.examples ?? []).flatMap((node, index) => {\n const example = getResolvedAsyncApiRef(node)\n return example?.payload !== undefined\n ? [{ key: String(index), ...example }]\n : []\n }),\n)\nconst exampleOptions = computed<PickerOptions>(() =>\n Object.fromEntries(\n examples.value.map((example, index) => [\n example.key,\n { summary: example.name || example.summary || `Example ${index + 1}` },\n ]),\n ),\n)\nconst example = computed<MessageExample | undefined>(() =>\n examples.value.find(({ key }) => key === selectedExample.value),\n)\nconst messageLabel = computed<string>(\n () =>\n `Message: ${messages.value[selectedMessage.value]?.summary ?? 'Select a message'}`,\n)\nconst exampleLabel = computed<string>(\n () =>\n `Message example: ${exampleOptions.value[selectedExample.value]?.summary ?? 'Select an example'}`,\n)\n\n// Keep selections valid when operations, messages, or the active document change.\nwatch(\n messages,\n (options) => {\n if (!Object.hasOwn(options, selectedMessage.value))\n selectedMessage.value = Object.keys(options)[0] ?? ''\n },\n { immediate: true },\n)\nwatch([selectedMessage, () => operationName], () => {\n selectedExample.value = Object.keys(exampleOptions.value)[0] ?? ''\n})\nwatch(\n exampleOptions,\n (options) => {\n if (!Object.hasOwn(options, selectedExample.value))\n selectedExample.value = Object.keys(options)[0] ?? ''\n },\n { immediate: true },\n)\nconst content = computed(() =>\n getMessageExampleContent(\n example.value\n ? example.value.payload\n : message.value\n ? getGeneratedPayloadExample(message.value)\n : undefined,\n message.value?.contentType ?? document.defaultContentType,\n ),\n)\n</script>\n\n<template>\n <ScalarCard\n class=\"request-card dark-mode min-w-0\"\n label=\"Message example\">\n <ScalarCardHeader\n class=\"flex-nowrap items-start gap-3 pr-2.5 [&_.scalar-card-header-title]:flex-1 [&_.scalar-card-header-title]:whitespace-normal [&>div:last-child]:shrink-0\">\n <span class=\"sr-only\">Message example for</span>\n <span\n class=\"font-code mr-1.5 uppercase\"\n :class=\"\n context?.operation.action === 'send' ? 'text-blue' : 'text-green'\n \"\n >{{ context?.operation.action }}</span\n >\n <span class=\"text-c-2 font-code min-w-0 font-semibold break-words\">\n <template\n v-for=\"(part, index) in channelPathParts\"\n :key=\"index\">\n <span\n v-if=\"part.startsWith('{') && part.endsWith('}')\"\n class=\"text-c-1 whitespace-nowrap\"\n >{{ part }}</span\n >\n <ScalarWrappingText\n v-else\n :text=\"part\" />\n </template>\n </span>\n </ScalarCardHeader>\n <ScalarCardSection class=\"custom-scroll flex flex-1 p-0\">\n <div class=\"flex w-full flex-col\">\n <p\n v-if=\"content?.structural\"\n class=\"text-c-2 px-3 py-2 text-sm\">\n Structure only; not encoded\n </p>\n <ScalarCodeBlock\n v-if=\"content\"\n class=\"h-full bg-transparent\"\n :content=\"content.content\"\n :lang=\"content.lang\"\n lineNumbers />\n <p\n v-else\n class=\"text-c-2 p-4\"\n role=\"status\">\n No message payload example available.\n </p>\n </div>\n </ScalarCardSection>\n <ScalarCardFooter\n v-if=\"Object.keys(messages).length || examples.length\"\n class=\"relative flex shrink-0 flex-wrap items-center justify-end gap-2 p-1.5\">\n <div class=\"flex min-w-0 flex-1 flex-wrap items-center gap-2\">\n <ExamplePicker\n v-if=\"examples.length > 1\"\n v-model=\"selectedExample\"\n :aria-label=\"exampleLabel\"\n :examples=\"exampleOptions\" />\n <span\n v-else-if=\"examples.length === 1\"\n class=\"text-c-2 min-w-0 truncate px-1.5 py-0.75 text-base\">\n {{ exampleOptions[selectedExample]?.summary }}\n </span>\n <div class=\"ml-auto flex min-w-0 items-center\">\n <ExamplePicker\n v-if=\"Object.keys(messages).length > 1\"\n v-model=\"selectedMessage\"\n :aria-label=\"messageLabel\"\n :examples=\"messages\" />\n <span\n v-else-if=\"Object.keys(messages).length === 1\"\n class=\"text-c-2 min-w-0 truncate px-1.5 py-0.75 text-base\">\n {{ messages[selectedMessage]?.summary }}\n </span>\n </div>\n </div>\n </ScalarCardFooter>\n </ScalarCard>\n</template>\n\n<style scoped>\n.request-card {\n color: var(--scalar-color-1);\n font-size: var(--scalar-font-size-3);\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCA,IAAM0B,IAAUC,QACdC,EAA0BC,EAAA,UAAUA,EAAA,aAAa,CACnD,GACMC,IAAmBH,SACtBD,EAAQ,OAAO,SAAS,WAAWG,EAAA,cAAA,CAAe,MAAM,WAAW,CACtE,GAEME,IAAkB/B,EAAmB6B,GAAC,iBAAkC,GACxEI,IAAkBC,EAAY,EAAE,GAChCC,IAAWR,QACf,OAAO,aACJD,EAAQ,OAAO,YAAY,CAAC,EAAA,CAAG,KAAK,EAAE,SAAM,iBAAc,CACzDU,GACA,EAAE,SAASC,EAAQ,SAASA,EAAQ,QAAQD,EAAK,CACnD,CAAC,CACH,CACF,GACMC,IAAUV,QAEZD,EAAQ,OAAO,SAAS,MAAM,EAAE,cAAWU,MAASL,EAAgB,KAAK,CAAA,EACrE,OACR,GACMO,IAAWX,SACdU,EAAQ,OAAO,YAAY,CAAC,EAAA,CAAG,SAAS,GAAM,MAAU;GACvD,IAAME,IAAUC,EAAuBC,CAAI;GAC3C,OAAOF,GAAS,YAAY,KAAA,IAExB,CAAC,IADD,CAAC;IAAE,KAAK,OAAOG,CAAK;IAAG,GAAGH;GAAQ,CAAC;EAEzC,CAAC,CACH,GACMI,IAAiBhB,QACrB,OAAO,YACLW,EAAS,MAAM,KAAK,GAAS,MAAU,CACrCC,EAAQ,KACR,EAAE,SAASA,EAAQ,QAAQA,EAAQ,WAAW,WAAWG,IAAQ,IAAI,CACvE,CAAC,CACH,CACF,GACMH,IAAUZ,QACdW,EAAS,MAAM,MAAM,EAAE,aAAUM,MAAQX,EAAgB,KAAK,CAChE,GACMY,IAAelB,QAEjB,YAAYQ,EAAS,MAAMJ,EAAgB,MAAM,EAAE,WAAW,oBAClE,GACMe,IAAenB,QAEjB,oBAAoBgB,EAAe,M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A,uBAAA,AAAA4B,EAAA,QAAA,MAAA,EAAe,QAAAa;MACvB,cAAY3B,EAAA;MACZ,UAAUV,EAAA;;;;;K,MAEA,OAAO,KAAKA,EAAA,KAAQ,CAAA,CAAE,WAAM,KADzClC,EAAA,GAAAQ,EAIO,QAJPa,GAIOd,EADF2B,EAAA,MAASJ,EAAA,MAAe,EAAG,OAAO,GAAA,CAAA,K"}
@@ -123,6 +123,8 @@ export type CodeExampleProps = {
123
123
  */
124
124
  /** Originating OpenAPI version, used for XML mapping rules. */
125
125
  openapiVersion?: string;
126
+ /** Document-level JSON Schema dialect used when generating array `contains` examples. */
127
+ jsonSchemaDialect?: string;
126
128
  requestBodyCompositionSelection?: Record<string, number>;
127
129
  };
128
130
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"CodeExample.vue.d.ts","sourceRoot":"","sources":["../../../src/code-example/components/CodeExample.vue"],"names":[],"mappings":"AA+wBA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAUvE,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qEAAqE,CAAA;AACxG,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACb,MAAM,8DAA8D,CAAA;AAiBrE,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,UAAU,CAAA;AAKjB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,uFAAuF;IACvF,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,+EAA+E;IAC/E,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;OAGG;IACH,WAAW,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;IACpC;;OAEG;IACH,aAAa,EAAE,iBAAiB,EAAE,CAAA;IAClC;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AA;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,+DAA+D;IAC/D,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,yFAAyF;IACzF,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,+BAA+B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACzD,CAAA;AAED;;;;;;;;GAQG;wBACkB,OAAO,YAAY;AAAxC,wBAAyC;AAGzC,QAAA,MAAM,YAAY;;;;;YAwCN,MAAM,OAAO;IACvB,kGAAkG;qBACjF,MAAM,OAAO;YACpB,CAAC,EAAE,WAAW,EAAE,EAAE;QAAE,WAAW,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO;EAgzB7D,CAAC;AACL,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
@@ -1,9 +1,8 @@
1
- import e from "../../_virtual/_plugin-vue_export-helper.js";
2
- import t from "./CodeExample.vue_vue_type_script_setup_true_lang.js";
1
+ import e from "./CodeExample.vue_vue_type_script_setup_true_lang.js";
3
2
  /* empty css */
4
- //#region src/code-example/components/CodeExample.vue
5
- var n = /*#__PURE__*/ e(t, [["__scopeId", "data-v-8530ae0b"]]);
6
- //#endregion
3
+ import t from "../../_virtual/_plugin-vue_export-helper.js";
4
+ // src/code-example/components/CodeExample.vue
5
+ var n = /*#__PURE__*/ t(e, [["__scopeId", "data-v-5057e16b"]]);
7
6
  export { n as default };
8
7
 
9
8
  //# sourceMappingURL=CodeExample.vue.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CodeExample.vue.js","names":["_sfc_main","_plugin_vue_export_helper_default","CodeExample_vue_vue_type_script_setup_true_lang_default","CodeExample_default"],"sources":["../../../src/code-example/components/CodeExample.vue"],"sourcesContent":["<script lang=\"ts\">\nexport type CodeExampleProps = {\n /** Localized status text shown when the selected example has no linked code sample. */\n codeSampleUnavailable?: string\n /**\n * Localized purpose of the client picker. It opens the button's accessible name and the\n * selected client's title is appended, so the name still contains the visible label.\n */\n clientPickerLabel?: string\n /** Localized accessible name for the search field inside the client picker. */\n clientSearchLabel?: string\n /**\n * Localized accessible name for the focusable code sample. The selected client's title is\n * appended so the announcement also says which language the sample is in.\n */\n codeSampleLabel?: string\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: string\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 /** Originating OpenAPI version, used for XML mapping rules. */\n openapiVersion?: string\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 {\n ScalarCodeBlock,\n ScalarCodeBlockCopy,\n} 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 { 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 {\n resolveCredentialPlaceholders,\n type SecuritySchemeObjectSecret,\n} 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 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 codeSampleUnavailable = 'No code sample available for this example.',\n clientPickerLabel = 'Change code sample language',\n clientSearchLabel = 'Search clients',\n codeSampleLabel = 'Code sample',\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 openapiVersion,\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 /** Rendered at the start of the footer, only while the example picker does not need that space */\n 'footer-start'?: () => 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.\n// This runs during setup so the server renders the same example as the browser.\nlocalExampleKey.value = resolveExampleKey(selectedExample)\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/**\n * Accessible name for the client picker.\n *\n * On its own the button reads as its current value (\"C Libcurl\"), which never\n * says what activating it does. The visible title stays part of the name so it\n * still matches what is on screen.\n */\nconst clientPickerAriaLabel = computed(() =>\n [clientPickerLabel, localSelectedClient.value?.title]\n .filter(Boolean)\n .join(': '),\n)\n\n/**\n * Accessible name for the focusable code sample, e.g. \"Code sample: Shell cURL\".\n *\n * Screen readers announce only the name and role when focus lands on the scroller, so the\n * name tells the user both what the region is and which client it is generated for.\n */\nconst codeSampleAriaLabel = computed(() =>\n [codeSampleLabel, localSelectedClient.value?.title]\n .filter(Boolean)\n .join(': '),\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/** Keep the picker available because it also selects the example opened by Test Request. */\nconst showExamplePicker = computed(\n () => Object.keys(requestBodyExamples.value).length > 1,\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 openapiVersion,\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 generatedTemplate = computed<string | null>(() => {\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 openapiVersion,\n requestBodyCompositionSelection,\n })\n})\n\n/** Resolve custom templates at render time so auth changes never mutate the document. */\nconst resolvedCredentials = computed(() =>\n !isWebhook &&\n localSelectedClient.value?.id.startsWith('custom/') &&\n generatedTemplate.value !== null &&\n securitySchemes.some((scheme) => 'x-scalar-credential-placeholders' in scheme)\n ? resolveCredentialPlaceholders(generatedTemplate.value, securitySchemes)\n : undefined,\n)\n\nconst generatedCode = computed(\n () => resolvedCredentials.value?.content ?? generatedTemplate.value,\n)\n\n/** Mask inserted secrets before escaping or syntax tokenization can split their values. */\nconst displayCode = computed(\n () => resolvedCredentials.value?.displayContent ?? generatedCode.value,\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(() =>\n resolvedCredentials.value ? [] : getSecrets(securitySchemes),\n)\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=\"\n generatedCode === null || generatedCode || externalExamples.pending.value\n \"\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 v-slot=\"{ open }\"\n class=\"max-h-80\"\n :filterFn=\"filterClientsByQuery\"\n :inputLabel=\"clientSearchLabel\"\n :modelValue=\"localSelectedClient\"\n :options=\"clients\"\n placement=\"bottom-end\"\n teleport\n @update:modelValue=\"selectClient($event as ClientOption)\">\n <ScalarButton\n :aria-label=\"clientPickerAriaLabel\"\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 <!--\n Follow this picker's own state. The `ui-open:` variant also matches any open\n Headless UI ancestor, such as an expanded operation in the classic layout.\n -->\n <ScalarIconCaretDown\n class=\"mt-px size-3 transition-transform duration-100\"\n :class=\"{ 'rotate-180': open }\"\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-if=\"generatedCode === null\"\n class=\"text-c-2 p-4\"\n role=\"status\">\n {{ codeSampleUnavailable }}\n </div>\n <div\n v-else\n :id=\"`${id}-example`\"\n class=\"code-snippet group/code-block relative\">\n <ScalarCodeBlock\n v-if=\"!shouldVirtualize\"\n class=\"h-full bg-transparent\"\n :content=\"displayCode ?? ''\"\n :copyContent=\"resolvedCredentials ? (generatedCode ?? '') : undefined\"\n :hideCredentials=\"secretCredentials\"\n :label=\"codeSampleAriaLabel\"\n :lang=\"codeBlockLanguage\"\n lineNumbers />\n <template v-else>\n <ScalarCodeBlockCopy\n :aria-controls=\"`${id}-virtual-code`\"\n class=\"scalar-code-copy absolute top-2.5 right-2.5 z-1\"\n :content=\"generatedCode\"\n :lang=\"codeBlockLanguage\" />\n <ScalarVirtualText\n :id=\"`${id}-virtual-code`\"\n aria-label=\"Request code sample\"\n containerClass=\"custom-scroll scalar-code-block flex flex-1 max-h-screen\"\n contentClass=\"language-plaintext whitespace-pre font-code text-base p-2\"\n :lineHeight=\"20\"\n role=\"region\"\n :text=\"displayCode ?? ''\" />\n </template>\n </div>\n </ScalarCardSection>\n\n <!-- Footer -->\n <ScalarCardFooter\n v-if=\"showExamplePicker || $slots.footer || $slots['footer-start']\"\n class=\"request-card-footer\"\n :class=\"{\n 'request-card-footer--wraps':\n showExamplePicker || $slots['footer-start'],\n }\">\n <!-- Example picker -->\n <div\n v-if=\"showExamplePicker\"\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 <!-- Otherwise the start of the footer is free for the caller -->\n <div\n v-else-if=\"$slots['footer-start']\"\n class=\"request-card-footer-start\">\n <slot name=\"footer-start\" />\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 <!-- A single row of method, path and actions reads as a header, so it stays on the card -->\n <ScalarCardSection class=\"request-card-simple bg-transparent shadow-none\">\n <div class=\"request-header\">\n <HttpMethod\n as=\"span\"\n class=\"request-method\"\n :method=\"method\" />\n <slot name=\"header\" />\n </div>\n <div\n v-if=\"$slots.footer\"\n class=\"request-card-actions relative max-w-full\">\n <slot\n :exampleName=\"localExampleKey\"\n name=\"footer\" />\n </div>\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 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/*\n * The example picker or footer-start content keeps room for itself; when the footer is too narrow\n * for everything, the end controls wrap onto a second line instead of squeezing or covering it.\n */\n.request-card-footer--wraps {\n flex-wrap: wrap;\n row-gap: 4px;\n}\n.request-card-footer-start {\n display: flex;\n align-items: center;\n flex: 1 0 auto;\n}\n/*\n * The picker asks for its example name's width, capped at 7em (about eight characters), so on a\n * narrow card the end controls wrap rather than squeeze the name out of view. The cap keeps a long\n * name truncating beside them on wider cards, as before. The picker never grows past its name, and\n * the end margin holds it at the start of the line.\n */\n.request-card-footer-addon {\n display: flex;\n align-items: center;\n\n flex: 1 1 7em;\n min-width: 0;\n max-width: max-content;\n margin-inline-end: auto;\n}\n.request-editor-section {\n display: flex;\n flex: 1;\n}\n/*\n * A long sample is drawn as virtual text with its own copy button rather than a code block, so\n * that button gets the same raised fill a code block gives its button on a card's surface.\n */\n.code-snippet > .scalar-code-copy {\n background: var(--scalar-card-surface-raised, var(--scalar-background-2));\n}\n.request-card-simple {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n justify-content: space-between;\n gap: 8px;\n\n padding: 8px 8px 8px 12px;\n\n font-size: var(--scalar-small);\n}\n.request-header {\n /* Give spare inline space to the path, while actions fill their own row after wrapping. */\n flex: 999 1 auto;\n min-width: 0;\n overflow-wrap: anywhere;\n}\n.request-card-actions {\n flex: 1 0 auto;\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":["CodeExample_vue_vue_type_script_setup_true_lang_default","_plugin_vue_export_helper_default","CodeExample_default"],"sources":[],"mappings":""}