@@ -86,27 +86,48 @@ const getRenderedRowHeight = (row) => {
8686 return Math . max ( Math . round ( rectHeight ) , Math . round ( offsetHeight ) , 0 ) ;
8787} ;
8888
89+ const rowHasFolderPreview = ( row ) => {
90+ return ! ! ( row && row . querySelector && row . querySelector ( 'div.folder-preview' ) ) ;
91+ } ;
92+
8993const syncFolderRowsHeight = ( rows ) => {
9094 if ( ! rows || ! rows . length ) {
9195 return 0 ;
9296 }
93- let maxHeight = 0 ;
97+ let baseHeight = 0 ;
9498 rows . forEach ( ( row ) => {
95- maxHeight = Math . max ( maxHeight , getRenderedRowHeight ( row ) ) ;
99+ if ( rowHasFolderPreview ( row ) ) {
100+ baseHeight = Math . max ( baseHeight , getRenderedRowHeight ( row ) ) ;
101+ }
96102 } ) ;
97- if ( maxHeight <= 0 ) {
103+ if ( baseHeight <= 0 ) {
104+ rows . forEach ( ( row ) => {
105+ baseHeight = Math . max ( baseHeight , getRenderedRowHeight ( row ) ) ;
106+ } ) ;
107+ }
108+ if ( baseHeight <= 0 ) {
98109 return 0 ;
99110 }
111+
100112 rows . forEach ( ( row ) => {
101- row . style . setProperty ( 'height' , `${ maxHeight } px` , 'important' ) ;
113+ const shouldSyncHeight = ! rowHasFolderPreview ( row ) ;
114+ if ( shouldSyncHeight ) {
115+ row . style . setProperty ( 'height' , `${ baseHeight } px` , 'important' ) ;
116+ } else {
117+ row . style . removeProperty ( 'height' ) ;
118+ }
102119 Array . from ( row . children || [ ] ) . forEach ( ( td ) => {
103120 if ( td && td . tagName === 'TD' ) {
104- td . style . setProperty ( 'height' , `${ maxHeight } px` , 'important' ) ;
121+ if ( shouldSyncHeight ) {
122+ td . style . setProperty ( 'height' , `${ baseHeight } px` , 'important' ) ;
123+ } else {
124+ td . style . removeProperty ( 'height' ) ;
125+ }
105126 td . style . setProperty ( 'vertical-align' , 'middle' , 'important' ) ;
106127 }
107128 } ) ;
108129 } ) ;
109- return maxHeight ;
130+ return baseHeight ;
110131} ;
111132
112133const applyFolderCellCentering = ( cell , rowHeight = 0 ) => {
@@ -127,14 +148,16 @@ const applyFolderCellCentering = (cell, rowHeight = 0) => {
127148 return false ;
128149 }
129150
130- const height = Number . isFinite ( rowHeight ) && rowHeight > 0 ? Math . round ( rowHeight ) : getRenderedRowHeight ( cell . parentElement ) ;
151+ const height = Number . isFinite ( rowHeight ) && rowHeight > 0 ? Math . round ( rowHeight ) : 0 ;
131152 cell . style . setProperty ( 'vertical-align' , 'middle' , 'important' ) ;
132153 cell . style . setProperty ( 'position' , 'static' , 'important' ) ;
133154 cell . style . setProperty ( 'display' , 'table-cell' , 'important' ) ;
134155 cell . style . setProperty ( 'padding-top' , '0px' , 'important' ) ;
135156 cell . style . setProperty ( 'padding-bottom' , '0px' , 'important' ) ;
136157 if ( height > 0 ) {
137158 cell . style . setProperty ( 'height' , `${ height } px` , 'important' ) ;
159+ } else {
160+ cell . style . removeProperty ( 'height' ) ;
138161 }
139162
140163 sub . style . setProperty ( 'position' , 'relative' , 'important' ) ;
@@ -144,10 +167,12 @@ const applyFolderCellCentering = (cell, rowHeight = 0) => {
144167 sub . style . setProperty ( 'transform' , 'none' , 'important' ) ;
145168 sub . style . setProperty ( 'display' , 'flex' , 'important' ) ;
146169 sub . style . setProperty ( 'align-items' , 'center' , 'important' ) ;
147- sub . style . setProperty ( 'min-height' , '48px ' , 'important' ) ;
170+ sub . style . setProperty ( 'min-height' , '0 ' , 'important' ) ;
148171 sub . style . setProperty ( 'width' , '100%' , 'important' ) ;
149172 if ( height > 0 ) {
150173 sub . style . setProperty ( 'height' , `${ Math . max ( 0 , height - 2 ) } px` , 'important' ) ;
174+ } else {
175+ sub . style . removeProperty ( 'height' ) ;
151176 }
152177
153178 return true ;
@@ -172,16 +197,17 @@ const forceAllFolderRowsVerticalCenter = () => {
172197 const syncedHeight = syncFolderRowsHeight ( rows ) ;
173198 rows . forEach ( ( row ) => {
174199 handledRows . add ( row ) ;
200+ const rowHeight = rowHasFolderPreview ( row ) ? 0 : syncedHeight ;
175201 row . querySelectorAll ( 'td.ct-name.folder-name' ) . forEach ( ( cell ) => {
176- applyFolderCellCentering ( cell , syncedHeight ) ;
202+ applyFolderCellCentering ( cell , rowHeight ) ;
177203 } ) ;
178204 } ) ;
179205 } ) ;
180206
181207 document . querySelectorAll ( 'td.ct-name.folder-name' ) . forEach ( ( cell ) => {
182208 const parentRow = cell . parentElement ;
183209 if ( ! handledRows . has ( parentRow ) ) {
184- applyFolderCellCentering ( cell , getRenderedRowHeight ( parentRow ) ) ;
210+ applyFolderCellCentering ( cell , rowHasFolderPreview ( parentRow ) ? 0 : getRenderedRowHeight ( parentRow ) ) ;
185211 }
186212 } ) ;
187213} ;
@@ -195,8 +221,9 @@ const forceFolderRowVerticalCenter = (id) => {
195221 }
196222 const syncedHeight = syncFolderRowsHeight ( rows ) ;
197223 rows . forEach ( ( row ) => {
224+ const rowHeight = rowHasFolderPreview ( row ) ? 0 : syncedHeight ;
198225 row . querySelectorAll ( 'td.ct-name.folder-name' ) . forEach ( ( cell ) => {
199- applyFolderCellCentering ( cell , syncedHeight ) ;
226+ applyFolderCellCentering ( cell , rowHeight ) ;
200227 } ) ;
201228 } ) ;
202229} ;
0 commit comments