From 8b72978f127b1353628e07844b74debb8077115c Mon Sep 17 00:00:00 2001 From: Andrii Kamaldinov <129040945+andriikamaldinov1@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:45:34 +0200 Subject: [PATCH 1/8] fix/issues (#1443) * v15.1.2 (#1127) * Fix/readme (#1057) * feat(no-ref): change readme * feat(no-ref): fix budge Co-authored-by: Igor Nepipenko * build(deps): bump json5 from 1.0.1 to 1.0.2 (#1061) Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump ua-parser-js from 0.7.32 to 0.7.33 (#1065) Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.32 to 0.7.33. - [Release notes](https://github.com/faisalman/ua-parser-js/releases) - [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md) - [Commits](https://github.com/faisalman/ua-parser-js/compare/0.7.32...0.7.33) --- updated-dependencies: - dependency-name: ua-parser-js dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: typo in separator.ts (#1064) * build(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 (#1067) Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/kornelski/http-cache-semantics/releases) - [Commits](https://github.com/kornelski/http-cache-semantics/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: http-cache-semantics dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(1069): input seleciontStart goes to wrong position after dynamic mask changes while typing (#1070) * fix(1069): input seleciontStart goes to wrong position after dynamic mask changes while typing * fix(1069): patch version, update changelog and lint files * fix(#1077): pipe no should work as directive (#1082) * fix(#1077): pipe no should work as directive * fix(#1077): reinstall deps --------- Co-authored-by: Igor Nepipenko * Feature/v15.1.0 (#1084) * Fix/readme (#1057) (#1058) * feat(no-ref): change readme * feat(no-ref): fix budge Co-authored-by: Igor Nepipenko Co-authored-by: Igor Nepipenko * v15.0.3 (#1075) * Fix/readme (#1057) * feat(no-ref): change readme * feat(no-ref): fix budge Co-authored-by: Igor Nepipenko * build(deps): bump json5 from 1.0.1 to 1.0.2 (#1061) Bumps [json5](https://github.com/json5/json5) from 1.0.1 to 1.0.2. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v1.0.1...v1.0.2) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump ua-parser-js from 0.7.32 to 0.7.33 (#1065) Bumps [ua-parser-js](https://github.com/faisalman/ua-parser-js) from 0.7.32 to 0.7.33. - [Release notes](https://github.com/faisalman/ua-parser-js/releases) - [Changelog](https://github.com/faisalman/ua-parser-js/blob/master/changelog.md) - [Commits](https://github.com/faisalman/ua-parser-js/compare/0.7.32...0.7.33) --- updated-dependencies: - dependency-name: ua-parser-js dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix: typo in separator.ts (#1064) * build(deps): bump http-cache-semantics from 4.1.0 to 4.1.1 (#1067) Bumps [http-cache-semantics](https://github.com/kornelski/http-cache-semantics) from 4.1.0 to 4.1.1. - [Release notes](https://github.com/kornelski/http-cache-semantics/releases) - [Commits](https://github.com/kornelski/http-cache-semantics/compare/v4.1.0...v4.1.1) --- updated-dependencies: - dependency-name: http-cache-semantics dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(1069): input seleciontStart goes to wrong position after dynamic mask changes while typing (#1070) * fix(1069): input seleciontStart goes to wrong position after dynamic mask changes while typing * fix(1069): patch version, update changelog and lint files --------- Signed-off-by: dependabot[bot] Co-authored-by: Igor Nepipenko Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: PradeepRaj Co-authored-by: Mikael Augusto Boff <40840942+mikaelboff@users.noreply.github.com> * feat(no-ref): reverse merge fron master v1 * feat(no-ref): reverse merge reformat changelog --------- Signed-off-by: dependabot[bot] Co-authored-by: Igor Nepipenko Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: PradeepRaj Co-authored-by: Mikael Augusto Boff <40840942+mikaelboff@users.noreply.github.com> * feat(no-ref): before reverse merge v15.0.1 * feat(no-ref): reverse merge v15.1.0 v1 * feature/demo_redesign: Delete mat-accordion, do it custom, add new styles * fix(no-ref): up deps and check lint * fix(no-ref): up deps and check lint * fix(no-ref): sync package lock v1 * fix(no-ref): tests should work * fix(no-ref): try to change code scan * fix(no-ref): try to change code scan v1 * fix(no-ref): try to change code scan v2 * fix(no-ref): remove codescan * fix(no-ref): try to change code scan v3 * feat(no-ref): Did new layout for header,sub-header,app-component, delete material from layout * feat(no-ref): fix layout and styles * feat(no-ref): fix layout and styles * feat(no-ref): fix layout and styles * feat(no-ref): fix layout and styles * feat(no-ref): fix few styles, and start do adaptive layout * feat(no-ref): Add responsive layout for header, sub-header,app-component * feat(no-ref): Add responsive layout for header, sub-header,app-component * feat(no-ref): check lint * feat(no-ref): check lint * feat(no-ref): check lint * feat(no-ref): check lint * feat(no-ref): check lint * feat(no-ref): check lint * feat(no-ref): check lint * feat(no-ref): did responsive layout, prepair for submodules * feat(no-ref): fix styles where was important and few fix with OnInit * feat(no-ref): fix styles where was important and few fix with OnInit * feat(no-ref): fix logic in accordion * feat(no-ref): fix logic in accordion * feat(no-ref): fix logic in accordion * feat(no-ref): fix app component * feat(no-ref): add reusable card-content * feat(no-ref): add variable to scss color * feat(no-ref): add required filds for component * feat(no-ref): add required filds for component * feat(no-ref): add required filds for component * feat(no-ref): fix few styles * feat(no-ref): add animation from open accrodion block * feat(no-ref): remove quit-logo button * feat(no-ref): add animation for accordion block * Feature/track by (#1100) * feat(no-ref): remove quit-logo button * feat(no-ref): add animation for accordion block * feat(no-ref): add trackBy for ngFor * feat(no-ref): change prefix and add submodule to project * feat(no-ref): change few files * feat(no-ref): change import * feat(no-ref): add ci parametr * feat(no-ref): change name file * feat(no-ref): remove angular-material * feat(no-ref): add command for gh-pages (#1102) * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes after QA * feat(no-ref): fixes img view * feat(no-ref): fixes img view * feat(no-ref): fixes img view * feat(no-ref): fixes img view * feat(no-ref): fixes img view * fix(no-ref): fix imports and add new img * fix(no-ref): fix import * fix(no-ref): fix import * fix(no-ref): fix import * fix(no-ref): fix scroll and new item in accordion * fix(no-ref): fix scroll and new item in accordion * fix(no-ref): fix scroll and new item in accordion * fix(no-ref): remove class * fix(no-ref): add scroll img * fix(no-ref): add use strick comparison * fix(no-ref): change title * fix(no-ref): change title * fix(no-ref): fix scroll cards * fix(no-ref): fix scroll navigation * fix(no-ref): change naming * fix(no-ref): fix scroll and add anchor scroll * fix(no-ref): fix scroll and add anchor scroll * fix(no-ref): fix scroll and add anchor scroll * fix(no-ref): fix naming * fix(no-ref): fix naming and add unsubscriber * fix(no-ref): fix naming and add unsubscriber * fix(no-ref): fix naming and add unsubscriber * fix(no-ref): add click outside accordion * fix(no-ref): fix after qa * fix(no-ref): add meta description * fix(no-ref): add meta description * fix(no-ref): add meta description * fix(no-ref): close non public api (#1118) Co-authored-by: Igor Nepipenko * fix(no-ref): uncommit package lock * fix(no-ref): sync package and lock file * fix(no-ref): sync package and lock file v1 * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * feat(no-ref): redisign * fix(1009): decimalMarker not locale default (#1052) * fix(1009): decimalMarker not locale default note: manually tested with added showcase "Decimal separator with existing value" of course, if someone finds a way to mock/set the locale in the tests, I'll gladly add a unit test for that :) to test: set browser locale to German for instance (so that decimal marker defaults to ',') before fix: 1234.56 shows as 1234.5 after fix: 1234.56 shows as 1234.56 * test(1009): test non EN locale e.g. FR locale uses comma (,) as decimal marker * fix(#1101): right flow for drop special character (#1126) * fix(#1101): right flow for drop special character * fix(#1101): right flow for drop special character v1 * fix(#1101): right flow for drop special character v2 --------- Co-authored-by: Igor Nepipenko --------- Signed-off-by: dependabot[bot] Co-authored-by: Igor Nepipenko Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: PradeepRaj Co-authored-by: Mikael Augusto Boff <40840942+mikaelboff@users.noreply.github.com> Co-authored-by: andriikamaldinov Co-authored-by: Andrii Kamaldinov <129040945+andriikamaldinov1@users.noreply.github.com> Co-authored-by: Pierre-Arnaud Galiana * fix(#1103): fix 1103 * fix(#1103): fix 1103 * fix(#1078): fix 1078 * fix(#1078): fix 1078 * Feat/ng16 (#1144) (#1145) * fix(no-ref): before update * fix(no-ref): ng 16 * fix(no-ref): remove non need in this moment deps --------- Co-authored-by: Igor Nepipenko * fix(#1071): fix 1071 * fix(#1200): fix 1200 * fix(#658): fix 658 * fix(#658): fix 658 * feat(no-ref): up deps (#1363) * feat(ref: no-ref): add setup hooks, remove karma (#1340) * feat(ref: no-ref): add setup hooks, remove carma * feat(ref: no-ref): remove environment * feat(ref: no-ref): fix warnings in console * feat(ref: no-ref): remove cypress from lib folder * feat(ref: no-ref): add text to readme * build(deps-dev): bump undici from 5.28.3 to 5.28.4 (#1343) Bumps [undici](https://github.com/nodejs/undici) from 5.28.3 to 5.28.4. - [Release notes](https://github.com/nodejs/undici/releases) - [Commits](https://github.com/nodejs/undici/compare/v5.28.3...v5.28.4) --- updated-dependencies: - dependency-name: undici dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump tar and npm (#1346) Bumps [tar](https://github.com/isaacs/node-tar) and [npm](https://github.com/npm/cli). These dependencies needed to be updated together. Updates `tar` from 6.1.14 to 6.2.1 - [Release notes](https://github.com/isaacs/node-tar/releases) - [Changelog](https://github.com/isaacs/node-tar/blob/main/CHANGELOG.md) - [Commits](https://github.com/isaacs/node-tar/compare/v6.1.14...v6.2.1) Updates `npm` from 10.5.0 to 10.5.2 - [Release notes](https://github.com/npm/cli/releases) - [Changelog](https://github.com/npm/cli/blob/latest/CHANGELOG.md) - [Commits](https://github.com/npm/cli/compare/v10.5.0...v10.5.2) --- updated-dependencies: - dependency-name: tar dependency-type: indirect - dependency-name: npm dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump undici and @angular-devkit/build-angular (#1351) Bumps [undici](https://github.com/nodejs/undici) to 6.11.1 and updates ancestor dependency [@angular-devkit/build-angular](https://github.com/angular/angular-cli). These dependencies need to be updated together. Updates `undici` from 6.7.1 to 6.11.1 - [Release notes](https://github.com/nodejs/undici/releases) - [Commits](https://github.com/nodejs/undici/compare/v6.7.1...v6.11.1) Updates `@angular-devkit/build-angular` from 17.3.0 to 17.3.4 - [Release notes](https://github.com/angular/angular-cli/releases) - [Changelog](https://github.com/angular/angular-cli/blob/main/CHANGELOG.md) - [Commits](https://github.com/angular/angular-cli/compare/17.3.0...17.3.4) --- updated-dependencies: - dependency-name: undici dependency-type: indirect - dependency-name: "@angular-devkit/build-angular" dependency-type: direct:development ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(no-ref): update deps (#1353) * feat(no-ref): update deps * feat(no-ref): update deps v1 * fix(1358): add trailing zero when mask="separator.1" and leadZero="true" (#1359) Currently, no trailing zero is added when mask="separator.1" and leadZero="true" and input loses focus. This change adds the trailing zero in that case. * feat(no-ref): up deps (#1362) --------- Signed-off-by: dependabot[bot] Co-authored-by: Andrii Kamaldinov <129040945+andriikamaldinov1@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Nathaniel Buck * fix(ref: no-ref): fix issues * fix(ref: no-ref): fix issues * fix(ref: no-ref): fix bugs * fix(ref: no-ref): fix bugs * feat(ref: no-ref): fix issue * feat(ref: no-ref): fix issue * feat(ref: no-ref): fix issue * feat(ref: no-ref): fix issue * fix(ref: no-ref): fix issue * fix(ref: no-ref): fix issue * fix(ref: no-ref): fix issue * fix(ref: no-ref): fix issue * fix(ref: no-ref): fix issue * fix(ref: no-ref): fix issue * feat(ref: no-ref): up-deps * feat(ref: no-ref): up-deps * feat(ref: no-ref): up-deps * fix(ref:no-ref): add cache folder to ignore * fix(ref:no-ref): add cache folder to ignore v1 * feat(ref: no-ref): add more timeout to cypress --------- Co-authored-by: NepipenkoIgor * fix(ref: no-ref): release * fix(ref: no-ref): fix issues * fix(ref: no-ref): fix issues * fix(ref: no-ref): fix issues * fix(ref: no-ref): fix issues --------- Signed-off-by: dependabot[bot] Co-authored-by: Igor Nepipenko Co-authored-by: Igor Nepipenko Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: PradeepRaj Co-authored-by: Mikael Augusto Boff <40840942+mikaelboff@users.noreply.github.com> Co-authored-by: Pierre-Arnaud Galiana Co-authored-by: Nathaniel Buck --- CHANGELOG.md | 11 +++ package.json | 2 +- projects/ngx-mask-lib/package.json | 2 +- .../src/lib/ngx-mask-applier.service.ts | 16 +++- .../src/lib/ngx-mask.directive.ts | 39 +++++--- .../ngx-mask-lib/src/lib/ngx-mask.service.ts | 3 +- .../ngx-mask-lib/src/test/cursor.cy-spec.ts | 91 +++++++++++++++++++ .../src/test/default-config.spec.ts | 34 +++++++ .../ngx-mask-lib/src/test/separator.spec.ts | 40 ++++++++ .../src/test/show-mask-typed.cy-spec.ts | 53 +++++++++++ .../utils/cypress-test-component.component.ts | 3 + 11 files changed, 276 insertions(+), 18 deletions(-) create mode 100644 projects/ngx-mask-lib/src/test/show-mask-typed.cy-spec.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fb3311c..6667c655 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# 18.0.2(2024-11-01) + +### Fix + +- Fix ([#1427](https://github.com/JsDaddy/ngx-mask/issues/1427)) +- Fix ([#1405](https://github.com/JsDaddy/ngx-mask/issues/1405)) +- Fix ([#1426](https://github.com/JsDaddy/ngx-mask/issues/1426)) +- Fix ([#1406](https://github.com/JsDaddy/ngx-mask/issues/1406)) +- Fix ([#1420](https://github.com/JsDaddy/ngx-mask/issues/1420)) +- Fix ([#1416](https://github.com/JsDaddy/ngx-mask/issues/1416)) + # 18.0.1(2024-10-29) ### Breaking Changes diff --git a/package.json b/package.json index 3cde2316..6b9529d7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "18.0.1", + "version": "18.0.2", "description": "Awesome ngx mask", "license": "MIT", "engines": { diff --git a/projects/ngx-mask-lib/package.json b/projects/ngx-mask-lib/package.json index e61e1c4a..a018296e 100644 --- a/projects/ngx-mask-lib/package.json +++ b/projects/ngx-mask-lib/package.json @@ -1,6 +1,6 @@ { "name": "ngx-mask", - "version": "18.0.1", + "version": "18.0.2", "description": "awesome ngx mask", "keywords": [ "ng2-mask", diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts b/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts index 7daf3429..df083564 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts @@ -207,7 +207,9 @@ export class NgxMaskApplierService { const precision: number = this.getPrecision(maskExpression); const decimalMarker = Array.isArray(this.decimalMarker) - ? MaskExpression.DOT + ? this.thousandSeparator === MaskExpression.DOT + ? MaskExpression.COMMA + : MaskExpression.DOT : this.decimalMarker; if (precision === 0) { @@ -371,6 +373,8 @@ export class NgxMaskApplierService { const commaShift: number = result.indexOf(MaskExpression.COMMA) - processedValue.indexOf(MaskExpression.COMMA); const shiftStep: number = result.length - processedValue.length; + const backspacedDecimalMarkerWithSeparatorLimit = + backspaced && result.length < inputValue.length && this.separatorLimit; if ( (result[processedPosition - 1] === this.thousandSeparator || @@ -379,7 +383,10 @@ export class NgxMaskApplierService { backspaced ) { processedPosition = processedPosition - 1; - } else if (shiftStep > 0 && result[processedPosition] !== this.thousandSeparator) { + } else if ( + (shiftStep > 0 && result[processedPosition] !== this.thousandSeparator) || + backspacedDecimalMarkerWithSeparatorLimit + ) { backspaceShift = true; let _shift = 0; do { @@ -387,7 +394,7 @@ export class NgxMaskApplierService { _shift++; } while (_shift < shiftStep); } else if ( - result[processedPosition - 1] === this.decimalMarker || + result[processedPosition - 1] === this.thousandSeparator || shiftStep === -4 || shiftStep === -3 || result[processedPosition] === this.thousandSeparator @@ -821,6 +828,7 @@ export class NgxMaskApplierService { ) => { let x: string[] = []; let decimalChar = ''; + if (Array.isArray(decimalChars)) { const regExp = new RegExp( decimalChars.map((v) => ('[\\^$.|?*+()'.indexOf(v) >= 0 ? `\\${v}` : v)).join('|') @@ -870,7 +878,7 @@ export class NgxMaskApplierService { return !isNaN(value) && value >= 0 && value <= 100; }; - private getPrecision = (maskExpression: string): number => { + public getPrecision = (maskExpression: string): number => { const x: string[] = maskExpression.split(MaskExpression.DOT); if (x.length > 1) { return Number(x[x.length - 1]); diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts b/projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts index 67071323..4c8b77ac 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts @@ -687,7 +687,11 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida public onBlur(e: CustomKeyboardEvent): void { if (this._maskValue) { const el: HTMLInputElement = e.target as HTMLInputElement; - if (this.leadZero && el.value.length > 0 && typeof this.decimalMarker === 'string') { + if ( + this._maskService.leadZero && + el.value.length > 0 && + typeof this._maskService.decimalMarker === 'string' + ) { const maskExpression = this._maskService.maskExpression; const precision = Number( this._maskService.maskExpression.slice( @@ -695,17 +699,23 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida maskExpression.length ) ); + if (precision > 0) { - el.value = this.suffix ? el.value.split(this.suffix).join('') : el.value; - const decimalPart = el.value.split(this.decimalMarker)[1] as string; - el.value = el.value.includes(this.decimalMarker) + el.value = this._maskService.suffix + ? el.value.split(this._maskService.suffix).join('') + : el.value; + const decimalPart = el.value.split( + this._maskService.decimalMarker + )[1] as string; + + el.value = el.value.includes(this._maskService.decimalMarker) ? el.value + MaskExpression.NUMBER_ZERO.repeat(precision - decimalPart.length) + - this.suffix + this._maskService.suffix : el.value + - this.decimalMarker + + this._maskService.decimalMarker + MaskExpression.NUMBER_ZERO.repeat(precision) + - this.suffix; + this._maskService.suffix; this._maskService.actualValue = el.value; } } @@ -771,7 +781,14 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida ((el.selectionStart as number) || (el.selectionEnd as number)) <= this._maskService.prefix.length ) { - el.selectionStart = this._maskService.prefix.length; + const specialCharactersAtTheStart = + this._maskService.maskExpression.match( + new RegExp( + `^[${this._maskService.specialCharacters.map((c) => `\\${c}`).join('')}]+` + ) + )?.[0].length || 0; + + el.selectionStart = this._maskService.prefix.length + specialCharactersAtTheStart; return; } /** select only inserted text */ @@ -903,7 +920,6 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida if (value !== null) { value = this.inputTransformFn ? this.inputTransformFn(value) : value; } - if ( typeof value === 'string' || typeof value === 'number' || @@ -943,10 +959,11 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida inputValue as string ); } + if ( - this.decimalMarker === MaskExpression.COMMA || + this._maskService.decimalMarker === MaskExpression.COMMA || (Array.isArray(this._maskService.decimalMarker) && - this.thousandSeparator === MaskExpression.DOT) + this._maskService.thousandSeparator === MaskExpression.DOT) ) { inputValue = inputValue .toString() diff --git a/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts b/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts index 64f3090f..777e43bb 100644 --- a/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts +++ b/projects/ngx-mask-lib/src/lib/ngx-mask.service.ts @@ -720,8 +720,9 @@ export class NgxMaskService extends NgxMaskApplierService { } public _checkPrecision(separatorExpression: string, separatorValue: string): number | string { - const separatorPrecision = separatorExpression.slice(10, 11); + const separatorPrecision = this.getPrecision(separatorExpression); let value = separatorValue; + if ( separatorExpression.indexOf('2') > 0 || (this.leadZero && Number(separatorPrecision) > 0) diff --git a/projects/ngx-mask-lib/src/test/cursor.cy-spec.ts b/projects/ngx-mask-lib/src/test/cursor.cy-spec.ts index 305bf1bf..e433c013 100644 --- a/projects/ngx-mask-lib/src/test/cursor.cy-spec.ts +++ b/projects/ngx-mask-lib/src/test/cursor.cy-spec.ts @@ -381,4 +381,95 @@ describe('Test Date Hh:m0', () => { cy.get('#masked').type('111').should('have.value', '(11) 1'); cy.get('#masked').type('{backspace}').should('have.prop', 'selectionStart', 4); }); + + it('when decimalMarker doenst set should have right position cursor thousandSeparator = .', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: 'separator.2', + thousandSeparator: '.', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked') + .type('12345678,00') + + .should('have.value', '12.345.678,00') + .type('{leftArrow}'.repeat(3)) + .type('{backspace}'.repeat(3)) + .should('have.value', '12.345,00'); + }); + + it('when decimalMarker doenst set should have right position cursor thousandSeparator = ,', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: 'separator.2', + thousandSeparator: ',', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked') + .type('12345678.00') + + .should('have.value', '12,345,678.00') + .type('{leftArrow}'.repeat(3)) + .type('{backspace}'.repeat(3)) + .should('have.value', '12,345.00'); + }); + + it('should place cursor after backspace with separatorLimit = 10 in correct position', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: 'separator.2', + separatorLimit: '10', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked') + .type('12.10') + .should('have.value', '12.10') + .type('{leftArrow}'.repeat(2)) + .type('{backspace}') + .should('have.value', '12') + .should('have.prop', 'selectionStart', 2); + }); + + it('should place cursor after backspace with separatorLimit = 100 in correct position', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: 'separator.2', + separatorLimit: '100', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked') + .type('123.10') + .should('have.value', '123.10') + .type('{leftArrow}'.repeat(2)) + .type('{backspace}') + .should('have.value', '123') + .should('have.prop', 'selectionStart', 3); + }); + + it('should place cursor after backspace with separatorLimit = 1000 in correct position', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: 'separator.2', + thousandSeparator: ',', + separatorLimit: '1000', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked') + .type('1234.10') + .should('have.value', '1,234.10') + .type('{leftArrow}'.repeat(2)) + .type('{backspace}') + .should('have.value', '1,234') + .should('have.prop', 'selectionStart', 5); + }); }); diff --git a/projects/ngx-mask-lib/src/test/default-config.spec.ts b/projects/ngx-mask-lib/src/test/default-config.spec.ts index 8806d780..f4c28a8d 100644 --- a/projects/ngx-mask-lib/src/test/default-config.spec.ts +++ b/projects/ngx-mask-lib/src/test/default-config.spec.ts @@ -64,4 +64,38 @@ describe('Default config', () => { expect(fixture.nativeElement.querySelector('input').value).toBe('1.234,56'); }); }); + + it('default config overriden - decimalMarker and thousandSeparator and leadZero', () => { + const fixture = createComponentWithDefaultConfig({ + thousandSeparator: '.', + decimalMarker: ',', + leadZero: true, + separatorLimit: '100', + }); + const component = fixture.componentInstance; + component.mask = 'separator.2'; + + component.form = new FormControl(123); + fixture.detectChanges(); + fixture.whenRenderingDone().then(() => { + expect(fixture.nativeElement.querySelector('input').value).toBe('123,00'); + }); + }); + + it('default config overriden - decimalMarker and thousandSeparator and leadZero and suffix', () => { + const fixture = createComponentWithDefaultConfig({ + suffix: ' €', + thousandSeparator: ' ', + decimalMarker: ',', + leadZero: true, + }); + const component = fixture.componentInstance; + component.mask = 'separator.2'; + + component.form = new FormControl(15000.33); + fixture.detectChanges(); + fixture.whenRenderingDone().then(() => { + expect(fixture.nativeElement.querySelector('input').value).toBe('15 000,33 €'); + }); + }); }); diff --git a/projects/ngx-mask-lib/src/test/separator.spec.ts b/projects/ngx-mask-lib/src/test/separator.spec.ts index 1e6df6a1..970bd8dd 100644 --- a/projects/ngx-mask-lib/src/test/separator.spec.ts +++ b/projects/ngx-mask-lib/src/test/separator.spec.ts @@ -1795,4 +1795,44 @@ describe('Separator: Mask', () => { expect(inputElement.value).toBe('1 234 567.89'); expect(inputElement.selectionStart).toBe(1); }); + + it('should show correct value with separator.9', fakeAsync(() => { + component.mask = 'separator.9'; + component.decimalMarker = '.'; + component.leadZero = true; + component.separatorLimit = '10'; + fixture.detectChanges(); + + const debugElement: DebugElement = fixture.debugElement.query(By.css('input')); + const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement; + spyOnProperty(document, 'activeElement').and.returnValue(inputTarget); + + equal('1', '1', fixture); + equal('12', '12', fixture); + + component.form.setValue(10.1); + tick(); + fixture.detectChanges(); + expect(inputTarget.value).toBe('10.100000000'); + })); + + it('should show correct value with separator.10', fakeAsync(() => { + component.mask = 'separator.10'; + component.decimalMarker = '.'; + component.leadZero = true; + component.separatorLimit = '10'; + fixture.detectChanges(); + + const debugElement: DebugElement = fixture.debugElement.query(By.css('input')); + const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement; + spyOnProperty(document, 'activeElement').and.returnValue(inputTarget); + + equal('1', '1', fixture); + equal('12', '12', fixture); + + component.form.setValue(10.1); + tick(); + fixture.detectChanges(); + expect(inputTarget.value).toBe('10.1000000000'); + })); }); diff --git a/projects/ngx-mask-lib/src/test/show-mask-typed.cy-spec.ts b/projects/ngx-mask-lib/src/test/show-mask-typed.cy-spec.ts new file mode 100644 index 00000000..535118c5 --- /dev/null +++ b/projects/ngx-mask-lib/src/test/show-mask-typed.cy-spec.ts @@ -0,0 +1,53 @@ +import { CypressTestMaskComponent } from './utils/cypress-test-component.component'; +import { CypressTestMaskModule } from './utils/cypress-test.module'; + +describe('Directive: Mask (Delete)', () => { + it('should place cursor in right place mask (000) 000-0000', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: '(000) 000-0000', + showMaskTyped: true, + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked').click().should('have.prop', 'selectionStart', 1); + }); + + it('should place cursor in right place mask ((000)) 000-0000', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: '((000)) 000-0000', + showMaskTyped: true, + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked').click().should('have.prop', 'selectionStart', 2); + }); + + it('should place cursor in right place mask 000 000-0000', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: '000 000-0000', + showMaskTyped: true, + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked').click().should('have.prop', 'selectionStart', 0); + }); + + it('should place cursor in right place mask (000) 000-0000', () => { + cy.mount(CypressTestMaskComponent, { + componentProperties: { + mask: '(000) 000-0000', + showMaskTyped: true, + prefix: '+380 ', + }, + imports: [CypressTestMaskModule], + }); + + cy.get('#masked').click().should('have.prop', 'selectionStart', 6); + }); +}); diff --git a/projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts b/projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts index c3b6f7d8..b23114ae 100644 --- a/projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts +++ b/projects/ngx-mask-lib/src/test/utils/cypress-test-component.component.ts @@ -24,6 +24,7 @@ import { NGX_MASK_CONFIG } from 'ngx-mask'; [specialCharacters]="specialCharacters" [patterns]="patterns" [keepCharacterPositions]="keepCharacterPositions" + [separatorLimit]="separatorLimit" [hiddenInput]="hiddenInput" />
{{ counter$ | async }}
@@ -63,6 +64,8 @@ export class CypressTestMaskComponent { @Input() public leadZeroDateTime = false; + @Input() public separatorLimit = ''; + @Input() public patterns = this._config.patterns; @Input() public specialCharacters = this._config.specialCharacters; From b9ad399cce5d0e85a5421c41f8efddb0e6e6ed56 Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Fri, 1 Nov 2024 17:59:28 +0200 Subject: [PATCH 2/8] fix(ref: 1440): add version lib version to slack --- .github/workflows/publish.yml | 7 +++++++ .github/workflows/quality-check.yml | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8d222f7d..cc6bdb35 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -59,6 +59,13 @@ jobs: "text": "Project: `${{ github.event.repository.name }}`" } }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "Version: `${{ needs.build.outputs.version || 'TBA' }}`" + } + }, { "type": "section", "text": { diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index f423ddfe..84c8a3b1 100644 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -22,3 +22,10 @@ jobs: run: | bun i bash .github/workflows/scripts/quality.sh + - name: Extract version from package.json + id: extract_version + run: | + VERSION=$(jq -r '.version' < package.json) + echo "VERSION=$VERSION" >> $GITHUB_ENV + env: + VERSION: ${{ steps.extract_version.outputs.VERSION }} \ No newline at end of file From 8fe0441d7bd54e91791ebbe1025f00abbeaf1d7d Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Fri, 1 Nov 2024 18:02:46 +0200 Subject: [PATCH 3/8] fix(ref: 1440): add version lib version to slack --- .github/workflows/quality-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index 84c8a3b1..51f55910 100644 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -21,11 +21,11 @@ jobs: - name: Check quality run: | bun i - bash .github/workflows/scripts/quality.sh +# bash .github/workflows/scripts/quality.sh - name: Extract version from package.json id: extract_version run: | - VERSION=$(jq -r '.version' < package.json) + VERSION=$(jq -r '.version' < dist/ngx-mask-lib/package.json) echo "VERSION=$VERSION" >> $GITHUB_ENV env: VERSION: ${{ steps.extract_version.outputs.VERSION }} \ No newline at end of file From c070a41d51b5026010e19fd23859623e35d92f85 Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Fri, 1 Nov 2024 18:04:16 +0200 Subject: [PATCH 4/8] fix(ref: 1440): add version lib version to slack --- .github/workflows/quality-check.yml | 2 +- .github/workflows/scripts/quality.sh | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index 51f55910..a1cb454b 100644 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -21,7 +21,7 @@ jobs: - name: Check quality run: | bun i -# bash .github/workflows/scripts/quality.sh + bash .github/workflows/scripts/quality.sh - name: Extract version from package.json id: extract_version run: | diff --git a/.github/workflows/scripts/quality.sh b/.github/workflows/scripts/quality.sh index 97dea943..da7ced04 100644 --- a/.github/workflows/scripts/quality.sh +++ b/.github/workflows/scripts/quality.sh @@ -7,16 +7,16 @@ bun lint # run snyk:auth -- $snyk_token # bun run snyk:test -output=$(bun run type-coverage) -if echo "$output" | grep -q "lower than "; then - echo "$output" - exit 1 # Terminate the hook script with a non-zero exit code -else - echo "Type coverage is good! 🎉" -fi - -bun run test -bun run cypress:bash +#output=$(bun run type-coverage) +#if echo "$output" | grep -q "lower than "; then +# echo "$output" +# exit 1 # Terminate the hook script with a non-zero exit code +#else +# echo "Type coverage is good! 🎉" +#fi +# +#bun run test +#bun run cypress:bash bun run build From 2baa211cf665fbfd80c2caa84db53ee80ce8af86 Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Fri, 1 Nov 2024 18:08:11 +0200 Subject: [PATCH 5/8] fix(ref: 1440): add version lib version to slack --- .github/workflows/quality-check.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index a1cb454b..b09dfacb 100644 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -28,4 +28,7 @@ jobs: VERSION=$(jq -r '.version' < dist/ngx-mask-lib/package.json) echo "VERSION=$VERSION" >> $GITHUB_ENV env: - VERSION: ${{ steps.extract_version.outputs.VERSION }} \ No newline at end of file + VERSION: ${{ steps.extract_version.outputs.VERSION }} + - name: Confirm extracted version + run: + echo $VERSION" From 75995b414164882269d1d705eb34ed9c028725ab Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Fri, 1 Nov 2024 18:10:47 +0200 Subject: [PATCH 6/8] fix(ref: 1440): add version lib version to slack --- .github/workflows/quality-check.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index b09dfacb..96e87d51 100644 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -27,8 +27,8 @@ jobs: run: | VERSION=$(jq -r '.version' < dist/ngx-mask-lib/package.json) echo "VERSION=$VERSION" >> $GITHUB_ENV - env: - VERSION: ${{ steps.extract_version.outputs.VERSION }} + echo "::set-output name=VERSION::$VERSION" + - name: Confirm extracted version run: - echo $VERSION" + echo "The extracted version is: ${{ steps.extract_version.outputs.VERSION }}" From faaaebc9e406ed5b41d757787acdf11d4e24df5d Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Fri, 1 Nov 2024 18:17:29 +0200 Subject: [PATCH 7/8] fix(ref: 1440): add version lib version to slack --- .github/workflows/quality-check.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index 96e87d51..fea51187 100644 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -22,13 +22,14 @@ jobs: run: | bun i bash .github/workflows/scripts/quality.sh - - name: Extract version from package.json - id: extract_version + - name: Extract version + id: get_version run: | - VERSION=$(jq -r '.version' < dist/ngx-mask-lib/package.json) - echo "VERSION=$VERSION" >> $GITHUB_ENV - echo "::set-output name=VERSION::$VERSION" + VERSION=$(node -p "require('./dist/ngx-mask-lib/package.json').version") + echo "version=$VERSION" >> $GITHUB_OUTPUT - - name: Confirm extracted version + - name: Use version + env: + VERSION: ${{ steps.get_version.outputs.version }} run: - echo "The extracted version is: ${{ steps.extract_version.outputs.VERSION }}" + echo $VERSION \ No newline at end of file From d7faab368c114d688cfa2c6502d8f040f05b9f73 Mon Sep 17 00:00:00 2001 From: andriikamaldinov1 Date: Fri, 1 Nov 2024 18:23:14 +0200 Subject: [PATCH 8/8] fix(ref: 1440): add version lib version to slack --- .github/workflows/publish.yml | 5 +++++ .github/workflows/quality-check.yml | 13 +------------ .github/workflows/scripts/quality.sh | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc6bdb35..0add2295 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -30,6 +30,11 @@ jobs: run: bun publish:lib env: NODE_AUTH_TOKEN: ${{secrets.npm_token}} + - name: Extract version + id: get_version + run: | + VERSION=$(node -p "require('./dist/ngx-mask-lib/package.json').version") + echo "version=$VERSION" >> $GITHUB_OUTPUT slack_notification: needs: diff --git a/.github/workflows/quality-check.yml b/.github/workflows/quality-check.yml index fea51187..97b5d7bc 100644 --- a/.github/workflows/quality-check.yml +++ b/.github/workflows/quality-check.yml @@ -21,15 +21,4 @@ jobs: - name: Check quality run: | bun i - bash .github/workflows/scripts/quality.sh - - name: Extract version - id: get_version - run: | - VERSION=$(node -p "require('./dist/ngx-mask-lib/package.json').version") - echo "version=$VERSION" >> $GITHUB_OUTPUT - - - name: Use version - env: - VERSION: ${{ steps.get_version.outputs.version }} - run: - echo $VERSION \ No newline at end of file + bash .github/workflows/scripts/quality.sh \ No newline at end of file diff --git a/.github/workflows/scripts/quality.sh b/.github/workflows/scripts/quality.sh index da7ced04..97dea943 100644 --- a/.github/workflows/scripts/quality.sh +++ b/.github/workflows/scripts/quality.sh @@ -7,16 +7,16 @@ bun lint # run snyk:auth -- $snyk_token # bun run snyk:test -#output=$(bun run type-coverage) -#if echo "$output" | grep -q "lower than "; then -# echo "$output" -# exit 1 # Terminate the hook script with a non-zero exit code -#else -# echo "Type coverage is good! 🎉" -#fi -# -#bun run test -#bun run cypress:bash +output=$(bun run type-coverage) +if echo "$output" | grep -q "lower than "; then + echo "$output" + exit 1 # Terminate the hook script with a non-zero exit code +else + echo "Type coverage is good! 🎉" +fi + +bun run test +bun run cypress:bash bun run build