@mitcsutt/kiln-forms
Version:
Kiln forms: typed React forms on TanStack Form, in component or JSON schema mode, rendered through kiln-ui
45 lines (44 loc) • 1.35 kB
JavaScript
import { issuePath as e } from "../utils/paths.js";
//#region src/runtime/errors.ts
function t(e) {
return typeof e == "object" && !!e;
}
function n(n) {
if (n === !0) return { message: "" };
if (typeof n == "string") return n === "" ? null : { message: n };
if (n instanceof Error) return { message: n.message };
if (!t(n) || Array.isArray(n) || typeof n.message != "string") return null;
let r = { message: n.message };
if (typeof n.code == "string" && (r.code = n.code), t(n.params) && (r.params = n.params), Array.isArray(n.path)) {
let t = e({
message: n.message,
path: n.path
});
t !== "" && (r.path = t);
} else typeof n.path == "string" && n.path !== "" && (r.path = n.path);
return r;
}
function r(e) {
if (e == null || e === !1) return [];
if (Array.isArray(e)) return e.flatMap((e) => r(e));
let t = n(e);
return t ? [t] : [];
}
var i = [
"onServer",
"onSubmit",
"onDynamic",
"onChange",
"onBlur",
"onMount"
];
function a(e) {
if (!e) return [];
let t = /* @__PURE__ */ new Set(), n = [], a = [...i];
for (let t of Object.keys(e)) a.includes(t) || a.push(t);
for (let i of a) for (let a of r(e[i])) t.has(a.message) || (t.add(a.message), n.push(a));
return n;
}
//#endregion
export { i as ERROR_SLOT_PRIORITY, n as normaliseError, r as normaliseErrors, a as pickErrors };
//# sourceMappingURL=errors.js.map