@@ -45,7 +45,7 @@ import {
4545 WrapTextIcon ,
4646 type LucideIcon ,
4747} from "lucide-react" ;
48- import { Check , Copy } from "lucide" ;
48+ import { Check , Copy , Maximize2 , Minimize2 } from "lucide" ;
4949import {
5050 AuthPreviewOperateScope ,
5151 type AssetResource ,
@@ -593,49 +593,25 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
593593 const [ hasClippedCells , setHasClippedCells ] = useState ( false ) ;
594594 const [ copied , setCopied ] = useState ( false ) ;
595595 const copiedTimerRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
596- const wrapButtonRef = useRef < HTMLButtonElement | null > ( null ) ;
597- const copyButtonRef = useRef < HTMLButtonElement | null > ( null ) ;
598- const wrapLabel = expanded ? "Disable cell wrap" : "Wrap long cells" ;
596+ const expandLabel = expanded ? "Collapse table cells" : "Expand table cells" ;
599597 const copyLabel = copied ? "Copied" : "Copy table" ;
600598
601599 const measureClippedCells = useCallback ( ( ) => {
602600 const container = containerRef . current ;
603601 const table = tableRef . current ;
604602 if ( ! container || ! table ) return ;
605- const clipped = tableHasClippedCells ( container , table ) ;
606- // Hiding the focused wrap button would drop keyboard focus to the page.
607- if ( ! clipped && wrapButtonRef . current === document . activeElement ) {
608- copyButtonRef . current ?. focus ( ) ;
609- }
610- setHasClippedCells ( clipped ) ;
603+ setHasClippedCells ( tableHasClippedCells ( container , table ) ) ;
611604 } , [ ] ) ;
612605
613606 // A streamed cell can grow until it clips while the table keeps its size,
614607 // so remeasure after every render, not only on resize.
615608 useLayoutEffect ( measureClippedCells ) ;
616609
617- // Column width changes, late fonts, and images settling inside cells can
618- // clip a cell without rendering this table.
610+ // Column width changes can clip a cell without rendering this table.
619611 useLayoutEffect ( ( ) => {
620612 const table = tableRef . current ;
621613 if ( ! table ) return ;
622- let frame = 0 ;
623- const measureNextFrame = ( ) => {
624- cancelAnimationFrame ( frame ) ;
625- frame = requestAnimationFrame ( measureClippedCells ) ;
626- } ;
627- // Media load and error events don't bubble, so listen in the capture phase.
628- table . addEventListener ( "load" , measureNextFrame , true ) ;
629- table . addEventListener ( "error" , measureNextFrame , true ) ;
630- document . fonts ?. addEventListener ( "loadingdone" , measureNextFrame ) ;
631- const stopObserving = observeResize ( table , measureClippedCells ) ;
632- return ( ) => {
633- cancelAnimationFrame ( frame ) ;
634- table . removeEventListener ( "load" , measureNextFrame , true ) ;
635- table . removeEventListener ( "error" , measureNextFrame , true ) ;
636- document . fonts ?. removeEventListener ( "loadingdone" , measureNextFrame ) ;
637- stopObserving ( ) ;
638- } ;
614+ return observeResize ( table , measureClippedCells ) ;
639615 } , [ measureClippedCells ] ) ;
640616
641617 function toggleExpanded ( ) {
@@ -715,19 +691,18 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
715691 < TooltipTrigger
716692 render = {
717693 < Button
718- ref = { wrapButtonRef }
719694 type = "button"
720695 variant = { expanded ? "secondary" : "ghost-muted" }
721696 size = "icon-xs"
722697 aria-pressed = { expanded }
723698 onClick = { toggleExpanded }
724- aria-label = { wrapLabel }
699+ aria-label = { expandLabel }
725700 />
726701 }
727702 >
728- < WrapTextIcon className = "size-3" />
703+ < MorphIcon className = "size-3" icon = { expanded ? Minimize2 : Maximize2 } />
729704 </ TooltipTrigger >
730- < TooltipPopup side = "top" > { wrapLabel } </ TooltipPopup >
705+ < TooltipPopup side = "top" > { expandLabel } </ TooltipPopup >
731706 </ Tooltip >
732707 ) : (
733708 < span />
@@ -739,7 +714,6 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
739714 < MenuTrigger
740715 render = {
741716 < Button
742- ref = { copyButtonRef }
743717 type = "button"
744718 variant = "ghost-muted"
745719 size = "icon-xs"
0 commit comments