@@ -51,15 +51,22 @@ const TableContextProvider = ({
5151 columnCount,
5252 children,
5353} : TableContextProviderProps ) => {
54+ const { contentSize } = useMarkdownContext ( ) ;
5455 const [ columnWidths , setColumnWidths ] = useState < number [ ] > (
5556 Array ( columnCount ) . fill ( 0 ) ,
5657 ) ;
5758
5859 const setColumnWidth = useCallback (
5960 ( index : number , width : number ) => {
61+ console . log ( "setColumnWidth" , index , width ) ;
6062 setColumnWidths ( ( prev ) => {
63+ const minWidth = Math . max ( contentSize . width / columnCount , 64 ) ;
64+ const maxWidth = Math . min ( contentSize . width , 180 ) ;
6165 const old = prev [ index ] ?? 0 ;
62- const newWidth = Math . min ( Math . max ( Math . max ( old , width ) , 64 ) , 180 ) ;
66+ const newWidth = Math . min (
67+ Math . max ( Math . max ( old , width ) , minWidth ) ,
68+ maxWidth ,
69+ ) ;
6370 if ( newWidth === old ) return prev ;
6471
6572 const newColumnWidth = [
@@ -70,7 +77,7 @@ const TableContextProvider = ({
7077 return newColumnWidth ;
7178 } ) ;
7279 } ,
73- [ setColumnWidths ] ,
80+ [ contentSize , columnCount , setColumnWidths ] ,
7481 ) ;
7582
7683 return (
@@ -149,6 +156,11 @@ export const TableCellRenderer = ({
149156 const style = mergeStyles ( styles . tableCell , {
150157 fontWeight : rowIndex === 0 ? "bold" : "normal" ,
151158 } ) ;
159+ const measuredStyle = mergeStyles ( style , {
160+ width : undefined ,
161+ minWidth : undefined ,
162+ maxWidth : undefined ,
163+ } ) ;
152164
153165 const padding = 8 ;
154166 const onTextLayout = useCallback (
@@ -171,21 +183,31 @@ export const TableCellRenderer = ({
171183 ) ;
172184
173185 return (
174- < View
175- style = { {
176- width : width ,
177- minHeight : 32 ,
178- padding : padding ,
179- justifyContent : "center" ,
180- } }
181- >
182- < Text style = { style } > { content } </ Text >
186+ < >
187+ < View
188+ style = { {
189+ width : width ,
190+ minHeight : 32 ,
191+ padding : padding ,
192+ justifyContent : "center" ,
193+ } }
194+ >
195+ < Text style = { style } > { content } </ Text >
196+ </ View >
183197 < Text
184- style = { [ style , { position : "absolute" , opacity : 0 , zIndex : - 100 } ] }
198+ style = { [
199+ measuredStyle ,
200+ {
201+ position : "absolute" ,
202+ opacity : 0 ,
203+ zIndex : - 1000 ,
204+ } ,
205+ ] }
185206 onLayout = { onTextLayout }
207+ numberOfLines = { 1 }
186208 >
187209 { content }
188210 </ Text >
189- </ View >
211+ </ >
190212 ) ;
191213} ;
0 commit comments