@readme/markdown 14.11.1 → 14.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -83,6 +83,34 @@ function useScrollHighlight(navRef: React.RefObject<HTMLElement | null>) {
|
|
|
83
83
|
&& scrollParent.scrollTop + scrollParent.clientHeight >= scrollParent.scrollHeight - SCROLL_BOTTOM_TOLERANCE;
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Keeps the active link visible within the TOC's own scroll container —
|
|
88
|
+
* the same result as `scrollIntoView({ block: 'nearest' })`, but scoped to
|
|
89
|
+
* a single scroller. `scrollIntoView` adjusts *every* scrollable ancestor,
|
|
90
|
+
* and starting a scroll on the page's content scroller cancels any
|
|
91
|
+
* in-flight smooth scroll there — e.g. the hub's scroll-to-top reset when
|
|
92
|
+
* navigating between pages (CX-3667).
|
|
93
|
+
*/
|
|
94
|
+
const scrollTOCLinkIntoView = (link: HTMLAnchorElement) => {
|
|
95
|
+
const tocScroller = getScrollParent(link);
|
|
96
|
+
// Without a TOC-local scroll area, the link's nearest scrollable
|
|
97
|
+
// ancestor is the window (`getScrollParent`'s fallback) or the scroller
|
|
98
|
+
// holding the page content — never auto-scroll those just to reveal a
|
|
99
|
+
// TOC link.
|
|
100
|
+
if (!(tocScroller instanceof HTMLElement) || tocScroller.contains(headings[0])) return;
|
|
101
|
+
|
|
102
|
+
const scrollerRect = tocScroller.getBoundingClientRect();
|
|
103
|
+
const linkRect = link.getBoundingClientRect();
|
|
104
|
+
if (linkRect.top < scrollerRect.top) {
|
|
105
|
+
tocScroller.scrollTo?.({ top: tocScroller.scrollTop + (linkRect.top - scrollerRect.top), behavior: 'smooth' });
|
|
106
|
+
} else if (linkRect.bottom > scrollerRect.bottom) {
|
|
107
|
+
tocScroller.scrollTo?.({
|
|
108
|
+
top: tocScroller.scrollTop + (linkRect.bottom - scrollerRect.bottom),
|
|
109
|
+
behavior: 'smooth',
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
86
114
|
const activate = (id: string | null) => {
|
|
87
115
|
if (id === activeId) return;
|
|
88
116
|
if (activeId) linkMap.get(activeId)?.forEach(a => a.classList.remove('active'));
|
|
@@ -100,7 +128,7 @@ function useScrollHighlight(navRef: React.RefObject<HTMLElement | null>) {
|
|
|
100
128
|
nav.style.setProperty('--ToC-border-active-height', `${linkRect.height}px`);
|
|
101
129
|
nav.style.setProperty('--ToC-border-active-top', `${linkRect.top - navRect.top}px`);
|
|
102
130
|
|
|
103
|
-
link
|
|
131
|
+
scrollTOCLinkIntoView(link);
|
|
104
132
|
}
|
|
105
133
|
}
|
|
106
134
|
};
|
package/dist/main.js
CHANGED
|
@@ -12484,6 +12484,34 @@ function useScrollHighlight(navRef) {
|
|
|
12484
12484
|
return scrollParent.scrollHeight > scrollParent.clientHeight
|
|
12485
12485
|
&& scrollParent.scrollTop + scrollParent.clientHeight >= scrollParent.scrollHeight - SCROLL_BOTTOM_TOLERANCE;
|
|
12486
12486
|
};
|
|
12487
|
+
/**
|
|
12488
|
+
* Keeps the active link visible within the TOC's own scroll container —
|
|
12489
|
+
* the same result as `scrollIntoView({ block: 'nearest' })`, but scoped to
|
|
12490
|
+
* a single scroller. `scrollIntoView` adjusts *every* scrollable ancestor,
|
|
12491
|
+
* and starting a scroll on the page's content scroller cancels any
|
|
12492
|
+
* in-flight smooth scroll there — e.g. the hub's scroll-to-top reset when
|
|
12493
|
+
* navigating between pages (CX-3667).
|
|
12494
|
+
*/
|
|
12495
|
+
const scrollTOCLinkIntoView = (link) => {
|
|
12496
|
+
const tocScroller = getScrollParent(link);
|
|
12497
|
+
// Without a TOC-local scroll area, the link's nearest scrollable
|
|
12498
|
+
// ancestor is the window (`getScrollParent`'s fallback) or the scroller
|
|
12499
|
+
// holding the page content — never auto-scroll those just to reveal a
|
|
12500
|
+
// TOC link.
|
|
12501
|
+
if (!(tocScroller instanceof HTMLElement) || tocScroller.contains(headings[0]))
|
|
12502
|
+
return;
|
|
12503
|
+
const scrollerRect = tocScroller.getBoundingClientRect();
|
|
12504
|
+
const linkRect = link.getBoundingClientRect();
|
|
12505
|
+
if (linkRect.top < scrollerRect.top) {
|
|
12506
|
+
tocScroller.scrollTo?.({ top: tocScroller.scrollTop + (linkRect.top - scrollerRect.top), behavior: 'smooth' });
|
|
12507
|
+
}
|
|
12508
|
+
else if (linkRect.bottom > scrollerRect.bottom) {
|
|
12509
|
+
tocScroller.scrollTo?.({
|
|
12510
|
+
top: tocScroller.scrollTop + (linkRect.bottom - scrollerRect.bottom),
|
|
12511
|
+
behavior: 'smooth',
|
|
12512
|
+
});
|
|
12513
|
+
}
|
|
12514
|
+
};
|
|
12487
12515
|
const activate = (id) => {
|
|
12488
12516
|
if (id === activeId)
|
|
12489
12517
|
return;
|
|
@@ -12500,7 +12528,7 @@ function useScrollHighlight(navRef) {
|
|
|
12500
12528
|
const linkRect = link.getBoundingClientRect();
|
|
12501
12529
|
nav.style.setProperty('--ToC-border-active-height', `${linkRect.height}px`);
|
|
12502
12530
|
nav.style.setProperty('--ToC-border-active-top', `${linkRect.top - navRect.top}px`);
|
|
12503
|
-
link
|
|
12531
|
+
scrollTOCLinkIntoView(link);
|
|
12504
12532
|
}
|
|
12505
12533
|
}
|
|
12506
12534
|
};
|
package/dist/main.node.js
CHANGED
|
@@ -25110,6 +25110,34 @@ function useScrollHighlight(navRef) {
|
|
|
25110
25110
|
return scrollParent.scrollHeight > scrollParent.clientHeight
|
|
25111
25111
|
&& scrollParent.scrollTop + scrollParent.clientHeight >= scrollParent.scrollHeight - SCROLL_BOTTOM_TOLERANCE;
|
|
25112
25112
|
};
|
|
25113
|
+
/**
|
|
25114
|
+
* Keeps the active link visible within the TOC's own scroll container —
|
|
25115
|
+
* the same result as `scrollIntoView({ block: 'nearest' })`, but scoped to
|
|
25116
|
+
* a single scroller. `scrollIntoView` adjusts *every* scrollable ancestor,
|
|
25117
|
+
* and starting a scroll on the page's content scroller cancels any
|
|
25118
|
+
* in-flight smooth scroll there — e.g. the hub's scroll-to-top reset when
|
|
25119
|
+
* navigating between pages (CX-3667).
|
|
25120
|
+
*/
|
|
25121
|
+
const scrollTOCLinkIntoView = (link) => {
|
|
25122
|
+
const tocScroller = TableOfContents_getScrollParent(link);
|
|
25123
|
+
// Without a TOC-local scroll area, the link's nearest scrollable
|
|
25124
|
+
// ancestor is the window (`getScrollParent`'s fallback) or the scroller
|
|
25125
|
+
// holding the page content — never auto-scroll those just to reveal a
|
|
25126
|
+
// TOC link.
|
|
25127
|
+
if (!(tocScroller instanceof HTMLElement) || tocScroller.contains(headings[0]))
|
|
25128
|
+
return;
|
|
25129
|
+
const scrollerRect = tocScroller.getBoundingClientRect();
|
|
25130
|
+
const linkRect = link.getBoundingClientRect();
|
|
25131
|
+
if (linkRect.top < scrollerRect.top) {
|
|
25132
|
+
tocScroller.scrollTo?.({ top: tocScroller.scrollTop + (linkRect.top - scrollerRect.top), behavior: 'smooth' });
|
|
25133
|
+
}
|
|
25134
|
+
else if (linkRect.bottom > scrollerRect.bottom) {
|
|
25135
|
+
tocScroller.scrollTo?.({
|
|
25136
|
+
top: tocScroller.scrollTop + (linkRect.bottom - scrollerRect.bottom),
|
|
25137
|
+
behavior: 'smooth',
|
|
25138
|
+
});
|
|
25139
|
+
}
|
|
25140
|
+
};
|
|
25113
25141
|
const activate = (id) => {
|
|
25114
25142
|
if (id === activeId)
|
|
25115
25143
|
return;
|
|
@@ -25126,7 +25154,7 @@ function useScrollHighlight(navRef) {
|
|
|
25126
25154
|
const linkRect = link.getBoundingClientRect();
|
|
25127
25155
|
nav.style.setProperty('--ToC-border-active-height', `${linkRect.height}px`);
|
|
25128
25156
|
nav.style.setProperty('--ToC-border-active-top', `${linkRect.top - navRect.top}px`);
|
|
25129
|
-
link
|
|
25157
|
+
scrollTOCLinkIntoView(link);
|
|
25130
25158
|
}
|
|
25131
25159
|
}
|
|
25132
25160
|
};
|