@salesforcedevs/docs-components 1.32.0 → 1.33.1-new-content-type-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 +1 -0
- package/package.json +28 -28
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.css +1 -0
- package/src/modules/doc/redocReference/redocReference.css +1 -2
- package/src/modules/doc/redocReference/redocReference.ts +188 -35
- package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.css +19 -0
- package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.html +29 -0
- package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.ts +88 -0
- package/src/modules/docUtils/searchClient/searchClient.ts +60 -0
- package/LICENSE +0 -12
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
2
|
+
"name": "@salesforcedevs/docs-components",
|
|
3
|
+
"version": "1.33.1-new-content-type-alpha",
|
|
4
|
+
"description": "Docs Lightning web components for DSC",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": "22.x"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@api-components/amf-helper-mixin": "4.5.29",
|
|
15
|
+
"classnames": "2.5.1",
|
|
16
|
+
"dompurify": "3.2.4",
|
|
17
|
+
"kagekiri": "1.4.2",
|
|
18
|
+
"lodash.orderby": "4.6.0",
|
|
19
|
+
"lodash.uniqby": "4.7.0",
|
|
20
|
+
"query-string": "7.1.3",
|
|
21
|
+
"sentence-case": "3.0.4"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/classnames": "2.3.1",
|
|
25
|
+
"@types/lodash.orderby": "4.6.9",
|
|
26
|
+
"@types/lodash.uniqby": "4.7.9"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
|
|
29
|
+
}
|
|
@@ -3,9 +3,12 @@ import { createElement, LightningElement, api } from "lwc";
|
|
|
3
3
|
import DocPhase from "doc/phase";
|
|
4
4
|
import DxFooter from "dx/footer";
|
|
5
5
|
import DxIcon from "dx/icon";
|
|
6
|
+
import SidebarFooterNav from "dx/sidebarFooterNav";
|
|
6
7
|
import SprigSurvey from "doc/sprigSurvey";
|
|
7
8
|
import { throttle } from "throttle-debounce";
|
|
8
9
|
import { pollUntil } from "dxUtils/async";
|
|
10
|
+
import { toJson } from "dxUtils/normalizers";
|
|
11
|
+
import type { OptionWithLink } from "typings/custom";
|
|
9
12
|
|
|
10
13
|
declare global {
|
|
11
14
|
interface Window {
|
|
@@ -37,7 +40,10 @@ type ReferenceConfig = {
|
|
|
37
40
|
const SCROLL_THROTTLE_DELAY = 50;
|
|
38
41
|
const ELEMENT_TIMEOUT = 10000;
|
|
39
42
|
const ELEMENT_CHECK_INTERVAL = 100;
|
|
40
|
-
const
|
|
43
|
+
const DEFAULT_PROJECT_TITLE = "All Reference";
|
|
44
|
+
const BACK_TARGET_STORAGE_KEY = "redoc-back-target";
|
|
45
|
+
const DOCS_PATH_SEGMENT = "docs";
|
|
46
|
+
const DEFAULT_LOCALE = "en-us";
|
|
41
47
|
|
|
42
48
|
export default class RedocReference extends LightningElement {
|
|
43
49
|
private _referenceConfig: ReferenceConfig = { refList: [] };
|
|
@@ -47,6 +53,7 @@ export default class RedocReference extends LightningElement {
|
|
|
47
53
|
private docHeaderElement: Element | null = null;
|
|
48
54
|
private docPhaseWrapperElement: Element | null = null;
|
|
49
55
|
private lastSidebarTop = 0;
|
|
56
|
+
private _languages: OptionWithLink[] = [];
|
|
50
57
|
|
|
51
58
|
/**
|
|
52
59
|
* History length captured at mount (pre-Redoc), used by `onBackClick` to
|
|
@@ -91,19 +98,86 @@ export default class RedocReference extends LightningElement {
|
|
|
91
98
|
* Project title (same value passed to `<doc-header>` as `subtitle`). Used
|
|
92
99
|
* inside the Redoc-rendered UI to label the parent project.
|
|
93
100
|
*/
|
|
94
|
-
@api
|
|
101
|
+
@api
|
|
102
|
+
get projectTitle(): string | null {
|
|
103
|
+
return this.isDocContentType
|
|
104
|
+
? this._projectTitle
|
|
105
|
+
: DEFAULT_PROJECT_TITLE;
|
|
106
|
+
}
|
|
107
|
+
set projectTitle(value: string | null) {
|
|
108
|
+
this._projectTitle = value;
|
|
109
|
+
}
|
|
110
|
+
private _projectTitle: string | null = null;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Href to navigate to when the back link is clicked AND there is no
|
|
114
|
+
* usable referrer (e.g. the user opened the page directly in a fresh
|
|
115
|
+
* tab).
|
|
116
|
+
*/
|
|
117
|
+
@api headerHref: string | null = null;
|
|
118
|
+
|
|
119
|
+
@api
|
|
120
|
+
get contentType(): string {
|
|
121
|
+
return this._contentType;
|
|
122
|
+
}
|
|
123
|
+
set contentType(value: string) {
|
|
124
|
+
this._contentType = value;
|
|
125
|
+
}
|
|
126
|
+
private _contentType: string = "";
|
|
127
|
+
|
|
128
|
+
@api
|
|
129
|
+
get languages(): OptionWithLink[] {
|
|
130
|
+
return this._languages;
|
|
131
|
+
}
|
|
132
|
+
set languages(value: string | OptionWithLink[]) {
|
|
133
|
+
this._languages = toJson(value) || [];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@api language: string | null = null;
|
|
95
137
|
|
|
96
138
|
get specTitle(): string | null {
|
|
97
139
|
return this.getSelectedReference()?.title ?? null;
|
|
98
140
|
}
|
|
99
141
|
|
|
142
|
+
get isDocContentType(): boolean {
|
|
143
|
+
return this.contentType === "docs";
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
get isReferenceContentType(): boolean {
|
|
147
|
+
return this.contentType === "references";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get isMultiSpecSet(): boolean {
|
|
151
|
+
const refCount = this.referenceConfig?.refList?.length ?? 0;
|
|
152
|
+
return refCount > 1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Reads stored back target
|
|
156
|
+
private getBackTargetFromSession(): string | null {
|
|
157
|
+
return sessionStorage.getItem(BACK_TARGET_STORAGE_KEY);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private setBackTargetInSession(href: string): void {
|
|
161
|
+
sessionStorage.setItem(BACK_TARGET_STORAGE_KEY, href);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* when more than one localized spec is available
|
|
166
|
+
*/
|
|
167
|
+
get hasLocalePicker(): boolean {
|
|
168
|
+
return this.languages.length > 1;
|
|
169
|
+
}
|
|
170
|
+
|
|
100
171
|
/**
|
|
101
|
-
* Whether to show the project header
|
|
172
|
+
* Whether to show the project header. Shown for multi-spec reference
|
|
173
|
+
* sets, and for any docs-content spec topic so it always has a back
|
|
174
|
+
* link.
|
|
102
175
|
*/
|
|
103
176
|
get showRedocHeader(): boolean {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
177
|
+
return (
|
|
178
|
+
(this.isReferenceContentType && this.isMultiSpecSet) ||
|
|
179
|
+
this.isDocContentType
|
|
180
|
+
);
|
|
107
181
|
}
|
|
108
182
|
|
|
109
183
|
/**
|
|
@@ -111,16 +185,68 @@ export default class RedocReference extends LightningElement {
|
|
|
111
185
|
*/
|
|
112
186
|
private onBackClick = (event: Event): void => {
|
|
113
187
|
event.preventDefault();
|
|
188
|
+
|
|
189
|
+
const target = this.getTranslatedBackTarget() ?? this.headerHref;
|
|
190
|
+
|
|
191
|
+
if (target) {
|
|
192
|
+
window.location.assign(target);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
private getTranslatedBackTarget(): string | null {
|
|
197
|
+
const stored = this.getBackTargetFromSession();
|
|
198
|
+
if (stored) {
|
|
199
|
+
return this.language
|
|
200
|
+
? this.translateToCurrentLocale(stored)
|
|
201
|
+
: stored;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const referrer = this.getSameOriginReferrerHref();
|
|
205
|
+
return referrer && !this.isLocaleHref(new URL(referrer).pathname)
|
|
206
|
+
? referrer
|
|
207
|
+
: null;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* The locale segment sits after "docs" for docs pages,
|
|
211
|
+
* and after the product segment for references.
|
|
212
|
+
*/
|
|
213
|
+
private translateToCurrentLocale(storedHref: string): string {
|
|
214
|
+
const url = new URL(storedHref, window.location.origin);
|
|
215
|
+
const localeIds = this.languages.map((loc) => loc.id);
|
|
216
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
217
|
+
|
|
218
|
+
// docs -> right after "docs"; references -> after the product segment.
|
|
219
|
+
const localeIndex = this.isDocContentType ? 1 : 2;
|
|
220
|
+
|
|
221
|
+
if (segments[0] === DOCS_PATH_SEGMENT) {
|
|
222
|
+
// Drop the existing locale segment, if any
|
|
223
|
+
if (localeIds.includes(segments[localeIndex])) {
|
|
224
|
+
segments.splice(localeIndex, 1);
|
|
225
|
+
}
|
|
226
|
+
// Add the current locale
|
|
227
|
+
if (this.language && this.language !== DEFAULT_LOCALE) {
|
|
228
|
+
segments.splice(localeIndex, 0, this.language);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
url.pathname = "/" + segments.join("/");
|
|
233
|
+
return url.href;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Preserves target across locale switches, updates on normal navigation
|
|
237
|
+
private trackBackTarget(): void {
|
|
114
238
|
const referrerHref = this.getSameOriginReferrerHref();
|
|
115
|
-
if (referrerHref) {
|
|
116
|
-
window.location.href = referrerHref;
|
|
239
|
+
if (!referrerHref) {
|
|
117
240
|
return;
|
|
118
241
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
242
|
+
|
|
243
|
+
const referrerUrl = new URL(referrerHref);
|
|
244
|
+
if (this.isLocaleHref(referrerUrl.pathname)) {
|
|
245
|
+
return;
|
|
122
246
|
}
|
|
123
|
-
|
|
247
|
+
|
|
248
|
+
this.setBackTargetInSession(referrerHref);
|
|
249
|
+
}
|
|
124
250
|
|
|
125
251
|
/**
|
|
126
252
|
* Returns the referrer URL when the page was reached via in-tab navigation
|
|
@@ -144,16 +270,16 @@ export default class RedocReference extends LightningElement {
|
|
|
144
270
|
}
|
|
145
271
|
|
|
146
272
|
/**
|
|
147
|
-
*
|
|
148
|
-
* trimming any trailing reference id (and deeper segments). Returns null
|
|
149
|
-
* when the URL doesn't contain a `/references` segment.
|
|
273
|
+
* switching locale on this same page.
|
|
150
274
|
*/
|
|
151
|
-
private
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
275
|
+
private isLocaleHref(pathname: string): boolean {
|
|
276
|
+
return this.languages.some((locale) => {
|
|
277
|
+
const href = locale?.link?.href;
|
|
278
|
+
return (
|
|
279
|
+
!!href &&
|
|
280
|
+
new URL(href, window.location.origin).pathname === pathname
|
|
281
|
+
);
|
|
282
|
+
});
|
|
157
283
|
}
|
|
158
284
|
|
|
159
285
|
/** When origin is provided, pass it to the footer; otherwise use dx-footer's default. */
|
|
@@ -168,6 +294,9 @@ export default class RedocReference extends LightningElement {
|
|
|
168
294
|
// so it reflects real in-tab navigation rather than Redoc's churn.
|
|
169
295
|
this.initialHistoryLength = window.history.length;
|
|
170
296
|
|
|
297
|
+
// Track the back target, preserving it across locale switches
|
|
298
|
+
this.trackBackTarget();
|
|
299
|
+
|
|
171
300
|
window.addEventListener("scroll", this.handleScrollAndResize);
|
|
172
301
|
window.addEventListener("resize", this.handleScrollAndResize);
|
|
173
302
|
}
|
|
@@ -394,7 +523,7 @@ export default class RedocReference extends LightningElement {
|
|
|
394
523
|
this.appendFooterItems(apiContentDiv);
|
|
395
524
|
|
|
396
525
|
// Inject the multi-spec project header into Redoc's left menu only.
|
|
397
|
-
this.
|
|
526
|
+
this.insertSidebarNav(redocContainer);
|
|
398
527
|
|
|
399
528
|
// Wait for footer to be rendered before updating styles
|
|
400
529
|
requestAnimationFrame(() => {
|
|
@@ -409,22 +538,46 @@ export default class RedocReference extends LightningElement {
|
|
|
409
538
|
}
|
|
410
539
|
|
|
411
540
|
/**
|
|
412
|
-
* Inserts the project header
|
|
541
|
+
* Inserts the project header and LNB footer into Redoc.
|
|
413
542
|
*/
|
|
414
|
-
private
|
|
415
|
-
|
|
416
|
-
|
|
543
|
+
private insertSidebarNav(redocContainer: HTMLElement): void {
|
|
544
|
+
// Select the LNB and content area of Redoc and insert the requried header.
|
|
545
|
+
if (this.showRedocHeader) {
|
|
546
|
+
redocContainer
|
|
547
|
+
.querySelectorAll<HTMLElement>(".menu-content, .api-content")
|
|
548
|
+
.forEach((target) => {
|
|
549
|
+
target.insertBefore(
|
|
550
|
+
this.buildProjectHeaderDom(),
|
|
551
|
+
target.firstChild
|
|
552
|
+
);
|
|
553
|
+
});
|
|
417
554
|
}
|
|
418
555
|
|
|
419
|
-
//
|
|
420
|
-
|
|
421
|
-
.
|
|
422
|
-
.
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
556
|
+
// Locale picker
|
|
557
|
+
if (this.hasLocalePicker) {
|
|
558
|
+
const menuContent = redocContainer.querySelector(".menu-content");
|
|
559
|
+
menuContent?.appendChild(this.buildLocalePickerDom());
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Builds the locale picker DOM by reusing `dx-sidebar-footer-nav`
|
|
565
|
+
*/
|
|
566
|
+
private buildLocalePickerDom(): HTMLElement {
|
|
567
|
+
const wrapper = document.createElement("div");
|
|
568
|
+
wrapper.className = "redoc-footer-nav";
|
|
569
|
+
|
|
570
|
+
const picker = createElement("dx-sidebar-footer-nav", {
|
|
571
|
+
is: SidebarFooterNav
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
Object.assign(picker, {
|
|
575
|
+
languages: this.languages,
|
|
576
|
+
language: this.language
|
|
577
|
+
});
|
|
578
|
+
wrapper.appendChild(picker);
|
|
579
|
+
|
|
580
|
+
return wrapper;
|
|
428
581
|
}
|
|
429
582
|
|
|
430
583
|
/**
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.content-type-docs doc-phase {
|
|
6
|
+
--doc-c-phase-top: calc(
|
|
7
|
+
var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
|
|
8
|
+
var(--dx-g-spacing-xl)
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
@media screen and (max-width: 768px) {
|
|
13
|
+
.content-type-docs doc-phase {
|
|
14
|
+
--doc-c-phase-top: calc(
|
|
15
|
+
var(--dx-g-global-header-height) + var(--dx-g-doc-header-height) +
|
|
16
|
+
40px
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<doc-content-layout
|
|
3
|
+
class="content-type content-type-markdown content-type-docs"
|
|
4
|
+
breadcrumbs={breadcrumbs}
|
|
5
|
+
share-title={shareTitle}
|
|
6
|
+
share-twitter-via={twitterVia}
|
|
7
|
+
sidebar-header={sidebarHeader}
|
|
8
|
+
sidebar-value={sidebarValue}
|
|
9
|
+
sidebar-content={sidebarContent}
|
|
10
|
+
toc-title={tocTitle}
|
|
11
|
+
toc-options={tocOptions}
|
|
12
|
+
toc-aria-level={tocAriaLevel}
|
|
13
|
+
enable-slot-change="true"
|
|
14
|
+
languages={languages}
|
|
15
|
+
language={language}
|
|
16
|
+
show-footer={enableFooter}
|
|
17
|
+
show-content-action-toolbar={showContentActionToolbar}
|
|
18
|
+
origin={origin}
|
|
19
|
+
dev-center={devCenter}
|
|
20
|
+
brand={brand}
|
|
21
|
+
>
|
|
22
|
+
<doc-phase
|
|
23
|
+
slot="doc-phase"
|
|
24
|
+
lwc:if={docPhaseInfo}
|
|
25
|
+
doc-phase-info={docPhaseInfo}
|
|
26
|
+
></doc-phase>
|
|
27
|
+
<slot></slot>
|
|
28
|
+
</doc-content-layout>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { toJson } from "dxUtils/normalizers";
|
|
3
|
+
import type { OptionWithLink, TreeNode } from "typings/custom";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Per-topic type emitted by the docs content-type parser
|
|
7
|
+
* (see @salesforcedevs/sfdocs-doc-framework: `TopicTypeEnum`). Only `spec`
|
|
8
|
+
* is meaningful inside this component; everything else renders as a plain
|
|
9
|
+
* markdown-style tile.
|
|
10
|
+
*/
|
|
11
|
+
const TOPIC_TYPE_SPEC = "spec";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Translates per-topic `topicType` into the generic `showForwardArrow` flag
|
|
15
|
+
* that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc).
|
|
16
|
+
*/
|
|
17
|
+
function decorateTopicsWithForwardArrow(
|
|
18
|
+
topics: Array<TreeNode & { topicType?: string }> | undefined
|
|
19
|
+
): TreeNode[] | undefined {
|
|
20
|
+
return topics?.map((topic) => {
|
|
21
|
+
const { topicType, ...decorated } = topic;
|
|
22
|
+
if (topicType === TOPIC_TYPE_SPEC) {
|
|
23
|
+
decorated.showForwardArrow = true;
|
|
24
|
+
}
|
|
25
|
+
if (decorated.children) {
|
|
26
|
+
decorated.children = decorateTopicsWithForwardArrow(
|
|
27
|
+
decorated.children
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return decorated;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Wrapper around `doc-content-layout` for the "docs" content type emitted by
|
|
36
|
+
* the `DocsContentTypeParser`.
|
|
37
|
+
*/
|
|
38
|
+
export default class UnifiedContentLayout extends LightningElement {
|
|
39
|
+
@api breadcrumbs: string | null = null;
|
|
40
|
+
@api sidebarHeader?: string;
|
|
41
|
+
@api sidebarValue?: string;
|
|
42
|
+
@api tocTitle?: string;
|
|
43
|
+
@api tocOptions?: string;
|
|
44
|
+
@api tocAriaLevel?: string;
|
|
45
|
+
@api languages?: OptionWithLink[];
|
|
46
|
+
@api language?: string;
|
|
47
|
+
@api devCenter: any = null;
|
|
48
|
+
@api brand: any = null;
|
|
49
|
+
@api showContentActionToolbar = false;
|
|
50
|
+
|
|
51
|
+
/** Optional origin URL for the footer MFE (e.g. wp-json endpoint). */
|
|
52
|
+
@api origin: string | null = null;
|
|
53
|
+
|
|
54
|
+
/** Article name from breadcrumbs, used as share title (e.g. for social share). */
|
|
55
|
+
@api shareTitle: string | null = null;
|
|
56
|
+
|
|
57
|
+
/** Optional Twitter "via" handle (e.g. SalesforceDevs) for social share. */
|
|
58
|
+
@api twitterVia: string | null = null;
|
|
59
|
+
|
|
60
|
+
@api hideFooter = false;
|
|
61
|
+
|
|
62
|
+
private _docPhaseInfo: string | null = null;
|
|
63
|
+
private _sidebarContent: unknown = null;
|
|
64
|
+
|
|
65
|
+
@api
|
|
66
|
+
get docPhaseInfo(): string | null {
|
|
67
|
+
return this._docPhaseInfo;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
set docPhaseInfo(value: string | null) {
|
|
71
|
+
this._docPhaseInfo = value || null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@api
|
|
75
|
+
get sidebarContent(): unknown {
|
|
76
|
+
return this._sidebarContent;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
set sidebarContent(value: string) {
|
|
80
|
+
this._sidebarContent = decorateTopicsWithForwardArrow(
|
|
81
|
+
toJson(value)?.topics
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private get enableFooter(): boolean {
|
|
86
|
+
return !this.hideFooter;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// The ONLY place a /api/search URL is built, and the ONLY place the HTTP
|
|
3
3
|
// contract lives. No LWC / arch / dx imports — browser DOM APIs only.
|
|
4
4
|
|
|
5
|
+
/** Where a result's `snippet` came from (mirrors the backend contract). */
|
|
6
|
+
export type SnippetSource = "headline" | "description" | "none";
|
|
7
|
+
|
|
5
8
|
export interface SearchResult {
|
|
6
9
|
url: string;
|
|
7
10
|
title: string;
|
|
@@ -14,6 +17,12 @@ export interface SearchResult {
|
|
|
14
17
|
lexScore: number;
|
|
15
18
|
semScore: number;
|
|
16
19
|
matchType: string;
|
|
20
|
+
// Contextual highlighted passage (P4.5). Always XSS-safe HTML from the
|
|
21
|
+
// backend, but only display-correct as HTML when snippetSource is
|
|
22
|
+
// "headline" (see highlightedSnippetHtml). Optional so pre-P4.5 backends
|
|
23
|
+
// and existing fixtures still satisfy the type.
|
|
24
|
+
snippet?: string | null;
|
|
25
|
+
snippetSource?: SnippetSource;
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
export interface FacetBucket {
|
|
@@ -158,3 +167,54 @@ export function decodeHtmlEntities(value: unknown): string {
|
|
|
158
167
|
const doc = new DOMParser().parseFromString(value, "text/html");
|
|
159
168
|
return doc.documentElement.textContent ?? "";
|
|
160
169
|
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Defense-in-depth sanitizer for a backend `snippet` (P4.5). The backend
|
|
173
|
+
* already emits XSS-safe HTML whose ONLY tags are the `<b>`/`</b>` it wrapped
|
|
174
|
+
* around matched terms (escape-then-mark via PUA sentinels), so this is a
|
|
175
|
+
* belt-and-braces second gate on the client: strip every tag except `<b>` and
|
|
176
|
+
* `</b>`. A malformed backend, a proxy that rewrites bodies, or a future
|
|
177
|
+
* contract drift can't inject anything else. Text between the bold tags is
|
|
178
|
+
* left byte-for-byte (it is already entity-escaped by the backend, so literal
|
|
179
|
+
* `<`/`>`/`&` in prose arrive as `<`/`>`/`&` and stay inert).
|
|
180
|
+
*/
|
|
181
|
+
export function sanitizeSnippetHtml(value: unknown): string {
|
|
182
|
+
// Strip every tag except a BARE <b> or </b> (case-insensitive). The backend
|
|
183
|
+
// only ever emits attribute-less bold tags, so requiring the `>` right after
|
|
184
|
+
// `b` also drops an attribute-bearing `<b onmouseover=…>` — the tightest
|
|
185
|
+
// possible allowlist. Text between tags is left as-is (already escaped).
|
|
186
|
+
//
|
|
187
|
+
// The trailing `(?:>|$)` also consumes an UNTERMINATED tag that runs to the
|
|
188
|
+
// end of the string (e.g. `…<img src=x onerror=alert(1)` with no closing
|
|
189
|
+
// `>`). A plain `…>` alternative would leave that fragment as literal text;
|
|
190
|
+
// today's sole sink (innerHTML at end-of-fragment) happens to drop such a
|
|
191
|
+
// tag, but this helper is exported and must honor its own contract without
|
|
192
|
+
// leaning on the parser's incidental EOF behavior.
|
|
193
|
+
return String(value ?? "").replace(/<(?!\/?b>)[^>]*(?:>|$)/gi, "");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* The HTML to render for a result's highlighted snippet, or `null` when the
|
|
198
|
+
* caller should fall back to the plain-text description path.
|
|
199
|
+
*
|
|
200
|
+
* Only `snippetSource === "headline"` yields HTML: that branch is
|
|
201
|
+
* `markHtml(headline)` over `chunk_text`, which the backend already DECODED
|
|
202
|
+
* (entities resolved, markup stripped) and then escaped, so it renders
|
|
203
|
+
* display-correct as HTML. The `"description"` branch, by contrast, is
|
|
204
|
+
* `escapeHtml(rawDescription)` where the raw description is still
|
|
205
|
+
* entity-ENCODED frontmatter (verified on the live corpus: descriptions carry
|
|
206
|
+
* `"` etc.) — rendering that as HTML would double-escape and show literal
|
|
207
|
+
* entities, a regression vs. the existing `decodeHtmlEntities(description)`
|
|
208
|
+
* text path. So for anything but a headline we return `null` and let the
|
|
209
|
+
* caller keep today's text rendering.
|
|
210
|
+
*/
|
|
211
|
+
export function highlightedSnippetHtml(result: SearchResult): string | null {
|
|
212
|
+
if (result.snippetSource !== "headline") {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const snippet = result.snippet;
|
|
216
|
+
if (typeof snippet !== "string" || snippet === "") {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
return sanitizeSnippetHtml(snippet);
|
|
220
|
+
}
|
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.
|