@digitransit-component/digitransit-component-favourite-bar 5.0.8 → 6.0.0

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
@@ -1,2 +1,610 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("prop-types"),require("react"),require("react-i18next"),require("classnames"),require("lodash/differenceWith"),require("lodash/isEqual"),require("lodash/isEmpty"),require("@hsl-fi/shimmer"),require("@digitransit-component/digitransit-component-suggestion-item"),require("@digitransit-component/digitransit-component-icon"),require("lodash/uniqWith"),require("lodash/memoize"),require("lodash/escapeRegExp"),require("lodash/cloneDeep"),require("i18next")):"function"==typeof define&&define.amd?define(["exports","prop-types","react","react-i18next","classnames","lodash/differenceWith","lodash/isEqual","lodash/isEmpty","@hsl-fi/shimmer","@digitransit-component/digitransit-component-suggestion-item","@digitransit-component/digitransit-component-icon","lodash/uniqWith","lodash/memoize","lodash/escapeRegExp","lodash/cloneDeep","i18next"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@digitransit-component/digitransit-component-favourite-bar"]={},e.PropTypes,e.React,e.reactI18next,e.cx,e.differenceWith,e.isEqual,e.isEmpty,e.Shimmer,e.SuggestionItem,e.Icon,e.uniqWith,e.memoize,e.escapeRegExp,e.cloneDeep,e.i18next)}(this,function(e,t,n,s,i,o,a,r,l,d,u,c,f,_,p,h){"use strict";function m(e){return e&&e.__esModule?e:{default:e}}var g=m(t),v=m(n),y=m(i),w=m(o),x=m(a),b=m(r),E=m(l),k=m(d),R=m(u),F=m(f),O=m(_),I=m(p);function S(e){return S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},S(e)}function L(e){var t=function(e,t){if("object"!=S(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var s=n.call(e,t);if("object"!=S(s))return s;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==S(t)?t:t+""}function j(e,t,n){return(t=L(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const q=e=>e.localadmin||e.localadmin||e.address&&e.address.lastIndexOf(",")<e.address.length-2&&e.address.substring(e.address.lastIndexOf(",")+2)||"",H=({id:e,code:t})=>t||(void 0!==e&&void 0!==e.indexOf&&-1!==e.indexOf("#")?e.substring(e.indexOf("#")+1):void 0),W=(e,t)=>[e||t&&t.split(",")[0],"string"==typeof t?t.replace(new RegExp(`${O.default(e)}([ ,]|$)+`),""):""];F.default((e,t=!1)=>{switch(e.layer){case"currentPosition":return[e.labelId,e.address];case"selectFromMap":case"ownLocations":case"back":return[e.labelId];case"favouritePlace":return W(e.name,e.address);case"favouriteVehicleRentalStation":case"bikestation":return[e.name];case"favouriteRoute":case"route-BUS":case"route-TRAM":case"route-RAIL":case"route-SUBWAY":case"route-FERRY":case"route-FUNICULAR":case"route-AIRPLANE":return!t&&e.shortName?[e.gtfsId,e.mode.toLowerCase(),e.longName]:[e.shortName,e.longName,e.agency?e.agency.name:void 0];case"venue":case"address":case"street":return[e.name,e.label.replace(new RegExp(`${O.default(e.name)}(,)?( )?`),"")];case"favouriteStop":case"stop":return t?[e.name||e.label||e.address&&e.address.split(",")[0],q(e)]:[e.name,e.id,H(e),q(e)];default:return[e.name||e.label||e.address&&e.address.split(",")[0],q(e)]}},(e,t)=>{const n=I.default(e);return n.plain=t,n});var P={"button-shared":"styles_button-shared__SvYPP","favourite-container":"styles_favourite-container__-FJ4E",expandButton:"styles_expandButton__HhwVE","favourite-content":"styles_favourite-content__XfiHR","shimmer-shared":"styles_shimmer-shared__8ctsd",shimmer:"styles_shimmer__GiosY",icon:"styles_icon__W-oyj",place:"styles_place__ymmqu",home:"styles_home__pPJsU",school:"styles_school__Gq5Lo",sport:"styles_sport__fBWhN",shopping:"styles_shopping__EFuXp",work:"styles_work__fs304","favourite-location":"styles_favourite-location__dGlSc",name:"styles_name__O-aXc",address:"styles_address__Kvq32",plus:"styles_plus__dwT5g",arrow:"styles_arrow__N3LQQ",rotate:"styles_rotate__4cHBr","favourite-suggestion-container":"styles_favourite-suggestion-container__tUOWb",divider:"styles_divider__I8SMP","favourite-suggestion-list":"styles_favourite-suggestion-list__TipcA","favourite-suggestion-item":"styles_favourite-suggestion-item__6cdmu",custom:"styles_custom__4R1qq"};!function(e,t){void 0===t&&(t={});var n=t.insertAt;if("undefined"!=typeof document){var s=document.head||document.getElementsByTagName("head")[0],i=document.createElement("style");i.type="text/css","top"===n&&s.firstChild?s.insertBefore(i,s.firstChild):s.appendChild(i),i.styleSheet?i.styleSheet.cssText=e:i.appendChild(document.createTextNode(e))}}(".styles_button-shared__SvYPP, .styles_favourite-container__-FJ4E .styles_expandButton__HhwVE, .styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR {\n background-color: white;\n display: flex;\n flex-direction: row;\n justify-content: center;\n align-items: center;\n border-radius: 5px;\n border: 1px solid #ddd;\n cursor: pointer;\n}\n.styles_button-shared__SvYPP:hover, .styles_favourite-container__-FJ4E .styles_expandButton__HhwVE:hover, .styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR:hover {\n box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);\n}\n\n.styles_shimmer-shared__8ctsd, .styles_favourite-container__-FJ4E .styles_expandButton__HhwVE > div, .styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR > div {\n display: flex;\n align-items: center;\n overflow: hidden;\n}\n.styles_shimmer-shared__8ctsd .styles_shimmer__GiosY, .styles_favourite-container__-FJ4E .styles_expandButton__HhwVE > div .styles_shimmer__GiosY, .styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR > div .styles_shimmer__GiosY {\n border-radius: 5px;\n}\n\n.styles_favourite-container__-FJ4E {\n display: flex;\n position: relative;\n z-index: 1;\n width: 100%;\n height: 50px;\n flex-shrink: 1;\n flex-direction: row;\n justify-content: space-between;\n align-items: center;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR {\n width: auto;\n min-width: 0;\n flex: 1;\n flex-grow: 1;\n height: 100%;\n position: relative;\n padding: 0;\n margin-right: 8px;\n overflow: hidden;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj {\n display: flex;\n width: 50px;\n height: 100%;\n justify-content: center;\n align-items: center;\n flex-shrink: 1;\n}\n@media screen and (min-width: 375px) {\n .styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj {\n flex-shrink: 0;\n }\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj svg {\n width: 20px;\n height: 20px;\n position: relative;\n left: 2px;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj.styles_place__ymmqu svg {\n width: 24px;\n height: 24px;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj.styles_home__pPJsU svg, .styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj.styles_school__Gq5Lo svg, .styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj.styles_sport__fBWhN svg, .styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj.styles_shopping__EFuXp svg {\n width: 18px;\n height: 18px;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_icon__W-oyj.styles_work__fs304 svg {\n width: 20px;\n height: 20px;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_favourite-location__dGlSc {\n white-space: nowrap;\n overflow: hidden;\n text-align: start;\n width: 100%;\n flex-direction: row;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_favourite-location__dGlSc .styles_name__O-aXc {\n font-family: inherit;\n font-size: 15px;\n margin-right: 6px;\n font-weight: var(--font-weight-medium);\n font-stretch: normal;\n font-style: normal;\n letter-spacing: -0.6px;\n color: #333;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_favourite-location__dGlSc .styles_name__O-aXc:empty {\n margin-top: 0;\n}\n.styles_favourite-container__-FJ4E .styles_favourite-content__XfiHR .styles_favourite-location__dGlSc .styles_address__Kvq32 {\n font-family: inherit;\n font-size: 12px;\n margin-right: 6px;\n font-weight: normal;\n font-stretch: normal;\n font-style: normal;\n line-height: 1.67;\n letter-spacing: -0.48px;\n color: #666;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.styles_favourite-container__-FJ4E .styles_expandButton__HhwVE {\n height: 100%;\n width: 42px;\n flex-shrink: 0;\n overflow: hidden;\n padding: 0;\n}\n.styles_favourite-container__-FJ4E .styles_expandButton__HhwVE > div {\n justify-content: center;\n}\n.styles_favourite-container__-FJ4E .styles_expandButton__HhwVE.styles_plus__dwT5g svg {\n width: 16px;\n height: 16px;\n}\n.styles_favourite-container__-FJ4E .styles_expandButton__HhwVE.styles_arrow__N3LQQ svg {\n width: 19px;\n height: 19px;\n transform: rotate(90deg);\n}\n.styles_favourite-container__-FJ4E .styles_expandButton__HhwVE.styles_arrow__N3LQQ.styles_rotate__4cHBr svg {\n transform: rotate(-90deg);\n}\n\n.styles_favourite-suggestion-container__tUOWb {\n position: relative;\n display: flex;\n justify-content: center;\n padding-top: 9px;\n}\n.styles_favourite-suggestion-container__tUOWb .styles_divider__I8SMP {\n display: block;\n height: 6px;\n background-color: #f2f5f7;\n border-top: 1px solid rgba(0, 0, 0, 0.1);\n}\n.styles_favourite-suggestion-container__tUOWb .styles_favourite-suggestion-list__TipcA {\n max-height: 30vh;\n list-style-type: none;\n padding: 0;\n position: absolute;\n z-index: 20;\n width: 100%;\n margin: 0 auto;\n border-radius: 5px;\n box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.16);\n border: solid 1px rgba(0, 0, 0, 0.1);\n background-color: #fff;\n overflow-x: hidden;\n overflow-y: scroll;\n}\n.styles_favourite-suggestion-container__tUOWb .styles_favourite-suggestion-item__6cdmu.styles_custom__4R1qq {\n font-size: 15px;\n font-weight: var(--font-weight-medium);\n letter-spacing: -0.5;\n}\n.styles_favourite-suggestion-container__tUOWb .styles_favourite-suggestion-item__6cdmu:hover {\n background-color: #f2f5f7;\n}");const N=h.createInstance({fallbackLng:"fi",resources:{de:{translation:{"add-favourite":"Füge Favorit hinzu","add-home":"Setze Zuhause","add-place":"Setze Ort","add-work":"Setze Arbeitsort",edit:"Bearbeiten","open-favourites":"Öffne Favoriten",home:"Zuhause",work:"Arbeit"}},en:{translation:{"add-destination":"Set as destination","add-favourite":"Add favourite","add-home":"Add home","add-place":"Add place","add-work":"Add work","favourites-list":"Favourites list",edit:"Edit","open-favourites":"Open favourites",home:"Home",work:"Work"}},fi:{translation:{"add-destination":"Aseta määränpääksi","add-favourite":"Lisää suosikki","add-home":"Lisää koti","add-place":"Lisää paikka","add-work":"Lisää työ","favourites-list":"Suosikit lista",edit:"Muokkaa","open-favourites":"Avaa suosikit",home:"Koti",work:"Työ"}},pl:{translation:{"add-destination":"Wybierz jako punkt docelowy","add-favourite":"Dodaj ulubione","add-home":"Dodaj dom","add-place":"Dodaj miejsce","add-work":"Dodaj pracę","favourites-list":"Lista ulubionych",edit:"Edytuj","open-favourites":"Pokaż ulubione",home:"Dom",work:"Praca"}},sv:{translation:{"add-destination":"Ställa in som destination","add-favourite":"Lägg till favorit","add-home":"Lägg till hem","add-place":"Lägg till plats","add-work":"Lägg till arbete","favourites-list":"Favoritlista",edit:"Redigera","open-favourites":"Öppna favoriter",home:"Hem",work:"Arbete"}}},defaultNS:"translation",react:{useSuspense:!0}});function J(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,s)}return n}function A(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?J(Object(n),!0).forEach(function(t){j(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):J(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}N.init();const D=e=>{const t=e&&(e.key||e.which||e.keyCode)||"";return!(!t||![13," ","Spacebar"].concat([32,"Enter"]).includes(t))&&(e.preventDefault(),!0)},X=e=>e&&(e.name||e.address)?W(e.name,e.address):[],C=({clickItem:e,iconId:t,text:n,label:i,isLoading:o,color:a,lang:r})=>{const[l]=s.useTranslation(),d=""===i?n:`${n} ${i} ${l("add-destination",{lng:r})}`;return v.default.createElement("button",{type:"button",tabIndex:"0",className:y.default(P["favourite-content"]),onClick:e,onKeyDown:t=>D(t)&&e(),"aria-label":d},v.default.createElement(E.default,{active:o,className:P.shimmer},v.default.createElement("span",{className:y.default(P.icon,P[t])},v.default.createElement(R.default,{img:t,color:a})),v.default.createElement("div",{className:P["favourite-location"]},v.default.createElement("div",{className:P.name},n),v.default.createElement("div",{className:P.address},i))))};"production"!==process.env.NODE_ENV&&(C.propTypes={clickItem:g.default.func.isRequired,iconId:g.default.string.isRequired,text:g.default.string.isRequired,label:g.default.string.isRequired,isLoading:g.default.bool,color:g.default.string.isRequired,lang:g.default.string.isRequired}),C.defaultProps={isLoading:!1};class T extends v.default.Component{constructor(e){super(e),j(this,"toggleList",()=>{(new Date).getTime()-this.state.timestamp>200&&this.setState(e=>({listOpen:!e.listOpen,timestamp:(new Date).getTime()}),()=>{this.state.listOpen?this.firstItemRef.current?.focus():this.expandListRef.current?.focus()})}),j(this,"translate",e=>this.props.t(e,{lng:this.props.lang})),j(this,"handleClickOutside",e=>{this.suggestionListRef.current&&this.expandListRef.current&&!this.suggestionListRef.current.contains(e.target)&&!this.expandListRef.current.contains(e.target)&&this.setState({listOpen:!1})}),j(this,"suggestionSelected",e=>{const{favourites:t}=this.state;e<t.length?this.props.onClickFavourite(t[e]):e===t.length?this.props.onAddPlace():e===t.length+1&&this.props.onEdit(),this.toggleList()}),j(this,"handleKeyDown",(e,t)=>{const{listOpen:n,favourites:s}=this.state,i=e&&(e.key||e.which||e.keyCode)||"";D(e)?n?this.suggestionSelected(t):this.toggleList():"Escape"===i||27===i?n&&this.toggleList():"Tab"!==i||e.shiftKey||t!==s.length+this.getCustomSuggestions().length-1||this.setState({listOpen:!1})}),j(this,"renderSuggestion",(e,t,n="")=>{const s=`favourite-suggestion-list--item-${t}`;return v.default.createElement("li",{key:`favourite-suggestion-item-${t}`},v.default.createElement("div",{role:"button",type:"button",tabIndex:"0",id:s,className:y.default(P["favourite-suggestion-item"]),onClick:()=>this.suggestionSelected(t),onKeyDown:e=>this.handleKeyDown(e,t),ref:0===t?this.firstItemRef:"",autoFocus:0===t,"aria-label":`${e?.name||""} ${e?.address||""} ${n}`},v.default.createElement(k.default,{item:e,colors:this.props.colors,fontWeights:this.props.fontWeights})))}),j(this,"getCustomSuggestions",()=>{const e=[{name:this.translate("add-place"),selectedIconId:"favourite"}];return 0===this.props.favourites.length?e:[...e,{name:this.translate("edit"),selectedIconId:"edit"}]}),this.state={listOpen:!1,firstFavourite:e.favourites[0]||null,secondFavourite:e.favourites[1]||null,favourites:e.favourites.slice(2,e.favourites.length),timestamp:0},this.expandListRef=v.default.createRef(),this.suggestionListRef=v.default.createRef(),this.firstItemRef=v.default.createRef()}componentDidMount(){document.addEventListener("mousedown",this.handleClickOutside)}static getDerivedStateFromProps(e,t){const{favourites:n}=t,s=e.favourites;return b.default(w.default(s,n,x.default))&&b.default(w.default(n,s,x.default))&&x.default(s,n)&&!b.default(s)?null:{firstFavourite:s[0]||null,secondFavourite:s[1]||null,favourites:s.slice(2,s.length)}}componentWillUnmount(){document.removeEventListener("mousedown",this.handleClickOutside)}render(){const{onClickFavourite:e,isLoading:t,fontWeights:n}=this.props,{primary:s}=this.props.colors,{listOpen:i,favourites:o,firstFavourite:a,secondFavourite:r}=this.state,l=0===this.props.favourites.length?"plus":"arrow",[d,u]=X(a),[c,f]=X(r);return v.default.createElement("div",{style:{"--font-weight-medium":n.medium}},v.default.createElement("div",{className:P["favourite-container"]},v.default.createElement(C,{text:d||this.translate("add-home"),label:u||"",clickItem:()=>a?e(a):this.props.onAddHome(),iconId:a&&a.selectedIconId?T.FavouriteIconIdToNameMap[a.selectedIconId]:"home",isLoading:t,color:s,lang:this.props.lang}),v.default.createElement(C,{text:c||this.translate("add-work"),label:f||"",clickItem:()=>r?e(r):this.props.onAddWork(),iconId:r&&r.selectedIconId?T.FavouriteIconIdToNameMap[r.selectedIconId]:"work",isLoading:t,color:s,lang:this.props.lang}),v.default.createElement("button",{type:"button",className:y.default(P.expandButton,P[l],i&&P.rotate),ref:this.expandListRef,id:"favourite-expand-button",onKeyDown:e=>this.handleKeyDown(e),onClick:()=>this.toggleList(),"aria-expanded":this.state.listOpen,"aria-label":this.translate("open-favourites")},v.default.createElement(E.default,{active:t},v.default.createElement(R.default,{img:l,color:s})))),v.default.createElement("div",{className:P["favourite-suggestion-container"]},i&&v.default.createElement("ul",{className:P["favourite-suggestion-list"],id:"favourite-suggestion-list",ref:this.suggestionListRef,"aria-label":this.translate("favourites-list")},o.map((e,t)=>{const n=W(e.name,e.address)[1];return this.renderSuggestion(A(A({},e),{},{address:n}),t,`, ${this.translate("add-destination")}`)}),o.length>0&&v.default.createElement("div",{"aria-hidden":!0,className:P.divider}),this.getCustomSuggestions().map((e,t)=>this.renderSuggestion(e,o.length+t,void 0)))))}}j(T,"defaultProps",{onClickFavourite:()=>({}),onAddPlace:()=>({}),onEdit:()=>({}),onAddHome:()=>({}),onAddWork:()=>({}),lang:"fi",isLoading:!1,colors:u.defaultColors,fontWeights:{medium:500}}),j(T,"FavouriteIconIdToNameMap",{"icon-icon_place":"place","icon-icon_home":"home","icon-icon_work":"work","icon-icon_sport":"sport","icon-icon_school":"school","icon-icon_shopping":"shopping",icon_home:"home",icon_work:"work"}),"production"!==process.env.NODE_ENV&&(T.propTypes={favourites:g.default.arrayOf(g.default.shape({address:g.default.string,gtfsId:g.default.string,gid:g.default.string,lat:g.default.number,name:g.default.string,lon:g.default.number,selectedIconId:g.default.string,favouriteId:g.default.string})).isRequired,onClickFavourite:g.default.func,onAddPlace:g.default.func,onEdit:g.default.func,onAddHome:g.default.func,onAddWork:g.default.func,lang:g.default.string,isLoading:g.default.bool,colors:g.default.objectOf(g.default.string),fontWeights:g.default.shape({medium:g.default.number}),t:g.default.func.isRequired});const B=s.withTranslation()(T);e.default=e=>v.default.createElement(s.I18nextProvider,{i18n:N},v.default.createElement(B,e)),Object.defineProperty(e,"__esModule",{value:!0})});
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import { withTranslation, useTranslation, I18nextProvider } from 'react-i18next';
4
+ import cx from 'classnames';
5
+ import differenceWith from 'lodash/differenceWith.js';
6
+ import isEqual from 'lodash/isEqual.js';
7
+ import isEmpty from 'lodash/isEmpty.js';
8
+ import Shimmer from '@hsl-fi/shimmer';
9
+ import SuggestionItem from '@digitransit-component/digitransit-component-suggestion-item';
10
+ import Icon, { defaultColors } from '@digitransit-component/digitransit-component-icon';
11
+ import 'lodash/uniqWith.js';
12
+ import memoize from 'lodash/memoize.js';
13
+ import escapeRegExp from 'lodash/escapeRegExp.js';
14
+ import cloneDeep from 'lodash/cloneDeep.js';
15
+ import { createInstance } from 'i18next';
16
+
17
+ function _typeof(o) {
18
+ "@babel/helpers - typeof";
19
+
20
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
21
+ return typeof o;
22
+ } : function (o) {
23
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
24
+ }, _typeof(o);
25
+ }
26
+
27
+ function toPrimitive(t, r) {
28
+ if ("object" != _typeof(t) || !t) return t;
29
+ var e = t[Symbol.toPrimitive];
30
+ if (void 0 !== e) {
31
+ var i = e.call(t, r);
32
+ if ("object" != _typeof(i)) return i;
33
+ throw new TypeError("@@toPrimitive must return a primitive value.");
34
+ }
35
+ return ("string" === r ? String : Number)(t);
36
+ }
37
+
38
+ function toPropertyKey(t) {
39
+ var i = toPrimitive(t, "string");
40
+ return "symbol" == _typeof(i) ? i : i + "";
41
+ }
42
+
43
+ function _defineProperty(e, r, t) {
44
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
45
+ value: t,
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true
49
+ }) : e[r] = t, e;
50
+ }
51
+
52
+ /**
53
+ * Location properties.
54
+ * @typedef {LocationProperties}
55
+ * @property {string} layer Suggestion layer.
56
+ * @property {lat} [number]
57
+ * @property {lon} [number]
58
+ * @property {string} address Address.
59
+ */
60
+
61
+ /**
62
+ * Returns localadmin (city name) for suggestions
63
+ *
64
+ * @name getLocaladmin
65
+ * @param {Object} suggestion suggestion's properties from geocoding or a favourite stop/station.
66
+ * Expects last part of an address (after ',') to contain the city name of the suggestion location.
67
+ * @returns {String} City name or empty string
68
+ */
69
+ const getLocaladmin = suggestion => suggestion.localadmin || suggestion.localadmin || suggestion.address && suggestion.address.lastIndexOf(',') < suggestion.address.length - 2 && suggestion.address.substring(suggestion.address.lastIndexOf(',') + 2) || '';
70
+ const getStopCode = ({
71
+ id,
72
+ code
73
+ }) => {
74
+ if (code) {
75
+ return code;
76
+ }
77
+ if (id === undefined || typeof id.indexOf === 'undefined' || id.indexOf('#') === -1) {
78
+ return undefined;
79
+ }
80
+ // id from pelias
81
+ return id.substring(id.indexOf('#') + 1);
82
+ };
83
+ const formatFavouritePlaceLabel = (name, address) => [name || address && address.split(',')[0], typeof address === 'string' ? address.replace(new RegExp(`${escapeRegExp(name)}([ ,]|$)+`), '') : ''];
84
+
85
+ /**
86
+ * Format suggestion-pair [name, address] by `suggestion.layer`.
87
+ *
88
+ * @name getNameLabel
89
+ * @param {LocationProperties} suggestion
90
+ * @param {boolean} [plain]
91
+ *
92
+ * @returns {Array.<string>} Formatted label.
93
+ */
94
+ memoize((suggestion, plain = false) => {
95
+ switch (suggestion.layer) {
96
+ case 'currentPosition':
97
+ return [suggestion.labelId, suggestion.address];
98
+ case 'selectFromMap':
99
+ case 'ownLocations':
100
+ case 'back':
101
+ return [suggestion.labelId];
102
+ case 'favouritePlace':
103
+ return formatFavouritePlaceLabel(suggestion.name, suggestion.address);
104
+ case 'favouriteVehicleRentalStation':
105
+ case 'bikestation':
106
+ return [suggestion.name];
107
+ case 'favouriteRoute':
108
+ case 'route-BUS':
109
+ case 'route-TRAM':
110
+ case 'route-RAIL':
111
+ case 'route-SUBWAY':
112
+ case 'route-FERRY':
113
+ case 'route-FUNICULAR':
114
+ case 'route-AIRPLANE':
115
+ return !plain && suggestion.shortName ? [suggestion.gtfsId, suggestion.mode.toLowerCase(), suggestion.longName] : [suggestion.shortName, suggestion.longName, suggestion.agency ? suggestion.agency.name : undefined];
116
+ case 'venue':
117
+ case 'address':
118
+ case 'street':
119
+ return [suggestion.name, suggestion.label.replace(new RegExp(`${escapeRegExp(suggestion.name)}(,)?( )?`), '')];
120
+ case 'favouriteStop':
121
+ case 'stop':
122
+ return plain ? [suggestion.name || suggestion.label || suggestion.address && suggestion.address.split(',')[0], getLocaladmin(suggestion)] : [suggestion.name, suggestion.id, getStopCode(suggestion), getLocaladmin(suggestion)];
123
+ case 'favouriteStation':
124
+ case 'station':
125
+ default:
126
+ return [suggestion.name || suggestion.label || suggestion.address && suggestion.address.split(',')[0], getLocaladmin(suggestion)];
127
+ }
128
+ }, (item, plain) => {
129
+ const i = cloneDeep(item);
130
+ i.plain = plain;
131
+ return i;
132
+ });
133
+
134
+ function styleInject(css, ref) {
135
+ if ( ref === void 0 ) ref = {};
136
+ var insertAt = ref.insertAt;
137
+
138
+ if (typeof document === 'undefined') { return; }
139
+
140
+ var head = document.head || document.getElementsByTagName('head')[0];
141
+ var style = document.createElement('style');
142
+ style.type = 'text/css';
143
+
144
+ if (insertAt === 'top') {
145
+ if (head.firstChild) {
146
+ head.insertBefore(style, head.firstChild);
147
+ } else {
148
+ head.appendChild(style);
149
+ }
150
+ } else {
151
+ head.appendChild(style);
152
+ }
153
+
154
+ if (style.styleSheet) {
155
+ style.styleSheet.cssText = css;
156
+ } else {
157
+ style.appendChild(document.createTextNode(css));
158
+ }
159
+ }
160
+
161
+ var css_248z = ".styles_button-shared__RSwxE, .styles_favourite-container__WTJm3 .styles_expandButton__mkemf, .styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 {\n background-color: white;\n display: flex;\n flex-direction: row;\n justify-content: center;\n align-items: center;\n border-radius: 5px;\n border: 1px solid #ddd;\n cursor: pointer;\n}\n.styles_button-shared__RSwxE:hover, .styles_favourite-container__WTJm3 .styles_expandButton__mkemf:hover, .styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1:hover {\n box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);\n}\n\n.styles_shimmer-shared__MGBAa, .styles_favourite-container__WTJm3 .styles_expandButton__mkemf > div, .styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 > div {\n display: flex;\n align-items: center;\n overflow: hidden;\n}\n.styles_shimmer-shared__MGBAa .styles_shimmer__bIP9J, .styles_favourite-container__WTJm3 .styles_expandButton__mkemf > div .styles_shimmer__bIP9J, .styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 > div .styles_shimmer__bIP9J {\n border-radius: 5px;\n}\n\n.styles_favourite-container__WTJm3 {\n display: flex;\n position: relative;\n z-index: 1;\n width: 100%;\n height: 50px;\n flex-shrink: 1;\n flex-direction: row;\n justify-content: space-between;\n align-items: center;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 {\n width: auto;\n min-width: 0;\n flex: 1;\n flex-grow: 1;\n height: 100%;\n position: relative;\n padding: 0;\n margin-right: 8px;\n overflow: hidden;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD {\n display: flex;\n width: 50px;\n height: 100%;\n justify-content: center;\n align-items: center;\n flex-shrink: 1;\n}\n@media screen and (min-width: 375px) {\n .styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD {\n flex-shrink: 0;\n }\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD svg {\n width: 20px;\n height: 20px;\n position: relative;\n left: 2px;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD.styles_place__4mHYj svg {\n width: 24px;\n height: 24px;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD.styles_home__msJXd svg, .styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD.styles_school__Hta8J svg, .styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD.styles_sport__YFDd0 svg, .styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD.styles_shopping__jMKed svg {\n width: 18px;\n height: 18px;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_icon__mAwUD.styles_work__uZX4R svg {\n width: 20px;\n height: 20px;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_favourite-location__RiyEV {\n white-space: nowrap;\n overflow: hidden;\n text-align: start;\n width: 100%;\n flex-direction: row;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_favourite-location__RiyEV .styles_name__Fvsvr {\n font-family: inherit;\n font-size: 15px;\n margin-right: 6px;\n font-weight: var(--font-weight-medium);\n font-stretch: normal;\n font-style: normal;\n letter-spacing: -0.6px;\n color: #333;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_favourite-location__RiyEV .styles_name__Fvsvr:empty {\n margin-top: 0;\n}\n.styles_favourite-container__WTJm3 .styles_favourite-content__6gqt1 .styles_favourite-location__RiyEV .styles_address__iBEhu {\n font-family: inherit;\n font-size: 12px;\n margin-right: 6px;\n font-weight: normal;\n font-stretch: normal;\n font-style: normal;\n line-height: 1.67;\n letter-spacing: -0.48px;\n color: #666;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.styles_favourite-container__WTJm3 .styles_expandButton__mkemf {\n height: 100%;\n width: 42px;\n flex-shrink: 0;\n overflow: hidden;\n padding: 0;\n}\n.styles_favourite-container__WTJm3 .styles_expandButton__mkemf > div {\n justify-content: center;\n}\n.styles_favourite-container__WTJm3 .styles_expandButton__mkemf.styles_plus__ryt4n svg {\n width: 16px;\n height: 16px;\n}\n.styles_favourite-container__WTJm3 .styles_expandButton__mkemf.styles_arrow__EbmBZ svg {\n width: 19px;\n height: 19px;\n transform: rotate(90deg);\n}\n.styles_favourite-container__WTJm3 .styles_expandButton__mkemf.styles_arrow__EbmBZ.styles_rotate__Nw2-A svg {\n transform: rotate(-90deg);\n}\n\n.styles_favourite-suggestion-container__MVZBj {\n position: relative;\n display: flex;\n justify-content: center;\n padding-top: 9px;\n}\n.styles_favourite-suggestion-container__MVZBj .styles_divider__podkI {\n display: block;\n height: 6px;\n background-color: #f2f5f7;\n border-top: 1px solid rgba(0, 0, 0, 0.1);\n}\n.styles_favourite-suggestion-container__MVZBj .styles_favourite-suggestion-list__boIJY {\n max-height: 30vh;\n list-style-type: none;\n padding: 0;\n position: absolute;\n z-index: 20;\n width: 100%;\n margin: 0 auto;\n border-radius: 5px;\n box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.16);\n border: solid 1px rgba(0, 0, 0, 0.1);\n background-color: #fff;\n overflow-x: hidden;\n overflow-y: scroll;\n}\n.styles_favourite-suggestion-container__MVZBj .styles_favourite-suggestion-item__ptExh.styles_custom__87c-n {\n font-size: 15px;\n font-weight: var(--font-weight-medium);\n letter-spacing: -0.5;\n}\n.styles_favourite-suggestion-container__MVZBj .styles_favourite-suggestion-item__ptExh:hover {\n background-color: #f2f5f7;\n}";
162
+ var styles = {"button-shared":"styles_button-shared__RSwxE","favourite-container":"styles_favourite-container__WTJm3","expandButton":"styles_expandButton__mkemf","favourite-content":"styles_favourite-content__6gqt1","shimmer-shared":"styles_shimmer-shared__MGBAa","shimmer":"styles_shimmer__bIP9J","icon":"styles_icon__mAwUD","place":"styles_place__4mHYj","home":"styles_home__msJXd","school":"styles_school__Hta8J","sport":"styles_sport__YFDd0","shopping":"styles_shopping__jMKed","work":"styles_work__uZX4R","favourite-location":"styles_favourite-location__RiyEV","name":"styles_name__Fvsvr","address":"styles_address__iBEhu","plus":"styles_plus__ryt4n","arrow":"styles_arrow__EbmBZ","rotate":"styles_rotate__Nw2-A","favourite-suggestion-container":"styles_favourite-suggestion-container__MVZBj","divider":"styles_divider__podkI","favourite-suggestion-list":"styles_favourite-suggestion-list__boIJY","favourite-suggestion-item":"styles_favourite-suggestion-item__ptExh","custom":"styles_custom__87c-n"};
163
+ styleInject(css_248z);
164
+
165
+ /* eslint sort-keys: "error" */
166
+ const translations = {
167
+ de: {
168
+ translation: {
169
+ 'add-favourite': 'Füge Favorit hinzu',
170
+ 'add-home': 'Setze Zuhause',
171
+ 'add-place': 'Setze Ort',
172
+ 'add-work': 'Setze Arbeitsort',
173
+ edit: 'Bearbeiten',
174
+ home: 'Zuhause',
175
+ 'open-favourites': 'Öffne Favoriten',
176
+ work: 'Arbeit'
177
+ }
178
+ },
179
+ en: {
180
+ translation: {
181
+ 'add-destination': 'Set as destination',
182
+ 'add-favourite': 'Add favourite',
183
+ 'add-home': 'Add home',
184
+ 'add-place': 'Add place',
185
+ 'add-work': 'Add work',
186
+ edit: 'Edit',
187
+ 'favourites-list': 'Favourites list',
188
+ home: 'Home',
189
+ 'open-favourites': 'Open favourites',
190
+ work: 'Work'
191
+ }
192
+ },
193
+ fi: {
194
+ translation: {
195
+ 'add-destination': 'Aseta määränpääksi',
196
+ 'add-favourite': 'Lisää suosikki',
197
+ 'add-home': 'Lisää koti',
198
+ 'add-place': 'Lisää paikka',
199
+ 'add-work': 'Lisää työ',
200
+ edit: 'Muokkaa',
201
+ 'favourites-list': 'Suosikit lista',
202
+ home: 'Koti',
203
+ 'open-favourites': 'Avaa suosikit',
204
+ work: 'Työ'
205
+ }
206
+ },
207
+ pl: {
208
+ translation: {
209
+ 'add-destination': 'Wybierz jako punkt docelowy',
210
+ 'add-favourite': 'Dodaj ulubione',
211
+ 'add-home': 'Dodaj dom',
212
+ 'add-place': 'Dodaj miejsce',
213
+ 'add-work': 'Dodaj pracę',
214
+ edit: 'Edytuj',
215
+ 'favourites-list': 'Lista ulubionych',
216
+ home: 'Dom',
217
+ 'open-favourites': 'Pokaż ulubione',
218
+ work: 'Praca'
219
+ }
220
+ },
221
+ sv: {
222
+ translation: {
223
+ 'add-destination': 'Ställa in som destination',
224
+ 'add-favourite': 'Lägg till favorit',
225
+ 'add-home': 'Lägg till hem',
226
+ 'add-place': 'Lägg till plats',
227
+ 'add-work': 'Lägg till arbete',
228
+ edit: 'Redigera',
229
+ 'favourites-list': 'Favoritlista',
230
+ home: 'Hem',
231
+ 'open-favourites': 'Öppna favoriter',
232
+ work: 'Arbete'
233
+ }
234
+ }
235
+ };
236
+
237
+ const i18n = createInstance({
238
+ fallbackLng: 'fi',
239
+ // debug: true,
240
+ resources: translations,
241
+ defaultNS: 'translation',
242
+ react: {
243
+ useSuspense: true
244
+ }
245
+ });
246
+ i18n.init();
247
+
248
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
249
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
250
+ const isKeyboardSelectionEvent = event => {
251
+ const space = [13, ' ', 'Spacebar'];
252
+ const enter = [32, 'Enter'];
253
+ const key = event && (event.key || event.which || event.keyCode) || '';
254
+ if (!key || !space.concat(enter).includes(key)) {
255
+ return false;
256
+ }
257
+ event.preventDefault();
258
+ return true;
259
+ };
260
+
261
+ /**
262
+ * Utility to format location [name, address] pair.
263
+ * @param {LocationProperties} favourite
264
+ * @returns {Array.<string>}
265
+ */
266
+ const formatFavourite = favourite => favourite && (favourite.name || favourite.address) ? formatFavouritePlaceLabel(favourite.name, favourite.address) : [];
267
+ const FavouriteLocation = ({
268
+ clickItem,
269
+ iconId,
270
+ text,
271
+ label,
272
+ isLoading,
273
+ color,
274
+ lang
275
+ }) => {
276
+ const [t] = useTranslation();
277
+ const ariaLabel = label === '' ? text : `${text} ${label} ${t('add-destination', {
278
+ lng: lang
279
+ })}`;
280
+ return /*#__PURE__*/React.createElement("button", {
281
+ type: "button",
282
+ tabIndex: "0",
283
+ className: cx(styles['favourite-content']),
284
+ onClick: clickItem,
285
+ onKeyDown: e => isKeyboardSelectionEvent(e) && clickItem(),
286
+ "aria-label": ariaLabel
287
+ }, /*#__PURE__*/React.createElement(Shimmer, {
288
+ active: isLoading,
289
+ className: styles.shimmer
290
+ }, /*#__PURE__*/React.createElement("span", {
291
+ className: cx(styles.icon, styles[iconId])
292
+ }, /*#__PURE__*/React.createElement(Icon, {
293
+ img: iconId,
294
+ color: color
295
+ })), /*#__PURE__*/React.createElement("div", {
296
+ className: styles['favourite-location']
297
+ }, /*#__PURE__*/React.createElement("div", {
298
+ className: styles.name
299
+ }, text), /*#__PURE__*/React.createElement("div", {
300
+ className: styles.address
301
+ }, label))));
302
+ };
303
+ process.env.NODE_ENV !== "production" ? FavouriteLocation.propTypes = {
304
+ clickItem: PropTypes.func.isRequired,
305
+ iconId: PropTypes.string.isRequired,
306
+ text: PropTypes.string.isRequired,
307
+ label: PropTypes.string.isRequired,
308
+ isLoading: PropTypes.bool,
309
+ color: PropTypes.string.isRequired,
310
+ lang: PropTypes.string.isRequired
311
+ } : void 0;
312
+ FavouriteLocation.defaultProps = {
313
+ isLoading: false
314
+ };
315
+
316
+ /**
317
+ * FavouriteBar renders favourites. FavouriteBar displays the first two favourites, the rest are shown in a list.
318
+ * @example
319
+ * <FavouriteBar
320
+ * favourites={favourites}
321
+ * onClickFavourite={onClickFavourite}
322
+ * onAddPlace={this.addPlace}
323
+ * onAddHome={this.addHome}
324
+ * onAddWork={this.addWork}
325
+ * lang={this.props.lang}
326
+ * isLoading={this.props.isLoading}
327
+ * />
328
+ */
329
+ class FavouriteBar extends React.Component {
330
+ constructor(props) {
331
+ super(props);
332
+ _defineProperty(this, "toggleList", () => {
333
+ const eventDiff = new Date().getTime() - this.state.timestamp;
334
+ if (eventDiff > 200) {
335
+ this.setState(prevState => ({
336
+ listOpen: !prevState.listOpen,
337
+ timestamp: new Date().getTime()
338
+ }), () => {
339
+ if (this.state.listOpen) {
340
+ this.firstItemRef.current?.focus();
341
+ } else {
342
+ this.expandListRef.current?.focus();
343
+ }
344
+ });
345
+ }
346
+ });
347
+ _defineProperty(this, "translate", id => {
348
+ return this.props.t(id, {
349
+ lng: this.props.lang
350
+ });
351
+ });
352
+ _defineProperty(this, "handleClickOutside", event => {
353
+ if (this.suggestionListRef.current && this.expandListRef.current && !this.suggestionListRef.current.contains(event.target) && !this.expandListRef.current.contains(event.target)) {
354
+ this.setState({
355
+ listOpen: false
356
+ });
357
+ }
358
+ });
359
+ _defineProperty(this, "suggestionSelected", index => {
360
+ const {
361
+ favourites
362
+ } = this.state;
363
+ if (index < favourites.length) {
364
+ this.props.onClickFavourite(favourites[index]);
365
+ } else if (index === favourites.length) {
366
+ this.props.onAddPlace();
367
+ } else if (index === favourites.length + 1) {
368
+ this.props.onEdit();
369
+ }
370
+ this.toggleList();
371
+ });
372
+ _defineProperty(this, "handleKeyDown", (event, index) => {
373
+ const {
374
+ listOpen,
375
+ favourites
376
+ } = this.state;
377
+ const key = event && (event.key || event.which || event.keyCode) || '';
378
+ if (isKeyboardSelectionEvent(event)) {
379
+ if (!listOpen) {
380
+ this.toggleList();
381
+ } else {
382
+ this.suggestionSelected(index);
383
+ }
384
+ } else if (key === 'Escape' || key === 27) {
385
+ if (listOpen) {
386
+ this.toggleList();
387
+ }
388
+ } else if (key === 'Tab' && !event.shiftKey && index === favourites.length + this.getCustomSuggestions().length - 1) {
389
+ this.setState({
390
+ listOpen: false
391
+ });
392
+ }
393
+ });
394
+ _defineProperty(this, "renderSuggestion", (item, index, ariaLabelSuffix = '') => {
395
+ const id = `favourite-suggestion-list--item-${index}`;
396
+ return /*#__PURE__*/React.createElement("li", {
397
+ key: `favourite-suggestion-item-${index}`
398
+ }, /*#__PURE__*/React.createElement("div", {
399
+ role: "button",
400
+ type: "button",
401
+ tabIndex: "0",
402
+ id: id,
403
+ className: cx(styles['favourite-suggestion-item']),
404
+ onClick: () => this.suggestionSelected(index),
405
+ onKeyDown: e => this.handleKeyDown(e, index),
406
+ ref: index === 0 ? this.firstItemRef : ''
407
+ // eslint-disable-next-line jsx-a11y/no-autofocus
408
+ ,
409
+ autoFocus: index === 0,
410
+ "aria-label": `${item?.name || ''} ${item?.address || ''} ${ariaLabelSuffix}`
411
+ }, /*#__PURE__*/React.createElement(SuggestionItem, {
412
+ item: item,
413
+ colors: this.props.colors,
414
+ fontWeights: this.props.fontWeights
415
+ })));
416
+ });
417
+ _defineProperty(this, "getCustomSuggestions", () => {
418
+ const customSuggestions = [{
419
+ name: this.translate('add-place'),
420
+ selectedIconId: 'favourite'
421
+ }];
422
+ if (this.props.favourites.length === 0) {
423
+ return customSuggestions;
424
+ }
425
+ return [...customSuggestions, {
426
+ name: this.translate('edit'),
427
+ selectedIconId: 'edit'
428
+ }];
429
+ });
430
+ this.state = {
431
+ listOpen: false,
432
+ firstFavourite: props.favourites[0] || null,
433
+ secondFavourite: props.favourites[1] || null,
434
+ favourites: props.favourites.slice(2, props.favourites.length),
435
+ timestamp: 0
436
+ };
437
+ this.expandListRef = /*#__PURE__*/React.createRef();
438
+ this.suggestionListRef = /*#__PURE__*/React.createRef();
439
+ this.firstItemRef = /*#__PURE__*/React.createRef();
440
+ }
441
+ componentDidMount() {
442
+ document.addEventListener('mousedown', this.handleClickOutside);
443
+ }
444
+ static getDerivedStateFromProps(nextProps, prevState) {
445
+ const {
446
+ favourites
447
+ } = prevState;
448
+ const nextFavourites = nextProps.favourites;
449
+ if (!isEmpty(differenceWith(nextFavourites, favourites, isEqual)) || !isEmpty(differenceWith(favourites, nextFavourites, isEqual)) || !isEqual(nextFavourites, favourites) || isEmpty(nextFavourites)) {
450
+ return {
451
+ firstFavourite: nextFavourites[0] || null,
452
+ secondFavourite: nextFavourites[1] || null,
453
+ favourites: nextFavourites.slice(2, nextFavourites.length)
454
+ };
455
+ }
456
+ return null;
457
+ }
458
+ componentWillUnmount() {
459
+ document.removeEventListener('mousedown', this.handleClickOutside);
460
+ }
461
+ render() {
462
+ const {
463
+ onClickFavourite,
464
+ isLoading,
465
+ fontWeights
466
+ } = this.props;
467
+ const {
468
+ primary
469
+ } = this.props.colors;
470
+ const {
471
+ listOpen,
472
+ favourites,
473
+ firstFavourite,
474
+ secondFavourite
475
+ } = this.state;
476
+ const expandIcon = this.props.favourites.length === 0 ? 'plus' : 'arrow';
477
+ const [name1, address1] = formatFavourite(firstFavourite);
478
+ const [name2, address2] = formatFavourite(secondFavourite);
479
+ return /*#__PURE__*/React.createElement("div", {
480
+ style: {
481
+ '--font-weight-medium': fontWeights.medium
482
+ }
483
+ }, /*#__PURE__*/React.createElement("div", {
484
+ className: styles['favourite-container']
485
+ }, /*#__PURE__*/React.createElement(FavouriteLocation, {
486
+ text: name1 || this.translate('add-home'),
487
+ label: address1 || '',
488
+ clickItem: () => firstFavourite ? onClickFavourite(firstFavourite) : this.props.onAddHome(),
489
+ iconId: firstFavourite && firstFavourite.selectedIconId ? FavouriteBar.FavouriteIconIdToNameMap[firstFavourite.selectedIconId] : 'home',
490
+ isLoading: isLoading,
491
+ color: primary,
492
+ lang: this.props.lang
493
+ }), /*#__PURE__*/React.createElement(FavouriteLocation, {
494
+ text: name2 || this.translate('add-work'),
495
+ label: address2 || '',
496
+ clickItem: () => secondFavourite ? onClickFavourite(secondFavourite) : this.props.onAddWork(),
497
+ iconId: secondFavourite && secondFavourite.selectedIconId ? FavouriteBar.FavouriteIconIdToNameMap[secondFavourite.selectedIconId] : 'work',
498
+ isLoading: isLoading,
499
+ color: primary,
500
+ lang: this.props.lang
501
+ }), /*#__PURE__*/React.createElement("button", {
502
+ type: "button",
503
+ className: cx(styles.expandButton, styles[expandIcon], listOpen && styles.rotate),
504
+ ref: this.expandListRef,
505
+ id: "favourite-expand-button",
506
+ onKeyDown: e => this.handleKeyDown(e),
507
+ onClick: () => this.toggleList(),
508
+ "aria-expanded": this.state.listOpen,
509
+ "aria-label": this.translate('open-favourites')
510
+ }, /*#__PURE__*/React.createElement(Shimmer, {
511
+ active: isLoading
512
+ }, /*#__PURE__*/React.createElement(Icon, {
513
+ img: expandIcon,
514
+ color: primary
515
+ })))), /*#__PURE__*/React.createElement("div", {
516
+ className: styles['favourite-suggestion-container']
517
+ }, listOpen && /*#__PURE__*/React.createElement("ul", {
518
+ className: styles['favourite-suggestion-list'],
519
+ id: "favourite-suggestion-list",
520
+ ref: this.suggestionListRef,
521
+ "aria-label": this.translate('favourites-list')
522
+ }, favourites.map((item, index) => {
523
+ const favouriteLabel = formatFavouritePlaceLabel(item.name, item.address);
524
+ const address = favouriteLabel[1];
525
+ return this.renderSuggestion(_objectSpread(_objectSpread({}, item), {}, {
526
+ address
527
+ }), index, `, ${this.translate('add-destination')}`);
528
+ }), favourites.length > 0 && /*#__PURE__*/React.createElement("div", {
529
+ "aria-hidden": true,
530
+ className: styles.divider
531
+ }), this.getCustomSuggestions().map((item, index) => this.renderSuggestion(item, favourites.length + index, undefined)))));
532
+ }
533
+ }
534
+ _defineProperty(FavouriteBar, "defaultProps", {
535
+ onClickFavourite: () => ({}),
536
+ onAddPlace: () => ({}),
537
+ onEdit: () => ({}),
538
+ onAddHome: () => ({}),
539
+ onAddWork: () => ({}),
540
+ lang: 'fi',
541
+ isLoading: false,
542
+ colors: defaultColors,
543
+ fontWeights: {
544
+ medium: 500
545
+ }
546
+ });
547
+ _defineProperty(FavouriteBar, "FavouriteIconIdToNameMap", {
548
+ 'icon-icon_place': 'place',
549
+ 'icon-icon_home': 'home',
550
+ 'icon-icon_work': 'work',
551
+ 'icon-icon_sport': 'sport',
552
+ 'icon-icon_school': 'school',
553
+ 'icon-icon_shopping': 'shopping',
554
+ // Map two buggy ids temporarily. This code can be removed at some point.
555
+ icon_home: 'home',
556
+ icon_work: 'work'
557
+ });
558
+ process.env.NODE_ENV !== "production" ? FavouriteBar.propTypes = {
559
+ /** Required. Array of favourites, favourite object contains following properties.
560
+ * @type {Array<object>}
561
+ * @property {string} address
562
+ * @property {string} gtfsId
563
+ * @property {string} gid
564
+ * @property {number} lat
565
+ * @property {number} lon
566
+ * @property {string} name
567
+ * @property {string} selectedIconId
568
+ * @property {string} favouriteId
569
+ */
570
+ favourites: PropTypes.arrayOf(PropTypes.shape({
571
+ address: PropTypes.string,
572
+ gtfsId: PropTypes.string,
573
+ gid: PropTypes.string,
574
+ lat: PropTypes.number,
575
+ name: PropTypes.string,
576
+ lon: PropTypes.number,
577
+ selectedIconId: PropTypes.string,
578
+ favouriteId: PropTypes.string
579
+ })).isRequired,
580
+ /** Optional. Function for clicking favourites. */
581
+ onClickFavourite: PropTypes.func,
582
+ /** Optional. Function for selecting "Add place" from suggestions. */
583
+ onAddPlace: PropTypes.func,
584
+ /** Optional. Function for selected "Edit" from suggestions. */
585
+ onEdit: PropTypes.func,
586
+ /** Optional. Function for "Add home" button. */
587
+ onAddHome: PropTypes.func,
588
+ /** Optional. Function for "Add work" button. */
589
+ onAddWork: PropTypes.func,
590
+ /** Optional. Language, fi, en or sv. */
591
+ lang: PropTypes.string,
592
+ /** Optional. Whether to show loading animation, true or false. */
593
+ isLoading: PropTypes.bool,
594
+ /** Optional color palette */
595
+ colors: PropTypes.objectOf(PropTypes.string),
596
+ /** Optional. */
597
+ fontWeights: PropTypes.shape({
598
+ /** Default value is 500. */
599
+ medium: PropTypes.number
600
+ }),
601
+ /** Translation function */
602
+ t: PropTypes.func.isRequired
603
+ } : void 0;
604
+ const FavouriteBarWithTranslation = withTranslation()(FavouriteBar);
605
+ var index = props => /*#__PURE__*/React.createElement(I18nextProvider, {
606
+ i18n: i18n
607
+ }, /*#__PURE__*/React.createElement(FavouriteBarWithTranslation, props));
608
+
609
+ export { index as default };
2
610
  //# sourceMappingURL=index.js.map