@ea-lab/reactive-json
Version:
A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.
50 lines (49 loc) • 1.73 kB
JavaScript
import { jsx as d } from "react/jsx-runtime";
import { useContext as m, useEffect as x } from "react";
import { ActionDependant as v, isValid as A } from "../../../engine/Actions.js";
import { GlobalDataContext as F } from "../../../engine/GlobalDataContext.js";
import { TemplateContext as h } from "../../../engine/TemplateContext.js";
import { View as y } from "../../../engine/View.js";
const p = ({ props: t, currentData: e, path: i }) => {
const c = m(F), n = m(h), a = Array.isArray(t.delayedActions) ? t.delayedActions : [], o = { globalDataContext: c, templateContext: n };
return x(() => {
if (!t.interval)
return;
const r = setInterval(() => {
const l = g(a, o);
for (let u = 0; u < l.length; ++u) {
const s = l[u];
if (!s)
continue;
const f = s.what && (reactionFunctions[s.what] ?? null);
f && f({ args: s, globalDataContext: c, templateContext: n });
}
t.once && clearInterval(r);
}, t.interval);
return () => clearInterval(r);
}, [c, n]), /* @__PURE__ */ d(v, { ...t, children: t.content && /* @__PURE__ */ d(
y,
{
props: t.content,
currentData: (e == null ? void 0 : e.content) ?? void 0,
datafield: "content",
path: i + ".content"
}
) });
}, g = (t, e) => {
const i = [];
if (!Array.isArray(t))
return i;
const { globalDataContext: c } = e, n = c.plugins ?? {}, a = (n == null ? void 0 : n.reaction) ?? {};
if (!a)
return i;
for (const [, o] of t.entries()) {
const r = (o == null ? void 0 : o.what) ?? void 0;
!r || !(a[r] ?? void 0) || A(o, e) && i.push(o);
}
return i;
};
export {
p as DelayedActions,
g as getReactionFunctionsToExecute
};