@constructor-io/constructorio-ui-autocomplete 1.20.9 → 1.22.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.
@@ -34,6 +34,11 @@ const {
34
34
  // must be used for a hooks integrations
35
35
  query: string, // current input field value
36
36
  sections: [{...}], // array of sections data to render in menu list
37
+ totalNumResultsPerSection: {
38
+ "Products": number,
39
+ "Search Suggestions": number,
40
+ ...
41
+ }, // total number of product and search suggestion results (and other sections)
37
42
  getFormProps: () => ({...})), // prop getter for jsx form element
38
43
  getInputProps: () => ({...})), // prop getter for jsx input element
39
44
  getMenuProps: () => ({...})), // prop getter for jsx element rendering the results container
@@ -57,7 +57,7 @@ const useCioAutocomplete = (options) => {
57
57
  const previousQuery = (0, usePrevious_1.default)(query);
58
58
  const cioClient = (0, useCioClient_1.default)({ apiKey, cioJsClient, cioJsClientOptions });
59
59
  // Get autocomplete sections (autocomplete + recommendations + custom)
60
- const { activeSections, activeSectionsWithData, zeroStateActiveSections, request } = (0, useSections_1.default)(query, cioClient, sections, zeroStateSections, advancedParameters);
60
+ const { activeSections, activeSectionsWithData, zeroStateActiveSections, request, totalNumResultsPerSection, } = (0, useSections_1.default)(query, cioClient, sections, zeroStateSections, advancedParameters);
61
61
  const features = (0, react_1.useMemo)(() => (0, utils_1.getFeatures)(request), [request]);
62
62
  // Get dropdown items array from active sections (autocomplete + recommendations + custom)
63
63
  const items = (0, react_1.useMemo)(() => (0, utils_1.getItemsForActiveSections)(activeSectionsWithData), [activeSectionsWithData]);
@@ -69,6 +69,7 @@ const useCioAutocomplete = (options) => {
69
69
  return {
70
70
  query,
71
71
  sections: activeSectionsWithData,
72
+ totalNumResultsPerSection,
72
73
  request,
73
74
  featureToggles: features,
74
75
  isOpen: isOpen && (items === null || items === void 0 ? void 0 : items.length) > 0,
@@ -118,7 +119,7 @@ const useCioAutocomplete = (options) => {
118
119
  onSubmit({ query });
119
120
  }
120
121
  try {
121
- cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(query, { originalQuery: query });
122
+ (0, utils_1.trackSearchSubmit)(cioClient, query, { originalQuery: query });
122
123
  }
123
124
  catch (error) {
124
125
  // eslint-disable-next-line no-console
@@ -133,7 +134,7 @@ const useCioAutocomplete = (options) => {
133
134
  onSubmit({ query });
134
135
  }
135
136
  try {
136
- cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(query, { originalQuery: query });
137
+ (0, utils_1.trackSearchSubmit)(cioClient, query, { originalQuery: query });
137
138
  }
138
139
  catch (error) {
139
140
  // eslint-disable-next-line no-console
@@ -28,12 +28,18 @@ const transformResponse = (response, options) => {
28
28
  }
29
29
  });
30
30
  });
31
- return { sectionsData: newSectionsData, request: response === null || response === void 0 ? void 0 : response.request };
31
+ return {
32
+ sectionsData: newSectionsData,
33
+ request: response === null || response === void 0 ? void 0 : response.request,
34
+ totalNumResultsPerSection: response === null || response === void 0 ? void 0 : response.total_num_results_per_section,
35
+ };
32
36
  };
33
37
  const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advancedParameters) => {
38
+ // This says sectionsData but it also contain request information
34
39
  const [sectionsData, setSectionsData] = (0, react_1.useState)({
35
40
  sectionsData: {},
36
41
  request: {},
42
+ totalNumResultsPerSection: {},
37
43
  });
38
44
  const debouncedSearchTerm = (0, useDebounce_1.default)(query, advancedParameters === null || advancedParameters === void 0 ? void 0 : advancedParameters.debounce);
39
45
  const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters || {};
@@ -65,7 +71,7 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
65
71
  }
66
72
  }
67
73
  else if (!debouncedSearchTerm) {
68
- setSectionsData({ sectionsData: {}, request: {} });
74
+ setSectionsData({ sectionsData: {}, request: {}, totalNumResultsPerSection: {} });
69
75
  }
70
76
  }))();
71
77
  }, [
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const downshift_1 = require("downshift");
4
+ const utils_1 = require("../utils");
4
5
  let idCounter = 0;
5
6
  const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = '' }) => (0, downshift_1.useCombobox)({
6
7
  id: `cio-autocomplete-${idCounter++}`,
@@ -15,7 +16,7 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
15
16
  try {
16
17
  if ((selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.section) === 'Search Suggestions') {
17
18
  setQuery(selectedItem.value || '');
18
- cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(selectedItem.value, {
19
+ (0, utils_1.trackSearchSubmit)(cioClient, selectedItem.value, {
19
20
  originalQuery: previousQuery,
20
21
  });
21
22
  }
@@ -16,7 +16,7 @@ function useSections(query, cioClient, sections, zeroStateSections, advancedPara
16
16
  const autocompleteSections = (0, react_1.useMemo)(() => activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => (0, typeGuards_1.isAutocompleteSection)(config)), [activeSections]);
17
17
  const recommendationsSections = (0, react_1.useMemo)(() => activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => (0, typeGuards_1.isRecommendationsSection)(config)), [activeSections]);
18
18
  // Fetch Autocomplete Results
19
- const { sectionsData: autocompleteResults, request } = (0, useDebouncedFetchSections_1.default)(query, cioClient, autocompleteSections, advancedParameters);
19
+ const { sectionsData: autocompleteResults, request, totalNumResultsPerSection, } = (0, useDebouncedFetchSections_1.default)(query, cioClient, autocompleteSections, advancedParameters);
20
20
  // Fetch Recommendations Results
21
21
  const { recommendationsResults, podsData } = (0, useFetchRecommendationPod_1.default)(cioClient, recommendationsSections);
22
22
  // Remove sections if necessary
@@ -56,6 +56,7 @@ function useSections(query, cioClient, sections, zeroStateSections, advancedPara
56
56
  activeSectionsWithData,
57
57
  zeroStateActiveSections,
58
58
  request,
59
+ totalNumResultsPerSection,
59
60
  };
60
61
  }
61
62
  exports.default = useSections;
package/lib/cjs/utils.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.translate = exports.getItemsForActiveSections = exports.trackRecommendationView = exports.escapeRegExp = exports.getActiveSectionsWithData = exports.getCioClient = exports.disableStoryActions = exports.stringifyWithDefaults = exports.functionStrings = exports.getStoryParams = exports.sleep = exports.clearConstructorRequests = exports.isTrackingRequestSent = exports.toKebabCase = exports.camelToStartCase = exports.getItemPosition = exports.getFeatures = void 0;
3
+ exports.logger = exports.trackSearchSubmit = exports.translate = exports.getItemsForActiveSections = exports.trackRecommendationView = exports.escapeRegExp = exports.getActiveSectionsWithData = exports.getCioClient = exports.disableStoryActions = exports.stringifyWithDefaults = exports.functionStrings = exports.getStoryParams = exports.sleep = exports.clearConstructorRequests = exports.isTrackingRequestSent = exports.toKebabCase = exports.camelToStartCase = exports.getItemPosition = exports.getFeatures = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const constructorio_client_javascript_1 = tslib_1.__importDefault(require("@constructor-io/constructorio-client-javascript"));
6
+ // eslint-disable-next-line import/no-cycle
7
+ const beaconUtils_1 = require("./beaconUtils");
6
8
  const typeGuards_1 = require("./typeGuards");
7
9
  const version_1 = tslib_1.__importDefault(require("./version"));
8
10
  function getFeatures(request) {
@@ -210,3 +212,23 @@ const translate = (word, translations) => {
210
212
  return localTranslations[word] || word;
211
213
  };
212
214
  exports.translate = translate;
215
+ const trackSearchSubmit = (cioClient, term, autocompleteData = {}) => {
216
+ cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(term, autocompleteData);
217
+ (0, beaconUtils_1.storageSetItem)(beaconUtils_1.CONSTANTS.SEARCH_TERM_STORAGE_KEY, term);
218
+ (0, beaconUtils_1.storeRecentSearch)(term, {});
219
+ (0, beaconUtils_1.storeRecentAction)(beaconUtils_1.CONSTANTS.SEARCH_SUBMIT);
220
+ };
221
+ exports.trackSearchSubmit = trackSearchSubmit;
222
+ const logger = (error) => {
223
+ var _a;
224
+ try {
225
+ if (typeof process !== 'undefined' && ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.LOGGER)) {
226
+ // eslint-disable-next-line no-console
227
+ console.log(error);
228
+ }
229
+ }
230
+ catch (e) {
231
+ // process variable is not available and logger should not be active
232
+ }
233
+ };
234
+ exports.logger = logger;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.20.9';
3
+ exports.default = '1.22.0';
@@ -31,6 +31,11 @@ const {
31
31
  // must be used for a hooks integrations
32
32
  query: string, // current input field value
33
33
  sections: [{...}], // array of sections data to render in menu list
34
+ totalNumResultsPerSection: {
35
+ "Products": number,
36
+ "Search Suggestions": number,
37
+ ...
38
+ }, // total number of product and search suggestion results (and other sections)
34
39
  getFormProps: () => ({...})), // prop getter for jsx form element
35
40
  getInputProps: () => ({...})), // prop getter for jsx input element
36
41
  getMenuProps: () => ({...})), // prop getter for jsx element rendering the results container
@@ -3,7 +3,7 @@ import { useMemo, useState } from 'react';
3
3
  import useCioClient from './useCioClient';
4
4
  import useDownShift from './useDownShift';
5
5
  import usePrevious from './usePrevious';
6
- import { getItemPosition, getItemsForActiveSections, getFeatures, trackRecommendationView, toKebabCase, } from '../utils';
6
+ import { getItemPosition, getItemsForActiveSections, getFeatures, trackRecommendationView, toKebabCase, trackSearchSubmit, } from '../utils';
7
7
  import useConsoleErrors from './useConsoleErrors';
8
8
  import useSections from './useSections';
9
9
  import useRecommendationsObserver from './useRecommendationsObserver';
@@ -53,7 +53,7 @@ const useCioAutocomplete = (options) => {
53
53
  const previousQuery = usePrevious(query);
54
54
  const cioClient = useCioClient({ apiKey, cioJsClient, cioJsClientOptions });
55
55
  // Get autocomplete sections (autocomplete + recommendations + custom)
56
- const { activeSections, activeSectionsWithData, zeroStateActiveSections, request } = useSections(query, cioClient, sections, zeroStateSections, advancedParameters);
56
+ const { activeSections, activeSectionsWithData, zeroStateActiveSections, request, totalNumResultsPerSection, } = useSections(query, cioClient, sections, zeroStateSections, advancedParameters);
57
57
  const features = useMemo(() => getFeatures(request), [request]);
58
58
  // Get dropdown items array from active sections (autocomplete + recommendations + custom)
59
59
  const items = useMemo(() => getItemsForActiveSections(activeSectionsWithData), [activeSectionsWithData]);
@@ -65,6 +65,7 @@ const useCioAutocomplete = (options) => {
65
65
  return {
66
66
  query,
67
67
  sections: activeSectionsWithData,
68
+ totalNumResultsPerSection,
68
69
  request,
69
70
  featureToggles: features,
70
71
  isOpen: isOpen && items?.length > 0,
@@ -127,7 +128,7 @@ const useCioAutocomplete = (options) => {
127
128
  onSubmit({ query });
128
129
  }
129
130
  try {
130
- cioClient?.tracker.trackSearchSubmit(query, { originalQuery: query });
131
+ trackSearchSubmit(cioClient, query, { originalQuery: query });
131
132
  }
132
133
  catch (error) {
133
134
  // eslint-disable-next-line no-console
@@ -143,7 +144,7 @@ const useCioAutocomplete = (options) => {
143
144
  onSubmit({ query });
144
145
  }
145
146
  try {
146
- cioClient?.tracker.trackSearchSubmit(query, { originalQuery: query });
147
+ trackSearchSubmit(cioClient, query, { originalQuery: query });
147
148
  }
148
149
  catch (error) {
149
150
  // eslint-disable-next-line no-console
@@ -29,12 +29,18 @@ const transformResponse = (response, options) => {
29
29
  }
30
30
  });
31
31
  });
32
- return { sectionsData: newSectionsData, request: response?.request };
32
+ return {
33
+ sectionsData: newSectionsData,
34
+ request: response?.request,
35
+ totalNumResultsPerSection: response?.total_num_results_per_section,
36
+ };
33
37
  };
34
38
  const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advancedParameters) => {
39
+ // This says sectionsData but it also contain request information
35
40
  const [sectionsData, setSectionsData] = useState({
36
41
  sectionsData: {},
37
42
  request: {},
43
+ totalNumResultsPerSection: {},
38
44
  });
39
45
  const debouncedSearchTerm = useDebounce(query, advancedParameters?.debounce);
40
46
  const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters || {};
@@ -71,7 +77,7 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
71
77
  }
72
78
  }
73
79
  else if (!debouncedSearchTerm) {
74
- setSectionsData({ sectionsData: {}, request: {} });
80
+ setSectionsData({ sectionsData: {}, request: {}, totalNumResultsPerSection: {} });
75
81
  }
76
82
  })();
77
83
  }, [
@@ -1,4 +1,5 @@
1
1
  import { useCombobox } from 'downshift';
2
+ import { trackSearchSubmit } from '../utils';
2
3
  let idCounter = 0;
3
4
  const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = '' }) => useCombobox({
4
5
  id: `cio-autocomplete-${idCounter++}`,
@@ -12,7 +13,7 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
12
13
  try {
13
14
  if (selectedItem?.section === 'Search Suggestions') {
14
15
  setQuery(selectedItem.value || '');
15
- cioClient?.tracker.trackSearchSubmit(selectedItem.value, {
16
+ trackSearchSubmit(cioClient, selectedItem.value, {
16
17
  originalQuery: previousQuery,
17
18
  });
18
19
  }
@@ -13,7 +13,7 @@ export default function useSections(query, cioClient, sections, zeroStateSection
13
13
  const autocompleteSections = useMemo(() => activeSections?.filter((config) => isAutocompleteSection(config)), [activeSections]);
14
14
  const recommendationsSections = useMemo(() => activeSections?.filter((config) => isRecommendationsSection(config)), [activeSections]);
15
15
  // Fetch Autocomplete Results
16
- const { sectionsData: autocompleteResults, request } = useDebouncedFetchSection(query, cioClient, autocompleteSections, advancedParameters);
16
+ const { sectionsData: autocompleteResults, request, totalNumResultsPerSection, } = useDebouncedFetchSection(query, cioClient, autocompleteSections, advancedParameters);
17
17
  // Fetch Recommendations Results
18
18
  const { recommendationsResults, podsData } = useFetchRecommendationPod(cioClient, recommendationsSections);
19
19
  // Remove sections if necessary
@@ -52,5 +52,6 @@ export default function useSections(query, cioClient, sections, zeroStateSection
52
52
  activeSectionsWithData,
53
53
  zeroStateActiveSections,
54
54
  request,
55
+ totalNumResultsPerSection,
55
56
  };
56
57
  }
package/lib/mjs/utils.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
+ // eslint-disable-next-line import/no-cycle
3
+ import { storageSetItem, storeRecentSearch, storeRecentAction, CONSTANTS } from './beaconUtils';
2
4
  import { isRecommendationsSection } from './typeGuards';
3
5
  import version from './version';
4
6
  export function getFeatures(request) {
@@ -191,3 +193,20 @@ export const translate = (word, translations) => {
191
193
  return translations[word];
192
194
  return localTranslations[word] || word;
193
195
  };
196
+ export const trackSearchSubmit = (cioClient, term, autocompleteData = {}) => {
197
+ cioClient?.tracker.trackSearchSubmit(term, autocompleteData);
198
+ storageSetItem(CONSTANTS.SEARCH_TERM_STORAGE_KEY, term);
199
+ storeRecentSearch(term, {});
200
+ storeRecentAction(CONSTANTS.SEARCH_SUBMIT);
201
+ };
202
+ export const logger = (error) => {
203
+ try {
204
+ if (typeof process !== 'undefined' && process?.env?.LOGGER) {
205
+ // eslint-disable-next-line no-console
206
+ console.log(error);
207
+ }
208
+ }
209
+ catch (e) {
210
+ // process variable is not available and logger should not be active
211
+ }
212
+ };
@@ -1 +1 @@
1
- export default '1.20.9';
1
+ export default '1.22.0';
@@ -3,6 +3,7 @@ import { CioAutocompleteProps } from '../../types';
3
3
  export declare const CioAutocompleteContext: React.Context<{
4
4
  query: string;
5
5
  sections: import("../../types").Section[];
6
+ totalNumResultsPerSection: Record<string, number>;
6
7
  request: Partial<import("@constructor-io/constructorio-client-javascript/lib/types").AutocompleteRequestType>;
7
8
  featureToggles: {
8
9
  featureDisplaySearchSuggestionImages: boolean;
@@ -1,7 +1,7 @@
1
1
  import { AutocompleteSubmitEvent } from './types';
2
2
  export declare const apiKey = "key_M57QS8SMPdLdLx4x";
3
3
  export declare const componentDescription = "- import `CioAutocomplete` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, an `apiKey` or `cioJsClient` are required, and an `onSubmit` callback must be passed. All other values are optional.\n- Use different props to configure the behavior of this component.\n- The following stories shows how different props affect the component's behavior\n\n> Note: when we say `cioJsClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
4
- export declare const hookDescription = "- import `useCioAutocomplete` and call this custom hook in a functional component.\n- This hook leaves rendering logic up to you, while handling:\n - state management\n - data fetching\n - keyboard navigation\n - mouse interactions\n - focus and submit event handling\n - accessibility\n- To use this hook, an `apiKey` or `cioJsClient` are required, and an `onSubmit` callback must be passed to the `useCioAutocomplete` hook to configure behavior. All other values are optional.\n- use the <a href=\"https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters\" target=\"__blank\">prop getters</a> and other variables returned by this hook (below) to leverage the functionality described above with jsx elements in your react component definitions\n\n> **Important: Please note that all of the select or submit events should go through the `onSubmit` callback. The `getItemProps` hook returns click and keyboard handlers which should be applied to the elements using the spread operator (see code examples below). Adding an `onClick` event manually to the elements would override the default behavior of the library preventing it from sending tracking events and would cause different behavior between click and keyboard events. Selecting an item or submitting the search would both cause `onSubmit` to be called. **\n\nCalling the `useCioAutocomplete` hook returns an object with the following keys:\n\n```jsx\nconst {\n // must be used for a hooks integrations\n query: string, // current input field value\n sections: [{...}], // array of sections data to render in menu list\n getFormProps: () => ({...})), // prop getter for jsx form element\n getInputProps: () => ({...})), // prop getter for jsx input element\n getMenuProps: () => ({...})), // prop getter for jsx element rendering the results container\n getItemProps: (item) => ({...})), // prop getter for jsx element rendering each result\n getSectionProps: (section: Section) => ({...})), // prop getter for jsx element rendering each section.\n\n // available for use, but not required for all use cases\n selectedItem: item, // undefined or current selected item (via hover or arrow keys)\n isOpen: boolean, // current state of the menu list\n openMenu: () => void, // open menu\n closeMenu: () => void, // close menu\n setQuery: () => void, // update the current input field value\n getLabelProps: () => ({...})), // prop getter for a jsx label element\n cioJsClient, // instance of constructorio-client-javascript\n } = useCioAutocomplete(args);\n```\n\n> Note: when we say `cioJsClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n\nThe following stories show how different options affect the hook's behavior!\n";
4
+ export declare const hookDescription = "- import `useCioAutocomplete` and call this custom hook in a functional component.\n- This hook leaves rendering logic up to you, while handling:\n - state management\n - data fetching\n - keyboard navigation\n - mouse interactions\n - focus and submit event handling\n - accessibility\n- To use this hook, an `apiKey` or `cioJsClient` are required, and an `onSubmit` callback must be passed to the `useCioAutocomplete` hook to configure behavior. All other values are optional.\n- use the <a href=\"https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters\" target=\"__blank\">prop getters</a> and other variables returned by this hook (below) to leverage the functionality described above with jsx elements in your react component definitions\n\n> **Important: Please note that all of the select or submit events should go through the `onSubmit` callback. The `getItemProps` hook returns click and keyboard handlers which should be applied to the elements using the spread operator (see code examples below). Adding an `onClick` event manually to the elements would override the default behavior of the library preventing it from sending tracking events and would cause different behavior between click and keyboard events. Selecting an item or submitting the search would both cause `onSubmit` to be called. **\n\nCalling the `useCioAutocomplete` hook returns an object with the following keys:\n\n```jsx\nconst {\n // must be used for a hooks integrations\n query: string, // current input field value\n sections: [{...}], // array of sections data to render in menu list\n totalNumResultsPerSection: {\n \"Products\": number,\n \"Search Suggestions\": number,\n ...\n }, // total number of product and search suggestion results (and other sections)\n getFormProps: () => ({...})), // prop getter for jsx form element\n getInputProps: () => ({...})), // prop getter for jsx input element\n getMenuProps: () => ({...})), // prop getter for jsx element rendering the results container\n getItemProps: (item) => ({...})), // prop getter for jsx element rendering each result\n getSectionProps: (section: Section) => ({...})), // prop getter for jsx element rendering each section.\n\n // available for use, but not required for all use cases\n selectedItem: item, // undefined or current selected item (via hover or arrow keys)\n isOpen: boolean, // current state of the menu list\n openMenu: () => void, // open menu\n closeMenu: () => void, // close menu\n setQuery: () => void, // update the current input field value\n getLabelProps: () => ({...})), // prop getter for a jsx label element\n cioJsClient, // instance of constructorio-client-javascript\n } = useCioAutocomplete(args);\n```\n\n> Note: when we say `cioJsClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n\nThe following stories show how different options affect the hook's behavior!\n";
5
5
  export declare const sectionsDescription = "- by default, typing a query will fetch data for Search Suggestions and Products\n- to override this, pass an array of sections objects\n- the order of the objects in the `sections` array determines the order of the results\n- each autocomplete section object must have a `indexSectionName`\n- each recommendation section object must have a `podId`\n- each custom section object must have a `displayName`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8\n\n`indexSectionName` refers to a section under an index. The default sections are \"Products\" and \"Search Suggestions\". You can find all the sections that exist in your index under the \"Indexes\" tab of Constructor dashboard.\n\nWhen no values are passed for the `sections` argument, the following defaults are used:\n\n```jsx\n[\n {\n indexSectionName: 'Search Suggestions',\n type: 'autocomplete',\n numResults: 8\n },\n {\n indexSectionName: 'Products',\n type: 'autocomplete',\n numResults: 8\n }\n]\n```\n";
6
6
  export declare const userEventsDescription = "- pass callback functions to respond to user events\n- if provided, the onFocus callback function will be called each time the user focuses on the text input field\n- if provided, the onChange callback function will be called each time the user changes the value in the text input field\n- the onSubmit callback function will be called each time the user submits the form\n- the user can submit the form by pressing the enter key in the text input field, clicking a submit button within the form, clicking on a result, or pressing enter while a result is selected\n\n> \u26A0\uFE0F NOTE \u26A0\uFE0F Use the Storybook Canvas Actions tab to explore the behavior of all of these `OnEvent` callback functions as you interact with our Default User Events example rendered in the Canvas. In the stories below, Storybook Canvas Actions have been disabled to focus on each of these callback functions in isolation. Each of the example callback functions in the stories below log output to the console tab of the browser's developer tools.";
7
7
  export declare const zeroStateDescription = "- when the text input field has no text, we call this zero state\n- by default, the autocomplete shows nothing in the menu it's for zero state\n- to show zero state results, pass an array of section objects for `zeroStateSections`\n- when `zeroStateSections` has sections, the menu will open on user focus by default\n- set `openOnFocus` to false, to only show `zeroStateSections` after user has typed and then cleared the text input, instead of as soon as the user focuses on the text input\n- the order of the objects in the `zeroStateSections` array determines the order of the results\n- each autocomplete section object must have a `indexSectionName`\n- each recommendation section object must have a `podId`\n- each custom section object must have a `displayName`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8";
@@ -4,6 +4,7 @@ export type UseCioAutocompleteOptions = Omit<CioAutocompleteProps, 'children'>;
4
4
  declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
5
5
  query: string;
6
6
  sections: Section[];
7
+ totalNumResultsPerSection: Record<string, number>;
7
8
  request: Partial<import("@constructor-io/constructorio-client-javascript/lib/types").AutocompleteRequestType>;
8
9
  featureToggles: {
9
10
  featureDisplaySearchSuggestionImages: boolean;
@@ -6,4 +6,5 @@ export default function useSections(query: string, cioClient: Nullable<Construct
6
6
  activeSectionsWithData: Section[];
7
7
  zeroStateActiveSections: number | false | undefined;
8
8
  request: Partial<import("@constructor-io/constructorio-client-javascript/lib/types").AutocompleteRequestType>;
9
+ totalNumResultsPerSection: Record<string, number>;
9
10
  };
@@ -79,6 +79,7 @@ export type SectionsData = {
79
79
  export type AutocompleteResultSections = {
80
80
  sectionsData: SectionsData;
81
81
  request: Partial<AutocompleteRequestType>;
82
+ totalNumResultsPerSection: Record<string, number>;
82
83
  };
83
84
  type SectionType = 'autocomplete' | 'recommendations' | 'custom';
84
85
  export type SectionConfiguration = {
@@ -41,4 +41,6 @@ export declare const escapeRegExp: (string: string) => string;
41
41
  export declare const trackRecommendationView: (target: HTMLElement, activeSectionsWithData: Section[], cioClient: Nullable<ConstructorIOClient>) => void;
42
42
  export declare const getItemsForActiveSections: (activeSectionsWithData: Section[]) => Item[];
43
43
  export declare const translate: (word: string, translations?: Translations) => any;
44
+ export declare const trackSearchSubmit: (cioClient: any, term: any, autocompleteData?: {}) => void;
45
+ export declare const logger: (error: any) => void;
44
46
  export {};
@@ -1,2 +1,2 @@
1
- declare const _default: "1.20.9";
1
+ declare const _default: "1.22.0";
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.20.9",
3
+ "version": "1.22.0",
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",