UNPKG

@dooboostore/dom-render

Version:
91 lines 6.48 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 { ScriptUtils } from '@dooboostore/core-web/script/ScriptUtils'; import { RawSet } from '../rawsets/RawSet'; import { ExecuteState, OperatorExecuter } from './OperatorExecuter'; // 여기서 사용자가 등록한 TargetElement가 들어간다. export class DrTargetElement 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, _e; const targetElement = (_b = (_a = this.source.config) === null || _a === void 0 ? void 0 : _a.targetElements) === null || _b === void 0 ? void 0 : _b.find(it => it.name.toLowerCase() === this.elementSource.element.tagName.toLowerCase()); if (targetElement) { 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', `this.__domrender_components.${this.rawSet.uuid}`); this.rawSet.point.end.setAttribute('this-path', `this.__domrender_components.${this.rawSet.uuid}`); } const documentFragment = yield targetElement.callBack(this.elementSource.element, this.source.obj, this.rawSet, this.elementSource.attrs, this.source.config); if (documentFragment) { const detectAction = this.elementSource.element.getAttribute(RawSet.DR_DETECT_NAME); // const dictionaryKey = this.elementSource.element.getAttribute(RawSet.DR_DICTIONARY_OPTIONKEYNAME); // console.log('dictionaryKey', dictionaryKey); // const render = (documentFragment as any).render; this.rawSet.dataSet.fragment = documentFragment; // if (documentFragment) { // const tempDiv = this.source.config.window.document.createElement('div'); // tempDiv.appendChild(documentFragment.cloneNode(true)); // console.log('DocumentFragment innerHTML:', tempDiv.innerHTML); // } // this.rawSet.dataSet??={}; // this.rawSet.dataSet.data = render.component; if (detectAction && this.rawSet.dataSet.render) { // TODO: 없어져야될듯? this.rawSet.detect = { action: () => { const script = `var $component = this.__render.component; var $element = this.__render.element; var $innerHTML = this.__render.innerHTML; var $attribute = this.__render.attribute; ${detectAction} `; ScriptUtils.eval(script, Object.assign(this.source.obj, { __render: this.rawSet.dataSet.render })); } }; } // fag.append(documentFragment) // console.log('----------1', ElementUtils.toInnerHTML(documentFragment, {document: this.source.config.window.document})); // await Promises.sleep(1000) let targetFragment = documentFragment; if (targetElement.noStrip) { // documentFragment.firstElementChild.classList.add(`${this.rawSet.uuid}___DrTargetElement`) const fragment = this.source.config.window.document.createDocumentFragment(); Array.from(((_c = documentFragment.firstElementChild) === null || _c === void 0 ? void 0 : _c.childNodes) || []).forEach(child => { // fragment.appendChild(child.cloneNode(true)); fragment.appendChild(child); }); // fragment.append(documentFragment.firstElementChild); targetFragment = fragment; } // console.log('----------2', ElementUtils.toInnerHTML(targetFragment, {document: this.source.config.window.document})); const rr = RawSet.checkPointCreates(targetFragment, this.source.obj, this.source.config); if (targetElement.noStrip) { Array.from(targetFragment.childNodes || []).forEach(child => { documentFragment.firstElementChild.appendChild(child); }); } (_d = this.elementSource.element.parentNode) === null || _d === void 0 ? void 0 : _d.replaceChild(documentFragment, this.elementSource.element); this.returnContainer.raws.push(...rr); this.afterCallBack.onElementInitCallBacks.push({ name: targetElement.name.toLowerCase(), obj: this.source.obj, targetElement, creatorMetaData: targetElement.__creatorMetaData }); // console.log('sssssssssssssss', this.source.obj); (_e = targetElement === null || targetElement === void 0 ? void 0 : targetElement.complete) === null || _e === void 0 ? void 0 : _e.call(targetElement, this.elementSource.element, this.source.obj, this.rawSet); } return ExecuteState.EXECUTE; } return ExecuteState.NO_EXECUTE; }); } } //# sourceMappingURL=DrTargetElement.js.map