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.6 kB
JavaScript
import e from"primevue/button";import t 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 d from"primevue/basecomponent";import a from"primevue/orderlist/style";import{resolveComponent as u,resolveDirective as h,openBlock as p,createElementBlock as f,mergeProps as m,createElementVNode as v,renderSlot as y,createVNode as b,withCtx as g,createCommentVNode as I,TransitionGroup as O,Fragment as x,renderList as w,withDirectives as _}from"vue";function S(e){return B(e)||$(e)||A(e)||D()}function D(){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 A(e,t){if(e){if("string"==typeof e)return E(e,t);var i=Object.prototype.toString.call(e).slice(8,-1);return"Object"===i&&e.constructor&&(i=e.constructor.name),"Map"===i||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?E(e,t):void 0}}function $(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function B(e){if(Array.isArray(e))return E(e)}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}var K={name:"OrderList",extends:{name:"BaseOrderList",extends:d,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},autoOptionFocus:{type:Boolean,default:!0},focusOnHover:{type:Boolean,default:!0},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:a,provide:function(){return{$parentInstance:this}}},inheritAttrs:!1,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(e){this.id=e||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(e,t){return this.dataKey?l.resolveFieldData(e,this.dataKey):t},getPTOptions:function(e,t,i){return this.ptm(t,{context:{active:this.isSelected(e),focused:"".concat(this.id,"_").concat(i)===this.focusedOptionId}})},isSelected:function(e){return-1!=l.findIndexInList(e,this.d_selection)},onListFocus:function(e){this.focused=!0,this.findCurrentFocusedIndex(),this.scrollInView(this.focusedOptionIndex),this.$emit("focus",e)},onListBlur:function(e){this.focused=!1,this.focusedOptionIndex=-1,this.$emit("blur",e)},onListKeyDown:function(e){switch(e.code){case"ArrowDown":this.onArrowDownKey(e);break;case"ArrowUp":this.onArrowUpKey(e);break;case"Home":this.onHomeKey(e);break;case"End":this.onEndKey(e);break;case"Enter":case"NumpadEnter":this.onEnterKey(e);break;case"Space":this.onSpaceKey(e);break;case"KeyA":e.ctrlKey&&(this.d_selection=S(this.modelValue),this.$emit("update:selection",this.d_selection),e.preventDefault())}},onOptionMouseDown:function(e,t){this.changeFocusedOptionIndex(t)},onOptionMouseMove:function(e){this.focusOnHover&&this.focused&&this.changeFocusedOptionIndex(e)},onArrowDownKey:function(e){var t=-1!==this.focusedOptionIndex?this.findNextOptionIndex():this.findFirstSelectedOptionIndex();this.changeFocusedOptionIndex(t),e.shiftKey&&this.onEnterKey(e),e.preventDefault()},onArrowUpKey:function(e){var t=-1!==this.focusedOptionIndex?this.findPrevOptionIndex():this.findLastSelectedOptionIndex();this.changeFocusedOptionIndex(t),e.shiftKey&&this.onEnterKey(e),e.preventDefault()},onHomeKey:function(e){if(e.ctrlKey&&e.shiftKey){var t=this.findMatchedOptionIndex();this.d_selection=S(this.modelValue).slice(0,t+1),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}else this.changeFocusedOptionIndex(0);e.preventDefault()},onEndKey:function(e){if(e.ctrlKey&&e.shiftKey){var t=this.findMatchedOptionIndex();this.d_selection=S(this.modelValue).slice(t,items.length),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}else this.changeFocusedOptionIndex(this.findAllItems().length-1);e.preventDefault()},onEnterKey:function(e){var t=this.findMatchedOptionIndex();this.onItemClick(e,this.modelValue[t],t),e.preventDefault()},onSpaceKey:function(e){if(e.preventDefault(),e.shiftKey&&this.d_selection&&this.d_selection.length>0){var t=l.findIndexInList(this.d_selection[0],S(this.modelValue)),i=this.findMatchedOptionIndex();this.d_selection=S(this.modelValue).slice(Math.min(t,i),Math.max(t,i)+1),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}else this.onEnterKey(e)},findAllItems:function(){return c.find(this.list,'[data-pc-section="item"]')},findFocusedItem:function(){return c.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]"))},findCurrentFocusedIndex:function(){-1===this.focusedOptionIndex&&(this.focusedOptionIndex=this.findFirstSelectedOptionIndex(),this.autoOptionFocus&&-1===this.focusedOptionIndex&&(this.focusedOptionIndex=this.findFirstFocusedOptionIndex()))},findFirstFocusedOptionIndex:function(){var e=c.findSingle(this.list,'[data-pc-section="item"]');return c.getAttribute(e,"id")},findFirstSelectedOptionIndex:function(){if(this.hasSelectedOption){var e=c.findSingle(this.list,'[data-p-highlight="true"]');return c.getAttribute(e,"id")}return-1},findLastSelectedOptionIndex:function(){if(this.hasSelectedOption){var e=c.find(this.list,'[data-p-highlight="true"]');return l.findIndexInList(e[e.length-1],this.list.children)}return-1},findMatchedOptionIndex:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.focusedOptionIndex;return S(this.findAllItems()).findIndex((function(t){return t.id===e}))},findNextOptionIndex:function(){var e=this.findMatchedOptionIndex();return e>-1?e+1:0},findPrevOptionIndex:function(){var e=this.findMatchedOptionIndex();return e>-1?e-1:0},changeFocusedOptionIndex:function(e){var t=this.findAllItems(),i=e>=t.length?t.length-1:e<0?0:e;this.focusedOptionIndex=t[i]?t[i].getAttribute("id"):-1,this.scrollInView(this.focusedOptionIndex)},scrollInView:function(e){var t=c.findSingle(this.list,'[data-pc-section="item"][id="'.concat(e,'"]'));t&&t.scrollIntoView&&t.scrollIntoView({block:"nearest",inline:"start",behavior:"smooth"})},moveUp:function(e){if(this.d_selection){for(var t=S(this.modelValue),i=0;i<this.d_selection.length;i++){var n=l.findIndexInList(this.d_selection[i],t);if(0===n)break;var o=t[n-1];t[n-1]=t[n],t[n]=o}this.reorderDirection="up",this.$emit("update:modelValue",t),this.$emit("reorder",{originalEvent:e,value:t,direction:this.reorderDirection})}},moveTop:function(e){if(this.d_selection){for(var t=S(this.modelValue),i=0;i<this.d_selection.length;i++){var n=l.findIndexInList(this.d_selection[i],t);if(0===n)break;var o=t.splice(n,1)[0];t.unshift(o)}this.reorderDirection="top",this.$emit("update:modelValue",t),this.$emit("reorder",{originalEvent:e,value:t,direction:this.reorderDirection})}},moveDown:function(e){if(this.d_selection){for(var t=S(this.modelValue),i=this.d_selection.length-1;i>=0;i--){var n=l.findIndexInList(this.d_selection[i],t);if(n===t.length-1)break;var o=t[n+1];t[n+1]=t[n],t[n]=o}this.reorderDirection="down",this.$emit("update:modelValue",t),this.$emit("reorder",{originalEvent:e,value:t,direction:this.reorderDirection})}},moveBottom:function(e){if(this.d_selection){for(var t=S(this.modelValue),i=this.d_selection.length-1;i>=0;i--){var n=l.findIndexInList(this.d_selection[i],t);if(n===t.length-1)break;var o=t.splice(n,1)[0];t.push(o)}this.reorderDirection="bottom",this.$emit("update:modelValue",t),this.$emit("reorder",{originalEvent:e,value:t,direction:this.reorderDirection})}},onItemClick:function(e,t,i){this.itemTouched=!1;var n=l.findIndexInList(t,this.d_selection),o=-1!=n,r=!this.itemTouched&&this.metaKeySelection,s=this.findAllItems()[i].getAttribute("id");if(this.focusedOptionIndex=s,r){var c=e.metaKey||e.ctrlKey;o&&c?this.d_selection=this.d_selection.filter((function(e,t){return t!==n})):(this.d_selection=c&&this.d_selection?S(this.d_selection):[],l.insertIntoOrderedArray(t,i,this.d_selection,this.modelValue))}else o?this.d_selection=this.d_selection.filter((function(e,t){return t!==n})):(this.d_selection=this.d_selection?S(this.d_selection):[],l.insertIntoOrderedArray(t,i,this.d_selection,this.modelValue));this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})},onItemTouchEnd:function(){this.itemTouched=!0},updateListScroll:function(){var e=c.find(this.list,'[data-pc-section="item"][data-p-highlight="true"]');if(e&&e.length)switch(this.reorderDirection){case"up":c.scrollInView(this.list,e[0]);break;case"top":this.list.scrollTop=0;break;case"down":c.scrollInView(this.list,e[e.length-1]);break;case"bottom":this.list.scrollTop=this.list.scrollHeight}},createStyle:function(){if(!this.styleElement&&!this.isUnstyled){var e;this.$el.setAttribute(this.attributeSelector,""),this.styleElement=document.createElement("style"),this.styleElement.type="text/css",c.setAttribute(this.styleElement,"nonce",null===(e=this.$primevue)||void 0===e||null===(e=e.config)||void 0===e||null===(e=e.csp)||void 0===e?void 0:e.nonce),document.head.appendChild(this.styleElement);var t="\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=t}},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(e){this.list=e?e.$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},hasSelectedOption:function(){return l.isNotEmpty(this.d_selection)}},components:{OLButton:e,AngleUpIcon:o,AngleDownIcon:n,AngleDoubleUpIcon:i,AngleDoubleDownIcon:t},directives:{ripple:r}};function L(e){return L="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},L(e)}function k(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function V(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?k(Object(i),!0).forEach((function(t){P(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):k(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function P(e,t,i){var n;return(t="symbol"==L(n=F(t,"string"))?n:String(n))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function F(e,t){if("object"!=L(e)||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=L(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var T=["id","onClick","onMousedown","onMousemove","aria-selected","data-p-highlight","data-p-focused"];K.render=function(e,t,i,n,o,r){var s=u("AngleUpIcon"),l=u("OLButton"),c=u("AngleDoubleUpIcon"),d=u("AngleDownIcon"),a=u("AngleDoubleDownIcon"),S=h("ripple");return p(),f("div",m({class:e.cx("root")},e.ptmi("root")),[v("div",m({class:e.cx("controls")},e.ptm("controls")),[y(e.$slots,"controlsstart"),b(l,m({type:"button",onClick:r.moveUp,"aria-label":r.moveUpAriaLabel,disabled:r.moveDisabled()},e.moveUpButtonProps,{pt:e.ptm("moveUpButton"),unstyled:e.unstyled}),{icon:g((function(){return[y(e.$slots,"moveupicon",{},(function(){return[b(s,m(e.ptm("moveUpButton").icon,{"data-pc-section":"moveupicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,m({type:"button",onClick:r.moveTop,"aria-label":r.moveTopAriaLabel,disabled:r.moveDisabled()},e.moveTopButtonProps,{pt:e.ptm("moveTopButton"),unstyled:e.unstyled}),{icon:g((function(){return[y(e.$slots,"movetopicon",{},(function(){return[b(c,m(e.ptm("moveTopButton").icon,{"data-pc-section":"movetopicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,m({type:"button",onClick:r.moveDown,"aria-label":r.moveDownAriaLabel,disabled:r.moveDisabled()},e.moveDownButtonProps,{pt:e.ptm("moveDownButton"),unstyled:e.unstyled}),{icon:g((function(){return[y(e.$slots,"movedownicon",{},(function(){return[b(d,m(e.ptm("moveDownButton").icon,{"data-pc-section":"movedownicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,m({type:"button",onClick:r.moveBottom,"aria-label":r.moveBottomAriaLabel,disabled:r.moveDisabled()},e.moveBottomButtonProps,{pt:e.ptm("moveBottomButton"),unstyled:e.unstyled}),{icon:g((function(){return[y(e.$slots,"movebottomicon",{},(function(){return[b(a,m(e.ptm("moveBottomButton").icon,{"data-pc-section":"movebottomicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),y(e.$slots,"controlsend")],16),v("div",m({class:e.cx("container")},e.ptm("container")),[e.$slots.header?(p(),f("div",m({key:0,class:e.cx("header")},e.ptm("header")),[y(e.$slots,"header")],16)):I("",!0),b(O,m({ref:r.listRef,id:o.id+"_list",name:"p-orderlist-flip",tag:"ul",class:e.cx("list"),style:e.listStyle,role:"listbox","aria-multiselectable":"true",tabindex:e.tabindex,"aria-activedescendant":o.focused?r.focusedOptionId:void 0,"aria-label":e.ariaLabel,"aria-labelledby":e.ariaLabelledby,onFocus:r.onListFocus,onBlur:r.onListBlur,onKeydown:r.onListKeyDown},V(V(V({},e.listProps),e.ptm("list")),e.ptm("transition"))),{default:g((function(){return[(p(!0),f(x,null,w(e.modelValue,(function(i,n){return _((p(),f("li",m({key:r.getItemKey(i,n),id:o.id+"_"+n,role:"option",class:e.cx("item",{item:i,id:"".concat(o.id,"_").concat(n)}),onClick:function(e){return r.onItemClick(e,i,n)},onTouchend:t[0]||(t[0]=function(){return r.onItemTouchEnd&&r.onItemTouchEnd.apply(r,arguments)}),onMousedown:function(e){return r.onOptionMouseDown(e,n)},onMousemove:function(e){return r.onOptionMouseMove(n)},"aria-selected":r.isSelected(i)},r.getPTOptions(i,"item",n),{"data-p-highlight":r.isSelected(i),"data-p-focused":"".concat(o.id,"_").concat(n)===r.focusedOptionId}),[y(e.$slots,"item",{item:i,index:n})],16,T)),[[S]])})),128))]})),_:3},16,["id","class","style","tabindex","aria-activedescendant","aria-label","aria-labelledby","onFocus","onBlur","onKeydown"])],16)],16)};export{K as default};