@brainfish-ai/components 0.16.8-alpha.2 → 0.16.8

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.
@@ -5203,7 +5203,7 @@ function Header({
5203
5203
  onToggleSizeButtonClick,
5204
5204
  onBackButtonClick,
5205
5205
  onCloseWidgetClick,
5206
- hideHeaderButtons,
5206
+ isSearchWidget,
5207
5207
  className,
5208
5208
  ...props
5209
5209
  }) {
@@ -5223,6 +5223,7 @@ function Header({
5223
5223
  "md:hidden",
5224
5224
  "@3xl:bg-transparent @3xl:h-auto @3xl:leading-normal",
5225
5225
  "@3xl:justify-center @3xl:space-y-4 @3xl:p-0",
5226
+ isSearchWidget ? "hidden bg-transparent" : "",
5226
5227
  className
5227
5228
  ),
5228
5229
  ...props
@@ -5233,7 +5234,10 @@ function Header({
5233
5234
  initial: { opacity: 0, y: 20 },
5234
5235
  animate: { opacity: 1, y: 0 },
5235
5236
  transition: { duration: 0.5, delay: 0.3 },
5236
- className: "@3xl:text-5xl m-0 text-primary-foreground @3xl:text-foreground flex gap-1 items-center font-bold text-base"
5237
+ className: cn(
5238
+ "m-0 text-primary-foreground @3xl:text-foreground flex gap-1 items-center font-bold text-base",
5239
+ isSearchWidget ? "" : "@3xl:text-5xl"
5240
+ )
5237
5241
  },
5238
5242
  isDirty && /* @__PURE__ */ React__default.createElement(
5239
5243
  Button,
@@ -5242,14 +5246,14 @@ function Header({
5242
5246
  variant: "ghost",
5243
5247
  onClick: onBackButtonClick,
5244
5248
  "aria-label": "Go back",
5245
- className: "@3xl:hidden shrink-0",
5249
+ className: cn("shrink-0", isSearchWidget ? "" : "@3xl:hidden"),
5246
5250
  disabled: isSearching
5247
5251
  },
5248
5252
  /* @__PURE__ */ React__default.createElement(ArrowLeft, null)
5249
5253
  ),
5250
5254
  /* @__PURE__ */ React__default.createElement("span", null, headerText)
5251
5255
  ),
5252
- !hideHeaderButtons && /* @__PURE__ */ React__default.createElement("div", { className: "@3xl:hidden shrink-0", "data-name": "HeaderButtons" }, !hideExpandButton && /* @__PURE__ */ React__default.createElement(
5256
+ /* @__PURE__ */ React__default.createElement("div", { className: "@3xl:hidden shrink-0", "data-name": "HeaderButtons" }, !hideExpandButton && /* @__PURE__ */ React__default.createElement(
5253
5257
  Button,
5254
5258
  {
5255
5259
  size: "icon",
@@ -5281,7 +5285,7 @@ const defaultTextConfig = {
5281
5285
  loadingSearchText: "Searching for relevant content...",
5282
5286
  loadingAnswerText: "Crafting a response...",
5283
5287
  errorText: "Sorry, there was an error generating the answer.",
5284
- followUpPlaceholder: "Ask follow-up",
5288
+ followUpPlaceholder: "Type your response or follow-up",
5285
5289
  positiveAnswerText: "Helpful",
5286
5290
  negativeAnswerText: "Not helpful",
5287
5291
  uncertaintyFallbackText: {
@@ -5998,44 +6002,54 @@ const ChatSearchComponent = forwardRef(
5998
6002
  useEffect(() => {
5999
6003
  const container = containerRef.current;
6000
6004
  if (!container || !isSearchWidget) return;
6001
- const scrollAreaViewport = container;
6002
6005
  let lastSentHeight = 0;
6003
- const sendResize = () => {
6004
- let contentHeight = 0;
6005
- if (scrollAreaViewport) {
6006
- const innerContent = scrollAreaViewport.firstElementChild;
6007
- contentHeight = innerContent ? innerContent.scrollHeight : scrollAreaViewport.scrollHeight;
6008
- } else {
6009
- contentHeight = container.scrollHeight;
6010
- }
6011
- const footerHeight = 40;
6006
+ let rafId = null;
6007
+ const calculateTotalHeight = () => {
6008
+ const innerContent2 = container.firstElementChild;
6009
+ const contentHeight = innerContent2?.scrollHeight ?? container.scrollHeight;
6010
+ const footerHeight = document.querySelector('[data-name="BrandFooter"]')?.clientHeight ?? 0;
6011
+ const headerHeight = document.querySelector('[data-name="Header"]')?.clientHeight ?? 0;
6012
6012
  const followUpHeight = showResults && showFollowUp ? 70 : 0;
6013
- const headerHeight = showResults ? 56 : 0;
6014
- const newHeight = contentHeight + footerHeight + followUpHeight + headerHeight;
6015
- if (newHeight > 0 && newHeight !== lastSentHeight) {
6016
- lastSentHeight = newHeight;
6013
+ const verticalPadding = 32;
6014
+ const chatSearchHeight = document.querySelector('[data-name="ChatSearch"]')?.clientHeight ?? 0;
6015
+ const totalHeight = contentHeight + footerHeight + followUpHeight + headerHeight + verticalPadding;
6016
+ return Math.max(totalHeight, chatSearchHeight);
6017
+ };
6018
+ const sendResize = () => {
6019
+ const totalHeight = calculateTotalHeight();
6020
+ if (totalHeight > 0 && totalHeight !== lastSentHeight) {
6021
+ lastSentHeight = totalHeight;
6017
6022
  window.parent.postMessage(
6018
6023
  {
6019
6024
  type: "RESIZE_IFRAME",
6020
- height: newHeight,
6025
+ height: totalHeight,
6021
6026
  widgetKey: apiKey
6022
6027
  },
6023
6028
  "*"
6024
6029
  );
6025
6030
  }
6026
6031
  };
6027
- const timeoutId = setTimeout(sendResize, 100);
6028
- const resizeObserver = new ResizeObserver(() => {
6029
- requestAnimationFrame(() => {
6032
+ const handleResize = () => {
6033
+ if (rafId !== null) {
6034
+ cancelAnimationFrame(rafId);
6035
+ }
6036
+ rafId = requestAnimationFrame(() => {
6030
6037
  sendResize();
6038
+ rafId = null;
6031
6039
  });
6032
- });
6033
- if (scrollAreaViewport?.firstElementChild) {
6034
- resizeObserver.observe(scrollAreaViewport.firstElementChild);
6040
+ };
6041
+ const timeoutId = setTimeout(sendResize, 100);
6042
+ const resizeObserver = new ResizeObserver(handleResize);
6043
+ const innerContent = container.firstElementChild;
6044
+ if (innerContent) {
6045
+ resizeObserver.observe(innerContent);
6035
6046
  }
6036
6047
  resizeObserver.observe(container);
6037
6048
  return () => {
6038
6049
  clearTimeout(timeoutId);
6050
+ if (rafId !== null) {
6051
+ cancelAnimationFrame(rafId);
6052
+ }
6039
6053
  resizeObserver.disconnect();
6040
6054
  };
6041
6055
  }, [isSearchWidget, apiKey, showResults, showFollowUp]);
@@ -6053,7 +6067,7 @@ const ChatSearchComponent = forwardRef(
6053
6067
  (isWidgetMode || !showResults) && /* @__PURE__ */ React__default.createElement(
6054
6068
  Header,
6055
6069
  {
6056
- hideHeaderButtons: isSearchWidget,
6070
+ isSearchWidget,
6057
6071
  "data-name": "Header",
6058
6072
  headerText: mergedTextConfig.headerText,
6059
6073
  onToggleSizeButtonClick: () => {
@@ -6061,165 +6075,177 @@ const ChatSearchComponent = forwardRef(
6061
6075
  },
6062
6076
  onBackButtonClick: () => void createNewThread(),
6063
6077
  onCloseWidgetClick: () => onCloseWidget?.(),
6064
- className: cn(
6065
- "@3xl:mb-4",
6066
- isSearchWidget ? "hidden bg-transparent" : "",
6067
- showResults ? "block" : "hidden"
6068
- )
6078
+ className: cn("@3xl:mb-4", showResults ? "!block" : "hidden")
6069
6079
  }
6070
6080
  ),
6071
- /* @__PURE__ */ React__default.createElement(ScrollArea, { className: "w-full relative h-auto flex-grow", ref: containerRef }, /* @__PURE__ */ React__default.createElement(AnimatePresence, null, isLoadingConversation ? /* @__PURE__ */ React__default.createElement(LoadingConversation, null) : !showResults ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
6072
- motion.div,
6081
+ /* @__PURE__ */ React__default.createElement(
6082
+ ScrollArea,
6073
6083
  {
6074
- key: "search",
6075
- initial: { opacity: 0, y: 20 },
6076
- animate: { opacity: 1, y: 0 },
6077
- transition: { duration: 0.5 },
6078
- className: "w-full md:space-y-4"
6084
+ className: "w-full relative h-auto flex-grow [&>[data-radix-scroll-area-viewport]>div:first-child]:!block",
6085
+ ref: containerRef
6079
6086
  },
6080
- /* @__PURE__ */ React__default.createElement("div", { className: cn(
6081
- "pb-4",
6082
- isSearchWidget ? "bg-transparent p-3 md:p-0" : "px-3 bg-primary md:p-0 md:bg-transparent"
6083
- ) }, /* @__PURE__ */ React__default.createElement(
6087
+ /* @__PURE__ */ React__default.createElement(AnimatePresence, null, isLoadingConversation ? /* @__PURE__ */ React__default.createElement(LoadingConversation, null) : !showResults ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
6084
6088
  motion.div,
6085
6089
  {
6090
+ key: "search",
6086
6091
  initial: { opacity: 0, y: 20 },
6087
6092
  animate: { opacity: 1, y: 0 },
6088
- transition: { duration: 0.5, delay: 0.4 }
6093
+ transition: { duration: 0.5 },
6094
+ className: "w-full md:space-y-4"
6089
6095
  },
6090
6096
  /* @__PURE__ */ React__default.createElement(
6091
- PrimarySearch,
6097
+ "div",
6092
6098
  {
6093
- ref: primarySearchRef,
6094
- query,
6095
- onQueryChange: (value) => {
6096
- setQuery(value);
6097
- if (primaryTextareaRef.current) {
6098
- adjustTextareaHeight(primaryTextareaRef.current);
6099
- }
6099
+ className: cn(
6100
+ "pb-4",
6101
+ isSearchWidget ? "bg-transparent p-3 md:p-0" : "px-3 bg-primary md:p-0 md:bg-transparent"
6102
+ )
6103
+ },
6104
+ /* @__PURE__ */ React__default.createElement(
6105
+ motion.div,
6106
+ {
6107
+ initial: { opacity: 0, y: 20 },
6108
+ animate: { opacity: 1, y: 0 },
6109
+ transition: { duration: 0.5, delay: 0.4 }
6100
6110
  },
6101
- onSearch: () => void handlePrimarySearch(),
6102
- textConfig: mergedTextConfig,
6103
- collections,
6104
- currentCollectionId,
6105
- onCollectionChange: handleCollectionChange,
6106
- allowedRegions,
6107
- currentRegion,
6108
- onRegionChange: handleRegionChange,
6109
- apiKey,
6110
- fetchRegionConfig,
6111
- disableImageAttachment,
6112
- attachedImages,
6113
- onImageUpload: handleImageUpload,
6114
- onRemoveImage: removeImage,
6115
- isSearching,
6116
- autocompleteSuggestions,
6117
- onAutocompleteSuggestionSelect: handleAutocompleteSuggestionClick
6118
- }
6119
- )
6120
- )),
6121
- /* @__PURE__ */ React__default.createElement(
6122
- Suggestions,
6123
- {
6124
- suggestions: initialSuggestions,
6125
- onQuestionClick: handleSuggestedQuestionClick,
6126
- title: mergedTextConfig.suggestionsTitle
6127
- }
6128
- ),
6129
- isWidgetMode && bodyActionButtons && bodyActionButtons.length > 0 && /* @__PURE__ */ React__default.createElement("div", { className: "mt-4 mb-4 px-3 @3xl:px-0" }, /* @__PURE__ */ React__default.createElement("div", { className: "space-y-3" }, /* @__PURE__ */ React__default.createElement(
6130
- NextBestActions,
6131
- {
6132
- nextBestActions: bodyActionButtons || [],
6133
- onActionClick: (action) => handleNextBestActionClick({
6134
- action,
6135
- searchQueryId: "",
6136
- query: "",
6137
- answer: ""
6138
- })
6139
- }
6140
- )))
6141
- )) : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
6142
- motion.div,
6143
- {
6144
- key: "results",
6145
- initial: { opacity: 0 },
6146
- animate: { opacity: 1 },
6147
- exit: { opacity: 0 },
6148
- transition: { duration: 0.5 },
6149
- className: "w-full max-w-[100vw] space-y-4 p-3 md:p-0"
6150
- },
6151
- answers.map((answer, i) => /* @__PURE__ */ React__default.createElement(
6152
- motion.div,
6153
- {
6154
- key: i,
6155
- ref: (el) => answerRefs.current[i] = el,
6156
- initial: { opacity: 0, y: 20 },
6157
- animate: { opacity: 1, y: 0 },
6158
- transition: { duration: 0.5, delay: i * 0.1 },
6159
- className: "space-y-4 last:!mb-8"
6160
- },
6111
+ /* @__PURE__ */ React__default.createElement(
6112
+ PrimarySearch,
6113
+ {
6114
+ ref: primarySearchRef,
6115
+ query,
6116
+ onQueryChange: (value) => {
6117
+ setQuery(value);
6118
+ if (primaryTextareaRef.current) {
6119
+ adjustTextareaHeight(primaryTextareaRef.current);
6120
+ }
6121
+ },
6122
+ onSearch: () => void handlePrimarySearch(),
6123
+ textConfig: mergedTextConfig,
6124
+ collections,
6125
+ currentCollectionId,
6126
+ onCollectionChange: handleCollectionChange,
6127
+ allowedRegions,
6128
+ currentRegion,
6129
+ onRegionChange: handleRegionChange,
6130
+ apiKey,
6131
+ fetchRegionConfig,
6132
+ disableImageAttachment,
6133
+ attachedImages,
6134
+ onImageUpload: handleImageUpload,
6135
+ onRemoveImage: removeImage,
6136
+ isSearching,
6137
+ autocompleteSuggestions,
6138
+ onAutocompleteSuggestionSelect: handleAutocompleteSuggestionClick
6139
+ }
6140
+ )
6141
+ )
6142
+ ),
6161
6143
  /* @__PURE__ */ React__default.createElement(
6162
- Answer,
6144
+ Suggestions,
6163
6145
  {
6164
- index: i,
6165
- blocks: answer.blocks,
6166
- question: answer.question,
6167
- state: answer.state,
6168
- searchResults: answer.searchResults,
6169
- searchQueryId: answer.searchQueryId,
6170
- searchIntentId: answer.searchIntentId,
6171
- feedback: answer.feedback,
6172
- onFeedback: (response) => void handleFeedback(response, answer.searchQueryId, i),
6173
- disableFeedback,
6174
- textConfig: mergedTextConfig,
6175
- redirectRules,
6176
- nextBestActions,
6177
- actions: answer.actions,
6178
- handleActionClick: handleNextBestActionClick,
6179
- isLastAnswer: i === answers.length - 1,
6180
- onFeedbackReasonSubmit: (reason) => void handleFeedbackReasonSubmit(reason, answer.searchQueryId)
6146
+ suggestions: initialSuggestions,
6147
+ onQuestionClick: handleSuggestedQuestionClick,
6148
+ title: mergedTextConfig.suggestionsTitle
6181
6149
  }
6182
6150
  ),
6183
- i === answers.length - 1 && !disableFollowUpQuestions && answer.followUpQuestions && answer.state === "completed" && /* @__PURE__ */ React__default.createElement(
6184
- FollowUpQuestions,
6151
+ isWidgetMode && bodyActionButtons && bodyActionButtons.length > 0 && /* @__PURE__ */ React__default.createElement("div", { className: "mt-4 mb-4 px-3 @3xl:px-0" }, /* @__PURE__ */ React__default.createElement("div", { className: "space-y-3" }, /* @__PURE__ */ React__default.createElement(
6152
+ NextBestActions,
6185
6153
  {
6186
- questions: answer.followUpQuestions,
6187
- onQuestionClick: handleFollowUpQuestionClick
6154
+ nextBestActions: bodyActionButtons || [],
6155
+ onActionClick: (action) => handleNextBestActionClick({
6156
+ action,
6157
+ searchQueryId: "",
6158
+ query: "",
6159
+ answer: ""
6160
+ })
6188
6161
  }
6189
- )
6190
- ))
6191
- ))), showResults && answers.length > 1 && /* @__PURE__ */ React__default.createElement("div", { className: "hidden lg:block" }, /* @__PURE__ */ React__default.createElement(
6192
- TimelineNavigation,
6193
- {
6194
- questions: answers.map((a) => a.question),
6195
- activeIndex: activeAnswerIndex,
6196
- onNavigate: (index) => {
6197
- setActiveAnswerIndex(index);
6198
- scrollToAnswer(index);
6162
+ )))
6163
+ )) : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(
6164
+ motion.div,
6165
+ {
6166
+ key: "results",
6167
+ initial: { opacity: 0 },
6168
+ animate: { opacity: 1 },
6169
+ exit: { opacity: 0 },
6170
+ transition: { duration: 0.5 },
6171
+ className: "w-full max-w-[100vw] space-y-4 p-3 md:p-0"
6199
6172
  },
6200
- offset
6201
- }
6202
- )), disclaimer && isWidgetMode && !(showResults && showFollowUp) && /* @__PURE__ */ React__default.createElement(
6203
- "div",
6204
- {
6205
- "data-name": "disclaimer",
6206
- className: cn(
6207
- "mt-2 px-3 @3xl:px-0 text-xs text-dark-500 dark:text-dark-400 flex items-center gap-1 justify-center text-center w-full md:static md:mt-4 md:text-left md:flex md:gap-4 leading-5",
6208
- isSearchWidget ? "static mb-2 md:text-left [&>svg]:flex-shrink-0" : "absolute bottom-12"
6209
- )
6210
- },
6211
- /* @__PURE__ */ React__default.createElement(MemoizedIcon, { iconName: "Info", className: "size-4" }),
6212
- /* @__PURE__ */ React__default.createElement(
6213
- MemoizedReactMarkdown,
6173
+ answers.map((answer, i) => /* @__PURE__ */ React__default.createElement(
6174
+ motion.div,
6175
+ {
6176
+ key: i,
6177
+ ref: (el) => answerRefs.current[i] = el,
6178
+ initial: { opacity: 0, y: 20 },
6179
+ animate: { opacity: 1, y: 0 },
6180
+ transition: { duration: 0.5, delay: i * 0.1 },
6181
+ className: "space-y-4 last:!mb-8"
6182
+ },
6183
+ /* @__PURE__ */ React__default.createElement(
6184
+ Answer,
6185
+ {
6186
+ index: i,
6187
+ blocks: answer.blocks,
6188
+ question: answer.question,
6189
+ state: answer.state,
6190
+ searchResults: answer.searchResults,
6191
+ searchQueryId: answer.searchQueryId,
6192
+ searchIntentId: answer.searchIntentId,
6193
+ feedback: answer.feedback,
6194
+ onFeedback: (response) => void handleFeedback(response, answer.searchQueryId, i),
6195
+ disableFeedback,
6196
+ textConfig: mergedTextConfig,
6197
+ redirectRules,
6198
+ nextBestActions,
6199
+ actions: answer.actions,
6200
+ handleActionClick: handleNextBestActionClick,
6201
+ isLastAnswer: i === answers.length - 1,
6202
+ onFeedbackReasonSubmit: (reason) => void handleFeedbackReasonSubmit(reason, answer.searchQueryId)
6203
+ }
6204
+ ),
6205
+ i === answers.length - 1 && !disableFollowUpQuestions && answer.followUpQuestions && answer.state === "completed" && /* @__PURE__ */ React__default.createElement(
6206
+ FollowUpQuestions,
6207
+ {
6208
+ questions: answer.followUpQuestions,
6209
+ onQuestionClick: handleFollowUpQuestionClick
6210
+ }
6211
+ )
6212
+ ))
6213
+ ))),
6214
+ showResults && answers.length > 1 && /* @__PURE__ */ React__default.createElement("div", { className: "hidden lg:block" }, /* @__PURE__ */ React__default.createElement(
6215
+ TimelineNavigation,
6216
+ {
6217
+ questions: answers.map((a) => a.question),
6218
+ activeIndex: activeAnswerIndex,
6219
+ onNavigate: (index) => {
6220
+ setActiveAnswerIndex(index);
6221
+ scrollToAnswer(index);
6222
+ },
6223
+ offset
6224
+ }
6225
+ )),
6226
+ disclaimer && isWidgetMode && !(showResults && showFollowUp) && /* @__PURE__ */ React__default.createElement(
6227
+ "div",
6214
6228
  {
6215
- className: "[&_a]:underline [&_a:hover]:no-underline",
6216
- remarkPlugins: markdownRemarkPlugins,
6217
- rehypePlugins: markdownRehypePlugins,
6218
- components: markdownComponents
6229
+ "data-name": "disclaimer",
6230
+ className: cn(
6231
+ "mt-2 px-3 @3xl:px-0 text-xs text-dark-500 dark:text-dark-400 flex items-center gap-1 justify-center text-center w-full md:static md:mt-4 md:text-left md:flex md:gap-4 leading-5",
6232
+ isSearchWidget ? "static mb-2 md:text-left [&>svg]:flex-shrink-0" : "absolute bottom-12"
6233
+ )
6219
6234
  },
6220
- disclaimer
6221
- )
6222
- ), /* @__PURE__ */ React__default.createElement("div", { ref: bottomRef })),
6235
+ /* @__PURE__ */ React__default.createElement(MemoizedIcon, { iconName: "Info", className: "size-4" }),
6236
+ /* @__PURE__ */ React__default.createElement(
6237
+ MemoizedReactMarkdown,
6238
+ {
6239
+ className: "[&_a]:underline [&_a:hover]:no-underline",
6240
+ remarkPlugins: markdownRemarkPlugins,
6241
+ rehypePlugins: markdownRehypePlugins,
6242
+ components: markdownComponents
6243
+ },
6244
+ disclaimer
6245
+ )
6246
+ ),
6247
+ /* @__PURE__ */ React__default.createElement("div", { ref: bottomRef })
6248
+ ),
6223
6249
  showResults && showFollowUp && /* @__PURE__ */ React__default.createElement(
6224
6250
  FollowUpSearchBar,
6225
6251
  {
@@ -6240,4 +6266,4 @@ const ChatSearch = forwardRef(({ featureFlags, ...props }, ref) => /* @__PURE__
6240
6266
  ChatSearch.displayName = "ChatSearch";
6241
6267
 
6242
6268
  export { ChatSearch as C, ChatSearchProvider as a, useIsChatSearchDirty as b, useChatSearch as u };
6243
- //# sourceMappingURL=ChatSearch.CtqkZ1_R.js.map
6269
+ //# sourceMappingURL=ChatSearch.D8_9CRIM.js.map