@magicx-eng/ai-autocomplete-react 0.60.4 → 0.61.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 +4 -2
- package/REFERENCE.md +8 -0
- package/dist/index.d.mts +20 -2
- package/dist/index.d.ts +20 -2
- package/dist/index.js +15 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -308,6 +308,7 @@ function App() {
|
|
|
308
308
|
| `showProducts?` | `boolean` | `true` | Render the product strip below the options whenever there are products to show — see [Product strip](#product-strip). Set to `false` to render no strip. |
|
|
309
309
|
| `productsLayout?` | `"row" \| "list"` | `"row"` | How the strip lays its cards out: a horizontally scrolling row, or the same cards stacked as full-width rows — see [Product strip](#product-strip). |
|
|
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
|
+
| `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). |
|
|
311
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. |
|
|
312
313
|
| `onProductSelect?` | `(product: Product) => void` | — | Called when a product card is activated. The SDK never navigates. |
|
|
313
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). |
|
|
@@ -393,7 +394,7 @@ The SDK handles token refresh transparently: 401 → `getAccessToken` → retry
|
|
|
393
394
|
|
|
394
395
|
### `useAIAutocomplete(options)`
|
|
395
396
|
|
|
396
|
-
The headless hook for Tier 2 and Tier 3. Accepts the same options as `<AIAutocomplete />` except for the component-only rendering props: `className`, `ref`, `pillPlacement`, `mode`, `animations`, `optionsStyle`, and `autoFocus` (those belong to the wrapping component — the hook doesn't own the input element). `productImageFallback`
|
|
397
|
+
The headless hook for Tier 2 and Tier 3. Accepts the same options as `<AIAutocomplete />` except for the component-only rendering props: `className`, `ref`, `pillPlacement`, `mode`, `animations`, `optionsStyle`, and `autoFocus` (those belong to the wrapping component — the hook doesn't own the input element). `productImageFallback` and `showProductVendor` are also accepted and forwarded through `dropdownProps`. `optionsPosition` **is** accepted: it sets the arrow-key direction and flows through `dropdownProps` to the dropdown. `onFocus` and `onBlur` are forwarded and fire whenever the consumer-owned textarea's focus changes (they're driven by `inputProps.onFocus` / `inputProps.onBlur`). `onResult` is accepted too and fires after every successful round-trip — see [Reading the query as it's built](#reading-the-query-as-its-built).
|
|
397
398
|
|
|
398
399
|
#### Return Value
|
|
399
400
|
|
|
@@ -445,7 +446,7 @@ The headless hook for Tier 2 and Tier 3. Accepts the same options as `<AIAutocom
|
|
|
445
446
|
| Field | Type | Description |
|
|
446
447
|
|---|---|---|
|
|
447
448
|
| `inputProps` | `object` | Spread onto a `<textarea>`. Includes `value`, `placeholder`, `onChange`, `onKeyDown`, and ARIA attributes. |
|
|
448
|
-
| `dropdownProps` | `AIAutocompleteDropdownProps` | Spread onto `<AIAutocompleteDropdown />`. Carries the options, `activeIndex`, `onSelect` / `onHighlight`, pills, open state, `optionsPosition`, and the product strip's `products` / `productImageFallback` / `onProductSelect` / `onProductAddToCart` (only when the hook has one) / `onProductFocusChange` — read these directly to render your own dropdown in Tier 3. |
|
|
449
|
+
| `dropdownProps` | `AIAutocompleteDropdownProps` | Spread onto `<AIAutocompleteDropdown />`. Carries the options, `activeIndex`, `onSelect` / `onHighlight`, pills, open state, `optionsPosition`, and the product strip's `products` / `productImageFallback` / `showProductVendor` / `onProductSelect` / `onProductAddToCart` (only when the hook has one) / `onProductFocusChange` — read these directly to render your own dropdown in Tier 3. |
|
|
449
450
|
|
|
450
451
|
### `<AIAutocompleteDropdown />`
|
|
451
452
|
|
|
@@ -467,6 +468,7 @@ The dropdown component for Tier 2. Spread `dropdownProps` from the hook (and add
|
|
|
467
468
|
| `showPills?` | `boolean` | Whether to render pills. Default: `true`. |
|
|
468
469
|
| `products?` | `Product[]` | Product cards to render below the options grid. Empty renders no strip. |
|
|
469
470
|
| `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
|
+
| `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`. |
|
|
470
472
|
| `onProductSelect?` | `(product: Product) => void` | Called when a card is activated. |
|
|
471
473
|
| `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). |
|
|
472
474
|
| `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. |
|
package/REFERENCE.md
CHANGED
|
@@ -52,6 +52,14 @@ default); `--aia-product-list-media-size` (44px) sizes the thumbnail and
|
|
|
52
52
|
is the horizontal strip. Changing the prop re-lays the strip out at once, and
|
|
53
53
|
`<AIAutocompleteDropdown>` takes the same prop in Tier 2.
|
|
54
54
|
|
|
55
|
+
**Vendor line.** A product with a `vendor` shows it as a line above the
|
|
56
|
+
title. Pass `showProductVendor={false}` to leave that line off every card, for
|
|
57
|
+
a catalog whose titles already start with the brand. The card's other lines
|
|
58
|
+
are unchanged, and so is a product without a `vendor`. Changing the prop
|
|
59
|
+
applies to the cards on screen at once; `<AIAutocompleteDropdown>` takes the
|
|
60
|
+
same prop in Tier 2, and the hook accepts it and carries it through
|
|
61
|
+
`dropdownProps`.
|
|
62
|
+
|
|
55
63
|
**Product image fallback.** A product's image takes priority when its
|
|
56
64
|
`imageUrl` loads successfully. A missing or blank URL, or an image load error,
|
|
57
65
|
uses `productImageFallback`: `"image"` (the default) shows the existing
|
package/dist/index.d.mts
CHANGED
|
@@ -167,6 +167,12 @@ interface AIAutocompleteProps {
|
|
|
167
167
|
* Style initial tiles with `[data-aia-product-initial]` in CSS.
|
|
168
168
|
*/
|
|
169
169
|
productImageFallback?: ProductImageFallback;
|
|
170
|
+
/**
|
|
171
|
+
* Whether product cards draw the product's `vendor` as a line above the
|
|
172
|
+
* title. Default: true. Set to false when your product titles already name
|
|
173
|
+
* the brand, so a card does not show it twice.
|
|
174
|
+
*/
|
|
175
|
+
showProductVendor?: boolean;
|
|
170
176
|
/**
|
|
171
177
|
* Custom source for the product strip. Omit it and the strip shows the
|
|
172
178
|
* items the `/suggest` response itself reports as matching the query, with
|
|
@@ -368,6 +374,12 @@ interface UseAIAutocompleteOptions {
|
|
|
368
374
|
* Style initial tiles with `[data-aia-product-initial]` in CSS.
|
|
369
375
|
*/
|
|
370
376
|
productImageFallback?: ProductImageFallback;
|
|
377
|
+
/**
|
|
378
|
+
* Whether product cards draw the product's `vendor` as a line above the
|
|
379
|
+
* title. Default: true. Set to false when your product titles already name
|
|
380
|
+
* the brand, so a card does not show it twice.
|
|
381
|
+
*/
|
|
382
|
+
showProductVendor?: boolean;
|
|
371
383
|
/**
|
|
372
384
|
* Custom source for the product strip. Omit it and the strip shows the
|
|
373
385
|
* items the `/suggest` response itself reports as matching the query, with
|
|
@@ -677,6 +689,12 @@ interface AIAutocompleteDropdownProps {
|
|
|
677
689
|
* Style initial tiles with `[data-aia-product-initial]` in CSS.
|
|
678
690
|
*/
|
|
679
691
|
productImageFallback?: ProductImageFallback;
|
|
692
|
+
/**
|
|
693
|
+
* Whether product cards draw the product's `vendor` as a line above the
|
|
694
|
+
* title. Default: true. Set to false when your product titles already name
|
|
695
|
+
* the brand, so a card does not show it twice.
|
|
696
|
+
*/
|
|
697
|
+
showProductVendor?: boolean;
|
|
680
698
|
/**
|
|
681
699
|
* Called when focus moves into / out of the product strip. The panel closes
|
|
682
700
|
* on blur by default and the input blurs the instant a card takes focus, so
|
|
@@ -774,8 +792,8 @@ interface AIAutocompleteDropdownProps {
|
|
|
774
792
|
|
|
775
793
|
declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProps & react.RefAttributes<AIAutocompleteHandle>>;
|
|
776
794
|
|
|
777
|
-
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, onSeeAllResults, fullWidth, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
|
|
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;
|
|
778
796
|
|
|
779
|
-
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;
|
|
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;
|
|
780
798
|
|
|
781
799
|
export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };
|
package/dist/index.d.ts
CHANGED
|
@@ -167,6 +167,12 @@ interface AIAutocompleteProps {
|
|
|
167
167
|
* Style initial tiles with `[data-aia-product-initial]` in CSS.
|
|
168
168
|
*/
|
|
169
169
|
productImageFallback?: ProductImageFallback;
|
|
170
|
+
/**
|
|
171
|
+
* Whether product cards draw the product's `vendor` as a line above the
|
|
172
|
+
* title. Default: true. Set to false when your product titles already name
|
|
173
|
+
* the brand, so a card does not show it twice.
|
|
174
|
+
*/
|
|
175
|
+
showProductVendor?: boolean;
|
|
170
176
|
/**
|
|
171
177
|
* Custom source for the product strip. Omit it and the strip shows the
|
|
172
178
|
* items the `/suggest` response itself reports as matching the query, with
|
|
@@ -368,6 +374,12 @@ interface UseAIAutocompleteOptions {
|
|
|
368
374
|
* Style initial tiles with `[data-aia-product-initial]` in CSS.
|
|
369
375
|
*/
|
|
370
376
|
productImageFallback?: ProductImageFallback;
|
|
377
|
+
/**
|
|
378
|
+
* Whether product cards draw the product's `vendor` as a line above the
|
|
379
|
+
* title. Default: true. Set to false when your product titles already name
|
|
380
|
+
* the brand, so a card does not show it twice.
|
|
381
|
+
*/
|
|
382
|
+
showProductVendor?: boolean;
|
|
371
383
|
/**
|
|
372
384
|
* Custom source for the product strip. Omit it and the strip shows the
|
|
373
385
|
* items the `/suggest` response itself reports as matching the query, with
|
|
@@ -677,6 +689,12 @@ interface AIAutocompleteDropdownProps {
|
|
|
677
689
|
* Style initial tiles with `[data-aia-product-initial]` in CSS.
|
|
678
690
|
*/
|
|
679
691
|
productImageFallback?: ProductImageFallback;
|
|
692
|
+
/**
|
|
693
|
+
* Whether product cards draw the product's `vendor` as a line above the
|
|
694
|
+
* title. Default: true. Set to false when your product titles already name
|
|
695
|
+
* the brand, so a card does not show it twice.
|
|
696
|
+
*/
|
|
697
|
+
showProductVendor?: boolean;
|
|
680
698
|
/**
|
|
681
699
|
* Called when focus moves into / out of the product strip. The panel closes
|
|
682
700
|
* on blur by default and the input blurs the instant a card takes focus, so
|
|
@@ -774,8 +792,8 @@ interface AIAutocompleteDropdownProps {
|
|
|
774
792
|
|
|
775
793
|
declare const AIAutocomplete: react.ForwardRefExoticComponent<AIAutocompleteProps & react.RefAttributes<AIAutocompleteHandle>>;
|
|
776
794
|
|
|
777
|
-
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, onSeeAllResults, fullWidth, onTimeChange, onTimeCommit, locationView, isReediting, onLocationQuery, onLocationMove, onLocationCommit, onLocationFocusChange, isFocused, optionsPosition, mode, }: AIAutocompleteDropdownProps): react_jsx_runtime.JSX.Element;
|
|
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;
|
|
778
796
|
|
|
779
|
-
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;
|
|
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;
|
|
780
798
|
|
|
781
799
|
export { AIAutocomplete, AIAutocompleteDropdown, type AIAutocompleteDropdownProps, type AIAutocompleteHandle, type AIAutocompleteProps, type UseAIAutocompleteOptions, type UseAIAutocompleteReturn, useAIAutocomplete };
|