@pyreon/head 0.11.5 → 0.11.7
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/README.md +6 -8
- package/lib/index.js.map +1 -1
- package/lib/provider.js.map +1 -1
- package/lib/ssr.js.map +1 -1
- package/lib/types/index.d.ts +4 -4
- package/lib/types/provider.d.ts +1 -1
- package/lib/types/use-head.d.ts +3 -3
- package/lib/use-head.js.map +1 -1
- package/package.json +18 -18
- package/src/context.ts +5 -5
- package/src/dom.ts +7 -7
- package/src/index.ts +5 -5
- package/src/provider.ts +5 -5
- package/src/ssr.ts +15 -15
- package/src/tests/head.test.ts +447 -445
- package/src/tests/setup.ts +1 -1
- package/src/use-head.ts +19 -19
package/src/tests/setup.ts
CHANGED
package/src/use-head.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { onMount, onUnmount, useContext } from
|
|
2
|
-
import { effect } from
|
|
3
|
-
import type { HeadEntry, HeadTag, UseHeadInput } from
|
|
4
|
-
import { HeadContext } from
|
|
5
|
-
import { syncDom } from
|
|
1
|
+
import { onMount, onUnmount, useContext } from '@pyreon/core'
|
|
2
|
+
import { effect } from '@pyreon/reactivity'
|
|
3
|
+
import type { HeadEntry, HeadTag, UseHeadInput } from './context'
|
|
4
|
+
import { HeadContext } from './context'
|
|
5
|
+
import { syncDom } from './dom'
|
|
6
6
|
|
|
7
7
|
/** Cast a strict tag interface to the internal props format, stripping undefined values */
|
|
8
8
|
function toProps(obj: Record<string, string | undefined>): Record<string, string> {
|
|
@@ -15,25 +15,25 @@ function toProps(obj: Record<string, string | undefined>): Record<string, string
|
|
|
15
15
|
|
|
16
16
|
function buildEntry(o: UseHeadInput): HeadEntry {
|
|
17
17
|
const tags: HeadTag[] = []
|
|
18
|
-
if (o.title != null) tags.push({ tag:
|
|
18
|
+
if (o.title != null) tags.push({ tag: 'title', key: 'title', children: o.title })
|
|
19
19
|
o.meta?.forEach((m, i) => {
|
|
20
20
|
tags.push({
|
|
21
|
-
tag:
|
|
21
|
+
tag: 'meta',
|
|
22
22
|
key: m.name ?? m.property ?? `meta-${i}`,
|
|
23
23
|
props: toProps(m as Record<string, string | undefined>),
|
|
24
24
|
})
|
|
25
25
|
})
|
|
26
26
|
o.link?.forEach((l, i) => {
|
|
27
27
|
tags.push({
|
|
28
|
-
tag:
|
|
29
|
-
key: l.href ? `link-${l.rel ||
|
|
28
|
+
tag: 'link',
|
|
29
|
+
key: l.href ? `link-${l.rel || ''}-${l.href}` : l.rel ? `link-${l.rel}` : `link-${i}`,
|
|
30
30
|
props: toProps(l as Record<string, string | undefined>),
|
|
31
31
|
})
|
|
32
32
|
})
|
|
33
33
|
o.script?.forEach((s, i) => {
|
|
34
34
|
const { children, ...rest } = s
|
|
35
35
|
tags.push({
|
|
36
|
-
tag:
|
|
36
|
+
tag: 'script',
|
|
37
37
|
key: s.src ?? `script-${i}`,
|
|
38
38
|
props: toProps(rest as Record<string, string | undefined>),
|
|
39
39
|
...(children != null ? { children } : {}),
|
|
@@ -42,27 +42,27 @@ function buildEntry(o: UseHeadInput): HeadEntry {
|
|
|
42
42
|
o.style?.forEach((s, i) => {
|
|
43
43
|
const { children, ...rest } = s
|
|
44
44
|
tags.push({
|
|
45
|
-
tag:
|
|
45
|
+
tag: 'style',
|
|
46
46
|
key: `style-${i}`,
|
|
47
47
|
props: toProps(rest as Record<string, string | undefined>),
|
|
48
48
|
children,
|
|
49
49
|
})
|
|
50
50
|
})
|
|
51
51
|
o.noscript?.forEach((ns, i) => {
|
|
52
|
-
tags.push({ tag:
|
|
52
|
+
tags.push({ tag: 'noscript', key: `noscript-${i}`, children: ns.children })
|
|
53
53
|
})
|
|
54
54
|
if (o.jsonLd) {
|
|
55
55
|
tags.push({
|
|
56
|
-
tag:
|
|
57
|
-
key:
|
|
58
|
-
props: { type:
|
|
56
|
+
tag: 'script',
|
|
57
|
+
key: 'jsonld',
|
|
58
|
+
props: { type: 'application/ld+json' },
|
|
59
59
|
children: JSON.stringify(o.jsonLd),
|
|
60
60
|
})
|
|
61
61
|
}
|
|
62
62
|
if (o.base)
|
|
63
63
|
tags.push({
|
|
64
|
-
tag:
|
|
65
|
-
key:
|
|
64
|
+
tag: 'base',
|
|
65
|
+
key: 'base',
|
|
66
66
|
props: toProps(o.base as Record<string, string | undefined>),
|
|
67
67
|
})
|
|
68
68
|
return {
|
|
@@ -90,8 +90,8 @@ export function useHead(input: UseHeadInput | (() => UseHeadInput)): void {
|
|
|
90
90
|
|
|
91
91
|
const id = Symbol()
|
|
92
92
|
|
|
93
|
-
if (typeof input ===
|
|
94
|
-
if (typeof document !==
|
|
93
|
+
if (typeof input === 'function') {
|
|
94
|
+
if (typeof document !== 'undefined') {
|
|
95
95
|
// CSR: reactive — re-register whenever signals change
|
|
96
96
|
effect(() => {
|
|
97
97
|
ctx.add(id, buildEntry(input()))
|