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

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
@@ -2,12 +2,10 @@
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
- import ApiPlayground from "doc/apiPlayground";
7
7
  import { throttle } from "throttle-debounce";
8
8
  import { pollUntil } from "dxUtils/async";
9
- import { parseOpenApiSpec } from "docUtils/openApiParser";
10
- import type { OperationDefinition } from "docUtils/openApiParser";
11
9
 
12
10
  declare global {
13
11
  interface Window {
@@ -17,11 +15,19 @@ declare global {
17
15
 
18
16
  declare const Sprig: (eventType: string, eventName: string) => void;
19
17
 
18
+ type ReferenceTopic = {
19
+ link?: { href?: string };
20
+ children?: ReferenceTopic[];
21
+ };
22
+
20
23
  type ReferenceItem = {
21
24
  source: string;
22
25
  href: string;
26
+ title?: string;
23
27
  isSelected?: boolean;
24
28
  docPhase?: string | null;
29
+ referenceType?: string;
30
+ topic?: ReferenceTopic;
25
31
  };
26
32
 
27
33
  type ReferenceConfig = {
@@ -31,6 +37,7 @@ type ReferenceConfig = {
31
37
  const SCROLL_THROTTLE_DELAY = 50;
32
38
  const ELEMENT_TIMEOUT = 10000;
33
39
  const ELEMENT_CHECK_INTERVAL = 100;
40
+ const REFERENCES_SEGMENT = "/references/";
34
41
 
35
42
  export default class RedocReference extends LightningElement {
36
43
  private _referenceConfig: ReferenceConfig = { refList: [] };
@@ -41,11 +48,13 @@ export default class RedocReference extends LightningElement {
41
48
  private docPhaseWrapperElement: Element | null = null;
42
49
  private lastSidebarTop = 0;
43
50
 
44
- showError = false;
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;
45
56
 
46
- private parsedOperations: OperationDefinition[] = [];
47
- private openApiSpec: any = null;
48
- private playgroundInstances: Map<string, HTMLElement> = new Map();
57
+ showError = false;
49
58
 
50
59
  @api
51
60
  get referenceConfig(): ReferenceConfig {
@@ -78,6 +87,75 @@ export default class RedocReference extends LightningElement {
78
87
  /** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer. */
79
88
  @api origin: string | null = null;
80
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
+
81
159
  /** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
82
160
  get effectiveFooterOrigin(): string {
83
161
  return (
@@ -86,6 +164,10 @@ export default class RedocReference extends LightningElement {
86
164
  }
87
165
 
88
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
+
89
171
  window.addEventListener("scroll", this.handleScrollAndResize);
90
172
  window.addEventListener("resize", this.handleScrollAndResize);
91
173
  }
@@ -106,7 +188,6 @@ export default class RedocReference extends LightningElement {
106
188
  // Clean up cached DOM element references to prevent memory leaks
107
189
  this.docHeaderElement = null;
108
190
  this.docPhaseWrapperElement = null;
109
- this.playgroundInstances.clear();
110
191
  }
111
192
 
112
193
  // Displays error UI and logs error message for debugging
@@ -220,7 +301,8 @@ export default class RedocReference extends LightningElement {
220
301
  const currentUrl = window.location;
221
302
  const existingParams = currentUrl.search + currentUrl.hash;
222
303
 
223
- window.history.pushState(
304
+ // Use replaceState to avoid creating a new history entry when the user visits /references without any reference ID
305
+ window.history.replaceState(
224
306
  {},
225
307
  "",
226
308
  `${parentReferencePath}${existingParams}`
@@ -254,8 +336,6 @@ export default class RedocReference extends LightningElement {
254
336
  return;
255
337
  }
256
338
 
257
- this.fetchAndParseSpec(specUrl);
258
-
259
339
  window.Redoc.init(
260
340
  specUrl,
261
341
  {
@@ -313,10 +393,12 @@ export default class RedocReference extends LightningElement {
313
393
 
314
394
  this.appendFooterItems(apiContentDiv);
315
395
 
396
+ // Inject the multi-spec project header into Redoc's left menu only.
397
+ this.insertProjectHeaderInMenu(redocContainer);
398
+
316
399
  // Wait for footer to be rendered before updating styles
317
400
  requestAnimationFrame(() => {
318
401
  this.updateRedocThirdColumnStyle(redocContainer);
319
- this.injectTryItButtons();
320
402
 
321
403
  // Fix initial hash scroll after doc phase insertion
322
404
  this.handleInitialHashScrollFix();
@@ -326,6 +408,65 @@ export default class RedocReference extends LightningElement {
326
408
  }
327
409
  }
328
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
+
329
470
  // Waits for Redoc's API content element to be rendered
330
471
  private async waitForApiContent(
331
472
  container: HTMLElement
@@ -359,7 +500,10 @@ export default class RedocReference extends LightningElement {
359
500
  // Appends footer component to container
360
501
  private insertFooter(container: HTMLElement): void {
361
502
  const footerElement = createElement("dx-footer", { is: DxFooter });
362
- Object.assign(footerElement, { variant: "no-signup", mfeConfigOrigin: this.effectiveFooterOrigin });
503
+ Object.assign(footerElement, {
504
+ variant: "no-signup",
505
+ mfeConfigOrigin: this.effectiveFooterOrigin
506
+ });
363
507
  container.appendChild(footerElement);
364
508
  }
365
509
 
@@ -421,114 +565,6 @@ export default class RedocReference extends LightningElement {
421
565
  );
422
566
  }
423
567
 
424
- // Fetches and parses the OpenAPI spec for Try It playground
425
- private async fetchAndParseSpec(specUrl: string): Promise<void> {
426
- try {
427
- const response = await fetch(specUrl);
428
- if (!response.ok) {
429
- return;
430
- }
431
- this.openApiSpec = await response.json();
432
- this.parsedOperations = parseOpenApiSpec(this.openApiSpec);
433
- } catch {
434
- // Non-fatal: playground simply won't be available
435
- }
436
- }
437
-
438
- // Injects "Try It" toggle buttons into Redoc operation sections
439
- private injectTryItButtons(): void {
440
- if (this.parsedOperations.length === 0) {
441
- return;
442
- }
443
-
444
- const redocContainer = this.getRedocContainer();
445
- if (!redocContainer) {
446
- return;
447
- }
448
-
449
- for (const operation of this.parsedOperations) {
450
- const sectionId = `operation/${operation.operationId}`;
451
- const section = redocContainer.querySelector(
452
- `[data-section-id="${sectionId}"]`
453
- );
454
- if (!section) {
455
- continue;
456
- }
457
-
458
- // Skip if button already injected
459
- if (section.querySelector(".try-it-toggle")) {
460
- continue;
461
- }
462
-
463
- const button = document.createElement("button");
464
- button.className = "try-it-toggle";
465
- button.textContent = "Try It";
466
- button.setAttribute("type", "button");
467
- button.setAttribute("aria-expanded", "false");
468
- button.style.cssText =
469
- "display:inline-flex;align-items:center;gap:4px;padding:4px 12px;" +
470
- "border:1px solid #0070d2;border-radius:4px;background:#fff;color:#0070d2;" +
471
- "font-size:12px;font-weight:600;cursor:pointer;margin-left:12px;vertical-align:middle;";
472
- button.addEventListener("click", () => {
473
- this.togglePlayground(operation, section as HTMLElement);
474
- });
475
-
476
- // Insert button after the first heading or at the start
477
- const heading = section.querySelector("h1, h2, h3");
478
- if (heading?.parentElement) {
479
- heading.parentElement.insertBefore(
480
- button,
481
- heading.nextSibling
482
- );
483
- } else {
484
- section.insertBefore(button, section.firstChild);
485
- }
486
- }
487
- }
488
-
489
- // Toggles the playground panel for an operation section
490
- private togglePlayground(
491
- operation: OperationDefinition,
492
- section: HTMLElement
493
- ): void {
494
- const operationId = operation.operationId;
495
- const existingWrapper = this.playgroundInstances.get(operationId);
496
-
497
- if (existingWrapper) {
498
- const isHidden = existingWrapper.style.display === "none";
499
- existingWrapper.style.display = isHidden ? "block" : "none";
500
-
501
- const button = section.querySelector(".try-it-toggle");
502
- if (button) {
503
- button.setAttribute(
504
- "aria-expanded",
505
- isHidden ? "true" : "false"
506
- );
507
- }
508
- return;
509
- }
510
-
511
- const wrapper = document.createElement("div");
512
- wrapper.className = "try-it-playground-wrapper";
513
-
514
- const playgroundElement = createElement("doc-api-playground", {
515
- is: ApiPlayground
516
- });
517
- Object.assign(playgroundElement, {
518
- operation,
519
- spec: this.openApiSpec
520
- });
521
-
522
- wrapper.appendChild(playgroundElement);
523
- section.appendChild(wrapper);
524
- this.playgroundInstances.set(operationId, wrapper);
525
-
526
- const button = section.querySelector(".try-it-toggle");
527
- if (button) {
528
- button.setAttribute("aria-expanded", "true");
529
- }
530
- }
531
-
532
568
  // Fixes initial hash scroll positioning after doc phase insertion
533
569
  private handleInitialHashScrollFix(): void {
534
570
  const hash = window.location.hash;
@@ -53,7 +53,7 @@
53
53
  </doc-content-layout>
54
54
  <div lwc:if={display404}>
55
55
  <dx-error
56
- image="https://a.sfdcstatic.com/developer-website/prod/images/404.svg"
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."
@@ -322,8 +322,10 @@ export default class DocXmlContent extends LightningElementWithState<{
322
322
  };
323
323
  }
324
324
 
325
- private handlePopState = (event: PopStateEvent): void =>
325
+ private handlePopState = (event: PopStateEvent): void => {
326
326
  this.updatePageReference(this.getReferenceFromUrl(), event);
327
+ this.handleLocaleReload();
328
+ };
327
329
 
328
330
  handleDismissVersionBanner() {
329
331
  this.showVersionBanner = false;
@@ -598,6 +600,31 @@ export default class DocXmlContent extends LightningElementWithState<{
598
600
  "docs",
599
601
  this.pageReferenceToString(this.pageReference)
600
602
  );
603
+ this.handleLocaleReload();
604
+ }
605
+
606
+ /* This method reloads the page as locale banner context is not available in developer-website. */
607
+ private handleLocaleReload(): void {
608
+ const targetLocale = this.language?.id;
609
+ if (!targetLocale) {
610
+ return;
611
+ }
612
+
613
+ const currentPath = window.location.pathname;
614
+ const localePattern = /atlas\.[a-z]{2}-[a-z]{2}\./;
615
+
616
+ if (localePattern.test(currentPath)) {
617
+ const newPath = currentPath.replace(
618
+ localePattern,
619
+ `atlas.${targetLocale}.`
620
+ );
621
+ const newUrl =
622
+ window.location.origin +
623
+ newPath +
624
+ window.location.search +
625
+ window.location.hash;
626
+ window.location.href = newUrl;
627
+ }
601
628
  }
602
629
 
603
630
  private updateHighlighting(searchParam: string): void {
@@ -1,186 +0,0 @@
1
- :host {
2
- display: block;
3
- }
4
-
5
- .playground-container {
6
- border: 1px solid var(--dx-g-color-border-primary, #e0e0e0);
7
- border-radius: 8px;
8
- padding: 20px;
9
- margin: 16px 0;
10
- background: var(--dx-g-color-surface-primary, #ffffff);
11
- }
12
-
13
- .playground-header {
14
- display: flex;
15
- align-items: center;
16
- gap: 12px;
17
- margin-bottom: 20px;
18
- }
19
-
20
- .method-badge {
21
- display: inline-block;
22
- padding: 4px 10px;
23
- border-radius: 4px;
24
- font-size: 12px;
25
- font-weight: 700;
26
- text-transform: uppercase;
27
- color: #fff;
28
- letter-spacing: 0.5px;
29
- }
30
-
31
- .method-get {
32
- background-color: #61affe;
33
- }
34
-
35
- .method-post {
36
- background-color: #49cc90;
37
- }
38
-
39
- .method-put {
40
- background-color: #fca130;
41
- }
42
-
43
- .method-delete {
44
- background-color: #f93e3e;
45
- }
46
-
47
- .method-patch {
48
- background-color: #50e3c2;
49
- }
50
-
51
- .method-options,
52
- .method-head {
53
- background-color: #9012fe;
54
- }
55
-
56
- .operation-path {
57
- font-family: var(--dx-g-font-family-mono, monospace);
58
- font-size: 14px;
59
- font-weight: 600;
60
- color: var(--dx-g-color-text-primary, #181818);
61
- }
62
-
63
- .params-section {
64
- margin-bottom: 16px;
65
- }
66
-
67
- .section-title {
68
- font-size: 13px;
69
- font-weight: 600;
70
- margin: 0 0 8px 0;
71
- color: var(--dx-g-color-text-secondary, #444);
72
- text-transform: uppercase;
73
- letter-spacing: 0.5px;
74
- }
75
-
76
- .field-group {
77
- margin-bottom: 12px;
78
- }
79
-
80
- .field-label {
81
- display: block;
82
- font-size: 13px;
83
- font-weight: 500;
84
- margin-bottom: 4px;
85
- color: var(--dx-g-color-text-primary, #181818);
86
- }
87
-
88
- .required-marker {
89
- color: #f93e3e;
90
- margin-left: 2px;
91
- }
92
-
93
- .field-input,
94
- .server-select {
95
- width: 100%;
96
- padding: 8px 12px;
97
- border: 1px solid var(--dx-g-color-border-primary, #e0e0e0);
98
- border-radius: 4px;
99
- font-size: 14px;
100
- font-family: var(--dx-g-font-family-mono, monospace);
101
- background: var(--dx-g-color-surface-primary, #ffffff);
102
- color: var(--dx-g-color-text-primary, #181818);
103
- box-sizing: border-box;
104
- }
105
-
106
- .field-input:focus,
107
- .server-select:focus {
108
- outline: none;
109
- border-color: var(--dx-g-color-brand, #0070d2);
110
- box-shadow: 0 0 0 1px var(--dx-g-color-brand, #0070d2);
111
- }
112
-
113
- .body-textarea {
114
- width: 100%;
115
- padding: 8px 12px;
116
- border: 1px solid var(--dx-g-color-border-primary, #e0e0e0);
117
- border-radius: 4px;
118
- font-size: 13px;
119
- font-family: var(--dx-g-font-family-mono, monospace);
120
- background: var(--dx-g-color-surface-primary, #ffffff);
121
- color: var(--dx-g-color-text-primary, #181818);
122
- resize: vertical;
123
- box-sizing: border-box;
124
- }
125
-
126
- .body-textarea:focus {
127
- outline: none;
128
- border-color: var(--dx-g-color-brand, #0070d2);
129
- box-shadow: 0 0 0 1px var(--dx-g-color-brand, #0070d2);
130
- }
131
-
132
- .actions {
133
- margin: 16px 0;
134
- }
135
-
136
- .error-display {
137
- margin-top: 16px;
138
- padding: 12px;
139
- border-radius: 4px;
140
- background-color: #fef0ef;
141
- border: 1px solid #f93e3e;
142
- }
143
-
144
- .error-message {
145
- color: #c23934;
146
- font-size: 13px;
147
- margin: 0;
148
- }
149
-
150
- .response-section {
151
- margin-top: 16px;
152
- }
153
-
154
- .response-header {
155
- display: flex;
156
- align-items: center;
157
- gap: 12px;
158
- margin-bottom: 8px;
159
- }
160
-
161
- .status-code {
162
- font-weight: 700;
163
- font-size: 14px;
164
- padding: 2px 8px;
165
- border-radius: 4px;
166
- }
167
-
168
- .status-success {
169
- color: #256029;
170
- background-color: #e6f9ec;
171
- }
172
-
173
- .status-client-error {
174
- color: #974b00;
175
- background-color: #fff3e0;
176
- }
177
-
178
- .status-server-error {
179
- color: #c23934;
180
- background-color: #fef0ef;
181
- }
182
-
183
- .response-duration {
184
- font-size: 12px;
185
- color: var(--dx-g-color-text-tertiary, #999);
186
- }