UNPKG

@dooboostore/dom-render

Version:
80 lines (79 loc) 3.72 kB
import { OperatorExecuterAttrRequire } from "./OperatorExecuterAttrRequire.js"; import { RawSet } from "../rawsets/RawSet.js"; import { ComponentSet } from "../components/ComponentSet.js"; import { ExecuteState } from "./OperatorExecuter.js"; import { isOnDrThisUnBind } from "../lifecycle/dr-this/OnDrThisUnBind.js"; import { isOnDrThisBind } from "../lifecycle/dr-this/OnDrThisBind.js"; import { ObjectUtils } from "@dooboostore/core"; class DrThis extends OperatorExecuterAttrRequire { async executeAttrRequire(attr) { const optionIf = this.elementSource.attrs.drDetectIfOption ?? this.elementSource.attrs.drIfOption; const ok = 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: RawSet.drAttrsOriginName, ...this.render }) } )); if (attr && this.elementSource.attrs.drThis && ok) { let thisPath = this.elementSource.attrs.drThis; if (attr instanceof ComponentSet) { if (attr.config?.beforeComponentSet?.obj !== attr.obj) { if (isOnDrThisUnBind(attr.config.beforeComponentSet?.obj)) { attr.config.beforeComponentSet?.obj?.onDrThisUnBind?.(); } } if (attr.config?.beforeComponentSet?.obj !== attr.obj) { if (isOnDrThisBind(attr.obj)) { attr.obj?.onDrThisBind?.(); } } thisPath = `${this.elementSource.attrs.drThis}${attr.config.objPath ? "." + attr.config.objPath : ""}`; this.setThisPath(thisPath); const componentBody = await 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 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 = 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 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); } } } export { DrThis }; //# sourceMappingURL=DrThis.js.map