places-autocomplete-js 1.0.12 → 1.1.0
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.
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
1
|
+
var J = Object.defineProperty;
|
|
2
2
|
var B = (c) => {
|
|
3
3
|
throw TypeError(c);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var H = (c, t,
|
|
7
|
-
var e = (c, t,
|
|
5
|
+
var U = (c, t, s) => t in c ? J(c, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : c[t] = s;
|
|
6
|
+
var H = (c, t, s) => U(c, typeof t != "symbol" ? t + "" : t, s), V = (c, t, s) => t.has(c) || B("Cannot " + s);
|
|
7
|
+
var e = (c, t, s) => (V(c, t, "read from private field"), s ? s.call(c) : t.get(c)), h = (c, t, s) => t.has(c) ? B("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(c) : t.set(c, s), o = (c, t, s, i) => (V(c, t, "write to private field"), i ? i.call(c, s) : t.set(c, s), s);
|
|
8
8
|
/**
|
|
9
9
|
* Initializes a Places Autocomplete widget.
|
|
10
10
|
* This script dynamically loads the Google Maps JavaScript API, creates the UI elements
|
|
@@ -16,8 +16,8 @@ var e = (c, t, i) => (V(c, t, "read from private field"), i ? i.call(c) : t.get(
|
|
|
16
16
|
* @license MIT
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
|
-
var
|
|
20
|
-
class
|
|
19
|
+
var M, C, R, j, n, f, a, p, l, x, w, k, _, u, z, y, G, q, O, D, K;
|
|
20
|
+
class Q {
|
|
21
21
|
// Fields to fetch for the selected place (can be extended).
|
|
22
22
|
/**
|
|
23
23
|
* Class constructor for PacAutocomplete.
|
|
@@ -34,23 +34,25 @@ class W {
|
|
|
34
34
|
// --- Private Properties (using # or _ prefix by convention) ---
|
|
35
35
|
h(this, M);
|
|
36
36
|
// Container ID where the autocomplete widget will be rendered.
|
|
37
|
-
h(this, A);
|
|
38
|
-
h(this, D);
|
|
39
|
-
h(this, R);
|
|
40
|
-
h(this, s);
|
|
41
37
|
h(this, C);
|
|
38
|
+
h(this, R);
|
|
39
|
+
h(this, j);
|
|
40
|
+
h(this, n);
|
|
41
|
+
h(this, f);
|
|
42
42
|
h(this, a);
|
|
43
|
-
h(this,
|
|
44
|
-
h(this,
|
|
45
|
-
h(this, y);
|
|
46
|
-
h(this, v);
|
|
43
|
+
h(this, p);
|
|
44
|
+
h(this, l);
|
|
47
45
|
h(this, x);
|
|
48
|
-
h(this,
|
|
49
|
-
h(this,
|
|
46
|
+
h(this, w);
|
|
47
|
+
h(this, k);
|
|
48
|
+
h(this, _, []);
|
|
49
|
+
h(this, u, -1);
|
|
50
50
|
h(this, z);
|
|
51
51
|
// For user-provided data callback
|
|
52
|
-
h(this,
|
|
52
|
+
h(this, y);
|
|
53
53
|
// For user-provided error callback
|
|
54
|
+
H(this, "_debouncedMakeAcRequest");
|
|
55
|
+
// Declare without initializing here
|
|
54
56
|
h(this, G, {
|
|
55
57
|
// Default options for the autocomplete widget.
|
|
56
58
|
autofocus: !1,
|
|
@@ -67,10 +69,12 @@ class W {
|
|
|
67
69
|
// Optional label text above the input.
|
|
68
70
|
debounce: 100,
|
|
69
71
|
// Debounce delay (ms) for API requests.
|
|
70
|
-
clear_input: !0
|
|
72
|
+
clear_input: !0,
|
|
71
73
|
// Clear input button (not implemented in this version).
|
|
74
|
+
debug: !1
|
|
75
|
+
// Enable debug mode (not implemented in this version).
|
|
72
76
|
});
|
|
73
|
-
h(this,
|
|
77
|
+
h(this, q, {
|
|
74
78
|
// CSS classes for various parts of the widget.
|
|
75
79
|
section: "",
|
|
76
80
|
// Outer section container.
|
|
@@ -124,76 +128,82 @@ class W {
|
|
|
124
128
|
language: "en-gb",
|
|
125
129
|
region: "GB"
|
|
126
130
|
});
|
|
127
|
-
h(this,
|
|
131
|
+
h(this, D, ["formattedAddress", "addressComponents"]);
|
|
128
132
|
h(this, K, ["formattedAddress", "addressComponents"]);
|
|
129
|
-
/**
|
|
130
|
-
* Debounced function to fetch autocomplete suggestions from the Google Places API.
|
|
131
|
-
* Triggered by the 'input' event on the input element.
|
|
132
|
-
*/
|
|
133
|
-
H(this, "_debouncedMakeAcRequest", this._debounce(async () => {
|
|
134
|
-
if (!e(this, a) || !e(this, a).value) {
|
|
135
|
-
this._reset(), e(this, a) && e(this, a).setAttribute("aria-expanded", "false");
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
e(this, C).input = e(this, a).value;
|
|
139
|
-
try {
|
|
140
|
-
const { suggestions: t } = (
|
|
141
|
-
// eslint-disable-next-line no-undef
|
|
142
|
-
await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(
|
|
143
|
-
e(this, C)
|
|
144
|
-
)
|
|
145
|
-
);
|
|
146
|
-
t && t.length > 0 ? (e(this, o).replaceChildren(
|
|
147
|
-
...this._createSuggestionElements(t)
|
|
148
|
-
), e(this, o).style.display = "block", e(this, a).setAttribute("aria-expanded", "true")) : (this._reset(), e(this, a).setAttribute("aria-expanded", "false"));
|
|
149
|
-
} catch (t) {
|
|
150
|
-
e(this, L).call(this, t), this._reset();
|
|
151
|
-
}
|
|
152
|
-
}, ((J = e(this, s)) == null ? void 0 : J.debounce) ?? 100));
|
|
153
133
|
if (!t || !t.containerId || !t.googleMapsApiKey)
|
|
154
134
|
throw new Error(
|
|
155
135
|
"PacAutocomplete: Missing required configuration (containerId, googleMapsApiKey)."
|
|
156
136
|
);
|
|
157
|
-
if (
|
|
137
|
+
if (o(this, M, t.containerId), o(this, C, document.getElementById(t.containerId)), !e(this, C))
|
|
158
138
|
throw new Error(
|
|
159
139
|
`PacAutocomplete: Container element with ID "${t.containerId}" not found.`
|
|
160
140
|
);
|
|
161
|
-
|
|
141
|
+
o(this, R, t.googleMapsApiKey), o(this, j, t.googleMapsApiVersion || "weekly"), o(this, n, {
|
|
162
142
|
...e(this, G),
|
|
163
143
|
// Default options
|
|
164
144
|
...t.options
|
|
165
145
|
// User-defined options override defaults
|
|
166
|
-
}), t.options && t.options.classes ? e(this,
|
|
167
|
-
...e(this,
|
|
146
|
+
}), t.options && t.options.classes ? e(this, n).classes = {
|
|
147
|
+
...e(this, q),
|
|
168
148
|
...t.options.classes
|
|
169
|
-
} : e(this,
|
|
170
|
-
console.info("---------Default onResponse not provided---------"), console.info("Selected Place:", JSON.stringify(
|
|
171
|
-
})),
|
|
172
|
-
console.error("---------Default onError not provided---------"), console.error("PAC Error:",
|
|
173
|
-
})), t.requestParams && Object.keys(t.requestParams).length > 0 ?
|
|
149
|
+
} : e(this, n).classes = e(this, q), e(this, n).debug && (console.log("___debug constructor options:"), console.log(e(this, n))), t.fetchFields && Array.isArray(t.fetchFields) && this._setFetchFields(t.fetchFields), o(this, z, t.onResponse || ((s) => {
|
|
150
|
+
console.info("---------Default onResponse not provided---------"), console.info("Selected Place:", JSON.stringify(s, null, 2));
|
|
151
|
+
})), o(this, y, t.onError || ((s) => {
|
|
152
|
+
console.error("---------Default onError not provided---------"), console.error("PAC Error:", s);
|
|
153
|
+
})), t.requestParams && Object.keys(t.requestParams).length > 0 ? o(this, f, {
|
|
174
154
|
...e(this, O),
|
|
175
155
|
...t.requestParams
|
|
176
|
-
}) :
|
|
156
|
+
}) : o(this, f, { ...e(this, O) }), e(this, n).debug && console.log("___debug constructor requestParams:", e(this, f)), this._initialiseDebouncedRequest(), this._init();
|
|
177
157
|
}
|
|
178
158
|
// --- Private Initialization Method ---
|
|
179
159
|
async _init() {
|
|
180
160
|
try {
|
|
181
161
|
(typeof google > "u" || !google.maps) && await this._loadGoogleMapsApi({
|
|
182
|
-
key: e(this,
|
|
183
|
-
v: e(this,
|
|
162
|
+
key: e(this, R),
|
|
163
|
+
v: e(this, j)
|
|
184
164
|
}), this._createPACStructure(), await this._initializeAutocomplete();
|
|
185
165
|
} catch (t) {
|
|
186
|
-
e(this,
|
|
166
|
+
e(this, y).call(this, t);
|
|
187
167
|
}
|
|
188
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Initializes the debounced request function for fetching autocomplete suggestions.
|
|
171
|
+
*
|
|
172
|
+
* Debounced function to fetch autocomplete suggestions from the Google Places API.
|
|
173
|
+
* Triggered by the 'input' event on the input element.
|
|
174
|
+
*
|
|
175
|
+
*
|
|
176
|
+
*/
|
|
177
|
+
_initialiseDebouncedRequest() {
|
|
178
|
+
this._debouncedMakeAcRequest = this._debounce(async () => {
|
|
179
|
+
if (!e(this, a) || !e(this, a).value) {
|
|
180
|
+
this._reset(), e(this, a) && e(this, a).setAttribute("aria-expanded", "false");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
e(this, f).input = e(this, a).value;
|
|
184
|
+
try {
|
|
185
|
+
const { suggestions: t } = (
|
|
186
|
+
// eslint-disable-next-line no-undef
|
|
187
|
+
await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(
|
|
188
|
+
e(this, f)
|
|
189
|
+
)
|
|
190
|
+
);
|
|
191
|
+
t && t.length > 0 ? (e(this, l).replaceChildren(
|
|
192
|
+
...this._createSuggestionElements(t)
|
|
193
|
+
), e(this, l).style.display = "block", e(this, a).setAttribute("aria-expanded", "true")) : (this._reset(), e(this, a).setAttribute("aria-expanded", "false"));
|
|
194
|
+
} catch (t) {
|
|
195
|
+
e(this, y).call(this, t), this._reset();
|
|
196
|
+
}
|
|
197
|
+
}, e(this, n).debounce);
|
|
198
|
+
}
|
|
189
199
|
/**
|
|
190
200
|
* Sets the fields to fetch for the selected place.
|
|
191
201
|
* @param {Array<string>} fields - The fields to fetch.
|
|
192
202
|
*/
|
|
193
203
|
_setFetchFields(t) {
|
|
194
|
-
Array.isArray(t) && t.length > 0 &&
|
|
204
|
+
Array.isArray(t) && t.length > 0 && o(this, D, [
|
|
195
205
|
.../* @__PURE__ */ new Set([...e(this, K), ...t])
|
|
196
|
-
].filter((
|
|
206
|
+
].filter((s) => s));
|
|
197
207
|
}
|
|
198
208
|
/**
|
|
199
209
|
* Creates a debounced version of a function.
|
|
@@ -203,13 +213,14 @@ class W {
|
|
|
203
213
|
* @param {number} wait - The number of milliseconds to delay.
|
|
204
214
|
* @returns {Function} The new debounced function.
|
|
205
215
|
*/
|
|
206
|
-
_debounce(t,
|
|
207
|
-
|
|
216
|
+
_debounce(t, s) {
|
|
217
|
+
e(this, n).debug && console.log("___debug debounce function called with wait:", s);
|
|
218
|
+
let i = null;
|
|
208
219
|
return function(...d) {
|
|
209
|
-
const
|
|
210
|
-
|
|
220
|
+
const b = () => {
|
|
221
|
+
i = null, t(...d);
|
|
211
222
|
};
|
|
212
|
-
|
|
223
|
+
i !== null && clearTimeout(i), i = setTimeout(b, s ?? 100);
|
|
213
224
|
};
|
|
214
225
|
}
|
|
215
226
|
/**
|
|
@@ -218,11 +229,11 @@ class W {
|
|
|
218
229
|
* @param {'km' | 'miles'} units - The desired output units.
|
|
219
230
|
* @returns {string | null} Formatted distance string (e.g., "1.23 km") or null if input is invalid.
|
|
220
231
|
*/
|
|
221
|
-
_formatDistance(t,
|
|
222
|
-
if (typeof t != "number" || !e(this,
|
|
232
|
+
_formatDistance(t, s) {
|
|
233
|
+
if (typeof t != "number" || !e(this, n).distance)
|
|
223
234
|
return null;
|
|
224
|
-
let
|
|
225
|
-
return
|
|
235
|
+
let i, r;
|
|
236
|
+
return s === "km" ? (i = (t / 1e3).toFixed(2), r = "km") : (i = (t / 1609.34).toFixed(2), r = "miles"), i = i.replace(/\.00$/, ""), `${i} ${r}`;
|
|
226
237
|
}
|
|
227
238
|
/**
|
|
228
239
|
* Dynamically loads the Google Maps JavaScript API using the importLibrary method.
|
|
@@ -231,39 +242,61 @@ class W {
|
|
|
231
242
|
* @param {object} g - Configuration object for the API loader (key, v, libraries, etc.).
|
|
232
243
|
*/
|
|
233
244
|
async _loadGoogleMapsApi(t) {
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
var
|
|
245
|
+
var s, i, r, d = "The Google Maps JavaScript API", b = "google", F = "importLibrary", L = "__ib__", T = document, v = window;
|
|
246
|
+
v = v[b] || (v[b] = {});
|
|
247
|
+
var E = v.maps || (v.maps = {}), P = /* @__PURE__ */ new Set(), I = new URLSearchParams(), N = () => (
|
|
237
248
|
// Function to initiate API loading (if not already started)
|
|
238
|
-
|
|
239
|
-
(
|
|
240
|
-
var
|
|
241
|
-
|
|
249
|
+
s || // eslint-disable-next-line no-async-promise-executor
|
|
250
|
+
(s = new Promise(async (A, m) => {
|
|
251
|
+
var S;
|
|
252
|
+
i = T.createElement("script"), I.set("libraries", [...P].join(","));
|
|
242
253
|
for (r in t)
|
|
243
|
-
|
|
244
|
-
r.replace(/[A-Z]/g, (
|
|
254
|
+
I.set(
|
|
255
|
+
r.replace(/[A-Z]/g, (g) => "_" + g[0].toLowerCase()),
|
|
245
256
|
// Convert camelCase to snake_case
|
|
246
257
|
t[r]
|
|
247
258
|
);
|
|
248
|
-
|
|
259
|
+
I.set("callback", b + ".maps." + L), i.src = `https://maps.${b}apis.com/maps/api/js?` + I, E[L] = A, i.onerror = () => s = m(Error(d + " could not load.")), i.nonce = ((S = T.querySelector("script[nonce]")) == null ? void 0 : S.nonce) || "", T.head.append(i);
|
|
249
260
|
}))
|
|
250
261
|
);
|
|
251
|
-
|
|
262
|
+
E[F] ? console.warn(d + " only loads once. Ignoring:", t) : E[F] = (A, ...m) => P.add(A) && N().then(() => E[F](A, ...m));
|
|
252
263
|
}
|
|
253
264
|
// --- UI Creation ---
|
|
254
265
|
_createPACStructure() {
|
|
255
266
|
const t = document.createElement("section");
|
|
256
|
-
e(this,
|
|
267
|
+
e(this, n).classes.section.split(" ").forEach((d) => d && t.classList.add(d)), o(this, p, document.createElement("div")), e(this, p).className = e(this, n).classes.container, e(this, p).setAttribute("id", e(this, M) + "-div"), t.appendChild(e(this, p));
|
|
268
|
+
const s = document.createElement("div");
|
|
269
|
+
s.className = e(this, n).classes.icon_container, e(this, p).appendChild(s);
|
|
257
270
|
const i = document.createElement("div");
|
|
258
|
-
i.
|
|
259
|
-
const n = document.createElement("div");
|
|
260
|
-
if (n.innerHTML = e(this, s).classes.icon, i.appendChild(n.firstElementChild), l(this, a, document.createElement("input")), e(this, a).id = e(this, M) + "-input", e(this, a).type = "text", e(this, a).name = "search", e(this, a).placeholder = e(this, s).placeholder, e(this, a).autocomplete = e(this, s).autocomplete, e(this, a).className = e(this, s).classes.input, e(this, a).setAttribute("role", "combobox"), e(this, a).setAttribute("aria-autocomplete", "list"), e(this, a).setAttribute("aria-expanded", "false"), e(this, a).setAttribute("aria-controls", "pacSuggestions"), e(this, s).autofocus && (e(this, a).autofocus = !0), e(this, s).label) {
|
|
271
|
+
if (i.innerHTML = e(this, n).classes.icon, s.appendChild(i.firstElementChild), o(this, a, document.createElement("input")), e(this, a).id = e(this, M) + "-input", e(this, a).type = "text", e(this, a).name = "search", e(this, a).placeholder = e(this, n).placeholder, e(this, a).autocomplete = e(this, n).autocomplete, e(this, a).className = e(this, n).classes.input, e(this, a).setAttribute("role", "combobox"), e(this, a).setAttribute("aria-autocomplete", "list"), e(this, a).setAttribute("aria-expanded", "false"), e(this, a).setAttribute("aria-controls", "pacSuggestions"), e(this, n).autofocus && (e(this, a).autofocus = !0), e(this, n).label) {
|
|
261
272
|
const d = document.createElement("label");
|
|
262
|
-
d.htmlFor = e(this, M) + "-labelInput", d.textContent = e(this,
|
|
273
|
+
d.htmlFor = e(this, M) + "-labelInput", d.textContent = e(this, n).label, e(this, p).appendChild(d);
|
|
263
274
|
}
|
|
264
|
-
e(this,
|
|
275
|
+
e(this, p).appendChild(e(this, a));
|
|
265
276
|
const r = document.createElement("div");
|
|
266
|
-
r.className = e(this,
|
|
277
|
+
r.className = e(this, n).classes.kbd_container, o(this, x, document.createElement("kbd")), e(this, x).className = e(this, n).classes.kbd_escape, e(this, x).textContent = "Esc", r.appendChild(e(this, x)), o(this, w, document.createElement("kbd")), e(this, w).className = e(this, n).classes.kbd_up, e(this, w).innerHTML = "↑", r.appendChild(e(this, w)), o(this, k, document.createElement("kbd")), e(this, k).className = e(this, n).classes.kbd_down, e(this, k).innerHTML = "↓", r.appendChild(e(this, k)), e(this, p).appendChild(r), o(this, l, document.createElement("ul")), e(this, l).id = "pacSuggestions", e(this, l).className = e(this, n).classes.ul, e(this, l).style.display = "none", e(this, l).setAttribute("role", "listbox"), e(this, p).appendChild(e(this, l)), e(this, C).appendChild(t), t.addEventListener("keydown", this._onKeyDown.bind(this));
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Attaches event listeners to the input element for handling user input.
|
|
281
|
+
* This includes debounced input handling, focus/blur events, and keyboard navigation.
|
|
282
|
+
*/
|
|
283
|
+
_attachedEventListeners() {
|
|
284
|
+
e(this, a).addEventListener(
|
|
285
|
+
"input",
|
|
286
|
+
this._debouncedMakeAcRequest.bind(this)
|
|
287
|
+
), e(this, a).addEventListener("blur", () => {
|
|
288
|
+
setTimeout(() => {
|
|
289
|
+
e(this, l) && !e(this, l).contains(document.activeElement) && (e(this, l).style.display = "none", e(this, a).setAttribute("aria-expanded", "false"));
|
|
290
|
+
}, 200);
|
|
291
|
+
}), e(this, a).addEventListener("focus", () => {
|
|
292
|
+
e(this, a).value && e(this, _).length > 0 && (e(this, l).style.display = "block", e(this, a).setAttribute("aria-expanded", "true"));
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
_detachEventListeners() {
|
|
296
|
+
e(this, a) && e(this, a).removeEventListener(
|
|
297
|
+
"input",
|
|
298
|
+
this._debouncedMakeAcRequest
|
|
299
|
+
), e(this, C) && e(this, p) && e(this, C).removeChild(e(this, p).parentElement);
|
|
267
300
|
}
|
|
268
301
|
/**
|
|
269
302
|
* Initializes the core autocomplete functionality after the API is loaded.
|
|
@@ -271,35 +304,26 @@ class W {
|
|
|
271
304
|
*/
|
|
272
305
|
async _initializeAutocomplete() {
|
|
273
306
|
try {
|
|
274
|
-
await google.maps.importLibrary("places"), this._refreshToken(), e(this, a) ? (e(this,
|
|
275
|
-
"input",
|
|
276
|
-
this._debouncedMakeAcRequest.bind(this)
|
|
277
|
-
), e(this, a).addEventListener("blur", () => {
|
|
278
|
-
setTimeout(() => {
|
|
279
|
-
e(this, o) && !e(this, o).contains(document.activeElement) && (e(this, o).style.display = "none", e(this, a).setAttribute("aria-expanded", "false"));
|
|
280
|
-
}, 200);
|
|
281
|
-
}), e(this, a).addEventListener("focus", () => {
|
|
282
|
-
e(this, a).value && e(this, k).length > 0 && (e(this, o).style.display = "block", e(this, a).setAttribute("aria-expanded", "true"));
|
|
283
|
-
})) : e(this, L).call(this, new Error("Input element not found during initialization."));
|
|
307
|
+
await google.maps.importLibrary("places"), this._refreshToken(), e(this, a) ? this._attachedEventListeners() : e(this, y).call(this, new Error("Input element not found during initialization."));
|
|
284
308
|
} catch (t) {
|
|
285
|
-
console.error("Error initializing Google Places Autocomplete:", t), e(this,
|
|
309
|
+
console.error("Error initializing Google Places Autocomplete:", t), e(this, y).call(this, new Error("Google Maps Places library not available."));
|
|
286
310
|
}
|
|
287
311
|
}
|
|
288
312
|
/**
|
|
289
313
|
* Resets the autocomplete input field, clears suggestions, and optionally refreshes the session token.
|
|
290
314
|
* @param {boolean} [refresh=false] - Whether to refresh the Google Places session token.
|
|
291
315
|
*/
|
|
292
|
-
_reset(t = !1,
|
|
293
|
-
|
|
316
|
+
_reset(t = !1, s = null) {
|
|
317
|
+
o(this, u, -1), e(this, a) && e(this, n).clear_input == !1 && s && s.formattedAddress ? e(this, a).value = s.formattedAddress : e(this, a) && (e(this, a).value = ""), e(this, a) && (e(this, a).setAttribute("aria-expanded", "false"), e(this, a).blur()), o(this, _, []), o(this, u, -1), e(this, l) && (e(this, l).innerHTML = "", e(this, l).style.display = "none"), t && this._refreshToken();
|
|
294
318
|
}
|
|
295
319
|
/**
|
|
296
320
|
* Removes the 'current' highlighting classes from all suggestion list items (li) and their links (a).
|
|
297
321
|
*/
|
|
298
322
|
_resetLiClasses() {
|
|
299
|
-
e(this,
|
|
300
|
-
e(this,
|
|
301
|
-
const
|
|
302
|
-
|
|
323
|
+
e(this, l) && Array.from(e(this, l).children).forEach((t) => {
|
|
324
|
+
e(this, n).classes.li_current.split(" ").forEach((i) => t.classList.remove(i));
|
|
325
|
+
const s = t.querySelector("a");
|
|
326
|
+
s && e(this, n).classes.li_a_current.split(" ").forEach((i) => s.classList.remove(i));
|
|
303
327
|
});
|
|
304
328
|
}
|
|
305
329
|
/**
|
|
@@ -308,55 +332,55 @@ class W {
|
|
|
308
332
|
* @param {KeyboardEvent} e - The keyboard event object.
|
|
309
333
|
*/
|
|
310
334
|
_onKeyDown(t) {
|
|
311
|
-
if (this._resetLiClasses(), t.key === "Escape" && (t.preventDefault(), e(this,
|
|
312
|
-
var
|
|
313
|
-
return (
|
|
335
|
+
if (this._resetLiClasses(), t.key === "Escape" && (t.preventDefault(), e(this, n).classes.kbd_active.split(" ").forEach((s) => {
|
|
336
|
+
var i;
|
|
337
|
+
return (i = e(this, x)) == null ? void 0 : i.classList.add(s);
|
|
314
338
|
}), setTimeout(
|
|
315
|
-
() => e(this,
|
|
316
|
-
var
|
|
317
|
-
return (
|
|
339
|
+
() => e(this, n).classes.kbd_active.split(" ").forEach((s) => {
|
|
340
|
+
var i;
|
|
341
|
+
return (i = e(this, x)) == null ? void 0 : i.classList.remove(s);
|
|
318
342
|
}),
|
|
319
343
|
300
|
|
320
|
-
), this._reset(!0)), !(!e(this,
|
|
344
|
+
), this._reset(!0)), !(!e(this, _).length || !e(this, l) || e(this, l).style.display === "none"))
|
|
321
345
|
if (t.key === "ArrowDown") {
|
|
322
|
-
t.preventDefault(),
|
|
323
|
-
e(this,
|
|
324
|
-
e(this,
|
|
325
|
-
)), e(this,
|
|
326
|
-
const
|
|
327
|
-
if (
|
|
328
|
-
const
|
|
329
|
-
e(this,
|
|
346
|
+
t.preventDefault(), o(this, u, Math.min(
|
|
347
|
+
e(this, u) + 1,
|
|
348
|
+
e(this, _).length - 1
|
|
349
|
+
)), e(this, u) < 0 && o(this, u, 0);
|
|
350
|
+
const s = e(this, l).children.item(e(this, u));
|
|
351
|
+
if (s) {
|
|
352
|
+
const i = s.querySelector("a");
|
|
353
|
+
e(this, n).classes.li_current.split(" ").forEach((r) => s.classList.add(r)), i && e(this, n).classes.li_a_current.split(" ").forEach((r) => i.classList.add(r)), s.scrollIntoView({ block: "nearest" });
|
|
330
354
|
}
|
|
331
|
-
e(this,
|
|
355
|
+
e(this, n).classes.kbd_active.split(" ").forEach((i) => {
|
|
332
356
|
var r;
|
|
333
|
-
return (r = e(this,
|
|
357
|
+
return (r = e(this, k)) == null ? void 0 : r.classList.add(i);
|
|
334
358
|
}), setTimeout(
|
|
335
|
-
() => e(this,
|
|
359
|
+
() => e(this, n).classes.kbd_active.split(" ").forEach((i) => {
|
|
336
360
|
var r;
|
|
337
|
-
return (r = e(this,
|
|
361
|
+
return (r = e(this, k)) == null ? void 0 : r.classList.remove(i);
|
|
338
362
|
}),
|
|
339
363
|
300
|
|
340
364
|
);
|
|
341
365
|
} else if (t.key === "ArrowUp") {
|
|
342
|
-
t.preventDefault(),
|
|
343
|
-
const
|
|
344
|
-
if (
|
|
345
|
-
const
|
|
346
|
-
e(this,
|
|
366
|
+
t.preventDefault(), o(this, u, Math.max(e(this, u) - 1, 0));
|
|
367
|
+
const s = e(this, l).children.item(e(this, u));
|
|
368
|
+
if (s) {
|
|
369
|
+
const i = s.querySelector("a");
|
|
370
|
+
e(this, n).classes.li_current.split(" ").forEach((r) => s.classList.add(r)), i && e(this, n).classes.li_a_current.split(" ").forEach((r) => i.classList.add(r)), s.scrollIntoView({ block: "nearest" });
|
|
347
371
|
}
|
|
348
|
-
e(this,
|
|
372
|
+
e(this, n).classes.kbd_active.split(" ").forEach((i) => {
|
|
349
373
|
var r;
|
|
350
|
-
return (r = e(this,
|
|
374
|
+
return (r = e(this, w)) == null ? void 0 : r.classList.add(i);
|
|
351
375
|
}), setTimeout(
|
|
352
|
-
() => e(this,
|
|
376
|
+
() => e(this, n).classes.kbd_active.split(" ").forEach((i) => {
|
|
353
377
|
var r;
|
|
354
|
-
return (r = e(this,
|
|
378
|
+
return (r = e(this, w)) == null ? void 0 : r.classList.remove(i);
|
|
355
379
|
}),
|
|
356
380
|
300
|
|
357
381
|
);
|
|
358
|
-
} else t.key === "Enter" && (t.preventDefault(), e(this,
|
|
359
|
-
e(this,
|
|
382
|
+
} else t.key === "Enter" && (t.preventDefault(), e(this, u) >= 0 && e(this, u) < e(this, _).length && this._onPlaceSelected(
|
|
383
|
+
e(this, _)[e(this, u)].place
|
|
360
384
|
));
|
|
361
385
|
}
|
|
362
386
|
/**
|
|
@@ -367,48 +391,48 @@ class W {
|
|
|
367
391
|
* @returns {Array<HTMLLIElement>} An array of LI elements to be added to the suggestions UL.
|
|
368
392
|
*/
|
|
369
393
|
_createSuggestionElements(t) {
|
|
370
|
-
return
|
|
371
|
-
e(this,
|
|
372
|
-
id:
|
|
373
|
-
description:
|
|
374
|
-
place:
|
|
394
|
+
return o(this, _, []), t.map((s, i) => {
|
|
395
|
+
e(this, _).push({
|
|
396
|
+
id: i + 1,
|
|
397
|
+
description: s.placePrediction.toString(),
|
|
398
|
+
place: s.placePrediction.toPlace()
|
|
375
399
|
});
|
|
376
400
|
const r = document.createElement("div");
|
|
377
|
-
r.className = e(this,
|
|
401
|
+
r.className = e(this, n).classes.li_div_container;
|
|
378
402
|
const d = document.createElement("div");
|
|
379
|
-
d.className = e(this,
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
const
|
|
383
|
-
let
|
|
384
|
-
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
for (const
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
),
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
),
|
|
395
|
-
const
|
|
396
|
-
|
|
403
|
+
d.className = e(this, n).classes.li_div_one, r.appendChild(d);
|
|
404
|
+
const b = document.createElement("p");
|
|
405
|
+
b.className = e(this, n).classes.li_div_one_p;
|
|
406
|
+
const F = s.placePrediction.text, L = F.text, T = F.matches;
|
|
407
|
+
let v = 0;
|
|
408
|
+
T.sort((g, $) => g.startOffset - $.startOffset);
|
|
409
|
+
const E = document.createElement("span"), P = document.createElement("span");
|
|
410
|
+
P.classList = e(this, n).classes.highlight ?? "font-bold";
|
|
411
|
+
for (const g of T)
|
|
412
|
+
E.textContent += L.substring(
|
|
413
|
+
v,
|
|
414
|
+
g.startOffset
|
|
415
|
+
), g.startOffset > 0 && L.charAt(g.startOffset - 1) == " " && (P.textContent += " "), P.textContent += L.substring(
|
|
416
|
+
g.startOffset,
|
|
417
|
+
g.endOffset
|
|
418
|
+
), v = g.endOffset;
|
|
419
|
+
const I = document.createTextNode(
|
|
420
|
+
L.substring(v)
|
|
397
421
|
);
|
|
398
|
-
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
e(this,
|
|
405
|
-
),
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
this._onPlaceSelected(
|
|
409
|
-
}),
|
|
410
|
-
const
|
|
411
|
-
return
|
|
422
|
+
E.appendChild(P), E.appendChild(I), b.appendChild(E), d.appendChild(b), r.appendChild(d);
|
|
423
|
+
const N = document.createElement("div");
|
|
424
|
+
N.className = e(this, n).classes.li_div_two, r.appendChild(N);
|
|
425
|
+
const A = document.createElement("p");
|
|
426
|
+
A.className = e(this, n).classes.li_div_two_p, A.textContent = this._formatDistance(
|
|
427
|
+
s.placePrediction.distanceMeters,
|
|
428
|
+
e(this, n).distance_units ?? "km"
|
|
429
|
+
), N.appendChild(A);
|
|
430
|
+
const m = document.createElement("a");
|
|
431
|
+
m.href = "javascript:void(0)", m.tabIndex = i + 1, m.className = e(this, n).classes.li_a, m.addEventListener("click", () => {
|
|
432
|
+
this._onPlaceSelected(s.placePrediction.toPlace());
|
|
433
|
+
}), m.appendChild(r), m.appendChild(N);
|
|
434
|
+
const S = document.createElement("li");
|
|
435
|
+
return S.id = `option-${i + 1}`, S.className = e(this, n).classes.li, S.appendChild(m), S;
|
|
412
436
|
});
|
|
413
437
|
}
|
|
414
438
|
/**
|
|
@@ -418,16 +442,16 @@ class W {
|
|
|
418
442
|
* @param {google.maps.places.Place} place - The selected Place object.
|
|
419
443
|
*/
|
|
420
444
|
async _onPlaceSelected(t) {
|
|
421
|
-
let
|
|
445
|
+
let s = null;
|
|
422
446
|
try {
|
|
423
447
|
await t.fetchFields({
|
|
424
|
-
fields: e(this,
|
|
448
|
+
fields: e(this, D)
|
|
425
449
|
//["displayName", "formattedAddress", "addressComponents"], // Add more fields as needed
|
|
426
|
-
}),
|
|
427
|
-
} catch (
|
|
428
|
-
console.error("Error fetching place details:",
|
|
450
|
+
}), s = t.toJSON(), e(this, z).call(this, s);
|
|
451
|
+
} catch (i) {
|
|
452
|
+
console.error("Error fetching place details:", i), e(this, y).call(this, i);
|
|
429
453
|
} finally {
|
|
430
|
-
this._reset(!0,
|
|
454
|
+
this._reset(!0, s);
|
|
431
455
|
}
|
|
432
456
|
}
|
|
433
457
|
/**
|
|
@@ -436,9 +460,9 @@ class W {
|
|
|
436
460
|
*/
|
|
437
461
|
_refreshToken() {
|
|
438
462
|
try {
|
|
439
|
-
e(this,
|
|
463
|
+
e(this, f).sessionToken = new google.maps.places.AutocompleteSessionToken();
|
|
440
464
|
} catch (t) {
|
|
441
|
-
console.error("Error creating session token:", t), e(this,
|
|
465
|
+
console.error("Error creating session token:", t), e(this, y).call(this, t);
|
|
442
466
|
}
|
|
443
467
|
}
|
|
444
468
|
/**
|
|
@@ -459,7 +483,7 @@ class W {
|
|
|
459
483
|
* @returns {Array<string>} The current fetch fields.
|
|
460
484
|
*/
|
|
461
485
|
getFetchFields() {
|
|
462
|
-
return e(this,
|
|
486
|
+
return e(this, D);
|
|
463
487
|
}
|
|
464
488
|
/**
|
|
465
489
|
* Sets the request parameters for the Places Autocomplete instance.
|
|
@@ -471,17 +495,19 @@ class W {
|
|
|
471
495
|
* @param {*} params
|
|
472
496
|
*/
|
|
473
497
|
setRequestParams(t) {
|
|
474
|
-
typeof t == "object" && !Array.isArray(t) && t !== null && (t.input && typeof t.input == "string" && (e(this, a).value = t.input),
|
|
498
|
+
typeof t == "object" && !Array.isArray(t) && t !== null && (t.input && typeof t.input == "string" && (e(this, a).value = t.input), o(this, f, {
|
|
475
499
|
...e(this, O),
|
|
476
500
|
...t
|
|
477
501
|
}));
|
|
478
502
|
}
|
|
479
503
|
/**
|
|
480
|
-
*
|
|
504
|
+
* Returns the current request parameters used by the Places Autocomplete instance.
|
|
505
|
+
* This includes the input value, included region codes, language, and other settings.
|
|
506
|
+
* It is useful for debugging or when you need to know the current search criteria.
|
|
481
507
|
* @returns {Object} The current request parameters.
|
|
482
508
|
*/
|
|
483
509
|
getRequestParams() {
|
|
484
|
-
return e(this,
|
|
510
|
+
return e(this, f);
|
|
485
511
|
}
|
|
486
512
|
/**
|
|
487
513
|
* Sets the options for the Places Autocomplete instance.
|
|
@@ -493,37 +519,16 @@ class W {
|
|
|
493
519
|
* @param {*} options
|
|
494
520
|
*/
|
|
495
521
|
setOptions(t) {
|
|
496
|
-
var i, n, r, d, m, S, E;
|
|
497
522
|
if (typeof t == "object" && !Array.isArray(t) && t !== null) {
|
|
498
|
-
|
|
499
|
-
|
|
523
|
+
this._detachEventListeners();
|
|
524
|
+
const s = t.classes || {};
|
|
525
|
+
delete t.classes, o(this, n, {
|
|
500
526
|
...e(this, G),
|
|
501
527
|
...t
|
|
502
|
-
}),
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
), e(this, a).
|
|
506
|
-
"aria-autocomplete",
|
|
507
|
-
e(this, s).aria_autocomplete || "list"
|
|
508
|
-
), e(this, a).setAttribute(
|
|
509
|
-
"aria-expanded",
|
|
510
|
-
e(this, s).aria_expanded || "false"
|
|
511
|
-
), e(this, a).setAttribute(
|
|
512
|
-
"aria-controls",
|
|
513
|
-
e(this, s).aria_controls || "pacSuggestions"
|
|
514
|
-
), e(this, a).setAttribute("role", e(this, s).role || "combobox"), e(this, a).setAttribute(
|
|
515
|
-
"aria-required",
|
|
516
|
-
e(this, s).aria_required || "false"
|
|
517
|
-
), e(this, a).setAttribute(
|
|
518
|
-
"aria-activedescendant",
|
|
519
|
-
e(this, s).aria_activedescendant || ""
|
|
520
|
-
), _ && typeof _ == "object" && Object.keys(_).length > 0 && (e(this, s).classes = {
|
|
521
|
-
...e(this, I),
|
|
522
|
-
..._
|
|
523
|
-
}), e(this, u) && ((i = e(this, s).classes) != null && i.container) && (e(this, u).className = e(this, s).classes.container), e(this, a) && ((n = e(this, s).classes) != null && n.input) && (e(this, a).className = e(this, s).classes.input), e(this, o) && ((r = e(this, s).classes) != null && r.ul) && (e(this, o).className = e(this, s).classes.ul), e(this, y) && ((d = e(this, s).classes) != null && d.kbd_escape) && (e(this, y).className = e(this, s).classes.kbd_escape), e(this, v) && ((m = e(this, s).classes) != null && m.kbd_up) && (e(this, v).className = e(this, s).classes.kbd_up), e(this, x) && ((S = e(this, s).classes) != null && S.kbd_down) && (e(this, x).className = e(this, s).classes.kbd_down), e(this, A)) {
|
|
524
|
-
const f = e(this, A).querySelector("section");
|
|
525
|
-
f && ((E = e(this, s).classes) != null && E.section) && e(this, s).classes.section.split(" ").forEach((b) => b && f.classList.add(b));
|
|
526
|
-
}
|
|
528
|
+
}), s && typeof s == "object" && Object.keys(s).length > 0 ? e(this, n).classes = {
|
|
529
|
+
...e(this, q),
|
|
530
|
+
...s
|
|
531
|
+
} : e(this, n).classes = { ...e(this, q) }, this._initialiseDebouncedRequest(), this._createPACStructure(), e(this, a) && this._attachedEventListeners();
|
|
527
532
|
}
|
|
528
533
|
}
|
|
529
534
|
/**
|
|
@@ -531,7 +536,7 @@ class W {
|
|
|
531
536
|
* @returns {Object} The current options.
|
|
532
537
|
*/
|
|
533
538
|
getOptions() {
|
|
534
|
-
return e(this,
|
|
539
|
+
return e(this, n);
|
|
535
540
|
}
|
|
536
541
|
/**
|
|
537
542
|
* Clears the autocomplete input field and suggestions list.
|
|
@@ -551,17 +556,14 @@ class W {
|
|
|
551
556
|
* @returns {void}
|
|
552
557
|
*/
|
|
553
558
|
destroy() {
|
|
554
|
-
|
|
555
|
-
"input",
|
|
556
|
-
this._debouncedMakeAcRequest
|
|
557
|
-
), e(this, A) && e(this, u) && e(this, A).removeChild(e(this, u).parentElement);
|
|
559
|
+
this._detachEventListeners();
|
|
558
560
|
for (const t in this)
|
|
559
561
|
Object.hasOwn(this, t) && (this[t] = null);
|
|
560
562
|
console.log("PacAutocomplete instance destroyed.");
|
|
561
563
|
}
|
|
562
564
|
}
|
|
563
|
-
M = new WeakMap(),
|
|
565
|
+
M = new WeakMap(), C = new WeakMap(), R = new WeakMap(), j = new WeakMap(), n = new WeakMap(), f = new WeakMap(), a = new WeakMap(), p = new WeakMap(), l = new WeakMap(), x = new WeakMap(), w = new WeakMap(), k = new WeakMap(), _ = new WeakMap(), u = new WeakMap(), z = new WeakMap(), y = new WeakMap(), G = new WeakMap(), q = new WeakMap(), O = new WeakMap(), D = new WeakMap(), K = new WeakMap();
|
|
564
566
|
export {
|
|
565
|
-
|
|
567
|
+
Q as PlacesAutocomplete
|
|
566
568
|
};
|
|
567
569
|
//# sourceMappingURL=places-autocomplete.js.map
|