unhead 0.2.4 → 0.2.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 +26 -2
- package/dist/index.d.ts +12 -6
- package/dist/index.mjs +26 -3
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -321,6 +321,11 @@ const DedupesTagsPlugin = (options) => {
|
|
|
321
321
|
return;
|
|
322
322
|
} else if (tag._e === dupedTag._e) {
|
|
323
323
|
dedupeKey = `${dedupeKey}:entry(${tag._e}:${tag._p})`;
|
|
324
|
+
if (dupedTag._s) {
|
|
325
|
+
delete tag.props[dupedTag._s];
|
|
326
|
+
tag._s = dupedTag._s + tag._p;
|
|
327
|
+
tag.props[tag._s] = "";
|
|
328
|
+
}
|
|
324
329
|
tag._d = dedupeKey;
|
|
325
330
|
} else {
|
|
326
331
|
tag._p = dupedTag._p;
|
|
@@ -413,6 +418,23 @@ const HydratesStatePlugin = () => {
|
|
|
413
418
|
});
|
|
414
419
|
};
|
|
415
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
|
+
|
|
416
438
|
function asArray(value) {
|
|
417
439
|
return Array.isArray(value) ? value : [value];
|
|
418
440
|
}
|
|
@@ -515,13 +537,14 @@ function createHead(options = {}) {
|
|
|
515
537
|
let _sde = {};
|
|
516
538
|
let entryId = 0;
|
|
517
539
|
const hooks = hookable.createHooks();
|
|
518
|
-
if (options
|
|
540
|
+
if (options?.hooks)
|
|
519
541
|
hooks.addHooks(options.hooks);
|
|
520
542
|
const plugins = [
|
|
521
543
|
DeprecatedTagAttrPlugin(),
|
|
522
544
|
DedupesTagsPlugin(),
|
|
523
545
|
SortTagsPlugin(),
|
|
524
|
-
TitleTemplatePlugin()
|
|
546
|
+
TitleTemplatePlugin(),
|
|
547
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn })
|
|
525
548
|
];
|
|
526
549
|
plugins.push(...options.plugins || []);
|
|
527
550
|
plugins.forEach((plugin) => hooks.addHooks(plugin.hooks || {}));
|
|
@@ -596,6 +619,7 @@ function createHead(options = {}) {
|
|
|
596
619
|
exports.DedupesTagsPlugin = DedupesTagsPlugin;
|
|
597
620
|
exports.DeprecatedTagAttrPlugin = DeprecatedTagAttrPlugin;
|
|
598
621
|
exports.HydratesStatePlugin = HydratesStatePlugin;
|
|
622
|
+
exports.PatchDomOnEntryUpdatesPlugin = PatchDomOnEntryUpdatesPlugin;
|
|
599
623
|
exports.SortTagsPlugin = SortTagsPlugin;
|
|
600
624
|
exports.TitleTemplatePlugin = TitleTemplatePlugin;
|
|
601
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
|
@@ -319,6 +319,11 @@ const DedupesTagsPlugin = (options) => {
|
|
|
319
319
|
return;
|
|
320
320
|
} else if (tag._e === dupedTag._e) {
|
|
321
321
|
dedupeKey = `${dedupeKey}:entry(${tag._e}:${tag._p})`;
|
|
322
|
+
if (dupedTag._s) {
|
|
323
|
+
delete tag.props[dupedTag._s];
|
|
324
|
+
tag._s = dupedTag._s + tag._p;
|
|
325
|
+
tag.props[tag._s] = "";
|
|
326
|
+
}
|
|
322
327
|
tag._d = dedupeKey;
|
|
323
328
|
} else {
|
|
324
329
|
tag._p = dupedTag._p;
|
|
@@ -411,6 +416,23 @@ const HydratesStatePlugin = () => {
|
|
|
411
416
|
});
|
|
412
417
|
};
|
|
413
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
|
+
|
|
414
436
|
function asArray(value) {
|
|
415
437
|
return Array.isArray(value) ? value : [value];
|
|
416
438
|
}
|
|
@@ -513,13 +535,14 @@ function createHead(options = {}) {
|
|
|
513
535
|
let _sde = {};
|
|
514
536
|
let entryId = 0;
|
|
515
537
|
const hooks = createHooks();
|
|
516
|
-
if (options
|
|
538
|
+
if (options?.hooks)
|
|
517
539
|
hooks.addHooks(options.hooks);
|
|
518
540
|
const plugins = [
|
|
519
541
|
DeprecatedTagAttrPlugin(),
|
|
520
542
|
DedupesTagsPlugin(),
|
|
521
543
|
SortTagsPlugin(),
|
|
522
|
-
TitleTemplatePlugin()
|
|
544
|
+
TitleTemplatePlugin(),
|
|
545
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn })
|
|
523
546
|
];
|
|
524
547
|
plugins.push(...options.plugins || []);
|
|
525
548
|
plugins.forEach((plugin) => hooks.addHooks(plugin.hooks || {}));
|
|
@@ -591,4 +614,4 @@ function createHead(options = {}) {
|
|
|
591
614
|
return head;
|
|
592
615
|
}
|
|
593
616
|
|
|
594
|
-
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.6",
|
|
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.6",
|
|
34
34
|
"hookable": "^5.4.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|