@magicx-eng/ai-autocomplete-react 0.65.1 → 0.66.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
@@ -287,6 +287,8 @@ function App() {
287
287
  | `optionsStyle?` | `"floating" \| "classic"` | `"floating"` | The options box's look and motion. `"floating"`: no stroke, sized to the text, and it dissolves in where it sits and glides between questions. `"classic"` brings back the earlier stroke, size and motion: it unfolds out of the input with a stroke, at full size. A standalone `AIAutocompleteDropdown` opts in with `data-aia-options-style="classic"` on its `.magicx-aia` element or an ancestor of that element: any ancestor when `mode` is set, otherwise your `.magicx-aia` wrapper or above. |
288
288
  | `dropdownTrigger?` | `"auto" \| "manual" \| "hidden"` | `"auto"` | When the dropdown appears. `"auto"` = when options available. `"manual"` = only on pill tap, closes after selection. `"hidden"` = never shows. |
289
289
  | `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. |
290
+ | `focusInputOnSelect?` | `"auto" \| "always" \| "never"` | `"auto"` | Whether a pick focuses the input. `"auto"`: on a desktop yes; on a touch device a tapped pick puts the keyboard away. `"always"` restores focusing on every device. See "On phones: the keyboard after a pick" in REFERENCE.md. |
291
+ | `startingState?` | `boolean` | `true` | `false`: request and show nothing while the input is empty; suggestions start with the first typed character. See "Starting state" in REFERENCE.md. |
290
292
  | `prependPlaceholder?` | `boolean` | `true` | Set to `false` to show the starting state's lead-in text as a hint only: a picked option is not written after it. |
291
293
  | `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. |
292
294
  | `allOption?` | `boolean` | `false` | Lead a plain question of two or more options with an **All** row (labelled in the UI language) that skips the question, keeping every option. Its tile shows up to four of the options' pictures. Never on the starting state, the Smart Suggestion, a price question, pickers or multi-select questions. |
@@ -315,6 +317,7 @@ function App() {
315
317
  | `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
318
  | `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
319
  | `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. |
320
+ | `awaitAnswerOnSubmit?` | `boolean` | `false` | A submit waits for the answer to its own query, so its `custom_fields` match it. See "The filters a submit carries" in REFERENCE.md. |
318
321
  | `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`. |
319
322
  | `ref?` | `Ref<AIAutocompleteHandle>` | — | Imperative handle with `focus()`, `blur()`, `reset()`, and `setMode()`. |
320
323
 
@@ -491,7 +494,8 @@ The structured query as the SDK currently understands it. The same object is pas
491
494
  | `completed_params` | `CompletedParam[]` | Filled parameter values in query order, followed by any the user skipped (see below). |
492
495
  | `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. |
493
496
  | `is_ready` | `boolean` | Whether the server considers the query complete enough to act on. |
494
- | `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. |
497
+ | `custom_fields?` | `CustomFieldsReport` | The catalog report of the latest applied response (`applied_filters`, `dropped_filters`, `items`) — see [Product strip](#product-strip). Absent (no key) when the response carried none. |
498
+ | `custom_fields_stale?` | `true` | Set when `custom_fields` does not answer this query. See "The filters a submit carries" in REFERENCE.md. |
495
499
 
496
500
  #### Reading the query as it's built
497
501
 
package/REFERENCE.md CHANGED
@@ -2,16 +2,48 @@
2
2
 
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
+ - [Starting state](#starting-state)
5
6
  - [Product strip](#product-strip)
6
7
  - [While your page loads](#while-your-page-loads)
8
+ - [The filters a submit carries](#the-filters-a-submit-carries)
7
9
  - [Datepicker](#datepicker)
8
10
  - [Time picker](#time-picker)
9
11
  - [Multiple selections](#multiple-selections)
10
12
  - [Location search](#location-search)
13
+ - [On phones: the keyboard after a pick](#on-phones-the-keyboard-after-a-pick)
11
14
  - [CSS variables](#css-variables)
12
15
  - [Visitor id kept by the SDK](#visitor-id-kept-by-the-sdk)
13
16
  - [Search id](#search-id)
14
17
 
18
+ ## Starting state
19
+
20
+ By default the SDK asks for your product's starting state when it mounts and whenever the input is empty again, and shows it while the input has focus: the opening question with its options, the lead-in text and rotating hint inside the box, and any items. Set `startingState` to `false` when shoppers should type first, for example when most of them start with a brand name and the opening question would lead them through several steps.
21
+
22
+ ```tsx
23
+ <AIAutocomplete startingState={false} onSubmit={handleSubmit} />
24
+ ```
25
+
26
+ `useAIAutocomplete({ startingState: false })` takes it too.
27
+
28
+ With it off, while nothing is typed and nothing is picked (spaces alone count as nothing):
29
+
30
+ - No request is made: not on mount, not when the text is deleted or the last chip removed, not after `reset()`. That covers both the cacheable starting-state URL (`productId`) and the empty suggestion request, so no impression of a starting state is sent either.
31
+ - The dropdown stays closed whatever the focus, `closeDropdownOnBlur` and `dropdownTrigger`: no options, no loading skeleton, no product strip, no "See all results" row.
32
+ - The SDK writes nothing in the box: no lead-in text, no typed placeholder, no rotating hint. An answer to typed text does not bring a lead-in back, so `prependPlaceholder` has nothing to act on.
33
+ - State reads as nothing to show: `isDropdownOpen` is `false`, `suggestions`, the options, `products` and `placeholderText` are empty, and `isLoading` is `false`.
34
+
35
+ From the first typed character everything works as it does by default: the request goes out after the usual debounce (two or more new characters after 100ms, a single character after 300ms), and the dropdown opens with its answer. No starting question is on screen, so typed text never filters one: "Ki" is sent like any other text instead of narrowing a "Kids" option. When the box is cleared, the dropdown closes and the last answer is dropped in the same update; a request still on its way is ignored.
36
+
37
+ With `awaitAnswerOnSubmit` (or `awaitSubmitResult()`), a submit of typed text waits for its answer as usual. A submit of the empty input has no answer to wait for: it goes out at once, with no `custom_fields`.
38
+
39
+ The prop can change after mount: turned off over an empty input, the starting state on screen is cleared at once; turned on, it is requested as on mount. In Tier 2/3 `inputProps.placeholder` is then `undefined`, so a `placeholder` you set on your own input shows.
40
+
41
+ How it differs from the options it is confused with:
42
+
43
+ - `autoFocus` only decides whether the input takes focus on mount. With `autoFocus={false}` the starting state is still requested, and it opens as soon as the shopper taps the input.
44
+ - `dropdownTrigger: "manual"` and `"hidden"` close the dropdown for typed text too, and the starting state is still requested. `startingState: false` hides only the starting state.
45
+ - `prependPlaceholder: false` keeps the starting state and only stops its lead-in from being written before a pick.
46
+
15
47
  ## Product strip
16
48
 
17
49
  The dropdown renders a horizontal row of product cards below the options grid
@@ -406,6 +438,64 @@ To hide the spinner and keep the behaviour (repeats still ignored, `aria-busy` s
406
438
 
407
439
  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.
408
440
 
441
+ ## The filters a submit carries
442
+
443
+ `custom_fields` on a result is the catalog report of the last response the SDK applied. On a submit that response is often not an answer to the query being submitted:
444
+
445
+ - the dropdown was showing completions of the word being typed. Their block reads no filters from the query (`applied_filters: []`), and Enter then turns the typed word into a completed param the block knows nothing about;
446
+ - the request for the latest text has not come back yet, so the block answers an earlier text.
447
+
448
+ A shopper who types `jackets men` and presses Enter at once is in the first case; one who types a space and waits is in neither, which is why this is easy to miss in testing. A results page built from such a block loses the filters the query expressed.
449
+
450
+ **By default** the submit is handed over at once, as before, and such a block is marked: the result carries `custom_fields_stale: true` beside it. Read `applied_filters` and `items` only when the mark is absent, and treat a marked block as "no filters known".
451
+
452
+ **With `awaitAnswerOnSubmit`** a submit (Enter, the arrow button, "See all results") whose stored block does not answer the submitted query first gets the full answer for it, then calls `onSubmit` with that answer's `custom_fields`, `identified_params` and `is_ready`:
453
+
454
+ ```tsx
455
+ <AIAutocomplete
456
+ apiConfig={{ apiKey: "..." }}
457
+ awaitAnswerOnSubmit // wait for the answer to the submitted query
458
+ submitAnswerTimeoutMs={2500} // the default
459
+ onSubmit={(result) => openResults(result.query, result.custom_fields?.applied_filters ?? [])}
460
+ />
461
+ ```
462
+
463
+ `useAIAutocomplete` takes the same two options; they cover Enter.
464
+
465
+ - A request already on the wire for the same query is waited for; otherwise one goes out at once, past the typing debounce. It asks for the whole answer, not for completions.
466
+ - That request is an ordinary `/suggest` call, billed like any other. It is sent only with the option on or through `awaitSubmitResult()`, and only when the stored answer is not the submitted query's; with the option off a submit sends nothing.
467
+ - While it waits the submit is in progress: `isSubmitting` is `true`, the submit controls show their spinner, and a second submit is ignored. See "While your page loads" above.
468
+ - Typing, picking an option or a product, or a press elsewhere on the page cancels the wait, and `onSubmit` is not called.
469
+ - Escape in the widget's own input does not cancel the wait: the submit still goes out when its answer arrives. Change the text to call it off.
470
+ - The wait lasts at most `submitAnswerTimeoutMs` (2500 ms by default). When no answer came in time, or the request failed (network error, 4xx, 5xx), `onSubmit` is called once with **no `custom_fields` key**, never with the earlier block. Treat a missing block as "no filters known" and fall back to a text search on `query`.
471
+ - When the stored block already answers the query, nothing waits and `onSubmit` is called at once.
472
+
473
+ With the option on, a submit never carries `custom_fields_stale`: the block answers the submitted query or is left out.
474
+
475
+ **Your own submit button, with the hook (Tier 2 or 3).** `getState()` and `getResult()` read the same stored block, so after `prepareSubmit()` they have the same staleness. `awaitSubmitResult()` from the hook prepares the submit and resolves to the result with the answer to it, whatever `awaitAnswerOnSubmit` is set to:
476
+
477
+ ```tsx
478
+ const { awaitSubmitResult, recordSubmit, holdSubmit, isSubmitting } = useAIAutocomplete({ ... });
479
+
480
+ async function submit() {
481
+ if (isSubmitting) return;
482
+ const result = await awaitSubmitResult(); // no custom_fields key when no answer came in time
483
+ if (!result) return; // the shopper changed the input, or a submit is in progress
484
+ recordSubmit(result);
485
+ holdSubmit(openResults(result));
486
+ }
487
+ ```
488
+
489
+ `null` from `awaitSubmitResult()` is not an error. It means there is nothing to submit now: the shopper changed the input, picked a product or pressed elsewhere while it waited, or a submit is already in progress (a repeat press, or Enter's own submit still waiting). Return quietly; do not report it or fall back to another submit.
490
+
491
+ | | |
492
+ |---|---|
493
+ | `awaitAnswerOnSubmit?` | `boolean`, default `false`. A submit waits for the answer to its own query before `onSubmit`. On `<AIAutocomplete>` and the hook. |
494
+ | `submitAnswerTimeoutMs?` | `number`, default `2500`. The longest that wait lasts, also for `awaitSubmitResult()`. |
495
+ | `awaitSubmitResult()` | From the hook: `Promise<AutocompleteResult \| null>`. The result to submit from your own button; `null` when there is nothing to submit. |
496
+ | `getResult()` | From the hook: the structured query as it stands, marked `custom_fields_stale` when its block is not an answer to it. |
497
+ | `result.custom_fields_stale` | `true` when `custom_fields` does not answer the result's query; absent otherwise. |
498
+
409
499
  ## Datepicker
410
500
 
411
501
  When the next parameter is a date, the dropdown shows a calendar instead of a
@@ -616,6 +706,39 @@ replaces it.
616
706
 
617
707
  ---
618
708
 
709
+ ## On phones: the keyboard after a pick
710
+
711
+ On a touch device (one whose main pointer is a finger: `(hover: none) and (pointer: coarse)`) the keyboard covers part of the dropdown. So a tapped pick puts the keyboard away, and it stays away while the shopper answers:
712
+
713
+ - The option becomes a chip and the next question shows in the same dropdown, which stays open.
714
+ - If the field was focused, it is blurred, so the keyboard goes down. If it was not, it is left unfocused.
715
+ - The same holds for the All row, a checkbox row and Done on a checkbox list, a calendar date, the time picker and the skip button. A pill tapped in the dropdown's pill bar does not focus the field either.
716
+ - The keyboard comes back when the shopper taps the field (the caret goes to the end of the text) or taps a chip to re-edit it. A chip's "×", the submit button and "See all results" work without it. The next tap outside the dropdown closes it.
717
+ - A pick made from the keyboard keeps focus in the field, with the caret after the new chip: arrow keys and Enter (on a hardware keyboard for instance), and any option, skip, Done, day or place activated without a pointer (Enter or Space on it, switch control, assistive technology that activates the element directly). A click that carries no click count (`event.detail === 0`) is read as one of these.
718
+
719
+ On a device whose main pointer is not touch, a pick focuses the field and places the caret after the chip, as before.
720
+
721
+ `focusInputOnSelect` changes the rule:
722
+
723
+ | Value | After a pick |
724
+ | --- | --- |
725
+ | `"auto"` (default) | Focus the field on a desktop. On a touch device, put the keyboard away as described above. |
726
+ | `"always"` | Focus the field on every device. On a phone the keyboard stays up, or comes up, after each pick. This was the behaviour before `"auto"` existed. |
727
+ | `"never"` | A pick never focuses the field. On a touch device a tapped pick still puts the keyboard away, as with `"auto"`. On a desktop a focused field stays focused and an unfocused one stays unfocused: a tap on a pill in the dropdown's pill bar does not focus it either, so the shopper clicks the field before typing. |
728
+
729
+ For example, `focusInputOnSelect="always"`. It can change at any time.
730
+
731
+ With `useAIAutocomplete` you own the input, and the hook takes the same option. The same rule applies to your input as long as `inputProps.onFocus` and `inputProps.onBlur` are wired to it: on a touch device a tapped pick blurs it, and the SDK does not focus it. If your own code focuses the input after a selection, skip that on a touch device.
732
+
733
+ To know which rule is in force in your own code, use `focusesInputOnSelect(focusInputOnSelect)` from `@magicx-eng/ai-autocomplete-react`: when it returns `false`, do not focus your input after a pick. A host that focuses its input after every pick brings the keyboard straight back.
734
+
735
+ A pick your own code makes while a key press is being handled (Enter in your own `keydown` listener) is read as a keyboard pick too, and keeps focus. If the pick happens later than the key press (after a timer or a request), say so yourself: `dropdownProps.onSelect(option, { fromKeyboard: true })`. Without that, a call with no key press or click behind it counts as a tap.
736
+
737
+ Two things to know before relying on the default:
738
+
739
+ - **A tablet with a mouse or trackpad** still reports a touch main pointer, so a mouse click on an option there counts as a tap and blurs the field. `"always"` is the opt-out.
740
+ - **Screen readers.** A pick activated without a pointer keeps focus in the field (see above). A screen reader that activates an option by sending a touch, as a double-tap usually does, counts as a tap: nothing holds focus afterwards, it goes to the document body, and the user's position leaves the field until they move back to it. If that matters more to you than the keyboard covering the options, use `"always"`.
741
+
619
742
  ## CSS variables
620
743
 
621
744
  Override on the container (via `className`). The variables are declared with `:where()` (zero specificity), so a value you set on the container always wins.
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AutocompleteResult, OptionOverrides, APIConfig, CurrencyOptions, AppearanceMode, CompletedParamState, ProductsLayout, ProductImageFallback, ProductsConfig, Product, MatchedItem, Suggestion, SuggestionOption, SelectOptionOptions, FormatType, DateMonthView, DateRange, TimeView, LocationView, SkippedParamState, IdentifiedParamState, CoreState, Segment, CustomFieldsReport } from '@magicx-eng/ai-autocomplete-vanilla';
2
- export { APIConfig, APIKeyConfig, AccessTokenConfig, AccessTokenResult, AppearanceMode, AutocompleteResult, CompletedParam, CompletedParamState, CurrencyOptions, CustomFieldsReport, DATE_RANGE_META_END, DATE_RANGE_META_START, DEFAULT_OPTION_COUNT_UNIT, DateMonthView, DateRange, ExpressedFilter, FilterOp, FormatType, IdentifiedParam, IdentifiedParamState, LOCATION_META_KEY, LocationPlace, LocationView, MatchedItem, MatchedItems, OptionOverrides, PRODUCT_PATH_PREFIX, Product, ProductImageFallback, ProductsConfig, ProductsLayout, Segment, SelectOptionOptions, SkippedParamState, SubmitResultExtras, Suggestion, SuggestionOption, TIME_META_KEY, TaskKind, TimeView, WEEKDAY_LABELS, buildSubmitResult, cellDay, cellIso, dateCellMarks, formatDate, formatDateRange, formatOptionCount, formatPlace, formatTime, isoDate, monthLabel, optionCountLabel, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsShowLeadingVisuals, parseDate, parseLooseDate, parseLooseDateRange, parseTime, productFromMatchedItem, productImageSources, productsFromCustomFields, sanitizeOptionIconSvg, selectedRangeFor, visibleDateRange, withSkippedParams } from '@magicx-eng/ai-autocomplete-vanilla';
2
+ export { APIConfig, APIKeyConfig, AccessTokenConfig, AccessTokenResult, AppearanceMode, AutocompleteResult, CompletedParam, CompletedParamState, CurrencyOptions, CustomFieldsReport, DATE_RANGE_META_END, DATE_RANGE_META_START, DEFAULT_OPTION_COUNT_UNIT, DateMonthView, DateRange, ExpressedFilter, FilterOp, FocusInputOnSelect, FormatType, IdentifiedParam, IdentifiedParamState, LOCATION_META_KEY, LocationPlace, LocationView, MatchedItem, MatchedItems, OptionOverrides, PRODUCT_PATH_PREFIX, Product, ProductImageFallback, ProductsConfig, ProductsLayout, Segment, SelectOptionOptions, SkippedParamState, SubmitResultExtras, Suggestion, SuggestionOption, TIME_META_KEY, TaskKind, TimeView, WEEKDAY_LABELS, buildSubmitResult, cellDay, cellIso, dateCellMarks, focusesInputOnSelect, formatDate, formatDateRange, formatOptionCount, formatPlace, formatTime, isTouchPrimary, isoDate, monthLabel, optionCountLabel, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsShowLeadingVisuals, parseDate, parseLooseDate, parseLooseDateRange, parseTime, productFromMatchedItem, productImageSources, productsFromCustomFields, sanitizeOptionIconSvg, selectedRangeFor, visibleDateRange, withSkippedParams } from '@magicx-eng/ai-autocomplete-vanilla';
3
3
  import * as react from 'react';
4
4
  import { ReactNode, KeyboardEvent, ChangeEvent } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -121,6 +121,26 @@ interface AIAutocompleteProps {
121
121
  dropdownTrigger?: "auto" | "manual" | "hidden";
122
122
  /** When true (default), the dropdown closes when the input loses focus. Set to false to keep it open whenever options are available, regardless of focus. */
123
123
  closeDropdownOnBlur?: boolean;
124
+ /**
125
+ * Whether picking an option puts focus in the input. Default `"auto"`:
126
+ * where the pointer hovers (a desktop) it does; on a touch device it does
127
+ * not, and a tapped pick blurs the input, so the keyboard goes away and the
128
+ * next question's options are in view (the dropdown stays open; a tap on
129
+ * the input or a chip brings the keyboard back). A pick made from the
130
+ * keyboard (Enter) keeps focus. `"always"` focuses on every device, which
131
+ * keeps the keyboard up on a phone. `"never"`: a pick never focuses the
132
+ * input. On a touch device a tapped pick still puts the keyboard away, as
133
+ * with `"auto"`.
134
+ */
135
+ focusInputOnSelect?: "auto" | "always" | "never";
136
+ /**
137
+ * Whether anything is offered before the shopper types. Default `true`.
138
+ * Set to `false` to request and show nothing while the input is empty: no
139
+ * starting-state request, a closed dropdown, and no lead-in or hint in the
140
+ * box. Typed text works as usual. Unlike `dropdownTrigger`, it hides only
141
+ * the starting state; `autoFocus` only decides focus on mount.
142
+ */
143
+ startingState?: boolean;
124
144
  /** When true (default), the starting state's lead-in text is written before the first picked option. Set to false to show it as a hint only: a pick writes just the option. */
125
145
  prependPlaceholder?: boolean;
126
146
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
@@ -190,6 +210,21 @@ interface AIAutocompleteProps {
190
210
  * all of it off: nothing is marked, and every press calls your handler.
191
211
  */
192
212
  submitProgress?: boolean;
213
+ /**
214
+ * When true, a submit (Enter, the submit button, See all results) whose
215
+ * `custom_fields` do not answer the submitted query first gets the full
216
+ * answer for it, then calls `onSubmit` with that answer's `custom_fields`.
217
+ * The submit shows as in progress while it waits, a second submit is
218
+ * ignored, and typing, tapping or pressing elsewhere cancels it without
219
+ * calling `onSubmit`. After `submitAnswerTimeoutMs`, or when the request
220
+ * fails, `onSubmit` is called once with no `custom_fields` key: treat a
221
+ * missing block as "no filters known". Default: false, where `onSubmit` is
222
+ * called at once and a block that does not answer the query is marked
223
+ * `custom_fields_stale: true`.
224
+ */
225
+ awaitAnswerOnSubmit?: boolean;
226
+ /** The longest a submit waits for its answer, in milliseconds. Default: 2500. */
227
+ submitAnswerTimeoutMs?: number;
193
228
  /**
194
229
  * How the product strip lays its cards out. `"row"` (the default) is a
195
230
  * horizontally scrolling shelf of cards. `"list"` stacks the same cards as
@@ -358,6 +393,26 @@ interface UseAIAutocompleteOptions {
358
393
  optionsPosition?: "above" | "below";
359
394
  /** When true (default), the dropdown closes when the input loses focus. Set to false to keep it open whenever options are available. */
360
395
  closeDropdownOnBlur?: boolean;
396
+ /**
397
+ * Whether picking an option puts focus in the input. Default `"auto"`:
398
+ * where the pointer hovers (a desktop) it does; on a touch device it does
399
+ * not, and a tapped pick blurs the input, so the keyboard goes away and the
400
+ * next question's options are in view (the dropdown stays open; a tap on
401
+ * the input or a chip brings the keyboard back). A pick made from the
402
+ * keyboard (Enter) keeps focus. `"always"` focuses on every device, which
403
+ * keeps the keyboard up on a phone. `"never"`: a pick never focuses the
404
+ * input. On a touch device a tapped pick still puts the keyboard away, as
405
+ * with `"auto"`.
406
+ */
407
+ focusInputOnSelect?: "auto" | "always" | "never";
408
+ /**
409
+ * Whether anything is offered before the shopper types. Default `true`.
410
+ * Set to `false` to request and show nothing while the input is empty: no
411
+ * starting-state request, a closed dropdown, and no lead-in or hint in the
412
+ * box. Typed text works as usual. Unlike `dropdownTrigger`, it hides only
413
+ * the starting state; `autoFocus` only decides focus on mount.
414
+ */
415
+ startingState?: boolean;
361
416
  /** When true (default), the starting state's lead-in text is written before the first picked option. Set to false to show it as a hint only: a pick writes just the option. */
362
417
  prependPlaceholder?: boolean;
363
418
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
@@ -421,6 +476,21 @@ interface UseAIAutocompleteOptions {
421
476
  * all of it off: nothing is marked, and every press calls your handler.
422
477
  */
423
478
  submitProgress?: boolean;
479
+ /**
480
+ * When true, a submit (Enter, the submit button, See all results) whose
481
+ * `custom_fields` do not answer the submitted query first gets the full
482
+ * answer for it, then calls `onSubmit` with that answer's `custom_fields`.
483
+ * The submit shows as in progress while it waits, a second submit is
484
+ * ignored, and typing, tapping or pressing elsewhere cancels it without
485
+ * calling `onSubmit`. After `submitAnswerTimeoutMs`, or when the request
486
+ * fails, `onSubmit` is called once with no `custom_fields` key: treat a
487
+ * missing block as "no filters known". Default: false, where `onSubmit` is
488
+ * called at once and a block that does not answer the query is marked
489
+ * `custom_fields_stale: true`.
490
+ */
491
+ awaitAnswerOnSubmit?: boolean;
492
+ /** The longest a submit waits for its answer, in milliseconds. Default: 2500. */
493
+ submitAnswerTimeoutMs?: number;
424
494
  /**
425
495
  * How the product strip lays its cards out. `"row"` (the default) is a
426
496
  * horizontally scrolling shelf of cards. `"list"` stacks the same cards as
@@ -549,6 +619,21 @@ interface UseAIAutocompleteReturn {
549
619
  prepareSubmit: () => void;
550
620
  /** Read the current state, including changes from prepareSubmit(). */
551
621
  getState: () => CoreState;
622
+ /**
623
+ * The structured query as it stands, as `onResult` and `onSubmit` deliver
624
+ * it. Its `custom_fields` are the last response's: `custom_fields_stale`
625
+ * marks a block that does not answer this query.
626
+ */
627
+ getResult: () => AutocompleteResult;
628
+ /**
629
+ * The result to submit from your own button, with `custom_fields` that
630
+ * answer it: prepares the submit as `prepareSubmit()` does, then waits for
631
+ * the answer to the query when the stored one is for another, for up to
632
+ * `submitAnswerTimeoutMs`. Resolves without a `custom_fields` key when no
633
+ * answer came, and to null when there is nothing to submit (the input
634
+ * changed while it waited, or a submit is already in progress).
635
+ */
636
+ awaitSubmitResult: () => Promise<AutocompleteResult | null>;
552
637
  /**
553
638
  * Records a submit in telemetry. Enter is recorded by the SDK; call this
554
639
  * from a submit button you render, so each submit is counted once.
@@ -898,6 +983,6 @@ declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProp
898
983
 
899
984
  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;
900
985
 
901
- declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, analyticsConsent, 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;
986
+ declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, analyticsConsent, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, focusInputOnSelect, startingState, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, submitProgress, awaitAnswerOnSubmit, submitAnswerTimeoutMs, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
902
987
 
903
988
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { AutocompleteResult, OptionOverrides, APIConfig, CurrencyOptions, AppearanceMode, CompletedParamState, ProductsLayout, ProductImageFallback, ProductsConfig, Product, MatchedItem, Suggestion, SuggestionOption, SelectOptionOptions, FormatType, DateMonthView, DateRange, TimeView, LocationView, SkippedParamState, IdentifiedParamState, CoreState, Segment, CustomFieldsReport } from '@magicx-eng/ai-autocomplete-vanilla';
2
- export { APIConfig, APIKeyConfig, AccessTokenConfig, AccessTokenResult, AppearanceMode, AutocompleteResult, CompletedParam, CompletedParamState, CurrencyOptions, CustomFieldsReport, DATE_RANGE_META_END, DATE_RANGE_META_START, DEFAULT_OPTION_COUNT_UNIT, DateMonthView, DateRange, ExpressedFilter, FilterOp, FormatType, IdentifiedParam, IdentifiedParamState, LOCATION_META_KEY, LocationPlace, LocationView, MatchedItem, MatchedItems, OptionOverrides, PRODUCT_PATH_PREFIX, Product, ProductImageFallback, ProductsConfig, ProductsLayout, Segment, SelectOptionOptions, SkippedParamState, SubmitResultExtras, Suggestion, SuggestionOption, TIME_META_KEY, TaskKind, TimeView, WEEKDAY_LABELS, buildSubmitResult, cellDay, cellIso, dateCellMarks, formatDate, formatDateRange, formatOptionCount, formatPlace, formatTime, isoDate, monthLabel, optionCountLabel, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsShowLeadingVisuals, parseDate, parseLooseDate, parseLooseDateRange, parseTime, productFromMatchedItem, productImageSources, productsFromCustomFields, sanitizeOptionIconSvg, selectedRangeFor, visibleDateRange, withSkippedParams } from '@magicx-eng/ai-autocomplete-vanilla';
2
+ export { APIConfig, APIKeyConfig, AccessTokenConfig, AccessTokenResult, AppearanceMode, AutocompleteResult, CompletedParam, CompletedParamState, CurrencyOptions, CustomFieldsReport, DATE_RANGE_META_END, DATE_RANGE_META_START, DEFAULT_OPTION_COUNT_UNIT, DateMonthView, DateRange, ExpressedFilter, FilterOp, FocusInputOnSelect, FormatType, IdentifiedParam, IdentifiedParamState, LOCATION_META_KEY, LocationPlace, LocationView, MatchedItem, MatchedItems, OptionOverrides, PRODUCT_PATH_PREFIX, Product, ProductImageFallback, ProductsConfig, ProductsLayout, Segment, SelectOptionOptions, SkippedParamState, SubmitResultExtras, Suggestion, SuggestionOption, TIME_META_KEY, TaskKind, TimeView, WEEKDAY_LABELS, buildSubmitResult, cellDay, cellIso, dateCellMarks, focusesInputOnSelect, formatDate, formatDateRange, formatOptionCount, formatPlace, formatTime, isTouchPrimary, isoDate, monthLabel, optionCountLabel, optionHasImage, optionImageSources, optionImageSrc, optionLabel, optionsShowLeadingVisuals, parseDate, parseLooseDate, parseLooseDateRange, parseTime, productFromMatchedItem, productImageSources, productsFromCustomFields, sanitizeOptionIconSvg, selectedRangeFor, visibleDateRange, withSkippedParams } from '@magicx-eng/ai-autocomplete-vanilla';
3
3
  import * as react from 'react';
4
4
  import { ReactNode, KeyboardEvent, ChangeEvent } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -121,6 +121,26 @@ interface AIAutocompleteProps {
121
121
  dropdownTrigger?: "auto" | "manual" | "hidden";
122
122
  /** When true (default), the dropdown closes when the input loses focus. Set to false to keep it open whenever options are available, regardless of focus. */
123
123
  closeDropdownOnBlur?: boolean;
124
+ /**
125
+ * Whether picking an option puts focus in the input. Default `"auto"`:
126
+ * where the pointer hovers (a desktop) it does; on a touch device it does
127
+ * not, and a tapped pick blurs the input, so the keyboard goes away and the
128
+ * next question's options are in view (the dropdown stays open; a tap on
129
+ * the input or a chip brings the keyboard back). A pick made from the
130
+ * keyboard (Enter) keeps focus. `"always"` focuses on every device, which
131
+ * keeps the keyboard up on a phone. `"never"`: a pick never focuses the
132
+ * input. On a touch device a tapped pick still puts the keyboard away, as
133
+ * with `"auto"`.
134
+ */
135
+ focusInputOnSelect?: "auto" | "always" | "never";
136
+ /**
137
+ * Whether anything is offered before the shopper types. Default `true`.
138
+ * Set to `false` to request and show nothing while the input is empty: no
139
+ * starting-state request, a closed dropdown, and no lead-in or hint in the
140
+ * box. Typed text works as usual. Unlike `dropdownTrigger`, it hides only
141
+ * the starting state; `autoFocus` only decides focus on mount.
142
+ */
143
+ startingState?: boolean;
124
144
  /** When true (default), the starting state's lead-in text is written before the first picked option. Set to false to show it as a hint only: a pick writes just the option. */
125
145
  prependPlaceholder?: boolean;
126
146
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
@@ -190,6 +210,21 @@ interface AIAutocompleteProps {
190
210
  * all of it off: nothing is marked, and every press calls your handler.
191
211
  */
192
212
  submitProgress?: boolean;
213
+ /**
214
+ * When true, a submit (Enter, the submit button, See all results) whose
215
+ * `custom_fields` do not answer the submitted query first gets the full
216
+ * answer for it, then calls `onSubmit` with that answer's `custom_fields`.
217
+ * The submit shows as in progress while it waits, a second submit is
218
+ * ignored, and typing, tapping or pressing elsewhere cancels it without
219
+ * calling `onSubmit`. After `submitAnswerTimeoutMs`, or when the request
220
+ * fails, `onSubmit` is called once with no `custom_fields` key: treat a
221
+ * missing block as "no filters known". Default: false, where `onSubmit` is
222
+ * called at once and a block that does not answer the query is marked
223
+ * `custom_fields_stale: true`.
224
+ */
225
+ awaitAnswerOnSubmit?: boolean;
226
+ /** The longest a submit waits for its answer, in milliseconds. Default: 2500. */
227
+ submitAnswerTimeoutMs?: number;
193
228
  /**
194
229
  * How the product strip lays its cards out. `"row"` (the default) is a
195
230
  * horizontally scrolling shelf of cards. `"list"` stacks the same cards as
@@ -358,6 +393,26 @@ interface UseAIAutocompleteOptions {
358
393
  optionsPosition?: "above" | "below";
359
394
  /** When true (default), the dropdown closes when the input loses focus. Set to false to keep it open whenever options are available. */
360
395
  closeDropdownOnBlur?: boolean;
396
+ /**
397
+ * Whether picking an option puts focus in the input. Default `"auto"`:
398
+ * where the pointer hovers (a desktop) it does; on a touch device it does
399
+ * not, and a tapped pick blurs the input, so the keyboard goes away and the
400
+ * next question's options are in view (the dropdown stays open; a tap on
401
+ * the input or a chip brings the keyboard back). A pick made from the
402
+ * keyboard (Enter) keeps focus. `"always"` focuses on every device, which
403
+ * keeps the keyboard up on a phone. `"never"`: a pick never focuses the
404
+ * input. On a touch device a tapped pick still puts the keyboard away, as
405
+ * with `"auto"`.
406
+ */
407
+ focusInputOnSelect?: "auto" | "always" | "never";
408
+ /**
409
+ * Whether anything is offered before the shopper types. Default `true`.
410
+ * Set to `false` to request and show nothing while the input is empty: no
411
+ * starting-state request, a closed dropdown, and no lead-in or hint in the
412
+ * box. Typed text works as usual. Unlike `dropdownTrigger`, it hides only
413
+ * the starting state; `autoFocus` only decides focus on mount.
414
+ */
415
+ startingState?: boolean;
361
416
  /** When true (default), the starting state's lead-in text is written before the first picked option. Set to false to show it as a hint only: a pick writes just the option. */
362
417
  prependPlaceholder?: boolean;
363
418
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
@@ -421,6 +476,21 @@ interface UseAIAutocompleteOptions {
421
476
  * all of it off: nothing is marked, and every press calls your handler.
422
477
  */
423
478
  submitProgress?: boolean;
479
+ /**
480
+ * When true, a submit (Enter, the submit button, See all results) whose
481
+ * `custom_fields` do not answer the submitted query first gets the full
482
+ * answer for it, then calls `onSubmit` with that answer's `custom_fields`.
483
+ * The submit shows as in progress while it waits, a second submit is
484
+ * ignored, and typing, tapping or pressing elsewhere cancels it without
485
+ * calling `onSubmit`. After `submitAnswerTimeoutMs`, or when the request
486
+ * fails, `onSubmit` is called once with no `custom_fields` key: treat a
487
+ * missing block as "no filters known". Default: false, where `onSubmit` is
488
+ * called at once and a block that does not answer the query is marked
489
+ * `custom_fields_stale: true`.
490
+ */
491
+ awaitAnswerOnSubmit?: boolean;
492
+ /** The longest a submit waits for its answer, in milliseconds. Default: 2500. */
493
+ submitAnswerTimeoutMs?: number;
424
494
  /**
425
495
  * How the product strip lays its cards out. `"row"` (the default) is a
426
496
  * horizontally scrolling shelf of cards. `"list"` stacks the same cards as
@@ -549,6 +619,21 @@ interface UseAIAutocompleteReturn {
549
619
  prepareSubmit: () => void;
550
620
  /** Read the current state, including changes from prepareSubmit(). */
551
621
  getState: () => CoreState;
622
+ /**
623
+ * The structured query as it stands, as `onResult` and `onSubmit` deliver
624
+ * it. Its `custom_fields` are the last response's: `custom_fields_stale`
625
+ * marks a block that does not answer this query.
626
+ */
627
+ getResult: () => AutocompleteResult;
628
+ /**
629
+ * The result to submit from your own button, with `custom_fields` that
630
+ * answer it: prepares the submit as `prepareSubmit()` does, then waits for
631
+ * the answer to the query when the stored one is for another, for up to
632
+ * `submitAnswerTimeoutMs`. Resolves without a `custom_fields` key when no
633
+ * answer came, and to null when there is nothing to submit (the input
634
+ * changed while it waited, or a submit is already in progress).
635
+ */
636
+ awaitSubmitResult: () => Promise<AutocompleteResult | null>;
552
637
  /**
553
638
  * Records a submit in telemetry. Enter is recorded by the SDK; call this
554
639
  * from a submit button you render, so each submit is counted once.
@@ -898,6 +983,6 @@ declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProp
898
983
 
899
984
  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;
900
985
 
901
- declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, analyticsConsent, 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;
986
+ declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, analyticsConsent, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, focusInputOnSelect, startingState, prependPlaceholder, allOption, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, submitProgress, awaitAnswerOnSubmit, submitAnswerTimeoutMs, productImageFallback, showProductVendor, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
902
987
 
903
988
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };