From 06ab87c06f67b9ccc9bd76d0da14f13dce62dabf Mon Sep 17 00:00:00 2001 From: Jan Andrle Date: Fri, 13 Oct 2023 16:51:43 +0200 Subject: [PATCH] :sparkles: Add __dde_lifecycleToEvents flag to lifecycleToEvents --- dist/dde-with-signals.js | 80 ++++++++++++------------- dist/dde.js | 90 ++++++++++++++--------------- dist/esm-with-signals.js | 80 ++++++++++++------------- dist/esm.js | 90 ++++++++++++++--------------- examples/components/webComponent.js | 1 + src/events.js | 13 ++--- 6 files changed, 176 insertions(+), 178 deletions(-) diff --git a/dist/dde-with-signals.js b/dist/dde-with-signals.js index 5e989b1..b3e4242 100644 --- a/dist/dde-with-signals.js +++ b/dist/dde-with-signals.js @@ -1,7 +1,7 @@ //deka-dom-el library is available via global namespace `dde` (()=> { // src/signals-common.js - var y = { + var w = { isSignal(e) { return !1; }, @@ -10,10 +10,10 @@ } }; function N(e, t = !0) { - return t ? Object.assign(y, e) : (Object.setPrototypeOf(e, y), e); + return t ? Object.assign(w, e) : (Object.setPrototypeOf(e, w), e); } - function _(e) { - return y.isPrototypeOf(e) && e !== y ? e : y; + function x(e) { + return w.isPrototypeOf(e) && e !== w ? e : w; } // src/helpers.js @@ -34,8 +34,8 @@ } // src/dom-common.js - var W = { setDeleteAttr: H }; - function H(e, t, n) { + var T = { setDeleteAttr: k }; + function k(e, t, n) { if (Reflect.set(e, t, n), !!v(n)) { if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") return e.removeAttribute(t); @@ -45,12 +45,12 @@ } // src/dom.js - var S = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], M = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, E = { + var y = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], W = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, E = { get current() { - return S[S.length - 1]; + return y[y.length - 1]; }, get state() { - return [...S]; + return [...y]; }, get host() { return this.current.host; @@ -59,7 +59,7 @@ return this.current.namespace; }, set namespace(e) { - return this.current.namespace = M(e); + return this.current.namespace = W(e); }, elNamespace(e) { let t = this.namespace; @@ -70,14 +70,14 @@ }; }, push(e = {}) { - return e.namespace && (e.namespace = M(e.namespace)), S.push(Object.assign({}, this.current, e)); + return e.namespace && (e.namespace = W(e.namespace)), y.push(Object.assign({}, this.current, e)); }, pop() { - return S.pop(); + return y.pop(); } }; function ie(e, t, ...n) { - let r = this, o = _(this), { namespace: c } = E, a; + let r = this, o = x(this), { namespace: c } = E, a; switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) { case typeof e == "function": { E.push({ scope: e, host: (s) => s ? (n.unshift(s), void 0) : a }), a = e(t || void 0), E.pop(); @@ -97,9 +97,9 @@ } return n.forEach((s) => s(a)), a; } - var { setDeleteAttr: k } = W; + var { setDeleteAttr: M } = T; function O(e, ...t) { - let n = this, r = _(this); + let n = this, r = x(this); if (!t.length) return e; let c = (e instanceof SVGElement ? J : I).bind(null, e, "Attribute"); @@ -116,7 +116,7 @@ case "xlink:href": return c(s, d, "http://www.w3.org/1999/xlink"); case "textContent": - return k(e, s, d); + return M(e, s, d); case "style": if (typeof d != "object") break; @@ -127,11 +127,11 @@ case "classList": return B.call(n, e, d); } - return G(e, s) ? k(e, s, d) : c(s, d); + return G(e, s) ? M(e, s, d) : c(s, d); }), e; } function B(e, t) { - let n = _(this); + let n = x(this); return D( n, t, @@ -159,14 +159,14 @@ o && (c = e.processReactiveAttribute(t, o, c, (a) => n(...a)), n(o, c)); }); } - function T(e) { + function U(e) { return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; } function I(e, t, n, r) { - return e[(v(r) ? "remove" : "set") + t](n, T(r)); + return e[(v(r) ? "remove" : "set") + t](n, U(r)); } function J(e, t, n, r, o = null) { - return e[(v(r) ? "remove" : "set") + t + "NS"](o, n, T(r)); + return e[(v(r) ? "remove" : "set") + t + "NS"](o, n, U(r)); } function F(e, t, n) { if (Reflect.set(e, t, n), !!v(n)) @@ -178,31 +178,31 @@ let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); return e.dispatchEvent(r); } - function x(e, t, n) { + function S(e, t, n) { return function(o) { return o.addEventListener(e, t, n), o; }; } var R = Z(), V = /* @__PURE__ */ new WeakSet(); - x.connected = function(e, t) { + S.connected = function(e, t) { let n = "connected"; return typeof t != "object" && (t = {}), t.once = !0, function(o) { let c = "dde:" + n; - return o.addEventListener(c, e, t), typeof o[n + "Callback"] == "function" ? o : o.isConnected ? (o.dispatchEvent(new Event(c)), o) : (A(t.signal, () => R.offConnected(o, e)) && R.onConnected(o, e), o); + return o.addEventListener(c, e, t), o.__dde_lifecycleToEvents ? o : o.isConnected ? (o.dispatchEvent(new Event(c)), o) : (A(t.signal, () => R.offConnected(o, e)) && R.onConnected(o, e), o); }; }; - x.disconnected = function(e, t) { + S.disconnected = function(e, t) { let n = "disconnected"; return typeof t != "object" && (t = {}), t.once = !0, function(o) { let c = "dde:" + n; - return o.addEventListener(c, e, t), typeof o[n + "Callback"] == "function" || A(t.signal, () => R.offDisconnected(o, e)) && R.onDisconnected(o, e), o; + return o.addEventListener(c, e, t), o.__dde_lifecycleToEvents || A(t.signal, () => R.offDisconnected(o, e)) && R.onDisconnected(o, e), o; }; }; - x.attributeChanged = function(e, t) { + S.attributeChanged = function(e, t) { let n = "attributeChanged"; return typeof t != "object" && (t = {}), function(o) { let c = "dde:" + n; - if (o.addEventListener(c, e, t), typeof o[n + "Callback"] == "function" || V.has(o)) + if (o.addEventListener(c, e, t), o.__dde_lifecycleToEvents || V.has(o)) return o; let a = new MutationObserver(function(d) { for (let { attributeName: m, target: b } of d) @@ -287,8 +287,8 @@ for (let p of i) { if (u && d(p).then(m), !e.has(p)) continue; - let w = e.get(p); - w.length_c && (p.dispatchEvent(new Event("dde:connected")), w.connected = /* @__PURE__ */ new WeakSet(), w.length_c = 0, w.length_d || e.delete(p), f = !0); + let _ = e.get(p); + _.length_c && (p.dispatchEvent(new Event("dde:connected")), _.connected = /* @__PURE__ */ new WeakSet(), _.length_c = 0, _.length_d || e.delete(p), f = !0); } return f; } @@ -320,10 +320,10 @@ var g = /* @__PURE__ */ new WeakMap(); function h(e, t) { if (typeof e != "function") - return U(e, t); + return $(e, t); if (C(e)) return e; - let n = U(""), r = () => n(e()); + let n = $(""), r = () => n(e()); return g.set(r, /* @__PURE__ */ new Set([n])), X(r), n; } h.action = function(e, t, ...n) { @@ -339,7 +339,7 @@ if (!(o && o.aborted)) { if (Array.isArray(t)) return t.forEach((c) => e(c, n, r)); - P(t, n), o && o.addEventListener("abort", () => q(t, n)); + P(t, n), o && o.addEventListener("abort", () => H(t, n)); } }; h.symbols = { @@ -352,7 +352,7 @@ o.abort(); } }); - return E.host(x.attributeChanged(function({ detail: a }) { + return E.host(S.attributeChanged(function({ detail: a }) { let [s, d] = a; s === e && c(d); }, { signal: o.signal })), c; @@ -377,7 +377,7 @@ o.append(n, r); let c = (a) => { if (!n.parentNode || !r.parentNode) - return q(e, c); + return H(e, c); let s = t(a); Array.isArray(s) || (s = [s]); let d = n; @@ -387,13 +387,13 @@ }; return P(e, c), c(e()), o; }; - var $ = { + var q = { isSignal: C, processReactiveAttribute(e, t, n, r) { return C(n) ? (P(n, (o) => r([t, o])), n()) : n; } }; - function U(e, t) { + function $(e, t) { let n = (...r) => r.length ? te(n, ...r) : ee(n); return Q(n, e, t); } @@ -436,13 +436,13 @@ if (e[l]) return e[l].listeners.add(t); } - function q(e, t) { + function H(e, t) { if (e[l]) return e[l].listeners.delete(t); } // signals.js - N($); + N(q); globalThis.dde= { S: h, @@ -453,7 +453,7 @@ el: ie, empty: fe, isSignal: C, - on: x, + on: S, registerReactivity: N, scope: E }; diff --git a/dist/dde.js b/dist/dde.js index 52ead9d..adf121c 100644 --- a/dist/dde.js +++ b/dist/dde.js @@ -1,7 +1,7 @@ //deka-dom-el library is available via global namespace `dde` (()=> { // src/signals-common.js - var b = { + var m = { isSignal(e) { return !1; }, @@ -10,17 +10,17 @@ } }; function P(e, t = !0) { - return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e); + return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e); } - function E(e) { - return b.isPrototypeOf(e) && e !== b ? e : b; + function b(e) { + return m.isPrototypeOf(e) && e !== m ? e : m; } // src/helpers.js function g(e) { return typeof e > "u"; } - function w(e, t) { + function _(e, t) { if (!e || !(e instanceof AbortSignal)) return !0; if (!e.aborted) @@ -30,7 +30,7 @@ } // src/dom-common.js - var y = { setDeleteAttr: j }; + var C = { setDeleteAttr: j }; function j(e, t, n) { if (Reflect.set(e, t, n), !!g(n)) { if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") @@ -41,12 +41,12 @@ } // src/dom.js - var m = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], R = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, _ = { + var E = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], R = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, x = { get current() { - return m[m.length - 1]; + return E[E.length - 1]; }, get state() { - return [...m]; + return [...E]; }, get host() { return this.current.host; @@ -61,44 +61,44 @@ let t = this.namespace; return this.namespace = e, { append(...n) { - return _.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n); + return x.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n); } }; }, push(e = {}) { - return e.namespace && (e.namespace = R(e.namespace)), m.push(Object.assign({}, this.current, e)); + return e.namespace && (e.namespace = R(e.namespace)), E.push(Object.assign({}, this.current, e)); }, pop() { - return m.pop(); + return E.pop(); } }; function V(e, t, ...n) { - let s = this, r = E(this), { namespace: f } = _, a; + let s = this, r = b(this), { namespace: f } = x, a; switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { case typeof e == "function": { - _.push({ scope: e, host: (u) => u ? (n.unshift(u), void 0) : a }), a = e(t || void 0), _.pop(); + x.push({ scope: e, host: (u) => u ? (n.unshift(u), void 0) : a }), a = e(t || void 0), x.pop(); break; } case e === "#text": - a = x.call(s, document.createTextNode(""), t); + a = w.call(s, document.createTextNode(""), t); break; case e === "<>": - a = x.call(s, document.createDocumentFragment(), t); + a = w.call(s, document.createDocumentFragment(), t); break; case f !== "html": - a = x.call(s, document.createElementNS(f, e), t); + a = w.call(s, document.createElementNS(f, e), t); break; case !a: - a = x.call(s, document.createElement(e), t); + a = w.call(s, document.createElement(e), t); } return n.forEach((u) => u(a)), a; } - var { setDeleteAttr: S } = y; - function x(e, ...t) { - let n = this, s = E(this); + var { setDeleteAttr: S } = C; + function w(e, ...t) { + let n = this, s = b(this); if (!t.length) return e; - let f = (e instanceof SVGElement ? T : F).bind(null, e, "Attribute"); + let f = (e instanceof SVGElement ? F : W).bind(null, e, "Attribute"); return Object.entries(Object.assign({}, ...t)).forEach(function a([u, d]) { d = s.processReactiveAttribute(e, u, d, a); let [h] = u; @@ -117,18 +117,18 @@ if (typeof d != "object") break; case "dataset": - return C(s, d, L.bind(null, e[u])); + return O(s, d, L.bind(null, e[u])); case "ariaset": - return C(s, d, (l, c) => f("aria-" + l, c)); + return O(s, d, (l, c) => f("aria-" + l, c)); case "classList": - return M.call(n, e, d); + return T.call(n, e, d); } - return W(e, u) ? S(e, u, d) : f(u, d); + return M(e, u) ? S(e, u, d) : f(u, d); }), e; } - function M(e, t) { - let n = E(this); - return C( + function T(e, t) { + let n = b(this); + return O( n, t, (s, r) => e.classList.toggle(s, r === -1 ? void 0 : !!r) @@ -137,7 +137,7 @@ function $(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } - function W(e, t) { + function M(e, t) { if (!Reflect.has(e, t)) return !1; let n = D(e, t); @@ -149,7 +149,7 @@ let n = Object.getOwnPropertyDescriptor(e, t); return n || D(e, t); } - function C(e, t, n) { + 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, (a) => n(...a)), n(r, f)); @@ -158,10 +158,10 @@ function N(e) { return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; } - function F(e, t, n, s) { + function W(e, t, n, s) { return e[(g(s) ? "remove" : "set") + t](n, N(s)); } - function T(e, t, n, s, r = null) { + function F(e, t, n, s, r = null) { return e[(g(s) ? "remove" : "set") + t + "NS"](r, n, N(s)); } function L(e, t, n) { @@ -174,31 +174,31 @@ let s = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); return e.dispatchEvent(s); } - function O(e, t, n) { + function y(e, t, n) { return function(r) { return r.addEventListener(e, t, n), r; }; } var A = q(), U = /* @__PURE__ */ new WeakSet(); - O.connected = function(e, t) { + y.connected = function(e, t) { let n = "connected"; return typeof t != "object" && (t = {}), t.once = !0, function(r) { let f = "dde:" + n; - return r.addEventListener(f, e, t), typeof r[n + "Callback"] == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event(f)), r) : (w(t.signal, () => A.offConnected(r, e)) && A.onConnected(r, e), r); + return r.addEventListener(f, e, t), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(f)), r) : (_(t.signal, () => A.offConnected(r, e)) && A.onConnected(r, e), r); }; }; - O.disconnected = function(e, t) { + y.disconnected = function(e, t) { let n = "disconnected"; return typeof t != "object" && (t = {}), t.once = !0, function(r) { let f = "dde:" + n; - return r.addEventListener(f, e, t), typeof r[n + "Callback"] == "function" || w(t.signal, () => A.offDisconnected(r, e)) && A.onDisconnected(r, e), r; + return r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || _(t.signal, () => A.offDisconnected(r, e)) && A.onDisconnected(r, e), r; }; }; - O.attributeChanged = function(e, t) { + y.attributeChanged = function(e, t) { let n = "attributeChanged"; return typeof t != "object" && (t = {}), function(r) { let f = "dde:" + n; - if (r.addEventListener(f, e, t), typeof r[n + "Callback"] == "function" || U.has(r)) + if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || U.has(r)) return r; let a = new MutationObserver(function(d) { for (let { attributeName: h, target: l } of d) @@ -206,7 +206,7 @@ new CustomEvent(f, { detail: [h, l.getAttribute(h)] }) ); }); - return w(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r; + return _(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r; }; }; function q() { @@ -305,15 +305,15 @@ }); globalThis.dde= { - assign: x, - classListDeclarative: M, + assign: w, + classListDeclarative: T, createElement: V, dispatchEvent: Q, el: V, empty: $, - on: O, + on: y, registerReactivity: P, - scope: _ + scope: x }; })(); \ No newline at end of file diff --git a/dist/esm-with-signals.js b/dist/esm-with-signals.js index 8ec264f..302903d 100644 --- a/dist/esm-with-signals.js +++ b/dist/esm-with-signals.js @@ -1,5 +1,5 @@ // src/signals-common.js -var y = { +var w = { isSignal(e) { return !1; }, @@ -8,10 +8,10 @@ var y = { } }; function N(e, t = !0) { - return t ? Object.assign(y, e) : (Object.setPrototypeOf(e, y), e); + return t ? Object.assign(w, e) : (Object.setPrototypeOf(e, w), e); } -function _(e) { - return y.isPrototypeOf(e) && e !== y ? e : y; +function x(e) { + return w.isPrototypeOf(e) && e !== w ? e : w; } // src/helpers.js @@ -32,8 +32,8 @@ function A(e, t) { } // src/dom-common.js -var W = { setDeleteAttr: H }; -function H(e, t, n) { +var T = { setDeleteAttr: k }; +function k(e, t, n) { if (Reflect.set(e, t, n), !!v(n)) { if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") return e.removeAttribute(t); @@ -43,12 +43,12 @@ function H(e, t, n) { } // src/dom.js -var S = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], M = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, E = { +var y = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], W = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, E = { get current() { - return S[S.length - 1]; + return y[y.length - 1]; }, get state() { - return [...S]; + return [...y]; }, get host() { return this.current.host; @@ -57,7 +57,7 @@ var S = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document. return this.current.namespace; }, set namespace(e) { - return this.current.namespace = M(e); + return this.current.namespace = W(e); }, elNamespace(e) { let t = this.namespace; @@ -68,14 +68,14 @@ var S = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document. }; }, push(e = {}) { - return e.namespace && (e.namespace = M(e.namespace)), S.push(Object.assign({}, this.current, e)); + return e.namespace && (e.namespace = W(e.namespace)), y.push(Object.assign({}, this.current, e)); }, pop() { - return S.pop(); + return y.pop(); } }; function ie(e, t, ...n) { - let r = this, o = _(this), { namespace: c } = E, a; + let r = this, o = x(this), { namespace: c } = E, a; switch ((Object(t) !== t || o.isSignal(t)) && (t = { textContent: t }), !0) { case typeof e == "function": { E.push({ scope: e, host: (s) => s ? (n.unshift(s), void 0) : a }), a = e(t || void 0), E.pop(); @@ -95,9 +95,9 @@ function ie(e, t, ...n) { } return n.forEach((s) => s(a)), a; } -var { setDeleteAttr: k } = W; +var { setDeleteAttr: M } = T; function O(e, ...t) { - let n = this, r = _(this); + let n = this, r = x(this); if (!t.length) return e; let c = (e instanceof SVGElement ? J : I).bind(null, e, "Attribute"); @@ -114,7 +114,7 @@ function O(e, ...t) { case "xlink:href": return c(s, d, "http://www.w3.org/1999/xlink"); case "textContent": - return k(e, s, d); + return M(e, s, d); case "style": if (typeof d != "object") break; @@ -125,11 +125,11 @@ function O(e, ...t) { case "classList": return B.call(n, e, d); } - return G(e, s) ? k(e, s, d) : c(s, d); + return G(e, s) ? M(e, s, d) : c(s, d); }), e; } function B(e, t) { - let n = _(this); + let n = x(this); return D( n, t, @@ -157,14 +157,14 @@ function D(e, t, n) { o && (c = e.processReactiveAttribute(t, o, c, (a) => n(...a)), n(o, c)); }); } -function T(e) { +function U(e) { return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; } function I(e, t, n, r) { - return e[(v(r) ? "remove" : "set") + t](n, T(r)); + return e[(v(r) ? "remove" : "set") + t](n, U(r)); } function J(e, t, n, r, o = null) { - return e[(v(r) ? "remove" : "set") + t + "NS"](o, n, T(r)); + return e[(v(r) ? "remove" : "set") + t + "NS"](o, n, U(r)); } function F(e, t, n) { if (Reflect.set(e, t, n), !!v(n)) @@ -176,31 +176,31 @@ function le(e, t, ...n) { let r = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); return e.dispatchEvent(r); } -function x(e, t, n) { +function S(e, t, n) { return function(o) { return o.addEventListener(e, t, n), o; }; } var R = Z(), V = /* @__PURE__ */ new WeakSet(); -x.connected = function(e, t) { +S.connected = function(e, t) { let n = "connected"; return typeof t != "object" && (t = {}), t.once = !0, function(o) { let c = "dde:" + n; - return o.addEventListener(c, e, t), typeof o[n + "Callback"] == "function" ? o : o.isConnected ? (o.dispatchEvent(new Event(c)), o) : (A(t.signal, () => R.offConnected(o, e)) && R.onConnected(o, e), o); + return o.addEventListener(c, e, t), o.__dde_lifecycleToEvents ? o : o.isConnected ? (o.dispatchEvent(new Event(c)), o) : (A(t.signal, () => R.offConnected(o, e)) && R.onConnected(o, e), o); }; }; -x.disconnected = function(e, t) { +S.disconnected = function(e, t) { let n = "disconnected"; return typeof t != "object" && (t = {}), t.once = !0, function(o) { let c = "dde:" + n; - return o.addEventListener(c, e, t), typeof o[n + "Callback"] == "function" || A(t.signal, () => R.offDisconnected(o, e)) && R.onDisconnected(o, e), o; + return o.addEventListener(c, e, t), o.__dde_lifecycleToEvents || A(t.signal, () => R.offDisconnected(o, e)) && R.onDisconnected(o, e), o; }; }; -x.attributeChanged = function(e, t) { +S.attributeChanged = function(e, t) { let n = "attributeChanged"; return typeof t != "object" && (t = {}), function(o) { let c = "dde:" + n; - if (o.addEventListener(c, e, t), typeof o[n + "Callback"] == "function" || V.has(o)) + if (o.addEventListener(c, e, t), o.__dde_lifecycleToEvents || V.has(o)) return o; let a = new MutationObserver(function(d) { for (let { attributeName: m, target: b } of d) @@ -285,8 +285,8 @@ function Z() { for (let p of i) { if (u && d(p).then(m), !e.has(p)) continue; - let w = e.get(p); - w.length_c && (p.dispatchEvent(new Event("dde:connected")), w.connected = /* @__PURE__ */ new WeakSet(), w.length_c = 0, w.length_d || e.delete(p), f = !0); + let _ = e.get(p); + _.length_c && (p.dispatchEvent(new Event("dde:connected")), _.connected = /* @__PURE__ */ new WeakSet(), _.length_c = 0, _.length_d || e.delete(p), f = !0); } return f; } @@ -318,10 +318,10 @@ function C(e) { var g = /* @__PURE__ */ new WeakMap(); function h(e, t) { if (typeof e != "function") - return U(e, t); + return $(e, t); if (C(e)) return e; - let n = U(""), r = () => n(e()); + let n = $(""), r = () => n(e()); return g.set(r, /* @__PURE__ */ new Set([n])), X(r), n; } h.action = function(e, t, ...n) { @@ -337,7 +337,7 @@ h.on = function e(t, n, r = {}) { if (!(o && o.aborted)) { if (Array.isArray(t)) return t.forEach((c) => e(c, n, r)); - P(t, n), o && o.addEventListener("abort", () => q(t, n)); + P(t, n), o && o.addEventListener("abort", () => H(t, n)); } }; h.symbols = { @@ -350,7 +350,7 @@ h.attribute = function(e, t = void 0) { o.abort(); } }); - return E.host(x.attributeChanged(function({ detail: a }) { + return E.host(S.attributeChanged(function({ detail: a }) { let [s, d] = a; s === e && c(d); }, { signal: o.signal })), c; @@ -375,7 +375,7 @@ h.el = function(e, t) { o.append(n, r); let c = (a) => { if (!n.parentNode || !r.parentNode) - return q(e, c); + return H(e, c); let s = t(a); Array.isArray(s) || (s = [s]); let d = n; @@ -385,13 +385,13 @@ h.el = function(e, t) { }; return P(e, c), c(e()), o; }; -var $ = { +var q = { isSignal: C, processReactiveAttribute(e, t, n, r) { return C(n) ? (P(n, (o) => r([t, o])), n()) : n; } }; -function U(e, t) { +function $(e, t) { let n = (...r) => r.length ? te(n, ...r) : ee(n); return Q(n, e, t); } @@ -434,13 +434,13 @@ function P(e, t) { if (e[l]) return e[l].listeners.add(t); } -function q(e, t) { +function H(e, t) { if (e[l]) return e[l].listeners.delete(t); } // signals.js -N($); +N(q); export { h as S, O as assign, @@ -450,7 +450,7 @@ export { ie as el, fe as empty, C as isSignal, - x as on, + S as on, N as registerReactivity, E as scope }; diff --git a/dist/esm.js b/dist/esm.js index 557e690..ff31ea1 100644 --- a/dist/esm.js +++ b/dist/esm.js @@ -1,5 +1,5 @@ // src/signals-common.js -var b = { +var m = { isSignal(e) { return !1; }, @@ -8,17 +8,17 @@ var b = { } }; function P(e, t = !0) { - return t ? Object.assign(b, e) : (Object.setPrototypeOf(e, b), e); + return t ? Object.assign(m, e) : (Object.setPrototypeOf(e, m), e); } -function E(e) { - return b.isPrototypeOf(e) && e !== b ? e : b; +function b(e) { + return m.isPrototypeOf(e) && e !== m ? e : m; } // src/helpers.js function g(e) { return typeof e > "u"; } -function w(e, t) { +function _(e, t) { if (!e || !(e instanceof AbortSignal)) return !0; if (!e.aborted) @@ -28,7 +28,7 @@ function w(e, t) { } // src/dom-common.js -var y = { setDeleteAttr: j }; +var C = { setDeleteAttr: j }; function j(e, t, n) { if (Reflect.set(e, t, n), !!g(n)) { if (Reflect.deleteProperty(e, t), e instanceof HTMLElement && e.getAttribute(t) === "undefined") @@ -39,12 +39,12 @@ function j(e, t, n) { } // src/dom.js -var m = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], R = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, _ = { +var E = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document.body) : document.body }], R = (e) => e === "svg" ? "http://www.w3.org/2000/svg" : e, x = { get current() { - return m[m.length - 1]; + return E[E.length - 1]; }, get state() { - return [...m]; + return [...E]; }, get host() { return this.current.host; @@ -59,44 +59,44 @@ var m = [{ scope: document.body, namespace: "html", host: (e) => e ? e(document. let t = this.namespace; return this.namespace = e, { append(...n) { - return _.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n); + return x.namespace = t, n.length === 1 ? n[0] : document.createDocumentFragment().append(...n); } }; }, push(e = {}) { - return e.namespace && (e.namespace = R(e.namespace)), m.push(Object.assign({}, this.current, e)); + return e.namespace && (e.namespace = R(e.namespace)), E.push(Object.assign({}, this.current, e)); }, pop() { - return m.pop(); + return E.pop(); } }; function V(e, t, ...n) { - let s = this, r = E(this), { namespace: f } = _, a; + let s = this, r = b(this), { namespace: f } = x, a; switch ((Object(t) !== t || r.isSignal(t)) && (t = { textContent: t }), !0) { case typeof e == "function": { - _.push({ scope: e, host: (u) => u ? (n.unshift(u), void 0) : a }), a = e(t || void 0), _.pop(); + x.push({ scope: e, host: (u) => u ? (n.unshift(u), void 0) : a }), a = e(t || void 0), x.pop(); break; } case e === "#text": - a = x.call(s, document.createTextNode(""), t); + a = w.call(s, document.createTextNode(""), t); break; case e === "<>": - a = x.call(s, document.createDocumentFragment(), t); + a = w.call(s, document.createDocumentFragment(), t); break; case f !== "html": - a = x.call(s, document.createElementNS(f, e), t); + a = w.call(s, document.createElementNS(f, e), t); break; case !a: - a = x.call(s, document.createElement(e), t); + a = w.call(s, document.createElement(e), t); } return n.forEach((u) => u(a)), a; } -var { setDeleteAttr: S } = y; -function x(e, ...t) { - let n = this, s = E(this); +var { setDeleteAttr: S } = C; +function w(e, ...t) { + let n = this, s = b(this); if (!t.length) return e; - let f = (e instanceof SVGElement ? T : F).bind(null, e, "Attribute"); + let f = (e instanceof SVGElement ? F : W).bind(null, e, "Attribute"); return Object.entries(Object.assign({}, ...t)).forEach(function a([u, d]) { d = s.processReactiveAttribute(e, u, d, a); let [h] = u; @@ -115,18 +115,18 @@ function x(e, ...t) { if (typeof d != "object") break; case "dataset": - return C(s, d, L.bind(null, e[u])); + return O(s, d, L.bind(null, e[u])); case "ariaset": - return C(s, d, (l, c) => f("aria-" + l, c)); + return O(s, d, (l, c) => f("aria-" + l, c)); case "classList": - return M.call(n, e, d); + return T.call(n, e, d); } - return W(e, u) ? S(e, u, d) : f(u, d); + return M(e, u) ? S(e, u, d) : f(u, d); }), e; } -function M(e, t) { - let n = E(this); - return C( +function T(e, t) { + let n = b(this); + return O( n, t, (s, r) => e.classList.toggle(s, r === -1 ? void 0 : !!r) @@ -135,7 +135,7 @@ function M(e, t) { function $(e) { return Array.from(e.children).forEach((t) => t.remove()), e; } -function W(e, t) { +function M(e, t) { if (!Reflect.has(e, t)) return !1; let n = D(e, t); @@ -147,7 +147,7 @@ function D(e, t) { let n = Object.getOwnPropertyDescriptor(e, t); return n || D(e, t); } -function C(e, t, n) { +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, (a) => n(...a)), n(r, f)); @@ -156,10 +156,10 @@ function C(e, t, n) { function N(e) { return Array.isArray(e) ? e.filter(Boolean).join(" ") : e; } -function F(e, t, n, s) { +function W(e, t, n, s) { return e[(g(s) ? "remove" : "set") + t](n, N(s)); } -function T(e, t, n, s, r = null) { +function F(e, t, n, s, r = null) { return e[(g(s) ? "remove" : "set") + t + "NS"](r, n, N(s)); } function L(e, t, n) { @@ -172,31 +172,31 @@ function Q(e, t, ...n) { let s = n.length ? new CustomEvent(t, { detail: n[0] }) : new Event(t); return e.dispatchEvent(s); } -function O(e, t, n) { +function y(e, t, n) { return function(r) { return r.addEventListener(e, t, n), r; }; } var A = q(), U = /* @__PURE__ */ new WeakSet(); -O.connected = function(e, t) { +y.connected = function(e, t) { let n = "connected"; return typeof t != "object" && (t = {}), t.once = !0, function(r) { let f = "dde:" + n; - return r.addEventListener(f, e, t), typeof r[n + "Callback"] == "function" ? r : r.isConnected ? (r.dispatchEvent(new Event(f)), r) : (w(t.signal, () => A.offConnected(r, e)) && A.onConnected(r, e), r); + return r.addEventListener(f, e, t), r.__dde_lifecycleToEvents ? r : r.isConnected ? (r.dispatchEvent(new Event(f)), r) : (_(t.signal, () => A.offConnected(r, e)) && A.onConnected(r, e), r); }; }; -O.disconnected = function(e, t) { +y.disconnected = function(e, t) { let n = "disconnected"; return typeof t != "object" && (t = {}), t.once = !0, function(r) { let f = "dde:" + n; - return r.addEventListener(f, e, t), typeof r[n + "Callback"] == "function" || w(t.signal, () => A.offDisconnected(r, e)) && A.onDisconnected(r, e), r; + return r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || _(t.signal, () => A.offDisconnected(r, e)) && A.onDisconnected(r, e), r; }; }; -O.attributeChanged = function(e, t) { +y.attributeChanged = function(e, t) { let n = "attributeChanged"; return typeof t != "object" && (t = {}), function(r) { let f = "dde:" + n; - if (r.addEventListener(f, e, t), typeof r[n + "Callback"] == "function" || U.has(r)) + if (r.addEventListener(f, e, t), r.__dde_lifecycleToEvents || U.has(r)) return r; let a = new MutationObserver(function(d) { for (let { attributeName: h, target: l } of d) @@ -204,7 +204,7 @@ O.attributeChanged = function(e, t) { new CustomEvent(f, { detail: [h, l.getAttribute(h)] }) ); }); - return w(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r; + return _(t.signal, () => a.disconnect()) && a.observe(r, { attributes: !0 }), r; }; }; function q() { @@ -302,13 +302,13 @@ function q() { }; }); export { - x as assign, - M as classListDeclarative, + w as assign, + T as classListDeclarative, V as createElement, Q as dispatchEvent, V as el, $ as empty, - O as on, + y as on, P as registerReactivity, - _ as scope + x as scope }; diff --git a/examples/components/webComponent.js b/examples/components/webComponent.js index 45104de..5232a3d 100644 --- a/examples/components/webComponent.js +++ b/examples/components/webComponent.js @@ -74,6 +74,7 @@ function lifecycleToEvents(class_declaration){ })); target.apply(thisArg, detail); }); + class_declaration.prototype.__dde_lifecycleToEvents= true; } function wrapMethod(obj, method, apply){ obj[method]= new Proxy(obj[method] || (()=> {}), { apply }); diff --git a/src/events.js b/src/events.js index 5f45be8..95f1986 100644 --- a/src/events.js +++ b/src/events.js @@ -23,11 +23,8 @@ on.connected= function(listener, options){ return function registerElement(element){ const event= "dde:"+name; element.addEventListener(event, listener, options); - if(typeof element[name+"Callback"] === "function") return element; - if(element.isConnected){ - element.dispatchEvent(new Event(event)); - return element; - } + if(element.__dde_lifecycleToEvents) return element; + if(element.isConnected) return ( element.dispatchEvent(new Event(event)), element ) const c= onAbort(options.signal, ()=> c_ch_o.offConnected(element, listener)); if(c) c_ch_o.onConnected(element, listener); @@ -42,7 +39,7 @@ on.disconnected= function(listener, options){ return function registerElement(element){ const event= "dde:"+name; element.addEventListener(event, listener, options); - if(typeof element[name+"Callback"] === "function") return element; + if(element.__dde_lifecycleToEvents) return element; const c= onAbort(options.signal, ()=> c_ch_o.offDisconnected(element, listener)); if(c) c_ch_o.onDisconnected(element, listener); @@ -56,8 +53,8 @@ on.attributeChanged= function(listener, options){ return function registerElement(element){ const event= "dde:"+name; element.addEventListener(event, listener, options); - if(typeof element[name+"Callback"] === "function") return element; - if(els_attribute_store.has(element)) return element; + if(element.__dde_lifecycleToEvents || els_attribute_store.has(element)) + return element; const observer= new MutationObserver(function(mutations){ for(const { attributeName, target } of mutations)