@scalar/blocks 0.6.4 → 0.7.1
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 +23 -0
- package/dist/code-example/components/CodeExample.vue.d.ts +1 -1
- package/dist/code-example/components/CodeExample.vue.d.ts.map +1 -1
- package/dist/code-example/components/CodeExample.vue.js +1 -1
- package/dist/code-example/components/CodeExample.vue.js.map +1 -1
- package/dist/code-example/components/CodeExample.vue_vue_type_script_setup_true_lang.js +139 -127
- package/dist/code-example/components/CodeExample.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/code-example/helpers/generate-client-options.d.ts +1 -1
- package/dist/code-example/helpers/generate-client-options.d.ts.map +1 -1
- package/dist/code-example/helpers/generate-client-options.js +5 -1
- package/dist/code-example/helpers/generate-client-options.js.map +1 -1
- package/dist/code-example/helpers/get-clients.d.ts.map +1 -1
- package/dist/code-example/helpers/get-clients.js +17 -18
- package/dist/code-example/helpers/get-clients.js.map +1 -1
- package/dist/code-example/helpers/get-snippet.d.ts +1 -1
- package/dist/code-example/helpers/get-snippet.d.ts.map +1 -1
- package/dist/code-example/helpers/get-snippet.js +3 -4
- package/dist/code-example/helpers/get-snippet.js.map +1 -1
- package/dist/code-example/types.d.ts +1 -1
- package/dist/code-example/types.d.ts.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/schema/SchemaPropertyExamples.vue.js +1 -1
- package/dist/schema/SchemaPropertyExamples.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyExamples.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/SchemaPropertyHeading.vue.d.ts +3 -3
- package/dist/schema/SchemaPropertyHeading.vue.d.ts.map +1 -1
- package/dist/schema/SchemaPropertyHeading.vue.js +1 -1
- package/dist/schema/SchemaPropertyHeading.vue.js.map +1 -1
- package/dist/schema/SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js +154 -137
- package/dist/schema/SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/schema/helpers/optimize-value-for-display.d.ts.map +1 -1
- package/dist/schema/helpers/optimize-value-for-display.js +8 -5
- package/dist/schema/helpers/optimize-value-for-display.js.map +1 -1
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +12 -10
- package/dist/schema/protobuf-metadata.d.ts +11 -0
- package/dist/schema/protobuf-metadata.d.ts.map +1 -0
- package/dist/schema/protobuf-metadata.js +6 -0
- package/dist/schema/protobuf-metadata.js.map +1 -0
- package/dist/schema/recursive-metadata.d.ts +8 -0
- package/dist/schema/recursive-metadata.d.ts.map +1 -0
- package/dist/schema/recursive-metadata.js +6 -0
- package/dist/schema/recursive-metadata.js.map +1 -0
- package/dist/style.css +1 -1
- package/dist/vue-styles.css +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SchemaPropertyHeading.vue.js","names":["_sfc_main","_plugin_vue_export_helper_default","SchemaPropertyHeading_vue_vue_type_script_setup_true_lang_default","SchemaPropertyHeading_default"],"sources":["../../src/schema/SchemaPropertyHeading.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport type { WorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type { SchemaObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport {\n isArraySchema,\n isNumberSchema,\n isStringSchema,\n} from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\nimport { computed, toRef } from 'vue'\n\nimport Badge from '../shared/Badge.vue'\nimport { getSchemaType } from './helpers/get-schema-type'\nimport { getDisplayTypeSignatureTokens } from './helpers/get-type-signature-tokens'\nimport {\n isModelLinkable,\n type ModelLinkOptions,\n} from './helpers/is-model-linkable'\nimport { getModelNameWithArray } from './helpers/schema-name'\nimport { useLocalization } from './localization'\nimport RenderString from './RenderString.vue'\nimport SchemaPropertyDefault from './SchemaPropertyDefault.vue'\nimport SchemaPropertyDetail from './SchemaPropertyDetail.vue'\nimport SchemaPropertyExamples from './SchemaPropertyExamples.vue'\nimport SchemaPropertyPattern from './SchemaPropertyPattern.vue'\n\nconst props = withDefaults(\n defineProps<{\n value: SchemaObject | undefined\n enum?: boolean\n isDiscriminator?: boolean\n /** Effective AsyncAPI variant value, separate from const/enum constraints. */\n discriminatorValue?: string\n required?: boolean\n additional?: boolean\n withExamples?: boolean\n hideModelNames?: boolean\n /**\n * Config for deciding whether a model name links to the models section. When the section or\n * the referenced model is hidden there is nothing to scroll to, so the name renders as plain text.\n */\n modelLinkOptions?: ModelLinkOptions\n /** When the schema was resolved from a $ref, pass the ref name so it displays as e.g. \"Data\" instead of \"object\". */\n modelName?: string | null\n /** Resolved propertyNames schema, used to surface key constraints like `format` for additional properties. */\n propertyNames?: SchemaObject\n eventBus?: WorkspaceEventBus | null\n /**\n * The row's name is a stand-in for keys the caller chooses\n * (`additionalProperties`) or keys matching a regex (`patternProperties`),\n * not a literal property. The heading says so in the signature line, where\n * the tree already describes shapes, instead of styling the name itself.\n */\n keyKind?: 'additional' | 'pattern'\n /**\n * The name of the schema this row loops back to. A cut cycle is a leaf, so\n * the signature line says why it does not expand; the model link beside it\n * already names the schema the loop returns to.\n */\n recursiveTo?: string\n }>(),\n {\n isDiscriminator: false,\n required: false,\n withExamples: true,\n hideModelNames: false,\n eventBus: null,\n },\n)\nconst { translate } = useLocalization()\n\n// Convert to reactive refs for composables\nconst valueRef = toRef(props, 'value')\n\nconst constValue = computed(() => {\n if (!valueRef.value) {\n return undefined\n }\n\n const schema = valueRef.value\n\n // Direct const value\n if (schema.const !== undefined) {\n return schema.const\n }\n\n // Single-item enum acts as const\n if (schema.enum?.length === 1) {\n return schema.enum[0]\n }\n\n // Check items for const values (for arrays)\n if (isArraySchema(schema) && schema.items) {\n const items = resolve.schema(schema.items)\n\n if (isDefined(items.const)) {\n return items.const\n }\n\n if (items.enum?.length === 1) {\n return items.enum[0]\n }\n }\n\n return undefined\n})\n\ntype ValidationProperty = {\n key: string\n value: string | number\n prefix?: string\n code?: boolean\n truncate?: boolean\n}\n\n/**\n * Constraints that live on a leaf (string or number) schema: length, pattern,\n * format and numeric ranges. Extracted so they can be surfaced for a primitive\n * schema as well as for a primitive array's items, which are not rendered on\n * their own. See https://github.com/scalar/scalar/issues/9690\n */\nconst getLeafConstraints = (schema: SchemaObject) => {\n const properties: ValidationProperty[] = []\n\n if (isStringSchema(schema)) {\n if (schema.minLength) {\n properties.push({\n key: 'min-length',\n prefix: `${translate('schema.minLength')}: `,\n value: schema.minLength,\n })\n }\n\n if (schema.maxLength) {\n properties.push({\n key: 'max-length',\n prefix: `${translate('schema.maxLength')}: `,\n value: schema.maxLength,\n })\n }\n\n // pattern is rendered via SchemaPropertyPattern (hover dropdown), skip here\n }\n\n if ((isStringSchema(schema) || isNumberSchema(schema)) && schema.format) {\n properties.push({\n key: 'format',\n value: schema.format,\n truncate: true,\n })\n }\n\n if (isNumberSchema(schema)) {\n if (isDefined(schema.exclusiveMinimum)) {\n properties.push({\n key: 'exclusive-minimum',\n prefix: `${translate('schema.greaterThan')}: `,\n value: schema.exclusiveMinimum,\n })\n }\n\n if (isDefined(schema.minimum)) {\n properties.push({\n key: 'minimum',\n prefix: `${translate('schema.min')}: `,\n value: schema.minimum,\n })\n }\n\n if (isDefined(schema.exclusiveMaximum)) {\n properties.push({\n key: 'exclusive-maximum',\n prefix: `${translate('schema.lessThan')}: `,\n value: schema.exclusiveMaximum,\n })\n }\n\n if (isDefined(schema.maximum)) {\n properties.push({\n key: 'maximum',\n prefix: `${translate('schema.max')}: `,\n value: schema.maximum,\n })\n }\n\n if (isDefined(schema.multipleOf)) {\n properties.push({\n key: 'multiple-of',\n prefix: `${translate('schema.multipleOf')}: `,\n value: schema.multipleOf,\n })\n }\n }\n\n return properties\n}\n\nconst validationProperties = computed(() => {\n if (!valueRef.value) {\n return []\n }\n\n const schema = valueRef.value\n const properties: ValidationProperty[] = []\n\n // Array validation properties\n if (isArraySchema(schema)) {\n if (schema.minItems || schema.maxItems) {\n properties.push({\n key: 'array-range',\n value: `${schema.minItems || ''}…${schema.maxItems || ''}`,\n })\n }\n\n // Unique items\n if (schema.uniqueItems) {\n properties.push({\n key: 'unique-items',\n value: `${translate('schema.unique')}!`,\n })\n }\n }\n\n properties.push(...getLeafConstraints(schema))\n\n // Primitive array items carry their own constraints (e.g. an array of `uuid`\n // strings) but are not rendered separately, so surface them here.\n if (isArraySchema(schema) && schema.items) {\n properties.push(...getLeafConstraints(resolve.schema(schema.items)))\n }\n\n return properties\n})\n\n/** Link data for navigating to the referenced model in the sidebar. */\nconst modelLink = computed(() => {\n if (!props.value) {\n return null\n }\n\n if (props.hideModelNames) {\n return null\n }\n\n if (props.modelName) {\n return { schemaKey: props.modelName, label: props.modelName }\n }\n\n return getModelNameWithArray(props.value)\n})\n\n/** Whether the model name links to the models section, or renders as plain text. */\nconst modelLinkable = computed(() =>\n isModelLinkable(modelLink.value?.schemaKey, props.modelLinkOptions ?? {}),\n)\n\n/**\n * The type as a run of tokens rather than a single string — identifiers in\n * the code face, English words like `array of` in the sans face, and a muted\n * `|` so `string | null` reads as one type with an alternative.\n *\n * The token run and the screen-reader label are written straight into the\n * template instead of being their own components: the tree mounts one per\n * typed row, and a component instance costs more to create than the span it\n * renders. On a flat object the type cells would be most of the instance\n * count. The linked and the plain copy of the token markup below must stay\n * identical.\n */\nconst signatureTokens = computed(() =>\n getDisplayTypeSignatureTokens(props.value, {\n hideModelNames: props.hideModelNames,\n modelName: modelLink.value?.label,\n }),\n)\n\n/** Check if we should show the type information */\nconst shouldShowType = computed(() => {\n if (!props.value || !('type' in props.value)) {\n return false\n }\n\n // Always show type for arrays, even when items have const values\n if (props.value.type === 'array') {\n return true\n }\n\n // For non-arrays, only show if no const value at the schema level\n return !constValue.value\n})\n\n/**\n * Type and format of the property keys, derived from the propertyNames schema.\n *\n * For a map keyed by UUIDs this renders e.g. \"string · uuid\" so the key\n * constraints are not lost. Returns undefined when there is nothing to show.\n */\nconst propertyNamesDetail = computed(() => {\n const schema = props.propertyNames\n if (!schema) {\n return undefined\n }\n\n const parts = [getSchemaType(schema)]\n if ('format' in schema && typeof schema.format === 'string') {\n parts.push(schema.format)\n }\n\n const detail = parts.filter(Boolean).join(' · ')\n return detail.length > 0 ? detail : undefined\n})\n\nconst exampleValue = computed(() => {\n // Treat only `undefined` as \"not set\" — `null` is a valid example value on a nullable schema.\n if (\n props.value &&\n 'example' in props.value &&\n props.value.example !== undefined\n ) {\n return props.value.example\n }\n\n if (props.value && isArraySchema(props.value)) {\n const itemsSchema = resolve.schema(props.value.items)\n if (\n itemsSchema &&\n 'example' in itemsSchema &&\n itemsSchema.example !== undefined\n ) {\n return itemsSchema.example\n }\n }\n\n return undefined\n})\n\n/**\n * Whether the examples chip has anything to render.\n *\n * `SchemaPropertyExamples` already renders nothing without an example, but it\n * still mounts, and mounting is what installs its popup's window-level click\n * and keydown listeners. `withExamples` defaults to true, so without this gate\n * every property row on the page — including a plain `{ type: 'string' }` —\n * pays for a popup it never opens. Mirrors the component's own two branches.\n */\nconst hasExampleContent = computed((): boolean => {\n if (exampleValue.value !== undefined) {\n return true\n }\n\n const examples = props.value?.examples\n\n return (\n !!examples &&\n typeof examples === 'object' &&\n Object.keys(examples).length > 0\n )\n})\n\n/**\n * The regex `pattern` to surface via the hover dropdown. It lives on a string\n * schema, or on the items of a primitive array (which is not rendered on its\n * own, so its constraints are surfaced on the array heading — see\n * https://github.com/scalar/scalar/issues/9690).\n */\nconst patternValue = computed(() => {\n const schema = valueRef.value\n if (!schema) {\n return undefined\n }\n\n if (isStringSchema(schema) && schema.pattern) {\n return schema.pattern\n }\n\n if (isArraySchema(schema) && schema.items) {\n const items = resolve.schema(schema.items)\n if (isStringSchema(items) && items.pattern) {\n return items.pattern\n }\n }\n\n return undefined\n})\n</script>\n<template>\n <div\n class=\"property-heading [&>.property-detail:has(+.property-detail)]:mr-0\">\n <!-- `:has(+.property-detail)`: only a detail FOLLOWED BY another detail\n drops its right margin, because the `·` separator supplies the gap\n there. Not `:not(:last-of-type)`, which matches by element type: the\n collapsed preview and the trailing copy-link are spans as well, so it\n would strip the margin from the final detail and glue \"Addressrequired\"\n together on a collapsed row. -->\n <div\n v-if=\"$slots.name\"\n class=\"property-name\"\n :class=\"{ deprecated: props.value?.deprecated }\">\n <slot name=\"name\" />\n </div>\n <div\n v-if=\"props.isDiscriminator\"\n class=\"property-discriminator\">\n {{ translate('schema.discriminator') }}\n </div>\n <template v-if=\"props.value\">\n <!-- A map key reads `additionalProperty · string`: the keyword leads the\n detail list in the accent colour, like a type word, so the name\n above it can look like every other name. -->\n <SchemaPropertyDetail\n v-if=\"props.keyKind\"\n class=\"property-key-kind\">\n <span class=\"font-code text-c-accent\">{{\n props.keyKind === 'pattern' ? 'patternProperty' : 'additionalProperty'\n }}</span>\n </SchemaPropertyDetail>\n <!-- Type information -->\n <SchemaPropertyDetail\n v-if=\"shouldShowType\"\n truncate>\n <!-- The type is a token run (`array of Planet`) and a $ref link IS the\n type, not an appended `· Account` -->\n <!-- Written across lines on purpose: Vue drops whitespace-only text\n between two elements, so a single-line label would read\n `Type:string`. -->\n <span class=\"screenreader-only\"> {{ translate('schema.type') }}: </span>\n <button\n v-if=\"props.eventBus && modelLink?.schemaKey && modelLinkable\"\n class=\"text-c-2 hover:text-c-1 underline\"\n type=\"button\"\n @click=\"\n props.eventBus.emit('scroll-to:model-by-name', {\n name: modelLink.schemaKey,\n })\n \">\n <span\n v-if=\"signatureTokens.length\"\n class=\"property-type-signature text-c-2 text-(length:--scalar-mini)\">\n <template\n v-for=\"(token, index) in signatureTokens\"\n :key=\"index\">\n {{ index > 0 ? ' ' : ''\n }}<span\n class=\"property-type-token\"\n :class=\"[\n `property-type-token--${token.kind}`,\n token.kind === 'word' ? 'font-sans' : '',\n token.kind === 'ident' || token.kind === 'literal'\n ? 'font-code'\n : '',\n token.kind === 'punctuation' ? 'text-c-2' : '',\n ]\"\n >{{ token.text }}</span\n >\n </template>\n </span>\n </button>\n <span\n v-else-if=\"signatureTokens.length\"\n class=\"property-type-signature text-c-2 text-(length:--scalar-mini)\">\n <template\n v-for=\"(token, index) in signatureTokens\"\n :key=\"index\">\n {{ index > 0 ? ' ' : ''\n }}<span\n class=\"property-type-token\"\n :class=\"[\n `property-type-token--${token.kind}`,\n token.kind === 'word' ? 'font-sans' : '',\n token.kind === 'ident' || token.kind === 'literal'\n ? 'font-code'\n : '',\n token.kind === 'punctuation' ? 'text-c-2' : '',\n ]\"\n >{{ token.text }}</span\n >\n </template>\n </span>\n </SchemaPropertyDetail>\n\n <!-- A cycle reads `array of Satellite · recursive`, a modifier like\n `nullable`; the full sentence rides the tooltip. -->\n <SchemaPropertyDetail\n v-if=\"props.recursiveTo\"\n class=\"property-recursive\"\n :title=\"\n translate('schema.recursiveReference', { name: props.recursiveTo })\n \">\n {{ translate('schema.recursive') }}\n </SchemaPropertyDetail>\n\n <!-- Key constraints from propertyNames (e.g. \"keys: string · uuid\") -->\n <SchemaPropertyDetail\n v-if=\"propertyNamesDetail\"\n truncate>\n <template #prefix>{{ translate('schema.keys') }}:</template>\n {{ propertyNamesDetail }}\n </SchemaPropertyDetail>\n\n <!-- Dynamic validation properties from composable -->\n <SchemaPropertyDetail\n v-for=\"property in validationProperties\"\n :key=\"property.key\"\n :code=\"property.code\"\n :truncate=\"property.truncate\">\n <span\n v-if=\"property.key === 'format'\"\n class=\"screenreader-only\">\n {{ translate('schema.format') }}:\n </span>\n <template\n v-if=\"property.prefix\"\n #prefix>\n {{ property.prefix }}\n </template>\n {{ property.value }}\n </SchemaPropertyDetail>\n\n <!-- Enum indicator -->\n <SchemaPropertyDetail v-if=\"props.enum\">\n {{ translate('schema.enum') }}\n </SchemaPropertyDetail>\n </template>\n <div\n v-if=\"props.additional\"\n class=\"property-additional\">\n <template v-if=\"props.value?.['x-additionalPropertiesName']\">\n {{ props.value['x-additionalPropertiesName'] }}\n </template>\n <template v-else>{{ translate('schema.additionalProperties') }}</template>\n </div>\n <div\n v-if=\"props.value?.deprecated\"\n class=\"property-deprecated\">\n <Badge>{{ translate('schema.deprecated') }}</Badge>\n </div>\n <span\n v-if=\"discriminatorValue !== undefined\"\n class=\"text-c-2\">\n {{ translate('schema.discriminatorValue') }}:\n <RenderString :value=\"discriminatorValue\" />\n </span>\n <!-- Don't use `isDefined` here, we want to show `const` when the value is `null` -->\n <div\n v-if=\"constValue !== undefined\"\n class=\"property-const\">\n <SchemaPropertyDetail truncate>\n <template #prefix>{{ translate('schema.const') }}: </template>\n <RenderString :value=\"constValue\" />\n </SchemaPropertyDetail>\n </div>\n <template v-else>\n <!-- Shows only when a composition is used (so props.value?.type is undefined) -->\n <SchemaPropertyDetail v-if=\"(props.value as any)?.nullable === true\">\n {{ translate('schema.nullable') }}\n </SchemaPropertyDetail>\n </template>\n <div\n v-if=\"props.value?.writeOnly\"\n class=\"property-write-only\">\n {{ translate('schema.writeOnly') }}\n </div>\n <div\n v-else-if=\"props.value?.readOnly\"\n class=\"property-read-only\">\n {{ translate('schema.readOnly') }}\n </div>\n <div\n v-if=\"props.required\"\n class=\"property-required\">\n {{ translate('schema.required') }}\n </div>\n <!-- Gated here, not only inside the component: each popup instance installs\n window-level click and keydown listeners for its dismissal, so mounting\n one per row costs the page a listener per row it never shows anything\n for. Same reason `SchemaPropertyPattern` below is gated. -->\n <SchemaPropertyDefault\n v-if=\"props.value?.default !== undefined\"\n :value=\"props.value?.default\" />\n <!--\n Pattern is a hover dropdown chip like Examples, not an inline constraint,\n so it sits beside the example. This keeps the real constraints (length,\n nullable, …) together in the dotted list. See #9966.\n -->\n <SchemaPropertyPattern\n v-if=\"patternValue\"\n :pattern=\"patternValue\" />\n <SchemaPropertyExamples\n v-if=\"props.withExamples && hasExampleContent\"\n :example=\"exampleValue\"\n :examples=\"props.value?.examples\" />\n <!-- The collapsed preview rides the end of the heading line -->\n <slot name=\"preview\" />\n <!-- Last so the tab order matches the visual order: the trailing copy-link\n is painted at the row's right edge, after every control to its left -->\n <slot name=\"trailing\" />\n </div>\n</template>\n<style scoped>\n.property-heading {\n display: flex;\n flex-wrap: wrap;\n align-items: baseline;\n row-gap: 9px;\n white-space: nowrap;\n}\n\n.property-heading:has(+ .children),\n.property-heading:has(+ .property-rule) {\n margin-bottom: 9px;\n}\n\n.property-heading > * {\n margin-right: 9px;\n}\n\n.property-heading:last-child {\n margin-right: 0;\n}\n\n.property-name {\n max-width: 100%;\n font-family: var(--scalar-font-code);\n font-weight: var(--scalar-bold);\n font-size: var(--scalar-font-size-4);\n white-space: normal;\n overflow-wrap: break-word;\n}\n\n.property-additional {\n font-family: var(--scalar-font-code);\n}\n\n.property-required,\n.property-optional {\n color: var(--scalar-color-2);\n}\n\n.property-required {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-orange);\n}\n/*\n * Light-mode oranges are too bright on a light page for 13px text (the default\n * #ff5800 is 3.16:1), so blend the theme orange toward the text colour to reach\n * WCAG 1.4.3 (4.5:1) while keeping the hue and letting custom themes flow\n * through. Dark mode already passes (8.37:1) and keeps the plain token.\n */\n.light-mode .property-required {\n color: color-mix(\n in srgb,\n var(--scalar-color-orange),\n var(--scalar-color-1) 32%\n );\n}\n\n.property-read-only {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-blue);\n}\n\n.property-write-only {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-green);\n}\n\n.property-discriminator {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-purple);\n}\n\n.property-detail {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-2);\n display: flex;\n align-items: center;\n\n min-width: 0;\n}\n\n.property-const {\n color: var(--scalar-color-1);\n}\n\n.deprecated {\n text-decoration: line-through;\n}\n</style>\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"SchemaPropertyHeading.vue.js","names":["_sfc_main","_plugin_vue_export_helper_default","SchemaPropertyHeading_vue_vue_type_script_setup_true_lang_default","SchemaPropertyHeading_default"],"sources":["../../src/schema/SchemaPropertyHeading.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { ScalarTooltip } from '@scalar/components/tooltip'\nimport { isDefined } from '@scalar/helpers/array/is-defined'\nimport type { WorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type { SchemaObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport {\n isArraySchema,\n isNumberSchema,\n isStringSchema,\n} from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\nimport { computed, toRef } from 'vue'\n\nimport Badge from '../shared/Badge.vue'\nimport { getSchemaType } from './helpers/get-schema-type'\nimport { getDisplayTypeSignatureTokens } from './helpers/get-type-signature-tokens'\nimport {\n isModelLinkable,\n type ModelLinkOptions,\n} from './helpers/is-model-linkable'\nimport { getModelNameWithArray } from './helpers/schema-name'\nimport { useLocalization } from './localization'\nimport {\n protobufFieldNumber,\n protobufPresence,\n type ProtobufSchema,\n} from './protobuf-metadata'\nimport {\n schemaRecursiveTarget,\n type RecursiveSchema,\n} from './recursive-metadata'\nimport RenderString from './RenderString.vue'\nimport SchemaPropertyDefault from './SchemaPropertyDefault.vue'\nimport SchemaPropertyDetail from './SchemaPropertyDetail.vue'\nimport SchemaPropertyExamples from './SchemaPropertyExamples.vue'\nimport SchemaPropertyPattern from './SchemaPropertyPattern.vue'\n\nconst props = withDefaults(\n defineProps<{\n value: SchemaObject | undefined\n enum?: boolean\n isDiscriminator?: boolean\n /** Effective AsyncAPI variant value, separate from const/enum constraints. */\n discriminatorValue?: string\n required?: boolean\n additional?: boolean\n withExamples?: boolean\n hideModelNames?: boolean\n /**\n * Config for deciding whether a model name links to the models section. When the section or\n * the referenced model is hidden there is nothing to scroll to, so the name renders as plain text.\n */\n modelLinkOptions?: ModelLinkOptions\n /** When the schema was resolved from a $ref, pass the ref name so it displays as e.g. \"Data\" instead of \"object\". */\n modelName?: string | null\n /** Resolved propertyNames schema, used to surface key constraints like `format` for additional properties. */\n propertyNames?: SchemaObject\n eventBus?: WorkspaceEventBus | null\n /**\n * The row's name is a stand-in for keys the caller chooses\n * (`additionalProperties`) or keys matching a regex (`patternProperties`),\n * not a literal property. The heading says so in the signature line, where\n * the tree already describes shapes, instead of styling the name itself.\n */\n keyKind?: 'additional' | 'pattern'\n /**\n * The name of the schema this row loops back to. A cut cycle is a leaf, so\n * the signature line says why it does not expand; the model link beside it\n * already names the schema the loop returns to.\n */\n recursiveTo?: string\n }>(),\n {\n isDiscriminator: false,\n required: false,\n withExamples: true,\n hideModelNames: false,\n eventBus: null,\n },\n)\nconst { translate } = useLocalization()\n\n// Convert to reactive refs for composables\nconst fieldNumber = computed(\n () => (props.value as ProtobufSchema | undefined)?.[protobufFieldNumber],\n)\n\nconst recursiveTarget = computed(\n () =>\n props.recursiveTo ??\n (props.value as RecursiveSchema | undefined)?.[schemaRecursiveTarget],\n)\n\nconst presence = computed(\n () => (props.value as ProtobufSchema | undefined)?.[protobufPresence],\n)\nconst presenceDescription = computed(() =>\n presence.value === 'explicit'\n ? 'Explicit presence: Protobuf distinguishes an unset field from one set to its default value.'\n : 'Implicit presence: Protobuf does not distinguish an unset field from one set to its default value.',\n)\n\nconst valueRef = toRef(props, 'value')\n\nconst constValue = computed(() => {\n if (!valueRef.value) {\n return undefined\n }\n\n const schema = valueRef.value\n\n // Direct const value\n if (schema.const !== undefined) {\n return schema.const\n }\n\n // Single-item enum acts as const\n if (schema.enum?.length === 1) {\n return schema.enum[0]\n }\n\n // Check items for const values (for arrays)\n if (isArraySchema(schema) && schema.items) {\n const items = resolve.schema(schema.items)\n\n if (isDefined(items.const)) {\n return items.const\n }\n\n if (items.enum?.length === 1) {\n return items.enum[0]\n }\n }\n\n return undefined\n})\n\ntype ValidationProperty = {\n key: string\n value: string | number\n prefix?: string\n code?: boolean\n truncate?: boolean\n}\n\n/**\n * Constraints that live on a leaf (string or number) schema: length, pattern,\n * format and numeric ranges. Extracted so they can be surfaced for a primitive\n * schema as well as for a primitive array's items, which are not rendered on\n * their own. See https://github.com/scalar/scalar/issues/9690\n */\nconst getLeafConstraints = (schema: SchemaObject) => {\n const properties: ValidationProperty[] = []\n\n if (isStringSchema(schema)) {\n if (schema.minLength) {\n properties.push({\n key: 'min-length',\n prefix: `${translate('schema.minLength')}: `,\n value: schema.minLength,\n })\n }\n\n if (schema.maxLength) {\n properties.push({\n key: 'max-length',\n prefix: `${translate('schema.maxLength')}: `,\n value: schema.maxLength,\n })\n }\n\n // pattern is rendered via SchemaPropertyPattern (hover dropdown), skip here\n }\n\n if ((isStringSchema(schema) || isNumberSchema(schema)) && schema.format) {\n properties.push({\n key: 'format',\n value: schema.format,\n truncate: true,\n })\n }\n\n if (isNumberSchema(schema)) {\n if (isDefined(schema.exclusiveMinimum)) {\n properties.push({\n key: 'exclusive-minimum',\n prefix: `${translate('schema.greaterThan')}: `,\n value: schema.exclusiveMinimum,\n })\n }\n\n if (isDefined(schema.minimum)) {\n properties.push({\n key: 'minimum',\n prefix: `${translate('schema.min')}: `,\n value: schema.minimum,\n })\n }\n\n if (isDefined(schema.exclusiveMaximum)) {\n properties.push({\n key: 'exclusive-maximum',\n prefix: `${translate('schema.lessThan')}: `,\n value: schema.exclusiveMaximum,\n })\n }\n\n if (isDefined(schema.maximum)) {\n properties.push({\n key: 'maximum',\n prefix: `${translate('schema.max')}: `,\n value: schema.maximum,\n })\n }\n\n if (isDefined(schema.multipleOf)) {\n properties.push({\n key: 'multiple-of',\n prefix: `${translate('schema.multipleOf')}: `,\n value: schema.multipleOf,\n })\n }\n }\n\n return properties\n}\n\nconst validationProperties = computed(() => {\n if (!valueRef.value) {\n return []\n }\n\n const schema = valueRef.value\n const properties: ValidationProperty[] = []\n\n // Array validation properties\n if (isArraySchema(schema)) {\n if (schema.minItems || schema.maxItems) {\n properties.push({\n key: 'array-range',\n value: `${schema.minItems || ''}…${schema.maxItems || ''}`,\n })\n }\n\n // Unique items\n if (schema.uniqueItems) {\n properties.push({\n key: 'unique-items',\n value: `${translate('schema.unique')}!`,\n })\n }\n }\n\n properties.push(...getLeafConstraints(schema))\n\n // Primitive array items carry their own constraints (e.g. an array of `uuid`\n // strings) but are not rendered separately, so surface them here.\n if (isArraySchema(schema) && schema.items) {\n properties.push(...getLeafConstraints(resolve.schema(schema.items)))\n }\n\n return properties\n})\n\n/** Link data for navigating to the referenced model in the sidebar. */\nconst modelLink = computed(() => {\n if (!props.value) {\n return null\n }\n\n if (props.hideModelNames) {\n return null\n }\n\n if (props.modelName) {\n return { schemaKey: props.modelName, label: props.modelName }\n }\n\n return getModelNameWithArray(props.value)\n})\n\n/** Whether the model name links to the models section, or renders as plain text. */\nconst modelLinkable = computed(() =>\n isModelLinkable(modelLink.value?.schemaKey, props.modelLinkOptions ?? {}),\n)\n\n/**\n * The type as a run of tokens rather than a single string — identifiers in\n * the code face, English words like `array of` in the sans face, and a muted\n * `|` so `string | null` reads as one type with an alternative.\n *\n * The token run and the screen-reader label are written straight into the\n * template instead of being their own components: the tree mounts one per\n * typed row, and a component instance costs more to create than the span it\n * renders. On a flat object the type cells would be most of the instance\n * count. The linked and the plain copy of the token markup below must stay\n * identical.\n */\nconst signatureTokens = computed(() =>\n getDisplayTypeSignatureTokens(props.value, {\n hideModelNames: props.hideModelNames,\n modelName: modelLink.value?.label,\n }),\n)\n\n/** Check if we should show the type information */\nconst shouldShowType = computed(() => {\n if (!props.value || !('type' in props.value)) {\n return false\n }\n\n // Always show type for arrays, even when items have const values\n if (props.value.type === 'array') {\n return true\n }\n\n // For non-arrays, only show if no const value at the schema level\n return !constValue.value\n})\n\n/**\n * Type and format of the property keys, derived from the propertyNames schema.\n *\n * For a map keyed by UUIDs this renders e.g. \"string · uuid\" so the key\n * constraints are not lost. Returns undefined when there is nothing to show.\n */\nconst propertyNamesDetail = computed(() => {\n const schema = props.propertyNames\n if (!schema) {\n return undefined\n }\n\n const parts = [getSchemaType(schema)]\n if ('format' in schema && typeof schema.format === 'string') {\n parts.push(schema.format)\n }\n\n const detail = parts.filter(Boolean).join(' · ')\n return detail.length > 0 ? detail : undefined\n})\n\nconst exampleValue = computed(() => {\n // Treat only `undefined` as \"not set\" — `null` is a valid example value on a nullable schema.\n if (\n props.value &&\n 'example' in props.value &&\n props.value.example !== undefined\n ) {\n return props.value.example\n }\n\n // An array's own examples take precedence over the fallback from its items.\n if (\n props.value &&\n isArraySchema(props.value) &&\n !props.value.examples?.length\n ) {\n const itemsSchema = resolve.schema(props.value.items)\n if (\n itemsSchema &&\n 'example' in itemsSchema &&\n itemsSchema.example !== undefined\n ) {\n return itemsSchema.example\n }\n }\n\n return undefined\n})\n\n/**\n * Whether the examples chip has anything to render.\n *\n * `SchemaPropertyExamples` already renders nothing without an example, but it\n * still mounts, and mounting is what installs its popup's window-level click\n * and keydown listeners. `withExamples` defaults to true, so without this gate\n * every property row on the page — including a plain `{ type: 'string' }` —\n * pays for a popup it never opens. Mirrors the component's own two branches.\n */\nconst hasExampleContent = computed((): boolean => {\n if (exampleValue.value !== undefined) {\n return true\n }\n\n const examples = props.value?.examples\n\n return (\n !!examples &&\n typeof examples === 'object' &&\n Object.keys(examples).length > 0\n )\n})\n\n/**\n * The regex `pattern` to surface via the hover dropdown. It lives on a string\n * schema, or on the items of a primitive array (which is not rendered on its\n * own, so its constraints are surfaced on the array heading — see\n * https://github.com/scalar/scalar/issues/9690).\n */\nconst patternValue = computed(() => {\n const schema = valueRef.value\n if (!schema) {\n return undefined\n }\n\n if (isStringSchema(schema) && schema.pattern) {\n return schema.pattern\n }\n\n if (isArraySchema(schema) && schema.items) {\n const items = resolve.schema(schema.items)\n if (isStringSchema(items) && items.pattern) {\n return items.pattern\n }\n }\n\n return undefined\n})\n</script>\n<template>\n <div\n class=\"property-heading [&>.property-detail:has(+.property-detail)]:mr-0\">\n <!-- `:has(+.property-detail)`: only a detail FOLLOWED BY another detail\n drops its right margin, because the `·` separator supplies the gap\n there. Not `:not(:last-of-type)`, which matches by element type: the\n collapsed preview and the trailing copy-link are spans as well, so it\n would strip the margin from the final detail and glue \"Addressrequired\"\n together on a collapsed row. -->\n <div\n v-if=\"$slots.name\"\n class=\"property-name\"\n :class=\"{ deprecated: props.value?.deprecated }\">\n <slot name=\"name\" />\n </div>\n <ScalarTooltip\n v-if=\"fieldNumber !== undefined\"\n content=\"Protobuf field number\">\n <span class=\"text-c-3 font-code mr-2 text-xs\">\n <span aria-hidden=\"true\">#{{ fieldNumber }}</span>\n <span class=\"sr-only\">Protobuf field number: {{ fieldNumber }}</span>\n </span>\n </ScalarTooltip>\n <div\n v-if=\"props.isDiscriminator\"\n class=\"property-discriminator\">\n {{ translate('schema.discriminator') }}\n </div>\n <template v-if=\"props.value\">\n <!-- A map key reads `additionalProperty · string`: the keyword leads the\n detail list in the accent colour, like a type word, so the name\n above it can look like every other name. -->\n <SchemaPropertyDetail\n v-if=\"props.keyKind\"\n class=\"property-key-kind\">\n <span class=\"font-code text-c-accent\">{{\n props.keyKind === 'pattern' ? 'patternProperty' : 'additionalProperty'\n }}</span>\n </SchemaPropertyDetail>\n <!-- Type information -->\n <SchemaPropertyDetail\n v-if=\"shouldShowType\"\n truncate>\n <!-- The type is a token run (`array of Planet`) and a $ref link IS the\n type, not an appended `· Account` -->\n <!-- Written across lines on purpose: Vue drops whitespace-only text\n between two elements, so a single-line label would read\n `Type:string`. -->\n <span class=\"screenreader-only\"> {{ translate('schema.type') }}: </span>\n <button\n v-if=\"props.eventBus && modelLink?.schemaKey && modelLinkable\"\n class=\"text-c-2 hover:text-c-1 underline\"\n type=\"button\"\n @click=\"\n props.eventBus.emit('scroll-to:model-by-name', {\n name: modelLink.schemaKey,\n })\n \">\n <span\n v-if=\"signatureTokens.length\"\n class=\"property-type-signature text-c-2 text-(length:--scalar-mini)\">\n <template\n v-for=\"(token, index) in signatureTokens\"\n :key=\"index\">\n {{ index > 0 ? ' ' : ''\n }}<span\n class=\"property-type-token\"\n :class=\"[\n `property-type-token--${token.kind}`,\n token.kind === 'word' ? 'font-sans' : '',\n token.kind === 'ident' || token.kind === 'literal'\n ? 'font-code'\n : '',\n token.kind === 'punctuation' ? 'text-c-2' : '',\n ]\"\n >{{ token.text }}</span\n >\n </template>\n </span>\n </button>\n <span\n v-else-if=\"signatureTokens.length\"\n class=\"property-type-signature text-c-2 text-(length:--scalar-mini)\">\n <template\n v-for=\"(token, index) in signatureTokens\"\n :key=\"index\">\n {{ index > 0 ? ' ' : ''\n }}<span\n class=\"property-type-token\"\n :class=\"[\n `property-type-token--${token.kind}`,\n token.kind === 'word' ? 'font-sans' : '',\n token.kind === 'ident' || token.kind === 'literal'\n ? 'font-code'\n : '',\n token.kind === 'punctuation' ? 'text-c-2' : '',\n ]\"\n >{{ token.text }}</span\n >\n </template>\n </span>\n </SchemaPropertyDetail>\n\n <!-- A cycle reads `array of Satellite · recursive`, a modifier like\n `nullable`; the full sentence rides the tooltip. -->\n <SchemaPropertyDetail\n v-if=\"recursiveTarget\"\n class=\"property-recursive\"\n :title=\"\n translate('schema.recursiveReference', { name: recursiveTarget })\n \">\n {{ translate('schema.recursive') }}\n </SchemaPropertyDetail>\n\n <ScalarTooltip\n v-if=\"presence\"\n :content=\"presenceDescription\">\n <span class=\"text-c-2 mr-2 text-xs\">\n <span aria-hidden=\"true\">optional</span>\n <span class=\"sr-only\"\n >Optional ({{ presence }} presence). {{ presenceDescription }}</span\n >\n </span>\n </ScalarTooltip>\n\n <!-- Key constraints from propertyNames (e.g. \"keys: string · uuid\") -->\n <SchemaPropertyDetail\n v-if=\"propertyNamesDetail\"\n truncate>\n <template #prefix>{{ translate('schema.keys') }}:</template>\n {{ propertyNamesDetail }}\n </SchemaPropertyDetail>\n\n <!-- Dynamic validation properties from composable -->\n <SchemaPropertyDetail\n v-for=\"property in validationProperties\"\n :key=\"property.key\"\n :code=\"property.code\"\n :truncate=\"property.truncate\">\n <span\n v-if=\"property.key === 'format'\"\n class=\"screenreader-only\">\n {{ translate('schema.format') }}:\n </span>\n <template\n v-if=\"property.prefix\"\n #prefix>\n {{ property.prefix }}\n </template>\n {{ property.value }}\n </SchemaPropertyDetail>\n\n <!-- Enum indicator -->\n <SchemaPropertyDetail v-if=\"props.enum\">\n {{ translate('schema.enum') }}\n </SchemaPropertyDetail>\n </template>\n <div\n v-if=\"props.additional\"\n class=\"property-additional\">\n <template v-if=\"props.value?.['x-additionalPropertiesName']\">\n {{ props.value['x-additionalPropertiesName'] }}\n </template>\n <template v-else>{{ translate('schema.additionalProperties') }}</template>\n </div>\n <div\n v-if=\"props.value?.deprecated\"\n class=\"property-deprecated\">\n <Badge>{{ translate('schema.deprecated') }}</Badge>\n </div>\n <span\n v-if=\"discriminatorValue !== undefined\"\n class=\"text-c-2\">\n {{ translate('schema.discriminatorValue') }}:\n <RenderString :value=\"discriminatorValue\" />\n </span>\n <!-- Don't use `isDefined` here, we want to show `const` when the value is `null` -->\n <div\n v-if=\"constValue !== undefined\"\n class=\"property-const\">\n <SchemaPropertyDetail truncate>\n <template #prefix>{{ translate('schema.const') }}: </template>\n <RenderString :value=\"constValue\" />\n </SchemaPropertyDetail>\n </div>\n <template v-else>\n <!-- Shows only when a composition is used (so props.value?.type is undefined) -->\n <SchemaPropertyDetail v-if=\"(props.value as any)?.nullable === true\">\n {{ translate('schema.nullable') }}\n </SchemaPropertyDetail>\n </template>\n <div\n v-if=\"props.value?.writeOnly\"\n class=\"property-write-only\">\n {{ translate('schema.writeOnly') }}\n </div>\n <div\n v-else-if=\"props.value?.readOnly\"\n class=\"property-read-only\">\n {{ translate('schema.readOnly') }}\n </div>\n <div\n v-if=\"props.required\"\n class=\"property-required\">\n {{ translate('schema.required') }}\n </div>\n <!-- Gated here, not only inside the component: each popup instance installs\n window-level click and keydown listeners for its dismissal, so mounting\n one per row costs the page a listener per row it never shows anything\n for. Same reason `SchemaPropertyPattern` below is gated. -->\n <SchemaPropertyDefault\n v-if=\"props.value?.default !== undefined\"\n :value=\"props.value?.default\" />\n <!--\n Pattern is a hover dropdown chip like Examples, not an inline constraint,\n so it sits beside the example. This keeps the real constraints (length,\n nullable, …) together in the dotted list. See #9966.\n -->\n <SchemaPropertyPattern\n v-if=\"patternValue\"\n :pattern=\"patternValue\" />\n <SchemaPropertyExamples\n v-if=\"props.withExamples && hasExampleContent\"\n :example=\"exampleValue\"\n :examples=\"props.value?.examples\" />\n <!-- The collapsed preview rides the end of the heading line -->\n <slot name=\"preview\" />\n <!-- Last so the tab order matches the visual order: the trailing copy-link\n is painted at the row's right edge, after every control to its left -->\n <slot name=\"trailing\" />\n </div>\n</template>\n<style scoped>\n.property-heading {\n display: flex;\n flex-wrap: wrap;\n align-items: baseline;\n row-gap: 9px;\n white-space: nowrap;\n}\n\n.property-heading:has(+ .children),\n.property-heading:has(+ .property-rule) {\n margin-bottom: 9px;\n}\n\n.property-heading > * {\n margin-right: 9px;\n}\n\n.property-heading:last-child {\n margin-right: 0;\n}\n\n.property-name {\n max-width: 100%;\n font-family: var(--scalar-font-code);\n font-weight: var(--scalar-bold);\n font-size: var(--scalar-font-size-4);\n white-space: normal;\n overflow-wrap: break-word;\n}\n\n.property-additional {\n font-family: var(--scalar-font-code);\n}\n\n.property-required,\n.property-optional {\n color: var(--scalar-color-2);\n}\n\n.property-required {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-orange);\n}\n/*\n * Light-mode oranges are too bright on a light page for 13px text (the default\n * #ff5800 is 3.16:1), so blend the theme orange toward the text colour to reach\n * WCAG 1.4.3 (4.5:1) while keeping the hue and letting custom themes flow\n * through. Dark mode already passes (8.37:1) and keeps the plain token.\n */\n.light-mode .property-required {\n color: color-mix(\n in srgb,\n var(--scalar-color-orange),\n var(--scalar-color-1) 32%\n );\n}\n\n.property-read-only {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-blue);\n}\n\n.property-write-only {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-green);\n}\n\n.property-discriminator {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-purple);\n}\n\n.property-detail {\n font-size: var(--scalar-mini);\n color: var(--scalar-color-2);\n display: flex;\n align-items: center;\n\n min-width: 0;\n}\n\n.property-const {\n color: var(--scalar-color-1);\n}\n\n.deprecated {\n text-decoration: line-through;\n}\n</style>\n"],"mappings":""}
|
|
@@ -1,53 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
1
|
+
import { protobufFieldNumber as e, protobufPresence as t } from "./protobuf-metadata.js";
|
|
2
|
+
import { schemaRecursiveTarget as n } from "./recursive-metadata.js";
|
|
3
|
+
import { useLocalization as ee } from "./localization/index.js";
|
|
4
|
+
import { getSchemaType as te } from "./helpers/get-schema-type.js";
|
|
5
|
+
import { getModelNameWithArray as ne } from "./helpers/schema-name.js";
|
|
6
|
+
import { getDisplayTypeSignatureTokens as re } from "./helpers/get-type-signature-tokens.js";
|
|
7
|
+
import ie from "../shared/Badge.vue.js";
|
|
8
|
+
import { isModelLinkable as r } from "./helpers/is-model-linkable.js";
|
|
9
|
+
import i from "./RenderString.vue.js";
|
|
10
|
+
import ae from "./SchemaPropertyDefault.vue.js";
|
|
11
|
+
import a from "./SchemaPropertyDetail.vue.js";
|
|
12
|
+
import oe from "./SchemaPropertyExamples.vue.js";
|
|
13
|
+
import se from "./SchemaPropertyPattern.vue.js";
|
|
14
|
+
import { Fragment as o, computed as s, createBlock as c, createCommentVNode as l, createElementBlock as u, createElementVNode as d, createSlots as ce, createTextVNode as f, createVNode as p, defineComponent as m, normalizeClass as h, openBlock as g, renderList as _, renderSlot as v, toDisplayString as y, toRef as le, unref as b, withCtx as x } from "vue";
|
|
15
|
+
import { isDefined as S } from "@scalar/helpers/array/is-defined";
|
|
16
|
+
import { resolve as C } from "@scalar/workspace-store/resolve";
|
|
17
|
+
import { isArraySchema as w, isNumberSchema as T, isStringSchema as E } from "@scalar/workspace-store/schemas/v3.2/strict/type-guards";
|
|
18
|
+
import { ScalarTooltip as D } from "@scalar/components/tooltip";
|
|
16
19
|
//#region src/schema/SchemaPropertyHeading.vue?vue&type=script&setup=true&lang.ts
|
|
17
|
-
var
|
|
18
|
-
key:
|
|
20
|
+
var ue = { class: "property-heading [&>.property-detail:has(+.property-detail)]:mr-0" }, de = { class: "text-c-3 font-code mr-2 text-xs" }, fe = { "aria-hidden": "true" }, pe = { class: "sr-only" }, me = {
|
|
21
|
+
key: 2,
|
|
19
22
|
class: "property-discriminator"
|
|
20
|
-
},
|
|
23
|
+
}, O = { class: "font-code text-c-accent" }, k = { class: "screenreader-only" }, A = {
|
|
21
24
|
key: 0,
|
|
22
25
|
class: "property-type-signature text-c-2 text-(length:--scalar-mini)"
|
|
23
|
-
},
|
|
26
|
+
}, j = {
|
|
24
27
|
key: 1,
|
|
25
28
|
class: "property-type-signature text-c-2 text-(length:--scalar-mini)"
|
|
26
|
-
},
|
|
29
|
+
}, M = { class: "text-c-2 mr-2 text-xs" }, N = { class: "sr-only" }, P = {
|
|
27
30
|
key: 0,
|
|
28
31
|
class: "screenreader-only"
|
|
29
|
-
},
|
|
30
|
-
key: 3,
|
|
31
|
-
class: "property-additional"
|
|
32
|
-
}, R = {
|
|
32
|
+
}, F = {
|
|
33
33
|
key: 4,
|
|
34
|
-
class: "property-
|
|
35
|
-
},
|
|
34
|
+
class: "property-additional"
|
|
35
|
+
}, I = {
|
|
36
36
|
key: 5,
|
|
37
|
-
class: "
|
|
38
|
-
},
|
|
37
|
+
class: "property-deprecated"
|
|
38
|
+
}, L = {
|
|
39
39
|
key: 6,
|
|
40
|
+
class: "text-c-2"
|
|
41
|
+
}, R = {
|
|
42
|
+
key: 7,
|
|
40
43
|
class: "property-const"
|
|
41
|
-
},
|
|
42
|
-
key: 8,
|
|
43
|
-
class: "property-write-only"
|
|
44
|
-
}, H = {
|
|
44
|
+
}, z = {
|
|
45
45
|
key: 9,
|
|
46
|
-
class: "property-
|
|
47
|
-
},
|
|
46
|
+
class: "property-write-only"
|
|
47
|
+
}, he = {
|
|
48
48
|
key: 10,
|
|
49
|
+
class: "property-read-only"
|
|
50
|
+
}, ge = {
|
|
51
|
+
key: 11,
|
|
49
52
|
class: "property-required"
|
|
50
|
-
},
|
|
53
|
+
}, B = /*@__PURE__*/ m({
|
|
51
54
|
__name: "SchemaPropertyHeading",
|
|
52
55
|
props: {
|
|
53
56
|
value: {},
|
|
@@ -77,199 +80,213 @@ var A = { class: "property-heading [&>.property-detail:has(+.property-detail)]:m
|
|
|
77
80
|
keyKind: {},
|
|
78
81
|
recursiveTo: {}
|
|
79
82
|
},
|
|
80
|
-
setup(
|
|
81
|
-
let
|
|
83
|
+
setup(m) {
|
|
84
|
+
let B = m, { translate: V } = ee(), H = s(() => B.value?.[e]), U = s(() => B.recursiveTo ?? B.value?.[n]), W = s(() => B.value?.[t]), G = s(() => W.value === "explicit" ? "Explicit presence: Protobuf distinguishes an unset field from one set to its default value." : "Implicit presence: Protobuf does not distinguish an unset field from one set to its default value."), K = le(B, "value"), q = s(() => {
|
|
82
85
|
if (!K.value) return;
|
|
83
86
|
let e = K.value;
|
|
84
87
|
if (e.const !== void 0) return e.const;
|
|
85
88
|
if (e.enum?.length === 1) return e.enum[0];
|
|
86
|
-
if (
|
|
87
|
-
let t =
|
|
88
|
-
if (
|
|
89
|
+
if (w(e) && e.items) {
|
|
90
|
+
let t = C.schema(e.items);
|
|
91
|
+
if (S(t.const)) return t.const;
|
|
89
92
|
if (t.enum?.length === 1) return t.enum[0];
|
|
90
93
|
}
|
|
91
94
|
}), J = (e) => {
|
|
92
95
|
let t = [];
|
|
93
|
-
return
|
|
96
|
+
return E(e) && (e.minLength && t.push({
|
|
94
97
|
key: "min-length",
|
|
95
|
-
prefix: `${
|
|
98
|
+
prefix: `${V("schema.minLength")}: `,
|
|
96
99
|
value: e.minLength
|
|
97
100
|
}), e.maxLength && t.push({
|
|
98
101
|
key: "max-length",
|
|
99
|
-
prefix: `${
|
|
102
|
+
prefix: `${V("schema.maxLength")}: `,
|
|
100
103
|
value: e.maxLength
|
|
101
|
-
})), (
|
|
104
|
+
})), (E(e) || T(e)) && e.format && t.push({
|
|
102
105
|
key: "format",
|
|
103
106
|
value: e.format,
|
|
104
107
|
truncate: !0
|
|
105
|
-
}),
|
|
108
|
+
}), T(e) && (S(e.exclusiveMinimum) && t.push({
|
|
106
109
|
key: "exclusive-minimum",
|
|
107
|
-
prefix: `${
|
|
110
|
+
prefix: `${V("schema.greaterThan")}: `,
|
|
108
111
|
value: e.exclusiveMinimum
|
|
109
|
-
}),
|
|
112
|
+
}), S(e.minimum) && t.push({
|
|
110
113
|
key: "minimum",
|
|
111
|
-
prefix: `${
|
|
114
|
+
prefix: `${V("schema.min")}: `,
|
|
112
115
|
value: e.minimum
|
|
113
|
-
}),
|
|
116
|
+
}), S(e.exclusiveMaximum) && t.push({
|
|
114
117
|
key: "exclusive-maximum",
|
|
115
|
-
prefix: `${
|
|
118
|
+
prefix: `${V("schema.lessThan")}: `,
|
|
116
119
|
value: e.exclusiveMaximum
|
|
117
|
-
}),
|
|
120
|
+
}), S(e.maximum) && t.push({
|
|
118
121
|
key: "maximum",
|
|
119
|
-
prefix: `${
|
|
122
|
+
prefix: `${V("schema.max")}: `,
|
|
120
123
|
value: e.maximum
|
|
121
|
-
}),
|
|
124
|
+
}), S(e.multipleOf) && t.push({
|
|
122
125
|
key: "multiple-of",
|
|
123
|
-
prefix: `${
|
|
126
|
+
prefix: `${V("schema.multipleOf")}: `,
|
|
124
127
|
value: e.multipleOf
|
|
125
128
|
})), t;
|
|
126
|
-
},
|
|
129
|
+
}, _e = s(() => {
|
|
127
130
|
if (!K.value) return [];
|
|
128
131
|
let e = K.value, t = [];
|
|
129
|
-
return
|
|
132
|
+
return w(e) && ((e.minItems || e.maxItems) && t.push({
|
|
130
133
|
key: "array-range",
|
|
131
134
|
value: `${e.minItems || ""}…${e.maxItems || ""}`
|
|
132
135
|
}), e.uniqueItems && t.push({
|
|
133
136
|
key: "unique-items",
|
|
134
|
-
value: `${
|
|
135
|
-
})), t.push(...J(e)),
|
|
136
|
-
}), Y =
|
|
137
|
-
schemaKey:
|
|
138
|
-
label:
|
|
139
|
-
} :
|
|
140
|
-
hideModelNames:
|
|
137
|
+
value: `${V("schema.unique")}!`
|
|
138
|
+
})), t.push(...J(e)), w(e) && e.items && t.push(...J(C.schema(e.items))), t;
|
|
139
|
+
}), Y = s(() => !B.value || B.hideModelNames ? null : B.modelName ? {
|
|
140
|
+
schemaKey: B.modelName,
|
|
141
|
+
label: B.modelName
|
|
142
|
+
} : ne(B.value)), ve = s(() => r(Y.value?.schemaKey, B.modelLinkOptions ?? {})), X = s(() => re(B.value, {
|
|
143
|
+
hideModelNames: B.hideModelNames,
|
|
141
144
|
modelName: Y.value?.label
|
|
142
|
-
})),
|
|
143
|
-
let e =
|
|
145
|
+
})), ye = s(() => !B.value || !("type" in B.value) ? !1 : B.value.type === "array" || !q.value), Z = s(() => {
|
|
146
|
+
let e = B.propertyNames;
|
|
144
147
|
if (!e) return;
|
|
145
|
-
let
|
|
146
|
-
"format" in e && typeof e.format == "string" &&
|
|
147
|
-
let
|
|
148
|
-
return
|
|
149
|
-
}), Q =
|
|
150
|
-
if (
|
|
151
|
-
if (
|
|
152
|
-
let e =
|
|
148
|
+
let t = [te(e)];
|
|
149
|
+
"format" in e && typeof e.format == "string" && t.push(e.format);
|
|
150
|
+
let n = t.filter(Boolean).join(" · ");
|
|
151
|
+
return n.length > 0 ? n : void 0;
|
|
152
|
+
}), Q = s(() => {
|
|
153
|
+
if (B.value && "example" in B.value && B.value.example !== void 0) return B.value.example;
|
|
154
|
+
if (B.value && w(B.value) && !B.value.examples?.length) {
|
|
155
|
+
let e = C.schema(B.value.items);
|
|
153
156
|
if (e && "example" in e && e.example !== void 0) return e.example;
|
|
154
157
|
}
|
|
155
|
-
}),
|
|
158
|
+
}), be = s(() => {
|
|
156
159
|
if (Q.value !== void 0) return !0;
|
|
157
|
-
let e =
|
|
160
|
+
let e = B.value?.examples;
|
|
158
161
|
return !!e && typeof e == "object" && Object.keys(e).length > 0;
|
|
159
|
-
}), $ =
|
|
162
|
+
}), $ = s(() => {
|
|
160
163
|
let e = K.value;
|
|
161
164
|
if (e) {
|
|
162
|
-
if (
|
|
163
|
-
if (
|
|
164
|
-
let t =
|
|
165
|
-
if (
|
|
165
|
+
if (E(e) && e.pattern) return e.pattern;
|
|
166
|
+
if (w(e) && e.items) {
|
|
167
|
+
let t = C.schema(e.items);
|
|
168
|
+
if (E(t) && t.pattern) return t.pattern;
|
|
166
169
|
}
|
|
167
170
|
}
|
|
168
171
|
});
|
|
169
|
-
return (e, t) => (
|
|
170
|
-
e.$slots.name ? (
|
|
172
|
+
return (e, t) => (g(), u("div", ue, [
|
|
173
|
+
e.$slots.name ? (g(), u("div", {
|
|
171
174
|
key: 0,
|
|
172
|
-
class:
|
|
173
|
-
}, [
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
class: h(["property-name", { deprecated: B.value?.deprecated }])
|
|
176
|
+
}, [v(e.$slots, "name", {}, void 0, !0)], 2)) : l("", !0),
|
|
177
|
+
H.value === void 0 ? l("", !0) : (g(), c(b(D), {
|
|
178
|
+
key: 1,
|
|
179
|
+
content: "Protobuf field number"
|
|
180
|
+
}, {
|
|
181
|
+
default: x(() => [d("span", de, [d("span", fe, "#" + y(H.value), 1), d("span", pe, "Protobuf field number: " + y(H.value), 1)])]),
|
|
182
|
+
_: 1
|
|
183
|
+
})),
|
|
184
|
+
B.isDiscriminator ? (g(), u("div", me, y(b(V)("schema.discriminator")), 1)) : l("", !0),
|
|
185
|
+
B.value ? (g(), u(o, { key: 3 }, [
|
|
186
|
+
B.keyKind ? (g(), c(a, {
|
|
177
187
|
key: 0,
|
|
178
188
|
class: "property-key-kind"
|
|
179
189
|
}, {
|
|
180
|
-
default:
|
|
190
|
+
default: x(() => [d("span", O, y(B.keyKind === "pattern" ? "patternProperty" : "additionalProperty"), 1)]),
|
|
181
191
|
_: 1
|
|
182
|
-
})) :
|
|
183
|
-
|
|
192
|
+
})) : l("", !0),
|
|
193
|
+
ye.value ? (g(), c(a, {
|
|
184
194
|
key: 1,
|
|
185
195
|
truncate: ""
|
|
186
196
|
}, {
|
|
187
|
-
default:
|
|
197
|
+
default: x(() => [d("span", k, y(b(V)("schema.type")) + ": ", 1), B.eventBus && Y.value?.schemaKey && ve.value ? (g(), u("button", {
|
|
188
198
|
key: 0,
|
|
189
199
|
class: "text-c-2 hover:text-c-1 underline",
|
|
190
200
|
type: "button",
|
|
191
|
-
onClick: t[0] ||= (e) =>
|
|
192
|
-
}, [X.value.length ? (
|
|
201
|
+
onClick: t[0] ||= (e) => B.eventBus.emit("scroll-to:model-by-name", { name: Y.value.schemaKey })
|
|
202
|
+
}, [X.value.length ? (g(), u("span", A, [(g(!0), u(o, null, _(X.value, (e, t) => (g(), u(o, { key: t }, [f(y(t > 0 ? " " : ""), 1), d("span", { class: h(["property-type-token", [
|
|
193
203
|
`property-type-token--${e.kind}`,
|
|
194
204
|
e.kind === "word" ? "font-sans" : "",
|
|
195
205
|
e.kind === "ident" || e.kind === "literal" ? "font-code" : "",
|
|
196
206
|
e.kind === "punctuation" ? "text-c-2" : ""
|
|
197
|
-
]]) },
|
|
207
|
+
]]) }, y(e.text), 3)], 64))), 128))])) : l("", !0)])) : X.value.length ? (g(), u("span", j, [(g(!0), u(o, null, _(X.value, (e, t) => (g(), u(o, { key: t }, [f(y(t > 0 ? " " : ""), 1), d("span", { class: h(["property-type-token", [
|
|
198
208
|
`property-type-token--${e.kind}`,
|
|
199
209
|
e.kind === "word" ? "font-sans" : "",
|
|
200
210
|
e.kind === "ident" || e.kind === "literal" ? "font-code" : "",
|
|
201
211
|
e.kind === "punctuation" ? "text-c-2" : ""
|
|
202
|
-
]]) },
|
|
212
|
+
]]) }, y(e.text), 3)], 64))), 128))])) : l("", !0)]),
|
|
203
213
|
_: 1
|
|
204
|
-
})) :
|
|
205
|
-
|
|
214
|
+
})) : l("", !0),
|
|
215
|
+
U.value ? (g(), c(a, {
|
|
206
216
|
key: 2,
|
|
207
217
|
class: "property-recursive",
|
|
208
|
-
title:
|
|
218
|
+
title: b(V)("schema.recursiveReference", { name: U.value })
|
|
209
219
|
}, {
|
|
210
|
-
default:
|
|
220
|
+
default: x(() => [f(y(b(V)("schema.recursive")), 1)]),
|
|
211
221
|
_: 1
|
|
212
|
-
}, 8, ["title"])) :
|
|
213
|
-
|
|
222
|
+
}, 8, ["title"])) : l("", !0),
|
|
223
|
+
W.value ? (g(), c(b(D), {
|
|
214
224
|
key: 3,
|
|
225
|
+
content: G.value
|
|
226
|
+
}, {
|
|
227
|
+
default: x(() => [d("span", M, [t[1] ||= d("span", { "aria-hidden": "true" }, "optional", -1), d("span", N, "Optional (" + y(W.value) + " presence). " + y(G.value), 1)])]),
|
|
228
|
+
_: 1
|
|
229
|
+
}, 8, ["content"])) : l("", !0),
|
|
230
|
+
Z.value ? (g(), c(a, {
|
|
231
|
+
key: 4,
|
|
215
232
|
truncate: ""
|
|
216
233
|
}, {
|
|
217
|
-
prefix:
|
|
218
|
-
default:
|
|
234
|
+
prefix: x(() => [f(y(b(V)("schema.keys")) + ":", 1)]),
|
|
235
|
+
default: x(() => [f(" " + y(Z.value), 1)]),
|
|
219
236
|
_: 1
|
|
220
|
-
})) :
|
|
221
|
-
(
|
|
237
|
+
})) : l("", !0),
|
|
238
|
+
(g(!0), u(o, null, _(_e.value, (e) => (g(), c(a, {
|
|
222
239
|
key: e.key,
|
|
223
240
|
code: e.code,
|
|
224
241
|
truncate: e.truncate
|
|
225
|
-
},
|
|
226
|
-
default:
|
|
242
|
+
}, ce({
|
|
243
|
+
default: x(() => [e.key === "format" ? (g(), u("span", P, y(b(V)("schema.format")) + ": ", 1)) : l("", !0), f(" " + y(e.value), 1)]),
|
|
227
244
|
_: 2
|
|
228
245
|
}, [e.prefix ? {
|
|
229
246
|
name: "prefix",
|
|
230
|
-
fn:
|
|
247
|
+
fn: x(() => [f(y(e.prefix), 1)]),
|
|
231
248
|
key: "0"
|
|
232
249
|
} : void 0]), 1032, ["code", "truncate"]))), 128)),
|
|
233
|
-
|
|
234
|
-
default:
|
|
250
|
+
B.enum ? (g(), c(a, { key: 5 }, {
|
|
251
|
+
default: x(() => [f(y(b(V)("schema.enum")), 1)]),
|
|
235
252
|
_: 1
|
|
236
|
-
})) :
|
|
237
|
-
], 64)) :
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
default:
|
|
253
|
+
})) : l("", !0)
|
|
254
|
+
], 64)) : l("", !0),
|
|
255
|
+
B.additional ? (g(), u("div", F, [B.value?.["x-additionalPropertiesName"] ? (g(), u(o, { key: 0 }, [f(y(B.value["x-additionalPropertiesName"]), 1)], 64)) : (g(), u(o, { key: 1 }, [f(y(b(V)("schema.additionalProperties")), 1)], 64))])) : l("", !0),
|
|
256
|
+
B.value?.deprecated ? (g(), u("div", I, [p(ie, null, {
|
|
257
|
+
default: x(() => [f(y(b(V)("schema.deprecated")), 1)]),
|
|
241
258
|
_: 1
|
|
242
|
-
})])) :
|
|
243
|
-
|
|
244
|
-
q.value === void 0 ? (
|
|
245
|
-
default:
|
|
259
|
+
})])) : l("", !0),
|
|
260
|
+
m.discriminatorValue === void 0 ? l("", !0) : (g(), u("span", L, [f(y(b(V)("schema.discriminatorValue")) + ": ", 1), p(i, { value: m.discriminatorValue }, null, 8, ["value"])])),
|
|
261
|
+
q.value === void 0 ? (g(), u(o, { key: 8 }, [B.value?.nullable === !0 ? (g(), c(a, { key: 0 }, {
|
|
262
|
+
default: x(() => [f(y(b(V)("schema.nullable")), 1)]),
|
|
246
263
|
_: 1
|
|
247
|
-
})) :
|
|
248
|
-
prefix:
|
|
249
|
-
default:
|
|
264
|
+
})) : l("", !0)], 64)) : (g(), u("div", R, [p(a, { truncate: "" }, {
|
|
265
|
+
prefix: x(() => [f(y(b(V)("schema.const")) + ": ", 1)]),
|
|
266
|
+
default: x(() => [p(i, { value: q.value }, null, 8, ["value"])]),
|
|
250
267
|
_: 1
|
|
251
268
|
})])),
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
key: 11,
|
|
256
|
-
value: W.value?.default
|
|
257
|
-
}, null, 8, ["value"])),
|
|
258
|
-
$.value ? (y(), d(te, {
|
|
269
|
+
B.value?.writeOnly ? (g(), u("div", z, y(b(V)("schema.writeOnly")), 1)) : B.value?.readOnly ? (g(), u("div", he, y(b(V)("schema.readOnly")), 1)) : l("", !0),
|
|
270
|
+
B.required ? (g(), u("div", ge, y(b(V)("schema.required")), 1)) : l("", !0),
|
|
271
|
+
B.value?.default === void 0 ? l("", !0) : (g(), c(ae, {
|
|
259
272
|
key: 12,
|
|
260
|
-
|
|
261
|
-
}, null, 8, ["
|
|
262
|
-
|
|
273
|
+
value: B.value?.default
|
|
274
|
+
}, null, 8, ["value"])),
|
|
275
|
+
$.value ? (g(), c(se, {
|
|
263
276
|
key: 13,
|
|
277
|
+
pattern: $.value
|
|
278
|
+
}, null, 8, ["pattern"])) : l("", !0),
|
|
279
|
+
B.withExamples && be.value ? (g(), c(oe, {
|
|
280
|
+
key: 14,
|
|
264
281
|
example: Q.value,
|
|
265
|
-
examples:
|
|
266
|
-
}, null, 8, ["example", "examples"])) :
|
|
267
|
-
|
|
268
|
-
|
|
282
|
+
examples: B.value?.examples
|
|
283
|
+
}, null, 8, ["example", "examples"])) : l("", !0),
|
|
284
|
+
v(e.$slots, "preview", {}, void 0, !0),
|
|
285
|
+
v(e.$slots, "trailing", {}, void 0, !0)
|
|
269
286
|
]));
|
|
270
287
|
}
|
|
271
288
|
});
|
|
272
289
|
//#endregion
|
|
273
|
-
export {
|
|
290
|
+
export { B as default };
|
|
274
291
|
|
|
275
292
|
//# sourceMappingURL=SchemaPropertyHeading.vue_vue_type_script_setup_true_lang.js.map
|