@salesforcedevs/docs-components 1.20.9 → 1.20.13-redocly1
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 +2 -2
- package/src/modules/doc/redocReference/redocReference.css +6 -0
- package/src/modules/doc/redocReference/redocReference.html +8 -0
- package/src/modules/doc/redocReference/redocReference.ts +280 -0
- package/src/modules/doc/xmlContent/xmlContent.html +1 -1
- package/src/modules/doc/xmlContent/xmlContent.ts +1 -1
- package/LICENSE +0 -12
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.13-redocly1",
|
|
4
4
|
"description": "Docs Lightning web components for DSC",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@types/lodash.orderby": "4.6.9",
|
|
26
26
|
"@types/lodash.uniqby": "4.7.9"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
|
|
29
29
|
"volta": {
|
|
30
30
|
"node": "20.19.0",
|
|
31
31
|
"yarn": "1.22.19"
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/* eslint-disable @lwc/lwc/no-document-query */
|
|
2
|
+
import { createElement, LightningElement, api } from "lwc";
|
|
3
|
+
import DocPhase from "doc/phase";
|
|
4
|
+
import DxFooter from "dx/footer";
|
|
5
|
+
import SprigSurvey from "doc/sprigSurvey";
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
Redoc: any;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type ReferenceItem = {
|
|
14
|
+
source: string;
|
|
15
|
+
href: string;
|
|
16
|
+
isSelected?: boolean;
|
|
17
|
+
docPhase?: any;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type ReferenceConfig = {
|
|
21
|
+
refList: ReferenceItem[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
declare const Sprig: (eventType: string, eventNme: string) => void;
|
|
25
|
+
|
|
26
|
+
export default class RedocReference extends LightningElement {
|
|
27
|
+
private _referenceConfig: ReferenceConfig = { refList: [] };
|
|
28
|
+
private _parentDocPhaseInfo: string | null = null;
|
|
29
|
+
|
|
30
|
+
private layoutTimeoutId: number | null = null;
|
|
31
|
+
private isScrolling: boolean = false;
|
|
32
|
+
private previousTopValue = "";
|
|
33
|
+
private redocInitialized = false;
|
|
34
|
+
|
|
35
|
+
showError = false;
|
|
36
|
+
title: string = "API Documentation Unavailable";
|
|
37
|
+
description: string =
|
|
38
|
+
"This API reference is currently unavailable. Please try again later.";
|
|
39
|
+
|
|
40
|
+
@api
|
|
41
|
+
get referenceConfig(): ReferenceConfig {
|
|
42
|
+
return this._referenceConfig;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
set referenceConfig(value: string | ReferenceConfig) {
|
|
46
|
+
try {
|
|
47
|
+
const refConfig =
|
|
48
|
+
typeof value === "string" ? JSON.parse(value) : value;
|
|
49
|
+
this._referenceConfig = refConfig;
|
|
50
|
+
} catch (error) {
|
|
51
|
+
this.title = "Failed to parse reference configuration data";
|
|
52
|
+
this.description =
|
|
53
|
+
"An error occurred while reading/parsing the reference configuration. Please check the config file for syntax errors or invalid references and try again.";
|
|
54
|
+
console.error(
|
|
55
|
+
"Failed to parse reference configuration data",
|
|
56
|
+
error
|
|
57
|
+
);
|
|
58
|
+
this._referenceConfig = { refList: [] };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@api
|
|
63
|
+
get docPhaseInfo(): string | null {
|
|
64
|
+
return this._parentDocPhaseInfo;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
set docPhaseInfo(value: string) {
|
|
68
|
+
this._parentDocPhaseInfo = value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
connectedCallback(): void {
|
|
72
|
+
window.addEventListener("scroll", this.handleScrollWithThrottle);
|
|
73
|
+
window.addEventListener("resize", this.handleScrollWithThrottle);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
renderedCallback(): void {
|
|
77
|
+
if (!this.redocInitialized && window.Redoc) {
|
|
78
|
+
this.initializeRedoc();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
disconnectedCallback(): void {
|
|
83
|
+
if (this.layoutTimeoutId) {
|
|
84
|
+
clearTimeout(this.layoutTimeoutId);
|
|
85
|
+
this.layoutTimeoutId = null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
window.removeEventListener("scroll", this.handleScrollWithThrottle);
|
|
89
|
+
window.removeEventListener("resize", this.handleScrollWithThrottle);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@api
|
|
93
|
+
setDocPhaseInfo(docPhaseInfo: string): void {
|
|
94
|
+
this._parentDocPhaseInfo = docPhaseInfo;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private handleScrollWithThrottle = () => {
|
|
98
|
+
if (!this.isScrolling) {
|
|
99
|
+
this.isScrolling = true;
|
|
100
|
+
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
this.adjustPosition();
|
|
103
|
+
}, 200);
|
|
104
|
+
|
|
105
|
+
this.isScrolling = false;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
private adjustPosition = () => {
|
|
110
|
+
const redocContainer = this.getRedocContainer();
|
|
111
|
+
const sidebarMenuElement = redocContainer?.querySelector(
|
|
112
|
+
".redoc-wrap .menu-content"
|
|
113
|
+
) as HTMLElement;
|
|
114
|
+
|
|
115
|
+
requestAnimationFrame(() => {
|
|
116
|
+
const globalNavElement = document.querySelector("hgf-c360nav");
|
|
117
|
+
const contextNavElement =
|
|
118
|
+
document.querySelector("hgf-c360contextnav");
|
|
119
|
+
const docHeaderElement =
|
|
120
|
+
document.querySelector(".sticky-doc-header");
|
|
121
|
+
|
|
122
|
+
if (sidebarMenuElement) {
|
|
123
|
+
const globalNavHeight =
|
|
124
|
+
globalNavElement?.getBoundingClientRect().height || 0;
|
|
125
|
+
const contextNavHeight =
|
|
126
|
+
contextNavElement?.getBoundingClientRect().height || 0;
|
|
127
|
+
const docHeaderHeight =
|
|
128
|
+
docHeaderElement?.getBoundingClientRect().height || 0;
|
|
129
|
+
|
|
130
|
+
const calculatedTopValue = `${
|
|
131
|
+
globalNavHeight + contextNavHeight + docHeaderHeight
|
|
132
|
+
}px`;
|
|
133
|
+
|
|
134
|
+
if (calculatedTopValue !== this.previousTopValue) {
|
|
135
|
+
sidebarMenuElement.style.setProperty(
|
|
136
|
+
"--doc-c-redoc-sidebar-top",
|
|
137
|
+
calculatedTopValue
|
|
138
|
+
);
|
|
139
|
+
this.previousTopValue = calculatedTopValue;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
private getDocPhaseInfo(): string | null {
|
|
146
|
+
if (this._parentDocPhaseInfo) {
|
|
147
|
+
return this._parentDocPhaseInfo;
|
|
148
|
+
}
|
|
149
|
+
const selectedRef = this.getSelectedReference();
|
|
150
|
+
return selectedRef?.docPhase
|
|
151
|
+
? JSON.stringify(selectedRef.docPhase)
|
|
152
|
+
: null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private getSelectedReference(): ReferenceItem | null {
|
|
156
|
+
return this._referenceConfig?.refList?.length
|
|
157
|
+
? this._referenceConfig.refList.find((ref) => ref.isSelected) ||
|
|
158
|
+
this._referenceConfig.refList[0]
|
|
159
|
+
: null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private getRedocContainer(): HTMLElement | null {
|
|
163
|
+
return document.querySelector(".redoc-container");
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private updateUrlWithReference(selectedRef: ReferenceItem): void {
|
|
167
|
+
if (selectedRef?.href) {
|
|
168
|
+
const parentReferencePath = selectedRef.href;
|
|
169
|
+
const currentUrl = window.location;
|
|
170
|
+
const existingParams = currentUrl.search + currentUrl.hash;
|
|
171
|
+
|
|
172
|
+
window.history.pushState(
|
|
173
|
+
{},
|
|
174
|
+
"",
|
|
175
|
+
`${parentReferencePath}${existingParams}`
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private initializeRedoc(): void {
|
|
181
|
+
try {
|
|
182
|
+
const selectedRef = this.getSelectedReference();
|
|
183
|
+
if (selectedRef) {
|
|
184
|
+
this.updateUrlWithReference(selectedRef);
|
|
185
|
+
|
|
186
|
+
const specUrl = selectedRef.source;
|
|
187
|
+
const redocContainer = this.getRedocContainer();
|
|
188
|
+
if (specUrl && redocContainer) {
|
|
189
|
+
this.redocInitialized = true;
|
|
190
|
+
window.Redoc.init(
|
|
191
|
+
specUrl,
|
|
192
|
+
{
|
|
193
|
+
expandResponses: "200,400"
|
|
194
|
+
},
|
|
195
|
+
redocContainer,
|
|
196
|
+
() => {
|
|
197
|
+
this.insertCustomLayoutElements();
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
} else {
|
|
201
|
+
this.showError = true;
|
|
202
|
+
console.error(
|
|
203
|
+
"Failed to initialize Redoc, required params missing."
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
} catch (error) {
|
|
208
|
+
this.title = "Failed to load API specification";
|
|
209
|
+
this.description =
|
|
210
|
+
"An error occurred while trying to initialize Redoc. This may be due to a missing or invalid source in the configuration file, or a network connectivity issue. Please verify the source path and your internet connection and try again.";
|
|
211
|
+
console.error("Failed to load API specification", error);
|
|
212
|
+
this.showError = true;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private insertCustomLayoutElements(): void {
|
|
217
|
+
const redocContainer = this.getRedocContainer();
|
|
218
|
+
const apiContentDiv = redocContainer?.querySelector(".api-content");
|
|
219
|
+
if (apiContentDiv) {
|
|
220
|
+
(apiContentDiv as HTMLElement).setAttribute("lwc:dom", "manual");
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
const docPhaseInfo = this.getDocPhaseInfo();
|
|
224
|
+
if (docPhaseInfo) {
|
|
225
|
+
this.insertDocPhase(
|
|
226
|
+
apiContentDiv as HTMLElement,
|
|
227
|
+
docPhaseInfo
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (typeof Sprig !== "undefined") {
|
|
232
|
+
this.insertSprigSurvey(apiContentDiv as HTMLElement);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
this.insertFooter(apiContentDiv as HTMLElement);
|
|
236
|
+
} catch (error) {
|
|
237
|
+
this.showError = true;
|
|
238
|
+
console.error(
|
|
239
|
+
"Error showing banner and footer elements",
|
|
240
|
+
error
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
this.layoutTimeoutId = window.setTimeout(
|
|
245
|
+
() => this.insertCustomLayoutElements(),
|
|
246
|
+
100
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private insertDocPhase(container: HTMLElement, docPhaseInfo: string): void {
|
|
252
|
+
const docPhaseElement = createElement("doc-phase", { is: DocPhase });
|
|
253
|
+
Object.assign(docPhaseElement, { docPhaseInfo });
|
|
254
|
+
|
|
255
|
+
const wrapper = document.createElement("div");
|
|
256
|
+
wrapper.className = "doc-phase-wrapper";
|
|
257
|
+
wrapper.appendChild(docPhaseElement);
|
|
258
|
+
|
|
259
|
+
container.insertBefore(wrapper, container.firstChild);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
private insertFooter(container: HTMLElement): void {
|
|
263
|
+
const footerElement = createElement("dx-footer", { is: DxFooter });
|
|
264
|
+
Object.assign(footerElement, { variant: "no-signup" });
|
|
265
|
+
container.appendChild(footerElement);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
private insertSprigSurvey(container: HTMLElement): void {
|
|
269
|
+
const feedbackElement = createElement("doc-sprig-survey", {
|
|
270
|
+
is: SprigSurvey
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
// targeting the last element of middle section of page
|
|
274
|
+
const targetElement =
|
|
275
|
+
container.lastElementChild?.firstElementChild?.firstElementChild;
|
|
276
|
+
if (targetElement) {
|
|
277
|
+
targetElement.appendChild(feedbackElement);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
<div lwc:if={showVersionPicker} slot="sidebar-header">
|
|
25
25
|
<doc-version-picker
|
|
26
26
|
data-type="version"
|
|
27
|
-
analytics-event="
|
|
27
|
+
analytics-event="custEv_linkClick"
|
|
28
28
|
analytics-payload={ANALYTICS_PAYLOAD}
|
|
29
29
|
versions={versionOptions}
|
|
30
30
|
selected-version={version}
|
|
@@ -355,7 +355,7 @@ export default class DocXmlContent extends LightningElementWithState<{
|
|
|
355
355
|
);
|
|
356
356
|
this.pageReference.docId = this.language!.url;
|
|
357
357
|
|
|
358
|
-
trackGTM(event.target!, "
|
|
358
|
+
trackGTM(event.target!, "custEv_linkClick", {
|
|
359
359
|
click_text: event.detail,
|
|
360
360
|
element_title: "language selector",
|
|
361
361
|
click_url: `${window.location.origin}${this.pageReferenceToString(
|
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.
|