react-instantsearch 7.40.0 → 7.42.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.
@@ -6,14 +6,14 @@ import { _ as _$3 } from '@swc/helpers/esm/_to_consumable_array.js';
6
6
  import { _ as _$5 } from '@swc/helpers/esm/_type_of.js';
7
7
  import { createAutocompleteComponent, createAutocompletePanelComponent, createAutocompleteIndexComponent, createAutocompleteSuggestionComponent, createAutocompletePromptSuggestionComponent, createAutocompleteRecentSearchComponent, createAutocompleteDetachedContainerComponent, createAutocompleteDetachedOverlayComponent, createAutocompleteDetachedFormContainerComponent, createAutocompleteDetachedSearchButtonComponent, createAutocompletePropGetters, createAutocompleteStorage, cx, getPromptSuggestionHits, isPromptSuggestion } from 'instantsearch-ui-components';
8
8
  import { openChat, isChatBusy } from 'instantsearch.js/es/lib/chat/index.js';
9
- import 'instantsearch.js/es/lib/utils/index.js';
9
+ import { deprecate } from 'instantsearch.js/es/lib/utils/index.js';
10
10
  import React, { createElement, Fragment, useEffect, useMemo, useRef, useState, useLayoutEffect } from 'react';
11
11
  import { useInstantSearch, useInstantSearchContext, useSearchBox, Index, Configure, Feeds, useAutocomplete } from 'react-instantsearch-core';
12
12
  import { AutocompleteSearch } from '../components/AutocompleteSearch.js';
13
13
  import { Highlight } from './Highlight.js';
14
14
  import { ReverseHighlight } from './ReverseHighlight.js';
15
15
 
16
- var Autocomplete = createAutocompleteComponent({
16
+ var AutocompleteUiComponent = createAutocompleteComponent({
17
17
  createElement: createElement,
18
18
  Fragment: Fragment
19
19
  });
@@ -199,7 +199,7 @@ function getMediaQueryList(mediaQuery) {
199
199
  setIsModalOpen: setIsModalOpen
200
200
  };
201
201
  }
202
- function EXPERIMENTAL_Autocomplete(props) {
202
+ function Autocomplete(props) {
203
203
  var _showRecent_classNames, _showRecent_classNames1, _showRecent_classNames2, _showRecent_classNames3;
204
204
  var indices = 'indices' in props ? props.indices : undefined;
205
205
  var feeds = 'feeds' in props ? props.feeds : undefined;
@@ -232,10 +232,10 @@ function EXPERIMENTAL_Autocomplete(props) {
232
232
  var domId = useAutocompleteId();
233
233
  var instanceKey = domId.replace(/:/g, '');
234
234
  if (isFeedsMode && indices !== undefined) {
235
- throw new Error('EXPERIMENTAL_Autocomplete: `feeds` and `indices` are mutually exclusive.');
235
+ throw new Error('Autocomplete: `feeds` and `indices` are mutually exclusive.');
236
236
  }
237
237
  if (isFeedsMode && !compositionID) {
238
- throw new Error('EXPERIMENTAL_Autocomplete in feeds-mode requires a composition-based <InstantSearch> (compositionID must be set).');
238
+ throw new Error('Autocomplete in feeds-mode requires a composition-based <InstantSearch> (compositionID must be set).');
239
239
  }
240
240
  var isSearchStalled = status === 'stalled';
241
241
  var searchParameters = _$2({
@@ -450,7 +450,7 @@ function EXPERIMENTAL_Autocomplete(props) {
450
450
  }
451
451
  setActivated(true);
452
452
  };
453
- return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$2({}, shellRootProps), {
453
+ return /*#__PURE__*/ React.createElement(AutocompleteUiComponent, _$4(_$2({}, shellRootProps), {
454
454
  classNames: classNames
455
455
  }), isDetached ? /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
456
456
  query: (_indexUiState_query = indexUiState.query) !== null && _indexUiState_query !== void 0 ? _indexUiState_query : '',
@@ -493,7 +493,7 @@ function EXPERIMENTAL_Autocomplete(props) {
493
493
  }));
494
494
  if (isFeedsMode) {
495
495
  return /*#__PURE__*/ React.createElement(Index, {
496
- EXPERIMENTAL_isolated: true,
496
+ isolated: true,
497
497
  indexName: compositionID,
498
498
  indexId: "ais-autocomplete-".concat(instanceKey)
499
499
  }, /*#__PURE__*/ React.createElement(Configure, searchParameters), /*#__PURE__*/ React.createElement(Feeds, {
@@ -504,7 +504,7 @@ function EXPERIMENTAL_Autocomplete(props) {
504
504
  }), innerAutocomplete);
505
505
  }
506
506
  return /*#__PURE__*/ React.createElement(Index, {
507
- EXPERIMENTAL_isolated: true,
507
+ isolated: true,
508
508
  indexId: "ais-autocomplete-".concat(instanceKey)
509
509
  }, /*#__PURE__*/ React.createElement(Configure, searchParameters), indicesConfig.map(function(index) {
510
510
  return /*#__PURE__*/ React.createElement(Index, {
@@ -514,6 +514,7 @@ function EXPERIMENTAL_Autocomplete(props) {
514
514
  }, /*#__PURE__*/ React.createElement(Configure, index.searchParameters));
515
515
  }), innerAutocomplete);
516
516
  }
517
+ /** @deprecated use Autocomplete instead */ var EXPERIMENTAL_Autocomplete = deprecate(Autocomplete, 'EXPERIMENTAL_Autocomplete is no longer experimental. Please use Autocomplete instead.');
517
518
  function InnerAutocomplete(_0) {
518
519
  var indicesConfig = _0.indicesConfig, refineSearchBox = _0.refineSearchBox, isSearchStalled = _0.isSearchStalled, getSearchPageURL = _0.getSearchPageURL, userOnSelect = _0.onSelect, indexUiState = _0.indexUiState, isSearchPage = _0.isSearchPage, PanelComponent = _0.panelComponent, showRecent = _0.showRecent, recentSearchConfig = _0.recentSearchConfig, showQuerySuggestions = _0.showQuerySuggestions, showPromptSuggestions = _0.showPromptSuggestions, chatRenderState = _0.chatRenderState, transformItems = _0.transformItems, placeholder = _0.placeholder, autoFocus = _0.autoFocus, translations = _0.translations, classNames = _0.classNames, aiMode = _0.aiMode, domId = _0.domId, detached = _0.detached, props = _(_0, [
519
520
  "indicesConfig",
@@ -630,7 +631,7 @@ function InnerAutocomplete(_0) {
630
631
  if (chatRenderState) {
631
632
  if (openChat(chatRenderState, {
632
633
  message: item.prompt,
633
- referer: 'prompt-suggestions'
634
+ referer: 'prompt-suggestions-autocomplete'
634
635
  })) {
635
636
  setQuery('');
636
637
  }
@@ -799,7 +800,7 @@ function InnerAutocomplete(_0) {
799
800
  "ref"
800
801
  ]);
801
802
  if (isDetached) {
802
- return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$2({}, props, rootProps), {
803
+ return /*#__PURE__*/ React.createElement(AutocompleteUiComponent, _$4(_$2({}, props, rootProps), {
803
804
  rootRef: rootRef,
804
805
  classNames: classNames
805
806
  }), /*#__PURE__*/ React.createElement(AutocompleteDetachedSearchButton, {
@@ -825,7 +826,7 @@ function InnerAutocomplete(_0) {
825
826
  }, searchBoxContent), panelContent)));
826
827
  }
827
828
  // Normal (non-detached) rendering
828
- return /*#__PURE__*/ React.createElement(Autocomplete, _$4(_$2({}, props, rootProps), {
829
+ return /*#__PURE__*/ React.createElement(AutocompleteUiComponent, _$4(_$2({}, props, rootProps), {
829
830
  rootRef: rootRef,
830
831
  classNames: classNames
831
832
  }), searchBoxContent, panelContent);
@@ -855,4 +856,4 @@ function ConditionalHighlight(param) {
855
856
  });
856
857
  }
857
858
 
858
- export { EXPERIMENTAL_Autocomplete };
859
+ export { Autocomplete, EXPERIMENTAL_Autocomplete };
@@ -38,6 +38,10 @@ export type ChatProps<TObject, TUiMessage extends UIMessage = UIMessage> = Omit<
38
38
  userMessageLeadingComponent?: ChatMessageProps['leadingComponent'];
39
39
  userMessageFooterComponent?: ChatMessageProps['footerComponent'];
40
40
  suggestionsComponent?: ChatUiProps['suggestionsComponent'];
41
+ /**
42
+ * Whether to render reasoning parts
43
+ */
44
+ showReasoning?: boolean;
41
45
  translations?: Partial<{
42
46
  prompt: ChatUiProps['promptProps']['translations'];
43
47
  header: ChatUiProps['headerProps']['translations'];
@@ -1,13 +1,13 @@
1
1
  import { _ } from '@swc/helpers/esm/_define_property.js';
2
- import { _ as _$4 } from '@swc/helpers/esm/_object_spread.js';
3
- import { _ as _$5 } from '@swc/helpers/esm/_object_spread_props.js';
2
+ import { _ as _$5 } from '@swc/helpers/esm/_object_spread.js';
3
+ import { _ as _$4 } from '@swc/helpers/esm/_object_spread_props.js';
4
4
  import { _ as _$2 } from '@swc/helpers/esm/_object_without_properties.js';
5
5
  import { _ as _$3 } from '@swc/helpers/esm/_sliced_to_array.js';
6
6
  import { _ as _$1 } from '@swc/helpers/esm/_to_array.js';
7
7
  import { createChatComponent } from 'instantsearch-ui-components';
8
8
  import { SearchIndexToolType, RecommendToolType, DisplayResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType } from 'instantsearch.js/es/lib/chat/index.js';
9
9
  export { DisplayResultsToolType, MemorizeToolType, MemorySearchToolType, PonderToolType, RecommendToolType, SearchIndexToolType } from 'instantsearch.js/es/lib/chat/index.js';
10
- import React, { createElement, Fragment, memo, useState, useRef, useMemo, useImperativeHandle, useEffect } from 'react';
10
+ import React, { createElement, Fragment, useMemo, useState, useRef, useImperativeHandle, useEffect } from 'react';
11
11
  import { useInstantSearch, useChat } from 'react-instantsearch-core';
12
12
  import { useStickToBottom } from '../lib/useStickToBottom.js';
13
13
  import { createDisplayResultsTool } from './chat/tools/DisplayResultsTool.js';
@@ -16,18 +16,35 @@ import { createCarouselTool } from './chat/tools/SearchIndexTool.js';
16
16
  var ChatUiComponent = createChatComponent({
17
17
  createElement: createElement,
18
18
  Fragment: Fragment,
19
- memo: memo,
19
+ useMemo: useMemo,
20
20
  useState: useState
21
21
  });
22
22
  function createDefaultTools(itemComponent, getSearchPageURL) {
23
23
  var _obj;
24
24
  return _obj = {}, _(_obj, SearchIndexToolType, createCarouselTool(true, itemComponent, getSearchPageURL)), _(_obj, RecommendToolType, createCarouselTool(false, itemComponent, getSearchPageURL)), _(_obj, DisplayResultsToolType, createDisplayResultsTool(itemComponent)), _(_obj, MemorizeToolType, {}), _(_obj, MemorySearchToolType, {}), _(_obj, PonderToolType, {}), _obj;
25
25
  }
26
+ function mergeToolOptions(defaultTools, userTools) {
27
+ if (!userTools) {
28
+ return defaultTools;
29
+ }
30
+ var tools = _$5({}, defaultTools, userTools);
31
+ Object.keys(userTools).forEach(function(toolName) {
32
+ var _defaultTools_toolName;
33
+ var userTool = userTools[toolName];
34
+ var defaultStreamInput = (_defaultTools_toolName = defaultTools[toolName]) === null || _defaultTools_toolName === void 0 ? void 0 : _defaultTools_toolName.streamInput;
35
+ if (userTool.layoutComponent !== undefined && userTool.streamInput === undefined && defaultStreamInput !== undefined) {
36
+ tools[toolName] = _$4(_$5({}, userTool), {
37
+ streamInput: defaultStreamInput
38
+ });
39
+ }
40
+ });
41
+ return tools;
42
+ }
26
43
  function ChatInner(_0, _1) {
27
44
  var _ref = [
28
45
  _0,
29
46
  _1
30
- ], _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, [
47
+ ], _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, showReasoning = _ref2.showReasoning, props = _$2(_ref2, [
31
48
  "tools",
32
49
  "headerProps",
33
50
  "messagesProps",
@@ -55,7 +72,8 @@ function ChatInner(_0, _1) {
55
72
  "translations",
56
73
  "title",
57
74
  "getSearchPageURL",
58
- "disableTriggerValidation"
75
+ "disableTriggerValidation",
76
+ "showReasoning"
59
77
  ]), _rest1 = _$3(_rest, 1), ref = _rest1[0];
60
78
  var promptTranslations = translations.prompt, headerTranslations = translations.header, messageTranslations = translations.message, messagesTranslations = translations.messages;
61
79
  var _useInstantSearch = useInstantSearch(), indexUiState = _useInstantSearch.indexUiState, setIndexUiState = _useInstantSearch.setIndexUiState;
@@ -67,7 +85,7 @@ function ChatInner(_0, _1) {
67
85
  }), scrollRef = _useStickToBottom.scrollRef, contentRef = _useStickToBottom.contentRef, scrollToBottom = _useStickToBottom.scrollToBottom, isAtBottom = _useStickToBottom.isAtBottom;
68
86
  var tools = useMemo(function() {
69
87
  var defaults = createDefaultTools(itemComponent, getSearchPageURL);
70
- return _$4({}, defaults, userTools);
88
+ return mergeToolOptions(defaults, userTools);
71
89
  }, [
72
90
  getSearchPageURL,
73
91
  itemComponent,
@@ -78,7 +96,7 @@ function ChatInner(_0, _1) {
78
96
  // set on the layout component, which is consistent across flavors.
79
97
  var isInlineLayoutComponent = typeof layoutComponent === 'function' && layoutComponent.$$inlineLayout === true;
80
98
  var effectiveDisableTriggerValidation = disableTriggerValidation || isInlineLayoutComponent;
81
- var chatState = useChat(_$5(_$4({}, props), {
99
+ var chatState = useChat(_$4(_$5({}, props), {
82
100
  tools: tools,
83
101
  disableTriggerValidation: effectiveDisableTriggerValidation
84
102
  }));
@@ -122,6 +140,10 @@ function ChatInner(_0, _1) {
122
140
  status,
123
141
  scrollToBottom
124
142
  ]);
143
+ var _ref3 = messagesProps !== null && messagesProps !== void 0 ? messagesProps : {}, callerAssistantMessageProps = _ref3.assistantMessageProps, callerUserMessageProps = _ref3.userMessageProps, restMessagesProps = _$2(_ref3, [
144
+ "assistantMessageProps",
145
+ "userMessageProps"
146
+ ]);
125
147
  return /*#__PURE__*/ React.createElement(ChatUiComponent, {
126
148
  title: title,
127
149
  open: open,
@@ -134,7 +156,7 @@ function ChatInner(_0, _1) {
134
156
  headerComponent: headerComponent,
135
157
  promptComponent: promptComponent,
136
158
  suggestionsComponent: suggestionsComponent,
137
- headerProps: _$4({
159
+ headerProps: _$5({
138
160
  onClose: function onClose() {
139
161
  return setOpen(false);
140
162
  },
@@ -150,7 +172,7 @@ function ChatInner(_0, _1) {
150
172
  maximizeIconComponent: headerMaximizeIconComponent,
151
173
  translations: headerTranslations
152
174
  }, headerProps),
153
- messagesProps: _$5(_$4({
175
+ messagesProps: _$4(_$5({
154
176
  status: status,
155
177
  onReload: function onReload(messageId) {
156
178
  return regenerate({
@@ -177,20 +199,21 @@ function ChatInner(_0, _1) {
177
199
  errorComponent: messagesErrorComponent,
178
200
  emptyComponent: emptyComponent,
179
201
  actionsComponent: actionsComponent,
180
- assistantMessageProps: _$4({
202
+ translations: messagesTranslations,
203
+ messageTranslations: messageTranslations
204
+ }, restMessagesProps), {
205
+ assistantMessageProps: _$5({
181
206
  leadingComponent: assistantMessageLeadingComponent,
182
- footerComponent: assistantMessageFooterComponent
183
- }, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.assistantMessageProps),
184
- userMessageProps: _$4({
207
+ footerComponent: assistantMessageFooterComponent,
208
+ showReasoning: showReasoning
209
+ }, callerAssistantMessageProps),
210
+ userMessageProps: _$5({
185
211
  leadingComponent: userMessageLeadingComponent,
186
212
  footerComponent: userMessageFooterComponent
187
- }, messagesProps === null || messagesProps === void 0 ? void 0 : messagesProps.userMessageProps),
188
- translations: messagesTranslations,
189
- messageTranslations: messageTranslations
190
- }, messagesProps), {
213
+ }, callerUserMessageProps),
191
214
  error: error
192
215
  }),
193
- promptProps: _$4({
216
+ promptProps: _$5({
194
217
  promptRef: promptRef,
195
218
  status: status,
196
219
  value: input,
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import type { PromptSuggestionsOwnProps } from 'instantsearch-ui-components';
3
+ import type { UsePromptSuggestionsProps } from 'react-instantsearch-core';
4
+ /**
5
+ * Props passed to a custom `layoutComponent`. Mirrors the connector render
6
+ * state so a layout component owns the full markup.
7
+ */
8
+ export type PromptSuggestionsLayoutComponentProps = {
9
+ suggestions: string[];
10
+ isLoading: boolean;
11
+ onSuggestionClick: (prompt: string) => void;
12
+ isChatBusy: boolean;
13
+ };
14
+ export type PromptSuggestionsOnSuggestionClick = (prompt: string, helpers: {
15
+ sendToChat: (prompt: string) => boolean;
16
+ }) => void;
17
+ type OwnedUiProps = 'suggestions' | 'isLoading' | 'onSuggestionClick' | 'disabled' | 'skeletonCount';
18
+ export type PromptSuggestionsProps = Omit<PromptSuggestionsOwnProps, OwnedUiProps> & UsePromptSuggestionsProps & {
19
+ layoutComponent?: (props: PromptSuggestionsLayoutComponentProps) => JSX.Element | null;
20
+ onSuggestionClick?: PromptSuggestionsOnSuggestionClick;
21
+ };
22
+ export declare function PromptSuggestions({ classNames, layoutComponent: LayoutComponent, onSuggestionClick: onSuggestionClickOverride, agentId, transport, configurationId, transformHits, context, transformItems, ...props }: PromptSuggestionsProps): React.JSX.Element;
23
+ export {};
@@ -0,0 +1,57 @@
1
+ import { _ as _$2 } from '@swc/helpers/esm/_object_spread.js';
2
+ import { _ as _$1 } from '@swc/helpers/esm/_object_spread_props.js';
3
+ import { _ } from '@swc/helpers/esm/_object_without_properties.js';
4
+ import { createPromptSuggestionsComponent } from 'instantsearch-ui-components';
5
+ import React, { createElement, Fragment } from 'react';
6
+ import { usePromptSuggestions } from 'react-instantsearch-core';
7
+
8
+ var PromptSuggestionsUi = createPromptSuggestionsComponent({
9
+ createElement: createElement,
10
+ Fragment: Fragment
11
+ });
12
+ function PromptSuggestions(_0) {
13
+ var _0_classNames = _0.classNames, classNames = _0_classNames === void 0 ? {} : _0_classNames, LayoutComponent = _0.layoutComponent, onSuggestionClickOverride = _0.onSuggestionClick, // Connector params — forwarded to the hook, not the UI root.
14
+ agentId = _0.agentId, transport = _0.transport, configurationId = _0.configurationId, transformHits = _0.transformHits, context = _0.context, transformItems = _0.transformItems, props = _(_0, [
15
+ "classNames",
16
+ "layoutComponent",
17
+ "onSuggestionClick",
18
+ "agentId",
19
+ "transport",
20
+ "configurationId",
21
+ "transformHits",
22
+ "context",
23
+ "transformItems"
24
+ ]);
25
+ var _usePromptSuggestions = usePromptSuggestions({
26
+ agentId: agentId,
27
+ transport: transport,
28
+ configurationId: configurationId,
29
+ transformHits: transformHits,
30
+ context: context,
31
+ transformItems: transformItems
32
+ }, {
33
+ $$widgetType: 'ais.promptSuggestions'
34
+ }), suggestions = _usePromptSuggestions.suggestions, isLoading = _usePromptSuggestions.isLoading, onSuggestionClick = _usePromptSuggestions.onSuggestionClick, isChatBusy = _usePromptSuggestions.isChatBusy, sendToChat = _usePromptSuggestions.sendToChat;
35
+ var handleClick = onSuggestionClickOverride ? function(prompt) {
36
+ return onSuggestionClickOverride(prompt, {
37
+ sendToChat: sendToChat
38
+ });
39
+ } : onSuggestionClick;
40
+ if (LayoutComponent) {
41
+ return /*#__PURE__*/ React.createElement(LayoutComponent, {
42
+ suggestions: suggestions,
43
+ isLoading: isLoading,
44
+ onSuggestionClick: handleClick,
45
+ isChatBusy: isChatBusy
46
+ });
47
+ }
48
+ return /*#__PURE__*/ React.createElement(PromptSuggestionsUi, _$1(_$2({}, props), {
49
+ classNames: classNames,
50
+ suggestions: suggestions,
51
+ isLoading: isLoading,
52
+ onSuggestionClick: handleClick,
53
+ disabled: isChatBusy
54
+ }));
55
+ }
56
+
57
+ export { PromptSuggestions };
@@ -1,16 +1,48 @@
1
1
  import { createDisplayResultsToolComponent, createButtonComponent, ChevronLeftIcon, ChevronRightIcon } from 'instantsearch-ui-components';
2
- import React, { createElement, Fragment, useMemo } from 'react';
2
+ import React, { createElement, Fragment, useEffect, useMemo, useRef } from 'react';
3
3
  import { Carousel } from '../../../components/Carousel.js';
4
4
 
5
5
  function createDisplayResultsTool(itemComponent) {
6
6
  var DisplayResultsUIComponent = createDisplayResultsToolComponent({
7
7
  createElement: createElement,
8
8
  Fragment: Fragment,
9
- useMemo: useMemo
9
+ useEffect: useEffect,
10
+ useMemo: useMemo,
11
+ useRef: useRef
10
12
  });
11
13
  var Button = createButtonComponent({
12
14
  createElement: createElement
13
15
  });
16
+ var DisplayResultsCarouselHeader = function DisplayResultsCarouselHeader(param) {
17
+ var nbItems = param.nbItems, canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight;
18
+ return /*#__PURE__*/ React.createElement("div", {
19
+ className: "ais-ChatToolDisplayResultsCarouselHeader"
20
+ }, /*#__PURE__*/ React.createElement("div", {
21
+ className: "ais-ChatToolDisplayResultsCarouselHeaderCount"
22
+ }, nbItems, " result", nbItems > 1 ? 's' : ''), /*#__PURE__*/ React.createElement("div", {
23
+ className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButtons"
24
+ }, /*#__PURE__*/ React.createElement(Button, {
25
+ variant: "outline",
26
+ size: "sm",
27
+ iconOnly: true,
28
+ "aria-label": "Previous",
29
+ onClick: scrollLeft,
30
+ disabled: !canScrollLeft,
31
+ className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
32
+ }, /*#__PURE__*/ React.createElement(ChevronLeftIcon, {
33
+ createElement: createElement
34
+ })), /*#__PURE__*/ React.createElement(Button, {
35
+ variant: "outline",
36
+ size: "sm",
37
+ iconOnly: true,
38
+ "aria-label": "Next",
39
+ onClick: scrollRight,
40
+ disabled: !canScrollRight,
41
+ className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
42
+ }, /*#__PURE__*/ React.createElement(ChevronRightIcon, {
43
+ createElement: createElement
44
+ }))));
45
+ };
14
46
  var DisplayResultsLayoutComponent = function DisplayResultsLayoutComponent(toolProps) {
15
47
  return /*#__PURE__*/ React.createElement(DisplayResultsUIComponent, {
16
48
  toolProps: toolProps,
@@ -21,40 +53,14 @@ function createDisplayResultsTool(itemComponent) {
21
53
  itemComponent: itemComponent,
22
54
  sendEvent: sendEvent,
23
55
  showNavigation: false,
24
- headerComponent: function headerComponent(param) {
25
- var canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight;
26
- return /*#__PURE__*/ React.createElement("div", {
27
- className: "ais-ChatToolDisplayResultsCarouselHeader"
28
- }, /*#__PURE__*/ React.createElement("div", {
29
- className: "ais-ChatToolDisplayResultsCarouselHeaderCount"
30
- }, items.length, " result", items.length > 1 ? 's' : ''), /*#__PURE__*/ React.createElement("div", {
31
- className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButtons"
32
- }, /*#__PURE__*/ React.createElement(Button, {
33
- variant: "outline",
34
- size: "sm",
35
- iconOnly: true,
36
- onClick: scrollLeft,
37
- disabled: !canScrollLeft,
38
- className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
39
- }, /*#__PURE__*/ React.createElement(ChevronLeftIcon, {
40
- createElement: createElement
41
- })), /*#__PURE__*/ React.createElement(Button, {
42
- variant: "outline",
43
- size: "sm",
44
- iconOnly: true,
45
- onClick: scrollRight,
46
- disabled: !canScrollRight,
47
- className: "ais-ChatToolDisplayResultsCarouselHeaderScrollButton"
48
- }, /*#__PURE__*/ React.createElement(ChevronRightIcon, {
49
- createElement: createElement
50
- }))));
51
- }
56
+ headerComponent: DisplayResultsCarouselHeader
52
57
  });
53
58
  }
54
59
  });
55
60
  };
56
61
  return {
57
- layoutComponent: DisplayResultsLayoutComponent
62
+ layoutComponent: DisplayResultsLayoutComponent,
63
+ streamInput: true
58
64
  };
59
65
  }
60
66
 
@@ -1,96 +1,25 @@
1
- import { _ } from '@swc/helpers/esm/_object_spread.js';
2
- import { createButtonComponent, getFacetFiltersFromToolInput, ArrowRightIcon, ChevronLeftIcon, ChevronRightIcon } from 'instantsearch-ui-components';
3
- import { addAbsolutePosition, addQueryID } from 'instantsearch.js/es/lib/utils/index.js';
4
- import React, { createElement } from 'react';
5
- import { Carousel } from '../../../components/Carousel.js';
1
+ import { createCarouselToolComponent } from 'instantsearch-ui-components';
2
+ import React, { createElement, Fragment, useEffect, useMemo, useRef, useState } from 'react';
6
3
 
7
4
  function createCarouselTool(showViewAll, itemComponent, getSearchPageURL) {
8
- var Button = createButtonComponent({
9
- createElement: createElement
5
+ var SearchLayoutUIComponent = createCarouselToolComponent({
6
+ createElement: createElement,
7
+ Fragment: Fragment,
8
+ useEffect: useEffect,
9
+ useMemo: useMemo,
10
+ useRef: useRef,
11
+ useState: useState
10
12
  });
11
- function SearchLayoutComponent(param) {
12
- var message = param.message, applyFilters = param.applyFilters, onClose = param.onClose, sendEvent = param.sendEvent;
13
- var _ref;
14
- var _output_hits;
15
- var input = message === null || message === void 0 ? void 0 : message.input;
16
- var output = message === null || message === void 0 ? void 0 : message.output;
17
- var hitsWithAbsolutePosition = addAbsolutePosition((output === null || output === void 0 ? void 0 : output.hits) || [], 0, ((_ref = input === null || input === void 0 ? void 0 : input.number_of_results) !== null && _ref !== void 0 ? _ref : output === null || output === void 0 ? void 0 : (_output_hits = output.hits) === null || _output_hits === void 0 ? void 0 : _output_hits.length) || 5);
18
- var items = addQueryID(hitsWithAbsolutePosition, output === null || output === void 0 ? void 0 : output.queryID);
19
- var MemoedHeaderComponent = React.useMemo(function() {
20
- return function(props) {
21
- return /*#__PURE__*/ React.createElement(HeaderComponent, _({
22
- nbHits: output === null || output === void 0 ? void 0 : output.nbHits,
23
- input: input,
24
- hitsPerPage: items.length,
25
- onClose: onClose,
26
- applyFilters: applyFilters
27
- }, props));
28
- };
29
- }, [
30
- items.length,
31
- input,
32
- output === null || output === void 0 ? void 0 : output.nbHits,
33
- applyFilters,
34
- onClose
35
- ]);
36
- return /*#__PURE__*/ React.createElement(Carousel, {
37
- items: items,
13
+ var SearchLayoutComponent = function SearchLayoutComponent(toolProps) {
14
+ return /*#__PURE__*/ React.createElement(SearchLayoutUIComponent, {
15
+ getSearchPageURL: getSearchPageURL,
16
+ headerProps: {
17
+ showViewAll: showViewAll
18
+ },
38
19
  itemComponent: itemComponent,
39
- sendEvent: sendEvent,
40
- showNavigation: false,
41
- headerComponent: MemoedHeaderComponent
20
+ toolProps: toolProps
42
21
  });
43
- }
44
- function HeaderComponent(param) {
45
- var canScrollLeft = param.canScrollLeft, canScrollRight = param.canScrollRight, scrollLeft = param.scrollLeft, scrollRight = param.scrollRight, nbHits = param.nbHits, input = param.input, hitsPerPage = param.hitsPerPage, applyFilters = param.applyFilters, onClose = param.onClose;
46
- if ((hitsPerPage !== null && hitsPerPage !== void 0 ? hitsPerPage : 0) < 1) {
47
- return null;
48
- }
49
- return /*#__PURE__*/ React.createElement("div", {
50
- className: "ais-ChatToolSearchIndexCarouselHeader"
51
- }, /*#__PURE__*/ React.createElement("div", {
52
- className: "ais-ChatToolSearchIndexCarouselHeaderResults"
53
- }, nbHits && /*#__PURE__*/ React.createElement("div", {
54
- className: "ais-ChatToolSearchIndexCarouselHeaderCount"
55
- }, hitsPerPage !== null && hitsPerPage !== void 0 ? hitsPerPage : 0, " of ", nbHits.toLocaleString(), " result", nbHits > 1 ? 's' : ''), showViewAll && /*#__PURE__*/ React.createElement(Button, {
56
- variant: "ghost",
57
- size: "sm",
58
- onClick: function onClick() {
59
- if (!input || !applyFilters) return;
60
- var params = applyFilters({
61
- query: input.query,
62
- facetFilters: getFacetFiltersFromToolInput(input)
63
- });
64
- if (getSearchPageURL && new URL(getSearchPageURL(params)).pathname !== window.location.pathname) {
65
- window.location.href = getSearchPageURL(params);
66
- }
67
- onClose();
68
- },
69
- className: "ais-ChatToolSearchIndexCarouselHeaderViewAll"
70
- }, "View all", /*#__PURE__*/ React.createElement(ArrowRightIcon, {
71
- createElement: createElement
72
- }))), (hitsPerPage !== null && hitsPerPage !== void 0 ? hitsPerPage : 0) > 2 && /*#__PURE__*/ React.createElement("div", {
73
- className: "ais-ChatToolSearchIndexCarouselHeaderScrollButtons"
74
- }, /*#__PURE__*/ React.createElement(Button, {
75
- variant: "outline",
76
- size: "sm",
77
- iconOnly: true,
78
- onClick: scrollLeft,
79
- disabled: !canScrollLeft,
80
- className: "ais-ChatToolSearchIndexCarouselHeaderScrollButton"
81
- }, /*#__PURE__*/ React.createElement(ChevronLeftIcon, {
82
- createElement: createElement
83
- })), /*#__PURE__*/ React.createElement(Button, {
84
- variant: "outline",
85
- size: "sm",
86
- iconOnly: true,
87
- onClick: scrollRight,
88
- disabled: !canScrollRight,
89
- className: "ais-ChatToolSearchIndexCarouselHeaderScrollButton"
90
- }, /*#__PURE__*/ React.createElement(ChevronRightIcon, {
91
- createElement: createElement
92
- }))));
93
- }
22
+ };
94
23
  return {
95
24
  layoutComponent: SearchLayoutComponent
96
25
  };
@@ -1,6 +1,7 @@
1
1
  export * from './Autocomplete';
2
2
  export * from './Breadcrumb';
3
3
  export * from './Chat';
4
+ export * from './PromptSuggestions';
4
5
  export * from './ChatTrigger';
5
6
  export * from './ClearRefinements';
6
7
  export * from './CurrentRefinements';
@@ -1,6 +1,7 @@
1
- export { EXPERIMENTAL_Autocomplete } from './Autocomplete.js';
1
+ export { Autocomplete, EXPERIMENTAL_Autocomplete } from './Autocomplete.js';
2
2
  export { Breadcrumb } from './Breadcrumb.js';
3
3
  export { Chat, createDefaultTools } from './Chat.js';
4
+ export { PromptSuggestions } from './PromptSuggestions.js';
4
5
  export { ChatTrigger } from './ChatTrigger.js';
5
6
  export { ClearRefinements } from './ClearRefinements.js';
6
7
  export { CurrentRefinements } from './CurrentRefinements.js';