@mapcairn/map 0.0.0-stage → 0.1.0-rc.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.
Files changed (315) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +167 -2
  3. package/dist/chrome/Attribution/Attribution.js +304 -0
  4. package/dist/chrome/Attribution/Attribution.js.map +1 -0
  5. package/dist/chrome/Attribution/Attribution.styles.js +10 -0
  6. package/dist/chrome/Attribution/Attribution.styles.js.map +1 -0
  7. package/dist/chrome/Attribution/AttributionSkeleton.js +29 -0
  8. package/dist/chrome/Attribution/AttributionSkeleton.js.map +1 -0
  9. package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js +83 -0
  10. package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js.map +1 -0
  11. package/dist/chrome/EndStack/EndStack.js +157 -0
  12. package/dist/chrome/EndStack/EndStack.js.map +1 -0
  13. package/dist/chrome/EndStack/EndStack.styles.js +12 -0
  14. package/dist/chrome/EndStack/EndStack.styles.js.map +1 -0
  15. package/dist/chrome/EndStack/EndStackSkeleton.js +78 -0
  16. package/dist/chrome/EndStack/EndStackSkeleton.js.map +1 -0
  17. package/dist/chrome/EndStack/endStackHeight.js +22 -0
  18. package/dist/chrome/EndStack/endStackHeight.js.map +1 -0
  19. package/dist/chrome/MapChrome/MapChrome.js +488 -0
  20. package/dist/chrome/MapChrome/MapChrome.js.map +1 -0
  21. package/dist/chrome/MapChrome/MapChrome.styles.js +15 -0
  22. package/dist/chrome/MapChrome/MapChrome.styles.js.map +1 -0
  23. package/dist/chrome/MapChrome/chromeSurface.js +18 -0
  24. package/dist/chrome/MapChrome/chromeSurface.js.map +1 -0
  25. package/dist/chrome/MapChrome/chromeVars.js +71 -0
  26. package/dist/chrome/MapChrome/chromeVars.js.map +1 -0
  27. package/dist/chrome/MapChrome/mapKeyPlacement.js +41 -0
  28. package/dist/chrome/MapChrome/mapKeyPlacement.js.map +1 -0
  29. package/dist/chrome/MapChrome/sharesWidth.js +13 -0
  30. package/dist/chrome/MapChrome/sharesWidth.js.map +1 -0
  31. package/dist/chrome/MapReadout/MapReadout.js +199 -0
  32. package/dist/chrome/MapReadout/MapReadout.js.map +1 -0
  33. package/dist/chrome/MapReadout/MapReadout.styles.js +14 -0
  34. package/dist/chrome/MapReadout/MapReadout.styles.js.map +1 -0
  35. package/dist/chrome/Sheet/Sheet.js +412 -0
  36. package/dist/chrome/Sheet/Sheet.js.map +1 -0
  37. package/dist/chrome/Sheet/Sheet.styles.js +14 -0
  38. package/dist/chrome/Sheet/Sheet.styles.js.map +1 -0
  39. package/dist/chrome/focusRegistry.js +76 -0
  40. package/dist/chrome/focusRegistry.js.map +1 -0
  41. package/dist/chrome/layoutContext.js +30 -0
  42. package/dist/chrome/layoutContext.js.map +1 -0
  43. package/dist/chrome/useScrollEdges.js +53 -0
  44. package/dist/chrome/useScrollEdges.js.map +1 -0
  45. package/dist/host/MapContext.js +16 -0
  46. package/dist/host/MapContext.js.map +1 -0
  47. package/dist/host/MapView.js +189 -0
  48. package/dist/host/MapView.js.map +1 -0
  49. package/dist/host/MapView.styles.js +16 -0
  50. package/dist/host/MapView.styles.js.map +1 -0
  51. package/dist/host/overlays/AccuracyCircle.js +36 -0
  52. package/dist/host/overlays/AccuracyCircle.js.map +1 -0
  53. package/dist/host/overlays/CentreCrosshair.js +40 -0
  54. package/dist/host/overlays/CentreCrosshair.js.map +1 -0
  55. package/dist/host/overlays/DrawOverlay.js +221 -0
  56. package/dist/host/overlays/DrawOverlay.js.map +1 -0
  57. package/dist/host/overlays/MapOverlayLayer.js +27 -0
  58. package/dist/host/overlays/MapOverlayLayer.js.map +1 -0
  59. package/dist/host/overlays/MeasureOverlay.js +87 -0
  60. package/dist/host/overlays/MeasureOverlay.js.map +1 -0
  61. package/dist/host/overlays/PinMarker.js +40 -0
  62. package/dist/host/overlays/PinMarker.js.map +1 -0
  63. package/dist/host/overlays/geometry.js +41 -0
  64. package/dist/host/overlays/geometry.js.map +1 -0
  65. package/dist/host/overlays/overlays.styles.js +27 -0
  66. package/dist/host/overlays/overlays.styles.js.map +1 -0
  67. package/dist/host/pointerTargets.js +22 -0
  68. package/dist/host/pointerTargets.js.map +1 -0
  69. package/dist/host/useLongPress.js +102 -0
  70. package/dist/host/useLongPress.js.map +1 -0
  71. package/dist/host/useMapEngine.js +352 -0
  72. package/dist/host/useMapEngine.js.map +1 -0
  73. package/dist/host/usePointerPosition.js +60 -0
  74. package/dist/host/usePointerPosition.js.map +1 -0
  75. package/dist/index.d.ts +3845 -0
  76. package/dist/index.js +89 -0
  77. package/dist/layers/CatalogueStatus.js +138 -0
  78. package/dist/layers/CatalogueStatus.js.map +1 -0
  79. package/dist/layers/DateTimeControl.js +101 -0
  80. package/dist/layers/DateTimeControl.js.map +1 -0
  81. package/dist/layers/FeatureCard.js +147 -0
  82. package/dist/layers/FeatureCard.js.map +1 -0
  83. package/dist/layers/FeatureChoices.js +101 -0
  84. package/dist/layers/FeatureChoices.js.map +1 -0
  85. package/dist/layers/FeatureGlyph.js +56 -0
  86. package/dist/layers/FeatureGlyph.js.map +1 -0
  87. package/dist/layers/IdentifyStatus.js +36 -0
  88. package/dist/layers/IdentifyStatus.js.map +1 -0
  89. package/dist/layers/LayerItem.js +321 -0
  90. package/dist/layers/LayerItem.js.map +1 -0
  91. package/dist/layers/LayerKey.js +36 -0
  92. package/dist/layers/LayerKey.js.map +1 -0
  93. package/dist/layers/Layers.styles.js +50 -0
  94. package/dist/layers/Layers.styles.js.map +1 -0
  95. package/dist/layers/LayersSection.js +267 -0
  96. package/dist/layers/LayersSection.js.map +1 -0
  97. package/dist/layers/MapDataLayers.js +261 -0
  98. package/dist/layers/MapDataLayers.js.map +1 -0
  99. package/dist/layers/MapKey.js +131 -0
  100. package/dist/layers/MapKey.js.map +1 -0
  101. package/dist/layers/MapKey.styles.js +16 -0
  102. package/dist/layers/MapKey.styles.js.map +1 -0
  103. package/dist/layers/MarkerGlyph.js +84 -0
  104. package/dist/layers/MarkerGlyph.js.map +1 -0
  105. package/dist/layers/SelectionProvider.js +27 -0
  106. package/dist/layers/SelectionProvider.js.map +1 -0
  107. package/dist/layers/ShapeGlyph.js +122 -0
  108. package/dist/layers/ShapeGlyph.js.map +1 -0
  109. package/dist/layers/TurnOffActions.js +147 -0
  110. package/dist/layers/TurnOffActions.js.map +1 -0
  111. package/dist/layers/answersTap.js +16 -0
  112. package/dist/layers/answersTap.js.map +1 -0
  113. package/dist/layers/catalogueNotice.js +65 -0
  114. package/dist/layers/catalogueNotice.js.map +1 -0
  115. package/dist/layers/catalogueReconcile.js +55 -0
  116. package/dist/layers/catalogueReconcile.js.map +1 -0
  117. package/dist/layers/catalogueView.js +32 -0
  118. package/dist/layers/catalogueView.js.map +1 -0
  119. package/dist/layers/featureTitle.js +14 -0
  120. package/dist/layers/featureTitle.js.map +1 -0
  121. package/dist/layers/identifyFeedback.js +30 -0
  122. package/dist/layers/identifyFeedback.js.map +1 -0
  123. package/dist/layers/identifyRun.js +148 -0
  124. package/dist/layers/identifyRun.js.map +1 -0
  125. package/dist/layers/layerStatus.js +13 -0
  126. package/dist/layers/layerStatus.js.map +1 -0
  127. package/dist/layers/loadOutcome.js +107 -0
  128. package/dist/layers/loadOutcome.js.map +1 -0
  129. package/dist/layers/loadReport.js +33 -0
  130. package/dist/layers/loadReport.js.map +1 -0
  131. package/dist/layers/loadRequests.js +73 -0
  132. package/dist/layers/loadRequests.js.map +1 -0
  133. package/dist/layers/mapFeatures.js +307 -0
  134. package/dist/layers/mapFeatures.js.map +1 -0
  135. package/dist/layers/mapKeyBlocks.js +24 -0
  136. package/dist/layers/mapKeyBlocks.js.map +1 -0
  137. package/dist/layers/reveal.js +119 -0
  138. package/dist/layers/reveal.js.map +1 -0
  139. package/dist/layers/selectionMessages.js +53 -0
  140. package/dist/layers/selectionMessages.js.map +1 -0
  141. package/dist/layers/selectionResolve.js +111 -0
  142. package/dist/layers/selectionResolve.js.map +1 -0
  143. package/dist/layers/useDataLayers.js +940 -0
  144. package/dist/layers/useDataLayers.js.map +1 -0
  145. package/dist/layers/useFeatureSelection.js +179 -0
  146. package/dist/layers/useFeatureSelection.js.map +1 -0
  147. package/dist/layers/useScrolls.js +37 -0
  148. package/dist/layers/useScrolls.js.map +1 -0
  149. package/dist/panels/BasemapPicker/BasemapPicker.js +169 -0
  150. package/dist/panels/BasemapPicker/BasemapPicker.js.map +1 -0
  151. package/dist/panels/BasemapPicker/BasemapPicker.styles.js +42 -0
  152. package/dist/panels/BasemapPicker/BasemapPicker.styles.js.map +1 -0
  153. package/dist/panels/ExportSection/ExportSection.js +91 -0
  154. package/dist/panels/ExportSection/ExportSection.js.map +1 -0
  155. package/dist/panels/HelpSection/HelpSection.js +163 -0
  156. package/dist/panels/HelpSection/HelpSection.js.map +1 -0
  157. package/dist/panels/HelpSection/HelpSection.styles.js +9 -0
  158. package/dist/panels/HelpSection/HelpSection.styles.js.map +1 -0
  159. package/dist/panels/PinSection/PinSection.js +39 -0
  160. package/dist/panels/PinSection/PinSection.js.map +1 -0
  161. package/dist/panels/Section/Section.js +43 -0
  162. package/dist/panels/Section/Section.js.map +1 -0
  163. package/dist/panels/Section/Section.styles.js +13 -0
  164. package/dist/panels/Section/Section.styles.js.map +1 -0
  165. package/dist/panels/SettingsSection/LanguageField.js +126 -0
  166. package/dist/panels/SettingsSection/LanguageField.js.map +1 -0
  167. package/dist/panels/SettingsSection/SettingsSection.js +175 -0
  168. package/dist/panels/SettingsSection/SettingsSection.js.map +1 -0
  169. package/dist/panels/SettingsSection/SettingsSection.styles.js +9 -0
  170. package/dist/panels/SettingsSection/SettingsSection.styles.js.map +1 -0
  171. package/dist/panels/ShapesSection/ShapesSection.js +229 -0
  172. package/dist/panels/ShapesSection/ShapesSection.js.map +1 -0
  173. package/dist/panels/ShapesSection/ShapesSection.styles.js +7 -0
  174. package/dist/panels/ShapesSection/ShapesSection.styles.js.map +1 -0
  175. package/dist/panels/SheetContent/SheetContent.js +92 -0
  176. package/dist/panels/SheetContent/SheetContent.js.map +1 -0
  177. package/dist/panels/SheetContent/SheetContent.styles.js +6 -0
  178. package/dist/panels/SheetContent/SheetContent.styles.js.map +1 -0
  179. package/dist/services/ServicesProvider.js +42 -0
  180. package/dist/services/ServicesProvider.js.map +1 -0
  181. package/dist/services/activeMessages.js +140 -0
  182. package/dist/services/activeMessages.js.map +1 -0
  183. package/dist/services/basemapAvailability.js +78 -0
  184. package/dist/services/basemapAvailability.js.map +1 -0
  185. package/dist/services/englishMessages.js +10 -0
  186. package/dist/services/englishMessages.js.map +1 -0
  187. package/dist/services/hooks.js +214 -0
  188. package/dist/services/hooks.js.map +1 -0
  189. package/dist/styles.css +2866 -0
  190. package/dist/styles.css.d.ts +1 -0
  191. package/dist/tools/Directions/Directions.styles.js +25 -0
  192. package/dist/tools/Directions/Directions.styles.js.map +1 -0
  193. package/dist/tools/Directions/DirectionsOverlay.js +46 -0
  194. package/dist/tools/Directions/DirectionsOverlay.js.map +1 -0
  195. package/dist/tools/Directions/DirectionsPanel.js +428 -0
  196. package/dist/tools/Directions/DirectionsPanel.js.map +1 -0
  197. package/dist/tools/Directions/MapDirections.js +84 -0
  198. package/dist/tools/Directions/MapDirections.js.map +1 -0
  199. package/dist/tools/Directions/useDirections.js +226 -0
  200. package/dist/tools/Directions/useDirections.js.map +1 -0
  201. package/dist/tools/Directions/useFreeCentre.js +30 -0
  202. package/dist/tools/Directions/useFreeCentre.js.map +1 -0
  203. package/dist/tools/DrawToolbar/DrawMapBindings.js +34 -0
  204. package/dist/tools/DrawToolbar/DrawMapBindings.js.map +1 -0
  205. package/dist/tools/DrawToolbar/DrawToolbar.js +296 -0
  206. package/dist/tools/DrawToolbar/DrawToolbar.js.map +1 -0
  207. package/dist/tools/DrawToolbar/DrawToolbar.styles.js +21 -0
  208. package/dist/tools/DrawToolbar/DrawToolbar.styles.js.map +1 -0
  209. package/dist/tools/DrawToolbar/imageDrawing.js +24 -0
  210. package/dist/tools/DrawToolbar/imageDrawing.js.map +1 -0
  211. package/dist/tools/DrawToolbar/useDraw.js +543 -0
  212. package/dist/tools/DrawToolbar/useDraw.js.map +1 -0
  213. package/dist/tools/MeasureToolbar/MeasureToolbar.js +116 -0
  214. package/dist/tools/MeasureToolbar/MeasureToolbar.js.map +1 -0
  215. package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js +12 -0
  216. package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js.map +1 -0
  217. package/dist/tools/MeasureToolbar/useMeasure.js +75 -0
  218. package/dist/tools/MeasureToolbar/useMeasure.js.map +1 -0
  219. package/dist/tools/PinCard/PinCard.js +174 -0
  220. package/dist/tools/PinCard/PinCard.js.map +1 -0
  221. package/dist/tools/PinCard/PinCard.styles.js +16 -0
  222. package/dist/tools/PinCard/PinCard.styles.js.map +1 -0
  223. package/dist/tools/PinCard/useReverseAddress.js +77 -0
  224. package/dist/tools/PinCard/useReverseAddress.js.map +1 -0
  225. package/dist/tools/SearchPill/SearchPill.js +292 -0
  226. package/dist/tools/SearchPill/SearchPill.js.map +1 -0
  227. package/dist/tools/SearchPill/SearchPill.styles.js +16 -0
  228. package/dist/tools/SearchPill/SearchPill.styles.js.map +1 -0
  229. package/dist/tools/SearchPill/SearchPillSkeleton.js +41 -0
  230. package/dist/tools/SearchPill/SearchPillSkeleton.js.map +1 -0
  231. package/dist/tools/SearchPill/useSearch.js +143 -0
  232. package/dist/tools/SearchPill/useSearch.js.map +1 -0
  233. package/dist/tools/SearchPill/useSuggestions.js +105 -0
  234. package/dist/tools/SearchPill/useSuggestions.js.map +1 -0
  235. package/dist/tools/Tour/TourCard.js +156 -0
  236. package/dist/tools/Tour/TourCard.js.map +1 -0
  237. package/dist/tools/Tour/TourCard.styles.js +10 -0
  238. package/dist/tools/Tour/TourCard.styles.js.map +1 -0
  239. package/dist/tools/Tour/useTour.js +110 -0
  240. package/dist/tools/Tour/useTour.js.map +1 -0
  241. package/dist/tools/locate/useLocate.js +94 -0
  242. package/dist/tools/locate/useLocate.js.map +1 -0
  243. package/dist/ui/Button/Button.js +36 -0
  244. package/dist/ui/Button/Button.js.map +1 -0
  245. package/dist/ui/Button/Button.styles.js +17 -0
  246. package/dist/ui/Button/Button.styles.js.map +1 -0
  247. package/dist/ui/Chip/Chip.js +37 -0
  248. package/dist/ui/Chip/Chip.js.map +1 -0
  249. package/dist/ui/Chip/Chip.styles.js +29 -0
  250. package/dist/ui/Chip/Chip.styles.js.map +1 -0
  251. package/dist/ui/ControlGroup/ControlGroup.js +23 -0
  252. package/dist/ui/ControlGroup/ControlGroup.js.map +1 -0
  253. package/dist/ui/ControlGroup/ControlGroup.styles.js +6 -0
  254. package/dist/ui/ControlGroup/ControlGroup.styles.js.map +1 -0
  255. package/dist/ui/EmptyState/EmptyState.js +37 -0
  256. package/dist/ui/EmptyState/EmptyState.js.map +1 -0
  257. package/dist/ui/EmptyState/EmptyState.styles.js +10 -0
  258. package/dist/ui/EmptyState/EmptyState.styles.js.map +1 -0
  259. package/dist/ui/Icon/Icon.js +28 -0
  260. package/dist/ui/Icon/Icon.js.map +1 -0
  261. package/dist/ui/Icon/Icon.styles.js +8 -0
  262. package/dist/ui/Icon/Icon.styles.js.map +1 -0
  263. package/dist/ui/IconButton/IconButton.js +47 -0
  264. package/dist/ui/IconButton/IconButton.js.map +1 -0
  265. package/dist/ui/IconButton/IconButton.styles.js +27 -0
  266. package/dist/ui/IconButton/IconButton.styles.js.map +1 -0
  267. package/dist/ui/Isolate/Isolate.js +26 -0
  268. package/dist/ui/Isolate/Isolate.js.map +1 -0
  269. package/dist/ui/Isolate/fillSlots.js +27 -0
  270. package/dist/ui/Isolate/fillSlots.js.map +1 -0
  271. package/dist/ui/ListRow/ListRow.js +59 -0
  272. package/dist/ui/ListRow/ListRow.js.map +1 -0
  273. package/dist/ui/ListRow/ListRow.styles.js +30 -0
  274. package/dist/ui/ListRow/ListRow.styles.js.map +1 -0
  275. package/dist/ui/LiveRegion/LiveRegion.js +88 -0
  276. package/dist/ui/LiveRegion/LiveRegion.js.map +1 -0
  277. package/dist/ui/LiveRegion/announcer.js +114 -0
  278. package/dist/ui/LiveRegion/announcer.js.map +1 -0
  279. package/dist/ui/SegmentedControl/SegmentedControl.js +55 -0
  280. package/dist/ui/SegmentedControl/SegmentedControl.js.map +1 -0
  281. package/dist/ui/SegmentedControl/SegmentedControl.styles.js +9 -0
  282. package/dist/ui/SegmentedControl/SegmentedControl.styles.js.map +1 -0
  283. package/dist/ui/SkipLink/SkipLink.js +35 -0
  284. package/dist/ui/SkipLink/SkipLink.js.map +1 -0
  285. package/dist/ui/SkipLink/SkipLink.styles.js +6 -0
  286. package/dist/ui/SkipLink/SkipLink.styles.js.map +1 -0
  287. package/dist/ui/Slider/Slider.js +68 -0
  288. package/dist/ui/Slider/Slider.js.map +1 -0
  289. package/dist/ui/Slider/Slider.styles.js +13 -0
  290. package/dist/ui/Slider/Slider.styles.js.map +1 -0
  291. package/dist/ui/StatusMessage/StatusMessage.js +124 -0
  292. package/dist/ui/StatusMessage/StatusMessage.js.map +1 -0
  293. package/dist/ui/StatusMessage/StatusMessage.styles.js +28 -0
  294. package/dist/ui/StatusMessage/StatusMessage.styles.js.map +1 -0
  295. package/dist/ui/StatusMessage/StatusMessageFocus.js +30 -0
  296. package/dist/ui/StatusMessage/StatusMessageFocus.js.map +1 -0
  297. package/dist/ui/Surface/Surface.js +22 -0
  298. package/dist/ui/Surface/Surface.js.map +1 -0
  299. package/dist/ui/Surface/Surface.styles.js +27 -0
  300. package/dist/ui/Surface/Surface.styles.js.map +1 -0
  301. package/dist/ui/Switch/Switch.js +58 -0
  302. package/dist/ui/Switch/Switch.js.map +1 -0
  303. package/dist/ui/Switch/Switch.styles.js +13 -0
  304. package/dist/ui/Switch/Switch.styles.js.map +1 -0
  305. package/dist/ui/Tooltip/Tooltip.js +66 -0
  306. package/dist/ui/Tooltip/Tooltip.js.map +1 -0
  307. package/dist/ui/Tooltip/Tooltip.styles.js +6 -0
  308. package/dist/ui/Tooltip/Tooltip.styles.js.map +1 -0
  309. package/dist/ui/Tooltip/inheritColours.js +27 -0
  310. package/dist/ui/Tooltip/inheritColours.js.map +1 -0
  311. package/dist/ui/VisuallyHidden/VisuallyHidden.js +16 -0
  312. package/dist/ui/VisuallyHidden/VisuallyHidden.js.map +1 -0
  313. package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js +6 -0
  314. package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js.map +1 -0
  315. package/package.json +82 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useReverseAddress.js","names":[],"sources":["../../../src/tools/PinCard/useReverseAddress.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { type LatLng, roundForLookup, type SearchResult } from \"@mapcairn/core\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useSearchProvider } from \"../../services/hooks\";\n\n/** Where the address lookup for a position stands. */\nexport type AddressState =\n | { readonly status: \"idle\" }\n | { readonly status: \"loading\" }\n | { readonly status: \"found\"; readonly text: string }\n | { readonly status: \"none\" }\n | { readonly status: \"error\" };\n\n/** What {@link useReverseAddress} returns. */\nexport interface ReverseAddress {\n /** Where the lookup stands. It is `idle` until `lookUp` is called. */\n readonly state: AddressState;\n /**\n * Sends the position, rounded to about 11 m, to the search provider.\n * Calling it again aborts a lookup still in flight and starts a new one.\n */\n readonly lookUp: () => void;\n}\n\n/** Joins a place's label and secondary label into one address line. */\nfunction addressLine(result: SearchResult): string {\n return result.secondaryLabel\n ? `${result.label}, ${result.secondaryLabel}`\n : result.label;\n}\n\ninterface Tracked {\n readonly lat: number;\n readonly lng: number;\n readonly state: AddressState;\n}\n\n/**\n * Looks up the address at a position with the search provider's `reverse`,\n * but only when `lookUp` is called, because the position leaves the device.\n * The provider receives the position rounded with `roundForLookup`.\n *\n * @remarks Moving the position, or unmounting, aborts the lookup in flight and\n * returns the state to `idle`. An aborted lookup never changes state, and an\n * answer is only ever shown for the position it was asked for. A failed\n * lookup is `error`, which callers should show with a way to try again.\n */\nexport function useReverseAddress({ lat, lng }: LatLng): ReverseAddress {\n const provider = useSearchProvider();\n const [tracked, setTracked] = useState<Tracked>({\n lat,\n lng,\n state: { status: \"idle\" },\n });\n const controller = useRef<AbortController | null>(null);\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: lat and lng are the triggers, not values read in the effect\n useEffect(() => {\n setTracked({ lat, lng, state: { status: \"idle\" } });\n return () => {\n controller.current?.abort();\n controller.current = null;\n };\n }, [provider, lat, lng]);\n\n const lookUp = useCallback(() => {\n controller.current?.abort();\n const current = new AbortController();\n controller.current = current;\n const settle = (settled: AddressState) => {\n if (!current.signal.aborted) {\n setTracked({ lat, lng, state: settled });\n }\n };\n setTracked({ lat, lng, state: { status: \"loading\" } });\n provider\n .reverse(roundForLookup({ lat, lng }), { signal: current.signal })\n .then(\n (result) =>\n settle(\n result === null\n ? { status: \"none\" }\n : { status: \"found\", text: addressLine(result) },\n ),\n () => settle({ status: \"error\" }),\n );\n }, [provider, lat, lng]);\n\n // A state from another position is stale for the one render before the\n // effect resets it; never show it.\n const state: AddressState =\n tracked.lat === lat && tracked.lng === lng\n ? tracked.state\n : { status: \"idle\" };\n return { state, lookUp };\n}\n"],"mappings":";;;;;AA0BA,SAAS,YAAY,QAA8B;CACjD,OAAO,OAAO,iBACV,GAAG,OAAO,MAAM,IAAI,OAAO,mBAC3B,OAAO;AACb;;;;;;;;;;;AAkBA,SAAgB,kBAAkB,EAAE,KAAK,OAA+B;CACtE,MAAM,WAAW,kBAAkB;CACnC,MAAM,CAAC,SAAS,cAAc,SAAkB;EAC9C;EACA;EACA,OAAO,EAAE,QAAQ,OAAO;CAC1B,CAAC;CACD,MAAM,aAAa,OAA+B,IAAI;CAGtD,gBAAgB;EACd,WAAW;GAAE;GAAK;GAAK,OAAO,EAAE,QAAQ,OAAO;EAAE,CAAC;EAClD,aAAa;GACX,WAAW,SAAS,MAAM;GAC1B,WAAW,UAAU;EACvB;CACF,GAAG;EAAC;EAAU;EAAK;CAAG,CAAC;CAEvB,MAAM,SAAS,kBAAkB;EAC/B,WAAW,SAAS,MAAM;EAC1B,MAAM,UAAU,IAAI,gBAAgB;EACpC,WAAW,UAAU;EACrB,MAAM,UAAU,YAA0B;GACxC,IAAI,CAAC,QAAQ,OAAO,SAClB,WAAW;IAAE;IAAK;IAAK,OAAO;GAAQ,CAAC;EAE3C;EACA,WAAW;GAAE;GAAK;GAAK,OAAO,EAAE,QAAQ,UAAU;EAAE,CAAC;EACrD,SACG,QAAQ,eAAe;GAAE;GAAK;EAAI,CAAC,GAAG,EAAE,QAAQ,QAAQ,OAAO,CAAC,CAAC,CACjE,MACE,WACC,OACE,WAAW,OACP,EAAE,QAAQ,OAAO,IACjB;GAAE,QAAQ;GAAS,MAAM,YAAY,MAAM;EAAE,CACnD,SACI,OAAO,EAAE,QAAQ,QAAQ,CAAC,CAClC;CACJ,GAAG;EAAC;EAAU;EAAK;CAAG,CAAC;CAQvB,OAAO;EAAE,OAHP,QAAQ,QAAQ,OAAO,QAAQ,QAAQ,MACnC,QAAQ,QACR,EAAE,QAAQ,OAAO;EACP;CAAO;AACzB"}
@@ -0,0 +1,292 @@
1
+ import { useFocusTarget } from "../../chrome/focusRegistry.js";
2
+ import { useMessages } from "../../services/hooks.js";
3
+ import { Button } from "../../ui/Button/Button.js";
4
+ import { Icon } from "../../ui/Icon/Icon.js";
5
+ import { IconButton } from "../../ui/IconButton/IconButton.js";
6
+ import { Isolate } from "../../ui/Isolate/Isolate.js";
7
+ import { Surface } from "../../ui/Surface/Surface.js";
8
+ import { chevron, input, listbox, message, option, optionLabel, optionSecondary, optionText, panel, pill, root } from "./SearchPill.styles.js";
9
+ import { useSearch } from "./useSearch.js";
10
+ import { useSuggestions } from "./useSuggestions.js";
11
+ import { ChevronRight, Search, X } from "lucide-react";
12
+ import { useCallback, useId, useRef, useState } from "react";
13
+ import { jsx, jsxs } from "react/jsx-runtime";
14
+ // src/tools/SearchPill/SearchPill.tsx
15
+ var NO_RESULTS = [];
16
+ /**
17
+ * The options the listbox holds: the results of a submitted search, or, while
18
+ * nothing has been submitted for the text, the suggestions for it.
19
+ */
20
+ function listedOptions(state, suggestions) {
21
+ if (state.status === "results") return state.results;
22
+ return state.status === "idle" ? suggestions : NO_RESULTS;
23
+ }
24
+ /** Keeps the pointer from moving focus off the input. */
25
+ function keepFocus(event) {
26
+ event.preventDefault();
27
+ }
28
+ /**
29
+ * The floating search pill: a 48px pill holding an ARIA 1.2 combobox and a
30
+ * Search button, with the results in a listbox just below it. It must be
31
+ * rendered inside a `FocusRegistryProvider`, which it tells where the input is
32
+ * so that closing the search surface can return focus to it.
33
+ *
34
+ * The geocoder searches only on submit (Enter, or the Search button), never
35
+ * as the user types, because the OpenStreetMap Foundation's Nominatim policy
36
+ * forbids client-side autocomplete. Editing the text hides any results for
37
+ * the old text. When the host supplies a suggestion provider, the listbox also
38
+ * holds suggestions for the text as it is typed (see {@link useSuggestions}):
39
+ * they are the same options with the same keys, picking one goes straight to
40
+ * its place with no second lookup, and Enter with none highlighted still
41
+ * submits the text to the geocoder. When the provider is missing or failing,
42
+ * typing shows nothing and Enter works as it always did.
43
+ *
44
+ * Keyboard, following the WAI-ARIA Authoring Practices "list" combobox, with
45
+ * the listbox filled by suggestions or by a submitted search:
46
+ * - Results never take focus: the input keeps focus and
47
+ * `aria-activedescendant` names the active option.
48
+ * - ArrowDown and ArrowUp move the active option, wrapping at the ends, and
49
+ * open a closed list that has something to show. They are the only keys
50
+ * that move between options.
51
+ * - Home and End are left to the browser, so they move the caret as in any
52
+ * text field. When an option is active they also hand visual focus back to
53
+ * the text box (the active option is cleared), as the pattern describes.
54
+ * - Enter selects the active option. With no active option it submits the
55
+ * text, or reopens the list when it already holds that text's results.
56
+ * - Escape closes the list. With the list already closed, a second Escape
57
+ * clears the text, and a third reaches the page (closing the surface).
58
+ *
59
+ * Selecting a result or a suggestion fills the box with its label without
60
+ * searching again, and suggests nothing more for that label.
61
+ * @remarks The panel is in normal flow below the pill; the chrome slot that
62
+ * holds this component decides where both sit. Text states in the panel
63
+ * ("Searching...", "Nothing matched that search.", the unavailable message)
64
+ * carry no live-region role, because the announcer speaks the outcome.
65
+ */
66
+ function SearchPill({ onSelect, getBias, onFocus, onBlur }) {
67
+ const search = useSearch({ getBias });
68
+ const { t } = useMessages();
69
+ const { query, state } = search;
70
+ const [pickedLabel, setPickedLabel] = useState(null);
71
+ const [listOpen, setListOpen] = useState(false);
72
+ const [focused, setFocused] = useState(false);
73
+ const suggestions = useSuggestions(query, focused && state.status === "idle" && query !== pickedLabel);
74
+ const listboxId = useId();
75
+ const inputRef = useRef(null);
76
+ const registerFocus = useFocusTarget("search");
77
+ const results = listedOptions(state, suggestions);
78
+ const [active, setActive] = useState(null);
79
+ const activeIndex = active !== null && active.results === results && active.index < results.length ? active.index : -1;
80
+ const expanded = listOpen && (state.status !== "idle" || suggestions.length > 0);
81
+ const optionId = (index) => `${listboxId}-option-${index}`;
82
+ const setInputRef = useCallback((element) => {
83
+ inputRef.current = element;
84
+ registerFocus(element);
85
+ }, [registerFocus]);
86
+ const select = (result) => {
87
+ search.settle(result.label);
88
+ setPickedLabel(result.label);
89
+ setListOpen(false);
90
+ setActive(null);
91
+ onSelect(result);
92
+ };
93
+ const handleChange = (event) => {
94
+ search.setQuery(event.target.value);
95
+ setPickedLabel(null);
96
+ setFocused(true);
97
+ setListOpen(true);
98
+ setActive(null);
99
+ };
100
+ /** Searches for the text, or shows the outcome already found for it. */
101
+ const submit = () => {
102
+ search.submit();
103
+ setListOpen(true);
104
+ setActive(null);
105
+ };
106
+ const moveActive = (key) => {
107
+ const last = results.length - 1;
108
+ const from = expanded ? activeIndex : -1;
109
+ let next;
110
+ if (key === "ArrowDown") next = from >= last ? 0 : from + 1;
111
+ else next = from <= 0 ? last : from - 1;
112
+ setActive({
113
+ results,
114
+ index: next
115
+ });
116
+ };
117
+ const handleKeyDown = (event) => {
118
+ if (event.nativeEvent.isComposing) return;
119
+ switch (event.key) {
120
+ case "ArrowDown":
121
+ case "ArrowUp":
122
+ if (state.status === "idle" && suggestions.length === 0) return;
123
+ event.preventDefault();
124
+ setListOpen(true);
125
+ if (results.length > 0) moveActive(event.key);
126
+ return;
127
+ case "Home":
128
+ case "End":
129
+ setActive(null);
130
+ return;
131
+ case "Enter": {
132
+ event.preventDefault();
133
+ const result = expanded ? results[activeIndex] : void 0;
134
+ if (result) select(result);
135
+ else submit();
136
+ return;
137
+ }
138
+ case "Escape":
139
+ if (expanded) {
140
+ event.preventDefault();
141
+ event.stopPropagation();
142
+ setListOpen(false);
143
+ setActive(null);
144
+ } else if (query !== "") {
145
+ event.preventDefault();
146
+ event.stopPropagation();
147
+ search.clear();
148
+ }
149
+ return;
150
+ }
151
+ };
152
+ const handleFocus = (event) => {
153
+ setFocused(true);
154
+ setListOpen(true);
155
+ onFocus?.(event);
156
+ };
157
+ const handleRootBlur = (event) => {
158
+ if (!event.currentTarget.contains(event.relatedTarget)) {
159
+ setFocused(false);
160
+ setListOpen(false);
161
+ setActive(null);
162
+ }
163
+ };
164
+ const handleClear = () => {
165
+ search.clear();
166
+ setListOpen(false);
167
+ setActive(null);
168
+ inputRef.current?.focus();
169
+ };
170
+ const handleSubmitClick = () => {
171
+ submit();
172
+ inputRef.current?.focus();
173
+ };
174
+ const handleRetry = () => {
175
+ search.retry();
176
+ inputRef.current?.focus();
177
+ };
178
+ return /* @__PURE__ */ jsxs("div", {
179
+ role: "search",
180
+ "aria-label": t("tools.search.label", {}),
181
+ className: root,
182
+ "data-chrome": "search-pill",
183
+ "data-testid": "search-pill",
184
+ onBlur: handleRootBlur,
185
+ children: [/* @__PURE__ */ jsxs(Surface, {
186
+ radius: "pill",
187
+ className: pill,
188
+ children: [
189
+ /* @__PURE__ */ jsx("input", {
190
+ ref: setInputRef,
191
+ className: input,
192
+ type: "text",
193
+ role: "combobox",
194
+ "aria-label": t("tools.search.places", {}),
195
+ "aria-autocomplete": "list",
196
+ "aria-expanded": expanded,
197
+ "aria-controls": listboxId,
198
+ "aria-activedescendant": expanded && activeIndex >= 0 ? optionId(activeIndex) : void 0,
199
+ autoComplete: "off",
200
+ autoCapitalize: "off",
201
+ spellCheck: false,
202
+ enterKeyHint: "search",
203
+ placeholder: t("tools.search.places", {}),
204
+ value: query,
205
+ "data-testid": "location-search-input",
206
+ onChange: handleChange,
207
+ onKeyDown: handleKeyDown,
208
+ onFocus: handleFocus,
209
+ onBlur
210
+ }),
211
+ query !== "" ? /* @__PURE__ */ jsx(IconButton, {
212
+ label: t("tools.search.clear", {}),
213
+ icon: X,
214
+ size: "compact",
215
+ "data-testid": "location-search-clear",
216
+ onMouseDown: keepFocus,
217
+ onClick: handleClear
218
+ }) : null,
219
+ /* @__PURE__ */ jsx(IconButton, {
220
+ label: t("tools.search.label", {}),
221
+ icon: Search,
222
+ size: "compact",
223
+ disabled: query.trim().length < 2,
224
+ busy: state.status === "loading",
225
+ "data-testid": "location-search-submit",
226
+ onMouseDown: keepFocus,
227
+ onClick: handleSubmitClick
228
+ })
229
+ ]
230
+ }), /* @__PURE__ */ jsxs(Surface, {
231
+ variant: "floating",
232
+ radius: "control",
233
+ className: panel,
234
+ hidden: !expanded,
235
+ "data-chrome": "search-results",
236
+ "data-testid": "location-search-panel",
237
+ children: [
238
+ /* @__PURE__ */ jsx("div", {
239
+ id: listboxId,
240
+ role: "listbox",
241
+ "aria-label": state.status === "idle" ? t("tools.search.suggestions", {}) : t("tools.search.results", {}),
242
+ className: listbox,
243
+ "data-testid": "location-search-results",
244
+ children: results.map((result, index) => /* @__PURE__ */ jsxs("div", {
245
+ id: optionId(index),
246
+ role: "option",
247
+ "aria-selected": index === activeIndex,
248
+ className: option,
249
+ "data-testid": "location-search-option",
250
+ onMouseDown: keepFocus,
251
+ onClick: () => select(result),
252
+ children: [/* @__PURE__ */ jsxs("span", {
253
+ className: optionText,
254
+ children: [/* @__PURE__ */ jsx("span", {
255
+ className: optionLabel,
256
+ children: /* @__PURE__ */ jsx(Isolate, { children: result.label })
257
+ }), result.secondaryLabel ? /* @__PURE__ */ jsx("span", {
258
+ className: optionSecondary,
259
+ children: /* @__PURE__ */ jsx(Isolate, { children: result.secondaryLabel })
260
+ }) : null]
261
+ }), index === activeIndex ? /* @__PURE__ */ jsx(Icon, {
262
+ icon: ChevronRight,
263
+ mirrorInRtl: true,
264
+ className: chevron
265
+ }) : null]
266
+ }, result.id))
267
+ }),
268
+ state.status === "loading" ? /* @__PURE__ */ jsx("div", {
269
+ className: message,
270
+ children: t("tools.search.searching", {})
271
+ }) : null,
272
+ state.status === "empty" ? /* @__PURE__ */ jsx("div", {
273
+ className: message,
274
+ children: t("tools.search.nothingMatched", {})
275
+ }) : null,
276
+ state.status === "error" ? /* @__PURE__ */ jsxs("div", {
277
+ className: message,
278
+ children: [/* @__PURE__ */ jsx("span", { children: t("tools.search.unavailable", {}) }), /* @__PURE__ */ jsx(Button, {
279
+ variant: "quiet",
280
+ "data-testid": "location-search-retry",
281
+ onMouseDown: keepFocus,
282
+ onClick: handleRetry,
283
+ children: t("tools.search.retry", {})
284
+ })]
285
+ }) : null
286
+ ]
287
+ })]
288
+ });
289
+ }
290
+ export { SearchPill };
291
+
292
+ //# sourceMappingURL=SearchPill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchPill.js","names":["styles.root","styles.pill","styles.input","styles.panel","styles.listbox","styles.option","styles.optionText","styles.optionLabel","styles.optionSecondary","styles.chevron","styles.message"],"sources":["../../../src/tools/SearchPill/SearchPill.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { Bounds, SearchResult } from \"@mapcairn/core\";\nimport { ChevronRight, Search, X } from \"lucide-react\";\nimport {\n type ChangeEvent,\n type FocusEvent,\n type FocusEventHandler,\n type KeyboardEvent,\n type MouseEvent,\n useCallback,\n useId,\n useRef,\n useState,\n} from \"react\";\nimport { useFocusTarget } from \"../../chrome/focusRegistry\";\nimport { useMessages } from \"../../services\";\nimport { Button } from \"../../ui/Button\";\nimport { Icon } from \"../../ui/Icon\";\nimport { IconButton } from \"../../ui/IconButton\";\nimport { Isolate } from \"../../ui/Isolate\";\nimport { Surface } from \"../../ui/Surface\";\nimport * as styles from \"./SearchPill.css\";\nimport { MIN_SEARCH_LENGTH, type SearchState, useSearch } from \"./useSearch\";\nimport { useSuggestions } from \"./useSuggestions\";\n\n/** Props for {@link SearchPill}. */\nexport interface SearchPillProps {\n /** Called when the user picks a result, by click, tap or Enter. */\n readonly onSelect: (result: SearchResult) => void;\n /**\n * Returns the box to favour results inside, usually the visible map. Read\n * once when each search is submitted. Optional, and passed to\n * {@link useSearch}, whose note on what a bias sends applies.\n */\n readonly getBias?: () => Bounds | undefined;\n /** Passed through from the input, for example to open the search surface. */\n readonly onFocus?: FocusEventHandler<HTMLInputElement>;\n /** Passed through from the input, for example to close the search surface. */\n readonly onBlur?: FocusEventHandler<HTMLInputElement>;\n}\n\nconst NO_RESULTS: readonly SearchResult[] = [];\n\n/**\n * The options the listbox holds: the results of a submitted search, or, while\n * nothing has been submitted for the text, the suggestions for it.\n */\nfunction listedOptions(\n state: SearchState,\n suggestions: readonly SearchResult[],\n): readonly SearchResult[] {\n if (state.status === \"results\") {\n return state.results;\n }\n return state.status === \"idle\" ? suggestions : NO_RESULTS;\n}\n\n/** Keeps the pointer from moving focus off the input. */\nfunction keepFocus(event: MouseEvent) {\n event.preventDefault();\n}\n\n/**\n * The floating search pill: a 48px pill holding an ARIA 1.2 combobox and a\n * Search button, with the results in a listbox just below it. It must be\n * rendered inside a `FocusRegistryProvider`, which it tells where the input is\n * so that closing the search surface can return focus to it.\n *\n * The geocoder searches only on submit (Enter, or the Search button), never\n * as the user types, because the OpenStreetMap Foundation's Nominatim policy\n * forbids client-side autocomplete. Editing the text hides any results for\n * the old text. When the host supplies a suggestion provider, the listbox also\n * holds suggestions for the text as it is typed (see {@link useSuggestions}):\n * they are the same options with the same keys, picking one goes straight to\n * its place with no second lookup, and Enter with none highlighted still\n * submits the text to the geocoder. When the provider is missing or failing,\n * typing shows nothing and Enter works as it always did.\n *\n * Keyboard, following the WAI-ARIA Authoring Practices \"list\" combobox, with\n * the listbox filled by suggestions or by a submitted search:\n * - Results never take focus: the input keeps focus and\n * `aria-activedescendant` names the active option.\n * - ArrowDown and ArrowUp move the active option, wrapping at the ends, and\n * open a closed list that has something to show. They are the only keys\n * that move between options.\n * - Home and End are left to the browser, so they move the caret as in any\n * text field. When an option is active they also hand visual focus back to\n * the text box (the active option is cleared), as the pattern describes.\n * - Enter selects the active option. With no active option it submits the\n * text, or reopens the list when it already holds that text's results.\n * - Escape closes the list. With the list already closed, a second Escape\n * clears the text, and a third reaches the page (closing the surface).\n *\n * Selecting a result or a suggestion fills the box with its label without\n * searching again, and suggests nothing more for that label.\n * @remarks The panel is in normal flow below the pill; the chrome slot that\n * holds this component decides where both sit. Text states in the panel\n * (\"Searching...\", \"Nothing matched that search.\", the unavailable message)\n * carry no live-region role, because the announcer speaks the outcome.\n */\nexport function SearchPill({\n onSelect,\n getBias,\n onFocus,\n onBlur,\n}: SearchPillProps) {\n const search = useSearch({ getBias });\n const { t } = useMessages();\n const { query, state } = search;\n const [pickedLabel, setPickedLabel] = useState<string | null>(null);\n const [listOpen, setListOpen] = useState(false);\n const [focused, setFocused] = useState(false);\n const suggestions = useSuggestions(\n query,\n focused && state.status === \"idle\" && query !== pickedLabel,\n );\n const listboxId = useId();\n const inputRef = useRef<HTMLInputElement | null>(null);\n const registerFocus = useFocusTarget(\"search\");\n const results = listedOptions(state, suggestions);\n const [active, setActive] = useState<{\n readonly results: readonly SearchResult[];\n readonly index: number;\n } | null>(null);\n\n // The active option belongs to one list of results; a new list resets it.\n const activeIndex =\n active !== null &&\n active.results === results &&\n active.index < results.length\n ? active.index\n : -1;\n const expanded =\n listOpen && (state.status !== \"idle\" || suggestions.length > 0);\n const optionId = (index: number) => `${listboxId}-option-${index}`;\n\n const setInputRef = useCallback(\n (element: HTMLInputElement | null) => {\n inputRef.current = element;\n registerFocus(element);\n },\n [registerFocus],\n );\n\n const select = (result: SearchResult) => {\n search.settle(result.label);\n setPickedLabel(result.label);\n setListOpen(false);\n setActive(null);\n onSelect(result);\n };\n\n const handleChange = (event: ChangeEvent<HTMLInputElement>) => {\n search.setQuery(event.target.value);\n setPickedLabel(null);\n setFocused(true);\n setListOpen(true);\n setActive(null);\n };\n\n /** Searches for the text, or shows the outcome already found for it. */\n const submit = () => {\n search.submit();\n setListOpen(true);\n setActive(null);\n };\n\n const moveActive = (key: \"ArrowDown\" | \"ArrowUp\") => {\n const last = results.length - 1;\n const from = expanded ? activeIndex : -1;\n let next: number;\n if (key === \"ArrowDown\") {\n next = from >= last ? 0 : from + 1;\n } else {\n next = from <= 0 ? last : from - 1;\n }\n setActive({ results, index: next });\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.nativeEvent.isComposing) {\n return;\n }\n switch (event.key) {\n case \"ArrowDown\":\n case \"ArrowUp\":\n if (state.status === \"idle\" && suggestions.length === 0) {\n return;\n }\n event.preventDefault();\n setListOpen(true);\n if (results.length > 0) {\n moveActive(event.key);\n }\n return;\n case \"Home\":\n case \"End\":\n setActive(null);\n return;\n case \"Enter\": {\n event.preventDefault();\n const result = expanded ? results[activeIndex] : undefined;\n if (result) {\n select(result);\n } else {\n submit();\n }\n return;\n }\n case \"Escape\":\n if (expanded) {\n event.preventDefault();\n event.stopPropagation();\n setListOpen(false);\n setActive(null);\n } else if (query !== \"\") {\n event.preventDefault();\n event.stopPropagation();\n search.clear();\n }\n return;\n default:\n }\n };\n\n const handleFocus = (event: FocusEvent<HTMLInputElement>) => {\n setFocused(true);\n setListOpen(true);\n onFocus?.(event);\n };\n\n const handleRootBlur = (event: FocusEvent<HTMLDivElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget)) {\n setFocused(false);\n setListOpen(false);\n setActive(null);\n }\n };\n\n const handleClear = () => {\n search.clear();\n setListOpen(false);\n setActive(null);\n inputRef.current?.focus();\n };\n\n const handleSubmitClick = () => {\n submit();\n inputRef.current?.focus();\n };\n\n const handleRetry = () => {\n search.retry();\n inputRef.current?.focus();\n };\n\n return (\n // biome-ignore lint/a11y/noNoninteractiveElementInteractions: the blur handler only closes the list when focus leaves the search; it adds no interaction of its own\n // biome-ignore lint/a11y/useSemanticElements: the search landmark is requested with role=\"search\" and a name\n <div\n role=\"search\"\n aria-label={t(\"tools.search.label\", {})}\n className={styles.root}\n data-chrome=\"search-pill\"\n data-testid=\"search-pill\"\n onBlur={handleRootBlur}\n >\n <Surface radius=\"pill\" className={styles.pill}>\n <input\n ref={setInputRef}\n className={styles.input}\n type=\"text\"\n role=\"combobox\"\n aria-label={t(\"tools.search.places\", {})}\n aria-autocomplete=\"list\"\n aria-expanded={expanded}\n aria-controls={listboxId}\n aria-activedescendant={\n expanded && activeIndex >= 0 ? optionId(activeIndex) : undefined\n }\n autoComplete=\"off\"\n autoCapitalize=\"off\"\n spellCheck={false}\n enterKeyHint=\"search\"\n placeholder={t(\"tools.search.places\", {})}\n value={query}\n data-testid=\"location-search-input\"\n onChange={handleChange}\n onKeyDown={handleKeyDown}\n onFocus={handleFocus}\n onBlur={onBlur}\n />\n {query !== \"\" ? (\n <IconButton\n label={t(\"tools.search.clear\", {})}\n icon={X}\n size=\"compact\"\n data-testid=\"location-search-clear\"\n onMouseDown={keepFocus}\n onClick={handleClear}\n />\n ) : null}\n <IconButton\n label={t(\"tools.search.label\", {})}\n icon={Search}\n size=\"compact\"\n disabled={query.trim().length < MIN_SEARCH_LENGTH}\n busy={state.status === \"loading\"}\n data-testid=\"location-search-submit\"\n onMouseDown={keepFocus}\n onClick={handleSubmitClick}\n />\n </Surface>\n <Surface\n variant=\"floating\"\n radius=\"control\"\n className={styles.panel}\n hidden={!expanded}\n data-chrome=\"search-results\"\n data-testid=\"location-search-panel\"\n >\n <div\n id={listboxId}\n role=\"listbox\"\n aria-label={\n state.status === \"idle\"\n ? t(\"tools.search.suggestions\", {})\n : t(\"tools.search.results\", {})\n }\n className={styles.listbox}\n data-testid=\"location-search-results\"\n >\n {results.map((result, index) => (\n // biome-ignore lint/a11y/useKeyWithClickEvents: keyboard selection happens on the combobox input, which keeps focus\n // biome-ignore lint/a11y/useFocusableInteractive: options are never focused; the input names the active one with aria-activedescendant\n <div\n key={result.id}\n id={optionId(index)}\n role=\"option\"\n aria-selected={index === activeIndex}\n className={styles.option}\n data-testid=\"location-search-option\"\n onMouseDown={keepFocus}\n onClick={() => select(result)}\n >\n <span className={styles.optionText}>\n <span className={styles.optionLabel}>\n <Isolate>{result.label}</Isolate>\n </span>\n {result.secondaryLabel ? (\n <span className={styles.optionSecondary}>\n <Isolate>{result.secondaryLabel}</Isolate>\n </span>\n ) : null}\n </span>\n {index === activeIndex ? (\n <Icon\n icon={ChevronRight}\n mirrorInRtl\n className={styles.chevron}\n />\n ) : null}\n </div>\n ))}\n </div>\n {state.status === \"loading\" ? (\n <div className={styles.message}>\n {t(\"tools.search.searching\", {})}\n </div>\n ) : null}\n {state.status === \"empty\" ? (\n <div className={styles.message}>\n {t(\"tools.search.nothingMatched\", {})}\n </div>\n ) : null}\n {state.status === \"error\" ? (\n <div className={styles.message}>\n <span>{t(\"tools.search.unavailable\", {})}</span>\n <Button\n variant=\"quiet\"\n data-testid=\"location-search-retry\"\n onMouseDown={keepFocus}\n onClick={handleRetry}\n >\n {t(\"tools.search.retry\", {})}\n </Button>\n </div>\n ) : null}\n </Surface>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,IAAM,aAAsC,CAAC;;;;;AAM7C,SAAS,cACP,OACA,aACyB;CACzB,IAAI,MAAM,WAAW,WACnB,OAAO,MAAM;CAEf,OAAO,MAAM,WAAW,SAAS,cAAc;AACjD;;AAGA,SAAS,UAAU,OAAmB;CACpC,MAAM,eAAe;AACvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,WAAW,EACzB,UACA,SACA,SACA,UACkB;CAClB,MAAM,SAAS,UAAU,EAAE,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ACZ,aAAa;MACb,eAAe,OAAO,MAAM;MAR9B,UAAA,CAUE,qBAAC,QAAD;OAAM,WAAWC;OAAjB,UAAA,CACE,oBAAC,QAAD;QAAM,WAAWC;QACf,UAAA,oBAAC,SAAD,EAAA,UAAU,OAAO,MAAe,CAAA;OAC5B,CAAA,GACL,OAAO,iBACN,oBAAC,QAAD;QAAM,WAAWC;QACf,UAAA,oBAAC,SAAD,EAAA,UAAU,OAAO,eAAwB,CAAA;OACrC,CAAA,IACJ,IACA;MACL,CAAA,GAAA,UAAU,cACT,oBAAC,MAAD;OACE,MAAM;OACN,aAAA;OACA,WAAWC;MACZ,CAAA,IACC,IACD;KA1BE,GAAA,OAAO,EA0BT,CACN;IACE,CAAA;IACJ,MAAM,WAAW,YAChB,oBAAC,OAAD;KAAK,WAAWC;KACb,UAAA,EAAE,0BAA0B,CAAC,CAAC;IAC5B,CAAA,IACH;IACH,MAAM,WAAW,UAChB,oBAAC,OAAD;KAAK,WAAWA;KACb,UAAA,EAAE,+BAA+B,CAAC,CAAC;IACjC,CAAA,IACH;IACH,MAAM,WAAW,UAChB,qBAAC,OAAD;KAAK,WAAWA;KAAhB,UAAA,CACE,oBAAC,QAAD,EAAA,UAAO,EAAE,4BAA4B,CAAC,CAAC,EAAQ,CAAA,GAC/C,oBAAC,QAAD;MACE,SAAQ;MACR,eAAY;MACZ,aAAa;MACb,SAAS;MAER,UAAA,EAAE,sBAAsB,CAAC,CAAC;KACrB,CAAA,CACL;IACH,CAAA,IAAA;GACG;EACN,CAAA,CAAA;;AAET"}
@@ -0,0 +1,16 @@
1
+ /* empty css */
2
+ // src/tools/SearchPill/SearchPill.css.ts
3
+ var root = "_1qolt5p0";
4
+ var pill = "_1qolt5p1";
5
+ var input = "_1qolt5p2";
6
+ var panel = "_1qolt5p3";
7
+ var listbox = "_1qolt5p4";
8
+ var option = "_1qolt5p5";
9
+ var optionText = "_1qolt5p6";
10
+ var optionLabel = "_1qolt5p7";
11
+ var optionSecondary = "_1qolt5p8";
12
+ var chevron = "_1qolt5p9";
13
+ var message = "_1qolt5pa";
14
+ export { chevron, input, listbox, message, option, optionLabel, optionSecondary, optionText, panel, pill, root };
15
+
16
+ //# sourceMappingURL=SearchPill.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchPill.styles.js","names":[],"sources":[],"mappings":""}
@@ -0,0 +1,41 @@
1
+ import { IconButton } from "../../ui/IconButton/IconButton.js";
2
+ import { Surface } from "../../ui/Surface/Surface.js";
3
+ import { input, pill, root } from "./SearchPill.styles.js";
4
+ import { Search } from "lucide-react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ // src/tools/SearchPill/SearchPillSkeleton.tsx
7
+ /**
8
+ * The search pill as a decorative stand-in for the server-rendered
9
+ * `ChromeSkeleton`: the same wrapper, pill and input classes as
10
+ * {@link SearchPill}, so it fills the same box, with nothing wired up.
11
+ *
12
+ * @remarks Only ever rendered inside an `aria-hidden`, `inert` container. It
13
+ * uses no hooks and needs no provider: its words arrive as `copy`. The Search button is disabled, as the
14
+ * real one is while the box is empty.
15
+ */
16
+ function SearchPillSkeleton({ copy }) {
17
+ return /* @__PURE__ */ jsx("div", {
18
+ className: root,
19
+ "data-skeleton": "search",
20
+ children: /* @__PURE__ */ jsxs(Surface, {
21
+ radius: "pill",
22
+ className: pill,
23
+ children: [/* @__PURE__ */ jsx("input", {
24
+ className: input,
25
+ type: "text",
26
+ readOnly: true,
27
+ tabIndex: -1,
28
+ placeholder: copy.placeholder
29
+ }), /* @__PURE__ */ jsx(IconButton, {
30
+ label: copy.searchLabel,
31
+ icon: Search,
32
+ size: "compact",
33
+ disabled: true,
34
+ tabIndex: -1
35
+ })]
36
+ })
37
+ });
38
+ }
39
+ export { SearchPillSkeleton };
40
+
41
+ //# sourceMappingURL=SearchPillSkeleton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchPillSkeleton.js","names":["styles.root","styles.pill","styles.input"],"sources":["../../../src/tools/SearchPill/SearchPillSkeleton.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { Search } from \"lucide-react\";\nimport { IconButton } from \"../../ui/IconButton\";\nimport { Surface } from \"../../ui/Surface\";\nimport * as styles from \"./SearchPill.css\";\n\n/** The words of {@link SearchPillSkeleton}, in the host's default language. */\nexport interface SearchPillSkeletonCopy {\n /** The input's placeholder, as the live pill's. */\n readonly placeholder: string;\n /** The Search button's name. */\n readonly searchLabel: string;\n}\n\n/** Props for {@link SearchPillSkeleton}. */\nexport interface SearchPillSkeletonProps {\n readonly copy: SearchPillSkeletonCopy;\n}\n\n/**\n * The search pill as a decorative stand-in for the server-rendered\n * `ChromeSkeleton`: the same wrapper, pill and input classes as\n * {@link SearchPill}, so it fills the same box, with nothing wired up.\n *\n * @remarks Only ever rendered inside an `aria-hidden`, `inert` container. It\n * uses no hooks and needs no provider: its words arrive as `copy`. The Search button is disabled, as the\n * real one is while the box is empty.\n */\nexport function SearchPillSkeleton({ copy }: SearchPillSkeletonProps) {\n return (\n <div className={styles.root} data-skeleton=\"search\">\n <Surface radius=\"pill\" className={styles.pill}>\n <input\n className={styles.input}\n type=\"text\"\n readOnly\n tabIndex={-1}\n placeholder={copy.placeholder}\n />\n <IconButton\n label={copy.searchLabel}\n icon={Search}\n size=\"compact\"\n disabled\n tabIndex={-1}\n />\n </Surface>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6BA,SAAgB,mBAAmB,EAAE,QAAiC;CACpE,OACE,oBAAC,OAAD;EAAK,WAAWA;EAAa,iBAAc;EACzC,UAAA,qBAAC,SAAD;GAAS,QAAO;GAAO,WAAWC;GAAlC,UAAA,CACE,oBAAC,SAAD;IACE,WAAWC;IACX,MAAK;IACL,UAAA;IACA,UAAU;IACV,aAAa,KAAK;GACnB,CAAA,GACD,oBAAC,YAAD;IACE,OAAO,KAAK;IACZ,MAAM;IACN,MAAK;IACL,UAAA;IACA,UAAU;GACX,CAAA,CACM;;CACN,CAAA;AAET"}
@@ -0,0 +1,143 @@
1
+ import { useMessages, useSearchProvider } from "../../services/hooks.js";
2
+ import { useAnnounce } from "../../ui/LiveRegion/LiveRegion.js";
3
+ import { PortAbortError, SearchError, announceCoordinateResult, announceNoResults, announceSearchError, announceSearchResults, coordinateSearchResult } from "@mapcairn/core";
4
+ import { useCallback, useEffect, useRef, useState } from "react";
5
+ import { useLatestRef } from "@mapcairn/react";
6
+ // src/tools/SearchPill/useSearch.ts
7
+ /**
8
+ * The fewest characters (after trimming) that a submitted search needs.
9
+ *
10
+ * @internal
11
+ */
12
+ var MIN_SEARCH_LENGTH = 2;
13
+ var IDLE = { status: "idle" };
14
+ /**
15
+ * Cancellable place search over the services' `SearchProvider`, run only
16
+ * when the user submits. Text that is a coordinate pair, such as
17
+ * `-26.2041, 28.0473` or `26°12'14.8"S 28°02'50.3"E`, is answered here with
18
+ * one result for that place and never reaches the provider, so it sends no
19
+ * request. Nothing is sent to the geocoder while they type, as the
20
+ * OpenStreetMap Foundation's Nominatim policy forbids client-side
21
+ * autocomplete; suggestions as they type come from a separate provider (see
22
+ * `useSuggestions`). This is the one place that owns the `AbortController`: each
23
+ * search aborts the one before it, and an aborted request never changes state
24
+ * or reaches the announcer. The provider itself keeps to the service's rate
25
+ * limit.
26
+ *
27
+ * Announcements go through the app-wide announcer: the result count (or "No
28
+ * results", or the error) once the search settles. An identical message is
29
+ * not repeated for consecutive searches until the box has been emptied or
30
+ * Retry is pressed.
31
+ */
32
+ function useSearch({ getBias } = {}) {
33
+ const provider = useSearchProvider();
34
+ const announce = useAnnounce();
35
+ const providerRef = useLatestRef(provider);
36
+ const announceRef = useLatestRef(announce);
37
+ const messagesRef = useLatestRef(useMessages());
38
+ const getBiasRef = useLatestRef(getBias);
39
+ const [query, setQueryState] = useState("");
40
+ const [state, setState] = useState(IDLE);
41
+ const stateRef = useLatestRef(state);
42
+ const queryRef = useRef("");
43
+ const controller = useRef(null);
44
+ const lastAnnounced = useRef(null);
45
+ const cancel = useCallback(() => {
46
+ controller.current?.abort();
47
+ controller.current = null;
48
+ }, []);
49
+ const announceOnce = useCallback((message, priority) => {
50
+ const outcome = JSON.stringify(message);
51
+ if (outcome === lastAnnounced.current) return;
52
+ lastAnnounced.current = outcome;
53
+ announceRef.current(message, { priority });
54
+ }, [announceRef]);
55
+ const showResults = useCallback((results, message) => {
56
+ setState({
57
+ status: "results",
58
+ results
59
+ });
60
+ announceOnce(message, "polite");
61
+ }, [announceOnce]);
62
+ const run = useCallback(async (text) => {
63
+ controller.current?.abort();
64
+ const coordinates = coordinateSearchResult(text, messagesRef.current);
65
+ if (coordinates !== null) {
66
+ controller.current = null;
67
+ showResults([coordinates], announceCoordinateResult(coordinates.label));
68
+ return;
69
+ }
70
+ const own = new AbortController();
71
+ controller.current = own;
72
+ setState({ status: "loading" });
73
+ try {
74
+ const results = await providerRef.current.search(text, {
75
+ bias: getBiasRef.current?.(),
76
+ signal: own.signal
77
+ });
78
+ if (own.signal.aborted) return;
79
+ if (results.length === 0) {
80
+ setState({ status: "empty" });
81
+ announceOnce(announceNoResults(), "polite");
82
+ } else showResults(results, announceSearchResults(results.length));
83
+ } catch (error) {
84
+ if (own.signal.aborted || error instanceof PortAbortError) return;
85
+ const kind = error instanceof SearchError ? error.kind : "failed";
86
+ setState({
87
+ status: "error",
88
+ kind
89
+ });
90
+ announceOnce(announceSearchError(kind), "assertive");
91
+ }
92
+ }, [
93
+ providerRef,
94
+ getBiasRef,
95
+ messagesRef,
96
+ announceOnce,
97
+ showResults
98
+ ]);
99
+ const setQuery = useCallback((next) => {
100
+ queryRef.current = next;
101
+ setQueryState(next);
102
+ cancel();
103
+ if (next.trim().length < 2) lastAnnounced.current = null;
104
+ setState(IDLE);
105
+ }, [cancel]);
106
+ const submit = useCallback(() => {
107
+ const trimmed = queryRef.current.trim();
108
+ if (trimmed.length < 2) return;
109
+ const status = stateRef.current.status;
110
+ if (status !== "idle" && status !== "error") return;
111
+ run(trimmed);
112
+ }, [run, stateRef]);
113
+ const settle = useCallback((next) => {
114
+ queryRef.current = next;
115
+ setQueryState(next);
116
+ cancel();
117
+ lastAnnounced.current = null;
118
+ setState(IDLE);
119
+ }, [cancel]);
120
+ const clear = useCallback(() => {
121
+ settle("");
122
+ }, [settle]);
123
+ const retry = useCallback(() => {
124
+ const trimmed = queryRef.current.trim();
125
+ if (trimmed.length < 2) return;
126
+ cancel();
127
+ lastAnnounced.current = null;
128
+ run(trimmed);
129
+ }, [cancel, run]);
130
+ useEffect(() => cancel, [cancel]);
131
+ return {
132
+ query,
133
+ state,
134
+ setQuery,
135
+ submit,
136
+ settle,
137
+ clear,
138
+ retry
139
+ };
140
+ }
141
+ export { MIN_SEARCH_LENGTH, useSearch };
142
+
143
+ //# sourceMappingURL=useSearch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSearch.js","names":[],"sources":["../../../src/tools/SearchPill/useSearch.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport {\n announceCoordinateResult,\n announceNoResults,\n announceSearchError,\n announceSearchResults,\n type Bounds,\n coordinateSearchResult,\n type Message,\n PortAbortError,\n SearchError,\n type SearchErrorKind,\n type SearchResult,\n} from \"@mapcairn/core\";\nimport { useLatestRef } from \"@mapcairn/react\";\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { useMessages, useSearchProvider } from \"../../services/hooks\";\nimport { useAnnounce } from \"../../ui/LiveRegion\";\n\n/**\n * The fewest characters (after trimming) that a submitted search needs.\n *\n * @internal\n */\nexport const MIN_SEARCH_LENGTH = 2;\n\n/** Where a search stands. Exactly one of these is true at a time. */\nexport type SearchState =\n | { readonly status: \"idle\" }\n | { readonly status: \"loading\" }\n | { readonly status: \"results\"; readonly results: readonly SearchResult[] }\n | { readonly status: \"empty\" }\n | { readonly status: \"error\"; readonly kind: SearchErrorKind };\n\n/** Options for {@link useSearch}. */\nexport interface UseSearchOptions {\n /**\n * Returns the box to favour results inside, usually the visible map. Called\n * once when each search starts, so the bias follows the map without the\n * caller recomputing it on every frame. Leave it out to send only the\n * query: a host that passes it sends that box to its geocoder with every\n * search, which can show where the person is, so its privacy text must say so.\n */\n readonly getBias?: () => Bounds | undefined;\n}\n\n/** What {@link useSearch} returns. */\nexport interface UseSearch {\n /** The text in the search box. */\n readonly query: string;\n /** Where the search stands. */\n readonly state: SearchState;\n /**\n * Sets the text as the user typed it. Never searches: it cancels any search\n * in flight and returns to `idle`, so results for older text never sit\n * under new text.\n */\n readonly setQuery: (query: string) => void;\n /**\n * Searches for the current text, for Enter or the Search button. Answers a\n * coordinate pair itself, without the provider. Does\n * nothing when the trimmed text is shorter than {@link MIN_SEARCH_LENGTH},\n * or when the text's own search is already loading or showing its outcome\n * (after a failure it searches again).\n */\n readonly submit: () => void;\n /**\n * Puts text in the box without searching: cancels anything in flight and\n * returns to `idle`. Used when the user picks a result, so the box shows\n * its label.\n */\n readonly settle: (query: string) => void;\n /** Empties the box and cancels everything. */\n readonly clear: () => void;\n /** Runs the current query again at once, for the Retry button. */\n readonly retry: () => void;\n}\n\nconst IDLE: SearchState = { status: \"idle\" };\n\n/**\n * Cancellable place search over the services' `SearchProvider`, run only\n * when the user submits. Text that is a coordinate pair, such as\n * `-26.2041, 28.0473` or `26°12'14.8\"S 28°02'50.3\"E`, is answered here with\n * one result for that place and never reaches the provider, so it sends no\n * request. Nothing is sent to the geocoder while they type, as the\n * OpenStreetMap Foundation's Nominatim policy forbids client-side\n * autocomplete; suggestions as they type come from a separate provider (see\n * `useSuggestions`). This is the one place that owns the `AbortController`: each\n * search aborts the one before it, and an aborted request never changes state\n * or reaches the announcer. The provider itself keeps to the service's rate\n * limit.\n *\n * Announcements go through the app-wide announcer: the result count (or \"No\n * results\", or the error) once the search settles. An identical message is\n * not repeated for consecutive searches until the box has been emptied or\n * Retry is pressed.\n */\nexport function useSearch({ getBias }: UseSearchOptions = {}): UseSearch {\n const provider = useSearchProvider();\n const announce = useAnnounce();\n const providerRef = useLatestRef(provider);\n const announceRef = useLatestRef(announce);\n const messagesRef = useLatestRef(useMessages());\n const getBiasRef = useLatestRef(getBias);\n\n const [query, setQueryState] = useState(\"\");\n const [state, setState] = useState<SearchState>(IDLE);\n const stateRef = useLatestRef(state);\n const queryRef = useRef(\"\");\n const controller = useRef<AbortController | null>(null);\n const lastAnnounced = useRef<string | null>(null);\n\n const cancel = useCallback(() => {\n controller.current?.abort();\n controller.current = null;\n }, []);\n\n const announceOnce = useCallback(\n (message: Message, priority: \"polite\" | \"assertive\") => {\n // The same outcome, by key and parameters, is said once.\n const outcome = JSON.stringify(message);\n if (outcome === lastAnnounced.current) {\n return;\n }\n lastAnnounced.current = outcome;\n announceRef.current(message, { priority });\n },\n [announceRef],\n );\n\n const showResults = useCallback(\n (results: readonly SearchResult[], message: Message) => {\n setState({ status: \"results\", results });\n announceOnce(message, \"polite\");\n },\n [announceOnce],\n );\n\n const run = useCallback(\n async (text: string) => {\n controller.current?.abort();\n const coordinates = coordinateSearchResult(text, messagesRef.current);\n if (coordinates !== null) {\n controller.current = null;\n showResults([coordinates], announceCoordinateResult(coordinates.label));\n return;\n }\n const own = new AbortController();\n controller.current = own;\n setState({ status: \"loading\" });\n try {\n const results = await providerRef.current.search(text, {\n bias: getBiasRef.current?.(),\n signal: own.signal,\n });\n if (own.signal.aborted) {\n return;\n }\n if (results.length === 0) {\n setState({ status: \"empty\" });\n announceOnce(announceNoResults(), \"polite\");\n } else {\n showResults(results, announceSearchResults(results.length));\n }\n } catch (error) {\n if (own.signal.aborted || error instanceof PortAbortError) {\n return;\n }\n const kind: SearchErrorKind =\n error instanceof SearchError ? error.kind : \"failed\";\n setState({ status: \"error\", kind });\n announceOnce(announceSearchError(kind), \"assertive\");\n }\n },\n [providerRef, getBiasRef, messagesRef, announceOnce, showResults],\n );\n\n const setQuery = useCallback(\n (next: string) => {\n queryRef.current = next;\n setQueryState(next);\n cancel();\n if (next.trim().length < MIN_SEARCH_LENGTH) {\n lastAnnounced.current = null;\n }\n setState(IDLE);\n },\n [cancel],\n );\n\n const submit = useCallback(() => {\n const trimmed = queryRef.current.trim();\n if (trimmed.length < MIN_SEARCH_LENGTH) {\n return;\n }\n // Any state but idle or error belongs to this same text: setQuery and\n // settle are the only ways the text changes, and both return to idle.\n const status = stateRef.current.status;\n if (status !== \"idle\" && status !== \"error\") {\n return;\n }\n void run(trimmed);\n }, [run, stateRef]);\n\n const settle = useCallback(\n (next: string) => {\n queryRef.current = next;\n setQueryState(next);\n cancel();\n lastAnnounced.current = null;\n setState(IDLE);\n },\n [cancel],\n );\n\n const clear = useCallback(() => {\n settle(\"\");\n }, [settle]);\n\n const retry = useCallback(() => {\n const trimmed = queryRef.current.trim();\n if (trimmed.length < MIN_SEARCH_LENGTH) {\n return;\n }\n cancel();\n lastAnnounced.current = null;\n void run(trimmed);\n }, [cancel, run]);\n\n useEffect(() => cancel, [cancel]);\n\n return { query, state, setQuery, submit, settle, clear, retry };\n}\n"],"mappings":";;;;;;;;;;;AAyBA,IAAa,oBAAoB;AAsDjC,IAAM,OAAoB,EAAE,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;AAoB3C,SAAgB,UAAU,EAAE,YAA8B,CAAC,GAAc;CACvE,MAAM,WAAW,kBAAkB;CACnC,MAAM,WAAW,YAAY;CAC7B,MAAM,cAAc,aAAa,QAAQ;CACzC,MAAM,cAAc,aAAa,QAAQ;CACzC,MAAM,cAAc,aAAa,YAAY,CAAC;CAC9C,MAAM,aAAa,aAAa,OAAO;CAEvC,MAAM,CAAC,OAAO,iBAAiB,SAAS,EAAE;CAC1C,MAAM,CAAC,OAAO,YAAY,SAAsB,IAAI;CACpD,MAAM,WAAW,aAAa,KAAK;CACnC,MAAM,WAAW,OAAO,EAAE;CAC1B,MAAM,aAAa,OAA+B,IAAI;CACtD,MAAM,gBAAgB,OAAsB,IAAI;CAEhD,MAAM,SAAS,kBAAkB;EAC/B,WAAW,SAAS,MAAM;EAC1B,WAAW,UAAU;CACvB,GAAG,CAAC,CAAC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