UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

81 lines (80 loc) 3.08 kB
var m = Object.defineProperty; var M = (i, t, n) => t in i ? m(i, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : i[t] = n; var a = (i, t, n) => M(i, typeof t != "symbol" ? t + "" : t, n); import { FieldBuilder as O } from "./FieldBuilder.mjs"; import { ValidationManager as b } from "./ValidationManager.mjs"; import { OptionManager as y } from "./OptionManager.mjs"; import { createForm as F, createLink as C, createSelectOption as B, createContainer as v, createButton as g } from "../../../utils/helpers.mjs"; class N { // Хранит конфигурации полей constructor() { a(this, "fieldBuilder"); a(this, "optionManager"); a(this, "validationManager"); a(this, "fieldsConfig", []); this.optionManager = new y(), this.fieldBuilder = new O(), this.validationManager = new b(); } // Добавляет поле в форму addField(t) { this.fieldsConfig.push(t); } // Удаляет поле по индексу removeField(t) { t >= 0 && t < this.fieldsConfig.length && this.fieldsConfig.splice(t, 1); } // Возвращает текущий список полей getFields() { return this.fieldsConfig; } clearFields() { this.fieldsConfig = []; } // Создает и возвращает форму на основе текущего конфига createForm(t, n = "GET") { const s = F("generated-form space-y-4", t, n); this.fieldsConfig.forEach((e) => { var c, u; let o = null; if (e.type === "button") { const r = ((c = e.options) == null ? void 0 : c.target) || ""; o = C(e.label, r, "_blank"); } else o = this.fieldBuilder.createField(e); if (o) { if (e.validation && this.validationManager.addValidation(o, e.validation), e.type === "select" && ((u = e.options) != null && u.options)) { const r = o.querySelector("select"); r && e.options.options.forEach((f) => { const h = B(f, f); r.appendChild(h); }); } s.appendChild(o); } }); const l = v("button-container flex gap-2"), p = g("Submit", () => { }, "primary"); p.type = "submit", p.className += " flex-1 p-2 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"; const d = g("Reset", () => { }, "secondary"); return d.type = "reset", d.className += " flex-1 p-2 rounded-md focus:outline-none focus:ring-2 focus:ring-gray-500 focus:ring-offset-2", l.appendChild(p), l.appendChild(d), s.appendChild(l), s; } // Устанавливает контейнер для опций setOptionsContainer(t) { this.optionManager.setOptionsContainer(t); } // Добавляет новую опцию addOption(t = "") { this.optionManager.addOption(t); } // Возвращает все опции getOptions() { return this.optionManager.getOptions(); } // Очищает все опции clearOptions() { this.optionManager.clearOptions(); } } export { N as FormManager };