@ea-lab/reactive-json
Version:
A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.
58 lines (57 loc) • 2.21 kB
JavaScript
import { jsx as v } from "react/jsx-runtime";
import { useContext as f } from "react";
import { ActionDependant as g } from "../../../engine/Actions.js";
import { GlobalDataContext as x } from "../../../engine/GlobalDataContext.js";
import { TemplateContext as I } from "../../../engine/TemplateContext.js";
import { evaluateTemplateValueCollection as h, dataLocationToPath as T } from "../../../engine/TemplateSystem.js";
import "../../../lodash-CYNxjS-I.js";
import { analyzeDataOverrideReferences as E } from "../../../engine/utility/analyzeDataOverrideReferences.js";
import "../../../js-yaml-CFDLc3Ha.js";
const L = ({ props: t }) => {
var d;
const a = f(x), n = f(I), l = a.ReactiveJsonRoot;
if (!l)
return null;
const e = h({
valueToEvaluate: t == null ? void 0 : t.rjOptions,
globalDataContext: a,
templateContext: n
}) || {};
if (typeof e != "object")
return;
let o;
if ((t == null ? void 0 : t.sharedUpdates) === !0 && ((d = t == null ? void 0 : t.rjOptions) != null && d.dataOverride)) {
const c = E(t.rjOptions.dataOverride);
if (c.size > 0) {
o = /* @__PURE__ */ new Map();
for (const [s, u] of c) {
const D = (b, m, C) => {
try {
const r = T({
dataLocation: u,
currentPath: n.templatePath,
globalDataContext: a,
templateContext: n
}), R = m ? `${r}.${m}` : r;
a.updateData(b, R, C);
} catch (r) {
console.warn(`Error during upstream propagation for ${u}:`, r);
}
};
o.set(s, D);
}
}
}
const i = Number.isInteger(parseInt(t == null ? void 0 : t.dataOverrideEvaluationDepth)) ? parseInt(t == null ? void 0 : t.dataOverrideEvaluationDepth) : 10;
e != null && e.dataOverride && Number.isInteger(i) && i !== 0 && (e.dataOverride = h({
valueToEvaluate: e == null ? void 0 : e.dataOverride,
globalDataContext: a,
templateContext: n,
evaluationDepth: i
}) || {});
const O = a.plugins ?? {};
return /* @__PURE__ */ v(g, { ...t, children: /* @__PURE__ */ v(l, { ...e, plugins: O, upstreamUpdateCallbacks: o }) });
};
export {
L as ReactiveJsonSubroot
};