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) • 9.27 kB
JavaScript
"use strict";var e=require("primevue/basecomponent"),t=require("primevue/dock/style"),n=require("primevue/ripple"),i=require("primevue/tooltip"),o=require("primevue/utils"),a=require("vue");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e),l={name:"BaseDock",extends:s.default,props:{position:{type:String,default:"bottom"},model:null,class:null,style:null,tooltipOptions:null,menuId:{type:String,default:null},tabindex:{type:Number,default:0},breakpoint:{type:String,default:"960px"},ariaLabel:{type:String,default:null},ariaLabelledby:{type:String,default:null}},style:r(t).default,provide:function(){return{$parentInstance:this}}};function c(e){return m(e)||p(e)||u(e)||d()}function d(){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 u(e,t){if(e){if("string"==typeof e)return f(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)?f(e,t):void 0}}function p(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function m(e){if(Array.isArray(e))return f(e)}function f(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 h={name:"DockSub",hostName:"Dock",extends:s.default,emits:["focus","blur"],props:{position:{type:String,default:"bottom"},model:{type:Array,default:null},templates:{type:null,default:null},tooltipOptions:null,menuId:{type:String,default:null},tabindex:{type:Number,default:0},ariaLabel:{type:String,default:null},ariaLabelledby:{type:String,default:null}},data:function(){return{id:this.menuId,currentIndex:-3,focused:!1,focusedOptionIndex:-1}},watch:{menuId:function(e){this.id=e||o.UniqueComponentId()}},mounted:function(){this.id=this.id||o.UniqueComponentId()},methods:{getItemId:function(e){return"".concat(this.id,"_").concat(e)},getItemProp:function(e,t){return e&&e.item?o.ObjectUtils.getItemValue(e.item[t]):void 0},getPTOptions:function(e,t,n){return this.ptm(e,{context:{index:n,item:t,active:this.isItemActive(this.getItemId(n))}})},isSameMenuItem:function(e){return e.currentTarget&&(e.currentTarget.isSameNode(e.target)||e.currentTarget.isSameNode(e.target.closest('[data-pc-section="menuitem"]')))},isItemActive:function(e){return e===this.focusedOptionIndex},onListMouseLeave:function(){this.currentIndex=-3},onItemMouseEnter:function(e){this.currentIndex=e},onItemClick:function(e,t){if(this.isSameMenuItem(e)){var n=this.getItemProp(t,"command");n&&n({originalEvent:e,item:t.item})}},onListFocus:function(e){this.focused=!0,this.changeFocusedOptionIndex(0),this.$emit("focus",e)},onListBlur:function(e){this.focused=!1,this.focusedOptionIndex=-1,this.$emit("blur",e)},onListKeyDown:function(e){switch(e.code){case"ArrowDown":"left"!==this.position&&"right"!==this.position||this.onArrowDownKey(),e.preventDefault();break;case"ArrowUp":"left"!==this.position&&"right"!==this.position||this.onArrowUpKey(),e.preventDefault();break;case"ArrowRight":"top"!==this.position&&"bottom"!==this.position||this.onArrowDownKey(),e.preventDefault();break;case"ArrowLeft":"top"!==this.position&&"bottom"!==this.position||this.onArrowUpKey(),e.preventDefault();break;case"Home":this.onHomeKey(),e.preventDefault();break;case"End":this.onEndKey(),e.preventDefault();break;case"Enter":case"NumpadEnter":case"Space":this.onSpaceKey(e),e.preventDefault()}},onArrowDownKey:function(){var e=this.findNextOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(e)},onArrowUpKey:function(){var e=this.findPrevOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(e)},onHomeKey:function(){this.changeFocusedOptionIndex(0)},onEndKey:function(){this.changeFocusedOptionIndex(o.DomHandler.find(this.$refs.list,'li[data-pc-section="menuitem"][data-p-disabled="false"]').length-1)},onSpaceKey:function(){var e=o.DomHandler.findSingle(this.$refs.list,'li[id="'.concat("".concat(this.focusedOptionIndex),'"]')),t=e&&o.DomHandler.findSingle(e,'[data-pc-section="action"]');t?t.click():e&&e.click()},findNextOptionIndex:function(e){var t=c(o.DomHandler.find(this.$refs.list,'li[data-pc-section="menuitem"][data-p-disabled="false"]')).findIndex((function(t){return t.id===e}));return t>-1?t+1:0},findPrevOptionIndex:function(e){var t=c(o.DomHandler.find(this.$refs.list,'li[data-pc-section="menuitem"][data-p-disabled="false"]')).findIndex((function(t){return t.id===e}));return t>-1?t-1:0},changeFocusedOptionIndex:function(e){var t=o.DomHandler.find(this.$refs.list,'li[data-pc-section="menuitem"][data-p-disabled="false"]');this.focusedOptionIndex=t[e>=t.length?t.length-1:e<0?0:e].getAttribute("id")},disabled:function(e){return"function"==typeof e.disabled?e.disabled():e.disabled},getMenuItemProps:function(e,t){return{action:a.mergeProps({tabindex:-1,"aria-hidden":!0,class:this.cx("action")},this.getPTOptions("action",e,t)),icon:a.mergeProps({class:[this.cx("icon"),e.icon]},this.getPTOptions("icon",e,t))}}},computed:{focusedOptionId:function(){return-1!==this.focusedOptionIndex?this.focusedOptionIndex:null}},directives:{ripple:r(n).default,tooltip:r(i).default}},b=["id","aria-orientation","aria-activedescendant","tabindex","aria-label","aria-labelledby"],y=["id","aria-label","aria-disabled","onClick","onMouseenter","data-p-focused","data-p-disabled"],v=["href","target"];h.render=function(e,t,n,i,o,r){var s=a.resolveDirective("ripple"),l=a.resolveDirective("tooltip");return a.openBlock(),a.createElementBlock("div",a.mergeProps({class:e.cx("container")},e.ptm("container")),[a.createElementVNode("ul",a.mergeProps({ref:"list",id:o.id,class:e.cx("menu"),role:"menu","aria-orientation":"bottom"===n.position||"top"===n.position?"horizontal":"vertical","aria-activedescendant":o.focused?r.focusedOptionId:void 0,tabindex:n.tabindex,"aria-label":n.ariaLabel,"aria-labelledby":n.ariaLabelledby,onFocus:t[0]||(t[0]=function(){return r.onListFocus&&r.onListFocus.apply(r,arguments)}),onBlur:t[1]||(t[1]=function(){return r.onListBlur&&r.onListBlur.apply(r,arguments)}),onKeydown:t[2]||(t[2]=function(){return r.onListKeyDown&&r.onListKeyDown.apply(r,arguments)}),onMouseleave:t[3]||(t[3]=function(){return r.onListMouseLeave&&r.onListMouseLeave.apply(r,arguments)})},e.ptm("menu")),[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(n.model,(function(t,i){return a.openBlock(),a.createElementBlock("li",a.mergeProps({key:i,id:r.getItemId(i),class:e.cx("menuitem",{processedItem:t,index:i,id:r.getItemId(i)}),role:"menuitem","aria-label":t.label,"aria-disabled":r.disabled(t),onClick:function(e){return r.onItemClick(e,t)},onMouseenter:function(e){return r.onItemMouseEnter(i)}},r.getPTOptions("menuitem",t,i),{"data-p-focused":r.isItemActive(r.getItemId(i)),"data-p-disabled":r.disabled(t)||!1}),[a.createElementVNode("div",a.mergeProps({class:e.cx("content")},r.getPTOptions("content",t,i)),[n.templates.item?(a.openBlock(),a.createBlock(a.resolveDynamicComponent(n.templates.item),{key:1,item:t,index:i,label:t.label,props:r.getMenuItemProps(t,i)},null,8,["item","index","label","props"])):a.withDirectives((a.openBlock(),a.createElementBlock("a",a.mergeProps({key:0,href:t.url,class:e.cx("action"),target:t.target,tabindex:"-1","aria-hidden":"true"},r.getPTOptions("action",t,i)),[n.templates.icon?(a.openBlock(),a.createBlock(a.resolveDynamicComponent(n.templates.icon),{key:1,item:t,class:a.normalizeClass(e.cx("icon"))},null,8,["item","class"])):a.withDirectives((a.openBlock(),a.createElementBlock("span",a.mergeProps({key:0,class:[e.cx("icon"),t.icon]},r.getPTOptions("icon",t,i)),null,16)),[[s]])],16,v)),[[l,{value:t.label,disabled:!n.tooltipOptions},n.tooltipOptions]])],16)],16,y)})),128))],16,b)],16)};var g={name:"Dock",extends:l,matchMediaListener:null,data:function(){return{query:null,queryMatches:!1}},mounted:function(){this.bindMatchMediaListener()},beforeUnmount:function(){this.unbindMatchMediaListener()},methods:{bindMatchMediaListener:function(){var e=this;if(!this.matchMediaListener){var t=matchMedia("(max-width: ".concat(this.breakpoint,")"));this.query=t,this.queryMatches=t.matches,this.matchMediaListener=function(){e.queryMatches=t.matches,e.mobileActive=!1},this.query.addEventListener("change",this.matchMediaListener)}},unbindMatchMediaListener:function(){this.matchMediaListener&&(this.query.removeEventListener("change",this.matchMediaListener),this.matchMediaListener=null)}},computed:{containerClass:function(){return[this.class,this.cx("root")]}},components:{DockSub:h}};g.render=function(e,t,n,i,o,r){var s=a.resolveComponent("DockSub");return a.openBlock(),a.createElementBlock("div",a.mergeProps({class:r.containerClass,style:e.style},e.ptm("root"),{"data-pc-name":"dock"}),[a.createVNode(s,{model:e.model,templates:e.$slots,tooltipOptions:e.tooltipOptions,position:e.position,menuId:e.menuId,"aria-label":e.ariaLabel,"aria-labelledby":e.ariaLabelledby,tabindex:e.tabindex,pt:e.pt,unstyled:e.unstyled},null,8,["model","templates","tooltipOptions","position","menuId","aria-label","aria-labelledby","tabindex","pt","unstyled"])],16)},module.exports=g;