@magicx-eng/ai-autocomplete-react 0.61.1 → 0.62.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 CHANGED
@@ -268,7 +268,7 @@ function App() {
268
268
 
269
269
  | Prop | Type | Default | Description |
270
270
  |---|---|---|---|
271
- | `onSubmit` | `(result: AutocompleteResult) => void` | **required** | Called on Enter or submit button. |
271
+ | `onSubmit` | `(result: AutocompleteResult) => void \| PromiseLike<unknown>` | **required** | Called on Enter or submit button. Until the page it opens takes over, the submit is in progress: see [REFERENCE.md](https://unpkg.com/@magicx-eng/ai-autocomplete-react/REFERENCE.md), under "While your page loads". |
272
272
  | `onResult?` | `(result: AutocompleteResult) => void` | — | Called 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). |
273
273
  | `onError?` | `(error: Error) => void` | — | Called when a fetch fails. |
274
274
  | `apiConfig?` | `APIConfig` | — | Runtime API configuration (see below). |
@@ -310,10 +310,11 @@ function App() {
310
310
  | `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). |
311
311
  | `showProductVendor?` | `boolean` | `true` | Whether product cards draw the product's `vendor` as a line above the title. Set to `false` when your product titles already name the brand, so a card does not show it twice. See [Product strip](#product-strip). |
312
312
  | `products?` | `ProductsConfig` | — | Custom source for the product strip — see [Your own product search](#your-own-product-search-products). Omit it and the strip shows the items the `/suggest` response reports. |
313
- | `onProductSelect?` | `(product: Product) => void` | — | Called when a product card is activated. The SDK never navigates. |
313
+ | `onProductSelect?` | `(product: Product) => void \| PromiseLike<unknown>` | — | Called when a product card is activated. The SDK never navigates. The card shows a spinner until your page takes over. |
314
314
  | `onProductAddToCart?` | `(product: Product) => void \| PromiseLike<unknown>` | — | When set, every card that isn't sold out shows an add-to-cart button; pressing it calls this instead of `onProductSelect`. Return a promise to show progress. See [Product strip](#product-strip). |
315
315
  | `resetOnSubmit?` | `boolean` | `true` | Clear the input and start a new session after `onSubmit` runs. Set to `false` to keep the query in place — e.g. when `onSubmit` navigates away — and call the handle's `reset()` yourself. |
316
- | `seeAllResults?` | `boolean` | `false` | End the dropdown in a "See all results" button that submits like Enter (`onSubmit`, then `resetOnSubmit`), shown while there is typed text. The dropdown then keeps its full width at every step. Style it with the `--aia-see-all-*` tokens. |
316
+ | `seeAllResults?` | `boolean` | `false` | End the dropdown in a "See all results" button that submits like Enter (`onSubmit`, then `resetOnSubmit`), shown while there is typed text. The dropdown then keeps its full width at every step. Style it with the `--aia-see-all-*` tokens. While the submit it starts is in progress the button shows a spinner and ignores further taps. |
317
+ | `submitProgress?` | `boolean` | `true` | Show a spinner and ignore repeats on a submit or product tap while your page loads. `false` turns it off. See "While your page loads" in REFERENCE.md. |
317
318
  | `submitButton?` | `ReactNode` | — | Custom submit button. Pass any `ReactNode` 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 `onClick`. |
318
319
  | `ref?` | `Ref<AIAutocompleteHandle>` | — | Imperative handle with `focus()`, `blur()`, `reset()`, and `setMode()`. |
319
320
 
@@ -412,6 +413,8 @@ The headless hook for Tier 2 and Tier 3. Accepts the same options as `<AIAutocom
412
413
  | `activeIndex` | `number` | Highlighted option index. `-1` = none. |
413
414
  | `isLoading` | `boolean` | True when the dropdown should render its loading state — a fetch is in flight, no option-selection animation is playing, and the user is not in re-edit mode (where cached options stay visible). |
414
415
  | `isReady` | `boolean` | Server indicates query is complete. |
416
+ | `isSubmitting` | `boolean` | A submit is in progress: `onSubmit` ran and the page it opens has not taken over yet. |
417
+ | `selectingProductId` | `string \| null` | The `id` of the product whose selection is in progress, else `null`. |
415
418
  | `isDropdownOpen` | `boolean` | Whether the dropdown should be visible. Drive your own dropdown's visibility with this in Tier 3. |
416
419
  | `placeholderText` | `string` | Suggested placeholder text for the current step. |
417
420
  | `error` | `Error \| null` | Last fetch error. |
@@ -429,6 +432,7 @@ The headless hook for Tier 2 and Tier 3. Accepts the same options as `<AIAutocom
429
432
  | `clearNewParamId` | `() => void` | Clear shimmer animation state. |
430
433
  | `reset` | `() => void` | Clear all state, re-fetch, and start a new session (rotates `session_id`). Call this after handling submit. |
431
434
  | `recordSubmit` | `(result: AutocompleteResult) => void` | Record a submit from a button you render. Enter is recorded for you; call this once per button submit. |
435
+ | `holdSubmit` | `(returned?: unknown) => void` | Mark a submit you ran from your own button as in progress. Call it right after your handler, with what the handler returned. Enter is marked for you. |
432
436
  | `selectProduct` | `(product: Product) => void` | Announce a product selection (fires `onProductSelect`). The built-in dropdown calls this for you; hand-rolled strips call it themselves. Never navigates. |
433
437
  | `addProductToCart` | `(product: Product) => Promise<void>` | Add a product through `onProductAddToCart`. The built-in dropdown's cart buttons call this for you; hand-rolled strips call it themselves. Resolves when the handler's promise settles and rejects with its error; does nothing without a handler. |
434
438
 
@@ -469,7 +473,9 @@ The dropdown component for Tier 2. Spread `dropdownProps` from the hook (and add
469
473
  | `products?` | `Product[]` | Product cards to render below the options grid. Empty renders no strip. |
470
474
  | `productImageFallback?` | `"image" \| "initial"` | Default: `"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). Forwarded by the hook in `dropdownProps`. |
471
475
  | `showProductVendor?` | `boolean` | Default: `true`. Whether product cards draw the product's `vendor` as a line above the title. Set to `false` when your product titles already name the brand, so a card does not show it twice. See [Product strip](#product-strip). Forwarded by the hook in `dropdownProps`. |
472
- | `onProductSelect?` | `(product: Product) => void` | Called when a card is activated. |
476
+ | `onProductSelect?` | `(product: Product) => void \| PromiseLike<unknown>` | Called when a card is activated. |
477
+ | `busyProductId?` | `string \| null` | The product whose selection is in progress: its card shows a spinner. Provided by `dropdownProps`. |
478
+ | `seeAllBusy?` | `boolean` | A submit is in progress: "See all results" shows a spinner and ignores a press. Provided by `dropdownProps`. |
473
479
  | `onProductAddToCart?` | `(product: Product) => void \| PromiseLike<unknown>` | When set, every card that isn't sold out draws an add-to-cart button whose press calls this. See [Product strip](#product-strip). |
474
480
  | `onProductFocusChange?` | `(focused: boolean) => void` | Called when focus enters/leaves the strip. Wired to `setFocused` by `dropdownProps` so a tabbed-to card doesn't close the panel. |
475
481
  | `isLoading?` | `boolean` | When `true`, the dropdown fades its cached pills + options out over 160ms, keeping their space (an empty placeholder holds it when nothing is cached). |
@@ -532,7 +538,7 @@ Styles are auto-injected at runtime — no CSS import needed. Built-in light and
532
538
 
533
539
  Every class name the package emits is namespaced — `aia-*` for its own (hashed CSS-module) classes and the layout primitives, `magicx-aia-*` for the classes it shares with the vanilla core — 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.
534
540
 
535
- **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.
541
+ **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`.
536
542
 
537
543
  ### CSS Variables
538
544
 
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-react/README.md) on the npm page. This file ships in the package, at `node_modules/@magicx-eng/ai-autocomplete-react/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)
@@ -311,6 +312,98 @@ Tier 2 gets the same thing: `useAIAutocomplete()` takes `showProducts`,
311
312
  `products` (and `customFields`) from the hook and call
312
313
  `selectProduct(product)` from their own cards.
313
314
 
315
+ ## While your page loads
316
+
317
+ 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`).
318
+
319
+ **What shows**
320
+
321
+ - **A submit**, by Enter (or the keyboard's Go), the arrow button, or "See all results": the arrow button shows a spinner in place of the arrow, and "See all results" shows one beside its label. Both keep their size, stay enabled and carry `aria-busy="true"`. The hook reports it as `isSubmitting`.
322
+ - **A product card**: the tapped card shows a spinner over its picture and carries `aria-busy="true"`. With no `onProductSelect` prop a card tap marks nothing. The hook reports its `id` as `selectingProductId`.
323
+
324
+ **What is ignored meanwhile**
325
+
326
+ Only a repeat of the same thing, so one tap is one `onSubmit` or `onProductSelect` call:
327
+
328
+ - while a submit is in progress, another submit by any route (Enter (or the keyboard's Go), the arrow button, or "See all results");
329
+ - while a product selection is in progress, another tap (or Enter / Space) on that same card.
330
+
331
+ 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.
332
+
333
+ **Every way it ends**, whichever comes first:
334
+
335
+ - **a promise your handler returned settles**, resolved or rejected. Return one from `onSubmit` / `onProductSelect` when the work stays on the page (inline results, a quick view), so the spinner lasts exactly as long as the work. A rejection is still reported to the page as an unhandled rejection unless you catch it;
336
+ - **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 `onSubmit`, so a submit is never marked and no spinner is drawn;
337
+ - **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);
338
+ - **you end it**: `endSubmitProgress()` (on the hook and on the component's ref handle), for when the work your handler started is done;
339
+ - **the page is shown again from the back/forward cache**, so a shopper who presses Back never finds a spinner still turning;
340
+ - **8 seconds pass**, for a handler that neither navigates nor does any of the above.
341
+
342
+ The spinner turns slower under `prefers-reduced-motion`.
343
+
344
+ Four things to know about those rules:
345
+
346
+ - Touch counts as interacting. A finger put down to scroll the page is a `pointerdown` like any other, so scrolling ends the wait.
347
+ - 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.
348
+ - A repeat Enter on an unchanged query is ignored while a submit is in progress, like a repeat press on the arrow.
349
+ - If you both return a promise and catch its rejection yourself, the page sees one extra `unhandledrejection` for it: return the caught promise instead (`return work.catch(report)`).
350
+
351
+ **Custom submit buttons**
352
+
353
+ A `submitButton` node 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 node) 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 with the hook (Tier 2 or 3) is yours entirely: `isSubmitting` is the way to show the state.
354
+
355
+ With the hook and your own submit button (Tier 2 or 3): skip the submit while `isSubmitting` is `true`, call `holdSubmit(returned)` right after your handler with what it returned, and put `data-aia-submit` on the button so a press on it counts as the repeat rather than as the shopper moving on. `dropdownProps` already carries the product cards' and the "See all results" button's state.
356
+
357
+ | | |
358
+ |---|---|
359
+ | `isSubmitting` | `boolean`. A submit is in progress. |
360
+ | `selectingProductId` | `string \| null`. The `id` of the product whose selection is in progress, else `null`. |
361
+ | `holdSubmit(returned?)` | Mark a submit you ran from your own button as in progress. Enter is marked for you. |
362
+ | `endSubmitProgress()` | End whatever is in progress, a submit or a product selection, now. Also on `<AIAutocomplete>`'s ref handle. |
363
+
364
+ ### Turning it off
365
+
366
+ `submitProgress={false}` turns all of it off for that component, together: nothing is marked busy, no `aria-busy` is set, and every press calls your handler again. The hook takes the same option; with it off `isSubmitting` stays `false`, `selectingProductId` stays `null` and `holdSubmit()` does nothing. It can change at any time; turning it off ends whatever was in progress.
367
+
368
+ If your page shows its results inline, leave it on and return a promise from `onSubmit` (and from `onProductSelect`) that settles when the results are on screen: the spinner then lasts exactly as long as the work, with no 8 second wait.
369
+
370
+ ### Styling the spinner
371
+
372
+ 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:
373
+
374
+ | Place | Busy selector | Spinner |
375
+ |---|---|---|
376
+ | The arrow button | `[data-aia-submit][data-aia-submit-state="busy"]` | its `::after`; the arrow is its `svg`, hidden meanwhile |
377
+ | "See all results" | `[data-aia-see-all] [data-aia-see-all-state="busy"]` | its `::after` |
378
+ | The tapped product card | `[data-aia-product][data-aia-product-state="busy"]` | `[data-aia-product-media]::before` inside it |
379
+
380
+ These variables restyle it; today's look is each one's fallback. Set them on the widget's container or any ancestor.
381
+
382
+ | Variable | Default | What it sets |
383
+ |---|---|---|
384
+ | `--aia-spinner-size` | `16px` | The spinner's diameter, in every place. |
385
+ | `--aia-spinner-width` | `2px` | Its stroke width, in every place. |
386
+ | `--aia-submit-spinner-color` | `currentColor` (the arrow's colour) | The spinner on the arrow button. |
387
+ | `--aia-see-all-spinner-color` | `currentColor` (the label's colour) | The spinner beside "See all results". |
388
+ | `--aia-product-spinner-color` | `--aia-product-cart-color`, then `#1f2328` | The arc on a product card. |
389
+ | `--aia-product-spinner-bg` | `--aia-product-cart-bg`, then `rgba(255, 255, 255, 0.94)` | The disc behind that arc. |
390
+
391
+ 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:
392
+
393
+ ```css
394
+ [data-aia-submit][data-aia-submit-state="busy"]::after,
395
+ [data-aia-see-all] [data-aia-see-all-state="busy"]::after,
396
+ [data-aia-product][data-aia-product-state="busy"] [data-aia-product-media]::before {
397
+ display: none;
398
+ }
399
+ /* Keep the arrow on show in place of its spinner. */
400
+ [data-aia-submit][data-aia-submit-state="busy"] svg {
401
+ display: block;
402
+ }
403
+ ```
404
+
405
+ 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.
406
+
314
407
  ## Datepicker
315
408
 
316
409
  When the next parameter is a date, the dropdown shows a calendar instead of a
@@ -606,10 +699,16 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
606
699
  | `--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
700
  | `--aia-multi-done-bg-beside-see-all` / `--aia-multi-done-color-beside-see-all` | `transparent` / `--aia-option-color-selected` | `transparent` / `--aia-option-color-selected` | The multi-select Done button's fill and label colour at rest while "See all results" is shown under it, so the two do not compete (hover keeps `--aia-multi-done-bg-hover` and the Done colour). `--aia-multi-done-bg` and `--aia-done-bg` do not apply in this state. |
608
701
  | `--aia-multi-done-width` | `100%` (classic: as wide as the widest option) | same | Width of the multi-select Done button. |
609
- | `--aia-panel-min-width` | `160px` | same | Narrowest the floating options box gets when it hugs its options (desktop). |
702
+ | `--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`. |
703
+ | `--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`. |
704
+ | `--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. |
705
+ | `--aia-focus-ring-offset` | `0px` | same | Gap between that ring and the field's border; negative draws it over the border. |
610
706
  | `--aia-multi-done-min-width` | `120px` | `120px` | Narrowest the multi-select Done button gets. |
611
707
  | `--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. |
612
708
  | `--aia-see-all-bg` / `--aia-see-all-bg-hover` / `--aia-see-all-color` | `#2b2b2b` / `#3d3d3d` / `#ffffff` | `--aia-confirm-*` | The "See all results" button (`seeAllResults`). |
709
+ | `--aia-spinner-size` / `--aia-spinner-width` | `16px` / `2px` | same | The spinner a submit or product tap shows while your page loads: its diameter and stroke width. See "While your page loads". |
710
+ | `--aia-submit-spinner-color` / `--aia-see-all-spinner-color` | `currentColor` | same | That spinner on the arrow button and beside "See all results". |
711
+ | `--aia-product-spinner-color` / `--aia-product-spinner-bg` | `--aia-product-cart-color` / `--aia-product-cart-bg` | same | That spinner's arc and disc on a product card. |
613
712
  | `--aia-see-all-height` / `--aia-see-all-radius` / `--aia-see-all-font-size` | `48px` / `12px` / `16px` | same | Its minimum height, corner radius and text size. |
614
713
  | `--aia-location-field-bg-idle` | `transparent` | `transparent` | The location search field at rest. |
615
714
  | `--aia-location-field-bg` | `--aia-streak-rgb` at 6% (indigo) | `--aia-streak-rgb` at 6% (white) | The location search field on hover or focus. |
package/dist/index.d.mts CHANGED
@@ -21,10 +21,21 @@ interface AIAutocompleteHandle {
21
21
  * drive skipping from their own UI without dropping to Tier 2.
22
22
  */
23
23
  skipActivePill: () => void;
24
+ /**
25
+ * Ends whatever is in progress, a submit or a product selection, at once:
26
+ * call it when the work your handler started is done and the shopper is
27
+ * still on the page (a quick view opened, inline results drawn).
28
+ */
29
+ endSubmitProgress: () => void;
24
30
  }
25
31
  interface AIAutocompleteProps {
26
- /** Called on Enter or submit-button click with the final structured query. */
27
- onSubmit: (result: AutocompleteResult) => void;
32
+ /**
33
+ * Called on Enter or submit-button click with the final structured query.
34
+ * Until the page it opens takes over, the submit is in progress: the submit
35
+ * controls show a spinner and a further submit is ignored. Return a promise
36
+ * to say when it is over, for a submit that stays on the page.
37
+ */
38
+ onSubmit: (result: AutocompleteResult) => void | PromiseLike<unknown>;
28
39
  /**
29
40
  * Called after every successful suggestion round-trip with the structured
30
41
  * query as the SDK now understands it — the same `AutocompleteResult` shape
@@ -152,6 +163,16 @@ interface AIAutocompleteProps {
152
163
  * and run no custom search.
153
164
  */
154
165
  showProducts?: boolean;
166
+ /**
167
+ * When true (default), a submit and a product card tap show that they took
168
+ * while the page they open loads: the submit controls and the tapped card
169
+ * show a spinner, and a repeat of the same tap is ignored until it is over
170
+ * (a promise the handler returned settles, the input changes, the shopper
171
+ * presses or types somewhere else, the page is shown again from the
172
+ * back/forward cache, or 8 seconds pass). Set to false to turn
173
+ * all of it off: nothing is marked, and every press calls your handler.
174
+ */
175
+ submitProgress?: boolean;
155
176
  /**
156
177
  * How the product strip lays its cards out. `"row"` (the default) is a
157
178
  * horizontally scrolling shelf of cards. `"list"` stacks the same cards as
@@ -207,7 +228,7 @@ interface AIAutocompleteProps {
207
228
  * you decide what a selection means. Modifier / middle clicks are left to the
208
229
  * browser (so cmd-click still opens a tab) and don't fire this.
209
230
  */
210
- onProductSelect?: (product: Product) => void;
231
+ onProductSelect?: (product: Product) => void | PromiseLike<unknown>;
211
232
  /**
212
233
  * Adds a product to the cart from its card. When set, every card that isn't
213
234
  * sold out (`available: false`) shows an add-to-cart button in the bottom
@@ -249,8 +270,11 @@ interface AIAutocompleteProps {
249
270
  seeAllResults?: boolean;
250
271
  }
251
272
  interface UseAIAutocompleteOptions {
252
- /** Called on Enter with the final structured query. */
253
- onSubmit?: (result: AutocompleteResult) => void;
273
+ /**
274
+ * Called on Enter with the final structured query. A promise it returns
275
+ * ends `isSubmitting` when it settles.
276
+ */
277
+ onSubmit?: (result: AutocompleteResult) => void | PromiseLike<unknown>;
254
278
  /**
255
279
  * Called after every successful suggestion round-trip with the structured
256
280
  * query as the SDK now understands it — see `AIAutocompleteProps.onResult`.
@@ -359,6 +383,16 @@ interface UseAIAutocompleteOptions {
359
383
  * and run no custom search.
360
384
  */
361
385
  showProducts?: boolean;
386
+ /**
387
+ * When true (default), a submit and a product card tap show that they took
388
+ * while the page they open loads: the submit controls and the tapped card
389
+ * show a spinner, and a repeat of the same tap is ignored until it is over
390
+ * (a promise the handler returned settles, the input changes, the shopper
391
+ * presses or types somewhere else, the page is shown again from the
392
+ * back/forward cache, or 8 seconds pass). Set to false to turn
393
+ * all of it off: nothing is marked, and every press calls your handler.
394
+ */
395
+ submitProgress?: boolean;
362
396
  /**
363
397
  * How the product strip lays its cards out. `"row"` (the default) is a
364
398
  * horizontally scrolling shelf of cards. `"list"` stacks the same cards as
@@ -414,7 +448,7 @@ interface UseAIAutocompleteOptions {
414
448
  * you decide what a selection means. Modifier / middle clicks are left to the
415
449
  * browser (so cmd-click still opens a tab) and don't fire this.
416
450
  */
417
- onProductSelect?: (product: Product) => void;
451
+ onProductSelect?: (product: Product) => void | PromiseLike<unknown>;
418
452
  /**
419
453
  * Adds a product to the cart from its card. When set, every card that isn't
420
454
  * sold out (`available: false`) shows an add-to-cart button in the bottom
@@ -492,6 +526,32 @@ interface UseAIAutocompleteReturn {
492
526
  * from a submit button you render, so each submit is counted once.
493
527
  */
494
528
  recordSubmit: (result: AutocompleteResult) => void;
529
+ /**
530
+ * Marks a submit you ran from your own button as in progress
531
+ * (`isSubmitting`): call it right after your handler, with what the handler
532
+ * returned. A promise ends it when it settles; otherwise it ends when the
533
+ * input changes, when the page is shown again from the back/forward cache,
534
+ * or after 8 seconds. Enter is marked by the SDK.
535
+ */
536
+ holdSubmit: (returned?: unknown) => void;
537
+ /**
538
+ * Ends whatever is in progress, a submit or a product selection, at once:
539
+ * call it when the work your handler started is done and the shopper is
540
+ * still on the page (a quick view opened, inline results drawn).
541
+ */
542
+ endSubmitProgress: () => void;
543
+ /**
544
+ * A submit is in progress: `onSubmit` ran and the page it opens has not
545
+ * taken over yet. Enter is ignored meanwhile; skip your own button's submit
546
+ * while it is true.
547
+ */
548
+ isSubmitting: boolean;
549
+ /**
550
+ * The `id` of the product whose selection is in progress (`onProductSelect`
551
+ * ran, its page has not taken over yet), else null. Selecting it again
552
+ * is ignored meanwhile; another product goes through and takes its place.
553
+ */
554
+ selectingProductId: string | null;
495
555
  segments: Segment[];
496
556
  newParamId: string | null;
497
557
  clearNewParamId: () => void;
@@ -672,7 +732,7 @@ interface AIAutocompleteDropdownProps {
672
732
  /** Product cards to render below the options grid. Provided by `dropdownProps` from the hook. Empty (the default) renders no strip. */
673
733
  products?: Product[];
674
734
  /** Called when a product card is activated. Provided by `dropdownProps` from the hook. */
675
- onProductSelect?: (product: Product) => void;
735
+ onProductSelect?: (product: Product) => void | PromiseLike<unknown>;
676
736
  /**
677
737
  * Called when a card's add-to-cart button is pressed. When set, every card
678
738
  * that isn't sold out draws the button; when unset, none do. Provided by
@@ -749,6 +809,16 @@ interface AIAutocompleteDropdownProps {
749
809
  * submit while the field holds typed text. Omitted → no button.
750
810
  */
751
811
  onSeeAllResults?: () => void;
812
+ /**
813
+ * A submit is in progress: the "See all results" button shows a spinner and
814
+ * ignores a press. Provided by `dropdownProps` from the hook. Default false.
815
+ */
816
+ seeAllBusy?: boolean;
817
+ /**
818
+ * The `id` of the product whose selection is in progress: its card shows a
819
+ * spinner. Provided by `dropdownProps` from the hook. Default null.
820
+ */
821
+ busyProductId?: string | null;
752
822
  /**
753
823
  * Keep the panel at its full width at every step instead of hugging its
754
824
  * options, so drawing "See all results" never changes its width.
@@ -792,8 +862,8 @@ interface AIAutocompleteDropdownProps {
792
862
 
793
863
  declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProps & react.RefAttributes<AIAutocompleteHandle>>;
794
864
 
795
- declare function AIAutocompleteDropdown({ suggestions, activeIndex, onSelect, onHighlight, onUnhighlight, isOpen, id, className, pills, onPillClick, showPills, onSkip, showSkipButton, showOptionIcons, showOptionImages, showOptionCounts, skipDisabled, activeSelected, isLoading, skeletonExiting, isInputEmpty, language, products, onProductSelect, onProductAddToCart, onProductFocusChange, productsLayout, productImageFallback, showProductVendor, formatType, dateView, selectedDateIso, selectedDateRange, dateRangeStart, dateReferences, onPreviousMonth, onNextMonth, timeView, multiSelectView, onMultiSelectCommit, onSeeAllResults, fullWidth, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
865
+ declare function AIAutocompleteDropdown({ suggestions, activeIndex, onSelect, onHighlight, onUnhighlight, isOpen, id, className, pills, onPillClick, showPills, onSkip, showSkipButton, showOptionIcons, showOptionImages, showOptionCounts, skipDisabled, activeSelected, isLoading, skeletonExiting, isInputEmpty, language, products, onProductSelect, onProductAddToCart, onProductFocusChange, productsLayout, productImageFallback, showProductVendor, formatType, dateView, selectedDateIso, selectedDateRange, dateRangeStart, dateReferences, onPreviousMonth, onNextMonth, timeView, multiSelectView, onMultiSelectCommit, onSeeAllResults, seeAllBusy, busyProductId, fullWidth, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
796
866
 
797
- declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
867
+ declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, submitProgress, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
798
868
 
799
869
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };
package/dist/index.d.ts CHANGED
@@ -21,10 +21,21 @@ interface AIAutocompleteHandle {
21
21
  * drive skipping from their own UI without dropping to Tier 2.
22
22
  */
23
23
  skipActivePill: () => void;
24
+ /**
25
+ * Ends whatever is in progress, a submit or a product selection, at once:
26
+ * call it when the work your handler started is done and the shopper is
27
+ * still on the page (a quick view opened, inline results drawn).
28
+ */
29
+ endSubmitProgress: () => void;
24
30
  }
25
31
  interface AIAutocompleteProps {
26
- /** Called on Enter or submit-button click with the final structured query. */
27
- onSubmit: (result: AutocompleteResult) => void;
32
+ /**
33
+ * Called on Enter or submit-button click with the final structured query.
34
+ * Until the page it opens takes over, the submit is in progress: the submit
35
+ * controls show a spinner and a further submit is ignored. Return a promise
36
+ * to say when it is over, for a submit that stays on the page.
37
+ */
38
+ onSubmit: (result: AutocompleteResult) => void | PromiseLike<unknown>;
28
39
  /**
29
40
  * Called after every successful suggestion round-trip with the structured
30
41
  * query as the SDK now understands it — the same `AutocompleteResult` shape
@@ -152,6 +163,16 @@ interface AIAutocompleteProps {
152
163
  * and run no custom search.
153
164
  */
154
165
  showProducts?: boolean;
166
+ /**
167
+ * When true (default), a submit and a product card tap show that they took
168
+ * while the page they open loads: the submit controls and the tapped card
169
+ * show a spinner, and a repeat of the same tap is ignored until it is over
170
+ * (a promise the handler returned settles, the input changes, the shopper
171
+ * presses or types somewhere else, the page is shown again from the
172
+ * back/forward cache, or 8 seconds pass). Set to false to turn
173
+ * all of it off: nothing is marked, and every press calls your handler.
174
+ */
175
+ submitProgress?: boolean;
155
176
  /**
156
177
  * How the product strip lays its cards out. `"row"` (the default) is a
157
178
  * horizontally scrolling shelf of cards. `"list"` stacks the same cards as
@@ -207,7 +228,7 @@ interface AIAutocompleteProps {
207
228
  * you decide what a selection means. Modifier / middle clicks are left to the
208
229
  * browser (so cmd-click still opens a tab) and don't fire this.
209
230
  */
210
- onProductSelect?: (product: Product) => void;
231
+ onProductSelect?: (product: Product) => void | PromiseLike<unknown>;
211
232
  /**
212
233
  * Adds a product to the cart from its card. When set, every card that isn't
213
234
  * sold out (`available: false`) shows an add-to-cart button in the bottom
@@ -249,8 +270,11 @@ interface AIAutocompleteProps {
249
270
  seeAllResults?: boolean;
250
271
  }
251
272
  interface UseAIAutocompleteOptions {
252
- /** Called on Enter with the final structured query. */
253
- onSubmit?: (result: AutocompleteResult) => void;
273
+ /**
274
+ * Called on Enter with the final structured query. A promise it returns
275
+ * ends `isSubmitting` when it settles.
276
+ */
277
+ onSubmit?: (result: AutocompleteResult) => void | PromiseLike<unknown>;
254
278
  /**
255
279
  * Called after every successful suggestion round-trip with the structured
256
280
  * query as the SDK now understands it — see `AIAutocompleteProps.onResult`.
@@ -359,6 +383,16 @@ interface UseAIAutocompleteOptions {
359
383
  * and run no custom search.
360
384
  */
361
385
  showProducts?: boolean;
386
+ /**
387
+ * When true (default), a submit and a product card tap show that they took
388
+ * while the page they open loads: the submit controls and the tapped card
389
+ * show a spinner, and a repeat of the same tap is ignored until it is over
390
+ * (a promise the handler returned settles, the input changes, the shopper
391
+ * presses or types somewhere else, the page is shown again from the
392
+ * back/forward cache, or 8 seconds pass). Set to false to turn
393
+ * all of it off: nothing is marked, and every press calls your handler.
394
+ */
395
+ submitProgress?: boolean;
362
396
  /**
363
397
  * How the product strip lays its cards out. `"row"` (the default) is a
364
398
  * horizontally scrolling shelf of cards. `"list"` stacks the same cards as
@@ -414,7 +448,7 @@ interface UseAIAutocompleteOptions {
414
448
  * you decide what a selection means. Modifier / middle clicks are left to the
415
449
  * browser (so cmd-click still opens a tab) and don't fire this.
416
450
  */
417
- onProductSelect?: (product: Product) => void;
451
+ onProductSelect?: (product: Product) => void | PromiseLike<unknown>;
418
452
  /**
419
453
  * Adds a product to the cart from its card. When set, every card that isn't
420
454
  * sold out (`available: false`) shows an add-to-cart button in the bottom
@@ -492,6 +526,32 @@ interface UseAIAutocompleteReturn {
492
526
  * from a submit button you render, so each submit is counted once.
493
527
  */
494
528
  recordSubmit: (result: AutocompleteResult) => void;
529
+ /**
530
+ * Marks a submit you ran from your own button as in progress
531
+ * (`isSubmitting`): call it right after your handler, with what the handler
532
+ * returned. A promise ends it when it settles; otherwise it ends when the
533
+ * input changes, when the page is shown again from the back/forward cache,
534
+ * or after 8 seconds. Enter is marked by the SDK.
535
+ */
536
+ holdSubmit: (returned?: unknown) => void;
537
+ /**
538
+ * Ends whatever is in progress, a submit or a product selection, at once:
539
+ * call it when the work your handler started is done and the shopper is
540
+ * still on the page (a quick view opened, inline results drawn).
541
+ */
542
+ endSubmitProgress: () => void;
543
+ /**
544
+ * A submit is in progress: `onSubmit` ran and the page it opens has not
545
+ * taken over yet. Enter is ignored meanwhile; skip your own button's submit
546
+ * while it is true.
547
+ */
548
+ isSubmitting: boolean;
549
+ /**
550
+ * The `id` of the product whose selection is in progress (`onProductSelect`
551
+ * ran, its page has not taken over yet), else null. Selecting it again
552
+ * is ignored meanwhile; another product goes through and takes its place.
553
+ */
554
+ selectingProductId: string | null;
495
555
  segments: Segment[];
496
556
  newParamId: string | null;
497
557
  clearNewParamId: () => void;
@@ -672,7 +732,7 @@ interface AIAutocompleteDropdownProps {
672
732
  /** Product cards to render below the options grid. Provided by `dropdownProps` from the hook. Empty (the default) renders no strip. */
673
733
  products?: Product[];
674
734
  /** Called when a product card is activated. Provided by `dropdownProps` from the hook. */
675
- onProductSelect?: (product: Product) => void;
735
+ onProductSelect?: (product: Product) => void | PromiseLike<unknown>;
676
736
  /**
677
737
  * Called when a card's add-to-cart button is pressed. When set, every card
678
738
  * that isn't sold out draws the button; when unset, none do. Provided by
@@ -749,6 +809,16 @@ interface AIAutocompleteDropdownProps {
749
809
  * submit while the field holds typed text. Omitted → no button.
750
810
  */
751
811
  onSeeAllResults?: () => void;
812
+ /**
813
+ * A submit is in progress: the "See all results" button shows a spinner and
814
+ * ignores a press. Provided by `dropdownProps` from the hook. Default false.
815
+ */
816
+ seeAllBusy?: boolean;
817
+ /**
818
+ * The `id` of the product whose selection is in progress: its card shows a
819
+ * spinner. Provided by `dropdownProps` from the hook. Default null.
820
+ */
821
+ busyProductId?: string | null;
752
822
  /**
753
823
  * Keep the panel at its full width at every step instead of hugging its
754
824
  * options, so drawing "See all results" never changes its width.
@@ -792,8 +862,8 @@ interface AIAutocompleteDropdownProps {
792
862
 
793
863
  declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProps & react.RefAttributes<AIAutocompleteHandle>>;
794
864
 
795
- declare function AIAutocompleteDropdown({ suggestions, activeIndex, onSelect, onHighlight, onUnhighlight, isOpen, id, className, pills, onPillClick, showPills, onSkip, showSkipButton, showOptionIcons, showOptionImages, showOptionCounts, skipDisabled, activeSelected, isLoading, skeletonExiting, isInputEmpty, language, products, onProductSelect, onProductAddToCart, onProductFocusChange, productsLayout, productImageFallback, showProductVendor, formatType, dateView, selectedDateIso, selectedDateRange, dateRangeStart, dateReferences, onPreviousMonth, onNextMonth, timeView, multiSelectView, onMultiSelectCommit, onSeeAllResults, fullWidth, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
865
+ declare function AIAutocompleteDropdown({ suggestions, activeIndex, onSelect, onHighlight, onUnhighlight, isOpen, id, className, pills, onPillClick, showPills, onSkip, showSkipButton, showOptionIcons, showOptionImages, showOptionCounts, skipDisabled, activeSelected, isLoading, skeletonExiting, isInputEmpty, language, products, onProductSelect, onProductAddToCart, onProductFocusChange, productsLayout, productImageFallback, showProductVendor, formatType, dateView, selectedDateIso, selectedDateRange, dateRangeStart, dateReferences, onPreviousMonth, onNextMonth, timeView, multiSelectView, onMultiSelectCommit, onSeeAllResults, seeAllBusy, busyProductId, fullWidth, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
796
866
 
797
- declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
867
+ declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, submitProgress, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
798
868
 
799
869
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };