@salesforcedevs/dx-components 1.35.2 → 1.36.0

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": "1.35.2",
3
+ "version": "1.36.0",
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": "32674746e426242b35fb5a5a28c4184431092ac3"
47
+ "gitHead": "e85fc1bb496e99a4ba453db278a465079bcf6385"
48
48
  }
@@ -112,12 +112,20 @@
112
112
  <p if:true={result.hasDate} class="dx-result-date">
113
113
  {result.displayDate}
114
114
  </p>
115
- <p
116
- if:true={result.hasDescription}
117
- class="dx-result-excerpt"
118
- >
119
- {result.description}
120
- </p>
115
+ <!-- Highlighted snippet (P4.5): innerHTML set in
116
+ renderedCallback, keyed by data-snippet-key. -->
117
+ <template lwc:if={result.hasSnippetHtml}>
118
+ <p
119
+ class="dx-result-excerpt"
120
+ data-snippet-key={result.key}
121
+ lwc:dom="manual"
122
+ ></p>
123
+ </template>
124
+ <template lwc:elseif={result.hasDescription}>
125
+ <p class="dx-result-excerpt">
126
+ {result.description}
127
+ </p>
128
+ </template>
121
129
  </li>
122
130
  </template>
123
131
  </ul>
@@ -6,6 +6,7 @@ import {
6
6
  import type { LocaleOption } from "docUtils/searchLocale";
7
7
  import {
8
8
  decodeHtmlEntities,
9
+ highlightedSnippetHtml,
9
10
  isSortOption,
10
11
  SORT_OPTIONS,
11
12
  type SearchResult,
@@ -32,6 +33,12 @@ interface DisplayResult {
32
33
  title: string;
33
34
  description: string | null;
34
35
  hasDescription: boolean;
36
+ // Highlighted-snippet HTML (P4.5), or null to fall back to the plain-text
37
+ // description. When set, it is injected as innerHTML into the matching
38
+ // lwc:dom="manual" node (see renderedCallback); when null the description
39
+ // text path renders exactly as before.
40
+ snippetHtml: string | null;
41
+ hasSnippetHtml: boolean;
35
42
  contentTypeLabel: string | null;
36
43
  hasBadge: boolean;
37
44
  displayDate: string;
@@ -154,12 +161,17 @@ export default class SearchHybrid extends LightningElement {
154
161
  : null;
155
162
  const label = this.contentTypeLabel(r.contentType);
156
163
  const displayDate = this.formatDate(r.lastmod);
164
+ // Prefer the highlighted snippet (headline source only); otherwise
165
+ // null → the description text path below renders unchanged.
166
+ const snippetHtml = highlightedSnippetHtml(r);
157
167
  return {
158
168
  key: `${r.url}-${i}`,
159
169
  url: r.url,
160
170
  title: decodeHtmlEntities(r.title),
161
171
  description,
162
172
  hasDescription: description !== null,
173
+ snippetHtml,
174
+ hasSnippetHtml: snippetHtml !== null,
163
175
  contentTypeLabel: label,
164
176
  hasBadge: label !== null,
165
177
  displayDate,
@@ -170,6 +182,30 @@ export default class SearchHybrid extends LightningElement {
170
182
  });
171
183
  }
172
184
 
185
+ /**
186
+ * Inject snippet HTML into the lwc:dom="manual" excerpt nodes after every
187
+ * render. LWC won't bind innerHTML declaratively, so we set it imperatively
188
+ * here, keyed by the result's `key` (data-snippet-key) so reorder/pagination
189
+ * can't cross-wire rows. Nodes without a matching row (fallback text path)
190
+ * are left untouched.
191
+ */
192
+ renderedCallback(): void {
193
+ const byKey = new Map(
194
+ this.displayResults
195
+ .filter((r) => r.hasSnippetHtml)
196
+ .map((r) => [r.key, r.snippetHtml as string])
197
+ );
198
+ const nodes = this.template.querySelectorAll<HTMLElement>(
199
+ ".dx-result-excerpt[data-snippet-key]"
200
+ );
201
+ nodes.forEach((node) => {
202
+ const html = byKey.get(node.dataset.snippetKey ?? "");
203
+ if (html != null && node.innerHTML !== html) {
204
+ node.innerHTML = html;
205
+ }
206
+ });
207
+ }
208
+
173
209
  /**
174
210
  * Null/NaN-safe date formatter (mirrors arch/searchHybrid). lastmod is null
175
211
  * for the entire SSG corpus (the common case → ""); the WordPress portion