@decaf-ts/for-angular 0.0.25 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/decaf-ts-for-angular.mjs +1486 -1505
- package/fesm2022/decaf-ts-for-angular.mjs.map +1 -1
- package/index.d.ts +7482 -3
- package/package.json +15 -18
- package/components/component-renderer/component-renderer.component.d.ts +0 -278
- package/components/crud-field/crud-field.component.d.ts +0 -611
- package/components/crud-form/constants.d.ts +0 -5
- package/components/crud-form/crud-form.component.d.ts +0 -288
- package/components/crud-form/types.d.ts +0 -17
- package/components/empty-state/empty-state.component.d.ts +0 -300
- package/components/fieldset/fieldset.component.d.ts +0 -555
- package/components/filter/filter.component.d.ts +0 -514
- package/components/for-angular-components.module.d.ts +0 -20
- package/components/index.d.ts +0 -16
- package/components/layout/layout.component.d.ts +0 -110
- package/components/list/list.component.d.ts +0 -848
- package/components/list-item/list-item.component.d.ts +0 -390
- package/components/model-renderer/model-renderer.component.d.ts +0 -97
- package/components/pagination/constants.d.ts +0 -7
- package/components/pagination/pagination.component.d.ts +0 -264
- package/components/searchbar/searchbar.component.d.ts +0 -407
- package/components/stepped-form/stepped-form.component.d.ts +0 -255
- package/directives/collapsable.directive.d.ts +0 -9
- package/directives/index.d.ts +0 -1
- package/engine/DynamicModule.d.ts +0 -17
- package/engine/NgxBaseComponent.d.ts +0 -541
- package/engine/NgxCrudFormField.d.ts +0 -123
- package/engine/NgxFormService.d.ts +0 -601
- package/engine/NgxRenderingEngine.d.ts +0 -282
- package/engine/ValidatorFactory.d.ts +0 -15
- package/engine/constants.d.ts +0 -168
- package/engine/decorators.d.ts +0 -25
- package/engine/index.d.ts +0 -18
- package/engine/interfaces.d.ts +0 -271
- package/engine/types.d.ts +0 -200
- package/esm2022/components/component-renderer/component-renderer.component.mjs +0 -321
- package/esm2022/components/crud-field/crud-field.component.mjs +0 -518
- package/esm2022/components/crud-form/constants.mjs +0 -14
- package/esm2022/components/crud-form/crud-form.component.mjs +0 -259
- package/esm2022/components/crud-form/types.mjs +0 -2
- package/esm2022/components/empty-state/empty-state.component.mjs +0 -345
- package/esm2022/components/fieldset/fieldset.component.mjs +0 -677
- package/esm2022/components/filter/filter.component.mjs +0 -700
- package/esm2022/components/for-angular-components.module.mjs +0 -84
- package/esm2022/components/index.mjs +0 -20
- package/esm2022/components/layout/layout.component.mjs +0 -150
- package/esm2022/components/list/list.component.mjs +0 -1238
- package/esm2022/components/list-item/list-item.component.mjs +0 -405
- package/esm2022/components/model-renderer/model-renderer.component.mjs +0 -144
- package/esm2022/components/pagination/constants.mjs +0 -2
- package/esm2022/components/pagination/pagination.component.mjs +0 -321
- package/esm2022/components/searchbar/searchbar.component.mjs +0 -491
- package/esm2022/components/stepped-form/stepped-form.component.mjs +0 -306
- package/esm2022/decaf-ts-for-angular.mjs +0 -5
- package/esm2022/directives/collapsable.directive.mjs +0 -29
- package/esm2022/directives/index.mjs +0 -2
- package/esm2022/engine/DynamicModule.mjs +0 -18
- package/esm2022/engine/NgxBaseComponent.mjs +0 -541
- package/esm2022/engine/NgxCrudFormField.mjs +0 -137
- package/esm2022/engine/NgxFormService.mjs +0 -917
- package/esm2022/engine/NgxRenderingEngine.mjs +0 -376
- package/esm2022/engine/ValidatorFactory.mjs +0 -106
- package/esm2022/engine/constants.mjs +0 -170
- package/esm2022/engine/decorators.mjs +0 -38
- package/esm2022/engine/index.mjs +0 -19
- package/esm2022/engine/interfaces.mjs +0 -4
- package/esm2022/engine/types.mjs +0 -2
- package/esm2022/for-angular-common.module.mjs +0 -84
- package/esm2022/helpers/index.mjs +0 -13
- package/esm2022/helpers/utils.mjs +0 -436
- package/esm2022/i18n/Loader.mjs +0 -86
- package/esm2022/i18n/data/en.json +0 -85
- package/esm2022/public-apis.mjs +0 -15
- package/for-angular-common.module.d.ts +0 -50
- package/helpers/index.d.ts +0 -12
- package/helpers/utils.d.ts +0 -279
- package/i18n/Loader.d.ts +0 -43
- package/public-apis.d.ts +0 -14
|
@@ -1,601 +0,0 @@
|
|
|
1
|
-
import { FieldProperties, UIModelMetadata } from '@decaf-ts/ui-decorators';
|
|
2
|
-
import { FieldUpdateMode, FormParent } from './types';
|
|
3
|
-
import { IComponentConfig, IComponentInput } from './interfaces';
|
|
4
|
-
import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
|
|
5
|
-
import { OperationKeys } from '@decaf-ts/db-decorators';
|
|
6
|
-
/**
|
|
7
|
-
* @description Service for managing Angular forms and form controls.
|
|
8
|
-
* @summary The NgxFormService provides utility methods for creating, managing, and validating Angular forms and form controls. It includes functionality for registering forms, adding controls, validating fields, and handling form data.
|
|
9
|
-
*
|
|
10
|
-
* @class
|
|
11
|
-
* @param {WeakMap<AbstractControl, FieldProperties>} controls - A WeakMap to store control properties.
|
|
12
|
-
* @param {Map<string, FormGroup>} formRegistry - A Map to store registered forms.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* // Creating a form from components
|
|
16
|
-
* const components = [
|
|
17
|
-
* { inputs: { name: 'username', type: 'text', required: true } },
|
|
18
|
-
* { inputs: { name: 'password', type: 'password', minLength: 8 } }
|
|
19
|
-
* ];
|
|
20
|
-
* const form = NgxFormService.createFormFromComponents('loginForm', components, true);
|
|
21
|
-
*
|
|
22
|
-
* // Validating fields
|
|
23
|
-
* NgxFormService.validateFields(form);
|
|
24
|
-
*
|
|
25
|
-
* // Getting form data
|
|
26
|
-
* const formData = NgxFormService.getFormData(form);
|
|
27
|
-
*
|
|
28
|
-
* @mermaid
|
|
29
|
-
* sequenceDiagram
|
|
30
|
-
* participant C as Component
|
|
31
|
-
* participant NFS as NgxFormService
|
|
32
|
-
* participant AF as Angular Forms
|
|
33
|
-
* C->>NFS: createFormFromComponents()
|
|
34
|
-
* NFS->>AF: new FormGroup()
|
|
35
|
-
* NFS->>NFS: addFormControl()
|
|
36
|
-
* NFS->>AF: addControl()
|
|
37
|
-
* NFS-->>C: Return FormGroup
|
|
38
|
-
* C->>NFS: validateFields()
|
|
39
|
-
* NFS->>AF: markAsTouched(), markAsDirty(), updateValueAndValidity()
|
|
40
|
-
* C->>NFS: getFormData()
|
|
41
|
-
* NFS->>AF: Get control values
|
|
42
|
-
* NFS-->>C: Return form data
|
|
43
|
-
*/
|
|
44
|
-
export declare class NgxFormService {
|
|
45
|
-
/**
|
|
46
|
-
* @description WeakMap that stores control properties for form controls.
|
|
47
|
-
* @summary A WeakMap that associates AbstractControl instances with their corresponding FieldProperties.
|
|
48
|
-
* This allows the service to track metadata for form controls without creating memory leaks.
|
|
49
|
-
*
|
|
50
|
-
* @type {WeakMap<AbstractControl, FieldProperties>}
|
|
51
|
-
* @private
|
|
52
|
-
* @static
|
|
53
|
-
* @memberOf NgxFormService
|
|
54
|
-
*/
|
|
55
|
-
private static controls;
|
|
56
|
-
/**
|
|
57
|
-
* @description Registry of form groups indexed by their unique identifiers.
|
|
58
|
-
* @summary A Map that stores FormGroup instances with their unique string identifiers.
|
|
59
|
-
* This allows global access to registered forms throughout the application.
|
|
60
|
-
*
|
|
61
|
-
* @type {Map<string, FormGroup>}
|
|
62
|
-
* @private
|
|
63
|
-
* @static
|
|
64
|
-
* @memberOf NgxFormService
|
|
65
|
-
*/
|
|
66
|
-
private static formRegistry;
|
|
67
|
-
private static pageMapper;
|
|
68
|
-
/**
|
|
69
|
-
* @description Creates a new form group or form array with the specified identifier.
|
|
70
|
-
* @summary Generates a FormGroup or FormArray based on the provided properties. If pages are specified
|
|
71
|
-
* and greater than 1, creates a FormArray; otherwise creates a FormGroup. The form can optionally
|
|
72
|
-
* be registered in the global form registry for later access throughout the application.
|
|
73
|
-
*
|
|
74
|
-
* @param {string} id - Unique identifier for the form
|
|
75
|
-
* @param {Partial<IComponentInput>} [props={}] - Configuration properties for the form
|
|
76
|
-
* @param {boolean} [registry=true] - Whether to register the form in the global registry
|
|
77
|
-
* @return {FormGroup | FormArray} The created form instance
|
|
78
|
-
*
|
|
79
|
-
* @mermaid
|
|
80
|
-
* sequenceDiagram
|
|
81
|
-
* participant C as Component
|
|
82
|
-
* participant NFS as NgxFormService
|
|
83
|
-
* participant FR as Form Registry
|
|
84
|
-
* participant AF as Angular Forms
|
|
85
|
-
*
|
|
86
|
-
* C->>NFS: createForm(id, props, registry)
|
|
87
|
-
* NFS->>FR: Check if form exists
|
|
88
|
-
* alt Form doesn't exist
|
|
89
|
-
* alt props.pages > 1
|
|
90
|
-
* NFS->>AF: new FormArray([])
|
|
91
|
-
* else
|
|
92
|
-
* NFS->>AF: new FormGroup({})
|
|
93
|
-
* end
|
|
94
|
-
* alt registry is true
|
|
95
|
-
* NFS->>FR: addRegistry(id, form)
|
|
96
|
-
* end
|
|
97
|
-
* end
|
|
98
|
-
* NFS-->>C: Return FormGroup | FormArray
|
|
99
|
-
*
|
|
100
|
-
* @static
|
|
101
|
-
* @memberOf NgxFormService
|
|
102
|
-
*/
|
|
103
|
-
static createForm(id: string, props?: Partial<IComponentInput>, registry?: boolean): FormGroup | FormArray;
|
|
104
|
-
/**
|
|
105
|
-
* @description Adds a form to the registry.
|
|
106
|
-
* @summary Registers a FormGroup or FormArray with a unique identifier for global access throughout
|
|
107
|
-
* the application. This allows forms to be retrieved and managed centrally. Throws an error if
|
|
108
|
-
* the identifier is already in use to prevent conflicts.
|
|
109
|
-
*
|
|
110
|
-
* @param {string} formId - The unique identifier for the form
|
|
111
|
-
* @param {FormParent} formGroup - The FormGroup or FormArray to be registered
|
|
112
|
-
* @return {void}
|
|
113
|
-
* @throws {Error} If a FormGroup with the given id is already registered
|
|
114
|
-
*
|
|
115
|
-
* @static
|
|
116
|
-
* @memberOf NgxFormService
|
|
117
|
-
*/
|
|
118
|
-
static addRegistry(formId: string, formGroup: FormParent): void;
|
|
119
|
-
/**
|
|
120
|
-
* @description Removes a form from the registry.
|
|
121
|
-
* @summary Deletes a FormGroup or FormArray from the registry using its unique identifier.
|
|
122
|
-
* This cleans up the registry and allows the identifier to be reused. The form itself
|
|
123
|
-
* is not destroyed, only removed from the central registry.
|
|
124
|
-
*
|
|
125
|
-
* @param {string} formId - The unique identifier of the form to be removed
|
|
126
|
-
* @return {void}
|
|
127
|
-
*
|
|
128
|
-
* @static
|
|
129
|
-
* @memberOf NgxFormService
|
|
130
|
-
*/
|
|
131
|
-
static removeRegistry(formId: string): void;
|
|
132
|
-
/**
|
|
133
|
-
* @description Resolves the parent group and control name from a path.
|
|
134
|
-
* @summary Traverses the form group structure to find the parent group and control name for a given path.
|
|
135
|
-
* Handles complex nested structures including arrays and sub-groups. Creates missing intermediate
|
|
136
|
-
* groups as needed and properly configures FormArray controls for multiple value scenarios.
|
|
137
|
-
*
|
|
138
|
-
* @param {FormGroup} formGroup - The root FormGroup to traverse
|
|
139
|
-
* @param {string} path - The dot-separated path to the control (e.g., 'user.address.street')
|
|
140
|
-
* @param {IComponentInput} componentProps - Properties defining the component configuration
|
|
141
|
-
* @param {KeyValue} parentProps - Properties from the parent component for context
|
|
142
|
-
* @return {FormParentGroup} A tuple containing the parent FormGroup and the control name
|
|
143
|
-
*
|
|
144
|
-
* @private
|
|
145
|
-
* @mermaid
|
|
146
|
-
* sequenceDiagram
|
|
147
|
-
* participant NFS as NgxFormService
|
|
148
|
-
* participant FG as FormGroup
|
|
149
|
-
* participant FA as FormArray
|
|
150
|
-
*
|
|
151
|
-
* NFS->>NFS: Split path into parts
|
|
152
|
-
* loop For each path part
|
|
153
|
-
* alt Control doesn't exist
|
|
154
|
-
* alt isMultiple and part is childOf
|
|
155
|
-
* NFS->>FA: new FormArray([new FormGroup({})])
|
|
156
|
-
* else
|
|
157
|
-
* NFS->>FG: new FormGroup({})
|
|
158
|
-
* end
|
|
159
|
-
* NFS->>FG: addControl(part, newControl)
|
|
160
|
-
* end
|
|
161
|
-
* NFS->>NFS: Navigate to next level
|
|
162
|
-
* end
|
|
163
|
-
* NFS-->>NFS: Return [parentGroup, controlName]
|
|
164
|
-
*
|
|
165
|
-
* @static
|
|
166
|
-
* @memberOf NgxFormService
|
|
167
|
-
*/
|
|
168
|
-
private static resolveParentGroup;
|
|
169
|
-
/**
|
|
170
|
-
* @description Retrieves component properties from a FormGroup or FormArray.
|
|
171
|
-
* @summary Extracts component properties stored in the form group metadata. If a FormGroup is provided
|
|
172
|
-
* and groupArrayName is specified, it will look for the FormArray within the form structure.
|
|
173
|
-
*
|
|
174
|
-
* @param {FormGroup | FormArray} formGroup - The form group or form array to extract properties from
|
|
175
|
-
* @param {string} [key] - Optional key to retrieve a specific property
|
|
176
|
-
* @param {string} [groupArrayName] - Optional name of the group array if formGroup is not a FormArray
|
|
177
|
-
* @return {Partial<FieldProperties>} The component properties or a specific property if key is provided
|
|
178
|
-
*
|
|
179
|
-
* @static
|
|
180
|
-
* @memberOf NgxFormService
|
|
181
|
-
*/
|
|
182
|
-
static getComponentPropsFromGroupArray(formGroup: FormGroup | FormArray, key?: string, groupArrayName?: string | undefined): Partial<FieldProperties>;
|
|
183
|
-
/**
|
|
184
|
-
* @description Adds a new group to a parent FormArray.
|
|
185
|
-
* @summary Creates and adds a new FormGroup to the specified parent FormArray based on the
|
|
186
|
-
* component properties stored in the parent's metadata. This is used for dynamic form arrays
|
|
187
|
-
* where new groups need to be added at runtime.
|
|
188
|
-
*
|
|
189
|
-
* @param {FormGroup} formGroup - The root form group containing the parent FormArray
|
|
190
|
-
* @param {string} parentName - The name of the parent FormArray to add the group to
|
|
191
|
-
* @param {number} [index=1] - The index position where the new group should be added
|
|
192
|
-
* @return {FormGroup} The newly created and added FormGroup
|
|
193
|
-
*
|
|
194
|
-
* @static
|
|
195
|
-
* @memberOf NgxFormService
|
|
196
|
-
*/
|
|
197
|
-
static addGroupToParent(formGroup: FormGroup, parentName: string, index?: number): FormGroup;
|
|
198
|
-
/**
|
|
199
|
-
* @description Retrieves a FormGroup from a parent FormArray at the specified index.
|
|
200
|
-
* @summary Gets a FormGroup from the specified parent FormArray. If the group doesn't exist
|
|
201
|
-
* at the given index, it will create a new one using addGroupToParent.
|
|
202
|
-
*
|
|
203
|
-
* @param {FormGroup} formGroup - The root form group containing the parent FormArray
|
|
204
|
-
* @param {string} parentName - The name of the parent FormArray to retrieve the group from
|
|
205
|
-
* @param {number} [index=1] - The index of the group to retrieve
|
|
206
|
-
* @return {FormGroup} The FormGroup at the specified index
|
|
207
|
-
*
|
|
208
|
-
* @static
|
|
209
|
-
* @memberOf NgxFormService
|
|
210
|
-
*/
|
|
211
|
-
static getGroupFromParent(formGroup: FormGroup, parentName: string, index?: number): FormGroup;
|
|
212
|
-
/**
|
|
213
|
-
* @description Checks if a value is unique within a FormArray group.
|
|
214
|
-
* @summary Validates that the primary key value in a FormGroup is unique among all groups
|
|
215
|
-
* in the parent FormArray. The uniqueness check behavior differs based on the operation type.
|
|
216
|
-
*
|
|
217
|
-
* @param {FormGroup} formGroup - The FormGroup to check for uniqueness
|
|
218
|
-
* @param {number} index - The index of the current group within the FormArray
|
|
219
|
-
* @param {OperationKeys} [operation=OperationKeys.CREATE] - The type of operation being performed
|
|
220
|
-
* @return {boolean} True if the value is unique, false otherwise
|
|
221
|
-
*
|
|
222
|
-
* @static
|
|
223
|
-
* @memberOf NgxFormService
|
|
224
|
-
*/
|
|
225
|
-
static isUniqueOnGroup(formGroup: FormGroup, index: number, operation?: OperationKeys): boolean;
|
|
226
|
-
/**
|
|
227
|
-
* @description Enables all controls within a FormGroup or FormArray.
|
|
228
|
-
* @summary Recursively enables all form controls within the provided FormGroup or FormArray.
|
|
229
|
-
* This is useful for making all controls interactive after they have been disabled.
|
|
230
|
-
*
|
|
231
|
-
* @param {FormArray | FormGroup} formGroup - The FormGroup or FormArray to enable all controls for
|
|
232
|
-
* @return {void}
|
|
233
|
-
*
|
|
234
|
-
* @static
|
|
235
|
-
* @memberOf NgxFormService
|
|
236
|
-
*/
|
|
237
|
-
static enableAllGroupControls(formGroup: FormArray | FormGroup): void;
|
|
238
|
-
/**
|
|
239
|
-
* @description Adds a form control to a form group based on component properties.
|
|
240
|
-
* @summary Creates and configures a FormControl within the specified FormGroup using the provided
|
|
241
|
-
* component properties. Handles nested paths, multiple controls (FormArrays), and control registration.
|
|
242
|
-
* This method supports complex form structures with nested groups and arrays.
|
|
243
|
-
*
|
|
244
|
-
* @param {FormGroup} formGroup - The form group to add the control to
|
|
245
|
-
* @param {IComponentInput} componentProps - The component properties defining the control configuration
|
|
246
|
-
* @param {KeyValue} [parentProps={}] - Properties from the parent component for context
|
|
247
|
-
* @param {number} [index=0] - The index for multiple controls in FormArrays
|
|
248
|
-
* @return {void}
|
|
249
|
-
*
|
|
250
|
-
* @private
|
|
251
|
-
* @static
|
|
252
|
-
* @memberOf NgxFormService
|
|
253
|
-
*/
|
|
254
|
-
private static addFormControl;
|
|
255
|
-
/**
|
|
256
|
-
* @description Retrieves a control from a registered form.
|
|
257
|
-
* @summary Finds and returns an AbstractControl from a registered form using the form id and optional path.
|
|
258
|
-
* This method provides centralized access to form controls across the application by leveraging
|
|
259
|
-
* the form registry system.
|
|
260
|
-
*
|
|
261
|
-
* @param {string} formId - The unique identifier of the form in the registry
|
|
262
|
-
* @param {string} [path] - The optional dot-separated path to a specific control within the form
|
|
263
|
-
* @return {AbstractControl} The requested AbstractControl (FormGroup, FormArray, or FormControl)
|
|
264
|
-
* @throws {Error} If the form is not found in the registry or the control is not found in the form
|
|
265
|
-
*
|
|
266
|
-
* @mermaid
|
|
267
|
-
* sequenceDiagram
|
|
268
|
-
* participant C as Component
|
|
269
|
-
* participant NFS as NgxFormService
|
|
270
|
-
* participant FR as Form Registry
|
|
271
|
-
*
|
|
272
|
-
* C->>NFS: getControlFromForm(formId, path?)
|
|
273
|
-
* NFS->>FR: Get form by formId
|
|
274
|
-
* alt Form not found
|
|
275
|
-
* FR-->>NFS: null
|
|
276
|
-
* NFS-->>C: Throw Error
|
|
277
|
-
* else Form found
|
|
278
|
-
* FR-->>NFS: Return form
|
|
279
|
-
* alt path provided
|
|
280
|
-
* NFS->>NFS: form.get(path)
|
|
281
|
-
* alt Control not found
|
|
282
|
-
* NFS-->>C: Throw Error
|
|
283
|
-
* else
|
|
284
|
-
* NFS-->>C: Return control
|
|
285
|
-
* end
|
|
286
|
-
* else
|
|
287
|
-
* NFS-->>C: Return form
|
|
288
|
-
* end
|
|
289
|
-
* end
|
|
290
|
-
*
|
|
291
|
-
* @static
|
|
292
|
-
* @memberOf NgxFormService
|
|
293
|
-
*/
|
|
294
|
-
static getControlFromForm(formId: string, path?: string): AbstractControl;
|
|
295
|
-
/**
|
|
296
|
-
* @description Creates a form from UI model metadata children.
|
|
297
|
-
* @summary Generates a FormGroup from an array of UIModelMetadata objects, extracting component
|
|
298
|
-
* properties and creating appropriate form controls. This method is specifically designed to work
|
|
299
|
-
* with the UI decorator system and provides automatic form generation from metadata.
|
|
300
|
-
*
|
|
301
|
-
* @param {string} id - Unique identifier for the form
|
|
302
|
-
* @param {boolean} [registry=false] - Whether to register the created form in the global registry
|
|
303
|
-
* @param {UIModelMetadata[]} [children] - Array of UI model metadata objects to create controls from
|
|
304
|
-
* @return {FormGroup} The created FormGroup with controls for each child metadata
|
|
305
|
-
*
|
|
306
|
-
* @mermaid
|
|
307
|
-
* sequenceDiagram
|
|
308
|
-
* participant C as Component
|
|
309
|
-
* participant NFS as NgxFormService
|
|
310
|
-
* participant AF as Angular Forms
|
|
311
|
-
*
|
|
312
|
-
* C->>NFS: createFormFromChildren(id, registry, children)
|
|
313
|
-
* NFS->>AF: new FormGroup({})
|
|
314
|
-
* loop For each child metadata
|
|
315
|
-
* NFS->>NFS: addFormControl(form, child.props)
|
|
316
|
-
* NFS->>AF: Create and add FormControl
|
|
317
|
-
* end
|
|
318
|
-
* alt registry is true
|
|
319
|
-
* NFS->>NFS: addRegistry(id, form)
|
|
320
|
-
* end
|
|
321
|
-
* NFS-->>C: Return FormGroup
|
|
322
|
-
*
|
|
323
|
-
* @static
|
|
324
|
-
* @memberOf NgxFormService
|
|
325
|
-
*/
|
|
326
|
-
static createFormFromChildren(id: string, registry?: boolean, children?: UIModelMetadata[]): FormGroup;
|
|
327
|
-
/**
|
|
328
|
-
* @description Creates a form from component configurations.
|
|
329
|
-
* @summary Generates a FormGroup based on an array of component configurations and optionally registers it.
|
|
330
|
-
* This method processes component input configurations to create appropriate form controls with
|
|
331
|
-
* validation and initial values.
|
|
332
|
-
*
|
|
333
|
-
* @param {string} id - The unique identifier for the form
|
|
334
|
-
* @param {IComponentConfig[]} components - An array of component configurations defining the form structure
|
|
335
|
-
* @param {boolean} [registry=false] - Whether to register the created form in the global registry
|
|
336
|
-
* @return {FormGroup} The created FormGroup with controls for each component configuration
|
|
337
|
-
*
|
|
338
|
-
* @mermaid
|
|
339
|
-
* sequenceDiagram
|
|
340
|
-
* participant C as Component
|
|
341
|
-
* participant NFS as NgxFormService
|
|
342
|
-
* participant AF as Angular Forms
|
|
343
|
-
*
|
|
344
|
-
* C->>NFS: createFormFromComponents(id, components, registry)
|
|
345
|
-
* NFS->>AF: new FormGroup({})
|
|
346
|
-
* loop For each component config
|
|
347
|
-
* NFS->>NFS: addFormControl(form, component.inputs)
|
|
348
|
-
* NFS->>AF: Create and add FormControl
|
|
349
|
-
* end
|
|
350
|
-
* alt registry is true
|
|
351
|
-
* NFS->>NFS: addRegistry(id, form)
|
|
352
|
-
* end
|
|
353
|
-
* NFS-->>C: Return FormGroup
|
|
354
|
-
*
|
|
355
|
-
* @static
|
|
356
|
-
* @memberOf NgxFormService
|
|
357
|
-
*/
|
|
358
|
-
static createFormFromComponents(id: string, components: IComponentConfig[], registry?: boolean): FormGroup;
|
|
359
|
-
/**
|
|
360
|
-
* @description Adds a control to a form based on component properties.
|
|
361
|
-
* @summary Creates and adds a form control to a form (existing or new) based on the provided component properties.
|
|
362
|
-
* Handles multi-page forms by managing FormArray structures and proper indexing. This method supports
|
|
363
|
-
* complex form scenarios including nested controls and page-based form organization.
|
|
364
|
-
*
|
|
365
|
-
* @param {string} id - The unique identifier of the form
|
|
366
|
-
* @param {FieldProperties} componentProperties - The properties of the component to create the control from
|
|
367
|
-
* @param {FieldProperties} [parentProps] - Optional parent properties for context and configuration
|
|
368
|
-
* @return {AbstractControl} The form or created control
|
|
369
|
-
*
|
|
370
|
-
* @mermaid
|
|
371
|
-
* sequenceDiagram
|
|
372
|
-
* participant C as Component
|
|
373
|
-
* participant NFS as NgxFormService
|
|
374
|
-
* participant F as Form
|
|
375
|
-
*
|
|
376
|
-
* C->>NFS: addControlFromProps(id, componentProps, parentProps?)
|
|
377
|
-
* NFS->>NFS: createForm(id, parentProps, true)
|
|
378
|
-
* alt Multi-page form (parentProps.pages > 1)
|
|
379
|
-
* NFS->>NFS: Calculate page index
|
|
380
|
-
* NFS->>F: Get or create FormGroup at index
|
|
381
|
-
* NFS->>NFS: Set form to page FormGroup
|
|
382
|
-
* end
|
|
383
|
-
* alt componentProperties has path
|
|
384
|
-
* NFS->>NFS: addFormControl(form, componentProperties, parentProps)
|
|
385
|
-
* end
|
|
386
|
-
* NFS-->>C: Return form/control
|
|
387
|
-
*
|
|
388
|
-
* @static
|
|
389
|
-
* @memberOf NgxFormService
|
|
390
|
-
*/
|
|
391
|
-
static addControlFromProps(id: string, componentProperties: FieldProperties, parentProps?: FieldProperties): AbstractControl;
|
|
392
|
-
/**
|
|
393
|
-
* @description Retrieves form data from a FormGroup.
|
|
394
|
-
* @summary Extracts and processes the data from a FormGroup, handling different input types and nested form groups.
|
|
395
|
-
* Performs type conversion for various HTML5 input types, validates nested controls, and manages
|
|
396
|
-
* multiple control scenarios. Automatically enables all group controls after data extraction.
|
|
397
|
-
*
|
|
398
|
-
* @param {FormGroup} formGroup - The FormGroup to extract data from
|
|
399
|
-
* @return {Record<string, unknown>} An object containing the processed form data with proper type conversions
|
|
400
|
-
*
|
|
401
|
-
* @mermaid
|
|
402
|
-
* sequenceDiagram
|
|
403
|
-
* participant C as Component
|
|
404
|
-
* participant NFS as NgxFormService
|
|
405
|
-
* participant FG as FormGroup
|
|
406
|
-
* participant FC as FormControl
|
|
407
|
-
*
|
|
408
|
-
* C->>NFS: getFormData(formGroup)
|
|
409
|
-
* loop For each control in formGroup
|
|
410
|
-
* alt Control is not FormControl
|
|
411
|
-
* NFS->>NFS: Recursive getFormData(control)
|
|
412
|
-
* alt parentProps.multiple and !isValid
|
|
413
|
-
* NFS->>NFS: reset(control)
|
|
414
|
-
* end
|
|
415
|
-
* else Control is FormControl
|
|
416
|
-
* NFS->>FC: Get control value
|
|
417
|
-
* NFS->>NFS: Apply type conversion based on props.type
|
|
418
|
-
* alt HTML5CheckTypes
|
|
419
|
-
* NFS->>NFS: Keep boolean value
|
|
420
|
-
* else NUMBER type
|
|
421
|
-
* NFS->>NFS: parseToNumber(value)
|
|
422
|
-
* else DATE/DATETIME types
|
|
423
|
-
* NFS->>NFS: new Date(value)
|
|
424
|
-
* else Other types
|
|
425
|
-
* NFS->>NFS: escapeHtml(value)
|
|
426
|
-
* end
|
|
427
|
-
* end
|
|
428
|
-
* end
|
|
429
|
-
* NFS->>NFS: enableAllGroupControls(formGroup)
|
|
430
|
-
* NFS-->>C: Return processed data object
|
|
431
|
-
*
|
|
432
|
-
* @static
|
|
433
|
-
* @memberOf NgxFormService
|
|
434
|
-
*/
|
|
435
|
-
static getFormData(formGroup: FormGroup): Record<string, unknown>;
|
|
436
|
-
/**
|
|
437
|
-
* @description Validates fields in a form control or form group.
|
|
438
|
-
* @summary Recursively validates all fields in a form control or form group, marking them as touched and dirty.
|
|
439
|
-
* Performs comprehensive validation including uniqueness checks for primary keys in FormArray scenarios.
|
|
440
|
-
* This method ensures all validation rules are applied and form state is properly updated.
|
|
441
|
-
*
|
|
442
|
-
* @param {AbstractControl} control - The control or form group to validate
|
|
443
|
-
* @param {string} [pk] - Optional primary key field name for uniqueness validation
|
|
444
|
-
* @param {string} [path] - The path to the control within the form for error reporting
|
|
445
|
-
* @return {boolean} True if all fields are valid, false otherwise
|
|
446
|
-
* @throws {Error} If no control is found at the specified path or if the control type is unknown
|
|
447
|
-
*
|
|
448
|
-
* @mermaid
|
|
449
|
-
* sequenceDiagram
|
|
450
|
-
* participant C as Component
|
|
451
|
-
* participant NFS as NgxFormService
|
|
452
|
-
* participant FC as FormControl
|
|
453
|
-
* participant FG as FormGroup
|
|
454
|
-
* participant FA as FormArray
|
|
455
|
-
*
|
|
456
|
-
* C->>NFS: validateFields(control, pk?, path?)
|
|
457
|
-
* alt Control is FormControl
|
|
458
|
-
* NFS->>FC: markAsTouched()
|
|
459
|
-
* NFS->>FC: markAsDirty()
|
|
460
|
-
* NFS->>FC: updateValueAndValidity()
|
|
461
|
-
* alt Is in FormArray group
|
|
462
|
-
* NFS->>NFS: Check uniqueness in group
|
|
463
|
-
* alt Not unique
|
|
464
|
-
* NFS->>FC: setErrors({notUnique: true})
|
|
465
|
-
* end
|
|
466
|
-
* end
|
|
467
|
-
* NFS-->>C: Return control.valid
|
|
468
|
-
* else Control is FormGroup
|
|
469
|
-
* loop For each child control
|
|
470
|
-
* NFS->>NFS: Recursive validateFields(child)
|
|
471
|
-
* end
|
|
472
|
-
* NFS-->>C: Return allValid
|
|
473
|
-
* else Control is FormArray
|
|
474
|
-
* loop For each array control
|
|
475
|
-
* NFS->>NFS: Recursive validateFields(child)
|
|
476
|
-
* end
|
|
477
|
-
* NFS-->>C: Return allValid
|
|
478
|
-
* else Unknown control type
|
|
479
|
-
* NFS-->>C: Throw Error
|
|
480
|
-
* end
|
|
481
|
-
*
|
|
482
|
-
* @static
|
|
483
|
-
* @memberOf NgxFormService
|
|
484
|
-
*/
|
|
485
|
-
static validateFields(control: AbstractControl, pk?: string, path?: string): boolean;
|
|
486
|
-
/**
|
|
487
|
-
* @description Generates validators from component properties.
|
|
488
|
-
* @summary Creates an array of ValidatorFn based on the supported validation keys in the component properties.
|
|
489
|
-
* @param {FieldProperties} props - The component properties.
|
|
490
|
-
* @return {ValidatorFn[]} An array of validator functions.
|
|
491
|
-
*/
|
|
492
|
-
private static validatorsFromProps;
|
|
493
|
-
/**
|
|
494
|
-
* @description Creates a FormControl from component properties.
|
|
495
|
-
* @summary Generates a FormControl with validators and initial configuration based on the provided
|
|
496
|
-
* component properties. Handles different input types, sets initial values, and configures
|
|
497
|
-
* validation rules and update modes.
|
|
498
|
-
*
|
|
499
|
-
* @param {FieldProperties} props - The component properties defining the control configuration
|
|
500
|
-
* @param {FieldUpdateMode} [updateMode='change'] - The update mode for the control ('change', 'blur', 'submit')
|
|
501
|
-
* @return {FormControl} The created FormControl with proper configuration and validators
|
|
502
|
-
*
|
|
503
|
-
* @mermaid
|
|
504
|
-
* sequenceDiagram
|
|
505
|
-
* participant C as Component
|
|
506
|
-
* participant NFS as NgxFormService
|
|
507
|
-
* participant VF as ValidatorFactory
|
|
508
|
-
* participant AF as Angular Forms
|
|
509
|
-
*
|
|
510
|
-
* C->>NFS: fromProps(props, updateMode?)
|
|
511
|
-
* NFS->>NFS: validatorsFromProps(props)
|
|
512
|
-
* NFS->>VF: Create validators from props
|
|
513
|
-
* VF-->>NFS: Return validator array
|
|
514
|
-
* NFS->>NFS: Compose validators
|
|
515
|
-
* alt props.value exists and not checkbox
|
|
516
|
-
* alt props.type is DATE
|
|
517
|
-
* NFS->>NFS: Validate date format
|
|
518
|
-
* end
|
|
519
|
-
* NFS->>NFS: Set initial value
|
|
520
|
-
* end
|
|
521
|
-
* NFS->>AF: new FormControl(config)
|
|
522
|
-
* AF-->>NFS: Return FormControl
|
|
523
|
-
* NFS-->>C: Return configured FormControl
|
|
524
|
-
*
|
|
525
|
-
* @static
|
|
526
|
-
* @memberOf NgxFormService
|
|
527
|
-
*/
|
|
528
|
-
static fromProps(props: FieldProperties, updateMode?: FieldUpdateMode): FormControl;
|
|
529
|
-
/**
|
|
530
|
-
* @description Retrieves properties from a FormControl, FormArray, or FormGroup.
|
|
531
|
-
* @summary Gets the FieldProperties associated with a form control from the internal WeakMap.
|
|
532
|
-
* This method provides access to the original component properties that were used to create
|
|
533
|
-
* the control, enabling validation, rendering, and behavior configuration.
|
|
534
|
-
*
|
|
535
|
-
* @param {FormControl | FormArray | FormGroup} control - The form control to get properties for
|
|
536
|
-
* @return {FieldProperties} The properties associated with the control, or empty object if not found
|
|
537
|
-
*
|
|
538
|
-
* @static
|
|
539
|
-
* @memberOf NgxFormService
|
|
540
|
-
*/
|
|
541
|
-
static getPropsFromControl(control: FormControl | FormArray | FormGroup): FieldProperties;
|
|
542
|
-
/**
|
|
543
|
-
* @description Finds a parent element with a specific tag in the DOM tree.
|
|
544
|
-
* @summary Traverses up the DOM tree to find the nearest parent element with the specified tag name.
|
|
545
|
-
* This is useful for finding container elements or specific parent components in the DOM hierarchy.
|
|
546
|
-
* The search is case-insensitive for tag name matching.
|
|
547
|
-
*
|
|
548
|
-
* @param {HTMLElement} el - The starting element to traverse from
|
|
549
|
-
* @param {string} tag - The tag name to search for (case-insensitive)
|
|
550
|
-
* @return {HTMLElement} The found parent element with the specified tag
|
|
551
|
-
* @throws {Error} If no parent with the specified tag is found in the DOM tree
|
|
552
|
-
*
|
|
553
|
-
* @mermaid
|
|
554
|
-
* sequenceDiagram
|
|
555
|
-
* participant C as Component
|
|
556
|
-
* participant NFS as NgxFormService
|
|
557
|
-
* participant DOM as DOM Tree
|
|
558
|
-
*
|
|
559
|
-
* C->>NFS: getParentEl(element, tagName)
|
|
560
|
-
* loop Traverse up DOM tree
|
|
561
|
-
* NFS->>DOM: Get parentElement
|
|
562
|
-
* DOM-->>NFS: Return parent or null
|
|
563
|
-
* alt Parent exists and tag matches
|
|
564
|
-
* NFS-->>C: Return parent element
|
|
565
|
-
* else Parent is null
|
|
566
|
-
* NFS-->>C: Throw Error
|
|
567
|
-
* end
|
|
568
|
-
* end
|
|
569
|
-
*
|
|
570
|
-
* @static
|
|
571
|
-
* @memberOf NgxFormService
|
|
572
|
-
*/
|
|
573
|
-
static getParentEl(el: HTMLElement, tag: string): HTMLElement;
|
|
574
|
-
/**
|
|
575
|
-
* @description Registers a control with its properties in the internal WeakMap.
|
|
576
|
-
* @summary Associates a form control with its component properties for later retrieval.
|
|
577
|
-
* This enables the service to maintain metadata about controls without creating memory leaks,
|
|
578
|
-
* as WeakMap automatically cleans up references when controls are garbage collected.
|
|
579
|
-
*
|
|
580
|
-
* @param {AbstractControl} control - The control to register (FormControl, FormGroup, or FormArray)
|
|
581
|
-
* @param {FieldProperties} props - The properties to associate with the control
|
|
582
|
-
* @return {void}
|
|
583
|
-
*
|
|
584
|
-
* @static
|
|
585
|
-
* @memberOf NgxFormService
|
|
586
|
-
*/
|
|
587
|
-
static register(control: AbstractControl, props: FieldProperties): void;
|
|
588
|
-
/**
|
|
589
|
-
* @description Unregisters a control.
|
|
590
|
-
* @summary Removes a control and its associated properties from the internal WeakMap.
|
|
591
|
-
* @param {AbstractControl} control - The control to unregister.
|
|
592
|
-
* @return {boolean} True if the control was successfully unregistered, false otherwise.
|
|
593
|
-
*/
|
|
594
|
-
static unregister(control: AbstractControl): boolean;
|
|
595
|
-
/**
|
|
596
|
-
* @description Resets a form group.
|
|
597
|
-
* @summary Recursively resets all controls in a form group, clearing values, errors, and marking them as pristine and untouched.
|
|
598
|
-
* @param {FormGroup} formGroup - The form group to reset.
|
|
599
|
-
*/
|
|
600
|
-
static reset(formGroup: FormGroup | FormControl): void;
|
|
601
|
-
}
|