UNPKG

@ea-lab/reactive-json

Version:

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

86 lines (85 loc) 3.06 kB
import { jsx as i, jsxs as A, Fragment as k } from "react/jsx-runtime"; import { useContext as I, createElement as L } from "react"; import { ActionDependant as z } from "../../../engine/Actions.js"; import { GlobalDataContext as B } from "../../../engine/GlobalDataContext.js"; import { PaginationContext as F } from "../../../engine/PaginationContext.js"; import { TemplateContext as G } from "../../../engine/TemplateContext.js"; import { evaluateTemplateValue as K, isTemplateValue as R, dataLocationToPath as q, evaluateAttributes as E } from "../../../engine/TemplateSystem.js"; import { View as g } from "../../../engine/View.js"; const _ = ({ props: t, currentData: e, path: m }) => { var T; const a = I(B), l = I(G), { usePagination: x } = ((T = a.plugins) == null ? void 0 : T.hook) ?? {}; if (!x) return null; const h = (t == null ? void 0 : t.cardinality) ?? -1, V = (t == null ? void 0 : t.options) ?? [], C = (t == null ? void 0 : t.singleOption) ?? void 0, P = !!C, o = (t == null ? void 0 : t.content) ?? null, j = o && K({ globalDataContext: a, templateContext: l, valueToEvaluate: o }), u = Object.entries(typeof j == "object" ? j : e).map(([W, n]) => { const c = W; if (h >= 1 && c >= h || !n || typeof n != "object") return null; let d, b, f; if (P) b = n, f = C; else { if (d = Object.keys(n)[0] ?? void 0, d === void 0) return null; b = Object.values(n)[0] ?? void 0, f = V[d] ?? void 0; } if (f === void 0) return null; let w = (R(o) && q({ dataLocation: o, currentPath: l.templatePath, globalDataContext: a, templateContext: l }) || m) + "." + c; return P || (w += "." + d), /* @__PURE__ */ i( g, { currentData: b, datafield: c, path: w, props: f }, c ); }), v = x({ dataToPaginate: u, ...(t == null ? void 0 : t.paginationProps) ?? {} }), O = t != null && t.paginated ? u.slice(v.firstShownItemIndex, v.maxShownItemIndexExcluded) : u, y = t != null && t.contentWrapper ? L( t.contentWrapper.tag ?? "div", E({ attrs: t.contentWrapper.attributes ?? {}, globalDataContext: a, options: { normalizeBeforeEvaluation: !0 }, templateContext: l }), O ) : O, S = /* @__PURE__ */ A(k, { children: [ (t == null ? void 0 : t.before) && /* @__PURE__ */ i( g, { currentData: (e == null ? void 0 : e.before) ?? void 0, path: m + ".before", datafield: "before", props: t == null ? void 0 : t.before } ), y, (t == null ? void 0 : t.after) && /* @__PURE__ */ i( g, { currentData: (e == null ? void 0 : e.after) ?? void 0, path: m + ".after", datafield: "after", props: t == null ? void 0 : t.after } ) ] }); return /* @__PURE__ */ i(z, { ...t, children: t != null && t.paginated ? /* @__PURE__ */ i(F.Provider, { value: { pagination: v }, children: S }) : S }); }; export { _ as Switch };