unhead 0.6.6 → 0.6.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/dist/index.cjs +9 -19
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +9 -18
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const hookable = require('hookable');
|
|
4
|
+
const dom = require('@unhead/dom');
|
|
4
5
|
|
|
5
6
|
const ValidHeadTags = [
|
|
6
7
|
"title",
|
|
@@ -408,7 +409,7 @@ const ProvideTagHashPlugin = () => {
|
|
|
408
409
|
const isDynamic = typeof tag.props._dynamic !== "undefined";
|
|
409
410
|
if (!HasElementTags.includes(tag.tag) || !tag.key)
|
|
410
411
|
return;
|
|
411
|
-
tag._hash = hashCode(JSON.stringify({ tag: tag.tag, key: tag.key }));
|
|
412
|
+
tag._hash = dom.hashCode(JSON.stringify({ tag: tag.tag, key: tag.key }));
|
|
412
413
|
if (IsBrowser || getActiveHead()?.resolvedOptions?.document)
|
|
413
414
|
return;
|
|
414
415
|
if (entry._m === "server" || isDynamic) {
|
|
@@ -484,7 +485,7 @@ const EventHandlersPlugin = () => {
|
|
|
484
485
|
const sdeKey = `${ctx.tag._d || ctx.tag._p}:${k}`;
|
|
485
486
|
const eventName = k.slice(2).toLowerCase();
|
|
486
487
|
const eventDedupeKey = `data-h-${eventName}`;
|
|
487
|
-
delete ctx.
|
|
488
|
+
delete ctx.staleSideEffects[sdeKey];
|
|
488
489
|
if ($el.hasAttribute(eventDedupeKey))
|
|
489
490
|
return;
|
|
490
491
|
const handler = value;
|
|
@@ -508,12 +509,6 @@ const EventHandlersPlugin = () => {
|
|
|
508
509
|
function asArray(value) {
|
|
509
510
|
return Array.isArray(value) ? value : [value];
|
|
510
511
|
}
|
|
511
|
-
function hashCode(s) {
|
|
512
|
-
let h = 9;
|
|
513
|
-
for (let i = 0; i < s.length; )
|
|
514
|
-
h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
|
|
515
|
-
return ((h ^ h >>> 9) + 65536).toString(16).substring(1, 8).toLowerCase();
|
|
516
|
-
}
|
|
517
512
|
const HasElementTags = [
|
|
518
513
|
"base",
|
|
519
514
|
"meta",
|
|
@@ -607,7 +602,7 @@ function createHeadCore(options = {}) {
|
|
|
607
602
|
...options?.plugins || []
|
|
608
603
|
];
|
|
609
604
|
options.plugins.forEach((p) => p.hooks && hooks.addHooks(p.hooks));
|
|
610
|
-
const
|
|
605
|
+
const updated = () => hooks.callHook("entries:updated", head);
|
|
611
606
|
const head = {
|
|
612
607
|
resolvedOptions: options,
|
|
613
608
|
headEntries() {
|
|
@@ -625,27 +620,23 @@ function createHeadCore(options = {}) {
|
|
|
625
620
|
if (options2?.mode)
|
|
626
621
|
activeEntry._m = options2?.mode;
|
|
627
622
|
entries.push(activeEntry);
|
|
628
|
-
|
|
629
|
-
const queueSideEffects = (e) => {
|
|
630
|
-
_sde = { ..._sde, ...e._sde || {} };
|
|
631
|
-
e._sde = {};
|
|
632
|
-
triggerUpdateHook();
|
|
633
|
-
};
|
|
623
|
+
updated();
|
|
634
624
|
return {
|
|
635
625
|
dispose() {
|
|
636
626
|
entries = entries.filter((e) => {
|
|
637
627
|
if (e._i !== activeEntry._i)
|
|
638
628
|
return true;
|
|
639
|
-
|
|
629
|
+
_sde = { ..._sde, ...e._sde || {} };
|
|
630
|
+
e._sde = {};
|
|
631
|
+
updated();
|
|
640
632
|
return false;
|
|
641
633
|
});
|
|
642
634
|
},
|
|
643
635
|
patch(input2) {
|
|
644
636
|
entries = entries.map((e) => {
|
|
645
637
|
if (e._i === activeEntry._i) {
|
|
646
|
-
queueSideEffects(e);
|
|
647
638
|
activeEntry.input = e.input = input2;
|
|
648
|
-
|
|
639
|
+
updated();
|
|
649
640
|
}
|
|
650
641
|
return e;
|
|
651
642
|
});
|
|
@@ -733,7 +724,6 @@ exports.createHead = createHead;
|
|
|
733
724
|
exports.createHeadCore = createHeadCore;
|
|
734
725
|
exports.defineHeadPlugin = defineHeadPlugin;
|
|
735
726
|
exports.getActiveHead = getActiveHead;
|
|
736
|
-
exports.hashCode = hashCode;
|
|
737
727
|
exports.normaliseEntryTags = normaliseEntryTags;
|
|
738
728
|
exports.setActiveHead = setActiveHead;
|
|
739
729
|
exports.unheadComposablesImports = unheadComposablesImports;
|
package/dist/index.d.ts
CHANGED
|
@@ -29,7 +29,6 @@ declare const EventHandlersPlugin: () => _unhead_schema.HeadPlugin;
|
|
|
29
29
|
|
|
30
30
|
declare type Arrayable<T> = T | Array<T>;
|
|
31
31
|
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
32
|
-
declare function hashCode(s: string): string;
|
|
33
32
|
declare const HasElementTags: string[];
|
|
34
33
|
|
|
35
34
|
declare function useHead<T extends Head>(input: T, options?: HeadEntryOptions): ActiveHeadEntry<T> | void;
|
|
@@ -84,4 +83,4 @@ declare const unheadComposablesImports: {
|
|
|
84
83
|
imports: string[];
|
|
85
84
|
}[];
|
|
86
85
|
|
|
87
|
-
export { Arrayable, CorePlugins, DOMPlugins, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, HasElementTags, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, createHeadCore, defineHeadPlugin, getActiveHead,
|
|
86
|
+
export { Arrayable, CorePlugins, DOMPlugins, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, HasElementTags, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, createHeadCore, defineHeadPlugin, getActiveHead, 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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHooks } from 'hookable';
|
|
2
|
+
import { hashCode } from '@unhead/dom';
|
|
2
3
|
|
|
3
4
|
const ValidHeadTags = [
|
|
4
5
|
"title",
|
|
@@ -482,7 +483,7 @@ const EventHandlersPlugin = () => {
|
|
|
482
483
|
const sdeKey = `${ctx.tag._d || ctx.tag._p}:${k}`;
|
|
483
484
|
const eventName = k.slice(2).toLowerCase();
|
|
484
485
|
const eventDedupeKey = `data-h-${eventName}`;
|
|
485
|
-
delete ctx.
|
|
486
|
+
delete ctx.staleSideEffects[sdeKey];
|
|
486
487
|
if ($el.hasAttribute(eventDedupeKey))
|
|
487
488
|
return;
|
|
488
489
|
const handler = value;
|
|
@@ -506,12 +507,6 @@ const EventHandlersPlugin = () => {
|
|
|
506
507
|
function asArray(value) {
|
|
507
508
|
return Array.isArray(value) ? value : [value];
|
|
508
509
|
}
|
|
509
|
-
function hashCode(s) {
|
|
510
|
-
let h = 9;
|
|
511
|
-
for (let i = 0; i < s.length; )
|
|
512
|
-
h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
|
|
513
|
-
return ((h ^ h >>> 9) + 65536).toString(16).substring(1, 8).toLowerCase();
|
|
514
|
-
}
|
|
515
510
|
const HasElementTags = [
|
|
516
511
|
"base",
|
|
517
512
|
"meta",
|
|
@@ -605,7 +600,7 @@ function createHeadCore(options = {}) {
|
|
|
605
600
|
...options?.plugins || []
|
|
606
601
|
];
|
|
607
602
|
options.plugins.forEach((p) => p.hooks && hooks.addHooks(p.hooks));
|
|
608
|
-
const
|
|
603
|
+
const updated = () => hooks.callHook("entries:updated", head);
|
|
609
604
|
const head = {
|
|
610
605
|
resolvedOptions: options,
|
|
611
606
|
headEntries() {
|
|
@@ -623,27 +618,23 @@ function createHeadCore(options = {}) {
|
|
|
623
618
|
if (options2?.mode)
|
|
624
619
|
activeEntry._m = options2?.mode;
|
|
625
620
|
entries.push(activeEntry);
|
|
626
|
-
|
|
627
|
-
const queueSideEffects = (e) => {
|
|
628
|
-
_sde = { ..._sde, ...e._sde || {} };
|
|
629
|
-
e._sde = {};
|
|
630
|
-
triggerUpdateHook();
|
|
631
|
-
};
|
|
621
|
+
updated();
|
|
632
622
|
return {
|
|
633
623
|
dispose() {
|
|
634
624
|
entries = entries.filter((e) => {
|
|
635
625
|
if (e._i !== activeEntry._i)
|
|
636
626
|
return true;
|
|
637
|
-
|
|
627
|
+
_sde = { ..._sde, ...e._sde || {} };
|
|
628
|
+
e._sde = {};
|
|
629
|
+
updated();
|
|
638
630
|
return false;
|
|
639
631
|
});
|
|
640
632
|
},
|
|
641
633
|
patch(input2) {
|
|
642
634
|
entries = entries.map((e) => {
|
|
643
635
|
if (e._i === activeEntry._i) {
|
|
644
|
-
queueSideEffects(e);
|
|
645
636
|
activeEntry.input = e.input = input2;
|
|
646
|
-
|
|
637
|
+
updated();
|
|
647
638
|
}
|
|
648
639
|
return e;
|
|
649
640
|
});
|
|
@@ -715,4 +706,4 @@ const unheadComposablesImports = [
|
|
|
715
706
|
}
|
|
716
707
|
];
|
|
717
708
|
|
|
718
|
-
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, HasElementTags, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, createHeadCore, defineHeadPlugin, getActiveHead,
|
|
709
|
+
export { CorePlugins, DOMPlugins, DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, HasElementTags, PatchDomOnEntryUpdatesPlugin, ProvideTagHashPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, composableNames, createHead, createHeadCore, defineHeadPlugin, getActiveHead, 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.7",
|
|
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.7",
|
|
34
|
+
"@unhead/schema": "0.6.7",
|
|
35
35
|
"hookable": "^5.4.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|