katoikia-app/web-ui/web-react/node_modules/primereact/picklist/picklist.esm.min.js

2 lines
17 KiB
JavaScript

import e,{Component as t}from"react";import{classNames as o,ObjectUtils as r,DomHandler as n}from"primereact/utils";import{Ripple as i}from"primereact/ripple";import{Button as s}from"primereact/button";function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function c(e,t,o){return t&&a(e.prototype,t),o&&a(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){return u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},u(e,t)}function h(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&&u(e,t)}function f(e){return f="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},f(e)}function v(e,t){if(t&&("object"===f(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return p(e)}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},d(e)}function m(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function y(){return y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},y.apply(this,arguments)}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var o=0,r=new Array(t);o<t;o++)r[o]=e[o];return r}function b(e){if(Array.isArray(e))return g(e)}function S(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function k(e,t){if(e){if("string"==typeof e)return g(e,t);var o=Object.prototype.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?g(e,t):void 0}}function E(){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){return b(e)||S(e)||k(e)||E()}function C(){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){h(u,t);var n,s,a=(n=u,s=C(),function(){var e,t=d(n);if(s){var o=d(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return v(this,e)});function u(e){var t;return l(this,u),(t=a.call(this,e)).onClick=t.onClick.bind(p(t)),t.onKeyDown=t.onKeyDown.bind(p(t)),t}return c(u,[{key:"onClick",value:function(e){this.props.onClick&&this.props.onClick({originalEvent:e,value:this.props.value})}},{key:"onKeyDown",value:function(e){this.props.onKeyDown&&this.props.onKeyDown({originalEvent:e,value:this.props.value})}},{key:"render",value:function(){var t=this.props.template?this.props.template(this.props.value):this.props.value,r=o("p-picklist-item",{"p-highlight":this.props.selected},this.props.className);return e.createElement("li",{className:r,onClick:this.onClick,onKeyDown:this.onKeyDown,tabIndex:this.props.tabIndex,role:"option","aria-selected":this.props.selected},t,e.createElement(i,null))}}]),u}();function R(){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}}m(w,"defaultProps",{value:null,className:null,template:null,selected:!1,tabIndex:null,onClick:null,onKeyDown:null});var I=function(i){h(f,t);var s,a,u=(s=f,a=R(),function(){var e,t=d(s);if(a){var o=d(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return v(this,e)});function f(e){var t;return l(this,f),(t=u.call(this,e)).onItemClick=t.onItemClick.bind(p(t)),t.onItemKeyDown=t.onItemKeyDown.bind(p(t)),t}return c(f,[{key:"onItemClick",value:function(e){var t=e.originalEvent,o=e.value,n=T(this.props.selection),i=r.findIndexInList(o,n,this.props.dataKey),s=-1!==i;if(this.props.metaKeySelection){var l=t.metaKey||t.ctrlKey;s&&l?n.splice(i,1):(l||(n.length=0),n.push(o))}else s?n.splice(i,1):n.push(o);this.props.onSelectionChange&&this.props.onSelectionChange({event:t,value:n})}},{key:"onItemKeyDown",value:function(e){var t=e.originalEvent.currentTarget;switch(e.originalEvent.which){case 40:var o=this.findNextItem(t);o&&o.focus(),e.originalEvent.preventDefault();break;case 38:var r=this.findPrevItem(t);r&&r.focus(),e.originalEvent.preventDefault();break;case 13:this.onItemClick(e),e.originalEvent.preventDefault()}}},{key:"findNextItem",value:function(e){var t=e.nextElementSibling;return t?n.hasClass(t,"p-picklist-item")?t:this.findNextItem(t):null}},{key:"findPrevItem",value:function(e){var t=e.previousElementSibling;return t?n.hasClass(t,"p-picklist-item")?t:this.findPrevItem(t):null}},{key:"isSelected",value:function(e){return-1!==r.findIndexInList(e,this.props.selection,this.props.dataKey)}},{key:"render",value:function(){var t=this,n=null,i=null,s=o("p-picklist-list-wrapper",this.props.className),l=o("p-picklist-list",this.props.listClassName);return this.props.header&&(n=e.createElement("div",{className:"p-picklist-header"},r.getJSXElement(this.props.header,this.props))),this.props.list&&(i=this.props.list.map((function(o,r){return e.createElement(w,{key:JSON.stringify(o),value:o,template:t.props.itemTemplate,selected:t.isSelected(o),onClick:t.onItemClick,onKeyDown:t.onItemKeyDown,tabIndex:t.props.tabIndex})}))),e.createElement("div",{ref:this.props.forwardRef,className:s},n,e.createElement("ul",{className:l,style:this.props.style,role:"listbox","aria-multiselectable":!0},i))}}]),f}(),K=e.forwardRef((function(t,o){return e.createElement(I,y({forwardRef:o},t))}));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 N=function(n){h(f,t);var i,a,u=(i=f,a=x(),function(){var e,t=d(i);if(a){var o=d(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return v(this,e)});function f(e){var t;return l(this,f),(t=u.call(this,e)).moveUp=t.moveUp.bind(p(t)),t.moveTop=t.moveTop.bind(p(t)),t.moveDown=t.moveDown.bind(p(t)),t.moveBottom=t.moveBottom.bind(p(t)),t}return c(f,[{key:"moveUp",value:function(e){var t=this.props.selection;if(t&&t.length){for(var o=T(this.props.list),n=0;n<t.length;n++){var i=r.findIndexInList(t[n],o,this.props.dataKey);if(0===i)break;var s=o[i-1];o[i-1]=o[i],o[i]=s}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:o,direction:"up"})}}},{key:"moveTop",value:function(e){var t=this.props.selection;if(t&&t.length){for(var o=T(this.props.list),n=0;n<t.length;n++){var i=r.findIndexInList(t[n],o,this.props.dataKey);if(0===i)break;var s=o.splice(i,1)[0];o.unshift(s)}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:o,direction:"top"})}}},{key:"moveDown",value:function(e){var t=this.props.selection;if(t&&t.length){for(var o=T(this.props.list),n=t.length-1;n>=0;n--){var i=r.findIndexInList(t[n],o,this.props.dataKey);if(i===o.length-1)break;var s=o[i+1];o[i+1]=o[i],o[i]=s}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:o,direction:"down"}),this.movedDown=!0}}},{key:"moveBottom",value:function(e){var t=this.props.selection;if(t&&t.length){for(var o=T(this.props.list),n=t.length-1;n>=0;n--){var i=r.findIndexInList(t[n],o,this.props.dataKey);if(i===o.length-1)break;var s=o.splice(i,1)[0];o.push(s)}this.props.onReorder&&this.props.onReorder({originalEvent:e,value:o,direction:"bottom"})}}},{key:"render",value:function(){var t=!this.props.selection.length,r=o("p-picklist-buttons",this.props.className);return e.createElement("div",{className:r},e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-up",onClick:this.moveUp}),e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-double-up",onClick:this.moveTop}),e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-down",onClick:this.moveDown}),e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-double-down",onClick:this.moveBottom}))}}]),f}();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 L=function(n){h(f,t);var i,a,u=(i=f,a=D(),function(){var e,t=d(i);if(a){var o=d(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return v(this,e)});function f(e){var t;return l(this,f),(t=u.call(this,e)).moveRight=t.moveRight.bind(p(t)),t.moveAllRight=t.moveAllRight.bind(p(t)),t.moveLeft=t.moveLeft.bind(p(t)),t.moveAllLeft=t.moveAllLeft.bind(p(t)),t}return c(f,[{key:"moveRight",value:function(e){var t=this.props.sourceSelection;if(r.isNotEmpty(t)){for(var o=T(this.props.target),n=T(this.props.source),i=0;i<t.length;i++){var s=t[i];-1===r.findIndexInList(s,o,this.props.dataKey)&&o.push(n.splice(r.findIndexInList(s,n,this.props.dataKey),1)[0])}this.props.onTransfer&&this.props.onTransfer({originalEvent:e,source:n,target:o,direction:"toTarget"})}}},{key:"moveAllRight",value:function(e){if(this.props.source){var t=[].concat(T(this.props.target),T(this.props.source));this.props.onTransfer&&this.props.onTransfer({originalEvent:e,source:[],target:t,direction:"allToTarget"})}}},{key:"moveLeft",value:function(e){var t=this.props.targetSelection;if(r.isNotEmpty(t)){for(var o=T(this.props.target),n=T(this.props.source),i=0;i<t.length;i++){var s=t[i];-1===r.findIndexInList(s,n,this.props.dataKey)&&n.push(o.splice(r.findIndexInList(s,o,this.props.dataKey),1)[0])}this.props.onTransfer&&this.props.onTransfer({originalEvent:e,source:n,target:o,direction:"toSource"})}}},{key:"moveAllLeft",value:function(e){if(this.props.source){var t=[].concat(T(this.props.source),T(this.props.target));this.props.onTransfer&&this.props.onTransfer({originalEvent:e,source:t,target:[],direction:"allToSource"})}}},{key:"render",value:function(){var t=r.isEmpty(this.props.sourceSelection),n=r.isEmpty(this.props.targetSelection),i=r.isEmpty(this.props.source),l=r.isEmpty(this.props.target),a=o("p-picklist-buttons p-picklist-transfer-buttons",this.props.className);return e.createElement("div",{className:a},e.createElement(s,{disabled:t,type:"button",icon:"pi pi-angle-right",onClick:this.moveRight}),e.createElement(s,{disabled:i,type:"button",icon:"pi pi-angle-double-right",onClick:this.moveAllRight}),e.createElement(s,{disabled:n,type:"button",icon:"pi pi-angle-left",onClick:this.moveLeft}),e.createElement(s,{disabled:l,type:"button",icon:"pi pi-angle-double-left",onClick:this.moveAllLeft}))}}]),f}();function O(){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 A=function(i){h(f,t);var s,a,u=(s=f,a=O(),function(){var e,t=d(s);if(a){var o=d(this).constructor;e=Reflect.construct(t,arguments,o)}else e=t.apply(this,arguments);return v(this,e)});function f(e){var t;return l(this,f),(t=u.call(this,e)).state={},t.props.onSourceSelectionChange||(t.state.sourceSelection=[]),t.props.onTargetSelectionChange||(t.state.targetSelection=[]),t.onSourceReorder=t.onSourceReorder.bind(p(t)),t.onTargetReorder=t.onTargetReorder.bind(p(t)),t.onTransfer=t.onTransfer.bind(p(t)),t}return c(f,[{key:"getSourceSelection",value:function(){return this.props.onSourceSelectionChange?this.props.sourceSelection:this.state.sourceSelection}},{key:"getTargetSelection",value:function(){return this.props.onTargetSelectionChange?this.props.targetSelection:this.state.targetSelection}},{key:"onSourceReorder",value:function(e){this.handleChange(e,e.value,this.props.target),this.reorderedListElement=this.sourceListElement,this.reorderDirection=e.direction}},{key:"onTargetReorder",value:function(e){this.handleChange(e,this.props.source,e.value),this.reorderedListElement=this.targetListElement,this.reorderDirection=e.direction}},{key:"handleScrollPosition",value:function(e,t){if(e){var o=n.findSingle(e,".p-picklist-list");switch(t){case"up":this.scrollInView(o,-1);break;case"top":o.scrollTop=0;break;case"down":this.scrollInView(o,1);break;case"bottom":o.scrollTop=o.scrollHeight}}}},{key:"handleChange",value:function(e,t,o){this.props.onChange&&this.props.onChange({originalEvent:e.originalEvent,source:t,target:o})}},{key:"onTransfer",value:function(e){var t=e.originalEvent,o=e.source,r=e.target;switch(e.direction){case"toTarget":this.props.onMoveToTarget&&this.props.onMoveToTarget({originalEvent:t,value:this.getSourceSelection()});break;case"allToTarget":this.props.onMoveAllToTarget&&this.props.onMoveAllToTarget({originalEvent:t,value:this.props.source});break;case"toSource":this.props.onMoveToSource&&this.props.onMoveToSource({originalEvent:t,value:this.getTargetSelection()});break;case"allToSource":this.props.onMoveAllToSource&&this.props.onMoveAllToSource({originalEvent:t,value:this.props.target})}this.onSelectionChange({originalEvent:t,value:[]},"sourceSelection",this.props.onSourceSelectionChange),this.onSelectionChange({originalEvent:t,value:[]},"targetSelection",this.props.onTargetSelectionChange),this.handleChange(e,o,r)}},{key:"scrollInView",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,o=e.getElementsByClassName("p-highlight");r.isNotEmpty(o)&&n.scrollInView(e,-1===t?o[0]:o[o.length-1])}},{key:"onSelectionChange",value:function(e,t,o){o?o(e):this.setState(m({},t,e.value)),r.isNotEmpty(this.state.sourceSelection)&&"targetSelection"===t?this.setState({sourceSelection:[]}):r.isNotEmpty(this.state.targetSelection)&&"sourceSelection"===t&&this.setState({targetSelection:[]})}},{key:"componentDidUpdate",value:function(){this.reorderedListElement&&(this.handleScrollPosition(this.reorderedListElement,this.reorderDirection),this.reorderedListElement=null,this.reorderDirection=null)}},{key:"render",value:function(){var t=this,r=o("p-picklist p-component",this.props.className),n=this.getSourceSelection(),i=this.getTargetSelection();return e.createElement("div",{id:this.props.id,className:r,style:this.props.style},this.props.showSourceControls&&e.createElement(N,{list:this.props.source,selection:n,onReorder:this.onSourceReorder,className:"p-picklist-source-controls",dataKey:this.props.dataKey}),e.createElement(K,{ref:function(e){return t.sourceListElement=e},list:this.props.source,selection:n,onSelectionChange:function(e){return t.onSelectionChange(e,"sourceSelection",t.props.onSourceSelectionChange)},itemTemplate:this.props.itemTemplate,header:this.props.sourceHeader,style:this.props.sourceStyle,className:"p-picklist-source-wrapper",listClassName:"p-picklist-source",metaKeySelection:this.props.metaKeySelection,tabIndex:this.props.tabIndex,dataKey:this.props.dataKey}),e.createElement(L,{onTransfer:this.onTransfer,source:this.props.source,target:this.props.target,sourceSelection:n,targetSelection:i,dataKey:this.props.dataKey}),e.createElement(K,{ref:function(e){return t.targetListElement=e},list:this.props.target,selection:i,onSelectionChange:function(e){return t.onSelectionChange(e,"targetSelection",t.props.onTargetSelectionChange)},itemTemplate:this.props.itemTemplate,header:this.props.targetHeader,style:this.props.targetStyle,className:"p-picklist-target-wrapper",listClassName:"p-picklist-target",metaKeySelection:this.props.metaKeySelection,tabIndex:this.props.tabIndex,dataKey:this.props.dataKey}),this.props.showTargetControls&&e.createElement(N,{list:this.props.target,selection:i,onReorder:this.onTargetReorder,className:"p-picklist-target-controls",dataKey:this.props.dataKey}))}}]),f}();m(A,"defaultProps",{id:null,source:null,target:null,sourceHeader:null,targetHeader:null,style:null,className:null,sourceStyle:null,targetStyle:null,sourceSelection:null,targetSelection:null,showSourceControls:!0,showTargetControls:!0,metaKeySelection:!0,tabIndex:0,dataKey:null,itemTemplate:null,onChange:null,onMoveToSource:null,onMoveAllToSource:null,onMoveToTarget:null,onMoveAllToTarget:null,onSourceSelectionChange:null,onTargetSelectionChange:null});export{A as PickList};