places-autocomplete-svelte 2.2.21 → 2.2.22
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/README.md +8 -3
- package/dist/PlaceAutocomplete.svelte +41 -10
- package/dist/PlaceAutocomplete.svelte.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/places-autocomplete-svelte)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[](https://
|
|
5
|
+
[](https://mapsplatform.google.com/awards/)
|
|
6
6
|
|
|
7
7
|
A flexible, accessible, and secure [Svelte](https://kit.svelte.dev) component leveraging the [Google Maps Places Autocomplete API (New)](https://developers.google.com/maps/documentation/javascript/place-autocomplete-overview). **Winner of the Google Maps Platform Awards 2025**, recognising excellence in Google Maps Platform development.
|
|
8
8
|
|
|
@@ -74,7 +74,7 @@ Explore live examples showcasing different features and use cases:
|
|
|
74
74
|
|
|
75
75
|
### 🏆 Google Maps Platform Awards 2025 Winner
|
|
76
76
|
<p align="left">
|
|
77
|
-
<a href="https://
|
|
77
|
+
<a href="https://mapsplatform.google.com/awards/">
|
|
78
78
|
<img src="badge.svg" alt="Google Maps Platform Awards 2025 Winner" width="200">
|
|
79
79
|
</a>
|
|
80
80
|
</p>
|
|
@@ -267,6 +267,9 @@ Get a reference to the component instance using `bind:this` to call its methods
|
|
|
267
267
|
<button onclick={() => autocompleteComponent?.setRequestParams({ region: 'FR', language: 'fr' })}>
|
|
268
268
|
Switch to French
|
|
269
269
|
</button>
|
|
270
|
+
<button onclick={() => autocompleteComponent?.setOptions({ placeholder: 'Search locations...', debounce: 300 })}>
|
|
271
|
+
Update Options
|
|
272
|
+
</button>
|
|
270
273
|
```
|
|
271
274
|
|
|
272
275
|
| Method | Signature | Description |
|
|
@@ -277,6 +280,8 @@ Get a reference to the component instance using `bind:this` to call its methods
|
|
|
277
280
|
| `setRequestParams(params)` | `(params: Partial<RequestParams>) => void` | Dynamically updates request parameters. Useful for changing search criteria (region, language, location bias, etc.). Parameters are merged with existing ones. |
|
|
278
281
|
| `setFetchFields(fields)` | `(fields: string[]) => void` | Dynamically updates the Place Data Fields to fetch when a place is selected. |
|
|
279
282
|
| `getFetchFields()` | `() => string[]` | Returns the current array of Place Data Fields that will be requested. |
|
|
283
|
+
| `setOptions(options)` | `(options: Partial<ComponentOptions>) => void` | Dynamically updates the component's configuration options. Merges the provided options with existing settings. |
|
|
284
|
+
| `getOptions()` | `() => ComponentOptions` | Returns the current validated options used by the component. Useful for inspecting configuration settings. |
|
|
280
285
|
|
|
281
286
|
## Options
|
|
282
287
|
|
|
@@ -387,7 +392,7 @@ This component is fully written in TypeScript with comprehensive type definition
|
|
|
387
392
|
|
|
388
393
|
**Component:**
|
|
389
394
|
```typescript
|
|
390
|
-
import PlaceAutocomplete from 'places-autocomplete-svelte';
|
|
395
|
+
import { PlaceAutocomplete } from 'places-autocomplete-svelte';
|
|
391
396
|
```
|
|
392
397
|
|
|
393
398
|
**Types and Interfaces:**
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
/**
|
|
74
74
|
* Create validated derived values that react to prop changes
|
|
75
75
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
let validatedOptions = $derived(validateOptions(options));
|
|
77
|
+
let validatedFetchFields = $derived(validateFetchFields(fetchFields));
|
|
78
|
+
let validatedRequestParams = $derived(validateRequestParams(requestParams));
|
|
79
79
|
|
|
80
80
|
/**
|
|
81
81
|
* Local variables
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
* @returns {RequestParams} The current request parameters object.
|
|
165
165
|
*/
|
|
166
166
|
export function getRequestParams() {
|
|
167
|
-
return
|
|
167
|
+
return validatedRequestParams;
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
/**
|
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
* });
|
|
188
188
|
*/
|
|
189
189
|
export function setRequestParams(params: Partial<typeof requestParams>) {
|
|
190
|
-
|
|
190
|
+
validatedRequestParams = validateRequestParams({ ...requestParams, ...params });
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
/**
|
|
@@ -200,7 +200,7 @@
|
|
|
200
200
|
* autocompleteComponent.setFetchFields(['displayName', 'types', 'location']);
|
|
201
201
|
*/
|
|
202
202
|
export function setFetchFields(fields: string[]) {
|
|
203
|
-
|
|
203
|
+
validatedFetchFields = validateFetchFields(fields);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
/**
|
|
@@ -212,9 +212,40 @@
|
|
|
212
212
|
* console.log('Current fields:', fields);
|
|
213
213
|
*/
|
|
214
214
|
export function getFetchFields(): string[] {
|
|
215
|
-
return
|
|
215
|
+
return validatedFetchFields;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Dynamically updates the component's configuration options.
|
|
220
|
+
* Merges the provided options with existing settings.
|
|
221
|
+
* @public
|
|
222
|
+
* @param options - Partial options object to update component behavior and appearance.
|
|
223
|
+
* @example
|
|
224
|
+
* // Update options to change placeholder and enable distance display
|
|
225
|
+
* autocompleteComponent.setOptions({
|
|
226
|
+
* placeholder: 'Enter a location',
|
|
227
|
+
* showDistance: true
|
|
228
|
+
* });
|
|
229
|
+
*/
|
|
230
|
+
export function setOptions(options: typeof validatedOptions){
|
|
231
|
+
validatedOptions = validateOptions(options);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Returns the current validated options used by the component.
|
|
237
|
+
* Useful for inspecting configuration settings.
|
|
238
|
+
* @public
|
|
239
|
+
* @returns {typeof validatedOptions} The current validated options object.
|
|
240
|
+
* @example
|
|
241
|
+
* const options = autocompleteComponent.getOptions();
|
|
242
|
+
* console.log('Current options:', options);
|
|
243
|
+
*/
|
|
244
|
+
export function getOptions(): typeof validatedOptions {
|
|
245
|
+
return validatedOptions;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
218
249
|
/**
|
|
219
250
|
* Extracts a specific address component from the place response.
|
|
220
251
|
* @private
|
|
@@ -317,10 +348,10 @@
|
|
|
317
348
|
|
|
318
349
|
/**
|
|
319
350
|
* Debounced version of makeAcRequest that delays API calls to reduce request frequency.
|
|
320
|
-
* The debounce delay is reactive and updates when the
|
|
351
|
+
* The debounce delay is reactive and updates when the validatedOptions.debounce value changes.
|
|
321
352
|
* @private
|
|
322
353
|
*/
|
|
323
|
-
const debouncedMakeAcRequest = $derived(debounce(makeAcRequest,
|
|
354
|
+
const debouncedMakeAcRequest = $derived(debounce(makeAcRequest, validatedOptions?.debounce ?? 100));
|
|
324
355
|
|
|
325
356
|
/**
|
|
326
357
|
* Handles the selection of an autocomplete suggestion.
|
|
@@ -388,7 +419,7 @@
|
|
|
388
419
|
// If the parent has already finished, this resolves immediately.
|
|
389
420
|
// If the parent is still loading, this will wait.
|
|
390
421
|
if (typeof gmaps !== 'undefined' && gmaps) {
|
|
391
|
-
await gmaps?.
|
|
422
|
+
await gmaps?.initialisationPromise;
|
|
392
423
|
} else {
|
|
393
424
|
// Check if the API key is provided
|
|
394
425
|
if (PUBLIC_GOOGLE_MAPS_API_KEY === '' || !PUBLIC_GOOGLE_MAPS_API_KEY) {
|
|
@@ -2,10 +2,12 @@ import type { Props } from './interfaces.js';
|
|
|
2
2
|
declare const PlaceAutocomplete: import("svelte").Component<Props, {
|
|
3
3
|
clear: () => void;
|
|
4
4
|
focus: () => void;
|
|
5
|
-
getRequestParams: () =>
|
|
5
|
+
getRequestParams: () => import("./interfaces.js").RequestParams;
|
|
6
6
|
setRequestParams: (params: Partial<import("./interfaces.js").RequestParams>) => void;
|
|
7
7
|
setFetchFields: (fields: string[]) => void;
|
|
8
8
|
getFetchFields: () => string[];
|
|
9
|
+
setOptions: (options: import("./interfaces.js").ComponentOptions) => void;
|
|
10
|
+
getOptions: () => import("./interfaces.js").ComponentOptions;
|
|
9
11
|
}, "onResponse" | "onError">;
|
|
10
12
|
type PlaceAutocomplete = ReturnType<typeof PlaceAutocomplete>;
|
|
11
13
|
export default PlaceAutocomplete;
|
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.22",
|
|
5
5
|
"description": "A flexible, accessible, and secure Svelte component leveraging the Google Maps Places Autocomplete API (New). Winner of the Google Maps Platform Awards 2025, recognising excellence in Google Maps Platform development.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"svelte",
|