UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

101 lines (100 loc) 2.25 kB
import { camelCase as l } from "lodash"; import { MAIN_DROPZONE_ID as p, getComponentKeyFromDropzoneId as m } from "./dropzone.js"; import { iterComponents as c, isPlaceholder as i } from "../../../../formio.js"; import { getRegistryEntry as f } from "../../../../registry/index.js"; import { hasOwnProperty as a } from "../../../../types/index.js"; const d = (o, e) => { if (e === p) return o; const n = m(e); return u(o, n); }, u = (o, e) => { for (const { component: n } of c(o)) { if (i(n)) continue; const { getComponentSlots: t } = f(n.type); if (t) { for (const r of t(n)) if (r.reference === e) return r.collection; } } }, P = (o, e, n) => { const { edit: t, formDesigner: r } = f(o), s = n.formatMessage(r.label); return { ...t.defaultValues, id: window.crypto.randomUUID(), type: o, key: e(l(s)), ...a(t.defaultValues, "label") ? { label: s } : {} // type cast necessary because the discriminated union doesn't narrow and // getRegistryEntry doesn't narrow either, essentially returning AnyComponentSchema }; }, w = (o) => { for (const { index: e, component: n, collection: t } of c(o)) if (i(n)) { t.splice(e, 1); return; } }, x = (o, e) => { for (const { index: n, component: t, collection: r } of c(o)) if (!i(t) && t.key === e) { r.splice(n, 1); return; } }, v = (o, e) => { for (const { index: n, component: t, collection: r } of c(o)) if (i(t)) { r[n] = e; return; } }, b = (o, e, n) => { for (const { index: t, component: r, collection: s } of c(o)) if (!i(r) && r.key === e) { s[t] = n; return; } }, k = (o, e, n, t) => { const r = d(e, n); r !== void 0 && r.splice(o, 0, t); }; function z(o) { for (const { component: e } of c(o)) if (i(e)) throw new Error("Components must not contain a placeholder"); } export { z as assertNoPlaceholders, P as createComponent, d as getDropzoneComponents, k as insertComponentDefinition, x as removeComponent, w as removePlaceholder, b as replaceComponent, v as replacePlaceholderWithComponent };