-
-
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.
fix(core,vue): missing subpath exports
- Loading branch information
Showing
20 changed files
with
186 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './dist/server' | ||
export * from './dist/legacy' |
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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
import { composableNames } from '@unhead/shared' | ||
|
||
const coreComposableNames = [ | ||
'injectHead', | ||
] | ||
|
||
export const unheadVueComposablesImports = { | ||
'@unhead/vue': [...coreComposableNames, ...composableNames], | ||
'@unhead/vue': ['injectHead', ...composableNames], | ||
} |
4 changes: 2 additions & 2 deletions
4
packages/vue/src/components/Head.ts → packages/vue/src/components.ts
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 was deleted.
Oops, something went wrong.
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,112 @@ | ||
import type { ActiveHeadEntry, HeadEntryOptions, MergeHead } from '@unhead/schema' | ||
import type { | ||
Ref, | ||
} from 'vue' | ||
import type { | ||
ReactiveHead, | ||
UseHeadInput, | ||
UseHeadOptions, | ||
UseHeadSafeInput, | ||
UseSeoMetaInput, | ||
VueHeadClient, | ||
} from './types' | ||
import { unpackMeta, whitelistSafeInput } from '@unhead/shared' | ||
import { | ||
getCurrentInstance, | ||
hasInjectionContext, | ||
inject, | ||
onActivated, | ||
onBeforeUnmount, | ||
onDeactivated, | ||
ref, | ||
watch, | ||
watchEffect, | ||
} from 'vue' | ||
import { headSymbol } from './install' | ||
import { resolveUnrefHeadInput } from './utils' | ||
|
||
export function injectHead() { | ||
if (hasInjectionContext()) { | ||
// fallback to vue context | ||
const instance = inject<VueHeadClient<MergeHead>>(headSymbol) | ||
if (!instance) { | ||
throw new Error('useHead() was called without provide context, ensure you call it through the setup() function.') | ||
} | ||
return instance | ||
} | ||
throw new Error('useHead() was called without provide context, ensure you call it through the setup() function.') | ||
} | ||
|
||
export function useHead<T extends MergeHead>(input: UseHeadInput<T>, options: UseHeadOptions = {}): ActiveHeadEntry<UseHeadInput<T>> { | ||
const head = options.head || injectHead() | ||
return head.ssr ? head.push(input, options as HeadEntryOptions) : clientUseHead(head, input, options as HeadEntryOptions) | ||
} | ||
|
||
function clientUseHead<T extends MergeHead>(head: VueHeadClient<T>, input: UseHeadInput<T>, options: HeadEntryOptions = {}): ActiveHeadEntry<UseHeadInput<T>> { | ||
const deactivated = ref(false) | ||
|
||
const resolvedInput: Ref<ReactiveHead> = ref({}) | ||
watchEffect(() => { | ||
resolvedInput.value = deactivated.value | ||
? {} | ||
: resolveUnrefHeadInput(input) | ||
}) | ||
const entry: ActiveHeadEntry<UseHeadInput<T>> = head.push(resolvedInput.value, options) | ||
watch(resolvedInput, (e) => { | ||
entry.patch(e) | ||
}) | ||
|
||
const vm = getCurrentInstance() | ||
if (vm) { | ||
onBeforeUnmount(() => { | ||
entry.dispose() | ||
}) | ||
onDeactivated(() => { | ||
deactivated.value = true | ||
}) | ||
onActivated(() => { | ||
deactivated.value = false | ||
}) | ||
} | ||
return entry | ||
} | ||
|
||
export function useHeadSafe(input: UseHeadSafeInput, options: UseHeadOptions = {}): ActiveHeadEntry<any> { | ||
// @ts-expect-error untyped | ||
return useHead(input, { ...options, transform: whitelistSafeInput }) | ||
} | ||
|
||
export function useSeoMeta(input: UseSeoMetaInput, options?: UseHeadOptions): ActiveHeadEntry<any> { | ||
const { title, titleTemplate, ...meta } = input | ||
return useHead({ | ||
title, | ||
titleTemplate, | ||
// @ts-expect-error runtime type | ||
_flatMeta: meta, | ||
}, { | ||
...options, | ||
transform(t) { | ||
// @ts-expect-error runtime type | ||
const meta = unpackMeta({ ...t._flatMeta }) | ||
// @ts-expect-error runtime type | ||
delete t._flatMeta | ||
return { | ||
// @ts-expect-error runtime type | ||
...t, | ||
meta, | ||
} | ||
}, | ||
}) | ||
} | ||
|
||
export function useServerHead<T extends MergeHead>(input: UseHeadInput<T>, options: UseHeadOptions = {}): ActiveHeadEntry<any> { | ||
return useHead<T>(input, { ...options, mode: 'server' }) | ||
} | ||
|
||
export function useServerHeadSafe(input: UseHeadSafeInput, options: UseHeadOptions = {}): ActiveHeadEntry<any> { | ||
return useHeadSafe(input, { ...options, mode: 'server' }) | ||
} | ||
|
||
export function useServerSeoMeta(input: UseSeoMetaInput, options?: UseHeadOptions): ActiveHeadEntry<UseSeoMetaInput> { | ||
return useSeoMeta(input, { ...options, mode: 'server' }) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.