chore: add meta tables

This commit is contained in:
zernonia 2024-04-26 22:01:50 +08:00
parent 4ec3dd9d76
commit 9cf07be61b
15 changed files with 59 additions and 28 deletions

View File

@ -0,0 +1,26 @@
<script setup lang="ts">
defineProps<{
type: 'prop' | 'emit' | 'slot' | 'method'
data: { name: string, description: string, type: string, required: boolean }[]
}>()
</script>
<template>
<div>
<h2 class="capitalize">
{{ type }}
</h2>
<div v-for="(item, index) in data" :key="index" class="py-4 border-b text-sm">
<div class="flex items-center gap-2 flex-wrap">
<h5 class="text-sm">
<code>{{ item.name }}</code>
</h5>
<code>{{ item.type }}</code>
<span v-if="item.required" class="font-normal text-red-500 text-xs">Required*</span>
</div>
<div class="[&_p]:!my-2 ml-1" v-html="item.description" />
</div>
</div>
</template>

View File

@ -1,5 +1,6 @@
export { default as CodeWrapper } from './CodeWrapper' export { default as CodeWrapper } from './CodeWrapper'
export { default as ComponentPreview } from './ComponentPreview.vue' export { default as ComponentPreview } from './ComponentPreview.vue'
export { default as APITable } from './APITable.vue'
export { default as TabPreview } from './TabPreview.vue' export { default as TabPreview } from './TabPreview.vue'
export { default as TabMarkdown } from './TabMarkdown.vue' export { default as TabMarkdown } from './TabMarkdown.vue'
export { default as TabsMarkdown } from './TabsMarkdown.vue' export { default as TabsMarkdown } from './TabsMarkdown.vue'

View File

@ -42,16 +42,16 @@ components.forEach((componentPath) => {
let parsedString = '<!-- This file was automatic generated. Do not edit it manually -->\n\n' let parsedString = '<!-- This file was automatic generated. Do not edit it manually -->\n\n'
if (meta.props.length) if (meta.props.length)
parsedString += `<PropsTable :data="${JSON.stringify(meta.props, null, 2).replace(/"/g, '\'')}" />\n` parsedString += `<APITable :type="'prop'" :data="${JSON.stringify(meta.props, null, 2).replace(/"/g, '\'')}" />\n`
if (meta.events.length) if (meta.events.length)
parsedString += `\n<EmitsTable :data="${JSON.stringify(meta.events, null, 2).replace(/"/g, '\'')}" />\n` parsedString += `\n<APITable :type="'emit'" :data="${JSON.stringify(meta.events, null, 2).replace(/"/g, '\'')}" />\n`
if (meta.slots.length) if (meta.slots.length)
parsedString += `\n<SlotsTable :data="${JSON.stringify(meta.slots, null, 2).replace(/"/g, '\'')}" />\n` parsedString += `\n<APITable :type="'slot'" :data="${JSON.stringify(meta.slots, null, 2).replace(/"/g, '\'')}" />\n`
if (meta.methods.length) if (meta.methods.length)
parsedString += `\n<MethodsTable :data="${JSON.stringify(meta.methods, null, 2).replace(/"/g, '\'')}" />\n` parsedString += `\n<APITable :type="'method'" :data="${JSON.stringify(meta.methods, null, 2).replace(/"/g, '\'')}" />\n`
writeFileSync(metaMdFilePath, parsedString) writeFileSync(metaMdFilePath, parsedString)
} }
@ -90,7 +90,6 @@ function parseMeta(meta: ComponentMeta) {
.filter(prop => !prop.global) .filter(prop => !prop.global)
.map((prop) => { .map((prop) => {
let defaultValue = prop.default let defaultValue = prop.default
let type = prop.type
const { name, description, required } = prop const { name, description, required } = prop
if (name === 'as') if (name === 'as')
@ -99,13 +98,10 @@ function parseMeta(meta: ComponentMeta) {
if (defaultValue === 'undefined') if (defaultValue === 'undefined')
defaultValue = undefined defaultValue = undefined
if (!type.includes('AcceptableValue'))
type = parseTypeFromSchema(prop.schema) || type
return ({ return ({
name, name,
description: md.render(description), description: md.render(description),
type: type.replace(/\s*\|\s*undefined/g, ''), type: prop.type.replace(/\s*\|\s*undefined/g, ''),
required, required,
default: defaultValue ?? undefined, default: defaultValue ?? undefined,
}) })

View File

@ -26,3 +26,5 @@ npx shadcn-vue@latest add chart-area
Follow the [guide](/docs/charts/guide.html#installation) to complete the setup. Follow the [guide](/docs/charts/guide.html#installation) to complete the setup.
</Steps> </Steps>
<!-- @include: @/content/meta/AreaChart.md -->

View File

@ -26,3 +26,5 @@ npx shadcn-vue@latest add chart-bar
Follow the [guide](/docs/charts/guide.html#installation) to complete the setup. Follow the [guide](/docs/charts/guide.html#installation) to complete the setup.
</Steps> </Steps>
<!-- @include: @/content/meta/BarChart.md -->

View File

@ -26,3 +26,5 @@ npx shadcn-vue@latest add chart-donut
Follow the [guide](/docs/charts/guide.html#installation) to complete the setup. Follow the [guide](/docs/charts/guide.html#installation) to complete the setup.
</Steps> </Steps>
<!-- @include: @/content/meta/DonutChart.md -->

View File

@ -26,3 +26,5 @@ npx shadcn-vue@latest add chart-line
Follow the [guide](/docs/charts/guide.html#installation) to complete the setup. Follow the [guide](/docs/charts/guide.html#installation) to complete the setup.
</Steps> </Steps>
<!-- @include: @/content/meta/LineChart.md -->

View File

@ -1,10 +1,10 @@
<!-- This file was automatic generated. Do not edit it manually --> <!-- This file was automatic generated. Do not edit it manually -->
<PropsTable :data="[ <APITable :type="'prop'" :data="[
{ {
'name': 'data', 'name': 'data',
'description': '<p>The source data, in which each entry is a dictionary.</p>\n', 'description': '<p>The source data, in which each entry is a dictionary.</p>\n',
'type': 'Record<string, any>', 'type': 'Record<string, any>[]',
'required': true 'required': true
}, },
{ {
@ -95,7 +95,7 @@
{ {
'name': 'curveType', 'name': 'curveType',
'description': '<p>Type of curve</p>\n', 'description': '<p>Type of curve</p>\n',
'type': 'CurveType.Basis | CurveType.BasisClosed | CurveType.BasisOpen | CurveType.Bundle | CurveType.Cardinal | CurveType.CardinalClosed | CurveType.CardinalOpen | CurveType.CatmullRom | CurveType.CatmullRomClosed | CurveType.CatmullRomOpen | CurveType.Linear | CurveType.LinearClosed | CurveType.MonotoneX | CurveType.MonotoneY | CurveType.Natural | CurveType.Step | CurveType.StepAfter | CurveType.StepBefore', 'type': 'CurveType',
'required': false, 'required': false,
'default': 'CurveType.MonotoneX' 'default': 'CurveType.MonotoneX'
}, },
@ -108,7 +108,7 @@
} }
]" /> ]" />
<EmitsTable :data="[ <APITable :type="'emit'" :data="[
{ {
'name': 'legendItemClick', 'name': 'legendItemClick',
'type': '[d: BulletLegendItemInterface, i: number]' 'type': '[d: BulletLegendItemInterface, i: number]'

View File

@ -1,10 +1,10 @@
<!-- This file was automatic generated. Do not edit it manually --> <!-- This file was automatic generated. Do not edit it manually -->
<PropsTable :data="[ <APITable :type="'prop'" :data="[
{ {
'name': 'data', 'name': 'data',
'description': '<p>The source data, in which each entry is a dictionary.</p>\n', 'description': '<p>The source data, in which each entry is a dictionary.</p>\n',
'type': 'Record<string, any>', 'type': 'Record<string, any>[]',
'required': true 'required': true
}, },
{ {
@ -108,7 +108,7 @@
} }
]" /> ]" />
<EmitsTable :data="[ <APITable :type="'emit'" :data="[
{ {
'name': 'legendItemClick', 'name': 'legendItemClick',
'type': '[d: BulletLegendItemInterface, i: number]' 'type': '[d: BulletLegendItemInterface, i: number]'

View File

@ -1,6 +1,6 @@
<!-- This file was automatic generated. Do not edit it manually --> <!-- This file was automatic generated. Do not edit it manually -->
<PropsTable :data="[ <APITable :type="'prop'" :data="[
{ {
'name': 'colors', 'name': 'colors',
'description': '', 'description': '',

View File

@ -1,6 +1,6 @@
<!-- This file was automatic generated. Do not edit it manually --> <!-- This file was automatic generated. Do not edit it manually -->
<PropsTable :data="[ <APITable :type="'prop'" :data="[
{ {
'name': 'items', 'name': 'items',
'description': '', 'description': '',
@ -10,7 +10,7 @@
} }
]" /> ]" />
<EmitsTable :data="[ <APITable :type="'emit'" :data="[
{ {
'name': 'legendItemClick', 'name': 'legendItemClick',
'type': '[d: BulletLegendItemInterface, i: number]' 'type': '[d: BulletLegendItemInterface, i: number]'

View File

@ -1,6 +1,6 @@
<!-- This file was automatic generated. Do not edit it manually --> <!-- This file was automatic generated. Do not edit it manually -->
<PropsTable :data="[ <APITable :type="'prop'" :data="[
{ {
'name': 'valueFormatter', 'name': 'valueFormatter',
'description': '', 'description': '',
@ -34,7 +34,7 @@
} }
]" /> ]" />
<MethodsTable :data="[ <APITable :type="'method'" :data="[
{ {
'name': 'valueFormatter', 'name': 'valueFormatter',
'description': '', 'description': '',

View File

@ -1,6 +1,6 @@
<!-- This file was automatic generated. Do not edit it manually --> <!-- This file was automatic generated. Do not edit it manually -->
<PropsTable :data="[ <APITable :type="'prop'" :data="[
{ {
'name': 'title', 'name': 'title',
'description': '', 'description': '',

View File

@ -1,6 +1,6 @@
<!-- This file was automatic generated. Do not edit it manually --> <!-- This file was automatic generated. Do not edit it manually -->
<PropsTable :data="[ <APITable :type="'prop'" :data="[
{ {
'name': 'colors', 'name': 'colors',
'description': '<p>Change the default colors.</p>\n', 'description': '<p>Change the default colors.</p>\n',
@ -16,7 +16,7 @@
{ {
'name': 'data', 'name': 'data',
'description': '<p>The source data, in which each entry is a dictionary.</p>\n', 'description': '<p>The source data, in which each entry is a dictionary.</p>\n',
'type': 'Record<string, any>', 'type': 'Record<string, any>[]',
'required': true 'required': true
}, },
{ {

View File

@ -1,10 +1,10 @@
<!-- This file was automatic generated. Do not edit it manually --> <!-- This file was automatic generated. Do not edit it manually -->
<PropsTable :data="[ <APITable :type="'prop'" :data="[
{ {
'name': 'data', 'name': 'data',
'description': '<p>The source data, in which each entry is a dictionary.</p>\n', 'description': '<p>The source data, in which each entry is a dictionary.</p>\n',
'type': 'Record<string, any>', 'type': 'Record<string, any>[]',
'required': true 'required': true
}, },
{ {
@ -95,13 +95,13 @@
{ {
'name': 'curveType', 'name': 'curveType',
'description': '<p>Type of curve</p>\n', 'description': '<p>Type of curve</p>\n',
'type': 'CurveType.Basis | CurveType.BasisClosed | CurveType.BasisOpen | CurveType.Bundle | CurveType.Cardinal | CurveType.CardinalClosed | CurveType.CardinalOpen | CurveType.CatmullRom | CurveType.CatmullRomClosed | CurveType.CatmullRomOpen | CurveType.Linear | CurveType.LinearClosed | CurveType.MonotoneX | CurveType.MonotoneY | CurveType.Natural | CurveType.Step | CurveType.StepAfter | CurveType.StepBefore', 'type': 'CurveType',
'required': false, 'required': false,
'default': 'CurveType.MonotoneX' 'default': 'CurveType.MonotoneX'
} }
]" /> ]" />
<EmitsTable :data="[ <APITable :type="'emit'" :data="[
{ {
'name': 'legendItemClick', 'name': 'legendItemClick',
'type': '[d: BulletLegendItemInterface, i: number]' 'type': '[d: BulletLegendItemInterface, i: number]'