fg-dynamic-component 1.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -11
- package/fesm2022/fg-dynamic-component.mjs +1671 -408
- package/fesm2022/fg-dynamic-component.mjs.map +1 -1
- package/package.json +10 -11
- package/types/fg-dynamic-component.d.ts +216 -0
- package/esm2022/fg-dynamic-component.mjs +0 -5
- package/esm2022/lib/fg-dynamic.component.mjs +0 -404
- package/esm2022/public-api.mjs +0 -5
- package/index.d.ts +0 -5
- package/lib/fg-dynamic.component.d.ts +0 -114
- package/public-api.d.ts +0 -1
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { InputSignal, ModelSignal, OnChanges, OnDestroy, Signal, SimpleChanges, Type } from "@angular/core";
|
|
3
|
+
import { FormGroup } from "@angular/forms";
|
|
4
|
+
export type FGDynamicType = Type<unknown> | Promise<Type<unknown>> | (() => Promise<Type<unknown>>);
|
|
5
|
+
export interface IFGDynamicItem {
|
|
6
|
+
type?: string | FGDynamicType;
|
|
7
|
+
inputs?: Record<string, string | unknown>;
|
|
8
|
+
outputs?: Record<string, string | Function>;
|
|
9
|
+
attributes?: Record<string, string | unknown>;
|
|
10
|
+
items?: IFGDynamicItem[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A scoped component registry. Backed by a `Map`, so lookups never walk the
|
|
14
|
+
* prototype chain and names such as `__proto__` or `constructor` are ordinary keys.
|
|
15
|
+
*
|
|
16
|
+
* Use one registry per rendering context (e.g. per plugin or tenant) so a
|
|
17
|
+
* configuration can only select components that were explicitly registered for
|
|
18
|
+
* that context.
|
|
19
|
+
*/
|
|
20
|
+
export declare class FGDynamicRegistry {
|
|
21
|
+
private readonly _components;
|
|
22
|
+
register(name: string, type: FGDynamicType): void;
|
|
23
|
+
get(name: string): FGDynamicType | undefined;
|
|
24
|
+
has(name: string): boolean;
|
|
25
|
+
unregister(name: string): boolean;
|
|
26
|
+
clear(): void;
|
|
27
|
+
get names(): string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Declare components to dynamically load in static and/or dynamic way using the FGDynamicService.
|
|
31
|
+
*
|
|
32
|
+
* The static registry is global. For untrusted or multi-tenant configurations,
|
|
33
|
+
* create a scoped registry with `FGDynamicService.createRegistry()` and pass it
|
|
34
|
+
* to `<fg-dynamic [registry]="registry">`.
|
|
35
|
+
*/
|
|
36
|
+
export declare class FGDynamicService {
|
|
37
|
+
private static readonly _defaultRegistry;
|
|
38
|
+
static get registry(): FGDynamicRegistry;
|
|
39
|
+
static createRegistry(): FGDynamicRegistry;
|
|
40
|
+
static registerComponent(name: string, type: FGDynamicType): void;
|
|
41
|
+
static getComponent(name: string): FGDynamicType | undefined;
|
|
42
|
+
static hasComponent(name: string): boolean;
|
|
43
|
+
static unregisterComponent(name: string): boolean;
|
|
44
|
+
static clearRegistry(): void;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Create a standalone signals based dynamic components tree through a JSON configuration with full
|
|
48
|
+
* life-cycle support for inputs, outputs, attributes, reactive forms and expressions binding evaluation.
|
|
49
|
+
*/
|
|
50
|
+
export declare class FGDynamicComponent implements OnChanges, OnDestroy {
|
|
51
|
+
configuration: InputSignal<IFGDynamicItem>;
|
|
52
|
+
viewModel: ModelSignal<unknown>;
|
|
53
|
+
formGroup: InputSignal<FormGroup>;
|
|
54
|
+
registry: InputSignal<FGDynamicRegistry>;
|
|
55
|
+
/**
|
|
56
|
+
* Validated child items. Invalid entries are ignored and the list is capped
|
|
57
|
+
* to avoid pathological configurations blocking the renderer.
|
|
58
|
+
*/
|
|
59
|
+
protected readonly items: Signal<readonly IFGDynamicItem[]>;
|
|
60
|
+
private _viewContainerRef;
|
|
61
|
+
private _dynamicItems;
|
|
62
|
+
private _componentRef;
|
|
63
|
+
private _renderer;
|
|
64
|
+
private _outputsSubscriptions;
|
|
65
|
+
private _currentOutputsConfig?;
|
|
66
|
+
private _formControl;
|
|
67
|
+
private _formControlDirective;
|
|
68
|
+
private _formControlSubscription;
|
|
69
|
+
private _managedValidatorFns;
|
|
70
|
+
private _component;
|
|
71
|
+
private _injector;
|
|
72
|
+
private _ngOnChangesCounter;
|
|
73
|
+
private _lastProjectedItemsSignature;
|
|
74
|
+
/**
|
|
75
|
+
* A callback method that is invoked immediately after the default change
|
|
76
|
+
* detector has checked data-bound properties if at least one has changed,
|
|
77
|
+
* and before the view and content children are checked.
|
|
78
|
+
*/
|
|
79
|
+
ngOnChanges(changes?: SimpleChanges): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* A method to lazy-load a component.
|
|
82
|
+
*/
|
|
83
|
+
private loadComponentAsync;
|
|
84
|
+
private resolveCandidate;
|
|
85
|
+
private toComponentType;
|
|
86
|
+
private isAngularComponentType;
|
|
87
|
+
private getRegistry;
|
|
88
|
+
/**
|
|
89
|
+
* Instantiates a single component and inserts its host view into this container.
|
|
90
|
+
*/
|
|
91
|
+
private createComponent;
|
|
92
|
+
/**
|
|
93
|
+
* Register handlers for those events by subscribing to an instance.
|
|
94
|
+
*/
|
|
95
|
+
private handleOutputs;
|
|
96
|
+
private handleOutputsIfChanged;
|
|
97
|
+
/**
|
|
98
|
+
* Construct a FormControl with an initial value.
|
|
99
|
+
*/
|
|
100
|
+
private createFormControl;
|
|
101
|
+
/**
|
|
102
|
+
* Disables/enables the control.
|
|
103
|
+
*/
|
|
104
|
+
private setFormControlStatus;
|
|
105
|
+
/**
|
|
106
|
+
* Add synchronous validators to this control.
|
|
107
|
+
*/
|
|
108
|
+
private setFormControlValidators;
|
|
109
|
+
/**
|
|
110
|
+
* Builds a defensive `pattern` validator. Invalid, oversized or potentially
|
|
111
|
+
* catastrophic regular expressions are ignored instead of blocking the UI.
|
|
112
|
+
*/
|
|
113
|
+
private createPatternValidator;
|
|
114
|
+
/**
|
|
115
|
+
* Heuristic check for regular expressions with nested/ambiguous quantifiers
|
|
116
|
+
* (e.g. `(a+)+`, `(a*)*`, `(\d+){2,}`) that can cause exponential backtracking.
|
|
117
|
+
*/
|
|
118
|
+
private isUnsafeRegex;
|
|
119
|
+
/**
|
|
120
|
+
* Synchronizes a standalone FormControl instance to a form control element.
|
|
121
|
+
*/
|
|
122
|
+
private attachFormControlDirective;
|
|
123
|
+
/**
|
|
124
|
+
* Parses a dot/bracket path. Returns `null` when the path is malformed or
|
|
125
|
+
* contains prototype-related segments (`__proto__`, `prototype`,
|
|
126
|
+
* `constructor`), which protects both the view model and `FormGroup`.
|
|
127
|
+
*/
|
|
128
|
+
private parsePath;
|
|
129
|
+
private isSafePath;
|
|
130
|
+
private defineOwn;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
|
|
133
|
+
* Only own properties are read; prototype-chain reads are blocked.
|
|
134
|
+
* @param model The object.
|
|
135
|
+
* @param property The path.
|
|
136
|
+
* @param defaultValue The resolved value.
|
|
137
|
+
*/
|
|
138
|
+
private getModelPropertyValue;
|
|
139
|
+
/**
|
|
140
|
+
* Sets the value at path of object. If a portion of path doesn't exist, it's created.
|
|
141
|
+
* Arrays are created for missing index properties while objects are created for all other missing properties.
|
|
142
|
+
* Only own properties are traversed and written; prototype-related segments are rejected.
|
|
143
|
+
* This method mutates object.
|
|
144
|
+
* @param model The object.
|
|
145
|
+
* @param property The path.
|
|
146
|
+
* @param value The value.
|
|
147
|
+
*/
|
|
148
|
+
private setModelPropertyValue;
|
|
149
|
+
/**
|
|
150
|
+
* Updates specified input names to new values.
|
|
151
|
+
*/
|
|
152
|
+
private setInputs;
|
|
153
|
+
/**
|
|
154
|
+
* Set attribute values for an element in the DOM.
|
|
155
|
+
*
|
|
156
|
+
* Attribute names and values are validated: event handlers (`on*`),
|
|
157
|
+
* namespaced attributes, `style`/`srcdoc`/`formaction` and unsafe URL
|
|
158
|
+
* schemes are never applied. Non-primitive values are ignored so that
|
|
159
|
+
* configuration data cannot invoke `toString()`/`toJSON()` hooks.
|
|
160
|
+
*/
|
|
161
|
+
private setAttributes;
|
|
162
|
+
private isAllowedAttribute;
|
|
163
|
+
/**
|
|
164
|
+
* Returns `undefined` to skip the attribute entirely, `null` to remove it,
|
|
165
|
+
* or a safe string value.
|
|
166
|
+
*/
|
|
167
|
+
private attributeValueToString;
|
|
168
|
+
private isSafeUrl;
|
|
169
|
+
/**
|
|
170
|
+
* Evaluates an expression with a small, allowlisted interpreter. No `eval`,
|
|
171
|
+
* `Function` or other string-to-code primitive is used.
|
|
172
|
+
* @param value The expression or literal value.
|
|
173
|
+
* @param vmParam The view model (signal or plain value).
|
|
174
|
+
* @param eventParam The event payload.
|
|
175
|
+
* @returns Evaluated expression, `undefined` when the expression is rejected,
|
|
176
|
+
* or the original value when it is a literal.
|
|
177
|
+
*/
|
|
178
|
+
private evaluateExpression;
|
|
179
|
+
private getViewModelValue;
|
|
180
|
+
private logWarning;
|
|
181
|
+
private logError;
|
|
182
|
+
/**
|
|
183
|
+
* Cleans up every dynamically created resource: subscriptions, form control, value accessor directive and component reference.
|
|
184
|
+
* Used both on component type change and on destroy.
|
|
185
|
+
*/
|
|
186
|
+
private cleanup;
|
|
187
|
+
/**
|
|
188
|
+
* A callback method that performs custom clean-up, invoked immediately before a directive, pipe, or service instance is destroyed.
|
|
189
|
+
*/
|
|
190
|
+
ngOnDestroy(): void;
|
|
191
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FGDynamicComponent, never>;
|
|
192
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<FGDynamicComponent, "fg-dynamic", never, {
|
|
193
|
+
"configuration": {
|
|
194
|
+
"alias": "configuration";
|
|
195
|
+
"required": true;
|
|
196
|
+
"isSignal": true;
|
|
197
|
+
};
|
|
198
|
+
"viewModel": {
|
|
199
|
+
"alias": "viewModel";
|
|
200
|
+
"required": false;
|
|
201
|
+
"isSignal": true;
|
|
202
|
+
};
|
|
203
|
+
"formGroup": {
|
|
204
|
+
"alias": "formGroup";
|
|
205
|
+
"required": false;
|
|
206
|
+
"isSignal": true;
|
|
207
|
+
};
|
|
208
|
+
"registry": {
|
|
209
|
+
"alias": "registry";
|
|
210
|
+
"required": false;
|
|
211
|
+
"isSignal": true;
|
|
212
|
+
};
|
|
213
|
+
}, {
|
|
214
|
+
"viewModel": "viewModelChange";
|
|
215
|
+
}, never, never, true, never>;
|
|
216
|
+
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generated bundle index. Do not edit.
|
|
3
|
-
*/
|
|
4
|
-
export * from './public-api';
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmctZHluYW1pYy1jb21wb25lbnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9wcm9qZWN0cy9mZy1keW5hbWljLWNvbXBvbmVudC9zcmMvZmctZHluYW1pYy1jb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLGNBQWMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9wdWJsaWMtYXBpJztcbiJdfQ==
|