@salesforcedevs/docs-components 1.34.4-scroll-2 → 1.34.4-scroll-3
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.
package/package.json
CHANGED
|
@@ -31,6 +31,9 @@ const HIGHLIGHTABLE_SELECTOR = [
|
|
|
31
31
|
"td"
|
|
32
32
|
].join(",");
|
|
33
33
|
export const OBSERVER_ATTACH_WAIT_TIME = 500;
|
|
34
|
+
const HASH_SCROLL_DELAY = 500;
|
|
35
|
+
const MAX_HASH_SCROLL_WAIT_TIME = 10000;
|
|
36
|
+
const CODE_BLOCK_TAG = "dx-code-block";
|
|
34
37
|
|
|
35
38
|
const DEFAULT_READING_TIME_LOCALE = "en-us";
|
|
36
39
|
|
|
@@ -191,6 +194,9 @@ export default class ContentLayout extends LightningElement {
|
|
|
191
194
|
// eslint-disable-next-line no-undef
|
|
192
195
|
protected observerTimerId?: NodeJS.Timeout;
|
|
193
196
|
protected didScrollToSelectedHash = false;
|
|
197
|
+
// eslint-disable-next-line no-undef
|
|
198
|
+
protected hashScrollTimerId?: NodeJS.Timeout;
|
|
199
|
+
protected hashScrollWaitStart?: number;
|
|
194
200
|
protected _scrollInterval = 0;
|
|
195
201
|
protected handleLinkClick = buildDocLinkClickHandler();
|
|
196
202
|
|
|
@@ -335,6 +341,7 @@ export default class ContentLayout extends LightningElement {
|
|
|
335
341
|
this.clearRenderObserverTimer();
|
|
336
342
|
|
|
337
343
|
window.clearInterval(this._scrollInterval);
|
|
344
|
+
clearTimeout(this.hashScrollTimerId);
|
|
338
345
|
|
|
339
346
|
// Remove link click handler
|
|
340
347
|
this.template.removeEventListener("click", this.handleLinkClick);
|
|
@@ -501,16 +508,42 @@ export default class ContentLayout extends LightningElement {
|
|
|
501
508
|
}
|
|
502
509
|
|
|
503
510
|
/**
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
|
|
511
|
+
* Scrolls to the hash once available, retrying while code blocks render
|
|
512
|
+
* to avoid unexpected scrolling on observer re-attach.
|
|
513
|
+
*/
|
|
507
514
|
// eslint-disable-next-line no-undef
|
|
508
515
|
protected tryScrollToHash(headingElements: NodeListOf<Element>): void {
|
|
509
|
-
if (!window.location.hash
|
|
516
|
+
if (!window.location.hash) {
|
|
517
|
+
this.didScrollToSelectedHash = true;
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
if (this.hasPendingCodeBlocks()) {
|
|
521
|
+
this.hashScrollWaitStart ??= Date.now();
|
|
522
|
+
if (
|
|
523
|
+
Date.now() - this.hashScrollWaitStart <
|
|
524
|
+
MAX_HASH_SCROLL_WAIT_TIME
|
|
525
|
+
) {
|
|
526
|
+
clearTimeout(this.hashScrollTimerId);
|
|
527
|
+
this.hashScrollTimerId = setTimeout(
|
|
528
|
+
() => this.tryScrollToHash(this.getHeadingElements()),
|
|
529
|
+
HASH_SCROLL_DELAY
|
|
530
|
+
);
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
if (this.scrollToHash(headingElements)) {
|
|
510
535
|
this.didScrollToSelectedHash = true;
|
|
536
|
+
this.hashScrollWaitStart = undefined;
|
|
537
|
+
clearTimeout(this.hashScrollTimerId);
|
|
511
538
|
}
|
|
512
539
|
}
|
|
513
540
|
|
|
541
|
+
protected hasPendingCodeBlocks(): boolean {
|
|
542
|
+
return Array.from(document.querySelectorAll(CODE_BLOCK_TAG)).some(
|
|
543
|
+
(codeBlock) => !(codeBlock as any).rendered
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
514
547
|
attachInteractionObserver = (): void => {
|
|
515
548
|
if (!this.enableSlotChange) {
|
|
516
549
|
return;
|
|
@@ -596,7 +629,7 @@ export default class ContentLayout extends LightningElement {
|
|
|
596
629
|
this.updateContentActionToolbar();
|
|
597
630
|
this.contentLoaded = true;
|
|
598
631
|
|
|
599
|
-
if (
|
|
632
|
+
if (!this.didScrollToSelectedHash) {
|
|
600
633
|
this.tryScrollToHash(this.getHeadingElements());
|
|
601
634
|
}
|
|
602
635
|
}
|