places-autocomplete-svelte 2.2.1 → 2.2.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/dist/PlaceAutocomplete.svelte +43 -25
- package/dist/helpers.js +9 -2
- package/package.json +13 -13
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount } from 'svelte';
|
|
3
3
|
import * as GMaps from '@googlemaps/js-api-loader';
|
|
4
|
-
import type {Props } from './interfaces.js';
|
|
4
|
+
import type { Props } from './interfaces.js';
|
|
5
5
|
import { validateOptions, validateRequestParams, formatDistance } from './helpers.js';
|
|
6
6
|
const { Loader } = GMaps;
|
|
7
7
|
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
// set classes as state
|
|
26
26
|
let cl = $state(options.classes);
|
|
27
27
|
|
|
28
|
-
|
|
29
28
|
// reset keyboard classes
|
|
30
29
|
const resetKbdClasses = () => {
|
|
31
30
|
cl.kbd_down = options.classes.kbd_down;
|
|
@@ -39,7 +38,6 @@
|
|
|
39
38
|
let loader: GMaps.Loader;
|
|
40
39
|
let placesApi: { [key: string]: any } = {};
|
|
41
40
|
|
|
42
|
-
|
|
43
41
|
//https://developers.google.com/maps/documentation/javascript/reference/autocomplete-data
|
|
44
42
|
// validate requestParams
|
|
45
43
|
requestParams = validateRequestParams(requestParams);
|
|
@@ -92,15 +90,17 @@
|
|
|
92
90
|
const { suggestions } =
|
|
93
91
|
await placesApi.AutocompleteSuggestion.fetchAutocompleteSuggestions(request);
|
|
94
92
|
results = [];
|
|
95
|
-
const formatter = new Intl.NumberFormat('en');
|
|
93
|
+
//const formatter = new Intl.NumberFormat('en');
|
|
96
94
|
// iterate suggestions and add results to an array
|
|
97
95
|
for (const suggestion of suggestions) {
|
|
98
|
-
|
|
99
96
|
// add suggestions to results
|
|
100
97
|
results.push({
|
|
101
|
-
|
|
98
|
+
place: suggestion.placePrediction.toPlace(),
|
|
102
99
|
text: suggestion.placePrediction.text.toString(),
|
|
103
|
-
distance: formatDistance(
|
|
100
|
+
distance: formatDistance(
|
|
101
|
+
suggestion.placePrediction.distanceMeters,
|
|
102
|
+
options.distance_units ?? 'km'
|
|
103
|
+
)
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
} catch (e: any) {
|
|
@@ -164,8 +164,13 @@
|
|
|
164
164
|
|
|
165
165
|
const { AutocompleteSessionToken, AutocompleteSuggestion } =
|
|
166
166
|
await loader.importLibrary('places');
|
|
167
|
+
|
|
167
168
|
placesApi.AutocompleteSessionToken = AutocompleteSessionToken;
|
|
168
169
|
placesApi.AutocompleteSuggestion = AutocompleteSuggestion;
|
|
170
|
+
|
|
171
|
+
// const {Geocoder} = await loader.importLibrary("geocoding");
|
|
172
|
+
// placesApi.Geocoder = new Geocoder();
|
|
173
|
+
|
|
169
174
|
setSessionToken();
|
|
170
175
|
} catch (e: any) {
|
|
171
176
|
onError(
|
|
@@ -188,7 +193,7 @@
|
|
|
188
193
|
} else if (e.key === 'Enter') {
|
|
189
194
|
e.preventDefault();
|
|
190
195
|
if (currentSuggestion >= 0) {
|
|
191
|
-
onPlaceSelected(results[currentSuggestion].
|
|
196
|
+
onPlaceSelected(results[currentSuggestion].place);
|
|
192
197
|
}
|
|
193
198
|
} else if (e.key === 'Escape') {
|
|
194
199
|
// reset srarch input and results
|
|
@@ -211,7 +216,6 @@
|
|
|
211
216
|
</div>
|
|
212
217
|
{/if}
|
|
213
218
|
|
|
214
|
-
|
|
215
219
|
<input
|
|
216
220
|
type="text"
|
|
217
221
|
name="search"
|
|
@@ -237,7 +241,7 @@
|
|
|
237
241
|
</div>
|
|
238
242
|
|
|
239
243
|
<ul class={options.classes.ul} id="options">
|
|
240
|
-
{#each results as
|
|
244
|
+
{#each results as p, i}
|
|
241
245
|
<li
|
|
242
246
|
class={[options.classes.li, i === currentSuggestion && options.classes.li_current]}
|
|
243
247
|
id="option-{i + 1}"
|
|
@@ -245,25 +249,39 @@
|
|
|
245
249
|
<!-- svelte-ignore a11y_invalid_attribute -->
|
|
246
250
|
<a
|
|
247
251
|
href="javascript:void(0)"
|
|
248
|
-
class={[
|
|
252
|
+
class={[
|
|
253
|
+
options.classes?.li_a,
|
|
254
|
+
i === currentSuggestion && options.classes.li_a_current
|
|
255
|
+
]}
|
|
249
256
|
tabindex={i + 1}
|
|
250
|
-
onclick={() => onPlaceSelected(place
|
|
257
|
+
onclick={() => onPlaceSelected(p.place)}
|
|
251
258
|
>
|
|
252
|
-
<div class=
|
|
253
|
-
|
|
254
|
-
class=
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
<p
|
|
260
|
-
|
|
259
|
+
<div class={[options.classes.li_div_container]}>
|
|
260
|
+
<div
|
|
261
|
+
class={[
|
|
262
|
+
options.classes.li_div_one,
|
|
263
|
+
i === currentSuggestion && options.classes.li_div_current
|
|
264
|
+
]}
|
|
265
|
+
>
|
|
266
|
+
<p
|
|
267
|
+
class={[
|
|
268
|
+
i === currentSuggestion && options.classes.li_current,
|
|
269
|
+
options.classes.li_div_one_p
|
|
270
|
+
]}
|
|
271
|
+
>
|
|
272
|
+
{p.text}
|
|
273
|
+
</p>
|
|
261
274
|
</div>
|
|
262
275
|
</div>
|
|
263
|
-
{#if options.distance &&
|
|
264
|
-
<div class=
|
|
265
|
-
<p
|
|
266
|
-
{
|
|
276
|
+
{#if options.distance && p.distance}
|
|
277
|
+
<div class={[options.classes.li_div_two]}>
|
|
278
|
+
<p
|
|
279
|
+
class={[
|
|
280
|
+
i === currentSuggestion && options.classes.li_current,
|
|
281
|
+
options.classes.li_div_two_p
|
|
282
|
+
]}
|
|
283
|
+
>
|
|
284
|
+
{p.distance}
|
|
267
285
|
</p>
|
|
268
286
|
</div>
|
|
269
287
|
{/if}
|
package/dist/helpers.js
CHANGED
|
@@ -201,10 +201,17 @@ export const componentClasses = {
|
|
|
201
201
|
kbd_escape: 'inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1',
|
|
202
202
|
kbd_up: 'inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6',
|
|
203
203
|
kbd_down: 'inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6',
|
|
204
|
+
kbd_active: 'bg-indigo-500 text-white',
|
|
204
205
|
ul: 'absolute z-50 -mb-2 mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm divide-y divide-gray-100',
|
|
205
206
|
li: 'z-50 cursor-default select-none py-2 px-2 lg:px-4 text-gray-900 hover:bg-indigo-500 hover:text-white',
|
|
206
|
-
li_current: 'bg-indigo-500
|
|
207
|
-
li_a: 'block w-full',
|
|
207
|
+
li_current: 'bg-indigo-500',
|
|
208
|
+
li_a: 'block w-full flex justify-between',
|
|
209
|
+
li_a_current: 'text-white',
|
|
210
|
+
li_div_container: 'flex min-w-0 gap-x-4',
|
|
211
|
+
li_div_one: 'min-w-0 flex-auto',
|
|
212
|
+
li_div_one_p: 'text-sm/6 font-semibold',
|
|
213
|
+
li_div_two: 'shrink-0 flex flex-col items-end min-w-16',
|
|
214
|
+
li_div_two_p: 'mt-1 text-xs/5'
|
|
208
215
|
};
|
|
209
216
|
/**
|
|
210
217
|
* Default component options
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "places-autocomplete-svelte",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "2.2.
|
|
4
|
+
"version": "2.2.2",
|
|
5
5
|
"description": "A lightweight and customizable Svelte component for easy integration of Google Maps Places (New) Autocomplete in your Svelte/SvelteKit applications. Provides accessible autocomplete suggestions and detailed address retrieval.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"svelte",
|
|
@@ -68,29 +68,29 @@
|
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"@sveltejs/adapter-auto": "^4.0.0",
|
|
71
|
-
"@sveltejs/adapter-cloudflare": "^5.0.
|
|
72
|
-
"@sveltejs/kit": "^2.17.
|
|
71
|
+
"@sveltejs/adapter-cloudflare": "^5.0.3",
|
|
72
|
+
"@sveltejs/kit": "^2.17.2",
|
|
73
73
|
"@sveltejs/package": "^2.3.10",
|
|
74
74
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
75
|
-
"@tailwindcss/postcss": "^4.0.
|
|
75
|
+
"@tailwindcss/postcss": "^4.0.6",
|
|
76
76
|
"@tailwindcss/typography": "^0.5.16",
|
|
77
|
-
"@tailwindcss/vite": "^4.0.
|
|
77
|
+
"@tailwindcss/vite": "^4.0.6",
|
|
78
78
|
"@types/eslint": "^9.6.1",
|
|
79
79
|
"autoprefixer": "^10.4.20",
|
|
80
|
-
"eslint": "^9.20.
|
|
80
|
+
"eslint": "^9.20.1",
|
|
81
81
|
"eslint-config-prettier": "^10.0.1",
|
|
82
82
|
"eslint-plugin-svelte": "^2.46.1",
|
|
83
|
-
"globals": "^15.
|
|
84
|
-
"postcss": "^8.5.
|
|
85
|
-
"prettier": "^3.
|
|
83
|
+
"globals": "^15.15.0",
|
|
84
|
+
"postcss": "^8.5.2",
|
|
85
|
+
"prettier": "^3.5.1",
|
|
86
86
|
"prettier-plugin-svelte": "^3.3.3",
|
|
87
|
-
"publint": "^0.3.
|
|
88
|
-
"svelte": "^5.
|
|
87
|
+
"publint": "^0.3.5",
|
|
88
|
+
"svelte": "^5.20.1",
|
|
89
89
|
"svelte-check": "^4.1.4",
|
|
90
|
-
"tailwindcss": "^4.0.
|
|
90
|
+
"tailwindcss": "^4.0.6",
|
|
91
91
|
"tslib": "^2.8.1",
|
|
92
92
|
"typescript": "^5.7.3",
|
|
93
|
-
"typescript-eslint": "^8.
|
|
93
|
+
"typescript-eslint": "^8.24.0",
|
|
94
94
|
"vite": "^6.1.0"
|
|
95
95
|
},
|
|
96
96
|
"svelte": "./dist/index.js",
|