UNPKG

react-autocomplete-plugin

Version:

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

2 lines (1 loc) 32 kB
"use strict";var e=require("react/jsx-runtime"),t=require("react");function n(e,t){if(e||t){var n=e||"",o=null==t?void 0:t.split(" ");if(!o)return n;for(var r=0,l=o;r<l.length;r++){n=n+" "+l[r]}return n}}var o=function(){return o=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},o.apply(this,arguments)};function r(r){var l=r.ariaInputLabel?r.ariaInputLabel:"Autocomplete input label",i=r.inputLabelStyle?r.inputLabelStyle:{},a=r.inputLabelClass?r.inputLabelClass:"",u=r.inputLabel?r.inputLabel:"Select or search item.";return e.jsx(t.Fragment,{children:e.jsx("label",o({"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,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},l.apply(this,arguments)};var i=t.forwardRef(function(o,r){var i=void 0===o.showdropDownArrow||null===o.showdropDownArrow||o.showdropDownArrow,a=void 0===o.showClearOption||null===o.showClearOption||o.showClearOption,u=o.placeHolder?o.placeHolder:"Type or select..";return e.jsxs(t.Fragment,{children:[e.jsx("input",{onFocus:o.handleOnFocusEvent,onBlur:o.handleOnBlurEvent,onInput:o.onSearch,id:"searchInput",className:n("auto-complete-textfield",o.inputFieldClass),style:o.inputFieldStyle,ref:r,placeholder:u,type:"text",autoComplete:"off",disabled:!!o.isAutoCompleteDisabled,role:(null==o?void 0:o.ariaRole)?o.ariaRole:"textbox","aria-roledescription":(null==o?void 0:o.ariaRoleDescription)?o.ariaRoleDescription:"Autocomplete input field","aria-label":(null==o?void 0:o.ariaInputField)?o.ariaInputField:"Autocomplete input field"}),i&&e.jsx("span",{tabIndex:0,className:"arrow down",onClick:o.handleDropdownClick}),a&&e.jsx("span",l({className:"auto-complete-remove-selection",onClick:o.clearSearch},{children:"×"}))]})}),a=function(){return a=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},a.apply(this,arguments)};var u=t.forwardRef(function(o,r){var l=t.useCallback(function(){var e={};return(null==o?void 0:o.dropdownListStyle)&&(e=a({},o.dropdownListStyle)),e},[o.dropdownListStyle]),i=t.useCallback(function(){var e="";return(null==o?void 0:o.dropdownListClass)&&(e=o.dropdownListClass),e&&""!==e?n("autocomplete-data-list",e):n("autocomplete-data-list")},[o.dropdownListClass]);return e.jsx(t.Fragment,{children:e.jsx("li",a({tabIndex:0,ref:r,id:"autocomplete-li-element-"+o.index,className:"".concat(i()).concat(o.disableProperty&&o.data[o.disableProperty]||o.disableListFn&&o.disableListFn(o.index,o.data)?" disable-list-element":""),style:l(),onMouseDown:function(){return o.onSelect(o.index,o.data,!0)},"aria-disabled":!!(o.disableProperty&&o.data[o.disableProperty]||o.disableListFn&&o.disableListFn(o.index,o.data)),"aria-label":o.objectProperty?o.data[o.objectProperty]:o.data},{children:o.objectProperty?o.data[o.objectProperty]:o.data}),o.index)})}),c=function(){return c=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},c.apply(this,arguments)},d=function(e,t,n,o){return new(n||(n=Promise))(function(r,l){function i(e){try{u(o.next(e))}catch(e){l(e)}}function a(e){try{u(o.throw(e))}catch(e){l(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(i,a)}u((o=o.apply(e,t||[])).next())})},s=function(e,t){var n,o,r,l,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[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,o&&(r=2&a[0]?o.return:a[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,a[1])).done)return r;switch(o=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,o=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){i.label=a[1];break}if(6===a[0]&&i.label<r[1]){i.label=r[1],r=a;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(a);break}r[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],o=0}finally{n=r=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 o,r=0,l=t.length;r<l;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))};function p(o){var r,l,a,p,f,h,m,w,g,b,y,S,C,L,x,D,F,k,j,E,R,V,O,A,T,P,M,I,N,H=this,B=t.useRef(null),z=t.useRef(0),q=o.scrollThreshold?o.scrollThreshold:3,W=t.useState(!1),U=W[0],G=W[1],Y=t.useRef(null),J=t.useRef([]),K=t.useState(!1),Q=K[0],X=K[1],Z=t.useState([]),$=Z[0],_=Z[1],ee=t.useState([]),te=ee[0],ne=ee[1],oe=o.noSearchResultMessage?o.noSearchResultMessage:"No results found.",re=o.initialVisibleData?o.initialVisibleData:1e3,le=void 0===o.isScrollThresholdRequired||null===o.isScrollThresholdRequired||o.isScrollThresholdRequired,ie=t.useState(!1),ae=ie[0],ue=ie[1],ce=t.useState(0),de=ce[0],se=ce[1],ve=t.useState(!1),pe=ve[0],fe=ve[1],he=t.useState(!1),me=he[0],we=he[1],ge=o.viewMoreText?o.viewMoreText:"View More",be=void 0===o.showViewMore||null===o.showViewMore||o.showViewMore,ye=void 0===o.showLoadingSpinner||null===o.showLoadingSpinner||o.showLoadingSpinner,Se=void 0!==o.isApiLoad&&null!==o.isApiLoad&&o.isApiLoad,Ce=void 0!==o.disableProperty&&null!==o.disableProperty?o.disableProperty:void 0,Le=void 0!==o.objectProperty&&null!==o.objectProperty?o.objectProperty:void 0,xe=void 0!==o.triggerApiLoadEvent&&null!==o.triggerApiLoadEvent&&"function"==typeof o.triggerApiLoadEvent?o.triggerApiLoadEvent:void 0,De=void 0!==o.disableListFn&&null!==o.disableListFn&&"function"==typeof o.disableListFn?o.disableListFn:void 0,Fe=void 0!==o.broadcastSelectedValue&&null!==o.broadcastSelectedValue&&"function"==typeof o.broadcastSelectedValue?o.broadcastSelectedValue:void 0,ke=t.useRef(null),je=t.useRef(null),Ee=t.useRef(-1),Re=t.useRef(!1),Ve=t.useCallback(function(){var e,t,n=null===(e=ke.current)||void 0===e?void 0:e.style,o=null===(t=B.current)||void 0===t?void 0:t.clientWidth;n&&o&&(n.width=o+"px")},[]),Oe=t.useCallback(function(e,t,n){if(!n)return!1;null!=t&&(Ce&&t[Ce]||null!=De&&De(e,t)||(B.current.value=Le?t[Le]:t,G(!1),fe(!1),_([]),ne([]),we(!1),ze(),Fe&&Fe(t)))},[Fe,De,Ce,Le]),Ae=function(e){return d(H,void 0,void 0,function(){var e,t,n,r,l,i,a,u,c,d,v;return s(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),(null===(a=B.current)||void 0===a?void 0:a.value)&&""!==(null===(u=B.current)||void 0===u?void 0:u.value.trim())?(pe||fe(!0),z.current=0,U||G(!0),o.searchFn&&"function"==typeof o.searchFn?[4,o.searchFn(B.current.value,o.dropdownData)]:[3,2]):(ne([]),Te(),Pe(),null===(c=Y.current)||void 0===c||c.scrollTo(0,0),[2]);case 1:if((e=s.sent())&&e.length>0)return ne(e),l=e.slice(0,re),z.current=z.current+l.length,_(l),Pe(),[2];s.label=2;case 2:if(Le){if(qe()){if("object"==typeof(n=null===(d=o.additionalData)||void 0===d?void 0:d.relativeSearch)&&Object.prototype.hasOwnProperty.call(n,"customRelativeSearchFunction")&&"function"==typeof n.customRelativeSearchFunction)return[2,null===(v=Ge())||void 0===v?void 0:v.then(function(e){if(ne(e),(t=e).length>0){var n=t.slice(0,re);return z.current=z.current+n.length,ne(t),_(n),void Pe()}}).catch(function(e){console.log(e),_([])})];t=Je(),ne(t)}else t=o.dropdownData.filter(function(e){var t;return null===(t=e[Le])||void 0===t?void 0:t.toString().toLowerCase().includes(B.current.value.toLowerCase().trim())});return t.length>0?(l=t.slice(0,re),z.current=z.current+l.length,ne(t),_(l),Pe(),[2]):(_([]),[2])}return(r=o.dropdownData.filter(function(e){return null==e?void 0:e.toString().toLowerCase().includes(B.current.value.toLowerCase().trim())})).length>0?(l=r.slice(0,re),z.current=z.current+l.length,ne(r),_(l),Pe(),[2]):(_([]),[2]);case 3:return i=s.sent(),console.log(i),[3,4];case 4:return[2]}})})},Te=function(){var e,t=pe&&te.length>0&&(null===(e=B.current)||void 0===e?void 0:e.value)?te.slice(0,re):o.dropdownData.slice(0,re);_(t),z.current=t.length},Pe=t.useCallback(function(){var e;void 0!==o.totalRecords&&de>=o.totalRecords?we(!1):(null===(e=B.current)||void 0===e?void 0:e.value)&&""!==B.current.value&&Se&&!ae||z.current>=de?we(!0):we(!1)},[de,o.totalRecords,ae,Se]),Me=function(){try{if(!U)return;setTimeout(function(){Ie()},50)}catch(e){console.log(e)}},Ie=function(){var e,t,n=te.length>0?v([],te,!0):v([],o.dropdownData,!0);if(o.dropdownData.length!==z.current&&te.length!==z.current){if(n.length>$.length){var r,l=Math.ceil($.length/q);if(le&&l>=re){var i=v([],$,!0);i.splice(0,re),(r=n.slice(z.current,z.current+re)).length>0&&(z.current=z.current+r.length,pe&&(null===(e=B.current)||void 0===e?void 0:e.value)&&""!==B.current.value&&(r=Le?r.filter(function(e){var t,n,r;return null===(t=e[Le])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(n=o.defaultValue)||void 0===n?void 0:n.toString())||void 0===r?void 0:r.toLowerCase().trim())}):r.filter(function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=o.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())})),_(v(v([],i,!0),r,!0)))}else(r=n.slice(z.current,z.current+re)).length>0&&(z.current=z.current+r.length,pe&&(null===(t=B.current)||void 0===t?void 0:t.value)&&""!==B.current.value&&(r=Le?r.filter(function(e){var t,n,o;return null===(t=e[Le])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(o=null===(n=B.current.value)||void 0===n?void 0:n.toString())||void 0===o?void 0:o.toLowerCase().trim())}):r.filter(function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=B.current.value)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())})),_(function(e){return v(v([],e,!0),r,!0)}));setTimeout(function(){var e;null===(e=Y.current)||void 0===e||e.scrollTo(0,Math.ceil(50*Y.current.scrollHeight/100))},75)}}else if(!ae&&Se&&xe&&"function"==typeof xe){if(o.optViewMoreOnlyForApiCall)return we(!0),void setTimeout(function(){var e;null===(e=Y.current)||void 0===e||e.scrollTo(0,Y.current.scrollHeight+10)},75);xe({dataIndex:o.dropdownData.length}),ue(!0),ye&&(X(!0),setTimeout(function(){var e;null===(e=Y.current)||void 0===e||e.scrollTo(0,Y.current.scrollHeight+10)},75))}},Ne=t.useCallback(function(e,t,n){var o;try{var r=v([],e,!0);if(r.length<=re)return _(r),z.current=r.length,void Pe();var l=r.slice(0,re);return z.current=l.length,pe&&(null===(o=B.current)||void 0===o?void 0:o.value)&&""!==B.current.value&&(l=n?l.filter(function(e){var t,o,r;return null===(t=e[n])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(o=B.current.value)||void 0===o?void 0:o.toString())||void 0===r?void 0:r.toLowerCase().trim())}):l.filter(function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=B.current.value)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())})),_(l),void Pe()}catch(e){console.log(e)}},[re,pe,Pe]),He=t.useCallback(function(e){var t,n,r;try{if(!ae)return;if((null===(t=B.current)||void 0===t?void 0:t.value)&&""!==B.current.value){var l=void 0;if(l=Le?e.filter(function(e){var t;return null===(t=e[Le])||void 0===t?void 0:t.toString().toLowerCase().includes(B.current.value.toLowerCase().trim())}):e.filter(function(e){return null==e?void 0:e.toString().toLowerCase().includes(B.current.value.toLowerCase().trim())}),l&&l.length>0){pe&&ne(l);var i=l.slice(z.current,z.current+re);if(i&&i.length>0){z.current=z.current+i.length;var a=Math.ceil($.length/q);if(le&&a>=re)(c=v([],$,!0)).splice(0,re),_(v(v([],c,!0),i,!0));else _(function(e){return v(v([],e,!0),i,!0)})}setTimeout(function(){var e;null===(e=Y.current)||void 0===e||e.scrollTo(0,Math.ceil(50*Y.current.scrollHeight/100)),ue(!1),X(!1)},100)}else ue(!1),X(!1),ne([]),_([]);return}if(e.length>$.length){var u,c;a=Math.ceil($.length/q);if(le&&a>=re)(c=v([],$,!0)).splice(0,re),(u=e.slice(z.current,z.current+re)).length>0&&(z.current=z.current+u.length,o.defaultValue&&(null===(n=B.current)||void 0===n?void 0:n.value)&&""!==B.current.value&&(u=Le?u.filter(function(e){var t,n,r;return null===(t=e[Le])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(n=o.defaultValue)||void 0===n?void 0:n.toString())||void 0===r?void 0:r.toLowerCase().trim())}):u.filter(function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=o.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())})),_(v(v([],c,!0),u,!0)));else(u=e.slice(z.current,z.current+re)).length>0&&(z.current=z.current+u.length,o.defaultValue&&(null===(r=B.current)||void 0===r?void 0:r.value)&&""!==B.current.value&&(u=Le?u.filter(function(e){var t,n,r;return null===(t=e[Le])||void 0===t?void 0:t.toString().toLowerCase().includes(null===(r=null===(n=o.defaultValue)||void 0===n?void 0:n.toString())||void 0===r?void 0:r.toLowerCase().trim())}):u.filter(function(e){var t,n;return null==e?void 0:e.toString().toLowerCase().includes(null===(n=null===(t=o.defaultValue)||void 0===t?void 0:t.toString())||void 0===n?void 0:n.toLowerCase().trim())})),_(function(e){return v(v([],e,!0),u,!0)}));setTimeout(function(){var e;null===(e=Y.current)||void 0===e||e.scrollTo(0,Math.ceil(50*Y.current.scrollHeight/100)),ue(!1),X(!1)},100)}}catch(e){console.log(e)}},[$,re,le,q,ae,Le,o.defaultValue,pe]),Be=t.useCallback(function(e,t){var n;t&&Se&&!ae&&"function"==typeof xe&&(xe({dataIndex:de}),null===(n=B.current)||void 0===n||n.focus(),ue(!0),ye&&X(!0))},[Se,ae,xe,de,ye]),ze=function(){var e,t;-1!==Ee.current&&(null===(e=J.current[Ee.current])||void 0===e||e.classList.remove("autocomplete-keydown-background")),Re.current&&(null===(t=je.current)||void 0===t||t.classList.remove("autocomplete-keydown-viewmore")),Ee.current=-1,Re.current=!1,J.current=[]},qe=t.useCallback(function(){var e;return!!(null===(e=o.additionalData)||void 0===e?void 0:e.relativeSearch)},[null===(r=o.additionalData)||void 0===r?void 0:r.relativeSearch]),We=t.useCallback(function(){var e,t;return"object"==typeof(null===(e=o.additionalData)||void 0===e?void 0:e.relativeSearch)&&"function"==typeof(null===(t=o.additionalData.relativeSearch)||void 0===t?void 0:t.setDefaultValueWithACustomFunction)},[null===(l=o.additionalData)||void 0===l?void 0:l.relativeSearch,null===(p=null===(a=o.additionalData)||void 0===a?void 0:a.relativeSearch)||void 0===p?void 0:p.setDefaultValueWithACustomFunction]),Ue=t.useCallback(function(){return new Promise(function(e,t){var n,r,l,i=null===(r=null===(n=o.additionalData)||void 0===n?void 0:n.relativeSearch)||void 0===r?void 0:r.setDefaultValueWithACustomFunction(null===(l=B.current)||void 0===l?void 0:l.value);i&&e(i),t([])})},[null===(f=o.additionalData)||void 0===f?void 0:f.relativeSearch,null===(m=null===(h=o.additionalData)||void 0===h?void 0:h.relativeSearch)||void 0===m?void 0:m.setDefaultValueWithACustomFunction]),Ge=t.useCallback(function(){var e,t=null===(e=o.additionalData)||void 0===e?void 0:e.relativeSearch;if("object"==typeof t&&Object.prototype.hasOwnProperty.call(t,"customRelativeSearchFunction")&&"function"==typeof t.customRelativeSearchFunction)return new Promise(function(e,n){var o,r=t.customRelativeSearchFunction(null===(o=B.current)||void 0===o?void 0:o.value);r&&e(r),n([])})},[null===(w=o.additionalData)||void 0===w?void 0:w.relativeSearch,null===(b=null===(g=o.additionalData)||void 0===g?void 0:g.relativeSearch)||void 0===b?void 0:b.customRelativeSearchFunction]),Ye=t.useCallback(function(e,t){return e?o.dropdownData.filter(function(n){return t.some(function(t){return n[t].toString().toLowerCase().includes(e)})}):[]},[o.dropdownData]),Je=t.useCallback(function(){var e,t,n,r=null===(e=o.additionalData)||void 0===e?void 0:e.relativeSearch;if(!r)return[];var l=[];if("boolean"==typeof r&&!0===r)for(var i in o.dropdownData[0])l.push(i);else if("object"==typeof r&&Object.keys(r).length>0){if(Object.prototype.hasOwnProperty.call(r,"includeOnly")&&r.includeOnly.length>0)l=v([],r.includeOnly,!0);else for(var i in o.dropdownData[0])l.push(i);Object.prototype.hasOwnProperty.call(r,"customRelativeSearchFunction")&&r.customRelativeSearchFunction}return l.length>0?Ye(null===(n=null===(t=B.current)||void 0===t?void 0:t.value)||void 0===n?void 0:n.toLowerCase().trim(),l):[]},[o.dropdownData]);return t.useEffect(function(){var e,t;if(U){var n=null===(e=ke.current)||void 0===e?void 0:e.style,r=null===(t=B.current)||void 0===t?void 0:t.clientWidth;(null==n?void 0:n.width)!==r+"px"&&Ve(),ae&&de!==o.dropdownData.length&&"function"==typeof xe&&He(o.dropdownData)}},[de,ae,xe,He,o.dropdownData,U,Ve]),t.useEffect(function(){U||Ne(o.dropdownData,o.defaultValue,Le)},[Ne,o.dropdownData,o.defaultValue,Le,U]),t.useEffect(function(){o.dropdownData.length>0&&se(o.dropdownData.length)},[o.dropdownData]),t.useEffect(function(){var e=function(){Ve()};return U?window.addEventListener("resize",e):window.removeEventListener("resize",e),function(){return window.removeEventListener("resize",e)}},[Ve,U]),t.useEffect(function(){var e=function(e){var t,n,o,r,l,i,a,u,c,d,s;if(!($.length<=0&&27!==(null==e?void 0:e.keyCode)))switch(null==e?void 0:e.keyCode){case 27:return void(U&&(G(!1),null===(t=B.current)||void 0===t||t.blur(),ze()));case 13:if(Re.current)return Be(null,!0),void(Re.current=!1);if(null===(n=J.current[Ee.current])||void 0===n?void 0:n.classList.contains("disable-list-element"))return;var v=$[Ee.current];return null!=v&&(Oe(Ee.current,v,!0),null===(o=J.current[Ee.current])||void 0===o||o.classList.remove("autocomplete-keydown-background")),void(null===(r=B.current)||void 0===r||r.blur());case 40:if(Ee.current+1===J.current.length)return void(je.current&&(null===(l=je.current)||void 0===l||l.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(i=je.current)||void 0===i||i.classList.add("autocomplete-keydown-viewmore"),null===(a=J.current[Ee.current])||void 0===a||a.classList.remove("autocomplete-keydown-background"),Re.current=!0));if(Ee.current=Ee.current+1,null==(s=null===(u=J.current[Ee.current])||void 0===u?void 0:u.id))return;if(!s.includes("autocomplete-li-element-"))return;if("number"!=typeof Number(s.substring(s.lastIndexOf("-")+1)))return;return void setTimeout(function(){var e,t,n,o,r;null===(e=J.current[Ee.current])||void 0===e||e.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(t=J.current[Ee.current])||void 0===t||t.classList.add("autocomplete-keydown-background"),Ee.current>0&&(null===(n=J.current[Ee.current-1])||void 0===n||n.classList.remove("autocomplete-keydown-background"),Ee.current+1===J.current.length&&me&&(null===(o=Y.current)||void 0===o||o.scrollTo(0,(null===(r=Y.current)||void 0===r?void 0:r.scrollHeight)+10)))},20);case 38:if(Ee.current<=0)return;if(Re.current?(null===(c=je.current)||void 0===c||c.classList.remove("autocomplete-keydown-viewmore"),Re.current=!1):Ee.current=Ee.current-1,null==(s=null===(d=J.current[Ee.current])||void 0===d?void 0:d.id))return;if(!s.includes("autocomplete-li-element-"))return;if("number"!=typeof Number(s.substring(s.lastIndexOf("-")+1)))return;return void setTimeout(function(){var e,t,n;null===(e=J.current[Ee.current])||void 0===e||e.scrollIntoView({behavior:"smooth",block:"nearest"}),null===(t=J.current[Ee.current])||void 0===t||t.classList.add("autocomplete-keydown-background"),null===(n=J.current[Ee.current+1])||void 0===n||n.classList.remove("autocomplete-keydown-background")},20);default:return}};return U?window.addEventListener("keydown",e):window.removeEventListener("keydown",e),function(){return window.removeEventListener("keydown",e)}},[$,me,Oe,Be,U]),t.useEffect(function(){if(!(ae||de>0)&&o.defaultValue)if(Le){var e=void 0;if("object"==typeof o.defaultValue){if(qe()){if(!We())return;return void Ue().then(function(e){e&&(null==e?void 0:e[o.objectProperty])&&(B.current.value=e[o.objectProperty])}).catch(function(e){return console.log(e)})}e=o.dropdownData.find(function(e){return e[Le]===o.defaultValue[Le]})}else{if(qe()){if(!We())return;return void Ue().then(function(e){e&&(null==e?void 0:e[o.objectProperty])&&(B.current.value=e[o.objectProperty])}).catch(function(e){return console.log(e)})}e=o.dropdownData.find(function(e){return e[Le]===o.defaultValue})}e&&(B.current.value=e[Le])}else{e=void 0;(e="object"==typeof o.defaultValue?o.dropdownData.find(function(e){return e===o.defaultValue[Le]}):o.dropdownData.find(function(e){return e===o.defaultValue}))&&(B.current.value=e)}},[o.dropdownData,o.defaultValue,Le,ae,de]),e.jsxs(t.Fragment,{children:[e.jsx(i,{handleOnBlurEvent:function(e){var t,n,r,l,i,a,u,c,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===(r=null==e?void 0:e.relatedTarget)||void 0===r?void 0:r.classList)||void 0===l?void 0:l.contains("unorder-list"))?null===(i=B.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===(c=null==e?void 0:e.relatedTarget)||void 0===c?void 0:c.classList)||void 0===d?void 0:d.contains("autocomplete-data-list"))||(o.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."):(G(!1),_([]),ze(),o.triggerBlurEvent&&"function"==typeof o.triggerBlurEvent&&o.triggerBlurEvent(e))))},handleOnFocusEvent:function(e){var t,n,r;if(!o.isAutoCompleteDisabled){G(!0),Ve();var l=null===(t=ke.current)||void 0===t?void 0:t.style,i=null===(n=B.current)||void 0===n?void 0:n.clientWidth;l&&i&&(l.width=i+"px"),o.triggerOnFocusEvent&&"function"==typeof o.triggerOnFocusEvent&&o.triggerOnFocusEvent(e),$.length<=0&&(pe&&(null===(r=B.current)||void 0===r?void 0:r.value)&&""!==B.current.value?Ae():Ne(o.dropdownData,o.defaultValue,Le))}},onSearch:o.searchFn?o.searchFn:Ae,ariaInputField:null===(y=o.aria)||void 0===y?void 0:y.ariaInputField,ariaRole:null===(S=o.aria)||void 0===S?void 0:S.ariaRole,ariaRoleDescription:null===(C=o.aria)||void 0===C?void 0:C.ariaRoleDescription,inputFieldClass:null===(L=o.customClass)||void 0===L?void 0:L.inputFieldClass,inputFieldStyle:null===(x=o.customStyle)||void 0===x?void 0:x.inputFieldStyle,isAutoCompleteDisabled:o.isAutoCompleteDisabled,placeHolder:o.placeHolder,ref:B,clearSearch:function(e){o.isAutoCompleteDisabled||(B.current.value="",o.triggerClearSelectionEvent&&"function"==typeof o.triggerClearSelectionEvent&&o.triggerClearSelectionEvent(e))},handleDropdownClick:function(e){var t;o.isAutoCompleteDisabled||(U?G(!1):null===(t=B.current)||void 0===t||t.focus())},showClearOption:o.showClearOption,showdropDownArrow:o.showdropDownArrow},"input-field"),e.jsx("div",c({id:"autoCompleteListContainerId",ref:ke,className:n("auto-complete-list",null===(D=null==o?void 0:o.customClass)||void 0===D?void 0:D.listContainerClass),style:(null===(F=null==o?void 0:o.customStyle)||void 0===F?void 0:F.listContainerStyle)?o.customStyle.listContainerStyle:{},"aria-label":(null===(k=o.aria)||void 0===k?void 0:k.ariaListContainer)?o.aria.ariaListContainer:"Autocomplete list container."},{children:U&&e.jsx("div",c({id:"list-container"},{children:e.jsxs("ul",c({id:"list-id",ref:Y,onScroll:function(e){var t,n;if(!($.length<=0)){if(e.target.offsetHeight+e.target.scrollTop>=e.target.scrollHeight){if(o.totalRecords&&z.current>=o.totalRecords)return void we(!1);Me()}else le&&e.target.scrollTop<10&&$.length>re&&Te();0===e.target.scrollTop&&(-1!==Ee.current&&(null===(t=J.current[Ee.current])||void 0===t||t.classList.remove("autocomplete-keydown-background")),Re.current&&(null===(n=je.current)||void 0===n||n.classList.remove("autocomplete-keydown-viewmore")),Ee.current=-1,Re.current=!1)}},className:n("unorder-list",null===(j=null==o?void 0:o.customClass)||void 0===j?void 0:j.dropdownUnorderedListClass),style:(null===(E=null==o?void 0:o.customStyle)||void 0===E?void 0:E.dropdownUnorderedListStyle)?o.customStyle.dropdownUnorderedListStyle:{},tabIndex:0,"aria-label":(null===(R=o.aria)||void 0===R?void 0:R.ariaULList)?o.aria.ariaULList:"Autocomplete unordered list"},{children:[$.length>0&&$.map(function(t,n){var r,l;return Le||"object"!=typeof t?e.jsx(u,{index:n,onSelect:Oe,data:t,disableListFn:De,disableProperty:Ce,dropdownListClass:null===(r=o.customClass)||void 0===r?void 0:r.dropdownListClass,dropdownListStyle:null===(l=o.customStyle)||void 0===l?void 0:l.dropdownListStyle,objectProperty:Le,ref:function(e){J.current[n]=e}},n):null}),Q&&ye&&!o.isCustomSpinner&&e.jsx("li",c({className:"auto-complete-list-spinner"},{children:e.jsx("span",{className:"autocomplete-plugin-loader"})})),Q&&ye&&o.isCustomSpinner&&e.jsx("li",c({className:"auto-complete-list-spinner"},{children:e.jsx("span",{className:(null===(V=null==o?void 0:o.customClass)||void 0===V?void 0:V.customSpinnerClass)?o.customClass.customSpinnerClass:"",style:(null===(O=null==o?void 0:o.customStyle)||void 0===O?void 0:O.customSpinnerStyle)?o.customStyle.customSpinnerStyle:{}})})),!Q&&$.length<=0&&e.jsx("li",c({className:n("autocomplete-data-list noSearchResult",null===(A=null==o?void 0:o.customClass)||void 0===A?void 0:A.noResultClass),style:(null===(T=null==o?void 0:o.customStyle)||void 0===T?void 0:T.noResultStyle)?o.customStyle.noResultStyle:{},"aria-label":(null===(P=o.aria)||void 0===P?void 0:P.ariaNoSearchResult)?o.aria.ariaNoSearchResult:"No search result."},{children:oe})),be&&!ae&&!Q&&Se&&me&&e.jsx("li",c({className:n("autocomplete-data-list view-more",null===(M=null==o?void 0:o.customClass)||void 0===M?void 0:M.viewMoreClass),style:(null===(I=null==o?void 0:o.customStyle)||void 0===I?void 0:I.viewMoreStyle)?o.customStyle.viewMoreStyle:{},"aria-label":(null===(N=o.aria)||void 0===N?void 0:N.ariaViewMore)?o.aria.ariaViewMore:"View more results",tabIndex:0,onClick:function(e){return Be(e,!0)},ref:je},{children:ge}))]}))}))}))]})}!function(e,t){void 0===t&&(t={});var n=t.insertAt;if(e&&"undefined"!=typeof document){var o=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===n&&o.firstChild?o.insertBefore(r,o.firstChild):o.appendChild(r),r.styleSheet?r.styleSheet.cssText=e:r.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,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},f.apply(this,arguments)};exports.Autocomplete=function(n){var o,l,i,a,u,c,d,s,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||"",o=null==t?void 0:t.split(" ");if(!o)return n;for(var r=0,l=o;r<l.length;r++){n=n+" "+l[r]}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(r,{inputLabel:w,ariaInputLabel:null===(o=n.aria)||void 0===o?void 0:o.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===(c=n.aria)||void 0===c?void 0:c.ariaInputField,ariaRole:null===(d=n.aria)||void 0===d?void 0:d.ariaRole,ariaRoleDescription:null===(s=n.aria)||void 0===s?void 0:s.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,additionalData:n.additionalData},"input-field")]}))};