@salesforcedevs/docs-components 1.3.319-scroll-alpha → 1.3.319-tabrnb-alpha
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
|
@@ -385,7 +385,6 @@ mark {
|
|
|
385
385
|
/* offset page jump link due to fixed header */
|
|
386
386
|
[id] {
|
|
387
387
|
scroll-margin-top: calc(
|
|
388
|
-
var(--dx-g-global-header-height) + var(--dx-g-doc-header-height)
|
|
389
|
-
var(--dx-g-spacing-2xl)
|
|
388
|
+
var(--dx-g-global-header-height) + var(--dx-g-doc-header-height)
|
|
390
389
|
);
|
|
391
390
|
}
|
|
@@ -43,8 +43,7 @@ dx-toc {
|
|
|
43
43
|
/* offset page jump link due to fixed header */
|
|
44
44
|
::slotted(doc-heading) {
|
|
45
45
|
scroll-margin-top: calc(
|
|
46
|
-
var(--dx-g-global-header-height) + var(--dx-g-doc-header-height)
|
|
47
|
-
var(--dx-g-spacing-2xl)
|
|
46
|
+
var(--dx-g-global-header-height) + var(--dx-g-doc-header-height)
|
|
48
47
|
);
|
|
49
48
|
}
|
|
50
49
|
|
|
@@ -41,6 +41,8 @@ export default class ContentLayout extends LightningElement {
|
|
|
41
41
|
@api language!: string;
|
|
42
42
|
@api bailHref!: string;
|
|
43
43
|
@api bailLabel!: string;
|
|
44
|
+
@api rnbByTabId?: string = "docs-tab";
|
|
45
|
+
@api initialIndex: number = 0;
|
|
44
46
|
|
|
45
47
|
// This is needed for now to prevent failing snapshot tests due to links in the footer
|
|
46
48
|
@api showFooter = false;
|
|
@@ -101,6 +103,10 @@ export default class ContentLayout extends LightningElement {
|
|
|
101
103
|
return this.contentLoaded && typeof Sprig !== "undefined";
|
|
102
104
|
}
|
|
103
105
|
|
|
106
|
+
get showTabBasedRNB() {
|
|
107
|
+
return this.rnbByTabId ? true : false;
|
|
108
|
+
}
|
|
109
|
+
|
|
104
110
|
private searchSyncer = new SearchSyncer({
|
|
105
111
|
callbacks: {
|
|
106
112
|
onSearchChange: (nextSearchString: string): void => {
|
|
@@ -136,6 +142,72 @@ export default class ContentLayout extends LightningElement {
|
|
|
136
142
|
);
|
|
137
143
|
}
|
|
138
144
|
|
|
145
|
+
onTabChanged = () => {
|
|
146
|
+
this.updateRNB();
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
private selectTabElement() {
|
|
150
|
+
return document.querySelector("dx-tab-panel-list");
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
updateRNB = () => {
|
|
154
|
+
const headingElements = this.getHeadingElements();
|
|
155
|
+
headingElements.forEach((headingElement: any) => {
|
|
156
|
+
headingElement.hash = headingElement.attributes.hash?.nodeValue;
|
|
157
|
+
});
|
|
158
|
+
this.updateTocItems(headingElements);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
private getHeadingElements() {
|
|
162
|
+
let headingElements = document.querySelectorAll(TOC_HEADER_TAG);
|
|
163
|
+
if (this.showTabBasedRNB) {
|
|
164
|
+
const tabPanelListItem: any = this.selectTabElement();
|
|
165
|
+
// for (const tabPanelListItem of tabPanelListItems) {
|
|
166
|
+
if (tabPanelListItem.id === this.rnbByTabId) {
|
|
167
|
+
const tabPanels =
|
|
168
|
+
tabPanelListItem.querySelectorAll("dx-tab-panel");
|
|
169
|
+
for (const tabPanelItem of tabPanels) {
|
|
170
|
+
if (tabPanelItem.active) {
|
|
171
|
+
headingElements =
|
|
172
|
+
tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// const tabPanelItems: any = tabPanelListItem.shadowRoot.querySelectorAll("dx-tab-panel-item");
|
|
178
|
+
// this.updateURL(tabPanelItems);
|
|
179
|
+
}
|
|
180
|
+
// }
|
|
181
|
+
}
|
|
182
|
+
return headingElements;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private updateURL() {
|
|
186
|
+
const tabPanelListItem: any = this.selectTabElement();
|
|
187
|
+
if (tabPanelListItem.id === this.rnbByTabId) {
|
|
188
|
+
const tabPanelItems: any =
|
|
189
|
+
tabPanelListItem?.shadowRoot.querySelectorAll(
|
|
190
|
+
"dx-tab-panel-item"
|
|
191
|
+
);
|
|
192
|
+
if (tabPanelItems) {
|
|
193
|
+
for (const tabPanelItem of tabPanelItems as any) {
|
|
194
|
+
const tab = tabPanelItem.shadowRoot.querySelector("button");
|
|
195
|
+
const url = new URL(window.location.href);
|
|
196
|
+
const previousTabID = url.searchParams.get("type");
|
|
197
|
+
const tabID = tab?.getAttribute("aria-label");
|
|
198
|
+
if (
|
|
199
|
+
tab?.getAttribute("aria-selected") === "true" &&
|
|
200
|
+
previousTabID !== tabID
|
|
201
|
+
) {
|
|
202
|
+
url.searchParams.set("type", tabID);
|
|
203
|
+
url.hash = "";
|
|
204
|
+
window.history.pushState({}, "", url.toString());
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
139
211
|
connectedCallback(): void {
|
|
140
212
|
const hasParentHighlightListener = closest(
|
|
141
213
|
"doc-xml-content",
|
|
@@ -148,6 +220,9 @@ export default class ContentLayout extends LightningElement {
|
|
|
148
220
|
);
|
|
149
221
|
this.searchSyncer.init();
|
|
150
222
|
}
|
|
223
|
+
if (this.showTabBasedRNB) {
|
|
224
|
+
window.addEventListener("tabchanged", this.onTabChanged);
|
|
225
|
+
}
|
|
151
226
|
}
|
|
152
227
|
|
|
153
228
|
renderedCallback(): void {
|
|
@@ -215,16 +290,10 @@ export default class ContentLayout extends LightningElement {
|
|
|
215
290
|
".sticky-doc-header"
|
|
216
291
|
) as HTMLElement;
|
|
217
292
|
|
|
218
|
-
|
|
293
|
+
const docPhaseEl = (
|
|
219
294
|
this.template.querySelector("[name=doc-phase]")! as any
|
|
220
295
|
).assignedElements()[0] as HTMLSlotElement;
|
|
221
296
|
|
|
222
|
-
if (!docPhaseEl) {
|
|
223
|
-
docPhaseEl = (
|
|
224
|
-
this.template.querySelector("[name=version-banner]")! as any
|
|
225
|
-
).assignedElements()[0] as HTMLSlotElement;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
297
|
if (!sidebarEl || !globalNavEl || !contextNavEl || !docHeaderEl) {
|
|
229
298
|
console.warn("One or more required elements are missing.");
|
|
230
299
|
return;
|
|
@@ -237,14 +306,6 @@ export default class ContentLayout extends LightningElement {
|
|
|
237
306
|
(globalNavEl.getBoundingClientRect().height !== 72 ? 0 : 72) +
|
|
238
307
|
contextNavEl.getBoundingClientRect().height;
|
|
239
308
|
const docHeaderHeight = docHeaderEl.getBoundingClientRect().height;
|
|
240
|
-
const totalHeaderHeight = globalNavHeight + docHeaderHeight;
|
|
241
|
-
|
|
242
|
-
// Selecting the doc section heading and RNB here.
|
|
243
|
-
const docHeadingEls = Array.from(
|
|
244
|
-
document.querySelectorAll("doc-heading")
|
|
245
|
-
);
|
|
246
|
-
const rightNavBarEl = this.template.querySelector(".right-nav-bar");
|
|
247
|
-
|
|
248
309
|
sidebarEl.style.setProperty(
|
|
249
310
|
"--dx-c-content-sidebar-sticky-top",
|
|
250
311
|
`${globalNavHeight + docHeaderHeight}px`
|
|
@@ -255,27 +316,6 @@ export default class ContentLayout extends LightningElement {
|
|
|
255
316
|
`${globalNavHeight}px`
|
|
256
317
|
);
|
|
257
318
|
|
|
258
|
-
// Adjusting the doc section heading on scroll.
|
|
259
|
-
docHeadingEls.forEach((docHeadingEl) => {
|
|
260
|
-
(docHeadingEl as any).style.scrollMarginTop = docPhaseEl
|
|
261
|
-
? `${
|
|
262
|
-
totalHeaderHeight +
|
|
263
|
-
docPhaseEl.getBoundingClientRect().height +
|
|
264
|
-
40
|
|
265
|
-
}px`
|
|
266
|
-
: `${totalHeaderHeight + 40}px`;
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
// Adjusting the right nav bar on scroll.
|
|
270
|
-
if (rightNavBarEl) {
|
|
271
|
-
rightNavBarEl.style.top = docPhaseEl
|
|
272
|
-
? `${
|
|
273
|
-
totalHeaderHeight +
|
|
274
|
-
docPhaseEl.getBoundingClientRect().height
|
|
275
|
-
}px`
|
|
276
|
-
: `${totalHeaderHeight}px`;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
319
|
// If doc phase element exists, we need to account for its sticky position. Mobile should include the sidebar height (since it becomes sticky aswell).
|
|
280
320
|
if (docPhaseEl) {
|
|
281
321
|
docPhaseEl.style.setProperty(
|
|
@@ -288,6 +328,28 @@ export default class ContentLayout extends LightningElement {
|
|
|
288
328
|
: globalNavHeight + docHeaderHeight
|
|
289
329
|
}px`
|
|
290
330
|
);
|
|
331
|
+
|
|
332
|
+
// Adjust scroll margin for doc headings when doc phase is present
|
|
333
|
+
const docHeadingEls = this.getHeadingElements();
|
|
334
|
+
docHeadingEls.forEach((docHeadingEl) => {
|
|
335
|
+
(docHeadingEl as any).style.scrollMarginTop = `${
|
|
336
|
+
globalNavHeight +
|
|
337
|
+
docHeaderHeight +
|
|
338
|
+
docPhaseEl.getBoundingClientRect().height
|
|
339
|
+
}px`;
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
// Adjust right nav bar position when doc phase is present
|
|
343
|
+
const rightNavBarEl =
|
|
344
|
+
this.template.querySelector(".right-nav-bar");
|
|
345
|
+
|
|
346
|
+
if (rightNavBarEl) {
|
|
347
|
+
rightNavBarEl.style.top = `${
|
|
348
|
+
globalNavHeight +
|
|
349
|
+
docHeaderHeight +
|
|
350
|
+
docPhaseEl.getBoundingClientRect().height
|
|
351
|
+
}px`;
|
|
352
|
+
}
|
|
291
353
|
}
|
|
292
354
|
});
|
|
293
355
|
};
|
|
@@ -324,7 +386,8 @@ export default class ContentLayout extends LightningElement {
|
|
|
324
386
|
);
|
|
325
387
|
|
|
326
388
|
// Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
|
|
327
|
-
const headingElements =
|
|
389
|
+
const headingElements = this.getHeadingElements();
|
|
390
|
+
this.updateURL();
|
|
328
391
|
for (const headingElement of headingElements as any) {
|
|
329
392
|
// Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
|
|
330
393
|
const id = headingElement.getAttribute("id")!;
|
|
@@ -340,47 +403,43 @@ export default class ContentLayout extends LightningElement {
|
|
|
340
403
|
}
|
|
341
404
|
};
|
|
342
405
|
|
|
343
|
-
onSlotChange(
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
).assignedElements();
|
|
347
|
-
|
|
348
|
-
if (slotElements.length) {
|
|
349
|
-
this.contentLoaded = true;
|
|
350
|
-
const slotContentElement = slotElements[0];
|
|
351
|
-
const headingElements =
|
|
352
|
-
slotContentElement.ownerDocument?.getElementsByTagName(
|
|
353
|
-
TOC_HEADER_TAG
|
|
354
|
-
);
|
|
406
|
+
onSlotChange(e): void {
|
|
407
|
+
const slot = e.target;
|
|
408
|
+
const child = slot.assignedElements(); // Get the first slotted child component
|
|
355
409
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
410
|
+
const tabComponent = child.find(
|
|
411
|
+
(element) => element.tagName.toLowerCase() === "dx-tab-panel-list"
|
|
412
|
+
);
|
|
413
|
+
if (tabComponent) {
|
|
414
|
+
tabComponent.initialIndex = this.initialIndex; // Set the index value on the child component
|
|
415
|
+
}
|
|
416
|
+
this.updateRNB();
|
|
417
|
+
}
|
|
360
418
|
|
|
361
|
-
|
|
419
|
+
// eslint-disable-next-line no-undef
|
|
420
|
+
private updateTocItems(headingElements: NodeListOf<Element>): void {
|
|
421
|
+
const tocOptions = [];
|
|
362
422
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
423
|
+
for (const headingElement of headingElements as any) {
|
|
424
|
+
headingElement.id = headingElement.hash;
|
|
425
|
+
|
|
426
|
+
// Update tocOptions from anchorTags only for H2, consider default as 2 as per component
|
|
427
|
+
const headingAriaLevel =
|
|
428
|
+
headingElement.attributes["aria-level"]?.nodeValue || "2";
|
|
429
|
+
const isH2 = headingAriaLevel === "2";
|
|
430
|
+
|
|
431
|
+
if (isH2) {
|
|
432
|
+
const tocItem = {
|
|
433
|
+
anchor: `#${headingElement.hash}`,
|
|
434
|
+
id: headingElement.id,
|
|
435
|
+
label: headingElement.title
|
|
436
|
+
};
|
|
437
|
+
tocOptions.push(tocItem);
|
|
438
|
+
this.tocOptionIdsSet.add(headingElement.id);
|
|
380
439
|
}
|
|
381
|
-
|
|
382
|
-
this._tocOptions = tocOptions;
|
|
383
440
|
}
|
|
441
|
+
|
|
442
|
+
this._tocOptions = tocOptions;
|
|
384
443
|
}
|
|
385
444
|
|
|
386
445
|
private disconnectObserver(): void {
|