UNPKG

@ea-lab/reactive-json

Version:

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

67 lines (66 loc) 2.49 kB
import { jsx as d, Fragment as x } from "react/jsx-runtime"; import { useContext as l, Children as f, Fragment as C, isValidElement as y, cloneElement as T } from "react"; import { GlobalDataContext as A } from "../../engine/GlobalDataContext.js"; import "../../jsonpath-B9kE9k9e.js"; import "../../lodash-CYNxjS-I.js"; import { TemplateContext as E } from "../../engine/TemplateContext.js"; import "../../engine/EventDispatcherContext.js"; import "../../engine/EventDispatcherProvider.js"; import "../../engine/PaginationContext.js"; import "../../dnd-kit-sortable-tree.esm-Cz1RJyIg.js"; import "../../index-NNBvIV0S.js"; import { replaceEventPlaceholders as j } from "../../engine/utility/eventPlaceholderSystem.js"; import "../../js-yaml-CFDLc3Ha.js"; import "../../engine/ParsingDebugDisplay/ParsingDebugDisplay.js"; const H = (s) => { const p = l(A), g = l(E), n = p.plugins ?? {}, b = (n == null ? void 0 : n.reaction) ?? {}, { actionProps: P } = s, c = {}; for (const [o, a] of Object.entries(P)) c[o] = (t) => { let r = !0; for (const e of a) { if (!e) continue; const u = e.what && (b[e.what] ?? null); if (!u) continue; const i = j(e, t); if (u({ args: i, event: t, eventData: { // We copy the event data to make them available // to asynchronous reaction functions. // This is needed because React will reset the event object data // to reuse it for other events (see pooling of events in React). currentTarget: t.currentTarget, bubbles: t.bubbles, cancelable: t.cancelable, composed: t.composed, defaultPrevented: t.defaultPrevented, isTrusted: t.isTrusted, target: t.target, timeStamp: t.timeStamp, type: t.type }, globalDataContext: p, templateContext: g }), i.stopPropagation === !0) break; r = i.stopPropagation ?? !0; } r !== !1 && t.stopPropagation(); }; const m = (o) => { if (!o) return o; const a = f.toArray(o); return f.map(a, (t) => { var r; return t.type === C ? m((r = t == null ? void 0 : t.props) == null ? void 0 : r.children) : typeof t != "object" || !y(t) ? t : T(t, c); }); }, F = m(s.children); return /* @__PURE__ */ d(x, { children: F }); }; export { H as ReactOnEvent };