@unhead/vue 0.6.9 → 0.7.1
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.cjs +18 -10
- package/dist/index.d.ts +20 -19
- package/dist/index.mjs +18 -10
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -233,13 +233,13 @@ const ValidHeadTags = [
|
|
|
233
233
|
];
|
|
234
234
|
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy"];
|
|
235
235
|
|
|
236
|
-
function normaliseTag(tagName, input) {
|
|
236
|
+
async function normaliseTag(tagName, input) {
|
|
237
237
|
const tag = { tag: tagName, props: {} };
|
|
238
238
|
if (tagName === "title" || tagName === "titleTemplate") {
|
|
239
|
-
tag.children = input;
|
|
239
|
+
tag.children = input instanceof Promise ? await input : input;
|
|
240
240
|
return tag;
|
|
241
241
|
}
|
|
242
|
-
tag.props = normaliseProps({ ...input });
|
|
242
|
+
tag.props = await normaliseProps({ ...input });
|
|
243
243
|
["children", "innerHtml", "innerHTML"].forEach((key) => {
|
|
244
244
|
if (typeof tag.props[key] !== "undefined") {
|
|
245
245
|
tag.children = tag.props[key];
|
|
@@ -265,8 +265,11 @@ function normaliseTag(tagName, input) {
|
|
|
265
265
|
}
|
|
266
266
|
return tag;
|
|
267
267
|
}
|
|
268
|
-
function normaliseProps(props) {
|
|
269
|
-
for (const k
|
|
268
|
+
async function normaliseProps(props) {
|
|
269
|
+
for (const k of Object.keys(props)) {
|
|
270
|
+
if (props[k] instanceof Promise) {
|
|
271
|
+
props[k] = await props[k];
|
|
272
|
+
}
|
|
270
273
|
if (String(props[k]) === "true") {
|
|
271
274
|
props[k] = "";
|
|
272
275
|
} else if (String(props[k]) === "false") {
|
|
@@ -600,10 +603,13 @@ const getActiveHead = () => activeHead;
|
|
|
600
603
|
|
|
601
604
|
const TagEntityBits = 10;
|
|
602
605
|
|
|
603
|
-
function normaliseEntryTags(e) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
606
|
+
async function normaliseEntryTags(e) {
|
|
607
|
+
const tagPromises = [];
|
|
608
|
+
Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).forEach(([k, value]) => {
|
|
609
|
+
const v = asArray$1(value);
|
|
610
|
+
tagPromises.push(...v.map((props) => normaliseTag(k, props)).flat());
|
|
611
|
+
});
|
|
612
|
+
return (await Promise.all(tagPromises)).flat().map((t, i) => {
|
|
607
613
|
t._e = e._i;
|
|
608
614
|
t._p = (e._i << TagEntityBits) + i;
|
|
609
615
|
return t;
|
|
@@ -686,7 +692,7 @@ function createHeadCore(options = {}) {
|
|
|
686
692
|
const resolveCtx = { tags: [], entries: [...entries] };
|
|
687
693
|
await hooks.callHook("entries:resolve", resolveCtx);
|
|
688
694
|
for (const entry of resolveCtx.entries) {
|
|
689
|
-
for (const tag of normaliseEntryTags(entry)) {
|
|
695
|
+
for (const tag of await normaliseEntryTags(entry)) {
|
|
690
696
|
const tagCtx = { tag, entry };
|
|
691
697
|
await hooks.callHook("tag:normalise", tagCtx);
|
|
692
698
|
resolveCtx.tags.push(tagCtx.tag);
|
|
@@ -741,6 +747,8 @@ function resolveUnref(r) {
|
|
|
741
747
|
return typeof r === "function" ? r() : vue.unref(r);
|
|
742
748
|
}
|
|
743
749
|
function resolveUnrefHeadInput(ref, lastKey = "") {
|
|
750
|
+
if (ref instanceof Promise)
|
|
751
|
+
return ref;
|
|
744
752
|
const root = resolveUnref(ref);
|
|
745
753
|
if (!ref || !root)
|
|
746
754
|
return root;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,12 +11,13 @@ import { ComputedRef, Ref, Plugin } from 'vue';
|
|
|
11
11
|
*/
|
|
12
12
|
declare function createHeadCore<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
type MaybeReadonlyRef<T> = (() => T) | ComputedRef<T>;
|
|
15
|
+
type MaybeComputedRef<T> = T | MaybeReadonlyRef<T> | Ref<T>;
|
|
16
|
+
type MaybeComputedRefOrPromise<T> = T | MaybeReadonlyRef<T> | Ref<T> | Promise<T>;
|
|
17
|
+
type MaybeComputedRefEntries<T> = MaybeComputedRef<T> | {
|
|
18
|
+
[key in keyof T]?: MaybeComputedRefOrPromise<T[key]>;
|
|
18
19
|
};
|
|
19
|
-
|
|
20
|
+
type Arrayable<T> = T | Array<T>;
|
|
20
21
|
|
|
21
22
|
interface HtmlAttr extends Omit<BaseHtmlAttr, 'class'> {
|
|
22
23
|
/**
|
|
@@ -34,16 +35,16 @@ interface BodyAttr extends Omit<BaseBodyAttr, 'class'> {
|
|
|
34
35
|
*/
|
|
35
36
|
class?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<boolean>>;
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
38
|
+
type Title = MaybeComputedRef<Title$1>;
|
|
39
|
+
type TitleTemplate = TitleTemplate$1 | Ref<TitleTemplate$1> | ((title?: string) => TitleTemplate$1);
|
|
40
|
+
type Base<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<Base$1<E>>>;
|
|
41
|
+
type Link<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Link$1<E>>;
|
|
42
|
+
type Meta<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Meta$1<E>>;
|
|
43
|
+
type Style<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Style$1<E>>;
|
|
44
|
+
type Script<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Script$1<E>>;
|
|
45
|
+
type Noscript<E extends EntryAugmentation = {}> = MaybeComputedRefEntries<Noscript$1<E>>;
|
|
46
|
+
type HtmlAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<HtmlAttr & DataKeys & SchemaAugmentations['htmlAttrs'] & DefinedValueOrEmptyObject<E>>>;
|
|
47
|
+
type BodyAttributes<E extends EntryAugmentation = {}> = MaybeComputedRef<MaybeComputedRefEntries<BodyAttr & DataKeys & SchemaAugmentations['bodyAttrs'] & DefinedValueOrEmptyObject<E>>>;
|
|
47
48
|
interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
48
49
|
/**
|
|
49
50
|
* The <title> HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
|
|
@@ -51,7 +52,7 @@ interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
|
51
52
|
*
|
|
52
53
|
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
|
|
53
54
|
*/
|
|
54
|
-
title?: Title
|
|
55
|
+
title?: Title | Promise<Title>;
|
|
55
56
|
/**
|
|
56
57
|
* Generate the title from a template.
|
|
57
58
|
*/
|
|
@@ -110,12 +111,12 @@ interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
|
110
111
|
*/
|
|
111
112
|
bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
+
type UseHeadInput<T extends MergeHead = {}> = MaybeComputedRef<ReactiveHead<T>>;
|
|
114
115
|
|
|
115
116
|
declare function resolveUnrefHeadInput(ref: any, lastKey?: string | number): any;
|
|
116
117
|
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
type VueHeadClient<T extends MergeHead> = Unhead<MaybeComputedRef<ReactiveHead<T>>> & Plugin;
|
|
119
120
|
declare const headSymbol = "usehead";
|
|
120
121
|
declare function injectHead<T extends MergeHead>(): VueHeadClient<T>;
|
|
121
122
|
declare function createHead<T extends MergeHead>(options?: Omit<CreateHeadOptions, 'domDelayFn'>): VueHeadClient<T>;
|
|
@@ -160,4 +161,4 @@ declare const unheadVueComposablesImports: {
|
|
|
160
161
|
imports: string[];
|
|
161
162
|
}[];
|
|
162
163
|
|
|
163
|
-
export { Arrayable, Base, BodyAttributes, HtmlAttributes, Link, MaybeComputedRef, MaybeComputedRefEntries, MaybeReadonlyRef, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate, UseHeadInput, Vue2ProvideUnheadPlugin, VueHeadClient, VueHeadMixin, VueReactiveUseHeadPlugin, asArray, createHead, createHeadCore, headSymbol, injectHead, resolveUnrefHeadInput, unheadVueComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
|
164
|
+
export { Arrayable, Base, BodyAttributes, HtmlAttributes, Link, MaybeComputedRef, MaybeComputedRefEntries, MaybeComputedRefOrPromise, MaybeReadonlyRef, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate, UseHeadInput, Vue2ProvideUnheadPlugin, VueHeadClient, VueHeadMixin, VueReactiveUseHeadPlugin, asArray, createHead, createHeadCore, headSymbol, injectHead, resolveUnrefHeadInput, unheadVueComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useSeoMeta, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
package/dist/index.mjs
CHANGED
|
@@ -231,13 +231,13 @@ const ValidHeadTags = [
|
|
|
231
231
|
];
|
|
232
232
|
const TagConfigKeys = ["tagPosition", "tagPriority", "tagDuplicateStrategy"];
|
|
233
233
|
|
|
234
|
-
function normaliseTag(tagName, input) {
|
|
234
|
+
async function normaliseTag(tagName, input) {
|
|
235
235
|
const tag = { tag: tagName, props: {} };
|
|
236
236
|
if (tagName === "title" || tagName === "titleTemplate") {
|
|
237
|
-
tag.children = input;
|
|
237
|
+
tag.children = input instanceof Promise ? await input : input;
|
|
238
238
|
return tag;
|
|
239
239
|
}
|
|
240
|
-
tag.props = normaliseProps({ ...input });
|
|
240
|
+
tag.props = await normaliseProps({ ...input });
|
|
241
241
|
["children", "innerHtml", "innerHTML"].forEach((key) => {
|
|
242
242
|
if (typeof tag.props[key] !== "undefined") {
|
|
243
243
|
tag.children = tag.props[key];
|
|
@@ -263,8 +263,11 @@ function normaliseTag(tagName, input) {
|
|
|
263
263
|
}
|
|
264
264
|
return tag;
|
|
265
265
|
}
|
|
266
|
-
function normaliseProps(props) {
|
|
267
|
-
for (const k
|
|
266
|
+
async function normaliseProps(props) {
|
|
267
|
+
for (const k of Object.keys(props)) {
|
|
268
|
+
if (props[k] instanceof Promise) {
|
|
269
|
+
props[k] = await props[k];
|
|
270
|
+
}
|
|
268
271
|
if (String(props[k]) === "true") {
|
|
269
272
|
props[k] = "";
|
|
270
273
|
} else if (String(props[k]) === "false") {
|
|
@@ -598,10 +601,13 @@ const getActiveHead = () => activeHead;
|
|
|
598
601
|
|
|
599
602
|
const TagEntityBits = 10;
|
|
600
603
|
|
|
601
|
-
function normaliseEntryTags(e) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
604
|
+
async function normaliseEntryTags(e) {
|
|
605
|
+
const tagPromises = [];
|
|
606
|
+
Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).forEach(([k, value]) => {
|
|
607
|
+
const v = asArray$1(value);
|
|
608
|
+
tagPromises.push(...v.map((props) => normaliseTag(k, props)).flat());
|
|
609
|
+
});
|
|
610
|
+
return (await Promise.all(tagPromises)).flat().map((t, i) => {
|
|
605
611
|
t._e = e._i;
|
|
606
612
|
t._p = (e._i << TagEntityBits) + i;
|
|
607
613
|
return t;
|
|
@@ -684,7 +690,7 @@ function createHeadCore(options = {}) {
|
|
|
684
690
|
const resolveCtx = { tags: [], entries: [...entries] };
|
|
685
691
|
await hooks.callHook("entries:resolve", resolveCtx);
|
|
686
692
|
for (const entry of resolveCtx.entries) {
|
|
687
|
-
for (const tag of normaliseEntryTags(entry)) {
|
|
693
|
+
for (const tag of await normaliseEntryTags(entry)) {
|
|
688
694
|
const tagCtx = { tag, entry };
|
|
689
695
|
await hooks.callHook("tag:normalise", tagCtx);
|
|
690
696
|
resolveCtx.tags.push(tagCtx.tag);
|
|
@@ -739,6 +745,8 @@ function resolveUnref(r) {
|
|
|
739
745
|
return typeof r === "function" ? r() : unref(r);
|
|
740
746
|
}
|
|
741
747
|
function resolveUnrefHeadInput(ref, lastKey = "") {
|
|
748
|
+
if (ref instanceof Promise)
|
|
749
|
+
return ref;
|
|
742
750
|
const root = resolveUnref(ref);
|
|
743
751
|
if (!ref || !root)
|
|
744
752
|
return root;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unhead/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"vue": ">=2.7 || >=3"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unhead/schema": "0.
|
|
36
|
+
"@unhead/schema": "0.7.1",
|
|
37
37
|
"hookable": "^5.4.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"unhead": "0.
|
|
40
|
+
"unhead": "0.7.1",
|
|
41
41
|
"vue": "^3.2.45"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|