From ddb24da0c301aa5c925be4ca8b7c353f6fcdcb18 Mon Sep 17 00:00:00 2001 From: Yauheni Prakopchyk Date: Wed, 21 Jun 2023 13:53:58 +0400 Subject: [PATCH] fix: props descriptions (#3516) * fix: props descriptions * fix(docs): api block types --------- Co-authored-by: Yauheni Prakopchyk Co-authored-by: Maksim Nedoshev --- .../blocks/api/common-description.ts | 3 ++ .../blocks/api/component-parser/index.ts | 4 +- .../components/{api-table.vue => ApiDocs.vue} | 2 +- .../modules/page-config/blocks/api/index.vue | 51 ++++++++++--------- .../modules/page-config/blocks/api/types.ts | 7 +++ yarn.lock | 7 ++- 6 files changed, 47 insertions(+), 27 deletions(-) rename packages/docs/modules/page-config/blocks/api/components/{api-table.vue => ApiDocs.vue} (98%) diff --git a/packages/docs/modules/page-config/blocks/api/common-description.ts b/packages/docs/modules/page-config/blocks/api/common-description.ts index f8468d306d..42f01a6caa 100644 --- a/packages/docs/modules/page-config/blocks/api/common-description.ts +++ b/packages/docs/modules/page-config/blocks/api/common-description.ts @@ -112,5 +112,8 @@ export default }, slots: { scopeAvailable: "Slot scope available:" + }, + methods: { + } } diff --git a/packages/docs/modules/page-config/blocks/api/component-parser/index.ts b/packages/docs/modules/page-config/blocks/api/component-parser/index.ts index 163b5395af..1daa7a7169 100644 --- a/packages/docs/modules/page-config/blocks/api/component-parser/index.ts +++ b/packages/docs/modules/page-config/blocks/api/component-parser/index.ts @@ -50,9 +50,11 @@ export const getTypes = (componentProp: any): string[] => { } export type PropOptionsCompiled = { + name: string; types: string[]; required: boolean; default: any; + hidden: boolean; // TODO Not sure if hidden works at all right now. } export type EventOptionsCompiled = Record & { @@ -184,7 +186,7 @@ export function compileComponentOptions(componentOptions: ComponentOptions): Com props: props.map((prop) => ({ ...prop, types: prop.type, - })), + })), events: emits.reduce((acc, event) => ({ ...acc, [eventNameToCamelCase(event.name)]: ({ diff --git a/packages/docs/modules/page-config/blocks/api/components/api-table.vue b/packages/docs/modules/page-config/blocks/api/components/ApiDocs.vue similarity index 98% rename from packages/docs/modules/page-config/blocks/api/components/api-table.vue rename to packages/docs/modules/page-config/blocks/api/components/ApiDocs.vue index bc8b65a540..90946c1e38 100644 --- a/packages/docs/modules/page-config/blocks/api/components/api-table.vue +++ b/packages/docs/modules/page-config/blocks/api/components/ApiDocs.vue @@ -54,7 +54,7 @@ defineProps({ > , + type: Object as PropType, required: true }, visualOptions: { @@ -44,15 +45,15 @@ const props = defineProps({ }) const withManual = computed(() => { - return merge(props.meta, props.manual as ManualApiOptions) + return merge(props.meta, props.manual as ManualApiOptions) as ComponentMeta }) function getDescription (type: APIDescriptionType, name: string): string { const nameCamel = camelCase(name) return props.descriptionOptions?.[type]?.[nameCamel] - || commonDescription?.[type]?.[nameCamel] - || ''; + ?? (commonDescription[type] as Record)[nameCamel] + ?? ''; } const cleanDefaultValue = (o: Record | string) => { @@ -72,18 +73,20 @@ const cleanDefaultValue = (o: Record | string) => { return str } -const propsOptions = computed(() => Object - .entries(withManual.value.props || {}) - .filter(([key, prop]) => !prop.hidden) - .map(([key, prop]) => ({ - name: { name: key, ...prop }, - description: getDescription('props', key), - types: '`' + prop.types + '`', - default: cleanDefaultValue(prop.default), - })) - .sort((a, b) => { - return a.name.name.localeCompare(b.name.name) - }) +const propsOptions = computed(() => { + if (!withManual.value.props) { return [] } + + return Object + .values(withManual.value.props) + .filter(prop => !prop.hidden) + .map((prop) => ({ + name: prop.name, + description: getDescription('props', prop.name), + types: '`' + prop.types + '`', + default: cleanDefaultValue(prop.default), + })) + .sort((a, b) => (a.name || '').localeCompare(b.name)) + } ) const eventsOptions = computed(() => Object @@ -144,10 +147,10 @@ const cssVariablesOptions = computed(() => props.cssVariables.map(([name, value, :columns="['Name', 'Description', 'Types', 'Default']" :data="propsOptions" > -