@salesforcedevs/docs-components 1.20.13-redocly → 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 {
|
|
@@ -21,16 +22,22 @@ type ReferenceConfig = {
|
|
|
21
22
|
refList: ReferenceItem[];
|
|
22
23
|
};
|
|
23
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;
|
|
31
|
+
|
|
24
32
|
export default class RedocReference extends LightningElement {
|
|
25
33
|
private _referenceConfig: ReferenceConfig = { refList: [] };
|
|
26
34
|
private _parentDocPhaseInfo: string | null = null;
|
|
27
35
|
|
|
28
36
|
private layoutTimeoutId: number | null = null;
|
|
29
|
-
private isScrolling: boolean = false;
|
|
30
|
-
private previousTopValue = "";
|
|
31
37
|
private redocInitialized = false;
|
|
32
38
|
|
|
33
39
|
showError = false;
|
|
40
|
+
showServerError = false;
|
|
34
41
|
|
|
35
42
|
@api
|
|
36
43
|
get referenceConfig(): ReferenceConfig {
|
|
@@ -42,7 +49,12 @@ export default class RedocReference extends LightningElement {
|
|
|
42
49
|
const refConfig =
|
|
43
50
|
typeof value === "string" ? JSON.parse(value) : value;
|
|
44
51
|
this._referenceConfig = refConfig;
|
|
45
|
-
} catch (
|
|
52
|
+
} catch (error) {
|
|
53
|
+
this.showServerError = true;
|
|
54
|
+
console.error(
|
|
55
|
+
"Failed to parse reference configuration data",
|
|
56
|
+
error
|
|
57
|
+
);
|
|
46
58
|
this._referenceConfig = { refList: [] };
|
|
47
59
|
}
|
|
48
60
|
}
|
|
@@ -57,12 +69,12 @@ export default class RedocReference extends LightningElement {
|
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
connectedCallback(): void {
|
|
60
|
-
window.addEventListener("scroll", this.
|
|
61
|
-
window.addEventListener("resize", this.
|
|
72
|
+
window.addEventListener("scroll", this.handleScroll);
|
|
73
|
+
window.addEventListener("resize", this.handleScroll);
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
renderedCallback(): void {
|
|
65
|
-
if (!this.redocInitialized
|
|
77
|
+
if (!this.redocInitialized) {
|
|
66
78
|
this.initializeRedoc();
|
|
67
79
|
}
|
|
68
80
|
}
|
|
@@ -73,8 +85,8 @@ export default class RedocReference extends LightningElement {
|
|
|
73
85
|
this.layoutTimeoutId = null;
|
|
74
86
|
}
|
|
75
87
|
|
|
76
|
-
window.removeEventListener("scroll", this.
|
|
77
|
-
window.removeEventListener("resize", this.
|
|
88
|
+
window.removeEventListener("scroll", this.handleScroll);
|
|
89
|
+
window.removeEventListener("resize", this.handleScroll);
|
|
78
90
|
}
|
|
79
91
|
|
|
80
92
|
@api
|
|
@@ -82,23 +94,17 @@ export default class RedocReference extends LightningElement {
|
|
|
82
94
|
this._parentDocPhaseInfo = docPhaseInfo;
|
|
83
95
|
}
|
|
84
96
|
|
|
85
|
-
private handleScrollWithThrottle = () => {
|
|
86
|
-
if (!this.isScrolling) {
|
|
87
|
-
this.isScrolling = true;
|
|
88
|
-
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
this.adjustPosition();
|
|
91
|
-
}, 200);
|
|
92
|
-
|
|
93
|
-
this.isScrolling = false;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
97
|
private adjustPosition = () => {
|
|
98
98
|
const redocContainer = this.getRedocContainer();
|
|
99
99
|
const sidebarMenuElement = redocContainer?.querySelector(
|
|
100
100
|
".redoc-wrap .menu-content"
|
|
101
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;
|
|
102
108
|
|
|
103
109
|
requestAnimationFrame(() => {
|
|
104
110
|
const globalNavElement = document.querySelector("hgf-c360nav");
|
|
@@ -107,6 +113,16 @@ export default class RedocReference extends LightningElement {
|
|
|
107
113
|
const docHeaderElement =
|
|
108
114
|
document.querySelector(".sticky-doc-header");
|
|
109
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
|
+
|
|
110
126
|
if (sidebarMenuElement) {
|
|
111
127
|
const globalNavHeight =
|
|
112
128
|
globalNavElement?.getBoundingClientRect().height || 0;
|
|
@@ -119,17 +135,18 @@ export default class RedocReference extends LightningElement {
|
|
|
119
135
|
globalNavHeight + contextNavHeight + docHeaderHeight
|
|
120
136
|
}px`;
|
|
121
137
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
);
|
|
127
|
-
this.previousTopValue = calculatedTopValue;
|
|
128
|
-
}
|
|
138
|
+
sidebarMenuElement.style.setProperty(
|
|
139
|
+
"--doc-c-redoc-sidebar-top",
|
|
140
|
+
calculatedTopValue
|
|
141
|
+
);
|
|
129
142
|
}
|
|
130
143
|
});
|
|
131
144
|
};
|
|
132
145
|
|
|
146
|
+
private handleScroll = throttle(THROTTLE_TIMEOUT, () =>
|
|
147
|
+
this.adjustPosition()
|
|
148
|
+
);
|
|
149
|
+
|
|
133
150
|
private getDocPhaseInfo(): string | null {
|
|
134
151
|
if (this._parentDocPhaseInfo) {
|
|
135
152
|
return this._parentDocPhaseInfo;
|
|
@@ -165,8 +182,9 @@ export default class RedocReference extends LightningElement {
|
|
|
165
182
|
}
|
|
166
183
|
}
|
|
167
184
|
|
|
168
|
-
private initializeRedoc(): void {
|
|
185
|
+
private async initializeRedoc(): Promise<void> {
|
|
169
186
|
try {
|
|
187
|
+
await this.waitForRedoc();
|
|
170
188
|
const selectedRef = this.getSelectedReference();
|
|
171
189
|
if (selectedRef) {
|
|
172
190
|
this.updateUrlWithReference(selectedRef);
|
|
@@ -190,11 +208,35 @@ export default class RedocReference extends LightningElement {
|
|
|
190
208
|
}
|
|
191
209
|
}
|
|
192
210
|
} catch (error) {
|
|
193
|
-
this.
|
|
194
|
-
console.error("Failed to
|
|
211
|
+
this.showServerError = true;
|
|
212
|
+
console.error("Failed to initialize Redoc:", error);
|
|
195
213
|
}
|
|
196
214
|
}
|
|
197
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
|
+
|
|
198
240
|
private insertCustomLayoutElements(): void {
|
|
199
241
|
const redocContainer = this.getRedocContainer();
|
|
200
242
|
const apiContentDiv = redocContainer?.querySelector(".api-content");
|
|
@@ -209,9 +251,14 @@ export default class RedocReference extends LightningElement {
|
|
|
209
251
|
docPhaseInfo
|
|
210
252
|
);
|
|
211
253
|
}
|
|
212
|
-
|
|
254
|
+
|
|
255
|
+
if (typeof Sprig !== "undefined") {
|
|
256
|
+
this.insertSprigSurvey(apiContentDiv as HTMLElement);
|
|
257
|
+
}
|
|
258
|
+
|
|
213
259
|
this.insertFooter(apiContentDiv as HTMLElement);
|
|
214
260
|
} catch (error) {
|
|
261
|
+
this.showServerError = true;
|
|
215
262
|
console.error(
|
|
216
263
|
"Error showing banner and footer elements",
|
|
217
264
|
error
|
|
@@ -220,7 +267,7 @@ export default class RedocReference extends LightningElement {
|
|
|
220
267
|
} else {
|
|
221
268
|
this.layoutTimeoutId = window.setTimeout(
|
|
222
269
|
() => this.insertCustomLayoutElements(),
|
|
223
|
-
|
|
270
|
+
LAYOUT_TIMEOUT
|
|
224
271
|
);
|
|
225
272
|
}
|
|
226
273
|
}
|
|
@@ -248,9 +295,8 @@ export default class RedocReference extends LightningElement {
|
|
|
248
295
|
});
|
|
249
296
|
|
|
250
297
|
const wrapper = document.createElement("div");
|
|
251
|
-
wrapper.className = "
|
|
298
|
+
wrapper.className = "sprig-survey-wrapper";
|
|
252
299
|
wrapper.appendChild(feedbackElement);
|
|
253
|
-
|
|
254
300
|
container.appendChild(wrapper);
|
|
255
301
|
}
|
|
256
302
|
}
|