Skip to content

Commit

Permalink
fix(ref: no-ref): fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
andriikamaldinov1 committed Nov 4, 2024
1 parent cced956 commit 2937297
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
44 changes: 43 additions & 1 deletion .github/workflows/quality-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on: [push]
jobs:
quality-check:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
permissions:
contents: write
steps:
Expand All @@ -21,4 +23,44 @@ jobs:
- name: Check quality
run: |
bun i
bash .github/workflows/scripts/quality.sh
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
slack_notification:
needs:
- build
runs-on: ubuntu-latest
steps:
- name: Post to a Slack channel
id: slack
uses: slackapi/[email protected]
with:
channel-id: 'deployments'
payload: |
{
"text": "GitHub Action build result: ${{ job.status == 'success' && ':white_check_mark:' || ':x:' }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "GitHub Action build result: ${{ job.status == 'success' && ':white_check_mark:' || ':x:' }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Version: `${{ needs.quality-check.outputs.version || 'TBA' }}`"
}
},
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/scripts/quality.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ else
echo "Type coverage is good! 🎉"
fi

bun run test
bun run cypress:bash
#bun run test
#bun run cypress:bash

bun run build

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
https://github.com/JsDaddy/ngx-mask/issues/1372
https://github.com/JsDaddy/ngx-mask/issues/1441

# 18.0.2(2024-11-01)

### Fix
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-mask",
"version": "18.0.2",
"version": "18.0.3",
"description": "Awesome ngx mask",
"license": "MIT",
"engines": {
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": "18.0.2",
"version": "18.0.3",
"description": "awesome ngx mask",
"keywords": [
"ng2-mask",
Expand Down
10 changes: 8 additions & 2 deletions projects/ngx-mask-lib/src/lib/ngx-mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida
const selStart = Number(this._maskService.selStart) - prefixLength;
const selEnd = Number(this._maskService.selEnd) - prefixLength;

if (this._code === MaskExpression.BACKSPACE) {
const backspaceOrDelete =
this._code === MaskExpression.BACKSPACE ||
this._code === MaskExpression.DELETE;

if (backspaceOrDelete) {
if (!selectRangeBackspace) {
if (this._maskService.selStart === prefixLength) {
this._maskService.actualValue = `${this.prefix}${this._maskService.maskIsShown.slice(0, selEnd)}${this._inputValue.split(this.prefix).join('')}`;
Expand Down Expand Up @@ -505,8 +509,9 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida
this._maskService.actualValue = `${part1}${this._maskService.placeHolderCharacter}${part2}`;
}
}
position = this._code === MaskExpression.DELETE ? position + 1 : position;
}
if (this._code !== MaskExpression.BACKSPACE) {
if (!backspaceOrDelete) {
if (!checkSymbols && !checkSpecialCharacter && selectRangeBackspace) {
position = Number(el.selectionStart) - 1;
} else if (
Expand Down Expand Up @@ -996,6 +1001,7 @@ export class NgxMaskDirective implements ControlValueAccessor, OnChanges, Valida
if (typeof this.inputTransformFn !== 'function') {
this._maskService.writingValue = true;
}

this._maskService.formElementProperty = [
'value',
this._maskService.applyMask(inputValue, this._maskService.maskExpression),
Expand Down
8 changes: 7 additions & 1 deletion projects/ngx-mask-lib/src/lib/ngx-mask.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,16 @@ export class NgxMaskService extends NgxMaskApplierService {
this._emitValue =
this._previousValue !== this._currentValue ||
this.maskChanged ||
this.writingValue ||
(this._previousValue === this._currentValue && justPasted);
}

// eslint-disable-next-line no-unused-expressions,@typescript-eslint/no-unused-expressions
this._emitValue
? this.writingValue && this.triggerOnMaskChange
? requestAnimationFrame(() => this.formControlResult(result))
: this.formControlResult(result)
: '';

if (!this.showMaskTyped || (this.showMaskTyped && this.hiddenInput)) {
if (this.hiddenInput) {
if (backspaced) {
Expand Down Expand Up @@ -530,6 +531,10 @@ export class NgxMaskService extends NgxMaskApplierService {
* @param inputValue the current form input value
*/
private formControlResult(inputValue: string): void {
if (this.writingValue && !inputValue) {
this.onChange('');
return;
}
if (this.writingValue || (!this.triggerOnMaskChange && this.maskChanged)) {
// eslint-disable-next-line no-unused-expressions,@typescript-eslint/no-unused-expressions
this.triggerOnMaskChange && this.maskChanged
Expand Down Expand Up @@ -586,6 +591,7 @@ export class NgxMaskService extends NgxMaskApplierService {
if (String(value).length > 16 && this.separatorLimit.length > 14) {
return String(value);
}

const num = Number(value);
if (this.maskExpression.startsWith(MaskExpression.SEPARATOR) && Number.isNaN(num)) {
const val = String(value).replace(',', '.');
Expand Down
52 changes: 52 additions & 0 deletions projects/ngx-mask-lib/src/test/basic-logic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -969,4 +969,56 @@ describe('Directive: Mask', () => {

expect(component.form.dirty).toBe(false);
});

it('mask sepator.2 after setValue should be dont dirty', () => {
component.mask = 'separator.0';
component.form.setValue('2002');

expect(component.form.dirty).toBe(false);
});

it('should return empty string in formControl mask SSS-SSS-SSS', () => {
component.mask = 'SSS-SSS-SSS';
component.form.setValue('978-1-93624-386-0');
const debugElement: DebugElement = fixture.debugElement.query(By.css('input'));
const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement;
spyOnProperty(document, 'activeElement').and.returnValue(inputTarget);
fixture.detectChanges();

expect(inputTarget.value).toBe('');
});

it('should return empty string in formControl mask AAA-AAA-AAA', () => {
component.mask = 'AAA-AAA-AAA';
component.form.setValue('978-123-936');
const debugElement: DebugElement = fixture.debugElement.query(By.css('input'));
const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement;
spyOnProperty(document, 'activeElement').and.returnValue(inputTarget);
fixture.detectChanges();

expect(inputTarget.value).toBe('');
});

it('should return empty string in formControl mask (000) 000-000', () => {
component.mask = '(000) 000-000';
component.form.setValue('978-123-936');
const debugElement: DebugElement = fixture.debugElement.query(By.css('input'));
const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement;
spyOnProperty(document, 'activeElement').and.returnValue(inputTarget);
fixture.detectChanges();

expect(inputTarget.value).toBe('');
});

it('should return empty string in formControl mask (000) 000-000 with prefix +7', () => {
component.mask = '(000) 000-000';
component.prefix = '+7 ';
component.form.setValue('978-123-936');
const debugElement: DebugElement = fixture.debugElement.query(By.css('input'));
const inputTarget: HTMLInputElement = debugElement.nativeElement as HTMLInputElement;
spyOnProperty(document, 'activeElement').and.returnValue(inputTarget);
fixture.detectChanges();

expect(inputTarget.value).toBe('');
});
});
43 changes: 43 additions & 0 deletions projects/ngx-mask-lib/src/test/keep-character-position.cy-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,47 @@ describe('Directive: Mask (Delete)', () => {
.type('{backspace}'.repeat(2))
.should('have.value', '12/__/567 test');
});

it('should delete character from del', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: '000-000-000',
keepCharacterPositions: true,
showMaskTyped: true,
},
imports: [CypressTestMaskModule],
});

cy.get('#masked')
.type('123456789')
.type('{leftArrow}'.repeat(11))
.type('{del}'.repeat(11))
.should('have.value', '___-___-___');

cy.get('#masked').clear();
cy.get('#masked')
.type('123456789')
.type('{leftArrow}'.repeat(4))
.type('{del}')
.should('have.value', '123-456-789')
.should('have.prop', 'selectionStart', 8);
});

it('should delete character from del', () => {
cy.mount(CypressTestMaskComponent, {
componentProperties: {
mask: '0000 0000 0000 0000',
keepCharacterPositions: true,
showMaskTyped: true,
},
imports: [CypressTestMaskModule],
});

cy.get('#masked')
.type('1234567891011121')
.type('{leftArrow}'.repeat(5))
.type('{del}')
.should('have.value', '1234 5678 9101 1121')
.should('have.prop', 'selectionStart', 15);
});
});
38 changes: 38 additions & 0 deletions src/app/options/options.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
<div class="flex flex-col bg-black">
<!-- <input-->
<!-- type="text"-->
<!-- mask="000-000-000"-->
<!-- [formControl]="formControl"-->
<!-- [showMaskTyped]="true"-->
<!-- [keepCharacterPositions]="true" />-->

<!-- <input-->
<!-- type="text"-->
<!-- mask="000-000-000"-->
<!-- [formControl]="formControl"-->
<!-- [showMaskTyped]="true"-->
<!-- prefix="+387 "-->
<!-- [keepCharacterPositions]="true" />-->
<!-- <span>{{ formControl.value }}</span>-->

<input type="text" mask="d0.M0." [dropSpecialCharacters]="false" />
<input type="text" mask="M0.d0." [dropSpecialCharacters]="false" />

<br />
<span>Workaround</span>
<input type="text" mask="d0.M0." [dropSpecialCharacters]="false" [leadZeroDateTime]="true" />
<input type="text" mask="M0.d0." [dropSpecialCharacters]="false" [leadZeroDateTime]="true" />

<!-- <div>-->
<!-- <p>Mask set to 'SSS-SSS-SSS'</p>-->
<!-- <input-->
<!-- [formControl]="formControl"-->
<!-- [showMaskTyped]="true"-->
<!-- [validation]="true"-->
<!-- type="text"-->
<!-- [mask]="'SSS-SSS-SSS'" />-->
<!-- </div>-->
<!-- <span>{{ formControl.value }}</span>-->
<!-- <button (click)="onClick()" class="text-full-white">Set value to: 978-1-93624-386-0</button>-->
</div>

@for (tile of cardDocs(); track tile.id; let i = $index) {
<div
class="flex flex-col p-2.5 gap-2.5 bg-dark/[.02] rounded-15px"
Expand Down
6 changes: 6 additions & 0 deletions src/app/options/options.component.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
:host {
@apply flex flex-col gap-4 p-4 bg-full-white box-border border-t border-t-black/10 py-5 pl-[22px] pr-4;
input {
@apply w-full h-[51px] placeholder:text-white/25 text-full-white py-3 px-5 outline-none bg-black border-b-2px border-b-white rounded-10px focus:border-b-yellow hover:border-b-yellow hover:bg-full-white/25 focus:bg-full-white/25;
}
span {
@apply text-full-white;
}
}
8 changes: 7 additions & 1 deletion src/app/options/options.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, effect, ElementRef, inject, input, viewChildren } from '@angular/core';
import { JsonPipe, NgOptimizedImage, NgTemplateOutlet } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { initialConfig, NgxMaskDirective, NgxMaskPipe } from 'ngx-mask';
import { HighlightModule } from 'ngx-highlightjs';
import { AssetPipe } from '@libraries/asset/asset.pipe';
Expand Down Expand Up @@ -59,4 +59,10 @@ export class OptionsComponent {
this.accordionService.onChangeAccordion(this.cards());
});
}

public formControl = new FormControl('123 456 789 999 999 9');

public onClick() {
this.formControl.setValue('978-1-93624-386-0');
}
}

0 comments on commit 2937297

Please sign in to comment.