fg-dynamic-component 1.0.1 → 1.0.2
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.
|
@@ -2,6 +2,9 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { input, model, viewChild, ViewContainerRef, viewChildren, ElementRef, inject, Renderer2, Injector, EventEmitter, Component, ChangeDetectionStrategy } from '@angular/core';
|
|
3
3
|
import { FormControlDirective, NgControl, FormControl, Validators, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Declare components to dynamically load in static and/or dynamic way using the FGDynamicService.
|
|
7
|
+
*/
|
|
5
8
|
class FGDynamicService {
|
|
6
9
|
static { this._components = {}; }
|
|
7
10
|
static registerComponent(name, type) {
|
|
@@ -13,6 +16,10 @@ class FGDynamicService {
|
|
|
13
16
|
return FGDynamicService._components[name];
|
|
14
17
|
}
|
|
15
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a standalone signals based dynamic components tree through a JSON configuration with full
|
|
21
|
+
* life-cycle support for inputs, outputs, attributes, reactive forms and expressions binding evaluation.
|
|
22
|
+
*/
|
|
16
23
|
class FGDynamicComponent {
|
|
17
24
|
constructor() {
|
|
18
25
|
this.configuration = input.required();
|
|
@@ -29,14 +36,28 @@ class FGDynamicComponent {
|
|
|
29
36
|
this._outputsSubscriptions = [];
|
|
30
37
|
this._injector = inject(Injector);
|
|
31
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* A callback method that is invoked immediately after the default change
|
|
41
|
+
* detector has checked data-bound properties if at least one has changed,
|
|
42
|
+
* and before the view and content children are checked.
|
|
43
|
+
*/
|
|
32
44
|
async ngOnChanges() {
|
|
45
|
+
// A method to lazy-load a component.
|
|
33
46
|
await this.loadComponentAsync();
|
|
47
|
+
// Instantiates a single component and inserts its host view into this container.
|
|
34
48
|
this.createComponent();
|
|
49
|
+
// Instantiates a single component and inserts its host view into this container.
|
|
35
50
|
this.setInputs();
|
|
36
|
-
|
|
51
|
+
// Disables/enables the control.
|
|
37
52
|
this.setFormControlStatus();
|
|
53
|
+
// Add a synchronous validators to this control.
|
|
38
54
|
this.setFormControlValidators();
|
|
55
|
+
// Set attribute values for an element in the DOM.
|
|
56
|
+
this.setAttributes();
|
|
39
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* A method to lazy-load a component.
|
|
60
|
+
*/
|
|
40
61
|
async loadComponentAsync() {
|
|
41
62
|
if (this.configuration().type != null && !this._component) {
|
|
42
63
|
if (typeof (this.configuration().type) === 'string') {
|
|
@@ -47,11 +68,16 @@ class FGDynamicComponent {
|
|
|
47
68
|
}
|
|
48
69
|
}
|
|
49
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Instantiates a single component and inserts its host view into this container.
|
|
73
|
+
*/
|
|
50
74
|
createComponent() {
|
|
51
|
-
if (this._component && !this._componentRef && this._viewContainerRef()) {
|
|
75
|
+
if (this._component && !this._componentRef && this._viewContainerRef() && !this._formControlDirective) {
|
|
52
76
|
let injector;
|
|
53
|
-
if (this.formGroup() && this.configuration()?.attributes && this.configuration()
|
|
77
|
+
if (this.formGroup() && this.configuration()?.attributes && this.configuration().attributes['name'] && typeof (this.evaluateExpression(this.configuration().attributes['name'], this.viewModel)) === 'string' && this.viewModel()) {
|
|
78
|
+
// Synchronizes a standalone FormControl instance to a form control element.
|
|
54
79
|
this._formControlDirective = new FormControlDirective(null, null, null, null);
|
|
80
|
+
// Creates a new injector instance that provides one or more dependencies, according to a given type or types of StaticProvider.
|
|
55
81
|
injector = Injector.create({
|
|
56
82
|
providers: [{
|
|
57
83
|
provide: NgControl,
|
|
@@ -60,18 +86,28 @@ class FGDynamicComponent {
|
|
|
60
86
|
parent: this._injector
|
|
61
87
|
});
|
|
62
88
|
}
|
|
89
|
+
// Creates a new injector instance that provides one or more dependencies, according to a given type or types of StaticProvider.
|
|
63
90
|
this._componentRef = this._viewContainerRef().createComponent(this._component, {
|
|
64
91
|
projectableNodes: this._dynamicItems()?.length > 0 ? [this._dynamicItems().map((e) => e.nativeElement)] : undefined,
|
|
65
92
|
injector: injector
|
|
66
93
|
});
|
|
94
|
+
// When a view uses the ChangeDetectionStrategy#OnPush (checkOnce) change detection strategy, explicitly marks the view as changed so that it can be checked again.
|
|
95
|
+
// Components are normally marked as dirty (in need of rerendering) when inputs have changed or events have fired in the view.
|
|
96
|
+
// Call this method to ensure that a component is checked even if these triggers have not occurred.
|
|
67
97
|
if (this._componentRef?.changeDetectorRef) {
|
|
68
98
|
this._componentRef.changeDetectorRef.markForCheck();
|
|
69
99
|
}
|
|
100
|
+
// A method to remove the fg-dynamic tag.
|
|
70
101
|
this.removeHostElement();
|
|
102
|
+
// Register handlers for those events by subscribing to an instance.
|
|
71
103
|
this.handleOutputs();
|
|
104
|
+
// Construct a FormControl with an initial value.
|
|
72
105
|
this.createFormControl();
|
|
73
106
|
}
|
|
74
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* A method to remove the fg-dynamic tag.
|
|
110
|
+
*/
|
|
75
111
|
removeHostElement() {
|
|
76
112
|
if (this._elementRef?.nativeElement?.parentElement) {
|
|
77
113
|
const nativeElement = this._elementRef.nativeElement;
|
|
@@ -84,14 +120,18 @@ class FGDynamicComponent {
|
|
|
84
120
|
parentElement.removeChild(nativeElement);
|
|
85
121
|
}
|
|
86
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Register handlers for those events by subscribing to an instance.
|
|
125
|
+
*/
|
|
87
126
|
handleOutputs() {
|
|
88
|
-
this.
|
|
89
|
-
if (this.configuration()?.outputs && this._componentRef?.instance) {
|
|
127
|
+
if (this.configuration()?.outputs && Object.keys(this.configuration().outputs).length > 0 && this._componentRef?.instance) {
|
|
90
128
|
for (const outputName in this.configuration().outputs) {
|
|
91
129
|
if (this._componentRef.instance[outputName] instanceof EventEmitter) {
|
|
92
|
-
this._outputsSubscriptions
|
|
130
|
+
this._outputsSubscriptions.push(this._componentRef.instance[outputName].subscribe(($event) => {
|
|
131
|
+
// Evaluates JavaScript code and executes it.
|
|
93
132
|
const result = this.evaluateExpression(this.configuration().outputs[outputName], this.viewModel, $event);
|
|
94
133
|
if (result instanceof Function) {
|
|
134
|
+
// Executes a function.
|
|
95
135
|
result($event);
|
|
96
136
|
}
|
|
97
137
|
}));
|
|
@@ -99,84 +139,125 @@ class FGDynamicComponent {
|
|
|
99
139
|
}
|
|
100
140
|
}
|
|
101
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Construct a FormControl with an initial value.
|
|
144
|
+
*/
|
|
102
145
|
createFormControl() {
|
|
103
|
-
if (this.formGroup() && this.configuration()?.attributes && this.configuration()
|
|
104
|
-
|
|
105
|
-
this.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
146
|
+
if (this.formGroup() && this.configuration()?.attributes && this.configuration().attributes['name'] && this.viewModel()) {
|
|
147
|
+
// Evaluates JavaScript code and executes it.
|
|
148
|
+
const name = this.evaluateExpression(this.configuration().attributes['name'], this.viewModel);
|
|
149
|
+
if (typeof (name) === 'string') {
|
|
150
|
+
// Construct a FormControl with no initial value or validators.
|
|
151
|
+
this._formControl = new FormControl(this.getModelPropertyValue(this.viewModel(), name, null));
|
|
152
|
+
// Add a control to this group. In a strongly-typed group, the control must be in the group's type (possibly as an optional key).
|
|
153
|
+
// If a control with a given name already exists, it would not be replaced with a new one.
|
|
154
|
+
// If you want to replace an existing control, use the FormGroup#setControl setControl method instead.
|
|
155
|
+
// This method also updates the value and validity of the control.
|
|
156
|
+
this.formGroup().addControl(name, this._formControl);
|
|
157
|
+
// A multicasting observable that emits an event every time the value of the control changes, in the UI or programmatically.
|
|
158
|
+
this._formControlSubscription = this._formControl.valueChanges.subscribe((value) => {
|
|
159
|
+
// Creates a deep clone of an object.
|
|
111
160
|
const viewModel = structuredClone(this.viewModel());
|
|
112
|
-
|
|
161
|
+
// Sets the value at path of object.
|
|
162
|
+
// If a portion of path doesn't exist, it's created.
|
|
163
|
+
// Arrays are created for missing index properties while objects are created for all other missing properties.
|
|
164
|
+
// This method mutates object.
|
|
165
|
+
this.setModelPropertyValue(viewModel, name, value);
|
|
166
|
+
// Directly set the signal to a new value, and notify any dependents.
|
|
113
167
|
this.viewModel.set(viewModel);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
168
|
+
});
|
|
169
|
+
// Synchronizes a standalone FormControl instance to a form control element.
|
|
170
|
+
this.attachFormControlDirective();
|
|
171
|
+
}
|
|
117
172
|
}
|
|
118
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Disables/enables the control.
|
|
176
|
+
*/
|
|
119
177
|
setFormControlStatus() {
|
|
120
178
|
if (this._formControl && this.configuration().attributes && this.configuration().attributes['disabled'] != null) {
|
|
179
|
+
// Evaluates JavaScript code and executes it.
|
|
121
180
|
const isDisabled = this.evaluateExpression(this.configuration().attributes['disabled'], this.viewModel);
|
|
122
|
-
if (isDisabled) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
181
|
+
if (typeof (isDisabled) === 'boolean' && ((isDisabled && this._formControl.enabled) || (!isDisabled && this._formControl.disabled))) {
|
|
182
|
+
if (isDisabled) {
|
|
183
|
+
// Disables the control.
|
|
184
|
+
this._formControl.disable({
|
|
185
|
+
onlySelf: true,
|
|
186
|
+
emitEvent: false
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
// Enables the control.
|
|
191
|
+
this._formControl.enable({
|
|
192
|
+
onlySelf: true,
|
|
193
|
+
emitEvent: false
|
|
194
|
+
});
|
|
195
|
+
}
|
|
133
196
|
}
|
|
134
197
|
}
|
|
135
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Add a synchronous validators to this control.
|
|
201
|
+
*/
|
|
136
202
|
setFormControlValidators() {
|
|
137
|
-
if (this._formControl && this.configuration()?.attributes) {
|
|
138
|
-
this._formControl.clearValidators();
|
|
203
|
+
if (this._formControl && this.configuration()?.attributes && Object.keys(this.configuration().attributes).length > 0 && this._componentRef?.location?.nativeElement) {
|
|
139
204
|
const validators = [];
|
|
205
|
+
// Validator that requires the control's value to be greater than or equal to the provided number.
|
|
140
206
|
const min = this.evaluateExpression(this.configuration().attributes['min'], this.viewModel);
|
|
141
|
-
if (typeof (min) === 'number') {
|
|
207
|
+
if (typeof (min) === 'number' && min.toString() !== this._componentRef.location.nativeElement.getAttribute('min')) {
|
|
142
208
|
validators.push(Validators.min(min));
|
|
143
209
|
}
|
|
210
|
+
// Validator that requires the control's value to be less than or equal to the provided number.
|
|
144
211
|
const max = this.evaluateExpression(this.configuration().attributes['max'], this.viewModel);
|
|
145
|
-
if (typeof (max) === 'number') {
|
|
212
|
+
if (typeof (max) === 'number' && max.toString() !== this._componentRef.location.nativeElement.getAttribute('max')) {
|
|
146
213
|
validators.push(Validators.max(max));
|
|
147
214
|
}
|
|
215
|
+
// Validator that requires the control have a non-empty value.
|
|
148
216
|
const required = this.evaluateExpression(this.configuration().attributes['required'], this.viewModel);
|
|
149
|
-
if (required === true) {
|
|
217
|
+
if (required === true && required.toString() !== this._componentRef.location.nativeElement.getAttribute('required')) {
|
|
150
218
|
validators.push(Validators.required);
|
|
151
219
|
}
|
|
220
|
+
// Validator that requires the control's value pass an email validation test.
|
|
152
221
|
const email = this.evaluateExpression(this.configuration().attributes['email'], this.viewModel);
|
|
153
|
-
if (email === true) {
|
|
222
|
+
if (email === true && email.toString() !== this._componentRef.location.nativeElement.getAttribute('email')) {
|
|
154
223
|
validators.push(Validators.email);
|
|
155
224
|
}
|
|
225
|
+
// Validator that requires the length of the control's value to be less than or equal to the provided maximum length.
|
|
156
226
|
const maxLength = this.evaluateExpression(this.configuration().attributes['maxlength'], this.viewModel);
|
|
157
|
-
if (maxLength > 0) {
|
|
227
|
+
if (maxLength > 0 && maxLength.toString() !== this._componentRef.location.nativeElement.getAttribute('maxlength')) {
|
|
158
228
|
validators.push(Validators.maxLength(maxLength));
|
|
159
229
|
}
|
|
230
|
+
// Validator that requires the length of the control's value to be greater than or equal to the provided minimum length.
|
|
160
231
|
const minLength = this.evaluateExpression(this.configuration().attributes['minlength'], this.viewModel);
|
|
161
|
-
if (minLength > 0) {
|
|
232
|
+
if (minLength > 0 && minLength.toString() !== this._componentRef.location.nativeElement.getAttribute('minlength')) {
|
|
162
233
|
validators.push(Validators.minLength(minLength));
|
|
163
234
|
}
|
|
235
|
+
// Validator that requires the control's value to match a regex pattern.
|
|
164
236
|
const pattern = this.evaluateExpression(this.configuration().attributes['pattern'], this.viewModel);
|
|
165
|
-
if (typeof (pattern) === 'string'
|
|
237
|
+
if (typeof (pattern) === 'string' && pattern !== this._componentRef.location.nativeElement.getAttribute('pattern')) {
|
|
166
238
|
validators.push(Validators.pattern(pattern));
|
|
167
239
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
240
|
+
if (validators.length > 0) {
|
|
241
|
+
// Empties out the synchronous validator list.
|
|
242
|
+
this._formControl.clearValidators();
|
|
243
|
+
// Add a synchronous validator or validators to this control, without affecting other validators.
|
|
244
|
+
this._formControl.addValidators(validators);
|
|
245
|
+
// Recalculates the value and validation status of the control.
|
|
246
|
+
this._formControl.updateValueAndValidity({
|
|
247
|
+
onlySelf: true,
|
|
248
|
+
emitEvent: false
|
|
249
|
+
});
|
|
250
|
+
}
|
|
173
251
|
}
|
|
174
252
|
}
|
|
253
|
+
/**
|
|
254
|
+
* Synchronizes a standalone FormControl instance to a form control element.
|
|
255
|
+
*/
|
|
175
256
|
attachFormControlDirective() {
|
|
176
257
|
if (this._formControlDirective && this._componentRef?.injector && this._formControl) {
|
|
177
|
-
|
|
178
|
-
this._formControlDirective.valueAccessor = valueAccessor;
|
|
258
|
+
this._formControlDirective.valueAccessor = this._componentRef.injector.get(NG_VALUE_ACCESSOR, null)?.find((_) => true);
|
|
179
259
|
this._formControlDirective.form = this._formControl;
|
|
260
|
+
// A callback method that is invoked immediately after the default change detector has checked data-bound properties if at least one has changed, and before the view and content children are checked.
|
|
180
261
|
this._formControlDirective.ngOnChanges({
|
|
181
262
|
form: {
|
|
182
263
|
firstChange: true,
|
|
@@ -187,6 +268,12 @@ class FGDynamicComponent {
|
|
|
187
268
|
});
|
|
188
269
|
}
|
|
189
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
|
|
273
|
+
* @param model The object.
|
|
274
|
+
* @param property The path.
|
|
275
|
+
* @param defaultValue The resolved value.
|
|
276
|
+
*/
|
|
190
277
|
getModelPropertyValue(model, property, defaultValue) {
|
|
191
278
|
// If path is not defined or it has false value
|
|
192
279
|
if (!property) {
|
|
@@ -199,6 +286,14 @@ class FGDynamicComponent {
|
|
|
199
286
|
// If found value is undefined return default value; otherwise return the value
|
|
200
287
|
return result != null ? result : defaultValue;
|
|
201
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
|
|
291
|
+
* Arrays are created for missing index properties while objects are created for all other missing properties.
|
|
292
|
+
* This method mutates object.
|
|
293
|
+
* @param model The object.
|
|
294
|
+
* @param property The path.
|
|
295
|
+
* @param value The value.
|
|
296
|
+
*/
|
|
202
297
|
setModelPropertyValue(model, property, value) {
|
|
203
298
|
const pathArray = Array.isArray(property) ? property : property.match(/([^[.\]])+/g);
|
|
204
299
|
pathArray.reduce((acc, key, i) => {
|
|
@@ -211,32 +306,63 @@ class FGDynamicComponent {
|
|
|
211
306
|
return acc[key];
|
|
212
307
|
}, model);
|
|
213
308
|
}
|
|
309
|
+
/**
|
|
310
|
+
* Updates specified input names to new values.
|
|
311
|
+
*/
|
|
214
312
|
setInputs() {
|
|
215
|
-
if (this.configuration()?.inputs && this._componentRef) {
|
|
313
|
+
if (this.configuration()?.inputs && Object.keys(this.configuration().inputs).length > 0 && this._componentRef) {
|
|
216
314
|
for (const inputName in this.configuration().inputs) {
|
|
315
|
+
// Updates a specified input name to a new value.
|
|
316
|
+
// Using this method will properly mark for check component using the OnPush change detection strategy.
|
|
317
|
+
// It will also assure that the OnChanges lifecycle hook runs when a dynamically created component is change-detected.
|
|
217
318
|
this._componentRef.setInput(inputName, this.evaluateExpression(this.configuration().inputs[inputName], this.viewModel));
|
|
218
319
|
}
|
|
219
320
|
}
|
|
220
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Set attribute values for an element in the DOM.
|
|
324
|
+
*/
|
|
221
325
|
setAttributes() {
|
|
222
|
-
if (this.configuration()?.attributes && this._componentRef) {
|
|
326
|
+
if (this.configuration()?.attributes && Object.keys(this.configuration().attributes).length > 0 && this._componentRef?.location?.nativeElement) {
|
|
223
327
|
for (const attributeName in this.configuration().attributes) {
|
|
224
|
-
|
|
328
|
+
// Evaluates JavaScript code and executes it.
|
|
329
|
+
const value = this.evaluateExpression(this.configuration().attributes[attributeName], this.viewModel);
|
|
330
|
+
// Returns element's first attribute whose qualified name is qualifiedName, and null if there is no such attribute otherwise.
|
|
331
|
+
if (value !== this._componentRef.location.nativeElement.getAttribute(attributeName)) {
|
|
332
|
+
// Implement this callback to set an attribute value for an element in the DOM.
|
|
333
|
+
this._renderer.setAttribute(this._componentRef.location.nativeElement, attributeName, value);
|
|
334
|
+
}
|
|
225
335
|
}
|
|
226
336
|
}
|
|
227
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Evaluates JavaScript code and executes it.
|
|
340
|
+
* @param value The JavaScript code.
|
|
341
|
+
* @param $vm The view model.
|
|
342
|
+
* @param $event The event.
|
|
343
|
+
* @returns Evaluated expression.
|
|
344
|
+
*/
|
|
228
345
|
evaluateExpression(value, $vm, $event) {
|
|
229
|
-
if (typeof (value) === 'string' && ((value.includes('$vm') && $vm() != null) || (value.includes('$event') && $event != null))) {
|
|
346
|
+
if (typeof (value) === 'string' && ((value.includes('$vm') && $vm != null && $vm() != null) || (value.includes('$event') && $event != null))) {
|
|
347
|
+
// Evaluates JavaScript code and executes it.
|
|
230
348
|
return eval(value);
|
|
231
349
|
}
|
|
232
350
|
else {
|
|
233
351
|
return value;
|
|
234
352
|
}
|
|
235
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* A callback method that performs custom clean-up, invoked immediately before a directive, pipe, or service instance is destroyed.
|
|
356
|
+
*/
|
|
236
357
|
ngOnDestroy() {
|
|
358
|
+
// Performs the specified action for each element in an array (Disposes the resources held by the subscription).
|
|
237
359
|
this._outputsSubscriptions?.forEach((s) => s.unsubscribe());
|
|
238
|
-
|
|
360
|
+
// Disposes the resources held by the subscription.
|
|
361
|
+
// May, for instance, cancel an ongoing Observable execution or cancel any other type of work that started when the Subscription was created.
|
|
362
|
+
this._formControlSubscription?.unsubscribe();
|
|
363
|
+
// A callback method that performs custom clean-up, invoked immediately before a directive, pipe, or service instance is destroyed.
|
|
239
364
|
this._formControlDirective?.ngOnDestroy();
|
|
365
|
+
// Destroys the component instance and all of the data structures associated with it.
|
|
240
366
|
this._componentRef?.destroy();
|
|
241
367
|
}
|
|
242
368
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.4", ngImport: i0, type: FGDynamicComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fg-dynamic-component.mjs","sources":["../../../projects/fg-dynamic-component/src/lib/fg-dynamic.component.ts","../../../projects/fg-dynamic-component/src/public-api.ts","../../../projects/fg-dynamic-component/src/fg-dynamic-component.ts"],"sourcesContent":["import { ChangeDetectionStrategy, Component, ComponentRef, ElementRef, EventEmitter, Injector, InputSignal, ModelSignal, OnDestroy, Renderer2, Signal, Type, ViewContainerRef, inject, input, model, viewChild, viewChildren } from '@angular/core';\nimport { ControlValueAccessor, FormControl, FormControlDirective, FormGroup, NG_VALUE_ACCESSOR, NgControl, ValidatorFn, Validators } from '@angular/forms';\nimport { Subscription } from 'rxjs';\n\nexport interface FGDynamicItem {\n type?: string | Type<unknown> | Promise<Type<unknown>>;\n inputs?: Record<string, string | unknown>;\n outputs?: Record<string, string | Function>;\n attributes?: Record<string, string | unknown>;\n items?: FGDynamicItem[];\n}\n\nexport class FGDynamicService {\n private static _components: Record<string, Type<unknown> | Promise<Type<unknown>>> = {};\n\n static registerComponent(name: string, type: Type<unknown> | Promise<Type<unknown>>): void {\n if (name && type) {\n FGDynamicService._components[name] = type;\n }\n }\n\n static getComponent(name: string): Type<unknown> | Promise<Type<unknown>> {\n return FGDynamicService._components[name];\n }\n}\n\n@Component({\n\tselector: 'fg-dynamic',\n\ttemplate: `\n <ng-container #viewContainer></ng-container>\n @for (item of configuration()?.items; track $index) {\n <fg-dynamic #dynamicItem [configuration]=\"item\" [(viewModel)]=\"viewModel\" [formGroup]=\"formGroup()\" />\n }\n `,\n\tchangeDetection: ChangeDetectionStrategy.OnPush,\n\tstandalone: true\n})\nexport class FGDynamicComponent implements OnDestroy {\n\tconfiguration: InputSignal<FGDynamicItem> = input.required<FGDynamicItem>();\n\tviewModel: ModelSignal<unknown> = model<unknown>();\n\tformGroup: InputSignal<FormGroup> = input<FormGroup>();\n\n\tprivate _viewContainerRef: Signal<ViewContainerRef> = viewChild.required('viewContainer', {\n read: ViewContainerRef\n });\n private _dynamicItems: Signal<readonly ElementRef<unknown>[]> = viewChildren('dynamicItem', {\n read: ElementRef\n });\n\tprivate _componentRef: ComponentRef<unknown>;\n private _elementRef: ElementRef<HTMLElement> = inject(ElementRef);\n private _renderer: Renderer2 = inject(Renderer2);\n private _outputsSubscriptions: Subscription[] = [];\n private _formControl: FormControl;\n private _formControlDirective: FormControlDirective;\n private _formGroupSubscription: Subscription;\n private _component: Type<unknown>;\n private _injector: Injector = inject(Injector);\n\n async ngOnChanges(): Promise<void> {\n await this.loadComponentAsync();\n this.createComponent();\n this.setInputs();\n this.setAttributes();\n this.setFormControlStatus();\n this.setFormControlValidators();\n }\n\n private async loadComponentAsync(): Promise<void> {\n if (this.configuration().type != null && !this._component) {\n if (typeof(this.configuration().type) === 'string') {\n this._component = await FGDynamicService.getComponent(this.configuration().type as string);\n } else {\n this._component = await (this.configuration().type as (Type<unknown> | Promise<Type<unknown>>));\n }\n }\n }\n\n private createComponent(): void {\n if (this._component && !this._componentRef && this._viewContainerRef()) {\n let injector: Injector;\n\n if (this.formGroup() && this.configuration()?.attributes && this.configuration()?.attributes['name'] && this.viewModel()) {\n this._formControlDirective = new FormControlDirective(null, null, null, null);\n\n injector = Injector.create({\n providers: [{\n provide: NgControl,\n useValue: this._formControlDirective\n }],\n parent: this._injector\n });\n }\n\n this._componentRef = this._viewContainerRef().createComponent(this._component, {\n projectableNodes: this._dynamicItems()?.length > 0 ? [this._dynamicItems().map((e: ElementRef<unknown>): Node => e.nativeElement as Node)] : undefined,\n injector: injector\n });\n\n if (this._componentRef?.changeDetectorRef) {\n this._componentRef.changeDetectorRef.markForCheck();\n }\n\n this.removeHostElement();\n this.handleOutputs();\n this.createFormControl();\n }\n }\n\n private removeHostElement(): void {\n if (this._elementRef?.nativeElement?.parentElement) {\n const nativeElement: HTMLElement = this._elementRef.nativeElement;\n const parentElement: HTMLElement = nativeElement.parentElement;\n\n // Move all children out of the element\n while (nativeElement.firstChild) {\n parentElement.insertBefore(nativeElement.firstChild, nativeElement);\n }\n\n // Remove the empty element (the host)\n parentElement.removeChild(nativeElement);\n }\n }\n\n private handleOutputs(): void {\n this._outputsSubscriptions?.forEach((s: Subscription): void => s.unsubscribe());\n\n if (this.configuration()?.outputs && this._componentRef?.instance) {\n for (const outputName in this.configuration().outputs) {\n if (this._componentRef.instance[outputName] instanceof EventEmitter) {\n this._outputsSubscriptions?.push(this._componentRef.instance[outputName].subscribe(($event: unknown): void => {\n const result: unknown = this.evaluateExpression(this.configuration().outputs[outputName], this.viewModel, $event);\n\n if (result instanceof Function) {\n result($event)\n }\n }));\n }\n }\n }\n }\n\n private createFormControl(): void {\n if (this.formGroup() && this.configuration()?.attributes && this.configuration()?.attributes['name'] && this.viewModel()) {\n this._formControl = new FormControl(this.getModelPropertyValue(this.viewModel(), this.configuration().attributes['name'] as string, null));\n\n this.formGroup().addControl(this.configuration().attributes['name'] as string, this._formControl);\n this._formGroupSubscription?.unsubscribe();\n\n this._formGroupSubscription = this.formGroup().valueChanges.subscribe((): void => {\n const model: unknown = this.formGroup().getRawValue();\n\n if (model) {\n const value: unknown = model[this.configuration().attributes['name'] as string] ?? null;\n const viewModel: unknown = structuredClone(this.viewModel());\n\n this.setModelPropertyValue(viewModel, this.configuration().attributes['name'] as string, value);\n this.viewModel.set(viewModel);\n }\n });\n\n this.attachFormControlDirective();\n }\n }\n\n private setFormControlStatus(): void {\n if (this._formControl && this.configuration().attributes && this.configuration().attributes['disabled'] != null) {\n const isDisabled: boolean = this.evaluateExpression(this.configuration().attributes['disabled'], this.viewModel) as boolean;\n\n if (isDisabled) {\n this._formControl.disable({\n onlySelf: true,\n emitEvent: false\n });\n } else {\n this._formControl.enable({\n onlySelf: true,\n emitEvent: false\n });\n }\n }\n }\n\n private setFormControlValidators(): void {\n if (this._formControl && this.configuration()?.attributes) {\n this._formControl.clearValidators();\n\n const validators: ValidatorFn[] = [];\n const min = this.evaluateExpression(this.configuration().attributes['min'], this.viewModel) as number;\n\n if (typeof(min) === 'number') {\n validators.push(Validators.min(min));\n }\n\n const max = this.evaluateExpression(this.configuration().attributes['max'], this.viewModel) as number;\n\n if (typeof(max) === 'number') {\n validators.push(Validators.max(max));\n }\n\n const required = this.evaluateExpression(this.configuration().attributes['required'], this.viewModel) as boolean;\n\n if (required === true) {\n validators.push(Validators.required);\n }\n\n const email = this.evaluateExpression(this.configuration().attributes['email'], this.viewModel) as boolean;\n\n if (email === true) {\n validators.push(Validators.email);\n }\n\n const maxLength = this.evaluateExpression(this.configuration().attributes['maxlength'], this.viewModel) as number;\n\n if (maxLength > 0) {\n validators.push(Validators.maxLength(maxLength));\n }\n\n const minLength = this.evaluateExpression(this.configuration().attributes['minlength'], this.viewModel) as number;\n\n if (minLength > 0) {\n validators.push(Validators.minLength(minLength));\n }\n\n const pattern = this.evaluateExpression(this.configuration().attributes['pattern'], this.viewModel) as (string | RegExp);\n\n if (typeof(pattern) === 'string' || pattern instanceof RegExp) {\n validators.push(Validators.pattern(pattern));\n }\n\n this._formControl.addValidators(validators);\n this._formControl.updateValueAndValidity({\n onlySelf: true,\n emitEvent: false\n });\n }\n }\n\n private attachFormControlDirective(): void {\n if (this._formControlDirective && this._componentRef?.injector && this._formControl) {\n const valueAccessor: ControlValueAccessor = this._componentRef.injector.get<ControlValueAccessor[]>(NG_VALUE_ACCESSOR, null)?.find((_: ControlValueAccessor): true => true);\n\n this._formControlDirective.valueAccessor = valueAccessor;\n this._formControlDirective.form = this._formControl;\n\n this._formControlDirective.ngOnChanges({\n form: {\n firstChange: true,\n currentValue: this._formControl,\n previousValue: undefined,\n isFirstChange: (): true => true\n }\n });\n }\n }\n\n private getModelPropertyValue(model: unknown, property: Array<string> | string, defaultValue: unknown): unknown {\n // If path is not defined or it has false value\n if (!property) {\n return undefined\n }\n\n // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.\n const pathArray: string[] = Array.isArray(property) ? property : property.match(/([^[.\\]])+/g);\n // Find value\n const result: unknown = pathArray.reduce((prevObj: unknown, key: string): unknown => prevObj && prevObj[key], model);\n\n // If found value is undefined return default value; otherwise return the value\n return result != null ? result : defaultValue\n }\n\n private setModelPropertyValue(model: unknown, property: Array<string> | string, value: unknown): void {\n const pathArray: string[] = Array.isArray(property) ? property : property.match(/([^[.\\]])+/g);\n\n pathArray.reduce((acc: unknown, key: string, i: number): unknown => {\n if (acc[key] === undefined) {\n acc[key] = {};\n }\n\n if (i === pathArray.length - 1) {\n acc[key] = value;\n }\n\n return acc[key]\n }, model);\n }\n\n private setInputs(): void {\n if (this.configuration()?.inputs && this._componentRef) {\n for (const inputName in this.configuration().inputs) {\n this._componentRef.setInput(inputName, this.evaluateExpression(this.configuration().inputs[inputName], this.viewModel));\n }\n }\n }\n\n private setAttributes(): void {\n if (this.configuration()?.attributes && this._componentRef) {\n for (const attributeName in this.configuration().attributes) {\n this._renderer.setAttribute(this._componentRef.location.nativeElement, attributeName, this.evaluateExpression(this.configuration().attributes[attributeName], this.viewModel) as string);\n }\n }\n }\n\n private evaluateExpression(value: unknown, $vm?: ModelSignal<unknown>, $event?: unknown): unknown {\n if (typeof(value) === 'string' && ((value.includes('$vm') && $vm() != null) || (value.includes('$event') && $event != null))) {\n return eval(value);\n } else {\n return value;\n }\n }\n\n\tngOnDestroy(): void {\n this._outputsSubscriptions?.forEach((s: Subscription): void => s.unsubscribe());\n this._formGroupSubscription?.unsubscribe();\n this._formControlDirective?.ngOnDestroy();\n this._componentRef?.destroy();\n\t}\n}\n","/*\n * Public API Surface of fg-dynamic-component\n */\n\nexport * from './lib/fg-dynamic.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAYa,gBAAgB,CAAA;aACV,IAAW,CAAA,WAAA,GAA2D,EAAE,CAAC,EAAA;AAExF,IAAA,OAAO,iBAAiB,CAAC,IAAY,EAAE,IAA4C,EAAA;AAC/E,QAAA,IAAI,IAAI,IAAI,IAAI,EAAE;AACd,YAAA,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;SAC7C;KACJ;IAED,OAAO,YAAY,CAAC,IAAY,EAAA;AAC5B,QAAA,OAAO,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;KAC7C;;MAcQ,kBAAkB,CAAA;AAX/B,IAAA,WAAA,GAAA;AAYC,QAAA,IAAA,CAAA,aAAa,GAA+B,KAAK,CAAC,QAAQ,EAAiB,CAAC;QAC5E,IAAS,CAAA,SAAA,GAAyB,KAAK,EAAW,CAAC;QACnD,IAAS,CAAA,SAAA,GAA2B,KAAK,EAAa,CAAC;AAE/C,QAAA,IAAA,CAAA,iBAAiB,GAA6B,SAAS,CAAC,QAAQ,CAAC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AAA,CAAA;;;;;AAKN,IAAA,CAAA,EAAA,QAAA,EAAA,IAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAIQ,kBAAkB,EAAA,QAAA,EAAA,YAAA,EAAA,MAAA,EAAA,CAAA,eAAA,EAAA,WAAA,EAAA,WAAA,CAAA,EAAA,OAAA,EAAA,CAAA,iBAAA,CAAA,EAAA,CAAA,EAAA,eAAA,EAAA,EAAA,CAAA,uBAAA,CAAA,MAAA,EAAA,CAAA,CAAA,EAAA;;2FAAlB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAX9B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,QAAQ,EAAE,YAAY;AACtB,oBAAA,QAAQ,EAAE,CAAA;;;;;AAKN,IAAA,CAAA;oBACJ,eAAe,EAAE,uBAAuB,CAAC,MAAM;AAC/C,oBAAA,UAAU,EAAE,IAAI;AAChB,iBAAA,CAAA;;;ACpCD;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"fg-dynamic-component.mjs","sources":["../../../projects/fg-dynamic-component/src/lib/fg-dynamic.component.ts","../../../projects/fg-dynamic-component/src/public-api.ts","../../../projects/fg-dynamic-component/src/fg-dynamic-component.ts"],"sourcesContent":["import { ChangeDetectionStrategy, Component, ComponentRef, ElementRef, EventEmitter, Injector, InputSignal, ModelSignal, OnChanges, OnDestroy, Renderer2, Signal, Type, ViewContainerRef, inject, input, model, viewChild, viewChildren } from '@angular/core';\nimport { ControlValueAccessor, FormControl, FormControlDirective, FormGroup, NG_VALUE_ACCESSOR, NgControl, ValidatorFn, Validators } from '@angular/forms';\nimport { Subscription } from 'rxjs';\n\nexport interface FGDynamicItem {\n type?: string | Type<unknown> | Promise<Type<unknown>>;\n inputs?: Record<string, string | unknown>;\n outputs?: Record<string, string | Function>;\n attributes?: Record<string, string | unknown>;\n items?: FGDynamicItem[];\n}\n\n/**\n * Declare components to dynamically load in static and/or dynamic way using the FGDynamicService.\n */\nexport class FGDynamicService {\n private static _components: Record<string, Type<unknown> | Promise<Type<unknown>>> = {};\n\n static registerComponent(name: string, type: Type<unknown> | Promise<Type<unknown>>): void {\n if (name && type) {\n FGDynamicService._components[name] = type;\n }\n }\n\n static getComponent(name: string): Type<unknown> | Promise<Type<unknown>> {\n return FGDynamicService._components[name];\n }\n}\n\n/**\n * Create a standalone signals based dynamic components tree through a JSON configuration with full\n * life-cycle support for inputs, outputs, attributes, reactive forms and expressions binding evaluation.\n */\n@Component({\n\tselector: 'fg-dynamic',\n\ttemplate: `\n <ng-container #viewContainer></ng-container>\n @for (item of configuration()?.items; track $index) {\n <fg-dynamic #dynamicItem [configuration]=\"item\" [(viewModel)]=\"viewModel\" [formGroup]=\"formGroup()\" />\n }\n `,\n\tchangeDetection: ChangeDetectionStrategy.OnPush,\n\tstandalone: true\n})\nexport class FGDynamicComponent implements OnChanges, OnDestroy {\n\tconfiguration: InputSignal<FGDynamicItem> = input.required<FGDynamicItem>();\n\tviewModel: ModelSignal<unknown> = model<unknown>();\n\tformGroup: InputSignal<FormGroup> = input<FormGroup>();\n\n\tprivate _viewContainerRef: Signal<ViewContainerRef> = viewChild.required('viewContainer', {\n read: ViewContainerRef\n });\n private _dynamicItems: Signal<readonly ElementRef<unknown>[]> = viewChildren('dynamicItem', {\n read: ElementRef\n });\n\tprivate _componentRef: ComponentRef<unknown>;\n private _elementRef: ElementRef<HTMLElement> = inject(ElementRef);\n private _renderer: Renderer2 = inject(Renderer2);\n private _outputsSubscriptions: Subscription[] = [];\n private _formControl: FormControl;\n private _formControlDirective: FormControlDirective;\n private _formControlSubscription: Subscription;\n private _component: Type<unknown>;\n private _injector: Injector = inject(Injector);\n\n /**\n * A callback method that is invoked immediately after the default change\n * detector has checked data-bound properties if at least one has changed,\n * and before the view and content children are checked.\n */\n async ngOnChanges(): Promise<void> {\n // A method to lazy-load a component.\n await this.loadComponentAsync();\n // Instantiates a single component and inserts its host view into this container.\n this.createComponent();\n // Instantiates a single component and inserts its host view into this container.\n this.setInputs();\n // Disables/enables the control.\n this.setFormControlStatus();\n // Add a synchronous validators to this control.\n this.setFormControlValidators();\n // Set attribute values for an element in the DOM.\n this.setAttributes();\n }\n\n /**\n * A method to lazy-load a component.\n */\n private async loadComponentAsync(): Promise<void> {\n if (this.configuration().type != null && !this._component) {\n if (typeof(this.configuration().type) === 'string') {\n this._component = await FGDynamicService.getComponent(this.configuration().type as string);\n } else {\n this._component = await (this.configuration().type as (Type<unknown> | Promise<Type<unknown>>));\n }\n }\n }\n\n /**\n * Instantiates a single component and inserts its host view into this container.\n */\n private createComponent(): void {\n if (this._component && !this._componentRef && this._viewContainerRef() && !this._formControlDirective) {\n let injector: Injector;\n\n if (this.formGroup() && this.configuration()?.attributes && this.configuration().attributes['name'] && typeof(this.evaluateExpression(this.configuration().attributes['name'], this.viewModel)) === 'string' && this.viewModel()) {\n // Synchronizes a standalone FormControl instance to a form control element.\n this._formControlDirective = new FormControlDirective(null, null, null, null);\n\n // Creates a new injector instance that provides one or more dependencies, according to a given type or types of StaticProvider.\n injector = Injector.create({\n providers: [{\n provide: NgControl,\n useValue: this._formControlDirective\n }],\n parent: this._injector\n });\n }\n\n // Creates a new injector instance that provides one or more dependencies, according to a given type or types of StaticProvider.\n this._componentRef = this._viewContainerRef().createComponent(this._component, {\n projectableNodes: this._dynamicItems()?.length > 0 ? [this._dynamicItems().map((e: ElementRef<unknown>): Node => e.nativeElement as Node)] : undefined,\n injector: injector\n });\n\n // When a view uses the ChangeDetectionStrategy#OnPush (checkOnce) change detection strategy, explicitly marks the view as changed so that it can be checked again.\n // Components are normally marked as dirty (in need of rerendering) when inputs have changed or events have fired in the view.\n // Call this method to ensure that a component is checked even if these triggers have not occurred.\n if (this._componentRef?.changeDetectorRef) {\n this._componentRef.changeDetectorRef.markForCheck();\n }\n\n // A method to remove the fg-dynamic tag.\n this.removeHostElement();\n // Register handlers for those events by subscribing to an instance.\n this.handleOutputs();\n // Construct a FormControl with an initial value.\n this.createFormControl();\n }\n }\n\n /**\n * A method to remove the fg-dynamic tag.\n */\n private removeHostElement(): void {\n if (this._elementRef?.nativeElement?.parentElement) {\n const nativeElement: HTMLElement = this._elementRef.nativeElement;\n const parentElement: HTMLElement = nativeElement.parentElement;\n\n // Move all children out of the element\n while (nativeElement.firstChild) {\n parentElement.insertBefore(nativeElement.firstChild, nativeElement);\n }\n\n // Remove the empty element (the host)\n parentElement.removeChild(nativeElement);\n }\n }\n\n /**\n * Register handlers for those events by subscribing to an instance.\n */\n private handleOutputs(): void {\n if (this.configuration()?.outputs && Object.keys(this.configuration().outputs).length > 0 && this._componentRef?.instance) {\n for (const outputName in this.configuration().outputs) {\n if (this._componentRef.instance[outputName] instanceof EventEmitter) {\n this._outputsSubscriptions.push(this._componentRef.instance[outputName].subscribe(($event: unknown): void => {\n // Evaluates JavaScript code and executes it.\n const result: unknown = this.evaluateExpression(this.configuration().outputs[outputName], this.viewModel, $event);\n\n if (result instanceof Function) {\n // Executes a function.\n result($event);\n }\n }));\n }\n }\n }\n }\n\n /**\n * Construct a FormControl with an initial value.\n */\n private createFormControl(): void {\n if (this.formGroup() && this.configuration()?.attributes && this.configuration().attributes['name'] && this.viewModel()) {\n // Evaluates JavaScript code and executes it.\n const name = this.evaluateExpression(this.configuration().attributes['name'], this.viewModel) as string;\n\n if (typeof(name) === 'string') {\n // Construct a FormControl with no initial value or validators.\n this._formControl = new FormControl(this.getModelPropertyValue(this.viewModel(), name, null));\n\n // Add a control to this group. In a strongly-typed group, the control must be in the group's type (possibly as an optional key).\n // If a control with a given name already exists, it would not be replaced with a new one.\n // If you want to replace an existing control, use the FormGroup#setControl setControl method instead.\n // This method also updates the value and validity of the control.\n this.formGroup().addControl(name, this._formControl);\n\n // A multicasting observable that emits an event every time the value of the control changes, in the UI or programmatically.\n this._formControlSubscription = this._formControl.valueChanges.subscribe((value: unknown): void => {\n // Creates a deep clone of an object.\n const viewModel: unknown = structuredClone(this.viewModel());\n\n // Sets the value at path of object.\n // If a portion of path doesn't exist, it's created.\n // Arrays are created for missing index properties while objects are created for all other missing properties.\n // This method mutates object.\n this.setModelPropertyValue(viewModel, name, value);\n // Directly set the signal to a new value, and notify any dependents.\n this.viewModel.set(viewModel);\n });\n\n // Synchronizes a standalone FormControl instance to a form control element.\n this.attachFormControlDirective();\n }\n }\n }\n\n /**\n * Disables/enables the control.\n */\n private setFormControlStatus(): void {\n if (this._formControl && this.configuration().attributes && this.configuration().attributes['disabled'] != null) {\n // Evaluates JavaScript code and executes it.\n const isDisabled: boolean = this.evaluateExpression(this.configuration().attributes['disabled'], this.viewModel) as boolean;\n\n if (typeof(isDisabled) === 'boolean' && ((isDisabled && this._formControl.enabled) || (!isDisabled && this._formControl.disabled))) {\n if (isDisabled) {\n // Disables the control.\n this._formControl.disable({\n onlySelf: true,\n emitEvent: false\n });\n } else {\n // Enables the control.\n this._formControl.enable({\n onlySelf: true,\n emitEvent: false\n });\n }\n }\n }\n }\n\n /**\n * Add a synchronous validators to this control.\n */\n private setFormControlValidators(): void {\n if (this._formControl && this.configuration()?.attributes && Object.keys(this.configuration().attributes).length > 0 && this._componentRef?.location?.nativeElement) {\n const validators: ValidatorFn[] = [];\n // Validator that requires the control's value to be greater than or equal to the provided number.\n const min = this.evaluateExpression(this.configuration().attributes['min'], this.viewModel) as number;\n\n if (typeof(min) === 'number' && min.toString() !== this._componentRef.location.nativeElement.getAttribute('min')) {\n validators.push(Validators.min(min));\n }\n\n // Validator that requires the control's value to be less than or equal to the provided number.\n const max = this.evaluateExpression(this.configuration().attributes['max'], this.viewModel) as number;\n\n if (typeof(max) === 'number' && max.toString() !== this._componentRef.location.nativeElement.getAttribute('max')) {\n validators.push(Validators.max(max));\n }\n\n // Validator that requires the control have a non-empty value.\n const required = this.evaluateExpression(this.configuration().attributes['required'], this.viewModel) as boolean;\n\n if (required === true && required.toString() !== this._componentRef.location.nativeElement.getAttribute('required')) {\n validators.push(Validators.required);\n }\n\n // Validator that requires the control's value pass an email validation test.\n const email = this.evaluateExpression(this.configuration().attributes['email'], this.viewModel) as boolean;\n\n if (email === true && email.toString() !== this._componentRef.location.nativeElement.getAttribute('email')) {\n validators.push(Validators.email);\n }\n\n // Validator that requires the length of the control's value to be less than or equal to the provided maximum length.\n const maxLength = this.evaluateExpression(this.configuration().attributes['maxlength'], this.viewModel) as number;\n\n if (maxLength > 0 && maxLength.toString() !== this._componentRef.location.nativeElement.getAttribute('maxlength')) {\n validators.push(Validators.maxLength(maxLength));\n }\n\n // Validator that requires the length of the control's value to be greater than or equal to the provided minimum length.\n const minLength = this.evaluateExpression(this.configuration().attributes['minlength'], this.viewModel) as number;\n\n if (minLength > 0 && minLength.toString() !== this._componentRef.location.nativeElement.getAttribute('minlength')) {\n validators.push(Validators.minLength(minLength));\n }\n\n // Validator that requires the control's value to match a regex pattern.\n const pattern = this.evaluateExpression(this.configuration().attributes['pattern'], this.viewModel) as string;\n\n if (typeof(pattern) === 'string' && pattern !== this._componentRef.location.nativeElement.getAttribute('pattern')) {\n validators.push(Validators.pattern(pattern));\n }\n\n if (validators.length > 0) {\n // Empties out the synchronous validator list.\n this._formControl.clearValidators();\n // Add a synchronous validator or validators to this control, without affecting other validators.\n this._formControl.addValidators(validators);\n // Recalculates the value and validation status of the control.\n this._formControl.updateValueAndValidity({\n onlySelf: true,\n emitEvent: false\n });\n }\n }\n }\n\n /**\n * Synchronizes a standalone FormControl instance to a form control element.\n */\n private attachFormControlDirective(): void {\n if (this._formControlDirective && this._componentRef?.injector && this._formControl) {\n this._formControlDirective.valueAccessor = this._componentRef.injector.get<ControlValueAccessor[]>(NG_VALUE_ACCESSOR, null)?.find((_: ControlValueAccessor): true => true);\n this._formControlDirective.form = this._formControl;\n\n // A callback method that is invoked immediately after the default change detector has checked data-bound properties if at least one has changed, and before the view and content children are checked.\n this._formControlDirective.ngOnChanges({\n form: {\n firstChange: true,\n currentValue: this._formControl,\n previousValue: undefined,\n isFirstChange: (): true => true\n }\n });\n }\n }\n\n /**\n * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.\n * @param model The object.\n * @param property The path.\n * @param defaultValue The resolved value.\n */\n private getModelPropertyValue(model: unknown, property: Array<string> | string, defaultValue: unknown): unknown {\n // If path is not defined or it has false value\n if (!property) {\n return undefined\n }\n\n // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.\n const pathArray: string[] = Array.isArray(property) ? property : property.match(/([^[.\\]])+/g);\n // Find value\n const result: unknown = pathArray.reduce((prevObj: unknown, key: string): unknown => prevObj && prevObj[key], model);\n\n // If found value is undefined return default value; otherwise return the value\n return result != null ? result : defaultValue\n }\n\n /**\n * Sets the value at path of object. If a portion of path doesn't exist, it's created.\n * Arrays are created for missing index properties while objects are created for all other missing properties.\n * This method mutates object.\n * @param model The object.\n * @param property The path.\n * @param value The value.\n */\n private setModelPropertyValue(model: unknown, property: Array<string> | string, value: unknown): void {\n const pathArray: string[] = Array.isArray(property) ? property : property.match(/([^[.\\]])+/g);\n\n pathArray.reduce((acc: unknown, key: string, i: number): unknown => {\n if (acc[key] === undefined) {\n acc[key] = {};\n }\n\n if (i === pathArray.length - 1) {\n acc[key] = value;\n }\n\n return acc[key]\n }, model);\n }\n\n /**\n * Updates specified input names to new values.\n */\n private setInputs(): void {\n if (this.configuration()?.inputs && Object.keys(this.configuration().inputs).length > 0 && this._componentRef) {\n for (const inputName in this.configuration().inputs) {\n // Updates a specified input name to a new value.\n // Using this method will properly mark for check component using the OnPush change detection strategy.\n // It will also assure that the OnChanges lifecycle hook runs when a dynamically created component is change-detected.\n this._componentRef.setInput(inputName, this.evaluateExpression(this.configuration().inputs[inputName], this.viewModel));\n }\n }\n }\n\n /**\n * Set attribute values for an element in the DOM.\n */\n private setAttributes(): void {\n if (this.configuration()?.attributes && Object.keys(this.configuration().attributes).length > 0 && this._componentRef?.location?.nativeElement) {\n for (const attributeName in this.configuration().attributes) {\n // Evaluates JavaScript code and executes it.\n const value = this.evaluateExpression(this.configuration().attributes[attributeName], this.viewModel) as string;\n\n // Returns element's first attribute whose qualified name is qualifiedName, and null if there is no such attribute otherwise.\n if (value !== this._componentRef.location.nativeElement.getAttribute(attributeName)) {\n // Implement this callback to set an attribute value for an element in the DOM.\n this._renderer.setAttribute(this._componentRef.location.nativeElement, attributeName, value);\n }\n }\n }\n }\n\n /**\n * Evaluates JavaScript code and executes it.\n * @param value The JavaScript code.\n * @param $vm The view model.\n * @param $event The event.\n * @returns Evaluated expression.\n */\n private evaluateExpression(value: unknown, $vm?: ModelSignal<unknown>, $event?: unknown): unknown {\n if (typeof(value) === 'string' && ((value.includes('$vm') && $vm != null && $vm() != null) || (value.includes('$event') && $event != null))) {\n // Evaluates JavaScript code and executes it.\n return eval(value);\n } else {\n return value;\n }\n }\n\n /**\n * A callback method that performs custom clean-up, invoked immediately before a directive, pipe, or service instance is destroyed.\n */\n\tngOnDestroy(): void {\n // Performs the specified action for each element in an array (Disposes the resources held by the subscription).\n this._outputsSubscriptions?.forEach((s: Subscription): void => s.unsubscribe());\n // Disposes the resources held by the subscription.\n // May, for instance, cancel an ongoing Observable execution or cancel any other type of work that started when the Subscription was created.\n this._formControlSubscription?.unsubscribe();\n // A callback method that performs custom clean-up, invoked immediately before a directive, pipe, or service instance is destroyed.\n this._formControlDirective?.ngOnDestroy();\n // Destroys the component instance and all of the data structures associated with it.\n this._componentRef?.destroy();\n\t}\n}\n","/*\n * Public API Surface of fg-dynamic-component\n */\n\nexport * from './lib/fg-dynamic.component';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAYA;;AAEG;MACU,gBAAgB,CAAA;aACV,IAAW,CAAA,WAAA,GAA2D,EAAE,CAAC,EAAA;AAExF,IAAA,OAAO,iBAAiB,CAAC,IAAY,EAAE,IAA4C,EAAA;AAC/E,QAAA,IAAI,IAAI,IAAI,IAAI,EAAE;AACd,YAAA,gBAAgB,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;SAC7C;K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EAAA,CAAA;kBAX9B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,QAAQ,EAAE,YAAY;AACtB,oBAAA,QAAQ,EAAE,CAAA;;;;;AAKN,IAAA,CAAA;oBACJ,eAAe,EAAE,uBAAuB,CAAC,MAAM;AAC/C,oBAAA,UAAU,EAAE,IAAI;AAChB,iBAAA,CAAA;;;AC3CD;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputSignal, ModelSignal, OnDestroy, Type } from '@angular/core';
|
|
1
|
+
import { InputSignal, ModelSignal, OnChanges, OnDestroy, Type } from '@angular/core';
|
|
2
2
|
import { FormGroup } from '@angular/forms';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
export interface FGDynamicItem {
|
|
@@ -8,12 +8,19 @@ export interface FGDynamicItem {
|
|
|
8
8
|
attributes?: Record<string, string | unknown>;
|
|
9
9
|
items?: FGDynamicItem[];
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Declare components to dynamically load in static and/or dynamic way using the FGDynamicService.
|
|
13
|
+
*/
|
|
11
14
|
export declare class FGDynamicService {
|
|
12
15
|
private static _components;
|
|
13
16
|
static registerComponent(name: string, type: Type<unknown> | Promise<Type<unknown>>): void;
|
|
14
17
|
static getComponent(name: string): Type<unknown> | Promise<Type<unknown>>;
|
|
15
18
|
}
|
|
16
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Create a standalone signals based dynamic components tree through a JSON configuration with full
|
|
21
|
+
* life-cycle support for inputs, outputs, attributes, reactive forms and expressions binding evaluation.
|
|
22
|
+
*/
|
|
23
|
+
export declare class FGDynamicComponent implements OnChanges, OnDestroy {
|
|
17
24
|
configuration: InputSignal<FGDynamicItem>;
|
|
18
25
|
viewModel: ModelSignal<unknown>;
|
|
19
26
|
formGroup: InputSignal<FormGroup>;
|
|
@@ -25,23 +32,82 @@ export declare class FGDynamicComponent implements OnDestroy {
|
|
|
25
32
|
private _outputsSubscriptions;
|
|
26
33
|
private _formControl;
|
|
27
34
|
private _formControlDirective;
|
|
28
|
-
private
|
|
35
|
+
private _formControlSubscription;
|
|
29
36
|
private _component;
|
|
30
37
|
private _injector;
|
|
38
|
+
/**
|
|
39
|
+
* A callback method that is invoked immediately after the default change
|
|
40
|
+
* detector has checked data-bound properties if at least one has changed,
|
|
41
|
+
* and before the view and content children are checked.
|
|
42
|
+
*/
|
|
31
43
|
ngOnChanges(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* A method to lazy-load a component.
|
|
46
|
+
*/
|
|
32
47
|
private loadComponentAsync;
|
|
48
|
+
/**
|
|
49
|
+
* Instantiates a single component and inserts its host view into this container.
|
|
50
|
+
*/
|
|
33
51
|
private createComponent;
|
|
52
|
+
/**
|
|
53
|
+
* A method to remove the fg-dynamic tag.
|
|
54
|
+
*/
|
|
34
55
|
private removeHostElement;
|
|
56
|
+
/**
|
|
57
|
+
* Register handlers for those events by subscribing to an instance.
|
|
58
|
+
*/
|
|
35
59
|
private handleOutputs;
|
|
60
|
+
/**
|
|
61
|
+
* Construct a FormControl with an initial value.
|
|
62
|
+
*/
|
|
36
63
|
private createFormControl;
|
|
64
|
+
/**
|
|
65
|
+
* Disables/enables the control.
|
|
66
|
+
*/
|
|
37
67
|
private setFormControlStatus;
|
|
68
|
+
/**
|
|
69
|
+
* Add a synchronous validators to this control.
|
|
70
|
+
*/
|
|
38
71
|
private setFormControlValidators;
|
|
72
|
+
/**
|
|
73
|
+
* Synchronizes a standalone FormControl instance to a form control element.
|
|
74
|
+
*/
|
|
39
75
|
private attachFormControlDirective;
|
|
76
|
+
/**
|
|
77
|
+
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
|
|
78
|
+
* @param model The object.
|
|
79
|
+
* @param property The path.
|
|
80
|
+
* @param defaultValue The resolved value.
|
|
81
|
+
*/
|
|
40
82
|
private getModelPropertyValue;
|
|
83
|
+
/**
|
|
84
|
+
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
|
|
85
|
+
* Arrays are created for missing index properties while objects are created for all other missing properties.
|
|
86
|
+
* This method mutates object.
|
|
87
|
+
* @param model The object.
|
|
88
|
+
* @param property The path.
|
|
89
|
+
* @param value The value.
|
|
90
|
+
*/
|
|
41
91
|
private setModelPropertyValue;
|
|
92
|
+
/**
|
|
93
|
+
* Updates specified input names to new values.
|
|
94
|
+
*/
|
|
42
95
|
private setInputs;
|
|
96
|
+
/**
|
|
97
|
+
* Set attribute values for an element in the DOM.
|
|
98
|
+
*/
|
|
43
99
|
private setAttributes;
|
|
100
|
+
/**
|
|
101
|
+
* Evaluates JavaScript code and executes it.
|
|
102
|
+
* @param value The JavaScript code.
|
|
103
|
+
* @param $vm The view model.
|
|
104
|
+
* @param $event The event.
|
|
105
|
+
* @returns Evaluated expression.
|
|
106
|
+
*/
|
|
44
107
|
private evaluateExpression;
|
|
108
|
+
/**
|
|
109
|
+
* A callback method that performs custom clean-up, invoked immediately before a directive, pipe, or service instance is destroyed.
|
|
110
|
+
*/
|
|
45
111
|
ngOnDestroy(): void;
|
|
46
112
|
static ɵfac: i0.ɵɵFactoryDeclaration<FGDynamicComponent, never>;
|
|
47
113
|
static ɵcmp: i0.ɵɵComponentDeclaration<FGDynamicComponent, "fg-dynamic", never, { "configuration": { "alias": "configuration"; "required": true; "isSignal": true; }; "viewModel": { "alias": "viewModel"; "required": false; "isSignal": true; }; "formGroup": { "alias": "formGroup"; "required": false; "isSignal": true; }; }, { "viewModel": "viewModelChange"; }, never, never, true, never>;
|