@salesforcedevs/docs-components 1.20.18-redocly3 → 1.21.1-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.20.18-redocly3",
3
+ "version": "1.21.1-redocly1",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -23,13 +23,6 @@ iframe {
23
23
  height: 606px;
24
24
  min-height: var(--playground-iframe-min-height);
25
25
  max-height: var(--playground-iframe-max-height);
26
- transition: height 0.3s ease, min-height 0.3s ease;
27
- }
28
-
29
- @media (prefers-reduced-motion: reduce) {
30
- iframe {
31
- transition: none;
32
- }
33
26
  }
34
27
 
35
28
  .playground-container {
@@ -4,6 +4,7 @@ import DocPhase from "doc/phase";
4
4
  import DxFooter from "dx/footer";
5
5
  import SprigSurvey from "doc/sprigSurvey";
6
6
  import { throttle } from "throttle-debounce";
7
+ import { pollUntil } from "dxUtils/async";
7
8
 
8
9
  declare global {
9
10
  interface Window {
@@ -33,6 +34,8 @@ export default class RedocReference extends LightningElement {
33
34
  private _parentDocPhaseInfo: string | null = null;
34
35
  private redocInitialized = false;
35
36
 
37
+ private docHeaderElement: Element | null = null;
38
+
36
39
  showError = false;
37
40
 
38
41
  @api
@@ -85,6 +88,35 @@ export default class RedocReference extends LightningElement {
85
88
  this._parentDocPhaseInfo = docPhaseInfo;
86
89
  }
87
90
 
91
+ private getGlobalCSSVariableValue(variableName: string): number {
92
+ const value = getComputedStyle(
93
+ document.documentElement
94
+ ).getPropertyValue(variableName);
95
+ return parseInt(value, 10) || 0;
96
+ }
97
+
98
+ private getGlobalHeaderHeight(): number {
99
+ /*
100
+ ** Since we could not use --dx-g-global-header-height as getPropertyValue returns a calc expression,
101
+ ** we are using the respective CSS variables to calculate the height.
102
+ */
103
+ const rowHeight = this.getGlobalCSSVariableValue(
104
+ "--dx-g-global-header-nav-row-height"
105
+ );
106
+ const rowCount = this.getGlobalCSSVariableValue(
107
+ "--dx-g-global-header-nav-row-count"
108
+ );
109
+ return rowHeight * rowCount;
110
+ }
111
+
112
+ private getDocHeaderHeight(): number {
113
+ if (!this.docHeaderElement) {
114
+ this.docHeaderElement =
115
+ document.querySelector(".sticky-doc-header");
116
+ }
117
+ return this.docHeaderElement?.getBoundingClientRect().height || 0;
118
+ }
119
+
88
120
  private handleLayoutChange = () => {
89
121
  requestAnimationFrame(() => {
90
122
  const redocContainer = this.getRedocContainer();
@@ -92,50 +124,15 @@ export default class RedocReference extends LightningElement {
92
124
  return;
93
125
  }
94
126
 
95
- const globalNavElement = document.querySelector("hgf-c360nav");
96
- const contextNavElement =
97
- document.querySelector("hgf-c360contextnav");
98
- const docHeaderElement =
99
- document.querySelector(".sticky-doc-header");
100
-
101
- const globalNavHeight =
102
- globalNavElement?.getBoundingClientRect().height || 0;
103
- const contextNavHeight =
104
- contextNavElement?.getBoundingClientRect().height || 0;
105
- const docHeaderHeight =
106
- docHeaderElement?.getBoundingClientRect().height || 0;
107
-
108
- const calculatedTopValue = `${
109
- globalNavHeight + contextNavHeight + docHeaderHeight
110
- }px`;
127
+ const globalNavHeight = this.getGlobalHeaderHeight();
128
+ const docHeaderHeight = this.getDocHeaderHeight();
129
+ const calculatedTopValue = `${globalNavHeight + docHeaderHeight}px`;
111
130
 
112
131
  // Set updated top value for the sidebar and doc phase
113
132
  this.template.host.style.setProperty(
114
133
  "--doc-c-redoc-sidebar-top",
115
134
  calculatedTopValue
116
135
  );
117
-
118
- // Update thirdColumnContainer bottom positioning
119
- const footer = redocContainer.querySelector(
120
- ".redoc-wrap .api-content dx-footer"
121
- ) as HTMLElement;
122
- const thirdColumnContainer = redocContainer.querySelector(
123
- ".redoc-wrap > div:last-child"
124
- ) as HTMLElement;
125
-
126
- if (thirdColumnContainer && footer) {
127
- const footerHeight = footer.getBoundingClientRect().height || 0;
128
- const footerMarginTop = parseInt(
129
- getComputedStyle(this.template.host).getPropertyValue(
130
- "--dx-footer-margin-top"
131
- ) || "142",
132
- 10
133
- );
134
- thirdColumnContainer.style.setProperty(
135
- "bottom",
136
- `${footerHeight + footerMarginTop}px`
137
- );
138
- }
139
136
  });
140
137
  };
141
138
 
@@ -155,10 +152,10 @@ export default class RedocReference extends LightningElement {
155
152
  }
156
153
 
157
154
  private getSelectedReference(): ReferenceItem | null {
158
- return this._referenceConfig?.refList?.length
159
- ? this._referenceConfig.refList.find((ref) => ref.isSelected) ||
160
- this._referenceConfig.refList[0]
161
- : null;
155
+ return (
156
+ this._referenceConfig?.refList?.find((ref) => ref.isSelected) ||
157
+ this._referenceConfig?.refList?.[0]
158
+ );
162
159
  }
163
160
 
164
161
  private getRedocContainer(): HTMLElement | null {
@@ -191,24 +188,24 @@ export default class RedocReference extends LightningElement {
191
188
  const specUrl = selectedRef.source;
192
189
  const redocContainer = this.getRedocContainer();
193
190
  if (specUrl && redocContainer) {
194
- try {
195
- window.Redoc.init(
196
- specUrl,
197
- {
198
- expandResponses: "200,400"
199
- },
200
- redocContainer,
201
- () => {
191
+ window.Redoc.init(
192
+ specUrl,
193
+ {
194
+ expandResponses: "200,400"
195
+ },
196
+ redocContainer,
197
+ (error: any) => {
198
+ if (error) {
199
+ this.showError = true;
200
+ console.error(
201
+ "Failed to show Reference UI using Redoc: ",
202
+ error
203
+ );
204
+ } else {
202
205
  this.insertCustomLayoutElements();
203
206
  }
204
- );
205
- } catch (error) {
206
- this.showError = true;
207
- console.error(
208
- "Failed to show Reference UI using Redoc:",
209
- error
210
- );
211
- }
207
+ }
208
+ );
212
209
  } else {
213
210
  this.showError = true;
214
211
  }
@@ -219,45 +216,18 @@ export default class RedocReference extends LightningElement {
219
216
  }
220
217
  }
221
218
 
222
- /**
223
- * Waits until a condition is ready/satisfied within a timeout period
224
- * @param readinessCheck - Function that returns truthy when condition is satisfied
225
- * @param timeoutErrorMessage - Error message if timeout occurs
226
- * @param maxWaitTime - Maximum time to wait in milliseconds
227
- */
228
- private waitUntilReady(
229
- readinessCheck: () => boolean | HTMLElement | null,
230
- timeoutErrorMessage: string,
231
- maxWaitTime = ELEMENT_TIMEOUT
232
- ): Promise<void> {
233
- return new Promise((resolve, reject) => {
234
- const pollingStartTime = Date.now();
235
-
236
- const performReadinessCheck = () => {
237
- if (readinessCheck()) {
238
- resolve();
239
- return;
240
- }
241
-
242
- const elapsedTime = Date.now() - pollingStartTime;
243
- if (elapsedTime > maxWaitTime) {
244
- reject(new Error(timeoutErrorMessage));
245
- return;
246
- }
247
-
248
- setTimeout(performReadinessCheck, ELEMENT_CHECK_INTERVAL);
249
- };
250
-
251
- performReadinessCheck();
252
- });
253
- }
254
-
255
- private waitForRedoc(timeout = ELEMENT_TIMEOUT): Promise<void> {
256
- return this.waitUntilReady(
219
+ private async waitForRedoc(timeout = ELEMENT_TIMEOUT): Promise<void> {
220
+ const success = await pollUntil(
257
221
  () => !!window.Redoc,
258
- "Redoc library failed to load within timeout period",
222
+ ELEMENT_CHECK_INTERVAL,
259
223
  timeout
260
224
  );
225
+
226
+ if (!success) {
227
+ throw new Error(
228
+ "Redoc library failed to load within timeout period"
229
+ );
230
+ }
261
231
  }
262
232
 
263
233
  private async insertCustomLayoutElements(): Promise<void> {
@@ -280,6 +250,12 @@ export default class RedocReference extends LightningElement {
280
250
  }
281
251
 
282
252
  this.insertFooter(apiContentDiv);
253
+
254
+ // Wait for footer to be rendered before updating styles
255
+ requestAnimationFrame(() => {
256
+ // Update third column bottom position to avoid footer overlap.
257
+ this.updateRedocThirdColumnStyle(redocContainer);
258
+ });
283
259
  }
284
260
  } catch (error) {
285
261
  this.showError = true;
@@ -290,10 +266,18 @@ export default class RedocReference extends LightningElement {
290
266
  private async waitForApiContent(
291
267
  container: HTMLElement
292
268
  ): Promise<HTMLElement> {
293
- await this.waitUntilReady(
294
- () => container.querySelector<HTMLElement>(".api-content"),
295
- "Redoc API content element not found within timeout period"
269
+ const success = await pollUntil(
270
+ () => !!container.querySelector(".api-content"),
271
+ ELEMENT_CHECK_INTERVAL,
272
+ ELEMENT_TIMEOUT
296
273
  );
274
+
275
+ if (!success) {
276
+ throw new Error(
277
+ "Redoc API content element not found within timeout period"
278
+ );
279
+ }
280
+
297
281
  return container.querySelector<HTMLElement>(".api-content")!;
298
282
  }
299
283
 
@@ -324,4 +308,35 @@ export default class RedocReference extends LightningElement {
324
308
  wrapper.appendChild(feedbackElement);
325
309
  container.appendChild(wrapper);
326
310
  }
311
+
312
+ private updateRedocThirdColumnStyle(redocContainer: HTMLElement): void {
313
+ const footer = redocContainer.querySelector(
314
+ ".redoc-wrap .api-content dx-footer"
315
+ ) as HTMLElement;
316
+ const thirdColumnContainer = redocContainer.querySelector(
317
+ ".redoc-wrap > div:last-child"
318
+ ) as HTMLElement;
319
+
320
+ if (!thirdColumnContainer || !footer) {
321
+ console.warn(
322
+ !thirdColumnContainer
323
+ ? "Redoc Third column container not found"
324
+ : "Footer not found in DOM, skipping third column styling"
325
+ );
326
+ return;
327
+ }
328
+
329
+ const footerHeight = footer.getBoundingClientRect().height || 0;
330
+ const footerMarginTop = parseInt(
331
+ getComputedStyle(this.template.host).getPropertyValue(
332
+ "--dx-footer-margin-top"
333
+ ),
334
+ 10
335
+ );
336
+
337
+ thirdColumnContainer.style.setProperty(
338
+ "bottom",
339
+ `${footerHeight + footerMarginTop}px`
340
+ );
341
+ }
327
342
  }