@dooboostore/dom-render
Version:
html view template engine
99 lines (98 loc) • 4.82 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var DrThis_exports = {};
__export(DrThis_exports, {
DrThis: () => DrThis
});
module.exports = __toCommonJS(DrThis_exports);
var import_OperatorExecuterAttrRequire = require("./OperatorExecuterAttrRequire");
var import_RawSet = require("../rawsets/RawSet");
var import_ComponentSet = require("../components/ComponentSet");
var import_OperatorExecuter = require("./OperatorExecuter");
var import_OnDrThisUnBind = require("../lifecycle/dr-this/OnDrThisUnBind");
var import_OnDrThisBind = require("../lifecycle/dr-this/OnDrThisBind");
var import_core = require("@dooboostore/core");
class DrThis extends import_OperatorExecuterAttrRequire.OperatorExecuterAttrRequire {
async executeAttrRequire(attr) {
const optionIf = this.elementSource.attrs.drDetectIfOption ?? this.elementSource.attrs.drIfOption;
const ok = import_core.ObjectUtils.Script.evaluate(`
${this.render.bindScript}
try {
const ok = ${this.elementSource.attrs.drThis};
const option = ${optionIf};
if (option!==null) {
return !!(ok && option);
}
// console.log('vv', ${this.elementSource.attrs.drThis}, ${this.elementSource.attrs.drIfOption}, '${this.elementSource.attrs.drIfOption}');
return !!ok;
} catch(e) {
return false;
}
`, Object.assign(
this.source.obj,
{
__render: Object.freeze({
drAttr: this.elementSource.attrs,
drAttrsOriginName: import_RawSet.RawSet.drAttrsOriginName,
...this.render
})
}
));
if (attr && this.elementSource.attrs.drThis && ok) {
let thisPath = this.elementSource.attrs.drThis;
if (attr instanceof import_ComponentSet.ComponentSet) {
if (attr.config?.beforeComponentSet?.obj !== attr.obj) {
if ((0, import_OnDrThisUnBind.isOnDrThisUnBind)(attr.config.beforeComponentSet?.obj)) {
attr.config.beforeComponentSet?.obj?.onDrThisUnBind?.();
}
}
if (attr.config?.beforeComponentSet?.obj !== attr.obj) {
if ((0, import_OnDrThisBind.isOnDrThisBind)(attr.obj)) {
attr.obj?.onDrThisBind?.();
}
}
thisPath = `${this.elementSource.attrs.drThis}${attr.config.objPath ? "." + attr.config.objPath : ""}`;
this.setThisPath(thisPath);
const componentBody = await import_RawSet.RawSet.drThisCreate(this.rawSet, this.elementSource.element, thisPath, this.elementSource.attrs.drVarOption ?? "", this.elementSource.attrs.drStripOption, this.source.obj, this.source.config, attr);
if (componentBody) {
this.returnContainer.fag.append(componentBody);
this.afterCallBack.onThisComponentSetCallBacks.push(attr);
}
} else {
this.setThisPath(thisPath);
const fragment = await import_RawSet.RawSet.drThisCreate(this.rawSet, this.elementSource.element, this.elementSource.attrs.drThis, this.elementSource.attrs.drVarOption ?? "", this.elementSource.attrs.drStripOption, this.source.obj, this.source.config);
if (fragment) {
this.returnContainer.fag.append(fragment);
}
}
const rr = import_RawSet.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);
} else {
this.elementSource.element.remove();
}
return import_OperatorExecuter.ExecuteState.EXECUTE;
}
setThisPath(thisPath) {
if (this.rawSet.point.start instanceof this.source.config.window.HTMLMetaElement && this.rawSet.point.end instanceof this.source.config.window.HTMLMetaElement) {
this.rawSet.point.start.setAttribute("this-path", thisPath);
this.rawSet.point.end.setAttribute("this-path", thisPath);
}
}
}
//# sourceMappingURL=DrThis.js.map