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