UNPKG

@true-directive/base

Version:

The set of base classes for the TrueDirective Grid

38 lines (37 loc) 1.45 kB
/** * Copyright (c) 2018-2019 Aleksey Melnikov, True Directive Company. * @link https://truedirective.com/ * @license MIT */ import { ColumnType } from './enums'; import { Strings } from '../common/strings.class'; var CellHighlighter = /** @class */ (function () { function CellHighlighter() { } // Подсветка найденной подстроки CellHighlighter.highlight = function (searchStr, col, v, v_displayed) { if (!v || !v_displayed) { return v_displayed; } var s = searchStr.toLowerCase(); if (s === '') { return v_displayed; } if (col.type === ColumnType.NUMBER) { if (!/\d/.test(s)) { return v_displayed; } } var start_hl = "<span class='true-hl'>"; var end_hl = "</span>"; if (col.type === ColumnType.UNSAFE_HTML || col.type === ColumnType.HTML) { var decoratedValue = Strings.decorate(v, s, start_hl, end_hl); // Если пробел на границе, то надо заменить на &nbsp; decoratedValue = decoratedValue.replace('> ', '>&nbsp;').replace(' <', '&nbsp;<'); return v_displayed.replace(v, decoratedValue); } return Strings.decorate(v_displayed, s, start_hl, end_hl); }; return CellHighlighter; }()); export { CellHighlighter };