@salesforcedevs/docs-components 1.29.0-alpha1 → 1.29.0-llm-alpha

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.
Files changed (26) hide show
  1. package/lwc.config.json +3 -1
  2. package/package.json +3 -3
  3. package/src/modules/doc/aiToolbar/aiToolbar.css +40 -0
  4. package/src/modules/doc/aiToolbar/aiToolbar.html +53 -0
  5. package/src/modules/doc/aiToolbar/aiToolbar.ts +83 -0
  6. package/src/modules/doc/aiToolbar/aiToolbarMocks.ts +48 -0
  7. package/src/modules/doc/amfReference/amfReference.ts +52 -10
  8. package/src/modules/doc/amfReference/types.ts +5 -0
  9. package/src/modules/doc/banner/banner.css +88 -0
  10. package/src/modules/doc/banner/banner.html +47 -0
  11. package/src/modules/doc/banner/banner.ts +73 -0
  12. package/src/modules/doc/contentLayout/contentLayout.html +1 -1
  13. package/src/modules/doc/contentLayout/contentLayout.ts +106 -2
  14. package/src/modules/doc/header/header.html +0 -1
  15. package/src/modules/doc/localeBanner/localeBanner.css +3 -0
  16. package/src/modules/doc/localeBanner/localeBanner.html +9 -0
  17. package/src/modules/doc/localeBanner/localeBanner.ts +195 -0
  18. package/src/modules/doc/lwcContentLayout/lwcContentLayout.html +5 -2
  19. package/src/modules/doc/redocReference/redocReference.ts +157 -121
  20. package/src/modules/doc/xmlContent/xmlContent.html +1 -1
  21. package/src/modules/doc/xmlContent/xmlContent.ts +28 -1
  22. package/src/modules/doc/apiPlayground/apiPlayground.css +0 -186
  23. package/src/modules/doc/apiPlayground/apiPlayground.html +0 -136
  24. package/src/modules/doc/apiPlayground/apiPlayground.ts +0 -240
  25. package/src/modules/docUtils/apiRequestExecutor/apiRequestExecutor.ts +0 -96
  26. package/src/modules/docUtils/openApiParser/openApiParser.ts +0 -187
@@ -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 AiToolbar from "doc/aiToolbar";
10
+
11
+ const AI_TOOLBAR_TAG = "doc-ai-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 AI toolbar is displayed. */
103
+ @api
104
+ get showAiToolbar() {
105
+ return this._showAiToolbar;
106
+ }
107
+ set showAiToolbar(value) {
108
+ this._showAiToolbar = normalizeBoolean(value);
109
+ this.updateAiToolbar();
110
+ }
111
+ private _showAiToolbar = 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 aiToolbarElement: 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.updateAiToolbar();
277
+
218
278
  if (!this.hasRendered) {
219
279
  this.hasRendered = true;
220
280
  this.restoreScroll();
@@ -224,6 +284,47 @@ export default class ContentLayout extends LightningElement {
224
284
  }
225
285
  }
226
286
 
287
+ /**
288
+ * Inserts the AI toolbar into the slotted content immediately after the
289
+ * first H1 found inside this layout. The H1 typically lives deep in
290
+ * `doc-content`'s shadow (rendered via `lwc:dom="manual"`), so we use
291
+ * kagekiri's shadow-piercing query to locate it from here.
292
+ */
293
+ protected updateAiToolbar(): void {
294
+ if (!this.showAiToolbar) {
295
+ this.removeAiToolbar();
296
+ return;
297
+ }
298
+
299
+ const heading = querySelector(
300
+ PAGE_HEADING_SELECTOR,
301
+ this.template.host
302
+ ) as HTMLElement | null;
303
+
304
+ if (!heading) {
305
+ return;
306
+ }
307
+
308
+ if (this.aiToolbarElement?.previousElementSibling === heading) {
309
+ return;
310
+ }
311
+
312
+ this.removeAiToolbar();
313
+
314
+ const toolbar = createElement(AI_TOOLBAR_TAG, {
315
+ is: AiToolbar
316
+ }) as unknown as HTMLElement;
317
+ heading.parentNode?.insertBefore(toolbar, heading.nextSibling);
318
+ this.aiToolbarElement = toolbar;
319
+ }
320
+
321
+ protected removeAiToolbar(): void {
322
+ if (this.aiToolbarElement) {
323
+ this.aiToolbarElement.remove();
324
+ this.aiToolbarElement = null;
325
+ }
326
+ }
327
+
227
328
  disconnectedCallback(): void {
228
329
  this.disconnectObserver();
229
330
  window.removeEventListener(
@@ -239,6 +340,8 @@ export default class ContentLayout extends LightningElement {
239
340
 
240
341
  // Remove link click handler
241
342
  this.template.removeEventListener("click", this.handleLinkClick);
343
+
344
+ this.removeAiToolbar();
242
345
  }
243
346
 
244
347
  restoreScroll() {
@@ -481,6 +584,7 @@ export default class ContentLayout extends LightningElement {
481
584
 
482
585
  onSlotChange(): void {
483
586
  this.updateRNB();
587
+ this.updateAiToolbar();
484
588
  this.contentLoaded = true;
485
589
  }
486
590
 
@@ -13,7 +13,6 @@
13
13
  onclick={onLinkClick}
14
14
  class="dev-center-content"
15
15
  >
16
- <dx-icon symbol="back"></dx-icon>
17
16
  <dx-icon
18
17
  class="brand-icon"
19
18
  lwc:if={devCenter.icon}
@@ -0,0 +1,3 @@
1
+ :host {
2
+ display: block;
3
+ }
@@ -0,0 +1,9 @@
1
+ <template>
2
+ <doc-banner
3
+ message={bannerMessage}
4
+ button-label={bannerButtonLabel}
5
+ button-href={bannerButtonHref}
6
+ secondary-label={bannerSecondaryLabel}
7
+ dismiss-storage-key={dismissStorageKey}
8
+ ></doc-banner>
9
+ </template>
@@ -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
- {readingTime} minute read
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 variant="no-signup" mfe-config-origin={effectiveFooterOrigin}></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>