@@ -147,7 +147,7 @@ pub struct StyleSheet {
147147 #[ serde( default ) ]
148148 pub global_css_files : BTreeSet < String > ,
149149 #[ serde( default ) ]
150- pub imports : BTreeMap < String , String > ,
150+ pub imports : BTreeMap < String , BTreeSet < String > > ,
151151 #[ serde( skip) ]
152152 pub theme : Theme ,
153153}
@@ -182,7 +182,10 @@ impl StyleSheet {
182182
183183 pub fn add_import ( & mut self , file : & str , import : & str ) {
184184 self . global_css_files . insert ( file. to_string ( ) ) ;
185- self . imports . insert ( file. to_string ( ) , import. to_string ( ) ) ;
185+ self . imports
186+ . entry ( file. to_string ( ) )
187+ . or_default ( )
188+ . insert ( import. to_string ( ) ) ;
186189 }
187190
188191 pub fn add_css ( & mut self , file : & str , css : & str ) -> bool {
@@ -289,6 +292,7 @@ impl StyleSheet {
289292 let mut css = self
290293 . imports
291294 . values ( )
295+ . flatten ( )
292296 . map ( |import| format ! ( "@import \" {import}\" ;" ) )
293297 . collect :: < Vec < String > > ( )
294298 . join ( "" ) ;
@@ -902,12 +906,26 @@ mod tests {
902906
903907 #[ test]
904908 fn test_create_css_with_imports ( ) {
905- let mut sheet = StyleSheet :: default ( ) ;
906- sheet. add_import ( "test.tsx" , "@devup-ui/core/css/global.css" ) ;
907- sheet. add_import ( "test2.tsx" , "@devup-ui/core/css/global2.css" ) ;
908- sheet. add_import ( "test3.tsx" , "@devup-ui/core/css/global3.css" ) ;
909- sheet. add_import ( "test4.tsx" , "@devup-ui/core/css/global4.css" ) ;
910- assert_debug_snapshot ! ( sheet. create_css( ) ) ;
909+ {
910+ let mut sheet = StyleSheet :: default ( ) ;
911+ sheet. add_import ( "test.tsx" , "@devup-ui/core/css/global.css" ) ;
912+ sheet. add_import ( "test2.tsx" , "@devup-ui/core/css/global2.css" ) ;
913+ sheet. add_import ( "test3.tsx" , "@devup-ui/core/css/global3.css" ) ;
914+ sheet. add_import ( "test4.tsx" , "@devup-ui/core/css/global4.css" ) ;
915+ assert_debug_snapshot ! ( sheet. create_css( ) ) ;
916+ }
917+ {
918+ let mut sheet = StyleSheet :: default ( ) ;
919+ sheet. add_import ( "test.tsx" , "@devup-ui/core/css/global.css" ) ;
920+ sheet. add_import ( "test.tsx" , "@devup-ui/core/css/new-global.css" ) ;
921+ assert_debug_snapshot ! ( sheet. create_css( ) ) ;
922+ }
923+ {
924+ let mut sheet = StyleSheet :: default ( ) ;
925+ sheet. add_import ( "test.tsx" , "@devup-ui/core/css/global.css" ) ;
926+ sheet. add_import ( "test.tsx" , "@devup-ui/core/css/global.css" ) ;
927+ assert_debug_snapshot ! ( sheet. create_css( ) ) ;
928+ }
911929 }
912930
913931 #[ test]
0 commit comments