UNPKG

@mitcsutt/kiln-forms

Version:

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

33 lines (32 loc) • 1.23 kB
import { formatErrorText as e, getFormRuntime as t } from "../../runtime/formRuntime.js"; import { compileRules as n } from "../core/rules.js"; import { DEFAULT_EMPTIES as r } from "../core/toStandardSchema.js"; var i = /* @__PURE__ */ new WeakMap(); function a(e, a, o, s) { let c = t(o).options.messages, l = i.get(e); if (l?.messages === c && l.validators === s) return l.compiled; let u = a !== void 0 && Object.prototype.hasOwnProperty.call(r, a) ? r[a] : void 0, d = n(e, { validators: s, messages: c, empty: u }); return i.set(e, { messages: c, validators: s, compiled: d }), d; } function o(e, t, n, r) { if (e.length === 0) return; let i = a(e, t, n, r), o = {}; return i.sync && (o.onDynamic = ({ value: i, fieldApi: o }) => a(e, t, n, r).sync?.(i, o.form.state.values)), i.async && (o.onDynamicAsync = async ({ value: i, fieldApi: o, signal: s }) => a(e, t, n, r).async?.(i, o.form.state.values, s), o.onDynamicAsyncDebounceMs = 300), o; } function s(n, r, i, o, s) { if (n.length !== 0) return (c) => { let l = a(n, r, i, s).sync?.(c, o()); return l ? e(t(i), l) : void 0; }; } //#endregion export { a as compiledRules, o as ruleValidators, s as ruleWarning }; //# sourceMappingURL=rules.js.map