@salesforcedevs/docs-components 1.17.11-lwc-fix-alpha1 → 1.17.12-banner

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.17.11-lwc-fix-alpha1",
3
+ "version": "1.17.12-banner",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -248,41 +248,65 @@ export default class ContentLayout extends LightningElement {
248
248
  const docHeaderHeight = docHeaderEl.getBoundingClientRect().height;
249
249
  const totalHeaderHeight = globalNavHeight + docHeaderHeight;
250
250
 
251
+ // Collect any banners rendered via the doc-phase and version-banner slots
252
+ const versionBannerSlot = this.template.querySelector(
253
+ "[name=version-banner]"
254
+ ) as any;
255
+ const docPhaseSlot = this.template.querySelector(
256
+ "[name=doc-phase]"
257
+ ) as any;
258
+ const versionBannerEls = (
259
+ versionBannerSlot
260
+ ? (versionBannerSlot.assignedElements() as HTMLElement[])
261
+ : []
262
+ ) as HTMLElement[];
263
+ const docPhaseEls = (
264
+ docPhaseSlot
265
+ ? (docPhaseSlot.assignedElements() as HTMLElement[])
266
+ : []
267
+ ) as HTMLElement[];
268
+ const bannersTotalHeight = [
269
+ ...versionBannerEls,
270
+ ...docPhaseEls
271
+ ].reduce(
272
+ (sum, el) => sum + (el?.getBoundingClientRect()?.height || 0),
273
+ 0
274
+ );
275
+
251
276
  // Selecting the doc section heading and RNB here.
252
277
  const docHeadingEls = Array.from(
253
278
  document.querySelectorAll("doc-heading")
254
279
  );
255
280
  const rightNavBarEl = this.template.querySelector(".right-nav-bar");
256
281
 
257
- sidebarEl.style.setProperty(
282
+ (sidebarEl as HTMLElement).style.setProperty(
258
283
  "--dx-c-content-sidebar-sticky-top",
259
- `${globalNavHeight + docHeaderHeight}px`
284
+ `${totalHeaderHeight}px`
260
285
  );
261
286
 
262
287
  docHeaderEl.style.setProperty(
263
288
  "--dx-g-global-header-height",
264
289
  `${globalNavHeight}px`
265
290
  );
291
+ // Expose heights as CSS variables for sticky offsets used by page content
292
+ const rootStyle = document.documentElement.style;
293
+ rootStyle.setProperty(
294
+ "--dx-g-doc-header-banner-height",
295
+ `${docHeaderHeight + bannersTotalHeight}px`
296
+ );
266
297
 
267
298
  // Adjusting the doc section heading on scroll.
268
299
  docHeadingEls.forEach((docHeadingEl) => {
269
- (docHeadingEl as any).style.scrollMarginTop = docPhaseEl
270
- ? `${
271
- totalHeaderHeight +
272
- docPhaseEl.getBoundingClientRect().height +
273
- 40
274
- }px`
275
- : `${totalHeaderHeight + 40}px`;
300
+ (docHeadingEl as any).style.scrollMarginTop = `${
301
+ totalHeaderHeight + bannersTotalHeight + 40
302
+ }px`;
276
303
  });
277
304
 
278
305
  // Adjusting the right nav bar on scroll.
279
306
  if (rightNavBarEl) {
280
- rightNavBarEl.style.top = docPhaseEl
281
- ? `${
282
- totalHeaderHeight +
283
- docPhaseEl.getBoundingClientRect().height
284
- }px`
285
- : `${totalHeaderHeight}px`;
307
+ (rightNavBarEl as HTMLElement).style.top = `${
308
+ totalHeaderHeight + bannersTotalHeight
309
+ }px`;
286
310
  }
287
311
 
288
312
  // If doc phase element exists, we need to account for its sticky position. Mobile should include the sidebar height (since it becomes sticky aswell).
@@ -2,111 +2,44 @@ import ContentLayout from "doc/contentLayout";
2
2
 
3
3
  const TOC_HEADER_TAG = "doc-heading";
4
4
  const RNB_BY_TAB = "docs-tab";
5
- const SPECIFICATION_TAG = "doc-specification-content";
5
+ const SPECIFICATION_TAB_TITLE = "Specification";
6
6
  export const OBSERVER_ATTACH_WAIT_TIME = 500;
7
7
 
8
8
  export default class LwcContentLayout extends ContentLayout {
9
9
  private rnbByTab: boolean = false;
10
10
 
11
- // DOM element caches to avoid repeated queries
12
- private tabPanelListCache: any = null;
13
- private hasSpecContentCache: boolean | null = null;
14
- private allTabsCache: any[] | null = null;
15
- private mainSlotCache: any = null;
16
-
17
11
  private setRNBByTab() {
18
- const tabPanelListItem = this.getTabPanelList();
19
- this.rnbByTab = tabPanelListItem?.id === RNB_BY_TAB;
12
+ const tabPanelListItem: any = this.getTabPanelList();
13
+ this.rnbByTab = tabPanelListItem?.id === RNB_BY_TAB ? true : false;
20
14
  }
21
15
 
22
16
  get showTabBasedRNB() {
23
17
  return this.rnbByTab;
24
18
  }
25
19
 
26
- /**
27
- * Check if the main slot contains doc-specification-content
28
- * Uses caching to avoid repeated DOM queries
29
- */
30
- private hasSpecificationContent(): boolean {
31
- if (this.hasSpecContentCache !== null) {
32
- return this.hasSpecContentCache;
33
- }
34
-
35
- const mainSlot = this.getMainSlot();
36
- if (mainSlot) {
37
- const assignedElements = (mainSlot as any).assignedElements();
38
-
39
- for (const element of assignedElements) {
40
- if (
41
- element.tagName === SPECIFICATION_TAG ||
42
- element.querySelector(SPECIFICATION_TAG) ||
43
- element.shadowRoot?.querySelector(SPECIFICATION_TAG)
44
- ) {
45
- return (this.hasSpecContentCache = true);
46
- }
47
- }
48
- }
49
- return (this.hasSpecContentCache = false);
50
- }
51
-
52
- /**
53
- * Clear all caches when content changes
54
- */
55
- private clearAllCaches(): void {
56
- this.hasSpecContentCache = null;
57
- this.tabPanelListCache = null;
58
- this.allTabsCache = null;
59
- this.mainSlotCache = null;
60
- }
61
-
62
- /**
63
- * Get the main slot element with caching
64
- */
65
- private getMainSlot(): any {
66
- if (!this.mainSlotCache) {
67
- this.mainSlotCache =
68
- this.template.querySelector("slot:not([name])");
69
- }
70
- return this.mainSlotCache;
71
- }
72
-
73
- /**
74
- * Get tab panel list with caching
75
- */
76
- private getTabPanelList(): any {
77
- if (!this.tabPanelListCache) {
78
- // eslint-disable-next-line @lwc/lwc/no-document-query
79
- this.tabPanelListCache =
80
- document.querySelector("dx-tab-panel-list");
81
- }
82
- return this.tabPanelListCache;
83
- }
84
-
85
20
  onRNBClick = (event: CustomEvent) => {
86
21
  event.stopPropagation();
87
- if (this.hasSpecificationContent()) {
22
+ const currentTab = this.getSelectedTabId();
23
+ if (currentTab === SPECIFICATION_TAB_TITLE) {
88
24
  this.didScrollToSelectedHash = false;
89
25
  }
90
26
  };
91
27
 
92
28
  onTabChanged = () => {
93
29
  this.updateRNB();
94
-
95
- const { hash } = window.location;
96
- if (this.hasSpecificationContent() && hash) {
97
- this.didScrollToSelectedHash = false;
98
-
99
- requestAnimationFrame(() => this.updateHeadingForRNB());
100
- }
101
30
  };
102
31
 
32
+ private getTabPanelList() {
33
+ // eslint-disable-next-line @lwc/lwc/no-document-query
34
+ return document.querySelector("dx-tab-panel-list");
35
+ }
36
+
103
37
  protected getHeadingElements() {
104
38
  let headingElements = super.getHeadingElements();
105
39
  if (this.showTabBasedRNB) {
106
- const tabPanelListItem = this.getTabPanelList();
40
+ const tabPanelListItem: any = this.getTabPanelList();
107
41
  const tabPanels =
108
42
  tabPanelListItem?.querySelectorAll("dx-tab-panel");
109
-
110
43
  for (const tabPanelItem of tabPanels) {
111
44
  if (tabPanelItem.active) {
112
45
  // This is needed for Specification tab content
@@ -132,7 +65,6 @@ export default class LwcContentLayout extends ContentLayout {
132
65
  private updateURL() {
133
66
  const tabs = this.getAllTabs();
134
67
  const selectedTabId = this.getSelectedTabId();
135
-
136
68
  tabs.forEach((tab: any) => {
137
69
  if (tab.getAttribute("aria-selected") === "true") {
138
70
  const tabID = tab.getAttribute("aria-label");
@@ -169,38 +101,22 @@ export default class LwcContentLayout extends ContentLayout {
169
101
  const selectedTabId = this.getSelectedTabId();
170
102
  if (selectedTabId) {
171
103
  this.selectTabById(selectedTabId);
172
-
173
- // If there's a hash and we have specification content,
174
- // we need to wait for the content to load before scrolling
175
- const { hash } = window.location;
176
- if (this.hasSpecificationContent() && hash) {
177
- // Reset the scroll flag to allow scrolling once content is loaded
178
- this.didScrollToSelectedHash = false;
179
- }
180
104
  }
181
105
  });
182
106
  }
183
107
 
184
108
  private getAllTabs(): any[] {
185
- // Return cached result if available
186
- if (this.allTabsCache) {
187
- return this.allTabsCache;
188
- }
189
-
190
- const tabPanelListItem = this.getTabPanelList();
109
+ const tabPanelListItem: any = this.getTabPanelList();
191
110
  if (tabPanelListItem?.shadowRoot) {
192
- this.allTabsCache = Array.from(
111
+ return Array.from(
193
112
  tabPanelListItem.shadowRoot.querySelectorAll(
194
113
  "dx-tab-panel-item"
195
114
  )
196
115
  ).map((tabPanelItem: any) =>
197
116
  tabPanelItem.shadowRoot.querySelector("button")
198
117
  );
199
- } else {
200
- this.allTabsCache = [];
201
118
  }
202
-
203
- return this.allTabsCache;
119
+ return [];
204
120
  }
205
121
 
206
122
  private selectTabById(tabId: string) {
@@ -242,12 +158,8 @@ export default class LwcContentLayout extends ContentLayout {
242
158
  }
243
159
  }
244
160
 
245
- onSlotChange(): void {
246
- this.clearAllCaches();
247
- super.onSlotChange();
248
- }
249
-
250
161
  updateHeadingForRNB(): void {
162
+ // We only need to update URL in case of /docs and ignore if tabs are used anywhere else in DSC
251
163
  if (this.showTabBasedRNB) {
252
164
  this.updateURL();
253
165
  }
@@ -73,7 +73,9 @@
73
73
  <template lwc:if={method.firstArgument}>
74
74
  <tr key={method.name}>
75
75
  <td rowspan={method.arguments.length}>
76
- <span class="code">{method.name}</span>
76
+ <span class="code">
77
+ {method.nameInKebabCase}
78
+ </span>
77
79
  </td>
78
80
  <td rowspan={method.arguments.length}>
79
81
  {method.description}
@@ -98,7 +100,9 @@
98
100
  <template lwc:else>
99
101
  <tr key={method.name}>
100
102
  <td>
101
- <span class="code">{method.name}</span>
103
+ <span class="code">
104
+ {method.nameInKebabCase}
105
+ </span>
102
106
  </td>
103
107
  <td>{method.description}</td>
104
108
  <td colspan="3"></td>