@opentripplanner/map-popup 0.0.1 → 1.0.0-alpha.1

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/esm/index.js ADDED
@@ -0,0 +1,106 @@
1
+ import React from "react";
2
+ import { Styled as BaseMapStyled } from "@opentripplanner/base-map";
3
+ import FromToLocationPicker from "@opentripplanner/from-to-location-picker"; // eslint-disable-next-line prettier/prettier
4
+
5
+ import { FormattedMessage, useIntl } from "react-intl";
6
+ import { flatten } from "flat";
7
+ import * as S from "./styled"; // Load the default messages.
8
+
9
+ import defaultEnglishMessages from "../i18n/en-US.yml";
10
+ import { makeDefaultGetEntityName } from "./util"; // HACK: We should flatten the messages loaded above because
11
+ // the YAML loaders behave differently between webpack and our version of jest:
12
+ // - the yaml loader for webpack returns a nested object,
13
+ // - the yaml loader for jest returns messages with flattened ids.
14
+
15
+ export var defaultMessages = flatten(defaultEnglishMessages);
16
+
17
+ var generateLocation = function generateLocation(entity, name) {
18
+ // @ts-expect-error some of these values may be null, but that's ok
19
+ var entityLon = entity.lon,
20
+ entityLat = entity.lat,
21
+ x = entity.x,
22
+ y = entity.y;
23
+ var lat = entityLat || x;
24
+ var lon = entityLon || y;
25
+ if (!lat || !lon) return null;
26
+ return {
27
+ lat: lat,
28
+ lon: lon,
29
+ name: name
30
+ };
31
+ };
32
+
33
+ var StationHubDetails = function StationHubDetails(_ref) {
34
+ var station = _ref.station;
35
+ return /*#__PURE__*/React.createElement(BaseMapStyled.PopupRow, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FormattedMessage, {
36
+ defaultMessage: defaultMessages["otpUi.MapPopup.availableBikes"],
37
+ description: "Label text for the number of bikes available",
38
+ id: "otpUi.MapPopup.availableBikes",
39
+ values: {
40
+ value: station.bikesAvailable
41
+ }
42
+ })), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FormattedMessage, {
43
+ defaultMessage: defaultMessages["otpUi.MapPopup.availableDocks"],
44
+ description: "Label text for the number of docks available",
45
+ id: "otpUi.MapPopup.availableDocks",
46
+ values: {
47
+ value: station.spacesAvailable
48
+ }
49
+ })));
50
+ };
51
+
52
+ var StopDetails = function StopDetails(_ref2) {
53
+ var id = _ref2.id,
54
+ setViewedStop = _ref2.setViewedStop;
55
+ return /*#__PURE__*/React.createElement(BaseMapStyled.PopupRow, null, /*#__PURE__*/React.createElement("strong", null, /*#__PURE__*/React.createElement(FormattedMessage, {
56
+ defaultMessage: defaultMessages["otpUi.MapPopup.stopId"],
57
+ description: "Displays the stop id",
58
+ id: "otpUi.MapPopup.stopId",
59
+ values: {
60
+ stopId: id
61
+ }
62
+ })), /*#__PURE__*/React.createElement(S.ViewStopButton, {
63
+ onClick: function onClick() {
64
+ return setViewedStop({
65
+ stopId: id
66
+ });
67
+ }
68
+ }, /*#__PURE__*/React.createElement(FormattedMessage, {
69
+ defaultMessage: defaultMessages["otpUi.MapPopup.stopViewer"],
70
+ description: "Text for link that opens the stop viewer",
71
+ id: "otpUi.MapPopup.stopViewer"
72
+ })));
73
+ };
74
+
75
+ /**
76
+ * Renders a map popup for a stop, scooter, or shared bike
77
+ */
78
+ export function MapPopup(_ref3) {
79
+ var configCompanies = _ref3.configCompanies,
80
+ entity = _ref3.entity,
81
+ getEntityName = _ref3.getEntityName,
82
+ setLocation = _ref3.setLocation,
83
+ setViewedStop = _ref3.setViewedStop;
84
+ var intl = useIntl();
85
+ if (!entity) return /*#__PURE__*/React.createElement(React.Fragment, null);
86
+ var getNameFunc = getEntityName || makeDefaultGetEntityName(intl, defaultMessages);
87
+ var name = getNameFunc(entity, configCompanies);
88
+ var bikesAvailablePresent = ("bikesAvailable" in entity);
89
+ var entityIsStationHub = bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.bikesAvailable) !== undefined && !(entity !== null && entity !== void 0 && entity.isFloatingBike); // @ts-expect-error ts doesn't understand entityIsStop
90
+
91
+ var stopId = !bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.code) || entity.id.split(":")[1] || entity.id;
92
+ return /*#__PURE__*/React.createElement(BaseMapStyled.MapOverlayPopup, null, /*#__PURE__*/React.createElement(BaseMapStyled.PopupTitle, null, name), entityIsStationHub && /*#__PURE__*/React.createElement(StationHubDetails, {
93
+ station: entity
94
+ }), setViewedStop && !bikesAvailablePresent && /*#__PURE__*/React.createElement(StopDetails, {
95
+ id: stopId,
96
+ setViewedStop: setViewedStop
97
+ }), setLocation && /*#__PURE__*/React.createElement(BaseMapStyled.PopupRow, null, /*#__PURE__*/React.createElement(FromToLocationPicker, {
98
+ label: true,
99
+ location: generateLocation(entity, name),
100
+ setLocation: setLocation
101
+ })));
102
+ }
103
+ export default MapPopup; // Rename styled components for export
104
+
105
+ export { S as Styled };
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx"],"names":["React","Styled","BaseMapStyled","FromToLocationPicker","FormattedMessage","useIntl","flatten","S","defaultEnglishMessages","makeDefaultGetEntityName","defaultMessages","generateLocation","entity","name","entityLon","lon","entityLat","lat","x","y","StationHubDetails","station","value","bikesAvailable","spacesAvailable","StopDetails","id","setViewedStop","stopId","MapPopup","configCompanies","getEntityName","setLocation","intl","getNameFunc","bikesAvailablePresent","entityIsStationHub","undefined","isFloatingBike","code","split"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAEA,SAASC,MAAM,IAAIC,aAAnB,QAAwC,2BAAxC;AACA,OAAOC,oBAAP,MAAiC,0CAAjC,C,CACA;;AAGA,SAASC,gBAAT,EAA2BC,OAA3B,QAA0C,YAA1C;AACA,SAASC,OAAT,QAAwB,MAAxB;AACA,OAAO,KAAKC,CAAZ,MAAmB,UAAnB,C,CAEA;;AACA,OAAOC,sBAAP,MAAmC,mBAAnC;AACA,SAASC,wBAAT,QAAyC,QAAzC,C,CAEA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,eAA0C,GAAGJ,OAAO,CAACE,sBAA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,MAAM,CAAEW,cAAR,MAA2Bc,SAApD,IAAiE,EAACzB,MAAD,aAACA,MAAD,eAACA,MAAM,CAAE0B,cAAT,CAA5F,CAToH,CAUpH;;AACA,MAAMV,MAAM,GAAG,CAACO,qBAAD,KAA0BvB,MAA1B,aAA0BA,MAA1B,uBAA0BA,MAAM,CAAE2B,IAAlC,KAA0C3B,MAAM,CAACc,EAAP,CAAUc,KAAV,CAAgB,GAAhB,EAAqB,CAArB,CAA1C,IAAqE5B,MAAM,CAACc,EAA3F;AAEA,sBACE,oBAAC,aAAD,CAAe,eAAf,qBACE,oBAAC,aAAD,CAAe,UAAf,QAA2Bb,IAA3B,CADF,EAGGuB,kBAAkB,iBAAI,oBAAC,iBAAD;AAAmB,IAAA,OAAO,EAAExB;AAA5B,IAHzB,EAMGe,aAAa,IAAI,CAACQ,qBAAlB,iBAA2C,oBAAC,WAAD;AAAa,IAAA,EAAE,EAAEP,MAAjB;AAAyB,IAAA,aAAa,EAAED;AAAxC,IAN9C,EASGK,WAAW,iBACV,oBAAC,aAAD,CAAe,QAAf,qBACE,oBAAC,oBAAD;AACE,IAAA,KAAK,MADP;AAEE,IAAA,QAAQ,EAAErB,gBAAgB,CAACC,MAAD,EAASC,IAAT,CAF5B;AAGE,IAAA,WAAW,EAAEmB;AAHf,IADF,CAVJ,CADF;AAqBD;AAED,eAAeH,QAAf,C,CAEA;;AACA,SAAStB,CAAC,IAAIN,MAAd","sourcesContent":["import React from \"react\";\n\nimport { Styled as BaseMapStyled } from \"@opentripplanner/base-map\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\n// eslint-disable-next-line prettier/prettier\nimport type { Company, ConfiguredCompany, Location, Station, Stop } from \"@opentripplanner/types\";\n\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport { flatten } from \"flat\";\nimport * as S from \"./styled\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../i18n/en-US.yml\";\nimport { makeDefaultGetEntityName } from \"./util\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nexport const defaultMessages: { [key: string]: string } = flatten(defaultEnglishMessages);\n\n\nconst generateLocation = (entity: Entity, name: string) => {\n // @ts-expect-error some of these values may be null, but that's ok\n const { lon: entityLon, lat: entityLat, x, y } = entity\n\n const lat = entityLat || x\n const lon = entityLon || y\n if (!lat || !lon) return null\n\n return { lat, lon, name };\n}\n\nconst StationHubDetails = ({ station }: { station: Station }) => {\n return (\n <BaseMapStyled.PopupRow>\n <div>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.MapPopup.availableBikes\"]\n }\n description=\"Label text for the number of bikes available\"\n id=\"otpUi.MapPopup.availableBikes\"\n values={{ value: station.bikesAvailable }}\n />\n </div>\n <div>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.MapPopup.availableDocks\"]\n }\n description=\"Label text for the number of docks available\"\n id=\"otpUi.MapPopup.availableDocks\"\n values={{ value: station.spacesAvailable }}\n />\n </div>\n </BaseMapStyled.PopupRow>\n )\n}\n\nconst StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: ({ stopId }: { stopId: string }) => void; }) => {\n return (\n <BaseMapStyled.PopupRow>\n <strong>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.MapPopup.stopId\"]}\n description=\"Displays the stop id\"\n id=\"otpUi.MapPopup.stopId\"\n values={{\n stopId: id\n }}\n />\n </strong>\n <S.ViewStopButton onClick={() => setViewedStop({ stopId: id })}>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.MapPopup.stopViewer\"]}\n description=\"Text for link that opens the stop viewer\"\n id=\"otpUi.MapPopup.stopViewer\"\n />\n </S.ViewStopButton>\n </BaseMapStyled.PopupRow>\n )\n}\n\ntype Entity = Stop | Station\ntype Props = {\n configCompanies?: ConfiguredCompany[];\n entity: Entity\n getEntityName?: (entity: Entity, configCompanies: Company[],) => string;\n setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;\n setViewedStop?: ({ stopId }: { stopId: string }) => void;\n};\n\n/**\n * Renders a map popup for a stop, scooter, or shared bike\n */\nexport function MapPopup({ configCompanies, entity, getEntityName, setLocation, setViewedStop, }: Props): JSX.Element {\n const intl = useIntl()\n if (!entity) return <></>\n\n const getNameFunc = getEntityName || makeDefaultGetEntityName(intl, defaultMessages);\n const name = getNameFunc(entity, configCompanies);\n\n\n const bikesAvailablePresent = \"bikesAvailable\" in entity\n const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;\n // @ts-expect-error ts doesn't understand entityIsStop\n const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(\":\")[1] || entity.id\n\n return (\n <BaseMapStyled.MapOverlayPopup>\n <BaseMapStyled.PopupTitle>{name}</BaseMapStyled.PopupTitle>\n {/* render dock info if it is available */}\n {entityIsStationHub && <StationHubDetails station={entity} />}\n\n {/* render stop viewer link if available */}\n {setViewedStop && !bikesAvailablePresent && <StopDetails id={stopId} setViewedStop={setViewedStop} />}\n\n {/* The \"Set as [from/to]\" ButtonGroup */}\n {setLocation && (\n <BaseMapStyled.PopupRow>\n <FromToLocationPicker\n label\n location={generateLocation(entity, name)}\n setLocation={setLocation}\n />\n </BaseMapStyled.PopupRow>\n )}\n </BaseMapStyled.MapOverlayPopup>\n );\n}\n\nexport default MapPopup;\n\n// Rename styled components for export\nexport { S as Styled };\n"],"file":"index.js"}
package/esm/styled.js ADDED
@@ -0,0 +1,8 @@
1
+ import styled from "styled-components";
2
+ /* eslint-disable-next-line import/prefer-default-export */
3
+
4
+ export var ViewStopButton = styled.button.withConfig({
5
+ displayName: "styled__ViewStopButton",
6
+ componentId: "sc-12v7ov3-0"
7
+ })(["background:none;border-bottom:none;border-left:1px solid #000;border-right:none;border-top:none;color:#008;font-family:inherit;margin-left:5px;padding-top:0;"]);
8
+ //# sourceMappingURL=styled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/styled.ts"],"names":["styled","ViewStopButton","button"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,mBAAnB;AAEA;;AACA,OAAO,IAAMC,cAAc,GAAGD,MAAM,CAACE,MAAV;AAAA;AAAA;AAAA,qKAApB","sourcesContent":["import styled from \"styled-components\";\n\n/* eslint-disable-next-line import/prefer-default-export */\nexport const ViewStopButton = styled.button`\n background: none;\n border-bottom: none;\n border-left: 1px solid #000;\n border-right: none;\n border-top: none;\n color: #008;\n font-family: inherit;\n margin-left: 5px;\n padding-top: 0;\n`;\n"],"file":"styled.js"}
package/esm/util.js ADDED
@@ -0,0 +1,46 @@
1
+ import coreUtils from "@opentripplanner/core-utils"; // eslint-disable-next-line import/prefer-default-export
2
+
3
+ export function makeDefaultGetEntityName(intl, defaultEnglishMessages) {
4
+ return function defaultGetEntityName(entity, configCompanies) {
5
+ var _entity$networks;
6
+
7
+ var stationNetworks = "networks" in entity && (coreUtils.itinerary.getCompaniesLabelFromNetworks((entity === null || entity === void 0 ? void 0 : entity.networks) || [], configCompanies) || (entity === null || entity === void 0 ? void 0 : (_entity$networks = entity.networks) === null || _entity$networks === void 0 ? void 0 : _entity$networks[0]));
8
+ var stationName = entity.name || entity.id; // If the station name or id is a giant UUID (with more than 3 "-" characters)
9
+ // best not to show that at all. The company name will still be shown.
10
+
11
+ if ((stationName.match(/-/g) || []).length > 3) {
12
+ stationName = null;
13
+ }
14
+
15
+ if ("isFloatingBike" in entity && entity.isFloatingBike) {
16
+ stationName = intl.formatMessage({
17
+ defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingBike"],
18
+ description: "Popup title for a free-floating bike",
19
+ id: "otpUi.MapPopup.floatingBike"
20
+ }, {
21
+ name: stationName || stationNetworks
22
+ });
23
+ } else if ("isFloatingCar" in entity && entity.isFloatingCar) {
24
+ stationName = intl.formatMessage({
25
+ defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingCar"],
26
+ description: "Popup title for a free-floating car",
27
+ id: "otpUi.MapPopup.floatingCar"
28
+ }, {
29
+ company: stationNetworks,
30
+ name: stationName
31
+ });
32
+ } else if ("isFloatingVehicle" in entity && entity.isFloatingVehicle) {
33
+ // assumes that all floating vehicles are E-scooters
34
+ stationName = intl.formatMessage({
35
+ defaultMessage: defaultEnglishMessages["otpUi.MapPopup.floatingEScooter"],
36
+ description: "Popup title for a free-floating e-scooter",
37
+ id: "otpUi.MapPopup.floatingEScooter"
38
+ }, {
39
+ name: stationName || stationNetworks
40
+ });
41
+ }
42
+
43
+ return stationName;
44
+ };
45
+ }
46
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util.ts"],"names":["coreUtils","makeDefaultGetEntityName","intl","defaultEnglishMessages","defaultGetEntityName","entity","configCompanies","stationNetworks","itinerary","getCompaniesLabelFromNetworks","networks","stationName","name","id","match","length","isFloatingBike","formatMessage","defaultMessage","description","isFloatingCar","company","isFloatingVehicle"],"mappings":"AAEA,OAAOA,SAAP,MAAsB,6BAAtB,C,CAEA;;AACA,OAAO,SAASC,wBAAT,CACLC,IADK,EAELC,sBAFK,EAGL;AACA,SAAO,SAASC,oBAAT,CACLC,MADK,EAELC,eAFK,EAGU;AAAA;;AACf,QAAMC,eAAe,GACnB,cAAcF,MAAd,KACCL,SAAS,CAACQ,SAAV,CAAoBC,6BAApB,CACC,CAAAJ,MAAM,SAAN,IAAAA,MAAM,WAAN,YAAAA,MAAM,CAAEK,QAAR,KAAoB,EADrB,EAECJ,eAFD,MAICD,MAJD,aAICA,MAJD,2CAICA,MAAM,CAAEK,QAJT,qDAIC,iBAAmB,CAAnB,CAJD,CADD,CADF;AAOA,QAAIC,WAA0B,GAAGN,MAAM,CAACO,IAAP,IAAeP,MAAM,CAACQ,EAAvD,CARe,CASf;AACA;;AACA,QAAI,CAACF,WAAW,CAACG,KAAZ,CAAkB,IAAlB,KAA2B,EAA5B,EAAgCC,MAAhC,GAAyC,CAA7C,EAAgD;AAC9CJ,MAAAA,WAAW,GAAG,IAAd;AACD;;AAED,QAAI,oBAAoBN,MAApB,IAA8BA,MAAM,CAACW,cAAzC,EAAyD;AACvDL,MAAAA,WAAW,GAAGT,IAAI,CAACe,aAAL,CACZ;AACEC,QAAAA,cAAc,EAAEf,sBAAsB,CAAC,6BAAD,CADxC;AAEEgB,QAAAA,WAAW,EAAE,sCAFf;AAGEN,QAAAA,EAAE,EAAE;AAHN,OADY,EAMZ;AAAED,QAAAA,IAAI,EAAED,WAAW,IAAIJ;AAAvB,OANY,CAAd;AAQD,KATD,MASO,IAAI,mBAAmBF,MAAnB,IAA6BA,MAAM,CAACe,aAAxC,EAAuD;AAC5DT,MAAAA,WAAW,GAAGT,IAAI,CAACe,aAAL,CACZ;AACEC,QAAAA,cAAc,EAAEf,sBAAsB,CAAC,4BAAD,CADxC;AAEEgB,QAAAA,WAAW,EAAE,qCAFf;AAGEN,QAAAA,EAAE,EAAE;AAHN,OADY,EAMZ;AACEQ,QAAAA,OAAO,EAAEd,eADX;AAEEK,QAAAA,IAAI,EAAED;AAFR,OANY,CAAd;AAWD,KAZM,MAYA,IAAI,uBAAuBN,MAAvB,IAAiCA,MAAM,CAACiB,iBAA5C,EAA+D;AACpE;AACAX,MAAAA,WAAW,GAAGT,IAAI,CAACe,aAAL,CACZ;AACEC,QAAAA,cAAc,EACZf,sBAAsB,CAAC,iCAAD,CAF1B;AAGEgB,QAAAA,WAAW,EAAE,2CAHf;AAIEN,QAAAA,EAAE,EAAE;AAJN,OADY,EAOZ;AAAED,QAAAA,IAAI,EAAED,WAAW,IAAIJ;AAAvB,OAPY,CAAd;AASD;;AACD,WAAOI,WAAP;AACD,GApDD;AAqDD","sourcesContent":["import { Company, Station, Stop } from \"@opentripplanner/types\";\nimport { IntlShape } from \"react-intl\";\nimport coreUtils from \"@opentripplanner/core-utils\";\n\n// eslint-disable-next-line import/prefer-default-export\nexport function makeDefaultGetEntityName(\n intl: IntlShape,\n defaultEnglishMessages: { [key: string]: string }\n) {\n return function defaultGetEntityName(\n entity: Station | Stop,\n configCompanies: Company[]\n ): string | null {\n const stationNetworks =\n \"networks\" in entity &&\n (coreUtils.itinerary.getCompaniesLabelFromNetworks(\n entity?.networks || [],\n configCompanies\n ) ||\n entity?.networks?.[0]);\n let stationName: string | null = entity.name || entity.id;\n // If the station name or id is a giant UUID (with more than 3 \"-\" characters)\n // best not to show that at all. The company name will still be shown.\n if ((stationName.match(/-/g) || []).length > 3) {\n stationName = null;\n }\n\n if (\"isFloatingBike\" in entity && entity.isFloatingBike) {\n stationName = intl.formatMessage(\n {\n defaultMessage: defaultEnglishMessages[\"otpUi.MapPopup.floatingBike\"],\n description: \"Popup title for a free-floating bike\",\n id: \"otpUi.MapPopup.floatingBike\"\n },\n { name: stationName || stationNetworks }\n );\n } else if (\"isFloatingCar\" in entity && entity.isFloatingCar) {\n stationName = intl.formatMessage(\n {\n defaultMessage: defaultEnglishMessages[\"otpUi.MapPopup.floatingCar\"],\n description: \"Popup title for a free-floating car\",\n id: \"otpUi.MapPopup.floatingCar\"\n },\n {\n company: stationNetworks,\n name: stationName\n }\n );\n } else if (\"isFloatingVehicle\" in entity && entity.isFloatingVehicle) {\n // assumes that all floating vehicles are E-scooters\n stationName = intl.formatMessage(\n {\n defaultMessage:\n defaultEnglishMessages[\"otpUi.MapPopup.floatingEScooter\"],\n description: \"Popup title for a free-floating e-scooter\",\n id: \"otpUi.MapPopup.floatingEScooter\"\n },\n { name: stationName || stationNetworks }\n );\n }\n return stationName;\n };\n}\n"],"file":"util.js"}
package/i18n/en-US.yml CHANGED
@@ -1,10 +1,10 @@
1
- # Default messages for the TripDetails component.
1
+ # Default messages for the MapPopup component.
2
2
  # To use from a react-intl application:
3
3
  # - merge the content of this file into the messages object
4
4
  # that has your other localized strings,
5
5
  # - flatten the ids, i.e. convert a structure such as
6
- # otpUi > TripDetails > calories
7
- # into "otpUi.TripDetails.calories" (see TripDetail story for an example),
6
+ # otpUi > MapPopup > stopViewer
7
+ # into "otpUi.MapPopup.stopViewer" (see TripDetail story for an example),
8
8
  # - pass the resulting object to the messages prop of IntlProvider.
9
9
  #
10
10
  # The meaning of the pseudo <tags> used in the strings below is as follows:
package/i18n/es.yml ADDED
@@ -0,0 +1,10 @@
1
+ otpUi:
2
+ MapPopup:
3
+ availableBikes: "Bicicletas disponibles: {value}"
4
+ availableDocks: "Estaciones de carga disponibles: {value}"
5
+ floatingBike: "Bicicleta flotante: {name}"
6
+ floatingCar: "{company} {name}"
7
+ floatingEScooter: "{company} E-scooter"
8
+
9
+ stopId: ID de Parada {stopId}
10
+ stopViewer: Visor de paradas
package/i18n/fr.yml ADDED
@@ -0,0 +1,10 @@
1
+ otpUi:
2
+ MapPopup:
3
+ availableBikes: "Vélos disponibles : {value}"
4
+ availableDocks: "Bornes disponibles : {value}"
5
+ floatingBike: "Vélo flottant : {name}"
6
+ floatingCar: "{company} {name}" # as in "CarCompany Veh1234a"
7
+ floatingEScooter: "Trottinette {company}"
8
+
9
+ stopId: Arrêt n°{stopId}
10
+ stopViewer: Info arrêt
package/i18n/ko.yml ADDED
@@ -0,0 +1,10 @@
1
+ otpUi:
2
+ MapPopup:
3
+ floatingEScooter: "{company} 전기 스쿠터"
4
+ availableDocks: "사용 가능한 독: {value}"
5
+ availableBikes: "사용 가능한 자전거: {value}"
6
+ floatingCar: "{company} {name}"
7
+ floatingBike: "프리 플로팅 자전거: {name}"
8
+
9
+ stopViewer: 뷰어 중지하기
10
+ stopId: "중지 ID: {stopId}"
package/i18n/vi.yml ADDED
@@ -0,0 +1,9 @@
1
+ otpUi:
2
+ MapPopup:
3
+ availableBikes: "Xe đạp có sẵn: {value}"
4
+ availableDocks: "Đế sạc có sẵn: {value}"
5
+ floatingBike: "Xe đạp nổi tự do: {name}"
6
+ floatingCar: "{company} {name}"
7
+ floatingEScooter: "{company} Xe tay ga điện"
8
+ stopViewer: Trình xem trạm dừng
9
+ stopId: "ID điểm dừng: {stopId}"
@@ -0,0 +1,10 @@
1
+ otpUi:
2
+ MapPopup:
3
+ availableBikes: "可用的自行车: {value}"
4
+ availableDocks: "可用的充电座: {value}"
5
+ floatingBike: "自由浮动的自行车: {name}"
6
+ floatingCar: "{company} {name}" # as in "CarCompany Veh1234a"
7
+ floatingEScooter: "{company} 电动滑板车"
8
+
9
+ stopId: 车站查看器
10
+ stopViewer: "车站 ID: {stopId}"
package/lib/index.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import type { Company, ConfiguredCompany, Location, Station, Stop } from "@opentripplanner/types";
3
3
  import * as S from "./styled";
4
- export declare const defaultMessages: unknown;
4
+ export declare const defaultMessages: {
5
+ [key: string]: string;
6
+ };
5
7
  declare type Entity = Stop | Station;
6
8
  declare type Props = {
7
9
  configCompanies?: ConfiguredCompany[];
10
+ entity: Entity;
8
11
  getEntityName?: (entity: Entity, configCompanies: Company[]) => string;
9
12
  setLocation?: ({ location, locationType }: {
10
13
  location: Location;
@@ -13,7 +16,6 @@ declare type Props = {
13
16
  setViewedStop?: ({ stopId }: {
14
17
  stopId: string;
15
18
  }) => void;
16
- entity: Entity;
17
19
  };
18
20
  /**
19
21
  * Renders a map popup for a stop, scooter, or shared bike
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAIlG,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAW9B,eAAO,MAAM,eAAe,SAAkC,CAAC;AAE/D,aAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAA;AAC5B,aAAK,KAAK,GAAG;IACX,eAAe,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACtC,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,KAAM,MAAM,CAAC;IAExE,W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IACjG,aAAa,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC1D,CAAC;AAEF;;GAEG;AACH,wBAAgB,QAAQ,CAAC,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,GAAG,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CAkCpH;AAED,eAAe,QAAQ,CAAC;AAGxB,OAAO,EAAE,CAAC,IAAI,MAAM,EAAE,CAAC"}
package/lib/index.js CHANGED
@@ -1,88 +1,134 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
17
7
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Styled = exports.MapPopup = exports.defaultMessages = void 0;
30
- const react_1 = __importDefault(require("react"));
31
- const base_map_1 = require("@opentripplanner/base-map");
32
- const from_to_location_picker_1 = __importDefault(require("@opentripplanner/from-to-location-picker"));
33
- const react_intl_1 = require("react-intl");
34
- const flat_1 = require("flat");
35
- const S = __importStar(require("./styled"));
8
+ exports.MapPopup = MapPopup;
9
+ exports.Styled = exports.default = exports.defaultMessages = void 0;
10
+
11
+ var _react = _interopRequireDefault(require("react"));
12
+
13
+ var _baseMap = require("@opentripplanner/base-map");
14
+
15
+ var _fromToLocationPicker = _interopRequireDefault(require("@opentripplanner/from-to-location-picker"));
16
+
17
+ var _reactIntl = require("react-intl");
18
+
19
+ var _flat = require("flat");
20
+
21
+ var S = _interopRequireWildcard(require("./styled"));
22
+
36
23
  exports.Styled = S;
24
+
25
+ var _enUS = _interopRequireDefault(require("../i18n/en-US.yml"));
26
+
27
+ var _util = require("./util");
28
+
29
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
30
+
31
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
32
+
37
33
  // Load the default messages.
38
- // @ts-expect-error TODO: why is this failing?
39
- const en_US_yml_1 = __importDefault(require("../i18n/en-US.yml"));
40
- const util_1 = require("./util");
41
34
  // HACK: We should flatten the messages loaded above because
42
35
  // the YAML loaders behave differently between webpack and our version of jest:
43
36
  // - the yaml loader for webpack returns a nested object,
44
37
  // - the yaml loader for jest returns messages with flattened ids.
45
- exports.defaultMessages = (0, flat_1.flatten)(en_US_yml_1.default);
38
+ const defaultMessages = (0, _flat.flatten)(_enUS.default);
39
+ exports.defaultMessages = defaultMessages;
40
+
41
+ const generateLocation = (entity, name) => {
42
+ // @ts-expect-error some of these values may be null, but that's ok
43
+ const {
44
+ lon: entityLon,
45
+ lat: entityLat,
46
+ x,
47
+ y
48
+ } = entity;
49
+ const lat = entityLat || x;
50
+ const lon = entityLon || y;
51
+ if (!lat || !lon) return null;
52
+ return {
53
+ lat,
54
+ lon,
55
+ name
56
+ };
57
+ };
58
+
59
+ const StationHubDetails = ({
60
+ station
61
+ }) => {
62
+ return /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
63
+ defaultMessage: defaultMessages["otpUi.MapPopup.availableBikes"],
64
+ description: "Label text for the number of bikes available",
65
+ id: "otpUi.MapPopup.availableBikes",
66
+ values: {
67
+ value: station.bikesAvailable
68
+ }
69
+ })), /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
70
+ defaultMessage: defaultMessages["otpUi.MapPopup.availableDocks"],
71
+ description: "Label text for the number of docks available",
72
+ id: "otpUi.MapPopup.availableDocks",
73
+ values: {
74
+ value: station.spacesAvailable
75
+ }
76
+ })));
77
+ };
78
+
79
+ const StopDetails = ({
80
+ id,
81
+ setViewedStop
82
+ }) => {
83
+ return /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement("strong", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
84
+ defaultMessage: defaultMessages["otpUi.MapPopup.stopId"],
85
+ description: "Displays the stop id",
86
+ id: "otpUi.MapPopup.stopId",
87
+ values: {
88
+ stopId: id
89
+ }
90
+ })), /*#__PURE__*/_react.default.createElement(S.ViewStopButton, {
91
+ onClick: () => setViewedStop({
92
+ stopId: id
93
+ })
94
+ }, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
95
+ defaultMessage: defaultMessages["otpUi.MapPopup.stopViewer"],
96
+ description: "Text for link that opens the stop viewer",
97
+ id: "otpUi.MapPopup.stopViewer"
98
+ })));
99
+ };
100
+
46
101
  /**
47
102
  * Renders a map popup for a stop, scooter, or shared bike
48
103
  */
49
- function MapPopup({ configCompanies, entity, getEntityName, setLocation, setViewedStop, }) {
50
- if (!entity)
51
- return null;
52
- const intl = (0, react_intl_1.useIntl)();
53
- const getNameFunc = getEntityName || (0, util_1.makeDefaultGetEntityName)(intl, en_US_yml_1.default);
54
- const name = getNameFunc(entity, configCompanies);
55
- const generateLocation = () => {
56
- // @ts-expect-error some of these values may be null, but that's ok
57
- const { lon: entityLon, lat: entityLat, x, y } = entity;
58
- const lat = entityLat || x;
59
- const lon = entityLon || y;
60
- if (!lat || !lon)
61
- return null;
62
- return { lat, lon, name };
63
- };
64
- const entityIsStationHub = "bikesAvailable" in entity && (entity === null || entity === void 0 ? void 0 : entity.bikesAvailable) !== undefined && !(entity === null || entity === void 0 ? void 0 : entity.isFloatingBike);
65
- const entityIsStop = !("bikesAvailable" in entity);
66
- // @ts-expect-error ts doesn't understand entityIsStop
67
- const stopId = entityIsStop && (entity === null || entity === void 0 ? void 0 : entity.code) || entity.id.split(":")[1] || entity.id;
68
- return (react_1.default.createElement(base_map_1.Styled.MapOverlayPopup, null,
69
- react_1.default.createElement(base_map_1.Styled.PopupTitle, null, name),
70
- entityIsStationHub && (react_1.default.createElement(base_map_1.Styled.PopupRow, null,
71
- react_1.default.createElement("div", null,
72
- react_1.default.createElement(react_intl_1.FormattedMessage, { defaultMessage: exports.defaultMessages["otpUi.MapPopup.availableBikes"], description: "Label text for the number of bikes available", id: "otpUi.MapPopup.availableBikes", values: { value: entity.bikesAvailable } })),
73
- react_1.default.createElement("div", null,
74
- react_1.default.createElement(react_intl_1.FormattedMessage, { defaultMessage: exports.defaultMessages["otpUi.MapPopup.availableDocks"], description: "Label text for the number of docks available", id: "otpUi.MapPopup.availableDocks", values: { value: entity.spacesAvailable } })))),
75
- setViewedStop && entityIsStop && react_1.default.createElement(base_map_1.Styled.PopupRow, null,
76
- react_1.default.createElement("span", null,
77
- react_1.default.createElement("strong", null,
78
- react_1.default.createElement(react_intl_1.FormattedMessage, { defaultMessage: exports.defaultMessages["otpUi.MapPopup.stopId"], description: "Displays the stop id", id: "otpUi.MapPopup.stopId", values: {
79
- stopId
80
- } }))),
81
- react_1.default.createElement(S.ViewStopButton, { onClick: () => setViewedStop(stopId) },
82
- react_1.default.createElement(react_intl_1.FormattedMessage, { defaultMessage: exports.defaultMessages["otpUi.MapPopup.stopViewer"], description: "Text for link that opens the stop viewer", id: "otpUi.MapPopup.stopViewer" }))),
83
- setLocation && (react_1.default.createElement(base_map_1.Styled.PopupRow, null,
84
- react_1.default.createElement(from_to_location_picker_1.default, { label: true, location: generateLocation(), setLocation: setLocation })))));
104
+ function MapPopup({
105
+ configCompanies,
106
+ entity,
107
+ getEntityName,
108
+ setLocation,
109
+ setViewedStop
110
+ }) {
111
+ const intl = (0, _reactIntl.useIntl)();
112
+ if (!entity) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
113
+ const getNameFunc = getEntityName || (0, _util.makeDefaultGetEntityName)(intl, defaultMessages);
114
+ const name = getNameFunc(entity, configCompanies);
115
+ const bikesAvailablePresent = ("bikesAvailable" in entity);
116
+ const entityIsStationHub = bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.bikesAvailable) !== undefined && !(entity !== null && entity !== void 0 && entity.isFloatingBike); // @ts-expect-error ts doesn't understand entityIsStop
117
+
118
+ const stopId = !bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.code) || entity.id.split(":")[1] || entity.id;
119
+ return /*#__PURE__*/_react.default.createElement(_baseMap.Styled.MapOverlayPopup, null, /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupTitle, null, name), entityIsStationHub && /*#__PURE__*/_react.default.createElement(StationHubDetails, {
120
+ station: entity
121
+ }), setViewedStop && !bikesAvailablePresent && /*#__PURE__*/_react.default.createElement(StopDetails, {
122
+ id: stopId,
123
+ setViewedStop: setViewedStop
124
+ }), setLocation && /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement(_fromToLocationPicker.default, {
125
+ label: true,
126
+ location: generateLocation(entity, name),
127
+ setLocation: setLocation
128
+ })));
85
129
  }
86
- exports.MapPopup = MapPopup;
87
- exports.default = MapPopup;
130
+
131
+ var _default = MapPopup; // Rename styled components for export
132
+
133
+ exports.default = _default;
88
134
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAE1B,wDAAoE;AACpE,uGAA4E;AAI5E,2CAAuD;AACvD,+BAA+B;AAC/B,4CAA8B;AAuHhB,mBAAM;AArHpB,6BAA6B;AAC7B,8CAA8C;AAC9C,kEAAuD;AACvD,iCAAkD;AAElD,4DAA4D;AAC5D,+EAA+E;AAC/E,yDAAyD;AACzD,kEAAkE;AACrD,QAAA,eAAe,GAAG,IAAA,cAAO,EAAC,mBAAsB,CAAC,CAAC;AAa/D;;GAEG;AACH,SAAgB,QAAQ,CAAC,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,GAAU;IACrG,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxB,MAAM,IAAI,GAAG,IAAA,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c,EACZ,uBAAe,CAAC,+BAA+B,CAAC,EAElD,WAAW,EAAC,8CAA8C,EAC1D,EAAE,EAAC,+BAA+B,EAClC,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,cAAc,EAAE,GACxC,CACE;YACN;gBACE,8BAAC,6BAAgB,IACf,cAAc,EACZ,uBAAe,CAAC,+BAA+B,CAAC,EAElD,WAAW,EAAC,8CAA8C,EAC1D,EAAE,EAAC,+BAA+B,EAClC,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,eAAe,EAAE,GACzC,CACE,CACiB,CAC1B;QAGA,aAAa,IAAI,YAAY,IAAI,8BAAC,iBAAa,CAAC,QAAQ;YACvD;gBACE;oBACE,8BAAC,6BAAgB,IACf,cAAc,EAAE,uBAAe,CAAC,uBAAuB,CAAC,EACxD,WAAW,EAAC,sBAAsB,EAClC,EAAE,EAAC,uBAAuB,EAC1B,MAAM,EAAE;4BACN,MAAM;yBACP,GACD,CACK,CACJ;YACP,8BAAC,CAAC,CAAC,cAAc,IAAC,OAAO,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC;gBACpD,8BAAC,6BAAgB,IACf,cAAc,EAAE,uBAAe,CAAC,2BAA2B,CAAC,EAC5D,WAAW,EAAC,0CAA0C,EACtD,EAAE,EAAC,2BAA2B,GAC9B,CACe,CACI;QAGxB,WAAW,IAAI,CACd,8BAAC,iBAAa,CAAC,QAAQ;YACrB,8BAAC,iCAAoB,IACnB,KAAK,QACL,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,WAAW,EAAE,WAAW,GACxB,CACqB,CAC1B,CAC6B,CACjC,CAAC;AACJ,CAAC;AAvFD,4BAuFC;AAED,kBAAe,QAAQ,CAAC"}
1
+ {"version":3,"sources":["../src/index.tsx"],"names":["defaultMessages","defaultEnglishMessages","generateLocation","entity","name","lon","entityLon","lat","entityLat","x","y","StationHubDetails","station","value","bikesAvailable","spacesAvailable","StopDetails","id","setViewedStop","stopId","MapPopup","configCompanies","getEntityName","setLocation","intl","getNameFunc","bikesAvailablePresent","entityIsStationHub","undefined","isFloatingBike","code","split"],"mappings":";;;;;;;;;;AAAA;;AAEA;;AACA;;AAIA;;AACA;;AACA;;;;AAGA;;AACA;;;;;;AAFA;AAIA;AACA;AACA;AACA;AACO,MAAMA,eAA0C,GAAG,mBAAQC,aAAR,CAAnD;;;AAGP,MAAMC,gBAAgB,GAAG,CAACC,MAAD,EAAiBC,IAAjB,KAAkC;AACzD;AACA,QAAM;AAAEC,IAAAA,GAAG,EAAEC,SAAP;AAAkBC,IAAAA,GAAG,EAAEC,SAAvB;AAAkCC,IAAAA,CAAlC;AAAqCC,IAAAA;AAArC,MAA2CP,MAAjD;AAEA,QAAMI,GAAG,GAAGC,SAAS,IAAIC,CAAzB;AACA,QAAMJ,GAAG,GAAGC,SAAS,IAAII,CAAzB;AACA,MAAI,CAACH,GAAD,IAAQ,CAACF,GAAb,EAAkB,OAAO,IAAP;AAElB,SAAO;AAAEE,IAAAA,GAAF;AAAOF,IAAAA,GAAP;AAAYD,IAAAA;AAAZ,GAAP;AACD,CATD;;AAWA,MAAMO,iBAAiB,GAAG,CAAC;AAAEC,EAAAA;AAAF,CAAD,KAAuC;AAC/D,sBACE,6BAAC,eAAD,CAAe,QAAf,qBACE,uDACE,6BAAC,2BAAD;AACE,IAAA,cAAc,EACZZ,eAAe,CAAC,+BAAD,CAFnB;AAIE,IAAA,WAAW,EAAC,8CAJd;AAKE,IAAA,EAAE,EAAC,+BALL;AAME,IAAA,MAAM,EAAE;AAAEa,MAAAA,KAAK,EAAED,OAAO,CAACE;AAAjB;AANV,IADF,CADF,eAWE,uDACE,6BAAC,2BAAD;AACE,IAAA,cAAc,EACZd,eAAe,CAAC,+BAAD,CAFnB;AAIE,IAAA,WAAW,EAAC,8CAJd;AAKE,IAAA,EAAE,EAAC,+BALL;AAME,IAAA,MAAM,EAAE;AAAEa,MAAAA,KAAK,EAAED,OAAO,CAACG;AAAjB;AANV,IADF,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B,MAAD,aAACA,MAAD,eAACA,MAAM,CAAE0B,cAAT,CAA5F,CAToH,CAUpH;;AACA,QAAMV,MAAM,GAAG,CAACO,qBAAD,KAA0BvB,MAA1B,aAA0BA,MAA1B,uBAA0BA,MAAM,CAAE2B,IAAlC,KAA0C3B,MAAM,CAACc,EAAP,CAAUc,KAAV,CAAgB,GAAhB,EAAqB,CAArB,CAA1C,IAAqE5B,MAAM,CAACc,EAA3F;AAEA,sBACE,6BAAC,eAAD,CAAe,eAAf,qBACE,6BAAC,eAAD,CAAe,UAAf,QAA2Bb,IAA3B,CADF,EAGGuB,kBAAkB,iBAAI,6BAAC,iBAAD;AAAmB,IAAA,OAAO,EAAExB;AAA5B,IAHzB,EAMGe,aAAa,IAAI,CAACQ,qBAAlB,iBAA2C,6BAAC,WAAD;AAAa,IAAA,EAAE,EAAEP,MAAjB;AAAyB,IAAA,aAAa,EAAED;AAAxC,IAN9C,EASGK,WAAW,iBACV,6BAAC,eAAD,CAAe,QAAf,qBACE,6BAAC,6BAAD;AACE,IAAA,KAAK,MADP;AAEE,IAAA,QAAQ,EAAErB,gBAAgB,CAACC,MAAD,EAASC,IAAT,CAF5B;AAGE,IAAA,WAAW,EAAEmB;AAHf,IADF,CAVJ,CADF;AAqBD;;eAEcH,Q,EAEf","sourcesContent":["import React from \"react\";\n\nimport { Styled as BaseMapStyled } from \"@opentripplanner/base-map\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\n// eslint-disable-next-line prettier/prettier\nimport type { Company, ConfiguredCompany, Location, Station, Stop } from \"@opentripplanner/types\";\n\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport { flatten } from \"flat\";\nimport * as S from \"./styled\";\n\n// Load the default messages.\nimport defaultEnglishMessages from \"../i18n/en-US.yml\";\nimport { makeDefaultGetEntityName } from \"./util\";\n\n// HACK: We should flatten the messages loaded above because\n// the YAML loaders behave differently between webpack and our version of jest:\n// - the yaml loader for webpack returns a nested object,\n// - the yaml loader for jest returns messages with flattened ids.\nexport const defaultMessages: { [key: string]: string } = flatten(defaultEnglishMessages);\n\n\nconst generateLocation = (entity: Entity, name: string) => {\n // @ts-expect-error some of these values may be null, but that's ok\n const { lon: entityLon, lat: entityLat, x, y } = entity\n\n const lat = entityLat || x\n const lon = entityLon || y\n if (!lat || !lon) return null\n\n return { lat, lon, name };\n}\n\nconst StationHubDetails = ({ station }: { station: Station }) => {\n return (\n <BaseMapStyled.PopupRow>\n <div>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.MapPopup.availableBikes\"]\n }\n description=\"Label text for the number of bikes available\"\n id=\"otpUi.MapPopup.availableBikes\"\n values={{ value: station.bikesAvailable }}\n />\n </div>\n <div>\n <FormattedMessage\n defaultMessage={\n defaultMessages[\"otpUi.MapPopup.availableDocks\"]\n }\n description=\"Label text for the number of docks available\"\n id=\"otpUi.MapPopup.availableDocks\"\n values={{ value: station.spacesAvailable }}\n />\n </div>\n </BaseMapStyled.PopupRow>\n )\n}\n\nconst StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: ({ stopId }: { stopId: string }) => void; }) => {\n return (\n <BaseMapStyled.PopupRow>\n <strong>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.MapPopup.stopId\"]}\n description=\"Displays the stop id\"\n id=\"otpUi.MapPopup.stopId\"\n values={{\n stopId: id\n }}\n />\n </strong>\n <S.ViewStopButton onClick={() => setViewedStop({ stopId: id })}>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.MapPopup.stopViewer\"]}\n description=\"Text for link that opens the stop viewer\"\n id=\"otpUi.MapPopup.stopViewer\"\n />\n </S.ViewStopButton>\n </BaseMapStyled.PopupRow>\n )\n}\n\ntype Entity = Stop | Station\ntype Props = {\n configCompanies?: ConfiguredCompany[];\n entity: Entity\n getEntityName?: (entity: Entity, configCompanies: Company[],) => string;\n setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;\n setViewedStop?: ({ stopId }: { stopId: string }) => void;\n};\n\n/**\n * Renders a map popup for a stop, scooter, or shared bike\n */\nexport function MapPopup({ configCompanies, entity, getEntityName, setLocation, setViewedStop, }: Props): JSX.Element {\n const intl = useIntl()\n if (!entity) return <></>\n\n const getNameFunc = getEntityName || makeDefaultGetEntityName(intl, defaultMessages);\n const name = getNameFunc(entity, configCompanies);\n\n\n const bikesAvailablePresent = \"bikesAvailable\" in entity\n const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;\n // @ts-expect-error ts doesn't understand entityIsStop\n const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(\":\")[1] || entity.id\n\n return (\n <BaseMapStyled.MapOverlayPopup>\n <BaseMapStyled.PopupTitle>{name}</BaseMapStyled.PopupTitle>\n {/* render dock info if it is available */}\n {entityIsStationHub && <StationHubDetails station={entity} />}\n\n {/* render stop viewer link if available */}\n {setViewedStop && !bikesAvailablePresent && <StopDetails id={stopId} setViewedStop={setViewedStop} />}\n\n {/* The \"Set as [from/to]\" ButtonGroup */}\n {setLocation && (\n <BaseMapStyled.PopupRow>\n <FromToLocationPicker\n label\n location={generateLocation(entity, name)}\n setLocation={setLocation}\n />\n </BaseMapStyled.PopupRow>\n )}\n </BaseMapStyled.MapOverlayPopup>\n );\n}\n\nexport default MapPopup;\n\n// Rename styled components for export\nexport { S as Styled };\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"file":"styled.d.ts","sourceRoot":"","sources":["../src/styled.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,uEAa1B,CAAC"}
1
+ {"version":3,"file":"styled.d.ts","sourceRoot":"","sources":["../src/styled.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,uEAU1B,CAAC"}
package/lib/styled.js CHANGED
@@ -1,23 +1,19 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
6
8
  exports.ViewStopButton = void 0;
7
- const styled_components_1 = __importDefault(require("styled-components"));
9
+
10
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
11
+
8
12
  /* eslint-disable-next-line import/prefer-default-export */
9
- exports.ViewStopButton = styled_components_1.default.button `
10
- background: none;
11
- border-bottom: none;
12
- border-left: 1px solid #000;
13
- border-radius: 0;
14
- border-right: none;
15
- border-top: none;
16
- color: #008;
17
- height: 14px;
18
- line-height: 1;
19
- margin-left: 5px;
20
- outline: none;
21
- padding-top: 0;
22
- `;
13
+ const ViewStopButton = _styledComponents.default.button.withConfig({
14
+ displayName: "styled__ViewStopButton",
15
+ componentId: "sc-12v7ov3-0"
16
+ })(["background:none;border-bottom:none;border-left:1px solid #000;border-right:none;border-top:none;color:#008;font-family:inherit;margin-left:5px;padding-top:0;"]);
17
+
18
+ exports.ViewStopButton = ViewStopButton;
23
19
  //# sourceMappingURL=styled.js.map
package/lib/styled.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"styled.js","sourceRoot":"","sources":["../src/styled.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAuC;AAEvC,2DAA2D;AAC9C,QAAA,cAAc,GAAG,2BAAM,CAAC,MAAM,CAAA;;;;;;;;;;;;;CAa1C,CAAC"}
1
+ {"version":3,"sources":["../src/styled.ts"],"names":["ViewStopButton","styled","button"],"mappings":";;;;;;;;;AAAA;;AAEA;AACO,MAAMA,cAAc,GAAGC,0BAAOC,MAAV;AAAA;AAAA;AAAA,qKAApB","sourcesContent":["import styled from \"styled-components\";\n\n/* eslint-disable-next-line import/prefer-default-export */\nexport const ViewStopButton = styled.button`\n background: none;\n border-bottom: none;\n border-left: 1px solid #000;\n border-right: none;\n border-top: none;\n color: #008;\n font-family: inherit;\n margin-left: 5px;\n padding-top: 0;\n`;\n"],"file":"styled.js"}
package/lib/util.d.ts CHANGED
@@ -2,5 +2,5 @@ import { Company, Station, Stop } from "@opentripplanner/types";
2
2
  import { IntlShape } from "react-intl";
3
3
  export declare function makeDefaultGetEntityName(intl: IntlShape, defaultEnglishMessages: {
4
4
  [key: string]: string;
5
- }): (entity: Station | Stop, configCompanies: Company[]) => string;
5
+ }): (entity: Station | Stop, configCompanies: Company[]) => string | null;
6
6
  //# sourceMappingURL=util.d.ts.map