UNPKG

@ionic/core

Version:
4 lines 2.3 kB
import{__awaiter,__generator,__spreadArray}from"tslib"; /*! * (C) Ionic http://ionicframework.com - MIT License */import{c as componentOnReady}from"./helpers-78efeec3.js";var attachComponent=function(e,r,n,t,o,i){return __awaiter(void 0,void 0,void 0,(function(){var a,u;return __generator(this,(function(c){switch(c.label){case 0:if(e){return[2,e.attachViewToDom(r,n,o,t)]}if(!i&&typeof n!=="string"&&!(n instanceof HTMLElement)){throw new Error("framework delegate is missing")}u=typeof n==="string"?(a=r.ownerDocument)===null||a===void 0?void 0:a.createElement(n):n;if(t){t.forEach((function(e){return u.classList.add(e)}))}if(o){Object.assign(u,o)}r.appendChild(u);return[4,new Promise((function(e){return componentOnReady(u,e)}))];case 1:c.sent();return[2,u]}}))}))};var detachComponent=function(e,r){if(r){if(e){var n=r.parentElement;return e.removeViewFromDom(n,r)}r.remove()}return Promise.resolve()};var CoreDelegate=function(){var e;var r;var n=function(n,t){var o=[];for(var i=2;i<arguments.length;i++){o[i-2]=arguments[i]}return __awaiter(void 0,__spreadArray([n,t],o,true),void 0,(function(n,t,o,i){var a,u,c,f,s,d,v;if(o===void 0){o={}}if(i===void 0){i=[]}return __generator(this,(function(m){switch(m.label){case 0:e=n;if(!t)return[3,2];f=typeof t==="string"?(a=e.ownerDocument)===null||a===void 0?void 0:a.createElement(t):t;i.forEach((function(e){return f.classList.add(e)}));Object.assign(f,o);e.appendChild(f);c=f;return[4,new Promise((function(e){return componentOnReady(f,e)}))];case 1:m.sent();return[3,3];case 2:if(e.children.length>0&&(e.tagName==="ION-MODAL"||e.tagName==="ION-POPOVER")){s=c=e.children[0];if(!s.classList.contains("ion-delegate-host")){d=(u=e.ownerDocument)===null||u===void 0?void 0:u.createElement("div");d.classList.add("ion-delegate-host");i.forEach((function(e){return d.classList.add(e)}));d.append.apply(d,e.children);e.appendChild(d);c=d}}m.label=3;case 3:v=document.querySelector("ion-app")||document.body;r=document.createComment("ionic teleport");e.parentNode.insertBefore(r,e);v.appendChild(e);return[2,c!==null&&c!==void 0?c:e]}}))}))};var t=function(){if(e&&r){r.parentNode.insertBefore(e,r);r.remove()}return Promise.resolve()};return{attachViewToDom:n,removeViewFromDom:t}};export{CoreDelegate as C,attachComponent as a,detachComponent as d};