react-spatial 1.2.2 → 1.2.3-beta.3
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/LayerService.js +128 -184
- package/LayerService.js.map +7 -1
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +163 -221
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -1
- package/components/BaseLayerSwitcher/index.js +1 -3
- package/components/BaseLayerSwitcher/index.js.map +7 -1
- package/components/BasicMap/BasicMap.js +147 -285
- package/components/BasicMap/BasicMap.js.map +7 -1
- package/components/BasicMap/index.js +1 -3
- package/components/BasicMap/index.js.map +7 -1
- package/components/CanvasSaveButton/CanvasSaveButton.js +165 -419
- package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -1
- package/components/CanvasSaveButton/index.js +1 -3
- package/components/CanvasSaveButton/index.js.map +7 -1
- package/components/Copyright/Copyright.js +29 -70
- package/components/Copyright/Copyright.js.map +7 -1
- package/components/Copyright/index.js +1 -3
- package/components/Copyright/index.js.map +7 -1
- package/components/FeatureExportButton/FeatureExportButton.js +40 -106
- package/components/FeatureExportButton/FeatureExportButton.js.map +7 -1
- package/components/FeatureExportButton/index.js +1 -3
- package/components/FeatureExportButton/index.js.map +7 -1
- package/components/FilterButton/FilterButton.js +41 -106
- package/components/FilterButton/FilterButton.js.map +7 -1
- package/components/FilterButton/index.js +1 -3
- package/components/FilterButton/index.js.map +7 -1
- package/components/FitExtent/FitExtent.js +17 -50
- package/components/FitExtent/FitExtent.js.map +7 -1
- package/components/FitExtent/index.js +1 -3
- package/components/FitExtent/index.js.map +7 -1
- package/components/FollowButton/FollowButton.js +41 -111
- package/components/FollowButton/FollowButton.js.map +7 -1
- package/components/FollowButton/index.js +1 -3
- package/components/FollowButton/index.js.map +7 -1
- package/components/Geolocation/Geolocation.js +104 -213
- package/components/Geolocation/Geolocation.js.map +7 -1
- package/components/Geolocation/index.js +1 -3
- package/components/Geolocation/index.js.map +7 -1
- package/components/LayerTree/LayerTree.js +204 -410
- package/components/LayerTree/LayerTree.js.map +7 -1
- package/components/LayerTree/index.js +1 -3
- package/components/LayerTree/index.js.map +7 -1
- package/components/MousePosition/MousePosition.js +61 -130
- package/components/MousePosition/MousePosition.js.map +7 -1
- package/components/MousePosition/index.js +1 -3
- package/components/MousePosition/index.js.map +7 -1
- package/components/NorthArrow/NorthArrow.js +22 -62
- package/components/NorthArrow/NorthArrow.js.map +7 -1
- package/components/NorthArrow/index.js +1 -3
- package/components/NorthArrow/index.js.map +7 -1
- package/components/Overlay/Overlay.js +83 -130
- package/components/Overlay/Overlay.js.map +7 -1
- package/components/Overlay/index.js +1 -3
- package/components/Overlay/index.js.map +7 -1
- package/components/Permalink/Permalink.js +150 -244
- package/components/Permalink/Permalink.js.map +7 -1
- package/components/Permalink/index.js +1 -3
- package/components/Permalink/index.js.map +7 -1
- package/components/Popup/Popup.js +106 -233
- package/components/Popup/Popup.js.map +7 -1
- package/components/Popup/index.js +1 -3
- package/components/Popup/index.js.map +7 -1
- package/components/ResizeHandler/ResizeHandler.js +58 -113
- package/components/ResizeHandler/ResizeHandler.js.map +7 -1
- package/components/ResizeHandler/index.js +1 -3
- package/components/ResizeHandler/index.js.map +7 -1
- package/components/RouteSchedule/RouteSchedule.js +150 -283
- package/components/RouteSchedule/RouteSchedule.js.map +7 -1
- package/components/RouteSchedule/index.js +1 -3
- package/components/RouteSchedule/index.js.map +7 -1
- package/components/ScaleLine/ScaleLine.js +21 -45
- package/components/ScaleLine/ScaleLine.js.map +7 -1
- package/components/ScaleLine/index.js +1 -3
- package/components/ScaleLine/index.js.map +7 -1
- package/components/Search/Search.js +122 -186
- package/components/Search/Search.js.map +7 -1
- package/components/Search/SearchService.js +45 -69
- package/components/Search/SearchService.js.map +7 -1
- package/components/Search/engines/Engine.js +18 -25
- package/components/Search/engines/Engine.js.map +7 -1
- package/components/Search/engines/StopFinder.js +21 -38
- package/components/Search/engines/StopFinder.js.map +7 -1
- package/components/Search/index.js +3 -6
- package/components/Search/index.js.map +7 -1
- package/components/StopsFinder/StopsFinder.js +123 -174
- package/components/StopsFinder/StopsFinder.js.map +7 -1
- package/components/StopsFinder/StopsFinderOption.js +37 -54
- package/components/StopsFinder/StopsFinderOption.js.map +7 -1
- package/components/StopsFinder/index.js +1 -3
- package/components/StopsFinder/index.js.map +7 -1
- package/components/TrackerControl/TrackerControl.js +73 -128
- package/components/TrackerControl/TrackerControl.js.map +7 -1
- package/components/TrackerControl/index.js +1 -3
- package/components/TrackerControl/index.js.map +7 -1
- package/components/Zoom/Zoom.js +69 -112
- package/components/Zoom/Zoom.js.map +7 -1
- package/components/Zoom/index.js +1 -3
- package/components/Zoom/index.js.map +7 -1
- package/package.json +10 -5
- package/propTypes.js +17 -23
- package/propTypes.js.map +7 -1
- package/setupTests.js +2 -4
- package/setupTests.js.map +7 -1
- package/themes/README.md +26 -0
- package/themes/default/components.scss +0 -1
- package/themes/default/examples.scss +0 -1
- package/utils/GlobalsForOle.js +63 -64
- package/utils/GlobalsForOle.js.map +7 -1
- package/utils/KML.js +178 -364
- package/utils/KML.js.map +7 -1
- package/utils/KMLFormat.js +37 -73
- package/utils/KMLFormat.js.map +7 -1
- package/utils/Styles.js +24 -32
- package/utils/Styles.js.map +7 -1
- package/utils/getPolygonPattern.js +11 -44
- package/utils/getPolygonPattern.js.map +7 -1
- package/utils/timeUtils.js +16 -35
- package/utils/timeUtils.js.map +7 -1
- package/LayerService.test.js +0 -160
- package/LayerService.test.js.map +0 -1
- package/Projections.js +0 -16
- package/Projections.js.map +0 -1
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -88
- package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js.map +0 -1
- package/components/BaseLayerToggler/BaseLayerToggler.js +0 -490
- package/components/BaseLayerToggler/BaseLayerToggler.js.map +0 -1
- package/components/BaseLayerToggler/BaseLayerToggler.md.scss +0 -9
- package/components/BaseLayerToggler/BaseLayerToggler.scss +0 -49
- package/components/BaseLayerToggler/BaseLayerToggler.test.js +0 -127
- package/components/BaseLayerToggler/BaseLayerToggler.test.js.map +0 -1
- package/components/BaseLayerToggler/index.js +0 -3
- package/components/BaseLayerToggler/index.js.map +0 -1
- package/components/BasicMap/BasicMap.test.js +0 -288
- package/components/BasicMap/BasicMap.test.js.map +0 -1
- package/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -173
- package/components/CanvasSaveButton/CanvasSaveButton.test.js.map +0 -1
- package/components/Copyright/Copyright.test.js +0 -133
- package/components/Copyright/Copyright.test.js.map +0 -1
- package/components/FeatureExportButton/FeatureExportButton.test.js +0 -407
- package/components/FeatureExportButton/FeatureExportButton.test.js.map +0 -1
- package/components/FilterButton/FilterButton.test.js +0 -48
- package/components/FilterButton/FilterButton.test.js.map +0 -1
- package/components/FitExtent/FitExtent.test.js +0 -44
- package/components/FitExtent/FitExtent.test.js.map +0 -1
- package/components/FollowButton/FollowButton.test.js +0 -57
- package/components/FollowButton/FollowButton.test.js.map +0 -1
- package/components/Geolocation/Geolocation.test.js +0 -263
- package/components/Geolocation/Geolocation.test.js.map +0 -1
- package/components/LayerTree/LayerTree.test.js +0 -323
- package/components/LayerTree/LayerTree.test.js.map +0 -1
- package/components/MousePosition/MousePosition.test.js +0 -125
- package/components/MousePosition/MousePosition.test.js.map +0 -1
- package/components/NorthArrow/NorthArrow.test.js +0 -106
- package/components/NorthArrow/NorthArrow.test.js.map +0 -1
- package/components/Overlay/Overlay.test.js +0 -145
- package/components/Overlay/Overlay.test.js.map +0 -1
- package/components/Permalink/Permalink.test.js +0 -267
- package/components/Permalink/Permalink.test.js.map +0 -1
- package/components/Popup/Popup.test.js +0 -291
- package/components/Popup/Popup.test.js.map +0 -1
- package/components/ResizeHandler/ResizeHandler.test.js +0 -410
- package/components/ResizeHandler/ResizeHandler.test.js.map +0 -1
- package/components/RouteSchedule/RouteSchedule.test.js +0 -102
- package/components/RouteSchedule/RouteSchedule.test.js.map +0 -1
- package/components/ScaleLine/ScaleLine.test.js +0 -32
- package/components/ScaleLine/ScaleLine.test.js.map +0 -1
- package/components/Search/Search.test.js +0 -15
- package/components/Search/Search.test.js.map +0 -1
- package/components/StopsFinder/StopsFinder.test.js +0 -19
- package/components/StopsFinder/StopsFinder.test.js.map +0 -1
- package/components/TrackerControl/TrackerControl.test.js +0 -17
- package/components/TrackerControl/TrackerControl.test.js.map +0 -1
- package/components/Zoom/Zoom.test.js +0 -150
- package/components/Zoom/Zoom.test.js.map +0 -1
- package/styleguidist/ComponentsList.js +0 -52
- package/styleguidist/ComponentsList.js.map +0 -1
- package/styleguidist/StyleGuide.js +0 -253
- package/styleguidist/StyleGuide.js.map +0 -1
- package/utils/KML.test.js +0 -163
- package/utils/KML.test.js.map +0 -1
- package/utils/KMLFormat.test.js +0 -22
- package/utils/KMLFormat.test.js.map +0 -1
- package/utils/getPolygonPattern.test.js +0 -66
- package/utils/getPolygonPattern.test.js.map +0 -1
- package/utils/timeUtils.test.js +0 -32
- package/utils/timeUtils.test.js.map +0 -1
|
@@ -1,56 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var propTypes = {
|
|
8
|
-
/**
|
|
9
|
-
* ol/map.
|
|
10
|
-
*/
|
|
1
|
+
import React, { useRef, useEffect } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import OLScaleLine from "ol/control/ScaleLine";
|
|
4
|
+
import OLMap from "ol/Map";
|
|
5
|
+
const propTypes = {
|
|
11
6
|
map: PropTypes.instanceOf(OLMap).isRequired,
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Options for ol/control/ScaleLine.
|
|
15
|
-
* See https://openlayers.org/en/latest/apidoc/module-ol_control_ScaleLine-ScaleLine.html
|
|
16
|
-
*/
|
|
17
|
-
options: PropTypes.object,
|
|
7
|
+
options: PropTypes.object
|
|
18
8
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
options: {},
|
|
9
|
+
const defaultProps = {
|
|
10
|
+
options: {}
|
|
22
11
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
var map = ref$1.map;
|
|
31
|
-
var options = ref$1.options;
|
|
32
|
-
var rest = objectWithoutProperties( ref$1, ["map", "options"] );
|
|
33
|
-
var other = rest;
|
|
34
|
-
|
|
35
|
-
var ref = useRef();
|
|
36
|
-
|
|
37
|
-
useEffect(function () {
|
|
38
|
-
var control = new OLScaleLine(Object.assign({}, options,
|
|
39
|
-
{target: ref.current}));
|
|
40
|
-
|
|
12
|
+
function ScaleLine({ map, options, ...other }) {
|
|
13
|
+
const ref = useRef();
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const control = new OLScaleLine({
|
|
16
|
+
...options,
|
|
17
|
+
...{ target: ref.current }
|
|
18
|
+
});
|
|
41
19
|
map.addControl(control);
|
|
42
|
-
return
|
|
20
|
+
return () => {
|
|
43
21
|
map.removeControl(control);
|
|
44
22
|
};
|
|
45
23
|
}, [map, options]);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
24
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
25
|
+
className: "rs-scale-line",
|
|
26
|
+
ref,
|
|
27
|
+
...other
|
|
28
|
+
});
|
|
49
29
|
}
|
|
50
|
-
|
|
51
30
|
ScaleLine.propTypes = propTypes;
|
|
52
31
|
ScaleLine.defaultProps = defaultProps;
|
|
53
|
-
|
|
54
32
|
export default React.memo(ScaleLine);
|
|
55
|
-
|
|
56
|
-
//# sourceMappingURL=ScaleLine.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/ScaleLine/ScaleLine.js"],
|
|
4
|
+
"sourcesContent": ["import React, { useRef, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport OLScaleLine from 'ol/control/ScaleLine';\nimport OLMap from 'ol/Map';\n\nconst propTypes = {\n /**\n * ol/map.\n */\n map: PropTypes.instanceOf(OLMap).isRequired,\n\n /**\n * Options for ol/control/ScaleLine.\n * See https://openlayers.org/en/latest/apidoc/module-ol_control_ScaleLine-ScaleLine.html\n */\n options: PropTypes.object,\n};\n\nconst defaultProps = {\n options: {},\n};\n\n/**\n * The ScaleLine component creates an\n * [ol/control/ScaleLine](https://openlayers.org/en/latest/apidoc/module-ol_control_ScaleLine-ScaleLine.html)\n * for an [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).\n */\nfunction ScaleLine({ map, options, ...other }) {\n const ref = useRef();\n\n useEffect(() => {\n const control = new OLScaleLine({\n ...options,\n ...{ target: ref.current },\n });\n\n map.addControl(control);\n return () => {\n map.removeControl(control);\n };\n }, [map, options]);\n\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <div className=\"rs-scale-line\" ref={ref} {...other} />;\n}\n\nScaleLine.propTypes = propTypes;\nScaleLine.defaultProps = defaultProps;\n\nexport default React.memo(ScaleLine);\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,QAAQ,iBAAiB;AACzC,OAAO,eAAe;AACtB,OAAO,iBAAiB;AACxB,OAAO,WAAW;AAElB,MAAM,YAAY;AAAA,EAIhB,KAAK,UAAU,WAAW,KAAK,EAAE;AAAA,EAMjC,SAAS,UAAU;AACrB;AAEA,MAAM,eAAe;AAAA,EACnB,SAAS,CAAC;AACZ;AAOA,SAAS,UAAU,EAAE,KAAK,YAAY,MAAM,GAAG;AAC7C,QAAM,MAAM,OAAO;AAEnB,YAAU,MAAM;AACd,UAAM,UAAU,IAAI,YAAY;AAAA,MAC9B,GAAG;AAAA,MACH,GAAG,EAAE,QAAQ,IAAI,QAAQ;AAAA,IAC3B,CAAC;AAED,QAAI,WAAW,OAAO;AACtB,WAAO,MAAM;AACX,UAAI,cAAc,OAAO;AAAA,IAC3B;AAAA,EACF,GAAG,CAAC,KAAK,OAAO,CAAC;AAGjB,SAAO,oCAAC;AAAA,IAAI,WAAU;AAAA,IAAgB;AAAA,IAAW,GAAG;AAAA,GAAO;AAC7D;AAEA,UAAU,YAAY;AACtB,UAAU,eAAe;AAEzB,eAAe,MAAM,KAAK,SAAS;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/ScaleLine/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default } from './ScaleLine';\n"],
|
|
5
|
+
"mappings": "AAAA,wBAAwB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,104 +1,60 @@
|
|
|
1
|
-
import PropTypes from
|
|
2
|
-
import React, { useMemo, useState } from
|
|
3
|
-
import Autosuggest from
|
|
4
|
-
import { FaSearch, FaTimes } from
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var propTypes = {
|
|
10
|
-
/**
|
|
11
|
-
* Flat object to provide custom search engines: key is the section and value an instance of the Engine class.
|
|
12
|
-
*/
|
|
1
|
+
import PropTypes from "prop-types";
|
|
2
|
+
import React, { useMemo, useState } from "react";
|
|
3
|
+
import Autosuggest from "react-autosuggest";
|
|
4
|
+
import { FaSearch, FaTimes } from "react-icons/fa";
|
|
5
|
+
import SearchService from "./SearchService";
|
|
6
|
+
import StopFinder from "./engines/StopFinder";
|
|
7
|
+
const propTypes = {
|
|
13
8
|
engines: PropTypes.object,
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A function which will receive the searchService instance and needs to return a render function for the section title, see [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#render-section-title-prop) for details.
|
|
17
|
-
*/
|
|
18
9
|
getRenderSectionTitle: PropTypes.func,
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Initial value for the search input field.
|
|
22
|
-
*/
|
|
23
10
|
initialValue: PropTypes.string,
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Props for the search input field, see [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#input-props-prop) for details.
|
|
27
|
-
*/
|
|
28
11
|
inputProps: PropTypes.object,
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Callback function which will be called with the hovered suggestion.
|
|
32
|
-
*/
|
|
33
12
|
onHighlight: PropTypes.func,
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Function to define whether the suggestions are displayed or not.
|
|
37
|
-
* See 'shouldRenderSuggestions' in [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#input-props-prop) for details.
|
|
38
|
-
*/
|
|
39
13
|
shouldRenderSuggestions: PropTypes.func,
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Callback function which will be called with the selected suggestion.
|
|
43
|
-
*/
|
|
44
14
|
onSelect: PropTypes.func,
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* CSS class of the component.
|
|
48
|
-
*/
|
|
49
15
|
className: PropTypes.string,
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Key to access the engine api.
|
|
53
|
-
*/
|
|
54
|
-
apiKey: PropTypes.string,
|
|
16
|
+
apiKey: PropTypes.string
|
|
55
17
|
};
|
|
56
|
-
|
|
57
|
-
var defaultProps = {
|
|
18
|
+
const defaultProps = {
|
|
58
19
|
apiKey: null,
|
|
59
20
|
engines: null,
|
|
60
|
-
getRenderSectionTitle:
|
|
61
|
-
return
|
|
21
|
+
getRenderSectionTitle: () => {
|
|
22
|
+
return () => {
|
|
62
23
|
return null;
|
|
63
24
|
};
|
|
64
25
|
},
|
|
65
|
-
initialValue:
|
|
66
|
-
onHighlight:
|
|
26
|
+
initialValue: "",
|
|
27
|
+
onHighlight: () => {
|
|
67
28
|
return null;
|
|
68
29
|
},
|
|
69
|
-
shouldRenderSuggestions:
|
|
30
|
+
shouldRenderSuggestions: (newValue) => {
|
|
70
31
|
return newValue.trim().length > 2;
|
|
71
32
|
},
|
|
72
|
-
onSelect:
|
|
33
|
+
onSelect: () => {
|
|
73
34
|
return null;
|
|
74
35
|
},
|
|
75
|
-
className:
|
|
76
|
-
inputProps: {}
|
|
36
|
+
className: "rt-search",
|
|
37
|
+
inputProps: {}
|
|
77
38
|
};
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
var shouldRenderSuggestions = ref.shouldRenderSuggestions;
|
|
91
|
-
var onSelect = ref.onSelect;
|
|
92
|
-
var className = ref.className;
|
|
93
|
-
|
|
94
|
-
var currentEngines = useMemo(function () {
|
|
39
|
+
function Search({
|
|
40
|
+
apiKey,
|
|
41
|
+
engines,
|
|
42
|
+
getRenderSectionTitle,
|
|
43
|
+
initialValue,
|
|
44
|
+
inputProps,
|
|
45
|
+
onHighlight,
|
|
46
|
+
shouldRenderSuggestions,
|
|
47
|
+
onSelect,
|
|
48
|
+
className
|
|
49
|
+
}) {
|
|
50
|
+
const currentEngines = useMemo(() => {
|
|
95
51
|
if (!engines) {
|
|
96
52
|
return {
|
|
97
|
-
stops: new StopFinder(
|
|
53
|
+
stops: new StopFinder(void 0, { apiKey })
|
|
98
54
|
};
|
|
99
55
|
}
|
|
100
56
|
if (apiKey) {
|
|
101
|
-
Object.values(engines).forEach(
|
|
57
|
+
Object.values(engines).forEach((engine) => {
|
|
102
58
|
if (engine.setApiKey) {
|
|
103
59
|
engine.setApiKey(apiKey);
|
|
104
60
|
}
|
|
@@ -106,125 +62,105 @@ function Search(ref) {
|
|
|
106
62
|
}
|
|
107
63
|
return engines;
|
|
108
64
|
}, [apiKey, engines]);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
var setSuggestions = ref$1[1];
|
|
113
|
-
var ref$2 = useState(initialValue);
|
|
114
|
-
var value = ref$2[0];
|
|
115
|
-
var setValue = ref$2[1];
|
|
116
|
-
|
|
117
|
-
var searchService = useMemo(function () {
|
|
65
|
+
const [suggestions, setSuggestions] = useState([]);
|
|
66
|
+
const [value, setValue] = useState(initialValue);
|
|
67
|
+
const searchService = useMemo(() => {
|
|
118
68
|
return new SearchService({
|
|
119
|
-
apiKey
|
|
69
|
+
apiKey,
|
|
120
70
|
engines: currentEngines,
|
|
121
|
-
setSuggestions
|
|
71
|
+
setSuggestions
|
|
122
72
|
});
|
|
123
73
|
}, [apiKey, currentEngines]);
|
|
124
|
-
|
|
125
|
-
var theme = useMemo(function () {
|
|
74
|
+
const theme = useMemo(() => {
|
|
126
75
|
return {
|
|
127
|
-
container:
|
|
128
|
-
containerOpen:
|
|
129
|
-
input:
|
|
130
|
-
inputOpen:
|
|
131
|
-
inputFocused:
|
|
132
|
-
suggestionsContainer:
|
|
133
|
-
suggestionsContainerOpen:
|
|
134
|
-
suggestionsList:
|
|
135
|
-
suggestion:
|
|
136
|
-
suggestionFirst:
|
|
137
|
-
suggestionHighlighted:
|
|
138
|
-
sectionContainer:
|
|
139
|
-
sectionContainerFirst:
|
|
140
|
-
sectionTitle:
|
|
76
|
+
container: `${className}__container`,
|
|
77
|
+
containerOpen: `${className}__container--open`,
|
|
78
|
+
input: `${className}__input`,
|
|
79
|
+
inputOpen: `${className}__input--open`,
|
|
80
|
+
inputFocused: `${className}__input--focused`,
|
|
81
|
+
suggestionsContainer: `${className}__suggestions-container`,
|
|
82
|
+
suggestionsContainerOpen: `${className}__suggestions-container--open`,
|
|
83
|
+
suggestionsList: `${className}__suggestions-list`,
|
|
84
|
+
suggestion: `${className}__suggestion`,
|
|
85
|
+
suggestionFirst: `${className}__suggestion--first`,
|
|
86
|
+
suggestionHighlighted: `${className}__suggestion--highlighted`,
|
|
87
|
+
sectionContainer: `${className}__section-container`,
|
|
88
|
+
sectionContainerFirst: `${className}__section-container--first`,
|
|
89
|
+
sectionTitle: `${className}__section-title`
|
|
141
90
|
};
|
|
142
91
|
}, [className]);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
)
|
|
215
|
-
),
|
|
216
|
-
React.createElement( 'button', {
|
|
217
|
-
type: "button", tabIndex: 0, className: "rt-search-button rt-search-button-submit" },
|
|
218
|
-
React.createElement( FaSearch, { focusable: false })
|
|
219
|
-
)
|
|
220
|
-
)
|
|
221
|
-
)
|
|
222
|
-
);
|
|
92
|
+
return Object.keys(currentEngines).length > 0 && /* @__PURE__ */ React.createElement("div", {
|
|
93
|
+
className: "rt-search"
|
|
94
|
+
}, /* @__PURE__ */ React.createElement(Autosuggest, {
|
|
95
|
+
theme,
|
|
96
|
+
inputProps: {
|
|
97
|
+
autoFocus: true,
|
|
98
|
+
tabIndex: 0,
|
|
99
|
+
onChange: (e, { newValue }) => {
|
|
100
|
+
return setValue(newValue);
|
|
101
|
+
},
|
|
102
|
+
onKeyUp: ({ key }) => {
|
|
103
|
+
if (key === "Enter") {
|
|
104
|
+
const filtered = suggestions.filter((s) => {
|
|
105
|
+
return s.items.length > 0;
|
|
106
|
+
});
|
|
107
|
+
if (filtered.length > 0) {
|
|
108
|
+
const { items, section } = filtered[0];
|
|
109
|
+
const targetSuggestion = { ...items[0], section };
|
|
110
|
+
setValue(searchService.value(targetSuggestion));
|
|
111
|
+
onSelect(targetSuggestion);
|
|
112
|
+
}
|
|
113
|
+
} else if ((key === "ArrowDown" || key === "ArrowUp") && typeof searchService.highlightSection === "function") {
|
|
114
|
+
searchService.highlightSection();
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
value,
|
|
118
|
+
...inputProps
|
|
119
|
+
},
|
|
120
|
+
multiSection: true,
|
|
121
|
+
getSectionSuggestions: ({ items, section }) => {
|
|
122
|
+
return items ? items.map((i) => {
|
|
123
|
+
return { ...i, section };
|
|
124
|
+
}) : [];
|
|
125
|
+
},
|
|
126
|
+
getSuggestionValue: (suggestion) => {
|
|
127
|
+
return searchService.value(suggestion);
|
|
128
|
+
},
|
|
129
|
+
onSuggestionsFetchRequested: ({ value: newValue }) => {
|
|
130
|
+
return searchService.search(newValue);
|
|
131
|
+
},
|
|
132
|
+
onSuggestionsClearRequested: () => {
|
|
133
|
+
return setSuggestions([]);
|
|
134
|
+
},
|
|
135
|
+
onSuggestionHighlighted: ({ suggestion }) => {
|
|
136
|
+
return onHighlight(suggestion);
|
|
137
|
+
},
|
|
138
|
+
onSuggestionSelected: (e, { suggestion }) => {
|
|
139
|
+
return onSelect(suggestion);
|
|
140
|
+
},
|
|
141
|
+
renderSuggestion: (suggestion) => {
|
|
142
|
+
return searchService.render(suggestion);
|
|
143
|
+
},
|
|
144
|
+
renderSectionTitle: getRenderSectionTitle(searchService),
|
|
145
|
+
shouldRenderSuggestions: (newValue) => {
|
|
146
|
+
return shouldRenderSuggestions(newValue);
|
|
147
|
+
},
|
|
148
|
+
suggestions
|
|
149
|
+
}), value && /* @__PURE__ */ React.createElement("button", {
|
|
150
|
+
type: "button",
|
|
151
|
+
tabIndex: 0,
|
|
152
|
+
className: "rt-search-button rt-search-button-clear",
|
|
153
|
+
onClick: () => {
|
|
154
|
+
return setValue("");
|
|
155
|
+
}
|
|
156
|
+
}, /* @__PURE__ */ React.createElement(FaTimes, null)), /* @__PURE__ */ React.createElement("button", {
|
|
157
|
+
type: "button",
|
|
158
|
+
tabIndex: 0,
|
|
159
|
+
className: "rt-search-button rt-search-button-submit"
|
|
160
|
+
}, /* @__PURE__ */ React.createElement(FaSearch, {
|
|
161
|
+
focusable: false
|
|
162
|
+
})));
|
|
223
163
|
}
|
|
224
|
-
|
|
225
164
|
Search.propTypes = propTypes;
|
|
226
165
|
Search.defaultProps = defaultProps;
|
|
227
|
-
|
|
228
166
|
export default Search;
|
|
229
|
-
|
|
230
|
-
//# sourceMappingURL=Search.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"file":"Search.js","sources":["../../../src/components/Search/Search.js"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React, { useMemo, useState } from 'react';\nimport Autosuggest from 'react-autosuggest';\nimport { FaSearch, FaTimes } from 'react-icons/fa';\n\nimport SearchService from './SearchService';\nimport StopFinder from './engines/StopFinder';\n\nconst propTypes = {\n /**\n * Flat object to provide custom search engines: key is the section and value an instance of the Engine class.\n */\n engines: PropTypes.object,\n\n /**\n * A function which will receive the searchService instance and needs to return a render function for the section title, see [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#render-section-title-prop) for details.\n */\n getRenderSectionTitle: PropTypes.func,\n\n /**\n * Initial value for the search input field.\n */\n initialValue: PropTypes.string,\n\n /**\n * Props for the search input field, see [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#input-props-prop) for details.\n */\n inputProps: PropTypes.object,\n\n /**\n * Callback function which will be called with the hovered suggestion.\n */\n onHighlight: PropTypes.func,\n\n /**\n * Function to define whether the suggestions are displayed or not.\n * See 'shouldRenderSuggestions' in [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#input-props-prop) for details.\n */\n shouldRenderSuggestions: PropTypes.func,\n\n /**\n * Callback function which will be called with the selected suggestion.\n */\n onSelect: PropTypes.func,\n\n /**\n * CSS class of the component.\n */\n className: PropTypes.string,\n\n /**\n * Key to access the engine api.\n */\n apiKey: PropTypes.string,\n};\n\nconst defaultProps = {\n apiKey: null,\n engines: null,\n getRenderSectionTitle: () => {\n return () => {\n return null;\n };\n },\n initialValue: '',\n onHighlight: () => {\n return null;\n },\n shouldRenderSuggestions: (newValue) => {\n return newValue.trim().length > 2;\n },\n onSelect: () => {\n return null;\n },\n className: 'rt-search',\n inputProps: {},\n};\n\n/**\n * The Search component renders a text input field which searches for stops\n * using the input string and centers the map on the selected stop.\n */\nfunction Search({\n apiKey,\n engines,\n getRenderSectionTitle,\n initialValue,\n inputProps,\n onHighlight,\n shouldRenderSuggestions,\n onSelect,\n className,\n}) {\n const currentEngines = useMemo(() => {\n if (!engines) {\n return {\n stops: new StopFinder(undefined, { apiKey }),\n };\n }\n if (apiKey) {\n Object.values(engines).forEach((engine) => {\n if (engine.setApiKey) {\n engine.setApiKey(apiKey);\n }\n });\n }\n return engines;\n }, [apiKey, engines]);\n\n const [suggestions, setSuggestions] = useState([]);\n const [value, setValue] = useState(initialValue);\n\n const searchService = useMemo(() => {\n return new SearchService({\n apiKey,\n engines: currentEngines,\n setSuggestions,\n });\n }, [apiKey, currentEngines]);\n\n const theme = useMemo(() => {\n return {\n container: `${className}__container`,\n containerOpen: `${className}__container--open`,\n input: `${className}__input`,\n inputOpen: `${className}__input--open`,\n inputFocused: `${className}__input--focused`,\n suggestionsContainer: `${className}__suggestions-container`,\n suggestionsContainerOpen: `${className}__suggestions-container--open`,\n suggestionsList: `${className}__suggestions-list`,\n suggestion: `${className}__suggestion`,\n suggestionFirst: `${className}__suggestion--first`,\n suggestionHighlighted: `${className}__suggestion--highlighted`,\n sectionContainer: `${className}__section-container`,\n sectionContainerFirst: `${className}__section-container--first`,\n sectionTitle: `${className}__section-title`,\n };\n }, [className]);\n\n return (\n Object.keys(currentEngines).length > 0 && (\n <div className=\"rt-search\">\n <Autosuggest\n theme={theme}\n inputProps={{\n autoFocus: true,\n tabIndex: 0,\n onChange: (e, { newValue }) => {\n return setValue(newValue);\n },\n onKeyUp: ({ key }) => {\n if (key === 'Enter') {\n const filtered = suggestions.filter((s) => {\n return s.items.length > 0;\n });\n if (filtered.length > 0) {\n const { items, section } = filtered[0];\n const targetSuggestion = { ...items[0], section };\n setValue(searchService.value(targetSuggestion));\n onSelect(targetSuggestion);\n }\n } else if (\n (key === 'ArrowDown' || key === 'ArrowUp') &&\n typeof searchService.highlightSection === 'function'\n ) {\n searchService.highlightSection(); // for improved accessibility\n }\n },\n value,\n ...inputProps,\n }}\n multiSection\n getSectionSuggestions={({ items, section }) => {\n return items\n ? items.map((i) => {\n return { ...i, section };\n })\n : [];\n }}\n getSuggestionValue={(suggestion) => {\n return searchService.value(suggestion);\n }}\n onSuggestionsFetchRequested={({ value: newValue }) => {\n return searchService.search(newValue);\n }}\n onSuggestionsClearRequested={() => {\n return setSuggestions([]);\n }}\n onSuggestionHighlighted={({ suggestion }) => {\n return onHighlight(suggestion);\n }}\n onSuggestionSelected={(e, { suggestion }) => {\n return onSelect(suggestion);\n }}\n renderSuggestion={(suggestion) => {\n return searchService.render(suggestion);\n }}\n renderSectionTitle={getRenderSectionTitle(searchService)}\n shouldRenderSuggestions={(newValue) => {\n return shouldRenderSuggestions(newValue);\n }}\n suggestions={suggestions}\n />\n {value && (\n <button\n type=\"button\"\n tabIndex={0}\n className=\"rt-search-button rt-search-button-clear\"\n onClick={() => {\n return setValue('');\n }}\n >\n <FaTimes />\n </button>\n )}\n <button\n type=\"button\"\n tabIndex={0}\n className=\"rt-search-button rt-search-button-submit\"\n >\n <FaSearch focusable={false} />\n </button>\n </div>\n )\n );\n}\n\nSearch.propTypes = propTypes;\nSearch.defaultProps = defaultProps;\n\nexport default Search;\n"],"names":["const"],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,IAAI,OAAO,EAAE,QAAQ,QAAQ,OAAO,CAAC;AACjD,OAAO,WAAW,MAAM,mBAAmB,CAAC;AAC5C,SAAS,QAAQ,EAAE,OAAO,QAAQ,gBAAgB,CAAC;AACnD;AACA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,UAAU,MAAM,sBAAsB,CAAC;AAC9C;AACAA,GAAK,CAAC,SAAS,GAAG;AAClB;AACA;AACA;AACA,EAAE,OAAO,EAAE,SAAS,CAAC,MAAM;AAC3B;AACA;AACA;AACA;AACA,EAAE,qBAAqB,EAAE,SAAS,CAAC,IAAI;AACvC;AACA;AACA;AACA;AACA,EAAE,YAAY,EAAE,SAAS,CAAC,MAAM;AAChC;AACA;AACA;AACA;AACA,EAAE,UAAU,EAAE,SAAS,CAAC,MAAM;AAC9B;AACA;AACA;AACA;AACA,EAAE,WAAW,EAAE,SAAS,CAAC,IAAI;AAC7B;AACA;AACA;AACA;AACA;AACA,EAAE,uBAAuB,EAAE,SAAS,CAAC,IAAI;AACzC;AACA;AACA;AACA;AACA,EAAE,QAAQ,EAAE,SAAS,CAAC,IAAI;AAC1B;AACA;AACA;AACA;AACA,EAAE,SAAS,EAAE,SAAS,CAAC,MAAM;AAC7B;AACA;AACA;AACA;AACA,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM;AAC1B,CAAC,CAAC;AACF;AACAA,GAAK,CAAC,YAAY,GAAG;AACrB,EAAE,MAAM,EAAE,IAAI;AACd,EAAE,OAAO,EAAE,IAAI;AACf,EAAE,qBAAqB,WAAE,GAAM;AAC/B,IAAI,gBAAO,GAAM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AM,CAAM;AACZ,KAAK;AACL,GAAG,CAAC;AACJ,CAAC;AACD;AACA,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC;AAC7B,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;AACnC;AACA,eAAe,MAAM,CAAC;"}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/Search/Search.js"],
|
|
4
|
+
"sourcesContent": ["import PropTypes from 'prop-types';\nimport React, { useMemo, useState } from 'react';\nimport Autosuggest from 'react-autosuggest';\nimport { FaSearch, FaTimes } from 'react-icons/fa';\n\nimport SearchService from './SearchService';\nimport StopFinder from './engines/StopFinder';\n\nconst propTypes = {\n /**\n * Flat object to provide custom search engines: key is the section and value an instance of the Engine class.\n */\n engines: PropTypes.object,\n\n /**\n * A function which will receive the searchService instance and needs to return a render function for the section title, see [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#render-section-title-prop) for details.\n */\n getRenderSectionTitle: PropTypes.func,\n\n /**\n * Initial value for the search input field.\n */\n initialValue: PropTypes.string,\n\n /**\n * Props for the search input field, see [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#input-props-prop) for details.\n */\n inputProps: PropTypes.object,\n\n /**\n * Callback function which will be called with the hovered suggestion.\n */\n onHighlight: PropTypes.func,\n\n /**\n * Function to define whether the suggestions are displayed or not.\n * See 'shouldRenderSuggestions' in [react-autosuggest documentation](https://github.com/moroshko/react-autosuggest#input-props-prop) for details.\n */\n shouldRenderSuggestions: PropTypes.func,\n\n /**\n * Callback function which will be called with the selected suggestion.\n */\n onSelect: PropTypes.func,\n\n /**\n * CSS class of the component.\n */\n className: PropTypes.string,\n\n /**\n * Key to access the engine api.\n */\n apiKey: PropTypes.string,\n};\n\nconst defaultProps = {\n apiKey: null,\n engines: null,\n getRenderSectionTitle: () => {\n return () => {\n return null;\n };\n },\n initialValue: '',\n onHighlight: () => {\n return null;\n },\n shouldRenderSuggestions: (newValue) => {\n return newValue.trim().length > 2;\n },\n onSelect: () => {\n return null;\n },\n className: 'rt-search',\n inputProps: {},\n};\n\n/**\n * The Search component renders a text input field which searches for stops\n * using the input string and centers the map on the selected stop.\n */\nfunction Search({\n apiKey,\n engines,\n getRenderSectionTitle,\n initialValue,\n inputProps,\n onHighlight,\n shouldRenderSuggestions,\n onSelect,\n className,\n}) {\n const currentEngines = useMemo(() => {\n if (!engines) {\n return {\n stops: new StopFinder(undefined, { apiKey }),\n };\n }\n if (apiKey) {\n Object.values(engines).forEach((engine) => {\n if (engine.setApiKey) {\n engine.setApiKey(apiKey);\n }\n });\n }\n return engines;\n }, [apiKey, engines]);\n\n const [suggestions, setSuggestions] = useState([]);\n const [value, setValue] = useState(initialValue);\n\n const searchService = useMemo(() => {\n return new SearchService({\n apiKey,\n engines: currentEngines,\n setSuggestions,\n });\n }, [apiKey, currentEngines]);\n\n const theme = useMemo(() => {\n return {\n container: `${className}__container`,\n containerOpen: `${className}__container--open`,\n input: `${className}__input`,\n inputOpen: `${className}__input--open`,\n inputFocused: `${className}__input--focused`,\n suggestionsContainer: `${className}__suggestions-container`,\n suggestionsContainerOpen: `${className}__suggestions-container--open`,\n suggestionsList: `${className}__suggestions-list`,\n suggestion: `${className}__suggestion`,\n suggestionFirst: `${className}__suggestion--first`,\n suggestionHighlighted: `${className}__suggestion--highlighted`,\n sectionContainer: `${className}__section-container`,\n sectionContainerFirst: `${className}__section-container--first`,\n sectionTitle: `${className}__section-title`,\n };\n }, [className]);\n\n return (\n Object.keys(currentEngines).length > 0 && (\n <div className=\"rt-search\">\n <Autosuggest\n theme={theme}\n inputProps={{\n autoFocus: true,\n tabIndex: 0,\n onChange: (e, { newValue }) => {\n return setValue(newValue);\n },\n onKeyUp: ({ key }) => {\n if (key === 'Enter') {\n const filtered = suggestions.filter((s) => {\n return s.items.length > 0;\n });\n if (filtered.length > 0) {\n const { items, section } = filtered[0];\n const targetSuggestion = { ...items[0], section };\n setValue(searchService.value(targetSuggestion));\n onSelect(targetSuggestion);\n }\n } else if (\n (key === 'ArrowDown' || key === 'ArrowUp') &&\n typeof searchService.highlightSection === 'function'\n ) {\n searchService.highlightSection(); // for improved accessibility\n }\n },\n value,\n ...inputProps,\n }}\n multiSection\n getSectionSuggestions={({ items, section }) => {\n return items\n ? items.map((i) => {\n return { ...i, section };\n })\n : [];\n }}\n getSuggestionValue={(suggestion) => {\n return searchService.value(suggestion);\n }}\n onSuggestionsFetchRequested={({ value: newValue }) => {\n return searchService.search(newValue);\n }}\n onSuggestionsClearRequested={() => {\n return setSuggestions([]);\n }}\n onSuggestionHighlighted={({ suggestion }) => {\n return onHighlight(suggestion);\n }}\n onSuggestionSelected={(e, { suggestion }) => {\n return onSelect(suggestion);\n }}\n renderSuggestion={(suggestion) => {\n return searchService.render(suggestion);\n }}\n renderSectionTitle={getRenderSectionTitle(searchService)}\n shouldRenderSuggestions={(newValue) => {\n return shouldRenderSuggestions(newValue);\n }}\n suggestions={suggestions}\n />\n {value && (\n <button\n type=\"button\"\n tabIndex={0}\n className=\"rt-search-button rt-search-button-clear\"\n onClick={() => {\n return setValue('');\n }}\n >\n <FaTimes />\n </button>\n )}\n <button\n type=\"button\"\n tabIndex={0}\n className=\"rt-search-button rt-search-button-submit\"\n >\n <FaSearch focusable={false} />\n </button>\n </div>\n )\n );\n}\n\nSearch.propTypes = propTypes;\nSearch.defaultProps = defaultProps;\n\nexport default Search;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,eAAe;AACtB,OAAO,SAAS,SAAS,gBAAgB;AACzC,OAAO,iBAAiB;AACxB,SAAS,UAAU,eAAe;AAElC,OAAO,mBAAmB;AAC1B,OAAO,gBAAgB;AAEvB,MAAM,YAAY;AAAA,EAIhB,SAAS,UAAU;AAAA,EAKnB,uBAAuB,UAAU;AAAA,EAKjC,cAAc,UAAU;AAAA,EAKxB,YAAY,UAAU;AAAA,EAKtB,aAAa,UAAU;AAAA,EAMvB,yBAAyB,UAAU;AAAA,EAKnC,UAAU,UAAU;AAAA,EAKpB,W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[1];
|
|
10
|
-
|
|
11
|
-
return e.setApiKey(apiKey);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
SearchService.prototype.countItems = function countItems (section) {
|
|
16
|
-
return this.engines[section].items && this.engines[section].items.length;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
SearchService.prototype.render = function render (item) {
|
|
20
|
-
return this.engines[item.section].render(item);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
SearchService.prototype.value = function value (item) {
|
|
24
|
-
return this.engines[item.section].constructor.value(item);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
SearchService.prototype.search = function search (value) {
|
|
28
|
-
var this$1 = this;
|
|
29
|
-
|
|
30
|
-
Object.entries(this.engines).forEach(function (ref, position) {
|
|
31
|
-
var section = ref[0];
|
|
32
|
-
var engine = ref[1];
|
|
33
|
-
|
|
34
|
-
engine.search(value).then(function (items) {
|
|
35
|
-
engine.setItems(items);
|
|
36
|
-
this$1.upsert(section, engine.getItems(items), position);
|
|
1
|
+
class SearchService {
|
|
2
|
+
constructor({ apiKey, engines, setSuggestions }) {
|
|
3
|
+
this.engines = engines;
|
|
4
|
+
this.setSuggestions = setSuggestions;
|
|
5
|
+
Object.entries(this.engines).forEach(([, e]) => {
|
|
6
|
+
return e.setApiKey(apiKey);
|
|
37
7
|
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
SearchService.prototype.upsert = function upsert (section, items, position) {
|
|
58
|
-
this.setSuggestions(function (oldSuggestions) {
|
|
59
|
-
var sectionIndex = oldSuggestions.findIndex(function (s) {
|
|
60
|
-
return s.section === section;
|
|
8
|
+
}
|
|
9
|
+
countItems(section) {
|
|
10
|
+
return this.engines[section].items && this.engines[section].items.length;
|
|
11
|
+
}
|
|
12
|
+
render(item) {
|
|
13
|
+
return this.engines[item.section].render(item);
|
|
14
|
+
}
|
|
15
|
+
value(item) {
|
|
16
|
+
return this.engines[item.section].constructor.value(item);
|
|
17
|
+
}
|
|
18
|
+
search(value) {
|
|
19
|
+
Object.entries(this.engines).forEach(([section, engine], position) => {
|
|
20
|
+
engine.search(value).then((items) => {
|
|
21
|
+
engine.setItems(items);
|
|
22
|
+
this.upsert(section, engine.getItems(items), position);
|
|
23
|
+
});
|
|
61
24
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
25
|
+
}
|
|
26
|
+
sectionCollapsed(section) {
|
|
27
|
+
return this.engines[section].collapsed;
|
|
28
|
+
}
|
|
29
|
+
toggleSection(toggledSection) {
|
|
30
|
+
Object.entries(this.engines).forEach(([section, engine], position) => {
|
|
31
|
+
engine.collapse(!(section === toggledSection && engine.collapsed));
|
|
32
|
+
this.upsert(section, engine.getItems(), position);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
upsert(section, items, position) {
|
|
36
|
+
this.setSuggestions((oldSuggestions) => {
|
|
37
|
+
const sectionIndex = oldSuggestions.findIndex((s) => {
|
|
38
|
+
return s.section === section;
|
|
39
|
+
});
|
|
40
|
+
const start = sectionIndex === -1 ? position : sectionIndex;
|
|
41
|
+
const deleteCount = sectionIndex === -1 ? 0 : 1;
|
|
42
|
+
const newSuggestions = [...oldSuggestions];
|
|
43
|
+
newSuggestions.splice(start, deleteCount, { section, items });
|
|
44
|
+
return newSuggestions;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
70
48
|
export default SearchService;
|
|
71
|
-
|
|
72
|
-
//# sourceMappingURL=SearchService.js.map
|