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) 13.1 kB
this.primevue=this.primevue||{},this.primevue.picklist=function(e,t,i,l){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(e),s=n(i),c={name:"PickList",emits:["update:modelValue","reorder","update:selection","selection-change","move-to-target","move-to-source","move-all-to-target","move-all-to-source"],props:{modelValue:{type:Array,default:()=>[[],[]]},selection:{type:Array,default:()=>[[],[]]},dataKey:{type:String,default:null},listStyle:{type:null,default:null},metaKeySelection:{type:Boolean,default:!0},responsive:{type:Boolean,default:!0},breakpoint:{type:String,default:"960px"}},itemTouched:!1,reorderDirection:null,styleElement:null,data(){return{d_selection:this.selection}},updated(){this.reorderDirection&&(this.updateListScroll(this.$refs.sourceList.$el),this.updateListScroll(this.$refs.targetList.$el),this.reorderDirection=null)},beforeUnmount(){this.destroyStyle()},mounted(){this.responsive&&this.createStyle()},watch:{selection(e){this.d_selection=e}},methods:{getItemKey(e,i){return this.dataKey?t.ObjectUtils.resolveFieldData(e,this.dataKey):i},isSelected(e,i){return-1!=t.ObjectUtils.findIndexInList(e,this.d_selection[i])},moveUp(e,i){if(this.d_selection&&this.d_selection[i]){let l=[...this.modelValue[i]],n=this.d_selection[i];for(let e=0;e<n.length;e++){let i=n[e],o=t.ObjectUtils.findIndexInList(i,l);if(0===o)break;{let e=l[o],t=l[o-1];l[o-1]=e,l[o]=t}}let o=[...this.modelValue];o[i]=l,this.reorderDirection="up",this.$emit("update:modelValue",o),this.$emit("reorder",{originalEvent:e,value:o,direction:this.reorderDirection,listIndex:i})}},moveTop(e,i){if(this.d_selection){let l=[...this.modelValue[i]],n=this.d_selection[i];for(let e=0;e<n.length;e++){let i=n[e],o=t.ObjectUtils.findIndexInList(i,l);if(0===o)break;{let e=l.splice(o,1)[0];l.unshift(e)}}let o=[...this.modelValue];o[i]=l,this.reorderDirection="top",this.$emit("update:modelValue",o),this.$emit("reorder",{originalEvent:e,value:o,direction:this.reorderDirection,listIndex:i})}},moveDown(e,i){if(this.d_selection){let l=[...this.modelValue[i]],n=this.d_selection[i];for(let e=n.length-1;e>=0;e--){let i=n[e],o=t.ObjectUtils.findIndexInList(i,l);if(o===l.length-1)break;{let e=l[o],t=l[o+1];l[o+1]=e,l[o]=t}}let o=[...this.modelValue];o[i]=l,this.reorderDirection="down",this.$emit("update:modelValue",o),this.$emit("reorder",{originalEvent:e,value:o,direction:this.reorderDirection,listIndex:i})}},moveBottom(e,i){if(this.d_selection){let l=[...this.modelValue[i]],n=this.d_selection[i];for(let e=n.length-1;e>=0;e--){let i=n[e],o=t.ObjectUtils.findIndexInList(i,l);if(o===l.length-1)break;{let e=l.splice(o,1)[0];l.push(e)}}let o=[...this.modelValue];o[i]=l,this.reorderDirection="bottom",this.$emit("update:modelValue",o),this.$emit("reorder",{originalEvent:e,value:o,direction:this.reorderDirection,listIndex:i})}},moveToTarget(e){let i=this.d_selection&&this.d_selection[0]?this.d_selection[0]:null,l=[...this.modelValue[0]],n=[...this.modelValue[1]];if(i){for(let e=0;e<i.length;e++){let o=i[e];-1==t.ObjectUtils.findIndexInList(o,n)&&n.push(l.splice(t.ObjectUtils.findIndexInList(o,l),1)[0])}let o=[...this.modelValue];o[0]=l,o[1]=n,this.$emit("update:modelValue",o),this.$emit("move-to-target",{originalEvent:e,items:i}),this.d_selection[0]=[],this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}},moveAllToTarget(e){if(this.modelValue[0]){let t=[...this.modelValue[0]],i=[...this.modelValue[1]];this.$emit("move-all-to-target",{originalEvent:e,items:t}),i=[...i,...t],t=[];let l=[...this.modelValue];l[0]=t,l[1]=i,this.$emit("update:modelValue",l),this.d_selection[0]=[],this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}},moveToSource(e){let i=this.d_selection&&this.d_selection[1]?this.d_selection[1]:null,l=[...this.modelValue[0]],n=[...this.modelValue[1]];if(i){for(let e=0;e<i.length;e++){let o=i[e];-1==t.ObjectUtils.findIndexInList(o,l)&&l.push(n.splice(t.ObjectUtils.findIndexInList(o,n),1)[0])}let o=[...this.modelValue];o[0]=l,o[1]=n,this.$emit("update:modelValue",o),this.$emit("move-to-source",{originalEvent:e,items:i}),this.d_selection[1]=[],this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}},moveAllToSource(e){if(this.modelValue[1]){let t=[...this.modelValue[0]],i=[...this.modelValue[1]];this.$emit("move-all-to-source",{originalEvent:e,items:i}),t=[...t,...i],i=[];let l=[...this.modelValue];l[0]=t,l[1]=i,this.$emit("update:modelValue",l),this.d_selection[1]=[],this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}},onItemClick(e,i,l){this.itemTouched=!1;const n=this.d_selection[l],o=t.ObjectUtils.findIndexInList(i,n),s=-1!=o;let c;if(!this.itemTouched&&this.metaKeySelection){let t=e.metaKey||e.ctrlKey;s&&t?c=n.filter(((e,t)=>t!==o)):(c=t&&n?[...n]:[],c.push(i))}else s?c=n.filter(((e,t)=>t!==o)):(c=n?[...n]:[],c.push(i));let r=[...this.d_selection];r[l]=c,this.d_selection=r,this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})},onItemDblClick(e,t,i){0===i?this.moveToTarget(e):1===i&&this.moveToSource(e)},onItemTouchEnd(){this.itemTouched=!0},onItemKeyDown(e,t,i){let l=e.currentTarget;switch(e.which){case 40:var n=this.findNextItem(l);n&&n.focus(),e.preventDefault();break;case 38:var o=this.findPrevItem(l);o&&o.focus(),e.preventDefault();break;case 13:this.onItemClick(e,t,i),e.preventDefault()}},findNextItem(e){let i=e.nextElementSibling;return i?t.DomHandler.hasClass(i,"p-picklist-item")?i:this.findNextItem(i):null},findPrevItem(e){let i=e.previousElementSibling;return i?t.DomHandler.hasClass(i,"p-picklist-item")?i:this.findPrevItem(i):null},updateListScroll(e){const i=t.DomHandler.find(e,".p-picklist-item.p-highlight");if(i&&i.length)switch(this.reorderDirection){case"up":t.DomHandler.scrollInView(e,i[0]);break;case"top":e.scrollTop=0;break;case"down":t.DomHandler.scrollInView(e,i[i.length-1]);break;case"bottom":e.scrollTop=e.scrollHeight}},createStyle(){if(!this.styleElement){this.$el.setAttribute(this.attributeSelector,""),this.styleElement=document.createElement("style"),this.styleElement.type="text/css",document.head.appendChild(this.styleElement);let e=`\n@media screen and (max-width: ${this.breakpoint}) {\n .p-picklist[${this.attributeSelector}] {\n flex-direction: column;\n }\n\n .p-picklist[${this.attributeSelector}] .p-picklist-buttons {\n padding: var(--content-padding);\n flex-direction: row;\n }\n\n .p-picklist[${this.attributeSelector}] .p-picklist-buttons .p-button {\n margin-right: var(--inline-spacing);\n margin-bottom: 0;\n }\n\n .p-picklist[${this.attributeSelector}] .p-picklist-buttons .p-button:last-child {\n margin-right: 0;\n }\n\n .p-picklist[${this.attributeSelector}] .pi-angle-right:before {\n content: "\\e930"\n }\n\n .p-picklist[${this.attributeSelector}] .pi-angle-double-right:before {\n content: "\\e92c"\n }\n\n .p-picklist[${this.attributeSelector}] .pi-angle-left:before {\n content: "\\e933"\n }\n\n .p-picklist[${this.attributeSelector}] .pi-angle-double-left:before {\n content: "\\e92f"\n }\n}\n`;this.styleElement.innerHTML=e}},destroyStyle(){this.styleElement&&(document.head.removeChild(this.styleElement),this.styleElement=null)}},computed:{sourceList(){return this.modelValue&&this.modelValue[0]?this.modelValue[0]:null},targetList(){return this.modelValue&&this.modelValue[1]?this.modelValue[1]:null},attributeSelector:()=>t.UniqueComponentId()},components:{PLButton:o.default},directives:{ripple:s.default}};const r={class:"p-picklist p-component"},a={class:"p-picklist-buttons p-picklist-source-controls"},d={class:"p-picklist-list-wrapper p-picklist-source-wrapper"},p={key:0,class:"p-picklist-header"},u={class:"p-picklist-buttons p-picklist-transfer-buttons"},m={class:"p-picklist-list-wrapper p-picklist-target-wrapper"},h={key:0,class:"p-picklist-header"},k={class:"p-picklist-buttons p-picklist-target-controls"};return 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-picklist {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n}\n.p-picklist-buttons {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-orient: vertical;\n -webkit-box-direction: normal;\n -ms-flex-direction: column;\n flex-direction: column;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n}\n.p-picklist-list-wrapper {\n -webkit-box-flex: 1;\n -ms-flex: 1 1 50%;\n flex: 1 1 50%;\n}\n.p-picklist-list {\n list-style-type: none;\n margin: 0;\n padding: 0;\n overflow: auto;\n min-height: 12rem;\n max-height: 24rem;\n}\n.p-picklist-item {\n cursor: pointer;\n overflow: hidden;\n position: relative;\n}\n.p-picklist-item.p-picklist-flip-enter-active.p-picklist-flip-enter-to,\n.p-picklist-item.p-picklist-flip-leave-active.p-picklist-flip-leave-to {\n -webkit-transition: none !important;\n transition: none !important;\n}\n"),c.render=function(e,t,i,n,o,s){const c=l.resolveComponent("PLButton"),f=l.resolveDirective("ripple");return l.openBlock(),l.createBlock("div",r,[l.createVNode("div",a,[l.createVNode(c,{type:"button",icon:"pi pi-angle-up",onClick:t[1]||(t[1]=e=>s.moveUp(e,0))}),l.createVNode(c,{type:"button",icon:"pi pi-angle-double-up",onClick:t[2]||(t[2]=e=>s.moveTop(e,0))}),l.createVNode(c,{type:"button",icon:"pi pi-angle-down",onClick:t[3]||(t[3]=e=>s.moveDown(e,0))}),l.createVNode(c,{type:"button",icon:"pi pi-angle-double-down",onClick:t[4]||(t[4]=e=>s.moveBottom(e,0))})]),l.createVNode("div",d,[e.$slots.sourceHeader?(l.openBlock(),l.createBlock("div",p,[l.renderSlot(e.$slots,"sourceHeader")])):l.createCommentVNode("",!0),l.createVNode(l.TransitionGroup,{ref:"sourceList",name:"p-picklist-flip",tag:"ul",class:"p-picklist-list p-picklist-source",style:i.listStyle,role:"listbox","aria-multiselectable":"multiple"},{default:l.withCtx((()=>[(l.openBlock(!0),l.createBlock(l.Fragment,null,l.renderList(s.sourceList,((i,n)=>l.withDirectives((l.openBlock(),l.createBlock("li",{key:s.getItemKey(i,n),tabindex:"0",class:["p-picklist-item",{"p-highlight":s.isSelected(i,0)}],onClick:e=>s.onItemClick(e,i,0),onDblclick:e=>s.onItemDblClick(e,i,0),onKeydown:e=>s.onItemKeyDown(e,i,0),onTouchend:t[5]||(t[5]=(...e)=>s.onItemTouchEnd&&s.onItemTouchEnd(...e)),role:"option","aria-selected":s.isSelected(i,0)},[l.renderSlot(e.$slots,"item",{item:i,index:n})],42,["onClick","onDblclick","onKeydown","aria-selected"])),[[f]]))),128))])),_:3},8,["style"])]),l.createVNode("div",u,[l.createVNode(c,{type:"button",icon:"pi pi-angle-right",onClick:s.moveToTarget},null,8,["onClick"]),l.createVNode(c,{type:"button",icon:"pi pi-angle-double-right",onClick:s.moveAllToTarget},null,8,["onClick"]),l.createVNode(c,{type:"button",icon:"pi pi-angle-left",onClick:s.moveToSource},null,8,["onClick"]),l.createVNode(c,{type:"button",icon:"pi pi-angle-double-left",onClick:s.moveAllToSource},null,8,["onClick"])]),l.createVNode("div",m,[e.$slots.targetHeader?(l.openBlock(),l.createBlock("div",h,[l.renderSlot(e.$slots,"targetHeader")])):l.createCommentVNode("",!0),l.createVNode(l.TransitionGroup,{ref:"targetList",name:"p-picklist-flip",tag:"ul",class:"p-picklist-list p-picklist-target",style:i.listStyle,role:"listbox","aria-multiselectable":"multiple"},{default:l.withCtx((()=>[(l.openBlock(!0),l.createBlock(l.Fragment,null,l.renderList(s.targetList,((i,n)=>l.withDirectives((l.openBlock(),l.createBlock("li",{key:s.getItemKey(i,n),tabindex:"0",class:["p-picklist-item",{"p-highlight":s.isSelected(i,1)}],onClick:e=>s.onItemClick(e,i,1),onDblclick:e=>s.onItemDblClick(e,i,1),onKeydown:e=>s.onItemKeyDown(e,i,1),onTouchend:t[6]||(t[6]=(...e)=>s.onItemTouchEnd&&s.onItemTouchEnd(...e)),role:"option","aria-selected":s.isSelected(i,1)},[l.renderSlot(e.$slots,"item",{item:i,index:n})],42,["onClick","onDblclick","onKeydown","aria-selected"])),[[f]]))),128))])),_:3},8,["style"])]),l.createVNode("div",k,[l.createVNode(c,{type:"button",icon:"pi pi-angle-up",onClick:t[7]||(t[7]=e=>s.moveUp(e,1))}),l.createVNode(c,{type:"button",icon:"pi pi-angle-double-up",onClick:t[8]||(t[8]=e=>s.moveTop(e,1))}),l.createVNode(c,{type:"button",icon:"pi pi-angle-down",onClick:t[9]||(t[9]=e=>s.moveDown(e,1))}),l.createVNode(c,{type:"button",icon:"pi pi-angle-double-down",onClick:t[10]||(t[10]=e=>s.moveBottom(e,1))})])])},c}(primevue.button,primevue.utils,primevue.ripple,Vue);