UNPKG

@dooboostore/dom-render

Version:
72 lines (71 loc) 3.56 kB
import { RawSet } from "../rawsets/RawSet.js"; import { Validator } from "@dooboostore/core"; import { EventManager } from "../events/EventManager.js"; import { ValidatorArray } from "@dooboostore/core"; import { OperatorExecuterAttrRequire } from "./OperatorExecuterAttrRequire.js"; import { ExecuteState } from "./OperatorExecuter.js"; import { ObjectUtils } from "@dooboostore/core"; class DrForm extends OperatorExecuterAttrRequire { constructor(rawSet, render, returnContainer, elementSource, source, afterCallBack) { super(rawSet, render, returnContainer, elementSource, source, afterCallBack, false); } async executeAttrRequire(attr) { RawSet.drFormOtherMoveAttr(this.elementSource.element, "name", "temp-name", this.source.config); const data = ObjectUtils.Script.evaluateReturn(`${attr}`, this.source.obj); const childs = Array.from(this.elementSource.element.querySelectorAll("[name]")); const fromName = ObjectUtils.Script.evaluateReturn(this.elementSource.element.getAttribute(`${RawSet.DR_FORM_NAME}:name`) ?? "", this.source.obj); const thisName = fromName ?? this.elementSource.element.getAttribute("name"); if (childs.length <= 0 && thisName) { childs.push(this.elementSource.element); } else { if (data instanceof Validator) { data.setTarget(this.elementSource.element); } } childs.forEach((it) => { const eventName = it.getAttribute(`${RawSet.DR_FORM_NAME}:event`) ?? "change"; const validatorName = it.getAttribute(`${RawSet.DR_FORM_NAME}:validator`); const attrEventName = EventManager.attrPrefix + "event-" + eventName; let varpath = ObjectUtils.Script.evaluateReturn(this.elementSource.element.getAttribute(`${RawSet.DR_FORM_NAME}:name`) ?? "", this.source.obj) ?? it.getAttribute("name"); if (varpath != null) { if (validatorName) { ObjectUtils.Script.evaluate( ` ${this.render.bindScript} const validator = typeof ${validatorName} ==='function' ? new ${validatorName}() : ${validatorName}; ${attr}['${varpath}'] = validator; `, Object.assign( this.source.obj, { __render: Object.freeze({ drStripOption: this.elementSource.attrs.drStripOption, ...this.render }) } ) ); } varpath = `${attr}['${varpath}']`; const data2 = ObjectUtils.Script.evaluateReturn(`${varpath}`, this.source.obj); if (data2 instanceof ValidatorArray) { it.setAttribute(attrEventName, `${varpath}.setArrayValue($target, $target.value, $event); ${it.getAttribute(attrEventName) ?? ""};`); data2.addValidator(it.value, it); } else if (data2 instanceof Validator) { it.setAttribute(attrEventName, `${varpath}.set($target.value, $target, $event); ${it.getAttribute(attrEventName) ?? ""};`); data2.setTarget(it); data2.value = it.value; } else { it.setAttribute(attrEventName, `${varpath} = $target.value;`); } } }); RawSet.drFormOtherMoveAttr(this.elementSource.element, "temp-name", "name", this.source.config); this.returnContainer.raws.push(...RawSet.checkPointCreates(this.elementSource.element, this.source.obj, this.source.config)); return ExecuteState.EXECUTE; } } export { DrForm }; //# sourceMappingURL=DrForm.js.map