@salesforcedevs/docs-components 1.31.0-md-doctoolbar-alpha → 1.31.1-lwr

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
@@ -18,7 +18,6 @@
18
18
  "doc/contentMedia",
19
19
  "doc/docXmlContent",
20
20
  "doc/lwcContentLayout",
21
- "doc/unifiedContentLayout",
22
21
  "doc/header",
23
22
  "doc/heading",
24
23
  "doc/headingAnchor",
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
1
  {
2
- "name": "@salesforcedevs/docs-components",
3
- "version": "1.31.0-md-doctoolbar-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
- }
2
+ "name": "@salesforcedevs/docs-components",
3
+ "version": "1.31.1-lwr",
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": "956930d90ebb6b2cc4fcc2c33b11199a28f1407a"
29
+ }
@@ -9,7 +9,7 @@ import { buildDocLinkClickHandler } from "dxUtils/analytics";
9
9
  import ContentActionToolbar from "doc/contentActionToolbar";
10
10
 
11
11
  const CONTENT_ACTION_TOOLBAR_TAG = "doc-content-action-toolbar";
12
- const PAGE_HEADING_SELECTOR = "h1";
12
+ const PAGE_HEADING_SELECTOR = "h1, doc-heading";
13
13
 
14
14
  type AnchorMap = { [key: string]: { intersect: boolean; id: string } };
15
15
 
@@ -286,7 +286,8 @@ export default class ContentLayout extends LightningElement {
286
286
 
287
287
  /**
288
288
  * Inserts the content action toolbar into the slotted content immediately
289
- * after the first H1 found inside this layout.
289
+ * after the first heading (any level) found inside the content body. This is
290
+ * the page's H1 when present, otherwise the first heading in document order.
290
291
  */
291
292
  protected updateContentActionToolbar(): void {
292
293
  if (!this.showContentActionToolbar || !this.sidebarValue) {
@@ -1,6 +1,7 @@
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)
4
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
5
+ var(--dx-g-spacing-xl)
5
6
  );
6
7
  }
@@ -3,12 +3,9 @@ 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";
7
6
  import SprigSurvey from "doc/sprigSurvey";
8
7
  import { throttle } from "throttle-debounce";
9
8
  import { pollUntil } from "dxUtils/async";
10
- import { toJson } from "dxUtils/normalizers";
11
- import type { OptionWithLink } from "typings/custom";
12
9
 
13
10
  declare global {
14
11
  interface Window {
@@ -40,10 +37,7 @@ type ReferenceConfig = {
40
37
  const SCROLL_THROTTLE_DELAY = 50;
41
38
  const ELEMENT_TIMEOUT = 10000;
42
39
  const ELEMENT_CHECK_INTERVAL = 100;
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";
40
+ const REFERENCES_SEGMENT = "/references/";
47
41
 
48
42
  export default class RedocReference extends LightningElement {
49
43
  private _referenceConfig: ReferenceConfig = { refList: [] };
@@ -53,7 +47,6 @@ export default class RedocReference extends LightningElement {
53
47
  private docHeaderElement: Element | null = null;
54
48
  private docPhaseWrapperElement: Element | null = null;
55
49
  private lastSidebarTop = 0;
56
- private _languages: OptionWithLink[] = [];
57
50
 
58
51
  /**
59
52
  * History length captured at mount (pre-Redoc), used by `onBackClick` to
@@ -98,86 +91,19 @@ export default class RedocReference extends LightningElement {
98
91
  * Project title (same value passed to `<doc-header>` as `subtitle`). Used
99
92
  * inside the Redoc-rendered UI to label the parent project.
100
93
  */
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;
94
+ @api projectTitle: string | null = "All Reference";
137
95
 
138
96
  get specTitle(): string | null {
139
97
  return this.getSelectedReference()?.title ?? null;
140
98
  }
141
99
 
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
-
171
100
  /**
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.
101
+ * Whether to show the project header (only for multi-spec reference sets).
175
102
  */
176
103
  get showRedocHeader(): boolean {
177
- return (
178
- (this.isReferenceContentType && this.isMultiSpecSet) ||
179
- this.isDocContentType
180
- );
104
+ const refCount = this._referenceConfig?.refList?.length ?? 0;
105
+ const isMultiSpecSet = refCount > 1;
106
+ return isMultiSpecSet && !!(this.projectTitle || this.specTitle);
181
107
  }
182
108
 
183
109
  /**
@@ -185,68 +111,16 @@ export default class RedocReference extends LightningElement {
185
111
  */
186
112
  private onBackClick = (event: Event): void => {
187
113
  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 {
238
114
  const referrerHref = this.getSameOriginReferrerHref();
239
- if (!referrerHref) {
115
+ if (referrerHref) {
116
+ window.location.href = referrerHref;
240
117
  return;
241
118
  }
242
-
243
- const referrerUrl = new URL(referrerHref);
244
- if (this.isLocaleHref(referrerUrl.pathname)) {
245
- return;
119
+ const fallbackHref = this.getReferencesRootHref();
120
+ if (fallbackHref) {
121
+ window.location.href = fallbackHref;
246
122
  }
247
-
248
- this.setBackTargetInSession(referrerHref);
249
- }
123
+ };
250
124
 
251
125
  /**
252
126
  * Returns the referrer URL when the page was reached via in-tab navigation
@@ -270,16 +144,16 @@ export default class RedocReference extends LightningElement {
270
144
  }
271
145
 
272
146
  /**
273
- * switching locale on this same page.
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.
274
150
  */
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
- });
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);
283
157
  }
284
158
 
285
159
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
@@ -294,9 +168,6 @@ export default class RedocReference extends LightningElement {
294
168
  // so it reflects real in-tab navigation rather than Redoc's churn.
295
169
  this.initialHistoryLength = window.history.length;
296
170
 
297
- // Track the back target, preserving it across locale switches
298
- this.trackBackTarget();
299
-
300
171
  window.addEventListener("scroll", this.handleScrollAndResize);
301
172
  window.addEventListener("resize", this.handleScrollAndResize);
302
173
  }
@@ -523,7 +394,7 @@ export default class RedocReference extends LightningElement {
523
394
  this.appendFooterItems(apiContentDiv);
524
395
 
525
396
  // Inject the multi-spec project header into Redoc's left menu only.
526
- this.insertSidebarNav(redocContainer);
397
+ this.insertProjectHeaderInMenu(redocContainer);
527
398
 
528
399
  // Wait for footer to be rendered before updating styles
529
400
  requestAnimationFrame(() => {
@@ -538,46 +409,22 @@ export default class RedocReference extends LightningElement {
538
409
  }
539
410
 
540
411
  /**
541
- * Inserts the project header and LNB footer into Redoc.
412
+ * Inserts the project header into Redoc for multi-spec reference sets.
542
413
  */
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
- });
554
- }
555
-
556
- // Locale picker
557
- if (this.hasLocalePicker) {
558
- const menuContent = redocContainer.querySelector(".menu-content");
559
- menuContent?.appendChild(this.buildLocalePickerDom());
414
+ private insertProjectHeaderInMenu(redocContainer: HTMLElement): void {
415
+ if (!this.showRedocHeader) {
416
+ return;
560
417
  }
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
418
 
580
- return wrapper;
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
+ });
581
428
  }
582
429
 
583
430
  /**
@@ -1,19 +0,0 @@
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
- }
@@ -1,29 +0,0 @@
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>
@@ -1,88 +0,0 @@
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
- @api devCenter: any = null;
48
- @api brand: any = null;
49
- @api showContentActionToolbar = false;
50
-
51
- /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). */
52
- @api origin: string | null = null;
53
-
54
- /** Article name from breadcrumbs, used as share title (e.g. for social share). */
55
- @api shareTitle: string | null = null;
56
-
57
- /** Optional Twitter "via" handle (e.g. SalesforceDevs) for social share. */
58
- @api twitterVia: string | null = null;
59
-
60
- @api hideFooter = false;
61
-
62
- private _docPhaseInfo: string | null = null;
63
- private _sidebarContent: unknown = null;
64
-
65
- @api
66
- get docPhaseInfo(): string | null {
67
- return this._docPhaseInfo;
68
- }
69
-
70
- set docPhaseInfo(value: string | null) {
71
- this._docPhaseInfo = value || null;
72
- }
73
-
74
- @api
75
- get sidebarContent(): unknown {
76
- return this._sidebarContent;
77
- }
78
-
79
- set sidebarContent(value: string) {
80
- this._sidebarContent = decorateTopicsWithForwardArrow(
81
- toJson(value)?.topics
82
- );
83
- }
84
-
85
- private get enableFooter(): boolean {
86
- return !this.hideFooter;
87
- }
88
- }