UNPKG

@mitcsutt/kiln-forms

Version:

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

37 lines (36 loc) • 1.14 kB
import { issuePath as e } from "../utils/paths.js"; import { getFormRuntime as t, isInactive as n } from "./formRuntime.js"; //#region src/runtime/standardSchema.ts function r(t, r) { if (!t || t.length === 0) return; let i = [], a = {}, o = 0; for (let s of t) { let t = e(s); if (t === "") { i.push(s), o += 1; continue; } r && n(r, t) || ((a[t] ??= []).push(s), o += 1); } if (o !== 0) return i.length > 0 ? { form: i, fields: a } : { fields: a }; } var i = "[@mitcsutt/kiln-forms] This schema validates asynchronously. Pass `schemaAsync: true` to useAppForm so it runs in the async slot."; function a(e) { return ({ value: n, formApi: a }) => { let o = e["~standard"].validate(n); if (o instanceof Promise) throw Error(i); return r(o.issues, t(a)); }; } function o(e) { return async ({ value: n, formApi: i }) => r((await e["~standard"].validate(n)).issues, t(i)); } function s(e) { return typeof e == "object" && !!e && "~standard" in e; } //#endregion export { s as isStandardSchema, r as routeIssues, a as schemaValidator, o as schemaValidatorAsync }; //# sourceMappingURL=standardSchema.js.map