@salesforcedevs/docs-components 1.20.13-redocly2 → 1.20.13-redocly3

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.20.13-redocly2",
3
+ "version": "1.20.13-redocly3",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -24,10 +24,9 @@ type ReferenceConfig = {
24
24
 
25
25
  declare const Sprig: (eventType: string, eventNme: string) => void;
26
26
  const FOOTER_MARGIN_TOP = 142;
27
- const THROTTLE_TIMEOUT = 200;
27
+ const DEFAULT_TIMEOUT = 200;
28
28
  const REDOC_TIMEOUT = 10000;
29
29
  const REDOC_CHECK_TIMEOUT = 100;
30
- const LAYOUT_TIMEOUT = 100;
31
30
 
32
31
  export default class RedocReference extends LightningElement {
33
32
  private _referenceConfig: ReferenceConfig = { refList: [] };
@@ -143,8 +142,9 @@ export default class RedocReference extends LightningElement {
143
142
  });
144
143
  };
145
144
 
146
- private handleScroll = throttle(THROTTLE_TIMEOUT, () =>
147
- this.adjustPosition()
145
+ private handleScroll = throttle(
146
+ DEFAULT_TIMEOUT,
147
+ () => !this.showServerError && !this.showError && this.adjustPosition()
148
148
  );
149
149
 
150
150
  private getDocPhaseInfo(): string | null {
@@ -184,6 +184,8 @@ export default class RedocReference extends LightningElement {
184
184
 
185
185
  private async initializeRedoc(): Promise<void> {
186
186
  try {
187
+ this.redocInitialized = true;
188
+
187
189
  await this.waitForRedoc();
188
190
  const selectedRef = this.getSelectedReference();
189
191
  if (selectedRef) {
@@ -192,17 +194,21 @@ export default class RedocReference extends LightningElement {
192
194
  const specUrl = selectedRef.source;
193
195
  const redocContainer = this.getRedocContainer();
194
196
  if (specUrl && redocContainer) {
195
- this.redocInitialized = true;
196
- window.Redoc.init(
197
- specUrl,
198
- {
199
- expandResponses: "200,400"
200
- },
201
- redocContainer,
202
- () => {
203
- this.insertCustomLayoutElements();
204
- }
205
- );
197
+ try {
198
+ window.Redoc.init(
199
+ specUrl,
200
+ {
201
+ expandResponses: "200,400"
202
+ },
203
+ redocContainer,
204
+ () => {
205
+ this.insertCustomLayoutElements();
206
+ }
207
+ );
208
+ } catch (error) {
209
+ this.showServerError = true;
210
+ console.error("Failed to load Redoc:", error);
211
+ }
206
212
  } else {
207
213
  this.showError = true;
208
214
  }
@@ -237,41 +243,58 @@ export default class RedocReference extends LightningElement {
237
243
  });
238
244
  }
239
245
 
240
- private insertCustomLayoutElements(): void {
241
- const redocContainer = this.getRedocContainer();
242
- const apiContentDiv = redocContainer?.querySelector(".api-content");
243
- if (apiContentDiv) {
244
- (apiContentDiv as HTMLElement).setAttribute("lwc:dom", "manual");
246
+ private async insertCustomLayoutElements(): Promise<void> {
247
+ try {
248
+ const redocContainer = this.getRedocContainer();
249
+
250
+ if (redocContainer) {
251
+ const apiContentDiv = await this.waitForApiContent(
252
+ redocContainer
253
+ );
254
+ apiContentDiv.setAttribute("lwc:dom", "manual");
245
255
 
246
- try {
247
256
  const docPhaseInfo = this.getDocPhaseInfo();
248
257
  if (docPhaseInfo) {
249
- this.insertDocPhase(
250
- apiContentDiv as HTMLElement,
251
- docPhaseInfo
252
- );
258
+ this.insertDocPhase(apiContentDiv, docPhaseInfo);
253
259
  }
254
260
 
255
261
  if (typeof Sprig !== "undefined") {
256
- this.insertSprigSurvey(apiContentDiv as HTMLElement);
262
+ this.insertSprigSurvey(apiContentDiv);
257
263
  }
258
264
 
259
- this.insertFooter(apiContentDiv as HTMLElement);
260
- } catch (error) {
261
- this.showServerError = true;
262
- console.error(
263
- "Error showing banner and footer elements",
264
- error
265
- );
265
+ this.insertFooter(apiContentDiv);
266
266
  }
267
- } else {
268
- this.layoutTimeoutId = window.setTimeout(
269
- () => this.insertCustomLayoutElements(),
270
- LAYOUT_TIMEOUT
271
- );
267
+ } catch (error) {
268
+ this.showServerError = true;
269
+ console.error("Failed to insert layout elements:", error);
272
270
  }
273
271
  }
274
272
 
273
+ private waitForApiContent(container: HTMLElement): Promise<HTMLElement> {
274
+ return new Promise((resolve, reject) => {
275
+ const start = Date.now();
276
+
277
+ const check = () => {
278
+ const div =
279
+ container.querySelector<HTMLElement>(".api-content");
280
+
281
+ if (div) {
282
+ resolve(div);
283
+ return;
284
+ }
285
+
286
+ if (Date.now() - start > DEFAULT_TIMEOUT) {
287
+ reject(new Error("API content load timeout"));
288
+ return;
289
+ }
290
+
291
+ setTimeout(check, DEFAULT_TIMEOUT);
292
+ };
293
+
294
+ check();
295
+ });
296
+ }
297
+
275
298
  private insertDocPhase(container: HTMLElement, docPhaseInfo: string): void {
276
299
  const docPhaseElement = createElement("doc-phase", { is: DocPhase });
277
300
  Object.assign(docPhaseElement, { docPhaseInfo });