UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

37 lines (36 loc) 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const leaflet_tools_1 = require("@open-formulieren/leaflet-tools"); const zod_1 = require("zod"); const validation_1 = require("../../registry/validation"); const buildConfigurationSchema = (intl) => zod_1.z.object({ defaultZoom: zod_1.z.number().int().lte(leaflet_tools_1.TILE_LAYER_RD.maxZoom).gte(leaflet_tools_1.TILE_LAYER_RD.minZoom).optional(), initialCenter: zod_1.z .object({ lat: zod_1.z.number().lte(90).gte(-90).optional(), lng: zod_1.z.number().lte(180).gte(-180).optional(), }) .superRefine((val, ctx) => { const bothMissing = val.lat == null && val.lng == null; const bothSet = val.lat != null && val.lng != null; if (bothMissing || bothSet) { return; } const missing = val.lat == null ? 'lat' : 'lng'; ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, message: intl.formatMessage({ id: "R/XadM", defaultMessage: [{ type: 0, value: "You need to configure both longitude and latitude." }] }), path: [missing], }); }) .optional(), }); const buildMapSchema = (intl) => zod_1.z .object({ useConfigDefaultMapSettings: zod_1.z.literal(true), defaultZoom: zod_1.z.undefined().or(zod_1.z.null()), initialCenter: zod_1.z.undefined(), }) .or(zod_1.z.object({ useConfigDefaultMapSettings: zod_1.z.literal(false) }).and(buildConfigurationSchema(intl))); const schema = ({ intl }) => (0, validation_1.buildCommonSchema)(intl).and(buildMapSchema(intl)); exports.default = schema;