44 addEventListener ,
55 executeCallbacks ,
66 useRefById ,
7+ afterTick ,
78} from "svelte-toolbelt" ;
89import { onMount , untrack } from "svelte" ;
910import { Context , watch } from "runed" ;
@@ -40,6 +41,7 @@ import type {
4041 PaneOnExpand ,
4142 PaneOnResize ,
4243 PaneResizeHandleOnDragging ,
44+ PaneTransitionState ,
4345 ResizeEvent ,
4446 ResizeHandler ,
4547} from "$lib/internal/types.js" ;
@@ -717,6 +719,7 @@ type PaneStateProps = WithRefProps<
717719> ;
718720
719721export class PaneState {
722+ #paneTransitionState: PaneTransitionState = $state ( "" ) ;
720723 callbacks = $derived . by ( ( ) => ( {
721724 onCollapse : this . opts . onCollapse . current ,
722725 onExpand : this . opts . onExpand . current ,
@@ -731,11 +734,44 @@ export class PaneState {
731734 minSize : this . opts . minSize . current ,
732735 } ) ) ;
733736
737+ #handleTransition = ( state : PaneTransitionState ) => {
738+ this . #paneTransitionState = state ;
739+ afterTick ( ( ) => {
740+ if ( this . opts . ref . current ) {
741+ const element = this . opts . ref . current ;
742+ const computedStyle = getComputedStyle ( element ) ;
743+
744+ const hasTransition = computedStyle . transitionDuration !== "0s" ;
745+
746+ if ( ! hasTransition ) {
747+ this . #paneTransitionState = "" ;
748+ return ;
749+ }
750+ const handleTransitionEnd = ( event : TransitionEvent ) => {
751+ // Only handle width/flex transitions
752+ if ( event . propertyName === "flex-grow" ) {
753+ this . #paneTransitionState = "" ;
754+ element . removeEventListener ( "transitionend" , handleTransitionEnd ) ;
755+ }
756+ } ;
757+
758+ // Always add the listener - if there's no transition, it won't fire
759+ element . addEventListener ( "transitionend" , handleTransitionEnd ) ;
760+ } else {
761+ this . #paneTransitionState = "" ;
762+ }
763+ } ) ;
764+ } ;
765+
734766 pane = {
735767 collapse : ( ) => {
768+ this . #handleTransition( "collapsing" ) ;
736769 this . group . collapsePane ( this ) ;
737770 } ,
738- expand : ( ) => this . group . expandPane ( this ) ,
771+ expand : ( ) => {
772+ this . #handleTransition( "expanding" ) ;
773+ this . group . expandPane ( this ) ;
774+ } ,
739775 getSize : ( ) => this . group . getPaneSize ( this ) ,
740776 isCollapsed : ( ) => this . group . isPaneCollapsed ( this ) ,
741777 isExpanded : ( ) => this . group . isPaneExpanded ( this ) ,
@@ -763,6 +799,14 @@ export class PaneState {
763799
764800 #isCollapsed = $derived . by ( ( ) => this . group . isPaneCollapsed ( this ) ) ;
765801
802+ #paneState = $derived . by ( ( ) =>
803+ this . #paneTransitionState !== ""
804+ ? this . #paneTransitionState
805+ : this . #isCollapsed
806+ ? "collapsed"
807+ : "expanded"
808+ ) ;
809+
766810 props = $derived . by (
767811 ( ) =>
768812 ( {
@@ -773,6 +817,7 @@ export class PaneState {
773817 "data-pane-group-id" : this . group . opts . id . current ,
774818 "data-collapsed" : this . #isCollapsed ? "" : undefined ,
775819 "data-expanded" : this . #isCollapsed ? undefined : "" ,
820+ "data-pane-state" : this . #paneState,
776821 } ) as const
777822 ) ;
778823}
0 commit comments