UNPKG

@ea-lab/reactive-json

Version:

A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.

43 lines (42 loc) 1.24 kB
const f = "<reactive-json:event>", d = "<reactive-json:event-new-value>", s = (e) => { var n; if (e) { if (e instanceof CustomEvent) return (n = e == null ? void 0 : e.detail) == null ? void 0 : n.value; if (e.target) { const t = e.target; if (t.type === "checkbox") return t.checked; if (t.type === "radio") return t.checked ? t.value : void 0; if (typeof t.value < "u") return t.value; if (typeof t.checked < "u") return t.checked; } } }, o = (e, n) => { if (typeof e != "string") return e; let t; if (e.startsWith(d) && (t = d), e.startsWith(f) && (t = f), !t) return e; let i, r; if (t === d && (i = s(n), r = e.slice(d.length)), t === f && (i = n, r = e.slice(f.length)), r.startsWith(".") && (r = r.slice(1)), !r) return t === f ? void 0 : i; if (!(typeof i != "object" || !i)) return r.split(".").reduce((c, a) => c ? c[a] : void 0, i); }, u = (e, n) => { if (Array.isArray(e)) return e.map((t) => u(t, n)); if (e && typeof e == "object") { const t = {}; for (const [i, r] of Object.entries(e)) t[i] = u(r, n); return t; } return o(e, n); }; export { u as replaceEventPlaceholders };