@salesforcedevs/docs-components 1.3.325-rnbtab-alpha → 1.3.325
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/LICENSE +12 -0
- package/package.json +2 -2
- package/src/modules/doc/contentLayout/contentLayout.ts +40 -149
package/LICENSE
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Copyright (c) 2020, Salesforce.com, Inc.
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
7
|
+
|
|
8
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
9
|
+
|
|
10
|
+
* Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
11
|
+
|
|
12
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "1.3.325
|
|
3
|
+
"version": "1.3.325",
|
|
4
4
|
"description": "Docs Lightning web components for DSC",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"@types/lodash.orderby": "^4.6.7",
|
|
25
25
|
"@types/lodash.uniqby": "^4.7.7"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "142d2d19228378de3cf5a98e3f0586a34626fed3"
|
|
28
28
|
}
|
|
@@ -11,7 +11,6 @@ type AnchorMap = { [key: string]: { intersect: boolean; id: string } };
|
|
|
11
11
|
declare const Sprig: (eventType: string, eventNme: string) => void;
|
|
12
12
|
|
|
13
13
|
const TOC_HEADER_TAG = "doc-heading";
|
|
14
|
-
const RNB_BY_TAB = "docs-tab";
|
|
15
14
|
const HIGHLIGHTABLE_SELECTOR = [
|
|
16
15
|
"p",
|
|
17
16
|
"h1",
|
|
@@ -42,7 +41,6 @@ export default class ContentLayout extends LightningElement {
|
|
|
42
41
|
@api language!: string;
|
|
43
42
|
@api bailHref!: string;
|
|
44
43
|
@api bailLabel!: string;
|
|
45
|
-
@track initialIndex: number = 0;
|
|
46
44
|
|
|
47
45
|
// This is needed for now to prevent failing snapshot tests due to links in the footer
|
|
48
46
|
@api showFooter = false;
|
|
@@ -103,113 +101,6 @@ export default class ContentLayout extends LightningElement {
|
|
|
103
101
|
return this.contentLoaded && typeof Sprig !== "undefined";
|
|
104
102
|
}
|
|
105
103
|
|
|
106
|
-
get showTabBasedRNB() {
|
|
107
|
-
const tabPanelListItem: any = this.selectTabElement();
|
|
108
|
-
return tabPanelListItem?.id === RNB_BY_TAB ? true : false;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
onTabChanged = () => {
|
|
112
|
-
this.updateRNB();
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
private selectTabElement() {
|
|
116
|
-
return document.querySelector("dx-tab-panel-list");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
updateRNB = () => {
|
|
120
|
-
const headingElements = this.getHeadingElements();
|
|
121
|
-
headingElements.forEach((headingElement: any) => {
|
|
122
|
-
headingElement.hash = headingElement.attributes.hash?.nodeValue;
|
|
123
|
-
});
|
|
124
|
-
this.updateTocItems(headingElements);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
private getHeadingElements() {
|
|
128
|
-
let headingElements = document.querySelectorAll(TOC_HEADER_TAG);
|
|
129
|
-
if (this.showTabBasedRNB) {
|
|
130
|
-
const tabPanelListItem: any = this.selectTabElement();
|
|
131
|
-
// for (const tabPanelListItem of tabPanelListItems) {
|
|
132
|
-
if (tabPanelListItem.id === RNB_BY_TAB) {
|
|
133
|
-
const tabPanels =
|
|
134
|
-
tabPanelListItem.querySelectorAll("dx-tab-panel");
|
|
135
|
-
for (const tabPanelItem of tabPanels) {
|
|
136
|
-
if (tabPanelItem.active) {
|
|
137
|
-
headingElements =
|
|
138
|
-
tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return headingElements;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private updateURL() {
|
|
148
|
-
const tabPanelListItem: any = this.selectTabElement();
|
|
149
|
-
if (tabPanelListItem?.id === RNB_BY_TAB) {
|
|
150
|
-
const tabPanelItems: any =
|
|
151
|
-
tabPanelListItem?.shadowRoot.querySelectorAll(
|
|
152
|
-
"dx-tab-panel-item"
|
|
153
|
-
);
|
|
154
|
-
if (tabPanelItems) {
|
|
155
|
-
for (const tabPanelItem of tabPanelItems as any) {
|
|
156
|
-
const tab = tabPanelItem.shadowRoot.querySelector("button");
|
|
157
|
-
const url = new URL(window.location.href);
|
|
158
|
-
const previousTabID = url.searchParams.get("type");
|
|
159
|
-
const tabID = tab?.getAttribute("aria-label");
|
|
160
|
-
if (
|
|
161
|
-
tab?.getAttribute("aria-selected") === "true" &&
|
|
162
|
-
previousTabID !== tabID
|
|
163
|
-
) {
|
|
164
|
-
url.searchParams.set("type", tabID);
|
|
165
|
-
url.hash = "";
|
|
166
|
-
window.history.pushState({}, "", url.toString());
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
private tabOnPageLoad() {
|
|
175
|
-
const url = new URL(window.location.href);
|
|
176
|
-
const previousTabID = url.searchParams.get("type");
|
|
177
|
-
|
|
178
|
-
if (!previousTabID) {
|
|
179
|
-
this.updateURL();
|
|
180
|
-
} else {
|
|
181
|
-
const tabPanelListItem: any = this.selectTabElement();
|
|
182
|
-
const tabPanelItems: any =
|
|
183
|
-
tabPanelListItem?.shadowRoot.querySelectorAll(
|
|
184
|
-
"dx-tab-panel-item"
|
|
185
|
-
);
|
|
186
|
-
const tabPanels = tabPanelListItem.querySelectorAll("dx-tab-panel");
|
|
187
|
-
if (tabPanelItems) {
|
|
188
|
-
let tabIndex = 0;
|
|
189
|
-
for (const tabPanelItem of tabPanelItems as any) {
|
|
190
|
-
const tab = tabPanelItem.shadowRoot.querySelector("button");
|
|
191
|
-
const activeTab =
|
|
192
|
-
tabPanels[tabIndex]?.shadowRoot.querySelector(
|
|
193
|
-
".tabpanel"
|
|
194
|
-
);
|
|
195
|
-
if (tab?.getAttribute("aria-label") === previousTabID) {
|
|
196
|
-
if (activeTab) {
|
|
197
|
-
activeTab.classList.add("tabpanel-active");
|
|
198
|
-
}
|
|
199
|
-
tab.active = true;
|
|
200
|
-
this.initialIndex = tabIndex;
|
|
201
|
-
} else {
|
|
202
|
-
if (activeTab) {
|
|
203
|
-
activeTab.classList.remove("tabpanel-active");
|
|
204
|
-
}
|
|
205
|
-
tab.active = false;
|
|
206
|
-
}
|
|
207
|
-
tabIndex++;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
104
|
private searchSyncer = new SearchSyncer({
|
|
214
105
|
callbacks: {
|
|
215
106
|
onSearchChange: (nextSearchString: string): void => {
|
|
@@ -257,11 +148,6 @@ export default class ContentLayout extends LightningElement {
|
|
|
257
148
|
);
|
|
258
149
|
this.searchSyncer.init();
|
|
259
150
|
}
|
|
260
|
-
|
|
261
|
-
if (this.showTabBasedRNB) {
|
|
262
|
-
window.addEventListener("tabchanged", this.onTabChanged);
|
|
263
|
-
this.tabOnPageLoad();
|
|
264
|
-
}
|
|
265
151
|
}
|
|
266
152
|
|
|
267
153
|
renderedCallback(): void {
|
|
@@ -438,8 +324,7 @@ export default class ContentLayout extends LightningElement {
|
|
|
438
324
|
);
|
|
439
325
|
|
|
440
326
|
// Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
|
|
441
|
-
const headingElements =
|
|
442
|
-
this.updateURL();
|
|
327
|
+
const headingElements = document.querySelectorAll(TOC_HEADER_TAG);
|
|
443
328
|
for (const headingElement of headingElements as any) {
|
|
444
329
|
// Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
|
|
445
330
|
const id = headingElement.getAttribute("id")!;
|
|
@@ -455,43 +340,49 @@ export default class ContentLayout extends LightningElement {
|
|
|
455
340
|
}
|
|
456
341
|
};
|
|
457
342
|
|
|
458
|
-
onSlotChange(
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
343
|
+
onSlotChange(event: Event): void {
|
|
344
|
+
const slotElements = (
|
|
345
|
+
event.target as HTMLSlotElement
|
|
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
|
+
);
|
|
470
355
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
356
|
+
for (const headingElement of headingElements as any) {
|
|
357
|
+
// Sometimes elements hash and header is not being set when slot content is wrapped with div
|
|
358
|
+
headingElement.hash = headingElement.attributes.hash?.nodeValue;
|
|
359
|
+
headingElement.header =
|
|
360
|
+
headingElement.attributes.header?.nodeValue;
|
|
361
|
+
}
|
|
474
362
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
363
|
+
const tocOptions = [];
|
|
364
|
+
|
|
365
|
+
for (const headingElement of headingElements as any) {
|
|
366
|
+
headingElement.id = headingElement.hash;
|
|
367
|
+
|
|
368
|
+
// Update tocOptions from anchorTags only for H2, consider default as 2 as per component
|
|
369
|
+
const headingAriaLevel =
|
|
370
|
+
headingElement.attributes["aria-level"]?.nodeValue || "2";
|
|
371
|
+
const isH2 = headingAriaLevel === "2";
|
|
372
|
+
|
|
373
|
+
if (isH2) {
|
|
374
|
+
const tocItem = {
|
|
375
|
+
anchor: `#${headingElement.hash}`,
|
|
376
|
+
id: headingElement.id,
|
|
377
|
+
label: headingElement.header
|
|
378
|
+
};
|
|
379
|
+
tocOptions.push(tocItem);
|
|
380
|
+
this.tocOptionIdsSet.add(headingElement.id);
|
|
381
|
+
}
|
|
491
382
|
}
|
|
492
|
-
}
|
|
493
383
|
|
|
494
|
-
|
|
384
|
+
this._tocOptions = tocOptions;
|
|
385
|
+
}
|
|
495
386
|
}
|
|
496
387
|
|
|
497
388
|
private disconnectObserver(): void {
|