react-instantsearch 7.33.1 → 7.34.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/ChatInlineLayout.js +3 -0
- package/dist/cjs/widgets/Autocomplete.js +8 -4
- package/dist/cjs/widgets/Chat.js +10 -14
- package/dist/cjs/widgets/ChatTrigger.js +49 -0
- package/dist/cjs/widgets/SearchBox.js +4 -2
- package/dist/cjs/widgets/index.js +1 -0
- package/dist/es/components/ChatInlineLayout.d.ts +4 -1
- package/dist/es/components/ChatInlineLayout.js +3 -0
- package/dist/es/index.js +1 -0
- package/dist/es/widgets/Autocomplete.d.ts +1 -1
- package/dist/es/widgets/Autocomplete.js +8 -4
- package/dist/es/widgets/Chat.d.ts +1 -5
- package/dist/es/widgets/Chat.js +10 -14
- package/dist/es/widgets/ChatTrigger.d.ts +24 -0
- package/dist/es/widgets/ChatTrigger.js +40 -0
- package/dist/es/widgets/SearchBox.js +9 -7
- package/dist/es/widgets/index.d.ts +1 -0
- package/dist/es/widgets/index.js +1 -0
- package/dist/umd/ReactInstantSearch.js +237 -133
- package/dist/umd/ReactInstantSearch.min.js +3 -3
- package/package.json +5 -5
|
@@ -15,3 +15,6 @@ var ChatInlineLayout = (0, _instantsearchuicomponents.createChatInlineLayoutComp
|
|
|
15
15
|
createElement: _react.createElement,
|
|
16
16
|
Fragment: _react.Fragment
|
|
17
17
|
});
|
|
18
|
+
// Marker used by `<Chat>` to auto-exempt inline layouts from the entry-point
|
|
19
|
+
// validation, since inline chats are always visible (no trigger needed).
|
|
20
|
+
ChatInlineLayout.$$inlineLayout = true;
|
|
@@ -201,22 +201,25 @@ function getMediaQueryList(mediaQuery) {
|
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
203
|
function EXPERIMENTAL_Autocomplete(_0) {
|
|
204
|
-
var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, props = _object_without_properties._(_0, [
|
|
204
|
+
var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, aiMode = _0.aiMode, props = _object_without_properties._(_0, [
|
|
205
205
|
"indices",
|
|
206
206
|
"showQuerySuggestions",
|
|
207
207
|
"showPromptSuggestions",
|
|
208
208
|
"showRecent",
|
|
209
209
|
"searchParameters",
|
|
210
210
|
"detachedMediaQuery",
|
|
211
|
-
"translations"
|
|
211
|
+
"translations",
|
|
212
|
+
"aiMode"
|
|
212
213
|
]);
|
|
213
214
|
var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
|
|
214
215
|
var translations = _object_spread._({}, DEFAULT_TRANSLATIONS, userTranslations);
|
|
215
216
|
var _useInstantSearch = (0, _reactinstantsearchcore.useInstantSearch)(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
|
|
216
|
-
var refine = (0, _reactinstantsearchcore.useSearchBox)({}, {
|
|
217
|
+
var refine = (0, _reactinstantsearchcore.useSearchBox)({}, _object_spread._({
|
|
217
218
|
$$type: 'ais.autocomplete',
|
|
218
219
|
$$widgetType: 'ais.autocomplete'
|
|
219
|
-
}
|
|
220
|
+
}, aiMode ? {
|
|
221
|
+
opensChat: true
|
|
222
|
+
} : {})).refine;
|
|
220
223
|
var isSearchStalled = status === 'stalled';
|
|
221
224
|
var searchParameters = _object_spread._({
|
|
222
225
|
hitsPerPage: 5
|
|
@@ -305,6 +308,7 @@ function EXPERIMENTAL_Autocomplete(_0) {
|
|
|
305
308
|
indexName: index.indexName
|
|
306
309
|
}, /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.Configure, index.searchParameters));
|
|
307
310
|
}), /*#__PURE__*/ _react.default.createElement(InnerAutocomplete, _object_spread_props._(_object_spread._({}, props), {
|
|
311
|
+
aiMode: aiMode,
|
|
308
312
|
indicesConfig: indicesConfig,
|
|
309
313
|
refineSearchBox: refine,
|
|
310
314
|
isSearchStalled: isSearchStalled,
|
package/dist/cjs/widgets/Chat.js
CHANGED
|
@@ -61,16 +61,13 @@ function ChatInner(_0, _1) {
|
|
|
61
61
|
var _ref = [
|
|
62
62
|
_0,
|
|
63
63
|
_1
|
|
64
|
-
], _ref1 = _to_array._(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), userTools = _ref2.tools,
|
|
64
|
+
], _ref1 = _to_array._(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), userTools = _ref2.tools, headerProps = _ref2.headerProps, messagesProps = _ref2.messagesProps, promptProps = _ref2.promptProps, itemComponent = _ref2.itemComponent, layoutComponent = _ref2.layoutComponent, headerComponent = _ref2.headerComponent, headerTitleIconComponent = _ref2.headerTitleIconComponent, headerCloseIconComponent = _ref2.headerCloseIconComponent, headerMinimizeIconComponent = _ref2.headerMinimizeIconComponent, headerMaximizeIconComponent = _ref2.headerMaximizeIconComponent, loaderComponent = _ref2.loaderComponent, messagesErrorComponent = _ref2.messagesErrorComponent, promptComponent = _ref2.promptComponent, promptHeaderComponent = _ref2.promptHeaderComponent, promptFooterComponent = _ref2.promptFooterComponent, assistantMessageLeadingComponent = _ref2.assistantMessageLeadingComponent, assistantMessageFooterComponent = _ref2.assistantMessageFooterComponent, userMessageLeadingComponent = _ref2.userMessageLeadingComponent, userMessageFooterComponent = _ref2.userMessageFooterComponent, emptyComponent = _ref2.emptyComponent, actionsComponent = _ref2.actionsComponent, suggestionsComponent = _ref2.suggestionsComponent, classNames = _ref2.classNames, _ref_translations = _ref2.translations, translations = _ref_translations === void 0 ? {} : _ref_translations, title = _ref2.title, getSearchPageURL = _ref2.getSearchPageURL, _ref_disableTriggerValidation = _ref2.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, props = _object_without_properties._(_ref2, [
|
|
65
65
|
"tools",
|
|
66
|
-
"toggleButtonProps",
|
|
67
66
|
"headerProps",
|
|
68
67
|
"messagesProps",
|
|
69
68
|
"promptProps",
|
|
70
69
|
"itemComponent",
|
|
71
70
|
"layoutComponent",
|
|
72
|
-
"toggleButtonComponent",
|
|
73
|
-
"toggleButtonIconComponent",
|
|
74
71
|
"headerComponent",
|
|
75
72
|
"headerTitleIconComponent",
|
|
76
73
|
"headerCloseIconComponent",
|
|
@@ -91,7 +88,8 @@ function ChatInner(_0, _1) {
|
|
|
91
88
|
"classNames",
|
|
92
89
|
"translations",
|
|
93
90
|
"title",
|
|
94
|
-
"getSearchPageURL"
|
|
91
|
+
"getSearchPageURL",
|
|
92
|
+
"disableTriggerValidation"
|
|
95
93
|
]), _rest1 = _sliced_to_array._(_rest, 1), ref = _rest1[0];
|
|
96
94
|
var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
|
|
97
95
|
var _useInstantSearch = (0, _reactinstantsearchcore.useInstantSearch)(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
|
|
@@ -109,8 +107,14 @@ function ChatInner(_0, _1) {
|
|
|
109
107
|
itemComponent,
|
|
110
108
|
userTools
|
|
111
109
|
]);
|
|
110
|
+
// Inline layouts are always visible, so they don't require a `<ChatTrigger />`
|
|
111
|
+
// (or AI mode) to be present. We detect this via a `$$inlineLayout` marker
|
|
112
|
+
// set on the layout component, which is consistent across flavors.
|
|
113
|
+
var isInlineLayoutComponent = typeof layoutComponent === 'function' && layoutComponent.$$inlineLayout === true;
|
|
114
|
+
var effectiveDisableTriggerValidation = disableTriggerValidation || isInlineLayoutComponent;
|
|
112
115
|
var chatState = (0, _reactinstantsearchcore.useChat)(_object_spread_props._(_object_spread._({}, props), {
|
|
113
|
-
tools: tools
|
|
116
|
+
tools: tools,
|
|
117
|
+
disableTriggerValidation: effectiveDisableTriggerValidation
|
|
114
118
|
}));
|
|
115
119
|
var messages = chatState.messages, sendMessage = chatState.sendMessage, status = chatState.status, regenerate = chatState.regenerate, stop = chatState.stop, error = chatState.error, input = chatState.input, setInput = chatState.setInput, open = chatState.open, setOpen = chatState.setOpen, isClearing = chatState.isClearing, clearMessages = chatState.clearMessages, onClearTransitionEnd = chatState.onClearTransitionEnd, toolsFromConnector = chatState.tools, suggestions = chatState.suggestions, onFeedback = chatState.sendChatMessageFeedback, feedbackState = chatState.feedbackState;
|
|
116
120
|
(0, _react.useImperativeHandle)(ref, function() {
|
|
@@ -146,15 +150,7 @@ function ChatInner(_0, _1) {
|
|
|
146
150
|
layoutComponent: layoutComponent,
|
|
147
151
|
headerComponent: headerComponent,
|
|
148
152
|
promptComponent: promptComponent,
|
|
149
|
-
toggleButtonComponent: toggleButtonComponent,
|
|
150
153
|
suggestionsComponent: suggestionsComponent,
|
|
151
|
-
toggleButtonProps: _object_spread._({
|
|
152
|
-
open: open,
|
|
153
|
-
onClick: function onClick() {
|
|
154
|
-
return setOpen(!open);
|
|
155
|
-
},
|
|
156
|
-
toggleIconComponent: toggleButtonIconComponent
|
|
157
|
-
}, toggleButtonProps),
|
|
158
154
|
headerProps: _object_spread._({
|
|
159
155
|
onClose: function onClose() {
|
|
160
156
|
return setOpen(false);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ChatTrigger", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return ChatTrigger;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
|
|
13
|
+
var _object_spread = require("@swc/helpers/_/_object_spread");
|
|
14
|
+
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
|
|
15
|
+
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
|
|
16
|
+
var _instantsearchuicomponents = require("instantsearch-ui-components");
|
|
17
|
+
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
|
|
18
|
+
var _reactinstantsearchcore = require("react-instantsearch-core");
|
|
19
|
+
var ChatToggleButton = (0, _instantsearchuicomponents.createChatToggleButtonComponent)({
|
|
20
|
+
createElement: _react.createElement,
|
|
21
|
+
Fragment: _react.Fragment
|
|
22
|
+
});
|
|
23
|
+
function ChatTrigger(_0) {
|
|
24
|
+
var classNames = _0.classNames, toggleIconComponent = _0.toggleIconComponent, onClick = _0.onClick, _0_floating = _0.floating, floating = _0_floating === void 0 ? true : _0_floating, props = _object_without_properties._(_0, [
|
|
25
|
+
"classNames",
|
|
26
|
+
"toggleIconComponent",
|
|
27
|
+
"onClick",
|
|
28
|
+
"floating"
|
|
29
|
+
]);
|
|
30
|
+
var _useChatTrigger = (0, _reactinstantsearchcore.useChatTrigger)({}, {
|
|
31
|
+
$$widgetType: 'ais.chatTrigger'
|
|
32
|
+
}), open = _useChatTrigger.open, toggleOpen = _useChatTrigger.toggleOpen;
|
|
33
|
+
var handleClick = function handleClick() {
|
|
34
|
+
toggleOpen();
|
|
35
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
36
|
+
};
|
|
37
|
+
var rootClassName = [
|
|
38
|
+
floating && 'ais-ChatToggleButton--floating',
|
|
39
|
+
classNames === null || classNames === void 0 ? void 0 : classNames.root
|
|
40
|
+
].filter(Boolean).flat();
|
|
41
|
+
return /*#__PURE__*/ _react.default.createElement(ChatToggleButton, _object_spread._({
|
|
42
|
+
open: open,
|
|
43
|
+
onClick: handleClick,
|
|
44
|
+
classNames: _object_spread_props._(_object_spread._({}, classNames), {
|
|
45
|
+
root: rootClassName
|
|
46
|
+
}),
|
|
47
|
+
toggleIconComponent: toggleIconComponent
|
|
48
|
+
}, props));
|
|
49
|
+
}
|
|
@@ -27,9 +27,11 @@ function SearchBox(_0) {
|
|
|
27
27
|
]);
|
|
28
28
|
var _useSearchBox = (0, _reactinstantsearchcore.useSearchBox)({
|
|
29
29
|
queryHook: queryHook
|
|
30
|
-
}, {
|
|
30
|
+
}, _object_spread._({
|
|
31
31
|
$$widgetType: 'ais.searchBox'
|
|
32
|
-
}
|
|
32
|
+
}, aiMode ? {
|
|
33
|
+
opensChat: true
|
|
34
|
+
} : {})), query = _useSearchBox.query, refine = _useSearchBox.refine, isSearchStalled = _useSearchBox.isSearchStalled;
|
|
33
35
|
var indexRenderState = (0, _reactinstantsearchcore.useInstantSearch)().indexRenderState;
|
|
34
36
|
var _useState = _sliced_to_array._((0, _react.useState)(query), 2), inputValue = _useState[0], setInputValue = _useState[1];
|
|
35
37
|
var inputRef = (0, _react.useRef)(null);
|
|
@@ -7,6 +7,7 @@ var _export_star = require("@swc/helpers/_/_export_star");
|
|
|
7
7
|
_export_star._(require("./Autocomplete"), exports);
|
|
8
8
|
_export_star._(require("./Breadcrumb"), exports);
|
|
9
9
|
_export_star._(require("./Chat"), exports);
|
|
10
|
+
_export_star._(require("./ChatTrigger"), exports);
|
|
10
11
|
_export_star._(require("./ClearRefinements"), exports);
|
|
11
12
|
_export_star._(require("./CurrentRefinements"), exports);
|
|
12
13
|
_export_star._(require("./FrequentlyBoughtTogether"), exports);
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { createChatInlineLayoutComponent } from 'instantsearch-ui-components';
|
|
2
|
+
export declare const ChatInlineLayout: ReturnType<typeof createChatInlineLayoutComponent> & {
|
|
3
|
+
$$inlineLayout: true;
|
|
4
|
+
};
|
|
@@ -5,5 +5,8 @@ var ChatInlineLayout = createChatInlineLayoutComponent({
|
|
|
5
5
|
createElement: createElement,
|
|
6
6
|
Fragment: Fragment
|
|
7
7
|
});
|
|
8
|
+
// Marker used by `<Chat>` to auto-exempt inline layouts from the entry-point
|
|
9
|
+
// validation, since inline chats are always visible (no trigger needed).
|
|
10
|
+
ChatInlineLayout.$$inlineLayout = true;
|
|
8
11
|
|
|
9
12
|
export { ChatInlineLayout };
|
package/dist/es/index.js
CHANGED
|
@@ -4,6 +4,7 @@ export { EXPERIMENTAL_Autocomplete } from './widgets/Autocomplete.js';
|
|
|
4
4
|
export { Breadcrumb } from './widgets/Breadcrumb.js';
|
|
5
5
|
export { DisplayResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
|
|
6
6
|
export { Chat, createDefaultTools } from './widgets/Chat.js';
|
|
7
|
+
export { ChatTrigger } from './widgets/ChatTrigger.js';
|
|
7
8
|
export { ClearRefinements } from './widgets/ClearRefinements.js';
|
|
8
9
|
export { CurrentRefinements } from './widgets/CurrentRefinements.js';
|
|
9
10
|
export { FrequentlyBoughtTogether } from './widgets/FrequentlyBoughtTogether.js';
|
|
@@ -84,5 +84,5 @@ export type AutocompleteProps<TItem extends BaseHit> = ComponentProps<'div'> & {
|
|
|
84
84
|
*/
|
|
85
85
|
aiMode?: boolean;
|
|
86
86
|
};
|
|
87
|
-
export declare function EXPERIMENTAL_Autocomplete<TItem extends BaseHit = BaseHit>({ indices, showQuerySuggestions, showPromptSuggestions, showRecent, searchParameters: userSearchParameters, detachedMediaQuery, translations: userTranslations, ...props }: AutocompleteProps<TItem>): React.JSX.Element;
|
|
87
|
+
export declare function EXPERIMENTAL_Autocomplete<TItem extends BaseHit = BaseHit>({ indices, showQuerySuggestions, showPromptSuggestions, showRecent, searchParameters: userSearchParameters, detachedMediaQuery, translations: userTranslations, aiMode, ...props }: AutocompleteProps<TItem>): React.JSX.Element;
|
|
88
88
|
export {};
|
|
@@ -190,22 +190,25 @@ function getMediaQueryList(mediaQuery) {
|
|
|
190
190
|
};
|
|
191
191
|
}
|
|
192
192
|
function EXPERIMENTAL_Autocomplete(_0) {
|
|
193
|
-
var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, props = _(_0, [
|
|
193
|
+
var _0_indices = _0.indices, indices = _0_indices === void 0 ? [] : _0_indices, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, showRecent = _0.showRecent, userSearchParameters = _0.searchParameters, detachedMediaQuery = _0.detachedMediaQuery, tmp = _0.translations, userTranslations = tmp === void 0 ? {} : tmp, aiMode = _0.aiMode, props = _(_0, [
|
|
194
194
|
"indices",
|
|
195
195
|
"showQuerySuggestions",
|
|
196
196
|
"showPromptSuggestions",
|
|
197
197
|
"showRecent",
|
|
198
198
|
"searchParameters",
|
|
199
199
|
"detachedMediaQuery",
|
|
200
|
-
"translations"
|
|
200
|
+
"translations",
|
|
201
|
+
"aiMode"
|
|
201
202
|
]);
|
|
202
203
|
var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
|
|
203
204
|
var translations = _$1({}, DEFAULT_TRANSLATIONS, userTranslations);
|
|
204
205
|
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, indexRenderState = _useInstantSearch.indexRenderState, status = _useInstantSearch.status;
|
|
205
|
-
var refine = useSearchBox({}, {
|
|
206
|
+
var refine = useSearchBox({}, _$1({
|
|
206
207
|
$$type: 'ais.autocomplete',
|
|
207
208
|
$$widgetType: 'ais.autocomplete'
|
|
208
|
-
}
|
|
209
|
+
}, aiMode ? {
|
|
210
|
+
opensChat: true
|
|
211
|
+
} : {})).refine;
|
|
209
212
|
var isSearchStalled = status === 'stalled';
|
|
210
213
|
var searchParameters = _$1({
|
|
211
214
|
hitsPerPage: 5
|
|
@@ -294,6 +297,7 @@ function EXPERIMENTAL_Autocomplete(_0) {
|
|
|
294
297
|
indexName: index.indexName
|
|
295
298
|
}, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
|
|
296
299
|
}), /*#__PURE__*/ React.createElement(InnerAutocomplete, _$4(_$1({}, props), {
|
|
300
|
+
aiMode: aiMode,
|
|
297
301
|
indicesConfig: indicesConfig,
|
|
298
302
|
refineSearchBox: refine,
|
|
299
303
|
isSearchStalled: isSearchStalled,
|
|
@@ -7,8 +7,7 @@ import type { UIMessage } from 'instantsearch.js/es/lib/chat';
|
|
|
7
7
|
import type { UseChatProps } from 'react-instantsearch-core';
|
|
8
8
|
export declare function createDefaultTools<TObject extends RecordWithObjectID>(itemComponent?: ItemComponent<TObject>, getSearchPageURL?: (nextUiState: IndexUiState) => string): UserClientSideTools;
|
|
9
9
|
type ItemComponent<TObject> = RecommendComponentProps<TObject>['itemComponent'];
|
|
10
|
-
type UiProps = Pick<ChatUiProps, 'open' | 'headerProps' | '
|
|
11
|
-
type UserToggleButtonProps = Omit<ChatUiProps['toggleButtonProps'], 'open' | 'onClick'>;
|
|
10
|
+
type UiProps = Pick<ChatUiProps, 'open' | 'headerProps' | 'messagesProps' | 'promptProps' | 'suggestionsProps' | 'headerComponent' | 'promptComponent' | 'suggestionsComponent' | 'layoutComponent' | 'sendMessage' | 'regenerate' | 'stop' | 'error'>;
|
|
12
11
|
type UserHeaderProps = Omit<ChatUiProps['headerProps'], 'onClose'>;
|
|
13
12
|
type UserMessagesProps = Omit<ChatUiProps['messagesProps'], 'messages' | 'tools' | 'indexUiState' | 'setIndexUiState' | 'scrollRef' | 'contentRef' | 'messageComponent' | 'leadingComponent' | 'footerComponent' | 'suggestionsComponent' | 'translations' | 'classNames'>;
|
|
14
13
|
type UserPromptProps = Omit<ChatUiProps['promptProps'], 'value' | 'onInput' | 'onSubmit' | 'headerComponent' | 'footerComponent'>;
|
|
@@ -18,13 +17,10 @@ export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<
|
|
|
18
17
|
itemComponent?: ItemComponent<TObject>;
|
|
19
18
|
tools?: UserClientSideTools;
|
|
20
19
|
getSearchPageURL?: (nextUiState: IndexUiState) => string;
|
|
21
|
-
toggleButtonProps?: UserToggleButtonProps;
|
|
22
20
|
headerProps?: UserHeaderProps;
|
|
23
21
|
messagesProps?: UserMessagesProps;
|
|
24
22
|
promptProps?: UserPromptProps;
|
|
25
23
|
layoutComponent?: (props: ChatLayoutOwnProps) => JSX.Element;
|
|
26
|
-
toggleButtonComponent?: ChatUiProps['toggleButtonComponent'];
|
|
27
|
-
toggleButtonIconComponent?: ChatUiProps['toggleButtonProps']['toggleIconComponent'];
|
|
28
24
|
headerComponent?: ChatUiProps['headerComponent'];
|
|
29
25
|
headerTitleIconComponent?: ChatUiProps['headerProps']['titleIconComponent'];
|
|
30
26
|
headerCloseIconComponent?: ChatUiProps['headerProps']['closeIconComponent'];
|
package/dist/es/widgets/Chat.js
CHANGED
|
@@ -25,16 +25,13 @@ function ChatInner(_0, _1) {
|
|
|
25
25
|
var _ref = [
|
|
26
26
|
_0,
|
|
27
27
|
_1
|
|
28
|
-
], _ref1 = _$1(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), userTools = _ref2.tools,
|
|
28
|
+
], _ref1 = _$1(_ref), _ref2 = _ref1[0], _rest = _ref1.slice(1), userTools = _ref2.tools, headerProps = _ref2.headerProps, messagesProps = _ref2.messagesProps, promptProps = _ref2.promptProps, itemComponent = _ref2.itemComponent, layoutComponent = _ref2.layoutComponent, headerComponent = _ref2.headerComponent, headerTitleIconComponent = _ref2.headerTitleIconComponent, headerCloseIconComponent = _ref2.headerCloseIconComponent, headerMinimizeIconComponent = _ref2.headerMinimizeIconComponent, headerMaximizeIconComponent = _ref2.headerMaximizeIconComponent, loaderComponent = _ref2.loaderComponent, messagesErrorComponent = _ref2.messagesErrorComponent, promptComponent = _ref2.promptComponent, promptHeaderComponent = _ref2.promptHeaderComponent, promptFooterComponent = _ref2.promptFooterComponent, assistantMessageLeadingComponent = _ref2.assistantMessageLeadingComponent, assistantMessageFooterComponent = _ref2.assistantMessageFooterComponent, userMessageLeadingComponent = _ref2.userMessageLeadingComponent, userMessageFooterComponent = _ref2.userMessageFooterComponent, emptyComponent = _ref2.emptyComponent, actionsComponent = _ref2.actionsComponent, suggestionsComponent = _ref2.suggestionsComponent, classNames = _ref2.classNames, _ref_translations = _ref2.translations, translations = _ref_translations === void 0 ? {} : _ref_translations, title = _ref2.title, getSearchPageURL = _ref2.getSearchPageURL, _ref_disableTriggerValidation = _ref2.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, props = _$2(_ref2, [
|
|
29
29
|
"tools",
|
|
30
|
-
"toggleButtonProps",
|
|
31
30
|
"headerProps",
|
|
32
31
|
"messagesProps",
|
|
33
32
|
"promptProps",
|
|
34
33
|
"itemComponent",
|
|
35
34
|
"layoutComponent",
|
|
36
|
-
"toggleButtonComponent",
|
|
37
|
-
"toggleButtonIconComponent",
|
|
38
35
|
"headerComponent",
|
|
39
36
|
"headerTitleIconComponent",
|
|
40
37
|
"headerCloseIconComponent",
|
|
@@ -55,7 +52,8 @@ function ChatInner(_0, _1) {
|
|
|
55
52
|
"classNames",
|
|
56
53
|
"translations",
|
|
57
54
|
"title",
|
|
58
|
-
"getSearchPageURL"
|
|
55
|
+
"getSearchPageURL",
|
|
56
|
+
"disableTriggerValidation"
|
|
59
57
|
]), _rest1 = _$3(_rest, 1), ref = _rest1[0];
|
|
60
58
|
var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
|
|
61
59
|
var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
|
|
@@ -73,8 +71,14 @@ function ChatInner(_0, _1) {
|
|
|
73
71
|
itemComponent,
|
|
74
72
|
userTools
|
|
75
73
|
]);
|
|
74
|
+
// Inline layouts are always visible, so they don't require a `<ChatTrigger />`
|
|
75
|
+
// (or AI mode) to be present. We detect this via a `$$inlineLayout` marker
|
|
76
|
+
// set on the layout component, which is consistent across flavors.
|
|
77
|
+
var isInlineLayoutComponent = typeof layoutComponent === 'function' && layoutComponent.$$inlineLayout === true;
|
|
78
|
+
var effectiveDisableTriggerValidation = disableTriggerValidation || isInlineLayoutComponent;
|
|
76
79
|
var chatState = useChat(_$5(_$4({}, props), {
|
|
77
|
-
tools: tools
|
|
80
|
+
tools: tools,
|
|
81
|
+
disableTriggerValidation: effectiveDisableTriggerValidation
|
|
78
82
|
}));
|
|
79
83
|
var messages = chatState.messages, sendMessage = chatState.sendMessage, status = chatState.status, regenerate = chatState.regenerate, stop = chatState.stop, error = chatState.error, input = chatState.input, setInput = chatState.setInput, open = chatState.open, setOpen = chatState.setOpen, isClearing = chatState.isClearing, clearMessages = chatState.clearMessages, onClearTransitionEnd = chatState.onClearTransitionEnd, toolsFromConnector = chatState.tools, suggestions = chatState.suggestions, onFeedback = chatState.sendChatMessageFeedback, feedbackState = chatState.feedbackState;
|
|
80
84
|
useImperativeHandle(ref, function() {
|
|
@@ -110,15 +114,7 @@ function ChatInner(_0, _1) {
|
|
|
110
114
|
layoutComponent: layoutComponent,
|
|
111
115
|
headerComponent: headerComponent,
|
|
112
116
|
promptComponent: promptComponent,
|
|
113
|
-
toggleButtonComponent: toggleButtonComponent,
|
|
114
117
|
suggestionsComponent: suggestionsComponent,
|
|
115
|
-
toggleButtonProps: _$4({
|
|
116
|
-
open: open,
|
|
117
|
-
onClick: function onClick() {
|
|
118
|
-
return setOpen(!open);
|
|
119
|
-
},
|
|
120
|
-
toggleIconComponent: toggleButtonIconComponent
|
|
121
|
-
}, toggleButtonProps),
|
|
122
118
|
headerProps: _$4({
|
|
123
119
|
onClose: function onClose() {
|
|
124
120
|
return setOpen(false);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ChatToggleButtonClassNames, ChatToggleButtonProps as ChatToggleButtonUiProps } from 'instantsearch-ui-components';
|
|
3
|
+
export type ChatTriggerProps = Omit<ChatToggleButtonUiProps, 'open' | 'onClick'> & {
|
|
4
|
+
/**
|
|
5
|
+
* CSS classes to add to the widget elements.
|
|
6
|
+
*/
|
|
7
|
+
classNames?: Partial<ChatToggleButtonClassNames>;
|
|
8
|
+
/**
|
|
9
|
+
* Custom icon component to replace the default sparkles/chevron icons.
|
|
10
|
+
*/
|
|
11
|
+
toggleIconComponent?: ChatToggleButtonUiProps['toggleIconComponent'];
|
|
12
|
+
/**
|
|
13
|
+
* Callback when the trigger is clicked.
|
|
14
|
+
*/
|
|
15
|
+
onClick?: () => void;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the button is positioned as a floating action button at the
|
|
18
|
+
* bottom-right of the viewport. Set to `false` to render an inline button
|
|
19
|
+
* that flows with surrounding content.
|
|
20
|
+
* @default true
|
|
21
|
+
*/
|
|
22
|
+
floating?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare function ChatTrigger({ classNames, toggleIconComponent, onClick, floating, ...props }: ChatTriggerProps): React.JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { _ as _$1 } from '@swc/helpers/esm/_object_spread.js';
|
|
2
|
+
import { _ as _$2 } from '@swc/helpers/esm/_object_spread_props.js';
|
|
3
|
+
import { _ } from '@swc/helpers/esm/_object_without_properties.js';
|
|
4
|
+
import { createChatToggleButtonComponent } from 'instantsearch-ui-components';
|
|
5
|
+
import React, { createElement, Fragment } from 'react';
|
|
6
|
+
import { useChatTrigger } from 'react-instantsearch-core';
|
|
7
|
+
|
|
8
|
+
var ChatToggleButton = createChatToggleButtonComponent({
|
|
9
|
+
createElement: createElement,
|
|
10
|
+
Fragment: Fragment
|
|
11
|
+
});
|
|
12
|
+
function ChatTrigger(_0) {
|
|
13
|
+
var classNames = _0.classNames, toggleIconComponent = _0.toggleIconComponent, onClick = _0.onClick, _0_floating = _0.floating, floating = _0_floating === void 0 ? true : _0_floating, props = _(_0, [
|
|
14
|
+
"classNames",
|
|
15
|
+
"toggleIconComponent",
|
|
16
|
+
"onClick",
|
|
17
|
+
"floating"
|
|
18
|
+
]);
|
|
19
|
+
var _useChatTrigger = useChatTrigger({}, {
|
|
20
|
+
$$widgetType: 'ais.chatTrigger'
|
|
21
|
+
}), open = _useChatTrigger.open, toggleOpen = _useChatTrigger.toggleOpen;
|
|
22
|
+
var handleClick = function handleClick() {
|
|
23
|
+
toggleOpen();
|
|
24
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
25
|
+
};
|
|
26
|
+
var rootClassName = [
|
|
27
|
+
floating && 'ais-ChatToggleButton--floating',
|
|
28
|
+
classNames === null || classNames === void 0 ? void 0 : classNames.root
|
|
29
|
+
].filter(Boolean).flat();
|
|
30
|
+
return /*#__PURE__*/ React.createElement(ChatToggleButton, _$1({
|
|
31
|
+
open: open,
|
|
32
|
+
onClick: handleClick,
|
|
33
|
+
classNames: _$2(_$1({}, classNames), {
|
|
34
|
+
root: rootClassName
|
|
35
|
+
}),
|
|
36
|
+
toggleIconComponent: toggleIconComponent
|
|
37
|
+
}, props));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { ChatTrigger };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as _$
|
|
1
|
+
import { _ as _$1 } from '@swc/helpers/esm/_object_spread.js';
|
|
2
2
|
import { _ } from '@swc/helpers/esm/_object_without_properties.js';
|
|
3
|
-
import { _ as _$
|
|
3
|
+
import { _ as _$2 } from '@swc/helpers/esm/_sliced_to_array.js';
|
|
4
4
|
import { openChat, isChatBusy } from 'instantsearch.js/es/lib/chat/index.js';
|
|
5
5
|
import React, { useState, useRef } from 'react';
|
|
6
6
|
import { useSearchBox, useInstantSearch } from 'react-instantsearch-core';
|
|
@@ -16,11 +16,13 @@ function SearchBox(_0) {
|
|
|
16
16
|
]);
|
|
17
17
|
var _useSearchBox = useSearchBox({
|
|
18
18
|
queryHook: queryHook
|
|
19
|
-
}, {
|
|
19
|
+
}, _$1({
|
|
20
20
|
$$widgetType: 'ais.searchBox'
|
|
21
|
-
}
|
|
21
|
+
}, aiMode ? {
|
|
22
|
+
opensChat: true
|
|
23
|
+
} : {})), query = _useSearchBox.query, refine = _useSearchBox.refine, isSearchStalled = _useSearchBox.isSearchStalled;
|
|
22
24
|
var indexRenderState = useInstantSearch().indexRenderState;
|
|
23
|
-
var _useState = _$
|
|
25
|
+
var _useState = _$2(useState(query), 2), inputValue = _useState[0], setInputValue = _useState[1];
|
|
24
26
|
var inputRef = useRef(null);
|
|
25
27
|
function setQuery(newQuery) {
|
|
26
28
|
var isComposing = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
|
|
@@ -70,13 +72,13 @@ function SearchBox(_0) {
|
|
|
70
72
|
} : undefined,
|
|
71
73
|
aiModeButtonDisabled: aiMode ? isChatBusy(chatRenderState) : undefined,
|
|
72
74
|
value: inputValue,
|
|
73
|
-
translations: _$
|
|
75
|
+
translations: _$1({
|
|
74
76
|
submitButtonTitle: 'Submit the search query',
|
|
75
77
|
resetButtonTitle: 'Clear the search query',
|
|
76
78
|
aiModeButtonTitle: 'AI Mode'
|
|
77
79
|
}, translations)
|
|
78
80
|
};
|
|
79
|
-
return /*#__PURE__*/ React.createElement(SearchBox$1, _$
|
|
81
|
+
return /*#__PURE__*/ React.createElement(SearchBox$1, _$1({}, props, uiProps));
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
export { SearchBox };
|
package/dist/es/widgets/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { EXPERIMENTAL_Autocomplete } from './Autocomplete.js';
|
|
2
2
|
export { Breadcrumb } from './Breadcrumb.js';
|
|
3
3
|
export { Chat, createDefaultTools } from './Chat.js';
|
|
4
|
+
export { ChatTrigger } from './ChatTrigger.js';
|
|
4
5
|
export { ClearRefinements } from './ClearRefinements.js';
|
|
5
6
|
export { CurrentRefinements } from './CurrentRefinements.js';
|
|
6
7
|
export { FrequentlyBoughtTogether } from './FrequentlyBoughtTogether.js';
|