@salesforcedevs/docs-components 1.20.17 → 1.20.18-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/lwc.config.json CHANGED
@@ -20,6 +20,7 @@
20
20
  "doc/headingAnchor",
21
21
  "doc/overview",
22
22
  "doc/phase",
23
+ "doc/redocReference",
23
24
  "doc/specificationContent",
24
25
  "doc/versionPicker",
25
26
  "doc/xmlContent",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.20.17",
3
+ "version": "1.20.18-redocly2",
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": "22c9cf5daf39dab3832c98616c2b557c69395105",
28
+ "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
29
29
  "volta": {
30
30
  "node": "20.19.0",
31
31
  "yarn": "1.22.19"
@@ -0,0 +1,7 @@
1
+ :host {
2
+ --dx-footer-margin-top: 142px;
3
+ --doc-c-redoc-sidebar-top: calc(
4
+ var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
5
+ var(--dx-g-spacing-xl)
6
+ );
7
+ }
@@ -0,0 +1,13 @@
1
+ <template>
2
+ <template lwc:if={showError}>
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:else>
11
+ <slot></slot>
12
+ </template>
13
+ </template>
@@ -0,0 +1,326 @@
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
+ import { throttle } from "throttle-debounce";
7
+
8
+ declare global {
9
+ interface Window {
10
+ Redoc: any;
11
+ }
12
+ }
13
+
14
+ type ReferenceItem = {
15
+ source: string;
16
+ href: string;
17
+ isSelected?: boolean;
18
+ docPhase?: string | null;
19
+ };
20
+
21
+ type ReferenceConfig = {
22
+ refList: ReferenceItem[];
23
+ };
24
+
25
+ declare const Sprig: (eventType: string, eventName: string) => void;
26
+ const SCROLL_THROTTLE_DELAY = 200;
27
+ const ELEMENT_TIMEOUT = 10000;
28
+ const ELEMENT_CHECK_INTERVAL = 100;
29
+
30
+ export default class RedocReference extends LightningElement {
31
+ private _referenceConfig: ReferenceConfig = { refList: [] };
32
+ private _parentDocPhaseInfo: string | null = null;
33
+ private redocInitialized = false;
34
+
35
+ showError = false;
36
+
37
+ @api
38
+ get referenceConfig(): ReferenceConfig {
39
+ return this._referenceConfig;
40
+ }
41
+
42
+ set referenceConfig(value: string | ReferenceConfig) {
43
+ try {
44
+ const refConfig =
45
+ typeof value === "string" ? JSON.parse(value) : value;
46
+ this._referenceConfig = refConfig;
47
+ } catch (error) {
48
+ this.showError = true;
49
+ console.error(
50
+ "Failed to parse reference configuration data",
51
+ error
52
+ );
53
+ this._referenceConfig = { refList: [] };
54
+ }
55
+ }
56
+
57
+ @api
58
+ get docPhaseInfo(): string | null {
59
+ return this._parentDocPhaseInfo;
60
+ }
61
+
62
+ set docPhaseInfo(value: string) {
63
+ this._parentDocPhaseInfo = value;
64
+ }
65
+
66
+ connectedCallback(): void {
67
+ window.addEventListener("scroll", this.handleScrollAndResize);
68
+ window.addEventListener("resize", this.handleScrollAndResize);
69
+ }
70
+
71
+ renderedCallback(): void {
72
+ if (!this.redocInitialized) {
73
+ this.initializeRedoc();
74
+ }
75
+ }
76
+
77
+ disconnectedCallback(): void {
78
+ window.removeEventListener("scroll", this.handleScrollAndResize);
79
+ window.removeEventListener("resize", this.handleScrollAndResize);
80
+ }
81
+
82
+ @api
83
+ setDocPhaseInfo(docPhaseInfo: string): void {
84
+ this._parentDocPhaseInfo = docPhaseInfo;
85
+ }
86
+
87
+ private handleLayoutChange = () => {
88
+ requestAnimationFrame(() => {
89
+ const redocContainer = this.getRedocContainer();
90
+ if (!redocContainer) {
91
+ return;
92
+ }
93
+
94
+ const globalNavElement = document.querySelector("hgf-c360nav");
95
+ const contextNavElement =
96
+ document.querySelector("hgf-c360contextnav");
97
+ const docHeaderElement =
98
+ document.querySelector(".sticky-doc-header");
99
+
100
+ const globalNavHeight =
101
+ globalNavElement?.getBoundingClientRect().height || 0;
102
+ const contextNavHeight =
103
+ contextNavElement?.getBoundingClientRect().height || 0;
104
+ const docHeaderHeight =
105
+ docHeaderElement?.getBoundingClientRect().height || 0;
106
+
107
+ const calculatedTopValue = `${
108
+ globalNavHeight + contextNavHeight + docHeaderHeight
109
+ }px`;
110
+
111
+ // Set updated top value for the sidebar and doc phase
112
+ this.template.host.style.setProperty(
113
+ "--doc-c-redoc-sidebar-top",
114
+ calculatedTopValue
115
+ );
116
+
117
+ // Update thirdColumnContainer bottom positioning
118
+ const footer = redocContainer.querySelector(
119
+ ".redoc-wrap .api-content dx-footer"
120
+ ) as HTMLElement;
121
+ const thirdColumnContainer = redocContainer.querySelector(
122
+ ".redoc-wrap > div:last-child"
123
+ ) as HTMLElement;
124
+
125
+ if (thirdColumnContainer && footer) {
126
+ const footerHeight = footer.getBoundingClientRect().height || 0;
127
+ const footerMarginTop = parseInt(
128
+ getComputedStyle(this.template.host).getPropertyValue(
129
+ "--dx-footer-margin-top"
130
+ ) || "142",
131
+ 10
132
+ );
133
+ thirdColumnContainer.style.setProperty(
134
+ "bottom",
135
+ `${footerHeight + footerMarginTop}px`
136
+ );
137
+ }
138
+ });
139
+ };
140
+
141
+ private handleScrollAndResize = throttle(
142
+ SCROLL_THROTTLE_DELAY,
143
+ () => !this.showError && this.handleLayoutChange()
144
+ );
145
+
146
+ private getDocPhaseInfo(): string | null {
147
+ if (this._parentDocPhaseInfo) {
148
+ return this._parentDocPhaseInfo;
149
+ }
150
+ const selectedRef = this.getSelectedReference();
151
+ return selectedRef?.docPhase
152
+ ? JSON.stringify(selectedRef.docPhase)
153
+ : null;
154
+ }
155
+
156
+ private getSelectedReference(): ReferenceItem | null {
157
+ return this._referenceConfig?.refList?.length
158
+ ? this._referenceConfig.refList.find((ref) => ref.isSelected) ||
159
+ this._referenceConfig.refList[0]
160
+ : null;
161
+ }
162
+
163
+ private getRedocContainer(): HTMLElement | null {
164
+ return document.querySelector(".redoc-container");
165
+ }
166
+
167
+ private updateUrlWithReference(selectedRef: ReferenceItem): void {
168
+ if (selectedRef?.href) {
169
+ const parentReferencePath = selectedRef.href;
170
+ const currentUrl = window.location;
171
+ const existingParams = currentUrl.search + currentUrl.hash;
172
+
173
+ window.history.pushState(
174
+ {},
175
+ "",
176
+ `${parentReferencePath}${existingParams}`
177
+ );
178
+ }
179
+ }
180
+
181
+ private async initializeRedoc(): Promise<void> {
182
+ try {
183
+ this.redocInitialized = true;
184
+
185
+ await this.waitForRedoc();
186
+ const selectedRef = this.getSelectedReference();
187
+ if (selectedRef) {
188
+ this.updateUrlWithReference(selectedRef);
189
+
190
+ const specUrl = selectedRef.source;
191
+ const redocContainer = this.getRedocContainer();
192
+ if (specUrl && redocContainer) {
193
+ try {
194
+ window.Redoc.init(
195
+ specUrl,
196
+ {
197
+ expandResponses: "200,400"
198
+ },
199
+ redocContainer,
200
+ () => {
201
+ this.insertCustomLayoutElements();
202
+ }
203
+ );
204
+ } catch (error) {
205
+ this.showError = true;
206
+ console.error(
207
+ "Failed to show Reference UI using Redoc:",
208
+ error
209
+ );
210
+ }
211
+ } else {
212
+ this.showError = true;
213
+ }
214
+ }
215
+ } catch (error) {
216
+ this.showError = true;
217
+ console.error("Failed to load Redoc library:", error);
218
+ }
219
+ }
220
+
221
+ /**
222
+ * Waits until a condition is ready/satisfied within a timeout period
223
+ * @param readinessCheck - Function that returns truthy when condition is satisfied
224
+ * @param timeoutErrorMessage - Error message if timeout occurs
225
+ * @param maxWaitTime - Maximum time to wait in milliseconds
226
+ */
227
+ private waitUntilReady(
228
+ readinessCheck: () => boolean | HTMLElement | null,
229
+ timeoutErrorMessage: string,
230
+ maxWaitTime = ELEMENT_TIMEOUT
231
+ ): Promise<void> {
232
+ return new Promise((resolve, reject) => {
233
+ const pollingStartTime = Date.now();
234
+
235
+ const performReadinessCheck = () => {
236
+ if (readinessCheck()) {
237
+ resolve();
238
+ return;
239
+ }
240
+
241
+ const elapsedTime = Date.now() - pollingStartTime;
242
+ if (elapsedTime > maxWaitTime) {
243
+ reject(new Error(timeoutErrorMessage));
244
+ return;
245
+ }
246
+
247
+ setTimeout(performReadinessCheck, ELEMENT_CHECK_INTERVAL);
248
+ };
249
+
250
+ performReadinessCheck();
251
+ });
252
+ }
253
+
254
+ private waitForRedoc(timeout = ELEMENT_TIMEOUT): Promise<void> {
255
+ return this.waitUntilReady(
256
+ () => !!window.Redoc,
257
+ "Redoc library failed to load within timeout period",
258
+ timeout
259
+ );
260
+ }
261
+
262
+ private async insertCustomLayoutElements(): Promise<void> {
263
+ try {
264
+ const redocContainer = this.getRedocContainer();
265
+
266
+ if (redocContainer) {
267
+ const apiContentDiv = await this.waitForApiContent(
268
+ redocContainer
269
+ );
270
+ apiContentDiv.setAttribute("lwc:dom", "manual");
271
+
272
+ const docPhaseInfo = this.getDocPhaseInfo();
273
+ if (docPhaseInfo) {
274
+ this.insertDocPhase(apiContentDiv, docPhaseInfo);
275
+ }
276
+
277
+ if (typeof Sprig !== "undefined") {
278
+ this.insertSprigSurvey(apiContentDiv);
279
+ }
280
+
281
+ this.insertFooter(apiContentDiv);
282
+ }
283
+ } catch (error) {
284
+ this.showError = true;
285
+ console.error("Failed to insert layout elements:", error);
286
+ }
287
+ }
288
+
289
+ private async waitForApiContent(
290
+ container: HTMLElement
291
+ ): Promise<HTMLElement> {
292
+ await this.waitUntilReady(
293
+ () => container.querySelector<HTMLElement>(".api-content"),
294
+ "Redoc API content element not found within timeout period"
295
+ );
296
+ return container.querySelector<HTMLElement>(".api-content")!;
297
+ }
298
+
299
+ private insertDocPhase(container: HTMLElement, docPhaseInfo: string): void {
300
+ const docPhaseElement = createElement("doc-phase", { is: DocPhase });
301
+ Object.assign(docPhaseElement, { docPhaseInfo });
302
+
303
+ const wrapper = document.createElement("div");
304
+ wrapper.className = "doc-phase-wrapper";
305
+ wrapper.appendChild(docPhaseElement);
306
+
307
+ container.insertBefore(wrapper, container.firstChild);
308
+ }
309
+
310
+ private insertFooter(container: HTMLElement): void {
311
+ const footerElement = createElement("dx-footer", { is: DxFooter });
312
+ Object.assign(footerElement, { variant: "no-signup" });
313
+ container.appendChild(footerElement);
314
+ }
315
+
316
+ private insertSprigSurvey(container: HTMLElement): void {
317
+ const feedbackElement = createElement("doc-sprig-survey", {
318
+ is: SprigSurvey
319
+ });
320
+
321
+ const wrapper = document.createElement("div");
322
+ wrapper.className = "sprig-survey-wrapper";
323
+ wrapper.appendChild(feedbackElement);
324
+ container.appendChild(wrapper);
325
+ }
326
+ }
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.