@copilotz/chat-ui 0.1.8 → 0.1.9

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/index.cjs CHANGED
@@ -881,7 +881,7 @@ var Message = (0, import_react.memo)(({
881
881
  message.isEdited && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { variant: "outline", className: "text-xs", children: "editado" })
882
882
  ] })
883
883
  ] }),
884
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `flex-1 min-w-0 ${messageIsUser ? "text-right" : "text-left"} ${isGrouped && showAvatar && !messageIsUser ? compactMode ? "ml-9" : "ml-11" : ""} ${isGrouped && showAvatar && messageIsUser ? compactMode ? "mr-9" : "mr-11" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: `relative inline-flex flex-col overflow-hidden ${messageIsUser ? "rounded-lg p-3 bg-primary text-primary-foreground ml-auto max-w-[85%]" : "max-w-full"}`, children: [
884
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `flex-1 min-w-0 ${messageIsUser ? "text-right" : "text-left"} ${isGrouped && showAvatar && !messageIsUser ? compactMode ? "ml-9" : "ml-11" : ""} ${isGrouped && showAvatar && messageIsUser ? compactMode ? "mr-9" : "mr-11" : ""}`, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: `relative inline-flex flex-col overflow-hidden text-left ${messageIsUser ? "rounded-lg p-3 bg-primary text-primary-foreground ml-auto max-w-[85%]" : "max-w-full"}`, children: [
885
885
  isEditing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "space-y-2", children: [
886
886
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
887
887
  Textarea,
@@ -909,8 +909,7 @@ var Message = (0, import_react.memo)(({
909
909
  {
910
910
  content: message.content,
911
911
  isStreaming: message.isStreaming,
912
- thinkingLabel,
913
- className: messageIsUser ? "[&_*]:text-right" : ""
912
+ thinkingLabel
914
913
  }
915
914
  ),
916
915
  message.attachments && message.attachments.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "mt-3 space-y-2", children: message.attachments.map((attachment, index) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MediaRenderer, { attachment }, index)) })
@@ -3812,8 +3811,23 @@ var ChatUI = ({
3812
3811
  return () => clearTimeout(t);
3813
3812
  }
3814
3813
  }, [state.showSidebar, isMobile, config.customComponent]);
3814
+ const prevMessageCountRef = (0, import_react7.useRef)(0);
3815
3815
  (0, import_react7.useEffect)(() => {
3816
- if (!state.isAtBottom || messages.length === 0) return;
3816
+ if (messages.length === 0) {
3817
+ prevMessageCountRef.current = 0;
3818
+ return;
3819
+ }
3820
+ const wasEmpty = prevMessageCountRef.current === 0;
3821
+ prevMessageCountRef.current = messages.length;
3822
+ if (wasEmpty) {
3823
+ requestAnimationFrame(() => {
3824
+ requestAnimationFrame(() => {
3825
+ virtualizer.scrollToIndex(messages.length - 1, { align: "end" });
3826
+ });
3827
+ });
3828
+ return;
3829
+ }
3830
+ if (!state.isAtBottom) return;
3817
3831
  requestAnimationFrame(() => {
3818
3832
  const viewport = scrollAreaRef.current;
3819
3833
  if (!viewport) return;
@@ -3823,7 +3837,7 @@ var ChatUI = ({
3823
3837
  viewport.scrollTop = viewport.scrollHeight;
3824
3838
  }
3825
3839
  });
3826
- }, [messages, state.isAtBottom]);
3840
+ }, [messages, state.isAtBottom, virtualizer]);
3827
3841
  const handleScroll = (0, import_react7.useCallback)((e) => {
3828
3842
  const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;
3829
3843
  const isAtBottom = scrollHeight - scrollTop - clientHeight < 50;