@salesforcedevs/docs-components 1.28.7-alpha.9 → 1.29.0-aitoolbar-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.
- package/lwc.config.json +3 -0
- package/package.json +28 -28
- package/src/modules/doc/aiToolbar/aiToolbar.css +40 -0
- package/src/modules/doc/aiToolbar/aiToolbar.html +53 -0
- package/src/modules/doc/aiToolbar/aiToolbar.ts +138 -0
- package/src/modules/doc/aiToolbar/aiToolbarMocks.ts +48 -0
- package/src/modules/doc/amfReference/amfReference.html +1 -0
- package/src/modules/doc/amfReference/amfReference.ts +62 -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/contentLayout/contentLayout.html +17 -30
- package/src/modules/doc/contentLayout/contentLayout.ts +105 -26
- 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 -13
- package/src/modules/doc/lwcContentLayout/lwcContentLayout.ts +11 -0
- package/src/modules/doc/redocReference/redocReference.ts +167 -2
- package/src/modules/doc/xmlContent/xmlContent.html +1 -1
- package/src/modules/doc/xmlContent/xmlContent.ts +49 -10
- package/LICENSE +0 -12
|
@@ -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
|
|
@@ -68,7 +84,90 @@ export default class RedocReference extends LightningElement {
|
|
|
68
84
|
this._parentDocPhaseInfo = value;
|
|
69
85
|
}
|
|
70
86
|
|
|
87
|
+
/** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer. */
|
|
88
|
+
@api origin: string | null = null;
|
|
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
|
+
|
|
159
|
+
/** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
|
|
160
|
+
get effectiveFooterOrigin(): string {
|
|
161
|
+
return (
|
|
162
|
+
this.origin ?? `${window.location.origin}/developer/en-us/wp-json`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
71
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
|
+
|
|
72
171
|
window.addEventListener("scroll", this.handleScrollAndResize);
|
|
73
172
|
window.addEventListener("resize", this.handleScrollAndResize);
|
|
74
173
|
}
|
|
@@ -202,7 +301,8 @@ export default class RedocReference extends LightningElement {
|
|
|
202
301
|
const currentUrl = window.location;
|
|
203
302
|
const existingParams = currentUrl.search + currentUrl.hash;
|
|
204
303
|
|
|
205
|
-
|
|
304
|
+
// Use replaceState to avoid creating a new history entry when the user visits /references without any reference ID
|
|
305
|
+
window.history.replaceState(
|
|
206
306
|
{},
|
|
207
307
|
"",
|
|
208
308
|
`${parentReferencePath}${existingParams}`
|
|
@@ -293,6 +393,9 @@ export default class RedocReference extends LightningElement {
|
|
|
293
393
|
|
|
294
394
|
this.appendFooterItems(apiContentDiv);
|
|
295
395
|
|
|
396
|
+
// Inject the multi-spec project header into Redoc's left menu only.
|
|
397
|
+
this.insertProjectHeaderInMenu(redocContainer);
|
|
398
|
+
|
|
296
399
|
// Wait for footer to be rendered before updating styles
|
|
297
400
|
requestAnimationFrame(() => {
|
|
298
401
|
this.updateRedocThirdColumnStyle(redocContainer);
|
|
@@ -305,6 +408,65 @@ export default class RedocReference extends LightningElement {
|
|
|
305
408
|
}
|
|
306
409
|
}
|
|
307
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
|
+
|
|
308
470
|
// Waits for Redoc's API content element to be rendered
|
|
309
471
|
private async waitForApiContent(
|
|
310
472
|
container: HTMLElement
|
|
@@ -338,7 +500,10 @@ export default class RedocReference extends LightningElement {
|
|
|
338
500
|
// Appends footer component to container
|
|
339
501
|
private insertFooter(container: HTMLElement): void {
|
|
340
502
|
const footerElement = createElement("dx-footer", { is: DxFooter });
|
|
341
|
-
Object.assign(footerElement, {
|
|
503
|
+
Object.assign(footerElement, {
|
|
504
|
+
variant: "no-signup",
|
|
505
|
+
mfeConfigOrigin: this.effectiveFooterOrigin
|
|
506
|
+
});
|
|
342
507
|
container.appendChild(footerElement);
|
|
343
508
|
}
|
|
344
509
|
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
</doc-content-layout>
|
|
54
54
|
<div lwc:if={display404}>
|
|
55
55
|
<dx-error
|
|
56
|
-
image="https://
|
|
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."
|
|
@@ -48,6 +48,9 @@ export default class DocXmlContent extends LightningElementWithState<{
|
|
|
48
48
|
/** Optional origin URL for the footer MFE (e.g. wp-json endpoint). Passed through to dx-footer-mfe. */
|
|
49
49
|
@api origin: string | null = null;
|
|
50
50
|
|
|
51
|
+
/** Optional base URL for the canonical link (e.g. https://developer.salesforce.com). When set, used instead of window.location for the canonical href. */
|
|
52
|
+
@api baseUrl: string | null = null;
|
|
53
|
+
|
|
51
54
|
@api
|
|
52
55
|
get allLanguages(): Array<Language> {
|
|
53
56
|
return this._allLanguages;
|
|
@@ -251,6 +254,17 @@ export default class DocXmlContent extends LightningElementWithState<{
|
|
|
251
254
|
return this.pageReference.deliverable;
|
|
252
255
|
}
|
|
253
256
|
|
|
257
|
+
private get useOldSidebar(): boolean {
|
|
258
|
+
// Coveo is enabled and the version is greater than 51 (within the latest 3 versions)
|
|
259
|
+
// TODO: we need a better fix for version number check
|
|
260
|
+
return !(
|
|
261
|
+
!this.version?.releaseVersion ||
|
|
262
|
+
(this.version?.releaseVersion &&
|
|
263
|
+
parseInt(this.version.releaseVersion.replace("v", ""), 10) >=
|
|
264
|
+
53)
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
254
268
|
private get pageHeader(): Header {
|
|
255
269
|
if (!this._pageHeader) {
|
|
256
270
|
this._pageHeader = document.querySelector("doc-header")!;
|
|
@@ -308,8 +322,10 @@ export default class DocXmlContent extends LightningElementWithState<{
|
|
|
308
322
|
};
|
|
309
323
|
}
|
|
310
324
|
|
|
311
|
-
private handlePopState = (event: PopStateEvent): void =>
|
|
325
|
+
private handlePopState = (event: PopStateEvent): void => {
|
|
312
326
|
this.updatePageReference(this.getReferenceFromUrl(), event);
|
|
327
|
+
this.handleLocaleReload();
|
|
328
|
+
};
|
|
313
329
|
|
|
314
330
|
handleDismissVersionBanner() {
|
|
315
331
|
this.showVersionBanner = false;
|
|
@@ -584,6 +600,31 @@ export default class DocXmlContent extends LightningElementWithState<{
|
|
|
584
600
|
"docs",
|
|
585
601
|
this.pageReferenceToString(this.pageReference)
|
|
586
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
|
+
}
|
|
587
628
|
}
|
|
588
629
|
|
|
589
630
|
private updateHighlighting(searchParam: string): void {
|
|
@@ -755,21 +796,19 @@ export default class DocXmlContent extends LightningElementWithState<{
|
|
|
755
796
|
}
|
|
756
797
|
|
|
757
798
|
if (this.pageReference) {
|
|
758
|
-
const
|
|
799
|
+
const canonicalLink = document.querySelector(
|
|
759
800
|
'link[rel="canonical"]'
|
|
760
801
|
);
|
|
761
|
-
if (
|
|
802
|
+
if (canonicalLink) {
|
|
762
803
|
const copyPageReference = { ...this.pageReference };
|
|
763
804
|
copyPageReference.docId = copyPageReference.docId
|
|
764
805
|
? this.dropVersionFromDocId(copyPageReference.docId)
|
|
765
806
|
: copyPageReference.docId;
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
this.pageReferenceToString(copyPageReference)
|
|
772
|
-
);
|
|
807
|
+
const path = this.pageReferenceToString(copyPageReference);
|
|
808
|
+
const origin = this.baseUrl
|
|
809
|
+
? this.baseUrl.replace(/\/$/, "")
|
|
810
|
+
: `${window.location.protocol}//${window.location.host}`;
|
|
811
|
+
canonicalLink.setAttribute("href", `${origin}${path}`);
|
|
773
812
|
}
|
|
774
813
|
}
|
|
775
814
|
|
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.
|