@unhead/vue 0.2.7 → 0.4.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 +49 -54
- package/dist/index.d.ts +10 -10
- package/dist/index.mjs +49 -54
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -14,7 +14,7 @@ function resolveUnrefHeadInput(ref) {
|
|
|
14
14
|
if (typeof root === "object") {
|
|
15
15
|
return Object.fromEntries(
|
|
16
16
|
Object.entries(root).map(([key, value]) => {
|
|
17
|
-
if (key === "titleTemplate")
|
|
17
|
+
if (key === "titleTemplate" || key.startsWith("on"))
|
|
18
18
|
return [key, vue.unref(value)];
|
|
19
19
|
return [key, resolveUnrefHeadInput(value)];
|
|
20
20
|
})
|
|
@@ -26,16 +26,9 @@ function asArray(value) {
|
|
|
26
26
|
return Array.isArray(value) ? value : [value];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"entries:resolve": function(ctx) {
|
|
33
|
-
for (const entry of ctx.entries)
|
|
34
|
-
entry.input = resolveUnrefHeadInput(entry.input);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
};
|
|
29
|
+
const Vue3 = vue.version.startsWith("3");
|
|
30
|
+
vue.version.startsWith("2.");
|
|
31
|
+
const IsBrowser = typeof window !== "undefined";
|
|
39
32
|
|
|
40
33
|
function unpackToArray(input, options) {
|
|
41
34
|
const unpacked = [];
|
|
@@ -177,10 +170,6 @@ function changeKeyCasingDeep(input) {
|
|
|
177
170
|
return output;
|
|
178
171
|
}
|
|
179
172
|
|
|
180
|
-
const Vue3 = vue.version.startsWith("3");
|
|
181
|
-
vue.version.startsWith("2.");
|
|
182
|
-
const IsBrowser = typeof window !== "undefined";
|
|
183
|
-
|
|
184
173
|
function clientUseHead(input, options = {}) {
|
|
185
174
|
const head = injectHead();
|
|
186
175
|
const vm = vue.getCurrentInstance();
|
|
@@ -260,64 +249,70 @@ function injectHead() {
|
|
|
260
249
|
function createHead(options = {}) {
|
|
261
250
|
const plugins = [
|
|
262
251
|
unhead.HydratesStatePlugin(),
|
|
263
|
-
|
|
252
|
+
VueReactiveUseHeadPlugin(),
|
|
264
253
|
...options?.plugins || []
|
|
265
254
|
];
|
|
266
255
|
const head = unhead.createHead({
|
|
267
256
|
...options,
|
|
268
|
-
domDelayFn: vue.nextTick,
|
|
257
|
+
domDelayFn: (fn) => setTimeout(() => vue.nextTick(() => fn()), 10),
|
|
269
258
|
plugins
|
|
270
259
|
});
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
app.config.globalProperties.$head = head;
|
|
260
|
+
head.install = (app) => {
|
|
261
|
+
if (Vue3) {
|
|
262
|
+
app.config.globalProperties.$unhead = head;
|
|
275
263
|
app.provide(headSymbol, head);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
const instance = vue.getCurrentInstance();
|
|
279
|
-
if (!instance)
|
|
280
|
-
return;
|
|
281
|
-
const options2 = instance.type;
|
|
282
|
-
if (!options2 || !("head" in options2))
|
|
283
|
-
return;
|
|
284
|
-
const source = typeof options2.head === "function" ? () => options2.head() : options2.head;
|
|
285
|
-
useHead(source);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
264
|
+
} else {
|
|
265
|
+
app.options.$unhead = head;
|
|
288
266
|
}
|
|
267
|
+
app.mixin({
|
|
268
|
+
created() {
|
|
269
|
+
const instance = vue.getCurrentInstance();
|
|
270
|
+
if (!instance)
|
|
271
|
+
return;
|
|
272
|
+
const options2 = Vue3 ? instance.type : instance.proxy.$options;
|
|
273
|
+
if (!options2 || !("head" in options2))
|
|
274
|
+
return;
|
|
275
|
+
const source = typeof options2.head === "function" ? () => options2.head() : options2.head;
|
|
276
|
+
useHead(source);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
289
279
|
};
|
|
290
|
-
return
|
|
280
|
+
return head;
|
|
291
281
|
}
|
|
292
282
|
|
|
293
|
-
const
|
|
283
|
+
const VueReactiveUseHeadPlugin = () => {
|
|
284
|
+
return unhead.defineHeadPlugin({
|
|
285
|
+
hooks: {
|
|
286
|
+
"entries:resolve": function(ctx) {
|
|
287
|
+
for (const entry of ctx.entries)
|
|
288
|
+
entry.input = resolveUnrefHeadInput(entry.input);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
const Vue2ProvideUnheadPlugin = function(_Vue, head) {
|
|
294
295
|
_Vue.mixin({
|
|
295
296
|
beforeCreate() {
|
|
296
297
|
const options = this.$options;
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
[headSymbol]: options.head
|
|
308
|
-
};
|
|
298
|
+
const origProvide = options.provide;
|
|
299
|
+
options.provide = function() {
|
|
300
|
+
let origProvideResult;
|
|
301
|
+
if (typeof origProvide === "function")
|
|
302
|
+
origProvideResult = origProvide.call(this);
|
|
303
|
+
else
|
|
304
|
+
origProvideResult = origProvide || {};
|
|
305
|
+
return {
|
|
306
|
+
...origProvideResult,
|
|
307
|
+
[headSymbol]: head
|
|
309
308
|
};
|
|
310
|
-
|
|
311
|
-
this.$head = options.head;
|
|
312
|
-
} else if (!this.$head && options.parent && options.parent.$head) {
|
|
313
|
-
this.$head = options.parent.$head;
|
|
314
|
-
}
|
|
309
|
+
};
|
|
315
310
|
}
|
|
316
311
|
});
|
|
317
312
|
};
|
|
318
313
|
|
|
319
|
-
exports.
|
|
320
|
-
exports.
|
|
314
|
+
exports.Vue2ProvideUnheadPlugin = Vue2ProvideUnheadPlugin;
|
|
315
|
+
exports.VueReactiveUseHeadPlugin = VueReactiveUseHeadPlugin;
|
|
321
316
|
exports.asArray = asArray;
|
|
322
317
|
exports.createHead = createHead;
|
|
323
318
|
exports.headSymbol = headSymbol;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MaybeComputedRef, MaybeRef } from '@vueuse/shared';
|
|
2
2
|
export { MaybeComputedRef } from '@vueuse/shared';
|
|
3
3
|
import * as _unhead_schema from '@unhead/schema';
|
|
4
|
-
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, DataKeys, SchemaAugmentations, DefinedValueOrEmptyObject, MergeHead, BaseHtmlAttr, MaybeArray, BaseBodyAttr,
|
|
4
|
+
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, DataKeys, SchemaAugmentations, DefinedValueOrEmptyObject, MergeHead, BaseHtmlAttr, MaybeArray, BaseBodyAttr, Unhead, CreateHeadOptions, HeadEntryOptions, MetaFlatInput } from '@unhead/schema';
|
|
5
5
|
export { ActiveHeadEntry, Head, HeadEntryOptions, HeadTag, MergeHead, Unhead } from '@unhead/schema';
|
|
6
6
|
import { Plugin } from 'vue';
|
|
7
7
|
export * from '@unhead/dom';
|
|
@@ -108,7 +108,14 @@ declare type UseHeadInput<T extends MergeHead = {}> = MaybeComputedRef<ReactiveH
|
|
|
108
108
|
declare function resolveUnrefHeadInput(ref: any): any;
|
|
109
109
|
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
110
110
|
|
|
111
|
-
declare
|
|
111
|
+
declare type VueHeadClient<T extends MergeHead> = Unhead<MaybeComputedRef<ReactiveHead<T>>> & Plugin;
|
|
112
|
+
declare const headSymbol = "usehead";
|
|
113
|
+
declare function injectHead<T extends MergeHead>(): VueHeadClient<T>;
|
|
114
|
+
declare function createHead<T extends MergeHead>(options?: Omit<CreateHeadOptions, 'domDelayFn'>): VueHeadClient<T>;
|
|
115
|
+
|
|
116
|
+
declare const VueReactiveUseHeadPlugin: () => _unhead_schema.HeadPlugin;
|
|
117
|
+
|
|
118
|
+
declare const Vue2ProvideUnheadPlugin: Plugin;
|
|
112
119
|
|
|
113
120
|
declare function useServerHead<T extends MergeHead>(input: UseHeadInput<T>, options?: HeadEntryOptions): void;
|
|
114
121
|
declare const useServerTagTitle: (title: ReactiveHead['title']) => void;
|
|
@@ -136,11 +143,4 @@ declare const useTagBase: (base: ReactiveHead['base']) => void;
|
|
|
136
143
|
declare const useHtmlAttrs: (attrs: ReactiveHead['htmlAttrs']) => void;
|
|
137
144
|
declare const useBodyAttrs: (attrs: ReactiveHead['bodyAttrs']) => void;
|
|
138
145
|
|
|
139
|
-
|
|
140
|
-
declare const headSymbol = "usehead";
|
|
141
|
-
declare function injectHead<T extends MergeHead>(): VueHeadClient<T>;
|
|
142
|
-
declare function createHead<T extends MergeHead>(options?: Omit<CreateHeadOptions, 'domDelayFn'>): VueHeadClient<T>;
|
|
143
|
-
|
|
144
|
-
declare const HeadVuePlugin: Plugin;
|
|
145
|
-
|
|
146
|
-
export { Arrayable, Base, BodyAttributes, HeadVuePlugin, HtmlAttributes, Link, MaybeComputedRefEntries, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate, UseHeadInput, VueHeadClient, VueReactiveInputPlugin, asArray, createHead, headSymbol, injectHead, resolveUnrefHeadInput, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
|
146
|
+
export { Arrayable, Base, BodyAttributes, HtmlAttributes, Link, MaybeComputedRefEntries, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate, UseHeadInput, Vue2ProvideUnheadPlugin, VueHeadClient, VueReactiveUseHeadPlugin, asArray, createHead, headSymbol, injectHead, resolveUnrefHeadInput, useBodyAttrs, useHead, useHtmlAttrs, 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveUnref } from '@vueuse/shared';
|
|
2
2
|
import { unref, version, getCurrentInstance, ref, watchEffect, watch, onBeforeUnmount, inject, nextTick } from 'vue';
|
|
3
|
-
import {
|
|
3
|
+
import { getActiveHead, HydratesStatePlugin, createHead as createHead$1, defineHeadPlugin } from 'unhead';
|
|
4
4
|
export * from '@unhead/dom';
|
|
5
5
|
|
|
6
6
|
function resolveUnrefHeadInput(ref) {
|
|
@@ -12,7 +12,7 @@ function resolveUnrefHeadInput(ref) {
|
|
|
12
12
|
if (typeof root === "object") {
|
|
13
13
|
return Object.fromEntries(
|
|
14
14
|
Object.entries(root).map(([key, value]) => {
|
|
15
|
-
if (key === "titleTemplate")
|
|
15
|
+
if (key === "titleTemplate" || key.startsWith("on"))
|
|
16
16
|
return [key, unref(value)];
|
|
17
17
|
return [key, resolveUnrefHeadInput(value)];
|
|
18
18
|
})
|
|
@@ -24,16 +24,9 @@ function asArray(value) {
|
|
|
24
24
|
return Array.isArray(value) ? value : [value];
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"entries:resolve": function(ctx) {
|
|
31
|
-
for (const entry of ctx.entries)
|
|
32
|
-
entry.input = resolveUnrefHeadInput(entry.input);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
};
|
|
27
|
+
const Vue3 = version.startsWith("3");
|
|
28
|
+
version.startsWith("2.");
|
|
29
|
+
const IsBrowser = typeof window !== "undefined";
|
|
37
30
|
|
|
38
31
|
function unpackToArray(input, options) {
|
|
39
32
|
const unpacked = [];
|
|
@@ -175,10 +168,6 @@ function changeKeyCasingDeep(input) {
|
|
|
175
168
|
return output;
|
|
176
169
|
}
|
|
177
170
|
|
|
178
|
-
const Vue3 = version.startsWith("3");
|
|
179
|
-
version.startsWith("2.");
|
|
180
|
-
const IsBrowser = typeof window !== "undefined";
|
|
181
|
-
|
|
182
171
|
function clientUseHead(input, options = {}) {
|
|
183
172
|
const head = injectHead();
|
|
184
173
|
const vm = getCurrentInstance();
|
|
@@ -258,60 +247,66 @@ function injectHead() {
|
|
|
258
247
|
function createHead(options = {}) {
|
|
259
248
|
const plugins = [
|
|
260
249
|
HydratesStatePlugin(),
|
|
261
|
-
|
|
250
|
+
VueReactiveUseHeadPlugin(),
|
|
262
251
|
...options?.plugins || []
|
|
263
252
|
];
|
|
264
253
|
const head = createHead$1({
|
|
265
254
|
...options,
|
|
266
|
-
domDelayFn: nextTick,
|
|
255
|
+
domDelayFn: (fn) => setTimeout(() => nextTick(() => fn()), 10),
|
|
267
256
|
plugins
|
|
268
257
|
});
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
app.config.globalProperties.$head = head;
|
|
258
|
+
head.install = (app) => {
|
|
259
|
+
if (Vue3) {
|
|
260
|
+
app.config.globalProperties.$unhead = head;
|
|
273
261
|
app.provide(headSymbol, head);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
const instance = getCurrentInstance();
|
|
277
|
-
if (!instance)
|
|
278
|
-
return;
|
|
279
|
-
const options2 = instance.type;
|
|
280
|
-
if (!options2 || !("head" in options2))
|
|
281
|
-
return;
|
|
282
|
-
const source = typeof options2.head === "function" ? () => options2.head() : options2.head;
|
|
283
|
-
useHead(source);
|
|
284
|
-
}
|
|
285
|
-
});
|
|
262
|
+
} else {
|
|
263
|
+
app.options.$unhead = head;
|
|
286
264
|
}
|
|
265
|
+
app.mixin({
|
|
266
|
+
created() {
|
|
267
|
+
const instance = getCurrentInstance();
|
|
268
|
+
if (!instance)
|
|
269
|
+
return;
|
|
270
|
+
const options2 = Vue3 ? instance.type : instance.proxy.$options;
|
|
271
|
+
if (!options2 || !("head" in options2))
|
|
272
|
+
return;
|
|
273
|
+
const source = typeof options2.head === "function" ? () => options2.head() : options2.head;
|
|
274
|
+
useHead(source);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
287
277
|
};
|
|
288
|
-
return
|
|
278
|
+
return head;
|
|
289
279
|
}
|
|
290
280
|
|
|
291
|
-
const
|
|
281
|
+
const VueReactiveUseHeadPlugin = () => {
|
|
282
|
+
return defineHeadPlugin({
|
|
283
|
+
hooks: {
|
|
284
|
+
"entries:resolve": function(ctx) {
|
|
285
|
+
for (const entry of ctx.entries)
|
|
286
|
+
entry.input = resolveUnrefHeadInput(entry.input);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const Vue2ProvideUnheadPlugin = function(_Vue, head) {
|
|
292
293
|
_Vue.mixin({
|
|
293
294
|
beforeCreate() {
|
|
294
295
|
const options = this.$options;
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
[headSymbol]: options.head
|
|
306
|
-
};
|
|
296
|
+
const origProvide = options.provide;
|
|
297
|
+
options.provide = function() {
|
|
298
|
+
let origProvideResult;
|
|
299
|
+
if (typeof origProvide === "function")
|
|
300
|
+
origProvideResult = origProvide.call(this);
|
|
301
|
+
else
|
|
302
|
+
origProvideResult = origProvide || {};
|
|
303
|
+
return {
|
|
304
|
+
...origProvideResult,
|
|
305
|
+
[headSymbol]: head
|
|
307
306
|
};
|
|
308
|
-
|
|
309
|
-
this.$head = options.head;
|
|
310
|
-
} else if (!this.$head && options.parent && options.parent.$head) {
|
|
311
|
-
this.$head = options.parent.$head;
|
|
312
|
-
}
|
|
307
|
+
};
|
|
313
308
|
}
|
|
314
309
|
});
|
|
315
310
|
};
|
|
316
311
|
|
|
317
|
-
export {
|
|
312
|
+
export { Vue2ProvideUnheadPlugin, VueReactiveUseHeadPlugin, asArray, createHead, headSymbol, injectHead, resolveUnrefHeadInput, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
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.4.1",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"vue": ">=2.7 || >=3"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unhead/dom": "0.
|
|
37
|
-
"@unhead/schema": "0.
|
|
36
|
+
"@unhead/dom": "0.4.1",
|
|
37
|
+
"@unhead/schema": "0.4.1",
|
|
38
38
|
"@vueuse/shared": "latest",
|
|
39
|
-
"unhead": "0.
|
|
39
|
+
"unhead": "0.4.1"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"vue": "^3.2.42"
|