@brainfish-ai/components 0.13.7 → 0.13.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.
@@ -1,5 +1,6 @@
1
1
  import { RefObject } from 'react';
2
- export declare const useScrollManager: (answerRefs: RefObject<(HTMLDivElement | null)[]>, containerRef: RefObject<HTMLDivElement | null>) => {
2
+ export declare const useScrollManager: (answerRefs: RefObject<(HTMLDivElement | null)[]>, containerRef: RefObject<HTMLDivElement | null>, bottomRef?: RefObject<HTMLDivElement | null>) => {
3
3
  scrollToLastAnswer: () => void;
4
4
  scrollToAnswer: (index: number) => void;
5
+ scrollToBottom: () => void;
5
6
  };
@@ -4104,7 +4104,7 @@ const useIsChatSearchDirty = () => {
4104
4104
  return isDirty;
4105
4105
  };
4106
4106
 
4107
- const useScrollManager = (answerRefs, containerRef) => {
4107
+ const useScrollManager = (answerRefs, containerRef, bottomRef) => {
4108
4108
  const scrollToLastAnswer = () => {
4109
4109
  requestAnimationFrame(() => {
4110
4110
  const lastAnswer = answerRefs.current?.[answerRefs.current.length - 1];
@@ -4129,7 +4129,14 @@ const useScrollManager = (answerRefs, containerRef) => {
4129
4129
  }
4130
4130
  });
4131
4131
  };
4132
- return { scrollToLastAnswer, scrollToAnswer };
4132
+ const scrollToBottom = () => {
4133
+ setTimeout(() => {
4134
+ if (bottomRef?.current && containerRef.current) {
4135
+ bottomRef.current.scrollIntoView({ behavior: "smooth", block: "end" });
4136
+ }
4137
+ }, 200);
4138
+ };
4139
+ return { scrollToLastAnswer, scrollToAnswer, scrollToBottom };
4133
4140
  };
4134
4141
 
4135
4142
  const defaultRetryOptions = {
@@ -4524,7 +4531,7 @@ function Answer({
4524
4531
  return /* @__PURE__ */ React__default.createElement(
4525
4532
  "div",
4526
4533
  {
4527
- className: "rounded-lg relative mx-auto overflow-hidden bg-card border border-primary mb-4",
4534
+ className: "rounded-lg relative mx-auto overflow-hidden bg-card border border-primary",
4528
4535
  "data-name": "SearchResults",
4529
4536
  "data-index": index
4530
4537
  },
@@ -5352,6 +5359,7 @@ const ChatSearchComponent = forwardRef(
5352
5359
  const fileInputRef = useRef(null);
5353
5360
  const primarySearchRef = useRef(null);
5354
5361
  const followUpSearchRef = useRef(null);
5362
+ const bottomRef = useRef(null);
5355
5363
  const { suggestions: autocompleteSuggestions } = useAutocomplete({
5356
5364
  query,
5357
5365
  endpoint: autocompleteEndpoint || "",
@@ -5366,7 +5374,11 @@ const ChatSearchComponent = forwardRef(
5366
5374
  headers,
5367
5375
  mergedTextConfig
5368
5376
  });
5369
- const { scrollToLastAnswer, scrollToAnswer } = useScrollManager(answerRefs, containerRef);
5377
+ const { scrollToLastAnswer, scrollToAnswer, scrollToBottom } = useScrollManager(
5378
+ answerRefs,
5379
+ containerRef,
5380
+ bottomRef
5381
+ );
5370
5382
  const { subscribeToStateChanges } = useSubscriptionManager();
5371
5383
  const loadFollowUpQuestions = async (searchQueryId, conversationId) => {
5372
5384
  if (!followUpQuestionsEndpoint || disableFollowUpQuestions) {
@@ -5403,6 +5415,7 @@ const ChatSearchComponent = forwardRef(
5403
5415
  for (const line of lines) {
5404
5416
  try {
5405
5417
  if (line === "[DONE]") {
5418
+ scrollToBottom();
5406
5419
  continue;
5407
5420
  }
5408
5421
  const event = JSON.parse(line);
@@ -5413,6 +5426,7 @@ const ChatSearchComponent = forwardRef(
5413
5426
  text: event.content
5414
5427
  })
5415
5428
  );
5429
+ scrollToBottom();
5416
5430
  const uncertaintyCheck = isAnswerUncertain(accumulatedAnswer);
5417
5431
  isUncertain = uncertaintyCheck.uncertain;
5418
5432
  if (isUncertain) {
@@ -5944,7 +5958,8 @@ const ChatSearchComponent = forwardRef(
5944
5958
  ref: (el) => answerRefs.current[i] = el,
5945
5959
  initial: { opacity: 0, y: 20 },
5946
5960
  animate: { opacity: 1, y: 0 },
5947
- transition: { duration: 0.5, delay: i * 0.1 }
5961
+ transition: { duration: 0.5, delay: i * 0.1 },
5962
+ className: "space-y-4 last:!mb-8"
5948
5963
  },
5949
5964
  /* @__PURE__ */ React__default.createElement(
5950
5965
  Answer,
@@ -5967,13 +5982,13 @@ const ChatSearchComponent = forwardRef(
5967
5982
  onFeedbackReasonSubmit: (reason) => void handleFeedbackReasonSubmit(reason, answer.searchQueryId)
5968
5983
  }
5969
5984
  ),
5970
- i === answers.length - 1 && !disableFollowUpQuestions && answer.followUpQuestions && answer.state === "completed" && /* @__PURE__ */ React__default.createElement("div", { className: "mt-4" }, /* @__PURE__ */ React__default.createElement(
5985
+ i === answers.length - 1 && !disableFollowUpQuestions && answer.followUpQuestions && answer.state === "completed" && /* @__PURE__ */ React__default.createElement(
5971
5986
  FollowUpQuestions,
5972
5987
  {
5973
5988
  questions: answer.followUpQuestions,
5974
5989
  onQuestionClick: handleFollowUpQuestionClick
5975
5990
  }
5976
- ))
5991
+ )
5977
5992
  ))
5978
5993
  ))), showResults && answers.length > 1 && /* @__PURE__ */ React__default.createElement("div", { className: "hidden lg:block" }, /* @__PURE__ */ React__default.createElement(
5979
5994
  TimelineNavigation,
@@ -5986,7 +6001,7 @@ const ChatSearchComponent = forwardRef(
5986
6001
  },
5987
6002
  offset
5988
6003
  }
5989
- )), disclaimer && isWidgetMode && !(showResults && showFollowUp) && /* @__PURE__ */ React__default.createElement("div", { className: "mt-2 px-3 @3xl:px-0 text-xs text-dark-500 flex items-center gap-1 absolute bottom-12 justify-center text-center w-full" }, /* @__PURE__ */ React__default.createElement(MemoizedIcon, { iconName: "Info", className: "size-4" }), disclaimer)),
6004
+ )), disclaimer && isWidgetMode && !(showResults && showFollowUp) && /* @__PURE__ */ React__default.createElement("div", { className: "mt-2 px-3 @3xl:px-0 text-xs text-dark-500 flex items-center gap-1 absolute bottom-12 justify-center text-center w-full" }, /* @__PURE__ */ React__default.createElement(MemoizedIcon, { iconName: "Info", className: "size-4" }), disclaimer), /* @__PURE__ */ React__default.createElement("div", { ref: bottomRef })),
5990
6005
  showResults && showFollowUp && /* @__PURE__ */ React__default.createElement(
5991
6006
  FollowUpSearchBar,
5992
6007
  {
@@ -6007,4 +6022,4 @@ const ChatSearch = forwardRef(({ featureFlags, ...props }, ref) => /* @__PURE__
6007
6022
  ChatSearch.displayName = "ChatSearch";
6008
6023
 
6009
6024
  export { ChatSearch as C, ChatSearchProvider as a, useIsChatSearchDirty as b, useChatSearch as u };
6010
- //# sourceMappingURL=ChatSearch.CxwRDkGx.js.map
6025
+ //# sourceMappingURL=ChatSearch.JQEWTiqr.js.map