instantsearch-ui-components 0.15.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/FilterSuggestions.js +108 -0
- package/dist/cjs/components/autocomplete/AutocompleteIndex.js +4 -2
- package/dist/cjs/components/autocomplete/AutocompleteRecentSearch.js +10 -0
- package/dist/cjs/components/autocomplete/AutocompleteSuggestion.js +16 -2
- package/dist/cjs/components/autocomplete/createAutocompletePropGetters.js +22 -8
- package/dist/cjs/components/autocomplete/createAutocompleteStorage.js +15 -2
- package/dist/cjs/components/autocomplete/icons.js +10 -0
- package/dist/cjs/components/chat/Chat.js +12 -2
- package/dist/cjs/components/chat/ChatMessage.js +3 -2
- package/dist/cjs/components/chat/ChatMessages.js +9 -5
- package/dist/cjs/components/chat/ChatPromptSuggestions.js +37 -0
- package/dist/cjs/components/index.js +11 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/components/FilterSuggestions.d.ts +108 -0
- package/dist/es/components/FilterSuggestions.js +101 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.d.ts +2 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.js +4 -2
- package/dist/es/components/autocomplete/AutocompleteRecentSearch.d.ts +5 -0
- package/dist/es/components/autocomplete/AutocompleteRecentSearch.js +11 -1
- package/dist/es/components/autocomplete/AutocompleteSuggestion.d.ts +3 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.js +17 -3
- package/dist/es/components/autocomplete/createAutocompletePropGetters.d.ts +3 -1
- package/dist/es/components/autocomplete/createAutocompletePropGetters.js +22 -8
- package/dist/es/components/autocomplete/createAutocompleteStorage.d.ts +2 -1
- package/dist/es/components/autocomplete/createAutocompleteStorage.js +15 -2
- package/dist/es/components/autocomplete/icons.d.ts +1 -0
- package/dist/es/components/autocomplete/icons.js +9 -0
- package/dist/es/components/chat/Chat.d.ts +7 -0
- package/dist/es/components/chat/Chat.js +12 -2
- package/dist/es/components/chat/ChatMessage.d.ts +5 -1
- package/dist/es/components/chat/ChatMessage.js +3 -2
- package/dist/es/components/chat/ChatMessages.d.ts +5 -1
- package/dist/es/components/chat/ChatMessages.js +9 -5
- package/dist/es/components/chat/ChatPromptSuggestions.d.ts +14 -0
- package/dist/es/components/chat/ChatPromptSuggestions.js +31 -0
- package/dist/es/components/index.d.ts +1 -0
- package/dist/es/components/index.js +2 -1
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createFilterSuggestionsComponent = createFilterSuggestionsComponent;
|
|
8
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
var _lib = require("../lib");
|
|
12
|
+
var _Button = require("./Button");
|
|
13
|
+
var _icons = require("./chat/icons");
|
|
14
|
+
var _excluded = ["classNames", "suggestions", "isLoading", "refine", "skeletonCount", "itemComponent", "headerComponent", "emptyComponent"];
|
|
15
|
+
function createFilterSuggestionsComponent(_ref) {
|
|
16
|
+
var createElement = _ref.createElement;
|
|
17
|
+
var Button = (0, _Button.createButtonComponent)({
|
|
18
|
+
createElement: createElement
|
|
19
|
+
});
|
|
20
|
+
function DefaultHeader(_ref2) {
|
|
21
|
+
var classNames = _ref2.classNames;
|
|
22
|
+
return createElement("div", {
|
|
23
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-header', classNames.header)
|
|
24
|
+
}, createElement("span", {
|
|
25
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-headerIcon', classNames.headerIcon)
|
|
26
|
+
}, createElement(_icons.SparklesIcon, {
|
|
27
|
+
createElement: createElement
|
|
28
|
+
})), createElement("span", {
|
|
29
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-headerTitle', classNames.headerTitle)
|
|
30
|
+
}, "Filter suggestions"));
|
|
31
|
+
}
|
|
32
|
+
function DefaultItem(_ref3) {
|
|
33
|
+
var suggestion = _ref3.suggestion,
|
|
34
|
+
classNames = _ref3.classNames,
|
|
35
|
+
refine = _ref3.refine;
|
|
36
|
+
return createElement(Button, {
|
|
37
|
+
variant: "outline",
|
|
38
|
+
size: "sm",
|
|
39
|
+
className: (0, _lib.cx)(classNames.button),
|
|
40
|
+
onClick: refine
|
|
41
|
+
}, createElement("span", {
|
|
42
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-label', classNames.label)
|
|
43
|
+
}, suggestion.label, ": ", suggestion.value), createElement("span", {
|
|
44
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-count', classNames.count)
|
|
45
|
+
}, suggestion.count));
|
|
46
|
+
}
|
|
47
|
+
return function FilterSuggestions(userProps) {
|
|
48
|
+
var _userProps$classNames = userProps.classNames,
|
|
49
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
50
|
+
suggestions = userProps.suggestions,
|
|
51
|
+
isLoading = userProps.isLoading,
|
|
52
|
+
_refine = userProps.refine,
|
|
53
|
+
_userProps$skeletonCo = userProps.skeletonCount,
|
|
54
|
+
skeletonCount = _userProps$skeletonCo === void 0 ? 3 : _userProps$skeletonCo,
|
|
55
|
+
_userProps$itemCompon = userProps.itemComponent,
|
|
56
|
+
ItemComponent = _userProps$itemCompon === void 0 ? DefaultItem : _userProps$itemCompon,
|
|
57
|
+
headerComponent = userProps.headerComponent,
|
|
58
|
+
EmptyComponent = userProps.emptyComponent,
|
|
59
|
+
props = (0, _objectWithoutProperties2.default)(userProps, _excluded);
|
|
60
|
+
var HeaderComponent = headerComponent === false ? null : headerComponent !== null && headerComponent !== void 0 ? headerComponent : DefaultHeader;
|
|
61
|
+
var isEmpty = suggestions.length === 0;
|
|
62
|
+
if (isEmpty && !isLoading) {
|
|
63
|
+
return createElement("div", (0, _extends2.default)({}, props, {
|
|
64
|
+
className: (0, _lib.cx)('ais-FilterSuggestions', classNames.root, 'ais-FilterSuggestions--empty', classNames.emptyRoot, props.className)
|
|
65
|
+
}), EmptyComponent && createElement(EmptyComponent, {
|
|
66
|
+
classNames: {
|
|
67
|
+
emptyRoot: classNames.emptyRoot
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
var headerClassNames = {
|
|
72
|
+
header: classNames.header,
|
|
73
|
+
headerIcon: classNames.headerIcon,
|
|
74
|
+
headerTitle: classNames.headerTitle
|
|
75
|
+
};
|
|
76
|
+
var itemClassNames = {
|
|
77
|
+
item: classNames.item,
|
|
78
|
+
button: classNames.button,
|
|
79
|
+
label: classNames.label,
|
|
80
|
+
count: classNames.count
|
|
81
|
+
};
|
|
82
|
+
return createElement("div", (0, _extends2.default)({}, props, {
|
|
83
|
+
className: (0, _lib.cx)('ais-FilterSuggestions', classNames.root, isLoading && (0, _lib.cx)('ais-FilterSuggestions--loading', classNames.loadingRoot), props.className)
|
|
84
|
+
}), HeaderComponent && createElement(HeaderComponent, {
|
|
85
|
+
classNames: headerClassNames
|
|
86
|
+
}), isLoading ? createElement("div", {
|
|
87
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-skeleton', classNames.skeleton)
|
|
88
|
+
}, (0, _toConsumableArray2.default)(new Array(skeletonCount)).map(function (_, i) {
|
|
89
|
+
return createElement("div", {
|
|
90
|
+
key: i,
|
|
91
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-skeletonItem', classNames.skeletonItem)
|
|
92
|
+
});
|
|
93
|
+
})) : createElement("ul", {
|
|
94
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-list', classNames.list)
|
|
95
|
+
}, suggestions.map(function (suggestion) {
|
|
96
|
+
return createElement("li", {
|
|
97
|
+
key: "".concat(suggestion.attribute, "-").concat(suggestion.value),
|
|
98
|
+
className: (0, _lib.cx)('ais-FilterSuggestions-item', classNames.item)
|
|
99
|
+
}, createElement(ItemComponent, {
|
|
100
|
+
suggestion: suggestion,
|
|
101
|
+
classNames: itemClassNames,
|
|
102
|
+
refine: function refine() {
|
|
103
|
+
return _refine(suggestion.attribute, suggestion.value);
|
|
104
|
+
}
|
|
105
|
+
}));
|
|
106
|
+
})));
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -8,7 +8,7 @@ exports.createAutocompleteIndexComponent = createAutocompleteIndexComponent;
|
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
10
10
|
var _cx = require("../../lib/cx");
|
|
11
|
-
var _excluded = ["className", "onSelect"];
|
|
11
|
+
var _excluded = ["className", "onSelect", "onApply"];
|
|
12
12
|
function createAutocompleteIndexComponent(_ref) {
|
|
13
13
|
var createElement = _ref.createElement;
|
|
14
14
|
return function AutocompleteIndex(userProps) {
|
|
@@ -30,6 +30,7 @@ function createAutocompleteIndexComponent(_ref) {
|
|
|
30
30
|
var _getItemProps = getItemProps(item, index),
|
|
31
31
|
className = _getItemProps.className,
|
|
32
32
|
onSelect = _getItemProps.onSelect,
|
|
33
|
+
onApply = _getItemProps.onApply,
|
|
33
34
|
itemProps = (0, _objectWithoutProperties2.default)(_getItemProps, _excluded);
|
|
34
35
|
return createElement("li", (0, _extends2.default)({
|
|
35
36
|
key: "".concat(itemProps.id, ":").concat(item.objectID)
|
|
@@ -37,7 +38,8 @@ function createAutocompleteIndexComponent(_ref) {
|
|
|
37
38
|
className: (0, _cx.cx)('ais-AutocompleteIndexItem', classNames.item, className)
|
|
38
39
|
}), createElement(ItemComponent, {
|
|
39
40
|
item: item,
|
|
40
|
-
onSelect: onSelect
|
|
41
|
+
onSelect: onSelect,
|
|
42
|
+
onApply: onApply
|
|
41
43
|
}));
|
|
42
44
|
})));
|
|
43
45
|
};
|
|
@@ -13,6 +13,7 @@ function createAutocompleteRecentSearchComponent(_ref) {
|
|
|
13
13
|
children = userProps.children,
|
|
14
14
|
onSelect = userProps.onSelect,
|
|
15
15
|
onRemoveRecentSearch = userProps.onRemoveRecentSearch,
|
|
16
|
+
onApply = userProps.onApply,
|
|
16
17
|
_userProps$classNames = userProps.classNames,
|
|
17
18
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
18
19
|
return createElement("div", {
|
|
@@ -37,6 +38,15 @@ function createAutocompleteRecentSearchComponent(_ref) {
|
|
|
37
38
|
}
|
|
38
39
|
}, createElement(_icons.TrashIcon, {
|
|
39
40
|
createElement: createElement
|
|
41
|
+
})), createElement("button", {
|
|
42
|
+
className: (0, _lib.cx)('ais-AutocompleteItemActionButton', 'ais-AutocompleteRecentSearchItemApplyButton', classNames.applyButton),
|
|
43
|
+
title: "Apply ".concat(item.query, " as search"),
|
|
44
|
+
onClick: function onClick(evt) {
|
|
45
|
+
evt.stopPropagation();
|
|
46
|
+
onApply();
|
|
47
|
+
}
|
|
48
|
+
}, createElement(_icons.ApplyIcon, {
|
|
49
|
+
createElement: createElement
|
|
40
50
|
}))));
|
|
41
51
|
};
|
|
42
52
|
}
|
|
@@ -9,8 +9,10 @@ var _icons = require("./icons");
|
|
|
9
9
|
function createAutocompleteSuggestionComponent(_ref) {
|
|
10
10
|
var createElement = _ref.createElement;
|
|
11
11
|
return function AutocompleteSuggestion(userProps) {
|
|
12
|
-
var
|
|
12
|
+
var item = userProps.item,
|
|
13
|
+
children = userProps.children,
|
|
13
14
|
onSelect = userProps.onSelect,
|
|
15
|
+
onApply = userProps.onApply,
|
|
14
16
|
_userProps$classNames = userProps.classNames,
|
|
15
17
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
16
18
|
return createElement("div", {
|
|
@@ -24,6 +26,18 @@ function createAutocompleteSuggestionComponent(_ref) {
|
|
|
24
26
|
createElement: createElement
|
|
25
27
|
})), createElement("div", {
|
|
26
28
|
className: (0, _lib.cx)('ais-AutocompleteItemContentBody', 'ais-AutocompleteSuggestionItemContentBody', classNames.content)
|
|
27
|
-
}, children))
|
|
29
|
+
}, children)), createElement("div", {
|
|
30
|
+
className: (0, _lib.cx)('ais-AutocompleteItemActions', 'ais-AutocompleteSuggestionItemActions', classNames.actions)
|
|
31
|
+
}, createElement("button", {
|
|
32
|
+
className: (0, _lib.cx)('ais-AutocompleteItemActionButton', 'ais-AutocompleteSuggestionItemApplyButton', classNames.applyButton),
|
|
33
|
+
type: "button",
|
|
34
|
+
title: "Apply ".concat(item.query, " as search"),
|
|
35
|
+
onClick: function onClick(evt) {
|
|
36
|
+
evt.stopPropagation();
|
|
37
|
+
onApply();
|
|
38
|
+
}
|
|
39
|
+
}, createElement(_icons.ApplyIcon, {
|
|
40
|
+
createElement: createElement
|
|
41
|
+
}))));
|
|
28
42
|
};
|
|
29
43
|
}
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.createAutocompletePropGetters = createAutocompletePropGetters;
|
|
8
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _lib = require("../../lib");
|
|
10
11
|
function createAutocompletePropGetters(_ref) {
|
|
11
12
|
var useEffect = _ref.useEffect,
|
|
12
13
|
useId = _ref.useId,
|
|
@@ -18,6 +19,7 @@ function createAutocompletePropGetters(_ref) {
|
|
|
18
19
|
indicesConfig = _ref2.indicesConfig,
|
|
19
20
|
onRefine = _ref2.onRefine,
|
|
20
21
|
globalOnSelect = _ref2.onSelect,
|
|
22
|
+
_onApply = _ref2.onApply,
|
|
21
23
|
placeholder = _ref2.placeholder;
|
|
22
24
|
var getElementId = createGetElementId(useId());
|
|
23
25
|
var inputRef = useRef(null);
|
|
@@ -185,6 +187,13 @@ function createAutocompletePropGetters(_ref) {
|
|
|
185
187
|
return submit({
|
|
186
188
|
activeDescendant: id
|
|
187
189
|
});
|
|
190
|
+
},
|
|
191
|
+
onApply: function onApply() {
|
|
192
|
+
var _getQuery2;
|
|
193
|
+
var _ref4 = items.get(id),
|
|
194
|
+
currentItem = _ref4.item,
|
|
195
|
+
getQuery = _ref4.config.getQuery;
|
|
196
|
+
_onApply((_getQuery2 = getQuery === null || getQuery === void 0 ? void 0 : getQuery(currentItem)) !== null && _getQuery2 !== void 0 ? _getQuery2 : '');
|
|
188
197
|
}
|
|
189
198
|
};
|
|
190
199
|
},
|
|
@@ -204,24 +213,29 @@ function createAutocompletePropGetters(_ref) {
|
|
|
204
213
|
};
|
|
205
214
|
};
|
|
206
215
|
}
|
|
207
|
-
function buildItems(
|
|
208
|
-
var indices =
|
|
209
|
-
indicesConfig =
|
|
210
|
-
getElementId =
|
|
216
|
+
function buildItems(_ref5) {
|
|
217
|
+
var indices = _ref5.indices,
|
|
218
|
+
indicesConfig = _ref5.indicesConfig,
|
|
219
|
+
getElementId = _ref5.getElementId;
|
|
211
220
|
var itemsIds = [];
|
|
212
221
|
var items = new Map();
|
|
213
|
-
|
|
222
|
+
var _loop = function _loop(i) {
|
|
214
223
|
var _indices$i;
|
|
215
|
-
var
|
|
224
|
+
var currentIndexConfig = (0, _lib.find)(indicesConfig, function (config) {
|
|
225
|
+
return config.indexName === indices[i].indexName;
|
|
226
|
+
});
|
|
216
227
|
var hits = ((_indices$i = indices[i]) === null || _indices$i === void 0 ? void 0 : _indices$i.hits) || [];
|
|
217
228
|
for (var position = 0; position < hits.length; position++) {
|
|
218
|
-
var itemId = getElementId('item',
|
|
229
|
+
var itemId = getElementId('item', (currentIndexConfig === null || currentIndexConfig === void 0 ? void 0 : currentIndexConfig.indexName) || indices[i].indexName, position);
|
|
219
230
|
items.set(itemId, {
|
|
220
231
|
item: hits[position],
|
|
221
|
-
config:
|
|
232
|
+
config: currentIndexConfig
|
|
222
233
|
});
|
|
223
234
|
itemsIds.push(itemId);
|
|
224
235
|
}
|
|
236
|
+
};
|
|
237
|
+
for (var i = 0; i < indices.length; i++) {
|
|
238
|
+
_loop(i);
|
|
225
239
|
}
|
|
226
240
|
return {
|
|
227
241
|
items: items,
|
|
@@ -6,9 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.createAutocompleteStorage = createAutocompleteStorage;
|
|
8
8
|
exports.createStorage = createStorage;
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
11
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
12
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
+
var _lib = require("../../lib");
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
16
|
function createAutocompleteStorage(_ref) {
|
|
13
17
|
var useEffect = _ref.useEffect,
|
|
14
18
|
useMemo = _ref.useMemo,
|
|
@@ -17,7 +21,8 @@ function createAutocompleteStorage(_ref) {
|
|
|
17
21
|
var showRecent = _ref2.showRecent,
|
|
18
22
|
query = _ref2.query,
|
|
19
23
|
indices = _ref2.indices,
|
|
20
|
-
indicesConfig = _ref2.indicesConfig
|
|
24
|
+
indicesConfig = _ref2.indicesConfig,
|
|
25
|
+
suggestionsIndexName = _ref2.suggestionsIndexName;
|
|
21
26
|
var storageKey = showRecent && (0, _typeof2.default)(showRecent) === 'object' ? showRecent.storageKey : undefined;
|
|
22
27
|
var storage = useMemo(function () {
|
|
23
28
|
return createStorage({
|
|
@@ -61,7 +66,15 @@ function createAutocompleteStorage(_ref) {
|
|
|
61
66
|
})
|
|
62
67
|
};
|
|
63
68
|
});
|
|
64
|
-
var indicesForPropGetters = (0, _toConsumableArray2.default)(indices)
|
|
69
|
+
var indicesForPropGetters = (0, _toConsumableArray2.default)(indices.map(function (index) {
|
|
70
|
+
return index.indexName === suggestionsIndexName ? _objectSpread(_objectSpread({}, index), {}, {
|
|
71
|
+
hits: index.hits.filter(function (hit) {
|
|
72
|
+
return !(0, _lib.find)(storageHits, function (storageHit) {
|
|
73
|
+
return storageHit.query === hit.query;
|
|
74
|
+
});
|
|
75
|
+
})
|
|
76
|
+
}) : index;
|
|
77
|
+
}));
|
|
65
78
|
var indicesConfigForPropGetters = (0, _toConsumableArray2.default)(indicesConfig);
|
|
66
79
|
indicesForPropGetters.unshift({
|
|
67
80
|
indexName: 'recent-searches',
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.ApplyIcon = ApplyIcon;
|
|
6
7
|
exports.ClearIcon = ClearIcon;
|
|
7
8
|
exports.ClockIcon = ClockIcon;
|
|
8
9
|
exports.LoadingIcon = LoadingIcon;
|
|
@@ -67,4 +68,13 @@ function TrashIcon(_ref5) {
|
|
|
67
68
|
}, createElement("path", {
|
|
68
69
|
d: "M18 7v13c0 0.276-0.111 0.525-0.293 0.707s-0.431 0.293-0.707 0.293h-10c-0.276 0-0.525-0.111-0.707-0.293s-0.293-0.431-0.293-0.707v-13zM17 5v-1c0-0.828-0.337-1.58-0.879-2.121s-1.293-0.879-2.121-0.879h-4c-0.828 0-1.58 0.337-2.121 0.879s-0.879 1.293-0.879 2.121v1h-4c-0.552 0-1 0.448-1 1s0.448 1 1 1h1v13c0 0.828 0.337 1.58 0.879 2.121s1.293 0.879 2.121 0.879h10c0.828 0 1.58-0.337 2.121-0.879s0.879-1.293 0.879-2.121v-13h1c0.552 0 1-0.448 1-1s-0.448-1-1-1zM9 5v-1c0-0.276 0.111-0.525 0.293-0.707s0.431-0.293 0.707-0.293h4c0.276 0 0.525 0.111 0.707 0.293s0.293 0.431 0.293 0.707v1zM9 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1zM13 11v6c0 0.552 0.448 1 1 1s1-0.448 1-1v-6c0-0.552-0.448-1-1-1s-1 0.448-1 1z"
|
|
69
70
|
}));
|
|
71
|
+
}
|
|
72
|
+
function ApplyIcon(_ref6) {
|
|
73
|
+
var createElement = _ref6.createElement;
|
|
74
|
+
return createElement("svg", {
|
|
75
|
+
viewBox: "0 0 24 24",
|
|
76
|
+
fill: "currentColor"
|
|
77
|
+
}, createElement("path", {
|
|
78
|
+
d: "M8 17v-7.586l8.293 8.293c0.391 0.391 1.024 0.391 1.414 0s0.391-1.024 0-1.414l-8.293-8.293h7.586c0.552 0 1-0.448 1-1s-0.448-1-1-1h-10c-0.552 0-1 0.448-1 1v10c0 0.552 0.448 1 1 1s1-0.448 1-1z"
|
|
79
|
+
}));
|
|
70
80
|
}
|
|
@@ -12,8 +12,9 @@ var _lib = require("../../lib");
|
|
|
12
12
|
var _ChatHeader = require("./ChatHeader");
|
|
13
13
|
var _ChatMessages = require("./ChatMessages");
|
|
14
14
|
var _ChatPrompt = require("./ChatPrompt");
|
|
15
|
+
var _ChatPromptSuggestions = require("./ChatPromptSuggestions");
|
|
15
16
|
var _ChatToggleButton = require("./ChatToggleButton");
|
|
16
|
-
var _excluded = ["open", "maximized", "headerProps", "toggleButtonProps", "messagesProps", "promptProps", "headerComponent", "promptComponent", "toggleButtonComponent", "classNames", "className"];
|
|
17
|
+
var _excluded = ["open", "maximized", "headerProps", "toggleButtonProps", "messagesProps", "suggestionsProps", "promptProps", "headerComponent", "promptComponent", "toggleButtonComponent", "suggestionsComponent", "classNames", "className"];
|
|
17
18
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
18
19
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
20
|
function createChatComponent(_ref) {
|
|
@@ -35,6 +36,10 @@ function createChatComponent(_ref) {
|
|
|
35
36
|
createElement: createElement,
|
|
36
37
|
Fragment: Fragment
|
|
37
38
|
});
|
|
39
|
+
var ChatPromptSuggestions = (0, _ChatPromptSuggestions.createChatPromptSuggestionsComponent)({
|
|
40
|
+
createElement: createElement,
|
|
41
|
+
Fragment: Fragment
|
|
42
|
+
});
|
|
38
43
|
return function Chat(userProps) {
|
|
39
44
|
var open = userProps.open,
|
|
40
45
|
_userProps$maximized = userProps.maximized,
|
|
@@ -42,11 +47,13 @@ function createChatComponent(_ref) {
|
|
|
42
47
|
headerProps = userProps.headerProps,
|
|
43
48
|
toggleButtonProps = userProps.toggleButtonProps,
|
|
44
49
|
messagesProps = userProps.messagesProps,
|
|
50
|
+
suggestionsProps = userProps.suggestionsProps,
|
|
45
51
|
_userProps$promptProp = userProps.promptProps,
|
|
46
52
|
promptProps = _userProps$promptProp === void 0 ? {} : _userProps$promptProp,
|
|
47
53
|
HeaderComponent = userProps.headerComponent,
|
|
48
54
|
PromptComponent = userProps.promptComponent,
|
|
49
55
|
ToggleButtonComponent = userProps.toggleButtonComponent,
|
|
56
|
+
SuggestionsComponent = userProps.suggestionsComponent,
|
|
50
57
|
_userProps$classNames = userProps.classNames,
|
|
51
58
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
52
59
|
className = userProps.className,
|
|
@@ -60,7 +67,10 @@ function createChatComponent(_ref) {
|
|
|
60
67
|
maximized: maximized
|
|
61
68
|
})), createElement(ChatMessages, (0, _extends2.default)({}, messagesProps, {
|
|
62
69
|
classNames: classNames.messages,
|
|
63
|
-
messageClassNames: classNames.message
|
|
70
|
+
messageClassNames: classNames.message,
|
|
71
|
+
suggestionsElement: createElement(SuggestionsComponent || ChatPromptSuggestions, _objectSpread(_objectSpread({}, suggestionsProps), {}, {
|
|
72
|
+
classNames: classNames.suggestions
|
|
73
|
+
}))
|
|
64
74
|
})), createElement(PromptComponent || ChatPrompt, _objectSpread(_objectSpread({}, promptProps), {}, {
|
|
65
75
|
classNames: classNames.prompt
|
|
66
76
|
}))), createElement("div", {
|
|
@@ -12,7 +12,7 @@ var _markdownToJsx = require("markdown-to-jsx");
|
|
|
12
12
|
var _lib = require("../../lib");
|
|
13
13
|
var _Button = require("../Button");
|
|
14
14
|
var _icons = require("./icons");
|
|
15
|
-
var _excluded = ["classNames", "message", "side", "variant", "actions", "autoHideActions", "leadingComponent", "actionsComponent", "footerComponent", "tools", "indexUiState", "setIndexUiState", "onClose", "translations"];
|
|
15
|
+
var _excluded = ["classNames", "message", "side", "variant", "actions", "autoHideActions", "leadingComponent", "actionsComponent", "footerComponent", "tools", "indexUiState", "setIndexUiState", "onClose", "translations", "suggestionsElement"];
|
|
16
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
17
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
18
18
|
function createChatMessageComponent(_ref) {
|
|
@@ -41,6 +41,7 @@ function createChatMessageComponent(_ref) {
|
|
|
41
41
|
setIndexUiState = userProps.setIndexUiState,
|
|
42
42
|
onClose = userProps.onClose,
|
|
43
43
|
userTranslations = userProps.translations,
|
|
44
|
+
suggestionsElement = userProps.suggestionsElement,
|
|
44
45
|
props = (0, _objectWithoutProperties2.default)(userProps, _excluded);
|
|
45
46
|
var translations = _objectSpread({
|
|
46
47
|
messageLabel: 'Message',
|
|
@@ -112,7 +113,7 @@ function createChatMessageComponent(_ref) {
|
|
|
112
113
|
className: (0, _lib.cx)(cssClasses.content)
|
|
113
114
|
}, createElement("div", {
|
|
114
115
|
className: (0, _lib.cx)(cssClasses.message)
|
|
115
|
-
}, message.parts.map(renderMessagePart)), hasActions && createElement("div", {
|
|
116
|
+
}, message.parts.map(renderMessagePart)), suggestionsElement, hasActions && createElement("div", {
|
|
116
117
|
className: (0, _lib.cx)(cssClasses.actions),
|
|
117
118
|
"aria-label": translations.actionsLabel
|
|
118
119
|
}, ActionsComponent ? createElement(ActionsComponent, {
|
|
@@ -15,7 +15,7 @@ var _ChatMessage = require("./ChatMessage");
|
|
|
15
15
|
var _ChatMessageError = require("./ChatMessageError");
|
|
16
16
|
var _ChatMessageLoader = require("./ChatMessageLoader");
|
|
17
17
|
var _icons = require("./icons");
|
|
18
|
-
var _excluded = ["classNames", "messageClassNames", "messageTranslations", "messages", "messageComponent", "loaderComponent", "errorComponent", "actionsComponent", "tools", "indexUiState", "setIndexUiState", "status", "hideScrollToBottom", "onReload", "onClose", "translations", "userMessageProps", "assistantMessageProps", "isClearing", "onClearTransitionEnd", "isScrollAtBottom", "scrollRef", "contentRef", "onScrollToBottom"];
|
|
18
|
+
var _excluded = ["classNames", "messageClassNames", "messageTranslations", "messages", "messageComponent", "loaderComponent", "errorComponent", "actionsComponent", "tools", "indexUiState", "setIndexUiState", "status", "hideScrollToBottom", "onReload", "onClose", "translations", "userMessageProps", "assistantMessageProps", "isClearing", "onClearTransitionEnd", "isScrollAtBottom", "scrollRef", "contentRef", "onScrollToBottom", "suggestionsElement"];
|
|
19
19
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
20
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
21
|
var getTextContent = function getTextContent(message) {
|
|
@@ -48,7 +48,8 @@ function createDefaultMessageComponent(_ref) {
|
|
|
48
48
|
actionsComponent = _ref2.actionsComponent,
|
|
49
49
|
classNames = _ref2.classNames,
|
|
50
50
|
messageTranslations = _ref2.messageTranslations,
|
|
51
|
-
translations = _ref2.translations
|
|
51
|
+
translations = _ref2.translations,
|
|
52
|
+
suggestionsElement = _ref2.suggestionsElement;
|
|
52
53
|
var defaultAssistantActions = [].concat((0, _toConsumableArray2.default)(hasTextContent(message) ? [{
|
|
53
54
|
title: translations.copyToClipboardLabel,
|
|
54
55
|
icon: function icon() {
|
|
@@ -82,7 +83,8 @@ function createDefaultMessageComponent(_ref) {
|
|
|
82
83
|
actionsComponent: actionsComponent,
|
|
83
84
|
"data-role": message.role,
|
|
84
85
|
classNames: classNames,
|
|
85
|
-
translations: messageTranslations
|
|
86
|
+
translations: messageTranslations,
|
|
87
|
+
suggestionsElement: suggestionsElement
|
|
86
88
|
}, messageProps));
|
|
87
89
|
};
|
|
88
90
|
}
|
|
@@ -133,6 +135,7 @@ function createChatMessagesComponent(_ref3) {
|
|
|
133
135
|
scrollRef = userProps.scrollRef,
|
|
134
136
|
contentRef = userProps.contentRef,
|
|
135
137
|
onScrollToBottom = userProps.onScrollToBottom,
|
|
138
|
+
suggestionsElement = userProps.suggestionsElement,
|
|
136
139
|
props = (0, _objectWithoutProperties2.default)(userProps, _excluded);
|
|
137
140
|
var translations = _objectSpread({
|
|
138
141
|
scrollToBottomLabel: 'Scroll to bottom',
|
|
@@ -164,7 +167,7 @@ function createChatMessagesComponent(_ref3) {
|
|
|
164
167
|
onClearTransitionEnd === null || onClearTransitionEnd === void 0 ? void 0 : onClearTransitionEnd();
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
|
-
}, messages.map(function (message) {
|
|
170
|
+
}, messages.map(function (message, index) {
|
|
168
171
|
return createElement(DefaultMessage, {
|
|
169
172
|
key: message.id,
|
|
170
173
|
message: message,
|
|
@@ -178,7 +181,8 @@ function createChatMessagesComponent(_ref3) {
|
|
|
178
181
|
onClose: onClose,
|
|
179
182
|
translations: translations,
|
|
180
183
|
classNames: messageClassNames,
|
|
181
|
-
messageTranslations: messageTranslations
|
|
184
|
+
messageTranslations: messageTranslations,
|
|
185
|
+
suggestionsElement: status === 'ready' && message.role === 'assistant' && index === messages.length - 1 ? suggestionsElement : undefined
|
|
182
186
|
});
|
|
183
187
|
}), status === 'submitted' && createElement(DefaultLoader, {
|
|
184
188
|
translations: {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createChatPromptSuggestionsComponent = createChatPromptSuggestionsComponent;
|
|
7
|
+
var _lib = require("../../lib");
|
|
8
|
+
var _Button = require("../Button");
|
|
9
|
+
function createChatPromptSuggestionsComponent(_ref) {
|
|
10
|
+
var createElement = _ref.createElement;
|
|
11
|
+
var Button = (0, _Button.createButtonComponent)({
|
|
12
|
+
createElement: createElement
|
|
13
|
+
});
|
|
14
|
+
return function ChatPromptSuggestions(userProps) {
|
|
15
|
+
var _userProps$suggestion = userProps.suggestions,
|
|
16
|
+
suggestions = _userProps$suggestion === void 0 ? [] : _userProps$suggestion,
|
|
17
|
+
onSuggestionClick = userProps.onSuggestionClick,
|
|
18
|
+
_userProps$classNames = userProps.classNames,
|
|
19
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
20
|
+
if (suggestions.length === 0) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
return createElement("div", {
|
|
24
|
+
className: (0, _lib.cx)('ais-ChatPromptSuggestions', classNames.root)
|
|
25
|
+
}, suggestions.map(function (suggestion, index) {
|
|
26
|
+
return createElement(Button, {
|
|
27
|
+
key: index,
|
|
28
|
+
size: "sm",
|
|
29
|
+
variant: "primary",
|
|
30
|
+
className: (0, _lib.cx)('ais-ChatPromptSuggestions-suggestion', classNames.suggestion),
|
|
31
|
+
onClick: function onClick() {
|
|
32
|
+
return onSuggestionClick(suggestion);
|
|
33
|
+
}
|
|
34
|
+
}, suggestion);
|
|
35
|
+
}));
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -211,4 +211,15 @@ Object.keys(_TrendingItems).forEach(function (key) {
|
|
|
211
211
|
return _TrendingItems[key];
|
|
212
212
|
}
|
|
213
213
|
});
|
|
214
|
+
});
|
|
215
|
+
var _FilterSuggestions = require("./FilterSuggestions");
|
|
216
|
+
Object.keys(_FilterSuggestions).forEach(function (key) {
|
|
217
|
+
if (key === "default" || key === "__esModule") return;
|
|
218
|
+
if (key in exports && exports[key] === _FilterSuggestions[key]) return;
|
|
219
|
+
Object.defineProperty(exports, key, {
|
|
220
|
+
enumerable: true,
|
|
221
|
+
get: function get() {
|
|
222
|
+
return _FilterSuggestions[key];
|
|
223
|
+
}
|
|
224
|
+
});
|
|
214
225
|
});
|
package/dist/cjs/version.js
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ComponentProps, Renderer } from '../types';
|
|
2
|
+
export type Suggestion = {
|
|
3
|
+
/**
|
|
4
|
+
* The facet attribute name.
|
|
5
|
+
*/
|
|
6
|
+
attribute: string;
|
|
7
|
+
/**
|
|
8
|
+
* The facet value to filter by.
|
|
9
|
+
*/
|
|
10
|
+
value: string;
|
|
11
|
+
/**
|
|
12
|
+
* Human-readable display label.
|
|
13
|
+
*/
|
|
14
|
+
label: string;
|
|
15
|
+
/**
|
|
16
|
+
* Number of records matching this filter.
|
|
17
|
+
*/
|
|
18
|
+
count: number;
|
|
19
|
+
};
|
|
20
|
+
export type FilterSuggestionsItemComponentProps = {
|
|
21
|
+
suggestion: Suggestion;
|
|
22
|
+
classNames: Partial<Pick<FilterSuggestionsClassNames, 'item' | 'button' | 'label' | 'count'>>;
|
|
23
|
+
refine: () => void;
|
|
24
|
+
};
|
|
25
|
+
export type FilterSuggestionsHeaderComponentProps = {
|
|
26
|
+
classNames: Partial<Pick<FilterSuggestionsClassNames, 'header' | 'headerIcon' | 'headerTitle'>>;
|
|
27
|
+
};
|
|
28
|
+
export type FilterSuggestionsEmptyComponentProps = {
|
|
29
|
+
classNames: Partial<Pick<FilterSuggestionsClassNames, 'emptyRoot'>>;
|
|
30
|
+
};
|
|
31
|
+
export type FilterSuggestionsProps = ComponentProps<'div'> & {
|
|
32
|
+
suggestions: Suggestion[];
|
|
33
|
+
isLoading: boolean;
|
|
34
|
+
refine: (attribute: string, value: string) => void;
|
|
35
|
+
classNames?: Partial<FilterSuggestionsClassNames>;
|
|
36
|
+
/**
|
|
37
|
+
* Number of skeleton items to show when loading.
|
|
38
|
+
* @default 3
|
|
39
|
+
*/
|
|
40
|
+
skeletonCount?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Component to render each suggestion item.
|
|
43
|
+
*/
|
|
44
|
+
itemComponent?: (props: FilterSuggestionsItemComponentProps) => JSX.Element;
|
|
45
|
+
/**
|
|
46
|
+
* Component to render the header. Set to `false` to disable the header.
|
|
47
|
+
*/
|
|
48
|
+
headerComponent?: ((props: FilterSuggestionsHeaderComponentProps) => JSX.Element) | false;
|
|
49
|
+
/**
|
|
50
|
+
* Component to render when there are no suggestions.
|
|
51
|
+
*/
|
|
52
|
+
emptyComponent?: (props: FilterSuggestionsEmptyComponentProps) => JSX.Element | null;
|
|
53
|
+
};
|
|
54
|
+
export type FilterSuggestionsClassNames = {
|
|
55
|
+
/**
|
|
56
|
+
* Class names to apply to the root element
|
|
57
|
+
*/
|
|
58
|
+
root: string | string[];
|
|
59
|
+
/**
|
|
60
|
+
* Class names to apply to the root element when loading
|
|
61
|
+
*/
|
|
62
|
+
loadingRoot: string | string[];
|
|
63
|
+
/**
|
|
64
|
+
* Class names to apply to the root element when empty
|
|
65
|
+
*/
|
|
66
|
+
emptyRoot: string | string[];
|
|
67
|
+
/**
|
|
68
|
+
* Class names to apply to the header element
|
|
69
|
+
*/
|
|
70
|
+
header: string | string[];
|
|
71
|
+
/**
|
|
72
|
+
* Class names to apply to the header icon element
|
|
73
|
+
*/
|
|
74
|
+
headerIcon: string | string[];
|
|
75
|
+
/**
|
|
76
|
+
* Class names to apply to the header title element
|
|
77
|
+
*/
|
|
78
|
+
headerTitle: string | string[];
|
|
79
|
+
/**
|
|
80
|
+
* Class names to apply to the skeleton container element
|
|
81
|
+
*/
|
|
82
|
+
skeleton: string | string[];
|
|
83
|
+
/**
|
|
84
|
+
* Class names to apply to each skeleton item element
|
|
85
|
+
*/
|
|
86
|
+
skeletonItem: string | string[];
|
|
87
|
+
/**
|
|
88
|
+
* Class names to apply to the list element
|
|
89
|
+
*/
|
|
90
|
+
list: string | string[];
|
|
91
|
+
/**
|
|
92
|
+
* Class names to apply to each item element
|
|
93
|
+
*/
|
|
94
|
+
item: string | string[];
|
|
95
|
+
/**
|
|
96
|
+
* Class names to apply to the button element
|
|
97
|
+
*/
|
|
98
|
+
button: string | string[];
|
|
99
|
+
/**
|
|
100
|
+
* Class names to apply to the label element
|
|
101
|
+
*/
|
|
102
|
+
label: string | string[];
|
|
103
|
+
/**
|
|
104
|
+
* Class names to apply to the count element
|
|
105
|
+
*/
|
|
106
|
+
count: string | string[];
|
|
107
|
+
};
|
|
108
|
+
export declare function createFilterSuggestionsComponent({ createElement }: Renderer): (userProps: FilterSuggestionsProps) => JSX.Element | null;
|