UNPKG

@ea-lab/reactive-json

Version:

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

60 lines (59 loc) 2 kB
import "react/jsx-runtime"; import "../../jsonpath-B9kE9k9e.js"; import "../../lodash-CYNxjS-I.js"; import "react"; import "../../engine/GlobalDataContext.js"; import "../../engine/TemplateContext.js"; import { evaluateTemplateValue as v } from "../../engine/TemplateSystem.js"; import "../../engine/EventDispatcherContext.js"; import "../../engine/EventDispatcherProvider.js"; import "../../engine/PaginationContext.js"; import "../../dnd-kit-sortable-tree.esm-Cz1RJyIg.js"; import { normalizeAttributeNameForReactJsx as A } from "../../engine/utility/reactJsxHelpers.js"; import "../../index-NNBvIV0S.js"; import "../../js-yaml-CFDLc3Ha.js"; import "../../engine/ParsingDebugDisplay/ParsingDebugDisplay.js"; const q = ({ attributes: o, globalDataContext: V, singleTransformProps: x, templateContext: g }) => { const { name: p, value: u, separator: m = " ", keepAttributeWhenEmpty: h = !1 } = x || {}; if (!p || u === void 0) return o; const s = v({ valueToEvaluate: u, globalDataContext: V, templateContext: g }), i = A(p), f = o[i] || ""; let l = [...f ? f.split(m).filter((e) => e.trim() !== "") : []]; if (Array.isArray(s)) { const e = s.map((t) => String(t)); if (e.length === 0) return o; if (e.length === 1) { const t = e[0], n = l.indexOf(t); n > -1 ? l.splice(n, 1) : t !== "" && l.push(t); } else { let t = -1, n = -1; for (let r = 0; r < e.length; r++) { const a = e[r], d = l.indexOf(a); if (d > -1) { t = d, n = r; break; } } if (t > -1) { const r = (n + 1) % e.length, a = e[r]; l.splice(t, 1), a !== "" && l.push(a); } else { const r = e[0]; r !== "" && l.push(r); } } } else { const e = String(s), t = l.indexOf(e); t > -1 ? l.splice(t, 1) : l.push(e); } const c = l.join(m); return c.trim() === "" ? h ? o[i] = "" : delete o[i] : o[i] = c, o; }; export { q as toggleAttributeValue };