@constructor-io/constructorio-ui-autocomplete 1.23.17 → 1.23.18

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.displayShowAllResultsButtonDescription = exports.customRenderItemDescription = exports.translationsDescription = exports.fetchZeroStateOnFocusDescription = exports.debounceDescription = exports.termsWithImagesAndCountsDescription = exports.filteredSuggestionsDescription = exports.termsWithGroupSuggestionsDescription = exports.advancedParametersDefaultDescription = exports.advancedParametersDescription = exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDefault = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.displaySearchTermHighlightsDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientOptionsDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.fullFeaturedAndStyledExampleDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
3
+ exports.displayShowAllResultsButtonDescription = exports.customRenderItemDescription = exports.translationsDescription = exports.fetchZeroStateOnFocusDescription = exports.debounceDescription = exports.termsWithImagesAndCountsDescription = exports.filteredSuggestionsDescription = exports.termsWithGroupSuggestionsDescription = exports.advancedParametersDefaultDescription = exports.advancedParametersDescription = exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDefault = exports.onSubmitDescription = exports.onIsOpenChangeDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.displaySearchTermHighlightsDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientOptionsDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.fullFeaturedAndStyledExampleDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
4
4
  // Autocomplete key index
5
5
  exports.apiKey = 'key_M57QS8SMPdLdLx4x';
6
6
  /// //////////////////////////////
@@ -129,6 +129,7 @@ exports.displaySearchTermHighlightsDescription = `Use constructor's auto highlig
129
129
  exports.customSectionDescription = `Use a custom section, by managing and passing your own data, with \`"type": "custom"\` and \`"data":[{...}]\``;
130
130
  exports.onFocusDescription = `Pass an \`onFocus\` callback function to execute some code each time the user applies focus to the text input field`;
131
131
  exports.onChangeDescription = `Pass an \`onChange\` callback function to execute some code each time the user changes the value of the text input field`;
132
+ exports.onIsOpenChangeDescription = `Pass an \`onIsOpenChange\` callback function to execute some code each time the dropdown state changes ie: close/open`;
132
133
  exports.onSubmitDescription = `Pass an \`onSubmit\` callback function to execute some code after a user submits the search form.
133
134
 
134
135
  Your callback function will be invoked with a submit event containing useful metadata about the submit event:
@@ -41,7 +41,7 @@ const convertLegacyParametersAndAddDefaults = (sections) => sections.map((config
41
41
  const useCioAutocomplete = (options) => {
42
42
  // eslint-disable-next-line react-hooks/exhaustive-deps
43
43
  const memoizedOptions = (0, react_1.useMemo)(() => options, [JSON.stringify(options)]);
44
- const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, getSearchResultsUrl, } = memoizedOptions;
44
+ const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, getSearchResultsUrl, onIsOpenChange, } = memoizedOptions;
45
45
  let { sections = exports.defaultSections, zeroStateSections } = memoizedOptions;
46
46
  sections = (0, react_1.useMemo)(() => {
47
47
  if (sections) {
@@ -63,7 +63,7 @@ const useCioAutocomplete = (options) => {
63
63
  const features = (0, react_1.useMemo)(() => (0, utils_1.getFeatures)(request), [request]);
64
64
  // Get dropdown items array from active sections (autocomplete + recommendations + custom)
65
65
  const items = (0, react_1.useMemo)(() => (0, utils_1.getItemsForActiveSections)(activeSectionsWithData), [activeSectionsWithData]);
66
- const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex, getInputProps, getItemProps: getItemPropsDownShift, } = (0, useDownShift_1.default)({ setQuery, items, onSubmit, cioClient, previousQuery });
66
+ const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex, getInputProps, getItemProps: getItemPropsDownShift, } = (0, useDownShift_1.default)({ setQuery, items, onSubmit, cioClient, previousQuery, onIsOpenChange });
67
67
  // Log console errors
68
68
  (0, useConsoleErrors_1.default)(sections, activeSections);
69
69
  // Track recommendation view
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const downshift_1 = require("downshift");
4
4
  const utils_1 = require("../utils");
5
5
  let idCounter = 0;
6
- const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = '' }) => (0, downshift_1.useCombobox)({
6
+ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = '', onIsOpenChange, }) => (0, downshift_1.useCombobox)({
7
7
  id: `cio-autocomplete-${idCounter++}`,
8
8
  items,
9
9
  itemToString: (item) => (item === null || item === void 0 ? void 0 : item.value) || '',
@@ -50,5 +50,6 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
50
50
  }
51
51
  }
52
52
  },
53
+ onIsOpenChange,
53
54
  });
54
55
  exports.default = useDownShift;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.23.17';
3
+ exports.default = '1.23.18';
@@ -126,6 +126,7 @@ export const displaySearchTermHighlightsDescription = `Use constructor's auto hi
126
126
  export const customSectionDescription = `Use a custom section, by managing and passing your own data, with \`"type": "custom"\` and \`"data":[{...}]\``;
127
127
  export const onFocusDescription = `Pass an \`onFocus\` callback function to execute some code each time the user applies focus to the text input field`;
128
128
  export const onChangeDescription = `Pass an \`onChange\` callback function to execute some code each time the user changes the value of the text input field`;
129
+ export const onIsOpenChangeDescription = `Pass an \`onIsOpenChange\` callback function to execute some code each time the dropdown state changes ie: close/open`;
129
130
  export const onSubmitDescription = `Pass an \`onSubmit\` callback function to execute some code after a user submits the search form.
130
131
 
131
132
  Your callback function will be invoked with a submit event containing useful metadata about the submit event:
@@ -37,7 +37,7 @@ const convertLegacyParametersAndAddDefaults = (sections) => sections.map((config
37
37
  const useCioAutocomplete = (options) => {
38
38
  // eslint-disable-next-line react-hooks/exhaustive-deps
39
39
  const memoizedOptions = useMemo(() => options, [JSON.stringify(options)]);
40
- const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, getSearchResultsUrl, } = memoizedOptions;
40
+ const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, getSearchResultsUrl, onIsOpenChange, } = memoizedOptions;
41
41
  let { sections = defaultSections, zeroStateSections } = memoizedOptions;
42
42
  sections = useMemo(() => {
43
43
  if (sections) {
@@ -59,7 +59,7 @@ const useCioAutocomplete = (options) => {
59
59
  const features = useMemo(() => getFeatures(request), [request]);
60
60
  // Get dropdown items array from active sections (autocomplete + recommendations + custom)
61
61
  const items = useMemo(() => getItemsForActiveSections(activeSectionsWithData), [activeSectionsWithData]);
62
- const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex, getInputProps, getItemProps: getItemPropsDownShift, } = useDownShift({ setQuery, items, onSubmit, cioClient, previousQuery });
62
+ const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu, highlightedIndex, getInputProps, getItemProps: getItemPropsDownShift, } = useDownShift({ setQuery, items, onSubmit, cioClient, previousQuery, onIsOpenChange });
63
63
  // Log console errors
64
64
  useConsoleErrors(sections, activeSections);
65
65
  // Track recommendation view
@@ -1,7 +1,7 @@
1
1
  import { useCombobox } from 'downshift';
2
2
  import { trackSearchSubmit } from '../utils';
3
3
  let idCounter = 0;
4
- const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = '' }) => useCombobox({
4
+ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = '', onIsOpenChange, }) => useCombobox({
5
5
  id: `cio-autocomplete-${idCounter++}`,
6
6
  items,
7
7
  itemToString: (item) => item?.value || '',
@@ -47,5 +47,6 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
47
47
  }
48
48
  }
49
49
  },
50
+ onIsOpenChange,
50
51
  });
51
52
  export default useDownShift;
@@ -1 +1 @@
1
- export default '1.23.17';
1
+ export default '1.23.18';
@@ -20,6 +20,7 @@ export declare const displaySearchTermHighlightsDescription = "Use constructor's
20
20
  export declare const customSectionDescription = "Use a custom section, by managing and passing your own data, with `\"type\": \"custom\"` and `\"data\":[{...}]`";
21
21
  export declare const onFocusDescription = "Pass an `onFocus` callback function to execute some code each time the user applies focus to the text input field";
22
22
  export declare const onChangeDescription = "Pass an `onChange` callback function to execute some code each time the user changes the value of the text input field";
23
+ export declare const onIsOpenChangeDescription = "Pass an `onIsOpenChange` callback function to execute some code each time the dropdown state changes ie: close/open";
23
24
  export declare const onSubmitDescription = "Pass an `onSubmit` callback function to execute some code after a user submits the search form.\n\n Your callback function will be invoked with a submit event containing useful metadata about the submit event:\n - if the user submits the text input:\n - the `query` field will provide the value of that input field\n - if the user selects a suggested item from the dropdown list:\n - the `originalQuery` field will provide the value of the input field that generated the selected item\n - an `item` object with information about the suggestion that the user selected";
24
25
  export declare const onSubmitDefault: (submitEvent: AutocompleteSubmitEvent) => void;
25
26
  export declare const zeroStateSectionsDescription = "Use `zeroStateSections` to show suggestions after a user applies focus to the search input field and before they start typing a query";
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { UseComboboxReturnValue } from 'downshift';
2
+ import { UseComboboxReturnValue, UseComboboxStateChange } from 'downshift';
3
3
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
4
4
  import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types';
5
5
  import { Item, OnSubmit } from '../types';
@@ -9,6 +9,7 @@ type UseDownShiftOptions = {
9
9
  onSubmit: OnSubmit;
10
10
  previousQuery?: string;
11
11
  cioClient: Nullable<ConstructorIOClient>;
12
+ onIsOpenChange?: (changes: UseComboboxStateChange<Item>) => void;
12
13
  };
13
14
  export type DownShift = UseComboboxReturnValue<Item>;
14
15
  type UseDownShift = (options: UseDownShiftOptions) => DownShift;
@@ -1,4 +1,4 @@
1
- import { GetItemPropsOptions } from 'downshift';
1
+ import { GetItemPropsOptions, UseComboboxStateChange } from 'downshift';
2
2
  import { ReactNode } from 'react';
3
3
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
4
4
  import { IAutocompleteParameters, SearchSuggestion as SearchSuggestionFromClient, Product as ProductFromClient, Item as ItemBase, AutocompleteRequestType, ConstructorClientOptions, RecommendationsParameters } from '@constructor-io/constructorio-client-javascript/lib/types';
@@ -25,6 +25,7 @@ export type CioAutocompleteProps = CioClientConfig & {
25
25
  onSubmit: OnSubmit;
26
26
  onFocus?: () => void;
27
27
  onChange?: (input: string) => void;
28
+ onIsOpenChange?: (changes: UseComboboxStateChange<Item>) => void;
28
29
  placeholder?: string;
29
30
  children?: ReactNode;
30
31
  sections?: UserDefinedSection[];
@@ -1,2 +1,2 @@
1
- declare const _default: "1.23.17";
1
+ declare const _default: "1.23.18";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-autocomplete",
3
- "version": "1.23.17",
3
+ "version": "1.23.18",
4
4
  "description": "Constructor.io Autocomplete UI library for web applications",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",