@f-ewald/components 1.46.1 → 1.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/custom-elements.json +4520 -2463
- package/dist/address-autocomplete.d.ts +9 -44
- package/dist/address-autocomplete.d.ts.map +1 -1
- package/dist/address-autocomplete.js +16 -597
- package/dist/address-autocomplete.js.map +1 -1
- package/dist/app-shell.d.ts.map +1 -1
- package/dist/app-shell.js +8 -5
- package/dist/app-shell.js.map +1 -1
- package/dist/autocomplete-base.d.ts +79 -0
- package/dist/autocomplete-base.d.ts.map +1 -0
- package/dist/autocomplete-base.js +679 -0
- package/dist/autocomplete-base.js.map +1 -0
- package/dist/autocomplete-input.d.ts +9 -44
- package/dist/autocomplete-input.d.ts.map +1 -1
- package/dist/autocomplete-input.js +18 -647
- package/dist/autocomplete-input.js.map +1 -1
- package/dist/calendar-month.d.ts +3 -2
- package/dist/calendar-month.d.ts.map +1 -1
- package/dist/calendar-month.js +5 -3
- package/dist/calendar-month.js.map +1 -1
- package/dist/calendar-timeline-base.d.ts +3 -2
- package/dist/calendar-timeline-base.d.ts.map +1 -1
- package/dist/calendar-timeline-base.js +5 -3
- package/dist/calendar-timeline-base.js.map +1 -1
- package/dist/drop-zone.d.ts +78 -0
- package/dist/drop-zone.d.ts.map +1 -0
- package/dist/drop-zone.js +479 -0
- package/dist/drop-zone.js.map +1 -0
- package/dist/icons.d.ts +2 -0
- package/dist/icons.d.ts.map +1 -1
- package/dist/icons.js +2 -0
- package/dist/icons.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.js +13 -10
- package/dist/mcp-server.js.map +1 -1
- package/dist/utils/calendar.d.ts +5 -0
- package/dist/utils/calendar.d.ts.map +1 -1
- package/dist/utils/calendar.js +17 -0
- package/dist/utils/calendar.js.map +1 -1
- package/docs/address-autocomplete.md +7 -7
- package/docs/autocomplete-input.md +5 -5
- package/docs/drop-zone.md +87 -0
- package/docs/icons.md +1 -0
- package/llms.txt +42 -2
- package/package.json +1 -1
|
@@ -4,13 +4,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { iconX } from "./icons.js";
|
|
7
|
+
import { customElement, property } from "lit/decorators.js";
|
|
8
|
+
import { AutocompleteBase, autocompleteStyles } from "./autocomplete-base.js";
|
|
10
9
|
import { tokens } from "./tokens.js";
|
|
11
|
-
import { formFieldControl, } from "./utils/form-field-control.js";
|
|
12
|
-
import { submitWithDefaultButton } from "./utils/form.js";
|
|
13
|
-
let instanceCount = 0;
|
|
14
10
|
/**
|
|
15
11
|
* Form-associated text input with a suggestion dropdown. Works as a
|
|
16
12
|
* drop-in replacement for a plain `<input name="address">`: consumers keep
|
|
@@ -32,19 +28,9 @@ let instanceCount = 0;
|
|
|
32
28
|
* @fires address-select - A suggestion was picked; detail: AddressSuggestion.
|
|
33
29
|
* @fires input - Native-compatible input event fired while editing or clearing.
|
|
34
30
|
*/
|
|
35
|
-
let AddressAutocomplete = class AddressAutocomplete extends
|
|
31
|
+
let AddressAutocomplete = class AddressAutocomplete extends AutocompleteBase {
|
|
36
32
|
constructor() {
|
|
37
33
|
super(...arguments);
|
|
38
|
-
/** Current input value; also the form-associated value submitted with the form. */
|
|
39
|
-
this.value = "";
|
|
40
|
-
/** Placeholder text shown when the input is empty. */
|
|
41
|
-
this.placeholder = "";
|
|
42
|
-
/** Marks the input as required for native form validation. */
|
|
43
|
-
this.required = false;
|
|
44
|
-
/** Disables the input and closes its suggestion popup. */
|
|
45
|
-
this.disabled = false;
|
|
46
|
-
/** Shows an in-field clear action while the control has a value. */
|
|
47
|
-
this.clearable = false;
|
|
48
34
|
/** Mapbox `types` param, e.g. "address" or "address,poi". */
|
|
49
35
|
this.types = "address";
|
|
50
36
|
/** Geocoding endpoint URL. Defaults to the Mapbox Geocoding v6 forward URL. */
|
|
@@ -55,368 +41,27 @@ let AddressAutocomplete = class AddressAutocomplete extends LitElement {
|
|
|
55
41
|
this.bbox = "";
|
|
56
42
|
/** Optional proximity bias, comma-separated `lng,lat`. */
|
|
57
43
|
this.proximity = "";
|
|
58
|
-
/** Debounce delay (ms) before firing a geocode request after typing. */
|
|
59
|
-
this.debounce = 300;
|
|
60
|
-
/** Minimum query length before suggestions are fetched. */
|
|
61
|
-
this.minLength = 3;
|
|
62
44
|
/**
|
|
63
45
|
* Fixed candidate list to filter locally instead of fetching from
|
|
64
46
|
* `endpoint`. When set (non-null), no network request is ever made —
|
|
65
47
|
* this takes priority over the API mode.
|
|
66
48
|
*/
|
|
67
49
|
this.suggestions = null;
|
|
68
|
-
this.
|
|
69
|
-
this.
|
|
70
|
-
this._activeIndex = -1;
|
|
71
|
-
this._formDisabled = false;
|
|
72
|
-
this._formFieldConfig = null;
|
|
73
|
-
this.#internals = this.attachInternals();
|
|
74
|
-
this.#lastPicked = null;
|
|
75
|
-
this.#debounceTimer = null;
|
|
76
|
-
this.#abortController = null;
|
|
77
|
-
this.#isComposing = false;
|
|
78
|
-
this.#compositionJustEnded = false;
|
|
79
|
-
this.#compositionEndTimer = null;
|
|
80
|
-
this.#inputId = `address-autocomplete-field-${++instanceCount}`;
|
|
81
|
-
this.#listboxId = `address-autocomplete-listbox-${instanceCount}`;
|
|
82
|
-
}
|
|
83
|
-
static { this.formAssociated = true; }
|
|
84
|
-
static { this.styles = [
|
|
85
|
-
tokens,
|
|
86
|
-
css `
|
|
87
|
-
:host {
|
|
88
|
-
display: block;
|
|
89
|
-
position: relative;
|
|
90
|
-
}
|
|
91
|
-
.field-shell {
|
|
92
|
-
position: relative;
|
|
93
|
-
}
|
|
94
|
-
input {
|
|
95
|
-
font-family: var(
|
|
96
|
-
--ui-font,
|
|
97
|
-
ui-sans-serif,
|
|
98
|
-
system-ui,
|
|
99
|
-
sans-serif,
|
|
100
|
-
"Apple Color Emoji",
|
|
101
|
-
"Segoe UI Emoji",
|
|
102
|
-
"Segoe UI Symbol",
|
|
103
|
-
"Noto Color Emoji"
|
|
104
|
-
);
|
|
105
|
-
font-size: var(--ui-font-size, 0.875rem);
|
|
106
|
-
line-height: var(--ui-line-height-tight, 1.25);
|
|
107
|
-
color: var(--ui-text, #0f172a);
|
|
108
|
-
background: var(--ui-surface, #ffffff);
|
|
109
|
-
padding: 0.5rem 0.75rem;
|
|
110
|
-
border: var(--ui-border-width, 1px) solid var(--ui-border, #e2e8f0);
|
|
111
|
-
border-radius: var(--ui-radius-sm, 0.25rem);
|
|
112
|
-
width: 100%;
|
|
113
|
-
height: 2rem;
|
|
114
|
-
box-sizing: border-box;
|
|
115
|
-
}
|
|
116
|
-
.field-shell.clearable input {
|
|
117
|
-
padding-right: 2rem;
|
|
118
|
-
}
|
|
119
|
-
.clear-button {
|
|
120
|
-
position: absolute;
|
|
121
|
-
top: 0;
|
|
122
|
-
right: 0;
|
|
123
|
-
display: inline-flex;
|
|
124
|
-
align-items: center;
|
|
125
|
-
justify-content: center;
|
|
126
|
-
box-sizing: border-box;
|
|
127
|
-
width: 2rem;
|
|
128
|
-
height: 2rem;
|
|
129
|
-
/* Insets the hover/focus background by the input's 1px border so it
|
|
130
|
-
stays fully inside the field instead of painting over the border. */
|
|
131
|
-
padding: 1px;
|
|
132
|
-
background-clip: content-box;
|
|
133
|
-
border: 0;
|
|
134
|
-
border-radius: var(--ui-radius-sm, 0.25rem);
|
|
135
|
-
color: var(--ui-text-muted, #64748b);
|
|
136
|
-
background-color: transparent;
|
|
137
|
-
cursor: pointer;
|
|
138
|
-
line-height: 0;
|
|
139
|
-
}
|
|
140
|
-
.clear-button:hover {
|
|
141
|
-
color: var(--ui-text, #0f172a);
|
|
142
|
-
background-color: var(--ui-surface-muted, #f8fafc);
|
|
143
|
-
}
|
|
144
|
-
.clear-button:focus-visible {
|
|
145
|
-
outline: none;
|
|
146
|
-
box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
|
|
147
|
-
}
|
|
148
|
-
.floating-label {
|
|
149
|
-
position: absolute;
|
|
150
|
-
top: 50%;
|
|
151
|
-
left: 0.75rem;
|
|
152
|
-
right: 0.75rem;
|
|
153
|
-
z-index: 1;
|
|
154
|
-
display: flex;
|
|
155
|
-
align-items: baseline;
|
|
156
|
-
gap: 0.25rem;
|
|
157
|
-
overflow: hidden;
|
|
158
|
-
transform: translateY(-50%);
|
|
159
|
-
color: var(--ui-text-muted, #64748b);
|
|
160
|
-
font-family: var(
|
|
161
|
-
--ui-font,
|
|
162
|
-
ui-sans-serif,
|
|
163
|
-
system-ui,
|
|
164
|
-
sans-serif,
|
|
165
|
-
"Apple Color Emoji",
|
|
166
|
-
"Segoe UI Emoji",
|
|
167
|
-
"Segoe UI Symbol",
|
|
168
|
-
"Noto Color Emoji"
|
|
169
|
-
);
|
|
170
|
-
font-size: var(--ui-font-size-sm, 0.75rem);
|
|
171
|
-
font-weight: var(--ui-font-weight-regular, 400);
|
|
172
|
-
line-height: var(--ui-line-height-tight, 1.25);
|
|
173
|
-
white-space: nowrap;
|
|
174
|
-
text-overflow: ellipsis;
|
|
175
|
-
cursor: text;
|
|
176
|
-
transition:
|
|
177
|
-
top 150ms ease,
|
|
178
|
-
transform 150ms ease,
|
|
179
|
-
font-size 150ms ease;
|
|
180
|
-
}
|
|
181
|
-
.field-shell.clearable .floating-label {
|
|
182
|
-
right: 2rem;
|
|
183
|
-
}
|
|
184
|
-
.field-shell.floating input {
|
|
185
|
-
height: 3rem;
|
|
186
|
-
padding-top: 1.25rem;
|
|
187
|
-
padding-bottom: 0.25rem;
|
|
188
|
-
}
|
|
189
|
-
.field-shell.floating .clear-button {
|
|
190
|
-
top: 0.5rem;
|
|
191
|
-
}
|
|
192
|
-
.field-shell.floating.has-value .floating-label,
|
|
193
|
-
.field-shell.floating:focus-within .floating-label {
|
|
194
|
-
top: 0.25rem;
|
|
195
|
-
transform: none;
|
|
196
|
-
font-size: var(--ui-font-size-xs, 0.6875rem);
|
|
197
|
-
}
|
|
198
|
-
.field-shell.floating:not(.has-value):not(:focus-within) input::placeholder {
|
|
199
|
-
opacity: 0;
|
|
200
|
-
}
|
|
201
|
-
.field-shell.disabled .floating-label {
|
|
202
|
-
cursor: not-allowed;
|
|
203
|
-
opacity: 0.6;
|
|
204
|
-
}
|
|
205
|
-
.required-mark {
|
|
206
|
-
flex: 0 0 auto;
|
|
207
|
-
color: var(--ui-danger, #dc2626);
|
|
208
|
-
}
|
|
209
|
-
.sr-only {
|
|
210
|
-
position: absolute;
|
|
211
|
-
width: 1px;
|
|
212
|
-
height: 1px;
|
|
213
|
-
margin: -1px;
|
|
214
|
-
padding: 0;
|
|
215
|
-
overflow: hidden;
|
|
216
|
-
clip: rect(0 0 0 0);
|
|
217
|
-
clip-path: inset(50%);
|
|
218
|
-
white-space: nowrap;
|
|
219
|
-
border: 0;
|
|
220
|
-
}
|
|
221
|
-
input:disabled {
|
|
222
|
-
cursor: not-allowed;
|
|
223
|
-
opacity: 0.6;
|
|
224
|
-
}
|
|
225
|
-
input:focus-visible {
|
|
226
|
-
outline: none;
|
|
227
|
-
border-color: var(--ui-primary, #4f46e5);
|
|
228
|
-
box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
|
|
229
|
-
}
|
|
230
|
-
.suggestions {
|
|
231
|
-
position: absolute;
|
|
232
|
-
top: 100%;
|
|
233
|
-
left: 0;
|
|
234
|
-
right: 0;
|
|
235
|
-
z-index: 10;
|
|
236
|
-
max-height: 40vh;
|
|
237
|
-
overflow-y: auto;
|
|
238
|
-
margin: 0.25rem 0 0;
|
|
239
|
-
padding: 0.25rem 0;
|
|
240
|
-
list-style: none;
|
|
241
|
-
background: var(--ui-surface, #ffffff);
|
|
242
|
-
border: var(--ui-border-width, 1px) solid var(--ui-border, #e2e8f0);
|
|
243
|
-
border-radius: var(--ui-radius-sm, 0.25rem);
|
|
244
|
-
box-shadow: var(--ui-shadow, 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1));
|
|
245
|
-
}
|
|
246
|
-
.suggestion {
|
|
247
|
-
padding: 0.5rem 0.75rem;
|
|
248
|
-
font-size: var(--ui-font-size-sm, 0.75rem);
|
|
249
|
-
cursor: pointer;
|
|
250
|
-
}
|
|
251
|
-
.suggestion.active,
|
|
252
|
-
.suggestion:hover {
|
|
253
|
-
background: var(--ui-surface-muted, #f8fafc);
|
|
254
|
-
}
|
|
255
|
-
.no-suggestions {
|
|
256
|
-
padding: 0.5rem 0.75rem;
|
|
257
|
-
color: var(--ui-text-muted, #64748b);
|
|
258
|
-
font-size: var(--ui-font-size-sm, 0.75rem);
|
|
259
|
-
font-style: italic;
|
|
260
|
-
}
|
|
261
|
-
@media (forced-colors: active) {
|
|
262
|
-
input:focus-visible {
|
|
263
|
-
outline: 2px solid CanvasText;
|
|
264
|
-
outline-offset: 2px;
|
|
265
|
-
box-shadow: none;
|
|
266
|
-
}
|
|
267
|
-
input:disabled {
|
|
268
|
-
color: GrayText;
|
|
269
|
-
opacity: 1;
|
|
270
|
-
}
|
|
271
|
-
.clear-button:focus-visible {
|
|
272
|
-
outline: 2px solid CanvasText;
|
|
273
|
-
outline-offset: -2px;
|
|
274
|
-
box-shadow: none;
|
|
275
|
-
}
|
|
276
|
-
.field-shell.disabled .floating-label {
|
|
277
|
-
color: GrayText;
|
|
278
|
-
opacity: 1;
|
|
279
|
-
}
|
|
280
|
-
.suggestion.active,
|
|
281
|
-
.suggestion:hover {
|
|
282
|
-
color: HighlightText;
|
|
283
|
-
background: Highlight;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
@media (prefers-reduced-motion: reduce) {
|
|
287
|
-
.floating-label {
|
|
288
|
-
transition: none;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
`,
|
|
292
|
-
]; }
|
|
293
|
-
#internals;
|
|
294
|
-
#lastPicked;
|
|
295
|
-
#debounceTimer;
|
|
296
|
-
#abortController;
|
|
297
|
-
#isComposing;
|
|
298
|
-
#compositionJustEnded;
|
|
299
|
-
#compositionEndTimer;
|
|
300
|
-
#inputId;
|
|
301
|
-
#listboxId;
|
|
302
|
-
/** Whether the host or an ancestor fieldset currently disables the control. */
|
|
303
|
-
get #isDisabled() {
|
|
304
|
-
return this.disabled || this._formDisabled;
|
|
50
|
+
this.listboxLabel = "Address suggestions";
|
|
51
|
+
this.clearLabel = "Clear address";
|
|
305
52
|
}
|
|
53
|
+
static { this.styles = [tokens, autocompleteStyles]; }
|
|
306
54
|
/** Last-picked suggestion, or null once the input diverges from it. */
|
|
307
55
|
get selectedSuggestion() {
|
|
308
|
-
|
|
309
|
-
return this.#lastPicked;
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Applies or clears label configuration supplied by a wrapping `form-field`.
|
|
314
|
-
* @private
|
|
315
|
-
*/
|
|
316
|
-
[formFieldControl](config) {
|
|
317
|
-
this._formFieldConfig = config;
|
|
318
|
-
}
|
|
319
|
-
willUpdate(changed) {
|
|
320
|
-
if (changed.has("disabled") && this.#isDisabled) {
|
|
321
|
-
if (this.#debounceTimer)
|
|
322
|
-
clearTimeout(this.#debounceTimer);
|
|
323
|
-
this.#resetComposition();
|
|
324
|
-
this.#abortController?.abort();
|
|
325
|
-
this._open = false;
|
|
326
|
-
this._activeIndex = -1;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
updated(changed) {
|
|
330
|
-
if (changed.has("value"))
|
|
331
|
-
this.#internals.setFormValue(this.value);
|
|
332
|
-
}
|
|
333
|
-
disconnectedCallback() {
|
|
334
|
-
super.disconnectedCallback();
|
|
335
|
-
if (this.#debounceTimer)
|
|
336
|
-
clearTimeout(this.#debounceTimer);
|
|
337
|
-
this.#resetComposition();
|
|
338
|
-
this.#abortController?.abort();
|
|
339
|
-
}
|
|
340
|
-
/** Resets to empty on `form.reset()`, per the form-associated custom element contract. */
|
|
341
|
-
formResetCallback() {
|
|
342
|
-
this.value = "";
|
|
343
|
-
this._suggestions = [];
|
|
344
|
-
this._open = false;
|
|
345
|
-
this.#lastPicked = null;
|
|
346
|
-
}
|
|
347
|
-
/** Mirrors ancestor fieldset disabled state onto the native input. */
|
|
348
|
-
formDisabledCallback(disabled) {
|
|
349
|
-
this._formDisabled = disabled;
|
|
350
|
-
if (!disabled)
|
|
351
|
-
return;
|
|
352
|
-
if (this.#debounceTimer)
|
|
353
|
-
clearTimeout(this.#debounceTimer);
|
|
354
|
-
this.#resetComposition();
|
|
355
|
-
this.#abortController?.abort();
|
|
356
|
-
this._open = false;
|
|
357
|
-
this._activeIndex = -1;
|
|
358
|
-
}
|
|
359
|
-
onInput(e) {
|
|
360
|
-
if (this.#isDisabled)
|
|
361
|
-
return;
|
|
362
|
-
this.value = e.target.value;
|
|
363
|
-
this.#lastPicked = null;
|
|
364
|
-
this.#scheduleFetch(this.value);
|
|
365
|
-
}
|
|
366
|
-
#scheduleFetch(query) {
|
|
367
|
-
if (this.#isDisabled)
|
|
368
|
-
return;
|
|
369
|
-
if (this.#debounceTimer)
|
|
370
|
-
clearTimeout(this.#debounceTimer);
|
|
371
|
-
if (query.trim().length < this.minLength) {
|
|
372
|
-
this._suggestions = [];
|
|
373
|
-
this._open = false;
|
|
374
|
-
this._activeIndex = -1;
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
if (this.suggestions) {
|
|
378
|
-
// Local mode: filtering is synchronous and cheap, but keep the same
|
|
379
|
-
// debounce as the API mode so the UX doesn't shift between sources.
|
|
380
|
-
this.#debounceTimer = setTimeout(() => this.#filterLocalSuggestions(query), this.debounce);
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
this.#debounceTimer = setTimeout(() => void this.#fetchSuggestions(query), this.debounce);
|
|
56
|
+
return this.lastPicked && this.lastPicked.address === this.value ? this.lastPicked : null;
|
|
384
57
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
const needle = query.trim().toLowerCase();
|
|
388
|
-
this._suggestions = (this.suggestions ?? [])
|
|
389
|
-
.filter((s) => s.address.toLowerCase().includes(needle))
|
|
390
|
-
.slice(0, 5);
|
|
391
|
-
this._activeIndex = -1;
|
|
392
|
-
this._open = !this.#isDisabled;
|
|
58
|
+
localItems() {
|
|
59
|
+
return this.suggestions;
|
|
393
60
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
this.#abortController?.abort();
|
|
397
|
-
const controller = new AbortController();
|
|
398
|
-
this.#abortController = controller;
|
|
399
|
-
try {
|
|
400
|
-
const res = await fetch(this.#buildUrl(query), { signal: controller.signal });
|
|
401
|
-
if (!res.ok)
|
|
402
|
-
throw new Error(`geocode request failed: ${res.status}`);
|
|
403
|
-
const body = (await res.json());
|
|
404
|
-
if (this.#isDisabled)
|
|
405
|
-
return;
|
|
406
|
-
this._suggestions = parseFeatures(body.features ?? []);
|
|
407
|
-
this._activeIndex = -1;
|
|
408
|
-
this._open = true;
|
|
409
|
-
}
|
|
410
|
-
catch {
|
|
411
|
-
// Aborted (superseded by newer keystroke) or a network failure while
|
|
412
|
-
// typing — fail silently and just close the list.
|
|
413
|
-
if (!controller.signal.aborted) {
|
|
414
|
-
this._suggestions = [];
|
|
415
|
-
this._open = false;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
61
|
+
view(suggestion) {
|
|
62
|
+
return { text: suggestion.address };
|
|
418
63
|
}
|
|
419
|
-
|
|
64
|
+
requestUrl(query) {
|
|
420
65
|
const params = new URLSearchParams({
|
|
421
66
|
q: query,
|
|
422
67
|
access_token: this.accessToken,
|
|
@@ -430,215 +75,13 @@ let AddressAutocomplete = class AddressAutocomplete extends LitElement {
|
|
|
430
75
|
params.set("proximity", this.proximity);
|
|
431
76
|
return `${this.endpoint}?${params.toString()}`;
|
|
432
77
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return;
|
|
436
|
-
if (e.isComposing || e.keyCode === 229 || this.#isComposing || this.#compositionJustEnded) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
if (e.key === "ArrowDown")
|
|
440
|
-
this.#moveActive(1, e);
|
|
441
|
-
else if (e.key === "ArrowUp")
|
|
442
|
-
this.#moveActive(-1, e);
|
|
443
|
-
else if (e.key === "Enter")
|
|
444
|
-
this.#handleEnter(e);
|
|
445
|
-
else if (e.key === "Escape")
|
|
446
|
-
this.#handleEscape(e);
|
|
447
|
-
}
|
|
448
|
-
#moveActive(delta, e) {
|
|
449
|
-
if (!this._open || this._suggestions.length === 0)
|
|
450
|
-
return;
|
|
451
|
-
e.preventDefault();
|
|
452
|
-
const n = this._suggestions.length;
|
|
453
|
-
this._activeIndex = (this._activeIndex + delta + n) % n;
|
|
454
|
-
}
|
|
455
|
-
#handleEnter(e) {
|
|
456
|
-
const pick = this._suggestions[this._activeIndex] ?? this._suggestions[0];
|
|
457
|
-
if (this._open && pick) {
|
|
458
|
-
e.preventDefault();
|
|
459
|
-
this.#selectSuggestion(pick);
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
if (this.#internals.form) {
|
|
463
|
-
const form = this.#internals.form;
|
|
464
|
-
window.setTimeout(() => {
|
|
465
|
-
if (!e.defaultPrevented && form.isConnected)
|
|
466
|
-
submitWithDefaultButton(form);
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
#handleEscape(e) {
|
|
471
|
-
if (!this._open)
|
|
472
|
-
return;
|
|
473
|
-
e.preventDefault();
|
|
474
|
-
this._open = false;
|
|
475
|
-
}
|
|
476
|
-
onBlur() {
|
|
477
|
-
this._open = false;
|
|
478
|
-
}
|
|
479
|
-
onCompositionStart() {
|
|
480
|
-
if (this.#compositionEndTimer)
|
|
481
|
-
clearTimeout(this.#compositionEndTimer);
|
|
482
|
-
this.#compositionEndTimer = null;
|
|
483
|
-
this.#compositionJustEnded = false;
|
|
484
|
-
this.#isComposing = true;
|
|
485
|
-
}
|
|
486
|
-
onCompositionEnd() {
|
|
487
|
-
this.#isComposing = false;
|
|
488
|
-
this.#compositionJustEnded = true;
|
|
489
|
-
if (this.#compositionEndTimer)
|
|
490
|
-
clearTimeout(this.#compositionEndTimer);
|
|
491
|
-
this.#compositionEndTimer = setTimeout(() => {
|
|
492
|
-
this.#compositionJustEnded = false;
|
|
493
|
-
this.#compositionEndTimer = null;
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
/** Clears composition state when the control can no longer receive keys. */
|
|
497
|
-
#resetComposition() {
|
|
498
|
-
if (this.#compositionEndTimer)
|
|
499
|
-
clearTimeout(this.#compositionEndTimer);
|
|
500
|
-
this.#compositionEndTimer = null;
|
|
501
|
-
this.#isComposing = false;
|
|
502
|
-
this.#compositionJustEnded = false;
|
|
503
|
-
}
|
|
504
|
-
#selectSuggestion(s) {
|
|
505
|
-
this.value = s.address;
|
|
506
|
-
this.#lastPicked = s;
|
|
507
|
-
this._open = false;
|
|
508
|
-
this._suggestions = [];
|
|
509
|
-
this.dispatchEvent(new CustomEvent("address-select", { detail: s, bubbles: true, composed: true }));
|
|
78
|
+
parseItems(body) {
|
|
79
|
+
return parseFeatures(body.features ?? []);
|
|
510
80
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
if (this.#isDisabled || !this.value)
|
|
514
|
-
return;
|
|
515
|
-
if (this.#debounceTimer)
|
|
516
|
-
clearTimeout(this.#debounceTimer);
|
|
517
|
-
this.#debounceTimer = null;
|
|
518
|
-
this.#abortController?.abort();
|
|
519
|
-
this.#abortController = null;
|
|
520
|
-
this.#resetComposition();
|
|
521
|
-
this.value = "";
|
|
522
|
-
this.#lastPicked = null;
|
|
523
|
-
this._suggestions = [];
|
|
524
|
-
this._activeIndex = -1;
|
|
525
|
-
this._open = false;
|
|
526
|
-
this.#internals.setFormValue("");
|
|
527
|
-
this.dispatchEvent(new InputEvent("input", {
|
|
528
|
-
bubbles: true,
|
|
529
|
-
composed: true,
|
|
530
|
-
inputType: "deleteContentBackward",
|
|
531
|
-
}));
|
|
532
|
-
this._input?.focus({ preventScroll: true });
|
|
533
|
-
}
|
|
534
|
-
/** Selects on mousedown (not click) so it wins over the input's blur, which closes the list. */
|
|
535
|
-
#onSuggestionMousedown(e, s) {
|
|
536
|
-
e.preventDefault();
|
|
537
|
-
this.#selectSuggestion(s);
|
|
538
|
-
}
|
|
539
|
-
renderSuggestions() {
|
|
540
|
-
if (!this._open || this.#isDisabled)
|
|
541
|
-
return nothing;
|
|
542
|
-
return html `
|
|
543
|
-
<ul id=${this.#listboxId} class="suggestions" role="listbox" aria-label="Address suggestions">
|
|
544
|
-
${this._suggestions.map((s, i) => html `
|
|
545
|
-
<li
|
|
546
|
-
id=${`${this.#listboxId}-option-${i}`}
|
|
547
|
-
role="option"
|
|
548
|
-
aria-selected=${i === this._activeIndex}
|
|
549
|
-
class="suggestion ${i === this._activeIndex ? "active" : ""}"
|
|
550
|
-
@mousedown=${(e) => this.#onSuggestionMousedown(e, s)}
|
|
551
|
-
>
|
|
552
|
-
${s.address}
|
|
553
|
-
</li>
|
|
554
|
-
`)}
|
|
555
|
-
${this._suggestions.length === 0
|
|
556
|
-
? html `<li class="no-suggestions" role="presentation">
|
|
557
|
-
<span role="status">No suggestions found</span>
|
|
558
|
-
</li>`
|
|
559
|
-
: nothing}
|
|
560
|
-
</ul>
|
|
561
|
-
`;
|
|
562
|
-
}
|
|
563
|
-
render() {
|
|
564
|
-
const activeDescendant = this._open && !this.#isDisabled && this._activeIndex >= 0
|
|
565
|
-
? `${this.#listboxId}-option-${this._activeIndex}`
|
|
566
|
-
: nothing;
|
|
567
|
-
const expanded = this._open && !this.#isDisabled;
|
|
568
|
-
const floating = Boolean(this._formFieldConfig?.floating) && Boolean(this._formFieldConfig?.label);
|
|
569
|
-
const showClear = this.clearable && Boolean(this.value) && !this.#isDisabled;
|
|
570
|
-
return html `
|
|
571
|
-
<div
|
|
572
|
-
class="field-shell ${this.clearable ? "clearable" : ""} ${floating
|
|
573
|
-
? "floating"
|
|
574
|
-
: ""} ${this.value ? "has-value" : ""} ${this.#isDisabled ? "disabled" : ""}"
|
|
575
|
-
>
|
|
576
|
-
${floating
|
|
577
|
-
? html `
|
|
578
|
-
<label class="floating-label" for=${this.#inputId}>
|
|
579
|
-
<span>${this._formFieldConfig.label}</span>
|
|
580
|
-
${this._formFieldConfig.required
|
|
581
|
-
? html `
|
|
582
|
-
<span class="required-mark" aria-hidden="true">*</span>
|
|
583
|
-
<span class="sr-only"> (required)</span>
|
|
584
|
-
`
|
|
585
|
-
: nothing}
|
|
586
|
-
</label>
|
|
587
|
-
`
|
|
588
|
-
: nothing}
|
|
589
|
-
<input
|
|
590
|
-
id=${this.#inputId}
|
|
591
|
-
type="text"
|
|
592
|
-
role="combobox"
|
|
593
|
-
aria-autocomplete="list"
|
|
594
|
-
aria-expanded=${expanded}
|
|
595
|
-
aria-controls=${this.#listboxId}
|
|
596
|
-
aria-activedescendant=${activeDescendant}
|
|
597
|
-
.value=${this.value}
|
|
598
|
-
placeholder=${this.placeholder}
|
|
599
|
-
?required=${this.required}
|
|
600
|
-
?disabled=${this.#isDisabled}
|
|
601
|
-
autocomplete="off"
|
|
602
|
-
@input=${this.onInput}
|
|
603
|
-
@compositionstart=${this.onCompositionStart}
|
|
604
|
-
@compositionend=${this.onCompositionEnd}
|
|
605
|
-
@keydown=${this.onKeydown}
|
|
606
|
-
@blur=${this.onBlur}
|
|
607
|
-
/>
|
|
608
|
-
${showClear
|
|
609
|
-
? html `
|
|
610
|
-
<button
|
|
611
|
-
type="button"
|
|
612
|
-
class="clear-button"
|
|
613
|
-
aria-label="Clear address"
|
|
614
|
-
title="Clear address"
|
|
615
|
-
@mousedown=${(event) => event.preventDefault()}
|
|
616
|
-
@click=${() => this.#clear()}
|
|
617
|
-
>
|
|
618
|
-
${iconX(18)}
|
|
619
|
-
</button>
|
|
620
|
-
`
|
|
621
|
-
: nothing}
|
|
622
|
-
${this.renderSuggestions()}
|
|
623
|
-
</div>
|
|
624
|
-
`;
|
|
81
|
+
onSelect(suggestion) {
|
|
82
|
+
this.dispatchEvent(new CustomEvent("address-select", { detail: suggestion, bubbles: true, composed: true }));
|
|
625
83
|
}
|
|
626
84
|
};
|
|
627
|
-
__decorate([
|
|
628
|
-
property()
|
|
629
|
-
], AddressAutocomplete.prototype, "value", void 0);
|
|
630
|
-
__decorate([
|
|
631
|
-
property()
|
|
632
|
-
], AddressAutocomplete.prototype, "placeholder", void 0);
|
|
633
|
-
__decorate([
|
|
634
|
-
property({ type: Boolean })
|
|
635
|
-
], AddressAutocomplete.prototype, "required", void 0);
|
|
636
|
-
__decorate([
|
|
637
|
-
property({ type: Boolean, reflect: true })
|
|
638
|
-
], AddressAutocomplete.prototype, "disabled", void 0);
|
|
639
|
-
__decorate([
|
|
640
|
-
property({ type: Boolean, reflect: true })
|
|
641
|
-
], AddressAutocomplete.prototype, "clearable", void 0);
|
|
642
85
|
__decorate([
|
|
643
86
|
property()
|
|
644
87
|
], AddressAutocomplete.prototype, "types", void 0);
|
|
@@ -654,33 +97,9 @@ __decorate([
|
|
|
654
97
|
__decorate([
|
|
655
98
|
property()
|
|
656
99
|
], AddressAutocomplete.prototype, "proximity", void 0);
|
|
657
|
-
__decorate([
|
|
658
|
-
property({ type: Number })
|
|
659
|
-
], AddressAutocomplete.prototype, "debounce", void 0);
|
|
660
|
-
__decorate([
|
|
661
|
-
property({ type: Number, attribute: "min-length" })
|
|
662
|
-
], AddressAutocomplete.prototype, "minLength", void 0);
|
|
663
100
|
__decorate([
|
|
664
101
|
property({ attribute: false })
|
|
665
102
|
], AddressAutocomplete.prototype, "suggestions", void 0);
|
|
666
|
-
__decorate([
|
|
667
|
-
state()
|
|
668
|
-
], AddressAutocomplete.prototype, "_suggestions", void 0);
|
|
669
|
-
__decorate([
|
|
670
|
-
state()
|
|
671
|
-
], AddressAutocomplete.prototype, "_open", void 0);
|
|
672
|
-
__decorate([
|
|
673
|
-
state()
|
|
674
|
-
], AddressAutocomplete.prototype, "_activeIndex", void 0);
|
|
675
|
-
__decorate([
|
|
676
|
-
state()
|
|
677
|
-
], AddressAutocomplete.prototype, "_formDisabled", void 0);
|
|
678
|
-
__decorate([
|
|
679
|
-
state()
|
|
680
|
-
], AddressAutocomplete.prototype, "_formFieldConfig", void 0);
|
|
681
|
-
__decorate([
|
|
682
|
-
query("input")
|
|
683
|
-
], AddressAutocomplete.prototype, "_input", void 0);
|
|
684
103
|
AddressAutocomplete = __decorate([
|
|
685
104
|
customElement("address-autocomplete")
|
|
686
105
|
], AddressAutocomplete);
|