2 lines
38 KiB
JavaScript
2 lines
38 KiB
JavaScript
this.primereact=this.primereact||{},this.primereact.multiselect=function(e,t,n,i,r,o,l,s,p,a,u){"use strict";function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var h=c(t),d=c(a);function f(){return f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},f.apply(this,arguments)}function y(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}function v(e){if(Array.isArray(e))return y(e)}function m(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function b(e,t){if(e){if("string"==typeof e)return y(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)?y(e,t):void 0}}function O(){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){return v(e)||m(e)||b(e)||O()}function k(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function C(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function S(e,t,n){return t&&C(e.prototype,t),n&&C(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function E(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function w(e,t){return w=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},w(e,t)}function L(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&&w(e,t)}function D(e){return D="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},D(e)}function x(e,t){if(t&&("object"===D(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return E(e)}function I(e){return I=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},I(e)}function R(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function F(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 j(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?F(Object(n),!0).forEach((function(t){R(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):F(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function P(){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(e){L(s,e);var r,o,l=(r=s,o=P(),function(){var e,t=I(r);if(o){var n=I(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return x(this,e)});function s(e){var n;return k(this,s),(n=l.call(this,e)).state={focused:!1},n.onClick=n.onClick.bind(E(n)),n.onFocus=n.onFocus.bind(E(n)),n.onBlur=n.onBlur.bind(E(n)),n.onKeyDown=n.onKeyDown.bind(E(n)),n.inputRef=t.createRef(n.props.inputRef),n}return S(s,[{key:"onClick",value:function(e){if(!this.props.disabled&&!this.props.readOnly&&this.props.onChange){var t=this.isChecked()?this.props.falseValue:this.props.trueValue;this.props.onChange({originalEvent:e,value:this.props.value,checked:t,stopPropagation:function(){},preventDefault:function(){},target:{type:"checkbox",name:this.props.name,id:this.props.id,value:this.props.value,checked:t}}),this.inputRef.current.checked=!this.isChecked(),this.inputRef.current.focus(),e.preventDefault()}}},{key:"updateInputRef",value:function(){var e=this.props.inputRef;e&&("function"==typeof e?e(this.inputRef.current):e.current=this.inputRef.current)}},{key:"componentDidMount",value:function(){this.updateInputRef(),this.props.tooltip&&this.renderTooltip()}},{key:"componentWillUnmount",value:function(){this.tooltip&&(this.tooltip.destroy(),this.tooltip=null)}},{key:"componentDidUpdate",value:function(e){this.inputRef.current.checked=this.isChecked(),e.tooltip===this.props.tooltip&&e.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(j({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip())}},{key:"onFocus",value:function(){this.setState({focused:!0})}},{key:"onBlur",value:function(){this.setState({focused:!1})}},{key:"onKeyDown",value:function(e){"Enter"===e.key&&(this.onClick(e),e.preventDefault())}},{key:"renderTooltip",value:function(){this.tooltip=i.tip({target:this.element,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"isChecked",value:function(){return this.props.checked===this.props.trueValue}},{key:"render",value:function(){var e=this,t=this.isChecked(),i=n.classNames("p-checkbox p-component",{"p-checkbox-checked":t,"p-checkbox-disabled":this.props.disabled,"p-checkbox-focused":this.state.focused},this.props.className),r=n.classNames("p-checkbox-box",{"p-highlight":t,"p-disabled":this.props.disabled,"p-focus":this.state.focused}),o=t&&this.props.icon;return h.default.createElement("div",{ref:function(t){return e.element=t},id:this.props.id,className:i,style:this.props.style,onClick:this.onClick,onContextMenu:this.props.onContextMenu,onMouseDown:this.props.onMouseDown},h.default.createElement("div",{className:"p-hidden-accessible"},h.default.createElement("input",{ref:this.inputRef,type:"checkbox","aria-labelledby":this.props.ariaLabelledBy,id:this.props.inputId,name:this.props.name,tabIndex:this.props.tabIndex,defaultChecked:t,onKeyDown:this.onKeyDown,onFocus:this.onFocus,onBlur:this.onBlur,disabled:this.props.disabled,readOnly:this.props.readOnly,required:this.props.required})),h.default.createElement("div",{className:r,ref:function(t){return e.box=t},role:"checkbox","aria-checked":t},n.IconUtils.getJSXIcon(o,{className:"p-checkbox-icon p-c"},{props:this.props,checked:t})))}}]),s}(t.Component);function V(){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}}R(N,"defaultProps",{id:null,inputRef:null,inputId:null,value:null,name:null,checked:!1,trueValue:!0,falseValue:!1,style:null,className:null,disabled:!1,required:!1,readOnly:!1,tabIndex:null,icon:"pi pi-check",tooltip:null,tooltipOptions:null,ariaLabelledBy:null,onChange:null,onMouseDown:null,onContextMenu:null});var K=function(e){L(o,e);var t,i,r=(t=o,i=V(),function(){var e,n=I(t);if(i){var r=I(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return x(this,e)});function o(e){var t;return k(this,o),(t=r.call(this,e)).onFilter=t.onFilter.bind(E(t)),t.onSelectAll=t.onSelectAll.bind(E(t)),t}return S(o,[{key:"onFilter",value:function(e){this.props.onFilter&&this.props.onFilter({originalEvent:e,query:e.target.value})}},{key:"onSelectAll",value:function(e){this.props.onSelectAll&&this.props.onSelectAll({originalEvent:e,checked:this.props.selectAll})}},{key:"renderFilterElement",value:function(){return this.props.filter?h.default.createElement("div",{className:"p-multiselect-filter-container"},h.default.createElement(l.InputText,{type:"text",role:"textbox",value:this.props.filterValue,onChange:this.onFilter,className:"p-multiselect-filter",placeholder:this.props.filterPlaceholder}),h.default.createElement("span",{className:"p-multiselect-filter-icon pi pi-search"})):null}},{key:"render",value:function(){var e=this.renderFilterElement(),t=this.props.showSelectAll&&h.default.createElement(N,{checked:this.props.selectAll,onChange:this.onSelectAll,role:"checkbox","aria-checked":this.props.selectAll}),i=h.default.createElement("button",{type:"button",className:"p-multiselect-close p-link",onClick:this.props.onClose},h.default.createElement("span",{className:"p-multiselect-close-icon pi pi-times"}),h.default.createElement(s.Ripple,null)),r=h.default.createElement("div",{className:"p-multiselect-header"},t,e,i);return this.props.template?n.ObjectUtils.getJSXElement(this.props.template,{className:"p-multiselect-header",checkboxElement:t,checked:this.props.selectAll,onChange:this.onSelectAll,filterElement:e,closeElement:i,closeElementClassName:"p-multiselect-close p-link",closeIconClassName:"p-multiselect-close-icon pi pi-times",onCloseClick:this.props.onClose,element:r,props:this.props}):r}}]),o}(t.Component);function A(){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 T=function(e){L(o,e);var t,i,r=(t=o,i=A(),function(){var e,n=I(t);if(i){var r=I(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return x(this,e)});function o(e){var t;return k(this,o),(t=r.call(this,e)).onClick=t.onClick.bind(E(t)),t.onKeyDown=t.onKeyDown.bind(E(t)),t}return S(o,[{key:"onClick",value:function(e){this.props.onClick&&this.props.onClick({originalEvent:e,option:this.props.option}),e.preventDefault()}},{key:"onKeyDown",value:function(e){this.props.onKeyDown&&this.props.onKeyDown({originalEvent:e,option:this.props.option})}},{key:"render",value:function(){var e=n.classNames("p-multiselect-item",{"p-highlight":this.props.selected,"p-disabled":this.props.disabled},this.props.option.className),t=n.classNames("p-checkbox-box",{"p-highlight":this.props.selected}),i=n.classNames("p-checkbox-icon p-c",{"pi pi-check":this.props.selected}),r=this.props.template?n.ObjectUtils.getJSXElement(this.props.template,this.props.option):this.props.label;return h.default.createElement("li",{className:e,onClick:this.onClick,tabIndex:this.props.disabled?null:this.props.tabIndex||0,onKeyDown:this.onKeyDown,role:"option","aria-selected":this.props.selected},h.default.createElement("div",{className:"p-checkbox p-component"},h.default.createElement("div",{className:t},h.default.createElement("span",{className:i}))),h.default.createElement("span",null,r),h.default.createElement(s.Ripple,null))}}]),o}(t.Component);function G(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 B(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?G(Object(n),!0).forEach((function(t){R(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):G(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function U(){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}}R(T,"defaultProps",{option:null,label:null,selected:!1,disabled:!1,tabIndex:null,template:null,onClick:null,onKeyDown:null});var H=function(e){L(s,e);var t,i,l=(t=s,i=U(),function(){var e,n=I(t);if(i){var r=I(this).constructor;e=Reflect.construct(n,arguments,r)}else e=n.apply(this,arguments);return x(this,e)});function s(e){var t;return k(this,s),(t=l.call(this,e)).onEnter=t.onEnter.bind(E(t)),t.onFilterInputChange=t.onFilterInputChange.bind(E(t)),t}return S(s,[{key:"onEnter",value:function(){var e=this;this.props.onEnter((function(){if(e.virtualScrollerRef){var t=e.props.getSelectedOptionIndex();-1!==t&&e.virtualScrollerRef.scrollToIndex(t)}}))}},{key:"onFilterInputChange",value:function(e){this.virtualScrollerRef&&this.virtualScrollerRef.scrollToIndex(0),this.props.onFilterInputChange&&this.props.onFilterInputChange(e)}},{key:"isEmptyFilter",value:function(){return!(this.props.visibleOptions&&this.props.visibleOptions.length)&&this.props.hasFilter()}},{key:"renderHeader",value:function(){return h.default.createElement(K,{filter:this.props.filter,filterValue:this.props.filterValue,onFilter:this.onFilterInputChange,filterPlaceholder:this.props.filterPlaceholder,onClose:this.props.onCloseClick,showSelectAll:this.props.showSelectAll,selectAll:this.props.isAllSelected(),onSelectAll:this.props.onSelectAll,template:this.props.panelHeaderTemplate})}},{key:"renderFooter",value:function(){if(this.props.panelFooterTemplate){var e=n.ObjectUtils.getJSXElement(this.props.panelFooterTemplate,this.props,this.props.onOverlayHide);return h.default.createElement("div",{className:"p-multiselect-footer"},e)}return null}},{key:"renderGroupChildren",value:function(e){var t=this;return this.props.getOptionGroupChildren(e).map((function(e,n){var i=t.props.getOptionLabel(e),r=n+"_"+t.props.getOptionRenderKey(e),o=t.props.isOptionDisabled(e),l=o?null:t.props.tabIndex||0;return h.default.createElement(T,{key:r,label:i,option:e,template:t.props.itemTemplate,selected:t.props.isSelected(e),onClick:t.props.onOptionSelect,onKeyDown:t.props.onOptionKeyDown,tabIndex:l,disabled:o})}))}},{key:"renderEmptyFilter",value:function(){var e=n.ObjectUtils.getJSXElement(this.props.emptyFilterMessage,this.props)||a.localeOption("emptyFilterMessage");return h.default.createElement("li",{className:"p-multiselect-empty-message"},e)}},{key:"renderItem",value:function(e,t){if(this.props.optionGroupLabel){var i=this.props.optionGroupTemplate?n.ObjectUtils.getJSXElement(this.props.optionGroupTemplate,e,t):this.props.getOptionGroupLabel(e),r=this.renderGroupChildren(e),o=t+"_"+this.props.getOptionGroupRenderKey(e);return h.default.createElement(h.default.Fragment,{key:o},h.default.createElement("li",{className:"p-multiselect-item-group"},i),r)}var l=this.props.getOptionLabel(e),s=t+"_"+this.props.getOptionRenderKey(e),p=this.props.isOptionDisabled(e),a=p?null:this.props.tabIndex||0;return h.default.createElement(T,{key:s,label:l,option:e,template:this.props.itemTemplate,selected:this.props.isSelected(e),onClick:this.props.onOptionSelect,onKeyDown:this.props.onOptionKeyDown,tabIndex:a,disabled:p})}},{key:"renderItems",value:function(){var e=this;return this.props.visibleOptions&&this.props.visibleOptions.length?this.props.visibleOptions.map((function(t,n){return e.renderItem(t,n)})):this.props.hasFilter()?this.renderEmptyFilter():null}},{key:"renderContent",value:function(){var e=this;if(this.props.virtualScrollerOptions){var t=B(B({},this.props.virtualScrollerOptions),{style:B(B({},this.props.virtualScrollerOptions.style),{height:this.props.scrollHeight}),className:n.classNames("p-multiselect-items-wrapper",this.props.virtualScrollerOptions.className),items:this.props.visibleOptions,onLazyLoad:function(t){return e.props.virtualScrollerOptions.onLazyLoad(B(B({},t),{filter:e.props.filterValue}))},itemTemplate:function(t,n){return t&&e.renderItem(t,n.index)},contentTemplate:function(t){var i=n.classNames("p-multiselect-items p-component",t.className),r=e.isEmptyFilter()?e.renderEmptyFilter():t.children;return h.default.createElement("ul",{ref:t.contentRef,className:i,role:"listbox","aria-multiselectable":!0},r)}});return h.default.createElement(p.VirtualScroller,f({ref:function(t){return e.virtualScrollerRef=t}},t))}var i=this.renderItems();return h.default.createElement("div",{className:"p-multiselect-items-wrapper",style:{maxHeight:this.props.scrollHeight}},h.default.createElement("ul",{className:"p-multiselect-items p-component",role:"listbox","aria-multiselectable":!0},i))}},{key:"renderElement",value:function(){var e=n.classNames("p-multiselect-panel p-component",{"p-multiselect-limited":!this.props.allowOptionSelect()},this.props.panelClassName),t=this.renderHeader(),i=this.renderContent(),o=this.renderFooter();return h.default.createElement(r.CSSTransition,{nodeRef:this.props.forwardRef,classNames:"p-connected-overlay",in:this.props.in,timeout:{enter:120,exit:100},options:this.props.transitionOptions,unmountOnExit:!0,onEnter:this.onEnter,onEntered:this.props.onEntered,onExit:this.props.onExit,onExited:this.props.onExited},h.default.createElement("div",{ref:this.props.forwardRef,className:e,style:this.props.panelStyle,onClick:this.props.onClick},t,i,o))}},{key:"render",value:function(){var e=this.renderElement();return h.default.createElement(o.Portal,{element:e,appendTo:this.props.appendTo})}}]),s}(t.Component),M=h.default.forwardRef((function(e,t){return h.default.createElement(H,f({forwardRef:t},e))}));function q(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 z(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?q(Object(n),!0).forEach((function(t){R(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):q(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=J(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0,r=function(){};return{s:r,n:function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}},e:function(e){throw e},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,l=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return l=e.done,e},e:function(e){s=!0,o=e},f:function(){try{l||null==n.return||n.return()}finally{if(s)throw o}}}}function J(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 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}function Z(){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(e){L(s,e);var r,o,l=(r=s,o=Z(),function(){var e,t=I(r);if(o){var n=I(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return x(this,e)});function s(e){var n;return k(this,s),(n=l.call(this,e)).state={filter:"",focused:!1,overlayVisible:!1},n.onClick=n.onClick.bind(E(n)),n.onKeyDown=n.onKeyDown.bind(E(n)),n.onOptionSelect=n.onOptionSelect.bind(E(n)),n.onOptionKeyDown=n.onOptionKeyDown.bind(E(n)),n.onFocus=n.onFocus.bind(E(n)),n.onBlur=n.onBlur.bind(E(n)),n.onFilterInputChange=n.onFilterInputChange.bind(E(n)),n.onCloseClick=n.onCloseClick.bind(E(n)),n.onSelectAll=n.onSelectAll.bind(E(n)),n.onOverlayEnter=n.onOverlayEnter.bind(E(n)),n.onOverlayEntered=n.onOverlayEntered.bind(E(n)),n.onOverlayExit=n.onOverlayExit.bind(E(n)),n.onOverlayExited=n.onOverlayExited.bind(E(n)),n.onPanelClick=n.onPanelClick.bind(E(n)),n.getOptionLabel=n.getOptionLabel.bind(E(n)),n.getOptionRenderKey=n.getOptionRenderKey.bind(E(n)),n.isOptionDisabled=n.isOptionDisabled.bind(E(n)),n.getOptionGroupChildren=n.getOptionGroupChildren.bind(E(n)),n.getOptionGroupLabel=n.getOptionGroupLabel.bind(E(n)),n.getOptionGroupRenderKey=n.getOptionGroupRenderKey.bind(E(n)),n.allowOptionSelect=n.allowOptionSelect.bind(E(n)),n.isSelected=n.isSelected.bind(E(n)),n.isAllSelected=n.isAllSelected.bind(E(n)),n.hasFilter=n.hasFilter.bind(E(n)),n.getSelectedOptionIndex=n.getSelectedOptionIndex.bind(E(n)),n.hide=n.hide.bind(E(n)),n.onOptionKeyDown=n.onOptionKeyDown.bind(E(n)),n.overlayRef=t.createRef(),n.inputRef=t.createRef(n.props.inputRef),n}return S(s,[{key:"onPanelClick",value:function(e){u.OverlayService.emit("overlay-click",{originalEvent:e,target:this.container})}},{key:"allowOptionSelect",value:function(){return!this.props.selectionLimit||!this.props.value||this.props.value&&this.props.value.length<this.props.selectionLimit}},{key:"onOptionSelect",value:function(e){var t=this,i=e.originalEvent,r=e.option;if(!this.props.disabled&&!this.isOptionDisabled(r)){var o=this.getOptionValue(r),l=this.isOptionValueUsed(r),s=this.isSelected(r),p=this.allowOptionSelect();s?this.updateModel(i,this.props.value.filter((function(e){return!n.ObjectUtils.equals(l?e:t.getOptionValue(e),o,t.equalityKey())}))):p&&this.updateModel(i,[].concat(g(this.props.value||[]),[o]))}}},{key:"onOptionKeyDown",value:function(e){var t=e.originalEvent,n=t.currentTarget;switch(t.which){case 40:var i=this.findNextItem(n);i&&i.focus(),t.preventDefault();break;case 38:var r=this.findPrevItem(n);r&&r.focus(),t.preventDefault();break;case 13:case 32:this.onOptionSelect(e),t.preventDefault();break;case 27:this.hide(),this.inputRef.current.focus()}}},{key:"findNextItem",value:function(e){var t=e.nextElementSibling;return t?n.DomHandler.hasClass(t,"p-disabled")||n.DomHandler.hasClass(t,"p-multiselect-item-group")?this.findNextItem(t):t:null}},{key:"findPrevItem",value:function(e){var t=e.previousElementSibling;return t?n.DomHandler.hasClass(t,"p-disabled")||n.DomHandler.hasClass(t,"p-multiselect-item-group")?this.findPrevItem(t):t:null}},{key:"onClick",value:function(e){this.props.disabled||this.isPanelClicked(e)||n.DomHandler.hasClass(e.target,"p-multiselect-token-icon")||this.isClearClicked(e)||(this.state.overlayVisible?this.hide():this.show(),this.inputRef.current.focus(),e.preventDefault())}},{key:"onKeyDown",value:function(e){switch(e.which){case 40:!this.state.overlayVisible&&e.altKey&&(this.show(),e.preventDefault());break;case 32:this.state.overlayVisible?this.hide():this.show(),e.preventDefault();break;case 27:this.hide();break;case 9:if(this.state.overlayVisible){var t=n.DomHandler.getFirstFocusableElement(this.overlayRef.current);t&&(t.focus(),e.preventDefault())}}}},{key:"onSelectAll",value:function(e){var t=this;if(this.props.onSelectAll)this.props.onSelectAll(e);else{var n=null,i=this.getVisibleOptions();if(e.checked){if(n=[],i){var r=i.filter((function(e){return t.isOptionDisabled(e)&&t.isSelected(e)}));n=r.map((function(e){return t.getOptionValue(e)}))}}else i&&(i=i.filter((function(e){return!t.isOptionDisabled(e)})),this.props.optionGroupLabel?(n=[],i.forEach((function(e){return n=[].concat(g(n),g(t.getOptionGroupChildren(e).filter((function(e){return!t.isOptionDisabled(e)})).map((function(e){return t.getOptionValue(e)}))))}))):n=i.map((function(e){return t.getOptionValue(e)})));this.updateModel(e.originalEvent,n)}}},{key:"updateModel",value:function(e,t){this.props.onChange&&this.props.onChange({originalEvent:e,value:t,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:t}})}},{key:"onFilterInputChange",value:function(e){var t=this,n=e.query;this.setState({filter:n},(function(){t.props.onFilter&&t.props.onFilter({originalEvent:e,filter:n})}))}},{key:"resetFilter",value:function(){var e=this;this.setState({filter:""},(function(){e.props.onFilter&&e.props.onFilter({filter:""})}))}},{key:"show",value:function(){this.setState({overlayVisible:!0})}},{key:"hide",value:function(){this.setState({overlayVisible:!1})}},{key:"onOverlayEnter",value:function(e){n.ZIndexUtils.set("overlay",this.overlayRef.current,d.default.autoZIndex,d.default.zIndex.overlay),this.alignOverlay(),this.scrollInView(),e&&e()}},{key:"onOverlayEntered",value:function(){this.bindDocumentClickListener(),this.bindScrollListener(),this.bindResizeListener(),this.props.onShow&&this.props.onShow()}},{key:"onOverlayExit",value:function(){this.unbindDocumentClickListener(),this.unbindScrollListener(),this.unbindResizeListener()}},{key:"onOverlayExited",value:function(){this.props.filter&&this.props.resetFilterOnHide&&this.resetFilter(),n.ZIndexUtils.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"alignOverlay",value:function(){n.DomHandler.alignOverlay(this.overlayRef.current,this.label.parentElement,this.props.appendTo||d.default.appendTo)}},{key:"scrollInView",value:function(){var e=n.DomHandler.findSingle(this.overlayRef.current,"li.p-highlight");e&&e.scrollIntoView({block:"nearest",inline:"start"})}},{key:"onCloseClick",value:function(e){this.hide(),this.inputRef.current.focus(),e.preventDefault(),e.stopPropagation()}},{key:"getSelectedOptionIndex",value:function(){if(null!=this.props.value&&this.props.options){if(!this.props.optionGroupLabel)return this.findOptionIndexInList(this.props.value,this.props.options);for(var e=0;e<this.props.options.length;e++){var t=this.findOptionIndexInList(this.props.value,this.getOptionGroupChildren(this.props.options[e]));if(-1!==t)return{group:e,option:t}}}return-1}},{key:"findOptionIndexInList",value:function(e,t){var i=this,r=this.equalityKey();return t.findIndex((function(t){return e.some((function(e){return n.ObjectUtils.equals(e,i.getOptionValue(t),r)}))}))}},{key:"isSelected",value:function(e){var t=this,i=!1;if(this.props.value){var r=this.getOptionValue(e),o=this.isOptionValueUsed(e),l=this.equalityKey();i=this.props.value.some((function(e){return n.ObjectUtils.equals(o?e:t.getOptionValue(e),r,l)}))}return i}},{key:"getLabelByValue",value:function(e){var t;if(this.props.options)if(this.props.optionGroupLabel){var n,i=_(this.props.options);try{for(i.s();!(n=i.n()).done;){if(t=this.findOptionByValue(e,this.getOptionGroupChildren(n.value)))break}}catch(e){i.e(e)}finally{i.f()}}else t=this.findOptionByValue(e,this.props.options);return t?this.getOptionLabel(t):null}},{key:"findOptionByValue",value:function(e,t){var i,r=this.equalityKey(),o=_(t);try{for(o.s();!(i=o.n()).done;){var l=i.value,s=this.getOptionValue(l);if(n.ObjectUtils.equals(s,e,r))return l}}catch(e){o.e(e)}finally{o.f()}return null}},{key:"onFocus",value:function(e){var t=this;e.persist(),this.setState({focused:!0},(function(){t.props.onFocus&&t.props.onFocus(e)}))}},{key:"onBlur",value:function(e){var t=this;e.persist(),this.setState({focused:!1},(function(){t.props.onBlur&&t.props.onBlur(e)}))}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.state.overlayVisible&&e.isOutsideClicked(t)&&e.hide()},document.addEventListener("click",this.documentClickListener))}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new n.ConnectedOverlayScrollHandler(this.container,(function(){e.state.overlayVisible&&e.hide()}))),this.scrollHandler.bindScrollListener()}},{key:"unbindScrollListener",value:function(){this.scrollHandler&&this.scrollHandler.unbindScrollListener()}},{key:"bindResizeListener",value:function(){var e=this;this.resizeListener||(this.resizeListener=function(){e.state.overlayVisible&&!n.DomHandler.isTouchDevice()&&e.hide()},window.addEventListener("resize",this.resizeListener))}},{key:"unbindResizeListener",value:function(){this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null)}},{key:"isOutsideClicked",value:function(e){return this.container&&!(this.container.isSameNode(e.target)||this.isClearClicked(e)||this.container.contains(e.target)||this.isPanelClicked(e))}},{key:"isClearClicked",value:function(e){return n.DomHandler.hasClass(e.target,"p-multiselect-clear-icon")}},{key:"isPanelClicked",value:function(e){return this.overlayRef&&this.overlayRef.current&&this.overlayRef.current.contains(e.target)}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"updateInputRef",value:function(){var e=this.props.inputRef;e&&("function"==typeof e?e(this.inputRef.current):e.current=this.inputRef.current)}},{key:"componentDidMount",value:function(){this.updateInputRef(),this.props.tooltip&&this.renderTooltip()}},{key:"componentDidUpdate",value:function(e){e.tooltip===this.props.tooltip&&e.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(z({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip()),this.state.overlayVisible&&this.hasFilter()&&this.alignOverlay()}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=null),n.ZIndexUtils.clear(this.overlayRef.current)}},{key:"hasFilter",value:function(){return this.state.filter&&this.state.filter.trim().length>0}},{key:"isAllSelected",value:function(){var e=this;if(this.props.onSelectAll)return this.props.selectAll;var t=this.getVisibleOptions();if(n.ObjectUtils.isEmpty(t))return!1;if(t=t.filter((function(t){return!e.isOptionDisabled(t)})),this.props.optionGroupLabel){var i,r=_(t);try{for(r.s();!(i=r.n()).done;){var o,l=this.getOptionGroupChildren(i.value).filter((function(t){return!e.isOptionDisabled(t)})),s=_(l);try{for(s.s();!(o=s.n()).done;){if(!this.isSelected(o.value))return!1}}catch(e){s.e(e)}finally{s.f()}}}catch(e){r.e(e)}finally{r.f()}}else{var p,a=_(t);try{for(a.s();!(p=a.n()).done;){if(!this.isSelected(p.value))return!1}}catch(e){a.e(e)}finally{a.f()}}return!0}},{key:"getOptionLabel",value:function(e){return this.props.optionLabel?n.ObjectUtils.resolveFieldData(e,this.props.optionLabel):e&&void 0!==e.label?e.label:e}},{key:"getOptionValue",value:function(e){if(this.props.optionValue){var t=n.ObjectUtils.resolveFieldData(e,this.props.optionValue);return null!==t?t:e}return e&&void 0!==e.value?e.value:e}},{key:"getOptionRenderKey",value:function(e){return this.props.dataKey?n.ObjectUtils.resolveFieldData(e,this.props.dataKey):this.getOptionLabel(e)}},{key:"getOptionGroupRenderKey",value:function(e){return n.ObjectUtils.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupLabel",value:function(e){return n.ObjectUtils.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupChildren",value:function(e){return n.ObjectUtils.resolveFieldData(e,this.props.optionGroupChildren)}},{key:"isOptionDisabled",value:function(e){return this.props.optionDisabled?n.ObjectUtils.isFunction(this.props.optionDisabled)?this.props.optionDisabled(e):n.ObjectUtils.resolveFieldData(e,this.props.optionDisabled):!(!e||void 0===e.disabled)&&e.disabled}},{key:"isOptionValueUsed",value:function(e){return this.props.optionValue||e&&void 0!==e.value}},{key:"getVisibleOptions",value:function(){if(this.hasFilter()){var e=this.state.filter.trim().toLocaleLowerCase(this.props.filterLocale),t=this.props.filterBy?this.props.filterBy.split(","):[this.props.optionLabel||"label"];if(this.props.optionGroupLabel){var n,i=[],r=_(this.props.options);try{for(r.s();!(n=r.n()).done;){var o=n.value,l=a.FilterService.filter(this.getOptionGroupChildren(o),t,e,this.props.filterMatchMode,this.props.filterLocale);l&&l.length&&i.push(z(z({},o),{items:l}))}}catch(e){r.e(e)}finally{r.f()}return i}return a.FilterService.filter(this.props.options,t,e,this.props.filterMatchMode,this.props.filterLocale)}return this.props.options}},{key:"isEmpty",value:function(){return!this.props.value||0===this.props.value.length}},{key:"equalityKey",value:function(){return this.props.optionValue?null:this.props.dataKey}},{key:"checkValidity",value:function(){return this.inputRef.current.checkValidity()}},{key:"removeChip",value:function(e,t){var i=this.equalityKey(),r=this.props.value.filter((function(e){return!n.ObjectUtils.equals(e,t,i)}));this.updateModel(e,r)}},{key:"getSelectedItemsLabel",value:function(){var e=/{(.*?)}/;return e.test(this.props.selectedItemsLabel)?this.props.selectedItemsLabel.replace(this.props.selectedItemsLabel.match(e)[0],this.props.value.length+""):this.props.selectedItemsLabel}},{key:"getLabel",value:function(){var e;if(!this.isEmpty()&&!this.props.fixedPlaceholder){if(this.props.maxSelectedLabels&&this.props.value.length>this.props.maxSelectedLabels)return this.getSelectedItemsLabel();e="";for(var t=0;t<this.props.value.length;t++)0!==t&&(e+=","),e+=this.getLabelByValue(this.props.value[t]);return e}return e}},{key:"getLabelContent",value:function(){var e=this;return this.props.selectedItemTemplate?this.isEmpty()?n.ObjectUtils.getJSXElement(this.props.selectedItemTemplate):this.props.maxSelectedLabels&&this.props.value.length>this.props.maxSelectedLabels?this.getSelectedItemsLabel():this.props.value.map((function(t,i){var r=n.ObjectUtils.getJSXElement(e.props.selectedItemTemplate,t);return h.default.createElement(h.default.Fragment,{key:i},r)})):"chip"!==this.props.display||this.isEmpty()?this.getLabel():this.props.value.slice(0,this.props.maxSelectedLabels||this.props.value.length).map((function(t){var i=e.getLabelByValue(t);return h.default.createElement("div",{className:"p-multiselect-token",key:i},h.default.createElement("span",{className:"p-multiselect-token-label"},i),!e.props.disabled&&n.IconUtils.getJSXIcon(e.props.removeIcon,{className:"p-multiselect-token-icon",onClick:function(n){return e.removeChip(n,t)}},{props:e.props}))}))}},{key:"renderTooltip",value:function(){this.tooltip=i.tip({target:this.container,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"renderClearIcon",value:function(){var e=this;return this.isEmpty()||!this.props.showClear||this.props.disabled?null:h.default.createElement("i",{className:"p-multiselect-clear-icon pi pi-times",onClick:function(t){return e.updateModel(t,null)}})}},{key:"renderLabel",value:function(){var e=this,t=this.isEmpty(),i=this.getLabelContent(),r=n.classNames("p-multiselect-label",{"p-placeholder":t&&this.props.placeholder,"p-multiselect-label-empty":t&&!this.props.placeholder&&!this.props.selectedItemTemplate,"p-multiselect-items-label":!t&&"chip"!==this.props.display&&this.props.value.length>this.props.maxSelectedLabels});return h.default.createElement("div",{ref:function(t){return e.label=t},className:"p-multiselect-label-container"},h.default.createElement("div",{className:r},i||this.props.placeholder||"empty"))}},{key:"render",value:function(){var e=this,t=n.classNames("p-multiselect p-component p-inputwrapper",{"p-multiselect-chip":"chip"===this.props.display,"p-disabled":this.props.disabled,"p-multiselect-clearable":this.props.showClear&&!this.props.disabled,"p-focus":this.state.focused,"p-inputwrapper-filled":this.props.value&&this.props.value.length>0,"p-inputwrapper-focus":this.state.focused||this.state.overlayVisible},this.props.className),i=this.getVisibleOptions(),r=this.renderLabel(),o=this.renderClearIcon();return h.default.createElement("div",{id:this.props.id,className:t,onClick:this.onClick,ref:function(t){return e.container=t},style:this.props.style},h.default.createElement("div",{className:"p-hidden-accessible"},h.default.createElement("input",{ref:this.inputRef,id:this.props.inputId,name:this.props.name,readOnly:!0,type:"text",onFocus:this.onFocus,onBlur:this.onBlur,onKeyDown:this.onKeyDown,role:"listbox","aria-haspopup":"listbox","aria-labelledby":this.props.ariaLabelledBy,"aria-expanded":this.state.overlayVisible,disabled:this.props.disabled,tabIndex:this.props.tabIndex})),r,o,h.default.createElement("div",{className:"p-multiselect-trigger"},n.IconUtils.getJSXIcon(this.props.dropdownIcon,{className:"p-multiselect-trigger-icon p-c"},{props:this.props})),h.default.createElement(M,f({ref:this.overlayRef,visibleOptions:i},this.props,{onClick:this.onPanelClick,onOverlayHide:this.hide,filterValue:this.state.filter,hasFilter:this.hasFilter,onFilterInputChange:this.onFilterInputChange,onCloseClick:this.onCloseClick,onSelectAll:this.onSelectAll,getOptionLabel:this.getOptionLabel,getOptionRenderKey:this.getOptionRenderKey,isOptionDisabled:this.isOptionDisabled,getOptionGroupChildren:this.getOptionGroupChildren,getOptionGroupLabel:this.getOptionGroupLabel,getOptionGroupRenderKey:this.getOptionGroupRenderKey,isSelected:this.isSelected,getSelectedOptionIndex:this.getSelectedOptionIndex,isAllSelected:this.isAllSelected,onOptionSelect:this.onOptionSelect,allowOptionSelect:this.allowOptionSelect,onOptionKeyDown:this.onOptionKeyDown,in:this.state.overlayVisible,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited})))}}]),s}(t.Component);return R(W,"defaultProps",{id:null,inputRef:null,name:null,value:null,options:null,optionLabel:null,optionValue:null,optionDisabled:null,optionGroupLabel:null,optionGroupChildren:null,optionGroupTemplate:null,display:"comma",style:null,className:null,panelClassName:null,panelStyle:null,virtualScrollerOptions:null,scrollHeight:"200px",placeholder:null,fixedPlaceholder:!1,disabled:!1,showClear:!1,filter:!1,filterBy:null,filterMatchMode:"contains",filterPlaceholder:null,filterLocale:void 0,emptyFilterMessage:null,resetFilterOnHide:!1,tabIndex:0,dataKey:null,inputId:null,appendTo:null,tooltip:null,tooltipOptions:null,maxSelectedLabels:null,selectionLimit:null,selectedItemsLabel:"{0} items selected",ariaLabelledBy:null,itemTemplate:null,selectedItemTemplate:null,panelHeaderTemplate:null,panelFooterTemplate:null,transitionOptions:null,dropdownIcon:"pi pi-chevron-down",removeIcon:"pi pi-times-circle",showSelectAll:!0,selectAll:!1,onChange:null,onFocus:null,onBlur:null,onShow:null,onHide:null,onFilter:null,onSelectAll:null}),e.MultiSelect=W,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.utils,primereact.tooltip,primereact.csstransition,primereact.portal,primereact.inputtext,primereact.ripple,primereact.virtualscroller,primereact.api,primereact.overlayservice);
|