@salesforcedevs/docs-components 1.3.155-rnb-by-tab1 → 1.3.156-canary.0

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.155-rnb-by-tab1",
3
+ "version": "1.3.156-canary.0",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -35,7 +35,6 @@ export default class ContentLayout extends LightningElement {
35
35
  @api coveoSearchHub!: string;
36
36
  @api coveoAdvancedQueryConfig!: string;
37
37
  @api useOldSidebar?: boolean = false;
38
- @api rnbByTabId?: string = "lwc-doc-tab";
39
38
 
40
39
  @api
41
40
  get breadcrumbs() {
@@ -119,10 +118,6 @@ export default class ContentLayout extends LightningElement {
119
118
  return window.location.pathname;
120
119
  }
121
120
 
122
- get showTabBasedRNB() {
123
- return this.rnbByTabId ? true : false;
124
- }
125
-
126
121
  get showBreadcrumbs(): boolean {
127
122
  return (
128
123
  this.breadcrumbs != null && (this.breadcrumbs as any[]).length > 1
@@ -141,24 +136,8 @@ export default class ContentLayout extends LightningElement {
141
136
  );
142
137
  this.searchSyncer.init();
143
138
  }
144
-
145
- if (this.showTabBasedRNB) {
146
- window.addEventListener("tabchanged", this.onTabChanged);
147
- }
148
139
  }
149
140
 
150
- onTabChanged = () => {
151
- this.updateRNB();
152
- };
153
-
154
- updateRNB = () => {
155
- const headingElements = this.getHeadingElements();
156
- headingElements.forEach((headingElement) => {
157
- headingElement.hash = headingElement.attributes.hash?.nodeValue;
158
- });
159
- this.updateTocItems(headingElements);
160
- };
161
-
162
141
  renderedCallback(): void {
163
142
  /**
164
143
  * Note: We are adding timeout because chrome is optimizing and not triggering recent renderedCallback though elements reference is changed
@@ -186,10 +165,6 @@ export default class ContentLayout extends LightningElement {
186
165
  "highlightedtermchange",
187
166
  this.updateHighlighted
188
167
  );
189
-
190
- if (this.showTabBasedRNB) {
191
- window.removeEventListener("tabchanged", this.onTabChanged);
192
- }
193
168
  window.removeEventListener("scroll", this.adjustNavPosition);
194
169
  window.removeEventListener("resize", this.adjustNavPosition);
195
170
  this.searchSyncer.dispose();
@@ -209,29 +184,6 @@ export default class ContentLayout extends LightningElement {
209
184
  }
210
185
  };
211
186
 
212
- private getHeadingElements() {
213
- let headingElements = document.querySelectorAll(TOC_HEADER_TAG);
214
- if (this.showTabBasedRNB) {
215
- const tabPanelListItems =
216
- document.querySelectorAll("dx-tab-panel-list");
217
- for (const tabPanelListItem of tabPanelListItems) {
218
- if (tabPanelListItem.id === this.rnbByTabId) {
219
- const tabPanelItems =
220
- tabPanelListItem.querySelectorAll("dx-tab-panel");
221
- for (const tabPanelItem of tabPanelItems) {
222
- if (tabPanelItem.active) {
223
- headingElements =
224
- tabPanelItem.querySelectorAll(TOC_HEADER_TAG);
225
- break;
226
- }
227
- }
228
- break;
229
- }
230
- }
231
- }
232
- return headingElements;
233
- }
234
-
235
187
  /*
236
188
  This is a workaround for the global nav sticky header being decoupled from the doc header & doc phase.
237
189
  We have to account for the global nav changing height due to animations.
@@ -291,7 +243,9 @@ export default class ContentLayout extends LightningElement {
291
243
  );
292
244
 
293
245
  // Adjust scroll margin for doc headings when doc phase is present
294
- const docHeadingEls = this.getHeadingElements();
246
+ const docHeadingEls = Array.from(
247
+ document.querySelectorAll("doc-heading")
248
+ );
295
249
  docHeadingEls.forEach((docHeadingEl) => {
296
250
  docHeadingEl.style.scrollMarginTop = `${
297
251
  globalNavHeight +
@@ -347,7 +301,7 @@ export default class ContentLayout extends LightningElement {
347
301
  );
348
302
 
349
303
  // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
350
- const headingElements = this.getHeadingElements();
304
+ const headingElements = document.querySelectorAll(TOC_HEADER_TAG);
351
305
  for (const headingElement of headingElements) {
352
306
  // Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
353
307
  const id = headingElement.getAttribute("id");
@@ -363,34 +317,47 @@ export default class ContentLayout extends LightningElement {
363
317
  }
364
318
  };
365
319
 
366
- onSlotChange(): void {
367
- this.updateRNB();
368
- }
320
+ onSlotChange(event: Event): void {
321
+ const slotElements = (
322
+ event.target as HTMLSlotElement
323
+ ).assignedElements();
324
+
325
+ if (slotElements.length) {
326
+ this.contentLoaded = true;
327
+ const slotContentElement = slotElements[0];
328
+ const headingElements =
329
+ slotContentElement.ownerDocument?.getElementsByTagName(
330
+ TOC_HEADER_TAG
331
+ );
369
332
 
370
- // eslint-disable-next-line no-undef
371
- private updateTocItems(headingElements: NodeListOf<Element>): void {
372
- const tocOptions = [];
333
+ for (const headingElement of headingElements) {
334
+ // Sometimes elements hash is not being set when slot content is wrapped with div
335
+ headingElement.hash = headingElement.attributes.hash?.nodeValue;
336
+ }
373
337
 
374
- for (const headingElement of headingElements) {
375
- headingElement.id = headingElement.hash;
376
-
377
- // Update tocOptions from anchorTags only for H2, consider default as 2 as per component
378
- const headingAriaLevel =
379
- headingElement.attributes["aria-level"]?.nodeValue || "2";
380
- const isH2 = headingAriaLevel === "2";
381
-
382
- if (isH2) {
383
- const tocItem = {
384
- anchor: `#${headingElement.hash}`,
385
- id: headingElement.id,
386
- label: headingElement.title
387
- };
388
- tocOptions.push(tocItem);
389
- this.tocOptionIdsSet.add(headingElement.id);
338
+ const tocOptions = [];
339
+
340
+ for (const headingElement of headingElements) {
341
+ headingElement.id = headingElement.hash;
342
+
343
+ // Update tocOptions from anchorTags only for H2, consider default as 2 as per component
344
+ const headingAriaLevel =
345
+ headingElement.attributes["aria-level"]?.nodeValue || "2";
346
+ const isH2 = headingAriaLevel === "2";
347
+
348
+ if (isH2) {
349
+ const tocItem = {
350
+ anchor: `#${headingElement.hash}`,
351
+ id: headingElement.id,
352
+ label: headingElement.title
353
+ };
354
+ tocOptions.push(tocItem);
355
+ this.tocOptionIdsSet.add(headingElement.id);
356
+ }
390
357
  }
391
- }
392
358
 
393
- this._tocOptions = tocOptions;
359
+ this._tocOptions = tocOptions;
360
+ }
394
361
  }
395
362
 
396
363
  private disconnectObserver(): void {
@@ -13,7 +13,7 @@ import {
13
13
  TocMap
14
14
  } from "./types";
15
15
  import { SearchSyncer } from "docUtils/SearchSyncer";
16
- import { LightningElementWithState } from "docBaseElements/lightningElementWithState";
16
+ import { LightningElementWithState } from "dxBaseElements/lightningElementWithState";
17
17
  import { oldVersionDocInfo } from "docUtils/utils";
18
18
  import { Breadcrumb, DocPhaseInfo, Language } from "typings/custom";
19
19
  import { track as trackGTM } from "dxUtils/analytics";
@@ -1,93 +0,0 @@
1
- import { LightningElement, track } from "lwc";
2
-
3
- /**
4
- * This is a helper class for when you want your LWC component to have state
5
- * that is automatically tracked _along with_ its previous state, in a React-
6
- * like fashion, so that you can compare current state with previous state
7
- * after a render (like React's `commponentDidUpdate`). One benefit of doing
8
- * things this way is that you can put all of your reactions to state changes
9
- * in one place, in `renderedCallback`, rather than having them in various
10
- * places throughout the component.
11
- *
12
- * The API consists in `this.prevState`, `this.state`, and `this.setState`.
13
- *
14
- * Usage:
15
- *
16
- * ```
17
- * type MyState = {
18
- * isFetchingContent: boolean;
19
- * };
20
- *
21
- * class MyFetchingComponent extends LightningElementWithState<MyState> {
22
- * constructor() {
23
- * // `this.state` can only be initialized once
24
- * this.state = {
25
- * isFetchingContent: false
26
- * };
27
- * }
28
- *
29
- * // Queued for execution whenever a `setState` call completes
30
- * renderedCallback() {
31
- * if (this.prevState.isFetchingContent && !this.state.isFetchingContent) {
32
- * // Do something knowing that we just finished fetching.
33
- * notifyFetchSuccessful();
34
- * }
35
- * }
36
- *
37
- * fetchSomething() {
38
- * this.setState({
39
- * isFetchingContent: true
40
- * });
41
- *
42
- * fetch(whatever).then(() => {
43
- * this.setState({
44
- * isFetching: false
45
- * }
46
- * });
47
- * }
48
- * }
49
- * ```
50
- */
51
- export abstract class LightningElementWithState<
52
- T extends { [key: string]: unknown }
53
- > extends LightningElement {
54
- private _prevState = {} as T;
55
- @track private _state = {} as T;
56
-
57
- private _didInitializeState = false;
58
-
59
- protected get prevState(): T {
60
- return Object.freeze({
61
- ...this._prevState
62
- });
63
- }
64
-
65
- protected get state(): T {
66
- return Object.freeze({
67
- ...this._state
68
- });
69
- }
70
-
71
- protected set state(initialState: T) {
72
- if (!this._didInitializeState) {
73
- this._state = {
74
- ...initialState
75
- };
76
- this._didInitializeState = true;
77
- } else {
78
- throw new Error(
79
- "To mutate state after initialization, use `this.setState`."
80
- );
81
- }
82
- }
83
-
84
- protected setState = (state: Partial<T>): void => {
85
- this._prevState = {
86
- ...this._state
87
- };
88
- this._state = {
89
- ...this._state,
90
- ...state
91
- };
92
- };
93
- }