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) 10.6 kB
import e from"primevue/button";import{ObjectUtils as t,DomHandler as i}from"primevue/utils";import l from"primevue/ripple";import{resolveComponent as o,resolveDirective as n,openBlock as s,createBlock as r,createVNode as c,renderSlot as a,createCommentVNode as d,TransitionGroup as p,withCtx as u,Fragment as m,renderList as h,withDirectives as f}from"vue";var v={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}},itemTouched:!1,reorderDirection: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)},watch:{selection(e){this.d_selection=e}},methods:{getItemKey(e,i){return this.dataKey?t.resolveFieldData(e,this.dataKey):i},isSelected(e,i){return-1!=t.findIndexInList(e,this.d_selection[i])},moveUp(e,i){if(this.d_selection&&this.d_selection[i]){let l=[...this.modelValue[i]],o=this.d_selection[i];for(let e=0;e<o.length;e++){let i=o[e],n=t.findIndexInList(i,l);if(0===n)break;{let e=l[n],t=l[n-1];l[n-1]=e,l[n]=t}}let n=[...this.modelValue];n[i]=l,this.reorderDirection="up",this.$emit("update:modelValue",n),this.$emit("reorder",{originalEvent:e,value:n,direction:this.reorderDirection,listIndex:i})}},moveTop(e,i){if(this.d_selection){let l=[...this.modelValue[i]],o=this.d_selection[i];for(let e=0;e<o.length;e++){let i=o[e],n=t.findIndexInList(i,l);if(0===n)break;{let e=l.splice(n,1)[0];l.unshift(e)}}let n=[...this.modelValue];n[i]=l,this.reorderDirection="top",this.$emit("update:modelValue",n),this.$emit("reorder",{originalEvent:e,value:n,direction:this.reorderDirection})}},moveDown(e,i){if(this.d_selection){let l=[...this.modelValue[i]],o=this.d_selection[i];for(let e=o.length-1;e>=0;e--){let i=o[e],n=t.findIndexInList(i,l);if(n===l.length-1)break;{let e=l[n],t=l[n+1];l[n+1]=e,l[n]=t}}let n=[...this.modelValue];n[i]=l,this.reorderDirection="down",this.$emit("update:modelValue",n),this.$emit("reorder",{originalEvent:e,value:n,direction:this.reorderDirection})}},moveBottom(e,i){if(this.d_selection){let l=[...this.modelValue[i]],o=this.d_selection[i];for(let e=o.length-1;e>=0;e--){let i=o[e],n=t.findIndexInList(i,l);if(n===l.length-1)break;{let e=l.splice(n,1)[0];l.push(e)}}let n=[...this.modelValue];n[i]=l,this.reorderDirection="bottom",this.$emit("update:modelValue",n),this.$emit("reorder",{originalEvent:e,value:n,direction:this.reorderDirection})}},moveToTarget(e){let i=this.d_selection&&this.d_selection[0]?this.d_selection[0]:null,l=[...this.modelValue[0]],o=[...this.modelValue[1]];if(i){for(let e=0;e<i.length;e++){let n=i[e];-1==t.findIndexInList(n,o)&&o.push(l.splice(t.findIndexInList(n,l),1)[0])}let n=[...this.modelValue];n[0]=l,n[1]=o,this.$emit("update:modelValue",n),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]],o=[...this.modelValue[1]];if(i){for(let e=0;e<i.length;e++){let n=i[e];-1==t.findIndexInList(n,l)&&l.push(o.splice(t.findIndexInList(n,o),1)[0])}let n=[...this.modelValue];n[0]=l,n[1]=o,this.$emit("update:modelValue",n),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,o){this.itemTouched=!1;const n=this.d_selection[o],s=t.findIndexInList(i,n),r=-1!=s;let c;if(!this.itemTouched&&this.metaKeySelection){let t=e.metaKey||e.ctrlKey;r&&t?c=n.filter(((e,t)=>t!==s)):(c=t&&n?[...n]:[],c.push(i))}else r?c=n.filter(((e,t)=>t!==s)):(c=n?[...n]:[],c.push(i));let a=[...this.d_selection];a[o]=c,this.d_selection=a,this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})},onItemTouchEnd(){this.itemTouched=!0},onItemKeyDown(e,t,i,l){let o=e.currentTarget;switch(e.which){case 40:var n=this.findNextItem(o);n&&n.focus(),e.preventDefault();break;case 38:var s=this.findPrevItem(o);s&&s.focus(),e.preventDefault();break;case 13:this.onItemClick(e,t,i,l),e.preventDefault()}},findNextItem(e){let t=e.nextElementSibling;return t?i.hasClass(t,"p-picklist-item")?t:this.findNextItem(t):null},findPrevItem(e){let t=e.previousElementSibling;return t?i.hasClass(t,"p-picklist-item")?t:this.findPrevItem(t):null},updateListScroll(e){const t=i.find(e,".p-picklist-item.p-highlight");if(t&&t.length)switch(this.reorderDirection){case"up":i.scrollInView(e,t[0]);break;case"top":e.scrollTop=0;break;case"down":i.scrollInView(e,t[t.length-1]);break;case"bottom":e.scrollTop=e.scrollHeight}}},computed:{sourceList(){return this.modelValue&&this.modelValue[0]?this.modelValue[0]:null},targetList(){return this.modelValue&&this.modelValue[1]?this.modelValue[1]:null}},components:{PLButton:e},directives:{ripple:l}};const g={class:"p-picklist p-component"},k={class:"p-picklist-buttons p-picklist-source-controls"},y={class:"p-picklist-list-wrapper p-picklist-source-wrapper"},b={key:0,class:"p-picklist-header"},x={class:"p-picklist-buttons p-picklist-transfer-buttons"},I={class:"p-picklist-list-wrapper p-picklist-target-wrapper"},V={key:0,class:"p-picklist-header"},_={class:"p-picklist-buttons p-picklist-target-controls"};!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-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"),v.render=function(e,t,i,l,v,w){const $=o("PLButton"),T=n("ripple");return s(),r("div",g,[c("div",k,[c($,{type:"button",icon:"pi pi-angle-up",onClick:t[1]||(t[1]=e=>w.moveUp(e,0))}),c($,{type:"button",icon:"pi pi-angle-double-up",onClick:t[2]||(t[2]=e=>w.moveTop(e,0))}),c($,{type:"button",icon:"pi pi-angle-down",onClick:t[3]||(t[3]=e=>w.moveDown(e,0))}),c($,{type:"button",icon:"pi pi-angle-double-down",onClick:t[4]||(t[4]=e=>w.moveBottom(e,0))})]),c("div",y,[e.$slots.sourceHeader?(s(),r("div",b,[a(e.$slots,"sourceHeader")])):d("",!0),c(p,{ref:"sourceList",name:"p-picklist-flip",tag:"ul",class:"p-picklist-list p-picklist-source",style:i.listStyle,role:"listbox","aria-multiselectable":"multiple"},{default:u((()=>[(s(!0),r(m,null,h(w.sourceList,((i,l)=>f((s(),r("li",{key:w.getItemKey(i,l),tabindex:"0",class:["p-picklist-item",{"p-highlight":w.isSelected(i,0)}],onClick:e=>w.onItemClick(e,i,l,0),onKeydown:e=>w.onItemKeyDown(e,i,l,0),onTouchend:t[5]||(t[5]=(...e)=>w.onItemTouchEnd&&w.onItemTouchEnd(...e)),role:"option","aria-selected":w.isSelected(i,0)},[a(e.$slots,"item",{item:i,index:l})],42,["onClick","onKeydown","aria-selected"])),[[T]]))),128))])),_:1},8,["style"])]),c("div",x,[c($,{type:"button",icon:"pi pi-angle-right",onClick:w.moveToTarget},null,8,["onClick"]),c($,{type:"button",icon:"pi pi-angle-double-right",onClick:w.moveAllToTarget},null,8,["onClick"]),c($,{type:"button",icon:"pi pi-angle-left",onClick:w.moveToSource},null,8,["onClick"]),c($,{type:"button",icon:"pi pi-angle-double-left",onClick:w.moveAllToSource},null,8,["onClick"])]),c("div",I,[e.$slots.targetHeader?(s(),r("div",V,[a(e.$slots,"targetHeader")])):d("",!0),c(p,{ref:"targetList",name:"p-picklist-flip",tag:"ul",class:"p-picklist-list p-picklist-target",style:i.listStyle,role:"listbox","aria-multiselectable":"multiple"},{default:u((()=>[(s(!0),r(m,null,h(w.targetList,((i,l)=>f((s(),r("li",{key:w.getItemKey(i,l),tabindex:"0",class:["p-picklist-item",{"p-highlight":w.isSelected(i,1)}],onClick:e=>w.onItemClick(e,i,l,1),onKeydown:e=>w.onItemKeyDown(e,i,l,1),onTouchend:t[6]||(t[6]=(...e)=>w.onItemTouchEnd&&w.onItemTouchEnd(...e)),role:"option","aria-selected":w.isSelected(i,1)},[a(e.$slots,"item",{item:i,index:l})],42,["onClick","onKeydown","aria-selected"])),[[T]]))),128))])),_:1},8,["style"])]),c("div",_,[c($,{type:"button",icon:"pi pi-angle-up",onClick:t[7]||(t[7]=e=>w.moveUp(e,1))}),c($,{type:"button",icon:"pi pi-angle-double-up",onClick:t[8]||(t[8]=e=>w.moveTop(e,1))}),c($,{type:"button",icon:"pi pi-angle-down",onClick:t[9]||(t[9]=e=>w.moveDown(e,1))}),c($,{type:"button",icon:"pi pi-angle-double-down",onClick:t[10]||(t[10]=e=>w.moveBottom(e,1))})])])};export default v;