@opentripplanner/map-popup 3.1.2 → 3.2.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 +21 -14
- package/esm/index.js.map +1 -1
- package/esm/styled.js +0 -21
- package/esm/styled.js.map +1 -1
- package/lib/index.d.ts +3 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +20 -20
- package/lib/index.js.map +1 -1
- package/lib/styled.d.ts +0 -8
- package/lib/styled.d.ts.map +1 -1
- package/lib/styled.js +1 -33
- package/lib/styled.js.map +1 -1
- package/package.json +6 -4
- package/src/MapPopup.story.tsx +24 -11
- package/src/__snapshots__/MapPopup.story.tsx.snap +235 -212
- package/src/index.tsx +29 -20
- package/src/styled.ts +0 -29
- package/tsconfig.tsbuildinfo +1 -1
package/esm/index.js
CHANGED
|
@@ -2,10 +2,11 @@ import React, { useCallback } from "react";
|
|
|
2
2
|
import FromToLocationPicker from "@opentripplanner/from-to-location-picker";
|
|
3
3
|
import coreUtils from "@opentripplanner/core-utils"; // eslint-disable-next-line prettier/prettier
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { FocusTrapWrapper } from "@opentripplanner/building-blocks";
|
|
6
6
|
import { flatten } from "flat";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import { FormattedMessage, useIntl } from "react-intl";
|
|
8
|
+
import { Styled } from "@opentripplanner/base-map";
|
|
9
|
+
import { ViewStopButton } from "./styled"; // Load the default messages.
|
|
9
10
|
|
|
10
11
|
import defaultEnglishMessages from "../i18n/en-US.yml";
|
|
11
12
|
import { makeDefaultGetEntityName } from "./util"; // HACK: We should flatten the messages loaded above because
|
|
@@ -33,7 +34,7 @@ var generateLocation = function generateLocation(entity, name) {
|
|
|
33
34
|
|
|
34
35
|
var StationHubDetails = function StationHubDetails(_ref) {
|
|
35
36
|
var station = _ref.station;
|
|
36
|
-
return /*#__PURE__*/React.createElement(
|
|
37
|
+
return /*#__PURE__*/React.createElement(Styled.PopupRow, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
37
38
|
defaultMessage: defaultMessages["otpUi.MapPopup.availableBikes"],
|
|
38
39
|
description: "Label text for the number of bikes available",
|
|
39
40
|
id: "otpUi.MapPopup.availableBikes",
|
|
@@ -53,14 +54,14 @@ var StationHubDetails = function StationHubDetails(_ref) {
|
|
|
53
54
|
var StopDetails = function StopDetails(_ref2) {
|
|
54
55
|
var id = _ref2.id,
|
|
55
56
|
setViewedStop = _ref2.setViewedStop;
|
|
56
|
-
return /*#__PURE__*/React.createElement(
|
|
57
|
+
return /*#__PURE__*/React.createElement(Styled.PopupRow, null, /*#__PURE__*/React.createElement("strong", null, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
57
58
|
defaultMessage: defaultMessages["otpUi.MapPopup.stopId"],
|
|
58
59
|
description: "Displays the stop id",
|
|
59
60
|
id: "otpUi.MapPopup.stopId",
|
|
60
61
|
values: {
|
|
61
62
|
stopId: id
|
|
62
63
|
}
|
|
63
|
-
})), /*#__PURE__*/React.createElement(
|
|
64
|
+
})), /*#__PURE__*/React.createElement(ViewStopButton, {
|
|
64
65
|
onClick: setViewedStop
|
|
65
66
|
}, /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
66
67
|
defaultMessage: defaultMessages["otpUi.MapPopup.stopViewer"],
|
|
@@ -80,9 +81,12 @@ function entityIsStation(entity) {
|
|
|
80
81
|
export function MapPopup(_ref3) {
|
|
81
82
|
var _entity$networks;
|
|
82
83
|
|
|
83
|
-
var
|
|
84
|
+
var _ref3$closePopup = _ref3.closePopup,
|
|
85
|
+
closePopup = _ref3$closePopup === void 0 ? function () {} : _ref3$closePopup,
|
|
86
|
+
configCompanies = _ref3.configCompanies,
|
|
84
87
|
entity = _ref3.entity,
|
|
85
88
|
getEntityName = _ref3.getEntityName,
|
|
89
|
+
getEntityPrefix = _ref3.getEntityPrefix,
|
|
86
90
|
setLocation = _ref3.setLocation,
|
|
87
91
|
setViewedStop = _ref3.setViewedStop;
|
|
88
92
|
var intl = useIntl();
|
|
@@ -92,8 +96,13 @@ export function MapPopup(_ref3) {
|
|
|
92
96
|
var stationNetwork = "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]));
|
|
93
97
|
var bikesAvailablePresent = entityIsStation(entity);
|
|
94
98
|
var entityIsStationHub = bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.bikesAvailable) !== undefined && !(entity !== null && entity !== void 0 && entity.isFloatingBike);
|
|
95
|
-
var stopId = !bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.code) || entity.id.split(":")[1] || entity.id;
|
|
96
|
-
|
|
99
|
+
var stopId = !bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.code) || entity.id.split(":")[1] || entity.id; // Double quotes make the query invalid, so remove them from the id just in case
|
|
100
|
+
|
|
101
|
+
var id = "focus-".concat(encodeURIComponent(entity.id).replace(/%/g, ""), "-popup");
|
|
102
|
+
return /*#__PURE__*/React.createElement(Styled.MapOverlayPopup, null, /*#__PURE__*/React.createElement(FocusTrapWrapper, {
|
|
103
|
+
closePopup: closePopup,
|
|
104
|
+
id: id
|
|
105
|
+
}, /*#__PURE__*/React.createElement(Styled.PopupTitle, null, getEntityPrefix && getEntityPrefix(entity), /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
97
106
|
defaultMessage: defaultMessages["otpUi.MapPopup.popupTitle"],
|
|
98
107
|
description: "Text for title of the popup, contains an optional company name",
|
|
99
108
|
id: "otpUi.MapPopup.popupTitle",
|
|
@@ -108,13 +117,11 @@ export function MapPopup(_ref3) {
|
|
|
108
117
|
setViewedStop: useCallback(function () {
|
|
109
118
|
return setViewedStop(entity);
|
|
110
119
|
}, [entity])
|
|
111
|
-
}), setLocation && /*#__PURE__*/React.createElement(
|
|
120
|
+
}), setLocation && /*#__PURE__*/React.createElement(Styled.PopupRow, null, /*#__PURE__*/React.createElement(FromToLocationPicker, {
|
|
112
121
|
label: true,
|
|
113
122
|
location: generateLocation(entity, name),
|
|
114
123
|
setLocation: setLocation
|
|
115
|
-
})));
|
|
124
|
+
}))));
|
|
116
125
|
}
|
|
117
|
-
export default MapPopup;
|
|
118
|
-
|
|
119
|
-
export { S as Styled, FocusTrapWrapper };
|
|
126
|
+
export default MapPopup;
|
|
120
127
|
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx"],"names":["React","useCallback","FromToLocationPicker","coreUtils","FormattedMessage","useIntl","flatten","S","FocusTrapWrapper","defaultEnglishMessages","makeDefaultGetEntityName","defaultMessages","generateLocation","entity","name","entityLon","lon","entityLat","lat","x","y","StationHubDetails","station","value","bikesAvailable","spacesAvailable","StopDetails","id","setViewedStop","stopId","entityIsStation","MapPopup","configCompanies","getEntityName","setLocation","intl","getNameFunc","stationNetwork","itinerary","getCompaniesLabelFromNetworks","networks","bikesAvailablePresent","entityIsStationHub","undefined","isFloatingBike","code","split","Styled"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,OAAOC,oBAAP,MAAiC,0CAAjC;AACA,OAAOC,SAAP,MAAsB,6BAAtB,C,CAEA;;AAGA,SAASC,gBAAT,EAA2BC,OAA3B,QAA0C,YAA1C;AACA,SAASC,OAAT,QAAwB,MAAxB;AACA,OAAO,KAAKC,CAAZ,MAAmB,UAAnB;AACA,OAAOC,gBAAP,MAA6B,oBAA7B,C,CAEA;;AACA,OAAOC,sBAAP,MAAmC,mBAAnC;AACA,SAASC,wBAAT,QAAyC,QAAzC,C,CAEA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,eAA0C,GAAGL,OAAO,CAACG,sBAAD,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,iBACV,oBAAC,CAAD,CAAG,QAAH,qBACE,oBAAC,oBAAD;AACE,IAAA,KAAK,MADP;AAEE,IAAA,QAAQ,EAAEtB,gBAAgB,CAACC,MAAD,EAASC,IAAT,CAF5B;AAGE,IAAA,WAAW,EAAEoB;AAHf,IADF,CAtBJ,CADF;AAiCD;AAED,eAAeH,QAAf,C,CAEA;;AACA,SAASxB,CAAC,IAAIwC,MAAd,EAAsBvC,gBAAtB","sourcesContent":["import React, { useCallback } from \"react\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\nimport coreUtils from \"@opentripplanner/core-utils\";\n\n// eslint-disable-next-line prettier/prettier\nimport type { Company, ConfiguredCompany, Location, Station, Stop, StopEventHandler } from \"@opentripplanner/types\";\n\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport { flatten } from \"flat\";\nimport * as S from \"./styled\";\nimport FocusTrapWrapper from \"./FocusTrapWrapper\";\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\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 || y\n const lon = entityLon || x\n if (!lat || !lon) return null\n\n return { lat, lon, name };\n}\n\nconst StationHubDetails = ({ station }: { station: Station }) => {\n return (\n <S.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 </S.PopupRow>\n )\n}\n\nconst StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {\n return (\n <S.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}>\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 </S.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?: StopEventHandler;\n};\n\nfunction entityIsStation(entity: Entity): entity is Station {\n return \"bikesAvailable\" in entity\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 const stationNetwork = \"networks\" in entity && (coreUtils.itinerary.getCompaniesLabelFromNetworks(entity?.networks || [], configCompanies) || entity?.networks?.[0]);\n\n const bikesAvailablePresent = entityIsStation(entity)\n const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;\n const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(\":\")[1] || entity.id\n\n return (\n <S.MapOverlayPopup>\n <S.PopupTitle>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.MapPopup.popupTitle\"]}\n description=\"Text for title of the popup, contains an optional company name\"\n id=\"otpUi.MapPopup.popupTitle\"\n values={{ name, stationNetwork }}\n />\n </S.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 && (\n <StopDetails\n id={stopId}\n setViewedStop={useCallback(() => setViewedStop(entity), [entity])}\n />\n )}\n\n {/* The \"Set as [from/to]\" ButtonGroup */}\n {setLocation && (\n <S.PopupRow>\n <FromToLocationPicker\n label\n location={generateLocation(entity, name)}\n setLocation={setLocation}\n />\n </S.PopupRow>\n )}\n </S.MapOverlayPopup>\n );\n}\n\nexport default MapPopup;\n\n// Rename styled components for export.\nexport { S as Styled, FocusTrapWrapper };"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx"],"names":["React","useCallback","FromToLocationPicker","coreUtils","FocusTrapWrapper","flatten","FormattedMessage","useIntl","Styled","ViewStopButton","defaultEnglishMessages","makeDefaultGetEntityName","defaultMessages","generateLocation","entity","name","entityLon","lon","entityLat","lat","x","y","StationHubDetails","station","value","bikesAvailable","spacesAvailable","StopDetails","id","setViewedStop","stopId","entityIsStation","MapPopup","closePopup","configCompanies","getEntityName","getEntityPrefix","setLocation","intl","getNameFunc","stationNetwork","itinerary","getCompaniesLabelFromNetworks","networks","bikesAvailablePresent","entityIsStationHub","undefined","isFloatingBike","code","split","encodeURIComponent","replace"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,WAAhB,QAAmC,OAAnC;AACA,OAAOC,oBAAP,MAAiC,0CAAjC;AACA,OAAOC,SAAP,MAAsB,6BAAtB,C,CAEA;;AAGA,SAASC,gBAAT,QAAiC,kCAAjC;AACA,SAASC,OAAT,QAAwB,MAAxB;AACA,SAASC,gBAAT,EAA2BC,OAA3B,QAA0C,YAA1C;AACA,SAASC,MAAT,QAAuB,2BAAvB;AAEA,SAASC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,CADrC,eAEE,oBAAC,gBAAD;AACE,IAAA,cAAc,EAAEF,eAAe,CAAC,2BAAD,CADjC;AAEE,IAAA,WAAW,EAAC,gEAFd;AAGE,IAAA,EAAE,EAAC,2BAHL;AAIE,IAAA,MAAM,EAAE;AAAEG,MAAAA,IAAI,EAAJA,IAAF;AAAQyB,MAAAA,cAAc,EAAdA;AAAR;AAJV,IAFF,CADA,EAWCK,kBAAkB,iBAAI,oBAAC,iBAAD;AAAmB,IAAA,OAAO,EAAE/B;AAA5B,IAXvB,EAcCe,aAAa,IAAI,CAACe,qBAAlB,iBACC,oBAAC,WAAD;AACE,IAAA,EAAE,EAAEd,MADN;AAEE,IAAA,aAAa,EAAE7B,WAAW,CAAC;AAAA,aAAM4B,aAAa,CAACf,MAAD,CAAnB;AAAA,KAAD,EAA8B,CAACA,MAAD,CAA9B;AAF5B,IAfF,EAsBCuB,WAAW,iBACV,oBAAC,MAAD,CAAQ,QAAR,qBACE,oBAAC,oBAAD;AACE,IAAA,KAAK,MADP;AAEE,IAAA,QAAQ,EAAExB,gBAAgB,CAACC,MAAD,EAASC,IAAT,CAF5B;AAGE,IAAA,WAAW,EAAEsB;AAHf,IADF,CAvBF,CADF,CADF;AAqCD;AAED,eAAeL,QAAf","sourcesContent":["import React, { useCallback } from \"react\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\nimport coreUtils from \"@opentripplanner/core-utils\";\n\n// eslint-disable-next-line prettier/prettier\nimport type { Company, ConfiguredCompany, Location, Station, Stop, StopEventHandler } from \"@opentripplanner/types\";\n\nimport { FocusTrapWrapper } from \"@opentripplanner/building-blocks\";\nimport { flatten } from \"flat\";\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport { Styled } from \"@opentripplanner/base-map\";\n\nimport { ViewStopButton } 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\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 || y\n const lon = entityLon || x\n if (!lat || !lon) return null\n\n return { lat, lon, name };\n}\n\nconst StationHubDetails = ({ station }: { station: Station }) => {\n return (\n <Styled.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 </Styled.PopupRow>\n )\n}\n\nconst StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {\n return (\n <Styled.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 <ViewStopButton onClick={setViewedStop}>\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 </ViewStopButton>\n </Styled.PopupRow>\n )\n}\n\ntype Entity = Stop | Station\ntype Props = {\n closePopup?: (arg?: any) => void\n configCompanies?: ConfiguredCompany[];\n entity: Entity\n getEntityName?: (entity: Entity, configCompanies: Company[],) => string;\n getEntityPrefix?: (entity: Entity) => JSX.Element\n setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;\n setViewedStop?: StopEventHandler;\n};\n\nfunction entityIsStation(entity: Entity): entity is Station {\n return \"bikesAvailable\" in entity\n}\n\n/**\n * Renders a map popup for a stop, scooter, or shared bike\n */\nexport function MapPopup({ closePopup = () => {}, configCompanies, entity, getEntityName, getEntityPrefix, setLocation, setViewedStop }: Props): JSX.Element {\n\n const intl = useIntl()\n if (!entity) return <></>\n\n const getNameFunc = getEntityName || makeDefaultGetEntityName(intl, defaultMessages);\n const name = getNameFunc(entity, configCompanies);\n\n const stationNetwork = \"networks\" in entity && (coreUtils.itinerary.getCompaniesLabelFromNetworks(entity?.networks || [], configCompanies) || entity?.networks?.[0]);\n\n const bikesAvailablePresent = entityIsStation(entity)\n const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;\n const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(\":\")[1] || entity.id\n\n // Double quotes make the query invalid, so remove them from the id just in case\n const id = `focus-${encodeURIComponent(entity.id).replace(/%/g, \"\")}-popup`\n\n return (\n <Styled.MapOverlayPopup>\n <FocusTrapWrapper closePopup={closePopup} id={id}>\n <Styled.PopupTitle>\n {getEntityPrefix && getEntityPrefix(entity)}\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.MapPopup.popupTitle\"]}\n description=\"Text for title of the popup, contains an optional company name\"\n id=\"otpUi.MapPopup.popupTitle\"\n values={{ name, stationNetwork }}\n />\n </Styled.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 && (\n <StopDetails\n id={stopId}\n setViewedStop={useCallback(() => setViewedStop(entity), [entity])}\n />\n )}\n\n {/* The \"Set as [from/to]\" ButtonGroup */}\n {setLocation && (\n <Styled.PopupRow>\n <FromToLocationPicker\n label\n location={generateLocation(entity, name)}\n setLocation={setLocation}\n />\n </Styled.PopupRow>\n )}\n </FocusTrapWrapper>\n \n </Styled.MapOverlayPopup>\n );\n}\n\nexport default MapPopup;"],"file":"index.js"}
|
package/esm/styled.js
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
1
|
import styled from "styled-components";
|
|
2
|
-
import { Popup as MapGlPopup } from "react-map-gl";
|
|
3
2
|
/* eslint-disable-next-line import/prefer-default-export */
|
|
4
3
|
|
|
5
4
|
export var ViewStopButton = styled.button.withConfig({
|
|
6
5
|
displayName: "styled__ViewStopButton",
|
|
7
6
|
componentId: "sc-12v7ov3-0"
|
|
8
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;"]);
|
|
9
|
-
/**
|
|
10
|
-
* Adds a box shadow and tweaks border radius to make popups easier to read.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
export var Popup = styled(MapGlPopup).withConfig({
|
|
14
|
-
displayName: "styled__Popup",
|
|
15
|
-
componentId: "sc-12v7ov3-1"
|
|
16
|
-
})(["& > .maplibregl-popup-content,& > .mapboxgl-popup-content{border-radius:10px;box-shadow:0 3px 14px 4px rgb(0 0 0 / 20%);}"]);
|
|
17
|
-
export var MapOverlayPopup = styled.div.withConfig({
|
|
18
|
-
displayName: "styled__MapOverlayPopup",
|
|
19
|
-
componentId: "sc-12v7ov3-2"
|
|
20
|
-
})(["font-size:12px;line-height:1.5;min-width:250px;"]);
|
|
21
|
-
export var PopupRow = styled.p.withConfig({
|
|
22
|
-
displayName: "styled__PopupRow",
|
|
23
|
-
componentId: "sc-12v7ov3-3"
|
|
24
|
-
})(["margin-top:6px;"]);
|
|
25
|
-
export var PopupTitle = styled.header.withConfig({
|
|
26
|
-
displayName: "styled__PopupTitle",
|
|
27
|
-
componentId: "sc-12v7ov3-4"
|
|
28
|
-
})(["font-size:18px;font-weight:500;margin-bottom:6px;"]);
|
|
29
8
|
//# sourceMappingURL=styled.js.map
|
package/esm/styled.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/styled.ts"],"names":["styled","
|
|
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/lib/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Company, ConfiguredCompany, Location, Station, Stop, StopEventHandler } from "@opentripplanner/types";
|
|
3
|
-
import * as S from "./styled";
|
|
4
|
-
import FocusTrapWrapper from "./FocusTrapWrapper";
|
|
5
3
|
export declare const defaultMessages: {
|
|
6
4
|
[key: string]: string;
|
|
7
5
|
};
|
|
8
6
|
declare type Entity = Stop | Station;
|
|
9
7
|
declare type Props = {
|
|
8
|
+
closePopup?: (arg?: any) => void;
|
|
10
9
|
configCompanies?: ConfiguredCompany[];
|
|
11
10
|
entity: Entity;
|
|
12
11
|
getEntityName?: (entity: Entity, configCompanies: Company[]) => string;
|
|
12
|
+
getEntityPrefix?: (entity: Entity) => JSX.Element;
|
|
13
13
|
setLocation?: ({ location, locationType }: {
|
|
14
14
|
location: Location;
|
|
15
15
|
locationType: string;
|
|
@@ -19,7 +19,6 @@ declare type Props = {
|
|
|
19
19
|
/**
|
|
20
20
|
* Renders a map popup for a stop, scooter, or shared bike
|
|
21
21
|
*/
|
|
22
|
-
export declare function MapPopup({ configCompanies, entity, getEntityName, setLocation, setViewedStop }: Props): JSX.Element;
|
|
22
|
+
export declare function MapPopup({ closePopup, configCompanies, entity, getEntityName, getEntityPrefix, setLocation, setViewedStop }: Props): JSX.Element;
|
|
23
23
|
export default MapPopup;
|
|
24
|
-
export { S as Styled, FocusTrapWrapper };
|
|
25
24
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -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,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
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,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAiBpH,eAAO,MAAM,eAAe,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAoC,CAAC;AAgE1F,aAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAA;AAC5B,aAAK,KAAK,GAAG;IACX,UAAU,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,KAAK,IAAI,CAAA;IAChC,eAAe,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACtC,MAAM,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,KAAM,MAAM,CAAC;IACxE,eAAe,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,GAAG,CAAC,OAAO,CAAA;IACjD,WAAW,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACjG,aAAa,CAAC,EAAE,gBAAgB,CAAC;CAClC,CAAC;AAMF;;GAEG;AACH,wBAAgB,QAAQ,CAAC,EAAE,UAAqB,EAAE,eAAe,EAAE,MAAM,EAAE,aAAa,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,EAAE,KAAK,GAAG,GAAG,CAAC,OAAO,CAsD3J;AAED,eAAe,QAAQ,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -6,13 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.MapPopup = MapPopup;
|
|
9
|
-
|
|
10
|
-
enumerable: true,
|
|
11
|
-
get: function () {
|
|
12
|
-
return _FocusTrapWrapper.default;
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
exports.Styled = exports.default = exports.defaultMessages = void 0;
|
|
9
|
+
exports.default = exports.defaultMessages = void 0;
|
|
16
10
|
|
|
17
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
18
12
|
|
|
@@ -20,15 +14,15 @@ var _fromToLocationPicker = _interopRequireDefault(require("@opentripplanner/fro
|
|
|
20
14
|
|
|
21
15
|
var _coreUtils = _interopRequireDefault(require("@opentripplanner/core-utils"));
|
|
22
16
|
|
|
23
|
-
var
|
|
17
|
+
var _buildingBlocks = require("@opentripplanner/building-blocks");
|
|
24
18
|
|
|
25
19
|
var _flat = require("flat");
|
|
26
20
|
|
|
27
|
-
var
|
|
21
|
+
var _reactIntl = require("react-intl");
|
|
28
22
|
|
|
29
|
-
|
|
23
|
+
var _baseMap = require("@opentripplanner/base-map");
|
|
30
24
|
|
|
31
|
-
var
|
|
25
|
+
var _styled = require("./styled");
|
|
32
26
|
|
|
33
27
|
var _enUS = _interopRequireDefault(require("../i18n/en-US.yml"));
|
|
34
28
|
|
|
@@ -67,7 +61,7 @@ const generateLocation = (entity, name) => {
|
|
|
67
61
|
const StationHubDetails = ({
|
|
68
62
|
station
|
|
69
63
|
}) => {
|
|
70
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
64
|
+
return /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
71
65
|
defaultMessage: defaultMessages["otpUi.MapPopup.availableBikes"],
|
|
72
66
|
description: "Label text for the number of bikes available",
|
|
73
67
|
id: "otpUi.MapPopup.availableBikes",
|
|
@@ -88,14 +82,14 @@ const StopDetails = ({
|
|
|
88
82
|
id,
|
|
89
83
|
setViewedStop
|
|
90
84
|
}) => {
|
|
91
|
-
return /*#__PURE__*/_react.default.createElement(
|
|
85
|
+
return /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement("strong", null, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
92
86
|
defaultMessage: defaultMessages["otpUi.MapPopup.stopId"],
|
|
93
87
|
description: "Displays the stop id",
|
|
94
88
|
id: "otpUi.MapPopup.stopId",
|
|
95
89
|
values: {
|
|
96
90
|
stopId: id
|
|
97
91
|
}
|
|
98
|
-
})), /*#__PURE__*/_react.default.createElement(
|
|
92
|
+
})), /*#__PURE__*/_react.default.createElement(_styled.ViewStopButton, {
|
|
99
93
|
onClick: setViewedStop
|
|
100
94
|
}, /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
101
95
|
defaultMessage: defaultMessages["otpUi.MapPopup.stopViewer"],
|
|
@@ -113,9 +107,11 @@ function entityIsStation(entity) {
|
|
|
113
107
|
|
|
114
108
|
|
|
115
109
|
function MapPopup({
|
|
110
|
+
closePopup = () => {},
|
|
116
111
|
configCompanies,
|
|
117
112
|
entity,
|
|
118
113
|
getEntityName,
|
|
114
|
+
getEntityPrefix,
|
|
119
115
|
setLocation,
|
|
120
116
|
setViewedStop
|
|
121
117
|
}) {
|
|
@@ -128,8 +124,13 @@ function MapPopup({
|
|
|
128
124
|
const stationNetwork = "networks" in entity && (_coreUtils.default.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]));
|
|
129
125
|
const bikesAvailablePresent = entityIsStation(entity);
|
|
130
126
|
const entityIsStationHub = bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.bikesAvailable) !== undefined && !(entity !== null && entity !== void 0 && entity.isFloatingBike);
|
|
131
|
-
const stopId = !bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.code) || entity.id.split(":")[1] || entity.id;
|
|
132
|
-
|
|
127
|
+
const stopId = !bikesAvailablePresent && (entity === null || entity === void 0 ? void 0 : entity.code) || entity.id.split(":")[1] || entity.id; // Double quotes make the query invalid, so remove them from the id just in case
|
|
128
|
+
|
|
129
|
+
const id = `focus-${encodeURIComponent(entity.id).replace(/%/g, "")}-popup`;
|
|
130
|
+
return /*#__PURE__*/_react.default.createElement(_baseMap.Styled.MapOverlayPopup, null, /*#__PURE__*/_react.default.createElement(_buildingBlocks.FocusTrapWrapper, {
|
|
131
|
+
closePopup: closePopup,
|
|
132
|
+
id: id
|
|
133
|
+
}, /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupTitle, null, getEntityPrefix && getEntityPrefix(entity), /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, {
|
|
133
134
|
defaultMessage: defaultMessages["otpUi.MapPopup.popupTitle"],
|
|
134
135
|
description: "Text for title of the popup, contains an optional company name",
|
|
135
136
|
id: "otpUi.MapPopup.popupTitle",
|
|
@@ -142,14 +143,13 @@ function MapPopup({
|
|
|
142
143
|
}), setViewedStop && !bikesAvailablePresent && /*#__PURE__*/_react.default.createElement(StopDetails, {
|
|
143
144
|
id: stopId,
|
|
144
145
|
setViewedStop: (0, _react.useCallback)(() => setViewedStop(entity), [entity])
|
|
145
|
-
}), setLocation && /*#__PURE__*/_react.default.createElement(
|
|
146
|
+
}), setLocation && /*#__PURE__*/_react.default.createElement(_baseMap.Styled.PopupRow, null, /*#__PURE__*/_react.default.createElement(_fromToLocationPicker.default, {
|
|
146
147
|
label: true,
|
|
147
148
|
location: generateLocation(entity, name),
|
|
148
149
|
setLocation: setLocation
|
|
149
|
-
})));
|
|
150
|
+
}))));
|
|
150
151
|
}
|
|
151
152
|
|
|
152
|
-
var _default = MapPopup;
|
|
153
|
-
|
|
153
|
+
var _default = MapPopup;
|
|
154
154
|
exports.default = _default;
|
|
155
155
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","entityIsStation","MapPopup","configCompanies","getEntityName","setLocation","intl","getNameFunc","stationNetwork","coreUtils","itinerary","getCompaniesLabelFromNetworks","networks","bikesAvailablePresent","entityIsStationHub","undefined","isFloatingBike","code","split"],"mappings":";;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAKA;;AACA;;AACA;;;;AACA;;AAGA;;AACA;;;;;;AAFA;AAIA;AACA;AACA;AACA;AACO,MAAMA,eAA0C,GAAG,mBAAQC,aAAR,CAAnD;;;AAEP,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,IAAIE,CAAzB;AACA,QAAML,GAAG,GAAGC,SAAS,IAAIG,CAAzB;AACA,MAAI,CAACF,GAAD,IAAQ,CAACF,GAAb,EAAkB,OAAO,IAAP;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BAAC,CAAD,CAAG,eAAH,qBACE,6BAAC,CAAD,CAAG,UAAH,qBACE,6BAAC,2BAAD;AACE,IAAA,cAAc,EAAEjB,eAAe,CAAC,2BAAD,CADjC;AAEE,IAAA,WAAW,EAAC,gEAFd;AAGE,IAAA,EAAE,EAAC,2BAHL;AAIE,IAAA,MAAM,EAAE;AAAEI,MAAAA,IAAF;AAAQuB,MAAAA;AAAR;AAJV,IADF,CADF,EAUGM,kBAAkB,iBAAI,6BAAC,iBAAD;AAAmB,IAAA,OAAO,EAAE9B;AAA5B,IAVzB,EAaGe,aAAa,IAAI,CAACc,qBAAlB,iBACC,6BAAC,WAAD;AACE,IAAA,EAAE,EAAEb,MADN;AAEE,IAAA,aAAa,EAAE,wBAAY,MAAMD,aAAa,CAACf,MAAD,CAA/B,EAAyC,CAACA,MAAD,CAAzC;AAFjB,IAdJ,EAqBGqB,WAAW,iBACV,6BAAC,CAAD,CAAG,QAAH,qBACE,6BAAC,6BAAD;AACE,IAAA,KAAK,MADP;AAEE,IAAA,QAAQ,EAAEtB,gBAAgB,CAACC,MAAD,EAASC,IAAT,CAF5B;AAGE,IAAA,WAAW,EAAEoB;AAHf,IADF,CAtBJ,CADF;AAiCD;;eAEcH,Q,EAEf","sourcesContent":["import React, { useCallback } from \"react\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\nimport coreUtils from \"@opentripplanner/core-utils\";\n\n// eslint-disable-next-line prettier/prettier\nimport type { Company, ConfiguredCompany, Location, Station, Stop, StopEventHandler } from \"@opentripplanner/types\";\n\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport { flatten } from \"flat\";\nimport * as S from \"./styled\";\nimport FocusTrapWrapper from \"./FocusTrapWrapper\";\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\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 || y\n const lon = entityLon || x\n if (!lat || !lon) return null\n\n return { lat, lon, name };\n}\n\nconst StationHubDetails = ({ station }: { station: Station }) => {\n return (\n <S.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 </S.PopupRow>\n )\n}\n\nconst StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {\n return (\n <S.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}>\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 </S.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?: StopEventHandler;\n};\n\nfunction entityIsStation(entity: Entity): entity is Station {\n return \"bikesAvailable\" in entity\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 const stationNetwork = \"networks\" in entity && (coreUtils.itinerary.getCompaniesLabelFromNetworks(entity?.networks || [], configCompanies) || entity?.networks?.[0]);\n\n const bikesAvailablePresent = entityIsStation(entity)\n const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;\n const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(\":\")[1] || entity.id\n\n return (\n <S.MapOverlayPopup>\n <S.PopupTitle>\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.MapPopup.popupTitle\"]}\n description=\"Text for title of the popup, contains an optional company name\"\n id=\"otpUi.MapPopup.popupTitle\"\n values={{ name, stationNetwork }}\n />\n </S.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 && (\n <StopDetails\n id={stopId}\n setViewedStop={useCallback(() => setViewedStop(entity), [entity])}\n />\n )}\n\n {/* The \"Set as [from/to]\" ButtonGroup */}\n {setLocation && (\n <S.PopupRow>\n <FromToLocationPicker\n label\n location={generateLocation(entity, name)}\n setLocation={setLocation}\n />\n </S.PopupRow>\n )}\n </S.MapOverlayPopup>\n );\n}\n\nexport default MapPopup;\n\n// Rename styled components for export.\nexport { S as Styled, FocusTrapWrapper };"],"file":"index.js"}
|
|
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","entityIsStation","MapPopup","closePopup","configCompanies","getEntityName","getEntityPrefix","setLocation","intl","getNameFunc","stationNetwork","coreUtils","itinerary","getCompaniesLabelFromNetworks","networks","bikesAvailablePresent","entityIsStationHub","undefined","isFloatingBike","code","split","encodeURIComponent","replace"],"mappings":";;;;;;;;;;AAAA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AAEA;;AAGA;;AACA;;;;;;AAFA;AAIA;AACA;AACA;AACA;AACO,MAAMA,eAA0C,GAAG,mBAAQC,aAAR,CAAnD;;;AAEP,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,IAAIE,CAAzB;AACA,QAAML,GAAG,GAAGC,SAAS,IAAIG,CAAzB;AACA,MAAI,CAACF,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,CAAQ,QAAR,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,MAAA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,MAAAA;AAAR;AAJV,IAFF,CADA,EAWCM,kBAAkB,iBAAI,6BAAC,iBAAD;AAAmB,IAAA,OAAO,EAAEhC;AAA5B,IAXvB,EAcCe,aAAa,IAAI,CAACgB,qBAAlB,iBACC,6BAAC,WAAD;AACE,IAAA,EAAE,EAAEf,MADN;AAEE,IAAA,aAAa,EAAE,wBAAY,MAAMD,aAAa,CAACf,MAAD,CAA/B,EAAyC,CAACA,MAAD,CAAzC;AAFjB,IAfF,EAsBCuB,WAAW,iBACV,6BAAC,eAAD,CAAQ,QAAR,qBACE,6BAAC,6BAAD;AACE,IAAA,KAAK,MADP;AAEE,IAAA,QAAQ,EAAExB,gBAAgB,CAACC,MAAD,EAASC,IAAT,CAF5B;AAGE,IAAA,WAAW,EAAEsB;AAHf,IADF,CAvBF,CADF,CADF;AAqCD;;eAEcL,Q","sourcesContent":["import React, { useCallback } from \"react\";\nimport FromToLocationPicker from \"@opentripplanner/from-to-location-picker\";\nimport coreUtils from \"@opentripplanner/core-utils\";\n\n// eslint-disable-next-line prettier/prettier\nimport type { Company, ConfiguredCompany, Location, Station, Stop, StopEventHandler } from \"@opentripplanner/types\";\n\nimport { FocusTrapWrapper } from \"@opentripplanner/building-blocks\";\nimport { flatten } from \"flat\";\nimport { FormattedMessage, useIntl } from \"react-intl\";\nimport { Styled } from \"@opentripplanner/base-map\";\n\nimport { ViewStopButton } 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\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 || y\n const lon = entityLon || x\n if (!lat || !lon) return null\n\n return { lat, lon, name };\n}\n\nconst StationHubDetails = ({ station }: { station: Station }) => {\n return (\n <Styled.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 </Styled.PopupRow>\n )\n}\n\nconst StopDetails = ({ id, setViewedStop }: { id: string, setViewedStop: () => void; }) => {\n return (\n <Styled.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 <ViewStopButton onClick={setViewedStop}>\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 </ViewStopButton>\n </Styled.PopupRow>\n )\n}\n\ntype Entity = Stop | Station\ntype Props = {\n closePopup?: (arg?: any) => void\n configCompanies?: ConfiguredCompany[];\n entity: Entity\n getEntityName?: (entity: Entity, configCompanies: Company[],) => string;\n getEntityPrefix?: (entity: Entity) => JSX.Element\n setLocation?: ({ location, locationType }: { location: Location, locationType: string }) => void;\n setViewedStop?: StopEventHandler;\n};\n\nfunction entityIsStation(entity: Entity): entity is Station {\n return \"bikesAvailable\" in entity\n}\n\n/**\n * Renders a map popup for a stop, scooter, or shared bike\n */\nexport function MapPopup({ closePopup = () => {}, configCompanies, entity, getEntityName, getEntityPrefix, setLocation, setViewedStop }: Props): JSX.Element {\n\n const intl = useIntl()\n if (!entity) return <></>\n\n const getNameFunc = getEntityName || makeDefaultGetEntityName(intl, defaultMessages);\n const name = getNameFunc(entity, configCompanies);\n\n const stationNetwork = \"networks\" in entity && (coreUtils.itinerary.getCompaniesLabelFromNetworks(entity?.networks || [], configCompanies) || entity?.networks?.[0]);\n\n const bikesAvailablePresent = entityIsStation(entity)\n const entityIsStationHub = bikesAvailablePresent && entity?.bikesAvailable !== undefined && !entity?.isFloatingBike;\n const stopId = !bikesAvailablePresent && entity?.code || entity.id.split(\":\")[1] || entity.id\n\n // Double quotes make the query invalid, so remove them from the id just in case\n const id = `focus-${encodeURIComponent(entity.id).replace(/%/g, \"\")}-popup`\n\n return (\n <Styled.MapOverlayPopup>\n <FocusTrapWrapper closePopup={closePopup} id={id}>\n <Styled.PopupTitle>\n {getEntityPrefix && getEntityPrefix(entity)}\n <FormattedMessage\n defaultMessage={defaultMessages[\"otpUi.MapPopup.popupTitle\"]}\n description=\"Text for title of the popup, contains an optional company name\"\n id=\"otpUi.MapPopup.popupTitle\"\n values={{ name, stationNetwork }}\n />\n </Styled.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 && (\n <StopDetails\n id={stopId}\n setViewedStop={useCallback(() => setViewedStop(entity), [entity])}\n />\n )}\n\n {/* The \"Set as [from/to]\" ButtonGroup */}\n {setLocation && (\n <Styled.PopupRow>\n <FromToLocationPicker\n label\n location={generateLocation(entity, name)}\n setLocation={setLocation}\n />\n </Styled.PopupRow>\n )}\n </FocusTrapWrapper>\n \n </Styled.MapOverlayPopup>\n );\n}\n\nexport default MapPopup;"],"file":"index.js"}
|
package/lib/styled.d.ts
CHANGED
|
@@ -1,10 +1,2 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export declare const ViewStopButton: import("styled-components").StyledComponent<"button", any, {}, never>;
|
|
3
|
-
/**
|
|
4
|
-
* Adds a box shadow and tweaks border radius to make popups easier to read.
|
|
5
|
-
*/
|
|
6
|
-
export declare const Popup: import("styled-components").StyledComponent<import("react").MemoExoticComponent<(props: import("react-map-gl").PopupProps) => any>, any, {}, never>;
|
|
7
|
-
export declare const MapOverlayPopup: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
8
|
-
export declare const PopupRow: import("styled-components").StyledComponent<"p", any, {}, never>;
|
|
9
|
-
export declare const PopupTitle: import("styled-components").StyledComponent<"header", any, {}, never>;
|
|
10
2
|
//# sourceMappingURL=styled.d.ts.map
|
package/lib/styled.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styled.d.ts","sourceRoot":"","sources":["../src/styled.ts"],"names":[],"mappings":"
|
|
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
|
@@ -5,47 +5,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.ViewStopButton = void 0;
|
|
9
9
|
|
|
10
10
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
11
|
|
|
12
|
-
var _reactMapGl = require("react-map-gl");
|
|
13
|
-
|
|
14
12
|
/* eslint-disable-next-line import/prefer-default-export */
|
|
15
13
|
const ViewStopButton = _styledComponents.default.button.withConfig({
|
|
16
14
|
displayName: "styled__ViewStopButton",
|
|
17
15
|
componentId: "sc-12v7ov3-0"
|
|
18
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;"]);
|
|
19
|
-
/**
|
|
20
|
-
* Adds a box shadow and tweaks border radius to make popups easier to read.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
17
|
|
|
24
18
|
exports.ViewStopButton = ViewStopButton;
|
|
25
|
-
const Popup = (0, _styledComponents.default)(_reactMapGl.Popup).withConfig({
|
|
26
|
-
displayName: "styled__Popup",
|
|
27
|
-
componentId: "sc-12v7ov3-1"
|
|
28
|
-
})(["& > .maplibregl-popup-content,& > .mapboxgl-popup-content{border-radius:10px;box-shadow:0 3px 14px 4px rgb(0 0 0 / 20%);}"]);
|
|
29
|
-
exports.Popup = Popup;
|
|
30
|
-
|
|
31
|
-
const MapOverlayPopup = _styledComponents.default.div.withConfig({
|
|
32
|
-
displayName: "styled__MapOverlayPopup",
|
|
33
|
-
componentId: "sc-12v7ov3-2"
|
|
34
|
-
})(["font-size:12px;line-height:1.5;min-width:250px;"]);
|
|
35
|
-
|
|
36
|
-
exports.MapOverlayPopup = MapOverlayPopup;
|
|
37
|
-
|
|
38
|
-
const PopupRow = _styledComponents.default.p.withConfig({
|
|
39
|
-
displayName: "styled__PopupRow",
|
|
40
|
-
componentId: "sc-12v7ov3-3"
|
|
41
|
-
})(["margin-top:6px;"]);
|
|
42
|
-
|
|
43
|
-
exports.PopupRow = PopupRow;
|
|
44
|
-
|
|
45
|
-
const PopupTitle = _styledComponents.default.header.withConfig({
|
|
46
|
-
displayName: "styled__PopupTitle",
|
|
47
|
-
componentId: "sc-12v7ov3-4"
|
|
48
|
-
})(["font-size:18px;font-weight:500;margin-bottom:6px;"]);
|
|
49
|
-
|
|
50
|
-
exports.PopupTitle = PopupTitle;
|
|
51
19
|
//# sourceMappingURL=styled.js.map
|
package/lib/styled.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/styled.ts"],"names":["ViewStopButton","styled","button"
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentripplanner/map-popup",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.0-alpha.1",
|
|
4
4
|
"description": "A component for displaying map popup contents",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -11,12 +11,14 @@
|
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"private": false,
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@opentripplanner/
|
|
15
|
-
"@opentripplanner/
|
|
14
|
+
"@opentripplanner/base-map": "^3.2.2",
|
|
15
|
+
"@opentripplanner/building-blocks": "^1.2.2",
|
|
16
|
+
"@opentripplanner/core-utils": "^11.4.4",
|
|
17
|
+
"@opentripplanner/from-to-location-picker": "^2.1.14",
|
|
16
18
|
"flat": "^5.0.2"
|
|
17
19
|
},
|
|
18
20
|
"devDependencies": {
|
|
19
|
-
"@opentripplanner/types": "^6.5.
|
|
21
|
+
"@opentripplanner/types": "^6.5.2"
|
|
20
22
|
},
|
|
21
23
|
"peerDependencies": {
|
|
22
24
|
"react": "^18.2.0",
|
package/src/MapPopup.story.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { action } from "@storybook/addon-actions";
|
|
3
|
-
import
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { Station, Stop } from "@opentripplanner/types";
|
|
5
|
+
import MapPopupContents from "./index";
|
|
4
6
|
|
|
5
7
|
export default {
|
|
6
8
|
title: "Map Popup"
|
|
@@ -8,6 +10,7 @@ export default {
|
|
|
8
10
|
|
|
9
11
|
const STOP = {
|
|
10
12
|
flex: false,
|
|
13
|
+
gtfsId: "9526",
|
|
11
14
|
id: "9526",
|
|
12
15
|
lat: 45.523009,
|
|
13
16
|
lon: -122.672529,
|
|
@@ -64,6 +67,18 @@ const FLOATING_CAR = {
|
|
|
64
67
|
y: 52.52
|
|
65
68
|
};
|
|
66
69
|
|
|
70
|
+
const getEntityPrefixExample = (entity: Stop | Station) => {
|
|
71
|
+
const DemoIcon = styled.span`
|
|
72
|
+
background-color: blue;
|
|
73
|
+
border-radius: 50px;
|
|
74
|
+
color: white;
|
|
75
|
+
margin-right: 0.5ch;
|
|
76
|
+
padding: 2px;
|
|
77
|
+
`;
|
|
78
|
+
|
|
79
|
+
return <DemoIcon>{entity.name?.charAt(0)}</DemoIcon>;
|
|
80
|
+
};
|
|
81
|
+
|
|
67
82
|
export const StopEntity = (): JSX.Element => (
|
|
68
83
|
<MapPopupContents
|
|
69
84
|
entity={STOP}
|
|
@@ -71,6 +86,14 @@ export const StopEntity = (): JSX.Element => (
|
|
|
71
86
|
setViewedStop={action("setViewedStop")}
|
|
72
87
|
/>
|
|
73
88
|
);
|
|
89
|
+
export const StopEntitywithEntityPrefix = (): JSX.Element => (
|
|
90
|
+
<MapPopupContents
|
|
91
|
+
entity={STOP}
|
|
92
|
+
getEntityPrefix={getEntityPrefixExample}
|
|
93
|
+
setLocation={action("setLocation")}
|
|
94
|
+
setViewedStop={action("setViewedStop")}
|
|
95
|
+
/>
|
|
96
|
+
);
|
|
74
97
|
|
|
75
98
|
export const StopEntityNoHandlers = (): JSX.Element => (
|
|
76
99
|
<MapPopupContents entity={STOP} />
|
|
@@ -95,13 +118,3 @@ export const FloatingVehicleEntity = (): JSX.Element => (
|
|
|
95
118
|
setViewedStop={action("setViewedStop")}
|
|
96
119
|
/>
|
|
97
120
|
);
|
|
98
|
-
|
|
99
|
-
export const StopEntityWithFocusTrap = (): JSX.Element => (
|
|
100
|
-
<FocusTrapWrapper closePopup={() => {}} id="storybook-stop">
|
|
101
|
-
<MapPopupContents
|
|
102
|
-
entity={STOP}
|
|
103
|
-
setLocation={action("setLocation")}
|
|
104
|
-
setViewedStop={action("setViewedStop")}
|
|
105
|
-
/>
|
|
106
|
-
</FocusTrapWrapper>
|
|
107
|
-
);
|