@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
208 lines (207 loc) • 7.54 kB
JavaScript
import { jsxs as u, jsx as e } from "react/jsx-runtime";
import { useFormikContext as M } from "formik";
import { isEqual as x } from "lodash";
import { useContext as d, useLayoutEffect as V } from "react";
import { useIntl as c, FormattedMessage as g } from "react-intl";
import C from "../../components/builder/label.js";
import T from "../../components/builder/description.js";
import E from "../../components/builder/tooltip.js";
import { BuilderContext as f } from "../../context.js";
import { Tabs as F, TabList as w, TabPanel as m } from "../../components/formio/tabs.js";
import "clsx";
import { useErrorChecker as k } from "../../utils/errors.js";
/* empty css */
import "@floating-ui/react";
/* empty css */
import "@formio/vanilla-text-mask";
import "formiojs";
/* empty css */
import "react-select";
import { SelectBoxes as D } from "../../components/formio/selectboxes.js";
import { NumberField as S } from "../../components/formio/number.js";
import "../../components/formio/datagrid.js";
import { LABELS as p } from "../../components/builder/messages.js";
import I, { useDeriveComponentKey as O } from "../../components/builder/key.js";
import A from "../../components/builder/hidden.js";
import P from "../../components/builder/clear-on-hide.js";
import q from "../../components/builder/is-sensitive-data.js";
import K from "../../components/builder/presentation-config.js";
import "@ckeditor/ckeditor5-react";
import "../../components/CKEditor.js";
/* empty css */
import L from "../../components/builder/simple-conditional.js";
import B from "../../components/builder/validate/required.js";
import R from "../../components/builder/validate/validator-select.js";
import H, { useManageValidatorsTranslations as j } from "../../components/builder/validate/i18n.js";
import G from "../../components/builder/registration/registration-attribute.js";
import "react-use";
import "../../components/builder/prefill/identifierRole.js";
import { ComponentTranslations as J } from "../../components/builder/i18n.js";
import { Basic as N, Advanced as Q, Validation as W, Registration as z, Translations as U } from "../../components/builder/tabs.js";
import { ValuesConfig as X } from "../../components/builder/values/values-config.js";
/* empty css */
import { ValuesTranslations as Y } from "../../components/builder/values/i18n.js";
import { checkIsManualOptions as Z } from "./helpers.js";
const _ = () => {
const t = c(), [a, r] = O(), {
values: s,
setFieldValue: n
} = M(), {
hasAnyError: i
} = k(), {
formType: h
} = d(f), {
openForms: {
dataSrc: l
},
defaultValue: v
} = s;
j(h === "appointment" ? ["required"] : ["required", "minSelectedCount", "maxSelectedCount"]);
const o = Z(s), b = o ? s.values || [] : [];
return V(() => {
l !== "variable" || x(v, {}) || n("defaultValue", {});
}, [l]), /* @__PURE__ */ u(F, { children: [
/* @__PURE__ */ u(w, { children: [
/* @__PURE__ */ e(N, { hasErrors: i("label", "key", "description", "tooltip", "showInSummary", "showInEmail", "showInPDF", "hidden", "clearOnHide", "isSensitiveData", "openForms.dataSrc", "openForms.itemsExpression", "values", "defaultValue") }),
/* @__PURE__ */ e(Q, { hasErrors: i("conditional") }),
/* @__PURE__ */ e(W, { hasErrors: i("validate") }),
/* @__PURE__ */ e(z, { hasErrors: i("registration") }),
/* @__PURE__ */ e(U, { hasErrors: i("openForms.translations") })
] }),
/* @__PURE__ */ u(m, { children: [
/* @__PURE__ */ e(C, {}),
/* @__PURE__ */ e(I, { isManuallySetRef: a, generatedValue: r }),
/* @__PURE__ */ e(T, {}),
/* @__PURE__ */ e(E, {}),
/* @__PURE__ */ e(K, {}),
/* @__PURE__ */ e(A, {}),
/* @__PURE__ */ e(P, {}),
/* @__PURE__ */ e(q, {}),
/* @__PURE__ */ e(X, { name: "values", withOptionDescription: !0 }),
o && /* @__PURE__ */ e($, { options: b })
] }),
/* @__PURE__ */ e(m, { children: /* @__PURE__ */ e(L, {}) }),
/* @__PURE__ */ u(m, { children: [
/* @__PURE__ */ e(B, {}),
/* @__PURE__ */ e(R, {}),
/* @__PURE__ */ e(ee, {}),
/* @__PURE__ */ e(te, {}),
/* @__PURE__ */ e(H, {})
] }),
/* @__PURE__ */ e(m, { children: /* @__PURE__ */ e(G, {}) }),
/* @__PURE__ */ e(m, { children: /* @__PURE__ */ e(J, { propertyLabels: {
label: t.formatMessage(p.label),
description: t.formatMessage(p.description),
tooltip: t.formatMessage(p.tooltip)
}, children: /* @__PURE__ */ e(Y, { name: "values", withOptionDescription: !0 }) }) })
] });
};
_.defaultValues = {
// basic tab
label: "",
key: "",
description: "",
tooltip: "",
showInSummary: !0,
showInEmail: !1,
showInPDF: !0,
hidden: !1,
clearOnHide: !0,
isSensitiveData: !1,
openForms: {
dataSrc: "manual",
translations: {}
},
values: [{
value: "",
label: ""
}],
// TODO: check that the initial values are set based on component.values
// TODO: at some point we can allow an itemsExpression for this too
defaultValue: {},
// Advanced tab
conditional: {
show: void 0,
when: "",
eq: ""
},
// Validation tab
validate: {
required: !1,
plugins: []
},
translatedErrors: {},
registration: {
attribute: ""
}
};
const $ = ({
options: t
}) => {
const a = c(), {
getFieldProps: r,
setFieldValue: s
} = M(), {
value: n = {}
} = r("defaultValue"), {
formType: i
} = d(f), h = a.formatMessage({
id: "FffJxu",
defaultMessage: [{
type: 0,
value: "This will be the initial value for this field before user interaction."
}]
});
return V(() => {
const l = t.map((o) => o.value);
if (new Set(Object.keys(n)) === new Set(l)) return;
const y = {};
l.forEach((o) => {
const b = n.hasOwnProperty(o) ? n[o] : !1;
y[o] = b;
}), s("defaultValue", y);
}, [t]), i === "appointment" ? null : /* @__PURE__ */ e(D, { name: "defaultValue", options: t, label: /* @__PURE__ */ e(g, { ...p.defaultValue }), tooltip: h });
}, ee = () => {
const t = c(), {
formType: a
} = d(f), r = t.formatMessage({
id: "BVuE94",
defaultMessage: [{
type: 0,
value: "If specified, the user must check at least this many options."
}]
});
return a === "appointment" ? null : /* @__PURE__ */ e(S, { name: "validate.minSelectedCount", label: /* @__PURE__ */ e(g, { id: "dbAJfK", defaultMessage: [{
type: 0,
value: "Minimum selected checkboxes"
}] }), placeholder: t.formatMessage({
id: "oGBVo2",
defaultMessage: [{
type: 0,
value: "Minimum selected checkboxes (e.g. 1)"
}]
}), tooltip: r, min: 1, step: 1 });
}, te = () => {
const t = c(), {
formType: a
} = d(f), r = t.formatMessage({
id: "sR9GVQ",
defaultMessage: [{
type: 0,
value: "If specified, the user must check at most this many options."
}]
});
return a === "appointment" ? null : /* @__PURE__ */ e(S, { name: "validate.maxSelectedCount", label: /* @__PURE__ */ e(g, { id: "aWwaAq", defaultMessage: [{
type: 0,
value: "Maximum selected checkboxes"
}] }), placeholder: t.formatMessage({
id: "VNGD7o",
defaultMessage: [{
type: 0,
value: "Maximum selected checkboxes (e.g. 1)"
}]
}), tooltip: r, min: 1, step: 1 });
};
export {
_ as default
};