@djangocfg/ui-tools 2.1.368 → 2.1.369

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
@@ -7,7 +7,7 @@ var chunkKNDLV4PI_cjs = require('./chunk-KNDLV4PI.cjs');
7
7
  var chunk5I5QNGUG_cjs = require('./chunk-5I5QNGUG.cjs');
8
8
  var chunkYW5IVWHQ_cjs = require('./chunk-YW5IVWHQ.cjs');
9
9
  var chunk76NNDZH6_cjs = require('./chunk-76NNDZH6.cjs');
10
- var chunkOPKFKTIN_cjs = require('./chunk-OPKFKTIN.cjs');
10
+ var chunkOD3P64QD_cjs = require('./chunk-OD3P64QD.cjs');
11
11
  var chunkYXZ6GU7H_cjs = require('./chunk-YXZ6GU7H.cjs');
12
12
  var chunkFVVF7VCD_cjs = require('./chunk-FVVF7VCD.cjs');
13
13
  var chunk7EYHNP3E_cjs = require('./chunk-7EYHNP3E.cjs');
@@ -373,7 +373,7 @@ var LazyTree = createLazyComponent(
373
373
  }
374
374
  );
375
375
  var LazyChat = createLazyComponent(
376
- () => import('./ChatRoot-HARTIAJ5.cjs').then((m) => ({ default: m.ChatRoot })),
376
+ () => import('./ChatRoot-PW6U3QVF.cjs').then((m) => ({ default: m.ChatRoot })),
377
377
  {
378
378
  displayName: "LazyChat",
379
379
  fallback: /* @__PURE__ */ jsxRuntime.jsx(LoadingFallback, { minHeight: 320, text: "Loading chat\u2026" })
@@ -410,7 +410,7 @@ async function* parseSSE(response, options = {}) {
410
410
  throw new Error("SSE response has no body");
411
411
  }
412
412
  const map = options.map ?? DEFAULT_MAP;
413
- const idleMs = options.idleTimeoutMs ?? chunkOPKFKTIN_cjs.LIMITS.sseIdleMs;
413
+ const idleMs = options.idleTimeoutMs ?? chunkOD3P64QD_cjs.LIMITS.sseIdleMs;
414
414
  const reader = response.body.getReader();
415
415
  const decoder = new TextDecoder();
416
416
  let buffer = "";
@@ -613,7 +613,7 @@ function createMockTransport(opts = {}) {
613
613
  async createSession(_opts) {
614
614
  await sleep(latency);
615
615
  return {
616
- sessionId: chunkOPKFKTIN_cjs.createId("s"),
616
+ sessionId: chunkOD3P64QD_cjs.createId("s"),
617
617
  messages: history.length ? [...history] : void 0,
618
618
  hasMore: false,
619
619
  cursor: null,
@@ -630,12 +630,12 @@ function createMockTransport(opts = {}) {
630
630
  throw new Error("mock transport scripted failure");
631
631
  }
632
632
  history.push({
633
- id: chunkOPKFKTIN_cjs.createId("u"),
633
+ id: chunkOD3P64QD_cjs.createId("u"),
634
634
  role: "user",
635
635
  content,
636
636
  createdAt: Date.now()
637
637
  });
638
- const messageId = chunkOPKFKTIN_cjs.createId("a");
638
+ const messageId = chunkOD3P64QD_cjs.createId("a");
639
639
  yield { type: "message_start", messageId, sessionId: _sid };
640
640
  const reply = replies[turn % replies.length];
641
641
  turn += 1;
@@ -664,7 +664,7 @@ function createMockTransport(opts = {}) {
664
664
  turn += 1;
665
665
  const text = typeof reply === "string" ? reply : reply.filter((e) => e.type === "chunk").map((e) => e.delta).join("");
666
666
  return {
667
- id: chunkOPKFKTIN_cjs.createId("a"),
667
+ id: chunkOD3P64QD_cjs.createId("a"),
668
668
  role: "assistant",
669
669
  content: text || DEFAULT_REPLY,
670
670
  createdAt: Date.now()
@@ -675,6 +675,138 @@ function createMockTransport(opts = {}) {
675
675
  };
676
676
  }
677
677
  chunkOLISEQHS_cjs.__name(createMockTransport, "createMockTransport");
678
+ function useChatScroll(options) {
679
+ const {
680
+ containerRef,
681
+ bottomRef,
682
+ isStreaming = false,
683
+ bottomThresholdPx = 80,
684
+ messagesCount = 0
685
+ } = options;
686
+ const [isAtBottom, setIsAtBottom] = React.useState(true);
687
+ const [unreadCount, setUnreadCount] = React.useState(0);
688
+ const lastCountRef = React.useRef(messagesCount);
689
+ const stickyRef = React.useRef(true);
690
+ const wasStreamingRef = React.useRef(isStreaming);
691
+ const scrollToBottom = React.useCallback(
692
+ (smooth = false) => {
693
+ const el = containerRef.current;
694
+ if (!el) return;
695
+ el.scrollTo({
696
+ top: el.scrollHeight,
697
+ behavior: smooth ? "smooth" : "auto"
698
+ });
699
+ stickyRef.current = true;
700
+ setIsAtBottom(true);
701
+ setUnreadCount(0);
702
+ },
703
+ [containerRef]
704
+ );
705
+ const resetUnread = React.useCallback(() => setUnreadCount(0), []);
706
+ React.useEffect(() => {
707
+ const el = containerRef.current;
708
+ if (!el) return;
709
+ const onScroll = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
710
+ const distance = el.scrollHeight - el.scrollTop - el.clientHeight;
711
+ const atBottom = distance <= bottomThresholdPx;
712
+ stickyRef.current = atBottom;
713
+ setIsAtBottom(atBottom);
714
+ if (atBottom) setUnreadCount(0);
715
+ }, "onScroll");
716
+ onScroll();
717
+ el.addEventListener("scroll", onScroll, { passive: true });
718
+ return () => {
719
+ el.removeEventListener("scroll", onScroll);
720
+ };
721
+ }, [containerRef, bottomThresholdPx]);
722
+ React.useEffect(() => {
723
+ const el = containerRef.current;
724
+ if (!el) return;
725
+ if (isStreaming) {
726
+ wasStreamingRef.current = true;
727
+ if (!stickyRef.current) return;
728
+ let raf = 0;
729
+ const tick = /* @__PURE__ */ chunkOLISEQHS_cjs.__name(() => {
730
+ if (!stickyRef.current) return;
731
+ el.scrollTop = el.scrollHeight;
732
+ raf = requestAnimationFrame(tick);
733
+ }, "tick");
734
+ raf = requestAnimationFrame(tick);
735
+ return () => cancelAnimationFrame(raf);
736
+ }
737
+ if (wasStreamingRef.current && stickyRef.current) {
738
+ wasStreamingRef.current = false;
739
+ let raf1 = 0;
740
+ let raf2 = 0;
741
+ raf1 = requestAnimationFrame(() => {
742
+ el.scrollTop = el.scrollHeight;
743
+ raf2 = requestAnimationFrame(() => {
744
+ el.scrollTop = el.scrollHeight;
745
+ });
746
+ });
747
+ return () => {
748
+ cancelAnimationFrame(raf1);
749
+ cancelAnimationFrame(raf2);
750
+ };
751
+ }
752
+ wasStreamingRef.current = false;
753
+ return;
754
+ }, [containerRef, isStreaming]);
755
+ React.useEffect(() => {
756
+ if (messagesCount > lastCountRef.current) {
757
+ if (stickyRef.current) {
758
+ const el = containerRef.current;
759
+ if (el) el.scrollTop = el.scrollHeight;
760
+ } else {
761
+ setUnreadCount((n) => n + (messagesCount - lastCountRef.current));
762
+ }
763
+ }
764
+ lastCountRef.current = messagesCount;
765
+ }, [containerRef, messagesCount]);
766
+ React.useEffect(() => {
767
+ }, [bottomRef]);
768
+ return { isAtBottom, unreadCount, scrollToBottom, resetUnread };
769
+ }
770
+ chunkOLISEQHS_cjs.__name(useChatScroll, "useChatScroll");
771
+ function useChatHistory(options) {
772
+ const { enabled = true, containerRef, topSentinelRef, hasMore, isLoadingMore, loadMore } = options;
773
+ const heightBeforeRef = React.useRef(null);
774
+ React.useEffect(() => {
775
+ if (heightBeforeRef.current == null) return;
776
+ const el = containerRef.current;
777
+ if (!el) {
778
+ heightBeforeRef.current = null;
779
+ return;
780
+ }
781
+ if (!isLoadingMore) {
782
+ const delta = el.scrollHeight - heightBeforeRef.current;
783
+ if (delta > 0) {
784
+ el.scrollTop += delta;
785
+ }
786
+ heightBeforeRef.current = null;
787
+ }
788
+ }, [containerRef, isLoadingMore]);
789
+ React.useEffect(() => {
790
+ if (!enabled || !hasMore) return;
791
+ const sentinel = topSentinelRef.current;
792
+ const root = containerRef.current;
793
+ if (!sentinel || !root) return;
794
+ const observer = new IntersectionObserver(
795
+ (entries) => {
796
+ const entry = entries[0];
797
+ if (!entry?.isIntersecting) return;
798
+ if (isLoadingMore) return;
799
+ const el = containerRef.current;
800
+ if (el) heightBeforeRef.current = el.scrollHeight;
801
+ void loadMore();
802
+ },
803
+ { root, threshold: 0, rootMargin: "200px 0px 0px 0px" }
804
+ );
805
+ observer.observe(sentinel);
806
+ return () => observer.disconnect();
807
+ }, [enabled, hasMore, isLoadingMore, containerRef, topSentinelRef, loadMore]);
808
+ }
809
+ chunkOLISEQHS_cjs.__name(useChatHistory, "useChatHistory");
678
810
  function useChatLightbox() {
679
811
  const [state, setState] = React.useState(null);
680
812
  const open = React.useCallback((att, gallery) => {
@@ -732,9 +864,9 @@ function AudioToggle({
732
864
  alwaysShow = false,
733
865
  className
734
866
  }) {
735
- const muted = chunkOPKFKTIN_cjs.useChatAudioPrefs((s) => s.muted);
736
- const setMuted = chunkOPKFKTIN_cjs.useChatAudioPrefs((s) => s.setMuted);
737
- const ctx = chunkOPKFKTIN_cjs.useChatContextOptional();
867
+ const muted = chunkOD3P64QD_cjs.useChatAudioPrefs((s) => s.muted);
868
+ const setMuted = chunkOD3P64QD_cjs.useChatAudioPrefs((s) => s.setMuted);
869
+ const ctx = chunkOD3P64QD_cjs.useChatContextOptional();
738
870
  if (ctx && !ctx.hasAudio && !alwaysShow) return null;
739
871
  const Icon = muted ? lucideReact.VolumeX : lucideReact.Volume2;
740
872
  const label = muted ? "Unmute chat sounds" : "Mute chat sounds";
@@ -2048,159 +2180,151 @@ Object.defineProperty(exports, "useCronWeekDays", {
2048
2180
  });
2049
2181
  Object.defineProperty(exports, "Attachments", {
2050
2182
  enumerable: true,
2051
- get: function () { return chunkOPKFKTIN_cjs.Attachments; }
2183
+ get: function () { return chunkOD3P64QD_cjs.Attachments; }
2052
2184
  });
2053
2185
  Object.defineProperty(exports, "AttachmentsGrid", {
2054
2186
  enumerable: true,
2055
- get: function () { return chunkOPKFKTIN_cjs.AttachmentsGrid; }
2187
+ get: function () { return chunkOD3P64QD_cjs.AttachmentsGrid; }
2056
2188
  });
2057
2189
  Object.defineProperty(exports, "AttachmentsList", {
2058
2190
  enumerable: true,
2059
- get: function () { return chunkOPKFKTIN_cjs.AttachmentsList; }
2191
+ get: function () { return chunkOD3P64QD_cjs.AttachmentsList; }
2060
2192
  });
2061
2193
  Object.defineProperty(exports, "CHAT_EVENT_NAME", {
2062
2194
  enumerable: true,
2063
- get: function () { return chunkOPKFKTIN_cjs.CHAT_EVENT_NAME; }
2195
+ get: function () { return chunkOD3P64QD_cjs.CHAT_EVENT_NAME; }
2064
2196
  });
2065
2197
  Object.defineProperty(exports, "CSS_VARS", {
2066
2198
  enumerable: true,
2067
- get: function () { return chunkOPKFKTIN_cjs.CSS_VARS; }
2199
+ get: function () { return chunkOD3P64QD_cjs.CSS_VARS; }
2068
2200
  });
2069
2201
  Object.defineProperty(exports, "ChatProvider", {
2070
2202
  enumerable: true,
2071
- get: function () { return chunkOPKFKTIN_cjs.ChatProvider; }
2203
+ get: function () { return chunkOD3P64QD_cjs.ChatProvider; }
2072
2204
  });
2073
2205
  Object.defineProperty(exports, "ChatRoot", {
2074
2206
  enumerable: true,
2075
- get: function () { return chunkOPKFKTIN_cjs.ChatRoot; }
2207
+ get: function () { return chunkOD3P64QD_cjs.ChatRoot; }
2076
2208
  });
2077
2209
  Object.defineProperty(exports, "Composer", {
2078
2210
  enumerable: true,
2079
- get: function () { return chunkOPKFKTIN_cjs.Composer; }
2211
+ get: function () { return chunkOD3P64QD_cjs.Composer; }
2080
2212
  });
2081
2213
  Object.defineProperty(exports, "DEFAULT_LABELS", {
2082
2214
  enumerable: true,
2083
- get: function () { return chunkOPKFKTIN_cjs.DEFAULT_LABELS; }
2215
+ get: function () { return chunkOD3P64QD_cjs.DEFAULT_LABELS; }
2084
2216
  });
2085
2217
  Object.defineProperty(exports, "DEFAULT_SIDEBAR", {
2086
2218
  enumerable: true,
2087
- get: function () { return chunkOPKFKTIN_cjs.DEFAULT_SIDEBAR; }
2219
+ get: function () { return chunkOD3P64QD_cjs.DEFAULT_SIDEBAR; }
2088
2220
  });
2089
2221
  Object.defineProperty(exports, "DEFAULT_Z_INDEX", {
2090
2222
  enumerable: true,
2091
- get: function () { return chunkOPKFKTIN_cjs.DEFAULT_Z_INDEX; }
2223
+ get: function () { return chunkOD3P64QD_cjs.DEFAULT_Z_INDEX; }
2092
2224
  });
2093
2225
  Object.defineProperty(exports, "EmptyState", {
2094
2226
  enumerable: true,
2095
- get: function () { return chunkOPKFKTIN_cjs.EmptyState; }
2227
+ get: function () { return chunkOD3P64QD_cjs.EmptyState; }
2096
2228
  });
2097
2229
  Object.defineProperty(exports, "ErrorBanner", {
2098
2230
  enumerable: true,
2099
- get: function () { return chunkOPKFKTIN_cjs.ErrorBanner; }
2231
+ get: function () { return chunkOD3P64QD_cjs.ErrorBanner; }
2100
2232
  });
2101
2233
  Object.defineProperty(exports, "HOTKEYS", {
2102
2234
  enumerable: true,
2103
- get: function () { return chunkOPKFKTIN_cjs.HOTKEYS; }
2235
+ get: function () { return chunkOD3P64QD_cjs.HOTKEYS; }
2104
2236
  });
2105
2237
  Object.defineProperty(exports, "JumpToLatest", {
2106
2238
  enumerable: true,
2107
- get: function () { return chunkOPKFKTIN_cjs.JumpToLatest; }
2239
+ get: function () { return chunkOD3P64QD_cjs.JumpToLatest; }
2108
2240
  });
2109
2241
  Object.defineProperty(exports, "LIMITS", {
2110
2242
  enumerable: true,
2111
- get: function () { return chunkOPKFKTIN_cjs.LIMITS; }
2243
+ get: function () { return chunkOD3P64QD_cjs.LIMITS; }
2112
2244
  });
2113
2245
  Object.defineProperty(exports, "MessageActions", {
2114
2246
  enumerable: true,
2115
- get: function () { return chunkOPKFKTIN_cjs.MessageActions; }
2247
+ get: function () { return chunkOD3P64QD_cjs.MessageActions; }
2116
2248
  });
2117
2249
  Object.defineProperty(exports, "MessageBubble", {
2118
2250
  enumerable: true,
2119
- get: function () { return chunkOPKFKTIN_cjs.MessageBubble; }
2251
+ get: function () { return chunkOD3P64QD_cjs.MessageBubble; }
2120
2252
  });
2121
2253
  Object.defineProperty(exports, "MessageList", {
2122
2254
  enumerable: true,
2123
- get: function () { return chunkOPKFKTIN_cjs.MessageList; }
2255
+ get: function () { return chunkOD3P64QD_cjs.MessageList; }
2124
2256
  });
2125
2257
  Object.defineProperty(exports, "STORAGE_KEYS", {
2126
2258
  enumerable: true,
2127
- get: function () { return chunkOPKFKTIN_cjs.STORAGE_KEYS; }
2259
+ get: function () { return chunkOD3P64QD_cjs.STORAGE_KEYS; }
2128
2260
  });
2129
2261
  Object.defineProperty(exports, "Sources", {
2130
2262
  enumerable: true,
2131
- get: function () { return chunkOPKFKTIN_cjs.Sources; }
2263
+ get: function () { return chunkOD3P64QD_cjs.Sources; }
2132
2264
  });
2133
2265
  Object.defineProperty(exports, "StreamingIndicator", {
2134
2266
  enumerable: true,
2135
- get: function () { return chunkOPKFKTIN_cjs.StreamingIndicator; }
2267
+ get: function () { return chunkOD3P64QD_cjs.StreamingIndicator; }
2136
2268
  });
2137
2269
  Object.defineProperty(exports, "ToolCalls", {
2138
2270
  enumerable: true,
2139
- get: function () { return chunkOPKFKTIN_cjs.ToolCalls; }
2271
+ get: function () { return chunkOD3P64QD_cjs.ToolCalls; }
2140
2272
  });
2141
2273
  Object.defineProperty(exports, "createId", {
2142
2274
  enumerable: true,
2143
- get: function () { return chunkOPKFKTIN_cjs.createId; }
2275
+ get: function () { return chunkOD3P64QD_cjs.createId; }
2144
2276
  });
2145
2277
  Object.defineProperty(exports, "createTokenBuffer", {
2146
2278
  enumerable: true,
2147
- get: function () { return chunkOPKFKTIN_cjs.createTokenBuffer; }
2279
+ get: function () { return chunkOD3P64QD_cjs.createTokenBuffer; }
2148
2280
  });
2149
2281
  Object.defineProperty(exports, "deriveInitials", {
2150
2282
  enumerable: true,
2151
- get: function () { return chunkOPKFKTIN_cjs.deriveInitials; }
2283
+ get: function () { return chunkOD3P64QD_cjs.deriveInitials; }
2152
2284
  });
2153
2285
  Object.defineProperty(exports, "getChatLogger", {
2154
2286
  enumerable: true,
2155
- get: function () { return chunkOPKFKTIN_cjs.getChatLogger; }
2287
+ get: function () { return chunkOD3P64QD_cjs.getChatLogger; }
2156
2288
  });
2157
2289
  Object.defineProperty(exports, "initialState", {
2158
2290
  enumerable: true,
2159
- get: function () { return chunkOPKFKTIN_cjs.initialState; }
2291
+ get: function () { return chunkOD3P64QD_cjs.initialState; }
2160
2292
  });
2161
2293
  Object.defineProperty(exports, "reducer", {
2162
2294
  enumerable: true,
2163
- get: function () { return chunkOPKFKTIN_cjs.reducer; }
2295
+ get: function () { return chunkOD3P64QD_cjs.reducer; }
2164
2296
  });
2165
2297
  Object.defineProperty(exports, "resolvePersona", {
2166
2298
  enumerable: true,
2167
- get: function () { return chunkOPKFKTIN_cjs.resolvePersona; }
2299
+ get: function () { return chunkOD3P64QD_cjs.resolvePersona; }
2168
2300
  });
2169
2301
  Object.defineProperty(exports, "useChat", {
2170
2302
  enumerable: true,
2171
- get: function () { return chunkOPKFKTIN_cjs.useChat; }
2303
+ get: function () { return chunkOD3P64QD_cjs.useChat; }
2172
2304
  });
2173
2305
  Object.defineProperty(exports, "useChatAudio", {
2174
2306
  enumerable: true,
2175
- get: function () { return chunkOPKFKTIN_cjs.useChatAudio; }
2307
+ get: function () { return chunkOD3P64QD_cjs.useChatAudio; }
2176
2308
  });
2177
2309
  Object.defineProperty(exports, "useChatAudioPrefs", {
2178
2310
  enumerable: true,
2179
- get: function () { return chunkOPKFKTIN_cjs.useChatAudioPrefs; }
2311
+ get: function () { return chunkOD3P64QD_cjs.useChatAudioPrefs; }
2180
2312
  });
2181
2313
  Object.defineProperty(exports, "useChatComposer", {
2182
2314
  enumerable: true,
2183
- get: function () { return chunkOPKFKTIN_cjs.useChatComposer; }
2315
+ get: function () { return chunkOD3P64QD_cjs.useChatComposer; }
2184
2316
  });
2185
2317
  Object.defineProperty(exports, "useChatContext", {
2186
2318
  enumerable: true,
2187
- get: function () { return chunkOPKFKTIN_cjs.useChatContext; }
2319
+ get: function () { return chunkOD3P64QD_cjs.useChatContext; }
2188
2320
  });
2189
2321
  Object.defineProperty(exports, "useChatContextOptional", {
2190
2322
  enumerable: true,
2191
- get: function () { return chunkOPKFKTIN_cjs.useChatContextOptional; }
2192
- });
2193
- Object.defineProperty(exports, "useChatHistory", {
2194
- enumerable: true,
2195
- get: function () { return chunkOPKFKTIN_cjs.useChatHistory; }
2323
+ get: function () { return chunkOD3P64QD_cjs.useChatContextOptional; }
2196
2324
  });
2197
2325
  Object.defineProperty(exports, "useChatLayout", {
2198
2326
  enumerable: true,
2199
- get: function () { return chunkOPKFKTIN_cjs.useChatLayout; }
2200
- });
2201
- Object.defineProperty(exports, "useChatScroll", {
2202
- enumerable: true,
2203
- get: function () { return chunkOPKFKTIN_cjs.useChatScroll; }
2327
+ get: function () { return chunkOD3P64QD_cjs.useChatLayout; }
2204
2328
  });
2205
2329
  Object.defineProperty(exports, "TreeError", {
2206
2330
  enumerable: true,
@@ -2401,7 +2525,9 @@ exports.isPlainObject = isPlainObject;
2401
2525
  exports.isStringValue = isStringValue;
2402
2526
  exports.mentionPresets = mentionPresets;
2403
2527
  exports.parseSSE = parseSSE;
2528
+ exports.useChatHistory = useChatHistory;
2404
2529
  exports.useChatLightbox = useChatLightbox;
2530
+ exports.useChatScroll = useChatScroll;
2405
2531
  exports.useEditor = useEditor;
2406
2532
  exports.useEditorContext = useEditorContext;
2407
2533
  exports.useLanguage = useLanguage;