@salesforcedevs/dx-components 0.19.3-alpha.47 → 0.19.3-alpha.50

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.19.3-alpha.47",
3
+ "version": "0.19.3-alpha.50",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -122,7 +122,10 @@ export default class Sidebar extends LightningElement {
122
122
  this.assignFilteredTrees();
123
123
  this.dispatchEvent(
124
124
  new CustomEvent("highlightedtermchange", {
125
- detail: this.searchText,
125
+ detail: {
126
+ query: this.searchText,
127
+ termsToHighlight: [this.searchText]
128
+ },
126
129
  composed: true,
127
130
  bubbles: true
128
131
  })
@@ -89,6 +89,25 @@ export default class SidebarSearch extends LightningElement {
89
89
  private fetchingMoreResults: boolean = false;
90
90
  private didRender = false;
91
91
 
92
+ private get termsToHighlight(): string[] | null {
93
+ const { termsToHighlight, phrasesToHighlight } =
94
+ this.engine?.state?.search?.response;
95
+ if (!termsToHighlight || !phrasesToHighlight) {
96
+ return null;
97
+ }
98
+ return Array.from(
99
+ new Set(
100
+ [
101
+ this.value,
102
+ Object.keys(termsToHighlight),
103
+ Object.keys(phrasesToHighlight),
104
+ Object.values(termsToHighlight),
105
+ Object.values(phrasesToHighlight)
106
+ ].flat(2)
107
+ )
108
+ ) as string[];
109
+ }
110
+
92
111
  private get hasCorrectCoveoConfig(): boolean {
93
112
  const coveoConfigurations = [
94
113
  this.coveoOrganizationId,
@@ -330,32 +349,19 @@ export default class SidebarSearch extends LightningElement {
330
349
  }
331
350
 
332
351
  private dispatchHighlightedTermChange = () => {
333
- const { termsToHighlight, phrasesToHighlight } =
334
- this.engine?.state?.search?.response;
335
- if (!termsToHighlight || !phrasesToHighlight) {
336
- return;
352
+ if (this.termsToHighlight) {
353
+ console.log('dispatching terms to highlight')
354
+ this.dispatchEvent(
355
+ new CustomEvent("highlightedtermchange", {
356
+ detail: {
357
+ query: this.value,
358
+ termsToHighlight: this.termsToHighlight
359
+ },
360
+ composed: true,
361
+ bubbles: true
362
+ })
363
+ );
337
364
  }
338
- const normalizedTermsToHighlight = Array.from(
339
- new Set(
340
- [
341
- this.value,
342
- Object.keys(termsToHighlight),
343
- Object.keys(phrasesToHighlight),
344
- Object.values(termsToHighlight),
345
- Object.values(phrasesToHighlight)
346
- ].flat(2)
347
- )
348
- );
349
- this.dispatchEvent(
350
- new CustomEvent("highlightedtermchange", {
351
- detail: {
352
- query: this.value,
353
- termsToHighlight: normalizedTermsToHighlight
354
- },
355
- composed: true,
356
- bubbles: true
357
- })
358
- );
359
365
  };
360
366
 
361
367
  private updateRecentSearches = () =>
@@ -23,15 +23,9 @@ export const highlightTerms = (
23
23
  try {
24
24
  if (element.innerHTML.match(MARK_TAGS)) {
25
25
  // Remove previously added mark tags
26
- console.log(
27
- "matching marks",
28
- element,
29
- element.style.backgroundColor
30
- );
31
26
  element.innerHTML = element.innerHTML.replace(MARK_TAGS, "");
32
27
  }
33
28
  if (element.innerHTML.match(searchExp) && query) {
34
- console.log("matching", element, element.innerHTML);
35
29
  element.innerHTML = element.innerHTML.replace(
36
30
  searchExp,
37
31
  '<mark style="background-color:var(--dx-g-yellow-vibrant-90)">$&</mark>'