@krak-stack/registry 0.2.2 → 0.3.0
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/CHANGELOG.md +8 -6
- package/README.md +8 -0
- package/dist/components/ui/color-picker.js +2 -3
- package/dist/components/ui/data-table.js +18 -11
- package/dist/components/ui/effect-form.js +2 -2
- package/dist/components/ui/form.d.ts +5 -5
- package/dist/components/ui/form.js +2 -2
- package/dist/components/ui/icon-input.js +2 -2
- package/dist/components/ui/{google-map.d.ts → map-menu-map.d.ts} +3 -1
- package/dist/components/ui/map-menu.d.ts +75 -0
- package/dist/components/ui/map-menu.js +1027 -0
- package/dist/components/ui/stepper.d.ts +37 -0
- package/dist/components/ui/stepper.js +244 -0
- package/dist/components/ui/virtualized-combobox.js +2 -2
- package/dist/services/events/client/audit-log-table.js +18 -11
- package/dist/services/webhooks/client/delivery-table.js +18 -11
- package/package.json +8 -4
- package/dist/components/ui/google-map.js +0 -441
|
@@ -0,0 +1,1027 @@
|
|
|
1
|
+
// ../../src/components/ui/map-menu.tsx
|
|
2
|
+
import { Dialog as DialogPrimitive2 } from "@base-ui/react/dialog";
|
|
3
|
+
import { ChevronDown, LocateFixed as LocateFixed2, MapPin, Search, X } from "lucide-react";
|
|
4
|
+
import { useEffect as useEffect2, useId, useRef as useRef2, useState as useState2 } from "react";
|
|
5
|
+
|
|
6
|
+
// ../../src/components/ui/button.tsx
|
|
7
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
8
|
+
import { cva } from "class-variance-authority";
|
|
9
|
+
|
|
10
|
+
// ../../src/lib/utils.ts
|
|
11
|
+
import { cn } from "cn";
|
|
12
|
+
|
|
13
|
+
// ../../src/components/ui/button.tsx
|
|
14
|
+
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
var buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
|
|
16
|
+
variants: {
|
|
17
|
+
variant: {
|
|
18
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
19
|
+
outline: "border-border bg-background shadow-xs hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
20
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
21
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
22
|
+
destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
23
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
24
|
+
},
|
|
25
|
+
size: {
|
|
26
|
+
default: "h-9 gap-1.5 px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
27
|
+
xs: "h-6 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
28
|
+
sm: "h-8 gap-1 rounded-[min(var(--radius-md),10px)] px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
|
|
29
|
+
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
30
|
+
icon: "size-9",
|
|
31
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
32
|
+
"icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
|
|
33
|
+
"icon-lg": "size-10"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
defaultVariants: {
|
|
37
|
+
variant: "default",
|
|
38
|
+
size: "default"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
function Button({
|
|
42
|
+
className,
|
|
43
|
+
variant = "default",
|
|
44
|
+
size = "default",
|
|
45
|
+
...props
|
|
46
|
+
}) {
|
|
47
|
+
return /* @__PURE__ */ jsx(ButtonPrimitive, {
|
|
48
|
+
"data-slot": "button",
|
|
49
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
50
|
+
...props
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ../../src/components/ui/dialog.tsx
|
|
55
|
+
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
|
|
56
|
+
import { XIcon } from "lucide-react";
|
|
57
|
+
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
58
|
+
function Dialog({ ...props }) {
|
|
59
|
+
return /* @__PURE__ */ jsx2(DialogPrimitive.Root, {
|
|
60
|
+
"data-slot": "dialog",
|
|
61
|
+
...props
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function DialogPortal({ ...props }) {
|
|
65
|
+
return /* @__PURE__ */ jsx2(DialogPrimitive.Portal, {
|
|
66
|
+
"data-slot": "dialog-portal",
|
|
67
|
+
...props
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function DialogOverlay({
|
|
71
|
+
className,
|
|
72
|
+
...props
|
|
73
|
+
}) {
|
|
74
|
+
return /* @__PURE__ */ jsx2(DialogPrimitive.Backdrop, {
|
|
75
|
+
"data-slot": "dialog-overlay",
|
|
76
|
+
className: cn("fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0", className),
|
|
77
|
+
...props
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function DialogHeader({ className, ...props }) {
|
|
81
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
82
|
+
"data-slot": "dialog-header",
|
|
83
|
+
className: cn("grid gap-1.5", className),
|
|
84
|
+
...props
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function DialogFooter({ className, ...props }) {
|
|
88
|
+
return /* @__PURE__ */ jsx2("div", {
|
|
89
|
+
"data-slot": "dialog-footer",
|
|
90
|
+
className: cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className),
|
|
91
|
+
...props
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function DialogTitle({
|
|
95
|
+
className,
|
|
96
|
+
...props
|
|
97
|
+
}) {
|
|
98
|
+
return /* @__PURE__ */ jsx2(DialogPrimitive.Title, {
|
|
99
|
+
"data-slot": "dialog-title",
|
|
100
|
+
className: cn("text-lg font-medium", className),
|
|
101
|
+
...props
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// ../../src/components/ui/map-menu-map.tsx
|
|
106
|
+
import { LocateFixed, Minus, Plus } from "lucide-react";
|
|
107
|
+
import { useEffect, useEffectEvent, useRef, useState, useSyncExternalStore } from "react";
|
|
108
|
+
import { Schema } from "effect";
|
|
109
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
110
|
+
import { jsx as jsx3, jsxs as jsxs2, Fragment } from "react/jsx-runtime";
|
|
111
|
+
var googleMapsScriptId = "krak-stack-google-maps-script";
|
|
112
|
+
var googleMapsCallbackName = "__krakStackGoogleMapsInit";
|
|
113
|
+
var googleMapsPromise;
|
|
114
|
+
var defaultMessages = {
|
|
115
|
+
en: {
|
|
116
|
+
mapLabel: "Google map",
|
|
117
|
+
loading: "Loading map...",
|
|
118
|
+
missingKeyTitle: "Map unavailable",
|
|
119
|
+
missingKeyBody: "Provide a Google Maps API key to display the map.",
|
|
120
|
+
errorTitle: "Map unavailable",
|
|
121
|
+
errorBody: "Google Maps could not be loaded. Try again later.",
|
|
122
|
+
zoomIn: "Zoom in",
|
|
123
|
+
zoomOut: "Zoom out",
|
|
124
|
+
showArea: "Show selected area"
|
|
125
|
+
},
|
|
126
|
+
fr: {
|
|
127
|
+
mapLabel: "Carte Google",
|
|
128
|
+
loading: "Chargement de la carte...",
|
|
129
|
+
missingKeyTitle: "Carte indisponible",
|
|
130
|
+
missingKeyBody: "Fournissez une clé d’API Google Maps pour afficher la carte.",
|
|
131
|
+
errorTitle: "Carte indisponible",
|
|
132
|
+
errorBody: "Impossible de charger Google Maps. Réessayez plus tard.",
|
|
133
|
+
zoomIn: "Zoom avant",
|
|
134
|
+
zoomOut: "Zoom arrière",
|
|
135
|
+
showArea: "Afficher la zone sélectionnée"
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var googleMapMessages = (locale, translations) => ({
|
|
139
|
+
...locale.startsWith("fr") ? defaultMessages.fr : defaultMessages.en,
|
|
140
|
+
...translations?.[locale.split("-")[0] ?? locale],
|
|
141
|
+
...translations?.[locale]
|
|
142
|
+
});
|
|
143
|
+
var isGoogleMapsReady = (api) => Boolean(api?.maps.Map && api.maps.Marker && api.maps.Circle && api.maps.event);
|
|
144
|
+
var loadGoogleMaps = (apiKey) => {
|
|
145
|
+
if (!globalThis.window || !globalThis.document) {
|
|
146
|
+
return Promise.reject(new Error("Google Maps requires a browser."));
|
|
147
|
+
}
|
|
148
|
+
const browserWindow = window;
|
|
149
|
+
if (isGoogleMapsReady(browserWindow.google)) {
|
|
150
|
+
return Promise.resolve(browserWindow.google);
|
|
151
|
+
}
|
|
152
|
+
if (googleMapsPromise)
|
|
153
|
+
return googleMapsPromise;
|
|
154
|
+
googleMapsPromise = new Promise((resolve, reject) => {
|
|
155
|
+
const resolveApi = () => {
|
|
156
|
+
if (isGoogleMapsReady(browserWindow.google)) {
|
|
157
|
+
resolve(browserWindow.google);
|
|
158
|
+
} else
|
|
159
|
+
reject(new Error("Google Maps failed to initialize."));
|
|
160
|
+
};
|
|
161
|
+
const rejectLoad = () => reject(new Error("Google Maps failed to load."));
|
|
162
|
+
browserWindow.__krakStackGoogleMapsInit = resolveApi;
|
|
163
|
+
const existingScript = document.getElementById(googleMapsScriptId);
|
|
164
|
+
if (existingScript) {
|
|
165
|
+
existingScript.addEventListener("error", rejectLoad, { once: true });
|
|
166
|
+
existingScript.addEventListener("load", resolveApi, { once: true });
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const script = document.createElement("script");
|
|
170
|
+
script.id = googleMapsScriptId;
|
|
171
|
+
script.async = true;
|
|
172
|
+
script.src = `https://maps.googleapis.com/maps/api/js?key=${encodeURIComponent(apiKey)}&loading=async&callback=${googleMapsCallbackName}`;
|
|
173
|
+
script.addEventListener("error", rejectLoad, { once: true });
|
|
174
|
+
document.head.append(script);
|
|
175
|
+
}).catch((error) => {
|
|
176
|
+
googleMapsPromise = undefined;
|
|
177
|
+
browserWindow.__krakStackGoogleMapsInit = undefined;
|
|
178
|
+
document.getElementById(googleMapsScriptId)?.remove();
|
|
179
|
+
throw error;
|
|
180
|
+
});
|
|
181
|
+
return googleMapsPromise;
|
|
182
|
+
};
|
|
183
|
+
var clampZoom = (zoom, minZoom, maxZoom) => Math.min(maxZoom, Math.max(minZoom, zoom));
|
|
184
|
+
var mapOptions = (center, zoom, interactive, minZoom, maxZoom) => ({
|
|
185
|
+
center,
|
|
186
|
+
zoom: clampZoom(zoom, minZoom, maxZoom),
|
|
187
|
+
clickableIcons: interactive,
|
|
188
|
+
disableDefaultUI: true,
|
|
189
|
+
draggable: interactive,
|
|
190
|
+
fullscreenControl: false,
|
|
191
|
+
gestureHandling: interactive ? "auto" : "none",
|
|
192
|
+
keyboardShortcuts: interactive,
|
|
193
|
+
mapTypeControl: false,
|
|
194
|
+
maxZoom,
|
|
195
|
+
minZoom,
|
|
196
|
+
scrollwheel: interactive,
|
|
197
|
+
streetViewControl: false,
|
|
198
|
+
zoomControl: false
|
|
199
|
+
});
|
|
200
|
+
var createMapState = (loadState, currentZoom) => {
|
|
201
|
+
let snapshot = { loadState, currentZoom };
|
|
202
|
+
const listeners = new Set;
|
|
203
|
+
const update = (next) => {
|
|
204
|
+
if (next.loadState === snapshot.loadState && next.currentZoom === snapshot.currentZoom)
|
|
205
|
+
return;
|
|
206
|
+
snapshot = next;
|
|
207
|
+
for (const listener of listeners)
|
|
208
|
+
listener();
|
|
209
|
+
};
|
|
210
|
+
return {
|
|
211
|
+
getSnapshot: () => snapshot,
|
|
212
|
+
subscribe: (listener) => {
|
|
213
|
+
listeners.add(listener);
|
|
214
|
+
return () => {
|
|
215
|
+
listeners.delete(listener);
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
setLoadState: (loadState) => update({ ...snapshot, loadState }),
|
|
219
|
+
setCurrentZoom: (currentZoom) => update({ ...snapshot, currentZoom })
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
var MapMenuMap = ({
|
|
223
|
+
apiKey,
|
|
224
|
+
center,
|
|
225
|
+
zoom,
|
|
226
|
+
marker,
|
|
227
|
+
radius,
|
|
228
|
+
interactive = true,
|
|
229
|
+
zoomControls = true,
|
|
230
|
+
fitRadius = false,
|
|
231
|
+
fitPadding = 32,
|
|
232
|
+
minZoom = 3,
|
|
233
|
+
maxZoom = 20,
|
|
234
|
+
className,
|
|
235
|
+
controlsClassName,
|
|
236
|
+
messages: messageOverrides,
|
|
237
|
+
locale: localeOverride
|
|
238
|
+
}) => {
|
|
239
|
+
const locale = useKrakstackLocale(localeOverride);
|
|
240
|
+
const mapElementRef = useRef(null);
|
|
241
|
+
const apiRef = useRef(null);
|
|
242
|
+
const mapRef = useRef(null);
|
|
243
|
+
const markerRef = useRef(null);
|
|
244
|
+
const circleRef = useRef(null);
|
|
245
|
+
const zoomListenerRef = useRef(null);
|
|
246
|
+
const normalizedApiKey = apiKey.trim();
|
|
247
|
+
const normalizedMinZoom = Math.min(minZoom, maxZoom);
|
|
248
|
+
const normalizedMaxZoom = Math.max(minZoom, maxZoom);
|
|
249
|
+
const initialZoom = clampZoom(zoom, normalizedMinZoom, normalizedMaxZoom);
|
|
250
|
+
const [mapState] = useState(() => createMapState(normalizedApiKey ? "loading" : "missing-key", initialZoom));
|
|
251
|
+
const { loadState, currentZoom } = useSyncExternalStore(mapState.subscribe, mapState.getSnapshot, mapState.getSnapshot);
|
|
252
|
+
const { setLoadState, setCurrentZoom } = mapState;
|
|
253
|
+
const labels = googleMapMessages(locale, messageOverrides);
|
|
254
|
+
const markerOptions = Schema.is(Schema.Struct({ icon: Schema.optional(Schema.String) }))(marker) ? marker : undefined;
|
|
255
|
+
const markerEnabled = marker === true || markerOptions !== undefined;
|
|
256
|
+
const markerIcon = markerOptions?.icon;
|
|
257
|
+
const centerLat = center.lat;
|
|
258
|
+
const centerLng = center.lng;
|
|
259
|
+
const radiusMeters = radius?.radiusMeters;
|
|
260
|
+
const radiusFillColor = radius?.fillColor;
|
|
261
|
+
const radiusFillOpacity = radius?.fillOpacity;
|
|
262
|
+
const radiusStrokeColor = radius?.strokeColor;
|
|
263
|
+
const radiusStrokeOpacity = radius?.strokeOpacity;
|
|
264
|
+
const radiusStrokeWeight = radius?.strokeWeight;
|
|
265
|
+
const showSelectedArea = () => {
|
|
266
|
+
try {
|
|
267
|
+
const element = mapElementRef.current;
|
|
268
|
+
const bounds = circleRef.current?.getBounds()?.toJSON();
|
|
269
|
+
if (!element?.clientWidth || !element.clientHeight || !bounds)
|
|
270
|
+
return;
|
|
271
|
+
mapRef.current?.fitBounds(bounds, Math.max(0, fitPadding));
|
|
272
|
+
} catch {
|
|
273
|
+
setLoadState("error");
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
const fitSelection = useEffectEvent(showSelectedArea);
|
|
277
|
+
const initializeMap = useEffectEvent((api, element) => {
|
|
278
|
+
const map = new api.maps.Map(element, mapOptions(center, zoom, interactive, normalizedMinZoom, normalizedMaxZoom));
|
|
279
|
+
apiRef.current = api;
|
|
280
|
+
mapRef.current = map;
|
|
281
|
+
zoomListenerRef.current = api.maps.event.addListener(map, "zoom_changed", () => setCurrentZoom(map.getZoom() ?? zoom));
|
|
282
|
+
setCurrentZoom(clampZoom(zoom, normalizedMinZoom, normalizedMaxZoom));
|
|
283
|
+
setLoadState("ready");
|
|
284
|
+
});
|
|
285
|
+
useEffect(() => {
|
|
286
|
+
if (!normalizedApiKey) {
|
|
287
|
+
setLoadState("missing-key");
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const element = mapElementRef.current;
|
|
291
|
+
if (!element)
|
|
292
|
+
return;
|
|
293
|
+
let mounted = true;
|
|
294
|
+
setLoadState("loading");
|
|
295
|
+
loadGoogleMaps(normalizedApiKey).then((api) => {
|
|
296
|
+
if (!mounted)
|
|
297
|
+
return;
|
|
298
|
+
try {
|
|
299
|
+
initializeMap(api, element);
|
|
300
|
+
} catch {
|
|
301
|
+
setLoadState("error");
|
|
302
|
+
}
|
|
303
|
+
}).catch(() => {
|
|
304
|
+
if (mounted)
|
|
305
|
+
setLoadState("error");
|
|
306
|
+
});
|
|
307
|
+
return () => {
|
|
308
|
+
mounted = false;
|
|
309
|
+
zoomListenerRef.current?.remove();
|
|
310
|
+
markerRef.current?.setMap(null);
|
|
311
|
+
circleRef.current?.setMap(null);
|
|
312
|
+
if (mapRef.current) {
|
|
313
|
+
apiRef.current?.maps.event.clearInstanceListeners(mapRef.current);
|
|
314
|
+
}
|
|
315
|
+
markerRef.current = null;
|
|
316
|
+
circleRef.current = null;
|
|
317
|
+
zoomListenerRef.current = null;
|
|
318
|
+
mapRef.current = null;
|
|
319
|
+
apiRef.current = null;
|
|
320
|
+
element.replaceChildren();
|
|
321
|
+
};
|
|
322
|
+
}, [normalizedApiKey, setLoadState]);
|
|
323
|
+
useEffect(() => {
|
|
324
|
+
const map = mapRef.current;
|
|
325
|
+
if (loadState !== "ready" || !map)
|
|
326
|
+
return;
|
|
327
|
+
const nextCenter = { lat: centerLat, lng: centerLng };
|
|
328
|
+
const nextZoom = clampZoom(zoom, normalizedMinZoom, normalizedMaxZoom);
|
|
329
|
+
try {
|
|
330
|
+
map.setOptions(mapOptions(nextCenter, nextZoom, interactive, normalizedMinZoom, normalizedMaxZoom));
|
|
331
|
+
map.setCenter(nextCenter);
|
|
332
|
+
map.setZoom(nextZoom);
|
|
333
|
+
setCurrentZoom(nextZoom);
|
|
334
|
+
} catch {
|
|
335
|
+
setLoadState("error");
|
|
336
|
+
}
|
|
337
|
+
}, [
|
|
338
|
+
centerLat,
|
|
339
|
+
centerLng,
|
|
340
|
+
zoom,
|
|
341
|
+
interactive,
|
|
342
|
+
fitRadius,
|
|
343
|
+
normalizedMinZoom,
|
|
344
|
+
normalizedMaxZoom,
|
|
345
|
+
loadState,
|
|
346
|
+
setLoadState,
|
|
347
|
+
setCurrentZoom
|
|
348
|
+
]);
|
|
349
|
+
useEffect(() => {
|
|
350
|
+
const api = apiRef.current;
|
|
351
|
+
const map = mapRef.current;
|
|
352
|
+
if (loadState !== "ready" || !api || !map)
|
|
353
|
+
return;
|
|
354
|
+
try {
|
|
355
|
+
const nextCenter = { lat: centerLat, lng: centerLng };
|
|
356
|
+
if (markerEnabled) {
|
|
357
|
+
if (markerRef.current) {
|
|
358
|
+
markerRef.current.setMap(map);
|
|
359
|
+
markerRef.current.setPosition(nextCenter);
|
|
360
|
+
markerRef.current.setIcon(markerIcon);
|
|
361
|
+
} else {
|
|
362
|
+
markerRef.current = new api.maps.Marker({
|
|
363
|
+
icon: markerIcon,
|
|
364
|
+
map,
|
|
365
|
+
position: nextCenter
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
markerRef.current?.setMap(null);
|
|
370
|
+
markerRef.current = null;
|
|
371
|
+
}
|
|
372
|
+
if (radiusMeters !== undefined) {
|
|
373
|
+
const style = {
|
|
374
|
+
fillColor: radiusFillColor ?? "#18181b",
|
|
375
|
+
fillOpacity: radiusFillOpacity ?? 0.12,
|
|
376
|
+
strokeColor: radiusStrokeColor ?? "#18181b",
|
|
377
|
+
strokeOpacity: radiusStrokeOpacity ?? 0.7,
|
|
378
|
+
strokeWeight: radiusStrokeWeight ?? 2
|
|
379
|
+
};
|
|
380
|
+
if (circleRef.current) {
|
|
381
|
+
circleRef.current.setMap(map);
|
|
382
|
+
circleRef.current.setCenter(nextCenter);
|
|
383
|
+
circleRef.current.setRadius(radiusMeters);
|
|
384
|
+
circleRef.current.setOptions(style);
|
|
385
|
+
} else {
|
|
386
|
+
circleRef.current = new api.maps.Circle({
|
|
387
|
+
...style,
|
|
388
|
+
center: nextCenter,
|
|
389
|
+
clickable: false,
|
|
390
|
+
map,
|
|
391
|
+
radius: radiusMeters
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
circleRef.current?.setMap(null);
|
|
396
|
+
circleRef.current = null;
|
|
397
|
+
}
|
|
398
|
+
} catch {
|
|
399
|
+
setLoadState("error");
|
|
400
|
+
}
|
|
401
|
+
}, [
|
|
402
|
+
centerLat,
|
|
403
|
+
centerLng,
|
|
404
|
+
loadState,
|
|
405
|
+
markerEnabled,
|
|
406
|
+
markerIcon,
|
|
407
|
+
radiusFillColor,
|
|
408
|
+
radiusFillOpacity,
|
|
409
|
+
radiusMeters,
|
|
410
|
+
radiusStrokeColor,
|
|
411
|
+
radiusStrokeOpacity,
|
|
412
|
+
radiusStrokeWeight,
|
|
413
|
+
setLoadState
|
|
414
|
+
]);
|
|
415
|
+
useEffect(() => {
|
|
416
|
+
const element = mapElementRef.current;
|
|
417
|
+
if (loadState !== "ready" || !fitRadius || radiusMeters === undefined || !element)
|
|
418
|
+
return;
|
|
419
|
+
let frame = 0;
|
|
420
|
+
const scheduleFit = () => {
|
|
421
|
+
cancelAnimationFrame(frame);
|
|
422
|
+
frame = requestAnimationFrame(() => {
|
|
423
|
+
frame = requestAnimationFrame(() => fitSelection());
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
scheduleFit();
|
|
427
|
+
let width = element.clientWidth;
|
|
428
|
+
let height = element.clientHeight;
|
|
429
|
+
const observer = globalThis.ResizeObserver ? new ResizeObserver(() => {
|
|
430
|
+
const nextWidth = element.clientWidth;
|
|
431
|
+
const nextHeight = element.clientHeight;
|
|
432
|
+
if (nextWidth === width && nextHeight === height)
|
|
433
|
+
return;
|
|
434
|
+
width = nextWidth;
|
|
435
|
+
height = nextHeight;
|
|
436
|
+
scheduleFit();
|
|
437
|
+
}) : undefined;
|
|
438
|
+
observer?.observe(element);
|
|
439
|
+
return () => {
|
|
440
|
+
cancelAnimationFrame(frame);
|
|
441
|
+
observer?.disconnect();
|
|
442
|
+
};
|
|
443
|
+
}, [
|
|
444
|
+
loadState,
|
|
445
|
+
fitRadius,
|
|
446
|
+
fitPadding,
|
|
447
|
+
interactive,
|
|
448
|
+
centerLat,
|
|
449
|
+
centerLng,
|
|
450
|
+
radiusMeters,
|
|
451
|
+
normalizedMinZoom,
|
|
452
|
+
normalizedMaxZoom
|
|
453
|
+
]);
|
|
454
|
+
const changeZoom = (delta) => {
|
|
455
|
+
const map = mapRef.current;
|
|
456
|
+
if (!map)
|
|
457
|
+
return;
|
|
458
|
+
const nextZoom = clampZoom((map.getZoom() ?? currentZoom) + delta, normalizedMinZoom, normalizedMaxZoom);
|
|
459
|
+
map.setZoom(nextZoom);
|
|
460
|
+
setCurrentZoom(nextZoom);
|
|
461
|
+
};
|
|
462
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
463
|
+
"data-slot": "map-menu-renderer",
|
|
464
|
+
className: cn("bg-muted relative isolate min-h-64 min-w-0 overflow-hidden rounded-lg border", className),
|
|
465
|
+
children: [
|
|
466
|
+
/* @__PURE__ */ jsx3("div", {
|
|
467
|
+
ref: mapElementRef,
|
|
468
|
+
"data-slot": "map-menu-canvas",
|
|
469
|
+
className: "h-full min-h-[inherit] w-full",
|
|
470
|
+
role: "region",
|
|
471
|
+
"aria-label": labels.mapLabel
|
|
472
|
+
}),
|
|
473
|
+
loadState === "ready" && zoomControls ? /* @__PURE__ */ jsxs2("div", {
|
|
474
|
+
"data-slot": "map-menu-controls",
|
|
475
|
+
className: cn("bg-background/95 absolute top-3 right-3 z-10 overflow-hidden rounded-md border shadow-sm backdrop-blur", controlsClassName),
|
|
476
|
+
children: [
|
|
477
|
+
fitRadius && radiusMeters !== undefined ? /* @__PURE__ */ jsxs2(Fragment, {
|
|
478
|
+
children: [
|
|
479
|
+
/* @__PURE__ */ jsx3("button", {
|
|
480
|
+
"data-slot": "map-menu-control",
|
|
481
|
+
type: "button",
|
|
482
|
+
onClick: showSelectedArea,
|
|
483
|
+
"aria-label": labels.showArea,
|
|
484
|
+
title: labels.showArea,
|
|
485
|
+
className: "text-foreground hover:bg-accent focus-visible:ring-ring relative flex size-11 items-center justify-center focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-inset",
|
|
486
|
+
children: /* @__PURE__ */ jsx3(LocateFixed, {
|
|
487
|
+
className: "size-4"
|
|
488
|
+
})
|
|
489
|
+
}),
|
|
490
|
+
/* @__PURE__ */ jsx3("div", {
|
|
491
|
+
className: "bg-border h-px"
|
|
492
|
+
})
|
|
493
|
+
]
|
|
494
|
+
}) : null,
|
|
495
|
+
/* @__PURE__ */ jsx3("button", {
|
|
496
|
+
"data-slot": "map-menu-control",
|
|
497
|
+
type: "button",
|
|
498
|
+
className: "text-foreground hover:bg-accent focus-visible:ring-ring relative flex size-11 items-center justify-center transition-colors focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50",
|
|
499
|
+
disabled: currentZoom >= normalizedMaxZoom,
|
|
500
|
+
onClick: () => changeZoom(1),
|
|
501
|
+
"aria-label": labels.zoomIn,
|
|
502
|
+
children: /* @__PURE__ */ jsx3(Plus, {
|
|
503
|
+
className: "size-4"
|
|
504
|
+
})
|
|
505
|
+
}),
|
|
506
|
+
/* @__PURE__ */ jsx3("div", {
|
|
507
|
+
className: "bg-border h-px"
|
|
508
|
+
}),
|
|
509
|
+
/* @__PURE__ */ jsx3("button", {
|
|
510
|
+
"data-slot": "map-menu-control",
|
|
511
|
+
type: "button",
|
|
512
|
+
className: "text-foreground hover:bg-accent focus-visible:ring-ring relative flex size-11 items-center justify-center transition-colors focus-visible:z-10 focus-visible:ring-2 focus-visible:ring-inset disabled:pointer-events-none disabled:opacity-50",
|
|
513
|
+
disabled: currentZoom <= normalizedMinZoom,
|
|
514
|
+
onClick: () => changeZoom(-1),
|
|
515
|
+
"aria-label": labels.zoomOut,
|
|
516
|
+
children: /* @__PURE__ */ jsx3(Minus, {
|
|
517
|
+
className: "size-4"
|
|
518
|
+
})
|
|
519
|
+
})
|
|
520
|
+
]
|
|
521
|
+
}) : null,
|
|
522
|
+
loadState === "loading" ? /* @__PURE__ */ jsx3("div", {
|
|
523
|
+
className: "bg-background/75 text-muted-foreground absolute inset-0 grid place-items-center text-sm font-medium backdrop-blur-sm",
|
|
524
|
+
role: "status",
|
|
525
|
+
children: labels.loading
|
|
526
|
+
}) : null,
|
|
527
|
+
loadState === "missing-key" || loadState === "error" ? /* @__PURE__ */ jsx3("div", {
|
|
528
|
+
className: "bg-background/85 absolute inset-0 grid place-items-center p-6 text-center backdrop-blur-sm",
|
|
529
|
+
children: /* @__PURE__ */ jsxs2("div", {
|
|
530
|
+
className: "bg-card text-card-foreground max-w-sm rounded-lg border p-5 shadow-sm",
|
|
531
|
+
role: "alert",
|
|
532
|
+
children: [
|
|
533
|
+
/* @__PURE__ */ jsx3("p", {
|
|
534
|
+
className: "text-sm font-semibold",
|
|
535
|
+
children: loadState === "missing-key" ? labels.missingKeyTitle : labels.errorTitle
|
|
536
|
+
}),
|
|
537
|
+
/* @__PURE__ */ jsx3("p", {
|
|
538
|
+
className: "text-muted-foreground mt-2 text-xs",
|
|
539
|
+
children: loadState === "missing-key" ? labels.missingKeyBody : labels.errorBody
|
|
540
|
+
})
|
|
541
|
+
]
|
|
542
|
+
})
|
|
543
|
+
}) : null
|
|
544
|
+
]
|
|
545
|
+
});
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// ../../src/components/ui/input.tsx
|
|
549
|
+
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
550
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
551
|
+
function Input({ className, type, ...props }) {
|
|
552
|
+
return /* @__PURE__ */ jsx4(InputPrimitive, {
|
|
553
|
+
type,
|
|
554
|
+
"data-slot": "input",
|
|
555
|
+
className: cn("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className),
|
|
556
|
+
...props
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// ../../src/components/ui/map-menu.tsx
|
|
561
|
+
import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
|
|
562
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
563
|
+
var MapMenuMode;
|
|
564
|
+
((MapMenuMode) => {
|
|
565
|
+
MapMenuMode["Point"] = "point";
|
|
566
|
+
MapMenuMode["Radius"] = "radius";
|
|
567
|
+
})(MapMenuMode ||= {});
|
|
568
|
+
var mapMenuRadiiKm = [1, 2, 5, 10, 20, 40, 60, 80, 100, 250, 500];
|
|
569
|
+
var defaultMessages2 = {
|
|
570
|
+
en: {
|
|
571
|
+
title: "Choose your location",
|
|
572
|
+
location: "City or address",
|
|
573
|
+
placeholder: "Search a city or address…",
|
|
574
|
+
clear: "Clear location",
|
|
575
|
+
close: "Close",
|
|
576
|
+
currentLocation: "Use my location",
|
|
577
|
+
searchWithin: "Search within",
|
|
578
|
+
suggestions: "Location suggestions",
|
|
579
|
+
loading: "Finding matching places…",
|
|
580
|
+
noResults: "No matching places. Try a city or address.",
|
|
581
|
+
searchHint: "Search for a place and choose a suggestion to preview it on the map.",
|
|
582
|
+
ipNotice: "Using your approximate location from your IP address.",
|
|
583
|
+
browserNotice: "Using your browser location.",
|
|
584
|
+
radiusHint: "The circle shows your search area.",
|
|
585
|
+
cancel: "Cancel",
|
|
586
|
+
confirm: "Use this location",
|
|
587
|
+
confirmError: "Your location could not be saved. Try again."
|
|
588
|
+
},
|
|
589
|
+
fr: {
|
|
590
|
+
title: "Choisir votre lieu",
|
|
591
|
+
location: "Ville ou adresse",
|
|
592
|
+
placeholder: "Rechercher une ville ou une adresse…",
|
|
593
|
+
clear: "Effacer le lieu",
|
|
594
|
+
close: "Fermer",
|
|
595
|
+
currentLocation: "Utiliser ma position",
|
|
596
|
+
searchWithin: "Rechercher dans un rayon de",
|
|
597
|
+
suggestions: "Suggestions de lieux",
|
|
598
|
+
loading: "Recherche de lieux…",
|
|
599
|
+
noResults: "Aucun lieu correspondant. Essayez une ville ou une adresse.",
|
|
600
|
+
searchHint: "Recherchez un lieu et choisissez une suggestion pour le voir sur la carte.",
|
|
601
|
+
ipNotice: "Position approximative obtenue à partir de votre adresse IP.",
|
|
602
|
+
browserNotice: "Position fournie par votre navigateur.",
|
|
603
|
+
radiusHint: "Le cercle indique votre zone de recherche.",
|
|
604
|
+
cancel: "Annuler",
|
|
605
|
+
confirm: "Utiliser ce lieu",
|
|
606
|
+
confirmError: "Votre lieu n’a pas pu être enregistré. Réessayez."
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
var MapMenu = (props) => {
|
|
610
|
+
const {
|
|
611
|
+
apiKey,
|
|
612
|
+
open,
|
|
613
|
+
onOpenChange,
|
|
614
|
+
input,
|
|
615
|
+
onInputChange,
|
|
616
|
+
selectedLocation,
|
|
617
|
+
suggestions: locationSuggestions,
|
|
618
|
+
onSelectLocation,
|
|
619
|
+
radiusKm,
|
|
620
|
+
radiusOptions = mapMenuRadiiKm,
|
|
621
|
+
onUseCurrentLocation,
|
|
622
|
+
locating = false,
|
|
623
|
+
loadingSuggestions = false,
|
|
624
|
+
suggestionsError,
|
|
625
|
+
error,
|
|
626
|
+
provenance,
|
|
627
|
+
overlayColor = "#f56476",
|
|
628
|
+
className,
|
|
629
|
+
confirmClassName,
|
|
630
|
+
locale: localeOverride,
|
|
631
|
+
messages
|
|
632
|
+
} = props;
|
|
633
|
+
const radiusEnabled = props.mode !== "point" /* Point */;
|
|
634
|
+
const locale = useKrakstackLocale2(localeOverride);
|
|
635
|
+
const suggestions = locationSuggestions.slice(0, 3);
|
|
636
|
+
const baseLocale = locale.split("-")[0] ?? "en";
|
|
637
|
+
const labels = {
|
|
638
|
+
...baseLocale === "fr" ? defaultMessages2.fr : defaultMessages2.en,
|
|
639
|
+
...messages?.[baseLocale],
|
|
640
|
+
...messages?.[locale]
|
|
641
|
+
};
|
|
642
|
+
const id = useId();
|
|
643
|
+
const inputRef = useRef2(null);
|
|
644
|
+
const popupRef = useRef2(null);
|
|
645
|
+
const [dropdownOpen, setDropdownOpen] = useState2(false);
|
|
646
|
+
const [activeIndex, setActiveIndex] = useState2(-1);
|
|
647
|
+
const [applying, setApplying] = useState2(false);
|
|
648
|
+
const [confirmFailed, setConfirmFailed] = useState2(false);
|
|
649
|
+
const selectedMatchesInput = selectedLocation?.label === input.trim();
|
|
650
|
+
const notice = provenance === "ip" ? labels.ipNotice : provenance === "browser" ? labels.browserNotice : !selectedMatchesInput ? labels.searchHint : undefined;
|
|
651
|
+
const markerIcon = `data:image/svg+xml;charset=UTF-8,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" width="40" height="48" viewBox="0 0 40 48"><path d="M20 46s15-14.3 15-27A15 15 0 1 0 5 19c0 12.7 15 27 15 27Z" fill="${overlayColor}" stroke="white" stroke-width="3"/><circle cx="20" cy="19" r="6" fill="white"/></svg>`)}`;
|
|
652
|
+
useEffect2(() => {
|
|
653
|
+
if (!open || !window.visualViewport)
|
|
654
|
+
return;
|
|
655
|
+
const viewport = window.visualViewport;
|
|
656
|
+
const sync = () => {
|
|
657
|
+
popupRef.current?.style.setProperty("--map-picker-height", `${viewport.height}px`);
|
|
658
|
+
popupRef.current?.style.setProperty("--map-picker-top", `${viewport.offsetTop}px`);
|
|
659
|
+
};
|
|
660
|
+
sync();
|
|
661
|
+
viewport.addEventListener("resize", sync);
|
|
662
|
+
viewport.addEventListener("scroll", sync);
|
|
663
|
+
return () => {
|
|
664
|
+
viewport.removeEventListener("resize", sync);
|
|
665
|
+
viewport.removeEventListener("scroll", sync);
|
|
666
|
+
};
|
|
667
|
+
}, [open]);
|
|
668
|
+
useEffect2(() => {
|
|
669
|
+
if (dropdownOpen && activeIndex >= 0)
|
|
670
|
+
document.getElementById(`${id}-option-${activeIndex}`)?.scrollIntoView?.({ block: "nearest" });
|
|
671
|
+
}, [activeIndex, dropdownOpen, id]);
|
|
672
|
+
const changeOpen = (next) => {
|
|
673
|
+
if (applying)
|
|
674
|
+
return;
|
|
675
|
+
setDropdownOpen(false);
|
|
676
|
+
setActiveIndex(-1);
|
|
677
|
+
setConfirmFailed(false);
|
|
678
|
+
onOpenChange(next);
|
|
679
|
+
};
|
|
680
|
+
const select = (location) => {
|
|
681
|
+
onInputChange(location.label);
|
|
682
|
+
onSelectLocation(location);
|
|
683
|
+
inputRef.current?.focus();
|
|
684
|
+
setDropdownOpen(false);
|
|
685
|
+
setActiveIndex(-1);
|
|
686
|
+
};
|
|
687
|
+
const confirm = async () => {
|
|
688
|
+
if (applying || !selectedLocation || !selectedMatchesInput)
|
|
689
|
+
return;
|
|
690
|
+
setApplying(true);
|
|
691
|
+
setConfirmFailed(false);
|
|
692
|
+
setDropdownOpen(false);
|
|
693
|
+
try {
|
|
694
|
+
if (props.mode === "point" /* Point */) {
|
|
695
|
+
await props.onConfirm({ location: selectedLocation });
|
|
696
|
+
} else {
|
|
697
|
+
await props.onConfirm({
|
|
698
|
+
location: selectedLocation,
|
|
699
|
+
radiusKm: props.radiusKm
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
onOpenChange(false);
|
|
703
|
+
} catch {
|
|
704
|
+
setConfirmFailed(true);
|
|
705
|
+
} finally {
|
|
706
|
+
setApplying(false);
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
return /* @__PURE__ */ jsx5(Dialog, {
|
|
710
|
+
open,
|
|
711
|
+
onOpenChange: changeOpen,
|
|
712
|
+
children: /* @__PURE__ */ jsxs3(DialogPortal, {
|
|
713
|
+
children: [
|
|
714
|
+
/* @__PURE__ */ jsx5(DialogOverlay, {}),
|
|
715
|
+
/* @__PURE__ */ jsxs3(DialogPrimitive2.Popup, {
|
|
716
|
+
ref: popupRef,
|
|
717
|
+
initialFocus: inputRef,
|
|
718
|
+
"aria-describedby": undefined,
|
|
719
|
+
"data-slot": "map-menu",
|
|
720
|
+
className: cn("bg-muted text-foreground fixed top-[calc(var(--map-picker-top,0px)_+_var(--map-picker-height,100dvh)/2)] left-1/2 z-50 flex h-[var(--map-picker-height,100dvh)] w-screen max-w-none -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden border p-0 outline-none sm:h-[min(46.75rem,calc(var(--map-picker-height,100dvh)_-_5rem))] sm:w-[calc(100vw-4rem)] sm:max-w-[840px] sm:rounded-[10px] [@media(max-height:599px)]:h-[var(--map-picker-height,100dvh)]", className),
|
|
721
|
+
children: [
|
|
722
|
+
/* @__PURE__ */ jsxs3(DialogHeader, {
|
|
723
|
+
className: "shrink-0 px-5 pt-6 pr-16 pb-5 text-left sm:px-7 sm:pt-[25px] sm:pb-[22px] [@media(max-height:599px)]:py-4",
|
|
724
|
+
children: [
|
|
725
|
+
/* @__PURE__ */ jsx5(DialogTitle, {
|
|
726
|
+
className: "text-2xl font-semibold",
|
|
727
|
+
children: labels.title
|
|
728
|
+
}),
|
|
729
|
+
/* @__PURE__ */ jsx5(Button, {
|
|
730
|
+
type: "button",
|
|
731
|
+
variant: "ghost",
|
|
732
|
+
size: "icon",
|
|
733
|
+
className: "absolute top-4 right-4 size-11",
|
|
734
|
+
disabled: applying,
|
|
735
|
+
"aria-label": labels.close,
|
|
736
|
+
onClick: () => changeOpen(false),
|
|
737
|
+
children: /* @__PURE__ */ jsx5(X, {})
|
|
738
|
+
})
|
|
739
|
+
]
|
|
740
|
+
}),
|
|
741
|
+
/* @__PURE__ */ jsxs3("div", {
|
|
742
|
+
className: "flex min-h-0 min-w-0 flex-1 flex-col gap-[18px] overflow-y-auto px-5 pb-6 sm:px-7 [@media(max-height:599px)]:pb-3",
|
|
743
|
+
children: [
|
|
744
|
+
/* @__PURE__ */ jsxs3("fieldset", {
|
|
745
|
+
disabled: applying,
|
|
746
|
+
"data-slot": "map-menu-toolbar",
|
|
747
|
+
className: cn("grid min-w-0 shrink-0 grid-cols-1 items-end gap-3", onUseCurrentLocation && "sm:grid-cols-[minmax(0,1fr)_max-content]"),
|
|
748
|
+
children: [
|
|
749
|
+
/* @__PURE__ */ jsxs3("div", {
|
|
750
|
+
className: "relative flex min-w-0 flex-col gap-2",
|
|
751
|
+
onBlur: (event) => {
|
|
752
|
+
if (!event.currentTarget.contains(event.relatedTarget))
|
|
753
|
+
setDropdownOpen(false);
|
|
754
|
+
},
|
|
755
|
+
children: [
|
|
756
|
+
/* @__PURE__ */ jsx5("label", {
|
|
757
|
+
htmlFor: `${id}-input`,
|
|
758
|
+
className: "text-sm font-medium",
|
|
759
|
+
children: labels.location
|
|
760
|
+
}),
|
|
761
|
+
/* @__PURE__ */ jsxs3("div", {
|
|
762
|
+
className: "relative",
|
|
763
|
+
children: [
|
|
764
|
+
/* @__PURE__ */ jsx5(Search, {
|
|
765
|
+
"aria-hidden": "true",
|
|
766
|
+
className: "text-muted-foreground pointer-events-none absolute top-1/2 left-3.5 size-4 -translate-y-1/2"
|
|
767
|
+
}),
|
|
768
|
+
/* @__PURE__ */ jsx5(Input, {
|
|
769
|
+
ref: inputRef,
|
|
770
|
+
id: `${id}-input`,
|
|
771
|
+
value: input,
|
|
772
|
+
placeholder: labels.placeholder,
|
|
773
|
+
className: "bg-card h-[50px] w-full rounded-md pr-11 pl-11 text-base",
|
|
774
|
+
autoComplete: "off",
|
|
775
|
+
role: "combobox",
|
|
776
|
+
"aria-autocomplete": "list",
|
|
777
|
+
"aria-controls": `${id}-suggestions`,
|
|
778
|
+
"aria-expanded": dropdownOpen,
|
|
779
|
+
"aria-activedescendant": dropdownOpen && suggestions[activeIndex] ? `${id}-option-${activeIndex}` : undefined,
|
|
780
|
+
onFocus: () => {
|
|
781
|
+
if (input.trim() && !selectedMatchesInput)
|
|
782
|
+
setDropdownOpen(true);
|
|
783
|
+
},
|
|
784
|
+
onChange: (event) => {
|
|
785
|
+
onInputChange(event.currentTarget.value);
|
|
786
|
+
setActiveIndex(-1);
|
|
787
|
+
setConfirmFailed(false);
|
|
788
|
+
setDropdownOpen(Boolean(event.currentTarget.value.trim()));
|
|
789
|
+
},
|
|
790
|
+
onKeyDown: (event) => {
|
|
791
|
+
if (event.key === "Escape" && dropdownOpen) {
|
|
792
|
+
event.preventDefault();
|
|
793
|
+
event.stopPropagation();
|
|
794
|
+
setDropdownOpen(false);
|
|
795
|
+
}
|
|
796
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
797
|
+
event.preventDefault();
|
|
798
|
+
setDropdownOpen(true);
|
|
799
|
+
if (suggestions.length)
|
|
800
|
+
setActiveIndex((index) => index < 0 ? event.key === "ArrowDown" ? 0 : suggestions.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + suggestions.length) % suggestions.length);
|
|
801
|
+
}
|
|
802
|
+
if (event.key === "Enter" && dropdownOpen) {
|
|
803
|
+
event.preventDefault();
|
|
804
|
+
const location = suggestions[activeIndex];
|
|
805
|
+
if (location)
|
|
806
|
+
select(location);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}),
|
|
810
|
+
input ? /* @__PURE__ */ jsx5("button", {
|
|
811
|
+
type: "button",
|
|
812
|
+
"aria-label": labels.clear,
|
|
813
|
+
className: "text-muted-foreground absolute top-[3px] right-1 grid size-11 cursor-pointer place-items-center rounded focus-visible:outline-2 focus-visible:outline-offset-2",
|
|
814
|
+
onClick: () => {
|
|
815
|
+
onInputChange("");
|
|
816
|
+
setDropdownOpen(false);
|
|
817
|
+
setActiveIndex(-1);
|
|
818
|
+
inputRef.current?.focus();
|
|
819
|
+
},
|
|
820
|
+
children: /* @__PURE__ */ jsx5(X, {
|
|
821
|
+
className: "size-4"
|
|
822
|
+
})
|
|
823
|
+
}) : null
|
|
824
|
+
]
|
|
825
|
+
}),
|
|
826
|
+
dropdownOpen ? /* @__PURE__ */ jsxs3("div", {
|
|
827
|
+
id: `${id}-suggestions`,
|
|
828
|
+
role: "listbox",
|
|
829
|
+
"aria-label": labels.suggestions,
|
|
830
|
+
"aria-busy": loadingSuggestions,
|
|
831
|
+
className: "bg-popover text-popover-foreground absolute inset-x-0 top-full z-30 mt-1 max-h-[min(16rem,35dvh)] overflow-y-auto rounded-md border p-1 shadow-lg",
|
|
832
|
+
children: [
|
|
833
|
+
suggestions.map((location, index) => /* @__PURE__ */ jsxs3("button", {
|
|
834
|
+
id: `${id}-option-${index}`,
|
|
835
|
+
type: "button",
|
|
836
|
+
role: "option",
|
|
837
|
+
tabIndex: -1,
|
|
838
|
+
"aria-label": location.label,
|
|
839
|
+
"aria-selected": index === activeIndex,
|
|
840
|
+
className: cn("hover:bg-accent flex min-h-11 w-full items-center gap-3 rounded px-3 py-3 text-left", index === activeIndex && "bg-accent"),
|
|
841
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
842
|
+
onClick: () => select(location),
|
|
843
|
+
children: [
|
|
844
|
+
/* @__PURE__ */ jsx5(MapPin, {
|
|
845
|
+
"aria-hidden": "true",
|
|
846
|
+
className: "size-4 shrink-0",
|
|
847
|
+
style: { color: overlayColor }
|
|
848
|
+
}),
|
|
849
|
+
/* @__PURE__ */ jsxs3("span", {
|
|
850
|
+
className: "min-w-0",
|
|
851
|
+
children: [
|
|
852
|
+
/* @__PURE__ */ jsx5("span", {
|
|
853
|
+
className: "block text-sm font-medium wrap-anywhere",
|
|
854
|
+
children: location.title ?? location.label
|
|
855
|
+
}),
|
|
856
|
+
location.details ? /* @__PURE__ */ jsx5("span", {
|
|
857
|
+
className: "text-muted-foreground mt-1 block text-xs wrap-anywhere",
|
|
858
|
+
children: location.details
|
|
859
|
+
}) : null
|
|
860
|
+
]
|
|
861
|
+
})
|
|
862
|
+
]
|
|
863
|
+
}, location.id)),
|
|
864
|
+
loadingSuggestions ? /* @__PURE__ */ jsx5("p", {
|
|
865
|
+
role: "status",
|
|
866
|
+
className: "text-muted-foreground p-3 text-sm",
|
|
867
|
+
children: labels.loading
|
|
868
|
+
}) : suggestionsError ? /* @__PURE__ */ jsx5("p", {
|
|
869
|
+
role: "alert",
|
|
870
|
+
className: "text-destructive p-3 text-sm",
|
|
871
|
+
children: suggestionsError
|
|
872
|
+
}) : !suggestions.length ? /* @__PURE__ */ jsx5("p", {
|
|
873
|
+
className: "text-muted-foreground p-3 text-sm",
|
|
874
|
+
children: labels.noResults
|
|
875
|
+
}) : null
|
|
876
|
+
]
|
|
877
|
+
}) : null
|
|
878
|
+
]
|
|
879
|
+
}),
|
|
880
|
+
onUseCurrentLocation ? /* @__PURE__ */ jsxs3(Button, {
|
|
881
|
+
type: "button",
|
|
882
|
+
variant: "outline",
|
|
883
|
+
"data-slot": "map-menu-current",
|
|
884
|
+
disabled: locating,
|
|
885
|
+
className: "bg-card h-[50px] w-max gap-[7px] justify-self-start px-3 shadow-none",
|
|
886
|
+
onClick: onUseCurrentLocation,
|
|
887
|
+
children: [
|
|
888
|
+
/* @__PURE__ */ jsx5(LocateFixed2, {
|
|
889
|
+
className: "text-foreground size-[17px]"
|
|
890
|
+
}),
|
|
891
|
+
labels.currentLocation
|
|
892
|
+
]
|
|
893
|
+
}) : null,
|
|
894
|
+
/* @__PURE__ */ jsxs3("div", {
|
|
895
|
+
className: "col-span-full grid text-xs leading-5",
|
|
896
|
+
children: [
|
|
897
|
+
[labels.ipNotice, labels.browserNotice, labels.searchHint].map((text) => /* @__PURE__ */ jsx5("span", {
|
|
898
|
+
"aria-hidden": "true",
|
|
899
|
+
className: "invisible col-start-1 row-start-1 pl-6",
|
|
900
|
+
children: text
|
|
901
|
+
}, text)),
|
|
902
|
+
notice ? /* @__PURE__ */ jsxs3("p", {
|
|
903
|
+
role: "status",
|
|
904
|
+
"data-slot": "map-menu-provenance",
|
|
905
|
+
className: "text-muted-foreground col-start-1 row-start-1 flex items-start gap-2",
|
|
906
|
+
children: [
|
|
907
|
+
/* @__PURE__ */ jsx5(MapPin, {
|
|
908
|
+
"aria-hidden": "true",
|
|
909
|
+
className: "text-foreground mt-0.5 size-4 shrink-0"
|
|
910
|
+
}),
|
|
911
|
+
/* @__PURE__ */ jsx5("span", {
|
|
912
|
+
className: "wrap-anywhere",
|
|
913
|
+
children: notice
|
|
914
|
+
})
|
|
915
|
+
]
|
|
916
|
+
}) : null
|
|
917
|
+
]
|
|
918
|
+
}),
|
|
919
|
+
radiusEnabled ? /* @__PURE__ */ jsxs3("div", {
|
|
920
|
+
className: "after:bg-border col-span-full flex flex-wrap items-center gap-3 after:h-px after:flex-1",
|
|
921
|
+
children: [
|
|
922
|
+
/* @__PURE__ */ jsx5("label", {
|
|
923
|
+
htmlFor: `${id}-radius`,
|
|
924
|
+
className: "text-sm font-medium",
|
|
925
|
+
children: labels.searchWithin
|
|
926
|
+
}),
|
|
927
|
+
/* @__PURE__ */ jsxs3("div", {
|
|
928
|
+
className: "relative",
|
|
929
|
+
children: [
|
|
930
|
+
/* @__PURE__ */ jsx5("select", {
|
|
931
|
+
id: `${id}-radius`,
|
|
932
|
+
value: radiusKm,
|
|
933
|
+
className: "bg-card focus-visible:outline-ring h-11 appearance-none rounded border py-2 pr-9 pl-3 text-sm focus-visible:outline-2 focus-visible:outline-offset-2",
|
|
934
|
+
onChange: (event) => props.onRadiusChange(Number(event.currentTarget.value)),
|
|
935
|
+
children: radiusOptions.map((radius) => /* @__PURE__ */ jsxs3("option", {
|
|
936
|
+
value: radius,
|
|
937
|
+
children: [
|
|
938
|
+
radius,
|
|
939
|
+
" km"
|
|
940
|
+
]
|
|
941
|
+
}, radius))
|
|
942
|
+
}),
|
|
943
|
+
/* @__PURE__ */ jsx5(ChevronDown, {
|
|
944
|
+
"aria-hidden": "true",
|
|
945
|
+
className: "pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2"
|
|
946
|
+
})
|
|
947
|
+
]
|
|
948
|
+
})
|
|
949
|
+
]
|
|
950
|
+
}) : null
|
|
951
|
+
]
|
|
952
|
+
}),
|
|
953
|
+
/* @__PURE__ */ jsxs3("div", {
|
|
954
|
+
"data-slot": "map-menu-map",
|
|
955
|
+
className: "relative min-h-56 min-w-0 flex-[1_0_14rem] [@media(max-height:599px)]:min-h-[182px] [@media(max-height:599px)]:basis-[182px]",
|
|
956
|
+
children: [
|
|
957
|
+
/* @__PURE__ */ jsx5(MapMenuMap, {
|
|
958
|
+
apiKey,
|
|
959
|
+
center: selectedLocation?.center ?? { lat: 0, lng: 0 },
|
|
960
|
+
zoom: !radiusEnabled && selectedLocation ? 15 : 4,
|
|
961
|
+
marker: selectedLocation ? { icon: markerIcon } : undefined,
|
|
962
|
+
radius: radiusEnabled && selectedLocation && radiusKm !== undefined ? {
|
|
963
|
+
radiusMeters: radiusKm * 1000,
|
|
964
|
+
fillColor: overlayColor,
|
|
965
|
+
fillOpacity: 0.12,
|
|
966
|
+
strokeColor: overlayColor,
|
|
967
|
+
strokeOpacity: 0.82,
|
|
968
|
+
strokeWeight: 2
|
|
969
|
+
} : undefined,
|
|
970
|
+
fitRadius: radiusEnabled && Boolean(selectedLocation),
|
|
971
|
+
fitPadding: 40,
|
|
972
|
+
minZoom: 3,
|
|
973
|
+
maxZoom: 18,
|
|
974
|
+
locale,
|
|
975
|
+
className: "h-full min-h-0 w-full rounded-md",
|
|
976
|
+
controlsClassName: "bg-card rounded-md shadow-md"
|
|
977
|
+
}),
|
|
978
|
+
radiusEnabled && selectedLocation ? /* @__PURE__ */ jsx5("p", {
|
|
979
|
+
className: "bg-card text-muted-foreground pointer-events-none absolute bottom-[25px] left-3 m-0 max-w-[calc(100%-24px)] rounded px-2.5 py-[7px] text-xs shadow-sm",
|
|
980
|
+
children: labels.radiusHint
|
|
981
|
+
}) : null
|
|
982
|
+
]
|
|
983
|
+
})
|
|
984
|
+
]
|
|
985
|
+
}),
|
|
986
|
+
/* @__PURE__ */ jsxs3(DialogFooter, {
|
|
987
|
+
className: "shrink-0 gap-3 border-0 bg-transparent px-5 pt-[18px] pb-[max(18px,env(safe-area-inset-bottom))] sm:px-7 [@media(max-height:599px)]:pt-3 [@media(max-height:599px)]:pb-[max(12px,env(safe-area-inset-bottom))]",
|
|
988
|
+
children: [
|
|
989
|
+
error || confirmFailed ? /* @__PURE__ */ jsx5("p", {
|
|
990
|
+
role: "alert",
|
|
991
|
+
className: "text-destructive w-full self-center text-sm sm:mr-auto sm:w-auto",
|
|
992
|
+
children: error ?? labels.confirmError
|
|
993
|
+
}) : null,
|
|
994
|
+
/* @__PURE__ */ jsxs3("div", {
|
|
995
|
+
className: "flex gap-2",
|
|
996
|
+
children: [
|
|
997
|
+
/* @__PURE__ */ jsx5(Button, {
|
|
998
|
+
type: "button",
|
|
999
|
+
variant: "outline",
|
|
1000
|
+
className: "bg-card min-h-11 flex-1",
|
|
1001
|
+
disabled: applying,
|
|
1002
|
+
onClick: () => changeOpen(false),
|
|
1003
|
+
children: labels.cancel
|
|
1004
|
+
}),
|
|
1005
|
+
/* @__PURE__ */ jsx5(Button, {
|
|
1006
|
+
type: "button",
|
|
1007
|
+
"data-slot": "map-menu-confirm",
|
|
1008
|
+
className: cn("min-h-11 flex-[2] bg-[oklch(0.9247_0.0524_66.1732)] text-zinc-950 hover:bg-[oklch(0.9247_0.0524_66.1732)] hover:brightness-95", confirmClassName),
|
|
1009
|
+
disabled: applying || !selectedMatchesInput || !selectedLocation,
|
|
1010
|
+
onClick: () => void confirm(),
|
|
1011
|
+
children: labels.confirm
|
|
1012
|
+
})
|
|
1013
|
+
]
|
|
1014
|
+
})
|
|
1015
|
+
]
|
|
1016
|
+
})
|
|
1017
|
+
]
|
|
1018
|
+
})
|
|
1019
|
+
]
|
|
1020
|
+
})
|
|
1021
|
+
});
|
|
1022
|
+
};
|
|
1023
|
+
export {
|
|
1024
|
+
MapMenu,
|
|
1025
|
+
MapMenuMode,
|
|
1026
|
+
mapMenuRadiiKm
|
|
1027
|
+
};
|