@constructor-io/constructorio-ui-autocomplete 1.1.8 → 1.1.9

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.
Files changed (98) hide show
  1. package/lib/cjs/components/Autocomplete/Autocomplete.css +110 -0
  2. package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +22 -0
  3. package/lib/cjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js.map +1 -0
  4. package/lib/cjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js +18 -0
  5. package/lib/cjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js.map +1 -0
  6. package/lib/cjs/components/Autocomplete/CioAutocompleteProvider.js +15 -0
  7. package/lib/cjs/components/Autocomplete/CioAutocompleteProvider.js.map +1 -0
  8. package/lib/cjs/components/Autocomplete/SearchInput/SearchInput.js +30 -0
  9. package/lib/cjs/components/Autocomplete/SearchInput/SearchInput.js.map +1 -0
  10. package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js +22 -0
  11. package/lib/cjs/components/Autocomplete/SectionItem/SectionItem.js.map +1 -0
  12. package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +22 -0
  13. package/lib/cjs/components/Autocomplete/SectionItemsList/SectionItemsList.js.map +1 -0
  14. package/lib/cjs/constants.js +179 -0
  15. package/lib/cjs/constants.js.map +1 -0
  16. package/lib/cjs/hooks/useCioAutocomplete.js +107 -0
  17. package/lib/cjs/hooks/useCioAutocomplete.js.map +1 -0
  18. package/lib/cjs/hooks/useCioClient.js +22 -0
  19. package/lib/cjs/hooks/useCioClient.js.map +1 -0
  20. package/lib/cjs/hooks/useDebounce.js +24 -0
  21. package/lib/cjs/hooks/useDebounce.js.map +1 -0
  22. package/lib/cjs/hooks/useDebouncedFetchSections.js +35 -0
  23. package/lib/cjs/hooks/useDebouncedFetchSections.js.map +1 -0
  24. package/lib/cjs/hooks/useDownShift.js +37 -0
  25. package/lib/cjs/hooks/useDownShift.js.map +1 -0
  26. package/lib/cjs/hooks/useFetchRecommendationPod.js +30 -0
  27. package/lib/cjs/hooks/useFetchRecommendationPod.js.map +1 -0
  28. package/lib/cjs/hooks/usePrevious.js +12 -0
  29. package/lib/cjs/hooks/usePrevious.js.map +1 -0
  30. package/lib/cjs/index.js +16 -0
  31. package/lib/cjs/index.js.map +1 -0
  32. package/lib/cjs/stories/Autocomplete/argTypes.js +65 -0
  33. package/lib/cjs/stories/Autocomplete/argTypes.js.map +1 -0
  34. package/lib/cjs/typeGuards.js +10 -0
  35. package/lib/cjs/typeGuards.js.map +1 -0
  36. package/lib/cjs/types.js +3 -0
  37. package/lib/cjs/types.js.map +1 -0
  38. package/lib/cjs/utils.js +72 -0
  39. package/lib/cjs/utils.js.map +1 -0
  40. package/lib/mjs/components/Autocomplete/Autocomplete.css +110 -0
  41. package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js +21 -0
  42. package/lib/mjs/components/Autocomplete/AutocompleteResults/AutocompleteResults.js.map +1 -0
  43. package/lib/mjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js +15 -0
  44. package/lib/mjs/components/Autocomplete/CioAutocomplete/CioAutocomplete.js.map +1 -0
  45. package/lib/mjs/components/Autocomplete/CioAutocompleteProvider.js +10 -0
  46. package/lib/mjs/components/Autocomplete/CioAutocompleteProvider.js.map +1 -0
  47. package/lib/mjs/components/Autocomplete/SearchInput/SearchInput.js +27 -0
  48. package/lib/mjs/components/Autocomplete/SearchInput/SearchInput.js.map +1 -0
  49. package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js +18 -0
  50. package/lib/mjs/components/Autocomplete/SectionItem/SectionItem.js.map +1 -0
  51. package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js +15 -0
  52. package/lib/mjs/components/Autocomplete/SectionItemsList/SectionItemsList.js.map +1 -0
  53. package/lib/mjs/constants.js +176 -0
  54. package/lib/mjs/constants.js.map +1 -0
  55. package/lib/mjs/hooks/useCioAutocomplete.js +118 -0
  56. package/lib/mjs/hooks/useCioAutocomplete.js.map +1 -0
  57. package/lib/mjs/hooks/useCioClient.js +20 -0
  58. package/lib/mjs/hooks/useCioClient.js.map +1 -0
  59. package/lib/mjs/hooks/useDebounce.js +22 -0
  60. package/lib/mjs/hooks/useDebounce.js.map +1 -0
  61. package/lib/mjs/hooks/useDebouncedFetchSections.js +41 -0
  62. package/lib/mjs/hooks/useDebouncedFetchSections.js.map +1 -0
  63. package/lib/mjs/hooks/useDownShift.js +33 -0
  64. package/lib/mjs/hooks/useDownShift.js.map +1 -0
  65. package/lib/mjs/hooks/useFetchRecommendationPod.js +27 -0
  66. package/lib/mjs/hooks/useFetchRecommendationPod.js.map +1 -0
  67. package/lib/mjs/hooks/usePrevious.js +10 -0
  68. package/lib/mjs/hooks/usePrevious.js.map +1 -0
  69. package/lib/mjs/index.js +7 -0
  70. package/lib/mjs/index.js.map +1 -0
  71. package/lib/mjs/stories/Autocomplete/argTypes.js +62 -0
  72. package/lib/mjs/stories/Autocomplete/argTypes.js.map +1 -0
  73. package/lib/mjs/typeGuards.js +6 -0
  74. package/lib/mjs/typeGuards.js.map +1 -0
  75. package/lib/mjs/types.js +2 -0
  76. package/lib/mjs/types.js.map +1 -0
  77. package/lib/mjs/utils.js +58 -0
  78. package/lib/mjs/utils.js.map +1 -0
  79. package/lib/types/components/Autocomplete/AutocompleteResults/AutocompleteResults.d.ts +11 -0
  80. package/lib/types/components/Autocomplete/CioAutocomplete/CioAutocomplete.d.ts +3 -0
  81. package/lib/types/components/Autocomplete/CioAutocompleteProvider.d.ts +28 -0
  82. package/lib/types/components/Autocomplete/SearchInput/SearchInput.d.ts +7 -0
  83. package/lib/types/components/Autocomplete/SectionItem/SectionItem.d.ts +10 -0
  84. package/lib/types/components/Autocomplete/SectionItemsList/SectionItemsList.d.ts +12 -0
  85. package/lib/types/constants.d.ts +23 -0
  86. package/lib/types/hooks/useCioAutocomplete.d.ts +29 -0
  87. package/lib/types/hooks/useCioClient.d.ts +15 -0
  88. package/lib/types/hooks/useDebounce.d.ts +2 -0
  89. package/lib/types/hooks/useDebouncedFetchSections.d.ts +4 -0
  90. package/lib/types/hooks/useDownShift.d.ts +16 -0
  91. package/lib/types/hooks/useFetchRecommendationPod.d.ts +4 -0
  92. package/lib/types/hooks/usePrevious.d.ts +2 -0
  93. package/lib/types/index.d.ts +6 -0
  94. package/lib/types/stories/Autocomplete/argTypes.d.ts +62 -0
  95. package/lib/types/typeGuards.d.ts +2 -0
  96. package/lib/types/types.d.ts +131 -0
  97. package/lib/types/utils.d.ts +24 -0
  98. package/package.json +1 -1
@@ -0,0 +1,110 @@
1
+ /* Autosuggest Container */
2
+ .cio-autocomplete {
3
+ position: relative;
4
+ height: 2rem;
5
+ padding: 20px;
6
+ font-family: Arial, Helvetica, sans-serif;
7
+ }
8
+
9
+ /* Autosuggest Form */
10
+ .cio-autocomplete .cio-form {
11
+ position: relative;
12
+ height: 100%;
13
+ width: 24rem;
14
+ }
15
+
16
+ .cio-autocomplete .cio-input {
17
+ width: 100%;
18
+ height: 100%;
19
+ border: 1px solid gray;
20
+ padding: 0 10px;
21
+ border-radius: 3px;
22
+ font-size: 1rem;
23
+ }
24
+
25
+ .cio-autocomplete .cio-submit-btn,
26
+ .cio-autocomplete .cio-clear-btn {
27
+ position: absolute;
28
+ top: 1px;
29
+ bottom: -1px;
30
+ right: -21px;
31
+ cursor: pointer;
32
+ }
33
+
34
+ .cio-autocomplete button:disabled {
35
+ cursor: not-allowed;
36
+ }
37
+
38
+ .cio-autocomplete .cio-submit-btn {
39
+ right: -21px;
40
+ }
41
+
42
+ .cio-autocomplete .cio-clear-btn {
43
+ right: 10px;
44
+ }
45
+
46
+ .cio-autocomplete .cio-icon {
47
+ display: flex;
48
+ justify-content: center;
49
+ }
50
+
51
+ /* Autosuggest Results */
52
+ .cio-autocomplete .cio-results {
53
+ position: absolute;
54
+ background-color: white;
55
+ gap: 20px;
56
+ padding-left: 0px;
57
+ list-style: none;
58
+ display: flex;
59
+ flex-direction: row;
60
+ z-index: 1000;
61
+ margin-top: 5px;
62
+ }
63
+
64
+ .cio-autocomplete .cio-sectionName {
65
+ margin: 15px 0;
66
+ font-size: 1rem;
67
+ }
68
+
69
+ .cio-autocomplete .cio-section-items {
70
+ padding: 0;
71
+ }
72
+
73
+ .cio-autocomplete .cio-item-SearchSuggestions {
74
+ flex-direction: column;
75
+ min-width: 160px;
76
+ }
77
+
78
+ .cio-autocomplete .cio-item {
79
+ flex: 1;
80
+ display: flex;
81
+ flex-direction: column;
82
+ cursor: pointer;
83
+ list-style: none;
84
+ padding: 5px;
85
+ border-bottom: 3px solid transparent;
86
+ }
87
+
88
+ .cio-autocomplete .cio-item[aria-selected='true'] {
89
+ background-color: hsl(0, 0%, 90%);
90
+ border-radius: 4px;
91
+ }
92
+
93
+ .cio-autocomplete .Products .cio-item {
94
+ display: inline-flex;
95
+ align-items: center;
96
+ width: 25%;
97
+ height: 140px;
98
+ padding: 5px 0;
99
+ }
100
+
101
+ .cio-autocomplete .cio-item p {
102
+ margin: 0;
103
+ overflow: hidden;
104
+ }
105
+
106
+ .cio-autocomplete .cio-item img {
107
+ width: 100%;
108
+ max-width: 100px;
109
+ max-height: 100px;
110
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
5
+ const SectionItemsList_1 = require("../SectionItemsList/SectionItemsList");
6
+ const DefaultRenderResults = ({ sections }) => sections === null || sections === void 0 ? void 0 : sections.map((section) => (react_1.default.createElement(SectionItemsList_1.default, { section: section, key: section.identifier })));
7
+ function AutocompleteResults(props) {
8
+ const { children = DefaultRenderResults } = props;
9
+ const { sections, isOpen, getMenuProps, getItemProps } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
10
+ const hasResults = sections && sections.some((section) => { var _a; return (_a = section === null || section === void 0 ? void 0 : section.data) === null || _a === void 0 ? void 0 : _a.length; });
11
+ let content;
12
+ if (isOpen && hasResults) {
13
+ content = typeof children === 'function' ? children({ sections, getItemProps }) : children;
14
+ }
15
+ else {
16
+ content = null;
17
+ }
18
+ const menuProps = Object.assign({}, getMenuProps());
19
+ return react_1.default.createElement("ul", Object.assign({}, menuProps), content);
20
+ }
21
+ exports.default = AutocompleteResults;
22
+ //# sourceMappingURL=AutocompleteResults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AutocompleteResults.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/AutocompleteResults/AutocompleteResults.tsx"],"names":[],"mappings":";;AAAA,iCAAqD;AAErD,wEAAoE;AACpE,2EAAoE;AAWpE,MAAM,oBAAoB,GAAkB,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAC3D,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,GAAG,CAAC,CAAC,OAA6B,EAAE,EAAE,CAAC,CAC/C,8BAAC,0BAAgB,IAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,UAAU,GAAI,CAChE,CAAC,CAAC;AAEL,SAAwB,mBAAmB,CAAC,KAA+B;IACzE,MAAM,EAAE,QAAQ,GAAG,oBAAoB,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,IAAA,kBAAU,EAAC,gDAAsB,CAAC,CAAC;IAE5F,MAAM,UAAU,GAAG,QAAQ,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,WAAC,OAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,MAAM,CAAA,EAAA,CAAC,CAAC;IAEjF,IAAI,OAAO,CAAC;IACZ,IAAI,MAAM,IAAI,UAAU,EAAE;QACxB,OAAO,GAAG,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;KAC5F;SAAM;QACL,OAAO,GAAG,IAAI,CAAC;KAChB;IAED,MAAM,SAAS,qBACV,YAAY,EAAE,CAClB,CAAC;IAEF,OAAO,sDAAQ,SAAS,GAAG,OAAO,CAAM,CAAC;AAC3C,CAAC;AAlBD,sCAkBC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
5
+ const AutocompleteResults_1 = require("../AutocompleteResults/AutocompleteResults");
6
+ const SearchInput_1 = require("../SearchInput/SearchInput");
7
+ function CioAutocomplete(props) {
8
+ const { children } = props;
9
+ if (children) {
10
+ return react_1.default.createElement(CioAutocompleteProvider_1.default, Object.assign({}, props), children);
11
+ }
12
+ return (react_1.default.createElement("div", null,
13
+ react_1.default.createElement(CioAutocompleteProvider_1.default, Object.assign({}, props),
14
+ react_1.default.createElement(SearchInput_1.default, null),
15
+ react_1.default.createElement(AutocompleteResults_1.default, null))));
16
+ }
17
+ exports.default = CioAutocomplete;
18
+ //# sourceMappingURL=CioAutocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CioAutocomplete.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/CioAutocomplete/CioAutocomplete.tsx"],"names":[],"mappings":";;AAAA,iCAA0B;AAC1B,wEAAiE;AACjE,oFAA6E;AAC7E,4DAAqD;AAGrD,SAAwB,eAAe,CAAC,KAA2B;IACjE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAE3B,IAAI,QAAQ,EAAE;QACZ,OAAO,8BAAC,iCAAuB,oBAAK,KAAK,GAAG,QAAQ,CAA2B,CAAC;KACjF;IAED,OAAO,CACL;QACE,8BAAC,iCAAuB,oBAAK,KAAK;YAChC,8BAAC,qBAAW,OAAG;YACf,8BAAC,6BAAmB,OAAG,CACC,CACtB,CACP,CAAC;AACJ,CAAC;AAfD,kCAeC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CioAutocompleteContext = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const react_1 = require("react");
6
+ const useCioAutocomplete_1 = require("../../hooks/useCioAutocomplete");
7
+ exports.CioAutocompleteContext = (0, react_1.createContext)({});
8
+ function CioAutocompleteProvider(props) {
9
+ const { children } = props, restProps = tslib_1.__rest(props, ["children"]);
10
+ const cioAutocomplete = (0, useCioAutocomplete_1.default)(restProps);
11
+ return (react_1.default.createElement(exports.CioAutocompleteContext.Provider, { value: cioAutocomplete },
12
+ react_1.default.createElement("div", { className: cioAutocomplete.autocompleteClassName }, children)));
13
+ }
14
+ exports.default = CioAutocompleteProvider;
15
+ //# sourceMappingURL=CioAutocompleteProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CioAutocompleteProvider.js","sourceRoot":"","sources":["../../../../src/components/Autocomplete/CioAutocompleteProvider.tsx"],"names":[],"mappings":";;;;AAAA,iCAA6C;AAC7C,uEAAgE;AAGnD,QAAA,sBAAsB,GAAG,IAAA,qBAAa,EACjD,EAA2C,CAC5C,CAAC;AAEF,SAAwB,uBAAuB,CAAC,KAA2B;IACzE,MAAM,EAAE,QAAQ,KAAmB,KAAK,EAAnB,SAAS,kBAAK,KAAK,EAAlC,YAA0B,CAAQ,CAAC;IACzC,MAAM,eAAe,GAAG,IAAA,4BAAkB,EAAC,SAAS,CAAC,CAAC;IAEtD,OAAO,CACL,8BAAC,8BAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe;QACrD,uCAAK,SAAS,EAAE,eAAe,CAAC,qBAAqB,IAAG,QAAQ,CAAO,CACvC,CACnC,CAAC;AACJ,CAAC;AATD,0CASC"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
5
+ function DefaultRenderInput({ getFormProps, getInputProps, getLabelProps, setQuery }) {
6
+ const inputProps = getInputProps();
7
+ return (react_1.default.createElement("form", Object.assign({}, getFormProps()),
8
+ react_1.default.createElement("label", Object.assign({}, getLabelProps(), { htmlFor: 'cio-input' }),
9
+ react_1.default.createElement("input", Object.assign({ id: 'cio-input' }, inputProps))),
10
+ react_1.default.createElement("button", { className: 'cio-clear-btn', "data-testid": 'cio-clear-btn', hidden: !inputProps.value, onClick: () => {
11
+ setQuery('');
12
+ if (inputProps.id) {
13
+ setTimeout(() => { var _a; return (_a = document.getElementById(inputProps.id)) === null || _a === void 0 ? void 0 : _a.focus(); }, 100);
14
+ }
15
+ }, type: 'button', "aria-label": 'Clear search field text' },
16
+ react_1.default.createElement("div", { className: 'cio-icon' },
17
+ react_1.default.createElement("svg", { stroke: 'currentColor', fill: 'currentColor', strokeWidth: '0', viewBox: '0 0 512 512', height: '1em', width: '1em', xmlns: 'http://www.w3.org/2000/svg' },
18
+ react_1.default.createElement("path", { d: 'M289.94 256l95-95A24 24 0 00351 127l-95 95-95-95a24 24 0 00-34 34l95 95-95 95a24 24 0 1034 34l95-95 95 95a24 24 0 0034-34z' })))),
19
+ react_1.default.createElement("button", { className: 'cio-submit-btn', "data-testid": 'cio-submit-btn', disabled: !inputProps.value, type: 'submit', "aria-label": 'Submit Search' },
20
+ react_1.default.createElement("div", { className: 'cio-icon' },
21
+ react_1.default.createElement("svg", { stroke: 'currentColor', fill: 'currentColor', strokeWidth: '0', viewBox: '0 0 512 512', height: '1em', width: '1em', xmlns: 'http://www.w3.org/2000/svg' },
22
+ react_1.default.createElement("path", { d: 'M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z' }))))));
23
+ }
24
+ function SearchInput(props) {
25
+ const { children = DefaultRenderInput } = props;
26
+ const { getFormProps, getInputProps, getLabelProps, setQuery } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
27
+ return children({ getFormProps, getInputProps, getLabelProps, setQuery });
28
+ }
29
+ exports.default = SearchInput;
30
+ //# sourceMappingURL=SearchInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchInput.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/SearchInput/SearchInput.tsx"],"names":[],"mappings":";;AAAA,iCAAwD;AAExD,wEAAoE;AAMpE,SAAS,kBAAkB,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE;IAClF,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IAEnC,OAAO,CACL,wDAAU,YAAY,EAAE;QACtB,yDAAW,aAAa,EAAE,IAAE,OAAO,EAAC,WAAW;YAC7C,uDAAO,EAAE,EAAC,WAAW,IAAK,UAAU,EAAI,CAClC;QACR,0CACE,SAAS,EAAC,eAAe,iBACb,eAAe,EAC3B,MAAM,EAAE,CAAC,UAAU,CAAC,KAAK,EACzB,OAAO,EAAE,GAAG,EAAE;gBACZ,QAAQ,CAAC,EAAE,CAAC,CAAC;gBACb,IAAI,UAAU,CAAC,EAAE,EAAE;oBACjB,UAAU,CAAC,GAAG,EAAE,WAAC,OAAA,MAAA,QAAQ,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,CAAC,0CAAE,KAAK,EAAE,CAAA,EAAA,EAAE,GAAG,CAAC,CAAC;iBACxE;YACH,CAAC,EACD,IAAI,EAAC,QAAQ,gBACF,yBAAyB;YACpC,uCAAK,SAAS,EAAC,UAAU;gBACvB,uCACE,MAAM,EAAC,cAAc,EACrB,IAAI,EAAC,cAAc,EACnB,WAAW,EAAC,GAAG,EACf,OAAO,EAAC,aAAa,EACrB,MAAM,EAAC,KAAK,EACZ,KAAK,EAAC,KAAK,EACX,KAAK,EAAC,4BAA4B;oBAClC,wCAAM,CAAC,EAAC,4HAA4H,GAAG,CACnI,CACF,CACC;QACT,0CACE,SAAS,EAAC,gBAAgB,iBACd,gBAAgB,EAC5B,QAAQ,EAAE,CAAC,UAAU,CAAC,KAAK,EAC3B,IAAI,EAAC,QAAQ,gBACF,eAAe;YAC1B,uCAAK,SAAS,EAAC,UAAU;gBACvB,uCACE,MAAM,EAAC,cAAc,EACrB,IAAI,EAAC,cAAc,EACnB,WAAW,EAAC,GAAG,EACf,OAAO,EAAC,aAAa,EACrB,MAAM,EAAC,KAAK,EACZ,KAAK,EAAC,KAAK,EACX,KAAK,EAAC,4BAA4B;oBAClC,wCAAM,CAAC,EAAC,2VAA2V,GAAG,CAClW,CACF,CACC,CACJ,CACR,CAAC;AACJ,CAAC;AAED,SAAwB,WAAW,CAAC,KAAuB;IACzD,MAAM,EAAE,QAAQ,GAAG,kBAAkB,EAAE,GAAG,KAAK,CAAC;IAChD,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,GAC5D,IAAA,kBAAU,EAAC,gDAAsB,CAAC,CAAC;IAErC,OAAO,QAAQ,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC;AAC5E,CAAC;AAND,8BAMC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ const CioAutocompleteProvider_1 = require("../CioAutocompleteProvider");
5
+ const typeGuards_1 = require("../../../typeGuards");
6
+ function SectionItem(props) {
7
+ var _a;
8
+ const { item, index, sectionIdentifier, children } = props;
9
+ const { getItemProps } = (0, react_1.useContext)(CioAutocompleteProvider_1.CioAutocompleteContext);
10
+ let defaultChildren;
11
+ if ((0, typeGuards_1.isProduct)(item)) {
12
+ defaultChildren = (react_1.default.createElement(react_1.default.Fragment, null,
13
+ react_1.default.createElement("img", { "data-testid": 'cio-img', src: (_a = item.data) === null || _a === void 0 ? void 0 : _a.image_url, alt: item.value }),
14
+ react_1.default.createElement("p", { "data-testid": 'cio-text' }, item.value)));
15
+ }
16
+ else {
17
+ defaultChildren = item.value;
18
+ }
19
+ return (react_1.default.createElement("li", Object.assign({}, getItemProps({ item, index, sectionIdentifier })), children || defaultChildren));
20
+ }
21
+ exports.default = SectionItem;
22
+ //# sourceMappingURL=SectionItem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SectionItem.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/SectionItem/SectionItem.tsx"],"names":[],"mappings":";;AAAA,iCAAqD;AACrD,wEAAoE;AAEpE,oDAAgD;AAUhD,SAAwB,WAAW,CAAC,KAAuB;;IACzD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC3D,MAAM,EAAE,YAAY,EAAE,GAAG,IAAA,kBAAU,EAAC,gDAAsB,CAAC,CAAC;IAE5D,IAAI,eAAe,CAAC;IACpB,IAAI,IAAA,sBAAS,EAAC,IAAI,CAAC,EAAE;QACnB,eAAe,GAAG,CAChB;YACE,sDAAiB,SAAS,EAAC,GAAG,EAAE,MAAA,IAAI,CAAC,IAAI,0CAAE,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,KAAK,GAAI;YACzE,oDAAe,UAAU,IAAE,IAAI,CAAC,KAAK,CAAK,CACzC,CACJ,CAAC;KACH;SAAM;QACL,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC;KAC9B;IAED,OAAO,CACL,sDAAQ,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,iBAAiB,EAAE,CAAC,GAAG,QAAQ,IAAI,eAAe,CAAM,CAC7F,CAAC;AACJ,CAAC;AAnBD,8BAmBC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ const SectionItem_1 = require("../SectionItem/SectionItem");
5
+ const utils_1 = require("../../../utils");
6
+ // eslint-disable-next-line func-names
7
+ const DefaultRenderSectionItemsList = function ({ section }) {
8
+ var _a;
9
+ const sectionName = (section === null || section === void 0 ? void 0 : section.displayName) || (section === null || section === void 0 ? void 0 : section.identifier);
10
+ return (react_1.default.createElement("li", { className: `${sectionName} cio-section`, role: 'none' },
11
+ react_1.default.createElement("h5", { className: 'cio-sectionName', "aria-hidden": true }, (0, utils_1.camelToStartCase)(sectionName)),
12
+ react_1.default.createElement("ul", { className: 'cio-section-items', role: 'none' }, (_a = section === null || section === void 0 ? void 0 : section.data) === null || _a === void 0 ? void 0 : _a.map((item, index) => {
13
+ var _a;
14
+ return (react_1.default.createElement(SectionItem_1.default, { item: item, index: index, sectionIdentifier: section === null || section === void 0 ? void 0 : section.identifier, key: `${section === null || section === void 0 ? void 0 : section.identifier}_${(_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.id}` }));
15
+ }))));
16
+ };
17
+ function SectionItemsList(props) {
18
+ const { section, children = DefaultRenderSectionItemsList } = props;
19
+ return children({ section });
20
+ }
21
+ exports.default = SectionItemsList;
22
+ //# sourceMappingURL=SectionItemsList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SectionItemsList.js","sourceRoot":"","sources":["../../../../../src/components/Autocomplete/SectionItemsList/SectionItemsList.tsx"],"names":[],"mappings":";;AAAA,iCAA4C;AAE5C,4DAAqD;AACrD,0CAAkD;AAYlD,sCAAsC;AACtC,MAAM,6BAA6B,GAA2B,UAAU,EAAE,OAAO,EAAE;;IACjF,MAAM,WAAW,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAA,CAAC;IAEhE,OAAO,CACL,sCAAI,SAAS,EAAE,GAAG,WAAW,cAAc,EAAE,IAAI,EAAC,MAAM;QACtD,sCAAI,SAAS,EAAC,iBAAiB,yBAC5B,IAAA,wBAAgB,EAAC,WAAW,CAAC,CAC3B;QACL,sCAAI,SAAS,EAAC,mBAAmB,EAAC,IAAI,EAAC,MAAM,IAC1C,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,0CAAE,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;;YAAC,OAAA,CACnC,8BAAC,qBAAW,IACV,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,EACZ,iBAAiB,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,EACtC,GAAG,EAAE,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,IAAI,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,0CAAE,EAAE,EAAE,GAC/C,CACH,CAAA;SAAA,CAAC,CACC,CACF,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,SAAwB,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;AAJD,mCAIC"}
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.customStylesDescription = exports.multipleSectionsDescription = exports.openOnFocusDescription = exports.zeroStateSectionsDescription = exports.onSubmitDescription = exports.onChangeDescription = exports.onFocusDescription = exports.customSectionDescription = exports.recommendationsDescription = exports.sectionOrderDescription = exports.numResultsDescription = exports.contentDescription = exports.productsDescription = exports.searchSuggestionsDescription = exports.placeholderDescription = exports.cioJsClientDescription = exports.apiKeyDescription = exports.zeroStateDescription = exports.userEventsDescription = exports.sectionsDescription = exports.hookDescription = exports.componentDescription = exports.apiKey = void 0;
4
+ // Autocomplete key index
5
+ exports.apiKey = 'key_Gep3oQOu5IMcNh9A';
6
+ /// //////////////////////////////
7
+ // Storybook Folder Descriptions
8
+ /// //////////////////////////////
9
+ exports.componentDescription = `- import \`CioAutocomplete\` to render in your JSX.
10
+ - This component handles state management, data fetching, and rendering logic.
11
+ - To use this component, an \`apiKey\` or \`cioJsClient\` are required, all other values are optional.
12
+ - Use different props to configure the behavior of this component.
13
+ - The following stories shows how different props affect the component's behavior
14
+
15
+ > 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)
16
+ `;
17
+ exports.hookDescription = `- import \`useCioAutocomplete\` and call this custom hook in a functional component.
18
+ - This hook handles state management & data fetching, but leaves rendering logic up to you
19
+ - To use this hook, an \`apiKey\` or \`cioJsClient\` are required, all other values are optional.
20
+ - Pass different options to the \`useCioAutocomplete\` hook to configure behavior.
21
+ - The following stories shows how different options affect the hook's behavior
22
+
23
+ Calling the \`useCioAutocomplete\` hook returns an object with the following keys:
24
+
25
+ \`\`\`jsx
26
+ const {
27
+ // must be used for a hooks integrations
28
+ query: string, // current input field value
29
+ sections: [{...}], // array of sections data to render in menu list,
30
+ getFormProps: () => ({...})), // prop getter for jsx form element
31
+ getLabelProps: () => ({...})), // optional: prop getter for jsx label element
32
+ getInputProps: () => ({...})), // prop getter for jsx input element
33
+ getMenuProps: () => ({...})), // prop getter for jsx element serving as menu container
34
+ getItemProps: () => ({...})), // prop getter for jsx element serving as each result
35
+ isOpen: boolean,
36
+
37
+ // available for advanced hooks integration use cases
38
+ openMenu: () => void, // open menu
39
+ closeMenu: () => void, // close menu
40
+ setQuery: () => void, // update the current input field value
41
+ cioJsClient, // instance of constructorio-client-javascript
42
+ } = useCioAutocomplete(args);
43
+ \`\`\`
44
+
45
+ > 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)
46
+ `;
47
+ /// //////////////////////////////
48
+ // Storybook Pages
49
+ /// //////////////////////////////
50
+ exports.sectionsDescription = `- by default, typing a query will fetch data for search suggestions and Products
51
+ - to override this, pass a an array of sections objects
52
+ - the order of the objects in the \`sections\` array determines the order of the results
53
+ - each section object must have an \`identifier\`
54
+ - each section object can specify a \`type\`
55
+ - each section object can override the default \`numResults\` of 8
56
+
57
+ When no values are passed for the \`sections\` argument, the following defaults are used:
58
+
59
+ \`\`\`jsx
60
+ [
61
+ {
62
+ identifier: 'Search Suggestions',
63
+ type: 'autocomplete',
64
+ numResults: 8
65
+ },
66
+ {
67
+ identifier: 'Products',
68
+ type: 'autocomplete',
69
+ numResults: 8
70
+ }
71
+ ]
72
+ \`\`\`
73
+ `;
74
+ exports.userEventsDescription = `- pass callback functions to respond to user events
75
+ - if provided, the onFocus callback function will be called each time the user focuses on the text input field
76
+ - if provided, the onChange callback function will be called each time the user changes the value in the text input field
77
+ - if provided, the onSubmit callback function will be called each time the user submits the form
78
+ - 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
79
+
80
+ > ⚠️ 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.`;
81
+ exports.zeroStateDescription = `- when the text input field has no text, we call this zero state
82
+ - by default, the autocomplete shows nothing in the menu it's for zero state
83
+ - to show zero state results, pass an array of section objects for \`zeroStateSections\`
84
+ - when \`zeroStateSections\` has sections, the menu will open on user focus by default
85
+ - 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
86
+ - the order of the objects in the \`zeroStateSections\` array determines the order of the results
87
+ - each section object must have an \`identifier\`
88
+ - each section object can specify a \`type\`
89
+ - each section object can override the default \`numResults\` of 8`;
90
+ /// //////////////////////////////
91
+ // Storybook Stories
92
+ /// //////////////////////////////
93
+ exports.apiKeyDescription = `Pass an \`apiKey\` to request results from constructor's servers`;
94
+ exports.cioJsClientDescription = `If you are already using an instance of the \`ConstructorIOClient\`, you can pass a \`cioJsClient\` instead of an \`apiKey\` to request results from constructor's servers
95
+
96
+ > 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)`;
97
+ exports.placeholderDescription = `Pass a \`placeholder\` to override the default input field placeholder text shown to users before they start typing their query`;
98
+ exports.searchSuggestionsDescription = `Override default \`sections\` to only suggest search terms`;
99
+ exports.productsDescription = `Override default \`sections\` to only suggested products`;
100
+ exports.contentDescription = `Override default \`sections\` to only suggest content`;
101
+ exports.numResultsDescription = `Override default \`numResults\` to only suggest 2 products per query`;
102
+ exports.sectionOrderDescription = `Override default \`numResults\` to suggest products, then terms`;
103
+ exports.recommendationsDescription = `Use constructor's recommendations service, with \`"type": "recommendations"\``;
104
+ exports.customSectionDescription = `Use a custom section, by managing and passing your own data, with \`"type": "custom"\` and \`"data":[{...}]\``;
105
+ exports.onFocusDescription = `Pass an \`onFocus\` callback function to execute some code each time the user applies focus to the text input field`;
106
+ exports.onChangeDescription = `Pass an \`onChange\` callback function to execute some code each time the user changes the value of the text input field`;
107
+ exports.onSubmitDescription = `Pass an \`onSubmit\` callback function to execute some code after a user submits the search form.
108
+
109
+ Your callback function will be invoked with a submit event containing useful metadata about the submit event:
110
+ - if the user submits the text input:
111
+ - the \`query\` field will provide the value of that input field
112
+ - if the user selects a suggested item from the dropdown list:
113
+ - the \`originalQuery\` field will provide the value of the input field that generated the selected item
114
+ - an \`item\` object with information about the suggestion that the user selected`;
115
+ exports.zeroStateSectionsDescription = `Use \`zeroStateSections\` to show suggestions after a user applies focus to the search input field and before they start typing a query`;
116
+ exports.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`;
117
+ exports.multipleSectionsDescription = `Use as many different \`recommendations\` and \`custom\` sections as you'd like and in whatever order you would like!`;
118
+ // from .storybook/custom-styles-story.css
119
+ exports.customStylesDescription = `
120
+ By default, importing react components or hooks from this library does not pull any css into your project.
121
+
122
+ If you wish to use some starter styles from this library, add an import statement similar to the example import statement below:
123
+
124
+ \`
125
+ import 'node_modules/@constructor-io/constructorio-ui-autocomplete/lib/mjs/components/Autocomplete/Autocomplete.css';
126
+ \`
127
+
128
+ <i></i>
129
+
130
+ - To opt out of all default styling, do not import the \`Autocomplete.css\` stylesheet.
131
+ - The path and syntax in the example above may change depending on your module bundling strategy
132
+ - These starter styles can be used as a foundation to build on top of, or just as a reference for you to replace completely.
133
+ - All starter styles in this library are scoped within the \`.cio-autocomplete\` css selector.
134
+ - These starter styles are intended to be extended by layering in your own css rules
135
+ - If you like, you can override the container's className like so:
136
+ \`autocompleteClassName='custom-autocomplete-container'\`
137
+ - If you like, you can pass additional className(s) of your choosing like so:
138
+ \`autocompleteClassName='cio-autocomplete custom-autocomplete-container'\`
139
+
140
+
141
+ \`\`\`css
142
+ /* Custom Style Sheet */
143
+ .cio-autocomplete.custom-autocomplete-styles form {
144
+ height: 44px;
145
+ width: 600px;
146
+ border-radius: 8px;
147
+ background-color: rgb(247, 247, 247);
148
+ }
149
+
150
+ .cio-autocomplete.custom-autocomplete-styles .cio-input {
151
+ font-weight: bold;
152
+ }
153
+
154
+ .cio-autocomplete.custom-autocomplete-styles .cio-form button {
155
+ width: 44px;
156
+ }
157
+
158
+ .cio-autocomplete.custom-autocomplete-styles .cio-clear-btn {
159
+ right: 24px;
160
+ }
161
+
162
+ .cio-autocomplete.custom-autocomplete-styles .cio-sectionName {
163
+ margin: 5px 3px;
164
+ }
165
+
166
+ .cio-autocomplete.custom-autocomplete-styles .cio-results {
167
+ width: 620px;
168
+ max-height: 334px;
169
+ overflow: hidden;
170
+ border-radius: 0px 0px 8px 8px;
171
+ color: rgb(51, 51, 51);
172
+ }
173
+
174
+ .cio-autocomplete.custom-autocomplete-styles .Products p {
175
+ padding: 5px 5px 0;
176
+ }
177
+ \`\`\`
178
+ `;
179
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAA,yBAAyB;AACZ,QAAA,MAAM,GAAG,sBAAsB,CAAC;AAE7C,kCAAkC;AAClC,gCAAgC;AAChC,kCAAkC;AAErB,QAAA,oBAAoB,GAAG;;;;;;;CAOnC,CAAC;AAEW,QAAA,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B9B,CAAC;AAEF,kCAAkC;AAClC,kBAAkB;AAClB,kCAAkC;AAErB,QAAA,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;CAuBlC,CAAC;AAEW,QAAA,qBAAqB,GAAG;;;;;;+bAM0Z,CAAC;AAEnb,QAAA,oBAAoB,GAAG;;;;;;;;mEAQ+B,CAAC;AAEpE,kCAAkC;AAClC,oBAAoB;AACpB,kCAAkC;AAErB,QAAA,iBAAiB,GAAG,kEAAkE,CAAC;AACvF,QAAA,sBAAsB,GAAG;;6LAEuJ,CAAC;AACjL,QAAA,sBAAsB,GAAG,iIAAiI,CAAC;AAC3J,QAAA,4BAA4B,GAAG,4DAA4D,CAAC;AAC5F,QAAA,mBAAmB,GAAG,0DAA0D,CAAC;AACjF,QAAA,kBAAkB,GAAG,uDAAuD,CAAC;AAC7E,QAAA,qBAAqB,GAAG,sEAAsE,CAAC;AAC/F,QAAA,uBAAuB,GAAG,iEAAiE,CAAC;AAC5F,QAAA,0BAA0B,GAAG,+EAA+E,CAAC;AAC7G,QAAA,wBAAwB,GAAG,+GAA+G,CAAC;AAC3I,QAAA,kBAAkB,GAAG,qHAAqH,CAAC;AAC3I,QAAA,mBAAmB,GAAG,0HAA0H,CAAC;AACjJ,QAAA,mBAAmB,GAAG;;;;;;;sFAOmD,CAAC;AAC1E,QAAA,4BAA4B,GAAG,yIAAyI,CAAC;AACzK,QAAA,sBAAsB,GAAG,mJAAmJ,CAAC;AAC7K,QAAA,2BAA2B,GAAG,uHAAuH,CAAC;AAEnK,0CAA0C;AAC7B,QAAA,uBAAuB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2DtC,CAAC"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultSections = void 0;
4
+ const react_1 = require("react");
5
+ const useCioClient_1 = require("./useCioClient");
6
+ const useDownShift_1 = require("./useDownShift");
7
+ const useDebouncedFetchSections_1 = require("./useDebouncedFetchSections");
8
+ const useFetchRecommendationPod_1 = require("./useFetchRecommendationPod");
9
+ const usePrevious_1 = require("./usePrevious");
10
+ const utils_1 = require("../utils");
11
+ exports.defaultSections = [
12
+ {
13
+ identifier: 'Search Suggestions',
14
+ type: 'autocomplete',
15
+ },
16
+ {
17
+ identifier: 'Products',
18
+ type: 'autocomplete',
19
+ },
20
+ ];
21
+ const useCioAutocomplete = (options) => {
22
+ const defaultPlaceholder = 'What can we help you find today?';
23
+ const { onSubmit, onChange, openOnFocus, apiKey, cioJsClient, placeholder = defaultPlaceholder, sections = exports.defaultSections, zeroStateSections, autocompleteClassName = 'cio-autocomplete', } = options;
24
+ const [query, setQuery] = (0, react_1.useState)('');
25
+ const previousQuery = (0, usePrevious_1.default)(query);
26
+ const cioClient = (0, useCioClient_1.default)({ apiKey, cioJsClient });
27
+ const zeroStateSectionsActive = !query.length && zeroStateSections;
28
+ let activeSections = zeroStateSectionsActive ? zeroStateSections : sections;
29
+ if (sections && !Array.isArray(sections)) {
30
+ // eslint-disable-next-line
31
+ console.error('useCioAutocomplete expects sections to reference an array of section configuration objects');
32
+ activeSections = [];
33
+ }
34
+ if (zeroStateSections && !Array.isArray(zeroStateSections)) {
35
+ // eslint-disable-next-line
36
+ console.error('useCioAutocomplete expects zeroStateSections to reference an array of section configuration objects');
37
+ activeSections = [];
38
+ }
39
+ const autocompleteSections = activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => config.type === 'autocomplete' || !config.type);
40
+ const recommendationsSections = activeSections === null || activeSections === void 0 ? void 0 : activeSections.filter((config) => config.type === 'recommendations');
41
+ const autocompleteResults = (0, useDebouncedFetchSections_1.default)(query, cioClient, autocompleteSections);
42
+ const recommendationsResults = (0, useFetchRecommendationPod_1.default)(cioClient, recommendationsSections);
43
+ const sectionResults = Object.assign(Object.assign({}, autocompleteResults), recommendationsResults);
44
+ const activeSectionsWithData = [];
45
+ activeSections === null || activeSections === void 0 ? void 0 : activeSections.forEach((config) => {
46
+ const { identifier, data: customData } = config;
47
+ const data = sectionResults[identifier] || customData;
48
+ if (data && data !== undefined) {
49
+ activeSectionsWithData.push(Object.assign(Object.assign({}, config), { data }));
50
+ }
51
+ });
52
+ const items = [];
53
+ activeSectionsWithData === null || activeSectionsWithData === void 0 ? void 0 : activeSectionsWithData.forEach((config) => {
54
+ if (config === null || config === void 0 ? void 0 : config.data) {
55
+ items.push(...config.data);
56
+ }
57
+ });
58
+ const downshift = (0, useDownShift_1.default)({ setQuery, onChange, items, onSubmit, cioClient, previousQuery });
59
+ const { isOpen, getMenuProps, getLabelProps, openMenu, closeMenu } = downshift;
60
+ return {
61
+ query,
62
+ sections: activeSectionsWithData,
63
+ isOpen: isOpen && (items === null || items === void 0 ? void 0 : items.length) > 0,
64
+ getMenuProps: () => (Object.assign(Object.assign({}, getMenuProps()), { className: 'cio-results', 'data-testid': 'cio-results' })),
65
+ getLabelProps,
66
+ openMenu,
67
+ closeMenu,
68
+ getItemProps: ({ item, index = 0, sectionIdentifier = 'Products' }) => {
69
+ const indexOffset = (0, utils_1.getIndexOffset)({
70
+ activeSections: activeSectionsWithData,
71
+ sectionIdentifier,
72
+ });
73
+ const sectionItemTestId = `cio-item-${sectionIdentifier.replace(' ', '')}`;
74
+ return Object.assign(Object.assign({}, downshift.getItemProps({ item, index: index + indexOffset })), { className: `cio-item ${sectionItemTestId}`, 'data-testid': sectionItemTestId });
75
+ },
76
+ getInputProps: () => (Object.assign(Object.assign({}, downshift.getInputProps()), { value: query, onFocus: () => {
77
+ var _a;
78
+ if (options.onFocus) {
79
+ options.onFocus();
80
+ }
81
+ if (zeroStateSectionsActive && openOnFocus !== false) {
82
+ downshift.openMenu();
83
+ }
84
+ if (query === null || query === void 0 ? void 0 : query.length) {
85
+ downshift.openMenu();
86
+ }
87
+ (_a = cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker) === null || _a === void 0 ? void 0 : _a.trackInputFocus();
88
+ }, className: 'cio-input', 'data-testid': 'cio-input', placeholder })),
89
+ getFormProps: () => ({
90
+ onSubmit: (event) => {
91
+ event.preventDefault();
92
+ if (onSubmit) {
93
+ onSubmit({ query });
94
+ }
95
+ cioClient === null || cioClient === void 0 ? void 0 : cioClient.tracker.trackSearchSubmit(query, { original_query: query });
96
+ return { query };
97
+ },
98
+ className: 'cio-form',
99
+ 'data-testid': 'cio-form',
100
+ }),
101
+ setQuery,
102
+ cioClient,
103
+ autocompleteClassName,
104
+ };
105
+ };
106
+ exports.default = useCioAutocomplete;
107
+ //# sourceMappingURL=useCioAutocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCioAutocomplete.js","sourceRoot":"","sources":["../../../src/hooks/useCioAutocomplete.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,iDAA+D;AAC/D,iDAA0C;AAC1C,2EAAmE;AAOnE,2EAAoE;AACpE,+CAAwC;AACxC,oCAA0C;AAE7B,QAAA,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,kBAA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MAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,0CAAE,eAAe,EAAE,CAAC;YACxC,CAAC,EACD,SAAS,EAAE,WAAW,EACtB,aAAa,EAAE,WAAW,EAC1B,WAAW,IACX;QACF,YAAY,EAAE,GAAG,EAAE,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,aAAT,SAAS,uBAAT,SAAS,CAAE,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,kBAAe,kBAAkB,CAAC"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ const constructorio_client_javascript_1 = require("@constructor-io/constructorio-client-javascript");
5
+ const useCioClient = ({ apiKey, cioJsClient }) => {
6
+ const [cioClient, setCioClient] = (0, react_1.useState)(cioJsClient);
7
+ (0, react_1.useEffect)(() => {
8
+ if (apiKey && !cioJsClient) {
9
+ const client = new constructorio_client_javascript_1.default({
10
+ apiKey,
11
+ sendTrackingEvents: true,
12
+ });
13
+ setCioClient(client);
14
+ }
15
+ else if (cioJsClient) {
16
+ setCioClient(cioJsClient);
17
+ }
18
+ }, [apiKey, cioJsClient]);
19
+ return cioClient;
20
+ };
21
+ exports.default = useCioClient;
22
+ //# sourceMappingURL=useCioClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCioClient.js","sourceRoot":"","sources":["../../../src/hooks/useCioClient.ts"],"names":[],"mappings":";;AAAA,iCAA4C;AAC5C,qGAAkF;AAuBlF,MAAM,YAAY,GAAiB,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE;IAC7D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAAC,WAAW,CAAC,CAAC;IAExD,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,MAAM,IAAI,CAAC,WAAW,EAAE;YAC1B,MAAM,MAAM,GAAG,IAAI,yCAAmB,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,kBAAe,YAAY,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const react_1 = require("react");
4
+ // adapted from: https://usehooks.com/useDebounce/
5
+ const useDebounce = (value, delay = 250) => {
6
+ // State and setters for debounced value
7
+ const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(value);
8
+ (0, react_1.useEffect)(() => {
9
+ // Update debounced value after delay
10
+ const handler = setTimeout(() => {
11
+ setDebouncedValue(value);
12
+ }, delay);
13
+ // Cancel the timeout if value changes (also on delay change or unmount)
14
+ // This is how we prevent debounced value from updating if value is changed ...
15
+ // .. within the delay period. Timeout gets cleared and restarted.
16
+ return () => {
17
+ clearTimeout(handler);
18
+ };
19
+ }, [value, delay] // Only re-call effect if value or delay changes
20
+ );
21
+ return debouncedValue;
22
+ };
23
+ exports.default = useDebounce;
24
+ //# sourceMappingURL=useDebounce.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDebounce.js","sourceRoot":"","sources":["../../../src/hooks/useDebounce.ts"],"names":[],"mappings":";;AAAA,iCAA4C;AAE5C,kDAAkD;AAClD,MAAM,WAAW,GAAG,CAAC,KAAa,EAAE,KAAK,GAAG,GAAG,EAAE,EAAE;IACjD,wCAAwC;IACxC,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAC5D,IAAA,iBAAS,EACP,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,kBAAe,WAAW,CAAC"}