1
0
mirror of https://github.com/jaandrle/deka-dom-el synced 2025-07-29 07:00:16 +02:00

add removeSignalsFromElements

for better auto-removing signals↔elements listeners (e.g.
provide a way to debug/investigate deps from browser inspector)
This commit is contained in:
2023-10-14 12:43:53 +02:00
parent 9f57913f8d
commit c20f5ae117
8 changed files with 623 additions and 583 deletions

182
dist/esm.js vendored
View File

@@ -3,7 +3,7 @@ var m = {
isSignal(e) {
return !1;
},
processReactiveAttribute(e, t, n, i) {
processReactiveAttribute(e, t, n, u) {
return n;
}
};
@@ -48,9 +48,6 @@ var E = [{
get current() {
return E[E.length - 1];
},
get state() {
return [...E];
},
get host() {
return this.current.host;
},
@@ -72,6 +69,9 @@ var E = [{
}
};
},
get state() {
return [...E];
},
push(e = {}) {
return e.namespace && (e.namespace = R(e.namespace)), E.push(Object.assign({}, this.current, { prevent: !1 }, e));
},
@@ -80,57 +80,57 @@ var E = [{
}
};
function V(e, t, ...n) {
let i = this, r = b(this), { namespace: f } = x, d = !1, c;
switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) {
let u = b(this), { namespace: r } = x, f = 0, a;
switch ((Object(t) !== t || u.isSignal(t)) && (t = { textContent: t }), !0) {
case typeof e == "function": {
d = !0, x.push({ scope: e, host: (a) => a ? (n.unshift(a), void 0) : c }), c = e(t || void 0), (c instanceof HTMLElement ? P : j)(c, "Attribute", "dde-fun", e.name);
f = 1, x.push({ scope: e, host: (i) => i ? (f === 1 ? n.unshift(i) : i(a), void 0) : a }), a = e(t || void 0), (a instanceof HTMLElement ? P : j)(a, "Attribute", "dde-fun", e.name);
break;
}
case e === "#text":
c = w.call(i, document.createTextNode(""), t);
a = w.call(this, document.createTextNode(""), t);
break;
case e === "<>":
c = w.call(i, document.createDocumentFragment(), t);
a = w.call(this, document.createDocumentFragment(), t);
break;
case f !== "html":
c = w.call(i, document.createElementNS(f, e), t);
case r !== "html":
a = w.call(this, document.createElementNS(r, e), t);
break;
case !c:
c = w.call(i, document.createElement(e), t);
case !a:
a = w.call(this, document.createElement(e), t);
}
return n.forEach((a) => a(c)), d && x.pop(), c;
return n.forEach((i) => i(a)), f && x.pop(), f = 2, a;
}
var { setDeleteAttr: S } = C;
function w(e, ...t) {
let n = this, i = b(this);
let n = this, u = b(this);
if (!t.length)
return e;
let f = (e instanceof SVGElement ? j : P).bind(null, e, "Attribute");
return Object.entries(Object.assign({}, ...t)).forEach(function d([c, a]) {
a = i.processReactiveAttribute(e, c, a, d);
let [l] = c;
return Object.entries(Object.assign({}, ...t)).forEach(function a([i, d]) {
d = u.processReactiveAttribute(e, i, d, a);
let [l] = i;
if (l === "=")
return f(c.slice(1), a);
return f(i.slice(1), d);
if (l === ".")
return L(e, c.slice(1), a);
if (/(aria|data)([A-Z])/.test(c))
return c = c.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(c, a);
switch (c === "className" && (c = "class"), c) {
return L(e, i.slice(1), d);
if (/(aria|data)([A-Z])/.test(i))
return i = i.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase(), f(i, d);
switch (i === "className" && (i = "class"), i) {
case "xlink:href":
return f(c, a, "http://www.w3.org/1999/xlink");
return f(i, d, "http://www.w3.org/1999/xlink");
case "textContent":
return S(e, c, a);
return S(e, i, d);
case "style":
if (typeof a != "object")
if (typeof d != "object")
break;
case "dataset":
return O(i, a, L.bind(null, e[c]));
return O(u, d, L.bind(null, e[i]));
case "ariaset":
return O(i, a, (h, o) => f("aria-" + h, o));
return O(u, d, (h, c) => f("aria-" + h, c));
case "classList":
return W.call(n, e, a);
return W.call(n, e, d);
}
return F(e, c) ? S(e, c, a) : f(c, a);
return F(e, i) ? S(e, i, d) : f(i, d);
}), e;
}
function W(e, t) {
@@ -138,7 +138,7 @@ function W(e, t) {
return O(
n,
t,
(i, r) => e.classList.toggle(i, r === -1 ? void 0 : !!r)
(u, r) => e.classList.toggle(u, r === -1 ? void 0 : !!r)
), e;
}
function $(e) {
@@ -159,17 +159,17 @@ function D(e, t) {
function O(e, t, n) {
if (!(typeof t != "object" || t === null))
return Object.entries(t).forEach(function([r, f]) {
r && (f = e.processReactiveAttribute(t, r, f, (d) => n(...d)), n(r, f));
r && (f = e.processReactiveAttribute(t, r, f, (a) => n(...a)), n(r, f));
});
}
function N(e) {
return Array.isArray(e) ? e.filter(Boolean).join(" ") : e;
}
function P(e, t, n, i) {
return e[(g(i) ? "remove" : "set") + t](n, N(i));
function P(e, t, n, u) {
return e[(g(u) ? "remove" : "set") + t](n, N(u));
}
function j(e, t, n, i, r = null) {
return e[(g(i) ? "remove" : "set") + t + "NS"](r, n, N(i));
function j(e, t, n, u, r = null) {
return e[(g(u) ? "remove" : "set") + t + "NS"](r, n, N(u));
}
function L(e, t, n) {
if (Reflect.set(e, t, n), !!g(n))
@@ -178,8 +178,8 @@ function L(e, t, n) {
// src/events.js
function Q(e, t, ...n) {
let i = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(i);
let u = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t);
return e.dispatchEvent(u);
}
function y(e, t, n) {
return function(r) {
@@ -207,99 +207,99 @@ y.attributeChanged = function(e, t) {
let f = "dde:" + n;
if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || H.has(r))
return r;
let d = new MutationObserver(function(a) {
for (let { attributeName: l, target: h } of a)
let a = new MutationObserver(function(d) {
for (let { attributeName: l, target: h } of d)
h.dispatchEvent(
new CustomEvent(f, { detail: [l, h.getAttribute(l)] })
);
});
return _(t.signal, () => d.disconnect()) && d.observe(r, { attributes: !0 }), r;
return _(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r;
};
};
function U() {
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(o) {
for (let s of o)
if (s.type === "childList") {
if (l(s.addedNodes, !0)) {
d();
let e = /* @__PURE__ */ new Map(), t = !1, n = new MutationObserver(function(c) {
for (let o of c)
if (o.type === "childList") {
if (l(o.addedNodes, !0)) {
a();
continue;
}
h(s.removedNodes, !0) && d();
h(o.removedNodes, !0) && a();
}
});
return {
onConnected(o, s) {
onConnected(c, o) {
f();
let u = r(o);
u.connected.has(s) || (u.connected.add(s), u.length_c += 1);
let s = r(c);
s.connected.has(o) || (s.connected.add(o), s.length_c += 1);
},
offConnected(o, s) {
if (!e.has(o))
offConnected(c, o) {
if (!e.has(c))
return;
let u = e.get(o);
u.connected.has(s) && (u.connected.delete(s), u.length_c -= 1, i(o, u));
let s = e.get(c);
s.connected.has(o) && (s.connected.delete(o), s.length_c -= 1, u(c, s));
},
onDisconnected(o, s) {
onDisconnected(c, o) {
f();
let u = r(o);
u.disconnected.has(s) || (u.disconnected.add(s), u.length_d += 1);
let s = r(c);
s.disconnected.has(o) || (s.disconnected.add(o), s.length_d += 1);
},
offDisconnected(o, s) {
if (!e.has(o))
offDisconnected(c, o) {
if (!e.has(c))
return;
let u = e.get(o);
u.disconnected.has(s) && (u.disconnected.delete(s), u.length_d -= 1, i(o, u));
let s = e.get(c);
s.disconnected.has(o) && (s.disconnected.delete(o), s.length_d -= 1, u(c, s));
}
};
function i(o, s) {
s.length_c || s.length_d || (e.delete(o), d());
function u(c, o) {
o.length_c || o.length_d || (e.delete(c), a());
}
function r(o) {
if (e.has(o))
return e.get(o);
let s = {
function r(c) {
if (e.has(c))
return e.get(c);
let o = {
connected: /* @__PURE__ */ new WeakSet(),
length_c: 0,
disconnected: /* @__PURE__ */ new WeakSet(),
length_d: 0
};
return e.set(o, s), s;
return e.set(c, o), o;
}
function f() {
t || (t = !0, n.observe(document.body, { childList: !0, subtree: !0 }));
}
function d() {
function a() {
!t || e.size || (t = !1, n.disconnect());
}
function c() {
return new Promise(function(o) {
(requestIdleCallback || requestAnimationFrame)(o);
function i() {
return new Promise(function(c) {
(requestIdleCallback || requestAnimationFrame)(c);
});
}
async function a(o) {
e.size > 30 && await c();
let s = [];
if (!(o instanceof Node))
return s;
for (let u of e.keys())
u === o || !(u instanceof Node) || o.contains(u) && s.push(u);
return s;
async function d(c) {
e.size > 30 && await i();
let o = [];
if (!(c instanceof Node))
return o;
for (let s of e.keys())
s === c || !(s instanceof Node) || c.contains(s) && o.push(s);
return o;
}
function l(o, s) {
let u = !1;
for (let p of o) {
if (s && a(p).then(l), !e.has(p))
function l(c, o) {
let s = !1;
for (let p of c) {
if (o && d(p).then(l), !e.has(p))
continue;
let v = e.get(p);
v.length_c && (p.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(p), u = !0);
v.length_c && (p.dispatchEvent(new Event("dde:connected")), v.connected = /* @__PURE__ */ new WeakSet(), v.length_c = 0, v.length_d || e.delete(p), s = !0);
}
return u;
return s;
}
function h(o, s) {
let u = !1;
for (let p of o)
s && a(p).then(h), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), u = !0);
return u;
function h(c, o) {
let s = !1;
for (let p of c)
o && d(p).then(h), !(!e.has(p) || !e.get(p).length_d) && (p.dispatchEvent(new Event("dde:disconnected")), e.delete(p), s = !0);
return s;
}
}