@salesforcedevs/docs-components 1.34.4-scroll-1 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.34.4-scroll-1",
3
+ "version": "1.34.4-scroll-3",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -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
- * Attempts the one-shot hash scroll and marks it complete only if scrolling succeeds,
505
- * keeping both trigger points consistent.
511
+ * Scrolls to the hash once available, retrying while code blocks render
512
+ * to avoid unexpected scrolling on observer re-attach.
506
513
  */
507
514
  // eslint-disable-next-line no-undef
508
515
  protected tryScrollToHash(headingElements: NodeListOf<Element>): void {
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
+ }
509
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 (this.enableSlotChange && !this.didScrollToSelectedHash) {
632
+ if (!this.didScrollToSelectedHash) {
600
633
  this.tryScrollToHash(this.getHeadingElements());
601
634
  }
602
635
  }