@constructor-io/constructorio-ui-autocomplete 1.1.6 → 1.1.8
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 +17 -3
- package/package.json +5 -3
- package/lib/.DS_Store +0 -0
- package/lib/cjs/components/Autocomplete/Autocomplete.css +0 -110
- package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +0 -22
- package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js.map +0 -1
- package/lib/cjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js +0 -18
- package/lib/cjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js.map +0 -1
- package/lib/cjs/components/Autocomplete/CioAutocompleteProvider.js +0 -15
- package/lib/cjs/components/Autocomplete/CioAutocompleteProvider.js.map +0 -1
- package/lib/cjs/components/Autocomplete/SearchInput/SearchInput.js +0 -30
- package/lib/cjs/components/Autocomplete/SearchInput/SearchInput.js.map +0 -1
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +0 -22
- package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js.map +0 -1
- package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +0 -22
- package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js.map +0 -1
- package/lib/cjs/constants.js +0 -163
- package/lib/cjs/constants.js.map +0 -1
- package/lib/cjs/hooks/useCioAutocomplete.js +0 -107
- package/lib/cjs/hooks/useCioAutocomplete.js.map +0 -1
- package/lib/cjs/hooks/useCioClient.js +0 -22
- package/lib/cjs/hooks/useCioClient.js.map +0 -1
- package/lib/cjs/hooks/useDebounce.js +0 -24
- package/lib/cjs/hooks/useDebounce.js.map +0 -1
- package/lib/cjs/hooks/useDebouncedFetchSections.js +0 -35
- package/lib/cjs/hooks/useDebouncedFetchSections.js.map +0 -1
- package/lib/cjs/hooks/useDownShift.js +0 -37
- package/lib/cjs/hooks/useDownShift.js.map +0 -1
- package/lib/cjs/hooks/useFetchRecommendationPod.js +0 -30
- package/lib/cjs/hooks/useFetchRecommendationPod.js.map +0 -1
- package/lib/cjs/hooks/usePrevious.js +0 -12
- package/lib/cjs/hooks/usePrevious.js.map +0 -1
- package/lib/cjs/index.js +0 -16
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/stories/Autocomplete/argTypes.js +0 -65
- package/lib/cjs/stories/Autocomplete/argTypes.js.map +0 -1
- package/lib/cjs/typeGuards.js +0 -10
- package/lib/cjs/typeGuards.js.map +0 -1
- package/lib/cjs/types.js +0 -3
- package/lib/cjs/types.js.map +0 -1
- package/lib/cjs/utils.js +0 -72
- package/lib/cjs/utils.js.map +0 -1
- package/lib/mjs/components/Autocomplete/Autocomplete.css +0 -110
- package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +0 -21
- package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js.map +0 -1
- package/lib/mjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js +0 -15
- package/lib/mjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js.map +0 -1
- package/lib/mjs/components/Autocomplete/CioAutocompleteProvider.js +0 -10
- package/lib/mjs/components/Autocomplete/CioAutocompleteProvider.js.map +0 -1
- package/lib/mjs/components/Autocomplete/SearchInput/SearchInput.js +0 -27
- package/lib/mjs/components/Autocomplete/SearchInput/SearchInput.js.map +0 -1
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +0 -18
- package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js.map +0 -1
- package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +0 -15
- package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js.map +0 -1
- package/lib/mjs/constants.js +0 -160
- package/lib/mjs/constants.js.map +0 -1
- package/lib/mjs/hooks/useCioAutocomplete.js +0 -118
- package/lib/mjs/hooks/useCioAutocomplete.js.map +0 -1
- package/lib/mjs/hooks/useCioClient.js +0 -20
- package/lib/mjs/hooks/useCioClient.js.map +0 -1
- package/lib/mjs/hooks/useDebounce.js +0 -22
- package/lib/mjs/hooks/useDebounce.js.map +0 -1
- package/lib/mjs/hooks/useDebouncedFetchSections.js +0 -41
- package/lib/mjs/hooks/useDebouncedFetchSections.js.map +0 -1
- package/lib/mjs/hooks/useDownShift.js +0 -33
- package/lib/mjs/hooks/useDownShift.js.map +0 -1
- package/lib/mjs/hooks/useFetchRecommendationPod.js +0 -27
- package/lib/mjs/hooks/useFetchRecommendationPod.js.map +0 -1
- package/lib/mjs/hooks/usePrevious.js +0 -10
- package/lib/mjs/hooks/usePrevious.js.map +0 -1
- package/lib/mjs/index.js +0 -7
- package/lib/mjs/index.js.map +0 -1
- package/lib/mjs/stories/Autocomplete/argTypes.js +0 -62
- package/lib/mjs/stories/Autocomplete/argTypes.js.map +0 -1
- package/lib/mjs/typeGuards.js +0 -6
- package/lib/mjs/typeGuards.js.map +0 -1
- package/lib/mjs/types.js +0 -2
- package/lib/mjs/types.js.map +0 -1
- package/lib/mjs/utils.js +0 -58
- package/lib/mjs/utils.js.map +0 -1
- package/lib/types/components/Autocomplete/AutocompleteResults/AutocompleteResults.d.ts +0 -11
- package/lib/types/components/Autocomplete/CioAutocomplete/CioAutocomplete.d.ts +0 -3
- package/lib/types/components/Autocomplete/CioAutocompleteProvider.d.ts +0 -28
- package/lib/types/components/Autocomplete/SearchInput/SearchInput.d.ts +0 -7
- package/lib/types/components/Autocomplete/SectionItem/SectionItem.d.ts +0 -10
- package/lib/types/components/Autocomplete/SectionItemsList/SectionItemsList.d.ts +0 -12
- package/lib/types/constants.d.ts +0 -23
- package/lib/types/hooks/useCioAutocomplete.d.ts +0 -29
- package/lib/types/hooks/useCioClient.d.ts +0 -15
- package/lib/types/hooks/useDebounce.d.ts +0 -2
- package/lib/types/hooks/useDebouncedFetchSections.d.ts +0 -4
- package/lib/types/hooks/useDownShift.d.ts +0 -16
- package/lib/types/hooks/useFetchRecommendationPod.d.ts +0 -4
- package/lib/types/hooks/usePrevious.d.ts +0 -2
- package/lib/types/index.d.ts +0 -6
- package/lib/types/stories/Autocomplete/argTypes.d.ts +0 -62
- package/lib/types/typeGuards.d.ts +0 -2
- package/lib/types/types.d.ts +0 -131
- package/lib/types/utils.d.ts +0 -24
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import SectionItem from '../SectionItem/SectionItem';
|
|
3
|
-
import { camelToStartCase } from '../../../utils';
|
|
4
|
-
// eslint-disable-next-line func-names
|
|
5
|
-
const DefaultRenderSectionItemsList = function ({ section }) {
|
|
6
|
-
const sectionName = section?.displayName || section?.identifier;
|
|
7
|
-
return (React.createElement("li", { className: `${sectionName} cio-section`, role: 'none' },
|
|
8
|
-
React.createElement("h5", { className: 'cio-sectionName', "aria-hidden": true }, camelToStartCase(sectionName)),
|
|
9
|
-
React.createElement("ul", { className: 'cio-section-items', role: 'none' }, section?.data?.map((item, index) => (React.createElement(SectionItem, { item: item, index: index, sectionIdentifier: section?.identifier, key: `${section?.identifier}_${item?.data?.id}` }))))));
|
|
10
|
-
};
|
|
11
|
-
export default function SectionItemsList(props) {
|
|
12
|
-
const { section, children = DefaultRenderSectionItemsList } = props;
|
|
13
|
-
return children({ section });
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=SectionItemsList.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SectionItemsList.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/SectionItemsList/SectionItemsList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuB,MAAM,OAAO,CAAC;AAE5C,OAAO,WAAW,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAYlD,sCAAsC;AACtC,MAAM,6BAA6B,GAA2B,UAAU,EAAE,OAAO,EAAE;IACjF,MAAM,WAAW,GAAG,OAAO,EAAE,WAAW,IAAI,OAAO,EAAE,UAAU,CAAC;IAEhE,OAAO,CACL,4BAAI,SAAS,EAAE,GAAG,WAAW,cAAc,EAAE,IAAI,EAAC,MAAM;QACtD,4BAAI,SAAS,EAAC,iBAAiB,yBAC5B,gBAAgB,CAAC,WAAW,CAAC,CAC3B;QACL,4BAAI,SAAS,EAAC,mBAAmB,EAAC,IAAI,EAAC,MAAM,IAC1C,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CACnC,oBAAC,WAAW,IACV,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAE,OAAO,EAAE,UAAU,EACtC,GAAG,EAAE,GAAG,OAAO,EAAE,UAAU,IAAI,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,GAC/C,CACH,CAAC,CACC,CACF,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,KAA4B;IACnE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,6BAA6B,EAAE,GAAG,KAAK,CAAC;IAEpE,OAAO,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/B,CAAC"}
|
package/lib/mjs/constants.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
// Autocomplete key index
|
|
2
|
-
export const apiKey = 'key_Gep3oQOu5IMcNh9A';
|
|
3
|
-
/// //////////////////////////////
|
|
4
|
-
// Storybook Folder Descriptions
|
|
5
|
-
/// //////////////////////////////
|
|
6
|
-
export const componentDescription = `- import \`CioAutocomplete\` to render in your JSX.
|
|
7
|
-
- This component handles state management, data fetching, and rendering logic.
|
|
8
|
-
- To use this component, an \`apiKey\` or \`cioJsClient\` are required, all other values are optional.
|
|
9
|
-
- Use different props to configure the behavior of this component.
|
|
10
|
-
- The following stories shows how different props affect the component's behavior
|
|
11
|
-
|
|
12
|
-
> 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)
|
|
13
|
-
`;
|
|
14
|
-
export const hookDescription = `- import \`useCioAutocomplete\` and call this custom hook in a functional component.
|
|
15
|
-
- This hook handles state management & data fetching, but leaves rendering logic up to you
|
|
16
|
-
- To use this hook, an \`apiKey\` or \`cioJsClient\` are required, all other values are optional.
|
|
17
|
-
- Pass different options to the \`useCioAutocomplete\` hook to configure behavior.
|
|
18
|
-
- The following stories shows how different options affect the hook's behavior
|
|
19
|
-
|
|
20
|
-
Calling the \`useCioAutocomplete\` hook returns an object with the following keys:
|
|
21
|
-
|
|
22
|
-
\`\`\`jsx
|
|
23
|
-
const {
|
|
24
|
-
// must be used for a hooks integrations
|
|
25
|
-
query: string, // current input field value
|
|
26
|
-
sections: [{...}], // array of sections data to render in menu list,
|
|
27
|
-
getFormProps: () => ({...})), // prop getter for jsx form element
|
|
28
|
-
getLabelProps: () => ({...})), // optional: prop getter for jsx label element
|
|
29
|
-
getInputProps: () => ({...})), // prop getter for jsx input element
|
|
30
|
-
getMenuProps: () => ({...})), // prop getter for jsx element serving as menu container
|
|
31
|
-
getItemProps: () => ({...})), // prop getter for jsx element serving as each result
|
|
32
|
-
isOpen: boolean,
|
|
33
|
-
|
|
34
|
-
// available for advanced hooks integration use cases
|
|
35
|
-
openMenu: () => void, // open menu
|
|
36
|
-
closeMenu: () => void, // close menu
|
|
37
|
-
setQuery: () => void, // update the current input field value
|
|
38
|
-
cioJsClient, // instance of constructorio-client-javascript
|
|
39
|
-
} = useCioAutocomplete(args);
|
|
40
|
-
\`\`\`
|
|
41
|
-
|
|
42
|
-
> 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)
|
|
43
|
-
`;
|
|
44
|
-
/// //////////////////////////////
|
|
45
|
-
// Storybook Pages
|
|
46
|
-
/// //////////////////////////////
|
|
47
|
-
export const sectionsDescription = `- by default, typing a query will fetch data for search suggestions and Products
|
|
48
|
-
- to override this, pass a an array of sections objects
|
|
49
|
-
- the order of the objects in the \`sections\` array determines the order of the results
|
|
50
|
-
- each section object must have an \`identifier\`
|
|
51
|
-
- each section object can specify a \`type\`
|
|
52
|
-
- each section object can override the default \`numResults\` of 8
|
|
53
|
-
|
|
54
|
-
When no values are passed for the \`sections\` argument, the following defaults are used:
|
|
55
|
-
|
|
56
|
-
\`\`\`jsx
|
|
57
|
-
[
|
|
58
|
-
{
|
|
59
|
-
identifier: 'Search Suggestions',
|
|
60
|
-
type: 'autocomplete',
|
|
61
|
-
numResults: 8
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
identifier: 'Products',
|
|
65
|
-
type: 'autocomplete',
|
|
66
|
-
numResults: 8
|
|
67
|
-
}
|
|
68
|
-
]
|
|
69
|
-
\`\`\`
|
|
70
|
-
`;
|
|
71
|
-
export const userEventsDescription = `- pass callback functions to respond to user events
|
|
72
|
-
- if provided, the onFocus callback function will be called each time the user focuses on the text input field
|
|
73
|
-
- if provided, the onChange callback function will be called each time the user changes the value in the text input field
|
|
74
|
-
- if provided, the onSubmit callback function will be called each time the user submits the form
|
|
75
|
-
- 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
|
|
76
|
-
|
|
77
|
-
> ⚠️ NOTE ⚠️ 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.`;
|
|
78
|
-
export const zeroStateDescription = `- when the text input field has no text, we call this zero state
|
|
79
|
-
- by default, the autocomplete shows nothing in the menu it's for zero state
|
|
80
|
-
- to show zero state results, pass an array of section objects for \`zeroStateSections\`
|
|
81
|
-
- when \`zeroStateSections\` has sections, the menu will open on user focus by default
|
|
82
|
-
- 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
|
|
83
|
-
- the order of the objects in the \`zeroStateSections\` array determines the order of the results
|
|
84
|
-
- each section object must have an \`identifier\`
|
|
85
|
-
- each section object can specify a \`type\`
|
|
86
|
-
- each section object can override the default \`numResults\` of 8`;
|
|
87
|
-
/// //////////////////////////////
|
|
88
|
-
// Storybook Stories
|
|
89
|
-
/// //////////////////////////////
|
|
90
|
-
export const apiKeyDescription = `Pass an \`apiKey\` to request results from constructor's servers`;
|
|
91
|
-
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
|
|
92
|
-
|
|
93
|
-
> 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)`;
|
|
94
|
-
export const placeholderDescription = `Pass a \`placeholder\` to override the default input field placeholder text shown to users before they start typing their query`;
|
|
95
|
-
export const searchSuggestionsDescription = `Override default \`sections\` to only suggest search terms`;
|
|
96
|
-
export const productsDescription = `Override default \`sections\` to only suggested products`;
|
|
97
|
-
export const contentDescription = `Override default \`sections\` to only suggest content`;
|
|
98
|
-
export const numResultsDescription = `Override default \`numResults\` to only suggest 2 products per query`;
|
|
99
|
-
export const sectionOrderDescription = `Override default \`numResults\` to suggest products, then terms`;
|
|
100
|
-
export const recommendationsDescription = `Use constructor's recommendations service, with \`"type": "recommendations"\``;
|
|
101
|
-
export const customSectionDescription = `Use a custom section, by managing and passing your own data, with \`"type": "custom"\` and \`"data":[{...}]\``;
|
|
102
|
-
export const onFocusDescription = `Pass an \`onFocus\` callback function to execute some code each time the user applies focus to the text input field`;
|
|
103
|
-
export const onChangeDescription = `Pass an \`onChange\` callback function to execute some code each time the user changes the value of the text input field`;
|
|
104
|
-
export const onSubmitDescription = `Pass an \`onSubmit\` callback function to execute some code after a user submits the search form.
|
|
105
|
-
|
|
106
|
-
Your callback function will be invoked with a submit event containing useful metadata about the submit event:
|
|
107
|
-
- if the user submits the text input:
|
|
108
|
-
- the \`query\` field will provide the value of that input field
|
|
109
|
-
- if the user selects a suggested item from the dropdown list:
|
|
110
|
-
- the \`originalQuery\` field will provide the value of the input field that generated the selected item
|
|
111
|
-
- an \`item\` object with information about the suggestion that the user selected`;
|
|
112
|
-
export const zeroStateSectionsDescription = `Use \`zeroStateSections\` to show suggestions after a user applies focus to the search input field and before they start typing a query`;
|
|
113
|
-
export const openOnFocusDescription = `Use \`openOnFocus: false\` to show suggestions after a user clears their query, but not when they initially apply focus to the search input field`;
|
|
114
|
-
export const multipleSectionsDescription = `Use as many different \`recommendations\` and \`custom\` sections as you'd like and in whatever order you would like!`;
|
|
115
|
-
// from .storybook/custom-styles-story.css
|
|
116
|
-
export const customStylesDescription = `
|
|
117
|
-
This library provides some default styles. These default styles can be used as a foundation to build on top of or just as a reference for you to replace completely. All default styles in this library are scoped within the \`.cio-autocomplete\` css selector.
|
|
118
|
-
|
|
119
|
-
- If you would like to remove all default styling, simply pass an empty string or your own custom autocomplete container className as the value for the \`autocompleteClassName\` prop
|
|
120
|
-
- If you would like to layer your own custom styles on top of the library default styles, you can do so by passing additional className(s) of your choosing \`autocompleteClassName='cio-autocomplete custom-autocomplete-container'\`
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
\`\`\`css
|
|
124
|
-
.cio-autocomplete.custom-autocomplete-styles form {
|
|
125
|
-
height: 44px;
|
|
126
|
-
width: 600px;
|
|
127
|
-
border-radius: 8px;
|
|
128
|
-
background-color: rgb(247, 247, 247);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.cio-autocomplete.custom-autocomplete-styles .cio-input {
|
|
132
|
-
font-weight: bold;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
.cio-autocomplete.custom-autocomplete-styles .cio-form button {
|
|
136
|
-
width: 44px;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
.cio-autocomplete.custom-autocomplete-styles .cio-clear-btn {
|
|
140
|
-
right: 24px;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
.cio-autocomplete.custom-autocomplete-styles .cio-sectionName {
|
|
144
|
-
margin: 5px 3px;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
.cio-autocomplete.custom-autocomplete-styles .cio-results {
|
|
148
|
-
width: 620px;
|
|
149
|
-
max-height: 334px;
|
|
150
|
-
overflow: hidden;
|
|
151
|
-
border-radius: 0px 0px 8px 8px;
|
|
152
|
-
color: rgb(51, 51, 51);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
.cio-autocomplete.custom-autocomplete-styles .Products p {
|
|
156
|
-
padding: 5px 5px 0;
|
|
157
|
-
}
|
|
158
|
-
\`\`\`
|
|
159
|
-
`;
|
|
160
|
-
//# sourceMappingURL=constants.js.map
|
package/lib/mjs/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,MAAM,CAAC,MAAM,MAAM,GAAG,sBAAsB,CAAC;AAE7C,kCAAkC;AAClC,gCAAgC;AAChC,kCAAkC;AAElC,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;CAOnC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B9B,CAAC;AAEF,kCAAkC;AAClC,kBAAkB;AAClB,kCAAkC;AAElC,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBlC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;+bAM0Z,CAAC;AAEhc,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;mEAQ+B,CAAC;AAEpE,kCAAkC;AAClC,oBAAoB;AACpB,kCAAkC;AAElC,MAAM,CAAC,MAAM,iBAAiB,GAAG,kEAAkE,CAAC;AACpG,MAAM,CAAC,MAAM,sBAAsB,GAAG;;6LAEuJ,CAAC;AAC9L,MAAM,CAAC,MAAM,sBAAsB,GAAG,iIAAiI,CAAC;AACxK,MAAM,CAAC,MAAM,4BAA4B,GAAG,4DAA4D,CAAC;AACzG,MAAM,CAAC,MAAM,mBAAmB,GAAG,0DAA0D,CAAC;AAC9F,MAAM,CAAC,MAAM,kBAAkB,GAAG,uDAAuD,CAAC;AAC1F,MAAM,CAAC,MAAM,qBAAqB,GAAG,sEAAsE,CAAC;AAC5G,MAAM,CAAC,MAAM,uBAAuB,GAAG,iEAAiE,CAAC;AACzG,MAAM,CAAC,MAAM,0BAA0B,GAAG,+EAA+E,CAAC;AAC1H,MAAM,CAAC,MAAM,wBAAwB,GAAG,+GAA+G,CAAC;AACxJ,MAAM,CAAC,MAAM,kBAAkB,GAAG,qHAAqH,CAAC;AACxJ,MAAM,CAAC,MAAM,mBAAmB,GAAG,0HAA0H,CAAC;AAC9J,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;sFAOmD,CAAC;AACvF,MAAM,CAAC,MAAM,4BAA4B,GAAG,yIAAyI,CAAC;AACtL,MAAM,CAAC,MAAM,sBAAsB,GAAG,mJAAmJ,CAAC;AAC1L,MAAM,CAAC,MAAM,2BAA2B,GAAG,uHAAuH,CAAC;AAEnK,0CAA0C;AAC1C,MAAM,CAAC,MAAM,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CtC,CAAC"}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import useCioClient from './useCioClient';
|
|
3
|
-
import useDownShift from './useDownShift';
|
|
4
|
-
import useDebouncedFetchSection from './useDebouncedFetchSections';
|
|
5
|
-
import useFetchRecommendationPod from './useFetchRecommendationPod';
|
|
6
|
-
import usePrevious from './usePrevious';
|
|
7
|
-
import { getIndexOffset } from '../utils';
|
|
8
|
-
export const defaultSections = [
|
|
9
|
-
{
|
|
10
|
-
identifier: 'Search Suggestions',
|
|
11
|
-
type: 'autocomplete'
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
identifier: 'Products',
|
|
15
|
-
type: 'autocomplete'
|
|
16
|
-
}
|
|
17
|
-
];
|
|
18
|
-
const useCioAutocomplete = (options) => {
|
|
19
|
-
const defaultPlaceholder = 'What can we help you find today?';
|
|
20
|
-
const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = defaultPlaceholder, sections = defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete' } = options;
|
|
21
|
-
const [query, setQuery] = useState('');
|
|
22
|
-
const previousQuery = usePrevious(query);
|
|
23
|
-
const cioClient = useCioClient({ apiKey, cioJsClient });
|
|
24
|
-
const zeroStateSectionsActive = !query.length && zeroStateSections;
|
|
25
|
-
let activeSections = zeroStateSectionsActive ? zeroStateSections : sections;
|
|
26
|
-
if (sections && !Array.isArray(sections)) {
|
|
27
|
-
// eslint-disable-next-line
|
|
28
|
-
console.error('useCioAutocomplete expects sections to reference an array of section configuration objects');
|
|
29
|
-
activeSections = [];
|
|
30
|
-
}
|
|
31
|
-
if (zeroStateSections && !Array.isArray(zeroStateSections)) {
|
|
32
|
-
// eslint-disable-next-line
|
|
33
|
-
console.error('useCioAutocomplete expects zeroStateSections to reference an array of section configuration objects');
|
|
34
|
-
activeSections = [];
|
|
35
|
-
}
|
|
36
|
-
const autocompleteSections = activeSections?.filter((config) => config.type === 'autocomplete' || !config.type);
|
|
37
|
-
const recommendationsSections = activeSections?.filter((config) => config.type === 'recommendations');
|
|
38
|
-
const autocompleteResults = useDebouncedFetchSection(query, cioClient, autocompleteSections);
|
|
39
|
-
const recommendationsResults = useFetchRecommendationPod(cioClient, recommendationsSections);
|
|
40
|
-
const sectionResults = { ...autocompleteResults, ...recommendationsResults };
|
|
41
|
-
const activeSectionsWithData = [];
|
|
42
|
-
activeSections?.forEach((config) => {
|
|
43
|
-
const { identifier, data: customData } = config;
|
|
44
|
-
const data = sectionResults[identifier] || customData;
|
|
45
|
-
if (data && data !== undefined) {
|
|
46
|
-
activeSectionsWithData.push({ ...config, data });
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
const items = [];
|
|
50
|
-
activeSectionsWithData?.forEach((config) => {
|
|
51
|
-
if (config?.data) {
|
|
52
|
-
items.push(...config.data);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
const downshift = useDownShift({ setQuery, onChange, items, onSubmit, cioClient, previousQuery });
|
|
56
|
-
const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu } = downshift;
|
|
57
|
-
return {
|
|
58
|
-
query,
|
|
59
|
-
sections: activeSectionsWithData,
|
|
60
|
-
isOpen: isOpen && items?.length > 0,
|
|
61
|
-
getMenuProps: () => ({
|
|
62
|
-
...getMenuProps(),
|
|
63
|
-
className: 'cio-results',
|
|
64
|
-
'data-testid': 'cio-results'
|
|
65
|
-
}),
|
|
66
|
-
getLabelProps,
|
|
67
|
-
openMenu,
|
|
68
|
-
closeMenu,
|
|
69
|
-
getItemProps: ({ item, index = 0, sectionIdentifier = 'Products' }) => {
|
|
70
|
-
const indexOffset = getIndexOffset({
|
|
71
|
-
activeSections: activeSectionsWithData,
|
|
72
|
-
sectionIdentifier
|
|
73
|
-
});
|
|
74
|
-
const sectionItemTestId = `cio-item-${sectionIdentifier.replace(' ', '')}`;
|
|
75
|
-
return {
|
|
76
|
-
...downshift.getItemProps({ item, index: index + indexOffset }),
|
|
77
|
-
className: `cio-item ${sectionItemTestId}`,
|
|
78
|
-
'data-testid': sectionItemTestId
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
getInputProps: () => ({
|
|
82
|
-
...downshift.getInputProps(),
|
|
83
|
-
value: query,
|
|
84
|
-
onFocus: () => {
|
|
85
|
-
if (options.onFocus) {
|
|
86
|
-
options.onFocus();
|
|
87
|
-
}
|
|
88
|
-
if (zeroStateSectionsActive && openOnFocus !== false) {
|
|
89
|
-
downshift.openMenu();
|
|
90
|
-
}
|
|
91
|
-
if (query?.length) {
|
|
92
|
-
downshift.openMenu();
|
|
93
|
-
}
|
|
94
|
-
cioClient?.tracker?.trackInputFocus();
|
|
95
|
-
},
|
|
96
|
-
className: 'cio-input',
|
|
97
|
-
'data-testid': 'cio-input',
|
|
98
|
-
placeholder
|
|
99
|
-
}),
|
|
100
|
-
getFormProps: () => ({
|
|
101
|
-
onSubmit: (event) => {
|
|
102
|
-
event.preventDefault();
|
|
103
|
-
if (onSubmit) {
|
|
104
|
-
onSubmit({ query });
|
|
105
|
-
}
|
|
106
|
-
cioClient?.tracker.trackSearchSubmit(query, { original_query: query });
|
|
107
|
-
return { query };
|
|
108
|
-
},
|
|
109
|
-
className: 'cio-form',
|
|
110
|
-
'data-testid': 'cio-form'
|
|
111
|
-
}),
|
|
112
|
-
setQuery,
|
|
113
|
-
cioClient,
|
|
114
|
-
autocompleteClassName
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
export default useCioAutocomplete;
|
|
118
|
-
//# sourceMappingURL=useCioAutocomplete.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCioAutocomplete.js","sourceRoot":"","sources":["../../../src/hooks/useCioAutocomplete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,YAAiC,MAAM,gBAAgB,CAAC;AAC/D,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,wBAAwB,MAAM,6BAA6B,CAAC;AAOnE,OAAO,yBAAyB,MAAM,6BAA6B,CAAC;AACpE,OAAO,WAAW,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,CAAC,MAAM,eAAe,GAA2B;IACrD;QACE,UAAU,EAAE,oBAAoB;QAChC,IAAI,EAAE,cAAc;KACrB;IACD;QACE,UAAU,EAAE,UAAU;QACtB,IAAI,EAAE,cAAc;KACrB;CACF,CAAC;AAIF,MAAM,k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CAAC,CAAC;YACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;gBAClB,KAAK,CAAC,cAAc,EAAE,CAAC;gBACvB,IAAI,QAAQ,EAAE;oBACZ,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;iBACrB;gBACD,SAAS,EAAE,OAAO,CAAC,iBAAiB,CAAC,KAAK,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;gBACvE,OAAO,EAAE,KAAK,EAAE,CAAC;YACnB,CAAC;YACD,SAAS,EAAE,UAAU;YACrB,aAAa,EAAE,UAAU;SAC1B,CAAC;QACF,QAAQ;QACR,SAAS;QACT,qBAAqB;KACtB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
|
|
3
|
-
const useCioClient = ({ apiKey, cioJsClient }) => {
|
|
4
|
-
const [cioClient, setCioClient] = useState(cioJsClient);
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
if (apiKey && !cioJsClient) {
|
|
7
|
-
const client = new ConstructorIOClient({
|
|
8
|
-
apiKey,
|
|
9
|
-
sendTrackingEvents: true
|
|
10
|
-
});
|
|
11
|
-
setCioClient(client);
|
|
12
|
-
}
|
|
13
|
-
else if (cioJsClient) {
|
|
14
|
-
setCioClient(cioJsClient);
|
|
15
|
-
}
|
|
16
|
-
}, [apiKey, cioJsClient]);
|
|
17
|
-
return cioClient;
|
|
18
|
-
};
|
|
19
|
-
export default useCioClient;
|
|
20
|
-
//# sourceMappingURL=useCioClient.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useCioClient.js","sourceRoot":"","sources":["../../../src/hooks/useCioClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,mBAAmB,MAAM,iDAAiD,CAAC;AAuBlF,MAAM,YAAY,GAAiB,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE;IAC7D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;IAExD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,MAAM,IAAI,CAAC,WAAW,EAAE;YAC1B,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC;gBACrC,MAAM;gBACN,kBAAkB,EAAE,IAAI;aACzB,CAAC,CAAC;YAEH,YAAY,CAAC,MAAM,CAAC,CAAC;SACtB;aAAM,IAAI,WAAW,EAAE;YACtB,YAAY,CAAC,WAAW,CAAC,CAAC;SAC3B;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAE1B,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
// adapted from: https://usehooks.com/useDebounce/
|
|
3
|
-
const useDebounce = (value, delay = 250) => {
|
|
4
|
-
// State and setters for debounced value
|
|
5
|
-
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
// Update debounced value after delay
|
|
8
|
-
const handler = setTimeout(() => {
|
|
9
|
-
setDebouncedValue(value);
|
|
10
|
-
}, delay);
|
|
11
|
-
// Cancel the timeout if value changes (also on delay change or unmount)
|
|
12
|
-
// This is how we prevent debounced value from updating if value is changed ...
|
|
13
|
-
// .. within the delay period. Timeout gets cleared and restarted.
|
|
14
|
-
return () => {
|
|
15
|
-
clearTimeout(handler);
|
|
16
|
-
};
|
|
17
|
-
}, [value, delay] // Only re-call effect if value or delay changes
|
|
18
|
-
);
|
|
19
|
-
return debouncedValue;
|
|
20
|
-
};
|
|
21
|
-
export default useDebounce;
|
|
22
|
-
//# sourceMappingURL=useDebounce.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../../../src/hooks/useDebounce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,kDAAkD;AAClD,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,KAAK,GAAG,GAAG,EAAE,EAAE;IACjD,wCAAwC;IACxC,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5D,SAAS,CACP,GAAG,EAAE;QACH,qCAAqC;QACrC,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9B,iBAAiB,CAAC,KAAK,CAAC,CAAC;QAC3B,CAAC,EAAE,KAAK,CAAC,CAAC;QACV,wEAAwE;QACxE,+EAA+E;QAC/E,kEAAkE;QAClE,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EACD,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,gDAAgD;KAChE,CAAC;IACF,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import useDebounce from './useDebounce';
|
|
3
|
-
const autocompleteParameters = {
|
|
4
|
-
resultsPerSection: {}
|
|
5
|
-
// numResults: 8,
|
|
6
|
-
// hiddenFields: [],
|
|
7
|
-
// filters: {},
|
|
8
|
-
// variationsMap: {}
|
|
9
|
-
};
|
|
10
|
-
const useDebouncedFetchSection = (query, cioClient, autocompleteSections) => {
|
|
11
|
-
const [sectionsData, setSectionsData] = useState({});
|
|
12
|
-
const debouncedSearchTerm = useDebounce(query);
|
|
13
|
-
if (autocompleteSections) {
|
|
14
|
-
autocompleteParameters.resultsPerSection = autocompleteSections.reduce((acc, sectionConfig) => ({
|
|
15
|
-
...acc,
|
|
16
|
-
[sectionConfig.identifier]: sectionConfig?.numResults || 8
|
|
17
|
-
}), {});
|
|
18
|
-
}
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
if (debouncedSearchTerm) {
|
|
21
|
-
cioClient?.autocomplete
|
|
22
|
-
.getAutocompleteResults(debouncedSearchTerm, autocompleteParameters)
|
|
23
|
-
.then((response) => {
|
|
24
|
-
const newSectionsData = {};
|
|
25
|
-
Object.keys(response.sections).forEach((section) => {
|
|
26
|
-
newSectionsData[section] = response.sections[section].map((item) => ({
|
|
27
|
-
...item,
|
|
28
|
-
section
|
|
29
|
-
}));
|
|
30
|
-
});
|
|
31
|
-
setSectionsData(newSectionsData);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
else if (!debouncedSearchTerm) {
|
|
35
|
-
setSectionsData({});
|
|
36
|
-
}
|
|
37
|
-
}, [debouncedSearchTerm, cioClient]);
|
|
38
|
-
return sectionsData;
|
|
39
|
-
};
|
|
40
|
-
export default useDebouncedFetchSection;
|
|
41
|
-
//# sourceMappingURL=useDebouncedFetchSections.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDebouncedFetchSections.js","sourceRoot":"","sources":["../../../src/hooks/useDebouncedFetchSections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,WAAW,MAAM,eAAe,CAAC;AAaxC,MAAM,sBAAsB,GAAG;IAC7B,iBAAiB,EAAE,EAAE;IACrB,iBAAiB;IACjB,oBAAoB;IACpB,eAAe;IACf,oBAAoB;CACM,CAAC;AAE7B,MAAM,wBAAwB,GAAG,CAC/B,KAAa,EACb,SAA+B,EAC/B,oBAA6C,EAC7C,EAAE;IACF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAA6B,EAAE,CAAC,CAAC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onSubmit, cioClient, previousQuery = '', onChange }) => useCombobox({
|
|
4
|
-
id: `cio-autocomplete-${idCounter++}`,
|
|
5
|
-
items,
|
|
6
|
-
itemToString: (item) => item?.value || '',
|
|
7
|
-
onInputValueChange: async ({ inputValue = '' }) => {
|
|
8
|
-
setQuery(inputValue);
|
|
9
|
-
if (onChange) {
|
|
10
|
-
onChange(inputValue);
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
onSelectedItemChange({ selectedItem }) {
|
|
14
|
-
if (selectedItem) {
|
|
15
|
-
setQuery(selectedItem.value || '');
|
|
16
|
-
if (selectedItem?.value) {
|
|
17
|
-
if (onSubmit)
|
|
18
|
-
onSubmit({ item: selectedItem, originalQuery: previousQuery });
|
|
19
|
-
if (!selectedItem?.data?.url) {
|
|
20
|
-
cioClient?.tracker.trackSearchSubmit(selectedItem.value, {
|
|
21
|
-
original_query: previousQuery
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
cioClient?.tracker.trackAutocompleteSelect(selectedItem.value, {
|
|
25
|
-
original_query: previousQuery,
|
|
26
|
-
section: selectedItem.section
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
export default useDownShift;
|
|
33
|
-
//# sourceMappingURL=useDownShift.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDownShift.js","sourceRoot":"","sources":["../../../src/hooks/useDownShift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAA0B,MAAM,WAAW,CAAC;AAIhE,IAAI,SAAS,GAAG,CAAC,CAAC;AAelB,MAAM,YAAY,GAAiB,CAAC,EAClC,QAAQ,EACR,KAAK,EACL,QAAQ,EACR,SAAS,EACT,aAAa,GAAG,EAAE,EAClB,QAAQ,EACT,EAAE,EAAE,CACH,WAAW,CAAC;IACV,EAAE,EAAE,oBAAoB,SAAS,EAAE,EAAE;IACrC,KAAK;IACL,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE;IACzC,kBAAkB,EAAE,KAAK,EAAE,EAAE,UAAU,GAAG,EAAE,EAAE,EAAE,EAAE;QAChD,QAAQ,CAAC,UAAU,CAAC,CAAC;QACrB,IAAI,QAAQ,EAAE;YACZ,QAAQ,CAAC,UAAU,CAAC,CAAC;SACtB;IACH,CAAC;IACD,oBAAoB,CAAC,EAAE,YAAY,EAAE;QACnC,IAAI,YAAY,EAAE;YAChB,QAAQ,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;YACnC,IAAI,YAAY,EAAE,KAAK,EAAE;gBACvB,IAAI,QAAQ;oBAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC,CAAC;gBAC7E,IAAI,CAAC,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE;oBAC5B,SAAS,EAAE,OAAO,CAAC,iBAAiB,CAAC,YAAY,CAAC,KAAK,EAAE;wBACvD,cAAc,EAAE,aAAa;qBAC9B,CAAC,CAAC;iBACJ;gBACD,SAAS,EAAE,OAAO,CAAC,uBAAuB,CAAC,YAAY,CAAC,KAAK,EAAE;oBAC7D,cAAc,EAAE,aAAa;oBAC7B,OAAO,EAAE,YAAY,CAAC,OAAO;iBAC9B,CAAC,CAAC;aACJ;SACF;IACH,CAAC;CACF,CAAC,CAAC;AAEL,eAAe,YAAY,CAAC"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
const useFetchRecommendationPod = (cioClient, recommendationPods) => {
|
|
3
|
-
const [recommendationResults, setRecommendationResults] = useState({});
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
if (!cioClient || !Array.isArray(recommendationPods) || recommendationPods.length === 0)
|
|
6
|
-
return;
|
|
7
|
-
const fetchRecommendationResults = async () => {
|
|
8
|
-
const responses = await Promise.all(recommendationPods.map(({ identifier: podId, ...parameters }) => cioClient.recommendations.getRecommendations(podId, parameters)));
|
|
9
|
-
const recommendationPodResults = {};
|
|
10
|
-
responses.forEach(({ response }) => {
|
|
11
|
-
const { pod, results } = response;
|
|
12
|
-
if (pod?.id) {
|
|
13
|
-
recommendationPodResults[pod.id] = results?.map((item) => ({
|
|
14
|
-
...item,
|
|
15
|
-
section: pod.id
|
|
16
|
-
}));
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
setRecommendationResults(recommendationPodResults);
|
|
20
|
-
};
|
|
21
|
-
fetchRecommendationResults();
|
|
22
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
23
|
-
}, [cioClient]);
|
|
24
|
-
return recommendationResults;
|
|
25
|
-
};
|
|
26
|
-
export default useFetchRecommendationPod;
|
|
27
|
-
//# sourceMappingURL=useFetchRecommendationPod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFetchRecommendationPod.js","sourceRoot":"","sources":["../../../src/hooks/useFetchRecommendationPod.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAI5C,MAAM,yBAAyB,GAAG,CAChC,SAA0C,EAC1C,kBAAyD,EACzD,EAAE;IACF,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC,GAAG,QAAQ,CAChE,EAAE,CACH,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,SAAS,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAChG,MAAM,0BAA0B,GAAG,KAAK,IAAI,EAAE;YAC5C,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CACjC,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,UAAU,EAAE,EAAE,EAAE,CAC9D,SAAS,CAAC,eAAe,CAAC,kBAAkB,CAAC,KAAK,EAAE,UAAU,CAAC,CAChE,CACF,CAAC;YACF,MAAM,wBAAwB,GAAG,EAAE,CAAC;YAEpC,SAAS,CAAC,OAAO,CAAC,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACjC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC;gBAClC,IAAI,GAAG,EAAE,EAAE,EAAE;oBACX,wBAAwB,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,CAAC,CAAC,IAAU,EAAE,EAAE,CAAC,CAAC;wBAC/D,GAAG,IAAI;wBACP,OAAO,EAAE,GAAG,CAAC,EAAE;qBAChB,CAAC,CAAC,CAAC;iBACL;YACH,CAAC,CAAC,CAAC;YAEH,wBAAwB,CAAC,wBAAwB,CAAC,CAAC;QACrD,CAAC,CAAC;QACF,0BAA0B,EAAE,CAAC;QAC7B,uDAAuD;IACzD,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,qBAAqB,CAAC;AAC/B,CAAC,CAAC;AAEF,eAAe,yBAAyB,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
const usePrevious = (value) => {
|
|
3
|
-
const ref = useRef();
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
ref.current = value; // assign the value of ref to the argument
|
|
6
|
-
}, [value]); // this code will run when the value of 'value' changes
|
|
7
|
-
return ref.current; // in the end, return the current ref value.
|
|
8
|
-
};
|
|
9
|
-
export default usePrevious;
|
|
10
|
-
//# sourceMappingURL=usePrevious.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePrevious.js","sourceRoot":"","sources":["../../../src/hooks/usePrevious.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1C,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,EAAE;IACpC,MAAM,GAAG,GAAG,MAAM,EAAU,CAAC;IAC7B,SAAS,CAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,0CAA0C;IACjE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,uDAAuD;IACpE,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,4CAA4C;AAClE,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
package/lib/mjs/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { default as AutocompleteResults } from './components/Autocomplete/AutocompleteResults/AutocompleteResults';
|
|
2
|
-
export { default as CioAutocomplete } from './components/Autocomplete/CioAutocomplete/CioAutocomplete';
|
|
3
|
-
export { default as SearchInput } from './components/Autocomplete/SearchInput/SearchInput';
|
|
4
|
-
export { default as SectionItem } from './components/Autocomplete/SectionItem/SectionItem';
|
|
5
|
-
export { default as SectionItemsList } from './components/Autocomplete/SectionItemsList/SectionItemsList';
|
|
6
|
-
export { default as useCioAutocomplete } from './hooks/useCioAutocomplete';
|
|
7
|
-
//# sourceMappingURL=index.js.map
|
package/lib/mjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,mEAAmE,CAAC;AACnH,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,2DAA2D,CAAC;AACvG,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAC3F,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,mDAAmD,CAAC;AAC3F,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,6DAA6D,CAAC;AAC1G,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line
|
|
2
|
-
export const argTypes = {
|
|
3
|
-
placeholder: {
|
|
4
|
-
description: 'Search input placeholder',
|
|
5
|
-
table: {
|
|
6
|
-
type: {
|
|
7
|
-
summary: 'string'
|
|
8
|
-
}
|
|
9
|
-
},
|
|
10
|
-
control: {
|
|
11
|
-
type: 'text'
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
apiKey: {
|
|
15
|
-
type: { name: 'string' },
|
|
16
|
-
description: 'Your constructor API key',
|
|
17
|
-
table: {
|
|
18
|
-
type: {
|
|
19
|
-
summary: 'string'
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
control: {
|
|
23
|
-
type: 'text'
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
onSubmit: {
|
|
27
|
-
type: {
|
|
28
|
-
name: 'function'
|
|
29
|
-
},
|
|
30
|
-
description: `On search submit callback function`,
|
|
31
|
-
table: {
|
|
32
|
-
type: {
|
|
33
|
-
summary: 'Function'
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
control: null
|
|
37
|
-
},
|
|
38
|
-
onFocus: {
|
|
39
|
-
type: {
|
|
40
|
-
name: 'function'
|
|
41
|
-
},
|
|
42
|
-
description: `On focus callback function`,
|
|
43
|
-
table: {
|
|
44
|
-
type: {
|
|
45
|
-
summary: 'Function'
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
control: null
|
|
49
|
-
},
|
|
50
|
-
openOnFocus: {
|
|
51
|
-
description: 'Open results on focus',
|
|
52
|
-
table: {
|
|
53
|
-
type: {
|
|
54
|
-
summary: 'boolean'
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
control: {
|
|
58
|
-
type: 'boolean'
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
//# sourceMappingURL=argTypes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"argTypes.js","sourceRoot":"","sources":["../../../../src/stories/Autocomplete/argTypes.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,WAAW,EAAE;QACX,WAAW,EAAE,0BAA0B;QACvC,KAAK,EAAE;YACL,IAAI,EAAE;gBACJ,OAAO,EAAE,QAAQ;aAClB;SACF;QACD,OAAO,EAAE;YACP,IAAI,EAAE,MAAM;SACb;KACF;IACD,MAAM,EAAE;QACN,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACxB,WAAW,EAAE,0BAA0B;QACvC,KAAK,EAAE;YACL,IAAI,EAAE;gBACJ,OAAO,EAAE,QAAQ;aAClB;SACF;QACD,OAAO,EAAE;YACP,IAAI,EAAE,MAAM;SACb;KACF;IACD,QAAQ,EAAE;QACR,IAAI,EAAE;YACJ,IAAI,EAAE,UAAU;SACjB;QACD,WAAW,EAAE,oCAAoC;QACjD,KAAK,EAAE;YACL,IAAI,EAAE;gBACJ,OAAO,EAAE,UAAU;aACpB;SACF;QACD,OAAO,EAAE,IAAI;KACd;IACD,OAAO,EAAE;QACP,IAAI,EAAE;YACJ,IAAI,EAAE,UAAU;SACjB;QACD,WAAW,EAAE,4BAA4B;QACzC,KAAK,EAAE;YACL,IAAI,EAAE;gBACJ,OAAO,EAAE,UAAU;aACpB;SACF;QACD,OAAO,EAAE,IAAI;KACd;IACD,WAAW,EAAE;QACX,WAAW,EAAE,uBAAuB;QACpC,KAAK,EAAE;YACL,IAAI,EAAE;gBACJ,OAAO,EAAE,SAAS;aACnB;SACF;QACD,OAAO,EAAE;YACP,IAAI,EAAE,SAAS;SAChB;KACF;CACF,CAAC"}
|
package/lib/mjs/typeGuards.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"typeGuards.js","sourceRoot":"","sources":["../../src/typeGuards.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,2BAA2B;AAC3B,MAAM,UAAU,SAAS,CAAC,IAAU;IAClC,OAAQ,IAAgB,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC;AACxD,CAAC"}
|
package/lib/mjs/types.js
DELETED
package/lib/mjs/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|