@stemy/ngx-dynamic-form 13.1.21 → 13.2.0

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 } 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 } 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,202 +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
- const refs = Array.isArray(property.allOf)
115
- ? property.allOf.map(o => o.$ref).filter(isStringWithVal)
116
- : [property.items?.$ref, property.$ref].filter(isStringWithVal);
117
- return refs.map(t => t.split("/").pop());
118
- }
119
- function replaceSpecialChars(str, to = "-") {
120
- return `${str}`.replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g, to);
121
- }
122
- function mergeFormModels(formModels) {
123
- const res = [];
124
- for (const formModel of formModels) {
125
- for (const subModel of formModel) {
126
- const index = res.findIndex(t => t.id == subModel.id);
127
- if (index >= 0) {
128
- res[index] = subModel;
129
- continue;
130
- }
131
- res.push(subModel);
132
- }
133
- }
134
- return res;
135
- }
136
- function collectPathAble(start, getter) {
137
- if (!start || !getter(start))
138
- return [];
139
- const parts = [];
140
- let currentPath = start;
141
- while (currentPath) {
142
- const val = getter(currentPath);
143
- if (val) {
144
- parts.unshift(val);
145
- }
146
- currentPath = currentPath.parent;
147
- }
148
- return parts;
149
- }
150
- const MIN_INPUT_NUM = -999999999;
151
- const MAX_INPUT_NUM = 999999999;
152
- const EDITOR_FORMATS = ["php", "json", "html", "css", "scss"];
153
-
154
- function validateJSON(control) {
155
- const value = control.value;
156
- if (!value)
157
- return null;
158
- try {
159
- JSON.parse(value);
160
- return null;
161
- }
162
- catch (e) {
163
- return { json: true };
164
- }
165
- }
166
- function validateRequiredTranslation(control) {
167
- const value = control.value;
168
- if (!value || value.length == 0)
169
- return { requiredTranslation: true };
170
- return value.findIndex(t => (t.lang == "de" || t.lang == "en") && !t.translation) < 0
171
- ? null
172
- : { requiredTranslation: true };
173
- }
174
- function validatePhone(control) {
175
- const value = control.value;
176
- if (!value)
177
- return Promise.resolve(null);
178
- const phoneRegexp = /^(?:\d){10,12}$/;
179
- return phoneRegexp.test(value) ? null : { phone: true };
180
- }
181
- function validateItemsMinLength(minLength) {
182
- return (control) => {
183
- const value = control.value;
184
- return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length >= minLength))
185
- ? null : { itemsMinLength: minLength };
186
- };
187
- }
188
- function validateItemsMaxLength(maxLength) {
189
- return (control) => {
190
- const value = control.value;
191
- return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length <= maxLength))
192
- ? null : { itemsMaxLength: maxLength };
193
- };
194
- }
195
- function validateItemsMinValue(min) {
196
- return (control) => {
197
- const value = control.value;
198
- return (Array.isArray(value) && value.every(v => typeof v == "number" && v >= min))
199
- ? null : { itemsMinValue: min };
200
- };
201
- }
202
- function validateItemsMaxValue(max) {
203
- return (control) => {
204
- const value = control.value;
205
- return (Array.isArray(value) && value.every(v => typeof v == "number" && v <= max))
206
- ? null : { itemsMaxValue: max };
207
- };
208
- }
209
-
210
14
  class DynamicEditorModel extends DynamicInputControlModel {
211
15
  constructor(config, layout) {
212
16
  super(config, layout);
@@ -398,6 +202,167 @@ class DynamicSelectModel extends DynamicSelectModel$1 {
398
202
  }
399
203
  }
400
204
 
205
+ function createFormConfig(id, config) {
206
+ config = config || { id };
207
+ config.id = id;
208
+ config.label = ObjectUtils.isNullOrUndefined(config.label) ? id : config.label;
209
+ config.disabled = config.disabled || false;
210
+ config.hidden = config.hidden || false;
211
+ return config;
212
+ }
213
+ function createFormCheckbox(id, config, layout) {
214
+ config = createFormConfig(id, config);
215
+ config.indeterminate = config.indeterminate || false;
216
+ return new DynamicCheckboxModel(config, layout);
217
+ }
218
+ function createFormDate(id, config, layout) {
219
+ config = createFormConfig(id, config);
220
+ config.autoFocus = config.autoFocus || false;
221
+ config.focusedDate = config.focusedDate || new Date();
222
+ config.inline = config.inline || false;
223
+ return new DynamicDatePickerModel(config, layout);
224
+ }
225
+ function createFormEditor(id, config, layout) {
226
+ config = createFormConfig(id, config);
227
+ return new DynamicEditorModel(config, layout);
228
+ }
229
+ function createFormArray(id, config, layout) {
230
+ config = createFormConfig(id, config);
231
+ return new DynamicFormArrayModel(config, layout);
232
+ }
233
+ function createFormGroup(id, config, layout) {
234
+ config = createFormConfig(id, config);
235
+ config.name = config.name || "";
236
+ return new DynamicFormGroupModel(config, layout);
237
+ }
238
+ function createFormInput(id, config, type = "text", layout) {
239
+ config = createFormConfig(id, config);
240
+ config.inputType = config.inputType || type;
241
+ config.placeholder = config.placeholder || (config.inputType == "mask" ? "_" : "");
242
+ config.step = config.step || 1;
243
+ config.mask = config.mask || null;
244
+ return new DynamicInputModel(config, layout);
245
+ }
246
+ function createFormSelect(id, config, layout) {
247
+ config = createFormConfig(id, config);
248
+ config.options = config.options || [];
249
+ return new DynamicSelectModel(config, layout);
250
+ }
251
+ function createFormTextarea(id, config, layout) {
252
+ config = createFormConfig(id, config);
253
+ config.cols = config.cols || 10;
254
+ config.rows = config.rows || 3;
255
+ config.wrap = config.wrap || "soft";
256
+ return new DynamicTextAreaModel(config, layout);
257
+ }
258
+ function createFormFile(id, config, layout) {
259
+ config = createFormConfig(id, config);
260
+ config.accept = config.accept || ["jpg", "jpeg", "png"];
261
+ config.multiple = config.multiple || false;
262
+ config.url = ObjectUtils.isString(config.url) ? config.url : "assets";
263
+ return new DynamicFileUploadModel(config, layout);
264
+ }
265
+
266
+ function isStringWithVal(val) {
267
+ return typeof val == "string" && val.length > 0;
268
+ }
269
+ function findRefs(property) {
270
+ const refs = Array.isArray(property.allOf)
271
+ ? property.allOf.map(o => o.$ref).filter(isStringWithVal)
272
+ : [property.items?.$ref, property.$ref].filter(isStringWithVal);
273
+ return refs.map(t => t.split("/").pop());
274
+ }
275
+ function replaceSpecialChars(str, to = "-") {
276
+ return `${str}`.replace(/[&\/\\#, +()$~%.@'":*?<>{}]/g, to);
277
+ }
278
+ function mergeFormModels(formModels) {
279
+ const res = [];
280
+ for (const formModel of formModels) {
281
+ for (const subModel of formModel) {
282
+ const index = res.findIndex(t => t.id == subModel.id);
283
+ if (index >= 0) {
284
+ res[index] = subModel;
285
+ continue;
286
+ }
287
+ res.push(subModel);
288
+ }
289
+ }
290
+ return res;
291
+ }
292
+ function collectPathAble(start, getter) {
293
+ if (!start || !getter(start))
294
+ return [];
295
+ const parts = [];
296
+ let currentPath = start;
297
+ while (currentPath) {
298
+ const val = getter(currentPath);
299
+ if (val) {
300
+ parts.unshift(val);
301
+ }
302
+ currentPath = currentPath.parent;
303
+ }
304
+ return parts;
305
+ }
306
+ const MIN_INPUT_NUM = -999999999;
307
+ const MAX_INPUT_NUM = 999999999;
308
+ const EDITOR_FORMATS = ["php", "json", "html", "css", "scss"];
309
+
310
+ function validateJSON(control) {
311
+ const value = control.value;
312
+ if (!value)
313
+ return null;
314
+ try {
315
+ JSON.parse(value);
316
+ return null;
317
+ }
318
+ catch (e) {
319
+ return { json: true };
320
+ }
321
+ }
322
+ function validateRequiredTranslation(control) {
323
+ const value = control.value;
324
+ if (!value || value.length == 0)
325
+ return { requiredTranslation: true };
326
+ return value.findIndex(t => (t.lang == "de" || t.lang == "en") && !t.translation) < 0
327
+ ? null
328
+ : { requiredTranslation: true };
329
+ }
330
+ function validatePhone(control) {
331
+ const value = control.value;
332
+ if (!value)
333
+ return Promise.resolve(null);
334
+ const phoneRegexp = /^(?:\d){10,12}$/;
335
+ return phoneRegexp.test(value) ? null : { phone: true };
336
+ }
337
+ function validateItemsMinLength(minLength) {
338
+ return (control) => {
339
+ const value = control.value;
340
+ return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length >= minLength))
341
+ ? null : { itemsMinLength: minLength };
342
+ };
343
+ }
344
+ function validateItemsMaxLength(maxLength) {
345
+ return (control) => {
346
+ const value = control.value;
347
+ return (Array.isArray(value) && value.every(v => typeof v == "string" && v.length <= maxLength))
348
+ ? null : { itemsMaxLength: maxLength };
349
+ };
350
+ }
351
+ function validateItemsMinValue(min) {
352
+ return (control) => {
353
+ const value = control.value;
354
+ return (Array.isArray(value) && value.every(v => typeof v == "number" && v >= min))
355
+ ? null : { itemsMinValue: min };
356
+ };
357
+ }
358
+ function validateItemsMaxValue(max) {
359
+ return (control) => {
360
+ const value = control.value;
361
+ return (Array.isArray(value) && value.every(v => typeof v == "number" && v <= max))
362
+ ? null : { itemsMaxValue: max };
363
+ };
364
+ }
365
+
401
366
  const indexLabels = ["$ix", "$pix"];
402
367
  class FormSubject extends Subject {
403
368
  constructor(notifyCallback) {
@@ -1762,7 +1727,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
1762
1727
  ReactiveFormsModule,
1763
1728
  NgxUtilsModule
1764
1729
  ],
1765
- entryComponents: components,
1766
1730
  providers: [
1767
1731
  ...pipes,
1768
1732
  { provide: NG_VALIDATORS, useValue: validateJSON, multi: true },
@@ -1791,5 +1755,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.8", ngImpor
1791
1755
  * Generated bundle index. Do not edit.
1792
1756
  */
1793
1757
 
1794
- 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 };
1758
+ 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 };
1795
1759
  //# sourceMappingURL=stemy-ngx-dynamic-form.mjs.map