UNPKG

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.7 kB
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 s from"primevue/ripple";import{UniqueComponentId as r,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(t){return B(t)||$(t)||A(t)||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(t,e){if(t){if("string"==typeof t)return E(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)?E(t,e):void 0}}function $(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function B(t){if(Array.isArray(t))return E(t)}function E(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 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}}},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||r()}},beforeUnmount:function(){this.destroyStyle()},updated:function(){this.reorderDirection&&(this.updateListScroll(),this.reorderDirection=null)},mounted:function(){this.id=this.id||r(),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){this.focused=!0,this.findCurrentFocusedIndex(),this.scrollInView(this.focusedOptionIndex),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=S(this.modelValue),this.$emit("update:selection",this.d_selection),t.preventDefault())}},onOptionMouseDown:function(t,e){this.changeFocusedOptionIndex(e)},onOptionMouseMove:function(t){this.focusOnHover&&this.focused&&this.changeFocusedOptionIndex(t)},onArrowDownKey:function(t){var e=-1!==this.focusedOptionIndex?this.findNextOptionIndex():this.findFirstSelectedOptionIndex();this.changeFocusedOptionIndex(e),t.shiftKey&&this.onEnterKey(t),t.preventDefault()},onArrowUpKey:function(t){var e=-1!==this.focusedOptionIndex?this.findPrevOptionIndex():this.findLastSelectedOptionIndex();this.changeFocusedOptionIndex(e),t.shiftKey&&this.onEnterKey(t),t.preventDefault()},onHomeKey:function(t){if(t.ctrlKey&&t.shiftKey){var e=this.findMatchedOptionIndex();this.d_selection=S(this.modelValue).slice(0,e+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=this.findMatchedOptionIndex();this.d_selection=S(this.modelValue).slice(e,items.length),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:t,value:this.d_selection})}else this.changeFocusedOptionIndex(this.findAllItems().length-1);t.preventDefault()},onEnterKey:function(t){var e=this.findMatchedOptionIndex();this.onItemClick(t,this.modelValue[e],e),t.preventDefault()},onSpaceKey:function(t){if(t.preventDefault(),t.shiftKey&&this.d_selection&&this.d_selection.length>0){var e=l.findIndexInList(this.d_selection[0],S(this.modelValue)),i=this.findMatchedOptionIndex();this.d_selection=S(this.modelValue).slice(Math.min(e,i),Math.max(e,i)+1),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:t,value:this.d_selection})}else this.onEnterKey(t)},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 t=c.findSingle(this.list,'[data-pc-section="item"]');return c.getAttribute(t,"id")},findFirstSelectedOptionIndex:function(){if(this.hasSelectedOption){var t=c.findSingle(this.list,'[data-p-highlight="true"]');return c.getAttribute(t,"id")}return-1},findLastSelectedOptionIndex:function(){if(this.hasSelectedOption){var t=c.find(this.list,'[data-p-highlight="true"]');return l.findIndexInList(t[t.length-1],this.list.children)}return-1},findMatchedOptionIndex:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.focusedOptionIndex;return S(this.findAllItems()).findIndex((function(e){return e.id===t}))},findNextOptionIndex:function(){var t=this.findMatchedOptionIndex();return t>-1?t+1:0},findPrevOptionIndex:function(){var t=this.findMatchedOptionIndex();return t>-1?t-1:0},changeFocusedOptionIndex:function(t){var e=this.findAllItems(),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",behavior:"smooth"})},moveUp:function(t){if(this.d_selection){for(var e=S(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=S(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=S(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=S(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,s=!this.itemTouched&&this.metaKeySelection,r=this.findAllItems()[i].getAttribute("id");if(this.focusedOptionIndex=r,s){var c=t.metaKey||t.ctrlKey;o&&c?this.d_selection=this.d_selection.filter((function(t,e){return e!==n})):(this.d_selection=c&&this.d_selection?S(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?S(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},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 r()},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:t,AngleUpIcon:o,AngleDownIcon:n,AngleDoubleUpIcon:i,AngleDoubleDownIcon:e},directives:{ripple:s}};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 V(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){P(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 P(t,e,i){var n;return(e="symbol"==L(n=F(e,"string"))?n:String(n))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function F(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 T=["id","onClick","onMousedown","onMousemove","aria-selected","data-p-highlight","data-p-focused"];K.render=function(t,e,i,n,o,s){var r=u("AngleUpIcon"),l=u("OLButton"),c=u("AngleDoubleUpIcon"),d=u("AngleDownIcon"),a=u("AngleDoubleDownIcon"),S=h("ripple");return p(),f("div",m({class:t.cx("root")},t.ptm("root")),[v("div",m({class:t.cx("controls")},t.ptm("controls")),[y(t.$slots,"controlsstart"),b(l,m({type:"button",onClick:s.moveUp,"aria-label":s.moveUpAriaLabel,disabled:s.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(r,m(t.ptm("moveUpButton").icon,{"data-pc-section":"moveupicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,m({type:"button",onClick:s.moveTop,"aria-label":s.moveTopAriaLabel,disabled:s.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,m(t.ptm("moveTopButton").icon,{"data-pc-section":"movetopicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,m({type:"button",onClick:s.moveDown,"aria-label":s.moveDownAriaLabel,disabled:s.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(d,m(t.ptm("moveDownButton").icon,{"data-pc-section":"movedownicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),b(l,m({type:"button",onClick:s.moveBottom,"aria-label":s.moveBottomAriaLabel,disabled:s.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(a,m(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",m({class:t.cx("container")},t.ptm("container")),[t.$slots.header?(p(),f("div",m({key:0,class:t.cx("header")},t.ptm("header")),[y(t.$slots,"header")],16)):I("",!0),b(O,m({ref:s.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?s.focusedOptionId:void 0,"aria-label":t.ariaLabel,"aria-labelledby":t.ariaLabelledby,onFocus:s.onListFocus,onBlur:s.onListBlur,onKeydown:s.onListKeyDown},V(V(V({},t.listProps),t.ptm("list")),t.ptm("transition"))),{default:g((function(){return[(p(!0),f(x,null,w(t.modelValue,(function(i,n){return _((p(),f("li",m({key:s.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 s.onItemClick(t,i,n)},onTouchend:e[0]||(e[0]=function(){return s.onItemTouchEnd&&s.onItemTouchEnd.apply(s,arguments)}),onMousedown:function(t){return s.onOptionMouseDown(t,n)},onMousemove:function(t){return s.onOptionMouseMove(n)},"aria-selected":s.isSelected(i)},s.getPTOptions(i,"item",n),{"data-p-highlight":s.isSelected(i),"data-p-focused":"".concat(o.id,"_").concat(n)===s.focusedOptionId}),[y(t.$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};