@telperion/elements 5.4.3 → 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 +863 -0
- package/fesm/elements.mjs +474 -1
- 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/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 +26 -2
- 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
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var domOps = require('./dom-ops.cjs');
|
|
4
|
+
var internalProps = require('./internal-props.cjs');
|
|
5
|
+
var portalRegistry = require('./portal-registry.cjs');
|
|
6
|
+
var projection = require('./projection.cjs');
|
|
7
|
+
var styles = require('./styles.cjs');
|
|
8
|
+
|
|
9
|
+
class PortalElement extends HTMLElement {
|
|
10
|
+
static { this.observedAttributes = ["name"]; }
|
|
11
|
+
#projection = new projection.Projection();
|
|
12
|
+
#observer = new MutationObserver(() => this.#projection.pull(this));
|
|
13
|
+
#outlet = null;
|
|
14
|
+
#registeredName = null;
|
|
15
|
+
/** Outlet name to project into. */
|
|
16
|
+
get name() {
|
|
17
|
+
return this.getAttribute("name") ?? "";
|
|
18
|
+
}
|
|
19
|
+
set name(value) {
|
|
20
|
+
this.setAttribute("name", value);
|
|
21
|
+
}
|
|
22
|
+
/** The outlet currently hosting this portal's content, if any. */
|
|
23
|
+
get outlet() {
|
|
24
|
+
return this.#outlet;
|
|
25
|
+
}
|
|
26
|
+
/** The portal's content nodes, wherever they currently live. */
|
|
27
|
+
get projectedNodes() {
|
|
28
|
+
return this.#projection.active ? this.#projection.nodes() : Array.from(this.childNodes);
|
|
29
|
+
}
|
|
30
|
+
connectedCallback() {
|
|
31
|
+
styles.injectPortalStyles();
|
|
32
|
+
// Catches children added behind our back (HTML parser, insertAdjacent*, …).
|
|
33
|
+
this.#observer.observe(this, { childList: true });
|
|
34
|
+
this.#register();
|
|
35
|
+
}
|
|
36
|
+
disconnectedCallback() {
|
|
37
|
+
this.#unregister();
|
|
38
|
+
this.#observer.disconnect();
|
|
39
|
+
}
|
|
40
|
+
attributeChangedCallback() {
|
|
41
|
+
if (!this.isConnected)
|
|
42
|
+
return;
|
|
43
|
+
this.#unregister();
|
|
44
|
+
this.#register();
|
|
45
|
+
}
|
|
46
|
+
/** @internal */
|
|
47
|
+
[internalProps.SYNC_PORTAL]() {
|
|
48
|
+
const next = this.#registeredName === null ? null : portalRegistry.portalRegistry.outletFor(this.#registeredName);
|
|
49
|
+
if (next === this.#outlet)
|
|
50
|
+
return;
|
|
51
|
+
this.#detach();
|
|
52
|
+
// Never project into an outlet nested in our own content (cycle).
|
|
53
|
+
if (next && !this.contains(next))
|
|
54
|
+
this.#attach(next);
|
|
55
|
+
}
|
|
56
|
+
// -- Registration ---------------------------------------------------------
|
|
57
|
+
#register() {
|
|
58
|
+
const name = this.name;
|
|
59
|
+
if (!name)
|
|
60
|
+
return;
|
|
61
|
+
this.#registeredName = name;
|
|
62
|
+
portalRegistry.portalRegistry.addPortal(name, this);
|
|
63
|
+
}
|
|
64
|
+
/** Unregisters and brings the content home (so it leaves the document with us). */
|
|
65
|
+
#unregister() {
|
|
66
|
+
if (this.#registeredName !== null) {
|
|
67
|
+
portalRegistry.portalRegistry.removePortal(this.#registeredName, this);
|
|
68
|
+
this.#registeredName = null;
|
|
69
|
+
}
|
|
70
|
+
this.#detach();
|
|
71
|
+
}
|
|
72
|
+
#attach(outlet) {
|
|
73
|
+
this.#outlet = outlet;
|
|
74
|
+
this.#projection.open(outlet, this);
|
|
75
|
+
outlet[internalProps.ATTACH_PORTAL](this);
|
|
76
|
+
this.toggleAttribute("projected", true);
|
|
77
|
+
}
|
|
78
|
+
#detach() {
|
|
79
|
+
const outlet = this.#outlet;
|
|
80
|
+
if (!outlet)
|
|
81
|
+
return;
|
|
82
|
+
this.#outlet = null;
|
|
83
|
+
this.#projection.close(this);
|
|
84
|
+
outlet[internalProps.DETACH_PORTAL](this);
|
|
85
|
+
this.toggleAttribute("projected", false);
|
|
86
|
+
}
|
|
87
|
+
// -- Forwarded DOM mutations ----------------------------------------------
|
|
88
|
+
// Frameworks hold a reference to the portal as the *parent* of the nodes
|
|
89
|
+
// they render. While projected, those nodes live in the outlet, so the
|
|
90
|
+
// native methods would throw; forward them into the projected range.
|
|
91
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
92
|
+
appendChild(node) {
|
|
93
|
+
if (!this.#projection.active)
|
|
94
|
+
return super.appendChild(node);
|
|
95
|
+
this.#projection.insert(node, null);
|
|
96
|
+
return node;
|
|
97
|
+
}
|
|
98
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
99
|
+
insertBefore(node, ref) {
|
|
100
|
+
if (!this.#projection.active || !this.#projection.owns(ref))
|
|
101
|
+
return super.insertBefore(node, ref);
|
|
102
|
+
this.#projection.insert(node, ref);
|
|
103
|
+
return node;
|
|
104
|
+
}
|
|
105
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
106
|
+
removeChild(child) {
|
|
107
|
+
if (!this.#projection.active || !this.#projection.owns(child))
|
|
108
|
+
return super.removeChild(child);
|
|
109
|
+
this.#projection.remove(child);
|
|
110
|
+
return child;
|
|
111
|
+
}
|
|
112
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
113
|
+
replaceChild(next, prev) {
|
|
114
|
+
if (!this.#projection.active || !this.#projection.owns(prev))
|
|
115
|
+
return super.replaceChild(next, prev);
|
|
116
|
+
this.#projection.replace(next, prev);
|
|
117
|
+
return prev;
|
|
118
|
+
}
|
|
119
|
+
// State-preserving `moveBefore()`, forwarded while projected. Only installed
|
|
120
|
+
// where the browser has it natively, so feature detection stays truthful.
|
|
121
|
+
static {
|
|
122
|
+
if (domOps.hasNativeMoveBefore()) {
|
|
123
|
+
Object.defineProperty(this.prototype, "moveBefore", {
|
|
124
|
+
configurable: true,
|
|
125
|
+
writable: true,
|
|
126
|
+
value(node, ref) {
|
|
127
|
+
const projected = this.#projection.active && this.#projection.owns(ref);
|
|
128
|
+
const parent = projected ? this.#projection.container : this;
|
|
129
|
+
domOps.nativeMove(parent, node, projected ? this.#projection.refFor(ref) : ref);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
135
|
+
append(...nodes) {
|
|
136
|
+
if (!this.#projection.active)
|
|
137
|
+
return super.append(...nodes);
|
|
138
|
+
for (const node of toNodes(nodes))
|
|
139
|
+
this.#projection.insert(node, null);
|
|
140
|
+
}
|
|
141
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
142
|
+
prepend(...nodes) {
|
|
143
|
+
if (!this.#projection.active)
|
|
144
|
+
return super.prepend(...nodes);
|
|
145
|
+
for (const node of toNodes(nodes).reverse())
|
|
146
|
+
this.#projection.prepend(node);
|
|
147
|
+
}
|
|
148
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
149
|
+
replaceChildren(...nodes) {
|
|
150
|
+
if (!this.#projection.active)
|
|
151
|
+
return super.replaceChildren(...nodes);
|
|
152
|
+
this.#projection.clear();
|
|
153
|
+
this.append(...nodes);
|
|
154
|
+
}
|
|
155
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
156
|
+
get textContent() {
|
|
157
|
+
if (!this.#projection.active)
|
|
158
|
+
return super.textContent;
|
|
159
|
+
return this.#projection
|
|
160
|
+
.nodes()
|
|
161
|
+
.map((n) => (n.nodeType === Node.COMMENT_NODE ? "" : (n.textContent ?? "")))
|
|
162
|
+
.join("");
|
|
163
|
+
}
|
|
164
|
+
/** @internal */
|
|
165
|
+
set textContent(value) {
|
|
166
|
+
if (!this.#projection.active) {
|
|
167
|
+
super.textContent = value;
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.#projection.clear();
|
|
171
|
+
if (value)
|
|
172
|
+
this.#projection.insert(document.createTextNode(value), null);
|
|
173
|
+
}
|
|
174
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
175
|
+
get innerHTML() {
|
|
176
|
+
return this.#projection.active ? domOps.serializeNodes(this.#projection.nodes()) : super.innerHTML;
|
|
177
|
+
}
|
|
178
|
+
/** @internal */
|
|
179
|
+
set innerHTML(value) {
|
|
180
|
+
if (!this.#projection.active) {
|
|
181
|
+
super.innerHTML = value;
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
this.#projection.clear();
|
|
185
|
+
super.innerHTML = value;
|
|
186
|
+
this.#projection.pull(this);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function toNodes(nodes) {
|
|
190
|
+
return nodes.map((n) => (typeof n === "string" ? document.createTextNode(n) : n));
|
|
191
|
+
}
|
|
192
|
+
if (!customElements.get("tp-portal"))
|
|
193
|
+
customElements.define("tp-portal", PortalElement);
|
|
194
|
+
|
|
195
|
+
exports.PortalElement = PortalElement;
|
|
196
|
+
//# sourceMappingURL=portal-element.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-element.cjs","sources":["../../../../libs/elements/src/portal/portal-element.ts"],"sourcesContent":[null],"names":["Projection","injectPortalStyles","SYNC_PORTAL","portalRegistry","ATTACH_PORTAL","DETACH_PORTAL","hasNativeMoveBefore","nativeMove","serializeNodes"],"mappings":";;;;;;;;AA6CM,MAAO,aAAc,SAAQ,WAAW,CAAA;AAC5B,IAAA,SAAA,IAAA,CAAA,kBAAkB,GAAG,CAAC,MAAM,CAAC,CAAC;AAErC,IAAA,WAAW,GAAG,IAAIA,qBAAU,EAAE;AAC9B,IAAA,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5E,OAAO,GAA+B,IAAI;IAC1C,eAAe,GAAkB,IAAI;;AAGrC,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE;IACxC;IAEA,IAAI,IAAI,CAAC,KAAa,EAAA;AACpB,QAAA,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAClC;;AAGA,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;;AAGA,IAAA,IAAI,cAAc,GAAA;QAChB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,KAAK,CA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K,CAAC,WAAW,GAAG,KAAK;YACzB;QACF;AACA,QAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;AACxB,QAAA,IAAI,KAAK;AAAE,YAAA,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC;IAC1E;;AAGA,IAAA,IAAa,SAAS,GAAA;QACpB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,GAAGC,qBAAc,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,SAAS;IAC7F;;IAGA,IAAa,SAAS,CAAC,KAAa,EAAA;AAClC,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;AAC5B,YAAA,KAAK,CAAC,SAAS,GAAG,KAAK;YACvB;QACF;AACA,QAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;AACxB,QAAA,KAAK,CAAC,SAAS,GAAG,KAAK;AACvB,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;IAC7B;;AAGF,SAAS,OAAO,CAAC,KAA2B,EAAA;AAC1C,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnF;AAEA,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC;;;;"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { hasNativeMoveBefore, nativeMove, serializeNodes } from './dom-ops.js';
|
|
2
|
+
import { SYNC_PORTAL, ATTACH_PORTAL, DETACH_PORTAL } from './internal-props.js';
|
|
3
|
+
import { portalRegistry } from './portal-registry.js';
|
|
4
|
+
import { Projection } from './projection.js';
|
|
5
|
+
import { injectPortalStyles } from './styles.js';
|
|
6
|
+
|
|
7
|
+
class PortalElement extends HTMLElement {
|
|
8
|
+
static { this.observedAttributes = ["name"]; }
|
|
9
|
+
#projection = new Projection();
|
|
10
|
+
#observer = new MutationObserver(() => this.#projection.pull(this));
|
|
11
|
+
#outlet = null;
|
|
12
|
+
#registeredName = null;
|
|
13
|
+
/** Outlet name to project into. */
|
|
14
|
+
get name() {
|
|
15
|
+
return this.getAttribute("name") ?? "";
|
|
16
|
+
}
|
|
17
|
+
set name(value) {
|
|
18
|
+
this.setAttribute("name", value);
|
|
19
|
+
}
|
|
20
|
+
/** The outlet currently hosting this portal's content, if any. */
|
|
21
|
+
get outlet() {
|
|
22
|
+
return this.#outlet;
|
|
23
|
+
}
|
|
24
|
+
/** The portal's content nodes, wherever they currently live. */
|
|
25
|
+
get projectedNodes() {
|
|
26
|
+
return this.#projection.active ? this.#projection.nodes() : Array.from(this.childNodes);
|
|
27
|
+
}
|
|
28
|
+
connectedCallback() {
|
|
29
|
+
injectPortalStyles();
|
|
30
|
+
// Catches children added behind our back (HTML parser, insertAdjacent*, …).
|
|
31
|
+
this.#observer.observe(this, { childList: true });
|
|
32
|
+
this.#register();
|
|
33
|
+
}
|
|
34
|
+
disconnectedCallback() {
|
|
35
|
+
this.#unregister();
|
|
36
|
+
this.#observer.disconnect();
|
|
37
|
+
}
|
|
38
|
+
attributeChangedCallback() {
|
|
39
|
+
if (!this.isConnected)
|
|
40
|
+
return;
|
|
41
|
+
this.#unregister();
|
|
42
|
+
this.#register();
|
|
43
|
+
}
|
|
44
|
+
/** @internal */
|
|
45
|
+
[SYNC_PORTAL]() {
|
|
46
|
+
const next = this.#registeredName === null ? null : portalRegistry.outletFor(this.#registeredName);
|
|
47
|
+
if (next === this.#outlet)
|
|
48
|
+
return;
|
|
49
|
+
this.#detach();
|
|
50
|
+
// Never project into an outlet nested in our own content (cycle).
|
|
51
|
+
if (next && !this.contains(next))
|
|
52
|
+
this.#attach(next);
|
|
53
|
+
}
|
|
54
|
+
// -- Registration ---------------------------------------------------------
|
|
55
|
+
#register() {
|
|
56
|
+
const name = this.name;
|
|
57
|
+
if (!name)
|
|
58
|
+
return;
|
|
59
|
+
this.#registeredName = name;
|
|
60
|
+
portalRegistry.addPortal(name, this);
|
|
61
|
+
}
|
|
62
|
+
/** Unregisters and brings the content home (so it leaves the document with us). */
|
|
63
|
+
#unregister() {
|
|
64
|
+
if (this.#registeredName !== null) {
|
|
65
|
+
portalRegistry.removePortal(this.#registeredName, this);
|
|
66
|
+
this.#registeredName = null;
|
|
67
|
+
}
|
|
68
|
+
this.#detach();
|
|
69
|
+
}
|
|
70
|
+
#attach(outlet) {
|
|
71
|
+
this.#outlet = outlet;
|
|
72
|
+
this.#projection.open(outlet, this);
|
|
73
|
+
outlet[ATTACH_PORTAL](this);
|
|
74
|
+
this.toggleAttribute("projected", true);
|
|
75
|
+
}
|
|
76
|
+
#detach() {
|
|
77
|
+
const outlet = this.#outlet;
|
|
78
|
+
if (!outlet)
|
|
79
|
+
return;
|
|
80
|
+
this.#outlet = null;
|
|
81
|
+
this.#projection.close(this);
|
|
82
|
+
outlet[DETACH_PORTAL](this);
|
|
83
|
+
this.toggleAttribute("projected", false);
|
|
84
|
+
}
|
|
85
|
+
// -- Forwarded DOM mutations ----------------------------------------------
|
|
86
|
+
// Frameworks hold a reference to the portal as the *parent* of the nodes
|
|
87
|
+
// they render. While projected, those nodes live in the outlet, so the
|
|
88
|
+
// native methods would throw; forward them into the projected range.
|
|
89
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
90
|
+
appendChild(node) {
|
|
91
|
+
if (!this.#projection.active)
|
|
92
|
+
return super.appendChild(node);
|
|
93
|
+
this.#projection.insert(node, null);
|
|
94
|
+
return node;
|
|
95
|
+
}
|
|
96
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
97
|
+
insertBefore(node, ref) {
|
|
98
|
+
if (!this.#projection.active || !this.#projection.owns(ref))
|
|
99
|
+
return super.insertBefore(node, ref);
|
|
100
|
+
this.#projection.insert(node, ref);
|
|
101
|
+
return node;
|
|
102
|
+
}
|
|
103
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
104
|
+
removeChild(child) {
|
|
105
|
+
if (!this.#projection.active || !this.#projection.owns(child))
|
|
106
|
+
return super.removeChild(child);
|
|
107
|
+
this.#projection.remove(child);
|
|
108
|
+
return child;
|
|
109
|
+
}
|
|
110
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
111
|
+
replaceChild(next, prev) {
|
|
112
|
+
if (!this.#projection.active || !this.#projection.owns(prev))
|
|
113
|
+
return super.replaceChild(next, prev);
|
|
114
|
+
this.#projection.replace(next, prev);
|
|
115
|
+
return prev;
|
|
116
|
+
}
|
|
117
|
+
// State-preserving `moveBefore()`, forwarded while projected. Only installed
|
|
118
|
+
// where the browser has it natively, so feature detection stays truthful.
|
|
119
|
+
static {
|
|
120
|
+
if (hasNativeMoveBefore()) {
|
|
121
|
+
Object.defineProperty(this.prototype, "moveBefore", {
|
|
122
|
+
configurable: true,
|
|
123
|
+
writable: true,
|
|
124
|
+
value(node, ref) {
|
|
125
|
+
const projected = this.#projection.active && this.#projection.owns(ref);
|
|
126
|
+
const parent = projected ? this.#projection.container : this;
|
|
127
|
+
nativeMove(parent, node, projected ? this.#projection.refFor(ref) : ref);
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
133
|
+
append(...nodes) {
|
|
134
|
+
if (!this.#projection.active)
|
|
135
|
+
return super.append(...nodes);
|
|
136
|
+
for (const node of toNodes(nodes))
|
|
137
|
+
this.#projection.insert(node, null);
|
|
138
|
+
}
|
|
139
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
140
|
+
prepend(...nodes) {
|
|
141
|
+
if (!this.#projection.active)
|
|
142
|
+
return super.prepend(...nodes);
|
|
143
|
+
for (const node of toNodes(nodes).reverse())
|
|
144
|
+
this.#projection.prepend(node);
|
|
145
|
+
}
|
|
146
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
147
|
+
replaceChildren(...nodes) {
|
|
148
|
+
if (!this.#projection.active)
|
|
149
|
+
return super.replaceChildren(...nodes);
|
|
150
|
+
this.#projection.clear();
|
|
151
|
+
this.append(...nodes);
|
|
152
|
+
}
|
|
153
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
154
|
+
get textContent() {
|
|
155
|
+
if (!this.#projection.active)
|
|
156
|
+
return super.textContent;
|
|
157
|
+
return this.#projection
|
|
158
|
+
.nodes()
|
|
159
|
+
.map((n) => (n.nodeType === Node.COMMENT_NODE ? "" : (n.textContent ?? "")))
|
|
160
|
+
.join("");
|
|
161
|
+
}
|
|
162
|
+
/** @internal */
|
|
163
|
+
set textContent(value) {
|
|
164
|
+
if (!this.#projection.active) {
|
|
165
|
+
super.textContent = value;
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
this.#projection.clear();
|
|
169
|
+
if (value)
|
|
170
|
+
this.#projection.insert(document.createTextNode(value), null);
|
|
171
|
+
}
|
|
172
|
+
/** @internal Forwarded to the outlet while projected. */
|
|
173
|
+
get innerHTML() {
|
|
174
|
+
return this.#projection.active ? serializeNodes(this.#projection.nodes()) : super.innerHTML;
|
|
175
|
+
}
|
|
176
|
+
/** @internal */
|
|
177
|
+
set innerHTML(value) {
|
|
178
|
+
if (!this.#projection.active) {
|
|
179
|
+
super.innerHTML = value;
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.#projection.clear();
|
|
183
|
+
super.innerHTML = value;
|
|
184
|
+
this.#projection.pull(this);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function toNodes(nodes) {
|
|
188
|
+
return nodes.map((n) => (typeof n === "string" ? document.createTextNode(n) : n));
|
|
189
|
+
}
|
|
190
|
+
if (!customElements.get("tp-portal"))
|
|
191
|
+
customElements.define("tp-portal", PortalElement);
|
|
192
|
+
|
|
193
|
+
export { PortalElement };
|
|
194
|
+
//# sourceMappingURL=portal-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-element.js","sources":["../../../../libs/elements/src/portal/portal-element.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;AA6CM,MAAO,aAAc,SAAQ,WAAW,CAAA;AAC5B,IAAA,SAAA,IAAA,CAAA,kBAAkB,GAAG,CAAC,MAAM,CAAC,CAAC;AAErC,IAAA,WAAW,GAAG,IAAI,UAAU,EAAE;AAC9B,IAAA,SAAS,GAAG,IAAI,gBAAgB,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5E,OAAO,GAA+B,IAAI;IAC1C,eAAe,GAAkB,IAAI;;AAGrC,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE;IACxC;IAEA,IAAI,IAAI,CAAC,KAAa,EAAA;AACpB,QAAA,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC;IAClC;;AAGA,IAAA,IAAI,MAAM,GAAA;QACR,OAAO,IAAI,CAAC,OAAO;IACrB;;AAGA,IAAA,IAAI,cAAc,GAAA;QAChB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;IACzF;IAEA,iBAAiB,GAAA;AACf,QAAA,kBAAkB,EAAE;;AAEpB,QAAA,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;QACjD,IAAI,CAAC,SAAS,EAAE;IAClB;IAEA,oBAAoB,GAAA;QAClB,IAAI,CAAC,WAAW,EAAE;AAClB,QAAA,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;IAC7B;IAEA,wBAAwB,GAAA;QACtB,IA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IAC7F;;IAGA,IAAa,SAAS,CAAC,KAAa,EAAA;AAClC,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE;AAC5B,YAAA,KAAK,CAAC,SAAS,GAAG,KAAK;YACvB;QACF;AACA,QAAA,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;AACxB,QAAA,KAAK,CAAC,SAAS,GAAG,KAAK;AACvB,QAAA,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;IAC7B;;AAGF,SAAS,OAAO,CAAC,KAA2B,EAAA;AAC1C,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,KAAK,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACnF;AAEA,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC;;;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var internalProps = require('./internal-props.cjs');
|
|
4
|
+
var portalRegistry = require('./portal-registry.cjs');
|
|
5
|
+
var styles = require('./styles.cjs');
|
|
6
|
+
|
|
7
|
+
class PortalOutletElement extends HTMLElement {
|
|
8
|
+
static { this.observedAttributes = ["name"]; }
|
|
9
|
+
#portals = new Set();
|
|
10
|
+
#registeredName = null;
|
|
11
|
+
/** Name that `<tp-portal>` elements target. */
|
|
12
|
+
get name() {
|
|
13
|
+
return this.getAttribute("name") ?? "";
|
|
14
|
+
}
|
|
15
|
+
set name(value) {
|
|
16
|
+
this.setAttribute("name", value);
|
|
17
|
+
}
|
|
18
|
+
/** Portals currently projecting into this outlet, in projection order. */
|
|
19
|
+
get portals() {
|
|
20
|
+
return [...this.#portals];
|
|
21
|
+
}
|
|
22
|
+
connectedCallback() {
|
|
23
|
+
styles.injectPortalStyles();
|
|
24
|
+
this.#register();
|
|
25
|
+
}
|
|
26
|
+
disconnectedCallback() {
|
|
27
|
+
this.#unregister();
|
|
28
|
+
}
|
|
29
|
+
attributeChangedCallback() {
|
|
30
|
+
if (!this.isConnected)
|
|
31
|
+
return;
|
|
32
|
+
this.#unregister();
|
|
33
|
+
this.#register();
|
|
34
|
+
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
[internalProps.ATTACH_PORTAL](portal) {
|
|
37
|
+
this.#portals.add(portal);
|
|
38
|
+
this.toggleAttribute("active", true);
|
|
39
|
+
}
|
|
40
|
+
/** @internal */
|
|
41
|
+
[internalProps.DETACH_PORTAL](portal) {
|
|
42
|
+
this.#portals.delete(portal);
|
|
43
|
+
this.toggleAttribute("active", this.#portals.size > 0);
|
|
44
|
+
}
|
|
45
|
+
#register() {
|
|
46
|
+
const name = this.name;
|
|
47
|
+
if (!name)
|
|
48
|
+
return;
|
|
49
|
+
this.#registeredName = name;
|
|
50
|
+
portalRegistry.portalRegistry.addOutlet(name, this);
|
|
51
|
+
}
|
|
52
|
+
#unregister() {
|
|
53
|
+
if (this.#registeredName === null)
|
|
54
|
+
return;
|
|
55
|
+
const name = this.#registeredName;
|
|
56
|
+
this.#registeredName = null;
|
|
57
|
+
portalRegistry.portalRegistry.removeOutlet(name, this);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!customElements.get("tp-portal-outlet"))
|
|
61
|
+
customElements.define("tp-portal-outlet", PortalOutletElement);
|
|
62
|
+
|
|
63
|
+
exports.PortalOutletElement = PortalOutletElement;
|
|
64
|
+
//# sourceMappingURL=portal-outlet-element.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-outlet-element.cjs","sources":["../../../../libs/elements/src/portal/portal-outlet-element.ts"],"sourcesContent":[null],"names":["injectPortalStyles","ATTACH_PORTAL","DETACH_PORTAL","portalRegistry"],"mappings":";;;;;;AA8BM,MAAO,mBAAoB,SAAQ,WAAW,CA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;AAC3B,QAAAC,6BAAc,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC;IACtC;IAEA,WAAW,GAAA;AACT,QAAA,IAAI,IAAI,CAAC,eAAe,KAAK,IAAI;YAAE;AACnC,QAAA,MAAM,IAAI,GAAG,IAAI,CAAC,eAAe;AACjC,QAAA,IAAI,CAAC,eAAe,GAAG,IAAI;AAC3B,QAAAA,6BAAc,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC;IACzC;;AAGF,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,mBAAmB,CAAC;;;;"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ATTACH_PORTAL, DETACH_PORTAL } from './internal-props.js';
|
|
2
|
+
import { portalRegistry } from './portal-registry.js';
|
|
3
|
+
import { injectPortalStyles } from './styles.js';
|
|
4
|
+
|
|
5
|
+
class PortalOutletElement extends HTMLElement {
|
|
6
|
+
static { this.observedAttributes = ["name"]; }
|
|
7
|
+
#portals = new Set();
|
|
8
|
+
#registeredName = null;
|
|
9
|
+
/** Name that `<tp-portal>` elements target. */
|
|
10
|
+
get name() {
|
|
11
|
+
return this.getAttribute("name") ?? "";
|
|
12
|
+
}
|
|
13
|
+
set name(value) {
|
|
14
|
+
this.setAttribute("name", value);
|
|
15
|
+
}
|
|
16
|
+
/** Portals currently projecting into this outlet, in projection order. */
|
|
17
|
+
get portals() {
|
|
18
|
+
return [...this.#portals];
|
|
19
|
+
}
|
|
20
|
+
connectedCallback() {
|
|
21
|
+
injectPortalStyles();
|
|
22
|
+
this.#register();
|
|
23
|
+
}
|
|
24
|
+
disconnectedCallback() {
|
|
25
|
+
this.#unregister();
|
|
26
|
+
}
|
|
27
|
+
attributeChangedCallback() {
|
|
28
|
+
if (!this.isConnected)
|
|
29
|
+
return;
|
|
30
|
+
this.#unregister();
|
|
31
|
+
this.#register();
|
|
32
|
+
}
|
|
33
|
+
/** @internal */
|
|
34
|
+
[ATTACH_PORTAL](portal) {
|
|
35
|
+
this.#portals.add(portal);
|
|
36
|
+
this.toggleAttribute("active", true);
|
|
37
|
+
}
|
|
38
|
+
/** @internal */
|
|
39
|
+
[DETACH_PORTAL](portal) {
|
|
40
|
+
this.#portals.delete(portal);
|
|
41
|
+
this.toggleAttribute("active", this.#portals.size > 0);
|
|
42
|
+
}
|
|
43
|
+
#register() {
|
|
44
|
+
const name = this.name;
|
|
45
|
+
if (!name)
|
|
46
|
+
return;
|
|
47
|
+
this.#registeredName = name;
|
|
48
|
+
portalRegistry.addOutlet(name, this);
|
|
49
|
+
}
|
|
50
|
+
#unregister() {
|
|
51
|
+
if (this.#registeredName === null)
|
|
52
|
+
return;
|
|
53
|
+
const name = this.#registeredName;
|
|
54
|
+
this.#registeredName = null;
|
|
55
|
+
portalRegistry.removeOutlet(name, this);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (!customElements.get("tp-portal-outlet"))
|
|
59
|
+
customElements.define("tp-portal-outlet", PortalOutletElement);
|
|
60
|
+
|
|
61
|
+
export { PortalOutletElement };
|
|
62
|
+
//# sourceMappingURL=portal-outlet-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-outlet-element.js","sources":["../../../../libs/elements/src/portal/portal-outlet-element.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AA8BM,MAAO,mBAAoB,SAAQ,WAAW,CAAA;AAClC,IAAA,SAAA,IAAA,CAAA,kBAAkB,GAAG,CAAC,MAAM,CAAC,CAAC;AAErC,IAAA,QAAQ,GAAG,IAAI,GAAG,EAAiB;IAC5C,eAAe,GAAkB,IAAI;;AAGrC,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE;IACxC;IAEA,IAAI,IAAI,CAAC,KAAa,EAAA;AACpB,QAAA,IAAI,CAAC,YAAY,CAAC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,cAAc,CAAC,GAAG,CAAC,kBAAkB,CAAC;AAAE,IAAA,cAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,mBAAmB,CAAC;;;;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var internalProps = require('./internal-props.cjs');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Module-level name → outlet/portal bookkeeping.
|
|
7
|
+
*
|
|
8
|
+
* - Several outlets may share a name; the **most recently connected** one is
|
|
9
|
+
* active, and the previous one takes over when it disconnects.
|
|
10
|
+
* - Several portals may share a name; all of them project into the active
|
|
11
|
+
* outlet, in connection order.
|
|
12
|
+
*/
|
|
13
|
+
class PortalRegistry {
|
|
14
|
+
#outlets = new Map();
|
|
15
|
+
#portals = new Map();
|
|
16
|
+
outletFor(name) {
|
|
17
|
+
const stack = this.#outlets.get(name);
|
|
18
|
+
return stack?.[stack.length - 1] ?? null;
|
|
19
|
+
}
|
|
20
|
+
addOutlet(name, outlet) {
|
|
21
|
+
const stack = this.#outlets.get(name) ?? [];
|
|
22
|
+
if (!stack.includes(outlet))
|
|
23
|
+
stack.push(outlet);
|
|
24
|
+
this.#outlets.set(name, stack);
|
|
25
|
+
this.#sync(name);
|
|
26
|
+
}
|
|
27
|
+
removeOutlet(name, outlet) {
|
|
28
|
+
const stack = this.#outlets.get(name);
|
|
29
|
+
if (!stack)
|
|
30
|
+
return;
|
|
31
|
+
const index = stack.indexOf(outlet);
|
|
32
|
+
if (index === -1)
|
|
33
|
+
return;
|
|
34
|
+
stack.splice(index, 1);
|
|
35
|
+
if (!stack.length)
|
|
36
|
+
this.#outlets.delete(name);
|
|
37
|
+
this.#sync(name);
|
|
38
|
+
}
|
|
39
|
+
addPortal(name, portal) {
|
|
40
|
+
const set = this.#portals.get(name) ?? new Set();
|
|
41
|
+
set.add(portal);
|
|
42
|
+
this.#portals.set(name, set);
|
|
43
|
+
portal[internalProps.SYNC_PORTAL]();
|
|
44
|
+
}
|
|
45
|
+
removePortal(name, portal) {
|
|
46
|
+
const set = this.#portals.get(name);
|
|
47
|
+
if (!set)
|
|
48
|
+
return;
|
|
49
|
+
set.delete(portal);
|
|
50
|
+
if (!set.size)
|
|
51
|
+
this.#portals.delete(name);
|
|
52
|
+
}
|
|
53
|
+
#sync(name) {
|
|
54
|
+
for (const portal of [...(this.#portals.get(name) ?? [])])
|
|
55
|
+
portal[internalProps.SYNC_PORTAL]();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const portalRegistry = new PortalRegistry();
|
|
59
|
+
|
|
60
|
+
exports.portalRegistry = portalRegistry;
|
|
61
|
+
//# sourceMappingURL=portal-registry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal-registry.cjs","sources":["../../../../libs/elements/src/portal/portal-registry.ts"],"sourcesContent":[null],"names":["SYNC_PORTAL"],"mappings":";;;;AAIA;;;;;;;AAOG;AACH,MAAM,cAAc,CAAA;AACT,IAAA,QAAQ,GAAG,IAAI,GAAG,EAAiC;AACnD,IAAA,QAAQ,GAAG,IAAI,GAAG,EAA8B;AAEzD,IAAA,SAAS,CAAC,IAAY,EAAA;QACpB,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;QACrC,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,IAAI;IAC1C;IAEA,SAAS,CAAC,IAAY,EAAE,MAA2B,EAAA;AACjD,QAAA,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE;AAC3C,QAAA,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC;AAAE,YAAA,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;QAC/C,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC;AAC9B,QAAA,IAAI,CAAC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