@salesforcedevs/docs-components 1.30.1-docs-alpha1 → 1.30.1-locale-picker-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.30.1-docs-alpha1",
3
+ "version": "1.30.1-locale-picker-1",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -25,5 +25,6 @@
25
25
  "@types/lodash.orderby": "4.6.9",
26
26
  "@types/lodash.uniqby": "4.7.9"
27
27
  },
28
- "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
28
+ "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
29
+ "stableVersion": "1.30.1"
29
30
  }
@@ -1,6 +1,7 @@
1
1
  :host {
2
2
  --dx-footer-margin-top: 142px;
3
3
  --doc-c-redoc-sidebar-top: calc(
4
- var(--dx-g-global-header-height) + var(--dx-g-doc-header-height)
4
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
5
+ var(--dx-g-spacing-xl)
5
6
  );
6
7
  }
@@ -3,9 +3,12 @@ import { createElement, LightningElement, api } from "lwc";
3
3
  import DocPhase from "doc/phase";
4
4
  import DxFooter from "dx/footer";
5
5
  import DxIcon from "dx/icon";
6
+ import SidebarFooterNav from "dx/sidebarFooterNav";
6
7
  import SprigSurvey from "doc/sprigSurvey";
7
8
  import { throttle } from "throttle-debounce";
8
9
  import { pollUntil } from "dxUtils/async";
10
+ import { toJson } from "dxUtils/normalizers";
11
+ import type { OptionWithLink } from "typings/custom";
9
12
 
10
13
  declare global {
11
14
  interface Window {
@@ -47,6 +50,7 @@ export default class RedocReference extends LightningElement {
47
50
  private docHeaderElement: Element | null = null;
48
51
  private docPhaseWrapperElement: Element | null = null;
49
52
  private lastSidebarTop = 0;
53
+ private _languages: OptionWithLink[] = [];
50
54
 
51
55
  /**
52
56
  * History length captured at mount (pre-Redoc), used by `onBackClick` to
@@ -118,6 +122,16 @@ export default class RedocReference extends LightningElement {
118
122
  }
119
123
  private _contentType: string = "";
120
124
 
125
+ @api
126
+ get languages(): OptionWithLink[] {
127
+ return this._languages;
128
+ }
129
+ set languages(value: string | OptionWithLink[]) {
130
+ this._languages = toJson(value) || [];
131
+ }
132
+
133
+ @api language: string | null = null;
134
+
121
135
  get specTitle(): string | null {
122
136
  return this.getSelectedReference()?.title ?? null;
123
137
  }
@@ -135,6 +149,13 @@ export default class RedocReference extends LightningElement {
135
149
  return refCount > 1;
136
150
  }
137
151
 
152
+ /**
153
+ * when more than one localized spec is available
154
+ */
155
+ get hasLocalePicker(): boolean {
156
+ return this.languages.length > 1;
157
+ }
158
+
138
159
  /**
139
160
  * Whether to show the project header. Shown for multi-spec reference
140
161
  * sets, and for any docs-content spec topic so it always has a back
@@ -175,12 +196,28 @@ export default class RedocReference extends LightningElement {
175
196
  if (referrerUrl.origin !== window.location.origin) {
176
197
  return null;
177
198
  }
199
+ if (this.isLocaleHref(referrerUrl.pathname)) {
200
+ return null;
201
+ }
178
202
  return referrerUrl.href;
179
203
  } catch {
180
204
  return null;
181
205
  }
182
206
  }
183
207
 
208
+ /**
209
+ * switching locale on this same page.
210
+ */
211
+ private isLocaleHref(pathname: string): boolean {
212
+ return this.languages.some((locale) => {
213
+ const href = locale?.link?.href;
214
+ return (
215
+ !!href &&
216
+ new URL(href, window.location.origin).pathname === pathname
217
+ );
218
+ });
219
+ }
220
+
184
221
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
185
222
  get effectiveFooterOrigin(): string {
186
223
  return (
@@ -419,7 +456,7 @@ export default class RedocReference extends LightningElement {
419
456
  this.appendFooterItems(apiContentDiv);
420
457
 
421
458
  // Inject the multi-spec project header into Redoc's left menu only.
422
- this.insertProjectHeaderInMenu(redocContainer);
459
+ this.insertSidebarNav(redocContainer);
423
460
 
424
461
  // Wait for footer to be rendered before updating styles
425
462
  requestAnimationFrame(() => {
@@ -436,7 +473,7 @@ export default class RedocReference extends LightningElement {
436
473
  /**
437
474
  * Inserts the project header into Redoc for multi-spec reference sets.
438
475
  */
439
- private insertProjectHeaderInMenu(redocContainer: HTMLElement): void {
476
+ private insertSidebarNav(redocContainer: HTMLElement): void {
440
477
  if (!this.showRedocHeader) {
441
478
  return;
442
479
  }
@@ -450,6 +487,32 @@ export default class RedocReference extends LightningElement {
450
487
  target.firstChild
451
488
  );
452
489
  });
490
+
491
+ // Locale picker
492
+ if (this.hasLocalePicker) {
493
+ const menuContent = redocContainer.querySelector(".menu-content");
494
+ menuContent?.appendChild(this.buildLocalePickerDom());
495
+ }
496
+ }
497
+
498
+ /**
499
+ * Builds the locale picker DOM by reusing `dx-sidebar-footer-nav`
500
+ */
501
+ private buildLocalePickerDom(): HTMLElement {
502
+ const wrapper = document.createElement("div");
503
+ wrapper.className = "redoc-footer-nav";
504
+
505
+ const picker = createElement("dx-sidebar-footer-nav", {
506
+ is: SidebarFooterNav
507
+ });
508
+
509
+ Object.assign(picker, {
510
+ languages: this.languages,
511
+ language: this.language
512
+ });
513
+ wrapper.appendChild(picker);
514
+
515
+ return wrapper;
453
516
  }
454
517
 
455
518
  /**
@@ -15,8 +15,6 @@
15
15
  language={language}
16
16
  show-footer={enableFooter}
17
17
  origin={origin}
18
- dev-center={devCenter}
19
- brand={brand}
20
18
  >
21
19
  <doc-phase
22
20
  slot="doc-phase"
@@ -44,8 +44,6 @@ export default class UnifiedContentLayout extends LightningElement {
44
44
  @api tocAriaLevel?: string;
45
45
  @api languages?: OptionWithLink[];
46
46
  @api language?: string;
47
- @api devCenter: any = null;
48
- @api brand: any = null;
49
47
 
50
48
  /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). */
51
49
  @api origin: string | null = null;