@salesforcedevs/docs-components 1.3.345-refactor-tab-alpha3 → 1.3.345-refactor-tab-alpha5

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.3.345-refactor-tab-alpha3",
3
+ "version": "1.3.345-refactor-tab-alpha5",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -152,7 +152,7 @@ export default class ContentLayout extends LightningElement {
152
152
  }
153
153
 
154
154
  // Placeholder for childs renderedCallback
155
- protected renderedCallbackForLwcContentLayout?(): void;
155
+ protected postRenderedCallback?(): void;
156
156
 
157
157
  renderedCallback(): void {
158
158
  /**
@@ -174,7 +174,7 @@ export default class ContentLayout extends LightningElement {
174
174
  this.restoreScroll();
175
175
 
176
176
  // Dynamically call `renderedCallbackForLwcContentLayout` if it exists
177
- this.renderedCallbackForLwcContentLayout?.();
177
+ this.postRenderedCallback?.();
178
178
  }
179
179
  }
180
180
 
@@ -360,6 +360,48 @@ export default class ContentLayout extends LightningElement {
360
360
  this.updateHeadingForRNB();
361
361
  };
362
362
 
363
+ // eslint-disable-next-line no-undef
364
+ updateTocItems(headingElements: any): void {
365
+ const tocOptions = [];
366
+
367
+ for (const headingElement of headingElements as any) {
368
+ headingElement.id = headingElement.hash;
369
+
370
+ // Update tocOptions from anchorTags only for H2, consider default as 2 as per component
371
+ const headingAriaLevel =
372
+ headingElement.attributes["aria-level"]?.nodeValue || "2";
373
+ const isH2 = headingAriaLevel === "2";
374
+
375
+ if (isH2) {
376
+ const tocItem = {
377
+ anchor: `#${headingElement.hash}`,
378
+ id: headingElement.id,
379
+ label: headingElement.header
380
+ };
381
+ tocOptions.push(tocItem);
382
+ this.tocOptionIdsSet.add(headingElement.id);
383
+ }
384
+ }
385
+
386
+ this._tocOptions = tocOptions;
387
+ }
388
+
389
+ setHashAndHeaderForDocHeading(headingElements: any) {
390
+ for (const headingElement of headingElements as any) {
391
+ // Sometimes elements hash and header is not being set when slot content is wrapped with div
392
+ if (!headingElement.hash) {
393
+ headingElement.hash = headingElement.attributes.hash?.nodeValue;
394
+ }
395
+
396
+ if (!headingElement.header) {
397
+ headingElement.header =
398
+ headingElement.attributes.header?.nodeValue;
399
+ }
400
+ }
401
+
402
+ this.updateTocItems(headingElements);
403
+ }
404
+
363
405
  onSlotChange(event: Event): void {
364
406
  const slotElements = (
365
407
  event.target as HTMLSlotElement
@@ -373,34 +415,7 @@ export default class ContentLayout extends LightningElement {
373
415
  TOC_HEADER_TAG
374
416
  );
375
417
 
376
- for (const headingElement of headingElements as any) {
377
- // Sometimes elements hash and header is not being set when slot content is wrapped with div
378
- headingElement.hash = headingElement.attributes.hash?.nodeValue;
379
- headingElement.header =
380
- headingElement.attributes.header?.nodeValue;
381
- }
382
-
383
- const tocOptions = [];
384
- for (const headingElement of headingElements as any) {
385
- headingElement.id = headingElement.hash;
386
-
387
- // Update tocOptions from anchorTags only for H2, consider default as 2 as per component
388
- const headingAriaLevel =
389
- headingElement.attributes["aria-level"]?.nodeValue || "2";
390
- const isH2 = headingAriaLevel === "2";
391
-
392
- if (isH2) {
393
- const tocItem = {
394
- anchor: `#${headingElement.hash}`,
395
- id: headingElement.id,
396
- label: headingElement.header
397
- };
398
- tocOptions.push(tocItem);
399
- this.tocOptionIdsSet.add(headingElement.id);
400
- }
401
- }
402
-
403
- this._tocOptions = tocOptions;
418
+ this.setHashAndHeaderForDocHeading(headingElements);
404
419
  }
405
420
  }
406
421
 
@@ -35,22 +35,11 @@ export default class LwcContentLayout extends ContentLayout {
35
35
 
36
36
  updateRNB = () => {
37
37
  const headingElements = this.getHeadingElements();
38
- headingElements.forEach((headingElement: any) => {
39
- // Sometimes elements hash and header is not being set when slot content is wrapped with div
40
- if (!headingElement.hash) {
41
- headingElement.hash = headingElement.attributes.hash?.nodeValue;
42
- }
43
-
44
- if (!headingElement.header) {
45
- headingElement.header =
46
- headingElement.attributes.header?.nodeValue;
47
- }
48
- });
49
- this.updateTocItems(headingElements);
38
+ this.setHashAndHeaderForDocHeading(headingElements);
50
39
  };
51
40
 
52
41
  protected getHeadingElements() {
53
- let headingElements = document.querySelectorAll(TOC_HEADER_TAG);
42
+ let headingElements = super.getHeadingElements();
54
43
  if (this.showTabBasedRNB) {
55
44
  const tabPanelListItem: any = this.getTabPanelList();
56
45
  const tabPanels =
@@ -142,7 +131,7 @@ export default class LwcContentLayout extends ContentLayout {
142
131
  });
143
132
  }
144
133
 
145
- renderedCallbackForLwcContentLayout(): void {
134
+ postRenderedCallback(): void {
146
135
  this.setRNBByTab();
147
136
  if (this.showTabBasedRNB) {
148
137
  window.addEventListener("tabchanged", this.onTabChanged);
@@ -173,44 +162,15 @@ export default class LwcContentLayout extends ContentLayout {
173
162
  }
174
163
 
175
164
  updateHeadingForRNB(): void {
176
- // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
177
- const headingElements = this.getHeadingElements();
178
-
179
165
  // We only need to update URL in case of /docs and ignore if tabs are used anywhere else in DSC
180
166
  if (this.showTabBasedRNB) {
181
167
  this.updateURL();
182
168
  }
183
- this.addObserverAndScroll(headingElements);
169
+ super.updateHeadingForRNB();
184
170
  }
185
171
 
186
172
  onSlotChange(): void {
187
173
  this.updateRNB();
188
174
  this.contentLoaded = true;
189
175
  }
190
-
191
- // eslint-disable-next-line no-undef
192
- private updateTocItems(headingElements: NodeListOf<Element>): void {
193
- const tocOptions = [];
194
-
195
- for (const headingElement of headingElements as any) {
196
- headingElement.id = headingElement.hash;
197
-
198
- // Update tocOptions from anchorTags only for H2, consider default as 2 as per component
199
- const headingAriaLevel =
200
- headingElement.attributes["aria-level"]?.nodeValue || "2";
201
- const isH2 = headingAriaLevel === "2";
202
-
203
- if (isH2) {
204
- const tocItem = {
205
- anchor: `#${headingElement.hash}`,
206
- id: headingElement.id,
207
- label: headingElement.header
208
- };
209
- tocOptions.push(tocItem);
210
- this.tocOptionIdsSet.add(headingElement.id);
211
- }
212
- }
213
-
214
- this._tocOptions = tocOptions;
215
- }
216
176
  }