@salesforcedevs/docs-components 1.30.0 → 1.30.1-locale-picker
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 +1 -0
- package/package.json +29 -28
- package/src/modules/doc/amfReference/amfReference.ts +1 -10
- package/src/modules/doc/redocReference/redocReference.ts +100 -24
- package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.css +19 -0
- package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.html +26 -0
- package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.ts +85 -0
- package/LICENSE +0 -12
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
"name": "@salesforcedevs/docs-components",
|
|
3
|
+
"version": "1.30.1-locale-picker",
|
|
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
|
+
"stableVersion": "1.30.1"
|
|
30
|
+
}
|
|
@@ -73,16 +73,7 @@ export default class AmfReference extends LightningElement {
|
|
|
73
73
|
return this.isSpecBasedReference(this._currentReferenceId);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
* Content action toolbar is only enabled for markdown-based references in the en-us locale.
|
|
78
|
-
*/
|
|
79
|
-
get showContentActionToolbar(): boolean {
|
|
80
|
-
if (this.showSpecBasedReference) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
const locale = this.language?.toLowerCase() ?? "en-us";
|
|
84
|
-
return locale === "en-us";
|
|
85
|
-
}
|
|
76
|
+
@api showContentActionToolbar = false;
|
|
86
77
|
|
|
87
78
|
@api
|
|
88
79
|
get referenceSetConfig(): ReferenceSetConfig {
|
|
@@ -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,7 @@ type ReferenceConfig = {
|
|
|
37
40
|
const SCROLL_THROTTLE_DELAY = 50;
|
|
38
41
|
const ELEMENT_TIMEOUT = 10000;
|
|
39
42
|
const ELEMENT_CHECK_INTERVAL = 100;
|
|
40
|
-
const
|
|
43
|
+
const DEFAULT_PROJECT_TITLE = "All Reference";
|
|
41
44
|
|
|
42
45
|
export default class RedocReference extends LightningElement {
|
|
43
46
|
private _referenceConfig: ReferenceConfig = { refList: [] };
|
|
@@ -47,6 +50,8 @@ export default class RedocReference extends LightningElement {
|
|
|
47
50
|
private docHeaderElement: Element | null = null;
|
|
48
51
|
private docPhaseWrapperElement: Element | null = null;
|
|
49
52
|
private lastSidebarTop = 0;
|
|
53
|
+
private _languages: OptionWithLink[] = [];
|
|
54
|
+
private langValuePath: string = "id";
|
|
50
55
|
|
|
51
56
|
/**
|
|
52
57
|
* History length captured at mount (pre-Redoc), used by `onBackClick` to
|
|
@@ -91,19 +96,79 @@ export default class RedocReference extends LightningElement {
|
|
|
91
96
|
* Project title (same value passed to `<doc-header>` as `subtitle`). Used
|
|
92
97
|
* inside the Redoc-rendered UI to label the parent project.
|
|
93
98
|
*/
|
|
94
|
-
@api
|
|
99
|
+
@api
|
|
100
|
+
get projectTitle(): string | null {
|
|
101
|
+
return this.isDocContentType
|
|
102
|
+
? this._projectTitle
|
|
103
|
+
: DEFAULT_PROJECT_TITLE;
|
|
104
|
+
}
|
|
105
|
+
set projectTitle(value: string | null) {
|
|
106
|
+
this._projectTitle = value;
|
|
107
|
+
}
|
|
108
|
+
private _projectTitle: string | null = null;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Href to navigate to when the back link is clicked AND there is no
|
|
112
|
+
* usable referrer (e.g. the user opened the page directly in a fresh
|
|
113
|
+
* tab).
|
|
114
|
+
*/
|
|
115
|
+
@api headerHref: string | null = null;
|
|
116
|
+
|
|
117
|
+
@api
|
|
118
|
+
get contentType(): string {
|
|
119
|
+
return this._contentType;
|
|
120
|
+
}
|
|
121
|
+
set contentType(value: string) {
|
|
122
|
+
this._contentType = value;
|
|
123
|
+
}
|
|
124
|
+
private _contentType: string = "";
|
|
125
|
+
|
|
126
|
+
@api
|
|
127
|
+
get languages(): OptionWithLink[] {
|
|
128
|
+
return this._languages;
|
|
129
|
+
}
|
|
130
|
+
set languages(value: string | OptionWithLink[]) {
|
|
131
|
+
this._languages = toJson(value) || [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Currently selected locale, matched against `langValuePath`. */
|
|
135
|
+
@api language: string | null = null;
|
|
95
136
|
|
|
96
137
|
get specTitle(): string | null {
|
|
97
138
|
return this.getSelectedReference()?.title ?? null;
|
|
98
139
|
}
|
|
99
140
|
|
|
141
|
+
get isDocContentType(): boolean {
|
|
142
|
+
return this.contentType === "docs";
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get isReferenceContentType(): boolean {
|
|
146
|
+
return this.contentType === "references";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
get isMultiSpecSet(): boolean {
|
|
150
|
+
const refCount = this.referenceConfig?.refList?.length ?? 0;
|
|
151
|
+
return refCount > 1;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Only for the docs content type and when more than one localized
|
|
156
|
+
* spec is available
|
|
157
|
+
*/
|
|
158
|
+
get hasLocalePicker(): boolean {
|
|
159
|
+
return this.isDocContentType && this.languages.length > 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
100
162
|
/**
|
|
101
|
-
* Whether to show the project header
|
|
163
|
+
* Whether to show the project header. Shown for multi-spec reference
|
|
164
|
+
* sets, and for any docs-content spec topic so it always has a back
|
|
165
|
+
* link.
|
|
102
166
|
*/
|
|
103
167
|
get showRedocHeader(): boolean {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
168
|
+
return (
|
|
169
|
+
(this.isReferenceContentType && this.isMultiSpecSet) ||
|
|
170
|
+
this.isDocContentType
|
|
171
|
+
);
|
|
107
172
|
}
|
|
108
173
|
|
|
109
174
|
/**
|
|
@@ -114,11 +179,8 @@ export default class RedocReference extends LightningElement {
|
|
|
114
179
|
const referrerHref = this.getSameOriginReferrerHref();
|
|
115
180
|
if (referrerHref) {
|
|
116
181
|
window.location.href = referrerHref;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const fallbackHref = this.getReferencesRootHref();
|
|
120
|
-
if (fallbackHref) {
|
|
121
|
-
window.location.href = fallbackHref;
|
|
182
|
+
} else if (this.headerHref) {
|
|
183
|
+
window.location.href = this.headerHref;
|
|
122
184
|
}
|
|
123
185
|
};
|
|
124
186
|
|
|
@@ -143,19 +205,6 @@ export default class RedocReference extends LightningElement {
|
|
|
143
205
|
}
|
|
144
206
|
}
|
|
145
207
|
|
|
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
|
-
|
|
159
208
|
/** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
|
|
160
209
|
get effectiveFooterOrigin(): string {
|
|
161
210
|
return (
|
|
@@ -425,6 +474,33 @@ export default class RedocReference extends LightningElement {
|
|
|
425
474
|
target.firstChild
|
|
426
475
|
);
|
|
427
476
|
});
|
|
477
|
+
|
|
478
|
+
// Locale picker
|
|
479
|
+
if (this.hasLocalePicker) {
|
|
480
|
+
const menuContent = redocContainer.querySelector(".menu-content");
|
|
481
|
+
menuContent?.appendChild(this.buildLocalePickerDom());
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Builds the locale picker DOM by reusing `dx-sidebar-footer-nav`
|
|
487
|
+
*/
|
|
488
|
+
private buildLocalePickerDom(): HTMLElement {
|
|
489
|
+
const wrapper = document.createElement("div");
|
|
490
|
+
wrapper.className = "redoc-footer-nav";
|
|
491
|
+
|
|
492
|
+
const picker = createElement("dx-sidebar-footer-nav", {
|
|
493
|
+
is: SidebarFooterNav
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
Object.assign(picker, {
|
|
497
|
+
languages: this.languages,
|
|
498
|
+
language: this.language,
|
|
499
|
+
langValuePath: this.langValuePath
|
|
500
|
+
});
|
|
501
|
+
wrapper.appendChild(picker);
|
|
502
|
+
|
|
503
|
+
return wrapper;
|
|
428
504
|
}
|
|
429
505
|
|
|
430
506
|
/**
|
|
@@ -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,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.
|