@telperion/elements 5.4.2 → 6.0.0
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/.build-manifest.json +12 -1
- package/README.md +37 -0
- package/custom-elements.json +5272 -0
- package/fesm/elements.mjs +477 -2
- package/fesm/elements.mjs.map +1 -1
- package/iife/elements.js +24 -24
- package/iife/elements.js.map +1 -1
- package/iife/portal/index.js +2 -0
- package/iife/portal/index.js.map +1 -0
- package/iife/router/index.js +16 -16
- package/iife/router/index.js.map +1 -1
- package/iife/select/index.js.map +1 -1
- package/index.cjs +4 -0
- package/index.cjs.map +1 -1
- package/index.d.cts +1 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +42 -17
- package/portal/dom-ops.cjs +81 -0
- package/portal/dom-ops.cjs.map +1 -0
- package/portal/dom-ops.js +72 -0
- package/portal/dom-ops.js.map +1 -0
- package/portal/index.cjs +10 -0
- package/portal/index.cjs.map +1 -0
- package/portal/index.d.cts +125 -0
- package/portal/index.d.ts +125 -0
- package/portal/index.js +3 -0
- package/portal/index.js.map +1 -0
- package/portal/internal-props.cjs +13 -0
- package/portal/internal-props.cjs.map +1 -0
- package/portal/internal-props.js +9 -0
- package/portal/internal-props.js.map +1 -0
- package/portal/portal-element.cjs +196 -0
- package/portal/portal-element.cjs.map +1 -0
- package/portal/portal-element.js +194 -0
- package/portal/portal-element.js.map +1 -0
- package/portal/portal-outlet-element.cjs +64 -0
- package/portal/portal-outlet-element.cjs.map +1 -0
- package/portal/portal-outlet-element.js +62 -0
- package/portal/portal-outlet-element.js.map +1 -0
- package/portal/portal-registry.cjs +61 -0
- package/portal/portal-registry.cjs.map +1 -0
- package/portal/portal-registry.js +59 -0
- package/portal/portal-registry.js.map +1 -0
- package/portal/projection.cjs +81 -0
- package/portal/projection.cjs.map +1 -0
- package/portal/projection.js +79 -0
- package/portal/projection.js.map +1 -0
- package/portal/styles.cjs +28 -0
- package/portal/styles.cjs.map +1 -0
- package/portal/styles.js +26 -0
- package/portal/styles.js.map +1 -0
- package/router/history-managed.cjs +3 -1
- package/router/history-managed.cjs.map +1 -1
- package/router/history-managed.js +3 -1
- package/router/history-managed.js.map +1 -1
package/fesm/elements.mjs
CHANGED
|
@@ -374,7 +374,9 @@ const HistoryManaged = (superClass) => {
|
|
|
374
374
|
this.#ownHistoryType = signal(this.history);
|
|
375
375
|
/** Computed signal for parent history type */
|
|
376
376
|
this.#parentHistoryType = computed(() => {
|
|
377
|
-
|
|
377
|
+
// Start above this element: `closest()` matches the element itself, and an outlet or config
|
|
378
|
+
// resolving its own history type would read its own computed (a signal cycle)
|
|
379
|
+
const parent = this.parentElement?.closest('tha-router-config, tha-router-outlet');
|
|
378
380
|
return parent?.[HISTORY_TYPE]?.get();
|
|
379
381
|
});
|
|
380
382
|
/** Resolved history type: own → parent → global */
|
|
@@ -3760,5 +3762,478 @@ ButtonElement = __decorate([
|
|
|
3760
3762
|
__metadata("design:paramtypes", [])
|
|
3761
3763
|
], ButtonElement);
|
|
3762
3764
|
|
|
3763
|
-
|
|
3765
|
+
/**
|
|
3766
|
+
* Native DOM operations captured before `<tp-portal>` overrides them, so the
|
|
3767
|
+
* element can still reach its *own* light DOM while forwarding framework
|
|
3768
|
+
* mutations to its outlet.
|
|
3769
|
+
*/
|
|
3770
|
+
const nativeInsertBefore = Node.prototype.insertBefore;
|
|
3771
|
+
const nativeRemoveChild = Node.prototype.removeChild;
|
|
3772
|
+
const nativeReplaceChild = Node.prototype.replaceChild;
|
|
3773
|
+
const nativeMoveBefore = Element.prototype.moveBefore;
|
|
3774
|
+
function insertNode(parent, node, ref) {
|
|
3775
|
+
nativeInsertBefore.call(parent, node, ref);
|
|
3776
|
+
}
|
|
3777
|
+
function removeNode(node) {
|
|
3778
|
+
if (node.parentNode)
|
|
3779
|
+
nativeRemoveChild.call(node.parentNode, node);
|
|
3780
|
+
}
|
|
3781
|
+
function replaceNode(parent, next, prev) {
|
|
3782
|
+
nativeReplaceChild.call(parent, next, prev);
|
|
3783
|
+
}
|
|
3784
|
+
/**
|
|
3785
|
+
* Moves `node` into `parent` before `ref`. Prefers the state-preserving
|
|
3786
|
+
* `moveBefore()` (focus, iframes, animations, no disconnect/connect
|
|
3787
|
+
* reactions) and falls back to a plain insertion where it is unsupported or
|
|
3788
|
+
* not allowed (e.g. one side is disconnected).
|
|
3789
|
+
*/
|
|
3790
|
+
function moveNode(parent, node, ref, preferMove = true) {
|
|
3791
|
+
if (preferMove && nativeMoveBefore && node.isConnected && parent.isConnected) {
|
|
3792
|
+
try {
|
|
3793
|
+
nativeMoveBefore.call(parent, node, ref);
|
|
3794
|
+
return;
|
|
3795
|
+
}
|
|
3796
|
+
catch {
|
|
3797
|
+
/* fall back to insertBefore */
|
|
3798
|
+
}
|
|
3799
|
+
}
|
|
3800
|
+
nativeInsertBefore.call(parent, node, ref);
|
|
3801
|
+
}
|
|
3802
|
+
function hasNativeMoveBefore() {
|
|
3803
|
+
return nativeMoveBefore !== undefined;
|
|
3804
|
+
}
|
|
3805
|
+
function nativeMove(parent, node, ref) {
|
|
3806
|
+
if (!nativeMoveBefore)
|
|
3807
|
+
throw new DOMException("moveBefore is not supported", "NotSupportedError");
|
|
3808
|
+
nativeMoveBefore.call(parent, node, ref);
|
|
3809
|
+
}
|
|
3810
|
+
/** Nodes strictly between two sibling markers (empty when the markers were torn out). */
|
|
3811
|
+
function nodesBetween(start, end) {
|
|
3812
|
+
const nodes = [];
|
|
3813
|
+
if (!start.parentNode || start.parentNode !== end.parentNode)
|
|
3814
|
+
return nodes;
|
|
3815
|
+
for (let n = start.nextSibling; n && n !== end; n = n.nextSibling)
|
|
3816
|
+
nodes.push(n);
|
|
3817
|
+
return nodes;
|
|
3818
|
+
}
|
|
3819
|
+
const ESCAPES = { "&": "&", "<": "<", ">": ">", " ": " " };
|
|
3820
|
+
/** Minimal HTML serialization of a node list (used for `innerHTML` while projected). */
|
|
3821
|
+
function serializeNodes(nodes) {
|
|
3822
|
+
return nodes
|
|
3823
|
+
.map((n) => {
|
|
3824
|
+
if (n instanceof Element)
|
|
3825
|
+
return n.outerHTML;
|
|
3826
|
+
if (n.nodeType === Node.TEXT_NODE)
|
|
3827
|
+
return (n.nodeValue ?? "").replace(/[&<> ]/g, (c) => ESCAPES[c] ?? c);
|
|
3828
|
+
if (n.nodeType === Node.COMMENT_NODE)
|
|
3829
|
+
return `<!--${n.nodeValue ?? ""}-->`;
|
|
3830
|
+
return "";
|
|
3831
|
+
})
|
|
3832
|
+
.join("");
|
|
3833
|
+
}
|
|
3834
|
+
|
|
3835
|
+
/** Registry → portal: re-resolve the active outlet and (re)project into it. */
|
|
3836
|
+
const SYNC_PORTAL = Symbol("portal:sync");
|
|
3837
|
+
/** Portal → outlet: a portal started projecting into the outlet. */
|
|
3838
|
+
const ATTACH_PORTAL = Symbol("portal-outlet:attach");
|
|
3839
|
+
/** Portal → outlet: a portal stopped projecting into the outlet. */
|
|
3840
|
+
const DETACH_PORTAL = Symbol("portal-outlet:detach");
|
|
3841
|
+
|
|
3842
|
+
/**
|
|
3843
|
+
* Module-level name → outlet/portal bookkeeping.
|
|
3844
|
+
*
|
|
3845
|
+
* - Several outlets may share a name; the **most recently connected** one is
|
|
3846
|
+
* active, and the previous one takes over when it disconnects.
|
|
3847
|
+
* - Several portals may share a name; all of them project into the active
|
|
3848
|
+
* outlet, in connection order.
|
|
3849
|
+
*/
|
|
3850
|
+
class PortalRegistry {
|
|
3851
|
+
#outlets = new Map();
|
|
3852
|
+
#portals = new Map();
|
|
3853
|
+
outletFor(name) {
|
|
3854
|
+
const stack = this.#outlets.get(name);
|
|
3855
|
+
return stack?.[stack.length - 1] ?? null;
|
|
3856
|
+
}
|
|
3857
|
+
addOutlet(name, outlet) {
|
|
3858
|
+
const stack = this.#outlets.get(name) ?? [];
|
|
3859
|
+
if (!stack.includes(outlet))
|
|
3860
|
+
stack.push(outlet);
|
|
3861
|
+
this.#outlets.set(name, stack);
|
|
3862
|
+
this.#sync(name);
|
|
3863
|
+
}
|
|
3864
|
+
removeOutlet(name, outlet) {
|
|
3865
|
+
const stack = this.#outlets.get(name);
|
|
3866
|
+
if (!stack)
|
|
3867
|
+
return;
|
|
3868
|
+
const index = stack.indexOf(outlet);
|
|
3869
|
+
if (index === -1)
|
|
3870
|
+
return;
|
|
3871
|
+
stack.splice(index, 1);
|
|
3872
|
+
if (!stack.length)
|
|
3873
|
+
this.#outlets.delete(name);
|
|
3874
|
+
this.#sync(name);
|
|
3875
|
+
}
|
|
3876
|
+
addPortal(name, portal) {
|
|
3877
|
+
const set = this.#portals.get(name) ?? new Set();
|
|
3878
|
+
set.add(portal);
|
|
3879
|
+
this.#portals.set(name, set);
|
|
3880
|
+
portal[SYNC_PORTAL]();
|
|
3881
|
+
}
|
|
3882
|
+
removePortal(name, portal) {
|
|
3883
|
+
const set = this.#portals.get(name);
|
|
3884
|
+
if (!set)
|
|
3885
|
+
return;
|
|
3886
|
+
set.delete(portal);
|
|
3887
|
+
if (!set.size)
|
|
3888
|
+
this.#portals.delete(name);
|
|
3889
|
+
}
|
|
3890
|
+
#sync(name) {
|
|
3891
|
+
for (const portal of [...(this.#portals.get(name) ?? [])])
|
|
3892
|
+
portal[SYNC_PORTAL]();
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
const portalRegistry = new PortalRegistry();
|
|
3896
|
+
|
|
3897
|
+
/**
|
|
3898
|
+
* The part of an outlet a single portal owns: a `<!--tp-portal-->` …
|
|
3899
|
+
* `<!--/tp-portal-->` comment pair, with the portal's nodes in between.
|
|
3900
|
+
*
|
|
3901
|
+
* Markers keep each portal's nodes contiguous even when several portals share
|
|
3902
|
+
* an outlet, and give frameworks a stable `nextSibling` to insert before
|
|
3903
|
+
* (Angular / Vue insert relative to siblings, which land inside the range).
|
|
3904
|
+
*/
|
|
3905
|
+
class Projection {
|
|
3906
|
+
#start = document.createComment("tp-portal");
|
|
3907
|
+
#end = document.createComment("/tp-portal");
|
|
3908
|
+
#container = null;
|
|
3909
|
+
/** The node currently hosting the projected content, if any. */
|
|
3910
|
+
get container() {
|
|
3911
|
+
return this.#container;
|
|
3912
|
+
}
|
|
3913
|
+
get active() {
|
|
3914
|
+
return this.#container !== null;
|
|
3915
|
+
}
|
|
3916
|
+
/** Nodes currently projected (in order). */
|
|
3917
|
+
nodes() {
|
|
3918
|
+
return this.#container ? nodesBetween(this.#start, this.#end) : [];
|
|
3919
|
+
}
|
|
3920
|
+
/** Whether `ref` is a valid insertion reference inside the projected range. */
|
|
3921
|
+
owns(ref) {
|
|
3922
|
+
return ref === null || (this.#container !== null && ref.parentNode === this.#container);
|
|
3923
|
+
}
|
|
3924
|
+
/** Opens the range at the end of `container` and moves `source`'s children into it. */
|
|
3925
|
+
open(container, source) {
|
|
3926
|
+
this.#container = container;
|
|
3927
|
+
insertNode(container, this.#start, null);
|
|
3928
|
+
insertNode(container, this.#end, null);
|
|
3929
|
+
this.pull(source);
|
|
3930
|
+
}
|
|
3931
|
+
/** Moves every child of `source` into the range (keeps order). */
|
|
3932
|
+
pull(source) {
|
|
3933
|
+
if (!this.#container)
|
|
3934
|
+
return;
|
|
3935
|
+
for (const node of Array.from(source.childNodes))
|
|
3936
|
+
moveNode(this.#container, node, this.#end);
|
|
3937
|
+
}
|
|
3938
|
+
/** Moves projected nodes back to `target`, removes the markers and closes the range. */
|
|
3939
|
+
close(target) {
|
|
3940
|
+
if (!this.#container)
|
|
3941
|
+
return;
|
|
3942
|
+
const nodes = this.nodes();
|
|
3943
|
+
this.#container = null;
|
|
3944
|
+
for (const node of nodes)
|
|
3945
|
+
moveNode(target, node, null);
|
|
3946
|
+
removeNode(this.#start);
|
|
3947
|
+
removeNode(this.#end);
|
|
3948
|
+
}
|
|
3949
|
+
// -- Forwarded mutations (only valid while active) -------------------------
|
|
3950
|
+
insert(node, ref) {
|
|
3951
|
+
insertNode(this.#container, node, ref ?? this.#end);
|
|
3952
|
+
}
|
|
3953
|
+
prepend(node) {
|
|
3954
|
+
insertNode(this.#container, node, this.#start.nextSibling);
|
|
3955
|
+
}
|
|
3956
|
+
remove(node) {
|
|
3957
|
+
removeNode(node);
|
|
3958
|
+
}
|
|
3959
|
+
replace(next, prev) {
|
|
3960
|
+
replaceNode(this.#container, next, prev);
|
|
3961
|
+
}
|
|
3962
|
+
clear() {
|
|
3963
|
+
for (const node of this.nodes())
|
|
3964
|
+
removeNode(node);
|
|
3965
|
+
}
|
|
3966
|
+
/** Reference node to use for `moveBefore` forwarding. */
|
|
3967
|
+
refFor(ref) {
|
|
3968
|
+
return ref ?? this.#end;
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3971
|
+
|
|
3972
|
+
let injected = false;
|
|
3973
|
+
/**
|
|
3974
|
+
* Document-level defaults, adopted once:
|
|
3975
|
+
* - `tp-portal` never renders in place; its content only shows in an outlet.
|
|
3976
|
+
* - `tp-portal-outlet` is layout-transparent so projected content behaves as
|
|
3977
|
+
* if it were a direct child of the outlet's parent. Override freely.
|
|
3978
|
+
*/
|
|
3979
|
+
function injectPortalStyles() {
|
|
3980
|
+
if (injected || typeof document === "undefined")
|
|
3981
|
+
return;
|
|
3982
|
+
injected = true;
|
|
3983
|
+
try {
|
|
3984
|
+
const sheet = new CSSStyleSheet();
|
|
3985
|
+
sheet.replaceSync(`
|
|
3986
|
+
:where(tp-portal) { display: none; }
|
|
3987
|
+
:where(tp-portal-outlet) { display: contents; }
|
|
3988
|
+
`);
|
|
3989
|
+
document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
|
|
3990
|
+
}
|
|
3991
|
+
catch {
|
|
3992
|
+
/* constructable stylesheets unsupported — styles are optional */
|
|
3993
|
+
}
|
|
3994
|
+
}
|
|
3995
|
+
|
|
3996
|
+
class PortalElement extends HTMLElement {
|
|
3997
|
+
static { this.observedAttributes = ["name"]; }
|
|
3998
|
+
#projection = new Projection();
|
|
3999
|
+
#observer = new MutationObserver(() => this.#projection.pull(this));
|
|
4000
|
+
#outlet = null;
|
|
4001
|
+
#registeredName = null;
|
|
4002
|
+
/** Outlet name to project into. */
|
|
4003
|
+
get name() {
|
|
4004
|
+
return this.getAttribute("name") ?? "";
|
|
4005
|
+
}
|
|
4006
|
+
set name(value) {
|
|
4007
|
+
this.setAttribute("name", value);
|
|
4008
|
+
}
|
|
4009
|
+
/** The outlet currently hosting this portal's content, if any. */
|
|
4010
|
+
get outlet() {
|
|
4011
|
+
return this.#outlet;
|
|
4012
|
+
}
|
|
4013
|
+
/** The portal's content nodes, wherever they currently live. */
|
|
4014
|
+
get projectedNodes() {
|
|
4015
|
+
return this.#projection.active ? this.#projection.nodes() : Array.from(this.childNodes);
|
|
4016
|
+
}
|
|
4017
|
+
connectedCallback() {
|
|
4018
|
+
injectPortalStyles();
|
|
4019
|
+
// Catches children added behind our back (HTML parser, insertAdjacent*, …).
|
|
4020
|
+
this.#observer.observe(this, { childList: true });
|
|
4021
|
+
this.#register();
|
|
4022
|
+
}
|
|
4023
|
+
disconnectedCallback() {
|
|
4024
|
+
this.#unregister();
|
|
4025
|
+
this.#observer.disconnect();
|
|
4026
|
+
}
|
|
4027
|
+
attributeChangedCallback() {
|
|
4028
|
+
if (!this.isConnected)
|
|
4029
|
+
return;
|
|
4030
|
+
this.#unregister();
|
|
4031
|
+
this.#register();
|
|
4032
|
+
}
|
|
4033
|
+
/** @internal */
|
|
4034
|
+
[SYNC_PORTAL]() {
|
|
4035
|
+
const next = this.#registeredName === null ? null : portalRegistry.outletFor(this.#registeredName);
|
|
4036
|
+
if (next === this.#outlet)
|
|
4037
|
+
return;
|
|
4038
|
+
this.#detach();
|
|
4039
|
+
// Never project into an outlet nested in our own content (cycle).
|
|
4040
|
+
if (next && !this.contains(next))
|
|
4041
|
+
this.#attach(next);
|
|
4042
|
+
}
|
|
4043
|
+
// -- Registration ---------------------------------------------------------
|
|
4044
|
+
#register() {
|
|
4045
|
+
const name = this.name;
|
|
4046
|
+
if (!name)
|
|
4047
|
+
return;
|
|
4048
|
+
this.#registeredName = name;
|
|
4049
|
+
portalRegistry.addPortal(name, this);
|
|
4050
|
+
}
|
|
4051
|
+
/** Unregisters and brings the content home (so it leaves the document with us). */
|
|
4052
|
+
#unregister() {
|
|
4053
|
+
if (this.#registeredName !== null) {
|
|
4054
|
+
portalRegistry.removePortal(this.#registeredName, this);
|
|
4055
|
+
this.#registeredName = null;
|
|
4056
|
+
}
|
|
4057
|
+
this.#detach();
|
|
4058
|
+
}
|
|
4059
|
+
#attach(outlet) {
|
|
4060
|
+
this.#outlet = outlet;
|
|
4061
|
+
this.#projection.open(outlet, this);
|
|
4062
|
+
outlet[ATTACH_PORTAL](this);
|
|
4063
|
+
this.toggleAttribute("projected", true);
|
|
4064
|
+
}
|
|
4065
|
+
#detach() {
|
|
4066
|
+
const outlet = this.#outlet;
|
|
4067
|
+
if (!outlet)
|
|
4068
|
+
return;
|
|
4069
|
+
this.#outlet = null;
|
|
4070
|
+
this.#projection.close(this);
|
|
4071
|
+
outlet[DETACH_PORTAL](this);
|
|
4072
|
+
this.toggleAttribute("projected", false);
|
|
4073
|
+
}
|
|
4074
|
+
// -- Forwarded DOM mutations ----------------------------------------------
|
|
4075
|
+
// Frameworks hold a reference to the portal as the *parent* of the nodes
|
|
4076
|
+
// they render. While projected, those nodes live in the outlet, so the
|
|
4077
|
+
// native methods would throw; forward them into the projected range.
|
|
4078
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4079
|
+
appendChild(node) {
|
|
4080
|
+
if (!this.#projection.active)
|
|
4081
|
+
return super.appendChild(node);
|
|
4082
|
+
this.#projection.insert(node, null);
|
|
4083
|
+
return node;
|
|
4084
|
+
}
|
|
4085
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4086
|
+
insertBefore(node, ref) {
|
|
4087
|
+
if (!this.#projection.active || !this.#projection.owns(ref))
|
|
4088
|
+
return super.insertBefore(node, ref);
|
|
4089
|
+
this.#projection.insert(node, ref);
|
|
4090
|
+
return node;
|
|
4091
|
+
}
|
|
4092
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4093
|
+
removeChild(child) {
|
|
4094
|
+
if (!this.#projection.active || !this.#projection.owns(child))
|
|
4095
|
+
return super.removeChild(child);
|
|
4096
|
+
this.#projection.remove(child);
|
|
4097
|
+
return child;
|
|
4098
|
+
}
|
|
4099
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4100
|
+
replaceChild(next, prev) {
|
|
4101
|
+
if (!this.#projection.active || !this.#projection.owns(prev))
|
|
4102
|
+
return super.replaceChild(next, prev);
|
|
4103
|
+
this.#projection.replace(next, prev);
|
|
4104
|
+
return prev;
|
|
4105
|
+
}
|
|
4106
|
+
// State-preserving `moveBefore()`, forwarded while projected. Only installed
|
|
4107
|
+
// where the browser has it natively, so feature detection stays truthful.
|
|
4108
|
+
static {
|
|
4109
|
+
if (hasNativeMoveBefore()) {
|
|
4110
|
+
Object.defineProperty(this.prototype, "moveBefore", {
|
|
4111
|
+
configurable: true,
|
|
4112
|
+
writable: true,
|
|
4113
|
+
value(node, ref) {
|
|
4114
|
+
const projected = this.#projection.active && this.#projection.owns(ref);
|
|
4115
|
+
const parent = projected ? this.#projection.container : this;
|
|
4116
|
+
nativeMove(parent, node, projected ? this.#projection.refFor(ref) : ref);
|
|
4117
|
+
},
|
|
4118
|
+
});
|
|
4119
|
+
}
|
|
4120
|
+
}
|
|
4121
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4122
|
+
append(...nodes) {
|
|
4123
|
+
if (!this.#projection.active)
|
|
4124
|
+
return super.append(...nodes);
|
|
4125
|
+
for (const node of toNodes(nodes))
|
|
4126
|
+
this.#projection.insert(node, null);
|
|
4127
|
+
}
|
|
4128
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4129
|
+
prepend(...nodes) {
|
|
4130
|
+
if (!this.#projection.active)
|
|
4131
|
+
return super.prepend(...nodes);
|
|
4132
|
+
for (const node of toNodes(nodes).reverse())
|
|
4133
|
+
this.#projection.prepend(node);
|
|
4134
|
+
}
|
|
4135
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4136
|
+
replaceChildren(...nodes) {
|
|
4137
|
+
if (!this.#projection.active)
|
|
4138
|
+
return super.replaceChildren(...nodes);
|
|
4139
|
+
this.#projection.clear();
|
|
4140
|
+
this.append(...nodes);
|
|
4141
|
+
}
|
|
4142
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4143
|
+
get textContent() {
|
|
4144
|
+
if (!this.#projection.active)
|
|
4145
|
+
return super.textContent;
|
|
4146
|
+
return this.#projection
|
|
4147
|
+
.nodes()
|
|
4148
|
+
.map((n) => (n.nodeType === Node.COMMENT_NODE ? "" : (n.textContent ?? "")))
|
|
4149
|
+
.join("");
|
|
4150
|
+
}
|
|
4151
|
+
/** @internal */
|
|
4152
|
+
set textContent(value) {
|
|
4153
|
+
if (!this.#projection.active) {
|
|
4154
|
+
super.textContent = value;
|
|
4155
|
+
return;
|
|
4156
|
+
}
|
|
4157
|
+
this.#projection.clear();
|
|
4158
|
+
if (value)
|
|
4159
|
+
this.#projection.insert(document.createTextNode(value), null);
|
|
4160
|
+
}
|
|
4161
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
4162
|
+
get innerHTML() {
|
|
4163
|
+
return this.#projection.active ? serializeNodes(this.#projection.nodes()) : super.innerHTML;
|
|
4164
|
+
}
|
|
4165
|
+
/** @internal */
|
|
4166
|
+
set innerHTML(value) {
|
|
4167
|
+
if (!this.#projection.active) {
|
|
4168
|
+
super.innerHTML = value;
|
|
4169
|
+
return;
|
|
4170
|
+
}
|
|
4171
|
+
this.#projection.clear();
|
|
4172
|
+
super.innerHTML = value;
|
|
4173
|
+
this.#projection.pull(this);
|
|
4174
|
+
}
|
|
4175
|
+
}
|
|
4176
|
+
function toNodes(nodes) {
|
|
4177
|
+
return nodes.map((n) => (typeof n === "string" ? document.createTextNode(n) : n));
|
|
4178
|
+
}
|
|
4179
|
+
if (!customElements.get("tp-portal"))
|
|
4180
|
+
customElements.define("tp-portal", PortalElement);
|
|
4181
|
+
|
|
4182
|
+
class PortalOutletElement extends HTMLElement {
|
|
4183
|
+
static { this.observedAttributes = ["name"]; }
|
|
4184
|
+
#portals = new Set();
|
|
4185
|
+
#registeredName = null;
|
|
4186
|
+
/** Name that `<tp-portal>` elements target. */
|
|
4187
|
+
get name() {
|
|
4188
|
+
return this.getAttribute("name") ?? "";
|
|
4189
|
+
}
|
|
4190
|
+
set name(value) {
|
|
4191
|
+
this.setAttribute("name", value);
|
|
4192
|
+
}
|
|
4193
|
+
/** Portals currently projecting into this outlet, in projection order. */
|
|
4194
|
+
get portals() {
|
|
4195
|
+
return [...this.#portals];
|
|
4196
|
+
}
|
|
4197
|
+
connectedCallback() {
|
|
4198
|
+
injectPortalStyles();
|
|
4199
|
+
this.#register();
|
|
4200
|
+
}
|
|
4201
|
+
disconnectedCallback() {
|
|
4202
|
+
this.#unregister();
|
|
4203
|
+
}
|
|
4204
|
+
attributeChangedCallback() {
|
|
4205
|
+
if (!this.isConnected)
|
|
4206
|
+
return;
|
|
4207
|
+
this.#unregister();
|
|
4208
|
+
this.#register();
|
|
4209
|
+
}
|
|
4210
|
+
/** @internal */
|
|
4211
|
+
[ATTACH_PORTAL](portal) {
|
|
4212
|
+
this.#portals.add(portal);
|
|
4213
|
+
this.toggleAttribute("active", true);
|
|
4214
|
+
}
|
|
4215
|
+
/** @internal */
|
|
4216
|
+
[DETACH_PORTAL](portal) {
|
|
4217
|
+
this.#portals.delete(portal);
|
|
4218
|
+
this.toggleAttribute("active", this.#portals.size > 0);
|
|
4219
|
+
}
|
|
4220
|
+
#register() {
|
|
4221
|
+
const name = this.name;
|
|
4222
|
+
if (!name)
|
|
4223
|
+
return;
|
|
4224
|
+
this.#registeredName = name;
|
|
4225
|
+
portalRegistry.addOutlet(name, this);
|
|
4226
|
+
}
|
|
4227
|
+
#unregister() {
|
|
4228
|
+
if (this.#registeredName === null)
|
|
4229
|
+
return;
|
|
4230
|
+
const name = this.#registeredName;
|
|
4231
|
+
this.#registeredName = null;
|
|
4232
|
+
portalRegistry.removeOutlet(name, this);
|
|
4233
|
+
}
|
|
4234
|
+
}
|
|
4235
|
+
if (!customElements.get("tp-portal-outlet"))
|
|
4236
|
+
customElements.define("tp-portal-outlet", PortalOutletElement);
|
|
4237
|
+
|
|
4238
|
+
export { ButtonElement, DetailsSetElement, DragElement, DragHandleElement, DropZoneElement, OptionElement, PopoverElement, PortalElement, PortalOutletElement, SelectChangeEvent, SelectElement, SelectedContentElement, ThaDragEvent, ThaRoute, ThaRouter, ThaRouterConfig, ThaRouterLink, ThaRouterOutlet, ThaRouterParam };
|
|
3764
4239
|
//# sourceMappingURL=elements.mjs.map
|