Skip to content

Commit 5234931

Browse files
authored
docs: types (#2186)
1 parent 26e5ac8 commit 5234931

File tree

19 files changed

+54
-47
lines changed

19 files changed

+54
-47
lines changed

docs/app/components/content/ComponentCode.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const props = defineProps<{
3232
const route = useRoute()
3333
const { $prettier } = useNuxtApp()
3434
35-
const camelName = camelCase(route.params.slug[route.params.slug.length - 1])
35+
const slug = Array.isArray(route.params.slug) ? route.params.slug[0] ?? '' : route.params.slug ?? ''
36+
const camelName = camelCase(slug[slug.length - 1] ?? '')
3637
const name = `U${upperFirst(camelName)}`
3738
3839
const componentProps = reactive({ ...(props.props || {}) })
@@ -45,11 +46,11 @@ function setComponentProp(name: string, value: any) {
4546
set(componentProps, name, value)
4647
}
4748
48-
const componentTheme = theme[camelName]
49+
const componentTheme = (theme as any)[camelName]
4950
const meta = await fetchComponentMeta(name as any)
5051
51-
function mapKeys(obj, parentKey = '') {
52-
return Object.entries(obj || {}).flatMap(([key, value]) => {
52+
function mapKeys(obj: object, parentKey = ''): any {
53+
return Object.entries(obj || {}).flatMap(([key, value]: [string, any]) => {
5354
if (typeof value === 'object' && !Array.isArray(value)) {
5455
return mapKeys(value, key)
5556
}
@@ -63,11 +64,11 @@ function mapKeys(obj, parentKey = '') {
6364
const options = computed(() => {
6465
const keys = mapKeys(props.props || {})
6566
66-
return keys.map((key) => {
67+
return keys.map((key: string) => {
6768
const prop = meta?.meta?.props?.find((prop: any) => prop.name === key)
6869
const propItems = get(props.items, key, [])
6970
const items = propItems.length
70-
? propItems.map(item => ({
71+
? propItems.map((item: any) => ({
7172
value: item,
7273
label: item
7374
}))
@@ -253,7 +254,7 @@ const { data: ast } = await useAsyncData(`component-code-${name}-${JSON.stringif
253254
<component :is="name" v-bind="componentProps" @update:model-value="!!componentProps.modelValue && setComponentProp('modelValue', $event)">
254255
<template v-for="slot in Object.keys(slots || {})" :key="slot" #[slot]>
255256
<ContentSlot :name="slot" unwrap="p">
256-
{{ slots[slot] }}
257+
{{ slots?.[slot] }}
257258
</ContentSlot>
258259
</template>
259260
</component>

docs/app/components/content/ComponentEmits.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { upperFirst, camelCase } from 'scule'
33
44
const route = useRoute()
55
6-
const camelName = camelCase(route.params.slug[route.params.slug.length - 1])
6+
const slug = Array.isArray(route.params.slug) ? route.params.slug[0] ?? '' : route.params.slug ?? ''
7+
const camelName = camelCase(slug[slug.length - 1] ?? '')
78
const name = `U${upperFirst(camelName)}`
89
910
const meta = await fetchComponentMeta(name as any)

docs/app/components/content/ComponentProps.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ const props = defineProps<{
99
1010
const route = useRoute()
1111
12-
const camelName = camelCase(route.params.slug[route.params.slug.length - 1])
12+
const slug = Array.isArray(route.params.slug) ? route.params.slug[0] ?? '' : route.params.slug ?? ''
13+
const camelName = camelCase(slug[slug.length - 1] ?? '')
1314
const name = `U${upperFirst(camelName)}`
1415
15-
const componentTheme = theme[camelName]
16+
const componentTheme = (theme as any)[camelName]
1617
const meta = await fetchComponentMeta(name as any)
1718
1819
const metaProps: ComputedRef<ComponentMeta['props']> = computed(() => {
@@ -43,6 +44,8 @@ const metaProps: ComputedRef<ComponentMeta['props']> = computed(() => {
4344
if (b.name === 'ui') {
4445
return -1
4546
}
47+
48+
return 0
4649
})
4750
})
4851
</script>

docs/app/components/content/ComponentPropsSchema.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const props = defineProps<{
66
ignore?: string[]
77
}>()
88
9-
function getSchemaProps(schema: PropertyMeta['schema']) {
9+
function getSchemaProps(schema: PropertyMeta['schema']): any {
1010
if (!schema || typeof schema === 'string' || !schema.schema) {
1111
return []
1212
}
@@ -15,12 +15,12 @@ function getSchemaProps(schema: PropertyMeta['schema']) {
1515
return Object.values(schema.schema).filter(prop => !props.ignore?.includes(prop.name))
1616
}
1717
18-
return (Array.isArray(schema.schema) ? schema.schema : Object.values(schema.schema)).flatMap(getSchemaProps)
18+
return (Array.isArray(schema.schema) ? schema.schema : Object.values(schema.schema)).flatMap(getSchemaProps as any)
1919
}
2020
2121
const schemaProps = computed(() => {
22-
return getSchemaProps(props.prop.schema).map((prop) => {
23-
const defaultValue = prop.default ?? prop.tags?.find(tag => tag.name === 'defaultValue')?.text
22+
return getSchemaProps(props.prop.schema).map((prop: any) => {
23+
const defaultValue = prop.default ?? prop.tags?.find((tag: any) => tag.name === 'defaultValue')?.text
2424
let description = prop.description
2525
if (defaultValue) {
2626
description = description ? `${description} Defaults to \`${defaultValue}\`{lang="ts-type"}.` : `Defaults to \`${defaultValue}\`{lang="ts-type"}.`

docs/app/components/content/ComponentSlots.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { upperFirst, camelCase } from 'scule'
33
44
const route = useRoute()
55
6-
const camelName = camelCase(route.params.slug[route.params.slug.length - 1])
6+
const slug = Array.isArray(route.params.slug) ? route.params.slug[0] ?? '' : route.params.slug ?? ''
7+
const camelName = camelCase(slug[slug.length - 1] ?? '')
78
const name = `U${upperFirst(camelName)}`
89
910
const meta = await fetchComponentMeta(name as any)

docs/app/components/content/ComponentTheme.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import * as theme from '#build/ui'
55
66
const route = useRoute()
77
8-
const name = camelCase(route.params.slug[route.params.slug.length - 1])
8+
const slug = Array.isArray(route.params.slug) ? route.params.slug[0] ?? '' : route.params.slug ?? ''
9+
const name = camelCase(slug[slug.length - 1] ?? '')
910
1011
const strippedCompoundVariants = ref(false)
1112
12-
function stripCompoundVariants(component) {
13+
function stripCompoundVariants(component: any) {
1314
if (component.compoundVariants) {
1415
component.compoundVariants = component.compoundVariants.filter((compoundVariant: any) => {
1516
if (compoundVariant.color) {
@@ -38,7 +39,7 @@ function stripCompoundVariants(component) {
3839
const component = computed(() => {
3940
return {
4041
ui: {
41-
[name]: stripCompoundVariants(theme[name])
42+
[name]: stripCompoundVariants((theme as any)[name])
4243
}
4344
}
4445
})

docs/app/components/content/examples/chip/ChipShowExample.vue

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22
const statuses = ['online', 'away', 'busy', 'offline']
33
const status = ref(statuses[0])
44
5-
const color = computed(() => ({
6-
online: 'green',
7-
away: 'amber',
8-
busy: 'red',
9-
offline: 'gray'
10-
})[status.value] as any)
5+
const color = computed(() => status.value ? { online: 'green', away: 'amber', busy: 'red', offline: 'gray' }[status.value] as any : 'online')
116
127
const show = computed(() => status.value !== 'offline')
138
149
// Note: This is for demonstration purposes only. Don't do this at home.
1510
onMounted(() => {
1611
setInterval(() => {
17-
status.value = statuses[(statuses.indexOf(status.value) + 1) % statuses.length]
12+
if (status.value) {
13+
status.value = statuses[(statuses.indexOf(status.value) + 1) % statuses.length]
14+
}
1815
}, 1000)
1916
})
2017
</script>

docs/app/composables/fetchComponentExample.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const useComponentExampleState = () => useState('component-example-state', () => ({}))
1+
const useComponentExampleState = () => useState<Record<string, any>>('component-example-state', () => ({}))
22

33
export async function fetchComponentExample(name: string) {
44
const state = useComponentExampleState()
@@ -14,9 +14,9 @@ export async function fetchComponentExample(name: string) {
1414
// Add to nitro prerender
1515
if (import.meta.server) {
1616
const event = useRequestEvent()
17-
event.node.res.setHeader(
17+
event?.node.res.setHeader(
1818
'x-nitro-prerender',
19-
[event.node.res.getHeader('x-nitro-prerender'), `/api/component-example/${name}.json`].filter(Boolean).join(',')
19+
[event?.node.res.getHeader('x-nitro-prerender'), `/api/component-example/${name}.json`].filter(Boolean).join(',')
2020
)
2121
}
2222

docs/app/composables/fetchComponentMeta.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ComponentMeta } from 'vue-component-meta'
22

3-
const useComponentsMetaState = () => useState('component-meta-state', () => ({}))
3+
const useComponentsMetaState = () => useState<Record<string, any>>('component-meta-state', () => ({}))
44

55
export async function fetchComponentMeta(name: string): Promise<{ meta: ComponentMeta }> {
66
const state = useComponentsMetaState()
@@ -16,9 +16,9 @@ export async function fetchComponentMeta(name: string): Promise<{ meta: Componen
1616
// Add to nitro prerender
1717
if (import.meta.server) {
1818
const event = useRequestEvent()
19-
event.node.res.setHeader(
19+
event?.node.res.setHeader(
2020
'x-nitro-prerender',
21-
[event.node.res.getHeader('x-nitro-prerender'), `/api/component-meta/${name}.json`].filter(Boolean).join(',')
21+
[event?.node.res.getHeader('x-nitro-prerender'), `/api/component-meta/${name}.json`].filter(Boolean).join(',')
2222
)
2323
}
2424

docs/app/layouts/docs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NavItem } from '@nuxt/content'
33
44
const nav = inject<Ref<NavItem[]>>('navigation')
55
6-
const navigation = computed(() => nav.value.filter(item => !item._path.startsWith('/pro')))
6+
const navigation = computed(() => nav?.value.filter(item => !item._path.startsWith('/pro')))
77
</script>
88

99
<template>

0 commit comments

Comments
 (0)