@salesforcedevs/docs-components
Advanced tools
Comparing version
{ | ||
"name": "@salesforcedevs/docs-components", | ||
"version": "1.3.345-refactor-tab-alpha2", | ||
"version": "1.3.345-refactor-tab-alpha3", | ||
"description": "Docs Lightning web components for DSC", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -154,2 +154,5 @@ /* eslint-disable @lwc/lwc/no-document-query */ | ||
// Placeholder for childs renderedCallback | ||
protected renderedCallbackForLwcContentLayout?(): void; | ||
renderedCallback(): void { | ||
@@ -173,2 +176,5 @@ /** | ||
this.restoreScroll(); | ||
// Dynamically call `renderedCallbackForLwcContentLayout` if it exists | ||
this.renderedCallbackForLwcContentLayout?.(); | ||
} | ||
@@ -304,2 +310,30 @@ } | ||
protected getHeadingElements() { | ||
// Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll | ||
const headingElements = document.querySelectorAll(TOC_HEADER_TAG); | ||
return headingElements; | ||
} | ||
updateHeadingForRNB(): void { | ||
const headingElements = this.getHeadingElements(); | ||
this.addObserverAndScroll(headingElements); | ||
} | ||
addObserverAndScroll(headingElements: any) { | ||
for (const headingElement of headingElements as any) { | ||
// Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll | ||
const id = headingElement.getAttribute("id")!; | ||
this.anchoredElements[id] = { | ||
id, | ||
intersect: false | ||
}; | ||
this.observer?.observe(headingElement); | ||
} | ||
if (!this.didScrollToSelectedHash) { | ||
this.didScrollToSelectedHash = true; | ||
this.scrollToHash(headingElements); | ||
} | ||
} | ||
attachInteractionObserver = (): void => { | ||
@@ -329,20 +363,3 @@ if (!this.enableSlotChange) { | ||
); | ||
// Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll | ||
const headingElements = document.querySelectorAll(TOC_HEADER_TAG); | ||
for (const headingElement of headingElements as any) { | ||
// Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll | ||
const id = headingElement.getAttribute("id")!; | ||
this.anchoredElements[id] = { | ||
id, | ||
intersect: false | ||
}; | ||
this.observer.observe(headingElement); | ||
} | ||
if (!this.didScrollToSelectedHash) { | ||
this.didScrollToSelectedHash = true; | ||
this.scrollToHash(headingElements); | ||
} | ||
this.updateHeadingForRNB(); | ||
}; | ||
@@ -349,0 +366,0 @@ |
@@ -52,3 +52,3 @@ import ContentLayout from "doc/contentLayout"; | ||
private getHeadingElements() { | ||
protected getHeadingElements() { | ||
let headingElements = document.querySelectorAll(TOC_HEADER_TAG); | ||
@@ -146,32 +146,14 @@ if (this.showTabBasedRNB) { | ||
renderedCallback(): void { | ||
/** | ||
* Note: We are adding timeout because chrome is optimizing and not triggering recent renderedCallback though elements reference is changed | ||
* Also we are considering recent renderedCallback | ||
*/ | ||
this.clearRenderObserverTimer(); | ||
this.observerTimerId = setTimeout( | ||
this.attachInteractionObserver, | ||
OBSERVER_ATTACH_WAIT_TIME | ||
); | ||
this.adjustNavPosition(); | ||
window.addEventListener("scroll", this.adjustNavPosition); | ||
window.addEventListener("resize", this.adjustNavPosition); | ||
if (!this.hasRendered) { | ||
this.hasRendered = true; | ||
this.setRNBByTab(); | ||
if (this.showTabBasedRNB) { | ||
window.addEventListener("tabchanged", this.onTabChanged); | ||
window.addEventListener( | ||
"specificationdatarendered", | ||
this.onTabChanged | ||
); | ||
window.addEventListener("selectedcontent", (event) => | ||
this.onRNBClick(event as CustomEvent) | ||
); | ||
this.restoreTabSelection(); | ||
} | ||
this.restoreScroll(); | ||
renderedCallbackForLwcContentLayout(): void { | ||
this.setRNBByTab(); | ||
if (this.showTabBasedRNB) { | ||
window.addEventListener("tabchanged", this.onTabChanged); | ||
window.addEventListener( | ||
"specificationdatarendered", | ||
this.onTabChanged | ||
); | ||
window.addEventListener("selectedcontent", (event) => | ||
this.onRNBClick(event as CustomEvent) | ||
); | ||
this.restoreTabSelection(); | ||
} | ||
@@ -181,10 +163,3 @@ } | ||
disconnectedCallback(): void { | ||
this.disconnectObserver(); | ||
window.removeEventListener( | ||
"highlightedtermchange", | ||
this.updateHighlighted | ||
); | ||
window.removeEventListener("scroll", this.adjustNavPosition); | ||
window.removeEventListener("resize", this.adjustNavPosition); | ||
super.disconnectedCallback(); | ||
if (this.showTabBasedRNB) { | ||
@@ -201,33 +176,5 @@ window.removeEventListener("tabchanged", this.onTabChanged); | ||
} | ||
this.searchSyncer.dispose(); | ||
this.clearRenderObserverTimer(); | ||
window.clearInterval(this._scrollInterval); | ||
} | ||
attachInteractionObserver = (): void => { | ||
if (!this.enableSlotChange) { | ||
return; | ||
} | ||
this.disconnectObserver(); | ||
const globalNavOffset = `-${getComputedStyle( | ||
document.documentElement | ||
).getPropertyValue("--dx-g-doc-header-main-nav-height")}`; | ||
this.observer = new IntersectionObserver( | ||
(entries) => { | ||
entries.forEach( | ||
(entry) => | ||
(this.anchoredElements[ | ||
entry.target.getAttribute("id")! | ||
].intersect = entry.isIntersecting) | ||
); | ||
this.calculateActualSection(); | ||
}, | ||
{ | ||
rootMargin: globalNavOffset.trim() | ||
} | ||
); | ||
updateHeadingForRNB(): void { | ||
// Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll | ||
@@ -240,19 +187,5 @@ const headingElements = this.getHeadingElements(); | ||
} | ||
this.addObserverAndScroll(headingElements); | ||
} | ||
for (const headingElement of headingElements as any) { | ||
// Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll | ||
const id = headingElement.getAttribute("id")!; | ||
this.anchoredElements[id] = { | ||
id, | ||
intersect: false | ||
}; | ||
this.observer.observe(headingElement); | ||
} | ||
if (!this.didScrollToSelectedHash) { | ||
this.didScrollToSelectedHash = true; | ||
this.scrollToHash(headingElements); | ||
} | ||
}; | ||
onSlotChange(): void { | ||
@@ -259,0 +192,0 @@ this.updateRNB(); |
277184
-0.65%6900
-0.63%