From 6eddef40f2fcc6122b9f46d5460f7e52c852c4b9 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sat, 17 Jun 2017 16:01:33 +0200 Subject: [PATCH] new build files for 1.1.0 --- dist/portal-vue.js | 2 +- dist/portal-vue.js.map | 2 +- dist/portal-vue.min.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/portal-vue.js b/dist/portal-vue.js index 4dd29f9..1361f81 100644 --- a/dist/portal-vue.js +++ b/dist/portal-vue.js @@ -182,7 +182,7 @@ var Wormhole = function () { }, { key: 'hasContentFor', value: function hasContentFor(to) { - return this.hasTarget(to) && this.transports[to].passengers != null; + return this.transports[to] && this.transports[to].passengers != null ? true : false; } }, { key: 'getSourceFor', diff --git a/dist/portal-vue.js.map b/dist/portal-vue.js.map index ed3d1d8..5cb3ea9 100644 --- a/dist/portal-vue.js.map +++ b/dist/portal-vue.js.map @@ -1 +1 @@ -{"version":3,"file":"portal-vue.js","sources":["../src/utils.js","../src/components/wormhole.js","../src/components/portal-target.js","../src/components/portal.js","../src/index.js"],"sourcesContent":["export function extractAttributes (el) {\n const map = el.hasAttributes() ? el.attributes : []\n const attrs = {}\n for (let i = 0; i < map.length; i++) {\n const attr = map[i]\n if (attr.value) {\n attrs[attr.name] = attr.value === '' ? true : attr.value\n }\n }\n return attrs\n}\n\nexport function freeze (item) {\n if (Array.isArray(item) || typeof item === 'object') {\n return Object.freeze(item)\n }\n return item\n}\n","import Vue from 'vue'\nimport { freeze } from '../utils'\nconst transports = {}\n\nexport { transports }\n\nexport class Wormhole {\n constructor (transports) {\n this.transports = transports\n }\n\n open (transport) {\n const { to, from, passengers } = transport\n if (!to || !from || !passengers) return\n\n transport.passengers = freeze(passengers)\n const keys = Object.keys(this.transports)\n if (keys.includes(to)) {\n this.transports[to] = transport\n } else {\n Vue.set(this.transports, to, transport)\n }\n }\n\n close (transport, force = false) {\n const { to, from } = transport\n if (!to || !from) return\n if (this.transports[to] && (force || this.transports[to].from === from)) {\n this.transports[to] = undefined\n }\n }\n\n hasTarget (to) {\n return this.transports.hasOwnProperty(to)\n }\n\n hasContentFor (to) {\n return this.hasTarget(to) && this.transports[to].passengers != null\n }\n\n getSourceFor (to) {\n return this.transports[to] && this.transports[to].from\n }\n\n getContentFor (to) {\n const transport = this.transports[to]\n return transport ? transport.passengers : undefined\n }\n\n}\nconst wormhole = new Wormhole(transports)\nexport default wormhole\n","\nimport { transports } from './wormhole'\n\nexport default {\n abstract: true,\n name: 'portalTarget',\n props: {\n attributes: { type: Object },\n name: { type: String, required: true },\n slim: { type: Boolean, default: false },\n tag: { type: String, default: 'div' },\n },\n data () {\n return {\n transports,\n }\n },\n\n mounted () {\n if (!this.transports[this.name]) {\n this.$set(this.transports, this.name, undefined)\n }\n\n this.unwatch = this.$watch(function () { return this.transports[this.name] }, this.emitChange)\n\n this.updateAttributes()\n },\n updated () {\n this.updateAttributes()\n },\n beforeDestroy () {\n this.unwatch()\n this.$el.innerHTML = ''\n },\n\n methods: {\n updateAttributes () {\n if (this.attributes) {\n const attrs = this.attributes\n const el = this.$el\n\n // special treatment for class\n if (attrs.class) {\n attrs.class.trim().split(' ').forEach((klass) => {\n el.classList.add(klass)\n })\n delete attrs.class\n }\n\n const keys = Object.keys(attrs)\n\n for (let i = 0; i < keys.length; i++) {\n el.setAttribute(keys[i], attrs[keys[i]])\n }\n }\n },\n emitChange (newTransport, oldTransport) {\n this.$emit('change',\n { ...newTransport },\n { ...oldTransport }\n )\n },\n },\n computed: {\n passengers () {\n return (this.transports[this.name] && this.transports[this.name].passengers) || []\n },\n children () {\n return this.passengers.length !== 0 ? this.passengers : (this.$slots.default || [])\n },\n renderSlim () {\n const children = this.children\n return children.length === 1 && !this.attributes && this.slim\n },\n },\n\n render (h) {\n const children = this.children\n const Tag = this.tag\n if (this.renderSlim) {\n return children[0]\n } else {\n return ({children})\n }\n },\n}\n","\nimport Vue from 'vue'\nimport wormhole from './wormhole'\nimport Target from './portal-target'\nimport { extractAttributes } from '../utils'\n\nconst inBrowser = (typeof window !== 'undefined')\n\nlet pid = 1\n\nexport default {\n abstract: true,\n name: 'portal',\n props: {\n /* global HTMLElement */\n disabled: { type: Boolean, default: false },\n name: { type: String, default: () => String(pid++) },\n slim: { type: Boolean, default: false },\n tag: { type: [String], default: 'DIV' },\n targetEl: { type: inBrowser ? [String, HTMLElement] : String },\n to: { type: String, default: () => String(Math.round(Math.random() * 10000000)) },\n },\n\n mounted () {\n if (this.targetEl) {\n this.mountToTarget()\n }\n if (!this.disabled) {\n this.sendUpdate()\n }\n },\n\n updated () {\n if (this.disabled) {\n this.clear()\n } else {\n this.sendUpdate()\n }\n },\n\n beforeDestroy () {\n this.clear()\n if (this.mountedComp) {\n this.mountedComp.$destroy()\n }\n },\n\n watch: {\n to (newValue, oldValue) {\n oldValue && this.clear(oldValue)\n this.sendUpdate()\n },\n targetEl (newValue, oldValue) {\n this.mountToTarget()\n },\n },\n\n methods: {\n\n sendUpdate () {\n if (this.to) {\n if (this.$slots.default) {\n wormhole.open({\n from: this.name,\n to: this.to,\n passengers: [...this.$slots.default],\n })\n }\n } else if (!this.to && !this.targetEl) {\n console.warn('[vue-portal]: You have to define a target via the `to` prop.')\n }\n },\n\n clear (target) {\n wormhole.close({\n from: this.name,\n to: target || this.to,\n })\n },\n\n mountToTarget () {\n let el\n const target = this.targetEl\n\n if (typeof target === 'string') {\n el = document.querySelector(this.targetEl)\n } else if (target instanceof HTMLElement) {\n el = target\n } else {\n console.warn('[vue-portal]: value of targetEl must be of type String or HTMLElement')\n return\n }\n\n const attributes = extractAttributes(el)\n\n if (el) {\n const target = new Vue({\n ...Target,\n parent: this,\n propsData: {\n name: this.to,\n tag: el.tagName,\n attributes,\n },\n })\n target.$mount(el)\n this.mountedComp = target\n } else {\n console.warn('[vue-portal]: The specified targetEl ' + this.targetEl + ' was not found')\n }\n },\n },\n\n render (h) {\n const children = this.$slots.default || []\n const Tag = this.tag\n if (children.length && this.disabled) {\n return children.length <= 1 && this.slim\n ? children[0]\n : ({children})\n } else {\n return ()\n // h(this.tag, { class: { 'v-portal': true }, style: { display: 'none' }, key: 'v-portal-placeholder' })\n }\n },\n}\n","import Portal from './components/portal.js'\nimport PortalTarget from './components/portal-target.js'\nimport Wormhole from './components/wormhole.js'\n\nfunction install (Vue, opts = {}) {\n Vue.component(opts.portalName || 'portal', Portal)\n Vue.component(opts.portalTargetName || 'portal-target', PortalTarget)\n}\nif (typeof window !== 'undefined' && window.Vue) {\n window.Vue.use({ install: install })\n}\n\nexport default {\n install,\n Portal,\n PortalTarget,\n Wormhole,\n}\n"],"names":["extractAttributes","el","map","hasAttributes","attributes","attrs","i","length","attr","value","name","freeze","item","Array","isArray","Object","transports","Wormhole","transport","to","from","passengers","keys","includes","set","force","undefined","hasOwnProperty","hasTarget","wormhole","type","String","required","Boolean","default","$set","unwatch","$watch","emitChange","updateAttributes","$el","innerHTML","class","trim","split","forEach","klass","classList","add","setAttribute","newTransport","oldTransport","$emit","$slots","children","slim","h","Tag","tag","renderSlim","inBrowser","window","pid","HTMLElement","Math","round","random","targetEl","mountToTarget","disabled","sendUpdate","clear","mountedComp","$destroy","newValue","oldValue","open","warn","target","close","document","querySelector","Vue","Target","tagName","$mount","install","opts","component","portalName","Portal","portalTargetName","PortalTarget","use"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAASA,iBAAT,CAA4BC,EAA5B,EAAgC;MAC/BC,MAAMD,GAAGE,aAAH,KAAqBF,GAAGG,UAAxB,GAAqC,EAAjD;MACMC,QAAQ,EAAd;OACK,IAAIC,IAAI,CAAb,EAAgBA,IAAIJ,IAAIK,MAAxB,EAAgCD,GAAhC,EAAqC;QAC7BE,OAAON,IAAII,CAAJ,CAAb;QACIE,KAAKC,KAAT,EAAgB;YACRD,KAAKE,IAAX,IAAmBF,KA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eAAvC,EAAwDC,MAAxD;;AAEF,IAAI,OAAO/B,MAAP,KAAkB,WAAlB,IAAiCA,OAAOqB,GAA5C,EAAiD;SACxCA,GAAP,CAAWW,GAAX,CAAe,EAAEP,SAASA,OAAX,EAAf;;;AAGF,YAAe;kBAAA;gBAAA;sBAAA;;CAAf;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"portal-vue.js","sources":["../src/utils.js","../src/components/wormhole.js","../src/components/portal-target.js","../src/components/portal.js","../src/index.js"],"sourcesContent":["export function extractAttributes (el) {\n const map = el.hasAttributes() ? el.attributes : []\n const attrs = {}\n for (let i = 0; i < map.length; i++) {\n const attr = map[i]\n if (attr.value) {\n attrs[attr.name] = attr.value === '' ? true : attr.value\n }\n }\n return attrs\n}\n\nexport function freeze (item) {\n if (Array.isArray(item) || typeof item === 'object') {\n return Object.freeze(item)\n }\n return item\n}\n","import Vue from 'vue'\nimport { freeze } from '../utils'\nconst transports = {}\n\nexport { transports }\n\nexport class Wormhole {\n constructor (transports) {\n this.transports = transports\n }\n\n open (transport) {\n const { to, from, passengers } = transport\n if (!to || !from || !passengers) return\n\n transport.passengers = freeze(passengers)\n const keys = Object.keys(this.transports)\n if (keys.includes(to)) {\n this.transports[to] = transport\n } else {\n Vue.set(this.transports, to, transport)\n }\n }\n\n close (transport, force = false) {\n const { to, from } = transport\n if (!to || !from) return\n if (this.transports[to] && (force || this.transports[to].from === from)) {\n this.transports[to] = undefined\n }\n }\n\n hasTarget (to) {\n return this.transports.hasOwnProperty(to)\n }\n\n hasContentFor (to) {\n /* eslint no-unneeded-ternary: 0 */\n return (this.transports[to] && this.transports[to].passengers != null) ? true : false\n }\n\n getSourceFor (to) {\n return this.transports[to] && this.transports[to].from\n }\n\n getContentFor (to) {\n const transport = this.transports[to]\n return transport ? transport.passengers : undefined\n }\n\n}\nconst wormhole = new Wormhole(transports)\nexport default wormhole\n","\nimport { transports } from './wormhole'\n\nexport default {\n abstract: true,\n name: 'portalTarget',\n props: {\n attributes: { type: Object },\n name: { type: String, required: true },\n slim: { type: Boolean, default: false },\n tag: { type: String, default: 'div' },\n },\n data () {\n return {\n transports,\n }\n },\n\n mounted () {\n if (!this.transports[this.name]) {\n this.$set(this.transports, this.name, undefined)\n }\n\n this.unwatch = this.$watch(function () { return this.transports[this.name] }, this.emitChange)\n\n this.updateAttributes()\n },\n updated () {\n this.updateAttributes()\n },\n beforeDestroy () {\n this.unwatch()\n this.$el.innerHTML = ''\n },\n\n methods: {\n updateAttributes () {\n if (this.attributes) {\n const attrs = this.attributes\n const el = this.$el\n\n // special treatment for class\n if (attrs.class) {\n attrs.class.trim().split(' ').forEach((klass) => {\n el.classList.add(klass)\n })\n delete attrs.class\n }\n\n const keys = Object.keys(attrs)\n\n for (let i = 0; i < keys.length; i++) {\n el.setAttribute(keys[i], attrs[keys[i]])\n }\n }\n },\n emitChange (newTransport, oldTransport) {\n this.$emit('change',\n { ...newTransport },\n { ...oldTransport }\n )\n },\n },\n computed: {\n passengers () {\n return (this.transports[this.name] && this.transports[this.name].passengers) || []\n },\n children () {\n return this.passengers.length !== 0 ? this.passengers : (this.$slots.default || [])\n },\n renderSlim () {\n const children = this.children\n return children.length === 1 && !this.attributes && this.slim\n },\n },\n\n render (h) {\n const children = this.children\n const Tag = this.tag\n if (this.renderSlim) {\n return children[0]\n } else {\n return ({children})\n }\n },\n}\n","\nimport Vue from 'vue'\nimport wormhole from './wormhole'\nimport Target from './portal-target'\nimport { extractAttributes } from '../utils'\n\nconst inBrowser = (typeof window !== 'undefined')\n\nlet pid = 1\n\nexport default {\n abstract: true,\n name: 'portal',\n props: {\n /* global HTMLElement */\n disabled: { type: Boolean, default: false },\n name: { type: String, default: () => String(pid++) },\n slim: { type: Boolean, default: false },\n tag: { type: [String], default: 'DIV' },\n targetEl: { type: inBrowser ? [String, HTMLElement] : String },\n to: { type: String, default: () => String(Math.round(Math.random() * 10000000)) },\n },\n\n mounted () {\n if (this.targetEl) {\n this.mountToTarget()\n }\n if (!this.disabled) {\n this.sendUpdate()\n }\n },\n\n updated () {\n if (this.disabled) {\n this.clear()\n } else {\n this.sendUpdate()\n }\n },\n\n beforeDestroy () {\n this.clear()\n if (this.mountedComp) {\n this.mountedComp.$destroy()\n }\n },\n\n watch: {\n to (newValue, oldValue) {\n oldValue && this.clear(oldValue)\n this.sendUpdate()\n },\n targetEl (newValue, oldValue) {\n this.mountToTarget()\n },\n },\n\n methods: {\n\n sendUpdate () {\n if (this.to) {\n if (this.$slots.default) {\n wormhole.open({\n from: this.name,\n to: this.to,\n passengers: [...this.$slots.default],\n })\n }\n } else if (!this.to && !this.targetEl) {\n console.warn('[vue-portal]: You have to define a target via the `to` prop.')\n }\n },\n\n clear (target) {\n wormhole.close({\n from: this.name,\n to: target || this.to,\n })\n },\n\n mountToTarget () {\n let el\n const target = this.targetEl\n\n if (typeof target === 'string') {\n el = document.querySelector(this.targetEl)\n } else if (target instanceof HTMLElement) {\n el = target\n } else {\n console.warn('[vue-portal]: value of targetEl must be of type String or HTMLElement')\n return\n }\n\n const attributes = extractAttributes(el)\n\n if (el) {\n const target = new Vue({\n ...Target,\n parent: this,\n propsData: {\n name: this.to,\n tag: el.tagName,\n attributes,\n },\n })\n target.$mount(el)\n this.mountedComp = target\n } else {\n console.warn('[vue-portal]: The specified targetEl ' + this.targetEl + ' was not found')\n }\n },\n },\n\n render (h) {\n const children = this.$slots.default || []\n const Tag = this.tag\n if (children.length && this.disabled) {\n return children.length <= 1 && this.slim\n ? children[0]\n : ({children})\n } else {\n return ()\n // h(this.tag, { class: { 'v-portal': true }, style: { display: 'none' }, key: 'v-portal-placeholder' })\n }\n },\n}\n","import Portal from './components/portal.js'\nimport PortalTarget from './components/portal-target.js'\nimport Wormhole from './components/wormhole.js'\n\nfunction install (Vue, opts = {}) {\n Vue.component(opts.portalName || 'portal', Portal)\n Vue.component(opts.portalTargetName || 'portal-target', PortalTarget)\n}\nif (typeof window !== 'undefined' && window.Vue) {\n window.Vue.use({ install: install })\n}\n\nexport default {\n install,\n Portal,\n PortalTarget,\n Wormhole,\n}\n"],"names":["extractAttributes","el","map","hasAttributes","attributes","attrs","i","length","attr","value","name","freeze","item","Array","isArray","Object","transports","Wormhole","transport","to","from","passengers","keys","includes","set","force","undefined","hasOwnProperty","wormhole","type","String","required","Boolean","default","$set","unwatch","$watch","emitChange","updateAttributes","$el","innerHTML","class","trim","split","forEach","klass","classList","add","setAttribute","newTransport","oldTransport","$emit","$slots","children","slim","h","Tag","tag","renderSlim","inBrowser","window","pid","HTMLElement","Math","round","random","targetEl","mountToTarget","disabled","sendUpdate","clear","mountedComp","$destroy","newValue","oldValue","open","warn","target","close","document","querySelector","Vue","Target","tagName","$mount","install","opts","component","portalName","Portal","portalTargetName","PortalTarget","use"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAO,SAASA,iBAAT,CAA4BC,EAA5B,EAAgC;MAC/BC,MAAMD,GAAGE,aAAH,KAAqBF,GAAGG,UAAxB,GAAqC,EAAjD;MACMC,QAAQ,EAAd;OACK,IAAIC,IAAI,CAAb,EAAgBA,IAAIJ,IAAIK,MAAxB,EAAgCD,GAAhC,EAAqC;QAC7BE,OAAON,IAAII,CAAJ,CAAb;QACIE,KAAKC,KAAT,EAAgB;YACRD,KAAKE,IAAX,IAAmBF,KAAKC,KAAL,KAAe,EAAf,GAAoB,IAApB,GAA2BD,KAAKC,KAAnD;;;SAGGJ,KAAP;;;AAGF,AAAO,SAASM,MAAT,CAAiBC,IAAjB,EAAuB;MACxBC,MAAMC,OAAN,CAAcF,IAAd,KAAuB,QAAOA,IAAP,yCAAOA,IAAP,OAAgB,QAA3C,EAAqD;WAC5CG,OAAOJ,MAAP,CAAcC,IAAd,CAAP;;SAEKA,IAAP;;;ACdF,IAAMI,aAAa,EAAnB;;AAEA,IAEaC,QAAb;oBACeD,UA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dist/portal-vue.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("vue")):"function"==typeof define&&define.amd?define(["vue"],e):t.PortalVue=e(t.Vue)}(this,function(t){"use strict";function e(t){for(var e=t.hasAttributes()?t.attributes:[],n={},r=0;r1&&void 0!==arguments[1]?arguments[1]:{};t.component(e.portalName||"portal",m),t.component(e.portalTargetName||"portal-target",p)}t=t&&"default"in t?t.default:t;var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},a=function(){function t(t,e){for(var n=0;n1&&void 0!==arguments[1]&&arguments[1],n=t.to,r=t.from;n&&r&&this.transports[n]&&(e||this.transports[n].from===r)&&(this.transports[n]=void 0)}},{key:"hasTarget",value:function(t){return this.transports.hasOwnProperty(t)}},{key:"hasContentFor",value:function(t){return this.hasTarget(t)&&null!=this.transports[t].passengers}},{key:"getSourceFor",value:function(t){return this.transports[t]&&this.transports[t].from}},{key:"getContentFor",value:function(t){var e=this.transports[t];return e?e.passengers:void 0}}]),e}(),f=new h(l),p={abstract:!0,name:"portalTarget",props:{attributes:{type:Object},name:{type:String,required:!0},slim:{type:Boolean,default:!1},tag:{type:String,default:"div"}},data:function(){return{transports:l}},mounted:function(){this.transports[this.name]||this.$set(this.transports,this.name,void 0),this.unwatch=this.$watch(function(){return this.transports[this.name]},this.emitChange),this.updateAttributes()},updated:function(){this.updateAttributes()},beforeDestroy:function(){this.unwatch(),this.$el.innerHTML=""},methods:{updateAttributes:function(){if(this.attributes){var t=this.attributes,e=this.$el;t.class&&(t.class.trim().split(" ").forEach(function(t){e.classList.add(t)}),delete t.class);for(var n=Object.keys(t),r=0;r1&&void 0!==arguments[1]?arguments[1]:{};t.component(e.portalName||"portal",m),t.component(e.portalTargetName||"portal-target",p)}t=t&&"default"in t?t.default:t;var s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},a=function(){function t(t,e){for(var n=0;n1&&void 0!==arguments[1]&&arguments[1],n=t.to,r=t.from;n&&r&&this.transports[n]&&(e||this.transports[n].from===r)&&(this.transports[n]=void 0)}},{key:"hasTarget",value:function(t){return this.transports.hasOwnProperty(t)}},{key:"hasContentFor",value:function(t){return!(!this.transports[t]||null==this.transports[t].passengers)}},{key:"getSourceFor",value:function(t){return this.transports[t]&&this.transports[t].from}},{key:"getContentFor",value:function(t){var e=this.transports[t];return e?e.passengers:void 0}}]),e}(),f=new h(l),p={abstract:!0,name:"portalTarget",props:{attributes:{type:Object},name:{type:String,required:!0},slim:{type:Boolean,default:!1},tag:{type:String,default:"div"}},data:function(){return{transports:l}},mounted:function(){this.transports[this.name]||this.$set(this.transports,this.name,void 0),this.unwatch=this.$watch(function(){return this.transports[this.name]},this.emitChange),this.updateAttributes()},updated:function(){this.updateAttributes()},beforeDestroy:function(){this.unwatch(),this.$el.innerHTML=""},methods:{updateAttributes:function(){if(this.attributes){var t=this.attributes,e=this.$el;t.class&&(t.class.trim().split(" ").forEach(function(t){e.classList.add(t)}),delete t.class);for(var n=Object.keys(t),r=0;r