diff --git a/.angular-cli.json b/.angular-cli.json deleted file mode 100644 index a100235..0000000 --- a/.angular-cli.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "$schema": "./node_modules/@angular/cli/lib/config/schema.json", - "project": { - "name": "edge-completer" - }, - "apps": [ - { - "root": "src", - "outDir": "dist", - "assets": [ - "assets", - "favicon.ico" - ], - "index": "index.html", - "main": "main.ts", - "polyfills": "polyfills.ts", - "test": "test.ts", - "tsconfig": "tsconfig.app.json", - "testTsconfig": "tsconfig.spec.json", - "prefix": "app", - "styles": [ - "styles.css" - ], - "scripts": [], - "environmentSource": "environments/environment.ts", - "environments": { - "dev": "environments/environment.ts", - "prod": "environments/environment.prod.ts" - } - } - ], - "e2e": { - "protractor": { - "config": "./protractor.conf.js" - } - }, - "lint": [ - { - "project": "src/tsconfig.app.json", - "exclude": "**/node_modules/**" - }, - { - "project": "src/tsconfig.spec.json", - "exclude": "**/node_modules/**" - }, - { - "project": "e2e/tsconfig.e2e.json", - "exclude": "**/node_modules/**" - } - ], - "test": { - "karma": { - "config": "./karma.conf.js" - } - }, - "defaults": { - "styleExt": "css", - "component": {} - } -} diff --git a/angular.json b/angular.json new file mode 100644 index 0000000..1692755 --- /dev/null +++ b/angular.json @@ -0,0 +1,132 @@ +{ + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "version": 1, + "newProjectRoot": "projects", + "projects": { + "edge-completer": { + "root": "", + "sourceRoot": "src", + "projectType": "application", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:browser", + "options": { + "outputPath": "dist", + "index": "src/index.html", + "main": "src/main.ts", + "tsConfig": "src/tsconfig.app.json", + "polyfills": "src/polyfills.ts", + "assets": [ + "src/assets", + "src/favicon.ico" + ], + "styles": [ + "src/styles.css" + ], + "scripts": [] + }, + "configurations": { + "production": { + "optimization": true, + "outputHashing": "all", + "sourceMap": false, + "extractCss": true, + "namedChunks": false, + "aot": true, + "extractLicenses": true, + "vendorChunk": false, + "buildOptimizer": true, + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.prod.ts" + } + ] + } + } + }, + "serve": { + "builder": "@angular-devkit/build-angular:dev-server", + "options": { + "browserTarget": "edge-completer:build" + }, + "configurations": { + "production": { + "browserTarget": "edge-completer:build:production" + } + } + }, + "extract-i18n": { + "builder": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "edge-completer:build" + } + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "src/test.ts", + "karmaConfig": "./karma.conf.js", + "polyfills": "src/polyfills.ts", + "tsConfig": "src/tsconfig.spec.json", + "scripts": [], + "styles": [ + "src/styles.css" + ], + "assets": [ + "src/assets", + "src/favicon.ico" + ] + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "src/tsconfig.app.json", + "src/tsconfig.spec.json" + ], + "exclude": [ + "**/node_modules/**" + ] + } + } + } + }, + "edge-completer-e2e": { + "root": "e2e", + "sourceRoot": "e2e", + "projectType": "application", + "architect": { + "e2e": { + "builder": "@angular-devkit/build-angular:protractor", + "options": { + "protractorConfig": "./protractor.conf.js", + "devServerTarget": "edge-completer:serve" + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "e2e/tsconfig.e2e.json" + ], + "exclude": [ + "**/node_modules/**" + ] + } + } + } + } + }, + "defaultProject": "edge-completer", + "schematics": { + "@schematics/angular:component": { + "prefix": "app", + "styleext": "css" + }, + "@schematics/angular:directive": { + "prefix": "app" + } + } +} \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js index af139fa..0840f6c 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -4,24 +4,22 @@ module.exports = function (config) { config.set({ basePath: '', - frameworks: ['jasmine', '@angular/cli'], + frameworks: ['jasmine', '@angular-devkit/build-angular'], plugins: [ require('karma-jasmine'), require('karma-chrome-launcher'), require('karma-jasmine-html-reporter'), require('karma-coverage-istanbul-reporter'), - require('@angular/cli/plugins/karma') + require('@angular-devkit/build-angular/plugins/karma') ], client:{ clearContext: false // leave Jasmine Spec Runner output visible in browser }, coverageIstanbulReporter: { - reports: [ 'html', 'lcovonly' ], + dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ], fixWebpackSourcePaths: true }, - angularCli: { - environment: 'dev' - }, + reporters: ['progress', 'kjhtml'], port: 9876, colors: true, diff --git a/ng-package.json b/ng-package.json index 46c4e08..56987c1 100644 --- a/ng-package.json +++ b/ng-package.json @@ -2,5 +2,6 @@ "$schema": "./node_modules/ng-packagr/ng-package.schema.json", "lib": { "entryFile": "public_api.ts" - } + }, + "whitelistedNonPeerDependencies": ["."] } diff --git a/package.json b/package.json index 5eae38d..bdb6f1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "edge-completer", - "version": "1.0.1", + "version": "1.1.0", "license": "MIT", "scripts": { "ng": "ng", @@ -10,31 +10,32 @@ "lint": "ng lint", "e2e": "ng e2e", "packagr": "ng-packagr -p ng-package.json && cp -R src/assets dist/assets", - "packagr-win": "ng-packagr -p ng-package.json && xcopy /E src\\assets dist\\assets\\ && cd dist && rmdir /Q /S node_modules && npm pack" + "packagr-win": "ng-packagr -p ng-package.json && xcopy /E src\\assets dist\\assets\\ && cd dist && npm pack" }, "private": false, "dependencies": { - "@angular/animations": "^5.2.0", - "@angular/common": "^5.2.0", - "@angular/compiler": "^5.2.0", - "@angular/core": "^5.2.0", - "@angular/forms": "^5.2.0", - "@angular/http": "^5.2.0", - "@angular/platform-browser": "^5.2.0", - "@angular/platform-browser-dynamic": "^5.2.0", - "@angular/router": "^5.2.0", + "@angular/common": "^8.1.1", + "@angular/compiler": "^8.1.1", + "@angular/core": "^8.1.1", + "@angular/forms": "^8.1.1", + "@angular/http": "^7.2.15", + "@angular/platform-browser": "^8.1.1", + "@angular/platform-browser-dynamic": "^8.1.1", + "@angular/router": "^8.1.1", "core-js": "^2.4.1", - "rxjs": "^5.5.6", - "zone.js": "^0.8.19" + "rxjs": "^6.5.2", + "tslib": "^1.9.0", + "zone.js": "^0.9.1" }, "devDependencies": { - "@angular/cli": "1.6.7", - "@angular/compiler-cli": "^5.2.0", - "@angular/language-service": "^5.2.0", + "@angular-devkit/build-angular": "^0.801.1", + "@angular/cli": "^8.1.1", + "@angular/compiler-cli": "^8.1.1", + "@angular/language-service": "^8.1.1", "@types/jasmine": "~2.8.3", "@types/jasminewd2": "~2.0.2", "@types/node": "~6.0.60", - "codelyzer": "^4.0.1", + "codelyzer": "^5.1.0", "jasmine-core": "~2.8.0", "jasmine-spec-reporter": "~4.2.1", "karma": "~2.0.0", @@ -42,10 +43,10 @@ "karma-coverage-istanbul-reporter": "^1.2.1", "karma-jasmine": "~1.1.0", "karma-jasmine-html-reporter": "^0.2.2", - "ng-packagr": "^2.0.0", + "ng-packagr": "^5.3.0", "protractor": "~5.1.2", "ts-node": "~4.1.0", "tslint": "~5.9.1", - "typescript": "~2.5.3" + "typescript": "~3.4.5" } } diff --git a/src/app/app.component.html b/src/app/app.component.html index fb5a245..d2d7c57 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,22 +1,13 @@

- Welcome to {{ title }}! + Edge-completer demo

- Angular Logo
-

Here are some links to help you start:

- - + diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 7b0f672..2a52009 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,7 @@ import { Component } from '@angular/core'; +import {CompleterItem} from './edge-completer/shared/completer-item'; +import {CompleterData} from './edge-completer/shared/completer-data'; +import {CompleterService} from './edge-completer/shared/completer-service'; @Component({ selector: 'app-root', @@ -7,4 +10,17 @@ import { Component } from '@angular/core'; }) export class AppComponent { title = 'app'; + + searchData = [{key: 'Item 1', value: 'valor do item 1'}, {key: 'Item 2', value: 'valor do item 2'}]; + + dataService: CompleterData; + + constructor(private completerService: CompleterService) { + this.dataService = completerService.local(this.searchData, 'key', 'key'); + } + + onDropdownChange($event: CompleterItem) { + if ($event) + alert('VocĂȘ selecionou ' + $event.originalObject.key); + } } diff --git a/src/app/edge-completer/directives/ctr-input.directive.ts b/src/app/edge-completer/directives/ctr-input.directive.ts index 61c2a7a..f2daef2 100644 --- a/src/app/edge-completer/directives/ctr-input.directive.ts +++ b/src/app/edge-completer/directives/ctr-input.directive.ts @@ -1,11 +1,10 @@ import { Directive, ElementRef, EventEmitter, Host, HostListener, Input, Output } from '@angular/core'; -import { Subscription } from 'rxjs/Subscription'; +import { Subscription , Observable } from 'rxjs'; import { NgModel } from '@angular/forms'; import { CtrCompleterDirective } from './ctr-completer.directive'; import { CompleterItem } from '../shared/completer-item'; import { isNil } from '../shared/globals'; -import { Observable } from 'rxjs/Observable'; -import 'rxjs/add/observable/timer'; +import { timer } from 'rxjs'; @@ -171,7 +170,7 @@ export class CtrInputDirective { } if (this.completer.isOpen) { - this.blurTimer = Observable.timer(200).subscribe(() => this.doBlur()); + this.blurTimer = timer(200).subscribe(() => this.doBlur()); } } diff --git a/src/app/edge-completer/directives/ctr-list.directive.ts b/src/app/edge-completer/directives/ctr-list.directive.ts index 24a79c0..e8fe5b7 100644 --- a/src/app/edge-completer/directives/ctr-list.directive.ts +++ b/src/app/edge-completer/directives/ctr-list.directive.ts @@ -2,14 +2,14 @@ import { ChangeDetectorRef, Directive, EmbeddedViewRef, Host, Input, OnInit, TemplateRef, ViewContainerRef } from '@angular/core'; -import { Observable } from 'rxjs/Observable'; -import 'rxjs/add/observable/timer'; +import { Observable , Subscription, timer, of } from 'rxjs'; + import { CompleterItem } from '../shared/completer-item'; import { CLEAR_TIMEOUT, isNil, MIN_SEARCH_LENGTH, PAUSE } from '../shared/globals'; import { CompleterList, CtrCompleterDirective } from './ctr-completer.directive'; -import { Subscription } from 'rxjs/Subscription'; import { CompleterData } from '../shared/completer-data'; -import 'rxjs/add/operator/catch'; +import {catchError} from 'rxjs/operators'; + export class CtrListContext { constructor( @@ -35,6 +35,9 @@ export class CtrListDirective implements OnInit, CompleterList { @Input() public ctrListDisplaySearching = true; + @Input() + public ctrListCd: ChangeDetectorRef; + private _dataService: CompleterData; // private results: CompleterItem[] = []; private term: string | null = null; @@ -48,8 +51,7 @@ export class CtrListDirective implements OnInit, CompleterList { constructor( @Host() private completer: CtrCompleterDirective, private templateRef: TemplateRef, - private viewContainer: ViewContainerRef, - private cd: ChangeDetectorRef) { } + private viewContainer: ViewContainerRef) { } public ngOnInit() { this.completer.registerList(this); @@ -96,7 +98,7 @@ export class CtrListDirective implements OnInit, CompleterList { if (this.clearTimer) { this.clearTimer.unsubscribe(); } - this.searchTimer = Observable.timer(this.ctrListPause).subscribe(() => { + this.searchTimer = timer(this.ctrListPause).subscribe(() => { this.searchTimerComplete(term); }); } else if (!isNil(term) && term.length < this.ctrListMinSearchLength) { @@ -109,7 +111,7 @@ export class CtrListDirective implements OnInit, CompleterList { if (this.searchTimer) { this.searchTimer.unsubscribe(); } - this.clearTimer = Observable.timer(CLEAR_TIMEOUT).subscribe(() => { + this.clearTimer = timer(CLEAR_TIMEOUT).subscribe(() => { this._clear(); }); } @@ -163,7 +165,7 @@ export class CtrListDirective implements OnInit, CompleterList { this.viewRef!.context.searchInitialized = this.ctx.searchInitialized; this.viewRef.detectChanges(); } - this.cd.markForCheck(); + this.ctrListCd.markForCheck(); } private getBestMatchIndex() { @@ -188,11 +190,11 @@ export class CtrListDirective implements OnInit, CompleterList { private dataServiceSubscribe() { if (this._dataService) { this._dataService - .catch(err => { + .pipe(catchError(err => { console.error(err); console.error('Unexpected error in dataService: errors should be handled by the dataService Observable'); - return []; - }) + return of([]); + })) .subscribe(results => { this.ctx.searchInitialized = true; this.ctx.searching = false; diff --git a/src/app/edge-completer/directives/ctr-row.directive.ts b/src/app/edge-completer/directives/ctr-row.directive.ts index 6acdab9..fcf18cb 100644 --- a/src/app/edge-completer/directives/ctr-row.directive.ts +++ b/src/app/edge-completer/directives/ctr-row.directive.ts @@ -1,4 +1,4 @@ -import { Directive, ElementRef, Host, HostListener, Input, OnDestroy, Renderer } from '@angular/core'; +import {Directive, ElementRef, Host, HostListener, Input, OnDestroy, Renderer2} from '@angular/core'; import { CtrlDropdownDirective, CtrRowElement, CtrRowItem } from './ctr-dropdown.directive'; import { CompleterItem } from '../shared/completer-item'; @@ -11,7 +11,7 @@ export class CtrRowDirective implements CtrRowElement, OnDestroy { private _rowIndex: number; private _item: CompleterItem; - constructor(private el: ElementRef, private renderer: Renderer, @Host() private dropdown: CtrlDropdownDirective) { } + constructor(private el: ElementRef, private renderer: Renderer2, @Host() private dropdown: CtrlDropdownDirective) { } public ngOnDestroy() { if (this._rowIndex) { @@ -41,7 +41,10 @@ export class CtrRowDirective implements CtrRowElement, OnDestroy { public setHighlighted(selected: boolean) { this.selected = selected; - this.renderer.setElementClass(this.el.nativeElement, 'completer-selected-row', this.selected); + if (this.selected) + this.renderer.addClass(this.el.nativeElement, 'completer-selected-row'); + else + this.renderer.removeClass(this.el.nativeElement, 'completer-selected-row'); } public getNativeElement() { diff --git a/src/app/edge-completer/edge-completer.component.html b/src/app/edge-completer/edge-completer.component.html index be7548a..591ef54 100644 --- a/src/app/edge-completer/edge-completer.component.html +++ b/src/app/edge-completer/edge-completer.component.html @@ -10,6 +10,7 @@
= 10, Chrome >= 55 (including Opera), - * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. - * - * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html - */ - -/*************************************************************************************************** - * BROWSER POLYFILLS - */ - -/** IE9, IE10 and IE11 requires all of the following polyfills. **/ -// import 'core-js/es6/symbol'; -// import 'core-js/es6/object'; -// import 'core-js/es6/function'; -// import 'core-js/es6/parse-int'; -// import 'core-js/es6/parse-float'; -// import 'core-js/es6/number'; -// import 'core-js/es6/math'; -// import 'core-js/es6/string'; -// import 'core-js/es6/date'; -// import 'core-js/es6/array'; -// import 'core-js/es6/regexp'; -// import 'core-js/es6/map'; -// import 'core-js/es6/weak-map'; -// import 'core-js/es6/set'; - -/** IE10 and IE11 requires the following for NgClass support on SVG elements */ -// import 'classlist.js'; // Run `npm install --save classlist.js`. - -/** IE10 and IE11 requires the following for the Reflect API. */ -// import 'core-js/es6/reflect'; - -/** Evergreen browsers require these. **/ -// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. -import 'core-js/es7/reflect'; /** diff --git a/src/tsconfig.spec.json b/src/tsconfig.spec.json index ac22a29..6e51cae 100644 --- a/src/tsconfig.spec.json +++ b/src/tsconfig.spec.json @@ -1,19 +1,20 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "outDir": "../out-tsc/spec", - "baseUrl": "./", - "module": "commonjs", - "types": [ - "jasmine", - "node" - ] - }, - "files": [ - "test.ts" - ], - "include": [ - "**/*.spec.ts", - "**/*.d.ts" - ] -} +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "outDir": "../out-tsc/spec", + "baseUrl": "./", + "module": "commonjs", + "types": [ + "jasmine", + "node" + ] + }, + "files": [ + "test.ts", "polyfills.ts" + + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} diff --git a/tsconfig.json b/tsconfig.json index a6c016b..8cd9a30 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "compileOnSave": false, "compilerOptions": { + "importHelpers": true, "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, @@ -14,6 +15,8 @@ "lib": [ "es2017", "dom" - ] + ], + "module": "es2015", + "baseUrl": "./" } -} +} \ No newline at end of file diff --git a/tslint.json b/tslint.json index c6715a6..1d05771 100644 --- a/tslint.json +++ b/tslint.json @@ -18,7 +18,6 @@ "forin": true, "import-blacklist": [ true, - "rxjs", "rxjs/Rx" ], "import-spacing": true,