UNPKG

@react-form-builder/core

Version:

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

100 lines (99 loc) 2.59 kB
import { BiDi as i } from "../../localization/bidi.js"; import { modalModel as s } from "../../modal/modalModel.js"; import { repeaterItemModel as o } from "../../repeater/RepeaterItem.js"; import { repeaterModel as n } from "../../repeater/repeaterModel.js"; import { embeddedFormModel as h } from "../../template/embeddedFormModel.js"; import { fragmentModel as d } from "../../template/fragmentModel.js"; import { slotModel as f } from "../../template/slotModel.js"; import { templateModel as m } from "../../template/templateModel.js"; import { internalErrorModel as p } from "../../ui/internalErrorModel.js"; import { screenModel as a } from "../../ui/screenModel.js"; import { errorMessageModel as l } from "../../validation/components/DefaultErrorMessage.js"; class r { #e = /* @__PURE__ */ new Map(); #t = /* @__PURE__ */ new Map(); #i = new Array(); /** * Static wrapper for the {@link View} constructor. * @param models the components metadata. * @returns the {@link View} instance. */ static create(e) { return new r(e); } /** * Creates an instance of the {@link View}. * @param models the components metadata. */ constructor(e = []) { this.define(a), this.define(p), this.define(f), this.define(h), this.define(m), this.define(d), this.define(n), this.define(o), this.define(l), this.define(s), e.forEach(this.define.bind(this)); } /** * @inheritDoc */ define(e) { this.#e.set(e.type, e); } /** * @inheritDoc */ get(e) { const t = this.find(e); if (t) return t; throw new Error(`Type '${e}' is not found!`); } /** * @inheritDoc */ find(e) { return this.#e.get(e); } /** * @inheritDoc */ all() { return [...this.#e.values()]; } /** * @inheritDoc */ filterModels(e) { return [...this.#e.values()].filter(e); } /** * @inheritDoc */ withViewerWrapper = (e) => (this.#i.push(e), this); /** * @inheritDoc */ get viewerWrappers() { return [...this.#i]; } /** * @inheritDoc */ withCssLoader(e, t) { return e === "common" ? (this.#r(i.LTR, t), this.#r(i.RTL, t)) : this.#r(e, t), this; } /** * Sets a CSS loader for the specified BiDi direction. * @param biDi the BiDi direction. * @param loader the loader function that returns a Promise. */ #r(e, t) { this.#t.set(e, [...this.#t.get(e) ?? [], t]); } /** * @inheritDoc */ getCssLoaders(e) { return this.#t.get(e) ?? []; } } const V = r.create; export { r as View, V as createView }; //# sourceMappingURL=View.js.map