@salesforcedevs/docs-components 1.33.2-llms-txt-3 → 1.34.0-docs-feedback

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
@@ -18,6 +18,7 @@
18
18
  "doc/contentMedia",
19
19
  "doc/docXmlContent",
20
20
  "doc/lwcContentLayout",
21
+ "doc/unifiedContentLayout",
21
22
  "doc/header",
22
23
  "doc/heading",
23
24
  "doc/headingAnchor",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.33.2-llms-txt-3",
3
+ "version": "1.34.0-docs-feedback",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -26,5 +26,5 @@
26
26
  "@types/lodash.uniqby": "4.7.9"
27
27
  },
28
28
  "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
29
- "stableVersion": "1.33.1"
29
+ "stableVersion": "1.34.0"
30
30
  }
@@ -1,24 +1,32 @@
1
1
  @import "dxHelpers/reset";
2
2
 
3
3
  :host {
4
- /* Match the Figma menu rows: Body 2 Regular, gray-10 (the dropdown option
5
- default is bold + blue), with 24px (spacing-lg) horizontal padding on
6
- both option rows and subheaders. These custom properties inherit through
7
- the composed tree down to each dx-dropdown-option. */
8
- --dx-c-dropdown-option-label-color: var(--dx-g-gray-10);
9
- --dx-c-dropdown-option-font-weight: var(--dx-g-font-normal);
10
- --dx-c-dropdown-option-padding-horizontal: var(--dx-g-spacing-lg);
4
+ display: block;
5
+ }
11
6
 
12
- /* Popover only needs 8px vertical padding; horizontal is 0 since the
13
- options already carry 24px each side. Inherits down to the dropdown's
14
- dx-popover. */
15
- --dx-c-popover-padding: var(--dx-g-spacing-sm) 0;
7
+ .toolbar {
8
+ display: flex;
9
+ align-items: center;
10
+ flex-wrap: wrap;
11
+ gap: var(--dx-g-spacing-smd);
12
+ margin-bottom: var(--dx-g-spacing-lg);
13
+ }
16
14
 
17
- /* Size the menu to its widest option instead of the default fixed 168px,
18
- so labels like "Copy as Markdown" aren't clipped or awkwardly narrow.
19
- Inherits down to the dropdown's dx-popover. */
20
- --dx-c-popover-width: max-content;
15
+ .toolbar-button {
16
+ --dx-c-button-font-weight: var(--dx-g-font-demi);
17
+ --dx-c-button-line-height: var(--dx-g-spacing-mlg);
18
+ --dx-c-button-letter-spacing: 0.005em;
19
+ }
21
20
 
22
- display: inline-flex;
23
- margin-bottom: var(--dx-g-spacing-lg);
21
+ .divider {
22
+ width: 1px;
23
+ height: var(--dx-g-spacing-md);
24
+ background-color: var(--dx-g-gray-70);
25
+ }
26
+
27
+ @media screen and (max-width: 480px) {
28
+ .toolbar-button_copy-url,
29
+ .divider_copy-url {
30
+ display: none;
31
+ }
24
32
  }
@@ -1,16 +1,53 @@
1
1
  <template>
2
- <dx-split-button
3
- lwc:if={markdownUrl}
4
- label="Copy as Markdown"
5
- action-tooltip={actionTooltip}
6
- icon-symbol="copy"
7
- icon-position="right"
8
- variant="secondary"
9
- size="small"
10
- menu-aria-label="More content actions"
11
- options={options}
12
- stay-open-after-change
13
- onactionclick={handleCopyMarkdown}
14
- onselect={handleMenuSelect}
15
- ></dx-split-button>
2
+ <div class="toolbar" lwc:if={markdownUrl}>
3
+ <dx-tooltip placement="top-right" label={copyMarkdownLabel}>
4
+ <dx-button
5
+ class="toolbar-button"
6
+ variant="inline"
7
+ size="small"
8
+ icon-sprite="utility"
9
+ icon-symbol="copy"
10
+ icon-size="medium"
11
+ icon-position="right"
12
+ aria-label={copyMarkdownButtonText}
13
+ onclick={handleCopyMarkdown}
14
+ >
15
+ {copyMarkdownButtonText}
16
+ </dx-button>
17
+ </dx-tooltip>
18
+
19
+ <div class="divider"></div>
20
+
21
+ <dx-button
22
+ class="toolbar-button"
23
+ variant="inline"
24
+ size="small"
25
+ icon-sprite="utility"
26
+ icon-symbol="new_window"
27
+ icon-size="medium"
28
+ icon-position="right"
29
+ aria-label={viewMarkdownButtonText}
30
+ onclick={handleViewMarkdown}
31
+ >
32
+ {viewMarkdownButtonText}
33
+ </dx-button>
34
+
35
+ <div class="divider divider_copy-url"></div>
36
+
37
+ <dx-tooltip placement="top-right" label={copyUrlLabel}>
38
+ <dx-button
39
+ class="toolbar-button toolbar-button_copy-url"
40
+ variant="inline"
41
+ size="small"
42
+ icon-sprite="utility"
43
+ icon-symbol="link"
44
+ icon-size="medium"
45
+ icon-position="right"
46
+ aria-label={copyUrlButtonText}
47
+ onclick={handleCopyUrl}
48
+ >
49
+ {copyUrlButtonText}
50
+ </dx-button>
51
+ </dx-tooltip>
52
+ </div>
16
53
  </template>
@@ -1,5 +1,4 @@
1
1
  import { LightningElement, api } from "lwc";
2
- import { OptionWithNested } from "typings/custom";
3
2
  import { track } from "dxUtils/analytics";
4
3
 
5
4
  const DEFAULT_COPY_TOOLTIP_LABEL = "Click to copy";
@@ -10,22 +9,6 @@ const ANALYTICS_CONTENT_CATEGORY = "content action toolbar";
10
9
  const COPY_MARKDOWN_LABEL = "Copy as Markdown";
11
10
  const VIEW_MARKDOWN_LABEL = "View as Markdown";
12
11
  const COPY_URL_LABEL = "Copy URL to Markdown";
13
- const VIEW_LLMS_LABEL = "View llms.txt";
14
- const COPY_LLMS_URL_LABEL = "Copy URL to llms.txt";
15
-
16
- // Option ids for the split-button menu; used to route `select` events.
17
- const OPTION_COPY_MARKDOWN = "copy-markdown";
18
- const OPTION_VIEW_MARKDOWN = "view-markdown";
19
- const OPTION_COPY_MARKDOWN_URL = "copy-markdown-url";
20
- const OPTION_VIEW_LLMS = "view-llms";
21
- const OPTION_COPY_LLMS_URL = "copy-llms-url";
22
-
23
- type ToolbarCtaLabel =
24
- | typeof COPY_MARKDOWN_LABEL
25
- | typeof VIEW_MARKDOWN_LABEL
26
- | typeof COPY_URL_LABEL
27
- | typeof VIEW_LLMS_LABEL
28
- | typeof COPY_LLMS_URL_LABEL;
29
12
 
30
13
  export default class ContentActionToolbar extends LightningElement {
31
14
  @api
@@ -40,9 +23,8 @@ export default class ContentActionToolbar extends LightningElement {
40
23
  }
41
24
  private _pageUrl?: string;
42
25
 
43
- // Id of the copy option currently flashing "Copied!" (null = none). Drives
44
- // the per-option tooltip label; reassigning it re-renders `options`.
45
- private copiedOptionId: string | null = null;
26
+ copyMarkdownLabel: string = DEFAULT_COPY_TOOLTIP_LABEL;
27
+ copyUrlLabel: string = DEFAULT_COPY_TOOLTIP_LABEL;
46
28
 
47
29
  private copyTooltipResetTimeout: number | null = null;
48
30
 
@@ -68,107 +50,16 @@ export default class ContentActionToolbar extends LightningElement {
68
50
  return url.toString();
69
51
  }
70
52
 
71
- /**
72
- * Site-root llms.txt file (same for every page), e.g.
73
- * `https://example.com/llms.txt`.
74
- */
75
- get llmsTxtUrl(): string {
76
- return new URL("/docs/llms.txt", window.location.origin).toString();
53
+ get copyMarkdownButtonText(): string {
54
+ return COPY_MARKDOWN_LABEL;
77
55
  }
78
56
 
79
- // Hardcoded menu preset rendered by dx-split-button, grouped under bold
80
- // subheaders with a divider between "This Page" and "All Documentation".
81
- // Copy options carry a tooltip that flashes "Copied!" after a copy.
82
- get options(): OptionWithNested[] {
83
- return [
84
- { id: "this-page", label: "This Page", subheader: true },
85
- {
86
- id: OPTION_COPY_MARKDOWN,
87
- label: COPY_MARKDOWN_LABEL,
88
- tooltip: this.copyTooltipFor(OPTION_COPY_MARKDOWN),
89
- rightIconData: {
90
- iconSymbol: "copy",
91
- iconSprite: "utility",
92
- iconColor: "gray-50"
93
- }
94
- },
95
- {
96
- id: OPTION_VIEW_MARKDOWN,
97
- label: VIEW_MARKDOWN_LABEL,
98
- rightIconData: {
99
- iconSymbol: "new_window",
100
- iconSprite: "utility",
101
- iconColor: "gray-50"
102
- }
103
- },
104
- {
105
- id: OPTION_COPY_MARKDOWN_URL,
106
- label: COPY_URL_LABEL,
107
- tooltip: this.copyTooltipFor(OPTION_COPY_MARKDOWN_URL),
108
- rightIconData: {
109
- iconSymbol: "link",
110
- iconSprite: "utility",
111
- iconColor: "gray-50"
112
- }
113
- },
114
- { id: "divider-1", label: "", divider: true },
115
- { id: "all-docs", label: "All Documentation", subheader: true },
116
- {
117
- id: OPTION_VIEW_LLMS,
118
- label: VIEW_LLMS_LABEL,
119
- rightIconData: {
120
- iconSymbol: "new_window",
121
- iconSprite: "utility",
122
- iconColor: "gray-50"
123
- }
124
- },
125
- {
126
- id: OPTION_COPY_LLMS_URL,
127
- label: COPY_LLMS_URL_LABEL,
128
- tooltip: this.copyTooltipFor(OPTION_COPY_LLMS_URL),
129
- rightIconData: {
130
- iconSymbol: "link",
131
- iconSprite: "utility",
132
- iconColor: "gray-50"
133
- }
134
- }
135
- ];
57
+ get viewMarkdownButtonText(): string {
58
+ return VIEW_MARKDOWN_LABEL;
136
59
  }
137
60
 
138
- // Tooltip for the split button's primary action (Copy as Markdown). Shares
139
- // the copy-markdown flash state, so it flips to "Copied!" after a successful
140
- // copy from either the primary button or the matching menu option.
141
- get actionTooltip(): string {
142
- return this.copyTooltipFor(OPTION_COPY_MARKDOWN);
143
- }
144
-
145
- // "Copied!" while this option is flashing, otherwise "Click to copy".
146
- private copyTooltipFor(optionId: string): string {
147
- return this.copiedOptionId === optionId
148
- ? COPIED_TOOLTIP_LABEL
149
- : DEFAULT_COPY_TOOLTIP_LABEL;
150
- }
151
-
152
- /** Routes a menu selection to the matching action handler. */
153
- handleMenuSelect(event: CustomEvent) {
154
- switch (event.detail) {
155
- case OPTION_COPY_MARKDOWN:
156
- this.handleCopyMarkdown(event);
157
- break;
158
- case OPTION_VIEW_MARKDOWN:
159
- this.handleViewMarkdown(event);
160
- break;
161
- case OPTION_COPY_MARKDOWN_URL:
162
- this.handleCopyUrl(event);
163
- break;
164
- case OPTION_VIEW_LLMS:
165
- this.handleViewLlms(event);
166
- break;
167
- case OPTION_COPY_LLMS_URL:
168
- this.handleCopyLlmsUrl(event);
169
- break;
170
- default:
171
- }
61
+ get copyUrlButtonText(): string {
62
+ return COPY_URL_LABEL;
172
63
  }
173
64
 
174
65
  async handleCopyMarkdown(event: Event) {
@@ -190,7 +81,7 @@ export default class ContentActionToolbar extends LightningElement {
190
81
  }
191
82
  const markdown = await response.text();
192
83
  await navigator.clipboard.writeText(markdown);
193
- this.flashCopied(OPTION_COPY_MARKDOWN);
84
+ this.flashCopied("copyMarkdownLabel");
194
85
  } catch (error) {
195
86
  console.error(error);
196
87
  }
@@ -225,55 +116,16 @@ export default class ContentActionToolbar extends LightningElement {
225
116
 
226
117
  try {
227
118
  await navigator.clipboard.writeText(this.markdownUrl);
228
- this.flashCopied(OPTION_COPY_MARKDOWN_URL);
229
- } catch (error) {
230
- console.error(error);
231
- }
232
- }
233
-
234
- handleViewLlms(event: Event) {
235
- this.trackToolbarEvent(
236
- event,
237
- "custEv_linkClick",
238
- VIEW_LLMS_LABEL,
239
- this.llmsTxtUrl
240
- );
241
-
242
- window.open(this.llmsTxtUrl, "_blank", "noopener,noreferrer");
243
- }
244
-
245
- async handleCopyLlmsUrl(event: Event) {
246
- this.trackToolbarEvent(
247
- event,
248
- "custEv_linkClick",
249
- COPY_LLMS_URL_LABEL,
250
- this.llmsTxtUrl
251
- );
252
-
253
- try {
254
- await navigator.clipboard.writeText(this.llmsTxtUrl);
255
- this.flashCopied(OPTION_COPY_LLMS_URL);
119
+ this.flashCopied("copyUrlLabel");
256
120
  } catch (error) {
257
121
  console.error(error);
258
122
  }
259
123
  }
260
124
 
261
- // Flash the given copy option's tooltip to "Copied!" then revert.
262
- private flashCopied(optionId: string) {
263
- if (this.copyTooltipResetTimeout !== null) {
264
- window.clearTimeout(this.copyTooltipResetTimeout);
265
- }
266
- this.copiedOptionId = optionId;
267
- this.copyTooltipResetTimeout = window.setTimeout(() => {
268
- this.copiedOptionId = null;
269
- this.copyTooltipResetTimeout = null;
270
- }, COPIED_TOOLTIP_RESET_MS);
271
- }
272
-
273
125
  private trackToolbarEvent(
274
126
  event: Event,
275
127
  eventName: "custEv_linkClick",
276
- label: ToolbarCtaLabel,
128
+ label: string,
277
129
  url: string
278
130
  ): void {
279
131
  track(event.currentTarget!, eventName, {
@@ -283,9 +135,21 @@ export default class ContentActionToolbar extends LightningElement {
283
135
  element_title: label,
284
136
  content_category: ANALYTICS_CONTENT_CATEGORY,
285
137
  // Source page the CTA was clicked from; `click_url` above is the
286
- // destination. Uses the same `page_path` expression as the
138
+ // `.md` destination. Uses the same `page_path` expression as the
287
139
  // amfReference doc_page_view events.
288
140
  page_path: window.location.pathname + window.location.search
289
141
  });
290
142
  }
143
+
144
+ private flashCopied(labelKey: "copyMarkdownLabel" | "copyUrlLabel") {
145
+ if (this.copyTooltipResetTimeout !== null) {
146
+ window.clearTimeout(this.copyTooltipResetTimeout);
147
+ }
148
+ this[labelKey] = COPIED_TOOLTIP_LABEL;
149
+ this.copyTooltipResetTimeout = window.setTimeout(() => {
150
+ this.copyMarkdownLabel = DEFAULT_COPY_TOOLTIP_LABEL;
151
+ this.copyUrlLabel = DEFAULT_COPY_TOOLTIP_LABEL;
152
+ this.copyTooltipResetTimeout = null;
153
+ }, COPIED_TOOLTIP_RESET_MS);
154
+ }
291
155
  }
@@ -10,8 +10,8 @@ export const DUMMY_MARKDOWN_CONTENT = `# Dummy Markdown
10
10
 
11
11
  Storybook serves this placeholder content in place of the real markdown
12
12
  that the docs backend would return for the current page. It exists so
13
- the "Copy as Markdown" clipboard action, the "View as Markdown" new tab,
14
- and the "Copy URL to Markdown" clipboard behavior are all exercisable in
13
+ the "Copied" tooltip, the "View as Markdown" new tab, and the
14
+ "Copy URL to Markdown" clipboard behavior are all exercisable in
15
15
  storybook without hitting the live backend.
16
16
 
17
17
  - Item 1
@@ -19,30 +19,18 @@ storybook without hitting the live backend.
19
19
  - Item 3
20
20
  `;
21
21
 
22
- export const DUMMY_LLMS_CONTENT = `# Dummy llms.txt
23
-
24
- Storybook serves this placeholder in place of the site-root llms.txt so
25
- the "View llms.txt" new tab and "Copy URL to llms.txt" clipboard behavior
26
- are exercisable without hitting the live backend.
27
- `;
28
-
29
22
  export const DUMMY_MARKDOWN_DATA_URL = `data:text/markdown;charset=utf-8,${encodeURIComponent(
30
23
  DUMMY_MARKDOWN_CONTENT
31
24
  )}`;
32
25
 
33
- export const DUMMY_LLMS_DATA_URL = `data:text/plain;charset=utf-8,${encodeURIComponent(
34
- DUMMY_LLMS_CONTENT
35
- )}`;
36
-
37
- /** Intercepts `.md` and `/llms.txt` GET requests and returns dummy content. */
26
+ /** Intercepts any `.md` GET request and returns the dummy markdown. */
38
27
  export const contentActionToolbarMswHandlers = [
39
- http.get(/\.md(\?.*)?$/, () => HttpResponse.text(DUMMY_MARKDOWN_CONTENT)),
40
- http.get(/\/llms\.txt(\?.*)?$/, () => HttpResponse.text(DUMMY_LLMS_CONTENT))
28
+ http.get(/\.md(\?.*)?$/, () => HttpResponse.text(DUMMY_MARKDOWN_CONTENT))
41
29
  ];
42
30
 
43
31
  let windowOpenIntercepted = false;
44
32
 
45
- /** Redirects `window.open` calls for `.md` and `llms.txt` URLs to dummy data URLs (MSW does not cover new tabs). */
33
+ /** Redirects `window.open` calls for `.md` URLs to the dummy markdown data URL (MSW does not cover new tabs). */
46
34
  export function interceptWindowOpenForContentActionToolbar() {
47
35
  if (windowOpenIntercepted) {
48
36
  return;
@@ -55,9 +43,6 @@ export function interceptWindowOpenForContentActionToolbar() {
55
43
  if (stringUrl.endsWith(".md")) {
56
44
  return originalOpen(DUMMY_MARKDOWN_DATA_URL, target, features);
57
45
  }
58
- if (stringUrl.endsWith("llms.txt")) {
59
- return originalOpen(DUMMY_LLMS_DATA_URL, target, features);
60
- }
61
46
  return originalOpen(url ?? "", target, features);
62
47
  }) as typeof window.open;
63
48
  }
@@ -77,6 +77,12 @@ header:not(.has-brand) > .header_l2 {
77
77
  border-top: 1px solid var(--dx-g-gray-90);
78
78
  }
79
79
 
80
+ @media (max-width: 1280px) {
81
+ .no-header-content {
82
+ border-top: 0;
83
+ }
84
+ }
85
+
80
86
  @media (max-width: 768px) {
81
87
  .header_l2 {
82
88
  padding: 0;
@@ -1,7 +1,6 @@
1
1
  :host {
2
2
  --dx-footer-margin-top: 142px;
3
3
  --doc-c-redoc-sidebar-top: calc(
4
- var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
5
- var(--dx-g-spacing-xl)
4
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height)
6
5
  );
7
6
  }
@@ -3,9 +3,12 @@ import { createElement, LightningElement, api } from "lwc";
3
3
  import DocPhase from "doc/phase";
4
4
  import DxFooter from "dx/footer";
5
5
  import DxIcon from "dx/icon";
6
+ import SidebarFooterNav from "dx/sidebarFooterNav";
6
7
  import SprigSurvey from "doc/sprigSurvey";
7
8
  import { throttle } from "throttle-debounce";
8
9
  import { pollUntil } from "dxUtils/async";
10
+ import { toJson } from "dxUtils/normalizers";
11
+ import type { OptionWithLink } from "typings/custom";
9
12
 
10
13
  declare global {
11
14
  interface Window {
@@ -37,7 +40,10 @@ type ReferenceConfig = {
37
40
  const SCROLL_THROTTLE_DELAY = 50;
38
41
  const ELEMENT_TIMEOUT = 10000;
39
42
  const ELEMENT_CHECK_INTERVAL = 100;
40
- const REFERENCES_SEGMENT = "/references/";
43
+ const DEFAULT_PROJECT_TITLE = "All Reference";
44
+ const BACK_TARGET_STORAGE_KEY = "redoc-back-target";
45
+ const DOCS_PATH_SEGMENT = "docs";
46
+ const DEFAULT_LOCALE = "en-us";
41
47
 
42
48
  export default class RedocReference extends LightningElement {
43
49
  private _referenceConfig: ReferenceConfig = { refList: [] };
@@ -47,6 +53,7 @@ export default class RedocReference extends LightningElement {
47
53
  private docHeaderElement: Element | null = null;
48
54
  private docPhaseWrapperElement: Element | null = null;
49
55
  private lastSidebarTop = 0;
56
+ private _languages: OptionWithLink[] = [];
50
57
 
51
58
  /**
52
59
  * History length captured at mount (pre-Redoc), used by `onBackClick` to
@@ -91,19 +98,86 @@ export default class RedocReference extends LightningElement {
91
98
  * Project title (same value passed to `<doc-header>` as `subtitle`). Used
92
99
  * inside the Redoc-rendered UI to label the parent project.
93
100
  */
94
- @api projectTitle: string | null = "All Reference";
101
+ @api
102
+ get projectTitle(): string | null {
103
+ return this.isDocContentType
104
+ ? this._projectTitle
105
+ : DEFAULT_PROJECT_TITLE;
106
+ }
107
+ set projectTitle(value: string | null) {
108
+ this._projectTitle = value;
109
+ }
110
+ private _projectTitle: string | null = null;
111
+
112
+ /**
113
+ * Href to navigate to when the back link is clicked AND there is no
114
+ * usable referrer (e.g. the user opened the page directly in a fresh
115
+ * tab).
116
+ */
117
+ @api headerHref: string | null = null;
118
+
119
+ @api
120
+ get contentType(): string {
121
+ return this._contentType;
122
+ }
123
+ set contentType(value: string) {
124
+ this._contentType = value;
125
+ }
126
+ private _contentType: string = "";
127
+
128
+ @api
129
+ get languages(): OptionWithLink[] {
130
+ return this._languages;
131
+ }
132
+ set languages(value: string | OptionWithLink[]) {
133
+ this._languages = toJson(value) || [];
134
+ }
135
+
136
+ @api language: string | null = null;
95
137
 
96
138
  get specTitle(): string | null {
97
139
  return this.getSelectedReference()?.title ?? null;
98
140
  }
99
141
 
142
+ get isDocContentType(): boolean {
143
+ return this.contentType === "docs";
144
+ }
145
+
146
+ get isReferenceContentType(): boolean {
147
+ return this.contentType === "references";
148
+ }
149
+
150
+ get isMultiSpecSet(): boolean {
151
+ const refCount = this.referenceConfig?.refList?.length ?? 0;
152
+ return refCount > 1;
153
+ }
154
+
155
+ // Reads stored back target
156
+ private getBackTargetFromSession(): string | null {
157
+ return sessionStorage.getItem(BACK_TARGET_STORAGE_KEY);
158
+ }
159
+
160
+ private setBackTargetInSession(href: string): void {
161
+ sessionStorage.setItem(BACK_TARGET_STORAGE_KEY, href);
162
+ }
163
+
164
+ /**
165
+ * when more than one localized spec is available
166
+ */
167
+ get hasLocalePicker(): boolean {
168
+ return this.languages.length > 1;
169
+ }
170
+
100
171
  /**
101
- * Whether to show the project header (only for multi-spec reference sets).
172
+ * Whether to show the project header. Shown for multi-spec reference
173
+ * sets, and for any docs-content spec topic so it always has a back
174
+ * link.
102
175
  */
103
176
  get showRedocHeader(): boolean {
104
- const refCount = this._referenceConfig?.refList?.length ?? 0;
105
- const isMultiSpecSet = refCount > 1;
106
- return isMultiSpecSet && !!(this.projectTitle || this.specTitle);
177
+ return (
178
+ (this.isReferenceContentType && this.isMultiSpecSet) ||
179
+ this.isDocContentType
180
+ );
107
181
  }
108
182
 
109
183
  /**
@@ -111,16 +185,68 @@ export default class RedocReference extends LightningElement {
111
185
  */
112
186
  private onBackClick = (event: Event): void => {
113
187
  event.preventDefault();
188
+
189
+ const target = this.getTranslatedBackTarget() ?? this.headerHref;
190
+
191
+ if (target) {
192
+ window.location.assign(target);
193
+ }
194
+ };
195
+
196
+ private getTranslatedBackTarget(): string | null {
197
+ const stored = this.getBackTargetFromSession();
198
+ if (stored) {
199
+ return this.language
200
+ ? this.translateToCurrentLocale(stored)
201
+ : stored;
202
+ }
203
+
204
+ const referrer = this.getSameOriginReferrerHref();
205
+ return referrer && !this.isLocaleHref(new URL(referrer).pathname)
206
+ ? referrer
207
+ : null;
208
+ }
209
+
210
+ /* The locale segment sits after "docs" for docs pages,
211
+ * and after the product segment for references.
212
+ */
213
+ private translateToCurrentLocale(storedHref: string): string {
214
+ const url = new URL(storedHref, window.location.origin);
215
+ const localeIds = this.languages.map((loc) => loc.id);
216
+ const segments = url.pathname.split("/").filter(Boolean);
217
+
218
+ // docs -> right after "docs"; references -> after the product segment.
219
+ const localeIndex = this.isDocContentType ? 1 : 2;
220
+
221
+ if (segments[0] === DOCS_PATH_SEGMENT) {
222
+ // Drop the existing locale segment, if any
223
+ if (localeIds.includes(segments[localeIndex])) {
224
+ segments.splice(localeIndex, 1);
225
+ }
226
+ // Add the current locale
227
+ if (this.language && this.language !== DEFAULT_LOCALE) {
228
+ segments.splice(localeIndex, 0, this.language);
229
+ }
230
+ }
231
+
232
+ url.pathname = "/" + segments.join("/");
233
+ return url.href;
234
+ }
235
+
236
+ // Preserves target across locale switches, updates on normal navigation
237
+ private trackBackTarget(): void {
114
238
  const referrerHref = this.getSameOriginReferrerHref();
115
- if (referrerHref) {
116
- window.location.href = referrerHref;
239
+ if (!referrerHref) {
117
240
  return;
118
241
  }
119
- const fallbackHref = this.getReferencesRootHref();
120
- if (fallbackHref) {
121
- window.location.href = fallbackHref;
242
+
243
+ const referrerUrl = new URL(referrerHref);
244
+ if (this.isLocaleHref(referrerUrl.pathname)) {
245
+ return;
122
246
  }
123
- };
247
+
248
+ this.setBackTargetInSession(referrerHref);
249
+ }
124
250
 
125
251
  /**
126
252
  * Returns the referrer URL when the page was reached via in-tab navigation
@@ -144,16 +270,16 @@ export default class RedocReference extends LightningElement {
144
270
  }
145
271
 
146
272
  /**
147
- * Derives the project's `.../references` root from the current URL by
148
- * trimming any trailing reference id (and deeper segments). Returns null
149
- * when the URL doesn't contain a `/references` segment.
273
+ * switching locale on this same page.
150
274
  */
151
- private getReferencesRootHref(): string | null {
152
- const { pathname } = window.location;
153
- const idx = pathname.lastIndexOf(REFERENCES_SEGMENT);
154
- return idx === -1
155
- ? null
156
- : pathname.slice(0, idx + REFERENCES_SEGMENT.length);
275
+ private isLocaleHref(pathname: string): boolean {
276
+ return this.languages.some((locale) => {
277
+ const href = locale?.link?.href;
278
+ return (
279
+ !!href &&
280
+ new URL(href, window.location.origin).pathname === pathname
281
+ );
282
+ });
157
283
  }
158
284
 
159
285
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
@@ -168,6 +294,9 @@ export default class RedocReference extends LightningElement {
168
294
  // so it reflects real in-tab navigation rather than Redoc's churn.
169
295
  this.initialHistoryLength = window.history.length;
170
296
 
297
+ // Track the back target, preserving it across locale switches
298
+ this.trackBackTarget();
299
+
171
300
  window.addEventListener("scroll", this.handleScrollAndResize);
172
301
  window.addEventListener("resize", this.handleScrollAndResize);
173
302
  }
@@ -394,7 +523,7 @@ export default class RedocReference extends LightningElement {
394
523
  this.appendFooterItems(apiContentDiv);
395
524
 
396
525
  // Inject the multi-spec project header into Redoc's left menu only.
397
- this.insertProjectHeaderInMenu(redocContainer);
526
+ this.insertSidebarNav(redocContainer);
398
527
 
399
528
  // Wait for footer to be rendered before updating styles
400
529
  requestAnimationFrame(() => {
@@ -409,22 +538,46 @@ export default class RedocReference extends LightningElement {
409
538
  }
410
539
 
411
540
  /**
412
- * Inserts the project header into Redoc for multi-spec reference sets.
541
+ * Inserts the project header and LNB footer into Redoc.
413
542
  */
414
- private insertProjectHeaderInMenu(redocContainer: HTMLElement): void {
415
- if (!this.showRedocHeader) {
416
- return;
543
+ private insertSidebarNav(redocContainer: HTMLElement): void {
544
+ // Select the LNB and content area of Redoc and insert the requried header.
545
+ if (this.showRedocHeader) {
546
+ redocContainer
547
+ .querySelectorAll<HTMLElement>(".menu-content, .api-content")
548
+ .forEach((target) => {
549
+ target.insertBefore(
550
+ this.buildProjectHeaderDom(),
551
+ target.firstChild
552
+ );
553
+ });
417
554
  }
418
555
 
419
- // Select the LNB and content area of Redoc and insert the requried header.
420
- redocContainer
421
- .querySelectorAll<HTMLElement>(".menu-content, .api-content")
422
- .forEach((target) => {
423
- target.insertBefore(
424
- this.buildProjectHeaderDom(),
425
- target.firstChild
426
- );
427
- });
556
+ // Locale picker
557
+ if (this.hasLocalePicker) {
558
+ const menuContent = redocContainer.querySelector(".menu-content");
559
+ menuContent?.appendChild(this.buildLocalePickerDom());
560
+ }
561
+ }
562
+
563
+ /**
564
+ * Builds the locale picker DOM by reusing `dx-sidebar-footer-nav`
565
+ */
566
+ private buildLocalePickerDom(): HTMLElement {
567
+ const wrapper = document.createElement("div");
568
+ wrapper.className = "redoc-footer-nav";
569
+
570
+ const picker = createElement("dx-sidebar-footer-nav", {
571
+ is: SidebarFooterNav
572
+ });
573
+
574
+ Object.assign(picker, {
575
+ languages: this.languages,
576
+ language: this.language
577
+ });
578
+ wrapper.appendChild(picker);
579
+
580
+ return wrapper;
428
581
  }
429
582
 
430
583
  /**
@@ -1,3 +1,9 @@
1
+ @media screen and (max-width: 768px) {
2
+ :host {
3
+ display: block;
4
+ }
5
+ }
6
+
1
7
  :host .survey-container {
2
8
  align-items: center;
3
9
  align-content: center;
@@ -7,6 +13,17 @@
7
13
  margin: 20px 0;
8
14
  }
9
15
 
16
+ @media screen and (max-width: 768px) {
17
+ :host .survey-container {
18
+ flex-direction: column;
19
+ gap: var(--dx-g-spacing-md);
20
+ }
21
+
22
+ .text-container {
23
+ text-align: center;
24
+ }
25
+ }
26
+
10
27
  dx-hr:first-of-type::part(hr) {
11
28
  margin-top: var(--dx-g-spacing-2xl);
12
29
  }
@@ -0,0 +1,19 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ .content-type-docs doc-phase {
6
+ --doc-c-phase-top: calc(
7
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
8
+ var(--dx-g-spacing-xl)
9
+ );
10
+ }
11
+
12
+ @media screen and (max-width: 768px) {
13
+ .content-type-docs doc-phase {
14
+ --doc-c-phase-top: calc(
15
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
16
+ 40px
17
+ );
18
+ }
19
+ }
@@ -0,0 +1,29 @@
1
+ <template>
2
+ <doc-content-layout
3
+ class="content-type content-type-markdown content-type-docs"
4
+ breadcrumbs={breadcrumbs}
5
+ share-title={shareTitle}
6
+ share-twitter-via={twitterVia}
7
+ sidebar-header={sidebarHeader}
8
+ sidebar-value={sidebarValue}
9
+ sidebar-content={sidebarContent}
10
+ toc-title={tocTitle}
11
+ toc-options={tocOptions}
12
+ toc-aria-level={tocAriaLevel}
13
+ enable-slot-change="true"
14
+ languages={languages}
15
+ language={language}
16
+ show-footer={enableFooter}
17
+ show-content-action-toolbar={showContentActionToolbar}
18
+ origin={origin}
19
+ dev-center={devCenter}
20
+ brand={brand}
21
+ >
22
+ <doc-phase
23
+ slot="doc-phase"
24
+ lwc:if={docPhaseInfo}
25
+ doc-phase-info={docPhaseInfo}
26
+ ></doc-phase>
27
+ <slot></slot>
28
+ </doc-content-layout>
29
+ </template>
@@ -0,0 +1,120 @@
1
+ import { LightningElement, api } from "lwc";
2
+ import { toJson } from "dxUtils/normalizers";
3
+ import type { OptionWithLink, TreeNode } from "typings/custom";
4
+
5
+ /**
6
+ * Per-topic type emitted by the docs content-type parser
7
+ * (see @salesforcedevs/sfdocs-doc-framework: `TopicTypeEnum`). Only `spec`
8
+ * is meaningful inside this component; everything else renders as a plain
9
+ * markdown-style tile.
10
+ */
11
+ const TOPIC_TYPE_SPEC = "spec";
12
+
13
+ function findFirstContentDescendant(node: TreeNode): TreeNode | undefined {
14
+ for (const child of node.children ?? []) {
15
+ const isSpec =
16
+ (child as { topicType?: string }).topicType === TOPIC_TYPE_SPEC;
17
+ const isExternal = child.link?.target === "_blank";
18
+ if (isSpec || isExternal) {
19
+ continue;
20
+ }
21
+
22
+ if (child.link?.href) {
23
+ return child;
24
+ }
25
+
26
+ const descendant = findFirstContentDescendant(child);
27
+ if (descendant) {
28
+ return descendant;
29
+ }
30
+ }
31
+
32
+ return undefined;
33
+ }
34
+
35
+ /**
36
+ * Translates per-topic `topicType` into the generic `showForwardArrow` flag
37
+ * that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc),
38
+ * and redirects content-less parent topics to their first content descendant.
39
+ */
40
+ function decorateTopics(
41
+ topics: Array<TreeNode & { topicType?: string }> | undefined
42
+ ): TreeNode[] | undefined {
43
+ return topics?.map((topic) => {
44
+ const { topicType, ...decorated } = topic;
45
+ if (topicType === TOPIC_TYPE_SPEC) {
46
+ decorated.showForwardArrow = true;
47
+ }
48
+ if (decorated.children) {
49
+ decorated.children = decorateTopics(decorated.children);
50
+ }
51
+
52
+ // Redirect parent topics without their own content to their first
53
+ // available content descendant.
54
+ const isContentlessParent =
55
+ !!decorated.children?.length && !decorated.link?.href;
56
+
57
+ if (isContentlessParent) {
58
+ const firstContent = findFirstContentDescendant(topic);
59
+ if (firstContent?.link) {
60
+ decorated.link = { ...firstContent.link };
61
+ }
62
+ }
63
+
64
+ return decorated;
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Wrapper around `doc-content-layout` for the "docs" content type emitted by
70
+ * the `DocsContentTypeParser`.
71
+ */
72
+ export default class UnifiedContentLayout extends LightningElement {
73
+ @api breadcrumbs: string | null = null;
74
+ @api sidebarHeader?: string;
75
+ @api sidebarValue?: string;
76
+ @api tocTitle?: string;
77
+ @api tocOptions?: string;
78
+ @api tocAriaLevel?: string;
79
+ @api languages?: OptionWithLink[];
80
+ @api language?: string;
81
+ @api devCenter: any = null;
82
+ @api brand: any = null;
83
+ @api showContentActionToolbar = false;
84
+
85
+ /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). */
86
+ @api origin: string | null = null;
87
+
88
+ /** Article name from breadcrumbs, used as share title (e.g. for social share). */
89
+ @api shareTitle: string | null = null;
90
+
91
+ /** Optional Twitter "via" handle (e.g. SalesforceDevs) for social share. */
92
+ @api twitterVia: string | null = null;
93
+
94
+ @api hideFooter = false;
95
+
96
+ private _docPhaseInfo: string | null = null;
97
+ private _sidebarContent: unknown = null;
98
+
99
+ @api
100
+ get docPhaseInfo(): string | null {
101
+ return this._docPhaseInfo;
102
+ }
103
+
104
+ set docPhaseInfo(value: string | null) {
105
+ this._docPhaseInfo = value || null;
106
+ }
107
+
108
+ @api
109
+ get sidebarContent(): unknown {
110
+ return this._sidebarContent;
111
+ }
112
+
113
+ set sidebarContent(value: string) {
114
+ this._sidebarContent = decorateTopics(toJson(value)?.topics);
115
+ }
116
+
117
+ private get enableFooter(): boolean {
118
+ return !this.hideFooter;
119
+ }
120
+ }