@constructor-io/constructorio-ui-autocomplete 1.25.5 → 1.26.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.
@@ -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.onIsOpenChangeDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.displayNoResultsMessageDescription = 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.displayNoResultsMessageDescription = exports.displaySearchTermHighlightsDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioClientOptionsDescription = 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
  /// //////////////////////////////
@@ -119,7 +119,9 @@ exports.apiKeyDescription = `Pass an \`apiKey\` to request results from construc
119
119
  exports.cioJsClientDescription = `If you are already using an instance of the \`ConstructorIOClient\`, you can pass a \`cioJsClient\` instead of an \`apiKey\` to request results from constructor's servers
120
120
 
121
121
  > 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)`;
122
- exports.cioJsClientOptionsDescription = `If you don't want to create an instance of the \`ConstructorIOClient\` but still want to customize some of the options, you can pass a \`cioJsClientOptions\` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).`;
122
+ exports.cioClientOptionsDescription = `If you don't want to create an instance of the \`ConstructorIOClient\` but still want to customize some of the options, you can pass a \`cioClientOptions\` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).
123
+
124
+ > Note: The legacy \`cioJsClientOptions\` prop is still supported for backwards compatibility, but \`cioClientOptions\` is now the preferred name.`;
123
125
  exports.placeholderDescription = `Pass a \`placeholder\` to override the default input field placeholder text shown to users before they start typing their query`;
124
126
  exports.searchSuggestionsDescription = `Override default \`sections\` to only suggest search terms`;
125
127
  exports.productsDescription = `Override default \`sections\` to only suggested products`;
@@ -28,11 +28,16 @@ exports.defaultSections = [
28
28
  },
29
29
  ];
30
30
  const useCioAutocomplete = (options) => {
31
- const { sections, zeroStateSections, cioJsClientOptions, advancedParameters } = (0, useNormalizedProps_1.default)(options);
31
+ const { sections, zeroStateSections, cioClientOptions, advancedParameters } = (0, useNormalizedProps_1.default)(options);
32
32
  const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', defaultInput, getSearchResultsUrl } = options, rest = tslib_1.__rest(options, ["onSubmit", "onChange", "openOnFocus", "apiKey", "cioJsClient", "placeholder", "autocompleteClassName", "defaultInput", "getSearchResultsUrl"]);
33
33
  const [query, setQuery] = (0, react_1.useState)(defaultInput || '');
34
34
  const previousQuery = (0, usePrevious_1.default)(query);
35
- const cioClient = (0, useCioClient_1.default)({ apiKey, cioJsClient, cioJsClientOptions });
35
+ const cioClient = (0, useCioClient_1.default)({
36
+ apiKey,
37
+ cioJsClient,
38
+ cioClientOptions,
39
+ cioJsClientOptions: options.cioJsClientOptions,
40
+ });
36
41
  // Get autocomplete sections (autocomplete + recommendations + custom)
37
42
  const { fetchRecommendationResults, activeSections, activeSectionsWithData, zeroStateActiveSections, request, totalNumResultsPerSection, } = (0, useSections_1.default)(query, cioClient, sections, zeroStateSections, advancedParameters);
38
43
  const features = (0, react_1.useMemo)(() => (0, features_1.getFeatures)(request), [request]);
@@ -2,11 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const react_1 = require("react");
4
4
  const helpers_1 = require("../utils/helpers");
5
- const useCioClient = ({ apiKey, cioJsClient, cioJsClientOptions }) => {
5
+ const useCioClient = ({ apiKey, cioJsClient, cioClientOptions, cioJsClientOptions, }) => {
6
6
  if (!apiKey && !cioJsClient) {
7
7
  // eslint-disable-next-line no-console
8
8
  console.error('Either apiKey or cioJsClient is required');
9
9
  }
10
- return (0, react_1.useMemo)(() => cioJsClient || (0, helpers_1.getCioClient)(apiKey, cioJsClientOptions), [apiKey, cioJsClient, cioJsClientOptions]);
10
+ const mergedClientOptions = cioClientOptions !== null && cioClientOptions !== void 0 ? cioClientOptions : cioJsClientOptions;
11
+ return (0, react_1.useMemo)(() => cioJsClient || (0, helpers_1.getCioClient)(apiKey, mergedClientOptions), [apiKey, cioJsClient, mergedClientOptions]);
11
12
  };
12
13
  exports.default = useCioClient;
@@ -38,15 +38,15 @@ const normalizeSections = (sections) => {
38
38
  };
39
39
  // Normalize and Memoize Objects to prevent infinite rerenders if users pass object literals to useCioAutocomplete
40
40
  const useNormalizedProps = (options) => {
41
- const { sections = exports.defaultSections, zeroStateSections, cioJsClientOptions, advancedParameters, } = options;
41
+ const { sections = exports.defaultSections, zeroStateSections, cioClientOptions, cioJsClientOptions, advancedParameters, } = options;
42
42
  const sectionsMemoized = (0, react_1.useMemo)(() => normalizeSections(sections), [JSON.stringify(sections)]);
43
43
  const zeroStateSectionsMemoized = (0, react_1.useMemo)(() => normalizeSections(zeroStateSections), [JSON.stringify(zeroStateSections)]);
44
- const cioJsClientOptionsMemoized = (0, react_1.useMemo)(() => cioJsClientOptions, [JSON.stringify(cioJsClientOptions)]);
44
+ const cioClientOptionsMemoized = (0, react_1.useMemo)(() => cioClientOptions !== null && cioClientOptions !== void 0 ? cioClientOptions : cioJsClientOptions, [JSON.stringify(cioClientOptions), JSON.stringify(cioJsClientOptions)]);
45
45
  const advancedParametersMemoized = (0, react_1.useMemo)(() => advancedParameters, [JSON.stringify(advancedParameters)]);
46
46
  return {
47
47
  sections: sectionsMemoized,
48
48
  zeroStateSections: zeroStateSectionsMemoized,
49
- cioJsClientOptions: cioJsClientOptionsMemoized,
49
+ cioClientOptions: cioClientOptionsMemoized,
50
50
  advancedParameters: advancedParametersMemoized,
51
51
  };
52
52
  };
@@ -61,9 +61,9 @@ const disableStoryActions = (story) => {
61
61
  story.parameters.actions = { argTypesRegex: null };
62
62
  };
63
63
  exports.disableStoryActions = disableStoryActions;
64
- const getCioClient = (apiKey, cioJsClientOptions) => {
64
+ const getCioClient = (apiKey, cioClientOptions) => {
65
65
  if (apiKey && typeof window !== 'undefined') {
66
- const cioClient = new constructorio_client_javascript_1.default(Object.assign(Object.assign({ apiKey, sendTrackingEvents: true, version: `cio-ui-autocomplete-${version_1.default}` }, cioJsClientOptions), { eventDispatcher: { waitForBeacon: false } }));
66
+ const cioClient = new constructorio_client_javascript_1.default(Object.assign(Object.assign({ apiKey, sendTrackingEvents: true, version: `cio-ui-autocomplete-${version_1.default}` }, cioClientOptions), { eventDispatcher: { waitForBeacon: false } }));
67
67
  // eslint-disable-next-line no-console
68
68
  cioClient.tracker.on('error', (error) => console.error(error));
69
69
  return cioClient;
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '1.25.5';
3
+ exports.default = '1.26.0';
@@ -116,7 +116,9 @@ export const apiKeyDescription = `Pass an \`apiKey\` to request results from con
116
116
  export const cioJsClientDescription = `If you are already using an instance of the \`ConstructorIOClient\`, you can pass a \`cioJsClient\` instead of an \`apiKey\` to request results from constructor's servers
117
117
 
118
118
  > 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)`;
119
- export const cioJsClientOptionsDescription = `If you don't want to create an instance of the \`ConstructorIOClient\` but still want to customize some of the options, you can pass a \`cioJsClientOptions\` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).`;
119
+ export const cioClientOptionsDescription = `If you don't want to create an instance of the \`ConstructorIOClient\` but still want to customize some of the options, you can pass a \`cioClientOptions\` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).
120
+
121
+ > Note: The legacy \`cioJsClientOptions\` prop is still supported for backwards compatibility, but \`cioClientOptions\` is now the preferred name.`;
120
122
  export const placeholderDescription = `Pass a \`placeholder\` to override the default input field placeholder text shown to users before they start typing their query`;
121
123
  export const searchSuggestionsDescription = `Override default \`sections\` to only suggest search terms`;
122
124
  export const productsDescription = `Override default \`sections\` to only suggested products`;
@@ -24,11 +24,16 @@ export const defaultSections = [
24
24
  },
25
25
  ];
26
26
  const useCioAutocomplete = (options) => {
27
- const { sections, zeroStateSections, cioJsClientOptions, advancedParameters } = useNormalizedProps(options);
27
+ const { sections, zeroStateSections, cioClientOptions, advancedParameters } = useNormalizedProps(options);
28
28
  const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = 'What can we help you find today?', autocompleteClassName = 'cio-autocomplete', defaultInput, getSearchResultsUrl, ...rest } = options;
29
29
  const [query, setQuery] = useState(defaultInput || '');
30
30
  const previousQuery = usePrevious(query);
31
- const cioClient = useCioClient({ apiKey, cioJsClient, cioJsClientOptions });
31
+ const cioClient = useCioClient({
32
+ apiKey,
33
+ cioJsClient,
34
+ cioClientOptions,
35
+ cioJsClientOptions: options.cioJsClientOptions,
36
+ });
32
37
  // Get autocomplete sections (autocomplete + recommendations + custom)
33
38
  const { fetchRecommendationResults, activeSections, activeSectionsWithData, zeroStateActiveSections, request, totalNumResultsPerSection, } = useSections(query, cioClient, sections, zeroStateSections, advancedParameters);
34
39
  const features = useMemo(() => getFeatures(request), [request]);
@@ -1,10 +1,11 @@
1
1
  import { useMemo } from 'react';
2
2
  import { getCioClient } from '../utils/helpers';
3
- const useCioClient = ({ apiKey, cioJsClient, cioJsClientOptions }) => {
3
+ const useCioClient = ({ apiKey, cioJsClient, cioClientOptions, cioJsClientOptions, }) => {
4
4
  if (!apiKey && !cioJsClient) {
5
5
  // eslint-disable-next-line no-console
6
6
  console.error('Either apiKey or cioJsClient is required');
7
7
  }
8
- return useMemo(() => cioJsClient || getCioClient(apiKey, cioJsClientOptions), [apiKey, cioJsClient, cioJsClientOptions]);
8
+ const mergedClientOptions = cioClientOptions ?? cioJsClientOptions;
9
+ return useMemo(() => cioJsClient || getCioClient(apiKey, mergedClientOptions), [apiKey, cioJsClient, mergedClientOptions]);
9
10
  };
10
11
  export default useCioClient;
@@ -35,15 +35,15 @@ const normalizeSections = (sections) => {
35
35
  };
36
36
  // Normalize and Memoize Objects to prevent infinite rerenders if users pass object literals to useCioAutocomplete
37
37
  const useNormalizedProps = (options) => {
38
- const { sections = defaultSections, zeroStateSections, cioJsClientOptions, advancedParameters, } = options;
38
+ const { sections = defaultSections, zeroStateSections, cioClientOptions, cioJsClientOptions, advancedParameters, } = options;
39
39
  const sectionsMemoized = useMemo(() => normalizeSections(sections), [JSON.stringify(sections)]);
40
40
  const zeroStateSectionsMemoized = useMemo(() => normalizeSections(zeroStateSections), [JSON.stringify(zeroStateSections)]);
41
- const cioJsClientOptionsMemoized = useMemo(() => cioJsClientOptions, [JSON.stringify(cioJsClientOptions)]);
41
+ const cioClientOptionsMemoized = useMemo(() => cioClientOptions ?? cioJsClientOptions, [JSON.stringify(cioClientOptions), JSON.stringify(cioJsClientOptions)]);
42
42
  const advancedParametersMemoized = useMemo(() => advancedParameters, [JSON.stringify(advancedParameters)]);
43
43
  return {
44
44
  sections: sectionsMemoized,
45
45
  zeroStateSections: zeroStateSectionsMemoized,
46
- cioJsClientOptions: cioJsClientOptionsMemoized,
46
+ cioClientOptions: cioClientOptionsMemoized,
47
47
  advancedParameters: advancedParametersMemoized,
48
48
  };
49
49
  };
@@ -50,13 +50,13 @@ export const disableStoryActions = (story) => {
50
50
  // eslint-disable-next-line
51
51
  story.parameters.actions = { argTypesRegex: null };
52
52
  };
53
- export const getCioClient = (apiKey, cioJsClientOptions) => {
53
+ export const getCioClient = (apiKey, cioClientOptions) => {
54
54
  if (apiKey && typeof window !== 'undefined') {
55
55
  const cioClient = new ConstructorIOClient({
56
56
  apiKey,
57
57
  sendTrackingEvents: true,
58
58
  version: `cio-ui-autocomplete-${version}`,
59
- ...cioJsClientOptions,
59
+ ...cioClientOptions,
60
60
  eventDispatcher: { waitForBeacon: false },
61
61
  });
62
62
  // eslint-disable-next-line no-console
@@ -1 +1 @@
1
- export default '1.25.5';
1
+ export default '1.26.0';
@@ -8,7 +8,7 @@ export declare const zeroStateDescription = "- when the text input field has no
8
8
  export declare const fullFeaturedAndStyledExampleDescription = "Using the default options, the library displays clean and minimal visual elements, with the intent of making it easy for consumers to easily extend and customize the styles to suit unique needs. The example below shows a full featured and styled example to demonstrate what is possible using Constructor.io's advanced Autocomplete UI library.";
9
9
  export declare const apiKeyDescription = "Pass an `apiKey` to request results from constructor's servers";
10
10
  export declare const cioJsClientDescription = "If you are already using an instance of the `ConstructorIOClient`, you can pass a `cioJsClient` instead of an `apiKey` to request results from constructor's servers\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)";
11
- export declare const cioJsClientOptionsDescription = "If you don't want to create an instance of the `ConstructorIOClient` but still want to customize some of the options, you can pass a `cioJsClientOptions` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).";
11
+ export declare const cioClientOptionsDescription = "If you don't want to create an instance of the `ConstructorIOClient` but still want to customize some of the options, you can pass a `cioClientOptions` object. You can learn more about the possible values [here under the parameters section](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html).\n\n> Note: The legacy `cioJsClientOptions` prop is still supported for backwards compatibility, but `cioClientOptions` is now the preferred name.";
12
12
  export declare const placeholderDescription = "Pass a `placeholder` to override the default input field placeholder text shown to users before they start typing their query";
13
13
  export declare const searchSuggestionsDescription = "Override default `sections` to only suggest search terms";
14
14
  export declare const productsDescription = "Override default `sections` to only suggested products";
@@ -3,7 +3,7 @@ export declare const defaultSections: UserDefinedSection[];
3
3
  declare const useNormalizedProps: (options: UseCioAutocompleteOptions) => {
4
4
  sections: UserDefinedSection[];
5
5
  zeroStateSections: UserDefinedSection[] | undefined;
6
- cioJsClientOptions: import("@constructor-io/constructorio-client-javascript").ConstructorClientOptions | undefined;
6
+ cioClientOptions: import("@constructor-io/constructorio-client-javascript").ConstructorClientOptions | undefined;
7
7
  advancedParameters: import("../types").AdvancedParameters | undefined;
8
8
  };
9
9
  export default useNormalizedProps;
@@ -13,7 +13,11 @@ export type CioClientConfig = {
13
13
  */
14
14
  cioJsClient?: ConstructorIOClient;
15
15
  /**
16
- * Pass a `cioJsClientOptions` object to customize the client's configurations w/o creating a new instance of `ConstructorIOClient`. You can learn more about the possible values [Here](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html)
16
+ * Pass a `cioClientOptions` object to customize the client's configurations w/o creating a new instance of `ConstructorIOClient`. You can learn more about the possible values [Here](https://constructor-io.github.io/constructorio-client-javascript/ConstructorIO.html)
17
+ */
18
+ cioClientOptions?: ConstructorClientOptions;
19
+ /**
20
+ * @deprecated Use `cioClientOptions` instead.
17
21
  */
18
22
  cioJsClientOptions?: ConstructorClientOptions;
19
23
  };
@@ -26,7 +26,7 @@ export declare const functionStrings: {
26
26
  renderItem: string;
27
27
  };
28
28
  export declare const disableStoryActions: (story: any) => void;
29
- export declare const getCioClient: (apiKey?: string, cioJsClientOptions?: ConstructorClientOptions) => ConstructorIOClient | null;
29
+ export declare const getCioClient: (apiKey?: string, cioClientOptions?: ConstructorClientOptions) => ConstructorIOClient | null;
30
30
  export declare const getActiveSectionsWithData: (activeSections: UserDefinedSection[], sectionsResults: SectionsData, sectionsRefs: React.MutableRefObject<React.RefObject<HTMLLIElement>[]>, podsData: Record<string, PodData>) => Section[];
31
31
  export declare const escapeRegExp: (string: string) => string;
32
32
  export declare const getItemsForActiveSections: (activeSectionsWithData: Section[]) => Item[];
@@ -1,2 +1,2 @@
1
- declare const _default: "1.25.5";
1
+ declare const _default: "1.26.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.25.5",
3
+ "version": "1.26.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",