@stemy/ngx-dynamic-form 10.2.33 → 12.0.1

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/bundles/stemy-ngx-dynamic-form.umd.js +1787 -1206
  2. package/bundles/stemy-ngx-dynamic-form.umd.js.map +1 -1
  3. package/esm2015/ngx-dynamic-form/common-types.js +527 -29
  4. package/esm2015/ngx-dynamic-form/components/base/dynamic-form-base.component.js +89 -0
  5. package/esm2015/ngx-dynamic-form/components/dynamic-form/dynamic-form.component.js +91 -0
  6. package/esm2015/ngx-dynamic-form/components/dynamic-form-file/dynamic-form-file.component.js +112 -0
  7. package/esm2015/ngx-dynamic-form/components/dynamic-form-group/dynamic-form-group.component.js +19 -0
  8. package/esm2015/ngx-dynamic-form/components/dynamic-form-input/dynamic-form-input.component.js +69 -0
  9. package/esm2015/ngx-dynamic-form/components/dynamic-form-model/dynamic-form-model.component.js +23 -0
  10. package/esm2015/ngx-dynamic-form/components/dynamic-form-select/dynamic-form-select.component.js +73 -0
  11. package/esm2015/ngx-dynamic-form/components/dynamic-form-static/dynamic-form-static.component.js +20 -0
  12. package/esm2015/ngx-dynamic-form/components/dynamic-forms/dynamic-forms.component.js +134 -0
  13. package/esm2015/ngx-dynamic-form/directives/async-submit.directive.js +6 -17
  14. package/esm2015/ngx-dynamic-form/directives/dynamic-form-control.directive.js +32 -0
  15. package/esm2015/ngx-dynamic-form/directives/dynamic-form-group.directive.js +40 -0
  16. package/esm2015/ngx-dynamic-form/directives/dynamic-form-template.directive.js +38 -0
  17. package/esm2015/ngx-dynamic-form/ngx-dynamic-form.module.js +37 -41
  18. package/esm2015/ngx-dynamic-form/services/dynamic-form.service.js +39 -448
  19. package/esm2015/ngx-dynamic-form/services/form-utilities.js +108 -0
  20. package/esm2015/ngx-dynamic-form/services/open-api.service.js +130 -0
  21. package/esm2015/public_api.js +15 -10
  22. package/esm2015/stemy-ngx-dynamic-form.js +4 -2
  23. package/fesm2015/stemy-ngx-dynamic-form.js +1406 -901
  24. package/fesm2015/stemy-ngx-dynamic-form.js.map +1 -1
  25. package/ngx-dynamic-form/common-types.d.ts +265 -38
  26. package/ngx-dynamic-form/components/base/dynamic-form-base.component.d.ts +45 -0
  27. package/ngx-dynamic-form/components/dynamic-form/dynamic-form.component.d.ts +21 -0
  28. package/ngx-dynamic-form/components/dynamic-form-file/dynamic-form-file.component.d.ts +16 -0
  29. package/ngx-dynamic-form/components/dynamic-form-group/dynamic-form-group.component.d.ts +6 -0
  30. package/ngx-dynamic-form/components/dynamic-form-input/dynamic-form-input.component.d.ts +12 -0
  31. package/ngx-dynamic-form/components/dynamic-form-model/dynamic-form-model.component.d.ts +6 -0
  32. package/ngx-dynamic-form/components/dynamic-form-select/dynamic-form-select.component.d.ts +9 -0
  33. package/ngx-dynamic-form/components/dynamic-form-static/dynamic-form-static.component.d.ts +5 -0
  34. package/ngx-dynamic-form/components/dynamic-forms/dynamic-forms.component.d.ts +26 -0
  35. package/ngx-dynamic-form/directives/async-submit.directive.d.ts +3 -7
  36. package/ngx-dynamic-form/directives/dynamic-form-control.directive.d.ts +12 -0
  37. package/ngx-dynamic-form/directives/dynamic-form-group.directive.d.ts +14 -0
  38. package/ngx-dynamic-form/directives/dynamic-form-template.directive.d.ts +16 -0
  39. package/ngx-dynamic-form/ngx-dynamic-form.module.d.ts +15 -7
  40. package/ngx-dynamic-form/services/dynamic-form.service.d.ts +10 -44
  41. package/ngx-dynamic-form/services/form-utilities.d.ts +19 -0
  42. package/ngx-dynamic-form/services/open-api.service.d.ts +37 -0
  43. package/package.json +16 -17
  44. package/public_api.d.ts +14 -9
  45. package/stemy-ngx-dynamic-form.d.ts +3 -1
  46. package/stemy-ngx-dynamic-form.metadata.json +1 -1
  47. package/bundles/stemy-ngx-dynamic-form.umd.min.js +0 -2
  48. package/bundles/stemy-ngx-dynamic-form.umd.min.js.map +0 -1
  49. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-array.component.js +0 -79
  50. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.js +0 -102
  51. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form-group.component.js +0 -65
  52. package/esm2015/ngx-dynamic-form/components/base/dynamic-base-form.component.js +0 -140
  53. package/esm2015/ngx-dynamic-form/utils/dynamic-form-array.model.js +0 -16
  54. package/esm2015/ngx-dynamic-form/utils/form-select-subject.js +0 -24
  55. package/esm2015/ngx-dynamic-form/utils/form-subject.js +0 -29
  56. package/esm2015/ngx-dynamic-form/utils/misc.js +0 -18
  57. package/esm2015/ngx-dynamic-form/utils/validators.js +0 -56
  58. package/ngx-dynamic-form/components/base/dynamic-base-form-array.component.d.ts +0 -26
  59. package/ngx-dynamic-form/components/base/dynamic-base-form-control-container.component.d.ts +0 -38
  60. package/ngx-dynamic-form/components/base/dynamic-base-form-group.component.d.ts +0 -21
  61. package/ngx-dynamic-form/components/base/dynamic-base-form.component.d.ts +0 -38
  62. package/ngx-dynamic-form/utils/dynamic-form-array.model.d.ts +0 -22
  63. package/ngx-dynamic-form/utils/form-select-subject.d.ts +0 -6
  64. package/ngx-dynamic-form/utils/form-subject.d.ts +0 -10
  65. package/ngx-dynamic-form/utils/misc.d.ts +0 -3
  66. package/ngx-dynamic-form/utils/validators.d.ts +0 -8
@@ -1,163 +1,10 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@stemy/ngx-utils'), require('@ng-dynamic-forms/core'), require('rxjs'), require('@angular/core'), require('@angular/forms'), require('rxjs/operators'), require('@angular/common')) :
3
- typeof define === 'function' && define.amd ? define('@stemy/ngx-dynamic-form', ['exports', '@stemy/ngx-utils', '@ng-dynamic-forms/core', 'rxjs', '@angular/core', '@angular/forms', 'rxjs/operators', '@angular/common'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy['ngx-dynamic-form'] = {}), global.ngxUtils, global.core, global.rxjs, global.ng.core, global.ng.forms, global.rxjs.operators, global.ng.common));
5
- }(this, (function (exports, ngxUtils, core, rxjs, core$1, forms, operators, common) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('@stemy/ngx-utils'), require('@angular/common'), require('rxjs/operators')) :
3
+ typeof define === 'function' && define.amd ? define('@stemy/ngx-dynamic-form', ['exports', '@angular/core', '@angular/forms', '@stemy/ngx-utils', '@angular/common', 'rxjs/operators'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.stemy = global.stemy || {}, global.stemy["ngx-dynamic-form"] = {}), global.ng.core, global.ng.forms, global["@stemy/ngx-utils"], global.ng.common, global.rxjs.operators));
5
+ })(this, (function (exports, core, forms, ngxUtils, common, operators) { 'use strict';
6
6
 
7
- // --- Decorator functions ---
8
- function defaultSerializer(id, parent) {
9
- var control = parent.get(id);
10
- return !control ? null : control.value;
11
- }
12
- function FormSerializable(serializer) {
13
- return function (target, propertyKey) {
14
- ngxUtils.ReflectUtils.defineMetadata("dynamicFormSerializer", serializer || defaultSerializer, target, propertyKey);
15
- };
16
- }
17
- function FormInput(data) {
18
- return function (target, propertyKey) {
19
- var meta = ngxUtils.ReflectUtils.getOwnMetadata("design:type", target, propertyKey);
20
- var type = meta ? meta.name : "";
21
- var inputType = propertyKey.indexOf("password") < 0 ? "text" : "password";
22
- switch (type) {
23
- case "Number":
24
- inputType = "number";
25
- break;
26
- case "Boolean":
27
- inputType = "checkbox";
28
- break;
29
- }
30
- defineFormControl(target, propertyKey, createFormInput(propertyKey, data, inputType));
31
- };
32
- }
33
- function FormSelect(data) {
34
- return function (target, propertyKey) {
35
- defineFormControl(target, propertyKey, createFormSelect(propertyKey, data));
36
- };
37
- }
38
- function FormStatic(data) {
39
- return function (target, propertyKey) {
40
- defineFormControl(target, propertyKey, createFormStatic(propertyKey, data));
41
- };
42
- }
43
- function FormModel(data) {
44
- return function (target, propertyKey) {
45
- defineFormControl(target, propertyKey, createFormModel(propertyKey, data));
46
- };
47
- }
48
- function FormFile(data) {
49
- return function (target, propertyKey) {
50
- defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
51
- };
52
- }
53
- function defineFormControl(target, propertyKey, control) {
54
- ngxUtils.ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
55
- }
56
- function getFormControl(target, propertyKey) {
57
- return ngxUtils.ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
58
- }
59
- function getFormSerializer(target, propertyKey) {
60
- return ngxUtils.ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
61
- }
62
- function createFormControl(id, type, config) {
63
- config = config || { id: id };
64
- config.id = id;
65
- config.label = ngxUtils.ObjectUtils.isNullOrUndefined(config.label) ? id : config.label;
66
- config.disabled = config.disabled || false;
67
- config.hidden = config.hidden || false;
68
- return { id: id, type: type, config: config };
69
- }
70
- function createFormInput(id, config, type) {
71
- if (type === void 0) { type = "text"; }
72
- var control = createFormControl(id, "input", config);
73
- config = control.config;
74
- config.inputType = config.inputType || type;
75
- config.placeholder = config.placeholder || (config.inputType == "mask" ? "_" : "");
76
- config.step = config.step || 1;
77
- config.mask = config.mask || [/\w*/gi];
78
- return control;
79
- }
80
- function createFormSelect(id, data) {
81
- var control = createFormControl(id, "select", data);
82
- data = control.config;
83
- data.options = data.options || [];
84
- return control;
85
- }
86
- function createFormStatic(id, config) {
87
- return createFormControl(id, "static", config);
88
- }
89
- function createFormModel(id, data) {
90
- var control = createFormControl(id, "group", data);
91
- data = control.config;
92
- data.name = data.name || "";
93
- return control;
94
- }
95
- function createFormFile(id, data) {
96
- var control = createFormControl(id, "file", data);
97
- data = control.config;
98
- data.accept = data.accept || ["jpg", "jpeg", "png"];
99
- data.multiple = data.multiple || false;
100
- data.url = ngxUtils.ObjectUtils.isString(data.url) ? data.url : "assets";
101
- return control;
102
- }
103
-
104
- function validateJSON(control) {
105
- var value = control.value;
106
- if (!value)
107
- return null;
108
- try {
109
- JSON.parse(value);
110
- return null;
111
- }
112
- catch (e) {
113
- return { json: true };
114
- }
115
- }
116
- function validateRequiredTranslation(control) {
117
- var value = control.value;
118
- if (!value || value.length == 0)
119
- return { requiredTranslation: true };
120
- return value.findIndex(function (t) { return (t.lang == "de" || t.lang == "en") && !t.translation; }) < 0
121
- ? null
122
- : { requiredTranslation: true };
123
- }
124
- function validatePhone(control) {
125
- var value = control.value;
126
- if (!value)
127
- return Promise.resolve(null);
128
- var phoneRegexp = /^(?:\d){10,12}$/;
129
- return phoneRegexp.test(value) ? null : { phone: true };
130
- }
131
- function validateItemsMinLength(minLength) {
132
- return function (control) {
133
- var value = control.value;
134
- return (Array.isArray(value) && value.every(function (v) { return typeof v == "string" && v.length >= minLength; }))
135
- ? null : { itemsMinLength: minLength };
136
- };
137
- }
138
- function validateItemsMaxLength(maxLength) {
139
- return function (control) {
140
- var value = control.value;
141
- return (Array.isArray(value) && value.every(function (v) { return typeof v == "string" && v.length <= maxLength; }))
142
- ? null : { itemsMaxLength: maxLength };
143
- };
144
- }
145
- function validateItemsMinValue(min) {
146
- return function (control) {
147
- var value = control.value;
148
- return (Array.isArray(value) && value.every(function (v) { return typeof v == "number" && v >= min; }))
149
- ? null : { itemsMinValue: min };
150
- };
151
- }
152
- function validateItemsMaxValue(max) {
153
- return function (control) {
154
- var value = control.value;
155
- return (Array.isArray(value) && value.every(function (v) { return typeof v == "number" && v <= max; }))
156
- ? null : { itemsMaxValue: max };
157
- };
158
- }
159
-
160
- /******************************************************************************
7
+ /*! *****************************************************************************
161
8
  Copyright (c) Microsoft Corporation.
162
9
 
163
10
  Permission to use, copy, modify, and/or distribute this software for any
@@ -319,11 +166,7 @@
319
166
  var __createBinding = Object.create ? (function (o, m, k, k2) {
320
167
  if (k2 === undefined)
321
168
  k2 = k;
322
- var desc = Object.getOwnPropertyDescriptor(m, k);
323
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
324
- desc = { enumerable: true, get: function () { return m[k]; } };
325
- }
326
- Object.defineProperty(o, k2, desc);
169
+ Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
327
170
  }) : (function (o, m, k, k2) {
328
171
  if (k2 === undefined)
329
172
  k2 = k;
@@ -387,16 +230,10 @@
387
230
  r[k] = a[j];
388
231
  return r;
389
232
  }
390
- function __spreadArray(to, from, pack) {
391
- if (pack || arguments.length === 2)
392
- for (var i = 0, l = from.length, ar; i < l; i++) {
393
- if (ar || !(i in from)) {
394
- if (!ar)
395
- ar = Array.prototype.slice.call(from, 0, i);
396
- ar[i] = from[i];
397
- }
398
- }
399
- return to.concat(ar || Array.prototype.slice.call(from));
233
+ function __spreadArray(to, from) {
234
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
235
+ to[j] = from[i];
236
+ return to;
400
237
  }
401
238
  function __await(v) {
402
239
  return this instanceof __await ? (this.v = v, this) : new __await(v);
@@ -462,688 +299,1076 @@
462
299
  function __importDefault(mod) {
463
300
  return (mod && mod.__esModule) ? mod : { default: mod };
464
301
  }
465
- function __classPrivateFieldGet(receiver, state, kind, f) {
466
- if (kind === "a" && !f)
467
- throw new TypeError("Private accessor was defined without a getter");
468
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
469
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
470
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
471
- }
472
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
473
- if (kind === "m")
474
- throw new TypeError("Private method is not writable");
475
- if (kind === "a" && !f)
476
- throw new TypeError("Private accessor was defined without a setter");
477
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
478
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
479
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
480
- }
481
- function __classPrivateFieldIn(state, receiver) {
482
- if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
483
- throw new TypeError("Cannot use 'in' operator on non-object");
484
- return typeof state === "function" ? receiver === state : state.has(receiver);
485
- }
486
-
487
- var DynamicFormArrayModel = /** @class */ (function (_super) {
488
- __extends(DynamicFormArrayModel, _super);
489
- function DynamicFormArrayModel(config, layout) {
490
- var _this = _super.call(this, config, layout) || this;
491
- _this.useTabs = config.useTabs || false;
492
- _this.saveTab = ngxUtils.ObjectUtils.isFunction(config.saveTab) ? config.saveTab : (function (index, model) {
493
- model.tabIndex = index;
494
- });
495
- _this.restoreTab = ngxUtils.ObjectUtils.isFunction(config.restoreTab) ? config.restoreTab : (function (model) {
496
- return model.tabIndex;
497
- });
498
- _this.additional = config.additional || {};
499
- return _this;
500
- }
501
- return DynamicFormArrayModel;
502
- }(core.DynamicFormArrayModel));
503
-
504
- var indexLabels = ["$ix", "$pix"];
505
- var FormSubject = /** @class */ (function (_super) {
506
- __extends(FormSubject, _super);
507
- function FormSubject(notifyCallback) {
508
- var _this = _super.call(this) || this;
509
- _this.notifyCallback = notifyCallback;
510
- return _this;
511
- }
512
- FormSubject.prototype.handleNotifiedValue = function (controlModel, control, val) {
513
- var _this = this;
514
- val.then(function (v) { return _this.next(v); });
515
- };
516
- FormSubject.prototype.notify = function (controlModel, control, root) {
517
- var indexes = {};
518
- var path = controlModel;
519
- var ix = 0;
520
- while (path) {
521
- if (!isNaN(path.index)) {
522
- var key = indexLabels[ix++] || "$pix" + ix;
523
- indexes[key] = path.index;
524
- }
525
- path = path.parent;
526
- }
527
- var value = this.notifyCallback(controlModel, control, root, indexes);
528
- if (!(value instanceof Promise)) {
529
- value = Promise.resolve(value);
530
- }
531
- this.handleNotifiedValue(controlModel, control, value);
532
- };
533
- return FormSubject;
534
- }(rxjs.Subject));
535
-
536
- var FormSelectSubject = /** @class */ (function (_super) {
537
- __extends(FormSelectSubject, _super);
538
- function FormSelectSubject() {
539
- return _super !== null && _super.apply(this, arguments) || this;
302
+ function __classPrivateFieldGet(receiver, privateMap) {
303
+ if (!privateMap.has(receiver)) {
304
+ throw new TypeError("attempted to get private field on non-instance");
540
305
  }
541
- FormSelectSubject.prototype.handleNotifiedValue = function (controlModel, control, val) {
542
- var _this = this;
543
- val.then(function (options) {
544
- var _a, _b;
545
- _this.next(options);
546
- if (options.length == 0)
547
- return;
548
- var currentVal = control.value;
549
- if (controlModel.multiple) {
550
- var correctVal = (currentVal || []).filter(function (t) { return options.findIndex(function (o) { return o.value == t; }) >= 0; });
551
- if (correctVal.length !== (currentVal === null || currentVal === void 0 ? void 0 : currentVal.length)) {
552
- control.setValue(correctVal, { onlySelf: true, emitEvent: false });
553
- }
554
- return;
555
- }
556
- var option = options.find(function (t) { return t.value == currentVal; });
557
- if (!option) {
558
- control.setValue((_b = (_a = options[0]) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null, { onlySelf: true, emitEvent: false });
559
- }
560
- });
561
- };
562
- return FormSelectSubject;
563
- }(FormSubject));
564
-
565
- function isStringWithVal(val) {
566
- return typeof val == "string" && val.length > 0;
306
+ return privateMap.get(receiver);
567
307
  }
568
- function collectPathAble(start, getter) {
569
- if (!start || !getter(start))
570
- return [];
571
- var parts = [];
572
- var currentPath = start;
573
- while (currentPath) {
574
- var val = getter(currentPath);
575
- if (val) {
576
- parts.unshift(val);
577
- }
578
- currentPath = currentPath.parent;
308
+ function __classPrivateFieldSet(receiver, privateMap, value) {
309
+ if (!privateMap.has(receiver)) {
310
+ throw new TypeError("attempted to set private field on non-instance");
579
311
  }
580
- return parts;
312
+ privateMap.set(receiver, value);
313
+ return value;
581
314
  }
582
315
 
583
- var DynamicFormService = /** @class */ (function (_super) {
584
- __extends(DynamicFormService, _super);
585
- function DynamicFormService(cs, vs, openApi, injector) {
586
- var _this = _super.call(this, cs, vs) || this;
587
- _this.openApi = openApi;
588
- _this.injector = injector;
589
- _this.onDetectChanges = new core$1.EventEmitter();
590
- return _this;
316
+ var FORM_GROUP_TYPE = new core.InjectionToken("form-group-provider");
317
+ var FORM_CONTROL_PROVIDER = new core.InjectionToken("form-control-provider");
318
+ var FormControlComponent = /** @class */ (function () {
319
+ function FormControlComponent() {
591
320
  }
592
- Object.defineProperty(DynamicFormService.prototype, "api", {
321
+ Object.defineProperty(FormControlComponent.prototype, "form", {
593
322
  get: function () {
594
- return this.openApi.api;
323
+ return !this.control ? null : this.control.form;
595
324
  },
596
325
  enumerable: false,
597
326
  configurable: true
598
327
  });
599
- Object.defineProperty(DynamicFormService.prototype, "language", {
328
+ Object.defineProperty(FormControlComponent.prototype, "data", {
600
329
  get: function () {
601
- return this.api.language;
330
+ return (!this.control ? {} : this.control.data);
602
331
  },
603
332
  enumerable: false,
604
333
  configurable: true
605
334
  });
606
- DynamicFormService.prototype.patchGroup = function (value, formModel, formGroup) {
607
- this.patchValueRecursive(value, formModel, formGroup);
608
- this.detectChanges();
609
- formGroup.patchValue(ngxUtils.ObjectUtils.copy(value));
610
- };
611
- DynamicFormService.prototype.patchForm = function (value, component) {
612
- this.patchValueRecursive(value, component.model, component.group);
613
- this.detectChanges(component);
614
- component.group.patchValue(value);
615
- };
616
- DynamicFormService.prototype.serialize = function (formModel, formGroup) {
617
- return this.serializeRecursive(formModel, formGroup);
618
- };
619
- DynamicFormService.prototype.notifyChanges = function (formModel, formGroup, root) {
620
- this.notifyChangesRecursive(formModel, formGroup, root);
621
- };
622
- DynamicFormService.prototype.updateSelectOptions = function (formControlModel, formControl, root) {
623
- if (formControlModel instanceof core.DynamicSelectModel) {
624
- var options = formControlModel.options$;
625
- if (options instanceof FormSubject) {
626
- options.notify(formControlModel, formControl, root);
627
- return;
628
- }
629
- while (options instanceof rxjs.Subject && options.source) {
630
- options = options.source;
631
- if (options instanceof FormSubject) {
632
- options.notify(formControlModel, formControl, root);
633
- }
634
- }
635
- }
636
- };
637
- DynamicFormService.prototype.showErrors = function (form) {
638
- this.showErrorsForGroup(form.group);
639
- this.detectChanges(form);
640
- };
641
- DynamicFormService.prototype.detectChanges = function (formComponent) {
642
- _super.prototype.detectChanges.call(this, formComponent);
643
- this.onDetectChanges.emit(formComponent);
644
- };
645
- DynamicFormService.prototype.patchValueRecursive = function (value, formModel, formGroup) {
646
- var _this = this;
647
- Object.keys(value).forEach(function (key) {
648
- var subModel = _this.findModelById(key, formModel);
649
- var subValue = value[key];
650
- if (!subModel)
651
- return;
652
- var subControl = _this.findControlByModel(subModel, formGroup);
653
- if (subModel instanceof core.DynamicSelectModel && ngxUtils.ObjectUtils.isObject(subValue)) {
654
- value[key] = subValue.id || subValue._id || subValue;
655
- return;
656
- }
657
- if (subModel instanceof core.DynamicFormArrayModel) {
658
- var length = Array.isArray(subValue) ? subValue.length : 0;
659
- var subArray = subControl;
660
- while (subModel.size > length) {
661
- _this.removeFormArrayGroup(0, subArray, subModel);
662
- }
663
- while (subModel.size < length) {
664
- _this.insertFormArrayGroup(subModel.size, subArray, subModel);
665
- }
666
- for (var i = 0; i < length; i++) {
667
- var itemModel = subModel.get(i);
668
- _this.patchValueRecursive(subValue[i], itemModel.group, subArray.at(i));
669
- }
335
+ Object.defineProperty(FormControlComponent.prototype, "value", {
336
+ get: function () {
337
+ return !this.control ? null : this.control.value;
338
+ },
339
+ enumerable: false,
340
+ configurable: true
341
+ });
342
+ Object.defineProperty(FormControlComponent.prototype, "meta", {
343
+ get: function () {
344
+ return !this.control ? null : this.control.meta;
345
+ },
346
+ enumerable: false,
347
+ configurable: true
348
+ });
349
+ Object.defineProperty(FormControlComponent.prototype, "testId", {
350
+ get: function () {
351
+ var _a, _b;
352
+ var prefix = ((_a = this.form) === null || _a === void 0 ? void 0 : _a.testId) || "form";
353
+ return prefix + "-" + (((_b = this.control) === null || _b === void 0 ? void 0 : _b.id) || "ctrl");
354
+ },
355
+ enumerable: false,
356
+ configurable: true
357
+ });
358
+ Object.defineProperty(FormControlComponent.prototype, "inputClass", {
359
+ get: function () {
360
+ return true;
361
+ },
362
+ enumerable: false,
363
+ configurable: true
364
+ });
365
+ return FormControlComponent;
366
+ }());
367
+ FormControlComponent.decorators = [
368
+ { type: core.Directive }
369
+ ];
370
+ FormControlComponent.propDecorators = {
371
+ inputClass: [{ type: core.HostBinding, args: ["class.form-input",] }]
372
+ };
373
+ function createValidator(control) {
374
+ var data = control.data || {};
375
+ var validators = [data.validator].concat(data.validators || []).filter(ngxUtils.ObjectUtils.isDefined).map(function (v) {
376
+ return ngxUtils.ReflectUtils.resolve(v, control.injector);
377
+ });
378
+ return function (ctrl) { return new Promise(function (resolve) {
379
+ var control = ctrl;
380
+ control.shouldValidate().then(function (should) {
381
+ if (!should) {
382
+ resolve(null);
670
383
  return;
671
384
  }
672
- if (subModel instanceof core.DynamicFormGroupModel) {
673
- _this.patchValueRecursive(subValue, subModel.group, subControl);
385
+ var validate = validators.map(function (v) { return v(control); });
386
+ var metaValidator = control.meta.validator;
387
+ if (ngxUtils.ObjectUtils.isFunction(metaValidator)) {
388
+ validate.push(metaValidator(control));
674
389
  }
675
- });
676
- };
677
- DynamicFormService.prototype.serializeRecursive = function (formModel, formGroup) {
678
- var _a, _b;
679
- return __awaiter(this, void 0, void 0, function () {
680
- var result, _c, _d, _i, i, subModel, subControl, serializer, _e, _f, length, subArray, resArray, i_1, itemModel, _g, _h, _j, _k;
681
- return __generator(this, function (_l) {
682
- switch (_l.label) {
683
- case 0:
684
- result = {};
685
- if (!formModel || !formGroup || !formGroup.value)
686
- return [2 /*return*/, result];
687
- _c = [];
688
- for (_d in formModel)
689
- _c.push(_d);
690
- _i = 0;
691
- _l.label = 1;
692
- case 1:
693
- if (!(_i < _c.length)) return [3 /*break*/, 12];
694
- i = _c[_i];
695
- subModel = formModel[i];
696
- subControl = this.findControlByModel(subModel, formGroup);
697
- serializer = (_a = subModel.additional) === null || _a === void 0 ? void 0 : _a.serializer;
698
- if (!ngxUtils.ObjectUtils.isFunction(serializer)) return [3 /*break*/, 3];
699
- _e = result;
700
- _f = subModel.id;
701
- return [4 /*yield*/, serializer(subModel, subControl)];
702
- case 2:
703
- _e[_f] = _l.sent();
704
- return [3 /*break*/, 11];
705
- case 3:
706
- if (!(subModel instanceof core.DynamicFormArrayModel)) return [3 /*break*/, 8];
707
- length = Array.isArray(subControl.value) ? subControl.value.length : 0;
708
- subArray = subControl;
709
- resArray = [];
710
- i_1 = 0;
711
- _l.label = 4;
712
- case 4:
713
- if (!(i_1 < length)) return [3 /*break*/, 7];
714
- itemModel = subModel.get(i_1);
715
- _h = (_g = resArray).push;
716
- return [4 /*yield*/, this.serializeRecursive(itemModel.group, subArray.at(i_1))];
717
- case 5:
718
- _h.apply(_g, [_l.sent()]);
719
- _l.label = 6;
720
- case 6:
721
- i_1++;
722
- return [3 /*break*/, 4];
723
- case 7:
724
- result[subModel.id] = resArray;
725
- return [3 /*break*/, 11];
726
- case 8:
727
- if (!(subModel instanceof core.DynamicFormGroupModel)) return [3 /*break*/, 10];
728
- _j = result;
729
- _k = subModel.id;
730
- return [4 /*yield*/, this.serializeRecursive(subModel.group, subControl)];
731
- case 9:
732
- _j[_k] = _l.sent();
733
- return [3 /*break*/, 11];
734
- case 10:
735
- if (subModel instanceof core.DynamicInputModel && !ngxUtils.ObjectUtils.isNullOrUndefined(subControl.value)) {
736
- result[subModel.id] = subModel.inputType == "number"
737
- ? (_b = parseFloat(("" + subControl.value || "0").replace(/,/gi, "."))) !== null && _b !== void 0 ? _b : null : subControl.value;
738
- return [3 /*break*/, 11];
390
+ Promise.all(validate).then(function (results) {
391
+ results = results.filter(function (error) { return ngxUtils.ObjectUtils.isObject(error) || ngxUtils.ObjectUtils.isString(error); });
392
+ var result = null;
393
+ if (results.length > 0) {
394
+ result = {};
395
+ results.forEach(function (error) {
396
+ if (ngxUtils.ObjectUtils.isString(error)) {
397
+ result[error] = {};
398
+ return;
739
399
  }
740
- result[subModel.id] = subControl.value;
741
- _l.label = 11;
742
- case 11:
743
- _i++;
744
- return [3 /*break*/, 1];
745
- case 12: return [2 /*return*/, result];
400
+ result = Object.assign(result, error);
401
+ });
746
402
  }
403
+ resolve(result);
747
404
  });
748
405
  });
749
- };
750
- DynamicFormService.prototype.notifyChangesRecursive = function (formModel, formGroup, root) {
751
- if (!formModel || !formGroup)
752
- return;
753
- for (var i in formModel) {
754
- var subModel = formModel[i];
755
- var subControl = this.findControlByModel(subModel, formGroup);
756
- if (subModel instanceof core.DynamicFormArrayModel) {
757
- var length = Array.isArray(subControl.value) ? subControl.value.length : 0;
758
- var subArray = subControl;
759
- for (var i_2 = 0; i_2 < length; i_2++) {
760
- var itemModel = subModel.get(i_2);
761
- this.notifyChangesRecursive(itemModel.group, subArray.at(i_2), root);
762
- }
763
- continue;
764
- }
765
- if (subModel instanceof core.DynamicFormGroupModel) {
766
- this.notifyChangesRecursive(subModel.group, subControl, root);
767
- continue;
768
- }
769
- this.updateSelectOptions(subModel, subControl, root);
770
- }
771
- };
772
- DynamicFormService.prototype.showErrorsForGroup = function (formGroup) {
773
- if (!formGroup)
774
- return;
775
- formGroup.markAsTouched({ onlySelf: true });
776
- var controls = Object.keys(formGroup.controls).map(function (id) { return formGroup.controls[id]; });
777
- this.showErrorsForControls(controls);
778
- };
779
- DynamicFormService.prototype.showErrorsForControls = function (controls) {
780
- var _this = this;
781
- controls.forEach(function (control) {
782
- if (control instanceof forms.FormGroup) {
783
- _this.showErrorsForGroup(control);
784
- return;
785
- }
786
- control.markAsTouched({ onlySelf: true });
787
- if (control instanceof forms.FormArray) {
788
- _this.showErrorsForControls(control.controls);
789
- }
406
+ }); };
407
+ }
408
+ var DynamicFormControlHelper = /** @class */ (function () {
409
+ function DynamicFormControlHelper(form, control) {
410
+ if (control === void 0) { control = null; }
411
+ this.form = form;
412
+ this.control = control;
413
+ this.formId = ngxUtils.UniqueUtils.uuid();
414
+ this.meta = {};
415
+ this.hidden = false;
416
+ this.dummyData = {};
417
+ this.readonlyTester = this.createTester("readonly");
418
+ this.hideTester = this.createTester("hidden");
419
+ this.serializeTester = this.createTester("shouldSerialize", function (control) {
420
+ return Promise.resolve(control.visible);
790
421
  });
422
+ this.validateTester = this.createTester("shouldValidate", function (control) {
423
+ return Promise.resolve(control.visible);
424
+ });
425
+ }
426
+ Object.defineProperty(DynamicFormControlHelper.prototype, "id", {
427
+ get: function () {
428
+ return !this.control ? null : this.control.id;
429
+ },
430
+ enumerable: false,
431
+ configurable: true
432
+ });
433
+ Object.defineProperty(DynamicFormControlHelper.prototype, "type", {
434
+ get: function () {
435
+ return !this.control ? "" : this.control.type;
436
+ },
437
+ enumerable: false,
438
+ configurable: true
439
+ });
440
+ Object.defineProperty(DynamicFormControlHelper.prototype, "data", {
441
+ get: function () {
442
+ return !this.control ? this.dummyData : this.control.data || this.dummyData;
443
+ },
444
+ enumerable: false,
445
+ configurable: true
446
+ });
447
+ Object.defineProperty(DynamicFormControlHelper.prototype, "visible", {
448
+ get: function () {
449
+ return !this.hidden;
450
+ },
451
+ enumerable: false,
452
+ configurable: true
453
+ });
454
+ Object.defineProperty(DynamicFormControlHelper.prototype, "provider", {
455
+ get: function () {
456
+ return this.ctrlProvider;
457
+ },
458
+ enumerable: false,
459
+ configurable: true
460
+ });
461
+ DynamicFormControlHelper.prototype.load = function (control) {
462
+ return !this.ctrlProvider ? Promise.resolve(null) : this.ctrlProvider.loader(control);
791
463
  };
792
- DynamicFormService.prototype.getFormModelForSchema = function (name, customizeModel) {
793
- return __awaiter(this, void 0, void 0, function () {
794
- var _c, customizeModels;
795
- var _this = this;
796
- return __generator(this, function (_d) {
797
- switch (_d.label) {
798
- case 0:
799
- this.api.cache = {};
800
- _c = this;
801
- return [4 /*yield*/, this.openApi.getSchemas()];
802
- case 1:
803
- _c.schemas = _d.sent();
804
- customizeModels = function (property, schema, modelType, config) {
805
- var model = new modelType(config);
806
- if (!ngxUtils.ObjectUtils.isFunction(customizeModel))
807
- return [model];
808
- var res = customizeModel(property, schema, model, config, _this.injector);
809
- return Array.isArray(res) ? res : [res];
810
- };
811
- return [2 /*return*/, this.getFormModelForSchemaDef(this.schemas[name], customizeModels)];
812
- }
464
+ DynamicFormControlHelper.prototype.check = function (control) {
465
+ var _this = this;
466
+ return new Promise(function (resolve) {
467
+ _this.hideTester(control).then(function (hide) {
468
+ _this.hidden = hide;
469
+ _this.readonlyTester(control).then(function (readonly) {
470
+ resolve(control.form.readonly || readonly);
471
+ });
813
472
  });
814
473
  });
815
474
  };
816
- DynamicFormService.prototype.getFormModelForSchemaDef = function (schema, customizeModels) {
817
- var e_1, _c;
818
- if (!schema)
819
- return [];
820
- var keys = Object.keys(schema.properties || {});
821
- var controls = [];
822
- try {
823
- for (var keys_1 = __values(keys), keys_1_1 = keys_1.next(); !keys_1_1.done; keys_1_1 = keys_1.next()) {
824
- var p = keys_1_1.value;
825
- var property = schema.properties[p];
826
- controls.push.apply(controls, __spread(this.getFormControlModels(property, schema, customizeModels)));
827
- }
828
- }
829
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
830
- finally {
831
- try {
832
- if (keys_1_1 && !keys_1_1.done && (_c = keys_1.return)) _c.call(keys_1);
833
- }
834
- finally { if (e_1) throw e_1.error; }
835
- }
836
- return controls.filter(function (t) { return null !== t; });
837
- };
838
- DynamicFormService.prototype.getFormControlModels = function (property, schema, customizeModels) {
839
- var _a, _b;
840
- var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
841
- if (Array.isArray($enum) || isStringWithVal(property.optionsPath) || isStringWithVal(property.endpoint)) {
842
- return customizeModels(property, schema, core.DynamicSelectModel, this.getFormSelectConfig(property, schema));
843
- }
844
- switch (property.type) {
845
- case "string":
846
- case "number":
847
- case "integer":
848
- return customizeModels(property, schema, core.DynamicInputModel, this.getFormInputConfig(property, schema));
849
- case "textarea":
850
- return customizeModels(property, schema, core.DynamicTextAreaModel, this.getFormTextareaConfig(property, schema));
851
- case "boolean":
852
- return customizeModels(property, schema, core.DynamicCheckboxModel, this.getFormCheckboxConfig(property, schema));
853
- case "array":
854
- if (((_b = property.items) === null || _b === void 0 ? void 0 : _b.$ref) || property.$ref) {
855
- return customizeModels(property, schema, DynamicFormArrayModel, this.getFormArrayConfig(property, schema, customizeModels));
856
- }
857
- else {
858
- return customizeModels(property, schema, core.DynamicInputModel, this.getFormInputConfig(property, schema));
859
- }
860
- case "file":
861
- return customizeModels(property, schema, core.DynamicFileUploadModel, this.getFormUploadConfig(property, schema));
862
- }
863
- if (property.$ref) {
864
- return customizeModels(property, schema, core.DynamicFormGroupModel, this.getFormGroupConfig(property, schema, customizeModels));
865
- }
866
- return [];
867
- };
868
- DynamicFormService.prototype.findModelByPath = function (parent, path) {
869
- if (path.length == 0)
870
- return parent;
871
- var next = path.shift();
872
- if (Array.isArray(parent)) {
873
- return this.findModelByPath(parent.find(function (t) { return t.id == next; }), path);
874
- }
875
- if (parent instanceof core.DynamicFormGroupModel) {
876
- return this.findModelByPath(parent.group.find(function (t) { return t.id == next; }), path);
877
- }
878
- if (parent instanceof DynamicFormArrayModel) {
879
- return this.findModelByPath(parent.groups.find(function (t) { return t.index == next; }), path);
880
- }
881
- return parent;
475
+ DynamicFormControlHelper.prototype.shouldSerialize = function (control) {
476
+ return this.serializeTester(control);
882
477
  };
883
- DynamicFormService.prototype.getFormControlConfig = function (property, schema) {
884
- var validators = this.getValidators(property, schema);
885
- var errorMessages = Object.keys(validators).reduce(function (res, key) {
886
- res[key] = "error." + key;
887
- return res;
888
- }, {});
889
- return {
890
- id: property.id,
891
- label: ngxUtils.ObjectUtils.isString(property.label) ? property.label : property.id,
892
- hidden: property.hidden,
893
- disabled: property.disabled,
894
- validators: validators,
895
- errorMessages: errorMessages,
896
- additional: Object.assign({}, property)
897
- };
478
+ DynamicFormControlHelper.prototype.shouldValidate = function (control) {
479
+ return this.validateTester(control);
898
480
  };
899
- DynamicFormService.prototype.getFormArrayConfig = function (property, schema, customizeModels) {
900
- var _this = this;
901
- var _a;
902
- var ref = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref) || property.$ref || "";
903
- var subSchema = this.schemas[ref.split("/").pop()];
904
- return Object.assign(this.getFormControlConfig(property, schema), {
905
- groupFactory: function () { return _this.getFormModelForSchemaDef(subSchema, customizeModels); },
906
- useTabs: property.useTabs || false
907
- });
481
+ DynamicFormControlHelper.prototype.findProvider = function (control) {
482
+ this.ctrlProvider = !this.control || !this.control.type ? null : this.form.findProvider(control);
908
483
  };
909
- DynamicFormService.prototype.getFormGroupConfig = function (property, schema, customizeModels) {
910
- var ref = property.$ref || "";
911
- var subSchema = this.schemas[ref.split("/").pop()];
912
- return Object.assign(this.getFormControlConfig(property, schema), { group: this.getFormModelForSchemaDef(subSchema, customizeModels) });
484
+ DynamicFormControlHelper.prototype.createTester = function (test, defaultFunc) {
485
+ if (defaultFunc === void 0) { defaultFunc = null; }
486
+ var tester = this.data[test]
487
+ ? ngxUtils.ReflectUtils.resolve(this.data[test], this.form.injector)
488
+ : (defaultFunc || (function () { return Promise.resolve(false); }));
489
+ return function (control) { return tester(control); };
913
490
  };
914
- DynamicFormService.prototype.getFormInputConfig = function (property, schema) {
915
- var _a;
916
- var inputType = ngxUtils.StringUtils.has(property.id, "password", "Password") ? "password" : (property.format || ((_a = property.items) === null || _a === void 0 ? void 0 : _a.type) || property.type);
917
- switch (inputType) {
918
- case "boolean":
919
- inputType = "checkbox";
920
- break;
921
- case "textarea":
922
- inputType = "textarea";
923
- break;
924
- case "integer":
925
- inputType = "number";
926
- break;
491
+ return DynamicFormControlHelper;
492
+ }());
493
+ var DynamicFormGroup = /** @class */ (function (_super) {
494
+ __extends(DynamicFormGroup, _super);
495
+ function DynamicFormGroup(form, control) {
496
+ if (control === void 0) { control = null; }
497
+ var _this = _super.call(this, {}, { updateOn: ((!control || !control.data) ? null : control.data.updateOn) || form.updateOn || "blur" }) || this;
498
+ _this.form = form;
499
+ _this.mName = "";
500
+ _this.mModel = {};
501
+ _this.mControls = [];
502
+ _this.mSerializers = [];
503
+ _this.mFieldSets = {};
504
+ _this.helper = new DynamicFormControlHelper(form, control);
505
+ _this.helper.findProvider(_this);
506
+ _this.initialized = false;
507
+ _this.loading = false;
508
+ _this.changeTimer = ngxUtils.TimerUtils.createTimeout();
509
+ _this.statusChanges.subscribe(function () {
510
+ var root = _this.form.root;
511
+ root.onStatusChange.emit(root);
512
+ });
513
+ _this.setAsyncValidators(createValidator(_this));
514
+ return _this;
515
+ }
516
+ Object.defineProperty(DynamicFormGroup.prototype, "id", {
517
+ get: function () {
518
+ return this.helper.id;
519
+ },
520
+ enumerable: false,
521
+ configurable: true
522
+ });
523
+ Object.defineProperty(DynamicFormGroup.prototype, "type", {
524
+ get: function () {
525
+ return this.helper.type;
526
+ },
527
+ enumerable: false,
528
+ configurable: true
529
+ });
530
+ Object.defineProperty(DynamicFormGroup.prototype, "data", {
531
+ get: function () {
532
+ return this.helper.data;
533
+ },
534
+ enumerable: false,
535
+ configurable: true
536
+ });
537
+ Object.defineProperty(DynamicFormGroup.prototype, "visible", {
538
+ get: function () {
539
+ return this.helper.visible;
540
+ },
541
+ enumerable: false,
542
+ configurable: true
543
+ });
544
+ Object.defineProperty(DynamicFormGroup.prototype, "meta", {
545
+ get: function () {
546
+ return this.helper.meta;
547
+ },
548
+ enumerable: false,
549
+ configurable: true
550
+ });
551
+ Object.defineProperty(DynamicFormGroup.prototype, "injector", {
552
+ get: function () {
553
+ return this.form.injector;
554
+ },
555
+ enumerable: false,
556
+ configurable: true
557
+ });
558
+ Object.defineProperty(DynamicFormGroup.prototype, "label", {
559
+ get: function () {
560
+ return this.data.label !== "" ? "" + this.prefix + this.data.label : "";
561
+ },
562
+ enumerable: false,
563
+ configurable: true
564
+ });
565
+ Object.defineProperty(DynamicFormGroup.prototype, "provider", {
566
+ get: function () {
567
+ return this.helper.provider;
568
+ },
569
+ enumerable: false,
570
+ configurable: true
571
+ });
572
+ Object.defineProperty(DynamicFormGroup.prototype, "model", {
573
+ get: function () {
574
+ return this.mModel;
575
+ },
576
+ enumerable: false,
577
+ configurable: true
578
+ });
579
+ Object.defineProperty(DynamicFormGroup.prototype, "formId", {
580
+ get: function () {
581
+ return this.helper.formId;
582
+ },
583
+ enumerable: false,
584
+ configurable: true
585
+ });
586
+ Object.defineProperty(DynamicFormGroup.prototype, "formControls", {
587
+ get: function () {
588
+ return this.mControls || [];
589
+ },
590
+ enumerable: false,
591
+ configurable: true
592
+ });
593
+ Object.defineProperty(DynamicFormGroup.prototype, "formFields", {
594
+ get: function () {
595
+ return this.mFieldSets || {};
596
+ },
597
+ enumerable: false,
598
+ configurable: true
599
+ });
600
+ Object.defineProperty(DynamicFormGroup.prototype, "prefix", {
601
+ get: function () {
602
+ return !this.name ? "" : this.name + ".";
603
+ },
604
+ enumerable: false,
605
+ configurable: true
606
+ });
607
+ Object.defineProperty(DynamicFormGroup.prototype, "name", {
608
+ get: function () {
609
+ return this.mName;
610
+ },
611
+ enumerable: false,
612
+ configurable: true
613
+ });
614
+ Object.defineProperty(DynamicFormGroup.prototype, "state", {
615
+ get: function () {
616
+ return (this.loading ? "LOADING" : this.status);
617
+ },
618
+ enumerable: false,
619
+ configurable: true
620
+ });
621
+ DynamicFormGroup.createFormControls = function (group, controls) {
622
+ if (!controls && ngxUtils.ObjectUtils.isObject(group.model)) {
623
+ var props = Object.keys(group.model);
624
+ controls = props.map(function (id) {
625
+ return getFormControl(group.model, id);
626
+ }).filter(ngxUtils.ObjectUtils.isDefined);
927
627
  }
928
- var sub = property.type == "array" ? property.items || property : property;
929
- return Object.assign(this.getFormControlConfig(property, schema), {
930
- inputType: inputType,
931
- autoComplete: property.autoComplete || "off",
932
- multiple: property.type == "array",
933
- accept: ngxUtils.ObjectUtils.isString(property.accept) ? property.accept : null,
934
- mask: ngxUtils.ObjectUtils.isString(property.mask) ? property.mask : null,
935
- pattern: ngxUtils.ObjectUtils.isString(property.pattern) ? property.pattern : null,
936
- step: isNaN(sub.step) ? (isNaN(property.step) ? 1 : property.step) : sub.step,
937
- min: isNaN(sub.minimum) ? Number.MIN_SAFE_INTEGER : sub.minimum,
938
- max: isNaN(sub.maximum) ? Number.MAX_SAFE_INTEGER : sub.maximum,
939
- minLength: isNaN(sub.minLength) ? Number.MIN_SAFE_INTEGER : sub.minLength,
940
- maxLength: isNaN(sub.maxLength) ? Number.MAX_SAFE_INTEGER : sub.maxLength,
941
- placeholder: property.placeholder || ""
628
+ if (!controls)
629
+ return [];
630
+ return controls.map(function (ctrl) {
631
+ if (ctrl.type == "model") {
632
+ var subGroup = new DynamicFormGroup(group.form, ctrl);
633
+ var model = group.model[ctrl.id] || {};
634
+ var data = subGroup.getData();
635
+ data.name = data.name || group.name;
636
+ subGroup.setup(model, data);
637
+ group.model[ctrl.id] = model;
638
+ group.addControl(subGroup.id, subGroup);
639
+ return subGroup;
640
+ }
641
+ return new DynamicFormControl(ctrl, group);
942
642
  });
943
643
  };
944
- DynamicFormService.prototype.getFormTextareaConfig = function (property, schema) {
945
- return Object.assign(this.getFormControlConfig(property, schema), {
946
- cols: property.cols || null,
947
- rows: property.rows || 10,
948
- wrap: property.wrap || false,
949
- autoComplete: property.autoComplete || "off",
950
- multiple: property.type == "array"
644
+ DynamicFormGroup.createFormSerializers = function (group, serializers) {
645
+ if (!serializers && ngxUtils.ObjectUtils.isObject(group.model)) {
646
+ var props = Object.keys(group.model);
647
+ serializers = props.reduce(function (result, id) {
648
+ var serializer = getFormSerializer(group.model, id);
649
+ if (!serializer)
650
+ return result;
651
+ result[id] = serializer;
652
+ return result;
653
+ }, {});
654
+ }
655
+ if (!serializers)
656
+ return [];
657
+ return Object.keys(serializers).map(function (id) {
658
+ var serializer = serializers[id] || defaultSerializer;
659
+ return !serializer ? null : {
660
+ id: id,
661
+ func: ngxUtils.ReflectUtils.resolve(serializer, group.injector)
662
+ };
951
663
  });
952
664
  };
953
- DynamicFormService.prototype.getFormSelectConfig = function (property, schema) {
954
- return Object.assign(this.getFormControlConfig(property, schema), {
955
- options: this.getFormSelectOptions(property, schema),
956
- multiple: property.type == "array"
665
+ DynamicFormGroup.prototype.getData = function () {
666
+ return this.data;
667
+ };
668
+ DynamicFormGroup.prototype.getControl = function (id) {
669
+ return this.get(id);
670
+ };
671
+ DynamicFormGroup.prototype.load = function () {
672
+ var promises = this.mControls.map(function (c) { return c.load(); });
673
+ promises.push(this.helper.load(this));
674
+ return Promise.all(promises);
675
+ };
676
+ DynamicFormGroup.prototype.check = function () {
677
+ var _this = this;
678
+ return new Promise(function (resolve) {
679
+ _this.helper.check(_this).then(function (readonly) {
680
+ if (readonly)
681
+ _this.disable({ emitEvent: false });
682
+ else
683
+ _this.enable({ emitEvent: false });
684
+ var promises = _this.mControls.map(function (c) { return c.check(); });
685
+ Promise.all(promises).then(resolve);
686
+ });
687
+ });
688
+ };
689
+ DynamicFormGroup.prototype.shouldSerialize = function () {
690
+ return this.helper.shouldSerialize(this);
691
+ };
692
+ DynamicFormGroup.prototype.shouldValidate = function () {
693
+ return this.helper.shouldValidate(this);
694
+ };
695
+ DynamicFormGroup.prototype.serialize = function () {
696
+ var _this = this;
697
+ return new Promise(function (resolve) {
698
+ var result = {};
699
+ var serializers = _this.mSerializers.map(function (s) {
700
+ return new Promise(function (resolve) {
701
+ s.func(s.id, _this).then(function (res) {
702
+ var ctrl = _this.getControl(s.id);
703
+ var promise = !ctrl ? Promise.resolve(true) : ctrl.shouldSerialize();
704
+ promise.then(function (should) {
705
+ if (should)
706
+ result[s.id] = res;
707
+ resolve(null);
708
+ });
709
+ });
710
+ });
711
+ });
712
+ Promise.all(serializers).then(function () { return resolve(result); });
713
+ });
714
+ };
715
+ DynamicFormGroup.prototype.onFocus = function () {
716
+ this.markAsUntouched({ onlySelf: true });
717
+ };
718
+ DynamicFormGroup.prototype.onBlur = function () {
719
+ this.markAsTouched({ onlySelf: true });
720
+ };
721
+ DynamicFormGroup.prototype.showErrors = function () {
722
+ this.markAsTouched({ onlySelf: true });
723
+ this.mControls.forEach(function (ctrl) { return ctrl.showErrors(); });
724
+ };
725
+ DynamicFormGroup.prototype.reloadControls = function () {
726
+ var _this = this;
727
+ var callback = function () { };
728
+ if (this.initialized === false) {
729
+ this.initialized = true;
730
+ this.loading = true;
731
+ callback = function () {
732
+ _this.loading = false;
733
+ // this.cdr.detectChanges();
734
+ var root = _this.form.root;
735
+ root.onInit.emit(root);
736
+ root.onStatusChange.emit(root);
737
+ // https://github.com/angular/angular/issues/14542
738
+ var statusTimer = ngxUtils.TimerUtils.createInterval();
739
+ statusTimer.set(function () {
740
+ if (_this.status == "PENDING")
741
+ return;
742
+ statusTimer.clear();
743
+ root.onStatusChange.emit(root);
744
+ }, 50);
745
+ setTimeout(statusTimer.clear, 5000);
746
+ };
747
+ }
748
+ var promise = new Promise(function (resolve) {
749
+ _this.load().then(function () { return _this.check().then(resolve); });
750
+ });
751
+ promise.then(callback, callback);
752
+ return promise;
753
+ };
754
+ DynamicFormGroup.prototype.setup = function (model, info) {
755
+ var _this = this;
756
+ this.mName = info.name || "";
757
+ this.mModel = model;
758
+ this.mControls.forEach(function (ctrl) { return _this.removeControl(ctrl.id); });
759
+ this.mControls = DynamicFormGroup.createFormControls(this, info.controls);
760
+ this.mControls.forEach(function (ctrl) { return _this.addControl(ctrl.id, ctrl); });
761
+ this.mSerializers = DynamicFormGroup.createFormSerializers(this, info.serializers);
762
+ this.mFieldSets = info.fieldSets ? info.fieldSets.reduce(function (result, fs) {
763
+ result[fs.id] = fs;
764
+ return result;
765
+ }, {}) : getFormFieldSets(Object.getPrototypeOf(model).constructor);
766
+ };
767
+ DynamicFormGroup.prototype.updateModel = function (control) {
768
+ var _this = this;
769
+ this.model[control.id] = control.value;
770
+ this.changeTimer.clear();
771
+ this.changeTimer.set(function () {
772
+ _this.check().then(function () { return _this.reloadControlsFrom(control, new Set()).then(function () {
773
+ _this.form.root.onChange.emit(control);
774
+ }); });
775
+ }, 250);
776
+ };
777
+ DynamicFormGroup.prototype.reloadControlsFrom = function (control, controls) {
778
+ var _this = this;
779
+ var data = control.data;
780
+ if (!data || !data.reload)
781
+ return Promise.resolve(null);
782
+ var reload = ngxUtils.ObjectUtils.isArray(data.reload) ? data.reload : [data.reload];
783
+ return Promise.all(reload.map(function (id) {
784
+ var nextControl = _this.getControl(id);
785
+ if (!nextControl || controls.has(nextControl))
786
+ return Promise.resolve(null);
787
+ controls.add(nextControl);
788
+ return new Promise(function (resolve) {
789
+ nextControl.load().then(function () {
790
+ _this.reloadControlsFrom(nextControl, controls).then(resolve);
791
+ });
792
+ });
793
+ }));
794
+ };
795
+ return DynamicFormGroup;
796
+ }(forms.FormGroup));
797
+ var DynamicFormControl = /** @class */ (function (_super) {
798
+ __extends(DynamicFormControl, _super);
799
+ function DynamicFormControl(control, group) {
800
+ var _this = _super.call(this, group.model[control.id], { updateOn: control.data.updateOn || group.updateOn }) || this;
801
+ _this.control = control;
802
+ _this.group = group;
803
+ _this.group.addControl(control.id, _this);
804
+ _this.helper = new DynamicFormControlHelper(_this.form, control);
805
+ _this.helper.findProvider(_this);
806
+ _this.valueChanges.subscribe(function () { return _this.group.updateModel(_this); });
807
+ _this.setAsyncValidators(createValidator(_this));
808
+ return _this;
809
+ }
810
+ Object.defineProperty(DynamicFormControl.prototype, "id", {
811
+ get: function () {
812
+ return this.helper.id;
813
+ },
814
+ enumerable: false,
815
+ configurable: true
816
+ });
817
+ Object.defineProperty(DynamicFormControl.prototype, "type", {
818
+ get: function () {
819
+ return this.helper.type;
820
+ },
821
+ enumerable: false,
822
+ configurable: true
823
+ });
824
+ Object.defineProperty(DynamicFormControl.prototype, "data", {
825
+ get: function () {
826
+ return this.helper.data;
827
+ },
828
+ enumerable: false,
829
+ configurable: true
830
+ });
831
+ Object.defineProperty(DynamicFormControl.prototype, "visible", {
832
+ get: function () {
833
+ return this.helper.visible;
834
+ },
835
+ enumerable: false,
836
+ configurable: true
837
+ });
838
+ Object.defineProperty(DynamicFormControl.prototype, "meta", {
839
+ get: function () {
840
+ return this.helper.meta;
841
+ },
842
+ enumerable: false,
843
+ configurable: true
844
+ });
845
+ Object.defineProperty(DynamicFormControl.prototype, "form", {
846
+ get: function () {
847
+ return this.group.form;
848
+ },
849
+ enumerable: false,
850
+ configurable: true
851
+ });
852
+ Object.defineProperty(DynamicFormControl.prototype, "injector", {
853
+ get: function () {
854
+ return this.form.injector;
855
+ },
856
+ enumerable: false,
857
+ configurable: true
858
+ });
859
+ Object.defineProperty(DynamicFormControl.prototype, "label", {
860
+ get: function () {
861
+ return this.data.label !== "" ? "" + this.group.prefix + this.data.label : "";
862
+ },
863
+ enumerable: false,
864
+ configurable: true
865
+ });
866
+ Object.defineProperty(DynamicFormControl.prototype, "provider", {
867
+ get: function () {
868
+ return this.helper.provider;
869
+ },
870
+ enumerable: false,
871
+ configurable: true
872
+ });
873
+ Object.defineProperty(DynamicFormControl.prototype, "model", {
874
+ get: function () {
875
+ return this.group.model;
876
+ },
877
+ enumerable: false,
878
+ configurable: true
879
+ });
880
+ Object.defineProperty(DynamicFormControl.prototype, "formId", {
881
+ get: function () {
882
+ return this.helper.formId;
883
+ },
884
+ enumerable: false,
885
+ configurable: true
886
+ });
887
+ DynamicFormControl.prototype.getData = function () {
888
+ return this.data;
889
+ };
890
+ DynamicFormControl.prototype.getControl = function (id) {
891
+ return null;
892
+ };
893
+ DynamicFormControl.prototype.load = function () {
894
+ return this.helper.load(this);
895
+ };
896
+ DynamicFormControl.prototype.check = function () {
897
+ var _this = this;
898
+ var check = this.helper.check(this);
899
+ check.then(function (readonly) {
900
+ if (readonly || _this.group.disabled)
901
+ _this.disable({ emitEvent: false });
902
+ else
903
+ _this.enable({ emitEvent: false });
957
904
  });
905
+ return check;
906
+ };
907
+ DynamicFormControl.prototype.shouldSerialize = function () {
908
+ return this.helper.shouldSerialize(this);
909
+ };
910
+ DynamicFormControl.prototype.shouldValidate = function () {
911
+ return this.helper.shouldValidate(this);
912
+ };
913
+ DynamicFormControl.prototype.serialize = function () {
914
+ return Promise.resolve(this.value);
915
+ };
916
+ DynamicFormControl.prototype.onFocus = function () {
917
+ this.markAsUntouched({ onlySelf: true });
918
+ };
919
+ DynamicFormControl.prototype.onBlur = function () {
920
+ this.markAsTouched({ onlySelf: true });
921
+ };
922
+ DynamicFormControl.prototype.showErrors = function () {
923
+ this.markAsTouched({ onlySelf: true });
924
+ };
925
+ return DynamicFormControl;
926
+ }(forms.FormControl));
927
+ // --- Decorator functions ---
928
+ var emptyArray = [];
929
+ var emptyTester = function () {
930
+ return Promise.resolve(false);
931
+ };
932
+ var ɵ0 = emptyTester;
933
+ function defaultSerializer(id, parent) {
934
+ var control = parent.getControl(id);
935
+ return !control ? Promise.resolve(parent.model[id]) : control.serialize();
936
+ }
937
+ function FormSerializable(serializer) {
938
+ return function (target, propertyKey) {
939
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormSerializer", serializer || defaultSerializer, target, propertyKey);
940
+ };
941
+ }
942
+ function FormInput(data) {
943
+ return function (target, propertyKey) {
944
+ var meta = ngxUtils.ReflectUtils.getOwnMetadata("design:type", target, propertyKey);
945
+ var type = meta ? meta.name : "";
946
+ var inputType = propertyKey.indexOf("password") < 0 ? "text" : "password";
947
+ switch (type) {
948
+ case "Number":
949
+ inputType = "number";
950
+ break;
951
+ case "Boolean":
952
+ inputType = "checkbox";
953
+ break;
954
+ }
955
+ defineFormControl(target, propertyKey, createFormInput(propertyKey, data, inputType));
956
+ };
957
+ }
958
+ function FormSelect(data) {
959
+ return function (target, propertyKey) {
960
+ defineFormControl(target, propertyKey, createFormSelect(propertyKey, data));
961
+ };
962
+ }
963
+ function FormStatic(data) {
964
+ return function (target, propertyKey) {
965
+ defineFormControl(target, propertyKey, createFormStatic(propertyKey, data));
966
+ };
967
+ }
968
+ function FormModel(data) {
969
+ return function (target, propertyKey) {
970
+ defineFormControl(target, propertyKey, createFormModel(propertyKey, data));
971
+ };
972
+ }
973
+ function FormFile(data) {
974
+ return function (target, propertyKey) {
975
+ defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
976
+ };
977
+ }
978
+ function FormFieldSet(data) {
979
+ return function (target) {
980
+ var sets = getFormFieldSets(target);
981
+ data.classes = data.classes || "";
982
+ sets[data.id] = data;
983
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormFieldSets", sets, target);
984
+ };
985
+ }
986
+ function provideFormGroup(component) {
987
+ return {
988
+ provide: FORM_GROUP_TYPE,
989
+ useValue: component
990
+ };
991
+ }
992
+ function provideFormControl(component, acceptor, loader, priority) {
993
+ if (priority === void 0) { priority = 0; }
994
+ return {
995
+ provide: FORM_CONTROL_PROVIDER,
996
+ multi: true,
997
+ useValue: {
998
+ component: component,
999
+ priority: priority,
1000
+ acceptor: acceptor,
1001
+ loader: loader
1002
+ }
1003
+ };
1004
+ }
1005
+ function defineFormControl(target, propertyKey, control) {
1006
+ ngxUtils.ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
1007
+ }
1008
+ function getFormFieldSets(target) {
1009
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormFieldSets", target) || {};
1010
+ }
1011
+ function getFormControl(target, propertyKey) {
1012
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
1013
+ }
1014
+ function getFormSerializer(target, propertyKey) {
1015
+ return ngxUtils.ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
1016
+ }
1017
+ function createFormControl(id, type, data) {
1018
+ data = data || {};
1019
+ data.label = ngxUtils.ObjectUtils.isNullOrUndefined(data.label) ? id : data.label;
1020
+ data.labelAlign = data.labelAlign || "left";
1021
+ data.fieldSet = data.fieldSet || ngxUtils.UniqueUtils.uuid();
1022
+ data.classes = data.classes || "";
1023
+ data.readonly = data.readonly || emptyTester;
1024
+ data.hidden = data.hidden || emptyTester;
1025
+ data.validators = data.validators || emptyArray;
1026
+ return {
1027
+ id: id,
1028
+ type: type,
1029
+ data: data
1030
+ };
1031
+ }
1032
+ function createFormInput(id, data, type) {
1033
+ if (type === void 0) { type = "text"; }
1034
+ var control = createFormControl(id, "input", data);
1035
+ data = control.data;
1036
+ data.type = data.type || type;
1037
+ data.classes = !data.classes ? "form-group-" + data.type : data.classes + " form-group-" + data.type;
1038
+ data.placeholder = data.placeholder || "";
1039
+ data.step = data.step || 1;
1040
+ return control;
1041
+ }
1042
+ function createFormSelect(id, data) {
1043
+ var control = createFormControl(id, "select", data);
1044
+ data = control.data;
1045
+ data.options = data.options || (function () { return Promise.resolve([]); });
1046
+ data.type = data.type || "select";
1047
+ var classType = data.type == "select" ? "select" : "select-" + data.type;
1048
+ data.classes = !data.classes ? "form-group-" + classType : data.classes + " form-group-" + classType;
1049
+ return control;
1050
+ }
1051
+ function createFormStatic(id, data) {
1052
+ var control = createFormControl(id, "static", data);
1053
+ data = control.data;
1054
+ data.style = data.style || "table";
1055
+ return control;
1056
+ }
1057
+ function createFormModel(id, data) {
1058
+ var control = createFormControl(id, "model", data);
1059
+ data = control.data;
1060
+ data.name = data.name || "";
1061
+ return control;
1062
+ }
1063
+ function createFormFile(id, data) {
1064
+ var control = createFormControl(id, "file", data);
1065
+ data = control.data;
1066
+ data.accept = data.accept || ".jpg,.jpeg,.png";
1067
+ data.multi = data.multi || false;
1068
+ data.baseUrl = ngxUtils.ObjectUtils.isString(data.baseUrl) ? data.baseUrl : "assets/";
1069
+ data.uploadUrl = ngxUtils.ObjectUtils.isString(data.uploadUrl) ? data.uploadUrl : "assets";
1070
+ data.createUploadData = data.createUploadData || (function (file) {
1071
+ var form = new FormData();
1072
+ form.append("file", file);
1073
+ return form;
1074
+ });
1075
+ return control;
1076
+ }
1077
+
1078
+ var DynamicFormService = /** @class */ (function () {
1079
+ function DynamicFormService(components, groupType, resolver, injector) {
1080
+ this.components = components;
1081
+ this.groupType = groupType;
1082
+ this.resolver = resolver;
1083
+ this.injector = injector;
1084
+ }
1085
+ DynamicFormService.prototype.findProvider = function (control) {
1086
+ if (!control)
1087
+ return null;
1088
+ var providers = this.components.filter(function (p) { return p.acceptor(control); });
1089
+ if (providers.length == 0) {
1090
+ throw new Error("No component provider for control: " + JSON.stringify({
1091
+ id: control.id,
1092
+ type: control.type,
1093
+ data: control.data
1094
+ }));
1095
+ }
1096
+ // Sort providers
1097
+ providers.sort(function (a, b) { return ngxUtils.ObjectUtils.compare(a.priority, b.priority); });
1098
+ return providers[0];
1099
+ };
1100
+ DynamicFormService.prototype.createComponent = function (vcr, provider) {
1101
+ vcr.clear();
1102
+ if (!provider)
1103
+ return null;
1104
+ var factory = this.resolver.resolveComponentFactory(provider.component);
1105
+ return vcr.createComponent(factory).instance;
1106
+ };
1107
+ DynamicFormService.prototype.createGroup = function (vcr) {
1108
+ vcr.clear();
1109
+ var factory = this.resolver.resolveComponentFactory(this.groupType);
1110
+ return vcr.createComponent(factory).instance;
1111
+ };
1112
+ return DynamicFormService;
1113
+ }());
1114
+ DynamicFormService.decorators = [
1115
+ { type: core.Injectable }
1116
+ ];
1117
+ DynamicFormService.ctorParameters = function () { return [
1118
+ { type: Array, decorators: [{ type: core.Inject, args: [FORM_CONTROL_PROVIDER,] }] },
1119
+ { type: core.Type, decorators: [{ type: core.Inject, args: [FORM_GROUP_TYPE,] }] },
1120
+ { type: core.ComponentFactoryResolver },
1121
+ { type: core.Injector }
1122
+ ]; };
1123
+
1124
+ var FormUtilities = /** @class */ (function () {
1125
+ function FormUtilities() {
1126
+ }
1127
+ FormUtilities.checkField = function (expression) {
1128
+ if (expression === void 0) { expression = "true"; }
1129
+ // @dynamic
1130
+ var lambda = function (control) {
1131
+ return Promise.resolve(ngxUtils.ObjectUtils.evaluate(expression, { control: control }));
1132
+ };
1133
+ return lambda;
1134
+ };
1135
+ FormUtilities.checkReadonly = function (control) {
1136
+ return Promise.resolve(control.visible && !control.disabled);
1137
+ };
1138
+ FormUtilities.readonly = function () {
1139
+ return Promise.resolve(true);
1140
+ };
1141
+ FormUtilities.validateJSON = function (control) {
1142
+ var value = control.value;
1143
+ if (!value)
1144
+ return Promise.resolve(null);
1145
+ try {
1146
+ JSON.parse(value);
1147
+ return Promise.resolve(null);
1148
+ }
1149
+ catch (e) {
1150
+ return Promise.resolve("error.not-valid-json");
1151
+ }
1152
+ };
1153
+ FormUtilities.validateRequired = function (control) {
1154
+ var value = control.value;
1155
+ return Promise.resolve(!ngxUtils.ObjectUtils.isNumber(value) && !value ? "error.required" : null);
1156
+ };
1157
+ FormUtilities.validateMinLength = function (length) {
1158
+ // @dynamic
1159
+ var lambda = function (control) {
1160
+ var value = control.value;
1161
+ if (!ngxUtils.ObjectUtils.isString(value) || value.length < length) {
1162
+ return Promise.resolve({ "error.min-length": { length: length } });
1163
+ }
1164
+ return Promise.resolve(null);
1165
+ };
1166
+ return lambda;
1167
+ };
1168
+ FormUtilities.validateMaxLength = function (length) {
1169
+ // @dynamic
1170
+ var lambda = function (control) {
1171
+ var value = control.value;
1172
+ if (!ngxUtils.ObjectUtils.isString(value) || value.length > length) {
1173
+ return Promise.resolve({ "error.max-length": { length: length } });
1174
+ }
1175
+ return Promise.resolve(null);
1176
+ };
1177
+ return lambda;
1178
+ };
1179
+ FormUtilities.validateRequiredTranslation = function (control) {
1180
+ var value = control.value;
1181
+ if (!value || value.length == 0)
1182
+ return Promise.resolve("error.required");
1183
+ return Promise.resolve(value.findIndex(function (t) { return (t.lang == "de" || t.lang == "en") && !t.translation; }) < 0 ? null : "error.required");
1184
+ };
1185
+ FormUtilities.validateEmail = function (control) {
1186
+ var value = control.value;
1187
+ if (!value)
1188
+ return Promise.resolve(null);
1189
+ var emailRegexp = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1190
+ return Promise.resolve(emailRegexp.test(value) ? null : "error.invalid-email");
958
1191
  };
959
- DynamicFormService.prototype.getFormCheckboxConfig = function (property, schema) {
960
- return Object.assign(this.getFormControlConfig(property, schema), {
961
- indeterminate: property.indeterminate === true
962
- });
1192
+ FormUtilities.validatePhone = function (control) {
1193
+ var value = control.value;
1194
+ if (!value)
1195
+ return Promise.resolve(null);
1196
+ var phoneRegexp = /^(?:\d){10,12}$/;
1197
+ return Promise.resolve(phoneRegexp.test(value) ? null : "error.invalid-phone");
1198
+ };
1199
+ FormUtilities.serializeLogo = function (id, parent) {
1200
+ var value = parent.model[id];
1201
+ return Promise.resolve(!value || value.length == 0 ? null : value);
1202
+ };
1203
+ FormUtilities.serializeFile = function (id, parent) {
1204
+ var value = parent.model[id];
1205
+ if (ngxUtils.ObjectUtils.isBlob(value))
1206
+ return Promise.resolve(value);
1207
+ return Promise.resolve(!ngxUtils.ObjectUtils.isString(value) || !value.startsWith("data:") ? null : ngxUtils.FileUtils.dataToBlob(value));
1208
+ };
1209
+ FormUtilities.serializeNumber = function (id, parent) {
1210
+ var value = parent.model[id];
1211
+ return Promise.resolve(!value || value.length == 0 ? 0 : parseFloat(value));
1212
+ };
1213
+ FormUtilities.serializeJSON = function (id, parent) {
1214
+ var value = parent.model[id];
1215
+ return Promise.resolve(!value ? {} : JSON.parse(value));
1216
+ };
1217
+ FormUtilities.serializeDate = function (date, format, defaultValue) {
1218
+ if (format === void 0) { format = "yyyy-MM-dd"; }
1219
+ if (defaultValue === void 0) { defaultValue = ""; }
1220
+ // @dynamic
1221
+ var lambda = function (id, parent) {
1222
+ var value = parent.model[id];
1223
+ if (!ngxUtils.ObjectUtils.isDate(value))
1224
+ return Promise.resolve(value || defaultValue);
1225
+ return Promise.resolve(!format ? value : date.transform(value, format));
1226
+ };
1227
+ return lambda;
963
1228
  };
964
- DynamicFormService.prototype.translateOptions = function (options) {
965
- return __awaiter(this, void 0, void 0, function () {
966
- var options_1, options_1_1, option, _c, e_2_1;
967
- var e_2, _d;
968
- return __generator(this, function (_e) {
969
- switch (_e.label) {
970
- case 0:
971
- if (!options)
972
- return [2 /*return*/, []];
973
- _e.label = 1;
974
- case 1:
975
- _e.trys.push([1, 6, 7, 8]);
976
- options_1 = __values(options), options_1_1 = options_1.next();
977
- _e.label = 2;
978
- case 2:
979
- if (!!options_1_1.done) return [3 /*break*/, 5];
980
- option = options_1_1.value;
981
- _c = option;
982
- return [4 /*yield*/, this.language.getTranslation(option.label)];
983
- case 3:
984
- _c.label = _e.sent();
985
- _e.label = 4;
986
- case 4:
987
- options_1_1 = options_1.next();
988
- return [3 /*break*/, 2];
989
- case 5: return [3 /*break*/, 8];
990
- case 6:
991
- e_2_1 = _e.sent();
992
- e_2 = { error: e_2_1 };
993
- return [3 /*break*/, 8];
994
- case 7:
995
- try {
996
- if (options_1_1 && !options_1_1.done && (_d = options_1.return)) _d.call(options_1);
997
- }
998
- finally { if (e_2) throw e_2.error; }
999
- return [7 /*endfinally*/];
1000
- case 8: return [2 /*return*/, options];
1001
- }
1229
+ return FormUtilities;
1230
+ }());
1231
+ __decorate([
1232
+ ngxUtils.FactoryDependencies(common.DatePipe)
1233
+ ], FormUtilities, "serializeDate", null);
1234
+
1235
+ var OpenApiService = /** @class */ (function () {
1236
+ function OpenApiService(api) {
1237
+ var _this = this;
1238
+ this.api = api;
1239
+ var baseUrl = this.api.url("").replace("api/", "api-docs");
1240
+ this.schemas = {};
1241
+ this.schemasPromise = new Promise((function (resolve) {
1242
+ _this.api.client.get(baseUrl).subscribe(function (res) {
1243
+ _this.schemas = res.definitions || {};
1244
+ resolve(_this.schemas);
1245
+ }, function () {
1246
+ resolve({});
1002
1247
  });
1248
+ }));
1249
+ }
1250
+ OpenApiService.prototype.getFormInputsForSchema = function (name) {
1251
+ var _this = this;
1252
+ this.api.cache = {};
1253
+ return this.schemasPromise.then(function (schemas) {
1254
+ var schema = schemas[name];
1255
+ var inputs = _this.getFormInputsForSchemaDef(schema);
1256
+ return inputs;
1003
1257
  });
1004
1258
  };
1005
- DynamicFormService.prototype.getFormSelectOptions = function (property, schema) {
1259
+ OpenApiService.prototype.getFormInputsForSchemaDef = function (schema) {
1006
1260
  var _this = this;
1007
- var _a;
1008
- var $enum = ((_a = property.items) === null || _a === void 0 ? void 0 : _a.enum) || property.enum;
1009
- if (Array.isArray($enum)) {
1010
- return new FormSelectSubject(function () {
1011
- var options = $enum.map(function (value) {
1012
- var label = property.translatable ? property.id + "." + value : "" + value;
1013
- return { value: value, label: label };
1014
- });
1015
- return _this.translateOptions(options);
1016
- });
1261
+ var inputs = {};
1262
+ if (!schema)
1263
+ return inputs;
1264
+ inputs.schema = schema;
1265
+ inputs.serializers = {};
1266
+ inputs.controls = Object.keys(schema.properties || {}).map(function (p) {
1267
+ var property = schema.properties[p];
1268
+ property.id = p;
1269
+ inputs.serializers[p] = function (id, parent) {
1270
+ return Promise.resolve(parent.model[id]);
1271
+ };
1272
+ return _this.getFormControlForProperty(property, schema);
1273
+ }).filter(function (t) { return null !== t; });
1274
+ return inputs;
1275
+ };
1276
+ OpenApiService.prototype.getFormControlForProperty = function (property, schema) {
1277
+ if (Array.isArray(property.enum)) {
1278
+ return createFormSelect(property.id, this.getFormSelectData(property, schema));
1017
1279
  }
1018
- if (isStringWithVal(property.optionsPath)) {
1019
- return new FormSelectSubject(function (formModel, control, root, indexes) {
1020
- var path = property.optionsPath;
1021
- var target = control;
1022
- var model = formModel;
1023
- if (path.startsWith("$root")) {
1024
- path = path.substr(5);
1025
- while (target.parent) {
1026
- target = target.parent;
1027
- }
1028
- model = root;
1029
- }
1030
- while (path.startsWith(".")) {
1031
- path = path.substr(1);
1032
- if (target.parent) {
1033
- target = target.parent;
1034
- }
1035
- model = model.parent || root;
1036
- }
1037
- Object.keys(indexes).forEach(function (key) {
1038
- path = path.replace(key, indexes[key]);
1039
- });
1040
- model = _this.findModelByPath(model, path.split("."));
1041
- var modelOptions = (model instanceof core.DynamicSelectModel ? model.options : []);
1042
- var value = ngxUtils.ObjectUtils.getValue(target.value, path);
1043
- var options = (!ngxUtils.ObjectUtils.isArray(value) ? [] : value).map(function (value) {
1044
- var modelOption = modelOptions.find(function (t) { return t.value == value; });
1045
- return { value: value, label: (modelOption === null || modelOption === void 0 ? void 0 : modelOption.label) || value };
1046
- });
1047
- return _this.translateOptions(options);
1048
- });
1280
+ switch (property.type) {
1281
+ case "string":
1282
+ case "number":
1283
+ case "boolean":
1284
+ case "textarea":
1285
+ return createFormInput(property.id, this.getFormInputData(property, schema));
1286
+ case "list":
1287
+ return createFormSelect(property.id, this.getFormSelectData(property, schema));
1288
+ case "file":
1289
+ return createFormFile(property.id, this.getFormFileData(property, schema));
1049
1290
  }
1050
- return new FormSelectSubject(function () { return __awaiter(_this, void 0, void 0, function () {
1051
- var options;
1052
- return __generator(this, function (_c) {
1053
- switch (_c.label) {
1054
- case 0:
1055
- this.api.cache[property.endpoint] = this.api.cache[property.endpoint] || this.api.list(property.endpoint, this.api.makeListParams(1, -1)).then(function (result) {
1056
- return result.items.map(function (i) {
1057
- return { value: i.id || i._id, label: i[property.labelField] || i.label || i.id || i._id };
1058
- });
1059
- });
1060
- return [4 /*yield*/, this.api.cache[property.endpoint]];
1061
- case 1:
1062
- options = (_c.sent()).map(function (t) { return Object.assign({}, t); });
1063
- return [2 /*return*/, this.translateOptions(options)];
1064
- }
1065
- });
1066
- }); });
1067
- };
1068
- DynamicFormService.prototype.getFormUploadConfig = function (property, schema) {
1069
- var url = this.api.url(property.url || "assets");
1070
- var accept = property.accept, autoUpload = property.autoUpload, maxSize = property.maxSize, minSize = property.minSize, removeUrl = property.removeUrl, showFileList = property.showFileList;
1071
- return Object.assign(this.getFormControlConfig(property, schema), {
1072
- url: url,
1073
- accept: accept,
1074
- autoUpload: autoUpload,
1075
- maxSize: maxSize,
1076
- minSize: minSize,
1077
- removeUrl: removeUrl,
1078
- showFileList: showFileList
1079
- });
1291
+ return null;
1080
1292
  };
1081
- DynamicFormService.prototype.getValidators = function (property, schema) {
1082
- var validators = {};
1083
- if (ngxUtils.ObjectUtils.isArray(schema.required) && schema.required.indexOf(property.id) >= 0) {
1084
- validators.required = null;
1085
- }
1086
- this.addPropertyValidators(validators, property);
1087
- this.addItemsValidators(validators, property.items);
1088
- return validators;
1293
+ OpenApiService.prototype.getBaseFormData = function (property, schema) {
1294
+ return {
1295
+ readonly: property.readonly ? FormUtilities.readonly : null,
1296
+ shouldSerialize: FormUtilities.checkReadonly,
1297
+ validators: this.getValidators(property, schema)
1298
+ };
1089
1299
  };
1090
- DynamicFormService.prototype.addPropertyValidators = function (validators, property) {
1091
- if (!property)
1092
- return;
1093
- if (!isNaN(property.minLength)) {
1094
- validators.minLength = property.minLength;
1300
+ OpenApiService.prototype.getFormInputData = function (property, schema) {
1301
+ var type = ngxUtils.StringUtils.has(property.id, "password", "Password") ? "password" : property.type;
1302
+ switch (property.type) {
1303
+ case "boolean":
1304
+ type = "checkbox";
1305
+ break;
1306
+ case "textarea":
1307
+ type = "textarea";
1308
+ break;
1095
1309
  }
1096
- if (!isNaN(property.maxLength)) {
1097
- validators.maxLength = property.maxLength;
1310
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { type: type });
1311
+ };
1312
+ OpenApiService.prototype.getFormSelectData = function (property, schema) {
1313
+ var _this = this;
1314
+ var options = Array.isArray(property.enum)
1315
+ ? function () {
1316
+ return Promise.resolve(property.enum.map(function (id) { return ({ id: id, label: property.id + "." + id }); }));
1317
+ }
1318
+ : function () {
1319
+ _this.api.cache[property.endpoint] = _this.api.cache[property.endpoint] || _this.api.list(property.endpoint, _this.api.makeListParams(1, -1)).then(function (result) {
1320
+ return result.items.map(function (i) {
1321
+ return { id: i._id, label: i.name };
1322
+ });
1323
+ });
1324
+ return _this.api.cache[property.endpoint];
1325
+ };
1326
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { options: options });
1327
+ };
1328
+ OpenApiService.prototype.getFormFileData = function (property, schema) {
1329
+ return Object.assign(Object.assign({}, this.getBaseFormData(property, schema)), { multi: property.multi });
1330
+ };
1331
+ OpenApiService.prototype.getValidators = function (property, schema) {
1332
+ var validators = [];
1333
+ if (schema.required.indexOf(property.id) >= 0) {
1334
+ validators.push(FormUtilities.validateRequired);
1098
1335
  }
1099
- if (!isNaN(property.minimum)) {
1100
- validators.min = property.minimum;
1336
+ if (property.minLength) {
1337
+ validators.push({
1338
+ type: FormUtilities,
1339
+ func: FormUtilities.validateMinLength,
1340
+ params: [property.minLength]
1341
+ });
1101
1342
  }
1102
- if (!isNaN(property.maximum)) {
1103
- validators.max = property.maximum;
1343
+ if (property.maxLength) {
1344
+ validators.push({
1345
+ type: FormUtilities,
1346
+ func: FormUtilities.validateMaxLength,
1347
+ params: [property.maxLength]
1348
+ });
1104
1349
  }
1105
1350
  switch (property.format) {
1106
1351
  case "email":
1107
- validators.email = null;
1352
+ validators.push(FormUtilities.validateEmail);
1108
1353
  break;
1109
1354
  }
1355
+ return validators;
1110
1356
  };
1111
- DynamicFormService.prototype.addItemsValidators = function (validators, items) {
1112
- if (!items)
1113
- return;
1114
- if (!isNaN(items.minLength)) {
1115
- validators.itemsMinLength = items.minLength;
1116
- }
1117
- if (!isNaN(items.maxLength)) {
1118
- validators.itemsMaxLength = items.maxLength;
1119
- }
1120
- if (!isNaN(items.minimum)) {
1121
- validators.itemsMinValue = items.minimum;
1122
- }
1123
- if (!isNaN(items.maximum)) {
1124
- validators.itemsMaxValue = items.maximum;
1125
- }
1126
- };
1127
- return DynamicFormService;
1128
- }(core.DynamicFormService));
1129
- DynamicFormService.decorators = [
1130
- { type: core$1.Injectable }
1357
+ return OpenApiService;
1358
+ }());
1359
+ OpenApiService.decorators = [
1360
+ { type: core.Injectable }
1131
1361
  ];
1132
- DynamicFormService.ctorParameters = function () { return [
1133
- { type: core.DynamicFormComponentService },
1134
- { type: core.DynamicFormValidationService },
1135
- { type: ngxUtils.OpenApiService, decorators: [{ type: core$1.Inject, args: [ngxUtils.OpenApiService,] }] },
1136
- { type: core$1.Injector, decorators: [{ type: core$1.Inject, args: [core$1.Injector,] }] }
1362
+ OpenApiService.ctorParameters = function () { return [
1363
+ { type: ngxUtils.ApiService }
1137
1364
  ]; };
1138
1365
 
1139
1366
  var AsyncSubmitDirective = /** @class */ (function () {
1140
1367
  function AsyncSubmitDirective(toaster, cdr, elem, renderer) {
1141
1368
  this.toaster = toaster;
1142
1369
  this.cdr = cdr;
1143
- this.elem = elem;
1144
- this.renderer = renderer;
1145
- this.onSuccess = new core$1.EventEmitter();
1146
- this.onError = new core$1.EventEmitter();
1370
+ this.onSuccess = new core.EventEmitter();
1371
+ this.onError = new core.EventEmitter();
1147
1372
  if (elem.nativeElement.tagName !== "BUTTON")
1148
1373
  return;
1149
1374
  renderer.setAttribute(elem.nativeElement, "type", "button");
@@ -1152,14 +1377,6 @@
1152
1377
  get: function () {
1153
1378
  return this.disabled;
1154
1379
  },
1155
- set: function (value) {
1156
- this.disabled = value;
1157
- if (value) {
1158
- this.renderer.setAttribute(this.elem.nativeElement, "disabled", "disabled");
1159
- return;
1160
- }
1161
- this.renderer.removeAttribute(this.elem.nativeElement, "disabled");
1162
- },
1163
1380
  enumerable: false,
1164
1381
  configurable: true
1165
1382
  });
@@ -1174,12 +1391,12 @@
1174
1391
  var _this = this;
1175
1392
  if (!this.form)
1176
1393
  return;
1177
- this.isDisabled = this.form.status !== "VALID";
1394
+ this.disabled = this.form.status !== "VALID";
1178
1395
  this.cdr.detectChanges();
1179
- this.onStatusChange = this.form.onStatusChange.subscribe(function () {
1180
- _this.isDisabled = _this.form.status !== "VALID";
1396
+ this.onStatusChange = this.form.onStatusChange.subscribe(function (form) {
1397
+ _this.disabled = form.status !== "VALID";
1181
1398
  _this.cdr.detectChanges();
1182
- if (!_this.callback || _this.form.status == "PENDING")
1399
+ if (!_this.callback || form.status == "PENDING")
1183
1400
  return;
1184
1401
  if (!_this.disabled) {
1185
1402
  _this.callback();
@@ -1207,7 +1424,7 @@
1207
1424
  if (this.loading)
1208
1425
  return;
1209
1426
  this.loading = true;
1210
- this.method(this.form, this.context).then(function (result) {
1427
+ this.method(this.form).then(function (result) {
1211
1428
  _this.loading = false;
1212
1429
  if (result) {
1213
1430
  _this.onSuccess.emit(result);
@@ -1224,120 +1441,231 @@
1224
1441
  return AsyncSubmitDirective;
1225
1442
  }());
1226
1443
  AsyncSubmitDirective.decorators = [
1227
- { type: core$1.Directive, args: [{
1444
+ { type: core.Directive, args: [{
1228
1445
  selector: "[async-submit]",
1229
1446
  exportAs: "async-submit"
1230
1447
  },] }
1231
1448
  ];
1232
1449
  AsyncSubmitDirective.ctorParameters = function () { return [
1233
- { type: undefined, decorators: [{ type: core$1.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] },
1234
- { type: core$1.ChangeDetectorRef },
1235
- { type: core$1.ElementRef },
1236
- { type: core$1.Renderer2 }
1450
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] },
1451
+ { type: core.ChangeDetectorRef },
1452
+ { type: core.ElementRef },
1453
+ { type: core.Renderer2 }
1237
1454
  ]; };
1238
1455
  AsyncSubmitDirective.propDecorators = {
1239
- method: [{ type: core$1.Input, args: ["async-submit",] }],
1240
- form: [{ type: core$1.Input }],
1241
- context: [{ type: core$1.Input }],
1242
- onSuccess: [{ type: core$1.Output }],
1243
- onError: [{ type: core$1.Output }],
1244
- isDisabled: [{ type: core$1.HostBinding, args: ["class.disabled",] }],
1245
- isLoading: [{ type: core$1.HostBinding, args: ["class.loading",] }],
1246
- click: [{ type: core$1.HostListener, args: ["click",] }]
1456
+ method: [{ type: core.Input, args: ["async-submit",] }],
1457
+ form: [{ type: core.Input }],
1458
+ onSuccess: [{ type: core.Output }],
1459
+ onError: [{ type: core.Output }],
1460
+ isDisabled: [{ type: core.HostBinding, args: ["class.disabled",] }],
1461
+ isLoading: [{ type: core.HostBinding, args: ["class.loading",] }],
1462
+ click: [{ type: core.HostListener, args: ["click",] }]
1247
1463
  };
1248
1464
 
1249
- var DynamicBaseFormComponent = /** @class */ (function (_super) {
1250
- __extends(DynamicBaseFormComponent, _super);
1251
- function DynamicBaseFormComponent(formService, events, changeDetectorRef, componentService) {
1252
- var _this = _super.call(this, changeDetectorRef, componentService) || this;
1253
- _this.formService = formService;
1254
- _this.events = events;
1255
- _this.blur = new core$1.EventEmitter();
1256
- _this.change = new core$1.EventEmitter();
1257
- _this.focus = new core$1.EventEmitter();
1258
- _this.onValueChange = new core$1.EventEmitter();
1259
- _this.onStatusChange = new core$1.EventEmitter();
1260
- _this.onSubmit = new core$1.EventEmitter();
1261
- _this.templates = new core$1.QueryList();
1262
- _this.subscription = new rxjs.Subscription();
1263
- _this.groupSubscription = new rxjs.Subscription();
1264
- _this.labelPrefix = "label";
1265
- return _this;
1465
+ var DynamicFormControlDirective = /** @class */ (function () {
1466
+ function DynamicFormControlDirective(vcr, forms) {
1467
+ this.vcr = vcr;
1468
+ this.forms = forms;
1266
1469
  }
1267
- Object.defineProperty(DynamicBaseFormComponent.prototype, "status", {
1470
+ Object.defineProperty(DynamicFormControlDirective.prototype, "component", {
1268
1471
  get: function () {
1269
- return !this.group ? null : this.group.status;
1472
+ return this.comp;
1270
1473
  },
1271
1474
  enumerable: false,
1272
1475
  configurable: true
1273
1476
  });
1274
- DynamicBaseFormComponent.prototype.ngOnChanges = function (changes) {
1275
- var _this = this;
1276
- this.groupSubscription.unsubscribe();
1277
- if (this.group) {
1278
- this.groupSubscription = ngxUtils.ObservableUtils.multiSubscription(this.group.statusChanges.subscribe(function () {
1279
- _this.onStatusChange.emit(_this);
1280
- }), this.group.valueChanges.subscribe(function () {
1281
- _this.formService.notifyChanges(_this.model, _this.group, _this.model);
1282
- }), this.change.subscribe(function (ev) {
1283
- _this.onValueChange.emit(Object.assign(Object.assign({}, ev), { form: _this }));
1284
- }));
1477
+ DynamicFormControlDirective.prototype.ngOnChanges = function (changes) {
1478
+ if (changes.control) {
1479
+ this.comp = this.forms.createComponent(this.vcr, this.control.provider);
1285
1480
  }
1481
+ if (!this.comp)
1482
+ return;
1483
+ this.comp.control = this.control;
1286
1484
  };
1287
- DynamicBaseFormComponent.prototype.ngAfterViewInit = function () {
1288
- var _this = this;
1289
- this.subscription = ngxUtils.ObservableUtils.multiSubscription(ngxUtils.ObservableUtils.subscribe({
1290
- subjects: [this.contentTemplates.changes, this.viewTemplates.changes],
1291
- cb: function () {
1292
- var templates = _this.contentTemplates.toArray().concat(_this.viewTemplates.toArray());
1293
- _this.templates.reset(templates);
1485
+ return DynamicFormControlDirective;
1486
+ }());
1487
+ DynamicFormControlDirective.decorators = [
1488
+ { type: core.Directive, args: [{
1489
+ selector: "[form-control]",
1490
+ },] }
1491
+ ];
1492
+ DynamicFormControlDirective.ctorParameters = function () { return [
1493
+ { type: core.ViewContainerRef },
1494
+ { type: DynamicFormService }
1495
+ ]; };
1496
+ DynamicFormControlDirective.propDecorators = {
1497
+ control: [{ type: core.Input, args: ["form-control",] }]
1498
+ };
1499
+
1500
+ var DynamicFormTemplateDirective = /** @class */ (function () {
1501
+ function DynamicFormTemplateDirective(template) {
1502
+ this.template = template;
1503
+ }
1504
+ return DynamicFormTemplateDirective;
1505
+ }());
1506
+ DynamicFormTemplateDirective.decorators = [
1507
+ { type: core.Directive, args: [{
1508
+ selector: "ng-template[control],\n ng-template[label],\n ng-template[input],\n ng-template[prefix],\n ng-template[suffix],\n ng-template[setPrefix],\n ng-template[setSuffix],\n ng-template[formPrefix],\n ng-template[formSuffix],\n ng-template[innerFormPrefix],\n ng-template[innerFormSuffix]"
1509
+ },] }
1510
+ ];
1511
+ DynamicFormTemplateDirective.ctorParameters = function () { return [
1512
+ { type: core.TemplateRef }
1513
+ ]; };
1514
+ DynamicFormTemplateDirective.propDecorators = {
1515
+ control: [{ type: core.Input }],
1516
+ label: [{ type: core.Input }],
1517
+ input: [{ type: core.Input }],
1518
+ prefix: [{ type: core.Input }],
1519
+ suffix: [{ type: core.Input }],
1520
+ setPrefix: [{ type: core.Input }],
1521
+ setSuffix: [{ type: core.Input }],
1522
+ formPrefix: [{ type: core.Input }],
1523
+ formSuffix: [{ type: core.Input }],
1524
+ innerFormPrefix: [{ type: core.Input }],
1525
+ innerFormSuffix: [{ type: core.Input }]
1526
+ };
1527
+
1528
+ var DynamicFormBaseComponent = /** @class */ (function () {
1529
+ function DynamicFormBaseComponent(cdr, formService) {
1530
+ this.formService = formService;
1531
+ this.name = "";
1532
+ this.testId = "form";
1533
+ this.controlTemplates = {};
1534
+ this.labelTemplates = {};
1535
+ this.inputTemplates = {};
1536
+ this.prefixTemplates = {};
1537
+ this.suffixTemplates = {};
1538
+ this.onChange = new core.EventEmitter();
1539
+ this.onStatusChange = new core.EventEmitter();
1540
+ this.onInit = new core.EventEmitter();
1541
+ this.onSubmit = new core.EventEmitter();
1542
+ this.injector = formService.injector;
1543
+ this.cdr = cdr;
1544
+ }
1545
+ Object.defineProperty(DynamicFormBaseComponent.prototype, "root", {
1546
+ get: function () {
1547
+ var form = this;
1548
+ while (ngxUtils.ObjectUtils.isDefined(form.parent)) {
1549
+ form = form.parent;
1294
1550
  }
1295
- }), this.events.languageChanged.subscribe(function () {
1296
- _this.formService.detectChanges(_this);
1297
- }), this.ngForm.ngSubmit.subscribe(function () {
1298
- _this.onSubmit.emit(_this);
1299
- }));
1551
+ return form;
1552
+ },
1553
+ enumerable: false,
1554
+ configurable: true
1555
+ });
1556
+ DynamicFormBaseComponent.prototype.findProvider = function (control) {
1557
+ return this.formService.findProvider(control);
1558
+ };
1559
+ // --- Lifecycle hooks
1560
+ DynamicFormBaseComponent.prototype.ngAfterContentInit = function () {
1561
+ this.wrapperTemplate = this.wrapperTemplate || this.cWrapperTemplate;
1562
+ this.fieldSetTemplate = this.fieldSetTemplate || this.cFieldSetTemplate;
1563
+ this.controlTemplate = this.controlTemplate || this.cControlTemplate;
1564
+ this.controlTemplates = this.filterTemplates(this.controlTemplates, "control");
1565
+ this.labelTemplates = this.filterTemplates(this.labelTemplates, "label");
1566
+ this.inputTemplates = this.filterTemplates(this.inputTemplates, "input");
1567
+ this.prefixTemplates = this.filterTemplates(this.prefixTemplates, "prefix");
1568
+ this.suffixTemplates = this.filterTemplates(this.suffixTemplates, "suffix");
1569
+ this.setPrefixTemplates = this.filterTemplates(this.setPrefixTemplates, "setPrefix");
1570
+ this.setSuffixTemplates = this.filterTemplates(this.setSuffixTemplates, "setSuffix");
1571
+ };
1572
+ DynamicFormBaseComponent.prototype.filterTemplates = function (templates, type) {
1573
+ if (ngxUtils.ObjectUtils.isObject(templates) && Object.keys(templates).length > 0)
1574
+ return templates;
1575
+ return this.templates.filter(function (t) { return !!t[type]; }).reduce(function (result, directive) {
1576
+ result[directive[type]] = directive.template;
1577
+ return result;
1578
+ }, {});
1300
1579
  };
1301
- DynamicBaseFormComponent.prototype.ngOnDestroy = function () {
1302
- _super.prototype.ngOnDestroy.call(this);
1303
- this.subscription.unsubscribe();
1304
- this.groupSubscription.unsubscribe();
1305
- };
1306
- DynamicBaseFormComponent.prototype.insertFormArrayGroup = function (index, formArray, formArrayModel) {
1307
- this.formService.insertFormArrayGroup(index, formArray, formArrayModel);
1308
- this.changeDetectorRef.detectChanges();
1309
- };
1310
- DynamicBaseFormComponent.prototype.removeFormArrayGroup = function (index, formArray, formArrayModel) {
1311
- this.formService.removeFormArrayGroup(index, formArray, formArrayModel);
1312
- this.changeDetectorRef.detectChanges();
1313
- };
1314
- DynamicBaseFormComponent.prototype.moveFormArrayGroup = function (index, step, formArray, formArrayModel) {
1315
- this.formService.moveFormArrayGroup(index, step, formArray, formArrayModel);
1316
- this.changeDetectorRef.detectChanges();
1317
- };
1318
- DynamicBaseFormComponent.prototype.clearFormArray = function (formArray, formArrayModel) {
1319
- this.formService.clearFormArray(formArray, formArrayModel);
1320
- this.changeDetectorRef.detectChanges();
1321
- };
1322
- DynamicBaseFormComponent.prototype.getClass = function (model) {
1323
- var parts = collectPathAble(model, function (p) { return p.id; });
1324
- if (parts.length == 0)
1325
- return "";
1326
- if (model instanceof core.DynamicFormGroupModel) {
1327
- return "form-group-" + parts.join("-");
1580
+ return DynamicFormBaseComponent;
1581
+ }());
1582
+ DynamicFormBaseComponent.decorators = [
1583
+ { type: core.Directive }
1584
+ ];
1585
+ DynamicFormBaseComponent.ctorParameters = function () { return [
1586
+ { type: core.ChangeDetectorRef },
1587
+ { type: DynamicFormService }
1588
+ ]; };
1589
+ DynamicFormBaseComponent.propDecorators = {
1590
+ name: [{ type: core.Input }],
1591
+ testId: [{ type: core.Input }],
1592
+ readonly: [{ type: core.Input }],
1593
+ updateOn: [{ type: core.Input }],
1594
+ classes: [{ type: core.Input }],
1595
+ parent: [{ type: core.Input }],
1596
+ wrapperTemplate: [{ type: core.Input }],
1597
+ fieldSetTemplate: [{ type: core.Input }],
1598
+ controlTemplate: [{ type: core.Input }],
1599
+ controlTemplates: [{ type: core.Input }],
1600
+ labelTemplates: [{ type: core.Input }],
1601
+ inputTemplates: [{ type: core.Input }],
1602
+ prefixTemplates: [{ type: core.Input }],
1603
+ suffixTemplates: [{ type: core.Input }],
1604
+ setPrefixTemplates: [{ type: core.Input }],
1605
+ setSuffixTemplates: [{ type: core.Input }],
1606
+ onChange: [{ type: core.Output }],
1607
+ onStatusChange: [{ type: core.Output }],
1608
+ onInit: [{ type: core.Output }],
1609
+ onSubmit: [{ type: core.Output }],
1610
+ prefixTemplate: [{ type: core.ContentChild, args: ["prefixTemplate",] }],
1611
+ suffixTemplate: [{ type: core.ContentChild, args: ["suffixTemplate",] }],
1612
+ templates: [{ type: core.ContentChildren, args: [DynamicFormTemplateDirective,] }],
1613
+ cWrapperTemplate: [{ type: core.ContentChild, args: ["wrapperTemplate",] }],
1614
+ cFieldSetTemplate: [{ type: core.ContentChild, args: ["fieldSetTemplate",] }],
1615
+ cControlTemplate: [{ type: core.ContentChild, args: ["controlTemplate",] }]
1616
+ };
1617
+
1618
+ var DynamicFormComponent = /** @class */ (function (_super) {
1619
+ __extends(DynamicFormComponent, _super);
1620
+ function DynamicFormComponent(cdr, forms) {
1621
+ var _this = _super.call(this, cdr, forms) || this;
1622
+ _this.group = new DynamicFormGroup(_this);
1623
+ _this.defaultFieldSet = {
1624
+ id: "",
1625
+ title: "",
1626
+ classes: ""
1627
+ };
1628
+ return _this;
1629
+ }
1630
+ Object.defineProperty(DynamicFormComponent.prototype, "status", {
1631
+ get: function () {
1632
+ return this.group.state;
1633
+ },
1634
+ enumerable: false,
1635
+ configurable: true
1636
+ });
1637
+ Object.defineProperty(DynamicFormComponent.prototype, "formControls", {
1638
+ get: function () {
1639
+ return this.group.formControls;
1640
+ },
1641
+ enumerable: false,
1642
+ configurable: true
1643
+ });
1644
+ // --- Lifecycle hooks
1645
+ DynamicFormComponent.prototype.ngOnChanges = function (changes) {
1646
+ if (!this.data)
1647
+ return;
1648
+ if (changes.data || changes.controls || changes.serializers || changes.formGroup) {
1649
+ if (this.group.id)
1650
+ return;
1651
+ this.group.setup(this.data, this);
1652
+ this.group.reloadControls();
1328
1653
  }
1329
- return "form-control-" + parts.join("-");
1330
1654
  };
1331
- DynamicBaseFormComponent.prototype.validate = function (showErrors) {
1655
+ // --- Custom ---
1656
+ DynamicFormComponent.prototype.onFormSubmit = function () {
1657
+ var _this = this;
1658
+ var root = this.root;
1659
+ root.validate().then(function () { return root.onSubmit.emit(_this); }, function () { });
1660
+ };
1661
+ // --- IDynamicForm ---
1662
+ DynamicFormComponent.prototype.validate = function (showErrors) {
1332
1663
  var _this = this;
1333
1664
  if (showErrors === void 0) { showErrors = true; }
1334
- if (!this.group)
1335
- return Promise.resolve();
1336
1665
  return new Promise(function (resolve, reject) {
1337
1666
  _this.group.statusChanges.pipe(operators.first(function (status) { return status == "VALID" || status == "INVALID"; })).subscribe(function (status) {
1338
- if (showErrors) {
1339
- _this.formService.showErrors(_this);
1340
- }
1667
+ if (showErrors)
1668
+ _this.group.showErrors();
1341
1669
  if (status == "VALID") {
1342
1670
  resolve(null);
1343
1671
  return;
@@ -1347,384 +1675,628 @@
1347
1675
  _this.group.updateValueAndValidity();
1348
1676
  });
1349
1677
  };
1350
- DynamicBaseFormComponent.prototype.serialize = function (validate) {
1351
- return __awaiter(this, void 0, void 0, function () {
1352
- return __generator(this, function (_a) {
1353
- switch (_a.label) {
1354
- case 0:
1355
- if (!this.group)
1356
- return [2 /*return*/, null];
1357
- if (!validate) return [3 /*break*/, 2];
1358
- return [4 /*yield*/, this.validate()];
1359
- case 1:
1360
- _a.sent();
1361
- _a.label = 2;
1362
- case 2: return [4 /*yield*/, this.formService.serialize(this.model, this.group)];
1363
- case 3: return [2 /*return*/, _a.sent()];
1364
- }
1365
- });
1678
+ DynamicFormComponent.prototype.serialize = function (validate) {
1679
+ var _this = this;
1680
+ return new Promise(function (resolve, reject) {
1681
+ var serialize = function () {
1682
+ _this.group.serialize().then(resolve);
1683
+ };
1684
+ if (validate) {
1685
+ _this.validate().then(serialize, reject);
1686
+ return;
1687
+ }
1688
+ serialize();
1366
1689
  });
1367
1690
  };
1368
- return DynamicBaseFormComponent;
1369
- }(core.DynamicFormComponent));
1370
- DynamicBaseFormComponent.decorators = [
1371
- { type: core$1.Component, args: [{
1372
- selector: "dynamic-base-form",
1373
- template: "",
1374
- changeDetection: core$1.ChangeDetectionStrategy.Default
1691
+ DynamicFormComponent.prototype.check = function () {
1692
+ return this.group.check();
1693
+ };
1694
+ DynamicFormComponent.prototype.getControl = function (id) {
1695
+ return this.group.getControl(id);
1696
+ };
1697
+ return DynamicFormComponent;
1698
+ }(DynamicFormBaseComponent));
1699
+ DynamicFormComponent.decorators = [
1700
+ { type: core.Component, args: [{
1701
+ moduleId: module.id,
1702
+ selector: "dynamic-form, [dynamic-form]",
1703
+ template: "<ng-template #defaultFieldSetTemplate let-id=\"id\" let-controls=\"controls\" let-fieldSet=\"fieldSet\">\r\n <div [ngClass]=\"['form-fields', 'form-fields-' + id, fieldSet.classes]\">\r\n <ng-container [ngxTemplateOutlet]=\"setPrefixTemplates[fieldSet.id]\" [context]=\"fieldSet\"></ng-container>\r\n <div *ngIf=\"fieldSet.title\" [ngClass]=\"['form-title', fieldSet.titleClasses || '']\">\r\n {{ group.prefix + fieldSet.title | translate }}\r\n </div>\r\n <ng-template #subControls>\r\n <ng-container *ngFor=\"let control of controls\" [form-group]=\"control\" [visible]=\"control.visible\" [form]=\"this\">\r\n\r\n </ng-container>\r\n </ng-template>\r\n <div *ngIf=\"fieldSet.setClasses; else subControls\" [ngClass]=\"fieldSet.setClasses\">\r\n <div *ngIf=\"fieldSet.controlClasses; else subControls\" [ngClass]=\"fieldSet.controlClasses\">\r\n <ng-container [ngTemplateOutlet]=\"subControls\"></ng-container>\r\n </div>\r\n </div>\r\n <ng-container [ngxTemplateOutlet]=\"setSuffixTemplates[fieldSet.id]\" [context]=\"fieldSet\"></ng-container>\r\n </div>\r\n</ng-template>\r\n\r\n<ng-template #fieldSetsTemplate>\r\n <ng-container *ngFor=\"let fs of formControls | groupBy:'data.fieldSet'\"\r\n [ngxTemplateOutlet]=\"fieldSetTemplate || defaultFieldSetTemplate\"\r\n [context]=\"{form: this, id: fs.group, controls: fs.items, fieldSet: group.formFields[fs.group] || defaultFieldSet}\">\r\n </ng-container>\r\n</ng-template>\r\n<ng-template #defaultWrapperTemplate let-form=\"form\" let-fieldSetsTemplate=\"fieldSetsTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, fieldSetsTemplate: fieldSetsTemplate}\"></ng-container>\r\n <form class=\"dynamic-form\" [ngClass]=\"form.classes || ''\" [formGroup]=\"group\" (submit)=\"onFormSubmit()\">\r\n <ng-container [ngTemplateOutlet]=\"fieldSetsTemplate\"></ng-container>\r\n <ng-content></ng-content>\r\n <div *ngIf=\"form.status == 'PENDING'\" class=\"dynamic-form-validator\">\r\n {{ group.prefix + 'message.pending' | translate }}\r\n </div>\r\n <button [ngStyle]=\"{display: 'none'}\">Submit</button>\r\n </form>\r\n <ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, fieldSetsTemplate: fieldSetsTemplate}\"></ng-container>\r\n</ng-template>\r\n<ng-template #loadingTemplate>\r\n <div *ngIf=\"status == 'LOADING'\" class=\"dynamic-form-loader\">\r\n {{ group.prefix + 'message.loading' | translate }}\r\n </div>\r\n</ng-template>\r\n<ng-container [ngTemplateOutlet]=\"wrapperTemplate || defaultWrapperTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this, fieldSetsTemplate: fieldSetsTemplate}\"\r\n *ngIf=\"status !== 'LOADING'; else loadingTemplate\">\r\n</ng-container>\r\n",
1704
+ providers: [{ provide: DynamicFormBaseComponent, useExisting: DynamicFormComponent }]
1375
1705
  },] }
1376
1706
  ];
1377
- DynamicBaseFormComponent.ctorParameters = function () { return [
1378
- { type: DynamicFormService, decorators: [{ type: core$1.Inject, args: [DynamicFormService,] }] },
1379
- { type: ngxUtils.EventsService, decorators: [{ type: core$1.Inject, args: [ngxUtils.EventsService,] }] },
1380
- { type: core$1.ChangeDetectorRef },
1381
- { type: core.DynamicFormComponentService }
1707
+ DynamicFormComponent.ctorParameters = function () { return [
1708
+ { type: core.ChangeDetectorRef },
1709
+ { type: DynamicFormService }
1382
1710
  ]; };
1383
- DynamicBaseFormComponent.propDecorators = {
1384
- group: [{ type: core$1.Input }],
1385
- model: [{ type: core$1.Input }],
1386
- layout: [{ type: core$1.Input }],
1387
- labelPrefix: [{ type: core$1.Input }],
1388
- blur: [{ type: core$1.Output }],
1389
- change: [{ type: core$1.Output }],
1390
- focus: [{ type: core$1.Output }],
1391
- contentTemplates: [{ type: core$1.ContentChildren, args: [core.DynamicTemplateDirective,] }],
1392
- viewTemplates: [{ type: core$1.ViewChildren, args: [core.DynamicTemplateDirective,] }],
1393
- onValueChange: [{ type: core$1.Output }],
1394
- onStatusChange: [{ type: core$1.Output }],
1395
- onSubmit: [{ type: core$1.Output }],
1396
- ngForm: [{ type: core$1.ViewChild, args: [forms.NgForm,] }]
1711
+ DynamicFormComponent.propDecorators = {
1712
+ group: [{ type: core.Input }],
1713
+ controls: [{ type: core.Input }],
1714
+ serializers: [{ type: core.Input }],
1715
+ fieldSets: [{ type: core.Input }],
1716
+ data: [{ type: core.Input }]
1397
1717
  };
1398
1718
 
1399
- var DynamicBaseFormArrayComponent = /** @class */ (function (_super) {
1400
- __extends(DynamicBaseFormArrayComponent, _super);
1401
- function DynamicBaseFormArrayComponent(layoutService, validationService, injector) {
1402
- var _this = _super.call(this, layoutService, validationService) || this;
1403
- _this.layoutService = layoutService;
1404
- _this.validationService = validationService;
1405
- _this.injector = injector;
1406
- _this.blur = new core$1.EventEmitter();
1407
- _this.change = new core$1.EventEmitter();
1408
- _this.customEvent = new core$1.EventEmitter();
1409
- _this.focus = new core$1.EventEmitter();
1719
+ var statusPriority = ["LOADING", "PENDING", "DISABLED", "INVALID"];
1720
+ var DynamicFormsComponent = /** @class */ (function (_super) {
1721
+ __extends(DynamicFormsComponent, _super);
1722
+ function DynamicFormsComponent(cdr, formService) {
1723
+ var _this = _super.call(this, cdr, formService) || this;
1724
+ _this.formPrefixTemplates = {};
1725
+ _this.formSuffixTemplates = {};
1726
+ _this.innerFormPrefixTemplates = {};
1727
+ _this.innerFormSuffixTemplates = {};
1410
1728
  return _this;
1411
1729
  }
1412
- Object.defineProperty(DynamicBaseFormArrayComponent.prototype, "useTabs", {
1730
+ Object.defineProperty(DynamicFormsComponent.prototype, "status", {
1413
1731
  get: function () {
1414
- var _a;
1415
- return (_a = this.model) === null || _a === void 0 ? void 0 : _a.useTabs;
1732
+ var _loop_1 = function (i) {
1733
+ var status = statusPriority[i];
1734
+ if (this_1.checkForms(function (f) { return f.status == status; }))
1735
+ return { value: status };
1736
+ };
1737
+ var this_1 = this;
1738
+ for (var i = 0; i < statusPriority.length; i++) {
1739
+ var state_1 = _loop_1(i);
1740
+ if (typeof state_1 === "object")
1741
+ return state_1.value;
1742
+ }
1743
+ return "VALID";
1416
1744
  },
1417
1745
  enumerable: false,
1418
1746
  configurable: true
1419
1747
  });
1420
- DynamicBaseFormArrayComponent.prototype.saveTab = function (index) {
1421
- this.model.saveTab(index, this.model, this.injector);
1422
- };
1423
- DynamicBaseFormArrayComponent.prototype.restoreTab = function () {
1424
- return this.model.restoreTab(this.model, this.injector);
1425
- };
1426
- DynamicBaseFormArrayComponent.prototype.getClass = function (context, place, model) {
1427
- var _a;
1428
- return [
1429
- context == "element" ? this.getModelClass(model) : null,
1430
- context == "element" ? this.getAdditionalClass(model) : null,
1431
- _super.prototype.getClass.call(this, context, place, model),
1432
- model instanceof core.DynamicFormValueControlModel ? (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes : null
1433
- ].filter(function (cls) { return !!cls; }).join(" ");
1434
- };
1435
- DynamicBaseFormArrayComponent.prototype.getModelClass = function (model) {
1436
- var parts = collectPathAble(model, function (p) { return p.id; });
1437
- if (parts.length == 0)
1438
- return "";
1439
- if (model instanceof core.DynamicFormGroupModel) {
1440
- return "form-group-" + parts.join("-");
1441
- }
1442
- return "form-control-" + parts.join("-");
1748
+ // --- Lifecycle hooks
1749
+ DynamicFormsComponent.prototype.ngAfterContentInit = function () {
1750
+ _super.prototype.ngAfterContentInit.call(this);
1751
+ this.containerTemplate = this.containerTemplate || this.cContainerTemplate;
1752
+ this.formPrefixTemplates = this.filterTemplates(this.formPrefixTemplates, "formPrefix");
1753
+ this.formSuffixTemplates = this.filterTemplates(this.formSuffixTemplates, "formSuffix");
1754
+ this.innerFormPrefixTemplates = this.filterTemplates(this.innerFormPrefixTemplates, "innerFormPrefix");
1755
+ this.innerFormSuffixTemplates = this.filterTemplates(this.innerFormSuffixTemplates, "innerFormSuffix");
1756
+ };
1757
+ DynamicFormsComponent.prototype.ngOnChanges = function (changes) {
1758
+ this.configs = this.createFormGroups(this.data);
1759
+ };
1760
+ // --- IDynamicFormBase ---
1761
+ DynamicFormsComponent.prototype.validate = function (showErrors) {
1762
+ if (showErrors === void 0) { showErrors = true; }
1763
+ if (!this.forms)
1764
+ return Promise.reject(null);
1765
+ return Promise.all(this.forms.map(function (f) { return f.validate(showErrors); }));
1443
1766
  };
1444
- DynamicBaseFormArrayComponent.prototype.getAdditionalClass = function (model) {
1445
- var _a, _b;
1446
- if (model instanceof DynamicFormArrayModel) {
1447
- return (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes;
1448
- }
1449
- if (model instanceof core.DynamicFormValueControlModel) {
1450
- return (_b = model.additional) === null || _b === void 0 ? void 0 : _b.classes;
1451
- }
1452
- return null;
1767
+ DynamicFormsComponent.prototype.serialize = function (validate) {
1768
+ var _this = this;
1769
+ if (!this.forms)
1770
+ return validate ? Promise.reject(null) : Promise.resolve({});
1771
+ return new Promise(function (resolve, reject) {
1772
+ var promises = _this.forms.map(function (f) { return f.serialize(validate); });
1773
+ Promise.all(promises).then(function (results) {
1774
+ var result = {};
1775
+ results.forEach(function (data, ix) {
1776
+ var config = _this.data[ix];
1777
+ var path = null;
1778
+ if (ngxUtils.ObjectUtils.isArray(config.path) && config.path.length > 0) {
1779
+ path = config.path;
1780
+ }
1781
+ else if (ngxUtils.ObjectUtils.isString(config.path) && config.path.length > 0) {
1782
+ path = config.path.split(".");
1783
+ }
1784
+ else if (ngxUtils.ObjectUtils.isNumber(config.path)) {
1785
+ path = [config.path];
1786
+ }
1787
+ if (!path) {
1788
+ result = ngxUtils.ObjectUtils.assign(result, data);
1789
+ return;
1790
+ }
1791
+ result = ngxUtils.ObjectUtils.mapToPath(result, data, path.map(function (p) { return "" + p; }));
1792
+ });
1793
+ resolve(result);
1794
+ }, reject);
1795
+ });
1453
1796
  };
1454
- return DynamicBaseFormArrayComponent;
1455
- }(core.DynamicFormArrayComponent));
1456
- DynamicBaseFormArrayComponent.decorators = [
1457
- { type: core$1.Component, args: [{
1458
- selector: "dynamic-base-form-array",
1459
- template: "",
1460
- changeDetection: core$1.ChangeDetectionStrategy.OnPush
1797
+ DynamicFormsComponent.prototype.check = function () {
1798
+ if (!this.forms)
1799
+ return Promise.resolve(null);
1800
+ return Promise.all(this.forms.map(function (t) { return t.check(); }));
1801
+ };
1802
+ DynamicFormsComponent.prototype.getControl = function (id) {
1803
+ return this.getFromValue(function (f) { return f.getControl(id); });
1804
+ };
1805
+ DynamicFormsComponent.prototype.checkForms = function (check) {
1806
+ this.cdr.detectChanges();
1807
+ if (!this.forms)
1808
+ return false;
1809
+ return ngxUtils.ObjectUtils.isDefined(this.forms.find(check));
1810
+ };
1811
+ DynamicFormsComponent.prototype.getFromValue = function (check) {
1812
+ if (!this.forms)
1813
+ return null;
1814
+ var value = null;
1815
+ this.forms.find(function (f) {
1816
+ value = check(f);
1817
+ return ngxUtils.ObjectUtils.isDefined(value);
1818
+ });
1819
+ return value;
1820
+ };
1821
+ DynamicFormsComponent.prototype.createFormGroups = function (configs) {
1822
+ var _this = this;
1823
+ return (configs || []).map(function (c) {
1824
+ if (c.multi)
1825
+ return c;
1826
+ var config = c;
1827
+ var group = new DynamicFormGroup(_this, {
1828
+ id: config.id || ngxUtils.UniqueUtils.uuid(),
1829
+ type: "model",
1830
+ data: config.controlData
1831
+ });
1832
+ config.group = group;
1833
+ config.name = config.name || _this.name;
1834
+ group.setup(config.data, config);
1835
+ group.reloadControls();
1836
+ return config;
1837
+ });
1838
+ };
1839
+ return DynamicFormsComponent;
1840
+ }(DynamicFormBaseComponent));
1841
+ DynamicFormsComponent.decorators = [
1842
+ { type: core.Component, args: [{
1843
+ moduleId: module.id,
1844
+ selector: "dynamic-forms, [dynamic-forms]",
1845
+ template: "<ng-template #configTemplate let-formTemplate=\"formTemplate\" let-form=\"form\" let-config=\"config\" let-configTemplate>\r\n <div [ngClass]=\"config.classes || ''\">\r\n <ng-container [ngTemplateOutlet]=\"formPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: form}\"></ng-container>\r\n <ng-template #singleFormTemplate>\r\n <div dynamic-form\r\n [hidden]=\"!config.group?.visible\"\r\n [ngClass]=\"config.formClasses || ''\"\r\n [name]=\"config.name || form.name\"\r\n [testId]=\"testId + '-' + (config.testId || config.name || name)\"\r\n [readonly]=\"form.readonly\"\r\n [updateOn]=\"form.updateOn\"\r\n [classes]=\"config.innerFormClasses\"\r\n [parent]=\"form\"\r\n\r\n [wrapperTemplate]=\"form.wrapperTemplate\"\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n [group]=\"config.group\"\r\n [fieldSets]=\"config.fieldSets\">\r\n <ng-template #prefixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n <ng-template #suffixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n </div>\r\n </ng-template>\r\n <div dynamic-forms\r\n [ngClass]=\"config.formClasses || ''\"\r\n [name]=\"config.name || name\"\r\n [testId]=\"testId + '-' + (config.testId || config.name || name)\"\r\n [readonly]=\"form.readonly\"\r\n [updateOn]=\"form.updateOn\"\r\n [classes]=\"config.innerFormClasses\"\r\n [parent]=\"form\"\r\n\r\n [wrapperTemplate]=\"form.wrapperTemplate\"\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n [data]=\"config.data\"\r\n [containerTemplate]=\"form.containerTemplate\"\r\n [formPrefixTemplates]=\"form.formPrefixTemplates\"\r\n [formSuffixTemplates]=\"form.formSuffixTemplates\"\r\n [innerFormPrefixTemplates]=\"form.innerFormPrefixTemplates\"\r\n [innerFormSuffixTemplates]=\"form.innerFormSuffixTemplates\"\r\n\r\n *ngIf=\"config.multi; else singleFormTemplate\">\r\n <ng-template #prefixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormPrefixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n <ng-template #suffixTemplate let-subForm=\"form\">\r\n <ng-container [ngTemplateOutlet]=\"form.innerFormSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: subForm}\"></ng-container>\r\n </ng-template>\r\n </div>\r\n <ng-container [ngTemplateOutlet]=\"formSuffixTemplates[config.id]\"\r\n [ngTemplateOutletContext]=\"{config: config, form: form}\"></ng-container>\r\n </div>\r\n</ng-template>\r\n<ng-template let-form=\"form\" let-configTemplate=\"configTemplate\" #defaultContainerTemplate>\r\n <div class=\"dynamic-forms\" [ngClass]=\"classes || ''\">\r\n <ng-container *ngFor=\"let config of form.configs\"\r\n [ngTemplateOutlet]=\"configTemplate\"\r\n [ngTemplateOutletContext]=\"{form: form, config: config}\"></ng-container>\r\n <ng-content></ng-content>\r\n </div>\r\n</ng-template>\r\n<ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this}\"></ng-container>\r\n<ng-container [ngTemplateOutlet]=\"containerTemplate || defaultContainerTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this, configTemplate: configTemplate, defaultContainerTemplate: defaultContainerTemplate}\">\r\n</ng-container>\r\n<ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"{form: this}\"></ng-container>\r\n",
1846
+ providers: [{ provide: DynamicFormBaseComponent, useExisting: DynamicFormsComponent }]
1461
1847
  },] }
1462
1848
  ];
1463
- DynamicBaseFormArrayComponent.ctorParameters = function () { return [
1464
- { type: core.DynamicFormLayoutService },
1465
- { type: core.DynamicFormValidationService },
1466
- { type: core$1.Injector }
1849
+ DynamicFormsComponent.ctorParameters = function () { return [
1850
+ { type: core.ChangeDetectorRef },
1851
+ { type: DynamicFormService }
1467
1852
  ]; };
1468
- DynamicBaseFormArrayComponent.propDecorators = {
1469
- formLayout: [{ type: core$1.Input }],
1470
- group: [{ type: core$1.Input }],
1471
- layout: [{ type: core$1.Input }],
1472
- model: [{ type: core$1.Input }],
1473
- templates: [{ type: core$1.Input }],
1474
- blur: [{ type: core$1.Output }],
1475
- change: [{ type: core$1.Output }],
1476
- customEvent: [{ type: core$1.Output }],
1477
- focus: [{ type: core$1.Output }],
1478
- components: [{ type: core$1.ViewChildren, args: [core$1.forwardRef(function () { return core.DynamicFormControlContainerComponent; }),] }]
1853
+ DynamicFormsComponent.propDecorators = {
1854
+ data: [{ type: core.Input }],
1855
+ containerTemplate: [{ type: core.Input }],
1856
+ formPrefixTemplates: [{ type: core.Input }],
1857
+ formSuffixTemplates: [{ type: core.Input }],
1858
+ innerFormPrefixTemplates: [{ type: core.Input }],
1859
+ innerFormSuffixTemplates: [{ type: core.Input }],
1860
+ cContainerTemplate: [{ type: core.ContentChild, args: ["containerTemplate",] }],
1861
+ forms: [{ type: core.ViewChildren, args: [DynamicFormBaseComponent,] }]
1479
1862
  };
1480
1863
 
1481
- var DynamicBaseFormControlContainerComponent = /** @class */ (function (_super) {
1482
- __extends(DynamicBaseFormControlContainerComponent, _super);
1483
- function DynamicBaseFormControlContainerComponent(form, changeDetectorRef, componentFactoryResolver, layoutService, validationService, componentService, relationService) {
1484
- var _this = _super.call(this, changeDetectorRef, componentFactoryResolver, layoutService, validationService, componentService, relationService) || this;
1485
- _this.form = form;
1486
- _this.changeDetectorRef = changeDetectorRef;
1487
- _this.componentFactoryResolver = componentFactoryResolver;
1488
- _this.layoutService = layoutService;
1489
- _this.validationService = validationService;
1490
- _this.componentService = componentService;
1491
- _this.relationService = relationService;
1492
- _this.context = null;
1493
- _this.blur = new core$1.EventEmitter();
1494
- _this.change = new core$1.EventEmitter();
1495
- _this.focus = new core$1.EventEmitter();
1496
- return _this;
1864
+ var DynamicFormGroupComponent = /** @class */ (function () {
1865
+ function DynamicFormGroupComponent() {
1497
1866
  }
1498
- Object.defineProperty(DynamicBaseFormControlContainerComponent.prototype, "componentType", {
1499
- get: function () {
1500
- var _a;
1501
- return (_a = this.componentService.getCustomComponentType(this.model)) !== null && _a !== void 0 ? _a : this.getComponentType(this.model);
1502
- },
1503
- enumerable: false,
1504
- configurable: true
1505
- });
1506
- Object.defineProperty(DynamicBaseFormControlContainerComponent.prototype, "startTemplate", {
1867
+ Object.defineProperty(DynamicFormGroupComponent.prototype, "classes", {
1507
1868
  get: function () {
1508
- return (this.model.type == core.DYNAMIC_FORM_CONTROL_TYPE_ARRAY)
1509
- ? this.layoutService.getAlignedTemplate(this.model, this.templates, "ARRAY_START")
1510
- : this.layoutService.getStartTemplate(this.model, this.templates);
1869
+ if (!this.control)
1870
+ return "form-group";
1871
+ return ["form-group", "form-group-" + this.control.id, this.control.data.classes, this.control.errors && this.control.touched ? "form-group-invalid" : ""].join(" ");
1511
1872
  },
1512
1873
  enumerable: false,
1513
1874
  configurable: true
1514
1875
  });
1515
- Object.defineProperty(DynamicBaseFormControlContainerComponent.prototype, "endTemplate", {
1516
- get: function () {
1517
- return (this.model.type == core.DYNAMIC_FORM_CONTROL_TYPE_ARRAY)
1518
- ? this.layoutService.getAlignedTemplate(this.model, this.templates, "ARRAY_END")
1519
- : this.layoutService.getEndTemplate(this.model, this.templates);
1520
- },
1521
- enumerable: false,
1522
- configurable: true
1523
- });
1524
- Object.defineProperty(DynamicBaseFormControlContainerComponent.prototype, "formService", {
1525
- get: function () {
1526
- return this.form.formService;
1527
- },
1528
- enumerable: false,
1529
- configurable: true
1530
- });
1531
- DynamicBaseFormControlContainerComponent.prototype.ngOnInit = function () {
1876
+ return DynamicFormGroupComponent;
1877
+ }());
1878
+ DynamicFormGroupComponent.decorators = [
1879
+ { type: core.Component, args: [{
1880
+ moduleId: module.id,
1881
+ selector: "div[dynamic-form-group]",
1882
+ template: "<ng-template #labelTemplate>\r\n <label [ngClass]=\"'control-label control-label-' + control.data.labelAlign\" [attr.for]=\"control.formId\">\r\n {{ control.label | translate: control.model }}\r\n </label>\r\n</ng-template>\r\n<ng-template #errorTemplate>\r\n <div class=\"error-message\" *ngIf=\"control.errors && control.touched\">\r\n <span class=\"help-block\" *ngFor=\"let error of control.errors | entries\">\r\n {{ error.key | translate: error.value }}\r\n </span>\r\n </div>\r\n</ng-template>\r\n<ng-template #inputTemplate let-control=\"control\">\r\n <ng-container [form-control]=\"control\"></ng-container>\r\n</ng-template>\r\n<ng-template #defaultControlTemplate\r\n let-context\r\n let-control=\"control\"\r\n let-data=\"control.data\"\r\n let-labelTemplate=\"labelTemplate\"\r\n let-inputTemplate=\"inputTemplate\"\r\n let-prefixTemplate=\"prefixTemplate\"\r\n let-suffixTemplate=\"suffixTemplate\"\r\n let-errorTemplate=\"errorTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"prefixTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container *ngIf=\"control.label && data.labelAlign == 'left'\"\r\n [ngTemplateOutlet]=\"labelTemplate\"\r\n [ngTemplateOutletContext]=\"context\">\r\n </ng-container>\r\n <ng-container [ngTemplateOutlet]=\"inputTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container *ngIf=\"control.label && data.labelAlign == 'right'\"\r\n [ngTemplateOutlet]=\"labelTemplate\"\r\n [ngTemplateOutletContext]=\"context\">\r\n </ng-container>\r\n <ng-container [ngTemplateOutlet]=\"suffixTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n <ng-container [ngTemplateOutlet]=\"errorTemplate\"\r\n [ngTemplateOutletContext]=\"context\"></ng-container>\r\n</ng-template>\r\n\r\n<ng-container [ngxTemplateOutlet]=\"form.controlTemplates[control.id] || form.controlTemplate || defaultControlTemplate\"\r\n [context]=\"{\r\n control: control,\r\n labelTemplate: form.labelTemplates[control.id] || labelTemplate,\r\n inputTemplate: form.inputTemplates[control.id] || inputTemplate,\r\n prefixTemplate: form.prefixTemplates[control.id],\r\n suffixTemplate: form.suffixTemplates[control.id],\r\n errorTemplate: errorTemplate\r\n }\">\r\n</ng-container>\r\n"
1883
+ },] }
1884
+ ];
1885
+ DynamicFormGroupComponent.propDecorators = {
1886
+ classes: [{ type: core.HostBinding, args: ["class",] }]
1887
+ };
1888
+
1889
+ var DynamicFormFileComponent = /** @class */ (function (_super) {
1890
+ __extends(DynamicFormFileComponent, _super);
1891
+ function DynamicFormFileComponent(api, toaster) {
1892
+ var _this = _super.call(this) || this;
1893
+ _this.api = api;
1894
+ _this.toaster = toaster;
1895
+ _this.fileImageCache = [];
1896
+ return _this;
1897
+ }
1898
+ // Acceptor for provider
1899
+ DynamicFormFileComponent.acceptor = function (control) {
1900
+ return control.type == "file";
1901
+ };
1902
+ // Loader for provider
1903
+ DynamicFormFileComponent.loader = function () {
1904
+ return Promise.resolve();
1905
+ };
1906
+ DynamicFormFileComponent.prototype.onSelect = function (input) {
1907
+ this.processFiles(input.files);
1908
+ input.value = "";
1909
+ };
1910
+ DynamicFormFileComponent.prototype.processFiles = function (fileList) {
1911
+ var files = [];
1912
+ var accept = this.data.accept;
1913
+ var types = ngxUtils.ObjectUtils.isString(accept) && accept.length > 0 ? accept.toLowerCase().split(",") : null;
1914
+ if (fileList.length == 0)
1915
+ return;
1916
+ for (var i = 0; i < fileList.length; i++) {
1917
+ var file = fileList.item(i);
1918
+ var type = file.type.toLowerCase();
1919
+ var ext = ngxUtils.FileUtils.getExtension(file);
1920
+ if (types && !ngxUtils.ArrayUtils.has(types, type, ext))
1921
+ continue;
1922
+ files.push(file);
1923
+ }
1924
+ if (files.length == 0) {
1925
+ this.toaster.error("message.error.wrong-files");
1926
+ return;
1927
+ }
1928
+ this.upload(files);
1929
+ };
1930
+ DynamicFormFileComponent.prototype.upload = function (files) {
1532
1931
  var _this = this;
1533
- this.onDetectChanges = this.formService.onDetectChanges.subscribe(function (form) {
1534
- if (form !== _this.form)
1932
+ var single = !this.data.multi;
1933
+ if (single)
1934
+ files.length = Math.min(files.length, 1);
1935
+ var promises = [];
1936
+ files.forEach(function (file, ix) {
1937
+ if (_this.data.asDataUrl) {
1938
+ promises.push(ngxUtils.FileUtils.readFileAsDataURL(file));
1535
1939
  return;
1536
- _this.changeDetectorRef.detectChanges();
1537
- _this.formService.updateSelectOptions(_this.model, _this.control, _this.form.model);
1940
+ }
1941
+ if (_this.data.asFile) {
1942
+ promises.push(Promise.resolve(file));
1943
+ return;
1944
+ }
1945
+ promises.push(_this.api.upload(_this.data.uploadUrl, _this.data.createUploadData(file), console.log, _this.data.uploadOptions).then(function (asset) { return asset._id || asset; }, function () { return null; }));
1946
+ });
1947
+ Promise.all(promises).then(function (assets) {
1948
+ if (single) {
1949
+ _this.control.setValue(assets[0]);
1950
+ return;
1951
+ }
1952
+ var current = _this.value || [];
1953
+ _this.control.setValue(current.concat(assets.filter(function (t) { return !!t; })));
1538
1954
  });
1539
1955
  };
1540
- DynamicBaseFormControlContainerComponent.prototype.ngOnDestroy = function () {
1541
- _super.prototype.ngOnDestroy.call(this);
1542
- this.onDetectChanges.unsubscribe();
1543
- };
1544
- DynamicBaseFormControlContainerComponent.prototype.getLabel = function () {
1545
- var _a;
1546
- var label = collectPathAble(this.model, function (p) { return p.label; });
1547
- if (label.length == 0)
1548
- return "";
1549
- if ((_a = this.form) === null || _a === void 0 ? void 0 : _a.labelPrefix) {
1550
- label.unshift(this.form.labelPrefix);
1956
+ DynamicFormFileComponent.prototype.delete = function (index) {
1957
+ if (this.data.multi) {
1958
+ var current = Array.from(this.value || []);
1959
+ current.splice(index, 1);
1960
+ this.control.setValue(current);
1961
+ return;
1962
+ }
1963
+ this.control.setValue(null);
1964
+ };
1965
+ DynamicFormFileComponent.prototype.getUrl = function (image) {
1966
+ return "url('" + this.getImgUrl(image) + "')";
1967
+ };
1968
+ DynamicFormFileComponent.prototype.getImgUrl = function (image) {
1969
+ if (ngxUtils.ObjectUtils.isBlob(image)) {
1970
+ var cache = this.fileImageCache.find(function (t) { return t.file == image; });
1971
+ if (!cache) {
1972
+ cache = { file: image, url: URL.createObjectURL(image) };
1973
+ this.fileImageCache.push(cache);
1974
+ }
1975
+ return cache.url;
1976
+ }
1977
+ var url = !image ? null : image.imageUrl || image;
1978
+ if (!ngxUtils.ObjectUtils.isString(url))
1979
+ return null;
1980
+ if (url.startsWith("data:"))
1981
+ return url;
1982
+ if (!this.data.baseUrl) {
1983
+ var subUrl = url.startsWith("/") ? url.substr(1) : url;
1984
+ return this.api.url(subUrl);
1551
1985
  }
1552
- return label.join(".");
1986
+ return this.api.url("" + this.data.baseUrl + url);
1987
+ };
1988
+ return DynamicFormFileComponent;
1989
+ }(FormControlComponent));
1990
+ DynamicFormFileComponent.decorators = [
1991
+ { type: core.Component, args: [{
1992
+ selector: "dynamic-form-file",
1993
+ template: "<div class=\"upload\">\r\n <input type=\"file\"\r\n multiple=\"multiple\"\r\n [attr.data-testid]=\"testId\"\r\n [attr.accept]=\"data.accept\"\r\n (change)=\"onSelect($event.target)\" />\r\n <ul class=\"images\" *ngIf=\"!data.multi\">\r\n <li class=\"image\" *ngIf=\"value\" [ngStyle]=\"{backgroundImage: getUrl(value)}\">\r\n <a class=\"btn btn-delete\" (click)=\"delete()\"></a>\r\n </li>\r\n </ul>\r\n <ul class=\"images\" *ngIf=\"data.multi\">\r\n <li class=\"image\" *ngFor=\"let image of value; let i = index\" [ngStyle]=\"{backgroundImage: getUrl(image)}\">\r\n <a class=\"btn btn-delete\" (click)=\"delete(i)\"></a>\r\n </li>\r\n </ul>\r\n</div>\r\n",
1994
+ styles: [".upload{display:inline-block}.upload ul{display:inline-flex;list-style:none;margin:10px 0 0;padding:0}.upload ul li{height:100px;width:100px;background:repeating-linear-gradient(45deg,gray,gray 10px,lightgray 10px,lightgray 20px) center center;background-size:cover;border:1px gray solid;margin-right:5px;position:relative}.upload .btn-delete{background:linear-gradient(to bottom,#c8607a,#a64d5a);border-color:#a64d5a;color:#fff;position:absolute;padding:0;right:5px;top:5px;width:20px;height:20px}.upload .btn-delete:before{color:#fff;display:block;position:absolute;top:0;right:6px;content:\"x\"}\n"]
1995
+ },] }
1996
+ ];
1997
+ DynamicFormFileComponent.ctorParameters = function () { return [
1998
+ { type: ngxUtils.ApiService },
1999
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.TOASTER_SERVICE,] }] }
2000
+ ]; };
2001
+
2002
+ var DynamicFormInputComponent = /** @class */ (function (_super) {
2003
+ __extends(DynamicFormInputComponent, _super);
2004
+ function DynamicFormInputComponent(language) {
2005
+ var _this = _super.call(this) || this;
2006
+ _this.language = language;
2007
+ return _this;
2008
+ }
2009
+ // Acceptor for provider
2010
+ DynamicFormInputComponent.acceptor = function (control) {
2011
+ return control.type == "input";
2012
+ };
2013
+ // Loader for provider
2014
+ DynamicFormInputComponent.loader = function () {
2015
+ return Promise.resolve();
1553
2016
  };
1554
- DynamicBaseFormControlContainerComponent.prototype.createFormControlComponent = function () {
1555
- var _a;
1556
- _super.prototype.createFormControlComponent.call(this);
1557
- var component = (_a = this.componentRef) === null || _a === void 0 ? void 0 : _a.instance;
1558
- if (!component || !ngxUtils.ObjectUtils.isFunction(component.onCreated))
2017
+ Object.defineProperty(DynamicFormInputComponent.prototype, "isChecked", {
2018
+ get: function () {
2019
+ return this.data.type == "checkbox" && this.value;
2020
+ },
2021
+ enumerable: false,
2022
+ configurable: true
2023
+ });
2024
+ DynamicFormInputComponent.prototype.onDateChange = function (value) {
2025
+ var date = new Date(value);
2026
+ var dateValue = date.valueOf();
2027
+ if (isNaN(dateValue) || dateValue < -30610224000000)
1559
2028
  return;
1560
- component.onCreated();
2029
+ this.control.setValue(date);
1561
2030
  };
1562
- DynamicBaseFormControlContainerComponent.prototype.getComponentType = function (model) {
1563
- return null;
2031
+ DynamicFormInputComponent.prototype.onTextChange = function (value) {
2032
+ var _this = this;
2033
+ if (!this.data.useLanguage) {
2034
+ this.control.setValue(value);
2035
+ return;
2036
+ }
2037
+ var translations = ngxUtils.ObjectUtils.isArray(this.value) ? Array.from(this.value) : [];
2038
+ var translation = translations.find(function (t) { return t.lang == _this.language.editLanguage; });
2039
+ if (translation) {
2040
+ translation.translation = value;
2041
+ }
2042
+ else {
2043
+ translations.push({
2044
+ lang: this.language.editLanguage,
2045
+ translation: value
2046
+ });
2047
+ }
2048
+ this.control.setValue(translations);
1564
2049
  };
1565
- return DynamicBaseFormControlContainerComponent;
1566
- }(core.DynamicFormControlContainerComponent));
1567
- DynamicBaseFormControlContainerComponent.decorators = [
1568
- { type: core$1.Component, args: [{
1569
- selector: "dynamic-base-form-control",
1570
- template: "",
1571
- changeDetection: core$1.ChangeDetectionStrategy.OnPush
2050
+ DynamicFormInputComponent.prototype.onNumberBlur = function () {
2051
+ var value = this.value;
2052
+ if (ngxUtils.ObjectUtils.isNumber(this.data.max) && this.data.max < value) {
2053
+ this.control.setValue(this.data.max);
2054
+ }
2055
+ else if (ngxUtils.ObjectUtils.isNumber(this.data.min) && this.data.min > value) {
2056
+ this.control.setValue(this.data.min);
2057
+ }
2058
+ this.control.onBlur();
2059
+ };
2060
+ return DynamicFormInputComponent;
2061
+ }(FormControlComponent));
2062
+ DynamicFormInputComponent.decorators = [
2063
+ { type: core.Component, args: [{
2064
+ moduleId: module.id,
2065
+ selector: "dynamic-form-input",
2066
+ template: "<ng-container [ngSwitch]=\"data.type\">\r\n <ng-container *ngSwitchCase=\"'textarea'\">\r\n <textarea class=\"form-control\"\r\n rows=\"5\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [attr.data-testid]=\"testId\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">{{ data.placeholder | translate }}</textarea>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'date'\">\r\n <input class=\"form-control\"\r\n type=\"date\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [attr.data-testid]=\"testId\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value | date: 'y-MM-dd'\"\r\n (ngModelChange)=\"onDateChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'number'\">\r\n <input class=\"form-control\"\r\n type=\"number\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [attr.data-testid]=\"testId\"\r\n [min]=\"data.min\"\r\n [max]=\"data.max\"\r\n [step]=\"data.step\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"onNumberBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'checkbox'\">\r\n <input class=\"form-control\"\r\n type=\"checkbox\"\r\n [attr.data-testid]=\"testId\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'text'\">\r\n <input class=\"form-control\"\r\n type=\"text\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [attr.data-testid]=\"testId\"\r\n [minlength]=\"data.min\"\r\n [maxlength]=\"data.max\"\r\n [placeholder]=\"data.placeholder | translate\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"data.useLanguage ? (value | translate) : value\"\r\n (ngModelChange)=\"onTextChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n <ng-container *ngSwitchDefault>\r\n <input class=\"form-control\"\r\n [attr.autocomplete]=\"data.autocomplete\"\r\n [attr.data-testid]=\"testId\"\r\n [minlength]=\"data.min\"\r\n [maxlength]=\"data.max\"\r\n [placeholder]=\"data.placeholder | translate\"\r\n [type]=\"data.type\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"control.setValue($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\"/>\r\n </ng-container>\r\n</ng-container>\r\n"
1572
2067
  },] }
1573
2068
  ];
1574
- DynamicBaseFormControlContainerComponent.ctorParameters = function () { return [
1575
- { type: DynamicBaseFormComponent },
1576
- { type: core$1.ChangeDetectorRef },
1577
- { type: core$1.ComponentFactoryResolver },
1578
- { type: core.DynamicFormLayoutService },
1579
- { type: core.DynamicFormValidationService },
1580
- { type: core.DynamicFormComponentService },
1581
- { type: core.DynamicFormRelationService }
2069
+ DynamicFormInputComponent.ctorParameters = function () { return [
2070
+ { type: undefined, decorators: [{ type: core.Inject, args: [ngxUtils.LANGUAGE_SERVICE,] }] }
1582
2071
  ]; };
1583
- DynamicBaseFormControlContainerComponent.propDecorators = {
1584
- contentTemplateList: [{ type: core$1.ContentChildren, args: [core.DynamicTemplateDirective,] }],
1585
- klass: [{ type: core$1.HostBinding, args: ["class",] }],
1586
- context: [{ type: core$1.Input }],
1587
- group: [{ type: core$1.Input }],
1588
- hostClass: [{ type: core$1.Input }],
1589
- inputTemplateList: [{ type: core$1.Input, args: ["templates",] }],
1590
- layout: [{ type: core$1.Input }],
1591
- model: [{ type: core$1.Input }],
1592
- blur: [{ type: core$1.Output }],
1593
- change: [{ type: core$1.Output }],
1594
- focus: [{ type: core$1.Output }],
1595
- componentViewContainerRef: [{ type: core$1.ViewChild, args: ["componentViewContainer", { read: core$1.ViewContainerRef, static: true },] }]
2072
+ DynamicFormInputComponent.propDecorators = {
2073
+ isChecked: [{ type: core.HostBinding, args: ["class.checked",] }]
1596
2074
  };
1597
2075
 
1598
- var DynamicBaseFormGroupComponent = /** @class */ (function (_super) {
1599
- __extends(DynamicBaseFormGroupComponent, _super);
1600
- function DynamicBaseFormGroupComponent(layoutService, validationService) {
1601
- var _this = _super.call(this, layoutService, validationService) || this;
1602
- _this.layoutService = layoutService;
1603
- _this.validationService = validationService;
1604
- _this.blur = new core$1.EventEmitter();
1605
- _this.change = new core$1.EventEmitter();
1606
- _this.customEvent = new core$1.EventEmitter();
1607
- _this.focus = new core$1.EventEmitter();
1608
- return _this;
2076
+ var DynamicFormSelectComponent = /** @class */ (function (_super) {
2077
+ __extends(DynamicFormSelectComponent, _super);
2078
+ function DynamicFormSelectComponent() {
2079
+ return _super !== null && _super.apply(this, arguments) || this;
1609
2080
  }
1610
- DynamicBaseFormGroupComponent.prototype.getClass = function (context, place, model) {
1611
- return [
1612
- context == "element" ? this.getModelClass(model) : null,
1613
- context == "element" ? this.getAdditionalClass(model) : null,
1614
- _super.prototype.getClass.call(this, context, place, model)
1615
- ].filter(function (cls) { return !!cls; }).join(" ");
1616
- };
1617
- DynamicBaseFormGroupComponent.prototype.getModelClass = function (model) {
1618
- var parts = collectPathAble(model, function (p) { return p.id; });
1619
- if (parts.length == 0)
1620
- return "";
1621
- if (model instanceof core.DynamicFormGroupModel) {
1622
- return "form-group-" + parts.join("-");
2081
+ // Acceptor for provider
2082
+ DynamicFormSelectComponent.acceptor = function (control) {
2083
+ return control.type == "select";
2084
+ };
2085
+ // Loader for provider
2086
+ DynamicFormSelectComponent.loader = function (control) {
2087
+ var data = control.getData();
2088
+ if (data.type == "radio" && data.multi) {
2089
+ return Promise.reject("Radio group doesn't support multi select!");
1623
2090
  }
1624
- return "form-control-" + parts.join("-");
2091
+ return new Promise(function (resolve) {
2092
+ var getOptions = ngxUtils.ReflectUtils.resolve(data.options, control.form.injector);
2093
+ getOptions(control).then(function (options) {
2094
+ if (data.emptyOption)
2095
+ options.unshift({ id: null, label: "" });
2096
+ control.meta.options = options;
2097
+ DynamicFormSelectComponent.fillOptions(control, options);
2098
+ resolve(options);
2099
+ });
2100
+ });
1625
2101
  };
1626
- DynamicBaseFormGroupComponent.prototype.getAdditionalClass = function (model) {
1627
- var _a, _b;
1628
- if (model instanceof DynamicFormArrayModel) {
1629
- return (_a = model.additional) === null || _a === void 0 ? void 0 : _a.classes;
2102
+ DynamicFormSelectComponent.fillOptions = function (control, options) {
2103
+ var data = control.getData();
2104
+ var selected = control.value;
2105
+ if (data.multi || options.length == 0 || options.findIndex(function (t) { return t.id == selected; }) >= 0)
2106
+ return;
2107
+ control.setValue(options[0].id);
2108
+ };
2109
+ DynamicFormSelectComponent.prototype.onSelectChange = function (value) {
2110
+ var isArray = ngxUtils.ObjectUtils.isArray(value);
2111
+ var current = this.value;
2112
+ if (this.data.multi) {
2113
+ if (isArray) {
2114
+ this.control.setValue(value);
2115
+ return;
2116
+ }
2117
+ if (ngxUtils.ObjectUtils.isArray(current)) {
2118
+ this.control.setValue(current.indexOf(value) < 0
2119
+ ? current.concat([value])
2120
+ : current.filter(function (c) { return c !== value; }));
2121
+ return;
2122
+ }
2123
+ this.control.setValue([value]);
2124
+ return;
1630
2125
  }
1631
- if (model instanceof core.DynamicFormValueControlModel) {
1632
- return (_b = model.additional) === null || _b === void 0 ? void 0 : _b.classes;
2126
+ if (isArray)
2127
+ value = value[0];
2128
+ if (current == value) {
2129
+ var option = this.meta.options.find(function (o) { return o.id !== value; });
2130
+ value = option ? option.id : null;
1633
2131
  }
1634
- return null;
2132
+ this.control.setValue(value);
2133
+ };
2134
+ DynamicFormSelectComponent.prototype.checkValue = function (option) {
2135
+ var value = this.value;
2136
+ return ngxUtils.ObjectUtils.isArray(value) ? value.indexOf(option.id) >= 0 : option.id == value;
2137
+ };
2138
+ DynamicFormSelectComponent.prototype.findOption = function (option, index, id) {
2139
+ return option.id == id;
2140
+ };
2141
+ return DynamicFormSelectComponent;
2142
+ }(FormControlComponent));
2143
+ DynamicFormSelectComponent.decorators = [
2144
+ { type: core.Component, args: [{
2145
+ moduleId: module.id,
2146
+ selector: "dynamic-form-select",
2147
+ template: "<ng-template #selectTemplate let-selected=\"selected\">\r\n <select class=\"form-control\"\r\n [attr.data-testid]=\"testId\"\r\n [multiple]=\"data.multi\"\r\n [id]=\"control.formId\"\r\n [name]=\"control.formId\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled\"\r\n [ngModel]=\"data.multi ? value : [value]\"\r\n (ngModelChange)=\"onSelectChange($event)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n <option *ngFor=\"let option of meta.options\" [value]=\"option.id\" [disabled]=\"option.selectable == false\">\r\n {{ option.label | translate }}\r\n </option>\r\n </select>\r\n <label class=\"form-control-description\" [attr.for]=\"control.formId\" *ngIf=\"!data.multi && selected?.description\">\r\n {{ selected?.description | translate }}\r\n </label>\r\n</ng-template>\r\n<ng-container [ngSwitch]=\"data.type\">\r\n <ng-container *ngSwitchCase=\"'radio'\">\r\n <ul class=\"radio-group\">\r\n <li *ngFor=\"let option of meta.options\" class=\"radio\">\r\n <label [ngClass]=\"{checked: value == option.id}\">\r\n <input type=\"radio\"\r\n [attr.data-testid]=\"testId + '-' + option.id\"\r\n [id]=\"control.formId + '-' + option.id\"\r\n [name]=\"control.formId + '-' + option.id\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled || option.selectable == false\"\r\n [value]=\"option.id\"\r\n [ngModel]=\"value\"\r\n (ngModelChange)=\"onSelectChange(option.id)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n {{ option.label | translate }}\r\n </label>\r\n </li>\r\n </ul>\r\n </ng-container>\r\n <ng-container *ngSwitchCase=\"'checkbox'\">\r\n <ul class=\"checkbox-group\">\r\n <li *ngFor=\"let option of meta.options\" class=\"checkbox\">\r\n <label [ngClass]=\"{checked: checkValue(option)}\">\r\n <input type=\"checkbox\"\r\n [attr.data-testid]=\"testId + '-' + option.id\"\r\n [id]=\"control.formId + '-' + option.id\"\r\n [name]=\"control.formId + '-' + option.id\"\r\n [ngClass]=\"{disabled: control.disabled}\"\r\n [disabled]=\"control.disabled || option.selectable == false\"\r\n [ngModel]=\"checkValue(option)\"\r\n (ngModelChange)=\"onSelectChange(option.id)\"\r\n (blur)=\"control.onBlur()\"\r\n (focus)=\"control.onFocus()\">\r\n {{ option.label | translate }}\r\n </label>\r\n </li>\r\n </ul>\r\n </ng-container>\r\n <ng-container *ngSwitchDefault [ngTemplateOutlet]=\"selectTemplate\" [ngTemplateOutletContext]=\"{selected: meta?.options | find:findOption:value}\">\r\n\r\n </ng-container>\r\n</ng-container>\r\n"
2148
+ },] }
2149
+ ];
2150
+
2151
+ var DynamicFormStaticComponent = /** @class */ (function (_super) {
2152
+ __extends(DynamicFormStaticComponent, _super);
2153
+ function DynamicFormStaticComponent() {
2154
+ return _super !== null && _super.apply(this, arguments) || this;
2155
+ }
2156
+ // Acceptor for provider
2157
+ DynamicFormStaticComponent.acceptor = function (control) {
2158
+ return control.type == "static";
2159
+ };
2160
+ // Loader for provider
2161
+ DynamicFormStaticComponent.loader = function () {
2162
+ return Promise.resolve();
2163
+ };
2164
+ return DynamicFormStaticComponent;
2165
+ }(FormControlComponent));
2166
+ DynamicFormStaticComponent.decorators = [
2167
+ { type: core.Component, args: [{
2168
+ moduleId: module.id,
2169
+ selector: "dynamic-form-static",
2170
+ template: "<unordered-list [listStyle]=\"data.style\" [ngClass]=\"{disabled: control.disabled}\"\r\n [data]=\"!data.properties ? {value: value} : data.properties | remap: value\">\r\n <ng-template [type]=\"!data.properties ? 'key' : null\" selector=\"level == 0\" let-item=\"item\"></ng-template>\r\n <ng-template type=\"value\" selector=\"valueType == 'date'\" let-item=\"item\">\r\n {{ item.value | date }}\r\n </ng-template>\r\n</unordered-list>\r\n"
2171
+ },] }
2172
+ ];
2173
+
2174
+ var DynamicFormModelComponent = /** @class */ (function (_super) {
2175
+ __extends(DynamicFormModelComponent, _super);
2176
+ function DynamicFormModelComponent() {
2177
+ return _super !== null && _super.apply(this, arguments) || this;
2178
+ }
2179
+ // Acceptor for provider
2180
+ DynamicFormModelComponent.acceptor = function (control) {
2181
+ return control.type == "model";
2182
+ };
2183
+ // Loader for provider
2184
+ DynamicFormModelComponent.loader = function () {
2185
+ return Promise.resolve();
2186
+ };
2187
+ return DynamicFormModelComponent;
2188
+ }(FormControlComponent));
2189
+ DynamicFormModelComponent.decorators = [
2190
+ { type: core.Component, args: [{
2191
+ moduleId: module.id,
2192
+ selector: "dynamic-form-model",
2193
+ template: "<dynamic-form [testId]=\"form.testId + '-' + control.id\"\r\n [name]=\"data.name || form.name\"\r\n [group]=\"control\"\r\n [data]=\"value\"\r\n [updateOn]=\"control.updateOn\"\r\n [parent]=\"form\"\r\n\r\n [fieldSetTemplate]=\"form.fieldSetTemplate\"\r\n [controlTemplates]=\"form.controlTemplates\"\r\n\r\n [controlTemplate]=\"form.controlTemplate\"\r\n [labelTemplates]=\"form.labelTemplates\"\r\n [inputTemplates]=\"form.inputTemplates\"\r\n [prefixTemplates]=\"form.prefixTemplates\"\r\n [suffixTemplates]=\"form.suffixTemplates\"\r\n [setPrefixTemplates]=\"form.setPrefixTemplates\"\r\n [setSuffixTemplates]=\"form.setSuffixTemplates\"\r\n\r\n #subForm>\r\n <ng-template #wrapperTemplate let-form=\"form\" let-fieldSetsTemplate=\"fieldSetsTemplate\">\r\n <ng-container [ngTemplateOutlet]=\"fieldSetsTemplate\"></ng-container>\r\n </ng-template>\r\n</dynamic-form>\r\n"
2194
+ },] }
2195
+ ];
2196
+ DynamicFormModelComponent.propDecorators = {
2197
+ subForm: [{ type: core.ViewChild, args: ["subForm",] }]
2198
+ };
2199
+
2200
+ var DynamicFormGroupDirective = /** @class */ (function () {
2201
+ function DynamicFormGroupDirective(vcr, forms) {
2202
+ this.vcr = vcr;
2203
+ this.forms = forms;
2204
+ }
2205
+ Object.defineProperty(DynamicFormGroupDirective.prototype, "component", {
2206
+ get: function () {
2207
+ return this.comp;
2208
+ },
2209
+ enumerable: false,
2210
+ configurable: true
2211
+ });
2212
+ DynamicFormGroupDirective.prototype.ngOnChanges = function (changes) {
2213
+ if (changes.control || changes.form || changes.visible) {
2214
+ if (!this.visible) {
2215
+ this.vcr.clear();
2216
+ this.comp = null;
2217
+ return;
2218
+ }
2219
+ this.comp = this.forms.createGroup(this.vcr);
2220
+ }
2221
+ if (!this.comp)
2222
+ return;
2223
+ this.comp.form = this.form;
2224
+ this.comp.control = this.control;
1635
2225
  };
1636
- return DynamicBaseFormGroupComponent;
1637
- }(core.DynamicFormGroupComponent));
1638
- DynamicBaseFormGroupComponent.decorators = [
1639
- { type: core$1.Component, args: [{
1640
- selector: "dynamic-base-form-group",
1641
- template: "",
1642
- changeDetection: core$1.ChangeDetectionStrategy.OnPush
2226
+ return DynamicFormGroupDirective;
2227
+ }());
2228
+ DynamicFormGroupDirective.decorators = [
2229
+ { type: core.Directive, args: [{
2230
+ selector: "[form-group]",
1643
2231
  },] }
1644
2232
  ];
1645
- DynamicBaseFormGroupComponent.ctorParameters = function () { return [
1646
- { type: core.DynamicFormLayoutService },
1647
- { type: core.DynamicFormValidationService }
2233
+ DynamicFormGroupDirective.ctorParameters = function () { return [
2234
+ { type: core.ViewContainerRef },
2235
+ { type: DynamicFormService }
1648
2236
  ]; };
1649
- DynamicBaseFormGroupComponent.propDecorators = {
1650
- formLayout: [{ type: core$1.Input }],
1651
- group: [{ type: core$1.Input }],
1652
- layout: [{ type: core$1.Input }],
1653
- model: [{ type: core$1.Input }],
1654
- templates: [{ type: core$1.Input }],
1655
- blur: [{ type: core$1.Output }],
1656
- change: [{ type: core$1.Output }],
1657
- customEvent: [{ type: core$1.Output }],
1658
- focus: [{ type: core$1.Output }],
1659
- components: [{ type: core$1.ViewChildren, args: [core$1.forwardRef(function () { return core.DynamicFormControlContainerComponent; }),] }]
2237
+ DynamicFormGroupDirective.propDecorators = {
2238
+ control: [{ type: core.Input, args: ["form-group",] }],
2239
+ form: [{ type: core.Input }],
2240
+ visible: [{ type: core.Input }]
1660
2241
  };
1661
2242
 
1662
2243
  // --- Components ---
1663
2244
  var components = [
1664
- DynamicBaseFormComponent,
1665
- DynamicBaseFormArrayComponent,
1666
- DynamicBaseFormControlContainerComponent,
1667
- DynamicBaseFormGroupComponent
2245
+ DynamicFormsComponent,
2246
+ DynamicFormComponent,
2247
+ DynamicFormGroupComponent,
2248
+ DynamicFormFileComponent,
2249
+ DynamicFormInputComponent,
2250
+ DynamicFormSelectComponent,
2251
+ DynamicFormStaticComponent,
2252
+ DynamicFormModelComponent
1668
2253
  ];
1669
2254
  // --- Directives ---
1670
2255
  var directives = [
1671
2256
  AsyncSubmitDirective,
2257
+ DynamicFormControlDirective,
2258
+ DynamicFormGroupDirective,
2259
+ DynamicFormTemplateDirective
1672
2260
  ];
1673
2261
  // --- Pipes ---
1674
2262
  var pipes = [];
1675
- var ɵ0 = validateJSON, ɵ1 = validateRequiredTranslation, ɵ2 = validateItemsMinLength, ɵ3 = validateItemsMaxLength, ɵ4 = validateItemsMinValue, ɵ5 = validateItemsMaxValue, ɵ6 = new Map([
1676
- ["json", validateJSON],
1677
- ["requiredTranslation", validateRequiredTranslation],
1678
- ["phone", validatePhone],
1679
- ["itemsMinLength", validateItemsMinLength],
1680
- ["itemsMaxLength", validateItemsMaxLength],
1681
- ["itemsMinValue", validateItemsMinValue],
1682
- ["itemsMaxValue", validateItemsMaxValue],
1683
- ]);
1684
2263
  var NgxDynamicFormModule = /** @class */ (function () {
1685
2264
  function NgxDynamicFormModule() {
1686
2265
  }
1687
- NgxDynamicFormModule.forRoot = function () {
2266
+ NgxDynamicFormModule.forRoot = function (controlProviders, groupProvider) {
1688
2267
  return {
1689
2268
  ngModule: NgxDynamicFormModule,
1690
- providers: [
2269
+ providers: __spreadArray(__spreadArray([
1691
2270
  DynamicFormService,
1692
- {
1693
- provide: core.DynamicFormService,
1694
- useExisting: DynamicFormService
1695
- }
1696
- ]
2271
+ OpenApiService,
2272
+ provideFormControl(DynamicFormFileComponent, DynamicFormFileComponent.acceptor, DynamicFormFileComponent.loader),
2273
+ provideFormControl(DynamicFormInputComponent, DynamicFormInputComponent.acceptor, DynamicFormInputComponent.loader),
2274
+ provideFormControl(DynamicFormSelectComponent, DynamicFormSelectComponent.acceptor, DynamicFormSelectComponent.loader),
2275
+ provideFormControl(DynamicFormStaticComponent, DynamicFormStaticComponent.acceptor, DynamicFormStaticComponent.loader),
2276
+ provideFormControl(DynamicFormModelComponent, DynamicFormModelComponent.acceptor, DynamicFormModelComponent.loader)
2277
+ ], __read((controlProviders || []))), [
2278
+ groupProvider || provideFormGroup(DynamicFormGroupComponent)
2279
+ ])
1697
2280
  };
1698
2281
  };
1699
2282
  return NgxDynamicFormModule;
1700
2283
  }());
1701
2284
  NgxDynamicFormModule.decorators = [
1702
- { type: core$1.NgModule, args: [{
1703
- declarations: __spread(components, directives, pipes),
2285
+ { type: core.NgModule, args: [{
2286
+ declarations: __spreadArray(__spreadArray(__spreadArray([], __read(components)), __read(directives)), __read(pipes)),
1704
2287
  imports: [
1705
2288
  common.CommonModule,
1706
2289
  forms.FormsModule,
1707
2290
  forms.ReactiveFormsModule,
1708
2291
  ngxUtils.NgxUtilsModule
1709
2292
  ],
1710
- exports: __spread(components, directives, pipes, [
2293
+ exports: __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(components)), __read(directives)), __read(pipes)), [
1711
2294
  forms.FormsModule,
1712
2295
  forms.ReactiveFormsModule,
1713
2296
  ngxUtils.NgxUtilsModule
1714
2297
  ]),
1715
2298
  entryComponents: components,
1716
- providers: __spread(pipes, [
1717
- { provide: forms.NG_VALIDATORS, useValue: ɵ0, multi: true },
1718
- { provide: forms.NG_VALIDATORS, useValue: ɵ1, multi: true },
1719
- { provide: forms.NG_VALIDATORS, useValue: ɵ2, multi: true },
1720
- { provide: forms.NG_VALIDATORS, useValue: ɵ3, multi: true },
1721
- { provide: forms.NG_VALIDATORS, useValue: ɵ4, multi: true },
1722
- { provide: forms.NG_VALIDATORS, useValue: ɵ5, multi: true },
1723
- {
1724
- provide: core.DYNAMIC_VALIDATORS,
1725
- useValue: ɵ6
1726
- }
1727
- ])
2299
+ providers: pipes
1728
2300
  },] }
1729
2301
  ];
1730
2302
 
@@ -1733,21 +2305,32 @@
1733
2305
  */
1734
2306
 
1735
2307
  exports.AsyncSubmitDirective = AsyncSubmitDirective;
1736
- exports.DynamicBaseFormArrayComponent = DynamicBaseFormArrayComponent;
1737
- exports.DynamicBaseFormComponent = DynamicBaseFormComponent;
1738
- exports.DynamicBaseFormControlContainerComponent = DynamicBaseFormControlContainerComponent;
1739
- exports.DynamicBaseFormGroupComponent = DynamicBaseFormGroupComponent;
1740
- exports.DynamicFormArrayModel = DynamicFormArrayModel;
2308
+ exports.DynamicFormBaseComponent = DynamicFormBaseComponent;
2309
+ exports.DynamicFormComponent = DynamicFormComponent;
2310
+ exports.DynamicFormControl = DynamicFormControl;
2311
+ exports.DynamicFormControlDirective = DynamicFormControlDirective;
2312
+ exports.DynamicFormFileComponent = DynamicFormFileComponent;
2313
+ exports.DynamicFormGroup = DynamicFormGroup;
2314
+ exports.DynamicFormGroupComponent = DynamicFormGroupComponent;
2315
+ exports.DynamicFormInputComponent = DynamicFormInputComponent;
2316
+ exports.DynamicFormModelComponent = DynamicFormModelComponent;
2317
+ exports.DynamicFormSelectComponent = DynamicFormSelectComponent;
1741
2318
  exports.DynamicFormService = DynamicFormService;
2319
+ exports.DynamicFormStaticComponent = DynamicFormStaticComponent;
2320
+ exports.DynamicFormTemplateDirective = DynamicFormTemplateDirective;
2321
+ exports.DynamicFormsComponent = DynamicFormsComponent;
2322
+ exports.FORM_CONTROL_PROVIDER = FORM_CONTROL_PROVIDER;
2323
+ exports.FormControlComponent = FormControlComponent;
2324
+ exports.FormFieldSet = FormFieldSet;
1742
2325
  exports.FormFile = FormFile;
1743
2326
  exports.FormInput = FormInput;
1744
2327
  exports.FormModel = FormModel;
1745
2328
  exports.FormSelect = FormSelect;
1746
- exports.FormSelectSubject = FormSelectSubject;
1747
2329
  exports.FormSerializable = FormSerializable;
1748
2330
  exports.FormStatic = FormStatic;
1749
- exports.FormSubject = FormSubject;
2331
+ exports.FormUtilities = FormUtilities;
1750
2332
  exports.NgxDynamicFormModule = NgxDynamicFormModule;
2333
+ exports.OpenApiService = OpenApiService;
1751
2334
  exports.createFormControl = createFormControl;
1752
2335
  exports.createFormInput = createFormInput;
1753
2336
  exports.createFormModel = createFormModel;
@@ -1756,19 +2339,17 @@
1756
2339
  exports.defaultSerializer = defaultSerializer;
1757
2340
  exports.defineFormControl = defineFormControl;
1758
2341
  exports.getFormControl = getFormControl;
2342
+ exports.getFormFieldSets = getFormFieldSets;
1759
2343
  exports.getFormSerializer = getFormSerializer;
1760
- exports.validateItemsMaxLength = validateItemsMaxLength;
1761
- exports.validateItemsMaxValue = validateItemsMaxValue;
1762
- exports.validateItemsMinLength = validateItemsMinLength;
1763
- exports.validateItemsMinValue = validateItemsMinValue;
1764
- exports.validateJSON = validateJSON;
1765
- exports.validatePhone = validatePhone;
1766
- exports.validateRequiredTranslation = validateRequiredTranslation;
1767
- exports.ɵa = components;
1768
- exports.ɵb = directives;
1769
- exports.ɵc = pipes;
2344
+ exports.provideFormControl = provideFormControl;
2345
+ exports.provideFormGroup = provideFormGroup;
2346
+ exports["ɵa"] = FORM_GROUP_TYPE;
2347
+ exports["ɵb"] = components;
2348
+ exports["ɵc"] = directives;
2349
+ exports["ɵd"] = pipes;
2350
+ exports["ɵe"] = DynamicFormGroupDirective;
1770
2351
 
1771
2352
  Object.defineProperty(exports, '__esModule', { value: true });
1772
2353
 
1773
- })));
2354
+ }));
1774
2355
  //# sourceMappingURL=stemy-ngx-dynamic-form.umd.js.map