UNPKG

@ea-lab/reactive-json

Version:

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

30 lines (29 loc) 1.31 kB
import { jsx as u } from "react/jsx-runtime"; import { useContext as f } from "react"; import { ActionDependant as D } from "../../../engine/Actions.js"; import { GlobalDataContext as x } from "../../../engine/GlobalDataContext.js"; import { TemplateContext as b } from "../../../engine/TemplateContext.js"; import { evaluateTemplateValue as c } from "../../../engine/TemplateSystem.js"; import { View as V } from "../../../engine/View.js"; const O = ({ currentData: s, datafield: o, path: v, props: e }) => { const n = f(x), t = f(b), m = e.dynamicOptions ?? void 0; let i; m ? i = c({ valueToEvaluate: m, globalDataContext: n, templateContext: t }) ?? [] : i = e.options ?? []; let a; const r = e.defaultFieldValue ?? void 0, p = e.dataLocation ?? void 0; p ? a = c({ globalDataContext: n, templateContext: t, valueToEvaluate: p }) ?? r : ((t.templateData[o] ?? void 0) === void 0 && (t.templateData = typeof t.templateData == "object" ? t.templateData : {}, t.templateData[o] = r), a = t.templateData[o]); let l = i.find((d) => d.value === a); if (!l || !l.label) { if (!a) return null; l = a; } return /* @__PURE__ */ u(D, { ...e, children: /* @__PURE__ */ u(V, { currentData: s, datafield: o, path: v, props: l.label }) }); }; export { O as LabelFromValue };