UNPKG

@mitcsutt/kiln-forms

Version:

Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui

54 lines (53 loc) • 1.66 kB
import { useFieldContext as e } from "../../../kit/contexts.js"; import { getFormRuntime as t } from "../../../runtime/formRuntime.js"; import { FieldView as n } from "../FieldView/FieldView.js"; import { accepts as r } from "../../../kit/accepts.js"; import { useFieldBinding as i } from "../../../hooks/useFieldBinding.js"; import { defineField as a } from "../../../kit/contracts.js"; import { useCallback as o } from "react"; import { jsx as s } from "react/jsx-runtime"; import { CodeBlock as c, JsonField as l, formatJson as u, validateJson as d } from "@mitcsutt/kiln-ui"; //#region src/components/fields/FormJsonField/FormJsonField.tsx var f = a()(function({ warn: a, excluded: f, onBlur: p, validate: m, copyLabel: h, ...g }) { let _ = t(e().form).options.messages, v = o((e) => { let t = d(e ?? "", m); return t.valid ? void 0 : _.invalidJson(t.error); }, [m, _]), y = i({ ...g, warn: a, excluded: f, check: v, accepts: r.string, empty: "" }), b = y.value ?? ""; if (y.mode === "view") { let e = b.trim() === "" ? "" : u(b, { ...g.indent === void 0 ? {} : { indent: g.indent }, ...g.sortKeys === void 0 ? {} : { sortKeys: g.sortKeys } }) ?? b; return /* @__PURE__ */ s(n, { label: g.label, children: e === "" ? e : /* @__PURE__ */ s(c, { code: e, copyLabel: h ?? _.copyJson }) }); } return /* @__PURE__ */ s(l, { ...g, ...y.fieldProps, ref: y.ref, value: b, validate: m, copyLabel: h ?? _.copyJson, onValueChange: (e) => { y.setValue(e); }, onBlur: (e) => { p?.(e), y.onBlur(); } }); }); //#endregion export { f as FormJsonField }; //# sourceMappingURL=FormJsonField.js.map