primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
2 lines (1 loc) • 16.5 kB
JavaScript
import t from"primevue/button";import e from"primevue/icons/angledoubledown";import i from"primevue/icons/angledoubleup";import n from"primevue/icons/angledown";import o from"primevue/icons/angleup";import r from"primevue/ripple";import{UniqueComponentId as s,ObjectUtils as l,DomHandler as c}from"primevue/utils";import a from"primevue/basecomponent";import d from"primevue/orderlist/style";import{resolveComponent as u,resolveDirective as p,openBlock as h,createElementBlock as m,mergeProps as f,createElementVNode as v,renderSlot as y,createVNode as b,withCtx as g,createCommentVNode as I,TransitionGroup as x,Fragment as w,renderList as O,withDirectives as _}from"vue";function D(t){return E(t)||A(t)||$(t)||S()}function S(){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 $(t,e){if(t){if("string"==typeof t)return K(t,e);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?K(t,e):void 0}}function A(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function E(t){if(Array.isArray(t))return K(t)}function K(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=new Array(e);i<e;i++)n[i]=t[i];return n}var B={name:"OrderList",extends:{name:"BaseOrderList",extends:a,props:{modelValue:{type:Array,default:null},selection:{type:Array,default:null},dataKey:{type:String,default:null},listStyle:{type:null,default:null},metaKeySelection:{type:Boolean,default:!1},responsive:{type:Boolean,default:!0},breakpoint:{type:String,default:"960px"},stripedRows:{type:Boolean,default:!1},tabindex:{type:Number,default:0},listProps:{type:null,default:null},moveUpButtonProps:{type:null,default:null},moveTopButtonProps:{type:null,default:null},moveDownButtonProps:{type:null,default:null},moveBottomButtonProps:{type:null,default:null},ariaLabelledby:{type:String,default:null},ariaLabel:{type:String,default:null}},style:d,provide:function(){return{$parentInstance:this}}},emits:["update:modelValue","reorder","update:selection","selection-change","focus","blur"],itemTouched:!1,reorderDirection:null,styleElement:null,list:null,data:function(){return{id:this.$attrs.id,d_selection:this.selection,focused:!1,focusedOptionIndex:-1}},watch:{"$attrs.id":function(t){this.id=t||s()}},beforeUnmount:function(){this.destroyStyle()},updated:function(){this.reorderDirection&&(this.updateListScroll(),this.reorderDirection=null)},mounted:function(){this.id=this.id||s(),this.responsive&&this.createStyle()},methods:{getItemKey:function(t,e){return this.dataKey?l.resolveFieldData(t,this.dataKey):e},getPTOptions:function(t,e,i){return this.ptm(e,{context:{active:this.isSelected(t),focused:"".concat(this.id,"_").concat(i)===this.focusedOptionId}})},isSelected:function(t){return-1!=l.findIndexInList(t,this.d_selection)},onListFocus:function(t){var e=c.findSingle(this.list,'[data-p-highlight="true"]')||c.findSingle(this.list,'[data-pc-section="item"]');if(e){var i=l.findIndexInList(e,this.list.children);this.focused=!0,this.changeFocusedOptionIndex(-1!==this.focusedOptionIndex?this.focusedOptionIndex:e?i:-1),this.$emit("focus",t)}},onListBlur:function(t){this.focused=!1,this.focusedOptionIndex=-1,this.$emit("blur",t)},onListKeyDown:function(t){switch(t.code){case"ArrowDown":this.onArrowDownKey(t);break;case"ArrowUp":this.onArrowUpKey(t);break;case"Home":this.onHomeKey(t);break;case"End":this.onEndKey(t);break;case"Enter":case"NumpadEnter":this.onEnterKey(t);break;case"Space":this.onSpaceKey(t);break;case"KeyA":t.ctrlKey&&(this.d_selection=D(this.modelValue),this.$emit("update:selection",this.d_selection),t.preventDefault())}},onOptionMouseDown:function(t){this.focused=!0,this.focusedOptionIndex=t},onArrowDownKey:function(t){var e=this.findNextOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(e),t.shiftKey&&this.onEnterKey(t),t.preventDefault()},onArrowUpKey:function(t){var e=this.findPrevOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(e),t.shiftKey&&this.onEnterKey(t),t.preventDefault()},onHomeKey:function(t){if(t.ctrlKey&&t.shiftKey){var e=c.find(this.list,'[data-pc-section="item"]'),i=c.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]")),n=D(e).findIndex((function(t){return t===i}));this.d_selection=D(this.modelValue).slice(0,n+1),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:t,value:this.d_selection})}else this.changeFocusedOptionIndex(0);t.preventDefault()},onEndKey:function(t){if(t.ctrlKey&&t.shiftKey){var e=c.find(this.list,'[data-pc-section="item"]'),i=c.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]")),n=D(e).findIndex((function(t){return t===i}));this.d_selection=D(this.modelValue).slice(n,e.length),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:t,value:this.d_selection})}else this.changeFocusedOptionIndex(c.find(this.list,'[data-pc-section="item"]').length-1);t.preventDefault()},onEnterKey:function(t){var e=c.find(this.list,'[data-pc-section="item"]'),i=c.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]")),n=D(e).findIndex((function(t){return t===i}));this.onItemClick(t,this.modelValue[n],n),t.preventDefault()},onSpaceKey:function(t){if(t.preventDefault(),t.shiftKey&&this.d_selection&&this.d_selection.length>0){var e=c.find(this.list,'[data-pc-section="item"]'),i=l.findIndexInList(this.d_selection[0],D(this.modelValue)),n=c.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]")),o=D(e).findIndex((function(t){return t===n}));this.d_selection=D(this.modelValue).slice(Math.min(i,o),Math.max(i,o)+1),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:t,value:this.d_selection})}else this.onEnterKey(t)},findNextOptionIndex:function(t){var e=D(c.find(this.list,'[data-pc-section="item"]')).findIndex((function(e){return e.id===t}));return e>-1?e+1:0},findPrevOptionIndex:function(t){var e=D(c.find(this.list,'[data-pc-section="item"]')).findIndex((function(e){return e.id===t}));return e>-1?e-1:0},changeFocusedOptionIndex:function(t){var e=c.find(this.list,'[data-pc-section="item"]'),i=t>=e.length?e.length-1:t<0?0:t;this.focusedOptionIndex=e[i]?e[i].getAttribute("id"):-1,this.scrollInView(this.focusedOptionIndex)},scrollInView:function(t){var e=c.findSingle(this.list,'[data-pc-section="item"][id="'.concat(t,'"]'));e&&e.scrollIntoView&&e.scrollIntoView({block:"nearest",inline:"start"})},moveUp:function(t){if(this.d_selection){for(var e=D(this.modelValue),i=0;i<this.d_selection.length;i++){var n=l.findIndexInList(this.d_selection[i],e);if(0===n)break;var o=e[n-1];e[n-1]=e[n],e[n]=o}this.reorderDirection="up",this.$emit("update:modelValue",e),this.$emit("reorder",{originalEvent:t,value:e,direction:this.reorderDirection})}},moveTop:function(t){if(this.d_selection){for(var e=D(this.modelValue),i=0;i<this.d_selection.length;i++){var n=l.findIndexInList(this.d_selection[i],e);if(0===n)break;var o=e.splice(n,1)[0];e.unshift(o)}this.reorderDirection="top",this.$emit("update:modelValue",e),this.$emit("reorder",{originalEvent:t,value:e,direction:this.reorderDirection})}},moveDown:function(t){if(this.d_selection){for(var e=D(this.modelValue),i=this.d_selection.length-1;i>=0;i--){var n=l.findIndexInList(this.d_selection[i],e);if(n===e.length-1)break;var o=e[n+1];e[n+1]=e[n],e[n]=o}this.reorderDirection="down",this.$emit("update:modelValue",e),this.$emit("reorder",{originalEvent:t,value:e,direction:this.reorderDirection})}},moveBottom:function(t){if(this.d_selection){for(var e=D(this.modelValue),i=this.d_selection.length-1;i>=0;i--){var n=l.findIndexInList(this.d_selection[i],e);if(n===e.length-1)break;var o=e.splice(n,1)[0];e.push(o)}this.reorderDirection="bottom",this.$emit("update:modelValue",e),this.$emit("reorder",{originalEvent:t,value:e,direction:this.reorderDirection})}},onItemClick:function(t,e,i){this.itemTouched=!1;var n=l.findIndexInList(e,this.d_selection),o=-1!=n,r=!this.itemTouched&&this.metaKeySelection,s=c.find(this.list,'[data-pc-section="item"]')[i].getAttribute("id");if(this.focusedOptionIndex=s,r){var a=t.metaKey||t.ctrlKey;o&&a?this.d_selection=this.d_selection.filter((function(t,e){return e!==n})):(this.d_selection=a&&this.d_selection?D(this.d_selection):[],l.insertIntoOrderedArray(e,i,this.d_selection,this.modelValue))}else o?this.d_selection=this.d_selection.filter((function(t,e){return e!==n})):(this.d_selection=this.d_selection?D(this.d_selection):[],l.insertIntoOrderedArray(e,i,this.d_selection,this.modelValue));this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:t,value:this.d_selection})},onItemTouchEnd:function(){this.itemTouched=!0},findNextItem:function(t){var e=t.nextElementSibling;return e?"item"!==c.getAttribute(e,"data-pc-section")?this.findNextItem(e):e:null},findPrevItem:function(t){var e=t.previousElementSibling;return e?"item"!==c.getAttribute(nextItem,"data-pc-section")?this.findPrevItem(e):e:null},updateListScroll:function(){var t=c.find(this.list,'[data-pc-section="item"][data-p-highlight="true"]');if(t&&t.length)switch(this.reorderDirection){case"up":c.scrollInView(this.list,t[0]);break;case"top":this.list.scrollTop=0;break;case"down":c.scrollInView(this.list,t[t.length-1]);break;case"bottom":this.list.scrollTop=this.list.scrollHeight}},createStyle:function(){if(!this.styleElement&&!this.isUnstyled){var t;this.$el.setAttribute(this.attributeSelector,""),this.styleElement=document.createElement("style"),this.styleElement.type="text/css",c.setAttribute(this.styleElement,"nonce",null===(t=this.$primevue)||void 0===t||null===(t=t.config)||void 0===t||null===(t=t.csp)||void 0===t?void 0:t.nonce),document.head.appendChild(this.styleElement);var e="\n@media screen and (max-width: ".concat(this.breakpoint,") {\n .p-orderlist[").concat(this.attributeSelector,"] {\n flex-direction: column;\n }\n\n .p-orderlist[").concat(this.attributeSelector,"] .p-orderlist-controls {\n padding: var(--content-padding);\n flex-direction: row;\n }\n\n .p-orderlist[").concat(this.attributeSelector,"] .p-orderlist-controls .p-button {\n margin-right: var(--inline-spacing);\n margin-bottom: 0;\n }\n\n .p-orderlist[").concat(this.attributeSelector,"] .p-orderlist-controls .p-button:last-child {\n margin-right: 0;\n }\n}\n");this.styleElement.innerHTML=e}},destroyStyle:function(){this.styleElement&&(document.head.removeChild(this.styleElement),this.styleElement=null)},moveDisabled:function(){if(!this.d_selection||!this.d_selection.length)return!0},listRef:function(t){this.list=t?t.$el:void 0}},computed:{attributeSelector:function(){return s()},focusedOptionId:function(){return-1!==this.focusedOptionIndex?this.focusedOptionIndex:null},moveUpAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.moveUp:void 0},moveTopAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.moveTop:void 0},moveDownAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.moveDown:void 0},moveBottomAriaLabel:function(){return this.$primevue.config.locale.aria?this.$primevue.config.locale.aria.moveBottom:void 0}},components:{OLButton:t,AngleUpIcon:o,AngleDownIcon:n,AngleDoubleUpIcon:i,AngleDoubleDownIcon:e},directives:{ripple:r}};function L(t){return L="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},L(t)}function k(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function P(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?k(Object(i),!0).forEach((function(e){V(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):k(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}function V(t,e,i){var n;return(e="symbol"==L(n=T(e,"string"))?n:String(n))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function T(t,e){if("object"!=L(t)||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!=L(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}var U=["id","onClick","aria-selected","onMousedown","data-p-highlight","data-p-focused"];B.render=function(t,e,i,n,o,r){var s=u("AngleUpIcon"),l=u("OLButton"),c=u("AngleDoubleUpIcon"),a=u("AngleDownIcon"),d=u("AngleDoubleDownIcon"),D=p("ripple");return h(),m("div",f({class:t.cx("root")},t.ptm("root")),[v("div",f({class:t.cx("controls")},t.ptm("controls")),[y(t.$slots,"controlsstart"),b(l,f({type:"button",onClick:r.moveUp,"aria-label":r.moveUpAriaLabel,disabled:r.moveDisabled()},t.moveUpButtonProps,{pt:t.ptm("moveUpButton"),unstyled:t.unstyled,"data-pc-section":"moveupbutton"}),{icon:g((function(){return[y(t.$slots,"moveupicon",{},(function(){return[b(s,f(t.ptm("moveUpButton").icon,{"data-pc-section":"moveupicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,f({type:"button",onClick:r.moveTop,"aria-label":r.moveTopAriaLabel,disabled:r.moveDisabled()},t.moveTopButtonProps,{pt:t.ptm("moveTopButton"),unstyled:t.unstyled,"data-pc-section":"movetopbutton"}),{icon:g((function(){return[y(t.$slots,"movetopicon",{},(function(){return[b(c,f(t.ptm("moveTopButton").icon,{"data-pc-section":"movetopicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,f({type:"button",onClick:r.moveDown,"aria-label":r.moveDownAriaLabel,disabled:r.moveDisabled()},t.moveDownButtonProps,{pt:t.ptm("moveDownButton"),unstyled:t.unstyled,"data-pc-section":"movedownbutton"}),{icon:g((function(){return[y(t.$slots,"movedownicon",{},(function(){return[b(a,f(t.ptm("moveDownButton").icon,{"data-pc-section":"movedownicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,f({type:"button",onClick:r.moveBottom,"aria-label":r.moveBottomAriaLabel,disabled:r.moveDisabled()},t.moveBottomButtonProps,{pt:t.ptm("moveBottomButton"),unstyled:t.unstyled,"data-pc-section":"movebottombutton"}),{icon:g((function(){return[y(t.$slots,"movebottomicon",{},(function(){return[b(d,f(t.ptm("moveBottomButton").icon,{"data-pc-section":"movebottomicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),y(t.$slots,"controlsend")],16),v("div",f({class:t.cx("container")},t.ptm("container")),[t.$slots.header?(h(),m("div",f({key:0,class:t.cx("header")},t.ptm("header")),[y(t.$slots,"header")],16)):I("",!0),b(x,f({ref:r.listRef,id:o.id+"_list",name:"p-orderlist-flip",tag:"ul",class:t.cx("list"),style:t.listStyle,role:"listbox","aria-multiselectable":"true",tabindex:t.tabindex,"aria-activedescendant":o.focused?r.focusedOptionId:void 0,"aria-label":t.ariaLabel,"aria-labelledby":t.ariaLabelledby,onFocus:r.onListFocus,onBlur:r.onListBlur,onKeydown:r.onListKeyDown},P(P(P({},t.listProps),t.ptm("list")),t.ptm("transition"))),{default:g((function(){return[(h(!0),m(w,null,O(t.modelValue,(function(i,n){return _((h(),m("li",f({key:r.getItemKey(i,n),id:o.id+"_"+n,role:"option",class:t.cx("item",{item:i,id:"".concat(o.id,"_").concat(n)}),onClick:function(t){return r.onItemClick(t,i,n)},onTouchend:e[0]||(e[0]=function(){return r.onItemTouchEnd&&r.onItemTouchEnd.apply(r,arguments)}),"aria-selected":r.isSelected(i),onMousedown:function(t){return r.onOptionMouseDown(n)}},r.getPTOptions(i,"item",n),{"data-p-highlight":r.isSelected(i),"data-p-focused":"".concat(o.id,"_").concat(n)===r.focusedOptionId}),[y(t.$slots,"item",{item:i,index:n})],16,U)),[[D]])})),128))]})),_:3},16,["id","class","style","tabindex","aria-activedescendant","aria-label","aria-labelledby","onFocus","onBlur","onKeydown"])],16)],16)};export{B as default};