@magicx-eng/ai-autocomplete-angular 0.55.0 → 0.56.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -150,7 +150,7 @@ export class SearchComponent {
150
150
 
151
151
  ### Imperative Handle
152
152
 
153
- The component exposes `focus()`, `blur()`, `reset()`, and `setMode()` as public instance methods — reach them through `@ViewChild`:
153
+ The component's public methods `focus()`, `blur()`, `reset()`, and `setMode()` are reached through `@ViewChild`:
154
154
 
155
155
  ```ts
156
156
  import { Component, ViewChild } from "@angular/core";
@@ -190,13 +190,13 @@ Pressing Backspace while the caret is inside or immediately after a bold complet
190
190
 
191
191
  ### Re-edit a completed param
192
192
 
193
- Tapping a bold completed param enters *re-edit mode* — the dropdown re-opens with the cached options the server originally returned for that param. From there:
193
+ Tapping a bold completed param enters *re-edit mode*: the dropdown re-opens with the cached options the server originally returned for that param. From there:
194
194
 
195
195
  - **Typing** atomically replaces the bold with what you type. If what you type exactly matches one of the cached options, it's re-promoted to a bold completed param immediately.
196
196
  - **Clicking an option** replaces the bold with the new selection.
197
197
  - **Arrow keys, Escape, or clicking outside the param** exit re-edit mode without changing anything.
198
198
 
199
- After a completed param is added (by any means — option click, exact-match typing, or re-edit), the caret always lands right after the trailing space following the bold so typing can continue immediately.
199
+ After a completed param is added (by option click, exact-match typing, or re-edit), the caret always lands right after the trailing space following the bold so typing can continue immediately.
200
200
 
201
201
  ---
202
202
 
@@ -339,7 +339,7 @@ import { AIAutocompleteModule } from "@magicx-eng/ai-autocomplete-angular";
339
339
  export class AppModule {}
340
340
  ```
341
341
 
342
- Standalone-first apps don't need this — import the components/directive directly.
342
+ Standalone-first apps don't need this: import the components/directive directly.
343
343
 
344
344
  ---
345
345
 
@@ -365,29 +365,30 @@ Standalone-first apps don't need this — import the components/directive direct
365
365
  | `dropdownTrigger` | `"auto" \| "manual" \| "hidden"` | `"auto"` | When the dropdown appears. `"auto"` = when options available. `"manual"` = only on pill tap, closes after selection. `"hidden"` = never shows. |
366
366
  | `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. |
367
367
  | `prependPlaceholder` | `boolean` | `true` | `false`: hint only. |
368
- | `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. |
368
+ | `showNonTappableOptions` | `boolean` | `true` | Non-tappable options are rendered alongside tappable ones in the dropdown. `false`: hide them. |
369
369
  | `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). |
370
- | `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 at the header's trailing edge, across from the label, once the input has text. Set to `false` to hide it. |
371
- | `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. |
372
- | `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. |
373
- | `showChipImages` | `boolean` | `true` | When `true`, a completed chip in the input draws the picture (`image_url`) of the option that answered it, in place of its icon. Set to `false` to render chips without pictures. |
374
- | `showOptionImages` | `boolean` | `true` | When `true`, an option that carries an `image_url` draws it as a square thumbnail before its text in the dropdown, in place of its icon. Set to `false` to render option rows without pictures. |
375
- | `showOptionCounts` | `boolean` | `true` | When `true`, an option that carries an `item_count` shows it as a muted label at the row's trailing edge (`"12 items"`). Set to `false` to hide the counts. |
370
+ | `showSkipButton` | `boolean` | `true` | The dropdown's pill bar ends in a small "skip" button that dismisses the active pill, as <kbd>→</kbd> at the end of the input does. It sits at the header's trailing edge, across from the label, once the input has text. `false` hides it. |
371
+ | `showOptionIcons` | `boolean` | `true` | An option that carries an `icon_svg` draws it before its text in the dropdown. `false`: text only. |
372
+ | `showChipIcons` | `boolean` | `true` | A completed chip in the input draws the icon of the option that answered it. `false`: text only. |
373
+ | `showChipImages` | `boolean` | `true` | A completed chip in the input draws the picture (`image_url`) of the option that answered it, in place of its icon. `false`: no pictures. |
374
+ | `showChipRemove` | `boolean` | `false` | `true`: every completed chip (not text the server only identified) ends in a faint × that removes it in one tap. Opacity: `--aia-chip-remove-opacity`, `--aia-chip-remove-opacity-hover`. |
375
+ | `showOptionImages` | `boolean` | `true` | An option that carries an `image_url` draws it as a square thumbnail before its text in the dropdown, in place of its icon. `false`: no pictures. |
376
+ | `showOptionCounts` | `boolean` | `true` | An option that carries an `item_count` shows it as a muted label at the row's trailing edge (`"12 items"`). `false`: no counts. |
376
377
  | `autoFocus` | `boolean` | `true` | Focus the input on mount. Set to `false` to leave focus to the consumer. |
377
378
  | `value` | `string` | — | Controlled text value. Pair with `(valueChange)` or use `[(value)]`. |
378
379
  | `completedParams` | `CompletedParamState[]` | — | Controlled completed params. Pair with `(completedParamsChange)` or use `[(completedParams)]`. |
379
- | `showProducts` | `boolean` | `true` | Render the product strip below the options whenever there are products to show — see [Product strip](#product-strip). Set to `false` to render no strip. |
380
- | `productsLayout` | `"row" \| "list"` | `"row"` | How the strip lays its cards out: a horizontally scrolling row, or the same cards stacked as full-width rows — see [Product strip](#product-strip). |
380
+ | `showProducts` | `boolean` | `true` | Render the product strip below the options whenever there are products to show; see [Product strip](#product-strip). `false` renders no strip. |
381
+ | `productsLayout` | `"row" \| "list"` | `"row"` | How the strip lays its cards out: a horizontally scrolling row, or the same cards stacked as full-width rows; see [Product strip](#product-strip). |
381
382
  | `productImageFallback` | `"image" \| "initial"` | `"image"` | Fallback for a missing or blank product image URL, or an image load error. `"image"` shows the placeholder pictogram; `"initial"` shows the title initial. A working image still takes priority. See [Product strip](#product-strip). |
382
- | `products` | `ProductsConfig` | — | Custom source for the product strip — see [Your own product search](#your-own-product-search-products). Bind a stable reference (a component field, not an inline object literal). Omit it and the strip shows the items the `/suggest` response reports. |
383
+ | `products` | `ProductsConfig` | — | Custom source for the product strip; see [Your own product search](#your-own-product-search-products). Bind a stable reference (a component field, not an inline object literal). Omit it and the strip shows the items the `/suggest` response reports. |
383
384
  | `onProductAddToCart` | `(product: Product) => void \| PromiseLike<unknown>` | — | When bound, every card that isn't sold out shows an add-to-cart button; pressing it calls this instead of emitting `(productSelect)`. Return a promise to show progress. An input rather than an output because its result drives the button. See [Product strip](#product-strip). |
384
- | `resetOnSubmit` | `boolean` | `true` | Clear the editor and start a new session after `(submitted)` emits. Set to `false` to keep the query in place — e.g. when the handler navigates away — and call `reset()` yourself. |
385
- | `submitButton` | `TemplateRef<unknown> \| null` | — | Custom submit button. Pass a `<ng-template>` to replace the default arrow button. Pass `null` to render no button. Clicks bubble up and trigger submit, so consumer-supplied buttons work without re-wiring. |
385
+ | `resetOnSubmit` | `boolean` | `true` | Clear the editor and start a new session after `(submitted)` emits. Set `false` to keep the query in place (e.g. when the handler navigates away) and call `reset()` yourself. |
386
+ | `submitButton` | `TemplateRef<unknown> \| null` | — | Custom submit button: a `<ng-template>` replaces the default arrow button, `null` renders none. Clicks bubble up and trigger submit, so your button needs no wiring. |
386
387
 
387
388
  | Output | Payload | Description |
388
389
  |---|---|---|
389
390
  | `submitted` | `AutocompleteResult` | Fires on Enter or submit-button click. |
390
- | `resultChange` | `AutocompleteResult` | Fires after every successful round-trip with the structured query as it now stands — see [Reading the query as it's built](#reading-the-query-as-its-built). |
391
+ | `resultChange` | `AutocompleteResult` | Fires after every successful round-trip with the structured query as it now stands; see [Reading the query as it's built](#reading-the-query-as-its-built). |
391
392
  | `errored` | `Error` | Fires when a fetch fails. |
392
393
  | `valueChange` | `string` | Two-way binding partner for `[value]`. |
393
394
  | `completedParamsChange` | `CompletedParamState[]` | Two-way binding partner for `[completedParams]`. |
@@ -488,7 +489,7 @@ The SDK handles token refresh transparently: 401 → `getAccessToken` → retry
488
489
 
489
490
  ### `AIAutocompleteController` (Tier 2)
490
491
 
491
- The headless logic surface for Tier 2 — the Angular equivalent of React's `useAIAutocomplete()` hook.
492
+ The headless logic surface for Tier 2: the Angular equivalent of React's `useAIAutocomplete()` hook.
492
493
 
493
494
  ```ts
494
495
  const ac = new AIAutocompleteController({
@@ -502,7 +503,7 @@ ac.destroy();
502
503
 
503
504
  #### Constructor options
504
505
 
505
- 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).
506
+ 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).
506
507
 
507
508
  #### State observables
508
509
 
@@ -510,13 +511,13 @@ Accepts the same shape as `<ai-autocomplete>`'s inputs (`apiConfig`, `additional
510
511
  |---|---|---|
511
512
  | `text$` | `Observable<string>` | Editor's plain-text content. |
512
513
  | `completedParams$` | `Observable<CompletedParamState[]>` | Bold completed params currently in the editor. |
513
- | `skippedParams$` | `Observable<SkippedParamState[]>` | Suggestions the user dismissed with <kbd>→</kbd>. Nothing renders them — pass them to `buildSubmitResult` for a hand-rolled submit. |
514
+ | `skippedParams$` | `Observable<SkippedParamState[]>` | Suggestions the user dismissed with <kbd>→</kbd>. Nothing renders them: pass them to `buildSubmitResult` for a hand-rolled submit. |
514
515
  | `identifiedParams$` | `Observable<IdentifiedParamState[]>` | Parameters the server recognised in the user's own words. Already rendered through `segments$`; pass them to `buildSubmitResult` for a hand-rolled submit so it reports the same `identified_params` the SDK's own results do. |
515
516
  | `suggestionPills$` | `Observable<Suggestion[]>` | Actionable suggestion pills (first item is the active pill). |
516
517
  | `segments$` | `Observable<Segment[]>` | Text + completed-param segments for rendering the editor body. |
517
518
  | `newParamId$` | `Observable<string \| null>` | ID of the most-recently-promoted param (drives shimmer animation). |
518
519
  | `suggestions$` | `Observable<Suggestion[]>` | All suggestions from the server (including non-actionable ones). |
519
- | `products$` | `Observable<Product[]>` | What the product strip shows: the items the latest response reported as matching the query, or the results of a custom `products` search — see [Product strip](#product-strip). |
520
+ | `products$` | `Observable<Product[]>` | What the product strip shows: the items the latest response reported as matching the query, or the results of a custom `products` search; see [Product strip](#product-strip). |
520
521
  | `customFields$` | `Observable<CustomFieldsReport \| null>` | The catalog report the latest response carried — applied and dropped filters, and the matching items' count and list — or `null` when it carried none. See [The catalog report](#the-catalog-report-customfields). |
521
522
  | `activeIndex$` | `Observable<number>` | Currently highlighted dropdown option index. `-1` = none. |
522
523
  | `isLoading$` | `Observable<boolean>` | UI-visible loading flag (suppressed during selection animation and re-edit). |
@@ -540,19 +541,20 @@ Every observable is gated by `distinctUntilChanged` + `shareReplay({ bufferSize:
540
541
  | `reset()` | Clear all state, rotate `session_id`, and re-fetch. Call after submit. |
541
542
  | `recordSubmit(result)` | Record a submit from a button you render. Enter is recorded for you; call this once per button submit. |
542
543
  | `selectOption(option)` | Pick a dropdown option (or replace the re-edited param if in re-edit mode). |
543
- | `selectProduct(product)` | Announce a product selection (fires `onProductSelect`). `<ai-autocomplete-dropdown>` calls this for you; hand-rolled strips call it themselves. Never navigates. |
544
- | `addProductToCart(product)` | Add a product through `onProductAddToCart`; returns a `Promise<void>` that settles with the handler's promise (rejecting with its error). `<ai-autocomplete-dropdown>`'s cart buttons call this for you; hand-rolled strips call it themselves. Does nothing without a handler. |
545
- | `hasProductAddToCart()` | Whether an `onProductAddToCart` handler is set — i.e. whether cards draw a cart button. Also on `dropdown$` as `hasProductAddToCart`. |
544
+ | `selectProduct(product)` | Announce a product selection (fires `onProductSelect`). `<ai-autocomplete-dropdown>` calls it; hand-rolled strips call it themselves. Never navigates. |
545
+ | `addProductToCart(product)` | Add a product through `onProductAddToCart`; returns a `Promise<void>` that settles with the handler's promise (rejecting with its error). `<ai-autocomplete-dropdown>`'s cart buttons call it; hand-rolled strips call it themselves. Does nothing without a handler. |
546
+ | `hasProductAddToCart()` | Whether an `onProductAddToCart` handler is set, i.e. whether cards draw a cart button. Also on `dropdown$` as `hasProductAddToCart`. |
546
547
  | `setActivePill(index)` | Promote the pill at `index` to active. |
547
- | `showPreviousMonth()` / `showNextMonth()` | Page the calendar a month at a time; paging never commits anything. `<ai-autocomplete-dropdown>` wires its own month arrows to these, so you only need them for a hand-rolled calendar. No-ops unless the active parameter is a date. |
548
- | `skipActivePill()` | Skip the active pill — same action as → / the dropdown's skip button. Records it in `skippedParams$`; no-ops during re-edit and the post-selection window. Use it to drive a custom skip affordance (e.g. with `[showSkipButton]="false"`). Also exposed as a Tier 1 component method. |
548
+ | `showPreviousMonth()` / `showNextMonth()` | Page the calendar by a month; paging commits nothing. `<ai-autocomplete-dropdown>`'s month arrows call these, so they are only for a hand-rolled calendar. No-ops unless the active parameter is a date. |
549
+ | `skipActivePill()` | Skip the active pill, as → or the dropdown's skip button does. Records it in `skippedParams$`; no-ops during re-edit and the post-selection window. Drives a custom skip control (e.g. with `[showSkipButton]="false"`). Also a Tier 1 component method. |
549
550
  | `removeLastParam()` | Drop the last completed param's "completed" status. |
551
+ | `removeParam(paramId)` | Remove the completed chip with that id (any value's id of one multi-select answer removes its joined chip), as Backspace at the chip's trailing edge or its × (`showChipRemove`) does. Returns `false`, changing nothing, when no completed chip has that id. |
550
552
  | `clearNewParamId()` | Clear the shimmer-animation state. |
551
553
  | `setValue(text)` | Controlled-mode setter for editor text. |
552
554
  | `setCompletedParams(params)` | Controlled-mode setter for completed params. |
553
- | `handleTextChange(value)` | Forward plain-text input from your `<textarea>` (the `[aiaInput]` directive does this for you). |
555
+ | `handleTextChange(value)` | Forward plain-text input from your `<textarea>` (`[aiaInput]` does this). |
554
556
  | `handleKeyDown(event)` | Forward keyboard events (also handled by `[aiaInput]`). |
555
- | `setFocused(focused)` | Notify the controller of focus state (custom inputs only — `[aiaInput]` does this). |
557
+ | `setFocused(focused)` | Notify the controller of focus state (custom inputs only; `[aiaInput]` does this). |
556
558
  | `handleCaretMove(offset)` | Report the caret position (plain-text offset) so arrow keys can move into the dropdown (custom inputs only). |
557
559
  | `setActiveDropdownIndex(index)` | Set the highlighted option index (typically driven by hover). |
558
560
  | `update(opts)` | Apply runtime changes to a subset of options (everything except event callbacks; `onProductAddToCart` can be set, swapped or removed). |
@@ -565,7 +567,7 @@ Every observable is gated by `distinctUntilChanged` + `shareReplay({ bufferSize:
565
567
  | `listboxId` | `string` | Stable ARIA listbox ID. |
566
568
  | `destroyed` | `boolean` | Whether `destroy()` has been called. |
567
569
  | `getState()` | `AIAutocompleteControllerState` | Synchronous snapshot of the current state. |
568
- | `getResult()` | `AutocompleteResult` | The structured query as it stands right now — the same object `onResult` delivers after each response. |
570
+ | `getResult()` | `AutocompleteResult` | The structured query as it stands right now: the same object `onResult` delivers after each response. |
569
571
 
570
572
  ### `[aiaInput]` directive
571
573
 
@@ -581,7 +583,7 @@ The directive automatically:
581
583
  - Forwards `input` / `keydown` / `focus` / `blur` to the controller.
582
584
  - Auto-capitalizes the first character of the user's first keystroke (matching the SDK's UX). Skipped during IME composition.
583
585
  - Mirrors the controller's `text$` back into the textarea (so programmatic `controller.setValue(...)` updates the DOM), preserving the cursor position when possible.
584
- - Implements `ControlValueAccessor` — use `[formControl]` or `[(ngModel)]` directly.
586
+ - Implements `ControlValueAccessor`: use `[formControl]` or `[(ngModel)]` directly.
585
587
 
586
588
  ### `<ai-autocomplete-dropdown>`
587
589
 
@@ -612,7 +614,7 @@ The structured query as the SDK currently understands it. The same object is emi
612
614
  | `completed_params` | `CompletedParam[]` | Filled parameter values in query order, followed by any the user skipped (see below). |
613
615
  | `identified_params` | `IdentifiedParam[]` | Parameters the server recognised in the user's own words, as `{ parameter, text }` — e.g. `{ parameter: "due_date", text: "Friday" }` when the user typed "by Friday" instead of picking a date. They are not tokenized in `raw_query`, and they are tentative: each response replaces the set, and an entry drops out as soon as its text is edited away. |
614
616
  | `is_ready` | `boolean` | Whether the server considers the query complete enough to act on. |
615
- | `custom_fields?` | `CustomFieldsReport` | What catalog grounding did for the latest applied response, when it read a catalog at all — see [Product strip](#product-strip). `applied_filters` and `dropped_filters` list the query's constraints as `{ parameter, value, op }`; `items.total` is how many items the applied ones left standing and `items.matched` the ones the strip renders. Absent (no key) when the response carried no report. |
617
+ | `custom_fields?` | `CustomFieldsReport` | What catalog grounding did for the latest applied response, when it read a catalog at all; see [Product strip](#product-strip). `applied_filters` and `dropped_filters` list the query's constraints as `{ parameter, value, op }`; `items.total` is how many items the applied ones left standing and `items.matched` the ones the strip renders. Absent (no key) when the response carried no report. |
616
618
 
617
619
  #### Reading the query as it's built
618
620
 
package/REFERENCE.md CHANGED
@@ -607,6 +607,8 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
607
607
  | `--aia-location-font-size` | `15px` | `15px` | The location field's text and the place names. |
608
608
  | `--aia-location-row-bg-highlighted` | `--aia-streak-rgb` at 8% (indigo) | `--aia-streak-rgb` at 8% (white) | The highlighted (or hovered) place. |
609
609
  | `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |
610
+ | `--aia-chip-remove-opacity` | `0.32` | `0.32` | Opacity of a completed chip's remove × (`showChipRemove`). The × is for a mouse or a tap and is hidden from assistive technology; from the keyboard, Backspace at the end of a chip removes it. |
611
+ | `--aia-chip-remove-opacity-hover` | `0.7` | `0.7` | Opacity of that × under a hovering pointer (never on touch). |
610
612
  | `--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. |
611
613
  | `--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. |
612
614