@ea-lab/reactive-json
Version:
A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.
79 lines (78 loc) • 2.4 kB
JavaScript
import { jsx as a } from "react/jsx-runtime";
import { useContext as b } from "react";
import { isValid as P } from "../../../engine/Actions.js";
import { GlobalDataContext as D } from "../../../engine/GlobalDataContext.js";
import { TemplateContext as x } from "../../../engine/TemplateContext.js";
import { View as v } from "../../../engine/View.js";
const W = (t) => {
var u, f;
const o = b(D), e = b(x), n = { globalDataContext: o, templateContext: e }, { contextToFilter: l = "global", filters: y = [] } = t.props, s = (p) => {
if (!p)
return !0;
for (const r of y) {
const m = (r == null ? void 0 : r.subjectsWithProperty) ?? void 0;
if (!m || !p.hasOwnProperty(m))
continue;
if (!P(r, n, /* @__PURE__ */ new Map([
[
"whenFilterableData",
({ condition: C }) => {
const w = C.whenFilterableData.split(".");
let i = p;
for (const h of w) {
const d = parseInt(h);
if (i = i[isNaN(d) ? h : d], i === void 0)
return;
}
return i;
}
]
])))
return !1;
}
return !0;
};
switch (l) {
case "template":
return e.templateData = c(e.templateData, s), e.templatePath = t.path, /* @__PURE__ */ a(x.Provider, { value: e, children: /* @__PURE__ */ a(
v,
{
props: t.props.content,
path: t.path + ".content",
datafield: "content",
currentData: ((u = t.currentData) == null ? void 0 : u.content) ?? void 0
}
) });
case "global":
default:
return o.templateData = c(o.templateData, s), /* @__PURE__ */ a(D.Provider, { value: o, children: /* @__PURE__ */ a(
v,
{
props: t.props.content,
path: t.path + ".content",
datafield: "content",
currentData: ((f = t.currentData) == null ? void 0 : f.content) ?? void 0
}
) });
}
}, c = (t, o) => {
if (Array.isArray(t)) {
const e = {};
return t.forEach((n, l) => {
o(n) && (e[l] = c(n, o));
}), e;
} else if (typeof t == "object" && t !== null) {
const e = {};
for (const n in t)
if (t.hasOwnProperty(n)) {
if (!o(t[n]))
continue;
e[n] = c(t[n], o);
}
return e;
} else
return t;
};
export {
W as DataFilter
};