@salesforcedevs/docs-components 1.20.13-redocly1 → 1.20.13-redocly2
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/package.json
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
<template lwc:if={showServerError}>
|
|
3
|
+
<dx-error
|
|
4
|
+
header="We lost communication with the space station."
|
|
5
|
+
subtitle="We encountered a server-related issue. (Don't worry, we're on it.) Refresh your browser or try again later."
|
|
6
|
+
image=""
|
|
7
|
+
code="500"
|
|
8
|
+
></dx-error>
|
|
9
|
+
</template>
|
|
10
|
+
<template lwc:elseif={showError}>
|
|
11
|
+
<dx-error
|
|
12
|
+
header="Head back to the space station"
|
|
13
|
+
subtitle="Looks like this page vaporized"
|
|
14
|
+
code="404"
|
|
15
|
+
image="https://a.sfdcstatic.com/developer-website/images/404.svg"
|
|
16
|
+
></dx-error>
|
|
17
|
+
</template>
|
|
18
|
+
<template lwc:else>
|
|
19
|
+
<slot></slot>
|
|
20
|
+
</template>
|
|
8
21
|
</template>
|
|
@@ -3,6 +3,7 @@ import { createElement, LightningElement, api } from "lwc";
|
|
|
3
3
|
import DocPhase from "doc/phase";
|
|
4
4
|
import DxFooter from "dx/footer";
|
|
5
5
|
import SprigSurvey from "doc/sprigSurvey";
|
|
6
|
+
import { throttle } from "throttle-debounce";
|
|
6
7
|
|
|
7
8
|
declare global {
|
|
8
9
|
interface Window {
|
|
@@ -22,20 +23,21 @@ type ReferenceConfig = {
|
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
declare const Sprig: (eventType: string, eventNme: string) => void;
|
|
26
|
+
const FOOTER_MARGIN_TOP = 142;
|
|
27
|
+
const THROTTLE_TIMEOUT = 200;
|
|
28
|
+
const REDOC_TIMEOUT = 10000;
|
|
29
|
+
const REDOC_CHECK_TIMEOUT = 100;
|
|
30
|
+
const LAYOUT_TIMEOUT = 100;
|
|
25
31
|
|
|
26
32
|
export default class RedocReference extends LightningElement {
|
|
27
33
|
private _referenceConfig: ReferenceConfig = { refList: [] };
|
|
28
34
|
private _parentDocPhaseInfo: string | null = null;
|
|
29
35
|
|
|
30
36
|
private layoutTimeoutId: number | null = null;
|
|
31
|
-
private isScrolling: boolean = false;
|
|
32
|
-
private previousTopValue = "";
|
|
33
37
|
private redocInitialized = false;
|
|
34
38
|
|
|
35
39
|
showError = false;
|
|
36
|
-
|
|
37
|
-
description: string =
|
|
38
|
-
"This API reference is currently unavailable. Please try again later.";
|
|
40
|
+
showServerError = false;
|
|
39
41
|
|
|
40
42
|
@api
|
|
41
43
|
get referenceConfig(): ReferenceConfig {
|
|
@@ -48,9 +50,7 @@ export default class RedocReference extends LightningElement {
|
|
|
48
50
|
typeof value === "string" ? JSON.parse(value) : value;
|
|
49
51
|
this._referenceConfig = refConfig;
|
|
50
52
|
} catch (error) {
|
|
51
|
-
this.
|
|
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.";
|
|
53
|
+
this.showServerError = true;
|
|
54
54
|
console.error(
|
|
55
55
|
"Failed to parse reference configuration data",
|
|
56
56
|
error
|
|
@@ -69,12 +69,12 @@ export default class RedocReference extends LightningElement {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
connectedCallback(): void {
|
|
72
|
-
window.addEventListener("scroll", this.
|
|
73
|
-
window.addEventListener("resize", this.
|
|
72
|
+
window.addEventListener("scroll", this.handleScroll);
|
|
73
|
+
window.addEventListener("resize", this.handleScroll);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
renderedCallback(): void {
|
|
77
|
-
if (!this.redocInitialized
|
|
77
|
+
if (!this.redocInitialized) {
|
|
78
78
|
this.initializeRedoc();
|
|
79
79
|
}
|
|
80
80
|
}
|
|
@@ -85,8 +85,8 @@ export default class RedocReference extends LightningElement {
|
|
|
85
85
|
this.layoutTimeoutId = null;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
window.removeEventListener("scroll", this.
|
|
89
|
-
window.removeEventListener("resize", this.
|
|
88
|
+
window.removeEventListener("scroll", this.handleScroll);
|
|
89
|
+
window.removeEventListener("resize", this.handleScroll);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
@api
|
|
@@ -94,23 +94,17 @@ export default class RedocReference extends LightningElement {
|
|
|
94
94
|
this._parentDocPhaseInfo = docPhaseInfo;
|
|
95
95
|
}
|
|
96
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
97
|
private adjustPosition = () => {
|
|
110
98
|
const redocContainer = this.getRedocContainer();
|
|
111
99
|
const sidebarMenuElement = redocContainer?.querySelector(
|
|
112
100
|
".redoc-wrap .menu-content"
|
|
113
101
|
) as HTMLElement;
|
|
102
|
+
const footer = redocContainer?.querySelector(
|
|
103
|
+
".redoc-wrap .api-content dx-footer"
|
|
104
|
+
) as HTMLElement;
|
|
105
|
+
const rightSidebar = redocContainer?.querySelector(
|
|
106
|
+
".redoc-wrap > div:last-child"
|
|
107
|
+
) as HTMLElement;
|
|
114
108
|
|
|
115
109
|
requestAnimationFrame(() => {
|
|
116
110
|
const globalNavElement = document.querySelector("hgf-c360nav");
|
|
@@ -119,6 +113,16 @@ export default class RedocReference extends LightningElement {
|
|
|
119
113
|
const docHeaderElement =
|
|
120
114
|
document.querySelector(".sticky-doc-header");
|
|
121
115
|
|
|
116
|
+
if (rightSidebar) {
|
|
117
|
+
rightSidebar.style.setProperty(
|
|
118
|
+
"bottom",
|
|
119
|
+
`${
|
|
120
|
+
(footer.getBoundingClientRect().height || 0) +
|
|
121
|
+
FOOTER_MARGIN_TOP
|
|
122
|
+
}px`
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
122
126
|
if (sidebarMenuElement) {
|
|
123
127
|
const globalNavHeight =
|
|
124
128
|
globalNavElement?.getBoundingClientRect().height || 0;
|
|
@@ -131,17 +135,18 @@ export default class RedocReference extends LightningElement {
|
|
|
131
135
|
globalNavHeight + contextNavHeight + docHeaderHeight
|
|
132
136
|
}px`;
|
|
133
137
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
);
|
|
139
|
-
this.previousTopValue = calculatedTopValue;
|
|
140
|
-
}
|
|
138
|
+
sidebarMenuElement.style.setProperty(
|
|
139
|
+
"--doc-c-redoc-sidebar-top",
|
|
140
|
+
calculatedTopValue
|
|
141
|
+
);
|
|
141
142
|
}
|
|
142
143
|
});
|
|
143
144
|
};
|
|
144
145
|
|
|
146
|
+
private handleScroll = throttle(THROTTLE_TIMEOUT, () =>
|
|
147
|
+
this.adjustPosition()
|
|
148
|
+
);
|
|
149
|
+
|
|
145
150
|
private getDocPhaseInfo(): string | null {
|
|
146
151
|
if (this._parentDocPhaseInfo) {
|
|
147
152
|
return this._parentDocPhaseInfo;
|
|
@@ -177,8 +182,9 @@ export default class RedocReference extends LightningElement {
|
|
|
177
182
|
}
|
|
178
183
|
}
|
|
179
184
|
|
|
180
|
-
private initializeRedoc(): void {
|
|
185
|
+
private async initializeRedoc(): Promise<void> {
|
|
181
186
|
try {
|
|
187
|
+
await this.waitForRedoc();
|
|
182
188
|
const selectedRef = this.getSelectedReference();
|
|
183
189
|
if (selectedRef) {
|
|
184
190
|
this.updateUrlWithReference(selectedRef);
|
|
@@ -199,20 +205,38 @@ export default class RedocReference extends LightningElement {
|
|
|
199
205
|
);
|
|
200
206
|
} else {
|
|
201
207
|
this.showError = true;
|
|
202
|
-
console.error(
|
|
203
|
-
"Failed to initialize Redoc, required params missing."
|
|
204
|
-
);
|
|
205
208
|
}
|
|
206
209
|
}
|
|
207
210
|
} catch (error) {
|
|
208
|
-
this.
|
|
209
|
-
|
|
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;
|
|
211
|
+
this.showServerError = true;
|
|
212
|
+
console.error("Failed to initialize Redoc:", error);
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
+
private waitForRedoc(timeout = REDOC_TIMEOUT): Promise<void> {
|
|
217
|
+
return new Promise((resolve, reject) => {
|
|
218
|
+
let resolved = false;
|
|
219
|
+
const startTime = Date.now();
|
|
220
|
+
|
|
221
|
+
const check = () => {
|
|
222
|
+
if (window.Redoc && !resolved) {
|
|
223
|
+
resolved = true;
|
|
224
|
+
resolve();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (Date.now() - startTime > timeout) {
|
|
229
|
+
reject(new Error("Redoc load timeout"));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
setTimeout(check, REDOC_CHECK_TIMEOUT);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
check();
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
216
240
|
private insertCustomLayoutElements(): void {
|
|
217
241
|
const redocContainer = this.getRedocContainer();
|
|
218
242
|
const apiContentDiv = redocContainer?.querySelector(".api-content");
|
|
@@ -234,7 +258,7 @@ export default class RedocReference extends LightningElement {
|
|
|
234
258
|
|
|
235
259
|
this.insertFooter(apiContentDiv as HTMLElement);
|
|
236
260
|
} catch (error) {
|
|
237
|
-
this.
|
|
261
|
+
this.showServerError = true;
|
|
238
262
|
console.error(
|
|
239
263
|
"Error showing banner and footer elements",
|
|
240
264
|
error
|
|
@@ -243,7 +267,7 @@ export default class RedocReference extends LightningElement {
|
|
|
243
267
|
} else {
|
|
244
268
|
this.layoutTimeoutId = window.setTimeout(
|
|
245
269
|
() => this.insertCustomLayoutElements(),
|
|
246
|
-
|
|
270
|
+
LAYOUT_TIMEOUT
|
|
247
271
|
);
|
|
248
272
|
}
|
|
249
273
|
}
|
|
@@ -270,11 +294,9 @@ export default class RedocReference extends LightningElement {
|
|
|
270
294
|
is: SprigSurvey
|
|
271
295
|
});
|
|
272
296
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
targetElement.appendChild(feedbackElement);
|
|
278
|
-
}
|
|
297
|
+
const wrapper = document.createElement("div");
|
|
298
|
+
wrapper.className = "sprig-survey-wrapper";
|
|
299
|
+
wrapper.appendChild(feedbackElement);
|
|
300
|
+
container.appendChild(wrapper);
|
|
279
301
|
}
|
|
280
302
|
}
|