@uploadcare/react-adapter
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
const w = /* @__PURE__ */ new Set([ | ||
const P = /* @__PURE__ */ new Set([ | ||
"children", | ||
@@ -6,73 +6,71 @@ "ref", | ||
"className" | ||
]), g = (e = {}) => Object == null ? void 0 : Object.keys(e).reduce((n, s) => { | ||
]), w = (e = {}) => Object == null ? void 0 : Object.keys(e).reduce((r, s) => { | ||
var t, c; | ||
const o = e == null ? void 0 : e[s], r = `on${(c = (t = o == null ? void 0 : o.split("-")) == null ? void 0 : t.map((a) => a.charAt(0).toUpperCase() + a.slice(1))) == null ? void 0 : c.join("")}`; | ||
return n[r] = o, n; | ||
}, {}), E = /* @__PURE__ */ new WeakMap(), v = (e) => { | ||
let n = E.get(e); | ||
return n || (n = /* @__PURE__ */ new Map(), E.set(e, n)), n; | ||
}, d = ({ | ||
const o = e == null ? void 0 : e[s], n = `on${(c = (t = o == null ? void 0 : o.split("-")) == null ? void 0 : t.map((i) => i.charAt(0).toUpperCase() + i.slice(1))) == null ? void 0 : c.join("")}`; | ||
return r[n] = o, r; | ||
}, {}), m = /* @__PURE__ */ new WeakMap(), g = (e) => { | ||
let r = m.get(e); | ||
return r === void 0 && (r = /* @__PURE__ */ new Map(), m.set(e, r)), r; | ||
}, E = ({ | ||
node: e, | ||
nameProp: n, | ||
nameProp: r, | ||
valueProp: s, | ||
prevValueProp: o, | ||
event: r | ||
event: n | ||
}) => { | ||
if (r !== void 0 && s !== o) { | ||
const t = v(e), c = t.has(r); | ||
if (s) { | ||
const a = { | ||
handleEvent: s | ||
}; | ||
c || e.addEventListener(r, a), t.set(r, a); | ||
} else if (c) { | ||
const a = t.get(r); | ||
e.removeEventListener(r, a), t.delete(r); | ||
if (n !== void 0) { | ||
if (s !== o) { | ||
const t = g(e), c = t.has(n); | ||
let i = t.get(n); | ||
s !== void 0 ? c ? i.handleEvent = s : (i = { handleEvent: s }, t.set(n, i), e.addEventListener( | ||
n, | ||
(a) => i.handleEvent(a.detail) | ||
)) : c && (t.delete(n), e.removeEventListener(n, i)); | ||
} | ||
return; | ||
} | ||
e[n] = s, s == null && n in HTMLElement.prototype && e.removeAttribute(n); | ||
}, M = (e, n, s) => { | ||
const o = {}, r = {}; | ||
e[r] = s, s == null && r in HTMLElement.prototype && e.removeAttribute(r); | ||
}, M = (e, r, s) => { | ||
const o = {}, n = {}; | ||
return Object.entries(e).forEach(([t, c]) => { | ||
w.has(t) ? o[t === "className" ? "class" : t] = c : n.has(t) || t in s.prototype ? r[t] = c : o[t] = c; | ||
}), { reactProps: o, customElProps: r }; | ||
P.has(t) ? o[t === "className" ? "class" : t] = c : r.has(t) || t in s.prototype ? n[t] = c : o[t] = c; | ||
}), { reactProps: o, customElProps: n }; | ||
}, b = ({ | ||
react: e, | ||
// https://react.dev/warnings/invalid-hook-call-warning | ||
tag: n, | ||
tag: r, | ||
elClass: s, | ||
schemaEvents: o | ||
}) => { | ||
const r = g(o), t = new Set(Object.keys(r ?? {})), c = e.forwardRef( | ||
(a, l) => { | ||
const f = e.useRef(/* @__PURE__ */ new Map()), p = e.useRef(null), { reactProps: h, customElProps: m } = M(a, t, s); | ||
const n = w(o), t = new Set(Object.keys(n ?? {})), c = e.forwardRef( | ||
(i, a) => { | ||
const f = e.useRef(/* @__PURE__ */ new Map()), p = e.useRef(null), { reactProps: h, customElProps: d } = M(i, t, s); | ||
return e.useLayoutEffect(() => { | ||
if (p.current === null) | ||
return; | ||
const i = /* @__PURE__ */ new Map(); | ||
for (const u in m) | ||
d({ | ||
const u = /* @__PURE__ */ new Map(); | ||
for (const l in d) | ||
E({ | ||
node: p.current, | ||
nameProp: u, | ||
valueProp: m[u], | ||
prevValueProp: f.current.get(u), | ||
event: r[u] | ||
}), f.current.delete(u), i.set(u, a[u]); | ||
for (const [u, P] of f.current) | ||
d({ | ||
nameProp: l, | ||
valueProp: d[l], | ||
prevValueProp: f.current.get(l), | ||
event: n[l] | ||
}), f.current.delete(l), u.set(l, i[l]); | ||
for (const [l, v] of f.current) | ||
E({ | ||
node: p.current, | ||
nameProp: u, | ||
nameProp: l, | ||
valueProp: void 0, | ||
prevValueProp: P, | ||
event: r[u] | ||
prevValueProp: v, | ||
event: n[l] | ||
}); | ||
f.current = i; | ||
}), e.createElement(n ?? s.__tag, { | ||
f.current = u; | ||
}), e.createElement(r ?? s.__tag, { | ||
...h, | ||
ref: e.useCallback( | ||
(i) => { | ||
p.current = i, typeof l == "function" ? l(i) : l !== null && (l.current = i); | ||
(u) => { | ||
p.current = u, typeof a == "function" ? a(u) : a !== null && (a.current = u); | ||
}, | ||
[l] | ||
[a] | ||
) | ||
@@ -79,0 +77,0 @@ }); |
{ | ||
"name": "@uploadcare/react-adapter", | ||
"version": "0.2.0-alpha.0", | ||
"version": "0.2.0-alpha.1", | ||
"private": false, | ||
@@ -29,4 +29,3 @@ "type": "module", | ||
"access": "public" | ||
}, | ||
"gitHead": "0527f20642f400a30e9b43374527596d9c19eef4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
7387
-26.85%5
-28.57%1
Infinity%101
-8.18%