instantsearch-ui-components 0.16.0 → 0.17.1
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 +3 -0
- package/dist/cjs/components/autocomplete/createAutocompletePropGetters.js +10 -4
- package/dist/cjs/components/autocomplete/createAutocompleteStorage.js +15 -2
- 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 +22 -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 +1 -1
- package/dist/es/components/autocomplete/AutocompleteIndex.js +3 -0
- package/dist/es/components/autocomplete/createAutocompletePropGetters.js +10 -4
- package/dist/es/components/autocomplete/createAutocompleteStorage.d.ts +2 -1
- package/dist/es/components/autocomplete/createAutocompleteStorage.js +15 -2
- 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/chat/types.d.ts +343 -2
- package/dist/es/components/index.d.ts +2 -0
- package/dist/es/components/index.js +3 -1
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/package.json +2 -3
|
@@ -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,
|
|
@@ -211,18 +212,23 @@ function buildItems(_ref5) {
|
|
|
211
212
|
getElementId = _ref5.getElementId;
|
|
212
213
|
var itemsIds = [];
|
|
213
214
|
var items = new Map();
|
|
214
|
-
|
|
215
|
+
var _loop = function _loop(i) {
|
|
215
216
|
var _indices$i;
|
|
216
|
-
var
|
|
217
|
+
var currentIndexConfig = find(indicesConfig, function (config) {
|
|
218
|
+
return config.indexName === indices[i].indexName;
|
|
219
|
+
});
|
|
217
220
|
var hits = ((_indices$i = indices[i]) === null || _indices$i === void 0 ? void 0 : _indices$i.hits) || [];
|
|
218
221
|
for (var position = 0; position < hits.length; position++) {
|
|
219
|
-
var itemId = getElementId('item',
|
|
222
|
+
var itemId = getElementId('item', (currentIndexConfig === null || currentIndexConfig === void 0 ? void 0 : currentIndexConfig.indexName) || indices[i].indexName, position);
|
|
220
223
|
items.set(itemId, {
|
|
221
224
|
item: hits[position],
|
|
222
|
-
config:
|
|
225
|
+
config: currentIndexConfig
|
|
223
226
|
});
|
|
224
227
|
itemsIds.push(itemId);
|
|
225
228
|
}
|
|
229
|
+
};
|
|
230
|
+
for (var i = 0; i < indices.length; i++) {
|
|
231
|
+
_loop(i);
|
|
226
232
|
}
|
|
227
233
|
return {
|
|
228
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',
|
|
@@ -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;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { cx } from "../../lib/index.js";
|
|
2
|
+
import { createButtonComponent } from "../Button.js";
|
|
3
|
+
export function createChatPromptSuggestionsComponent(_ref) {
|
|
4
|
+
var createElement = _ref.createElement;
|
|
5
|
+
var Button = createButtonComponent({
|
|
6
|
+
createElement: createElement
|
|
7
|
+
});
|
|
8
|
+
return function ChatPromptSuggestions(userProps) {
|
|
9
|
+
var _userProps$suggestion = userProps.suggestions,
|
|
10
|
+
suggestions = _userProps$suggestion === void 0 ? [] : _userProps$suggestion,
|
|
11
|
+
onSuggestionClick = userProps.onSuggestionClick,
|
|
12
|
+
_userProps$classNames = userProps.classNames,
|
|
13
|
+
classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
|
|
14
|
+
if (suggestions.length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return createElement("div", {
|
|
18
|
+
className: cx('ais-ChatPromptSuggestions', classNames.root)
|
|
19
|
+
}, suggestions.map(function (suggestion, index) {
|
|
20
|
+
return createElement(Button, {
|
|
21
|
+
key: index,
|
|
22
|
+
size: "sm",
|
|
23
|
+
variant: "primary",
|
|
24
|
+
className: cx('ais-ChatPromptSuggestions-suggestion', classNames.suggestion),
|
|
25
|
+
onClick: function onClick() {
|
|
26
|
+
return onSuggestionClick(suggestion);
|
|
27
|
+
}
|
|
28
|
+
}, suggestion);
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
}
|