UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime

2 lines (1 loc) 32.9 kB
import*as e from"react";import t,{PrimeReactContext as n,localeOption as r,FilterService as o}from"primereact/api";import{ComponentBase as l,useHandleStyle as i}from"primereact/componentbase";import{useMergeProps as a,useOverlayListener as u,useMountEffect as c,useUpdateEffect as p,useUnmountEffect as s}from"primereact/hooks";import{ChevronDownIcon as d}from"primereact/icons/chevrondown";import{ChevronUpIcon as f}from"primereact/icons/chevronup";import{SpinnerIcon as m}from"primereact/icons/spinner";import{TimesIcon as v}from"primereact/icons/times";import{OverlayService as b}from"primereact/overlayservice";import{Tooltip as g}from"primereact/tooltip";import{classNames as h,ObjectUtils as y,DomHandler as w,IconUtils as O,ZIndexUtils as I}from"primereact/utils";import{CSSTransition as E}from"primereact/csstransition";import{SearchIcon as x}from"primereact/icons/search";import{Portal as S}from"primereact/portal";import{VirtualScroller as F}from"primereact/virtualscroller";import{Ripple as D}from"primereact/ripple";import{CheckIcon as k}from"primereact/icons/check";import{IconBase as C}from"primereact/iconbase";function N(){return N=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},N.apply(this,arguments)}function L(e){return L="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},L(e)}function P(e,t){if("object"!==L(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!==L(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function j(e){var t=P(e,"string");return"symbol"===L(t)?t:String(t)}function T(e,t,n){return(t=j(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e){if(Array.isArray(e))return e}function M(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,l,i,a=[],u=!0,c=!1;try{if(l=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;u=!1}else for(;!(u=(r=l.call(n)).done)&&(a.push(r.value),a.length!==t);u=!0);}catch(e){c=!0,o=e}finally{try{if(!u&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function G(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function A(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 K(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function V(e,t){return R(e)||M(e,t)||A(e,t)||K()}function H(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function B(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?H(Object(n),!0).forEach((function(t){T(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):H(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var _=l.extend({defaultProps:{__TYPE:"Dropdown",__parentMetadata:null,appendTo:null,ariaLabel:null,ariaLabelledBy:null,autoFocus:!1,children:void 0,className:null,clearIcon:null,dataKey:null,disabled:!1,dropdownIcon:null,collapseIcon:null,editable:!1,emptyFilterMessage:null,highlightOnSelect:!0,checkmark:!1,emptyMessage:null,filter:!1,filterBy:null,filterClearIcon:null,filterIcon:null,filterInputAutoFocus:!1,filterLocale:void 0,filterMatchMode:"contains",filterPlaceholder:null,filterTemplate:null,focusInputRef:null,id:null,inputId:null,inputRef:null,invalid:!1,variant:null,itemTemplate:null,loading:!1,loadingIcon:null,maxLength:null,name:null,onBlur:null,onChange:null,onContextMenu:null,onFilter:null,onFocus:null,onHide:null,onMouseDown:null,onShow:null,optionDisabled:null,optionGroupChildren:"items",selectOnFocus:!1,focusOnHover:!0,autoOptionFocus:!1,optionGroupLabel:null,optionGroupTemplate:null,optionLabel:null,optionValue:null,options:null,panelClassName:null,panelFooterTemplate:null,panelStyle:null,placeholder:null,required:!1,resetFilterOnHide:!1,scrollHeight:"200px",showClear:!1,showFilterClear:!1,showOnFocus:!1,style:null,tabIndex:null,tooltip:null,tooltipOptions:null,transitionOptions:null,value:null,valueTemplate:null,virtualScrollerOptions:null},css:{classes:{root:function(e){var t=e.props,n=e.focusedState,r=e.overlayVisibleState,o=e.context;return h("p-dropdown p-component p-inputwrapper",{"p-disabled":t.disabled,"p-invalid":t.invalid,"p-focus":n,"p-variant-filled":t.variant?"filled"===t.variant:o&&"filled"===o.inputStyle,"p-dropdown-clearable":t.showClear&&!t.disabled,"p-inputwrapper-filled":y.isNotEmpty(t.value),"p-inputwrapper-focus":n||r})},input:function(e){var t=e.props,n=e.label;return t.editable?"p-dropdown-label p-inputtext":h("p-dropdown-label p-inputtext",{"p-placeholder":null===n&&t.placeholder,"p-dropdown-label-empty":null===n&&!t.placeholder})},trigger:"p-dropdown-trigger",emptyMessage:"p-dropdown-empty-message",itemGroup:function(e){var t=e.optionGroupLabel;return h("p-dropdown-item-group",{"p-dropdown-item-empty":!t||0===t.length})},itemGroupLabel:"p-dropdown-item-group-label",dropdownIcon:"p-dropdown-trigger-icon p-clickable",loadingIcon:"p-dropdown-trigger-icon p-clickable",clearIcon:"p-dropdown-clear-icon p-clickable",filterIcon:"p-dropdown-filter-icon",filterClearIcon:"p-dropdown-filter-clear-icon",filterContainer:function(e){return h("p-dropdown-filter-container",{"p-dropdown-clearable-filter":!!e.clearIcon})},filterInput:function(e){var t=e.props,n=e.context;return h("p-dropdown-filter p-inputtext p-component",{"p-variant-filled":t.variant?"filled"===t.variant:n&&"filled"===n.inputStyle})},list:function(e){return"p-dropdown-items"},panel:function(e){var n=e.context;return h("p-dropdown-panel p-component",{"p-input-filled":n&&"filled"===n.inputStyle||"filled"===t.inputStyle,"p-ripple-disabled":n&&!1===n.ripple||!1===t.ripple})},item:function(e){var t=e.label;return h("p-dropdown-item",{"p-highlight":e.selected&&e.highlightOnSelect,"p-disabled":e.disabled,"p-focus":e.index===e.focusedOptionIndex,"p-dropdown-item-empty":!t||0===t.length})},itemLabel:"p-dropdown-item-label",checkIcon:"p-dropdown-check-icon",blankIcon:"p-dropdown-blank-icon",wrapper:"p-dropdown-items-wrapper",header:"p-dropdown-header",footer:"p-dropdown-footer",transition:"p-connected-overlay"},styles:"\n@layer primereact {\n .p-dropdown {\n display: inline-flex;\n cursor: pointer;\n position: relative;\n user-select: none;\n }\n \n .p-dropdown-trigger {\n display: flex;\n align-items: center;\n justify-content: center;\n flex-shrink: 0;\n }\n \n .p-dropdown-label {\n display: block;\n white-space: nowrap;\n overflow: hidden;\n flex: 1 1 auto;\n width: 1%;\n text-overflow: ellipsis;\n cursor: pointer;\n }\n \n .p-dropdown-label-empty {\n overflow: hidden;\n visibility: hidden;\n }\n \n input.p-dropdown-label {\n cursor: default;\n }\n \n .p-dropdown .p-dropdown-panel {\n min-width: 100%;\n }\n \n .p-dropdown-panel {\n position: absolute;\n top: 0;\n left: 0;\n }\n \n .p-dropdown-items-wrapper {\n overflow: auto;\n }\n \n .p-dropdown-item {\n cursor: pointer;\n font-weight: normal;\n white-space: nowrap;\n position: relative;\n overflow: hidden;\n }\n \n .p-dropdown-items {\n margin: 0;\n padding: 0;\n list-style-type: none;\n }\n \n .p-dropdown-filter {\n width: 100%;\n }\n \n .p-dropdown-filter-container {\n position: relative;\n }\n \n .p-dropdown-clear-icon,\n .p-dropdown-filter-icon,\n .p-dropdown-filter-clear-icon {\n position: absolute;\n top: 50%;\n margin-top: -.5rem;\n right: 2rem;\n }\n \n .p-fluid .p-dropdown {\n display: flex;\n }\n \n .p-fluid .p-dropdown .p-dropdown-label {\n width: 1%;\n }\n}\n",inlineStyles:{wrapper:function(e){return{maxHeight:e.props.scrollHeight||"auto"}},panel:function(e){return B({},e.props.panelStyle)}}}}),J=e.memo(e.forwardRef((function(t,n){var r=C.getPTI(t);return e.createElement("svg",N({ref:n,width:"14",height:"14",viewBox:"0 0 14 14",fill:"none",xmlns:"http://www.w3.org/2000/svg"},r),e.createElement("rect",{width:"1",height:"1",fill:"currentColor",fillOpacity:"0"}))})));J.displayName="BlankIcon";var X=e.memo((function(t){var n=a(),r=t.ptm,o=t.cx,l=t.selected,i=t.disabled,u=t.option,c=t.label,p=t.index,s=t.focusedOptionIndex,d=t.ariaSetSize,f=t.checkmark,m=t.highlightOnSelect,v=t.onInputKeyDown,b=function(e){return r(e,{context:{selected:l,disabled:i,focused:p===s}})},g=t.template?y.getJSXElement(t.template,t.option):t.label,w=n({id:"dropdownItem_".concat(p),role:"option",key:t.label,className:h(u.className,o("item",{selected:l,disabled:i,label:c,index:p,focusedOptionIndex:s,highlightOnSelect:m})),style:t.style,tabIndex:0,onClick:function(e){return n=e,void(t.onClick&&t.onClick({originalEvent:n,option:u}));var n},onKeyDown:function(e){return v(e)},onMouseMove:function(e){return null==t?void 0:t.onMouseMove(e,p)},"aria-setsize":d,"aria-posinset":p+1,"aria-label":c,"aria-selected":l,"data-p-highlight":l,"data-p-focused":s===p,"data-p-disabled":i},b("item")),O=n({className:o("itemLabel")},b("itemLabel"));return e.createElement("li",w,f&&function(){if(l){var t=n({className:o("checkIcon")},b("checkIcon"));return e.createElement(k,t)}var r=n({className:o("blankIcon")},b("blankIcon"));return e.createElement(J,r)}(),e.createElement("span",O,g),e.createElement(D,null))}));function z(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function U(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){T(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}X.displayName="DropdownItem";var q=e.memo(e.forwardRef((function(t,o){var l,i,u,c,p,s=a(),d=t.ptm,f=t.cx,m=t.sx,b=e.useContext(n),g=e.useRef(null),I=!(t.visibleOptions&&t.visibleOptions.length)&&t.hasFilter,D=t.visibleOptions?t.visibleOptions.length:0,k={filter:function(e){return j(e)},reset:function(){return t.resetFilter()}},C=function(e,n){return d(e,U({hostName:t.hostName},n))},L=function(){t.onEnter((function(){if(t.virtualScrollerRef.current){var e=t.getSelectedOptionIndex();-1!==e&&setTimeout((function(){return t.virtualScrollerRef.current.scrollToIndex(e)}),0)}}))},P=function(){t.onEntered((function(){t.filter&&t.filterInputAutoFocus&&w.focus(g.current,!1)}))},j=function(e){t.onFilterInputChange&&t.onFilterInputChange(e)},T=function(){if(t.panelFooterTemplate){var n=y.getJSXElement(t.panelFooterTemplate,t,t.onOverlayHide),r=s({className:f("footer")},C("footer"));return e.createElement("div",r,n)}return null},R=function(e,n){var r;t.focusOnHover&&(null==t||null===(r=t.changeFocusedOptionIndex)||void 0===r||r.call(t,e,n))},M=function(n,o){var l=y.getJSXElement(n,t)||r(o?"emptyFilterMessage":"emptyMessage"),i=s({className:f("emptyMessage")},C("emptyMessage"));return e.createElement("li",i,l)},G=function(n,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},l={height:o.props?o.props.itemSize:void 0};if(l=U(U({},l),n.style),n.group&&t.optionGroupLabel){var i=t.optionGroupLabel,a=t.optionGroupTemplate?y.getJSXElement(t.optionGroupTemplate,n,r):t.getOptionGroupLabel(n),u=r+"_"+t.getOptionGroupRenderKey(n),c=s({className:f("itemGroup",{optionGroupLabel:i}),style:l,"data-p-highlight":t.selected},C("itemGroup")),p=s({className:f("itemGroupLabel")},C("itemGroupLabel"));return e.createElement("li",N({key:u},c),e.createElement("span",p,a))}var m=t.getOptionRenderKey(n)+"_"+r,v=t.getOptionLabel(n),b=t.isOptionDisabled(n);return e.createElement(X,{key:m,label:v,index:r,focusedOptionIndex:t.focusedOptionIndex,option:n,ariaSetSize:D,onInputKeyDown:t.onInputKeyDown,style:l,template:t.itemTemplate,selected:t.isSelected(n),highlightOnSelect:t.highlightOnSelect,disabled:b,onClick:t.onOptionClick,onMouseMove:R,ptm:d,cx:f,checkmark:t.checkmark})},A=function(){if(t.showFilterClear&&t.filterValue){var n=r("clear"),o=s({className:f("filterClearIcon"),"aria-label":n,onClick:function(){return t.onFilterClearIconClick((function(){return w.focus(g.current)}))}},C("filterClearIcon"));return O.getJSXIcon(t.filterClearIcon||e.createElement(v,o),U({},o),{props:t})}return null},K=function(){if(t.filter){var n=A(),r=s({className:f("filterIcon")},C("filterIcon")),o=O.getJSXIcon(t.filterIcon||e.createElement(x,r),U({},r),{props:t}),l=s({className:f("filterContainer",{clearIcon:n})},C("filterContainer")),i=s({ref:g,type:"text",autoComplete:"off",className:f("filterInput",{context:b}),placeholder:t.filterPlaceholder,onKeyDown:t.onFilterInputKeyDown,onChange:function(e){return j(e)},value:t.filterValue},C("filterInput")),a=e.createElement("div",l,e.createElement("input",i),n,o);if(t.filterTemplate){var u={className:h("p-dropdown-filter-container",{"p-dropdown-clearable-filter":!!n}),element:a,filterOptions:k,filterInputKeyDown:t.onFilterInputKeyDown,filterInputChange:j,filterIconClassName:"p-dropdown-filter-icon",clearIcon:n,props:t};a=y.getJSXElement(t.filterTemplate,u)}var c=s({className:f("header")},C("header"));return e.createElement("div",c,a)}return null},V=function(){if(t.virtualScrollerOptions){var n=U(U({},t.virtualScrollerOptions),{style:U(U({},t.virtualScrollerOptions.style),{height:t.scrollHeight}),className:h("p-dropdown-items-wrapper",t.virtualScrollerOptions.className),items:t.visibleOptions,autoSize:!0,onLazyLoad:function(e){return t.virtualScrollerOptions.onLazyLoad(U(U({},e),{filter:t.filterValue}))},itemTemplate:function(e,t){return e&&G(e,t.index,t)},contentTemplate:function(n){var r=I?M(t.hasFilter?t.emptyFilterMessage:t.emptyMessage):n.children,o=s({ref:n.contentRef,style:n.style,className:h(n.className,f("list",{virtualScrollerProps:t.virtualScrollerOptions})),role:"listbox"},C("list"));return e.createElement("ul",o,r)}});return e.createElement(F,N({ref:t.virtualScrollerRef},n,{pt:d("virtualScroller")}))}var r=y.isNotEmpty(t.visibleOptions)?t.visibleOptions.map(G):t.hasFilter?M(t.emptyFilterMessage,!0):M(t.emptyMessage),o=s({className:f("wrapper"),style:m("wrapper")},C("wrapper")),l=s({className:f("list"),role:"listbox"},C("list"));return e.createElement("div",o,e.createElement("ul",l,r))},H=(l=K(),i=V(),u=T(),c=s({className:h(t.panelClassName,f("panel",{context:b})),style:m("panel"),onClick:t.onClick},C("panel")),p=s({classNames:f("transition"),in:t.in,timeout:{enter:120,exit:100},options:t.transitionOptions,unmountOnExit:!0,onEnter:L,onEntered:P,onExit:t.onExit,onExited:t.onExited},C("transition")),e.createElement(E,N({nodeRef:o},p),e.createElement("div",N({ref:o},c),t.firstFocusableElement,l,i,u,t.lastFocusableElement)));return e.createElement(S,{element:H,appendTo:t.appendTo})})));function W(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=Z(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}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 l,i=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return i=e.done,e},e:function(e){a=!0,l=e},f:function(){try{i||null==n.return||n.return()}finally{if(a)throw l}}}}function Z(e,t){if(e){if("string"==typeof e)return $(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)?$(e,t):void 0}}function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function Y(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Q(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Y(Object(n),!0).forEach((function(t){T(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Y(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}q.displayName="DropdownPanel";var ee=e.memo(e.forwardRef((function(l,E){var x=a(),S=e.useContext(n),F=_.getProps(l,S),D=V(e.useState(""),2),k=D[0],C=D[1],P=V(e.useState(!1),2),j=P[0],R=P[1],M=V(e.useState(-1),2),G=M[0],A=M[1],K=V(e.useState(!1),2),H=K[0],B=K[1],J=e.useRef(!1),X=e.useRef(null),z=e.useRef(null),U=e.useRef(null),Z=e.useRef(null),$=e.useRef(F.inputRef),Y=e.useRef(F.focusInputRef),ee=e.useRef(null),te=e.useRef(null),ne=e.useRef(null),re=F.virtualScrollerOptions&&F.virtualScrollerOptions.lazy,oe=y.isNotEmpty(k),le=F.appendTo||S&&S.appendTo||t.appendTo,ie=_.setMetaData(Q(Q({props:F},F.__parentMetadata),{},{state:{filter:k,focused:j,overlayVisible:H}})),ae=ie.ptm,ue=ie.cx,ce=ie.sx;i(_.css.styles,ie.isUnstyled,{name:"dropdown"});var pe=V(u({target:X,overlay:z,listener:function(e,t){t.valid&&("outside"===t.type?!me(e)&&Ye():Ye())},when:H}),2),se=pe[0],de=pe[1],fe=function(e){return(e||[]).reduce((function(e,t,n){e.push(Q(Q({},t),{},{group:!0,index:n}));var r=it(t);return r&&r.forEach((function(t){return e.push(t)})),e}),[])},me=function(e){return w.isAttributeEquals(e.target,"data-pc-section","clearicon")||w.isAttributeEquals(e.target.parentElement||e.target,"data-pc-section","filterclearicon")},ve=function(e){F.showOnFocus&&!H&&$e(),R(!0),F.onFocus&&F.onFocus(e)},be=function(e){R(!1),F.onBlur&&setTimeout((function(){var t=$.current?$.current.value:void 0;F.onBlur({originalEvent:e.originalEvent,value:t,stopPropagation:function(){e.originalEvent.stopPropagation()},preventDefault:function(){e.originalEvent.preventDefault()},target:{name:F.name,id:F.id,value:t}})}),200)},ge=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r=rt(t);ze({originalEvent:e,option:r}),n&&Ye()},he=function(e){if(F.disabled)e.preventDefault();else{var t=e.metaKey||e.ctrlKey;switch(w.isAndroid()?e.key:e.code){case"ArrowDown":Ne(e);break;case"ArrowUp":Le(e);break;case"ArrowLeft":case"ArrowRight":Pe(e,F.editable);break;case"Home":je(e);break;case"End":Te(e);break;case"PageDown":Me(e);break;case"PageUp":Re(e);break;case"Space":Ge(e,F.editable);break;case"NumpadEnter":case"Enter":Ae(e);break;case"Escape":Ke(e);break;case"Tab":Ve(e);break;case"Backspace":He(e,F.editable);break;case"ShiftLeft":case"ShiftRight":break;default:!t&&y.isPrintableCharacter(e.key)&&(!H&&!F.editable&&$e(),!F.editable&&Se(e,e.key))}J.current=!1}},ye=function(e){var t;return we(e)&&(null===(t=nt(e))||void 0===t?void 0:t.toLocaleLowerCase(F.filterLocale).startsWith(ne.current.toLocaleLowerCase(F.filterLocale)))},we=function(e){return y.isNotEmpty(e)&&!(lt(e)||ot(e))},Oe=function(){return y.isNotEmpty(F.value)},Ie=function(e){return we(e)&&Ze(e)},Ee=function(){return Oe?mt.findIndex((function(e){return Ie(e)})):-1},xe=function(){var e=Ee();return e<0?Fe():e},Se=function(e,t){ne.current=(ne.current||"")+t;var n=-1,r=!1;return y.isNotEmpty(ne.current)&&(-1!==(n=-1!==G?-1===(n=mt.slice(G).findIndex((function(e){return ye(e)})))?mt.slice(0,G).findIndex((function(e){return ye(e)})):n+G:mt.findIndex((function(e){return ye(e)})))&&(r=!0),-1===n&&-1===G&&(n=xe()),-1!==n&&ke(e,n)),te.current&&clearTimeout(te.current),te.current=setTimeout((function(){ne.current="",te.current=null}),500),r},Fe=function(){return mt.findIndex((function(e){return we(e)}))},De=function(){return y.findLastIndex(mt,(function(e){return we(e)}))},ke=function(e,t){G!==t&&(A(t),Ce(t),F.selectOnFocus&&ge(e,mt[t],!1))},Ce=function(e){var t=w.findSingle(z.current,'li[id="dropdownItem_'.concat(e,'"]'));t&&t.focus()},Ne=function(e){if(H){var t=-1!==G?(r=(n=G)<mt.length-1?mt.slice(n+1).findIndex((function(e){return we(e)})):-1)>-1?r+n+1:n:J.current?Fe():xe();ke(e,t)}else $e(),F.editable&&ke(e,Ee());var n,r;e.preventDefault()},Le=function(e){var t,n,r;if(e.altKey&&!(arguments.length>1&&void 0!==arguments[1]&&arguments[1]))-1!==G&&ge(e,mt[G]),state.overlayVisible&&Ye(),e.preventDefault();else{var o=-1!==G?(r=(n=G)>0?y.findLastIndex(mt.slice(0,n),(function(e){return we(e)})):-1)>-1?r:n:J.current?De():(t=Ee())<0?De():t;ke(e,o),!H&&$e(),e.preventDefault()}},Pe=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]&&A(-1)},je=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]?(e.currentTarget.setSelectionRange(0,0),A(-1)):(ke(e,Fe()),!H&&$e()),e.preventDefault()},Te=function(e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1]){var t=e.currentTarget,n=t.value.length;t.setSelectionRange(n,n),A(-1)}else ke(e,De()),!H&&$e();e.preventDefault()},Re=function(e){e.preventDefault()},Me=function(e){e.preventDefault()},Ge=function(e){!(arguments.length>1&&void 0!==arguments[1]&&arguments[1])&&Ae(e)},Ae=function(e){H?(-1!==G&&ge(e,mt[G]),Ye()):(A(-1),Ne(e)),e.preventDefault()},Ke=function(e){H&&Ye(),e.preventDefault()},Ve=function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1]||(!H||w.getFocusableElements(z.current,':not([data-p-hidden-focusable="true"])').length>0?(-1!==G&&ge(e,mt[G]),H&&Ye()):(w.focus(U.current),e.preventDefault()))},He=function(e){e&&(arguments.length>1&&void 0!==arguments[1]&&arguments[1])&&!H&&$e()},Be=function(e){!H&&$e();var t=null;e.target.value&&mt&&(t=mt.findIndex((function(t){return nt(t).toLocaleLowerCase().startsWith(e.target.value.toLocaleLowerCase())}))),A(t),F.onChange&&F.onChange({originalEvent:e.originalEvent,value:e.target.value,stopPropagation:function(){e.originalEvent.stopPropagation()},preventDefault:function(){e.originalEvent.preventDefault()},target:{name:F.name,id:F.id,value:e.target.value}})},_e=function(e){R(!0),Ye(),F.onFocus&&F.onFocus(e)},Je=function(e){C(""),F.onFilter&&F.onFilter({filter:""}),e&&e()},Xe=function(e){F.onChange&&F.onChange({originalEvent:e,value:void 0,stopPropagation:function(){null==e||e.stopPropagation()},preventDefault:function(){null==e||e.preventDefault()},target:{name:F.name,id:F.id,value:void 0}}),F.filter&&Je(),tt()},ze=function(e){if(vt!==e.option){tt(e.option),A(-1);var t=rt(e.option),n=We(e.option,mt);F.onChange&&F.onChange({originalEvent:e.originalEvent,value:t,stopPropagation:function(){e.originalEvent.stopPropagation()},preventDefault:function(){e.originalEvent.preventDefault()},target:{name:F.name,id:F.id,value:t}}),ke(e.originalEvent,n)}},Ue=function(e){if(e=e||mt,null!=F.value&&e){if(!F.optionGroupLabel)return We(F.value,e);for(var t=0;t<e.length;t++){var n=We(F.value,it(e[t]));if(-1!==n)return{group:t,option:n}}}return-1},qe=function(){return F.optionValue?null:F.dataKey},We=function(e,t){var n=qe();return t.findIndex((function(t){return y.equals(e,rt(t),n)}))},Ze=function(e){return y.equals(F.value,rt(e),qe())},$e=function(){A(-1!==G?G:F.autoOptionFocus?xe():F.editable?-1:Ee()),B(!0)},Ye=function(){B(!1),J.current=!1},Qe=function(){w.alignOverlay(z.current,$.current.parentElement,F.appendTo||S&&S.appendTo||t.appendTo)},et=function(){var e=w.findSingle(z.current,'li[data-p-focused="true"]');if(e&&e.scrollIntoView)e.scrollIntoView({block:"nearest",inline:"nearest"});else{var t=w.findSingle(z.current,'li[data-p-highlight="true"]');t&&t.scrollIntoView&&t.scrollIntoView({block:"nearest",inline:"nearest"})}},tt=function(e){$.current&&($.current.value=e?nt(e):F.value||"",Y.current&&(Y.current.value=$.current.value))},nt=function(e){if(y.isScalar(e))return"".concat(e);var t=F.optionLabel?y.resolveFieldData(e,F.optionLabel):e.label;return"".concat(t)},rt=function(e){if(F.useOptionAsValue)return e;var t=F.optionValue?y.resolveFieldData(e,F.optionValue):e?e.value:y.resolveFieldData(e,"value");return F.optionValue||y.isNotEmpty(t)?t:e},ot=function(e){return F.optionGroupLabel&&e.group},lt=function(e){return F.optionDisabled?y.isFunction(F.optionDisabled)?F.optionDisabled(e):y.resolveFieldData(e,F.optionDisabled):!(!e||void 0===e.disabled)&&e.disabled},it=function(e){return y.resolveFieldData(e,F.optionGroupChildren)},at=function(){if(F.editable&&$.current){var e=(vt?nt(vt):null)||F.value||"";$.current.value=e,Y.current&&(Y.current.value=e)}};e.useImperativeHandle(E,(function(){return{props:F,show:$e,hide:Ye,clear:Xe,focus:function(){return w.focus(Y.current)},getElement:function(){return X.current},getOverlay:function(){return z.current},getInput:function(){return $.current},getFocusInput:function(){return Y.current},getVirtualScroller:function(){return ee.current}}})),e.useEffect((function(){y.combinedRefs($,F.inputRef),y.combinedRefs(Y,F.focusInputRef)}),[$,F.inputRef,Y,F.focusInputRef]),c((function(){F.autoFocus&&w.focus(Y.current,F.autoFocus),Qe()})),p((function(){H&&(F.value||G>=0)&&et()}),[H,F.value,G]),p((function(){H&&k&&F.filter&&Qe()}),[H,k,F.filter]),p((function(){ee.current&&ee.current.scrollInView(0)}),[k]),p((function(){!k||F.options&&0!==F.options.length||C(""),at(),$.current&&($.current.selectedIndex=1)})),s((function(){I.clear(z.current)}));var ut,ct,pt,st,dt,ft=function(e){"Enter"!==e.key&&"Space"!==e.code||(Xe(e),e.preventDefault())},mt=function(){var e=F.optionGroupLabel?fe(F.options):F.options;if(oe&&!re){var t=k.trim().toLocaleLowerCase(F.filterLocale),n=F.filterBy?F.filterBy.split(","):[F.optionLabel||"label"];if(F.optionGroupLabel){var r,l=[],i=W(F.options);try{for(i.s();!(r=i.n()).done;){var a=r.value,u=o.filter(it(a),n,t,F.filterMatchMode,F.filterLocale);u&&u.length&&l.push(Q(Q({},a),T({},"".concat(F.optionGroupChildren),u)))}}catch(e){i.e(e)}finally{i.f()}return fe(l)}return o.filter(e,n,t,F.filterMatchMode,F.filterLocale)}return e}(),vt=-1!==(ut=Ue(F.options))?F.optionGroupLabel?it(F.options[ut.group])[ut.option]:F.options[ut]:null,bt=y.isNotEmpty(F.tooltip),gt=_.getOtherProps(F),ht=y.reduceKeys(gt,w.ARIA_PROPS),yt=function(){var t={value:"",label:F.placeholder};if(vt){var n=rt(vt);t={value:"object"===L(n)?F.options.findIndex((function(e){return e===n})):n,label:nt(vt)}}var r=x({className:"p-hidden-accessible p-dropdown-hidden-select"},ae("hiddenSelectedMessage")),o=x({ref:$,required:F.required,defaultValue:t.value,name:F.name,tabIndex:-1,"aria-hidden":"true"},ae("select")),l=x({value:t.value},ae("option"));return e.createElement("div",r,e.createElement("select",o,e.createElement("option",l,t.label)))}(),wt=function(){var t=y.isNotEmpty(vt)?nt(vt):null;F.editable&&(t=t||F.value||"");var n=x({className:"p-hidden-accessible"},ae("hiddenSelectedMessage")),r=x(Q({ref:Y,id:F.inputId,defaultValue:t,type:"text",readOnly:!0,"aria-haspopup":"listbox",onFocus:ve,onBlur:be,onKeyDown:he,disabled:F.disabled,tabIndex:F.disabled?-1:F.tabIndex||0},ht),ae("input"));return e.createElement("div",n,e.createElement("input",r))}(),Ot=function(){var t=y.isNotEmpty(vt)?nt(vt):null;if(F.editable){var n=x(Q({ref:$,type:"text",defaultValue:t||F.value||"",className:ue("input",{label:t}),disabled:F.disabled,placeholder:F.placeholder,maxLength:F.maxLength,onInput:Be,onFocus:_e,onKeyDown:he,onBlur:be,tabIndex:F.disabled?-1:F.tabIndex||0,"aria-haspopup":"listbox"},ht),ae("input"));return e.createElement("input",n)}var r=F.valueTemplate?y.getJSXElement(F.valueTemplate,vt,F):t||F.placeholder||F.emptyMessage||e.createElement(e.Fragment,null," "),o=x({ref:$,className:ue("input",{label:t}),tabIndex:"-1"},ae("input"));return e.createElement("span",o,r)}(),It=F.loading?(ct=x({className:ue("loadingIcon"),"data-pr-overlay-visible":H},ae("loadingIcon")),pt=O.getJSXIcon(F.loadingIcon||e.createElement(m,{spin:!0}),Q({},ct),{props:F}),st=F.placeholder||F.ariaLabel,dt=x({className:ue("trigger"),role:"button","aria-haspopup":"listbox","aria-expanded":H,"aria-label":st},ae("trigger")),e.createElement("div",dt,pt)):function(){var t=x({className:ue("dropdownIcon"),"data-pr-overlay-visible":H},ae("dropdownIcon")),n=O.getJSXIcon(H?F.collapseIcon||e.createElement(f,t):F.dropdownIcon||e.createElement(d,t),Q({},t),{props:F}),r=F.placeholder||F.ariaLabel,o=x({className:ue("trigger"),role:"button","aria-haspopup":"listbox","aria-expanded":H,"aria-label":r},ae("trigger"));return e.createElement("div",o,n)}(),Et=function(){if(null!=F.value&&F.showClear&&!F.disabled&&!y.isEmpty(F.options)){var t=x({className:ue("clearIcon"),onPointerUp:Xe,tabIndex:F.tabIndex||"0",onKeyDown:ft,"aria-label":r("clear")},ae("clearIcon"));return O.getJSXIcon(F.clearIcon||e.createElement(v,t),Q({},t),{props:F})}return null}(),xt=x({id:F.id,ref:X,className:h(F.className,ue("root",{context:S,focusedState:j,overlayVisibleState:H})),style:F.style,onClick:function(e){return t=e,void(F.disabled||F.loading||(t.stopPropagation(),F.onClick&&F.onClick(t),t.defaultPrevented||me(t)||"INPUT"===t.target.tagName||(z.current&&z.current&&z.current.contains(t.target)||(w.focus(Y.current),H?Ye():$e()),J.current=!0)));var t},onMouseDown:F.onMouseDown,onContextMenu:F.onContextMenu,onFocus:function(){F.editable&&!H&&!1===J.current&&w.focus($.current)},"data-p-disabled":F.disabled,"data-p-focus":j,"aria-activedescendant":j?"dropdownItem_".concat(G):void 0},gt,ae("root")),St=x({ref:U,role:"presentation","aria-hidden":"true",className:"p-hidden-accessible p-hidden-focusable",tabIndex:"0",onFocus:function(e){var t=e.relatedTarget===Y.current?w.getFirstFocusableElement(z.current,':not([data-p-hidden-focusable="true"])'):Y.current;w.focus(t)},"data-p-hidden-accessible":!0,"data-p-hidden-focusable":!0},ae("hiddenFirstFocusableEl")),Ft=x({ref:Z,role:"presentation","aria-hidden":"true",className:"p-hidden-accessible p-hidden-focusable",tabIndex:"0",onFocus:function(e){var t=e.relatedTarget===Y.current?w.getLastFocusableElement(z.current,':not([data-p-hidden-focusable="true"])'):Y.current;w.focus(t)},"data-p-hidden-accessible":!0,"data-p-hidden-focusable":!0},ae("hiddenLastFocusableEl"));return e.createElement(e.Fragment,null,e.createElement("div",xt,wt,yt,Ot,Et,It,e.createElement(q,N({hostName:"Dropdown",ref:z,visibleOptions:mt,virtualScrollerRef:ee},F,{appendTo:le,cx:ue,filterValue:k,focusedOptionIndex:G,getOptionGroupChildren:it,getOptionGroupLabel:function(e){return y.resolveFieldData(e,F.optionGroupLabel)},getOptionGroupRenderKey:function(e){return y.resolveFieldData(e,F.optionGroupLabel)},getOptionLabel:nt,getOptionRenderKey:function(e){return F.dataKey?y.resolveFieldData(e,F.dataKey):nt(e)},getSelectedOptionIndex:Ue,hasFilter:oe,in:H,isOptionDisabled:lt,isSelected:Ze,onClick:function(e){b.emit("overlay-click",{originalEvent:e,target:X.current})},onEnter:function(e){I.set("overlay",z.current,S&&S.autoZIndex||t.autoZIndex,S&&S.zIndex.overlay||t.zIndex.overlay),w.addStyles(z.current,{position:"absolute",top:"0",left:"0"}),Qe(),e&&e()},onEntered:function(e){e&&e(),se(),F.onShow&&F.onShow()},onExit:function(){de()},onExited:function(){F.filter&&F.resetFilterOnHide&&Je(),I.clear(z.current),F.onHide&&F.onHide()},onFilterClearIconClick:function(e){Je(e)},onFilterInputChange:function(e){var t=e.target.value;C(t),F.onFilter&&F.onFilter({originalEvent:e,filter:t})},onFilterInputKeyDown:function(e){switch(e.code){case"ArrowDown":Ne(e);break;case"ArrowUp":Le(e);break;case"ArrowLeft":case"ArrowRight":Pe(e,!0);break;case"Escape":case"Enter":case"NumpadEnter":Ae(e),e.preventDefault()}},onOptionClick:function(e){e.option.disabled||(ze(e),w.focus(Y.current)),Ye()},onInputKeyDown:he,ptm:ae,resetFilter:Je,changeFocusedOptionIndex:ke,firstFocusableElement:e.createElement("span",St),lastFocusableElement:e.createElement("span",Ft),sx:ce}))),bt&&e.createElement(g,N({target:X,content:F.tooltip,pt:ae("tooltip")},F.tooltipOptions)))})));ee.displayName="Dropdown";export{ee as Dropdown};