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) 5.82 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 o={emits:["update:modelValue","change","filter"],props:{modelValue:null,options:Array,optionLabel:null,optionValue:null,optionDisabled:null,listStyle:null,disabled:Boolean,dataKey:null,multiple:Boolean,metaKeySelection:Boolean,filter:Boolean,filterPlaceholder:String,filterLocale:String,emptyFilterMessage:{type:String,default:"No results found"}},optionTouched:!1,data:()=>({filterValue: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)},onOptionSelect(e,t){this.disabled||this.isOptionDisabled(t)||(this.multiple?this.onOptionSelectMultiple(e,t):this.onOptionSelectSingle(e,t),this.optionTouched=!1)},onOptionTouchEnd(){this.disabled||(this.optionTouched=!0)},onOptionSelectSingle(e,t){let i=this.isSelected(t),l=!1,o=null;if(!this.optionTouched&&this.metaKeySelection){let n=e.metaKey||e.ctrlKey;i?n&&(o=null,l=!0):(o=this.getOptionValue(t),l=!0)}else o=i?null:this.getOptionValue(t),l=!0;l&&this.updateModel(e,o)},onOptionSelectMultiple(e,t){let i=this.isSelected(t),l=!1,o=null;if(!this.optionTouched&&this.metaKeySelection){let n=e.metaKey||e.ctrlKey;i?(o=n?this.removeOption(t):[this.getOptionValue(t)],l=!0):(o=n&&this.modelValue||[],o=[...o,this.getOptionValue(t)],l=!0)}else o=i?this.removeOption(t):[...this.modelValue||[],this.getOptionValue(t)],l=!0;l&&this.updateModel(e,o)},isSelected(t){let i=!1,l=this.getOptionValue(t);if(this.multiple){if(this.modelValue)for(let t of this.modelValue)if(e.ObjectUtils.equals(t,l,this.equalityKey)){i=!0;break}}else i=e.ObjectUtils.equals(this.modelValue,l,this.equalityKey);return i},removeOption(t){return this.modelValue.filter((i=>!e.ObjectUtils.equals(i,this.getOptionValue(t),this.equalityKey)))},updateModel(e,t){this.$emit("update:modelValue",t),this.$emit("change",{originalEvent:e,value:t})},onOptionKeyDown(e,t){let i=e.currentTarget;switch(e.which){case 40:var l=this.findNextItem(i);l&&l.focus(),e.preventDefault();break;case 38:var o=this.findPrevItem(i);o&&o.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.findNextOption(i):i:null},findPrevItem(t){let i=t.previousElementSibling;return i?e.DomHandler.hasClass(i,"p-disabled")?this.findPrevItem(i):i:null},onFilterChange(e){this.$emit("filter",{originalEvent:e,value:e.target.value})}},computed:{visibleOptions(){return this.filterValue?this.options.filter((e=>this.getOptionLabel(e).toLocaleLowerCase(this.filterLocale).indexOf(this.filterValue.toLocaleLowerCase(this.filterLocale))>-1)):this.options},equalityKey(){return this.optionValue?null:this.dataKey}},directives:{ripple:l(t).default}};const n={class:"p-listbox p-component"},s={key:0,class:"p-listbox-header"},a={class:"p-listbox-filter-container"},r=i.createVNode("span",{class:"p-listbox-filter-icon pi pi-search"},null,-1),p={class:"p-listbox-list",role:"listbox","aria-multiselectable":"multiple"},d={key:0,class:"p-listbox-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],o=document.createElement("style");o.type="text/css","top"===i&&l.firstChild?l.insertBefore(o,l.firstChild):l.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("\n.p-listbox-list-wrapper {\n overflow: auto;\n}\n.p-listbox-list {\n list-style-type: none;\n margin: 0;\n padding: 0;\n}\n.p-listbox-item {\n cursor: pointer;\n position: relative;\n overflow: hidden;\n}\n.p-listbox-filter-container {\n position: relative;\n}\n.p-listbox-filter-icon {\n position: absolute;\n top: 50%;\n margin-top: -.5rem;\n}\n.p-listbox-filter {\n width: 100%;\n}\n"),o.render=function(e,t,l,o,u,c){const h=i.resolveDirective("ripple");return i.openBlock(),i.createBlock("div",n,[l.filter?(i.openBlock(),i.createBlock("div",s,[i.createVNode("div",a,[i.withDirectives(i.createVNode("input",{type:"text",class:"p-listbox-filter p-inputtext p-component","onUpdate:modelValue":t[1]||(t[1]=e=>u.filterValue=e),placeholder:l.filterPlaceholder,onInput:t[2]||(t[2]=(...e)=>c.onFilterChange&&c.onFilterChange(...e))},null,40,["placeholder"]),[[i.vModelText,u.filterValue]]),r])])):i.createCommentVNode("",!0),i.createVNode("div",{class:"p-listbox-list-wrapper",style:l.listStyle},[i.createVNode("ul",p,[(i.openBlock(!0),i.createBlock(i.Fragment,null,i.renderList(c.visibleOptions,((l,o)=>i.withDirectives((i.openBlock(),i.createBlock("li",{tabindex:c.isOptionDisabled(l)?null:"0",class:["p-listbox-item",{"p-highlight":c.isSelected(l),"p-disabled":c.isOptionDisabled(l)}],"aria-label":c.getOptionLabel(l),key:c.getOptionRenderKey(l),onClick:e=>c.onOptionSelect(e,l),onTouchend:t[3]||(t[3]=e=>c.onOptionTouchEnd()),onKeydown:e=>c.onOptionKeyDown(e,l),role:"option","aria-selected":c.isSelected(l)},[i.renderSlot(e.$slots,"option",{option:l,index:o},(()=>[i.createTextVNode(i.toDisplayString(c.getOptionLabel(l)),1)]))],42,["tabindex","aria-label","onClick","onKeydown","aria-selected"])),[[h]]))),128)),u.filterValue&&(!c.visibleOptions||c.visibleOptions&&0===c.visibleOptions.length)?(i.openBlock(),i.createBlock("li",d,i.toDisplayString(l.emptyFilterMessage),1)):i.createCommentVNode("",!0)])],4)])},module.exports=o;