unhead 0.2.5 → 0.2.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 +26 -7
- package/dist/index.d.ts +12 -6
- package/dist/index.mjs +26 -8
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -377,15 +377,11 @@ const TitleTemplatePlugin = () => {
|
|
|
377
377
|
});
|
|
378
378
|
};
|
|
379
379
|
|
|
380
|
-
function defineHeadPlugin(plugin) {
|
|
381
|
-
return plugin;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
380
|
const DeprecatedTagAttrPlugin = () => {
|
|
385
381
|
return defineHeadPlugin({
|
|
386
382
|
hooks: {
|
|
387
383
|
"tag:normalise": function({ tag }) {
|
|
388
|
-
if (tag.props.body) {
|
|
384
|
+
if (typeof tag.props.body !== "undefined") {
|
|
389
385
|
tag.tagPosition = "bodyClose";
|
|
390
386
|
delete tag.props.body;
|
|
391
387
|
}
|
|
@@ -418,6 +414,27 @@ const HydratesStatePlugin = () => {
|
|
|
418
414
|
});
|
|
419
415
|
};
|
|
420
416
|
|
|
417
|
+
function defineHeadPlugin(plugin) {
|
|
418
|
+
return plugin;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const PatchDomOnEntryUpdatesPlugin = (options) => {
|
|
422
|
+
return defineHeadPlugin({
|
|
423
|
+
hooks: {
|
|
424
|
+
"entries:updated": function(head) {
|
|
425
|
+
if (typeof options?.document === "undefined" && typeof window === "undefined")
|
|
426
|
+
return;
|
|
427
|
+
let delayFn = options?.delayFn;
|
|
428
|
+
if (!delayFn && typeof requestAnimationFrame !== "undefined")
|
|
429
|
+
delayFn = requestAnimationFrame;
|
|
430
|
+
import('@unhead/dom').then(({ debouncedRenderDOMHead }) => {
|
|
431
|
+
debouncedRenderDOMHead(head, { document: options?.document || window.document, delayFn });
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
};
|
|
437
|
+
|
|
421
438
|
function asArray(value) {
|
|
422
439
|
return Array.isArray(value) ? value : [value];
|
|
423
440
|
}
|
|
@@ -520,13 +537,14 @@ function createHead(options = {}) {
|
|
|
520
537
|
let _sde = {};
|
|
521
538
|
let entryId = 0;
|
|
522
539
|
const hooks = hookable.createHooks();
|
|
523
|
-
if (options
|
|
540
|
+
if (options?.hooks)
|
|
524
541
|
hooks.addHooks(options.hooks);
|
|
525
542
|
const plugins = [
|
|
526
543
|
DeprecatedTagAttrPlugin(),
|
|
527
544
|
DedupesTagsPlugin(),
|
|
528
545
|
SortTagsPlugin(),
|
|
529
|
-
TitleTemplatePlugin()
|
|
546
|
+
TitleTemplatePlugin(),
|
|
547
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn })
|
|
530
548
|
];
|
|
531
549
|
plugins.push(...options.plugins || []);
|
|
532
550
|
plugins.forEach((plugin) => hooks.addHooks(plugin.hooks || {}));
|
|
@@ -601,6 +619,7 @@ function createHead(options = {}) {
|
|
|
601
619
|
exports.DedupesTagsPlugin = DedupesTagsPlugin;
|
|
602
620
|
exports.DeprecatedTagAttrPlugin = DeprecatedTagAttrPlugin;
|
|
603
621
|
exports.HydratesStatePlugin = HydratesStatePlugin;
|
|
622
|
+
exports.PatchDomOnEntryUpdatesPlugin = PatchDomOnEntryUpdatesPlugin;
|
|
604
623
|
exports.SortTagsPlugin = SortTagsPlugin;
|
|
605
624
|
exports.TitleTemplatePlugin = TitleTemplatePlugin;
|
|
606
625
|
exports.asArray = asArray;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as _unhead_schema from '@unhead/schema';
|
|
2
|
-
import { Head, HeadEntryOptions, ActiveHeadEntry, Title, Base, Meta, MetaFlatInput, Link, Script, Style, Noscript, HtmlAttributes, BodyAttributes, TitleTemplate,
|
|
2
|
+
import { Head, HeadEntryOptions, ActiveHeadEntry, Title, Base, Meta, MetaFlatInput, Link, Script, Style, Noscript, HtmlAttributes, BodyAttributes, TitleTemplate, Unhead, CreateHeadOptions, HeadPlugin, HeadEntry, HeadTag } from '@unhead/schema';
|
|
3
|
+
import { RenderDomHeadOptions } from '@unhead/dom';
|
|
3
4
|
|
|
4
5
|
interface DedupesTagsPluginOptions {
|
|
5
6
|
dedupeKeys?: string[];
|
|
@@ -14,6 +15,11 @@ declare const DeprecatedTagAttrPlugin: () => _unhead_schema.HeadPlugin;
|
|
|
14
15
|
|
|
15
16
|
declare const HydratesStatePlugin: () => _unhead_schema.HeadPlugin;
|
|
16
17
|
|
|
18
|
+
interface TriggerDomPatchingOnUpdatesPluginOptions extends RenderDomHeadOptions {
|
|
19
|
+
delayFn?: (fn: () => void) => void;
|
|
20
|
+
}
|
|
21
|
+
declare const PatchDomOnEntryUpdatesPlugin: (options?: TriggerDomPatchingOnUpdatesPluginOptions) => _unhead_schema.HeadPlugin;
|
|
22
|
+
|
|
17
23
|
declare type Arrayable<T> = T | Array<T>;
|
|
18
24
|
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
19
25
|
|
|
@@ -43,14 +49,14 @@ declare const useServerHtmlAttrs: (attrs: HtmlAttributes) => void;
|
|
|
43
49
|
declare const useServerBodyAttrs: (attrs: BodyAttributes) => void;
|
|
44
50
|
declare const useServerTitleTemplate: (titleTemplate: TitleTemplate) => void;
|
|
45
51
|
|
|
46
|
-
declare let activeHead:
|
|
47
|
-
declare const setActiveHead: <T extends
|
|
48
|
-
declare const getActiveHead: <T extends
|
|
52
|
+
declare let activeHead: Unhead<any> | undefined;
|
|
53
|
+
declare const setActiveHead: <T extends Unhead<_unhead_schema.Head<_unhead_schema.SchemaAugmentations>>>(head: T | undefined) => T | undefined;
|
|
54
|
+
declare const getActiveHead: <T extends Unhead<_unhead_schema.Head<_unhead_schema.SchemaAugmentations>>>() => T;
|
|
49
55
|
|
|
50
|
-
declare function createHead<T extends {} = Head>(options?: CreateHeadOptions):
|
|
56
|
+
declare function createHead<T extends {} = Head>(options?: CreateHeadOptions): Unhead<T>;
|
|
51
57
|
|
|
52
58
|
declare function defineHeadPlugin(plugin: HeadPlugin): HeadPlugin;
|
|
53
59
|
|
|
54
60
|
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): HeadTag[];
|
|
55
61
|
|
|
56
|
-
export { Arrayable, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, HydratesStatePlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
|
62
|
+
export { Arrayable, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, HydratesStatePlugin, PatchDomOnEntryUpdatesPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, useBodyAttrs, useHead, useHtmlAttrs, 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
|
@@ -375,15 +375,11 @@ const TitleTemplatePlugin = () => {
|
|
|
375
375
|
});
|
|
376
376
|
};
|
|
377
377
|
|
|
378
|
-
function defineHeadPlugin(plugin) {
|
|
379
|
-
return plugin;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
378
|
const DeprecatedTagAttrPlugin = () => {
|
|
383
379
|
return defineHeadPlugin({
|
|
384
380
|
hooks: {
|
|
385
381
|
"tag:normalise": function({ tag }) {
|
|
386
|
-
if (tag.props.body) {
|
|
382
|
+
if (typeof tag.props.body !== "undefined") {
|
|
387
383
|
tag.tagPosition = "bodyClose";
|
|
388
384
|
delete tag.props.body;
|
|
389
385
|
}
|
|
@@ -416,6 +412,27 @@ const HydratesStatePlugin = () => {
|
|
|
416
412
|
});
|
|
417
413
|
};
|
|
418
414
|
|
|
415
|
+
function defineHeadPlugin(plugin) {
|
|
416
|
+
return plugin;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const PatchDomOnEntryUpdatesPlugin = (options) => {
|
|
420
|
+
return defineHeadPlugin({
|
|
421
|
+
hooks: {
|
|
422
|
+
"entries:updated": function(head) {
|
|
423
|
+
if (typeof options?.document === "undefined" && typeof window === "undefined")
|
|
424
|
+
return;
|
|
425
|
+
let delayFn = options?.delayFn;
|
|
426
|
+
if (!delayFn && typeof requestAnimationFrame !== "undefined")
|
|
427
|
+
delayFn = requestAnimationFrame;
|
|
428
|
+
import('@unhead/dom').then(({ debouncedRenderDOMHead }) => {
|
|
429
|
+
debouncedRenderDOMHead(head, { document: options?.document || window.document, delayFn });
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
};
|
|
435
|
+
|
|
419
436
|
function asArray(value) {
|
|
420
437
|
return Array.isArray(value) ? value : [value];
|
|
421
438
|
}
|
|
@@ -518,13 +535,14 @@ function createHead(options = {}) {
|
|
|
518
535
|
let _sde = {};
|
|
519
536
|
let entryId = 0;
|
|
520
537
|
const hooks = createHooks();
|
|
521
|
-
if (options
|
|
538
|
+
if (options?.hooks)
|
|
522
539
|
hooks.addHooks(options.hooks);
|
|
523
540
|
const plugins = [
|
|
524
541
|
DeprecatedTagAttrPlugin(),
|
|
525
542
|
DedupesTagsPlugin(),
|
|
526
543
|
SortTagsPlugin(),
|
|
527
|
-
TitleTemplatePlugin()
|
|
544
|
+
TitleTemplatePlugin(),
|
|
545
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn })
|
|
528
546
|
];
|
|
529
547
|
plugins.push(...options.plugins || []);
|
|
530
548
|
plugins.forEach((plugin) => hooks.addHooks(plugin.hooks || {}));
|
|
@@ -596,4 +614,4 @@ function createHead(options = {}) {
|
|
|
596
614
|
return head;
|
|
597
615
|
}
|
|
598
616
|
|
|
599
|
-
export { DedupesTagsPlugin, DeprecatedTagAttrPlugin, HydratesStatePlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, useBodyAttrs, useHead, useHtmlAttrs, useServerBodyAttrs, useServerHead, useServerHtmlAttrs, useServerTagBase, useServerTagLink, useServerTagMeta, useServerTagMetaFlat, useServerTagNoscript, useServerTagScript, useServerTagStyle, useServerTagTitle, useServerTitleTemplate, useTagBase, useTagLink, useTagMeta, useTagMetaFlat, useTagNoscript, useTagScript, useTagStyle, useTagTitle, useTitleTemplate };
|
|
617
|
+
export { DedupesTagsPlugin, DeprecatedTagAttrPlugin, HydratesStatePlugin, PatchDomOnEntryUpdatesPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, normaliseEntryTags, setActiveHead, useBodyAttrs, useHead, useHtmlAttrs, 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.2.
|
|
4
|
+
"version": "0.2.7",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unhead/schema": "0.2.
|
|
33
|
+
"@unhead/schema": "0.2.7",
|
|
34
34
|
"hookable": "^5.4.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|