@salesforcedevs/dx-components 1.28.7-alpha.11 → 1.28.7-alpha.13
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 -1
- package/package.json +2 -2
- package/src/modules/dx/searchResults/searchResults.ts +5 -5
- package/src/modules/dx/sidebarSearch/sidebarSearch.ts +38 -12
- package/src/modules/dx/sidebarSearchResult/sidebarSearchResult.css +2 -0
- package/src/modules/dxUtils/{dataCloudSearch/dataCloudSearch.ts → data360Search/data360Search.ts} +12 -12
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "1.28.7-alpha.
|
|
3
|
+
"version": "1.28.7-alpha.13",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"luxon": "3.4.4",
|
|
45
45
|
"msw": "^2.12.4"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "30013174e0eb18a3bc89e854eaf505dc33d1089b"
|
|
48
48
|
}
|
|
@@ -2,10 +2,10 @@ import { LightningElement, api, track } from "lwc";
|
|
|
2
2
|
import debounce from "debounce";
|
|
3
3
|
import { track as trackGTM } from "dxUtils/analytics";
|
|
4
4
|
import {
|
|
5
|
-
type
|
|
5
|
+
type Data360SearchResultItem,
|
|
6
6
|
fetchSearch,
|
|
7
7
|
getQueryFromUrl
|
|
8
|
-
} from "dxUtils/
|
|
8
|
+
} from "dxUtils/data360Search";
|
|
9
9
|
|
|
10
10
|
const SEARCH_DEBOUNCE_DELAY = 400;
|
|
11
11
|
|
|
@@ -99,12 +99,12 @@ export default class SearchResults extends LightningElement {
|
|
|
99
99
|
try {
|
|
100
100
|
const raw = await fetchSearch(query);
|
|
101
101
|
this.results = raw.map(
|
|
102
|
-
(item:
|
|
102
|
+
(item: Data360SearchResultItem, index: number) =>
|
|
103
103
|
this.normalizeResult(item, index)
|
|
104
104
|
);
|
|
105
105
|
this.trackSearchResultsOnce(query, this.results.length);
|
|
106
106
|
} catch (err) {
|
|
107
|
-
console.error("Data
|
|
107
|
+
console.error("Data 360 Search request failed", err);
|
|
108
108
|
this.results = [];
|
|
109
109
|
} finally {
|
|
110
110
|
this.isLoading = false;
|
|
@@ -116,7 +116,7 @@ export default class SearchResults extends LightningElement {
|
|
|
116
116
|
}, SEARCH_DEBOUNCE_DELAY);
|
|
117
117
|
|
|
118
118
|
private normalizeResult(
|
|
119
|
-
item:
|
|
119
|
+
item: Data360SearchResultItem,
|
|
120
120
|
index: number
|
|
121
121
|
): SearchResultDisplay {
|
|
122
122
|
const href = item.url ?? "";
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { LightningElement, api } from "lwc";
|
|
2
2
|
import debounce from "debounce";
|
|
3
3
|
import {
|
|
4
|
-
type
|
|
4
|
+
type Data360SearchResultItem,
|
|
5
5
|
fetchSearch
|
|
6
|
-
} from "dxUtils/
|
|
6
|
+
} from "dxUtils/data360Search";
|
|
7
|
+
import { createSearchRegExp } from "dxUtils/regexps";
|
|
7
8
|
import { RecentSearches } from "dxUtils/recentSearches";
|
|
8
9
|
import {
|
|
10
|
+
type HighlightedSections,
|
|
9
11
|
Option,
|
|
10
12
|
PopoverRequestCloseType,
|
|
11
13
|
SidebarSearchResult
|
|
@@ -13,6 +15,27 @@ import {
|
|
|
13
15
|
|
|
14
16
|
const SEARCH_DEBOUNCE_DELAY = 1200;
|
|
15
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Find all matches of the search query in text and return ranges for highlighting.
|
|
20
|
+
* Uses the same regex as the full-doc highlighter (createSearchRegExp) so sidebar
|
|
21
|
+
* and doc highlight the same phrases (including spaces between words).
|
|
22
|
+
*/
|
|
23
|
+
function getHighlightRanges(
|
|
24
|
+
text: string,
|
|
25
|
+
searchQuery: string
|
|
26
|
+
): HighlightedSections {
|
|
27
|
+
if (!text || !searchQuery.trim()) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const re = createSearchRegExp(searchQuery.trim());
|
|
31
|
+
const ranges: HighlightedSections = [];
|
|
32
|
+
let match: RegExpExecArray | null;
|
|
33
|
+
while ((match = re.exec(text)) !== null) {
|
|
34
|
+
ranges.push({ offset: match.index, length: match[0].length });
|
|
35
|
+
}
|
|
36
|
+
return ranges;
|
|
37
|
+
}
|
|
38
|
+
|
|
16
39
|
const UserRecentSearches = new RecentSearches();
|
|
17
40
|
|
|
18
41
|
const getSearchQueryParam = (): string =>
|
|
@@ -21,7 +44,7 @@ const getSearchQueryParam = (): string =>
|
|
|
21
44
|
export default class SidebarSearch extends LightningElement {
|
|
22
45
|
@api
|
|
23
46
|
public fetchMoreResults() {
|
|
24
|
-
// Data
|
|
47
|
+
// Data 360 Search API does not expose pagination in the same way; no-op
|
|
25
48
|
}
|
|
26
49
|
|
|
27
50
|
@api
|
|
@@ -41,7 +64,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
41
64
|
private recentSearches: Option[] = [];
|
|
42
65
|
private value: string = "";
|
|
43
66
|
private didRender = false;
|
|
44
|
-
private
|
|
67
|
+
private data360SearchInitialized: boolean = false;
|
|
45
68
|
|
|
46
69
|
private get isDropdownOpen() {
|
|
47
70
|
return (
|
|
@@ -58,8 +81,8 @@ export default class SidebarSearch extends LightningElement {
|
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
renderedCallback() {
|
|
61
|
-
if (!this.
|
|
62
|
-
this.
|
|
84
|
+
if (!this.data360SearchInitialized) {
|
|
85
|
+
this.data360SearchInitialized = true;
|
|
63
86
|
if (this.value) {
|
|
64
87
|
// Page load with ?q= in URL: run search so results and loading state resolve
|
|
65
88
|
if (!this.didRender) {
|
|
@@ -78,7 +101,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
78
101
|
}
|
|
79
102
|
|
|
80
103
|
private normalizeDataCloudResult = (
|
|
81
|
-
item:
|
|
104
|
+
item: Data360SearchResultItem,
|
|
82
105
|
index: number
|
|
83
106
|
): SidebarSearchResult => {
|
|
84
107
|
const href = item.url ?? "";
|
|
@@ -87,11 +110,14 @@ export default class SidebarSearch extends LightningElement {
|
|
|
87
110
|
: href;
|
|
88
111
|
const isSelected =
|
|
89
112
|
!!resultPath && resultPath === window.location.pathname;
|
|
113
|
+
const title = item.title ?? "";
|
|
114
|
+
const excerpt = item.matchedText ?? "";
|
|
115
|
+
const searchQuery = this.value.trim();
|
|
90
116
|
return {
|
|
91
|
-
title
|
|
92
|
-
titleHighlights:
|
|
93
|
-
excerpt
|
|
94
|
-
excerptHighlights:
|
|
117
|
+
title,
|
|
118
|
+
titleHighlights: getHighlightRanges(title, searchQuery),
|
|
119
|
+
excerpt,
|
|
120
|
+
excerptHighlights: getHighlightRanges(excerpt, searchQuery),
|
|
95
121
|
uniqueId: href || `result-${index}`,
|
|
96
122
|
href,
|
|
97
123
|
selected: isSelected,
|
|
@@ -107,7 +133,7 @@ export default class SidebarSearch extends LightningElement {
|
|
|
107
133
|
);
|
|
108
134
|
this.dispatchChange(results);
|
|
109
135
|
} catch (err) {
|
|
110
|
-
console.error("Data
|
|
136
|
+
console.error("Data 360 Search request failed", err);
|
|
111
137
|
this.dispatchChange([]);
|
|
112
138
|
} finally {
|
|
113
139
|
this.dispatchOnLoading(false);
|
package/src/modules/dxUtils/{dataCloudSearch/dataCloudSearch.ts → data360Search/data360Search.ts}
RENAMED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Data
|
|
2
|
+
* Data 360 search API – shared endpoints and helpers for sidebar search,
|
|
3
3
|
* search results page, and has-results check.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
8
|
-
export const
|
|
6
|
+
export const DATA_360_SEARCH_PATH = "/data-360-search/search";
|
|
7
|
+
export const DATA_360_HAS_RESULTS_PATH = "/data-360-search/has-results";
|
|
8
|
+
export const DATA_360_SEARCH_ORIGIN = "https://developer.salesforce.com";
|
|
9
9
|
|
|
10
|
-
/** Data
|
|
11
|
-
export interface
|
|
10
|
+
/** Data 360 Search API result item (title, url, matchedText) */
|
|
11
|
+
export interface Data360SearchResultItem {
|
|
12
12
|
title?: string;
|
|
13
13
|
url?: string;
|
|
14
14
|
matchedText?: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function getBaseUrlPath(): string {
|
|
18
|
-
const url =
|
|
18
|
+
const url = DATA_360_SEARCH_ORIGIN + window.location.pathname;
|
|
19
19
|
const lastSlash = url.lastIndexOf("/");
|
|
20
20
|
return lastSlash > 0 ? url.substring(0, lastSlash) : url;
|
|
21
21
|
}
|
|
@@ -53,11 +53,11 @@ export function getQueryFromUrl(): string {
|
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
55
|
* Quick check if the current page has searchable results.
|
|
56
|
-
* Only when this returns true should the Data
|
|
56
|
+
* Only when this returns true should the Data 360 sidebar be shown.
|
|
57
57
|
*/
|
|
58
58
|
export async function fetchHasResults(): Promise<boolean> {
|
|
59
59
|
try {
|
|
60
|
-
const res = await fetch(
|
|
60
|
+
const res = await fetch(DATA_360_HAS_RESULTS_PATH, {
|
|
61
61
|
method: "POST",
|
|
62
62
|
headers: { "Content-Type": "application/json" },
|
|
63
63
|
body: JSON.stringify({ baseUrlPath: getBaseUrlPath() })
|
|
@@ -73,16 +73,16 @@ export async function fetchHasResults(): Promise<boolean> {
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
|
-
* Run a Data
|
|
76
|
+
* Run a Data 360 search. Returns the raw result items; callers normalize for UI.
|
|
77
77
|
*/
|
|
78
78
|
export async function fetchSearch(
|
|
79
79
|
searchQuery: string
|
|
80
|
-
): Promise<
|
|
80
|
+
): Promise<Data360SearchResultItem[]> {
|
|
81
81
|
const query = searchQuery.trim();
|
|
82
82
|
if (!query) {
|
|
83
83
|
return [];
|
|
84
84
|
}
|
|
85
|
-
const res = await fetch(
|
|
85
|
+
const res = await fetch(DATA_360_SEARCH_PATH, {
|
|
86
86
|
method: "POST",
|
|
87
87
|
headers: { "Content-Type": "application/json" },
|
|
88
88
|
body: JSON.stringify({
|