@decaf-ts/for-angular 0.0.16 → 0.0.18

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 (65) hide show
  1. package/assets/i18n/en.json +9 -69
  2. package/assets/i18n/pt.json +80 -0
  3. package/assets/icons/icon-128.webp +0 -0
  4. package/assets/icons/icon-192.webp +0 -0
  5. package/assets/icons/icon-256.webp +0 -0
  6. package/assets/icons/icon-48.webp +0 -0
  7. package/assets/icons/icon-512.webp +0 -0
  8. package/assets/icons/icon-72.webp +0 -0
  9. package/assets/icons/icon-96.webp +0 -0
  10. package/assets/images/apple-touch-icon.png +0 -0
  11. package/assets/images/favicon.png +0 -0
  12. package/assets/images/favicon.svg +29 -0
  13. package/components/component-renderer/component-renderer.component.d.ts +5 -4
  14. package/components/crud-field/crud-field.component.d.ts +186 -22
  15. package/components/crud-form/crud-form.component.d.ts +194 -8
  16. package/components/empty-state/empty-state.component.d.ts +9 -10
  17. package/components/fieldset/fieldset.component.d.ts +383 -36
  18. package/components/filter/filter.component.d.ts +11 -2
  19. package/components/list/list.component.d.ts +1 -1
  20. package/components/list-item/list-item.component.d.ts +2 -2
  21. package/components/model-renderer/model-renderer.component.d.ts +1 -5
  22. package/directives/collapsable.directive.d.ts +1 -0
  23. package/engine/NgxBaseComponent.d.ts +43 -43
  24. package/engine/NgxCrudFormField.d.ts +7 -3
  25. package/engine/NgxFormService.d.ts +113 -12
  26. package/engine/NgxRenderingEngine.d.ts +178 -25
  27. package/engine/constants.d.ts +11 -6
  28. package/engine/decorators.d.ts +2 -2
  29. package/engine/index.d.ts +4 -2
  30. package/engine/interfaces.d.ts +271 -0
  31. package/engine/types.d.ts +11 -206
  32. package/esm2022/components/component-renderer/component-renderer.component.mjs +13 -11
  33. package/esm2022/components/crud-field/crud-field.component.mjs +213 -8
  34. package/esm2022/components/crud-form/crud-form.component.mjs +133 -13
  35. package/esm2022/components/empty-state/empty-state.component.mjs +13 -12
  36. package/esm2022/components/fieldset/fieldset.component.mjs +485 -43
  37. package/esm2022/components/filter/filter.component.mjs +16 -6
  38. package/esm2022/components/layout/layout.component.mjs +3 -3
  39. package/esm2022/components/list/list.component.mjs +4 -5
  40. package/esm2022/components/list-item/list-item.component.mjs +10 -10
  41. package/esm2022/components/model-renderer/model-renderer.component.mjs +9 -8
  42. package/esm2022/components/pagination/pagination.component.mjs +7 -7
  43. package/esm2022/components/searchbar/searchbar.component.mjs +3 -3
  44. package/esm2022/directives/collapsable.directive.mjs +3 -2
  45. package/esm2022/engine/NgxBaseComponent.mjs +64 -63
  46. package/esm2022/engine/NgxCrudFormField.mjs +14 -4
  47. package/esm2022/engine/NgxFormService.mjs +239 -27
  48. package/esm2022/engine/NgxRenderingEngine.mjs +218 -46
  49. package/esm2022/engine/ValidatorFactory.mjs +6 -4
  50. package/esm2022/engine/constants.mjs +14 -9
  51. package/esm2022/engine/decorators.mjs +6 -6
  52. package/esm2022/engine/index.mjs +5 -3
  53. package/esm2022/engine/interfaces.mjs +4 -0
  54. package/esm2022/engine/types.mjs +1 -3
  55. package/esm2022/helpers/utils.mjs +53 -32
  56. package/esm2022/i18n/Loader.mjs +82 -0
  57. package/fesm2022/decaf-ts-for-angular.mjs +3030 -2097
  58. package/fesm2022/decaf-ts-for-angular.mjs.map +1 -1
  59. package/helpers/utils.d.ts +42 -16
  60. package/i18n/Loader.d.ts +48 -0
  61. package/package.json +11 -1
  62. package/engine/NgxRenderingEngine2.d.ts +0 -250
  63. package/esm2022/engine/NgxRenderingEngine2.mjs +0 -332
  64. package/esm2022/interfaces.mjs +0 -2
  65. package/interfaces.d.ts +0 -28
@@ -2,7 +2,7 @@ import { ElementRef, OnChanges, SimpleChanges, EventEmitter } from '@angular/cor
2
2
  import { KeyValue, RendererCustomEvent, StringOrBoolean } from './types';
3
3
  import { Model } from '@decaf-ts/decorator-validation';
4
4
  import { CrudOperations } from '@decaf-ts/db-decorators';
5
- import { NgxRenderingEngine2 } from './NgxRenderingEngine2';
5
+ import { NgxRenderingEngine } from './NgxRenderingEngine';
6
6
  import { Logger } from '@decaf-ts/logging';
7
7
  import { DecafRepository } from '../components/list/constants';
8
8
  import * as i0 from "@angular/core";
@@ -45,7 +45,7 @@ import * as i0 from "@angular/core";
45
45
  * participant App as Application
46
46
  * participant Comp as Component
47
47
  * participant Base as NgxBaseComponent
48
- * participant Engine as NgxRenderingEngine2
48
+ * participant Engine as NgxRenderingEngine
49
49
  *
50
50
  * App->>Comp: Create component
51
51
  * Comp->>Base: super(instance)
@@ -260,7 +260,7 @@ export declare abstract class NgxBaseComponent implements OnChanges {
260
260
  * @summary Stores the automatically derived locale based on the component's class name.
261
261
  * This is determined during component initialization and serves as a fallback when no
262
262
  * explicit locale is provided via the locale input property. The derivation is handled
263
- * by the getLocaleFromClassName utility function, which extracts a locale identifier
263
+ * by the getLocaleContext utility function, which extracts a locale identifier
264
264
  * from the component's class name.
265
265
  *
266
266
  * @type {string}
@@ -302,13 +302,13 @@ export declare abstract class NgxBaseComponent implements OnChanges {
302
302
  listenEvent: EventEmitter<RendererCustomEvent>;
303
303
  /**
304
304
  * @description Reference to the rendering engine instance
305
- * @summary Provides access to the NgxRenderingEngine2 singleton instance,
305
+ * @summary Provides access to the NgxRenderingEngine singleton instance,
306
306
  * which handles the rendering of components based on model definitions.
307
307
  * This engine is used to extract decorator metadata and render child components.
308
308
  *
309
- * @type {NgxRenderingEngine2}
309
+ * @type {NgxRenderingEngine}
310
310
  */
311
- renderingEngine: NgxRenderingEngine2;
311
+ renderingEngine: NgxRenderingEngine;
312
312
  /**
313
313
  * @description Logger instance for the component.
314
314
  * @summary Provides logging capabilities for the component, allowing for consistent
@@ -349,7 +349,7 @@ export declare abstract class NgxBaseComponent implements OnChanges {
349
349
  * A->>C: new Component(instance)
350
350
  * C->>B: super(instance)
351
351
  * B->>B: Set componentName = instance
352
- * B->>U: getLocaleFromClassName(instance)
352
+ * B->>U: getLocaleContext(instance)
353
353
  * U-->>B: Return derived locale
354
354
  * B->>B: Set componentLocale
355
355
  * B->>L: getLogger(this)
@@ -374,42 +374,6 @@ export declare abstract class NgxBaseComponent implements OnChanges {
374
374
  * @memberOf NgxBaseComponent
375
375
  */
376
376
  protected get repository(): DecafRepository<Model>;
377
- /**
378
- * @description Parses and applies properties from the props object to the component instance.
379
- * @summary This method iterates through the properties of the provided instance object
380
- * and applies any matching properties from the component's props configuration to the
381
- * component instance. This allows for dynamic property assignment based on configuration
382
- * stored in the props object, enabling flexible component customization without requiring
383
- * explicit property binding for every possible configuration option.
384
- *
385
- * The method performs a safe property assignment by checking if each key from the instance
386
- * exists in the props object before applying it. This prevents accidental property
387
- * overwriting and ensures only intended properties are modified.
388
- *
389
- * @param {KeyValue} instance - The component instance object to process
390
- * @return {void}
391
- *
392
- * @mermaid
393
- * sequenceDiagram
394
- * participant C as Component
395
- * participant B as NgxBaseComponent
396
- * participant P as Props Object
397
- *
398
- * C->>B: parseProps(instance)
399
- * B->>B: Get Object.keys(instance)
400
- * loop For each key in instance
401
- * B->>P: Check if key exists in this.props
402
- * alt Key exists in props
403
- * B->>B: Set this[key] = this.props[key]
404
- * else Key not in props
405
- * Note over B: Skip this key
406
- * end
407
- * end
408
- *
409
- * @protected
410
- * @memberOf NgxBaseComponent
411
- */
412
- protected parseProps(instance: KeyValue): void;
413
377
  /**
414
378
  * @description Handles changes to component inputs
415
379
  * @summary This Angular lifecycle hook is called when input properties change.
@@ -536,6 +500,42 @@ export declare abstract class NgxBaseComponent implements OnChanges {
536
500
  * @memberOf NgxBaseComponent
537
501
  */
538
502
  trackItemFn(index: number, item: KeyValue | string | number): string | number;
503
+ /**
504
+ * @description Parses and applies properties from the props object to the component instance.
505
+ * @summary This method iterates through the properties of the provided instance object
506
+ * and applies any matching properties from the component's props configuration to the
507
+ * component instance. This allows for dynamic property assignment based on configuration
508
+ * stored in the props object, enabling flexible component customization without requiring
509
+ * explicit property binding for every possible configuration option.
510
+ *
511
+ * The method performs a safe property assignment by checking if each key from the instance
512
+ * exists in the props object before applying it. This prevents accidental property
513
+ * overwriting and ensures only intended properties are modified.
514
+ *
515
+ * @param {KeyValue} instance - The component instance object to process
516
+ * @return {void}
517
+ *
518
+ * @mermaid
519
+ * sequenceDiagram
520
+ * participant C as Component
521
+ * participant B as NgxBaseComponent
522
+ * participant P as Props Object
523
+ *
524
+ * C->>B: parseProps(instance)
525
+ * B->>B: Get Object.keys(instance)
526
+ * loop For each key in instance
527
+ * B->>P: Check if key exists in this.props
528
+ * alt Key exists in props
529
+ * B->>B: Set this[key] = this.props[key]
530
+ * else Key not in props
531
+ * Note over B: Skip this key
532
+ * end
533
+ * end
534
+ *
535
+ * @protected
536
+ * @memberOf NgxBaseComponent
537
+ */
538
+ protected parseProps(instance: KeyValue): void;
539
539
  static ɵfac: i0.ɵɵFactoryDeclaration<NgxBaseComponent, never>;
540
540
  static ɵcmp: i0.ɵɵComponentDeclaration<NgxBaseComponent, "ng-component", never, { "rendererId": { "alias": "rendererId"; "required": false; }; "model": { "alias": "model"; "required": false; }; "props": { "alias": "props"; "required": false; }; "item": { "alias": "item"; "required": false; }; "pk": { "alias": "pk"; "required": false; }; "route": { "alias": "route"; "required": false; }; "operations": { "alias": "operations"; "required": false; }; "uid": { "alias": "uid"; "required": false; }; "mapper": { "alias": "mapper"; "required": false; }; "locale": { "alias": "locale"; "required": false; }; "translatable": { "alias": "translatable"; "required": false; }; "className": { "alias": "className"; "required": false; }; "mode": { "alias": "mode"; "required": false; }; "renderChild": { "alias": "renderChild"; "required": false; }; }, { "listenEvent": "listenEvent"; }, never, never, true, never>;
541
541
  }
@@ -1,8 +1,9 @@
1
- import { FieldProperties } from '@decaf-ts/ui-decorators';
1
+ import { CrudOperationKeys, FieldProperties } from '@decaf-ts/ui-decorators';
2
2
  import { PossibleInputTypes } from './types';
3
3
  import { CrudOperations } from '@decaf-ts/db-decorators';
4
4
  import { ControlValueAccessor, FormControl, FormGroup } from '@angular/forms';
5
5
  import { ElementRef } from '@angular/core';
6
+ import { TranslateService } from '@ngx-translate/core';
6
7
  /**
7
8
  * @class NgxCrudFormField
8
9
  * @implements {FieldProperties}
@@ -33,8 +34,9 @@ export declare abstract class NgxCrudFormField implements ControlValueAccessor,
33
34
  childOf?: string;
34
35
  type: PossibleInputTypes;
35
36
  disabled?: boolean;
37
+ uid?: string;
36
38
  format?: string;
37
- hidden?: boolean;
39
+ hidden?: boolean | CrudOperationKeys[];
38
40
  max?: number | Date;
39
41
  maxlength?: number;
40
42
  min?: number | Date;
@@ -50,7 +52,9 @@ export declare abstract class NgxCrudFormField implements ControlValueAccessor,
50
52
  greaterThan?: string;
51
53
  greaterThanOrEqual?: string;
52
54
  value: string | number | Date;
53
- private translateService;
55
+ multiple: boolean;
56
+ protected translateService: TranslateService;
57
+ private validationErrorEventDispateched;
54
58
  /**
55
59
  * @summary Parent HTML element
56
60
  * @description Reference to the parent HTML element of the field
@@ -1,6 +1,8 @@
1
1
  import { FieldProperties } from '@decaf-ts/ui-decorators';
2
- import { ComponentConfig, FieldUpdateMode } from './types';
3
- import { AbstractControl, FormControl, FormGroup } from '@angular/forms';
2
+ import { FieldUpdateMode } from './types';
3
+ import { IComponentConfig } from './interfaces';
4
+ import { AbstractControl, FormArray, FormControl, FormGroup } from '@angular/forms';
5
+ import { OperationKeys } from '@decaf-ts/db-decorators';
4
6
  /**
5
7
  * @description Service for managing Angular forms and form controls.
6
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.
@@ -40,7 +42,27 @@ import { AbstractControl, FormControl, FormGroup } from '@angular/forms';
40
42
  * NFS-->>C: Return form data
41
43
  */
42
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
+ */
43
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
+ */
44
66
  private static formRegistry;
45
67
  /**
46
68
  * @description Adds a form to the registry.
@@ -65,10 +87,89 @@ export declare class NgxFormService {
65
87
  */
66
88
  private static resolveParentGroup;
67
89
  /**
68
- * @description Adds a form control to a form group.
69
- * @summary Creates and adds a form control to the specified form group based on the provided component properties.
70
- * @param {FormGroup} formGroup - The form group to add the control to.
71
- * @param {ComponentInput} componentProps - The properties of the component to create the control from.
90
+ * @description Retrieves component properties from a FormGroup or FormArray.
91
+ * @summary Extracts component properties stored in the form group metadata. If a FormGroup is provided
92
+ * and groupArrayName is specified, it will look for the FormArray within the form structure.
93
+ *
94
+ * @param {FormGroup | FormArray} formGroup - The form group or form array to extract properties from
95
+ * @param {string} [key] - Optional key to retrieve a specific property
96
+ * @param {string} [groupArrayName] - Optional name of the group array if formGroup is not a FormArray
97
+ * @return {Partial<FieldProperties>} The component properties or a specific property if key is provided
98
+ *
99
+ * @static
100
+ * @memberOf NgxFormService
101
+ */
102
+ static getComponentPropsFromGroupArray(formGroup: FormGroup | FormArray, key?: string, groupArrayName?: string | undefined): Partial<FieldProperties>;
103
+ /**
104
+ * @description Adds a new group to a parent FormArray.
105
+ * @summary Creates and adds a new FormGroup to the specified parent FormArray based on the
106
+ * component properties stored in the parent's metadata. This is used for dynamic form arrays
107
+ * where new groups need to be added at runtime.
108
+ *
109
+ * @param {FormGroup} formGroup - The root form group containing the parent FormArray
110
+ * @param {string} parentName - The name of the parent FormArray to add the group to
111
+ * @param {number} [index=1] - The index position where the new group should be added
112
+ * @return {FormGroup} The newly created and added FormGroup
113
+ *
114
+ * @static
115
+ * @memberOf NgxFormService
116
+ */
117
+ static addGroupToParent(formGroup: FormGroup, parentName: string, index?: number): FormGroup;
118
+ /**
119
+ * @description Retrieves a FormGroup from a parent FormArray at the specified index.
120
+ * @summary Gets a FormGroup from the specified parent FormArray. If the group doesn't exist
121
+ * at the given index, it will create a new one using addGroupToParent.
122
+ *
123
+ * @param {FormGroup} formGroup - The root form group containing the parent FormArray
124
+ * @param {string} parentName - The name of the parent FormArray to retrieve the group from
125
+ * @param {number} [index=1] - The index of the group to retrieve
126
+ * @return {FormGroup} The FormGroup at the specified index
127
+ *
128
+ * @static
129
+ * @memberOf NgxFormService
130
+ */
131
+ static getGroupFromParent(formGroup: FormGroup, parentName: string, index?: number): FormGroup;
132
+ /**
133
+ * @description Checks if a value is unique within a FormArray group.
134
+ * @summary Validates that the primary key value in a FormGroup is unique among all groups
135
+ * in the parent FormArray. The uniqueness check behavior differs based on the operation type.
136
+ *
137
+ * @param {FormGroup} formGroup - The FormGroup to check for uniqueness
138
+ * @param {number} index - The index of the current group within the FormArray
139
+ * @param {OperationKeys} [operation=OperationKeys.CREATE] - The type of operation being performed
140
+ * @return {boolean} True if the value is unique, false otherwise
141
+ *
142
+ * @static
143
+ * @memberOf NgxFormService
144
+ */
145
+ static isUniqueOnGroup(formGroup: FormGroup, index: number, operation?: OperationKeys): boolean;
146
+ /**
147
+ * @description Enables all controls within a FormGroup or FormArray.
148
+ * @summary Recursively enables all form controls within the provided FormGroup or FormArray.
149
+ * This is useful for making all controls interactive after they have been disabled.
150
+ *
151
+ * @param {FormArray | FormGroup} formGroup - The FormGroup or FormArray to enable all controls for
152
+ * @return {void}
153
+ *
154
+ * @static
155
+ * @memberOf NgxFormService
156
+ */
157
+ static enableAllGroupControls(formGroup: FormArray | FormGroup): void;
158
+ /**
159
+ * @description Adds a form control to a form group based on component properties.
160
+ * @summary Creates and configures a FormControl within the specified FormGroup using the provided
161
+ * component properties. Handles nested paths, multiple controls (FormArrays), and control registration.
162
+ * This method supports complex form structures with nested groups and arrays.
163
+ *
164
+ * @param {FormGroup} formGroup - The form group to add the control to
165
+ * @param {IComponentInput} componentProps - The component properties defining the control configuration
166
+ * @param {KeyValue} [parentProps={}] - Properties from the parent component for context
167
+ * @param {number} [index=0] - The index for multiple controls in FormArrays
168
+ * @return {void}
169
+ *
170
+ * @private
171
+ * @static
172
+ * @memberOf NgxFormService
72
173
  */
73
174
  private static addFormControl;
74
175
  /**
@@ -84,11 +185,11 @@ export declare class NgxFormService {
84
185
  * @description Creates a form from component configurations.
85
186
  * @summary Generates a FormGroup based on an array of component configurations and optionally registers it.
86
187
  * @param {string} id - The unique identifier for the form.
87
- * @param {ComponentConfig[]} components - An array of component configurations.
188
+ * @param {IComponentConfig[]} components - An array of component configurations.
88
189
  * @param {boolean} [registry=false] - Whether to register the created form.
89
190
  * @return {FormGroup} The created FormGroup.
90
191
  */
91
- static createFormFromComponents(id: string, components: ComponentConfig[], registry?: boolean): FormGroup;
192
+ static createFormFromComponents(id: string, components: IComponentConfig[], registry?: boolean): FormGroup;
92
193
  /**
93
194
  * @description Adds a control to a form based on component properties.
94
195
  * @summary Creates and adds a form control to a form (existing or new) based on the provided component properties.
@@ -96,7 +197,7 @@ export declare class NgxFormService {
96
197
  * @param {FieldProperties} componentProperties - The properties of the component to create the control from.
97
198
  * @return {AbstractControl} The form or created control.
98
199
  */
99
- static addControlFromProps(id: string, componentProperties: FieldProperties): AbstractControl;
200
+ static addControlFromProps(id: string, componentProperties: FieldProperties, parentProps?: FieldProperties): AbstractControl;
100
201
  /**
101
202
  * @description Retrieves form data from a FormGroup.
102
203
  * @summary Extracts and processes the data from a FormGroup, handling different input types and nested form groups.
@@ -112,7 +213,7 @@ export declare class NgxFormService {
112
213
  * @return {boolean} True if all fields are valid, false otherwise.
113
214
  * @throws {Error} If no control is found at the specified path or if the control type is unknown.
114
215
  */
115
- static validateFields(control: AbstractControl, path?: string): boolean;
216
+ static validateFields(control: AbstractControl, pk?: string, path?: string): boolean;
116
217
  /**
117
218
  * @description Generates validators from component properties.
118
219
  * @summary Creates an array of ValidatorFn based on the supported validation keys in the component properties.
@@ -134,7 +235,7 @@ export declare class NgxFormService {
134
235
  * @param {FormControl} control - The FormControl to get properties for.
135
236
  * @return {FieldProperties} The properties associated with the control.
136
237
  */
137
- static getPropsFromControl(control: FormControl): FieldProperties;
238
+ static getPropsFromControl(control: FormControl | FormArray | FormGroup): FieldProperties;
138
239
  /**
139
240
  * @description Finds a parent element with a specific tag.
140
241
  * @summary Traverses up the DOM tree to find the nearest parent element with the specified tag.
@@ -163,5 +264,5 @@ export declare class NgxFormService {
163
264
  * @summary Recursively resets all controls in a form group, clearing values, errors, and marking them as pristine and untouched.
164
265
  * @param {FormGroup} formGroup - The form group to reset.
165
266
  */
166
- static reset(formGroup: FormGroup): void;
267
+ static reset(formGroup: FormGroup | FormControl): void;
167
268
  }
@@ -1,71 +1,182 @@
1
- import { RenderingEngine } from '@decaf-ts/ui-decorators';
2
- import { AngularDynamicOutput, AngularFieldDefinition } from './types';
1
+ import { FieldDefinition, RenderingEngine } from '@decaf-ts/ui-decorators';
2
+ import { AngularFieldDefinition, KeyValue } from './types';
3
+ import { AngularDynamicOutput } from './interfaces';
3
4
  import { Constructor, Model } from '@decaf-ts/decorator-validation';
4
- import { Injector, TemplateRef, ViewContainerRef } from '@angular/core';
5
+ import { ComponentMirror, ComponentRef, Injector, TemplateRef, Type, ViewContainerRef } from '@angular/core';
5
6
  /**
6
- * @description Angular implementation of the RenderingEngine
7
- * @summary This class extends the base RenderingEngine to provide Angular-specific rendering capabilities.
8
- * It handles the conversion of field definitions to Angular components and manages component registration.
7
+ * @description Angular implementation of the RenderingEngine with enhanced features
8
+ * @summary This class extends the base RenderingEngine to provide Angular-specific rendering capabilities
9
+ * with additional features compared to NgxRenderingEngine. It handles the conversion of field definitions
10
+ * to Angular components, manages component registration, and provides utilities for component creation
11
+ * and input handling. This implementation uses Angular's newer component APIs.
12
+ *
9
13
  * @template AngularFieldDefinition - Type for Angular-specific field definitions
10
14
  * @template AngularDynamicOutput - Type for Angular-specific component output
11
- * @param {Injector} injector - Angular injector for dependency injection
12
- * @param {ViewContainerRef} vcr - View container reference for component creation
13
- * @param {TemplateRef<any>} tpl - Template reference for content projection
15
+ *
14
16
  * @class NgxRenderingEngine
15
17
  * @example
16
18
  * ```typescript
17
- * const engine = new NgxRenderingEngine();
19
+ * const engine = NgxRenderingEngine.get();
18
20
  * engine.initialize();
19
21
  * const output = engine.render(myModel, {}, viewContainerRef, injector, templateRef);
20
22
  * ```
23
+ *
21
24
  * @mermaid
22
25
  * sequenceDiagram
23
26
  * participant Client
24
27
  * participant Engine as NgxRenderingEngine
25
28
  * participant Components as RegisteredComponents
26
29
  *
27
- * Client->>Engine: new NgxRenderingEngine()
30
+ * Client->>Engine: get()
28
31
  * Client->>Engine: initialize()
29
32
  * Client->>Engine: render(model, props, vcr, injector, tpl)
30
33
  * Engine->>Engine: toFieldDefinition(model, props)
31
34
  * Engine->>Engine: fromFieldDefinition(fieldDef, vcr, injector, tpl)
32
35
  * Engine->>Components: components(fieldDef.tag)
33
36
  * Components-->>Engine: component constructor
34
- * Engine->>Client: return AngularDynamicOutput
37
+ * Engine->>Engine: createComponent(component, inputs, metadata, vcr, injector, template)
38
+ * Engine-->>Client: return AngularDynamicOutput
35
39
  */
36
40
  export declare class NgxRenderingEngine extends RenderingEngine<AngularFieldDefinition, AngularDynamicOutput> {
41
+ /**
42
+ * @description Registry of components available for rendering
43
+ * @summary Static registry that stores all registered components indexed by their selector name.
44
+ * Each component entry contains a constructor reference that can be used to instantiate
45
+ * the component during the rendering process. This registry is shared across all instances
46
+ * of the rendering engine and is populated through the registerComponent method.
47
+ *
48
+ * @private
49
+ * @static
50
+ * @type {Record<string, { constructor: Constructor<unknown> }>}
51
+ */
37
52
  private static _components;
53
+ /**
54
+ * @description Currently active model being rendered
55
+ * @summary Stores a reference to the model instance that is currently being processed
56
+ * by the rendering engine. This property is set during the render method execution
57
+ * and is used throughout the rendering lifecycle to access model data and metadata.
58
+ * The definite assignment assertion (!) is used because this property is always
59
+ * initialized before use within the render method.
60
+ *
61
+ * @private
62
+ * @type {Model}
63
+ */
64
+ private _model;
65
+ /**
66
+ * @description Current operation context for component visibility control
67
+ * @summary Static property that stores the current operation being performed,
68
+ * which is used to determine component visibility through the 'hidden' property.
69
+ * Components can specify operations where they should be hidden, and this property
70
+ * provides the context for those visibility checks. The value is typically extracted
71
+ * from the global properties during the rendering process.
72
+ *
73
+ * @private
74
+ * @static
75
+ * @type {string | undefined}
76
+ */
77
+ private static _operation;
78
+ /**
79
+ * @description Reference to the currently active component instance
80
+ * @summary Static property that maintains a reference to the most recently created
81
+ * component instance. This is used internally for component lifecycle management
82
+ * and can be cleared through the destroy method. The reference allows access to
83
+ * the active component instance for operations that need to interact with the
84
+ * currently rendered component.
85
+ *
86
+ * @private
87
+ * @static
88
+ * @type {Type<unknown> | undefined}
89
+ */
90
+ private static _instance;
91
+ /**
92
+ * @description Constructs a new NgxRenderingEngine instance
93
+ * @summary Initializes a new instance of the Angular rendering engine by calling the parent
94
+ * constructor with the 'angular' engine type identifier. This constructor sets up the base
95
+ * rendering engine functionality with Angular-specific configurations and prepares the
96
+ * instance for component registration and rendering operations.
97
+ *
98
+ * @constructor
99
+ */
38
100
  constructor();
39
101
  /**
40
102
  * @description Converts a field definition to an Angular component output
41
103
  * @summary This private method takes a field definition and creates the corresponding Angular component.
42
104
  * It handles component instantiation, input property mapping, and child component rendering.
105
+ * The method validates input properties against the component's metadata and processes
106
+ * child components recursively.
107
+ *
43
108
  * @param {FieldDefinition<AngularFieldDefinition>} fieldDef - The field definition to convert
44
109
  * @param {ViewContainerRef} vcr - The view container reference for component creation
45
110
  * @param {Injector} injector - The Angular injector for dependency injection
46
111
  * @param {TemplateRef<any>} tpl - The template reference for content projection
112
+ * @param {string} registryFormId - Form identifier for the component renderer
47
113
  * @return {AngularDynamicOutput} The Angular component output with component reference and inputs
114
+ *
48
115
  * @mermaid
49
116
  * sequenceDiagram
50
117
  * participant Method as fromFieldDefinition
51
118
  * participant Components as NgxRenderingEngine.components
52
119
  * participant Angular as Angular Core
120
+ * participant Process as processChild
53
121
  *
54
122
  * Method->>Components: components(fieldDef.tag)
55
123
  * Components-->>Method: component constructor
56
124
  * Method->>Angular: reflectComponentType(component)
57
125
  * Angular-->>Method: componentMetadata
58
- * Method->>Method: Check input properties
126
+ * Method->>Method: Validate input properties
59
127
  * Method->>Method: Create result object
60
- * Method->>Method: Process children if any
128
+ * alt Has children
129
+ * Method->>Process: Process children recursively
130
+ * Process->>Method: Return processed children
131
+ * Method->>Angular: Create embedded view
132
+ * Method->>Method: Create component instance
133
+ * end
61
134
  * Method-->>Caller: return AngularDynamicOutput
62
135
  */
63
136
  private fromFieldDefinition;
137
+ /**
138
+ * @description Creates an Angular component instance
139
+ * @summary This static utility method creates an Angular component instance with the specified
140
+ * inputs and template. It uses Angular's component creation API to instantiate the component
141
+ * and then sets the input properties using the provided metadata.
142
+ *
143
+ * @param {Type<unknown>} component - The component type to create
144
+ * @param {KeyValue} [inputs={}] - The input properties to set on the component
145
+ * @param {ComponentMirror<unknown>} metadata - The component metadata for input validation
146
+ * @param {ViewContainerRef} vcr - The view container reference for component creation
147
+ * @param {Injector} injector - The Angular injector for dependency injection
148
+ * @param {Node[]} [template=[]] - The template nodes to project into the component
149
+ * @return {ComponentRef<unknown>} The created component reference
150
+ */
151
+ static createComponent(component: Type<unknown>, inputs: KeyValue | undefined, metadata: ComponentMirror<unknown>, vcr: ViewContainerRef, injector: Injector, template?: Node[]): ComponentRef<unknown>;
152
+ /**
153
+ * @description Extracts decorator metadata from a model
154
+ * @summary This method provides access to the field definition generated from a model's
155
+ * decorators. It's a convenience wrapper around the toFieldDefinition method that
156
+ * converts a model to a field definition based on its decorators and the provided
157
+ * global properties.
158
+ *
159
+ * @param {Model} model - The model to extract decorators from
160
+ * @param {Record<string, unknown>} globalProps - Global properties to include in the field definition
161
+ * @return {FieldDefinition<AngularFieldDefinition>} The field definition generated from the model
162
+ */
163
+ getDecorators(model: Model, globalProps: Record<string, unknown>): FieldDefinition<AngularFieldDefinition>;
164
+ /**
165
+ * @description Destroys the current engine instance
166
+ * @summary This static method clears the current instance reference, effectively
167
+ * destroying the singleton instance of the rendering engine. This can be used
168
+ * to reset the engine state or to prepare for a new instance creation.
169
+ *
170
+ * @return {Promise<void>} A promise that resolves when the instance is destroyed
171
+ */
172
+ static destroy(): Promise<void>;
64
173
  /**
65
174
  * @description Renders a model into an Angular component output
66
175
  * @summary This method takes a model and converts it to an Angular component output.
67
- * It first converts the model to a field definition using the base RenderingEngine's
68
- * toFieldDefinition method, then converts that field definition to an Angular component output.
176
+ * It first stores a reference to the model, then converts it to a field definition
177
+ * using the base RenderingEngine's toFieldDefinition method, and finally converts
178
+ * that field definition to an Angular component output using fromFieldDefinition.
179
+ *
69
180
  * @template M - Type extending Model
70
181
  * @param {M} model - The model to render
71
182
  * @param {Record<string, unknown>} globalProps - Global properties to pass to the component
@@ -73,6 +184,7 @@ export declare class NgxRenderingEngine extends RenderingEngine<AngularFieldDefi
73
184
  * @param {Injector} injector - The Angular injector for dependency injection
74
185
  * @param {TemplateRef<any>} tpl - The template reference for content projection
75
186
  * @return {AngularDynamicOutput} The Angular component output with component reference and inputs
187
+ *
76
188
  * @mermaid
77
189
  * sequenceDiagram
78
190
  * participant Client as Client Code
@@ -81,6 +193,7 @@ export declare class NgxRenderingEngine extends RenderingEngine<AngularFieldDefi
81
193
  * participant FromField as fromFieldDefinition
82
194
  *
83
195
  * Client->>Render: render(model, globalProps, vcr, injector, tpl)
196
+ * Render->>Render: Store model reference
84
197
  * Render->>ToField: toFieldDefinition(model, globalProps)
85
198
  * ToField-->>Render: fieldDef
86
199
  * Render->>FromField: fromFieldDefinition(fieldDef, vcr, injector, tpl)
@@ -91,14 +204,19 @@ export declare class NgxRenderingEngine extends RenderingEngine<AngularFieldDefi
91
204
  /**
92
205
  * @description Initializes the rendering engine
93
206
  * @summary This method initializes the rendering engine. It checks if the engine is already initialized
94
- * and sets the initialized flag to true. This method is called before the engine is used.
207
+ * and sets the initialized flag to true. This method is called before the engine is used
208
+ * to ensure it's properly set up for rendering operations.
209
+ *
95
210
  * @return {Promise<void>} A promise that resolves when initialization is complete
96
211
  */
97
212
  initialize(): Promise<void>;
98
213
  /**
99
214
  * @description Registers a component with the rendering engine
100
215
  * @summary This static method registers a component constructor with the rendering engine
101
- * under a specific name. It throws an error if a component is already registered under the same name.
216
+ * under a specific name. It initializes the components registry if needed and throws
217
+ * an error if a component is already registered under the same name to prevent
218
+ * accidental overrides.
219
+ *
102
220
  * @param {string} name - The name to register the component under
103
221
  * @param {Constructor<unknown>} constructor - The component constructor
104
222
  * @return {void}
@@ -107,21 +225,56 @@ export declare class NgxRenderingEngine extends RenderingEngine<AngularFieldDefi
107
225
  /**
108
226
  * @description Retrieves registered components from the rendering engine
109
227
  * @summary This static method retrieves either all registered components or a specific component
110
- * by its selector. It throws an error if the requested component is not registered.
228
+ * by its selector. When called without a selector, it returns an array of all registered
229
+ * components. When called with a selector, it returns the specific component if found,
230
+ * or throws an error if the component is not registered.
231
+ *
111
232
  * @param {string} [selector] - Optional selector to retrieve a specific component
112
233
  * @return {Object|Array} Either a specific component or an array of all components
113
234
  */
114
- static components(selector?: string): {
115
- constructor: Constructor<unknown>;
116
- } | {
117
- constructor: Constructor<unknown>;
118
- }[];
235
+ static components(selector?: string): object | string[];
119
236
  /**
120
237
  * @description Generates a key for reflection metadata
121
238
  * @summary This static method generates a key for reflection metadata by prefixing the input key
122
- * with the Angular engine's reflection prefix. This is used for storing and retrieving metadata.
239
+ * with the Angular engine's reflection prefix. This is used for storing and retrieving
240
+ * metadata in a namespaced way to avoid conflicts with other metadata.
241
+ *
123
242
  * @param {string} key - The base key to prefix
124
243
  * @return {string} The prefixed key for reflection metadata
125
244
  */
126
245
  static key(key: string): string;
246
+ /**
247
+ * @description Sets input properties on a component instance
248
+ * @summary This static utility method sets input properties on a component instance
249
+ * based on the provided inputs object and component metadata. It handles both simple
250
+ * values and nested objects, recursively processing object properties. The method
251
+ * validates each input against the component's metadata to ensure only valid inputs
252
+ * are set.
253
+ *
254
+ * @param {ComponentRef<unknown>} component - The component reference to set inputs on
255
+ * @param {KeyValue} inputs - The input properties to set
256
+ * @param {ComponentMirror<unknown>} metadata - The component metadata for input validation
257
+ * @return {void}
258
+ *
259
+ * @mermaid
260
+ * sequenceDiagram
261
+ * participant Caller
262
+ * participant SetInputs as setInputs
263
+ * participant Parse as parseInputValue
264
+ * participant Component as ComponentRef
265
+ *
266
+ * Caller->>SetInputs: setInputs(component, inputs, metadata)
267
+ * SetInputs->>SetInputs: Iterate through inputs
268
+ * loop For each input
269
+ * SetInputs->>SetInputs: Check if input exists in metadata
270
+ * alt Input is 'props'
271
+ * SetInputs->>Parse: parseInputValue(component, value)
272
+ * Parse->>Parse: Recursively process nested objects
273
+ * Parse->>Component: setInput(key, value)
274
+ * else Input is valid
275
+ * SetInputs->>Component: setInput(key, value)
276
+ * end
277
+ * end
278
+ */
279
+ static setInputs(component: ComponentRef<unknown>, inputs: KeyValue, metadata: ComponentMirror<unknown>): void;
127
280
  }