@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
125 lines (124 loc) • 4.16 kB
JavaScript
import { jsx as r, jsxs as L } from "react/jsx-runtime";
import { CRS_RD as $, TILE_LAYER_RD as h } from "@open-formulieren/leaflet-tools";
import { useContext as A, useRef as B, useLayoutEffect as G } from "react";
import { useIntl as U, FormattedMessage as W } from "react-intl";
import { MapContainer as q, TileLayer as z, LayersControl as C, FeatureGroup as J, WMSTileLayer as Y, useMap as Z } from "react-leaflet";
import { EditControl as H } from "react-leaflet-draw";
import { useAsync as K } from "react-use";
import N from "../../components/builder/loader.js";
import "../../components/formio/tabs.js";
import Q from "../../components/formio/component.js";
import X from "../../components/formio/description.js";
import "@floating-ui/react";
import "clsx";
import "formik";
import { BuilderContext as ee } from "../../context.js";
import "@formio/vanilla-text-mask";
import "formiojs";
/* empty css */
import "lodash";
/* empty css */
import "react-select";
import "dompurify";
import "../../components/formio/datagrid.js";
import re from "./edit-validation.js";
/* empty css */
const te = ({
lat: n,
lng: i,
zoom: a
}) => {
const s = Z();
return G(() => {
s.setView([n, i], a);
}, [s, n, i, a]), null;
}, oe = ({
index: n,
overlay: i,
url: a
}) => /* @__PURE__ */ r(C.Overlay, { name: i.label, checked: !0, children: /* @__PURE__ */ r(Y, { url: a, params: {
format: "image/png",
layers: i.layers.join(","),
transparent: !0
} }) }, `${n}-${i.label}`), ie = {
wms: oe
}, Ee = ({
component: n
}) => {
const {
key: i,
label: a,
description: s,
tooltip: v,
validate: w = {},
defaultZoom: x,
initialCenter: M = {},
tileLayerIdentifier: b,
interactions: t,
overlays: m
} = n, T = U(), k = A(ee), {
getMapTileLayers: R,
getMapOverlayTileLayers: j
} = k, u = B(null), {
value: [D, E] = [[], []],
loading: F,
error: c
} = K(async () => await Promise.all([R(), j()]), []);
if (c)
throw c;
if (F)
return /* @__PURE__ */ r(N, {});
const {
success: I
} = re({
intl: T
}).safeParse(n);
if (!I)
return /* @__PURE__ */ r(W, { id: "2gs8pJ", defaultMessage: [{
type: 0,
value: "The map configuration is not valid, so we can't show a preview. Fix the validation errors in the component configuration."
}] });
const p = m == null ? void 0 : m.filter((e) => !!(e != null && e.uuid)), {
required: S = !1
} = w, {
lat: f = 52.1326332,
lng: d = 5.291266
} = M, y = x ?? 8, O = (e) => {
var o;
return ((o = E.find((l) => l.uuid === e.uuid)) == null ? void 0 : o.url) ?? "";
}, P = () => {
var e;
return ((e = D.find((o) => o.identifier === b)) == null ? void 0 : e.url) ?? h.url;
}, V = (e) => {
var o, l;
(o = u.current) == null || o.clearLayers(), (l = u.current) == null || l.addLayer(e.layer);
}, _ = Object.values(t || {}).find((e) => e);
return /* @__PURE__ */ L(Q, { type: n.type, field: i, required: S, htmlId: `editform-${i}`, label: a, tooltip: v, children: [
/* @__PURE__ */ L(q, { crs: $, attributionControl: !0, center: [f, d], zoom: y, style: {
display: "flex",
flexDirection: "column",
minBlockSize: "400px"
}, children: [
/* @__PURE__ */ r(z, { ...h, url: P() }),
(p == null ? void 0 : p.length) && /* @__PURE__ */ r(C, { position: "topright", children: p.map((e, o) => {
const l = ie[e.type], g = O(e);
return g && l ? /* @__PURE__ */ r(l, { index: o, url: g, overlay: e }, o) : null;
}) }),
/* @__PURE__ */ r(J, { ref: u, children: _ && /* @__PURE__ */ r(H, { position: "topright", onCreated: V, edit: {
edit: !1
}, draw: {
rectangle: !1,
circle: !1,
polyline: !!(t != null && t.polyline),
polygon: !!(t != null && t.polygon),
marker: !!(t != null && t.marker),
circlemarker: !1
} }) }),
/* @__PURE__ */ r(te, { lat: f, lng: d, zoom: y })
] }),
s && /* @__PURE__ */ r(X, { text: s })
] });
};
export {
Ee as default
};