@molecule/app-search-autocomplete-angular 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +429 -2
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +66 -0
- package/dist/index.js.map +1 -0
- package/dist/search-autocomplete.component.d.ts +238 -0
- package/dist/search-autocomplete.component.d.ts.map +1 -0
- package/dist/search-autocomplete.component.js +542 -0
- package/dist/search-autocomplete.component.js.map +1 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -4
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SearchAutocomplete component (React parity).
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { NgTemplateOutlet } from '@angular/common';
|
|
7
|
+
import { ChangeDetectorRef, Component, ElementRef, inject, signal, ViewChild, } from '@angular/core';
|
|
8
|
+
import { useTranslation } from '@molecule/app-angular';
|
|
9
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
10
|
+
import * as i0 from "@angular/core";
|
|
11
|
+
const _c0 = ["inputEl"];
|
|
12
|
+
const _forTrack0 = ($index, $item) => $item.id;
|
|
13
|
+
function SearchAutocomplete_Conditional_4_For_2_Conditional_2_Template(rf, ctx) { if (rf & 1) {
|
|
14
|
+
i0.ɵɵelementContainer(0, 6);
|
|
15
|
+
} if (rf & 2) {
|
|
16
|
+
const suggestion_r4 = i0.ɵɵnextContext().$implicit;
|
|
17
|
+
const ctx_r2 = i0.ɵɵnextContext(2);
|
|
18
|
+
i0.ɵɵproperty("ngTemplateOutlet", ctx_r2.asTemplate(suggestion_r4.label));
|
|
19
|
+
} }
|
|
20
|
+
function SearchAutocomplete_Conditional_4_For_2_Conditional_3_Template(rf, ctx) { if (rf & 1) {
|
|
21
|
+
i0.ɵɵtext(0);
|
|
22
|
+
} if (rf & 2) {
|
|
23
|
+
const suggestion_r4 = i0.ɵɵnextContext().$implicit;
|
|
24
|
+
const ctx_r2 = i0.ɵɵnextContext(2);
|
|
25
|
+
i0.ɵɵtextInterpolate(ctx_r2.textOf(suggestion_r4.label));
|
|
26
|
+
} }
|
|
27
|
+
function SearchAutocomplete_Conditional_4_For_2_Conditional_4_Conditional_1_Template(rf, ctx) { if (rf & 1) {
|
|
28
|
+
i0.ɵɵelementContainer(0, 6);
|
|
29
|
+
} if (rf & 2) {
|
|
30
|
+
const suggestion_r4 = i0.ɵɵnextContext(2).$implicit;
|
|
31
|
+
const ctx_r2 = i0.ɵɵnextContext(2);
|
|
32
|
+
i0.ɵɵproperty("ngTemplateOutlet", ctx_r2.asTemplate(suggestion_r4.meta));
|
|
33
|
+
} }
|
|
34
|
+
function SearchAutocomplete_Conditional_4_For_2_Conditional_4_Conditional_2_Template(rf, ctx) { if (rf & 1) {
|
|
35
|
+
i0.ɵɵtext(0);
|
|
36
|
+
} if (rf & 2) {
|
|
37
|
+
const suggestion_r4 = i0.ɵɵnextContext(2).$implicit;
|
|
38
|
+
const ctx_r2 = i0.ɵɵnextContext(2);
|
|
39
|
+
i0.ɵɵtextInterpolate(ctx_r2.textOf(suggestion_r4.meta));
|
|
40
|
+
} }
|
|
41
|
+
function SearchAutocomplete_Conditional_4_For_2_Conditional_4_Template(rf, ctx) { if (rf & 1) {
|
|
42
|
+
i0.ɵɵelementStart(0, "div");
|
|
43
|
+
i0.ɵɵconditionalCreate(1, SearchAutocomplete_Conditional_4_For_2_Conditional_4_Conditional_1_Template, 1, 1, "ng-container", 6)(2, SearchAutocomplete_Conditional_4_For_2_Conditional_4_Conditional_2_Template, 1, 1);
|
|
44
|
+
i0.ɵɵelementEnd();
|
|
45
|
+
} if (rf & 2) {
|
|
46
|
+
const suggestion_r4 = i0.ɵɵnextContext().$implicit;
|
|
47
|
+
const ctx_r2 = i0.ɵɵnextContext(2);
|
|
48
|
+
i0.ɵɵclassMap(ctx_r2.metaClasses());
|
|
49
|
+
i0.ɵɵadvance();
|
|
50
|
+
i0.ɵɵconditional(ctx_r2.isTemplate(suggestion_r4.meta) ? 1 : 2);
|
|
51
|
+
} }
|
|
52
|
+
function SearchAutocomplete_Conditional_4_For_2_Template(rf, ctx) { if (rf & 1) {
|
|
53
|
+
const _r1 = i0.ɵɵgetCurrentView();
|
|
54
|
+
i0.ɵɵelementStart(0, "li", 5);
|
|
55
|
+
i0.ɵɵlistener("mouseenter", function SearchAutocomplete_Conditional_4_For_2_Template_li_mouseenter_0_listener() { const $index_r2 = i0.ɵɵrestoreView(_r1).$index; const ctx_r2 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r2.onOptionEnter($index_r2)); })("mousedown", function SearchAutocomplete_Conditional_4_For_2_Template_li_mousedown_0_listener($event) { const suggestion_r4 = i0.ɵɵrestoreView(_r1).$implicit; const ctx_r2 = i0.ɵɵnextContext(2); return i0.ɵɵresetView(ctx_r2.onOptionDown($event, suggestion_r4)); });
|
|
56
|
+
i0.ɵɵelementStart(1, "div");
|
|
57
|
+
i0.ɵɵconditionalCreate(2, SearchAutocomplete_Conditional_4_For_2_Conditional_2_Template, 1, 1, "ng-container", 6)(3, SearchAutocomplete_Conditional_4_For_2_Conditional_3_Template, 1, 1);
|
|
58
|
+
i0.ɵɵelementEnd();
|
|
59
|
+
i0.ɵɵconditionalCreate(4, SearchAutocomplete_Conditional_4_For_2_Conditional_4_Template, 3, 3, "div", 7);
|
|
60
|
+
i0.ɵɵelementEnd();
|
|
61
|
+
} if (rf & 2) {
|
|
62
|
+
const suggestion_r4 = ctx.$implicit;
|
|
63
|
+
const $index_r2 = ctx.$index;
|
|
64
|
+
const ctx_r2 = i0.ɵɵnextContext(2);
|
|
65
|
+
i0.ɵɵclassMap(ctx_r2.optionClasses($index_r2));
|
|
66
|
+
i0.ɵɵattribute("id", ctx_r2.optionId($index_r2))("aria-selected", $index_r2 === ctx_r2.active() ? "true" : "false");
|
|
67
|
+
i0.ɵɵadvance();
|
|
68
|
+
i0.ɵɵclassMap(ctx_r2.labelClasses());
|
|
69
|
+
i0.ɵɵadvance();
|
|
70
|
+
i0.ɵɵconditional(ctx_r2.isTemplate(suggestion_r4.label) ? 2 : 3);
|
|
71
|
+
i0.ɵɵadvance(2);
|
|
72
|
+
i0.ɵɵconditional(suggestion_r4.meta ? 4 : -1);
|
|
73
|
+
} }
|
|
74
|
+
function SearchAutocomplete_Conditional_4_Template(rf, ctx) { if (rf & 1) {
|
|
75
|
+
i0.ɵɵelementStart(0, "ul", 3);
|
|
76
|
+
i0.ɵɵrepeaterCreate(1, SearchAutocomplete_Conditional_4_For_2_Template, 5, 8, "li", 4, _forTrack0);
|
|
77
|
+
i0.ɵɵelementEnd();
|
|
78
|
+
} if (rf & 2) {
|
|
79
|
+
const ctx_r2 = i0.ɵɵnextContext();
|
|
80
|
+
i0.ɵɵclassMap(ctx_r2.listClasses());
|
|
81
|
+
i0.ɵɵattribute("id", ctx_r2.listId)("style", ctx_r2.listStyle, i0.ɵɵsanitizeStyle);
|
|
82
|
+
i0.ɵɵadvance();
|
|
83
|
+
i0.ɵɵrepeater(ctx_r2.list());
|
|
84
|
+
} }
|
|
85
|
+
/** Counter backing the per-instance ids (React's `useId()`). */
|
|
86
|
+
let nextGeneratedId = 0;
|
|
87
|
+
/**
|
|
88
|
+
* Whether a node-valued suggestion field is a template (a `TemplateRef`)
|
|
89
|
+
* rather than plain text. Checked structurally — `TemplateRef` is a type-only
|
|
90
|
+
* import in the emitted metadata, so `instanceof` is not dependable across
|
|
91
|
+
* bundles.
|
|
92
|
+
*
|
|
93
|
+
* @param value - The field value.
|
|
94
|
+
* @returns True when it renders through `ngTemplateOutlet`.
|
|
95
|
+
*/
|
|
96
|
+
const isTemplate = (value) => typeof value === 'object' &&
|
|
97
|
+
value !== null &&
|
|
98
|
+
typeof value.createEmbeddedView === 'function';
|
|
99
|
+
/**
|
|
100
|
+
* Renders a text value the way React renders a node string.
|
|
101
|
+
*
|
|
102
|
+
* @param value - The field value.
|
|
103
|
+
* @returns The text, or `''` when there is nothing.
|
|
104
|
+
*/
|
|
105
|
+
const textOf = (value) => value === null || value === undefined ? '' : String(value);
|
|
106
|
+
/**
|
|
107
|
+
* The popover's inline style, exactly the declaration text React serializes
|
|
108
|
+
* for the same style object.
|
|
109
|
+
*/
|
|
110
|
+
const LIST_STYLE = 'position: absolute; top: 100%; left: 0px; right: 0px; z-index: 50; background: var(--color-surface, #fff); border: 1px solid rgba(0, 0, 0, 0.1); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); max-height: 320px; overflow-y: auto';
|
|
111
|
+
/**
|
|
112
|
+
* SearchAutocomplete component.
|
|
113
|
+
*
|
|
114
|
+
* Search input with a typeahead suggestions popover. The host IS React's root
|
|
115
|
+
* `<div>` (`div[mol-search-autocomplete]`), carrying React's class list; the
|
|
116
|
+
* input surface reproduces `@molecule/app-ui-angular`'s `Input` DOM (the
|
|
117
|
+
* wrapper, the inner row and the native `input`) so the combobox attributes
|
|
118
|
+
* land on the input itself, exactly where React spreads them.
|
|
119
|
+
*/
|
|
120
|
+
export class SearchAutocomplete {
|
|
121
|
+
/** Current input value. */
|
|
122
|
+
value = '';
|
|
123
|
+
/** Called whenever the input changes (React's `onChange`). */
|
|
124
|
+
onChange;
|
|
125
|
+
/** Async search function (React's `onSearch`). */
|
|
126
|
+
onSearch;
|
|
127
|
+
/** Caller-controlled suggestion list (React's `suggestions`). */
|
|
128
|
+
suggestions;
|
|
129
|
+
/** Called when the user picks a suggestion (React's `onSelect`). */
|
|
130
|
+
onSelect;
|
|
131
|
+
/** Placeholder (falls back to the translated `search.placeholder`). */
|
|
132
|
+
placeholder;
|
|
133
|
+
/**
|
|
134
|
+
* Accessible name for the input (React's `aria-label`); falls back to the
|
|
135
|
+
* translated `search.aria.label`.
|
|
136
|
+
*/
|
|
137
|
+
ariaLabel;
|
|
138
|
+
/** Debounce ms for `onSearch` (React's default 200). */
|
|
139
|
+
debounceMs;
|
|
140
|
+
/** Min chars before suggestions appear (React's default 1). */
|
|
141
|
+
minChars;
|
|
142
|
+
/** Extra classes on the wrapper. */
|
|
143
|
+
className;
|
|
144
|
+
/** The native input (React's controlled-value restore targets it). */
|
|
145
|
+
inputEl;
|
|
146
|
+
/**
|
|
147
|
+
* Reactive translation, read in the injection context. Its `t` reads the
|
|
148
|
+
* locale, so the view re-renders the text on a locale switch.
|
|
149
|
+
*/
|
|
150
|
+
i18n = useTranslation();
|
|
151
|
+
cdr = inject(ChangeDetectorRef);
|
|
152
|
+
host = inject((ElementRef));
|
|
153
|
+
/** The fetched suggestion rows (React's `useState<SuggestionItem[]>([])`). */
|
|
154
|
+
internal = signal([], /* @ts-ignore */
|
|
155
|
+
...(ngDevMode ? [{ debugName: "internal" }] : /* istanbul ignore next */ []));
|
|
156
|
+
/** Whether the popover was opened (React's `open` state). */
|
|
157
|
+
open = signal(false, /* @ts-ignore */
|
|
158
|
+
...(ngDevMode ? [{ debugName: "open" }] : /* istanbul ignore next */ []));
|
|
159
|
+
/** Index of the keyboard-highlighted option (-1 = none). */
|
|
160
|
+
activeIndex = signal(-1, /* @ts-ignore */
|
|
161
|
+
...(ngDevMode ? [{ debugName: "activeIndex" }] : /* istanbul ignore next */ []));
|
|
162
|
+
/** Monotonic id of the latest in-flight `onSearch` (the race guard). */
|
|
163
|
+
request = 0;
|
|
164
|
+
/** The pending debounce timer. */
|
|
165
|
+
timer;
|
|
166
|
+
/** The per-instance id base (React's `useId()`). */
|
|
167
|
+
baseId = `mol-search-autocomplete-${nextGeneratedId++}`;
|
|
168
|
+
/** The listbox id (React's `${baseId}-listbox`). */
|
|
169
|
+
listId = `${this.baseId}-listbox`;
|
|
170
|
+
/** The popover's inline style (React's style object serialized). */
|
|
171
|
+
listStyle = LIST_STYLE;
|
|
172
|
+
/**
|
|
173
|
+
* Starts the outside-mousedown listener and the initial search.
|
|
174
|
+
*/
|
|
175
|
+
ngOnInit() {
|
|
176
|
+
document.addEventListener('mousedown', this.onDoc);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* React's effects on `value`, `onSearch`, `debounceMs` and `minChars`: a
|
|
180
|
+
* change restarts the debounced search, and a new query resets the highlight.
|
|
181
|
+
*
|
|
182
|
+
* @param changes - The inputs that changed in this pass.
|
|
183
|
+
*/
|
|
184
|
+
ngOnChanges(changes) {
|
|
185
|
+
if ('value' in changes)
|
|
186
|
+
this.activeIndex.set(-1);
|
|
187
|
+
if ('value' in changes ||
|
|
188
|
+
'onSearch' in changes ||
|
|
189
|
+
'debounceMs' in changes ||
|
|
190
|
+
'minChars' in changes)
|
|
191
|
+
this.scheduleSearch();
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Removes the document listener and the pending debounce timer.
|
|
195
|
+
*/
|
|
196
|
+
ngOnDestroy() {
|
|
197
|
+
document.removeEventListener('mousedown', this.onDoc);
|
|
198
|
+
clearTimeout(this.timer);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* The current class map.
|
|
202
|
+
* @returns The UIClassMap.
|
|
203
|
+
*/
|
|
204
|
+
cm() {
|
|
205
|
+
return getClassMap();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The wrapper's class list (React's `cn(position('relative'), className)`).
|
|
209
|
+
* @returns The class string.
|
|
210
|
+
*/
|
|
211
|
+
classes() {
|
|
212
|
+
return this.cm().cn(this.cm().position('relative'), this.className);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The native input's class list (React's Input root classes).
|
|
216
|
+
* @returns The class string.
|
|
217
|
+
*/
|
|
218
|
+
inputClasses() {
|
|
219
|
+
return this.cm().input({ error: false, size: 'md', align: undefined });
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* The listbox's class list.
|
|
223
|
+
* @returns The class string.
|
|
224
|
+
*/
|
|
225
|
+
listClasses() {
|
|
226
|
+
return this.cm().cn(this.cm().stack(0), this.cm().sp('p', 1));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* A row's label class (React's `fontWeight('medium')`).
|
|
230
|
+
* @returns The class string.
|
|
231
|
+
*/
|
|
232
|
+
labelClasses() {
|
|
233
|
+
return this.cm().fontWeight('medium');
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* A row's secondary line class (React's `textSize('xs')`).
|
|
237
|
+
* @returns The class string.
|
|
238
|
+
*/
|
|
239
|
+
metaClasses() {
|
|
240
|
+
return this.cm().textSize('xs');
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* One option row's class list, exactly as React composes it.
|
|
244
|
+
* @param index - The row's position.
|
|
245
|
+
* @returns The class string.
|
|
246
|
+
*/
|
|
247
|
+
optionClasses(index) {
|
|
248
|
+
return this.cm().cn(this.cm().sp('px', 2), this.cm().sp('py', 2), this.cm().textSize('sm'), this.cm().cursorPointer, index === this.active() && this.cm().surfaceSecondary);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The native input's id (React's generated input id).
|
|
252
|
+
* @returns The id.
|
|
253
|
+
*/
|
|
254
|
+
get inputId() {
|
|
255
|
+
return `${this.baseId}-input`;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Stable DOM id for the option at `index` (referenced by aria-activedescendant).
|
|
259
|
+
* @param index - Option position.
|
|
260
|
+
* @returns The option id.
|
|
261
|
+
*/
|
|
262
|
+
optionId(index) {
|
|
263
|
+
return `${this.baseId}-option-${index}`;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* The placeholder React renders: the prop, else the translated default.
|
|
267
|
+
* @returns The placeholder text.
|
|
268
|
+
*/
|
|
269
|
+
placeholderText() {
|
|
270
|
+
return this.placeholder ?? this.i18n.t('search.placeholder', {}, { defaultValue: 'Search…' });
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The input's accessible name: the prop, else the translated default. A
|
|
274
|
+
* placeholder is not a label, so the name never rests on it.
|
|
275
|
+
* @returns The `aria-label` text.
|
|
276
|
+
*/
|
|
277
|
+
ariaLabelText() {
|
|
278
|
+
return this.ariaLabel ?? this.i18n.t('search.aria.label', undefined, { defaultValue: 'Search' });
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The suggestion list: the caller's controlled list wins over fetched results.
|
|
282
|
+
* @returns The rows to render.
|
|
283
|
+
*/
|
|
284
|
+
list() {
|
|
285
|
+
return this.suggestions ?? this.internal();
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* The popover is only visible with open + at least one suggestion.
|
|
289
|
+
* @returns Whether the listbox renders.
|
|
290
|
+
*/
|
|
291
|
+
isExpanded() {
|
|
292
|
+
return this.open() && this.list().length > 0;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* The highlight clamped to the current list: a list that shrinks below the
|
|
296
|
+
* highlighted index leaves the old option id pointing at nothing, so every
|
|
297
|
+
* read of the index (activedescendant, the highlighted option, Enter) sees
|
|
298
|
+
* -1 — nothing highlighted — instead of naming an option that is gone.
|
|
299
|
+
*
|
|
300
|
+
* @returns The active index, or -1 when nothing is highlighted.
|
|
301
|
+
*/
|
|
302
|
+
active() {
|
|
303
|
+
const index = this.activeIndex();
|
|
304
|
+
return index < this.list().length ? index : -1;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* The highlighted option's id, or null when nothing is highlighted.
|
|
308
|
+
* @returns The id, or null.
|
|
309
|
+
*/
|
|
310
|
+
activeDescendant() {
|
|
311
|
+
return this.isExpanded() && this.active() >= 0 ? this.optionId(this.active()) : null;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Whether a node value is a template rather than text.
|
|
315
|
+
* @param value - The field value.
|
|
316
|
+
* @returns True when it renders through `ngTemplateOutlet`.
|
|
317
|
+
*/
|
|
318
|
+
isTemplate(value) {
|
|
319
|
+
return isTemplate(value);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Narrows a node value to its template form.
|
|
323
|
+
* @param value - The field value.
|
|
324
|
+
* @returns The template.
|
|
325
|
+
*/
|
|
326
|
+
asTemplate(value) {
|
|
327
|
+
return value;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* A node value as text (React renders strings and numbers).
|
|
331
|
+
* @param value - The field value.
|
|
332
|
+
* @returns The text, or `''`.
|
|
333
|
+
*/
|
|
334
|
+
textOf(value) {
|
|
335
|
+
return textOf(value);
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* React's `debounceMs = 200` default.
|
|
339
|
+
* @returns The debounce delay in ms.
|
|
340
|
+
*/
|
|
341
|
+
debounce() {
|
|
342
|
+
return this.debounceMs ?? 200;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* React's `minChars = 1` default.
|
|
346
|
+
* @returns The minimum query length.
|
|
347
|
+
*/
|
|
348
|
+
threshold() {
|
|
349
|
+
return this.minChars ?? 1;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Runs React's debounced `onSearch` effect: a query shorter than `minChars`
|
|
353
|
+
* clears the results, and only the latest response may apply.
|
|
354
|
+
*/
|
|
355
|
+
scheduleSearch() {
|
|
356
|
+
clearTimeout(this.timer);
|
|
357
|
+
const search = this.onSearch;
|
|
358
|
+
const query = this.value;
|
|
359
|
+
if (!search || query.length < this.threshold()) {
|
|
360
|
+
this.internal.set([]);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
this.timer = setTimeout(() => {
|
|
364
|
+
const token = ++this.request;
|
|
365
|
+
Promise.resolve(search(query))
|
|
366
|
+
.then((result) => {
|
|
367
|
+
// Drop a response that lost the race: only the LATEST request may
|
|
368
|
+
// apply, so a slow earlier fetch can't clobber fresher results.
|
|
369
|
+
if (token === this.request)
|
|
370
|
+
this.internal.set(result);
|
|
371
|
+
this.cdr.markForCheck();
|
|
372
|
+
})
|
|
373
|
+
.catch((_error) => {
|
|
374
|
+
// Typeahead is best-effort — a failed suggestion fetch simply yields
|
|
375
|
+
// no suggestions for THIS query. Guard on the token so an
|
|
376
|
+
// out-of-order failure can't wipe a fresher successful result.
|
|
377
|
+
if (token === this.request)
|
|
378
|
+
this.internal.set([]);
|
|
379
|
+
this.cdr.markForCheck();
|
|
380
|
+
});
|
|
381
|
+
}, this.debounce());
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* React's text-input `onChange`: report the typed value, open the popover and
|
|
385
|
+
* restore the controlled value.
|
|
386
|
+
*
|
|
387
|
+
* @param event - The native input event.
|
|
388
|
+
*/
|
|
389
|
+
handleInput(event) {
|
|
390
|
+
this.onChange?.(event.target.value);
|
|
391
|
+
this.open.set(true);
|
|
392
|
+
const input = this.inputEl?.nativeElement;
|
|
393
|
+
if (input && input.value !== String(this.value))
|
|
394
|
+
input.value = String(this.value);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* React's `onFocus`: a query at least `minChars` long opens the popover.
|
|
398
|
+
*/
|
|
399
|
+
handleFocus() {
|
|
400
|
+
if (this.value.length >= this.threshold())
|
|
401
|
+
this.open.set(true);
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Full keyboard support for the combobox: ArrowDown/ArrowUp move the
|
|
405
|
+
* highlight (opening the popover if needed), Enter selects the highlighted
|
|
406
|
+
* option, Escape closes.
|
|
407
|
+
*
|
|
408
|
+
* @param event - The keyboard event from the input.
|
|
409
|
+
*/
|
|
410
|
+
handleKeydown(event) {
|
|
411
|
+
const current = this.list();
|
|
412
|
+
if (event.key === 'ArrowDown') {
|
|
413
|
+
event.preventDefault();
|
|
414
|
+
if (!this.open()) {
|
|
415
|
+
if (current.length > 0)
|
|
416
|
+
this.open.set(true);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (current.length === 0)
|
|
420
|
+
return;
|
|
421
|
+
this.activeIndex.update((index) => (index + 1) % current.length);
|
|
422
|
+
}
|
|
423
|
+
else if (event.key === 'ArrowUp') {
|
|
424
|
+
event.preventDefault();
|
|
425
|
+
if (!this.open()) {
|
|
426
|
+
if (current.length > 0)
|
|
427
|
+
this.open.set(true);
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
if (current.length === 0)
|
|
431
|
+
return;
|
|
432
|
+
this.activeIndex.update((index) => (index <= 0 ? current.length - 1 : index - 1));
|
|
433
|
+
}
|
|
434
|
+
else if (event.key === 'Enter') {
|
|
435
|
+
const index = this.active();
|
|
436
|
+
if (this.isExpanded() && index >= 0) {
|
|
437
|
+
event.preventDefault();
|
|
438
|
+
this.select(current[index]);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
else if (event.key === 'Escape') {
|
|
442
|
+
if (this.open()) {
|
|
443
|
+
event.preventDefault();
|
|
444
|
+
this.open.set(false);
|
|
445
|
+
this.activeIndex.set(-1);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Highlights a row on pointer hover.
|
|
451
|
+
* @param index - The row's position.
|
|
452
|
+
*/
|
|
453
|
+
onOptionEnter(index) {
|
|
454
|
+
this.activeIndex.set(index);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Selects a row on press: preventDefault keeps DOM focus on the input, which
|
|
458
|
+
* owns the combobox.
|
|
459
|
+
*
|
|
460
|
+
* @param event - The mousedown event.
|
|
461
|
+
* @param suggestion - The pressed suggestion.
|
|
462
|
+
*/
|
|
463
|
+
onOptionDown(event, suggestion) {
|
|
464
|
+
event.preventDefault();
|
|
465
|
+
this.select(suggestion);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* Commits a suggestion selection and closes the popover.
|
|
469
|
+
* @param item - The chosen suggestion.
|
|
470
|
+
*/
|
|
471
|
+
select(item) {
|
|
472
|
+
this.onSelect?.(item);
|
|
473
|
+
this.open.set(false);
|
|
474
|
+
this.activeIndex.set(-1);
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Closes the dropdown when a click occurs outside the wrapper element.
|
|
478
|
+
* @param event - The document mousedown.
|
|
479
|
+
*/
|
|
480
|
+
onDoc = (event) => {
|
|
481
|
+
if (!this.open())
|
|
482
|
+
return;
|
|
483
|
+
if (this.host.nativeElement.contains(event.target))
|
|
484
|
+
return;
|
|
485
|
+
this.open.set(false);
|
|
486
|
+
this.activeIndex.set(-1);
|
|
487
|
+
this.cdr.markForCheck();
|
|
488
|
+
};
|
|
489
|
+
static ɵfac = function SearchAutocomplete_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || SearchAutocomplete)(); };
|
|
490
|
+
static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: SearchAutocomplete, selectors: [["div", "mol-search-autocomplete", ""]], viewQuery: function SearchAutocomplete_Query(rf, ctx) { if (rf & 1) {
|
|
491
|
+
i0.ɵɵviewQuery(_c0, 5);
|
|
492
|
+
} if (rf & 2) {
|
|
493
|
+
let _t;
|
|
494
|
+
i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.inputEl = _t.first);
|
|
495
|
+
} }, hostVars: 2, hostBindings: function SearchAutocomplete_HostBindings(rf, ctx) { if (rf & 2) {
|
|
496
|
+
i0.ɵɵclassMap(ctx.classes());
|
|
497
|
+
} }, inputs: { value: "value", onChange: "onChange", onSearch: "onSearch", suggestions: "suggestions", onSelect: "onSelect", placeholder: "placeholder", ariaLabel: "ariaLabel", debounceMs: "debounceMs", minChars: "minChars", className: "className" }, features: [i0.ɵɵNgOnChangesFeature], decls: 5, vars: 14, consts: [["inputEl", ""], ["type", "search", "aria-invalid", "false", "role", "combobox", "aria-autocomplete", "list", 3, "input", "focusin", "keydown"], ["role", "listbox", 3, "class"], ["role", "listbox"], ["role", "option", "tabindex", "-1", "data-mol-id", "search-autocomplete-option", 3, "class"], ["role", "option", "tabindex", "-1", "data-mol-id", "search-autocomplete-option", 3, "mouseenter", "mousedown"], [3, "ngTemplateOutlet"], [3, "class"]], template: function SearchAutocomplete_Template(rf, ctx) { if (rf & 1) {
|
|
498
|
+
i0.ɵɵelementStart(0, "div")(1, "div")(2, "input", 1, 0);
|
|
499
|
+
i0.ɵɵlistener("input", function SearchAutocomplete_Template_input_input_2_listener($event) { return ctx.handleInput($event); })("focusin", function SearchAutocomplete_Template_input_focusin_2_listener() { return ctx.handleFocus(); })("keydown", function SearchAutocomplete_Template_input_keydown_2_listener($event) { return ctx.handleKeydown($event); });
|
|
500
|
+
i0.ɵɵelementEnd()()();
|
|
501
|
+
i0.ɵɵconditionalCreate(4, SearchAutocomplete_Conditional_4_Template, 3, 4, "ul", 2);
|
|
502
|
+
} if (rf & 2) {
|
|
503
|
+
i0.ɵɵclassMap(ctx.cm().inputWrapper);
|
|
504
|
+
i0.ɵɵadvance();
|
|
505
|
+
i0.ɵɵclassMap(ctx.cm().inputInner);
|
|
506
|
+
i0.ɵɵadvance();
|
|
507
|
+
i0.ɵɵclassMap(ctx.inputClasses());
|
|
508
|
+
i0.ɵɵattribute("id", ctx.inputId)("value", ctx.value)("placeholder", ctx.placeholderText())("aria-label", ctx.ariaLabelText())("aria-expanded", ctx.isExpanded() ? "true" : "false")("aria-controls", ctx.listId)("aria-activedescendant", ctx.activeDescendant());
|
|
509
|
+
i0.ɵɵadvance(2);
|
|
510
|
+
i0.ɵɵconditional(ctx.isExpanded() ? 4 : -1);
|
|
511
|
+
} }, dependencies: [NgTemplateOutlet], encapsulation: 2 });
|
|
512
|
+
}
|
|
513
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(SearchAutocomplete, [{
|
|
514
|
+
type: Component,
|
|
515
|
+
args: [{
|
|
516
|
+
selector: 'div[mol-search-autocomplete]',
|
|
517
|
+
standalone: true,
|
|
518
|
+
imports: [NgTemplateOutlet],
|
|
519
|
+
inputs: [
|
|
520
|
+
'value',
|
|
521
|
+
'onChange',
|
|
522
|
+
'onSearch',
|
|
523
|
+
'suggestions',
|
|
524
|
+
'onSelect',
|
|
525
|
+
'placeholder',
|
|
526
|
+
'ariaLabel',
|
|
527
|
+
'debounceMs',
|
|
528
|
+
'minChars',
|
|
529
|
+
'className',
|
|
530
|
+
],
|
|
531
|
+
host: {
|
|
532
|
+
'[class]': 'classes()',
|
|
533
|
+
},
|
|
534
|
+
// prettier-ignore
|
|
535
|
+
template: `<div [class]="cm().inputWrapper"><div [class]="cm().inputInner"><input #inputEl type="search" [attr.id]="inputId" [attr.value]="value" [attr.placeholder]="placeholderText()" aria-invalid="false" [class]="inputClasses()" role="combobox" [attr.aria-label]="ariaLabelText()" aria-autocomplete="list" [attr.aria-expanded]="isExpanded() ? 'true' : 'false'" [attr.aria-controls]="listId" [attr.aria-activedescendant]="activeDescendant()" (input)="handleInput($event)" (focusin)="handleFocus()" (keydown)="handleKeydown($event)" /></div></div>@if (isExpanded()) {<ul role="listbox" [attr.id]="listId" [class]="listClasses()" [attr.style]="listStyle">@for (suggestion of list(); track suggestion.id) {<li [attr.id]="optionId($index)" role="option" [attr.aria-selected]="$index === active() ? 'true' : 'false'" tabindex="-1" data-mol-id="search-autocomplete-option" (mouseenter)="onOptionEnter($index)" (mousedown)="onOptionDown($event, suggestion)" [class]="optionClasses($index)"><div [class]="labelClasses()">@if (isTemplate(suggestion.label)) {<ng-container [ngTemplateOutlet]="asTemplate(suggestion.label)"></ng-container>}@else {{{ textOf(suggestion.label) }}}</div>@if (suggestion.meta) {<div [class]="metaClasses()">@if (isTemplate(suggestion.meta)) {<ng-container [ngTemplateOutlet]="asTemplate(suggestion.meta)"></ng-container>}@else {{{ textOf(suggestion.meta) }}}</div>}</li>}</ul>}`,
|
|
536
|
+
}]
|
|
537
|
+
}], null, { inputEl: [{
|
|
538
|
+
type: ViewChild,
|
|
539
|
+
args: ['inputEl']
|
|
540
|
+
}] }); })();
|
|
541
|
+
(() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(SearchAutocomplete, { className: "SearchAutocomplete", filePath: "search-autocomplete.component.ts", lineNumber: 92 }); })();
|
|
542
|
+
//# sourceMappingURL=search-autocomplete.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search-autocomplete.component.js","sourceRoot":"","sources":["../src/search-autocomplete.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,UAAU,EACV,MAAM,EAIN,MAAM,EAGN,SAAS,GACV,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;;;;;IAkE8+B,2BAA+E;;;;IAAjE,yEAAiD;;;IAAwB,YAA8B;;;;IAA9B,wDAA8B;;;IAA8F,2BAA8E;;;;IAAhE,wEAAgD;;;IAAwB,YAA6B;;;;IAA7B,uDAA6B;;;IAAnL,2BAA6B;IAAkH,AAAlH,+HAAmC,sFAAsF;IAA8B,iBAAM;;;;IAArL,mCAAuB;IAAC,cAAuJ;IAAvJ,+DAAuJ;;;;IAAjqB,6BAAwR;IAA/E,AAArC,4NAAc,+BAAqB,KAAC,0NAAc,0CAAgC,KAAC;IAAiC,2BAA8B;IAAoH,AAApH,iHAAoC,wEAAuF;IAA+B,iBAAM;IAAA,wGAAuB;IAA2L,iBAAK;;;;;IAArb,8CAA+B;;IAAM,cAAwB;IAAxB,oCAAwB;IAAC,cAA0J;IAA1J,gEAA0J;IAAM,eAAkN;IAAlN,6CAAkN;;;IAAjzB,6BAAuF;IAAA,kGAAguB;IAAA,iBAAK;;;IAAtxB,mCAAuB;;IAA0B,cAAguB;IAAhuB,cAAA,aAAM,CAA0tB;;AA9Dh3C,gEAAgE;AAChE,IAAI,eAAe,GAAG,CAAC,CAAA;AAEvB;;;;;;;;GAQG;AACH,MAAM,UAAU,GAAG,CAAC,KAAc,EAAiC,EAAE,CACnE,O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Z,UAAU;oBACV,WAAW;iBACZ;gBACD,IAAI,EAAE;oBACJ,SAAS,EAAE,WAAW;iBACvB;gBACD,kBAAkB;gBAClB,QAAQ,EAAE,22CAA22C;aACt3C;;kBA2BE,SAAS;mBAAC,SAAS;;kFA1BT,kBAAkB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of `@molecule/app-search-autocomplete-angular` — the Angular
|
|
3
|
+
* counterpart of `@molecule/app-search-autocomplete-react`, the same props
|
|
4
|
+
* (React names) and the same DOM for the same input.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { TemplateRef } from '@angular/core';
|
|
9
|
+
/**
|
|
10
|
+
* A single suggestion entry returned by `onSearch` or passed via `suggestions`.
|
|
11
|
+
*/
|
|
12
|
+
export interface SuggestionItem<T = unknown> {
|
|
13
|
+
id: string;
|
|
14
|
+
/** Display label: text, or a template rendering any node (`TemplateRef`). */
|
|
15
|
+
label: string | TemplateRef<unknown>;
|
|
16
|
+
/** Optional secondary line / category: text, or a template rendering any node. */
|
|
17
|
+
meta?: string | TemplateRef<unknown>;
|
|
18
|
+
/** Original payload for the selection callback. */
|
|
19
|
+
data?: T;
|
|
20
|
+
}
|
|
21
|
+
/** Props accepted by the {@link SearchAutocomplete} component. */
|
|
22
|
+
export interface SearchAutocompleteProps<T = unknown> {
|
|
23
|
+
/** Current input value. */
|
|
24
|
+
value: string;
|
|
25
|
+
/** Called whenever the input changes (an input: pass a function, as React does). */
|
|
26
|
+
onChange: (value: string) => void;
|
|
27
|
+
/** Async search function — receives the query, returns suggestions. */
|
|
28
|
+
onSearch?: (query: string) => Promise<SuggestionItem<T>[]> | SuggestionItem<T>[];
|
|
29
|
+
/** Optional pre-computed suggestion list (when caller controls fetching). */
|
|
30
|
+
suggestions?: SuggestionItem<T>[];
|
|
31
|
+
/** Called when the user picks a suggestion. */
|
|
32
|
+
onSelect: (item: SuggestionItem<T>) => void;
|
|
33
|
+
/** Placeholder. */
|
|
34
|
+
placeholder?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Accessible name for the input, rendered as `aria-label`. Defaults to the
|
|
37
|
+
* translated `search.aria.label`: a placeholder is not a label, so an input
|
|
38
|
+
* named only by its placeholder (let alone an empty one) is nameless for
|
|
39
|
+
* assistive technology.
|
|
40
|
+
*/
|
|
41
|
+
ariaLabel?: string;
|
|
42
|
+
/** Debounce ms for `onSearch`. Defaults to 200. */
|
|
43
|
+
debounceMs?: number;
|
|
44
|
+
/** Min chars before suggestions appear. Defaults to 1. */
|
|
45
|
+
minChars?: number;
|
|
46
|
+
/** Extra classes on the wrapper. */
|
|
47
|
+
className?: string;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAEhD;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,EAAE,EAAE,MAAM,CAAA;IACV,6EAA6E;IAC7E,KAAK,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IACpC,kFAAkF;IAClF,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,CAAA;IACpC,mDAAmD;IACnD,IAAI,CAAC,EAAE,CAAC,CAAA;CACT;AAED,kEAAkE;AAClE,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO;IAClD,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,oFAAoF;IACpF,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,uEAAuE;IACvE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAA;IAChF,6EAA6E;IAC7E,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAA;IACjC,+CAA+C;IAC/C,QAAQ,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IAC3C,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types of `@molecule/app-search-autocomplete-angular` — the Angular
|
|
3
|
+
* counterpart of `@molecule/app-search-autocomplete-react`, the same props
|
|
4
|
+
* (React names) and the same DOM for the same input.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|