@leanix/components 0.3.49 → 0.3.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/esm2020/lib/core-ui/pipes/highlight-range.pipe.mjs +6 -1
- package/esm2020/lib/core-ui/pipes/highlight-term.pipe.mjs +13 -5
- package/fesm2015/leanix-components.mjs +16 -3
- package/fesm2015/leanix-components.mjs.map +1 -1
- package/fesm2020/leanix-components.mjs +16 -3
- package/fesm2020/leanix-components.mjs.map +1 -1
- package/lib/core-ui/pipes/highlight-range.pipe.d.ts +2 -1
- package/lib/core-ui/pipes/highlight-term.pipe.d.ts +1 -0
- package/package.json +2 -1
|
@@ -16,6 +16,7 @@ import { TranslatePipe, TranslateModule } from '@ngx-translate/core';
|
|
|
16
16
|
import * as i1$3 from '@angular/platform-browser';
|
|
17
17
|
import Color from 'color';
|
|
18
18
|
import { format, distanceInWords, startOfDay } from 'date-fns';
|
|
19
|
+
import { sanitize } from 'dompurify';
|
|
19
20
|
import _, { curry } from 'lodash';
|
|
20
21
|
import { Renderer, marked } from 'marked';
|
|
21
22
|
import * as i2$1 from '@angular/forms';
|
|
@@ -1344,6 +1345,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImpor
|
|
|
1344
1345
|
|
|
1345
1346
|
class HighlightRangePipe {
|
|
1346
1347
|
transform(text, offset = 0, length = 0) {
|
|
1348
|
+
const highlightedMarkup = this.doTransform(text, offset, length);
|
|
1349
|
+
return sanitize(highlightedMarkup, { ALLOWED_TAGS: ['span'], ALLOWED_ATTR: ['class'] });
|
|
1350
|
+
}
|
|
1351
|
+
doTransform(text, offset, length) {
|
|
1347
1352
|
if (!text || offset < 0 || length < 0 || offset >= text?.length || offset + length > text?.length) {
|
|
1348
1353
|
return '';
|
|
1349
1354
|
}
|
|
@@ -1376,12 +1381,21 @@ class HighlightTermPipe {
|
|
|
1376
1381
|
* @returns The transformed text with highlighted search term.
|
|
1377
1382
|
*/
|
|
1378
1383
|
transform(text, search, options = { exactMatch: false }) {
|
|
1379
|
-
if (
|
|
1384
|
+
if (text) {
|
|
1385
|
+
const highlightedMarkup = this.doTransform(text, search, options);
|
|
1386
|
+
return highlightedMarkup ? sanitize(highlightedMarkup, { ALLOWED_TAGS: ['span'], ALLOWED_ATTR: ['class'] }) : undefined;
|
|
1387
|
+
}
|
|
1388
|
+
else {
|
|
1389
|
+
return undefined;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
doTransform(text, search, options) {
|
|
1393
|
+
if (search) {
|
|
1380
1394
|
let pattern = options.exactMatch ? search.trim() : search.replace(STANDARD_TOKENIZER_SEPERATORS, ' ');
|
|
1381
1395
|
// replace special chars for a backslash for RegExp
|
|
1382
1396
|
pattern = pattern.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
|
|
1383
1397
|
pattern = options.exactMatch
|
|
1384
|
-
?
|
|
1398
|
+
? pattern
|
|
1385
1399
|
: pattern
|
|
1386
1400
|
.split(' ')
|
|
1387
1401
|
.filter((t) => {
|
|
@@ -1389,7 +1403,6 @@ class HighlightTermPipe {
|
|
|
1389
1403
|
})
|
|
1390
1404
|
.join('|');
|
|
1391
1405
|
const regex = new RegExp(pattern, 'gi');
|
|
1392
|
-
text = escape(text);
|
|
1393
1406
|
return text.replace(regex, (match) => `<span class="termHighlight">${match}</span>`); // add highlighting to matched regex pattern
|
|
1394
1407
|
}
|
|
1395
1408
|
else {
|