unhead 0.6.5 → 0.6.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.cjs +38 -16
- package/dist/index.d.ts +13 -3
- package/dist/index.mjs +35 -17
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -490,10 +490,12 @@ const EventHandlersPlugin = () => {
|
|
|
490
490
|
const handler = value;
|
|
491
491
|
$el.setAttribute(eventDedupeKey, "");
|
|
492
492
|
$eventListenerTarget.addEventListener(eventName, handler);
|
|
493
|
-
ctx.entry
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
493
|
+
if (ctx.entry) {
|
|
494
|
+
ctx.entry._sde[sdeKey] = () => {
|
|
495
|
+
$eventListenerTarget.removeEventListener(eventName, handler);
|
|
496
|
+
$el.removeAttribute(eventDedupeKey);
|
|
497
|
+
};
|
|
498
|
+
}
|
|
497
499
|
});
|
|
498
500
|
if (ctx.tag._delayedSrc) {
|
|
499
501
|
$el.setAttribute("src", ctx.tag._delayedSrc);
|
|
@@ -527,15 +529,18 @@ const getActiveHead = () => exports.activeHead;
|
|
|
527
529
|
|
|
528
530
|
function useHead(input, options = {}) {
|
|
529
531
|
const head = getActiveHead();
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
532
|
+
if (head) {
|
|
533
|
+
const isBrowser = IsBrowser || head.resolvedOptions?.document;
|
|
534
|
+
if (options.mode === "server" && isBrowser || options.mode === "client" && !isBrowser)
|
|
535
|
+
return;
|
|
536
|
+
return head.push(input, options);
|
|
537
|
+
}
|
|
534
538
|
}
|
|
535
539
|
const useTagTitle = (title) => useHead({ title });
|
|
536
540
|
const useTagBase = (base) => useHead({ base });
|
|
537
541
|
const useTagMeta = (meta) => useHead({ meta: asArray(meta) });
|
|
538
542
|
const useTagMetaFlat = (meta) => useTagMeta(unpackMeta(meta));
|
|
543
|
+
const useSeoMeta = useTagMetaFlat;
|
|
539
544
|
const useTagLink = (link) => useHead({ link: asArray(link) });
|
|
540
545
|
const useTagScript = (script) => useHead({ script: asArray(script) });
|
|
541
546
|
const useTagStyle = (style) => useHead({ style: asArray(style) });
|
|
@@ -571,7 +576,26 @@ function normaliseEntryTags(e) {
|
|
|
571
576
|
});
|
|
572
577
|
}
|
|
573
578
|
|
|
579
|
+
const CorePlugins = () => [
|
|
580
|
+
DedupesTagsPlugin(),
|
|
581
|
+
SortTagsPlugin(),
|
|
582
|
+
TitleTemplatePlugin(),
|
|
583
|
+
ProvideTagHashPlugin(),
|
|
584
|
+
EventHandlersPlugin(),
|
|
585
|
+
DeprecatedTagAttrPlugin()
|
|
586
|
+
];
|
|
587
|
+
const DOMPlugins = (options = {}) => [
|
|
588
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn })
|
|
589
|
+
];
|
|
574
590
|
function createHead(options = {}) {
|
|
591
|
+
const head = createHeadCore({
|
|
592
|
+
...options,
|
|
593
|
+
plugins: [...DOMPlugins(options), ...options?.plugins || []]
|
|
594
|
+
});
|
|
595
|
+
setActiveHead(head);
|
|
596
|
+
return head;
|
|
597
|
+
}
|
|
598
|
+
function createHeadCore(options = {}) {
|
|
575
599
|
let entries = [];
|
|
576
600
|
let _sde = {};
|
|
577
601
|
let _eid = 0;
|
|
@@ -579,13 +603,7 @@ function createHead(options = {}) {
|
|
|
579
603
|
if (options?.hooks)
|
|
580
604
|
hooks.addHooks(options.hooks);
|
|
581
605
|
options.plugins = [
|
|
582
|
-
|
|
583
|
-
DedupesTagsPlugin(),
|
|
584
|
-
SortTagsPlugin(),
|
|
585
|
-
TitleTemplatePlugin(),
|
|
586
|
-
EventHandlersPlugin(),
|
|
587
|
-
ProvideTagHashPlugin(),
|
|
588
|
-
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn }),
|
|
606
|
+
...CorePlugins(),
|
|
589
607
|
...options?.plugins || []
|
|
590
608
|
];
|
|
591
609
|
options.plugins.forEach((p) => p.hooks && hooks.addHooks(p.hooks));
|
|
@@ -655,7 +673,6 @@ function createHead(options = {}) {
|
|
|
655
673
|
}
|
|
656
674
|
};
|
|
657
675
|
head.hooks.callHook("init", head);
|
|
658
|
-
setActiveHead(head);
|
|
659
676
|
return head;
|
|
660
677
|
}
|
|
661
678
|
|
|
@@ -672,6 +689,7 @@ const composableNames = [
|
|
|
672
689
|
"useTagBase",
|
|
673
690
|
"useTagMeta",
|
|
674
691
|
"useTagMetaFlat",
|
|
692
|
+
"useSeoMeta",
|
|
675
693
|
"useTagLink",
|
|
676
694
|
"useTagScript",
|
|
677
695
|
"useTagStyle",
|
|
@@ -699,6 +717,8 @@ const unheadComposablesImports = [
|
|
|
699
717
|
}
|
|
700
718
|
];
|
|
701
719
|
|
|
720
|
+
exports.CorePlugins = CorePlugins;
|
|
721
|
+
exports.DOMPlugins = DOMPlugins;
|
|
702
722
|
exports.DedupesTagsPlugin = DedupesTagsPlugin;
|
|
703
723
|
exports.DeprecatedTagAttrPlugin = DeprecatedTagAttrPlugin;
|
|
704
724
|
exports.EventHandlersPlugin = EventHandlersPlugin;
|
|
@@ -710,6 +730,7 @@ exports.TitleTemplatePlugin = TitleTemplatePlugin;
|
|
|
710
730
|
exports.asArray = asArray;
|
|
711
731
|
exports.composableNames = composableNames;
|
|
712
732
|
exports.createHead = createHead;
|
|
733
|
+
exports.createHeadCore = createHeadCore;
|
|
713
734
|
exports.defineHeadPlugin = defineHeadPlugin;
|
|
714
735
|
exports.getActiveHead = getActiveHead;
|
|
715
736
|
exports.hashCode = hashCode;
|
|
@@ -719,6 +740,7 @@ exports.unheadComposablesImports = unheadComposablesImports;
|
|
|
719
740
|
exports.useBodyAttrs = useBodyAttrs;
|
|
720
741
|
exports.useHead = useHead;
|
|
721
742
|
exports.useHtmlAttrs = useHtmlAttrs;
|
|
743
|
+
exports.useSeoMeta = useSeoMeta;
|
|
722
744
|
exports.useServerBodyAttrs = useServerBodyAttrs;
|
|
723
745
|
exports.useServerHead = useServerHead;
|
|
724
746
|
exports.useServerHtmlAttrs = useServerHtmlAttrs;
|
package/dist/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ declare const useTagTitle: (title: Title) => ActiveHeadEntry<any> | void;
|
|
|
37
37
|
declare const useTagBase: (base: Base) => ActiveHeadEntry<any> | void;
|
|
38
38
|
declare const useTagMeta: (meta: Arrayable<Meta>) => ActiveHeadEntry<any> | void;
|
|
39
39
|
declare const useTagMetaFlat: (meta: MetaFlatInput) => ActiveHeadEntry<any> | void;
|
|
40
|
+
declare const useSeoMeta: (meta: MetaFlatInput) => ActiveHeadEntry<any> | void;
|
|
40
41
|
declare const useTagLink: (link: Arrayable<Link>) => ActiveHeadEntry<any> | void;
|
|
41
42
|
declare const useTagScript: (script: Arrayable<Script>) => ActiveHeadEntry<any> | void;
|
|
42
43
|
declare const useTagStyle: (style: Arrayable<Style>) => ActiveHeadEntry<any> | void;
|
|
@@ -59,10 +60,19 @@ declare const useServerBodyAttrs: (attrs: BodyAttributes) => ActiveHeadEntry<any
|
|
|
59
60
|
declare const useServerTitleTemplate: (titleTemplate: TitleTemplate) => ActiveHeadEntry<any> | void;
|
|
60
61
|
|
|
61
62
|
declare let activeHead: Unhead<any> | undefined;
|
|
62
|
-
declare const setActiveHead:
|
|
63
|
-
declare const getActiveHead:
|
|
63
|
+
declare const setActiveHead: (head: Unhead<any> | undefined) => Unhead<any> | undefined;
|
|
64
|
+
declare const getActiveHead: () => Unhead<any> | undefined;
|
|
64
65
|
|
|
66
|
+
declare const CorePlugins: () => _unhead_schema.HeadPlugin[];
|
|
67
|
+
declare const DOMPlugins: (options?: CreateHeadOptions) => _unhead_schema.HeadPlugin[];
|
|
65
68
|
declare function createHead<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a core instance of unhead. Does not provide a global ctx for composables to work
|
|
71
|
+
* and does not register DOM plugins.
|
|
72
|
+
*
|
|
73
|
+
* @param options
|
|
74
|
+
*/
|
|
75
|
+
declare function createHeadCore<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
66
76
|
|
|
67
77
|
declare function defineHeadPlugin(plugin: HeadPlugin): HeadPlugin;
|
|
68
78
|
|
|
@@ -74,4 +84,4 @@ declare const unheadComposablesImports: {
|
|
|
74
84
|
imports: string[];
|
|
75
85
|
}[];
|
|
76
86
|
|
|
77
|
-
export { Arrayable, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, HasElementTags, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, defineHeadPlugin, getActiveHead, hashCode, normaliseEntryTags, setActiveHead, unheadComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
|
87
|
+
export { Arrayable, CorePlugins, DOMPlugins, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, HasElementTags, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, createHeadCore, defineHeadPlugin, getActiveHead, hashCode, normaliseEntryTags, setActiveHead, unheadComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useSeoMeta, 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
|
@@ -488,10 +488,12 @@ const EventHandlersPlugin = () => {
|
|
|
488
488
|
const handler = value;
|
|
489
489
|
$el.setAttribute(eventDedupeKey, "");
|
|
490
490
|
$eventListenerTarget.addEventListener(eventName, handler);
|
|
491
|
-
ctx.entry
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
491
|
+
if (ctx.entry) {
|
|
492
|
+
ctx.entry._sde[sdeKey] = () => {
|
|
493
|
+
$eventListenerTarget.removeEventListener(eventName, handler);
|
|
494
|
+
$el.removeAttribute(eventDedupeKey);
|
|
495
|
+
};
|
|
496
|
+
}
|
|
495
497
|
});
|
|
496
498
|
if (ctx.tag._delayedSrc) {
|
|
497
499
|
$el.setAttribute("src", ctx.tag._delayedSrc);
|
|
@@ -525,15 +527,18 @@ const getActiveHead = () => activeHead;
|
|
|
525
527
|
|
|
526
528
|
function useHead(input, options = {}) {
|
|
527
529
|
const head = getActiveHead();
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
530
|
+
if (head) {
|
|
531
|
+
const isBrowser = IsBrowser || head.resolvedOptions?.document;
|
|
532
|
+
if (options.mode === "server" && isBrowser || options.mode === "client" && !isBrowser)
|
|
533
|
+
return;
|
|
534
|
+
return head.push(input, options);
|
|
535
|
+
}
|
|
532
536
|
}
|
|
533
537
|
const useTagTitle = (title) => useHead({ title });
|
|
534
538
|
const useTagBase = (base) => useHead({ base });
|
|
535
539
|
const useTagMeta = (meta) => useHead({ meta: asArray(meta) });
|
|
536
540
|
const useTagMetaFlat = (meta) => useTagMeta(unpackMeta(meta));
|
|
541
|
+
const useSeoMeta = useTagMetaFlat;
|
|
537
542
|
const useTagLink = (link) => useHead({ link: asArray(link) });
|
|
538
543
|
const useTagScript = (script) => useHead({ script: asArray(script) });
|
|
539
544
|
const useTagStyle = (style) => useHead({ style: asArray(style) });
|
|
@@ -569,7 +574,26 @@ function normaliseEntryTags(e) {
|
|
|
569
574
|
});
|
|
570
575
|
}
|
|
571
576
|
|
|
577
|
+
const CorePlugins = () => [
|
|
578
|
+
DedupesTagsPlugin(),
|
|
579
|
+
SortTagsPlugin(),
|
|
580
|
+
TitleTemplatePlugin(),
|
|
581
|
+
ProvideTagHashPlugin(),
|
|
582
|
+
EventHandlersPlugin(),
|
|
583
|
+
DeprecatedTagAttrPlugin()
|
|
584
|
+
];
|
|
585
|
+
const DOMPlugins = (options = {}) => [
|
|
586
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn })
|
|
587
|
+
];
|
|
572
588
|
function createHead(options = {}) {
|
|
589
|
+
const head = createHeadCore({
|
|
590
|
+
...options,
|
|
591
|
+
plugins: [...DOMPlugins(options), ...options?.plugins || []]
|
|
592
|
+
});
|
|
593
|
+
setActiveHead(head);
|
|
594
|
+
return head;
|
|
595
|
+
}
|
|
596
|
+
function createHeadCore(options = {}) {
|
|
573
597
|
let entries = [];
|
|
574
598
|
let _sde = {};
|
|
575
599
|
let _eid = 0;
|
|
@@ -577,13 +601,7 @@ function createHead(options = {}) {
|
|
|
577
601
|
if (options?.hooks)
|
|
578
602
|
hooks.addHooks(options.hooks);
|
|
579
603
|
options.plugins = [
|
|
580
|
-
|
|
581
|
-
DedupesTagsPlugin(),
|
|
582
|
-
SortTagsPlugin(),
|
|
583
|
-
TitleTemplatePlugin(),
|
|
584
|
-
EventHandlersPlugin(),
|
|
585
|
-
ProvideTagHashPlugin(),
|
|
586
|
-
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn }),
|
|
604
|
+
...CorePlugins(),
|
|
587
605
|
...options?.plugins || []
|
|
588
606
|
];
|
|
589
607
|
options.plugins.forEach((p) => p.hooks && hooks.addHooks(p.hooks));
|
|
@@ -653,7 +671,6 @@ function createHead(options = {}) {
|
|
|
653
671
|
}
|
|
654
672
|
};
|
|
655
673
|
head.hooks.callHook("init", head);
|
|
656
|
-
setActiveHead(head);
|
|
657
674
|
return head;
|
|
658
675
|
}
|
|
659
676
|
|
|
@@ -670,6 +687,7 @@ const composableNames = [
|
|
|
670
687
|
"useTagBase",
|
|
671
688
|
"useTagMeta",
|
|
672
689
|
"useTagMetaFlat",
|
|
690
|
+
"useSeoMeta",
|
|
673
691
|
"useTagLink",
|
|
674
692
|
"useTagScript",
|
|
675
693
|
"useTagStyle",
|
|
@@ -697,4 +715,4 @@ const unheadComposablesImports = [
|
|
|
697
715
|
}
|
|
698
716
|
];
|
|
699
717
|
|
|
700
|
-
export { DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, HasElementTags, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, defineHeadPlugin, getActiveHead, hashCode, normaliseEntryTags, setActiveHead, unheadComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
|
718
|
+
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, HasElementTags, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, createHeadCore, defineHeadPlugin, getActiveHead, hashCode, normaliseEntryTags, setActiveHead, unheadComposablesImports, useBodyAttrs, useHead, useHtmlAttrs, useSeoMeta, 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",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.6",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unhead/dom": "0.6.
|
|
34
|
-
"@unhead/schema": "0.6.
|
|
33
|
+
"@unhead/dom": "0.6.6",
|
|
34
|
+
"@unhead/schema": "0.6.6",
|
|
35
35
|
"hookable": "^5.4.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|