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

2 lines
37 KiB
JavaScript

import e,{createRef as t,Component as n}from"react";import{classNames as i,IconUtils as r,ObjectUtils as o,DomHandler as l,ZIndexUtils as s,ConnectedOverlayScrollHandler as p}from"primereact/utils";import{tip as a}from"primereact/tooltip";import{CSSTransition as c}from"primereact/csstransition";import{Portal as u}from"primereact/portal";import{InputText as h}from"primereact/inputtext";import{Ripple as f}from"primereact/ripple";import{VirtualScroller as d}from"primereact/virtualscroller";import y,{localeOption as v,FilterService as m}from"primereact/api";import{OverlayService as b}from"primereact/overlayservice";function O(){return O=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},O.apply(this,arguments)}function g(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 k(e){if(Array.isArray(e))return g(e)}function C(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function E(e,t){if(e){if("string"==typeof e)return g(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)?g(e,t):void 0}}function S(){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 w(e){return k(e)||C(e)||E(e)||S()}function L(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function x(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 D(e,t,n){return t&&x(e.prototype,t),n&&x(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function I(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function R(e,t){return R=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},R(e,t)}function F(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&&R(e,t)}function P(e){return P="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},P(e)}function V(e,t){if(t&&("object"===P(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return I(e)}function K(e){return K=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},K(e)}function j(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function N(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 A(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?N(Object(n),!0).forEach((function(t){j(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):N(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function G(){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(o){F(c,n);var l,s,p=(l=c,s=G(),function(){var e,t=K(l);if(s){var n=K(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return V(this,e)});function c(e){var n;return L(this,c),(n=p.call(this,e)).state={focused:!1},n.onClick=n.onClick.bind(I(n)),n.onFocus=n.onFocus.bind(I(n)),n.onBlur=n.onBlur.bind(I(n)),n.onKeyDown=n.onKeyDown.bind(I(n)),n.inputRef=t(n.props.inputRef),n}return D(c,[{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(A({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=a({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 t=this,n=this.isChecked(),o=i("p-checkbox p-component",{"p-checkbox-checked":n,"p-checkbox-disabled":this.props.disabled,"p-checkbox-focused":this.state.focused},this.props.className),l=i("p-checkbox-box",{"p-highlight":n,"p-disabled":this.props.disabled,"p-focus":this.state.focused}),s=n&&this.props.icon;return e.createElement("div",{ref:function(e){return t.element=e},id:this.props.id,className:o,style:this.props.style,onClick:this.onClick,onContextMenu:this.props.onContextMenu,onMouseDown:this.props.onMouseDown},e.createElement("div",{className:"p-hidden-accessible"},e.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:n,onKeyDown:this.onKeyDown,onFocus:this.onFocus,onBlur:this.onBlur,disabled:this.props.disabled,readOnly:this.props.readOnly,required:this.props.required})),e.createElement("div",{className:l,ref:function(e){return t.box=e},role:"checkbox","aria-checked":n},r.getJSXIcon(s,{className:"p-checkbox-icon p-c"},{props:this.props,checked:n})))}}]),c}();function B(){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}}j(T,"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 M=function(t){F(s,n);var i,r,l=(i=s,r=B(),function(){var e,t=K(i);if(r){var n=K(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return V(this,e)});function s(e){var t;return L(this,s),(t=l.call(this,e)).onFilter=t.onFilter.bind(I(t)),t.onSelectAll=t.onSelectAll.bind(I(t)),t}return D(s,[{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?e.createElement("div",{className:"p-multiselect-filter-container"},e.createElement(h,{type:"text",role:"textbox",value:this.props.filterValue,onChange:this.onFilter,className:"p-multiselect-filter",placeholder:this.props.filterPlaceholder}),e.createElement("span",{className:"p-multiselect-filter-icon pi pi-search"})):null}},{key:"render",value:function(){var t=this.renderFilterElement(),n=this.props.showSelectAll&&e.createElement(T,{checked:this.props.selectAll,onChange:this.onSelectAll,role:"checkbox","aria-checked":this.props.selectAll}),i=e.createElement("button",{type:"button",className:"p-multiselect-close p-link",onClick:this.props.onClose},e.createElement("span",{className:"p-multiselect-close-icon pi pi-times"}),e.createElement(f,null)),r=e.createElement("div",{className:"p-multiselect-header"},n,t,i);return this.props.template?o.getJSXElement(this.props.template,{className:"p-multiselect-header",checkboxElement:n,checked:this.props.selectAll,onChange:this.onSelectAll,filterElement:t,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}}]),s}();function H(){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 q=function(t){F(p,n);var r,l,s=(r=p,l=H(),function(){var e,t=K(r);if(l){var n=K(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return V(this,e)});function p(e){var t;return L(this,p),(t=s.call(this,e)).onClick=t.onClick.bind(I(t)),t.onKeyDown=t.onKeyDown.bind(I(t)),t}return D(p,[{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 t=i("p-multiselect-item",{"p-highlight":this.props.selected,"p-disabled":this.props.disabled},this.props.option.className),n=i("p-checkbox-box",{"p-highlight":this.props.selected}),r=i("p-checkbox-icon p-c",{"pi pi-check":this.props.selected}),l=this.props.template?o.getJSXElement(this.props.template,this.props.option):this.props.label;return e.createElement("li",{className:t,onClick:this.onClick,tabIndex:this.props.disabled?null:this.props.tabIndex||0,onKeyDown:this.onKeyDown,role:"option","aria-selected":this.props.selected},e.createElement("div",{className:"p-checkbox p-component"},e.createElement("div",{className:n},e.createElement("span",{className:r}))),e.createElement("span",null,l),e.createElement(f,null))}}]),p}();function z(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?z(Object(n),!0).forEach((function(t){j(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):z(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}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}}j(q,"defaultProps",{option:null,label:null,selected:!1,disabled:!1,tabIndex:null,template:null,onClick:null,onKeyDown:null});var X=function(t){F(p,n);var r,l,s=(r=p,l=J(),function(){var e,t=K(r);if(l){var n=K(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return V(this,e)});function p(e){var t;return L(this,p),(t=s.call(this,e)).onEnter=t.onEnter.bind(I(t)),t.onFilterInputChange=t.onFilterInputChange.bind(I(t)),t}return D(p,[{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 e.createElement(M,{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 t=o.getJSXElement(this.props.panelFooterTemplate,this.props,this.props.onOverlayHide);return e.createElement("div",{className:"p-multiselect-footer"},t)}return null}},{key:"renderGroupChildren",value:function(t){var n=this;return this.props.getOptionGroupChildren(t).map((function(t,i){var r=n.props.getOptionLabel(t),o=i+"_"+n.props.getOptionRenderKey(t),l=n.props.isOptionDisabled(t),s=l?null:n.props.tabIndex||0;return e.createElement(q,{key:o,label:r,option:t,template:n.props.itemTemplate,selected:n.props.isSelected(t),onClick:n.props.onOptionSelect,onKeyDown:n.props.onOptionKeyDown,tabIndex:s,disabled:l})}))}},{key:"renderEmptyFilter",value:function(){var t=o.getJSXElement(this.props.emptyFilterMessage,this.props)||v("emptyFilterMessage");return e.createElement("li",{className:"p-multiselect-empty-message"},t)}},{key:"renderItem",value:function(t,n){if(this.props.optionGroupLabel){var i=this.props.optionGroupTemplate?o.getJSXElement(this.props.optionGroupTemplate,t,n):this.props.getOptionGroupLabel(t),r=this.renderGroupChildren(t),l=n+"_"+this.props.getOptionGroupRenderKey(t);return e.createElement(e.Fragment,{key:l},e.createElement("li",{className:"p-multiselect-item-group"},i),r)}var s=this.props.getOptionLabel(t),p=n+"_"+this.props.getOptionRenderKey(t),a=this.props.isOptionDisabled(t),c=a?null:this.props.tabIndex||0;return e.createElement(q,{key:p,label:s,option:t,template:this.props.itemTemplate,selected:this.props.isSelected(t),onClick:this.props.onOptionSelect,onKeyDown:this.props.onOptionKeyDown,tabIndex:c,disabled:a})}},{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 t=this;if(this.props.virtualScrollerOptions){var n=_(_({},this.props.virtualScrollerOptions),{style:_(_({},this.props.virtualScrollerOptions.style),{height:this.props.scrollHeight}),className:i("p-multiselect-items-wrapper",this.props.virtualScrollerOptions.className),items:this.props.visibleOptions,onLazyLoad:function(e){return t.props.virtualScrollerOptions.onLazyLoad(_(_({},e),{filter:t.props.filterValue}))},itemTemplate:function(e,n){return e&&t.renderItem(e,n.index)},contentTemplate:function(n){var r=i("p-multiselect-items p-component",n.className),o=t.isEmptyFilter()?t.renderEmptyFilter():n.children;return e.createElement("ul",{ref:n.contentRef,className:r,role:"listbox","aria-multiselectable":!0},o)}});return e.createElement(d,O({ref:function(e){return t.virtualScrollerRef=e}},n))}var r=this.renderItems();return e.createElement("div",{className:"p-multiselect-items-wrapper",style:{maxHeight:this.props.scrollHeight}},e.createElement("ul",{className:"p-multiselect-items p-component",role:"listbox","aria-multiselectable":!0},r))}},{key:"renderElement",value:function(){var t=i("p-multiselect-panel p-component",{"p-multiselect-limited":!this.props.allowOptionSelect()},this.props.panelClassName),n=this.renderHeader(),r=this.renderContent(),o=this.renderFooter();return e.createElement(c,{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},e.createElement("div",{ref:this.props.forwardRef,className:t,style:this.props.panelStyle,onClick:this.props.onClick},n,r,o))}},{key:"render",value:function(){var t=this.renderElement();return e.createElement(u,{element:t,appendTo:this.props.appendTo})}}]),p}(),U=e.forwardRef((function(t,n){return e.createElement(X,O({forwardRef:n},t))}));function W(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?W(Object(n),!0).forEach((function(t){j(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):W(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Z(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=Q(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 Q(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 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 ee(){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 te=function(c){F(d,n);var u,h,f=(u=d,h=ee(),function(){var e,t=K(u);if(h){var n=K(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return V(this,e)});function d(e){var n;return L(this,d),(n=f.call(this,e)).state={filter:"",focused:!1,overlayVisible:!1},n.onClick=n.onClick.bind(I(n)),n.onKeyDown=n.onKeyDown.bind(I(n)),n.onOptionSelect=n.onOptionSelect.bind(I(n)),n.onOptionKeyDown=n.onOptionKeyDown.bind(I(n)),n.onFocus=n.onFocus.bind(I(n)),n.onBlur=n.onBlur.bind(I(n)),n.onFilterInputChange=n.onFilterInputChange.bind(I(n)),n.onCloseClick=n.onCloseClick.bind(I(n)),n.onSelectAll=n.onSelectAll.bind(I(n)),n.onOverlayEnter=n.onOverlayEnter.bind(I(n)),n.onOverlayEntered=n.onOverlayEntered.bind(I(n)),n.onOverlayExit=n.onOverlayExit.bind(I(n)),n.onOverlayExited=n.onOverlayExited.bind(I(n)),n.onPanelClick=n.onPanelClick.bind(I(n)),n.getOptionLabel=n.getOptionLabel.bind(I(n)),n.getOptionRenderKey=n.getOptionRenderKey.bind(I(n)),n.isOptionDisabled=n.isOptionDisabled.bind(I(n)),n.getOptionGroupChildren=n.getOptionGroupChildren.bind(I(n)),n.getOptionGroupLabel=n.getOptionGroupLabel.bind(I(n)),n.getOptionGroupRenderKey=n.getOptionGroupRenderKey.bind(I(n)),n.allowOptionSelect=n.allowOptionSelect.bind(I(n)),n.isSelected=n.isSelected.bind(I(n)),n.isAllSelected=n.isAllSelected.bind(I(n)),n.hasFilter=n.hasFilter.bind(I(n)),n.getSelectedOptionIndex=n.getSelectedOptionIndex.bind(I(n)),n.hide=n.hide.bind(I(n)),n.onOptionKeyDown=n.onOptionKeyDown.bind(I(n)),n.overlayRef=t(),n.inputRef=t(n.props.inputRef),n}return D(d,[{key:"onPanelClick",value:function(e){b.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,n=e.originalEvent,i=e.option;if(!this.props.disabled&&!this.isOptionDisabled(i)){var r=this.getOptionValue(i),l=this.isOptionValueUsed(i),s=this.isSelected(i),p=this.allowOptionSelect();s?this.updateModel(n,this.props.value.filter((function(e){return!o.equals(l?e:t.getOptionValue(e),r,t.equalityKey())}))):p&&this.updateModel(n,[].concat(w(this.props.value||[]),[r]))}}},{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?l.hasClass(t,"p-disabled")||l.hasClass(t,"p-multiselect-item-group")?this.findNextItem(t):t:null}},{key:"findPrevItem",value:function(e){var t=e.previousElementSibling;return t?l.hasClass(t,"p-disabled")||l.hasClass(t,"p-multiselect-item-group")?this.findPrevItem(t):t:null}},{key:"onClick",value:function(e){this.props.disabled||this.isPanelClicked(e)||l.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=l.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(w(n),w(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){s.set("overlay",this.overlayRef.current,y.autoZIndex,y.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(),s.clear(this.overlayRef.current),this.props.onHide&&this.props.onHide()}},{key:"alignOverlay",value:function(){l.alignOverlay(this.overlayRef.current,this.label.parentElement,this.props.appendTo||y.appendTo)}},{key:"scrollInView",value:function(){var e=l.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 n=this,i=this.equalityKey();return t.findIndex((function(t){return e.some((function(e){return o.equals(e,n.getOptionValue(t),i)}))}))}},{key:"isSelected",value:function(e){var t=this,n=!1;if(this.props.value){var i=this.getOptionValue(e),r=this.isOptionValueUsed(e),l=this.equalityKey();n=this.props.value.some((function(e){return o.equals(r?e:t.getOptionValue(e),i,l)}))}return n}},{key:"getLabelByValue",value:function(e){var t;if(this.props.options)if(this.props.optionGroupLabel){var n,i=Z(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 n,i=this.equalityKey(),r=Z(t);try{for(r.s();!(n=r.n()).done;){var l=n.value,s=this.getOptionValue(l);if(o.equals(s,e,i))return l}}catch(e){r.e(e)}finally{r.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 p(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&&!l.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 l.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($({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),s.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(o.isEmpty(t))return!1;if(t=t.filter((function(t){return!e.isOptionDisabled(t)})),this.props.optionGroupLabel){var n,i=Z(t);try{for(i.s();!(n=i.n()).done;){var r,l=this.getOptionGroupChildren(n.value).filter((function(t){return!e.isOptionDisabled(t)})),s=Z(l);try{for(s.s();!(r=s.n()).done;){if(!this.isSelected(r.value))return!1}}catch(e){s.e(e)}finally{s.f()}}}catch(e){i.e(e)}finally{i.f()}}else{var p,a=Z(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?o.resolveFieldData(e,this.props.optionLabel):e&&void 0!==e.label?e.label:e}},{key:"getOptionValue",value:function(e){if(this.props.optionValue){var t=o.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?o.resolveFieldData(e,this.props.dataKey):this.getOptionLabel(e)}},{key:"getOptionGroupRenderKey",value:function(e){return o.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupLabel",value:function(e){return o.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupChildren",value:function(e){return o.resolveFieldData(e,this.props.optionGroupChildren)}},{key:"isOptionDisabled",value:function(e){return this.props.optionDisabled?o.isFunction(this.props.optionDisabled)?this.props.optionDisabled(e):o.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=Z(this.props.options);try{for(r.s();!(n=r.n()).done;){var o=n.value,l=m.filter(this.getOptionGroupChildren(o),t,e,this.props.filterMatchMode,this.props.filterLocale);l&&l.length&&i.push($($({},o),{items:l}))}}catch(e){r.e(e)}finally{r.f()}return i}return m.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 n=this.equalityKey(),i=this.props.value.filter((function(e){return!o.equals(e,t,n)}));this.updateModel(e,i)}},{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 t=this;return this.props.selectedItemTemplate?this.isEmpty()?o.getJSXElement(this.props.selectedItemTemplate):this.props.maxSelectedLabels&&this.props.value.length>this.props.maxSelectedLabels?this.getSelectedItemsLabel():this.props.value.map((function(n,i){var r=o.getJSXElement(t.props.selectedItemTemplate,n);return e.createElement(e.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(n){var i=t.getLabelByValue(n);return e.createElement("div",{className:"p-multiselect-token",key:i},e.createElement("span",{className:"p-multiselect-token-label"},i),!t.props.disabled&&r.getJSXIcon(t.props.removeIcon,{className:"p-multiselect-token-icon",onClick:function(e){return t.removeChip(e,n)}},{props:t.props}))}))}},{key:"renderTooltip",value:function(){this.tooltip=a({target:this.container,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"renderClearIcon",value:function(){var t=this;return this.isEmpty()||!this.props.showClear||this.props.disabled?null:e.createElement("i",{className:"p-multiselect-clear-icon pi pi-times",onClick:function(e){return t.updateModel(e,null)}})}},{key:"renderLabel",value:function(){var t=this,n=this.isEmpty(),r=this.getLabelContent(),o=i("p-multiselect-label",{"p-placeholder":n&&this.props.placeholder,"p-multiselect-label-empty":n&&!this.props.placeholder&&!this.props.selectedItemTemplate,"p-multiselect-items-label":!n&&"chip"!==this.props.display&&this.props.value.length>this.props.maxSelectedLabels});return e.createElement("div",{ref:function(e){return t.label=e},className:"p-multiselect-label-container"},e.createElement("div",{className:o},r||this.props.placeholder||"empty"))}},{key:"render",value:function(){var t=this,n=i("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),o=this.getVisibleOptions(),l=this.renderLabel(),s=this.renderClearIcon();return e.createElement("div",{id:this.props.id,className:n,onClick:this.onClick,ref:function(e){return t.container=e},style:this.props.style},e.createElement("div",{className:"p-hidden-accessible"},e.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})),l,s,e.createElement("div",{className:"p-multiselect-trigger"},r.getJSXIcon(this.props.dropdownIcon,{className:"p-multiselect-trigger-icon p-c"},{props:this.props})),e.createElement(U,O({ref:this.overlayRef,visibleOptions:o},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})))}}]),d}();j(te,"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});export{te as MultiSelect};