UNPKG

@react-form-builder/core

Version:

React JSON Schema Form Builder to create complex, validated, reusable forms with no deep React knowledge required

135 lines (134 loc) 3.94 kB
import { cloneDeep as s, startCase as r } from "../../../../utils/tools.js"; import { AnnotationMap as u } from "../../consts.js"; class l { /** * Type of component property description in the form builder. */ annotationType = "Module"; /** * Flag if true, the property name will be automatically converted in the designer from a camel case string to a human-readable string. */ autoName = !0; } class d { /** * Partial metadata for a component property. */ annotation; /** * Options for building an annotation. */ options = new l(); /** * @returns the main component property that is used as form data and for validation rules. */ get valued() { return this.setup({ valued: !0, dataBindingType: "twoWay" }); } /** * @returns the main property of the component that uses the form data as data (one-way data binding). */ get dataBound() { return this.setup({ valued: !0, dataBindingType: "oneWay" }); } /** * Sets the value for the property that prevents uncontrolled state. * @param uncontrolledValue the value for the uncontrolled state. * @returns the modified instance of the builder. */ uncontrolledValue(t) { return this.setup({ uncontrolledValue: t }); } /** * @returns the component property that can be localized. */ get localize() { return this.setup({ localizable: !0 }); } /** * @returns the non-localizable component property. */ get notLocalize() { return this.setup({ localizable: !1 }); } /** * Specifies the name of the component property. * @param name the property name. * @returns the modified instance of the builder. */ named(t) { return this.setup({ name: t }); } /** * Adds the hint to the property name of the component. * @param hint the hint. * @returns the modified instance of the builder. */ hinted(t) { return this.setup({ hint: t }); } /** * Marks the component property as calculable. * @param calculable true if the property is calculable. * @returns the modified instance of the builder. */ calculable(t) { return this.setup({ calculable: t }); } /** * Modifies the component property metadata builder with custom options. * @param options the custom options. * @returns the modified instance of the builder. */ setup(t) { const { annotationType: n, autoName: e, ...i } = t, o = this.clone(); return o.options.annotationType = n ?? o.options.annotationType, o.options.autoName = e ?? o.options.autoName, Object.assign(o.annotation, i), o; } /** * Clones the instance of the builder. * @returns the cloned instance of the builder. */ clone() { const t = s(this); return t.annotation ??= {}, t; } /** * Creates component property metadata for the form builder. * @param key the unique key of the component property. * @returns the instance of the component property metadata for the form builder. */ build(t) { const n = this.getName(t), e = new u[this.options.annotationType](t, n); return Object.assign(e, this.annotation), e; } /** * Sets custom properties for the component's property editor. * @param props the custom properties * @returns the modified instance of the builder. */ withEditorProps(t) { const n = this.clone(); return Object.assign(n.annotation, { editorProps: t }), n; } /** * Hides the component property editor. * @returns the modified instance of the builder. */ hideEditor() { const t = this.clone(); return Object.assign(t.annotation, { editor: void 0 }), t; } /** * Returns the annotation name. * @param key the property name * @returns the annotation name. */ getName(t) { return this.annotation.name ?? (this.options.autoName ? r(t) : t); } } export { d as BaseBuilder, l as BuilderOptions }; //# sourceMappingURL=BaseBuilder.js.map