@constructor-io/constructorio-ui-autocomplete 1.13.0 → 1.13.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/dist/constructorio-ui-autocomplete-bundled.js +13 -13
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +3 -2
- package/lib/cjs/constants.js +2 -1
- package/lib/cjs/hooks/useCioAutocomplete.js +3 -1
- package/lib/cjs/hooks/useDebouncedFetchSections.js +9 -4
- package/lib/cjs/hooks/useDownShift.js +3 -1
- package/lib/cjs/hooks/useSections.js +2 -1
- package/lib/cjs/utils.js +27 -1
- package/lib/cjs/version.js +1 -1
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +3 -2
- package/lib/mjs/constants.js +1 -0
- package/lib/mjs/hooks/useCioAutocomplete.js +4 -2
- package/lib/mjs/hooks/useDebouncedFetchSections.js +9 -4
- package/lib/mjs/hooks/useDownShift.js +3 -1
- package/lib/mjs/hooks/useSections.js +2 -1
- package/lib/mjs/utils.js +24 -0
- package/lib/mjs/version.js +1 -1
- package/lib/types/components/Autocomplete/CioAutocompleteProvider.d.ts +5 -0
- package/lib/types/constants.d.ts +1 -0
- package/lib/types/hooks/useCioAutocomplete.d.ts +5 -0
- package/lib/types/hooks/useFetchRecommendationPod.d.ts +2 -2
- package/lib/types/hooks/useSections.d.ts +1 -0
- package/lib/types/types.d.ts +8 -3
- package/lib/types/utils.d.ts +7 -2
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -1
|
@@ -8,8 +8,9 @@ const SectionItemText_1 = tslib_1.__importDefault(require("./SectionItemText"));
|
|
|
8
8
|
function SectionItem(props) {
|
|
9
9
|
var _a, _b, _c, _d, _e;
|
|
10
10
|
const { item, children, displaySearchTermHighlights } = props;
|
|
11
|
-
const { getItemProps, advancedParameters, query } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
12
|
-
const {
|
|
11
|
+
const { getItemProps, advancedParameters, query, featureToggles } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
|
|
12
|
+
const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
|
|
13
|
+
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, } = advancedParameters || {};
|
|
13
14
|
let defaultChildren;
|
|
14
15
|
if ((0, typeGuards_1.isProduct)(item)) {
|
|
15
16
|
defaultChildren = (react_1.default.createElement(react_1.default.Fragment, null,
|
package/lib/cjs/constants.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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.cioJsClientDescription = exports.apiKeyDescription = exports.fullFeaturedAndStyledExampleDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
|
|
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.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
|
/// //////////////////////////////
|
|
@@ -211,3 +211,4 @@ To see this in action:
|
|
|
211
211
|
- Notice how the user is presented with only short sleeved items as results.
|
|
212
212
|
- This is because we are filtering to the "Shirts" group`;
|
|
213
213
|
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.`;
|
|
214
|
+
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.`;
|
|
@@ -26,7 +26,7 @@ const useCioAutocomplete = (options) => {
|
|
|
26
26
|
const previousQuery = (0, usePrevious_1.default)(query);
|
|
27
27
|
const cioClient = (0, useCioClient_1.default)({ apiKey, cioJsClient });
|
|
28
28
|
// Get autocomplete sections (autocomplete + recommendations + custom)
|
|
29
|
-
const { activeSections, activeSectionsWithData, zeroStateActiveSections } = (0, useSections_1.default)(query, cioClient, sections, zeroStateSections, advancedParameters);
|
|
29
|
+
const { activeSections, activeSectionsWithData, zeroStateActiveSections, request } = (0, useSections_1.default)(query, cioClient, sections, zeroStateSections, advancedParameters);
|
|
30
30
|
// Get dropdown items array from active sections (autocomplete + recommendations + custom)
|
|
31
31
|
const items = (0, useItems_1.default)(activeSectionsWithData);
|
|
32
32
|
const downshift = (0, useDownShift_1.default)({ setQuery, items, onSubmit, cioClient, previousQuery });
|
|
@@ -36,6 +36,8 @@ const useCioAutocomplete = (options) => {
|
|
|
36
36
|
return {
|
|
37
37
|
query,
|
|
38
38
|
sections: activeSectionsWithData,
|
|
39
|
+
request,
|
|
40
|
+
featureToggles: (0, utils_1.getSearchSuggestionFeatures)(request),
|
|
39
41
|
isOpen: isOpen && (items === null || items === void 0 ? void 0 : items.length) > 0,
|
|
40
42
|
getMenuProps: () => (Object.assign(Object.assign({}, getMenuProps()), { className: 'cio-results', 'data-testid': 'cio-results' })),
|
|
41
43
|
getLabelProps,
|
|
@@ -28,14 +28,19 @@ const transformResponse = (response, options) => {
|
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
});
|
|
31
|
-
return newSectionsData;
|
|
31
|
+
return { sectionsData: newSectionsData, request: response === null || response === void 0 ? void 0 : response.request };
|
|
32
32
|
};
|
|
33
33
|
const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advancedParameters) => {
|
|
34
|
-
const [sectionsData, setSectionsData] = (0, react_1.useState)({
|
|
35
|
-
|
|
34
|
+
const [sectionsData, setSectionsData] = (0, react_1.useState)({
|
|
35
|
+
sectionsData: {},
|
|
36
|
+
request: {},
|
|
37
|
+
});
|
|
38
|
+
const debouncedSearchTerm = (0, useDebounce_1.default)(query, advancedParameters === null || advancedParameters === void 0 ? void 0 : advancedParameters.debounce);
|
|
36
39
|
const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters || {};
|
|
37
40
|
const autocompleteParameters = (0, react_1.useMemo)(() => {
|
|
38
41
|
const decoratedParameters = Object.assign({}, advancedParameters);
|
|
42
|
+
// eslint-disable-next-line no-param-reassign
|
|
43
|
+
decoratedParameters === null || decoratedParameters === void 0 ? true : delete decoratedParameters.debounce;
|
|
39
44
|
if (autocompleteSections) {
|
|
40
45
|
decoratedParameters.resultsPerSection = autocompleteSections.reduce((acc, sectionConfig) => (Object.assign(Object.assign({}, acc), { [sectionConfig.identifier]: (sectionConfig === null || sectionConfig === void 0 ? void 0 : sectionConfig.numResults) || 8 })), {});
|
|
41
46
|
}
|
|
@@ -58,7 +63,7 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
|
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
else if (!debouncedSearchTerm) {
|
|
61
|
-
setSectionsData({});
|
|
66
|
+
setSectionsData({ sectionsData: {}, request: {} });
|
|
62
67
|
}
|
|
63
68
|
}))();
|
|
64
69
|
}, [
|
|
@@ -9,7 +9,9 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
|
|
|
9
9
|
onSelectedItemChange({ selectedItem }) {
|
|
10
10
|
var _a;
|
|
11
11
|
if (selectedItem) {
|
|
12
|
-
|
|
12
|
+
if ((selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.section) === 'Search Suggestions') {
|
|
13
|
+
setQuery(selectedItem.value || '');
|
|
14
|
+
}
|
|
13
15
|
if (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) {
|
|
14
16
|
if (onSubmit)
|
|
15
17
|
onSubmit({ item: selectedItem, originalQuery: previousQuery });
|
|
@@ -11,7 +11,7 @@ function useSections(query, cioClient, sections, zeroStateSections, advancedPara
|
|
|
11
11
|
const autocompleteSections = (0, react_1.useMemo)(() => activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => config.type === 'autocomplete' || !config.type), [activeSections]);
|
|
12
12
|
const recommendationsSections = activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => config.type === 'recommendations');
|
|
13
13
|
// Fetch Autocomplete Results
|
|
14
|
-
const autocompleteResults = (0, useDebouncedFetchSections_1.default)(query, cioClient, autocompleteSections, advancedParameters);
|
|
14
|
+
const { sectionsData: autocompleteResults, request } = (0, useDebouncedFetchSections_1.default)(query, cioClient, autocompleteSections, advancedParameters);
|
|
15
15
|
// Fetch Recommendations Results
|
|
16
16
|
const recommendationsResults = (0, useFetchRecommendationPod_1.default)(cioClient, recommendationsSections);
|
|
17
17
|
const sectionResults = Object.assign(Object.assign({}, autocompleteResults), recommendationsResults);
|
|
@@ -31,6 +31,7 @@ function useSections(query, cioClient, sections, zeroStateSections, advancedPara
|
|
|
31
31
|
activeSections,
|
|
32
32
|
activeSectionsWithData,
|
|
33
33
|
zeroStateActiveSections,
|
|
34
|
+
request,
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
37
|
exports.default = useSections;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.escapeRegExp = exports.getActiveSectionsWithData = exports.getCioClient = exports.disableStoryActions = exports.stringifyWithDefaults = exports.functionStrings = exports.getStoryParams = exports.sleep = exports.clearConstructorRequests = exports.isTrackingRequestSent = exports.camelToStartCase = exports.getItemPosition = void 0;
|
|
3
|
+
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");
|
|
7
7
|
const version_1 = tslib_1.__importDefault(require("./version"));
|
|
8
|
+
function getSearchSuggestionFeatures(request) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
let featureDisplaySearchSuggestionImages = false;
|
|
11
|
+
let featureDisplaySearchSuggestionResultCounts = false;
|
|
12
|
+
if (((_a = request === null || request === void 0 ? void 0 : request.features) === null || _a === void 0 ? void 0 : _a.custom_autosuggest_ui) === true) {
|
|
13
|
+
switch ((_b = request === null || request === void 0 ? void 0 : request.feature_variants) === null || _b === void 0 ? void 0 : _b.custom_autosuggest_ui) {
|
|
14
|
+
case 'custom_autosuggest_ui_result_count':
|
|
15
|
+
featureDisplaySearchSuggestionResultCounts = true;
|
|
16
|
+
break;
|
|
17
|
+
case 'custom_autosuggest_ui_image':
|
|
18
|
+
featureDisplaySearchSuggestionImages = true;
|
|
19
|
+
break;
|
|
20
|
+
case 'custom_autosuggest_ui_image_result_count':
|
|
21
|
+
featureDisplaySearchSuggestionImages = true;
|
|
22
|
+
featureDisplaySearchSuggestionResultCounts = true;
|
|
23
|
+
break;
|
|
24
|
+
default:
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
featureDisplaySearchSuggestionImages,
|
|
30
|
+
featureDisplaySearchSuggestionResultCounts,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
exports.getSearchSuggestionFeatures = getSearchSuggestionFeatures;
|
|
8
34
|
const getItemPosition = ({ item, items }) => {
|
|
9
35
|
var _a;
|
|
10
36
|
const index = items.findIndex((itemInFlatList) => (itemInFlatList === null || itemInFlatList === void 0 ? void 0 : itemInFlatList.id) === (item === null || item === void 0 ? void 0 : item.id));
|
package/lib/cjs/version.js
CHANGED
|
@@ -4,8 +4,9 @@ import { isProduct, isInGroupSuggestion, isSearchSuggestion } from '../../../typ
|
|
|
4
4
|
import SectionItemText from './SectionItemText';
|
|
5
5
|
export default function SectionItem(props) {
|
|
6
6
|
const { item, children, displaySearchTermHighlights } = props;
|
|
7
|
-
const { getItemProps, advancedParameters, query } = useContext(CioAutocompleteContext);
|
|
8
|
-
const {
|
|
7
|
+
const { getItemProps, advancedParameters, query, featureToggles } = useContext(CioAutocompleteContext);
|
|
8
|
+
const { featureDisplaySearchSuggestionImages, featureDisplaySearchSuggestionResultCounts } = featureToggles;
|
|
9
|
+
const { displaySearchSuggestionImages = featureDisplaySearchSuggestionImages, displaySearchSuggestionResultCounts = featureDisplaySearchSuggestionResultCounts, } = advancedParameters || {};
|
|
9
10
|
let defaultChildren;
|
|
10
11
|
if (isProduct(item)) {
|
|
11
12
|
defaultChildren = (React.createElement(React.Fragment, null,
|
package/lib/mjs/constants.js
CHANGED
|
@@ -207,3 +207,4 @@ To see this in action:
|
|
|
207
207
|
- Notice how the user is presented with only short sleeved items as results.
|
|
208
208
|
- This is because we are filtering to the "Shirts" group`;
|
|
209
209
|
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.`;
|
|
210
|
+
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.`;
|
|
@@ -2,7 +2,7 @@ import { useState } from 'react';
|
|
|
2
2
|
import useCioClient from './useCioClient';
|
|
3
3
|
import useDownShift from './useDownShift';
|
|
4
4
|
import usePrevious from './usePrevious';
|
|
5
|
-
import { getItemPosition } from '../utils';
|
|
5
|
+
import { getItemPosition, getSearchSuggestionFeatures } from '../utils';
|
|
6
6
|
import useConsoleErrors from './useConsoleErrors';
|
|
7
7
|
import useSections from './useSections';
|
|
8
8
|
import useItems from './useItems';
|
|
@@ -22,7 +22,7 @@ const useCioAutocomplete = (options) => {
|
|
|
22
22
|
const previousQuery = usePrevious(query);
|
|
23
23
|
const cioClient = useCioClient({ apiKey, cioJsClient });
|
|
24
24
|
// Get autocomplete sections (autocomplete + recommendations + custom)
|
|
25
|
-
const { activeSections, activeSectionsWithData, zeroStateActiveSections } = useSections(query, cioClient, sections, zeroStateSections, advancedParameters);
|
|
25
|
+
const { activeSections, activeSectionsWithData, zeroStateActiveSections, request } = useSections(query, cioClient, sections, zeroStateSections, advancedParameters);
|
|
26
26
|
// Get dropdown items array from active sections (autocomplete + recommendations + custom)
|
|
27
27
|
const items = useItems(activeSectionsWithData);
|
|
28
28
|
const downshift = useDownShift({ setQuery, items, onSubmit, cioClient, previousQuery });
|
|
@@ -32,6 +32,8 @@ const useCioAutocomplete = (options) => {
|
|
|
32
32
|
return {
|
|
33
33
|
query,
|
|
34
34
|
sections: activeSectionsWithData,
|
|
35
|
+
request,
|
|
36
|
+
featureToggles: getSearchSuggestionFeatures(request),
|
|
35
37
|
isOpen: isOpen && items?.length > 0,
|
|
36
38
|
getMenuProps: () => ({
|
|
37
39
|
...getMenuProps(),
|
|
@@ -29,16 +29,21 @@ const transformResponse = (response, options) => {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
|
-
return newSectionsData;
|
|
32
|
+
return { sectionsData: newSectionsData, request: response?.request };
|
|
33
33
|
};
|
|
34
34
|
const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advancedParameters) => {
|
|
35
|
-
const [sectionsData, setSectionsData] = useState({
|
|
36
|
-
|
|
35
|
+
const [sectionsData, setSectionsData] = useState({
|
|
36
|
+
sectionsData: {},
|
|
37
|
+
request: {},
|
|
38
|
+
});
|
|
39
|
+
const debouncedSearchTerm = useDebounce(query, advancedParameters?.debounce);
|
|
37
40
|
const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters || {};
|
|
38
41
|
const autocompleteParameters = useMemo(() => {
|
|
39
42
|
const decoratedParameters = {
|
|
40
43
|
...advancedParameters,
|
|
41
44
|
};
|
|
45
|
+
// eslint-disable-next-line no-param-reassign
|
|
46
|
+
delete decoratedParameters?.debounce;
|
|
42
47
|
if (autocompleteSections) {
|
|
43
48
|
decoratedParameters.resultsPerSection = autocompleteSections.reduce((acc, sectionConfig) => ({
|
|
44
49
|
...acc,
|
|
@@ -64,7 +69,7 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
|
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
else if (!debouncedSearchTerm) {
|
|
67
|
-
setSectionsData({});
|
|
72
|
+
setSectionsData({ sectionsData: {}, request: {} });
|
|
68
73
|
}
|
|
69
74
|
})();
|
|
70
75
|
}, [
|
|
@@ -6,7 +6,9 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
|
|
|
6
6
|
itemToString: (item) => item?.value || '',
|
|
7
7
|
onSelectedItemChange({ selectedItem }) {
|
|
8
8
|
if (selectedItem) {
|
|
9
|
-
|
|
9
|
+
if (selectedItem?.section === 'Search Suggestions') {
|
|
10
|
+
setQuery(selectedItem.value || '');
|
|
11
|
+
}
|
|
10
12
|
if (selectedItem?.value) {
|
|
11
13
|
if (onSubmit)
|
|
12
14
|
onSubmit({ item: selectedItem, originalQuery: previousQuery });
|
|
@@ -8,7 +8,7 @@ export default function useSections(query, cioClient, sections, zeroStateSection
|
|
|
8
8
|
const autocompleteSections = useMemo(() => activeSections?.filter((config) => config.type === 'autocomplete' || !config.type), [activeSections]);
|
|
9
9
|
const recommendationsSections = activeSections?.filter((config) => config.type === 'recommendations');
|
|
10
10
|
// Fetch Autocomplete Results
|
|
11
|
-
const autocompleteResults = useDebouncedFetchSection(query, cioClient, autocompleteSections, advancedParameters);
|
|
11
|
+
const { sectionsData: autocompleteResults, request } = useDebouncedFetchSection(query, cioClient, autocompleteSections, advancedParameters);
|
|
12
12
|
// Fetch Recommendations Results
|
|
13
13
|
const recommendationsResults = useFetchRecommendationPod(cioClient, recommendationsSections);
|
|
14
14
|
const sectionResults = { ...autocompleteResults, ...recommendationsResults };
|
|
@@ -28,5 +28,6 @@ export default function useSections(query, cioClient, sections, zeroStateSection
|
|
|
28
28
|
activeSections,
|
|
29
29
|
activeSectionsWithData,
|
|
30
30
|
zeroStateActiveSections,
|
|
31
|
+
request,
|
|
31
32
|
};
|
|
32
33
|
}
|
package/lib/mjs/utils.js
CHANGED
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
2
|
import { isCustomSection } from './typeGuards';
|
|
3
3
|
import version from './version';
|
|
4
|
+
export function getSearchSuggestionFeatures(request) {
|
|
5
|
+
let featureDisplaySearchSuggestionImages = false;
|
|
6
|
+
let featureDisplaySearchSuggestionResultCounts = false;
|
|
7
|
+
if (request?.features?.custom_autosuggest_ui === true) {
|
|
8
|
+
switch (request?.feature_variants?.custom_autosuggest_ui) {
|
|
9
|
+
case 'custom_autosuggest_ui_result_count':
|
|
10
|
+
featureDisplaySearchSuggestionResultCounts = true;
|
|
11
|
+
break;
|
|
12
|
+
case 'custom_autosuggest_ui_image':
|
|
13
|
+
featureDisplaySearchSuggestionImages = true;
|
|
14
|
+
break;
|
|
15
|
+
case 'custom_autosuggest_ui_image_result_count':
|
|
16
|
+
featureDisplaySearchSuggestionImages = true;
|
|
17
|
+
featureDisplaySearchSuggestionResultCounts = true;
|
|
18
|
+
break;
|
|
19
|
+
default:
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
featureDisplaySearchSuggestionImages,
|
|
25
|
+
featureDisplaySearchSuggestionResultCounts,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
4
28
|
export const getItemPosition = ({ item, items }) => {
|
|
5
29
|
const index = items.findIndex((itemInFlatList) => itemInFlatList?.id === item?.id);
|
|
6
30
|
const sectionId = items[index]?.section;
|
package/lib/mjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.13.0';
|
|
@@ -3,6 +3,11 @@ import { CioAutocompleteProps } from '../../types';
|
|
|
3
3
|
export declare const CioAutocompleteContext: React.Context<{
|
|
4
4
|
query: string;
|
|
5
5
|
sections: import("../../types").Section[];
|
|
6
|
+
request: Partial<import("@constructor-io/constructorio-client-javascript/lib/types").AutocompleteRequestType>;
|
|
7
|
+
featureToggles: {
|
|
8
|
+
featureDisplaySearchSuggestionImages: boolean;
|
|
9
|
+
featureDisplaySearchSuggestionResultCounts: boolean;
|
|
10
|
+
};
|
|
6
11
|
isOpen: boolean;
|
|
7
12
|
getMenuProps: () => any;
|
|
8
13
|
getLabelProps: (options?: import("downshift").UseComboboxGetLabelPropsOptions | undefined) => any;
|
package/lib/types/constants.d.ts
CHANGED
|
@@ -30,3 +30,4 @@ export declare const advancedParametersDefaultDescription = "Passing an `advance
|
|
|
30
30
|
export declare const termsWithGroupSuggestionsDescription = "Pass integers for the `numTermsWithGroupSuggestions` and `numGroupsSuggestedPerTerm` fields to add suggested group filters to search term suggestions. Not all suggested search terms will have group filters, so these integers are upper limits, used to specify the maximum number of terms with group filters and the maximum number of suggested group filters per term.\n\nTo see this in action:\n1. Type \"pan\" in the example below.\n - Notice how the user is presented with a search term of \"all week flex pant\" as well as \"all week flex pant in Chinos\" and \"all week flex pant baby in Athleisure Pants & Joggers\"\n2. Navigate to the \"Terms With Group Suggestions\" story (using the navigation menu to the left)\n3. Then use the Controls to adjust the values of `numTermsWithGroupSuggestions` to `3` and `numGroupsSuggestedPerTerm` to `1`\n4. Next, type \"pan\" in the example autocomplete input field.\n - Notice how the user is presented with three different search terms that have a maximum of one \"in {group}\" suggestion each";
|
|
31
31
|
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";
|
|
32
32
|
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.";
|
|
33
|
+
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.";
|
|
@@ -4,6 +4,11 @@ export type UseCioAutocompleteOptions = Omit<CioAutocompleteProps, 'children'>;
|
|
|
4
4
|
declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
|
|
5
5
|
query: string;
|
|
6
6
|
sections: import("../types").Section[];
|
|
7
|
+
request: Partial<import("@constructor-io/constructorio-client-javascript/lib/types").AutocompleteRequestType>;
|
|
8
|
+
featureToggles: {
|
|
9
|
+
featureDisplaySearchSuggestionImages: boolean;
|
|
10
|
+
featureDisplaySearchSuggestionResultCounts: boolean;
|
|
11
|
+
};
|
|
7
12
|
isOpen: boolean;
|
|
8
13
|
getMenuProps: () => any;
|
|
9
14
|
getLabelProps: (options?: import("downshift").UseComboboxGetLabelPropsOptions | undefined) => any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
2
|
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
|
-
import {
|
|
4
|
-
declare const useFetchRecommendationPod: (cioClient: Nullable<ConstructorIOClient>, recommendationPods: RecommendationsSection[]) =>
|
|
3
|
+
import { RecommendationsSection, SectionsData } from '../types';
|
|
4
|
+
declare const useFetchRecommendationPod: (cioClient: Nullable<ConstructorIOClient>, recommendationPods: RecommendationsSection[]) => SectionsData;
|
|
5
5
|
export default useFetchRecommendationPod;
|
|
@@ -5,4 +5,5 @@ export default function useSections(query: string, cioClient: Nullable<Construct
|
|
|
5
5
|
activeSections: UserDefinedSection[];
|
|
6
6
|
activeSectionsWithData: import("../types").Section[];
|
|
7
7
|
zeroStateActiveSections: false | UserDefinedSection[] | undefined;
|
|
8
|
+
request: Partial<import("@constructor-io/constructorio-client-javascript/lib/types").AutocompleteRequestType>;
|
|
8
9
|
};
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GetItemPropsOptions } from 'downshift';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
4
|
-
import { IAutocompleteParameters, SearchSuggestion as SearchSuggestionFromClient, Product as ProductFromClient, Item as ItemBase } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
4
|
+
import { IAutocompleteParameters, SearchSuggestion as SearchSuggestionFromClient, Product as ProductFromClient, Item as ItemBase, AutocompleteRequestType } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
5
5
|
export type { IAutocompleteParameters } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
6
6
|
export type CioClientConfig = {
|
|
7
7
|
apiKey?: string;
|
|
@@ -12,13 +12,14 @@ export interface AdvancedParametersBase {
|
|
|
12
12
|
numGroupsSuggestedPerTerm?: number;
|
|
13
13
|
displaySearchSuggestionImages?: boolean;
|
|
14
14
|
displaySearchSuggestionResultCounts?: boolean;
|
|
15
|
+
debounce?: number;
|
|
15
16
|
}
|
|
16
17
|
export type AdvancedParameters = AdvancedParametersBase & Omit<IAutocompleteParameters, 'resultsPerSection'>;
|
|
17
18
|
export type CioAutocompleteProps = CioClientConfig & {
|
|
18
19
|
openOnFocus?: boolean;
|
|
19
20
|
onSubmit: OnSubmit;
|
|
20
21
|
onFocus?: () => void;
|
|
21
|
-
onChange?: (
|
|
22
|
+
onChange?: (input: string) => void;
|
|
22
23
|
placeholder?: string;
|
|
23
24
|
children?: ReactNode;
|
|
24
25
|
sections?: UserDefinedSection[];
|
|
@@ -46,9 +47,13 @@ export type GetAutocompleteResultsOptions = {
|
|
|
46
47
|
numResults: number;
|
|
47
48
|
};
|
|
48
49
|
};
|
|
50
|
+
export type SectionsData = {
|
|
51
|
+
[key: string]: Item[] | undefined;
|
|
52
|
+
};
|
|
49
53
|
/** CIO API Response Data */
|
|
50
54
|
export type AutocompleteResultSections = {
|
|
51
|
-
|
|
55
|
+
sectionsData: SectionsData;
|
|
56
|
+
request: Partial<AutocompleteRequestType>;
|
|
52
57
|
};
|
|
53
58
|
type SectionType = 'autocomplete' | 'recommendations' | 'custom';
|
|
54
59
|
export type SectionConfiguration = {
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
-
import {
|
|
2
|
+
import { AutocompleteRequestType } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
|
+
import { OnSubmit, Item, Section, UserDefinedSection, SectionsData } from './types';
|
|
3
4
|
export type GetItemPosition = (args: {
|
|
4
5
|
item: Item;
|
|
5
6
|
items: Item[];
|
|
@@ -7,6 +8,10 @@ export type GetItemPosition = (args: {
|
|
|
7
8
|
index: number;
|
|
8
9
|
sectionId: string;
|
|
9
10
|
};
|
|
11
|
+
export declare function getSearchSuggestionFeatures(request: Partial<AutocompleteRequestType>): {
|
|
12
|
+
featureDisplaySearchSuggestionImages: boolean;
|
|
13
|
+
featureDisplaySearchSuggestionResultCounts: boolean;
|
|
14
|
+
};
|
|
10
15
|
export declare const getItemPosition: GetItemPosition;
|
|
11
16
|
type CamelToStartCase = (camelCaseString: string) => string;
|
|
12
17
|
export declare const camelToStartCase: CamelToStartCase;
|
|
@@ -32,6 +37,6 @@ export declare const stringifyWithDefaults: (obj: {
|
|
|
32
37
|
}) => string;
|
|
33
38
|
export declare const disableStoryActions: (story: any) => void;
|
|
34
39
|
export declare const getCioClient: (apiKey?: string) => ConstructorIOClient | null;
|
|
35
|
-
export declare const getActiveSectionsWithData: (activeSections: UserDefinedSection[], sectionResults:
|
|
40
|
+
export declare const getActiveSectionsWithData: (activeSections: UserDefinedSection[], sectionResults: SectionsData) => Section[];
|
|
36
41
|
export declare const escapeRegExp: (string: string) => string;
|
|
37
42
|
export {};
|
package/lib/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "1.
|
|
1
|
+
declare const _default: "1.13.0";
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED