Skip to content

Commit

Permalink
fix(ref: no-ref): merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
andriikamaldinov1 committed Dec 5, 2024
2 parents 1ac0d27 + 3498c5d commit 029749a
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 91 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# 19.0.2(2024-12-03)

### Fix

- Fix ([#1456](https://github.com/JsDaddy/ngx-mask/issues/1456))
- Fix ([#1458](https://github.com/JsDaddy/ngx-mask/issues/1458))
- Fix ([#1446](https://github.com/JsDaddy/ngx-mask/issues/1446))
- Fix ([#1457](https://github.com/JsDaddy/ngx-mask/issues/1457))

# 19.0.1(2024-11-29)

### Feature
Expand All @@ -6,7 +15,6 @@
- change @Output output in NgxMaskDirective
- change variables to signals in NgxMaskDirective


# 19.0.0(2024-11-22)

### Feature
Expand Down
Binary file modified bun.lockb
Binary file not shown.
70 changes: 35 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "19.0.1",
"version": "19.0.2",
"description": "Awesome ngx mask",
"license": "MIT",
"engines": {
Expand Down Expand Up @@ -60,69 +60,69 @@
"url": "https://github.com/JsDaddy/ngx-mask.git"
},
"dependencies": {
"@angular/animations": "19.0.0",
"@angular/common": "19.0.0",
"@angular/compiler": "19.0.0",
"@angular/core": "19.0.0",
"@angular/forms": "19.0.0",
"@angular/platform-browser": "19.0.0",
"@angular/platform-browser-dynamic": "19.0.0",
"@angular/router": "19.0.0",
"@angular/animations": "19.0.3",
"@angular/common": "19.0.3",
"@angular/compiler": "19.0.3",
"@angular/core": "19.0.3",
"@angular/forms": "19.0.3",
"@angular/platform-browser": "19.0.3",
"@angular/platform-browser-dynamic": "19.0.3",
"@angular/router": "19.0.3",
"@types/jest": "^29.5.14",
"@types/mocha": "^10.0.10",
"ajv": "^8.17.1",
"cypress": "^13.16.0",
"cypress": "^13.16.1",
"highlight.js": "11.10.0",
"ngx-highlightjs": "12.0.0",
"ngxtension": "^4.1.0",
"rxjs": "7.8.1",
"semantic-release": "24.2.0",
"semantic-release-export-data": "^1.1.0",
"snyk": "^1.1294.1"
"snyk": "^1.1294.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "19.0.1",
"@angular-eslint/builder": "18.4.1",
"@angular-eslint/eslint-plugin": "18.4.1",
"@angular-eslint/eslint-plugin-template": "18.4.1",
"@angular-eslint/schematics": "18.4.1",
"@angular-eslint/template-parser": "18.4.1",
"@angular/cli": "19.0.1",
"@angular/compiler-cli": "19.0.0",
"@angular/language-service": "19.0.0",
"@angular-devkit/build-angular": "19.0.3",
"@angular-eslint/builder": "19.0.0",
"@angular-eslint/eslint-plugin": "19.0.0",
"@angular-eslint/eslint-plugin-template": "19.0.0",
"@angular-eslint/schematics": "19.0.0",
"@angular-eslint/template-parser": "19.0.0",
"@angular/cli": "19.0.3",
"@angular/compiler-cli": "19.0.3",
"@angular/language-service": "19.0.3",
"@commitlint/cli": "19.6.0",
"@commitlint/config-conventional": "19.6.0",
"@jscutlery/cypress-angular": "^0.9.22",
"@types/highlight.js": "9.12.4",
"@types/jasmine": "5.1.4",
"@types/node": "22.9.1",
"@typescript-eslint/eslint-plugin": "8.15.0",
"@typescript-eslint/parser": "8.15.0",
"@types/jasmine": "5.1.5",
"@types/node": "22.10.1",
"@typescript-eslint/eslint-plugin": "8.17.0",
"@typescript-eslint/parser": "8.17.0",
"@web/test-runner": "^0.19.0",
"angular-cli-ghpages": "2.0.3",
"angular-http-server": "1.12.0",
"eslint": "9.15.0",
"eslint": "9.16.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-json": "4.0.1",
"eslint-plugin-prettier": "5.2.1",
"jasmine-core": "5.4.0",
"jasmine-core": "5.5.0",
"jasmine-spec-reporter": "7.0.0",
"lint-staged": "15.2.10",
"markdownlint-cli": "0.42.0",
"ng-packagr": "19.0.0",
"markdownlint-cli": "0.43.0",
"ng-packagr": "19.0.1",
"npm-check-updates": "^17.1.11",
"prettier": "3.3.3",
"puppeteer": "23.9.0",
"stylelint": "16.10.0",
"prettier": "3.4.2",
"puppeteer": "23.10.1",
"stylelint": "16.11.0",
"stylelint-config-prettier": "9.0.5",
"stylelint-config-recommended-scss": "14.1.0",
"stylelint-prettier": "5.0.2",
"type-coverage": "^2.29.7",
"typescript": "5.6.3",
"angular-eslint": "^18.4.1",
"typescript-eslint": "^8.15.0",
"tailwindcss": "^3.4.15",
"bun-types": "^1.1.36",
"angular-eslint": "^19.0.0",
"typescript-eslint": "^8.17.0",
"tailwindcss": "^3.4.16",
"bun-types": "^1.1.38",
"postcss": "8.4.49",
"postcss-nesting": "13.0.1",
"cssnano": "7.0.6",
Expand Down
2 changes: 1 addition & 1 deletion projects/ngx-mask-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "19.0.1",
"version": "19.0.2",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
17 changes: 15 additions & 2 deletions projects/ngx-mask-lib/src/lib/ngx-mask-applier.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,11 @@ export class NgxMaskApplierService {
? processedValue.slice(1, processedValue.length)
: processedValue;
} else {
if (processedValue[0] === decimalMarker && processedValue.length > 1) {
if (
processedValue[0] === decimalMarker &&
processedValue.length > 1 &&
!backspaced
) {
processedValue =
MaskExpression.NUMBER_ZERO +
processedValue.slice(0, processedValue.length + 1);
Expand Down Expand Up @@ -275,12 +279,21 @@ export class NgxMaskApplierService {
processedValue[processedPosition] === MaskExpression.NUMBER_ZERO ||
processedValue[processedPosition] === decimalMarker;
const zeroIndexNumberZero = processedValue[0] === MaskExpression.NUMBER_ZERO;
const firstIndexNumberZero = processedValue[1] === MaskExpression.NUMBER_ZERO;
const zeroIndexMinus = processedValue[0] === MaskExpression.MINUS;
const zeroIndexThousand = processedValue[0] === this.thousandSeparator;
const firstIndexDecimalMarker = processedValue[1] === decimalMarker;
const firstIndexNumberZero = processedValue[1] === MaskExpression.NUMBER_ZERO;
const zeroIndexDecimalMarker = processedValue[0] === decimalMarker;
const secondIndexDecimalMarker = processedValue[2] === decimalMarker;

if (zeroIndexNumberZero && firstIndexDecimalMarker && processedPosition === 0) {
return processedValue;
}

if (zeroIndexDecimalMarker && processedPosition === 0) {
processedValue = inputValueAfterZero;
}

if (
zeroIndexNumberZero &&
firstIndexDecimalMarker &&
Expand Down
12 changes: 5 additions & 7 deletions projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida
private _position = signal<number | null>(null);
private _code = signal<string>('');
private _maskExpressionArray = signal<string[]>([]);
private _allowFewMaskChangeMask = signal<boolean>(false);
private _justPasted = signal<boolean>(false);
private _isFocused = signal<boolean>(false);
/**For IME composition event */
Expand Down Expand Up @@ -595,12 +594,15 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida
const specialChartMinusOne = this.specialCharacters().includes(
this._maskService.actualValue.slice(position - 1, position)
);
const allowFewMaskChangeMask =
this._maskService.removeMask(this._inputValue())?.length ===
this._maskService.removeMask(this._maskService.maskExpression)?.length;

const specialChartPlusOne = this.specialCharacters().includes(
this._maskService.actualValue.slice(position, position + 1)
);
if (this._allowFewMaskChangeMask() && !specialChartPlusOne) {
if (allowFewMaskChangeMask && !specialChartPlusOne) {
position = (el.selectionStart as number) + 1;
this._allowFewMaskChangeMask.set(false);
} else {
position = specialChartMinusOne ? position - 1 : position;
}
Expand Down Expand Up @@ -1105,10 +1107,6 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida
this._maskService.maskExpression = maskValue;
return test;
} else {
if (this._code() === MaskExpression.BACKSPACE) {
this._allowFewMaskChangeMask.set(true);
}

const expression =
this._maskExpressionArray()[this._maskExpressionArray().length - 1] ??
MaskExpression.EMPTY_STRING;
Expand Down
11 changes: 7 additions & 4 deletions projects/ngx-mask-lib/src/lib/ngx-mask.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ export class NgxMaskService extends NgxMaskApplierService {
*/
private formControlResult(inputValue: string): void {
if (this.writingValue && !inputValue) {
this.onChange('');
this.onChange(this.outputTransformFn(''));
return;
}
if (this.writingValue || (!this.triggerOnMaskChange && this.maskChanged)) {
Expand Down Expand Up @@ -713,6 +713,7 @@ export class NgxMaskService extends NgxMaskApplierService {
(char) => char !== MaskExpression.WHITE_SPACE
);
}

return this._removeMask(result, specialCharacters as string[]);
}

Expand Down Expand Up @@ -747,9 +748,11 @@ export class NgxMaskService extends NgxMaskApplierService {
const separatorPrecision: number | null = this._retrieveSeparatorPrecision(
this.maskExpression
);
const separatorValue: string = this._replaceDecimalMarkerToDot(
this._retrieveSeparatorValue(processedResult)
);

const separatorValue: string =
this.specialCharacters.length === 0
? this._retrieveSeparatorValue(processedResult)
: this._replaceDecimalMarkerToDot(this._retrieveSeparatorValue(processedResult));

if (!this.isNumberValue) {
return separatorValue;
Expand Down
68 changes: 68 additions & 0 deletions projects/ngx-mask-lib/src/test/allow-few-mask.cy-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { CypressTestMaskComponent } from './utils/cypress-test-component.component';
import { signal } from '@angular/core';

describe('Test Date Hh:m0', () => {
it('dynamic mask after backspace should have right cursor position (000) 000-0000||+000000000000000', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('(000) 000-0000||+000000000000000'),
},
});

cy.get('#masked').type('11111111111').should('have.value', '+11111111111');
cy.get('#masked')
.type('{backspace}')
.should('have.value', '(111) 111-1111')
.should('have.prop', 'selectionStart', 14);
});

it('dynamic mask after backspace should have right cursor position', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('(000) 000-0000||+000000000000000'),
},
});

cy.get('#masked')
.type('1234567890')

.should('have.value', '(123) 456-7890')
.type('{leftArrow}'.repeat(7))
.type('{backspace}')
.should('have.prop', 'selectionStart', 5);
});

it('dynamic mask after backspace should have right cursor position (00) 00000000||+00 (00) 00000000', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('(00) 00000000||+00 (00) 00000000'),
},
});

cy.get('#masked').type('111').should('have.value', '(11) 1');
cy.get('#masked').type('{backspace}').should('have.prop', 'selectionStart', 4);
});

it('dynamic mask after backspace should have right cursor position 00) 000-00-00||00) 000-00-00; 0 (000) 000-00-00', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('00) 000-00-00||00) 000-00-00; 0 (000) 000-00-00'),
showMaskTyped: signal(true),
dropSpecialCharacters: signal(false),
prefix: signal('8 (0'),
specialCharacters: signal(['(', ')', '-', ';', '.', ' ']),
},
});

cy.get('#masked')
.type('123456789 11')
.should('have.value', '8 (012) 345-67-89; 1 (1__) ___-__-__')
.type('{leftArrow}'.repeat(6))
.type('{backspace}')
.should('have.prop', 'selectionStart', 16)
.should('have.value', '8 (012) 345-67-81; 1 (___) ___-__-__')
.type('{backspace}')
.should('have.prop', 'selectionStart', 17)
.should('have.value', '8 (012) 345-67-11');
});
});
41 changes: 0 additions & 41 deletions projects/ngx-mask-lib/src/test/cursor.cy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,45 +222,4 @@ describe('Test Date Hh:m0', () => {
.should('have.value', '123')
.should('have.prop', 'selectionStart', 3);
});

it('dynamic mask after backspace should have right cursor position (000) 000-0000||+000000000000000', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('(000) 000-0000||+000000000000000'),
},
});

cy.get('#masked').type('11111111111').should('have.value', '+11111111111');
cy.get('#masked')
.type('{backspace}')
.should('have.value', '(111) 111-1111')
.should('have.prop', 'selectionStart', 14);
});

it('dynamic mask after backspace should have right cursor position', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('(000) 000-0000||+000000000000000'),
},
});

cy.get('#masked')
.type('1234567890')

.should('have.value', '(123) 456-7890')
.type('{leftArrow}'.repeat(7))
.type('{backspace}')
.should('have.prop', 'selectionStart', 5);
});

it('dynamic mask after backspace should have right cursor position (00) 00000000||+00 (00) 00000000', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: signal('(00) 00000000||+00 (00) 00000000'),
},
});

cy.get('#masked').type('111').should('have.value', '(11) 1');
cy.get('#masked').type('{backspace}').should('have.prop', 'selectionStart', 4);
});
});
32 changes: 32 additions & 0 deletions projects/ngx-mask-lib/src/test/custom-patterns.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,35 @@ describe('Directive: Mask (Provide custom patterns with symbol B optional)', ()
equal('123-45-6', '123-45-6', fixture);
});
});

describe('Directive: Mask (Provide custom patterns with symbol C with specialCharacter = [])', () => {
let fixture: ComponentFixture<TestMaskComponent>;
let component: TestMaskComponent;
const ngxMaskCustomPatterns = {
c: { pattern: new RegExp(/^[^'=<>()]*$/u) },
};

const ngxMaskConfigValue: Partial<NgxMaskConfig> = {
patterns: { ...initialConfig.patterns, ...ngxMaskCustomPatterns },
};

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, NgxMaskDirective, TestMaskComponent],
providers: [provideNgxMask(ngxMaskConfigValue)],
});
fixture = TestBed.createComponent(TestMaskComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('custom mask with c{10} should work correct with specialCharacter = []', () => {
component.mask.set('c{10}');
component.specialCharacters.set([]);

equal(',', ',', fixture);
equal(',.', ',.', fixture);
equal(',./', ',./', fixture);
expect(component.form.value).toBe(',./');
});
});
Loading

0 comments on commit 029749a

Please sign in to comment.