UNPKG

@dooboostore/dom-render

Version:
93 lines 5.96 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 DrThisProperty 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, _e; const itRandom = RawSet.drItOtherEncoding(this.elementSource.element, 'DrThisProperty'); 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'); const dictioanry = ScriptUtils.evalReturn(attr, this.source.obj); const dictionaryKey = (_b = this.elementSource.attrs.drKeyOption) !== null && _b !== void 0 ? _b : ''; // console.log('--->', attr, dictionaryKey) // if (!(dictioanry instanceof Dictionary)) { // return ExecuteState.STOP; // } // await new Promise(resolve => setTimeout(resolve, 1000)); // console.log('!!!!!!!!!!!!!!', this.rawSet); ScriptUtils.eval(` ${this.render.bindScript} ${(_c = this.elementSource.attrs.drBeforeOption) !== null && _c !== void 0 ? _c : ''} var i = 0; const dictionary = ${attr}; const dictionaryKey = '${dictionaryKey}'; const dictionaryStr = \`${attr}\`.trim(); // console.log('----@#!@#@!#', this.__render.oldChild); if (dictionary) { for(const it in dictionary) { var destIt = dictionaryStr + '["' + it + '"]'; const n = this.__render.element.cloneNode(true); n.setAttribute('dr-this', destIt); n.setAttribute('${RawSet.DR_KEY_OPTIONNAME}', it); // n.setAttribute('dr-dictionary-key', it); this.__render.fag.append(n); i++; } this.__render.rawset.point.start.setAttribute('${RawSet.DR_HAS_KEYS_OPTIONNAME}',Object.keys(dictionary).join(',')); } ${(_d = this.elementSource.attrs.drAfterOption) !== null && _d !== void 0 ? _d : ''} `, 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)) })); 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); (_e = this.elementSource.element.parentNode) === null || _e === void 0 ? void 0 : _e.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; }); } static append(obj, fullPath, key, rawSet, config) { var _a, _b; const genNode = config.window.document.importNode(rawSet.dataSet.fragment, true); // console.log('---> append', rawSet, genNode); const rawSets = []; for (const cNode of Array.from(genNode.childNodes.values())) { const element = cNode.cloneNode(true); element.removeAttribute(RawSet.DR_THIS_PROPERTY_NAME); element.setAttribute(RawSet.DR_THIS_NAME, `this.${fullPath}`); element.setAttribute(RawSet.DR_KEY_OPTIONNAME, key); // rawSet.point.end.after(element); const fg = config.window.document.createDocumentFragment(); fg.append(element); rawSets.push(...RawSet.checkPointCreates(fg, obj, config)); rawSet.point.end.before(fg); const start = rawSet.point.start; const keys = (_b = (_a = start.getAttribute(RawSet.DR_HAS_KEYS_OPTIONNAME)) === null || _a === void 0 ? void 0 : _a.split(',')) !== null && _b !== void 0 ? _b : []; keys.push(key); start.setAttribute(RawSet.DR_HAS_KEYS_OPTIONNAME, keys.join(',')); rawSets.forEach((it) => __awaiter(this, void 0, void 0, function* () { return yield it.render(obj, config); })); } return rawSets; } } //# sourceMappingURL=DrThisProperty.js.map