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) 17.4 kB
this.primevue=this.primevue||{},this.primevue.orderlist=function(e,t,n,i,o,r,l,s,c,a){"use strict";function d(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=d(e),p=d(t),m=d(n),h=d(i),f=d(o),v=d(r);function b(e){return D(e)||I(e)||g(e)||y()}function y(){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 g(e,t){if(e){if("string"==typeof e)return x(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?x(e,t):void 0}}function I(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function D(e){if(Array.isArray(e))return x(e)}function x(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=new Array(t);n<t;n++)i[n]=e[n];return i}var O={name:"OrderList",extends:{name:"BaseOrderList",extends:d(s).default,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(c).default,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(e){this.id=e||l.UniqueComponentId()}},beforeUnmount:function(){this.destroyStyle()},updated:function(){this.reorderDirection&&(this.updateListScroll(),this.reorderDirection=null)},mounted:function(){this.id=this.id||l.UniqueComponentId(),this.responsive&&this.createStyle()},methods:{getItemKey:function(e,t){return this.dataKey?l.ObjectUtils.resolveFieldData(e,this.dataKey):t},getPTOptions:function(e,t,n){return this.ptm(t,{context:{active:this.isSelected(e),focused:"".concat(this.id,"_").concat(n)===this.focusedOptionId}})},isSelected:function(e){return-1!=l.ObjectUtils.findIndexInList(e,this.d_selection)},onListFocus:function(e){var t=l.DomHandler.findSingle(this.list,'[data-p-highlight="true"]')||l.DomHandler.findSingle(this.list,'[data-pc-section="item"]');if(t){var n=l.ObjectUtils.findIndexInList(t,this.list.children);this.focused=!0,this.changeFocusedOptionIndex(-1!==this.focusedOptionIndex?this.focusedOptionIndex:t?n:-1),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=b(this.modelValue),this.$emit("update:selection",this.d_selection),e.preventDefault())}},onOptionMouseDown:function(e){this.focused=!0,this.focusedOptionIndex=e},onArrowDownKey:function(e){var t=this.findNextOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(t),e.shiftKey&&this.onEnterKey(e),e.preventDefault()},onArrowUpKey:function(e){var t=this.findPrevOptionIndex(this.focusedOptionIndex);this.changeFocusedOptionIndex(t),e.shiftKey&&this.onEnterKey(e),e.preventDefault()},onHomeKey:function(e){if(e.ctrlKey&&e.shiftKey){var t=l.DomHandler.find(this.list,'[data-pc-section="item"]'),n=l.DomHandler.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]")),i=b(t).findIndex((function(e){return e===n}));this.d_selection=b(this.modelValue).slice(0,i+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=l.DomHandler.find(this.list,'[data-pc-section="item"]'),n=l.DomHandler.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]")),i=b(t).findIndex((function(e){return e===n}));this.d_selection=b(this.modelValue).slice(i,t.length),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}else this.changeFocusedOptionIndex(l.DomHandler.find(this.list,'[data-pc-section="item"]').length-1);e.preventDefault()},onEnterKey:function(e){var t=l.DomHandler.find(this.list,'[data-pc-section="item"]'),n=l.DomHandler.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]")),i=b(t).findIndex((function(e){return e===n}));this.onItemClick(e,this.modelValue[i],i),e.preventDefault()},onSpaceKey:function(e){if(e.preventDefault(),e.shiftKey&&this.d_selection&&this.d_selection.length>0){var t=l.DomHandler.find(this.list,'[data-pc-section="item"]'),n=l.ObjectUtils.findIndexInList(this.d_selection[0],b(this.modelValue)),i=l.DomHandler.findSingle(this.list,'[data-pc-section="item"][id='.concat(this.focusedOptionIndex,"]")),o=b(t).findIndex((function(e){return e===i}));this.d_selection=b(this.modelValue).slice(Math.min(n,o),Math.max(n,o)+1),this.$emit("update:selection",this.d_selection),this.$emit("selection-change",{originalEvent:e,value:this.d_selection})}else this.onEnterKey(e)},findNextOptionIndex:function(e){var t=b(l.DomHandler.find(this.list,'[data-pc-section="item"]')).findIndex((function(t){return t.id===e}));return t>-1?t+1:0},findPrevOptionIndex:function(e){var t=b(l.DomHandler.find(this.list,'[data-pc-section="item"]')).findIndex((function(t){return t.id===e}));return t>-1?t-1:0},changeFocusedOptionIndex:function(e){var t=l.DomHandler.find(this.list,'[data-pc-section="item"]'),n=e>=t.length?t.length-1:e<0?0:e;this.focusedOptionIndex=t[n]?t[n].getAttribute("id"):-1,this.scrollInView(this.focusedOptionIndex)},scrollInView:function(e){var t=l.DomHandler.findSingle(this.list,'[data-pc-section="item"][id="'.concat(e,'"]'));t&&t.scrollIntoView&&t.scrollIntoView({block:"nearest",inline:"start"})},moveUp:function(e){if(this.d_selection){for(var t=b(this.modelValue),n=0;n<this.d_selection.length;n++){var i=l.ObjectUtils.findIndexInList(this.d_selection[n],t);if(0===i)break;var o=t[i-1];t[i-1]=t[i],t[i]=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=b(this.modelValue),n=0;n<this.d_selection.length;n++){var i=l.ObjectUtils.findIndexInList(this.d_selection[n],t);if(0===i)break;var o=t.splice(i,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=b(this.modelValue),n=this.d_selection.length-1;n>=0;n--){var i=l.ObjectUtils.findIndexInList(this.d_selection[n],t);if(i===t.length-1)break;var o=t[i+1];t[i+1]=t[i],t[i]=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=b(this.modelValue),n=this.d_selection.length-1;n>=0;n--){var i=l.ObjectUtils.findIndexInList(this.d_selection[n],t);if(i===t.length-1)break;var o=t.splice(i,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,n){this.itemTouched=!1;var i=l.ObjectUtils.findIndexInList(t,this.d_selection),o=-1!=i,r=!this.itemTouched&&this.metaKeySelection,s=l.DomHandler.find(this.list,'[data-pc-section="item"]')[n].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!==i})):(this.d_selection=c&&this.d_selection?b(this.d_selection):[],l.ObjectUtils.insertIntoOrderedArray(t,n,this.d_selection,this.modelValue))}else o?this.d_selection=this.d_selection.filter((function(e,t){return t!==i})):(this.d_selection=this.d_selection?b(this.d_selection):[],l.ObjectUtils.insertIntoOrderedArray(t,n,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},findNextItem:function(e){var t=e.nextElementSibling;return t?"item"!==l.DomHandler.getAttribute(t,"data-pc-section")?this.findNextItem(t):t:null},findPrevItem:function(e){var t=e.previousElementSibling;return t?"item"!==l.DomHandler.getAttribute(nextItem,"data-pc-section")?this.findPrevItem(t):t:null},updateListScroll:function(){var e=l.DomHandler.find(this.list,'[data-pc-section="item"][data-p-highlight="true"]');if(e&&e.length)switch(this.reorderDirection){case"up":l.DomHandler.scrollInView(this.list,e[0]);break;case"top":this.list.scrollTop=0;break;case"down":l.DomHandler.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",l.DomHandler.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 l.UniqueComponentId()},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:u.default,AngleUpIcon:f.default,AngleDownIcon:h.default,AngleDoubleUpIcon:m.default,AngleDoubleDownIcon:p.default},directives:{ripple:v.default}};function w(e){return w="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},w(e)}function S(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function _(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?S(Object(n),!0).forEach((function(t){E(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):S(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function E(e,t,n){var i;return(t="symbol"==w(i=B(t,"string"))?i:String(i))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function B(e,t){if("object"!=w(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=w(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var $=["id","onClick","aria-selected","onMousedown","data-p-highlight","data-p-focused"];return O.render=function(e,t,n,i,o,r){var l=a.resolveComponent("AngleUpIcon"),s=a.resolveComponent("OLButton"),c=a.resolveComponent("AngleDoubleUpIcon"),d=a.resolveComponent("AngleDownIcon"),u=a.resolveComponent("AngleDoubleDownIcon"),p=a.resolveDirective("ripple");return a.openBlock(),a.createElementBlock("div",a.mergeProps({class:e.cx("root")},e.ptm("root")),[a.createElementVNode("div",a.mergeProps({class:e.cx("controls")},e.ptm("controls")),[a.renderSlot(e.$slots,"controlsstart"),a.createVNode(s,a.mergeProps({type:"button",onClick:r.moveUp,"aria-label":r.moveUpAriaLabel,disabled:r.moveDisabled()},e.moveUpButtonProps,{pt:e.ptm("moveUpButton"),unstyled:e.unstyled,"data-pc-section":"moveupbutton"}),{icon:a.withCtx((function(){return[a.renderSlot(e.$slots,"moveupicon",{},(function(){return[a.createVNode(l,a.mergeProps(e.ptm("moveUpButton").icon,{"data-pc-section":"moveupicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),a.createVNode(s,a.mergeProps({type:"button",onClick:r.moveTop,"aria-label":r.moveTopAriaLabel,disabled:r.moveDisabled()},e.moveTopButtonProps,{pt:e.ptm("moveTopButton"),unstyled:e.unstyled,"data-pc-section":"movetopbutton"}),{icon:a.withCtx((function(){return[a.renderSlot(e.$slots,"movetopicon",{},(function(){return[a.createVNode(c,a.mergeProps(e.ptm("moveTopButton").icon,{"data-pc-section":"movetopicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),a.createVNode(s,a.mergeProps({type:"button",onClick:r.moveDown,"aria-label":r.moveDownAriaLabel,disabled:r.moveDisabled()},e.moveDownButtonProps,{pt:e.ptm("moveDownButton"),unstyled:e.unstyled,"data-pc-section":"movedownbutton"}),{icon:a.withCtx((function(){return[a.renderSlot(e.$slots,"movedownicon",{},(function(){return[a.createVNode(d,a.mergeProps(e.ptm("moveDownButton").icon,{"data-pc-section":"movedownicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),a.createVNode(s,a.mergeProps({type:"button",onClick:r.moveBottom,"aria-label":r.moveBottomAriaLabel,disabled:r.moveDisabled()},e.moveBottomButtonProps,{pt:e.ptm("moveBottomButton"),unstyled:e.unstyled,"data-pc-section":"movebottombutton"}),{icon:a.withCtx((function(){return[a.renderSlot(e.$slots,"movebottomicon",{},(function(){return[a.createVNode(u,a.mergeProps(e.ptm("moveBottomButton").icon,{"data-pc-section":"movebottomicon"}),null,16)]}))]})),_:3},16,["onClick","aria-label","disabled","pt","unstyled"]),a.renderSlot(e.$slots,"controlsend")],16),a.createElementVNode("div",a.mergeProps({class:e.cx("container")},e.ptm("container")),[e.$slots.header?(a.openBlock(),a.createElementBlock("div",a.mergeProps({key:0,class:e.cx("header")},e.ptm("header")),[a.renderSlot(e.$slots,"header")],16)):a.createCommentVNode("",!0),a.createVNode(a.TransitionGroup,a.mergeProps({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},_(_(_({},e.listProps),e.ptm("list")),e.ptm("transition"))),{default:a.withCtx((function(){return[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(e.modelValue,(function(n,i){return a.withDirectives((a.openBlock(),a.createElementBlock("li",a.mergeProps({key:r.getItemKey(n,i),id:o.id+"_"+i,role:"option",class:e.cx("item",{item:n,id:"".concat(o.id,"_").concat(i)}),onClick:function(e){return r.onItemClick(e,n,i)},onTouchend:t[0]||(t[0]=function(){return r.onItemTouchEnd&&r.onItemTouchEnd.apply(r,arguments)}),"aria-selected":r.isSelected(n),onMousedown:function(e){return r.onOptionMouseDown(i)}},r.getPTOptions(n,"item",i),{"data-p-highlight":r.isSelected(n),"data-p-focused":"".concat(o.id,"_").concat(i)===r.focusedOptionId}),[a.renderSlot(e.$slots,"item",{item:n,index:i})],16,$)),[[p]])})),128))]})),_:3},16,["id","class","style","tabindex","aria-activedescendant","aria-label","aria-labelledby","onFocus","onBlur","onKeydown"])],16)],16)},O}(primevue.button,primevue.icons.angledoubledown,primevue.icons.angledoubleup,primevue.icons.angledown,primevue.icons.angleup,primevue.ripple,primevue.utils,primevue.basecomponent,primevue.orderlist.style,Vue);