ngx-nz-formly 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/ng-package.json +7 -0
  2. package/package.json +18 -31
  3. package/src/lib/components/formly-button/formly-button.component.html +16 -0
  4. package/src/lib/components/formly-button/formly-button.component.scss +0 -0
  5. package/src/lib/components/formly-button/formly-button.component.ts +18 -0
  6. package/src/lib/components/formly-field-checkbox/formly-field-checkbox.component.html +9 -0
  7. package/src/lib/components/formly-field-checkbox/formly-field-checkbox.component.scss +8 -0
  8. package/src/lib/components/formly-field-checkbox/formly-field-checkbox.component.ts +38 -0
  9. package/src/lib/components/formly-field-input/formly-field-input.component.html +33 -0
  10. package/src/lib/components/formly-field-input/formly-field-input.component.scss +7 -0
  11. package/src/lib/components/formly-field-input/formly-field-input.component.ts +118 -0
  12. package/src/lib/components/formly-field-input/phone-mask.config.ts +1469 -0
  13. package/src/lib/components/formly-field-radio/formly-field-radio.component.html +32 -0
  14. package/src/lib/components/formly-field-radio/formly-field-radio.component.scss +0 -0
  15. package/src/lib/components/formly-field-radio/formly-field-radio.component.ts +44 -0
  16. package/src/lib/components/formly-field-select/formly-field-select.component.html +54 -0
  17. package/src/lib/components/formly-field-select/formly-field-select.component.scss +3 -0
  18. package/src/lib/components/formly-field-select/formly-field-select.component.ts +38 -0
  19. package/src/lib/components/formly-field-switch/formly-field-switch.component.html +10 -0
  20. package/src/lib/components/formly-field-switch/formly-field-switch.component.scss +0 -0
  21. package/src/lib/components/formly-field-switch/formly-field-switch.component.ts +44 -0
  22. package/src/lib/ngx-nz-formly-props.model.ts +158 -0
  23. package/src/lib/ngx-nz-formly-type-safe.model.ts +81 -0
  24. package/src/lib/ngx-nz-formly-validators.ts +92 -0
  25. package/src/lib/ngx-nz-formly.module.ts +260 -0
  26. package/src/lib/wrappers/formly-default-wrapper/formly-default-wrapper.component.html +16 -0
  27. package/src/lib/wrappers/formly-default-wrapper/formly-default-wrapper.component.scss +12 -0
  28. package/src/lib/wrappers/formly-default-wrapper/formly-default-wrapper.component.ts +25 -0
  29. package/src/lib/wrappers/formly-label-wrapper/formly-label-wrapper.component.html +27 -0
  30. package/src/lib/wrappers/formly-label-wrapper/formly-label-wrapper.component.scss +55 -0
  31. package/src/lib/wrappers/formly-label-wrapper/formly-label-wrapper.component.ts +12 -0
  32. package/tsconfig.lib.json +14 -0
  33. package/tsconfig.lib.prod.json +10 -0
  34. package/tsconfig.spec.json +14 -0
  35. package/esm2022/lib/components/formly-button/formly-button.component.mjs +0 -21
  36. package/esm2022/lib/components/formly-field-checkbox/formly-field-checkbox.component.mjs +0 -33
  37. package/esm2022/lib/components/formly-field-input/formly-field-input.component.mjs +0 -105
  38. package/esm2022/lib/components/formly-field-input/phone-mask.config.mjs +0 -1463
  39. package/esm2022/lib/components/formly-field-radio/formly-field-radio.component.mjs +0 -39
  40. package/esm2022/lib/components/formly-field-select/formly-field-select.component.mjs +0 -34
  41. package/esm2022/lib/components/formly-field-switch/formly-field-switch.component.mjs +0 -38
  42. package/esm2022/lib/ngx-nz-formly-props.model.mjs +0 -6
  43. package/esm2022/lib/ngx-nz-formly-type-safe.model.mjs +0 -44
  44. package/esm2022/lib/ngx-nz-formly-validators.mjs +0 -52
  45. package/esm2022/lib/ngx-nz-formly.module.mjs +0 -263
  46. package/esm2022/lib/wrappers/formly-default-wrapper/formly-default-wrapper.component.mjs +0 -39
  47. package/esm2022/lib/wrappers/formly-label-wrapper/formly-label-wrapper.component.mjs +0 -13
  48. package/esm2022/ngx-nz-formly.mjs +0 -5
  49. package/esm2022/public-api.mjs +0 -5
  50. package/fesm2022/ngx-nz-formly.mjs +0 -2101
  51. package/fesm2022/ngx-nz-formly.mjs.map +0 -1
  52. package/index.d.ts +0 -5
  53. package/lib/components/formly-button/formly-button.component.d.ts +0 -8
  54. package/lib/components/formly-field-checkbox/formly-field-checkbox.component.d.ts +0 -13
  55. package/lib/components/formly-field-input/formly-field-input.component.d.ts +0 -24
  56. package/lib/components/formly-field-input/phone-mask.config.d.ts +0 -11
  57. package/lib/components/formly-field-radio/formly-field-radio.component.d.ts +0 -14
  58. package/lib/components/formly-field-select/formly-field-select.component.d.ts +0 -13
  59. package/lib/components/formly-field-switch/formly-field-switch.component.d.ts +0 -14
  60. package/lib/ngx-nz-formly-props.model.d.ts +0 -145
  61. package/lib/ngx-nz-formly-type-safe.model.d.ts +0 -14
  62. package/lib/ngx-nz-formly-validators.d.ts +0 -16
  63. package/lib/ngx-nz-formly.module.d.ts +0 -28
  64. package/lib/wrappers/formly-default-wrapper/formly-default-wrapper.component.d.ts +0 -7
  65. package/lib/wrappers/formly-label-wrapper/formly-label-wrapper.component.d.ts +0 -7
  66. /package/{public-api.d.ts → src/public-api.ts} +0 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
3
+ "dest": "../../dist/ngx-nz-formly",
4
+ "lib": {
5
+ "entryFile": "src/public-api.ts"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,31 +1,18 @@
1
- {
2
- "name": "ngx-nz-formly",
3
- "version": "0.0.2",
4
- "peerDependencies": {
5
- "@angular/common": "^16.2.0",
6
- "@angular/core": "^16.2.0",
7
- "@ngx-formly/core": "6",
8
- "@ngx-formly/ng-zorro-antd": "6",
9
- "bootstrap": "^5.2.3",
10
- "ng-zorro-antd": "^16.1.0",
11
- "ngx-mask": "^13.1.3",
12
- "rxjs": "~7.5.0"
13
- },
14
- "dependencies": {
15
- "tslib": "^2.3.0"
16
- },
17
- "sideEffects": false,
18
- "module": "fesm2022/ngx-nz-formly.mjs",
19
- "typings": "index.d.ts",
20
- "exports": {
21
- "./package.json": {
22
- "default": "./package.json"
23
- },
24
- ".": {
25
- "types": "./index.d.ts",
26
- "esm2022": "./esm2022/ngx-nz-formly.mjs",
27
- "esm": "./esm2022/ngx-nz-formly.mjs",
28
- "default": "./fesm2022/ngx-nz-formly.mjs"
29
- }
30
- }
31
- }
1
+ {
2
+ "name": "ngx-nz-formly",
3
+ "version": "0.0.3",
4
+ "peerDependencies": {
5
+ "@angular/common": "^16.2.0",
6
+ "@angular/core": "^16.2.0",
7
+ "@ngx-formly/core": "6",
8
+ "@ngx-formly/ng-zorro-antd": "6",
9
+ "bootstrap": "^5.2.3",
10
+ "ng-zorro-antd": "^16.1.0",
11
+ "ngx-mask": "^13.1.3",
12
+ "rxjs": "~7.5.0"
13
+ },
14
+ "dependencies": {
15
+ "tslib": "^2.3.0"
16
+ },
17
+ "sideEffects": false
18
+ }
@@ -0,0 +1,16 @@
1
+ <button
2
+ nz-button
3
+ type="button"
4
+ [disabled]="props.disabled"
5
+ [nzGhost]="props.nzGhost"
6
+ [nzLoading]="props.nzLoading"
7
+ [nzShape]="props.nzShape"
8
+ [nzSize]="props.nzSize"
9
+ [nzType]="props.nzType"
10
+ [nzBlock]="props.nzBlock"
11
+ [nzDanger]="props.nzDanger"
12
+ [ngClass]="props.classList"
13
+ (click)="onClick()"
14
+ >
15
+ {{props.text}}
16
+ </button>
@@ -0,0 +1,18 @@
1
+ import { Component } from "@angular/core";
2
+ import { FieldType, FormlyFieldConfig } from "@ngx-formly/core";
3
+ import { NzFormlyButtonProps } from "../../ngx-nz-formly-props.model";
4
+
5
+ @Component({
6
+ selector: "app-formly-button",
7
+ templateUrl: "./formly-button.component.html",
8
+ styleUrls: ["./formly-button.component.scss"],
9
+ })
10
+ export class FormlyButtonComponent extends FieldType<
11
+ FormlyFieldConfig<NzFormlyButtonProps>
12
+ > {
13
+ onClick() {
14
+ if (typeof this.props?.click == "function") {
15
+ this.props.click();
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,9 @@
1
+ <label
2
+ nz-checkbox
3
+ [nzId]="fieldID"
4
+ [formControl]="formControl"
5
+ [formlyAttributes]="field"
6
+ [nzDisabled]="props.disabled"
7
+ >
8
+ {{props.label}}
9
+ </label>
@@ -0,0 +1,8 @@
1
+ label {
2
+ display: flex;
3
+ font-size: 100%;
4
+ font-weight: 600;
5
+ min-height: 30px;
6
+ width: fit-content;
7
+ align-items: center;
8
+ }
@@ -0,0 +1,38 @@
1
+ import { Component, OnDestroy, OnInit } from "@angular/core";
2
+ import { FieldType, FieldTypeConfig } from "@ngx-formly/core";
3
+ import { NzFormlyCheckboxProps } from "../../ngx-nz-formly-props.model";
4
+ import { Subject, takeUntil, tap } from "rxjs";
5
+
6
+ @Component({
7
+ selector: "app-formly-field-checkbox",
8
+ templateUrl: "./formly-field-checkbox.component.html",
9
+ styleUrls: ["./formly-field-checkbox.component.scss"],
10
+ })
11
+ export class FormlyFieldCheckboxComponent
12
+ extends FieldType<FieldTypeConfig<NzFormlyCheckboxProps>>
13
+ implements OnInit, OnDestroy
14
+ {
15
+ unSubscribeAll$ = new Subject<void>();
16
+
17
+ ngOnInit() {
18
+ this.formControl.valueChanges
19
+ .pipe(
20
+ takeUntil(this.unSubscribeAll$),
21
+ tap((value: string) => {
22
+ if (typeof this.props?.change == "function") {
23
+ this.props.change(this.field, value);
24
+ }
25
+ }),
26
+ )
27
+ .subscribe();
28
+ }
29
+
30
+ get fieldID() {
31
+ return "control-" + this.field.key;
32
+ }
33
+
34
+ ngOnDestroy() {
35
+ this.unSubscribeAll$.next();
36
+ this.unSubscribeAll$.complete();
37
+ }
38
+ }
@@ -0,0 +1,33 @@
1
+ <nz-input-group
2
+ [nzAddOnAfter]="props.nzAddOnAfter"
3
+ [nzAddOnBefore]="props.nzAddOnBefore"
4
+ [nzAddOnAfterIcon]="props.nzAddOnAfterIcon"
5
+ [nzAddOnBeforeIcon]="props.nzAddOnBeforeIcon"
6
+ [nzPrefix]="props.nzPrefix"
7
+ [nzSuffix]="props.nzSuffix"
8
+ [nzSize]="props.nzSize || 'default'"
9
+ >
10
+ <input
11
+ #input
12
+ nz-input
13
+ [id]="fieldID"
14
+ [formControl]="formControl"
15
+ [formlyAttributes]="field"
16
+ [mask]="mask"
17
+ [thousandSeparator]="props.thousandSeparator"
18
+ [type]="type"
19
+ [nzStatus]="status"
20
+ [disabled]="props.disabled"
21
+ [readonly]="props.readonly"
22
+ [placeholder]="props.placeholder"
23
+ [nzBorderless]="props.nzBorderless"
24
+ />
25
+ <div class="show-password" *ngIf="props.type === 'password'">
26
+ <span
27
+ nz-icon
28
+ nzTheme="outline"
29
+ (click)="changeShowPassword(input)"
30
+ [nzType]="showPassword(input) ? 'eye-invisible' : 'eye'"
31
+ ></span>
32
+ </div>
33
+ </nz-input-group>
@@ -0,0 +1,7 @@
1
+ .show-password {
2
+ z-index: 5;
3
+ opacity: 0.6;
4
+ cursor: pointer;
5
+ position: absolute;
6
+ inset-inline-end: 10px;
7
+ }
@@ -0,0 +1,118 @@
1
+ import { AfterViewInit, Component, OnDestroy } from "@angular/core";
2
+ import { FieldType, FieldTypeConfig } from "@ngx-formly/core";
3
+ import { NzFormlyInputProps } from "../../ngx-nz-formly-props.model";
4
+ import { debounceTime, Subject, takeUntil, tap } from "rxjs";
5
+ import { CountryCodeMask, CountryMasks2 } from "./phone-mask.config";
6
+
7
+ const DefaultPhoneMask: CountryCodeMask = {
8
+ countryShortName: "IR",
9
+ prefix: "+98",
10
+ globalMask: "+00(000)000-0000",
11
+ };
12
+
13
+ @Component({
14
+ selector: "app-formly-field-input",
15
+ templateUrl: "./formly-field-input.component.html",
16
+ styleUrls: ["./formly-field-input.component.scss"],
17
+ })
18
+ export class FormlyFieldInputComponent
19
+ extends FieldType<FieldTypeConfig<NzFormlyInputProps>>
20
+ implements AfterViewInit, OnDestroy
21
+ {
22
+ mask: string | undefined;
23
+ unSubscribeAll$ = new Subject<void>();
24
+
25
+ ngAfterViewInit() {
26
+ this.createInitState();
27
+ this.onValueChange();
28
+ }
29
+
30
+ createInitState() {
31
+ if (this.props.mask === "phone") {
32
+ this.mask = DefaultPhoneMask.globalMask;
33
+ this.handlePhoneMask();
34
+ } else {
35
+ this.mask = this.props.mask;
36
+ }
37
+ }
38
+
39
+ handlePhoneMask() {
40
+ this.formControl.valueChanges
41
+ .pipe(
42
+ takeUntil(this.unSubscribeAll$),
43
+ tap((value: string) => {
44
+ if (value == "") {
45
+ // hint: without setTimeout we don't have Ctrl + A -> delete
46
+ setTimeout(() => {
47
+ this.mask = DefaultPhoneMask.globalMask;
48
+ });
49
+ } else {
50
+ let mask = this.findAppropriateMask(value);
51
+ if (mask && this.mask !== mask.globalMask) {
52
+ this.mask = mask.globalMask?.replace(/#|[1-9]/g, "0");
53
+ }
54
+ }
55
+ }),
56
+ )
57
+ .subscribe();
58
+ }
59
+
60
+ onValueChange() {
61
+ this.formControl.valueChanges
62
+ .pipe(
63
+ takeUntil(this.unSubscribeAll$),
64
+ debounceTime(300),
65
+ tap((value: string) => {
66
+ if (typeof this.props?.change == "function") {
67
+ this.props.change(this.field, value);
68
+ }
69
+ }),
70
+ )
71
+ .subscribe();
72
+ }
73
+
74
+ findAppropriateMask(value: string): CountryCodeMask | null {
75
+ let newMask = CountryMasks2.filter(item =>
76
+ this.exactEquality(value, item.prefix),
77
+ ).find(item => value.length <= item.globalMask.length);
78
+ if (newMask) return newMask;
79
+ return null;
80
+ }
81
+
82
+ exactEquality(str: string, prefix: string): boolean {
83
+ // hint: replace function removes all characters except numbers to return clean numeric string
84
+ // hint: index of convince us to match prefix on first index of input value
85
+ let new_str = str.replace(/[^0-9.]/g, "");
86
+ let new_prefix = prefix.replace(/[^0-9.]/g, "");
87
+ return new_str.indexOf(new_prefix) == 0;
88
+ }
89
+
90
+ changeShowPassword(input: any) {
91
+ if (input.type === "password") {
92
+ input.type = "text";
93
+ } else {
94
+ input.type = "password";
95
+ }
96
+ }
97
+
98
+ showPassword(input: any): boolean {
99
+ return input.type === "text";
100
+ }
101
+
102
+ get type() {
103
+ return this.props.type ?? "text";
104
+ }
105
+
106
+ get fieldID() {
107
+ return "control-" + this.field.key;
108
+ }
109
+
110
+ get status() {
111
+ return this.formControl.touched && this.formControl.invalid ? "error" : "";
112
+ }
113
+
114
+ ngOnDestroy() {
115
+ this.unSubscribeAll$.next();
116
+ this.unSubscribeAll$.complete();
117
+ }
118
+ }