@@ -7,6 +7,7 @@ import { PropertyPanelFlatHeader } from "./PropertyPanelFlatHeader";
77import { PropertyPanelFlatFooter } from "./PropertyPanelFlatFooter" ;
88import { FlatGroup } from "./propertyPanelFlatPrimitives" ;
99import { FlatTextSection } from "./propertyPanelFlatTextSection" ;
10+ import { FlatStyleSection } from "./propertyPanelFlatStyleSections" ;
1011import { formatTextFieldPreview , StyleSections } from "./propertyPanelSections" ;
1112import { TimingSection } from "./propertyPanelTimingSection" ;
1213import { ColorGradingSection } from "./propertyPanelColorGradingSection" ;
@@ -102,15 +103,25 @@ export function PropertyPanelFlat({
102103 clipboardCopied : boolean ;
103104 onCopyElementInfo : ( ) => void ;
104105} ) {
105- // Defaulting to "text" is harmless for a non-text element even though the
106- // Text FlatGroup won't render (nothing else reads openGroupId yet) — this
107- // only matters once a second FlatGroup exists (Plan 2+), at which point a
108- // non-text element should default-open that group instead.
109- const [ openGroupId , setOpenGroupId ] = useState < string > ( "text" ) ;
106+ // Lazy initializer: pick whichever group actually renders for this element
107+ // (Text if text-editable, else Style if style-editable, else none open) so a
108+ // style-only element doesn't start with everything collapsed. Only runs on
109+ // mount — PropertyPanel.tsx keys <PropertyPanelFlat> by element identity so
110+ // switching the selection re-mounts this component and re-derives the
111+ // default instead of preserving stale state across unrelated elements.
112+ const [ openGroupId , setOpenGroupId ] = useState < string > ( ( ) =>
113+ isTextEditableSelection ( element ) ? "text" : showEditableSections ? "style" : "" ,
114+ ) ;
110115 const [ pinnedGroupIds , setPinnedGroupIds ] = useState < string [ ] > ( [ ] ) ;
111116
112117 const isTextEditable = isTextEditableSelection ( element ) ;
113118 const elementKind = sections . media ? "media" : element . textFields . length > 0 ? "text" : "other" ;
119+ const toggleOpen = ( groupId : string ) =>
120+ setOpenGroupId ( ( current ) => ( current === groupId ? "" : groupId ) ) ;
121+ const togglePin = ( groupId : string ) =>
122+ setPinnedGroupIds ( ( current ) =>
123+ current . includes ( groupId ) ? current . filter ( ( id ) => id !== groupId ) : [ ...current , groupId ] ,
124+ ) ;
114125
115126 return (
116127 < div className = "flex h-full min-h-0 flex-col overflow-hidden bg-panel-bg text-panel-text-1" >
@@ -136,14 +147,8 @@ export function PropertyPanelFlat({
136147 title = "Text"
137148 isOpen = { openGroupId === "text" || pinnedGroupIds . includes ( "text" ) }
138149 isPinned = { pinnedGroupIds . includes ( "text" ) }
139- onToggleOpen = { ( ) => setOpenGroupId ( ( current ) => ( current === "text" ? "" : "text" ) ) }
140- onTogglePin = { ( ) =>
141- setPinnedGroupIds ( ( current ) =>
142- current . includes ( "text" )
143- ? current . filter ( ( id ) => id !== "text" )
144- : [ ...current , "text" ] ,
145- )
146- }
150+ onToggleOpen = { ( ) => toggleOpen ( "text" ) }
151+ onTogglePin = { ( ) => togglePin ( "text" ) }
147152 summary = { formatTextFieldPreview ( element . textFields [ 0 ] ?. value ?? "" ) }
148153 >
149154 < FlatTextSection
@@ -159,6 +164,27 @@ export function PropertyPanelFlat({
159164 </ FlatGroup >
160165 ) }
161166
167+ { showEditableSections && (
168+ < FlatGroup
169+ title = "Style"
170+ isOpen = { openGroupId === "style" || pinnedGroupIds . includes ( "style" ) }
171+ isPinned = { pinnedGroupIds . includes ( "style" ) }
172+ onToggleOpen = { ( ) => toggleOpen ( "style" ) }
173+ onTogglePin = { ( ) => togglePin ( "style" ) }
174+ summary = { `fill ${ styles [ "background-image" ] && styles [ "background-image" ] !== "none" ? "image/gradient" : styles [ "background-color" ] ? "set" : "none" } · ${ Math . round ( ( parseFloat ( styles . opacity ?? "1" ) || 1 ) * 100 ) } %` }
175+ >
176+ < FlatStyleSection
177+ projectId = { projectId }
178+ element = { element }
179+ styles = { styles }
180+ assets = { assets }
181+ onSetStyle = { onSetStyle }
182+ onImportAssets = { onImportAssets }
183+ gsapBorderRadius = { gsapBorderRadius }
184+ />
185+ </ FlatGroup >
186+ ) }
187+
162188 { sections . timing && (
163189 < TimingSection
164190 element = { element }
0 commit comments