@@ -53,7 +53,6 @@ import { folderDropTarget, resolveDroppedFolderPath } from "./folderDrop";
5353import { createModelSelection , normalizeModelSlug } from "@t3tools/shared/model" ;
5454import { USAGE_LIMITS_COMMAND } from "@t3tools/shared/usageLimits" ;
5555import {
56- Fragment ,
5756 memo ,
5857 type ComponentProps ,
5958 type ReactNode ,
@@ -185,17 +184,14 @@ import {
185184import { useComposerPathSearch } from "../../lib/composerPathSearchState" ;
186185import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences" ;
187186import {
188- COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX ,
189- COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX ,
190187 getRestingComposerImagePreviewCounts ,
191188 resolveRestingComposerControlsLayout ,
192189 shouldAnimateComposerRestingTransition ,
193190 shouldUseCompactComposerPrimaryActions ,
194- shouldUseCompactComposerFooter ,
191+ resolveRestingComposerControlsNaturalWidth ,
195192 shouldUseRestingComposerLayout ,
196193} from "../composerFooterLayout" ;
197194import { measureRestingComposerControls } from "./restingComposerControlsMeasurement" ;
198- import { observeResponsiveBreakpointFade , usePanelAnimationSettings } from "../../panelAnimations" ;
199195import { type ComposerPromptEditorHandle , ComposerPromptEditor } from "../ComposerPromptEditor" ;
200196import {
201197 ComposerContextActionsContext ,
@@ -2096,8 +2092,6 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
20962092 key : 0 ,
20972093 active : false ,
20982094 } ) ;
2099- const { active : panelAnimationsActive , durationMs : panelAnimationDurationMs } =
2100- usePanelAnimationSettings ( ) ;
21012095 const isComposerCollapsedMobile =
21022096 isMobileViewport && ! forceExpandedOnMobile && ! isComposerFocused && ! hasMultilinePrompt ;
21032097
@@ -3133,71 +3127,48 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
31333127 // ------------------------------------------------------------------
31343128 // Footer compact layout observation
31353129 // ------------------------------------------------------------------
3136- useLayoutEffect ( ( ) => {
3130+ const measureFooterCompactness = useCallback ( ( ) => {
31373131 const composerForm = composerFormRef . current ;
31383132 if ( ! composerForm ) return ;
3139- const measureComposerFormWidth = ( ) => composerForm . clientWidth ;
3140- const measureFooterCompactness = ( ) => {
3141- const composerFormWidth = measureComposerFormWidth ( ) ;
3142- const footerCompact = shouldUseCompactComposerFooter ( composerFormWidth , {
3133+ setIsComposerPrimaryActionsCompact (
3134+ shouldUseCompactComposerPrimaryActions ( composerForm . clientWidth , {
31433135 hasWideActions : composerFooterHasWideActions ,
3144- } ) ;
3145- const primaryActionsCompact =
3146- footerCompact &&
3147- shouldUseCompactComposerPrimaryActions ( composerFormWidth , {
3148- hasWideActions : composerFooterHasWideActions ,
3149- } ) ;
3150- return {
3151- primaryActionsCompact,
3152- footerCompact,
3153- } ;
3154- } ;
3155-
3156- const initialCompactness = measureFooterCompactness ( ) ;
3157- setIsComposerPrimaryActionsCompact ( initialCompactness . primaryActionsCompact ) ;
3158- setIsComposerFooterCompact ( initialCompactness . footerCompact ) ;
3159- if ( typeof ResizeObserver === "undefined" ) return ;
3160- const footerControls = composerFooterControlsRef . current ;
3161- const stopFooterControlsFade = footerControls
3162- ? observeResponsiveBreakpointFade ( {
3163- target : footerControls ,
3164- container : composerForm ,
3165- active : panelAnimationsActive ,
3166- durationMs : panelAnimationDurationMs ,
3167- breakpoint : {
3168- value : composerFooterHasWideActions
3169- ? COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX
3170- : COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX ,
3171- unit : "px" ,
3172- } ,
3173- } )
3174- : undefined ;
3175-
3176- const observer = new ResizeObserver ( ( ) => {
3177- const nextCompactness = measureFooterCompactness ( ) ;
3178- setIsComposerPrimaryActionsCompact ( ( previous ) =>
3179- previous === nextCompactness . primaryActionsCompact
3180- ? previous
3181- : nextCompactness . primaryActionsCompact ,
3182- ) ;
3183- setIsComposerFooterCompact ( ( previous ) =>
3184- previous === nextCompactness . footerCompact ? previous : nextCompactness . footerCompact ,
3185- ) ;
3186- } ) ;
3187-
3136+ } ) ,
3137+ ) ;
3138+ const controls = composerFooterControlsRef . current ;
3139+ if ( ! controls || controls . clientWidth === 0 ) return ;
3140+ const measurement = measureRestingComposerControls ( controls ) ;
3141+ if ( ! measurement ) return ;
3142+ const style = getComputedStyle ( controls ) ;
3143+ const availableWidth =
3144+ controls . clientWidth -
3145+ ( Number . parseFloat ( style . paddingInlineStart ) || 0 ) -
3146+ ( Number . parseFloat ( style . paddingInlineEnd ) || 0 ) ;
3147+ const naturalWidth = resolveRestingComposerControlsNaturalWidth ( measurement ) ;
3148+ // Hidden controls keep their natural width, so reopening the footer does
3149+ // not depend on the smaller overflow menu. Leave a pixel for rounding.
3150+ setIsComposerFooterCompact ( ( previous ) => naturalWidth > availableWidth - ( previous ? 1 : 0 ) ) ;
3151+ } , [ composerFooterHasWideActions ] ) ;
3152+
3153+ useLayoutEffect ( measureFooterCompactness ) ;
3154+ useEffect ( ( ) => {
3155+ const composerForm = composerFormRef . current ;
3156+ if ( ! composerForm || typeof ResizeObserver === "undefined" ) return ;
3157+ const observer = new ResizeObserver ( measureFooterCompactness ) ;
31883158 observer . observe ( composerForm ) ;
3159+ const controls = composerFooterControlsRef . current ;
3160+ if ( controls ) observer . observe ( controls ) ;
3161+ document . fonts . addEventListener ( "loadingdone" , measureFooterCompactness ) ;
31893162 return ( ) => {
31903163 observer . disconnect ( ) ;
3191- stopFooterControlsFade ?. ( ) ;
3164+ document . fonts . removeEventListener ( "loadingdone" , measureFooterCompactness ) ;
31923165 } ;
31933166 } , [
31943167 activeThreadId ,
31953168 composerFooterActionLayoutKey ,
3196- composerFooterHasWideActions ,
31973169 isComposerApprovalState ,
31983170 isComposerCollapsedMobile ,
3199- panelAnimationDurationMs ,
3200- panelAnimationsActive ,
3171+ measureFooterCompactness ,
32013172 ] ) ;
32023173
32033174 // ------------------------------------------------------------------
@@ -4909,7 +4880,12 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
49094880 content : (
49104881 < >
49114882 < ComposerControlSeparator size = { composerControlsInStrip ? "xs" : "sm" } />
4912- { composerControlsInStrip ? restingProviderTraitsPicker : providerTraitsPicker }
4883+ { composerControlsInStrip
4884+ ? restingProviderTraitsPicker
4885+ : renderProviderTraitsPicker ( {
4886+ ...providerTraitsPickerInput ,
4887+ hidden : composerControlsHidden || composerControlsCompact ,
4888+ } ) }
49134889 </ >
49144890 ) ,
49154891 } ,
@@ -4923,7 +4899,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
49234899 interactionMode = { interactionMode }
49244900 runtimeMode = { runtimeMode }
49254901 size = { composerControlsInStrip ? "xs" : "sm" }
4926- hidden = { composerControlsHidden || restingHiddenBlockCount > 0 }
4902+ hidden = { composerControlsHidden || composerControlsCompact || restingHiddenBlockCount > 0 }
49274903 onToggleInteractionMode = { toggleInteractionMode }
49284904 onRuntimeModeChange = { handleRuntimeModeChange }
49294905 />
@@ -5052,56 +5028,49 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
50525028 onToggleInteractionMode = { toggleInteractionMode }
50535029 onRuntimeModeChange = { handleRuntimeModeChange }
50545030 />
5055- ) : (
5056- < >
5057- { restingBlockDefs . map ( ( def , index ) => {
5058- if ( ! composerControlsInStrip ) {
5059- return < Fragment key = { def . id } > { def . content } </ Fragment > ;
5031+ ) : null }
5032+ { restingBlockDefs . map ( ( def , index ) => {
5033+ const hidden =
5034+ composerControlsCompact || index >= restingBlockDefs . length - restingHiddenBlockCount ;
5035+ return (
5036+ < div
5037+ key = { def . id }
5038+ data-resting-block = { def . id }
5039+ aria-hidden = { hidden || undefined }
5040+ inert = { hidden || undefined }
5041+ className = { cn (
5042+ "flex w-max min-w-max shrink-0 items-center gap-1" ,
5043+ hidden && "pointer-events-none invisible absolute" ,
5044+ ) }
5045+ >
5046+ { def . content }
5047+ </ div >
5048+ ) ;
5049+ } ) }
5050+ { composerControlsInStrip ? (
5051+ < div
5052+ data-resting-controls-overflow
5053+ aria-hidden = { hiddenRestingBlockIds . length === 0 || undefined }
5054+ inert = { hiddenRestingBlockIds . length === 0 || undefined }
5055+ className = { cn (
5056+ "min-w-0 shrink-0" ,
5057+ hiddenRestingBlockIds . length === 0 && "pointer-events-none invisible absolute" ,
5058+ ) }
5059+ >
5060+ < CompactComposerControlsMenu
5061+ interactionMode = { interactionMode }
5062+ runtimeMode = { runtimeMode }
5063+ size = "xs"
5064+ hidden = { composerControlsHidden || hiddenRestingBlockIds . length === 0 }
5065+ showInteractionModeToggle = { planModeUiEnabled && hiddenRestingBlockIds . includes ( "mode" ) }
5066+ traitsMenuContent = {
5067+ hiddenRestingBlockIds . includes ( "traits" ) ? providerTraitsMenuContent : undefined
50605068 }
5061- const hidden = index >= restingBlockDefs . length - restingHiddenBlockCount ;
5062- return (
5063- < div
5064- key = { def . id }
5065- data-resting-block = { def . id }
5066- aria-hidden = { hidden || undefined }
5067- inert = { hidden || undefined }
5068- className = { cn (
5069- "flex w-max min-w-max shrink-0 items-center gap-1" ,
5070- hidden && "pointer-events-none invisible absolute" ,
5071- ) }
5072- >
5073- { def . content }
5074- </ div >
5075- ) ;
5076- } ) }
5077- { composerControlsInStrip ? (
5078- < div
5079- data-resting-controls-overflow
5080- aria-hidden = { hiddenRestingBlockIds . length === 0 || undefined }
5081- inert = { hiddenRestingBlockIds . length === 0 || undefined }
5082- className = { cn (
5083- "min-w-0 shrink-0" ,
5084- hiddenRestingBlockIds . length === 0 && "pointer-events-none invisible absolute" ,
5085- ) }
5086- >
5087- < CompactComposerControlsMenu
5088- interactionMode = { interactionMode }
5089- runtimeMode = { runtimeMode }
5090- size = "xs"
5091- hidden = { composerControlsHidden || hiddenRestingBlockIds . length === 0 }
5092- showInteractionModeToggle = {
5093- planModeUiEnabled && hiddenRestingBlockIds . includes ( "mode" )
5094- }
5095- traitsMenuContent = {
5096- hiddenRestingBlockIds . includes ( "traits" ) ? providerTraitsMenuContent : undefined
5097- }
5098- onToggleInteractionMode = { toggleInteractionMode }
5099- onRuntimeModeChange = { handleRuntimeModeChange }
5100- />
5101- </ div >
5102- ) : null }
5103- </ >
5104- ) }
5069+ onToggleInteractionMode = { toggleInteractionMode }
5070+ onRuntimeModeChange = { handleRuntimeModeChange }
5071+ />
5072+ </ div >
5073+ ) : null }
51055074 </ >
51065075 ) ;
51075076 const showTasksTab =
@@ -6901,9 +6870,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
69016870 data-chat-composer-footer = "true"
69026871 data-chat-composer-footer-compact = { isComposerFooterCompact ? "true" : "false" }
69036872 className = { cn (
6904- "flex min-w-0 flex-nowrap items-center justify-between gap-2 overflow-visible px-3 pb-3 sm:px-4 sm:pb-4" ,
6873+ "flex min-w-0 flex-nowrap items-center justify-between gap-2 overflow-visible px-3 pb-3 sm:gap-0 sm: px-4 sm:pb-4" ,
69056874 pendingUserInputs . length > 0 && "pt-2" ,
6906- isComposerFooterCompact ? "gap-1.5" : "gap-2 sm:gap-0" ,
69076875 showMobilePendingAnswerActions && "hidden sm:flex" ,
69086876 isComposerResting &&
69096877 "absolute bottom-px right-px z-10 h-12 w-auto gap-0 py-0 sm:gap-0 sm:py-0" ,
0 commit comments