diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f95b0b..58b8bda 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,11 +28,16 @@ jobs: cmd: install - name: run - run: | - yarn run test - cat ./coverage/lcov.info | ./node_modules/.bin/codecov - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + run: yarn run test + + - uses: codecov/codecov-action@v3 + name: upload + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: unittests + files: ./coverage/cobertura-coverage.xml + fail_ci_if_error: true + verbose: true lint: runs-on: ubuntu-latest @@ -61,11 +66,11 @@ jobs: - name: build run: | node --max_old_space_size=5120 ./node_modules/@angular/cli/bin/ng build --base-href /ngx-countdown/ - cp ./dist/index.html ./dist/404.html - ls ./dist + cp ./dist/browser/index.html ./dist/browser/404.html + ls ./dist/browser - name: deploy-to-gh-pages uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./dist + publish_dir: ./dist/browser diff --git a/.gitignore b/.gitignore index 7a9d8f0..1f94fbe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,18 @@ # See http://help.github.com/ignore-files/ for more about ignoring files. -# compiled output +# Compiled output /dist /tmp /out-tsc -/publish -/yarn.lock -/.angular/cache +/bazel-out -# dependencies +# Node /node_modules +npm-debug.log +yarn-error.log # IDEs and editors -/.idea +.idea/ .project .classpath .c9/ @@ -20,23 +20,26 @@ .settings/ *.sublime-workspace -# IDE - VSCode +# Visual Studio Code .vscode/* !.vscode/settings.json !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json +.history/* -# misc -/.sass-cache +# Miscellaneous +/.angular/cache +.sass-cache/ /connect.lock /coverage /libpeerconnection.log -npm-debug.log -yarn-error.log testem.log /typings -# System Files +# System files .DS_Store Thumbs.db + +/publish +/yarn.lock diff --git a/.nvmrc b/.nvmrc index 6b17d22..3e558c9 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14.16.1 +18.12.0 diff --git a/README.md b/README.md index e8e5d47..c23e341 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Simple, easy and performance countdown for angular [![NPM version](https://img.shields.io/npm/v/ngx-countdown.svg)](https://www.npmjs.com/package/ngx-countdown) [![Ci](https://github.com/cipchk/ngx-countdown/workflows/Ci/badge.svg)](https://github.com/cipchk/ngx-countdown/actions?query=workflow%3ACi) +[![codecov](https://codecov.io/github/cipchk/ngx-countdown/graph/badge.svg?token=SPQeYvppgH)](https://codecov.io/github/cipchk/ngx-countdown) ## Demo @@ -34,7 +35,7 @@ export class AppModule { } ### 2、Template ```html - + ``` **Method** @@ -54,6 +55,17 @@ export class AppModule { } this.countdown.begin(); ``` +### Standalone + +```ts +@Component({ + template: ``, + standalone: true, + imports: [CountdownComponent], +}) +export class App +``` + ## API ### countdown diff --git a/angular.json b/angular.json index 2168837..e9f97b3 100644 --- a/angular.json +++ b/angular.json @@ -14,15 +14,15 @@ } }, "root": "", - "sourceRoot": "src", + "sourceRoot": "", "prefix": "app", "architect": { "build": { - "builder": "@angular-devkit/build-angular:browser", + "builder": "@angular-devkit/build-angular:application", "options": { "outputPath": "dist", "index": "src/index.html", - "main": "src/main.ts", + "browser": "src/main.ts", "polyfills": [ "zone.js" ], @@ -49,21 +49,12 @@ "maximumError": "4kb" } ], - "fileReplacements": [ - { - "replace": "src/environments/environment.ts", - "with": "src/environments/environment.prod.ts" - } - ], "outputHashing": "all" }, "development": { - "buildOptimizer": false, "optimization": false, - "vendorChunk": true, "extractLicenses": false, - "sourceMap": true, - "namedChunks": true + "sourceMap": true } }, "defaultConfiguration": "production" @@ -72,10 +63,10 @@ "builder": "@angular-devkit/build-angular:dev-server", "configurations": { "production": { - "browserTarget": "ngx-countdown:build:production" + "buildTarget": "ngx-countdown:build:production" }, "development": { - "browserTarget": "ngx-countdown:build:development" + "buildTarget": "ngx-countdown:build:development" } }, "defaultConfiguration": "development" @@ -83,16 +74,14 @@ "test": { "builder": "@angular-devkit/build-angular:karma", "options": { - "main": "lib/test.ts", - "tsConfig": "tsconfig.spec.json", - "karmaConfig": "karma.conf.js", + "karmaConfig": "./karma.conf.js", "polyfills": [ "zone.js", "zone.js/testing" ], + "tsConfig": "tsconfig.spec.json", "include": [ - "../lib/test.ts", - "../lib/**/*.spec.ts" + "lib/**/*.spec.ts" ] } }, @@ -109,11 +98,5 @@ } } } - }, - "defaultProject": "ngx-countdown", - "cli": { - "schematicCollections": [ - "@angular-eslint/schematics" - ] } } diff --git a/karma.conf.js b/karma.conf.js index 5ccad91..91ca45a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,50 +1,51 @@ -// Karma configuration file, see link for more information -// https://karma-runner.github.io/1.0/config/configuration-file.html - -module.exports = function (config) { - config.set({ - basePath: '', - frameworks: ['jasmine', '@angular-devkit/build-angular'], - plugins: [ - require('karma-jasmine'), - require('karma-chrome-launcher'), - require('karma-jasmine-html-reporter'), - require('karma-coverage'), - require('@angular-devkit/build-angular/plugins/karma') - ], - client: { - jasmine: { - // you can add configuration options for Jasmine here - // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html - // for example, you can disable the random execution with `random: false` - // or set a specific seed with `seed: 4321` - }, - clearContext: false // leave Jasmine Spec Runner output visible in browser - }, - jasmineHtmlReporter: { - suppressAll: true // removes the duplicated traces - }, - coverageReporter: { - dir: require('path').join(__dirname, './coverage'), - subdir: '.', - reporters: [ - { type: 'html' }, - { type: 'text-summary' } - ] - }, - reporters: ['progress', 'kjhtml'], - port: 9876, - colors: true, - logLevel: config.LOG_INFO, - autoWatch: true, - browsers: ['Chrome'], - singleRun: false, - restartOnFileChange: true, - customLaunchers: { - ChromeHeadlessCI: { - base: 'ChromeHeadless', - flags: ['--no-sandbox'], - }, - } - }); -}; +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + jasmine: { + // you can add configuration options for Jasmine here + // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html + // for example, you can disable the random execution with `random: false` + // or set a specific seed with `seed: 4321` + }, + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + jasmineHtmlReporter: { + suppressAll: true // removes the duplicated traces + }, + coverageReporter: { + dir: require('path').join(__dirname, './coverage'), + subdir: '.', + reporters: [ + { type: 'html' }, + { type: 'text-summary' }, + { type: 'cobertura' }, + ] + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true, + customLaunchers: { + ChromeHeadlessCI: { + base: 'ChromeHeadless', + flags: ['--no-sandbox'], + }, + } + }); +}; diff --git a/lib/ng-package.json b/lib/ng-package.json index d8154f1..7e477c9 100644 --- a/lib/ng-package.json +++ b/lib/ng-package.json @@ -3,6 +3,6 @@ "dest": "../publish", "deleteDestPath": true, "lib": { - "entryFile": "src/public_api.ts" + "entryFile": "src/public-api.ts" } } diff --git a/lib/package.json b/lib/package.json index 36b822c..f9c84e1 100644 --- a/lib/package.json +++ b/lib/package.json @@ -1,6 +1,6 @@ { "name": "ngx-countdown", - "version": "16.0.0", + "version": "17.0.0", "description": "Simple, easy and performance countdown for angular", "keywords": [ "ngx-countdown", diff --git a/lib/spec/component.spec.ts b/lib/spec/component.spec.ts index 65def45..673f179 100644 --- a/lib/spec/component.spec.ts +++ b/lib/spec/component.spec.ts @@ -77,6 +77,31 @@ describe('Component: ngx-countdown', () => { expect(context.comp.i.text).toBe(`0`); tick(2000); })); + it('Support fractional seconds', fakeAsync(() => { + context.config = { leftTime: 2, format: 'S' }; + fixture.detectChanges(); + tick(250); + fixture.detectChanges(); + expect(context.comp.i.value).toBeGreaterThan(1001); + tick(2000); + })); + it('Pretty text', fakeAsync(() => { + context.config = { leftTime: 2, prettyText: jasmine.createSpy() }; + fixture.detectChanges(); + tick(250); + fixture.detectChanges(); + expect(context.config.prettyText).toHaveBeenCalled(); + tick(2000); + })); + describe('#stopTime', () => { + it('should be working', fakeAsync(() => { + context.config = { stopTime: new Date().getTime() + 1000 * 2 }; + fixture.detectChanges(); + tick(1001); + expect(context.comp.left).toBe(1000); + tick(3000); + })); + }); }); describe('[actions]', () => { diff --git a/lib/src/countdown.component.ts b/lib/src/countdown.component.ts index b5fa0fb..55266e4 100644 --- a/lib/src/countdown.component.ts +++ b/lib/src/countdown.component.ts @@ -20,7 +20,7 @@ import { import { CountdownConfig, CountdownStatus, CountdownEvent, CountdownEventAction, CountdownItem } from './interfaces'; import { CountdownTimer } from './countdown.timer'; import { CountdownGlobalConfig } from './countdown.config'; -import { CommonModule } from '@angular/common'; +import { NgIf, NgTemplateOutlet } from '@angular/common'; @Component({ selector: 'countdown', @@ -28,12 +28,12 @@ import { CommonModule } from '@angular/common'; - + `, host: { '[class.count-down]': 'true' }, encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, - imports: [CommonModule], + imports: [NgIf, NgTemplateOutlet], providers: [CountdownTimer], standalone: true, }) @@ -56,7 +56,7 @@ export class CountdownComponent implements OnInit, OnChanges, OnDestroy { get config(): CountdownConfig { return this._config; } - @Input() render!: TemplateRef<{ $implicit: CountdownItem }>; + @Input() render?: TemplateRef<{ $implicit: CountdownItem }>; @Output() readonly event = new EventEmitter(); constructor( @@ -131,7 +131,6 @@ export class CountdownComponent implements OnInit, OnChanges, OnDestroy { ...defCog, ...this.config, }); - // tslint:disable-next-line: no-bitwise const frq = (this.frequency = ~config.format!.indexOf('S') ? 100 : 1000); this.status = config.demand ? CountdownStatus.pause : CountdownStatus.ing; diff --git a/lib/src/countdown.config.ts b/lib/src/countdown.config.ts index d8af3b0..80d6d98 100644 --- a/lib/src/countdown.config.ts +++ b/lib/src/countdown.config.ts @@ -1,4 +1,3 @@ -// tslint:disable: no-inferrable-types import { Injectable, Inject, LOCALE_ID } from '@angular/core'; import { formatDate } from '@angular/common'; import { CountdownFormatFn, CountdownConfig } from './interfaces'; @@ -17,5 +16,5 @@ export class CountdownGlobalConfig implements CountdownConfig { formatDate?: CountdownFormatFn = ({ date, formatStr, timezone }) => { return formatDate(new Date(date), formatStr, this.locale, timezone || this.timezone || '+0000'); - } + }; } diff --git a/lib/src/index.ts b/lib/src/index.ts index 4aaf8f9..7e1a213 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -1 +1 @@ -export * from './public_api'; +export * from './public-api'; diff --git a/lib/src/public_api.ts b/lib/src/public-api.ts similarity index 100% rename from lib/src/public_api.ts rename to lib/src/public-api.ts diff --git a/lib/test.ts b/lib/test.ts deleted file mode 100644 index 089ddda..0000000 --- a/lib/test.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { getTestBed } from '@angular/core/testing'; -import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; - -getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); diff --git a/lib/tsconfig.lib.json b/lib/tsconfig.lib.json index 72c465b..e09fca8 100644 --- a/lib/tsconfig.lib.json +++ b/lib/tsconfig.lib.json @@ -6,14 +6,14 @@ "inlineSources": true, "declaration": true, "strictFunctionTypes": true, - "stripInternal": true + "stripInternal": true, + "declarationMap": false }, "files": ["./src/countdown.module.ts"], "include": [ "**/*.ts" ], "angularCompilerOptions": { - "enableIvy": true, "compilationMode": "partial" } } diff --git a/package.json b/package.json index ce0892d..118b2fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-countdown", - "version": "16.0.0", + "version": "17.0.0", "description": "Simple, easy and performance countdown for angular", "keywords": [ "ngx-countdown", @@ -22,50 +22,48 @@ }, "homepage": "https://cipchk.github.io/ngx-countdown/", "scripts": { - "analyze": "ng b --stats-json --source-map", "lint": "ng lint", - "test": "ng t --no-progress --browsers=ChromeHeadlessCI --code-coverage --no-watch", + "test": "ng t --no-progress --code-coverage --no-watch --browsers=ChromeHeadless", "build": "node scripts/build.js", - "release:next": "npm run build && cd publish && npm publish --access public --tag next", - "release": "npm run build && cd publish && npm publish --access public" + "release": "npm run build && cd publish && npm publish --access public", + "release:next": "npm run build && cd publish && npm publish --access public --tag next" }, "dependencies": { - "@angular/animations": "^16.0.0", - "@angular/common": "^16.0.0", - "@angular/compiler": "^16.0.0", - "@angular/core": "^16.0.0", - "@angular/forms": "^16.0.0", - "@angular/platform-browser": "^16.0.0", - "@angular/platform-browser-dynamic": "^16.0.0", - "@angular/router": "^16.0.0", + "@angular/animations": "^17.0.0", + "@angular/common": "^17.0.0", + "@angular/compiler": "^17.0.0", + "@angular/core": "^17.0.0", + "@angular/forms": "^17.0.0", + "@angular/platform-browser": "^17.0.0", + "@angular/platform-browser-dynamic": "^17.0.0", + "@angular/router": "^17.0.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", - "zone.js": "~0.13.0", - "bootstrap": "^5.3.0", - "ngx-highlight-js": "^16.0.0", + "zone.js": "~0.14.2", + "bootstrap": "^5.3.2", + "ngx-highlight-js": "^17.0.0", "date-fns": "^2.30.0" }, "devDependencies": { - "@angular-devkit/build-angular": "^16.0.3", - "@angular/cli": "~16.0.3", - "@angular/compiler-cli": "^16.0.0", - "@types/jasmine": "~4.3.0", - "jasmine-core": "~4.6.0", + "@angular-devkit/build-angular": "^17.0.0", + "@angular/cli": "^17.0.0", + "@angular/compiler-cli": "^17.0.0", + "@types/jasmine": "~5.1.0", + "jasmine-core": "~5.1.0", "karma": "~6.4.0", "karma-chrome-launcher": "~3.2.0", "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", - "karma-jasmine-html-reporter": "~2.0.0", - "typescript": "~5.0.2", - "@angular-eslint/builder": "^16.0.3", - "@angular-eslint/eslint-plugin": "^16.0.3", - "@angular-eslint/eslint-plugin-template": "^16.0.3", - "@angular-eslint/schematics": "^16.0.3", - "@angular-eslint/template-parser": "^16.0.3", - "@typescript-eslint/eslint-plugin": "^5.59.8", - "@typescript-eslint/parser": "^5.59.8", - "codecov": "^3.8.3", - "eslint": "^8.42.0", - "ng-packagr": "^16.0.1" + "karma-jasmine-html-reporter": "~2.1.0", + "typescript": "~5.2.2", + "@angular-eslint/builder": "^17.0.0", + "@angular-eslint/eslint-plugin": "^17.0.0", + "@angular-eslint/eslint-plugin-template": "^17.0.0", + "@angular-eslint/schematics": "^17.0.0", + "@angular-eslint/template-parser": "^17.0.0", + "@typescript-eslint/eslint-plugin": "^6.10.0", + "@typescript-eslint/parser": "^6.10.0", + "eslint": "^8.53.0", + "ng-packagr": "^17.0.0" } } diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 1b647c4..324d083 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; +import { RouterOutlet } from '@angular/router'; @Component({ selector: 'app-root', - template: ` - - `, + template: ``, + standalone: true, + imports: [RouterOutlet], }) export class AppComponent {} diff --git a/src/app/app.module.ts b/src/app/app.module.ts deleted file mode 100644 index f20927f..0000000 --- a/src/app/app.module.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { TestComponent } from './components/test.component'; -import { NgModule } from '@angular/core'; -import { FormsModule } from '@angular/forms'; -import { RouterModule } from '@angular/router'; -import { BrowserModule } from '@angular/platform-browser'; -import { CommonModule } from '@angular/common'; -import { HighlightJsModule } from 'ngx-highlight-js'; - -import { CountdownModule, CountdownGlobalConfig, CountdownConfig } from 'ngx-countdown'; - -import { AppComponent } from './app.component'; -import { LayoutComponent } from './components/layout.component'; -import { DemoComponent } from './components/demo.component'; -import { ALotComponent } from './components/alot.component'; -import { NothingComponent } from './components/nothing.component'; -import { OnlySecondsComponent } from './components/only-seconds.component'; -import { ViewCodeComponent } from './components/view-code.component'; -import { MoreThan24HoursComponent } from './components/more-than-24-hours.component'; -import { DatefnsComponent } from './components/date-fns.component'; -import { PrettyTextComponent } from './components/pretty-text.component'; -import { ActionsComponent } from './components/actions.component'; -import { DemandComponent } from './components/demand.component'; -import { CustomFormatDateComponent } from './components/custom-format-date.component'; -import { TimestampComponent } from './components/timestamp.component'; -import { NotifyComponent } from './components/notify.component'; -import { AccuracyComponent } from './components/accuracy.component'; -import { CustomFormatComponent } from './components/custom-format.component'; -import { BasicComponent } from './components/basic.component'; -import { KeepingWhenRefreshComponent } from './components/keeping-when-refresh.component'; -import { StandaloneComponent } from './standalone.component'; - -export function countdownConfigFactory(): CountdownConfig { - return {}; -} - -@NgModule({ - imports: [ - BrowserModule, - FormsModule, - CommonModule, - HighlightJsModule, - RouterModule.forRoot( - [ - { - path: '', - component: LayoutComponent, - children: [ - { path: '', component: DemoComponent }, - { path: 'alot', component: ALotComponent }, - { path: 'nothing', component: NothingComponent }, - { path: 'standalone', component: StandaloneComponent }, - ], - }, - { - path: 'test', - component: TestComponent, - }, - ], - { useHash: true }, - ), - CountdownModule, - ], - declarations: [ - AppComponent, - LayoutComponent, - DemoComponent, - ALotComponent, - NothingComponent, - TestComponent, - ViewCodeComponent, - BasicComponent, - CustomFormatComponent, - AccuracyComponent, - NotifyComponent, - TimestampComponent, - CustomFormatDateComponent, - DemandComponent, - ActionsComponent, - PrettyTextComponent, - DatefnsComponent, - MoreThan24HoursComponent, - OnlySecondsComponent, - KeepingWhenRefreshComponent, - ], - providers: [{ provide: CountdownGlobalConfig, useFactory: countdownConfigFactory }], - bootstrap: [AppComponent], -}) -export class AppDemoModule {} diff --git a/src/app/components/accuracy.component.ts b/src/app/components/accuracy.component.ts index 8de3f1e..4fdc85f 100644 --- a/src/app/components/accuracy.component.ts +++ b/src/app/components/accuracy.component.ts @@ -1,4 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { CountdownComponent } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-accuracy', @@ -16,5 +18,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class AccuracyComponent {} diff --git a/src/app/components/actions.component.ts b/src/app/components/actions.component.ts index 4b36d2f..b0d8e23 100644 --- a/src/app/components/actions.component.ts +++ b/src/app/components/actions.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { CountdownConfig, CountdownEvent } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig, CountdownEvent } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-actions', @@ -24,6 +25,8 @@ import { CountdownConfig, CountdownEvent } from 'ngx-countdown'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class ActionsComponent { config: CountdownConfig = { diff --git a/src/app/components/alot.component.html b/src/app/components/alot.component.html deleted file mode 100644 index 1ad6990..0000000 --- a/src/app/components/alot.component.html +++ /dev/null @@ -1,5 +0,0 @@ -
-
- -
-
diff --git a/src/app/components/alot.component.ts b/src/app/components/alot.component.ts index c0e72a7..202b77e 100644 --- a/src/app/components/alot.component.ts +++ b/src/app/components/alot.component.ts @@ -1,8 +1,17 @@ +import { NgFor } from '@angular/common'; import { Component } from '@angular/core'; +import { CountdownComponent } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-alot', - templateUrl: './alot.component.html', + template: `
+
+ +
+
`, + standalone: true, + imports: [NgFor, CountdownComponent, ViewCodeComponent], }) export class ALotComponent { arr = new Array(1000).fill({}); diff --git a/src/app/components/basic.component.ts b/src/app/components/basic.component.ts index 49c0653..6aef3a4 100644 --- a/src/app/components/basic.component.ts +++ b/src/app/components/basic.component.ts @@ -1,4 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { CountdownComponent } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-basic', @@ -16,5 +18,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class BasicComponent {} diff --git a/src/app/components/custom-format-date.component.ts b/src/app/components/custom-format-date.component.ts index 8bc12cb..8551600 100644 --- a/src/app/components/custom-format-date.component.ts +++ b/src/app/components/custom-format-date.component.ts @@ -1,6 +1,7 @@ import { ChangeDetectionStrategy, Component, Inject, LOCALE_ID } from '@angular/core'; -import { CountdownConfig } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig } from 'ngx-countdown'; import { formatDate } from '@angular/common'; +import { ViewCodeComponent } from './view-code.component'; const MINIUES = 1000 * 60; @@ -20,6 +21,8 @@ const MINIUES = 1000 * 60; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class CustomFormatDateComponent { constructor(@Inject(LOCALE_ID) private locale: string) {} diff --git a/src/app/components/custom-format.component.ts b/src/app/components/custom-format.component.ts index 100f587..cc13391 100644 --- a/src/app/components/custom-format.component.ts +++ b/src/app/components/custom-format.component.ts @@ -1,4 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { CountdownComponent } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-custom-format', @@ -16,5 +18,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class CustomFormatComponent {} diff --git a/src/app/components/date-fns.component.ts b/src/app/components/date-fns.component.ts index b871282..60b7230 100644 --- a/src/app/components/date-fns.component.ts +++ b/src/app/components/date-fns.component.ts @@ -1,6 +1,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { CountdownConfig } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig } from 'ngx-countdown'; import { format } from 'date-fns'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-date-fns', @@ -18,6 +19,8 @@ import { format } from 'date-fns'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class DatefnsComponent { config: CountdownConfig = { diff --git a/src/app/components/demand.component.ts b/src/app/components/demand.component.ts index 5fd5344..3a9952d 100644 --- a/src/app/components/demand.component.ts +++ b/src/app/components/demand.component.ts @@ -1,4 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { CountdownComponent } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-demand', @@ -19,5 +21,7 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class DemandComponent {} diff --git a/src/app/components/demo.component.ts b/src/app/components/demo.component.ts index fea1982..ef8084e 100644 --- a/src/app/components/demo.component.ts +++ b/src/app/components/demo.component.ts @@ -1,4 +1,17 @@ import { Component, ChangeDetectionStrategy } from '@angular/core'; +import { BasicComponent } from './basic.component'; +import { CustomFormatComponent } from './custom-format.component'; +import { AccuracyComponent } from './accuracy.component'; +import { NotifyComponent } from './notify.component'; +import { TimestampComponent } from './timestamp.component'; +import { CustomFormatDateComponent } from './custom-format-date.component'; +import { DemandComponent } from './demand.component'; +import { ActionsComponent } from './actions.component'; +import { DatefnsComponent } from './date-fns.component'; +import { PrettyTextComponent } from './pretty-text.component'; +import { MoreThan24HoursComponent } from './more-than-24-hours.component'; +import { OnlySecondsComponent } from './only-seconds.component'; +import { KeepingWhenRefreshComponent } from './keeping-when-refresh.component'; @Component({ selector: 'demo', @@ -18,5 +31,21 @@ import { Component, ChangeDetectionStrategy } from '@angular/core';
`, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [ + BasicComponent, + CustomFormatComponent, + AccuracyComponent, + NotifyComponent, + TimestampComponent, + CustomFormatDateComponent, + DemandComponent, + ActionsComponent, + DatefnsComponent, + PrettyTextComponent, + MoreThan24HoursComponent, + OnlySecondsComponent, + KeepingWhenRefreshComponent, + ], }) export class DemoComponent {} diff --git a/src/app/components/keeping-when-refresh.component.ts b/src/app/components/keeping-when-refresh.component.ts index c27f10d..db64d57 100644 --- a/src/app/components/keeping-when-refresh.component.ts +++ b/src/app/components/keeping-when-refresh.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; -import { CountdownConfig, CountdownEvent } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig, CountdownEvent } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; const KEY = 'time'; const DEFAULT = 50; @@ -20,6 +21,8 @@ const DEFAULT = 50; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class KeepingWhenRefreshComponent implements OnInit { config: CountdownConfig = { leftTime: DEFAULT, notify: 0 }; diff --git a/src/app/components/layout.component.ts b/src/app/components/layout.component.ts index 17a0d07..ff89a8d 100644 --- a/src/app/components/layout.component.ts +++ b/src/app/components/layout.component.ts @@ -1,4 +1,6 @@ import { Component } from '@angular/core'; +import { RouterLink, RouterOutlet } from '@angular/router'; + @Component({ selector: 'demo-layout', template: ` @@ -26,14 +28,13 @@ import { Component } from '@angular/core'; -

Simple, easy and performance countdown for angular

- + `, + standalone: true, + imports: [RouterOutlet, RouterLink], }) export class LayoutComponent {} diff --git a/src/app/components/more-than-24-hours.component.ts b/src/app/components/more-than-24-hours.component.ts index f69d7d7..202bb68 100644 --- a/src/app/components/more-than-24-hours.component.ts +++ b/src/app/components/more-than-24-hours.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { CountdownConfig } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; const CountdownTimeUnits: Array<[string, number]> = [ ['Y', 1000 * 60 * 60 * 24 * 365], // years @@ -19,7 +20,13 @@ const CountdownTimeUnits: Array<[string, number]> = [
- + +
+ + + + +
`, host: { @@ -27,10 +34,13 @@ const CountdownTimeUnits: Array<[string, number]> = [ '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class MoreThan24HoursComponent { config: CountdownConfig = { - leftTime: 60 * 60 * 25, + leftTime: 60 * 60 * 24 + 3, + format: 'DD HH:mm:ss', formatDate: ({ date, formatStr }) => { let duration = Number(date || 0); @@ -39,6 +49,10 @@ export class MoreThan24HoursComponent { const v = Math.floor(duration / unit); duration -= v * unit; return current.replace(new RegExp(`${name}+`, 'g'), (match: string) => { + // When days is empty + if (name === 'D' && v <= 0) { + return ''; + } return v.toString().padStart(match.length, '0'); }); } diff --git a/src/app/components/nothing.component.html b/src/app/components/nothing.component.html deleted file mode 100644 index cab1630..0000000 --- a/src/app/components/nothing.component.html +++ /dev/null @@ -1,4 +0,0 @@ -

- Since there are no any countdown component on this page, Timer will automatically stop running. -

-

Confirm this and you can observe it in Chrome-Profiles.

diff --git a/src/app/components/nothing.component.ts b/src/app/components/nothing.component.ts index e3197f1..14ec242 100644 --- a/src/app/components/nothing.component.ts +++ b/src/app/components/nothing.component.ts @@ -2,6 +2,7 @@ import { Component } from '@angular/core'; @Component({ selector: 'demo-nothing', - templateUrl: './nothing.component.html', + template: `

Since there are no any countdown component on this page, Timer will automatically stop running.

+

Confirm this and you can observe it in Chrome-Profiles.

`, }) export class NothingComponent {} diff --git a/src/app/components/notify.component.ts b/src/app/components/notify.component.ts index c3810b8..7890c5c 100644 --- a/src/app/components/notify.component.ts +++ b/src/app/components/notify.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { CountdownConfig, CountdownEvent } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig, CountdownEvent } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-notify', @@ -22,6 +23,8 @@ import { CountdownConfig, CountdownEvent } from 'ngx-countdown'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class NotifyComponent { config: CountdownConfig = { leftTime: 10, notify: [2, 5] }; diff --git a/src/app/components/only-seconds.component.ts b/src/app/components/only-seconds.component.ts index 6a65934..c29c29c 100644 --- a/src/app/components/only-seconds.component.ts +++ b/src/app/components/only-seconds.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { CountdownConfig } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-only-seconds', @@ -17,6 +18,8 @@ import { CountdownConfig } from 'ngx-countdown'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class OnlySecondsComponent { config: CountdownConfig = { diff --git a/src/app/components/pretty-text.component.ts b/src/app/components/pretty-text.component.ts index 1698a6a..b7be8a7 100644 --- a/src/app/components/pretty-text.component.ts +++ b/src/app/components/pretty-text.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { CountdownConfig } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-pretty-text', @@ -36,6 +37,8 @@ import { CountdownConfig } from 'ngx-countdown'; `, ], changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class PrettyTextComponent { config: CountdownConfig = { diff --git a/src/app/components/test.component.ts b/src/app/components/test.component.ts index 1a44519..4befbde 100644 --- a/src/app/components/test.component.ts +++ b/src/app/components/test.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; +import { CountdownComponent } from 'ngx-countdown'; @Component({ selector: 'test', - template: ` - - `, + template: ``, + standalone: true, + imports: [CountdownComponent], }) export class TestComponent {} diff --git a/src/app/components/timestamp.component.ts b/src/app/components/timestamp.component.ts index a905f0e..4077f7d 100644 --- a/src/app/components/timestamp.component.ts +++ b/src/app/components/timestamp.component.ts @@ -1,5 +1,6 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { CountdownConfig } from 'ngx-countdown'; +import { CountdownComponent, CountdownConfig } from 'ngx-countdown'; +import { ViewCodeComponent } from './view-code.component'; @Component({ selector: 'demo-timestamp', @@ -21,6 +22,8 @@ import { CountdownConfig } from 'ngx-countdown'; '[class.text-center]': `true`, }, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, + imports: [CountdownComponent, ViewCodeComponent], }) export class TimestampComponent { config: CountdownConfig = { stopTime: new Date().getTime() + 1000 * 30 }; diff --git a/src/app/components/view-code.component.ts b/src/app/components/view-code.component.ts index be48253..c16c6a7 100644 --- a/src/app/components/view-code.component.ts +++ b/src/app/components/view-code.component.ts @@ -6,6 +6,7 @@ import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; (View Code) `, changeDetection: ChangeDetectionStrategy.OnPush, + standalone: true, }) export class ViewCodeComponent { @Input() name = ''; diff --git a/src/app/router.ts b/src/app/router.ts new file mode 100644 index 0000000..fc4602b --- /dev/null +++ b/src/app/router.ts @@ -0,0 +1,22 @@ +import { Route } from '@angular/router'; +import { LayoutComponent } from './components/layout.component'; +import { DemoComponent } from './components/demo.component'; +import { ALotComponent } from './components/alot.component'; +import { NothingComponent } from './components/nothing.component'; +import { TestComponent } from './components/test.component'; + +export const ROUTERS: Route[] = [ + { + path: '', + component: LayoutComponent, + children: [ + { path: '', component: DemoComponent }, + { path: 'alot', component: ALotComponent }, + { path: 'nothing', component: NothingComponent }, + ], + }, + { + path: 'test', + component: TestComponent, + }, +]; diff --git a/src/app/standalone.component.ts b/src/app/standalone.component.ts deleted file mode 100644 index d700561..0000000 --- a/src/app/standalone.component.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Component } from '@angular/core'; -import { CountdownModule } from 'ngx-countdown'; - -@Component({ - selector: 'standalone-demo', - template: ` `, - standalone: true, - imports: [CountdownModule], -}) -export class StandaloneComponent {} diff --git a/src/assets/fork.png b/src/assets/fork.png deleted file mode 100644 index 146ef8a..0000000 Binary files a/src/assets/fork.png and /dev/null differ diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts deleted file mode 100644 index 3612073..0000000 --- a/src/environments/environment.prod.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const environment = { - production: true -}; diff --git a/src/environments/environment.ts b/src/environments/environment.ts deleted file mode 100644 index 00313f1..0000000 --- a/src/environments/environment.ts +++ /dev/null @@ -1,8 +0,0 @@ -// The file contents for the current environment will overwrite these during build. -// The build system defaults to the dev environment which uses `environment.ts`, but if you do -// `ng build --env=prod` then `environment.prod.ts` will be used instead. -// The list of which env maps to which file can be found in `angular-cli.json`. - -export const environment = { - production: false -}; diff --git a/src/index.html b/src/index.html index 814dc8f..50bfd6b 100644 --- a/src/index.html +++ b/src/index.html @@ -19,7 +19,12 @@ Loading... - Fork me on GitHub + Fork me on GitHub diff --git a/src/main.ts b/src/main.ts index 585e297..99f0ac9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,12 +1,18 @@ -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { enableProdMode } from '@angular/core'; -import { environment } from './environments/environment'; -import { AppDemoModule } from './app/app.module'; +import { bootstrapApplication } from '@angular/platform-browser'; +import { AppComponent } from './app/app.component'; +import { provideHttpClient } from '@angular/common/http'; +import { provideRouter, withHashLocation } from '@angular/router'; +import { ROUTERS } from './app/router'; +import { CountdownConfig, CountdownGlobalConfig } from 'ngx-countdown'; -if (environment.production) { - enableProdMode(); +export function countdownConfigFactory(): CountdownConfig { + return {}; } -platformBrowserDynamic() - .bootstrapModule(AppDemoModule) - .catch((err) => console.error(err)); +bootstrapApplication(AppComponent, { + providers: [ + provideHttpClient(), + provideRouter(ROUTERS, withHashLocation()), + { provide: CountdownGlobalConfig, useFactory: countdownConfigFactory }, + ], +}).catch((err) => console.error(err)); diff --git a/tsconfig.app.json b/tsconfig.app.json index 84f1f99..374cc9d 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -5,6 +5,10 @@ "outDir": "./out-tsc/app", "types": [] }, - "files": ["src/main.ts"], - "include": ["src/**/*.d.ts"] + "files": [ + "src/main.ts" + ], + "include": [ + "src/**/*.d.ts" + ] } diff --git a/tsconfig.json b/tsconfig.json index 15292bc..d81c67b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,6 +10,7 @@ "noPropertyAccessFromIndexSignature": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, + "allowSyntheticDefaultImports": true, "sourceMap": true, "declaration": false, "downlevelIteration": true, @@ -24,7 +25,9 @@ "dom" ], "paths": { - "ngx-countdown": ["lib/src/index"] + "ngx-countdown": [ + "lib/src/index" + ] } }, "angularCompilerOptions": { diff --git a/tsconfig.spec.json b/tsconfig.spec.json index a0bad79..57f6f1d 100644 --- a/tsconfig.spec.json +++ b/tsconfig.spec.json @@ -3,8 +3,11 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "./out-tsc/spec", - "types": ["jasmine"] + "types": [ + "jasmine" + ] }, - "files": ["lib/test.ts"], - "include": ["lib/**/*.spec.ts", "lib/**/*.d.ts"] + "include": [ + "lib/**/*.spec.ts" + ] }