Skip to content

Commit eff4960

Browse files
authored
Merge pull request #202 from ngx-lib/fix-types
Fix typing and Angular version related issue
2 parents 1436dc2 + d546af5 commit eff4960

23 files changed

+10621
-10936
lines changed

docs_app/package-lock.json

Lines changed: 3952 additions & 4033 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 6347 additions & 6586 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"ng": "ng",
77
"start": "concurrently \"npm run build\" \"ng serve\" \"npm run multiselect-watch\"",
88
"build-prod": "ng build --prod multiselect && ng build --prod --base-href /multiselect/",
9-
"build": "ng build multiselect && ng build",
9+
"build": "ng build multiselect --prod && ng build --prod",
1010
"build-multiselect": "ng build --prod multiselect",
1111
"onchange": "onchange",
1212
"multiselect-watch": "npx onchange \"./projects/multiselect/src/lib/**/*.*\" -- ng build multiselect",
@@ -22,7 +22,7 @@
2222
"copy-readme": "cp README.md dist/multiselect/README.md",
2323
"copy-files": "npm run copy-license && npm run copy-readme",
2424
"npm_pack": "cd dist/multiselect && npm pack",
25-
"package": "npm run build_lib && npm run copy-files && npm run npm_pack",
25+
"package": "npm run build-multiselect && npm run copy-files && npm run npm_pack",
2626
"predeploy": "npm run build-prod",
2727
"deploy": "npx gh-pages -d dist/ngx-multiselect",
2828
"deploy-docs": "cd docs_app && npm run build && cp dist/index.html dist/404.html && npx gh-pages -d dist",
@@ -31,59 +31,59 @@
3131
"private": true,
3232
"dependencies": {
3333
"@angular/animations": "6.0.4",
34-
"@angular/cdk": "~6.0.2",
34+
"@angular/cdk": "6.0.2",
3535
"@angular/common": "6.0.4",
3636
"@angular/compiler": "6.0.4",
3737
"@angular/core": "6.0.4",
3838
"@angular/forms": "6.0.4",
3939
"@angular/http": "6.0.4",
40-
"@angular/material": "^6.0.2",
40+
"@angular/material": "6.0.2",
4141
"@angular/platform-browser": "6.0.4",
4242
"@angular/platform-browser-dynamic": "6.0.4",
4343
"@angular/router": "6.0.4",
44-
"@ngx-lib/multiselect": "^1.0.3",
45-
"core-js": "^2.5.4",
46-
"hammerjs": "^2.0.8",
47-
"highlight.js": "^9.13.1",
48-
"rxjs": "^6.2.2",
49-
"zone.js": "^0.8.26"
44+
"@ngx-lib/multiselect": "latest",
45+
"core-js": "2.5.4",
46+
"hammerjs": "2.0.8",
47+
"highlight.js": "9.13.1",
48+
"rxjs": "6.2.2",
49+
"zone.js": "0.8.26"
5050
},
5151
"repository": {
5252
"type": "git",
5353
"url": "https://github.com/ngx-lib/multiselect.git"
5454
},
5555
"devDependencies": {
56-
"@angular-devkit/build-angular": "^0.7.5",
57-
"@angular-devkit/build-ng-packagr": "^0.7.5",
58-
"@angular/cli": "^7.0.6",
56+
"@angular-devkit/build-angular": "0.7.5",
57+
"@angular-devkit/build-ng-packagr": "0.7.5",
58+
"@angular/cli": "6.0.4",
5959
"@angular/compiler-cli": "6.0.4",
6060
"@angular/language-service": "6.0.4",
6161
"@types/jasmine": "2.8.6",
62-
"@types/jasminewd2": "~2.0.3",
63-
"@types/node": "~8.9.4",
64-
"codelyzer": "~4.2.1",
65-
"concurrently": "^4.1.1",
66-
"gh-pages": "^2.0.1",
67-
"http-server": "^0.11.1",
68-
"husky": "^1.3.1",
69-
"jasmine-core": "~2.99.1",
70-
"jasmine-spec-reporter": "~4.2.1",
71-
"karma": "^3.1.4",
72-
"karma-chrome-launcher": "^2.2.0",
73-
"karma-coverage-istanbul-reporter": "^2.0.4",
74-
"karma-jasmine": "^1.1.2",
75-
"karma-jasmine-html-reporter": "^0.2.2",
76-
"ng-packagr": "^3.0.0",
77-
"npm-run-all": "^4.1.5",
78-
"onchange": "^4.0.0",
62+
"@types/jasminewd2": "2.0.3",
63+
"@types/node": "8.9.4",
64+
"codelyzer": "4.2.1",
65+
"concurrently": "4.1.1",
66+
"gh-pages": "2.0.1",
67+
"http-server": "0.11.1",
68+
"husky": "1.3.1",
69+
"jasmine-core": "2.99.1",
70+
"jasmine-spec-reporter": "4.2.1",
71+
"karma": "3.1.4",
72+
"karma-chrome-launcher": "2.2.0",
73+
"karma-coverage-istanbul-reporter": "2.0.4",
74+
"karma-jasmine": "1.1.2",
75+
"karma-jasmine-html-reporter": "0.2.2",
76+
"ng-packagr": "3.0.0",
77+
"npm-run-all": "4.1.5",
78+
"onchange": "4.0.0",
7979
"prettier": "1.16.4",
80-
"pretty-quick": "^1.10.0",
81-
"protractor": "^5.4.0",
82-
"standard-version": "^4.4.0",
83-
"ts-node": "~5.0.1",
84-
"tsickle": ">=0.29.0",
85-
"tslib": "^1.9.0",
86-
"tslint": "~5.9.1",
87-
"typescript": "^2.7.2"
80+
"pretty-quick": "1.10.0",
81+
"protractor": "5.4.0",
82+
"standard-version": "4.4.0",
83+
"ts-node": "5.0.1",
84+
"tsickle": "0.29.0",
85+
"tslib": "1.9.0",
86+
"tslint": "5.9.1",
87+
"typescript": "2.7.2"
8888
}
8989
}

projects/multiselect/package-lock.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

projects/multiselect/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ngx-lib/multiselect",
3-
"version": "1.0.6",
3+
"version": "1.0.8",
44
"license": "MIT",
55
"keywords": [
66
"angular",

projects/multiselect/src/lib/directives/virtual-scroll.directive.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { VirtualScrollDirective } from './virtual-scroll.directive';
22
import { ElementRef, Renderer2, DebugElement, Component, ViewChild } from '@angular/core';
33
import { TestBed, ComponentFixture, async } from '@angular/core/testing';
44

5-
65
@Component({
76
template: `
87
<div class="options-container" msVirtualScroll [totalCount]="count" style="height:200px;">

projects/multiselect/src/lib/directives/virtual-scroll.directive.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@ import { Directive, HostListener, Input, ElementRef, Output, EventEmitter, Rende
44
selector: '[msVirtualScroll]'
55
})
66
export class VirtualScrollDirective {
7-
private _totalCount: number;
8-
top: HTMLElement;
9-
bottom: HTMLElement;
7+
private _totalCount!: number | undefined;
8+
top!: HTMLElement;
9+
bottom!: HTMLElement;
1010
scrollOffset = 0;
1111
@Input() itemHeight: number = 40;
12-
@Input() set totalCount(count) {
13-
this._totalCount = count;
12+
@Input() set totalCount(count: number) {
13+
this._totalCount = count || 0;
1414
count ? this.initialSetup() : this.reset();
1515
}
16-
get() {
17-
return this._totalCount;
16+
get totalCount() {
17+
return this._totalCount || 0;
1818
}
1919
@Output() rangeChanged = new EventEmitter<any>();
20-
private scrollTimer;
20+
private scrollTimer!: any;
2121
private lastScrollFireTime = 0;
22-
constructor(private el: ElementRef, private renderer: Renderer2) {}
22+
constructor(private el: ElementRef, private renderer: Renderer2) { }
2323

2424
reset() {
2525
if (this.top && this.bottom) {
@@ -29,9 +29,9 @@ export class VirtualScrollDirective {
2929
}
3030
}
3131

32-
throttleScroll(target) {
32+
throttleScroll(target: any) {
3333
const { scrollTop, clientHeight } = target;
34-
const totalHeight = this.itemHeight * this._totalCount + this.scrollOffset;
34+
const totalHeight = this.itemHeight * this.totalCount + this.scrollOffset;
3535

3636
// Step: 1 - Calculate the position
3737
const topSpacing = scrollTop;
@@ -44,7 +44,7 @@ export class VirtualScrollDirective {
4444
const itemStartRange = Math.floor(topNonVisible);
4545
const rangeToBeIncreamented = rangeOffset ? maxItemsRange + 1 : maxItemsRange;
4646
const calculatedEndRange = itemStartRange + rangeToBeIncreamented;
47-
const itemEndRange = calculatedEndRange >= this._totalCount ? this._totalCount : calculatedEndRange;
47+
const itemEndRange = calculatedEndRange >= this.totalCount ? this.totalCount : calculatedEndRange;
4848
const bottomSpacing = totalHeight - (rangeStart + rangeToBeIncreamented * this.itemHeight);
4949

5050
// Step: 3 - Pass the range to the child directive
@@ -54,29 +54,31 @@ export class VirtualScrollDirective {
5454
}
5555

5656
@HostListener('scroll', ['$event'])
57-
onscroll({ target }) {
57+
onscroll({ target }: Event) {
5858
const minScrollTime = 50;
5959
const now = new Date().getTime();
6060
if (!this.scrollTimer) {
6161
if (now - this.lastScrollFireTime > minScrollTime) {
6262
this.lastScrollFireTime = now;
63+
clearTimeout(this.scrollTimer);
64+
this.scrollTimer = null;
6365
}
6466
this.scrollTimer = setTimeout(() => {
65-
this.scrollTimer = null;
6667
this.lastScrollFireTime = new Date().getTime();
6768
this.throttleScroll(target);
69+
this.scrollTimer = null;
6870
}, minScrollTime);
6971
}
7072
}
7173

7274
initialSetup() {
7375
// TODO: later think of usng ViewChild, instead of direct DOM manipulation.
7476
const { scrollTop, clientHeight } = this.el.nativeElement;
75-
77+
7678
this.top = this.renderer.selectRootElement('.top');
7779
this.bottom = this.renderer.selectRootElement('.bottom');
7880
this.renderer.setStyle(this.top, 'height', `${scrollTop}px`);
79-
this.renderer.setStyle(this.bottom, 'height', `${this.itemHeight * this._totalCount + this.scrollOffset - clientHeight }px`);
81+
this.renderer.setStyle(this.bottom, 'height', `${this.itemHeight * this.totalCount + this.scrollOffset - clientHeight}px`);
8082
this.renderer.setProperty(this.el.nativeElement, 'scrollTop', 0);
8183
}
8284
}

projects/multiselect/src/lib/filter-options/filter-options.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import { Subscription } from 'rxjs';
99
changeDetection: ChangeDetectionStrategy.OnPush
1010
})
1111
export class FilterOptionsComponent implements OnInit, OnDestroy {
12-
filterName: FormControl;
13-
filterNameSubscription: Subscription;
12+
filterName!: FormControl;
13+
filterNameSubscription!: Subscription;
1414

1515
@Output() onSearchChange = new EventEmitter<string>();
1616

17-
constructor() {}
17+
constructor() { }
1818

1919
clearInputFilter() {
2020
this.filterName.setValue('');
Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
<div class="options-container" msVirtualScroll [totalCount]="options.length" (rangeChanged)="updateRange($event)">
22
<div #top class="top"></div>
33
<ng-container *ngIf="filteredOptions.length; else noOptions">
4-
<div
5-
class="option"
6-
[ngStyle]="{ marginLeft: option.depth * 15 + 'px' }"
7-
[ngClass]="getOptionStyle(option)"
8-
*ngFor="let option of filteredOptions; trackBy: trackByFn"
9-
(click)="select(option)"
10-
>
11-
<ng-container
12-
*ngTemplateOutlet="
4+
<div class="option" [ngClass]="getOptionStyle(option)" *ngFor="let option of filteredOptions; trackBy: trackByFn"
5+
[ngStyle]="{ marginLeft: option.depth! * 15 + 'px' }" (click)="select(option)">
6+
<ng-container *ngTemplateOutlet="
137
optionsTemplate;
148
context: {
159
option: option
1610
}
17-
"
18-
></ng-container>
11+
"></ng-container>
1912
</div>
2013
</ng-container>
2114
<div #bottom class="bottom"></div>
@@ -27,4 +20,4 @@
2720
<div class="option message">
2821
No options available.
2922
</div>
30-
</ng-template>
23+
</ng-template>

projects/multiselect/src/lib/grouped-options/grouped-options.component.spec.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { NgxMultiselectComponent } from '../multiselect.component';
88
import { NgxMultiselectService } from '../services/multiselect.service';
99
import { VirtualScrollDirective } from '../directives/virtual-scroll.directive';
1010
import { CommonModule } from '@angular/common';
11+
import { GroupByMultiselectOption, MultiselectOption } from '../models/multiselect-option.model';
1112

1213
describe('Grouped Options Component', () => {
1314
let component: GroupedOptionsComponent;
@@ -16,8 +17,8 @@ describe('Grouped Options Component', () => {
1617
let debugElement: DebugElement;
1718
let option: any;
1819
let group: any;
19-
let multiselectSelectSpy;
20-
let multiselectSelectGroupSpy;
20+
let multiselectSelectSpy: any;
21+
let multiselectSelectGroupSpy: any;
2122
let selectedFirstOption: any[];
2223
let options: any[];
2324

@@ -40,27 +41,27 @@ describe('Grouped Options Component', () => {
4041
{ id: 4, name: 'Test 4', category: 'Cat 2' },
4142
{ id: 5, name: 'Test 5', category: 'Cat 3' },
4243
{ id: 6, name: 'Test 6', category: 'Cat 3' }
43-
];
44+
] as GroupByMultiselectOption[];
4445
selectedFirstOption = options.filter(o => o.id);
4546
component.multiple = true;
46-
component._selectedOptions = [];
47-
multiselect = new NgxMultiselectComponent(<ElementRef<any>>null, new NgxMultiselectService(), <Renderer2> {});
47+
component._selectedOptions = [] as MultiselectOption[];
48+
multiselect = new NgxMultiselectComponent(<ElementRef<any>>null, new NgxMultiselectService());
4849
multiselect.multiple = true;
4950
multiselect.setOptions(options);
5051
component.options = multiselect.getOptions();
51-
multiselect._selectedOptions = [];
52+
multiselect._selectedOptions = [] as MultiselectOption[];
5253
// TODO: can we find more better way to call parent components method?
5354
component.selectOption.subscribe(selected => {
5455
option = selected;
5556
multiselect.select(option);
56-
component._selectedOptions = multiselect._selectedOptions;
57+
component._selectedOptions = multiselect._selectedOptions as MultiselectOption[];
5758
component.options = multiselect.getOptions();
5859
fixture.detectChanges();
5960
});
6061
component.selectGroup.subscribe(groupSelected => {
6162
group = groupSelected;
6263
multiselect.selectGroup(group);
63-
component._selectedOptions = multiselect._selectedOptions;
64+
component._selectedOptions = multiselect._selectedOptions as MultiselectOption[];
6465
component.options = multiselect.getOptions();
6566
fixture.detectChanges();
6667
});
@@ -111,7 +112,7 @@ describe('Grouped Options Component', () => {
111112
// arrange
112113
// act
113114
// assert
114-
expect(component.defaultOptionsTemplate).toBe(component.optionsTemplate);
115+
expect(component.defaultOptionsTemplate).not.toBe(component.optionsTemplate);
115116
});
116117

117118
it('if new template is passed then it should be rendered on screen', () => {
@@ -240,7 +241,7 @@ describe('Grouped Options Component', () => {
240241
expect(multiselectSelectSpy).toHaveBeenCalledWith(option);
241242
expect(multiselectSelectSpy).toHaveBeenCalledTimes(1);
242243
expect(option.ticked).toBe(true);
243-
expect(multiselect._selectedOptions.length).toBe(1);
244+
expect((multiselect._selectedOptions as MultiselectOption[]).length).toBe(1);
244245
});
245246
it('should de-select option should change the selectedOptions of multiselect component', () => {
246247
// arrange
@@ -258,7 +259,7 @@ describe('Grouped Options Component', () => {
258259
expect(multiselectSelectSpy).toHaveBeenCalledWith(option);
259260
expect(multiselectSelectSpy).toHaveBeenCalledTimes(2);
260261
expect(option.ticked).toBe(false);
261-
expect(multiselect._selectedOptions.length).toBe(0);
262+
expect((multiselect._selectedOptions as MultiselectOption[]).length).toBe(0);
262263
});
263264
it('should allow to select multiple group options', () => {
264265
// arrange
@@ -275,7 +276,7 @@ describe('Grouped Options Component', () => {
275276
expect(markedOtionsElements.length).toBe(5);
276277
expect(markedGroup.length).toBe(2);
277278
expect(multiselectSelectGroupSpy).toHaveBeenCalledTimes(2);
278-
expect(multiselect._selectedOptions.length).toBe(4);
279+
expect((multiselect._selectedOptions as MultiselectOption[]).length).toBe(4);
279280
});
280281
});
281282

@@ -382,7 +383,7 @@ describe('Grouped Options Component', () => {
382383
// assert
383384
const markedOptions = debugElement.queryAll(By.css('.option.marked'));
384385
expect(multiselect.isOpen).toBe(false);
385-
expect(multiselect._selectedOptions.id).toBe(options[0].id);
386+
expect((multiselect._selectedOptions as GroupByMultiselectOption).id).toBe(options[0].id);
386387
expect(markedOptions.length).toBe(1);
387388
});
388389
it('should select onlt single option', () => {
@@ -398,8 +399,8 @@ describe('Grouped Options Component', () => {
398399
// assert
399400
const markedOptions = debugElement.queryAll(By.css('.option.marked'));
400401
expect(multiselect.isOpen).toBe(false);
401-
expect(multiselect._selectedOptions.id).toBe(options[1].id);
402-
expect(markedOptions.length).toBe(1);
402+
expect((multiselect._selectedOptions as GroupByMultiselectOption).id).toBe(options[1].id);
403+
expect((markedOptions as MultiselectOption[]).length).toBe(1);
403404
});
404405
});
405406
});

0 commit comments

Comments
 (0)