@djangocfg/ui-tools 2.1.369 → 2.1.372

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,9 +1,9 @@
1
1
  import { MarkdownMessage } from './chunk-NWUT327A.mjs';
2
2
  import { __name } from './chunk-N2XQF2OL.mjs';
3
- import { createContext, forwardRef, memo, useRef, useImperativeHandle, useCallback, useMemo, useReducer, useEffect, useState, useSyncExternalStore, useContext } from 'react';
3
+ import { createContext, forwardRef, memo, useRef, useImperativeHandle, useCallback, useEffect, useMemo, useReducer, useState, useSyncExternalStore, useContext } from 'react';
4
4
  import { cn, isDev } from '@djangocfg/ui-core/lib';
5
5
  import { consola } from 'consola';
6
- import { useLocalStorage, useMediaQuery } from '@djangocfg/ui-core/hooks';
6
+ import { useCopy, useLocalStorage, useMediaQuery } from '@djangocfg/ui-core/hooks';
7
7
  import { create } from 'zustand';
8
8
  import { persist, createJSONStorage } from 'zustand/middleware';
9
9
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
@@ -2154,7 +2154,9 @@ var MessageList = forwardRef(/* @__PURE__ */ __name(function MessageList2({
2154
2154
  const ctx = useChatContextOptional();
2155
2155
  const messages = messagesProp ?? ctx?.messages ?? [];
2156
2156
  const isLoadingMore = isLoadingMoreProp ?? ctx?.isLoadingMore ?? false;
2157
+ const { copyToClipboard } = useCopy();
2157
2158
  const virtuosoRef = useRef(null);
2159
+ const didInitialScrollRef = useRef(false);
2158
2160
  useImperativeHandle(
2159
2161
  ref,
2160
2162
  () => ({
@@ -2179,15 +2181,31 @@ var MessageList = forwardRef(/* @__PURE__ */ __name(function MessageList2({
2179
2181
  MessageBubble,
2180
2182
  {
2181
2183
  message: m,
2182
- onCopy: () => copy(m.content),
2184
+ onCopy: () => void copyToClipboard(m.content),
2183
2185
  onRegenerate: ctx ? () => void ctx.regenerate(m.id) : void 0,
2184
2186
  onDelete: ctx ? () => ctx.deleteMessage(m.id) : void 0
2185
2187
  }
2186
2188
  ) }),
2187
- [itemClassName, ctx]
2189
+ [itemClassName, ctx, copyToClipboard]
2188
2190
  );
2189
2191
  const itemRenderer = renderItem ?? defaultRenderItem;
2190
- const computeItemKey = useCallback((index, m) => m.id ?? index, []);
2192
+ useEffect(() => {
2193
+ if (didInitialScrollRef.current) return;
2194
+ if (messages.length === 0) return;
2195
+ didInitialScrollRef.current = true;
2196
+ const id = requestAnimationFrame(() => {
2197
+ virtuosoRef.current?.scrollToIndex({
2198
+ index: "LAST",
2199
+ align: "end",
2200
+ behavior: "auto"
2201
+ });
2202
+ });
2203
+ return () => cancelAnimationFrame(id);
2204
+ }, [messages.length]);
2205
+ const computeItemKey = useCallback(
2206
+ (index, m) => m?.id ?? index,
2207
+ []
2208
+ );
2191
2209
  const startReachedHandler = useMemo(() => {
2192
2210
  if (!onStartReached) return void 0;
2193
2211
  let inFlight = false;
@@ -2240,25 +2258,21 @@ var MessageList = forwardRef(/* @__PURE__ */ __name(function MessageList2({
2240
2258
  className: cn("flex-1", className),
2241
2259
  data: messages,
2242
2260
  computeItemKey,
2243
- itemContent: (index, m) => itemRenderer(m, index),
2261
+ itemContent: (index, m) => m ? itemRenderer(m, index) : null,
2244
2262
  defaultItemHeight,
2263
+ initialTopMostItemIndex: messages.length > 0 ? messages.length - 1 : 0,
2245
2264
  followOutput: (isAtBottom) => isAtBottom ? "auto" : false,
2246
2265
  atBottomStateChange: onAtBottomChange,
2247
2266
  alignToBottom: true,
2248
2267
  startReached: startReachedHandler,
2249
2268
  components: isLoadingMore ? {
2250
2269
  Header: /* @__PURE__ */ __name(() => /* @__PURE__ */ jsx("div", { className: "flex justify-center py-2", children: /* @__PURE__ */ jsx(Spinner, { className: "size-4 text-muted-foreground" }) }), "Header")
2251
- } : void 0,
2270
+ } : EMPTY_COMPONENTS,
2252
2271
  increaseViewportBy: { top: 200, bottom: 400 }
2253
2272
  }
2254
2273
  );
2255
2274
  }, "MessageList"));
2256
- function copy(text) {
2257
- if (typeof navigator !== "undefined" && navigator.clipboard) {
2258
- void navigator.clipboard.writeText(text);
2259
- }
2260
- }
2261
- __name(copy, "copy");
2275
+ var EMPTY_COMPONENTS = {};
2262
2276
  function ChatRoot(props) {
2263
2277
  const { transport, config, initialSessionId, autoCreateSession, streaming, audio, debug, className, listClassName, ...slots } = props;
2264
2278
  return /* @__PURE__ */ jsx(
@@ -2308,7 +2322,7 @@ function ChatRootShell({ className, listClassName, slots }) {
2308
2322
  toolCallsProps: slots.toolCallsProps,
2309
2323
  attachmentRenderers: slots.attachmentRenderers,
2310
2324
  onAttachmentOpen: slots.onAttachmentOpen,
2311
- onCopy: () => copy2(m.content),
2325
+ onCopy: () => copy(m.content),
2312
2326
  onRegenerate: () => void chat.regenerate(m.id),
2313
2327
  onDelete: () => chat.deleteMessage(m.id)
2314
2328
  },
@@ -2362,13 +2376,13 @@ function ChatRootShell({ className, listClassName, slots }) {
2362
2376
  ] });
2363
2377
  }
2364
2378
  __name(ChatRootShell, "ChatRootShell");
2365
- function copy2(text) {
2379
+ function copy(text) {
2366
2380
  if (typeof navigator !== "undefined" && navigator.clipboard) {
2367
2381
  void navigator.clipboard.writeText(text);
2368
2382
  }
2369
2383
  }
2370
- __name(copy2, "copy");
2384
+ __name(copy, "copy");
2371
2385
 
2372
2386
  export { Attachments, AttachmentsGrid, AttachmentsList, CHAT_EVENT_NAME, CSS_VARS, ChatProvider, ChatRoot, Composer, DEFAULT_LABELS, DEFAULT_SIDEBAR, DEFAULT_Z_INDEX, EmptyState, ErrorBanner, HOTKEYS, JumpToLatest, LIMITS, MessageActions, MessageBubble, MessageList, STORAGE_KEYS, Sources, StreamingIndicator, ToolCalls, createId, createTokenBuffer, deriveInitials, getChatLogger, initialState, reducer, resolvePersona, useChat, useChatAudio, useChatAudioPrefs, useChatComposer, useChatContext, useChatContextOptional, useChatLayout };
2373
- //# sourceMappingURL=chunk-YLIYXSUO.mjs.map
2374
- //# sourceMappingURL=chunk-YLIYXSUO.mjs.map
2387
+ //# sourceMappingURL=chunk-KSBMKHYY.mjs.map
2388
+ //# sourceMappingURL=chunk-KSBMKHYY.mjs.map