places-autocomplete-svelte 2.1.8 → 2.1.9

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,6 +1,6 @@
1
1
  # Places (New) Autocomplete Svelte
2
2
 
3
- This Svelte component provides a user-friendly way to search for and retrieve detailed address information within your [SvelteKit](https://kit.svelte.dev) applications, leveraging the power of the [Google Maps Places (New) Autocomplete API](https://developers.google.com/maps/documentation/javascript/place-autocomplete-overview). It comes with default styling using [Tailwind CSS](https://tailwindcss.com/), which you can fully customize.
3
+ This Svelte component provides a user-friendly way to search for and retrieve detailed address information within your [SvelteKit](https://kit.svelte.dev) applications, leveraging the power of the [Google Maps Places (New) Autocomplete API](https://developers.google.com/maps/documentation/javascript/place-autocomplete-overview). It comes with default styling using [Tailwind CSS](https://tailwindcss.com/), which you can fully customise.
4
4
 
5
5
 
6
6
 
@@ -90,10 +90,10 @@ let onResponse = (response) => {
90
90
  | `placeholder` | `String` | Placeholder text for the input field. | `"Search..."` |
91
91
  | `autocomplete`| `string` | HTML `autocomplete` attribute for the input field. Set to `"off"` to disable browser autocomplete. | `"off"` |
92
92
  | `show_distance`| `boolean` | If `true`, and if an `origin` is specified in `requestParams`, displays the distance to each suggestion. The distance is calculated as a geodesic in meters. | `false` |
93
- | `classes` | `Object` | Object to override default Tailwind CSS classes.structure. | See [styling](https://places-autocomplete-demo.pages.dev/examples/styling) |
93
+ | `classes` | `Object` | Object to override default Tailwind CSS classes. | See [styling](https://places-autocomplete-demo.pages.dev/examples/styling) |
94
94
 
95
95
  ### Styling
96
- Customize the component's appearance by providing an object to the classes property. This object should contain key-value pairs, where the keys correspond to the component's elements and the values are your custom CSS class names. See [styling](https://places-autocomplete-demo.pages.dev/examples/styling) for details.
96
+ Customise the component's appearance by providing an object to the classes property. This object should contain key-value pairs, where the keys correspond to the component's elements and the values are your custom CSS class names. See [styling](https://places-autocomplete-demo.pages.dev/examples/styling) for details.
97
97
 
98
98
 
99
99
  ### Request Parameters (requestParams)
@@ -103,12 +103,6 @@ Fine-tune the autocomplete search with the requestParams property. This property
103
103
  <script>
104
104
  // ... other imports
105
105
 
106
- /**
107
- * @type boolean optional
108
- * Boolean attribute indicating that an element should be focused on page load.
109
- * default: false
110
- * */
111
- const autofocus = false;
112
106
  /**
113
107
  * @type object optional
114
108
  * AutocompleteRequest properties
@@ -128,12 +122,12 @@ const requestParams = {
128
122
  * @type object optional
129
123
  * Options
130
124
  */
131
- const options = {
132
- autofocus: false,
133
- autocompete: 'off',
134
- placeholder: 'Start typing your address',
135
- show_distance: true,
136
- };
125
+ const options = {
126
+ autofocus: false,
127
+ autocompete: 'off',
128
+ placeholder: 'Start typing your address',
129
+ show_distance: true,
130
+ };
137
131
 
138
132
  /**
139
133
  * @type array optional
package/dist/helpers.js CHANGED
@@ -43,7 +43,10 @@ export const requestParamsDefault = {
43
43
  * If neither are set, the results will be biased by IP address, meaning the IP address
44
44
  * will be mapped to an imprecise location and used as a biasing signal.
45
45
  */
46
- locationBias: null,
46
+ locationBias: {
47
+ lat: 0,
48
+ lng: 0
49
+ },
47
50
  /**
48
51
  * @param LocationRestriction optional
49
52
  * Restrict results to a specified location.
@@ -118,7 +121,7 @@ export const validateRequestParams = (requestParams) => {
118
121
  }
119
122
  }
120
123
  // merge requestParams with requestParamsDefault
121
- requestParams = Object.assign(requestParamsDefault, requestParams);
124
+ //requestParams = Object.assign(requestParamsDefault, requestParams);
122
125
  // Reset sessionToken to empty string if passed to the component
123
126
  if (requestParams.sessionToken) {
124
127
  requestParams.sessionToken = String('');
@@ -145,7 +148,7 @@ export const validateRequestParams = (requestParams) => {
145
148
  * If requestParams.includedRegionCodes is an array and has more than 15 items, slice it to 15
146
149
  */
147
150
  if (!Array.isArray(requestParams.includedRegionCodes)
148
- || (Array.isArray(requestParams.includedPrimaryTypes) && requestParams.includedPrimaryTypes.length === 0)) {
151
+ || (Array.isArray(requestParams.includedRegionCodes) && requestParams.includedRegionCodes.length === 0)) {
149
152
  delete requestParams.includedRegionCodes;
150
153
  }
151
154
  else if (Array.isArray(requestParams.includedRegionCodes) && requestParams.includedRegionCodes.length > 15) {
@@ -163,27 +166,38 @@ export const validateRequestParams = (requestParams) => {
163
166
  delete requestParams.language;
164
167
  }
165
168
  // If locationBias is not a string, remove it
166
- if (typeof requestParams.locationBias !== 'string') {
169
+ if (typeof requestParams.locationBias !== 'undefined'
170
+ && (!Object.keys(requestParams.locationBias).includes('lat') || !Object.keys(requestParams.locationBias).includes('lng'))
171
+ || requestParams.locationBias?.lat === 0
172
+ || requestParams.locationBias?.lng === 0) {
167
173
  delete requestParams.locationBias;
168
174
  }
169
175
  /**
170
176
  * If locationRestriction is not set, remove it
171
177
  */
172
- if (requestParams.locationRestriction?.east === 0
173
- && requestParams.locationRestriction?.north === 0
174
- && requestParams.locationRestriction?.south === 0
175
- && requestParams.locationRestriction?.west === 0) {
178
+ if (typeof requestParams.locationRestriction !== 'undefined'
179
+ && (!Object.keys(requestParams.locationRestriction).includes('east')
180
+ || !Object.keys(requestParams.locationRestriction).includes('north')
181
+ || !Object.keys(requestParams.locationRestriction).includes('south')
182
+ || !Object.keys(requestParams.locationRestriction).includes('west'))
183
+ || requestParams.locationRestriction?.east === 0
184
+ || requestParams.locationRestriction?.north === 0
185
+ || requestParams.locationRestriction?.south === 0
186
+ || requestParams.locationRestriction?.west === 0) {
176
187
  delete requestParams.locationRestriction;
177
188
  }
178
189
  // If origin is not set, remove it
179
- if (requestParams.origin?.lat === 0 && requestParams.origin?.lng === 0) {
190
+ if (typeof requestParams.origin !== 'undefined'
191
+ && (!Object.keys(requestParams.origin).includes('lat') || !Object.keys(requestParams.origin).includes('lng'))
192
+ || requestParams.origin?.lat === 0 || requestParams.origin?.lng === 0) {
180
193
  delete requestParams.origin;
181
194
  }
182
195
  // If region is not a string, remove it
183
196
  if (typeof requestParams.region !== 'string') {
184
197
  delete requestParams.region;
185
198
  }
186
- //console.log('requestParams:', Object.keys(requestParams));
199
+ // console.log('requestParams:', Object.keys(requestParams));
200
+ // console.log('requestParams:', requestParams);
187
201
  return requestParams;
188
202
  };
189
203
  /**
@@ -8,7 +8,10 @@ export interface RequestParams {
8
8
  includedRegionCodes?: string[];
9
9
  inputOffset?: number;
10
10
  language?: string;
11
- locationBias?: unknown | string;
11
+ locationBias?: {
12
+ lat: number;
13
+ lng: number;
14
+ };
12
15
  locationRestriction?: {
13
16
  west: number;
14
17
  south: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "places-autocomplete-svelte",
3
3
  "license": "MIT",
4
- "version": "2.1.8",
4
+ "version": "2.1.9",
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,30 +68,30 @@
68
68
  },
69
69
  "devDependencies": {
70
70
  "@sveltejs/adapter-auto": "^4.0.0",
71
- "@sveltejs/adapter-cloudflare": "^5.0.1",
72
- "@sveltejs/kit": "^2.16.1",
73
- "@sveltejs/package": "^2.3.9",
71
+ "@sveltejs/adapter-cloudflare": "^5.0.2",
72
+ "@sveltejs/kit": "^2.17.1",
73
+ "@sveltejs/package": "^2.3.10",
74
74
  "@sveltejs/vite-plugin-svelte": "^5.0.3",
75
- "@tailwindcss/postcss": "^4.0.3",
75
+ "@tailwindcss/postcss": "^4.0.5",
76
76
  "@tailwindcss/typography": "^0.5.16",
77
- "@tailwindcss/vite": "^4.0.3",
77
+ "@tailwindcss/vite": "^4.0.5",
78
78
  "@types/eslint": "^9.6.1",
79
79
  "autoprefixer": "^10.4.20",
80
- "eslint": "^9.19.0",
80
+ "eslint": "^9.20.0",
81
81
  "eslint-config-prettier": "^10.0.1",
82
82
  "eslint-plugin-svelte": "^2.46.1",
83
83
  "globals": "^15.14.0",
84
84
  "postcss": "^8.5.1",
85
85
  "prettier": "^3.4.2",
86
86
  "prettier-plugin-svelte": "^3.3.3",
87
- "publint": "^0.3.2",
88
- "svelte": "^5.19.6",
87
+ "publint": "^0.3.4",
88
+ "svelte": "^5.19.9",
89
89
  "svelte-check": "^4.1.4",
90
- "tailwindcss": "^4.0.3",
90
+ "tailwindcss": "^4.0.5",
91
91
  "tslib": "^2.8.1",
92
92
  "typescript": "^5.7.3",
93
- "typescript-eslint": "^8.22.0",
94
- "vite": "^6.0.11"
93
+ "typescript-eslint": "^8.23.0",
94
+ "vite": "^6.1.0"
95
95
  },
96
96
  "svelte": "./dist/index.js",
97
97
  "types": "./dist/PlaceAutocomplete.svelte.d.ts",