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.
Files changed (186) hide show
  1. package/LayerService.js +128 -184
  2. package/LayerService.js.map +7 -1
  3. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js +163 -221
  4. package/components/BaseLayerSwitcher/BaseLayerSwitcher.js.map +7 -1
  5. package/components/BaseLayerSwitcher/index.js +1 -3
  6. package/components/BaseLayerSwitcher/index.js.map +7 -1
  7. package/components/BasicMap/BasicMap.js +147 -285
  8. package/components/BasicMap/BasicMap.js.map +7 -1
  9. package/components/BasicMap/index.js +1 -3
  10. package/components/BasicMap/index.js.map +7 -1
  11. package/components/CanvasSaveButton/CanvasSaveButton.js +165 -419
  12. package/components/CanvasSaveButton/CanvasSaveButton.js.map +7 -1
  13. package/components/CanvasSaveButton/index.js +1 -3
  14. package/components/CanvasSaveButton/index.js.map +7 -1
  15. package/components/Copyright/Copyright.js +29 -70
  16. package/components/Copyright/Copyright.js.map +7 -1
  17. package/components/Copyright/index.js +1 -3
  18. package/components/Copyright/index.js.map +7 -1
  19. package/components/FeatureExportButton/FeatureExportButton.js +40 -106
  20. package/components/FeatureExportButton/FeatureExportButton.js.map +7 -1
  21. package/components/FeatureExportButton/index.js +1 -3
  22. package/components/FeatureExportButton/index.js.map +7 -1
  23. package/components/FilterButton/FilterButton.js +41 -106
  24. package/components/FilterButton/FilterButton.js.map +7 -1
  25. package/components/FilterButton/index.js +1 -3
  26. package/components/FilterButton/index.js.map +7 -1
  27. package/components/FitExtent/FitExtent.js +17 -50
  28. package/components/FitExtent/FitExtent.js.map +7 -1
  29. package/components/FitExtent/index.js +1 -3
  30. package/components/FitExtent/index.js.map +7 -1
  31. package/components/FollowButton/FollowButton.js +41 -111
  32. package/components/FollowButton/FollowButton.js.map +7 -1
  33. package/components/FollowButton/index.js +1 -3
  34. package/components/FollowButton/index.js.map +7 -1
  35. package/components/Geolocation/Geolocation.js +104 -213
  36. package/components/Geolocation/Geolocation.js.map +7 -1
  37. package/components/Geolocation/index.js +1 -3
  38. package/components/Geolocation/index.js.map +7 -1
  39. package/components/LayerTree/LayerTree.js +204 -410
  40. package/components/LayerTree/LayerTree.js.map +7 -1
  41. package/components/LayerTree/index.js +1 -3
  42. package/components/LayerTree/index.js.map +7 -1
  43. package/components/MousePosition/MousePosition.js +61 -130
  44. package/components/MousePosition/MousePosition.js.map +7 -1
  45. package/components/MousePosition/index.js +1 -3
  46. package/components/MousePosition/index.js.map +7 -1
  47. package/components/NorthArrow/NorthArrow.js +22 -62
  48. package/components/NorthArrow/NorthArrow.js.map +7 -1
  49. package/components/NorthArrow/index.js +1 -3
  50. package/components/NorthArrow/index.js.map +7 -1
  51. package/components/Overlay/Overlay.js +83 -130
  52. package/components/Overlay/Overlay.js.map +7 -1
  53. package/components/Overlay/index.js +1 -3
  54. package/components/Overlay/index.js.map +7 -1
  55. package/components/Permalink/Permalink.js +150 -244
  56. package/components/Permalink/Permalink.js.map +7 -1
  57. package/components/Permalink/index.js +1 -3
  58. package/components/Permalink/index.js.map +7 -1
  59. package/components/Popup/Popup.js +106 -233
  60. package/components/Popup/Popup.js.map +7 -1
  61. package/components/Popup/index.js +1 -3
  62. package/components/Popup/index.js.map +7 -1
  63. package/components/ResizeHandler/ResizeHandler.js +58 -113
  64. package/components/ResizeHandler/ResizeHandler.js.map +7 -1
  65. package/components/ResizeHandler/index.js +1 -3
  66. package/components/ResizeHandler/index.js.map +7 -1
  67. package/components/RouteSchedule/RouteSchedule.js +150 -283
  68. package/components/RouteSchedule/RouteSchedule.js.map +7 -1
  69. package/components/RouteSchedule/index.js +1 -3
  70. package/components/RouteSchedule/index.js.map +7 -1
  71. package/components/ScaleLine/ScaleLine.js +21 -45
  72. package/components/ScaleLine/ScaleLine.js.map +7 -1
  73. package/components/ScaleLine/index.js +1 -3
  74. package/components/ScaleLine/index.js.map +7 -1
  75. package/components/Search/Search.js +122 -186
  76. package/components/Search/Search.js.map +7 -1
  77. package/components/Search/SearchService.js +45 -69
  78. package/components/Search/SearchService.js.map +7 -1
  79. package/components/Search/engines/Engine.js +18 -25
  80. package/components/Search/engines/Engine.js.map +7 -1
  81. package/components/Search/engines/StopFinder.js +21 -38
  82. package/components/Search/engines/StopFinder.js.map +7 -1
  83. package/components/Search/index.js +3 -6
  84. package/components/Search/index.js.map +7 -1
  85. package/components/StopsFinder/StopsFinder.js +123 -174
  86. package/components/StopsFinder/StopsFinder.js.map +7 -1
  87. package/components/StopsFinder/StopsFinderOption.js +37 -54
  88. package/components/StopsFinder/StopsFinderOption.js.map +7 -1
  89. package/components/StopsFinder/index.js +1 -3
  90. package/components/StopsFinder/index.js.map +7 -1
  91. package/components/TrackerControl/TrackerControl.js +73 -128
  92. package/components/TrackerControl/TrackerControl.js.map +7 -1
  93. package/components/TrackerControl/index.js +1 -3
  94. package/components/TrackerControl/index.js.map +7 -1
  95. package/components/Zoom/Zoom.js +69 -112
  96. package/components/Zoom/Zoom.js.map +7 -1
  97. package/components/Zoom/index.js +1 -3
  98. package/components/Zoom/index.js.map +7 -1
  99. package/package.json +10 -5
  100. package/propTypes.js +17 -23
  101. package/propTypes.js.map +7 -1
  102. package/setupTests.js +2 -4
  103. package/setupTests.js.map +7 -1
  104. package/themes/README.md +26 -0
  105. package/themes/default/components.scss +0 -1
  106. package/themes/default/examples.scss +0 -1
  107. package/utils/GlobalsForOle.js +63 -64
  108. package/utils/GlobalsForOle.js.map +7 -1
  109. package/utils/KML.js +178 -364
  110. package/utils/KML.js.map +7 -1
  111. package/utils/KMLFormat.js +37 -73
  112. package/utils/KMLFormat.js.map +7 -1
  113. package/utils/Styles.js +24 -32
  114. package/utils/Styles.js.map +7 -1
  115. package/utils/getPolygonPattern.js +11 -44
  116. package/utils/getPolygonPattern.js.map +7 -1
  117. package/utils/timeUtils.js +16 -35
  118. package/utils/timeUtils.js.map +7 -1
  119. package/LayerService.test.js +0 -160
  120. package/LayerService.test.js.map +0 -1
  121. package/Projections.js +0 -16
  122. package/Projections.js.map +0 -1
  123. package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js +0 -88
  124. package/components/BaseLayerSwitcher/BaseLayerSwitcher.test.js.map +0 -1
  125. package/components/BaseLayerToggler/BaseLayerToggler.js +0 -490
  126. package/components/BaseLayerToggler/BaseLayerToggler.js.map +0 -1
  127. package/components/BaseLayerToggler/BaseLayerToggler.md.scss +0 -9
  128. package/components/BaseLayerToggler/BaseLayerToggler.scss +0 -49
  129. package/components/BaseLayerToggler/BaseLayerToggler.test.js +0 -127
  130. package/components/BaseLayerToggler/BaseLayerToggler.test.js.map +0 -1
  131. package/components/BaseLayerToggler/index.js +0 -3
  132. package/components/BaseLayerToggler/index.js.map +0 -1
  133. package/components/BasicMap/BasicMap.test.js +0 -288
  134. package/components/BasicMap/BasicMap.test.js.map +0 -1
  135. package/components/CanvasSaveButton/CanvasSaveButton.test.js +0 -173
  136. package/components/CanvasSaveButton/CanvasSaveButton.test.js.map +0 -1
  137. package/components/Copyright/Copyright.test.js +0 -133
  138. package/components/Copyright/Copyright.test.js.map +0 -1
  139. package/components/FeatureExportButton/FeatureExportButton.test.js +0 -407
  140. package/components/FeatureExportButton/FeatureExportButton.test.js.map +0 -1
  141. package/components/FilterButton/FilterButton.test.js +0 -48
  142. package/components/FilterButton/FilterButton.test.js.map +0 -1
  143. package/components/FitExtent/FitExtent.test.js +0 -44
  144. package/components/FitExtent/FitExtent.test.js.map +0 -1
  145. package/components/FollowButton/FollowButton.test.js +0 -57
  146. package/components/FollowButton/FollowButton.test.js.map +0 -1
  147. package/components/Geolocation/Geolocation.test.js +0 -263
  148. package/components/Geolocation/Geolocation.test.js.map +0 -1
  149. package/components/LayerTree/LayerTree.test.js +0 -323
  150. package/components/LayerTree/LayerTree.test.js.map +0 -1
  151. package/components/MousePosition/MousePosition.test.js +0 -125
  152. package/components/MousePosition/MousePosition.test.js.map +0 -1
  153. package/components/NorthArrow/NorthArrow.test.js +0 -106
  154. package/components/NorthArrow/NorthArrow.test.js.map +0 -1
  155. package/components/Overlay/Overlay.test.js +0 -145
  156. package/components/Overlay/Overlay.test.js.map +0 -1
  157. package/components/Permalink/Permalink.test.js +0 -267
  158. package/components/Permalink/Permalink.test.js.map +0 -1
  159. package/components/Popup/Popup.test.js +0 -291
  160. package/components/Popup/Popup.test.js.map +0 -1
  161. package/components/ResizeHandler/ResizeHandler.test.js +0 -410
  162. package/components/ResizeHandler/ResizeHandler.test.js.map +0 -1
  163. package/components/RouteSchedule/RouteSchedule.test.js +0 -102
  164. package/components/RouteSchedule/RouteSchedule.test.js.map +0 -1
  165. package/components/ScaleLine/ScaleLine.test.js +0 -32
  166. package/components/ScaleLine/ScaleLine.test.js.map +0 -1
  167. package/components/Search/Search.test.js +0 -15
  168. package/components/Search/Search.test.js.map +0 -1
  169. package/components/StopsFinder/StopsFinder.test.js +0 -19
  170. package/components/StopsFinder/StopsFinder.test.js.map +0 -1
  171. package/components/TrackerControl/TrackerControl.test.js +0 -17
  172. package/components/TrackerControl/TrackerControl.test.js.map +0 -1
  173. package/components/Zoom/Zoom.test.js +0 -150
  174. package/components/Zoom/Zoom.test.js.map +0 -1
  175. package/styleguidist/ComponentsList.js +0 -52
  176. package/styleguidist/ComponentsList.js.map +0 -1
  177. package/styleguidist/StyleGuide.js +0 -253
  178. package/styleguidist/StyleGuide.js.map +0 -1
  179. package/utils/KML.test.js +0 -163
  180. package/utils/KML.test.js.map +0 -1
  181. package/utils/KMLFormat.test.js +0 -22
  182. package/utils/KMLFormat.test.js.map +0 -1
  183. package/utils/getPolygonPattern.test.js +0 -66
  184. package/utils/getPolygonPattern.test.js.map +0 -1
  185. package/utils/timeUtils.test.js +0 -32
  186. package/utils/timeUtils.test.js.map +0 -1
@@ -1,56 +1,32 @@
1
- function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; }
2
- import React, { useRef, useEffect } from 'react';
3
- import PropTypes from 'prop-types';
4
- import OLScaleLine from 'ol/control/ScaleLine';
5
- import OLMap from 'ol/Map';
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
- var defaultProps = {
21
- options: {},
9
+ const defaultProps = {
10
+ options: {}
22
11
  };
23
-
24
- /**
25
- * The ScaleLine component creates an
26
- * [ol/control/ScaleLine](https://openlayers.org/en/latest/apidoc/module-ol_control_ScaleLine-ScaleLine.html)
27
- * for an [ol/map](https://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html).
28
- */
29
- function ScaleLine(ref$1) {
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 function () {
20
+ return () => {
43
21
  map.removeControl(control);
44
22
  };
45
23
  }, [map, options]);
46
-
47
- // eslint-disable-next-line react/jsx-props-no-spreading
48
- return React.createElement( 'div', Object.assign({}, { className: "rs-scale-line", ref: ref }, other));
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
- {"version":3,"file":"ScaleLine.js","sources":["../../../src/components/ScaleLine/ScaleLine.js"],"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"],"names":["const"],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,EAAE,SAAS,QAAQ,OAAO,CAAC;AACjD,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,KAAK,MAAM,QAAQ,CAAC;AAC3B;AACAA,GAAK,CAAC,SAAS,GAAG;AAClB;AACA;AACA;AACA,EAAE,GAAG,EAAE,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,UAAU;AAC7C;AACA;AACA;AACA;AACA;AACA,EAAE,OAAO,EAAE,SAAS,CAAC,MAAM;AAC3B,CAAC,CAAC;AACF;AACAA,GAAK,CAAC,YAAY,GAAG;AACrB,EAAE,OAAO,EAAE,EAAE;AACb,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,SAAS,MAA2B,EAAE,CAA1B;sBAAK;8BAAS;kEAAG;;AAAU;AAChD,EAAEA,GAAK,CAAC,GAAG,GAAG,MAAM,EAAE,CAAC;AACvB;AACA,EAAE,SAAS,UAAC,GAAM;AAClB,IAAIA,GAAK,CAAC,OAAO,GAAG,IAAI,WAAW,CAAC,kBAC3B,OAAO;AAChB,OAAW,MAAM,EAAE,GAAG,CAAC,QAAO,CACzB,CAAC,CAAC;AACP;AACA,IAAI,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;AAC5B,IAAI,gBAAO,GAAM;AACjB,MAAM,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACjC,KAAK,CAAC;AACN,GAAG,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AACrB;AACA;AACA,EAAE,OAAO,sBAAC,uBAAG,GAAC,WAAU,eAAe,EAAC,KAAK,KAAI,EAAK,MAAM,CAAG,CAAC;AAChE,CAAC;AACD;AACA,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC;AAChC,SAAS,CAAC,YAAY,GAAG,YAAY,CAAC;AACtC;AACA,eAAe,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;"}
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,3 +1 @@
1
- export { default } from './ScaleLine';
2
-
3
- //# sourceMappingURL=index.js.map
1
+ export { default } from "./ScaleLine";
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/ScaleLine/index.js"],"sourcesContent":["export { default } from './ScaleLine';\n"],"names":[],"mappings":"AAAA,SAAS,OAAO,QAAQ,aAAa,CAAC;"}
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 'prop-types';
2
- import React, { useMemo, useState } from 'react';
3
- import Autosuggest from 'react-autosuggest';
4
- import { FaSearch, FaTimes } from 'react-icons/fa';
5
-
6
- import SearchService from './SearchService';
7
- import StopFinder from './engines/StopFinder';
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: function () {
61
- return function () {
21
+ getRenderSectionTitle: () => {
22
+ return () => {
62
23
  return null;
63
24
  };
64
25
  },
65
- initialValue: '',
66
- onHighlight: function () {
26
+ initialValue: "",
27
+ onHighlight: () => {
67
28
  return null;
68
29
  },
69
- shouldRenderSuggestions: function (newValue) {
30
+ shouldRenderSuggestions: (newValue) => {
70
31
  return newValue.trim().length > 2;
71
32
  },
72
- onSelect: function () {
33
+ onSelect: () => {
73
34
  return null;
74
35
  },
75
- className: 'rt-search',
76
- inputProps: {},
36
+ className: "rt-search",
37
+ inputProps: {}
77
38
  };
78
-
79
- /**
80
- * The Search component renders a text input field which searches for stops
81
- * using the input string and centers the map on the selected stop.
82
- */
83
- function Search(ref) {
84
- var apiKey = ref.apiKey;
85
- var engines = ref.engines;
86
- var getRenderSectionTitle = ref.getRenderSectionTitle;
87
- var initialValue = ref.initialValue;
88
- var inputProps = ref.inputProps;
89
- var onHighlight = ref.onHighlight;
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(undefined, { apiKey: apiKey }),
53
+ stops: new StopFinder(void 0, { apiKey })
98
54
  };
99
55
  }
100
56
  if (apiKey) {
101
- Object.values(engines).forEach(function (engine) {
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
- var ref$1 = useState([]);
111
- var suggestions = ref$1[0];
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: apiKey,
69
+ apiKey,
120
70
  engines: currentEngines,
121
- setSuggestions: setSuggestions,
71
+ setSuggestions
122
72
  });
123
73
  }, [apiKey, currentEngines]);
124
-
125
- var theme = useMemo(function () {
74
+ const theme = useMemo(() => {
126
75
  return {
127
- container: (className + "__container"),
128
- containerOpen: (className + "__container--open"),
129
- input: (className + "__input"),
130
- inputOpen: (className + "__input--open"),
131
- inputFocused: (className + "__input--focused"),
132
- suggestionsContainer: (className + "__suggestions-container"),
133
- suggestionsContainerOpen: (className + "__suggestions-container--open"),
134
- suggestionsList: (className + "__suggestions-list"),
135
- suggestion: (className + "__suggestion"),
136
- suggestionFirst: (className + "__suggestion--first"),
137
- suggestionHighlighted: (className + "__suggestion--highlighted"),
138
- sectionContainer: (className + "__section-container"),
139
- sectionContainerFirst: (className + "__section-container--first"),
140
- sectionTitle: (className + "__section-title"),
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
- return (
145
- Object.keys(currentEngines).length > 0 && (
146
- React.createElement( 'div', { className: "rt-search" },
147
- React.createElement( Autosuggest, {
148
- theme: theme, inputProps: Object.assign({}, {autoFocus: true,
149
- tabIndex: 0,
150
- onChange: function (e, ref) {
151
- var newValue = ref.newValue;
152
-
153
- return setValue(newValue);
154
- },
155
- onKeyUp: function (ref) {
156
- var key = ref.key;
157
-
158
- if (key === 'Enter') {
159
- var filtered = suggestions.filter(function (s) {
160
- return s.items.length > 0;
161
- });
162
- if (filtered.length > 0) {
163
- var ref$1 = filtered[0];
164
- var items = ref$1.items;
165
- var section = ref$1.section;
166
- var targetSuggestion = Object.assign({}, items[0], {section: section});
167
- setValue(searchService.value(targetSuggestion));
168
- onSelect(targetSuggestion);
169
- }
170
- } else if (
171
- (key === 'ArrowDown' || key === 'ArrowUp') &&
172
- typeof searchService.highlightSection === 'function'
173
- ) {
174
- searchService.highlightSection(); // for improved accessibility
175
- }
176
- },
177
- value: value},
178
- inputProps), multiSection: true, getSectionSuggestions: function (ref) {
179
- var items = ref.items;
180
- var section = ref.section;
181
-
182
- return items
183
- ? items.map(function (i) {
184
- return Object.assign({}, i, {section: section});
185
- })
186
- : [];
187
- }, getSuggestionValue: function (suggestion) {
188
- return searchService.value(suggestion);
189
- }, onSuggestionsFetchRequested: function (ref) {
190
- var newValue = ref.value;
191
-
192
- return searchService.search(newValue);
193
- }, onSuggestionsClearRequested: function () {
194
- return setSuggestions([]);
195
- }, onSuggestionHighlighted: function (ref) {
196
- var suggestion = ref.suggestion;
197
-
198
- return onHighlight(suggestion);
199
- }, onSuggestionSelected: function (e, ref) {
200
- var suggestion = ref.suggestion;
201
-
202
- return onSelect(suggestion);
203
- }, renderSuggestion: function (suggestion) {
204
- return searchService.render(suggestion);
205
- }, renderSectionTitle: getRenderSectionTitle(searchService), shouldRenderSuggestions: function (newValue) {
206
- return shouldRenderSuggestions(newValue);
207
- }, suggestions: suggestions }),
208
- value && (
209
- React.createElement( 'button', {
210
- type: "button", tabIndex: 0, className: "rt-search-button rt-search-button-clear", onClick: function () {
211
- return setValue('');
212
- } },
213
- React.createElement( FaTimes, null )
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;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AC,UAAM;AACf,UAAU,MAAK,QAAQ,EACb,UAAU,CAAE,EACZ,WAAU,6CACX;AACT,UAAU,qBAAC,WAAQ,CAAC,WAAW,OAAM,CAAG;AACxC,QAAQ,CAAS;AACjB,MAAM,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,EA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,cAAY;AAAA,IACZ,uBAAuB,CAAC,EAAE,OAAO,QAAQ,MAAM;AAC7C,aAAO,QACH,MAAM,IAAI,CAAC,MAAM;AACf,eAAO,EAAE,GAAG,GAAG,QAAQ;AAAA,MACzB,CAAC,IACD,CAAC;AAAA,IACP;AAAA,IACA,oBAAoB,CAAC,eAAe;AAClC,aAAO,cAAc,MAAM,UAAU;AAAA,IACvC;AAAA,IACA,6BAA6B,CAAC,EAAE,OAAO,SAAS,MAAM;AACpD,aAAO,cAAc,OAAO,QAAQ;AAAA,IACtC;AAAA,IACA,6BAA6B,MAAM;AACjC,aAAO,eAAe,CAAC,CAAC;AAAA,IAC1B;AAAA,IACA,yBAAyB,CAAC,EAAE,WAAW,MAAM;AAC3C,aAAO,YAAY,UAAU;AAAA,IAC/B;AAAA,IACA,sBAAsB,CAAC,GAAG,EAAE,WAAW,MAAM;AAC3C,aAAO,SAAS,UAAU;AAAA,IAC5B;AAAA,IACA,kBAAkB,CAAC,eAAe;AAChC,aAAO,cAAc,OAAO,UAAU;AAAA,IACxC;AAAA,IACA,oBAAoB,sBAAsB,aAAa;AAAA,IACvD,yBAAyB,CAAC,aAAa;AACrC,aAAO,wBAAwB,QAAQ;AAAA,IACzC;AAAA,IACA;AAAA,GACF,GACC,SACC,oCAAC;AAAA,IACC,MAAK;AAAA,IACL,UAAU;AAAA,IACV,WAAU;AAAA,IACV,SAAS,MAAM;AACb,aAAO,SAAS,EAAE;AAAA,IACpB;AAAA,KAEA,oCAAC,aAAQ,CACX,GAEF,oCAAC;AAAA,IACC,MAAK;AAAA,IACL,UAAU;AAAA,IACV,WAAU;AAAA,KAEV,oCAAC;AAAA,IAAS,WAAW;AAAA,GAAO,CAC9B,CACF;AAGN;AAEA,OAAO,YAAY;AACnB,OAAO,eAAe;AAEtB,eAAe;",
6
+ "names": []
7
+ }
@@ -1,72 +1,48 @@
1
- var SearchService = function SearchService(ref) {
2
- var apiKey = ref.apiKey;
3
- var engines = ref.engines;
4
- var setSuggestions = ref.setSuggestions;
5
-
6
- this.engines = engines;
7
- this.setSuggestions = setSuggestions;
8
- Object.entries(this.engines).forEach(function (ref) {
9
- var e = ref[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
- SearchService.prototype.sectionCollapsed = function sectionCollapsed (section) {
42
- return this.engines[section].collapsed;
43
- };
44
-
45
- SearchService.prototype.toggleSection = function toggleSection (toggledSection) {
46
- var this$1 = this;
47
-
48
- Object.entries(this.engines).forEach(function (ref, position) {
49
- var section = ref[0];
50
- var engine = ref[1];
51
-
52
- engine.collapse(!(section === toggledSection && engine.collapsed));
53
- this$1.upsert(section, engine.getItems(), position);
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
- var start = sectionIndex === -1 ? position : sectionIndex;
63
- var deleteCount = sectionIndex === -1 ? 0 : 1;
64
- var newSuggestions = [].concat( oldSuggestions );
65
- newSuggestions.splice(start, deleteCount, { section: section, items: items });
66
- return newSuggestions;
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