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