places-autocomplete-js 1.0.4 → 1.0.5
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
|
@@ -7,9 +7,16 @@ A flexible and customizable vanilla JavaScript library leveraging the [Google Ma
|
|
|
7
7
|
|
|
8
8
|
It handles API loading, session tokens for cost-effective usage, fetching suggestions with debouncing, keyboard navigation, highlighting matched text, and requesting place details, allowing you to focus on integrating the results into your application.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Live Demos
|
|
11
|
+
|
|
12
|
+
Explore interactive examples of the Google Places Autocomplete JS library:
|
|
13
|
+
|
|
14
|
+
A quick, editable sandbox to experiment with the core functionality:
|
|
15
|
+
|
|
16
|
+
[](https://codepen.io/alexpechkarev/pen/wBaMaMY)
|
|
17
|
+
|
|
18
|
+
See a more comprehensive live demo of the library in action: [pacservice.pages.dev](https://pacservice.pages.dev/)
|
|
11
19
|
|
|
12
|
-
See a live demo of the library in action: [Basic Example](https://pacservice.pages.dev/)
|
|
13
20
|
|
|
14
21
|
|
|
15
22
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
throw TypeError(
|
|
1
|
+
var H = Object.defineProperty;
|
|
2
|
+
var K = (c) => {
|
|
3
|
+
throw TypeError(c);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var e = (
|
|
5
|
+
var V = (c, t, s) => t in c ? H(c, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : c[t] = s;
|
|
6
|
+
var $ = (c, t, s) => V(c, typeof t != "symbol" ? t + "" : t, s), F = (c, t, s) => t.has(c) || K("Cannot " + s);
|
|
7
|
+
var e = (c, t, s) => (F(c, t, "read from private field"), s ? s.call(c) : t.get(c)), h = (c, t, s) => t.has(c) ? K("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(c) : t.set(c, s), l = (c, t, s, i) => (F(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 = (l, t, s) => ($(l, t, "read from private field"), s ? s.call(l) : t.get(
|
|
|
16
16
|
* @license MIT
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
|
-
var
|
|
20
|
-
class
|
|
19
|
+
var B, M, C, D, O, n, A, r, u, o, x, E, w, f, p, j, g, R, z;
|
|
20
|
+
class U {
|
|
21
21
|
/**
|
|
22
22
|
* Class constructor for PacAutocomplete.
|
|
23
23
|
* Initializes the autocomplete widget with the provided configuration.
|
|
@@ -31,24 +31,26 @@ class J {
|
|
|
31
31
|
*/
|
|
32
32
|
constructor(t) {
|
|
33
33
|
// --- Private Properties (using # or _ prefix by convention) ---
|
|
34
|
-
h(this,
|
|
35
|
-
|
|
34
|
+
h(this, M);
|
|
35
|
+
// Container ID where the autocomplete widget will be rendered.
|
|
36
|
+
h(this, C);
|
|
36
37
|
h(this, D);
|
|
38
|
+
h(this, O);
|
|
37
39
|
h(this, n);
|
|
38
40
|
h(this, A);
|
|
39
41
|
h(this, r);
|
|
40
42
|
h(this, u);
|
|
41
43
|
h(this, o);
|
|
44
|
+
h(this, x);
|
|
42
45
|
h(this, E);
|
|
43
46
|
h(this, w);
|
|
44
|
-
h(this,
|
|
45
|
-
h(this, b, []);
|
|
47
|
+
h(this, f, []);
|
|
46
48
|
h(this, p, -1);
|
|
47
|
-
h(this,
|
|
49
|
+
h(this, j);
|
|
48
50
|
// For user-provided data callback
|
|
49
|
-
h(this,
|
|
51
|
+
h(this, g);
|
|
50
52
|
// For user-provided error callback
|
|
51
|
-
h(this,
|
|
53
|
+
h(this, R, {
|
|
52
54
|
// CSS classes for various parts of the widget.
|
|
53
55
|
section: "",
|
|
54
56
|
// Outer section container.
|
|
@@ -93,7 +95,7 @@ class J {
|
|
|
93
95
|
highlight: "font-bold"
|
|
94
96
|
// Class for highlighting matched text in suggestions.
|
|
95
97
|
});
|
|
96
|
-
h(this,
|
|
98
|
+
h(this, z, {
|
|
97
99
|
// Default parameters for the autocomplete request.
|
|
98
100
|
input: "",
|
|
99
101
|
// Initial input value (empty).
|
|
@@ -106,7 +108,7 @@ class J {
|
|
|
106
108
|
* Debounced function to fetch autocomplete suggestions from the Google Places API.
|
|
107
109
|
* Triggered by the 'input' event on the input element.
|
|
108
110
|
*/
|
|
109
|
-
|
|
111
|
+
$(this, "_debouncedMakeAcRequest", this._debounce(async () => {
|
|
110
112
|
if (!e(this, r) || !e(this, r).value) {
|
|
111
113
|
this._reset(), e(this, r) && e(this, r).setAttribute("aria-expanded", "false");
|
|
112
114
|
return;
|
|
@@ -123,18 +125,18 @@ class J {
|
|
|
123
125
|
...this._createSuggestionElements(t)
|
|
124
126
|
), e(this, o).style.display = "block", e(this, r).setAttribute("aria-expanded", "true")) : (this._reset(), e(this, r).setAttribute("aria-expanded", "false"));
|
|
125
127
|
} catch (t) {
|
|
126
|
-
e(this,
|
|
128
|
+
e(this, g).call(this, t), this._reset(), e(this, r) && e(this, r).setAttribute("aria-expanded", "false");
|
|
127
129
|
}
|
|
128
|
-
}, ((
|
|
130
|
+
}, ((B = e(this, n)) == null ? void 0 : B.debounce) ?? 100));
|
|
129
131
|
if (!t || !t.containerId || !t.googleMapsApiKey)
|
|
130
132
|
throw new Error(
|
|
131
133
|
"PacAutocomplete: Missing required configuration (containerId, googleMapsApiKey)."
|
|
132
134
|
);
|
|
133
|
-
if (
|
|
135
|
+
if (l(this, M, t.containerId), l(this, C, document.getElementById(t.containerId)), !e(this, C))
|
|
134
136
|
throw new Error(
|
|
135
137
|
`PacAutocomplete: Container element with ID "${t.containerId}" not found.`
|
|
136
138
|
);
|
|
137
|
-
|
|
139
|
+
l(this, D, t.googleMapsApiKey), l(this, O, t.googleMapsApiVersion || "weekly"), l(this, n, {
|
|
138
140
|
autofocus: !1,
|
|
139
141
|
// Automatically focus the input on load.
|
|
140
142
|
autocomplete: "off",
|
|
@@ -152,26 +154,26 @@ class J {
|
|
|
152
154
|
...t.options
|
|
153
155
|
// User-defined options override defaults
|
|
154
156
|
}), t.options && t.options.classes ? e(this, n).classes = {
|
|
155
|
-
...e(this,
|
|
157
|
+
...e(this, R),
|
|
156
158
|
...t.options.classes
|
|
157
|
-
} : e(this, n).classes = e(this,
|
|
159
|
+
} : e(this, n).classes = e(this, R), l(this, j, t.onResponse || ((s) => {
|
|
158
160
|
console.info("---------Default onResponse not provided---------"), console.info("Selected Place:", JSON.stringify(s, null, 2));
|
|
159
|
-
})),
|
|
161
|
+
})), l(this, g, t.onError || ((s) => {
|
|
160
162
|
console.error("---------Default onError not provided---------"), console.error("PAC Error:", s);
|
|
161
|
-
})), t.requestParams && Object.keys(t.requestParams).length > 0 ?
|
|
162
|
-
...e(this,
|
|
163
|
+
})), t.requestParams && Object.keys(t.requestParams).length > 0 ? l(this, A, {
|
|
164
|
+
...e(this, z),
|
|
163
165
|
...t.requestParams
|
|
164
|
-
}) :
|
|
166
|
+
}) : l(this, A, { ...e(this, z) }), this._init();
|
|
165
167
|
}
|
|
166
168
|
// --- Private Initialization Method ---
|
|
167
169
|
async _init() {
|
|
168
170
|
try {
|
|
169
171
|
(typeof google > "u" || !google.maps) && await this._loadGoogleMapsApi({
|
|
170
|
-
key: e(this,
|
|
171
|
-
v: e(this,
|
|
172
|
+
key: e(this, D),
|
|
173
|
+
v: e(this, O)
|
|
172
174
|
}), this._createPACStructure(), await this._initializeAutocomplete();
|
|
173
175
|
} catch (t) {
|
|
174
|
-
e(this,
|
|
176
|
+
e(this, g).call(this, t);
|
|
175
177
|
}
|
|
176
178
|
}
|
|
177
179
|
/**
|
|
@@ -185,10 +187,10 @@ class J {
|
|
|
185
187
|
_debounce(t, s) {
|
|
186
188
|
let i = null;
|
|
187
189
|
return function(...d) {
|
|
188
|
-
const
|
|
190
|
+
const b = () => {
|
|
189
191
|
i = null, t(...d);
|
|
190
192
|
};
|
|
191
|
-
i !== null && clearTimeout(i), i = setTimeout(
|
|
193
|
+
i !== null && clearTimeout(i), i = setTimeout(b, s ?? 100);
|
|
192
194
|
};
|
|
193
195
|
}
|
|
194
196
|
/**
|
|
@@ -210,39 +212,39 @@ class J {
|
|
|
210
212
|
* @param {object} g - Configuration object for the API loader (key, v, libraries, etc.).
|
|
211
213
|
*/
|
|
212
214
|
async _loadGoogleMapsApi(t) {
|
|
213
|
-
var s, i, a, d = "The Google Maps JavaScript API",
|
|
214
|
-
|
|
215
|
-
var
|
|
215
|
+
var s, i, a, d = "The Google Maps JavaScript API", b = "google", T = "importLibrary", L = "__ib__", N = document, y = window;
|
|
216
|
+
y = y[b] || (y[b] = {});
|
|
217
|
+
var v = y.maps || (y.maps = {}), S = /* @__PURE__ */ new Set(), I = new URLSearchParams(), q = () => (
|
|
216
218
|
// Function to initiate API loading (if not already started)
|
|
217
219
|
s || // eslint-disable-next-line no-async-promise-executor
|
|
218
|
-
(s = new Promise(async (
|
|
220
|
+
(s = new Promise(async (k, m) => {
|
|
219
221
|
var P;
|
|
220
|
-
i =
|
|
222
|
+
i = N.createElement("script"), I.set("libraries", [...S].join(","));
|
|
221
223
|
for (a in t)
|
|
222
|
-
|
|
223
|
-
a.replace(/[A-Z]/g, (
|
|
224
|
+
I.set(
|
|
225
|
+
a.replace(/[A-Z]/g, (_) => "_" + _[0].toLowerCase()),
|
|
224
226
|
// Convert camelCase to snake_case
|
|
225
227
|
t[a]
|
|
226
228
|
);
|
|
227
|
-
|
|
229
|
+
I.set("callback", b + ".maps." + L), i.src = `https://maps.${b}apis.com/maps/api/js?` + I, v[L] = k, i.onerror = () => s = m(Error(d + " could not load.")), i.nonce = ((P = N.querySelector("script[nonce]")) == null ? void 0 : P.nonce) || "", N.head.append(i);
|
|
228
230
|
}))
|
|
229
231
|
);
|
|
230
|
-
|
|
232
|
+
v[T] ? console.warn(d + " only loads once. Ignoring:", t) : v[T] = (k, ...m) => S.add(k) && q().then(() => v[T](k, ...m));
|
|
231
233
|
}
|
|
232
234
|
// --- UI Creation ---
|
|
233
235
|
_createPACStructure() {
|
|
234
236
|
const t = document.createElement("section");
|
|
235
|
-
e(this, n).classes.section.split(" ").forEach((d) => d && t.classList.add(d)),
|
|
237
|
+
e(this, n).classes.section.split(" ").forEach((d) => d && t.classList.add(d)), l(this, u, document.createElement("div")), e(this, u).className = e(this, n).classes.container, e(this, u).setAttribute("id", e(this, M) + "-div"), t.appendChild(e(this, u));
|
|
236
238
|
const s = document.createElement("div");
|
|
237
239
|
s.className = e(this, n).classes.icon_container, e(this, u).appendChild(s);
|
|
238
240
|
const i = document.createElement("div");
|
|
239
|
-
if (i.innerHTML = e(this, n).classes.icon, s.appendChild(i.firstElementChild),
|
|
241
|
+
if (i.innerHTML = e(this, n).classes.icon, s.appendChild(i.firstElementChild), l(this, r, document.createElement("input")), e(this, r).id = e(this, M) + "-input", e(this, r).type = "text", e(this, r).name = "search", e(this, r).placeholder = e(this, n).placeholder, e(this, r).autocomplete = e(this, n).autocomplete, e(this, r).className = e(this, n).classes.input, e(this, r).setAttribute("role", "combobox"), e(this, r).setAttribute("aria-autocomplete", "list"), e(this, r).setAttribute("aria-expanded", "false"), e(this, r).setAttribute("aria-controls", "pacSuggestions"), e(this, n).autofocus && (e(this, r).autofocus = !0), e(this, n).label) {
|
|
240
242
|
const d = document.createElement("label");
|
|
241
|
-
d.htmlFor =
|
|
243
|
+
d.htmlFor = e(this, M) + "-labelInput", d.textContent = e(this, n).label, e(this, u).appendChild(d);
|
|
242
244
|
}
|
|
243
245
|
e(this, u).appendChild(e(this, r));
|
|
244
246
|
const a = document.createElement("div");
|
|
245
|
-
a.className = e(this, n).classes.kbd_container,
|
|
247
|
+
a.className = e(this, n).classes.kbd_container, l(this, x, document.createElement("kbd")), e(this, x).className = e(this, n).classes.kbd_escape, e(this, x).textContent = "Esc", a.appendChild(e(this, x)), l(this, E, document.createElement("kbd")), e(this, E).className = e(this, n).classes.kbd_up, e(this, E).innerHTML = "↑", a.appendChild(e(this, E)), l(this, w, document.createElement("kbd")), e(this, w).className = e(this, n).classes.kbd_down, e(this, w).innerHTML = "↓", a.appendChild(e(this, w)), e(this, u).appendChild(a), l(this, o, document.createElement("ul")), e(this, o).id = "pacSuggestions", e(this, o).className = e(this, n).classes.ul, e(this, o).style.display = "none", e(this, o).setAttribute("role", "listbox"), e(this, u).appendChild(e(this, o)), e(this, C).appendChild(t), t.addEventListener("keydown", this._onKeyDown.bind(this));
|
|
246
248
|
}
|
|
247
249
|
/**
|
|
248
250
|
* Initializes the core autocomplete functionality after the API is loaded.
|
|
@@ -258,10 +260,10 @@ class J {
|
|
|
258
260
|
e(this, o) && !e(this, o).contains(document.activeElement) && (e(this, o).style.display = "none", e(this, r).setAttribute("aria-expanded", "false"));
|
|
259
261
|
}, 200);
|
|
260
262
|
}), e(this, r).addEventListener("focus", () => {
|
|
261
|
-
e(this, r).value && e(this,
|
|
262
|
-
})) : e(this,
|
|
263
|
+
e(this, r).value && e(this, f).length > 0 && (e(this, o).style.display = "block", e(this, r).setAttribute("aria-expanded", "true"));
|
|
264
|
+
})) : e(this, g).call(this, new Error("Input element not found during initialization."));
|
|
263
265
|
} catch (t) {
|
|
264
|
-
console.error("Error initializing Google Places Autocomplete:", t), e(this,
|
|
266
|
+
console.error("Error initializing Google Places Autocomplete:", t), e(this, g).call(this, new Error("Google Maps Places library not available."));
|
|
265
267
|
}
|
|
266
268
|
}
|
|
267
269
|
/**
|
|
@@ -269,7 +271,7 @@ class J {
|
|
|
269
271
|
* @param {boolean} [refresh=false] - Whether to refresh the Google Places session token.
|
|
270
272
|
*/
|
|
271
273
|
_reset(t = !1) {
|
|
272
|
-
|
|
274
|
+
l(this, p, -1), e(this, r) && (e(this, r).value = ""), l(this, f, []), l(this, p, -1), e(this, o) && (e(this, o).innerHTML = "", e(this, o).style.display = "none"), t && this._refreshToken();
|
|
273
275
|
}
|
|
274
276
|
/**
|
|
275
277
|
* Removes the 'current' highlighting classes from all suggestion list items (li) and their links (a).
|
|
@@ -287,12 +289,12 @@ class J {
|
|
|
287
289
|
* @param {KeyboardEvent} e - The keyboard event object.
|
|
288
290
|
*/
|
|
289
291
|
_onKeyDown(t) {
|
|
290
|
-
if (!(!e(this,
|
|
292
|
+
if (!(!e(this, f).length || !e(this, o) || e(this, o).style.display === "none"))
|
|
291
293
|
if (this._resetLiClasses(), t.key === "ArrowDown") {
|
|
292
|
-
t.preventDefault(),
|
|
294
|
+
t.preventDefault(), l(this, p, Math.min(
|
|
293
295
|
e(this, p) + 1,
|
|
294
|
-
e(this,
|
|
295
|
-
)), e(this, p) < 0 &&
|
|
296
|
+
e(this, f).length - 1
|
|
297
|
+
)), e(this, p) < 0 && l(this, p, 0);
|
|
296
298
|
const s = e(this, o).children.item(e(this, p));
|
|
297
299
|
if (s) {
|
|
298
300
|
const i = s.querySelector("a");
|
|
@@ -300,16 +302,16 @@ class J {
|
|
|
300
302
|
}
|
|
301
303
|
e(this, n).classes.kbd_active.split(" ").forEach((i) => {
|
|
302
304
|
var a;
|
|
303
|
-
return (a = e(this,
|
|
305
|
+
return (a = e(this, w)) == null ? void 0 : a.classList.add(i);
|
|
304
306
|
}), setTimeout(
|
|
305
307
|
() => e(this, n).classes.kbd_active.split(" ").forEach((i) => {
|
|
306
308
|
var a;
|
|
307
|
-
return (a = e(this,
|
|
309
|
+
return (a = e(this, w)) == null ? void 0 : a.classList.remove(i);
|
|
308
310
|
}),
|
|
309
311
|
300
|
|
310
312
|
);
|
|
311
313
|
} else if (t.key === "ArrowUp") {
|
|
312
|
-
t.preventDefault(),
|
|
314
|
+
t.preventDefault(), l(this, p, Math.max(e(this, p) - 1, 0));
|
|
313
315
|
const s = e(this, o).children.item(e(this, p));
|
|
314
316
|
if (s) {
|
|
315
317
|
const i = s.querySelector("a");
|
|
@@ -317,23 +319,23 @@ class J {
|
|
|
317
319
|
}
|
|
318
320
|
e(this, n).classes.kbd_active.split(" ").forEach((i) => {
|
|
319
321
|
var a;
|
|
320
|
-
return (a = e(this,
|
|
322
|
+
return (a = e(this, E)) == null ? void 0 : a.classList.add(i);
|
|
321
323
|
}), setTimeout(
|
|
322
324
|
() => e(this, n).classes.kbd_active.split(" ").forEach((i) => {
|
|
323
325
|
var a;
|
|
324
|
-
return (a = e(this,
|
|
326
|
+
return (a = e(this, E)) == null ? void 0 : a.classList.remove(i);
|
|
325
327
|
}),
|
|
326
328
|
300
|
|
327
329
|
);
|
|
328
|
-
} else t.key === "Enter" ? (t.preventDefault(), e(this, p) >= 0 && e(this, p) < e(this,
|
|
329
|
-
e(this,
|
|
330
|
+
} else t.key === "Enter" ? (t.preventDefault(), e(this, p) >= 0 && e(this, p) < e(this, f).length && this._onPlaceSelected(
|
|
331
|
+
e(this, f)[e(this, p)].place
|
|
330
332
|
)) : t.key === "Escape" && (t.preventDefault(), e(this, n).classes.kbd_active.split(" ").forEach((s) => {
|
|
331
333
|
var i;
|
|
332
|
-
return (i = e(this,
|
|
334
|
+
return (i = e(this, x)) == null ? void 0 : i.classList.add(s);
|
|
333
335
|
}), setTimeout(
|
|
334
336
|
() => e(this, n).classes.kbd_active.split(" ").forEach((s) => {
|
|
335
337
|
var i;
|
|
336
|
-
return (i = e(this,
|
|
338
|
+
return (i = e(this, x)) == null ? void 0 : i.classList.remove(s);
|
|
337
339
|
}),
|
|
338
340
|
300
|
|
339
341
|
), this._reset(!0));
|
|
@@ -346,8 +348,8 @@ class J {
|
|
|
346
348
|
* @returns {Array<HTMLLIElement>} An array of LI elements to be added to the suggestions UL.
|
|
347
349
|
*/
|
|
348
350
|
_createSuggestionElements(t) {
|
|
349
|
-
return
|
|
350
|
-
e(this,
|
|
351
|
+
return l(this, f, []), t.map((s, i) => {
|
|
352
|
+
e(this, f).push({
|
|
351
353
|
id: i + 1,
|
|
352
354
|
description: s.placePrediction.toString(),
|
|
353
355
|
place: s.placePrediction.toPlace()
|
|
@@ -356,36 +358,36 @@ class J {
|
|
|
356
358
|
a.className = e(this, n).classes.li_div_container;
|
|
357
359
|
const d = document.createElement("div");
|
|
358
360
|
d.className = e(this, n).classes.li_div_one, a.appendChild(d);
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
const
|
|
362
|
-
let
|
|
363
|
-
|
|
364
|
-
const
|
|
361
|
+
const b = document.createElement("p");
|
|
362
|
+
b.className = e(this, n).classes.li_div_one_p;
|
|
363
|
+
const T = s.placePrediction.text, L = T.text, N = T.matches;
|
|
364
|
+
let y = 0;
|
|
365
|
+
N.sort((_, G) => _.startOffset - G.startOffset);
|
|
366
|
+
const v = document.createElement("span"), S = document.createElement("span");
|
|
365
367
|
S.classList = e(this, n).classes.highlight ?? "font-bold";
|
|
366
|
-
for (const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
),
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
),
|
|
374
|
-
const
|
|
375
|
-
L.substring(
|
|
368
|
+
for (const _ of N)
|
|
369
|
+
v.textContent += L.substring(
|
|
370
|
+
y,
|
|
371
|
+
_.startOffset
|
|
372
|
+
), _.startOffset > 0 && L.charAt(_.startOffset - 1) == " " && (S.textContent += " "), S.textContent += L.substring(
|
|
373
|
+
_.startOffset,
|
|
374
|
+
_.endOffset
|
|
375
|
+
), y = _.endOffset;
|
|
376
|
+
const I = document.createTextNode(
|
|
377
|
+
L.substring(y)
|
|
376
378
|
);
|
|
377
|
-
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
const
|
|
381
|
-
|
|
379
|
+
v.appendChild(S), v.appendChild(I), b.appendChild(v), d.appendChild(b), a.appendChild(d);
|
|
380
|
+
const q = document.createElement("div");
|
|
381
|
+
q.className = e(this, n).classes.li_div_two, a.appendChild(q);
|
|
382
|
+
const k = document.createElement("p");
|
|
383
|
+
k.className = e(this, n).classes.li_div_two_p, k.textContent = this._formatDistance(
|
|
382
384
|
s.placePrediction.distanceMeters,
|
|
383
385
|
e(this, n).distance_units ?? "km"
|
|
384
|
-
),
|
|
386
|
+
), q.appendChild(k);
|
|
385
387
|
const m = document.createElement("a");
|
|
386
388
|
m.href = "javascript:void(0)", m.tabIndex = i + 1, m.className = e(this, n).classes.li_a, m.addEventListener("click", () => {
|
|
387
389
|
this._onPlaceSelected(s.placePrediction.toPlace());
|
|
388
|
-
}), m.appendChild(a), m.appendChild(
|
|
390
|
+
}), m.appendChild(a), m.appendChild(q);
|
|
389
391
|
const P = document.createElement("li");
|
|
390
392
|
return P.id = `option-${i + 1}`, P.className = e(this, n).classes.li, P.appendChild(m), P;
|
|
391
393
|
});
|
|
@@ -401,9 +403,9 @@ class J {
|
|
|
401
403
|
await t.fetchFields({
|
|
402
404
|
fields: ["displayName", "formattedAddress", "addressComponents"]
|
|
403
405
|
// Add more fields as needed
|
|
404
|
-
}), e(this,
|
|
406
|
+
}), e(this, j).call(this, t.toJSON());
|
|
405
407
|
} catch (s) {
|
|
406
|
-
console.error("Error fetching place details:", s), e(this,
|
|
408
|
+
console.error("Error fetching place details:", s), e(this, g).call(this, s);
|
|
407
409
|
} finally {
|
|
408
410
|
this._reset(!0);
|
|
409
411
|
}
|
|
@@ -416,7 +418,7 @@ class J {
|
|
|
416
418
|
try {
|
|
417
419
|
e(this, A).sessionToken = new google.maps.places.AutocompleteSessionToken();
|
|
418
420
|
} catch (t) {
|
|
419
|
-
console.error("Error creating session token:", t), e(this,
|
|
421
|
+
console.error("Error creating session token:", t), e(this, g).call(this, t);
|
|
420
422
|
}
|
|
421
423
|
}
|
|
422
424
|
clear() {
|
|
@@ -426,14 +428,14 @@ class J {
|
|
|
426
428
|
e(this, r) && e(this, r).removeEventListener(
|
|
427
429
|
"input",
|
|
428
430
|
this._debouncedMakeAcRequest
|
|
429
|
-
), e(this,
|
|
431
|
+
), e(this, C) && e(this, u) && e(this, C).removeChild(e(this, u).parentElement);
|
|
430
432
|
for (const t in this)
|
|
431
433
|
Object.hasOwn(this, t) && (this[t] = null);
|
|
432
434
|
console.log("PacAutocomplete instance destroyed.");
|
|
433
435
|
}
|
|
434
436
|
}
|
|
435
|
-
|
|
437
|
+
M = new WeakMap(), C = new WeakMap(), D = new WeakMap(), O = new WeakMap(), n = new WeakMap(), A = new WeakMap(), r = new WeakMap(), u = new WeakMap(), o = new WeakMap(), x = new WeakMap(), E = new WeakMap(), w = new WeakMap(), f = new WeakMap(), p = new WeakMap(), j = new WeakMap(), g = new WeakMap(), R = new WeakMap(), z = new WeakMap();
|
|
436
438
|
export {
|
|
437
|
-
|
|
439
|
+
U as PlacesAutocomplete
|
|
438
440
|
};
|
|
439
441
|
//# sourceMappingURL=places-autocomplete.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"places-autocomplete.js","sources":["../lib/PlacesAutocomplete.js"],"sourcesContent":["/**\n * Initializes a Places Autocomplete widget.\n * This script dynamically loads the Google Maps JavaScript API, creates the UI elements\n * for the autocomplete input and suggestions list, handles user input with debouncing,\n * fetches suggestions, manages keyboard navigation, and calls user-defined callbacks\n * on place selection or error.\n *\n * @author Alexander Pechkarev <alexpechkarev@gmail.com>\n * @license MIT\n *\n */\n\n/**\n * PacAutocomplete class\n * This class provides a Places Autocomplete widget.\n */\nexport class PlacesAutocomplete {\n // --- Private Properties (using # or _ prefix by convention) ---\n #pacEl;\n #googleMapsApiKey;\n #googleMapsApiVersion;\n #options;\n #request;\n #inputElement;\n #container;\n #ul;\n #kbdEscape;\n #kbdUp;\n #kbdDown;\n #allSuggestions = [];\n #currentSuggestion = -1;\n #onDataCallback; // For user-provided data callback\n #onErrorCallback; // For user-provided error callback\n #defaultClasses = {\n // CSS classes for various parts of the widget.\n section: \"\", // Outer section container.\n container: \"relative z-10 transform rounded-xl mt-4\", // Main container div.\n icon_container:\n \"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3\", // Container for the search icon.\n icon: '<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"w-5 h-5\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"11\" cy=\"11\" r=\"8\" /><path d=\"m21 21-4.3-4.3\" /></svg>', // SVG for the search icon.\n input:\n \"border-1 w-full rounded-md border-0 shadow-sm bg-gray-100 px-4 py-2.5 pl-10 pr-20 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 sm:text-sm\", // Input field.\n kbd_container: \"absolute inset-y-0 right-0 flex py-1.5 pr-1.5\", // Container for keyboard hints.\n kbd_escape:\n \"inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1\", // Escape key hint.\n kbd_up:\n \"inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6\", // Up arrow key hint.\n kbd_down:\n \"inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6\", // Down arrow key hint.\n kbd_active: \"bg-indigo-500 text-white\", // Class for active keyboard hint.\n 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\", // Suggestions list (ul).\n li: \"z-50 cursor-default select-none py-2 px-2 lg:px-4 text-gray-900 hover:bg-indigo-500 hover:text-white\", // Suggestion item (li).\n li_current: \"bg-indigo-500\", // Class for the currently selected suggestion item.\n li_a: \"block w-full flex justify-between\", // Link element within a suggestion item.\n li_a_current: \"text-white\", // Class for the link in the currently selected suggestion item.\n li_div_container: \"flex min-w-0 gap-x-4\", // Container div within the suggestion link.\n li_div_one: \"min-w-0 flex-auto\", // First inner div (for place name).\n li_div_one_p: \"text-sm/6\", // Paragraph for the place name.\n li_div_two: \"shrink-0 flex flex-col items-end min-w-16\", // Second inner div (for distance).\n li_div_two_p: \"mt-1 text-xs/5\", // Paragraph for the distance.\n highlight: \"font-bold\", // Class for highlighting matched text in suggestions.\n };\n #defaultRequestParams = {\n // Default parameters for the autocomplete request.\n input: \"\", // Initial input value (empty).\n includedRegionCodes: [\"GB\"], // Default region codes to include in suggestions.\n language: \"en-gb\",\n region: \"GB\",\n };\n\n /**\n * Class constructor for PacAutocomplete.\n * Initializes the autocomplete widget with the provided configuration.\n * @param {Object} config - Configuration object for the autocomplete widget.\n * @param {string} config.containerId - ID of the container element for the widget.\n * @param {string} config.googleMapsApiKey - Google Maps API key.\n * @param {string} [config.googleMapsApiVersion] - Version of the Google Maps API to use (default: \"weekly\").\n * @param {Object} [config.options] - Additional options for the widget (e.g., classes, callbacks).\n * @param {Object} [config.requestParams] - Parameters for the autocomplete request (e.g., input, region).\n * @param {*} config\n */\n constructor(config) {\n // console.log(\"PacAutocomplete constructor called.\", config.requestParams);\n if (!config || !config.containerId || !config.googleMapsApiKey) {\n throw new Error(\n \"PacAutocomplete: Missing required configuration (containerId, googleMapsApiKey).\"\n );\n }\n\n this.#pacEl = document.getElementById(config.containerId);\n if (!this.#pacEl) {\n throw new Error(\n `PacAutocomplete: Container element with ID \"${config.containerId}\" not found.`\n );\n }\n\n this.#googleMapsApiKey = config.googleMapsApiKey;\n this.#googleMapsApiVersion = config.googleMapsApiVersion || \"weekly\";\n\n // Merge user options with defaults\n this.#options = {\n autofocus: false, // Automatically focus the input on load.\n autocomplete: \"off\", // HTML autocomplete attribute for the input.\n placeholder: \"Start typing your address ...\", // Placeholder text for the input.\n distance: true, // Show distance in suggestions (requires origin in request).\n distance_units: \"km\", // Units for distance ('km' or 'miles').\n label: \"\", // Optional label text above the input.\n debounce: 100, // Debounce delay (ms) for API requests.\n ...config.options, // User-defined options override defaults\n };\n // Ensure classes are deeply merged if user provides partial classes\n if (config.options && config.options.classes) {\n this.#options.classes = {\n ...this.#defaultClasses,\n ...config.options.classes,\n };\n } else {\n this.#options.classes = this.#defaultClasses; // Use default classes if none provided\n }\n\n // Set default response and error callbacks if not provided\n this.#onDataCallback =\n config.onResponse ||\n ((place) => {\n console.info(\"---------Default onResponse not provided---------\");\n console.info(\"Selected Place:\", JSON.stringify(place, null, 2));\n });\n this.#onErrorCallback =\n config.onError ||\n ((error) => {\n console.error(\"---------Default onError not provided---------\");\n console.error(\"PAC Error:\", error);\n });\n\n if (config.requestParams && Object.keys(config.requestParams).length > 0) {\n this.#request = {\n ...this.#defaultRequestParams,\n ...config.requestParams,\n };\n } else {\n this.#request = { ...this.#defaultRequestParams }; // Use defaults if no requestParams provided\n }\n\n //console.log(this.#request);\n\n this._init(); // Underscore prefix for internal initialization method\n }\n\n // --- Private Initialization Method ---\n async _init() {\n try {\n // check if google maps api is already loaded\n if (typeof google === \"undefined\" || !google.maps) {\n // Load the Google Maps API dynamically\n await this._loadGoogleMapsApi({\n key: this.#googleMapsApiKey,\n v: this.#googleMapsApiVersion,\n });\n }\n this._createPACStructure(); // Pass this.#options\n await this._initializeAutocomplete(); // Pass this.#options\n //console.log(\"PacAutocomplete Initialized for container:\", this.#pacEl.id);\n } catch (error) {\n this.#onErrorCallback(error);\n }\n }\n\n /**\n * Creates a debounced version of a function.\n * The debounced function delays invoking `func` until after `wait` milliseconds have\n * elapsed since the last time the debounced function was invoked.\n * @param {Function} func - The function to debounce.\n * @param {number} wait - The number of milliseconds to delay.\n * @returns {Function} The new debounced function.\n */\n _debounce(func, wait) {\n let timeout = null;\n return function executedFunction(...args) {\n const later = () => {\n timeout = null;\n func(...args); // Call original function\n };\n if (timeout !== null) {\n clearTimeout(timeout); // Clear the previous timeout\n }\n timeout = setTimeout(later, wait ?? 100); // Set the new timeout\n };\n }\n /**\n * Formats a distance in meters into kilometers or miles.\n * @param {number | null | undefined} distance - Distance in meters.\n * @param {'km' | 'miles'} units - The desired output units.\n * @returns {string | null} Formatted distance string (e.g., \"1.23 km\") or null if input is invalid.\n */\n _formatDistance(distance, units) {\n if (typeof distance !== \"number\" || !this.#options.distance) {\n return null; // Return null if distance isn't shown or invalid\n }\n let value;\n let unitLabel;\n if (units === \"km\") {\n value = (distance / 1000).toFixed(2);\n unitLabel = \"km\";\n } else {\n // Default to miles if not 'km'\n value = (distance / 1609.34).toFixed(2);\n unitLabel = \"miles\";\n }\n // Avoid showing \".00\"\n value = value.replace(/\\.00$/, \"\");\n return `${value} ${unitLabel}`;\n }\n\n /**\n * Dynamically loads the Google Maps JavaScript API using the importLibrary method.\n * This is the standard approach recommended by Google.\n * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api\n * @param {object} g - Configuration object for the API loader (key, v, libraries, etc.).\n */\n async _loadGoogleMapsApi(g) {\n var h, // Promise tracking API load\n a, // Script element\n k, // Loop variable for config keys\n p = \"The Google Maps JavaScript API\", // Error message prefix\n c = \"google\", // Global namespace\n l = \"importLibrary\", // Loader function name\n q = \"__ib__\", // Internal callback name\n m = document, // Document reference\n b = window; // Window reference\n b = b[c] || (b[c] = {}); // Ensure google namespace exists\n var d = b.maps || (b.maps = {}), // Ensure google.maps namespace exists\n r = new Set(), // Set to track requested libraries\n e = new URLSearchParams(), // URL parameters for the API script\n u = () =>\n // Function to initiate API loading (if not already started)\n h ||\n // eslint-disable-next-line no-async-promise-executor\n (h = new Promise(async (f, n) => {\n // Create script element (done async to potentially wait for nonce)\n // await (a = m.createElement('script')); // Original Google code had await here, might not be needed\n a = m.createElement(\"script\"); // Create script tag\n e.set(\"libraries\", [...r].join(\",\")); // Add accumulated libraries\n // Add other parameters from the config object 'g'\n for (k in g)\n e.set(\n k.replace(/[A-Z]/g, (t) => \"_\" + t[0].toLowerCase()), // Convert camelCase to snake_case\n g[k]\n );\n e.set(\"callback\", c + \".maps.\" + q); // Set the internal callback function name\n a.src = `https://maps.${c}apis.com/maps/api/js?` + e; // Construct the API URL\n d[q] = f; // Assign the promise resolver to the callback name on google.maps\n // Error handling for script loading failure\n a.onerror = () => (h = n(Error(p + \" could not load.\"))); // Use onerror for load failures\n // Nonce for Content Security Policy\n a.nonce = m.querySelector(\"script[nonce]\")?.nonce || \"\";\n m.head.append(a); // Append the script to the document head\n }));\n // Define or reuse the importLibrary function on google.maps\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n d[l]\n ? console.warn(p + \" only loads once. Ignoring:\", g) // Warn if called again\n : (d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))); // The actual importLibrary implementation\n }\n\n // --- UI Creation ---\n _createPACStructure() {\n const section = document.createElement(\"section\");\n this.#options.classes.section\n .split(\" \")\n .forEach((cl) => cl && section.classList.add(cl));\n\n // Main container\n this.#container = document.createElement(\"div\");\n this.#container.className = this.#options.classes.container;\n this.#container.setAttribute(\"id\", this.#pacEl);\n section.appendChild(this.#container);\n\n // Icon\n const iconContainer = document.createElement(\"div\");\n iconContainer.className = this.#options.classes.icon_container;\n this.#container.appendChild(iconContainer);\n const icon = document.createElement(\"div\");\n icon.innerHTML = this.#options.classes.icon;\n iconContainer.appendChild(icon.firstElementChild); // Append the actual SVG element\n\n // Input field\n this.#inputElement = document.createElement(\"input\");\n this.#inputElement.id = \"input\" + this.#pacEl; // Assign ID for label association\n this.#inputElement.type = \"text\";\n this.#inputElement.name = \"search\"; // Consider making name configurable\n this.#inputElement.placeholder = this.#options.placeholder;\n this.#inputElement.autocomplete = this.#options.autocomplete;\n this.#inputElement.className = this.#options.classes.input;\n this.#inputElement.setAttribute(\"role\", \"combobox\");\n this.#inputElement.setAttribute(\"aria-autocomplete\", \"list\");\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\"); // Will be updated dynamically\n this.#inputElement.setAttribute(\"aria-controls\", \"pacSuggestions\"); // Links to the suggestions list\n\n if (this.#options.autofocus) {\n this.#inputElement.autofocus = true;\n }\n if (this.#options.label) {\n const label = document.createElement(\"label\");\n label.htmlFor = \"labelInput\" + this.#pacEl; // Assuming inputElement gets this ID\n label.textContent = this.#options.label;\n // Add label classes if needed from opts.classes\n this.#container.appendChild(label); // Append label before input or adjust structure\n }\n this.#container.appendChild(this.#inputElement);\n\n // Keyboard hints container\n const kbdContainer = document.createElement(\"div\");\n kbdContainer.className = this.#options.classes.kbd_container;\n this.#kbdEscape = document.createElement(\"kbd\");\n this.#kbdEscape.className = this.#options.classes.kbd_escape;\n this.#kbdEscape.textContent = \"Esc\";\n kbdContainer.appendChild(this.#kbdEscape);\n this.#kbdUp = document.createElement(\"kbd\");\n this.#kbdUp.className = this.#options.classes.kbd_up;\n this.#kbdUp.innerHTML = \"↑\"; // Up arrow HTML entity\n kbdContainer.appendChild(this.#kbdUp);\n this.#kbdDown = document.createElement(\"kbd\");\n this.#kbdDown.className = this.#options.classes.kbd_down;\n this.#kbdDown.innerHTML = \"↓\"; // Down arrow HTML entity\n kbdContainer.appendChild(this.#kbdDown);\n this.#container.appendChild(kbdContainer);\n\n // Suggestions list (initially hidden)\n this.#ul = document.createElement(\"ul\");\n this.#ul.id = \"pacSuggestions\"; // Must match aria-controls\n this.#ul.className = this.#options.classes.ul;\n this.#ul.style.display = \"none\";\n this.#ul.setAttribute(\"role\", \"listbox\");\n this.#container.appendChild(this.#ul);\n\n this.#pacEl.appendChild(section);\n section.addEventListener(\"keydown\", this._onKeyDown.bind(this)); // Bind 'this'\n }\n\n /**\n * Initializes the core autocomplete functionality after the API is loaded.\n * Imports necessary libraries and sets up the input event listener.\n */\n async _initializeAutocomplete() {\n try {\n // Ensure the 'places' library is available via the dynamic loader\n // eslint-disable-next-line no-undef\n await google.maps.importLibrary(\"places\");\n // console.log('Places library imported successfully.'); // For debugging\n\n // Initial token generation\n this._refreshToken();\n\n // Attach the debounced request function to the input element's 'input' event\n if (this.#inputElement) {\n this.#inputElement.addEventListener(\n \"input\",\n this._debouncedMakeAcRequest.bind(this)\n );\n // Add focus/blur listeners if needed to manage suggestion visibility\n this.#inputElement.addEventListener(\"blur\", () => {\n // Delay hiding suggestions to allow click events on them\n setTimeout(() => {\n if (this.#ul && !this.#ul.contains(document.activeElement)) {\n // Check if focus moved outside suggestions\n this.#ul.style.display = \"none\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n }\n }, 200); // Adjust delay as needed\n });\n this.#inputElement.addEventListener(\"focus\", () => {\n // Potentially show suggestions again if input has value\n if (this.#inputElement.value && this.#allSuggestions.length > 0) {\n this.#ul.style.display = \"block\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"true\");\n }\n });\n } else {\n this.#onErrorCallback(\n new Error(\"Input element not found during initialization.\")\n );\n }\n } catch (error) {\n console.error(\"Error initializing Google Places Autocomplete:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(\n new Error(\"Google Maps Places library not available.\")\n );\n }\n }\n\n /**\n * Resets the autocomplete input field, clears suggestions, and optionally refreshes the session token.\n * @param {boolean} [refresh=false] - Whether to refresh the Google Places session token.\n */\n _reset(refresh = false) {\n this.#currentSuggestion = -1;\n if (this.#inputElement) {\n this.#inputElement.value = \"\";\n }\n this.#allSuggestions = [];\n this.#currentSuggestion = -1;\n if (this.#ul) {\n this.#ul.innerHTML = \"\"; // Clear existing suggestions\n this.#ul.style.display = \"none\";\n }\n if (refresh) {\n this._refreshToken();\n }\n }\n /**\n * Removes the 'current' highlighting classes from all suggestion list items (li) and their links (a).\n */\n _resetLiClasses() {\n if (!this.#ul) return;\n Array.from(this.#ul.children).forEach((li) => {\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => li.classList.remove(cl));\n const link = li.querySelector(\"a\");\n if (link) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => link.classList.remove(cl));\n }\n });\n }\n\n /**\n * Handles keyboard events (ArrowDown, ArrowUp, Enter, Escape) for navigating\n * and selecting suggestions or closing the list.\n * @param {KeyboardEvent} e - The keyboard event object.\n */\n _onKeyDown(e) {\n if (\n !this.#allSuggestions.length ||\n !this.#ul ||\n this.#ul.style.display === \"none\"\n )\n return;\n\n this._resetLiClasses(); // Reset classes on any key press within the suggestions\n\n if (e.key === \"ArrowDown\") {\n e.preventDefault(); // Prevent cursor movement in input\n this.#currentSuggestion = Math.min(\n this.#currentSuggestion + 1,\n this.#allSuggestions.length - 1\n );\n if (this.#currentSuggestion < 0) this.#currentSuggestion = 0; // Handle case where it was -1\n\n const currentLi = this.#ul.children.item(this.#currentSuggestion);\n if (currentLi) {\n const currentA = currentLi.querySelector(\"a\");\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => currentLi.classList.add(cl));\n if (currentA) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => currentA.classList.add(cl));\n }\n currentLi.scrollIntoView({ block: \"nearest\" }); // Ensure visible\n }\n\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdDown?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdDown?.classList.remove(cl)),\n 300\n );\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault(); // Prevent cursor movement in input\n this.#currentSuggestion = Math.max(this.#currentSuggestion - 1, 0); // Stay at 0 if already there\n\n const currentLi = this.#ul.children.item(this.#currentSuggestion);\n if (currentLi) {\n const currentA = currentLi.querySelector(\"a\");\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => currentLi.classList.add(cl));\n if (currentA) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => currentA.classList.add(cl));\n }\n currentLi.scrollIntoView({ block: \"nearest\" }); // Ensure visible\n }\n\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdUp?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdUp?.classList.remove(cl)),\n 300\n );\n } else if (e.key === \"Enter\") {\n e.preventDefault(); // Prevent form submission if applicable\n if (\n this.#currentSuggestion >= 0 &&\n this.#currentSuggestion < this.#allSuggestions.length\n ) {\n this._onPlaceSelected(\n this.#allSuggestions[this.#currentSuggestion].place\n );\n // Reset is handled within onPlaceSelected via reset(true)\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdEscape?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdEscape?.classList.remove(cl)),\n 300\n );\n this._reset(true); // Reset search input and results, refresh token\n }\n }\n\n /**\n * Debounced function to fetch autocomplete suggestions from the Google Places API.\n * Triggered by the 'input' event on the input element.\n */\n _debouncedMakeAcRequest = this._debounce(async () => {\n if (!this.#inputElement || !this.#inputElement.value) {\n this._reset();\n if (this.#inputElement)\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n return;\n }\n\n this.#request.input = this.#inputElement.value;\n //console.log(\"Request:\", this.#request); // Debugging\n try {\n const { suggestions } =\n // eslint-disable-next-line no-undef\n await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(\n this.#request\n );\n\n // Display suggestions\n if (suggestions && suggestions.length > 0) {\n this.#ul.replaceChildren(\n ...this._createSuggestionElements(suggestions)\n );\n this.#ul.style.display = \"block\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"true\");\n } else {\n // No suggestions found\n this._reset(); // Clear any old suggestions\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n // Optionally display a \"no results\" message in the 'ul'\n }\n } catch (error) {\n this.#onErrorCallback(error);\n this._reset();\n if (this.#inputElement)\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n }\n }, this.#options?.debounce ?? 100);\n\n /**\n * Creates an array of list item (LI) elements for the suggestions dropdown.\n * Each LI contains a link (A) with the place prediction details and distance.\n * Handles highlighting the matched parts of the suggestion text.\n * @param {Array<google.maps.places.AutocompleteSuggestion>} suggestions - Array of suggestion objects from the API.\n * @returns {Array<HTMLLIElement>} An array of LI elements to be added to the suggestions UL.\n */\n _createSuggestionElements(suggestions) {\n this.#allSuggestions = []; // Reset before populating\n return suggestions.map((suggestion, index) => {\n this.#allSuggestions.push({\n id: index + 1,\n description: suggestion.placePrediction.toString(),\n place: suggestion.placePrediction.toPlace(),\n });\n\n // create div elements\n const divContainer = document.createElement(\"div\");\n divContainer.className = this.#options.classes.li_div_container; // flex min-w-0 gap-x-4\n // create inner div element - place name\n const divInner = document.createElement(\"div\");\n divInner.className = this.#options.classes.li_div_one; // min-w-0 flex-auto\n divContainer.appendChild(divInner);\n // create p element - place name\n const p = document.createElement(\"p\");\n p.className = this.#options.classes.li_div_one_p; // text-sm/6\n\n // get prediction text\n const predictionText = suggestion.placePrediction.text;\n const originalText = predictionText.text;\n // Array of objects with startOffset, endOffset\n const matches = predictionText.matches;\n\n //Highlighting Logic\n let lastIndex = 0;\n\n // Sort matches just in case they aren't ordered (though they usually are)\n matches.sort((a, b) => a.startOffset - b.startOffset);\n\n // 1. Create the outer span\n const outerSpan = document.createElement(\"span\");\n\n // 2. Create the inner span for the bold part\n const innerSpan = document.createElement(\"span\");\n innerSpan.classList = this.#options.classes.highlight ?? \"font-bold\"; // Use the highlight class from options\n\n for (const match of matches) {\n // Append text before the current match\n outerSpan.textContent += originalText.substring(\n lastIndex,\n match.startOffset\n );\n\n // Append the highlighted match segment\n if (match.startOffset > 0) {\n // check previous charter is space\n const prevChar = originalText.charAt(match.startOffset - 1);\n if (prevChar == \" \") {\n innerSpan.textContent += \" \";\n }\n }\n innerSpan.textContent += originalText.substring(\n match.startOffset,\n match.endOffset\n );\n\n // Update the last index processed\n lastIndex = match.endOffset;\n }\n\n // 3. Create a text node for the remaining text\n const remainingText = document.createTextNode(\n originalText.substring(lastIndex)\n );\n\n // 4. Append the inner span and the text node to the outer span\n outerSpan.appendChild(innerSpan);\n outerSpan.appendChild(remainingText);\n\n // 5. Append the outer span to the paragraph element\n p.appendChild(outerSpan);\n\n divInner.appendChild(p);\n divContainer.appendChild(divInner);\n\n // create inner div element - distance\n const divInner2 = document.createElement(\"div\");\n divInner2.className = this.#options.classes.li_div_two; //'shrink-0 flex flex-col items-end min-w-16';\n divContainer.appendChild(divInner2);\n // create p element - distance\n const p2 = document.createElement(\"p\");\n p2.className = this.#options.classes.li_div_two_p; //'mt-1 text-xs/5 ';\n p2.textContent = this._formatDistance(\n suggestion.placePrediction.distanceMeters,\n this.#options.distance_units ?? \"km\"\n );\n divInner2.appendChild(p2);\n\n // // create a link element\n const a = document.createElement(\"a\");\n a.href = \"javascript:void(0)\";\n a.tabIndex = index + 1;\n a.className = this.#options.classes.li_a; // block w-full flex justify-between\n\n a.addEventListener(\"click\", () => {\n this._onPlaceSelected(suggestion.placePrediction.toPlace());\n });\n\n // ...\n // a.addEventListener(\"click\", () => {\n // this._fetchPlaceDetails(prediction.place_id);\n // });\n a.appendChild(divContainer);\n a.appendChild(divInner2);\n\n const li = document.createElement(\"li\");\n li.id = `option-${index + 1}`;\n li.className = this.#options.classes.li;\n\n li.appendChild(a);\n return li;\n });\n }\n\n /**\n * Handles the selection of a place. Fetches required fields\n * (displayName, formattedAddress, addressComponents) and calls the\n * user-defined `onPacData` callback.\n * @param {google.maps.places.Place} place - The selected Place object.\n */\n async _onPlaceSelected(place) {\n try {\n // Fetch necessary details for the selected place\n await place.fetchFields({\n fields: [\"displayName\", \"formattedAddress\", \"addressComponents\"], // Add more fields as needed\n });\n // Call the user-provided callback with the place data\n // eslint-disable-next-line no-undef\n this.#onDataCallback(place.toJSON()); // Convert to plain JSON object for the callback\n } catch (error) {\n console.error(\"Error fetching place details:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(error);\n } finally {\n // Reset the input and suggestions regardless of success/error\n this._reset(true); // Refresh token after selection\n }\n }\n\n /**\n * Creates a new Google Places Autocomplete Session Token.\n * This should be called before starting a new series of autocomplete requests.\n */\n _refreshToken() {\n try {\n // eslint-disable-next-line no-undef\n this.#request.sessionToken =\n new google.maps.places.AutocompleteSessionToken();\n } catch (error) {\n console.error(\"Error creating session token:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(error);\n }\n }\n\n clear() {\n this._reset(true);\n }\n\n destroy() {\n // Remove event listeners, remove elements from DOM\n if (this.#inputElement) {\n this.#inputElement.removeEventListener(\n \"input\",\n this._debouncedMakeAcRequest\n );\n // remove other listeners\n }\n if (this.#pacEl && this.#container) {\n this.#pacEl.removeChild(this.#container.parentElement); // remove the whole section\n }\n // Nullify properties\n for (const prop in this) {\n if (Object.hasOwn(this, prop)) {\n this[prop] = null;\n }\n }\n console.log(\"PacAutocomplete instance destroyed.\");\n }\n}\n"],"names":["_a","_pacEl","_googleMapsApiKey","_googleMapsApiVersion","_options","_request","_inputElement","_container","_ul","_kbdEscape","_kbdUp","_kbdDown","_allSuggestions","_currentSuggestion","_onDataCallback","_onErrorCallback","_defaultClasses","_defaultRequestParams","PlacesAutocomplete","config","__privateAdd","__publicField","__privateGet","suggestions","error","__privateSet","place","func","wait","timeout","args","later","distance","units","value","unitLabel","g","h","a","k","p","c","l","q","m","b","d","r","e","u","f","n","t","section","cl","iconContainer","icon","label","kbdContainer","refresh","li","link","currentLi","currentA","suggestion","index","divContainer","divInner","predictionText","originalText","matches","lastIndex","outerSpan","innerSpan","match","remainingText","divInner2","p2","prop"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC;AAgBO,MAAMC,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiE9B,YAAYC,GAAQ;AA/DpB;AAAA,IAAAC,EAAA,MAAAnB;AACA,IAAAmB,EAAA,MAAAlB;AACA,IAAAkB,EAAA,MAAAjB;AACA,IAAAiB,EAAA,MAAAhB;AACA,IAAAgB,EAAA,MAAAf;AACA,IAAAe,EAAA,MAAAd;AACA,IAAAc,EAAA,MAAAb;AACA,IAAAa,EAAA,MAAAZ;AACA,IAAAY,EAAA,MAAAX;AACA,IAAAW,EAAA,MAAAV;AACA,IAAAU,EAAA,MAAAT;AACA,IAAAS,EAAA,MAAAR,GAA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AA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eA6BAC,IAAA;"}
|
|
1
|
+
{"version":3,"file":"places-autocomplete.js","sources":["../lib/PlacesAutocomplete.js"],"sourcesContent":["/**\n * Initializes a Places Autocomplete widget.\n * This script dynamically loads the Google Maps JavaScript API, creates the UI elements\n * for the autocomplete input and suggestions list, handles user input with debouncing,\n * fetches suggestions, manages keyboard navigation, and calls user-defined callbacks\n * on place selection or error.\n *\n * @author Alexander Pechkarev <alexpechkarev@gmail.com>\n * @license MIT\n *\n */\n\n/**\n * PacAutocomplete class\n * This class provides a Places Autocomplete widget.\n */\nexport class PlacesAutocomplete {\n // --- Private Properties (using # or _ prefix by convention) ---\n #containerId; // Container ID where the autocomplete widget will be rendered.\n #pacEl;\n #googleMapsApiKey;\n #googleMapsApiVersion;\n #options;\n #request;\n #inputElement;\n #container;\n #ul;\n #kbdEscape;\n #kbdUp;\n #kbdDown;\n #allSuggestions = [];\n #currentSuggestion = -1;\n #onDataCallback; // For user-provided data callback\n #onErrorCallback; // For user-provided error callback\n #defaultClasses = {\n // CSS classes for various parts of the widget.\n section: \"\", // Outer section container.\n container: \"relative z-10 transform rounded-xl mt-4\", // Main container div.\n icon_container:\n \"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3\", // Container for the search icon.\n icon: '<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"w-5 h-5\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"11\" cy=\"11\" r=\"8\" /><path d=\"m21 21-4.3-4.3\" /></svg>', // SVG for the search icon.\n input:\n \"border-1 w-full rounded-md border-0 shadow-sm bg-gray-100 px-4 py-2.5 pl-10 pr-20 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 sm:text-sm\", // Input field.\n kbd_container: \"absolute inset-y-0 right-0 flex py-1.5 pr-1.5\", // Container for keyboard hints.\n kbd_escape:\n \"inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1\", // Escape key hint.\n kbd_up:\n \"inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6\", // Up arrow key hint.\n kbd_down:\n \"inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6\", // Down arrow key hint.\n kbd_active: \"bg-indigo-500 text-white\", // Class for active keyboard hint.\n 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\", // Suggestions list (ul).\n li: \"z-50 cursor-default select-none py-2 px-2 lg:px-4 text-gray-900 hover:bg-indigo-500 hover:text-white\", // Suggestion item (li).\n li_current: \"bg-indigo-500\", // Class for the currently selected suggestion item.\n li_a: \"block w-full flex justify-between\", // Link element within a suggestion item.\n li_a_current: \"text-white\", // Class for the link in the currently selected suggestion item.\n li_div_container: \"flex min-w-0 gap-x-4\", // Container div within the suggestion link.\n li_div_one: \"min-w-0 flex-auto\", // First inner div (for place name).\n li_div_one_p: \"text-sm/6\", // Paragraph for the place name.\n li_div_two: \"shrink-0 flex flex-col items-end min-w-16\", // Second inner div (for distance).\n li_div_two_p: \"mt-1 text-xs/5\", // Paragraph for the distance.\n highlight: \"font-bold\", // Class for highlighting matched text in suggestions.\n };\n #defaultRequestParams = {\n // Default parameters for the autocomplete request.\n input: \"\", // Initial input value (empty).\n includedRegionCodes: [\"GB\"], // Default region codes to include in suggestions.\n language: \"en-gb\",\n region: \"GB\",\n };\n\n /**\n * Class constructor for PacAutocomplete.\n * Initializes the autocomplete widget with the provided configuration.\n * @param {Object} config - Configuration object for the autocomplete widget.\n * @param {string} config.containerId - ID of the container element for the widget.\n * @param {string} config.googleMapsApiKey - Google Maps API key.\n * @param {string} [config.googleMapsApiVersion] - Version of the Google Maps API to use (default: \"weekly\").\n * @param {Object} [config.options] - Additional options for the widget (e.g., classes, callbacks).\n * @param {Object} [config.requestParams] - Parameters for the autocomplete request (e.g., input, region).\n * @param {*} config\n */\n constructor(config) {\n // console.log(\"PacAutocomplete constructor called.\", config.requestParams);\n if (!config || !config.containerId || !config.googleMapsApiKey) {\n throw new Error(\n \"PacAutocomplete: Missing required configuration (containerId, googleMapsApiKey).\"\n );\n }\n\n this.#containerId = config.containerId; // Store the configuration object\n this.#pacEl = document.getElementById(config.containerId);\n if (!this.#pacEl) {\n throw new Error(\n `PacAutocomplete: Container element with ID \"${config.containerId}\" not found.`\n );\n }\n\n this.#googleMapsApiKey = config.googleMapsApiKey;\n this.#googleMapsApiVersion = config.googleMapsApiVersion || \"weekly\";\n\n // Merge user options with defaults\n this.#options = {\n autofocus: false, // Automatically focus the input on load.\n autocomplete: \"off\", // HTML autocomplete attribute for the input.\n placeholder: \"Start typing your address ...\", // Placeholder text for the input.\n distance: true, // Show distance in suggestions (requires origin in request).\n distance_units: \"km\", // Units for distance ('km' or 'miles').\n label: \"\", // Optional label text above the input.\n debounce: 100, // Debounce delay (ms) for API requests.\n ...config.options, // User-defined options override defaults\n };\n // Ensure classes are deeply merged if user provides partial classes\n if (config.options && config.options.classes) {\n this.#options.classes = {\n ...this.#defaultClasses,\n ...config.options.classes,\n };\n } else {\n this.#options.classes = this.#defaultClasses; // Use default classes if none provided\n }\n\n // Set default response and error callbacks if not provided\n this.#onDataCallback =\n config.onResponse ||\n ((place) => {\n console.info(\"---------Default onResponse not provided---------\");\n console.info(\"Selected Place:\", JSON.stringify(place, null, 2));\n });\n this.#onErrorCallback =\n config.onError ||\n ((error) => {\n console.error(\"---------Default onError not provided---------\");\n console.error(\"PAC Error:\", error);\n });\n\n if (config.requestParams && Object.keys(config.requestParams).length > 0) {\n this.#request = {\n ...this.#defaultRequestParams,\n ...config.requestParams,\n };\n } else {\n this.#request = { ...this.#defaultRequestParams }; // Use defaults if no requestParams provided\n }\n\n //console.log(this.#request);\n\n this._init(); // Underscore prefix for internal initialization method\n }\n\n // --- Private Initialization Method ---\n async _init() {\n try {\n // check if google maps api is already loaded\n if (typeof google === \"undefined\" || !google.maps) {\n // Load the Google Maps API dynamically\n await this._loadGoogleMapsApi({\n key: this.#googleMapsApiKey,\n v: this.#googleMapsApiVersion,\n });\n }\n this._createPACStructure(); // Pass this.#options\n await this._initializeAutocomplete(); // Pass this.#options\n //console.log(\"PacAutocomplete Initialized for container:\", this.#pacEl.id);\n } catch (error) {\n this.#onErrorCallback(error);\n }\n }\n\n /**\n * Creates a debounced version of a function.\n * The debounced function delays invoking `func` until after `wait` milliseconds have\n * elapsed since the last time the debounced function was invoked.\n * @param {Function} func - The function to debounce.\n * @param {number} wait - The number of milliseconds to delay.\n * @returns {Function} The new debounced function.\n */\n _debounce(func, wait) {\n let timeout = null;\n return function executedFunction(...args) {\n const later = () => {\n timeout = null;\n func(...args); // Call original function\n };\n if (timeout !== null) {\n clearTimeout(timeout); // Clear the previous timeout\n }\n timeout = setTimeout(later, wait ?? 100); // Set the new timeout\n };\n }\n /**\n * Formats a distance in meters into kilometers or miles.\n * @param {number | null | undefined} distance - Distance in meters.\n * @param {'km' | 'miles'} units - The desired output units.\n * @returns {string | null} Formatted distance string (e.g., \"1.23 km\") or null if input is invalid.\n */\n _formatDistance(distance, units) {\n if (typeof distance !== \"number\" || !this.#options.distance) {\n return null; // Return null if distance isn't shown or invalid\n }\n let value;\n let unitLabel;\n if (units === \"km\") {\n value = (distance / 1000).toFixed(2);\n unitLabel = \"km\";\n } else {\n // Default to miles if not 'km'\n value = (distance / 1609.34).toFixed(2);\n unitLabel = \"miles\";\n }\n // Avoid showing \".00\"\n value = value.replace(/\\.00$/, \"\");\n return `${value} ${unitLabel}`;\n }\n\n /**\n * Dynamically loads the Google Maps JavaScript API using the importLibrary method.\n * This is the standard approach recommended by Google.\n * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api\n * @param {object} g - Configuration object for the API loader (key, v, libraries, etc.).\n */\n async _loadGoogleMapsApi(g) {\n var h, // Promise tracking API load\n a, // Script element\n k, // Loop variable for config keys\n p = \"The Google Maps JavaScript API\", // Error message prefix\n c = \"google\", // Global namespace\n l = \"importLibrary\", // Loader function name\n q = \"__ib__\", // Internal callback name\n m = document, // Document reference\n b = window; // Window reference\n b = b[c] || (b[c] = {}); // Ensure google namespace exists\n var d = b.maps || (b.maps = {}), // Ensure google.maps namespace exists\n r = new Set(), // Set to track requested libraries\n e = new URLSearchParams(), // URL parameters for the API script\n u = () =>\n // Function to initiate API loading (if not already started)\n h ||\n // eslint-disable-next-line no-async-promise-executor\n (h = new Promise(async (f, n) => {\n // Create script element (done async to potentially wait for nonce)\n // await (a = m.createElement('script')); // Original Google code had await here, might not be needed\n a = m.createElement(\"script\"); // Create script tag\n e.set(\"libraries\", [...r].join(\",\")); // Add accumulated libraries\n // Add other parameters from the config object 'g'\n for (k in g)\n e.set(\n k.replace(/[A-Z]/g, (t) => \"_\" + t[0].toLowerCase()), // Convert camelCase to snake_case\n g[k]\n );\n e.set(\"callback\", c + \".maps.\" + q); // Set the internal callback function name\n a.src = `https://maps.${c}apis.com/maps/api/js?` + e; // Construct the API URL\n d[q] = f; // Assign the promise resolver to the callback name on google.maps\n // Error handling for script loading failure\n a.onerror = () => (h = n(Error(p + \" could not load.\"))); // Use onerror for load failures\n // Nonce for Content Security Policy\n a.nonce = m.querySelector(\"script[nonce]\")?.nonce || \"\";\n m.head.append(a); // Append the script to the document head\n }));\n // Define or reuse the importLibrary function on google.maps\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n d[l]\n ? console.warn(p + \" only loads once. Ignoring:\", g) // Warn if called again\n : (d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))); // The actual importLibrary implementation\n }\n\n // --- UI Creation ---\n _createPACStructure() {\n const section = document.createElement(\"section\");\n this.#options.classes.section\n .split(\" \")\n .forEach((cl) => cl && section.classList.add(cl));\n\n // Main container\n this.#container = document.createElement(\"div\");\n this.#container.className = this.#options.classes.container;\n this.#container.setAttribute(\"id\", this.#containerId + \"-div\");\n section.appendChild(this.#container);\n\n // Icon\n const iconContainer = document.createElement(\"div\");\n iconContainer.className = this.#options.classes.icon_container;\n this.#container.appendChild(iconContainer);\n const icon = document.createElement(\"div\");\n icon.innerHTML = this.#options.classes.icon;\n iconContainer.appendChild(icon.firstElementChild); // Append the actual SVG element\n\n // Input field\n this.#inputElement = document.createElement(\"input\");\n this.#inputElement.id = this.#containerId + \"-input\"; // Assign ID for label association\n this.#inputElement.type = \"text\";\n this.#inputElement.name = \"search\"; // Consider making name configurable\n this.#inputElement.placeholder = this.#options.placeholder;\n this.#inputElement.autocomplete = this.#options.autocomplete;\n this.#inputElement.className = this.#options.classes.input;\n this.#inputElement.setAttribute(\"role\", \"combobox\");\n this.#inputElement.setAttribute(\"aria-autocomplete\", \"list\");\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\"); // Will be updated dynamically\n this.#inputElement.setAttribute(\"aria-controls\", \"pacSuggestions\"); // Links to the suggestions list\n\n if (this.#options.autofocus) {\n this.#inputElement.autofocus = true;\n }\n if (this.#options.label) {\n const label = document.createElement(\"label\");\n label.htmlFor = this.#containerId + \"-labelInput\"; // Assuming inputElement gets this ID\n label.textContent = this.#options.label;\n // Add label classes if needed from opts.classes\n this.#container.appendChild(label); // Append label before input or adjust structure\n }\n this.#container.appendChild(this.#inputElement);\n\n // Keyboard hints container\n const kbdContainer = document.createElement(\"div\");\n kbdContainer.className = this.#options.classes.kbd_container;\n this.#kbdEscape = document.createElement(\"kbd\");\n this.#kbdEscape.className = this.#options.classes.kbd_escape;\n this.#kbdEscape.textContent = \"Esc\";\n kbdContainer.appendChild(this.#kbdEscape);\n this.#kbdUp = document.createElement(\"kbd\");\n this.#kbdUp.className = this.#options.classes.kbd_up;\n this.#kbdUp.innerHTML = \"↑\"; // Up arrow HTML entity\n kbdContainer.appendChild(this.#kbdUp);\n this.#kbdDown = document.createElement(\"kbd\");\n this.#kbdDown.className = this.#options.classes.kbd_down;\n this.#kbdDown.innerHTML = \"↓\"; // Down arrow HTML entity\n kbdContainer.appendChild(this.#kbdDown);\n this.#container.appendChild(kbdContainer);\n\n // Suggestions list (initially hidden)\n this.#ul = document.createElement(\"ul\");\n this.#ul.id = \"pacSuggestions\"; // Must match aria-controls\n this.#ul.className = this.#options.classes.ul;\n this.#ul.style.display = \"none\";\n this.#ul.setAttribute(\"role\", \"listbox\");\n this.#container.appendChild(this.#ul);\n\n this.#pacEl.appendChild(section);\n section.addEventListener(\"keydown\", this._onKeyDown.bind(this)); // Bind 'this'\n }\n\n /**\n * Initializes the core autocomplete functionality after the API is loaded.\n * Imports necessary libraries and sets up the input event listener.\n */\n async _initializeAutocomplete() {\n try {\n // Ensure the 'places' library is available via the dynamic loader\n // eslint-disable-next-line no-undef\n await google.maps.importLibrary(\"places\");\n // console.log('Places library imported successfully.'); // For debugging\n\n // Initial token generation\n this._refreshToken();\n\n // Attach the debounced request function to the input element's 'input' event\n if (this.#inputElement) {\n this.#inputElement.addEventListener(\n \"input\",\n this._debouncedMakeAcRequest.bind(this)\n );\n // Add focus/blur listeners if needed to manage suggestion visibility\n this.#inputElement.addEventListener(\"blur\", () => {\n // Delay hiding suggestions to allow click events on them\n setTimeout(() => {\n if (this.#ul && !this.#ul.contains(document.activeElement)) {\n // Check if focus moved outside suggestions\n this.#ul.style.display = \"none\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n }\n }, 200); // Adjust delay as needed\n });\n this.#inputElement.addEventListener(\"focus\", () => {\n // Potentially show suggestions again if input has value\n if (this.#inputElement.value && this.#allSuggestions.length > 0) {\n this.#ul.style.display = \"block\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"true\");\n }\n });\n } else {\n this.#onErrorCallback(\n new Error(\"Input element not found during initialization.\")\n );\n }\n } catch (error) {\n console.error(\"Error initializing Google Places Autocomplete:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(\n new Error(\"Google Maps Places library not available.\")\n );\n }\n }\n\n /**\n * Resets the autocomplete input field, clears suggestions, and optionally refreshes the session token.\n * @param {boolean} [refresh=false] - Whether to refresh the Google Places session token.\n */\n _reset(refresh = false) {\n this.#currentSuggestion = -1;\n if (this.#inputElement) {\n this.#inputElement.value = \"\";\n }\n this.#allSuggestions = [];\n this.#currentSuggestion = -1;\n if (this.#ul) {\n this.#ul.innerHTML = \"\"; // Clear existing suggestions\n this.#ul.style.display = \"none\";\n }\n if (refresh) {\n this._refreshToken();\n }\n }\n /**\n * Removes the 'current' highlighting classes from all suggestion list items (li) and their links (a).\n */\n _resetLiClasses() {\n if (!this.#ul) return;\n Array.from(this.#ul.children).forEach((li) => {\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => li.classList.remove(cl));\n const link = li.querySelector(\"a\");\n if (link) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => link.classList.remove(cl));\n }\n });\n }\n\n /**\n * Handles keyboard events (ArrowDown, ArrowUp, Enter, Escape) for navigating\n * and selecting suggestions or closing the list.\n * @param {KeyboardEvent} e - The keyboard event object.\n */\n _onKeyDown(e) {\n if (\n !this.#allSuggestions.length ||\n !this.#ul ||\n this.#ul.style.display === \"none\"\n )\n return;\n\n this._resetLiClasses(); // Reset classes on any key press within the suggestions\n\n if (e.key === \"ArrowDown\") {\n e.preventDefault(); // Prevent cursor movement in input\n this.#currentSuggestion = Math.min(\n this.#currentSuggestion + 1,\n this.#allSuggestions.length - 1\n );\n if (this.#currentSuggestion < 0) this.#currentSuggestion = 0; // Handle case where it was -1\n\n const currentLi = this.#ul.children.item(this.#currentSuggestion);\n if (currentLi) {\n const currentA = currentLi.querySelector(\"a\");\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => currentLi.classList.add(cl));\n if (currentA) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => currentA.classList.add(cl));\n }\n currentLi.scrollIntoView({ block: \"nearest\" }); // Ensure visible\n }\n\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdDown?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdDown?.classList.remove(cl)),\n 300\n );\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault(); // Prevent cursor movement in input\n this.#currentSuggestion = Math.max(this.#currentSuggestion - 1, 0); // Stay at 0 if already there\n\n const currentLi = this.#ul.children.item(this.#currentSuggestion);\n if (currentLi) {\n const currentA = currentLi.querySelector(\"a\");\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => currentLi.classList.add(cl));\n if (currentA) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => currentA.classList.add(cl));\n }\n currentLi.scrollIntoView({ block: \"nearest\" }); // Ensure visible\n }\n\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdUp?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdUp?.classList.remove(cl)),\n 300\n );\n } else if (e.key === \"Enter\") {\n e.preventDefault(); // Prevent form submission if applicable\n if (\n this.#currentSuggestion >= 0 &&\n this.#currentSuggestion < this.#allSuggestions.length\n ) {\n this._onPlaceSelected(\n this.#allSuggestions[this.#currentSuggestion].place\n );\n // Reset is handled within onPlaceSelected via reset(true)\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdEscape?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdEscape?.classList.remove(cl)),\n 300\n );\n this._reset(true); // Reset search input and results, refresh token\n }\n }\n\n /**\n * Debounced function to fetch autocomplete suggestions from the Google Places API.\n * Triggered by the 'input' event on the input element.\n */\n _debouncedMakeAcRequest = this._debounce(async () => {\n if (!this.#inputElement || !this.#inputElement.value) {\n this._reset();\n if (this.#inputElement)\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n return;\n }\n\n this.#request.input = this.#inputElement.value;\n //console.log(\"Request:\", this.#request); // Debugging\n try {\n const { suggestions } =\n // eslint-disable-next-line no-undef\n await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(\n this.#request\n );\n\n // Display suggestions\n if (suggestions && suggestions.length > 0) {\n this.#ul.replaceChildren(\n ...this._createSuggestionElements(suggestions)\n );\n this.#ul.style.display = \"block\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"true\");\n } else {\n // No suggestions found\n this._reset(); // Clear any old suggestions\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n // Optionally display a \"no results\" message in the 'ul'\n }\n } catch (error) {\n this.#onErrorCallback(error);\n this._reset();\n if (this.#inputElement)\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n }\n }, this.#options?.debounce ?? 100);\n\n /**\n * Creates an array of list item (LI) elements for the suggestions dropdown.\n * Each LI contains a link (A) with the place prediction details and distance.\n * Handles highlighting the matched parts of the suggestion text.\n * @param {Array<google.maps.places.AutocompleteSuggestion>} suggestions - Array of suggestion objects from the API.\n * @returns {Array<HTMLLIElement>} An array of LI elements to be added to the suggestions UL.\n */\n _createSuggestionElements(suggestions) {\n this.#allSuggestions = []; // Reset before populating\n return suggestions.map((suggestion, index) => {\n this.#allSuggestions.push({\n id: index + 1,\n description: suggestion.placePrediction.toString(),\n place: suggestion.placePrediction.toPlace(),\n });\n\n // create div elements\n const divContainer = document.createElement(\"div\");\n divContainer.className = this.#options.classes.li_div_container; // flex min-w-0 gap-x-4\n // create inner div element - place name\n const divInner = document.createElement(\"div\");\n divInner.className = this.#options.classes.li_div_one; // min-w-0 flex-auto\n divContainer.appendChild(divInner);\n // create p element - place name\n const p = document.createElement(\"p\");\n p.className = this.#options.classes.li_div_one_p; // text-sm/6\n\n // get prediction text\n const predictionText = suggestion.placePrediction.text;\n const originalText = predictionText.text;\n // Array of objects with startOffset, endOffset\n const matches = predictionText.matches;\n\n //Highlighting Logic\n let lastIndex = 0;\n\n // Sort matches just in case they aren't ordered (though they usually are)\n matches.sort((a, b) => a.startOffset - b.startOffset);\n\n // 1. Create the outer span\n const outerSpan = document.createElement(\"span\");\n\n // 2. Create the inner span for the bold part\n const innerSpan = document.createElement(\"span\");\n innerSpan.classList = this.#options.classes.highlight ?? \"font-bold\"; // Use the highlight class from options\n\n for (const match of matches) {\n // Append text before the current match\n outerSpan.textContent += originalText.substring(\n lastIndex,\n match.startOffset\n );\n\n // Append the highlighted match segment\n if (match.startOffset > 0) {\n // check previous charter is space\n const prevChar = originalText.charAt(match.startOffset - 1);\n if (prevChar == \" \") {\n innerSpan.textContent += \" \";\n }\n }\n innerSpan.textContent += originalText.substring(\n match.startOffset,\n match.endOffset\n );\n\n // Update the last index processed\n lastIndex = match.endOffset;\n }\n\n // 3. Create a text node for the remaining text\n const remainingText = document.createTextNode(\n originalText.substring(lastIndex)\n );\n\n // 4. Append the inner span and the text node to the outer span\n outerSpan.appendChild(innerSpan);\n outerSpan.appendChild(remainingText);\n\n // 5. Append the outer span to the paragraph element\n p.appendChild(outerSpan);\n\n divInner.appendChild(p);\n divContainer.appendChild(divInner);\n\n // create inner div element - distance\n const divInner2 = document.createElement(\"div\");\n divInner2.className = this.#options.classes.li_div_two; //'shrink-0 flex flex-col items-end min-w-16';\n divContainer.appendChild(divInner2);\n // create p element - distance\n const p2 = document.createElement(\"p\");\n p2.className = this.#options.classes.li_div_two_p; //'mt-1 text-xs/5 ';\n p2.textContent = this._formatDistance(\n suggestion.placePrediction.distanceMeters,\n this.#options.distance_units ?? \"km\"\n );\n divInner2.appendChild(p2);\n\n // // create a link element\n const a = document.createElement(\"a\");\n a.href = \"javascript:void(0)\";\n a.tabIndex = index + 1;\n a.className = this.#options.classes.li_a; // block w-full flex justify-between\n\n a.addEventListener(\"click\", () => {\n this._onPlaceSelected(suggestion.placePrediction.toPlace());\n });\n\n // ...\n // a.addEventListener(\"click\", () => {\n // this._fetchPlaceDetails(prediction.place_id);\n // });\n a.appendChild(divContainer);\n a.appendChild(divInner2);\n\n const li = document.createElement(\"li\");\n li.id = `option-${index + 1}`;\n li.className = this.#options.classes.li;\n\n li.appendChild(a);\n return li;\n });\n }\n\n /**\n * Handles the selection of a place. Fetches required fields\n * (displayName, formattedAddress, addressComponents) and calls the\n * user-defined `onPacData` callback.\n * @param {google.maps.places.Place} place - The selected Place object.\n */\n async _onPlaceSelected(place) {\n try {\n // Fetch necessary details for the selected place\n await place.fetchFields({\n fields: [\"displayName\", \"formattedAddress\", \"addressComponents\"], // Add more fields as needed\n });\n // Call the user-provided callback with the place data\n // eslint-disable-next-line no-undef\n this.#onDataCallback(place.toJSON()); // Convert to plain JSON object for the callback\n } catch (error) {\n console.error(\"Error fetching place details:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(error);\n } finally {\n // Reset the input and suggestions regardless of success/error\n this._reset(true); // Refresh token after selection\n }\n }\n\n /**\n * Creates a new Google Places Autocomplete Session Token.\n * This should be called before starting a new series of autocomplete requests.\n */\n _refreshToken() {\n try {\n // eslint-disable-next-line no-undef\n this.#request.sessionToken =\n new google.maps.places.AutocompleteSessionToken();\n } catch (error) {\n console.error(\"Error creating session token:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(error);\n }\n }\n\n clear() {\n this._reset(true);\n }\n\n destroy() {\n // Remove event listeners, remove elements from DOM\n if (this.#inputElement) {\n this.#inputElement.removeEventListener(\n \"input\",\n this._debouncedMakeAcRequest\n );\n // remove other listeners\n }\n if (this.#pacEl && this.#container) {\n this.#pacEl.removeChild(this.#container.parentElement); // remove the whole section\n }\n // Nullify properties\n for (const prop in this) {\n if (Object.hasOwn(this, prop)) {\n this[prop] = null;\n }\n }\n console.log(\"PacAutocomplete instance destroyed.\");\n }\n}\n"],"names":["_a","_containerId","_pacEl","_googleMapsApiKey","_googleMapsApiVersion","_options","_request","_inputElement","_container","_ul","_kbdEscape","_kbdUp","_kbdDown","_allSuggestions","_currentSuggestion","_onDataCallback","_onErrorCallback","_defaultClasses","_defaultRequestParams","PlacesAutocomplete","config","__privateAdd","__publicField","__privateGet","suggestions","error","__privateSet","place","func","wait","timeout","args","later","distance","units","value","unitLabel","g","h","a","k","p","c","l","q","m","b","d","r","e","u","f","n","t","section","cl","iconContainer","icon","label","kbdContainer","refresh","li","link","currentLi","currentA","suggestion","index","divContainer","divInner","predictionText","originalText","matches","lastIndex","outerSpan","innerSpan","match","remainingText","divInner2","p2","prop"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC;AAgBO,MAAMC,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkE9B,YAAYC,GAAQ;AAhEpB;AAAA,IAAAC,EAAA,MAAApB;AACA;AAAA,IAAAoB,EAAA,MAAAnB;AACA,IAAAmB,EAAA,MAAAlB;AACA,IAAAkB,EAAA,MAAAjB;AACA,IAAAiB,EAAA,MAAAhB;AACA,IAAAgB,EAAA,MAAAf;AACA,IAAAe,EAAA,MAAAd;AACA,IAAAc,EAAA,MAAAb;AACA,IAAAa,EAAA,MAAAZ;AACA,IAAAY,EAAA,MAAAX;AACA,IAAAW,EAAA,MAAAV;AACA,IAAAU,EAAA,MAAAT;AACA,IAAAS,EAAA,MAAAR,GAAkB,CAAE;AACpB,IAAAQ,EAAA,MAAAP,GAAqB;AACrB,IAAAO,EAAA,MAAAN;AACA;AAAA,IAAAM,EAAA,MAAAL;AACA;AAAA,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eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eACAC,IAAA,eA6BAC,IAAA;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(r,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(r=typeof globalThis<"u"?globalThis:r||self,l(r.PlacesAutocomplete={}))})(this,function(r){"use strict";var
|
|
1
|
+
(function(r,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(r=typeof globalThis<"u"?globalThis:r||self,l(r.PlacesAutocomplete={}))})(this,function(r){"use strict";var V=Object.defineProperty;var F=r=>{throw TypeError(r)};var J=(r,l,p)=>l in r?V(r,l,{enumerable:!0,configurable:!0,writable:!0,value:p}):r[l]=p;var B=(r,l,p)=>J(r,typeof l!="symbol"?l+"":l,p),H=(r,l,p)=>l.has(r)||F("Cannot "+p);var e=(r,l,p)=>(H(r,l,"read from private field"),p?p.call(r):l.get(r)),d=(r,l,p)=>l.has(r)?F("Cannot add the same private member more than once"):l instanceof WeakSet?l.add(r):l.set(r,p),h=(r,l,p,g)=>(H(r,l,"write to private field"),g?g.call(r,p):l.set(r,p),p);/**
|
|
2
2
|
* Initializes a Places Autocomplete widget.
|
|
3
3
|
* This script dynamically loads the Google Maps JavaScript API, creates the UI elements
|
|
4
4
|
* for the autocomplete input and suggestions list, handles user input with debouncing,
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
* @author Alexander Pechkarev <alexpechkarev@gmail.com>
|
|
9
9
|
* @license MIT
|
|
10
10
|
*
|
|
11
|
-
*/var d,f,O,j,i,L,o,b,c,E,w,k,_,u,R,y,z,G;class l{constructor(t){p(this,f);p(this,O);p(this,j);p(this,i);p(this,L);p(this,o);p(this,b);p(this,c);p(this,E);p(this,w);p(this,k);p(this,_,[]);p(this,u,-1);p(this,R);p(this,y);p(this,z,{section:"",container:"relative z-10 transform rounded-xl mt-4",icon_container:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3",icon:'<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /></svg>',input:"border-1 w-full rounded-md border-0 shadow-sm bg-gray-100 px-4 py-2.5 pl-10 pr-20 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 sm:text-sm",kbd_container:"absolute inset-y-0 right-0 flex py-1.5 pr-1.5",kbd_escape:"inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1",kbd_up:"inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6",kbd_down:"inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6",kbd_active:"bg-indigo-500 text-white",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",li:"z-50 cursor-default select-none py-2 px-2 lg:px-4 text-gray-900 hover:bg-indigo-500 hover:text-white",li_current:"bg-indigo-500",li_a:"block w-full flex justify-between",li_a_current:"text-white",li_div_container:"flex min-w-0 gap-x-4",li_div_one:"min-w-0 flex-auto",li_div_one_p:"text-sm/6",li_div_two:"shrink-0 flex flex-col items-end min-w-16",li_div_two_p:"mt-1 text-xs/5",highlight:"font-bold"});p(this,G,{input:"",includedRegionCodes:["GB"],language:"en-gb",region:"GB"});F(this,"_debouncedMakeAcRequest",this._debounce(async()=>{if(!e(this,o)||!e(this,o).value){this._reset(),e(this,o)&&e(this,o).setAttribute("aria-expanded","false");return}e(this,L).input=e(this,o).value;try{const{suggestions:t}=await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(e(this,L));t&&t.length>0?(e(this,c).replaceChildren(...this._createSuggestionElements(t)),e(this,c).style.display="block",e(this,o).setAttribute("aria-expanded","true")):(this._reset(),e(this,o).setAttribute("aria-expanded","false"))}catch(t){e(this,y).call(this,t),this._reset(),e(this,o)&&e(this,o).setAttribute("aria-expanded","false")}},((d=e(this,i))==null?void 0:d.debounce)??100));if(!t||!t.containerId||!t.googleMapsApiKey)throw new Error("PacAutocomplete: Missing required configuration (containerId, googleMapsApiKey).");if(h(this,f,document.getElementById(t.containerId)),!e(this,f))throw new Error(`PacAutocomplete: Container element with ID "${t.containerId}" not found.`);h(this,O,t.googleMapsApiKey),h(this,j,t.googleMapsApiVersion||"weekly"),h(this,i,{autofocus:!1,autocomplete:"off",placeholder:"Start typing your address ...",distance:!0,distance_units:"km",label:"",debounce:100,...t.options}),t.options&&t.options.classes?e(this,i).classes={...e(this,z),...t.options.classes}:e(this,i).classes=e(this,z),h(this,R,t.onResponse||(n=>{console.info("---------Default onResponse not provided---------"),console.info("Selected Place:",JSON.stringify(n,null,2))})),h(this,y,t.onError||(n=>{console.error("---------Default onError not provided---------"),console.error("PAC Error:",n)})),t.requestParams&&Object.keys(t.requestParams).length>0?h(this,L,{...e(this,G),...t.requestParams}):h(this,L,{...e(this,G)}),this._init()}async _init(){try{(typeof google>"u"||!google.maps)&&await this._loadGoogleMapsApi({key:e(this,O),v:e(this,j)}),this._createPACStructure(),await this._initializeAutocomplete()}catch(t){e(this,y).call(this,t)}}_debounce(t,n){let s=null;return function(...m){const v=()=>{s=null,t(...m)};s!==null&&clearTimeout(s),s=setTimeout(v,n??100)}}_formatDistance(t,n){if(typeof t!="number"||!e(this,i).distance)return null;let s,a;return n==="km"?(s=(t/1e3).toFixed(2),a="km"):(s=(t/1609.34).toFixed(2),a="miles"),s=s.replace(/\.00$/,""),`${s} ${a}`}async _loadGoogleMapsApi(t){var n,s,a,m="The Google Maps JavaScript API",v="google",N="importLibrary",S="__ib__",I=document,C=window;C=C[v]||(C[v]={});var A=C.maps||(C.maps={}),T=new Set,q=new URLSearchParams,D=()=>n||(n=new Promise(async(P,g)=>{var M;s=I.createElement("script"),q.set("libraries",[...T].join(","));for(a in t)q.set(a.replace(/[A-Z]/g,x=>"_"+x[0].toLowerCase()),t[a]);q.set("callback",v+".maps."+S),s.src=`https://maps.${v}apis.com/maps/api/js?`+q,A[S]=P,s.onerror=()=>n=g(Error(m+" could not load.")),s.nonce=((M=I.querySelector("script[nonce]"))==null?void 0:M.nonce)||"",I.head.append(s)}));A[N]?console.warn(m+" only loads once. Ignoring:",t):A[N]=(P,...g)=>T.add(P)&&D().then(()=>A[N](P,...g))}_createPACStructure(){const t=document.createElement("section");e(this,i).classes.section.split(" ").forEach(m=>m&&t.classList.add(m)),h(this,b,document.createElement("div")),e(this,b).className=e(this,i).classes.container,e(this,b).setAttribute("id",e(this,f)),t.appendChild(e(this,b));const n=document.createElement("div");n.className=e(this,i).classes.icon_container,e(this,b).appendChild(n);const s=document.createElement("div");if(s.innerHTML=e(this,i).classes.icon,n.appendChild(s.firstElementChild),h(this,o,document.createElement("input")),e(this,o).id="input"+e(this,f),e(this,o).type="text",e(this,o).name="search",e(this,o).placeholder=e(this,i).placeholder,e(this,o).autocomplete=e(this,i).autocomplete,e(this,o).className=e(this,i).classes.input,e(this,o).setAttribute("role","combobox"),e(this,o).setAttribute("aria-autocomplete","list"),e(this,o).setAttribute("aria-expanded","false"),e(this,o).setAttribute("aria-controls","pacSuggestions"),e(this,i).autofocus&&(e(this,o).autofocus=!0),e(this,i).label){const m=document.createElement("label");m.htmlFor="labelInput"+e(this,f),m.textContent=e(this,i).label,e(this,b).appendChild(m)}e(this,b).appendChild(e(this,o));const a=document.createElement("div");a.className=e(this,i).classes.kbd_container,h(this,E,document.createElement("kbd")),e(this,E).className=e(this,i).classes.kbd_escape,e(this,E).textContent="Esc",a.appendChild(e(this,E)),h(this,w,document.createElement("kbd")),e(this,w).className=e(this,i).classes.kbd_up,e(this,w).innerHTML="↑",a.appendChild(e(this,w)),h(this,k,document.createElement("kbd")),e(this,k).className=e(this,i).classes.kbd_down,e(this,k).innerHTML="↓",a.appendChild(e(this,k)),e(this,b).appendChild(a),h(this,c,document.createElement("ul")),e(this,c).id="pacSuggestions",e(this,c).className=e(this,i).classes.ul,e(this,c).style.display="none",e(this,c).setAttribute("role","listbox"),e(this,b).appendChild(e(this,c)),e(this,f).appendChild(t),t.addEventListener("keydown",this._onKeyDown.bind(this))}async _initializeAutocomplete(){try{await google.maps.importLibrary("places"),this._refreshToken(),e(this,o)?(e(this,o).addEventListener("input",this._debouncedMakeAcRequest.bind(this)),e(this,o).addEventListener("blur",()=>{setTimeout(()=>{e(this,c)&&!e(this,c).contains(document.activeElement)&&(e(this,c).style.display="none",e(this,o).setAttribute("aria-expanded","false"))},200)}),e(this,o).addEventListener("focus",()=>{e(this,o).value&&e(this,_).length>0&&(e(this,c).style.display="block",e(this,o).setAttribute("aria-expanded","true"))})):e(this,y).call(this,new Error("Input element not found during initialization."))}catch(t){console.error("Error initializing Google Places Autocomplete:",t),e(this,y).call(this,new Error("Google Maps Places library not available."))}}_reset(t=!1){h(this,u,-1),e(this,o)&&(e(this,o).value=""),h(this,_,[]),h(this,u,-1),e(this,c)&&(e(this,c).innerHTML="",e(this,c).style.display="none"),t&&this._refreshToken()}_resetLiClasses(){e(this,c)&&Array.from(e(this,c).children).forEach(t=>{e(this,i).classes.li_current.split(" ").forEach(s=>t.classList.remove(s));const n=t.querySelector("a");n&&e(this,i).classes.li_a_current.split(" ").forEach(s=>n.classList.remove(s))})}_onKeyDown(t){if(!(!e(this,_).length||!e(this,c)||e(this,c).style.display==="none"))if(this._resetLiClasses(),t.key==="ArrowDown"){t.preventDefault(),h(this,u,Math.min(e(this,u)+1,e(this,_).length-1)),e(this,u)<0&&h(this,u,0);const n=e(this,c).children.item(e(this,u));if(n){const s=n.querySelector("a");e(this,i).classes.li_current.split(" ").forEach(a=>n.classList.add(a)),s&&e(this,i).classes.li_a_current.split(" ").forEach(a=>s.classList.add(a)),n.scrollIntoView({block:"nearest"})}e(this,i).classes.kbd_active.split(" ").forEach(s=>{var a;return(a=e(this,k))==null?void 0:a.classList.add(s)}),setTimeout(()=>e(this,i).classes.kbd_active.split(" ").forEach(s=>{var a;return(a=e(this,k))==null?void 0:a.classList.remove(s)}),300)}else if(t.key==="ArrowUp"){t.preventDefault(),h(this,u,Math.max(e(this,u)-1,0));const n=e(this,c).children.item(e(this,u));if(n){const s=n.querySelector("a");e(this,i).classes.li_current.split(" ").forEach(a=>n.classList.add(a)),s&&e(this,i).classes.li_a_current.split(" ").forEach(a=>s.classList.add(a)),n.scrollIntoView({block:"nearest"})}e(this,i).classes.kbd_active.split(" ").forEach(s=>{var a;return(a=e(this,w))==null?void 0:a.classList.add(s)}),setTimeout(()=>e(this,i).classes.kbd_active.split(" ").forEach(s=>{var a;return(a=e(this,w))==null?void 0:a.classList.remove(s)}),300)}else t.key==="Enter"?(t.preventDefault(),e(this,u)>=0&&e(this,u)<e(this,_).length&&this._onPlaceSelected(e(this,_)[e(this,u)].place)):t.key==="Escape"&&(t.preventDefault(),e(this,i).classes.kbd_active.split(" ").forEach(n=>{var s;return(s=e(this,E))==null?void 0:s.classList.add(n)}),setTimeout(()=>e(this,i).classes.kbd_active.split(" ").forEach(n=>{var s;return(s=e(this,E))==null?void 0:s.classList.remove(n)}),300),this._reset(!0))}_createSuggestionElements(t){return h(this,_,[]),t.map((n,s)=>{e(this,_).push({id:s+1,description:n.placePrediction.toString(),place:n.placePrediction.toPlace()});const a=document.createElement("div");a.className=e(this,i).classes.li_div_container;const m=document.createElement("div");m.className=e(this,i).classes.li_div_one,a.appendChild(m);const v=document.createElement("p");v.className=e(this,i).classes.li_div_one_p;const N=n.placePrediction.text,S=N.text,I=N.matches;let C=0;I.sort((x,K)=>x.startOffset-K.startOffset);const A=document.createElement("span"),T=document.createElement("span");T.classList=e(this,i).classes.highlight??"font-bold";for(const x of I)A.textContent+=S.substring(C,x.startOffset),x.startOffset>0&&S.charAt(x.startOffset-1)==" "&&(T.textContent+=" "),T.textContent+=S.substring(x.startOffset,x.endOffset),C=x.endOffset;const q=document.createTextNode(S.substring(C));A.appendChild(T),A.appendChild(q),v.appendChild(A),m.appendChild(v),a.appendChild(m);const D=document.createElement("div");D.className=e(this,i).classes.li_div_two,a.appendChild(D);const P=document.createElement("p");P.className=e(this,i).classes.li_div_two_p,P.textContent=this._formatDistance(n.placePrediction.distanceMeters,e(this,i).distance_units??"km"),D.appendChild(P);const g=document.createElement("a");g.href="javascript:void(0)",g.tabIndex=s+1,g.className=e(this,i).classes.li_a,g.addEventListener("click",()=>{this._onPlaceSelected(n.placePrediction.toPlace())}),g.appendChild(a),g.appendChild(D);const M=document.createElement("li");return M.id=`option-${s+1}`,M.className=e(this,i).classes.li,M.appendChild(g),M})}async _onPlaceSelected(t){try{await t.fetchFields({fields:["displayName","formattedAddress","addressComponents"]}),e(this,R).call(this,t.toJSON())}catch(n){console.error("Error fetching place details:",n),e(this,y).call(this,n)}finally{this._reset(!0)}}_refreshToken(){try{e(this,L).sessionToken=new google.maps.places.AutocompleteSessionToken}catch(t){console.error("Error creating session token:",t),e(this,y).call(this,t)}}clear(){this._reset(!0)}destroy(){e(this,o)&&e(this,o).removeEventListener("input",this._debouncedMakeAcRequest),e(this,f)&&e(this,b)&&e(this,f).removeChild(e(this,b).parentElement);for(const t in this)Object.hasOwn(this,t)&&(this[t]=null);console.log("PacAutocomplete instance destroyed.")}}f=new WeakMap,O=new WeakMap,j=new WeakMap,i=new WeakMap,L=new WeakMap,o=new WeakMap,b=new WeakMap,c=new WeakMap,E=new WeakMap,w=new WeakMap,k=new WeakMap,_=new WeakMap,u=new WeakMap,R=new WeakMap,y=new WeakMap,z=new WeakMap,G=new WeakMap,r.PlacesAutocomplete=l,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
|
11
|
+
*/var p,g,L,j,R,i,P,o,f,c,E,w,k,b,u,z,y,G,K;class l{constructor(t){d(this,g);d(this,L);d(this,j);d(this,R);d(this,i);d(this,P);d(this,o);d(this,f);d(this,c);d(this,E);d(this,w);d(this,k);d(this,b,[]);d(this,u,-1);d(this,z);d(this,y);d(this,G,{section:"",container:"relative z-10 transform rounded-xl mt-4",icon_container:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3",icon:'<svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8" /><path d="m21 21-4.3-4.3" /></svg>',input:"border-1 w-full rounded-md border-0 shadow-sm bg-gray-100 px-4 py-2.5 pl-10 pr-20 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 sm:text-sm",kbd_container:"absolute inset-y-0 right-0 flex py-1.5 pr-1.5",kbd_escape:"inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1",kbd_up:"inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6",kbd_down:"inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6",kbd_active:"bg-indigo-500 text-white",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",li:"z-50 cursor-default select-none py-2 px-2 lg:px-4 text-gray-900 hover:bg-indigo-500 hover:text-white",li_current:"bg-indigo-500",li_a:"block w-full flex justify-between",li_a_current:"text-white",li_div_container:"flex min-w-0 gap-x-4",li_div_one:"min-w-0 flex-auto",li_div_one_p:"text-sm/6",li_div_two:"shrink-0 flex flex-col items-end min-w-16",li_div_two_p:"mt-1 text-xs/5",highlight:"font-bold"});d(this,K,{input:"",includedRegionCodes:["GB"],language:"en-gb",region:"GB"});B(this,"_debouncedMakeAcRequest",this._debounce(async()=>{if(!e(this,o)||!e(this,o).value){this._reset(),e(this,o)&&e(this,o).setAttribute("aria-expanded","false");return}e(this,P).input=e(this,o).value;try{const{suggestions:t}=await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(e(this,P));t&&t.length>0?(e(this,c).replaceChildren(...this._createSuggestionElements(t)),e(this,c).style.display="block",e(this,o).setAttribute("aria-expanded","true")):(this._reset(),e(this,o).setAttribute("aria-expanded","false"))}catch(t){e(this,y).call(this,t),this._reset(),e(this,o)&&e(this,o).setAttribute("aria-expanded","false")}},((p=e(this,i))==null?void 0:p.debounce)??100));if(!t||!t.containerId||!t.googleMapsApiKey)throw new Error("PacAutocomplete: Missing required configuration (containerId, googleMapsApiKey).");if(h(this,g,t.containerId),h(this,L,document.getElementById(t.containerId)),!e(this,L))throw new Error(`PacAutocomplete: Container element with ID "${t.containerId}" not found.`);h(this,j,t.googleMapsApiKey),h(this,R,t.googleMapsApiVersion||"weekly"),h(this,i,{autofocus:!1,autocomplete:"off",placeholder:"Start typing your address ...",distance:!0,distance_units:"km",label:"",debounce:100,...t.options}),t.options&&t.options.classes?e(this,i).classes={...e(this,G),...t.options.classes}:e(this,i).classes=e(this,G),h(this,z,t.onResponse||(n=>{console.info("---------Default onResponse not provided---------"),console.info("Selected Place:",JSON.stringify(n,null,2))})),h(this,y,t.onError||(n=>{console.error("---------Default onError not provided---------"),console.error("PAC Error:",n)})),t.requestParams&&Object.keys(t.requestParams).length>0?h(this,P,{...e(this,K),...t.requestParams}):h(this,P,{...e(this,K)}),this._init()}async _init(){try{(typeof google>"u"||!google.maps)&&await this._loadGoogleMapsApi({key:e(this,j),v:e(this,R)}),this._createPACStructure(),await this._initializeAutocomplete()}catch(t){e(this,y).call(this,t)}}_debounce(t,n){let s=null;return function(...m){const v=()=>{s=null,t(...m)};s!==null&&clearTimeout(s),s=setTimeout(v,n??100)}}_formatDistance(t,n){if(typeof t!="number"||!e(this,i).distance)return null;let s,a;return n==="km"?(s=(t/1e3).toFixed(2),a="km"):(s=(t/1609.34).toFixed(2),a="miles"),s=s.replace(/\.00$/,""),`${s} ${a}`}async _loadGoogleMapsApi(t){var n,s,a,m="The Google Maps JavaScript API",v="google",I="importLibrary",T="__ib__",q=document,C=window;C=C[v]||(C[v]={});var A=C.maps||(C.maps={}),M=new Set,D=new URLSearchParams,O=()=>n||(n=new Promise(async(S,_)=>{var N;s=q.createElement("script"),D.set("libraries",[...M].join(","));for(a in t)D.set(a.replace(/[A-Z]/g,x=>"_"+x[0].toLowerCase()),t[a]);D.set("callback",v+".maps."+T),s.src=`https://maps.${v}apis.com/maps/api/js?`+D,A[T]=S,s.onerror=()=>n=_(Error(m+" could not load.")),s.nonce=((N=q.querySelector("script[nonce]"))==null?void 0:N.nonce)||"",q.head.append(s)}));A[I]?console.warn(m+" only loads once. Ignoring:",t):A[I]=(S,..._)=>M.add(S)&&O().then(()=>A[I](S,..._))}_createPACStructure(){const t=document.createElement("section");e(this,i).classes.section.split(" ").forEach(m=>m&&t.classList.add(m)),h(this,f,document.createElement("div")),e(this,f).className=e(this,i).classes.container,e(this,f).setAttribute("id",e(this,g)+"-div"),t.appendChild(e(this,f));const n=document.createElement("div");n.className=e(this,i).classes.icon_container,e(this,f).appendChild(n);const s=document.createElement("div");if(s.innerHTML=e(this,i).classes.icon,n.appendChild(s.firstElementChild),h(this,o,document.createElement("input")),e(this,o).id=e(this,g)+"-input",e(this,o).type="text",e(this,o).name="search",e(this,o).placeholder=e(this,i).placeholder,e(this,o).autocomplete=e(this,i).autocomplete,e(this,o).className=e(this,i).classes.input,e(this,o).setAttribute("role","combobox"),e(this,o).setAttribute("aria-autocomplete","list"),e(this,o).setAttribute("aria-expanded","false"),e(this,o).setAttribute("aria-controls","pacSuggestions"),e(this,i).autofocus&&(e(this,o).autofocus=!0),e(this,i).label){const m=document.createElement("label");m.htmlFor=e(this,g)+"-labelInput",m.textContent=e(this,i).label,e(this,f).appendChild(m)}e(this,f).appendChild(e(this,o));const a=document.createElement("div");a.className=e(this,i).classes.kbd_container,h(this,E,document.createElement("kbd")),e(this,E).className=e(this,i).classes.kbd_escape,e(this,E).textContent="Esc",a.appendChild(e(this,E)),h(this,w,document.createElement("kbd")),e(this,w).className=e(this,i).classes.kbd_up,e(this,w).innerHTML="↑",a.appendChild(e(this,w)),h(this,k,document.createElement("kbd")),e(this,k).className=e(this,i).classes.kbd_down,e(this,k).innerHTML="↓",a.appendChild(e(this,k)),e(this,f).appendChild(a),h(this,c,document.createElement("ul")),e(this,c).id="pacSuggestions",e(this,c).className=e(this,i).classes.ul,e(this,c).style.display="none",e(this,c).setAttribute("role","listbox"),e(this,f).appendChild(e(this,c)),e(this,L).appendChild(t),t.addEventListener("keydown",this._onKeyDown.bind(this))}async _initializeAutocomplete(){try{await google.maps.importLibrary("places"),this._refreshToken(),e(this,o)?(e(this,o).addEventListener("input",this._debouncedMakeAcRequest.bind(this)),e(this,o).addEventListener("blur",()=>{setTimeout(()=>{e(this,c)&&!e(this,c).contains(document.activeElement)&&(e(this,c).style.display="none",e(this,o).setAttribute("aria-expanded","false"))},200)}),e(this,o).addEventListener("focus",()=>{e(this,o).value&&e(this,b).length>0&&(e(this,c).style.display="block",e(this,o).setAttribute("aria-expanded","true"))})):e(this,y).call(this,new Error("Input element not found during initialization."))}catch(t){console.error("Error initializing Google Places Autocomplete:",t),e(this,y).call(this,new Error("Google Maps Places library not available."))}}_reset(t=!1){h(this,u,-1),e(this,o)&&(e(this,o).value=""),h(this,b,[]),h(this,u,-1),e(this,c)&&(e(this,c).innerHTML="",e(this,c).style.display="none"),t&&this._refreshToken()}_resetLiClasses(){e(this,c)&&Array.from(e(this,c).children).forEach(t=>{e(this,i).classes.li_current.split(" ").forEach(s=>t.classList.remove(s));const n=t.querySelector("a");n&&e(this,i).classes.li_a_current.split(" ").forEach(s=>n.classList.remove(s))})}_onKeyDown(t){if(!(!e(this,b).length||!e(this,c)||e(this,c).style.display==="none"))if(this._resetLiClasses(),t.key==="ArrowDown"){t.preventDefault(),h(this,u,Math.min(e(this,u)+1,e(this,b).length-1)),e(this,u)<0&&h(this,u,0);const n=e(this,c).children.item(e(this,u));if(n){const s=n.querySelector("a");e(this,i).classes.li_current.split(" ").forEach(a=>n.classList.add(a)),s&&e(this,i).classes.li_a_current.split(" ").forEach(a=>s.classList.add(a)),n.scrollIntoView({block:"nearest"})}e(this,i).classes.kbd_active.split(" ").forEach(s=>{var a;return(a=e(this,k))==null?void 0:a.classList.add(s)}),setTimeout(()=>e(this,i).classes.kbd_active.split(" ").forEach(s=>{var a;return(a=e(this,k))==null?void 0:a.classList.remove(s)}),300)}else if(t.key==="ArrowUp"){t.preventDefault(),h(this,u,Math.max(e(this,u)-1,0));const n=e(this,c).children.item(e(this,u));if(n){const s=n.querySelector("a");e(this,i).classes.li_current.split(" ").forEach(a=>n.classList.add(a)),s&&e(this,i).classes.li_a_current.split(" ").forEach(a=>s.classList.add(a)),n.scrollIntoView({block:"nearest"})}e(this,i).classes.kbd_active.split(" ").forEach(s=>{var a;return(a=e(this,w))==null?void 0:a.classList.add(s)}),setTimeout(()=>e(this,i).classes.kbd_active.split(" ").forEach(s=>{var a;return(a=e(this,w))==null?void 0:a.classList.remove(s)}),300)}else t.key==="Enter"?(t.preventDefault(),e(this,u)>=0&&e(this,u)<e(this,b).length&&this._onPlaceSelected(e(this,b)[e(this,u)].place)):t.key==="Escape"&&(t.preventDefault(),e(this,i).classes.kbd_active.split(" ").forEach(n=>{var s;return(s=e(this,E))==null?void 0:s.classList.add(n)}),setTimeout(()=>e(this,i).classes.kbd_active.split(" ").forEach(n=>{var s;return(s=e(this,E))==null?void 0:s.classList.remove(n)}),300),this._reset(!0))}_createSuggestionElements(t){return h(this,b,[]),t.map((n,s)=>{e(this,b).push({id:s+1,description:n.placePrediction.toString(),place:n.placePrediction.toPlace()});const a=document.createElement("div");a.className=e(this,i).classes.li_div_container;const m=document.createElement("div");m.className=e(this,i).classes.li_div_one,a.appendChild(m);const v=document.createElement("p");v.className=e(this,i).classes.li_div_one_p;const I=n.placePrediction.text,T=I.text,q=I.matches;let C=0;q.sort((x,$)=>x.startOffset-$.startOffset);const A=document.createElement("span"),M=document.createElement("span");M.classList=e(this,i).classes.highlight??"font-bold";for(const x of q)A.textContent+=T.substring(C,x.startOffset),x.startOffset>0&&T.charAt(x.startOffset-1)==" "&&(M.textContent+=" "),M.textContent+=T.substring(x.startOffset,x.endOffset),C=x.endOffset;const D=document.createTextNode(T.substring(C));A.appendChild(M),A.appendChild(D),v.appendChild(A),m.appendChild(v),a.appendChild(m);const O=document.createElement("div");O.className=e(this,i).classes.li_div_two,a.appendChild(O);const S=document.createElement("p");S.className=e(this,i).classes.li_div_two_p,S.textContent=this._formatDistance(n.placePrediction.distanceMeters,e(this,i).distance_units??"km"),O.appendChild(S);const _=document.createElement("a");_.href="javascript:void(0)",_.tabIndex=s+1,_.className=e(this,i).classes.li_a,_.addEventListener("click",()=>{this._onPlaceSelected(n.placePrediction.toPlace())}),_.appendChild(a),_.appendChild(O);const N=document.createElement("li");return N.id=`option-${s+1}`,N.className=e(this,i).classes.li,N.appendChild(_),N})}async _onPlaceSelected(t){try{await t.fetchFields({fields:["displayName","formattedAddress","addressComponents"]}),e(this,z).call(this,t.toJSON())}catch(n){console.error("Error fetching place details:",n),e(this,y).call(this,n)}finally{this._reset(!0)}}_refreshToken(){try{e(this,P).sessionToken=new google.maps.places.AutocompleteSessionToken}catch(t){console.error("Error creating session token:",t),e(this,y).call(this,t)}}clear(){this._reset(!0)}destroy(){e(this,o)&&e(this,o).removeEventListener("input",this._debouncedMakeAcRequest),e(this,L)&&e(this,f)&&e(this,L).removeChild(e(this,f).parentElement);for(const t in this)Object.hasOwn(this,t)&&(this[t]=null);console.log("PacAutocomplete instance destroyed.")}}g=new WeakMap,L=new WeakMap,j=new WeakMap,R=new WeakMap,i=new WeakMap,P=new WeakMap,o=new WeakMap,f=new WeakMap,c=new WeakMap,E=new WeakMap,w=new WeakMap,k=new WeakMap,b=new WeakMap,u=new WeakMap,z=new WeakMap,y=new WeakMap,G=new WeakMap,K=new WeakMap,r.PlacesAutocomplete=l,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
|
12
12
|
//# sourceMappingURL=places-autocomplete.umd.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"places-autocomplete.umd.cjs","sources":["../lib/PlacesAutocomplete.js"],"sourcesContent":["/**\n * Initializes a Places Autocomplete widget.\n * This script dynamically loads the Google Maps JavaScript API, creates the UI elements\n * for the autocomplete input and suggestions list, handles user input with debouncing,\n * fetches suggestions, manages keyboard navigation, and calls user-defined callbacks\n * on place selection or error.\n *\n * @author Alexander Pechkarev <alexpechkarev@gmail.com>\n * @license MIT\n *\n */\n\n/**\n * PacAutocomplete class\n * This class provides a Places Autocomplete widget.\n */\nexport class PlacesAutocomplete {\n // --- Private Properties (using # or _ prefix by convention) ---\n #pacEl;\n #googleMapsApiKey;\n #googleMapsApiVersion;\n #options;\n #request;\n #inputElement;\n #container;\n #ul;\n #kbdEscape;\n #kbdUp;\n #kbdDown;\n #allSuggestions = [];\n #currentSuggestion = -1;\n #onDataCallback; // For user-provided data callback\n #onErrorCallback; // For user-provided error callback\n #defaultClasses = {\n // CSS classes for various parts of the widget.\n section: \"\", // Outer section container.\n container: \"relative z-10 transform rounded-xl mt-4\", // Main container div.\n icon_container:\n \"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3\", // Container for the search icon.\n icon: '<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"w-5 h-5\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"11\" cy=\"11\" r=\"8\" /><path d=\"m21 21-4.3-4.3\" /></svg>', // SVG for the search icon.\n input:\n \"border-1 w-full rounded-md border-0 shadow-sm bg-gray-100 px-4 py-2.5 pl-10 pr-20 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 sm:text-sm\", // Input field.\n kbd_container: \"absolute inset-y-0 right-0 flex py-1.5 pr-1.5\", // Container for keyboard hints.\n kbd_escape:\n \"inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1\", // Escape key hint.\n kbd_up:\n \"inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6\", // Up arrow key hint.\n kbd_down:\n \"inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6\", // Down arrow key hint.\n kbd_active: \"bg-indigo-500 text-white\", // Class for active keyboard hint.\n 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\", // Suggestions list (ul).\n li: \"z-50 cursor-default select-none py-2 px-2 lg:px-4 text-gray-900 hover:bg-indigo-500 hover:text-white\", // Suggestion item (li).\n li_current: \"bg-indigo-500\", // Class for the currently selected suggestion item.\n li_a: \"block w-full flex justify-between\", // Link element within a suggestion item.\n li_a_current: \"text-white\", // Class for the link in the currently selected suggestion item.\n li_div_container: \"flex min-w-0 gap-x-4\", // Container div within the suggestion link.\n li_div_one: \"min-w-0 flex-auto\", // First inner div (for place name).\n li_div_one_p: \"text-sm/6\", // Paragraph for the place name.\n li_div_two: \"shrink-0 flex flex-col items-end min-w-16\", // Second inner div (for distance).\n li_div_two_p: \"mt-1 text-xs/5\", // Paragraph for the distance.\n highlight: \"font-bold\", // Class for highlighting matched text in suggestions.\n };\n #defaultRequestParams = {\n // Default parameters for the autocomplete request.\n input: \"\", // Initial input value (empty).\n includedRegionCodes: [\"GB\"], // Default region codes to include in suggestions.\n language: \"en-gb\",\n region: \"GB\",\n };\n\n /**\n * Class constructor for PacAutocomplete.\n * Initializes the autocomplete widget with the provided configuration.\n * @param {Object} config - Configuration object for the autocomplete widget.\n * @param {string} config.containerId - ID of the container element for the widget.\n * @param {string} config.googleMapsApiKey - Google Maps API key.\n * @param {string} [config.googleMapsApiVersion] - Version of the Google Maps API to use (default: \"weekly\").\n * @param {Object} [config.options] - Additional options for the widget (e.g., classes, callbacks).\n * @param {Object} [config.requestParams] - Parameters for the autocomplete request (e.g., input, region).\n * @param {*} config\n */\n constructor(config) {\n // console.log(\"PacAutocomplete constructor called.\", config.requestParams);\n if (!config || !config.containerId || !config.googleMapsApiKey) {\n throw new Error(\n \"PacAutocomplete: Missing required configuration (containerId, googleMapsApiKey).\"\n );\n }\n\n this.#pacEl = document.getElementById(config.containerId);\n if (!this.#pacEl) {\n throw new Error(\n `PacAutocomplete: Container element with ID \"${config.containerId}\" not found.`\n );\n }\n\n this.#googleMapsApiKey = config.googleMapsApiKey;\n this.#googleMapsApiVersion = config.googleMapsApiVersion || \"weekly\";\n\n // Merge user options with defaults\n this.#options = {\n autofocus: false, // Automatically focus the input on load.\n autocomplete: \"off\", // HTML autocomplete attribute for the input.\n placeholder: \"Start typing your address ...\", // Placeholder text for the input.\n distance: true, // Show distance in suggestions (requires origin in request).\n distance_units: \"km\", // Units for distance ('km' or 'miles').\n label: \"\", // Optional label text above the input.\n debounce: 100, // Debounce delay (ms) for API requests.\n ...config.options, // User-defined options override defaults\n };\n // Ensure classes are deeply merged if user provides partial classes\n if (config.options && config.options.classes) {\n this.#options.classes = {\n ...this.#defaultClasses,\n ...config.options.classes,\n };\n } else {\n this.#options.classes = this.#defaultClasses; // Use default classes if none provided\n }\n\n // Set default response and error callbacks if not provided\n this.#onDataCallback =\n config.onResponse ||\n ((place) => {\n console.info(\"---------Default onResponse not provided---------\");\n console.info(\"Selected Place:\", JSON.stringify(place, null, 2));\n });\n this.#onErrorCallback =\n config.onError ||\n ((error) => {\n console.error(\"---------Default onError not provided---------\");\n console.error(\"PAC Error:\", error);\n });\n\n if (config.requestParams && Object.keys(config.requestParams).length > 0) {\n this.#request = {\n ...this.#defaultRequestParams,\n ...config.requestParams,\n };\n } else {\n this.#request = { ...this.#defaultRequestParams }; // Use defaults if no requestParams provided\n }\n\n //console.log(this.#request);\n\n this._init(); // Underscore prefix for internal initialization method\n }\n\n // --- Private Initialization Method ---\n async _init() {\n try {\n // check if google maps api is already loaded\n if (typeof google === \"undefined\" || !google.maps) {\n // Load the Google Maps API dynamically\n await this._loadGoogleMapsApi({\n key: this.#googleMapsApiKey,\n v: this.#googleMapsApiVersion,\n });\n }\n this._createPACStructure(); // Pass this.#options\n await this._initializeAutocomplete(); // Pass this.#options\n //console.log(\"PacAutocomplete Initialized for container:\", this.#pacEl.id);\n } catch (error) {\n this.#onErrorCallback(error);\n }\n }\n\n /**\n * Creates a debounced version of a function.\n * The debounced function delays invoking `func` until after `wait` milliseconds have\n * elapsed since the last time the debounced function was invoked.\n * @param {Function} func - The function to debounce.\n * @param {number} wait - The number of milliseconds to delay.\n * @returns {Function} The new debounced function.\n */\n _debounce(func, wait) {\n let timeout = null;\n return function executedFunction(...args) {\n const later = () => {\n timeout = null;\n func(...args); // Call original function\n };\n if (timeout !== null) {\n clearTimeout(timeout); // Clear the previous timeout\n }\n timeout = setTimeout(later, wait ?? 100); // Set the new timeout\n };\n }\n /**\n * Formats a distance in meters into kilometers or miles.\n * @param {number | null | undefined} distance - Distance in meters.\n * @param {'km' | 'miles'} units - The desired output units.\n * @returns {string | null} Formatted distance string (e.g., \"1.23 km\") or null if input is invalid.\n */\n _formatDistance(distance, units) {\n if (typeof distance !== \"number\" || !this.#options.distance) {\n return null; // Return null if distance isn't shown or invalid\n }\n let value;\n let unitLabel;\n if (units === \"km\") {\n value = (distance / 1000).toFixed(2);\n unitLabel = \"km\";\n } else {\n // Default to miles if not 'km'\n value = (distance / 1609.34).toFixed(2);\n unitLabel = \"miles\";\n }\n // Avoid showing \".00\"\n value = value.replace(/\\.00$/, \"\");\n return `${value} ${unitLabel}`;\n }\n\n /**\n * Dynamically loads the Google Maps JavaScript API using the importLibrary method.\n * This is the standard approach recommended by Google.\n * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api\n * @param {object} g - Configuration object for the API loader (key, v, libraries, etc.).\n */\n async _loadGoogleMapsApi(g) {\n var h, // Promise tracking API load\n a, // Script element\n k, // Loop variable for config keys\n p = \"The Google Maps JavaScript API\", // Error message prefix\n c = \"google\", // Global namespace\n l = \"importLibrary\", // Loader function name\n q = \"__ib__\", // Internal callback name\n m = document, // Document reference\n b = window; // Window reference\n b = b[c] || (b[c] = {}); // Ensure google namespace exists\n var d = b.maps || (b.maps = {}), // Ensure google.maps namespace exists\n r = new Set(), // Set to track requested libraries\n e = new URLSearchParams(), // URL parameters for the API script\n u = () =>\n // Function to initiate API loading (if not already started)\n h ||\n // eslint-disable-next-line no-async-promise-executor\n (h = new Promise(async (f, n) => {\n // Create script element (done async to potentially wait for nonce)\n // await (a = m.createElement('script')); // Original Google code had await here, might not be needed\n a = m.createElement(\"script\"); // Create script tag\n e.set(\"libraries\", [...r].join(\",\")); // Add accumulated libraries\n // Add other parameters from the config object 'g'\n for (k in g)\n e.set(\n k.replace(/[A-Z]/g, (t) => \"_\" + t[0].toLowerCase()), // Convert camelCase to snake_case\n g[k]\n );\n e.set(\"callback\", c + \".maps.\" + q); // Set the internal callback function name\n a.src = `https://maps.${c}apis.com/maps/api/js?` + e; // Construct the API URL\n d[q] = f; // Assign the promise resolver to the callback name on google.maps\n // Error handling for script loading failure\n a.onerror = () => (h = n(Error(p + \" could not load.\"))); // Use onerror for load failures\n // Nonce for Content Security Policy\n a.nonce = m.querySelector(\"script[nonce]\")?.nonce || \"\";\n m.head.append(a); // Append the script to the document head\n }));\n // Define or reuse the importLibrary function on google.maps\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n d[l]\n ? console.warn(p + \" only loads once. Ignoring:\", g) // Warn if called again\n : (d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))); // The actual importLibrary implementation\n }\n\n // --- UI Creation ---\n _createPACStructure() {\n const section = document.createElement(\"section\");\n this.#options.classes.section\n .split(\" \")\n .forEach((cl) => cl && section.classList.add(cl));\n\n // Main container\n this.#container = document.createElement(\"div\");\n this.#container.className = this.#options.classes.container;\n this.#container.setAttribute(\"id\", this.#pacEl);\n section.appendChild(this.#container);\n\n // Icon\n const iconContainer = document.createElement(\"div\");\n iconContainer.className = this.#options.classes.icon_container;\n this.#container.appendChild(iconContainer);\n const icon = document.createElement(\"div\");\n icon.innerHTML = this.#options.classes.icon;\n iconContainer.appendChild(icon.firstElementChild); // Append the actual SVG element\n\n // Input field\n this.#inputElement = document.createElement(\"input\");\n this.#inputElement.id = \"input\" + this.#pacEl; // Assign ID for label association\n this.#inputElement.type = \"text\";\n this.#inputElement.name = \"search\"; // Consider making name configurable\n this.#inputElement.placeholder = this.#options.placeholder;\n this.#inputElement.autocomplete = this.#options.autocomplete;\n this.#inputElement.className = this.#options.classes.input;\n this.#inputElement.setAttribute(\"role\", \"combobox\");\n this.#inputElement.setAttribute(\"aria-autocomplete\", \"list\");\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\"); // Will be updated dynamically\n this.#inputElement.setAttribute(\"aria-controls\", \"pacSuggestions\"); // Links to the suggestions list\n\n if (this.#options.autofocus) {\n this.#inputElement.autofocus = true;\n }\n if (this.#options.label) {\n const label = document.createElement(\"label\");\n label.htmlFor = \"labelInput\" + this.#pacEl; // Assuming inputElement gets this ID\n label.textContent = this.#options.label;\n // Add label classes if needed from opts.classes\n this.#container.appendChild(label); // Append label before input or adjust structure\n }\n this.#container.appendChild(this.#inputElement);\n\n // Keyboard hints container\n const kbdContainer = document.createElement(\"div\");\n kbdContainer.className = this.#options.classes.kbd_container;\n this.#kbdEscape = document.createElement(\"kbd\");\n this.#kbdEscape.className = this.#options.classes.kbd_escape;\n this.#kbdEscape.textContent = \"Esc\";\n kbdContainer.appendChild(this.#kbdEscape);\n this.#kbdUp = document.createElement(\"kbd\");\n this.#kbdUp.className = this.#options.classes.kbd_up;\n this.#kbdUp.innerHTML = \"↑\"; // Up arrow HTML entity\n kbdContainer.appendChild(this.#kbdUp);\n this.#kbdDown = document.createElement(\"kbd\");\n this.#kbdDown.className = this.#options.classes.kbd_down;\n this.#kbdDown.innerHTML = \"↓\"; // Down arrow HTML entity\n kbdContainer.appendChild(this.#kbdDown);\n this.#container.appendChild(kbdContainer);\n\n // Suggestions list (initially hidden)\n this.#ul = document.createElement(\"ul\");\n this.#ul.id = \"pacSuggestions\"; // Must match aria-controls\n this.#ul.className = this.#options.classes.ul;\n this.#ul.style.display = \"none\";\n this.#ul.setAttribute(\"role\", \"listbox\");\n this.#container.appendChild(this.#ul);\n\n this.#pacEl.appendChild(section);\n section.addEventListener(\"keydown\", this._onKeyDown.bind(this)); // Bind 'this'\n }\n\n /**\n * Initializes the core autocomplete functionality after the API is loaded.\n * Imports necessary libraries and sets up the input event listener.\n */\n async _initializeAutocomplete() {\n try {\n // Ensure the 'places' library is available via the dynamic loader\n // eslint-disable-next-line no-undef\n await google.maps.importLibrary(\"places\");\n // console.log('Places library imported successfully.'); // For debugging\n\n // Initial token generation\n this._refreshToken();\n\n // Attach the debounced request function to the input element's 'input' event\n if (this.#inputElement) {\n this.#inputElement.addEventListener(\n \"input\",\n this._debouncedMakeAcRequest.bind(this)\n );\n // Add focus/blur listeners if needed to manage suggestion visibility\n this.#inputElement.addEventListener(\"blur\", () => {\n // Delay hiding suggestions to allow click events on them\n setTimeout(() => {\n if (this.#ul && !this.#ul.contains(document.activeElement)) {\n // Check if focus moved outside suggestions\n this.#ul.style.display = \"none\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n }\n }, 200); // Adjust delay as needed\n });\n this.#inputElement.addEventListener(\"focus\", () => {\n // Potentially show suggestions again if input has value\n if (this.#inputElement.value && this.#allSuggestions.length > 0) {\n this.#ul.style.display = \"block\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"true\");\n }\n });\n } else {\n this.#onErrorCallback(\n new Error(\"Input element not found during initialization.\")\n );\n }\n } catch (error) {\n console.error(\"Error initializing Google Places Autocomplete:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(\n new Error(\"Google Maps Places library not available.\")\n );\n }\n }\n\n /**\n * Resets the autocomplete input field, clears suggestions, and optionally refreshes the session token.\n * @param {boolean} [refresh=false] - Whether to refresh the Google Places session token.\n */\n _reset(refresh = false) {\n this.#currentSuggestion = -1;\n if (this.#inputElement) {\n this.#inputElement.value = \"\";\n }\n this.#allSuggestions = [];\n this.#currentSuggestion = -1;\n if (this.#ul) {\n this.#ul.innerHTML = \"\"; // Clear existing suggestions\n this.#ul.style.display = \"none\";\n }\n if (refresh) {\n this._refreshToken();\n }\n }\n /**\n * Removes the 'current' highlighting classes from all suggestion list items (li) and their links (a).\n */\n _resetLiClasses() {\n if (!this.#ul) return;\n Array.from(this.#ul.children).forEach((li) => {\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => li.classList.remove(cl));\n const link = li.querySelector(\"a\");\n if (link) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => link.classList.remove(cl));\n }\n });\n }\n\n /**\n * Handles keyboard events (ArrowDown, ArrowUp, Enter, Escape) for navigating\n * and selecting suggestions or closing the list.\n * @param {KeyboardEvent} e - The keyboard event object.\n */\n _onKeyDown(e) {\n if (\n !this.#allSuggestions.length ||\n !this.#ul ||\n this.#ul.style.display === \"none\"\n )\n return;\n\n this._resetLiClasses(); // Reset classes on any key press within the suggestions\n\n if (e.key === \"ArrowDown\") {\n e.preventDefault(); // Prevent cursor movement in input\n this.#currentSuggestion = Math.min(\n this.#currentSuggestion + 1,\n this.#allSuggestions.length - 1\n );\n if (this.#currentSuggestion < 0) this.#currentSuggestion = 0; // Handle case where it was -1\n\n const currentLi = this.#ul.children.item(this.#currentSuggestion);\n if (currentLi) {\n const currentA = currentLi.querySelector(\"a\");\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => currentLi.classList.add(cl));\n if (currentA) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => currentA.classList.add(cl));\n }\n currentLi.scrollIntoView({ block: \"nearest\" }); // Ensure visible\n }\n\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdDown?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdDown?.classList.remove(cl)),\n 300\n );\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault(); // Prevent cursor movement in input\n this.#currentSuggestion = Math.max(this.#currentSuggestion - 1, 0); // Stay at 0 if already there\n\n const currentLi = this.#ul.children.item(this.#currentSuggestion);\n if (currentLi) {\n const currentA = currentLi.querySelector(\"a\");\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => currentLi.classList.add(cl));\n if (currentA) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => currentA.classList.add(cl));\n }\n currentLi.scrollIntoView({ block: \"nearest\" }); // Ensure visible\n }\n\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdUp?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdUp?.classList.remove(cl)),\n 300\n );\n } else if (e.key === \"Enter\") {\n e.preventDefault(); // Prevent form submission if applicable\n if (\n this.#currentSuggestion >= 0 &&\n this.#currentSuggestion < this.#allSuggestions.length\n ) {\n this._onPlaceSelected(\n this.#allSuggestions[this.#currentSuggestion].place\n );\n // Reset is handled within onPlaceSelected via reset(true)\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdEscape?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdEscape?.classList.remove(cl)),\n 300\n );\n this._reset(true); // Reset search input and results, refresh token\n }\n }\n\n /**\n * Debounced function to fetch autocomplete suggestions from the Google Places API.\n * Triggered by the 'input' event on the input element.\n */\n _debouncedMakeAcRequest = this._debounce(async () => {\n if (!this.#inputElement || !this.#inputElement.value) {\n this._reset();\n if (this.#inputElement)\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n return;\n }\n\n this.#request.input = this.#inputElement.value;\n //console.log(\"Request:\", this.#request); // Debugging\n try {\n const { suggestions } =\n // eslint-disable-next-line no-undef\n await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(\n this.#request\n );\n\n // Display suggestions\n if (suggestions && suggestions.length > 0) {\n this.#ul.replaceChildren(\n ...this._createSuggestionElements(suggestions)\n );\n this.#ul.style.display = \"block\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"true\");\n } else {\n // No suggestions found\n this._reset(); // Clear any old suggestions\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n // Optionally display a \"no results\" message in the 'ul'\n }\n } catch (error) {\n this.#onErrorCallback(error);\n this._reset();\n if (this.#inputElement)\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n }\n }, this.#options?.debounce ?? 100);\n\n /**\n * Creates an array of list item (LI) elements for the suggestions dropdown.\n * Each LI contains a link (A) with the place prediction details and distance.\n * Handles highlighting the matched parts of the suggestion text.\n * @param {Array<google.maps.places.AutocompleteSuggestion>} suggestions - Array of suggestion objects from the API.\n * @returns {Array<HTMLLIElement>} An array of LI elements to be added to the suggestions UL.\n */\n _createSuggestionElements(suggestions) {\n this.#allSuggestions = []; // Reset before populating\n return suggestions.map((suggestion, index) => {\n this.#allSuggestions.push({\n id: index + 1,\n description: suggestion.placePrediction.toString(),\n place: suggestion.placePrediction.toPlace(),\n });\n\n // create div elements\n const divContainer = document.createElement(\"div\");\n divContainer.className = this.#options.classes.li_div_container; // flex min-w-0 gap-x-4\n // create inner div element - place name\n const divInner = document.createElement(\"div\");\n divInner.className = this.#options.classes.li_div_one; // min-w-0 flex-auto\n divContainer.appendChild(divInner);\n // create p element - place name\n const p = document.createElement(\"p\");\n p.className = this.#options.classes.li_div_one_p; // text-sm/6\n\n // get prediction text\n const predictionText = suggestion.placePrediction.text;\n const originalText = predictionText.text;\n // Array of objects with startOffset, endOffset\n const matches = predictionText.matches;\n\n //Highlighting Logic\n let lastIndex = 0;\n\n // Sort matches just in case they aren't ordered (though they usually are)\n matches.sort((a, b) => a.startOffset - b.startOffset);\n\n // 1. Create the outer span\n const outerSpan = document.createElement(\"span\");\n\n // 2. Create the inner span for the bold part\n const innerSpan = document.createElement(\"span\");\n innerSpan.classList = this.#options.classes.highlight ?? \"font-bold\"; // Use the highlight class from options\n\n for (const match of matches) {\n // Append text before the current match\n outerSpan.textContent += originalText.substring(\n lastIndex,\n match.startOffset\n );\n\n // Append the highlighted match segment\n if (match.startOffset > 0) {\n // check previous charter is space\n const prevChar = originalText.charAt(match.startOffset - 1);\n if (prevChar == \" \") {\n innerSpan.textContent += \" \";\n }\n }\n innerSpan.textContent += originalText.substring(\n match.startOffset,\n match.endOffset\n );\n\n // Update the last index processed\n lastIndex = match.endOffset;\n }\n\n // 3. Create a text node for the remaining text\n const remainingText = document.createTextNode(\n originalText.substring(lastIndex)\n );\n\n // 4. Append the inner span and the text node to the outer span\n outerSpan.appendChild(innerSpan);\n outerSpan.appendChild(remainingText);\n\n // 5. Append the outer span to the paragraph element\n p.appendChild(outerSpan);\n\n divInner.appendChild(p);\n divContainer.appendChild(divInner);\n\n // create inner div element - distance\n const divInner2 = document.createElement(\"div\");\n divInner2.className = this.#options.classes.li_div_two; //'shrink-0 flex flex-col items-end min-w-16';\n divContainer.appendChild(divInner2);\n // create p element - distance\n const p2 = document.createElement(\"p\");\n p2.className = this.#options.classes.li_div_two_p; //'mt-1 text-xs/5 ';\n p2.textContent = this._formatDistance(\n suggestion.placePrediction.distanceMeters,\n this.#options.distance_units ?? \"km\"\n );\n divInner2.appendChild(p2);\n\n // // create a link element\n const a = document.createElement(\"a\");\n a.href = \"javascript:void(0)\";\n a.tabIndex = index + 1;\n a.className = this.#options.classes.li_a; // block w-full flex justify-between\n\n a.addEventListener(\"click\", () => {\n this._onPlaceSelected(suggestion.placePrediction.toPlace());\n });\n\n // ...\n // a.addEventListener(\"click\", () => {\n // this._fetchPlaceDetails(prediction.place_id);\n // });\n a.appendChild(divContainer);\n a.appendChild(divInner2);\n\n const li = document.createElement(\"li\");\n li.id = `option-${index + 1}`;\n li.className = this.#options.classes.li;\n\n li.appendChild(a);\n return li;\n });\n }\n\n /**\n * Handles the selection of a place. Fetches required fields\n * (displayName, formattedAddress, addressComponents) and calls the\n * user-defined `onPacData` callback.\n * @param {google.maps.places.Place} place - The selected Place object.\n */\n async _onPlaceSelected(place) {\n try {\n // Fetch necessary details for the selected place\n await place.fetchFields({\n fields: [\"displayName\", \"formattedAddress\", \"addressComponents\"], // Add more fields as needed\n });\n // Call the user-provided callback with the place data\n // eslint-disable-next-line no-undef\n this.#onDataCallback(place.toJSON()); // Convert to plain JSON object for the callback\n } catch (error) {\n console.error(\"Error fetching place details:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(error);\n } finally {\n // Reset the input and suggestions regardless of success/error\n this._reset(true); // Refresh token after selection\n }\n }\n\n /**\n * Creates a new Google Places Autocomplete Session Token.\n * This should be called before starting a new series of autocomplete requests.\n */\n _refreshToken() {\n try {\n // eslint-disable-next-line no-undef\n this.#request.sessionToken =\n new google.maps.places.AutocompleteSessionToken();\n } catch (error) {\n console.error(\"Error creating session token:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(error);\n }\n }\n\n clear() {\n this._reset(true);\n }\n\n destroy() {\n // Remove event listeners, remove elements from DOM\n if (this.#inputElement) {\n this.#inputElement.removeEventListener(\n \"input\",\n this._debouncedMakeAcRequest\n );\n // remove other listeners\n }\n if (this.#pacEl && this.#container) {\n this.#pacEl.removeChild(this.#container.parentElement); // remove the whole section\n }\n // Nullify properties\n for (const prop in this) {\n if (Object.hasOwn(this, prop)) {\n this[prop] = null;\n }\n }\n console.log(\"PacAutocomplete instance destroyed.\");\n }\n}\n"],"names":["PlacesAutocomplete","config","__privateAdd","_pacEl","_googleMapsApiKey","_googleMapsApiVersion","_options","_request","_inputElement","_container","_ul","_kbdEscape","_kbdUp","_kbdDown","_allSuggestions","_currentSuggestion","_onDataCallback","_onErrorCallback","_defaultClasses","_defaultRequestParams","__publicField","__privateGet","suggestions","error","_a","__privateSet","place","func","wait","timeout","args","later","distance","units","value","unitLabel","g","h","a","k","p","c","l","q","m","b","d","r","e","u","f","n","t","section","cl","iconContainer","icon","label","kbdContainer","refresh","li","link","currentLi","currentA","suggestion","index","divContainer","divInner","predictionText","originalText","matches","lastIndex","outerSpan","innerSpan","match","remainingText","divInner2","p2","prop"],"mappings":"qtBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2CAgBO,MAAMA,CAAmB,CAiE9B,YAAYC,EAAQ,CA/DpBC,EAAA,KAAAC,GACAD,EAAA,KAAAE,GACAF,EAAA,KAAAG,GACAH,EAAA,KAAAI,GACAJ,EAAA,KAAAK,GACAL,EAAA,KAAAM,GACAN,EAAA,KAAAO,GACAP,EAAA,KAAAQ,GACAR,EAAA,KAAAS,GACAT,EAAA,KAAAU,GACAV,EAAA,KAAAW,GACAX,EAAA,KAAAY,EAAkB,CAAE,GACpBZ,EAAA,KAAAa,EAAqB,IACrBb,EAAA,KAAAc,GACAd,EAAA,KAAAe,GACAf,EAAA,KAAAgB,EAAkB,CAEhB,QAAS,GACT,UAAW,0CACX,eACE,uEACF,KAAM,kPACN,MACE,0JACF,cAAe,gDACf,WACE,wGACF,OACE,kHACF,SACE,kHACF,WAAY,2BACZ,GAAI,8LACJ,GAAI,uGACJ,WAAY,gBACZ,KAAM,oCACN,aAAc,aACd,iBAAkB,uBAClB,WAAY,oBACZ,aAAc,YACd,WAAY,4CACZ,aAAc,iBACd,UAAW,WACZ,GACDhB,EAAA,KAAAiB,EAAwB,CAEtB,MAAO,GACP,oBAAqB,CAAC,IAAI,EAC1B,SAAU,QACV,OAAQ,IACT,GAqdDC,EAAA,+BAA0B,KAAK,UAAU,SAAY,CACnD,GAAI,CAACC,EAAA,KAAKb,IAAiB,CAACa,EAAA,KAAKb,GAAc,MAAO,CACpD,KAAK,OA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,CAC5B,GAAI,CAEF,MAAMA,EAAM,YAAY,CACtB,OAAQ,CAAC,cAAe,mBAAoB,mBAAmB,CACvE,CAAO,EAGDL,EAAA,KAAKL,GAAL,UAAqBU,EAAM,OAAQ,EACpC,OAAQH,EAAO,CACd,QAAQ,MAAM,gCAAiCA,CAAK,EAEpDF,EAAA,KAAKJ,GAAL,UAAsBM,EAC5B,QAAc,CAER,KAAK,OAAO,EAAI,CACtB,CACA,CAME,eAAgB,CACd,GAAI,CAEFF,EAAA,KAAKd,GAAS,aACZ,IAAI,OAAO,KAAK,OAAO,wBAC1B,OAAQgB,EAAO,CACd,QAAQ,MAAM,gCAAiCA,CAAK,EAEpDF,EAAA,KAAKJ,GAAL,UAAsBM,EAC5B,CACA,CAEE,OAAQ,CACN,KAAK,OAAO,EAAI,CACpB,CAEE,SAAU,CAEJF,EAAA,KAAKb,IACPa,EAAA,KAAKb,GAAc,oBACjB,QACA,KAAK,uBACN,EAGCa,EAAA,KAAKlB,IAAUkB,EAAA,KAAKZ,IACtBY,EAAA,KAAKlB,GAAO,YAAYkB,EAAA,KAAKZ,GAAW,aAAa,EAGvD,UAAWqE,KAAQ,KACb,OAAO,OAAO,KAAMA,CAAI,IAC1B,KAAKA,CAAI,EAAI,MAGjB,QAAQ,IAAI,qCAAqC,CACrD,CACA,CA1uBE3E,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YA6BAC,EAAA"}
|
|
1
|
+
{"version":3,"file":"places-autocomplete.umd.cjs","sources":["../lib/PlacesAutocomplete.js"],"sourcesContent":["/**\n * Initializes a Places Autocomplete widget.\n * This script dynamically loads the Google Maps JavaScript API, creates the UI elements\n * for the autocomplete input and suggestions list, handles user input with debouncing,\n * fetches suggestions, manages keyboard navigation, and calls user-defined callbacks\n * on place selection or error.\n *\n * @author Alexander Pechkarev <alexpechkarev@gmail.com>\n * @license MIT\n *\n */\n\n/**\n * PacAutocomplete class\n * This class provides a Places Autocomplete widget.\n */\nexport class PlacesAutocomplete {\n // --- Private Properties (using # or _ prefix by convention) ---\n #containerId; // Container ID where the autocomplete widget will be rendered.\n #pacEl;\n #googleMapsApiKey;\n #googleMapsApiVersion;\n #options;\n #request;\n #inputElement;\n #container;\n #ul;\n #kbdEscape;\n #kbdUp;\n #kbdDown;\n #allSuggestions = [];\n #currentSuggestion = -1;\n #onDataCallback; // For user-provided data callback\n #onErrorCallback; // For user-provided error callback\n #defaultClasses = {\n // CSS classes for various parts of the widget.\n section: \"\", // Outer section container.\n container: \"relative z-10 transform rounded-xl mt-4\", // Main container div.\n icon_container:\n \"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3\", // Container for the search icon.\n icon: '<svg xmlns=\"http://www.w3.org/2000/svg\" class=\"w-5 h-5\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><circle cx=\"11\" cy=\"11\" r=\"8\" /><path d=\"m21 21-4.3-4.3\" /></svg>', // SVG for the search icon.\n input:\n \"border-1 w-full rounded-md border-0 shadow-sm bg-gray-100 px-4 py-2.5 pl-10 pr-20 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 sm:text-sm\", // Input field.\n kbd_container: \"absolute inset-y-0 right-0 flex py-1.5 pr-1.5\", // Container for keyboard hints.\n kbd_escape:\n \"inline-flex items-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-8 mr-1\", // Escape key hint.\n kbd_up:\n \"inline-flex items-center justify-center rounded border border-gray-300 px-1 font-sans text-xs text-gray-500 w-6\", // Up arrow key hint.\n kbd_down:\n \"inline-flex items-center rounded border border-gray-400 px-1 font-sans text-xs text-gray-500 justify-center w-6\", // Down arrow key hint.\n kbd_active: \"bg-indigo-500 text-white\", // Class for active keyboard hint.\n 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\", // Suggestions list (ul).\n li: \"z-50 cursor-default select-none py-2 px-2 lg:px-4 text-gray-900 hover:bg-indigo-500 hover:text-white\", // Suggestion item (li).\n li_current: \"bg-indigo-500\", // Class for the currently selected suggestion item.\n li_a: \"block w-full flex justify-between\", // Link element within a suggestion item.\n li_a_current: \"text-white\", // Class for the link in the currently selected suggestion item.\n li_div_container: \"flex min-w-0 gap-x-4\", // Container div within the suggestion link.\n li_div_one: \"min-w-0 flex-auto\", // First inner div (for place name).\n li_div_one_p: \"text-sm/6\", // Paragraph for the place name.\n li_div_two: \"shrink-0 flex flex-col items-end min-w-16\", // Second inner div (for distance).\n li_div_two_p: \"mt-1 text-xs/5\", // Paragraph for the distance.\n highlight: \"font-bold\", // Class for highlighting matched text in suggestions.\n };\n #defaultRequestParams = {\n // Default parameters for the autocomplete request.\n input: \"\", // Initial input value (empty).\n includedRegionCodes: [\"GB\"], // Default region codes to include in suggestions.\n language: \"en-gb\",\n region: \"GB\",\n };\n\n /**\n * Class constructor for PacAutocomplete.\n * Initializes the autocomplete widget with the provided configuration.\n * @param {Object} config - Configuration object for the autocomplete widget.\n * @param {string} config.containerId - ID of the container element for the widget.\n * @param {string} config.googleMapsApiKey - Google Maps API key.\n * @param {string} [config.googleMapsApiVersion] - Version of the Google Maps API to use (default: \"weekly\").\n * @param {Object} [config.options] - Additional options for the widget (e.g., classes, callbacks).\n * @param {Object} [config.requestParams] - Parameters for the autocomplete request (e.g., input, region).\n * @param {*} config\n */\n constructor(config) {\n // console.log(\"PacAutocomplete constructor called.\", config.requestParams);\n if (!config || !config.containerId || !config.googleMapsApiKey) {\n throw new Error(\n \"PacAutocomplete: Missing required configuration (containerId, googleMapsApiKey).\"\n );\n }\n\n this.#containerId = config.containerId; // Store the configuration object\n this.#pacEl = document.getElementById(config.containerId);\n if (!this.#pacEl) {\n throw new Error(\n `PacAutocomplete: Container element with ID \"${config.containerId}\" not found.`\n );\n }\n\n this.#googleMapsApiKey = config.googleMapsApiKey;\n this.#googleMapsApiVersion = config.googleMapsApiVersion || \"weekly\";\n\n // Merge user options with defaults\n this.#options = {\n autofocus: false, // Automatically focus the input on load.\n autocomplete: \"off\", // HTML autocomplete attribute for the input.\n placeholder: \"Start typing your address ...\", // Placeholder text for the input.\n distance: true, // Show distance in suggestions (requires origin in request).\n distance_units: \"km\", // Units for distance ('km' or 'miles').\n label: \"\", // Optional label text above the input.\n debounce: 100, // Debounce delay (ms) for API requests.\n ...config.options, // User-defined options override defaults\n };\n // Ensure classes are deeply merged if user provides partial classes\n if (config.options && config.options.classes) {\n this.#options.classes = {\n ...this.#defaultClasses,\n ...config.options.classes,\n };\n } else {\n this.#options.classes = this.#defaultClasses; // Use default classes if none provided\n }\n\n // Set default response and error callbacks if not provided\n this.#onDataCallback =\n config.onResponse ||\n ((place) => {\n console.info(\"---------Default onResponse not provided---------\");\n console.info(\"Selected Place:\", JSON.stringify(place, null, 2));\n });\n this.#onErrorCallback =\n config.onError ||\n ((error) => {\n console.error(\"---------Default onError not provided---------\");\n console.error(\"PAC Error:\", error);\n });\n\n if (config.requestParams && Object.keys(config.requestParams).length > 0) {\n this.#request = {\n ...this.#defaultRequestParams,\n ...config.requestParams,\n };\n } else {\n this.#request = { ...this.#defaultRequestParams }; // Use defaults if no requestParams provided\n }\n\n //console.log(this.#request);\n\n this._init(); // Underscore prefix for internal initialization method\n }\n\n // --- Private Initialization Method ---\n async _init() {\n try {\n // check if google maps api is already loaded\n if (typeof google === \"undefined\" || !google.maps) {\n // Load the Google Maps API dynamically\n await this._loadGoogleMapsApi({\n key: this.#googleMapsApiKey,\n v: this.#googleMapsApiVersion,\n });\n }\n this._createPACStructure(); // Pass this.#options\n await this._initializeAutocomplete(); // Pass this.#options\n //console.log(\"PacAutocomplete Initialized for container:\", this.#pacEl.id);\n } catch (error) {\n this.#onErrorCallback(error);\n }\n }\n\n /**\n * Creates a debounced version of a function.\n * The debounced function delays invoking `func` until after `wait` milliseconds have\n * elapsed since the last time the debounced function was invoked.\n * @param {Function} func - The function to debounce.\n * @param {number} wait - The number of milliseconds to delay.\n * @returns {Function} The new debounced function.\n */\n _debounce(func, wait) {\n let timeout = null;\n return function executedFunction(...args) {\n const later = () => {\n timeout = null;\n func(...args); // Call original function\n };\n if (timeout !== null) {\n clearTimeout(timeout); // Clear the previous timeout\n }\n timeout = setTimeout(later, wait ?? 100); // Set the new timeout\n };\n }\n /**\n * Formats a distance in meters into kilometers or miles.\n * @param {number | null | undefined} distance - Distance in meters.\n * @param {'km' | 'miles'} units - The desired output units.\n * @returns {string | null} Formatted distance string (e.g., \"1.23 km\") or null if input is invalid.\n */\n _formatDistance(distance, units) {\n if (typeof distance !== \"number\" || !this.#options.distance) {\n return null; // Return null if distance isn't shown or invalid\n }\n let value;\n let unitLabel;\n if (units === \"km\") {\n value = (distance / 1000).toFixed(2);\n unitLabel = \"km\";\n } else {\n // Default to miles if not 'km'\n value = (distance / 1609.34).toFixed(2);\n unitLabel = \"miles\";\n }\n // Avoid showing \".00\"\n value = value.replace(/\\.00$/, \"\");\n return `${value} ${unitLabel}`;\n }\n\n /**\n * Dynamically loads the Google Maps JavaScript API using the importLibrary method.\n * This is the standard approach recommended by Google.\n * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api\n * @param {object} g - Configuration object for the API loader (key, v, libraries, etc.).\n */\n async _loadGoogleMapsApi(g) {\n var h, // Promise tracking API load\n a, // Script element\n k, // Loop variable for config keys\n p = \"The Google Maps JavaScript API\", // Error message prefix\n c = \"google\", // Global namespace\n l = \"importLibrary\", // Loader function name\n q = \"__ib__\", // Internal callback name\n m = document, // Document reference\n b = window; // Window reference\n b = b[c] || (b[c] = {}); // Ensure google namespace exists\n var d = b.maps || (b.maps = {}), // Ensure google.maps namespace exists\n r = new Set(), // Set to track requested libraries\n e = new URLSearchParams(), // URL parameters for the API script\n u = () =>\n // Function to initiate API loading (if not already started)\n h ||\n // eslint-disable-next-line no-async-promise-executor\n (h = new Promise(async (f, n) => {\n // Create script element (done async to potentially wait for nonce)\n // await (a = m.createElement('script')); // Original Google code had await here, might not be needed\n a = m.createElement(\"script\"); // Create script tag\n e.set(\"libraries\", [...r].join(\",\")); // Add accumulated libraries\n // Add other parameters from the config object 'g'\n for (k in g)\n e.set(\n k.replace(/[A-Z]/g, (t) => \"_\" + t[0].toLowerCase()), // Convert camelCase to snake_case\n g[k]\n );\n e.set(\"callback\", c + \".maps.\" + q); // Set the internal callback function name\n a.src = `https://maps.${c}apis.com/maps/api/js?` + e; // Construct the API URL\n d[q] = f; // Assign the promise resolver to the callback name on google.maps\n // Error handling for script loading failure\n a.onerror = () => (h = n(Error(p + \" could not load.\"))); // Use onerror for load failures\n // Nonce for Content Security Policy\n a.nonce = m.querySelector(\"script[nonce]\")?.nonce || \"\";\n m.head.append(a); // Append the script to the document head\n }));\n // Define or reuse the importLibrary function on google.maps\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n d[l]\n ? console.warn(p + \" only loads once. Ignoring:\", g) // Warn if called again\n : (d[l] = (f, ...n) => r.add(f) && u().then(() => d[l](f, ...n))); // The actual importLibrary implementation\n }\n\n // --- UI Creation ---\n _createPACStructure() {\n const section = document.createElement(\"section\");\n this.#options.classes.section\n .split(\" \")\n .forEach((cl) => cl && section.classList.add(cl));\n\n // Main container\n this.#container = document.createElement(\"div\");\n this.#container.className = this.#options.classes.container;\n this.#container.setAttribute(\"id\", this.#containerId + \"-div\");\n section.appendChild(this.#container);\n\n // Icon\n const iconContainer = document.createElement(\"div\");\n iconContainer.className = this.#options.classes.icon_container;\n this.#container.appendChild(iconContainer);\n const icon = document.createElement(\"div\");\n icon.innerHTML = this.#options.classes.icon;\n iconContainer.appendChild(icon.firstElementChild); // Append the actual SVG element\n\n // Input field\n this.#inputElement = document.createElement(\"input\");\n this.#inputElement.id = this.#containerId + \"-input\"; // Assign ID for label association\n this.#inputElement.type = \"text\";\n this.#inputElement.name = \"search\"; // Consider making name configurable\n this.#inputElement.placeholder = this.#options.placeholder;\n this.#inputElement.autocomplete = this.#options.autocomplete;\n this.#inputElement.className = this.#options.classes.input;\n this.#inputElement.setAttribute(\"role\", \"combobox\");\n this.#inputElement.setAttribute(\"aria-autocomplete\", \"list\");\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\"); // Will be updated dynamically\n this.#inputElement.setAttribute(\"aria-controls\", \"pacSuggestions\"); // Links to the suggestions list\n\n if (this.#options.autofocus) {\n this.#inputElement.autofocus = true;\n }\n if (this.#options.label) {\n const label = document.createElement(\"label\");\n label.htmlFor = this.#containerId + \"-labelInput\"; // Assuming inputElement gets this ID\n label.textContent = this.#options.label;\n // Add label classes if needed from opts.classes\n this.#container.appendChild(label); // Append label before input or adjust structure\n }\n this.#container.appendChild(this.#inputElement);\n\n // Keyboard hints container\n const kbdContainer = document.createElement(\"div\");\n kbdContainer.className = this.#options.classes.kbd_container;\n this.#kbdEscape = document.createElement(\"kbd\");\n this.#kbdEscape.className = this.#options.classes.kbd_escape;\n this.#kbdEscape.textContent = \"Esc\";\n kbdContainer.appendChild(this.#kbdEscape);\n this.#kbdUp = document.createElement(\"kbd\");\n this.#kbdUp.className = this.#options.classes.kbd_up;\n this.#kbdUp.innerHTML = \"↑\"; // Up arrow HTML entity\n kbdContainer.appendChild(this.#kbdUp);\n this.#kbdDown = document.createElement(\"kbd\");\n this.#kbdDown.className = this.#options.classes.kbd_down;\n this.#kbdDown.innerHTML = \"↓\"; // Down arrow HTML entity\n kbdContainer.appendChild(this.#kbdDown);\n this.#container.appendChild(kbdContainer);\n\n // Suggestions list (initially hidden)\n this.#ul = document.createElement(\"ul\");\n this.#ul.id = \"pacSuggestions\"; // Must match aria-controls\n this.#ul.className = this.#options.classes.ul;\n this.#ul.style.display = \"none\";\n this.#ul.setAttribute(\"role\", \"listbox\");\n this.#container.appendChild(this.#ul);\n\n this.#pacEl.appendChild(section);\n section.addEventListener(\"keydown\", this._onKeyDown.bind(this)); // Bind 'this'\n }\n\n /**\n * Initializes the core autocomplete functionality after the API is loaded.\n * Imports necessary libraries and sets up the input event listener.\n */\n async _initializeAutocomplete() {\n try {\n // Ensure the 'places' library is available via the dynamic loader\n // eslint-disable-next-line no-undef\n await google.maps.importLibrary(\"places\");\n // console.log('Places library imported successfully.'); // For debugging\n\n // Initial token generation\n this._refreshToken();\n\n // Attach the debounced request function to the input element's 'input' event\n if (this.#inputElement) {\n this.#inputElement.addEventListener(\n \"input\",\n this._debouncedMakeAcRequest.bind(this)\n );\n // Add focus/blur listeners if needed to manage suggestion visibility\n this.#inputElement.addEventListener(\"blur\", () => {\n // Delay hiding suggestions to allow click events on them\n setTimeout(() => {\n if (this.#ul && !this.#ul.contains(document.activeElement)) {\n // Check if focus moved outside suggestions\n this.#ul.style.display = \"none\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n }\n }, 200); // Adjust delay as needed\n });\n this.#inputElement.addEventListener(\"focus\", () => {\n // Potentially show suggestions again if input has value\n if (this.#inputElement.value && this.#allSuggestions.length > 0) {\n this.#ul.style.display = \"block\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"true\");\n }\n });\n } else {\n this.#onErrorCallback(\n new Error(\"Input element not found during initialization.\")\n );\n }\n } catch (error) {\n console.error(\"Error initializing Google Places Autocomplete:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(\n new Error(\"Google Maps Places library not available.\")\n );\n }\n }\n\n /**\n * Resets the autocomplete input field, clears suggestions, and optionally refreshes the session token.\n * @param {boolean} [refresh=false] - Whether to refresh the Google Places session token.\n */\n _reset(refresh = false) {\n this.#currentSuggestion = -1;\n if (this.#inputElement) {\n this.#inputElement.value = \"\";\n }\n this.#allSuggestions = [];\n this.#currentSuggestion = -1;\n if (this.#ul) {\n this.#ul.innerHTML = \"\"; // Clear existing suggestions\n this.#ul.style.display = \"none\";\n }\n if (refresh) {\n this._refreshToken();\n }\n }\n /**\n * Removes the 'current' highlighting classes from all suggestion list items (li) and their links (a).\n */\n _resetLiClasses() {\n if (!this.#ul) return;\n Array.from(this.#ul.children).forEach((li) => {\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => li.classList.remove(cl));\n const link = li.querySelector(\"a\");\n if (link) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => link.classList.remove(cl));\n }\n });\n }\n\n /**\n * Handles keyboard events (ArrowDown, ArrowUp, Enter, Escape) for navigating\n * and selecting suggestions or closing the list.\n * @param {KeyboardEvent} e - The keyboard event object.\n */\n _onKeyDown(e) {\n if (\n !this.#allSuggestions.length ||\n !this.#ul ||\n this.#ul.style.display === \"none\"\n )\n return;\n\n this._resetLiClasses(); // Reset classes on any key press within the suggestions\n\n if (e.key === \"ArrowDown\") {\n e.preventDefault(); // Prevent cursor movement in input\n this.#currentSuggestion = Math.min(\n this.#currentSuggestion + 1,\n this.#allSuggestions.length - 1\n );\n if (this.#currentSuggestion < 0) this.#currentSuggestion = 0; // Handle case where it was -1\n\n const currentLi = this.#ul.children.item(this.#currentSuggestion);\n if (currentLi) {\n const currentA = currentLi.querySelector(\"a\");\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => currentLi.classList.add(cl));\n if (currentA) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => currentA.classList.add(cl));\n }\n currentLi.scrollIntoView({ block: \"nearest\" }); // Ensure visible\n }\n\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdDown?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdDown?.classList.remove(cl)),\n 300\n );\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault(); // Prevent cursor movement in input\n this.#currentSuggestion = Math.max(this.#currentSuggestion - 1, 0); // Stay at 0 if already there\n\n const currentLi = this.#ul.children.item(this.#currentSuggestion);\n if (currentLi) {\n const currentA = currentLi.querySelector(\"a\");\n this.#options.classes.li_current\n .split(\" \")\n .forEach((cl) => currentLi.classList.add(cl));\n if (currentA) {\n this.#options.classes.li_a_current\n .split(\" \")\n .forEach((cl) => currentA.classList.add(cl));\n }\n currentLi.scrollIntoView({ block: \"nearest\" }); // Ensure visible\n }\n\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdUp?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdUp?.classList.remove(cl)),\n 300\n );\n } else if (e.key === \"Enter\") {\n e.preventDefault(); // Prevent form submission if applicable\n if (\n this.#currentSuggestion >= 0 &&\n this.#currentSuggestion < this.#allSuggestions.length\n ) {\n this._onPlaceSelected(\n this.#allSuggestions[this.#currentSuggestion].place\n );\n // Reset is handled within onPlaceSelected via reset(true)\n }\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n // Visual feedback for key press\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdEscape?.classList.add(cl));\n setTimeout(\n () =>\n this.#options.classes.kbd_active\n .split(\" \")\n .forEach((cl) => this.#kbdEscape?.classList.remove(cl)),\n 300\n );\n this._reset(true); // Reset search input and results, refresh token\n }\n }\n\n /**\n * Debounced function to fetch autocomplete suggestions from the Google Places API.\n * Triggered by the 'input' event on the input element.\n */\n _debouncedMakeAcRequest = this._debounce(async () => {\n if (!this.#inputElement || !this.#inputElement.value) {\n this._reset();\n if (this.#inputElement)\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n return;\n }\n\n this.#request.input = this.#inputElement.value;\n //console.log(\"Request:\", this.#request); // Debugging\n try {\n const { suggestions } =\n // eslint-disable-next-line no-undef\n await google.maps.places.AutocompleteSuggestion.fetchAutocompleteSuggestions(\n this.#request\n );\n\n // Display suggestions\n if (suggestions && suggestions.length > 0) {\n this.#ul.replaceChildren(\n ...this._createSuggestionElements(suggestions)\n );\n this.#ul.style.display = \"block\";\n this.#inputElement.setAttribute(\"aria-expanded\", \"true\");\n } else {\n // No suggestions found\n this._reset(); // Clear any old suggestions\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n // Optionally display a \"no results\" message in the 'ul'\n }\n } catch (error) {\n this.#onErrorCallback(error);\n this._reset();\n if (this.#inputElement)\n this.#inputElement.setAttribute(\"aria-expanded\", \"false\");\n }\n }, this.#options?.debounce ?? 100);\n\n /**\n * Creates an array of list item (LI) elements for the suggestions dropdown.\n * Each LI contains a link (A) with the place prediction details and distance.\n * Handles highlighting the matched parts of the suggestion text.\n * @param {Array<google.maps.places.AutocompleteSuggestion>} suggestions - Array of suggestion objects from the API.\n * @returns {Array<HTMLLIElement>} An array of LI elements to be added to the suggestions UL.\n */\n _createSuggestionElements(suggestions) {\n this.#allSuggestions = []; // Reset before populating\n return suggestions.map((suggestion, index) => {\n this.#allSuggestions.push({\n id: index + 1,\n description: suggestion.placePrediction.toString(),\n place: suggestion.placePrediction.toPlace(),\n });\n\n // create div elements\n const divContainer = document.createElement(\"div\");\n divContainer.className = this.#options.classes.li_div_container; // flex min-w-0 gap-x-4\n // create inner div element - place name\n const divInner = document.createElement(\"div\");\n divInner.className = this.#options.classes.li_div_one; // min-w-0 flex-auto\n divContainer.appendChild(divInner);\n // create p element - place name\n const p = document.createElement(\"p\");\n p.className = this.#options.classes.li_div_one_p; // text-sm/6\n\n // get prediction text\n const predictionText = suggestion.placePrediction.text;\n const originalText = predictionText.text;\n // Array of objects with startOffset, endOffset\n const matches = predictionText.matches;\n\n //Highlighting Logic\n let lastIndex = 0;\n\n // Sort matches just in case they aren't ordered (though they usually are)\n matches.sort((a, b) => a.startOffset - b.startOffset);\n\n // 1. Create the outer span\n const outerSpan = document.createElement(\"span\");\n\n // 2. Create the inner span for the bold part\n const innerSpan = document.createElement(\"span\");\n innerSpan.classList = this.#options.classes.highlight ?? \"font-bold\"; // Use the highlight class from options\n\n for (const match of matches) {\n // Append text before the current match\n outerSpan.textContent += originalText.substring(\n lastIndex,\n match.startOffset\n );\n\n // Append the highlighted match segment\n if (match.startOffset > 0) {\n // check previous charter is space\n const prevChar = originalText.charAt(match.startOffset - 1);\n if (prevChar == \" \") {\n innerSpan.textContent += \" \";\n }\n }\n innerSpan.textContent += originalText.substring(\n match.startOffset,\n match.endOffset\n );\n\n // Update the last index processed\n lastIndex = match.endOffset;\n }\n\n // 3. Create a text node for the remaining text\n const remainingText = document.createTextNode(\n originalText.substring(lastIndex)\n );\n\n // 4. Append the inner span and the text node to the outer span\n outerSpan.appendChild(innerSpan);\n outerSpan.appendChild(remainingText);\n\n // 5. Append the outer span to the paragraph element\n p.appendChild(outerSpan);\n\n divInner.appendChild(p);\n divContainer.appendChild(divInner);\n\n // create inner div element - distance\n const divInner2 = document.createElement(\"div\");\n divInner2.className = this.#options.classes.li_div_two; //'shrink-0 flex flex-col items-end min-w-16';\n divContainer.appendChild(divInner2);\n // create p element - distance\n const p2 = document.createElement(\"p\");\n p2.className = this.#options.classes.li_div_two_p; //'mt-1 text-xs/5 ';\n p2.textContent = this._formatDistance(\n suggestion.placePrediction.distanceMeters,\n this.#options.distance_units ?? \"km\"\n );\n divInner2.appendChild(p2);\n\n // // create a link element\n const a = document.createElement(\"a\");\n a.href = \"javascript:void(0)\";\n a.tabIndex = index + 1;\n a.className = this.#options.classes.li_a; // block w-full flex justify-between\n\n a.addEventListener(\"click\", () => {\n this._onPlaceSelected(suggestion.placePrediction.toPlace());\n });\n\n // ...\n // a.addEventListener(\"click\", () => {\n // this._fetchPlaceDetails(prediction.place_id);\n // });\n a.appendChild(divContainer);\n a.appendChild(divInner2);\n\n const li = document.createElement(\"li\");\n li.id = `option-${index + 1}`;\n li.className = this.#options.classes.li;\n\n li.appendChild(a);\n return li;\n });\n }\n\n /**\n * Handles the selection of a place. Fetches required fields\n * (displayName, formattedAddress, addressComponents) and calls the\n * user-defined `onPacData` callback.\n * @param {google.maps.places.Place} place - The selected Place object.\n */\n async _onPlaceSelected(place) {\n try {\n // Fetch necessary details for the selected place\n await place.fetchFields({\n fields: [\"displayName\", \"formattedAddress\", \"addressComponents\"], // Add more fields as needed\n });\n // Call the user-provided callback with the place data\n // eslint-disable-next-line no-undef\n this.#onDataCallback(place.toJSON()); // Convert to plain JSON object for the callback\n } catch (error) {\n console.error(\"Error fetching place details:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(error);\n } finally {\n // Reset the input and suggestions regardless of success/error\n this._reset(true); // Refresh token after selection\n }\n }\n\n /**\n * Creates a new Google Places Autocomplete Session Token.\n * This should be called before starting a new series of autocomplete requests.\n */\n _refreshToken() {\n try {\n // eslint-disable-next-line no-undef\n this.#request.sessionToken =\n new google.maps.places.AutocompleteSessionToken();\n } catch (error) {\n console.error(\"Error creating session token:\", error);\n // eslint-disable-next-line no-undef\n this.#onErrorCallback(error);\n }\n }\n\n clear() {\n this._reset(true);\n }\n\n destroy() {\n // Remove event listeners, remove elements from DOM\n if (this.#inputElement) {\n this.#inputElement.removeEventListener(\n \"input\",\n this._debouncedMakeAcRequest\n );\n // remove other listeners\n }\n if (this.#pacEl && this.#container) {\n this.#pacEl.removeChild(this.#container.parentElement); // remove the whole section\n }\n // Nullify properties\n for (const prop in this) {\n if (Object.hasOwn(this, prop)) {\n this[prop] = null;\n }\n }\n console.log(\"PacAutocomplete instance destroyed.\");\n }\n}\n"],"names":["PlacesAutocomplete","config","__privateAdd","_containerId","_pacEl","_googleMapsApiKey","_googleMapsApiVersion","_options","_request","_inputElement","_container","_ul","_kbdEscape","_kbdUp","_kbdDown","_allSuggestions","_currentSuggestion","_onDataCallback","_onErrorCallback","_defaultClasses","_defaultRequestParams","__publicField","__privateGet","suggestions","error","_a","__privateSet","place","func","wait","timeout","args","later","distance","units","value","unitLabel","g","h","a","k","p","c","l","q","m","b","d","r","e","u","f","n","t","section","cl","iconContainer","icon","label","kbdContainer","refresh","li","link","currentLi","currentA","suggestion","index","divContainer","divInner","predictionText","originalText","matches","lastIndex","outerSpan","innerSpan","match","remainingText","divInner2","p2","prop"],"mappings":"qtBAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,6CAgBO,MAAMA,CAAmB,CAkE9B,YAAYC,EAAQ,CAhEpBC,EAAA,KAAAC,GACAD,EAAA,KAAAE,GACAF,EAAA,KAAAG,GACAH,EAAA,KAAAI,GACAJ,EAAA,KAAAK,GACAL,EAAA,KAAAM,GACAN,EAAA,KAAAO,GACAP,EAAA,KAAAQ,GACAR,EAAA,KAAAS,GACAT,EAAA,KAAAU,GACAV,EAAA,KAAAW,GACAX,EAAA,KAAAY,GACAZ,EAAA,KAAAa,EAAkB,CAAE,GACpBb,EAAA,KAAAc,EAAqB,IACrBd,EAAA,KAAAe,GACAf,EAAA,KAAAgB,GACAhB,EAAA,KAAAiB,EAAkB,CAEhB,QAAS,GACT,UAAW,0CACX,eACE,uEACF,KAAM,kPACN,MACE,0JACF,cAAe,gDACf,WACE,wGACF,OACE,kHACF,SACE,kHACF,WAAY,2BACZ,GAAI,8LACJ,GAAI,uGACJ,WAAY,gBACZ,KAAM,oCACN,aAAc,aACd,iBAAkB,uBAClB,WAAY,oBACZ,aAAc,YACd,WAAY,4CACZ,aAAc,iBACd,UAAW,WACZ,GACDjB,EAAA,KAAAkB,EAAwB,CAEtB,MAAO,GACP,oBAAqB,CAAC,IAAI,EAC1B,SAAU,QACV,OAAQ,IACT,GAsdDC,EAAA,+BAA0B,KAAK,UAAU,SAAY,CACnD,GAAI,CAACC,EAAA,KAAKb,IAAiB,CAACa,EAAA,KAAKb,GAAc,MAAO,CACpD,KAAK,OAAQ,EACTa,EAAA,KAAKb,IACPa,EAAA,KAAKb,GAAc,aAAa,gBAAiB,OAAO,EAC1D,MACN,CAEIa,EAAA,KAAKd,GAAS,MAAQc,EAAA,KAAKb,GAAc,MAEzC,GAAI,CACF,KAAM,CAAE,YAAAc,CAAa,EAEnB,MAAM,OAAO,KAAK,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EAAO,CACd,QAAQ,MAAM,gCAAiCA,CAAK,EAEpDF,EAAA,KAAKJ,GAAL,UAAsBM,EAC5B,QAAc,CAER,KAAK,OAAO,EAAI,CACtB,CACA,CAME,eAAgB,CACd,GAAI,CAEFF,EAAA,KAAKd,GAAS,aACZ,IAAI,OAAO,KAAK,OAAO,wBAC1B,OAAQgB,EAAO,CACd,QAAQ,MAAM,gCAAiCA,CAAK,EAEpDF,EAAA,KAAKJ,GAAL,UAAsBM,EAC5B,CACA,CAEE,OAAQ,CACN,KAAK,OAAO,EAAI,CACpB,CAEE,SAAU,CAEJF,EAAA,KAAKb,IACPa,EAAA,KAAKb,GAAc,oBACjB,QACA,KAAK,uBACN,EAGCa,EAAA,KAAKlB,IAAUkB,EAAA,KAAKZ,IACtBY,EAAA,KAAKlB,GAAO,YAAYkB,EAAA,KAAKZ,GAAW,aAAa,EAGvD,UAAWqE,KAAQ,KACb,OAAO,OAAO,KAAMA,CAAI,IAC1B,KAAKA,CAAI,EAAI,MAGjB,QAAQ,IAAI,qCAAqC,CACrD,CACA,CA5uBE5E,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YACAC,EAAA,YA6BAC,EAAA"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "places-autocomplete-js",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "1.0.
|
|
5
|
+
"version": "1.0.5",
|
|
6
6
|
"description": "A flexible and customisable vanilla JavaScript library leveraging the Google Maps Places (New) Autocomplete API. This library provides a user-friendly way to search for and retrieve detailed address information in any web application.",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"place-autocomplete",
|
|
@@ -50,11 +50,11 @@
|
|
|
50
50
|
"lint": "eslint src/**/*.js"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@tailwindcss/postcss": "^4.1.
|
|
54
|
-
"@tailwindcss/vite": "^4.1.
|
|
55
|
-
"eslint": "^9.
|
|
56
|
-
"postcss": "^8.5.
|
|
57
|
-
"tailwindcss": "^4.1.
|
|
53
|
+
"@tailwindcss/postcss": "^4.1.8",
|
|
54
|
+
"@tailwindcss/vite": "^4.1.8",
|
|
55
|
+
"eslint": "^9.28.0",
|
|
56
|
+
"postcss": "^8.5.4",
|
|
57
|
+
"tailwindcss": "^4.1.8",
|
|
58
58
|
"vite": "^6.3.5",
|
|
59
59
|
"dotenv": "^16.5.0"
|
|
60
60
|
},
|