@magicx-eng/ai-autocomplete-react 0.57.1 → 0.58.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
@@ -289,12 +289,13 @@ function App() {
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
290
  | `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
291
  | `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
+ | `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. |
292
293
  | `locationSearch?` | `boolean` | `true` | When `true`, a location parameter without options searches places as the user types in its field. Set to `false` to take typed text only. See [Location search](#location-search). |
293
294
  | `showSkipButton?` | `boolean` | `true` | When `true`, the dropdown's pill bar ends in a small "skip" button that dismisses the active pill — same action as pressing <kbd>→</kbd> at the end of the input. It sits at the header's trailing edge, across from the label, once the input has text. Set to `false` to hide it. |
294
295
  | `showOptionIcons?` | `boolean` | `true` | When `true`, an option that carries an `icon_svg` draws its icon before its text in the dropdown. Set to `false` to render option rows as text only. |
295
296
  | `showChipIcons?` | `boolean` | `true` | When `true`, a completed chip in the input draws the icon of the option that answered it. Set to `false` to render chips as text only. |
296
297
  | `showChipImages?` | `boolean` | `true` | When `true`, a completed chip in the input draws the picture (`image_url`) of the option that answered it, in place of its icon. Set to `false` to render chips without pictures. |
297
- | `showChipRemove?` | `boolean` | `false` | When `true`, every completed chip in the input ends in a small, faint "×" that removes that chip in one tap or click, the same result as Backspace at the chip's trailing edge. Only completed chips get one; values the server merely identified in typed text do not. The × reads `--aia-chip-remove-opacity` (0.32) and `--aia-chip-remove-opacity-hover` (0.7). |
298
+ | `showChipRemove?` | `boolean` | `false` | When `true`, every chip in the input ends in a small, faint "×" that removes that chip in one tap or click, the same result as Backspace at the chip's trailing edge. Chips the server identified in typed text get one too. The × reads `--aia-chip-remove-opacity` (0.32) and `--aia-chip-remove-opacity-hover` (0.7). |
298
299
  | `showOptionImages?` | `boolean` | `true` | When `true`, an option that carries an `image_url` draws it as a square thumbnail before its text in the dropdown, in place of its icon. Set to `false` to render option rows without pictures. |
299
300
  | `showOptionCounts?` | `boolean` | `true` | When `true`, an option that carries an `item_count` shows it as a muted label at the row's trailing edge (`"12 items"`). Set to `false` to hide the counts. |
300
301
  | `autoFocus?` | `boolean` | `true` | Focus the input on mount. Set to `false` to leave focus to the consumer. |
@@ -422,7 +423,7 @@ The headless hook for Tier 2 and Tier 3. Accepts the same options as `<AIAutocom
422
423
  | `setActivePill` | `(index: number) => void` | Move pill at `index` to front (active). |
423
424
  | `skipActivePill` | `() => void` | Skip the active pill — same action as → / the dropdown's skip button. Records it in `skippedParams`; no-ops during re-edit and the post-selection window. Already wired into `dropdownProps.onSkip`; call it directly for a custom skip affordance (e.g. with `showSkipButton: false`). Also exposed on the Tier 1 imperative handle. |
424
425
  | `removeLastParam` | `() => void` | Remove the last completed param from state. The text stays in the input as plain text. |
425
- | `removeParam` | `(paramId: string) => boolean` | Remove the completed chip with that id, the same result as Backspace at the chip's trailing edge; the chip's × (`showChipRemove`) calls it. Any value's id of one multi-select answer removes its joined chip. Returns `false`, changing nothing, when no completed chip has that id. |
426
+ | `removeParam` | `(paramId: string) => boolean` | Remove the chip with that id (completed or identified), the same result as Backspace at the chip's trailing edge; the chip's × (`showChipRemove`) calls it. Any value's id of one multi-select answer removes its joined chip. Returns `false`, changing nothing, when no chip has that id. |
426
427
  | `clearNewParamId` | `() => void` | Clear shimmer animation state. |
427
428
  | `reset` | `() => void` | Clear all state, re-fetch, and start a new session (rotates `session_id`). Call this after handling submit. |
428
429
  | `recordSubmit` | `(result: AutocompleteResult) => void` | Record a submit from a button you render. Enter is recorded for you; call this once per button submit. |
@@ -518,7 +519,7 @@ Pressing <kbd>→</kbd> at the end of the input dismisses the active pill. The d
518
519
 
519
520
  Tier 2 consumers who build their own submit payload get the raw skips from the hook as `skippedParams`, and can fold them in the same way with the exported `buildSubmitResult(text, completedParams, skippedParams, { identifiedParams, isReady })` — the last argument carries the hook's `identifiedParams` and `isReady` so a hand-rolled submit reports the same `identified_params` and `is_ready` the SDK's own results do. Call `prepareSubmit()` first, then pass `getState().identifiedParams` and `getState().isReady` (not the hook's render-time values): a typed value with no pill yet joins `identifiedParams` only in that call.
520
521
 
521
- > **Reading `skippedParams` directly:** the array is append-only until `reset()`. The "drop a skip whose parameter got filled" rule is applied when the payload is built, not by pruning the array — so if the user skips `goal` and later fills one, the raw array still holds the `goal` entry. That's deliberate: the filter self-heals if they then delete that param's text, where pruning would discard the signal for good. `buildSubmitResult` applies the rule for you; to apply it elsewhere (say, a "you skipped X" badge), use the exported `withSkippedParams(completedParams, skippedParams)`.
522
+ > **Reading `skippedParams` directly:** the array lasts until `reset()` or a cleared search. The "drop a skip whose parameter got filled" rule is applied when the payload is built, not by pruning the array — so if the user skips `goal` and later fills one, the raw array still holds the `goal` entry. That's deliberate: the filter self-heals if they then delete that param's text, where pruning would discard the signal for good. `buildSubmitResult` applies the rule for you; to apply it elsewhere (say, a "you skipped X" badge), use the exported `withSkippedParams(completedParams, skippedParams)`.
522
523
 
523
524
  ---
524
525
 
package/REFERENCE.md CHANGED
@@ -291,7 +291,7 @@ fully under your control. (Angular additionally runs its own `href`
291
291
  sanitiser, so unrecognised schemes like `myapp://…` are rewritten to
292
292
  `unsafe:…` in that package only.)
293
293
 
294
- **Accessibility.** The strip is a `role="group"` labelled "Best match"; each card
294
+ **Accessibility.** The strip is a `role="group"` labelled "Items" (in English; other languages keep their own words); each card
295
295
  is a `role="option"` in the tab order, activated with Enter or Space, with a
296
296
  visible focus ring. Tabbing into the strip does not close the panel. The row
297
297
  scrolls horizontally by trackpad, wheel, touch and keyboard; the page never
@@ -572,7 +572,7 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
572
572
  | `--aia-product-compare-at-opacity` | `0.6` | `0.6` | How far the struck price is dimmed. |
573
573
  | `--aia-product-vendor-color` | `--aia-option-color` | `--aia-option-color` | Product vendor line. |
574
574
  | `--aia-product-focus-ring` | `--aia-option-color-selected` | `--aia-option-color-selected` | Focus ring drawn on a keyboard-focused card. |
575
- | `--aia-products-label-color` | `--aia-option-color` | `--aia-option-color` | "Best match" section label. |
575
+ | `--aia-products-label-color` | `--aia-option-color` | `--aia-option-color` | "Items" section label. |
576
576
  | `--aia-product-title-font-size` | `8.4px` | `8.4px` | Product title font size. |
577
577
  | `--aia-product-price-font-size` | `7.7px` | `7.7px` | Product price font size. |
578
578
  | `--aia-product-vendor-font-size` | `7px` | `7px` | Product vendor font size. |
@@ -606,7 +606,7 @@ The full input also accepts `--aia-input-radius` and `--aia-written-text-font-we
606
606
  | `--aia-location-font-size` | `15px` | `15px` | The location field's text and the place names. |
607
607
  | `--aia-location-row-bg-highlighted` | `--aia-streak-rgb` at 8% (indigo) | `--aia-streak-rgb` at 8% (white) | The highlighted (or hovered) place. |
608
608
  | `--aia-skeleton-bg` | `rgba(189, 189, 189, 0.083)` | `#1a1b1d` | Fill color of the option and chip image tiles while their picture loads (unless `--aia-option-image-bg` / `--aia-chip-image-bg` are set). |
609
- | `--aia-chip-remove-opacity` | `0.32` | `0.32` | Opacity of a completed chip's remove × (`showChipRemove`). The × is for a mouse or a tap and is hidden from assistive technology; from the keyboard, Backspace at the end of a chip removes it. |
609
+ | `--aia-chip-remove-opacity` | `0.32` | `0.32` | Opacity of a chip's remove × (`showChipRemove`). The × is for a mouse or a tap and is hidden from assistive technology; from the keyboard, Backspace at the end of a chip removes it. |
610
610
  | `--aia-chip-remove-opacity-hover` | `0.7` | `0.7` | Opacity of that × under a hovering pointer (never on touch). |
611
611
 
612
612
  Legacy `--aia-color-*` variables are still supported as fallbacks.
package/dist/index.d.mts CHANGED
@@ -97,6 +97,13 @@ interface AIAutocompleteProps {
97
97
  prependPlaceholder?: boolean;
98
98
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
99
99
  showNonTappableOptions?: boolean;
100
+ /**
101
+ * When true, a plain question of two or more options past the starting
102
+ * state leads with an All option, pictured with the first options'
103
+ * pictures; picking it skips the question. The price question, which
104
+ * declines the bound with its own "any price", gets none. Default false.
105
+ */
106
+ allOption?: boolean;
100
107
  /**
101
108
  * When true (default), a location parameter without options searches the
102
109
  * server's location search (cities, addresses, landmarks) as the user types
@@ -110,7 +117,7 @@ interface AIAutocompleteProps {
110
117
  showChipIcons?: boolean;
111
118
  /** When true (default), a completed chip in the input draws the picture (`image_url`) of the option that answered it, in place of its icon. Set to false to render chips without pictures. */
112
119
  showChipImages?: boolean;
113
- /** When true, every completed chip in the input ends in a small, faint "×" that removes the chip in one tap (the same result as Backspace at the chip's trailing edge). Default: false. */
120
+ /** When true, every chip in the input (completed, or identified by the server in typed text) ends in a small, faint "×" that removes the chip in one tap (the same result as Backspace at the chip's trailing edge). Default: false. */
114
121
  showChipRemove?: boolean;
115
122
  /** When true (default), an option that carries an `image_url` draws it as a square thumbnail before its text in the dropdown (in place of its `icon_svg`). Set to false to render option rows without pictures. */
116
123
  showOptionImages?: boolean;
@@ -286,6 +293,13 @@ interface UseAIAutocompleteOptions {
286
293
  prependPlaceholder?: boolean;
287
294
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
288
295
  showNonTappableOptions?: boolean;
296
+ /**
297
+ * When true, a plain question of two or more options past the starting
298
+ * state leads with an All option, pictured with the first options'
299
+ * pictures; picking it skips the question. The price question, which
300
+ * declines the bound with its own "any price", gets none. Default false.
301
+ */
302
+ allOption?: boolean;
289
303
  /**
290
304
  * When true (default), a location parameter without options searches the
291
305
  * server's location search (cities, addresses, landmarks) as the user types
@@ -526,7 +540,7 @@ interface UseAIAutocompleteReturn {
526
540
  caretOffset: number | null;
527
541
  /** Tier 1 re-edit: enter re-edit mode for the bold param with the given id. */
528
542
  startEditingParam: (paramId: string) => void;
529
- /** Remove the completed chip with the given id (the chip's "×", `showChipRemove`); the same result as Backspace at the chip's trailing edge. Returns false when no completed chip has that id. */
543
+ /** Remove the chip (completed or identified) with the given id (the chip's "×", `showChipRemove`); the same result as Backspace at the chip's trailing edge. Returns false when no chip has that id. */
530
544
  removeParam: (paramId: string) => boolean;
531
545
  /** Tier 1 re-edit: exit re-edit mode. */
532
546
  exitEditMode: () => void;
@@ -736,6 +750,6 @@ declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProp
736
750
 
737
751
  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, formatType, dateView, selectedDateIso, selectedDateRange, dateRangeStart, dateReferences, onPreviousMonth, onNextMonth, timeView, multiSelectView, onMultiSelectCommit, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
738
752
 
739
- declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, productImageFallback, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
753
+ 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, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
740
754
 
741
755
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };
package/dist/index.d.ts CHANGED
@@ -97,6 +97,13 @@ interface AIAutocompleteProps {
97
97
  prependPlaceholder?: boolean;
98
98
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
99
99
  showNonTappableOptions?: boolean;
100
+ /**
101
+ * When true, a plain question of two or more options past the starting
102
+ * state leads with an All option, pictured with the first options'
103
+ * pictures; picking it skips the question. The price question, which
104
+ * declines the bound with its own "any price", gets none. Default false.
105
+ */
106
+ allOption?: boolean;
100
107
  /**
101
108
  * When true (default), a location parameter without options searches the
102
109
  * server's location search (cities, addresses, landmarks) as the user types
@@ -110,7 +117,7 @@ interface AIAutocompleteProps {
110
117
  showChipIcons?: boolean;
111
118
  /** When true (default), a completed chip in the input draws the picture (`image_url`) of the option that answered it, in place of its icon. Set to false to render chips without pictures. */
112
119
  showChipImages?: boolean;
113
- /** When true, every completed chip in the input ends in a small, faint "×" that removes the chip in one tap (the same result as Backspace at the chip's trailing edge). Default: false. */
120
+ /** When true, every chip in the input (completed, or identified by the server in typed text) ends in a small, faint "×" that removes the chip in one tap (the same result as Backspace at the chip's trailing edge). Default: false. */
114
121
  showChipRemove?: boolean;
115
122
  /** When true (default), an option that carries an `image_url` draws it as a square thumbnail before its text in the dropdown (in place of its `icon_svg`). Set to false to render option rows without pictures. */
116
123
  showOptionImages?: boolean;
@@ -286,6 +293,13 @@ interface UseAIAutocompleteOptions {
286
293
  prependPlaceholder?: boolean;
287
294
  /** When true (default), non-tappable options are rendered in the dropdown alongside tappable ones. Set to false to hide them entirely. */
288
295
  showNonTappableOptions?: boolean;
296
+ /**
297
+ * When true, a plain question of two or more options past the starting
298
+ * state leads with an All option, pictured with the first options'
299
+ * pictures; picking it skips the question. The price question, which
300
+ * declines the bound with its own "any price", gets none. Default false.
301
+ */
302
+ allOption?: boolean;
289
303
  /**
290
304
  * When true (default), a location parameter without options searches the
291
305
  * server's location search (cities, addresses, landmarks) as the user types
@@ -526,7 +540,7 @@ interface UseAIAutocompleteReturn {
526
540
  caretOffset: number | null;
527
541
  /** Tier 1 re-edit: enter re-edit mode for the bold param with the given id. */
528
542
  startEditingParam: (paramId: string) => void;
529
- /** Remove the completed chip with the given id (the chip's "×", `showChipRemove`); the same result as Backspace at the chip's trailing edge. Returns false when no completed chip has that id. */
543
+ /** Remove the chip (completed or identified) with the given id (the chip's "×", `showChipRemove`); the same result as Backspace at the chip's trailing edge. Returns false when no chip has that id. */
530
544
  removeParam: (paramId: string) => boolean;
531
545
  /** Tier 1 re-edit: exit re-edit mode. */
532
546
  exitEditMode: () => void;
@@ -736,6 +750,6 @@ declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProp
736
750
 
737
751
  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, formatType, dateView, selectedDateIso, selectedDateRange, dateRangeStart, dateReferences, onPreviousMonth, onNextMonth, timeView, multiSelectView, onMultiSelectCommit, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
738
752
 
739
- declare function useAIAutocomplete({ onSubmit, onResult, onError, optionOverrides, maskCompletedText, apiConfig, additionalContext, language, currency, productId, visitorId, columns, dropdownTrigger, optionsPosition, closeDropdownOnBlur, prependPlaceholder, showNonTappableOptions, locationSearch, showOptionIcons, showOptionImages, showOptionCounts, showSkipButton, showProducts, productImageFallback, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
753
+ 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, onFocus, onBlur, value: controlledValue, completedParams: controlledParams, onChange: onChangeProp, onParamsChange, products, mapProducts, onProductSelect, onProductAddToCart, source, setCursor, }: UseAIAutocompleteOptions): UseAIAutocompleteReturn;
740
754
 
741
755
  export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };