@salesforcedevs/docs-components 1.30.1-node22-2 → 1.30.1
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 +3 -0
- package/package.json +3 -7
- package/src/modules/doc/amfReference/amfReference.html +1 -0
- package/src/modules/doc/amfReference/amfReference.ts +54 -10
- package/src/modules/doc/amfReference/types.ts +5 -0
- package/src/modules/doc/banner/banner.css +88 -0
- package/src/modules/doc/banner/banner.html +47 -0
- package/src/modules/doc/banner/banner.ts +73 -0
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.css +31 -0
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.html +53 -0
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.ts +151 -0
- package/src/modules/doc/contentActionToolbar/contentActionToolbarMocks.ts +48 -0
- package/src/modules/doc/contentLayout/contentLayout.html +1 -1
- package/src/modules/doc/contentLayout/contentLayout.ts +103 -2
- package/src/modules/doc/header/header.html +0 -1
- package/src/modules/doc/localeBanner/localeBanner.css +3 -0
- package/src/modules/doc/localeBanner/localeBanner.html +9 -0
- package/src/modules/doc/localeBanner/localeBanner.ts +195 -0
- package/src/modules/doc/lwcContentLayout/lwcContentLayout.html +5 -2
- package/src/modules/doc/redocReference/redocReference.ts +157 -2
- package/src/modules/doc/xmlContent/xmlContent.html +1 -1
- package/src/modules/doc/xmlContent/xmlContent.ts +28 -1
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
/* eslint-disable @lwc/lwc/no-document-query */
|
|
2
|
-
import { LightningElement, api, track } from "lwc";
|
|
3
|
-
import { closest } from "kagekiri";
|
|
2
|
+
import { LightningElement, api, createElement, track } from "lwc";
|
|
3
|
+
import { closest, querySelector } from "kagekiri";
|
|
4
4
|
import { toJson, normalizeBoolean } from "dxUtils/normalizers";
|
|
5
5
|
import { highlightTerms } from "dxUtils/highlight";
|
|
6
6
|
import { SearchSyncer } from "docUtils/searchSyncer";
|
|
7
7
|
import type { OptionWithLink } from "typings/custom";
|
|
8
8
|
import { buildDocLinkClickHandler } from "dxUtils/analytics";
|
|
9
|
+
import ContentActionToolbar from "doc/contentActionToolbar";
|
|
10
|
+
|
|
11
|
+
const CONTENT_ACTION_TOOLBAR_TAG = "doc-content-action-toolbar";
|
|
12
|
+
const PAGE_HEADING_SELECTOR = "h1";
|
|
9
13
|
|
|
10
14
|
type AnchorMap = { [key: string]: { intersect: boolean; id: string } };
|
|
11
15
|
|
|
@@ -28,6 +32,35 @@ const HIGHLIGHTABLE_SELECTOR = [
|
|
|
28
32
|
].join(",");
|
|
29
33
|
export const OBSERVER_ATTACH_WAIT_TIME = 500;
|
|
30
34
|
|
|
35
|
+
const DEFAULT_READING_TIME_LOCALE = "en-us";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Localized "minute read" templates. `{minutes}` is replaced with the rounded
|
|
39
|
+
* reading-time value. Only displayed when reading time is greater than 1, so
|
|
40
|
+
* plural forms are always appropriate. Keys match the locales declared in
|
|
41
|
+
* sfdocs (and the doc-locale-banner) so that a localized document automatically
|
|
42
|
+
* gets a localized reading-time label.
|
|
43
|
+
*/
|
|
44
|
+
export const READING_TIME_LABELS: Record<string, string> = {
|
|
45
|
+
"en-us": "{minutes} minute read",
|
|
46
|
+
"ja-jp": "読了時間 {minutes} 分",
|
|
47
|
+
"zh-cn": "阅读时间 {minutes} 分钟",
|
|
48
|
+
"zh-tw": "閱讀時間 {minutes} 分鐘",
|
|
49
|
+
"fr-fr": "Lecture de {minutes} minutes",
|
|
50
|
+
"de-de": "{minutes} Minuten Lesezeit",
|
|
51
|
+
"it-it": "{minutes} minuti di lettura",
|
|
52
|
+
"ko-kr": "읽는 데 {minutes}분",
|
|
53
|
+
"pt-br": "{minutes} minutos de leitura",
|
|
54
|
+
"es-mx": "{minutes} minutos de lectura",
|
|
55
|
+
"es-es": "{minutes} minutos de lectura",
|
|
56
|
+
"ru-ru": "Время чтения: {minutes} мин",
|
|
57
|
+
"fi-fi": "{minutes} minuutin lukuaika",
|
|
58
|
+
"da-dk": "{minutes} minutters læsning",
|
|
59
|
+
"sv-se": "{minutes} minuters läsning",
|
|
60
|
+
"nl-nl": "{minutes} minuten leestijd",
|
|
61
|
+
"nb-no": "{minutes} minutters lesetid"
|
|
62
|
+
};
|
|
63
|
+
|
|
31
64
|
export default class ContentLayout extends LightningElement {
|
|
32
65
|
@api sidebarValue!: string;
|
|
33
66
|
@api sidebarHeader!: string;
|
|
@@ -66,6 +99,17 @@ export default class ContentLayout extends LightningElement {
|
|
|
66
99
|
/** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer. */
|
|
67
100
|
@api origin: string | null = null;
|
|
68
101
|
|
|
102
|
+
/** Controls whether the content action toolbar is displayed. */
|
|
103
|
+
@api
|
|
104
|
+
get showContentActionToolbar() {
|
|
105
|
+
return this._showContentActionToolbar;
|
|
106
|
+
}
|
|
107
|
+
set showContentActionToolbar(value) {
|
|
108
|
+
this._showContentActionToolbar = normalizeBoolean(value);
|
|
109
|
+
this.updateContentActionToolbar();
|
|
110
|
+
}
|
|
111
|
+
private _showContentActionToolbar = false;
|
|
112
|
+
|
|
69
113
|
@api
|
|
70
114
|
get breadcrumbs() {
|
|
71
115
|
return this._breadcrumbs;
|
|
@@ -123,6 +167,7 @@ export default class ContentLayout extends LightningElement {
|
|
|
123
167
|
protected hasRendered: boolean = false;
|
|
124
168
|
protected contentLoaded: boolean = false;
|
|
125
169
|
protected sidebarOpen: boolean = false;
|
|
170
|
+
protected contentActionToolbarElement: HTMLElement | null = null;
|
|
126
171
|
|
|
127
172
|
get shouldDisplayFeedback() {
|
|
128
173
|
return this.contentLoaded && typeof Sprig !== "undefined";
|
|
@@ -173,6 +218,19 @@ export default class ContentLayout extends LightningElement {
|
|
|
173
218
|
return this.readingTime != null && this.readingTime > 1;
|
|
174
219
|
}
|
|
175
220
|
|
|
221
|
+
/**
|
|
222
|
+
* Localized "X minute read" string for the current document language.
|
|
223
|
+
* Falls back to the default (en-us) template when the language is missing
|
|
224
|
+
* or has no translation.
|
|
225
|
+
*/
|
|
226
|
+
get readingTimeLabel(): string {
|
|
227
|
+
const localeKey = (this.language || "").toLowerCase();
|
|
228
|
+
const template =
|
|
229
|
+
READING_TIME_LABELS[localeKey] ||
|
|
230
|
+
READING_TIME_LABELS[DEFAULT_READING_TIME_LOCALE];
|
|
231
|
+
return template.replace("{minutes}", String(this.readingTime));
|
|
232
|
+
}
|
|
233
|
+
|
|
176
234
|
/** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
|
|
177
235
|
get effectiveFooterOrigin(): string {
|
|
178
236
|
return (
|
|
@@ -215,6 +273,8 @@ export default class ContentLayout extends LightningElement {
|
|
|
215
273
|
window.addEventListener("scroll", this.adjustNavPosition);
|
|
216
274
|
window.addEventListener("resize", this.adjustNavPosition);
|
|
217
275
|
|
|
276
|
+
this.updateContentActionToolbar();
|
|
277
|
+
|
|
218
278
|
if (!this.hasRendered) {
|
|
219
279
|
this.hasRendered = true;
|
|
220
280
|
this.restoreScroll();
|
|
@@ -224,6 +284,43 @@ export default class ContentLayout extends LightningElement {
|
|
|
224
284
|
}
|
|
225
285
|
}
|
|
226
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Inserts the content action toolbar into the slotted content immediately
|
|
289
|
+
* after the first H1 found inside this layout.
|
|
290
|
+
*/
|
|
291
|
+
protected updateContentActionToolbar(): void {
|
|
292
|
+
if (!this.showContentActionToolbar || !this.sidebarValue) {
|
|
293
|
+
this.removeContentActionToolbar();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const heading = querySelector(
|
|
298
|
+
PAGE_HEADING_SELECTOR,
|
|
299
|
+
this.template.host
|
|
300
|
+
) as HTMLElement | null;
|
|
301
|
+
|
|
302
|
+
if (!heading) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const toolbar = (this.contentActionToolbarElement ??
|
|
307
|
+
createElement(CONTENT_ACTION_TOOLBAR_TAG, {
|
|
308
|
+
is: ContentActionToolbar
|
|
309
|
+
})) as HTMLElement & { pageUrl?: string };
|
|
310
|
+
|
|
311
|
+
toolbar.pageUrl = this.sidebarValue;
|
|
312
|
+
|
|
313
|
+
if (toolbar.previousElementSibling !== heading) {
|
|
314
|
+
heading.parentNode?.insertBefore(toolbar, heading.nextSibling);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
this.contentActionToolbarElement = toolbar;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
protected removeContentActionToolbar(): void {
|
|
321
|
+
this.contentActionToolbarElement?.remove();
|
|
322
|
+
}
|
|
323
|
+
|
|
227
324
|
disconnectedCallback(): void {
|
|
228
325
|
this.disconnectObserver();
|
|
229
326
|
window.removeEventListener(
|
|
@@ -239,6 +336,9 @@ export default class ContentLayout extends LightningElement {
|
|
|
239
336
|
|
|
240
337
|
// Remove link click handler
|
|
241
338
|
this.template.removeEventListener("click", this.handleLinkClick);
|
|
339
|
+
|
|
340
|
+
this.removeContentActionToolbar();
|
|
341
|
+
this.contentActionToolbarElement = null;
|
|
242
342
|
}
|
|
243
343
|
|
|
244
344
|
restoreScroll() {
|
|
@@ -481,6 +581,7 @@ export default class ContentLayout extends LightningElement {
|
|
|
481
581
|
|
|
482
582
|
onSlotChange(): void {
|
|
483
583
|
this.updateRNB();
|
|
584
|
+
this.updateContentActionToolbar();
|
|
484
585
|
this.contentLoaded = true;
|
|
485
586
|
}
|
|
486
587
|
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
|
|
3
|
+
interface LocaleStrings {
|
|
4
|
+
messageText: string;
|
|
5
|
+
linkUrl: string;
|
|
6
|
+
linkText: string;
|
|
7
|
+
buttonLabel: string;
|
|
8
|
+
secondaryLabel: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const DEFAULT_LOCALE = "en-us";
|
|
12
|
+
|
|
13
|
+
const LOCALE_STRINGS: Record<string, LocaleStrings> = {
|
|
14
|
+
"en-us": {
|
|
15
|
+
messageText:
|
|
16
|
+
"This text has been translated using Salesforce machine translation system. More details {link}.",
|
|
17
|
+
linkUrl:
|
|
18
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1",
|
|
19
|
+
linkText: "here",
|
|
20
|
+
buttonLabel: "Switch to English",
|
|
21
|
+
secondaryLabel: "Not Now"
|
|
22
|
+
},
|
|
23
|
+
"ja-jp": {
|
|
24
|
+
messageText:
|
|
25
|
+
"この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細は{link}をご参照ください。",
|
|
26
|
+
linkUrl:
|
|
27
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=ja",
|
|
28
|
+
linkText: "こちら",
|
|
29
|
+
buttonLabel: "英語に切り替える",
|
|
30
|
+
secondaryLabel: "今はしません"
|
|
31
|
+
},
|
|
32
|
+
"zh-cn": {
|
|
33
|
+
messageText:
|
|
34
|
+
"此文本已使用 Salesforce 机器翻译系统进行翻译。如需了解更多详情,请点击{link}。",
|
|
35
|
+
linkUrl:
|
|
36
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=zh_CN",
|
|
37
|
+
linkText: "此处",
|
|
38
|
+
buttonLabel: "切换为英语",
|
|
39
|
+
secondaryLabel: "而非现在"
|
|
40
|
+
},
|
|
41
|
+
"zh-tw": {
|
|
42
|
+
messageText:
|
|
43
|
+
"此文已使用 Salesforce 機器翻譯系統翻譯。更多詳細資料請參見{link}。",
|
|
44
|
+
linkUrl:
|
|
45
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=zh_TW",
|
|
46
|
+
linkText: "此處",
|
|
47
|
+
buttonLabel: "切換至英文",
|
|
48
|
+
secondaryLabel: "不要現在"
|
|
49
|
+
},
|
|
50
|
+
"fr-fr": {
|
|
51
|
+
messageText:
|
|
52
|
+
"Ce texte a été traduit à l’aide du système de traduction automatique de Salesforce. Plus de détails, consultez {link}.",
|
|
53
|
+
linkUrl:
|
|
54
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=fr",
|
|
55
|
+
linkText: "cette page",
|
|
56
|
+
buttonLabel: "Basculer vers la page en anglais",
|
|
57
|
+
secondaryLabel: "Pas maintenant"
|
|
58
|
+
},
|
|
59
|
+
"de-de": {
|
|
60
|
+
messageText:
|
|
61
|
+
"Dieser Text wurde mit dem maschinellen Übersetzungssystem von Salesforce übersetzt. Weitere Details finden Sie {link}.",
|
|
62
|
+
linkUrl:
|
|
63
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=de",
|
|
64
|
+
linkText: "hier",
|
|
65
|
+
buttonLabel: "Zu Englisch wechseln",
|
|
66
|
+
secondaryLabel: "Nicht jetzt"
|
|
67
|
+
},
|
|
68
|
+
"it-it": {
|
|
69
|
+
messageText:
|
|
70
|
+
"Questo testo è stato tradotto utilizzando il sistema di traduzione automatica di Salesforce. Ulteriori dettagli sono disponibili {link}.",
|
|
71
|
+
linkUrl:
|
|
72
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=it",
|
|
73
|
+
linkText: "qui",
|
|
74
|
+
buttonLabel: "Passa all'inglese",
|
|
75
|
+
secondaryLabel: "Non ora"
|
|
76
|
+
},
|
|
77
|
+
"ko-kr": {
|
|
78
|
+
messageText:
|
|
79
|
+
"본 텍스트는 Salesforce 기계 번역 시스템으로 번역되었습니다. 자세한 내용은 {link}를 참조하세요.",
|
|
80
|
+
linkUrl:
|
|
81
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=ko",
|
|
82
|
+
linkText: "여기",
|
|
83
|
+
buttonLabel: "영어로 전환",
|
|
84
|
+
secondaryLabel: "지금 안 함"
|
|
85
|
+
},
|
|
86
|
+
"pt-br": {
|
|
87
|
+
messageText:
|
|
88
|
+
"Este texto foi traduzido pelo sistema de tradução automática da Salesforce. Mais detalhes {link}.",
|
|
89
|
+
linkUrl:
|
|
90
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=pt_BR",
|
|
91
|
+
linkText: "aqui",
|
|
92
|
+
buttonLabel: "Alternar para inglês",
|
|
93
|
+
secondaryLabel: "Agora não"
|
|
94
|
+
},
|
|
95
|
+
"es-mx": {
|
|
96
|
+
messageText:
|
|
97
|
+
"Este texto se tradujo con el sistema de traducción automática de Salesforce. Obtenga más detalles {link}.",
|
|
98
|
+
linkUrl:
|
|
99
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=es_MX",
|
|
100
|
+
linkText: "aquí",
|
|
101
|
+
buttonLabel: "Cambiar a inglés",
|
|
102
|
+
secondaryLabel: "Ahora no"
|
|
103
|
+
},
|
|
104
|
+
"es-es": {
|
|
105
|
+
messageText:
|
|
106
|
+
"Este texto se ha traducido utilizando un sistema de traducción automática de Salesforce. Más información {link}.",
|
|
107
|
+
linkUrl:
|
|
108
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=es",
|
|
109
|
+
linkText: "aquí",
|
|
110
|
+
buttonLabel: "Cambiar a inglés",
|
|
111
|
+
secondaryLabel: "Ahora no"
|
|
112
|
+
},
|
|
113
|
+
"ru-ru": {
|
|
114
|
+
messageText:
|
|
115
|
+
"Данный текст был переведен при помощи системы машинного перевода Salesforce. Дополнительные сведения см. {link}.",
|
|
116
|
+
linkUrl:
|
|
117
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=ru",
|
|
118
|
+
linkText: "здесь",
|
|
119
|
+
buttonLabel: "Переключить на английский",
|
|
120
|
+
secondaryLabel: "Не сейчас"
|
|
121
|
+
},
|
|
122
|
+
"fi-fi": {
|
|
123
|
+
messageText:
|
|
124
|
+
"Tämä teksti on käännetty Salesforcen konekäännösjärjestelmän avulla. Katso lisätietoja {link}.",
|
|
125
|
+
linkUrl:
|
|
126
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=fi",
|
|
127
|
+
linkText: "täältä",
|
|
128
|
+
buttonLabel: "Vaihda englantiin",
|
|
129
|
+
secondaryLabel: "Ei nyt"
|
|
130
|
+
},
|
|
131
|
+
"da-dk": {
|
|
132
|
+
messageText:
|
|
133
|
+
"Denne tekst er oversat ved hjælp af Salesforce-maskinoversættelsessystem. Du finder flere detaljer {link}.",
|
|
134
|
+
linkUrl:
|
|
135
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=da",
|
|
136
|
+
linkText: "her",
|
|
137
|
+
buttonLabel: "Skift til engelsk",
|
|
138
|
+
secondaryLabel: "Ikke nu"
|
|
139
|
+
},
|
|
140
|
+
"sv-se": {
|
|
141
|
+
messageText:
|
|
142
|
+
"Den här texten har översatts med Salesforces maskinöversättningssystem. Mer information {link}.",
|
|
143
|
+
linkUrl:
|
|
144
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=sv",
|
|
145
|
+
linkText: "här",
|
|
146
|
+
buttonLabel: "Byt till engelska",
|
|
147
|
+
secondaryLabel: "Inte nu"
|
|
148
|
+
},
|
|
149
|
+
"nl-nl": {
|
|
150
|
+
messageText:
|
|
151
|
+
"Deze tekst werd vertaald aan de hand van het systeem voor automatische vertaling van Salesforce. U vindt {link} meer details.",
|
|
152
|
+
linkUrl:
|
|
153
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=nl_NL",
|
|
154
|
+
linkText: "hier",
|
|
155
|
+
buttonLabel: "Overschakelen op Engels",
|
|
156
|
+
secondaryLabel: "Niet nu"
|
|
157
|
+
},
|
|
158
|
+
"nb-no": {
|
|
159
|
+
messageText:
|
|
160
|
+
"Denne teksten er oversatt med Salesforce maskinoversettingssystem. Flere detaljer {link}.",
|
|
161
|
+
linkUrl:
|
|
162
|
+
"https://help.salesforce.com/s/articleView?id=000396076&type=1&language=no",
|
|
163
|
+
linkText: "her",
|
|
164
|
+
buttonLabel: "Bytt til engelsk",
|
|
165
|
+
secondaryLabel: "Ikke nå"
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export default class LocaleBanner extends LightningElement {
|
|
170
|
+
@api locale = DEFAULT_LOCALE;
|
|
171
|
+
@api targetHref = "";
|
|
172
|
+
@api dismissStorageKey = "";
|
|
173
|
+
|
|
174
|
+
get localeData(): LocaleStrings {
|
|
175
|
+
return LOCALE_STRINGS[this.locale] || LOCALE_STRINGS[DEFAULT_LOCALE];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
get bannerMessage(): string {
|
|
179
|
+
const data = this.localeData;
|
|
180
|
+
const link = `<a href="${data.linkUrl}">${data.linkText}</a>`;
|
|
181
|
+
return data.messageText.replace("{link}", link);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
get bannerButtonLabel(): string {
|
|
185
|
+
return this.localeData.buttonLabel;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
get bannerButtonHref(): string {
|
|
189
|
+
return this.targetHref;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
get bannerSecondaryLabel(): string {
|
|
193
|
+
return this.localeData.secondaryLabel;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
></path>
|
|
42
42
|
</g>
|
|
43
43
|
</svg>
|
|
44
|
-
{
|
|
44
|
+
{readingTimeLabel}
|
|
45
45
|
</div>
|
|
46
46
|
<slot onslotchange={onSlotChange}></slot>
|
|
47
47
|
<doc-sprig-survey
|
|
@@ -57,7 +57,10 @@
|
|
|
57
57
|
</div>
|
|
58
58
|
</div>
|
|
59
59
|
<div lwc:if={showFooter} class="footer-container">
|
|
60
|
-
<dx-footer
|
|
60
|
+
<dx-footer
|
|
61
|
+
variant="no-signup"
|
|
62
|
+
mfe-config-origin={effectiveFooterOrigin}
|
|
63
|
+
></dx-footer>
|
|
61
64
|
</div>
|
|
62
65
|
</div>
|
|
63
66
|
</div>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { createElement, LightningElement, api } from "lwc";
|
|
3
3
|
import DocPhase from "doc/phase";
|
|
4
4
|
import DxFooter from "dx/footer";
|
|
5
|
+
import DxIcon from "dx/icon";
|
|
5
6
|
import SprigSurvey from "doc/sprigSurvey";
|
|
6
7
|
import { throttle } from "throttle-debounce";
|
|
7
8
|
import { pollUntil } from "dxUtils/async";
|
|
@@ -14,11 +15,19 @@ declare global {
|
|
|
14
15
|
|
|
15
16
|
declare const Sprig: (eventType: string, eventName: string) => void;
|
|
16
17
|
|
|
18
|
+
type ReferenceTopic = {
|
|
19
|
+
link?: { href?: string };
|
|
20
|
+
children?: ReferenceTopic[];
|
|
21
|
+
};
|
|
22
|
+
|
|
17
23
|
type ReferenceItem = {
|
|
18
24
|
source: string;
|
|
19
25
|
href: string;
|
|
26
|
+
title?: string;
|
|
20
27
|
isSelected?: boolean;
|
|
21
28
|
docPhase?: string | null;
|
|
29
|
+
referenceType?: string;
|
|
30
|
+
topic?: ReferenceTopic;
|
|
22
31
|
};
|
|
23
32
|
|
|
24
33
|
type ReferenceConfig = {
|
|
@@ -28,6 +37,7 @@ type ReferenceConfig = {
|
|
|
28
37
|
const SCROLL_THROTTLE_DELAY = 50;
|
|
29
38
|
const ELEMENT_TIMEOUT = 10000;
|
|
30
39
|
const ELEMENT_CHECK_INTERVAL = 100;
|
|
40
|
+
const REFERENCES_SEGMENT = "/references/";
|
|
31
41
|
|
|
32
42
|
export default class RedocReference extends LightningElement {
|
|
33
43
|
private _referenceConfig: ReferenceConfig = { refList: [] };
|
|
@@ -38,6 +48,12 @@ export default class RedocReference extends LightningElement {
|
|
|
38
48
|
private docPhaseWrapperElement: Element | null = null;
|
|
39
49
|
private lastSidebarTop = 0;
|
|
40
50
|
|
|
51
|
+
/**
|
|
52
|
+
* History length captured at mount (pre-Redoc), used by `onBackClick` to
|
|
53
|
+
* distinguish in-tab navigation (> 1) from a fresh entry (=== 1).
|
|
54
|
+
*/
|
|
55
|
+
private initialHistoryLength = 0;
|
|
56
|
+
|
|
41
57
|
showError = false;
|
|
42
58
|
|
|
43
59
|
@api
|
|
@@ -71,6 +87,75 @@ export default class RedocReference extends LightningElement {
|
|
|
71
87
|
/** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer. */
|
|
72
88
|
@api origin: string | null = null;
|
|
73
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Project title (same value passed to `<doc-header>` as `subtitle`). Used
|
|
92
|
+
* inside the Redoc-rendered UI to label the parent project.
|
|
93
|
+
*/
|
|
94
|
+
@api projectTitle: string | null = "All Reference";
|
|
95
|
+
|
|
96
|
+
get specTitle(): string | null {
|
|
97
|
+
return this.getSelectedReference()?.title ?? null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Whether to show the project header (only for multi-spec reference sets).
|
|
102
|
+
*/
|
|
103
|
+
get showRedocHeader(): boolean {
|
|
104
|
+
const refCount = this._referenceConfig?.refList?.length ?? 0;
|
|
105
|
+
const isMultiSpecSet = refCount > 1;
|
|
106
|
+
return isMultiSpecSet && !!(this.projectTitle || this.specTitle);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Navigates back to reference doc.
|
|
111
|
+
*/
|
|
112
|
+
private onBackClick = (event: Event): void => {
|
|
113
|
+
event.preventDefault();
|
|
114
|
+
const referrerHref = this.getSameOriginReferrerHref();
|
|
115
|
+
if (referrerHref) {
|
|
116
|
+
window.location.href = referrerHref;
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const fallbackHref = this.getReferencesRootHref();
|
|
120
|
+
if (fallbackHref) {
|
|
121
|
+
window.location.href = fallbackHref;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Returns the referrer URL when the page was reached via in-tab navigation
|
|
127
|
+
* from a same-origin page; otherwise `null`. Both `initialHistoryLength`
|
|
128
|
+
* and `document.referrer` are checked since neither signal is reliable on
|
|
129
|
+
* its own.
|
|
130
|
+
*/
|
|
131
|
+
private getSameOriginReferrerHref(): string | null {
|
|
132
|
+
if (this.initialHistoryLength <= 1 || !document.referrer) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const referrerUrl = new URL(document.referrer);
|
|
137
|
+
if (referrerUrl.origin !== window.location.origin) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
return referrerUrl.href;
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Derives the project's `.../references` root from the current URL by
|
|
148
|
+
* trimming any trailing reference id (and deeper segments). Returns null
|
|
149
|
+
* when the URL doesn't contain a `/references` segment.
|
|
150
|
+
*/
|
|
151
|
+
private getReferencesRootHref(): string | null {
|
|
152
|
+
const { pathname } = window.location;
|
|
153
|
+
const idx = pathname.lastIndexOf(REFERENCES_SEGMENT);
|
|
154
|
+
return idx === -1
|
|
155
|
+
? null
|
|
156
|
+
: pathname.slice(0, idx + REFERENCES_SEGMENT.length);
|
|
157
|
+
}
|
|
158
|
+
|
|
74
159
|
/** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
|
|
75
160
|
get effectiveFooterOrigin(): string {
|
|
76
161
|
return (
|
|
@@ -79,6 +164,10 @@ export default class RedocReference extends LightningElement {
|
|
|
79
164
|
}
|
|
80
165
|
|
|
81
166
|
connectedCallback(): void {
|
|
167
|
+
// Snapshot history length before Redoc pushes its own hash entries,
|
|
168
|
+
// so it reflects real in-tab navigation rather than Redoc's churn.
|
|
169
|
+
this.initialHistoryLength = window.history.length;
|
|
170
|
+
|
|
82
171
|
window.addEventListener("scroll", this.handleScrollAndResize);
|
|
83
172
|
window.addEventListener("resize", this.handleScrollAndResize);
|
|
84
173
|
}
|
|
@@ -212,7 +301,8 @@ export default class RedocReference extends LightningElement {
|
|
|
212
301
|
const currentUrl = window.location;
|
|
213
302
|
const existingParams = currentUrl.search + currentUrl.hash;
|
|
214
303
|
|
|
215
|
-
|
|
304
|
+
// Use replaceState to avoid creating a new history entry when the user visits /references without any reference ID
|
|
305
|
+
window.history.replaceState(
|
|
216
306
|
{},
|
|
217
307
|
"",
|
|
218
308
|
`${parentReferencePath}${existingParams}`
|
|
@@ -303,6 +393,9 @@ export default class RedocReference extends LightningElement {
|
|
|
303
393
|
|
|
304
394
|
this.appendFooterItems(apiContentDiv);
|
|
305
395
|
|
|
396
|
+
// Inject the multi-spec project header into Redoc's left menu only.
|
|
397
|
+
this.insertProjectHeaderInMenu(redocContainer);
|
|
398
|
+
|
|
306
399
|
// Wait for footer to be rendered before updating styles
|
|
307
400
|
requestAnimationFrame(() => {
|
|
308
401
|
this.updateRedocThirdColumnStyle(redocContainer);
|
|
@@ -315,6 +408,65 @@ export default class RedocReference extends LightningElement {
|
|
|
315
408
|
}
|
|
316
409
|
}
|
|
317
410
|
|
|
411
|
+
/**
|
|
412
|
+
* Inserts the project header into Redoc for multi-spec reference sets.
|
|
413
|
+
*/
|
|
414
|
+
private insertProjectHeaderInMenu(redocContainer: HTMLElement): void {
|
|
415
|
+
if (!this.showRedocHeader) {
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// Select the LNB and content area of Redoc and insert the requried header.
|
|
420
|
+
redocContainer
|
|
421
|
+
.querySelectorAll<HTMLElement>(".menu-content, .api-content")
|
|
422
|
+
.forEach((target) => {
|
|
423
|
+
target.insertBefore(
|
|
424
|
+
this.buildProjectHeaderDom(),
|
|
425
|
+
target.firstChild
|
|
426
|
+
);
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Builds a fresh project-title/spec-title header DOM node.
|
|
432
|
+
*/
|
|
433
|
+
private buildProjectHeaderDom(): HTMLElement {
|
|
434
|
+
const wrapper = document.createElement("div");
|
|
435
|
+
wrapper.className = "redoc-project-header";
|
|
436
|
+
|
|
437
|
+
if (this.projectTitle) {
|
|
438
|
+
const backLink = document.createElement("a");
|
|
439
|
+
backLink.className = "redoc-project-back";
|
|
440
|
+
backLink.href = "#";
|
|
441
|
+
backLink.addEventListener("click", this.onBackClick);
|
|
442
|
+
|
|
443
|
+
const icon = createElement("dx-icon", { is: DxIcon });
|
|
444
|
+
Object.assign(icon, {
|
|
445
|
+
sprite: "utility",
|
|
446
|
+
symbol: "back",
|
|
447
|
+
size: "medium"
|
|
448
|
+
});
|
|
449
|
+
icon.classList.add("redoc-project-back-arrow");
|
|
450
|
+
|
|
451
|
+
const label = document.createElement("span");
|
|
452
|
+
label.className = "redoc-project-title";
|
|
453
|
+
label.textContent = this.projectTitle;
|
|
454
|
+
|
|
455
|
+
backLink.appendChild(icon);
|
|
456
|
+
backLink.appendChild(label);
|
|
457
|
+
wrapper.appendChild(backLink);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (this.specTitle) {
|
|
461
|
+
const specEl = document.createElement("h2");
|
|
462
|
+
specEl.className = "redoc-spec-title dx-text-display-7";
|
|
463
|
+
specEl.textContent = this.specTitle;
|
|
464
|
+
wrapper.appendChild(specEl);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
return wrapper;
|
|
468
|
+
}
|
|
469
|
+
|
|
318
470
|
// Waits for Redoc's API content element to be rendered
|
|
319
471
|
private async waitForApiContent(
|
|
320
472
|
container: HTMLElement
|
|
@@ -348,7 +500,10 @@ export default class RedocReference extends LightningElement {
|
|
|
348
500
|
// Appends footer component to container
|
|
349
501
|
private insertFooter(container: HTMLElement): void {
|
|
350
502
|
const footerElement = createElement("dx-footer", { is: DxFooter });
|
|
351
|
-
Object.assign(footerElement, {
|
|
503
|
+
Object.assign(footerElement, {
|
|
504
|
+
variant: "no-signup",
|
|
505
|
+
mfeConfigOrigin: this.effectiveFooterOrigin
|
|
506
|
+
});
|
|
352
507
|
container.appendChild(footerElement);
|
|
353
508
|
}
|
|
354
509
|
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
</doc-content-layout>
|
|
54
54
|
<div lwc:if={display404}>
|
|
55
55
|
<dx-error
|
|
56
|
-
image="https://developer.salesforce.com/ns-assets/
|
|
56
|
+
image="https://developer.salesforce.com/ns-assets/404.svg"
|
|
57
57
|
code="404"
|
|
58
58
|
header="Beep boop. That did not compute."
|
|
59
59
|
subtitle="The document you're looking for doesn't seem to exist."
|