feat(nuxt): add fetchpriority attribute and literal typings for meta components (#6251)

This commit is contained in:
Sanjaiyan Parthipan 2022-08-02 17:38:01 +05:30 committed by GitHub
parent 622c976cec
commit 94d0c08066
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 11 deletions

View File

@ -1,8 +1,15 @@
import { defineComponent } from 'vue' import { defineComponent, PropType } from 'vue'
import type { SetupContext } from 'vue' import type { SetupContext } from 'vue'
import { useHead } from './composables' import { useHead } from './composables'
import type {
type Props = Readonly<Record<string, any>> Props,
FetchPriority,
CrossOrigin,
HTTPEquiv,
ReferrerPolicy,
LinkRelationship,
Target
} from './types'
const removeUndefinedProps = (props: Props) => const removeUndefinedProps = (props: Props) =>
Object.fromEntries(Object.entries(props).filter(([, value]) => value !== undefined)) Object.fromEntries(Object.entries(props).filter(([, value]) => value !== undefined))
@ -66,14 +73,15 @@ export const Script = defineComponent({
...globalProps, ...globalProps,
async: Boolean, async: Boolean,
crossorigin: { crossorigin: {
type: [Boolean, String], type: [Boolean, String as () => CrossOrigin],
default: undefined default: undefined
}, },
defer: Boolean, defer: Boolean,
fetchpriority: String as PropType<FetchPriority>,
integrity: String, integrity: String,
nomodule: Boolean, nomodule: Boolean,
nonce: String, nonce: String,
referrerpolicy: String, referrerpolicy: String as PropType<ReferrerPolicy>,
src: String, src: String,
type: String, type: String,
/** @deprecated **/ /** @deprecated **/
@ -116,8 +124,9 @@ export const Link = defineComponent({
props: { props: {
...globalProps, ...globalProps,
as: String, as: String,
crossorigin: String, crossorigin: String as PropType<CrossOrigin>,
disabled: Boolean, disabled: Boolean,
fetchpriority: String as PropType<FetchPriority>,
href: String, href: String,
hreflang: String, hreflang: String,
imagesizes: String, imagesizes: String,
@ -128,15 +137,15 @@ export const Link = defineComponent({
type: Boolean, type: Boolean,
default: undefined default: undefined
}, },
referrerpolicy: String, referrerpolicy: String as PropType<ReferrerPolicy>,
rel: String, rel: String as PropType<LinkRelationship>,
sizes: String, sizes: String,
title: String, title: String,
type: String, type: String,
/** @deprecated **/ /** @deprecated **/
methods: String, methods: String,
/** @deprecated **/ /** @deprecated **/
target: String target: String as PropType<Target>
}, },
setup: setupForUseMeta(link => ({ setup: setupForUseMeta(link => ({
link: [link] link: [link]
@ -150,7 +159,7 @@ export const Base = defineComponent({
props: { props: {
...globalProps, ...globalProps,
href: String, href: String,
target: String target: String as PropType<Target>
}, },
setup: setupForUseMeta(base => ({ setup: setupForUseMeta(base => ({
base base
@ -180,7 +189,7 @@ export const Meta = defineComponent({
...globalProps, ...globalProps,
charset: String, charset: String,
content: String, content: String,
httpEquiv: String, httpEquiv: String as PropType<HTTPEquiv>,
name: String name: String
}, },
setup: setupForUseMeta(meta => ({ setup: setupForUseMeta(meta => ({

View File

@ -0,0 +1,47 @@
export type Props = Readonly<Record<string, any>>
export type FetchPriority = 'high' | 'low' | 'auto'
export type CrossOrigin = '' | 'anonymous' | 'use-credentials'
export type HTTPEquiv =
| 'content-security-policy'
| 'content-type'
| 'default-style'
| 'refresh'
| 'x-ua-compatible'
export type ReferrerPolicy =
| ''
| 'no-referrer'
| 'no-referrer-when-downgrade'
| 'same-origin'
| 'origin'
| 'strict-origin'
| 'origin-when-cross-origin'
| 'strict-origin-when-cross-origin'
| 'unsafe-url'
export type LinkRelationship =
| 'alternate'
| 'author'
| 'canonical'
| 'dns-prefetch'
| 'help'
| 'icon'
| 'license'
| 'manifest'
| 'me'
| 'modulepreload'
| 'next'
| 'pingback'
| 'preconnect'
| 'prefetch'
| 'preload'
| 'prerender'
| 'prev'
| 'search'
| 'stylesheet'
| (string & {})
export type Target = '_blank' | '_self' | '_parent' | '_top' | (string & {})