@salesforcedevs/docs-components 1.28.7 → 1.29.0-doc-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
@@ -17,6 +17,7 @@
17
17
  "doc/contentMedia",
18
18
  "doc/docXmlContent",
19
19
  "doc/lwcContentLayout",
20
+ "doc/unifiedContentLayout",
20
21
  "doc/header",
21
22
  "doc/heading",
22
23
  "doc/headingAnchor",
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
- "name": "@salesforcedevs/docs-components",
3
- "version": "1.28.7",
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": "aedcb1c0ab8cb16ff85f61c0d3ed0c908502d843"
29
- }
2
+ "name": "@salesforcedevs/docs-components",
3
+ "version": "1.29.0-doc-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
+ }
@@ -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 {
@@ -204,6 +205,7 @@ export default class AmfReference extends LightningElement {
204
205
 
205
206
  _boundOnApiNavigationChanged;
206
207
  _boundUpdateSelectedItemFromUrlQuery;
208
+ _boundOnPageShow;
207
209
 
208
210
  constructor() {
209
211
  super();
@@ -212,6 +214,7 @@ export default class AmfReference extends LightningElement {
212
214
  this.onApiNavigationChanged.bind(this);
213
215
  this._boundUpdateSelectedItemFromUrlQuery =
214
216
  this.updateSelectedItemFromUrlQuery.bind(this);
217
+ this._boundOnPageShow = this.onPageShow.bind(this);
215
218
  }
216
219
 
217
220
  connectedCallback(): void {
@@ -223,6 +226,7 @@ export default class AmfReference extends LightningElement {
223
226
  "popstate",
224
227
  this._boundUpdateSelectedItemFromUrlQuery
225
228
  );
229
+ window.addEventListener("pageshow", this._boundOnPageShow);
226
230
  }
227
231
 
228
232
  disconnectedCallback(): void {
@@ -234,6 +238,22 @@ export default class AmfReference extends LightningElement {
234
238
  "popstate",
235
239
  this._boundUpdateSelectedItemFromUrlQuery
236
240
  );
241
+ window.removeEventListener("pageshow", this._boundOnPageShow);
242
+ }
243
+
244
+ /**
245
+ * On bfcache restore, reset the sidebar selection so the tree re-syncs
246
+ * its highlighted tile with the current URL.
247
+ */
248
+ protected onPageShow(event: PageTransitionEvent): void {
249
+ if (!event.persisted) {
250
+ return;
251
+ }
252
+ const currentPath = window.location.pathname;
253
+ this.selectedSidebarValue = "";
254
+ Promise.resolve().then(() => {
255
+ this.selectedSidebarValue = currentPath;
256
+ });
237
257
  }
238
258
 
239
259
  renderedCallback(): void {
@@ -443,16 +463,21 @@ export default class AmfReference extends LightningElement {
443
463
  let navItemChildren = [] as ParsedMarkdownTopic[];
444
464
  let isChildrenLoading = false;
445
465
  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;
466
+ if (amfConfig.amf) {
467
+ if (amfConfig.isSelected) {
468
+ const amfPromise = this.fetchAmf(amfConfig).then(
469
+ (amfJson) => {
470
+ this.updateModel(amfConfig.id, amfJson);
471
+ this.assignNavigationItemsFromAmf(
472
+ amfConfig,
473
+ index
474
+ );
475
+ }
476
+ );
477
+ this.amfFetchPromiseMap[amfConfig.id] = amfPromise;
478
+ }
479
+ isChildrenLoading = true;
454
480
  }
455
- isChildrenLoading = true;
456
481
  } else {
457
482
  const isExpandChildrenEnabled = this.isExpandChildrenEnabled(
458
483
  amfConfig.id
@@ -473,13 +498,30 @@ export default class AmfReference extends LightningElement {
473
498
  amfConfig.isSelected ||
474
499
  this.isExpandChildrenEnabled(amfConfig.id),
475
500
  children: navItemChildren,
476
- isChildrenLoading
501
+ isChildrenLoading,
502
+ showForwardArrow: this.resolveNavRenderWith(amfConfig)
477
503
  };
478
504
  this.parentReferenceUrls.push(amfConfig.href);
479
505
  }
480
506
  this.navigation = navAmfOrder;
481
507
  }
482
508
 
509
+ /**
510
+ * Determines whether the sidebar tile should render a forward arrow for
511
+ * this reference. Honors `redoc` set on the config, and also infers it
512
+ * for non-markdown references that have no AMF URL (i.e. those rendered
513
+ * by Redoc).
514
+ */
515
+ private resolveNavRenderWith(amfConfig: AmfConfig): boolean {
516
+ if (amfConfig.renderWith) {
517
+ return amfConfig.renderWith === "redoc";
518
+ }
519
+ return (
520
+ amfConfig.referenceType !== REFERENCE_TYPES.markdown &&
521
+ !amfConfig.amf
522
+ );
523
+ }
524
+
483
525
  /**
484
526
  * Returns a boolean indicating whether the children should be expanded or not.
485
527
  */
@@ -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 {
@@ -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}
@@ -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
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }
@@ -0,0 +1,26 @@
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
+ origin={origin}
18
+ >
19
+ <doc-phase
20
+ slot="doc-phase"
21
+ lwc:if={docPhaseInfo}
22
+ doc-phase-info={docPhaseInfo}
23
+ ></doc-phase>
24
+ <slot></slot>
25
+ </doc-content-layout>
26
+ </template>
@@ -0,0 +1,85 @@
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
+ /**
14
+ * Translates per-topic `topicType` into the generic `showForwardArrow` flag
15
+ * that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc).
16
+ */
17
+ function decorateTopicsWithForwardArrow(
18
+ topics: Array<TreeNode & { topicType?: string }> | undefined
19
+ ): TreeNode[] | undefined {
20
+ return topics?.map((topic) => {
21
+ const { topicType, ...decorated } = topic;
22
+ if (topicType === TOPIC_TYPE_SPEC) {
23
+ decorated.showForwardArrow = true;
24
+ }
25
+ if (decorated.children) {
26
+ decorated.children = decorateTopicsWithForwardArrow(
27
+ decorated.children
28
+ );
29
+ }
30
+ return decorated;
31
+ });
32
+ }
33
+
34
+ /**
35
+ * Wrapper around `doc-content-layout` for the "docs" content type emitted by
36
+ * the `DocsContentTypeParser`.
37
+ */
38
+ export default class UnifiedContentLayout extends LightningElement {
39
+ @api breadcrumbs: string | null = null;
40
+ @api sidebarHeader?: string;
41
+ @api sidebarValue?: string;
42
+ @api tocTitle?: string;
43
+ @api tocOptions?: string;
44
+ @api tocAriaLevel?: string;
45
+ @api languages?: OptionWithLink[];
46
+ @api language?: string;
47
+
48
+ /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). */
49
+ @api origin: string | null = null;
50
+
51
+ /** Article name from breadcrumbs, used as share title (e.g. for social share). */
52
+ @api shareTitle: string | null = null;
53
+
54
+ /** Optional Twitter "via" handle (e.g. SalesforceDevs) for social share. */
55
+ @api twitterVia: string | null = null;
56
+
57
+ @api hideFooter = false;
58
+
59
+ private _docPhaseInfo: string | null = null;
60
+ private _sidebarContent: unknown = null;
61
+
62
+ @api
63
+ get docPhaseInfo(): string | null {
64
+ return this._docPhaseInfo;
65
+ }
66
+
67
+ set docPhaseInfo(value: string | null) {
68
+ this._docPhaseInfo = value || null;
69
+ }
70
+
71
+ @api
72
+ get sidebarContent(): unknown {
73
+ return this._sidebarContent;
74
+ }
75
+
76
+ set sidebarContent(value: string) {
77
+ this._sidebarContent = decorateTopicsWithForwardArrow(
78
+ toJson(value)?.topics
79
+ );
80
+ }
81
+
82
+ private get enableFooter(): boolean {
83
+ return !this.hideFooter;
84
+ }
85
+ }
package/LICENSE DELETED
@@ -1,12 +0,0 @@
1
- Copyright (c) 2020, Salesforce.com, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
-
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
-
10
- * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.