@salesforcedevs/docs-components 1.32.0-alpha.9 → 1.32.0-docs-content-type-1

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.
Files changed (26) hide show
  1. package/.npmrc +1 -0
  2. package/lwc.config.json +5 -0
  3. package/package.json +29 -28
  4. package/src/modules/doc/amfReference/amfReference.html +1 -0
  5. package/src/modules/doc/amfReference/amfReference.ts +54 -10
  6. package/src/modules/doc/amfReference/types.ts +5 -0
  7. package/src/modules/doc/contentActionToolbar/contentActionToolbar.css +31 -0
  8. package/src/modules/doc/contentActionToolbar/contentActionToolbar.html +53 -0
  9. package/src/modules/doc/contentActionToolbar/contentActionToolbar.ts +151 -0
  10. package/src/modules/doc/contentActionToolbar/contentActionToolbarMocks.ts +48 -0
  11. package/src/modules/doc/contentLayout/contentLayout.css +0 -7
  12. package/src/modules/doc/contentLayout/contentLayout.html +17 -36
  13. package/src/modules/doc/contentLayout/contentLayout.ts +104 -46
  14. package/src/modules/doc/header/header.html +0 -1
  15. package/src/modules/doc/lwcContentLayout/lwcContentLayout.html +1 -12
  16. package/src/modules/doc/redocReference/redocReference.ts +304 -0
  17. package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.css +19 -0
  18. package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.html +28 -0
  19. package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.ts +87 -0
  20. package/src/modules/doc/xmlContent/xmlContent.html +0 -1
  21. package/src/modules/doc/xmlContent/xmlContent.ts +11 -0
  22. package/src/modules/docUtils/searchClient/searchClient.ts +160 -0
  23. package/src/modules/docUtils/searchController/__mocks__/searchController.ts +90 -0
  24. package/src/modules/docUtils/searchController/searchController.ts +420 -0
  25. package/src/modules/docUtils/searchLocale/searchLocale.ts +85 -0
  26. package/LICENSE +0 -12
@@ -1,12 +1,15 @@
1
1
  /* eslint-disable @lwc/lwc/no-document-query */
2
- import { LightningElement, api, track } from "lwc";
3
- import { closest } from "kagekiri";
4
- import { fetchHasResults } from "dxUtils/data360Search";
2
+ import { LightningElement, api, createElement, track } from "lwc";
3
+ import { closest, querySelector } from "kagekiri";
5
4
  import { toJson, normalizeBoolean } from "dxUtils/normalizers";
6
5
  import { highlightTerms } from "dxUtils/highlight";
7
6
  import { SearchSyncer } from "docUtils/searchSyncer";
8
7
  import type { OptionWithLink } from "typings/custom";
9
8
  import { buildDocLinkClickHandler } from "dxUtils/analytics";
9
+ import ContentActionToolbar from "doc/contentActionToolbar";
10
+
11
+ const CONTENT_ACTION_TOOLBAR_TAG = "doc-content-action-toolbar";
12
+ const PAGE_HEADING_SELECTOR = "h1";
10
13
 
11
14
  type AnchorMap = { [key: string]: { intersect: boolean; id: string } };
12
15
 
@@ -29,6 +32,35 @@ const HIGHLIGHTABLE_SELECTOR = [
29
32
  ].join(",");
30
33
  export const OBSERVER_ATTACH_WAIT_TIME = 500;
31
34
 
35
+ const DEFAULT_READING_TIME_LOCALE = "en-us";
36
+
37
+ /**
38
+ * Localized "minute read" templates. `{minutes}` is replaced with the rounded
39
+ * reading-time value. Only displayed when reading time is greater than 1, so
40
+ * plural forms are always appropriate. Keys match the locales declared in
41
+ * sfdocs (and the doc-locale-banner) so that a localized document automatically
42
+ * gets a localized reading-time label.
43
+ */
44
+ export const READING_TIME_LABELS: Record<string, string> = {
45
+ "en-us": "{minutes} minute read",
46
+ "ja-jp": "読了時間 {minutes} 分",
47
+ "zh-cn": "阅读时间 {minutes} 分钟",
48
+ "zh-tw": "閱讀時間 {minutes} 分鐘",
49
+ "fr-fr": "Lecture de {minutes} minutes",
50
+ "de-de": "{minutes} Minuten Lesezeit",
51
+ "it-it": "{minutes} minuti di lettura",
52
+ "ko-kr": "읽는 데 {minutes}분",
53
+ "pt-br": "{minutes} minutos de leitura",
54
+ "es-mx": "{minutes} minutos de lectura",
55
+ "es-es": "{minutes} minutos de lectura",
56
+ "ru-ru": "Время чтения: {minutes} мин",
57
+ "fi-fi": "{minutes} minuutin lukuaika",
58
+ "da-dk": "{minutes} minutters læsning",
59
+ "sv-se": "{minutes} minuters läsning",
60
+ "nl-nl": "{minutes} minuten leestijd",
61
+ "nb-no": "{minutes} minutters lesetid"
62
+ };
63
+
32
64
  export default class ContentLayout extends LightningElement {
33
65
  @api sidebarValue!: string;
34
66
  @api sidebarHeader!: string;
@@ -43,15 +75,6 @@ export default class ContentLayout extends LightningElement {
43
75
  @api brand: any;
44
76
  @api emptyStateMessage?: string;
45
77
 
46
- @api
47
- get enableDataCloudSearch() {
48
- return this._enableDataCloudSearch;
49
- }
50
- set enableDataCloudSearch(value) {
51
- this._enableDataCloudSearch = normalizeBoolean(value);
52
- }
53
- private _enableDataCloudSearch = false;
54
-
55
78
  // This is needed for now to prevent failing snapshot tests due to links in the footer
56
79
  @api
57
80
  get showFooter() {
@@ -76,6 +99,17 @@ export default class ContentLayout extends LightningElement {
76
99
  /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer. */
77
100
  @api origin: string | null = null;
78
101
 
102
+ /** Controls whether the content action toolbar is displayed. */
103
+ @api
104
+ get showContentActionToolbar() {
105
+ return this._showContentActionToolbar;
106
+ }
107
+ set showContentActionToolbar(value) {
108
+ this._showContentActionToolbar = normalizeBoolean(value);
109
+ this.updateContentActionToolbar();
110
+ }
111
+ private _showContentActionToolbar = false;
112
+
79
113
  @api
80
114
  get breadcrumbs() {
81
115
  return this._breadcrumbs;
@@ -118,35 +152,9 @@ export default class ContentLayout extends LightningElement {
118
152
  );
119
153
  }
120
154
 
121
- /** Show Data 360 sidebar only when not using old sidebar and the page has searchable results. */
122
- protected get showDataCloudSidebar(): boolean {
123
- return (
124
- this.enableDataCloudSearch &&
125
- !this.useOldSidebar &&
126
- this.hasDataCloudResults === true
127
- );
128
- }
129
-
130
- /** Show legacy sidebar when explicitly requested or when Data 360 has no results. Don't show until we know (avoids flash). */
131
- protected get showOldSidebar(): boolean {
132
- return (
133
- this.useOldSidebar === true ||
134
- !this.enableDataCloudSearch ||
135
- this.hasDataCloudResults === false
136
- );
137
- }
138
-
139
- /** Show a space-holding placeholder while we're deciding which sidebar to show (avoids layout shift). */
140
- protected get showSidebarPlaceholder(): boolean {
141
- return !this.showDataCloudSidebar && !this.showOldSidebar;
142
- }
143
-
144
155
  @track
145
156
  protected _sidebarContent: unknown;
146
157
 
147
- @track
148
- protected hasDataCloudResults: boolean | null = null;
149
-
150
158
  protected _breadcrumbs = null;
151
159
 
152
160
  @track
@@ -159,6 +167,7 @@ export default class ContentLayout extends LightningElement {
159
167
  protected hasRendered: boolean = false;
160
168
  protected contentLoaded: boolean = false;
161
169
  protected sidebarOpen: boolean = false;
170
+ protected contentActionToolbarElement: HTMLElement | null = null;
162
171
 
163
172
  get shouldDisplayFeedback() {
164
173
  return this.contentLoaded && typeof Sprig !== "undefined";
@@ -209,6 +218,19 @@ export default class ContentLayout extends LightningElement {
209
218
  return this.readingTime != null && this.readingTime > 1;
210
219
  }
211
220
 
221
+ /**
222
+ * Localized "X minute read" string for the current document language.
223
+ * Falls back to the default (en-us) template when the language is missing
224
+ * or has no translation.
225
+ */
226
+ get readingTimeLabel(): string {
227
+ const localeKey = (this.language || "").toLowerCase();
228
+ const template =
229
+ READING_TIME_LABELS[localeKey] ||
230
+ READING_TIME_LABELS[DEFAULT_READING_TIME_LOCALE];
231
+ return template.replace("{minutes}", String(this.readingTime));
232
+ }
233
+
212
234
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
213
235
  get effectiveFooterOrigin(): string {
214
236
  return (
@@ -217,11 +239,6 @@ export default class ContentLayout extends LightningElement {
217
239
  }
218
240
 
219
241
  connectedCallback(): void {
220
- if (this.enableDataCloudSearch && !this.useOldSidebar) {
221
- fetchHasResults().then((hasResults: boolean) => {
222
- this.hasDataCloudResults = hasResults;
223
- });
224
- }
225
242
  const hasParentHighlightListener = closest(
226
243
  "doc-xml-content",
227
244
  this.template.host
@@ -256,6 +273,8 @@ export default class ContentLayout extends LightningElement {
256
273
  window.addEventListener("scroll", this.adjustNavPosition);
257
274
  window.addEventListener("resize", this.adjustNavPosition);
258
275
 
276
+ this.updateContentActionToolbar();
277
+
259
278
  if (!this.hasRendered) {
260
279
  this.hasRendered = true;
261
280
  this.restoreScroll();
@@ -265,6 +284,43 @@ export default class ContentLayout extends LightningElement {
265
284
  }
266
285
  }
267
286
 
287
+ /**
288
+ * Inserts the content action toolbar into the slotted content immediately
289
+ * after the first H1 found inside this layout.
290
+ */
291
+ protected updateContentActionToolbar(): void {
292
+ if (!this.showContentActionToolbar || !this.sidebarValue) {
293
+ this.removeContentActionToolbar();
294
+ return;
295
+ }
296
+
297
+ const heading = querySelector(
298
+ PAGE_HEADING_SELECTOR,
299
+ this.template.host
300
+ ) as HTMLElement | null;
301
+
302
+ if (!heading) {
303
+ return;
304
+ }
305
+
306
+ const toolbar = (this.contentActionToolbarElement ??
307
+ createElement(CONTENT_ACTION_TOOLBAR_TAG, {
308
+ is: ContentActionToolbar
309
+ })) as HTMLElement & { pageUrl?: string };
310
+
311
+ toolbar.pageUrl = this.sidebarValue;
312
+
313
+ if (toolbar.previousElementSibling !== heading) {
314
+ heading.parentNode?.insertBefore(toolbar, heading.nextSibling);
315
+ }
316
+
317
+ this.contentActionToolbarElement = toolbar;
318
+ }
319
+
320
+ protected removeContentActionToolbar(): void {
321
+ this.contentActionToolbarElement?.remove();
322
+ }
323
+
268
324
  disconnectedCallback(): void {
269
325
  this.disconnectObserver();
270
326
  window.removeEventListener(
@@ -280,6 +336,9 @@ export default class ContentLayout extends LightningElement {
280
336
 
281
337
  // Remove link click handler
282
338
  this.template.removeEventListener("click", this.handleLinkClick);
339
+
340
+ this.removeContentActionToolbar();
341
+ this.contentActionToolbarElement = null;
283
342
  }
284
343
 
285
344
  restoreScroll() {
@@ -298,9 +357,7 @@ export default class ContentLayout extends LightningElement {
298
357
  We have to account for the global nav changing height due to animations.
299
358
  */
300
359
  adjustNavPosition = () => {
301
- const sidebarEl =
302
- this.template.querySelector("dx-sidebar") ||
303
- this.template.querySelector("dx-sidebar-old");
360
+ const sidebarEl = this.template.querySelector("dx-sidebar-old");
304
361
  const globalNavEl = document.querySelector(
305
362
  "hgf-c360nav"
306
363
  ) as HTMLElement;
@@ -524,6 +581,7 @@ export default class ContentLayout extends LightningElement {
524
581
 
525
582
  onSlotChange(): void {
526
583
  this.updateRNB();
584
+ this.updateContentActionToolbar();
527
585
  this.contentLoaded = true;
528
586
  }
529
587
 
@@ -13,7 +13,6 @@
13
13
  onclick={onLinkClick}
14
14
  class="dev-center-content"
15
15
  >
16
- <dx-icon symbol="back"></dx-icon>
17
16
  <dx-icon
18
17
  class="brand-icon"
19
18
  lwc:if={devCenter.icon}
@@ -1,7 +1,6 @@
1
1
  <template>
2
2
  <div class="content">
3
3
  <dx-sidebar-old
4
- lwc:if={useOldSidebar}
5
4
  class="is-sticky left-nav-bar"
6
5
  trees={sidebarContent}
7
6
  value={sidebarValue}
@@ -16,16 +15,6 @@
16
15
  >
17
16
  <slot name="sidebar-header" slot="version-picker"></slot>
18
17
  </dx-sidebar-old>
19
- <dx-sidebar
20
- lwc:else
21
- class="is-sticky left-nav-bar"
22
- trees={sidebarContent}
23
- value={sidebarValue}
24
- header={sidebarHeader}
25
- ontogglesidebar={onToggleSidebar}
26
- >
27
- <slot name="sidebar-header" slot="version-picker"></slot>
28
- </dx-sidebar>
29
18
  <div class="content-body-doc-phase-container">
30
19
  <div class="doc-phase-wrapper">
31
20
  <slot name="doc-phase"></slot>
@@ -52,7 +41,7 @@
52
41
  ></path>
53
42
  </g>
54
43
  </svg>
55
- {readingTime} minute read
44
+ {readingTimeLabel}
56
45
  </div>
57
46
  <slot onslotchange={onSlotChange}></slot>
58
47
  <doc-sprig-survey
@@ -2,9 +2,13 @@
2
2
  import { createElement, LightningElement, api } from "lwc";
3
3
  import DocPhase from "doc/phase";
4
4
  import DxFooter from "dx/footer";
5
+ import DxIcon from "dx/icon";
6
+ import SidebarFooterNav from "dx/sidebarFooterNav";
5
7
  import SprigSurvey from "doc/sprigSurvey";
6
8
  import { throttle } from "throttle-debounce";
7
9
  import { pollUntil } from "dxUtils/async";
10
+ import { toJson } from "dxUtils/normalizers";
11
+ import type { OptionWithLink } from "typings/custom";
8
12
 
9
13
  declare global {
10
14
  interface Window {
@@ -14,11 +18,19 @@ declare global {
14
18
 
15
19
  declare const Sprig: (eventType: string, eventName: string) => void;
16
20
 
21
+ type ReferenceTopic = {
22
+ link?: { href?: string };
23
+ children?: ReferenceTopic[];
24
+ };
25
+
17
26
  type ReferenceItem = {
18
27
  source: string;
19
28
  href: string;
29
+ title?: string;
20
30
  isSelected?: boolean;
21
31
  docPhase?: string | null;
32
+ referenceType?: string;
33
+ topic?: ReferenceTopic;
22
34
  };
23
35
 
24
36
  type ReferenceConfig = {
@@ -28,6 +40,10 @@ type ReferenceConfig = {
28
40
  const SCROLL_THROTTLE_DELAY = 50;
29
41
  const ELEMENT_TIMEOUT = 10000;
30
42
  const ELEMENT_CHECK_INTERVAL = 100;
43
+ const DEFAULT_PROJECT_TITLE = "All Reference";
44
+ const BACK_TARGET_STORAGE_KEY = "redoc-back-target";
45
+ const DOCS_PATH_SEGMENT = "docs";
46
+ const DEFAULT_LOCALE = "en-us";
31
47
 
32
48
  export default class RedocReference extends LightningElement {
33
49
  private _referenceConfig: ReferenceConfig = { refList: [] };
@@ -37,6 +53,13 @@ export default class RedocReference extends LightningElement {
37
53
  private docHeaderElement: Element | null = null;
38
54
  private docPhaseWrapperElement: Element | null = null;
39
55
  private lastSidebarTop = 0;
56
+ private _languages: OptionWithLink[] = [];
57
+
58
+ /**
59
+ * History length captured at mount (pre-Redoc), used by `onBackClick` to
60
+ * distinguish in-tab navigation (> 1) from a fresh entry (=== 1).
61
+ */
62
+ private initialHistoryLength = 0;
40
63
 
41
64
  showError = false;
42
65
 
@@ -71,6 +94,194 @@ export default class RedocReference extends LightningElement {
71
94
  /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer. */
72
95
  @api origin: string | null = null;
73
96
 
97
+ /**
98
+ * Project title (same value passed to `<doc-header>` as `subtitle`). Used
99
+ * inside the Redoc-rendered UI to label the parent project.
100
+ */
101
+ @api
102
+ get projectTitle(): string | null {
103
+ return this.isDocContentType
104
+ ? this._projectTitle
105
+ : DEFAULT_PROJECT_TITLE;
106
+ }
107
+ set projectTitle(value: string | null) {
108
+ this._projectTitle = value;
109
+ }
110
+ private _projectTitle: string | null = null;
111
+
112
+ /**
113
+ * Href to navigate to when the back link is clicked AND there is no
114
+ * usable referrer (e.g. the user opened the page directly in a fresh
115
+ * tab).
116
+ */
117
+ @api headerHref: string | null = null;
118
+
119
+ @api
120
+ get contentType(): string {
121
+ return this._contentType;
122
+ }
123
+ set contentType(value: string) {
124
+ this._contentType = value;
125
+ }
126
+ private _contentType: string = "";
127
+
128
+ @api
129
+ get languages(): OptionWithLink[] {
130
+ return this._languages;
131
+ }
132
+ set languages(value: string | OptionWithLink[]) {
133
+ this._languages = toJson(value) || [];
134
+ }
135
+
136
+ @api language: string | null = null;
137
+
138
+ get specTitle(): string | null {
139
+ return this.getSelectedReference()?.title ?? null;
140
+ }
141
+
142
+ get isDocContentType(): boolean {
143
+ return this.contentType === "docs";
144
+ }
145
+
146
+ get isReferenceContentType(): boolean {
147
+ return this.contentType === "references";
148
+ }
149
+
150
+ get isMultiSpecSet(): boolean {
151
+ const refCount = this.referenceConfig?.refList?.length ?? 0;
152
+ return refCount > 1;
153
+ }
154
+
155
+ // Reads stored back target
156
+ private getBackTargetFromSession(): string | null {
157
+ return sessionStorage.getItem(BACK_TARGET_STORAGE_KEY);
158
+ }
159
+
160
+ private setBackTargetInSession(href: string): void {
161
+ sessionStorage.setItem(BACK_TARGET_STORAGE_KEY, href);
162
+ }
163
+
164
+ /**
165
+ * when more than one localized spec is available
166
+ */
167
+ get hasLocalePicker(): boolean {
168
+ return this.languages.length > 1;
169
+ }
170
+
171
+ /**
172
+ * Whether to show the project header. Shown for multi-spec reference
173
+ * sets, and for any docs-content spec topic so it always has a back
174
+ * link.
175
+ */
176
+ get showRedocHeader(): boolean {
177
+ return (
178
+ (this.isReferenceContentType && this.isMultiSpecSet) ||
179
+ this.isDocContentType
180
+ );
181
+ }
182
+
183
+ /**
184
+ * Navigates back to reference doc.
185
+ */
186
+ private onBackClick = (event: Event): void => {
187
+ event.preventDefault();
188
+
189
+ const target = this.getTranslatedBackTarget() ?? this.headerHref;
190
+
191
+ if (target) {
192
+ window.location.assign(target);
193
+ }
194
+ };
195
+
196
+ private getTranslatedBackTarget(): string | null {
197
+ const stored = this.getBackTargetFromSession();
198
+ if (stored) {
199
+ return this.language
200
+ ? this.translateToCurrentLocale(stored)
201
+ : stored;
202
+ }
203
+
204
+ const referrer = this.getSameOriginReferrerHref();
205
+ return referrer && !this.isLocaleHref(new URL(referrer).pathname)
206
+ ? referrer
207
+ : null;
208
+ }
209
+
210
+ /* The locale segment sits after "docs" for docs pages,
211
+ * and after the product segment for references.
212
+ */
213
+ private translateToCurrentLocale(storedHref: string): string {
214
+ const url = new URL(storedHref, window.location.origin);
215
+ const localeIds = this.languages.map((loc) => loc.id);
216
+ const segments = url.pathname.split("/").filter(Boolean);
217
+
218
+ // docs -> right after "docs"; references -> after the product segment.
219
+ const localeIndex = this.isDocContentType ? 1 : 2;
220
+
221
+ if (segments[0] === DOCS_PATH_SEGMENT) {
222
+ // Drop the existing locale segment, if any
223
+ if (localeIds.includes(segments[localeIndex])) {
224
+ segments.splice(localeIndex, 1);
225
+ }
226
+ // Add the current locale
227
+ if (this.language && this.language !== DEFAULT_LOCALE) {
228
+ segments.splice(localeIndex, 0, this.language);
229
+ }
230
+ }
231
+
232
+ url.pathname = "/" + segments.join("/");
233
+ return url.href;
234
+ }
235
+
236
+ // Preserves target across locale switches, updates on normal navigation
237
+ private trackBackTarget(): void {
238
+ const referrerHref = this.getSameOriginReferrerHref();
239
+ if (!referrerHref) {
240
+ return;
241
+ }
242
+
243
+ const referrerUrl = new URL(referrerHref);
244
+ if (this.isLocaleHref(referrerUrl.pathname)) {
245
+ return;
246
+ }
247
+
248
+ this.setBackTargetInSession(referrerHref);
249
+ }
250
+
251
+ /**
252
+ * Returns the referrer URL when the page was reached via in-tab navigation
253
+ * from a same-origin page; otherwise `null`. Both `initialHistoryLength`
254
+ * and `document.referrer` are checked since neither signal is reliable on
255
+ * its own.
256
+ */
257
+ private getSameOriginReferrerHref(): string | null {
258
+ if (this.initialHistoryLength <= 1 || !document.referrer) {
259
+ return null;
260
+ }
261
+ try {
262
+ const referrerUrl = new URL(document.referrer);
263
+ if (referrerUrl.origin !== window.location.origin) {
264
+ return null;
265
+ }
266
+ return referrerUrl.href;
267
+ } catch {
268
+ return null;
269
+ }
270
+ }
271
+
272
+ /**
273
+ * switching locale on this same page.
274
+ */
275
+ private isLocaleHref(pathname: string): boolean {
276
+ return this.languages.some((locale) => {
277
+ const href = locale?.link?.href;
278
+ return (
279
+ !!href &&
280
+ new URL(href, window.location.origin).pathname === pathname
281
+ );
282
+ });
283
+ }
284
+
74
285
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
75
286
  get effectiveFooterOrigin(): string {
76
287
  return (
@@ -79,6 +290,13 @@ export default class RedocReference extends LightningElement {
79
290
  }
80
291
 
81
292
  connectedCallback(): void {
293
+ // Snapshot history length before Redoc pushes its own hash entries,
294
+ // so it reflects real in-tab navigation rather than Redoc's churn.
295
+ this.initialHistoryLength = window.history.length;
296
+
297
+ // Track the back target, preserving it across locale switches
298
+ this.trackBackTarget();
299
+
82
300
  window.addEventListener("scroll", this.handleScrollAndResize);
83
301
  window.addEventListener("resize", this.handleScrollAndResize);
84
302
  }
@@ -304,6 +522,9 @@ export default class RedocReference extends LightningElement {
304
522
 
305
523
  this.appendFooterItems(apiContentDiv);
306
524
 
525
+ // Inject the multi-spec project header into Redoc's left menu only.
526
+ this.insertSidebarNav(redocContainer);
527
+
307
528
  // Wait for footer to be rendered before updating styles
308
529
  requestAnimationFrame(() => {
309
530
  this.updateRedocThirdColumnStyle(redocContainer);
@@ -316,6 +537,89 @@ export default class RedocReference extends LightningElement {
316
537
  }
317
538
  }
318
539
 
540
+ /**
541
+ * Inserts the project header and LNB footer into Redoc.
542
+ */
543
+ private insertSidebarNav(redocContainer: HTMLElement): void {
544
+ // Select the LNB and content area of Redoc and insert the requried header.
545
+ if (this.showRedocHeader) {
546
+ redocContainer
547
+ .querySelectorAll<HTMLElement>(".menu-content, .api-content")
548
+ .forEach((target) => {
549
+ target.insertBefore(
550
+ this.buildProjectHeaderDom(),
551
+ target.firstChild
552
+ );
553
+ });
554
+ }
555
+
556
+ // Locale picker
557
+ if (this.hasLocalePicker) {
558
+ const menuContent = redocContainer.querySelector(".menu-content");
559
+ menuContent?.appendChild(this.buildLocalePickerDom());
560
+ }
561
+ }
562
+
563
+ /**
564
+ * Builds the locale picker DOM by reusing `dx-sidebar-footer-nav`
565
+ */
566
+ private buildLocalePickerDom(): HTMLElement {
567
+ const wrapper = document.createElement("div");
568
+ wrapper.className = "redoc-footer-nav";
569
+
570
+ const picker = createElement("dx-sidebar-footer-nav", {
571
+ is: SidebarFooterNav
572
+ });
573
+
574
+ Object.assign(picker, {
575
+ languages: this.languages,
576
+ language: this.language
577
+ });
578
+ wrapper.appendChild(picker);
579
+
580
+ return wrapper;
581
+ }
582
+
583
+ /**
584
+ * Builds a fresh project-title/spec-title header DOM node.
585
+ */
586
+ private buildProjectHeaderDom(): HTMLElement {
587
+ const wrapper = document.createElement("div");
588
+ wrapper.className = "redoc-project-header";
589
+
590
+ if (this.projectTitle) {
591
+ const backLink = document.createElement("a");
592
+ backLink.className = "redoc-project-back";
593
+ backLink.href = "#";
594
+ backLink.addEventListener("click", this.onBackClick);
595
+
596
+ const icon = createElement("dx-icon", { is: DxIcon });
597
+ Object.assign(icon, {
598
+ sprite: "utility",
599
+ symbol: "back",
600
+ size: "medium"
601
+ });
602
+ icon.classList.add("redoc-project-back-arrow");
603
+
604
+ const label = document.createElement("span");
605
+ label.className = "redoc-project-title";
606
+ label.textContent = this.projectTitle;
607
+
608
+ backLink.appendChild(icon);
609
+ backLink.appendChild(label);
610
+ wrapper.appendChild(backLink);
611
+ }
612
+
613
+ if (this.specTitle) {
614
+ const specEl = document.createElement("h2");
615
+ specEl.className = "redoc-spec-title dx-text-display-7";
616
+ specEl.textContent = this.specTitle;
617
+ wrapper.appendChild(specEl);
618
+ }
619
+
620
+ return wrapper;
621
+ }
622
+
319
623
  // Waits for Redoc's API content element to be rendered
320
624
  private async waitForApiContent(
321
625
  container: HTMLElement
@@ -0,0 +1,19 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ .content-type-docs doc-phase {
6
+ --doc-c-phase-top: calc(
7
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
8
+ var(--dx-g-spacing-xl)
9
+ );
10
+ }
11
+
12
+ @media screen and (max-width: 768px) {
13
+ .content-type-docs doc-phase {
14
+ --doc-c-phase-top: calc(
15
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
16
+ 40px
17
+ );
18
+ }
19
+ }
@@ -0,0 +1,28 @@
1
+ <template>
2
+ <doc-content-layout
3
+ class="content-type content-type-markdown content-type-docs"
4
+ breadcrumbs={breadcrumbs}
5
+ share-title={shareTitle}
6
+ share-twitter-via={twitterVia}
7
+ sidebar-header={sidebarHeader}
8
+ sidebar-value={sidebarValue}
9
+ sidebar-content={sidebarContent}
10
+ toc-title={tocTitle}
11
+ toc-options={tocOptions}
12
+ toc-aria-level={tocAriaLevel}
13
+ enable-slot-change="true"
14
+ languages={languages}
15
+ language={language}
16
+ show-footer={enableFooter}
17
+ origin={origin}
18
+ dev-center={devCenter}
19
+ brand={brand}
20
+ >
21
+ <doc-phase
22
+ slot="doc-phase"
23
+ lwc:if={docPhaseInfo}
24
+ doc-phase-info={docPhaseInfo}
25
+ ></doc-phase>
26
+ <slot></slot>
27
+ </doc-content-layout>
28
+ </template>