UNPKG

@dooboostore/dom-render

Version:
79 lines 5.27 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { ScriptUtils } from '@dooboostore/core-web/script/ScriptUtils'; import { RawSet } from '../rawsets/RawSet'; import { Validator } from '../validators/Validator'; import { EventManager } from '../events/EventManager'; import { ValidatorArray } from '../validators/ValidatorArray'; import { OperatorExecuterAttrRequire } from './OperatorExecuterAttrRequire'; import { ExecuteState } from './OperatorExecuter'; export class DrForm extends OperatorExecuterAttrRequire { constructor(rawSet, render, returnContainer, elementSource, source, afterCallBack) { super(rawSet, render, returnContainer, elementSource, source, afterCallBack, false); } executeAttrRequire(attr) { return __awaiter(this, void 0, void 0, function* () { var _a; RawSet.drFormOtherMoveAttr(this.elementSource.element, 'name', 'temp-name', this.source.config); const data = ScriptUtils.evalReturn(`${attr}`, this.source.obj); const childs = Array.from(this.elementSource.element.querySelectorAll('[name]')); const fromName = ScriptUtils.evalReturn((_a = this.elementSource.element.getAttribute(`${RawSet.DR_FORM_NAME}:name`)) !== null && _a !== void 0 ? _a : '', this.source.obj); const thisName = fromName !== null && fromName !== void 0 ? fromName : this.elementSource.element.getAttribute('name'); // // 자기자신이 Input 대상일때 if (childs.length <= 0 && thisName) { childs.push(this.elementSource.element); } else { if (data instanceof Validator) { data.setTarget(this.elementSource.element); } } childs.forEach(it => { var _a, _b, _c, _d, _e; const eventName = (_a = it.getAttribute(`${RawSet.DR_FORM_NAME}:event`)) !== null && _a !== void 0 ? _a : 'change'; const validatorName = it.getAttribute(`${RawSet.DR_FORM_NAME}:validator`); const attrEventName = EventManager.attrPrefix + 'event-' + eventName; let varpath = (_c = ScriptUtils.evalReturn((_b = this.elementSource.element.getAttribute(`${RawSet.DR_FORM_NAME}:name`)) !== null && _b !== void 0 ? _b : '', this.source.obj)) !== null && _c !== void 0 ? _c : it.getAttribute('name'); if (varpath != null) { if (validatorName) { ScriptUtils.eval(` ${this.render.bindScript} const validator = typeof ${validatorName} ==='function' ? new ${validatorName}() : ${validatorName}; ${attr}['${varpath}'] = validator; `, Object.assign(this.source.obj, { __render: Object.freeze(Object.assign({ drStripOption: this.elementSource.attrs.drStripOption }, this.render)) })); } varpath = `${attr}['${varpath}']`; const data = ScriptUtils.evalReturn(`${varpath}`, this.source.obj); if (data instanceof ValidatorArray) { it.setAttribute(attrEventName, `${varpath}.setArrayValue($target, $target.value, $event); ${(_d = it.getAttribute(attrEventName)) !== null && _d !== void 0 ? _d : ''};`); data.addValidator(it.value, it); } else if (data instanceof Validator) { // varpath += (varpath ? '.value' : 'value'); // varpath = drAttr.drForm + '.' + varpath; // it.setAttribute(attrEventName, `${varpath} = $target.value; ${target}=$target; ${event}=$event;`); it.setAttribute(attrEventName, `${varpath}.set($target.value, $target, $event); ${(_e = it.getAttribute(attrEventName)) !== null && _e !== void 0 ? _e : ''};`); data.setTarget(it); data.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; }); } } //# sourceMappingURL=DrForm.js.map