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)

2 lines (1 loc) 16 kB
"use strict";var e=require("primevue/utils"),t=require("primevue/ripple"),i=require("vue");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n={emits:["update:modelValue","before-show","before-hide","change","show","hide","filter"],props:{modelValue:null,options:Array,optionLabel:null,optionValue:null,optionDisabled:null,scrollHeight:{type:String,default:"200px"},placeholder:String,disabled:Boolean,filter:Boolean,tabindex:String,inputId:String,dataKey:null,filterPlaceholder:String,filterLocale:String,ariaLabelledBy:null,appendTo:{type:String,default:null},emptyFilterMessage:{type:String,default:"No results found"},display:{type:String,default:"comma"}},data:()=>({focused:!1,headerCheckboxFocused:!1,filterValue:null,overlayVisible:!1}),outsideClickListener:null,resizeListener:null,scrollHandler:null,overlay:null,beforeUnmount(){this.restoreAppend(),this.unbindOutsideClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.overlay=null},methods:{getOptionLabel(t){return this.optionLabel?e.ObjectUtils.resolveFieldData(t,this.optionLabel):t},getOptionValue(t){return this.optionValue?e.ObjectUtils.resolveFieldData(t,this.optionValue):t},getOptionRenderKey(t){return this.dataKey?e.ObjectUtils.resolveFieldData(t,this.dataKey):this.getOptionLabel(t)},isOptionDisabled(t){return!!this.optionDisabled&&e.ObjectUtils.resolveFieldData(t,this.optionDisabled)},isSelected(t){let i=!1,l=this.getOptionValue(t);if(this.modelValue)for(let t of this.modelValue)if(e.ObjectUtils.equals(t,l,this.equalityKey)){i=!0;break}return i},show(){this.$emit("before-show"),this.overlayVisible=!0},hide(){this.$emit("before-hide"),this.overlayVisible=!1},onFocus(){this.focused=!0},onBlur(){this.focused=!1},onHeaderCheckboxFocus(){this.headerCheckboxFocused=!0},onHeaderCheckboxBlur(){this.headerCheckboxFocused=!1},onClick(t){this.disabled||this.overlay&&this.overlay.contains(t.target)||e.DomHandler.hasClass(t.target,"p-multiselect-close")||(e.DomHandler.hasClass(t.target,"p-multiselect-close"),this.overlayVisible?this.hide():this.show(),this.$refs.focusInput.focus())},onCloseClick(){this.hide()},onKeyDown(e){switch(e.which){case 40:this.visibleOptions&&!this.overlayVisible&&e.altKey&&this.show();break;case 32:this.overlayVisible||(this.show(),e.preventDefault());break;case 13:case 27:this.overlayVisible&&(this.hide(),e.preventDefault());break;case 9:this.hide()}},onOptionSelect(t,i){if(this.disabled||this.isOptionDisabled(i))return;let l=null;l=this.isSelected(i)?this.modelValue.filter((t=>!e.ObjectUtils.equals(t,this.getOptionValue(i),this.equalityKey))):[...this.modelValue||[],this.getOptionValue(i)],this.$emit("update:modelValue",l),this.$emit("change",{originalEvent:t,value:l})},onOptionKeyDown(e,t){let i=e.target;switch(e.which){case 40:var l=this.findNextItem(i);l&&l.focus(),e.preventDefault();break;case 38:var n=this.findPrevItem(i);n&&n.focus(),e.preventDefault();break;case 13:this.onOptionSelect(e,t),e.preventDefault()}},findNextItem(t){let i=t.nextElementSibling;return i?e.DomHandler.hasClass(i,"p-disabled")?this.findNextItem(i):i:null},findPrevItem(t){let i=t.previousElementSibling;return i?e.DomHandler.hasClass(i,"p-disabled")?this.findPrevItem(i):i:null},onOverlayEnter(){this.overlay.style.zIndex=String(e.DomHandler.generateZIndex()),this.appendContainer(),this.alignOverlay(),this.bindOutsideClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.$emit("show")},onOverlayLeave(){this.unbindOutsideClickListener(),this.unbindScrollListener(),this.unbindResizeListener(),this.$emit("hide"),this.overlay=null},alignOverlay(){this.appendTo?(e.DomHandler.absolutePosition(this.overlay,this.$el),this.overlay.style.minWidth=e.DomHandler.getOuterWidth(this.$el)+"px"):e.DomHandler.relativePosition(this.overlay,this.$el)},bindOutsideClickListener(){this.outsideClickListener||(this.outsideClickListener=e=>{this.overlayVisible&&this.isOutsideClicked(e)&&this.hide()},document.addEventListener("click",this.outsideClickListener))},unbindOutsideClickListener(){this.outsideClickListener&&(document.removeEventListener("click",this.outsideClickListener),this.outsideClickListener=null)},bindScrollListener(){this.scrollHandler||(this.scrollHandler=new e.ConnectedOverlayScrollHandler(this.$refs.container,(()=>{this.overlayVisible&&this.hide()}))),this.scrollHandler.bindScrollListener()},unbindScrollListener(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()},bindResizeListener(){this.resizeListener||(this.resizeListener=()=>{this.overlayVisible&&this.hide()},window.addEventListener("resize",this.resizeListener))},unbindResizeListener(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)},isOutsideClicked(e){return!(this.$el.isSameNode(e.target)||this.$el.contains(e.target)||this.overlay&&this.overlay.contains(e.target))},getLabelByValue(t){let i=null;if(this.options)for(let l of this.options){let n=this.getOptionValue(l);if(e.ObjectUtils.equals(n,t,this.equalityKey)){i=this.getOptionLabel(l);break}}return i},onToggleAll(e){const t=this.allSelected?[]:this.visibleOptions&&this.visibleOptions.map((e=>this.getOptionValue(e)));this.$emit("update:modelValue",t),this.$emit("change",{originalEvent:e,value:t})},appendContainer(){this.appendTo&&("body"===this.appendTo?document.body.appendChild(this.overlay):document.getElementById(this.appendTo).appendChild(this.overlay))},restoreAppend(){this.overlay&&this.appendTo&&("body"===this.appendTo?document.body.removeChild(this.overlay):document.getElementById(this.appendTo).removeChild(this.overlay))},onFilterChange(e){this.$emit("filter",{originalEvent:e,value:e.target.value}),this.overlayVisible&&this.alignOverlay()},overlayRef(e){this.overlay=e},removeChip(t){let i=this.modelValue.filter((i=>!e.ObjectUtils.equals(i,t,this.equalityKey)));this.$emit("update:modelValue",i),this.$emit("change",{originalEvent:event,value:i})}},computed:{visibleOptions(){return this.filterValue&&this.filterValue.trim().length>0?this.options.filter((e=>this.getOptionLabel(e).toLocaleLowerCase(this.filterLocale).indexOf(this.filterValue.toLocaleLowerCase(this.filterLocale))>-1)):this.options},containerClass(){return["p-multiselect p-component p-inputwrapper",{"p-multiselect-chip":"chip"===this.display,"p-disabled":this.disabled,"p-focus":this.focused,"p-inputwrapper-filled":this.modelValue&&this.modelValue.length,"p-inputwrapper-focus":this.focused||this.overlayVisible}]},labelClass(){return["p-multiselect-label",{"p-placeholder":this.label===this.placeholder,"p-multiselect-label-empty":!(this.placeholder||this.modelValue&&0!==this.modelValue.length)}]},label(){let e;if(this.modelValue&&this.modelValue.length){e="";for(let t=0;t<this.modelValue.length;t++)0!==t&&(e+=", "),e+=this.getLabelByValue(this.modelValue[t])}else e=this.placeholder;return e},allSelected(){if(this.filterValue&&this.filterValue.trim().length>0){let e=!0;if(this.visibleOptions.length>0){for(let t of this.visibleOptions)if(!this.isSelected(t)){e=!1;break}}else e=!1;return e}return this.modelValue&&this.options&&this.modelValue.length>0&&this.modelValue.length===this.options.length},equalityKey(){return this.optionValue?null:this.dataKey}},directives:{ripple:l(t).default}};const s={class:"p-hidden-accessible"},o={class:"p-multiselect-label-container"},a={class:"p-multiselect-token-label"},r=i.createVNode("div",{class:"p-multiselect-trigger"},[i.createVNode("span",{class:"p-multiselect-trigger-icon pi pi-chevron-down"})],-1),c={class:"p-multiselect-header"},d={class:"p-hidden-accessible"},p={key:0,class:"p-multiselect-filter-container"},h=i.createVNode("span",{class:"p-multiselect-filter-icon pi pi-search"},null,-1),u=i.createVNode("span",{class:"p-multiselect-close-icon pi pi-times"},null,-1),m={class:"p-multiselect-items p-component",role:"listbox","aria-multiselectable":"true"},b={class:"p-checkbox p-component"},y={key:0,class:"p-multiselect-empty-message"};!function(e,t){void 0===t&&(t={});var i=t.insertAt;if(e&&"undefined"!=typeof document){var l=document.head||document.getElementsByTagName("head")[0],n=document.createElement("style");n.type="text/css","top"===i&&l.firstChild?l.insertBefore(n,l.firstChild):l.appendChild(n),n.styleSheet?n.styleSheet.cssText=e:n.appendChild(document.createTextNode(e))}}("\n.p-multiselect {\n display: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n cursor: pointer;\n position: relative;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n.p-multiselect-trigger {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n -ms-flex-negative: 0;\n flex-shrink: 0;\n}\n.p-multiselect-label-container {\n overflow: hidden;\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n cursor: pointer;\n}\n.p-multiselect-label {\n display: block;\n white-space: nowrap;\n cursor: pointer;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.p-multiselect-label-empty {\n overflow: hidden;\n visibility: hidden;\n}\n.p-multiselect-token {\n cursor: default;\n display: -webkit-inline-box;\n display: -ms-inline-flexbox;\n display: inline-flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-flex: 0;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n}\n.p-multiselect-token-icon {\n cursor: pointer;\n}\n.p-multiselect .p-multiselect-panel {\n min-width: 100%;\n}\n.p-multiselect-panel {\n position: absolute;\n}\n.p-multiselect-items-wrapper {\n overflow: auto;\n}\n.p-multiselect-items {\n margin: 0;\n padding: 0;\n list-style-type: none;\n}\n.p-multiselect-item {\n cursor: pointer;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n font-weight: normal;\n white-space: nowrap;\n position: relative;\n overflow: hidden;\n}\n.p-multiselect-header {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: justify;\n -ms-flex-pack: justify;\n justify-content: space-between;\n}\n.p-multiselect-filter-container {\n position: relative;\n -webkit-box-flex: 1;\n -ms-flex: 1 1 auto;\n flex: 1 1 auto;\n}\n.p-multiselect-filter-icon {\n position: absolute;\n top: 50%;\n margin-top: -.5rem;\n}\n.p-multiselect-filter-container .p-inputtext {\n width: 100%;\n}\n.p-multiselect-close {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n -ms-flex-negative: 0;\n flex-shrink: 0;\n overflow: hidden;\n position: relative;\n}\n.p-fluid .p-multiselect {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n}\n"),n.render=function(e,t,l,n,f,v){const k=i.resolveDirective("ripple");return i.openBlock(),i.createBlock("div",{ref:"container",class:v.containerClass,onClick:t[10]||(t[10]=(...e)=>v.onClick&&v.onClick(...e))},[i.createVNode("div",s,[i.createVNode("input",{ref:"focusInput",type:"text",role:"listbox",id:l.inputId,readonly:"",disabled:l.disabled,onFocus:t[1]||(t[1]=(...e)=>v.onFocus&&v.onFocus(...e)),onBlur:t[2]||(t[2]=(...e)=>v.onBlur&&v.onBlur(...e)),onKeydown:t[3]||(t[3]=(...e)=>v.onKeyDown&&v.onKeyDown(...e)),tabindex:l.tabindex,"aria-haspopup":"listbox","aria-expanded":f.overlayVisible,"aria-labelledby":l.ariaLabelledBy},null,40,["id","disabled","tabindex","aria-expanded","aria-labelledby"])]),i.createVNode("div",o,[i.createVNode("div",{class:v.labelClass},[i.renderSlot(e.$slots,"value",{value:l.modelValue,placeholder:l.placeholder},(()=>["comma"===l.display?(i.openBlock(),i.createBlock(i.Fragment,{key:0},[i.createTextVNode(i.toDisplayString(v.label||"empty"),1)],64)):"chip"===l.display?(i.openBlock(),i.createBlock(i.Fragment,{key:1},[(i.openBlock(!0),i.createBlock(i.Fragment,null,i.renderList(l.modelValue,(e=>(i.openBlock(),i.createBlock("div",{class:"p-multiselect-token",key:v.getLabelByValue(e)},[i.createVNode("span",a,i.toDisplayString(v.getLabelByValue(e)),1),l.disabled?i.createCommentVNode("",!0):(i.openBlock(),i.createBlock("span",{key:0,class:"p-multiselect-token-icon pi pi-times-circle",onClick:t=>v.removeChip(e)},null,8,["onClick"]))])))),128)),l.modelValue&&0!==l.modelValue.length?i.createCommentVNode("",!0):(i.openBlock(),i.createBlock(i.Fragment,{key:0},[i.createTextVNode(i.toDisplayString(l.placeholder||"empty"),1)],64))],64)):i.createCommentVNode("",!0)]))],2)]),r,i.createVNode(i.Transition,{name:"p-connected-overlay",onEnter:v.onOverlayEnter,onLeave:v.onOverlayLeave},{default:i.withCtx((()=>[f.overlayVisible?(i.openBlock(),i.createBlock("div",{key:0,ref:v.overlayRef,class:"p-multiselect-panel p-component"},[i.createVNode("div",c,[i.createVNode("div",{class:"p-checkbox p-component",onClick:t[6]||(t[6]=(...e)=>v.onToggleAll&&v.onToggleAll(...e)),role:"checkbox","aria-checked":v.allSelected},[i.createVNode("div",d,[i.createVNode("input",{type:"checkbox",readonly:"",onFocus:t[4]||(t[4]=(...e)=>v.onHeaderCheckboxFocus&&v.onHeaderCheckboxFocus(...e)),onBlur:t[5]||(t[5]=(...e)=>v.onHeaderCheckboxBlur&&v.onHeaderCheckboxBlur(...e))},null,32)]),i.createVNode("div",{class:["p-checkbox-box",{"p-highlight":v.allSelected,"p-focus":f.headerCheckboxFocused}],role:"checkbox","aria-checked":v.allSelected},[i.createVNode("span",{class:["p-checkbox-icon",{"pi pi-check":v.allSelected}]},null,2)],10,["aria-checked"])],8,["aria-checked"]),l.filter?(i.openBlock(),i.createBlock("div",p,[i.withDirectives(i.createVNode("input",{type:"text","onUpdate:modelValue":t[7]||(t[7]=e=>f.filterValue=e),class:"p-multiselect-filter p-inputtext p-component",placeholder:l.filterPlaceholder,onInput:t[8]||(t[8]=(...e)=>v.onFilterChange&&v.onFilterChange(...e))},null,40,["placeholder"]),[[i.vModelText,f.filterValue]]),h])):i.createCommentVNode("",!0),i.withDirectives(i.createVNode("button",{class:"p-multiselect-close p-link",onClick:t[9]||(t[9]=(...e)=>v.onCloseClick&&v.onCloseClick(...e)),type:"button"},[u],512),[[k]])]),i.createVNode("div",{class:"p-multiselect-items-wrapper",style:{"max-height":l.scrollHeight}},[i.createVNode("ul",m,[(i.openBlock(!0),i.createBlock(i.Fragment,null,i.renderList(v.visibleOptions,((t,n)=>i.withDirectives((i.openBlock(),i.createBlock("li",{class:["p-multiselect-item",{"p-highlight":v.isSelected(t),"p-disabled":v.isOptionDisabled(t)}],role:"option","aria-selected":v.isSelected(t),"aria-label":v.getOptionLabel(t),key:v.getOptionRenderKey(t),onClick:e=>v.onOptionSelect(e,t),onKeydown:e=>v.onOptionKeyDown(e,t),tabindex:l.tabindex||"0"},[i.createVNode("div",b,[i.createVNode("div",{class:["p-checkbox-box",{"p-highlight":v.isSelected(t)}]},[i.createVNode("span",{class:["p-checkbox-icon",{"pi pi-check":v.isSelected(t)}]},null,2)],2)]),i.renderSlot(e.$slots,"option",{option:t,index:n},(()=>[i.createVNode("span",null,i.toDisplayString(v.getOptionLabel(t)),1)]))],42,["aria-selected","aria-label","onClick","onKeydown","tabindex"])),[[k]]))),128)),f.filterValue&&(!v.visibleOptions||v.visibleOptions&&0===v.visibleOptions.length)?(i.openBlock(),i.createBlock("li",y,i.toDisplayString(l.emptyFilterMessage),1)):i.createCommentVNode("",!0)])],4)],512)):i.createCommentVNode("",!0)])),_:1},8,["onEnter","onLeave"])],2)},module.exports=n;