@constructor-io/constructorio-ui-autocomplete 1.8.1 → 1.8.4
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/README.md +3 -0
- package/dist/constructorio-ui-autocomplete-bundled.js +13 -13
- package/lib/cjs/hooks/useCioAutocomplete.js +21 -3
- package/lib/cjs/hooks/useDownShift.js +13 -7
- package/lib/cjs/utils.js +1 -0
- package/lib/mjs/hooks/useCioAutocomplete.js +21 -3
- package/lib/mjs/hooks/useDebouncedFetchSections.js +3 -1
- package/lib/mjs/hooks/useDownShift.js +13 -7
- package/lib/mjs/utils.js +1 -0
- package/lib/types/components/Autocomplete/CioAutocompleteProvider.d.ts +1 -1
- package/lib/types/hooks/useCioAutocomplete.d.ts +1 -1
- package/lib/types/hooks/useCioClient.d.ts +1 -1
- package/lib/types/hooks/useDebouncedFetchSections.d.ts +1 -1
- package/lib/types/hooks/useDownShift.d.ts +1 -1
- package/lib/types/hooks/useFetchRecommendationPod.d.ts +1 -1
- package/lib/types/hooks/useSections.d.ts +1 -1
- package/lib/types/types.d.ts +3 -2
- package/package.json +2 -2
|
@@ -64,7 +64,13 @@ const useCioAutocomplete = (options) => {
|
|
|
64
64
|
if (query === null || query === void 0 ? void 0 : query.length) {
|
|
65
65
|
downshift.openMenu();
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
try {
|
|
68
|
+
(_a = cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker) === null || _a === void 0 ? void 0 : _a.trackInputFocus();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
// eslint-disable-next-line no-console
|
|
72
|
+
console.log(error);
|
|
73
|
+
}
|
|
68
74
|
}, className: 'cio-input', 'data-testid': 'cio-input', placeholder, onKeyDownCapture: ({ code }) => {
|
|
69
75
|
const isEnter = code === 'Enter';
|
|
70
76
|
const isUserInput = highlightedIndex < 0;
|
|
@@ -72,7 +78,13 @@ const useCioAutocomplete = (options) => {
|
|
|
72
78
|
if (onSubmit) {
|
|
73
79
|
onSubmit({ query });
|
|
74
80
|
}
|
|
75
|
-
|
|
81
|
+
try {
|
|
82
|
+
cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(query, { originalQuery: query });
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
console.log(error);
|
|
87
|
+
}
|
|
76
88
|
}
|
|
77
89
|
} })),
|
|
78
90
|
getFormProps: () => ({
|
|
@@ -81,7 +93,13 @@ const useCioAutocomplete = (options) => {
|
|
|
81
93
|
if (onSubmit) {
|
|
82
94
|
onSubmit({ query });
|
|
83
95
|
}
|
|
84
|
-
|
|
96
|
+
try {
|
|
97
|
+
cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(query, { originalQuery: query });
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
// eslint-disable-next-line no-console
|
|
101
|
+
console.log(error);
|
|
102
|
+
}
|
|
85
103
|
return { query };
|
|
86
104
|
},
|
|
87
105
|
className: 'cio-form',
|
|
@@ -13,15 +13,21 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
|
|
|
13
13
|
if (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) {
|
|
14
14
|
if (onSubmit)
|
|
15
15
|
onSubmit({ item: selectedItem, originalQuery: previousQuery });
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
try {
|
|
17
|
+
if (!((_a = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.data) === null || _a === void 0 ? void 0 : _a.url)) {
|
|
18
|
+
cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(selectedItem.value, {
|
|
19
|
+
originalQuery: previousQuery,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackAutocompleteSelect(selectedItem.value, {
|
|
23
|
+
originalQuery: previousQuery,
|
|
24
|
+
section: selectedItem.section,
|
|
19
25
|
});
|
|
20
26
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
29
|
+
console.log(error);
|
|
30
|
+
}
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
},
|
package/lib/cjs/utils.js
CHANGED
|
@@ -70,7 +70,13 @@ const useCioAutocomplete = (options) => {
|
|
|
70
70
|
if (query?.length) {
|
|
71
71
|
downshift.openMenu();
|
|
72
72
|
}
|
|
73
|
-
|
|
73
|
+
try {
|
|
74
|
+
cioClient?.tracker?.trackInputFocus();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
// eslint-disable-next-line no-console
|
|
78
|
+
console.log(error);
|
|
79
|
+
}
|
|
74
80
|
},
|
|
75
81
|
className: 'cio-input',
|
|
76
82
|
'data-testid': 'cio-input',
|
|
@@ -82,7 +88,13 @@ const useCioAutocomplete = (options) => {
|
|
|
82
88
|
if (onSubmit) {
|
|
83
89
|
onSubmit({ query });
|
|
84
90
|
}
|
|
85
|
-
|
|
91
|
+
try {
|
|
92
|
+
cioClient?.tracker.trackSearchSubmit(query, { originalQuery: query });
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
// eslint-disable-next-line no-console
|
|
96
|
+
console.log(error);
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
},
|
|
88
100
|
}),
|
|
@@ -92,7 +104,13 @@ const useCioAutocomplete = (options) => {
|
|
|
92
104
|
if (onSubmit) {
|
|
93
105
|
onSubmit({ query });
|
|
94
106
|
}
|
|
95
|
-
|
|
107
|
+
try {
|
|
108
|
+
cioClient?.tracker.trackSearchSubmit(query, { originalQuery: query });
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
// eslint-disable-next-line no-console
|
|
112
|
+
console.log(error);
|
|
113
|
+
}
|
|
96
114
|
return { query };
|
|
97
115
|
},
|
|
98
116
|
className: 'cio-form',
|
|
@@ -36,7 +36,9 @@ const useDebouncedFetchSection = (query, cioClient, autocompleteSections, advanc
|
|
|
36
36
|
const debouncedSearchTerm = useDebounce(query);
|
|
37
37
|
const { numTermsWithGroupSuggestions = 0, numGroupsSuggestedPerTerm = 0 } = advancedParameters || {};
|
|
38
38
|
const autocompleteParameters = useMemo(() => {
|
|
39
|
-
const decoratedParameters = {
|
|
39
|
+
const decoratedParameters = {
|
|
40
|
+
...advancedParameters,
|
|
41
|
+
};
|
|
40
42
|
if (autocompleteSections) {
|
|
41
43
|
decoratedParameters.resultsPerSection = autocompleteSections.reduce((acc, sectionConfig) => ({
|
|
42
44
|
...acc,
|
|
@@ -10,15 +10,21 @@ const useDownShift = ({ setQuery, items, onSubmit, cioClient, previousQuery = ''
|
|
|
10
10
|
if (selectedItem?.value) {
|
|
11
11
|
if (onSubmit)
|
|
12
12
|
onSubmit({ item: selectedItem, originalQuery: previousQuery });
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
try {
|
|
14
|
+
if (!selectedItem?.data?.url) {
|
|
15
|
+
cioClient?.tracker.trackSearchSubmit(selectedItem.value, {
|
|
16
|
+
originalQuery: previousQuery,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
cioClient?.tracker.trackAutocompleteSelect(selectedItem.value, {
|
|
20
|
+
originalQuery: previousQuery,
|
|
21
|
+
section: selectedItem.section,
|
|
16
22
|
});
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
// eslint-disable-next-line no-console
|
|
26
|
+
console.log(error);
|
|
27
|
+
}
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
},
|
package/lib/mjs/utils.js
CHANGED
|
@@ -18,7 +18,7 @@ export declare const CioAutocompleteContext: React.Context<{
|
|
|
18
18
|
'data-testid': string;
|
|
19
19
|
};
|
|
20
20
|
setQuery: React.Dispatch<React.SetStateAction<string>>;
|
|
21
|
-
cioClient: import("@constructor-io/constructorio-client-javascript/lib/types
|
|
21
|
+
cioClient: import("@constructor-io/constructorio-client-javascript/lib/types").Nullable<import("@constructor-io/constructorio-client-javascript")>;
|
|
22
22
|
autocompleteClassName: string;
|
|
23
23
|
selectedItem: import("../../types").Item;
|
|
24
24
|
}>;
|
|
@@ -19,7 +19,7 @@ declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
|
|
|
19
19
|
'data-testid': string;
|
|
20
20
|
};
|
|
21
21
|
setQuery: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
22
|
-
cioClient: import("@constructor-io/constructorio-client-javascript/lib/types
|
|
22
|
+
cioClient: import("@constructor-io/constructorio-client-javascript/lib/types").Nullable<import("@constructor-io/constructorio-client-javascript")>;
|
|
23
23
|
autocompleteClassName: string;
|
|
24
24
|
selectedItem: import("../types").Item;
|
|
25
25
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
-
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types
|
|
2
|
+
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
3
|
import { CioClientConfig } from '../types';
|
|
4
4
|
type UseCioClient = (cioClientConfig: CioClientConfig) => Nullable<ConstructorIOClient>;
|
|
5
5
|
declare const useCioClient: UseCioClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
-
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types
|
|
2
|
+
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
3
|
import { AutocompleteResultSections, UserDefinedSection, AdvancedParameters } from '../types';
|
|
4
4
|
declare const useDebouncedFetchSection: (query: string, cioClient: Nullable<ConstructorIOClient>, autocompleteSections: UserDefinedSection[], advancedParameters?: AdvancedParameters) => AutocompleteResultSections;
|
|
5
5
|
export default useDebouncedFetchSection;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { UseComboboxReturnValue } from 'downshift';
|
|
3
3
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
4
|
-
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types
|
|
4
|
+
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
5
5
|
import { Item, OnSubmit } from '../types';
|
|
6
6
|
type UseDownShiftOptions = {
|
|
7
7
|
setQuery: React.Dispatch<React.SetStateAction<string>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
2
|
-
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types
|
|
2
|
+
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
3
|
import { AutocompleteResultSections, RecommendationsSection } from '../types';
|
|
4
4
|
declare const useFetchRecommendationPod: (cioClient: Nullable<ConstructorIOClient>, recommendationPods: RecommendationsSection[]) => AutocompleteResultSections;
|
|
5
5
|
export default useFetchRecommendationPod;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ConstructorIO from '@constructor-io/constructorio-client-javascript';
|
|
2
|
-
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types
|
|
2
|
+
import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types';
|
|
3
3
|
import { AdvancedParameters, UserDefinedSection } from '../types';
|
|
4
4
|
export default function useSections(query: string, cioClient: Nullable<ConstructorIO>, sections: UserDefinedSection[], zeroStateSections: UserDefinedSection[] | undefined, advancedParameters?: AdvancedParameters): {
|
|
5
5
|
activeSections: UserDefinedSection[];
|
package/lib/types/types.d.ts
CHANGED
|
@@ -6,10 +6,11 @@ export type CioClientConfig = {
|
|
|
6
6
|
apiKey?: string;
|
|
7
7
|
cioJsClient?: ConstructorIOClient;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export interface AdvancedParametersBase {
|
|
10
10
|
numTermsWithGroupSuggestions?: number;
|
|
11
11
|
numGroupsSuggestedPerTerm?: number;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
|
+
export type AdvancedParameters = AdvancedParametersBase & Omit<IAutocompleteParameters, 'resultsPerSection'>;
|
|
13
14
|
export type CioAutocompleteProps = CioClientConfig & {
|
|
14
15
|
openOnFocus?: boolean;
|
|
15
16
|
onSubmit: OnSubmit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructor-io/constructorio-ui-autocomplete",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.4",
|
|
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",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"webpack": "^5.75.0"
|
|
95
95
|
},
|
|
96
96
|
"peerDependencies": {
|
|
97
|
-
"@constructor-io/constructorio-client-javascript": "^2.
|
|
97
|
+
"@constructor-io/constructorio-client-javascript": "^2.36.0",
|
|
98
98
|
"downshift": "^7.2.1",
|
|
99
99
|
"react": ">=16.12.0",
|
|
100
100
|
"react-dom": ">=16.12.0",
|