UNPKG

teleport-vue2

Version:
66 lines (65 loc) 2.18 kB
import { defineComponent as n } from "vue"; var s = n({ name: "Teleport", abstract: !0, props: { to: { type: [String, HTMLElement], required: !0 }, disabled: Boolean }, data: function() { var t = { teleported: !1, lastTo: "", rootEl: void 0, originalEl: void 0, dumb: document.createComment(" teleport ") }; return Object.preventExtensions(t), t; }, methods: { onEnter: function() { var t, e; this.rootEl = this._vnode.elm, this.originalEl = this.teleported ? (t = this.dumb) === null || t === void 0 ? void 0 : t.parentNode : (e = this.rootEl) === null || e === void 0 ? void 0 : e.parentNode, this.disabled ? this.restore() : this.telport(); }, restore: function() { var t; this.teleported && (this.$vnode.elm = this.rootEl, this.teleported = !1, this.lastTo = "", this.originalEl && (this.rootEl && this.originalEl.insertBefore(this.rootEl, this.dumb), (t = this.dumb.parentNode) === null || t === void 0 || t.removeChild(this.dumb))); }, telport: function() { if (!(!this.rootEl || !this.originalEl)) { this.teleported || this.originalEl.insertBefore(this.dumb, this.rootEl), this.$vnode.elm = this.dumb, this.teleported = !0; var t; this.to !== this.lastTo && (t = typeof this.to == "string" ? document.querySelector(this.to) : this.to), t && (t.appendChild(this.rootEl), this.lastTo = this.to); } } }, mounted: function() { this.onEnter(); }, updated: function() { this.onEnter(); }, beforeDestroy: function() { var t, e; (t = this.dumb.parentNode) === null || t === void 0 || t.removeChild(this.dumb), (e = this.rootEl) === null || e === void 0 || (e = e.parentNode) === null || e === void 0 || e.removeChild(this.rootEl); }, render: function(t) { var e, i = (e = this.$slots.default) === null || e === void 0 ? void 0 : e[0]; return i; } }); function l(o, t, e, i, h, a, u, m) { var r = typeof o == "function" ? o.options : o; return { exports: o, options: r }; } var d = /* @__PURE__ */ l(s), f = d.exports; export { f as Teleport, f as default };