@react-form-builder/core
Version:
React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required
123 lines (122 loc) • 4.49 kB
JavaScript
import { internalErrorMeta as m } from "../../components/internalErrorMeta.js";
import { screenMeta as i } from "../../components/screenMeta.js";
import { modalMeta as s } from "../../modal/modalMeta.js";
import { modalModel as p } from "../../modal/modalModel.js";
import { repeaterMeta as n } from "../../repeater/repeaterMeta.js";
import { repeaterModel as l } from "../../repeater/repeaterModel.js";
import { embeddedFormMeta as d } from "../../template/embeddedFormMeta.js";
import { embeddedFormModel as c } from "../../template/embeddedFormModel.js";
import { slotMeta as h } from "../../template/slotMeta.js";
import { slotModel as f } from "../../template/slotModel.js";
import { createTemplateMeta as M } from "../../template/templateMeta.js";
import { createTemplateModel as u } from "../../template/templateModel.js";
import { internalErrorModel as g } from "../../ui/internalErrorModel.js";
import { screenModel as y } from "../../ui/screenModel.js";
import { errorMessageModel as C } from "../../validation/components/DefaultErrorMessage.js";
import { errorMessageMeta as b } from "../../validation/errorMessageMeta.js";
import { View as w } from "./View.js";
const o = "templates", F = "structure", T = "modal";
class a extends w {
#e = /* @__PURE__ */ new Map();
/**
* The array of metadata of form builder components.
*/
builderComponents;
/**
* The function for filtering components on the component palette.
*/
paletteFilter;
/**
* The description of the component library in different languages.
*/
i18nDescriptions;
/**
* Returns the component metadata for the specified component type name.
* @param type the component type name.
* @returns the component metadata for the specified component type name.
*/
getMeta(e) {
const r = this.#e.get(e);
return r || m;
}
/**
* Adds the component metadata to the form builder.
* @param component the component metadata.
*/
addComponent(e) {
this.define(e.model), this.#e.set(e.meta.type, e.meta);
}
/**
* Removes the component metadata from the form builder.
* @param name the component type name.
*/
removeComponent(e) {
this.#e.delete(e);
}
/**
* Returns the component metadata for the specified component type name or undefined.
* @param type the component type name.
* @returns the component metadata for the specified component type name or undefined.
*/
findMeta(e) {
return this.#e.get(e);
}
/**
* Creates metadata for the form builder for templates from the specified template names.
* @param templates the array of template names.
* @returns the instance of the {@link BuilderView} class.
*/
withTemplates(e) {
return e.forEach((r) => {
const t = a.createTemplateComponent(r);
this.define(t.model), this.#e.set(t.meta.type, t.meta), this.builderComponents.push(t);
}), this;
}
/**
* Sets a function for filtering components on the component palette.
* @param filter the component filtering function.
* @returns the instance of the {@link BuilderView} class.
*/
withPaletteFilter(e) {
return this.paletteFilter = e, this;
}
/**
* Adds a description of the component library in different languages.
* @param i18nDescription the description of the component library in different languages.
* @returns the instance of the {@link BuilderView} class.
*/
withComponentLibraryDescription(e) {
return this.i18nDescriptions ??= [], this.i18nDescriptions.push(e), this;
}
/**
* Creates an instance of BuilderComponent for the specified template name.
* @param name the template name
* @returns the BuilderComponent instance.
*/
static createTemplateComponent(e) {
const r = u(e);
return { meta: M(e), model: r, category: o };
}
/**
* Creates metadata for form builder components.
* @param builderComponents the array of metadata of form builder components.
*/
constructor(e) {
super(e.map(({ model: t }) => t)), this.builderComponents = [
...e,
{ meta: i, model: y },
{ meta: m, model: g },
{ meta: h, model: f, category: o },
{ meta: d, model: c, category: o },
{ meta: n, model: l, category: F },
{ meta: b, model: C },
{ meta: s, model: p, category: T }
], this.builderComponents.map(({ meta: t }) => t).forEach((t) => {
this.#e.set(t.type, t);
});
}
}
export {
a as BuilderView
};
//# sourceMappingURL=BuilderView.js.map