moodle_local_treestudyplan/amd/build/portal-vue/portal-vue.esm.min.js
2023-12-02 23:22:00 +01:00

3 lines
9.8 KiB
JavaScript

define("local_treestudyplan/portal-vue/portal-vue.esm",["exports","../vue/vue"],(function(_exports,_vue){var obj;function _typeof(obj){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}function _toConsumableArray(arr){return function(arr){if(Array.isArray(arr)){for(var i=0,arr2=new Array(arr.length);i<arr.length;i++)arr2[i]=arr[i];return arr2}}(arr)||function(iter){if(Symbol.iterator in Object(iter)||"[object Arguments]"===Object.prototype.toString.call(iter))return Array.from(iter)}(arr)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=_exports.Wormhole=_exports.PortalTarget=_exports.Portal=_exports.MountingPortal=void 0,_vue=(obj=_vue)&&obj.__esModule?obj:{default:obj};var inBrowser="undefined"!=typeof window;function pick(obj,keys){return keys.reduce((function(acc,key){return obj.hasOwnProperty(key)&&(acc[key]=obj[key]),acc}),{})}var transports={},targets={},sources={},Wormhole=_vue.default.extend({data:function(){return{transports:transports,targets:targets,sources:sources,trackInstances:inBrowser}},methods:{open:function(transport){if(inBrowser){var to=transport.to,from=transport.from,passengers=transport.passengers,_transport$order=transport.order,order=void 0===_transport$order?1/0:_transport$order;if(to&&from&&passengers){var item,newTransport={to:to,from:from,passengers:(item=passengers,Array.isArray(item)||"object"===_typeof(item)?Object.freeze(item):item),order:order};-1===Object.keys(this.transports).indexOf(to)&&_vue.default.set(this.transports,to,[]);var compareFn,currentIndex=this.$_getTransportIndex(newTransport),newTransports=this.transports[to].slice(0);-1===currentIndex?newTransports.push(newTransport):newTransports[currentIndex]=newTransport,this.transports[to]=(compareFn=function(a,b){return a.order-b.order},newTransports.map((function(v,idx){return[idx,v]})).sort((function(a,b){return compareFn(a[1],b[1])||a[0]-b[0]})).map((function(c){return c[1]})))}}},close:function(transport){var force=arguments.length>1&&void 0!==arguments[1]&&arguments[1],to=transport.to,from=transport.from;if(to&&(from||!1!==force)&&this.transports[to])if(force)this.transports[to]=[];else{var index=this.$_getTransportIndex(transport);if(index>=0){var newTransports=this.transports[to].slice(0);newTransports.splice(index,1),this.transports[to]=newTransports}}},registerTarget:function(target,vm,force){inBrowser&&(this.trackInstances&&!force&&this.targets[target]&&console.warn("[portal-vue]: Target ".concat(target," already exists")),this.$set(this.targets,target,Object.freeze([vm])))},unregisterTarget:function(target){this.$delete(this.targets,target)},registerSource:function(source,vm,force){inBrowser&&(this.trackInstances&&!force&&this.sources[source]&&console.warn("[portal-vue]: source ".concat(source," already exists")),this.$set(this.sources,source,Object.freeze([vm])))},unregisterSource:function(source){this.$delete(this.sources,source)},hasTarget:function(to){return!(!this.targets[to]||!this.targets[to][0])},hasSource:function(to){return!(!this.sources[to]||!this.sources[to][0])},hasContentFor:function(to){return!!this.transports[to]&&!!this.transports[to].length},$_getTransportIndex:function(_ref){var to=_ref.to,from=_ref.from;for(var i in this.transports[to])if(this.transports[to][i].from===from)return+i;return-1}}}),wormhole=new Wormhole(transports);_exports.Wormhole=wormhole;var _id=1,Portal=_vue.default.extend({name:"portal",props:{disabled:{type:Boolean},name:{type:String,default:function(){return String(_id++)}},order:{type:Number,default:0},slim:{type:Boolean},slotProps:{type:Object,default:function(){return{}}},tag:{type:String,default:"DIV"},to:{type:String,default:function(){return String(Math.round(1e7*Math.random()))}}},created:function(){var _this=this;this.$nextTick((function(){wormhole.registerSource(_this.name,_this)}))},mounted:function(){this.disabled||this.sendUpdate()},updated:function(){this.disabled?this.clear():this.sendUpdate()},beforeDestroy:function(){wormhole.unregisterSource(this.name),this.clear()},watch:{to:function(newValue,oldValue){oldValue&&oldValue!==newValue&&this.clear(oldValue),this.sendUpdate()}},methods:{clear:function(target){var closer={from:this.name,to:target||this.to};wormhole.close(closer)},normalizeSlots:function(){return this.$scopedSlots.default?[this.$scopedSlots.default]:this.$slots.default},normalizeOwnChildren:function(children){return"function"==typeof children?children(this.slotProps):children},sendUpdate:function(){var slotContent=this.normalizeSlots();if(slotContent){var transport={from:this.name,to:this.to,passengers:_toConsumableArray(slotContent),order:this.order};wormhole.open(transport)}else this.clear()}},render:function(h){var children=this.$slots.default||this.$scopedSlots.default||[],Tag=this.tag;return children&&this.disabled?children.length<=1&&this.slim?this.normalizeOwnChildren(children)[0]:h(Tag,[this.normalizeOwnChildren(children)]):this.slim?h():h(Tag,{class:{"v-portal":!0},style:{display:"none"},key:"v-portal-placeholder"})}});_exports.Portal=Portal;var PortalTarget=_vue.default.extend({name:"portalTarget",props:{multiple:{type:Boolean,default:!1},name:{type:String,required:!0},slim:{type:Boolean,default:!1},slotProps:{type:Object,default:function(){return{}}},tag:{type:String,default:"div"},transition:{type:[String,Object,Function]}},data:function(){return{transports:wormhole.transports,firstRender:!0}},created:function(){var _this=this;this.$nextTick((function(){wormhole.registerTarget(_this.name,_this)}))},watch:{ownTransports:function(){this.$emit("change",this.children().length>0)},name:function(newVal,oldVal){wormhole.unregisterTarget(oldVal),wormhole.registerTarget(newVal,this)}},mounted:function(){var _this2=this;this.transition&&this.$nextTick((function(){_this2.firstRender=!1}))},beforeDestroy:function(){wormhole.unregisterTarget(this.name)},computed:{ownTransports:function(){var transports=this.transports[this.name]||[];return this.multiple?transports:0===transports.length?[]:[transports[transports.length-1]]},passengers:function(){return function(transports){var slotProps=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return transports.reduce((function(passengers,transport){var temp=transport.passengers[0],newPassengers="function"==typeof temp?temp(slotProps):transport.passengers;return passengers.concat(newPassengers)}),[])}(this.ownTransports,this.slotProps)}},methods:{children:function(){return 0!==this.passengers.length?this.passengers:this.$scopedSlots.default?this.$scopedSlots.default(this.slotProps):this.$slots.default||[]},noWrapper:function(){var noWrapper=this.slim&&!this.transition;return noWrapper&&this.children().length>1&&console.warn("[portal-vue]: PortalTarget with `slim` option received more than one child element."),noWrapper}},render:function(h){var noWrapper=this.noWrapper(),children=this.children(),Tag=this.transition||this.tag;return noWrapper?children[0]:this.slim&&!Tag?h():h(Tag,{props:{tag:this.transition&&this.tag?this.tag:void 0},class:{"vue-portal-target":!0}},children)}});_exports.PortalTarget=PortalTarget;var _id$1=0,portalProps=["disabled","name","order","slim","slotProps","tag","to"],targetProps=["multiple","transition"],MountingPortal=_vue.default.extend({name:"MountingPortal",inheritAttrs:!1,props:{append:{type:[Boolean,String]},bail:{type:Boolean},mountTo:{type:String,required:!0},disabled:{type:Boolean},name:{type:String,default:function(){return"mounted_"+String(_id$1++)}},order:{type:Number,default:0},slim:{type:Boolean},slotProps:{type:Object,default:function(){return{}}},tag:{type:String,default:"DIV"},to:{type:String,default:function(){return String(Math.round(1e7*Math.random()))}},multiple:{type:Boolean,default:!1},targetSlim:{type:Boolean},targetSlotProps:{type:Object,default:function(){return{}}},targetTag:{type:String,default:"div"},transition:{type:[String,Object,Function]}},created:function(){if("undefined"!=typeof document){var el=document.querySelector(this.mountTo);if(el){var props=this.$props;if(wormhole.targets[props.name])props.bail?console.warn("[portal-vue]: Target ".concat(props.name," is already mounted.\n Aborting because 'bail: true' is set")):this.portalTarget=wormhole.targets[props.name];else{var append=props.append;if(append){var type="string"==typeof append?append:"DIV",mountEl=document.createElement(type);el.appendChild(mountEl),el=mountEl}var _props=pick(this.$props,targetProps);_props.slim=this.targetSlim,_props.tag=this.targetTag,_props.slotProps=this.targetSlotProps,_props.name=this.to,this.portalTarget=new PortalTarget({el:el,parent:this.$parent||this,propsData:_props})}}else console.error("[portal-vue]: Mount Point '".concat(this.mountTo,"' not found in document"))}},beforeDestroy:function(){var target=this.portalTarget;if(this.append){var el=target.$el;el.parentNode.removeChild(el)}target.$destroy()},render:function(h){if(!this.portalTarget)return console.warn("[portal-vue] Target wasn't mounted"),h();if(!this.$scopedSlots.manual){var props=pick(this.$props,portalProps);return h(Portal,{props:props,attrs:this.$attrs,on:this.$listeners,scopedSlots:this.$scopedSlots},this.$slots.default)}var content=this.$scopedSlots.manual({to:this.to});return Array.isArray(content)&&(content=content[0]),content||h()}});_exports.MountingPortal=MountingPortal;var index={install:function(Vue$$1){var options=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};Vue$$1.component(options.portalName||"Portal",Portal),Vue$$1.component(options.portalTargetName||"PortalTarget",PortalTarget),Vue$$1.component(options.MountingPortalName||"MountingPortal",MountingPortal)}},_default2=index;return _exports.default=_default2,_exports.default}));
//# sourceMappingURL=portal-vue.esm.min.js.map