UNPKG

react-autocomplete-plugin

Version:

A simple, powerful, lightweight and customizable autocomplete tool programmed for React projects!

2 lines (1 loc) 28.7 kB
"use strict";var e=require("react/jsx-runtime"),t=require("react");function n(e,t){if(e||t){var n=e||"",r=null==t?void 0:t.split(" ");if(!r)return n;for(var o=0,l=r;o<l.length;o++){n=n+" "+l[o]}return n}}var r=function(){return r=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},r.apply(this,arguments)};function o(o){var l=o.ariaInputLabel?o.ariaInputLabel:"Autocomplete input label",i=o.inputLabelStyle?o.inputLabelStyle:{},a=o.inputLabelClass?o.inputLabelClass:"",u=o.inputLabel?o.inputLabel:"Select or search item.";return e.jsx(t.Fragment,{children:e.jsx("label",r({"aria-label":l,className:n("label-value",a),htmlFor:"searchInput",style:i},{children:u}))})}var l=function(){return l=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},l.apply(this,arguments)};var i=t.forwardRef((function(r,o){var i=void 0===r.showdropDownArrow||null===r.showdropDownArrow||r.showdropDownArrow,a=void 0===r.showClearOption||null===r.showClearOption||r.showClearOption,u=r.placeHolder?r.placeHolder:"Type or select..";return e.jsxs(t.Fragment,{children:[e.jsx("input",{onFocus:r.handleOnFocusEvent,onBlur:r.handleOnBlurEvent,onInput:r.onSearch,id:"searchInput",className:n("auto-complete-textfield",r.inputFieldClass),style:r.inputFieldStyle,ref:o,placeholder:u,type:"text",autoComplete:"off",disabled:!!r.isAutoCompleteDisabled,role:(null==r?void 0:r.ariaRole)?r.ariaRole:"textbox","aria-roledescription":(null==r?void 0:r.ariaRoleDescription)?r.ariaRoleDescription:"Autocomplete input field","aria-label":(null==r?void 0:r.ariaInputField)?r.ariaInputField:"Autocomplete input field"}),i&&e.jsx("span",{tabIndex:0,className:"arrow down",onClick:r.handleDropdownClick}),a&&e.jsx("span",l({className:"auto-complete-remove-selection",onClick:r.clearSearch},{children:"×"}))]})})),a=function(){return a=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};var u=t.forwardRef((function(r,o){var l=t.useCallback((function(){var e={};return(null==r?void 0:r.dropdownListStyle)&&(e=a({},r.dropdownListStyle)),e}),[r.dropdownListStyle]),i=t.useCallback((function(){var e="";return(null==r?void 0:r.dropdownListClass)&&(e=r.dropdownListClass),e&&""!==e?n("autocomplete-data-list",e):n("autocomplete-data-list")}),[r.dropdownListClass]);return e.jsx(t.Fragment,{children:e.jsx("li",a({tabIndex:0,ref:o,id:"autocomplete-li-element-"+r.index,className:"".concat(i()).concat(r.disableProperty&&r.data[r.disableProperty]||r.disableListFn&&r.disableListFn(r.index,r.data)?" disable-list-element":""),style:l(),onMouseDown:function(){return r.onSelect(r.index,r.data,!0)},"aria-disabled":!!(r.disableProperty&&r.data[r.disableProperty]||r.disableListFn&&r.disableListFn(r.index,r.data)),"aria-label":r.objectProperty?r.data[r.objectProperty]:r.data},{children:r.objectProperty?r.data[r.objectProperty]:r.data}),r.index)})})),s=function(){return s=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},s.apply(this,arguments)},d=function(e,t,n,r){return new(n||(n=Promise))((function(o,l){function i(e){try{u(r.next(e))}catch(e){l(e)}}function a(e){try{u(r.throw(e))}catch(e){l(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,a)}u((r=r.apply(e,t||[])).next())}))},c=function(e,t){var n,r,o,l,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return l={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;l&&(l=0,a[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},v=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,l=t.length;o<l;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};function p(r){var o,l,a,p,f,h,m,w,g,b,y,C,S,L,x,k,D,F,E,j=this,V=t.useRef(null),R=t.useRef(0),A=r.scrollThreshold?r.scrollThreshold:3,T=t.useState(!1),O=T[0],M=T[1],I=t.useRef(null),P=t.useRef([]),N=t.useState(!1),H=N[0],B=N[1],z=t.useState([]),q=z[0],U=z[1],W=t.useState([]),G=W[0],Y=W[1],J=r.noSearchResultMessage?r.noSearchResultMessage:"No results found.",K=r.initialVisibleData?r.initialVisibleData:1e3,Q=void 0===r.isScrollThresholdRequired||null===r.isScrollThresholdRequired||r.isScrollThresholdRequired,X=t.useState(!1),Z=X[0],$=X[1],_=t.useState(0),ee=_[0],te=_[1],ne=t.useState(!1),re=ne[0],oe=ne[1],le=t.useState(!1),ie=le[0],ae=le[1],ue=r.viewMoreText?r.viewMoreText:"View More",se=void 0===r.showViewMore||null===r.showViewMore||r.showViewMore,de=void 0===r.showLoadingSpinner||null===r.showLoadingSpinner||r.showLoadingSpinner,ce=void 0!==r.isApiLoad&&null!==r.isApiLoad&&r.isApiLoad,ve=void 0!==r.disableProperty&&null!==r.disableProperty?r.disableProperty:void 0,pe=void 0!==r.objectProperty&&null!==r.objectProperty?r.objectProperty:void 0,fe=void 0!==r.triggerApiLoadEvent&&null!==r.triggerApiLoadEvent&&"function"==typeof r.triggerApiLoadEvent?r.triggerApiLoadEvent:void 0,he=void 0!==r.disableListFn&&null!==r.disableListFn&&"function"==typeof r.disableListFn?r.disableListFn:void 0,me=void 0!==r.broadcastSelectedValue&&null!==r.broadcastSelectedValue&&"function"==typeof r.broadcastSelectedValue?r.broadcastSelectedValue:void 0,we=t.useRef(null),ge=t.useRef(null),be=t.useRef(-1),ye=t.useRef(!1),Ce=t.useCallback((function(){var e,t,n=null===(e=we.current)||void 0===e?void 0:e.style,r=null===(t=V.current)||void 0===t?void 0:t.clientWidth;n&&r&&(n.width=r+"px")}),[]),Se=t.useCallback((function(e,t,n){if(!n)return!1;null!=t&&(ve&&t[ve]||null!=he&&he(e,t)||(V.current.value=pe?t[pe]:t,M(!1),oe(!1),U([]),Y([]),ae(!1),Re(),me&&me(t)))}),[me,he,ve,pe]),Le=function(e){return d(j,void 0,void 0,(function(){var e,t,n,o,l,i,a,u;return c(this,(function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),(null===(i=V.current)||void 0===i?void 0:i.value)&&""!==(null===(a=V.current)||void 0===a?void 0:a.value.trim())?(re||oe(!0),R.current=0,O||M(!0),r.searchFn&&"function"==typeof r.searchFn?[4,r.searchFn(V.current.value,r.dropdownData)]:[3,2]):(Y([]),xe(),ke(),null===(u=I.current)||void 0===u||u.scrollTo(0,0),[2]);case 1:if((e=s.sent())&&e.length>0)return Y(e),o=e.slice(0,K),R.current=R.current+o.length,U(o),ke(),[2];s.label=2;case 2:return pe?(t=r.dropdownData.filter((function(e){var t;return null===(t=e[pe])||void 0===t?void 0:t.toString().toLowerCase().includes(V.current.value.toLowerCase().trim())})),t.length>0?(o=t.slice(0,K),R.current=R.current+o.length,Y(t),U(o),ke(),[2]):(U([]),[2])):(n=r.dropdownData.filter((function(e){return null==e?void 0:e.toString().toLowerCase().includes(V.current.value.toLowerCase().trim())}))).length>0?(o=n.slice(0,K),R.current=R.current+o.length,Y(n),U(o),ke(),[2]):(U([]),[2]);case 3:return l=s.sent(),console.log(l),[3,4];case 4:return[2]}}))}))},xe=function(){var e,t=re&&G.length>0&&(null===(e=V.current)||void 0===e?void 0:e.value)?G.slice(0,K):r.dropdownData.slice(0,K);U(t),R.current=t.length},ke=t.useCallback((function(){var e;void 0!==r.totalRecords&&ee>=r.totalRecords?ae(!1):(null===(e=V.current)||void 0===e?void 0:e.value)&&""!==V.current.value&&ce&&!Z||R.current>=ee?ae(!0):ae(!1)}),[ee,r.totalRecords,Z,ce]),De=function(){try{if(!O)return;setTimeout((function(){Fe()}),50)}catch(e){console.log(e)}},Fe=function(){var e,t,n=G.length>0?v([],G,!0):v([],r.dropdownData,!0);if(r.dropdownData.length!==R.current&&G.length!==R.current){if(n.length>q.length){var o,l=Math.ceil(q.length/A);if(Q&&l>=K){var i=v([],q,!0);i.splice(0,K),(o=n.slice(R.current,R.current+K)).length>0&&(R.current=R.current+o.length,re&&(null===(e=V.current)||void 0===e?void 0:e.value)&&""!==V.current.value&&(o=pe?o.filter((function(e){var t,n,o;return null===(t=e[pe])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(o=null===(n=r.defaultValue)||void 0===n?void 0:n.toString())||void 0===o?void 0:o.toLowerCase().trim())})):o.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=r.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),U(v(v([],i,!0),o,!0)))}else(o=n.slice(R.current,R.current+K)).length>0&&(R.current=R.current+o.length,re&&(null===(t=V.current)||void 0===t?void 0:t.value)&&""!==V.current.value&&(o=pe?o.filter((function(e){var t,n,r;return null===(t=e[pe])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(n=V.current.value)||void 0===n?void 0:n.toString())||void 0===r?void 0:r.toLowerCase().trim())})):o.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=V.current.value)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),U((function(e){return v(v([],e,!0),o,!0)})));setTimeout((function(){var e;null===(e=I.current)||void 0===e||e.scrollTo(0,Math.ceil(50*I.current.scrollHeight/100))}),75)}}else if(!Z&&ce&&fe&&"function"==typeof fe){if(r.optViewMoreOnlyForApiCall)return ae(!0),void setTimeout((function(){var e;null===(e=I.current)||void 0===e||e.scrollTo(0,I.current.scrollHeight+10)}),75);fe({dataIndex:r.dropdownData.length}),$(!0),de&&(B(!0),setTimeout((function(){var e;null===(e=I.current)||void 0===e||e.scrollTo(0,I.current.scrollHeight+10)}),75))}},Ee=t.useCallback((function(e,t,n){var r;try{var o=v([],e,!0);if(o.length<=K)return U(o),R.current=o.length,void ke();var l=o.slice(0,K);return R.current=l.length,re&&(null===(r=V.current)||void 0===r?void 0:r.value)&&""!==V.current.value&&(l=n?l.filter((function(e){var t,r,o;return null===(t=e[n])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(o=null===(r=V.current.value)||void 0===r?void 0:r.toString())||void 0===o?void 0:o.toLowerCase().trim())})):l.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=V.current.value)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),U(l),void ke()}catch(e){console.log(e)}}),[K,re,ke]),je=t.useCallback((function(e){var t,n,o;try{if(!Z)return;if((null===(t=V.current)||void 0===t?void 0:t.value)&&""!==V.current.value){var l=void 0;if(l=pe?e.filter((function(e){var t;return null===(t=e[pe])||void 0===t?void 0:t.toString().toLowerCase().includes(V.current.value.toLowerCase().trim())})):e.filter((function(e){return null==e?void 0:e.toString().toLowerCase().includes(V.current.value.toLowerCase().trim())})),l&&l.length>0){re&&Y(l);var i=l.slice(R.current,R.current+K);if(i&&i.length>0){R.current=R.current+i.length;var a=Math.ceil(q.length/A);if(Q&&a>=K)(s=v([],q,!0)).splice(0,K),U(v(v([],s,!0),i,!0));else U((function(e){return v(v([],e,!0),i,!0)}))}setTimeout((function(){var e;null===(e=I.current)||void 0===e||e.scrollTo(0,Math.ceil(50*I.current.scrollHeight/100)),$(!1),B(!1)}),100)}else $(!1),B(!1),Y([]),U([]);return}if(e.length>q.length){var u,s;a=Math.ceil(q.length/A);if(Q&&a>=K)(s=v([],q,!0)).splice(0,K),(u=e.slice(R.current,R.current+K)).length>0&&(R.current=R.current+u.length,r.defaultValue&&(null===(n=V.current)||void 0===n?void 0:n.value)&&""!==V.current.value&&(u=pe?u.filter((function(e){var t,n,o;return null===(t=e[pe])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(o=null===(n=r.defaultValue)||void 0===n?void 0:n.toString())||void 0===o?void 0:o.toLowerCase().trim())})):u.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=r.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),U(v(v([],s,!0),u,!0)));else(u=e.slice(R.current,R.current+K)).length>0&&(R.current=R.current+u.length,r.defaultValue&&(null===(o=V.current)||void 0===o?void 0:o.value)&&""!==V.current.value&&(u=pe?u.filter((function(e){var t,n,o;return null===(t=e[pe])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(o=null===(n=r.defaultValue)||void 0===n?void 0:n.toString())||void 0===o?void 0:o.toLowerCase().trim())})):u.filter((function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=r.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())}))),U((function(e){return v(v([],e,!0),u,!0)})));setTimeout((function(){var e;null===(e=I.current)||void 0===e||e.scrollTo(0,Math.ceil(50*I.current.scrollHeight/100)),$(!1),B(!1)}),100)}}catch(e){console.log(e)}}),[q,K,Q,A,Z,pe,r.defaultValue,re]),Ve=t.useCallback((function(e,t){var n;t&&ce&&!Z&&"function"==typeof fe&&(fe({dataIndex:ee}),null===(n=V.current)||void 0===n||n.focus(),$(!0),de&&B(!0))}),[ce,Z,fe,ee,de]),Re=function(){var e,t;-1!==be.current&&(null===(e=P.current[be.current])||void 0===e||e.classList.remove("autocomplete-keydown-background")),ye.current&&(null===(t=ge.current)||void 0===t||t.classList.remove("autocomplete-keydown-viewmore")),be.current=-1,ye.current=!1,P.current=[]};return t.useEffect((function(){var e,t;if(O){var n=null===(e=we.current)||void 0===e?void 0:e.style,o=null===(t=V.current)||void 0===t?void 0:t.clientWidth;(null==n?void 0:n.width)!==o+"px"&&Ce(),Z&&ee!==r.dropdownData.length&&"function"==typeof fe&&je(r.dropdownData)}}),[ee,Z,fe,je,r.dropdownData,O,Ce]),t.useEffect((function(){O||Ee(r.dropdownData,r.defaultValue,pe)}),[Ee,r.dropdownData,r.defaultValue,pe,O]),t.useEffect((function(){r.dropdownData.length>0&&te(r.dropdownData.length)}),[r.dropdownData]),t.useEffect((function(){var e=function(){Ce()};return O?window.addEventListener("resize",e):window.removeEventListener("resize",e),function(){return window.removeEventListener("resize",e)}}),[Ce,O]),t.useEffect((function(){var e=function(e){var t,n,r,o,l,i,a,u,s,d,c;if(!(q.length<=0&&27!==(null==e?void 0:e.keyCode)))switch(null==e?void 0:e.keyCode){case 27:return void(O&&(M(!1),null===(t=V.current)||void 0===t||t.blur(),Re()));case 13:if(ye.current)return Ve(null,!0),void(ye.current=!1);if(null===(n=P.current[be.current])||void 0===n?void 0:n.classList.contains("disable-list-element"))return;var v=q[be.current];return null!=v&&(Se(be.current,v,!0),null===(r=P.current[be.current])||void 0===r||r.classList.remove("autocomplete-keydown-background")),void(null===(o=V.current)||void 0===o||o.blur());case 40:if(be.current+1===P.current.length)return void(ge.current&&(null===(l=ge.current)||void 0===l||l.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(i=ge.current)||void 0===i||i.classList.add("autocomplete-keydown-viewmore"),null===(a=P.current[be.current])||void 0===a||a.classList.remove("autocomplete-keydown-background"),ye.current=!0));if(be.current=be.current+1,null==(c=null===(u=P.current[be.current])||void 0===u?void 0:u.id))return;if(!c.includes("autocomplete-li-element-"))return;if("number"!=typeof Number(c.substring(c.lastIndexOf("-")+1)))return;return void setTimeout((function(){var e,t,n,r,o;null===(e=P.current[be.current])||void 0===e||e.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(t=P.current[be.current])||void 0===t||t.classList.add("autocomplete-keydown-background"),be.current>0&&(null===(n=P.current[be.current-1])||void 0===n||n.classList.remove("autocomplete-keydown-background"),be.current+1===P.current.length&&ie&&(null===(r=I.current)||void 0===r||r.scrollTo(0,(null===(o=I.current)||void 0===o?void 0:o.scrollHeight)+10)))}),20);case 38:if(be.current<=0)return;if(ye.current?(null===(s=ge.current)||void 0===s||s.classList.remove("autocomplete-keydown-viewmore"),ye.current=!1):be.current=be.current-1,null==(c=null===(d=P.current[be.current])||void 0===d?void 0:d.id))return;if(!c.includes("autocomplete-li-element-"))return;if("number"!=typeof Number(c.substring(c.lastIndexOf("-")+1)))return;return void setTimeout((function(){var e,t,n;null===(e=P.current[be.current])||void 0===e||e.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(t=P.current[be.current])||void 0===t||t.classList.add("autocomplete-keydown-background"),null===(n=P.current[be.current+1])||void 0===n||n.classList.remove("autocomplete-keydown-background")}),20);default:return}};return O?window.addEventListener("keydown",e):window.removeEventListener("keydown",e),function(){return window.removeEventListener("keydown",e)}}),[q,ie,Se,Ve,O]),t.useEffect((function(){if(!(Z||ee>0)&&r.defaultValue)if(pe){var e=void 0;(e="object"==typeof r.defaultValue?r.dropdownData.find((function(e){return e[pe]===r.defaultValue[pe]})):r.dropdownData.find((function(e){return e[pe]===r.defaultValue})))&&(V.current.value=e[pe])}else{e=void 0;(e="object"==typeof r.defaultValue?r.dropdownData.find((function(e){return e===r.defaultValue[pe]})):r.dropdownData.find((function(e){return e===r.defaultValue})))&&(V.current.value=e)}}),[r.dropdownData,r.defaultValue,pe,Z,ee]),e.jsxs(t.Fragment,{children:[e.jsx(i,{handleOnBlurEvent:function(e){var t,n,o,l,i,a,u,s,d;(null===(n=null===(t=null==e?void 0:e.relatedTarget)||void 0===t?void 0:t.classList)||void 0===n?void 0:n.contains("arrow"))||((null===(l=null===(o=null==e?void 0:e.relatedTarget)||void 0===o?void 0:o.classList)||void 0===l?void 0:l.contains("unorder-list"))?null===(i=V.current)||void 0===i||i.focus():(null===(u=null===(a=null==e?void 0:e.relatedTarget)||void 0===a?void 0:a.classList)||void 0===u?void 0:u.contains("disable-list-element"))||(null===(d=null===(s=null==e?void 0:e.relatedTarget)||void 0===s?void 0:s.classList)||void 0===d?void 0:d.contains("autocomplete-data-list"))||(r.inspectAutoCompleteList?console.warn("You have turned off blur event in autocomplete module which will not close autocomplete list. Hope you know what you are doing. Update to false after inspect is complete."):(M(!1),U([]),Re(),r.triggerBlurEvent&&"function"==typeof r.triggerBlurEvent&&r.triggerBlurEvent(e))))},handleOnFocusEvent:function(e){var t,n,o;if(!r.isAutoCompleteDisabled){M(!0),Ce();var l=null===(t=we.current)||void 0===t?void 0:t.style,i=null===(n=V.current)||void 0===n?void 0:n.clientWidth;l&&i&&(l.width=i+"px"),r.triggerOnFocusEvent&&"function"==typeof r.triggerOnFocusEvent&&r.triggerOnFocusEvent(e),q.length<=0&&(re&&(null===(o=V.current)||void 0===o?void 0:o.value)&&""!==V.current.value?Le():Ee(r.dropdownData,r.defaultValue,pe))}},onSearch:r.searchFn?r.searchFn:Le,ariaInputField:null===(o=r.aria)||void 0===o?void 0:o.ariaInputField,ariaRole:null===(l=r.aria)||void 0===l?void 0:l.ariaRole,ariaRoleDescription:null===(a=r.aria)||void 0===a?void 0:a.ariaRoleDescription,inputFieldClass:null===(p=r.customClass)||void 0===p?void 0:p.inputFieldClass,inputFieldStyle:null===(f=r.customStyle)||void 0===f?void 0:f.inputFieldStyle,isAutoCompleteDisabled:r.isAutoCompleteDisabled,placeHolder:r.placeHolder,ref:V,clearSearch:function(e){r.isAutoCompleteDisabled||(V.current.value="",r.triggerClearSelectionEvent&&"function"==typeof r.triggerClearSelectionEvent&&r.triggerClearSelectionEvent(e))},handleDropdownClick:function(e){var t;r.isAutoCompleteDisabled||(O?M(!1):null===(t=V.current)||void 0===t||t.focus())},showClearOption:r.showClearOption,showdropDownArrow:r.showdropDownArrow},"input-field"),e.jsx("div",s({id:"autoCompleteListContainerId",ref:we,className:n("auto-complete-list",null===(h=null==r?void 0:r.customClass)||void 0===h?void 0:h.listContainerClass),style:(null===(m=null==r?void 0:r.customStyle)||void 0===m?void 0:m.listContainerStyle)?r.customStyle.listContainerStyle:{},"aria-label":(null===(w=r.aria)||void 0===w?void 0:w.ariaListContainer)?r.aria.ariaListContainer:"Autocomplete list container."},{children:O&&e.jsx("div",s({id:"list-container"},{children:e.jsxs("ul",s({id:"list-id",ref:I,onScroll:function(e){var t,n;if(!(q.length<=0)){if(e.target.offsetHeight+e.target.scrollTop>=e.target.scrollHeight){if(r.totalRecords&&R.current>=r.totalRecords)return void ae(!1);De()}else Q&&e.target.scrollTop<10&&q.length>K&&xe();0===e.target.scrollTop&&(-1!==be.current&&(null===(t=P.current[be.current])||void 0===t||t.classList.remove("autocomplete-keydown-background")),ye.current&&(null===(n=ge.current)||void 0===n||n.classList.remove("autocomplete-keydown-viewmore")),be.current=-1,ye.current=!1)}},className:n("unorder-list",null===(g=null==r?void 0:r.customClass)||void 0===g?void 0:g.dropdownUnorderedListClass),style:(null===(b=null==r?void 0:r.customStyle)||void 0===b?void 0:b.dropdownUnorderedListStyle)?r.customStyle.dropdownUnorderedListStyle:{},tabIndex:0,"aria-label":(null===(y=r.aria)||void 0===y?void 0:y.ariaULList)?r.aria.ariaULList:"Autocomplete unordered list"},{children:[q.length>0&&q.map((function(t,n){var o,l;return pe||"object"!=typeof t?e.jsx(u,{index:n,onSelect:Se,data:t,disableListFn:he,disableProperty:ve,dropdownListClass:null===(o=r.customClass)||void 0===o?void 0:o.dropdownListClass,dropdownListStyle:null===(l=r.customStyle)||void 0===l?void 0:l.dropdownListStyle,objectProperty:pe,ref:function(e){P.current[n]=e}},n):null})),H&&de&&!r.isCustomSpinner&&e.jsx("li",s({className:"auto-complete-list-spinner"},{children:e.jsx("span",{className:"autocomplete-plugin-loader"})})),H&&de&&r.isCustomSpinner&&e.jsx("li",s({className:"auto-complete-list-spinner"},{children:e.jsx("span",{className:(null===(C=null==r?void 0:r.customClass)||void 0===C?void 0:C.customSpinnerClass)?r.customClass.customSpinnerClass:"",style:(null===(S=null==r?void 0:r.customStyle)||void 0===S?void 0:S.customSpinnerStyle)?r.customStyle.customSpinnerStyle:{}})})),!H&&q.length<=0&&e.jsx("li",s({className:n("autocomplete-data-list noSearchResult",null===(L=null==r?void 0:r.customClass)||void 0===L?void 0:L.noResultClass),style:(null===(x=null==r?void 0:r.customStyle)||void 0===x?void 0:x.noResultStyle)?r.customStyle.noResultStyle:{},"aria-label":(null===(k=r.aria)||void 0===k?void 0:k.ariaNoSearchResult)?r.aria.ariaNoSearchResult:"No search result."},{children:J})),se&&!Z&&!H&&ce&&ie&&e.jsx("li",s({className:n("autocomplete-data-list view-more",null===(D=null==r?void 0:r.customClass)||void 0===D?void 0:D.viewMoreClass),style:(null===(F=null==r?void 0:r.customStyle)||void 0===F?void 0:F.viewMoreStyle)?r.customStyle.viewMoreStyle:{},"aria-label":(null===(E=r.aria)||void 0===E?void 0:E.ariaViewMore)?r.aria.ariaViewMore:"View more results",tabIndex:0,onClick:function(e){return Ve(e,!0)},ref:ge},{children:ue}))]}))}))}))]})}!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}("\n.auto-complete-textfield-container {\n width: 100%;\n height: inherit;\n }\n \n .auto-complete-remove-selection {\n display: inline-block;\n margin-top: 5px;\n margin-left: -25px;\n cursor: pointer;\n }\n \n .auto-complete-textfield {\n width: 100%;\n height: 2rem;\n outline: none;\n border: 1px solid grey;\n border-radius: 5px;\n cursor: text;\n }\n \n .auto-complete-list {\n position: absolute;\n background-color: #FFFFFF;\n }\n \n .field-container {\n width: inherit;\n }\n \n .unorder-list {\n list-style: none;\n max-height: 20rem;\n overflow: auto;\n margin: 0;\n padding: 0;\n text-align: center;\n border: 1px solid #E8E8E8;\n box-shadow: 0 2px 3px -1px rgba(0, 0, 0, 0.1);\n color: #000000;\n }\n \n .autocomplete-data-list {\n padding: 1rem;\n }\n \n .autocomplete-data-list:hover {\n background-color: #EEEDED;\n cursor: pointer;\n }\n \n .showDropdown {\n display: block;\n }\n \n .autocomplete-plugin-loader {\n width: 2rem;\n height: 2rem;\n border: 3px solid #D4D3D3;\n border-bottom-color: transparent;\n border-radius: 50%;\n display: inline-block;\n box-sizing: border-box;\n animation: rotation 1s linear infinite;\n position: relative;\n }\n \n .auto-complete-textfield:disabled {\n background-color: #E7E7E7;\n border: 1px solid #D5D5D5;\n cursor: default;\n }\n \n .auto-complete-list-spinner {\n padding: 1rem;\n }\n \n @keyframes rotation {\n 0% {\n transform: rotate(0deg);\n }\n \n 100% {\n transform: rotate(360deg);\n }\n }\n \n .arrow {\n height: 0;\n width: 0;\n border: 4px solid transparent;\n display: inline-block;\n margin-top: 5px;\n margin-left: -20px;\n cursor: pointer;\n }\n \n .arrow.down {\n border-top-color: #000;\n }\n \n .disable-list-element {\n pointer-events:none;\n opacity:0.5;\n background-color: #E5E5E5;\n }\n \n ::-webkit-input-placeholder {\n text-transform: capitalize;\n }\n \n ::-moz-placeholder {\n text-transform: capitalize;\n }\n \n ::-ms-placeholder {\n text-transform: capitalize;\n }\n \n .view-more {\n cursor: pointer;\n background-color: #f6f5f5;\n letter-spacing: 0.5px;\n }\n \n .autocomplete-keydown-background {\n background-color: #F4F4F4;\n }\n \n .autocomplete-keydown-viewmore {\n background-color: #c8c8c8;\n }");var f=function(){return f=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},f.apply(this,arguments)};exports.Autocomplete=function(n){var r,l,i,a,u,s,d,c,v=t.useRef(null),h=n.customClass?n.customClass:{},m=n.customStyle?n.customStyle:{},w=n.inputLabel?n.inputLabel:"Select a value",g=function(e,t){if(e||t){var n=e||"",r=null==t?void 0:t.split(" ");if(!r)return n;for(var o=0,l=r;o<l.length;o++){n=n+" "+l[o]}return n}};return e.jsxs("div",f({className:g("auto-complete-textfield-container",h.parentContainerClass),ref:v,style:m.parentContainerStyle?m.parentContainerStyle:{}},{children:[n.showInputlabel&&e.jsx("div",f({className:g("label-container",h.inputLabelContainerClass),style:m.inputLabelContainerStyle?m.inputLabelContainerStyle:{}},{children:e.jsx(o,{inputLabel:w,ariaInputLabel:null===(r=n.aria)||void 0===r?void 0:r.ariaInputLabel,inputLabelClass:null===(l=n.customClass)||void 0===l?void 0:l.inputLabelClass,inputLabelStyle:null===(i=n.customStyle)||void 0===i?void 0:i.inputLabelStyle},"label-key")})),e.jsx(p,{dropdownData:n.dropdownData,objectProperty:n.objectProperty,initialVisibleData:n.initialVisibleData,placeHolder:n.placeHolder,inputFieldClass:null===(a=n.customClass)||void 0===a?void 0:a.inputFieldClass,inputFieldStyle:null===(u=n.customStyle)||void 0===u?void 0:u.inputFieldStyle,isAutoCompleteDisabled:n.isAutoCompleteDisabled,ariaInputField:null===(s=n.aria)||void 0===s?void 0:s.ariaInputField,ariaRole:null===(d=n.aria)||void 0===d?void 0:d.ariaRole,ariaRoleDescription:null===(c=n.aria)||void 0===c?void 0:c.ariaRoleDescription,showClearOption:n.showClearOption,showdropDownArrow:n.showdropDownArrow,inspectAutoCompleteList:n.inspectAutoCompleteList,broadcastSelectedValue:n.broadcastSelectedValue,disableListFn:n.disableListFn,disableProperty:n.disableProperty,triggerClearSelectionEvent:n.triggerClearSelectionEvent,customStyle:n.customStyle,aria:n.aria,customClass:n.customClass,isCustomSpinner:n.isCustomSpinner,noSearchResultMessage:n.noSearchResultMessage,showLoadingSpinner:n.showLoadingSpinner,defaultValue:n.defaultValue,isScrollThresholdRequired:n.isScrollThresholdRequired,triggerBlurEvent:n.triggerBlurEvent,triggerApiLoadEvent:n.triggerApiLoadEvent,isApiLoad:n.isApiLoad,scrollThreshold:n.scrollThreshold,triggerOnFocusEvent:n.triggerOnFocusEvent,totalRecords:n.totalRecords,searchFn:n.searchFn,optViewMoreOnlyForApiCall:n.optViewMoreOnlyForApiCall,showViewMore:n.showViewMore,viewMoreText:n.viewMoreText},"input-field")]}))};