@salesforcedevs/docs-components 1.34.8 → 1.35.0-final-test

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/lwc.config.json CHANGED
@@ -26,7 +26,6 @@
26
26
  "doc/phase",
27
27
  "doc/redocReference",
28
28
  "doc/specificationContent",
29
- "doc/versionPicker",
30
29
  "doc/xmlContent",
31
30
  "docUtils/searchClient",
32
31
  "docUtils/searchController",
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
- "name": "@salesforcedevs/docs-components",
3
- "version": "1.34.8",
4
- "description": "Docs Lightning web components for DSC",
5
- "license": "MIT",
6
- "main": "index.js",
7
- "engines": {
8
- "node": "24.22.1"
9
- },
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "dependencies": {
14
- "@api-components/amf-helper-mixin": "4.5.29",
15
- "classnames": "2.5.1",
16
- "dompurify": "3.2.4",
17
- "kagekiri": "1.4.2",
18
- "lodash.orderby": "4.6.0",
19
- "lodash.uniqby": "4.7.0",
20
- "query-string": "7.1.3",
21
- "sentence-case": "3.0.4"
22
- },
23
- "devDependencies": {
24
- "@types/classnames": "2.3.1",
25
- "@types/lodash.orderby": "4.6.9",
26
- "@types/lodash.uniqby": "4.7.9"
27
- },
28
- "gitHead": "483ca68f1d878910284fbcb0df178fc2a4f48a3a"
29
- }
2
+ "name": "@salesforcedevs/docs-components",
3
+ "version": "1.35.0-final-test",
4
+ "description": "Docs Lightning web components for DSC",
5
+ "license": "MIT",
6
+ "main": "index.js",
7
+ "engines": {
8
+ "node": "22.x"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "dependencies": {
14
+ "@api-components/amf-helper-mixin": "4.5.29",
15
+ "classnames": "2.5.1",
16
+ "dompurify": "3.2.4",
17
+ "kagekiri": "1.4.2",
18
+ "lodash.orderby": "4.6.0",
19
+ "lodash.uniqby": "4.7.0",
20
+ "query-string": "7.1.3",
21
+ "sentence-case": "3.0.4"
22
+ },
23
+ "devDependencies": {
24
+ "@types/classnames": "2.3.1",
25
+ "@types/lodash.orderby": "4.6.9",
26
+ "@types/lodash.uniqby": "4.7.9"
27
+ },
28
+ "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
29
+ }
@@ -35,13 +35,13 @@
35
35
  ondismissphase={handleDismissVersionBanner}
36
36
  ></doc-phase>
37
37
  <div lwc:if={isVersionEnabled} slot="sidebar-header">
38
- <doc-version-picker
38
+ <dx-version-picker
39
39
  onchange={handleVersionChange}
40
40
  data-type="version"
41
41
  versions={versions}
42
42
  selected-version={selectedVersion}
43
43
  latest-version={latestVersion}
44
- ></doc-version-picker>
44
+ ></dx-version-picker>
45
45
  </div>
46
46
  <template lwc:if={showSpecBasedReference}>
47
47
  <div class="container">
@@ -1,21 +1,40 @@
1
1
  <template>
2
2
  <div class="content">
3
- <dx-sidebar-old
4
- class="is-sticky left-nav-bar"
5
- trees={sidebarContent}
6
- value={sidebarValue}
7
- header={sidebarHeader}
8
- ontogglesidebar={onToggleSidebar}
9
- languages={languages}
10
- language={language}
11
- bail-href={bailHref}
12
- bail-label={bailLabel}
13
- dev-center={devCenter}
14
- brand={brand}
15
- empty-state-message={emptyStateMessage}
16
- >
17
- <slot name="sidebar-header" slot="version-picker"></slot>
18
- </dx-sidebar-old>
3
+ <template lwc:if={showOpenSearchSidebar}>
4
+ <dx-sidebar
5
+ class="is-sticky left-nav-bar"
6
+ trees={sidebarContent}
7
+ value={sidebarValue}
8
+ header={sidebarHeader}
9
+ ontogglesidebar={onToggleSidebar}
10
+ languages={languages}
11
+ language={language}
12
+ bail-href={bailHref}
13
+ bail-label={bailLabel}
14
+ dev-center={devCenter}
15
+ brand={brand}
16
+ >
17
+ <slot name="sidebar-header" slot="version-picker"></slot>
18
+ </dx-sidebar>
19
+ </template>
20
+ <template lwc:if={showOldSidebar}>
21
+ <dx-sidebar-old
22
+ class="is-sticky left-nav-bar"
23
+ trees={sidebarContent}
24
+ value={sidebarValue}
25
+ header={sidebarHeader}
26
+ ontogglesidebar={onToggleSidebar}
27
+ languages={languages}
28
+ language={language}
29
+ bail-href={bailHref}
30
+ bail-label={bailLabel}
31
+ dev-center={devCenter}
32
+ brand={brand}
33
+ empty-state-message={emptyStateMessage}
34
+ >
35
+ <slot name="sidebar-header" slot="version-picker"></slot>
36
+ </dx-sidebar-old>
37
+ </template>
19
38
  <div class="content-body-doc-phase-container">
20
39
  <div class="doc-phase-wrapper">
21
40
  <slot name="doc-phase"></slot>
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable @lwc/lwc/no-document-query */
2
+ import { isOpenSearchConfigured } from "dxUtils/openSearch";
2
3
  import { LightningElement, api, createElement, track } from "lwc";
3
4
  import { closest, querySelector } from "kagekiri";
4
5
  import { toJson, normalizeBoolean } from "dxUtils/normalizers";
@@ -78,6 +79,15 @@ export default class ContentLayout extends LightningElement {
78
79
  @api brand: any;
79
80
  @api emptyStateMessage?: string;
80
81
 
82
+ @api
83
+ get enableOpenSearch() {
84
+ return this._enableOpenSearch;
85
+ }
86
+ set enableOpenSearch(value) {
87
+ this._enableOpenSearch = normalizeBoolean(value);
88
+ }
89
+ private _enableOpenSearch = false;
90
+
81
91
  // This is needed for now to prevent failing snapshot tests due to links in the footer
82
92
  @api
83
93
  get showFooter() {
@@ -155,6 +165,20 @@ export default class ContentLayout extends LightningElement {
155
165
  );
156
166
  }
157
167
 
168
+ /** Show the OpenSearch sidebar when enabled, configured, and the old sidebar isn't requested. */
169
+ protected get showOpenSearchSidebar(): boolean {
170
+ return (
171
+ this.enableOpenSearch &&
172
+ !this.useOldSidebar &&
173
+ isOpenSearchConfigured()
174
+ );
175
+ }
176
+
177
+ /** Show the legacy (keyword) sidebar when requested, or when OpenSearch is disabled or not configured. */
178
+ protected get showOldSidebar(): boolean {
179
+ return !this.showOpenSearchSidebar;
180
+ }
181
+
158
182
  @track
159
183
  protected _sidebarContent: unknown;
160
184
 
@@ -366,7 +390,9 @@ export default class ContentLayout extends LightningElement {
366
390
  We have to account for the global nav changing height due to animations.
367
391
  */
368
392
  adjustNavPosition = () => {
369
- const sidebarEl = this.template.querySelector("dx-sidebar-old");
393
+ const sidebarEl =
394
+ this.template.querySelector("dx-sidebar") ||
395
+ this.template.querySelector("dx-sidebar-old");
370
396
  const globalNavEl = document.querySelector(
371
397
  "hgf-c360nav"
372
398
  ) as HTMLElement;
@@ -1,6 +1,7 @@
1
1
  <template>
2
2
  <div class="content">
3
3
  <dx-sidebar-old
4
+ lwc:if={showOldSidebar}
4
5
  class="is-sticky left-nav-bar"
5
6
  trees={sidebarContent}
6
7
  value={sidebarValue}
@@ -15,6 +16,22 @@
15
16
  >
16
17
  <slot name="sidebar-header" slot="version-picker"></slot>
17
18
  </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
+ languages={languages}
27
+ language={language}
28
+ bail-href={bailHref}
29
+ bail-label={bailLabel}
30
+ dev-center={devCenter}
31
+ brand={brand}
32
+ >
33
+ <slot name="sidebar-header" slot="version-picker"></slot>
34
+ </dx-sidebar>
18
35
  <div class="content-body-doc-phase-container">
19
36
  <div class="doc-phase-wrapper">
20
37
  <slot name="doc-phase"></slot>
@@ -1,6 +1,7 @@
1
1
  import { api } from "lwc";
2
2
  import ContentLayout from "doc/contentLayout";
3
3
  import cx from "classnames";
4
+ import { isOpenSearchConfigured } from "dxUtils/openSearch";
4
5
 
5
6
  const TOC_HEADER_TAG = "doc-heading";
6
7
  const RNB_BY_TAB = "docs-tab";
@@ -26,6 +27,14 @@ export default class LwcContentLayout extends ContentLayout {
26
27
  );
27
28
  }
28
29
 
30
+ /**
31
+ * This layout uses the OpenSearch sidebar by default (no enable flag), so it
32
+ * falls back to the old sidebar when requested or when search isn't configured.
33
+ */
34
+ protected get showOldSidebar(): boolean {
35
+ return this.useOldSidebar || !isOpenSearchConfigured();
36
+ }
37
+
29
38
  private setRNBByTab() {
30
39
  const tabPanelListItem = this.getTabPanelList();
31
40
  this.rnbByTab = tabPanelListItem?.id === RNB_BY_TAB;
@@ -3,4 +3,5 @@
3
3
  --doc-c-redoc-sidebar-top: calc(
4
4
  var(--dx-g-global-header-height) + var(--dx-g-doc-header-height)
5
5
  );
6
+ --doc-c-redoc-sidebar-bg: white;
6
7
  }
@@ -4,11 +4,26 @@ import DocPhase from "doc/phase";
4
4
  import DxFooter from "dx/footer";
5
5
  import DxIcon from "dx/icon";
6
6
  import SidebarFooterNav from "dx/sidebarFooterNav";
7
+ import VersionPicker from "dx/versionPicker";
7
8
  import SprigSurvey from "doc/sprigSurvey";
8
9
  import { throttle } from "throttle-debounce";
9
10
  import { pollUntil } from "dxUtils/async";
10
11
  import { toJson } from "dxUtils/normalizers";
11
- import type { OptionWithLink } from "typings/custom";
12
+ import { oldVersionDocInfo } from "docUtils/utils";
13
+ import {
14
+ applyVersionToHref,
15
+ collectSubtreeCanonicalHrefs,
16
+ DOCS_LOCALE_SEGMENT_INDEX,
17
+ DOCS_PATH_SEGMENT,
18
+ normalizePath,
19
+ getTopicVersionKey,
20
+ getVersionPickerOptions,
21
+ persistTopicVersion,
22
+ REFERENCES_LOCALE_SEGMENT_INDEX,
23
+ toCanonicalHref
24
+ } from "dxUtils/topicVersion";
25
+ import type { VersionedNode } from "dxUtils/topicVersion";
26
+ import type { DocPhaseInfo, OptionWithLink } from "typings/custom";
12
27
 
13
28
  declare global {
14
29
  interface Window {
@@ -33,8 +48,20 @@ type ReferenceItem = {
33
48
  topic?: ReferenceTopic;
34
49
  };
35
50
 
51
+ /** A selectable spec version. Mirrors `ReferenceVersion` in `doc/amfReference`. */
52
+ type ReferenceVersion = {
53
+ id: string;
54
+ label: string;
55
+ deprecated?: boolean;
56
+ selected?: boolean;
57
+ link: { href: string };
58
+ };
59
+
36
60
  type ReferenceConfig = {
37
61
  refList: ReferenceItem[];
62
+ versions?: ReferenceVersion[];
63
+ /** Latest switching URL. The sidebar stores the selected version under this key. */
64
+ versionTopicSessionKey?: string;
38
65
  };
39
66
 
40
67
  const SCROLL_THROTTLE_DELAY = 50;
@@ -42,7 +69,7 @@ const ELEMENT_TIMEOUT = 10000;
42
69
  const ELEMENT_CHECK_INTERVAL = 100;
43
70
  const DEFAULT_PROJECT_TITLE = "All Reference";
44
71
  const BACK_TARGET_STORAGE_KEY = "redoc-back-target";
45
- const DOCS_PATH_SEGMENT = "docs";
72
+ const SELECTED_VIEW_STORAGE_KEY = "redoc-selected-view";
46
73
  const DEFAULT_LOCALE = "en-us";
47
74
 
48
75
  export default class RedocReference extends LightningElement {
@@ -80,6 +107,7 @@ export default class RedocReference extends LightningElement {
80
107
  error
81
108
  );
82
109
  }
110
+ this.refreshVersions();
83
111
  }
84
112
 
85
113
  @api
@@ -116,6 +144,32 @@ export default class RedocReference extends LightningElement {
116
144
  */
117
145
  @api headerHref: string | null = null;
118
146
 
147
+ /**
148
+ * Versioned topic that owns this spec, including its children.
149
+ * Href matches this page, so an older version still has its version
150
+ * in the path.
151
+ */
152
+ @api
153
+ set versionedTopicTree(
154
+ value: string | { topics?: VersionedNode[] } | null
155
+ ) {
156
+ try {
157
+ const parsed = toJson(value) as { topics?: VersionedNode[] } | null;
158
+ this._versionedTopicNode = parsed?.topics?.[0] ?? null;
159
+ } catch (error) {
160
+ this._versionedTopicNode = null;
161
+ }
162
+ this.refreshVersions();
163
+ }
164
+
165
+ get versionedTopicTree(): { topics?: VersionedNode[] } | null {
166
+ return this._versionedTopicNode
167
+ ? { topics: [this._versionedTopicNode] }
168
+ : null;
169
+ }
170
+
171
+ private _versionedTopicNode: VersionedNode | null = null;
172
+
119
173
  @api
120
174
  get contentType(): string {
121
175
  return this._contentType;
@@ -152,6 +206,76 @@ export default class RedocReference extends LightningElement {
152
206
  return refCount > 1;
153
207
  }
154
208
 
209
+ private _versions: ReferenceVersion[] = [];
210
+
211
+ get versions(): ReferenceVersion[] {
212
+ return this._versions;
213
+ }
214
+
215
+ /**
216
+ * Picker hrefs for the open page. Both setters call this because LWC can
217
+ * assign referenceConfig and versionedTopicTree in either order. The page
218
+ * URL is already set by then and does not change for this instance.
219
+ */
220
+ private refreshVersions(): void {
221
+ const versions = this._referenceConfig?.versions ?? [];
222
+ const node = this._versionedTopicNode;
223
+ if (!node?.versions?.length || typeof window === "undefined") {
224
+ this._versions = versions;
225
+ return;
226
+ }
227
+
228
+ // Same helper as the markdown sidebar. The same array means this page
229
+ // is outside the topic, so the backend switching URLs stay as authored.
230
+ const rewritten = getVersionPickerOptions(node);
231
+ if (!rewritten || rewritten === node.versions) {
232
+ this._versions = versions;
233
+ return;
234
+ }
235
+
236
+ this._versions = versions.map((version) => {
237
+ const href = rewritten.find((option) => option.id === version.id)
238
+ ?.link?.href;
239
+ if (!href || href === version.link?.href) {
240
+ return version;
241
+ }
242
+ return {
243
+ ...version,
244
+ link: { ...version.link, href }
245
+ };
246
+ });
247
+ }
248
+
249
+ /** The version flagged `selected`, else the first (the latest/GA version). */
250
+ get selectedVersion(): ReferenceVersion | null {
251
+ const versions = this.versions;
252
+ return versions.find((v) => v.selected) ?? versions[0] ?? null;
253
+ }
254
+
255
+ /** True when the selected version is the latest/GA one (index 0). */
256
+ get latestVersion(): boolean {
257
+ return this.versions.length
258
+ ? this.selectedVersion?.id === this.versions[0].id
259
+ : false;
260
+ }
261
+
262
+ get hasVersionPicker(): boolean {
263
+ return this.versions.length > 0;
264
+ }
265
+
266
+ /** "Newer version available" banner info when on a non-latest version, else null. */
267
+ private get oldVersionInfo(): DocPhaseInfo | null {
268
+ if (this.versions.length > 1 && !this.latestVersion) {
269
+ return oldVersionDocInfo(this.versions[0].link.href);
270
+ }
271
+ return null;
272
+ }
273
+
274
+ /** A single version has nothing to choose, so it renders read-only. */
275
+ get isVersionReadOnly(): boolean {
276
+ return this.versions.length === 1;
277
+ }
278
+
155
279
  // Reads stored back target
156
280
  private getBackTargetFromSession(): string | null {
157
281
  return sessionStorage.getItem(BACK_TARGET_STORAGE_KEY);
@@ -186,13 +310,88 @@ export default class RedocReference extends LightningElement {
186
310
  private onBackClick = (event: Event): void => {
187
311
  event.preventDefault();
188
312
 
189
- const target = this.getTranslatedBackTarget() ?? this.headerHref;
313
+ const target = this.getVersionedBackTarget() ?? this.headerHref;
190
314
 
191
315
  if (target) {
192
316
  window.location.assign(target);
193
317
  }
194
318
  };
195
319
 
320
+ /**
321
+ * When the back target is in this spec's topic, return it on the
322
+ * selected version. With no back target, do the same for the header
323
+ * link when that link is the versioned parent.
324
+ */
325
+ private getVersionedBackTarget(): string | null {
326
+ const stored = this.getTranslatedBackTarget();
327
+ const selectedVersion = this.selectedVersion;
328
+ const target = stored ?? this.headerHref;
329
+ if (!target || !selectedVersion) {
330
+ return stored;
331
+ }
332
+
333
+ let targetUrl: URL;
334
+ try {
335
+ targetUrl = new URL(target, window.location.origin);
336
+ } catch {
337
+ return target;
338
+ }
339
+
340
+ // The spec picker links can use a different file name in each version
341
+ // (`sample-api` and `new-sample-api`). That pair cannot move a sibling
342
+ // page between versions. The parent topic's switching URLs share one
343
+ // slug, so the back target is rewritten from those.
344
+ const rewriteVersions = this.backTargetVersions();
345
+ const rewriteVersion =
346
+ rewriteVersions.find(
347
+ (version) => version.id === selectedVersion.id
348
+ ) ?? selectedVersion;
349
+ const familyHrefs = this._versionedTopicNode
350
+ ? collectSubtreeCanonicalHrefs(this._versionedTopicNode).map(
351
+ (href) => toCanonicalHref(href, rewriteVersions)
352
+ )
353
+ : [];
354
+
355
+ const canonicalTarget = toCanonicalHref(
356
+ targetUrl.pathname,
357
+ rewriteVersions
358
+ );
359
+ const inFamily = familyHrefs.some(
360
+ (href) => normalizePath(href) === normalizePath(canonicalTarget)
361
+ );
362
+ if (!inFamily) {
363
+ return target;
364
+ }
365
+
366
+ const versioned = applyVersionToHref(
367
+ canonicalTarget,
368
+ rewriteVersion,
369
+ rewriteVersions
370
+ );
371
+ if (!versioned) {
372
+ return target;
373
+ }
374
+ return `${versioned}${targetUrl.search}${targetUrl.hash}`;
375
+ }
376
+
377
+ /**
378
+ * Version URLs used to move the back target. Prefer the parent topic's
379
+ * switching URLs. Fall back to the spec picker when this spec is the
380
+ * versioned topic itself.
381
+ */
382
+ private backTargetVersions(): ReferenceVersion[] {
383
+ const familyVersions = this._versionedTopicNode?.versions;
384
+ if (!familyVersions?.length) {
385
+ return this.versions;
386
+ }
387
+ return familyVersions.map((version) => ({
388
+ id: version.id,
389
+ label: version.label,
390
+ link: { href: version.link?.href ?? "" },
391
+ selected: version.id === this.selectedVersion?.id
392
+ }));
393
+ }
394
+
196
395
  private getTranslatedBackTarget(): string | null {
197
396
  const stored = this.getBackTargetFromSession();
198
397
  if (stored) {
@@ -202,7 +401,9 @@ export default class RedocReference extends LightningElement {
202
401
  }
203
402
 
204
403
  const referrer = this.getSameOriginReferrerHref();
205
- return referrer && !this.isLocaleHref(new URL(referrer).pathname)
404
+ return referrer &&
405
+ !this.isLocaleHref(new URL(referrer).pathname) &&
406
+ !this.isVersionHref(new URL(referrer).pathname)
206
407
  ? referrer
207
408
  : null;
208
409
  }
@@ -216,7 +417,9 @@ export default class RedocReference extends LightningElement {
216
417
  const segments = url.pathname.split("/").filter(Boolean);
217
418
 
218
419
  // docs -> right after "docs"; references -> after the product segment.
219
- const localeIndex = this.isDocContentType ? 1 : 2;
420
+ const localeIndex = this.isDocContentType
421
+ ? DOCS_LOCALE_SEGMENT_INDEX
422
+ : REFERENCES_LOCALE_SEGMENT_INDEX;
220
423
 
221
424
  if (segments[0] === DOCS_PATH_SEGMENT) {
222
425
  // Drop the existing locale segment, if any
@@ -241,7 +444,10 @@ export default class RedocReference extends LightningElement {
241
444
  }
242
445
 
243
446
  const referrerUrl = new URL(referrerHref);
244
- if (this.isLocaleHref(referrerUrl.pathname)) {
447
+ if (
448
+ this.isLocaleHref(referrerUrl.pathname) ||
449
+ this.isVersionHref(referrerUrl.pathname)
450
+ ) {
245
451
  return;
246
452
  }
247
453
 
@@ -282,6 +488,19 @@ export default class RedocReference extends LightningElement {
282
488
  });
283
489
  }
284
490
 
491
+ /**
492
+ * switching version on this same page.
493
+ */
494
+ private isVersionHref(pathname: string): boolean {
495
+ return this.versions.some((version) => {
496
+ const href = version?.link?.href;
497
+ return (
498
+ !!href &&
499
+ new URL(href, window.location.origin).pathname === pathname
500
+ );
501
+ });
502
+ }
503
+
285
504
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
286
505
  get effectiveFooterOrigin(): string {
287
506
  return (
@@ -297,6 +516,13 @@ export default class RedocReference extends LightningElement {
297
516
  // Track the back target, preserving it across locale switches
298
517
  this.trackBackTarget();
299
518
 
519
+ // Remember the selected version for the sidebar. Changing version
520
+ // reloads this page.
521
+ const topicKey = this.getParentTopicVersionKey();
522
+ if (topicKey && this.selectedVersion) {
523
+ persistTopicVersion(topicKey, this.selectedVersion.id);
524
+ }
525
+
300
526
  window.addEventListener("scroll", this.handleScrollAndResize);
301
527
  window.addEventListener("resize", this.handleScrollAndResize);
302
528
  }
@@ -354,6 +580,14 @@ export default class RedocReference extends LightningElement {
354
580
  return parseInt(value, 10) || 0;
355
581
  }
356
582
 
583
+ /** Redoc's LNB background color, themeable via `--doc-c-redoc-sidebar-bg`. */
584
+ private get sidebarBackgroundColor(): string {
585
+ const value = getComputedStyle(this.template.host).getPropertyValue(
586
+ "--doc-c-redoc-sidebar-bg"
587
+ );
588
+ return value.trim() || "white";
589
+ }
590
+
357
591
  /*
358
592
  ** Since we could not use --dx-g-global-header-height as getPropertyValue returns a calc expression,
359
593
  ** we are using the respective CSS variables to calculate the height.
@@ -469,7 +703,14 @@ export default class RedocReference extends LightningElement {
469
703
  specUrl,
470
704
  {
471
705
  // Dynamic scroll offset to account for headers
472
- scrollYOffset: this.calculateScrollYOffset
706
+ scrollYOffset: this.calculateScrollYOffset,
707
+ // Redoc's own styled background outranks injected
708
+ // CSS, so the LNB background must be set via theme.
709
+ theme: {
710
+ sidebar: {
711
+ backgroundColor: this.sidebarBackgroundColor
712
+ }
713
+ }
473
714
  },
474
715
  redocContainer,
475
716
  (error: any) => {
@@ -515,10 +756,7 @@ export default class RedocReference extends LightningElement {
515
756
  const apiContentDiv = await this.waitForApiContent(redocContainer);
516
757
  apiContentDiv.setAttribute("lwc:dom", "manual");
517
758
 
518
- const docPhaseInfo = this.getDocPhaseInfo();
519
- if (docPhaseInfo) {
520
- this.insertDocPhase(apiContentDiv, docPhaseInfo);
521
- }
759
+ this.insertStatusItems(apiContentDiv);
522
760
 
523
761
  this.appendFooterItems(apiContentDiv);
524
762
 
@@ -527,10 +765,22 @@ export default class RedocReference extends LightningElement {
527
765
 
528
766
  // Wait for footer to be rendered before updating styles
529
767
  requestAnimationFrame(() => {
530
- this.updateRedocThirdColumnStyle(redocContainer);
531
-
532
- // Fix initial hash scroll after doc phase insertion
533
- this.handleInitialHashScrollFix();
768
+ try {
769
+ this.updateRedocThirdColumnStyle(redocContainer);
770
+
771
+ // Restore the view selected before a version switch only
772
+ // after all layout mutations (footer, header) are
773
+ // complete, so the scroll lands on the correct element.
774
+ this.restoreSelectedView();
775
+
776
+ // Fix initial hash scroll after doc phase insertion
777
+ this.handleInitialHashScrollFix();
778
+ } catch (error) {
779
+ this.showErrorUI(
780
+ "Failed to integrate custom components:",
781
+ error
782
+ );
783
+ }
534
784
  });
535
785
  } catch (error) {
536
786
  this.showErrorUI("Failed to integrate custom components:", error);
@@ -560,6 +810,71 @@ export default class RedocReference extends LightningElement {
560
810
  }
561
811
  }
562
812
 
813
+ /** Builds the version picker DOM by reusing `dx-version-picker`. */
814
+ private buildVersionPickerDom(): HTMLElement {
815
+ const wrapper = document.createElement("div");
816
+ wrapper.className = "redoc-version-picker";
817
+
818
+ const picker = createElement("dx-version-picker", {
819
+ is: VersionPicker
820
+ });
821
+
822
+ Object.assign(picker, {
823
+ versions: this.versions,
824
+ selectedVersion: this.selectedVersion,
825
+ latestVersion: this.latestVersion,
826
+ readOnly: this.isVersionReadOnly
827
+ });
828
+ picker.addEventListener("change", this.onVersionChange);
829
+ wrapper.appendChild(picker);
830
+
831
+ return wrapper;
832
+ }
833
+
834
+ /**
835
+ * Key the sidebar uses for this topic's selected version.
836
+ * Missing `versionTopicSessionKey` returns null so nothing is written.
837
+ */
838
+ private getParentTopicVersionKey(): string | null {
839
+ const versionTopicSessionKey =
840
+ this._referenceConfig?.versionTopicSessionKey;
841
+ if (!versionTopicSessionKey) {
842
+ return null;
843
+ }
844
+ return (
845
+ getTopicVersionKey(
846
+ { name: versionTopicSessionKey },
847
+ this.language ?? undefined
848
+ ) || null
849
+ );
850
+ }
851
+
852
+ /** Stashes the current view (URL hash) before the version link navigates. */
853
+ private onVersionChange = (): void => {
854
+ sessionStorage.setItem(
855
+ SELECTED_VIEW_STORAGE_KEY,
856
+ window.location.hash || ""
857
+ );
858
+ };
859
+
860
+ /**
861
+ * Re-applies the view stashed before a version switch, if its anchor exists
862
+ * in the new spec; otherwise a no-op (lands on the spec root).
863
+ */
864
+ private restoreSelectedView(): void {
865
+ const storedHash = sessionStorage.getItem(SELECTED_VIEW_STORAGE_KEY);
866
+ sessionStorage.removeItem(SELECTED_VIEW_STORAGE_KEY);
867
+
868
+ if (!storedHash || window.location.hash) {
869
+ return;
870
+ }
871
+
872
+ const targetId = storedHash.replace(/^#/, "");
873
+ if (targetId && document.getElementById(targetId)) {
874
+ window.location.hash = storedHash;
875
+ }
876
+ }
877
+
563
878
  /**
564
879
  * Builds the locale picker DOM by reusing `dx-sidebar-footer-nav`
565
880
  */
@@ -581,12 +896,17 @@ export default class RedocReference extends LightningElement {
581
896
  }
582
897
 
583
898
  /**
584
- * Builds a fresh project-title/spec-title header DOM node.
899
+ * Builds the doc header: a title group (back link + spec title) and, when
900
+ * versions are available, the version picker as a sibling row. Layout/gaps
901
+ * are styled by the developer-website's redoc CSS.
585
902
  */
586
903
  private buildProjectHeaderDom(): HTMLElement {
587
904
  const wrapper = document.createElement("div");
588
905
  wrapper.className = "redoc-project-header";
589
906
 
907
+ const main = document.createElement("div");
908
+ main.className = "redoc-project-header-main";
909
+
590
910
  if (this.projectTitle) {
591
911
  const backLink = document.createElement("a");
592
912
  backLink.className = "redoc-project-back";
@@ -607,14 +927,20 @@ export default class RedocReference extends LightningElement {
607
927
 
608
928
  backLink.appendChild(icon);
609
929
  backLink.appendChild(label);
610
- wrapper.appendChild(backLink);
930
+ main.appendChild(backLink);
611
931
  }
612
932
 
613
933
  if (this.specTitle) {
614
934
  const specEl = document.createElement("h2");
615
935
  specEl.className = "redoc-spec-title dx-text-display-7";
616
936
  specEl.textContent = this.specTitle;
617
- wrapper.appendChild(specEl);
937
+ main.appendChild(specEl);
938
+ }
939
+
940
+ wrapper.appendChild(main);
941
+
942
+ if (this.hasVersionPicker) {
943
+ wrapper.appendChild(this.buildVersionPickerDom());
618
944
  }
619
945
 
620
946
  return wrapper;
@@ -639,15 +965,40 @@ export default class RedocReference extends LightningElement {
639
965
  return container.querySelector<HTMLElement>(".api-content")!;
640
966
  }
641
967
 
642
- // Creates and inserts doc phase component at container start
643
- private insertDocPhase(container: HTMLElement, docPhaseInfo: string): void {
968
+ // Inserts the doc phase and, on a non-latest version, a dismissible
969
+ // "newer version" banner into a shared doc-phase-wrapper at container start
970
+ private insertStatusItems(container: HTMLElement): void {
971
+ const docPhaseInfo = this.getDocPhaseInfo();
972
+ const oldVersionInfo = this.oldVersionInfo;
973
+ if (!docPhaseInfo && !oldVersionInfo) {
974
+ return;
975
+ }
976
+
644
977
  const wrapper = document.createElement("div");
645
978
  wrapper.className = "doc-phase-wrapper";
646
979
  container.insertBefore(wrapper, container.firstChild);
647
980
 
648
- const docPhaseElement = createElement("doc-phase", { is: DocPhase });
649
- Object.assign(docPhaseElement, { docPhaseInfo });
650
- wrapper.appendChild(docPhaseElement);
981
+ if (docPhaseInfo) {
982
+ const docPhaseElement = createElement("doc-phase", {
983
+ is: DocPhase
984
+ });
985
+ Object.assign(docPhaseElement, { docPhaseInfo });
986
+ wrapper.appendChild(docPhaseElement);
987
+ }
988
+
989
+ if (oldVersionInfo) {
990
+ const versionBanner = createElement("doc-phase", { is: DocPhase });
991
+ Object.assign(versionBanner, {
992
+ docPhaseInfo: oldVersionInfo,
993
+ dismissible: true,
994
+ iconName: "warning"
995
+ });
996
+ versionBanner.addEventListener("dismissphase", () => {
997
+ versionBanner.remove();
998
+ this.updateSidebarPosition();
999
+ });
1000
+ wrapper.appendChild(versionBanner);
1001
+ }
651
1002
  }
652
1003
 
653
1004
  // Appends footer component to container
@@ -1,5 +1,4 @@
1
1
  <template>
2
- <!-- linthtml-disable id-no-dup -->
3
2
  <div class="actions">
4
3
  <a
5
4
  class="fill"
@@ -24,6 +24,14 @@
24
24
  lwc:if={docPhaseInfo}
25
25
  doc-phase-info={docPhaseInfo}
26
26
  ></doc-phase>
27
+ <doc-phase
28
+ slot="version-banner"
29
+ lwc:if={showVersionBanner}
30
+ doc-phase-info={oldVersionInfo}
31
+ icon-name="warning"
32
+ dismissible="true"
33
+ ondismissphase={handleDismissVersionBanner}
34
+ ></doc-phase>
27
35
  <slot></slot>
28
36
  </doc-content-layout>
29
37
  </template>
@@ -1,6 +1,12 @@
1
- import { LightningElement, api } from "lwc";
1
+ import { LightningElement, api, track } from "lwc";
2
2
  import { toJson } from "dxUtils/normalizers";
3
- import type { OptionWithLink, TreeNode } from "typings/custom";
3
+ import type { VersionedNode } from "dxUtils/topicVersion";
4
+ import {
5
+ findTopicVersionForCurrentPage,
6
+ latestHrefForCurrentPage
7
+ } from "dxUtils/topicVersion";
8
+ import { oldVersionDocInfo } from "docUtils/utils";
9
+ import type { DocPhaseInfo, OptionWithLink, TreeNode } from "typings/custom";
4
10
 
5
11
  /**
6
12
  * Per-topic type emitted by the docs content-type parser
@@ -10,61 +16,48 @@ import type { OptionWithLink, TreeNode } from "typings/custom";
10
16
  */
11
17
  const TOPIC_TYPE_SPEC = "spec";
12
18
 
13
- /**
14
- * Walks down the first-child chain and returns the first markdown content
15
- * page found, descending through nested content-less parents. Returns
16
- * undefined if the chain breaks on a spec or external link before reaching a
17
- * content page.
18
- */
19
- function firstChildContentPage(node: TreeNode): TreeNode | undefined {
20
- const firstChild = node.children?.[0];
21
- if (!firstChild) {
22
- return undefined;
23
- }
24
-
25
- const isSpec =
26
- (firstChild as { topicType?: string }).topicType === TOPIC_TYPE_SPEC;
27
- const isExternal = firstChild.link?.target === "_blank";
28
- if (isSpec || isExternal) {
29
- return undefined;
30
- }
31
-
32
- if (firstChild.link?.href) {
33
- return firstChild;
34
- }
35
-
36
- return firstChildContentPage(firstChild);
37
- }
38
-
39
19
  /**
40
20
  * Translates per-topic `topicType` into the generic `showForwardArrow` flag
41
- * that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc),
42
- * and redirects content-less parent topics whose first child is a content page
21
+ * that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc).
22
+ *
23
+ * Content-less parents are flagged with redirectToChild and left without a
24
+ * link. The tree selects the first markdown descendant. Copying that child's
25
+ * href onto the parent makes the parent win selection.
43
26
  */
44
- function decorateTopics(
45
- topics: Array<TreeNode & { topicType?: string }> | undefined
27
+ function decorateTopicsWithForwardArrow(
28
+ topics:
29
+ | Array<TreeNode & { topicType?: string; versions?: unknown }>
30
+ | undefined
46
31
  ): TreeNode[] | undefined {
47
32
  return topics?.map((topic) => {
48
- const { topicType, ...decorated } = topic;
33
+ const { topicType, versions, ...decorated } = topic;
49
34
  if (topicType === TOPIC_TYPE_SPEC) {
50
35
  decorated.showForwardArrow = true;
36
+ // Nested and standalone specs never get a sidebar picker; only the
37
+ // parent MD topic (when versioned) shows one.
38
+ } else if (Array.isArray(versions)) {
39
+ decorated.versions = versions.map(
40
+ (version: { children?: TreeNode[] }) =>
41
+ version.children
42
+ ? {
43
+ ...version,
44
+ children: decorateTopicsWithForwardArrow(
45
+ version.children
46
+ )
47
+ }
48
+ : version
49
+ );
51
50
  }
52
51
  if (decorated.children) {
53
- decorated.children = decorateTopics(decorated.children);
52
+ decorated.children = decorateTopicsWithForwardArrow(
53
+ decorated.children
54
+ );
54
55
  }
55
56
 
56
- /** Redirect a parent that has no content of its own to its first child
57
- * but only when that first child is itself a content page
58
- */
59
- const isContentlessParent =
60
- !!decorated.children?.length && !decorated.link?.href;
61
-
62
- if (isContentlessParent) {
57
+ // Flag a parent with no page of its own. Leave its link empty so the
58
+ // child's URL stays indexed to the child.
59
+ if (!!decorated.children?.length && !decorated.link?.href) {
63
60
  decorated.redirectToChild = true;
64
- const firstChild = firstChildContentPage(topic);
65
- if (firstChild?.link) {
66
- decorated.link = { ...firstChild.link };
67
- }
68
61
  }
69
62
 
70
63
  return decorated;
@@ -101,6 +94,9 @@ export default class UnifiedContentLayout extends LightningElement {
101
94
 
102
95
  private _docPhaseInfo: string | null = null;
103
96
  private _sidebarContent: unknown = null;
97
+ private _oldVersionInfo: DocPhaseInfo | null = null;
98
+
99
+ @track showVersionBanner = false;
104
100
 
105
101
  @api
106
102
  get docPhaseInfo(): string | null {
@@ -117,7 +113,40 @@ export default class UnifiedContentLayout extends LightningElement {
117
113
  }
118
114
 
119
115
  set sidebarContent(value: string) {
120
- this._sidebarContent = decorateTopics(toJson(value)?.topics);
116
+ const topics = decorateTopicsWithForwardArrow(toJson(value)?.topics);
117
+ this._sidebarContent = topics;
118
+ this.updateTopicVersionBanner(topics as VersionedNode[] | undefined);
119
+ }
120
+
121
+ get oldVersionInfo(): DocPhaseInfo | null {
122
+ return this._oldVersionInfo;
123
+ }
124
+
125
+ handleDismissVersionBanner(): void {
126
+ this.showVersionBanner = false;
127
+ }
128
+
129
+ /**
130
+ * Same banner references use when the reader is on an older version.
131
+ * Topic versions are not a separate page property: the sidebar tree
132
+ * carries each version's switching URL, and the current pathname says
133
+ * which one is open.
134
+ */
135
+ private updateTopicVersionBanner(
136
+ topics: VersionedNode[] | undefined
137
+ ): void {
138
+ const match = findTopicVersionForCurrentPage(topics);
139
+ const latest = match?.node.versions?.[0];
140
+ const latestHref = latestHrefForCurrentPage(match?.node.versions);
141
+
142
+ if (match && latest && match.version.id !== latest.id && latestHref) {
143
+ this._oldVersionInfo = oldVersionDocInfo(latestHref);
144
+ this.showVersionBanner = true;
145
+ return;
146
+ }
147
+
148
+ this._oldVersionInfo = null;
149
+ this.showVersionBanner = false;
121
150
  }
122
151
 
123
152
  private get enableFooter(): boolean {
@@ -2,6 +2,7 @@
2
2
  <doc-content-layout
3
3
  lwc:if={displayContent}
4
4
  lwc:ref="docContentLayout"
5
+ enable-open-search
5
6
  sidebar-header={docTitle}
6
7
  sidebar-content={sidebarContent}
7
8
  sidebar-value={sidebarValue}
@@ -24,7 +25,7 @@
24
25
  ondismissphase={handleDismissVersionBanner}
25
26
  ></doc-phase>
26
27
  <div lwc:if={showVersionPicker} slot="sidebar-header">
27
- <doc-version-picker
28
+ <dx-version-picker
28
29
  data-type="version"
29
30
  analytics-event="custEv_linkClick"
30
31
  analytics-payload={ANALYTICS_PAYLOAD}
@@ -32,7 +33,7 @@
32
33
  selected-version={version}
33
34
  latest-version={latestVersion}
34
35
  hide-badge={previewVersion}
35
- ></doc-version-picker>
36
+ ></dx-version-picker>
36
37
  </div>
37
38
  <div class="breadcrumb-row" lwc:if={showBreadcrumbs}>
38
39
  <doc-breadcrumbs
@@ -261,17 +261,6 @@ export default class DocXmlContent extends LightningElementWithState<{
261
261
  return this.pageReference.deliverable;
262
262
  }
263
263
 
264
- private get useOldSidebar(): boolean {
265
- // Coveo is enabled and the version is greater than 51 (within the latest 3 versions)
266
- // TODO: we need a better fix for version number check
267
- return !(
268
- !this.version?.releaseVersion ||
269
- (this.version?.releaseVersion &&
270
- parseInt(this.version.releaseVersion.replace("v", ""), 10) >=
271
- 53)
272
- );
273
- }
274
-
275
264
  private get pageHeader(): Header {
276
265
  if (!this._pageHeader) {
277
266
  this._pageHeader = document.querySelector("doc-header")!;
@@ -1,10 +1,30 @@
1
1
  import { CoveoAnalyticsClient } from "coveo.analytics/dist/browser.mjs"; // This fix is required for Node 20 upgrade, so that Coveo analytics is loaded properly by LWR.
2
2
 
3
+ // Resolve against the current origin (version links are usually relative) and
4
+ // keep only http/https. Blocks executable schemes like javascript:/data: that
5
+ // would run when the innerHTML-rendered link is clicked.
6
+ // The link is already percent-encoded: location.pathname and AMF queries such
7
+ // as type%3A. encodeURI would encode "%" again (%20 -> %2520) and the View
8
+ // Latest href would 404. Escape only the quote that would close the attribute.
9
+ const toSafeHref = (link: string): string => {
10
+ try {
11
+ const { protocol } = new URL(link, window.location.origin);
12
+ if (protocol === "http:" || protocol === "https:") {
13
+ return link.replace(/"/g, "%22");
14
+ }
15
+ } catch {
16
+ // Fall through to the rejection below.
17
+ }
18
+ console.warn(`Blocked unsafe version link: ${link}`);
19
+ return "#";
20
+ };
21
+
3
22
  export const oldVersionDocInfo = (latestVersionLink: string) => {
23
+ const safeLink = toSafeHref(latestVersionLink);
4
24
  return {
5
25
  title: "Newer Version Available",
6
- body: `This content describes an older version of this product.
7
- <a style="font-weight: bold;" href="${latestVersionLink}">View Latest</a>`
26
+ body: `This content describes an older version of this product.
27
+ <a style="font-weight: bold;" href="${safeLink}">View Latest</a>`
8
28
  };
9
29
  };
10
30
 
package/LICENSE DELETED
@@ -1,12 +0,0 @@
1
- Copyright (c) 2020, Salesforce.com, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
-
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
-
10
- * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,64 +0,0 @@
1
- @import "dxHelpers/reset";
2
-
3
- /* NOTE: doc-version-picker-width width variable is used by both dx-button and dx-dropdown to maintain a consistent width. */
4
- :host {
5
- --dx-c-dropdown-option-font-weight: normal;
6
- --dx-c-dropdown-option-label-color: var(--dx-g-gray-10);
7
- --popover-container-open-transform: translateY(4px);
8
- }
9
-
10
- .version-picker-container {
11
- padding: 8px var(--dx-g-spacing-lg) 8px
12
- var(--dx-g-global-header-padding-horizontal);
13
- border-top: 1px solid var(--dx-g-gray-90);
14
- border-bottom: 1px solid var(--dx-g-gray-90);
15
- }
16
-
17
- .version-picker-button {
18
- display: flex;
19
- width: var(--doc-version-picker-width, 296px);
20
- }
21
-
22
- .version-picker-button:hover,
23
- .version-picker-button:active,
24
- .version-picker-button:focus {
25
- --dx-c-button-secondary-color-hover: var(--dx-g-cloud-blue-vibrant-95);
26
- --dx-c-button-primary-color: var(--dx-g-blue-vibrant-40);
27
- }
28
-
29
- /**
30
- * NOTE: This CSS ensures the span inside the button stays within the parent's width, avoiding overflow.
31
- * Not keeping this in common component to ensure that existing functionality works as it is.
32
- */
33
- dx-button::part(content) {
34
- width: inherit;
35
- overflow: hidden;
36
- }
37
-
38
- .selected-version {
39
- display: flex;
40
- flex-direction: row;
41
- align-items: center;
42
- }
43
-
44
- .selected-version-label {
45
- flex: 1;
46
- overflow: hidden;
47
- text-align: left;
48
- text-overflow: ellipsis;
49
- white-space: nowrap;
50
- }
51
-
52
- dx-type-badge.latest-badge {
53
- --dx-c-type-badge-color: var(--dx-g-green-vibrant-40);
54
- --dx-c-type-badge-background: var(--dx-g-green-vibrant-95);
55
-
56
- margin-left: var(--dx-g-spacing-sm);
57
- }
58
-
59
- dx-type-badge.not-latest-badge {
60
- --dx-c-type-badge-color: var(--dx-g-red-vibrant-40);
61
- --dx-c-type-badge-background: var(--dx-g-red-vibrant-95);
62
-
63
- margin-left: var(--dx-g-spacing-sm);
64
- }
@@ -1,40 +0,0 @@
1
- <template>
2
- <div lwc:if={showVersionPicker} class="version-picker-container">
3
- <dx-dropdown
4
- options={versions}
5
- analytics-event="custEv_docVersionSelect"
6
- analytics-payload={analyticsPayload}
7
- value={selectedVersion.id}
8
- width="var(--doc-version-picker-width)"
9
- onchange={onVersionChange}
10
- >
11
- <dx-button
12
- class="version-picker-button"
13
- variant="tertiary"
14
- size="small"
15
- icon-symbol="chevrondown"
16
- icon-size="medium"
17
- >
18
- <div class="selected-version">
19
- <p class="selected-version-label">
20
- {selectedVersion.label}
21
- </p>
22
- <template lwc:if={showLatestTag}>
23
- <dx-type-badge
24
- class="latest-badge"
25
- lwc:if={latestVersion}
26
- value="Latest"
27
- size="small"
28
- ></dx-type-badge>
29
- <dx-type-badge
30
- class="not-latest-badge"
31
- lwc:else
32
- value="Not Latest"
33
- size="small"
34
- ></dx-type-badge>
35
- </template>
36
- </div>
37
- </dx-button>
38
- </dx-dropdown>
39
- </div>
40
- </template>
@@ -1,65 +0,0 @@
1
- import { LightningElement, api, track } from "lwc";
2
-
3
- import { AnalyticsPayload, OptionWithNested } from "typings/custom";
4
-
5
- import { toJson, normalizeBoolean } from "dxUtils/normalizers";
6
-
7
- export default class VersionPicker extends LightningElement {
8
- @api analyticsEvent?: string;
9
- @api analyticsPayload?: AnalyticsPayload;
10
-
11
- @track private _versions!: OptionWithNested[];
12
- private _selectedVersion?: OptionWithNested;
13
- private _latestVersion: boolean = false;
14
- private _hideBadge: boolean = false;
15
-
16
- @api
17
- get versions() {
18
- return this._versions;
19
- }
20
-
21
- set versions(value: OptionWithNested[]) {
22
- this._versions = toJson(value);
23
- }
24
-
25
- @api
26
- get selectedVersion(): OptionWithNested | undefined {
27
- return this._selectedVersion || this.versions[0];
28
- }
29
-
30
- set selectedVersion(value: OptionWithNested) {
31
- if (value) {
32
- this._selectedVersion = toJson(value);
33
- }
34
- }
35
-
36
- @api
37
- get latestVersion() {
38
- return this._latestVersion;
39
- }
40
-
41
- set latestVersion(value) {
42
- this._latestVersion = normalizeBoolean(value);
43
- }
44
-
45
- @api
46
- get hideBadge() {
47
- return this._hideBadge;
48
- }
49
-
50
- set hideBadge(value) {
51
- this._hideBadge = normalizeBoolean(value);
52
- }
53
-
54
- private get showVersionPicker() {
55
- return this._versions && this._versions.length !== 0;
56
- }
57
-
58
- private get showLatestTag(): boolean {
59
- return !this.hideBadge;
60
- }
61
-
62
- private onVersionChange(e: CustomEvent) {
63
- this.dispatchEvent(new CustomEvent("change", { detail: e.detail }));
64
- }
65
- }