generated from Tinkoff/angular-open-source-starter
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): create new library
@maskito/angular
(#35)
* feat(angular): create new library `@maskito/angular` * chore: fix previous review comments
- Loading branch information
1 parent
ab9c0aa
commit 1855c35
Showing
30 changed files
with
359 additions
and
264 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# angular | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test angular` to execute the unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = { | ||
displayName: 'angular', | ||
preset: '../../jest.preset.js', | ||
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'], | ||
globals: { | ||
'ts-jest': { | ||
tsconfig: '<rootDir>/tsconfig.spec.json', | ||
stringifyContentPathRegex: '\\.(html|svg)$', | ||
}, | ||
}, | ||
coverageDirectory: '../../coverage/projects/angular', | ||
transform: { | ||
'^.+\\.(ts|js|html)$': 'jest-preset-angular', | ||
}, | ||
snapshotSerializers: [ | ||
'jest-preset-angular/build/serializers/no-ng-attributes', | ||
'jest-preset-angular/build/serializers/ng-snapshot', | ||
'jest-preset-angular/build/serializers/html-comment', | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json", | ||
"dest": "../../dist/projects/angular", | ||
"lib": { | ||
"entryFile": "src/index.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@maskito/angular", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"tslib": "^2.3.0" | ||
}, | ||
"peerDependencies": { | ||
"@angular/common": ">=12.0.0", | ||
"@angular/core": ">=12.0.0", | ||
"@maskito/core": "^0.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"projectType": "library", | ||
"root": "projects/angular", | ||
"sourceRoot": "projects/angular/src", | ||
"prefix": "maskito", | ||
"targets": { | ||
"build": { | ||
"executor": "@nrwl/angular:ng-packagr-lite", | ||
"outputs": ["dist/projects/angular"], | ||
"options": { | ||
"project": "projects/angular/ng-package.json" | ||
}, | ||
"configurations": { | ||
"production": { | ||
"tsConfig": "projects/angular/tsconfig.lib.prod.json" | ||
}, | ||
"development": { | ||
"tsConfig": "projects/angular/tsconfig.lib.json" | ||
} | ||
}, | ||
"defaultConfiguration": "production" | ||
}, | ||
"test": { | ||
"executor": "@nrwl/jest:jest", | ||
"outputs": ["coverage/projects/angular"], | ||
"options": { | ||
"jestConfig": "projects/angular/jest.config.js", | ||
"passWithNoTests": true | ||
} | ||
} | ||
}, | ||
"tags": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './lib/maskito.directive'; | ||
export * from './lib/maskito.module'; | ||
export * from './lib/maskito-options'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {InjectionToken} from '@angular/core'; | ||
import {MASKITO_DEFAULT_OPTIONS, MaskitoOptions} from '@maskito/core'; | ||
|
||
export const MASKITO_OPTIONS = new InjectionToken<MaskitoOptions>( | ||
'[MASKITO_OPTIONS] Default parameters for MaskitoDirective', | ||
{ | ||
factory: () => MASKITO_DEFAULT_OPTIONS, | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {Directive, ElementRef, Inject, Input, OnChanges, OnDestroy} from '@angular/core'; | ||
import {Maskito, MaskitoOptions} from '@maskito/core'; | ||
import {MASKITO_OPTIONS} from './maskito-options'; | ||
|
||
@Directive({ | ||
selector: 'input[maskito], textarea[maskito]', | ||
}) | ||
export class MaskitoDirective implements OnChanges, OnDestroy { | ||
private maskedElement: Maskito | null = null; | ||
|
||
/** | ||
* When developer has direct access to native input element: | ||
* ``` | ||
* <input [maskito]="options" /> | ||
* ``` | ||
* ___ | ||
* When native input element is hidden somewhere deep inside another component: | ||
* ``` | ||
* @Component({ | ||
* template: ` | ||
* <your-custom-input> | ||
* <!-- <input maskito /> is somewhere inside --> | ||
* </your-custom-input> | ||
* `, | ||
* providers: [{provide: MASKITO_OPTIONS, useValue: {mask: /^\d+$/}}], | ||
* }) | ||
* export class YourComponent {} | ||
* ``` | ||
* WARNING! This approach is acceptable only for the static mask (no mask option changes). | ||
*/ | ||
@Input('maskito') | ||
options: MaskitoOptions | '' = this.defaultOptions; | ||
|
||
constructor( | ||
@Inject(ElementRef) | ||
private readonly elementRef: ElementRef<HTMLInputElement | HTMLTextAreaElement>, | ||
@Inject(MASKITO_OPTIONS) | ||
private readonly defaultOptions: MaskitoOptions, | ||
) {} | ||
|
||
ngOnChanges() { | ||
this.maskedElement?.destroy(); | ||
|
||
this.maskedElement = new Maskito( | ||
this.elementRef.nativeElement, | ||
this.options || this.defaultOptions, | ||
); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.maskedElement?.destroy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {MaskitoDirective} from './maskito.directive'; | ||
|
||
@NgModule({ | ||
declarations: [MaskitoDirective], | ||
exports: [MaskitoDirective], | ||
}) | ||
export class MaskitoModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import 'jest-preset-angular/setup-jest'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.lib.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"angularCompilerOptions": { | ||
"strictInjectionParameters": true, | ||
"strictInputAccessModifiers": true, | ||
"strictTemplates": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"target": "es2015", | ||
"declaration": true, | ||
"declarationMap": true, | ||
"inlineSources": true, | ||
"types": [], | ||
"lib": ["dom", "es2018"] | ||
}, | ||
"exclude": ["src/test-setup.ts", "**/*.spec.ts", "**/*.test.ts"], | ||
"include": ["**/*.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* To learn more about this file see: https://angular.io/config/tsconfig. */ | ||
{ | ||
"extends": "./tsconfig.lib.json", | ||
"compilerOptions": { | ||
"declarationMap": false | ||
}, | ||
"angularCompilerOptions": { | ||
"compilationMode": "partial" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"files": ["src/test-setup.ts"], | ||
"include": ["**/*.test.ts", "**/*.spec.ts", "**/*.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export {Maskito} from './lib/mask'; | ||
export {MaskitoOptions} from './lib/types'; | ||
export {MASKITO_DEFAULT_OPTIONS} from './lib/constants'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {MaskitoOptions} from '@maskito/core'; | ||
import {identity} from '../utils'; | ||
|
||
export const MASKITO_DEFAULT_OPTIONS: Required<MaskitoOptions> = { | ||
mask: /^.*$/, | ||
preprocessor: identity, | ||
postprocessor: identity, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './default-options'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.