UNPKG

@dooboostore/dom-render

Version:
45 lines 3 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 { RawSet } from '../rawsets/RawSet'; import { ExecuteState, OperatorExecuter } from './OperatorExecuter'; export class DrTargetAttr extends OperatorExecuter { constructor(rawSet, render, returnContainer, elementSource, source, afterCallBack) { source.operatorAround = undefined; super(rawSet, render, returnContainer, elementSource, source, afterCallBack, false); } execute() { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d; const attributeNames = this.elementSource.element.getAttributeNames(); const targetAttr = (_b = (_a = this.source.config) === null || _a === void 0 ? void 0 : _a.targetAttrs) === null || _b === void 0 ? void 0 : _b.find(it => attributeNames.includes(it.name)); if (targetAttr) { const attrName = targetAttr.name; const attrValue = this.rawSet.getAttributeAndDelete(this.elementSource.element, attrName); if (attrValue && attrName && (!this.elementSource.attrs.drForOf && !this.elementSource.attrs.drFor && !this.elementSource.attrs.drRepeat)) { const documentFragment = targetAttr.callBack(this.elementSource.element, attrValue, this.source.obj, this.rawSet); if (documentFragment) { const rr = RawSet.checkPointCreates(documentFragment, this.source.obj, this.source.config); (_c = this.elementSource.element.parentNode) === null || _c === void 0 ? void 0 : _c.replaceChild(documentFragment, this.elementSource.element); this.returnContainer.raws.push(...rr); this.afterCallBack.onAttrInitCallBacks.push({ attrName, attrValue, obj: this.source.obj }); (_d = targetAttr === null || targetAttr === void 0 ? void 0 : targetAttr.complete) === null || _d === void 0 ? void 0 : _d.call(targetAttr, this.elementSource.element, attrValue, this.source.obj, this.rawSet); } } return ExecuteState.EXECUTE; } return ExecuteState.NO_EXECUTE; }); } } //# sourceMappingURL=DrTargetAttr.js.map