@@ -413,66 +413,62 @@ export default defineComponent({
413413 const before = slots . before ?.( ) ;
414414 const after = slots . after ?.( ) ;
415415
416- const tocContent =
417- tocHeaders || before || after
418- ? h ( "div" , { class : "vp-toc-placeholder" } , [
419- h ( "aside" , { id : "toc" , "vp-toc" : "" } , [
420- // Optional "before" slot
421- before ,
422- // The TOC itself
423- tocHeaders
424- ? [
425- h (
426- "div" ,
427- { class : "vp-toc-header" , onClick : toggleExpanded } ,
428- [
429- metaLocale . value . toc ,
430- h ( PrintButton ) ,
431- h ( "div" , {
432- class : [ "arrow" , isExpanded . value ? "down" : "end" ] ,
433- } ) ,
434- ]
435- ) ,
436- h (
437- "div" ,
438- {
439- class : [
440- "vp-toc-wrapper" ,
441- isExpanded . value ? "open" : "" ,
442- ] ,
443- ref : toc ,
416+ return h ( ClientOnly , ( ) => {
417+ if ( ! tocHeaders && ! before && ! after ) return null ;
418+
419+ // Main TOC container
420+ const tocContent = h ( "div" , { class : "vp-toc-placeholder" } , [
421+ h ( "aside" , { id : "toc" , "vp-toc" : "" } , [
422+ before ,
423+ tocHeaders
424+ ? [
425+ h (
426+ "div" ,
427+ {
428+ class : "vp-toc-header" ,
429+ onClick : ( ) => toggleExpanded ( ) ,
430+ } ,
431+ [
432+ metaLocale . value . toc ,
433+ h ( PrintButton ) ,
434+ h ( "div" , {
435+ class : [ "arrow" , isExpanded . value ? "down" : "end" ] ,
436+ } ) ,
437+ ]
438+ ) ,
439+ h (
440+ "div" ,
441+ {
442+ class : [ "vp-toc-wrapper" , isExpanded . value ? "open" : "" ] ,
443+ ref : toc ,
444+ } ,
445+ [
446+ tocHeaders ,
447+ h ( "div" , {
448+ class : "vp-toc-marker" ,
449+ style : {
450+ top : tocMarkerTop . value ,
444451 } ,
445- [
446- tocHeaders ,
447- h ( "div" , {
448- class : "vp-toc-marker" ,
449- style : { top : tocMarkerTop . value } ,
450- } ) ,
451- ]
452- ) ,
452+ } ) ,
453453 ]
454- : null ,
455- // Optional "after" slot
456- after ,
457- // On desktop: render survey form inside the TOC container
458- ! isMobile . value
459- ? h ( "div" , { class : "toc-survey-section" } , [
460- renderSurveyForm ( ) ,
461- ] )
462- : null ,
463- ] ) ,
464- ] )
454+ ) ,
455+ ]
456+ : null ,
457+ after ,
458+ // Add survey form inside the TOC for desktop
459+ ! isMobile . value
460+ ? h ( "div" , { class : "toc-survey-section" } , [ renderSurveyForm ( ) ] )
461+ : null ,
462+ ] ) ,
463+ ] ) ;
464+
465+ // For mobile: create a separate teleported component
466+ const mobileSurvey = isMobile . value
467+ ? h ( Teleport , { to : ".markdown-content" } , [ renderSurveyForm ( ) ] )
465468 : null ;
466469
467- return h ( ClientOnly , ( ) =>
468- h ( "div" , { } , [
469- tocContent ,
470- // On mobile: teleport the survey form to the element with class "theme-hope-content"
471- isMobile . value
472- ? h ( Teleport , { to : ".theme-hope-content" } , [ renderSurveyForm ( ) ] )
473- : null ,
474- ] )
475- ) ;
470+ return mobileSurvey ? [ tocContent , mobileSurvey ] : tocContent ;
471+ } ) ;
476472 } ;
477473 } ,
478474} ) ;
0 commit comments