Skip to content

Commit f15a210

Browse files
authored
Merge branch 'master' into ibarakov/fix-13854-master
2 parents 650ccce + 26d3cd6 commit f15a210

File tree

13 files changed

+74
-48
lines changed

13 files changed

+74
-48
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ All notable changes for each version of this project will be documented in this
3434
- `IgxForOf`
3535
- Unified logic for vertical and horizontal virtualization such as - caching, updating, max browser size exceeding.
3636
- Added new method - `addScroll` that can shift the scroll thumb by the specified amount in pixels (negative number to scroll to previous, positive to scroll next). Similar to `addScrollTop` but works for both vertical and horizontal virtualization.
37-
38-
37+
- `IgxTextHighlightDirective` is now correctly tree-shaken out of the bundle when not used.
38+
- **Breaking Change** A new `IgxTextHighlightService` is now exposed and methods `setActiveHighlight` and `clearActiveHighlight` have been moved to it.
3939
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
4040
- Tree-shaking of the grids has been improved:
4141
- The `igx-paginator`, `igx-grid-toolbar` and `igx-action-strip` components should now correctly tree-shake when not used in a grid.

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const copyDescriptors = (obj) => {
7171
return Object.create(
7272
Object.getPrototypeOf(obj),
7373
Object.getOwnPropertyDescriptors(obj)
74-
);
74+
);
7575
}
7676
}
7777

projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { TestBed, waitForAsync } from '@angular/core/testing';
44
import { IgxTextHighlightDirective, IActiveHighlightInfo} from './text-highlight.directive';
55

66
import { configureTestSuite } from '../../test-utils/configure-suite';
7+
import { IgxTextHighlightService } from './text-highlight.service';
78

89
describe('IgxHighlight', () => {
910
configureTestSuite();
@@ -321,6 +322,8 @@ class HighlightLoremIpsumComponent {
321322
// eslint-disable-next-line max-len
322323
public html = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum vulputate luctus dui ut maximus. Quisque sed suscipit lorem. Vestibulum sit.';
323324

325+
constructor(private highlightService: IgxTextHighlightService) { }
326+
324327
public highlightText(text: string, caseSensitive?: boolean, exactMatch?: boolean) {
325328
return this.highlight.highlight(text, caseSensitive, exactMatch);
326329
}
@@ -339,6 +342,6 @@ class HighlightLoremIpsumComponent {
339342
column: 0,
340343
index
341344
};
342-
IgxTextHighlightDirective.setActiveHighlight(this.groupName, activeHighlightInfo);
345+
this.highlightService.setActiveHighlight(this.groupName, activeHighlightInfo);
343346
}
344347
}

projects/igniteui-angular/src/lib/directives/text-highlight/text-highlight.directive.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
AfterViewInit,
33
Directive,
44
ElementRef,
5-
EventEmitter,
65
Input,
76
OnChanges,
87
OnDestroy,
@@ -13,6 +12,7 @@ import {
1312
import { takeUntil } from 'rxjs/operators';
1413
import { Subject } from 'rxjs';
1514
import { compareMaps } from '../../core/utils';
15+
import { IgxTextHighlightService } from './text-highlight.service';
1616

1717
export interface IBaseSearchInfo {
1818
searchText: string;
@@ -49,9 +49,6 @@ export interface IActiveHighlightInfo {
4949
standalone: true
5050
})
5151
export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecked, OnDestroy, OnChanges {
52-
public static highlightGroupsMap = new Map<string, IActiveHighlightInfo>();
53-
private static onActiveElementChanged = new EventEmitter<string>();
54-
5552
/**
5653
* Determines the `CSS` class of the highlight elements.
5754
* This allows the developer to provide custom `CSS` to customize the highlight.
@@ -202,8 +199,8 @@ export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecke
202199
private _defaultCssClass = 'igx-highlight';
203200
private _defaultActiveCssClass = 'igx-highlight--active';
204201

205-
constructor(private element: ElementRef, public renderer: Renderer2) {
206-
IgxTextHighlightDirective.onActiveElementChanged.pipe(takeUntil(this.destroy$)).subscribe((groupName) => {
202+
constructor(private element: ElementRef, private service: IgxTextHighlightService, private renderer: Renderer2) {
203+
this.service.onActiveElementChanged.pipe(takeUntil(this.destroy$)).subscribe((groupName) => {
207204
if (this.groupName === groupName) {
208205
if (this._activeElementIndex !== -1) {
209206
this.deactivate();
@@ -213,25 +210,6 @@ export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecke
213210
});
214211
}
215212

216-
/**
217-
* Activates the highlight at a given index.
218-
* (if such index exists)
219-
*/
220-
public static setActiveHighlight(groupName: string, highlight: IActiveHighlightInfo) {
221-
IgxTextHighlightDirective.highlightGroupsMap.set(groupName, highlight);
222-
IgxTextHighlightDirective.onActiveElementChanged.emit(groupName);
223-
}
224-
225-
/**
226-
* Clears any existing highlight.
227-
*/
228-
public static clearActiveHighlight(groupName) {
229-
IgxTextHighlightDirective.highlightGroupsMap.set(groupName, {
230-
index: -1
231-
});
232-
IgxTextHighlightDirective.onActiveElementChanged.emit(groupName);
233-
}
234-
235213
/**
236214
* @hidden
237215
*/
@@ -267,8 +245,8 @@ export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecke
267245
public ngAfterViewInit() {
268246
this.parentElement = this.renderer.parentNode(this.element.nativeElement);
269247

270-
if (IgxTextHighlightDirective.highlightGroupsMap.has(this.groupName) === false) {
271-
IgxTextHighlightDirective.highlightGroupsMap.set(this.groupName, {
248+
if (this.service.highlightGroupsMap.has(this.groupName) === false) {
249+
this.service.highlightGroupsMap.set(this.groupName, {
272250
index: -1
273251
});
274252
}
@@ -338,7 +316,7 @@ export class IgxTextHighlightDirective implements AfterViewInit, AfterViewChecke
338316
* Activates the highlight if it is on the currently active row and column.
339317
*/
340318
public activateIfNecessary(): void {
341-
const group = IgxTextHighlightDirective.highlightGroupsMap.get(this.groupName);
319+
const group = this.service.highlightGroupsMap.get(this.groupName);
342320

343321
if (group.index >= 0 && group.column === this.column && group.row === this.row && compareMaps(this.metadata, group.metadata)) {
344322
this.activate(group.index);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { EventEmitter, Injectable } from '@angular/core';
2+
import { IActiveHighlightInfo } from './text-highlight.directive';
3+
4+
@Injectable({
5+
providedIn: 'root'
6+
})
7+
export class IgxTextHighlightService {
8+
public highlightGroupsMap = new Map<string, IActiveHighlightInfo>();
9+
public onActiveElementChanged = new EventEmitter<string>();
10+
11+
constructor() { }
12+
13+
/**
14+
* Activates the highlight at a given index.
15+
* (if such index exists)
16+
*/
17+
public setActiveHighlight(groupName: string, highlight: IActiveHighlightInfo) {
18+
this.highlightGroupsMap.set(groupName, highlight);
19+
this.onActiveElementChanged.emit(groupName);
20+
}
21+
22+
/**
23+
* Clears any existing highlight.
24+
*/
25+
public clearActiveHighlight(groupName) {
26+
this.highlightGroupsMap.set(groupName, {
27+
index: -1
28+
});
29+
this.onActiveElementChanged.emit(groupName);
30+
}
31+
32+
}

projects/igniteui-angular/src/lib/grids/common/enums.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { mkenum } from '../../core/utils';
55
* - quickFilter: Default mode with a filter row UI between the column headers and the first row of records.
66
* - excelStyleFilter: Filter mode where an Excel-style filter is used.
77
*/
8-
export const FilterMode = mkenum({
8+
export const FilterMode = /*@__PURE__*/mkenum({
99
quickFilter: 'quickFilter',
1010
excelStyleFilter: 'excelStyleFilter'
1111
});
@@ -16,7 +16,7 @@ export type FilterMode = (typeof FilterMode)[keyof typeof FilterMode];
1616
* - top: Default value; Summary rows are displayed at the top of the grid.
1717
* - bottom: Summary rows are displayed at the bottom of the grid.
1818
*/
19-
export const GridSummaryPosition = mkenum({
19+
export const GridSummaryPosition = /*@__PURE__*/mkenum({
2020
top: 'top',
2121
bottom: 'bottom'
2222
});
@@ -28,7 +28,7 @@ export type GridSummaryPosition = (typeof GridSummaryPosition)[keyof typeof Grid
2828
* - childLevelsOnly: Summaries are calculated only for child levels.
2929
* - rootAndChildLevels: Default value; Summaries are calculated for both root and child levels.
3030
*/
31-
export const GridSummaryCalculationMode = mkenum({
31+
export const GridSummaryCalculationMode = /*@__PURE__*/mkenum({
3232
rootLevelOnly: 'rootLevelOnly',
3333
childLevelsOnly: 'childLevelsOnly',
3434
rootAndChildLevels: 'rootAndChildLevels'
@@ -42,8 +42,8 @@ export type GridSummaryCalculationMode = (typeof GridSummaryCalculationMode)[key
4242
*/
4343
export type GridValidationTrigger = 'change' | 'blur' ;
4444

45-
/**
46-
* Type representing the type of the target object (elements of the grid) for keydown (fired when a key is pressed) events in the grid.
45+
/**
46+
* Type representing the type of the target object (elements of the grid) for keydown (fired when a key is pressed) events in the grid.
4747
* - 'dataCell': Represents a data cell within the grid. It contains and displays individual data values
4848
* - 'summaryCell': Summary cells display aggregated/summarized data at the bottom of the grid. They provide insights like total record count, min/max values, etc.
4949
* - 'groupRow': Group row within the grid. Group rows are used to group related data rows by columns. Contains the related group expression, level, sub-records and group value.
@@ -66,7 +66,7 @@ export type GridKeydownTargetType =
6666
* - 'multiple': Default cell selection mode. More than one element can be selected at a time.
6767
* - 'multipleCascade': Similar to multiple selection. It is used in hierarchical or tree grids. Allows selection not only to an individual item but also all its related or nested items in a single action
6868
*/
69-
export const GridSelectionMode = mkenum({
69+
export const GridSelectionMode = /*@__PURE__*/mkenum({
7070
none: 'none',
7171
single: 'single',
7272
multiple: 'multiple',
@@ -75,7 +75,7 @@ export const GridSelectionMode = mkenum({
7575
export type GridSelectionMode = (typeof GridSelectionMode)[keyof typeof GridSelectionMode];
7676

7777
/** Enumeration representing different column display order options. */
78-
export const ColumnDisplayOrder = mkenum({
78+
export const ColumnDisplayOrder = /*@__PURE__*/mkenum({
7979
Alphabetical: 'Alphabetical',
8080
DisplayOrder: 'DisplayOrder'
8181
});

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { GridColumnDataType } from '../data-operations/data-util';
4040
import { FilteringLogic, IFilteringExpression } from '../data-operations/filtering-expression.interface';
4141
import { IGroupByRecord } from '../data-operations/groupby-record.interface';
4242
import { IForOfDataChangingEventArgs, IgxGridForOfDirective } from '../directives/for-of/for_of.directive';
43-
import { IgxTextHighlightDirective } from '../directives/text-highlight/text-highlight.directive';
43+
import { IgxTextHighlightService } from '../directives/text-highlight/text-highlight.service';
4444
import { ISummaryExpression } from './summaries/grid-summary';
4545
import { RowEditPositionStrategy } from './grid.common';
4646
import type { IgxGridToolbarComponent } from './toolbar/grid-toolbar.component';
@@ -3306,6 +3306,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
33063306
public navigation: IgxGridNavigationService,
33073307
/** @hidden @internal */
33083308
public filteringService: IgxFilteringService,
3309+
protected textHighlightService: IgxTextHighlightService,
33093310
@Inject(IgxOverlayService) protected overlayService: IgxOverlayService,
33103311
/** @hidden @internal */
33113312
public summaryService: IgxGridSummaryService,
@@ -5072,7 +5073,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
50725073
this.rebuildMatchCache();
50735074

50745075
if (updateActiveInfo) {
5075-
const activeInfo = IgxTextHighlightDirective.highlightGroupsMap.get(this.id);
5076+
const activeInfo = this.textHighlightService.highlightGroupsMap.get(this.id);
50765077
this.lastSearchInfo.matchInfoCache.forEach((match, i) => {
50775078
if (match.column === activeInfo.column &&
50785079
match.row === activeInfo.row &&
@@ -7527,15 +7528,15 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
75277528
this.scrollTo(matchInfo.row, matchInfo.column);
75287529
}
75297530

7530-
IgxTextHighlightDirective.setActiveHighlight(this.id, {
7531+
this.textHighlightService.setActiveHighlight(this.id, {
75317532
column: matchInfo.column,
75327533
row: matchInfo.row,
75337534
index: matchInfo.index,
75347535
metadata: matchInfo.metadata,
75357536
});
75367537

75377538
} else {
7538-
IgxTextHighlightDirective.clearActiveHighlight(this.id);
7539+
this.textHighlightService.clearActiveHighlight(this.id);
75397540
}
75407541

75417542
return this.lastSearchInfo.matchCount;

projects/igniteui-angular/src/lib/grids/hierarchical-grid/hierarchical-grid-base.directive.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { IgxOverlayService } from '../../services/overlay/overlay';
4040
import { State, Transaction, TransactionService } from '../../services/transaction/transaction';
4141
import { IgxGridTransaction } from '../common/types';
4242
import { IgxGridValidationService } from '../grid/grid-validation.service';
43+
import { IgxTextHighlightService } from '../../directives/text-highlight/text-highlight.service';
4344

4445
export const hierarchicalTransactionServiceFactory = () => new IgxTransactionService();
4546

@@ -156,6 +157,7 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect
156157
envInjector: EnvironmentInjector,
157158
navigation: IgxHierarchicalGridNavigationService,
158159
filteringService: IgxFilteringService,
160+
textHighlightService: IgxTextHighlightService,
159161
@Inject(IgxOverlayService) overlayService: IgxOverlayService,
160162
summaryService: IgxGridSummaryService,
161163
@Optional() @Inject(DisplayDensityToken) _displayDensityOptions: IDisplayDensityOptions,
@@ -178,6 +180,7 @@ export abstract class IgxHierarchicalGridBaseDirective extends IgxGridBaseDirect
178180
envInjector,
179181
navigation,
180182
filteringService,
183+
textHighlightService,
181184
overlayService,
182185
summaryService,
183186
_displayDensityOptions,

projects/igniteui-angular/src/lib/grids/hierarchical-grid/row-island.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { IgxPaginatorDirective } from '../../paginator/paginator-interfaces';
4848
import { IgxFlatTransactionFactory } from '../../services/transaction/transaction-factory.service';
4949
import { IGridCreatedEventArgs } from './events';
5050
import { IgxGridValidationService } from '../grid/grid-validation.service';
51+
import { IgxTextHighlightService } from '../../directives/text-highlight/text-highlight.service';
5152

5253
@Component({
5354
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -234,6 +235,7 @@ export class IgxRowIslandComponent extends IgxHierarchicalGridBaseDirective
234235
envInjector: EnvironmentInjector,
235236
navigation: IgxHierarchicalGridNavigationService,
236237
filteringService: IgxFilteringService,
238+
textHighlightService: IgxTextHighlightService,
237239
@Inject(IgxOverlayService) overlayService: IgxOverlayService,
238240
summaryService: IgxGridSummaryService,
239241
@Optional() @Inject(DisplayDensityToken) _displayDensityOptions: IDisplayDensityOptions,
@@ -256,6 +258,7 @@ export class IgxRowIslandComponent extends IgxHierarchicalGridBaseDirective
256258
envInjector,
257259
navigation,
258260
filteringService,
261+
textHighlightService,
259262
overlayService,
260263
summaryService,
261264
_displayDensityOptions,

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import { IgxGridDragSelectDirective } from '../selection/drag-select.directive';
9191
import { IgxGridBodyDirective } from '../grid.common';
9292
import { IgxColumnResizingService } from '../resizing/resizing.service';
9393
import { DefaultDataCloneStrategy, IDataCloneStrategy } from '../../data-operations/data-clone-strategy';
94+
import { IgxTextHighlightService } from '../../directives/text-highlight/text-highlight.service';
9495

9596
let NEXT_ID = 0;
9697
const MINIMUM_COLUMN_WIDTH = 200;
@@ -976,6 +977,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
976977
envInjector: EnvironmentInjector,
977978
navigation: IgxPivotGridNavigationService,
978979
filteringService: IgxFilteringService,
980+
textHighlightService: IgxTextHighlightService,
979981
@Inject(IgxOverlayService) overlayService: IgxOverlayService,
980982
summaryService: IgxGridSummaryService,
981983
@Optional() @Inject(DisplayDensityToken) _displayDensityOptions: IDisplayDensityOptions,
@@ -998,6 +1000,7 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
9981000
envInjector,
9991001
navigation,
10001002
filteringService,
1003+
textHighlightService,
10011004
overlayService,
10021005
summaryService,
10031006
_displayDensityOptions,

0 commit comments

Comments
 (0)