places-autocomplete-svelte 2.2.21 → 2.2.23

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 CHANGED
@@ -1,10 +1,11 @@
1
1
  # Places (New) Autocomplete Svelte
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/places-autocomplete-svelte.svg)](https://badge.fury.io/js/places-autocomplete-svelte)
4
+ [![npm downloads](https://img.shields.io/npm/dm/places-autocomplete-svelte.svg)](https://www.npmjs.com/package/places-autocomplete-svelte)
4
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
- [![Google Maps Platform Awards 2025](https://img.shields.io/badge/Google%20Maps%20Platform-Awards%202025%20Winner-4285F4?style=flat&logo=google-maps&logoColor=white)](https://developers.google.com/maps)
6
+ [![Google Maps Platform Awards 2025](https://img.shields.io/badge/Google%20Maps%20Platform-Awards%202025%20Winner-4285F4?style=flat&logo=google-maps&logoColor=white)](https://mapsplatform.google.com/awards/)
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
+ A flexible, accessible, and secure [Svelte 5](https://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
9
 
9
10
  The component handles API loading, session tokens, debounced fetching, and accessibility, allowing you to focus on building your application. It intelligently manages the Google Maps API loader, creating a shared instance via Svelte's context that prevents conflicts with other map components on the same page.
10
11
 
@@ -22,17 +23,23 @@ The component handles API loading, session tokens, debounced fetching, and acces
22
23
  - [Usage](#usage)
23
24
  - [Basic Usage](#basic-usage-automatic-initialisation)
24
25
  - [Advanced Usage](#advanced-usage-manual-initialisation)
25
- - [Props](#props)
26
- - [Component Methods](#component-methods-imperative-api)
27
- - [Options](#options)
26
+ - [API Reference](#api-reference)
27
+ - [Props](#props)
28
+ - [Component Methods](#component-methods-imperative-api)
29
+ - [Options](#options)
30
+ - [Events](#events)
28
31
  - [Styling](#styling)
29
- - [Events](#events)
30
32
  - [TypeScript](#typescript)
31
33
  - [Security](#security)
34
+ - [API Key Security](#api-key-security)
35
+ - [XSS Protection](#xss-protection)
32
36
  - [Accessibility](#accessibility)
33
37
  - [Google Places API & Billing](#google-places-api--billing)
38
+ - [Browser Compatibility](#browser-compatibility)
39
+ - [Troubleshooting](#troubleshooting)
34
40
  - [Standalone JavaScript Library](#standalone-javascript-library)
35
41
  - [Contributing](#contributing)
42
+ - [Author](#author)
36
43
  - [License](#license)
37
44
 
38
45
  ## Features
@@ -60,31 +67,34 @@ The component handles API loading, session tokens, debounced fetching, and acces
60
67
 
61
68
  Explore live examples showcasing different features and use cases:
62
69
 
63
- **[🚀 Basic Example](https://places-autocomplete-demo.pages.dev/)** - Get started with the simplest implementation
70
+ **[🚀 Basic Example](https://places-autocomplete-svelte.uk/examples/basic)** - Get started with the simplest implementation
64
71
 
65
- **[🔄 Reactive Parameters](https://places-autocomplete-demo.pages.dev/examples/reactive-parameters)** - Dynamically change search criteria based on user input, such as filtering by country or switching languages
72
+ **[🔄 Reactive Parameters](https://places-autocomplete-svelte.uk/examples/reactive-parameters)** - Dynamically change search criteria based on user input, such as filtering by country or switching languages
66
73
 
67
- **[⚙️ Custom Request Parameters](https://places-autocomplete-demo.pages.dev/examples/customise-request-parameters)** - Configure advanced search options including language, region, location bias, and place types
74
+ **[⚙️ Checkout Form](https://places-autocomplete-svelte.uk/examples/checkout-form)** - Capture the detailed address data from a user's selection and use it to automatically populate the fields of a checkout form.
68
75
 
69
- **[📝 Retain Input Value](https://places-autocomplete-demo.pages.dev/examples/retain-input-value)** - Keep the selected address visible in the input field after selection
76
+ **[📝 Distance & Proximity Filter](https://places-autocomplete-svelte.uk/examples/proximity-filter)** - Restrict or bias search results to a specific area.
70
77
 
71
78
  <img src="places-autocomplete-svelte.gif" alt="A video demonstrating the Places Autocomplete Svelte component in action, showing address suggestions and selection.">
72
79
 
73
80
  ## Recognition
74
81
 
75
82
  ### 🏆 Google Maps Platform Awards 2025 Winner
83
+
76
84
  <p align="left">
77
- <a href="https://developers.google.com/maps">
85
+ <a href="https://mapsplatform.google.com/awards/">
78
86
  <img src="badge.svg" alt="Google Maps Platform Awards 2025 Winner" width="200">
79
87
  </a>
80
88
  </p>
81
89
 
82
90
  This component has been recognised as a winner of the **Google Maps Platform Awards 2025** by the Google Developer Program. This award celebrates outstanding projects that demonstrate exceptional use of Google Maps Platform APIs, innovation, and contribution to the developer community.
83
91
 
84
- [Learn more about the Google Maps Platform Awards](https://developers.google.com/maps)
92
+ [Learn more about the Google Maps Platform Awards](https://mapsplatform.google.com/awards/)
85
93
 
86
94
  ## Requirements
87
95
 
96
+ * **Svelte 5+** - This component requires Svelte 5.0.0 or higher and uses Svelte 5 features including runes (`$state`, `$derived`, etc.)
97
+ * **Node.js 18+** - Required for development and building
88
98
  * **Google Maps API Key** with the "Places API" enabled. Refer to [Use API Keys](https://developers.google.com/maps/documentation/javascript/get-api-key) for detailed instructions.
89
99
 
90
100
  ## Installation
@@ -93,6 +103,8 @@ This component has been recognised as a winner of the **Google Maps Platform Awa
93
103
  npm install places-autocomplete-svelte
94
104
  # or
95
105
  yarn add places-autocomplete-svelte
106
+ # or
107
+ pnpm add places-autocomplete-svelte
96
108
  ```
97
109
 
98
110
  ## Usage
@@ -212,6 +224,10 @@ For applications using multiple Google Maps libraries (e.g., `places`, `maps`, `
212
224
  - `initialiseGMapsNoContext(options)` - Initialises without context (for edge cases)
213
225
  - `importLibrary(library)` - Dynamically imports Google Maps libraries
214
226
 
227
+ ## API Reference
228
+
229
+ The following sections detail the component's props, methods, options, and events.
230
+
215
231
  ## Security
216
232
 
217
233
  ### API Key Security
@@ -252,11 +268,12 @@ This component is built to be accessible and follows the [WAI-ARIA Authoring Pra
252
268
 
253
269
  Get a reference to the component instance using `bind:this` to call its methods directly.
254
270
 
255
- **Example:**
271
+ **Example (Svelte 5 syntax):**
256
272
 
257
273
  ```javascript
258
274
  <script lang="ts">
259
275
  import PlaceAutocomplete from 'places-autocomplete-svelte';
276
+ // Note: Using Svelte 5 $state rune
260
277
  let autocompleteComponent: PlaceAutocomplete | undefined = $state(undefined);
261
278
  </script>
262
279
 
@@ -267,6 +284,9 @@ Get a reference to the component instance using `bind:this` to call its methods
267
284
  <button onclick={() => autocompleteComponent?.setRequestParams({ region: 'FR', language: 'fr' })}>
268
285
  Switch to French
269
286
  </button>
287
+ <button onclick={() => autocompleteComponent?.setOptions({ placeholder: 'Search locations...', debounce: 300 })}>
288
+ Update Options
289
+ </button>
270
290
  ```
271
291
 
272
292
  | Method | Signature | Description |
@@ -277,6 +297,8 @@ Get a reference to the component instance using `bind:this` to call its methods
277
297
  | `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
298
  | `setFetchFields(fields)` | `(fields: string[]) => void` | Dynamically updates the Place Data Fields to fetch when a place is selected. |
279
299
  | `getFetchFields()` | `() => string[]` | Returns the current array of Place Data Fields that will be requested. |
300
+ | `setOptions(options)` | `(options: Partial<ComponentOptions>) => void` | Dynamically updates the component's configuration options. Merges the provided options with existing settings. |
301
+ | `getOptions()` | `() => ComponentOptions` | Returns the current validated options used by the component. Useful for inspecting configuration settings. |
280
302
 
281
303
  ## Options
282
304
 
@@ -387,7 +409,7 @@ This component is fully written in TypeScript with comprehensive type definition
387
409
 
388
410
  **Component:**
389
411
  ```typescript
390
- import PlaceAutocomplete from 'places-autocomplete-svelte';
412
+ import { PlaceAutocomplete } from 'places-autocomplete-svelte';
391
413
  ```
392
414
 
393
415
  **Types and Interfaces:**
@@ -416,7 +438,7 @@ import {
416
438
  } from 'places-autocomplete-svelte/gmaps';
417
439
  ```
418
440
 
419
- ## Security
441
+ ## Google Places API & Billing
420
442
 
421
443
  * This component uses the Google Maps JavaScript API (Places library). Usage is subject to Google's terms and pricing.
422
444
  * **Session Tokens** are used automatically to group Autocomplete requests, which can reduce costs.
@@ -73,9 +73,9 @@
73
73
  /**
74
74
  * Create validated derived values that react to prop changes
75
75
  */
76
- const validatedOptions = $derived(validateOptions(options));
77
- const validatedFetchFields = $derived(validateFetchFields(fetchFields));
78
- const validatedRequestParams = $derived(validateRequestParams(requestParams));
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 request;
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
- requestParams = { ...requestParams, ...params };
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
- fetchFields = fields;
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 fetchFields;
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 options.debounce value changes.
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, options?.debounce ?? 100));
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?.initializationPromise;
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: () => any;
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;
@@ -64,7 +64,7 @@ export interface ComponentClasses {
64
64
  * Controls browser autofill behavior for the input field.
65
65
  * @type {"on" | "off"}
66
66
  */
67
- export type AutoFill = "on" | "off";
67
+ export type AutoFill = "on" | "off" | string;
68
68
  /**
69
69
  * Distance measurement units for displaying place distances.
70
70
  * @type {"km" | "miles"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "places-autocomplete-svelte",
3
3
  "license": "MIT",
4
- "version": "2.2.21",
4
+ "version": "2.2.23",
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",
@@ -77,19 +77,19 @@
77
77
  "devDependencies": {
78
78
  "@sveltejs/adapter-auto": "^7.0.0",
79
79
  "@sveltejs/adapter-cloudflare": "^7.2.4",
80
- "@sveltejs/kit": "^2.49.2",
80
+ "@sveltejs/kit": "^2.49.4",
81
81
  "@sveltejs/package": "^2.5.7",
82
- "@sveltejs/vite-plugin-svelte": "^6.2.1",
82
+ "@sveltejs/vite-plugin-svelte": "^6.2.4",
83
83
  "@tailwindcss/postcss": "^4.1.18",
84
84
  "@tailwindcss/typography": "^0.5.19",
85
85
  "@tailwindcss/vite": "^4.1.18",
86
86
  "@types/eslint": "^9.6.1",
87
87
  "@types/google.maps": "^3.58.1",
88
- "@types/node": "^25.0.3",
88
+ "@types/node": "^25.0.6",
89
89
  "autoprefixer": "^10.4.23",
90
90
  "eslint": "^9.39.2",
91
91
  "eslint-config-prettier": "^10.1.8",
92
- "eslint-plugin-svelte": "^3.13.1",
92
+ "eslint-plugin-svelte": "^3.14.0",
93
93
  "globals": "^17.0.0",
94
94
  "postcss": "^8.5.6",
95
95
  "prettier": "^3.7.4",
@@ -100,8 +100,8 @@
100
100
  "tailwindcss": "^4.1.18",
101
101
  "tslib": "^2.8.1",
102
102
  "typescript": "^5.9.3",
103
- "typescript-eslint": "^8.51.0",
104
- "vite": "^7.3.0"
103
+ "typescript-eslint": "^8.52.0",
104
+ "vite": "^7.3.1"
105
105
  },
106
106
  "svelte": "./dist/index.js",
107
107
  "types": "./dist/PlaceAutocomplete.svelte.d.ts",