@dooboostore/dom-render
Version:
html view template engine
82 lines (81 loc) • 4.18 kB
JavaScript
import { OperatorExecuterAttrRequire } from "./OperatorExecuterAttrRequire.js";
import { ScriptUtils } from "@dooboostore/core-web";
import { RawSet } from "../rawsets/RawSet.js";
import { ExecuteState } from "./OperatorExecuter.js";
import { ObjectUtils } from "@dooboostore/core";
class DrThisProperty extends OperatorExecuterAttrRequire {
constructor(rawSet, render, returnContainer, elementSource, source, afterCallBack) {
source.operatorAround = void 0;
super(rawSet, render, returnContainer, elementSource, source, afterCallBack, false);
}
async executeAttrRequire(attr) {
const itRandom = RawSet.drItOtherEncoding(this.elementSource.element, "DrThisProperty");
const vars = RawSet.drVarEncoding(this.elementSource.element, this.elementSource.attrs.drVarOption ?? "");
const newTemp = this.source.config.window.document.createElement("temp");
const dictioanry = ScriptUtils.evaluateReturn(attr, this.source.obj);
const dictionaryKey = this.elementSource.attrs.drKeyOption ?? "";
ObjectUtils.Script.evaluate(`
${this.render.bindScript}
${this.elementSource.attrs.drBeforeOption ?? ""}
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(','));
}
${this.elementSource.attrs.drAfterOption ?? ""}
`, Object.assign(this.source.obj, {
__render: Object.freeze({
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);
this.elementSource.element.parentNode?.replaceChild(this.returnContainer.fag, this.elementSource.element);
this.returnContainer.raws.push(...rr);
return ExecuteState.EXECUTE;
}
static append(obj, fullPath, key, rawSet, config) {
const genNode = config.window.document.importNode(rawSet.dataSet.fragment, true);
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);
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 = start.getAttribute(RawSet.DR_HAS_KEYS_OPTIONNAME)?.split(",") ?? [];
keys.push(key);
start.setAttribute(RawSet.DR_HAS_KEYS_OPTIONNAME, keys.join(","));
rawSets.forEach(async (it) => await it.render(obj, config));
}
return rawSets;
}
}
export {
DrThisProperty
};
//# sourceMappingURL=DrThisProperty.js.map