ngwr 0.1.0 → 0.1.2

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.
package/fesm2015/ngwr.mjs CHANGED
@@ -3,11 +3,11 @@ import * as i0 from '@angular/core';
3
3
  import { Directive, Component, ViewEncapsulation, ChangeDetectionStrategy, HostBinding, Injectable, Optional, Inject, Input, NgModule, EventEmitter, forwardRef, ViewChild, Output } from '@angular/core';
4
4
  import { Subject, fromEvent } from 'rxjs';
5
5
  import { takeUntil } from 'rxjs/operators';
6
- import { coerceBooleanProperty } from '@angular/cdk/coercion';
6
+ import { coerceBooleanProperty, coerceNumberProperty } from '@angular/cdk/coercion';
7
7
  import * as i1 from '@angular/common';
8
8
  import { DOCUMENT, CommonModule } from '@angular/common';
9
9
  import * as i2 from '@angular/forms';
10
- import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
10
+ import { NG_VALUE_ACCESSOR, FormsModule, NG_VALIDATORS } from '@angular/forms';
11
11
  import * as i1$1 from '@angular/cdk/a11y';
12
12
  import { A11yModule } from '@angular/cdk/a11y';
13
13
 
@@ -1019,20 +1019,87 @@ class WrInputComponent extends BaseComponent {
1019
1019
  this.elRef = elRef;
1020
1020
  this.focusMonitor = focusMonitor;
1021
1021
  this.ngZone = ngZone;
1022
- this.value = null;
1023
- this.type = 'text';
1024
- this.autocomplete = 'on';
1025
- this.inputmode = 'text';
1026
- this.disabled = false;
1027
- this.readonly = false;
1028
- this.autofocus = false;
1029
- this.passwordIcons = false;
1030
- this.placeholder = undefined;
1022
+ this.placeholder = '';
1031
1023
  this.prefix = null;
1032
1024
  this.suffix = null;
1025
+ this.passwordIcons = false;
1033
1026
  this.eyeOn = true;
1034
- this.onChange = () => { };
1035
- this.onTouch = () => { };
1027
+ this._value = '';
1028
+ this._disabled = false;
1029
+ this._readonly = false;
1030
+ this._required = false;
1031
+ this._autofocus = false;
1032
+ this._focused = false;
1033
+ this._autocomplete = 'off';
1034
+ this._type = 'text';
1035
+ this._mode = 'text';
1036
+ this.onChangeCallback = () => { };
1037
+ this.onTouchedCallback = () => { };
1038
+ }
1039
+ get type() {
1040
+ return this._type;
1041
+ }
1042
+ set type(type) {
1043
+ this._type = type;
1044
+ }
1045
+ get inputmode() {
1046
+ return this._mode;
1047
+ }
1048
+ set inputmode(mode) {
1049
+ this._mode = mode;
1050
+ }
1051
+ get disabled() {
1052
+ return this._disabled;
1053
+ }
1054
+ set disabled(disabled) {
1055
+ this._disabled = coerceBooleanProperty(disabled);
1056
+ this.cdr.markForCheck();
1057
+ }
1058
+ get readonly() {
1059
+ return this._readonly;
1060
+ }
1061
+ set readonly(readonly) {
1062
+ this._readonly = coerceBooleanProperty(readonly);
1063
+ }
1064
+ get required() {
1065
+ return this._required;
1066
+ }
1067
+ set required(required) {
1068
+ this._required = coerceBooleanProperty(required);
1069
+ }
1070
+ get autofocus() {
1071
+ return this._autofocus;
1072
+ }
1073
+ set autofocus(autofocus) {
1074
+ this._autofocus = coerceBooleanProperty(autofocus);
1075
+ }
1076
+ get autocomplete() {
1077
+ return this._autocomplete;
1078
+ }
1079
+ set autocomplete(autofocus) {
1080
+ this._autocomplete = autofocus;
1081
+ }
1082
+ get value() {
1083
+ return this.type === 'number' ? this.valueAsNumber : this._value;
1084
+ }
1085
+ set value(val) {
1086
+ if (val !== this._value) {
1087
+ this._value = val;
1088
+ this.onChangeCallback(this.value);
1089
+ }
1090
+ }
1091
+ get valueAsString() {
1092
+ if (this._value == null || typeof this._value === 'undefined')
1093
+ return '';
1094
+ return String(this._value);
1095
+ }
1096
+ get valueAsNumber() {
1097
+ return coerceNumberProperty(this._value);
1098
+ }
1099
+ get isBadInput() {
1100
+ var _a, _b;
1101
+ const validity = (_b = (_a = this.inputElement) === null || _a === void 0 ? void 0 : _a.nativeElement) === null || _b === void 0 ? void 0 : _b.validity;
1102
+ return validity && validity.badInput;
1036
1103
  }
1037
1104
  get elClasses() {
1038
1105
  return {
@@ -1049,7 +1116,7 @@ class WrInputComponent extends BaseComponent {
1049
1116
  .pipe(takeUntil(this.ngUnsubscribe))
1050
1117
  .subscribe(event => {
1051
1118
  event.preventDefault();
1052
- this.focus();
1119
+ this.onFocus();
1053
1120
  if (this.disabled) {
1054
1121
  event.stopImmediatePropagation();
1055
1122
  return;
@@ -1062,62 +1129,66 @@ class WrInputComponent extends BaseComponent {
1062
1129
  }
1063
1130
  ngAfterViewInit() {
1064
1131
  if (this.autofocus) {
1065
- this.focus();
1132
+ this.onFocus();
1133
+ this.cdr.markForCheck();
1066
1134
  }
1067
1135
  }
1068
1136
  ngOnDestroy() {
1069
1137
  super.ngOnDestroy();
1070
1138
  this.focusMonitor.stopMonitoring(this.elRef);
1071
1139
  }
1072
- writeValue(value) {
1073
- this.value = value;
1074
- this.cdr.markForCheck();
1140
+ onFocus(event) {
1141
+ if (event) {
1142
+ event.stopPropagation();
1143
+ }
1144
+ this._focused = true;
1145
+ this.focusMonitor.focusVia(this.inputElement, 'keyboard');
1075
1146
  }
1076
- registerOnChange(fn) {
1077
- this.onChange = fn;
1147
+ onBlur(event) {
1148
+ if (event) {
1149
+ event.stopPropagation();
1150
+ }
1151
+ this._focused = false;
1152
+ // this.inputElement.nativeElement.blur();
1153
+ this.onTouchedCallback();
1078
1154
  }
1079
- registerOnTouched(fn) {
1080
- this.onTouch = fn;
1155
+ validate(control) {
1156
+ return Object.assign({}, (this.isBadInput ? { badInput: true } : null));
1081
1157
  }
1082
- setDisabledState(isDisabled) {
1083
- this.disabled = isDisabled;
1158
+ writeValue(value) {
1159
+ if (value !== this._value) {
1160
+ this._value = value;
1161
+ }
1084
1162
  this.cdr.markForCheck();
1085
1163
  }
1086
- focus() {
1087
- this.focusMonitor.focusVia(this.inputElement, 'keyboard');
1164
+ registerOnChange(fn) {
1165
+ this.onChangeCallback = fn;
1088
1166
  }
1089
- blur() {
1090
- this.inputElement.nativeElement.blur();
1167
+ registerOnTouched(fn) {
1168
+ this.onTouchedCallback = fn;
1091
1169
  }
1092
- onPasswordVisibilityChange(event) {
1093
- event.stopPropagation();
1170
+ onPasswordVisibilityChange() {
1094
1171
  this.type === 'password' ? (this.type = 'text') : (this.type = 'password');
1095
1172
  this.eyeOn = !this.eyeOn;
1173
+ this.onFocus();
1096
1174
  }
1097
- onModelChange(value) {
1098
- if (!this.disabled) {
1099
- this.value = value;
1100
- this.onChange(this.value);
1101
- }
1175
+ setDisabledState(isDisabled) {
1176
+ this.disabled = coerceBooleanProperty(isDisabled);
1102
1177
  }
1103
1178
  }
1104
1179
  WrInputComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.8", ngImport: i0, type: WrInputComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i1$1.FocusMonitor }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
1105
- WrInputComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.8", type: WrInputComponent, selector: "wr-input", inputs: { value: "value", type: "type", autocomplete: "autocomplete", inputmode: "inputmode", disabled: "disabled", readonly: "readonly", autofocus: "autofocus", passwordIcons: "passwordIcons", placeholder: "placeholder", prefix: "prefix", suffix: "suffix" }, host: { properties: { "class": "this.elClasses" } }, providers: [
1180
+ WrInputComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.8", type: WrInputComponent, selector: "wr-input", inputs: { placeholder: "placeholder", prefix: "prefix", suffix: "suffix", passwordIcons: "passwordIcons", type: "type", inputmode: "inputmode", disabled: "disabled", readonly: "readonly", required: "required", autofocus: "autofocus", autocomplete: "autocomplete", value: "value" }, host: { properties: { "class": "this.elClasses" } }, providers: [
1106
1181
  {
1107
1182
  provide: NG_VALUE_ACCESSOR,
1108
1183
  useExisting: forwardRef(() => WrInputComponent),
1109
1184
  multi: true
1185
+ },
1186
+ {
1187
+ provide: NG_VALIDATORS,
1188
+ useExisting: forwardRef(() => WrInputComponent),
1189
+ multi: true
1110
1190
  }
1111
- ], viewQueries: [{ propertyName: "inputElement", first: true, predicate: ["inputElement"], descendants: true, static: true }], exportAs: ["wrInput"], usesInheritance: true, ngImport: i0, template: "<div class=\"wr-input-prefix\" *ngIf=\"prefix\">\n <span class=\"wr-input-prefix__text\">{{ prefix }}</span>\n</div>\n<div class=\"wr-input-el\">\n <div\n *ngIf=\"passwordIcons\"\n class=\"wr-input-el-icon\"\n (click)=\"onPasswordVisibilityChange($event)\"\n >\n <wr-icon class=\"wr-input-el-icon__icon\" [name]=\"eyeOn ? 'eye' : 'eye-off'\"></wr-icon>\n </div>\n <input\n #inputElement\n class=\"wr-input-el__native\"\n [type]=\"type\"\n [value]=\"value\"\n [placeholder]=\"placeholder ? placeholder : ''\"\n [attr.readonly]=\"readonly ? 'readonly' : null\"\n [attr.autofocus]=\"autofocus ? 'autofocus' : null\"\n [attr.disabled]=\"disabled ? 'disabled' : null\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.inputmode]=\"inputmode\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange(value)\"\n />\n</div>\n<div class=\"wr-input-suffix\" *ngIf=\"suffix\">\n <span class=\"wr-input-suffix__text\">{{ suffix }}</span>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: WrIconComponent, selector: "wr-icon[name]", inputs: ["name"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1112
- __decorate([
1113
- InputBoolean()
1114
- ], WrInputComponent.prototype, "disabled", void 0);
1115
- __decorate([
1116
- InputBoolean()
1117
- ], WrInputComponent.prototype, "readonly", void 0);
1118
- __decorate([
1119
- InputBoolean()
1120
- ], WrInputComponent.prototype, "autofocus", void 0);
1191
+ ], viewQueries: [{ propertyName: "inputElement", first: true, predicate: ["inputElement"], descendants: true, static: true }], exportAs: ["wrInput"], usesInheritance: true, ngImport: i0, template: "<div class=\"wr-input-prefix\" *ngIf=\"prefix\">\n <span class=\"wr-input-prefix__text\">{{ prefix }}</span>\n</div>\n<div class=\"wr-input-el\">\n <div *ngIf=\"passwordIcons\" class=\"wr-input-el-icon\" (click)=\"onPasswordVisibilityChange()\">\n <wr-icon class=\"wr-input-el-icon__icon\" [name]=\"eyeOn ? 'eye' : 'eye-off'\"></wr-icon>\n </div>\n <input\n #inputElement\n class=\"wr-input-el__native\"\n [ngModel]=\"valueAsString\"\n [placeholder]=\"placeholder\"\n [disabled]=\"disabled\"\n [readonly]=\"readonly\"\n [type]=\"type\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.inputmode]=\"inputmode\"\n (focus)=\"onFocus($event)\"\n (blur)=\"onBlur($event)\"\n (ngModelChange)=\"value = $event\"\n />\n</div>\n<div class=\"wr-input-suffix\" *ngIf=\"suffix\">\n <span class=\"wr-input-suffix__text\">{{ suffix }}</span>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i2.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i2.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: WrIconComponent, selector: "wr-icon[name]", inputs: ["name"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
1121
1192
  __decorate([
1122
1193
  InputBoolean()
1123
1194
  ], WrInputComponent.prototype, "passwordIcons", void 0);
@@ -1128,13 +1199,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
1128
1199
  provide: NG_VALUE_ACCESSOR,
1129
1200
  useExisting: forwardRef(() => WrInputComponent),
1130
1201
  multi: true
1202
+ },
1203
+ {
1204
+ provide: NG_VALIDATORS,
1205
+ useExisting: forwardRef(() => WrInputComponent),
1206
+ multi: true
1131
1207
  }
1132
- ], template: "<div class=\"wr-input-prefix\" *ngIf=\"prefix\">\n <span class=\"wr-input-prefix__text\">{{ prefix }}</span>\n</div>\n<div class=\"wr-input-el\">\n <div\n *ngIf=\"passwordIcons\"\n class=\"wr-input-el-icon\"\n (click)=\"onPasswordVisibilityChange($event)\"\n >\n <wr-icon class=\"wr-input-el-icon__icon\" [name]=\"eyeOn ? 'eye' : 'eye-off'\"></wr-icon>\n </div>\n <input\n #inputElement\n class=\"wr-input-el__native\"\n [type]=\"type\"\n [value]=\"value\"\n [placeholder]=\"placeholder ? placeholder : ''\"\n [attr.readonly]=\"readonly ? 'readonly' : null\"\n [attr.autofocus]=\"autofocus ? 'autofocus' : null\"\n [attr.disabled]=\"disabled ? 'disabled' : null\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.inputmode]=\"inputmode\"\n [ngModel]=\"value\"\n (ngModelChange)=\"onModelChange(value)\"\n />\n</div>\n<div class=\"wr-input-suffix\" *ngIf=\"suffix\">\n <span class=\"wr-input-suffix__text\">{{ suffix }}</span>\n</div>\n" }]
1133
- }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1$1.FocusMonitor }, { type: i0.NgZone }]; }, propDecorators: { value: [{
1208
+ ], template: "<div class=\"wr-input-prefix\" *ngIf=\"prefix\">\n <span class=\"wr-input-prefix__text\">{{ prefix }}</span>\n</div>\n<div class=\"wr-input-el\">\n <div *ngIf=\"passwordIcons\" class=\"wr-input-el-icon\" (click)=\"onPasswordVisibilityChange()\">\n <wr-icon class=\"wr-input-el-icon__icon\" [name]=\"eyeOn ? 'eye' : 'eye-off'\"></wr-icon>\n </div>\n <input\n #inputElement\n class=\"wr-input-el__native\"\n [ngModel]=\"valueAsString\"\n [placeholder]=\"placeholder\"\n [disabled]=\"disabled\"\n [readonly]=\"readonly\"\n [type]=\"type\"\n [attr.autocomplete]=\"autocomplete\"\n [attr.inputmode]=\"inputmode\"\n (focus)=\"onFocus($event)\"\n (blur)=\"onBlur($event)\"\n (ngModelChange)=\"value = $event\"\n />\n</div>\n<div class=\"wr-input-suffix\" *ngIf=\"suffix\">\n <span class=\"wr-input-suffix__text\">{{ suffix }}</span>\n</div>\n" }]
1209
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i1$1.FocusMonitor }, { type: i0.NgZone }]; }, propDecorators: { placeholder: [{
1134
1210
  type: Input
1135
- }], type: [{
1211
+ }], prefix: [{
1136
1212
  type: Input
1137
- }], autocomplete: [{
1213
+ }], suffix: [{
1214
+ type: Input
1215
+ }], passwordIcons: [{
1216
+ type: Input
1217
+ }], type: [{
1138
1218
  type: Input
1139
1219
  }], inputmode: [{
1140
1220
  type: Input
@@ -1142,15 +1222,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.8", ngImpor
1142
1222
  type: Input
1143
1223
  }], readonly: [{
1144
1224
  type: Input
1145
- }], autofocus: [{
1146
- type: Input
1147
- }], passwordIcons: [{
1225
+ }], required: [{
1148
1226
  type: Input
1149
- }], placeholder: [{
1227
+ }], autofocus: [{
1150
1228
  type: Input
1151
- }], prefix: [{
1229
+ }], autocomplete: [{
1152
1230
  type: Input
1153
- }], suffix: [{
1231
+ }], value: [{
1154
1232
  type: Input
1155
1233
  }], inputElement: [{
1156
1234
  type: ViewChild,