@salesforcedevs/docs-components 1.34.5-fix-non-en-version-1 → 1.34.5-scroll-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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "1.34.5-
|
|
3
|
+
"version": "1.34.5-scroll-2",
|
|
4
4
|
"description": "Docs Lightning web components for DSC",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"@types/lodash.uniqby": "4.7.9"
|
|
27
27
|
},
|
|
28
28
|
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
|
|
29
|
-
"stableVersion": "1.34.
|
|
29
|
+
"stableVersion": "1.34.5"
|
|
30
30
|
}
|
|
@@ -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);
|
|
@@ -496,9 +503,45 @@ export default class ContentLayout extends LightningElement {
|
|
|
496
503
|
}
|
|
497
504
|
|
|
498
505
|
if (!this.didScrollToSelectedHash) {
|
|
506
|
+
this.tryScrollToHash(headingElements);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Scrolls to the hash once available, retrying while code blocks render
|
|
512
|
+
* to avoid unexpected scrolling on observer re-attach.
|
|
513
|
+
*/
|
|
514
|
+
// eslint-disable-next-line no-undef
|
|
515
|
+
protected tryScrollToHash(headingElements: NodeListOf<Element>): void {
|
|
516
|
+
if (!window.location.hash) {
|
|
499
517
|
this.didScrollToSelectedHash = true;
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
this.hashScrollWaitStart ??= Date.now();
|
|
521
|
+
const waitExpired =
|
|
522
|
+
Date.now() - this.hashScrollWaitStart >= MAX_HASH_SCROLL_WAIT_TIME;
|
|
523
|
+
const scrolled =
|
|
524
|
+
(waitExpired || !this.hasPendingCodeBlocks()) &&
|
|
500
525
|
this.scrollToHash(headingElements);
|
|
526
|
+
|
|
527
|
+
if (scrolled || waitExpired) {
|
|
528
|
+
this.didScrollToSelectedHash = true;
|
|
529
|
+
this.hashScrollWaitStart = undefined;
|
|
530
|
+
clearTimeout(this.hashScrollTimerId);
|
|
531
|
+
return;
|
|
501
532
|
}
|
|
533
|
+
|
|
534
|
+
clearTimeout(this.hashScrollTimerId);
|
|
535
|
+
this.hashScrollTimerId = setTimeout(
|
|
536
|
+
() => this.tryScrollToHash(this.getHeadingElements()),
|
|
537
|
+
HASH_SCROLL_DELAY
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
protected hasPendingCodeBlocks(): boolean {
|
|
542
|
+
return Array.from(document.querySelectorAll(CODE_BLOCK_TAG)).some(
|
|
543
|
+
(codeBlock) => !(codeBlock as any).rendered
|
|
544
|
+
);
|
|
502
545
|
}
|
|
503
546
|
|
|
504
547
|
attachInteractionObserver = (): void => {
|
|
@@ -585,6 +628,10 @@ export default class ContentLayout extends LightningElement {
|
|
|
585
628
|
this.updateRNB();
|
|
586
629
|
this.updateContentActionToolbar();
|
|
587
630
|
this.contentLoaded = true;
|
|
631
|
+
|
|
632
|
+
if (!this.didScrollToSelectedHash) {
|
|
633
|
+
this.tryScrollToHash(this.getHeadingElements());
|
|
634
|
+
}
|
|
588
635
|
}
|
|
589
636
|
|
|
590
637
|
protected disconnectObserver(): void {
|
|
@@ -595,7 +642,7 @@ export default class ContentLayout extends LightningElement {
|
|
|
595
642
|
}
|
|
596
643
|
|
|
597
644
|
// eslint-disable-next-line no-undef
|
|
598
|
-
protected scrollToHash(headingElements: NodeListOf<Element>):
|
|
645
|
+
protected scrollToHash(headingElements: NodeListOf<Element>): boolean {
|
|
599
646
|
let { hash } = window.location;
|
|
600
647
|
if (hash) {
|
|
601
648
|
hash = hash.substr(1);
|
|
@@ -610,14 +657,18 @@ export default class ContentLayout extends LightningElement {
|
|
|
610
657
|
"hgf-c360contextnav"
|
|
611
658
|
) as HTMLElement;
|
|
612
659
|
|
|
660
|
+
if (!docHeaderEl || !globalNavEl || !contextNavEl) {
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
|
|
613
664
|
const headerHeight =
|
|
614
|
-
docHeaderEl
|
|
615
|
-
globalNavEl
|
|
616
|
-
contextNavEl
|
|
665
|
+
(docHeaderEl.offsetHeight || 0) +
|
|
666
|
+
(globalNavEl.offsetHeight || 0) +
|
|
667
|
+
(contextNavEl.offsetHeight || 0);
|
|
617
668
|
|
|
618
669
|
const docPhaseEl = (
|
|
619
670
|
this.template.querySelector("[name=doc-phase]")! as any
|
|
620
|
-
)
|
|
671
|
+
)?.assignedElements?.()[0] as HTMLSlotElement | undefined;
|
|
621
672
|
|
|
622
673
|
const offset = docPhaseEl
|
|
623
674
|
? headerHeight + docPhaseEl.offsetHeight
|
|
@@ -626,10 +677,11 @@ export default class ContentLayout extends LightningElement {
|
|
|
626
677
|
for (const headingElement of headingElements as any) {
|
|
627
678
|
if (headingElement.getAttribute("id") === hash) {
|
|
628
679
|
this.scrollIntoViewWithOffset(headingElement, offset);
|
|
629
|
-
|
|
680
|
+
return true;
|
|
630
681
|
}
|
|
631
682
|
}
|
|
632
683
|
}
|
|
684
|
+
return false;
|
|
633
685
|
}
|
|
634
686
|
|
|
635
687
|
protected scrollIntoViewWithOffset(
|
|
@@ -130,16 +130,9 @@ export default class DocXmlContent extends LightningElementWithState<{
|
|
|
130
130
|
private get oldVersionInfo(): DocPhaseInfo | null {
|
|
131
131
|
let info = null;
|
|
132
132
|
if (!this.disableVersion) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
* does include the version id. In that case, the first version in the
|
|
137
|
-
* list is the latest one.
|
|
138
|
-
**/
|
|
139
|
-
const currentGAVersion =
|
|
140
|
-
this.versionOptions.find(
|
|
141
|
-
(version) => !version.url.includes(version.id)
|
|
142
|
-
) ?? this.versionOptions[0];
|
|
133
|
+
const currentGAVersion = this.versionOptions.find(
|
|
134
|
+
(version) => !version.url.includes(version.id)
|
|
135
|
+
);
|
|
143
136
|
if (currentGAVersion?.link?.href && this.version?.id) {
|
|
144
137
|
const versionNo = currentGAVersion.id;
|
|
145
138
|
/**
|
|
@@ -23,6 +23,9 @@ export interface SearchResult {
|
|
|
23
23
|
// and existing fixtures still satisfy the type.
|
|
24
24
|
snippet?: string | null;
|
|
25
25
|
snippetSource?: SnippetSource;
|
|
26
|
+
// `url` plus `#anchor` of the page section that matched, or null/absent
|
|
27
|
+
// when the matched chunk has no anchor. Link to it via resultHref().
|
|
28
|
+
sectionUrl?: string | null;
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
export interface FacetBucket {
|
|
@@ -208,6 +211,19 @@ export function sanitizeSnippetHtml(value: unknown): string {
|
|
|
208
211
|
* text path. So for anything but a headline we return `null` and let the
|
|
209
212
|
* caller keep today's text rendering.
|
|
210
213
|
*/
|
|
214
|
+
/**
|
|
215
|
+
* Where a result's title should link: the matched section when the backend
|
|
216
|
+
* returned one, else the page. The section link is only trusted when it is the
|
|
217
|
+
* page URL plus a fragment, so a malformed value can never send the user
|
|
218
|
+
* somewhere else.
|
|
219
|
+
*/
|
|
220
|
+
export function resultHref(result: SearchResult): string {
|
|
221
|
+
const { url, sectionUrl } = result;
|
|
222
|
+
return typeof sectionUrl === "string" && sectionUrl.startsWith(`${url}#`)
|
|
223
|
+
? sectionUrl
|
|
224
|
+
: url;
|
|
225
|
+
}
|
|
226
|
+
|
|
211
227
|
export function highlightedSnippetHtml(result: SearchResult): string | null {
|
|
212
228
|
if (result.snippetSource !== "headline") {
|
|
213
229
|
return null;
|