@salesforcedevs/dx-components 0.18.10 → 0.19.3-alpha.10
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/package.json +2 -3
- package/src/.DS_Store +0 -0
- package/src/modules/.DS_Store +0 -0
- package/src/modules/dx/.DS_Store +0 -0
- package/src/modules/dx/header/__tests__/mockProps.ts +4 -10
- package/src/modules/dx/headerSearch/headerSearch.html +0 -1
- package/src/modules/dx/headerSearch/headerSearch.ts +23 -19
- package/src/modules/dx/sidebarSearch/sidebarSearch.ts +7 -7
- package/src/modules/dx/sidebarSearchResult/__tests__/sidebarSearchResult.test.ts +47 -6
- package/src/modules/dx/sidebarSearchResult/sidebarSearchResult.ts +18 -4
- package/src/modules/utils/coveo/coveo.ts +4 -3
- package/src/modules/utils/highlight/highlight.ts +8 -0
- package/LICENSE +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.3-alpha.10",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -28,6 +28,5 @@
|
|
|
28
28
|
"@types/classnames": "^2.2.10",
|
|
29
29
|
"@types/debounce": "^1.2.0",
|
|
30
30
|
"@types/lodash.get": "^4.4.6"
|
|
31
|
-
}
|
|
32
|
-
"gitHead": "f29684780634b9abec6ead2e47fe7bda05e31412"
|
|
31
|
+
}
|
|
33
32
|
}
|
package/src/.DS_Store
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -13,13 +13,7 @@ import {
|
|
|
13
13
|
mockNavAnalytics
|
|
14
14
|
} from "./mockNavs";
|
|
15
15
|
import mockNavDevelopers from "./mockNavDevelopers";
|
|
16
|
-
|
|
17
|
-
export const coveoConfig = {
|
|
18
|
-
coveoOrganizationId: "coveosalesforcetestakshatha",
|
|
19
|
-
coveoPublicAccessToken: "xx114e9d50-bc6b-40f1-b25b-fa5a06c7e168",
|
|
20
|
-
coveoSearchPipeline: "salesforcedevdoc",
|
|
21
|
-
coveoSearchHub: "salesforcedevdoc2"
|
|
22
|
-
};
|
|
16
|
+
import { coveoHeaderConfig } from "../../../utils/coveo/coveo";
|
|
23
17
|
|
|
24
18
|
const versions = JSON.stringify([
|
|
25
19
|
{
|
|
@@ -44,18 +38,18 @@ export const mockPropsDevelopers = {
|
|
|
44
38
|
navItems: JSON.stringify(mockNavDevelopers),
|
|
45
39
|
subtitle: "Developers",
|
|
46
40
|
signupLink: "/sign-up",
|
|
47
|
-
...
|
|
41
|
+
...coveoHeaderConfig
|
|
48
42
|
};
|
|
49
43
|
|
|
50
44
|
export const mockPropsNoNavigation = {
|
|
51
45
|
subtitle: "Developers",
|
|
52
|
-
...
|
|
46
|
+
...coveoHeaderConfig
|
|
53
47
|
};
|
|
54
48
|
|
|
55
49
|
export const mockPropsDevWebsite = {
|
|
56
50
|
version: "1",
|
|
57
51
|
versions,
|
|
58
|
-
...
|
|
52
|
+
...coveoHeaderConfig,
|
|
59
53
|
signupLink: "/sign-up",
|
|
60
54
|
bannerMarkup:
|
|
61
55
|
'<span><a href="https://forms.gle/TdSyKFPHXoBx7seM9" target="blank">Share your feedback</a>about our new site.</span>'
|
|
@@ -77,25 +77,29 @@ export default class HeaderSearch extends LightningElement {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
private instantiateSearchbox() {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
80
|
+
try {
|
|
81
|
+
const options: StandaloneSearchBoxOptions = {
|
|
82
|
+
numberOfSuggestions: 3,
|
|
83
|
+
redirectionUrl: "https://developer.salesforce.com"
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const engine = buildSearchEngine({
|
|
87
|
+
organizationId: this.coveoOrganizationId,
|
|
88
|
+
publicAccessToken: this.coveoPublicAccessToken,
|
|
89
|
+
searchPipeline: this.coveoSearchPipeline,
|
|
90
|
+
searchHub: this.coveoSearchHub
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
this.searchBox = buildStandaloneSearchBox(engine, { options });
|
|
94
|
+
|
|
95
|
+
this.searchBox?.subscribe(() => {
|
|
96
|
+
if (this.searchBox) {
|
|
97
|
+
this.searchState = this.searchBox.state;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
} catch (e) {
|
|
101
|
+
console.error(`Coveo searchbox failed to initialize (${e})`);
|
|
102
|
+
}
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
private createSearchHref = (value: string | null = "") => {
|
|
@@ -27,6 +27,7 @@ export const SESSION_KEY = "dx-sidebar-search-state";
|
|
|
27
27
|
|
|
28
28
|
const DEFAULT_RESULT_COUNT = 20;
|
|
29
29
|
const SEARCH_DEBOUNCE_DELAY = 780;
|
|
30
|
+
const HIGHLIGHT_DEBOUNCE_DELAY = 200;
|
|
30
31
|
|
|
31
32
|
const UserRecentSearches = new RecentSearches();
|
|
32
33
|
|
|
@@ -217,10 +218,6 @@ export default class SidebarSearch extends LightningElement {
|
|
|
217
218
|
this.onResultListChange
|
|
218
219
|
);
|
|
219
220
|
|
|
220
|
-
if (this.value) {
|
|
221
|
-
this.dispatchHighlightedTermChange();
|
|
222
|
-
}
|
|
223
|
-
|
|
224
221
|
if (!this.preloadedState) {
|
|
225
222
|
if (this.value) {
|
|
226
223
|
this.submitSearch();
|
|
@@ -291,7 +288,10 @@ export default class SidebarSearch extends LightningElement {
|
|
|
291
288
|
} else {
|
|
292
289
|
const isNestedGuide = clickUri.includes("/guide/");
|
|
293
290
|
const url = new URL(clickUri);
|
|
294
|
-
const extension =
|
|
291
|
+
const extension =
|
|
292
|
+
isNestedGuide && !url.pathname?.endsWith(".html")
|
|
293
|
+
? ".html"
|
|
294
|
+
: "";
|
|
295
295
|
pathname = `${url.pathname}${extension}`;
|
|
296
296
|
}
|
|
297
297
|
|
|
@@ -334,7 +334,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
334
334
|
this.dispatchEvent(new CustomEvent("loading", { detail: loading }));
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
private dispatchHighlightedTermChange() {
|
|
337
|
+
private dispatchHighlightedTermChange = debounce(() => {
|
|
338
338
|
this.dispatchEvent(
|
|
339
339
|
new CustomEvent("highlightedtermchange", {
|
|
340
340
|
detail: this.value,
|
|
@@ -342,7 +342,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
342
342
|
bubbles: true
|
|
343
343
|
})
|
|
344
344
|
);
|
|
345
|
-
}
|
|
345
|
+
}, HIGHLIGHT_DEBOUNCE_DELAY);
|
|
346
346
|
|
|
347
347
|
private updateRecentSearches = () =>
|
|
348
348
|
(this.recentSearches = UserRecentSearches.get().map((item: string) => ({
|
|
@@ -4,7 +4,7 @@ import { createRenderComponent } from "utils/tests";
|
|
|
4
4
|
const TAG = "dx-sidebar-search-result";
|
|
5
5
|
const render = createRenderComponent(TAG, SidebarSearchResult);
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const MOCK_RESULT = {
|
|
8
8
|
description: "test description here",
|
|
9
9
|
descriptionHighlights: [{ length: 5, offset: 5 }],
|
|
10
10
|
href: "/test",
|
|
@@ -13,24 +13,65 @@ const PROPS = {
|
|
|
13
13
|
titleHighlights: [{ length: 5, offset: 5 }]
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
+
const MOCK_RESULT_2 = {
|
|
17
|
+
description:
|
|
18
|
+
"Auth.MyDomainLoginDiscoveryHandler to show a custom error message on the My Domain login page ... Auth.LoginDiscoveryHandler to show an error message on the Experience Cloud site login page",
|
|
19
|
+
descriptionHighlights: [
|
|
20
|
+
{ length: 4, offset: 0 },
|
|
21
|
+
{ length: 4, offset: 98 }
|
|
22
|
+
],
|
|
23
|
+
href: "/test",
|
|
24
|
+
selected: false,
|
|
25
|
+
title: "Auth Exceptions | Apex Reference Guide | Salesforce Developers",
|
|
26
|
+
titleHighlights: [{ length: 4, offset: 0 }]
|
|
27
|
+
};
|
|
28
|
+
|
|
16
29
|
describe(TAG, () => {
|
|
17
30
|
it("renders a result with the correct highlighted content", () => {
|
|
18
|
-
const element = render(
|
|
31
|
+
const element = render(MOCK_RESULT);
|
|
19
32
|
|
|
33
|
+
const title = element.shadowRoot.querySelector(".title");
|
|
20
34
|
const titleBolds = element.shadowRoot.querySelectorAll(".title .bold");
|
|
21
|
-
expect(
|
|
35
|
+
expect(title.textContent).toEqual(MOCK_RESULT.title);
|
|
36
|
+
expect(titleBolds.length).toEqual(MOCK_RESULT.titleHighlights.length);
|
|
22
37
|
expect(titleBolds[0].textContent).toEqual("title");
|
|
23
38
|
|
|
39
|
+
const description = element.shadowRoot.querySelector(".description");
|
|
24
40
|
const descriptionBolds =
|
|
25
41
|
element.shadowRoot.querySelectorAll(".description .bold");
|
|
26
|
-
expect(
|
|
42
|
+
expect(description.textContent).toEqual(MOCK_RESULT.description);
|
|
43
|
+
expect(descriptionBolds.length).toEqual(
|
|
44
|
+
MOCK_RESULT.descriptionHighlights.length
|
|
45
|
+
);
|
|
27
46
|
expect(descriptionBolds[0].textContent).toEqual("descr");
|
|
28
47
|
|
|
29
48
|
return expect(element).toBeAccessible();
|
|
30
49
|
});
|
|
31
50
|
|
|
51
|
+
it("renders another result variant with the correct highlighted content", () => {
|
|
52
|
+
const element = render(MOCK_RESULT_2);
|
|
53
|
+
|
|
54
|
+
const title = element.shadowRoot.querySelector(".title");
|
|
55
|
+
const titleBolds = element.shadowRoot.querySelectorAll(".title .bold");
|
|
56
|
+
expect(title.textContent).toEqual(MOCK_RESULT_2.title);
|
|
57
|
+
expect(titleBolds.length).toEqual(MOCK_RESULT_2.titleHighlights.length);
|
|
58
|
+
expect(titleBolds[0].textContent).toEqual("Auth");
|
|
59
|
+
|
|
60
|
+
const description = element.shadowRoot.querySelector(".description");
|
|
61
|
+
const descriptionBolds =
|
|
62
|
+
element.shadowRoot.querySelectorAll(".description .bold");
|
|
63
|
+
expect(description.textContent).toEqual(MOCK_RESULT_2.description);
|
|
64
|
+
expect(descriptionBolds.length).toEqual(
|
|
65
|
+
MOCK_RESULT_2.descriptionHighlights.length
|
|
66
|
+
);
|
|
67
|
+
expect(descriptionBolds[0].textContent).toEqual("Auth");
|
|
68
|
+
expect(descriptionBolds[1].textContent).toEqual("Auth");
|
|
69
|
+
|
|
70
|
+
return expect(element).toBeAccessible();
|
|
71
|
+
});
|
|
72
|
+
|
|
32
73
|
it("renders a result as selected when specified", () => {
|
|
33
|
-
const element = render({ ...
|
|
74
|
+
const element = render({ ...MOCK_RESULT, selected: true });
|
|
34
75
|
|
|
35
76
|
const selected = element.shadowRoot.querySelector(
|
|
36
77
|
".sidebar-item-selected"
|
|
@@ -42,7 +83,7 @@ describe(TAG, () => {
|
|
|
42
83
|
|
|
43
84
|
it("doesn't add bold class when there is no highlighted term", () => {
|
|
44
85
|
const element = render({
|
|
45
|
-
...
|
|
86
|
+
...MOCK_RESULT,
|
|
46
87
|
descriptionHighlights: [],
|
|
47
88
|
titleHighlights: []
|
|
48
89
|
});
|
|
@@ -13,7 +13,7 @@ const toChunks = (value: string, highlights: CoveoHighlights) => {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
let endIndex = 0;
|
|
16
|
-
return highlights.reduce((acc, { length, offset }) => {
|
|
16
|
+
return highlights.reduce((acc, { length, offset }, i) => {
|
|
17
17
|
const plainValue = value.slice(endIndex, offset);
|
|
18
18
|
const plainChunk = {
|
|
19
19
|
value: plainValue,
|
|
@@ -28,9 +28,23 @@ const toChunks = (value: string, highlights: CoveoHighlights) => {
|
|
|
28
28
|
id: offset
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
let chunks =
|
|
32
|
+
plainValue.length > 0
|
|
33
|
+
? [...acc, plainChunk, boldChunk]
|
|
34
|
+
: [...acc, boldChunk];
|
|
35
|
+
|
|
36
|
+
const remaining = value.slice(endIndex);
|
|
37
|
+
if (remaining.length > 0 && highlights.length - 1 === i) {
|
|
38
|
+
chunks = [
|
|
39
|
+
...chunks,
|
|
40
|
+
{
|
|
41
|
+
value: remaining,
|
|
42
|
+
id: value.length
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return chunks;
|
|
34
48
|
}, []);
|
|
35
49
|
};
|
|
36
50
|
|
|
@@ -38,17 +38,18 @@ export const getSidebarSearchParams = () =>
|
|
|
38
38
|
new URLSearchParams(window.location.search).get("q");
|
|
39
39
|
|
|
40
40
|
const coveoOrganizationId = "coveosalesforcetestakshatha";
|
|
41
|
+
const coveoPublicAccessToken = "xxfeb39525-e402-4e41-a870-7132441f7875";
|
|
41
42
|
|
|
42
43
|
export const coveoHeaderConfig = {
|
|
43
44
|
coveoOrganizationId,
|
|
44
|
-
coveoPublicAccessToken
|
|
45
|
+
coveoPublicAccessToken,
|
|
45
46
|
coveoSearchPipeline: "salesforcedevdoc",
|
|
46
47
|
coveoSearchHub: "salesforcedevdoc"
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
export const coveoXMLDocsConfig = {
|
|
50
51
|
coveoOrganizationId,
|
|
51
|
-
coveoPublicAccessToken
|
|
52
|
+
coveoPublicAccessToken,
|
|
52
53
|
coveoSearchHub: "Developer_Docs_SS",
|
|
53
54
|
coveoAdvancedQueryConfig: JSON.stringify({
|
|
54
55
|
objecttype: "HTDeveloperDocumentsC",
|
|
@@ -60,7 +61,7 @@ export const coveoXMLDocsConfig = {
|
|
|
60
61
|
|
|
61
62
|
export const coveoSFDocsConfig = {
|
|
62
63
|
coveoOrganizationId,
|
|
63
|
-
coveoPublicAccessToken
|
|
64
|
+
coveoPublicAccessToken,
|
|
64
65
|
coveoSearchHub: "Developer_MdDocs_SS",
|
|
65
66
|
coveoAdvancedQueryConfig: JSON.stringify({
|
|
66
67
|
source: "Sitemap - Developer Docs",
|
|
@@ -9,6 +9,7 @@ export const highlightTerms = (
|
|
|
9
9
|
): void => {
|
|
10
10
|
searchTerm = searchTerm.trim();
|
|
11
11
|
const searchExp = createSearchRegExp(searchTerm);
|
|
12
|
+
let scrolled = false;
|
|
12
13
|
elements.forEach((element) => {
|
|
13
14
|
if (
|
|
14
15
|
element?.innerHTML.includes("<dx-") ||
|
|
@@ -27,6 +28,13 @@ export const highlightTerms = (
|
|
|
27
28
|
innerHtml = innerHtml.replace(searchExp, "<mark>$&</mark>");
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
const mark = element.querySelector("mark");
|
|
32
|
+
|
|
33
|
+
if (mark && !scrolled) {
|
|
34
|
+
scrolled = true;
|
|
35
|
+
element.scrollIntoView({ block: "nearest" });
|
|
36
|
+
}
|
|
37
|
+
|
|
30
38
|
element.innerHTML = innerHtml;
|
|
31
39
|
});
|
|
32
40
|
};
|
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.
|