@unhead/vue 0.0.4 → 0.0.6
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 +16 -7
- package/dist/index.mjs +101 -12
- package/dist/runtime/alias/composables.d.ts +3 -3
- package/dist/runtime/server/useHead.d.ts +2 -2
- package/dist/runtime/server/useServerHead.d.ts +2 -2
- package/dist/runtimes/client/useHead.d.ts +2 -2
- package/dist/runtimes/client/useServerHead.d.ts +2 -2
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { MaybeComputedRef, MaybeRef } from '@vueuse/shared';
|
|
2
2
|
import * as _unhead_schema from '@unhead/schema';
|
|
3
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
|
+
export { HeadTag, MergeHead } from '@unhead/schema';
|
|
4
5
|
import { DataKeys, DefinedValueOrEmptyObject } from '@zhead/schema';
|
|
5
6
|
import * as unhead from 'unhead';
|
|
6
|
-
import { HeadEntryOptions, Arrayable, HeadClient } from 'unhead';
|
|
7
|
-
import
|
|
7
|
+
import { HeadEntryOptions, Arrayable, HeadClient, CreateHeadOptions } from 'unhead';
|
|
8
|
+
import * as vue from 'vue';
|
|
9
|
+
import { Plugin, InjectionKey } from 'vue';
|
|
10
|
+
export { debouncedRenderDOMHead, renderDOMHead } from 'unhead/client';
|
|
11
|
+
export { renderSSRHead } from 'unhead/server';
|
|
8
12
|
|
|
9
13
|
declare type MaybeComputedRefEntries<T> = MaybeComputedRef<T> | {
|
|
10
14
|
[key in keyof T]?: MaybeComputedRef<T[key]>;
|
|
@@ -102,13 +106,14 @@ interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
|
102
106
|
*/
|
|
103
107
|
bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
|
|
104
108
|
}
|
|
109
|
+
declare type UseHeadInput = MaybeComputedRef<ReactiveHead>;
|
|
105
110
|
|
|
106
111
|
declare function resolveUnrefHeadInput(ref: any): any;
|
|
107
112
|
|
|
108
113
|
declare const VueReactiveInputPlugin: unhead.HeadPlugin<_unhead_schema.Head<_unhead_schema.SchemaAugmentations>>;
|
|
109
114
|
|
|
110
115
|
declare function useServerHead(input: ReactiveHead, options?: HeadEntryOptions): void;
|
|
111
|
-
declare function useHead(input:
|
|
116
|
+
declare function useHead(input: UseHeadInput, options?: HeadEntryOptions): void;
|
|
112
117
|
declare const useTitle: (title: ReactiveHead['title']) => void;
|
|
113
118
|
declare const useTitleTemplate: (titleTemplate: ReactiveHead['titleTemplate']) => void;
|
|
114
119
|
declare const useMeta: (meta: Arrayable<Meta>) => void;
|
|
@@ -120,10 +125,14 @@ declare const useBase: (base: ReactiveHead['base']) => void;
|
|
|
120
125
|
declare const useHtmlAttrs: (attrs: ReactiveHead['htmlAttrs']) => void;
|
|
121
126
|
declare const useBodyAttrs: (attrs: ReactiveHead['bodyAttrs']) => void;
|
|
122
127
|
|
|
123
|
-
declare
|
|
124
|
-
declare
|
|
128
|
+
declare type Props = Readonly<Record<string, any>>;
|
|
129
|
+
declare const Head: vue.DefineComponent<{}, () => null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.VNodeProps & vue.AllowedComponentProps & vue.ComponentCustomProps, Readonly<vue.ExtractPropTypes<{}>>, {}>;
|
|
130
|
+
|
|
131
|
+
declare type VueHeadClient = HeadClient<UseHeadInput> & Plugin;
|
|
125
132
|
declare const headSymbol: InjectionKey<VueHeadClient>;
|
|
126
133
|
declare function injectHead(): VueHeadClient;
|
|
127
|
-
declare function createHead(
|
|
134
|
+
declare function createHead<T>(options?: CreateHeadOptions<T>): VueHeadClient;
|
|
135
|
+
|
|
136
|
+
declare const HeadVuePlugin: Plugin;
|
|
128
137
|
|
|
129
|
-
export { Base, BodyAttributes, HtmlAttributes, Link, MaybeComputedRefEntries, Meta, Noscript, ReactiveHead, Script, Style, Title, TitleTemplate,
|
|
138
|
+
export { Base, BodyAttributes, Head, HeadVuePlugin, HtmlAttributes, Link, MaybeComputedRefEntries, Meta, Noscript, Props, ReactiveHead, Script, Style, Title, TitleTemplate, UseHeadInput, 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,10 @@
|
|
|
1
1
|
import { resolveUnref } from '@vueuse/shared';
|
|
2
|
-
import { unref, getCurrentInstance, ref, watchEffect, watch, nextTick, onBeforeUnmount,
|
|
2
|
+
import { unref, version, getCurrentInstance, ref, watchEffect, watch, nextTick, onBeforeUnmount, defineComponent, inject } from 'vue';
|
|
3
3
|
import { defineHeadPlugin, asArray, getActiveHead, createHead as createHead$1, HydratesStatePlugin } from 'unhead';
|
|
4
4
|
import { debouncedRenderDOMHead } from 'unhead/client';
|
|
5
|
+
export { debouncedRenderDOMHead, renderDOMHead } from 'unhead/client';
|
|
6
|
+
export { renderSSRHead } from 'unhead/server';
|
|
7
|
+
export { HeadTag, MergeHead } from '@unhead/schema';
|
|
5
8
|
|
|
6
9
|
function resolveUnrefHeadInput(ref) {
|
|
7
10
|
const root = resolveUnref(ref);
|
|
@@ -30,7 +33,9 @@ const VueReactiveInputPlugin = defineHeadPlugin({
|
|
|
30
33
|
}
|
|
31
34
|
});
|
|
32
35
|
|
|
33
|
-
const
|
|
36
|
+
const Vue3 = version.startsWith("3");
|
|
37
|
+
const Vue2 = version.startsWith("2.");
|
|
38
|
+
const IsClient = typeof window !== "undefined";
|
|
34
39
|
|
|
35
40
|
function useHead$2(input, options = {}) {
|
|
36
41
|
const head = injectHead();
|
|
@@ -67,13 +72,13 @@ function useHead$1(input, options = {}) {
|
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
function useServerHead(input, options = {}) {
|
|
70
|
-
if (!
|
|
75
|
+
if (!IsClient)
|
|
71
76
|
useServerHead$1(input, options);
|
|
72
77
|
}
|
|
73
78
|
function useHead(input, options = {}) {
|
|
74
|
-
if (options.mode === "server" &&
|
|
79
|
+
if (options.mode === "server" && IsClient || options.mode === "client" && !IsClient)
|
|
75
80
|
return;
|
|
76
|
-
return
|
|
81
|
+
return IsClient ? useHead$1(input, options) : useHead$2(input, options);
|
|
77
82
|
}
|
|
78
83
|
const useTitle = (title) => useHead({ title });
|
|
79
84
|
const useTitleTemplate = (titleTemplate) => useHead({ titleTemplate });
|
|
@@ -86,16 +91,74 @@ const useBase = (base) => useHead({ base });
|
|
|
86
91
|
const useHtmlAttrs = (attrs) => useHead({ htmlAttrs: attrs });
|
|
87
92
|
const useBodyAttrs = (attrs) => useHead({ bodyAttrs: attrs });
|
|
88
93
|
|
|
89
|
-
const
|
|
94
|
+
const addVNodeToHeadObj = (node, obj) => {
|
|
95
|
+
const nodeType = Vue2 ? node.tag : node.type;
|
|
96
|
+
const type = nodeType === "html" ? "htmlAttrs" : nodeType === "body" ? "bodyAttrs" : nodeType;
|
|
97
|
+
if (typeof type !== "string" || !(type in obj))
|
|
98
|
+
return;
|
|
99
|
+
const nodeData = Vue2 ? node.data : node;
|
|
100
|
+
const props = (Vue2 ? nodeData.attrs : node.props) || {};
|
|
101
|
+
if (Vue2) {
|
|
102
|
+
if (nodeData.staticClass)
|
|
103
|
+
props.class = nodeData.staticClass;
|
|
104
|
+
if (nodeData.staticStyle)
|
|
105
|
+
props.style = Object.entries(nodeData.staticStyle).map(([key, value]) => `${key}:${value}`).join(";");
|
|
106
|
+
}
|
|
107
|
+
if (node.children) {
|
|
108
|
+
const childrenAttr = Vue2 ? "text" : "children";
|
|
109
|
+
props.children = Array.isArray(node.children) ? node.children[0][childrenAttr] : node[childrenAttr];
|
|
110
|
+
}
|
|
111
|
+
if (Array.isArray(obj[type])) {
|
|
112
|
+
obj[type].push(props);
|
|
113
|
+
} else if (type === "title") {
|
|
114
|
+
obj.title = props.children;
|
|
115
|
+
} else {
|
|
116
|
+
obj[type] = props;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const vnodesToHeadObj = (nodes) => {
|
|
120
|
+
const obj = {
|
|
121
|
+
title: void 0,
|
|
122
|
+
htmlAttrs: void 0,
|
|
123
|
+
bodyAttrs: void 0,
|
|
124
|
+
base: void 0,
|
|
125
|
+
meta: [],
|
|
126
|
+
link: [],
|
|
127
|
+
style: [],
|
|
128
|
+
script: [],
|
|
129
|
+
noscript: []
|
|
130
|
+
};
|
|
131
|
+
for (const node of nodes) {
|
|
132
|
+
if (typeof node.type === "symbol" && Array.isArray(node.children)) {
|
|
133
|
+
for (const childNode of node.children)
|
|
134
|
+
addVNodeToHeadObj(childNode, obj);
|
|
135
|
+
} else {
|
|
136
|
+
addVNodeToHeadObj(node, obj);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return obj;
|
|
140
|
+
};
|
|
141
|
+
const Head = /* @__PURE__ */ defineComponent({
|
|
142
|
+
name: "Head",
|
|
143
|
+
setup(_, { slots }) {
|
|
144
|
+
return () => {
|
|
145
|
+
useHead(() => vnodesToHeadObj(slots.default()));
|
|
146
|
+
return null;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
90
151
|
const headSymbol = Symbol("head");
|
|
91
152
|
function injectHead() {
|
|
92
153
|
return getCurrentInstance() && inject(headSymbol) || getActiveHead();
|
|
93
154
|
}
|
|
94
|
-
function createHead() {
|
|
155
|
+
function createHead(options = {}) {
|
|
95
156
|
const head = createHead$1({
|
|
157
|
+
...options,
|
|
96
158
|
plugins: [
|
|
97
159
|
HydratesStatePlugin,
|
|
98
|
-
VueReactiveInputPlugin
|
|
160
|
+
VueReactiveInputPlugin,
|
|
161
|
+
...options?.plugins || []
|
|
99
162
|
]
|
|
100
163
|
});
|
|
101
164
|
const vuePlugin = {
|
|
@@ -108,10 +171,10 @@ function createHead() {
|
|
|
108
171
|
const instance = getCurrentInstance();
|
|
109
172
|
if (!instance)
|
|
110
173
|
return;
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
174
|
+
const options2 = instance.type;
|
|
175
|
+
if (!options2 || !("head" in options2))
|
|
113
176
|
return;
|
|
114
|
-
const source = typeof
|
|
177
|
+
const source = typeof options2.head === "function" ? () => options2.head() : options2.head;
|
|
115
178
|
head.push(source);
|
|
116
179
|
}
|
|
117
180
|
});
|
|
@@ -120,4 +183,30 @@ function createHead() {
|
|
|
120
183
|
return { ...vuePlugin, ...head };
|
|
121
184
|
}
|
|
122
185
|
|
|
123
|
-
|
|
186
|
+
const HeadVuePlugin = function(_Vue) {
|
|
187
|
+
_Vue.mixin({
|
|
188
|
+
beforeCreate() {
|
|
189
|
+
const options = this.$options;
|
|
190
|
+
if (options.head) {
|
|
191
|
+
const origProvide = options.provide;
|
|
192
|
+
options.provide = function() {
|
|
193
|
+
let origProvideResult;
|
|
194
|
+
if (typeof origProvide === "function")
|
|
195
|
+
origProvideResult = origProvide.call(this);
|
|
196
|
+
else
|
|
197
|
+
origProvideResult = origProvide || {};
|
|
198
|
+
return {
|
|
199
|
+
...origProvideResult,
|
|
200
|
+
[headSymbol]: options.head
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
if (!this.$head)
|
|
204
|
+
this.$head = options.head;
|
|
205
|
+
} else if (!this.$head && options.parent && options.parent.$head) {
|
|
206
|
+
this.$head = options.parent.$head;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
export { Head, HeadVuePlugin, VueReactiveInputPlugin, createHead, headSymbol, injectHead, resolveUnrefHeadInput, useBase, useBodyAttrs, useHead, useHtmlAttrs, useLink, useMeta, useNoscript, useScript, useServerHead, useStyle, useTitle, useTitleTemplate };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Arrayable, HeadEntryOptions } from 'unhead';
|
|
2
|
-
import type { Link, Meta, Noscript, ReactiveHead, Script, Style } from '../../types';
|
|
3
|
-
export declare const useServerHead: (input:
|
|
4
|
-
export declare const useHead: (input:
|
|
2
|
+
import type { Link, Meta, Noscript, ReactiveHead, Script, Style, UseHeadInput } from '../../types';
|
|
3
|
+
export declare const useServerHead: (input: UseHeadInput, options?: HeadEntryOptions) => any;
|
|
4
|
+
export declare const useHead: (input: UseHeadInput, options?: HeadEntryOptions) => any;
|
|
5
5
|
export declare const useTitle: (title: ReactiveHead['title']) => any;
|
|
6
6
|
export declare const useTitleTemplate: (titleTemplate: ReactiveHead['titleTemplate']) => any;
|
|
7
7
|
export declare const useMeta: (meta: Arrayable<Meta>) => any;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { HeadEntryOptions } from 'unhead';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function useHead(input:
|
|
2
|
+
import type { UseHeadInput } from '../..';
|
|
3
|
+
export declare function useHead(input: UseHeadInput, options?: HeadEntryOptions): void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { HeadEntryOptions } from 'unhead';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function useServerHead(input:
|
|
2
|
+
import type { UseHeadInput } from '../../types';
|
|
3
|
+
export declare function useServerHead(input: UseHeadInput, options?: HeadEntryOptions): void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { HeadEntryOptions } from 'unhead';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function useHead(input:
|
|
2
|
+
import type { UseHeadInput } from '../../index';
|
|
3
|
+
export declare function useHead(input: UseHeadInput, options?: HeadEntryOptions): void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { HeadEntryOptions } from 'unhead';
|
|
2
|
-
import type {
|
|
3
|
-
export declare function useServerHead(input:
|
|
2
|
+
import type { UseHeadInput } from '../../types';
|
|
3
|
+
export declare function useServerHead(input: UseHeadInput, options?: HeadEntryOptions): void;
|
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.6",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"vue": ">=2.7 || >=3"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unhead/schema": "0.0.
|
|
34
|
+
"@unhead/schema": "0.0.6",
|
|
35
35
|
"@vueuse/shared": "latest",
|
|
36
36
|
"@zhead/schema": "^1.0.0-beta.4",
|
|
37
|
-
"unhead": "0.0.
|
|
37
|
+
"unhead": "0.0.6"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"vue": "latest"
|