@salesforcedevs/docs-components 1.30.1-node22-3 → 1.30.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2020, Salesforce.com, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/lwc.config.json CHANGED
@@ -5,6 +5,7 @@
5
5
  { "npm": "@salesforcedevs/dw-components" }
6
6
  ],
7
7
  "expose": [
8
+ "doc/contentActionToolbar",
8
9
  "doc/amfReference",
9
10
  "doc/banner",
10
11
  "doc/localeBanner",
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
- "name": "@salesforcedevs/docs-components",
3
- "version": "1.30.1-node22-3",
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.30.1",
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": "1ef01ecd6afcd77c06384577bbf7afa48907d82a"
29
+ }
@@ -17,6 +17,7 @@
17
17
  languages={languages}
18
18
  language={language}
19
19
  show-footer={enableFooter}
20
+ show-content-action-toolbar={showContentActionToolbar}
20
21
  empty-state-message={emptyStateMessage}
21
22
  origin={origin}
22
23
  >
@@ -37,6 +37,7 @@ type NavigationItem = {
37
37
  isExpanded: boolean;
38
38
  children: ParsedMarkdownTopic[];
39
39
  isChildrenLoading: boolean;
40
+ showForwardArrow?: boolean;
40
41
  };
41
42
 
42
43
  export default class AmfReference extends LightningElement {
@@ -72,6 +73,8 @@ export default class AmfReference extends LightningElement {
72
73
  return this.isSpecBasedReference(this._currentReferenceId);
73
74
  }
74
75
 
76
+ @api showContentActionToolbar = false;
77
+
75
78
  @api
76
79
  get referenceSetConfig(): ReferenceSetConfig {
77
80
  return this._referenceSetConfig;
@@ -204,6 +207,7 @@ export default class AmfReference extends LightningElement {
204
207
 
205
208
  _boundOnApiNavigationChanged;
206
209
  _boundUpdateSelectedItemFromUrlQuery;
210
+ _boundOnPageShow;
207
211
 
208
212
  constructor() {
209
213
  super();
@@ -212,6 +216,7 @@ export default class AmfReference extends LightningElement {
212
216
  this.onApiNavigationChanged.bind(this);
213
217
  this._boundUpdateSelectedItemFromUrlQuery =
214
218
  this.updateSelectedItemFromUrlQuery.bind(this);
219
+ this._boundOnPageShow = this.onPageShow.bind(this);
215
220
  }
216
221
 
217
222
  connectedCallback(): void {
@@ -223,6 +228,7 @@ export default class AmfReference extends LightningElement {
223
228
  "popstate",
224
229
  this._boundUpdateSelectedItemFromUrlQuery
225
230
  );
231
+ window.addEventListener("pageshow", this._boundOnPageShow);
226
232
  }
227
233
 
228
234
  disconnectedCallback(): void {
@@ -234,6 +240,22 @@ export default class AmfReference extends LightningElement {
234
240
  "popstate",
235
241
  this._boundUpdateSelectedItemFromUrlQuery
236
242
  );
243
+ window.removeEventListener("pageshow", this._boundOnPageShow);
244
+ }
245
+
246
+ /**
247
+ * On bfcache restore, reset the sidebar selection so the tree re-syncs
248
+ * its highlighted tile with the current URL.
249
+ */
250
+ protected onPageShow(event: PageTransitionEvent): void {
251
+ if (!event.persisted) {
252
+ return;
253
+ }
254
+ const currentPath = window.location.pathname;
255
+ this.selectedSidebarValue = "";
256
+ Promise.resolve().then(() => {
257
+ this.selectedSidebarValue = currentPath;
258
+ });
237
259
  }
238
260
 
239
261
  renderedCallback(): void {
@@ -443,16 +465,21 @@ export default class AmfReference extends LightningElement {
443
465
  let navItemChildren = [] as ParsedMarkdownTopic[];
444
466
  let isChildrenLoading = false;
445
467
  if (amfConfig.referenceType !== REFERENCE_TYPES.markdown) {
446
- if (amfConfig.isSelected) {
447
- const amfPromise = this.fetchAmf(amfConfig).then(
448
- (amfJson) => {
449
- this.updateModel(amfConfig.id, amfJson);
450
- this.assignNavigationItemsFromAmf(amfConfig, index);
451
- }
452
- );
453
- this.amfFetchPromiseMap[amfConfig.id] = amfPromise;
468
+ if (amfConfig.amf) {
469
+ if (amfConfig.isSelected) {
470
+ const amfPromise = this.fetchAmf(amfConfig).then(
471
+ (amfJson) => {
472
+ this.updateModel(amfConfig.id, amfJson);
473
+ this.assignNavigationItemsFromAmf(
474
+ amfConfig,
475
+ index
476
+ );
477
+ }
478
+ );
479
+ this.amfFetchPromiseMap[amfConfig.id] = amfPromise;
480
+ }
481
+ isChildrenLoading = true;
454
482
  }
455
- isChildrenLoading = true;
456
483
  } else {
457
484
  const isExpandChildrenEnabled = this.isExpandChildrenEnabled(
458
485
  amfConfig.id
@@ -473,13 +500,30 @@ export default class AmfReference extends LightningElement {
473
500
  amfConfig.isSelected ||
474
501
  this.isExpandChildrenEnabled(amfConfig.id),
475
502
  children: navItemChildren,
476
- isChildrenLoading
503
+ isChildrenLoading,
504
+ showForwardArrow: this.resolveNavRenderWith(amfConfig)
477
505
  };
478
506
  this.parentReferenceUrls.push(amfConfig.href);
479
507
  }
480
508
  this.navigation = navAmfOrder;
481
509
  }
482
510
 
511
+ /**
512
+ * Determines whether the sidebar tile should render a forward arrow for
513
+ * this reference. Honors `redoc` set on the config, and also infers it
514
+ * for non-markdown references that have no AMF URL (i.e. those rendered
515
+ * by Redoc).
516
+ */
517
+ private resolveNavRenderWith(amfConfig: AmfConfig): boolean {
518
+ if (amfConfig.renderWith) {
519
+ return amfConfig.renderWith === "redoc";
520
+ }
521
+ return (
522
+ amfConfig.referenceType !== REFERENCE_TYPES.markdown &&
523
+ !amfConfig.amf
524
+ );
525
+ }
526
+
483
527
  /**
484
528
  * Returns a boolean indicating whether the children should be expanded or not.
485
529
  */
@@ -78,6 +78,11 @@ export interface AmfConfig {
78
78
 
79
79
  // required for markdown based references
80
80
  topic?: ParsedMarkdownTopic;
81
+
82
+ /**
83
+ * Required for rendering the arrow on LNB
84
+ */
85
+ renderWith?: string;
81
86
  }
82
87
 
83
88
  export interface ParsedTopicModel {
@@ -0,0 +1,31 @@
1
+ @import "dxHelpers/reset";
2
+
3
+ :host {
4
+ display: block;
5
+ }
6
+
7
+ .toolbar {
8
+ display: flex;
9
+ align-items: center;
10
+ gap: var(--dx-g-spacing-smd);
11
+ margin-bottom: var(--dx-g-spacing-lg);
12
+ }
13
+
14
+ .toolbar-button {
15
+ --dx-c-button-font-weight: var(--dx-g-font-demi);
16
+ --dx-c-button-line-height: var(--dx-g-spacing-mlg);
17
+ --dx-c-button-letter-spacing: 0.005em;
18
+ }
19
+
20
+ .divider {
21
+ width: 1px;
22
+ height: var(--dx-g-spacing-md);
23
+ background-color: var(--dx-g-gray-70);
24
+ }
25
+
26
+ @media screen and (max-width: 480px) {
27
+ .toolbar-button_copy-url,
28
+ .divider_copy-url {
29
+ display: none;
30
+ }
31
+ }
@@ -0,0 +1,53 @@
1
+ <template>
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>
53
+ </template>
@@ -0,0 +1,151 @@
1
+ import { LightningElement, api } from "lwc";
2
+ import { track } from "dxUtils/analytics";
3
+
4
+ const DEFAULT_COPY_TOOLTIP_LABEL = "Click to copy";
5
+ const COPIED_TOOLTIP_LABEL = "Copied!";
6
+ const COPIED_TOOLTIP_RESET_MS = 1000;
7
+
8
+ const ANALYTICS_CONTENT_CATEGORY = "content action toolbar";
9
+ const COPY_MARKDOWN_LABEL = "Copy as Markdown";
10
+ const VIEW_MARKDOWN_LABEL = "View as Markdown";
11
+ const COPY_URL_LABEL = "Copy URL to Markdown";
12
+
13
+ export default class ContentActionToolbar extends LightningElement {
14
+ @api
15
+ get pageUrl(): string | undefined {
16
+ return this._pageUrl;
17
+ }
18
+ set pageUrl(value: string | undefined) {
19
+ if (this._pageUrl === value) {
20
+ return;
21
+ }
22
+ this._pageUrl = value;
23
+ }
24
+ private _pageUrl?: string;
25
+
26
+ copyMarkdownLabel: string = DEFAULT_COPY_TOOLTIP_LABEL;
27
+ copyUrlLabel: string = DEFAULT_COPY_TOOLTIP_LABEL;
28
+
29
+ private copyTooltipResetTimeout: number | null = null;
30
+
31
+ /**
32
+ * Returns the `.md` equivalent of `pageUrl` with any hash and query
33
+ * string stripped, or `null` when `pageUrl` is not set or does not end
34
+ * with `.html`.
35
+ */
36
+ get markdownUrl(): string | null {
37
+ if (!this.pageUrl) {
38
+ return null;
39
+ }
40
+
41
+ const url = new URL(this.pageUrl, window.location.href);
42
+ url.hash = "";
43
+ url.search = "";
44
+
45
+ if (!url.pathname.endsWith(".html")) {
46
+ return null;
47
+ }
48
+
49
+ url.pathname = url.pathname.replace(/\.html$/, ".md");
50
+ return url.toString();
51
+ }
52
+
53
+ get copyMarkdownButtonText(): string {
54
+ return COPY_MARKDOWN_LABEL;
55
+ }
56
+
57
+ get viewMarkdownButtonText(): string {
58
+ return VIEW_MARKDOWN_LABEL;
59
+ }
60
+
61
+ get copyUrlButtonText(): string {
62
+ return COPY_URL_LABEL;
63
+ }
64
+
65
+ async handleCopyMarkdown(event: Event) {
66
+ if (!this.markdownUrl) {
67
+ return;
68
+ }
69
+
70
+ this.trackToolbarEvent(
71
+ event,
72
+ "custEv_linkClick",
73
+ COPY_MARKDOWN_LABEL,
74
+ this.markdownUrl
75
+ );
76
+
77
+ try {
78
+ const response = await fetch(this.markdownUrl);
79
+ if (!response.ok) {
80
+ return;
81
+ }
82
+ const markdown = await response.text();
83
+ await navigator.clipboard.writeText(markdown);
84
+ this.flashCopied("copyMarkdownLabel");
85
+ } catch (error) {
86
+ console.error(error);
87
+ }
88
+ }
89
+
90
+ handleViewMarkdown(event: Event) {
91
+ if (!this.markdownUrl) {
92
+ return;
93
+ }
94
+
95
+ this.trackToolbarEvent(
96
+ event,
97
+ "custEv_linkClick",
98
+ VIEW_MARKDOWN_LABEL,
99
+ this.markdownUrl
100
+ );
101
+
102
+ window.open(this.markdownUrl, "_blank", "noopener,noreferrer");
103
+ }
104
+
105
+ async handleCopyUrl(event: Event) {
106
+ if (!this.markdownUrl) {
107
+ return;
108
+ }
109
+
110
+ this.trackToolbarEvent(
111
+ event,
112
+ "custEv_linkClick",
113
+ COPY_URL_LABEL,
114
+ this.markdownUrl
115
+ );
116
+
117
+ try {
118
+ await navigator.clipboard.writeText(this.markdownUrl);
119
+ this.flashCopied("copyUrlLabel");
120
+ } catch (error) {
121
+ console.error(error);
122
+ }
123
+ }
124
+
125
+ private trackToolbarEvent(
126
+ event: Event,
127
+ eventName: "custEv_linkClick",
128
+ label: string,
129
+ url: string
130
+ ): void {
131
+ track(event.currentTarget!, eventName, {
132
+ click_text: label,
133
+ click_url: url,
134
+ element_type: "button_link",
135
+ element_title: label,
136
+ content_category: ANALYTICS_CONTENT_CATEGORY
137
+ });
138
+ }
139
+
140
+ private flashCopied(labelKey: "copyMarkdownLabel" | "copyUrlLabel") {
141
+ if (this.copyTooltipResetTimeout !== null) {
142
+ window.clearTimeout(this.copyTooltipResetTimeout);
143
+ }
144
+ this[labelKey] = COPIED_TOOLTIP_LABEL;
145
+ this.copyTooltipResetTimeout = window.setTimeout(() => {
146
+ this.copyMarkdownLabel = DEFAULT_COPY_TOOLTIP_LABEL;
147
+ this.copyUrlLabel = DEFAULT_COPY_TOOLTIP_LABEL;
148
+ this.copyTooltipResetTimeout = null;
149
+ }, COPIED_TOOLTIP_RESET_MS);
150
+ }
151
+ }
@@ -0,0 +1,48 @@
1
+ import { http, HttpResponse } from "msw";
2
+
3
+ /**
4
+ * Mocks for the content action toolbar so stories never hit the real
5
+ * docs backend. Any story rendering `doc-content-action-toolbar` (directly or
6
+ * via `doc-content-layout`) must register `contentActionToolbarMswHandlers`
7
+ * and call `interceptWindowOpenForContentActionToolbar()`.
8
+ */
9
+ export const DUMMY_MARKDOWN_CONTENT = `# Dummy Markdown
10
+
11
+ Storybook serves this placeholder content in place of the real markdown
12
+ that the docs backend would return for the current page. It exists so
13
+ the "Copied" tooltip, the "View as Markdown" new tab, and the
14
+ "Copy URL to Markdown" clipboard behavior are all exercisable in
15
+ storybook without hitting the live backend.
16
+
17
+ - Item 1
18
+ - Item 2
19
+ - Item 3
20
+ `;
21
+
22
+ export const DUMMY_MARKDOWN_DATA_URL = `data:text/markdown;charset=utf-8,${encodeURIComponent(
23
+ DUMMY_MARKDOWN_CONTENT
24
+ )}`;
25
+
26
+ /** Intercepts any `.md` GET request and returns the dummy markdown. */
27
+ export const contentActionToolbarMswHandlers = [
28
+ http.get(/\.md(\?.*)?$/, () => HttpResponse.text(DUMMY_MARKDOWN_CONTENT))
29
+ ];
30
+
31
+ let windowOpenIntercepted = false;
32
+
33
+ /** Redirects `window.open` calls for `.md` URLs to the dummy markdown data URL (MSW does not cover new tabs). */
34
+ export function interceptWindowOpenForContentActionToolbar() {
35
+ if (windowOpenIntercepted) {
36
+ return;
37
+ }
38
+ windowOpenIntercepted = true;
39
+
40
+ const originalOpen = window.open.bind(window);
41
+ window.open = ((url?: string | URL, target?: string, features?: string) => {
42
+ const stringUrl = url?.toString() ?? "";
43
+ if (stringUrl.endsWith(".md")) {
44
+ return originalOpen(DUMMY_MARKDOWN_DATA_URL, target, features);
45
+ }
46
+ return originalOpen(url ?? "", target, features);
47
+ }) as typeof window.open;
48
+ }
@@ -43,7 +43,7 @@
43
43
  ></path>
44
44
  </g>
45
45
  </svg>
46
- {readingTime} minute read
46
+ {readingTimeLabel}
47
47
  </div>
48
48
  <div class="share-below-read" lwc:if={showSocialShare}>
49
49
  <doc-social-share
@@ -1,11 +1,15 @@
1
1
  /* eslint-disable @lwc/lwc/no-document-query */
2
- import { LightningElement, api, track } from "lwc";
3
- import { closest } from "kagekiri";
2
+ import { LightningElement, api, createElement, track } from "lwc";
3
+ import { closest, querySelector } from "kagekiri";
4
4
  import { toJson, normalizeBoolean } from "dxUtils/normalizers";
5
5
  import { highlightTerms } from "dxUtils/highlight";
6
6
  import { SearchSyncer } from "docUtils/searchSyncer";
7
7
  import type { OptionWithLink } from "typings/custom";
8
8
  import { buildDocLinkClickHandler } from "dxUtils/analytics";
9
+ import ContentActionToolbar from "doc/contentActionToolbar";
10
+
11
+ const CONTENT_ACTION_TOOLBAR_TAG = "doc-content-action-toolbar";
12
+ const PAGE_HEADING_SELECTOR = "h1";
9
13
 
10
14
  type AnchorMap = { [key: string]: { intersect: boolean; id: string } };
11
15
 
@@ -28,6 +32,35 @@ const HIGHLIGHTABLE_SELECTOR = [
28
32
  ].join(",");
29
33
  export const OBSERVER_ATTACH_WAIT_TIME = 500;
30
34
 
35
+ const DEFAULT_READING_TIME_LOCALE = "en-us";
36
+
37
+ /**
38
+ * Localized "minute read" templates. `{minutes}` is replaced with the rounded
39
+ * reading-time value. Only displayed when reading time is greater than 1, so
40
+ * plural forms are always appropriate. Keys match the locales declared in
41
+ * sfdocs (and the doc-locale-banner) so that a localized document automatically
42
+ * gets a localized reading-time label.
43
+ */
44
+ export const READING_TIME_LABELS: Record<string, string> = {
45
+ "en-us": "{minutes} minute read",
46
+ "ja-jp": "読了時間 {minutes} 分",
47
+ "zh-cn": "阅读时间 {minutes} 分钟",
48
+ "zh-tw": "閱讀時間 {minutes} 分鐘",
49
+ "fr-fr": "Lecture de {minutes} minutes",
50
+ "de-de": "{minutes} Minuten Lesezeit",
51
+ "it-it": "{minutes} minuti di lettura",
52
+ "ko-kr": "읽는 데 {minutes}분",
53
+ "pt-br": "{minutes} minutos de leitura",
54
+ "es-mx": "{minutes} minutos de lectura",
55
+ "es-es": "{minutes} minutos de lectura",
56
+ "ru-ru": "Время чтения: {minutes} мин",
57
+ "fi-fi": "{minutes} minuutin lukuaika",
58
+ "da-dk": "{minutes} minutters læsning",
59
+ "sv-se": "{minutes} minuters läsning",
60
+ "nl-nl": "{minutes} minuten leestijd",
61
+ "nb-no": "{minutes} minutters lesetid"
62
+ };
63
+
31
64
  export default class ContentLayout extends LightningElement {
32
65
  @api sidebarValue!: string;
33
66
  @api sidebarHeader!: string;
@@ -66,6 +99,17 @@ export default class ContentLayout extends LightningElement {
66
99
  /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer. */
67
100
  @api origin: string | null = null;
68
101
 
102
+ /** Controls whether the content action toolbar is displayed. */
103
+ @api
104
+ get showContentActionToolbar() {
105
+ return this._showContentActionToolbar;
106
+ }
107
+ set showContentActionToolbar(value) {
108
+ this._showContentActionToolbar = normalizeBoolean(value);
109
+ this.updateContentActionToolbar();
110
+ }
111
+ private _showContentActionToolbar = false;
112
+
69
113
  @api
70
114
  get breadcrumbs() {
71
115
  return this._breadcrumbs;
@@ -123,6 +167,7 @@ export default class ContentLayout extends LightningElement {
123
167
  protected hasRendered: boolean = false;
124
168
  protected contentLoaded: boolean = false;
125
169
  protected sidebarOpen: boolean = false;
170
+ protected contentActionToolbarElement: HTMLElement | null = null;
126
171
 
127
172
  get shouldDisplayFeedback() {
128
173
  return this.contentLoaded && typeof Sprig !== "undefined";
@@ -173,6 +218,19 @@ export default class ContentLayout extends LightningElement {
173
218
  return this.readingTime != null && this.readingTime > 1;
174
219
  }
175
220
 
221
+ /**
222
+ * Localized "X minute read" string for the current document language.
223
+ * Falls back to the default (en-us) template when the language is missing
224
+ * or has no translation.
225
+ */
226
+ get readingTimeLabel(): string {
227
+ const localeKey = (this.language || "").toLowerCase();
228
+ const template =
229
+ READING_TIME_LABELS[localeKey] ||
230
+ READING_TIME_LABELS[DEFAULT_READING_TIME_LOCALE];
231
+ return template.replace("{minutes}", String(this.readingTime));
232
+ }
233
+
176
234
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
177
235
  get effectiveFooterOrigin(): string {
178
236
  return (
@@ -215,6 +273,8 @@ export default class ContentLayout extends LightningElement {
215
273
  window.addEventListener("scroll", this.adjustNavPosition);
216
274
  window.addEventListener("resize", this.adjustNavPosition);
217
275
 
276
+ this.updateContentActionToolbar();
277
+
218
278
  if (!this.hasRendered) {
219
279
  this.hasRendered = true;
220
280
  this.restoreScroll();
@@ -224,6 +284,43 @@ export default class ContentLayout extends LightningElement {
224
284
  }
225
285
  }
226
286
 
287
+ /**
288
+ * Inserts the content action toolbar into the slotted content immediately
289
+ * after the first H1 found inside this layout.
290
+ */
291
+ protected updateContentActionToolbar(): void {
292
+ if (!this.showContentActionToolbar || !this.sidebarValue) {
293
+ this.removeContentActionToolbar();
294
+ return;
295
+ }
296
+
297
+ const heading = querySelector(
298
+ PAGE_HEADING_SELECTOR,
299
+ this.template.host
300
+ ) as HTMLElement | null;
301
+
302
+ if (!heading) {
303
+ return;
304
+ }
305
+
306
+ const toolbar = (this.contentActionToolbarElement ??
307
+ createElement(CONTENT_ACTION_TOOLBAR_TAG, {
308
+ is: ContentActionToolbar
309
+ })) as HTMLElement & { pageUrl?: string };
310
+
311
+ toolbar.pageUrl = this.sidebarValue;
312
+
313
+ if (toolbar.previousElementSibling !== heading) {
314
+ heading.parentNode?.insertBefore(toolbar, heading.nextSibling);
315
+ }
316
+
317
+ this.contentActionToolbarElement = toolbar;
318
+ }
319
+
320
+ protected removeContentActionToolbar(): void {
321
+ this.contentActionToolbarElement?.remove();
322
+ }
323
+
227
324
  disconnectedCallback(): void {
228
325
  this.disconnectObserver();
229
326
  window.removeEventListener(
@@ -239,6 +336,9 @@ export default class ContentLayout extends LightningElement {
239
336
 
240
337
  // Remove link click handler
241
338
  this.template.removeEventListener("click", this.handleLinkClick);
339
+
340
+ this.removeContentActionToolbar();
341
+ this.contentActionToolbarElement = null;
242
342
  }
243
343
 
244
344
  restoreScroll() {
@@ -481,6 +581,7 @@ export default class ContentLayout extends LightningElement {
481
581
 
482
582
  onSlotChange(): void {
483
583
  this.updateRNB();
584
+ this.updateContentActionToolbar();
484
585
  this.contentLoaded = true;
485
586
  }
486
587
 
@@ -13,7 +13,6 @@
13
13
  onclick={onLinkClick}
14
14
  class="dev-center-content"
15
15
  >
16
- <dx-icon symbol="back"></dx-icon>
17
16
  <dx-icon
18
17
  class="brand-icon"
19
18
  lwc:if={devCenter.icon}
@@ -41,7 +41,7 @@
41
41
  ></path>
42
42
  </g>
43
43
  </svg>
44
- {readingTime} minute read
44
+ {readingTimeLabel}
45
45
  </div>
46
46
  <slot onslotchange={onSlotChange}></slot>
47
47
  <doc-sprig-survey
@@ -2,6 +2,7 @@
2
2
  import { createElement, LightningElement, api } from "lwc";
3
3
  import DocPhase from "doc/phase";
4
4
  import DxFooter from "dx/footer";
5
+ import DxIcon from "dx/icon";
5
6
  import SprigSurvey from "doc/sprigSurvey";
6
7
  import { throttle } from "throttle-debounce";
7
8
  import { pollUntil } from "dxUtils/async";
@@ -14,11 +15,19 @@ declare global {
14
15
 
15
16
  declare const Sprig: (eventType: string, eventName: string) => void;
16
17
 
18
+ type ReferenceTopic = {
19
+ link?: { href?: string };
20
+ children?: ReferenceTopic[];
21
+ };
22
+
17
23
  type ReferenceItem = {
18
24
  source: string;
19
25
  href: string;
26
+ title?: string;
20
27
  isSelected?: boolean;
21
28
  docPhase?: string | null;
29
+ referenceType?: string;
30
+ topic?: ReferenceTopic;
22
31
  };
23
32
 
24
33
  type ReferenceConfig = {
@@ -28,6 +37,7 @@ type ReferenceConfig = {
28
37
  const SCROLL_THROTTLE_DELAY = 50;
29
38
  const ELEMENT_TIMEOUT = 10000;
30
39
  const ELEMENT_CHECK_INTERVAL = 100;
40
+ const REFERENCES_SEGMENT = "/references/";
31
41
 
32
42
  export default class RedocReference extends LightningElement {
33
43
  private _referenceConfig: ReferenceConfig = { refList: [] };
@@ -38,6 +48,12 @@ export default class RedocReference extends LightningElement {
38
48
  private docPhaseWrapperElement: Element | null = null;
39
49
  private lastSidebarTop = 0;
40
50
 
51
+ /**
52
+ * History length captured at mount (pre-Redoc), used by `onBackClick` to
53
+ * distinguish in-tab navigation (> 1) from a fresh entry (=== 1).
54
+ */
55
+ private initialHistoryLength = 0;
56
+
41
57
  showError = false;
42
58
 
43
59
  @api
@@ -71,6 +87,75 @@ export default class RedocReference extends LightningElement {
71
87
  /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer. */
72
88
  @api origin: string | null = null;
73
89
 
90
+ /**
91
+ * Project title (same value passed to `<doc-header>` as `subtitle`). Used
92
+ * inside the Redoc-rendered UI to label the parent project.
93
+ */
94
+ @api projectTitle: string | null = "All Reference";
95
+
96
+ get specTitle(): string | null {
97
+ return this.getSelectedReference()?.title ?? null;
98
+ }
99
+
100
+ /**
101
+ * Whether to show the project header (only for multi-spec reference sets).
102
+ */
103
+ get showRedocHeader(): boolean {
104
+ const refCount = this._referenceConfig?.refList?.length ?? 0;
105
+ const isMultiSpecSet = refCount > 1;
106
+ return isMultiSpecSet && !!(this.projectTitle || this.specTitle);
107
+ }
108
+
109
+ /**
110
+ * Navigates back to reference doc.
111
+ */
112
+ private onBackClick = (event: Event): void => {
113
+ event.preventDefault();
114
+ const referrerHref = this.getSameOriginReferrerHref();
115
+ if (referrerHref) {
116
+ window.location.href = referrerHref;
117
+ return;
118
+ }
119
+ const fallbackHref = this.getReferencesRootHref();
120
+ if (fallbackHref) {
121
+ window.location.href = fallbackHref;
122
+ }
123
+ };
124
+
125
+ /**
126
+ * Returns the referrer URL when the page was reached via in-tab navigation
127
+ * from a same-origin page; otherwise `null`. Both `initialHistoryLength`
128
+ * and `document.referrer` are checked since neither signal is reliable on
129
+ * its own.
130
+ */
131
+ private getSameOriginReferrerHref(): string | null {
132
+ if (this.initialHistoryLength <= 1 || !document.referrer) {
133
+ return null;
134
+ }
135
+ try {
136
+ const referrerUrl = new URL(document.referrer);
137
+ if (referrerUrl.origin !== window.location.origin) {
138
+ return null;
139
+ }
140
+ return referrerUrl.href;
141
+ } catch {
142
+ return null;
143
+ }
144
+ }
145
+
146
+ /**
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.
150
+ */
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);
157
+ }
158
+
74
159
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
75
160
  get effectiveFooterOrigin(): string {
76
161
  return (
@@ -79,6 +164,10 @@ export default class RedocReference extends LightningElement {
79
164
  }
80
165
 
81
166
  connectedCallback(): void {
167
+ // Snapshot history length before Redoc pushes its own hash entries,
168
+ // so it reflects real in-tab navigation rather than Redoc's churn.
169
+ this.initialHistoryLength = window.history.length;
170
+
82
171
  window.addEventListener("scroll", this.handleScrollAndResize);
83
172
  window.addEventListener("resize", this.handleScrollAndResize);
84
173
  }
@@ -304,6 +393,9 @@ export default class RedocReference extends LightningElement {
304
393
 
305
394
  this.appendFooterItems(apiContentDiv);
306
395
 
396
+ // Inject the multi-spec project header into Redoc's left menu only.
397
+ this.insertProjectHeaderInMenu(redocContainer);
398
+
307
399
  // Wait for footer to be rendered before updating styles
308
400
  requestAnimationFrame(() => {
309
401
  this.updateRedocThirdColumnStyle(redocContainer);
@@ -316,6 +408,65 @@ export default class RedocReference extends LightningElement {
316
408
  }
317
409
  }
318
410
 
411
+ /**
412
+ * Inserts the project header into Redoc for multi-spec reference sets.
413
+ */
414
+ private insertProjectHeaderInMenu(redocContainer: HTMLElement): void {
415
+ if (!this.showRedocHeader) {
416
+ return;
417
+ }
418
+
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
+ });
428
+ }
429
+
430
+ /**
431
+ * Builds a fresh project-title/spec-title header DOM node.
432
+ */
433
+ private buildProjectHeaderDom(): HTMLElement {
434
+ const wrapper = document.createElement("div");
435
+ wrapper.className = "redoc-project-header";
436
+
437
+ if (this.projectTitle) {
438
+ const backLink = document.createElement("a");
439
+ backLink.className = "redoc-project-back";
440
+ backLink.href = "#";
441
+ backLink.addEventListener("click", this.onBackClick);
442
+
443
+ const icon = createElement("dx-icon", { is: DxIcon });
444
+ Object.assign(icon, {
445
+ sprite: "utility",
446
+ symbol: "back",
447
+ size: "medium"
448
+ });
449
+ icon.classList.add("redoc-project-back-arrow");
450
+
451
+ const label = document.createElement("span");
452
+ label.className = "redoc-project-title";
453
+ label.textContent = this.projectTitle;
454
+
455
+ backLink.appendChild(icon);
456
+ backLink.appendChild(label);
457
+ wrapper.appendChild(backLink);
458
+ }
459
+
460
+ if (this.specTitle) {
461
+ const specEl = document.createElement("h2");
462
+ specEl.className = "redoc-spec-title dx-text-display-7";
463
+ specEl.textContent = this.specTitle;
464
+ wrapper.appendChild(specEl);
465
+ }
466
+
467
+ return wrapper;
468
+ }
469
+
319
470
  // Waits for Redoc's API content element to be rendered
320
471
  private async waitForApiContent(
321
472
  container: HTMLElement
package/.npmrc DELETED
@@ -1 +0,0 @@
1
- //registry.npmjs.org/:_authToken=${SFDOCS_NPM_AUTH_TOKEN}