UNPKG

primevue

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primevue.svg)](https://badge.fury.io/js/primevue) [![Discord Chat](https://img.shields.io/discord/55794023

2 lines (1 loc) 16.8 kB
this.primevue=this.primevue||{},this.primevue.menu=function(e,t,n,i,o,r,s){"use strict";function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=l(e),c=l(t),d=l(i),u=l(r),p=o.useStyle("\n.p-menu ul {\n margin: 0;\n padding: 0;\n list-style: none;\n}\n\n.p-menu .p-menuitem-link {\n cursor: pointer;\n display: flex;\n align-items: center;\n text-decoration: none;\n overflow: hidden;\n position: relative;\n}\n\n.p-menu .p-menuitem-text {\n line-height: 1;\n}\n",{name:"menu",manual:!0}),m={name:"BaseMenu",extends:d.default,props:{popup:{type:Boolean,default:!1},model:{type:Array,default:null},appendTo:{type:String,default:"body"},autoZIndex:{type:Boolean,default:!0},baseZIndex:{type:Number,default:0},exact:{type:Boolean,default:!0},tabindex:{type:Number,default:0},"aria-label":{type:String,default:null},"aria-labelledby":{type:String,default:null}},css:{classes:{root:function(e){var t=e.instance;return["p-menu p-component",{"p-menu-overlay":e.props.popup,"p-input-filled":"filled"===t.$primevue.config.inputStyle,"p-ripple-disabled":!1===t.$primevue.config.ripple}]},start:"p-menu-start",menu:"p-menu-list p-reset",submenuHeader:"p-submenu-header",separator:"p-menuitem-separator",end:"p-menu-end",menuitem:function(e){var t=e.instance;return["p-menuitem",{"p-focus":t.id===t.focusedOptionId,"p-disabled":t.disabled()}]},content:"p-menuitem-content",action:function(e){return["p-menuitem-link",{"router-link-active":e.isActive,"router-link-active-exact":e.props.exact&&e.isExactActive}]},icon:"p-menuitem-icon",label:"p-menuitem-text"},loadStyle:p.load},provide:function(){return{$parentInstance:this}}},f={name:"Menuitem",hostName:"Menu",extends:d.default,inheritAttrs:!1,emits:["item-click"],props:{item:null,templates:null,exact:null,id:null,focusedOptionId:null,index:null},methods:{getItemProp:function(e,t){return e&&e.item?n.ObjectUtils.getItemValue(e.item[t]):void 0},getPTOptions:function(e){return this.ptm(e,{context:{item:this.item,index:this.index,focused:this.isItemFocused()}})},isItemFocused:function(){return this.focusedOptionId===this.id},onItemActionClick:function(e,t){t&&t(e)},onItemClick:function(e){var t=this.getItemProp(this.item,"command");t&&t({originalEvent:e,item:this.item.item}),this.$emit("item-click",{originalEvent:e,item:this.item,id:this.id})},visible:function(){return"function"==typeof this.item.visible?this.item.visible():!1!==this.item.visible},disabled:function(){return"function"==typeof this.item.disabled?this.item.disabled():this.item.disabled},label:function(){return"function"==typeof this.item.label?this.item.label():this.item.label}},directives:{ripple:u.default}},h=["id","aria-label","aria-disabled","data-p-focused","data-p-disabled"],b=["href","onClick"],y=["href","target"];function v(e){return O(e)||x(e)||g(e)||k()}function k(){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 g(e,t){if(e){if("string"==typeof e)return I(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)?I(e,t):void 0}}function x(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function O(e){if(Array.isArray(e))return I(e)}function I(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}f.render=function(e,t,n,i,o,r){var l=s.resolveComponent("router-link"),a=s.resolveDirective("ripple");return r.visible()?(s.openBlock(),s.createElementBlock("li",s.mergeProps({key:0,id:n.id,class:[e.cx("menuitem"),n.item.class],role:"menuitem",style:n.item.style,"aria-label":r.label(),"aria-disabled":r.disabled()},r.getPTOptions("menuitem"),{"data-p-focused":r.isItemFocused(),"data-p-disabled":r.disabled()||!1}),[s.createElementVNode("div",s.mergeProps({class:e.cx("content"),onClick:t[0]||(t[0]=function(e){return r.onItemClick(e)})},r.getPTOptions("content")),[n.templates.item?(s.openBlock(),s.createBlock(s.resolveDynamicComponent(n.templates.item),{key:1,item:n.item},null,8,["item"])):(s.openBlock(),s.createElementBlock(s.Fragment,{key:0},[n.item.to&&!r.disabled()?(s.openBlock(),s.createBlock(l,{key:0,to:n.item.to,custom:""},{default:s.withCtx((function(t){var i=t.navigate,o=t.href,l=t.isActive,c=t.isExactActive;return[s.withDirectives((s.openBlock(),s.createElementBlock("a",s.mergeProps({href:o,class:e.cx("action",{isActive:l,isExactActive:c}),tabindex:"-1","aria-hidden":"true",onClick:function(e){return r.onItemActionClick(e,i)}},r.getPTOptions("action")),[n.templates.itemicon?(s.openBlock(),s.createBlock(s.resolveDynamicComponent(n.templates.itemicon),{key:0,item:n.item,class:s.normalizeClass([e.cx("icon"),n.item.icon])},null,8,["item","class"])):n.item.icon?(s.openBlock(),s.createElementBlock("span",s.mergeProps({key:1,class:[e.cx("icon"),n.item.icon]},r.getPTOptions("icon")),null,16)):s.createCommentVNode("",!0),s.createElementVNode("span",s.mergeProps({class:e.cx("label")},r.getPTOptions("label")),s.toDisplayString(r.label()),17)],16,b)),[[a]])]})),_:1},8,["to"])):s.withDirectives((s.openBlock(),s.createElementBlock("a",s.mergeProps({key:1,href:n.item.url,class:e.cx("action"),target:n.item.target,tabindex:"-1","aria-hidden":"true"},r.getPTOptions("action")),[n.templates.itemicon?(s.openBlock(),s.createBlock(s.resolveDynamicComponent(n.templates.itemicon),{key:0,item:n.item,class:s.normalizeClass([e.cx("icon"),n.item.icon])},null,8,["item","class"])):n.item.icon?(s.openBlock(),s.createElementBlock("span",s.mergeProps({key:1,class:[e.cx("icon"),n.item.icon]},r.getPTOptions("icon")),null,16)):s.createCommentVNode("",!0),s.createElementVNode("span",s.mergeProps({class:e.cx("label")},r.getPTOptions("label")),s.toDisplayString(r.label()),17)],16,y)),[[a]])],64))],16)],16,h)):s.createCommentVNode("",!0)};var L={name:"Menu",extends:m,inheritAttrs:!1,emits:["show","hide","focus","blur"],data:function(){return{id:this.$attrs.id,overlayVisible:!1,focused:!1,focusedOptionIndex:-1,selectedOptionIndex:-1}},watch:{"$attrs.id":function(e){this.id=e||n.UniqueComponentId()}},target:null,outsideClickListener:null,scrollHandler:null,resizeListener:null,container:null,list:null,mounted:function(){this.id=this.id||n.UniqueComponentId(),this.popup||(this.bindResizeListener(),this.bindOutsideClickListener())},beforeUnmount:function(){this.unbindResizeListener(),this.unbindOutsideClickListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.target=null,this.container&&this.autoZIndex&&n.ZIndexUtils.clear(this.container),this.container=null},methods:{itemClick:function(e){var t=e.item;this.disabled(t)||(t.command&&t.command(e),t.to&&e.navigate&&e.navigate(e.originalEvent),this.overlayVisible&&this.hide(),this.popup||this.focusedOptionIndex===e.id||(this.focusedOptionIndex=e.id))},onListFocus:function(e){this.focused=!0,this.popup||(-1!==this.selectedOptionIndex?(this.changeFocusedOptionIndex(this.selectedOptionIndex),this.selectedOptionIndex=-1):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":this.onArrowDownKey(e);break;case"ArrowUp":this.onArrowUpKey(e);break;case"Home":this.onHomeKey(e);break;case"End":this.onEndKey(e);break;case"Enter":this.onEnterKey(e);break;case"Space":this.onSpaceKey(e);break;case"Escape":this.popup&&(n.DomHandler.focus(this.target),this.hide());case"Tab":this.overlayVisible&&this.hide()}},onArrowDownKey:function(e){var t=this.findNextOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(t),e.preventDefault()},onArrowUpKey:function(e){if(e.altKey&&this.popup)n.DomHandler.focus(this.target),this.hide(),e.preventDefault();else{var t=this.findPrevOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(t),e.preventDefault()}},onHomeKey:function(e){this.changeFocusedOptionIndex(0),e.preventDefault()},onEndKey:function(e){this.changeFocusedOptionIndex(n.DomHandler.find(this.container,'li[data-pc-section="menuitem"][data-p-disabled="false"]').length-1),e.preventDefault()},onEnterKey:function(e){var t=n.DomHandler.findSingle(this.list,'li[id="'.concat("".concat(this.focusedOptionIndex),'"]')),i=t&&n.DomHandler.findSingle(t,'a[data-pc-section="action"]');this.popup&&n.DomHandler.focus(this.target),i?i.click():t&&t.click(),e.preventDefault()},onSpaceKey:function(e){this.onEnterKey(e)},findNextOptionIndex:function(e){var t=v(n.DomHandler.find(this.container,'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=v(n.DomHandler.find(this.container,'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=n.DomHandler.find(this.container,'li[data-pc-section="menuitem"][data-p-disabled="false"]'),i=e>=t.length?t.length-1:e<0?0:e;i>-1&&(this.focusedOptionIndex=t[i].getAttribute("id"))},toggle:function(e){this.overlayVisible?this.hide():this.show(e)},show:function(e){this.overlayVisible=!0,this.target=e.currentTarget},hide:function(){this.overlayVisible=!1,this.target=null},onEnter:function(e){n.DomHandler.addStyles(e,{position:"absolute",top:"0",left:"0"}),this.alignOverlay(),this.bindOutsideClickListener(),this.bindResizeListener(),this.bindScrollListener(),this.autoZIndex&&n.ZIndexUtils.set("menu",e,this.baseZIndex+this.$primevue.config.zIndex.menu),this.popup&&(n.DomHandler.focus(this.list),this.changeFocusedOptionIndex(0)),this.$emit("show")},onLeave:function(){this.unbindOutsideClickListener(),this.unbindResizeListener(),this.unbindScrollListener(),this.$emit("hide")},onAfterLeave:function(e){this.autoZIndex&&n.ZIndexUtils.clear(e)},alignOverlay:function(){n.DomHandler.absolutePosition(this.container,this.target),this.container.style.minWidth=n.DomHandler.getOuterWidth(this.target)+"px"},bindOutsideClickListener:function(){var e=this;this.outsideClickListener||(this.outsideClickListener=function(t){var n=e.container&&!e.container.contains(t.target),i=!(e.target&&(e.target===t.target||e.target.contains(t.target)));e.overlayVisible&&n&&i?e.hide():!e.popup&&n&&i&&(e.focusedOptionIndex=-1)},document.addEventListener("click",this.outsideClickListener))},unbindOutsideClickListener:function(){this.outsideClickListener&&(document.removeEventListener("click",this.outsideClickListener),this.outsideClickListener=null)},bindScrollListener:function(){var e=this;this.scrollHandler||(this.scrollHandler=new n.ConnectedOverlayScrollHandler(this.target,(function(){e.overlayVisible&&e.hide()}))),this.scrollHandler.bindScrollListener()},unbindScrollListener:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},bindResizeListener:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.overlayVisible&&!n.DomHandler.isTouchDevice()&&e.hide()},window.addEventListener("resize",this.resizeListener))},unbindResizeListener:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},visible:function(e){return"function"==typeof e.visible?e.visible():!1!==e.visible},disabled:function(e){return"function"==typeof e.disabled?e.disabled():e.disabled},label:function(e){return"function"==typeof e.label?e.label():e.label},onOverlayClick:function(e){a.default.emit("overlay-click",{originalEvent:e,target:this.target})},containerRef:function(e){this.container=e},listRef:function(e){this.list=e}},computed:{focusedOptionId:function(){return-1!==this.focusedOptionIndex?this.focusedOptionIndex:null}},components:{PVMenuitem:f,Portal:c.default}};function B(e){return B="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},B(e)}function C(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 E(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?C(Object(n),!0).forEach((function(t){P(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function P(e,t,n){return(t=S(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(e){var t=w(e,"string");return"symbol"===B(t)?t:String(t)}function w(e,t){if("object"!==B(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!==B(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var D=["id"],H=["id","tabindex","aria-activedescendant","aria-label","aria-labelledby"],A=["id"];return L.render=function(e,t,n,i,o,r){var l=s.resolveComponent("PVMenuitem"),a=s.resolveComponent("Portal");return s.openBlock(),s.createBlock(a,{appendTo:e.appendTo,disabled:!e.popup},{default:s.withCtx((function(){return[s.createVNode(s.Transition,{name:"p-connected-overlay",onEnter:r.onEnter,onLeave:r.onLeave,onAfterLeave:r.onAfterLeave},{default:s.withCtx((function(){return[!e.popup||o.overlayVisible?(s.openBlock(),s.createElementBlock("div",s.mergeProps({key:0,ref:r.containerRef,id:o.id,class:e.cx("root"),onClick:t[3]||(t[3]=function(){return r.onOverlayClick&&r.onOverlayClick.apply(r,arguments)})},E(E({},e.$attrs),e.ptm("root")),{"data-pc-name":"menu"}),[e.$slots.start?(s.openBlock(),s.createElementBlock("div",s.mergeProps({key:0,class:e.cx("start")},e.ptm("start")),[s.renderSlot(e.$slots,"start")],16)):s.createCommentVNode("",!0),s.createElementVNode("ul",s.mergeProps({ref:r.listRef,id:o.id+"_list",class:e.cx("menu"),role:"menu",tabindex:e.tabindex,"aria-activedescendant":o.focused?r.focusedOptionId:void 0,"aria-label":e.ariaLabel,"aria-labelledby":e.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)})},e.ptm("menu")),[(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(e.model,(function(t,n){return s.openBlock(),s.createElementBlock(s.Fragment,{key:r.label(t)+n.toString()},[t.items&&r.visible(t)&&!t.separator?(s.openBlock(),s.createElementBlock(s.Fragment,{key:0},[t.items?(s.openBlock(),s.createElementBlock("li",s.mergeProps({key:0,id:o.id+"_"+n,class:e.cx("submenuHeader"),role:"none"},e.ptm("submenuHeader")),[s.renderSlot(e.$slots,"item",{item:t},(function(){return[s.createTextVNode(s.toDisplayString(r.label(t)),1)]}))],16,A)):s.createCommentVNode("",!0),(s.openBlock(!0),s.createElementBlock(s.Fragment,null,s.renderList(t.items,(function(i,a){return s.openBlock(),s.createElementBlock(s.Fragment,{key:i.label+n+"_"+a},[r.visible(i)&&!i.separator?(s.openBlock(),s.createBlock(l,{key:0,id:o.id+"_"+n+"_"+a,item:i,templates:e.$slots,exact:e.exact,focusedOptionId:r.focusedOptionId,onItemClick:r.itemClick,pt:e.pt},null,8,["id","item","templates","exact","focusedOptionId","onItemClick","pt"])):r.visible(i)&&i.separator?(s.openBlock(),s.createElementBlock("li",s.mergeProps({key:"separator"+n+a,class:[e.cx("separator"),t.class],style:i.style,role:"separator"},e.ptm("separator")),null,16)):s.createCommentVNode("",!0)],64)})),128))],64)):r.visible(t)&&t.separator?(s.openBlock(),s.createElementBlock("li",s.mergeProps({key:"separator"+n.toString(),class:[e.cx("separator"),t.class],style:t.style,role:"separator"},e.ptm("separator")),null,16)):(s.openBlock(),s.createBlock(l,{key:r.label(t)+n.toString(),id:o.id+"_"+n,item:t,index:n,templates:e.$slots,exact:e.exact,focusedOptionId:r.focusedOptionId,onItemClick:r.itemClick,pt:e.pt},null,8,["id","item","index","templates","exact","focusedOptionId","onItemClick","pt"]))],64)})),128))],16,H),e.$slots.end?(s.openBlock(),s.createElementBlock("div",s.mergeProps({key:1,class:e.cx("end")},e.ptm("end")),[s.renderSlot(e.$slots,"end")],16)):s.createCommentVNode("",!0)],16,D)):s.createCommentVNode("",!0)]})),_:3},8,["onEnter","onLeave","onAfterLeave"])]})),_:3},8,["appendTo","disabled"])},L}(primevue.overlayeventbus,primevue.portal,primevue.utils,primevue.basecomponent,primevue.usestyle,primevue.ripple,Vue);