@constructor-io/constructorio-ui-autocomplete 1.16.1 → 1.18.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/dist/constructorio-ui-autocomplete-bundled.js +9 -9
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +3 -2
- package/lib/cjs/constants.js +10 -1
- package/lib/cjs/hooks/useCioAutocomplete.js +2 -2
- package/lib/cjs/utils.js +10 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +3 -2
- package/lib/mjs/constants.js +9 -0
- package/lib/mjs/hooks/useCioAutocomplete.js +2 -2
- package/lib/mjs/utils.js +8 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/constants.d.ts +1 -0
- package/lib/types/types.d.ts +5 -0
- package/lib/types/utils.d.ts +3 -5
- package/lib/types/version.d.ts +1 -1
- package/package.json +10 -10
|
@@ -5,12 +5,13 @@ const react_1 = tslib_1.__importStar(require("react"));
|
|
|
5
5
|
const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
|
|
6
6
|
const typeGuards_1 = require("../../../typeGuards");
|
|
7
7
|
const SectionItemText_1 = tslib_1.__importDefault(require("./SectionItemText"));
|
|
8
|
+
const utils_1 = require("../../../utils");
|
|
8
9
|
function SectionItem(props) {
|
|
9
10
|
var _a, _b, _c, _d, _e;
|
|
10
11
|
const { item, children, displaySearchTermHighlights } = props;
|
|
11
12
|
const { getItemProps, advancedParameters, query, featureToggles } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
12
13
|
const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
|
|
13
|
-
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, } = advancedParameters || {};
|
|
14
|
+
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, translations, } = advancedParameters || {};
|
|
14
15
|
let defaultChildren;
|
|
15
16
|
if ((0, typeGuards_1.isProduct)(item)) {
|
|
16
17
|
defaultChildren = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
@@ -20,7 +21,7 @@ function SectionItem(props) {
|
|
|
20
21
|
}
|
|
21
22
|
else if ((0, typeGuards_1.isInGroupSuggestion)(item)) {
|
|
22
23
|
defaultChildren = (react_1.default.createElement("p", { className: 'cio-term-in-group' },
|
|
23
|
-
|
|
24
|
+
(0, utils_1.translate)('in', translations),
|
|
24
25
|
' ',
|
|
25
26
|
react_1.default.createElement(SectionItemText_1.default, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })));
|
|
26
27
|
}
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.translationsDescription = 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;
|
|
4
4
|
// Autocomplete key index
|
|
5
5
|
exports.apiKey = 'key_M57QS8SMPdLdLx4x';
|
|
6
6
|
/// //////////////////////////////
|
|
@@ -214,3 +214,12 @@ To see this in action:
|
|
|
214
214
|
- This is because we are filtering to the "Shirts" group`;
|
|
215
215
|
exports.termsWithImagesAndCountsDescription = `Pass boolean flags for \`displaySearchSuggestionImages\` and \`displaySearchSuggestionResultCounts\` fields to display images and counts for search suggestions. These fields need to be made displayable before they can be used. Please contact your Constructor Integration Engineer for details.`;
|
|
216
216
|
exports.debounceDescription = `Pass an integer to \`debounce\` to override the recommended, default delay employed for debouncing autocomplete network requests between keystrokes as your users type into the text input field. The default value is 250, which results in a debounce delay of 250 milliseconds.`;
|
|
217
|
+
exports.translationsDescription = `Pass a \`translations\` object to display translatable words in your preferred language.
|
|
218
|
+
|
|
219
|
+
- Current translatable keys:
|
|
220
|
+
\`\`\`
|
|
221
|
+
{
|
|
222
|
+
"in": "..."
|
|
223
|
+
}
|
|
224
|
+
\`\`\`
|
|
225
|
+
`;
|
|
@@ -21,8 +21,8 @@ exports.defaultSections = [
|
|
|
21
21
|
},
|
|
22
22
|
];
|
|
23
23
|
const useCioAutocomplete = (options) => {
|
|
24
|
-
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', sections = exports.defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, } = options;
|
|
25
|
-
const [query, setQuery] = (0, react_1.useState)('');
|
|
24
|
+
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', sections = exports.defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, } = options;
|
|
25
|
+
const [query, setQuery] = (0, react_1.useState)(defaultInput || '');
|
|
26
26
|
const previousQuery = (0, usePrevious_1.default)(query);
|
|
27
27
|
const cioClient = (0, useCioClient_1.default)({ apiKey, cioJsClient, cioJsClientOptions });
|
|
28
28
|
// Get autocomplete sections (autocomplete + recommendations + custom)
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.camelToStartCase = exports.getItemPosition = exports.getSearchSuggestionFeatures = void 0;
|
|
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.camelToStartCase = exports.getItemPosition = exports.getSearchSuggestionFeatures = 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
6
|
const typeGuards_1 = require("./typeGuards");
|
|
@@ -182,3 +182,12 @@ const getItemsForActiveSections = (activeSectionsWithData) => {
|
|
|
182
182
|
return items;
|
|
183
183
|
};
|
|
184
184
|
exports.getItemsForActiveSections = getItemsForActiveSections;
|
|
185
|
+
const translate = (word, translations) => {
|
|
186
|
+
const localTranslations = {
|
|
187
|
+
in: 'in',
|
|
188
|
+
};
|
|
189
|
+
if (translations)
|
|
190
|
+
return translations[word];
|
|
191
|
+
return localTranslations[word] || word;
|
|
192
|
+
};
|
|
193
|
+
exports.translate = translate;
|
package/lib/cjs/version.js
CHANGED
|
@@ -2,11 +2,12 @@ import React, { useContext } from 'react';
|
|
|
2
2
|
import { CioAutocompleteContext } from '../CioAutocompleteProvider';
|
|
3
3
|
import { isProduct, isInGroupSuggestion, isSearchSuggestion } from '../../../typeGuards';
|
|
4
4
|
import SectionItemText from './SectionItemText';
|
|
5
|
+
import { translate } from '../../../utils';
|
|
5
6
|
export default function SectionItem(props) {
|
|
6
7
|
const { item, children, displaySearchTermHighlights } = props;
|
|
7
8
|
const { getItemProps, advancedParameters, query, featureToggles } = useContext(CioAutocompleteContext);
|
|
8
9
|
const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
|
|
9
|
-
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, } = advancedParameters || {};
|
|
10
|
+
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, translations, } = advancedParameters || {};
|
|
10
11
|
let defaultChildren;
|
|
11
12
|
if (isProduct(item)) {
|
|
12
13
|
defaultChildren = (React.createElement(React.Fragment, null,
|
|
@@ -16,7 +17,7 @@ export default function SectionItem(props) {
|
|
|
16
17
|
}
|
|
17
18
|
else if (isInGroupSuggestion(item)) {
|
|
18
19
|
defaultChildren = (React.createElement("p", { className: 'cio-term-in-group' },
|
|
19
|
-
|
|
20
|
+
translate('in', translations),
|
|
20
21
|
' ',
|
|
21
22
|
React.createElement(SectionItemText, { item: item, query: query, highlightSearchTerm: displaySearchTermHighlights })));
|
|
22
23
|
}
|
package/lib/mjs/constants.js
CHANGED
|
@@ -210,3 +210,12 @@ To see this in action:
|
|
|
210
210
|
- This is because we are filtering to the "Shirts" group`;
|
|
211
211
|
export const termsWithImagesAndCountsDescription = `Pass boolean flags for \`displaySearchSuggestionImages\` and \`displaySearchSuggestionResultCounts\` fields to display images and counts for search suggestions. These fields need to be made displayable before they can be used. Please contact your Constructor Integration Engineer for details.`;
|
|
212
212
|
export const debounceDescription = `Pass an integer to \`debounce\` to override the recommended, default delay employed for debouncing autocomplete network requests between keystrokes as your users type into the text input field. The default value is 250, which results in a debounce delay of 250 milliseconds.`;
|
|
213
|
+
export const translationsDescription = `Pass a \`translations\` object to display translatable words in your preferred language.
|
|
214
|
+
|
|
215
|
+
- Current translatable keys:
|
|
216
|
+
\`\`\`
|
|
217
|
+
{
|
|
218
|
+
"in": "..."
|
|
219
|
+
}
|
|
220
|
+
\`\`\`
|
|
221
|
+
`;
|
|
@@ -17,8 +17,8 @@ export const defaultSections = [
|
|
|
17
17
|
},
|
|
18
18
|
];
|
|
19
19
|
const useCioAutocomplete = (options) => {
|
|
20
|
-
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', sections = defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, } = options;
|
|
21
|
-
const [query, setQuery] = useState('');
|
|
20
|
+
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, cioJsClientOptions, placeholder = 'What can we help you find today?', sections = defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', advancedParameters, defaultInput, } = options;
|
|
21
|
+
const [query, setQuery] = useState(defaultInput || '');
|
|
22
22
|
const previousQuery = usePrevious(query);
|
|
23
23
|
const cioClient = useCioClient({ apiKey, cioJsClient, cioJsClientOptions });
|
|
24
24
|
// Get autocomplete sections (autocomplete + recommendations + custom)
|
package/lib/mjs/utils.js
CHANGED
|
@@ -165,3 +165,11 @@ export const getItemsForActiveSections = (activeSectionsWithData) => {
|
|
|
165
165
|
});
|
|
166
166
|
return items;
|
|
167
167
|
};
|
|
168
|
+
export const translate = (word, translations) => {
|
|
169
|
+
const localTranslations = {
|
|
170
|
+
in: 'in',
|
|
171
|
+
};
|
|
172
|
+
if (translations)
|
|
173
|
+
return translations[word];
|
|
174
|
+
return localTranslations[word] || word;
|
|
175
|
+
};
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.18.0';
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -32,3 +32,4 @@ export declare const termsWithGroupSuggestionsDescription = "Pass integers for t
|
|
|
32
32
|
export declare const filteredSuggestionsDescription = "Pass a `filters` object under `advancedParameters` to apply filters to the suggestions. Any parameter supported by <a href=\"https://docs.constructor.io/rest_api/autocomplete_queries/\" target=\"__blank\">our autocomplete endpoint</a> can be passed under `advancedParameters`.\n\nTo see this in action:\n1. Type \"short\" in the example below.\n - Notice how the user is presented with only short pants as results.\n - This is because the results are currently filtered to belong to the \"Shorts\" group.\n2. Navigate to the \"Filtered Suggestions\" story (using the navigation menu to the left)\n3. Then use the Controls to adjust the values of `\"group_id\"` to `\"1030\"`.\n4. Next, type \"short\" in the example autocomplete input field.\n - Notice how the user is presented with only short sleeved items as results.\n - This is because we are filtering to the \"Shirts\" group";
|
|
33
33
|
export declare const termsWithImagesAndCountsDescription = "Pass boolean flags for `displaySearchSuggestionImages` and `displaySearchSuggestionResultCounts` fields to display images and counts for search suggestions. These fields need to be made displayable before they can be used. Please contact your Constructor Integration Engineer for details.";
|
|
34
34
|
export declare const debounceDescription = "Pass an integer to `debounce` to override the recommended, default delay employed for debouncing autocomplete network requests between keystrokes as your users type into the text input field. The default value is 250, which results in a debounce delay of 250 milliseconds.";
|
|
35
|
+
export declare const translationsDescription = "Pass a `translations` object to display translatable words in your preferred language.\n\n- Current translatable keys:\n```\n {\n \"in\": \"...\"\n }\n```\n";
|
package/lib/types/types.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export interface AdvancedParametersBase {
|
|
|
14
14
|
displaySearchSuggestionImages?: boolean;
|
|
15
15
|
displaySearchSuggestionResultCounts?: boolean;
|
|
16
16
|
debounce?: number;
|
|
17
|
+
translations?: Translations;
|
|
17
18
|
}
|
|
18
19
|
export type AdvancedParameters = AdvancedParametersBase & Omit<IAutocompleteParameters, 'resultsPerSection'>;
|
|
19
20
|
export type CioAutocompleteProps = CioClientConfig & {
|
|
@@ -27,6 +28,7 @@ export type CioAutocompleteProps = CioClientConfig & {
|
|
|
27
28
|
zeroStateSections?: UserDefinedSection[];
|
|
28
29
|
autocompleteClassName?: string;
|
|
29
30
|
advancedParameters?: AdvancedParameters;
|
|
31
|
+
defaultInput?: string;
|
|
30
32
|
};
|
|
31
33
|
export type AutocompleteSubmitEvent = {
|
|
32
34
|
item: Item;
|
|
@@ -95,3 +97,6 @@ export type InGroupSuggestion = SearchSuggestion & {
|
|
|
95
97
|
export type HTMLPropsWithCioDataAttributes<T = any> = React.DetailedHTMLProps<React.HTMLAttributes<T>, T> & {
|
|
96
98
|
[key: `data-cnstrc-${string}`]: any;
|
|
97
99
|
};
|
|
100
|
+
export type Translations = {
|
|
101
|
+
in?: string;
|
|
102
|
+
};
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
2
|
import { AutocompleteRequestType, Nullable, ConstructorClientOptions } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
|
-
import {
|
|
3
|
+
import { Item, Section, UserDefinedSection, SectionsData, Translations } from './types';
|
|
4
4
|
export type GetItemPosition = (args: {
|
|
5
5
|
item: Item;
|
|
6
6
|
items: Item[];
|
|
@@ -31,14 +31,12 @@ export declare const getStoryParams: (storyCode: any, templateCode: any, importC
|
|
|
31
31
|
export declare const functionStrings: {
|
|
32
32
|
onSubmit: string;
|
|
33
33
|
};
|
|
34
|
-
export declare const stringifyWithDefaults: (obj:
|
|
35
|
-
apiKey: string;
|
|
36
|
-
onSubmit: OnSubmit;
|
|
37
|
-
}) => string;
|
|
34
|
+
export declare const stringifyWithDefaults: (obj: any) => string;
|
|
38
35
|
export declare const disableStoryActions: (story: any) => void;
|
|
39
36
|
export declare const getCioClient: (apiKey?: string, cioJsClientOptions?: ConstructorClientOptions) => ConstructorIOClient | null;
|
|
40
37
|
export declare const getActiveSectionsWithData: (activeSections: UserDefinedSection[], sectionResults: SectionsData, sectionsRefs: React.MutableRefObject<React.RefObject<HTMLLIElement>[]>) => Section[];
|
|
41
38
|
export declare const escapeRegExp: (string: string) => string;
|
|
42
39
|
export declare const trackRecommendationView: (target: HTMLElement, activeSectionsWithData: Section[], cioClient: Nullable<ConstructorIOClient>) => void;
|
|
43
40
|
export declare const getItemsForActiveSections: (activeSectionsWithData: Section[]) => Item[];
|
|
41
|
+
export declare const translate: (word: string, translations?: Translations) => any;
|
|
44
42
|
export {};
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.18.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.
|
|
3
|
+
"version": "1.18.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",
|
|
@@ -63,14 +63,14 @@
|
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@cspell/eslint-plugin": "^6.18.1",
|
|
66
|
-
"@storybook/addon-a11y": "^7.
|
|
67
|
-
"@storybook/addon-actions": "^7.
|
|
68
|
-
"@storybook/addon-essentials": "^7.
|
|
69
|
-
"@storybook/addon-interactions": "^7.
|
|
70
|
-
"@storybook/addon-links": "^7.
|
|
71
|
-
"@storybook/jest": "^0.
|
|
72
|
-
"@storybook/react-webpack5": "7.
|
|
73
|
-
"@storybook/test-runner": "^0.
|
|
66
|
+
"@storybook/addon-a11y": "^7.6.6",
|
|
67
|
+
"@storybook/addon-actions": "^7.6.6",
|
|
68
|
+
"@storybook/addon-essentials": "^7.6.6",
|
|
69
|
+
"@storybook/addon-interactions": "^7.6.6",
|
|
70
|
+
"@storybook/addon-links": "^7.6.6",
|
|
71
|
+
"@storybook/jest": "^0.2.3",
|
|
72
|
+
"@storybook/react-webpack5": "7.6.6",
|
|
73
|
+
"@storybook/test-runner": "^0.13.0",
|
|
74
74
|
"@storybook/testing-library": "^0.1.0",
|
|
75
75
|
"@types/react": "^18.0.20",
|
|
76
76
|
"@types/react-dom": "^18.0.6",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"react": "^18.2.0",
|
|
92
92
|
"react-dom": "^18.2.0",
|
|
93
93
|
"start-server-and-test": "^1.15.2",
|
|
94
|
-
"storybook": "^7.
|
|
94
|
+
"storybook": "^7.6.6",
|
|
95
95
|
"typescript": "^4.8.3",
|
|
96
96
|
"vite": "^4.3.7",
|
|
97
97
|
"vite-plugin-css-injected-by-js": "^3.1.1",
|