@@ -47,6 +47,57 @@ onMounted(() => {
4747 checkHeaderPosition ()
4848})
4949
50+ const windowSize = useWindowSize ()
51+ const sidebar = useTemplateRef <HTMLDivElement >(' sidebar' )
52+ const sidebarContainer = useTemplateRef <HTMLDivElement >(' container' )
53+ const sidebarBounds = useElementBounding (sidebar )
54+ const scrollState = useWindowScroll ()
55+ const scrollDirection = shallowRef <' up' | ' down' >(' down' )
56+ const sidebarOffset = shallowRef ([0 , 0 ])
57+
58+ const sidebarOverflow = computed (() => {
59+ return sidebarBounds .height .value > windowSize .height .value - 120
60+ })
61+
62+ const sidebarStyles = computed (() => {
63+ if (! sidebarOverflow .value ) {
64+ return {
65+ alignSelf: ' flex-start' ,
66+ top: ' 80px' ,
67+ }
68+ }
69+
70+ if (scrollDirection .value === ' down' ) {
71+ return {
72+ alignSelf: ' flex-end' ,
73+ marginBlockStart: ` ${sidebarOffset .value [0 ]}px ` ,
74+ bottom: ' 40px' ,
75+ }
76+ }
77+
78+ if (scrollDirection .value === ' up' ) {
79+ return {
80+ alignSelf: ' flex-start' ,
81+ marginBlockEnd: ` ${sidebarOffset .value [1 ]}px ` ,
82+ top: ' 80px' ,
83+ }
84+ }
85+ })
86+
87+ watch (scrollState .directions , ({ bottom , top }) => {
88+ if (bottom ) scrollDirection .value = ' down'
89+ if (top ) scrollDirection .value = ' up'
90+ })
91+
92+ function checkSidebarPosition() {
93+ sidebarOffset .value = [
94+ sidebar .value ! .offsetTop ,
95+ sidebarContainer .value ! .offsetHeight - sidebar .value ! .offsetTop - sidebar .value ! .offsetHeight ,
96+ ]
97+ }
98+
99+ useEventListener (' scroll' , checkSidebarPosition , { passive: true })
100+
50101const { packageName, requestedVersion, orgName } = usePackageRoute ()
51102const selectedPM = useSelectedPackageManager ()
52103const activePmId = computed (() => selectedPM .value ?? ' npm' )
@@ -1187,11 +1238,9 @@ onKeyStroke(
11871238 </div >
11881239 </section >
11891240 </section >
1190- <div class =" area-sidebar" >
1241+ <div ref = " container " class =" area-sidebar relative flex " >
11911242 <!-- Sidebar -->
1192- <div
1193- class =" sidebar-scroll sticky top-34 space-y-6 sm:space-y-8 min-w-0 overflow-y-auto pe-2.5 lg:(max-h-[calc(100dvh-8.5rem)] overscroll-contain) xl:(top-22 pt-2 max-h-[calc(100dvh-6rem)])"
1194- >
1243+ <div ref =" sidebar" class =" sticky w-full xl:(pt-2)" :style =" sidebarStyles" >
11951244 <!-- Team access controls (for scoped packages when connected) -->
11961245 <ClientOnly >
11971246 <PackageAccessControls :package-name =" pkg.name" />
0 commit comments