@stemy/ngx-dynamic-form 13.1.21 → 13.2.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.
@@ -1,9 +1,9 @@
1
- import * as i2 from '@stemy/ngx-utils';
2
- import { ReflectUtils, ObjectUtils, TimerUtils, StringUtils, OpenApiService, TOASTER_SERVICE, ObservableUtils, EventsService, NgxUtilsModule } from '@stemy/ngx-utils';
3
- import { __decorate, __awaiter } from 'tslib';
4
1
  import * as i1 from '@ng-dynamic-forms/core';
5
- import { DynamicInputControlModel, DYNAMIC_FORM_CONTROL_TYPE_EDITOR, serializable, DynamicFormArrayGroupModel as DynamicFormArrayGroupModel$1, DynamicFormArrayModel as DynamicFormArrayModel$1, DynamicFormOption as DynamicFormOption$1, DynamicSelectModel as DynamicSelectModel$1, DynamicFormService as DynamicFormService$1, DynamicDatePickerModel, DynamicFormGroupModel, DynamicInputModel, DynamicFormValueControlModel, DynamicFileUploadModel, DynamicCheckboxModel, DynamicTextAreaModel, DynamicFormComponent, DynamicTemplateDirective, DynamicFormControlContainerComponent, DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DynamicFormArrayComponent, DynamicFormControlComponent, DynamicFormGroupComponent, DYNAMIC_FORM_CONTROL_MAP_FN, DYNAMIC_VALIDATORS } from '@ng-dynamic-forms/core';
2
+ import { DynamicInputControlModel, DYNAMIC_FORM_CONTROL_TYPE_EDITOR, serializable, DynamicFormArrayGroupModel as DynamicFormArrayGroupModel$1, DynamicFormArrayModel as DynamicFormArrayModel$1, DynamicFormOption as DynamicFormOption$1, DynamicSelectModel as DynamicSelectModel$1, DynamicCheckboxModel, DynamicDatePickerModel, DynamicFormGroupModel, DynamicInputModel, DynamicTextAreaModel, DynamicFileUploadModel, DynamicFormService as DynamicFormService$1, DynamicFormValueControlModel, DynamicFormComponent, DynamicTemplateDirective, DynamicFormControlContainerComponent, DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DynamicFormArrayComponent, DynamicFormControlComponent, DynamicFormGroupComponent, DYNAMIC_FORM_CONTROL_MAP_FN, DYNAMIC_VALIDATORS } from '@ng-dynamic-forms/core';
6
3
  export { DYNAMIC_FORM_CONTROL_TYPE_ARRAY, DYNAMIC_FORM_CONTROL_TYPE_CHECKBOX, DYNAMIC_FORM_CONTROL_TYPE_CHECKBOX_GROUP, DYNAMIC_FORM_CONTROL_TYPE_DATEPICKER, DYNAMIC_FORM_CONTROL_TYPE_EDITOR, DYNAMIC_FORM_CONTROL_TYPE_FILE_UPLOAD, DYNAMIC_FORM_CONTROL_TYPE_GROUP, DYNAMIC_FORM_CONTROL_TYPE_INPUT, DYNAMIC_FORM_CONTROL_TYPE_RADIO_GROUP, DYNAMIC_FORM_CONTROL_TYPE_SELECT, DYNAMIC_FORM_CONTROL_TYPE_TEXTAREA, DynamicCheckboxGroupModel, DynamicCheckboxModel, DynamicDatePickerModel, DynamicFileUploadModel, DynamicFormControlComponent, DynamicFormGroupModel, DynamicFormsCoreModule, DynamicInputModel, DynamicListDirective, DynamicRadioGroupModel, DynamicTemplateDirective, DynamicTextAreaModel } from '@ng-dynamic-forms/core';
4
+ import * as i2 from '@stemy/ngx-utils';
5
+ import { ObjectUtils, TimerUtils, StringUtils, OpenApiService, TOASTER_SERVICE, ObservableUtils, EventsService, NgxUtilsModule } from '@stemy/ngx-utils';
6
+ import { __decorate, __awaiter } from 'tslib';
7
7
  import { BehaviorSubject, of, isObservable, Subject, firstValueFrom, Subscription } from 'rxjs';
8
8
  import { map, debounceTime, groupBy, mergeMap, first } from 'rxjs/operators';
9
9
  import * as i0 from '@angular/core';
@@ -11,203 +11,6 @@ import { Injector, Injectable, Inject, EventEmitter, Directive, Input, Output, H
11
11
  import { FormGroup, FormArray, FormsModule, ReactiveFormsModule, NG_VALIDATORS } from '@angular/forms';
12
12
  import { CommonModule } from '@angular/common';
13
13
 
14
- // --- Decorator functions ---
15
- function defaultSerializer(id, parent) {
16
- const control = parent.get(id);
17
- return !control ? null : control.value;
18
- }
19
- function FormSerializable(serializer) {
20
- return (target, propertyKey) => {
21
- ReflectUtils.defineMetadata("dynamicFormSerializer", serializer || defaultSerializer, target, propertyKey);
22
- };
23
- }
24
- function FormInput(data) {
25
- return (target, propertyKey) => {
26
- const meta = ReflectUtils.getOwnMetadata("design:type", target, propertyKey);
27
- const type = meta ? meta.name : "";
28
- let inputType = propertyKey.indexOf("password") < 0 ? "text" : "password";
29
- switch (type) {
30
- case "Number":
31
- inputType = "number";
32
- break;
33
- case "Boolean":
34
- inputType = "checkbox";
35
- break;
36
- }
37
- defineFormControl(target, propertyKey, createFormInput(propertyKey, data, inputType));
38
- };
39
- }
40
- function FormSelect(data) {
41
- return (target, propertyKey) => {
42
- defineFormControl(target, propertyKey, createFormSelect(propertyKey, data));
43
- };
44
- }
45
- function FormStatic(data) {
46
- return (target, propertyKey) => {
47
- defineFormControl(target, propertyKey, createFormStatic(propertyKey, data));
48
- };
49
- }
50
- function FormModel(data) {
51
- return (target, propertyKey) => {
52
- defineFormControl(target, propertyKey, createFormModel(propertyKey, data));
53
- };
54
- }
55
- function FormFile(data) {
56
- return (target, propertyKey) => {
57
- defineFormControl(target, propertyKey, createFormFile(propertyKey, data));
58
- };
59
- }
60
- function defineFormControl(target, propertyKey, control) {
61
- ReflectUtils.defineMetadata("dynamicFormControl", control, target, propertyKey);
62
- }
63
- function getFormControl(target, propertyKey) {
64
- return ReflectUtils.getMetadata("dynamicFormControl", target, propertyKey);
65
- }
66
- function getFormSerializer(target, propertyKey) {
67
- return ReflectUtils.getMetadata("dynamicFormSerializer", target, propertyKey);
68
- }
69
- function createFormControl(id, type, config) {
70
- config = config || { id };
71
- config.id = id;
72
- config.label = ObjectUtils.isNullOrUndefined(config.label) ? id : config.label;
73
- config.disabled = config.disabled || false;
74
- config.hidden = config.hidden || false;
75
- return { id, type, config };
76
- }
77
- function createFormInput(id, config, type = "text") {
78
- const control = createFormControl(id, "input", config);
79
- config = control.config;
80
- config.inputType = config.inputType || type;
81
- config.placeholder = config.placeholder || (config.inputType == "mask" ? "_" : "");
82
- config.step = config.step || 1;
83
- config.mask = config.mask || null;
84
- return control;
85
- }
86
- function createFormSelect(id, data) {
87
- const control = createFormControl(id, "select", data);
88
- data = control.config;
89
- data.options = data.options || [];
90
- return control;
91
- }
92
- function createFormStatic(id, config) {
93
- return createFormControl(id, "static", config);
94
- }
95
- function createFormModel(id, data) {
96
- const control = createFormControl(id, "group", data);
97
- data = control.config;
98
- data.name = data.name || "";
99
- return control;
100
- }
101
- function createFormFile(id, data) {
102
- const control = createFormControl(id, "file", data);
103
- data = control.config;
104
- data.accept = data.accept || ["jpg", "jpeg", "png"];
105
- data.multiple = data.multiple || false;
106
- data.url = ObjectUtils.isString(data.url) ? data.url : "assets";
107
- return control;
108
- }
109
-
110
- function isStringWithVal(val) {
111
- return typeof val == "string" && val.length > 0;
112
- }
113
- function findRefs(property) {
114
- var _a;
115
- const refs = Array.isArray(property.allOf)
116
- ? property.allOf.map(o => o.$ref).filter(isStringWithVal)
117
- : [(_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref, property.$ref].filter(isStringWithVal);
118
- return refs.map(t => t.split("/").pop());
119
- }
120
- function replaceSpecialChars(str, to = "-") {
121
- return `${str}`.replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g, to);
122
- }
123
- function mergeFormModels(formModels) {
124
- const res = [];
125
- for (const formModel of formModels) {
126
- for (const subModel of formModel) {
127
- const index = res.findIndex(t => t.id == subModel.id);
128
- if (index >= 0) {
129
- res[index] = subModel;
130
- continue;
131
- }
132
- res.push(subModel);
133
- }
134
- }
135
- return res;
136
- }
137
- function collectPathAble(start, getter) {
138
- if (!start || !getter(start))
139
- return [];
140
- const parts = [];
141
- let currentPath = start;
142
- while (currentPath) {
143
- const val = getter(currentPath);
144
- if (val) {
145
- parts.unshift(val);
146
- }
147
- currentPath = currentPath.parent;
148
- }
149
- return parts;
150
- }
151
- const MIN_INPUT_NUM = -999999999;
152
- const MAX_INPUT_NUM = 999999999;
153
- const EDITOR_FORMATS = ["php", "json", "html", "css", "scss"];
154
-
155
- function validateJSON(control) {
156
- const value = control.value;
157
- if (!value)
158
- return null;
159
- try {
160
- JSON.parse(value);
161
- return null;
162
- }
163
- catch (e) {
164
- return { json: true };
165
- }
166
- }
167
- function validateRequiredTranslation(control) {
168
- const value = control.value;
169
- if (!value || value.length == 0)
170
- return { requiredTranslation: true };
171
- return value.findIndex(t => (t.lang == "de" || t.lang == "en") && !t.translation) < 0
172
- ? null
173
- : { requiredTranslation: true };
174
- }
175
- function validatePhone(control) {
176
- const value = control.value;
177
- if (!value)
178
- return Promise.resolve(null);
179
- const phoneRegexp = /^(?:\d){10,12}$/;
180
- return phoneRegexp.test(value) ? null : { phone: true };
181
- }
182
- function validateItemsMinLength(minLength) {
183
- return (control) => {
184
- const value = control.value;
185
- return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length >= minLength))
186
- ? null : { itemsMinLength: minLength };
187
- };
188
- }
189
- function validateItemsMaxLength(maxLength) {
190
- return (control) => {
191
- const value = control.value;
192
- return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length <= maxLength))
193
- ? null : { itemsMaxLength: maxLength };
194
- };
195
- }
196
- function validateItemsMinValue(min) {
197
- return (control) => {
198
- const value = control.value;
199
- return (Array.isArray(value) && value.every(v => typeof v == "number" && v >= min))
200
- ? null : { itemsMinValue: min };
201
- };
202
- }
203
- function validateItemsMaxValue(max) {
204
- return (control) => {
205
- const value = control.value;
206
- return (Array.isArray(value) && value.every(v => typeof v == "number" && v <= max))
207
- ? null : { itemsMaxValue: max };
208
- };
209
- }
210
-
211
14
  class DynamicEditorModel extends DynamicInputControlModel {
212
15
  constructor(config, layout) {
213
16
  super(config, layout);
@@ -401,6 +204,168 @@ class DynamicSelectModel extends DynamicSelectModel$1 {
401
204
  }
402
205
  }
403
206
 
207
+ function createFormConfig(id, config) {
208
+ const res = (config || { id });
209
+ res.id = id;
210
+ res.label = ObjectUtils.isNullOrUndefined(config.label) ? id : config.label;
211
+ res.disabled = config.disabled || false;
212
+ res.hidden = config.hidden || false;
213
+ return res;
214
+ }
215
+ function createFormCheckbox(id, config, layout) {
216
+ const res = createFormConfig(id, config);
217
+ res.indeterminate = config.indeterminate || false;
218
+ return new DynamicCheckboxModel(res, layout);
219
+ }
220
+ function createFormDate(id, config, layout) {
221
+ const res = createFormConfig(id, config);
222
+ res.autoFocus = config.autoFocus || false;
223
+ res.focusedDate = config.focusedDate || new Date();
224
+ res.inline = config.inline || false;
225
+ return new DynamicDatePickerModel(res, layout);
226
+ }
227
+ function createFormEditor(id, config, layout) {
228
+ const res = createFormConfig(id, config);
229
+ return new DynamicEditorModel(res, layout);
230
+ }
231
+ function createFormArray(id, config, layout) {
232
+ const res = createFormConfig(id, config);
233
+ return new DynamicFormArrayModel(res, layout);
234
+ }
235
+ function createFormGroup(id, config, layout) {
236
+ const res = createFormConfig(id, config);
237
+ res.name = config.name || "";
238
+ return new DynamicFormGroupModel(res, layout);
239
+ }
240
+ function createFormInput(id, config, type = "text", layout) {
241
+ const res = createFormConfig(id, config);
242
+ res.inputType = config.inputType || type;
243
+ res.placeholder = config.placeholder || (config.inputType == "mask" ? "_" : "");
244
+ res.step = config.step || 1;
245
+ res.mask = config.mask || null;
246
+ return new DynamicInputModel(res, layout);
247
+ }
248
+ function createFormSelect(id, config, layout) {
249
+ const res = createFormConfig(id, config);
250
+ res.options = config.options || [];
251
+ return new DynamicSelectModel(res, layout);
252
+ }
253
+ function createFormTextarea(id, config, layout) {
254
+ const res = createFormConfig(id, config);
255
+ res.cols = config.cols || 10;
256
+ res.rows = config.rows || 3;
257
+ res.wrap = config.wrap || "soft";
258
+ return new DynamicTextAreaModel(res, layout);
259
+ }
260
+ function createFormFile(id, config, layout) {
261
+ const res = createFormConfig(id, config);
262
+ res.accept = config.accept || ["jpg", "jpeg", "png"];
263
+ res.multiple = config.multiple || false;
264
+ res.url = ObjectUtils.isString(config.url) ? config.url : "assets";
265
+ return new DynamicFileUploadModel(res, layout);
266
+ }
267
+
268
+ function isStringWithVal(val) {
269
+ return typeof val == "string" && val.length > 0;
270
+ }
271
+ function findRefs(property) {
272
+ var _a;
273
+ const refs = Array.isArray(property.allOf)
274
+ ? property.allOf.map(o => o.$ref).filter(isStringWithVal)
275
+ : [(_a = property.items) === null || _a === void 0 ? void 0 : _a.$ref, property.$ref].filter(isStringWithVal);
276
+ return refs.map(t => t.split("/").pop());
277
+ }
278
+ function replaceSpecialChars(str, to = "-") {
279
+ return `${str}`.replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g, to);
280
+ }
281
+ function mergeFormModels(formModels) {
282
+ const res = [];
283
+ for (const formModel of formModels) {
284
+ for (const subModel of formModel) {
285
+ const index = res.findIndex(t => t.id == subModel.id);
286
+ if (index >= 0) {
287
+ res[index] = subModel;
288
+ continue;
289
+ }
290
+ res.push(subModel);
291
+ }
292
+ }
293
+ return res;
294
+ }
295
+ function collectPathAble(start, getter) {
296
+ if (!start || !getter(start))
297
+ return [];
298
+ const parts = [];
299
+ let currentPath = start;
300
+ while (currentPath) {
301
+ const val = getter(currentPath);
302
+ if (val) {
303
+ parts.unshift(val);
304
+ }
305
+ currentPath = currentPath.parent;
306
+ }
307
+ return parts;
308
+ }
309
+ const MIN_INPUT_NUM = -999999999;
310
+ const MAX_INPUT_NUM = 999999999;
311
+ const EDITOR_FORMATS = ["php", "json", "html", "css", "scss"];
312
+
313
+ function validateJSON(control) {
314
+ const value = control.value;
315
+ if (!value)
316
+ return null;
317
+ try {
318
+ JSON.parse(value);
319
+ return null;
320
+ }
321
+ catch (e) {
322
+ return { json: true };
323
+ }
324
+ }
325
+ function validateRequiredTranslation(control) {
326
+ const value = control.value;
327
+ if (!value || value.length == 0)
328
+ return { requiredTranslation: true };
329
+ return value.findIndex(t => (t.lang == "de" || t.lang == "en") && !t.translation) < 0
330
+ ? null
331
+ : { requiredTranslation: true };
332
+ }
333
+ function validatePhone(control) {
334
+ const value = control.value;
335
+ if (!value)
336
+ return Promise.resolve(null);
337
+ const phoneRegexp = /^(?:\d){10,12}$/;
338
+ return phoneRegexp.test(value) ? null : { phone: true };
339
+ }
340
+ function validateItemsMinLength(minLength) {
341
+ return (control) => {
342
+ const value = control.value;
343
+ return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length >= minLength))
344
+ ? null : { itemsMinLength: minLength };
345
+ };
346
+ }
347
+ function validateItemsMaxLength(maxLength) {
348
+ return (control) => {
349
+ const value = control.value;
350
+ return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length <= maxLength))
351
+ ? null : { itemsMaxLength: maxLength };
352
+ };
353
+ }
354
+ function validateItemsMinValue(min) {
355
+ return (control) => {
356
+ const value = control.value;
357
+ return (Array.isArray(value) && value.every(v => typeof v == "number" && v >= min))
358
+ ? null : { itemsMinValue: min };
359
+ };
360
+ }
361
+ function validateItemsMaxValue(max) {
362
+ return (control) => {
363
+ const value = control.value;
364
+ return (Array.isArray(value) && value.every(v => typeof v == "number" && v <= max))
365
+ ? null : { itemsMaxValue: max };
366
+ };
367
+ }
368
+
404
369
  const indexLabels = ["$ix", "$pix"];
405
370
  class FormSubject extends Subject {
406
371
  constructor(notifyCallback) {
@@ -1797,7 +1762,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
1797
1762
  ReactiveFormsModule,
1798
1763
  NgxUtilsModule
1799
1764
  ],
1800
- entryComponents: components,
1801
1765
  providers: [
1802
1766
  ...pipes,
1803
1767
  { provide: NG_VALIDATORS, useValue: validateJSON, multi: true },
@@ -1826,5 +1790,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
1826
1790
  * Generated bundle index. Do not edit.
1827
1791
  */
1828
1792
 
1829
- export { AsyncSubmitDirective, DynamicBaseFormArrayComponent, DynamicBaseFormComponent, DynamicBaseFormControlComponent, DynamicBaseFormControlContainerComponent, DynamicBaseFormGroupComponent, DynamicBaseSelectComponent, DynamicEditorModel, DynamicFormArrayGroupModel, DynamicFormArrayModel, DynamicFormOption, DynamicFormService, DynamicSelectModel, EDITOR_FORMATS, FormFile, FormInput, FormModel, FormSelect, FormSelectSubject, FormSerializable, FormStatic, FormSubject, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, createFormControl, createFormFile, createFormInput, createFormModel, createFormSelect, createFormStatic, defaultSerializer, defineFormControl, getFormControl, getFormSerializer, mergeFormModels, replaceSpecialChars, validateItemsMaxLength, validateItemsMaxValue, validateItemsMinLength, validateItemsMinValue, validateJSON, validatePhone, validateRequiredTranslation };
1793
+ export { AsyncSubmitDirective, DynamicBaseFormArrayComponent, DynamicBaseFormComponent, DynamicBaseFormControlComponent, DynamicBaseFormControlContainerComponent, DynamicBaseFormGroupComponent, DynamicBaseSelectComponent, DynamicEditorModel, DynamicFormArrayGroupModel, DynamicFormArrayModel, DynamicFormOption, DynamicFormService, DynamicSelectModel, EDITOR_FORMATS, FormSelectSubject, FormSubject, MAX_INPUT_NUM, MIN_INPUT_NUM, NgxDynamicFormModule, createFormArray, createFormCheckbox, createFormDate, createFormEditor, createFormFile, createFormGroup, createFormInput, createFormSelect, createFormTextarea, mergeFormModels, replaceSpecialChars, validateItemsMaxLength, validateItemsMaxValue, validateItemsMinLength, validateItemsMinValue, validateJSON, validatePhone, validateRequiredTranslation };
1830
1794
  //# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map