@salesforcedevs/docs-components 1.34.4-topic-alpha.5 → 1.34.5-bug-fix-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,29 +1,29 @@
1
1
  {
2
- "name": "@salesforcedevs/docs-components",
3
- "version": "1.34.4-topic-alpha.5",
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
- }
2
+ "name": "@salesforcedevs/docs-components",
3
+ "version": "1.34.5-bug-fix-alpha",
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">
@@ -16,8 +16,6 @@
16
16
  }
17
17
 
18
18
  .icon {
19
- --dx-c-icon-size: var(--dx-g-icon-size-lg);
20
-
21
19
  flex-shrink: 0;
22
20
  margin-top: var(--dx-g-spacing-smd);
23
21
  margin-right: var(--dx-g-spacing-sm);
@@ -73,6 +71,47 @@
73
71
  cursor: pointer;
74
72
  }
75
73
 
74
+ /* Centered variant: the message is centered in the banner and the icon hangs
75
+ to its left. The close button is taken out of the flow so it doesn't offset
76
+ the centering. */
77
+ .container_centered {
78
+ position: relative;
79
+ display: grid;
80
+ grid-template-columns: 1fr auto 1fr;
81
+ align-items: center;
82
+
83
+ /* Reserve the close button's width plus its right inset on both sides */
84
+ padding: 0
85
+ calc(
86
+ var(--dx-g-spacing-3xl) + var(--dx-g-spacing-xs) +
87
+ var(--doc-banner-padding-right)
88
+ );
89
+ }
90
+
91
+ .container_centered .icon {
92
+ grid-column: 1;
93
+ justify-self: end;
94
+ margin-top: 0;
95
+ }
96
+
97
+ .container_centered .main {
98
+ grid-column: 2;
99
+ align-items: center;
100
+ justify-content: center;
101
+ }
102
+
103
+ .container_centered .message {
104
+ text-align: center;
105
+ }
106
+
107
+ .container_centered .close {
108
+ position: absolute;
109
+ top: 50%;
110
+ right: var(--doc-banner-padding-right);
111
+ margin-left: 0;
112
+ transform: translateY(-50%);
113
+ }
114
+
76
115
  @media (max-width: 1279px) {
77
116
  :host {
78
117
  --doc-banner-padding-left: var(--dx-g-spacing-xl);
@@ -1,16 +1,17 @@
1
1
  <template>
2
2
  <template lwc:if={showBanner}>
3
- <div class="container" part="container">
3
+ <div class={containerClass} part="container">
4
4
  <dx-icon
5
5
  class="icon"
6
- symbol="info"
7
- size="override"
8
- color="gray-50"
6
+ sprite={iconSprite}
7
+ symbol={iconSymbol}
8
+ size={iconSize}
9
+ color={iconColor}
9
10
  part="icon"
10
11
  ></dx-icon>
11
12
  <div class="main">
12
13
  <div class="message" part="message" lwc:dom="manual"></div>
13
- <div class="actions" part="actions">
14
+ <div lwc:if={hasActions} class="actions" part="actions">
14
15
  <template lwc:if={hasPrimaryButton}>
15
16
  <dx-button
16
17
  href={buttonHref}
@@ -1,4 +1,6 @@
1
1
  import { LightningElement, api } from "lwc";
2
+ import { IconSize, IconSprite, IconSymbol } from "typings/custom";
3
+ import { normalizeBoolean } from "dxUtils/normalizers";
2
4
 
3
5
  const BANNER_STORAGE_PREFIX = "doc-banner-";
4
6
 
@@ -13,6 +15,24 @@ export default class Banner extends LightningElement {
13
15
 
14
16
  @api dismissStorageKey = "";
15
17
 
18
+ @api
19
+ get centered(): boolean {
20
+ return this._centered;
21
+ }
22
+ set centered(value: boolean | string) {
23
+ this._centered = normalizeBoolean(value);
24
+ }
25
+
26
+ @api iconSprite: IconSprite = "utility";
27
+
28
+ @api iconSymbol: IconSymbol = "info";
29
+
30
+ @api iconColor = "gray-50";
31
+
32
+ @api iconSize: IconSize = "large";
33
+
34
+ private _centered = false;
35
+
16
36
  private _dismissed = false;
17
37
 
18
38
  connectedCallback() {
@@ -33,10 +53,18 @@ export default class Banner extends LightningElement {
33
53
  }
34
54
  }
35
55
 
56
+ get containerClass(): string {
57
+ return this._centered ? "container container_centered" : "container";
58
+ }
59
+
36
60
  get showBanner(): boolean {
37
61
  return !this._dismissed;
38
62
  }
39
63
 
64
+ get hasActions(): boolean {
65
+ return this.hasPrimaryButton || this.hasSecondaryAction;
66
+ }
67
+
40
68
  get hasPrimaryButton(): boolean {
41
69
  return !!(this.buttonLabel && this.buttonHref);
42
70
  }
@@ -21,7 +21,6 @@ nav {
21
21
 
22
22
  dx-dropdown {
23
23
  --dx-c-dropdown-option-font-size: var(--dx-g-text-sm);
24
- --dx-c-dropdown-option-font-weight: var(--dx-g-font-bold);
25
24
  --dx-c-dropdown-option-label-color: var(
26
25
  --dx-c-breadcrumbs-breadcrumb-color
27
26
  );
@@ -127,26 +127,26 @@ export default class ContentActionToolbar extends LightningElement {
127
127
  {
128
128
  id: ACTION_COPY_MARKDOWN,
129
129
  label: COPY_MARKDOWN_LABEL,
130
- endIconSprite: "utility",
131
- endIconSymbol: "copy"
130
+ iconSprite: "utility",
131
+ iconSymbol: "copy"
132
132
  },
133
133
  {
134
134
  id: ACTION_VIEW_MARKDOWN,
135
135
  label: VIEW_MARKDOWN_LABEL,
136
- endIconSprite: "utility",
137
- endIconSymbol: "new_window"
136
+ iconSprite: "utility",
137
+ iconSymbol: "new_window"
138
138
  },
139
139
  {
140
140
  id: ACTION_COPY_MARKDOWN_URL,
141
141
  label: COPY_MARKDOWN_URL_LABEL,
142
- endIconSprite: "utility",
143
- endIconSymbol: "link"
142
+ iconSprite: "utility",
143
+ iconSymbol: "link"
144
144
  },
145
145
  ...AI_ASSISTANTS.map(({ action, label }) => ({
146
146
  id: action,
147
147
  label,
148
- endIconSprite: "utility",
149
- endIconSymbol: "new_window"
148
+ iconSprite: "utility",
149
+ iconSymbol: "new_window"
150
150
  }))
151
151
  ]
152
152
  });
@@ -159,14 +159,14 @@ export default class ContentActionToolbar extends LightningElement {
159
159
  {
160
160
  id: ACTION_VIEW_LLMS,
161
161
  label: VIEW_LLMS_LABEL,
162
- endIconSprite: "utility",
163
- endIconSymbol: "new_window"
162
+ iconSprite: "utility",
163
+ iconSymbol: "new_window"
164
164
  },
165
165
  {
166
166
  id: ACTION_COPY_LLMS_URL,
167
167
  label: COPY_LLMS_URL_LABEL,
168
- endIconSprite: "utility",
169
- endIconSymbol: "link"
168
+ iconSprite: "utility",
169
+ iconSymbol: "link"
170
170
  }
171
171
  ]
172
172
  });
@@ -5,6 +5,7 @@ import { HeaderBase } from "dxBaseElements/headerBase";
5
5
  import { toJson, normalizeBoolean } from "dxUtils/normalizers";
6
6
  import { track } from "dxUtils/analytics";
7
7
 
8
+ const TABLET_MATCH = "980px";
8
9
  const MOBILE_MATCH = "768px";
9
10
 
10
11
  const isStorybook = () => {
@@ -46,6 +47,8 @@ export default class Header extends HeaderBase {
46
47
  }
47
48
 
48
49
  private _scopedNavItems!: OptionWithNested[];
50
+ private tablet = false;
51
+ private tabletMatchMedia!: MediaQueryList;
49
52
  private shouldRender: boolean = false;
50
53
  private showDocDivider: boolean = false;
51
54
  private _devCenter!: DevCenterConfig;
@@ -80,6 +83,11 @@ export default class Header extends HeaderBase {
80
83
 
81
84
  connectedCallback(): void {
82
85
  super.connectedCallback();
86
+ this.tabletMatchMedia = window.matchMedia(
87
+ `(max-width: ${TABLET_MATCH})`
88
+ );
89
+ this.onTabletChange(this.tabletMatchMedia);
90
+ this.tabletMatchMedia.addEventListener("change", this.onTabletChange);
83
91
 
84
92
  if (
85
93
  (!this.shouldHideHeader && this.isDocsPath) ||
@@ -98,12 +106,23 @@ export default class Header extends HeaderBase {
98
106
  }
99
107
  }
100
108
 
109
+ disconnectedCallback(): void {
110
+ super.disconnectedCallback();
111
+ this.tabletMatchMedia.removeEventListener(
112
+ "change",
113
+ this.onTabletChange
114
+ );
115
+ }
116
+
101
117
  renderedCallback(): void {
102
118
  if (this.hideDocHeader) {
103
119
  this.shouldRender = !this.shouldHideHeader && this.isDocsPath;
104
120
  }
105
121
  }
106
122
 
123
+ private onTabletChange = (e: MediaQueryListEvent | MediaQueryList) =>
124
+ (this.tablet = e.matches);
125
+
107
126
  protected additionalClasses(): string {
108
127
  return cx(
109
128
  this.brand && "has-brand",
@@ -8,7 +8,7 @@
8
8
  }
9
9
 
10
10
  dx-sidebar {
11
- --dx-c-sidebar-content-width: unset;
11
+ --dx-c-sidebar-width: unset;
12
12
 
13
13
  display: block;
14
14
  }
@@ -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(
@@ -16,36 +16,13 @@ import type { DocPhaseInfo, OptionWithLink, TreeNode } from "typings/custom";
16
16
  */
17
17
  const TOPIC_TYPE_SPEC = "spec";
18
18
 
19
- /**
20
- * Walks down the first-child chain and returns the first markdown content
21
- * page found, descending through nested content-less parents. Returns
22
- * undefined if the chain breaks on a spec or external link before reaching a
23
- * content page.
24
- */
25
- function firstChildContentPage(node: TreeNode): TreeNode | undefined {
26
- const firstChild = node.children?.[0];
27
- if (!firstChild) {
28
- return undefined;
29
- }
30
-
31
- const isSpec =
32
- (firstChild as { topicType?: string }).topicType === TOPIC_TYPE_SPEC;
33
- const isExternal = firstChild.link?.target === "_blank";
34
- if (isSpec || isExternal) {
35
- return undefined;
36
- }
37
-
38
- if (firstChild.link?.href) {
39
- return firstChild;
40
- }
41
-
42
- return firstChildContentPage(firstChild);
43
- }
44
-
45
19
  /**
46
20
  * Translates per-topic `topicType` into the generic `showForwardArrow` flag
47
- * that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc),
48
- * 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.
49
26
  */
50
27
  function decorateTopicsWithForwardArrow(
51
28
  topics:
@@ -58,8 +35,18 @@ function decorateTopicsWithForwardArrow(
58
35
  decorated.showForwardArrow = true;
59
36
  // Nested and standalone specs never get a sidebar picker; only the
60
37
  // parent MD topic (when versioned) shows one.
61
- } else if (versions) {
62
- decorated.versions = versions;
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
+ );
63
50
  }
64
51
  if (decorated.children) {
65
52
  decorated.children = decorateTopicsWithForwardArrow(
@@ -67,18 +54,10 @@ function decorateTopicsWithForwardArrow(
67
54
  );
68
55
  }
69
56
 
70
- /** Redirect a parent that has no content of its own to its first child
71
- * but only when that first child is itself a content page
72
- */
73
- const isContentlessParent =
74
- !!decorated.children?.length && !decorated.link?.href;
75
-
76
- 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) {
77
60
  decorated.redirectToChild = true;
78
- const firstChild = firstChildContentPage(topic);
79
- if (firstChild?.link) {
80
- decorated.link = { ...firstChild.link };
81
- }
82
61
  }
83
62
 
84
63
  return decorated;
@@ -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
@@ -23,6 +23,9 @@ export interface SearchResult {
23
23
  // and existing fixtures still satisfy the type.
24
24
  snippet?: string | null;
25
25
  snippetSource?: SnippetSource;
26
+ // `url` plus `#anchor` of the page section that matched, or null/absent
27
+ // when the matched chunk has no anchor. Link to it via resultHref().
28
+ sectionUrl?: string | null;
26
29
  }
27
30
 
28
31
  export interface FacetBucket {
@@ -208,6 +211,19 @@ export function sanitizeSnippetHtml(value: unknown): string {
208
211
  * text path. So for anything but a headline we return `null` and let the
209
212
  * caller keep today's text rendering.
210
213
  */
214
+ /**
215
+ * Where a result's title should link: the matched section when the backend
216
+ * returned one, else the page. The section link is only trusted when it is the
217
+ * page URL plus a fragment, so a malformed value can never send the user
218
+ * somewhere else.
219
+ */
220
+ export function resultHref(result: SearchResult): string {
221
+ const { url, sectionUrl } = result;
222
+ return typeof sectionUrl === "string" && sectionUrl.startsWith(`${url}#`)
223
+ ? sectionUrl
224
+ : url;
225
+ }
226
+
211
227
  export function highlightedSnippetHtml(result: SearchResult): string | null {
212
228
  if (result.snippetSource !== "headline") {
213
229
  return null;
@@ -1,194 +0,0 @@
1
- @import "dxHelpers/reset";
2
-
3
- /* The large picker fills its row (the sidebar sets the row padding). The small
4
- menu stops at --doc-version-picker-width, which the sidebar sets. */
5
- :host {
6
- display: block;
7
-
8
- /* Menu labels wrap; break long unspaced labels instead of overflowing. */
9
- --dx-c-dropdown-option-overflow-wrap: anywhere;
10
- --popover-container-open-transform: translateY(4px);
11
- }
12
-
13
- /* Open menus must stack above later sibling pickers in the sidebar. */
14
- :host(:has([aria-expanded="true"])) {
15
- position: relative;
16
- z-index: 2;
17
- }
18
-
19
- .version-picker-container {
20
- /* Override --doc-version-picker-padding to change the inset (e.g. when the
21
- picker sits inside an already-padded container). */
22
- padding: var(
23
- --doc-version-picker-padding,
24
- var(--dx-g-spacing-sm) var(--dx-g-spacing-lg) var(--dx-g-spacing-sm)
25
- var(--dx-g-global-header-padding-horizontal)
26
- );
27
-
28
- /* Override --doc-version-picker-divider (e.g. `none`) to restyle dividers. */
29
- border-top: var(
30
- --doc-version-picker-divider,
31
- 1px solid var(--dx-g-gray-90)
32
- );
33
- border-bottom: var(
34
- --doc-version-picker-divider,
35
- 1px solid var(--dx-g-gray-90)
36
- );
37
- }
38
-
39
- /* Inline sidebar variant: drop the header-slot chrome so the picker sits
40
- beside a tree node without extra padding or divider lines. */
41
- .version-picker-container-small {
42
- display: flex;
43
- align-items: center;
44
- padding: 0;
45
- border: none;
46
- }
47
-
48
- .version-picker-button {
49
- display: flex;
50
- width: 100%;
51
-
52
- --dx-c-button-horizontal-spacing: var(--dx-g-spacing-sm);
53
- --dx-c-button-icon-color: var(--dx-g-gray-50);
54
-
55
- /* A real 1px border at rest. Hover and the open menu turn it dark blue and
56
- add a 1px inset shadow, so the edge looks 2px without resizing. */
57
- --dx-c-button-custom-color: var(--dx-g-gray-10);
58
- --dx-c-button-custom-color-hover: var(--dx-g-gray-10);
59
- --dx-c-button-custom-background: white;
60
- --dx-c-button-custom-background-hover: var(--dx-g-blue-vibrant-95);
61
- --dx-c-button-custom-border: var(--dx-g-gray-50);
62
- --dx-c-button-custom-border-hover: var(--dx-g-blue-vibrant-20);
63
- --dx-c-button-custom-border-shadow-hover: inset 0 0 0 1px
64
- var(--dx-g-blue-vibrant-20);
65
-
66
- /* Keyboard focus keeps the 2px edge inside the white band. */
67
- --dx-c-button-focus-shadow: inset 0 0 0 1px var(--dx-g-blue-vibrant-20),
68
- 0 0 0 2px white;
69
- }
70
-
71
- .version-picker-button:hover,
72
- .version-picker-button:focus-within,
73
- .version-picker-button[aria-expanded="true"] {
74
- --dx-c-button-icon-color: var(--dx-g-blue-vibrant-20);
75
- }
76
-
77
- /**
78
- * NOTE: This CSS ensures the span inside the button stays within the parent's width, avoiding overflow.
79
- * Not keeping this in common component to ensure that existing functionality works as it is.
80
- */
81
- dx-button::part(content) {
82
- width: inherit;
83
- overflow: hidden;
84
- }
85
-
86
- .selected-version {
87
- display: flex;
88
- flex-direction: row;
89
- align-items: center;
90
- }
91
-
92
- .selected-version-label {
93
- flex: 1;
94
- overflow: hidden;
95
- text-align: left;
96
- text-overflow: ellipsis;
97
- white-space: nowrap;
98
- }
99
-
100
- dx-type-badge.latest-badge,
101
- dx-type-badge.not-latest-badge {
102
- margin-left: var(--dx-g-spacing-sm);
103
- }
104
-
105
- /* ------------------------------------------------------------------ *
106
- * Small "dot" variant (opt-in via `small`). Additive
107
- * ------------------------------------------------------------------ */
108
-
109
- /* The small menu hugs its longest label but never grows wider than the sidebar
110
- content (--doc-version-picker-width, set by the sidebar). Labels wrap only at
111
- that width. The large menu always matches its trigger (width-mode="full"). */
112
- .version-picker-dropdown-small {
113
- --dx-c-dropdown-menu-max-width: var(--doc-version-picker-width, 296px);
114
- }
115
-
116
- .version-picker-button-small {
117
- width: fit-content;
118
- max-width: 104px;
119
-
120
- --dx-c-button-font-size: var(--dx-g-text-xs);
121
- --dx-c-button-font-weight: var(--dx-g-font-normal);
122
- --dx-c-button-line-height: var(--dx-g-spacing-lg);
123
- --dx-c-button-icon-gap: var(--dx-g-spacing-2xs);
124
- }
125
-
126
- /* min-width: 0 on each flex ancestor lets the label truncate: a flex item's
127
- default min-width: auto refuses to shrink below its content and overrides the
128
- host's max-width, so without this the trigger overflows instead. */
129
- .version-picker-button-small::part(content) {
130
- display: flex;
131
- flex: 1;
132
- min-width: 0;
133
- width: auto;
134
- overflow: hidden;
135
- }
136
-
137
- /* width:100% re-ties to the 104px-capped host (container is width:inherit,
138
- which copies width but not max-width). Border, fill, and states come from the
139
- dx-button hooks on .version-picker-button. */
140
- .version-picker-button-small::part(container) {
141
- width: 100%;
142
- height: var(--dx-g-spacing-lg);
143
- padding: 0 var(--dx-g-spacing-xs);
144
- }
145
-
146
- .selected-version-small {
147
- flex: 1;
148
- min-width: 0;
149
- }
150
-
151
- .version-picker-dot {
152
- flex: 0 0 auto;
153
- width: var(--dx-g-spacing-sm);
154
- height: var(--dx-g-spacing-sm);
155
- margin-right: var(--dx-g-spacing-xs);
156
- border-radius: 50%;
157
- }
158
-
159
- .version-picker-dot-latest {
160
- background: var(--dx-g-green-vibrant-60);
161
- }
162
-
163
- .version-picker-dot-not-latest {
164
- background: var(--dx-g-yellow-vibrant-80);
165
- }
166
-
167
- /* inline-block (not flex) so the label can truncate; line-height centers it. */
168
- .version-picker-readonly {
169
- box-sizing: border-box;
170
- display: inline-block;
171
- width: 100%;
172
- height: var(--dx-g-spacing-xl);
173
- margin: 0;
174
- padding: 0 var(--dx-g-spacing-sm);
175
- border: 1px solid var(--dx-g-gray-80);
176
- border-radius: var(--dx-g-spacing-xs);
177
- overflow: hidden;
178
- color: var(--dx-g-gray-10);
179
- text-overflow: ellipsis;
180
- white-space: nowrap;
181
- font: var(--dx-g-font-normal) var(--dx-g-text-sm) / var(--dx-g-spacing-xl)
182
- var(--dx-g-font-sans),
183
- sans-serif;
184
- }
185
-
186
- .version-picker-readonly-small {
187
- width: fit-content;
188
- max-width: 104px;
189
- height: var(--dx-g-spacing-lg);
190
- padding: 0 var(--dx-g-spacing-xs);
191
- font: var(--dx-g-font-normal) var(--dx-g-text-xs) / var(--dx-g-spacing-lg)
192
- var(--dx-g-font-sans),
193
- sans-serif;
194
- }
@@ -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="custom"
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
- }