UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

163 lines (162 loc) 6.11 kB
import { jsxs as n, jsx as e } 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 s } from "../../components/formio/tabs.js"; import "clsx"; import { useErrorChecker as x } from "../../utils/errors.js"; /* empty css */ import "@floating-ui/react"; /* empty css */ import "@formio/vanilla-text-mask"; import "formiojs"; /* empty css */ import L from "../../components/formio/select.js"; import "dompurify"; import "../../components/formio/datagrid.js"; import { LABELS as m } 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 "@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 ee = () => { var h; const a = V(), [u, p] = P(), { values: o, setFieldValue: l } = v(), { hasAnyError: i } = x(), { openForms: { dataSrc: d }, defaultValue: t, multiple: f } = o; g(() => { if (t === void 0) return; let r; f ? r = t ? [t] : [] : Array.isArray(t) ? r = t[0] ?? "" : r = t || "", l("defaultValue", r); }, [f]), z(["required"]); const c = $(o), b = c ? ((h = o.data) == null ? void 0 : h.values) || [] : []; return E(() => { const r = f ? [] : ""; d !== "variable" || y(t, r) || l("defaultValue", r); }, [d]), /* @__PURE__ */ n(w, { children: [ /* @__PURE__ */ n(I, { children: [ /* @__PURE__ */ e(Q, { hasErrors: i("label", "key", "description", "tooltip", "showInSummary", "showInEmail", "showInPDF", "multiple", "hidden", "clearOnHide", "isSensitiveData", "openForms.dataSrc", "openForms.itemsExpression", "data.values", "defaultValue") }), /* @__PURE__ */ e(U, { hasErrors: i("conditional") }), /* @__PURE__ */ e(W, { hasErrors: i("validate") }), /* @__PURE__ */ e(X, { hasErrors: i("registration") }), /* @__PURE__ */ e(Y, { hasErrors: i("openForms.translations") }) ] }), /* @__PURE__ */ n(s, { children: [ /* @__PURE__ */ e(C, {}), /* @__PURE__ */ e(A, { isManuallySetRef: u, generatedValue: p }), /* @__PURE__ */ e(M, {}), /* @__PURE__ */ e(F, {}), /* @__PURE__ */ e(H, {}), /* @__PURE__ */ e(k, { updateDefaultValue: !1 }), /* @__PURE__ */ e(q, {}), /* @__PURE__ */ e(O, {}), /* @__PURE__ */ e(R, {}), /* @__PURE__ */ e(Z, { name: "data.values" }), c && /* @__PURE__ */ e(te, { options: b, multiple: !!o.multiple }) ] }), /* @__PURE__ */ e(s, { children: /* @__PURE__ */ e(K, {}) }), /* @__PURE__ */ n(s, { children: [ /* @__PURE__ */ e(B, {}), /* @__PURE__ */ e(j, {}), /* @__PURE__ */ e(J, {}) ] }), /* @__PURE__ */ e(s, { children: /* @__PURE__ */ e(G, {}) }), /* @__PURE__ */ e(s, { children: /* @__PURE__ */ e(N, { propertyLabels: { label: a.formatMessage(m.label), description: a.formatMessage(m.description), tooltip: a.formatMessage(m.tooltip) }, children: /* @__PURE__ */ e(_, { name: "data.values" }) }) }) ] }); }; ee.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 te = ({ options: a, multiple: u }) => { const p = V(), { formType: o } = S(D), l = p.formatMessage({ id: "FffJxu", defaultMessage: [{ type: 0, value: "This will be the initial value for this field before user interaction." }] }); return o === "appointment" ? null : /* @__PURE__ */ e(L, { name: "defaultValue", options: a, label: /* @__PURE__ */ e(T, { ...m.defaultValue }), tooltip: l, isMulti: u }); }; export { ee as default };