UNPKG

@dooboostore/dom-render

Version:
120 lines (116 loc) 8.03 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 { OperatorExecuterAttrRequire } from './OperatorExecuterAttrRequire'; import { ScriptUtils } from '@dooboostore/core-web/script/ScriptUtils'; import { RawSet } from '../rawsets/RawSet'; import { ExecuteState } from './OperatorExecuter'; export class DrForOf extends OperatorExecuterAttrRequire { constructor(rawSet, render, returnContainer, elementSource, source, afterCallBack) { source.operatorAround = undefined; super(rawSet, render, returnContainer, elementSource, source, afterCallBack, false); } executeAttrRequire(attr) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d; // console.log('타지도않냐?') const itRandom = RawSet.drItOtherEncoding(this.elementSource.element, 'DrForOf'); const vars = RawSet.drVarEncoding(this.elementSource.element, (_a = this.elementSource.attrs.drVarOption) !== null && _a !== void 0 ? _a : ''); const newTemp = this.source.config.window.document.createElement('temp'); // console.log('----!', this.elementSource.attrs) // ScriptUtils.evalReturn() ScriptUtils.eval(` ${this.render.bindScript} ${(_b = this.elementSource.attrs.drBeforeOption) !== null && _b !== void 0 ? _b : ''} var i = -1; const forOf = ${attr}; const forOfStr = \`${attr}\`.trim(); // console.log('forOf---',forOf); if (forOf) { for(const it of forOf) { i++; var destIt = it; if (/\\[(.*,?)\\],/g.test(forOfStr)) { if (typeof it === 'string') { destIt = it; } else { destIt = forOfStr.substring(1, forOfStr.length-1).split(',')[i]; } } else if (forOf.isRange) { destIt = it; } else { destIt = forOfStr + '[' + i +']' } const n = this.__render.element.cloneNode(true); // console.log('zzzzzzzzzzz', n.getAttribute('${RawSet.DR_DETECT_ATTR_OPTIONNAME}')); Object.entries(this.__render.drAttr).filter(([k,v]) => k !== 'drForOf' && k !== 'drNextOption' && v).forEach(([k, v]) => n.setAttribute(this.__render.drAttrsOriginName[k], v)); // console.log('---------'+destIt,n, Array.from(n.getAttributeNames()).map(it=>({name:it,attr: n.getAttribute(it)}))); // console.log('---------destItdestIt',destIt); n.getAttributeNames().forEach(it => n.setAttribute(it, n.getAttribute(it).replace(/\\#it\\#/g, destIt).replace(/\\#nearForOfIt\\#/g, destIt).replace(/\\#it\\#/g, destIt).replace(/\\#nearForOfIndex\\#/g, i))) const drOptionAttr = n.getAttribute('${RawSet.DR_DETECT_ATTR_OPTIONNAME}'); if (drOptionAttr) { const drOptionAttrResult = $scriptUtils.evalReturn(drOptionAttr, this); Array.from(Object.entries(drOptionAttrResult??{})).forEach(([k,v])=>{ if (v === null) { n.removeAttribute(k); } else { n.setAttribute(k,v); } }) } const drOptionFilter = n.getAttribute('${RawSet.DR_DETECT_FILTER_OPTIONNAME}'); if (drOptionFilter) { const drOptionFilterResult = $scriptUtils.evalReturn(drOptionFilter, this); // console.log('---drforof----', drOptionFilter, drOptionFilterResult) if (!drOptionFilterResult) { continue; } } n.innerHTML = n.innerHTML.replace(/\\#it\\#/g, destIt).replace(/\\#index\\#/g, i); // console.log('!@@@@', n.innerHTML); // DR_THIS_OPTIONNAME 는 제거한다 꼬인다. strip 할때 막 꼬여버린다. // const drOptionThis = n.getAttribute('${RawSet.DR_THIS_OPTIONNAME}'); // if (drOptionThis) { // n.setAttribute('${RawSet.DR_THIS_NAME}', drOptionThis) // } if (this.__render.drStripOption === 'true') { Array.from(n.childNodes).forEach(it => this.__render.fag.append(it)); } else { this.__render.fag.append(n); } } if('${this.elementSource.attrs.drNextOption}' !== 'null') { const n = this.__render.element.cloneNode(true); Object.entries(this.__render.drAttr).filter(([k,v]) => k !== 'drForOf' && k !== 'drNextOption' && v).forEach(([k, v]) => n.setAttribute(this.__render.drAttrsOriginName[k], v)); const [name, idx] = '${this.elementSource.attrs.drNextOption}'.split(','); n.setAttribute('${RawSet.DR_FOR_OF_NAME}', name + '[' + idx + ']'); n.setAttribute('${RawSet.DR_NEXT_OPTIONNAME}', name + ',' + (Number(idx) + 1)); this.__render.fag.append(n); } } ${(_c = this.elementSource.attrs.drAfterOption) !== null && _c !== void 0 ? _c : ''} `, Object.assign(this.source.obj, { __render: Object.freeze(Object.assign({ drStripOption: this.elementSource.attrs.drStripOption, drAttr: this.elementSource.attrs, drAttrsOriginName: RawSet.drAttrsOriginName, fag: newTemp }, this.render // eslint-disable-next-line no-use-before-define )) })); RawSet.drVarDecoding(newTemp, vars); RawSet.drItOtherDecoding(newTemp, itRandom); const tempalte = this.source.config.window.document.createElement('template'); tempalte.innerHTML = newTemp.innerHTML; this.returnContainer.fag.append(tempalte.content); const rr = RawSet.checkPointCreates(this.returnContainer.fag, this.source.obj, this.source.config); (_d = this.elementSource.element.parentNode) === null || _d === void 0 ? void 0 : _d.replaceChild(this.returnContainer.fag, this.elementSource.element); // const rrr = rr.flatMap(it => it.render(obj, config));// .flat(); this.returnContainer.raws.push(...rr); return ExecuteState.EXECUTE; }); } } //# sourceMappingURL=DrForOf.js.map