primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
2 lines (1 loc) • 13.7 kB
JavaScript
this.primevue=this.primevue||{},this.primevue.speeddial=function(e,t,n,i,o,r,c,a){"use strict";function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=s(e),u=s(t),d=s(n),f=s(i);function m(e){return m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},m(e)}function p(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function h(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?p(Object(n),!0).forEach((function(t){v(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function v(e,t,n){var i;return(t="symbol"==m(i=b(t,"string"))?i:String(i))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function b(e,t){if("object"!=m(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=m(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function y(e){return w(e)||I(e)||k(e)||g()}function g(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function k(e,t){if(e){if("string"==typeof e)return x(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(e,t):void 0}}function I(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function w(e){if(Array.isArray(e))return x(e)}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}var D={name:"SpeedDial",extends:{name:"BaseSpeedDial",extends:s(r).default,props:{model:null,visible:{type:Boolean,default:!1},direction:{type:String,default:"up"},transitionDelay:{type:Number,default:30},type:{type:String,default:"linear"},radius:{type:Number,default:0},mask:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},hideOnClickOutside:{type:Boolean,default:!0},buttonClass:null,maskStyle:null,maskClass:null,showIcon:{type:String,default:void 0},hideIcon:{type:String,default:void 0},rotateAnimation:{type:Boolean,default:!0},tooltipOptions:null,style:null,class:null,ariaLabelledby:{type:String,default:null},ariaLabel:{type:String,default:null}},style:s(c).default,provide:function(){return{$parentInstance:this}}},emits:["click","show","hide","focus","blur"],documentClickListener:null,container:null,list:null,data:function(){return{id:this.$attrs.id,d_visible:this.visible,isItemClicked:!1,focused:!1,focusedOptionIndex:-1}},watch:{"$attrs.id":function(e){this.id=e||o.UniqueComponentId()},visible:function(e){this.d_visible=e}},mounted:function(){if(this.id=this.id||o.UniqueComponentId(),"linear"!==this.type){var e=o.DomHandler.findSingle(this.container,'[data-pc-name="button"]'),t=o.DomHandler.findSingle(this.list,'[data-pc-section="menuitem"]');if(e&&t){var n=Math.abs(e.offsetWidth-t.offsetWidth),i=Math.abs(e.offsetHeight-t.offsetHeight);this.list.style.setProperty("--item-diff-x","".concat(n/2,"px")),this.list.style.setProperty("--item-diff-y","".concat(i/2,"px"))}}this.hideOnClickOutside&&this.bindDocumentClickListener()},beforeMount:function(){this.unbindDocumentClickListener()},methods:{getPTOptions:function(e,t){return this.ptm(t,{context:{active:this.isItemActive(e),hidden:!this.d_visible}})},onFocus:function(e){this.focused=!0,this.$emit("focus",e)},onBlur:function(e){this.focused=!1,this.focusedOptionIndex=-1,this.$emit("blur",e)},onItemClick:function(e,t){t.command&&t.command({originalEvent:e,item:t}),this.hide(),this.isItemClicked=!0,e.preventDefault()},onClick:function(e){this.d_visible?this.hide():this.show(),this.isItemClicked=!0,this.$emit("click",e)},show:function(){this.d_visible=!0,this.$emit("show")},hide:function(){this.d_visible=!1,this.$emit("hide")},calculateTransitionDelay:function(e){return(this.d_visible?e:this.model.length-e-1)*this.transitionDelay},onTogglerKeydown:function(e){switch(e.code){case"ArrowDown":case"ArrowLeft":this.onTogglerArrowDown(e);break;case"ArrowUp":case"ArrowRight":this.onTogglerArrowUp(e);break;case"Escape":this.onEscapeKey()}},onKeyDown:function(e){switch(e.code){case"ArrowDown":this.onArrowDown(e);break;case"ArrowUp":this.onArrowUp(e);break;case"ArrowLeft":this.onArrowLeft(e);break;case"ArrowRight":this.onArrowRight(e);break;case"Enter":case"NumpadEnter":case"Space":this.onEnterKey(e);break;case"Escape":this.onEscapeKey(e);break;case"Home":this.onHomeKey(e);break;case"End":this.onEndKey(e)}},onTogglerArrowUp:function(e){this.focused=!0,o.DomHandler.focus(this.list),this.show(),this.navigatePrevItem(e),e.preventDefault()},onTogglerArrowDown:function(e){this.focused=!0,o.DomHandler.focus(this.list),this.show(),this.navigateNextItem(e),e.preventDefault()},onEnterKey:function(e){var t=this,n=y(o.DomHandler.find(this.container,'[data-pc-section="menuitem"]')).findIndex((function(e){return e.id===t.focusedOptionIndex}));this.onItemClick(e,this.model[n]),this.onBlur(e);var i=o.DomHandler.findSingle(this.container,"button");i&&o.DomHandler.focus(i)},onEscapeKey:function(){this.hide();var e=o.DomHandler.findSingle(this.container,"button");e&&o.DomHandler.focus(e)},onArrowUp:function(e){"up"===this.direction?this.navigateNextItem(e):"down"===this.direction?this.navigatePrevItem(e):this.navigateNextItem(e)},onArrowDown:function(e){"up"===this.direction?this.navigatePrevItem(e):"down"===this.direction?this.navigateNextItem(e):this.navigatePrevItem(e)},onArrowLeft:function(e){["left","up-right","down-left"].includes(this.direction)?this.navigateNextItem(e):(["right","up-left","down-right"].includes(this.direction),this.navigatePrevItem(e))},onArrowRight:function(e){["left","up-right","down-left"].includes(this.direction)?this.navigatePrevItem(e):(["right","up-left","down-right"].includes(this.direction),this.navigateNextItem(e))},onEndKey:function(e){e.preventDefault(),this.focusedOptionIndex=-1,this.navigatePrevItem(e)},onHomeKey:function(e){e.preventDefault(),this.focusedOptionIndex=-1,this.navigateNextItem(e)},navigateNextItem:function(e){var t=this.findNextOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(t),e.preventDefault()},navigatePrevItem:function(e){var t=this.findPrevOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(t),e.preventDefault()},changeFocusedOptionIndex:function(e){var t=y(o.DomHandler.find(this.container,'[data-pc-section="menuitem"]')).filter((function(e){return!o.DomHandler.hasClass(o.DomHandler.findSingle(e,"a"),"p-disabled")}));t[e]&&(this.focusedOptionIndex=t[e].getAttribute("id"))},findPrevOptionIndex:function(e){var t=y(o.DomHandler.find(this.container,'[data-pc-section="menuitem"]')).filter((function(e){return!o.DomHandler.hasClass(o.DomHandler.findSingle(e,"a"),"p-disabled")})),n=-1===e?t[t.length-1].id:e,i=t.findIndex((function(e){return e.getAttribute("id")===n}));return i=-1===e?t.length-1:i-1},findNextOptionIndex:function(e){var t=y(o.DomHandler.find(this.container,'[data-pc-section="menuitem"]')).filter((function(e){return!o.DomHandler.hasClass(o.DomHandler.findSingle(e,"a"),"p-disabled")})),n=-1===e?t[0].id:e,i=t.findIndex((function(e){return e.getAttribute("id")===n}));return i=-1===e?0:i+1},calculatePointStyle:function(e){var t=this.type;if("linear"!==t){var n=this.model.length,i=this.radius||20*n;if("circle"===t){var o=2*Math.PI/n;return{left:"calc(".concat(i*Math.cos(o*e),"px + var(--item-diff-x, 0px))"),top:"calc(".concat(i*Math.sin(o*e),"px + var(--item-diff-y, 0px))")}}if("semi-circle"===t){var r=this.direction,c=Math.PI/(n-1),a="calc(".concat(i*Math.cos(c*e),"px + var(--item-diff-x, 0px))"),s="calc(".concat(i*Math.sin(c*e),"px + var(--item-diff-y, 0px))");if("up"===r)return{left:a,bottom:s};if("down"===r)return{left:a,top:s};if("left"===r)return{right:s,top:a};if("right"===r)return{left:s,top:a}}else if("quarter-circle"===t){var l=this.direction,u=Math.PI/(2*(n-1)),d="calc(".concat(i*Math.cos(u*e),"px + var(--item-diff-x, 0px))"),f="calc(".concat(i*Math.sin(u*e),"px + var(--item-diff-y, 0px))");if("up-left"===l)return{right:d,bottom:f};if("up-right"===l)return{left:d,bottom:f};if("down-left"===l)return{right:f,top:d};if("down-right"===l)return{left:f,top:d}}}return{}},getItemStyle:function(e){var t=this.calculateTransitionDelay(e),n=this.calculatePointStyle(e);return h({transitionDelay:"".concat(t,"ms")},n)},bindDocumentClickListener:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.d_visible&&e.isOutsideClicked(t)&&e.hide(),e.isItemClicked=!1},document.addEventListener("click",this.documentClickListener))},unbindDocumentClickListener:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)},isOutsideClicked:function(e){return this.container&&!(this.container.isSameNode(e.target)||this.container.contains(e.target)||this.isItemClicked)},isItemVisible:function(e){return"function"==typeof e.visible?e.visible():!1!==e.visible},isItemActive:function(e){return e===this.focusedOptionId},containerRef:function(e){this.container=e},listRef:function(e){this.list=e}},computed:{containerClass:function(){return[this.cx("root"),this.class]},focusedOptionId:function(){return-1!==this.focusedOptionIndex?this.focusedOptionIndex:null}},components:{SDButton:l.default,PlusIcon:u.default},directives:{ripple:d.default,tooltip:f.default}},C=["id","aria-activedescendant"],O=["id","aria-controls"],P=["href","target","onClick","aria-label"];return D.render=function(e,t,n,i,o,r){var c=a.resolveComponent("SDButton"),s=a.resolveDirective("ripple"),l=a.resolveDirective("tooltip");return a.openBlock(),a.createElementBlock(a.Fragment,null,[a.createElementVNode("div",a.mergeProps({ref:r.containerRef,class:r.containerClass,style:[e.style,e.sx("root")]},e.ptm("root"),{"data-pc-name":"speeddial"}),[a.renderSlot(e.$slots,"button",{onClick:r.onClick,toggleCallback:r.onClick},(function(){return[a.createVNode(c,{type:"button",class:a.normalizeClass([e.cx("button"),e.buttonClass]),onClick:t[0]||(t[0]=function(e){return r.onClick(e)}),disabled:e.disabled,onKeydown:r.onTogglerKeydown,"aria-expanded":o.d_visible,"aria-haspopup":!0,"aria-controls":o.id+"_list","aria-label":e.ariaLabel,"aria-labelledby":e.ariaLabelledby,pt:e.ptm("button"),unstyled:e.unstyled},{icon:a.withCtx((function(){return[a.renderSlot(e.$slots,"icon",{visible:o.d_visible},(function(){return[o.d_visible&&e.hideIcon?(a.openBlock(),a.createBlock(a.resolveDynamicComponent(e.hideIcon?"span":"PlusIcon"),a.mergeProps({key:0,class:e.cx("buttonIcon")},e.ptm("button").icon,{"data-pc-section":"icon"}),null,16,["class"])):(a.openBlock(),a.createBlock(a.resolveDynamicComponent(e.showIcon?"span":"PlusIcon"),a.mergeProps({key:1,class:o.d_visible&&e.hideIcon?e.hideIcon:e.showIcon},e.ptm("button").icon,{"data-pc-section":"icon"}),null,16,["class"]))]}))]})),_:3},8,["class","disabled","onKeydown","aria-expanded","aria-controls","aria-label","aria-labelledby","pt","unstyled"])]})),a.createElementVNode("ul",a.mergeProps({ref:r.listRef,id:o.id+"_list",class:e.cx("menu"),style:e.sx("menu"),role:"menu","aria-activedescendant":o.focused?r.focusedOptionId:void 0,tabindex:"-1",onFocus:t[1]||(t[1]=function(){return r.onFocus&&r.onFocus.apply(r,arguments)}),onBlur:t[2]||(t[2]=function(){return r.onBlur&&r.onBlur.apply(r,arguments)}),onKeydown:t[3]||(t[3]=function(){return r.onKeyDown&&r.onKeyDown.apply(r,arguments)})},e.ptm("menu")),[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(e.model,(function(t,n){return a.openBlock(),a.createElementBlock(a.Fragment,{key:n},[r.isItemVisible(t)?(a.openBlock(),a.createElementBlock("li",a.mergeProps({key:0,id:"".concat(o.id,"_").concat(n),"aria-controls":"".concat(o.id,"_item"),class:e.cx("menuitem",{id:"".concat(o.id,"_").concat(n)}),style:r.getItemStyle(n),role:"menuitem"},r.getPTOptions("".concat(o.id,"_").concat(n),"menuitem")),[e.$slots.item?(a.openBlock(),a.createBlock(a.resolveDynamicComponent(e.$slots.item),{key:1,item:t,onClick:function(e){return r.onItemClick(e,t)}},null,8,["item","onClick"])):a.withDirectives((a.openBlock(),a.createElementBlock("a",a.mergeProps({key:0,tabindex:-1,href:t.url||"#",role:"menuitem",class:e.cx("action",{item:t}),target:t.target,onClick:function(e){return r.onItemClick(e,t)},"aria-label":t.label},r.getPTOptions("".concat(o.id,"_").concat(n),"action")),[t.icon?(a.openBlock(),a.createElementBlock("span",a.mergeProps({key:0,class:[e.cx("actionIcon"),t.icon]},r.getPTOptions("".concat(o.id,"_").concat(n),"actionIcon")),null,16)):a.createCommentVNode("",!0)],16,P)),[[s],[l,{value:t.label,disabled:!e.tooltipOptions},e.tooltipOptions]])],16,O)):a.createCommentVNode("",!0)],64)})),128))],16,C)],16),e.mask?(a.openBlock(),a.createElementBlock("div",a.mergeProps({key:0,class:[e.cx("mask"),e.maskClass],style:e.maskStyle},e.ptm("mask")),null,16)):a.createCommentVNode("",!0)],64)},D}(primevue.button,primevue.icons.plus,primevue.ripple,primevue.tooltip,primevue.utils,primevue.basecomponent,primevue.speeddial.style,Vue);