@unhead/react 2.0.0-alpha.10
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/LICENSE +21 -0
- package/client.d.ts +1 -0
- package/dist/client.d.mts +14 -0
- package/dist/client.d.ts +14 -0
- package/dist/client.mjs +27 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.mjs +97 -0
- package/dist/server.d.mts +14 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.mjs +23 -0
- package/dist/shared/react.CaAmfJrQ.d.mts +130 -0
- package/dist/shared/react.CaAmfJrQ.d.ts +130 -0
- package/dist/shared/react.DF9T1fqs.mjs +5 -0
- package/dist/types.d.mts +17 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.mjs +1 -0
- package/package.json +79 -0
- package/server.d.ts +1 -0
- package/types.d.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Harlan Wilton <harlan@harlanzw.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/client.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/client'
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import * as unhead_types from 'unhead/types';
|
|
4
|
+
import { MergeHead, CreateClientHeadOptions } from 'unhead/types';
|
|
5
|
+
export { renderDOMHead } from 'unhead/client';
|
|
6
|
+
import { R as ReactUnhead } from './shared/react.CaAmfJrQ.mjs';
|
|
7
|
+
|
|
8
|
+
declare function createHead<T extends MergeHead>(options?: Omit<CreateClientHeadOptions, 'propResolvers'>): ReactUnhead<T>;
|
|
9
|
+
declare function UnheadProvider({ children, head }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
head?: ReturnType<typeof createHead>;
|
|
12
|
+
}): react.FunctionComponentElement<react.ProviderProps<unhead_types.Unhead<any> | null>>;
|
|
13
|
+
|
|
14
|
+
export { UnheadProvider, createHead };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import * as unhead_types from 'unhead/types';
|
|
4
|
+
import { MergeHead, CreateClientHeadOptions } from 'unhead/types';
|
|
5
|
+
export { renderDOMHead } from 'unhead/client';
|
|
6
|
+
import { R as ReactUnhead } from './shared/react.CaAmfJrQ.js';
|
|
7
|
+
|
|
8
|
+
declare function createHead<T extends MergeHead>(options?: Omit<CreateClientHeadOptions, 'propResolvers'>): ReactUnhead<T>;
|
|
9
|
+
declare function UnheadProvider({ children, head }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
head?: ReturnType<typeof createHead>;
|
|
12
|
+
}): react.FunctionComponentElement<react.ProviderProps<unhead_types.Unhead<any> | null>>;
|
|
13
|
+
|
|
14
|
+
export { UnheadProvider, createHead };
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { createHead as createHead$1, createDebouncedFn, renderDOMHead } from 'unhead/client';
|
|
3
|
+
export { renderDOMHead } from 'unhead/client';
|
|
4
|
+
import { U as UnheadContext } from './shared/react.DF9T1fqs.mjs';
|
|
5
|
+
|
|
6
|
+
function createHead(options = {}) {
|
|
7
|
+
const head = createHead$1({
|
|
8
|
+
domOptions: {
|
|
9
|
+
render: createDebouncedFn(() => renderDOMHead(head), (fn) => setTimeout(fn, 0))
|
|
10
|
+
},
|
|
11
|
+
...options,
|
|
12
|
+
propResolvers: [
|
|
13
|
+
(_, r) => {
|
|
14
|
+
if (typeof r === "object" && "current" in r) {
|
|
15
|
+
return r.current;
|
|
16
|
+
}
|
|
17
|
+
return r;
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
return head;
|
|
22
|
+
}
|
|
23
|
+
function UnheadProvider({ children, head }) {
|
|
24
|
+
return createElement(UnheadContext.Provider, { value: head || createHead() }, children);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { UnheadProvider, createHead };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import react__default, { ReactNode } from 'react';
|
|
2
|
+
import * as unhead_types from 'unhead/types';
|
|
3
|
+
import { MergeHead, HeadEntryOptions, ActiveHeadEntry, HeadSafe } from 'unhead/types';
|
|
4
|
+
import { U as UseHeadInput, a as UseSeoMetaInput } from './shared/react.CaAmfJrQ.mjs';
|
|
5
|
+
|
|
6
|
+
declare const hookImports: {
|
|
7
|
+
'@unhead/vue': string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
interface HeadProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
titleTemplate?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const Head: react__default.FC<HeadProps>;
|
|
15
|
+
|
|
16
|
+
declare function useUnhead(): unhead_types.Unhead<any>;
|
|
17
|
+
declare function useHead<T extends MergeHead>(input: UseHeadInput<T>, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput<T>>;
|
|
18
|
+
declare function useHeadSafe(input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
|
|
19
|
+
declare function useSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any>;
|
|
20
|
+
|
|
21
|
+
export { Head, hookImports, useHead, useHeadSafe, useSeoMeta, useUnhead };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import react__default, { ReactNode } from 'react';
|
|
2
|
+
import * as unhead_types from 'unhead/types';
|
|
3
|
+
import { MergeHead, HeadEntryOptions, ActiveHeadEntry, HeadSafe } from 'unhead/types';
|
|
4
|
+
import { U as UseHeadInput, a as UseSeoMetaInput } from './shared/react.CaAmfJrQ.js';
|
|
5
|
+
|
|
6
|
+
declare const hookImports: {
|
|
7
|
+
'@unhead/vue': string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
interface HeadProps {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
titleTemplate?: string;
|
|
13
|
+
}
|
|
14
|
+
declare const Head: react__default.FC<HeadProps>;
|
|
15
|
+
|
|
16
|
+
declare function useUnhead(): unhead_types.Unhead<any>;
|
|
17
|
+
declare function useHead<T extends MergeHead>(input: UseHeadInput<T>, options?: HeadEntryOptions): ActiveHeadEntry<UseHeadInput<T>>;
|
|
18
|
+
declare function useHeadSafe(input: HeadSafe, options?: HeadEntryOptions): ActiveHeadEntry<HeadSafe>;
|
|
19
|
+
declare function useSeoMeta(input: UseSeoMetaInput, options?: HeadEntryOptions): ActiveHeadEntry<any>;
|
|
20
|
+
|
|
21
|
+
export { Head, hookImports, useHead, useHeadSafe, useSeoMeta, useUnhead };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import React, { useContext, useEffect, useRef } from 'react';
|
|
2
|
+
import { ValidHeadTags, TagsWithInnerContent, HasElementTags } from 'unhead/utils';
|
|
3
|
+
import { SafeInputPlugin, FlatMetaPlugin } from 'unhead/plugins';
|
|
4
|
+
import { U as UnheadContext } from './shared/react.DF9T1fqs.mjs';
|
|
5
|
+
|
|
6
|
+
const hookImports = {
|
|
7
|
+
"@unhead/vue": [
|
|
8
|
+
"useUnhead",
|
|
9
|
+
"useHead",
|
|
10
|
+
"useSeoMeta",
|
|
11
|
+
"useHeadSafe",
|
|
12
|
+
"useServerHead",
|
|
13
|
+
"useServerSeoMeta",
|
|
14
|
+
"useServerHeadSafe"
|
|
15
|
+
]
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function useUnhead() {
|
|
19
|
+
const instance = useContext(UnheadContext);
|
|
20
|
+
if (!instance) {
|
|
21
|
+
throw new Error("useHead() was called without provide context.");
|
|
22
|
+
}
|
|
23
|
+
return instance;
|
|
24
|
+
}
|
|
25
|
+
function useHead(input, options = {}) {
|
|
26
|
+
const head = options.head || useUnhead();
|
|
27
|
+
const entry = head.push(input, options);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
entry.patch(input);
|
|
30
|
+
}, [input]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
return () => {
|
|
33
|
+
entry?.dispose();
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
return entry;
|
|
37
|
+
}
|
|
38
|
+
function useHeadSafe(input, options = {}) {
|
|
39
|
+
const head = options.head || useUnhead();
|
|
40
|
+
head.use(SafeInputPlugin);
|
|
41
|
+
options._safe = true;
|
|
42
|
+
return useHead(input, options);
|
|
43
|
+
}
|
|
44
|
+
function useSeoMeta(input, options = {}) {
|
|
45
|
+
const head = options.head || useUnhead();
|
|
46
|
+
head.use(FlatMetaPlugin);
|
|
47
|
+
const { title, titleTemplate, ...meta } = input;
|
|
48
|
+
return useHead({
|
|
49
|
+
title,
|
|
50
|
+
titleTemplate,
|
|
51
|
+
_flatMeta: meta
|
|
52
|
+
}, options);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const Head = ({ children, titleTemplate }) => {
|
|
56
|
+
const headRef = useRef(null);
|
|
57
|
+
const head = useUnhead();
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
return () => {
|
|
60
|
+
if (headRef.current?.dispose()) {
|
|
61
|
+
headRef.current.dispose();
|
|
62
|
+
}
|
|
63
|
+
headRef.current = null;
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const input = {
|
|
68
|
+
titleTemplate
|
|
69
|
+
};
|
|
70
|
+
const elements = React.Children.toArray(children).filter(React.isValidElement);
|
|
71
|
+
elements.forEach((element) => {
|
|
72
|
+
const { type, props } = element;
|
|
73
|
+
if (!ValidHeadTags.has(type)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const data = { ...typeof props === "object" ? props : {} };
|
|
77
|
+
if (TagsWithInnerContent.has(type) && data.children) {
|
|
78
|
+
data[type === "script" ? "innerHTML" : "textContent"] = Array.isArray(data.children) ? data.children.map(String).join("") : data.children;
|
|
79
|
+
}
|
|
80
|
+
delete data.children;
|
|
81
|
+
if (HasElementTags.has(type)) {
|
|
82
|
+
input[type] = input[type] || [];
|
|
83
|
+
input[type].push(data);
|
|
84
|
+
} else {
|
|
85
|
+
input[type] = data;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
if (!headRef.current) {
|
|
89
|
+
headRef.current = head.push(input);
|
|
90
|
+
} else {
|
|
91
|
+
headRef.current.patch(input);
|
|
92
|
+
}
|
|
93
|
+
}, [children, titleTemplate]);
|
|
94
|
+
return null;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export { Head, hookImports, useHead, useHeadSafe, useSeoMeta, useUnhead };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import * as unhead_types from 'unhead/types';
|
|
4
|
+
import { MergeHead, CreateServerHeadOptions } from 'unhead/types';
|
|
5
|
+
export { SSRHeadPayload, extractUnheadInputFromHtml, renderSSRHead, transformHtmlTemplate } from 'unhead/server';
|
|
6
|
+
import { R as ReactUnhead } from './shared/react.CaAmfJrQ.mjs';
|
|
7
|
+
|
|
8
|
+
declare function createHead<T extends MergeHead>(options?: Omit<CreateServerHeadOptions, 'propResolvers'>): ReactUnhead<T>;
|
|
9
|
+
declare function UnheadProvider({ children, value }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
value: ReturnType<typeof createHead>;
|
|
12
|
+
}): react.FunctionComponentElement<react.ProviderProps<unhead_types.Unhead<any> | null>>;
|
|
13
|
+
|
|
14
|
+
export { UnheadProvider, createHead };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import * as unhead_types from 'unhead/types';
|
|
4
|
+
import { MergeHead, CreateServerHeadOptions } from 'unhead/types';
|
|
5
|
+
export { SSRHeadPayload, extractUnheadInputFromHtml, renderSSRHead, transformHtmlTemplate } from 'unhead/server';
|
|
6
|
+
import { R as ReactUnhead } from './shared/react.CaAmfJrQ.js';
|
|
7
|
+
|
|
8
|
+
declare function createHead<T extends MergeHead>(options?: Omit<CreateServerHeadOptions, 'propResolvers'>): ReactUnhead<T>;
|
|
9
|
+
declare function UnheadProvider({ children, value }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
value: ReturnType<typeof createHead>;
|
|
12
|
+
}): react.FunctionComponentElement<react.ProviderProps<unhead_types.Unhead<any> | null>>;
|
|
13
|
+
|
|
14
|
+
export { UnheadProvider, createHead };
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { createHead as createHead$1 } from 'unhead/server';
|
|
3
|
+
export { extractUnheadInputFromHtml, renderSSRHead, transformHtmlTemplate } from 'unhead/server';
|
|
4
|
+
import { U as UnheadContext } from './shared/react.DF9T1fqs.mjs';
|
|
5
|
+
|
|
6
|
+
function createHead(options = {}) {
|
|
7
|
+
return createHead$1({
|
|
8
|
+
...options,
|
|
9
|
+
propResolvers: [
|
|
10
|
+
(_, r) => {
|
|
11
|
+
if (typeof r === "object" && "current" in r) {
|
|
12
|
+
return r.current;
|
|
13
|
+
}
|
|
14
|
+
return r;
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function UnheadProvider({ children, value }) {
|
|
20
|
+
return createElement(UnheadContext.Provider, { value }, children);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { UnheadProvider, createHead };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { Falsey, BaseHtmlAttr, MaybeArray, BaseBodyAttr, ResolvableValues, SchemaAugmentations, TitleTemplate as TitleTemplate$1, EntryAugmentation, Base as Base$1, DefinedValueOrEmptyObject, LinkBase, DataKeys, MaybeEventFnHandlers, HttpEventAttributes, BaseMeta, Style as Style$1, ScriptBase, Noscript as Noscript$1, BodyEvents, MergeHead, MetaFlatInput, HeadEntryOptions, Unhead } from 'unhead/types';
|
|
3
|
+
|
|
4
|
+
type MaybeComputedRef<T> = T | (() => T) | RefObject<T>;
|
|
5
|
+
type ResolvableArray<T> = MaybeComputedRef<MaybeComputedRef<T>[]>;
|
|
6
|
+
type ResolvableProperties<T> = {
|
|
7
|
+
[key in keyof T]?: MaybeComputedRef<T[key] | Falsey>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
interface HtmlAttr extends Omit<BaseHtmlAttr, 'class'> {
|
|
11
|
+
/**
|
|
12
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
13
|
+
*
|
|
14
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
15
|
+
*/
|
|
16
|
+
class?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<boolean>>;
|
|
17
|
+
}
|
|
18
|
+
interface BodyAttr extends Omit<BaseBodyAttr, 'class' | 'style'> {
|
|
19
|
+
/**
|
|
20
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
21
|
+
*
|
|
22
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
23
|
+
*/
|
|
24
|
+
class?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<boolean>>;
|
|
25
|
+
/**
|
|
26
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
27
|
+
*
|
|
28
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
29
|
+
*/
|
|
30
|
+
style?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<string | boolean>>;
|
|
31
|
+
}
|
|
32
|
+
type Title = MaybeComputedRef<number | string | Falsey> | ResolvableValues<({
|
|
33
|
+
textContent: string;
|
|
34
|
+
} & SchemaAugmentations['title'])>;
|
|
35
|
+
type TitleTemplate = TitleTemplate$1 | RefObject<TitleTemplate$1> | ((title?: string) => TitleTemplate$1);
|
|
36
|
+
type Base<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<Base$1 & SchemaAugmentations['base']> & DefinedValueOrEmptyObject<E>;
|
|
37
|
+
type Link<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<LinkBase & DataKeys & SchemaAugmentations['link']> & MaybeEventFnHandlers<HttpEventAttributes> & DefinedValueOrEmptyObject<E>;
|
|
38
|
+
type Meta<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<BaseMeta & DataKeys & SchemaAugmentations['meta']> & DefinedValueOrEmptyObject<E>;
|
|
39
|
+
type Style<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<Style$1 & DataKeys & SchemaAugmentations['style']> & DefinedValueOrEmptyObject<E>;
|
|
40
|
+
type Script<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<ScriptBase & DataKeys & SchemaAugmentations['script']> & MaybeEventFnHandlers<HttpEventAttributes> & DefinedValueOrEmptyObject<E>;
|
|
41
|
+
type Noscript<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<Noscript$1 & DataKeys & SchemaAugmentations['noscript']> & DefinedValueOrEmptyObject<E>;
|
|
42
|
+
type HtmlAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<HtmlAttr & DataKeys & SchemaAugmentations['htmlAttrs']> & DefinedValueOrEmptyObject<E>;
|
|
43
|
+
type BodyAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<BodyAttr & DataKeys & SchemaAugmentations['bodyAttrs']> & MaybeEventFnHandlers<BodyEvents> & DefinedValueOrEmptyObject<E>;
|
|
44
|
+
interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
45
|
+
/**
|
|
46
|
+
* The `<title>` HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
|
|
47
|
+
* It only contains text; tags within the element are ignored.
|
|
48
|
+
*
|
|
49
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
|
|
50
|
+
*/
|
|
51
|
+
title?: Title;
|
|
52
|
+
/**
|
|
53
|
+
* Generate the title from a template.
|
|
54
|
+
*/
|
|
55
|
+
titleTemplate?: TitleTemplate;
|
|
56
|
+
/**
|
|
57
|
+
* Variables used to substitute in the title and meta content.
|
|
58
|
+
*/
|
|
59
|
+
templateParams?: ResolvableArray<{
|
|
60
|
+
separator?: '|' | '-' | '·' | string;
|
|
61
|
+
} & Record<string, null | string | ResolvableArray<Record<string, null | string>>>>;
|
|
62
|
+
/**
|
|
63
|
+
* The `<base>` HTML element specifies the base URL to use for all relative URLs in a document.
|
|
64
|
+
* There can be only one <base> element in a document.
|
|
65
|
+
*
|
|
66
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
|
67
|
+
*/
|
|
68
|
+
base?: Base<E['base']>;
|
|
69
|
+
/**
|
|
70
|
+
* The `<link>` HTML element specifies relationships between the current document and an external resource.
|
|
71
|
+
* This element is most commonly used to link to stylesheets, but is also used to establish site icons
|
|
72
|
+
* (both "favicon" style icons and icons for the home screen and apps on mobile devices) among other things.
|
|
73
|
+
*
|
|
74
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as
|
|
75
|
+
*/
|
|
76
|
+
link?: ResolvableArray<Link<E['link']>>;
|
|
77
|
+
/**
|
|
78
|
+
* The `<meta>` element represents metadata that cannot be expressed in other HTML elements, like `<link>` or `<script>`.
|
|
79
|
+
*
|
|
80
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
|
|
81
|
+
*/
|
|
82
|
+
meta?: ResolvableArray<Meta<E['meta']>>;
|
|
83
|
+
/**
|
|
84
|
+
* The `<style>` HTML element contains style information for a document, or part of a document.
|
|
85
|
+
* It contains CSS, which is applied to the contents of the document containing the `<style>` element.
|
|
86
|
+
*
|
|
87
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
|
|
88
|
+
*/
|
|
89
|
+
style?: ResolvableArray<(Style<E['style']> | string)>;
|
|
90
|
+
/**
|
|
91
|
+
* The `<script>` HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code.
|
|
92
|
+
*
|
|
93
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
|
|
94
|
+
*/
|
|
95
|
+
script?: ResolvableArray<(Script<E['script']> | string)>;
|
|
96
|
+
/**
|
|
97
|
+
* The `<noscript>` HTML element defines a section of HTML to be inserted if a script type on the page is unsupported
|
|
98
|
+
* or if scripting is currently turned off in the browser.
|
|
99
|
+
*
|
|
100
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript
|
|
101
|
+
*/
|
|
102
|
+
noscript?: ResolvableArray<(Noscript<E['noscript']> | string)>;
|
|
103
|
+
/**
|
|
104
|
+
* Attributes for the `<html>` HTML element.
|
|
105
|
+
*
|
|
106
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html
|
|
107
|
+
*/
|
|
108
|
+
htmlAttrs?: HtmlAttributes<E['htmlAttrs']>;
|
|
109
|
+
/**
|
|
110
|
+
* Attributes for the `<body>` HTML element.
|
|
111
|
+
*
|
|
112
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body
|
|
113
|
+
*/
|
|
114
|
+
bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
|
|
115
|
+
/**
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
_flatMeta?: ResolvableProperties<MetaFlatInput>;
|
|
119
|
+
}
|
|
120
|
+
type UseHeadOptions = Omit<HeadEntryOptions, 'head'> & {
|
|
121
|
+
head?: ReactUnhead<any>;
|
|
122
|
+
};
|
|
123
|
+
type UseHeadInput<T extends MergeHead = Record<string, any>> = MaybeComputedRef<ReactiveHead<T>>;
|
|
124
|
+
type UseSeoMetaInput = ResolvableProperties<MetaFlatInput> & {
|
|
125
|
+
title?: ReactiveHead['title'];
|
|
126
|
+
titleTemplate?: ReactiveHead['titleTemplate'];
|
|
127
|
+
};
|
|
128
|
+
type ReactUnhead<T extends MergeHead> = Unhead<MaybeComputedRef<ReactiveHead<T>>>;
|
|
129
|
+
|
|
130
|
+
export type { BodyAttr as B, HtmlAttr as H, Link as L, MaybeComputedRef as M, Noscript as N, ReactUnhead as R, Style as S, Title as T, UseHeadInput as U, UseSeoMetaInput as a, ReactiveHead as b, ResolvableArray as c, TitleTemplate as d, Base as e, Meta as f, Script as g, HtmlAttributes as h, BodyAttributes as i, UseHeadOptions as j, ResolvableProperties as k };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
import { Falsey, BaseHtmlAttr, MaybeArray, BaseBodyAttr, ResolvableValues, SchemaAugmentations, TitleTemplate as TitleTemplate$1, EntryAugmentation, Base as Base$1, DefinedValueOrEmptyObject, LinkBase, DataKeys, MaybeEventFnHandlers, HttpEventAttributes, BaseMeta, Style as Style$1, ScriptBase, Noscript as Noscript$1, BodyEvents, MergeHead, MetaFlatInput, HeadEntryOptions, Unhead } from 'unhead/types';
|
|
3
|
+
|
|
4
|
+
type MaybeComputedRef<T> = T | (() => T) | RefObject<T>;
|
|
5
|
+
type ResolvableArray<T> = MaybeComputedRef<MaybeComputedRef<T>[]>;
|
|
6
|
+
type ResolvableProperties<T> = {
|
|
7
|
+
[key in keyof T]?: MaybeComputedRef<T[key] | Falsey>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
interface HtmlAttr extends Omit<BaseHtmlAttr, 'class'> {
|
|
11
|
+
/**
|
|
12
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
13
|
+
*
|
|
14
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
15
|
+
*/
|
|
16
|
+
class?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<boolean>>;
|
|
17
|
+
}
|
|
18
|
+
interface BodyAttr extends Omit<BaseBodyAttr, 'class' | 'style'> {
|
|
19
|
+
/**
|
|
20
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
21
|
+
*
|
|
22
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
23
|
+
*/
|
|
24
|
+
class?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<boolean>>;
|
|
25
|
+
/**
|
|
26
|
+
* The class global attribute is a space-separated list of the case-sensitive classes of the element.
|
|
27
|
+
*
|
|
28
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/class
|
|
29
|
+
*/
|
|
30
|
+
style?: MaybeArray<MaybeComputedRef<string>> | Record<string, MaybeComputedRef<string | boolean>>;
|
|
31
|
+
}
|
|
32
|
+
type Title = MaybeComputedRef<number | string | Falsey> | ResolvableValues<({
|
|
33
|
+
textContent: string;
|
|
34
|
+
} & SchemaAugmentations['title'])>;
|
|
35
|
+
type TitleTemplate = TitleTemplate$1 | RefObject<TitleTemplate$1> | ((title?: string) => TitleTemplate$1);
|
|
36
|
+
type Base<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<Base$1 & SchemaAugmentations['base']> & DefinedValueOrEmptyObject<E>;
|
|
37
|
+
type Link<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<LinkBase & DataKeys & SchemaAugmentations['link']> & MaybeEventFnHandlers<HttpEventAttributes> & DefinedValueOrEmptyObject<E>;
|
|
38
|
+
type Meta<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<BaseMeta & DataKeys & SchemaAugmentations['meta']> & DefinedValueOrEmptyObject<E>;
|
|
39
|
+
type Style<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<Style$1 & DataKeys & SchemaAugmentations['style']> & DefinedValueOrEmptyObject<E>;
|
|
40
|
+
type Script<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<ScriptBase & DataKeys & SchemaAugmentations['script']> & MaybeEventFnHandlers<HttpEventAttributes> & DefinedValueOrEmptyObject<E>;
|
|
41
|
+
type Noscript<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<Noscript$1 & DataKeys & SchemaAugmentations['noscript']> & DefinedValueOrEmptyObject<E>;
|
|
42
|
+
type HtmlAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<HtmlAttr & DataKeys & SchemaAugmentations['htmlAttrs']> & DefinedValueOrEmptyObject<E>;
|
|
43
|
+
type BodyAttributes<E extends EntryAugmentation = Record<string, any>> = ResolvableProperties<BodyAttr & DataKeys & SchemaAugmentations['bodyAttrs']> & MaybeEventFnHandlers<BodyEvents> & DefinedValueOrEmptyObject<E>;
|
|
44
|
+
interface ReactiveHead<E extends MergeHead = MergeHead> {
|
|
45
|
+
/**
|
|
46
|
+
* The `<title>` HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
|
|
47
|
+
* It only contains text; tags within the element are ignored.
|
|
48
|
+
*
|
|
49
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
|
|
50
|
+
*/
|
|
51
|
+
title?: Title;
|
|
52
|
+
/**
|
|
53
|
+
* Generate the title from a template.
|
|
54
|
+
*/
|
|
55
|
+
titleTemplate?: TitleTemplate;
|
|
56
|
+
/**
|
|
57
|
+
* Variables used to substitute in the title and meta content.
|
|
58
|
+
*/
|
|
59
|
+
templateParams?: ResolvableArray<{
|
|
60
|
+
separator?: '|' | '-' | '·' | string;
|
|
61
|
+
} & Record<string, null | string | ResolvableArray<Record<string, null | string>>>>;
|
|
62
|
+
/**
|
|
63
|
+
* The `<base>` HTML element specifies the base URL to use for all relative URLs in a document.
|
|
64
|
+
* There can be only one <base> element in a document.
|
|
65
|
+
*
|
|
66
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
|
|
67
|
+
*/
|
|
68
|
+
base?: Base<E['base']>;
|
|
69
|
+
/**
|
|
70
|
+
* The `<link>` HTML element specifies relationships between the current document and an external resource.
|
|
71
|
+
* This element is most commonly used to link to stylesheets, but is also used to establish site icons
|
|
72
|
+
* (both "favicon" style icons and icons for the home screen and apps on mobile devices) among other things.
|
|
73
|
+
*
|
|
74
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as
|
|
75
|
+
*/
|
|
76
|
+
link?: ResolvableArray<Link<E['link']>>;
|
|
77
|
+
/**
|
|
78
|
+
* The `<meta>` element represents metadata that cannot be expressed in other HTML elements, like `<link>` or `<script>`.
|
|
79
|
+
*
|
|
80
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
|
|
81
|
+
*/
|
|
82
|
+
meta?: ResolvableArray<Meta<E['meta']>>;
|
|
83
|
+
/**
|
|
84
|
+
* The `<style>` HTML element contains style information for a document, or part of a document.
|
|
85
|
+
* It contains CSS, which is applied to the contents of the document containing the `<style>` element.
|
|
86
|
+
*
|
|
87
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
|
|
88
|
+
*/
|
|
89
|
+
style?: ResolvableArray<(Style<E['style']> | string)>;
|
|
90
|
+
/**
|
|
91
|
+
* The `<script>` HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code.
|
|
92
|
+
*
|
|
93
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
|
|
94
|
+
*/
|
|
95
|
+
script?: ResolvableArray<(Script<E['script']> | string)>;
|
|
96
|
+
/**
|
|
97
|
+
* The `<noscript>` HTML element defines a section of HTML to be inserted if a script type on the page is unsupported
|
|
98
|
+
* or if scripting is currently turned off in the browser.
|
|
99
|
+
*
|
|
100
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript
|
|
101
|
+
*/
|
|
102
|
+
noscript?: ResolvableArray<(Noscript<E['noscript']> | string)>;
|
|
103
|
+
/**
|
|
104
|
+
* Attributes for the `<html>` HTML element.
|
|
105
|
+
*
|
|
106
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html
|
|
107
|
+
*/
|
|
108
|
+
htmlAttrs?: HtmlAttributes<E['htmlAttrs']>;
|
|
109
|
+
/**
|
|
110
|
+
* Attributes for the `<body>` HTML element.
|
|
111
|
+
*
|
|
112
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body
|
|
113
|
+
*/
|
|
114
|
+
bodyAttrs?: BodyAttributes<E['bodyAttrs']>;
|
|
115
|
+
/**
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
_flatMeta?: ResolvableProperties<MetaFlatInput>;
|
|
119
|
+
}
|
|
120
|
+
type UseHeadOptions = Omit<HeadEntryOptions, 'head'> & {
|
|
121
|
+
head?: ReactUnhead<any>;
|
|
122
|
+
};
|
|
123
|
+
type UseHeadInput<T extends MergeHead = Record<string, any>> = MaybeComputedRef<ReactiveHead<T>>;
|
|
124
|
+
type UseSeoMetaInput = ResolvableProperties<MetaFlatInput> & {
|
|
125
|
+
title?: ReactiveHead['title'];
|
|
126
|
+
titleTemplate?: ReactiveHead['titleTemplate'];
|
|
127
|
+
};
|
|
128
|
+
type ReactUnhead<T extends MergeHead> = Unhead<MaybeComputedRef<ReactiveHead<T>>>;
|
|
129
|
+
|
|
130
|
+
export type { BodyAttr as B, HtmlAttr as H, Link as L, MaybeComputedRef as M, Noscript as N, ReactUnhead as R, Style as S, Title as T, UseHeadInput as U, UseSeoMetaInput as a, ReactiveHead as b, ResolvableArray as c, TitleTemplate as d, Base as e, Meta as f, Script as g, HtmlAttributes as h, BodyAttributes as i, UseHeadOptions as j, ResolvableProperties as k };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SafeMeta, SafeLink, SafeNoscript, SafeScript, SafeHtmlAttr, SafeBodyAttr } from 'unhead/types';
|
|
2
|
+
export { ActiveHeadEntry, Head, HeadEntryOptions, HeadTag, MergeHead, ResolvedHead, Unhead } from 'unhead/types';
|
|
3
|
+
import { b as ReactiveHead, c as ResolvableArray, M as MaybeComputedRef } from './shared/react.CaAmfJrQ.mjs';
|
|
4
|
+
export { e as Base, B as BodyAttr, i as BodyAttributes, H as HtmlAttr, h as HtmlAttributes, L as Link, f as Meta, N as Noscript, R as ReactUnhead, k as ResolvableProperties, g as Script, S as Style, T as Title, d as TitleTemplate, U as UseHeadInput, j as UseHeadOptions, a as UseSeoMetaInput } from './shared/react.CaAmfJrQ.mjs';
|
|
5
|
+
import 'react';
|
|
6
|
+
|
|
7
|
+
interface HeadSafe extends Pick<ReactiveHead, 'title' | 'titleTemplate' | 'templateParams'> {
|
|
8
|
+
meta?: ResolvableArray<SafeMeta>[];
|
|
9
|
+
link?: ResolvableArray<SafeLink>[];
|
|
10
|
+
noscript?: ResolvableArray<SafeNoscript>[];
|
|
11
|
+
script?: ResolvableArray<SafeScript>[];
|
|
12
|
+
htmlAttrs?: ResolvableArray<SafeHtmlAttr>;
|
|
13
|
+
bodyAttrs?: ResolvableArray<SafeBodyAttr>;
|
|
14
|
+
}
|
|
15
|
+
type UseHeadSafeInput = MaybeComputedRef<HeadSafe>;
|
|
16
|
+
|
|
17
|
+
export { type HeadSafe, MaybeComputedRef, ReactiveHead, ResolvableArray, type UseHeadSafeInput };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SafeMeta, SafeLink, SafeNoscript, SafeScript, SafeHtmlAttr, SafeBodyAttr } from 'unhead/types';
|
|
2
|
+
export { ActiveHeadEntry, Head, HeadEntryOptions, HeadTag, MergeHead, ResolvedHead, Unhead } from 'unhead/types';
|
|
3
|
+
import { b as ReactiveHead, c as ResolvableArray, M as MaybeComputedRef } from './shared/react.CaAmfJrQ.js';
|
|
4
|
+
export { e as Base, B as BodyAttr, i as BodyAttributes, H as HtmlAttr, h as HtmlAttributes, L as Link, f as Meta, N as Noscript, R as ReactUnhead, k as ResolvableProperties, g as Script, S as Style, T as Title, d as TitleTemplate, U as UseHeadInput, j as UseHeadOptions, a as UseSeoMetaInput } from './shared/react.CaAmfJrQ.js';
|
|
5
|
+
import 'react';
|
|
6
|
+
|
|
7
|
+
interface HeadSafe extends Pick<ReactiveHead, 'title' | 'titleTemplate' | 'templateParams'> {
|
|
8
|
+
meta?: ResolvableArray<SafeMeta>[];
|
|
9
|
+
link?: ResolvableArray<SafeLink>[];
|
|
10
|
+
noscript?: ResolvableArray<SafeNoscript>[];
|
|
11
|
+
script?: ResolvableArray<SafeScript>[];
|
|
12
|
+
htmlAttrs?: ResolvableArray<SafeHtmlAttr>;
|
|
13
|
+
bodyAttrs?: ResolvableArray<SafeBodyAttr>;
|
|
14
|
+
}
|
|
15
|
+
type UseHeadSafeInput = MaybeComputedRef<HeadSafe>;
|
|
16
|
+
|
|
17
|
+
export { type HeadSafe, MaybeComputedRef, ReactiveHead, ResolvableArray, type UseHeadSafeInput };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@unhead/react",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "2.0.0-alpha.10",
|
|
5
|
+
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"funding": "https://github.com/sponsors/harlan-zw",
|
|
8
|
+
"homepage": "https://unhead.unjs.io",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/unjs/unhead.git",
|
|
12
|
+
"directory": "packages/react"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/unjs/unhead/issues"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./server": {
|
|
24
|
+
"types": "./dist/server.d.ts",
|
|
25
|
+
"import": "./dist/server.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./client": {
|
|
28
|
+
"types": "./dist/client.d.ts",
|
|
29
|
+
"import": "./dist/client.mjs"
|
|
30
|
+
},
|
|
31
|
+
"./types": {
|
|
32
|
+
"types": "./dist/types.d.ts",
|
|
33
|
+
"import": "./dist/types.mjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"main": "dist/index.mjs",
|
|
37
|
+
"module": "dist/index.mjs",
|
|
38
|
+
"types": "dist/index.d.ts",
|
|
39
|
+
"typesVersions": {
|
|
40
|
+
"*": {
|
|
41
|
+
"server": [
|
|
42
|
+
"dist/server"
|
|
43
|
+
],
|
|
44
|
+
"client": [
|
|
45
|
+
"dist/client"
|
|
46
|
+
],
|
|
47
|
+
"types": [
|
|
48
|
+
"dist/types"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"client.d.ts",
|
|
54
|
+
"dist",
|
|
55
|
+
"server.d.ts",
|
|
56
|
+
"types.d.ts"
|
|
57
|
+
],
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"react": ">=19"
|
|
60
|
+
},
|
|
61
|
+
"build": {
|
|
62
|
+
"external": [
|
|
63
|
+
"react"
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"unhead": "2.0.0-alpha.10"
|
|
68
|
+
},
|
|
69
|
+
"devDependencies": {
|
|
70
|
+
"@testing-library/react": "^16.2.0",
|
|
71
|
+
"react": "^19.0.0",
|
|
72
|
+
"react-dom": "^19.0.0"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"build": "unbuild .",
|
|
76
|
+
"stub": "unbuild . --stub",
|
|
77
|
+
"export:sizes": "npx export-size . -r"
|
|
78
|
+
}
|
|
79
|
+
}
|
package/server.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/server'
|
package/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/types'
|