UNPKG

2.46 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],e):e(t.CuriVue={},t.Vue)}(this,function(t,i){"use strict";i=i&&i.hasOwnProperty("default")?i.default:i;var o={name:"curi-link",props:["to","params","hash","query","state","click"],computed:{location:function(){var t=this.to?this.$router.route.pathname(this.to,this.params):this.$curi.response.location.pathname;return{hash:this.hash,query:this.query,state:this.state,pathname:t}},href:function(){return this.$router.history.toHref(this.location)}},data:function(){return{navigating:!1}},methods:{clickHandler:function(t){var e,i=this;if(this.click&&this.click(t),!(e=t).defaultPrevented&&void 0!==e.button&&0===e.button&&!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)){t.preventDefault();var n=void 0,o=void 0;this.$scopedSlots.default&&(n=o=function(){i.navigating=!1},this.navigating=!0),this.$router.navigate({name:this.to,params:this.params,hash:this.hash,query:this.query,state:this.state,cancelled:n,finished:o})}}},render:function(t){return t("a",{attrs:{href:this.href},on:{click:this.clickHandler}},this.$scopedSlots.default?this.$scopedSlots.default({navigating:this.navigating}):this.$slots.default)}},r={name:"curi-block",props:{active:{type:Boolean,default:!0},confirm:{type:Function,required:!0}},methods:{on:function(){this.$router.history.confirmWith(this.confirm)},off:function(){this.$router.history.removeConfirmation()},update:function(){this.off(),this.active&&this.on()}},beforeMount:function(){this.active&&this.on()},watch:{active:function(){this.update()},confirm:function(){this.update()}},beforeDestroy:function(){this.off()},render:function(t){return null}};function n(t,e){var i=e.preserve,n=void 0!==i&&i,o=e.preventScroll,r=void 0!==o&&o;n&&t.contains(document.activeElement)||setTimeout(function(){t.focus({preventScroll:r})})}var a={inserted:function(t,e){n(t,e.value)},update:function(t,e){e.value.key!==e.oldValue.key&&n(t,e.value)}},e={install:function(t,e){t.component(o.name,o),t.component(r.name,r),t.directive("curi-focus",a);var n=new i({data:{response:null,navigation:null}});e.router.observe(function(t){var e=t.response,i=t.navigation;n.response=e,n.navigation=i}),t.mixin({beforeCreate:function(){this.$curi=n}}),Object.defineProperty(t.prototype,"$router",{get:function(){return e.router}})}};t.CuriPlugin=e,Object.defineProperty(t,"__esModule",{value:!0})});