@salesforcedevs/docs-components 1.21.0 → 1.21.1-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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.1-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": "
|
|
28
|
+
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
|
|
29
29
|
"volta": {
|
|
30
30
|
"node": "20.19.0",
|
|
31
31
|
"yarn": "1.22.19"
|
|
@@ -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,343 @@
|
|
|
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
|
+
import { pollUntil } from "dxUtils/async";
|
|
8
|
+
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
Redoc: any;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare const Sprig: (eventType: string, eventName: string) => void;
|
|
16
|
+
|
|
17
|
+
type ReferenceItem = {
|
|
18
|
+
source: string;
|
|
19
|
+
href: string;
|
|
20
|
+
isSelected?: boolean;
|
|
21
|
+
docPhase?: string | null;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type ReferenceConfig = {
|
|
25
|
+
refList: ReferenceItem[];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const SCROLL_THROTTLE_DELAY = 50;
|
|
29
|
+
const ELEMENT_TIMEOUT = 10000;
|
|
30
|
+
const ELEMENT_CHECK_INTERVAL = 100;
|
|
31
|
+
|
|
32
|
+
export default class RedocReference extends LightningElement {
|
|
33
|
+
private _referenceConfig: ReferenceConfig = { refList: [] };
|
|
34
|
+
private _parentDocPhaseInfo: string | null = null;
|
|
35
|
+
private redocInitialized = false;
|
|
36
|
+
|
|
37
|
+
private docHeaderElement: Element | null = null;
|
|
38
|
+
|
|
39
|
+
showError = false;
|
|
40
|
+
|
|
41
|
+
@api
|
|
42
|
+
get referenceConfig(): ReferenceConfig {
|
|
43
|
+
return this._referenceConfig;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
set referenceConfig(value: string | ReferenceConfig) {
|
|
47
|
+
try {
|
|
48
|
+
const refConfig =
|
|
49
|
+
typeof value === "string" ? JSON.parse(value) : value;
|
|
50
|
+
this._referenceConfig = refConfig;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
this.showError = true;
|
|
53
|
+
console.error(
|
|
54
|
+
"Failed to parse reference configuration data",
|
|
55
|
+
error
|
|
56
|
+
);
|
|
57
|
+
this._referenceConfig = { refList: [] };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@api
|
|
62
|
+
get docPhaseInfo(): string | null {
|
|
63
|
+
return this._parentDocPhaseInfo;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
set docPhaseInfo(value: string) {
|
|
67
|
+
this._parentDocPhaseInfo = value;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
connectedCallback(): void {
|
|
71
|
+
window.addEventListener("scroll", this.handleScrollAndResize);
|
|
72
|
+
window.addEventListener("resize", this.handleScrollAndResize);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
renderedCallback(): void {
|
|
76
|
+
if (!this.redocInitialized) {
|
|
77
|
+
this.initializeRedoc();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
disconnectedCallback(): void {
|
|
82
|
+
window.removeEventListener("scroll", this.handleScrollAndResize);
|
|
83
|
+
window.removeEventListener("resize", this.handleScrollAndResize);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@api
|
|
87
|
+
setDocPhaseInfo(docPhaseInfo: string): void {
|
|
88
|
+
this._parentDocPhaseInfo = docPhaseInfo;
|
|
89
|
+
}
|
|
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
|
+
|
|
120
|
+
private handleLayoutChange = () => {
|
|
121
|
+
requestAnimationFrame(() => {
|
|
122
|
+
const redocContainer = this.getRedocContainer();
|
|
123
|
+
if (!redocContainer) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const globalNavHeight = this.getGlobalHeaderHeight();
|
|
128
|
+
const docHeaderHeight = this.getDocHeaderHeight();
|
|
129
|
+
const calculatedTopValue = `${globalNavHeight + docHeaderHeight}px`;
|
|
130
|
+
|
|
131
|
+
// Set updated top value for the sidebar and doc phase
|
|
132
|
+
this.template.host.style.setProperty(
|
|
133
|
+
"--doc-c-redoc-sidebar-top",
|
|
134
|
+
calculatedTopValue
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
private handleScrollAndResize = throttle(
|
|
140
|
+
SCROLL_THROTTLE_DELAY,
|
|
141
|
+
() => !this.showError && this.handleLayoutChange()
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
private getDocPhaseInfo(): string | null {
|
|
145
|
+
if (this._parentDocPhaseInfo) {
|
|
146
|
+
return this._parentDocPhaseInfo;
|
|
147
|
+
}
|
|
148
|
+
const selectedRef = this.getSelectedReference();
|
|
149
|
+
return selectedRef?.docPhase
|
|
150
|
+
? JSON.stringify(selectedRef.docPhase)
|
|
151
|
+
: null;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private getSelectedReference(): ReferenceItem | null {
|
|
155
|
+
return (
|
|
156
|
+
this._referenceConfig?.refList?.find((ref) => ref.isSelected) ||
|
|
157
|
+
this._referenceConfig?.refList?.[0]
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private getRedocContainer(): HTMLElement | null {
|
|
162
|
+
return document.querySelector(".redoc-container");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private updateUrlWithReference(selectedRef: ReferenceItem): void {
|
|
166
|
+
if (selectedRef?.href) {
|
|
167
|
+
const parentReferencePath = selectedRef.href;
|
|
168
|
+
const currentUrl = window.location;
|
|
169
|
+
const existingParams = currentUrl.search + currentUrl.hash;
|
|
170
|
+
|
|
171
|
+
window.history.pushState(
|
|
172
|
+
{},
|
|
173
|
+
"",
|
|
174
|
+
`${parentReferencePath}${existingParams}`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private async initializeRedoc(): Promise<void> {
|
|
180
|
+
try {
|
|
181
|
+
this.redocInitialized = true;
|
|
182
|
+
|
|
183
|
+
await this.waitForRedoc();
|
|
184
|
+
const selectedRef = this.getSelectedReference();
|
|
185
|
+
if (selectedRef) {
|
|
186
|
+
this.updateUrlWithReference(selectedRef);
|
|
187
|
+
|
|
188
|
+
const specUrl = selectedRef.source;
|
|
189
|
+
const redocContainer = this.getRedocContainer();
|
|
190
|
+
if (specUrl && redocContainer) {
|
|
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 {
|
|
205
|
+
this.insertCustomLayoutElements();
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
} else {
|
|
210
|
+
this.showError = true;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} catch (error) {
|
|
214
|
+
this.showError = true;
|
|
215
|
+
console.error("Failed to load Redoc library:", error);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
private async waitForRedoc(timeout = ELEMENT_TIMEOUT): Promise<void> {
|
|
220
|
+
const success = await pollUntil(
|
|
221
|
+
() => !!window.Redoc,
|
|
222
|
+
ELEMENT_CHECK_INTERVAL,
|
|
223
|
+
timeout
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
if (!success) {
|
|
227
|
+
throw new Error(
|
|
228
|
+
"Redoc library failed to load within timeout period"
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
private async insertCustomLayoutElements(): Promise<void> {
|
|
234
|
+
try {
|
|
235
|
+
const redocContainer = this.getRedocContainer();
|
|
236
|
+
|
|
237
|
+
if (redocContainer) {
|
|
238
|
+
const apiContentDiv = await this.waitForApiContent(
|
|
239
|
+
redocContainer
|
|
240
|
+
);
|
|
241
|
+
apiContentDiv.setAttribute("lwc:dom", "manual");
|
|
242
|
+
|
|
243
|
+
const docPhaseInfo = this.getDocPhaseInfo();
|
|
244
|
+
if (docPhaseInfo) {
|
|
245
|
+
this.insertDocPhase(apiContentDiv, docPhaseInfo);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (typeof Sprig !== "undefined") {
|
|
249
|
+
this.insertSprigSurvey(apiContentDiv);
|
|
250
|
+
}
|
|
251
|
+
|
|
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
|
+
});
|
|
259
|
+
}
|
|
260
|
+
} catch (error) {
|
|
261
|
+
this.showError = true;
|
|
262
|
+
console.error("Failed to insert layout elements:", error);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private async waitForApiContent(
|
|
267
|
+
container: HTMLElement
|
|
268
|
+
): Promise<HTMLElement> {
|
|
269
|
+
const success = await pollUntil(
|
|
270
|
+
() => !!container.querySelector(".api-content"),
|
|
271
|
+
ELEMENT_CHECK_INTERVAL,
|
|
272
|
+
ELEMENT_TIMEOUT
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
if (!success) {
|
|
276
|
+
throw new Error(
|
|
277
|
+
"Redoc API content element not found within timeout period"
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return container.querySelector<HTMLElement>(".api-content")!;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
private insertDocPhase(container: HTMLElement, docPhaseInfo: string): void {
|
|
285
|
+
const wrapper = document.createElement("div");
|
|
286
|
+
wrapper.className = "doc-phase-wrapper";
|
|
287
|
+
|
|
288
|
+
container.insertBefore(wrapper, container.firstChild);
|
|
289
|
+
|
|
290
|
+
const docPhaseElement = createElement("doc-phase", { is: DocPhase });
|
|
291
|
+
Object.assign(docPhaseElement, { docPhaseInfo });
|
|
292
|
+
|
|
293
|
+
wrapper.appendChild(docPhaseElement);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
private insertFooter(container: HTMLElement): void {
|
|
297
|
+
const footerElement = createElement("dx-footer", { is: DxFooter });
|
|
298
|
+
Object.assign(footerElement, { variant: "no-signup" });
|
|
299
|
+
container.appendChild(footerElement);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
private insertSprigSurvey(container: HTMLElement): void {
|
|
303
|
+
const wrapper = document.createElement("div");
|
|
304
|
+
wrapper.className = "sprig-survey-wrapper";
|
|
305
|
+
container.appendChild(wrapper);
|
|
306
|
+
|
|
307
|
+
const feedbackElement = createElement("doc-sprig-survey", {
|
|
308
|
+
is: SprigSurvey
|
|
309
|
+
});
|
|
310
|
+
wrapper.appendChild(feedbackElement);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
private updateRedocThirdColumnStyle(redocContainer: HTMLElement): void {
|
|
314
|
+
const footer = redocContainer.querySelector(
|
|
315
|
+
".redoc-wrap .api-content dx-footer"
|
|
316
|
+
) as HTMLElement;
|
|
317
|
+
const thirdColumnContainer = redocContainer.querySelector(
|
|
318
|
+
".redoc-wrap > div:last-child"
|
|
319
|
+
) as HTMLElement;
|
|
320
|
+
|
|
321
|
+
if (!thirdColumnContainer || !footer) {
|
|
322
|
+
console.warn(
|
|
323
|
+
!thirdColumnContainer
|
|
324
|
+
? "Redoc Third column container not found"
|
|
325
|
+
: "Footer not found in DOM, skipping third column styling"
|
|
326
|
+
);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const footerHeight = footer.getBoundingClientRect().height || 0;
|
|
331
|
+
const footerMarginTop = parseInt(
|
|
332
|
+
getComputedStyle(this.template.host).getPropertyValue(
|
|
333
|
+
"--dx-footer-margin-top"
|
|
334
|
+
),
|
|
335
|
+
10
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
thirdColumnContainer.style.setProperty(
|
|
339
|
+
"bottom",
|
|
340
|
+
`${footerHeight + footerMarginTop}px`
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
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.
|