igniteui-react-grids
Version:
Ignite UI React grid components.
176 lines (175 loc) • 5.68 kB
JavaScript
import { createComponent as E } from "@lit/react";
import { noChange as S, html as R } from "lit";
import { createPortal as P } from "react-dom";
import { directive as U, AsyncDirective as M } from "lit/async-directive.js";
const T = "dataContext";
let j = !1;
function $(e) {
return new Proxy(e, {
get(t, n, o) {
return n === T ? (j || (j = !0, console.warn(
"dataContext is deprecated and template context props are now available as the root object and can be accessed directly"
)), t) : Reflect.get(t, n, o);
}
});
}
function f(e, t, n = /* @__PURE__ */ new WeakSet()) {
if (Object.is(e, t)) return !0;
if (w(e) && w(t)) {
if (e.constructor !== t.constructor) return !1;
if (n.has(e) && n.has(t))
return !0;
if (n.add(e), n.add(t), A(e) && A(t)) return e.source === t.source && e.flags === t.flags;
if (e instanceof Map && t instanceof Map) {
if (e.size !== t.size) return !1;
for (const [s, c] of e.entries()) {
let d = !1;
for (const [u, a] of t.entries())
if (f(s, u, n) && f(c, a, n)) {
d = !0;
break;
}
if (!d) return !1;
}
return !0;
}
if (e instanceof Set && t instanceof Set) {
if (e.size !== t.size) return !1;
for (const s of e) {
let c = !1;
for (const d of t)
if (f(s, d, n)) {
c = !0;
break;
}
if (!c) return !1;
}
return !0;
}
if (Array.isArray(e) && Array.isArray(t)) {
const s = e.length;
if (s !== t.length) return !1;
for (let c = 0; c < s; c++)
if (!f(e[c], t[c], n)) return !1;
return !0;
}
if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === t.valueOf();
if (e.toString !== Object.prototype.toString) return e.toString() === t.toString();
const o = Object.keys(e), h = Object.keys(t);
if (o.length !== h.length) return !1;
for (const s of o)
if (!Object.hasOwn(t, s)) return !1;
for (const s of o)
if (!f(e[s], t[s], n)) return !1;
return n.delete(e), n.delete(t), !0;
}
return !1;
}
function w(e) {
return e != null && typeof e == "object";
}
function A(e) {
return e != null && e.constructor === RegExp;
}
const g = Symbol("renderer-remove"), C = Symbol("not-set");
function v(e, t, n, o) {
return {
name: e,
data: t === g ? t : $(t),
slotName: o !== void 0 ? `${e}${o}` : e,
node: n
};
}
class b extends M {
constructor() {
super(...arguments), this._key = crypto.randomUUID(), this._part = null, this._callback = null, this._state = { previous: C, current: void 0 };
}
get _renderNode() {
return this._part?.deref()?.parentNode;
}
_shouldUpdateNG(t) {
return f(t.$implicit, this._state.previous) ? !1 : (this._state.previous = t.$implicit, !0);
}
_shouldUpdate() {
const t = this._state.current;
return Reflect.has(t, "implicit") ? this._shouldUpdateNG(t) : f(this._state.previous, t) ? !1 : (this._state.previous = t, !0);
}
render(t, n, o) {
return S;
}
update(t, [n, o, h]) {
return this._callback = n, this._name = o, this._state.current = h, this._part = new WeakRef(t), this.isConnected && this._callback && this._shouldUpdate() && this._callback(
v(this._name, this._state.current, this._renderNode, this._key)
), S;
}
disconnected() {
this._callback && (this._callback(
v(this._name, g, this._renderNode, this._key)
), this._callback = null, this._part = null, this._state = { previous: C, current: void 0 });
}
}
const z = U(b), F = ({
react: e,
tagName: t,
elementClass: n,
events: o,
displayName: h,
renderProps: s,
moveBackOnDelete: c
}) => {
if ("register" in n && n.register(), !s && !c)
return E({ react: e, tagName: t, elementClass: n, events: o, displayName: h });
o ??= {};
const d = E({ react: e, tagName: t, elementClass: n, events: o, displayName: h });
return e.forwardRef((u, a) => {
const p = e.useRef(/* @__PURE__ */ new Map()), i = e.useRef(null), y = e.useRef(null), [m, N] = e.useState(/* @__PURE__ */ new Map()), _ = {}, k = {};
c && e.useLayoutEffect(() => {
const r = y.current?.deref();
return r && r !== i.current.parentElement && (r.appendChild(i.current), y.current = null), () => {
const l = i.current?.ngElementStrategy?.parentElement?.deref();
l && l !== i.current.parentElement && (y.current = new WeakRef(i.current.parentElement), l.appendChild(i.current));
};
}, []);
const x = (r) => {
r.data === g ? m.delete(r.slotName) : m.set(
r.slotName,
P(k[r.name]?.(r.data), r.node, r.slotName)
), N(() => new Map(m));
};
if (s)
for (const r of p.current.keys())
u[r] === void 0 && p.current.delete(r);
s ??= {};
for (const r in u) {
const l = s[r];
if (l === void 0)
_[r] = u[r];
else if (k[l] = u[r], i.current && p.current.has(r))
_[r] = p.current.get(r);
else {
const O = D(x, l);
_[r] = O, p.current.set(r, O);
}
}
return p.current.size ? Object.assign(_, {
children: [...e.Children.toArray(u.children), ...m.values()]
}) : Object.assign(_, {
children: e.Children.toArray(u.children)
}), e.createElement(d, {
..._,
ref: e.useCallback(
(r) => {
i.current = r, typeof a == "function" ? a(r) : a !== null && (a.current = r);
},
[a]
)
});
});
};
function D(e, t) {
return (n) => R`${z(e, t, n)}`;
}
export {
F as createComponent
};
//# sourceMappingURL=template-renderer.js.map