@salesforcedevs/docs-components 1.34.4-final-alpha → 1.34.4-ref-alpha

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.34.4-final-alpha",
3
+ "version": "1.34.4-ref-alpha",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -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">
@@ -4,12 +4,24 @@ 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 "doc/versionPicker";
7
+ import VersionPicker from "dx/versionPicker";
8
8
  import SprigSurvey from "doc/sprigSurvey";
9
9
  import { throttle } from "throttle-debounce";
10
10
  import { pollUntil } from "dxUtils/async";
11
11
  import { toJson } from "dxUtils/normalizers";
12
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
+ persistTopicVersion,
21
+ REFERENCES_LOCALE_SEGMENT_INDEX,
22
+ toCanonicalHref
23
+ } from "dxUtils/topicVersion";
24
+ import type { VersionedNode } from "dxUtils/topicVersion";
13
25
  import type { DocPhaseInfo, OptionWithLink } from "typings/custom";
14
26
 
15
27
  declare global {
@@ -47,6 +59,8 @@ type ReferenceVersion = {
47
59
  type ReferenceConfig = {
48
60
  refList: ReferenceItem[];
49
61
  versions?: ReferenceVersion[];
62
+ /** Sidebar topic name. Sidebar stores the selected version under this key. */
63
+ versionTopicKey?: string;
50
64
  };
51
65
 
52
66
  const SCROLL_THROTTLE_DELAY = 50;
@@ -55,7 +69,6 @@ const ELEMENT_CHECK_INTERVAL = 100;
55
69
  const DEFAULT_PROJECT_TITLE = "All Reference";
56
70
  const BACK_TARGET_STORAGE_KEY = "redoc-back-target";
57
71
  const SELECTED_VIEW_STORAGE_KEY = "redoc-selected-view";
58
- const DOCS_PATH_SEGMENT = "docs";
59
72
  const DEFAULT_LOCALE = "en-us";
60
73
 
61
74
  export default class RedocReference extends LightningElement {
@@ -129,6 +142,29 @@ export default class RedocReference extends LightningElement {
129
142
  */
130
143
  @api headerHref: string | null = null;
131
144
 
145
+ /**
146
+ * Versioned topic that owns this spec, including its children.
147
+ * Href matches this page, so an older version still has its version
148
+ * in the path.
149
+ */
150
+ @api
151
+ set parentTopicFamily(value: string | { topics?: VersionedNode[] } | null) {
152
+ try {
153
+ const parsed = toJson(value) as { topics?: VersionedNode[] } | null;
154
+ this._parentTopicFamilyNode = parsed?.topics?.[0] ?? null;
155
+ } catch (error) {
156
+ this._parentTopicFamilyNode = null;
157
+ }
158
+ }
159
+
160
+ get parentTopicFamily(): { topics?: VersionedNode[] } | null {
161
+ return this._parentTopicFamilyNode
162
+ ? { topics: [this._parentTopicFamilyNode] }
163
+ : null;
164
+ }
165
+
166
+ private _parentTopicFamilyNode: VersionedNode | null = null;
167
+
132
168
  @api
133
169
  get contentType(): string {
134
170
  return this._contentType;
@@ -233,13 +269,64 @@ export default class RedocReference extends LightningElement {
233
269
  private onBackClick = (event: Event): void => {
234
270
  event.preventDefault();
235
271
 
236
- const target = this.getTranslatedBackTarget() ?? this.headerHref;
272
+ const target = this.getVersionedBackTarget() ?? this.headerHref;
237
273
 
238
274
  if (target) {
239
275
  window.location.assign(target);
240
276
  }
241
277
  };
242
278
 
279
+ /**
280
+ * When the back target is in this spec's topic, return it on the
281
+ * selected version. With no back target, do the same for the header
282
+ * link when that link is the versioned parent.
283
+ */
284
+ private getVersionedBackTarget(): string | null {
285
+ const stored = this.getTranslatedBackTarget();
286
+ const selectedVersion = this.selectedVersion;
287
+ const target = stored ?? this.headerHref;
288
+ if (!target || !selectedVersion) {
289
+ return stored;
290
+ }
291
+
292
+ let targetUrl: URL;
293
+ try {
294
+ targetUrl = new URL(target, window.location.origin);
295
+ } catch {
296
+ return target;
297
+ }
298
+
299
+ // Family hrefs match this page's version. Compare them without
300
+ // the version segment. Rewrite only the pathname so the target's
301
+ // query and hash survive.
302
+ const familyHrefs = this._parentTopicFamilyNode
303
+ ? collectSubtreeCanonicalHrefs(this._parentTopicFamilyNode).map(
304
+ (href) => toCanonicalHref(href, this.versions)
305
+ )
306
+ : [];
307
+
308
+ const canonicalTarget = toCanonicalHref(
309
+ targetUrl.pathname,
310
+ this.versions
311
+ );
312
+ const inFamily = familyHrefs.some(
313
+ (href) => normalizePath(href) === normalizePath(canonicalTarget)
314
+ );
315
+ if (!inFamily) {
316
+ return target;
317
+ }
318
+
319
+ const versioned = applyVersionToHref(
320
+ canonicalTarget,
321
+ selectedVersion,
322
+ this.versions
323
+ );
324
+ if (!versioned) {
325
+ return target;
326
+ }
327
+ return `${versioned}${targetUrl.search}${targetUrl.hash}`;
328
+ }
329
+
243
330
  private getTranslatedBackTarget(): string | null {
244
331
  const stored = this.getBackTargetFromSession();
245
332
  if (stored) {
@@ -265,7 +352,9 @@ export default class RedocReference extends LightningElement {
265
352
  const segments = url.pathname.split("/").filter(Boolean);
266
353
 
267
354
  // docs -> right after "docs"; references -> after the product segment.
268
- const localeIndex = this.isDocContentType ? 1 : 2;
355
+ const localeIndex = this.isDocContentType
356
+ ? DOCS_LOCALE_SEGMENT_INDEX
357
+ : REFERENCES_LOCALE_SEGMENT_INDEX;
269
358
 
270
359
  if (segments[0] === DOCS_PATH_SEGMENT) {
271
360
  // Drop the existing locale segment, if any
@@ -362,6 +451,13 @@ export default class RedocReference extends LightningElement {
362
451
  // Track the back target, preserving it across locale switches
363
452
  this.trackBackTarget();
364
453
 
454
+ // Remember the selected version for the sidebar. Changing version
455
+ // reloads this page.
456
+ const topicKey = this.getParentTopicVersionKey();
457
+ if (topicKey && this.selectedVersion) {
458
+ persistTopicVersion(topicKey, this.selectedVersion.id);
459
+ }
460
+
365
461
  window.addEventListener("scroll", this.handleScrollAndResize);
366
462
  window.addEventListener("resize", this.handleScrollAndResize);
367
463
  }
@@ -649,12 +745,12 @@ export default class RedocReference extends LightningElement {
649
745
  }
650
746
  }
651
747
 
652
- /** Builds the version picker DOM by reusing `doc-version-picker`. */
748
+ /** Builds the version picker DOM by reusing `dx-version-picker`. */
653
749
  private buildVersionPickerDom(): HTMLElement {
654
750
  const wrapper = document.createElement("div");
655
751
  wrapper.className = "redoc-version-picker";
656
752
 
657
- const picker = createElement("doc-version-picker", {
753
+ const picker = createElement("dx-version-picker", {
658
754
  is: VersionPicker
659
755
  });
660
756
 
@@ -670,6 +766,23 @@ export default class RedocReference extends LightningElement {
670
766
  return wrapper;
671
767
  }
672
768
 
769
+ /**
770
+ * Key the sidebar uses for this topic's selected version.
771
+ * Missing `versionTopicKey` returns null so nothing is written.
772
+ */
773
+ private getParentTopicVersionKey(): string | null {
774
+ const versionTopicKey = this._referenceConfig?.versionTopicKey;
775
+ if (!versionTopicKey) {
776
+ return null;
777
+ }
778
+ return (
779
+ getTopicVersionKey(
780
+ { name: versionTopicKey },
781
+ this.language ?? undefined
782
+ ) || null
783
+ );
784
+ }
785
+
673
786
  /** Stashes the current view (URL hash) before the version link navigates. */
674
787
  private onVersionChange = (): void => {
675
788
  sessionStorage.setItem(
@@ -24,7 +24,7 @@
24
24
  ondismissphase={handleDismissVersionBanner}
25
25
  ></doc-phase>
26
26
  <div lwc:if={showVersionPicker} slot="sidebar-header">
27
- <doc-version-picker
27
+ <dx-version-picker
28
28
  data-type="version"
29
29
  analytics-event="custEv_linkClick"
30
30
  analytics-payload={ANALYTICS_PAYLOAD}
@@ -32,7 +32,7 @@
32
32
  selected-version={version}
33
33
  latest-version={latestVersion}
34
34
  hide-badge={previewVersion}
35
- ></doc-version-picker>
35
+ ></dx-version-picker>
36
36
  </div>
37
37
  <div class="breadcrumb-row" lwc:if={showBreadcrumbs}>
38
38
  <doc-breadcrumbs
@@ -1,251 +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
- /* Always positioned so the popover's containing block stays the picker.
6
- Toggling position with aria-expanded lets the menu jump to the sidebar
7
- (top of the ToC) for a frame before LWC hides it. */
8
- position: relative;
9
-
10
- --dx-c-dropdown-option-font-weight: normal;
11
- --dx-c-dropdown-option-font-size: var(--dx-g-text-base);
12
- --dx-c-dropdown-option-label-color: var(--dx-g-gray-10);
13
- --dx-c-dropdown-option-active-label-color: var(--dx-g-gray-10);
14
- --dx-c-dropdown-option-padding: var(--dx-g-spacing-sm)
15
- var(--dx-g-spacing-lg);
16
- --dx-c-popover-padding: var(--dx-g-spacing-sm) 0;
17
- --popover-container-open-transform: translateY(4px);
18
- --dx-c-version-picker-focus-ring: 0 0 0 2px white,
19
- 0 0 0 4px var(--dx-g-blue-vibrant-60);
20
- }
21
-
22
- /* Open menus must stack above later sibling pickers in the sidebar. */
23
- :host(:has([aria-expanded="true"])) {
24
- z-index: 2;
25
- }
26
-
27
- .version-picker-container {
28
- /* Override --doc-version-picker-padding to change the inset (e.g. when the
29
- picker sits inside an already-padded container). */
30
- padding: var(
31
- --doc-version-picker-padding,
32
- var(--dx-g-spacing-sm) var(--dx-g-spacing-lg) var(--dx-g-spacing-sm)
33
- var(--dx-g-global-header-padding-horizontal)
34
- );
35
-
36
- /* Override --doc-version-picker-divider (e.g. `none`) to restyle dividers. */
37
- border-top: var(
38
- --doc-version-picker-divider,
39
- 1px solid var(--dx-g-gray-90)
40
- );
41
- border-bottom: var(
42
- --doc-version-picker-divider,
43
- 1px solid var(--dx-g-gray-90)
44
- );
45
- }
46
-
47
- /* Inline sidebar variant: drop the header-slot chrome so the picker sits
48
- beside a tree node without extra padding or divider lines. */
49
- .version-picker-container-small {
50
- display: flex;
51
- align-items: center;
52
- padding: 0;
53
- border: none;
54
- }
55
-
56
- .version-picker-button {
57
- display: flex;
58
- width: 100%;
59
- overflow: visible;
60
-
61
- --dx-c-button-horizontal-spacing: var(--dx-g-spacing-sm);
62
- --dx-g-button-icon-color: var(--dx-g-gray-50);
63
- }
64
-
65
- .version-picker-button:hover,
66
- .version-picker-button[aria-expanded="true"] {
67
- --dx-g-button-icon-color: var(--dx-g-blue-vibrant-20);
68
- }
69
-
70
- /**
71
- * NOTE: This CSS ensures the span inside the button stays within the parent's width, avoiding overflow.
72
- * Not keeping this in common component to ensure that existing functionality works as it is.
73
- */
74
- dx-button::part(content) {
75
- width: inherit;
76
- overflow: hidden;
77
- }
78
-
79
- /* Border width stays 1px in every state. Hover, open, and focus paint the
80
- 2px blue stroke with an inset shadow so the box does not grow.
81
- Tertiary's hover border is overridden. */
82
- .version-picker-button::part(container) {
83
- box-sizing: border-box;
84
- background: white;
85
- border: 1px solid var(--dx-g-gray-50);
86
- border-radius: var(--dx-g-spacing-xs);
87
- box-shadow: none;
88
- color: var(--dx-g-gray-10);
89
- outline: none;
90
- transition: var(--dx-g-transition-hue-1x), box-shadow 0.15s linear;
91
- }
92
-
93
- /* Hover only (not open): 2px #032D60 on #EEF4FF, no ring.
94
- Border color matches the fill so the 1px border does not add a third
95
- pixel around the inset stroke.
96
- :focus-visible is included so click-open + Escape (which upgrades the
97
- trigger to keyboard focus) still looks like hover while the pointer is on
98
- the picker. */
99
- .version-picker-button:hover:not([aria-expanded="true"])::part(container),
100
- .version-picker-button:hover:not([aria-expanded="true"])::part(
101
- container
102
- ):focus-visible {
103
- background: var(--dx-g-blue-vibrant-95);
104
- border: 1px solid var(--dx-g-blue-vibrant-95);
105
- box-shadow: inset 0 0 0 2px var(--dx-g-blue-vibrant-20);
106
- }
107
-
108
- /* Open keeps the fill and the 2px stroke. The focus ring is keyboard-only,
109
- on the closed picker below. */
110
- .version-picker-button[aria-expanded="true"]::part(container) {
111
- background: var(--dx-g-blue-vibrant-95);
112
- border: 1px solid var(--dx-g-blue-vibrant-95);
113
- border-radius: var(--dx-g-spacing-xs);
114
- box-shadow: inset 0 0 0 2px var(--dx-g-blue-vibrant-20);
115
- }
116
-
117
- /* Keyboard focus while closed. */
118
- .version-picker-button:not([aria-expanded="true"])::part(
119
- container
120
- ):focus-visible {
121
- --dx-g-button-icon-color: var(--dx-g-blue-vibrant-20);
122
-
123
- background: var(--dx-g-blue-vibrant-95);
124
- border: 1px solid var(--dx-g-blue-vibrant-95);
125
- border-radius: var(--dx-g-spacing-xs);
126
- box-shadow: inset 0 0 0 2px var(--dx-g-blue-vibrant-20),
127
- var(--dx-c-version-picker-focus-ring);
128
- }
129
-
130
- .selected-version {
131
- display: flex;
132
- flex-direction: row;
133
- align-items: center;
134
- }
135
-
136
- .selected-version-label {
137
- flex: 1;
138
- overflow: hidden;
139
- text-align: left;
140
- text-overflow: ellipsis;
141
- white-space: nowrap;
142
- }
143
-
144
- dx-type-badge.latest-badge,
145
- dx-type-badge.not-latest-badge {
146
- margin-left: var(--dx-g-spacing-sm);
147
- }
148
-
149
- /* ------------------------------------------------------------------ *
150
- * Small "dot" variant (opt-in via `small`). Additive
151
- * ------------------------------------------------------------------ */
152
-
153
- /* Menu is capped at the ToC width (296px), not the 104px trigger, so options
154
- keep the same 16px / 8px 24px / gray-10 type as the default picker. */
155
- .version-picker-dropdown-small {
156
- --dx-c-dropdown-option-font-size: var(--dx-g-text-base);
157
- --dx-c-dropdown-option-padding: var(--dx-g-spacing-sm)
158
- var(--dx-g-spacing-lg);
159
- --dx-c-dropdown-option-label-color: var(--dx-g-gray-10);
160
- --dx-c-dropdown-option-border-radius: 0;
161
- --dx-c-popover-border: none;
162
-
163
- /* Hug the labels (down to the shortest) but never wider than the ToC
164
- content: 296px on desktop, and on the smallest breakpoint the sidebar
165
- variable grows with the viewport up to 720px. Long labels wrap inside
166
- that cap. */
167
- --dx-c-dropdown-menu-max-width: var(--doc-version-picker-width, 296px);
168
- --dx-c-dropdown-fit-white-space: normal;
169
- --dx-c-dropdown-fit-overflow: hidden;
170
- --dx-c-dropdown-fit-text-overflow: clip;
171
- --dx-c-dropdown-option-overflow-wrap: anywhere;
172
- }
173
-
174
- .version-picker-button-small {
175
- width: fit-content;
176
- max-width: 104px;
177
-
178
- --dx-c-button-font-size: var(--dx-g-text-xs);
179
- --dx-c-button-font-weight: var(--dx-g-font-normal);
180
- --dx-c-button-line-height: var(--dx-g-spacing-lg);
181
- --dx-c-button-icon-gap: var(--dx-g-spacing-2xs);
182
- }
183
-
184
- /* min-width: 0 on each flex ancestor lets the label truncate: a flex item's
185
- default min-width: auto refuses to shrink below its content and overrides the
186
- host's max-width, so without this the trigger overflows instead. */
187
- .version-picker-button-small::part(content) {
188
- display: flex;
189
- flex: 1;
190
- min-width: 0;
191
- width: auto;
192
- overflow: hidden;
193
- }
194
-
195
- /* width:100% re-ties to the 104px-capped host (container is width:inherit,
196
- which copies width but not max-width). Border/bg/states are shared above. */
197
- .version-picker-button-small::part(container) {
198
- width: 100%;
199
- height: var(--dx-g-spacing-lg);
200
- padding: 0 var(--dx-g-spacing-xs);
201
- }
202
-
203
- .selected-version-small {
204
- flex: 1;
205
- min-width: 0;
206
- }
207
-
208
- .version-picker-dot {
209
- flex: 0 0 auto;
210
- width: var(--dx-g-spacing-sm);
211
- height: var(--dx-g-spacing-sm);
212
- margin-right: var(--dx-g-spacing-xs);
213
- border-radius: 50%;
214
- }
215
-
216
- .version-picker-dot-latest {
217
- background: var(--dx-g-green-vibrant-60);
218
- }
219
-
220
- .version-picker-dot-not-latest {
221
- background: var(--dx-g-yellow-vibrant-80);
222
- }
223
-
224
- /* inline-block (not flex) so the label can truncate; line-height centers it. */
225
- .version-picker-readonly {
226
- box-sizing: border-box;
227
- display: inline-block;
228
- width: 100%;
229
- height: var(--dx-g-spacing-xl);
230
- margin: 0;
231
- padding: 0 var(--dx-g-spacing-sm);
232
- border: 1px solid var(--dx-g-gray-80);
233
- border-radius: var(--dx-g-spacing-xs);
234
- overflow: hidden;
235
- color: var(--dx-g-gray-10);
236
- text-overflow: ellipsis;
237
- white-space: nowrap;
238
- font: var(--dx-g-font-normal) var(--dx-g-text-sm) / var(--dx-g-spacing-xl)
239
- var(--dx-g-font-sans),
240
- sans-serif;
241
- }
242
-
243
- .version-picker-readonly-small {
244
- width: fit-content;
245
- max-width: 104px;
246
- height: var(--dx-g-spacing-lg);
247
- padding: 0 var(--dx-g-spacing-xs);
248
- font: var(--dx-g-font-normal) var(--dx-g-text-xs) / var(--dx-g-spacing-lg)
249
- var(--dx-g-font-sans),
250
- sans-serif;
251
- }
@@ -1,73 +0,0 @@
1
- <template>
2
- <div lwc:if={showVersionPicker} class={containerClass}>
3
- <!-- Small read-only: plain value, no dropdown -->
4
- <p
5
- lwc:if={readOnly}
6
- class={readOnlyClass}
7
- title={selectedVersion.label}
8
- >
9
- {selectedVersion.label}
10
- </p>
11
-
12
- <dx-dropdown
13
- lwc:else
14
- class={dropdownClass}
15
- options={versions}
16
- analytics-event="custEv_docVersionSelect"
17
- analytics-payload={analyticsPayload}
18
- value={selectedVersion.id}
19
- width-mode={dropdownWidthMode}
20
- onchange={onVersionChange}
21
- >
22
- <dx-button
23
- class={triggerClass}
24
- variant="tertiary"
25
- size="small"
26
- font="sans"
27
- icon-symbol="chevrondown"
28
- icon-size={triggerIconSize}
29
- aria-label={triggerAriaLabel}
30
- >
31
- <div class={selectedVersionClass}>
32
- <!-- Small: leading colored dot -->
33
- <template lwc:if={small}>
34
- <template lwc:if={showLatestTag}>
35
- <span class={dotClass} aria-hidden="true"></span>
36
- </template>
37
- <p
38
- class="selected-version-label"
39
- title={selectedVersion.label}
40
- >
41
- {selectedVersion.label}
42
- </p>
43
- </template>
44
- <!-- Default: trailing Latest/Not-Latest badge -->
45
- <template lwc:else>
46
- <p
47
- class="selected-version-label"
48
- title={selectedVersion.label}
49
- >
50
- {selectedVersion.label}
51
- </p>
52
- <template lwc:if={showLatestTag}>
53
- <dx-type-badge
54
- class="latest-badge"
55
- lwc:if={latestVersion}
56
- variant="status-success"
57
- value="Latest"
58
- size="small"
59
- ></dx-type-badge>
60
- <dx-type-badge
61
- class="not-latest-badge"
62
- lwc:else
63
- variant="status-warning"
64
- value="Not Latest"
65
- size="small"
66
- ></dx-type-badge>
67
- </template>
68
- </template>
69
- </div>
70
- </dx-button>
71
- </dx-dropdown>
72
- </div>
73
- </template>
@@ -1,157 +0,0 @@
1
- import { LightningElement, api, track } from "lwc";
2
- import cx from "classnames";
3
-
4
- import { AnalyticsPayload, OptionWithNested } from "typings/custom";
5
-
6
- import { toJson, normalizeBoolean } from "dxUtils/normalizers";
7
-
8
- export default class VersionPicker extends LightningElement {
9
- @api analyticsEvent?: string;
10
- @api analyticsPayload?: AnalyticsPayload;
11
-
12
- @track private _versions!: OptionWithNested[];
13
- private _selectedVersion?: OptionWithNested;
14
- private _latestVersion: boolean = false;
15
- private _hideBadge: boolean = false;
16
- private _small: boolean = false;
17
- private _readOnly: boolean = false;
18
-
19
- @api
20
- get versions() {
21
- return this._versions;
22
- }
23
-
24
- set versions(value: OptionWithNested[]) {
25
- this._versions = toJson(value);
26
- }
27
-
28
- @api
29
- get selectedVersion(): OptionWithNested | undefined {
30
- return this._selectedVersion || this.versions[0];
31
- }
32
-
33
- set selectedVersion(value: OptionWithNested) {
34
- if (value) {
35
- this._selectedVersion = toJson(value);
36
- }
37
- }
38
-
39
- @api
40
- get latestVersion() {
41
- return this._latestVersion;
42
- }
43
-
44
- set latestVersion(value) {
45
- this._latestVersion = normalizeBoolean(value);
46
- }
47
-
48
- @api
49
- get hideBadge() {
50
- return this._hideBadge;
51
- }
52
-
53
- set hideBadge(value) {
54
- this._hideBadge = normalizeBoolean(value);
55
- }
56
-
57
- // Opt-in compact "dot" variant (24px, abbreviated label). Off by default so
58
- // existing consumers render the default trigger unchanged.
59
- @api
60
- get small() {
61
- return this._small;
62
- }
63
-
64
- set small(value) {
65
- this._small = normalizeBoolean(value);
66
- }
67
-
68
- // Opt-in read-only state: plain value, no dropdown menu.
69
- @api
70
- get readOnly() {
71
- return this._readOnly;
72
- }
73
-
74
- set readOnly(value) {
75
- this._readOnly = normalizeBoolean(value);
76
- }
77
-
78
- private get showVersionPicker() {
79
- return this._versions && this._versions.length !== 0;
80
- }
81
-
82
- private get containerClass(): string {
83
- return this.small
84
- ? "version-picker-container-small"
85
- : "version-picker-container";
86
- }
87
-
88
- private get showLatestTag(): boolean {
89
- return !this.hideBadge;
90
- }
91
-
92
- private get readOnlyClass(): string {
93
- return cx(
94
- "version-picker-readonly",
95
- this.small && "version-picker-readonly-small"
96
- );
97
- }
98
-
99
- private get dotClass(): string {
100
- return `version-picker-dot ${
101
- this.latestVersion
102
- ? "version-picker-dot-latest"
103
- : "version-picker-dot-not-latest"
104
- }`;
105
- }
106
-
107
- // Accessible name for the small trigger: includes the latest state so it
108
- // isn't conveyed by the dot's color alone (WCAG 1.4.1). Omits the state
109
- // when the indicator is hidden.
110
- private get smallTriggerAriaLabel(): string {
111
- const label = this.selectedVersion?.label ?? "";
112
- if (!this.showLatestTag) {
113
- return label;
114
- }
115
- return `${label}, ${this.latestVersion ? "Latest" : "Not Latest"}`;
116
- }
117
-
118
- // --- Per-variant values for the shared dropdown/button markup below. The
119
- // small variant opts into extra classes and a compact chevron.
120
-
121
- // Not cx(): the default must have NO class attribute (cx returns "", which
122
- // would render class="" and break the frozen consumer snapshots).
123
- private get dropdownClass(): string | undefined {
124
- return this.small ? "version-picker-dropdown-small" : undefined;
125
- }
126
-
127
- // "full" matches the trigger (ToC width). "fit-end" sizes to the labels,
128
- // caps at the ToC width, and opens inward.
129
- private get dropdownWidthMode(): "full" | "fit-end" {
130
- return this.small ? "fit-end" : "full";
131
- }
132
-
133
- private get triggerClass(): string {
134
- return cx(
135
- "version-picker-button",
136
- this.small && "version-picker-button-small"
137
- );
138
- }
139
-
140
- private get triggerIconSize(): string {
141
- return this.small ? "xsmall" : "medium";
142
- }
143
-
144
- // Default returns "" (dx-button's own default) so the trigger's rendered
145
- // aria-label is unchanged for the default variant.
146
- private get triggerAriaLabel(): string {
147
- return this.small ? this.smallTriggerAriaLabel : "";
148
- }
149
-
150
- private get selectedVersionClass(): string {
151
- return cx("selected-version", this.small && "selected-version-small");
152
- }
153
-
154
- private onVersionChange(e: CustomEvent) {
155
- this.dispatchEvent(new CustomEvent("change", { detail: e.detail }));
156
- }
157
- }