@widgetic/chat 0.1.10 → 0.1.11

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.
@@ -5,7 +5,7 @@
5
5
  import { AttachmentDisplay, SuggestionButtons } from './index.js';
6
6
  import CodeBlock from './CodeBlock.svelte';
7
7
  import LoadingIndicator from './LoadingIndicator.svelte';
8
- import { onMount, tick } from 'svelte';
8
+ import { onDestroy, onMount, tick } from 'svelte';
9
9
 
10
10
  // Props
11
11
  interface Props {
@@ -422,6 +422,22 @@
422
422
  let messagesContainer: HTMLElement;
423
423
  let showSuggestionsInline = $state(false);
424
424
  let autoScroll = $state(true);
425
+ /**
426
+ * Opening on a small screen often resizes the container (parent panel layout)
427
+ * AFTER mount, which resets scroll to the top and clips the input below the
428
+ * fold. A ResizeObserver re-pins the view to the bottom whenever the scroll
429
+ * area's box changes, while `autoScroll` is still true (user has not scrolled
430
+ * up). Disconnected on destroy.
431
+ */
432
+ let containerResizeObserver: ResizeObserver | null = null;
433
+
434
+ function scrollToBottomInstant(): void {
435
+ if (!messagesContainer) return;
436
+ messagesContainer.scrollTo({
437
+ top: messagesContainer.scrollHeight,
438
+ behavior: 'instant',
439
+ });
440
+ }
425
441
 
426
442
  // Auto-scroll to bottom when new messages arrive or on initial load.
427
443
  // Also scrolls on mount/conversation-switch when messages are already present.
@@ -440,11 +456,24 @@
440
456
  onMount(() => {
441
457
  tick().then(() => {
442
458
  if (messagesContainer && visibleMessages.length > 0) {
443
- messagesContainer.scrollTo({ top: messagesContainer.scrollHeight, behavior: 'instant' });
459
+ scrollToBottomInstant();
460
+ }
461
+ // Re-pin after late container resizes (panel open animation, parent
462
+ // layout settling, height restored from prefs).
463
+ if (messagesContainer && typeof ResizeObserver !== 'undefined') {
464
+ containerResizeObserver = new ResizeObserver(() => {
465
+ if (autoScroll) scrollToBottomInstant();
466
+ });
467
+ containerResizeObserver.observe(messagesContainer);
444
468
  }
445
469
  });
446
470
  });
447
471
 
472
+ onDestroy(() => {
473
+ containerResizeObserver?.disconnect();
474
+ containerResizeObserver = null;
475
+ });
476
+
448
477
  function handleScroll() {
449
478
  if (!messagesContainer) return;
450
479
  const { scrollTop, scrollHeight, clientHeight } = messagesContainer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",