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

2 lines
30 KiB
JavaScript

import e,{Component as t,createRef as n}from"react";import{classNames as i,ObjectUtils as r,DomHandler as o,ZIndexUtils as s,ConnectedOverlayScrollHandler as l}from"primereact/utils";import{Ripple as p}from"primereact/ripple";import{CSSTransition as a}from"primereact/csstransition";import{Portal as u}from"primereact/portal";import{VirtualScroller as c}from"primereact/virtualscroller";import h,{localeOption as d,FilterService as f}from"primereact/api";import{tip as v}from"primereact/tooltip";import{OverlayService as y}from"primereact/overlayservice";function b(){return b=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},b.apply(this,arguments)}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function O(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 g(e,t,n){return t&&O(e.prototype,t),n&&O(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function k(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function C(e,t){return C=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},C(e,t)}function I(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&&C(e,t)}function E(e){return E="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},E(e)}function w(e,t){if(t&&("object"===E(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return k(e)}function L(e){return L=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},L(e)}function F(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function S(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var R=function(n){I(a,t);var o,s,l=(o=a,s=S(),function(){var e,t=L(o);if(s){var n=L(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return w(this,e)});function a(e){var t;return m(this,a),(t=l.call(this,e)).onClick=t.onClick.bind(k(t)),t}return g(a,[{key:"onClick",value:function(e){this.props.onClick&&this.props.onClick({originalEvent:e,option:this.props.option})}},{key:"render",value:function(){var t=i("p-dropdown-item",{"p-highlight":this.props.selected,"p-disabled":this.props.disabled,"p-dropdown-item-empty":!this.props.label||0===this.props.label.length},this.props.option.className),n=this.props.template?r.getJSXElement(this.props.template,this.props.option):this.props.label;return e.createElement("li",{className:t,onClick:this.onClick,"aria-label":this.props.label,key:this.props.label,role:"option","aria-selected":this.props.selected},n,e.createElement(p,null))}}]),a}();function x(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 D(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?x(Object(n),!0).forEach((function(t){F(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):x(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}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}}F(R,"defaultProps",{option:null,label:null,template:null,selected:!1,disabled:!1,onClick:null});var P=function(n){I(p,t);var o,s,l=(o=p,s=V(),function(){var e,t=L(o);if(s){var n=L(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return w(this,e)});function p(e){var t;return m(this,p),(t=l.call(this,e)).onEnter=t.onEnter.bind(k(t)),t.onEntered=t.onEntered.bind(k(t)),t.onFilterInputChange=t.onFilterInputChange.bind(k(t)),t}return g(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:"onEntered",value:function(){var e=this;this.props.onEntered((function(){e.props.filter&&e.props.filterInputAutoFocus&&e.filterInput.focus()}))}},{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:"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),s=n.props.isOptionDisabled(t);return e.createElement(R,{key:o,label:r,option:t,template:n.props.itemTemplate,selected:n.props.isSelected(t),disabled:s,onClick:n.props.onOptionClick})}))}},{key:"renderEmptyMessage",value:function(t,n){var i=r.getJSXElement(t,this.props)||d(n?"emptyFilterMessage":"emptyMessage");return e.createElement("li",{className:"p-dropdown-empty-message"},i)}},{key:"renderItem",value:function(t,n){if(this.props.optionGroupLabel){var i=this.props.optionGroupTemplate?r.getJSXElement(this.props.optionGroupTemplate,t,n):this.props.getOptionGroupLabel(t),o=this.renderGroupChildren(t),s=n+"_"+this.props.getOptionGroupRenderKey(t);return e.createElement(e.Fragment,{key:s},e.createElement("li",{className:"p-dropdown-item-group"},i),o)}var l=this.props.getOptionLabel(t),p=n+"_"+this.props.getOptionRenderKey(t),a=this.props.isOptionDisabled(t);return e.createElement(R,{key:p,label:l,option:t,template:this.props.itemTemplate,selected:this.props.isSelected(t),disabled:a,onClick:this.props.onOptionClick})}},{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.renderEmptyMessage(this.props.emptyFilterMessage,!0):this.renderEmptyMessage(this.props.emptyMessage)}},{key:"renderFilterClearIcon",value:function(){var t=this;return this.props.showFilterClear&&this.props.filterValue?e.createElement("i",{className:"p-dropdown-filter-clear-icon pi pi-times",onClick:function(){return t.props.onFilterClearIconClick((function(){return t.filterInput.focus()}))}}):null}},{key:"renderFilter",value:function(){var t=this;if(this.props.filter){var n=this.renderFilterClearIcon(),r=i("p-dropdown-filter-container",{"p-dropdown-clearable-filter":!!n});return e.createElement("div",{className:"p-dropdown-header"},e.createElement("div",{className:r},e.createElement("input",{ref:function(e){return t.filterInput=e},type:"text",autoComplete:"off",className:"p-dropdown-filter p-inputtext p-component",placeholder:this.props.filterPlaceholder,onKeyDown:this.props.onFilterInputKeyDown,onChange:this.onFilterInputChange,value:this.props.filterValue}),n,e.createElement("i",{className:"p-dropdown-filter-icon pi pi-search"})))}return null}},{key:"renderContent",value:function(){var t=this;if(this.props.virtualScrollerOptions){var n=D(D({},this.props.virtualScrollerOptions),{style:D(D({},this.props.virtualScrollerOptions.style),{height:this.props.scrollHeight}),className:i("p-dropdown-items-wrapper",this.props.virtualScrollerOptions.className),items:this.props.visibleOptions,onLazyLoad:function(e){return t.props.virtualScrollerOptions.onLazyLoad(D(D({},e),{filter:t.props.filterValue}))},itemTemplate:function(e,n){return e&&t.renderItem(e,n.index)},contentTemplate:function(n){var r=i("p-dropdown-items",n.className),o=t.isEmptyFilter()?t.renderEmptyMessage():n.children;return e.createElement("ul",{ref:n.contentRef,className:r,role:"listbox"},o)}});return e.createElement(c,b({ref:function(e){return t.virtualScrollerRef=e}},n))}var r=this.renderItems();return e.createElement("div",{className:"p-dropdown-items-wrapper",style:{maxHeight:this.props.scrollHeight||"auto"}},e.createElement("ul",{className:"p-dropdown-items",role:"listbox"},r))}},{key:"renderElement",value:function(){var t=i("p-dropdown-panel p-component",this.props.panelClassName),n=this.renderFilter(),r=this.renderContent();return e.createElement(a,{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,onEntering:this.props.onEntering,onEntered:this.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))}},{key:"render",value:function(){var t=this.renderElement();return e.createElement(u,{element:t,appendTo:this.props.appendTo})}}]),p}(),G=e.forwardRef((function(t,n){return e.createElement(P,b({forwardRef:n},t))}));function K(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 N(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?K(Object(n),!0).forEach((function(t){F(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):K(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function T(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,s=!0,l=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){l=!0,o=e},f:function(){try{s||null==n.return||n.return()}finally{if(l)throw o}}}}function j(e,t){if(e){if("string"==typeof e)return M(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)?M(e,t):void 0}}function M(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 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}}var H=function(p){I(d,t);var a,u,c=(a=d,u=B(),function(){var e,t=L(a);if(u){var n=L(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return w(this,e)});function d(e){var t;return m(this,d),(t=c.call(this,e)).state={filter:"",focused:!1,overlayVisible:!1},t.onClick=t.onClick.bind(k(t)),t.onInputFocus=t.onInputFocus.bind(k(t)),t.onInputBlur=t.onInputBlur.bind(k(t)),t.onInputKeyDown=t.onInputKeyDown.bind(k(t)),t.onEditableInputChange=t.onEditableInputChange.bind(k(t)),t.onEditableInputFocus=t.onEditableInputFocus.bind(k(t)),t.onOptionClick=t.onOptionClick.bind(k(t)),t.onFilterInputChange=t.onFilterInputChange.bind(k(t)),t.onFilterInputKeyDown=t.onFilterInputKeyDown.bind(k(t)),t.onFilterClearIconClick=t.onFilterClearIconClick.bind(k(t)),t.onPanelClick=t.onPanelClick.bind(k(t)),t.onOverlayEnter=t.onOverlayEnter.bind(k(t)),t.onOverlayEntered=t.onOverlayEntered.bind(k(t)),t.onOverlayExit=t.onOverlayExit.bind(k(t)),t.onOverlayExited=t.onOverlayExited.bind(k(t)),t.resetFilter=t.resetFilter.bind(k(t)),t.clear=t.clear.bind(k(t)),t.hasFilter=t.hasFilter.bind(k(t)),t.getOptionLabel=t.getOptionLabel.bind(k(t)),t.getOptionRenderKey=t.getOptionRenderKey.bind(k(t)),t.isOptionDisabled=t.isOptionDisabled.bind(k(t)),t.getOptionGroupChildren=t.getOptionGroupChildren.bind(k(t)),t.getOptionGroupLabel=t.getOptionGroupLabel.bind(k(t)),t.getOptionGroupRenderKey=t.getOptionGroupRenderKey.bind(k(t)),t.getSelectedOptionIndex=t.getSelectedOptionIndex.bind(k(t)),t.isSelected=t.isSelected.bind(k(t)),t.overlayRef=n(),t.inputRef=n(t.props.inputRef),t}return g(d,[{key:"onClick",value:function(e){this.props.disabled||o.hasClass(e.target,"p-dropdown-clear-icon")||"INPUT"===e.target.tagName||this.overlayRef.current&&this.overlayRef.current&&this.overlayRef.current.contains(e.target)||(this.focusInput.focus(),this.state.overlayVisible?this.hideOverlay():this.showOverlay())}},{key:"onInputFocus",value:function(e){var t=this;e.persist(),this.props.showOnFocus&&!this.state.overlayVisible&&this.showOverlay(),this.setState({focused:!0},(function(){t.props.onFocus&&t.props.onFocus(e)}))}},{key:"onInputBlur",value:function(e){var t=this;e.persist(),this.setState({focused:!1},(function(){t.props.onBlur&&t.props.onBlur(e)}))}},{key:"onPanelClick",value:function(e){y.emit("overlay-click",{originalEvent:e,target:this.container})}},{key:"onInputKeyDown",value:function(e){switch(e.which){case 40:this.onDownKey(e);break;case 38:this.onUpKey(e);break;case 32:this.state.overlayVisible?this.hideOverlay():this.showOverlay(),e.preventDefault();break;case 13:this.hideOverlay(),e.preventDefault();break;case 27:case 9:this.hideOverlay();break;default:this.search(e)}}},{key:"onFilterInputKeyDown",value:function(e){switch(e.which){case 40:this.onDownKey(e);break;case 38:this.onUpKey(e);break;case 13:case 27:this.hideOverlay(),e.preventDefault()}}},{key:"onUpKey",value:function(e){if(this.getVisibleOptions()){var t=this.findPrevOption(this.getSelectedOptionIndex());t&&this.selectItem({originalEvent:e,option:t})}e.preventDefault()}},{key:"onDownKey",value:function(e){if(this.getVisibleOptions())if(!this.state.overlayVisible&&e.altKey)this.showOverlay();else{var t=this.findNextOption(this.getSelectedOptionIndex());t&&this.selectItem({originalEvent:e,option:t})}e.preventDefault()}},{key:"findNextOption",value:function(e){var t=this.getVisibleOptions();if(this.props.optionGroupLabel){var n=-1===e?0:e.group,i=-1===e?-1:e.option,r=this.findNextOptionInList(this.getOptionGroupChildren(t[n]),i);return r||(n+1!==t.length?this.findNextOption({group:n+1,option:-1}):null)}return this.findNextOptionInList(t,e)}},{key:"findNextOptionInList",value:function(e,t){var n=t+1;if(n===e.length)return null;var i=e[n];return this.isOptionDisabled(i)?this.findNextOptionInList(n):i}},{key:"findPrevOption",value:function(e){if(-1===e)return null;var t=this.getVisibleOptions();if(this.props.optionGroupLabel){var n=e.group,i=e.option,r=this.findPrevOptionInList(this.getOptionGroupChildren(t[n]),i);return r||(n>0?this.findPrevOption({group:n-1,option:this.getOptionGroupChildren(t[n-1]).length}):null)}return this.findPrevOptionInList(t,e)}},{key:"findPrevOptionInList",value:function(e,t){var n=t-1;if(n<0)return null;var i=e[n];return this.isOptionDisabled(i)?this.findPrevOption(n):i}},{key:"search",value:function(e){var t=this;this.searchTimeout&&clearTimeout(this.searchTimeout);var n=e.key;if(this.previousSearchChar=this.currentSearchChar,this.currentSearchChar=n,this.searchValue=this.previousSearchChar===this.currentSearchChar?this.currentSearchChar:this.searchValue?this.searchValue+n:n,this.searchValue){var i=this.getSelectedOptionIndex(),r=this.props.optionGroupLabel?this.searchOptionInGroup(i):this.searchOption(++i);r&&(this.selectItem({originalEvent:e,option:r}),this.selectedOptionUpdated=!0)}this.searchTimeout=setTimeout((function(){t.searchValue=null}),250)}},{key:"searchOption",value:function(e){var t;if(this.searchValue){var n=this.getVisibleOptions();(t=this.searchOptionInRange(e,n.length))||(t=this.searchOptionInRange(0,e))}return t}},{key:"searchOptionInRange",value:function(e,t){for(var n=this.getVisibleOptions(),i=e;i<t;i++){var r=n[i];if(this.matchesSearchValue(r))return r}return null}},{key:"searchOptionInGroup",value:function(e){for(var t=-1===e?{group:0,option:-1}:e,n=this.getVisibleOptions(),i=t.group;i<n.length;i++)for(var r=this.getOptionGroupChildren(n[i]),o=t.group===i?t.option+1:0;o<r.length;o++)if(this.matchesSearchValue(r[o]))return r[o];for(var s=0;s<=t.group;s++)for(var l=this.getOptionGroupChildren(n[s]),p=0;p<(t.group===s?t.option:l.length);p++)if(this.matchesSearchValue(l[p]))return l[p];return null}},{key:"matchesSearchValue",value:function(e){return this.getOptionLabel(e).toLocaleLowerCase(this.props.filterLocale).startsWith(this.searchValue.toLocaleLowerCase(this.props.filterLocale))}},{key:"onEditableInputChange",value:function(e){this.props.onChange&&this.props.onChange({originalEvent:e.originalEvent,value:e.target.value,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:e.target.value}})}},{key:"onEditableInputFocus",value:function(e){var t=this;e.persist(),this.setState({focused:!0},(function(){t.hideOverlay(),t.props.onFocus&&t.props.onFocus(e)}))}},{key:"onOptionClick",value:function(e){e.option.disabled||(this.selectItem(e),this.focusInput.focus()),this.hideOverlay()}},{key:"onFilterInputChange",value:function(e){var t=this,n=e.target.value;this.setState({filter:n},(function(){t.props.onFilter&&t.props.onFilter({originalEvent:e,filter:n})}))}},{key:"onFilterClearIconClick",value:function(e){this.resetFilter(e)}},{key:"resetFilter",value:function(e){var t=this;this.setState({filter:""},(function(){t.props.onFilter&&t.props.onFilter({filter:""}),e&&e()}))}},{key:"clear",value:function(e){this.props.onChange&&this.props.onChange({originalEvent:e,value:void 0,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:void 0}}),this.updateEditableLabel()}},{key:"selectItem",value:function(e){if(this.getSelectedOption()!==e.option){this.updateEditableLabel(e.option);var t=this.getOptionValue(e.option);this.props.onChange&&this.props.onChange({originalEvent:e.originalEvent,value:t,stopPropagation:function(){},preventDefault:function(){},target:{name:this.props.name,id:this.props.id,value:t}})}}},{key:"getSelectedOption",value:function(){var e=this.getSelectedOptionIndex(),t=this.getVisibleOptions();return-1!==e?this.props.optionGroupLabel?this.getOptionGroupChildren(t[e.group])[e.option]:t[e]:null}},{key:"getSelectedOptionIndex",value:function(){var e=this.getVisibleOptions();if(null!=this.props.value&&e){if(!this.props.optionGroupLabel)return this.findOptionIndexInList(this.props.value,e);for(var t=0;t<e.length;t++){var n=this.findOptionIndexInList(this.props.value,this.getOptionGroupChildren(e[t]));if(-1!==n)return{group:t,option:n}}}return-1}},{key:"findOptionIndexInList",value:function(e,t){for(var n=this.equalityKey(),i=0;i<t.length;i++)if(r.equals(e,this.getOptionValue(t[i]),n))return i;return-1}},{key:"isSelected",value:function(e){return r.equals(this.props.value,this.getOptionValue(e),this.equalityKey())}},{key:"equalityKey",value:function(){return this.props.optionValue?null:this.props.dataKey}},{key:"showOverlay",value:function(){this.setState({overlayVisible:!0})}},{key:"hideOverlay",value:function(){this.setState({overlayVisible:!1})}},{key:"onOverlayEnter",value:function(e){s.set("overlay",this.overlayRef.current,h.autoZIndex,h.zIndex.overlay),this.alignOverlay(),e&&e()}},{key:"onOverlayEntered",value:function(e){e&&e(),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(){o.alignOverlay(this.overlayRef.current,this.input.parentElement,this.props.appendTo||h.appendTo)}},{key:"scrollInView",value:function(){var e=o.findSingle(this.overlayRef.current,"li.p-highlight");e&&e.scrollIntoView({block:"nearest",inline:"start"})}},{key:"bindDocumentClickListener",value:function(){var e=this;this.documentClickListener||(this.documentClickListener=function(t){e.state.overlayVisible&&e.isOutsideClicked(t)&&e.hideOverlay()},document.addEventListener("click",this.documentClickListener))}},{key:"unbindDocumentClickListener",value:function(){this.documentClickListener&&(document.removeEventListener("click",this.documentClickListener),this.documentClickListener=null)}},{key:"bindScrollListener",value:function(){var e=this;this.scrollHandler||(this.scrollHandler=new l(this.container,(function(){e.state.overlayVisible&&e.hideOverlay()}))),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&&!o.isTouchDevice()&&e.hideOverlay()},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.overlayRef&&this.overlayRef.current.contains(e.target))}},{key:"isClearClicked",value:function(e){return o.hasClass(e.target,"p-dropdown-clear-icon")||o.hasClass(e.target,"p-dropdown-filter-clear-icon")}},{key:"updateEditableLabel",value:function(e){this.input&&(this.input.value=e?this.getOptionLabel(e):this.props.value||"")}},{key:"hasFilter",value:function(){return this.state.filter&&this.state.filter.trim().length>0}},{key:"getOptionLabel",value:function(e){return this.props.optionLabel?r.resolveFieldData(e,this.props.optionLabel):e&&void 0!==e.label?e.label:e}},{key:"getOptionValue",value:function(e){return this.props.optionValue?r.resolveFieldData(e,this.props.optionValue):e&&void 0!==e.value?e.value:e}},{key:"getOptionRenderKey",value:function(e){return this.props.dataKey?r.resolveFieldData(e,this.props.dataKey):this.getOptionLabel(e)}},{key:"isOptionDisabled",value:function(e){return this.props.optionDisabled?r.isFunction(this.props.optionDisabled)?this.props.optionDisabled(e):r.resolveFieldData(e,this.props.optionDisabled):!(!e||void 0===e.disabled)&&e.disabled}},{key:"getOptionGroupRenderKey",value:function(e){return r.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupLabel",value:function(e){return r.resolveFieldData(e,this.props.optionGroupLabel)}},{key:"getOptionGroupChildren",value:function(e){return r.resolveFieldData(e,this.props.optionGroupChildren)}},{key:"checkValidity",value:function(){return!!this.inputRef.current&&this.inputRef.current.checkValidity()}},{key:"isLazy",value:function(){return this.props.virtualScrollerOptions&&this.props.virtualScrollerOptions.lazy}},{key:"getVisibleOptions",value:function(){if(this.hasFilter()&&!this.isLazy()){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=T(this.props.options);try{for(r.s();!(n=r.n()).done;){var o=n.value,s=f.filter(this.getOptionGroupChildren(o),t,e,this.props.filterMatchMode,this.props.filterLocale);s&&s.length&&i.push(N(N({},o),{items:s}))}}catch(e){r.e(e)}finally{r.f()}return i}return f.filter(this.props.options,t,e,this.props.filterMatchMode,this.props.filterLocale)}return this.props.options}},{key:"updateInputField",value:function(){if(this.props.editable&&this.input){var e=this.getSelectedOption(),t=e?this.getOptionLabel(e):null;this.input.value=t||this.props.value||""}}},{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.autoFocus&&this.focusInput&&this.focusInput.focus(),this.props.tooltip&&this.renderTooltip(),this.updateInputField(),this.inputRef.current&&(this.inputRef.current.selectedIndex=1)}},{key:"componentWillUnmount",value:function(){this.unbindDocumentClickListener(),this.unbindResizeListener(),this.scrollHandler&&(this.scrollHandler.destroy(),this.scrollHandler=null),this.tooltip&&(this.tooltip.destroy(),this.tooltip=null),this.hideTimeout&&(clearTimeout(this.hideTimeout),this.hideTimeout=null),s.clear(this.overlayRef.current)}},{key:"componentDidUpdate",value:function(e){this.state.overlayVisible&&(this.props.filter&&this.alignOverlay(),e.value!==this.props.value&&this.scrollInView()),e.tooltip===this.props.tooltip&&e.tooltipOptions===this.props.tooltipOptions||(this.tooltip?this.tooltip.update(N({content:this.props.tooltip},this.props.tooltipOptions||{})):this.renderTooltip()),!this.state.filter||this.props.options&&0!==this.props.options.length||this.setState({filter:""}),this.updateInputField(),this.inputRef.current&&(this.inputRef.current.selectedIndex=1)}},{key:"renderHiddenSelect",value:function(t){var n=e.createElement("option",{value:""},this.props.placeholder),i=t?e.createElement("option",{value:t.value},this.getOptionLabel(t)):null;return e.createElement("div",{className:"p-hidden-accessible p-dropdown-hidden-select"},e.createElement("select",{ref:this.inputRef,required:this.props.required,name:this.props.name,tabIndex:-1,"aria-hidden":"true"},n,i))}},{key:"renderTooltip",value:function(){this.tooltip=v({target:this.container,content:this.props.tooltip,options:this.props.tooltipOptions})}},{key:"renderKeyboardHelper",value:function(){var t=this;return e.createElement("div",{className:"p-hidden-accessible"},e.createElement("input",{ref:function(e){return t.focusInput=e},id:this.props.inputId,type:"text",readOnly:!0,"aria-haspopup":"listbox",onFocus:this.onInputFocus,onBlur:this.onInputBlur,onKeyDown:this.onInputKeyDown,disabled:this.props.disabled,tabIndex:this.props.tabIndex,"aria-label":this.props.ariaLabel,"aria-labelledby":this.props.ariaLabelledBy}))}},{key:"renderLabel",value:function(t){var n=this,o=r.isNotEmpty(t)?this.getOptionLabel(t):null;if(this.props.editable)return e.createElement("input",{ref:function(e){return n.input=e},type:"text",defaultValue:o||this.props.value||"",className:"p-dropdown-label p-inputtext",disabled:this.props.disabled,placeholder:this.props.placeholder,maxLength:this.props.maxLength,onInput:this.onEditableInputChange,onFocus:this.onEditableInputFocus,onBlur:this.onInputBlur,"aria-label":this.props.ariaLabel,"aria-labelledby":this.props.ariaLabelledBy,"aria-haspopup":"listbox"});var s=i("p-dropdown-label p-inputtext",{"p-placeholder":null===o&&this.props.placeholder,"p-dropdown-label-empty":null===o&&!this.props.placeholder}),l=this.props.valueTemplate?r.getJSXElement(this.props.valueTemplate,t,this.props):o||this.props.placeholder||"empty";return e.createElement("span",{ref:function(e){return n.input=e},className:s},l)}},{key:"renderClearIcon",value:function(){return null!=this.props.value&&this.props.showClear&&!this.props.disabled?e.createElement("i",{className:"p-dropdown-clear-icon pi pi-times",onClick:this.clear}):null}},{key:"renderDropdownIcon",value:function(){var t=this,n=i("p-dropdown-trigger-icon p-clickable",this.props.dropdownIcon);return e.createElement("div",{ref:function(e){return t.trigger=e},className:"p-dropdown-trigger",role:"button","aria-haspopup":"listbox","aria-expanded":this.state.overlayVisible},e.createElement("span",{className:n}))}},{key:"render",value:function(){var t=this,n=i("p-dropdown p-component p-inputwrapper",this.props.className,{"p-disabled":this.props.disabled,"p-focus":this.state.focused,"p-dropdown-clearable":this.props.showClear&&!this.props.disabled,"p-inputwrapper-filled":this.props.value,"p-inputwrapper-focus":this.state.focused||this.state.overlayVisible}),r=this.getVisibleOptions(),o=this.getSelectedOption(),s=this.props.appendTo||h.appendTo,l=this.renderHiddenSelect(o),p=this.renderKeyboardHelper(),a=this.renderLabel(o),u=this.renderDropdownIcon(),c=this.renderClearIcon();return e.createElement("div",{id:this.props.id,ref:function(e){return t.container=e},className:n,style:this.props.style,onClick:this.onClick,onMouseDown:this.props.onMouseDown,onContextMenu:this.props.onContextMenu},p,l,a,c,u,e.createElement(G,b({ref:this.overlayRef,visibleOptions:r},this.props,{appendTo:s,onClick:this.onPanelClick,onOptionClick:this.onOptionClick,filterValue:this.state.filter,hasFilter:this.hasFilter,onFilterClearIconClick:this.onFilterClearIconClick,onFilterInputKeyDown:this.onFilterInputKeyDown,onFilterInputChange:this.onFilterInputChange,getOptionLabel:this.getOptionLabel,getOptionRenderKey:this.getOptionRenderKey,isOptionDisabled:this.isOptionDisabled,getOptionGroupChildren:this.getOptionGroupChildren,getOptionGroupLabel:this.getOptionGroupLabel,getOptionGroupRenderKey:this.getOptionGroupRenderKey,isSelected:this.isSelected,getSelectedOptionIndex:this.getSelectedOptionIndex,in:this.state.overlayVisible,onEnter:this.onOverlayEnter,onEntered:this.onOverlayEntered,onExit:this.onOverlayExit,onExited:this.onOverlayExited})))}}]),d}();F(H,"defaultProps",{id:null,inputRef:null,name:null,value:null,options:null,optionLabel:null,optionValue:null,optionDisabled:null,optionGroupLabel:null,optionGroupChildren:null,optionGroupTemplate:null,valueTemplate:null,itemTemplate:null,style:null,className:null,virtualScrollerOptions:null,scrollHeight:"200px",filter:!1,filterBy:null,filterMatchMode:"contains",filterPlaceholder:null,filterLocale:void 0,emptyMessage:null,emptyFilterMessage:null,editable:!1,placeholder:null,required:!1,disabled:!1,appendTo:null,tabIndex:null,autoFocus:!1,filterInputAutoFocus:!0,resetFilterOnHide:!1,showFilterClear:!1,panelClassName:null,panelStyle:null,dataKey:null,inputId:null,showClear:!1,maxLength:null,tooltip:null,tooltipOptions:null,ariaLabel:null,ariaLabelledBy:null,transitionOptions:null,dropdownIcon:"pi pi-chevron-down",showOnFocus:!1,onChange:null,onFocus:null,onBlur:null,onMouseDown:null,onContextMenu:null,onShow:null,onHide:null,onFilter:null});export{H as Dropdown};