diff --git a/src/lib/components/AIGlyphPopup.svelte b/src/lib/components/AIPromptPopup.svelte similarity index 84% rename from src/lib/components/AIGlyphPopup.svelte rename to src/lib/components/AIPromptPopup.svelte index fb68de86..ded983f1 100644 --- a/src/lib/components/AIGlyphPopup.svelte +++ b/src/lib/components/AIPromptPopup.svelte @@ -4,18 +4,31 @@ import CloseIcon from '~icons/material-symbols/close-rounded'; interface Props { - top: number; show: boolean; - suggestion: string; + input: string; onClose: () => void; + onHeightChange?: (height: number) => void; onTryFree: () => void; } - let { top, show, suggestion = $bindable(), onClose, onTryFree }: Props = $props(); + let { show, input = $bindable(), onClose, onHeightChange, onTryFree }: Props = $props(); let textarea = $state(); let container = $state(); + $effect(() => { + if (!container || !onHeightChange) return; + const observer = new ResizeObserver((entries) => { + for (const entry of entries) { + if (entry.target instanceof HTMLElement) { + onHeightChange(entry.target.offsetHeight); + } + } + }); + observer.observe(container); + return () => observer.disconnect(); + }); + function resizeTextarea() { if (!textarea) return; const computed = globalThis.getComputedStyle(textarea); @@ -34,7 +47,7 @@ } $effect(() => { - if (suggestion !== undefined) { + if (input !== undefined) { resizeTextarea(); } }); @@ -58,21 +71,20 @@