-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
150 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useHead } from '../../src/composables' | ||
import { createHead } from '../../src/server' | ||
|
||
describe('types', () => { | ||
it('types useHead', () => { | ||
const unhead = createHead() | ||
useHead(unhead, { | ||
htmlAttrs: { | ||
lang: () => false, | ||
}, | ||
base: { href: '/base' }, | ||
link: () => [], | ||
meta: [ | ||
{ key: 'key', name: 'description', content: 'some description ' }, | ||
() => ({ key: 'key', name: 'description', content: 'some description ' }), | ||
], | ||
script: [ | ||
() => 'test', | ||
{ | ||
innerHTML: () => 'foo', | ||
}, | ||
], | ||
style: () => [ | ||
() => 'foo', | ||
], | ||
titleTemplate: (titleChunk) => { | ||
return titleChunk ? `${titleChunk} - Site Title` : 'Site Title' | ||
}, | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import type { SafeBodyAttr, SafeHtmlAttr, SafeLink, SafeMeta, SafeNoscript, SafeScript } from '@unhead/schema' | ||
import type { ReactiveHead } from './schema' | ||
import type { MaybeComputedRef, MaybeComputedRefEntries } from './util' | ||
import type { MaybeComputedRef, ResolvableArray } from './util' | ||
|
||
export interface HeadSafe extends Pick<ReactiveHead, 'title' | 'titleTemplate' | 'templateParams'> { | ||
meta?: MaybeComputedRefEntries<SafeMeta>[] | ||
link?: MaybeComputedRefEntries<SafeLink>[] | ||
noscript?: MaybeComputedRefEntries<SafeNoscript>[] | ||
script?: MaybeComputedRefEntries<SafeScript>[] | ||
htmlAttrs?: MaybeComputedRefEntries<SafeHtmlAttr> | ||
bodyAttrs?: MaybeComputedRefEntries<SafeBodyAttr> | ||
meta?: ResolvableArray<SafeMeta>[] | ||
link?: ResolvableArray<SafeLink>[] | ||
noscript?: ResolvableArray<SafeNoscript>[] | ||
script?: ResolvableArray<SafeScript>[] | ||
htmlAttrs?: ResolvableArray<SafeHtmlAttr> | ||
bodyAttrs?: ResolvableArray<SafeBodyAttr> | ||
} | ||
|
||
export type UseHeadSafeInput = MaybeComputedRef<HeadSafe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
import type { Falsey } from '@unhead/schema' | ||
import type { ComputedRef, Ref } from 'vue' | ||
|
||
// copied from @vueuse/shared | ||
export type MaybeReadonlyRef<T> = ComputedRef<T> | ||
export type MaybeComputedRef<T> = T | MaybeReadonlyRef<T> | Ref<T> | ||
export type MaybeComputedRefOrFalsy<T> = T | MaybeReadonlyRef<T> | Ref<T> | ||
export type MaybeComputedRef<T> = T | (() => T) | ComputedRef<T> | Ref<T> | ||
|
||
/** | ||
* @deprecated Use MaybeComputedRefOrFalsy | ||
*/ | ||
export type MaybeComputedRefOrPromise<T> = MaybeComputedRefOrFalsy<T> | ||
export type ResolvableArray<T> = MaybeComputedRef<MaybeComputedRef<T>[]> | ||
|
||
export type MaybeComputedRefEntries<T> = MaybeComputedRef<T> | { | ||
[key in keyof T]?: MaybeComputedRefOrFalsy<T[key]> | ||
} | ||
|
||
export type MaybeComputedRefEntriesOnly<T> = { | ||
[key in keyof T]?: MaybeComputedRefOrFalsy<T[key]> | ||
export type ResolvableProperties<T> = { | ||
[key in keyof T]?: MaybeComputedRef<T[key] | Falsey> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { createHead } from '@unhead/vue/client' | ||
import { computed } from 'vue' | ||
import { useHead } from '../../src/composables' | ||
|
||
describe('types', () => { | ||
it('types useHead', () => { | ||
const head = createHead() | ||
useHead({ | ||
htmlAttrs: { | ||
lang: () => false, | ||
class: { | ||
foo: () => false, | ||
something: computed(() => true), | ||
}, | ||
}, | ||
base: { href: () => '/base' }, | ||
link: () => [], | ||
meta: [ | ||
{ key: 'key', name: 'description', content: 'some description ' }, | ||
() => ({ key: 'key', name: 'description', content: 'some description ' }), | ||
], | ||
script: [ | ||
() => 'test', | ||
{ | ||
innerHTML: () => 'foo', | ||
}, | ||
], | ||
style: () => [ | ||
() => 'foo', | ||
], | ||
titleTemplate: (titleChunk) => { | ||
return titleChunk ? `${titleChunk} - Site Title` : 'Site Title' | ||
}, | ||
}, { | ||
head, | ||
}) | ||
|
||
useHead(() => ({ | ||
title: 'foo', | ||
}), { | ||
head, | ||
}) | ||
}) | ||
}) |