text: import e,{Component as t}from"react";import{Button as r}from"primereact/button";import{ObjectUtils as n,DomHandler as o,classNames as i}from"primereact/utils";import{Ripple as s}from"primereact/ripple";function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function l(e){if(Array.isArray(e))return a(e)}function p(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function u(e,t){if(e){if("string"==typeof e)return a(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,t):void 0}}function c(){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 d(e){return l(e)||p(e)||u(e)||c()}function f(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function v(e,t,r){return t&&h(e.prototype,t),r&&h(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function m(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function g(e,t){return g=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},g(e,t)}function y(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&g(e,t)}function b(e){return b="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},b(e)}function I(e,t){if(t&&("object"===b(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return m(e)}function E(e){return E=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},E(e)}function D(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var k=function(o){y(l,t);var i,s,a=(i=l,s=D(),function(){var e,t=E(i);if(s){var r=E(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return I(this,e)});function l(){var e;return f(this,l),(e=a.call(this)).moveUp=e.moveUp.bind(m(e)),e.moveTop=e.moveTop.bind(m(e)),e.moveDown=e.moveDown.bind(m(e)),e.moveBottom=e.moveBottom.bind(m(e)),e}return v(l,[{key:"moveUp",value:function(e){if(this.props.selection){for(var t=d(this.props.value),r=0;r<this.props.selection.length;r++){var o=n.findIndexInList(this.props.selection[r],t,this.props.dataKey);if(0===o)break;var i=t[o-1];t[o-1]=t[o],t[o]=i}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:t,direction:"up"})}}},{key:"moveTop",value:function(e){if(this.props.selection){for(var t=d(this.props.value),r=0;r<this.props.selection.length;r++){var o=n.findIndexInList(this.props.selection[r],t,this.props.dataKey);if(0===o)break;var i=t.splice(o,1)[0];t.unshift(i)}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:t,direction:"top"})}}},{key:"moveDown",value:function(e){if(this.props.selection){for(var t=d(this.props.value),r=this.props.selection.length-1;r>=0;r--){var o=n.findIndexInList(this.props.selection[r],t,this.props.dataKey);if(o===t.length-1)break;var i=t[o+1];t[o+1]=t[o],t[o]=i}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:t,direction:"down"})}}},{key:"moveBottom",value:function(e){if(this.props.selection){for(var t=d(this.props.value),r=this.props.selection.length-1;r>=0;r--){var o=n.findIndexInList(this.props.selection[r],t,this.props.dataKey);if(o===t.length-1)break;var i=t.splice(o,1)[0];t.push(i)}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:t,direction:"bottom"})}}},{key:"render",value:function(){return e.createElement("div",{className:"p-orderlist-controls"},e.createElement(r,{type:"button",icon:"pi pi-angle-up",onClick:this.moveUp}),e.createElement(r,{type:"button",icon:"pi pi-angle-double-up",onClick:this.moveTop}),e.createElement(r,{type:"button",icon:"pi pi-angle-down",onClick:this.moveDown}),e.createElement(r,{type:"button",icon:"pi pi-angle-double-down",onClick:this.moveBottom}))}}]),l}();function x(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var w=function(r){y(u,t);var a,l,p=(a=u,l=x(),function(){var e,t=E(a);if(l){var r=E(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return I(this,e)});function u(e){var t;return f(this,u),(t=p.call(this,e)).onDragEnd=t.onDragEnd.bind(m(t)),t.onDragLeave=t.onDragLeave.bind(m(t)),t.onDrop=t.onDrop.bind(m(t)),t.onListMouseMove=t.onListMouseMove.bind(m(t)),t}return v(u,[{key:"isSelected",value:function(e){return-1!==n.findIndexInList(e,this.props.selection,this.props.dataKey)}},{key:"onDragStart",value:function(e,t){this.dragging=!0,this.draggedItemIndex=t,this.props.dragdropScope&&e.dataTransfer.setData("text","orderlist")}},{key:"onDragOver",value:function(e,t){this.draggedItemIndex!==t&&this.draggedItemIndex+1!==t&&(this.dragOverItemIndex=t,o.addClass(e.target,"p-orderlist-droppoint-highlight"),e.preventDefault())}},{key:"onDragLeave",value:function(e){this.dragOverItemIndex=null,o.removeClass(e.target,"p-orderlist-droppoint-highlight")}},{key:"onDrop",value:function(e){var t=this.draggedItemIndex>this.dragOverItemIndex?this.dragOverItemIndex:0===this.dragOverItemIndex?0:this.dragOverItemIndex-1,r=d(this.props.value);n.reorderArray(r,this.draggedItemIndex,t),this.dragOverItemIndex=null,o.removeClass(e.target,"p-orderlist-droppoint-highlight"),this.props.onChange&&this.props.onChange({originalEvent:e,value:r})}},{key:"onDragEnd",value:function(e){this.dragging=!1}},{key:"onListMouseMove",value:function(e){if(this.dragging){var t=this.listElement.getBoundingClientRect().top+o.getWindowScrollTop(),r=t+this.listElement.clientHeight-e.pageY,n=e.pageY-t;r<25&&r>0?this.listElement.scrollTop+=15:n<25&&n>0&&(this.listElement.scrollTop-=15)}}},{key:"renderDropPoint",value:function(t,r){var n=this;return e.createElement("li",{key:r,className:"p-orderlist-droppoint",onDragOver:function(e){return n.onDragOver(e,t+1)},onDragLeave:this.onDragLeave,onDrop:this.onDrop})}},{key:"render",value:function(){var t=this,r=null,n=null;return this.props.header&&(r=e.createElement("div",{className:"p-orderlist-header"},this.props.header)),this.props.value&&(n=this.props.value.map((function(r,n){var o=t.props.itemTemplate?t.props.itemTemplate(r):r,a=i("p-orderlist-item",{"p-highlight":t.isSelected(r)},t.props.className),l=JSON.stringify(r);if(t.props.dragdrop){var p=[t.renderDropPoint(n,l+"_droppoint"),e.createElement("li",{key:l,className:a,onClick:function(e){return t.props.onItemClick({originalEvent:e,value:r,index:n})},onKeyDown:function(e){return t.props.onItemKeyDown({originalEvent:e,value:r,index:n})},role:"option","aria-selected":t.isSelected(r),draggable:"true",onDragStart:function(e){return t.onDragStart(e,n)},onDragEnd:t.onDragEnd,tabIndex:t.props.tabIndex},o,e.createElement(s,null))];return n===t.props.value.length-1&&p.push(t.renderDropPoint(r,n,l+"_droppoint_end")),p}return e.createElement("li",{key:JSON.stringify(r),className:a,role:"option","aria-selected":t.isSelected(r),onClick:function(e){return t.props.onItemClick({originalEvent:e,value:r,index:n})},onKeyDown:function(e){return t.props.onItemKeyDown({originalEvent:e,value:r,index:n})},tabIndex:t.props.tabIndex},o)}))),e.createElement("div",{className:"p-orderlist-list-container"},r,e.createElement("ul",{ref:function(e){return t.listElement=e},className:"p-orderlist-list",style:this.props.listStyle,onDragOver:this.onListMouseMove,role:"listbox","aria-multiselectable":!0},n))}}]),u}();function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var O,R,C,L=function(r){y(p,t);var s,a,l=(s=p,a=S(),function(){var e,t=E(s);if(a){var r=E(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return I(this,e)});function p(e){var t;return f(this,p),(t=l.call(this,e)).state={selection:[]},t.onItemClick=t.onItemClick.bind(m(t)),t.onItemKeyDown=t.onItemKeyDown.bind(m(t)),t.onReorder=t.onReorder.bind(m(t)),t}return v(p,[{key:"onItemClick",value:function(e){var t,r=e.originalEvent.metaKey||e.originalEvent.ctrlKey,o=n.findIndexInList(e.value,this.state.selection,this.props.dataKey);t=-1!==o?r?this.state.selection.filter((function(e,t){return t!==o})):[e.value]:r?[].concat(d(this.state.selection),[e.value]):[e.value],this.setState({selection:t})}},{key:"onItemKeyDown",value:function(e){var t=e.originalEvent.currentTarget;switch(e.originalEvent.which){case 40:var r=this.findNextItem(t);r&&r.focus(),e.originalEvent.preventDefault();break;case 38:var n=this.findPrevItem(t);n&&n.focus(),e.originalEvent.preventDefault();break;case 13:this.onItemClick(e),e.originalEvent.preventDefault()}}},{key:"findNextItem",value:function(e){var t=e.nextElementSibling;return t?o.hasClass(t,"p-orderlist-item")?t:this.findNextItem(t):null}},{key:"findPrevItem",value:function(e){var t=e.previousElementSibling;return t?o.hasClass(t,"p-orderlist-item")?t:this.findPrevItem(t):null}},{key:"onReorder",value:function(e){this.props.onChange&&this.props.onChange({event:e.originalEvent,value:e.value}),this.reorderDirection=e.direction}},{key:"componentDidUpdate",value:function(){this.reorderDirection&&(this.updateListScroll(),this.reorderDirection=null)}},{key:"updateListScroll",value:function(){var e=o.find(this.subList.listElement,".p-orderlist-item.p-highlight");if(e&&e.length)switch(this.reorderDirection){case"up":o.scrollInView(this.subList.listElement,e[0]);break;case"top":this.subList.listElement.scrollTop=0;break;case"down":o.scrollInView(this.subList.listElement,e[e.length-1]);break;case"bottom":this.subList.listElement.scrollTop=this.subList.listElement.scrollHeight}}},{key:"render",value:function(){var t=this,r=i("p-orderlist p-component",this.props.className);return e.createElement("div",{ref:function(e){return t.element=e},id:this.props.id,className:r,style:this.props.style},e.createElement(k,{value:this.props.value,selection:this.state.selection,onReorder:this.onReorder,dataKey:this.props.dataKey}),e.createElement(w,{ref:function(e){return t.subList=e},value:this.props.value,selection:this.state.selection,onItemClick:this.onItemClick,onItemKeyDown:this.onItemKeyDown,itemTemplate:this.props.itemTemplate,header:this.props.header,listStyle:this.props.listStyle,dataKey:this.props.dataKey,dragdrop:this.props.dragdrop,onDragStart:this.onDragStart,onDragEnter:this.onDragEnter,onDragEnd:this.onDragEnd,onDragLeave:this.onDragEnter,onDrop:this.onDrop,onChange:this.props.onChange,tabIndex:this.props.tabIndex}))}}]),p}();C={id:null,value:null,header:null,style:null,className:null,listStyle:null,dragdrop:!1,tabIndex:0,dataKey:null,onChange:null,itemTemplate:null},(R="defaultProps")in(O=L)?Object.defineProperty(O,R,{value:C,enumerable:!0,configurable:!0,writable:!0}):O[R]=C;export{L as OrderList};
  