@magicx-eng/ai-autocomplete-angular 0.59.0 → 0.60.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.
Files changed (25) hide show
  1. package/README.md +1 -1
  2. package/REFERENCE.md +95 -1
  3. package/esm2020/lib/ai-autocomplete/ai-autocomplete.component.mjs +44 -6
  4. package/esm2020/lib/ai-autocomplete-dropdown/ai-autocomplete-dropdown.component.mjs +4 -3
  5. package/esm2020/lib/controller/ai-autocomplete.controller.mjs +26 -1
  6. package/esm2020/lib/internal/product-strip/product-strip.component.mjs +10 -3
  7. package/esm2020/lib/internal/submit-button/submit-button.component.mjs +10 -3
  8. package/esm2020/lib/shared/types.mjs +1 -1
  9. package/fesm2015/magicx-eng-ai-autocomplete-angular.mjs +91 -12
  10. package/fesm2015/magicx-eng-ai-autocomplete-angular.mjs.map +1 -1
  11. package/fesm2020/magicx-eng-ai-autocomplete-angular.mjs +89 -11
  12. package/fesm2020/magicx-eng-ai-autocomplete-angular.mjs.map +1 -1
  13. package/lib/ai-autocomplete/ai-autocomplete.component.d.ts +18 -1
  14. package/lib/ai-autocomplete/ai-autocomplete.component.d.ts.map +1 -1
  15. package/lib/ai-autocomplete-dropdown/ai-autocomplete-dropdown.component.d.ts +2 -0
  16. package/lib/ai-autocomplete-dropdown/ai-autocomplete-dropdown.component.d.ts.map +1 -1
  17. package/lib/controller/ai-autocomplete.controller.d.ts +24 -0
  18. package/lib/controller/ai-autocomplete.controller.d.ts.map +1 -1
  19. package/lib/internal/product-strip/product-strip.component.d.ts +6 -1
  20. package/lib/internal/product-strip/product-strip.component.d.ts.map +1 -1
  21. package/lib/internal/submit-button/submit-button.component.d.ts +6 -1
  22. package/lib/internal/submit-button/submit-button.component.d.ts.map +1 -1
  23. package/lib/shared/types.d.ts +27 -1
  24. package/lib/shared/types.d.ts.map +1 -1
  25. package/package.json +2 -2
package/README.md CHANGED
@@ -667,7 +667,7 @@ Styles are bundled with the package; the published library wires its CSS up auto
667
667
 
668
668
  Every class name the package emits is namespaced — `magicx-aia-*` for the classes it shares with the vanilla core, `aia-*` for its own — so nothing it renders can match a `.container`, `.pill` or `.dropdown` rule in your own stylesheet, and none of its rules can reach your elements. Use the `--aia-*` variables and `data-aia-*` selector hooks below for overrides.
669
669
 
670
- **Page CSS stops at the widget's edge.** Everything inside the input wrapper (`[data-aia-input-wrapper]`) and the dropdown (`[data-aia-dropdown]`) is reset to browser defaults before the SDK's own styles apply, so element and universal rules in your stylesheet — `button { … }`, `a { … }`, `* { … }`, a CSS reset, a framework's preflight — never reach it, and inherited typography adjustments from the page (line-height, letter-spacing, text-transform, text-align, …) are pinned at those two roots. Font family, size, weight and text colour still inherit from your page; a submit button you provide is left to your own stylesheet; and nothing the SDK ships styles elements outside its own subtree. The reset sits at specificity (0,0,5), below any rule that names a class, attribute or id — your overrides on the `data-aia-*` hooks work exactly as before, and so does a page rule like `.sidebar button { … }`, which names a class: scope rules like that to your own markup.
670
+ **Page CSS stops at the widget's edge.** Everything inside the input wrapper (`[data-aia-input-wrapper]`) and the dropdown (`[data-aia-dropdown]`) is reset to browser defaults before the SDK's own styles apply, so element and universal rules — `button { … }`, `a { … }`, `* { … }`, a CSS reset, a framework's preflight — never reach it, and inherited typography adjustments (line-height, letter-spacing, text-transform, text-align, …) are pinned at those two roots. Font family, size, weight and text colour still inherit from your page, and a submit button you provide is left to your own stylesheet. The reset sits at specificity (0,0,5), below any rule that names a class, attribute, id or pseudo-class: your `data-aia-*` overrides win, and so does a page rule like `.sidebar button { … }`: scope those to your own markup. A page-wide `:focus-visible` ring still reaches the widget's buttons but never its editor; to show focus on the field, set `--aia-focus-ring`.
671
671
 
672
672
  ### CSS Variables
673
673
 
package/REFERENCE.md CHANGED
@@ -3,6 +3,7 @@
3
3
  Longer guides that do not fit in the [README](https://unpkg.com/@magicx-eng/ai-autocomplete-angular/README.md) on the npm page. This file ships in the package, at `node_modules/@magicx-eng/ai-autocomplete-angular/REFERENCE.md`.
4
4
 
5
5
  - [Product strip](#product-strip)
6
+ - [While your page loads](#while-your-page-loads)
6
7
  - [Datepicker](#datepicker)
7
8
  - [Time picker](#time-picker)
8
9
  - [Multiple selections](#multiple-selections)
@@ -318,6 +319,96 @@ Tier 2 gets the same thing: pass `showProducts` / `products` /
318
319
  `products$` (and `customFields$`) and call `controller.selectProduct(product)`
319
320
  from their own cards.
320
321
 
322
+ ## While your page loads
323
+
324
+ A submit and a tap on a product card usually hand the shopper off to a page of your own, which can take a few seconds to load, on a phone especially. Until it does, the control that was pressed shows that the tap took, and a repeat of the same tap is ignored. This is on by default (`[submitProgress]`).
325
+
326
+ **What shows**
327
+
328
+ - **A submit**, by Enter (or the keyboard's Go) or the arrow button: the arrow button shows a spinner in place of the arrow. It keeps its size, stays enabled and carries `aria-busy="true"`. The controller reports it as `isSubmitting$` (and `getState().isSubmitting`).
329
+ - **A product card**: the tapped card shows a spinner over its picture and carries `aria-busy="true"`. With nothing bound to `(productSelect)` a card tap marks nothing. `dropdown$` carries its `id` as `busyProductId`.
330
+
331
+ **What is ignored meanwhile**
332
+
333
+ Only a repeat of the same thing, so one tap is one `(submitted)` or `(productSelect)` event:
334
+
335
+ - while a submit is in progress, another submit by any route (Enter (or the keyboard's Go) or the arrow button);
336
+ - while a product selection is in progress, another tap (or Enter / Space) on that same card.
337
+
338
+ Nothing else is held back. A tap on a different product card goes through at once and that card becomes the busy one. A cmd/ctrl-click or middle-click on a card still opens the link in a new tab and marks nothing. The add-to-cart button keeps its own spinner, and picking an option is unaffected.
339
+
340
+ **Every way it ends**, whichever comes first:
341
+
342
+ - **a promise settles**, where there is one to give. An output cannot return a promise, so `(submitted)` and `(productSelect)` have none. For a submit, call `controller.holdSubmit(promise)` from inside your `(submitted)` handler: the wait then ends when that promise settles, whether the submit came from Enter or the arrow. A product selection has no promise exit: use `controller.endSubmitProgress()` below;
343
+ - **the input changes**: typed text, a chip added or removed, `reset()`. A product selection also ends when the products change. With `[resetOnSubmit]` on (the default) the field clears right after `(submitted)`, so a submit is never marked and no spinner is drawn;
344
+ - **the shopper interacts with something else**: a press (`pointerdown`) or a key anywhere on the page outside the busy control. Once they are doing something else the page did not leave, so the spinner is stale: a quick view your handler opened clears the card's spinner at the first tap inside it, and inline results clear the submit's at the first tap or key elsewhere. Keys in the widget's own input do not count (typing there already ends it by the rule above);
345
+ - **you end it**: `endSubmitProgress()`, on the `<ai-autocomplete>` component (beside `focus()`, `blur()` and `reset()`) and on the controller, for when the work your handler started is done;
346
+ - **the page is shown again from the back/forward cache**, so a shopper who presses Back never finds a spinner still turning;
347
+ - **8 seconds pass**, for a handler that neither navigates nor does any of the above.
348
+
349
+ The spinner turns slower under `prefers-reduced-motion`.
350
+
351
+ Three things to know about those rules:
352
+
353
+ - Touch counts as interacting. A finger put down to scroll the page is a `pointerdown` like any other, so scrolling ends the wait.
354
+ - The repeat guard needs to see where a press landed. Inside a closed shadow root it cannot (an open one is fine), so there a repeat press ends the wait and goes through as a new one.
355
+ - A repeat Enter on an unchanged query is ignored while a submit is in progress, like a repeat press on the arrow.
356
+
357
+ **Custom submit buttons**
358
+
359
+ A `[submitButton]` template you pass in sits in a slot the SDK marks the same way as the built-in arrow: the slot (`[data-aia-submit-slot]`, around your template) carries `data-aia-submit-state="busy"` and `aria-busy="true"` while a submit is in progress, and a press is ignored meanwhile. The SDK draws nothing on it; style the state yourself, for example `[data-aia-submit-slot][data-aia-submit-state="busy"] button { opacity: 0.6; }`. A button you render yourself on the controller is yours entirely: `isSubmitting$` is the way to show the state.
360
+
361
+ So the exits Angular has are: the input changing, the shopper interacting elsewhere, Back, the 8 seconds, `controller.endSubmitProgress()`, and for a submit `controller.holdSubmit(promise)`. The interaction rule covers the common stay-on-page cases without any code: a quick view or inline results clear the spinner at the shopper's first tap or key in them.
362
+
363
+ If you render your own submit button on the controller: skip the submit while `isSubmitting$` is true, call `controller.holdSubmit(promise?)` right after you hand the submit on, and put `data-aia-submit` on the button so a press on it counts as the repeat rather than as the shopper moving on.
364
+
365
+ | | |
366
+ |---|---|
367
+ | `controller.isSubmitting$` / `getState().isSubmitting` | A submit is in progress. |
368
+ | `dropdown$` → `busyProductId` | The `id` of the product whose selection is in progress, else `null`. |
369
+ | `controller.holdSubmit(promise?)` | Mark a submit as in progress; a promise ends it when it settles. The arrow and Enter are marked for you. |
370
+ | `endSubmitProgress()` | End whatever is in progress, a submit or a product selection, now. On the component (`@ViewChild(AIAutocompleteComponent) ac` → `ac.endSubmitProgress()`) and on the controller. |
371
+
372
+ ### Turning it off
373
+
374
+ `[submitProgress]="false"` turns all of it off for that component, together: nothing is marked busy, no `aria-busy` is set, and every press emits again. The controller takes the same option (`submitProgress: false`, or `controller.update({ submitProgress })`); with it off `isSubmitting$` stays false, `busyProductId` stays null and `holdSubmit()` does nothing. It can change at any time; turning it off ends whatever was in progress.
375
+
376
+ If your page shows its results inline, leave it on: the spinner clears at the shopper's first tap or key outside the submit button. To end it exactly when the results are drawn, call `controller.endSubmitProgress()` then, or `controller.holdSubmit(promise)` from your `(submitted)` handler with a promise that settles then.
377
+
378
+ ### Styling the spinner
379
+
380
+ Each control carries a state attribute while it is busy, plus `aria-busy="true"`. The attributes are the stable styling hooks, the same in the vanilla, React and Angular packages; class names are not. The spinner is a pseudo-element:
381
+
382
+ | Place | Busy selector | Spinner |
383
+ |---|---|---|
384
+ | The arrow button | `[data-aia-submit][data-aia-submit-state="busy"]` | its `::after`; the arrow is its `svg`, hidden meanwhile |
385
+ | The tapped product card | `[data-aia-product][data-aia-product-state="busy"]` | `[data-aia-product-media]::before` inside it |
386
+
387
+ These variables restyle it; today's look is each one's fallback. Set them on the widget's container or any ancestor.
388
+
389
+ | Variable | Default | What it sets |
390
+ |---|---|---|
391
+ | `--aia-spinner-size` | `16px` | The spinner's diameter, in every place. |
392
+ | `--aia-spinner-width` | `2px` | Its stroke width, in every place. |
393
+ | `--aia-submit-spinner-color` | `currentColor` (the arrow's colour) | The spinner on the arrow button. |
394
+ | `--aia-product-spinner-color` | `--aia-product-cart-color`, then `#1f2328` | The arc on a product card. |
395
+ | `--aia-product-spinner-bg` | `--aia-product-cart-bg`, then `rgba(255, 255, 255, 0.94)` | The disc behind that arc. |
396
+
397
+ To hide the spinner and keep the behaviour (repeats still ignored, `aria-busy` still set), use CSS alone. The SDK's own rules add no specificity for the busy state, so these win whatever order the stylesheets load in:
398
+
399
+ ```css
400
+ [data-aia-submit][data-aia-submit-state="busy"]::after,
401
+ [data-aia-product][data-aia-product-state="busy"] [data-aia-product-media]::before {
402
+ display: none;
403
+ }
404
+ /* Keep the arrow on show in place of its spinner. */
405
+ [data-aia-submit][data-aia-submit-state="busy"] svg {
406
+ display: block;
407
+ }
408
+ ```
409
+
410
+ The same selectors take any other rule, for a look of your own: a dimmed card (`[data-aia-product][data-aia-product-state="busy"] { opacity: 0.6; }`), a different animation, a label change.
411
+
321
412
  ## Datepicker
322
413
 
323
414
  When the next parameter is a date, the dropdown shows a calendar instead of a
@@ -605,7 +696,10 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
605
696
  | `--aia-done-bg` / `--aia-done-bg-hover` / `--aia-done-color` | `#e4e8f0` / `#d8dde8` / `#2a3150` | `--aia-confirm-*` | The Done buttons (multi-select and time wheel). |
606
697
  | `--aia-multi-done-bg` / `--aia-multi-done-bg-hover` / `--aia-multi-done-color` | `--aia-done-*` | `--aia-done-*` | Override the multi-select Done button alone. |
607
698
  | `--aia-multi-done-width` | `100%` (classic: as wide as the widest option) | same | Width of the multi-select Done button. |
608
- | `--aia-panel-min-width` | `160px` | same | Narrowest the floating options box gets when it hugs its options (desktop). |
699
+ | `--aia-panel-min-width` | `160px` | same | Narrowest the floating options box gets when it hugs its options (desktop). Set `100%` to turn the hug off: the box then stays as wide as the field, up to `--aia-dropdown-max-width`. |
700
+ | `--aia-dropdown-max-width` | `544px` | same | Widest the floating options box gets. `none` lets it span the whole field (with `--aia-panel-min-width: 100%`, it always does). The calendar and the time wheel keep `--aia-date-panel-width` and `--aia-time-panel-width`. |
701
+ | `--aia-focus-ring` | `none` | same | Outline drawn around the whole field while it has focus, e.g. `2px solid #1668e3`. Off by default. The editor inside never draws a ring of its own, whatever your page's `:focus-visible` rule says, so this is where focus shows. |
702
+ | `--aia-focus-ring-offset` | `0px` | same | Gap between that ring and the field's border; negative draws it over the border. |
609
703
  | `--aia-multi-done-min-width` | `120px` | `120px` | Narrowest the multi-select Done button gets. |
610
704
  | `--aia-time-done-bg` / `--aia-time-done-bg-hover` / `--aia-time-done-color` | `--aia-done-*` | `--aia-done-*` | Override the time wheel's Done button alone. |
611
705
  | `--aia-location-field-bg-idle` | `transparent` | `transparent` | The location search field at rest. |