@magicx-eng/ai-autocomplete-angular 0.46.1 → 0.47.1
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 +79 -544
- package/REFERENCE.md +610 -0
- package/esm2020/lib/ai-autocomplete/ai-autocomplete.component.mjs +22 -5
- package/esm2020/lib/ai-autocomplete-dropdown/ai-autocomplete-dropdown.component.mjs +36 -8
- package/esm2020/lib/controller/ai-autocomplete.controller.mjs +51 -5
- package/esm2020/lib/internal/date-grid/date-grid.component.mjs +3 -3
- package/esm2020/lib/internal/location-field/location-field.component.mjs +370 -0
- package/esm2020/lib/internal/submit-button/submit-button.component.mjs +7 -3
- package/esm2020/lib/internal/suggestion-grid/suggestion-grid.component.mjs +7 -3
- package/esm2020/lib/internal/suggestion-item/suggestion-item.component.mjs +22 -6
- package/esm2020/lib/shared/types.mjs +1 -1
- package/esm2020/public-api.mjs +6 -2
- package/fesm2015/magicx-eng-ai-autocomplete-angular.mjs +520 -32
- package/fesm2015/magicx-eng-ai-autocomplete-angular.mjs.map +1 -1
- package/fesm2020/magicx-eng-ai-autocomplete-angular.mjs +511 -27
- package/fesm2020/magicx-eng-ai-autocomplete-angular.mjs.map +1 -1
- package/lib/ai-autocomplete/ai-autocomplete.component.d.ts +9 -1
- package/lib/ai-autocomplete/ai-autocomplete.component.d.ts.map +1 -1
- package/lib/ai-autocomplete-dropdown/ai-autocomplete-dropdown.component.d.ts +13 -1
- package/lib/ai-autocomplete-dropdown/ai-autocomplete-dropdown.component.d.ts.map +1 -1
- package/lib/controller/ai-autocomplete.controller.d.ts +29 -4
- package/lib/controller/ai-autocomplete.controller.d.ts.map +1 -1
- package/lib/internal/location-field/location-field.component.d.ts +98 -0
- package/lib/internal/location-field/location-field.component.d.ts.map +1 -0
- package/lib/internal/submit-button/submit-button.component.d.ts +3 -1
- package/lib/internal/submit-button/submit-button.component.d.ts.map +1 -1
- package/lib/internal/suggestion-grid/suggestion-grid.component.d.ts +3 -1
- package/lib/internal/suggestion-grid/suggestion-grid.component.d.ts.map +1 -1
- package/lib/internal/suggestion-item/suggestion-item.component.d.ts +8 -2
- package/lib/internal/suggestion-item/suggestion-item.component.d.ts.map +1 -1
- package/lib/shared/types.d.ts +19 -1
- package/lib/shared/types.d.ts.map +1 -1
- package/package.json +5 -2
- package/public-api.d.ts +4 -2
- package/public-api.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1,49 +1,75 @@
|
|
|
1
1
|
# @magicx-eng/ai-autocomplete-angular
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
AI Autocomplete for Angular: an input and dropdown for search boxes and other
|
|
4
|
+
text inputs. As the user types, it suggests the next detail to add and the
|
|
5
|
+
options for it. Built on `@magicx-eng/ai-autocomplete-vanilla`.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
## Quick start
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install @magicx-eng/ai-autocomplete-angular
|
|
11
|
+
```
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
- **Rich inline input (Tier 1)** — a single `contentEditable` surface: typed text, bold completed params, and inline pills share one editing context
|
|
11
|
-
- **Pill-based input** — non-editable inline pills for unfilled parameters, bold inline text for completed ones
|
|
12
|
-
- **Instant exact-match bolding** — typing the full text of an option immediately promotes it to a completed param (no debounced fetch wait). Works in the normal typing flow *and* while re-editing an existing completed param.
|
|
13
|
-
- **Re-edit completed params** — tap a bold completed param to replace it; the dropdown re-opens with the cached options the server originally returned for that param
|
|
14
|
-
- **Pill placement** — render pills inline in the input or inside the dropdown
|
|
15
|
-
- **Light/dark mode** — built-in themes with `prefers-color-scheme` support, fully overridable via CSS variables
|
|
16
|
-
- **Inherits your font** — defaults to the host page's font, with `--aia-font-family` to pin a specific font on the library
|
|
17
|
-
- **Access token auth** — short-lived tokens with automatic refresh, single-flight deduplication, and 401 retry
|
|
18
|
-
- **Keyboard navigation** — arrow keys, enter to submit, tab to autocomplete, backspace to un-bold the last completed param
|
|
19
|
-
- **IME-safe** — composition events are buffered so input text is committed once, after composition ends
|
|
20
|
-
- **Client-side filtering** — instant substring filtering on every keystroke
|
|
21
|
-
- **Datepicker** — date parameters are answered with a calendar instead of an option list. Click a day or navigate with the arrow keys; the date is committed the way it would be written — `Tuesday` for a date inside the next week, `March 23` for one later this year, `March 23 2027` for another year. Tapping a committed date re-opens the calendar on the month that text names now — for a weekday name, that is the next such day, not the one originally picked. A date-range parameter gets the same calendar answered in two clicks, committed as one range.
|
|
22
|
-
- **Time picker** — time parameters are answered with a time wheel instead of an option list: three wheels (hour, minutes in fives, AM/PM) and a Done button. Scroll or tap the wheels, or press ↑ / ↓ in the input to move the time five minutes; Enter or Done commits it, written as `7:30 PM`. Tapping a committed time re-opens the wheel on it.
|
|
23
|
-
- **Option overrides** — supply the options for a parameter yourself: a fixed list, a computed one, or one fetched from your own search endpoint as the user types
|
|
24
|
-
- **Product strip** — the dropdown renders a horizontal row of product cards below the options, filled by default with the items the `/suggest` response reports as matching the query; plug in your own product search instead with `[products]`, or turn the strip off with `[showProducts]="false"`
|
|
25
|
-
- **Catalog report** — every response says which of the query's constraints the catalog applied, which it had to drop, and how many items are left, on `customFields$` / `custom_fields`
|
|
26
|
-
- **Controlled & uncontrolled** — works out of the box or integrates with external state, including **Reactive Forms** via `ControlValueAccessor`
|
|
27
|
-
- **Imperative handle** — `focus()`, `blur()`, `reset()`, and `setMode()` via `@ViewChild`
|
|
28
|
-
- **Accessible** — ARIA combobox 1.2 pattern with `role="listbox"`, `aria-activedescendant`
|
|
29
|
-
- **Animations** — option press (the picked option compresses while the rest step back), text shimmer on newly added params
|
|
30
|
-
- **Loading skeleton** — while a fetch is in flight, the dropdown and inline pills keep the previous layout (same count and widths) with their text masked and a shimmer pulse
|
|
31
|
-
- **Lightweight** — styles bundled via ng-packagr; no global style import required
|
|
32
|
-
- **TypeScript first** — full type definitions shipped with the package
|
|
33
|
-
|
|
34
|
-
## Installation
|
|
13
|
+
Peer dependencies, if your app does not have them yet:
|
|
35
14
|
|
|
36
15
|
```bash
|
|
37
|
-
|
|
16
|
+
npm install @angular/common @angular/core @angular/forms rxjs
|
|
38
17
|
```
|
|
39
18
|
|
|
40
|
-
|
|
19
|
+
It is built for Angular 15 and later, with RxJS 7 or later. The package ships
|
|
20
|
+
ng-packagr's partial-Ivy (APF) output, which is forward-compatible with newer
|
|
21
|
+
Angular majors. CI builds an Angular 15 test app against the packed package;
|
|
22
|
+
later majors are not tested in CI.
|
|
41
23
|
|
|
42
|
-
```
|
|
43
|
-
|
|
24
|
+
```ts
|
|
25
|
+
import { Component } from "@angular/core";
|
|
26
|
+
import {
|
|
27
|
+
AIAutocompleteComponent,
|
|
28
|
+
type AutocompleteResult,
|
|
29
|
+
} from "@magicx-eng/ai-autocomplete-angular";
|
|
30
|
+
|
|
31
|
+
@Component({
|
|
32
|
+
selector: "app-search",
|
|
33
|
+
standalone: true,
|
|
34
|
+
imports: [AIAutocompleteComponent],
|
|
35
|
+
template: `<ai-autocomplete [apiConfig]="apiConfig" (submitted)="onSubmit($event)"></ai-autocomplete>`,
|
|
36
|
+
})
|
|
37
|
+
export class SearchComponent {
|
|
38
|
+
apiConfig = { apiKey: "pk_v1_your_public_key" };
|
|
39
|
+
|
|
40
|
+
onSubmit(result: AutocompleteResult): void {
|
|
41
|
+
console.log(result.query);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
44
|
```
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
Styles ship with the components, so there is no global stylesheet to import.
|
|
47
|
+
Not using standalone components? Import `AIAutocompleteModule` instead.
|
|
48
|
+
|
|
49
|
+
To get a key, create your product at https://ai-autocomplete.com/edit/logic (it sets what the box suggests), then create a public key at https://ai-autocomplete.com/account/keys. Public keys start with `pk_v1_` and are safe to ship in the browser.
|
|
50
|
+
|
|
51
|
+
- Docs: https://ai-autocomplete.com/docs/angular/getting-started
|
|
52
|
+
- Install with an AI coding agent: https://ai-autocomplete.com/install/angular.md
|
|
53
|
+
- Product strip and datepicker guides: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), also shipped in the package
|
|
54
|
+
- On Shopify? The Shopify app sets this up in a few minutes, no code: https://apps.shopify.com/ai-autocomplete
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
|
|
58
|
+
- **Three tiers:** the full `<ai-autocomplete>` component, `AIAutocompleteController` with `[aiaInput]` and `<ai-autocomplete-dropdown>` on an input you own, or the controller alone with your own dropdown.
|
|
59
|
+
- **Pills and options:** the details still to fill show as pills in the input, with their options in the dropdown. Typing an option's full text completes it at once, and tapping a completed detail lets the user change it.
|
|
60
|
+
- **Datepicker:** date and date-range parameters get a calendar instead of a list.
|
|
61
|
+
- **Time picker:** time parameters get a time wheel instead of a list.
|
|
62
|
+
- **Multiple selections:** a multi-select question gets checkbox options and a Done button.
|
|
63
|
+
- **Location search:** a location parameter sent without options gets a search field for any city or address.
|
|
64
|
+
- **Product strip:** a row of product cards under the options, from your catalog or from your own search.
|
|
65
|
+
- **Option overrides:** supply a parameter's options yourself, as a fixed list, a computed one, or results from your own endpoint.
|
|
66
|
+
- **Catalog report:** each response says which of the query's constraints the catalog applied, which it dropped, and how many items are left.
|
|
67
|
+
- **Motion:** the picked option presses in, new details shimmer, and a loading skeleton keeps the layout while a request is in flight.
|
|
68
|
+
- **Input handling:** keyboard navigation, the ARIA combobox 1.2 pattern, and IME-safe typing.
|
|
69
|
+
- **Auth:** a public key, or short-lived access tokens with automatic refresh and one retry on a 401.
|
|
70
|
+
- **Styling:** light and dark themes, CSS variables and stable `data-aia-*` selector hooks. It uses your page's font unless you set `--aia-font-family`.
|
|
71
|
+
- **Controlled or uncontrolled,** including Reactive Forms through `ControlValueAccessor`, with `focus()`, `blur()`, `reset()` and `setMode()` through `@ViewChild`.
|
|
72
|
+
- **TypeScript:** full type definitions.
|
|
47
73
|
|
|
48
74
|
## Three Tiers
|
|
49
75
|
|
|
@@ -79,7 +105,7 @@ import {
|
|
|
79
105
|
`,
|
|
80
106
|
})
|
|
81
107
|
export class SearchComponent {
|
|
82
|
-
apiConfig = {
|
|
108
|
+
apiConfig = { apiKey: "your_api_key" };
|
|
83
109
|
|
|
84
110
|
handleSubmit(result: AutocompleteResult): void {
|
|
85
111
|
console.log(result.query); // "Create a email"
|
|
@@ -176,151 +202,19 @@ After a completed param is added (by any means — option click, exact-match typ
|
|
|
176
202
|
|
|
177
203
|
### Datepicker
|
|
178
204
|
|
|
179
|
-
When the next parameter is a date, the dropdown shows a calendar instead of a
|
|
180
|
-
list of options. Which parameters are dates is the server's call: one whose
|
|
181
|
-
`type` is `date` gets a calendar, and one without a date type keeps its option
|
|
182
|
-
list, however date-like its name or options look.
|
|
183
|
-
|
|
184
|
-
Nothing is required to switch it on — a date parameter renders this way
|
|
185
|
-
automatically, and every other parameter is unaffected. Tier 1 and Tier 2
|
|
186
|
-
render the calendar for you; in Tier 3 the same data reaches `dropdown$` so you
|
|
187
|
-
can render your own (see [Tier 3](#tier-3-headless)).
|
|
188
|
-
|
|
189
|
-
**What the user can do**
|
|
190
|
-
|
|
191
|
-
| Input | Result |
|
|
192
|
-
|---|---|
|
|
193
|
-
| Click a day | Commits that date |
|
|
194
|
-
| <kbd>↓</kbd> | Moves into the calendar, starting on today |
|
|
195
|
-
| <kbd>←</kbd> / <kbd>→</kbd> | Previous / next day, crossing week boundaries |
|
|
196
|
-
| <kbd>↑</kbd> / <kbd>↓</kbd> | Previous / next week. Past either end of the month, focus returns to the input |
|
|
197
|
-
| <kbd>Enter</kbd> | Commits the highlighted day |
|
|
198
|
-
| Month arrows | Page the calendar. Paging never commits anything |
|
|
199
|
-
| <kbd>→</kbd> at the end of the input | Skips the parameter, same as any other pill |
|
|
200
|
-
|
|
201
|
-
**The committed value** is written the way a person would write it, always in
|
|
202
|
-
English regardless of the visitor's locale, so the value you receive has one
|
|
203
|
-
vocabulary everywhere:
|
|
204
|
-
|
|
205
|
-
- a date inside the next week (today included) commits as its weekday name —
|
|
206
|
-
`Tuesday`. Like the sentence it sits in, that name is relative: read later,
|
|
207
|
-
it means the next such day;
|
|
208
|
-
- one further out in the current year as `MONTH DAY` — `March 23`;
|
|
209
|
-
- one in another year as `MONTH DAY YEAR` — `March 23 2027`.
|
|
210
|
-
|
|
211
|
-
It arrives as an ordinary completed parameter: bold in the input,
|
|
212
|
-
and present in `completed_params` on submit like any other answer.
|
|
213
|
-
|
|
214
|
-
**Re-editing** a committed date re-opens the calendar on the month the committed
|
|
215
|
-
text names, with that day marked, so changing an answer takes one click. For a
|
|
216
|
-
weekday name that reading is relative, so once the day it named has gone by,
|
|
217
|
-
re-editing marks the next such day rather than the one originally picked — the
|
|
218
|
-
calendar shows what the sentence says today, which is also what gets submitted.
|
|
219
|
-
|
|
220
|
-
**Reading the value back.** The date arrives as text, so if you need a `Date`
|
|
221
|
-
object, `parseDate` is exported for it:
|
|
222
|
-
|
|
223
|
-
```ts
|
|
224
|
-
import { parseDate } from "@magicx-eng/ai-autocomplete-angular";
|
|
225
|
-
|
|
226
|
-
// Reads all three committed shapes: a weekday name is the one date it can
|
|
227
|
-
// mean in the next seven days, and a yearless month-day is the current year.
|
|
228
|
-
const due = parseDate("March 23"); // Date, or null if the text isn't one of ours
|
|
229
|
-
```
|
|
230
|
-
|
|
231
|
-
`parseLooseDate` is exported too, for the looser shapes a person types into a
|
|
232
|
-
query — it reads `september 5th`, `5th September`, `Sept 5` and `2026-09-05`,
|
|
233
|
-
and answers `null` for anything ambiguous rather than guessing.
|
|
234
|
-
|
|
235
|
-
**Dates the user writes themselves.** When someone types a date into their query
|
|
236
|
-
— "fly to vegas on september 5th" — the parameter it answers is recognised in
|
|
237
|
-
place and the date becomes tappable. Tapping it opens the calendar on that
|
|
238
|
-
month with the day already marked, so confirming or changing it takes one tap,
|
|
239
|
-
and the picked date replaces their words with the canonical form.
|
|
240
|
-
|
|
241
|
-
The written date is read where it can be: `september 5th`, `5th September`,
|
|
242
|
-
`Sept 5`, `September 5, 2026` and `2026-09-05` all resolve, in any of those
|
|
243
|
-
orders and with or without the year (a date with no year means its next
|
|
244
|
-
occurrence). Two cases deliberately don't pre-select — a numeric date like
|
|
245
|
-
`09/05`, which is September 5th in the US and May 9th elsewhere with nothing to
|
|
246
|
-
say which, and phrases like `next friday`. Those still open the calendar, just
|
|
247
|
-
on the current month with nothing marked, so the user picks rather than being
|
|
248
|
-
shown a guess that might be wrong.
|
|
249
|
-
|
|
250
|
-
**Date ranges.** A parameter whose `type` is `date_range` is answered by the
|
|
251
|
-
same calendar in two clicks: the first sets the start, the second the end, and the pair
|
|
252
|
-
commits as one answer. The days between them band as the user moves across the
|
|
253
|
-
calendar, so the span being chosen is visible before it is committed. Paging the
|
|
254
|
-
month between the two clicks is expected — that is how a span crosses months —
|
|
255
|
-
and <kbd>Esc</kbd> drops the start and lets them begin again. Clicking the end
|
|
256
|
-
before the start is fine; the two are ordered on the way in.
|
|
257
|
-
|
|
258
|
-
It commits as one parameter, written as a span —
|
|
259
|
-
`September 11 - October 13`, with the year on whichever end needs it — and both
|
|
260
|
-
ends are also recorded on the completed parameter's `metadata` as `YYYY-MM-DD`,
|
|
261
|
-
under the `DATE_RANGE_META_START` / `DATE_RANGE_META_END` keys this package
|
|
262
|
-
exports (`aiaDateRangeStart` / `aiaDateRangeEnd`), so you never have to parse
|
|
263
|
-
the prose. Re-editing one re-opens the calendar with both ends marked.
|
|
264
|
-
|
|
265
|
-
**Typing** while the calendar is open does not filter it. The text is treated as
|
|
266
|
-
a new query, so suggestions refresh as the user types — useful when someone
|
|
267
|
-
would rather describe what they want than pick a day.
|
|
205
|
+
When the next parameter is a date, the dropdown shows a calendar instead of a list of options, and a date-range parameter gets the same calendar answered in two clicks. Nothing is needed to switch it on. The date is committed the way a person writes it (`Tuesday`, `March 23`, `March 23 2027`), and `parseDate` reads it back as a `Date`. Keyboard use, dates the user types and date ranges are covered in [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "Datepicker".
|
|
268
206
|
|
|
269
207
|
### Time picker
|
|
270
208
|
|
|
271
|
-
When the next parameter is a time, the dropdown shows a time wheel instead of a
|
|
272
|
-
list of options. As with dates, which parameters are times is the server's call:
|
|
273
|
-
one whose `type` is `time` gets the wheel, and one without it keeps its option
|
|
274
|
-
list, however time-like its options look.
|
|
275
|
-
|
|
276
|
-
Nothing is required to switch it on. The options the server still sends for a
|
|
277
|
-
time parameter are never shown, but they choose where the wheel opens: on the
|
|
278
|
-
middle of the times suggested (`6 PM`, `7 PM`, `8 PM` opens on 7:00 PM), or on
|
|
279
|
-
the next whole hour when there are none.
|
|
280
|
-
|
|
281
|
-
**What the user can do**
|
|
282
|
-
|
|
283
|
-
| Input | Result |
|
|
284
|
-
|---|---|
|
|
285
|
-
| Scroll or tap a wheel | Turns that wheel; the time on the top rows is the time. Commits nothing |
|
|
286
|
-
| <kbd>↓</kbd> / <kbd>↑</kbd> in the input | Moves the time 5 minutes later / earlier |
|
|
287
|
-
| <kbd>Enter</kbd> | Commits the time — once the wheel has been moved. Until then it is only a suggestion, and Enter submits as usual |
|
|
288
|
-
| Done | Commits the time |
|
|
289
|
-
| <kbd>Esc</kbd> | Puts a moved wheel back on its suggested time |
|
|
290
|
-
| <kbd>→</kbd> at the end of the input | Skips the parameter, same as any other pill |
|
|
291
|
-
|
|
292
|
-
**The committed value** is written the way a person would write it, always in
|
|
293
|
-
English: `7:30 PM`, `12:05 AM`. It arrives as an ordinary completed parameter
|
|
294
|
-
(bold in the input, in `completed_params` on submit) with the server's lead-in
|
|
295
|
-
before it when there is one (`at 7:30 PM`). The exact time is also recorded on
|
|
296
|
-
the parameter's `metadata` as 24-hour `HH:MM` under the `TIME_META_KEY` key
|
|
297
|
-
(`aiaTime`), so you never have to parse the prose:
|
|
298
|
-
|
|
299
|
-
```ts
|
|
300
|
-
import { parseTime, TIME_META_KEY } from "@magicx-eng/ai-autocomplete-angular";
|
|
301
|
-
|
|
302
|
-
const time = param.metadata?.[TIME_META_KEY]; // "19:30"
|
|
303
|
-
const minutes = parseTime(param.text); // 1170 — minutes since midnight, or null
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
**Re-editing** a committed time re-opens the wheel on it.
|
|
307
|
-
|
|
308
|
-
**Typing** while the wheel is open does not filter anything. As with the
|
|
309
|
-
calendar, the text is treated as a new query.
|
|
209
|
+
When the next parameter is a time, the dropdown shows a time wheel instead of a list of options. Nothing is needed to switch it on. The time is committed as `7:30 PM`, and the 24-hour value is on the parameter's `metadata` under `TIME_META_KEY`. Keyboard use and re-editing are covered in [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "Time picker".
|
|
310
210
|
|
|
311
211
|
### Multiple selections
|
|
312
212
|
|
|
313
|
-
|
|
314
|
-
- Select rows to toggle values. Typing filters the options and keeps the current picks.
|
|
315
|
-
- Done joins the picks in selection order with the UI language's word for "and".
|
|
316
|
-
- Each value has its own `completed_params` entry. The input shows one chip for the group.
|
|
317
|
-
- Remove the group chip to change the answer. Group chips do not open for editing.
|
|
318
|
-
- Done without picks skips the question. Typing a phrase with no matching options closes the question and keeps that phrase.
|
|
319
|
-
- Space toggles the highlighted row when nothing is typed for the question. Enter commits the picks, or selects the highlighted row when no values are picked.
|
|
320
|
-
- Headless integrations can call `toggleMultiSelectOption(option)` and `commitMultiSelect()`.
|
|
321
|
-
- `multiSelectView.picked` contains the selected option texts. The view is null outside a multi_select question.
|
|
213
|
+
A suggestion with `type: { kind: "multi_select" }` shows checkbox options and a Done button. Each picked value gets its own `completed_params` entry, and the input shows one chip for the group. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "Multiple selections".
|
|
322
214
|
|
|
323
|
-
|
|
215
|
+
### Location search
|
|
216
|
+
|
|
217
|
+
A location parameter the server sends without options gets a search field that looks up any city or address through the MagicX server. If `apiConfig.endpoint` points at a proxy with its own path, set `apiConfig.locationEndpoint` too. `locationSearch: false` takes typed text only, and an `optionOverrides` entry for the parameter replaces the search. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "Location search".
|
|
324
218
|
|
|
325
219
|
## Tier 2: Controller + Dropdown
|
|
326
220
|
|
|
@@ -427,6 +321,8 @@ export class SearchComponent implements OnInit, OnDestroy {
|
|
|
427
321
|
|
|
428
322
|
> **Time picker in a custom UI.** For a time parameter, `dd.formatType` is `"time"`, `dd.suggestions[0].options` is empty, and `dd.timeView` holds `{ minutes, touched }` — the time on show, as minutes since midnight. Draw it however you like (`formatTime(minutes)` gives `"7:30 PM"`), call `ac.setTime(minutes)` to move it (snapped to 5 minutes) and `ac.commitTime()` to answer with it. The input's ↑ / ↓ / Enter keys already drive it.
|
|
429
323
|
|
|
324
|
+
> **Location search in a custom UI.** For a location pill, `dd.formatType` is `"location"`, `dd.suggestions[0].options` is empty, and `dd.locationView` holds `{ query, places, status, highlighted }`. Call `ac.setLocationQuery(text)` as the user types (the SDK debounces and cancels the searches), `ac.moveLocationHighlight(±1)` for the arrow keys and `ac.commitLocation(index?)` to answer. Call `ac.setLocationFieldFocused(true)` *before* moving focus into your field (and `false` when it leaves), so the input's blur doesn't close the panel.
|
|
325
|
+
|
|
430
326
|
> **Option icons.** An option may carry an icon: `icon_svg` is inline SVG markup and `icon` its name. The built-in dropdown draws the SVG before the option's text, in the text color, and hides it while the row shows its loading skeleton. When rendering options yourself, pass `icon_svg` through the exported `sanitizeOptionIconSvg` before inserting it — it reduces the markup to plain vector drawing and returns `null` for anything else — and use `optionLabel(option)` for the text — it is the option's `text` alone; `icon` is the icon's name and is never shown as text, even when `icon_svg` is missing or fails to draw. A picked option's `icon` / `icon_svg` are copied onto its completed parameter, and the chip in the input draws the glyph before its text. Both surfaces can be switched off: `showOptionIcons: false` renders option rows as text only and `showChipIcons: false` renders chips as text only; either way the icon element is omitted rather than hidden.
|
|
431
327
|
|
|
432
328
|
> **Option pictures and counts.** An option may also carry `image_url` — a picture of the best-matching catalog item offering it — and `item_count`, how many items offer it (each is present only when the server includes it; when it includes counts, the options also arrive ordered by them, most items first; a starting state carries pictures but no counts). The built-in dropdown draws the picture as a square thumbnail before the option's text (in place of its `icon_svg`, so a row never leads with two visuals) and the count as a muted label at the row's trailing edge (`"12 items"`); a skeleton row keeps the tile's placeholder fill and hides the count. Icons and pictures are all-or-nothing per list: if any tappable option would draw neither, no row draws one, so a list never mixes rows with and without a leading visual (non-tappable rows don't count). A custom dropdown can apply the same rule with the exported `optionsShowLeadingVisuals(options, showIcons, showImages)`. The unit word after the number is a token: set `--aia-option-count-unit: "sneakers"` to name what is being counted, `--aia-option-count-unit-one: "sneaker"` for a count of 1 (it falls back to the plural token), or `--aia-option-count-unit: ""` for the number alone. When rendering options yourself, pass `image_url` through the exported `optionImageSrc` before using it as an `<img src>` — it returns the URL only when it is `http(s)` and `null` otherwise — and `formatOptionCount(option.item_count)` gives the number the built-in rows print (`null` when there is no count); `optionCountLabel(count, unit?)` appends a unit for a dropdown that prints the word itself (`"item"` / `"items"` by default; one word, a `{ one, other }` pair, or `""` for none). Both surfaces can be switched off: `showOptionImages: false` renders rows without pictures (an option's icon then draws instead) and `showOptionCounts: false` hides the counts. A picked option's `image_url` is copied onto its completed parameter too, and the chip in the input draws it as a small rounded tile before its text, in place of the icon; `showChipImages: false` renders chips without pictures (the icon then draws instead). The tile is sized by `--aia-option-image-size` (40px), rounded by `--aia-option-image-radius` (12px), spaced by `--aia-option-image-gap` (12px) and filled by `--aia-option-image-bg` (default: `--aia-skeleton-bg`) as a placeholder until its picture loads (and on skeleton rows, or if the picture fails); a loaded picture is scaled to fit rather than cropped and sits on the dropdown's background, and one narrower than the tile is rounded on its own corners by `--aia-option-picture-radius` (6px); in a grid with pictures, an icon row draws its glyph at `--aia-option-tile-icon-size` (1.5em) so it holds the picture column; the count reads `--aia-option-count-font-size` (12px), `--aia-option-count-color` and `--aia-option-count-opacity` (0.6); the chip's tile reads `--aia-chip-image-size` (1.25em of the chip's font), `--aia-chip-image-radius` (4px) and `--aia-chip-image-bg` (default: `--aia-skeleton-bg`), the placeholder fill shown until the picture loads; a loaded picture narrower than the tile narrows it to the picture's own width, so the radius rounds the picture.
|
|
@@ -468,6 +364,7 @@ Standalone-first apps don't need this — import the components/directive direct
|
|
|
468
364
|
| `dropdownTrigger` | `"auto" \| "manual" \| "hidden"` | `"auto"` | When the dropdown appears. `"auto"` = when options available. `"manual"` = only on pill tap, closes after selection. `"hidden"` = never shows. |
|
|
469
365
|
| `closeDropdownOnBlur` | `boolean` | `true` | When `true`, the dropdown closes if the input loses focus. Set to `false` to keep it open whenever options are available, regardless of focus. |
|
|
470
366
|
| `showNonTappableOptions` | `boolean` | `true` | When `true`, non-tappable options are rendered alongside tappable ones in the dropdown. Set to `false` to hide non-tappable options entirely. |
|
|
367
|
+
| `locationSearch` | `boolean` | `true` | When `true`, a location parameter without options searches places as the user types in its field. Set to `false` to take typed text only. See [Location search](#location-search). |
|
|
471
368
|
| `showSkipButton` | `boolean` | `true` | When `true`, the dropdown's pill bar ends in a small "skip" button that dismisses the active pill — same action as pressing <kbd>→</kbd> at the end of the input. It sits top-right when the dropdown opens below the input, bottom-right when `optionsPosition` is `"above"`, and appears once the input has text (alongside the footer's "→ to skip" hint). Set to `false` to hide it. |
|
|
472
369
|
| `showOptionIcons` | `boolean` | `true` | When `true`, an option that carries an `icon_svg` draws its icon before its text in the dropdown. Set to `false` to render option rows as text only. |
|
|
473
370
|
| `showChipIcons` | `boolean` | `true` | When `true`, a completed chip in the input draws the icon of the option that answered it. Set to `false` to render chips as text only. |
|
|
@@ -507,305 +404,19 @@ Standalone-first apps don't need this — import the components/directive direct
|
|
|
507
404
|
|
|
508
405
|
#### Product strip
|
|
509
406
|
|
|
510
|
-
The dropdown
|
|
511
|
-
whenever it has products to show. By default those are the items the
|
|
512
|
-
`/suggest` response itself reports as matching the query — no configuration,
|
|
513
|
-
no extra request: the cards land in the same state emission as the
|
|
514
|
-
suggestions, so what the strip shows and what the pills offer always describe
|
|
515
|
-
the same narrowing.
|
|
516
|
-
|
|
517
|
-
```html
|
|
518
|
-
<ai-autocomplete
|
|
519
|
-
[apiConfig]="apiConfig"
|
|
520
|
-
(productSelect)="openProduct($event)"
|
|
521
|
-
(submitted)="onSubmit($event)"
|
|
522
|
-
></ai-autocomplete>
|
|
523
|
-
```
|
|
524
|
-
|
|
525
|
-
Each server item becomes a `Product` with `id` (the item's stable id), `title`,
|
|
526
|
-
`price` (the item's lowest price, verbatim as the catalog spells it — the
|
|
527
|
-
currency is yours to add), `compareAtPrice` (the price before a markdown, on a
|
|
528
|
-
discounted item only, struck through beside the price), `vendor`, `imageUrl`, and a `url`: the item's own
|
|
529
|
-
`item_url` when the uploaded catalog named one (absolute or root-relative;
|
|
530
|
-
anything else is ignored), else a **relative** `/products/{handle}` — the right
|
|
531
|
-
link for a Shopify widget running on the storefront itself — opened on the
|
|
532
|
-
variant the query chose (`?variant=…`, e.g. the blue one for "blue shoes") when
|
|
533
|
-
there is one, whose price and image the card then shows. `available` is carried
|
|
534
|
-
over when the server reports it. An item with
|
|
535
|
-
neither gets no `url`: its card is still activatable and still emits
|
|
536
|
-
`(productSelect)`, it just has nothing for cmd-click to open. `productFromMatchedItem` / `productsFromCustomFields` are
|
|
537
|
-
exported for a hand-rolled strip that wants the same mapping.
|
|
538
|
-
|
|
539
|
-
Bind `[showProducts]="false"` to render no strip at all. The catalog report
|
|
540
|
-
(below) stays readable either way.
|
|
541
|
-
|
|
542
|
-
`[productsLayout]="'list'"` stacks the same cards as full-width rows — thumbnail
|
|
543
|
-
on the left, title, vendor and price on the right — for results that read as
|
|
544
|
-
a list (courses, listings, documents) rather than products on a shelf. The
|
|
545
|
-
column scrolls vertically inside `--aia-product-list-max-height` (320px by
|
|
546
|
-
default); `--aia-product-list-media-size` (44px) sizes the thumbnail and
|
|
547
|
-
`--aia-product-list-gap` (2px) the space between rows. `"row"`, the default,
|
|
548
|
-
is the horizontal strip. Changing the binding re-lays the strip out at once, and
|
|
549
|
-
`<ai-autocomplete-dropdown>` takes the same input in Tier 2.
|
|
550
|
-
|
|
551
|
-
**Product image fallback.** A product's image takes priority when its
|
|
552
|
-
`imageUrl` loads successfully. A missing or blank URL, or an image load error,
|
|
553
|
-
uses `productImageFallback`: `"image"` (the default) shows the existing
|
|
554
|
-
placeholder pictogram; `"initial"` shows the first character of the trimmed,
|
|
555
|
-
uppercased title. This is a Unicode grapheme (so a combined character or emoji
|
|
556
|
-
stays together), with a Unicode code point fallback in older browsers. An
|
|
557
|
-
empty or whitespace-only title shows `?`. The fallback works in both row and
|
|
558
|
-
list layouts. Initial tiles are decorative (`aria-hidden="true"`); the card's
|
|
559
|
-
visible title supplies its text.
|
|
560
|
-
|
|
561
|
-
**Sold out.** A product with `available: false` shows a "Sold out" badge over
|
|
562
|
-
the top-left of its image (in the list layout, a smaller banner across the
|
|
563
|
-
bottom of the thumbnail) and its image is desaturated; the card stays
|
|
564
|
-
selectable and keeps its link. Absent or `true` shows no
|
|
565
|
-
badge, so leave `available` out when you don't know. The badge is part of the
|
|
566
|
-
card's text, so screen readers announce it. Theme it with
|
|
567
|
-
`--aia-product-badge-bg`, `--aia-product-badge-color`,
|
|
568
|
-
`--aia-product-badge-font-size` and `--aia-product-badge-inset`, and the list
|
|
569
|
-
banner with `--aia-product-badge-list-bg`, `--aia-product-badge-list-color` and
|
|
570
|
-
`--aia-product-badge-list-font-size`.
|
|
571
|
-
|
|
572
|
-
Bind `productImageFallback` on `<ai-autocomplete>` in Tier 1 or directly
|
|
573
|
-
on `<ai-autocomplete-dropdown>` in Tier 2:
|
|
574
|
-
|
|
575
|
-
```html
|
|
576
|
-
<!-- Tier 1 -->
|
|
577
|
-
<ai-autocomplete
|
|
578
|
-
[apiConfig]="apiConfig"
|
|
579
|
-
[productImageFallback]="'initial'"
|
|
580
|
-
(submitted)="onSubmit($event)"
|
|
581
|
-
></ai-autocomplete>
|
|
582
|
-
|
|
583
|
-
<!-- Tier 2 -->
|
|
584
|
-
<ai-autocomplete-dropdown
|
|
585
|
-
[controller]="ac"
|
|
586
|
-
[productImageFallback]="'initial'"
|
|
587
|
-
mode="auto"
|
|
588
|
-
></ai-autocomplete-dropdown>
|
|
589
|
-
```
|
|
590
|
-
|
|
591
|
-
Style the initial tile itself with `[data-aia-product-initial]`. For
|
|
592
|
-
example, wrap the widget in an element with `id="catalog-search"` and add this
|
|
593
|
-
rule to your stylesheet (the global stylesheet in Angular). The existing
|
|
594
|
-
`--aia-product-media-bg` variable sets the background; `color`, `font-size`
|
|
595
|
-
and `border-radius` style the initial without additional SDK options.
|
|
596
|
-
|
|
597
|
-
```css
|
|
598
|
-
#catalog-search [data-aia-product-initial] {
|
|
599
|
-
--aia-product-media-bg: #eef2ff;
|
|
600
|
-
color: #4338ca;
|
|
601
|
-
font-size: 22px;
|
|
602
|
-
border-radius: 12px;
|
|
603
|
-
}
|
|
604
|
-
```
|
|
407
|
+
The dropdown shows a row of product cards under the options whenever there are products to show. By default they are the items the `/suggest` response reports as matching the query. When a card is picked, `(productSelect)` emits; the SDK never navigates. `[showProducts]="false"` turns the strip off, `[productsLayout]="'list'"` stacks the cards as rows, and `productImageFallback` sets what a card shows when it has no image. The full guide, with the `Product` shape, sold-out badges and accessibility, is in [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "Product strip".
|
|
605
408
|
|
|
606
409
|
#### The catalog report (`customFields$`)
|
|
607
410
|
|
|
608
|
-
|
|
609
|
-
controller exposes it as `customFields$` (and on `state$`), and it rides on
|
|
610
|
-
`AutocompleteResult` as `custom_fields`, so `(resultChange)` / `onResult`
|
|
611
|
-
carry it too:
|
|
612
|
-
|
|
613
|
-
```html
|
|
614
|
-
<ai-autocomplete (resultChange)="report = $event.custom_fields ?? null"></ai-autocomplete>
|
|
615
|
-
|
|
616
|
-
<p *ngIf="report">{{ report.items.total }} results</p>
|
|
617
|
-
<!-- e.g. { parameter: "Color", value: "Chartreuse", op: "eq" } — the shopper asked
|
|
618
|
-
for a colour no item carries, so the results ignore it. Say so. -->
|
|
619
|
-
<p *ngIf="report?.dropped_filters?.length">
|
|
620
|
-
No match for
|
|
621
|
-
<ng-container *ngFor="let filter of report.dropped_filters; let last = last">
|
|
622
|
-
{{ filter.value }}<ng-container *ngIf="!last">, </ng-container>
|
|
623
|
-
</ng-container>
|
|
624
|
-
</p>
|
|
625
|
-
```
|
|
626
|
-
|
|
627
|
-
- `applied_filters` / `dropped_filters` — the constraints the server read out
|
|
628
|
-
of the query as `{ parameter, value, op }` (`op` is one of `eq`, `ne`, `lt`,
|
|
629
|
-
`lte`, `gt`, `gte`), split into the ones the catalog answered and the ones it
|
|
630
|
-
could not (a parameter it does not have, a bound that is not a number, a
|
|
631
|
-
value no item carries). The items answer the applied set, so the dropped
|
|
632
|
-
list is what tells "87 black t-shirts" from "no black item, so here are
|
|
633
|
-
t-shirts". Both are always arrays.
|
|
634
|
-
- `items.total` — how many items the applied filters left standing. It also
|
|
635
|
-
moves with the query's own words, so it drops as a typed word starts
|
|
636
|
-
matching a title. `items.matched` is the list the strip renders, capped by
|
|
637
|
-
the server; it is empty (with a non-zero `total`) when nothing narrowed the
|
|
638
|
-
catalog, where listing arbitrary items as matches would mislead.
|
|
639
|
-
- `null` (no `custom_fields` key on the result) means the response carried no
|
|
640
|
-
report — no catalog was read for it (a product with no catalog, the starting
|
|
641
|
-
state, a response with no option-bearing parameter to offer). That is "no
|
|
642
|
-
news", not an empty catalog. The strip clears on such a response rather than
|
|
643
|
-
keeping an older query's items.
|
|
411
|
+
Each response that read the catalog says which of the query's constraints it applied (`applied_filters`), which it dropped (`dropped_filters`) and how many items are left (`items.total`). Read it from `customFields$` on the controller, or from `custom_fields` on `AutocompleteResult`. `null` means no catalog was read for that response. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "The catalog report".
|
|
644
412
|
|
|
645
413
|
#### Change product cards before display
|
|
646
414
|
|
|
647
|
-
|
|
648
|
-
- The SDK calls it once per response with its default cards and their matched items in the same order.
|
|
649
|
-
- The returned array becomes the product state and the displayed strip.
|
|
650
|
-
- A thrown error or a non-array result keeps the default cards. A thrown error warns once per instance.
|
|
651
|
-
- `refreshProducts()` maps the current items again without a request. Call it when your own data arrives.
|
|
652
|
-
- Both APIs leave a custom `products` integration unchanged.
|
|
653
|
-
|
|
654
|
-
- Pass `mapProducts` to `new AIAutocompleteController({ mapProducts })` and call `controller.refreshProducts()`.
|
|
655
|
-
- Bind `[mapProducts]="mapProducts"` on `<ai-autocomplete>` and call `refreshProducts()` on the component.
|
|
656
|
-
- Changing the callback through `controller.update({ mapProducts })` or the input maps the current items again.
|
|
657
|
-
- Define the callback as a stable component field.
|
|
658
|
-
|
|
659
|
-
```ts
|
|
660
|
-
mapProducts = (products: Product[], items: MatchedItem[]): Product[] =>
|
|
661
|
-
products.map((product, index) => ({
|
|
662
|
-
...product,
|
|
663
|
-
price: this.shopperPrices[items[index].source_id] ?? "",
|
|
664
|
-
}));
|
|
665
|
-
```
|
|
415
|
+
`mapProducts(products, items)` changes the cards before they show (to put in the shopper's own prices, say), and `refreshProducts()` maps them again when your data arrives. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "Change product cards before display".
|
|
666
416
|
|
|
667
417
|
#### Your own product search (`products`)
|
|
668
418
|
|
|
669
|
-
|
|
670
|
-
endpoint and response shape — bind `[products]`. The SDK owns the UI; you own
|
|
671
|
-
only the fetching and the mapping. The server's items are then not rendered
|
|
672
|
-
(they stay readable on `customFields$`).
|
|
673
|
-
|
|
674
|
-
```ts
|
|
675
|
-
import { Component } from "@angular/core";
|
|
676
|
-
import type { Product, ProductsConfig } from "@magicx-eng/ai-autocomplete-angular";
|
|
677
|
-
|
|
678
|
-
@Component({
|
|
679
|
-
template: `<ai-autocomplete
|
|
680
|
-
[apiConfig]="apiConfig"
|
|
681
|
-
[products]="products"
|
|
682
|
-
(productSelect)="openProduct($event)"
|
|
683
|
-
(submitted)="onSubmit($event)"
|
|
684
|
-
></ai-autocomplete>`,
|
|
685
|
-
})
|
|
686
|
-
export class SearchComponent {
|
|
687
|
-
// A component field, not an inline object literal: a new reference on each
|
|
688
|
-
// change-detection pass reads as a swapped integration and clears the
|
|
689
|
-
// current cards (the same rule `apiConfig` and `optionOverrides` follow).
|
|
690
|
-
products: ProductsConfig = {
|
|
691
|
-
// You own the request entirely — auth headers, GraphQL body, locale
|
|
692
|
-
// prefixes. Honour the signal: the SDK aborts it as soon as a newer query
|
|
693
|
-
// supersedes this one.
|
|
694
|
-
fetch: (query, signal) =>
|
|
695
|
-
fetch(`/api/products?q=${encodeURIComponent(query)}`, { signal }).then((r) => r.json()),
|
|
696
|
-
|
|
697
|
-
// Pure mapping, kept out of `fetch` so you can unit-test it without a
|
|
698
|
-
// network.
|
|
699
|
-
transform: (raw): Product[] =>
|
|
700
|
-
(raw as ApiResponse).items.map((item) => ({
|
|
701
|
-
id: item.id,
|
|
702
|
-
title: item.title,
|
|
703
|
-
url: item.url,
|
|
704
|
-
imageUrl: item.image?.src ?? null, // null uses the configured productImageFallback
|
|
705
|
-
price: formatMoney(item.price), // you know the currency
|
|
706
|
-
vendor: item.brand,
|
|
707
|
-
})),
|
|
708
|
-
|
|
709
|
-
limit: 8, // applied by the SDK, after transform
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
// Selection emits — the SDK never navigates.
|
|
713
|
-
openProduct(product: Product): void {
|
|
714
|
-
if (product.url) this.router.navigateByUrl(product.url);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
```
|
|
718
|
-
|
|
719
|
-
`Product` is exactly seven fields; only `id` and `title` are required:
|
|
720
|
-
|
|
721
|
-
```ts
|
|
722
|
-
type Product = {
|
|
723
|
-
id: string;
|
|
724
|
-
title: string;
|
|
725
|
-
url?: string; // absent = a card with no link (still activatable)
|
|
726
|
-
imageUrl?: string | null;
|
|
727
|
-
price?: string;
|
|
728
|
-
compareAtPrice?: string; // the price before a markdown; struck through beside price
|
|
729
|
-
vendor?: string;
|
|
730
|
-
available?: boolean; // false shows a "Sold out" badge
|
|
731
|
-
};
|
|
732
|
-
```
|
|
733
|
-
|
|
734
|
-
**What the SDK guarantees**
|
|
735
|
-
|
|
736
|
-
- **One fetch cadence.** The product search rides the same debounce, the same
|
|
737
|
-
`AbortController` and the same version guard as `/suggest` — there is no
|
|
738
|
-
second timer to drift out of step.
|
|
739
|
-
- **Empty queries never reach you.** On mount and after `reset()` the strip
|
|
740
|
-
clears.
|
|
741
|
-
- **Out-of-order responses are dropped.** A slow response for an older query is
|
|
742
|
-
never rendered over a newer one.
|
|
743
|
-
- **Failure is silent.** A rejected `fetch` or a throwing `transform` clears the
|
|
744
|
-
strip, logs once, and leaves the suggestions half untouched — no `error`
|
|
745
|
-
state, no `errored` output, no effect on `isLoading$`.
|
|
746
|
-
- **The two halves are independent.** The panel opens if *either* has content,
|
|
747
|
-
so products keep it open when option filtering empties the option list.
|
|
748
|
-
`dropdownTrigger` (`manual` / `hidden`) still gates the panel as before.
|
|
749
|
-
|
|
750
|
-
**Add to cart.** Bind `[onProductAddToCart]` and every card that isn't sold
|
|
751
|
-
out (`available: false`) shows a round cart button over the bottom-right corner
|
|
752
|
-
of its image (in the list layout, at the right end of the row). Leave it
|
|
753
|
-
unbound (or bind `undefined`) and no card has one; binding or unbinding it later
|
|
754
|
-
adds or removes the buttons. The SDK never touches a cart: pressing the button
|
|
755
|
-
calls your function with the card's `Product`, and does not emit
|
|
756
|
-
`(productSelect)`, navigate or close the panel.
|
|
757
|
-
|
|
758
|
-
```ts
|
|
759
|
-
// A field, not a method reference, so `this` stays bound.
|
|
760
|
-
addToCart = (product: Product) => this.cart.add(product.id); // may return a promise
|
|
761
|
-
```
|
|
762
|
-
|
|
763
|
-
```html
|
|
764
|
-
<ai-autocomplete [apiConfig]="apiConfig" [onProductAddToCart]="addToCart"></ai-autocomplete>
|
|
765
|
-
```
|
|
766
|
-
|
|
767
|
-
Return a promise (or any thenable — convert an `Observable` with
|
|
768
|
-
`firstValueFrom`) to have the button show progress. While it is pending the
|
|
769
|
-
button carries `data-aia-cart-state="adding"` (and `aria-busy="true"`), spins
|
|
770
|
-
and ignores further presses; once it resolves the cart turns into a check
|
|
771
|
-
(`data-aia-cart-state="added"`) and stays one until the card's product changes
|
|
772
|
-
(a price-only change keeps it). Pressing it again adds another unit, back
|
|
773
|
-
through "adding" to "added". A rejection puts the button back at rest — show your own error. A function that returns nothing goes
|
|
774
|
-
straight to "added". The button is labelled "Add to cart: {title}" in the
|
|
775
|
-
widget language, reachable by Tab and pressed with Enter or Space. Theme it
|
|
776
|
-
with `--aia-product-cart-size` (28px), `--aia-product-cart-bg` and
|
|
777
|
-
`--aia-product-cart-color`; its focus ring uses `--aia-product-focus-ring`.
|
|
778
|
-
The button is a `[data-aia-product-cart]` element, and a card that has one
|
|
779
|
-
carries `data-aia-product-has-cart`.
|
|
780
|
-
|
|
781
|
-
**Selection and links.** Cards are real `<a href>` elements, so cmd/ctrl-click,
|
|
782
|
-
middle-click and "copy link address" behave natively. A plain left click is
|
|
783
|
-
intercepted (`preventDefault`) and emits `(productSelect)` instead.
|
|
784
|
-
|
|
785
|
-
`product.url` is used verbatim — the SDK trusts your `transform` output and
|
|
786
|
-
does not sanitise it, so validate the URL there if the platform response isn't
|
|
787
|
-
fully under your control. (Angular additionally runs its own `href`
|
|
788
|
-
sanitiser, so unrecognised schemes like `myapp://…` are rewritten to
|
|
789
|
-
`unsafe:…` in that package only.)
|
|
790
|
-
|
|
791
|
-
**Accessibility.** The strip is a `role="group"` labelled "Products"; each card
|
|
792
|
-
is a `role="option"` in the tab order, activated with Enter or Space, with a
|
|
793
|
-
visible focus ring. Tabbing into the strip does not close the panel. The row
|
|
794
|
-
scrolls horizontally by trackpad, wheel, touch and keyboard; the page never
|
|
795
|
-
scrolls sideways and the scrollbar chrome is hidden in all engines.
|
|
796
|
-
|
|
797
|
-
Swapping `[products]` for a different config clears the current cards; the
|
|
798
|
-
strip repopulates on the *next* `/suggest` request rather than immediately,
|
|
799
|
-
since the product search rides that one scheduler. Binding it back to
|
|
800
|
-
`undefined` hands the strip back to the server's items at once, and toggling
|
|
801
|
-
`[showProducts]` empties or restores it at once.
|
|
802
|
-
|
|
803
|
-
Tier 2 gets the same thing: pass `showProducts` / `products` /
|
|
804
|
-
`onProductSelect` / `onProductAddToCart` to the `AIAutocompleteController` and
|
|
805
|
-
`<ai-autocomplete-dropdown>` renders the strip, cart buttons included. Tier 3
|
|
806
|
-
consumers subscribe to `products$` (and `customFields$`) and call
|
|
807
|
-
`controller.selectProduct(product)` and `controller.addProductToCart(product)`
|
|
808
|
-
from their own cards.
|
|
419
|
+
Bind `[products]` to fill the cards from your own search. You write a `fetch` that honours the abort signal and a `transform` that maps the response to `Product` objects; the SDK keeps the UI, the timing and the order of responses. Details: [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "Your own product search".
|
|
809
420
|
|
|
810
421
|
#### Custom submit button
|
|
811
422
|
|
|
@@ -889,7 +500,7 @@ ac.destroy();
|
|
|
889
500
|
|
|
890
501
|
#### Constructor options
|
|
891
502
|
|
|
892
|
-
Accepts the same shape as `<ai-autocomplete>`'s inputs (`apiConfig`, `additionalContext`, `language`, `productId`, `visitorId`, `optionOverrides`, `columns`, `dropdownTrigger`, `optionsPosition`, `closeDropdownOnBlur`, `showNonTappableOptions`, `showProducts`, `products`), plus event callbacks (`onSubmit`, `onResult`, `onError`, `onChange`, `onParamsChange`, `onFocus`, `onBlur`, `onProductSelect`), the add-to-cart handler (`onProductAddToCart`, which `update()` can also set, swap or remove) and controlled-mode initial values (`value`, `completedParams`). `onResult` fires after every successful round-trip — see [Reading the query as it's built](#reading-the-query-as-its-built).
|
|
503
|
+
Accepts the same shape as `<ai-autocomplete>`'s inputs (`apiConfig`, `additionalContext`, `language`, `productId`, `visitorId`, `optionOverrides`, `columns`, `dropdownTrigger`, `optionsPosition`, `closeDropdownOnBlur`, `showNonTappableOptions`, `locationSearch`, `showProducts`, `products`), plus event callbacks (`onSubmit`, `onResult`, `onError`, `onChange`, `onParamsChange`, `onFocus`, `onBlur`, `onProductSelect`), the add-to-cart handler (`onProductAddToCart`, which `update()` can also set, swap or remove) and controlled-mode initial values (`value`, `completedParams`). `onResult` fires after every successful round-trip — see [Reading the query as it's built](#reading-the-query-as-its-built).
|
|
893
504
|
|
|
894
505
|
#### State observables
|
|
895
506
|
|
|
@@ -1038,7 +649,7 @@ Pressing <kbd>→</kbd> at the end of the input dismisses the active pill. The d
|
|
|
1038
649
|
{ placeholder: "", parameter: "goal", text: "skipped", kind: null }
|
|
1039
650
|
```
|
|
1040
651
|
|
|
1041
|
-
Tier 2 consumers who build their own submit payload get the raw skips from the controller (`skippedParams$`, or `getState().skippedParams`) and can fold them in the same way with the exported `buildSubmitResult(text, completedParams, skippedParams, { identifiedParams, isReady })` — the last argument carries `identifiedParams$` / `isReady$` (or their `getState()` fields) so a hand-rolled submit reports the same `identified_params` and `is_ready` the SDK's own results do.
|
|
652
|
+
Tier 2 consumers who build their own submit payload get the raw skips from the controller (`skippedParams$`, or `getState().skippedParams`) and can fold them in the same way with the exported `buildSubmitResult(text, completedParams, skippedParams, { identifiedParams, isReady })` — the last argument carries `identifiedParams$` / `isReady$` (or their `getState()` fields) so a hand-rolled submit reports the same `identified_params` and `is_ready` the SDK's own results do. Call `controller.prepareSubmit()` first, then pass `controller.getState().identifiedParams` and `controller.getState().isReady`: a typed value with no pill yet joins `identifiedParams` only in that call.
|
|
1042
653
|
|
|
1043
654
|
> **Reading `skippedParams$` directly:** the array is append-only until `reset()`. The "drop a skip whose parameter got filled" rule is applied when the payload is built, not by pruning the array — so if the user skips `goal` and later fills one, the raw array still holds the `goal` entry. That's deliberate: the filter self-heals if they then delete that param's text, where pruning would discard the signal for good. `buildSubmitResult` applies the rule for you; to apply it elsewhere (say, a "you skipped X" badge), use the exported `withSkippedParams(completedParams, skippedParams)`.
|
|
1044
655
|
|
|
@@ -1056,73 +667,7 @@ Every class name the package emits is namespaced — `magicx-aia-*` for the clas
|
|
|
1056
667
|
|
|
1057
668
|
Override on the host element (via `class`). The variables are declared with `:where()` (zero specificity), so a value you set on the host always wins.
|
|
1058
669
|
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
```css
|
|
1062
|
-
.my-search {
|
|
1063
|
-
--aia-input-radius: 0;
|
|
1064
|
-
--aia-written-text-font-weight: 500;
|
|
1065
|
-
}
|
|
1066
|
-
```
|
|
1067
|
-
|
|
1068
|
-
| Variable | Light | Dark | Description |
|
|
1069
|
-
|---|---|---|---|
|
|
1070
|
-
| `--aia-font-family` | `inherit` | `inherit` | Font used by the library. Defaults to `inherit` so the library picks up your page's font automatically. Set this to pin a specific font on the library without changing the surrounding page. |
|
|
1071
|
-
| `--aia-pill-bg` | `#bdbdbd` | `#bdbdbd` | Pill background |
|
|
1072
|
-
| `--aia-pill-color` | `#000000` | `#ffffff` | Pill text |
|
|
1073
|
-
| `--aia-pill-font-size` | `19px` | `19px` | Pill font size |
|
|
1074
|
-
| `--aia-option-bg` | `transparent` | `transparent` | Highlighted option background |
|
|
1075
|
-
| `--aia-option-color` | `#000000` | `#ffffff` | Option text |
|
|
1076
|
-
| `--aia-option-color-selected` | `#000000` | `#ffffff` | Highlighted option text |
|
|
1077
|
-
| `--aia-option-font-size` | `19px` | `19px` | Option font size |
|
|
1078
|
-
| `--aia-written-text-color` | `#000000` | `#ffffff` | Input text |
|
|
1079
|
-
| `--aia-written-text-font-size` | `19px` | `19px` | Input text font size |
|
|
1080
|
-
| `--aia-input-radius` | `10px` | `10px` | Full input corner radius. Set `0` for square corners. |
|
|
1081
|
-
| `--aia-written-text-font-weight` | `300` | `300` | Written text weight in the full input. Completed chips keep their own typography. |
|
|
1082
|
-
| `--aia-caret-color` | `--aia-written-text-color` | `--aia-written-text-color` | Editor caret color. Override independently of input text color. |
|
|
1083
|
-
| `--aia-submit-bg` | `#000000` | `#ffffff` | Submit button background |
|
|
1084
|
-
| `--aia-submit-color` | `#ffffff` | `#000000` | Submit button icon color |
|
|
1085
|
-
| `--aia-dropdown-bg` | — | — | Optional bg color the dropdown's "glass" rim shadow tints toward. Set this to the page background behind the dropdown so the bottom-corner glow blends seamlessly. |
|
|
1086
|
-
| `--aia-scrollbar-thumb` | `rgba(0, 0, 0, 0.3)` | `rgba(0, 0, 0, 0.3)` | No longer used: the option list hides its scrollbar in every browser. Kept so existing overrides don't break. |
|
|
1087
|
-
| `--aia-streak-rgb` | `99, 102, 241` | `255, 255, 255` | Comma-separated RGB triplet tinting the datepicker's pressed cell, and its selected cell when `--aia-date-selected-bg` is unset. The today ring uses `--aia-date-today-ring`, not this. |
|
|
1088
|
-
| `--aia-product-card-width` | `116px` | `116px` | Width of a product card in the strip. The media tile is square, so this also sets its height. |
|
|
1089
|
-
| `--aia-product-gap` | `8px` | `8px` | Gap between product cards. |
|
|
1090
|
-
| `--aia-product-bg` | `transparent` | `transparent` | Product card background. |
|
|
1091
|
-
| `--aia-product-bg-active` | `--aia-option-bg` | `--aia-option-bg` | Product card background on hover. |
|
|
1092
|
-
| `--aia-product-media-bg` | `--aia-skeleton-bg` | `--aia-skeleton-bg` | Placeholder fill of the product tile: shown until the photo loads, and behind both fallback tiles (placeholder pictogram or title initial) used when an image URL is missing, blank or fails to load. Once a photo loads the tile is transparent. |
|
|
1093
|
-
| `--aia-scroll-arrow-color` | `--aia-option-color` | `--aia-option-color` | Chevron color of the arrow (`--aia-scroll-arrow-color-hover` on hover). |
|
|
1094
|
-
| `--aia-placeholder-fade` | `120ms` | `120ms` | Fade-out of the outgoing placeholder phrase when the starting-state placeholder changes (the incoming one types itself in). |
|
|
1095
|
-
| `--aia-product-image-radius` | `8px` | `8px` | Corner radius of a product photo narrower than its square tile (a tall one), which is scaled to fit rather than cropped. A photo that fills the tile takes the tile's own 8px corners. |
|
|
1096
|
-
| `--aia-product-placeholder-image` | storefront pictogram | storefront pictogram | The pictogram used by `productImageFallback: "image"` (the default) when an image URL is missing, blank or fails to load. Defaults to a two-tone storefront inlined as a data URI. Set any `url(...)` to swap it; it is centered and contained over `--aia-product-media-bg`. Does not affect `"initial"` tiles. |
|
|
1097
|
-
| `--aia-product-title-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | Product title text. Follows the option colors by default, so theming the panel moves suggestions and products together. |
|
|
1098
|
-
| `--aia-product-price-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | Product price text. |
|
|
1099
|
-
| `--aia-product-compare-at-color` | `currentColor` | `currentColor` | The struck price before a markdown. Defaults to the price's colour. |
|
|
1100
|
-
| `--aia-product-compare-at-opacity` | `0.6` | `0.6` | How far the struck price is dimmed. |
|
|
1101
|
-
| `--aia-product-vendor-color` | `--aia-option-color` | `--aia-option-color` | Product vendor line. |
|
|
1102
|
-
| `--aia-product-focus-ring` | `--aia-option-color-selected` | `--aia-option-color-selected` | Focus ring drawn on a keyboard-focused card. |
|
|
1103
|
-
| `--aia-products-label-color` | `--aia-option-color` | `--aia-option-color` | "Products" section label. |
|
|
1104
|
-
| `--aia-product-title-font-size` | `12px` | `12px` | Product title font size. |
|
|
1105
|
-
| `--aia-product-price-font-size` | `11px` | `11px` | Product price font size. |
|
|
1106
|
-
| `--aia-product-vendor-font-size` | `10px` | `10px` | Product vendor font size. |
|
|
1107
|
-
| `--aia-products-label-font-size` | `11px` | `11px` | Section label font size. |
|
|
1108
|
-
| `--aia-date-panel-width` | `312px` | `312px` | Max width of the whole dropdown panel while the calendar is up — the panel narrows to calendar size. |
|
|
1109
|
-
| `--aia-date-cell-size` | `26px` | `26px` | Size of a day's square — the box that carries the highlight, the today ring and the selected fill. |
|
|
1110
|
-
| `--aia-date-row-height` | `28px` | `28px` | Height of one week row. Lower it to fit a 6-week month in a shorter dropdown. |
|
|
1111
|
-
| `--aia-date-cell-font-size` | `13px` | `13px` | Day-number font size. |
|
|
1112
|
-
| `--aia-date-month-font-size` | `14px` | `14px` | Font size of the "March 2026" header. |
|
|
1113
|
-
| `--aia-date-weekday-font-size` | `11px` | `11px` | Font size of the S/M/T/W/T/F/S column letters. |
|
|
1114
|
-
| `--aia-date-today-ring` | `--aia-option-color` | `--aia-option-color` | Outline drawn around today's date. |
|
|
1115
|
-
| `--aia-date-selected-bg` | white at 12% | white at 12% | Fill behind the date a re-edited parameter already holds. |
|
|
1116
|
-
| `--aia-date-range-bg` | white at 6% | white at 6% | Band across the days between the two ends of a picked date range. The ends themselves use `--aia-date-selected-bg`. |
|
|
1117
|
-
| `--aia-time-panel-width` | `240px` | `240px` | Max width of the whole dropdown panel while the time wheel is up. |
|
|
1118
|
-
| `--aia-time-font-size` | `15px` | `15px` | The time wheel's numbers and its `:` separator. |
|
|
1119
|
-
| `--aia-time-band-bg` | white at 8% | white at 8% | The band behind the wheels' top rows — the chosen time. |
|
|
1120
|
-
| `--aia-time-done-bg` | white at 10% | white at 10% | The time wheel's Done button. |
|
|
1121
|
-
| `--aia-time-done-bg-hover` | white at 16% | white at 16% | The Done button on hover. |
|
|
1122
|
-
| `--aia-time-done-color` | `--aia-option-color-selected` | `--aia-option-color-selected` | The Done button's text. |
|
|
1123
|
-
| `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color for the loading skeleton bars and masked text in cached pills/options, and of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |
|
|
1124
|
-
| `--aia-content-inset-left` | `16px` | `16px` | Left inset of the SDK's content: the input wrapper's left padding, and the line the dropdown's content (parameter label, option text, product strip) starts on. Set it when you pad the field to clear a leading icon of your own, so the dropdown's content stays aligned under the typed text. Practical minimum is `10px` (the option text's own inset); both surfaces floor it there. |
|
|
1125
|
-
| `--aia-footer-chip-bg` | `--aia-surface` at 65% | `--aia-surface` at 65% | Fill behind the footer's keyboard hint and AI-Autocomplete badge. The option list scrolls under the footer, so this keeps both legible over the row passing behind them. `transparent` on the glass surface. |
|
|
670
|
+
Every variable, with its default, is listed in [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "CSS variables".
|
|
1126
671
|
|
|
1127
672
|
### Per-mode Overrides
|
|
1128
673
|
|
|
@@ -1165,6 +710,7 @@ For styling beyond the CSS variables, target these stable `data-aia-*` attribute
|
|
|
1165
710
|
| `[data-aia-dropdown]` | The dropdown root (listbox). Carries `data-aia-has-products` while the product strip has cards, and `data-aia-fit` while it is fitted to a short screen (see [Short screens](#short-screens)). |
|
|
1166
711
|
| `[data-aia-datepicker]` | The calendar, rendered in place of the option list for a date parameter |
|
|
1167
712
|
| `[data-aia-time-wheel]` | The time wheel, rendered in place of the option list for a time parameter |
|
|
713
|
+
| `[data-aia-location]` | The location search, rendered in place of the option list for a location parameter without options (`[data-aia-location-input]` is its field, `[data-aia-location-row]` each place) |
|
|
1168
714
|
| `[data-aia-date-month]` | The "March 2026" header label |
|
|
1169
715
|
| `[data-aia-date-prev]` / `[data-aia-date-next]` | The month arrows |
|
|
1170
716
|
| `[data-aia-date-grid]` | The 7-column grid of day cells |
|
|
@@ -1260,18 +806,7 @@ How it behaves:
|
|
|
1260
806
|
|
|
1261
807
|
## Server-side rendering
|
|
1262
808
|
|
|
1263
|
-
The
|
|
1264
|
-
|
|
1265
|
-
```ts
|
|
1266
|
-
import { Inject, PLATFORM_ID } from "@angular/core";
|
|
1267
|
-
import { isPlatformBrowser } from "@angular/common";
|
|
1268
|
-
|
|
1269
|
-
constructor(@Inject(PLATFORM_ID) private platformId: object) {
|
|
1270
|
-
if (isPlatformBrowser(platformId)) {
|
|
1271
|
-
this.ac = new AIAutocompleteController({ ... });
|
|
1272
|
-
}
|
|
1273
|
-
}
|
|
1274
|
-
```
|
|
809
|
+
The Tier 1 component renders a static shell during SSR and mounts on the client. Tier 2 needs an `isPlatformBrowser` guard: see [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/REFERENCE.md), under "Server-side rendering".
|
|
1275
810
|
|
|
1276
811
|
## License
|
|
1277
812
|
|