@ea-lab/reactive-json
Version:
A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.
32 lines (31 loc) • 1.52 kB
JavaScript
import { jsx as C, Fragment as H } from "react/jsx-runtime";
import { useContext as h, useEffect as E } from "react";
import { EventDispatcherContext as x } from "../../engine/EventDispatcherContext.js";
import { GlobalDataContext as L } from "../../engine/GlobalDataContext.js";
import { TemplateContext as T } from "../../engine/TemplateContext.js";
import { evaluateTemplateValueCollection as d } from "../../engine/TemplateSystem.js";
const R = (a) => {
const e = h(x), n = h(L), o = h(T), s = n.plugins ?? {}, f = (s == null ? void 0 : s.reaction) ?? {}, t = (a == null ? void 0 : a.actionProps) ?? void 0;
return E(() => {
const v = t ?? void 0, r = (t == null ? void 0 : t.what) ?? void 0, w = (t == null ? void 0 : t.whenHashIs) ?? void 0, g = (t == null ? void 0 : t.whenHashWas) ?? void 0, i = d({
globalDataContext: n,
templateContext: o,
valueToEvaluate: w
}), c = d({
globalDataContext: n,
templateContext: o,
valueToEvaluate: g
}), m = (l) => {
if (typeof i == "string" && new URL(l.newUrl).hash !== i || typeof c == "string" && new URL(l.oldUrl).hash !== c)
return;
const u = r && (f[r] ?? void 0);
u && u({ args: v, event: l, globalDataContext: n, templateContext: o });
};
return e == null || e.addEventListener("hashchange", m), () => {
e == null || e.removeEventListener("hashchange", m);
};
}, [e, n, t, o]), /* @__PURE__ */ C(H, { children: a.children });
};
export {
R as HashChangeListener
};