@muziehdesign/forms 0.0.1 → 0.0.397-alpha

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 (39) hide show
  1. package/esm2020/lib/constants.mjs +2 -2
  2. package/esm2020/lib/field-error.mjs +2 -2
  3. package/esm2020/lib/field-errors/field-errors.component.mjs +18 -0
  4. package/esm2020/lib/forms.module.mjs +27 -14
  5. package/esm2020/lib/masks.mjs +62 -0
  6. package/esm2020/lib/model-schema.factory.mjs +126 -58
  7. package/esm2020/lib/model-state-options.mjs +2 -0
  8. package/esm2020/lib/model-state-result.mjs +2 -0
  9. package/esm2020/lib/model-validator.mjs +16 -16
  10. package/esm2020/lib/ng-form-model-state.service.mjs +22 -0
  11. package/esm2020/lib/ngform-model-state.mjs +105 -0
  12. package/esm2020/lib/type-annotations.mjs +81 -0
  13. package/esm2020/muziehdesign-forms.mjs +4 -4
  14. package/esm2020/public-api.mjs +14 -9
  15. package/fesm2015/muziehdesign-forms.mjs +448 -112
  16. package/fesm2015/muziehdesign-forms.mjs.map +1 -1
  17. package/fesm2020/muziehdesign-forms.mjs +440 -112
  18. package/fesm2020/muziehdesign-forms.mjs.map +1 -1
  19. package/index.d.ts +5 -5
  20. package/lib/constants.d.ts +1 -1
  21. package/lib/field-error.d.ts +5 -5
  22. package/lib/field-errors/field-errors.component.d.ts +8 -0
  23. package/lib/forms.module.d.ts +8 -6
  24. package/lib/masks.d.ts +42 -0
  25. package/lib/model-schema.factory.d.ts +14 -10
  26. package/lib/model-state-options.d.ts +4 -0
  27. package/lib/model-state-result.d.ts +6 -0
  28. package/lib/model-validator.d.ts +7 -7
  29. package/lib/ng-form-model-state.service.d.ts +12 -0
  30. package/lib/ngform-model-state.d.ts +25 -0
  31. package/lib/type-annotations.d.ts +116 -0
  32. package/package.json +7 -2
  33. package/public-api.d.ts +10 -5
  34. package/esm2020/lib/property-schema-metadata.mjs +0 -2
  35. package/esm2020/lib/property-type.enum.mjs +0 -8
  36. package/esm2020/lib/string-schema.mjs +0 -27
  37. package/lib/property-schema-metadata.d.ts +0 -6
  38. package/lib/property-type.enum.d.ts +0 -6
  39. package/lib/string-schema.d.ts +0 -15
@@ -1,130 +1,458 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, NgModule } from '@angular/core';
3
- import { object, string, boolean } from 'yup';
2
+ import { Injectable, Component, Input, NgModule } from '@angular/core';
3
+ import * as Yup from 'yup';
4
+ import { object } from 'yup';
4
5
  import 'reflect-metadata';
6
+ import * as i1 from '@angular/common';
7
+ import { CommonModule } from '@angular/common';
8
+ import { FormGroup, FormArray } from '@angular/forms';
9
+ import { BehaviorSubject, switchMap, from } from 'rxjs';
10
+ import { format, parse, isValid } from 'date-fns';
11
+ import * as IMask from 'imask';
5
12
 
6
- class ModelValidator {
7
- constructor(modelSchema) {
8
- this.schema = modelSchema;
9
- }
10
- validate(model) {
11
- return this.schema
12
- .validate(model, { abortEarly: false })
13
- .then(() => {
14
- return [];
15
- })
16
- .catch((e) => {
17
- return e.inner.map((error) => ({ path: error.path, type: error.type, message: error.message }));
18
- });
19
- }
13
+ class ModelValidator {
14
+ constructor(modelSchema) {
15
+ this.schema = modelSchema;
16
+ }
17
+ validate(model) {
18
+ return this.schema
19
+ .validate(model, { abortEarly: false })
20
+ .then(() => {
21
+ return [];
22
+ })
23
+ .catch((e) => {
24
+ return e.inner.map((error) => ({ path: error.path, type: error.type, message: error.message }));
25
+ });
26
+ }
20
27
  }
21
28
 
22
- const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:schema';
29
+ const SCHEMA_METADATA_NAMESPACE = 'custom:muziehdesign:annotations';
23
30
 
24
- var PropertyType;
25
- (function (PropertyType) {
26
- PropertyType[PropertyType["string"] = 0] = "string";
27
- PropertyType[PropertyType["number"] = 1] = "number";
28
- PropertyType[PropertyType["array"] = 2] = "array";
29
- PropertyType[PropertyType["boolean"] = 3] = "boolean";
30
- })(PropertyType || (PropertyType = {}));
31
+ const METADATA_KEY = 'custom:muziehdesign:annotations';
32
+ var ConstraintType;
33
+ (function (ConstraintType) {
34
+ ConstraintType[ConstraintType["string"] = 0] = "string";
35
+ ConstraintType[ConstraintType["boolean"] = 1] = "boolean";
36
+ ConstraintType[ConstraintType["date"] = 2] = "date";
37
+ ConstraintType[ConstraintType["object"] = 3] = "object";
38
+ ConstraintType[ConstraintType["number"] = 4] = "number";
39
+ })(ConstraintType || (ConstraintType = {}));
40
+ const registerMetadata = (target, propertyKey, constraint) => {
41
+ const metadata = Reflect.getMetadata(METADATA_KEY, target) || new Map();
42
+ metadata.set(propertyKey, constraint);
43
+ Reflect.defineMetadata(METADATA_KEY, metadata, target);
44
+ };
45
+ function StringType(...annotations) {
46
+ return function (target, propertyKey) {
47
+ const o = Object.assign({}, ...annotations);
48
+ o.constraintType = ConstraintType.string;
49
+ registerMetadata(target, propertyKey, o);
50
+ };
51
+ }
52
+ function BooleanType(...annotations) {
53
+ return function (target, propertyKey) {
54
+ const o = Object.assign({}, ...annotations);
55
+ o.constraintType = ConstraintType.boolean;
56
+ registerMetadata(target, propertyKey, o);
57
+ };
58
+ }
59
+ function DateType(...annotations) {
60
+ return function (target, propertyKey) {
61
+ const o = Object.assign({}, ...annotations);
62
+ o.constraintType = ConstraintType.date;
63
+ registerMetadata(target, propertyKey, o);
64
+ };
65
+ }
66
+ function NumberType(...annotations) {
67
+ return function (target, propertyKey) {
68
+ const o = Object.assign({}, ...annotations);
69
+ o.constraintType = ConstraintType.number;
70
+ registerMetadata(target, propertyKey, o);
71
+ };
72
+ }
73
+ function ObjectType(type, ...annotations) {
74
+ return function (target, propertyKey) {
75
+ const o = Object.assign({}, ...annotations, { getInstance: () => new type() });
76
+ o.constraintType = ConstraintType.object;
77
+ registerMetadata(target, propertyKey, o);
78
+ };
79
+ }
80
+ function required(message) {
81
+ return { required: { required: true, message: message } };
82
+ }
83
+ function pattern(regex, message) {
84
+ return { pattern: { pattern: regex, message: message } };
85
+ }
86
+ function length(length, message) {
87
+ return { length: { length: length, message: message } };
88
+ }
89
+ function maxLength(maxLength, message) {
90
+ return { maxLength: { maxLength: maxLength, message: message } };
91
+ }
92
+ function minLength(minLength, message) {
93
+ return { minLength: { minLength: minLength, message: message } };
94
+ }
95
+ function ofValues(values, message) {
96
+ return { ofValues: { values: values, message: message } };
97
+ }
98
+ function equals(value, message) {
99
+ return { equals: { equals: value, message: message } };
100
+ }
101
+ function min(value, message) {
102
+ return { min: { min: value, message: message } };
103
+ }
104
+ function max(value, message) {
105
+ return { max: { max: value, message: message } };
106
+ }
107
+ function test(name, test, message) {
108
+ return { test: { name: name, test: test, message: message } };
109
+ }
31
110
 
32
- class ModelSchemaFactory {
33
- constructor() { }
34
- build(model) {
35
- const metadata = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);
36
- let shape = {};
37
- metadata.forEach((element) => {
38
- if (element.type == PropertyType.string) {
39
- shape[element.name] = this.buildStringSchema(element.options || {});
40
- }
41
- else if (element.type == PropertyType.boolean) {
42
- shape[element.name] = this.buildBooleanSchema(element.options || {});
43
- }
44
- });
45
- const schema = object(shape);
46
- return new ModelValidator(schema);
47
- }
48
- buildStringSchema(options) {
49
- let stringSchema = string();
50
- if (options.required) {
51
- stringSchema = stringSchema.required();
52
- }
53
- if (options.length) {
54
- stringSchema = stringSchema.length(options.length);
55
- }
56
- if (options.minimum) {
57
- stringSchema = stringSchema.min(options.minimum);
58
- }
59
- if (options.maximum) {
60
- stringSchema = stringSchema.max(options.maximum);
61
- }
62
- return stringSchema;
63
- }
64
- buildBooleanSchema(options) {
65
- let booleanSchema = boolean();
66
- if (options.equals) {
67
- return booleanSchema.test({
68
- name: 'mustBe',
69
- test: (value) => value == options.equals
70
- });
71
- }
72
- return booleanSchema;
73
- }
74
- }
75
- ModelSchemaFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
76
- ModelSchemaFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, providedIn: 'root' });
77
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, decorators: [{
78
- type: Injectable,
79
- args: [{
80
- providedIn: 'root',
81
- }]
111
+ /*
112
+ Schema rules need to be built in the order they need to be evaluated in.
113
+ For example,
114
+ ```
115
+ schema.required().max(...).matches(...);
116
+ ```
117
+ evaluates the 3 rules in this order
118
+ - required
119
+ - max
120
+ - matches
121
+ */
122
+ class ModelSchemaFactory {
123
+ constructor() { }
124
+ build(model) {
125
+ const schema = this.buildObjectSchema(model);
126
+ return new ModelValidator(schema);
127
+ }
128
+ buildObjectSchema(model) {
129
+ const metadata = Reflect.getMetadata(SCHEMA_METADATA_NAMESPACE, model);
130
+ let shape = {};
131
+ metadata.forEach((value, key) => {
132
+ if (value.constraintType == ConstraintType.string) {
133
+ shape[key] = this.buildStringSchema(value);
134
+ }
135
+ else if (value.constraintType == ConstraintType.boolean) {
136
+ shape[key] = this.buildBooleanSchema(value);
137
+ }
138
+ else if (value.constraintType == ConstraintType.date) {
139
+ shape[key] = this.buildDateSchema(value);
140
+ }
141
+ else if (value.constraintType == ConstraintType.object) {
142
+ shape[key] = this.buildNestedObjectSchema(value);
143
+ }
144
+ else if (value.constraintType == ConstraintType.number) {
145
+ shape[key] = this.buildNumberSchema(value);
146
+ }
147
+ });
148
+ return object(shape);
149
+ }
150
+ buildStringSchema(options) {
151
+ let schema = Yup.string();
152
+ if (options.required) {
153
+ schema = schema.required(options.required.message);
154
+ }
155
+ if (options.length) {
156
+ schema = schema.length(options.length.length, options.length.message);
157
+ }
158
+ if (options.maxLength) {
159
+ schema = schema.max(options.maxLength.maxLength, options.maxLength.message);
160
+ }
161
+ if (options.minLength) {
162
+ schema = schema.min(options.minLength.minLength, options.minLength.message);
163
+ }
164
+ if (options.pattern) {
165
+ schema = schema.matches(options.pattern.pattern, { message: options.pattern.message, excludeEmptyString: true });
166
+ }
167
+ return schema;
168
+ }
169
+ buildBooleanSchema(options) {
170
+ let schema = Yup.boolean();
171
+ if (options.required) {
172
+ schema = schema.required(options.required.message);
173
+ }
174
+ if (options.equals) {
175
+ if (options.equals.equals) {
176
+ schema = schema.isTrue(options.equals.message);
177
+ }
178
+ else {
179
+ schema = schema.isFalse(options.equals.message);
180
+ }
181
+ }
182
+ return schema;
183
+ }
184
+ buildDateSchema(options) {
185
+ let schema = Yup.date();
186
+ if (options.required) {
187
+ schema = schema.required(options.required.message);
188
+ }
189
+ if (options.min) {
190
+ schema = schema.min(options.min.min, options.min.message);
191
+ }
192
+ if (options.max) {
193
+ schema = schema.max(options.max.max, options.max.message);
194
+ }
195
+ if (options.test) {
196
+ schema = schema.test({
197
+ name: options.test.name,
198
+ message: options.test.message,
199
+ test: (d, context) => {
200
+ return options.test.test(d);
201
+ }
202
+ });
203
+ }
204
+ return schema;
205
+ }
206
+ buildNumberSchema(options) {
207
+ let schema = Yup.number();
208
+ if (options.required) {
209
+ schema = schema.required(options.required.message);
210
+ }
211
+ return schema;
212
+ }
213
+ buildNestedObjectSchema(options) {
214
+ let nestedSchema = this.buildObjectSchema(options.getInstance());
215
+ if (options.required) {
216
+ nestedSchema = nestedSchema.required();
217
+ }
218
+ return nestedSchema;
219
+ }
220
+ }
221
+ ModelSchemaFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
222
+ ModelSchemaFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, providedIn: 'root' });
223
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: ModelSchemaFactory, decorators: [{
224
+ type: Injectable,
225
+ args: [{
226
+ providedIn: 'root',
227
+ }]
82
228
  }], ctorParameters: function () { return []; } });
83
229
 
84
- function StringSchema(options) {
85
- return function (target, propertyKey) {
86
- const metadata = Reflect.getMetadata('custom:muziehdesign:schema', target) || [];
87
- metadata.push({
88
- name: propertyKey,
89
- type: PropertyType.string,
90
- options: options,
91
- });
92
- // TODO: define on property
93
- Reflect.defineMetadata('custom:muziehdesign:schema', metadata, target);
94
- };
95
- }
96
- function BooleanSchema(options) {
97
- return function (target, propertyKey) {
98
- const metadata = Reflect.getMetadata('custom:muziehdesign:schema', target) || [];
99
- metadata.push({
100
- name: propertyKey,
101
- type: PropertyType.boolean,
102
- options: options,
103
- });
104
- // TODO: define on property
105
- Reflect.defineMetadata('custom:muziehdesign:schema', metadata, target);
106
- };
230
+ class FieldErrorsComponent {
231
+ get errorMessage() {
232
+ const errorKeys = Object.keys(this.field?.errors || {});
233
+ return errorKeys.length > 0 ? this.field?.errors[errorKeys[0]] : '';
234
+ }
107
235
  }
236
+ FieldErrorsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FieldErrorsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
237
+ FieldErrorsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.0.5", type: FieldErrorsComponent, selector: "mz-field-errors", inputs: { field: "field" }, ngImport: i0, template: "<div class=\"field-error\" *ngIf=\"errorMessage\">{{ errorMessage }}</div>\n", styles: [""], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }] });
238
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FieldErrorsComponent, decorators: [{
239
+ type: Component,
240
+ args: [{ selector: 'mz-field-errors', template: "<div class=\"field-error\" *ngIf=\"errorMessage\">{{ errorMessage }}</div>\n" }]
241
+ }], propDecorators: { field: [{
242
+ type: Input
243
+ }] } });
108
244
 
109
- class FormsModule {
110
- }
111
- FormsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
112
- FormsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.5", ngImport: i0, type: FormsModule });
113
- FormsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule });
114
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, decorators: [{
115
- type: NgModule,
116
- args: [{
117
- providers: []
118
- }]
245
+ class FormsModule {
246
+ }
247
+ FormsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
248
+ FormsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, declarations: [FieldErrorsComponent], imports: [CommonModule // TODO: can remove once done with temp error displaying
249
+ ], exports: [FieldErrorsComponent] });
250
+ FormsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, imports: [CommonModule // TODO: can remove once done with temp error displaying
251
+ ] });
252
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: FormsModule, decorators: [{
253
+ type: NgModule,
254
+ args: [{
255
+ providers: [],
256
+ declarations: [
257
+ FieldErrorsComponent
258
+ ],
259
+ exports: [
260
+ FieldErrorsComponent
261
+ ],
262
+ imports: [
263
+ CommonModule // TODO: can remove once done with temp error displaying
264
+ ]
265
+ }]
119
266
  }] });
120
267
 
121
- /*
122
- * Public API Surface of forms
268
+ class NgFormModelState {
269
+ constructor(form, modelValidator, options) {
270
+ this.form = form;
271
+ this.modelValidator = modelValidator;
272
+ this.options = options;
273
+ this.changesSubject = new BehaviorSubject(undefined);
274
+ this.changes = this.changesSubject.asObservable();
275
+ this.form.form.valueChanges
276
+ .pipe(switchMap(async (x) => {
277
+ return from(this.validate());
278
+ }))
279
+ .subscribe();
280
+ }
281
+ getCurrent() {
282
+ return this.changesSubject.value;
283
+ }
284
+ setState(model, errors) {
285
+ const state = {
286
+ model: model,
287
+ errors: errors,
288
+ valid: errors.length === 0,
289
+ };
290
+ this.setStateInternal(state);
291
+ }
292
+ setErrors(errors) {
293
+ //this.errors.next(errors);
294
+ throw new Error('needs implementation');
295
+ }
296
+ appendErrors(errors, skipEmit) {
297
+ const allErrors = [...(this.changesSubject.value?.errors || []), ...errors];
298
+ const state = { ...this.changesSubject.value };
299
+ state.errors = allErrors;
300
+ this.setStateInternal(state);
301
+ }
302
+ async validate() {
303
+ const model = this.form.value;
304
+ const state = await this.runValidations(model, this.options?.onValidate);
305
+ this.setStateInternal(state);
306
+ return state;
307
+ }
308
+ setStateInternal(state) {
309
+ this.deleteFormErrors();
310
+ const grouped = state.errors.reduce((grouped, v) => grouped.set(v.path, [...(grouped.get(v.path) || []), v]), new Map());
311
+ grouped.forEach((value, path) => {
312
+ let validationErrors = {};
313
+ value.forEach((v) => (validationErrors[v.type] = v.message));
314
+ const control = this.form.form.get(path);
315
+ if (!control) {
316
+ // TODO: use actual logging service
317
+ }
318
+ else {
319
+ control.setErrors(validationErrors);
320
+ }
321
+ });
322
+ this.changesSubject.next(state);
323
+ }
324
+ deleteFormErrors() {
325
+ this.deleteErrors(this.form.form);
326
+ }
327
+ deleteErrors(rootFormGroup) {
328
+ Object.keys(rootFormGroup.controls).forEach((key) => {
329
+ const control = rootFormGroup.controls[key];
330
+ if (!this.isParentControl(control)) {
331
+ this.deleteErrorsFromControl(key, control);
332
+ }
333
+ else if (control instanceof FormGroup) {
334
+ this.deleteErrors(control);
335
+ }
336
+ else if (control instanceof FormArray) {
337
+ this.loopFormArray(control);
338
+ }
339
+ });
340
+ }
341
+ deleteErrorsFromControl(key, control) {
342
+ control.setErrors(null);
343
+ }
344
+ isParentControl(control) {
345
+ return control instanceof FormGroup || control instanceof FormArray;
346
+ }
347
+ loopFormArray(formArray) {
348
+ formArray.controls.forEach((control, index) => {
349
+ if (!this.isParentControl(control)) {
350
+ this.deleteErrorsFromControl(index, control);
351
+ }
352
+ else if (control instanceof FormGroup) {
353
+ this.deleteErrors(control);
354
+ }
355
+ else if (control instanceof FormArray) {
356
+ this.loopFormArray(control);
357
+ }
358
+ });
359
+ }
360
+ async runValidations(model, callback) {
361
+ const list = await this.modelValidator.validate(model);
362
+ const final = callback?.(list) || list;
363
+ return {
364
+ valid: final.length === 0,
365
+ errors: final,
366
+ model: model,
367
+ };
368
+ }
369
+ }
370
+
371
+ class NgFormModelStateFactory {
372
+ constructor(factory) {
373
+ this.factory = factory;
374
+ }
375
+ create(form, model, options) {
376
+ const modelState = new NgFormModelState(form, this.factory.build(model), options);
377
+ return modelState;
378
+ }
379
+ }
380
+ NgFormModelStateFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: NgFormModelStateFactory, deps: [{ token: ModelSchemaFactory }], target: i0.ɵɵFactoryTarget.Injectable });
381
+ NgFormModelStateFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: NgFormModelStateFactory, providedIn: 'root' });
382
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.5", ngImport: i0, type: NgFormModelStateFactory, decorators: [{
383
+ type: Injectable,
384
+ args: [{
385
+ providedIn: 'root',
386
+ }]
387
+ }], ctorParameters: function () { return [{ type: ModelSchemaFactory }]; } });
388
+
389
+ const dateMaskOptions = {
390
+ mask: 'MM/dd/yyyy',
391
+ format: (date) => {
392
+ if (!date) {
393
+ return '';
394
+ }
395
+ return format(date, 'MM/dd/yyyy');
396
+ },
397
+ parse: (str) => {
398
+ const dateRegex = /(0[1-9]|1[0-2])\/(0[1-9]|[12]\d|3[01])\/([12]\d{3})/;
399
+ if (!str.match(dateRegex)) {
400
+ return undefined;
401
+ }
402
+ const parsed = parse(str, 'MM/dd/yyyy', new Date());
403
+ if (isValid(parsed)) {
404
+ return parsed;
405
+ }
406
+ return undefined;
407
+ },
408
+ blocks: {
409
+ // eslint-disable-next-line @typescript-eslint/naming-convention
410
+ MM: {
411
+ mask: IMask.MaskedRange,
412
+ from: 1,
413
+ to: 12,
414
+ },
415
+ // eslint-disable-next-line @typescript-eslint/naming-convention
416
+ dd: {
417
+ mask: IMask.MaskedRange,
418
+ from: 1,
419
+ to: 31,
420
+ },
421
+ // eslint-disable-next-line @typescript-eslint/naming-convention
422
+ yyyy: {
423
+ mask: IMask.MaskedRange,
424
+ from: 1000,
425
+ to: 9999,
426
+ },
427
+ },
428
+ };
429
+ const phoneNumberOptions = {
430
+ mask: '(000) 000-0000',
431
+ };
432
+ const currencyOptions = {
433
+ mask: Number,
434
+ scale: 2,
435
+ thousandsSeparator: ',',
436
+ padFractionalZeros: true,
437
+ radix: '.',
438
+ mapToRadix: ['.'],
439
+ };
440
+ const integerOptions = {
441
+ mask: Number,
442
+ scale: 0,
443
+ thousandsSeparator: ',',
444
+ padFractionalZeros: true,
445
+ radix: '.',
446
+ mapToRadix: ['.'],
447
+ };
448
+
449
+ /*
450
+ * Public API Surface of forms
123
451
  */
124
452
 
125
- /**
126
- * Generated bundle index. Do not edit.
453
+ /**
454
+ * Generated bundle index. Do not edit.
127
455
  */
128
456
 
129
- export { BooleanSchema, FormsModule, ModelSchemaFactory, ModelValidator, StringSchema };
457
+ export { BooleanType, ConstraintType, DateType, FieldErrorsComponent, FormsModule, ModelSchemaFactory, ModelValidator, NgFormModelState, NgFormModelStateFactory, NumberType, ObjectType, StringType, currencyOptions, dateMaskOptions, equals, integerOptions, length, max, maxLength, min, minLength, ofValues, pattern, phoneNumberOptions, required, test };
130
458
  //# sourceMappingURL=muziehdesign-forms.mjs.map