@mapcairn/map 0.0.0-stage → 0.1.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +167 -2
- package/dist/chrome/Attribution/Attribution.js +304 -0
- package/dist/chrome/Attribution/Attribution.js.map +1 -0
- package/dist/chrome/Attribution/Attribution.styles.js +10 -0
- package/dist/chrome/Attribution/Attribution.styles.js.map +1 -0
- package/dist/chrome/Attribution/AttributionSkeleton.js +29 -0
- package/dist/chrome/Attribution/AttributionSkeleton.js.map +1 -0
- package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js +83 -0
- package/dist/chrome/ChromeSkeleton/ChromeSkeleton.js.map +1 -0
- package/dist/chrome/EndStack/EndStack.js +157 -0
- package/dist/chrome/EndStack/EndStack.js.map +1 -0
- package/dist/chrome/EndStack/EndStack.styles.js +12 -0
- package/dist/chrome/EndStack/EndStack.styles.js.map +1 -0
- package/dist/chrome/EndStack/EndStackSkeleton.js +78 -0
- package/dist/chrome/EndStack/EndStackSkeleton.js.map +1 -0
- package/dist/chrome/EndStack/endStackHeight.js +22 -0
- package/dist/chrome/EndStack/endStackHeight.js.map +1 -0
- package/dist/chrome/MapChrome/MapChrome.js +488 -0
- package/dist/chrome/MapChrome/MapChrome.js.map +1 -0
- package/dist/chrome/MapChrome/MapChrome.styles.js +15 -0
- package/dist/chrome/MapChrome/MapChrome.styles.js.map +1 -0
- package/dist/chrome/MapChrome/chromeSurface.js +18 -0
- package/dist/chrome/MapChrome/chromeSurface.js.map +1 -0
- package/dist/chrome/MapChrome/chromeVars.js +71 -0
- package/dist/chrome/MapChrome/chromeVars.js.map +1 -0
- package/dist/chrome/MapChrome/mapKeyPlacement.js +41 -0
- package/dist/chrome/MapChrome/mapKeyPlacement.js.map +1 -0
- package/dist/chrome/MapChrome/sharesWidth.js +13 -0
- package/dist/chrome/MapChrome/sharesWidth.js.map +1 -0
- package/dist/chrome/MapReadout/MapReadout.js +199 -0
- package/dist/chrome/MapReadout/MapReadout.js.map +1 -0
- package/dist/chrome/MapReadout/MapReadout.styles.js +14 -0
- package/dist/chrome/MapReadout/MapReadout.styles.js.map +1 -0
- package/dist/chrome/Sheet/Sheet.js +412 -0
- package/dist/chrome/Sheet/Sheet.js.map +1 -0
- package/dist/chrome/Sheet/Sheet.styles.js +14 -0
- package/dist/chrome/Sheet/Sheet.styles.js.map +1 -0
- package/dist/chrome/focusRegistry.js +76 -0
- package/dist/chrome/focusRegistry.js.map +1 -0
- package/dist/chrome/layoutContext.js +30 -0
- package/dist/chrome/layoutContext.js.map +1 -0
- package/dist/chrome/useScrollEdges.js +53 -0
- package/dist/chrome/useScrollEdges.js.map +1 -0
- package/dist/host/MapContext.js +16 -0
- package/dist/host/MapContext.js.map +1 -0
- package/dist/host/MapView.js +189 -0
- package/dist/host/MapView.js.map +1 -0
- package/dist/host/MapView.styles.js +16 -0
- package/dist/host/MapView.styles.js.map +1 -0
- package/dist/host/overlays/AccuracyCircle.js +36 -0
- package/dist/host/overlays/AccuracyCircle.js.map +1 -0
- package/dist/host/overlays/CentreCrosshair.js +40 -0
- package/dist/host/overlays/CentreCrosshair.js.map +1 -0
- package/dist/host/overlays/DrawOverlay.js +221 -0
- package/dist/host/overlays/DrawOverlay.js.map +1 -0
- package/dist/host/overlays/MapOverlayLayer.js +27 -0
- package/dist/host/overlays/MapOverlayLayer.js.map +1 -0
- package/dist/host/overlays/MeasureOverlay.js +87 -0
- package/dist/host/overlays/MeasureOverlay.js.map +1 -0
- package/dist/host/overlays/PinMarker.js +40 -0
- package/dist/host/overlays/PinMarker.js.map +1 -0
- package/dist/host/overlays/geometry.js +41 -0
- package/dist/host/overlays/geometry.js.map +1 -0
- package/dist/host/overlays/overlays.styles.js +27 -0
- package/dist/host/overlays/overlays.styles.js.map +1 -0
- package/dist/host/pointerTargets.js +22 -0
- package/dist/host/pointerTargets.js.map +1 -0
- package/dist/host/useLongPress.js +102 -0
- package/dist/host/useLongPress.js.map +1 -0
- package/dist/host/useMapEngine.js +352 -0
- package/dist/host/useMapEngine.js.map +1 -0
- package/dist/host/usePointerPosition.js +60 -0
- package/dist/host/usePointerPosition.js.map +1 -0
- package/dist/index.d.ts +3845 -0
- package/dist/index.js +89 -0
- package/dist/layers/CatalogueStatus.js +138 -0
- package/dist/layers/CatalogueStatus.js.map +1 -0
- package/dist/layers/DateTimeControl.js +101 -0
- package/dist/layers/DateTimeControl.js.map +1 -0
- package/dist/layers/FeatureCard.js +147 -0
- package/dist/layers/FeatureCard.js.map +1 -0
- package/dist/layers/FeatureChoices.js +101 -0
- package/dist/layers/FeatureChoices.js.map +1 -0
- package/dist/layers/FeatureGlyph.js +56 -0
- package/dist/layers/FeatureGlyph.js.map +1 -0
- package/dist/layers/IdentifyStatus.js +36 -0
- package/dist/layers/IdentifyStatus.js.map +1 -0
- package/dist/layers/LayerItem.js +321 -0
- package/dist/layers/LayerItem.js.map +1 -0
- package/dist/layers/LayerKey.js +36 -0
- package/dist/layers/LayerKey.js.map +1 -0
- package/dist/layers/Layers.styles.js +50 -0
- package/dist/layers/Layers.styles.js.map +1 -0
- package/dist/layers/LayersSection.js +267 -0
- package/dist/layers/LayersSection.js.map +1 -0
- package/dist/layers/MapDataLayers.js +261 -0
- package/dist/layers/MapDataLayers.js.map +1 -0
- package/dist/layers/MapKey.js +131 -0
- package/dist/layers/MapKey.js.map +1 -0
- package/dist/layers/MapKey.styles.js +16 -0
- package/dist/layers/MapKey.styles.js.map +1 -0
- package/dist/layers/MarkerGlyph.js +84 -0
- package/dist/layers/MarkerGlyph.js.map +1 -0
- package/dist/layers/SelectionProvider.js +27 -0
- package/dist/layers/SelectionProvider.js.map +1 -0
- package/dist/layers/ShapeGlyph.js +122 -0
- package/dist/layers/ShapeGlyph.js.map +1 -0
- package/dist/layers/TurnOffActions.js +147 -0
- package/dist/layers/TurnOffActions.js.map +1 -0
- package/dist/layers/answersTap.js +16 -0
- package/dist/layers/answersTap.js.map +1 -0
- package/dist/layers/catalogueNotice.js +65 -0
- package/dist/layers/catalogueNotice.js.map +1 -0
- package/dist/layers/catalogueReconcile.js +55 -0
- package/dist/layers/catalogueReconcile.js.map +1 -0
- package/dist/layers/catalogueView.js +32 -0
- package/dist/layers/catalogueView.js.map +1 -0
- package/dist/layers/featureTitle.js +14 -0
- package/dist/layers/featureTitle.js.map +1 -0
- package/dist/layers/identifyFeedback.js +30 -0
- package/dist/layers/identifyFeedback.js.map +1 -0
- package/dist/layers/identifyRun.js +148 -0
- package/dist/layers/identifyRun.js.map +1 -0
- package/dist/layers/layerStatus.js +13 -0
- package/dist/layers/layerStatus.js.map +1 -0
- package/dist/layers/loadOutcome.js +107 -0
- package/dist/layers/loadOutcome.js.map +1 -0
- package/dist/layers/loadReport.js +33 -0
- package/dist/layers/loadReport.js.map +1 -0
- package/dist/layers/loadRequests.js +73 -0
- package/dist/layers/loadRequests.js.map +1 -0
- package/dist/layers/mapFeatures.js +307 -0
- package/dist/layers/mapFeatures.js.map +1 -0
- package/dist/layers/mapKeyBlocks.js +24 -0
- package/dist/layers/mapKeyBlocks.js.map +1 -0
- package/dist/layers/reveal.js +119 -0
- package/dist/layers/reveal.js.map +1 -0
- package/dist/layers/selectionMessages.js +53 -0
- package/dist/layers/selectionMessages.js.map +1 -0
- package/dist/layers/selectionResolve.js +111 -0
- package/dist/layers/selectionResolve.js.map +1 -0
- package/dist/layers/useDataLayers.js +940 -0
- package/dist/layers/useDataLayers.js.map +1 -0
- package/dist/layers/useFeatureSelection.js +179 -0
- package/dist/layers/useFeatureSelection.js.map +1 -0
- package/dist/layers/useScrolls.js +37 -0
- package/dist/layers/useScrolls.js.map +1 -0
- package/dist/panels/BasemapPicker/BasemapPicker.js +169 -0
- package/dist/panels/BasemapPicker/BasemapPicker.js.map +1 -0
- package/dist/panels/BasemapPicker/BasemapPicker.styles.js +42 -0
- package/dist/panels/BasemapPicker/BasemapPicker.styles.js.map +1 -0
- package/dist/panels/ExportSection/ExportSection.js +91 -0
- package/dist/panels/ExportSection/ExportSection.js.map +1 -0
- package/dist/panels/HelpSection/HelpSection.js +163 -0
- package/dist/panels/HelpSection/HelpSection.js.map +1 -0
- package/dist/panels/HelpSection/HelpSection.styles.js +9 -0
- package/dist/panels/HelpSection/HelpSection.styles.js.map +1 -0
- package/dist/panels/PinSection/PinSection.js +39 -0
- package/dist/panels/PinSection/PinSection.js.map +1 -0
- package/dist/panels/Section/Section.js +43 -0
- package/dist/panels/Section/Section.js.map +1 -0
- package/dist/panels/Section/Section.styles.js +13 -0
- package/dist/panels/Section/Section.styles.js.map +1 -0
- package/dist/panels/SettingsSection/LanguageField.js +126 -0
- package/dist/panels/SettingsSection/LanguageField.js.map +1 -0
- package/dist/panels/SettingsSection/SettingsSection.js +175 -0
- package/dist/panels/SettingsSection/SettingsSection.js.map +1 -0
- package/dist/panels/SettingsSection/SettingsSection.styles.js +9 -0
- package/dist/panels/SettingsSection/SettingsSection.styles.js.map +1 -0
- package/dist/panels/ShapesSection/ShapesSection.js +229 -0
- package/dist/panels/ShapesSection/ShapesSection.js.map +1 -0
- package/dist/panels/ShapesSection/ShapesSection.styles.js +7 -0
- package/dist/panels/ShapesSection/ShapesSection.styles.js.map +1 -0
- package/dist/panels/SheetContent/SheetContent.js +92 -0
- package/dist/panels/SheetContent/SheetContent.js.map +1 -0
- package/dist/panels/SheetContent/SheetContent.styles.js +6 -0
- package/dist/panels/SheetContent/SheetContent.styles.js.map +1 -0
- package/dist/services/ServicesProvider.js +42 -0
- package/dist/services/ServicesProvider.js.map +1 -0
- package/dist/services/activeMessages.js +140 -0
- package/dist/services/activeMessages.js.map +1 -0
- package/dist/services/basemapAvailability.js +78 -0
- package/dist/services/basemapAvailability.js.map +1 -0
- package/dist/services/englishMessages.js +10 -0
- package/dist/services/englishMessages.js.map +1 -0
- package/dist/services/hooks.js +214 -0
- package/dist/services/hooks.js.map +1 -0
- package/dist/styles.css +2866 -0
- package/dist/styles.css.d.ts +1 -0
- package/dist/tools/Directions/Directions.styles.js +25 -0
- package/dist/tools/Directions/Directions.styles.js.map +1 -0
- package/dist/tools/Directions/DirectionsOverlay.js +46 -0
- package/dist/tools/Directions/DirectionsOverlay.js.map +1 -0
- package/dist/tools/Directions/DirectionsPanel.js +428 -0
- package/dist/tools/Directions/DirectionsPanel.js.map +1 -0
- package/dist/tools/Directions/MapDirections.js +84 -0
- package/dist/tools/Directions/MapDirections.js.map +1 -0
- package/dist/tools/Directions/useDirections.js +226 -0
- package/dist/tools/Directions/useDirections.js.map +1 -0
- package/dist/tools/Directions/useFreeCentre.js +30 -0
- package/dist/tools/Directions/useFreeCentre.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawMapBindings.js +34 -0
- package/dist/tools/DrawToolbar/DrawMapBindings.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawToolbar.js +296 -0
- package/dist/tools/DrawToolbar/DrawToolbar.js.map +1 -0
- package/dist/tools/DrawToolbar/DrawToolbar.styles.js +21 -0
- package/dist/tools/DrawToolbar/DrawToolbar.styles.js.map +1 -0
- package/dist/tools/DrawToolbar/imageDrawing.js +24 -0
- package/dist/tools/DrawToolbar/imageDrawing.js.map +1 -0
- package/dist/tools/DrawToolbar/useDraw.js +543 -0
- package/dist/tools/DrawToolbar/useDraw.js.map +1 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.js +116 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.js.map +1 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js +12 -0
- package/dist/tools/MeasureToolbar/MeasureToolbar.styles.js.map +1 -0
- package/dist/tools/MeasureToolbar/useMeasure.js +75 -0
- package/dist/tools/MeasureToolbar/useMeasure.js.map +1 -0
- package/dist/tools/PinCard/PinCard.js +174 -0
- package/dist/tools/PinCard/PinCard.js.map +1 -0
- package/dist/tools/PinCard/PinCard.styles.js +16 -0
- package/dist/tools/PinCard/PinCard.styles.js.map +1 -0
- package/dist/tools/PinCard/useReverseAddress.js +77 -0
- package/dist/tools/PinCard/useReverseAddress.js.map +1 -0
- package/dist/tools/SearchPill/SearchPill.js +292 -0
- package/dist/tools/SearchPill/SearchPill.js.map +1 -0
- package/dist/tools/SearchPill/SearchPill.styles.js +16 -0
- package/dist/tools/SearchPill/SearchPill.styles.js.map +1 -0
- package/dist/tools/SearchPill/SearchPillSkeleton.js +41 -0
- package/dist/tools/SearchPill/SearchPillSkeleton.js.map +1 -0
- package/dist/tools/SearchPill/useSearch.js +143 -0
- package/dist/tools/SearchPill/useSearch.js.map +1 -0
- package/dist/tools/SearchPill/useSuggestions.js +105 -0
- package/dist/tools/SearchPill/useSuggestions.js.map +1 -0
- package/dist/tools/Tour/TourCard.js +156 -0
- package/dist/tools/Tour/TourCard.js.map +1 -0
- package/dist/tools/Tour/TourCard.styles.js +10 -0
- package/dist/tools/Tour/TourCard.styles.js.map +1 -0
- package/dist/tools/Tour/useTour.js +110 -0
- package/dist/tools/Tour/useTour.js.map +1 -0
- package/dist/tools/locate/useLocate.js +94 -0
- package/dist/tools/locate/useLocate.js.map +1 -0
- package/dist/ui/Button/Button.js +36 -0
- package/dist/ui/Button/Button.js.map +1 -0
- package/dist/ui/Button/Button.styles.js +17 -0
- package/dist/ui/Button/Button.styles.js.map +1 -0
- package/dist/ui/Chip/Chip.js +37 -0
- package/dist/ui/Chip/Chip.js.map +1 -0
- package/dist/ui/Chip/Chip.styles.js +29 -0
- package/dist/ui/Chip/Chip.styles.js.map +1 -0
- package/dist/ui/ControlGroup/ControlGroup.js +23 -0
- package/dist/ui/ControlGroup/ControlGroup.js.map +1 -0
- package/dist/ui/ControlGroup/ControlGroup.styles.js +6 -0
- package/dist/ui/ControlGroup/ControlGroup.styles.js.map +1 -0
- package/dist/ui/EmptyState/EmptyState.js +37 -0
- package/dist/ui/EmptyState/EmptyState.js.map +1 -0
- package/dist/ui/EmptyState/EmptyState.styles.js +10 -0
- package/dist/ui/EmptyState/EmptyState.styles.js.map +1 -0
- package/dist/ui/Icon/Icon.js +28 -0
- package/dist/ui/Icon/Icon.js.map +1 -0
- package/dist/ui/Icon/Icon.styles.js +8 -0
- package/dist/ui/Icon/Icon.styles.js.map +1 -0
- package/dist/ui/IconButton/IconButton.js +47 -0
- package/dist/ui/IconButton/IconButton.js.map +1 -0
- package/dist/ui/IconButton/IconButton.styles.js +27 -0
- package/dist/ui/IconButton/IconButton.styles.js.map +1 -0
- package/dist/ui/Isolate/Isolate.js +26 -0
- package/dist/ui/Isolate/Isolate.js.map +1 -0
- package/dist/ui/Isolate/fillSlots.js +27 -0
- package/dist/ui/Isolate/fillSlots.js.map +1 -0
- package/dist/ui/ListRow/ListRow.js +59 -0
- package/dist/ui/ListRow/ListRow.js.map +1 -0
- package/dist/ui/ListRow/ListRow.styles.js +30 -0
- package/dist/ui/ListRow/ListRow.styles.js.map +1 -0
- package/dist/ui/LiveRegion/LiveRegion.js +88 -0
- package/dist/ui/LiveRegion/LiveRegion.js.map +1 -0
- package/dist/ui/LiveRegion/announcer.js +114 -0
- package/dist/ui/LiveRegion/announcer.js.map +1 -0
- package/dist/ui/SegmentedControl/SegmentedControl.js +55 -0
- package/dist/ui/SegmentedControl/SegmentedControl.js.map +1 -0
- package/dist/ui/SegmentedControl/SegmentedControl.styles.js +9 -0
- package/dist/ui/SegmentedControl/SegmentedControl.styles.js.map +1 -0
- package/dist/ui/SkipLink/SkipLink.js +35 -0
- package/dist/ui/SkipLink/SkipLink.js.map +1 -0
- package/dist/ui/SkipLink/SkipLink.styles.js +6 -0
- package/dist/ui/SkipLink/SkipLink.styles.js.map +1 -0
- package/dist/ui/Slider/Slider.js +68 -0
- package/dist/ui/Slider/Slider.js.map +1 -0
- package/dist/ui/Slider/Slider.styles.js +13 -0
- package/dist/ui/Slider/Slider.styles.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessage.js +124 -0
- package/dist/ui/StatusMessage/StatusMessage.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessage.styles.js +28 -0
- package/dist/ui/StatusMessage/StatusMessage.styles.js.map +1 -0
- package/dist/ui/StatusMessage/StatusMessageFocus.js +30 -0
- package/dist/ui/StatusMessage/StatusMessageFocus.js.map +1 -0
- package/dist/ui/Surface/Surface.js +22 -0
- package/dist/ui/Surface/Surface.js.map +1 -0
- package/dist/ui/Surface/Surface.styles.js +27 -0
- package/dist/ui/Surface/Surface.styles.js.map +1 -0
- package/dist/ui/Switch/Switch.js +58 -0
- package/dist/ui/Switch/Switch.js.map +1 -0
- package/dist/ui/Switch/Switch.styles.js +13 -0
- package/dist/ui/Switch/Switch.styles.js.map +1 -0
- package/dist/ui/Tooltip/Tooltip.js +66 -0
- package/dist/ui/Tooltip/Tooltip.js.map +1 -0
- package/dist/ui/Tooltip/Tooltip.styles.js +6 -0
- package/dist/ui/Tooltip/Tooltip.styles.js.map +1 -0
- package/dist/ui/Tooltip/inheritColours.js +27 -0
- package/dist/ui/Tooltip/inheritColours.js.map +1 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.js +16 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.js.map +1 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js +6 -0
- package/dist/ui/VisuallyHidden/VisuallyHidden.styles.js.map +1 -0
- package/package.json +82 -4
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** An identical message arriving within this window of the last is dropped. */
|
|
2
|
+
var DEDUPE_MS = 2e3;
|
|
3
|
+
function emptyChannel() {
|
|
4
|
+
return {
|
|
5
|
+
text: "",
|
|
6
|
+
lastMessage: null,
|
|
7
|
+
lastAcceptedAt: Number.NEGATIVE_INFINITY,
|
|
8
|
+
lastFlushedAt: Number.NEGATIVE_INFINITY,
|
|
9
|
+
queue: [],
|
|
10
|
+
throttleTimer: null,
|
|
11
|
+
clearTimer: null
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Builds the announcer behind `LiveRegionProvider`. Each priority has its own
|
|
16
|
+
* channel with three rules:
|
|
17
|
+
*
|
|
18
|
+
* - Throttle: at most one message per {@link THROTTLE_MS}. The first message
|
|
19
|
+
* after an idle window goes out at once. Messages that arrive inside the
|
|
20
|
+
* window wait for it to end, and a waiting message is replaced by a later one
|
|
21
|
+
* unless either is kept (`keep`). So a burst of updates is coalesced to the
|
|
22
|
+
* latest, and a kept message is never lost: it is spoken in its turn, one
|
|
23
|
+
* per window, in the order it arrived.
|
|
24
|
+
* - De-duplicate: the same message twice within {@link DEDUPE_MS} is read once.
|
|
25
|
+
* If the second is kept and the first still waits, the waiting one becomes
|
|
26
|
+
* kept, so a message that matters is not lost to the one that follows.
|
|
27
|
+
* - Clear then set: a region whose text would not change is emptied first, so
|
|
28
|
+
* a message repeated later is read again.
|
|
29
|
+
*/
|
|
30
|
+
function createAnnouncer({ setText, now = Date.now }) {
|
|
31
|
+
const channels = {
|
|
32
|
+
polite: emptyChannel(),
|
|
33
|
+
assertive: emptyChannel()
|
|
34
|
+
};
|
|
35
|
+
const show = (priority, message) => {
|
|
36
|
+
const channel = channels[priority];
|
|
37
|
+
if (channel.text !== message) {
|
|
38
|
+
channel.text = message;
|
|
39
|
+
setText(priority, message);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
channel.text = "";
|
|
43
|
+
setText(priority, "");
|
|
44
|
+
channel.clearTimer = setTimeout(() => {
|
|
45
|
+
channel.clearTimer = null;
|
|
46
|
+
channel.text = message;
|
|
47
|
+
setText(priority, message);
|
|
48
|
+
}, 50);
|
|
49
|
+
};
|
|
50
|
+
/** Speaks the oldest waiting message when the window allows, else waits for it to end. */
|
|
51
|
+
const schedule = (priority) => {
|
|
52
|
+
const channel = channels[priority];
|
|
53
|
+
const [head] = channel.queue;
|
|
54
|
+
if (head === void 0 || channel.throttleTimer !== null) return;
|
|
55
|
+
const wait = channel.lastFlushedAt + 600 - now();
|
|
56
|
+
if (wait > 0) {
|
|
57
|
+
channel.throttleTimer = setTimeout(() => {
|
|
58
|
+
channel.throttleTimer = null;
|
|
59
|
+
schedule(priority);
|
|
60
|
+
}, wait);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
channel.queue.shift();
|
|
64
|
+
channel.lastFlushedAt = now();
|
|
65
|
+
show(priority, head.message);
|
|
66
|
+
schedule(priority);
|
|
67
|
+
};
|
|
68
|
+
const announce = (message, options) => {
|
|
69
|
+
if (message.trim() === "") return;
|
|
70
|
+
const priority = options?.priority ?? "polite";
|
|
71
|
+
const channel = channels[priority];
|
|
72
|
+
const time = now();
|
|
73
|
+
const keep = options?.keep ?? false;
|
|
74
|
+
const tail = channel.queue.at(-1);
|
|
75
|
+
if (message === channel.lastMessage && time - channel.lastAcceptedAt < 2e3) {
|
|
76
|
+
if (keep && tail?.message === message) channel.queue[channel.queue.length - 1] = {
|
|
77
|
+
message,
|
|
78
|
+
keep
|
|
79
|
+
};
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
channel.lastMessage = message;
|
|
83
|
+
channel.lastAcceptedAt = time;
|
|
84
|
+
if (tail !== void 0 && !tail.keep && !keep) channel.queue[channel.queue.length - 1] = {
|
|
85
|
+
message,
|
|
86
|
+
keep
|
|
87
|
+
};
|
|
88
|
+
else channel.queue.push({
|
|
89
|
+
message,
|
|
90
|
+
keep
|
|
91
|
+
});
|
|
92
|
+
schedule(priority);
|
|
93
|
+
};
|
|
94
|
+
const dispose = () => {
|
|
95
|
+
for (const channel of Object.values(channels)) {
|
|
96
|
+
if (channel.throttleTimer !== null) {
|
|
97
|
+
clearTimeout(channel.throttleTimer);
|
|
98
|
+
channel.throttleTimer = null;
|
|
99
|
+
}
|
|
100
|
+
if (channel.clearTimer !== null) {
|
|
101
|
+
clearTimeout(channel.clearTimer);
|
|
102
|
+
channel.clearTimer = null;
|
|
103
|
+
}
|
|
104
|
+
channel.queue = [];
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
announce,
|
|
109
|
+
dispose
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
export { DEDUPE_MS, createAnnouncer };
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=announcer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announcer.js","names":[],"sources":["../../../src/ui/LiveRegion/announcer.ts"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { Message } from \"@mapcairn/core\";\n\n/** How urgently a message is read out. */\nexport type AnnouncePriority = \"polite\" | \"assertive\";\n\n/** Options for a single announcement. */\nexport interface AnnounceOptions {\n /** `polite` waits for the screen reader to finish; `assertive` interrupts. Defaults to `polite`. */\n readonly priority?: AnnouncePriority;\n /**\n * Speak this message even when others follow it closely. A message that is\n * not kept is replaced by a later one that arrives before the throttle\n * window ends, which suits a stream of updates. Set `keep` on a message that\n * reports the outcome of something the person did, so a later message does\n * not replace it. Kept messages wait their turn, one per window, in order.\n */\n readonly keep?: boolean;\n}\n\n/** Sends text to the announcer, which throttles and de-duplicates it as it is. */\nexport type AnnounceText = (message: string, options?: AnnounceOptions) => void;\n\n/**\n * Sends a message to the one app-wide announcer: text, or a {@link Message}\n * (a key and its parameters) that is formatted with the active catalogue\n * just before it is queued.\n */\nexport type Announce = (\n message: string | Message,\n options?: AnnounceOptions,\n) => void;\n\n/**\n * At most one message per priority is spoken in each window of this length.\n * Messages that are not kept and arrive inside it are coalesced to the latest;\n * kept messages queue.\n */\nexport const THROTTLE_MS = 600;\n/** An identical message arriving within this window of the last is dropped. */\nexport const DEDUPE_MS = 2000;\n/** How long a region stays empty before a repeated message is set again. */\nexport const CLEAR_MS = 50;\n\n/** A message waiting for the throttle window to end. */\ninterface Waiting {\n readonly message: string;\n readonly keep: boolean;\n}\n\n/** The mutable bookkeeping for one live region. */\ninterface Channel {\n /** What the region currently contains. */\n text: string;\n /** The last message accepted, for de-duplication. */\n lastMessage: string | null;\n lastAcceptedAt: number;\n lastFlushedAt: number;\n /** The messages waiting for the throttle window to end, oldest first. */\n queue: Waiting[];\n throttleTimer: ReturnType<typeof setTimeout> | null;\n clearTimer: ReturnType<typeof setTimeout> | null;\n}\n\n/** Callbacks `createAnnouncer` needs from its host. */\nexport interface AnnouncerHost {\n /** Writes the text of one live region. */\n readonly setText: (priority: AnnouncePriority, text: string) => void;\n /** The current time in milliseconds. Defaults to `Date.now`. */\n readonly now?: () => number;\n}\n\n/** The announcer: send messages, and stop its timers when the host unmounts. */\nexport interface Announcer {\n readonly announce: AnnounceText;\n /** Cancels timers. Safe to call more than once; the announcer still works afterwards. */\n readonly dispose: () => void;\n}\n\nfunction emptyChannel(): Channel {\n return {\n text: \"\",\n lastMessage: null,\n lastAcceptedAt: Number.NEGATIVE_INFINITY,\n lastFlushedAt: Number.NEGATIVE_INFINITY,\n queue: [],\n throttleTimer: null,\n clearTimer: null,\n };\n}\n\n/**\n * Builds the announcer behind `LiveRegionProvider`. Each priority has its own\n * channel with three rules:\n *\n * - Throttle: at most one message per {@link THROTTLE_MS}. The first message\n * after an idle window goes out at once. Messages that arrive inside the\n * window wait for it to end, and a waiting message is replaced by a later one\n * unless either is kept (`keep`). So a burst of updates is coalesced to the\n * latest, and a kept message is never lost: it is spoken in its turn, one\n * per window, in the order it arrived.\n * - De-duplicate: the same message twice within {@link DEDUPE_MS} is read once.\n * If the second is kept and the first still waits, the waiting one becomes\n * kept, so a message that matters is not lost to the one that follows.\n * - Clear then set: a region whose text would not change is emptied first, so\n * a message repeated later is read again.\n */\nexport function createAnnouncer({\n setText,\n now = Date.now,\n}: AnnouncerHost): Announcer {\n const channels: Record<AnnouncePriority, Channel> = {\n polite: emptyChannel(),\n assertive: emptyChannel(),\n };\n\n const show = (priority: AnnouncePriority, message: string) => {\n const channel = channels[priority];\n if (channel.text !== message) {\n channel.text = message;\n setText(priority, message);\n return;\n }\n channel.text = \"\";\n setText(priority, \"\");\n channel.clearTimer = setTimeout(() => {\n channel.clearTimer = null;\n channel.text = message;\n setText(priority, message);\n }, CLEAR_MS);\n };\n\n /** Speaks the oldest waiting message when the window allows, else waits for it to end. */\n const schedule = (priority: AnnouncePriority) => {\n const channel = channels[priority];\n const [head] = channel.queue;\n if (head === undefined || channel.throttleTimer !== null) {\n return;\n }\n const wait = channel.lastFlushedAt + THROTTLE_MS - now();\n if (wait > 0) {\n channel.throttleTimer = setTimeout(() => {\n channel.throttleTimer = null;\n schedule(priority);\n }, wait);\n return;\n }\n channel.queue.shift();\n channel.lastFlushedAt = now();\n show(priority, head.message);\n schedule(priority);\n };\n\n const announce: AnnounceText = (message, options) => {\n if (message.trim() === \"\") {\n return;\n }\n const priority = options?.priority ?? \"polite\";\n const channel = channels[priority];\n const time = now();\n const keep = options?.keep ?? false;\n const tail = channel.queue.at(-1);\n if (\n message === channel.lastMessage &&\n time - channel.lastAcceptedAt < DEDUPE_MS\n ) {\n if (keep && tail?.message === message) {\n channel.queue[channel.queue.length - 1] = { message, keep };\n }\n return;\n }\n channel.lastMessage = message;\n channel.lastAcceptedAt = time;\n if (tail !== undefined && !tail.keep && !keep) {\n channel.queue[channel.queue.length - 1] = { message, keep };\n } else {\n channel.queue.push({ message, keep });\n }\n schedule(priority);\n };\n\n const dispose = () => {\n for (const channel of Object.values(channels)) {\n if (channel.throttleTimer !== null) {\n clearTimeout(channel.throttleTimer);\n channel.throttleTimer = null;\n }\n if (channel.clearTimer !== null) {\n clearTimeout(channel.clearTimer);\n channel.clearTimer = null;\n }\n channel.queue = [];\n }\n };\n\n return { announce, dispose };\n}\n"],"mappings":";AAyCA,IAAa,YAAY;AAuCzB,SAAS,eAAwB;CAC/B,OAAO;EACL,MAAM;EACN,aAAa;EACb,gBAAgB,OAAO;EACvB,eAAe,OAAO;EACtB,OAAO,CAAC;EACR,eAAe;EACf,YAAY;CACd;AACF;;;;;;;;;;;;;;;;;AAkBA,SAAgB,gBAAgB,EAC9B,SACA,MAAM,KAAK,OACgB;CAC3B,MAAM,WAA8C;EAClD,QAAQ,aAAa;EACrB,WAAW,aAAa;CAC1B;CAEA,MAAM,QAAQ,UAA4B,YAAoB;EAC5D,MAAM,UAAU,SAAS;EACzB,IAAI,QAAQ,SAAS,SAAS;GAC5B,QAAQ,OAAO;GACf,QAAQ,UAAU,OAAO;GACzB;EACF;EACA,QAAQ,OAAO;EACf,QAAQ,UAAU,EAAE;EACpB,QAAQ,aAAa,iBAAiB;GACpC,QAAQ,aAAa;GACrB,QAAQ,OAAO;GACf,QAAQ,UAAU,OAAO;EAC3B,GAAA,EAAW;CACb;;CAGA,MAAM,YAAY,aAA+B;EAC/C,MAAM,UAAU,SAAS;EACzB,MAAM,CAAC,QAAQ,QAAQ;EACvB,IAAI,SAAS,KAAA,KAAa,QAAQ,kBAAkB,MAClD;EAEF,MAAM,OAAO,QAAQ,gBAAA,MAA8B,IAAI;EACvD,IAAI,OAAO,GAAG;GACZ,QAAQ,gBAAgB,iBAAiB;IACvC,QAAQ,gBAAgB;IACxB,SAAS,QAAQ;GACnB,GAAG,IAAI;GACP;EACF;EACA,QAAQ,MAAM,MAAM;EACpB,QAAQ,gBAAgB,IAAI;EAC5B,KAAK,UAAU,KAAK,OAAO;EAC3B,SAAS,QAAQ;CACnB;CAEA,MAAM,YAA0B,SAAS,YAAY;EACnD,IAAI,QAAQ,KAAK,MAAM,IACrB;EAEF,MAAM,WAAW,SAAS,YAAY;EACtC,MAAM,UAAU,SAAS;EACzB,MAAM,OAAO,IAAI;EACjB,MAAM,OAAO,SAAS,QAAQ;EAC9B,MAAM,OAAO,QAAQ,MAAM,GAAG,EAAE;EAChC,IACE,YAAY,QAAQ,eACpB,OAAO,QAAQ,iBAAA,KACf;GACA,IAAI,QAAQ,MAAM,YAAY,SAC5B,QAAQ,MAAM,QAAQ,MAAM,SAAS,KAAK;IAAE;IAAS;GAAK;GAE5D;EACF;EACA,QAAQ,cAAc;EACtB,QAAQ,iBAAiB;EACzB,IAAI,SAAS,KAAA,KAAa,CAAC,KAAK,QAAQ,CAAC,MACvC,QAAQ,MAAM,QAAQ,MAAM,SAAS,KAAK;GAAE;GAAS;EAAK;OAE1D,QAAQ,MAAM,KAAK;GAAE;GAAS;EAAK,CAAC;EAEtC,SAAS,QAAQ;CACnB;CAEA,MAAM,gBAAgB;EACpB,KAAK,MAAM,WAAW,OAAO,OAAO,QAAQ,GAAG;GAC7C,IAAI,QAAQ,kBAAkB,MAAM;IAClC,aAAa,QAAQ,aAAa;IAClC,QAAQ,gBAAgB;GAC1B;GACA,IAAI,QAAQ,eAAe,MAAM;IAC/B,aAAa,QAAQ,UAAU;IAC/B,QAAQ,aAAa;GACvB;GACA,QAAQ,QAAQ,CAAC;EACnB;CACF;CAEA,OAAO;EAAE;EAAU;CAAQ;AAC7B"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { check, group, icon, item } from "./SegmentedControl.styles.js";
|
|
2
|
+
import { Check } from "lucide-react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useReadingDirection } from "@mapcairn/react";
|
|
5
|
+
import * as ToggleGroup from "@radix-ui/react-toggle-group";
|
|
6
|
+
// src/ui/SegmentedControl/SegmentedControl.tsx
|
|
7
|
+
/**
|
|
8
|
+
* A single-choice control that shows all options at once, built on the Radix
|
|
9
|
+
* ToggleGroup in single mode.
|
|
10
|
+
*
|
|
11
|
+
* Radix renders the group as a `radiogroup` and each item as a `radio`, which
|
|
12
|
+
* is the right semantics for a mutually exclusive choice. Focus moves between
|
|
13
|
+
* items with the arrow keys (one tab stop for the whole group) and Space or
|
|
14
|
+
* Enter chooses the focused item.
|
|
15
|
+
*
|
|
16
|
+
* Unlike a raw toggle group, the selection can never be cleared: pressing the
|
|
17
|
+
* active item again is ignored. The selected item is filled and shows a check
|
|
18
|
+
* mark, so selection never relies on colour alone.
|
|
19
|
+
*/
|
|
20
|
+
function SegmentedControl({ label, options, value, onValueChange, disabled = false, className, "data-testid": testId }) {
|
|
21
|
+
const direction = useReadingDirection();
|
|
22
|
+
return /* @__PURE__ */ jsx(ToggleGroup.Root, {
|
|
23
|
+
type: "single",
|
|
24
|
+
className: className ? `${group} ${className}` : group,
|
|
25
|
+
"aria-label": label,
|
|
26
|
+
value,
|
|
27
|
+
disabled,
|
|
28
|
+
dir: direction,
|
|
29
|
+
onValueChange: (next) => {
|
|
30
|
+
if (next) onValueChange(next);
|
|
31
|
+
},
|
|
32
|
+
"data-testid": testId,
|
|
33
|
+
children: options.map((option) => /* @__PURE__ */ jsxs(ToggleGroup.Item, {
|
|
34
|
+
className: item,
|
|
35
|
+
value: option.value,
|
|
36
|
+
lang: option.lang,
|
|
37
|
+
"data-testid": testId ? `${testId}-${option.value}` : void 0,
|
|
38
|
+
children: [
|
|
39
|
+
option.icon ? /* @__PURE__ */ jsx("span", {
|
|
40
|
+
className: icon,
|
|
41
|
+
"aria-hidden": "true",
|
|
42
|
+
children: option.icon
|
|
43
|
+
}) : null,
|
|
44
|
+
option.label,
|
|
45
|
+
option.value === value ? /* @__PURE__ */ jsx(Check, {
|
|
46
|
+
"aria-hidden": "true",
|
|
47
|
+
className: check
|
|
48
|
+
}) : null
|
|
49
|
+
]
|
|
50
|
+
}, option.value))
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export { SegmentedControl };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=SegmentedControl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SegmentedControl.js","names":["styles.group","styles.item","styles.icon","styles.check"],"sources":["../../../src/ui/SegmentedControl/SegmentedControl.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { useReadingDirection } from \"@mapcairn/react\";\nimport * as ToggleGroup from \"@radix-ui/react-toggle-group\";\nimport { Check } from \"lucide-react\";\nimport type { ReactNode } from \"react\";\nimport * as styles from \"./SegmentedControl.css\";\n\n/** One choice in a {@link SegmentedControl}. */\nexport interface SegmentedControlOption {\n /** The value reported through `onValueChange` when this item is chosen. */\n readonly value: string;\n /** The visible text, which is also the item's accessible name. */\n readonly label: string;\n /** Optional decorative icon shown before the label. It is hidden from assistive technology. */\n readonly icon?: ReactNode;\n /**\n * The BCP 47 language the label is written in, when it differs from the\n * page's, so assistive technology reads it in that language.\n */\n readonly lang?: string;\n}\n\n/** Props for {@link SegmentedControl}. */\nexport interface SegmentedControlProps {\n /** Accessible name of the group, for example \"Theme\". Required. */\n readonly label: string;\n /** The choices, in display order. */\n readonly options: readonly SegmentedControlOption[];\n /** The selected value. The component is controlled and always has a selection. */\n readonly value: string;\n /** Called with the new value when the user picks a different item. */\n readonly onValueChange: (value: string) => void;\n /** Stops every item from being chosen and dims the group. */\n readonly disabled?: boolean;\n /** Applied to the group element. */\n readonly className?: string;\n /** Applied to the group. Each item gets the same id plus `-` and its value. */\n readonly \"data-testid\"?: string;\n}\n\n/**\n * A single-choice control that shows all options at once, built on the Radix\n * ToggleGroup in single mode.\n *\n * Radix renders the group as a `radiogroup` and each item as a `radio`, which\n * is the right semantics for a mutually exclusive choice. Focus moves between\n * items with the arrow keys (one tab stop for the whole group) and Space or\n * Enter chooses the focused item.\n *\n * Unlike a raw toggle group, the selection can never be cleared: pressing the\n * active item again is ignored. The selected item is filled and shows a check\n * mark, so selection never relies on colour alone.\n */\nexport function SegmentedControl({\n label,\n options,\n value,\n onValueChange,\n disabled = false,\n className,\n \"data-testid\": testId,\n}: SegmentedControlProps) {\n const direction = useReadingDirection();\n return (\n <ToggleGroup.Root\n type=\"single\"\n className={className ? `${styles.group} ${className}` : styles.group}\n aria-label={label}\n value={value}\n disabled={disabled}\n dir={direction}\n onValueChange={(next) => {\n if (next) {\n onValueChange(next);\n }\n }}\n data-testid={testId}\n >\n {options.map((option) => (\n <ToggleGroup.Item\n key={option.value}\n className={styles.item}\n value={option.value}\n lang={option.lang}\n data-testid={testId ? `${testId}-${option.value}` : undefined}\n >\n {option.icon ? (\n <span className={styles.icon} aria-hidden=\"true\">\n {option.icon}\n </span>\n ) : null}\n {option.label}\n {option.value === value ? (\n <Check aria-hidden=\"true\" className={styles.check} />\n ) : null}\n </ToggleGroup.Item>\n ))}\n </ToggleGroup.Root>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,iBAAiB,EAC/B,OACA,SACA,OACA,eACA,WAAW,OACX,WACA,eAAe,UACS;CACxB,MAAM,YAAY,oBAAoB;CACtC,OACE,oBAAC,YAAY,MAAb;EACE,MAAK;EACL,WAAW,YAAY,GAAGA,MAAa,GAAG,cAAcA;EACxD,cAAY;EACL;EACG;EACV,KAAK;EACL,gBAAgB,SAAS;GACvB,IAAI,MACF,cAAc,IAAI;EAEtB;EACA,eAAa;EAEZ,UAAA,QAAQ,KAAK,WACZ,qBAAC,YAAY,MAAb;GAEE,WAAWC;GACX,OAAO,OAAO;GACd,MAAM,OAAO;GACb,eAAa,SAAS,GAAG,OAAO,GAAG,OAAO,UAAU,KAAA;GALtD,UAAA;IAOG,OAAO,OACN,oBAAC,QAAD;KAAM,WAAWC;KAAa,eAAY;KACvC,UAAA,OAAO;IACJ,CAAA,IACJ;IACH,OAAO;IACP,OAAO,UAAU,QAChB,oBAAC,OAAD;KAAO,eAAY;KAAO,WAAWC;IAAe,CAAA,IAClD;GACY;EAfX,GAAA,OAAO,KAeI,CACnB;CACe,CAAA;AAEtB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
// src/ui/SegmentedControl/SegmentedControl.css.ts
|
|
3
|
+
var group = "_16n9tpa0";
|
|
4
|
+
var item = "_16n9tpa1";
|
|
5
|
+
var icon = "_16n9tpa2";
|
|
6
|
+
var check = "_16n9tpa3";
|
|
7
|
+
export { check, group, icon, item };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=SegmentedControl.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SegmentedControl.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useOptionalMessages } from "../../services/hooks.js";
|
|
2
|
+
import { visuallyHidden } from "../VisuallyHidden/VisuallyHidden.styles.js";
|
|
3
|
+
import { skipLink } from "./SkipLink.styles.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
// src/ui/SkipLink/SkipLink.tsx
|
|
6
|
+
/**
|
|
7
|
+
* The first focusable element on the page. It is visually hidden (with the
|
|
8
|
+
* shared `visuallyHidden` class) until it receives focus, then shows with the
|
|
9
|
+
* focus ring. Activating it moves focus to the
|
|
10
|
+
* target, which must be focusable (for example a region with `tabIndex={-1}`).
|
|
11
|
+
* @remarks The native hash jump is only prevented when the target exists, so
|
|
12
|
+
* the link still works as an ordinary anchor if the target is missing.
|
|
13
|
+
*/
|
|
14
|
+
function SkipLink({ targetId, children, className, onClick, ...rest }) {
|
|
15
|
+
const { t } = useOptionalMessages();
|
|
16
|
+
const handleClick = (event) => {
|
|
17
|
+
onClick?.(event);
|
|
18
|
+
if (event.defaultPrevented) return;
|
|
19
|
+
const target = event.currentTarget.ownerDocument.getElementById(targetId);
|
|
20
|
+
if (target) {
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
target.focus();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return /* @__PURE__ */ jsx("a", {
|
|
26
|
+
...rest,
|
|
27
|
+
href: `#${targetId}`,
|
|
28
|
+
className: className ? `${visuallyHidden} ${skipLink} ${className}` : `${visuallyHidden} ${skipLink}`,
|
|
29
|
+
onClick: handleClick,
|
|
30
|
+
children: children ?? t("ui.skipToMap", {})
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export { SkipLink };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=SkipLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SkipLink.js","names":[],"sources":["../../../src/ui/SkipLink/SkipLink.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { AnchorHTMLAttributes, MouseEvent, ReactNode } from \"react\";\nimport { useOptionalMessages } from \"../../services\";\nimport { visuallyHidden } from \"../VisuallyHidden/VisuallyHidden.css\";\nimport { skipLink } from \"./SkipLink.css\";\n\n/** Props for {@link SkipLink}. */\nexport interface SkipLinkProps\n extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, \"children\" | \"href\"> {\n /** The id of the element to move focus to. It must be focusable. */\n readonly targetId: string;\n /** The link text. Defaults to the catalogue's \"ui.skipToMap\". */\n readonly children?: ReactNode;\n}\n\n/**\n * The first focusable element on the page. It is visually hidden (with the\n * shared `visuallyHidden` class) until it receives focus, then shows with the\n * focus ring. Activating it moves focus to the\n * target, which must be focusable (for example a region with `tabIndex={-1}`).\n * @remarks The native hash jump is only prevented when the target exists, so\n * the link still works as an ordinary anchor if the target is missing.\n */\nexport function SkipLink({\n targetId,\n children,\n className,\n onClick,\n ...rest\n}: SkipLinkProps) {\n const { t } = useOptionalMessages();\n const handleClick = (event: MouseEvent<HTMLAnchorElement>) => {\n onClick?.(event);\n if (event.defaultPrevented) {\n return;\n }\n const target = event.currentTarget.ownerDocument.getElementById(targetId);\n if (target) {\n event.preventDefault();\n target.focus();\n }\n };\n return (\n <a\n {...rest}\n href={`#${targetId}`}\n className={\n className\n ? `${visuallyHidden} ${skipLink} ${className}`\n : `${visuallyHidden} ${skipLink}`\n }\n onClick={handleClick}\n >\n {children ?? t(\"ui.skipToMap\", {})}\n </a>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,SAAS,EACvB,UACA,UACA,WACA,SACA,GAAG,QACa;CAChB,MAAM,EAAE,MAAM,oBAAoB;CAClC,MAAM,eAAe,UAAyC;EAC5D,UAAU,KAAK;EACf,IAAI,MAAM,kBACR;EAEF,MAAM,SAAS,MAAM,cAAc,cAAc,eAAe,QAAQ;EACxE,IAAI,QAAQ;GACV,MAAM,eAAe;GACrB,OAAO,MAAM;EACf;CACF;CACA,OACE,oBAAC,KAAD;EACE,GAAI;EACJ,MAAM,IAAI;EACV,WACE,YACI,GAAG,eAAe,GAAG,SAAS,GAAG,cACjC,GAAG,eAAe,GAAG;EAE3B,SAAS;EAER,UAAA,YAAY,EAAE,gBAAgB,CAAC,CAAC;CAChC,CAAA;AAEP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SkipLink.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { control, header, label, root, thumb, thumbVisual, track, value } from "./Slider.styles.js";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { useReadingDirection } from "@mapcairn/react";
|
|
5
|
+
import * as RadixSlider from "@radix-ui/react-slider";
|
|
6
|
+
// src/ui/Slider/Slider.tsx
|
|
7
|
+
/** The filled share of the track as a percentage, kept within 0 to 100. */
|
|
8
|
+
function fillPercent(value, min, max) {
|
|
9
|
+
if (max <= min) return 0;
|
|
10
|
+
const share = (value - min) / (max - min) * 100;
|
|
11
|
+
return Math.min(100, Math.max(0, share));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A single-thumb slider built on the Radix Slider primitive, with a visible
|
|
15
|
+
* label and a visible value readout.
|
|
16
|
+
*
|
|
17
|
+
* Radix provides the keyboard model (arrows, Home, End, PageUp and PageDown).
|
|
18
|
+
* The thumb is a 24px circle inside a 44px hit area. The value text is also
|
|
19
|
+
* exposed as `aria-valuetext`, so assistive technology hears the formatted
|
|
20
|
+
* value rather than the raw number.
|
|
21
|
+
*/
|
|
22
|
+
function Slider({ label: label$1, min, max, step, value: value$1, onValueChange, formatValue, disabled = false, className, "data-testid": testId }) {
|
|
23
|
+
const direction = useReadingDirection();
|
|
24
|
+
const labelId = useId();
|
|
25
|
+
const text = formatValue(value$1);
|
|
26
|
+
const fill = `${fillPercent(value$1, min, max)}%`;
|
|
27
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
28
|
+
className: className ? `${root} ${className}` : root,
|
|
29
|
+
"data-testid": testId,
|
|
30
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
31
|
+
className: header,
|
|
32
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
33
|
+
className: label,
|
|
34
|
+
id: labelId,
|
|
35
|
+
children: label$1
|
|
36
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
37
|
+
className: value,
|
|
38
|
+
"data-testid": testId ? `${testId}-value` : void 0,
|
|
39
|
+
children: text
|
|
40
|
+
})]
|
|
41
|
+
}), /* @__PURE__ */ jsxs(RadixSlider.Root, {
|
|
42
|
+
className: control,
|
|
43
|
+
min,
|
|
44
|
+
max,
|
|
45
|
+
step,
|
|
46
|
+
value: [value$1],
|
|
47
|
+
disabled,
|
|
48
|
+
dir: direction,
|
|
49
|
+
onValueChange: (next) => {
|
|
50
|
+
const [first] = next;
|
|
51
|
+
if (first !== void 0) onValueChange(first);
|
|
52
|
+
},
|
|
53
|
+
children: [/* @__PURE__ */ jsx(RadixSlider.Track, {
|
|
54
|
+
className: track,
|
|
55
|
+
style: { "--slider-fill": fill },
|
|
56
|
+
"data-testid": testId ? `${testId}-track` : void 0
|
|
57
|
+
}), /* @__PURE__ */ jsx(RadixSlider.Thumb, {
|
|
58
|
+
className: thumb,
|
|
59
|
+
"aria-labelledby": labelId,
|
|
60
|
+
"aria-valuetext": text,
|
|
61
|
+
children: /* @__PURE__ */ jsx("span", { className: thumbVisual })
|
|
62
|
+
})]
|
|
63
|
+
})]
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export { Slider };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=Slider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Slider.js","names":["value","styles.root","styles.header","styles.label","label","styles.value","styles.control","styles.track","styles.thumb","styles.thumbVisual"],"sources":["../../../src/ui/Slider/Slider.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { useReadingDirection } from \"@mapcairn/react\";\nimport * as RadixSlider from \"@radix-ui/react-slider\";\nimport { type CSSProperties, useId } from \"react\";\nimport * as styles from \"./Slider.css\";\n\n/** Props for {@link Slider}. */\nexport interface SliderProps {\n /** The visible label. Required: the slider is named by it. */\n readonly label: string;\n /** Lowest value. */\n readonly min: number;\n /** Highest value. */\n readonly max: number;\n /** Distance between allowed values. Arrow keys move by one step. */\n readonly step: number;\n /** The current value. The component is controlled. */\n readonly value: number;\n /** Called with the next value as the user drags or presses keys. */\n readonly onValueChange: (value: number) => void;\n /**\n * Turns a value into the text shown beside the label and announced as the\n * slider's aria-valuetext. For example, a percentage slider returns \"60%\"\n * for 60.\n */\n readonly formatValue: (value: number) => string;\n /** Stops the slider from changing and dims it. */\n readonly disabled?: boolean;\n /** Applied to the outer wrapper. */\n readonly className?: string;\n /**\n * Applied to the outer wrapper. The value readout gets the same id with a\n * `-value` suffix and the track a `-track` suffix.\n */\n readonly \"data-testid\"?: string;\n}\n\n/** The filled share of the track as a percentage, kept within 0 to 100. */\nfunction fillPercent(value: number, min: number, max: number): number {\n if (max <= min) {\n return 0;\n }\n const share = ((value - min) / (max - min)) * 100;\n return Math.min(100, Math.max(0, share));\n}\n\n/**\n * A single-thumb slider built on the Radix Slider primitive, with a visible\n * label and a visible value readout.\n *\n * Radix provides the keyboard model (arrows, Home, End, PageUp and PageDown).\n * The thumb is a 24px circle inside a 44px hit area. The value text is also\n * exposed as `aria-valuetext`, so assistive technology hears the formatted\n * value rather than the raw number.\n */\nexport function Slider({\n label,\n min,\n max,\n step,\n value,\n onValueChange,\n formatValue,\n disabled = false,\n className,\n \"data-testid\": testId,\n}: SliderProps) {\n const direction = useReadingDirection();\n const labelId = useId();\n const text = formatValue(value);\n const fill = `${fillPercent(value, min, max)}%`;\n return (\n <div\n className={className ? `${styles.root} ${className}` : styles.root}\n data-testid={testId}\n >\n <div className={styles.header}>\n <span className={styles.label} id={labelId}>\n {label}\n </span>\n <span\n className={styles.value}\n data-testid={testId ? `${testId}-value` : undefined}\n >\n {text}\n </span>\n </div>\n <RadixSlider.Root\n className={styles.control}\n min={min}\n max={max}\n step={step}\n value={[value]}\n disabled={disabled}\n dir={direction}\n onValueChange={(next) => {\n const [first] = next;\n if (first !== undefined) {\n onValueChange(first);\n }\n }}\n >\n <RadixSlider.Track\n className={styles.track}\n style={{ \"--slider-fill\": fill } as CSSProperties}\n data-testid={testId ? `${testId}-track` : undefined}\n />\n <RadixSlider.Thumb\n className={styles.thumb}\n aria-labelledby={labelId}\n aria-valuetext={text}\n >\n <span className={styles.thumbVisual} />\n </RadixSlider.Thumb>\n </RadixSlider.Root>\n </div>\n );\n}\n"],"mappings":";;;;;;;AAuCA,SAAS,YAAY,OAAe,KAAa,KAAqB;CACpE,IAAI,OAAO,KACT,OAAO;CAET,MAAM,SAAU,QAAQ,QAAQ,MAAM,OAAQ;CAC9C,OAAO,KAAK,IAAI,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC;AACzC;;;;;;;;;;AAWA,SAAgB,OAAO,EACrB,OAAA,SACA,KACA,KACA,MACA,OAAA,SACA,eACA,aACA,WAAW,OACX,WACA,eAAe,UACD;CACd,MAAM,YAAY,oBAAoB;CACtC,MAAM,UAAU,MAAM;CACtB,MAAM,OAAO,YAAYA,OAAK;CAC9B,MAAM,OAAO,GAAG,YAAYA,SAAO,KAAK,GAAG,EAAE;CAC7C,OACE,qBAAC,OAAD;EACE,WAAW,YAAY,GAAGC,KAAY,GAAG,cAAcA;EACvD,eAAa;EAFf,UAAA,CAIE,qBAAC,OAAD;GAAK,WAAWC;GAAhB,UAAA,CACE,oBAAC,QAAD;IAAM,WAAWC;IAAc,IAAI;IAChC,UAAAC;GACG,CAAA,GACN,oBAAC,QAAD;IACE,WAAWC;IACX,eAAa,SAAS,GAAG,OAAO,UAAU,KAAA;IAEzC,UAAA;GACG,CAAA,CACH;EACL,CAAA,GAAA,qBAAC,YAAY,MAAb;GACE,WAAWC;GACN;GACA;GACC;GACN,OAAO,CAACN,OAAK;GACH;GACV,KAAK;GACL,gBAAgB,SAAS;IACvB,MAAM,CAAC,SAAS;IAChB,IAAI,UAAU,KAAA,GACZ,cAAc,KAAK;GAEvB;GAbF,UAAA,CAeE,oBAAC,YAAY,OAAb;IACE,WAAWO;IACX,OAAO,EAAE,iBAAiB,KAAK;IAC/B,eAAa,SAAS,GAAG,OAAO,UAAU,KAAA;GAC3C,CAAA,GACD,oBAAC,YAAY,OAAb;IACE,WAAWC;IACX,mBAAiB;IACjB,kBAAgB;IAEhB,UAAA,oBAAC,QAAD,EAAM,WAAWC,YAAqB,CAAA;GACrB,CAAA,CACH;EACf,CAAA,CAAA;;AAET"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
// src/ui/Slider/Slider.css.ts
|
|
3
|
+
var root = "_1we10bg0";
|
|
4
|
+
var header = "_1we10bg1";
|
|
5
|
+
var label = "_1we10bg2";
|
|
6
|
+
var value = "_1we10bg3";
|
|
7
|
+
var control = "_1we10bg4";
|
|
8
|
+
var track = "_1we10bg5";
|
|
9
|
+
var thumb = "_1we10bg6";
|
|
10
|
+
var thumbVisual = "_1we10bg7";
|
|
11
|
+
export { control, header, label, root, thumb, thumbVisual, track, value };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=Slider.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Slider.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { useOptionalMessages } from "../../services/hooks.js";
|
|
2
|
+
import { Button } from "../Button/Button.js";
|
|
3
|
+
import { Icon } from "../Icon/Icon.js";
|
|
4
|
+
import { IconButton } from "../IconButton/IconButton.js";
|
|
5
|
+
import { Surface } from "../Surface/Surface.js";
|
|
6
|
+
import { controls, messageText, statusIcon, statusMessage } from "./StatusMessage.styles.js";
|
|
7
|
+
import { useStatusMessageFocusFallback } from "./StatusMessageFocus.js";
|
|
8
|
+
import { CircleCheck, Info, TriangleAlert, X } from "lucide-react";
|
|
9
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
10
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { useLatestRef } from "@mapcairn/react";
|
|
12
|
+
// src/ui/StatusMessage/StatusMessage.tsx
|
|
13
|
+
/** The shortest time a message that dismisses itself stays on screen. */
|
|
14
|
+
var MIN_AUTO_DISMISS_MS = 6e3;
|
|
15
|
+
var icons = {
|
|
16
|
+
info: Info,
|
|
17
|
+
success: CircleCheck,
|
|
18
|
+
error: TriangleAlert
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A toast or banner: an icon, text and a dismiss button, so the variant is
|
|
22
|
+
* never conveyed by colour alone. It is the one visible live region besides
|
|
23
|
+
* the hidden announcer: `role="status"` for info and success, `role="alert"`
|
|
24
|
+
* for errors. The role sits on the text only, so a screen reader never reads
|
|
25
|
+
* the Retry and Dismiss buttons as part of the message.
|
|
26
|
+
*
|
|
27
|
+
* When the message goes away while focus is inside it (Dismiss, or an
|
|
28
|
+
* action that ends the condition), focus returns to the element it came from,
|
|
29
|
+
* or to the stop a `StatusMessageFocusProvider` supplies (`MapView` supplies
|
|
30
|
+
* its map region) when that element is gone, cannot take focus or focus came
|
|
31
|
+
* from the page, so a keyboard person keeps their place. Without a provider
|
|
32
|
+
* focus is left where it is. Focus is left alone if it was elsewhere.
|
|
33
|
+
*
|
|
34
|
+
* Errors stay until dismissed. Other messages dismiss themselves after the
|
|
35
|
+
* delay, and the countdown pauses while the pointer is over the message or
|
|
36
|
+
* focus is inside it, then resumes with the time left.
|
|
37
|
+
*/
|
|
38
|
+
function StatusMessage({ variant, children, onDismiss, action, autoDismissMs = MIN_AUTO_DISMISS_MS, dismissLabel, className, ...rest }) {
|
|
39
|
+
const { t } = useOptionalMessages();
|
|
40
|
+
const [hovered, setHovered] = useState(false);
|
|
41
|
+
const [focused, setFocused] = useState(false);
|
|
42
|
+
const [ready, setReady] = useState(false);
|
|
43
|
+
const paused = hovered || focused;
|
|
44
|
+
const dismissRef = useLatestRef(onDismiss);
|
|
45
|
+
const focusInside = useRef(false);
|
|
46
|
+
const focusFallback = useStatusMessageFocusFallback();
|
|
47
|
+
const focusFallbackRef = useLatestRef(focusFallback);
|
|
48
|
+
const cameFrom = useRef(null);
|
|
49
|
+
const remaining = useRef(Math.max(autoDismissMs, MIN_AUTO_DISMISS_MS));
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
setReady(true);
|
|
52
|
+
}, []);
|
|
53
|
+
useLayoutEffect(() => () => {
|
|
54
|
+
if (!focusInside.current) return;
|
|
55
|
+
const origin = cameFrom.current;
|
|
56
|
+
origin?.focus();
|
|
57
|
+
if (origin && document.activeElement === origin) return;
|
|
58
|
+
focusFallbackRef.current?.();
|
|
59
|
+
}, [focusFallbackRef]);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (variant === "error" || paused) return;
|
|
62
|
+
const startedAt = Date.now();
|
|
63
|
+
const timer = setTimeout(() => dismissRef.current(), remaining.current);
|
|
64
|
+
return () => {
|
|
65
|
+
clearTimeout(timer);
|
|
66
|
+
remaining.current = Math.max(0, remaining.current - (Date.now() - startedAt));
|
|
67
|
+
};
|
|
68
|
+
}, [
|
|
69
|
+
variant,
|
|
70
|
+
paused,
|
|
71
|
+
dismissRef
|
|
72
|
+
]);
|
|
73
|
+
const handleFocus = (event) => {
|
|
74
|
+
if (event.relatedTarget instanceof HTMLElement) {
|
|
75
|
+
if (!event.currentTarget.contains(event.relatedTarget)) cameFrom.current = event.relatedTarget;
|
|
76
|
+
}
|
|
77
|
+
focusInside.current = true;
|
|
78
|
+
setFocused(true);
|
|
79
|
+
};
|
|
80
|
+
const handleBlur = (event) => {
|
|
81
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
82
|
+
focusInside.current = false;
|
|
83
|
+
setFocused(false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const classes = statusMessage({ variant });
|
|
87
|
+
return /* @__PURE__ */ jsxs(Surface, {
|
|
88
|
+
...rest,
|
|
89
|
+
variant: "floating",
|
|
90
|
+
radius: "control",
|
|
91
|
+
className: className ? `${classes} ${className}` : classes,
|
|
92
|
+
onMouseEnter: () => setHovered(true),
|
|
93
|
+
onMouseLeave: () => setHovered(false),
|
|
94
|
+
onFocus: handleFocus,
|
|
95
|
+
onBlur: handleBlur,
|
|
96
|
+
children: [
|
|
97
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
98
|
+
icon: icons[variant],
|
|
99
|
+
className: statusIcon({ variant })
|
|
100
|
+
}),
|
|
101
|
+
/* @__PURE__ */ jsx("div", {
|
|
102
|
+
role: variant === "error" ? "alert" : "status",
|
|
103
|
+
className: messageText,
|
|
104
|
+
children: ready ? children : null
|
|
105
|
+
}),
|
|
106
|
+
/* @__PURE__ */ jsxs("div", {
|
|
107
|
+
className: controls,
|
|
108
|
+
children: [action ? /* @__PURE__ */ jsx(Button, {
|
|
109
|
+
variant: "quiet",
|
|
110
|
+
onClick: action.onClick,
|
|
111
|
+
children: action.label
|
|
112
|
+
}) : null, /* @__PURE__ */ jsx(IconButton, {
|
|
113
|
+
label: dismissLabel ?? t("ui.dismiss", {}),
|
|
114
|
+
icon: X,
|
|
115
|
+
size: "compact",
|
|
116
|
+
onClick: onDismiss
|
|
117
|
+
})]
|
|
118
|
+
})
|
|
119
|
+
]
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
export { StatusMessage };
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=StatusMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatusMessage.js","names":[],"sources":["../../../src/ui/StatusMessage/StatusMessage.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { useLatestRef } from \"@mapcairn/react\";\nimport { CircleCheck, Info, TriangleAlert, X } from \"lucide-react\";\nimport {\n type FocusEvent,\n type HTMLAttributes,\n type ReactNode,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { useOptionalMessages } from \"../../services\";\nimport { Button } from \"../Button\";\nimport { Icon, type IconComponent } from \"../Icon\";\nimport { IconButton } from \"../IconButton\";\nimport { Surface } from \"../Surface\";\nimport {\n controls,\n messageText,\n statusIcon,\n statusMessage,\n} from \"./StatusMessage.css\";\nimport { useStatusMessageFocusFallback } from \"./StatusMessageFocus\";\n\n/** The shortest time a message that dismisses itself stays on screen. */\nconst MIN_AUTO_DISMISS_MS = 6000;\n\nconst icons: Record<StatusMessageVariant, IconComponent> = {\n info: Info,\n success: CircleCheck,\n error: TriangleAlert,\n};\n\n/** The kind of message. Errors never dismiss themselves. */\nexport type StatusMessageVariant = \"info\" | \"success\" | \"error\";\n\n/** Props for {@link StatusMessage}. */\nexport interface StatusMessageProps\n extends Omit<\n HTMLAttributes<HTMLDivElement>,\n \"children\" | \"onBlur\" | \"onFocus\" | \"onMouseEnter\" | \"onMouseLeave\" | \"role\"\n > {\n /** `info` and `success` are polite status messages; `error` is an alert. */\n readonly variant: StatusMessageVariant;\n /** The message text. Keep it short and specific. */\n readonly children: ReactNode;\n /** Called when the person dismisses the message, and when it times out. */\n readonly onDismiss: () => void;\n /** An optional action, such as \"Retry\". It does not dismiss the message. */\n readonly action?: { readonly label: string; readonly onClick: () => void };\n /**\n * How long an `info` or `success` message stays before `onDismiss` is\n * called. Values under 6000 are raised to 6000. Ignored for errors.\n * Changing it after mount has no effect; remount with a `key` instead.\n */\n readonly autoDismissMs?: number;\n /** The accessible name of the dismiss button. Defaults to the catalogue's \"ui.dismiss\". */\n readonly dismissLabel?: string;\n}\n\n/**\n * A toast or banner: an icon, text and a dismiss button, so the variant is\n * never conveyed by colour alone. It is the one visible live region besides\n * the hidden announcer: `role=\"status\"` for info and success, `role=\"alert\"`\n * for errors. The role sits on the text only, so a screen reader never reads\n * the Retry and Dismiss buttons as part of the message.\n *\n * When the message goes away while focus is inside it (Dismiss, or an\n * action that ends the condition), focus returns to the element it came from,\n * or to the stop a `StatusMessageFocusProvider` supplies (`MapView` supplies\n * its map region) when that element is gone, cannot take focus or focus came\n * from the page, so a keyboard person keeps their place. Without a provider\n * focus is left where it is. Focus is left alone if it was elsewhere.\n *\n * Errors stay until dismissed. Other messages dismiss themselves after the\n * delay, and the countdown pauses while the pointer is over the message or\n * focus is inside it, then resumes with the time left.\n */\nexport function StatusMessage({\n variant,\n children,\n onDismiss,\n action,\n autoDismissMs = MIN_AUTO_DISMISS_MS,\n dismissLabel,\n className,\n ...rest\n}: StatusMessageProps) {\n const { t } = useOptionalMessages();\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const [ready, setReady] = useState(false);\n const paused = hovered || focused;\n const dismissRef = useLatestRef(onDismiss);\n const focusInside = useRef(false);\n const focusFallback = useStatusMessageFocusFallback();\n const focusFallbackRef = useLatestRef(focusFallback);\n const cameFrom = useRef<HTMLElement | null>(null);\n const remaining = useRef(Math.max(autoDismissMs, MIN_AUTO_DISMISS_MS));\n\n // A live region that already holds its text when inserted is often not\n // announced, so the role element mounts empty and is filled after mount.\n useEffect(() => {\n setReady(true);\n }, []);\n\n useLayoutEffect(\n () => () => {\n if (!focusInside.current) {\n return;\n }\n const origin = cameFrom.current;\n origin?.focus();\n if (origin && document.activeElement === origin) {\n return;\n }\n focusFallbackRef.current?.();\n },\n [focusFallbackRef],\n );\n\n useEffect(() => {\n if (variant === \"error\" || paused) {\n return;\n }\n const startedAt = Date.now();\n const timer = setTimeout(() => dismissRef.current(), remaining.current);\n return () => {\n clearTimeout(timer);\n remaining.current = Math.max(\n 0,\n remaining.current - (Date.now() - startedAt),\n );\n };\n }, [variant, paused, dismissRef]);\n\n const handleFocus = (event: FocusEvent<HTMLDivElement>) => {\n // A window or tab switch blurs and refocuses with no related target, which\n // must not forget the element focus really came from.\n if (event.relatedTarget instanceof HTMLElement) {\n if (!event.currentTarget.contains(event.relatedTarget)) {\n cameFrom.current = event.relatedTarget;\n }\n }\n focusInside.current = true;\n setFocused(true);\n };\n\n const handleBlur = (event: FocusEvent<HTMLDivElement>) => {\n if (!event.currentTarget.contains(event.relatedTarget)) {\n focusInside.current = false;\n setFocused(false);\n }\n };\n\n const classes = statusMessage({ variant });\n return (\n <Surface\n {...rest}\n variant=\"floating\"\n radius=\"control\"\n className={className ? `${classes} ${className}` : classes}\n onMouseEnter={() => setHovered(true)}\n onMouseLeave={() => setHovered(false)}\n onFocus={handleFocus}\n onBlur={handleBlur}\n >\n <Icon icon={icons[variant]} className={statusIcon({ variant })} />\n <div\n role={variant === \"error\" ? \"alert\" : \"status\"}\n className={messageText}\n >\n {ready ? children : null}\n </div>\n <div className={controls}>\n {action ? (\n <Button variant=\"quiet\" onClick={action.onClick}>\n {action.label}\n </Button>\n ) : null}\n <IconButton\n label={dismissLabel ?? t(\"ui.dismiss\", {})}\n icon={X}\n size=\"compact\"\n onClick={onDismiss}\n />\n </div>\n </Surface>\n );\n}\n"],"mappings":";;;;;;;;;;;;;AA2BA,IAAM,sBAAsB;AAE5B,IAAM,QAAqD;CACzD,MAAM;CACN,SAAS;CACT,OAAO;AACT;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,cAAc,EAC5B,SACA,UACA,WACA,QACA,gBAAgB,qBAChB,cACA,WACA,GAAG,QACkB;CACrB,MAAM,EAAE,MAAM,oBAAoB;CAClC,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,SAAS,cAAc,SAAS,KAAK;CAC5C,MAAM,CAAC,OAAO,YAAY,SAAS,KAAK;CACxC,MAAM,SAAS,WAAW;CAC1B,MAAM,aAAa,aAAa,SAAS;CACzC,MAAM,cAAc,OAAO,KAAK;CAChC,MAAM,gBAAgB,8BAA8B;CACpD,MAAM,mBAAmB,aAAa,aAAa;CACnD,MAAM,WAAW,OAA2B,IAAI;CAChD,MAAM,YAAY,OAAO,KAAK,IAAI,eAAe,mBAAmB,CAAC;CAIrE,gBAAgB;EACd,SAAS,IAAI;CACf,GAAG,CAAC,CAAC;CAEL,4BACc;EACV,IAAI,CAAC,YAAY,SACf;EAEF,MAAM,SAAS,SAAS;EACxB,QAAQ,MAAM;EACd,IAAI,UAAU,SAAS,kBAAkB,QACvC;EAEF,iBAAiB,UAAU;CAC7B,GACA,CAAC,gBAAgB,CACnB;CAEA,gBAAgB;EACd,IAAI,YAAY,WAAW,QACzB;EAEF,MAAM,YAAY,KAAK,IAAI;EAC3B,MAAM,QAAQ,iBAAiB,WAAW,QAAQ,GAAG,UAAU,OAAO;EACtE,aAAa;GACX,aAAa,KAAK;GAClB,UAAU,UAAU,KAAK,IACvB,GACA,UAAU,WAAW,KAAK,IAAI,IAAI,UACpC;EACF;CACF,GAAG;EAAC;EAAS;EAAQ;CAAU,CAAC;CAEhC,MAAM,eAAe,UAAsC;EAGzD,IAAI,MAAM,yBAAyB,aAC7B;OAAA,CAAC,MAAM,cAAc,SAAS,MAAM,aAAa,GACnD,SAAS,UAAU,MAAM;EAAA;EAG7B,YAAY,UAAU;EACtB,WAAW,IAAI;CACjB;CAEA,MAAM,cAAc,UAAsC;EACxD,IAAI,CAAC,MAAM,cAAc,SAAS,MAAM,aAAa,GAAG;GACtD,YAAY,UAAU;GACtB,WAAW,KAAK;EAClB;CACF;CAEA,MAAM,UAAU,cAAc,EAAE,QAAQ,CAAC;CACzC,OACE,qBAAC,SAAD;EACE,GAAI;EACJ,SAAQ;EACR,QAAO;EACP,WAAW,YAAY,GAAG,QAAQ,GAAG,cAAc;EACnD,oBAAoB,WAAW,IAAI;EACnC,oBAAoB,WAAW,KAAK;EACpC,SAAS;EACT,QAAQ;EARV,UAAA;GAUE,oBAAC,MAAD;IAAM,MAAM,MAAM;IAAU,WAAW,WAAW,EAAE,QAAQ,CAAC;GAAI,CAAA;GACjE,oBAAC,OAAD;IACE,MAAM,YAAY,UAAU,UAAU;IACtC,WAAW;IAEV,UAAA,QAAQ,WAAW;GACjB,CAAA;GACL,qBAAC,OAAD;IAAK,WAAW;IAAhB,UAAA,CACG,SACC,oBAAC,QAAD;KAAQ,SAAQ;KAAQ,SAAS,OAAO;KACrC,UAAA,OAAO;IACF,CAAA,IACN,MACJ,oBAAC,YAAD;KACE,OAAO,gBAAgB,EAAE,cAAc,CAAC,CAAC;KACzC,MAAM;KACN,MAAK;KACL,SAAS;IACV,CAAA,CACE;;EACE;;AAEb"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
3
|
+
// src/ui/StatusMessage/StatusMessage.css.ts
|
|
4
|
+
var statusMessage = createRuntimeFn({
|
|
5
|
+
defaultClassName: "euppkh0",
|
|
6
|
+
variantClassNames: { variant: {
|
|
7
|
+
info: "euppkh1",
|
|
8
|
+
success: "euppkh2",
|
|
9
|
+
error: "euppkh3"
|
|
10
|
+
} },
|
|
11
|
+
defaultVariants: { variant: "info" },
|
|
12
|
+
compoundVariants: []
|
|
13
|
+
});
|
|
14
|
+
var messageText = "euppkh4";
|
|
15
|
+
var statusIcon = createRuntimeFn({
|
|
16
|
+
defaultClassName: "euppkh5",
|
|
17
|
+
variantClassNames: { variant: {
|
|
18
|
+
info: "euppkh6",
|
|
19
|
+
success: "euppkh7",
|
|
20
|
+
error: "euppkh8"
|
|
21
|
+
} },
|
|
22
|
+
defaultVariants: {},
|
|
23
|
+
compoundVariants: []
|
|
24
|
+
});
|
|
25
|
+
var controls = "euppkh9";
|
|
26
|
+
export { controls, messageText, statusIcon, statusMessage };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=StatusMessage.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatusMessage.styles.js","names":[],"sources":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createContext, useCallback, useContext } from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useLatestRef } from "@mapcairn/react";
|
|
4
|
+
// src/ui/StatusMessage/StatusMessageFocus.tsx
|
|
5
|
+
var StatusMessageFocusContext = createContext(null);
|
|
6
|
+
/**
|
|
7
|
+
* Says where focus goes when a `StatusMessage` below it goes away and focus
|
|
8
|
+
* cannot return to where it came from. `MapView` supplies its own map region,
|
|
9
|
+
* so each map restores to itself; a host that renders messages without a
|
|
10
|
+
* `MapView` can supply its own stop. Without a provider, focus is left alone.
|
|
11
|
+
*/
|
|
12
|
+
function StatusMessageFocusProvider({ fallback, children }) {
|
|
13
|
+
const latest = useLatestRef(fallback);
|
|
14
|
+
const stable = useCallback(() => latest.current(), [latest]);
|
|
15
|
+
return /* @__PURE__ */ jsx(StatusMessageFocusContext.Provider, {
|
|
16
|
+
value: stable,
|
|
17
|
+
children
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The fallback focus function the nearest {@link StatusMessageFocusProvider}
|
|
22
|
+
* supplies, or null without one. Internal to `StatusMessage`, which calls it
|
|
23
|
+
* when it goes away with focus inside it; the package index does not export it.
|
|
24
|
+
*/
|
|
25
|
+
function useStatusMessageFocusFallback() {
|
|
26
|
+
return useContext(StatusMessageFocusContext);
|
|
27
|
+
}
|
|
28
|
+
export { StatusMessageFocusProvider, useStatusMessageFocusFallback };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=StatusMessageFocus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StatusMessageFocus.js","names":[],"sources":["../../../src/ui/StatusMessage/StatusMessageFocus.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport { useLatestRef } from \"@mapcairn/react\";\nimport { createContext, type ReactNode, useCallback, useContext } from \"react\";\n\n/** A function that moves focus to a stable stop. */\ntype FocusFallback = () => void;\n\nconst StatusMessageFocusContext = createContext<FocusFallback | null>(null);\n\n/** Props for {@link StatusMessageFocusProvider}. */\nexport interface StatusMessageFocusProviderProps {\n /**\n * Moves focus to a stable stop, such as the map region. A `StatusMessage`\n * below the provider calls it when it goes away with focus inside it and the\n * element focus came from cannot take focus. The latest function is used.\n */\n readonly fallback: () => void;\n readonly children: ReactNode;\n}\n\n/**\n * Says where focus goes when a `StatusMessage` below it goes away and focus\n * cannot return to where it came from. `MapView` supplies its own map region,\n * so each map restores to itself; a host that renders messages without a\n * `MapView` can supply its own stop. Without a provider, focus is left alone.\n */\nexport function StatusMessageFocusProvider({\n fallback,\n children,\n}: StatusMessageFocusProviderProps) {\n const latest = useLatestRef(fallback);\n const stable = useCallback(() => latest.current(), [latest]);\n return (\n <StatusMessageFocusContext.Provider value={stable}>\n {children}\n </StatusMessageFocusContext.Provider>\n );\n}\n\n/**\n * The fallback focus function the nearest {@link StatusMessageFocusProvider}\n * supplies, or null without one. Internal to `StatusMessage`, which calls it\n * when it goes away with focus inside it; the package index does not export it.\n */\nexport function useStatusMessageFocusFallback(): FocusFallback | null {\n return useContext(StatusMessageFocusContext);\n}\n"],"mappings":";;;;AAQA,IAAM,4BAA4B,cAAoC,IAAI;;;;;;;AAmB1E,SAAgB,2BAA2B,EACzC,UACA,YACkC;CAClC,MAAM,SAAS,aAAa,QAAQ;CACpC,MAAM,SAAS,kBAAkB,OAAO,QAAQ,GAAG,CAAC,MAAM,CAAC;CAC3D,OACE,oBAAC,0BAA0B,UAA3B;EAAoC,OAAO;EACxC;CACiC,CAAA;AAExC;;;;;;AAOA,SAAgB,gCAAsD;CACpE,OAAO,WAAW,yBAAyB;AAC7C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { surface } from "./Surface.styles.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/ui/Surface/Surface.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A translucent surface with backdrop blur, used by every floating control.
|
|
6
|
+
* Floating surfaces carry a shadow rather than a visible border.
|
|
7
|
+
* @remarks Pass `data-chrome` and `data-testid` straight through; a
|
|
8
|
+
* `section`, `aside` or `nav` needs an accessible name from the caller.
|
|
9
|
+
*/
|
|
10
|
+
function Surface({ as: Component = "div", variant = "floating", radius = "control", className, ...rest }) {
|
|
11
|
+
const classes = surface({
|
|
12
|
+
variant,
|
|
13
|
+
radius
|
|
14
|
+
});
|
|
15
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
16
|
+
...rest,
|
|
17
|
+
className: className ? `${classes} ${className}` : classes
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export { Surface };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=Surface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Surface.js","names":[],"sources":["../../../src/ui/Surface/Surface.tsx"],"sourcesContent":["// SPDX-License-Identifier: AGPL-3.0-only\n// Copyright MapCairn contributors\nimport type { HTMLAttributes } from \"react\";\nimport { surface } from \"./Surface.css\";\n\n/** Props for {@link Surface}. */\nexport interface SurfaceProps extends HTMLAttributes<HTMLElement> {\n /** The element to render. Defaults to `div`. */\n readonly as?: \"div\" | \"section\" | \"aside\" | \"nav\";\n /**\n * `floating` has the floating shadow, `raised` uses the raised surface\n * colour with no shadow, `flat` has neither. Defaults to `floating`.\n */\n readonly variant?: \"floating\" | \"raised\" | \"flat\";\n /** Corner radius role. Defaults to `control`. */\n readonly radius?: \"pill\" | \"control\" | \"sheet\";\n}\n\n/**\n * A translucent surface with backdrop blur, used by every floating control.\n * Floating surfaces carry a shadow rather than a visible border.\n * @remarks Pass `data-chrome` and `data-testid` straight through; a\n * `section`, `aside` or `nav` needs an accessible name from the caller.\n */\nexport function Surface({\n as: Component = \"div\",\n variant = \"floating\",\n radius = \"control\",\n className,\n ...rest\n}: SurfaceProps) {\n const classes = surface({ variant, radius });\n return (\n <Component\n {...rest}\n className={className ? `${classes} ${className}` : classes}\n />\n );\n}\n"],"mappings":";;;;;;;;;AAwBA,SAAgB,QAAQ,EACtB,IAAI,YAAY,OAChB,UAAU,YACV,SAAS,WACT,WACA,GAAG,QACY;CACf,MAAM,UAAU,QAAQ;EAAE;EAAS;CAAO,CAAC;CAC3C,OACE,oBAAC,WAAD;EACE,GAAI;EACJ,WAAW,YAAY,GAAG,QAAQ,GAAG,cAAc;CACpD,CAAA;AAEL"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* empty css */
|
|
2
|
+
/* empty css */
|
|
3
|
+
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
4
|
+
// src/ui/Surface/Surface.css.ts
|
|
5
|
+
var surface = createRuntimeFn({
|
|
6
|
+
defaultClassName: "_1qs0gc0",
|
|
7
|
+
variantClassNames: {
|
|
8
|
+
variant: {
|
|
9
|
+
floating: "_1qs0gc1",
|
|
10
|
+
raised: "_1qs0gc2",
|
|
11
|
+
flat: "_1qs0gc3"
|
|
12
|
+
},
|
|
13
|
+
radius: {
|
|
14
|
+
pill: "_1qs0gc4",
|
|
15
|
+
control: "_1qs0gc5",
|
|
16
|
+
sheet: "_1qs0gc6"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
defaultVariants: {
|
|
20
|
+
variant: "floating",
|
|
21
|
+
radius: "control"
|
|
22
|
+
},
|
|
23
|
+
compoundVariants: []
|
|
24
|
+
});
|
|
25
|
+
export { surface };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=Surface.styles.js.map
|