@unhead/vue 0.0.5 → 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 +9 -5
- package/dist/index.mjs +67 -9
- 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
|
@@ -5,6 +5,7 @@ export { HeadTag, MergeHead } from '@unhead/schema';
|
|
|
5
5
|
import { DataKeys, DefinedValueOrEmptyObject } from '@zhead/schema';
|
|
6
6
|
import * as unhead from 'unhead';
|
|
7
7
|
import { HeadEntryOptions, Arrayable, HeadClient, CreateHeadOptions } from 'unhead';
|
|
8
|
+
import * as vue from 'vue';
|
|
8
9
|
import { Plugin, InjectionKey } from 'vue';
|
|
9
10
|
export { debouncedRenderDOMHead, renderDOMHead } from 'unhead/client';
|
|
10
11
|
export { renderSSRHead } from 'unhead/server';
|
|
@@ -105,13 +106,14 @@ interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
|
105
106
|
*/
|
|
106
107
|
bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
|
|
107
108
|
}
|
|
109
|
+
declare type UseHeadInput = MaybeComputedRef<ReactiveHead>;
|
|
108
110
|
|
|
109
111
|
declare function resolveUnrefHeadInput(ref: any): any;
|
|
110
112
|
|
|
111
113
|
declare const VueReactiveInputPlugin: unhead.HeadPlugin<_unhead_schema.Head<_unhead_schema.SchemaAugmentations>>;
|
|
112
114
|
|
|
113
115
|
declare function useServerHead(input: ReactiveHead, options?: HeadEntryOptions): void;
|
|
114
|
-
declare function useHead(input:
|
|
116
|
+
declare function useHead(input: UseHeadInput, options?: HeadEntryOptions): void;
|
|
115
117
|
declare const useTitle: (title: ReactiveHead['title']) => void;
|
|
116
118
|
declare const useTitleTemplate: (titleTemplate: ReactiveHead['titleTemplate']) => void;
|
|
117
119
|
declare const useMeta: (meta: Arrayable<Meta>) => void;
|
|
@@ -123,12 +125,14 @@ declare const useBase: (base: ReactiveHead['base']) => void;
|
|
|
123
125
|
declare const useHtmlAttrs: (attrs: ReactiveHead['htmlAttrs']) => void;
|
|
124
126
|
declare const useBodyAttrs: (attrs: ReactiveHead['bodyAttrs']) => void;
|
|
125
127
|
|
|
126
|
-
declare
|
|
127
|
-
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;
|
|
128
132
|
declare const headSymbol: InjectionKey<VueHeadClient>;
|
|
129
133
|
declare function injectHead(): VueHeadClient;
|
|
130
|
-
declare function createHead<T>(options
|
|
134
|
+
declare function createHead<T>(options?: CreateHeadOptions<T>): VueHeadClient;
|
|
131
135
|
|
|
132
136
|
declare const HeadVuePlugin: Plugin;
|
|
133
137
|
|
|
134
|
-
export { Base, BodyAttributes, HeadVuePlugin, 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,5 +1,5 @@
|
|
|
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
5
|
export { debouncedRenderDOMHead, renderDOMHead } from 'unhead/client';
|
|
@@ -33,7 +33,9 @@ const VueReactiveInputPlugin = defineHeadPlugin({
|
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const Vue3 = version.startsWith("3");
|
|
37
|
+
const Vue2 = version.startsWith("2.");
|
|
38
|
+
const IsClient = typeof window !== "undefined";
|
|
37
39
|
|
|
38
40
|
function useHead$2(input, options = {}) {
|
|
39
41
|
const head = injectHead();
|
|
@@ -70,13 +72,13 @@ function useHead$1(input, options = {}) {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
function useServerHead(input, options = {}) {
|
|
73
|
-
if (!
|
|
75
|
+
if (!IsClient)
|
|
74
76
|
useServerHead$1(input, options);
|
|
75
77
|
}
|
|
76
78
|
function useHead(input, options = {}) {
|
|
77
|
-
if (options.mode === "server" &&
|
|
79
|
+
if (options.mode === "server" && IsClient || options.mode === "client" && !IsClient)
|
|
78
80
|
return;
|
|
79
|
-
return
|
|
81
|
+
return IsClient ? useHead$1(input, options) : useHead$2(input, options);
|
|
80
82
|
}
|
|
81
83
|
const useTitle = (title) => useHead({ title });
|
|
82
84
|
const useTitleTemplate = (titleTemplate) => useHead({ titleTemplate });
|
|
@@ -89,18 +91,74 @@ const useBase = (base) => useHead({ base });
|
|
|
89
91
|
const useHtmlAttrs = (attrs) => useHead({ htmlAttrs: attrs });
|
|
90
92
|
const useBodyAttrs = (attrs) => useHead({ bodyAttrs: attrs });
|
|
91
93
|
|
|
92
|
-
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
|
+
|
|
93
151
|
const headSymbol = Symbol("head");
|
|
94
152
|
function injectHead() {
|
|
95
153
|
return getCurrentInstance() && inject(headSymbol) || getActiveHead();
|
|
96
154
|
}
|
|
97
|
-
function createHead(options) {
|
|
155
|
+
function createHead(options = {}) {
|
|
98
156
|
const head = createHead$1({
|
|
99
157
|
...options,
|
|
100
158
|
plugins: [
|
|
101
159
|
HydratesStatePlugin,
|
|
102
160
|
VueReactiveInputPlugin,
|
|
103
|
-
...options
|
|
161
|
+
...options?.plugins || []
|
|
104
162
|
]
|
|
105
163
|
});
|
|
106
164
|
const vuePlugin = {
|
|
@@ -151,4 +209,4 @@ const HeadVuePlugin = function(_Vue) {
|
|
|
151
209
|
});
|
|
152
210
|
};
|
|
153
211
|
|
|
154
|
-
export {
|
|
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"
|