@salesforcedevs/docs-components 1.3.345-refactor-tab-alpha2 → 1.3.345-refactor-tab-alpha4

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-alpha2",
3
+ "version": "1.3.345-refactor-tab-alpha4",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -151,6 +151,9 @@ export default class ContentLayout extends LightningElement {
151
151
  }
152
152
  }
153
153
 
154
+ // Placeholder for childs renderedCallback
155
+ protected postRenderedCallback?(): void;
156
+
154
157
  renderedCallback(): void {
155
158
  /**
156
159
  * Note: We are adding timeout because chrome is optimizing and not triggering recent renderedCallback though elements reference is changed
@@ -169,6 +172,9 @@ export default class ContentLayout extends LightningElement {
169
172
  if (!this.hasRendered) {
170
173
  this.hasRendered = true;
171
174
  this.restoreScroll();
175
+
176
+ // Dynamically call `renderedCallbackForLwcContentLayout` if it exists
177
+ this.postRenderedCallback?.();
172
178
  }
173
179
  }
174
180
 
@@ -299,6 +305,34 @@ export default class ContentLayout extends LightningElement {
299
305
  (event as CustomEvent<string>).detail
300
306
  );
301
307
 
308
+ protected getHeadingElements() {
309
+ // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
310
+ const headingElements = document.querySelectorAll(TOC_HEADER_TAG);
311
+ return headingElements;
312
+ }
313
+
314
+ updateHeadingForRNB(): void {
315
+ const headingElements = this.getHeadingElements();
316
+ this.addObserverAndScroll(headingElements);
317
+ }
318
+
319
+ addObserverAndScroll(headingElements: any) {
320
+ for (const headingElement of headingElements as any) {
321
+ // Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
322
+ const id = headingElement.getAttribute("id")!;
323
+ this.anchoredElements[id] = {
324
+ id,
325
+ intersect: false
326
+ };
327
+ this.observer?.observe(headingElement);
328
+ }
329
+
330
+ if (!this.didScrollToSelectedHash) {
331
+ this.didScrollToSelectedHash = true;
332
+ this.scrollToHash(headingElements);
333
+ }
334
+ }
335
+
302
336
  attachInteractionObserver = (): void => {
303
337
  if (!this.enableSlotChange) {
304
338
  return;
@@ -323,25 +357,34 @@ export default class ContentLayout extends LightningElement {
323
357
  rootMargin: globalNavOffset.trim()
324
358
  }
325
359
  );
360
+ this.updateHeadingForRNB();
361
+ };
326
362
 
327
- // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
328
- const headingElements = document.querySelectorAll(TOC_HEADER_TAG);
363
+ // eslint-disable-next-line no-undef
364
+ updateTocItems(headingElements: any): void {
365
+ const tocOptions = [];
329
366
 
330
367
  for (const headingElement of headingElements as any) {
331
- // Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
332
- const id = headingElement.getAttribute("id")!;
333
- this.anchoredElements[id] = {
334
- id,
335
- intersect: false
336
- };
337
- this.observer.observe(headingElement);
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
+ }
338
384
  }
339
385
 
340
- if (!this.didScrollToSelectedHash) {
341
- this.didScrollToSelectedHash = true;
342
- this.scrollToHash(headingElements);
343
- }
344
- };
386
+ this._tocOptions = tocOptions;
387
+ }
345
388
 
346
389
  onSlotChange(event: Event): void {
347
390
  const slotElements = (
@@ -363,27 +406,7 @@ export default class ContentLayout extends LightningElement {
363
406
  headingElement.attributes.header?.nodeValue;
364
407
  }
365
408
 
366
- const tocOptions = [];
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;
409
+ this.updateTocItems(headingElements);
387
410
  }
388
411
  }
389
412
 
@@ -49,7 +49,7 @@ export default class LwcContentLayout extends ContentLayout {
49
49
  this.updateTocItems(headingElements);
50
50
  };
51
51
 
52
- private getHeadingElements() {
52
+ protected getHeadingElements() {
53
53
  let headingElements = document.querySelectorAll(TOC_HEADER_TAG);
54
54
  if (this.showTabBasedRNB) {
55
55
  const tabPanelListItem: any = this.getTabPanelList();
@@ -142,48 +142,23 @@ export default class LwcContentLayout extends ContentLayout {
142
142
  });
143
143
  }
144
144
 
145
- renderedCallback(): void {
146
- /**
147
- * Note: We are adding timeout because chrome is optimizing and not triggering recent renderedCallback though elements reference is changed
148
- * Also we are considering recent renderedCallback
149
- */
150
- this.clearRenderObserverTimer();
151
- this.observerTimerId = setTimeout(
152
- this.attachInteractionObserver,
153
- OBSERVER_ATTACH_WAIT_TIME
154
- );
155
-
156
- this.adjustNavPosition();
157
- window.addEventListener("scroll", this.adjustNavPosition);
158
- window.addEventListener("resize", this.adjustNavPosition);
159
-
160
- if (!this.hasRendered) {
161
- this.hasRendered = true;
162
- this.setRNBByTab();
163
- if (this.showTabBasedRNB) {
164
- window.addEventListener("tabchanged", this.onTabChanged);
165
- window.addEventListener(
166
- "specificationdatarendered",
167
- this.onTabChanged
168
- );
169
- window.addEventListener("selectedcontent", (event) =>
170
- this.onRNBClick(event as CustomEvent)
171
- );
172
- this.restoreTabSelection();
173
- }
174
- this.restoreScroll();
145
+ postRenderedCallback(): void {
146
+ this.setRNBByTab();
147
+ if (this.showTabBasedRNB) {
148
+ window.addEventListener("tabchanged", this.onTabChanged);
149
+ window.addEventListener(
150
+ "specificationdatarendered",
151
+ this.onTabChanged
152
+ );
153
+ window.addEventListener("selectedcontent", (event) =>
154
+ this.onRNBClick(event as CustomEvent)
155
+ );
156
+ this.restoreTabSelection();
175
157
  }
176
158
  }
177
159
 
178
160
  disconnectedCallback(): void {
179
- this.disconnectObserver();
180
- window.removeEventListener(
181
- "highlightedtermchange",
182
- this.updateHighlighted
183
- );
184
- window.removeEventListener("scroll", this.adjustNavPosition);
185
- window.removeEventListener("resize", this.adjustNavPosition);
186
-
161
+ super.disconnectedCallback();
187
162
  if (this.showTabBasedRNB) {
188
163
  window.removeEventListener("tabchanged", this.onTabChanged);
189
164
  window.removeEventListener(
@@ -195,37 +170,9 @@ export default class LwcContentLayout extends ContentLayout {
195
170
  );
196
171
  window.removeEventListener("popstate", this.handlePopState);
197
172
  }
198
- this.searchSyncer.dispose();
199
- this.clearRenderObserverTimer();
200
-
201
- window.clearInterval(this._scrollInterval);
202
173
  }
203
174
 
204
- attachInteractionObserver = (): void => {
205
- if (!this.enableSlotChange) {
206
- return;
207
- }
208
- this.disconnectObserver();
209
-
210
- const globalNavOffset = `-${getComputedStyle(
211
- document.documentElement
212
- ).getPropertyValue("--dx-g-doc-header-main-nav-height")}`;
213
-
214
- this.observer = new IntersectionObserver(
215
- (entries) => {
216
- entries.forEach(
217
- (entry) =>
218
- (this.anchoredElements[
219
- entry.target.getAttribute("id")!
220
- ].intersect = entry.isIntersecting)
221
- );
222
- this.calculateActualSection();
223
- },
224
- {
225
- rootMargin: globalNavOffset.trim()
226
- }
227
- );
228
-
175
+ updateHeadingForRNB(): void {
229
176
  // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
230
177
  const headingElements = this.getHeadingElements();
231
178
 
@@ -233,51 +180,11 @@ export default class LwcContentLayout extends ContentLayout {
233
180
  if (this.showTabBasedRNB) {
234
181
  this.updateURL();
235
182
  }
236
-
237
- for (const headingElement of headingElements as any) {
238
- // Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
239
- const id = headingElement.getAttribute("id")!;
240
- this.anchoredElements[id] = {
241
- id,
242
- intersect: false
243
- };
244
- this.observer.observe(headingElement);
245
- }
246
-
247
- if (!this.didScrollToSelectedHash) {
248
- this.didScrollToSelectedHash = true;
249
- this.scrollToHash(headingElements);
250
- }
251
- };
183
+ this.addObserverAndScroll(headingElements);
184
+ }
252
185
 
253
186
  onSlotChange(): void {
254
187
  this.updateRNB();
255
188
  this.contentLoaded = true;
256
189
  }
257
-
258
- // eslint-disable-next-line no-undef
259
- private updateTocItems(headingElements: NodeListOf<Element>): void {
260
- const tocOptions = [];
261
-
262
- for (const headingElement of headingElements as any) {
263
- headingElement.id = headingElement.hash;
264
-
265
- // Update tocOptions from anchorTags only for H2, consider default as 2 as per component
266
- const headingAriaLevel =
267
- headingElement.attributes["aria-level"]?.nodeValue || "2";
268
- const isH2 = headingAriaLevel === "2";
269
-
270
- if (isH2) {
271
- const tocItem = {
272
- anchor: `#${headingElement.hash}`,
273
- id: headingElement.id,
274
- label: headingElement.header
275
- };
276
- tocOptions.push(tocItem);
277
- this.tocOptionIdsSet.add(headingElement.id);
278
- }
279
- }
280
-
281
- this._tocOptions = tocOptions;
282
- }
283
190
  }