@digitransit-component/digitransit-component-autosuggest 1.8.9 → 1.8.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -42,5 +42,5 @@ function c(e,c,n,o){var t={m:["eine Minute","einer Minute"],h:["eine Stunde","ei
42
42
  /*!************************!*\
43
43
  !*** external "react" ***!
44
44
  \************************/
45
- /*! no static exports found */function(c,n){c.exports=e}})},e.exports=n(g.default)})),Qe=(Ve=Ke)&&Ve.__esModule&&Object.prototype.hasOwnProperty.call(Ve,"default")?Ve.default:Ve;function Je(e){var c=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,o=ne(e);if(c){var t=ne(this).constructor;n=Reflect.construct(o,arguments,t)}else n=o.apply(this,arguments);return ce(this,n)}}Pe.locale("en"),W.default.init({fallbackLng:"fi",defaultNS:"translation",interpolation:{escapeValue:!1}});"production"!==process.env.NODE_ENV&&N.default.node;var Ze=function(e){if(e&&e.GTFS.platform){var c=e.GTFS,n=c.modes,o=c.platform;return[n&&"RAIL"===n[0]?W.default.t("track"):W.default.t("platform"),o]}};function $e(e){if("FutureRoute"!==e.type){if("SelectFromMap"===e.type)return["",W.default.t("select-from-map")];if("CurrentLocation"===e.type)return["",W.default.t("use-own-position")];if("SelectFromOwnLocations"===e.type)return["",W.default.t("select-from-own-locations")];var c,n=oe(Ae(e.properties,!0),2),o=n[0],t=n[1];if(e.properties.layer.toLowerCase().includes("bikerental")||e.properties.layer.toLowerCase().includes("bikestation"))return[c=W.default.t("bikerentalstation"),o,void 0,e.properties.labelId];if("bikepark"===e.properties.layer)return[c=W.default.t("bikepark"),o,void 0,void 0];if("carpark"===e.properties.layer)return[c=W.default.t("carpark"),o,void 0,void 0];if(e.properties.mode)c=W.default.t(e.properties.mode.toLowerCase().replace("favourite",""));else{var a=e.properties.layer.replace("route-","").toLowerCase().replace("favourite","");c=W.default.t(a)}if(e.properties.id&&("stop"===e.properties.layer||"station"===e.properties.layer)){var i,r=de(e.properties),M=null===(i=e.properties.addendum)||void 0===i?void 0:i.GTFS.modes,s=Ze(e.properties.addendum);return[c,ue(o,r),t,r,M,s]}if("favouriteStop"===e.properties.layer||"favouriteStation"===e.properties.layer){var l=e.properties,u=l.address,p=l.code;return[c,u?ue(u.split(",")[0],p):o,t,p,void 0,Ze(e.properties.addendum)]}return[c,o,t]}var d=e.properties,b=d.origin,A=d.destination,f=b.locality?", ".concat(b.locality," foobar"):"",z=A.locality?", ".concat(A.locality):"",h=b.name,O=A.name;return[W.default.t("future-route"),"".concat(W.default.t("origin")," ").concat(h).concat(f," ").concat(W.default.t("destination")," ").concat(O).concat(z),e.translatedText]}function ec(e){var c=Pe.unix(e.properties.time),n=e.properties.arriveBy?W.default.t("arrival"):W.default.t("departure");return n=c.isSame(Pe(),"day")?"".concat(n," ").concat(W.default.t("today-at")):c.isSame(Pe().add(1,"day"),"day")?"".concat(n," ").concat(W.default.t("tomorrow-at")):"".concat(n," ").concat(c.format("dd D.M.")),n="".concat(n," ").concat(Pe(c).format("HH:mm"))}var cc=function(e){$(n,e);var c=Je(n);function n(e){var o;return K(this,n),(o=c.call(this,e)).componentDidUpdate=function(){W.default.language!==o.props.lang&&W.default.changeLanguage(o.props.lang)},o.UNSAFE_componentWillReceiveProps=function(e){e.value===o.state.value||o.state.editing||o.setState({value:e.value})},o.onChange=function(e,c){var n=c.newValue,t=c.method,a={value:o.fInput||n||"",renderMobileSearch:o.props.isMobile};if(o.fInput=null,o.state.editing){if("enter"!==t||o.state.valid){if(o.state.typingTimer&&clearTimeout(o.state.typingTimer),"type"===t){var i=setTimeout((function(){o.setState({typing:!1})}),1e3);a.typingTimer=i,a.typing=!0}o.setState(a)}}else a.editing=!0,o.setState(a,(function(){return o.fetchFunction({value:n||""})}))},o.onBlur=function(){o.state.renderMobileSearch||(o.state.editing&&o.input.focus(),o.setState({editing:!1,renderMobileSearch:!1,value:o.props.value}))},o.onSelected=function(e,c){if(o.state.valid){if("SelectFromOwnLocations"===c.suggestion.type)return void o.setState({sources:["Favourite","Back"],ownPlaces:!0,pendingSelection:c.suggestion.type,value:""},(function(){o.fetchFunction({value:""})}));if("back"===c.suggestion.type||"FutureRoute"===c.suggestion.type)return void o.setState({sources:o.props.sources,ownPlaces:!1,pendingSelection:c.suggestion.type,suggestionIndex:c.suggestionIndex},(function(){o.fetchFunction({value:""})}));o.selectionDone=!0,o.setState({editing:!1,value:c.suggestionValue},(function(){o.input.blur(),o.props.handleViaPoints?o.props.handleViaPoints(c.suggestion,c.suggestionIndex):o.props.onSelect(c.suggestion,o.props.id),o.setState({renderMobileSearch:!1,sources:o.props.sources,ownPlaces:!1,suggestions:[]},(function(){o.selectionDone=!1})),!o.props.focusChange||o.props.isMobile&&!o.props.isEmbedded||o.props.focusChange(),o.props.isMobile&&o.closeMobileSearch()}))}else o.setState((function(e){return{pendingSelection:e.value}}),(function(){return o.checkPendingSelection()}))},o.onSuggestionsClearRequested=function(){o.setState({suggestions:[],sources:o.props.sources,ownPlaces:!1,editing:!1})},o.getSuggestionValue=function(e){return"SelectFromOwnLocations"===e.type||"back"===e.type?"":function(e){var c=Ae(e,!0);switch(e.layer){case"selectFromMap":case"currentPosition":case"ownLocations":case"back":return c[1]||c[0];case"favouriteBikeRentalStation":case"favouritePlace":return c[0];default:return c.length>1&&""!==c[1]?c.join(", "):c[1]||c[0]}}(e.properties)},o.checkPendingSelection=function(){"SelectFromOwnLocations"!==o.state.pendingSelection&&"back"!==o.state.pendingSelection||!o.state.valid?o.state.pendingSelection&&o.state.valid&&o.setState({pendingSelection:null,editing:!1},(function(){o.state.suggestions.length&&(o.input.blur(),o.props.onSelect(o.state.suggestions[o.state.suggestionIndex],o.props.id),o.props.isMobile&&o.closeMobileSearch(),!o.props.focusChange||o.props.isMobile&&!o.props.isEmbedded||o.props.focusChange())})):o.setState({pendingSelection:null,editing:!0},(function(){o.input.focus()}))},o.clearButton=function(){return g.default.createElement("button",{type:"button",className:He["clear-input"],onClick:o.clearInput,"aria-label":W.default.t("clear-button-label")},g.default.createElement(x.default,{img:"close",color:o.props.color}))},o.fetchFunction=function(e){var c=e.value,n=e.cleanExecuted;return o.setState({valid:!1,cleanExecuted:n||!1},(function(){if(!o.selectionDone){var e,n=I.default(o.props.targets)||o.props.targets.includes("Locations");o.state.ownPlaces?(e=["Locations"],(I.default(o.props.targets)||o.props.targets.includes("Stops"))&&e.push("Stops"),(I.default(o.props.targets)||o.props.targets.includes("BikeRentalStations"))&&e.push("BikeRentalStations")):I.default(o.props.targets)||(e=V(o.props.targets),n&&!o.props.isMobile&&(I.default(o.props.sources)||o.props.sources.includes("Favourite"))&&e.push("SelectFromOwnLocations")),function(e,c,n,o,t,a,i,r,M,s){r(null),Te(e,c,n,o,t,a,i,r,M,s)}(e,o.state.sources&&o.state.sources.filter((function(e){return!(n&&"Favourite"===e&&!o.state.ownPlaces&&!o.props.isMobile)})),o.props.transportMode,o.props.searchContext,o.props.filterResults,o.props.geocodingSize,{input:c||""},(function(e){if(null!=e){var n=(e.results||[]).filter((function(e){return"FutureRoute"!==e.type||"FutureRoute"===e.type&&e.properties.time>Pe().unix()})).map((function(e){if("CurrentLocation"===e.type||"SelectFromMap"===e.type||"SelectFromOwnLocations"===e.type||"back"===e.type){var c=j({},e);return c.properties.labelId=W.default.t(e.properties.labelId),c}return e}));c!==o.state.value&&c!==o.state.pendingSelection&&"SelectFromOwnLocations"!==o.state.pendingSelection&&"back"!==o.state.pendingSelection&&"FutureRoute"!==o.state.pendingSelection||o.setState({valid:!0,suggestions:n},(function(){return o.checkPendingSelection()}))}}),o.props.pathOpts,o.props.refPoint)}}))},o.clearInput=function(){var e={editing:!0,value:"",sources:o.props.sources,ownPlaces:!1};o.setState(e,(function(){return o.fetchFunction({value:"",cleanExecuted:!0})})),o.props.onClear&&o.props.onClear(o.props.id),o.input.focus()},o.inputClicked=function(e){if(o.input.focus(),o.props.isMobile&&o.props.lock(),!o.state.editing){var c={editing:!0,pendingSelection:null,renderMobileSearch:o.props.isMobile},n={editing:!0,pendingSelection:null,value:e};o.state.suggestions.length?(o.fetchFunction({value:o.state.value}),o.setState(c)):"object"!==F(e)&&e?o.setState(n,(function(){return o.fetchFunction({value:e})})):o.setState(c,(function(){return o.fetchFunction({value:o.state.value})}))}},o.storeInputReference=function(e){null!==e&&(o.input=e.input,o.props.storeRef&&o.props.storeRef(e.input))},o.fillInput=function(e){o.fInput=e.properties.name;var c={editing:!0,value:e.properties.name,checkPendingSelection:e,valid:!0};o.setState(c),o.fetchFunction({value:e.properties.name}),o.input.focus()},o.renderItem=function(e){var c="FutureRoute"===e.type?j({},e,{translatedText:ec(e)}):e,n=$e(e);return g.default.createElement(P.default,{item:c,content:n,loading:!o.state.valid,isMobile:o.props.isMobile,ariaFavouriteString:W.default.t("favourite"),color:o.props.color,accessiblePrimaryColor:o.props.accessiblePrimaryColor,fillInput:o.fillInput,fontWeights:o.props.fontWeights,modeIconColors:o.props.modeIconColors,modeSet:o.props.modeSet})},o.closeMobileSearch=function(){o.props.unlock(),o.setState({renderMobileSearch:!1,value:o.props.value},(function(){window.scrollTo(0,o.state.scrollY),o.onSuggestionsClearRequested()}))},o.keyDown=function(e){if(!o.selectionDone){var c=e.key;if("Escape"===c&&o.setState({editing:!1}),o.state.editing)return"Enter"===c&&""!==o.state.value&&o.setState({pendingSelection:!0},(function(){o.fetchFunction({value:o.state.value})})),void o.inputClicked();if("Enter"!==c&&"ArrowDown"!==c||""!==o.state.value){if("ArrowDown"===c&&""!==o.state.value){var n={editing:!0,value:o.state.value};o.setState(n,(function(){return o.fetchFunction({value:o.state.value})}))}o.state.editing||o.setState({editing:!0}),"Tab"===c&&o.onBlur()}else o.clearInput()}},o.suggestionAsAriaContent=function(){var e=[],c=o.state.suggestions[0];return c&&(c.type&&c.type.includes("Favourite")&&e.push(W.default.t("favourite")),e=e.concat($e(o.state.suggestions[0]))),V(new Set(e)).join(" - ")},o.clearOldSearches=function(){var e=o.props.searchContext,c=e.context,n=e.clearOldSearches,t=e.clearFutureRoutes;c&&n&&(n(c),t&&t(c),o.fetchFunction({value:o.state.value}))},o.isOriginDestinationOrViapoint=function(){return"origin"===o.props.id||"destination"===o.props.id||"via-point"===o.props.id||"origin-stop-near-you"===o.props.id},o.onFocus=function(){["Valittu sijainti","Nykyinen sijaintisi","Current position","Selected location","Vald position","Använd min position","Min position","Käytä nykyistä sijaintia","Use current location","Your current location"].includes(o.state.value)&&o.clearInput();var e=window.pageYOffset;return o.setState({scrollY:e})},Pe.tz.setDefault(e.timeZone),Pe.locale(e.lang),o.state={value:e.value,suggestions:[],editing:!1,valid:!0,renderMobileSearch:!1,sources:e.sources,ownPlaces:!1,typingTimer:null,typing:!1,pendingSelection:null,suggestionIndex:0,cleanExecuted:!1,scrollY:0},Object.keys(xe).forEach((function(e){W.default.addResourceBundle(e,"translation",xe[e])})),o}return J(n,[{key:"shouldComponentUpdate",value:function(e,c){return!C.default(c,this.state)||!C.default(e,this.props)}},{key:"render",value:function(){var e=this;W.default.language!==this.props.lang&&W.default.changeLanguage(this.props.lang);var c=this.state,n=c.value,o=c.suggestions,t=c.renderMobileSearch,a=c.cleanExecuted,i={placeholder:this.props.translatedPlaceholder?this.props.translatedPlaceholder:W.default.t(this.props.placeholder),value:n,onChange:this.onChange,onBlur:this.onBlur,className:"".concat(He.input," ").concat(this.props.isMobile&&this.props.transportMode?He.thin:""," ").concat(He[this.props.id]||""," ").concat(this.state.value?He.hasValue:""," ").concat(this.props.inputClassName),onKeyDown:this.keyDown,required:this.props.required},r=this.props.id.replace("searchfield-",""),M=this.props.ariaLabel||W.default.t(r);M=M.replace("searchfield-","");var s=this.props.required?"".concat(W.default.t("required"),"."):"",l=this.props.isMobile?W.default.t("search-autosuggest-label-mobile"):W.default.t("search-autosuggest-label-desktop"),u=W.default.t("search-autosuggest-len",{count:o.length}),p=function(){return e.suggestionAsAriaContent()||e.props.value?W.default.t("search-current-suggestion",{selection:e.suggestionAsAriaContent()||e.props.value}):""};return g.default.createElement(g.default.Fragment,null,g.default.createElement("span",{className:He["sr-only"],role:"alert"},!this.state.typing&&this.state.editing&&"".concat(u," ").concat(p())),this.props.isMobile&&g.default.createElement(Ge,{searchOpen:t,appElement:this.props.appElement,clearOldSearches:this.clearOldSearches,id:this.props.id,clearInput:this.clearInput,value:this.state.value,suggestions:[].concat(V(o),[{type:"clear-search-history",labelId:W.default.t("clear-search-history")}]),inputProps:j({},i,{placeholder:this.isOriginDestinationOrViapoint()?W.default.t("address-place-or-business"):i.placeholder}),fetchFunction:this.fetchFunction,onSuggestionsClearRequested:this.onSuggestionsClearRequested,getSuggestionValue:this.getSuggestionValue,renderSuggestion:this.renderItem,closeHandle:this.closeMobileSearch,ariaLabel:s.concat(" ").concat(M).concat(" ").concat(p()),label:this.props.mobileLabel?this.props.mobileLabel:W.default.t(this.props.id),onSuggestionSelected:this.onSelected,dialogHeaderText:W.default.t("delete-old-searches-header"),dialogPrimaryButtonText:W.default.t("delete"),dialogSecondaryButtonText:W.default.t("cancel"),clearInputButtonText:W.default.t("clear-button-label"),focusInput:a,color:this.props.color,hoverColor:this.props.hoverColor,accessiblePrimaryColor:this.props.accessiblePrimaryColor,fontWeights:this.props.fontWeights,showScroll:this.props.showScroll}),!t&&g.default.createElement("div",{className:_.default(He["autosuggest-input-container"],He[this.props.id]),style:{"--color":"".concat(this.props.color),"--hover-color":"".concat(this.props.hoverColor)}},this.props.icon&&g.default.createElement("div",{className:_.default(He["autosuggest-input-icon"],He[this.props.id],this.props.inputClassName&&"".concat(this.props.inputClassName,"-input-icon"))},g.default.createElement(x.default,{img:"".concat(this.props.icon)})),g.default.createElement(T.default,{alwaysRenderSuggestions:this.state.editing,id:this.props.id,suggestions:o,onSuggestionsFetchRequested:this.fetchFunction,onSuggestionsClearRequested:this.onSuggestionsClearRequested,getSuggestionValue:this.getSuggestionValue,renderSuggestion:this.renderItem,inputProps:j({},i,{onFocus:this.onFocus}),focusInputOnSuggestionClick:!0,shouldRenderSuggestions:function(){return e.state.editing},highlightFirstSuggestion:!this.state.ownPlaces,theme:He,renderInputComponent:function(c){return g.default.createElement(g.default.Fragment,null,g.default.createElement("label",{className:He["sr-only"],htmlFor:e.props.id},p().concat(" ").concat(s).concat(" ").concat(M).concat(" ").concat(l)),g.default.createElement("input",Object.assign({"aria-label":p().concat(" ").concat(s).concat(" ").concat(M).concat(" ").concat(l),id:e.props.id,onClick:e.inputClicked,onKeyDown:e.keyDown},c)),e.state.value&&e.clearButton())},onSuggestionSelected:this.onSelected,ref:this.storeInputReference})))}}]),n}(g.default.Component);cc.defaultProps={autoFocus:!1,className:"",icon:void 0,value:"",transportMode:void 0,lang:"fi",sources:[],isMobile:!1,color:"#007ac9",hoverColor:"#0062a1",accessiblePrimaryColor:"#0074be",timeZone:"Europe/Helsinki",pathOpts:{routesPrefix:"linjat",stopsPrefix:"pysakit"},mobileLabel:void 0,inputClassName:"",translatedPlaceholder:void 0,fontWeights:{medium:500},modeIconColors:{"mode-bus":"#007ac9","mode-rail":"#8c4799","mode-tram":"#008151","mode-metro":"#ed8c00","mode-ferry":"#007A97","mode-citybike":"#f2b62d"},required:!1,modeSet:void 0,showScroll:!1},"production"!==process.env.NODE_ENV&&(cc.propTypes={appElement:N.default.string.isRequired,autoFocus:N.default.bool,className:N.default.string,icon:N.default.string,id:N.default.string.isRequired,placeholder:N.default.string.isRequired,translatedPlaceholder:N.default.string,value:N.default.string,searchContext:N.default.any.isRequired,ariaLabel:N.default.string,onSelect:N.default.func,transportMode:N.default.string,filterResults:N.default.func,geocodingSize:N.default.number,onClear:N.default.func,storeRef:N.default.func,handleViaPoints:N.default.func,focusChange:N.default.func,lang:N.default.string,sources:N.default.arrayOf(N.default.string),targets:N.default.arrayOf(N.default.string),isMobile:N.default.bool,color:N.default.string,hoverColor:N.default.string,accessiblePrimaryColor:N.default.string,timeZone:N.default.string,pathOpts:N.default.shape({routesPrefix:N.default.string,stopsPrefix:N.default.string}),mobileLabel:N.default.string,lock:N.default.func.isRequired,unlock:N.default.func.isRequired,refPoint:N.default.object,inputClassName:N.default.string,fontWeights:N.default.shape({medium:N.default.number}),modeIconColors:N.default.object,required:N.default.bool,modeSet:N.default.string,showScroll:N.default.bool,isEmbedded:N.default.bool});var nc,oc=(nc=cc,function(e){var c=Qe.useScrollLock(),n=c.lock,o=c.unlock;return g.default.createElement(nc,Object.assign({lock:n,unlock:o},e))});e.default=oc,Object.defineProperty(e,"__esModule",{value:!0})}));
45
+ /*! no static exports found */function(c,n){c.exports=e}})},e.exports=n(g.default)})),Qe=(Ve=Ke)&&Ve.__esModule&&Object.prototype.hasOwnProperty.call(Ve,"default")?Ve.default:Ve;function Je(e){var c=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var n,o=ne(e);if(c){var t=ne(this).constructor;n=Reflect.construct(o,arguments,t)}else n=o.apply(this,arguments);return ce(this,n)}}Pe.locale("en"),W.default.init({fallbackLng:"fi",defaultNS:"translation",interpolation:{escapeValue:!1}});"production"!==process.env.NODE_ENV&&N.default.node;var Ze=function(e){if(e&&e.GTFS.platform){var c=e.GTFS,n=c.modes,o=c.platform;return[n&&"RAIL"===n[0]?W.default.t("track"):W.default.t("platform"),o]}};function $e(e){if("FutureRoute"!==e.type){if("SelectFromMap"===e.type)return["",W.default.t("select-from-map")];if("CurrentLocation"===e.type)return["",W.default.t("use-own-position")];if("SelectFromOwnLocations"===e.type)return["",W.default.t("select-from-own-locations")];var c,n=oe(Ae(e.properties,!0),2),o=n[0],t=n[1];if(e.properties.layer.toLowerCase().includes("bikerental")||e.properties.layer.toLowerCase().includes("bikestation"))return[c=W.default.t("bikerentalstation"),o,void 0,e.properties.labelId];if("bikepark"===e.properties.layer)return[c=W.default.t("bikepark"),o,void 0,void 0];if("carpark"===e.properties.layer)return[c=W.default.t("carpark"),o,void 0,void 0];if(e.properties.mode)c=W.default.t(e.properties.mode.toLowerCase().replace("favourite",""));else{var a=e.properties.layer.replace("route-","").toLowerCase().replace("favourite","");c=W.default.t(a)}if(e.properties.id&&("stop"===e.properties.layer||"station"===e.properties.layer)){var i,r=de(e.properties),M=null===(i=e.properties.addendum)||void 0===i?void 0:i.GTFS.modes,s=Ze(e.properties.addendum);return[c,ue(o,r),t,r,M,s]}if("favouriteStop"===e.properties.layer||"favouriteStation"===e.properties.layer){var l=e.properties,u=l.address,p=l.code;return[c,u?ue(u.split(",")[0],p):o,t,p,void 0,Ze(e.properties.addendum)]}return[c,o,t]}var d=e.properties,b=d.origin,A=d.destination,f=b.locality?", ".concat(b.locality," foobar"):"",z=A.locality?", ".concat(A.locality):"",h=b.name,O=A.name;return[W.default.t("future-route"),"".concat(W.default.t("origin")," ").concat(h).concat(f," ").concat(W.default.t("destination")," ").concat(O).concat(z),e.translatedText]}function ec(e){var c=Pe.unix(e.properties.time),n=e.properties.arriveBy?W.default.t("arrival"):W.default.t("departure");return n=c.isSame(Pe(),"day")?"".concat(n," ").concat(W.default.t("today-at")):c.isSame(Pe().add(1,"day"),"day")?"".concat(n," ").concat(W.default.t("tomorrow-at")):"".concat(n," ").concat(c.format("dd D.M.")),n="".concat(n," ").concat(Pe(c).format("HH:mm"))}var cc=function(e){$(n,e);var c=Je(n);function n(e){var o;return K(this,n),(o=c.call(this,e)).componentDidUpdate=function(){W.default.language!==o.props.lang&&W.default.changeLanguage(o.props.lang)},o.UNSAFE_componentWillReceiveProps=function(e){e.value===o.state.value||o.state.editing||o.setState({value:e.value})},o.onChange=function(e,c){var n=c.newValue,t=c.method,a={value:o.fInput||n||"",renderMobileSearch:o.props.isMobile};if(o.fInput=null,o.state.editing){if("enter"!==t||o.state.valid){if(o.state.typingTimer&&clearTimeout(o.state.typingTimer),"type"===t){var i=setTimeout((function(){o.setState({typing:!1})}),1e3);a.typingTimer=i,a.typing=!0}o.setState(a)}}else a.editing=!0,o.setState(a,(function(){return o.fetchFunction({value:n||""})}))},o.onBlur=function(){o.state.renderMobileSearch||(o.state.editing&&o.input.focus(),o.setState({editing:!1,renderMobileSearch:!1,value:o.props.value}))},o.onSelected=function(e,c){if(o.state.valid){if("SelectFromOwnLocations"===c.suggestion.type)return void o.setState({sources:["Favourite","Back"],ownPlaces:!0,pendingSelection:c.suggestion.type,value:""},(function(){o.fetchFunction({value:""})}));if("back"===c.suggestion.type||"FutureRoute"===c.suggestion.type)return void o.setState({sources:o.props.sources,ownPlaces:!1,pendingSelection:c.suggestion.type,suggestionIndex:c.suggestionIndex},(function(){o.fetchFunction({value:""})}));o.selectionDone=!0,o.setState({editing:!1,value:c.suggestionValue},(function(){o.input.blur(),o.props.handleViaPoints?o.props.handleViaPoints(c.suggestion,c.suggestionIndex):o.props.onSelect(c.suggestion,o.props.id),o.setState({renderMobileSearch:!1,sources:o.props.sources,ownPlaces:!1,suggestions:[]},(function(){o.selectionDone=!1})),!o.props.focusChange||o.props.isMobile&&!o.props.isEmbedded||o.props.focusChange(),o.props.isMobile&&o.closeMobileSearch()}))}else o.setState((function(e){return{pendingSelection:e.value}}),(function(){return o.checkPendingSelection()}))},o.onSuggestionsClearRequested=function(){o.setState({suggestions:[],sources:o.props.sources,ownPlaces:!1,editing:!1})},o.getSuggestionValue=function(e){return"SelectFromOwnLocations"===e.type||"back"===e.type?"":function(e){var c=Ae(e,!0);switch(e.layer){case"selectFromMap":case"currentPosition":case"ownLocations":case"back":return c[1]||c[0];case"favouriteBikeRentalStation":case"favouritePlace":return c[0];default:return c.length>1&&""!==c[1]?c.join(", "):c[1]||c[0]}}(e.properties)},o.checkPendingSelection=function(){"SelectFromOwnLocations"!==o.state.pendingSelection&&"back"!==o.state.pendingSelection||!o.state.valid?o.state.pendingSelection&&o.state.valid&&o.setState({pendingSelection:null,editing:!1},(function(){o.state.suggestions.length&&(o.input.blur(),o.props.onSelect(o.state.suggestions[o.state.suggestionIndex],o.props.id),o.props.isMobile&&o.closeMobileSearch(),!o.props.focusChange||o.props.isMobile&&!o.props.isEmbedded||o.props.focusChange())})):o.setState({pendingSelection:null,editing:!0},(function(){o.input.focus()}))},o.clearButton=function(){return g.default.createElement("button",{type:"button",className:He["clear-input"],onClick:o.clearInput,"aria-label":W.default.t("clear-button-label")},g.default.createElement(x.default,{img:"close",color:o.props.color}))},o.fetchFunction=function(e){var c=e.value,n=e.cleanExecuted;return o.setState({valid:!1,cleanExecuted:n||!1},(function(){if(!o.selectionDone){var e,n=I.default(o.props.targets)||o.props.targets.includes("Locations");o.state.ownPlaces?(e=["Locations"],(I.default(o.props.targets)||o.props.targets.includes("Stops"))&&e.push("Stops"),(I.default(o.props.targets)||o.props.targets.includes("BikeRentalStations"))&&e.push("BikeRentalStations")):I.default(o.props.targets)||(e=V(o.props.targets),n&&!o.props.isMobile&&(I.default(o.props.sources)||o.props.sources.includes("Favourite"))&&e.push("SelectFromOwnLocations")),function(e,c,n,o,t,a,i,r,M,s){r(null),Te(e,c,n,o,t,a,i,r,M,s)}(e,o.state.sources&&o.state.sources.filter((function(e){return!(n&&"Favourite"===e&&!o.state.ownPlaces&&!o.props.isMobile)})),o.props.transportMode,o.props.searchContext,o.props.filterResults,o.props.geocodingSize,{input:c||""},(function(e){if(null!=e){var n=(e.results||[]).filter((function(e){return"FutureRoute"!==e.type||"FutureRoute"===e.type&&e.properties.time>Pe().unix()})).map((function(e){if("CurrentLocation"===e.type||"SelectFromMap"===e.type||"SelectFromOwnLocations"===e.type||"back"===e.type){var c=j({},e);return c.properties.labelId=W.default.t(e.properties.labelId),c}return e}));c!==o.state.value&&c!==o.state.pendingSelection&&"SelectFromOwnLocations"!==o.state.pendingSelection&&"back"!==o.state.pendingSelection&&"FutureRoute"!==o.state.pendingSelection||o.setState({valid:!0,suggestions:n},(function(){return o.checkPendingSelection()}))}}),o.props.pathOpts,o.props.refPoint)}}))},o.clearInput=function(){var e={editing:!0,value:"",sources:o.props.sources,ownPlaces:!1};o.setState(e,(function(){return o.fetchFunction({value:"",cleanExecuted:!0})})),o.props.onClear&&o.props.onClear(o.props.id),o.input.focus()},o.inputClicked=function(e){if(o.input.focus(),o.props.isMobile&&o.props.lock(),!o.state.editing){var c={editing:!0,pendingSelection:null,renderMobileSearch:o.props.isMobile},n={editing:!0,pendingSelection:null,value:e};o.state.suggestions.length?(o.fetchFunction({value:o.state.value}),o.setState(c)):"object"!==F(e)&&e?o.setState(n,(function(){return o.fetchFunction({value:e})})):o.setState(c,(function(){return o.fetchFunction({value:o.state.value})}))}},o.storeInputReference=function(e){null!==e&&(o.input=e.input,o.props.storeRef&&o.props.storeRef(e.input))},o.fillInput=function(e){o.fInput=e.properties.name;var c={editing:!0,value:e.properties.name,checkPendingSelection:e,valid:!0};o.setState(c),o.fetchFunction({value:e.properties.name}),o.input.focus()},o.renderItem=function(e){var c="FutureRoute"===e.type?j({},e,{translatedText:ec(e)}):e,n=$e(e);return g.default.createElement(P.default,{item:c,content:n,loading:!o.state.valid,isMobile:o.props.isMobile,ariaFavouriteString:W.default.t("favourite"),color:o.props.color,accessiblePrimaryColor:o.props.accessiblePrimaryColor,fillInput:o.fillInput,fontWeights:o.props.fontWeights,getAutoSuggestIcons:o.props.getAutoSuggestIcons,modeIconColors:o.props.modeIconColors,modeSet:o.props.modeSet})},o.closeMobileSearch=function(){o.props.unlock(),o.setState({renderMobileSearch:!1,value:o.props.value},(function(){window.scrollTo(0,o.state.scrollY),o.onSuggestionsClearRequested()}))},o.keyDown=function(e){if(!o.selectionDone){var c=e.key;if("Escape"===c&&o.setState({editing:!1}),o.state.editing)return"Enter"===c&&""!==o.state.value&&o.setState({pendingSelection:!0},(function(){o.fetchFunction({value:o.state.value})})),void o.inputClicked();if("Enter"!==c&&"ArrowDown"!==c||""!==o.state.value){if("ArrowDown"===c&&""!==o.state.value){var n={editing:!0,value:o.state.value};o.setState(n,(function(){return o.fetchFunction({value:o.state.value})}))}o.state.editing||o.setState({editing:!0}),"Tab"===c&&o.onBlur()}else o.clearInput()}},o.suggestionAsAriaContent=function(){var e=[],c=o.state.suggestions[0];return c&&(c.type&&c.type.includes("Favourite")&&e.push(W.default.t("favourite")),e=e.concat($e(o.state.suggestions[0]))),V(new Set(e)).join(" - ")},o.clearOldSearches=function(){var e=o.props.searchContext,c=e.context,n=e.clearOldSearches,t=e.clearFutureRoutes;c&&n&&(n(c),t&&t(c),o.fetchFunction({value:o.state.value}))},o.isOriginDestinationOrViapoint=function(){return"origin"===o.props.id||"destination"===o.props.id||"via-point"===o.props.id||"origin-stop-near-you"===o.props.id},o.onFocus=function(){["Valittu sijainti","Nykyinen sijaintisi","Current position","Selected location","Vald position","Använd min position","Min position","Käytä nykyistä sijaintia","Use current location","Your current location"].includes(o.state.value)&&o.clearInput();var e=window.pageYOffset;return o.setState({scrollY:e})},Pe.tz.setDefault(e.timeZone),Pe.locale(e.lang),o.state={value:e.value,suggestions:[],editing:!1,valid:!0,renderMobileSearch:!1,sources:e.sources,ownPlaces:!1,typingTimer:null,typing:!1,pendingSelection:null,suggestionIndex:0,cleanExecuted:!1,scrollY:0},Object.keys(xe).forEach((function(e){W.default.addResourceBundle(e,"translation",xe[e])})),o}return J(n,[{key:"shouldComponentUpdate",value:function(e,c){return!C.default(c,this.state)||!C.default(e,this.props)}},{key:"render",value:function(){var e=this;W.default.language!==this.props.lang&&W.default.changeLanguage(this.props.lang);var c=this.state,n=c.value,o=c.suggestions,t=c.renderMobileSearch,a=c.cleanExecuted,i={placeholder:this.props.translatedPlaceholder?this.props.translatedPlaceholder:W.default.t(this.props.placeholder),value:n,onChange:this.onChange,onBlur:this.onBlur,className:"".concat(He.input," ").concat(this.props.isMobile&&this.props.transportMode?He.thin:""," ").concat(He[this.props.id]||""," ").concat(this.state.value?He.hasValue:""," ").concat(this.props.inputClassName),onKeyDown:this.keyDown,required:this.props.required},r=this.props.id.replace("searchfield-",""),M=this.props.ariaLabel||W.default.t(r);M=M.replace("searchfield-","");var s=this.props.required?"".concat(W.default.t("required"),"."):"",l=this.props.isMobile?W.default.t("search-autosuggest-label-mobile"):W.default.t("search-autosuggest-label-desktop"),u=W.default.t("search-autosuggest-len",{count:o.length}),p=function(){return e.suggestionAsAriaContent()||e.props.value?W.default.t("search-current-suggestion",{selection:e.suggestionAsAriaContent()||e.props.value}):""};return g.default.createElement(g.default.Fragment,null,g.default.createElement("span",{className:He["sr-only"],role:"alert"},!this.state.typing&&this.state.editing&&"".concat(u," ").concat(p())),this.props.isMobile&&g.default.createElement(Ge,{searchOpen:t,appElement:this.props.appElement,clearOldSearches:this.clearOldSearches,id:this.props.id,clearInput:this.clearInput,value:this.state.value,suggestions:[].concat(V(o),[{type:"clear-search-history",labelId:W.default.t("clear-search-history")}]),inputProps:j({},i,{placeholder:this.isOriginDestinationOrViapoint()?W.default.t("address-place-or-business"):i.placeholder}),fetchFunction:this.fetchFunction,onSuggestionsClearRequested:this.onSuggestionsClearRequested,getSuggestionValue:this.getSuggestionValue,renderSuggestion:this.renderItem,closeHandle:this.closeMobileSearch,ariaLabel:s.concat(" ").concat(M).concat(" ").concat(p()),label:this.props.mobileLabel?this.props.mobileLabel:W.default.t(this.props.id),onSuggestionSelected:this.onSelected,dialogHeaderText:W.default.t("delete-old-searches-header"),dialogPrimaryButtonText:W.default.t("delete"),dialogSecondaryButtonText:W.default.t("cancel"),clearInputButtonText:W.default.t("clear-button-label"),focusInput:a,color:this.props.color,hoverColor:this.props.hoverColor,accessiblePrimaryColor:this.props.accessiblePrimaryColor,fontWeights:this.props.fontWeights,showScroll:this.props.showScroll}),!t&&g.default.createElement("div",{className:_.default(He["autosuggest-input-container"],He[this.props.id]),style:{"--color":"".concat(this.props.color),"--hover-color":"".concat(this.props.hoverColor)}},this.props.icon&&g.default.createElement("div",{className:_.default(He["autosuggest-input-icon"],He[this.props.id],this.props.inputClassName&&"".concat(this.props.inputClassName,"-input-icon"))},g.default.createElement(x.default,{img:"".concat(this.props.icon)})),g.default.createElement(T.default,{alwaysRenderSuggestions:this.state.editing,id:this.props.id,suggestions:o,onSuggestionsFetchRequested:this.fetchFunction,onSuggestionsClearRequested:this.onSuggestionsClearRequested,getSuggestionValue:this.getSuggestionValue,renderSuggestion:this.renderItem,inputProps:j({},i,{onFocus:this.onFocus}),focusInputOnSuggestionClick:!0,shouldRenderSuggestions:function(){return e.state.editing},highlightFirstSuggestion:!this.state.ownPlaces,theme:He,renderInputComponent:function(c){return g.default.createElement(g.default.Fragment,null,g.default.createElement("label",{className:He["sr-only"],htmlFor:e.props.id},p().concat(" ").concat(s).concat(" ").concat(M).concat(" ").concat(l)),g.default.createElement("input",Object.assign({"aria-label":p().concat(" ").concat(s).concat(" ").concat(M).concat(" ").concat(l),id:e.props.id,onClick:e.inputClicked,onKeyDown:e.keyDown},c)),e.state.value&&e.clearButton())},onSuggestionSelected:this.onSelected,ref:this.storeInputReference})))}}]),n}(g.default.Component);cc.defaultProps={autoFocus:!1,className:"",icon:void 0,value:"",transportMode:void 0,lang:"fi",sources:[],isMobile:!1,color:"#007ac9",hoverColor:"#0062a1",accessiblePrimaryColor:"#0074be",timeZone:"Europe/Helsinki",pathOpts:{routesPrefix:"linjat",stopsPrefix:"pysakit"},mobileLabel:void 0,inputClassName:"",translatedPlaceholder:void 0,fontWeights:{medium:500},modeIconColors:{"mode-bus":"#007ac9","mode-rail":"#8c4799","mode-tram":"#008151","mode-metro":"#ed8c00","mode-ferry":"#007A97","mode-citybike":"#f2b62d"},required:!1,modeSet:void 0,showScroll:!1},"production"!==process.env.NODE_ENV&&(cc.propTypes={appElement:N.default.string.isRequired,autoFocus:N.default.bool,className:N.default.string,icon:N.default.string,id:N.default.string.isRequired,placeholder:N.default.string.isRequired,translatedPlaceholder:N.default.string,value:N.default.string,searchContext:N.default.any.isRequired,ariaLabel:N.default.string,onSelect:N.default.func,transportMode:N.default.string,filterResults:N.default.func,geocodingSize:N.default.number,onClear:N.default.func,storeRef:N.default.func,handleViaPoints:N.default.func,focusChange:N.default.func,lang:N.default.string,sources:N.default.arrayOf(N.default.string),targets:N.default.arrayOf(N.default.string),isMobile:N.default.bool,color:N.default.string,hoverColor:N.default.string,accessiblePrimaryColor:N.default.string,timeZone:N.default.string,pathOpts:N.default.shape({routesPrefix:N.default.string,stopsPrefix:N.default.string}),mobileLabel:N.default.string,lock:N.default.func.isRequired,unlock:N.default.func.isRequired,refPoint:N.default.object,inputClassName:N.default.string,fontWeights:N.default.shape({medium:N.default.number}),modeIconColors:N.default.object,getAutoSuggestIcons:N.default.object,required:N.default.bool,modeSet:N.default.string,showScroll:N.default.bool,isEmbedded:N.default.bool});var nc,oc=(nc=cc,function(e){var c=Qe.useScrollLock(),n=c.lock,o=c.unlock;return g.default.createElement(nc,Object.assign({lock:n,unlock:o},e))});e.default=oc,Object.defineProperty(e,"__esModule",{value:!0})}));
46
46
  //# sourceMappingURL=index.js.map