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,101 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["classNames", "suggestions", "isLoading", "refine", "skeletonCount", "itemComponent", "headerComponent", "emptyComponent"];
|
|
5
|
+
import { cx } from "../lib/index.js";
|
|
6
|
+
import { createButtonComponent } from "./Button.js";
|
|
7
|
+
import { SparklesIcon } from "./chat/icons.js";
|
|
8
|
+
export function createFilterSuggestionsComponent(_ref) {
|
|
9
|
+
var createElement = _ref.createElement;
|
|
10
|
+
var Button = createButtonComponent({
|
|
11
|
+
createElement: createElement
|
|
12
|
+
});
|
|
13
|
+
function DefaultHeader(_ref2) {
|
|
14
|
+
var classNames = _ref2.classNames;
|
|
15
|
+
return createElement("div", {
|
|
16
|
+
className: cx('ais-FilterSuggestions-header', classNames.header)
|
|
17
|
+
}, createElement("span", {
|
|
18
|
+
className: cx('ais-FilterSuggestions-headerIcon', classNames.headerIcon)
|
|
19
|
+
}, createElement(SparklesIcon, {
|
|
20
|
+
createElement: createElement
|
|
21
|
+
})), createElement("span", {
|
|
22
|
+
className: cx('ais-FilterSuggestions-headerTitle', classNames.headerTitle)
|
|
23
|
+
}, "Filter suggestions"));
|
|
24
|
+
}
|
|
25
|
+
function DefaultItem(_ref3) {
|
|
26
|
+
var suggestion = _ref3.suggestion,
|
|
27
|
+
classNames = _ref3.classNames,
|
|
28
|
+
refine = _ref3.refine;
|
|
29
|
+
return createElement(Button, {
|
|
30
|
+
variant: "outline",
|
|
31
|
+
size: "sm",
|
|
32
|
+
className: cx(classNames.button),
|
|
33
|
+
onClick: refine
|
|
34
|
+
}, createElement("span", {
|
|
35
|
+
className: cx('ais-FilterSuggestions-label', classNames.label)
|
|
36
|
+
}, suggestion.label, ": ", suggestion.value), createElement("span", {
|
|
37
|
+
className: cx('ais-FilterSuggestions-count', classNames.count)
|
|
38
|
+
}, suggestion.count));
|
|
39
|
+
}
|
|
40
|
+
return function FilterSuggestions(userProps) {
|
|
41
|
+
var _userProps$classNames = userProps.classNames,
|
|
42
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
43
|
+
suggestions = userProps.suggestions,
|
|
44
|
+
isLoading = userProps.isLoading,
|
|
45
|
+
_refine = userProps.refine,
|
|
46
|
+
_userProps$skeletonCo = userProps.skeletonCount,
|
|
47
|
+
skeletonCount = _userProps$skeletonCo === void 0 ? 3 : _userProps$skeletonCo,
|
|
48
|
+
_userProps$itemCompon = userProps.itemComponent,
|
|
49
|
+
ItemComponent = _userProps$itemCompon === void 0 ? DefaultItem : _userProps$itemCompon,
|
|
50
|
+
headerComponent = userProps.headerComponent,
|
|
51
|
+
EmptyComponent = userProps.emptyComponent,
|
|
52
|
+
props = _objectWithoutProperties(userProps, _excluded);
|
|
53
|
+
var HeaderComponent = headerComponent === false ? null : headerComponent !== null && headerComponent !== void 0 ? headerComponent : DefaultHeader;
|
|
54
|
+
var isEmpty = suggestions.length === 0;
|
|
55
|
+
if (isEmpty && !isLoading) {
|
|
56
|
+
return createElement("div", _extends({}, props, {
|
|
57
|
+
className: cx('ais-FilterSuggestions', classNames.root, 'ais-FilterSuggestions--empty', classNames.emptyRoot, props.className)
|
|
58
|
+
}), EmptyComponent && createElement(EmptyComponent, {
|
|
59
|
+
classNames: {
|
|
60
|
+
emptyRoot: classNames.emptyRoot
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
var headerClassNames = {
|
|
65
|
+
header: classNames.header,
|
|
66
|
+
headerIcon: classNames.headerIcon,
|
|
67
|
+
headerTitle: classNames.headerTitle
|
|
68
|
+
};
|
|
69
|
+
var itemClassNames = {
|
|
70
|
+
item: classNames.item,
|
|
71
|
+
button: classNames.button,
|
|
72
|
+
label: classNames.label,
|
|
73
|
+
count: classNames.count
|
|
74
|
+
};
|
|
75
|
+
return createElement("div", _extends({}, props, {
|
|
76
|
+
className: cx('ais-FilterSuggestions', classNames.root, isLoading && cx('ais-FilterSuggestions--loading', classNames.loadingRoot), props.className)
|
|
77
|
+
}), HeaderComponent && createElement(HeaderComponent, {
|
|
78
|
+
classNames: headerClassNames
|
|
79
|
+
}), isLoading ? createElement("div", {
|
|
80
|
+
className: cx('ais-FilterSuggestions-skeleton', classNames.skeleton)
|
|
81
|
+
}, _toConsumableArray(new Array(skeletonCount)).map(function (_, i) {
|
|
82
|
+
return createElement("div", {
|
|
83
|
+
key: i,
|
|
84
|
+
className: cx('ais-FilterSuggestions-skeletonItem', classNames.skeletonItem)
|
|
85
|
+
});
|
|
86
|
+
})) : createElement("ul", {
|
|
87
|
+
className: cx('ais-FilterSuggestions-list', classNames.list)
|
|
88
|
+
}, suggestions.map(function (suggestion) {
|
|
89
|
+
return createElement("li", {
|
|
90
|
+
key: "".concat(suggestion.attribute, "-").concat(suggestion.value),
|
|
91
|
+
className: cx('ais-FilterSuggestions-item', classNames.item)
|
|
92
|
+
}, createElement(ItemComponent, {
|
|
93
|
+
suggestion: suggestion,
|
|
94
|
+
classNames: itemClassNames,
|
|
95
|
+
refine: function refine() {
|
|
96
|
+
return _refine(suggestion.attribute, suggestion.value);
|
|
97
|
+
}
|
|
98
|
+
}));
|
|
99
|
+
})));
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -11,9 +11,11 @@ export type AutocompleteIndexProps<T = {
|
|
|
11
11
|
ItemComponent: (props: {
|
|
12
12
|
item: T;
|
|
13
13
|
onSelect: () => void;
|
|
14
|
+
onApply: () => void;
|
|
14
15
|
}) => JSX.Element;
|
|
15
16
|
getItemProps: (item: T, index: number) => Omit<ComponentProps<'li'>, 'onSelect'> & {
|
|
16
17
|
onSelect: () => void;
|
|
18
|
+
onApply: () => void;
|
|
17
19
|
};
|
|
18
20
|
classNames?: Partial<AutocompleteIndexClassNames>;
|
|
19
21
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["className", "onSelect"];
|
|
3
|
+
var _excluded = ["className", "onSelect", "onApply"];
|
|
4
4
|
import { cx } from "../../lib/cx.js";
|
|
5
5
|
export function createAutocompleteIndexComponent(_ref) {
|
|
6
6
|
var createElement = _ref.createElement;
|
|
@@ -23,6 +23,7 @@ export function createAutocompleteIndexComponent(_ref) {
|
|
|
23
23
|
var _getItemProps = getItemProps(item, index),
|
|
24
24
|
className = _getItemProps.className,
|
|
25
25
|
onSelect = _getItemProps.onSelect,
|
|
26
|
+
onApply = _getItemProps.onApply,
|
|
26
27
|
itemProps = _objectWithoutProperties(_getItemProps, _excluded);
|
|
27
28
|
return createElement("li", _extends({
|
|
28
29
|
key: "".concat(itemProps.id, ":").concat(item.objectID)
|
|
@@ -30,7 +31,8 @@ export function createAutocompleteIndexComponent(_ref) {
|
|
|
30
31
|
className: cx('ais-AutocompleteIndexItem', classNames.item, className)
|
|
31
32
|
}), createElement(ItemComponent, {
|
|
32
33
|
item: item,
|
|
33
|
-
onSelect: onSelect
|
|
34
|
+
onSelect: onSelect,
|
|
35
|
+
onApply: onApply
|
|
34
36
|
}));
|
|
35
37
|
})));
|
|
36
38
|
};
|
|
@@ -7,6 +7,7 @@ export type AutocompleteRecentSearchProps<T = {
|
|
|
7
7
|
children?: ComponentChildren;
|
|
8
8
|
onSelect: () => void;
|
|
9
9
|
onRemoveRecentSearch: () => void;
|
|
10
|
+
onApply: () => void;
|
|
10
11
|
classNames?: Partial<AutocompleteRecentSearchClassNames>;
|
|
11
12
|
};
|
|
12
13
|
export type AutocompleteRecentSearchClassNames = {
|
|
@@ -34,5 +35,9 @@ export type AutocompleteRecentSearchClassNames = {
|
|
|
34
35
|
* Class names to apply to the delete button element
|
|
35
36
|
**/
|
|
36
37
|
deleteButton: string | string[];
|
|
38
|
+
/**
|
|
39
|
+
* Class names to apply to the apply button element
|
|
40
|
+
**/
|
|
41
|
+
applyButton: string | string[];
|
|
37
42
|
};
|
|
38
43
|
export declare function createAutocompleteRecentSearchComponent({ createElement, }: Renderer): (userProps: AutocompleteRecentSearchProps) => JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cx } from "../../lib/index.js";
|
|
2
|
-
import { ClockIcon, TrashIcon } from "./icons.js";
|
|
2
|
+
import { ApplyIcon, ClockIcon, TrashIcon } from "./icons.js";
|
|
3
3
|
export function createAutocompleteRecentSearchComponent(_ref) {
|
|
4
4
|
var createElement = _ref.createElement;
|
|
5
5
|
return function AutocompleteRecentSearch(userProps) {
|
|
@@ -7,6 +7,7 @@ export function createAutocompleteRecentSearchComponent(_ref) {
|
|
|
7
7
|
children = userProps.children,
|
|
8
8
|
onSelect = userProps.onSelect,
|
|
9
9
|
onRemoveRecentSearch = userProps.onRemoveRecentSearch,
|
|
10
|
+
onApply = userProps.onApply,
|
|
10
11
|
_userProps$classNames = userProps.classNames,
|
|
11
12
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
12
13
|
return createElement("div", {
|
|
@@ -31,6 +32,15 @@ export function createAutocompleteRecentSearchComponent(_ref) {
|
|
|
31
32
|
}
|
|
32
33
|
}, createElement(TrashIcon, {
|
|
33
34
|
createElement: createElement
|
|
35
|
+
})), createElement("button", {
|
|
36
|
+
className: cx('ais-AutocompleteItemActionButton', 'ais-AutocompleteRecentSearchItemApplyButton', classNames.applyButton),
|
|
37
|
+
title: "Apply ".concat(item.query, " as search"),
|
|
38
|
+
onClick: function onClick(evt) {
|
|
39
|
+
evt.stopPropagation();
|
|
40
|
+
onApply();
|
|
41
|
+
}
|
|
42
|
+
}, createElement(ApplyIcon, {
|
|
43
|
+
createElement: createElement
|
|
34
44
|
}))));
|
|
35
45
|
};
|
|
36
46
|
}
|
|
@@ -5,6 +5,7 @@ export type AutocompleteSuggestionProps<T = {
|
|
|
5
5
|
} & Record<string, unknown>> = {
|
|
6
6
|
item: T;
|
|
7
7
|
onSelect: () => void;
|
|
8
|
+
onApply: () => void;
|
|
8
9
|
children: ComponentChildren;
|
|
9
10
|
classNames?: Partial<AutocompleteSuggestionClassNames>;
|
|
10
11
|
};
|
|
@@ -21,5 +22,7 @@ export type AutocompleteSuggestionClassNames = {
|
|
|
21
22
|
icon: string | string[];
|
|
22
23
|
/** Class names to apply to the body element **/
|
|
23
24
|
body: string | string[];
|
|
25
|
+
/** Class names to apply to the apply button element **/
|
|
26
|
+
applyButton: string | string[];
|
|
24
27
|
};
|
|
25
28
|
export declare function createAutocompleteSuggestionComponent({ createElement, }: Renderer): (userProps: AutocompleteSuggestionProps) => JSX.Element;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { cx } from "../../lib/index.js";
|
|
2
|
-
import { SubmitIcon } from "./icons.js";
|
|
2
|
+
import { SubmitIcon, ApplyIcon } from "./icons.js";
|
|
3
3
|
export function createAutocompleteSuggestionComponent(_ref) {
|
|
4
4
|
var createElement = _ref.createElement;
|
|
5
5
|
return function AutocompleteSuggestion(userProps) {
|
|
6
|
-
var
|
|
6
|
+
var item = userProps.item,
|
|
7
|
+
children = userProps.children,
|
|
7
8
|
onSelect = userProps.onSelect,
|
|
9
|
+
onApply = userProps.onApply,
|
|
8
10
|
_userProps$classNames = userProps.classNames,
|
|
9
11
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
10
12
|
return createElement("div", {
|
|
@@ -18,6 +20,18 @@ export function createAutocompleteSuggestionComponent(_ref) {
|
|
|
18
20
|
createElement: createElement
|
|
19
21
|
})), createElement("div", {
|
|
20
22
|
className: cx('ais-AutocompleteItemContentBody', 'ais-AutocompleteSuggestionItemContentBody', classNames.content)
|
|
21
|
-
}, children))
|
|
23
|
+
}, children)), createElement("div", {
|
|
24
|
+
className: cx('ais-AutocompleteItemActions', 'ais-AutocompleteSuggestionItemActions', classNames.actions)
|
|
25
|
+
}, createElement("button", {
|
|
26
|
+
className: cx('ais-AutocompleteItemActionButton', 'ais-AutocompleteSuggestionItemApplyButton', classNames.applyButton),
|
|
27
|
+
type: "button",
|
|
28
|
+
title: "Apply ".concat(item.query, " as search"),
|
|
29
|
+
onClick: function onClick(evt) {
|
|
30
|
+
evt.stopPropagation();
|
|
31
|
+
onApply();
|
|
32
|
+
}
|
|
33
|
+
}, createElement(ApplyIcon, {
|
|
34
|
+
createElement: createElement
|
|
35
|
+
}))));
|
|
22
36
|
};
|
|
23
37
|
}
|
|
@@ -21,6 +21,7 @@ type GetItemProps = (item: {
|
|
|
21
21
|
'aria-selected'?: boolean;
|
|
22
22
|
} & {
|
|
23
23
|
onSelect: () => void;
|
|
24
|
+
onApply: () => void;
|
|
24
25
|
};
|
|
25
26
|
type GetPanelProps = () => {
|
|
26
27
|
id?: string;
|
|
@@ -51,6 +52,7 @@ export type UsePropGetters<TItem extends BaseHit> = (params: {
|
|
|
51
52
|
indicesConfig: Array<AutocompleteIndexConfig<TItem>>;
|
|
52
53
|
onRefine: (query: string) => void;
|
|
53
54
|
onSelect: NonNullable<AutocompleteIndexConfig<TItem>['onSelect']>;
|
|
55
|
+
onApply: (query: string) => void;
|
|
54
56
|
placeholder?: string;
|
|
55
57
|
}) => {
|
|
56
58
|
getInputProps: GetInputProps;
|
|
@@ -58,5 +60,5 @@ export type UsePropGetters<TItem extends BaseHit> = (params: {
|
|
|
58
60
|
getPanelProps: GetPanelProps;
|
|
59
61
|
getRootProps: GetRootProps;
|
|
60
62
|
};
|
|
61
|
-
export declare function createAutocompletePropGetters({ useEffect, useId, useMemo, useRef, useState, }: CreateAutocompletePropGettersParams): <TItem extends BaseHit>({ indices, indicesConfig, onRefine, onSelect: globalOnSelect, placeholder, }: Parameters<UsePropGetters<TItem>>[0]) => ReturnType<UsePropGetters<TItem>>;
|
|
63
|
+
export declare function createAutocompletePropGetters({ useEffect, useId, useMemo, useRef, useState, }: CreateAutocompletePropGettersParams): <TItem extends BaseHit>({ indices, indicesConfig, onRefine, onSelect: globalOnSelect, onApply, placeholder, }: Parameters<UsePropGetters<TItem>>[0]) => ReturnType<UsePropGetters<TItem>>;
|
|
62
64
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import { find } from "../../lib/index.js";
|
|
3
4
|
export function createAutocompletePropGetters(_ref) {
|
|
4
5
|
var useEffect = _ref.useEffect,
|
|
5
6
|
useId = _ref.useId,
|
|
@@ -11,6 +12,7 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
11
12
|
indicesConfig = _ref2.indicesConfig,
|
|
12
13
|
onRefine = _ref2.onRefine,
|
|
13
14
|
globalOnSelect = _ref2.onSelect,
|
|
15
|
+
_onApply = _ref2.onApply,
|
|
14
16
|
placeholder = _ref2.placeholder;
|
|
15
17
|
var getElementId = createGetElementId(useId());
|
|
16
18
|
var inputRef = useRef(null);
|
|
@@ -178,6 +180,13 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
178
180
|
return submit({
|
|
179
181
|
activeDescendant: id
|
|
180
182
|
});
|
|
183
|
+
},
|
|
184
|
+
onApply: function onApply() {
|
|
185
|
+
var _getQuery2;
|
|
186
|
+
var _ref4 = items.get(id),
|
|
187
|
+
currentItem = _ref4.item,
|
|
188
|
+
getQuery = _ref4.config.getQuery;
|
|
189
|
+
_onApply((_getQuery2 = getQuery === null || getQuery === void 0 ? void 0 : getQuery(currentItem)) !== null && _getQuery2 !== void 0 ? _getQuery2 : '');
|
|
181
190
|
}
|
|
182
191
|
};
|
|
183
192
|
},
|
|
@@ -197,24 +206,29 @@ export function createAutocompletePropGetters(_ref) {
|
|
|
197
206
|
};
|
|
198
207
|
};
|
|
199
208
|
}
|
|
200
|
-
function buildItems(
|
|
201
|
-
var indices =
|
|
202
|
-
indicesConfig =
|
|
203
|
-
getElementId =
|
|
209
|
+
function buildItems(_ref5) {
|
|
210
|
+
var indices = _ref5.indices,
|
|
211
|
+
indicesConfig = _ref5.indicesConfig,
|
|
212
|
+
getElementId = _ref5.getElementId;
|
|
204
213
|
var itemsIds = [];
|
|
205
214
|
var items = new Map();
|
|
206
|
-
|
|
215
|
+
var _loop = function _loop(i) {
|
|
207
216
|
var _indices$i;
|
|
208
|
-
var
|
|
217
|
+
var currentIndexConfig = find(indicesConfig, function (config) {
|
|
218
|
+
return config.indexName === indices[i].indexName;
|
|
219
|
+
});
|
|
209
220
|
var hits = ((_indices$i = indices[i]) === null || _indices$i === void 0 ? void 0 : _indices$i.hits) || [];
|
|
210
221
|
for (var position = 0; position < hits.length; position++) {
|
|
211
|
-
var itemId = getElementId('item',
|
|
222
|
+
var itemId = getElementId('item', (currentIndexConfig === null || currentIndexConfig === void 0 ? void 0 : currentIndexConfig.indexName) || indices[i].indexName, position);
|
|
212
223
|
items.set(itemId, {
|
|
213
224
|
item: hits[position],
|
|
214
|
-
config:
|
|
225
|
+
config: currentIndexConfig
|
|
215
226
|
});
|
|
216
227
|
itemsIds.push(itemId);
|
|
217
228
|
}
|
|
229
|
+
};
|
|
230
|
+
for (var i = 0; i < indices.length; i++) {
|
|
231
|
+
_loop(i);
|
|
218
232
|
}
|
|
219
233
|
return {
|
|
220
234
|
items: items,
|
|
@@ -9,8 +9,9 @@ type UseStorageParams<TItem extends Record<string, unknown>> = {
|
|
|
9
9
|
storageKey?: string;
|
|
10
10
|
};
|
|
11
11
|
query?: string;
|
|
12
|
+
suggestionsIndexName?: string;
|
|
12
13
|
} & Pick<Parameters<UsePropGetters<TItem>>[0], 'indices' | 'indicesConfig'>;
|
|
13
|
-
export declare function createAutocompleteStorage({ useEffect, useMemo, useState, }: CreateAutocompleteStorageParams): <TItem extends Record<string, unknown>>({ showRecent, query, indices, indicesConfig, }: UseStorageParams<TItem>) => {
|
|
14
|
+
export declare function createAutocompleteStorage({ useEffect, useMemo, useState, }: CreateAutocompleteStorageParams): <TItem extends Record<string, unknown>>({ showRecent, query, indices, indicesConfig, suggestionsIndexName, }: UseStorageParams<TItem>) => {
|
|
14
15
|
storage: {
|
|
15
16
|
onAdd: () => void;
|
|
16
17
|
onRemove: () => void;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
3
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
4
|
import _typeof from "@babel/runtime/helpers/typeof";
|
|
5
|
+
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; }
|
|
6
|
+
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) { _defineProperty(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; }
|
|
7
|
+
import { find } from "../../lib/index.js";
|
|
4
8
|
export function createAutocompleteStorage(_ref) {
|
|
5
9
|
var useEffect = _ref.useEffect,
|
|
6
10
|
useMemo = _ref.useMemo,
|
|
@@ -9,7 +13,8 @@ export function createAutocompleteStorage(_ref) {
|
|
|
9
13
|
var showRecent = _ref2.showRecent,
|
|
10
14
|
query = _ref2.query,
|
|
11
15
|
indices = _ref2.indices,
|
|
12
|
-
indicesConfig = _ref2.indicesConfig
|
|
16
|
+
indicesConfig = _ref2.indicesConfig,
|
|
17
|
+
suggestionsIndexName = _ref2.suggestionsIndexName;
|
|
13
18
|
var storageKey = showRecent && _typeof(showRecent) === 'object' ? showRecent.storageKey : undefined;
|
|
14
19
|
var storage = useMemo(function () {
|
|
15
20
|
return createStorage({
|
|
@@ -53,7 +58,15 @@ export function createAutocompleteStorage(_ref) {
|
|
|
53
58
|
})
|
|
54
59
|
};
|
|
55
60
|
});
|
|
56
|
-
var indicesForPropGetters = _toConsumableArray(indices)
|
|
61
|
+
var indicesForPropGetters = _toConsumableArray(indices.map(function (index) {
|
|
62
|
+
return index.indexName === suggestionsIndexName ? _objectSpread(_objectSpread({}, index), {}, {
|
|
63
|
+
hits: index.hits.filter(function (hit) {
|
|
64
|
+
return !find(storageHits, function (storageHit) {
|
|
65
|
+
return storageHit.query === hit.query;
|
|
66
|
+
});
|
|
67
|
+
})
|
|
68
|
+
}) : index;
|
|
69
|
+
}));
|
|
57
70
|
var indicesConfigForPropGetters = _toConsumableArray(indicesConfig);
|
|
58
71
|
indicesForPropGetters.unshift({
|
|
59
72
|
indexName: 'recent-searches',
|
|
@@ -6,4 +6,5 @@ export declare function LoadingIcon({ createElement }: IconProps): JSX.Element;
|
|
|
6
6
|
export declare function ClearIcon({ createElement }: IconProps): JSX.Element;
|
|
7
7
|
export declare function ClockIcon({ createElement }: IconProps): JSX.Element;
|
|
8
8
|
export declare function TrashIcon({ createElement }: IconProps): JSX.Element;
|
|
9
|
+
export declare function ApplyIcon({ createElement }: IconProps): JSX.Element;
|
|
9
10
|
export {};
|
|
@@ -57,4 +57,13 @@ export function TrashIcon(_ref5) {
|
|
|
57
57
|
}, createElement("path", {
|
|
58
58
|
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"
|
|
59
59
|
}));
|
|
60
|
+
}
|
|
61
|
+
export function ApplyIcon(_ref6) {
|
|
62
|
+
var createElement = _ref6.createElement;
|
|
63
|
+
return createElement("svg", {
|
|
64
|
+
viewBox: "0 0 24 24",
|
|
65
|
+
fill: "currentColor"
|
|
66
|
+
}, createElement("path", {
|
|
67
|
+
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"
|
|
68
|
+
}));
|
|
60
69
|
}
|
|
@@ -2,6 +2,7 @@ import type { Renderer, ComponentProps } from '../../types';
|
|
|
2
2
|
import type { ChatHeaderProps, ChatHeaderOwnProps } from './ChatHeader';
|
|
3
3
|
import type { ChatMessagesProps } from './ChatMessages';
|
|
4
4
|
import type { ChatPromptProps, ChatPromptOwnProps } from './ChatPrompt';
|
|
5
|
+
import type { ChatPromptSuggestionsOwnProps } from './ChatPromptSuggestions';
|
|
5
6
|
import type { ChatToggleButtonOwnProps, ChatToggleButtonProps } from './ChatToggleButton';
|
|
6
7
|
export type ChatClassNames = {
|
|
7
8
|
root?: string | string[];
|
|
@@ -11,6 +12,7 @@ export type ChatClassNames = {
|
|
|
11
12
|
message?: ChatMessagesProps['messageClassNames'];
|
|
12
13
|
prompt?: ChatPromptProps['classNames'];
|
|
13
14
|
toggleButton?: ChatToggleButtonProps['classNames'];
|
|
15
|
+
suggestions?: ChatPromptSuggestionsOwnProps['classNames'];
|
|
14
16
|
};
|
|
15
17
|
export type ChatProps = Omit<ComponentProps<'div'>, 'onError' | 'title'> & {
|
|
16
18
|
open: boolean;
|
|
@@ -19,6 +21,7 @@ export type ChatProps = Omit<ComponentProps<'div'>, 'onError' | 'title'> & {
|
|
|
19
21
|
toggleButtonProps: ChatToggleButtonProps;
|
|
20
22
|
messagesProps: ChatMessagesProps;
|
|
21
23
|
promptProps: ChatPromptProps;
|
|
24
|
+
suggestionsProps: ChatPromptSuggestionsOwnProps;
|
|
22
25
|
/**
|
|
23
26
|
* Optional class names for elements
|
|
24
27
|
*/
|
|
@@ -39,5 +42,9 @@ export type ChatProps = Omit<ComponentProps<'div'>, 'onError' | 'title'> & {
|
|
|
39
42
|
* Optional toggle button component for the chat
|
|
40
43
|
*/
|
|
41
44
|
toggleButtonComponent?: (props: ChatToggleButtonOwnProps) => JSX.Element;
|
|
45
|
+
/**
|
|
46
|
+
* Optional suggestions component for the chat
|
|
47
|
+
*/
|
|
48
|
+
suggestionsComponent?: (props: ChatPromptSuggestionsOwnProps) => JSX.Element;
|
|
42
49
|
};
|
|
43
50
|
export declare function createChatComponent({ createElement, Fragment }: Renderer): (userProps: ChatProps) => JSX.Element;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["open", "maximized", "headerProps", "toggleButtonProps", "messagesProps", "promptProps", "headerComponent", "promptComponent", "toggleButtonComponent", "classNames", "className"];
|
|
4
|
+
var _excluded = ["open", "maximized", "headerProps", "toggleButtonProps", "messagesProps", "suggestionsProps", "promptProps", "headerComponent", "promptComponent", "toggleButtonComponent", "suggestionsComponent", "classNames", "className"];
|
|
5
5
|
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; }
|
|
6
6
|
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) { _defineProperty(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; }
|
|
7
7
|
import { cx } from "../../lib/index.js";
|
|
8
8
|
import { createChatHeaderComponent } from "./ChatHeader.js";
|
|
9
9
|
import { createChatMessagesComponent } from "./ChatMessages.js";
|
|
10
10
|
import { createChatPromptComponent } from "./ChatPrompt.js";
|
|
11
|
+
import { createChatPromptSuggestionsComponent } from "./ChatPromptSuggestions.js";
|
|
11
12
|
import { createChatToggleButtonComponent } from "./ChatToggleButton.js";
|
|
12
13
|
export function createChatComponent(_ref) {
|
|
13
14
|
var createElement = _ref.createElement,
|
|
@@ -28,6 +29,10 @@ export function createChatComponent(_ref) {
|
|
|
28
29
|
createElement: createElement,
|
|
29
30
|
Fragment: Fragment
|
|
30
31
|
});
|
|
32
|
+
var ChatPromptSuggestions = createChatPromptSuggestionsComponent({
|
|
33
|
+
createElement: createElement,
|
|
34
|
+
Fragment: Fragment
|
|
35
|
+
});
|
|
31
36
|
return function Chat(userProps) {
|
|
32
37
|
var open = userProps.open,
|
|
33
38
|
_userProps$maximized = userProps.maximized,
|
|
@@ -35,11 +40,13 @@ export function createChatComponent(_ref) {
|
|
|
35
40
|
headerProps = userProps.headerProps,
|
|
36
41
|
toggleButtonProps = userProps.toggleButtonProps,
|
|
37
42
|
messagesProps = userProps.messagesProps,
|
|
43
|
+
suggestionsProps = userProps.suggestionsProps,
|
|
38
44
|
_userProps$promptProp = userProps.promptProps,
|
|
39
45
|
promptProps = _userProps$promptProp === void 0 ? {} : _userProps$promptProp,
|
|
40
46
|
HeaderComponent = userProps.headerComponent,
|
|
41
47
|
PromptComponent = userProps.promptComponent,
|
|
42
48
|
ToggleButtonComponent = userProps.toggleButtonComponent,
|
|
49
|
+
SuggestionsComponent = userProps.suggestionsComponent,
|
|
43
50
|
_userProps$classNames = userProps.classNames,
|
|
44
51
|
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames,
|
|
45
52
|
className = userProps.className,
|
|
@@ -53,7 +60,10 @@ export function createChatComponent(_ref) {
|
|
|
53
60
|
maximized: maximized
|
|
54
61
|
})), createElement(ChatMessages, _extends({}, messagesProps, {
|
|
55
62
|
classNames: classNames.messages,
|
|
56
|
-
messageClassNames: classNames.message
|
|
63
|
+
messageClassNames: classNames.message,
|
|
64
|
+
suggestionsElement: createElement(SuggestionsComponent || ChatPromptSuggestions, _objectSpread(_objectSpread({}, suggestionsProps), {}, {
|
|
65
|
+
classNames: classNames.suggestions
|
|
66
|
+
}))
|
|
57
67
|
})), createElement(PromptComponent || ChatPrompt, _objectSpread(_objectSpread({}, promptProps), {}, {
|
|
58
68
|
classNames: classNames.prompt
|
|
59
69
|
}))), createElement("div", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentProps, Renderer } from '../../types';
|
|
1
|
+
import type { ComponentProps, Renderer, VNode } from '../../types';
|
|
2
2
|
import type { ChatMessageBase, ClientSideTools } from './types';
|
|
3
3
|
export type ChatMessageSide = 'left' | 'right';
|
|
4
4
|
export type ChatMessageVariant = 'neutral' | 'subtle';
|
|
@@ -112,6 +112,10 @@ export type ChatMessageProps = ComponentProps<'article'> & {
|
|
|
112
112
|
* Array of tools available for the assistant (for tool messages)
|
|
113
113
|
*/
|
|
114
114
|
tools: ClientSideTools;
|
|
115
|
+
/**
|
|
116
|
+
* Optional suggestions element
|
|
117
|
+
*/
|
|
118
|
+
suggestionsElement?: VNode;
|
|
115
119
|
/**
|
|
116
120
|
* Optional class names
|
|
117
121
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["classNames", "message", "side", "variant", "actions", "autoHideActions", "leadingComponent", "actionsComponent", "footerComponent", "tools", "indexUiState", "setIndexUiState", "onClose", "translations"];
|
|
4
|
+
var _excluded = ["classNames", "message", "side", "variant", "actions", "autoHideActions", "leadingComponent", "actionsComponent", "footerComponent", "tools", "indexUiState", "setIndexUiState", "onClose", "translations", "suggestionsElement"];
|
|
5
5
|
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; }
|
|
6
6
|
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) { _defineProperty(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; }
|
|
7
7
|
import { compiler } from 'markdown-to-jsx';
|
|
@@ -34,6 +34,7 @@ export function createChatMessageComponent(_ref) {
|
|
|
34
34
|
setIndexUiState = userProps.setIndexUiState,
|
|
35
35
|
onClose = userProps.onClose,
|
|
36
36
|
userTranslations = userProps.translations,
|
|
37
|
+
suggestionsElement = userProps.suggestionsElement,
|
|
37
38
|
props = _objectWithoutProperties(userProps, _excluded);
|
|
38
39
|
var translations = _objectSpread({
|
|
39
40
|
messageLabel: 'Message',
|
|
@@ -105,7 +106,7 @@ export function createChatMessageComponent(_ref) {
|
|
|
105
106
|
className: cx(cssClasses.content)
|
|
106
107
|
}, createElement("div", {
|
|
107
108
|
className: cx(cssClasses.message)
|
|
108
|
-
}, message.parts.map(renderMessagePart)), hasActions && createElement("div", {
|
|
109
|
+
}, message.parts.map(renderMessagePart)), suggestionsElement, hasActions && createElement("div", {
|
|
109
110
|
className: cx(cssClasses.actions),
|
|
110
111
|
"aria-label": translations.actionsLabel
|
|
111
112
|
}, ActionsComponent ? createElement(ActionsComponent, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsx createElement */
|
|
2
|
-
import type { ComponentProps, MutableRef, Renderer } from '../../types';
|
|
2
|
+
import type { ComponentProps, MutableRef, Renderer, VNode } from '../../types';
|
|
3
3
|
import type { ChatMessageProps, ChatMessageClassNames, ChatMessageTranslations } from './ChatMessage';
|
|
4
4
|
import type { ChatMessageErrorProps } from './ChatMessageError';
|
|
5
5
|
import type { ChatMessageLoaderProps } from './ChatMessageLoader';
|
|
@@ -143,5 +143,9 @@ export type ChatMessagesProps<TMessage extends ChatMessageBase = ChatMessageBase
|
|
|
143
143
|
* Callback to scroll to bottom
|
|
144
144
|
*/
|
|
145
145
|
onScrollToBottom?: () => void;
|
|
146
|
+
/**
|
|
147
|
+
* Suggestions element to display below a message
|
|
148
|
+
*/
|
|
149
|
+
suggestionsElement?: VNode;
|
|
146
150
|
};
|
|
147
151
|
export declare function createChatMessagesComponent({ createElement, Fragment, }: Renderer): <TMessage extends ChatMessageBase = ChatMessageBase>(userProps: ChatMessagesProps<TMessage>) => JSX.Element;
|
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
import _extends from "@babel/runtime/helpers/extends";
|
|
4
4
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
5
|
-
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"];
|
|
5
|
+
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"];
|
|
6
6
|
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; }
|
|
7
7
|
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) { _defineProperty(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; }
|
|
8
8
|
import { cx } from "../../lib/index.js";
|
|
@@ -41,7 +41,8 @@ function createDefaultMessageComponent(_ref) {
|
|
|
41
41
|
actionsComponent = _ref2.actionsComponent,
|
|
42
42
|
classNames = _ref2.classNames,
|
|
43
43
|
messageTranslations = _ref2.messageTranslations,
|
|
44
|
-
translations = _ref2.translations
|
|
44
|
+
translations = _ref2.translations,
|
|
45
|
+
suggestionsElement = _ref2.suggestionsElement;
|
|
45
46
|
var defaultAssistantActions = [].concat(_toConsumableArray(hasTextContent(message) ? [{
|
|
46
47
|
title: translations.copyToClipboardLabel,
|
|
47
48
|
icon: function icon() {
|
|
@@ -75,7 +76,8 @@ function createDefaultMessageComponent(_ref) {
|
|
|
75
76
|
actionsComponent: actionsComponent,
|
|
76
77
|
"data-role": message.role,
|
|
77
78
|
classNames: classNames,
|
|
78
|
-
translations: messageTranslations
|
|
79
|
+
translations: messageTranslations,
|
|
80
|
+
suggestionsElement: suggestionsElement
|
|
79
81
|
}, messageProps));
|
|
80
82
|
};
|
|
81
83
|
}
|
|
@@ -126,6 +128,7 @@ export function createChatMessagesComponent(_ref3) {
|
|
|
126
128
|
scrollRef = userProps.scrollRef,
|
|
127
129
|
contentRef = userProps.contentRef,
|
|
128
130
|
onScrollToBottom = userProps.onScrollToBottom,
|
|
131
|
+
suggestionsElement = userProps.suggestionsElement,
|
|
129
132
|
props = _objectWithoutProperties(userProps, _excluded);
|
|
130
133
|
var translations = _objectSpread({
|
|
131
134
|
scrollToBottomLabel: 'Scroll to bottom',
|
|
@@ -157,7 +160,7 @@ export function createChatMessagesComponent(_ref3) {
|
|
|
157
160
|
onClearTransitionEnd === null || onClearTransitionEnd === void 0 ? void 0 : onClearTransitionEnd();
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
|
-
}, messages.map(function (message) {
|
|
163
|
+
}, messages.map(function (message, index) {
|
|
161
164
|
return createElement(DefaultMessage, {
|
|
162
165
|
key: message.id,
|
|
163
166
|
message: message,
|
|
@@ -171,7 +174,8 @@ export function createChatMessagesComponent(_ref3) {
|
|
|
171
174
|
onClose: onClose,
|
|
172
175
|
translations: translations,
|
|
173
176
|
classNames: messageClassNames,
|
|
174
|
-
messageTranslations: messageTranslations
|
|
177
|
+
messageTranslations: messageTranslations,
|
|
178
|
+
suggestionsElement: status === 'ready' && message.role === 'assistant' && index === messages.length - 1 ? suggestionsElement : undefined
|
|
175
179
|
});
|
|
176
180
|
}), status === 'submitted' && createElement(DefaultLoader, {
|
|
177
181
|
translations: {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Renderer } from '../../types';
|
|
2
|
+
export type ChatPromptSuggestionsClassNames = {
|
|
3
|
+
root?: string | string[];
|
|
4
|
+
suggestion?: string | string[];
|
|
5
|
+
};
|
|
6
|
+
export type ChatPromptSuggestionsOwnProps = {
|
|
7
|
+
suggestions?: string[];
|
|
8
|
+
onSuggestionClick: (suggestion: string) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Optional class names for elements
|
|
11
|
+
*/
|
|
12
|
+
classNames?: Partial<ChatPromptSuggestionsClassNames>;
|
|
13
|
+
};
|
|
14
|
+
export declare function createChatPromptSuggestionsComponent({ createElement, }: Renderer): (userProps: ChatPromptSuggestionsOwnProps) => JSX.Element | null;
|