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