@aiaiai-pt/design-system 0.5.2 → 0.5.4
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.
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component GeoSearch
|
|
3
|
+
|
|
4
|
+
Geocoding search input powered by Nominatim (OpenStreetMap).
|
|
5
|
+
Wraps Combobox with built-in address/place search and debounced API calls.
|
|
6
|
+
Emits lon/lat coordinates when a result is selected.
|
|
7
|
+
Consumes --combobox-* tokens from components.css.
|
|
8
|
+
|
|
9
|
+
@example Basic
|
|
10
|
+
<GeoSearch onlocation={(lon, lat) => console.log(lon, lat)} />
|
|
11
|
+
|
|
12
|
+
@example With label and bounding box bias
|
|
13
|
+
<GeoSearch
|
|
14
|
+
label="Search location"
|
|
15
|
+
placeholder="City, address, or place..."
|
|
16
|
+
viewbox={[-9.5, 38.5, -8.8, 39.0]}
|
|
17
|
+
onlocation={(lon, lat) => { mapCenter = [lon, lat]; mapZoom = 15; }}
|
|
18
|
+
/>
|
|
19
|
+
|
|
20
|
+
@example Custom provider URL
|
|
21
|
+
<GeoSearch
|
|
22
|
+
providerUrl="https://my-nominatim.example.com/search"
|
|
23
|
+
onlocation={(lon, lat) => console.log(lon, lat)}
|
|
24
|
+
/>
|
|
25
|
+
-->
|
|
26
|
+
<script>
|
|
27
|
+
import Combobox from './Combobox.svelte';
|
|
28
|
+
|
|
29
|
+
let {
|
|
30
|
+
/** @type {string | undefined} */
|
|
31
|
+
label = undefined,
|
|
32
|
+
/** @type {string} */
|
|
33
|
+
placeholder = 'Search address or place...',
|
|
34
|
+
/** @type {boolean} */
|
|
35
|
+
disabled = false,
|
|
36
|
+
/** @type {string | undefined} */
|
|
37
|
+
error = undefined,
|
|
38
|
+
/** @type {string | undefined} */
|
|
39
|
+
help = undefined,
|
|
40
|
+
/** @type {string} */
|
|
41
|
+
size = 'md',
|
|
42
|
+
/** @type {string} — Nominatim-compatible search endpoint */
|
|
43
|
+
providerUrl = 'https://nominatim.openstreetmap.org/search',
|
|
44
|
+
/** @type {[number, number, number, number] | undefined} — [minLon, minLat, maxLon, maxLat] bias */
|
|
45
|
+
viewbox = undefined,
|
|
46
|
+
/** @type {((lon: number, lat: number, item: { label: string, value: string }) => void) | undefined} */
|
|
47
|
+
onlocation = undefined,
|
|
48
|
+
/** @type {string} */
|
|
49
|
+
class: className = '',
|
|
50
|
+
...rest
|
|
51
|
+
} = $props();
|
|
52
|
+
|
|
53
|
+
/** @type {import('./Combobox.svelte').ComboboxItem[]} */
|
|
54
|
+
let items = $state([]);
|
|
55
|
+
let loading = $state(false);
|
|
56
|
+
let value = $state('');
|
|
57
|
+
let debounceTimer = 0;
|
|
58
|
+
|
|
59
|
+
/** Nominatim rate limit: 1 req/sec. Debounce at 400ms. */
|
|
60
|
+
function handleSearch(query) {
|
|
61
|
+
clearTimeout(debounceTimer);
|
|
62
|
+
if (!query || query.length < 3) {
|
|
63
|
+
items = [];
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
loading = true;
|
|
67
|
+
debounceTimer = setTimeout(() => fetchResults(query), 400);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async function fetchResults(query) {
|
|
71
|
+
try {
|
|
72
|
+
const params = new URLSearchParams({
|
|
73
|
+
q: query,
|
|
74
|
+
format: 'json',
|
|
75
|
+
limit: '6',
|
|
76
|
+
addressdetails: '1',
|
|
77
|
+
});
|
|
78
|
+
if (viewbox) {
|
|
79
|
+
params.set('viewbox', viewbox.join(','));
|
|
80
|
+
params.set('bounded', '0'); // bias, not restrict
|
|
81
|
+
}
|
|
82
|
+
const resp = await fetch(`${providerUrl}?${params}`, {
|
|
83
|
+
headers: { 'Accept': 'application/json' },
|
|
84
|
+
});
|
|
85
|
+
if (!resp.ok) {
|
|
86
|
+
items = [];
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
/** @type {Array<{lat: string, lon: string, display_name: string, type: string, class: string}>} */
|
|
90
|
+
const results = await resp.json();
|
|
91
|
+
items = results.map((r) => ({
|
|
92
|
+
value: `${r.lon},${r.lat}`,
|
|
93
|
+
label: r.display_name,
|
|
94
|
+
description: r.type !== 'yes' ? r.type.replace(/_/g, ' ') : r.class.replace(/_/g, ' '),
|
|
95
|
+
}));
|
|
96
|
+
} catch {
|
|
97
|
+
items = [];
|
|
98
|
+
} finally {
|
|
99
|
+
loading = false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function handleChange(val) {
|
|
104
|
+
if (!val) return;
|
|
105
|
+
const [lonStr, latStr] = val.split(',');
|
|
106
|
+
const lon = parseFloat(lonStr);
|
|
107
|
+
const lat = parseFloat(latStr);
|
|
108
|
+
if (!Number.isNaN(lon) && !Number.isNaN(lat) && onlocation) {
|
|
109
|
+
const selectedItem = items.find((i) => i.value === val);
|
|
110
|
+
onlocation(lon, lat, selectedItem ?? { label: '', value: val });
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<Combobox
|
|
116
|
+
{label}
|
|
117
|
+
{placeholder}
|
|
118
|
+
{disabled}
|
|
119
|
+
{error}
|
|
120
|
+
{help}
|
|
121
|
+
{size}
|
|
122
|
+
{items}
|
|
123
|
+
{loading}
|
|
124
|
+
bind:value
|
|
125
|
+
onsearch={handleSearch}
|
|
126
|
+
onchange={handleChange}
|
|
127
|
+
class={className}
|
|
128
|
+
{...rest}
|
|
129
|
+
/>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export default GeoSearch;
|
|
2
|
+
type GeoSearch = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* GeoSearch
|
|
8
|
+
*
|
|
9
|
+
* Geocoding search input powered by Nominatim (OpenStreetMap).
|
|
10
|
+
* Wraps Combobox with built-in address/place search and debounced API calls.
|
|
11
|
+
* Emits lon/lat coordinates when a result is selected.
|
|
12
|
+
* Consumes --combobox-* tokens from components.css.
|
|
13
|
+
*
|
|
14
|
+
* @example Basic
|
|
15
|
+
* <GeoSearch onlocation={(lon, lat) => console.log(lon, lat)} />
|
|
16
|
+
*
|
|
17
|
+
* @example With label and bounding box bias
|
|
18
|
+
* <GeoSearch
|
|
19
|
+
* label="Search location"
|
|
20
|
+
* placeholder="City, address, or place..."
|
|
21
|
+
* viewbox={[-9.5, 38.5, -8.8, 39.0]}
|
|
22
|
+
* onlocation={(lon, lat) => { mapCenter = [lon, lat]; mapZoom = 15; }}
|
|
23
|
+
* />
|
|
24
|
+
*
|
|
25
|
+
* @example Custom provider URL
|
|
26
|
+
* <GeoSearch
|
|
27
|
+
* providerUrl="https://my-nominatim.example.com/search"
|
|
28
|
+
* onlocation={(lon, lat) => console.log(lon, lat)}
|
|
29
|
+
* />
|
|
30
|
+
*/
|
|
31
|
+
declare const GeoSearch: import("svelte").Component<{
|
|
32
|
+
label?: any;
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
error?: any;
|
|
36
|
+
help?: any;
|
|
37
|
+
size?: string;
|
|
38
|
+
providerUrl?: string;
|
|
39
|
+
viewbox?: any;
|
|
40
|
+
onlocation?: any;
|
|
41
|
+
class?: string;
|
|
42
|
+
} & Record<string, any>, {}, "">;
|
|
43
|
+
type $$ComponentProps = {
|
|
44
|
+
label?: any;
|
|
45
|
+
placeholder?: string;
|
|
46
|
+
disabled?: boolean;
|
|
47
|
+
error?: any;
|
|
48
|
+
help?: any;
|
|
49
|
+
size?: string;
|
|
50
|
+
providerUrl?: string;
|
|
51
|
+
viewbox?: any;
|
|
52
|
+
onlocation?: any;
|
|
53
|
+
class?: string;
|
|
54
|
+
} & Record<string, any>;
|
package/components/index.js
CHANGED
|
@@ -96,6 +96,7 @@ export { default as MapPicker } from "./MapPicker.svelte";
|
|
|
96
96
|
export { default as MapCluster } from "./MapCluster.svelte";
|
|
97
97
|
export { default as MapHeatmap } from "./MapHeatmap.svelte";
|
|
98
98
|
export { default as MapPopup } from "./MapPopup.svelte";
|
|
99
|
+
export { default as GeoSearch } from "./GeoSearch.svelte";
|
|
99
100
|
|
|
100
101
|
// Scheduling
|
|
101
102
|
export { default as Calendar } from "./Calendar.svelte";
|