fg-dynamic-component 4.0.0 → 5.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/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { InputSignal, ModelSignal, OnChanges, OnDestroy, Signal, SimpleChanges, Type } from "@angular/core";
|
|
3
3
|
import { FormGroup } from "@angular/forms";
|
|
4
|
+
/**
|
|
5
|
+
* Small, allowlisted expression interpreter used for the `$vm` / `$event` binding
|
|
6
|
+
* feature of `FGDynamicComponent`.
|
|
7
|
+
*
|
|
8
|
+
* This intentionally does NOT use `eval`, `new Function`, or any other
|
|
9
|
+
* string-to-code primitive. Only the following constructs are supported:
|
|
10
|
+
*
|
|
11
|
+
* - literals (string, number, boolean, null, undefined, NaN, Infinity)
|
|
12
|
+
* - identifiers from the provided variables (`$vm`, `$event`, arrow parameters)
|
|
13
|
+
* - member access: `a.b`, `a['b']`, optional chaining `a?.b`
|
|
14
|
+
* - calls: `$vm()`, `$vm.update(fn)`, `$event.value`
|
|
15
|
+
* - unary: `!`, `-`, `+`, `typeof`
|
|
16
|
+
* - binary/logical/ternary operators
|
|
17
|
+
* - array and object literals, including spread
|
|
18
|
+
* - expression-bodied arrow functions (and arrow blocks containing `return`)
|
|
19
|
+
*
|
|
20
|
+
* Assignments, `new`, `this`, globals (e.g. `window`, `fetch`), template
|
|
21
|
+
* literals and regular-expression literals are rejected. Prototype-related
|
|
22
|
+
* property names are blocked at every access.
|
|
23
|
+
*
|
|
24
|
+
* Expressions are also treated as a capability boundary: browser host objects
|
|
25
|
+
* (DOM nodes, events, `window`, `document`, storage, …) are never readable and
|
|
26
|
+
* methods can only be invoked through an allowlist. This prevents an expression
|
|
27
|
+
* from escaping through `$event`/`$vm` values that happen to reference the DOM.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* A single method capability granted to expressions.
|
|
31
|
+
*
|
|
32
|
+
* `receiver` defaults to `'root'`, which only permits the call on the `$vm`
|
|
33
|
+
* capability or on the value returned by `$vm()`. Granting a method name to
|
|
34
|
+
* every reachable object (`'any'`) is only safe for fully trusted view models;
|
|
35
|
+
* `on` pins the capability to one object identity.
|
|
36
|
+
*/
|
|
37
|
+
interface FGDynamicAllowedMethod {
|
|
38
|
+
name: string;
|
|
39
|
+
receiver?: 'root' | 'any';
|
|
40
|
+
on?: object;
|
|
41
|
+
}
|
|
4
42
|
export type FGDynamicType = Type<unknown> | Promise<Type<unknown>> | (() => Promise<Type<unknown>>);
|
|
5
43
|
export interface IFGDynamicItem {
|
|
6
44
|
type?: string | FGDynamicType;
|
|
@@ -17,8 +55,12 @@ export interface IFGDynamicItem {
|
|
|
17
55
|
export interface IFGDynamicExpressionPolicy {
|
|
18
56
|
/** Allow calling any method reachable from the view model. Defaults to `false`. */
|
|
19
57
|
allowCustomMethods?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Methods that may be called when `allowCustomMethods` is `false`.
|
|
60
|
+
* String entries are scoped to `$vm` and the value returned by `$vm()`;
|
|
61
|
+
* use `{ name, receiver: 'any' }` or `{ name, on }` to grant a nested method.
|
|
62
|
+
*/
|
|
63
|
+
allowedMethods?: readonly (string | FGDynamicAllowedMethod)[];
|
|
22
64
|
/** Expose `$vm.set` and `$vm.update`. Defaults to `false`. */
|
|
23
65
|
allowViewModelMutation?: boolean;
|
|
24
66
|
}
|
|
@@ -49,6 +91,13 @@ export interface IFGDynamicTypePolicy {
|
|
|
49
91
|
export interface IFGDynamicAttributePolicy {
|
|
50
92
|
/** Disallow `id`, `class`, `for`, `href` and `src`. Defaults to `false`. */
|
|
51
93
|
strict?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Allow `href`/`src` to point at other origins (including protocol-relative
|
|
96
|
+
* URLs). Defaults to `false`: relative and same-origin URLs only, so an
|
|
97
|
+
* untrusted configuration cannot exfiltrate view-model data by rendering a
|
|
98
|
+
* request to an attacker-controlled host.
|
|
99
|
+
*/
|
|
100
|
+
allowExternalUrls?: boolean;
|
|
52
101
|
}
|
|
53
102
|
/**
|
|
54
103
|
* A scoped component registry. Backed by a `Map`, so lookups never walk the
|
|
@@ -100,8 +149,15 @@ export declare class FGDynamicComponent implements OnChanges, OnDestroy {
|
|
|
100
149
|
/** Current nesting depth; used to bound recursive configurations. */
|
|
101
150
|
depth: InputSignal<number>;
|
|
102
151
|
/**
|
|
103
|
-
*
|
|
104
|
-
*
|
|
152
|
+
* Cached structural validation for the current configuration. Both
|
|
153
|
+
* `ngOnChanges` and `items` read this computed, so the tree is validated
|
|
154
|
+
* once per signal change rather than twice.
|
|
155
|
+
*/
|
|
156
|
+
private readonly _configurationIsValid;
|
|
157
|
+
/**
|
|
158
|
+
* Child items, capped to avoid pathological configurations blocking the
|
|
159
|
+
* renderer. Non-object entries are ignored. Structural limits (depth, node
|
|
160
|
+
* count, cycles) are enforced by `_configurationIsValid`.
|
|
105
161
|
*/
|
|
106
162
|
protected readonly items: Signal<readonly IFGDynamicItem[]>;
|
|
107
163
|
private _viewContainerRef;
|
|
@@ -117,6 +173,7 @@ export declare class FGDynamicComponent implements OnChanges, OnDestroy {
|
|
|
117
173
|
private _component?;
|
|
118
174
|
private _injector;
|
|
119
175
|
private _ngOnChangesCounter;
|
|
176
|
+
private _destroyed;
|
|
120
177
|
private _lastProjectedItemsSignature?;
|
|
121
178
|
/** Group that literally contains the current control (may be a nested group). */
|
|
122
179
|
private _formControlContainer?;
|
|
@@ -129,6 +186,11 @@ export declare class FGDynamicComponent implements OnChanges, OnDestroy {
|
|
|
129
186
|
/** Form wiring currently attached to the rendered component, used to detect rebinds. */
|
|
130
187
|
private _wiredFormGroup?;
|
|
131
188
|
private _wiredControlName?;
|
|
189
|
+
/** `allowExistingControls` value used for the active wiring. */
|
|
190
|
+
private _wiredAllowExistingControls?;
|
|
191
|
+
/** Last value written to the control, used to avoid feedback loops when syncing the model. */
|
|
192
|
+
private _hasSyncedControlValue;
|
|
193
|
+
private _lastSyncedControlValue;
|
|
132
194
|
/** Disabled state managed by this component, so it can be restored when `disabled` disappears. */
|
|
133
195
|
private _disabledManaged;
|
|
134
196
|
private _disabledBeforeManagement?;
|
|
@@ -209,10 +271,24 @@ export declare class FGDynamicComponent implements OnChanges, OnDestroy {
|
|
|
209
271
|
*/
|
|
210
272
|
private bindFormControlValueChanges;
|
|
211
273
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
274
|
+
* Clones only the containers along `path`, sharing every other subtree.
|
|
275
|
+
* Accessor properties are preserved without being invoked.
|
|
276
|
+
*/
|
|
277
|
+
private cloneAlongPathForMutation;
|
|
278
|
+
/** Shallow-copies own descriptors without invoking getters. */
|
|
279
|
+
private cloneContainerShallow;
|
|
280
|
+
/**
|
|
281
|
+
* Reflects external view-model changes into the control. Values written by
|
|
282
|
+
* the control itself are skipped to avoid clobbering user input.
|
|
214
283
|
*/
|
|
215
|
-
private
|
|
284
|
+
private syncFormControlFromViewModel;
|
|
285
|
+
/** Bounded structural comparison used to detect real view-model changes. */
|
|
286
|
+
private valuesEqual;
|
|
287
|
+
/**
|
|
288
|
+
* Removes created intermediate groups that are detached or still empty.
|
|
289
|
+
* Used after a failed wiring attempt and during cleanup.
|
|
290
|
+
*/
|
|
291
|
+
private pruneCreatedFormGroups;
|
|
216
292
|
private setControlDisabled;
|
|
217
293
|
/**
|
|
218
294
|
* Restores the disabled state a control had before this component managed
|
|
@@ -311,6 +387,12 @@ export declare class FGDynamicComponent implements OnChanges, OnDestroy {
|
|
|
311
387
|
*/
|
|
312
388
|
private attributeValueToString;
|
|
313
389
|
private isSafeUrl;
|
|
390
|
+
private allowsExternalUrls;
|
|
391
|
+
/**
|
|
392
|
+
* Resolves `value` against the document base URL and compares origins. In a
|
|
393
|
+
* non-browser environment absolute URLs are treated as external.
|
|
394
|
+
*/
|
|
395
|
+
private isSameOriginUrl;
|
|
314
396
|
/**
|
|
315
397
|
* Evaluates a configured attribute value and reports whether it is an
|
|
316
398
|
* expression that could not be evaluated because its context was missing.
|
|
@@ -401,4 +483,5 @@ export declare class FGDynamicComponent implements OnChanges, OnDestroy {
|
|
|
401
483
|
}, {
|
|
402
484
|
"viewModel": "viewModelChange";
|
|
403
485
|
}, never, never, true, never>;
|
|
404
|
-
}
|
|
486
|
+
}
|
|
487
|
+
export type { FGDynamicAllowedMethod };
|