@unhead/vue 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +22 -5
- package/dist/index.mjs +21 -32
- package/dist/runtimes/client/useHead.mjs +7 -15
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MaybeComputedRef, MaybeRef } from '@vueuse/shared';
|
|
2
2
|
import * as _unhead_schema from '@unhead/schema';
|
|
3
|
-
import { Title as Title$1, TitleTemplate as TitleTemplate$1, EntryAugmentation, Base as Base$1, Link as Link$1, Meta as Meta$1, Style as Style$1, Script as Script$1, Noscript as Noscript$1,
|
|
3
|
+
import { Title as Title$1, TitleTemplate as TitleTemplate$1, EntryAugmentation, Base as Base$1, Link as Link$1, Meta as Meta$1, Style as Style$1, Script as Script$1, Noscript as Noscript$1, SchemaAugmentations, MergeHead, BaseHtmlAttr, MaybeArray, BaseBodyAttr } from '@unhead/schema';
|
|
4
|
+
import { DataKeys, DefinedValueOrEmptyObject } from '@zhead/schema';
|
|
4
5
|
import * as unhead from 'unhead';
|
|
5
6
|
import { HeadEntryOptions, Arrayable, HeadClient } from 'unhead';
|
|
6
7
|
import { InjectionKey, Plugin } from 'vue';
|
|
@@ -9,6 +10,22 @@ declare type MaybeComputedRefEntries<T> = MaybeComputedRef<T> | {
|
|
|
9
10
|
[key in keyof T]?: MaybeComputedRef<T[key]>;
|
|
10
11
|
};
|
|
11
12
|
|
|
13
|
+
interface HtmlAttr extends Omit<BaseHtmlAttr, 'class'> {
|
|
14
|
+
/**
|
|
15
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
16
|
+
*
|
|
17
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
18
|
+
*/
|
|
19
|
+
class?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<boolean>>;
|
|
20
|
+
}
|
|
21
|
+
interface BodyAttr extends Omit<BaseBodyAttr, 'class'> {
|
|
22
|
+
/**
|
|
23
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
24
|
+
*
|
|
25
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
26
|
+
*/
|
|
27
|
+
class?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<boolean>>;
|
|
28
|
+
}
|
|
12
29
|
declare type Title = MaybeComputedRef<Title$1>;
|
|
13
30
|
declare type TitleTemplate = MaybeRef<TitleTemplate$1> | ((title?: string) => TitleTemplate$1);
|
|
14
31
|
declare type Base<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<Base$1<E>>>;
|
|
@@ -17,8 +34,8 @@ declare type Meta<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Me
|
|
|
17
34
|
declare type Style<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Style$1<E>>;
|
|
18
35
|
declare type Script<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Script$1<E>>;
|
|
19
36
|
declare type Noscript<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Noscript$1<E>>;
|
|
20
|
-
declare type HtmlAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<
|
|
21
|
-
declare type BodyAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<
|
|
37
|
+
declare type HtmlAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<HtmlAttr & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>>>;
|
|
38
|
+
declare type BodyAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<BodyAttr & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>>>;
|
|
22
39
|
interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
23
40
|
/**
|
|
24
41
|
* The <title> HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
|
|
@@ -88,7 +105,7 @@ interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
|
88
105
|
|
|
89
106
|
declare function resolveUnrefHeadInput(ref: any): any;
|
|
90
107
|
|
|
91
|
-
declare const
|
|
108
|
+
declare const VueReactiveInputPlugin: unhead.HeadPlugin<_unhead_schema.Head<_unhead_schema.SchemaAugmentations>>;
|
|
92
109
|
|
|
93
110
|
declare function useServerHead(input: ReactiveHead, options?: HeadEntryOptions): void;
|
|
94
111
|
declare function useHead(input: ReactiveHead, options?: HeadEntryOptions): void;
|
|
@@ -109,4 +126,4 @@ declare const headSymbol: InjectionKey<VueHeadClient>;
|
|
|
109
126
|
declare function injectHead(): VueHeadClient;
|
|
110
127
|
declare function createHead(): HeadClient<ReactiveHead> & Plugin;
|
|
111
128
|
|
|
112
|
-
export { Base, BodyAttributes, HtmlAttributes, Link, MaybeComputedRefEntries, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate, Vue3, VueHeadClient, createHead, headSymbol, injectHead, resolveUnrefHeadInput,
|
|
129
|
+
export { Base, BodyAttributes, HtmlAttributes, Link, MaybeComputedRefEntries, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate, Vue3, VueHeadClient, VueReactiveInputPlugin, createHead, headSymbol, injectHead, resolveUnrefHeadInput, useBase, useBodyAttrs, useHead, useHtmlAttrs, useLink, useMeta, useNoscript, useScript, useServerHead, useStyle, useTitle, useTitleTemplate };
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveUnref } from '@vueuse/shared';
|
|
2
2
|
import { unref, getCurrentInstance, ref, watchEffect, watch, nextTick, onBeforeUnmount, version, inject } from 'vue';
|
|
3
|
-
import { defineHeadPlugin, asArray, getActiveHead, createHead as createHead$1,
|
|
4
|
-
import {
|
|
3
|
+
import { defineHeadPlugin, asArray, getActiveHead, createHead as createHead$1, HydratesStatePlugin } from 'unhead';
|
|
4
|
+
import { debouncedRenderDOMHead } from 'unhead/client';
|
|
5
5
|
|
|
6
6
|
function resolveUnrefHeadInput(ref) {
|
|
7
7
|
const root = resolveUnref(ref);
|
|
@@ -14,21 +14,18 @@ function resolveUnrefHeadInput(ref) {
|
|
|
14
14
|
Object.entries(root).map(([key, value]) => {
|
|
15
15
|
if (key === "titleTemplate")
|
|
16
16
|
return [key, unref(value)];
|
|
17
|
-
return [
|
|
18
|
-
key,
|
|
19
|
-
resolveUnrefHeadInput(value)
|
|
20
|
-
];
|
|
17
|
+
return [key, resolveUnrefHeadInput(value)];
|
|
21
18
|
})
|
|
22
19
|
);
|
|
23
20
|
}
|
|
24
21
|
return root;
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
const
|
|
24
|
+
const VueReactiveInputPlugin = defineHeadPlugin({
|
|
28
25
|
hooks: {
|
|
29
|
-
"entries:resolve": function(
|
|
30
|
-
for (const
|
|
31
|
-
|
|
26
|
+
"entries:resolve": function(ctx) {
|
|
27
|
+
for (const entry of ctx.entries)
|
|
28
|
+
entry.input = resolveUnrefHeadInput(entry.input);
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
});
|
|
@@ -40,7 +37,7 @@ function useHead$2(input, options = {}) {
|
|
|
40
37
|
head.push(input, options);
|
|
41
38
|
}
|
|
42
39
|
|
|
43
|
-
function useServerHead$
|
|
40
|
+
function useServerHead$1(input, options = {}) {
|
|
44
41
|
useHead$2(input, { ...options, mode: "server" });
|
|
45
42
|
}
|
|
46
43
|
|
|
@@ -48,42 +45,34 @@ function useHead$1(input, options = {}) {
|
|
|
48
45
|
const head = injectHead();
|
|
49
46
|
const vm = getCurrentInstance();
|
|
50
47
|
if (!vm) {
|
|
51
|
-
head.push(
|
|
52
|
-
input,
|
|
53
|
-
options
|
|
54
|
-
);
|
|
48
|
+
head.push(input, options);
|
|
55
49
|
return;
|
|
56
50
|
}
|
|
57
|
-
const sideEffects = [];
|
|
58
51
|
const resolvedInput = ref({});
|
|
59
52
|
watchEffect(() => {
|
|
60
53
|
resolvedInput.value = resolveUnrefHeadInput(input);
|
|
61
54
|
});
|
|
62
55
|
let entry;
|
|
63
56
|
watch(resolvedInput, (e) => {
|
|
64
|
-
if (!entry)
|
|
57
|
+
if (!entry)
|
|
65
58
|
entry = head.push(e, options);
|
|
66
|
-
|
|
67
|
-
} else {
|
|
59
|
+
else
|
|
68
60
|
entry.patch(e);
|
|
69
|
-
|
|
70
|
-
}
|
|
61
|
+
debouncedRenderDOMHead(nextTick, head);
|
|
71
62
|
}, { immediate: true });
|
|
72
63
|
onBeforeUnmount(() => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
entry.dispose();
|
|
76
|
-
debouncedUpdateDom(nextTick, head);
|
|
64
|
+
entry?.dispose();
|
|
65
|
+
debouncedRenderDOMHead(nextTick, head);
|
|
77
66
|
});
|
|
78
67
|
}
|
|
79
68
|
|
|
80
|
-
function useServerHead$1(input, options = {}) {
|
|
81
|
-
}
|
|
82
|
-
|
|
83
69
|
function useServerHead(input, options = {}) {
|
|
84
|
-
|
|
70
|
+
if (!IS_CLIENT)
|
|
71
|
+
useServerHead$1(input, options);
|
|
85
72
|
}
|
|
86
73
|
function useHead(input, options = {}) {
|
|
74
|
+
if (options.mode === "server" && IS_CLIENT || options.mode === "client" && !IS_CLIENT)
|
|
75
|
+
return;
|
|
87
76
|
return IS_CLIENT ? useHead$1(input, options) : useHead$2(input, options);
|
|
88
77
|
}
|
|
89
78
|
const useTitle = (title) => useHead({ title });
|
|
@@ -105,8 +94,8 @@ function injectHead() {
|
|
|
105
94
|
function createHead() {
|
|
106
95
|
const head = createHead$1({
|
|
107
96
|
plugins: [
|
|
108
|
-
|
|
109
|
-
|
|
97
|
+
HydratesStatePlugin,
|
|
98
|
+
VueReactiveInputPlugin
|
|
110
99
|
]
|
|
111
100
|
});
|
|
112
101
|
const vuePlugin = {
|
|
@@ -131,4 +120,4 @@ function createHead() {
|
|
|
131
120
|
return { ...vuePlugin, ...head };
|
|
132
121
|
}
|
|
133
122
|
|
|
134
|
-
export { Vue3, createHead, headSymbol, injectHead, resolveUnrefHeadInput,
|
|
123
|
+
export { Vue3, VueReactiveInputPlugin, createHead, headSymbol, injectHead, resolveUnrefHeadInput, useBase, useBodyAttrs, useHead, useHtmlAttrs, useLink, useMeta, useNoscript, useScript, useServerHead, useStyle, useTitle, useTitleTemplate };
|
|
@@ -1,35 +1,27 @@
|
|
|
1
1
|
import { getCurrentInstance, nextTick, onBeforeUnmount, ref, watch, watchEffect } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { debouncedRenderDOMHead } from "unhead/client";
|
|
3
3
|
import { injectHead, resolveUnrefHeadInput } from "../../index";
|
|
4
4
|
export function useHead(input, options = {}) {
|
|
5
5
|
const head = injectHead();
|
|
6
6
|
const vm = getCurrentInstance();
|
|
7
7
|
if (!vm) {
|
|
8
|
-
head.push(
|
|
9
|
-
input,
|
|
10
|
-
options
|
|
11
|
-
);
|
|
8
|
+
head.push(input, options);
|
|
12
9
|
return;
|
|
13
10
|
}
|
|
14
|
-
const sideEffects = [];
|
|
15
11
|
const resolvedInput = ref({});
|
|
16
12
|
watchEffect(() => {
|
|
17
13
|
resolvedInput.value = resolveUnrefHeadInput(input);
|
|
18
14
|
});
|
|
19
15
|
let entry;
|
|
20
16
|
watch(resolvedInput, (e) => {
|
|
21
|
-
if (!entry)
|
|
17
|
+
if (!entry)
|
|
22
18
|
entry = head.push(e, options);
|
|
23
|
-
|
|
24
|
-
} else {
|
|
19
|
+
else
|
|
25
20
|
entry.patch(e);
|
|
26
|
-
|
|
27
|
-
}
|
|
21
|
+
debouncedRenderDOMHead(nextTick, head);
|
|
28
22
|
}, { immediate: true });
|
|
29
23
|
onBeforeUnmount(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
entry.dispose();
|
|
33
|
-
debouncedUpdateDom(nextTick, head);
|
|
24
|
+
entry?.dispose();
|
|
25
|
+
debouncedRenderDOMHead(nextTick, head);
|
|
34
26
|
});
|
|
35
27
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,9 +31,10 @@
|
|
|
31
31
|
"vue": ">=2.7 || >=3"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unhead/schema": "0.0.
|
|
34
|
+
"@unhead/schema": "0.0.2",
|
|
35
35
|
"@vueuse/shared": "latest",
|
|
36
|
-
"
|
|
36
|
+
"@zhead/schema": "^1.0.0-beta.4",
|
|
37
|
+
"unhead": "0.0.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"vue": "latest"
|