UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

74 lines (73 loc) 2.04 kB
import { defineMessages as l } from "react-intl"; import { z as e } from "zod"; const s = l({ required: { id: "dazu9j", defaultMessage: [{ type: 0, value: "Label is a required field." }] }, invalidKeyPattern: { id: "h0B9Fr", defaultMessage: [{ type: 0, value: "The property name must only contain alphanumeric characters, underscores, dots and dashes and should not be ended by dash or dot." }] } }), u = (r) => e.string({ errorMap: d((a, o) => { if (a.code === "invalid_type" && o.data === void 0) return r.formatMessage(s.required); }) }), c = (r) => e.string({ errorMap: d((a) => { if (g(a) && a.validation === "regex") return r.formatMessage(s.invalidKeyPattern); }) }).regex(new RegExp("^(\\w|\\w[\\w-.]*\\w)$")), h = (r) => e.object({ label: u(r), key: c(r) }), m = e.union([e.string(), e.number(), e.boolean(), e.null()]), i = e.lazy(() => e.union([m, e.array(i), e.record(i)])), p = e.object({ label: e.string().optional() }), M = (r) => e.object({ value: e.string({ required_error: r.formatMessage({ id: "BKe/DT", defaultMessage: [{ type: 0, value: "The option value is a required field." }] }) }).min(1), label: e.string({ required_error: r.formatMessage({ id: "arAMAF", defaultMessage: [{ type: 0, value: "The option label is a required field." }] }) }).min(1), openForms: e.object({ // zod doesn't seem to be able to use our supportedLanguageCodes for z.object keys, // they need to be defined statically. So, 'record' it is. translations: e.record(e.string(), p.optional()) }).optional() }), g = (r) => r.code === "invalid_string", d = (r) => (o, t) => { const n = r(o, t); return n ? { message: n } : { message: t.defaultError }; }; export { h as buildCommonSchema, c as buildKeySchema, u as buildLabelSchema, d as getErrorMap, g as isInvalidStringIssue, i as jsonSchema, M as optionSchema };