UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

199 lines (198 loc) 7.33 kB
import { jsxs as l, jsx as t } from "react/jsx-runtime"; import { useFormikContext as v } from "formik"; import { isEqual as y } from "lodash"; import { useEffect as g, useLayoutEffect as E, useContext as S } from "react"; import { useIntl as V, FormattedMessage as T } from "react-intl"; import C from "../../components/builder/label.js"; import M from "../../components/builder/description.js"; import F from "../../components/builder/tooltip.js"; import { BuilderContext as D } from "../../context.js"; import { Tabs as w, TabList as I, TabPanel as m } from "../../components/formio/tabs.js"; import "clsx"; import { useErrorChecker as x } from "../../utils/errors.js"; /* empty css */ import "@floating-ui/react"; /* empty css */ import "../../components/formio/textfield.js"; import "../../components/formio/datefield.js"; import "../../components/formio/datetimefield.js"; import "../../components/formio/timefield.js"; /* empty css */ import L from "../../components/formio/select.js"; import "dompurify"; import "../../components/formio/textarea.js"; import "../../components/formio/datagrid.js"; /* empty css */ import { LABELS as n } from "../../components/builder/messages.js"; import A, { useDeriveComponentKey as P } from "../../components/builder/key.js"; import k from "../../components/builder/multiple.js"; import q from "../../components/builder/hidden.js"; import O from "../../components/builder/clear-on-hide.js"; import R from "../../components/builder/is-sensitive-data.js"; import H from "../../components/builder/presentation-config.js"; import "../addressNL/index.js"; import "../bsn/index.js"; import "../checkbox/index.js"; import "../children/index.js"; import "../columns/index.js"; import "../content/index.js"; import "../cosignV1/index.js"; import "../cosignV2/index.js"; import "../currency/index.js"; import "../customerProfile/index.js"; import "../date/index.js"; import "../datetime/index.js"; import "../editgrid/index.js"; import "../email/index.js"; import "../fieldset/index.js"; import "../file/index.js"; import "../iban/index.js"; import "../licenseplate/index.js"; import "../map/index.js"; import "../npFamilyMembers/index.js"; import "../number/index.js"; import "../partners/index.js"; import "../phonenumber/index.js"; import "../postcode/index.js"; import "../radio/index.js"; import "./index.js"; import "../selectboxes/index.js"; import "../signature/index.js"; import "../softRequiredErrors/index.js"; import "../textarea/index.js"; import "../textfield/index.js"; import "../time/index.js"; import "@ckeditor/ckeditor5-react"; import "../../components/CKEditor.js"; /* empty css */ import K from "../../components/builder/simple-conditional.js"; import B from "../../components/builder/validate/required.js"; import j from "../../components/builder/validate/validator-select.js"; import J, { useManageValidatorsTranslations as z } 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 N } from "../../components/builder/i18n.js"; import { Basic as Q, Advanced as U, Validation as W, Registration as X, Translations as Y } from "../../components/builder/tabs.js"; import { ValuesConfig as Z } from "../../components/builder/values/values-config.js"; /* empty css */ import { ValuesTranslations as _ } from "../../components/builder/values/i18n.js"; import { checkIsManualOptions as $ } from "./helpers.js"; const tt = () => { var h; const i = V(), [p, u] = P(), { values: e, setFieldValue: s } = v(), { hasAnyError: a } = x(), { openForms: { dataSrc: d }, defaultValue: r, multiple: f } = e; g(() => { if (r === void 0) return; let o; f ? o = r ? [r] : [] : Array.isArray(r) ? o = r[0] ?? "" : o = r || "", s("defaultValue", o); }, [f]), z(["required"]); const c = $(e), b = c ? ((h = e.data) == null ? void 0 : h.values) || [] : []; return E(() => { const o = f ? [] : ""; d !== "variable" || y(r, o) || s("defaultValue", o); }, [d]), /* @__PURE__ */ l(w, { children: [ /* @__PURE__ */ l(I, { children: [ /* @__PURE__ */ t(Q, { hasErrors: a("label", "key", "description", "tooltip", "showInSummary", "showInEmail", "showInPDF", "multiple", "hidden", "clearOnHide", "isSensitiveData", "openForms.dataSrc", "openForms.itemsExpression", "data.values", "defaultValue") }), /* @__PURE__ */ t(U, { hasErrors: a("conditional") }), /* @__PURE__ */ t(W, { hasErrors: a("validate") }), /* @__PURE__ */ t(X, { hasErrors: a("registration") }), /* @__PURE__ */ t(Y, { hasErrors: a("openForms.translations") }) ] }), /* @__PURE__ */ l(m, { children: [ /* @__PURE__ */ t(C, {}), /* @__PURE__ */ t(A, { isManuallySetRef: p, generatedValue: u }), /* @__PURE__ */ t(M, {}), /* @__PURE__ */ t(F, {}), /* @__PURE__ */ t(H, {}), /* @__PURE__ */ t(k, { updateDefaultValue: !1 }), /* @__PURE__ */ t(q, {}), /* @__PURE__ */ t(O, {}), /* @__PURE__ */ t(R, {}), /* @__PURE__ */ t(Z, { name: "data.values" }), c && /* @__PURE__ */ t(rt, { options: b, multiple: !!e.multiple }) ] }), /* @__PURE__ */ t(m, { children: /* @__PURE__ */ t(K, {}) }), /* @__PURE__ */ l(m, { children: [ /* @__PURE__ */ t(B, {}), /* @__PURE__ */ t(j, {}), /* @__PURE__ */ t(J, {}) ] }), /* @__PURE__ */ t(m, { children: /* @__PURE__ */ t(G, {}) }), /* @__PURE__ */ t(m, { children: /* @__PURE__ */ t(N, { propertyLabels: { label: i.formatMessage(n.label), description: i.formatMessage(n.description), tooltip: i.formatMessage(n.tooltip) }, children: /* @__PURE__ */ t(_, { name: "data.values" }) }) }) ] }); }; tt.defaultValues = { // basic tab label: "", key: "", description: "", tooltip: "", showInSummary: !0, showInEmail: !1, showInPDF: !0, hidden: !1, clearOnHide: !0, isSensitiveData: !1, openForms: { dataSrc: "manual", translations: {} }, data: { values: [{ value: "", label: "" }] }, // TODO: at some point we can allow an itemsExpression for this too // Note: Formio will override this to `null`! So be careful when dealing with // the default values of the form defaultValue: "", // Advanced tab conditional: { show: void 0, when: "", eq: "" }, // Validation tab validate: { required: !1, plugins: [] }, translatedErrors: {}, registration: { attribute: "" } }; const rt = ({ options: i, multiple: p }) => { const u = V(), { formType: e } = S(D), s = u.formatMessage({ id: "FffJxu", defaultMessage: [{ type: 0, value: "This will be the initial value for this field before user interaction." }] }); return e === "appointment" ? null : /* @__PURE__ */ t(L, { name: "defaultValue", options: i, label: /* @__PURE__ */ t(T, { ...n.defaultValue }), tooltip: s, isMulti: p }); }; export { tt as default };