unhead 0.3.1 → 0.4.2
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 +87 -35
- package/dist/index.d.ts +10 -2
- package/dist/index.mjs +85 -35
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -301,8 +301,8 @@ const DedupesTagsPlugin = (options) => {
|
|
|
301
301
|
},
|
|
302
302
|
"tags:resolve": function(ctx) {
|
|
303
303
|
const deduping = {};
|
|
304
|
-
ctx.tags.forEach((tag
|
|
305
|
-
let dedupeKey = tag._d || tag._p
|
|
304
|
+
ctx.tags.forEach((tag) => {
|
|
305
|
+
let dedupeKey = tag._d || tag._p;
|
|
306
306
|
const dupedTag = deduping[dedupeKey];
|
|
307
307
|
if (dupedTag) {
|
|
308
308
|
let strategy = tag?.tagDuplicateStrategy;
|
|
@@ -323,13 +323,12 @@ const DedupesTagsPlugin = (options) => {
|
|
|
323
323
|
};
|
|
324
324
|
return;
|
|
325
325
|
} else if (tag._e === dupedTag._e) {
|
|
326
|
-
dedupeKey = `${dedupeKey}
|
|
327
|
-
if (dupedTag._s) {
|
|
326
|
+
dedupeKey = tag._d = `${dedupeKey}:${tag._p}`;
|
|
327
|
+
if (dupedTag._s && typeof dupedTag.props[dupedTag._s] !== "undefined") {
|
|
328
328
|
delete tag.props[dupedTag._s];
|
|
329
|
-
tag._s = dupedTag._s
|
|
329
|
+
tag._s = `${dupedTag._s}${tag._p}`;
|
|
330
330
|
tag.props[tag._s] = "";
|
|
331
331
|
}
|
|
332
|
-
tag._d = dedupeKey;
|
|
333
332
|
}
|
|
334
333
|
if (Object.keys(tag.props).length === 0 && !tag.children) {
|
|
335
334
|
delete deduping[dedupeKey];
|
|
@@ -397,18 +396,16 @@ function hashCode(s) {
|
|
|
397
396
|
h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
|
|
398
397
|
return ((h ^ h >>> 9) + 65536).toString(16).substring(1, 7).toLowerCase();
|
|
399
398
|
}
|
|
400
|
-
|
|
401
|
-
const HydratesStatePlugin = () => {
|
|
399
|
+
const HydrateStateFromSSRPlugin = () => {
|
|
402
400
|
return defineHeadPlugin({
|
|
403
401
|
hooks: {
|
|
404
402
|
"tag:normalise": (ctx) => {
|
|
405
403
|
const { tag, entry } = ctx;
|
|
406
|
-
if (!HasElementTags.includes(tag.tag))
|
|
407
|
-
return;
|
|
408
|
-
if (typeof tag._d === "undefined" && entry._m === "server")
|
|
404
|
+
if (!HasElementTags.includes(tag.tag) || typeof tag._d === "undefined")
|
|
409
405
|
return;
|
|
410
|
-
tag._s = `data-h-${hashCode(tag._d
|
|
411
|
-
|
|
406
|
+
tag._s = `data-h-${hashCode(tag._d)}`;
|
|
407
|
+
if (entry._m === "server")
|
|
408
|
+
tag.props[tag._s] = "";
|
|
412
409
|
}
|
|
413
410
|
}
|
|
414
411
|
});
|
|
@@ -431,20 +428,67 @@ const PatchDomOnEntryUpdatesPlugin = (options) => {
|
|
|
431
428
|
});
|
|
432
429
|
};
|
|
433
430
|
|
|
431
|
+
const EventHandlersPlugin = () => {
|
|
432
|
+
const stripEventHandlers = (tag) => {
|
|
433
|
+
const props = {};
|
|
434
|
+
const eventHandlers = {};
|
|
435
|
+
Object.entries(tag.props).forEach(([key, value]) => {
|
|
436
|
+
if (key.startsWith("on") && typeof value === "function")
|
|
437
|
+
eventHandlers[key] = value;
|
|
438
|
+
else
|
|
439
|
+
props[key] = value;
|
|
440
|
+
});
|
|
441
|
+
return { props, eventHandlers };
|
|
442
|
+
};
|
|
443
|
+
return defineHeadPlugin({
|
|
444
|
+
hooks: {
|
|
445
|
+
"ssr:beforeRender": function(ctx) {
|
|
446
|
+
ctx.tags = ctx.tags.map((tag) => {
|
|
447
|
+
tag.props = stripEventHandlers(tag).props;
|
|
448
|
+
return tag;
|
|
449
|
+
});
|
|
450
|
+
},
|
|
451
|
+
"dom:beforeRenderTag": function(ctx) {
|
|
452
|
+
const { props, eventHandlers } = stripEventHandlers(ctx.tag);
|
|
453
|
+
if (!Object.keys(eventHandlers).length)
|
|
454
|
+
return;
|
|
455
|
+
ctx.tag.props = props;
|
|
456
|
+
ctx.tag._eventHandlers = eventHandlers;
|
|
457
|
+
},
|
|
458
|
+
"dom:renderTag": function(ctx) {
|
|
459
|
+
const $el = ctx.$el;
|
|
460
|
+
if (!ctx.tag._eventHandlers || !$el)
|
|
461
|
+
return;
|
|
462
|
+
Object.entries(ctx.tag._eventHandlers).forEach(([k, value]) => {
|
|
463
|
+
const sdeKey = `${ctx.tag._s || ctx.tag._p}:${k}`;
|
|
464
|
+
const eventName = k.slice(2).toLowerCase();
|
|
465
|
+
const handler = value;
|
|
466
|
+
$el?.addEventListener(eventName, handler);
|
|
467
|
+
ctx.entry._sde[sdeKey] = () => {
|
|
468
|
+
$el.removeEventListener(eventName, handler);
|
|
469
|
+
};
|
|
470
|
+
delete ctx.queuedSideEffects[sdeKey];
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
};
|
|
476
|
+
|
|
434
477
|
function asArray(value) {
|
|
435
478
|
return Array.isArray(value) ? value : [value];
|
|
436
479
|
}
|
|
437
480
|
|
|
438
|
-
const
|
|
481
|
+
const IsBrowser = typeof window !== "undefined";
|
|
439
482
|
|
|
440
483
|
exports.activeHead = void 0;
|
|
441
484
|
const setActiveHead = (head) => exports.activeHead = head;
|
|
442
485
|
const getActiveHead = () => exports.activeHead;
|
|
443
486
|
|
|
444
487
|
function useHead(input, options = {}) {
|
|
445
|
-
if (options.mode === "server" && IsClient || options.mode === "client" && !IsClient)
|
|
446
|
-
return;
|
|
447
488
|
const head = getActiveHead();
|
|
489
|
+
const isBrowser = IsBrowser || head.resolvedOptions?.document;
|
|
490
|
+
if (options.mode === "server" && isBrowser || options.mode === "client" && !isBrowser)
|
|
491
|
+
return;
|
|
448
492
|
head.push(input, options);
|
|
449
493
|
}
|
|
450
494
|
const useTagTitle = (title) => {
|
|
@@ -518,12 +562,14 @@ const useServerTitleTemplate = (titleTemplate) => {
|
|
|
518
562
|
useServerHead({ titleTemplate });
|
|
519
563
|
};
|
|
520
564
|
|
|
565
|
+
const TagEntityBits = 10;
|
|
566
|
+
|
|
521
567
|
function normaliseEntryTags(e) {
|
|
522
568
|
return Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).map(
|
|
523
569
|
([k, value]) => asArray(value).map((props) => asArray(normaliseTag(k, props)))
|
|
524
570
|
).flat(3).map((t, i) => {
|
|
525
571
|
t._e = e._i;
|
|
526
|
-
t._p = (e._i <<
|
|
572
|
+
t._p = (e._i << TagEntityBits) + i;
|
|
527
573
|
return t;
|
|
528
574
|
});
|
|
529
575
|
}
|
|
@@ -531,21 +577,23 @@ function normaliseEntryTags(e) {
|
|
|
531
577
|
function createHead(options = {}) {
|
|
532
578
|
let entries = [];
|
|
533
579
|
let _sde = {};
|
|
534
|
-
let
|
|
580
|
+
let _eid = 0;
|
|
535
581
|
const hooks = hookable.createHooks();
|
|
536
582
|
if (options?.hooks)
|
|
537
583
|
hooks.addHooks(options.hooks);
|
|
538
|
-
|
|
584
|
+
options.plugins = [
|
|
539
585
|
DeprecatedTagAttrPlugin(),
|
|
540
586
|
DedupesTagsPlugin(),
|
|
541
587
|
SortTagsPlugin(),
|
|
542
588
|
TitleTemplatePlugin(),
|
|
543
|
-
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn })
|
|
589
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn }),
|
|
590
|
+
EventHandlersPlugin(),
|
|
591
|
+
...options?.plugins || []
|
|
544
592
|
];
|
|
545
|
-
plugins.
|
|
546
|
-
|
|
547
|
-
const triggerUpdate = () => hooks.callHook("entries:updated", head);
|
|
593
|
+
options.plugins.forEach((p) => p.hooks && hooks.addHooks(p.hooks));
|
|
594
|
+
const triggerUpdateHook = () => hooks.callHook("entries:updated", head);
|
|
548
595
|
const head = {
|
|
596
|
+
resolvedOptions: options,
|
|
549
597
|
_popSideEffectQueue() {
|
|
550
598
|
const sde = { ..._sde };
|
|
551
599
|
_sde = {};
|
|
@@ -558,23 +606,24 @@ function createHead(options = {}) {
|
|
|
558
606
|
return hooks;
|
|
559
607
|
},
|
|
560
608
|
push(input, options2) {
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
_i,
|
|
609
|
+
const activeEntry = {
|
|
610
|
+
_i: _eid++,
|
|
564
611
|
input,
|
|
565
|
-
_sde: {}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
612
|
+
_sde: {}
|
|
613
|
+
};
|
|
614
|
+
if (options2?.mode)
|
|
615
|
+
activeEntry._m = options2?.mode;
|
|
616
|
+
entries.push(activeEntry);
|
|
617
|
+
triggerUpdateHook();
|
|
569
618
|
const queueSideEffects = (e) => {
|
|
570
619
|
_sde = { ..._sde, ...e._sde || {} };
|
|
571
620
|
e._sde = {};
|
|
572
|
-
|
|
621
|
+
triggerUpdateHook();
|
|
573
622
|
};
|
|
574
623
|
return {
|
|
575
624
|
dispose() {
|
|
576
625
|
entries = entries.filter((e) => {
|
|
577
|
-
if (e._i !== _i)
|
|
626
|
+
if (e._i !== activeEntry._i)
|
|
578
627
|
return true;
|
|
579
628
|
queueSideEffects(e);
|
|
580
629
|
return false;
|
|
@@ -582,9 +631,10 @@ function createHead(options = {}) {
|
|
|
582
631
|
},
|
|
583
632
|
patch(input2) {
|
|
584
633
|
entries = entries.map((e) => {
|
|
585
|
-
if (e._i === _i) {
|
|
634
|
+
if (e._i === activeEntry._i) {
|
|
586
635
|
queueSideEffects(e);
|
|
587
|
-
|
|
636
|
+
activeEntry.input = e.input = input2;
|
|
637
|
+
activeEntry._i = e._i = _eid++;
|
|
588
638
|
}
|
|
589
639
|
return e;
|
|
590
640
|
});
|
|
@@ -616,7 +666,8 @@ function defineHeadPlugin(plugin) {
|
|
|
616
666
|
|
|
617
667
|
exports.DedupesTagsPlugin = DedupesTagsPlugin;
|
|
618
668
|
exports.DeprecatedTagAttrPlugin = DeprecatedTagAttrPlugin;
|
|
619
|
-
exports.
|
|
669
|
+
exports.EventHandlersPlugin = EventHandlersPlugin;
|
|
670
|
+
exports.HydrateStateFromSSRPlugin = HydrateStateFromSSRPlugin;
|
|
620
671
|
exports.PatchDomOnEntryUpdatesPlugin = PatchDomOnEntryUpdatesPlugin;
|
|
621
672
|
exports.SortTagsPlugin = SortTagsPlugin;
|
|
622
673
|
exports.TitleTemplatePlugin = TitleTemplatePlugin;
|
|
@@ -624,6 +675,7 @@ exports.asArray = asArray;
|
|
|
624
675
|
exports.createHead = createHead;
|
|
625
676
|
exports.defineHeadPlugin = defineHeadPlugin;
|
|
626
677
|
exports.getActiveHead = getActiveHead;
|
|
678
|
+
exports.hashCode = hashCode;
|
|
627
679
|
exports.normaliseEntryTags = normaliseEntryTags;
|
|
628
680
|
exports.setActiveHead = setActiveHead;
|
|
629
681
|
exports.useBodyAttrs = useBodyAttrs;
|
package/dist/index.d.ts
CHANGED
|
@@ -13,13 +13,21 @@ declare const TitleTemplatePlugin: () => _unhead_schema.HeadPlugin;
|
|
|
13
13
|
|
|
14
14
|
declare const DeprecatedTagAttrPlugin: () => _unhead_schema.HeadPlugin;
|
|
15
15
|
|
|
16
|
-
declare
|
|
16
|
+
declare function hashCode(s: string): string;
|
|
17
|
+
declare const HydrateStateFromSSRPlugin: () => _unhead_schema.HeadPlugin;
|
|
17
18
|
|
|
18
19
|
interface TriggerDomPatchingOnUpdatesPluginOptions extends RenderDomHeadOptions {
|
|
19
20
|
delayFn?: (fn: () => void) => void;
|
|
20
21
|
}
|
|
21
22
|
declare const PatchDomOnEntryUpdatesPlugin: (options?: TriggerDomPatchingOnUpdatesPluginOptions) => _unhead_schema.HeadPlugin;
|
|
22
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Supports DOM event handlers (i.e `onload`) as functions.
|
|
26
|
+
*
|
|
27
|
+
* When SSR we need to strip out these values. On CSR we
|
|
28
|
+
*/
|
|
29
|
+
declare const EventHandlersPlugin: () => _unhead_schema.HeadPlugin;
|
|
30
|
+
|
|
23
31
|
declare type Arrayable<T> = T | Array<T>;
|
|
24
32
|
declare function asArray<T>(value: Arrayable<T>): T[];
|
|
25
33
|
|
|
@@ -59,4 +67,4 @@ declare function defineHeadPlugin(plugin: HeadPlugin): HeadPlugin;
|
|
|
59
67
|
|
|
60
68
|
declare function normaliseEntryTags<T extends {} = Head>(e: HeadEntry<T>): HeadTag[];
|
|
61
69
|
|
|
62
|
-
export { Arrayable, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin,
|
|
70
|
+
export { Arrayable, DedupesTagsPlugin, DedupesTagsPluginOptions, DeprecatedTagAttrPlugin, EventHandlersPlugin, HydrateStateFromSSRPlugin, PatchDomOnEntryUpdatesPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, hashCode, 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
|
@@ -299,8 +299,8 @@ const DedupesTagsPlugin = (options) => {
|
|
|
299
299
|
},
|
|
300
300
|
"tags:resolve": function(ctx) {
|
|
301
301
|
const deduping = {};
|
|
302
|
-
ctx.tags.forEach((tag
|
|
303
|
-
let dedupeKey = tag._d || tag._p
|
|
302
|
+
ctx.tags.forEach((tag) => {
|
|
303
|
+
let dedupeKey = tag._d || tag._p;
|
|
304
304
|
const dupedTag = deduping[dedupeKey];
|
|
305
305
|
if (dupedTag) {
|
|
306
306
|
let strategy = tag?.tagDuplicateStrategy;
|
|
@@ -321,13 +321,12 @@ const DedupesTagsPlugin = (options) => {
|
|
|
321
321
|
};
|
|
322
322
|
return;
|
|
323
323
|
} else if (tag._e === dupedTag._e) {
|
|
324
|
-
dedupeKey = `${dedupeKey}
|
|
325
|
-
if (dupedTag._s) {
|
|
324
|
+
dedupeKey = tag._d = `${dedupeKey}:${tag._p}`;
|
|
325
|
+
if (dupedTag._s && typeof dupedTag.props[dupedTag._s] !== "undefined") {
|
|
326
326
|
delete tag.props[dupedTag._s];
|
|
327
|
-
tag._s = dupedTag._s
|
|
327
|
+
tag._s = `${dupedTag._s}${tag._p}`;
|
|
328
328
|
tag.props[tag._s] = "";
|
|
329
329
|
}
|
|
330
|
-
tag._d = dedupeKey;
|
|
331
330
|
}
|
|
332
331
|
if (Object.keys(tag.props).length === 0 && !tag.children) {
|
|
333
332
|
delete deduping[dedupeKey];
|
|
@@ -395,18 +394,16 @@ function hashCode(s) {
|
|
|
395
394
|
h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
|
|
396
395
|
return ((h ^ h >>> 9) + 65536).toString(16).substring(1, 7).toLowerCase();
|
|
397
396
|
}
|
|
398
|
-
|
|
399
|
-
const HydratesStatePlugin = () => {
|
|
397
|
+
const HydrateStateFromSSRPlugin = () => {
|
|
400
398
|
return defineHeadPlugin({
|
|
401
399
|
hooks: {
|
|
402
400
|
"tag:normalise": (ctx) => {
|
|
403
401
|
const { tag, entry } = ctx;
|
|
404
|
-
if (!HasElementTags.includes(tag.tag))
|
|
405
|
-
return;
|
|
406
|
-
if (typeof tag._d === "undefined" && entry._m === "server")
|
|
402
|
+
if (!HasElementTags.includes(tag.tag) || typeof tag._d === "undefined")
|
|
407
403
|
return;
|
|
408
|
-
tag._s = `data-h-${hashCode(tag._d
|
|
409
|
-
|
|
404
|
+
tag._s = `data-h-${hashCode(tag._d)}`;
|
|
405
|
+
if (entry._m === "server")
|
|
406
|
+
tag.props[tag._s] = "";
|
|
410
407
|
}
|
|
411
408
|
}
|
|
412
409
|
});
|
|
@@ -429,20 +426,67 @@ const PatchDomOnEntryUpdatesPlugin = (options) => {
|
|
|
429
426
|
});
|
|
430
427
|
};
|
|
431
428
|
|
|
429
|
+
const EventHandlersPlugin = () => {
|
|
430
|
+
const stripEventHandlers = (tag) => {
|
|
431
|
+
const props = {};
|
|
432
|
+
const eventHandlers = {};
|
|
433
|
+
Object.entries(tag.props).forEach(([key, value]) => {
|
|
434
|
+
if (key.startsWith("on") && typeof value === "function")
|
|
435
|
+
eventHandlers[key] = value;
|
|
436
|
+
else
|
|
437
|
+
props[key] = value;
|
|
438
|
+
});
|
|
439
|
+
return { props, eventHandlers };
|
|
440
|
+
};
|
|
441
|
+
return defineHeadPlugin({
|
|
442
|
+
hooks: {
|
|
443
|
+
"ssr:beforeRender": function(ctx) {
|
|
444
|
+
ctx.tags = ctx.tags.map((tag) => {
|
|
445
|
+
tag.props = stripEventHandlers(tag).props;
|
|
446
|
+
return tag;
|
|
447
|
+
});
|
|
448
|
+
},
|
|
449
|
+
"dom:beforeRenderTag": function(ctx) {
|
|
450
|
+
const { props, eventHandlers } = stripEventHandlers(ctx.tag);
|
|
451
|
+
if (!Object.keys(eventHandlers).length)
|
|
452
|
+
return;
|
|
453
|
+
ctx.tag.props = props;
|
|
454
|
+
ctx.tag._eventHandlers = eventHandlers;
|
|
455
|
+
},
|
|
456
|
+
"dom:renderTag": function(ctx) {
|
|
457
|
+
const $el = ctx.$el;
|
|
458
|
+
if (!ctx.tag._eventHandlers || !$el)
|
|
459
|
+
return;
|
|
460
|
+
Object.entries(ctx.tag._eventHandlers).forEach(([k, value]) => {
|
|
461
|
+
const sdeKey = `${ctx.tag._s || ctx.tag._p}:${k}`;
|
|
462
|
+
const eventName = k.slice(2).toLowerCase();
|
|
463
|
+
const handler = value;
|
|
464
|
+
$el?.addEventListener(eventName, handler);
|
|
465
|
+
ctx.entry._sde[sdeKey] = () => {
|
|
466
|
+
$el.removeEventListener(eventName, handler);
|
|
467
|
+
};
|
|
468
|
+
delete ctx.queuedSideEffects[sdeKey];
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
|
|
432
475
|
function asArray(value) {
|
|
433
476
|
return Array.isArray(value) ? value : [value];
|
|
434
477
|
}
|
|
435
478
|
|
|
436
|
-
const
|
|
479
|
+
const IsBrowser = typeof window !== "undefined";
|
|
437
480
|
|
|
438
481
|
let activeHead;
|
|
439
482
|
const setActiveHead = (head) => activeHead = head;
|
|
440
483
|
const getActiveHead = () => activeHead;
|
|
441
484
|
|
|
442
485
|
function useHead(input, options = {}) {
|
|
443
|
-
if (options.mode === "server" && IsClient || options.mode === "client" && !IsClient)
|
|
444
|
-
return;
|
|
445
486
|
const head = getActiveHead();
|
|
487
|
+
const isBrowser = IsBrowser || head.resolvedOptions?.document;
|
|
488
|
+
if (options.mode === "server" && isBrowser || options.mode === "client" && !isBrowser)
|
|
489
|
+
return;
|
|
446
490
|
head.push(input, options);
|
|
447
491
|
}
|
|
448
492
|
const useTagTitle = (title) => {
|
|
@@ -516,12 +560,14 @@ const useServerTitleTemplate = (titleTemplate) => {
|
|
|
516
560
|
useServerHead({ titleTemplate });
|
|
517
561
|
};
|
|
518
562
|
|
|
563
|
+
const TagEntityBits = 10;
|
|
564
|
+
|
|
519
565
|
function normaliseEntryTags(e) {
|
|
520
566
|
return Object.entries(e.input).filter(([k, v]) => typeof v !== "undefined" && ValidHeadTags.includes(k)).map(
|
|
521
567
|
([k, value]) => asArray(value).map((props) => asArray(normaliseTag(k, props)))
|
|
522
568
|
).flat(3).map((t, i) => {
|
|
523
569
|
t._e = e._i;
|
|
524
|
-
t._p = (e._i <<
|
|
570
|
+
t._p = (e._i << TagEntityBits) + i;
|
|
525
571
|
return t;
|
|
526
572
|
});
|
|
527
573
|
}
|
|
@@ -529,21 +575,23 @@ function normaliseEntryTags(e) {
|
|
|
529
575
|
function createHead(options = {}) {
|
|
530
576
|
let entries = [];
|
|
531
577
|
let _sde = {};
|
|
532
|
-
let
|
|
578
|
+
let _eid = 0;
|
|
533
579
|
const hooks = createHooks();
|
|
534
580
|
if (options?.hooks)
|
|
535
581
|
hooks.addHooks(options.hooks);
|
|
536
|
-
|
|
582
|
+
options.plugins = [
|
|
537
583
|
DeprecatedTagAttrPlugin(),
|
|
538
584
|
DedupesTagsPlugin(),
|
|
539
585
|
SortTagsPlugin(),
|
|
540
586
|
TitleTemplatePlugin(),
|
|
541
|
-
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn })
|
|
587
|
+
PatchDomOnEntryUpdatesPlugin({ document: options?.document, delayFn: options?.domDelayFn }),
|
|
588
|
+
EventHandlersPlugin(),
|
|
589
|
+
...options?.plugins || []
|
|
542
590
|
];
|
|
543
|
-
plugins.
|
|
544
|
-
|
|
545
|
-
const triggerUpdate = () => hooks.callHook("entries:updated", head);
|
|
591
|
+
options.plugins.forEach((p) => p.hooks && hooks.addHooks(p.hooks));
|
|
592
|
+
const triggerUpdateHook = () => hooks.callHook("entries:updated", head);
|
|
546
593
|
const head = {
|
|
594
|
+
resolvedOptions: options,
|
|
547
595
|
_popSideEffectQueue() {
|
|
548
596
|
const sde = { ..._sde };
|
|
549
597
|
_sde = {};
|
|
@@ -556,23 +604,24 @@ function createHead(options = {}) {
|
|
|
556
604
|
return hooks;
|
|
557
605
|
},
|
|
558
606
|
push(input, options2) {
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
-
_i,
|
|
607
|
+
const activeEntry = {
|
|
608
|
+
_i: _eid++,
|
|
562
609
|
input,
|
|
563
|
-
_sde: {}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
610
|
+
_sde: {}
|
|
611
|
+
};
|
|
612
|
+
if (options2?.mode)
|
|
613
|
+
activeEntry._m = options2?.mode;
|
|
614
|
+
entries.push(activeEntry);
|
|
615
|
+
triggerUpdateHook();
|
|
567
616
|
const queueSideEffects = (e) => {
|
|
568
617
|
_sde = { ..._sde, ...e._sde || {} };
|
|
569
618
|
e._sde = {};
|
|
570
|
-
|
|
619
|
+
triggerUpdateHook();
|
|
571
620
|
};
|
|
572
621
|
return {
|
|
573
622
|
dispose() {
|
|
574
623
|
entries = entries.filter((e) => {
|
|
575
|
-
if (e._i !== _i)
|
|
624
|
+
if (e._i !== activeEntry._i)
|
|
576
625
|
return true;
|
|
577
626
|
queueSideEffects(e);
|
|
578
627
|
return false;
|
|
@@ -580,9 +629,10 @@ function createHead(options = {}) {
|
|
|
580
629
|
},
|
|
581
630
|
patch(input2) {
|
|
582
631
|
entries = entries.map((e) => {
|
|
583
|
-
if (e._i === _i) {
|
|
632
|
+
if (e._i === activeEntry._i) {
|
|
584
633
|
queueSideEffects(e);
|
|
585
|
-
|
|
634
|
+
activeEntry.input = e.input = input2;
|
|
635
|
+
activeEntry._i = e._i = _eid++;
|
|
586
636
|
}
|
|
587
637
|
return e;
|
|
588
638
|
});
|
|
@@ -612,4 +662,4 @@ function defineHeadPlugin(plugin) {
|
|
|
612
662
|
return plugin;
|
|
613
663
|
}
|
|
614
664
|
|
|
615
|
-
export { DedupesTagsPlugin, DeprecatedTagAttrPlugin,
|
|
665
|
+
export { DedupesTagsPlugin, DeprecatedTagAttrPlugin, EventHandlersPlugin, HydrateStateFromSSRPlugin, PatchDomOnEntryUpdatesPlugin, SortTagsPlugin, TitleTemplatePlugin, activeHead, asArray, createHead, defineHeadPlugin, getActiveHead, hashCode, 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.
|
|
4
|
+
"version": "0.4.2",
|
|
5
5
|
"packageManager": "pnpm@7.14.0",
|
|
6
6
|
"author": "Harlan Wilton <harlan@harlanzw.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@unhead/dom": "0.
|
|
34
|
-
"@unhead/schema": "0.
|
|
33
|
+
"@unhead/dom": "0.4.2",
|
|
34
|
+
"@unhead/schema": "0.4.2",
|
|
35
35
|
"hookable": "^5.4.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"zhead": "1.0.0-beta.
|
|
38
|
+
"zhead": "1.0.0-beta.11"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "unbuild .",
|