fg-dynamic-component 3.0.0 → 4.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 +77 -12
- package/fesm2022/fg-dynamic-component.mjs +1109 -285
- package/fesm2022/fg-dynamic-component.mjs.map +1 -1
- package/package.json +5 -3
- package/types/fg-dynamic-component.d.ts +204 -16
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
-
import { ChangeDetectionStrategy, Component, ElementRef,
|
|
3
|
-
import { FormControl, FormControlDirective, NG_VALUE_ACCESSOR, NgControl, Validators } from "@angular/forms";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, ElementRef, Injector, Renderer2, ViewContainerRef, computed, inject, input, isDevMode, model, viewChild, viewChildren } from "@angular/core";
|
|
3
|
+
import { FormControl, FormControlDirective, FormGroup, NG_VALUE_ACCESSOR, NgControl, Validators } from "@angular/forms";
|
|
4
4
|
const MAX_SOURCE_LENGTH = 2e3;
|
|
5
5
|
const MAX_TOKENS = 4e3;
|
|
6
6
|
const MAX_PARSE_DEPTH = 80;
|
|
7
7
|
const MAX_EVALUATION_STEPS = 2e4;
|
|
8
8
|
const MAX_EVALUATION_DEPTH = 80;
|
|
9
|
+
const MAX_STRING_LENGTH = 1e5;
|
|
10
|
+
const MAX_REPEAT_COUNT = 1e4;
|
|
9
11
|
const FORBIDDEN_PROPERTIES = /* @__PURE__ */ new Set([
|
|
10
12
|
"__proto__",
|
|
11
13
|
"prototype",
|
|
@@ -16,8 +18,208 @@ const FORBIDDEN_PROPERTIES = /* @__PURE__ */ new Set([
|
|
|
16
18
|
"__defineGetter__",
|
|
17
19
|
"__defineSetter__",
|
|
18
20
|
"__lookupGetter__",
|
|
19
|
-
"__lookupSetter__"
|
|
21
|
+
"__lookupSetter__",
|
|
22
|
+
"call",
|
|
23
|
+
"apply",
|
|
24
|
+
"bind",
|
|
25
|
+
"window",
|
|
26
|
+
"self",
|
|
27
|
+
"globalThis",
|
|
28
|
+
"global",
|
|
29
|
+
"top",
|
|
30
|
+
"parent",
|
|
31
|
+
"frames",
|
|
32
|
+
"opener",
|
|
33
|
+
"document",
|
|
34
|
+
"ownerDocument",
|
|
35
|
+
"defaultView",
|
|
36
|
+
"contentWindow",
|
|
37
|
+
"contentDocument",
|
|
38
|
+
"location",
|
|
39
|
+
"cookie",
|
|
40
|
+
"localStorage",
|
|
41
|
+
"sessionStorage",
|
|
42
|
+
"indexedDB",
|
|
43
|
+
"navigator",
|
|
44
|
+
"history",
|
|
45
|
+
"screen",
|
|
46
|
+
"fetch",
|
|
47
|
+
"XMLHttpRequest",
|
|
48
|
+
"WebSocket",
|
|
49
|
+
"Worker",
|
|
50
|
+
"importScripts",
|
|
51
|
+
"postMessage",
|
|
52
|
+
"sendBeacon",
|
|
53
|
+
"setTimeout",
|
|
54
|
+
"setInterval",
|
|
55
|
+
"setImmediate",
|
|
56
|
+
"requestAnimationFrame",
|
|
57
|
+
"open",
|
|
58
|
+
"close",
|
|
59
|
+
"write",
|
|
60
|
+
"writeln",
|
|
61
|
+
"innerHTML",
|
|
62
|
+
"outerHTML",
|
|
63
|
+
"insertAdjacentHTML",
|
|
64
|
+
"eval",
|
|
65
|
+
"Function"
|
|
20
66
|
]);
|
|
67
|
+
const SAFE_NATIVE_METHODS = /* @__PURE__ */ new Set([
|
|
68
|
+
Array.prototype.at,
|
|
69
|
+
Array.prototype.concat,
|
|
70
|
+
Array.prototype.entries,
|
|
71
|
+
Array.prototype.every,
|
|
72
|
+
Array.prototype.filter,
|
|
73
|
+
Array.prototype.find,
|
|
74
|
+
Array.prototype.findIndex,
|
|
75
|
+
Array.prototype.flat,
|
|
76
|
+
Array.prototype.flatMap,
|
|
77
|
+
Array.prototype.forEach,
|
|
78
|
+
Array.prototype.includes,
|
|
79
|
+
Array.prototype.indexOf,
|
|
80
|
+
Array.prototype.join,
|
|
81
|
+
Array.prototype.keys,
|
|
82
|
+
Array.prototype.lastIndexOf,
|
|
83
|
+
Array.prototype.map,
|
|
84
|
+
Array.prototype.reduce,
|
|
85
|
+
Array.prototype.reduceRight,
|
|
86
|
+
Array.prototype.slice,
|
|
87
|
+
Array.prototype.some,
|
|
88
|
+
Array.prototype.toLocaleString,
|
|
89
|
+
Array.prototype.toString,
|
|
90
|
+
Array.prototype.values,
|
|
91
|
+
String.prototype.at,
|
|
92
|
+
String.prototype.charAt,
|
|
93
|
+
String.prototype.charCodeAt,
|
|
94
|
+
String.prototype.codePointAt,
|
|
95
|
+
String.prototype.concat,
|
|
96
|
+
String.prototype.endsWith,
|
|
97
|
+
String.prototype.includes,
|
|
98
|
+
String.prototype.indexOf,
|
|
99
|
+
String.prototype.lastIndexOf,
|
|
100
|
+
String.prototype.localeCompare,
|
|
101
|
+
String.prototype.normalize,
|
|
102
|
+
String.prototype.padEnd,
|
|
103
|
+
String.prototype.padStart,
|
|
104
|
+
String.prototype.repeat,
|
|
105
|
+
String.prototype.replace,
|
|
106
|
+
String.prototype.replaceAll,
|
|
107
|
+
String.prototype.slice,
|
|
108
|
+
String.prototype.split,
|
|
109
|
+
String.prototype.startsWith,
|
|
110
|
+
String.prototype.substring,
|
|
111
|
+
String.prototype.substr,
|
|
112
|
+
String.prototype.toLocaleLowerCase,
|
|
113
|
+
String.prototype.toLocaleUpperCase,
|
|
114
|
+
String.prototype.toLowerCase,
|
|
115
|
+
String.prototype.toString,
|
|
116
|
+
String.prototype.toUpperCase,
|
|
117
|
+
String.prototype.trim,
|
|
118
|
+
String.prototype.trimEnd,
|
|
119
|
+
String.prototype.trimStart,
|
|
120
|
+
String.prototype.valueOf,
|
|
121
|
+
Number.prototype.toExponential,
|
|
122
|
+
Number.prototype.toFixed,
|
|
123
|
+
Number.prototype.toLocaleString,
|
|
124
|
+
Number.prototype.toPrecision,
|
|
125
|
+
Number.prototype.toString,
|
|
126
|
+
Number.prototype.valueOf,
|
|
127
|
+
Boolean.prototype.toString,
|
|
128
|
+
Boolean.prototype.valueOf,
|
|
129
|
+
BigInt.prototype.toString,
|
|
130
|
+
BigInt.prototype.valueOf,
|
|
131
|
+
Date.prototype.getDate,
|
|
132
|
+
Date.prototype.getDay,
|
|
133
|
+
Date.prototype.getFullYear,
|
|
134
|
+
Date.prototype.getHours,
|
|
135
|
+
Date.prototype.getMilliseconds,
|
|
136
|
+
Date.prototype.getMinutes,
|
|
137
|
+
Date.prototype.getMonth,
|
|
138
|
+
Date.prototype.getSeconds,
|
|
139
|
+
Date.prototype.getTime,
|
|
140
|
+
Date.prototype.getUTCDate,
|
|
141
|
+
Date.prototype.getUTCFullYear,
|
|
142
|
+
Date.prototype.toISOString,
|
|
143
|
+
Date.prototype.toJSON,
|
|
144
|
+
Date.prototype.toLocaleDateString,
|
|
145
|
+
Date.prototype.toLocaleString,
|
|
146
|
+
Date.prototype.toLocaleTimeString,
|
|
147
|
+
Date.prototype.toString,
|
|
148
|
+
Date.prototype.valueOf,
|
|
149
|
+
Object.prototype.hasOwnProperty,
|
|
150
|
+
Object.prototype.isPrototypeOf,
|
|
151
|
+
Object.prototype.propertyIsEnumerable,
|
|
152
|
+
Object.prototype.toLocaleString,
|
|
153
|
+
Object.prototype.toString,
|
|
154
|
+
Object.prototype.valueOf
|
|
155
|
+
]);
|
|
156
|
+
const INTERPRETER_FUNCTIONS = /* @__PURE__ */ new WeakSet();
|
|
157
|
+
const HOST_OBJECT_TAGS = /* @__PURE__ */ new Set([
|
|
158
|
+
"Window",
|
|
159
|
+
"global",
|
|
160
|
+
"globalThis",
|
|
161
|
+
"Document",
|
|
162
|
+
"HTMLDocument",
|
|
163
|
+
"XMLDocument",
|
|
164
|
+
"DocumentFragment",
|
|
165
|
+
"DocumentType",
|
|
166
|
+
"Node",
|
|
167
|
+
"NodeList",
|
|
168
|
+
"HTMLCollection",
|
|
169
|
+
"NamedNodeMap",
|
|
170
|
+
"Element",
|
|
171
|
+
"Event",
|
|
172
|
+
"EventTarget",
|
|
173
|
+
"CustomEvent",
|
|
174
|
+
"MouseEvent",
|
|
175
|
+
"KeyboardEvent",
|
|
176
|
+
"PointerEvent",
|
|
177
|
+
"FocusEvent",
|
|
178
|
+
"InputEvent",
|
|
179
|
+
"Storage",
|
|
180
|
+
"Location",
|
|
181
|
+
"History",
|
|
182
|
+
"Navigator",
|
|
183
|
+
"Screen",
|
|
184
|
+
"XMLHttpRequest",
|
|
185
|
+
"WebSocket",
|
|
186
|
+
"Worker",
|
|
187
|
+
"MessagePort",
|
|
188
|
+
"MessageChannel",
|
|
189
|
+
"File",
|
|
190
|
+
"FileList",
|
|
191
|
+
"FileReader",
|
|
192
|
+
"Blob",
|
|
193
|
+
"FormData",
|
|
194
|
+
"URL",
|
|
195
|
+
"URLSearchParams",
|
|
196
|
+
"MutationObserver",
|
|
197
|
+
"IntersectionObserver",
|
|
198
|
+
"ResizeObserver",
|
|
199
|
+
"Performance"
|
|
200
|
+
]);
|
|
201
|
+
function isHostObject(value) {
|
|
202
|
+
if (value == null || typeof value !== "object" && typeof value !== "function") return false;
|
|
203
|
+
if (value === globalThis) return true;
|
|
204
|
+
try {
|
|
205
|
+
const tag = Object.prototype.toString.call(value).slice(8, -1);
|
|
206
|
+
if (HOST_OBJECT_TAGS.has(tag)) return true;
|
|
207
|
+
if (/(?:Element|Event|Document|Node|Observer|Collection|List|Map)$/.test(tag) && tag !== "Map" && tag !== "WeakMap" && tag !== "Set" && tag !== "WeakSet") return true;
|
|
208
|
+
} catch {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
function isNativeFunction(value) {
|
|
214
|
+
return typeof value === "function" && SAFE_NATIVE_METHODS.has(value);
|
|
215
|
+
}
|
|
216
|
+
function isInterpreterFunction(value) {
|
|
217
|
+
return typeof value === "function" && INTERPRETER_FUNCTIONS.has(value);
|
|
218
|
+
}
|
|
219
|
+
function assertSafeValue(value) {
|
|
220
|
+
if (isHostObject(value)) fail("Access to host objects is not allowed.");
|
|
221
|
+
return value;
|
|
222
|
+
}
|
|
21
223
|
const PUNCTUATORS = [
|
|
22
224
|
"===",
|
|
23
225
|
"!==",
|
|
@@ -393,27 +595,46 @@ var ExpressionParser = class {
|
|
|
393
595
|
}
|
|
394
596
|
parseExponent() {
|
|
395
597
|
const left = this.parseUnary();
|
|
396
|
-
if (this.matchPunctuator("**"))
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
598
|
+
if (this.matchPunctuator("**")) {
|
|
599
|
+
this.enter();
|
|
600
|
+
try {
|
|
601
|
+
return {
|
|
602
|
+
type: "Binary",
|
|
603
|
+
operator: "**",
|
|
604
|
+
left,
|
|
605
|
+
right: this.parseExponent()
|
|
606
|
+
};
|
|
607
|
+
} finally {
|
|
608
|
+
this.leave();
|
|
609
|
+
}
|
|
610
|
+
}
|
|
402
611
|
return left;
|
|
403
612
|
}
|
|
404
613
|
parseUnary() {
|
|
405
|
-
if (isPunctuator(this.current(), "!") || isPunctuator(this.current(), "-") || isPunctuator(this.current(), "+"))
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
614
|
+
if (isPunctuator(this.current(), "!") || isPunctuator(this.current(), "-") || isPunctuator(this.current(), "+")) {
|
|
615
|
+
this.enter();
|
|
616
|
+
try {
|
|
617
|
+
return {
|
|
618
|
+
type: "Unary",
|
|
619
|
+
operator: this.advance().value,
|
|
620
|
+
argument: this.parseUnary()
|
|
621
|
+
};
|
|
622
|
+
} finally {
|
|
623
|
+
this.leave();
|
|
624
|
+
}
|
|
625
|
+
}
|
|
410
626
|
if (isIdentifier(this.current(), "typeof")) {
|
|
411
|
-
this.
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
627
|
+
this.enter();
|
|
628
|
+
try {
|
|
629
|
+
this.advance();
|
|
630
|
+
return {
|
|
631
|
+
type: "Unary",
|
|
632
|
+
operator: "typeof",
|
|
633
|
+
argument: this.parseUnary()
|
|
634
|
+
};
|
|
635
|
+
} finally {
|
|
636
|
+
this.leave();
|
|
637
|
+
}
|
|
417
638
|
}
|
|
418
639
|
return this.parsePostfix();
|
|
419
640
|
}
|
|
@@ -494,17 +715,22 @@ var ExpressionParser = class {
|
|
|
494
715
|
return node;
|
|
495
716
|
}
|
|
496
717
|
parseArguments() {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
spread
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
718
|
+
this.enter();
|
|
719
|
+
try {
|
|
720
|
+
const args = [];
|
|
721
|
+
if (!isPunctuator(this.current(), ")")) do {
|
|
722
|
+
if (isPunctuator(this.current(), ")")) break;
|
|
723
|
+
const spread = this.matchPunctuator("...");
|
|
724
|
+
args.push({
|
|
725
|
+
spread,
|
|
726
|
+
value: this.parseAssignment()
|
|
727
|
+
});
|
|
728
|
+
} while (this.matchPunctuator(","));
|
|
729
|
+
this.expectPunctuator(")");
|
|
730
|
+
return args;
|
|
731
|
+
} finally {
|
|
732
|
+
this.leave();
|
|
733
|
+
}
|
|
508
734
|
}
|
|
509
735
|
parsePrimary() {
|
|
510
736
|
const token = this.current();
|
|
@@ -565,70 +791,84 @@ var ExpressionParser = class {
|
|
|
565
791
|
return fail("Unexpected token in expression.");
|
|
566
792
|
}
|
|
567
793
|
parseArray() {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
spread
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
794
|
+
this.enter();
|
|
795
|
+
try {
|
|
796
|
+
const elements = [];
|
|
797
|
+
if (!isPunctuator(this.current(), "]")) do {
|
|
798
|
+
if (isPunctuator(this.current(), "]")) break;
|
|
799
|
+
const spread = this.matchPunctuator("...");
|
|
800
|
+
elements.push({
|
|
801
|
+
spread,
|
|
802
|
+
value: this.parseAssignment()
|
|
803
|
+
});
|
|
804
|
+
} while (this.matchPunctuator(","));
|
|
805
|
+
this.expectPunctuator("]");
|
|
806
|
+
return {
|
|
807
|
+
type: "Array",
|
|
808
|
+
elements
|
|
809
|
+
};
|
|
810
|
+
} finally {
|
|
811
|
+
this.leave();
|
|
812
|
+
}
|
|
582
813
|
}
|
|
583
814
|
parseObject() {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
if (this.
|
|
815
|
+
this.enter();
|
|
816
|
+
try {
|
|
817
|
+
const properties = [];
|
|
818
|
+
if (!isPunctuator(this.current(), "}")) do {
|
|
819
|
+
if (isPunctuator(this.current(), "}")) break;
|
|
820
|
+
if (this.matchPunctuator("...")) {
|
|
821
|
+
properties.push({
|
|
822
|
+
spread: true,
|
|
823
|
+
value: this.parseAssignment(),
|
|
824
|
+
computed: false
|
|
825
|
+
});
|
|
826
|
+
continue;
|
|
827
|
+
}
|
|
828
|
+
let key;
|
|
829
|
+
let computed = false;
|
|
830
|
+
if (this.matchPunctuator("[")) {
|
|
831
|
+
key = this.parseExpression();
|
|
832
|
+
this.expectPunctuator("]");
|
|
833
|
+
computed = true;
|
|
834
|
+
} else {
|
|
835
|
+
const keyToken = this.advance();
|
|
836
|
+
if (keyToken.type === "identifier" || keyToken.type === "string") key = {
|
|
837
|
+
type: "Literal",
|
|
838
|
+
value: keyToken.value
|
|
839
|
+
};
|
|
840
|
+
else if (keyToken.type === "number") key = {
|
|
841
|
+
type: "Literal",
|
|
842
|
+
value: String(Number(keyToken.value))
|
|
843
|
+
};
|
|
844
|
+
else return fail("Invalid object key.");
|
|
845
|
+
}
|
|
846
|
+
this.expectPunctuator(":");
|
|
847
|
+
const value = this.parseAssignment();
|
|
588
848
|
properties.push({
|
|
589
|
-
spread:
|
|
590
|
-
|
|
591
|
-
|
|
849
|
+
spread: false,
|
|
850
|
+
key,
|
|
851
|
+
value,
|
|
852
|
+
computed
|
|
592
853
|
});
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
const keyToken = this.advance();
|
|
603
|
-
if (keyToken.type === "identifier" || keyToken.type === "string") key = {
|
|
604
|
-
type: "Literal",
|
|
605
|
-
value: keyToken.value
|
|
606
|
-
};
|
|
607
|
-
else if (keyToken.type === "number") key = {
|
|
608
|
-
type: "Literal",
|
|
609
|
-
value: String(Number(keyToken.value))
|
|
610
|
-
};
|
|
611
|
-
else return fail("Invalid object key.");
|
|
612
|
-
}
|
|
613
|
-
this.expectPunctuator(":");
|
|
614
|
-
const value = this.parseAssignment();
|
|
615
|
-
properties.push({
|
|
616
|
-
spread: false,
|
|
617
|
-
key,
|
|
618
|
-
value,
|
|
619
|
-
computed
|
|
620
|
-
});
|
|
621
|
-
} while (this.matchPunctuator(","));
|
|
622
|
-
this.expectPunctuator("}");
|
|
623
|
-
return {
|
|
624
|
-
type: "Object",
|
|
625
|
-
properties
|
|
626
|
-
};
|
|
854
|
+
} while (this.matchPunctuator(","));
|
|
855
|
+
this.expectPunctuator("}");
|
|
856
|
+
return {
|
|
857
|
+
type: "Object",
|
|
858
|
+
properties
|
|
859
|
+
};
|
|
860
|
+
} finally {
|
|
861
|
+
this.leave();
|
|
862
|
+
}
|
|
627
863
|
}
|
|
628
864
|
};
|
|
629
865
|
function assertSafeProperty(property) {
|
|
630
866
|
if (FORBIDDEN_PROPERTIES.has(property)) fail("Access to a forbidden property was blocked.");
|
|
631
867
|
}
|
|
868
|
+
function isMethodAllowed(name, options) {
|
|
869
|
+
if (options?.allowCustomMethods === true) return true;
|
|
870
|
+
return Array.isArray(options?.allowedMethods) && options.allowedMethods.includes(name);
|
|
871
|
+
}
|
|
632
872
|
function defineSafeProperty(target, key, value) {
|
|
633
873
|
assertSafeProperty(key);
|
|
634
874
|
Object.defineProperty(target, key, {
|
|
@@ -638,7 +878,7 @@ function defineSafeProperty(target, key, value) {
|
|
|
638
878
|
configurable: true
|
|
639
879
|
});
|
|
640
880
|
}
|
|
641
|
-
function readMember(target, key, optional) {
|
|
881
|
+
function readMember(target, key, optional, options) {
|
|
642
882
|
if (typeof key !== "string" && typeof key !== "number") fail("Property keys must be strings or numbers.");
|
|
643
883
|
const property = String(key);
|
|
644
884
|
assertSafeProperty(property);
|
|
@@ -646,11 +886,36 @@ function readMember(target, key, optional) {
|
|
|
646
886
|
if (optional) return;
|
|
647
887
|
fail("Cannot read properties of null or undefined.");
|
|
648
888
|
}
|
|
649
|
-
|
|
889
|
+
if (isHostObject(target)) fail("Access to host objects is not allowed.");
|
|
890
|
+
const object = Object(target);
|
|
891
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, property);
|
|
892
|
+
if (descriptor) {
|
|
893
|
+
if (!("value" in descriptor)) fail("Access to accessor properties is not allowed.");
|
|
894
|
+
const value = descriptor.value;
|
|
895
|
+
if (typeof value === "function" && !isNativeFunction(value) && !isInterpreterFunction(value) && !isMethodAllowed(property, options)) fail("Access to custom methods is not allowed.");
|
|
896
|
+
return assertSafeValue(value);
|
|
897
|
+
}
|
|
898
|
+
let prototype = Object.getPrototypeOf(object);
|
|
899
|
+
while (prototype) {
|
|
900
|
+
const inheritedDescriptor = Object.getOwnPropertyDescriptor(prototype, property);
|
|
901
|
+
if (inheritedDescriptor) {
|
|
902
|
+
if (!("value" in inheritedDescriptor)) fail("Access to inherited accessor properties is not allowed.");
|
|
903
|
+
const inherited = inheritedDescriptor.value;
|
|
904
|
+
if (typeof inherited === "function") {
|
|
905
|
+
if (isNativeFunction(inherited) || isInterpreterFunction(inherited) || isMethodAllowed(property, options)) return inherited;
|
|
906
|
+
fail("Access to custom methods is not allowed.");
|
|
907
|
+
}
|
|
908
|
+
fail("Access to inherited properties is not allowed.");
|
|
909
|
+
}
|
|
910
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
911
|
+
}
|
|
650
912
|
}
|
|
651
913
|
function spreadValues(value) {
|
|
652
914
|
if (Array.isArray(value)) return value.slice();
|
|
653
|
-
if (typeof value === "string")
|
|
915
|
+
if (typeof value === "string") {
|
|
916
|
+
if (value.length > MAX_STRING_LENGTH) fail("Spread value is too large.");
|
|
917
|
+
return value.split("");
|
|
918
|
+
}
|
|
654
919
|
return fail("Spread is only supported for arrays and strings.");
|
|
655
920
|
}
|
|
656
921
|
function isPrimitive(value) {
|
|
@@ -685,7 +950,7 @@ function compareValues(operator, left, right) {
|
|
|
685
950
|
default: return fail(`Unsupported comparison operator "${operator}".`);
|
|
686
951
|
}
|
|
687
952
|
}
|
|
688
|
-
function evaluateNode(node, environment, state) {
|
|
953
|
+
function evaluateNode(node, environment, state, options) {
|
|
689
954
|
state.steps++;
|
|
690
955
|
state.depth++;
|
|
691
956
|
if (state.steps > MAX_EVALUATION_STEPS) {
|
|
@@ -701,38 +966,56 @@ function evaluateNode(node, environment, state) {
|
|
|
701
966
|
case "Literal": return node.value;
|
|
702
967
|
case "Identifier":
|
|
703
968
|
if (!environment.has(node.name)) return fail(`Unknown identifier "${node.name}".`);
|
|
704
|
-
return environment.get(node.name);
|
|
705
|
-
case "Member": return readMember(evaluateNode(node.object, environment, state), evaluateNode(node.property, environment, state), node.optional);
|
|
969
|
+
return assertSafeValue(environment.get(node.name));
|
|
970
|
+
case "Member": return readMember(evaluateNode(node.object, environment, state, options), evaluateNode(node.property, environment, state, options), node.optional, options);
|
|
706
971
|
case "Call": {
|
|
707
972
|
let fn;
|
|
708
973
|
let thisArg;
|
|
974
|
+
let methodName;
|
|
709
975
|
if (node.callee.type === "Member") {
|
|
710
|
-
const object = evaluateNode(node.callee.object, environment, state);
|
|
711
|
-
|
|
976
|
+
const object = evaluateNode(node.callee.object, environment, state, options);
|
|
977
|
+
const key = evaluateNode(node.callee.property, environment, state, options);
|
|
978
|
+
fn = readMember(object, key, node.callee.optional, options);
|
|
712
979
|
thisArg = object;
|
|
713
|
-
|
|
980
|
+
methodName = String(key);
|
|
981
|
+
} else fn = evaluateNode(node.callee, environment, state, options);
|
|
714
982
|
if (fn == null && node.optional) return;
|
|
715
983
|
if (typeof fn !== "function") {
|
|
716
984
|
if (node.optional) return;
|
|
717
985
|
return fail("Attempted to call a non-function value.");
|
|
718
986
|
}
|
|
719
987
|
if (fn === Function || fn === eval) return fail("Calling global constructors is not allowed.");
|
|
988
|
+
if (node.callee.type === "Member") {
|
|
989
|
+
if (!isNativeFunction(fn) && !isInterpreterFunction(fn) && !isMethodAllowed(methodName ?? "", options)) return fail("Calling custom methods is not allowed.");
|
|
990
|
+
} else if (!(node.callee.type === "Identifier" && node.callee.name === "$vm") && !isInterpreterFunction(fn) && !isMethodAllowed("", options)) return fail("Calling custom functions is not allowed.");
|
|
720
991
|
const args = [];
|
|
721
992
|
for (const argument of node.args) {
|
|
722
|
-
const value = evaluateNode(argument.value, environment, state);
|
|
993
|
+
const value = evaluateNode(argument.value, environment, state, options);
|
|
723
994
|
if (argument.spread) args.push(...spreadValues(value));
|
|
724
995
|
else args.push(value);
|
|
725
996
|
}
|
|
726
|
-
|
|
997
|
+
if (fn === String.prototype.repeat) {
|
|
998
|
+
const count = args[0];
|
|
999
|
+
const source = String(thisArg ?? "");
|
|
1000
|
+
if (typeof count !== "number" || !Number.isFinite(count) || count < 0 || count > MAX_REPEAT_COUNT || source.length * count > MAX_STRING_LENGTH) return fail("String repetition is too large.");
|
|
1001
|
+
}
|
|
1002
|
+
if (fn === String.prototype.padStart || fn === String.prototype.padEnd) {
|
|
1003
|
+
const targetLength = args[0];
|
|
1004
|
+
if (typeof targetLength === "number" && targetLength > MAX_STRING_LENGTH) return fail("String padding is too large.");
|
|
1005
|
+
}
|
|
1006
|
+
if (fn === Array.prototype.join && Array.isArray(thisArg) && thisArg.length > MAX_STRING_LENGTH) return fail("Array join is too large.");
|
|
1007
|
+
const result = fn.apply(thisArg, args);
|
|
1008
|
+
if (typeof result === "string" && result.length > MAX_STRING_LENGTH) return fail("Expression result is too large.");
|
|
1009
|
+
return assertSafeValue(result);
|
|
727
1010
|
}
|
|
728
1011
|
case "Unary": {
|
|
729
|
-
const argument = evaluateNode(node.argument, environment, state);
|
|
1012
|
+
const argument = evaluateNode(node.argument, environment, state, options);
|
|
730
1013
|
switch (node.operator) {
|
|
731
1014
|
case "!": return !argument;
|
|
732
1015
|
case "typeof": return typeof argument;
|
|
733
1016
|
case "-":
|
|
734
1017
|
if (typeof argument !== "number" && typeof argument !== "bigint") return fail("Unary \"-\" only supports numbers.");
|
|
735
|
-
return
|
|
1018
|
+
return -argument;
|
|
736
1019
|
case "+":
|
|
737
1020
|
if (typeof argument !== "number") return fail("Unary \"+\" only supports numbers.");
|
|
738
1021
|
return +argument;
|
|
@@ -740,8 +1023,8 @@ function evaluateNode(node, environment, state) {
|
|
|
740
1023
|
}
|
|
741
1024
|
}
|
|
742
1025
|
case "Binary": {
|
|
743
|
-
const left = evaluateNode(node.left, environment, state);
|
|
744
|
-
const right = evaluateNode(node.right, environment, state);
|
|
1026
|
+
const left = evaluateNode(node.left, environment, state, options);
|
|
1027
|
+
const right = evaluateNode(node.right, environment, state, options);
|
|
745
1028
|
switch (node.operator) {
|
|
746
1029
|
case "===": return left === right;
|
|
747
1030
|
case "!==": return left !== right;
|
|
@@ -761,19 +1044,19 @@ function evaluateNode(node, environment, state) {
|
|
|
761
1044
|
}
|
|
762
1045
|
}
|
|
763
1046
|
case "Logical": {
|
|
764
|
-
const left = evaluateNode(node.left, environment, state);
|
|
1047
|
+
const left = evaluateNode(node.left, environment, state, options);
|
|
765
1048
|
switch (node.operator) {
|
|
766
|
-
case "&&": return left ? evaluateNode(node.right, environment, state) : left;
|
|
767
|
-
case "||": return left ? left : evaluateNode(node.right, environment, state);
|
|
768
|
-
case "??": return left == null ? evaluateNode(node.right, environment, state) : left;
|
|
1049
|
+
case "&&": return left ? evaluateNode(node.right, environment, state, options) : left;
|
|
1050
|
+
case "||": return left ? left : evaluateNode(node.right, environment, state, options);
|
|
1051
|
+
case "??": return left == null ? evaluateNode(node.right, environment, state, options) : left;
|
|
769
1052
|
default: return fail(`Unsupported logical operator "${node.operator}".`);
|
|
770
1053
|
}
|
|
771
1054
|
}
|
|
772
|
-
case "Conditional": return evaluateNode(node.test, environment, state) ? evaluateNode(node.consequent, environment, state) : evaluateNode(node.alternate, environment, state);
|
|
1055
|
+
case "Conditional": return evaluateNode(node.test, environment, state, options) ? evaluateNode(node.consequent, environment, state, options) : evaluateNode(node.alternate, environment, state, options);
|
|
773
1056
|
case "Array": {
|
|
774
1057
|
const values = [];
|
|
775
1058
|
for (const element of node.elements) {
|
|
776
|
-
const value = evaluateNode(element.value, environment, state);
|
|
1059
|
+
const value = evaluateNode(element.value, environment, state, options);
|
|
777
1060
|
if (element.spread) values.push(...spreadValues(value));
|
|
778
1061
|
else values.push(value);
|
|
779
1062
|
}
|
|
@@ -783,7 +1066,7 @@ function evaluateNode(node, environment, state) {
|
|
|
783
1066
|
const result = {};
|
|
784
1067
|
for (const property of node.properties) {
|
|
785
1068
|
if (property.spread) {
|
|
786
|
-
const source = evaluateNode(property.value, environment, state);
|
|
1069
|
+
const source = evaluateNode(property.value, environment, state, options);
|
|
787
1070
|
if (source == null || typeof source !== "object") return fail("Object spread is only supported for objects.");
|
|
788
1071
|
for (const key of Object.keys(source)) {
|
|
789
1072
|
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
@@ -792,9 +1075,9 @@ function evaluateNode(node, environment, state) {
|
|
|
792
1075
|
continue;
|
|
793
1076
|
}
|
|
794
1077
|
if (!property.key) return fail("Invalid object property.");
|
|
795
|
-
const key = property.computed ? evaluateNode(property.key, environment, state) : property.key.value;
|
|
1078
|
+
const key = property.computed ? evaluateNode(property.key, environment, state, options) : property.key.value;
|
|
796
1079
|
if (typeof key !== "string" && typeof key !== "number") return fail("Object keys must be strings or numbers.");
|
|
797
|
-
defineSafeProperty(result, String(key), evaluateNode(property.value, environment, state));
|
|
1080
|
+
defineSafeProperty(result, String(key), evaluateNode(property.value, environment, state, options));
|
|
798
1081
|
}
|
|
799
1082
|
return result;
|
|
800
1083
|
}
|
|
@@ -802,13 +1085,15 @@ function evaluateNode(node, environment, state) {
|
|
|
802
1085
|
const params = node.params;
|
|
803
1086
|
const body = node.body;
|
|
804
1087
|
const closure = new Map(environment);
|
|
805
|
-
|
|
1088
|
+
const arrowFunction = function evaluateArrowFunction(...args) {
|
|
806
1089
|
const local = new Map(closure);
|
|
807
1090
|
params.forEach((parameter, index) => {
|
|
808
1091
|
local.set(parameter, args[index]);
|
|
809
1092
|
});
|
|
810
|
-
return evaluateNode(body, local, state);
|
|
1093
|
+
return evaluateNode(body, local, state, options);
|
|
811
1094
|
};
|
|
1095
|
+
INTERPRETER_FUNCTIONS.add(arrowFunction);
|
|
1096
|
+
return arrowFunction;
|
|
812
1097
|
}
|
|
813
1098
|
default: return fail("Unsupported expression node.");
|
|
814
1099
|
}
|
|
@@ -816,17 +1101,17 @@ function evaluateNode(node, environment, state) {
|
|
|
816
1101
|
state.depth--;
|
|
817
1102
|
}
|
|
818
1103
|
}
|
|
819
|
-
function evaluateSafeExpression(source, variables = {}) {
|
|
1104
|
+
function evaluateSafeExpression(source, variables = {}, options) {
|
|
820
1105
|
if (typeof source !== "string") fail("Expression must be a string.");
|
|
821
1106
|
if (source.length === 0) fail("Expression is empty.");
|
|
822
1107
|
if (source.length > MAX_SOURCE_LENGTH) fail("Expression is too long.");
|
|
823
1108
|
const ast = new ExpressionParser(tokenize(source)).parse();
|
|
824
1109
|
const environment = /* @__PURE__ */ new Map();
|
|
825
1110
|
for (const [key, value] of Object.entries(variables)) environment.set(key, value);
|
|
826
|
-
return evaluateNode(ast, environment, {
|
|
1111
|
+
return assertSafeValue(evaluateNode(ast, environment, {
|
|
827
1112
|
steps: 0,
|
|
828
1113
|
depth: 0
|
|
829
|
-
});
|
|
1114
|
+
}, options));
|
|
830
1115
|
}
|
|
831
1116
|
const FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set([
|
|
832
1117
|
"__proto__",
|
|
@@ -836,6 +1121,10 @@ const FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
836
1121
|
const MAX_PATH_DEPTH = 32;
|
|
837
1122
|
const MAX_PATH_SEGMENT_LENGTH = 128;
|
|
838
1123
|
const MAX_CONFIGURATION_ITEMS = 1e3;
|
|
1124
|
+
const MAX_CONFIGURATION_DEPTH = 32;
|
|
1125
|
+
const MAX_TOTAL_CONFIGURATION_NODES = 2e3;
|
|
1126
|
+
const MAX_CONFIGURATION_KEYS = 100;
|
|
1127
|
+
const MAX_CONFIGURATION_KEY_LENGTH = 128;
|
|
839
1128
|
const MAX_ATTRIBUTE_NAME_LENGTH = 128;
|
|
840
1129
|
const MAX_ATTRIBUTE_VALUE_LENGTH = 8192;
|
|
841
1130
|
const MAX_PATTERN_LENGTH = 512;
|
|
@@ -871,6 +1160,22 @@ const ALLOWED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
|
871
1160
|
"src"
|
|
872
1161
|
]);
|
|
873
1162
|
const URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src"]);
|
|
1163
|
+
const STRICT_DISALLOWED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
1164
|
+
"id",
|
|
1165
|
+
"class",
|
|
1166
|
+
"for",
|
|
1167
|
+
"href",
|
|
1168
|
+
"src"
|
|
1169
|
+
]);
|
|
1170
|
+
const BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
1171
|
+
"hidden",
|
|
1172
|
+
"disabled",
|
|
1173
|
+
"readonly",
|
|
1174
|
+
"required",
|
|
1175
|
+
"checked",
|
|
1176
|
+
"selected",
|
|
1177
|
+
"multiple"
|
|
1178
|
+
]);
|
|
874
1179
|
var FGDynamicRegistry = class {
|
|
875
1180
|
constructor() {
|
|
876
1181
|
this._components = /* @__PURE__ */ new Map();
|
|
@@ -926,8 +1231,15 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
926
1231
|
this.viewModel = model(...ngDevMode ? [void 0, { debugName: "viewModel" }] : /* istanbul ignore next */ []);
|
|
927
1232
|
this.formGroup = input(...ngDevMode ? [void 0, { debugName: "formGroup" }] : /* istanbul ignore next */ []);
|
|
928
1233
|
this.registry = input(FGDynamicService.registry, ...ngDevMode ? [{ debugName: "registry" }] : /* istanbul ignore next */ []);
|
|
1234
|
+
this.expressionPolicy = input({}, ...ngDevMode ? [{ debugName: "expressionPolicy" }] : /* istanbul ignore next */ []);
|
|
1235
|
+
this.formControlPolicy = input({}, ...ngDevMode ? [{ debugName: "formControlPolicy" }] : /* istanbul ignore next */ []);
|
|
1236
|
+
this.typePolicy = input({}, ...ngDevMode ? [{ debugName: "typePolicy" }] : /* istanbul ignore next */ []);
|
|
1237
|
+
this.attributePolicy = input({}, ...ngDevMode ? [{ debugName: "attributePolicy" }] : /* istanbul ignore next */ []);
|
|
1238
|
+
this.depth = input(0, ...ngDevMode ? [{ debugName: "depth" }] : /* istanbul ignore next */ []);
|
|
929
1239
|
this.items = computed(() => {
|
|
1240
|
+
if (this.depth() >= MAX_CONFIGURATION_DEPTH) return [];
|
|
930
1241
|
const configuration = this.configuration();
|
|
1242
|
+
if (!this.validateConfiguration(configuration)) return [];
|
|
931
1243
|
const items = configuration && typeof configuration === "object" && !Array.isArray(configuration) ? configuration.items : void 0;
|
|
932
1244
|
if (!Array.isArray(items)) return [];
|
|
933
1245
|
return items.filter((item) => item != null && typeof item === "object" && !Array.isArray(item)).slice(0, MAX_CONFIGURATION_ITEMS);
|
|
@@ -945,6 +1257,11 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
945
1257
|
this._managedValidatorFns = [];
|
|
946
1258
|
this._injector = inject(Injector);
|
|
947
1259
|
this._ngOnChangesCounter = 0;
|
|
1260
|
+
this._ownsFormControl = false;
|
|
1261
|
+
this._createdFormGroups = [];
|
|
1262
|
+
this._disabledManaged = false;
|
|
1263
|
+
this._appliedAttributes = /* @__PURE__ */ new Set();
|
|
1264
|
+
this._appliedInputs = /* @__PURE__ */ new Set();
|
|
948
1265
|
}
|
|
949
1266
|
async ngOnChanges(changes) {
|
|
950
1267
|
const counter = ++this._ngOnChangesCounter;
|
|
@@ -952,9 +1269,15 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
952
1269
|
const configuration = this.configuration();
|
|
953
1270
|
if (configuration != null && (typeof configuration !== "object" || Array.isArray(configuration))) {
|
|
954
1271
|
this.logError("Invalid configuration: expected an object.");
|
|
1272
|
+
this.clearResolvedComponent(counter);
|
|
1273
|
+
return;
|
|
1274
|
+
}
|
|
1275
|
+
if (!this.validateConfiguration(configuration)) {
|
|
1276
|
+
this.logError("Invalid configuration: it exceeds the structural limits.");
|
|
1277
|
+
this.clearResolvedComponent(counter);
|
|
955
1278
|
return;
|
|
956
1279
|
}
|
|
957
|
-
await this.loadComponentAsync();
|
|
1280
|
+
await this.loadComponentAsync(counter);
|
|
958
1281
|
if (counter !== this._ngOnChangesCounter) return;
|
|
959
1282
|
const items = this.items();
|
|
960
1283
|
const itemsSignature = items.length > 0 ? `${items.length}:${items.map((item, index) => `${index}:${item?.type}`).join("|")}` : "";
|
|
@@ -962,6 +1285,7 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
962
1285
|
this.cleanup();
|
|
963
1286
|
this._lastProjectedItemsSignature = itemsSignature;
|
|
964
1287
|
} else if (!this._componentRef) this._lastProjectedItemsSignature = itemsSignature;
|
|
1288
|
+
this.rewireFormIfNeeded();
|
|
965
1289
|
this.createComponent();
|
|
966
1290
|
if (counter !== this._ngOnChangesCounter) return;
|
|
967
1291
|
this.setInputs();
|
|
@@ -971,36 +1295,119 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
971
1295
|
this.handleOutputsIfChanged();
|
|
972
1296
|
if (this._componentRef?.changeDetectorRef) this._componentRef.changeDetectorRef.markForCheck();
|
|
973
1297
|
} catch (error) {
|
|
974
|
-
|
|
1298
|
+
if (counter === this._ngOnChangesCounter) {
|
|
1299
|
+
this.logError("Error during component initialization.", error);
|
|
1300
|
+
this.clearResolvedComponent(counter);
|
|
1301
|
+
}
|
|
975
1302
|
}
|
|
976
1303
|
}
|
|
977
|
-
|
|
1304
|
+
clearResolvedComponent(counter) {
|
|
1305
|
+
if (counter !== this._ngOnChangesCounter) return;
|
|
1306
|
+
this._component = void 0;
|
|
1307
|
+
if (this._componentRef) this.cleanup();
|
|
1308
|
+
}
|
|
1309
|
+
validateConfiguration(configuration) {
|
|
1310
|
+
if (configuration == null) return true;
|
|
1311
|
+
const stats = this.collectConfigurationStats(configuration);
|
|
1312
|
+
if (!stats) return false;
|
|
1313
|
+
return this.depth() + stats.maxDepth <= MAX_CONFIGURATION_DEPTH && stats.nodes <= MAX_TOTAL_CONFIGURATION_NODES;
|
|
1314
|
+
}
|
|
1315
|
+
collectConfigurationStats(configuration) {
|
|
1316
|
+
const stack = [{
|
|
1317
|
+
item: configuration,
|
|
1318
|
+
depth: 0
|
|
1319
|
+
}];
|
|
1320
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1321
|
+
let nodes = 0;
|
|
1322
|
+
let maxDepth = 0;
|
|
1323
|
+
while (stack.length > 0) {
|
|
1324
|
+
const current = stack.pop();
|
|
1325
|
+
const item = current.item;
|
|
1326
|
+
if (item == null || typeof item !== "object" || Array.isArray(item)) return null;
|
|
1327
|
+
if (seen.has(item)) return null;
|
|
1328
|
+
seen.add(item);
|
|
1329
|
+
nodes++;
|
|
1330
|
+
if (nodes > MAX_TOTAL_CONFIGURATION_NODES || current.depth > MAX_CONFIGURATION_DEPTH) return null;
|
|
1331
|
+
if (current.depth > maxDepth) maxDepth = current.depth;
|
|
1332
|
+
for (const field of [
|
|
1333
|
+
"inputs",
|
|
1334
|
+
"attributes",
|
|
1335
|
+
"outputs"
|
|
1336
|
+
]) {
|
|
1337
|
+
const map = item[field];
|
|
1338
|
+
if (map == null) continue;
|
|
1339
|
+
if (typeof map !== "object" || Array.isArray(map)) return null;
|
|
1340
|
+
const keys = Object.keys(map);
|
|
1341
|
+
if (keys.length > MAX_CONFIGURATION_KEYS) return null;
|
|
1342
|
+
if (keys.some((key) => key.length > MAX_CONFIGURATION_KEY_LENGTH || FORBIDDEN_PATH_SEGMENTS.has(key.toLowerCase()))) return null;
|
|
1343
|
+
}
|
|
1344
|
+
const items = item["items"];
|
|
1345
|
+
if (items == null) continue;
|
|
1346
|
+
if (!Array.isArray(items) || items.length > MAX_CONFIGURATION_ITEMS) return null;
|
|
1347
|
+
for (const child of items) stack.push({
|
|
1348
|
+
item: child,
|
|
1349
|
+
depth: current.depth + 1
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
return {
|
|
1353
|
+
nodes,
|
|
1354
|
+
maxDepth
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
async loadComponentAsync(counter) {
|
|
978
1358
|
const configurationType = this.configuration()?.type;
|
|
979
|
-
if (configurationType == null)
|
|
1359
|
+
if (configurationType == null) {
|
|
1360
|
+
this.clearResolvedComponent(counter);
|
|
1361
|
+
return;
|
|
1362
|
+
}
|
|
1363
|
+
if (this.typePolicy()?.requireScopedRegistry === true && this.isUsingGlobalRegistry()) {
|
|
1364
|
+
this.logWarning("A scoped registry is required by typePolicy but only the global registry is available.");
|
|
1365
|
+
this.clearResolvedComponent(counter);
|
|
1366
|
+
return;
|
|
1367
|
+
}
|
|
980
1368
|
let candidate;
|
|
981
1369
|
if (typeof configurationType === "string") {
|
|
982
1370
|
candidate = this.getRegistry().get(configurationType);
|
|
983
1371
|
if (candidate == null) {
|
|
984
1372
|
this.logWarning(`Component type "${configurationType}" not found in the registry.`);
|
|
1373
|
+
this.clearResolvedComponent(counter);
|
|
985
1374
|
return;
|
|
986
1375
|
}
|
|
987
1376
|
} else candidate = configurationType;
|
|
1377
|
+
if (!this.isCandidateAllowed(candidate)) {
|
|
1378
|
+
this.logWarning("Component type was rejected by typePolicy (function/promise types are disabled).");
|
|
1379
|
+
this.clearResolvedComponent(counter);
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
988
1382
|
try {
|
|
989
1383
|
const resolved = this.resolveCandidate(candidate);
|
|
990
|
-
const resolvedType = resolved
|
|
991
|
-
if (
|
|
1384
|
+
const resolvedType = this.isPromiseLike(resolved) ? await resolved : resolved;
|
|
1385
|
+
if (counter !== this._ngOnChangesCounter) return;
|
|
1386
|
+
if (!resolvedType) {
|
|
1387
|
+
this.clearResolvedComponent(counter);
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
if (this._component !== resolvedType) {
|
|
1391
|
+
this.cleanup();
|
|
1392
|
+
this._component = resolvedType;
|
|
1393
|
+
}
|
|
992
1394
|
} catch (error) {
|
|
1395
|
+
if (counter !== this._ngOnChangesCounter) return;
|
|
993
1396
|
this.logError("Unable to resolve the dynamic component type.", error);
|
|
1397
|
+
this.clearResolvedComponent(counter);
|
|
994
1398
|
}
|
|
995
1399
|
}
|
|
1400
|
+
isPromiseLike(value) {
|
|
1401
|
+
return value != null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
1402
|
+
}
|
|
996
1403
|
resolveCandidate(candidate) {
|
|
997
1404
|
if (candidate == null) return;
|
|
998
|
-
if (candidate
|
|
1405
|
+
if (this.isPromiseLike(candidate)) return Promise.resolve(candidate).then((resolved) => this.toComponentType(resolved));
|
|
999
1406
|
if (typeof candidate === "function") {
|
|
1000
1407
|
if (this.isAngularComponentType(candidate)) return candidate;
|
|
1001
1408
|
if (candidate.length > 0) return candidate;
|
|
1002
1409
|
const result = candidate();
|
|
1003
|
-
if (result
|
|
1410
|
+
if (this.isPromiseLike(result)) return Promise.resolve(result).then((resolved) => this.toComponentType(resolved));
|
|
1004
1411
|
return this.toComponentType(result);
|
|
1005
1412
|
}
|
|
1006
1413
|
this.logWarning("Invalid component type in configuration.");
|
|
@@ -1013,6 +1420,15 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1013
1420
|
const metadata = candidate;
|
|
1014
1421
|
return Boolean(metadata["ɵcmp"] || metadata["ɵdir"] || metadata["ɵpipe"] || metadata["ɵfac"] || metadata["ngComponentDef"] || metadata["ngDirectiveDef"]);
|
|
1015
1422
|
}
|
|
1423
|
+
isCandidateAllowed(candidate) {
|
|
1424
|
+
if (candidate == null) return false;
|
|
1425
|
+
if (this.typePolicy()?.allowFunctionTypes === true) return true;
|
|
1426
|
+
return typeof candidate === "function" && this.isAngularComponentType(candidate);
|
|
1427
|
+
}
|
|
1428
|
+
isUsingGlobalRegistry() {
|
|
1429
|
+
const registry = this.registry();
|
|
1430
|
+
return registry == null || registry === FGDynamicService.registry;
|
|
1431
|
+
}
|
|
1016
1432
|
getRegistry() {
|
|
1017
1433
|
return this.registry() ?? FGDynamicService.registry;
|
|
1018
1434
|
}
|
|
@@ -1020,20 +1436,17 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1020
1436
|
if (this._componentRef && this._component !== this._componentRef.componentType) this.cleanup();
|
|
1021
1437
|
if (this._component && !this._componentRef && this._viewContainerRef()) {
|
|
1022
1438
|
let injector = void 0;
|
|
1023
|
-
const
|
|
1024
|
-
const
|
|
1025
|
-
if (
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
parent: this._injector
|
|
1035
|
-
});
|
|
1036
|
-
} else if (typeof evaluatedName === "string") this.logWarning("Unsafe form control name was ignored.");
|
|
1439
|
+
const formGroup = this.formGroup();
|
|
1440
|
+
const controlName = this.resolveFormControlName();
|
|
1441
|
+
if (formGroup && controlName) {
|
|
1442
|
+
this._formControlDirective = new FormControlDirective(null, null, null, null);
|
|
1443
|
+
injector = Injector.create({
|
|
1444
|
+
providers: [{
|
|
1445
|
+
provide: NgControl,
|
|
1446
|
+
useValue: this._formControlDirective
|
|
1447
|
+
}],
|
|
1448
|
+
parent: this._injector
|
|
1449
|
+
});
|
|
1037
1450
|
}
|
|
1038
1451
|
const dynamicItems = this._dynamicItems();
|
|
1039
1452
|
this._componentRef = this._viewContainerRef().createComponent(this._component, {
|
|
@@ -1042,7 +1455,7 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1042
1455
|
});
|
|
1043
1456
|
if (this._componentRef?.changeDetectorRef) this._componentRef.changeDetectorRef.markForCheck();
|
|
1044
1457
|
this.handleOutputs();
|
|
1045
|
-
this.
|
|
1458
|
+
this.wireFormControl();
|
|
1046
1459
|
}
|
|
1047
1460
|
}
|
|
1048
1461
|
handleOutputs() {
|
|
@@ -1060,21 +1473,26 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1060
1473
|
const instance = this._componentRef.instance;
|
|
1061
1474
|
for (const outputName of Object.keys(outputs)) {
|
|
1062
1475
|
const emitter = instance[outputName];
|
|
1063
|
-
if (!(emitter
|
|
1064
|
-
|
|
1476
|
+
if (!this.isOutputEmitter(emitter)) continue;
|
|
1477
|
+
const subscription = emitter.subscribe(($event) => {
|
|
1065
1478
|
try {
|
|
1066
1479
|
const expr = outputs[outputName];
|
|
1067
1480
|
const viewModelValue = this.getViewModelValue();
|
|
1068
|
-
const result = typeof expr === "string" ? this.evaluateExpression(expr,
|
|
1481
|
+
const result = typeof expr === "string" ? this.evaluateExpression(expr, viewModelValue, $event, true) : expr;
|
|
1069
1482
|
if (typeof result === "function") result.call(viewModelValue, $event);
|
|
1070
|
-
else if (typeof expr === "function") expr.call(viewModelValue, $event);
|
|
1071
1483
|
} catch (error) {
|
|
1072
1484
|
this.logError("Error handling output.", error);
|
|
1073
1485
|
}
|
|
1074
|
-
})
|
|
1486
|
+
});
|
|
1487
|
+
if (subscription && typeof subscription.unsubscribe === "function") this._outputsSubscriptions.push(subscription);
|
|
1075
1488
|
}
|
|
1076
1489
|
}
|
|
1077
1490
|
}
|
|
1491
|
+
isOutputEmitter(value) {
|
|
1492
|
+
if (value == null) return false;
|
|
1493
|
+
const emitter = value;
|
|
1494
|
+
return typeof emitter["subscribe"] === "function" && typeof emitter["emit"] === "function";
|
|
1495
|
+
}
|
|
1078
1496
|
handleOutputsIfChanged() {
|
|
1079
1497
|
const outputs = this.configuration()?.outputs;
|
|
1080
1498
|
const current = this._currentOutputsConfig;
|
|
@@ -1094,158 +1512,261 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1094
1512
|
return;
|
|
1095
1513
|
}
|
|
1096
1514
|
}
|
|
1097
|
-
|
|
1515
|
+
resolveFormControlName() {
|
|
1098
1516
|
const attributes = this.configuration()?.attributes;
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1517
|
+
if (!attributes || !Object.hasOwn(attributes, "name")) return;
|
|
1518
|
+
const nameAttr = attributes["name"];
|
|
1519
|
+
if (nameAttr == null) return;
|
|
1520
|
+
const viewModelValue = this.getViewModelValue();
|
|
1521
|
+
if (viewModelValue == null) return;
|
|
1522
|
+
const name = this.evaluateExpression(nameAttr, viewModelValue);
|
|
1523
|
+
if (typeof name !== "string" || name.length === 0) return;
|
|
1524
|
+
if (!this.isSafePath(name)) {
|
|
1525
|
+
this.logWarning("Unsafe form control name was ignored.");
|
|
1526
|
+
return;
|
|
1527
|
+
}
|
|
1528
|
+
const allowedNames = this.formControlPolicy()?.allowedControlNames;
|
|
1529
|
+
if (allowedNames !== void 0 && (!Array.isArray(allowedNames) || !allowedNames.includes(name))) {
|
|
1530
|
+
this.logWarning("Form control name was rejected by formControlPolicy.");
|
|
1531
|
+
return;
|
|
1532
|
+
}
|
|
1533
|
+
return name;
|
|
1534
|
+
}
|
|
1535
|
+
rewireFormIfNeeded() {
|
|
1536
|
+
if (!this._componentRef) return;
|
|
1537
|
+
const formGroup = this.formGroup();
|
|
1538
|
+
const controlName = this.resolveFormControlName();
|
|
1539
|
+
const desiredGroup = formGroup && controlName ? formGroup : void 0;
|
|
1540
|
+
if (this._wiredFormGroup !== desiredGroup || this._wiredControlName !== controlName) this.cleanup();
|
|
1541
|
+
}
|
|
1542
|
+
wireFormControl() {
|
|
1543
|
+
const formGroup = this.formGroup();
|
|
1544
|
+
const name = this.resolveFormControlName();
|
|
1545
|
+
if (!formGroup || !name) {
|
|
1546
|
+
this._wiredFormGroup = void 0;
|
|
1547
|
+
this._wiredControlName = void 0;
|
|
1548
|
+
return;
|
|
1549
|
+
}
|
|
1550
|
+
const path = this.parsePath(name);
|
|
1551
|
+
if (!path) {
|
|
1552
|
+
this._wiredFormGroup = void 0;
|
|
1553
|
+
this._wiredControlName = void 0;
|
|
1554
|
+
return;
|
|
1555
|
+
}
|
|
1556
|
+
const parent = this.ensureFormGroupPath(formGroup, path.slice(0, -1));
|
|
1557
|
+
if (!parent) {
|
|
1558
|
+
this._wiredFormGroup = void 0;
|
|
1559
|
+
this._wiredControlName = void 0;
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
const key = path[path.length - 1];
|
|
1563
|
+
const existing = parent.get(key);
|
|
1564
|
+
if (existing) {
|
|
1565
|
+
if (this.formControlPolicy()?.allowExistingControls !== true) {
|
|
1566
|
+
this.logWarning("A form control with the requested name already exists; reuse is disabled by formControlPolicy.");
|
|
1567
|
+
this._wiredFormGroup = void 0;
|
|
1568
|
+
this._wiredControlName = void 0;
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1571
|
+
if (!(existing instanceof FormControl)) {
|
|
1572
|
+
this.logWarning("A form control with the requested name already exists and is not a FormControl.");
|
|
1573
|
+
this._wiredFormGroup = void 0;
|
|
1574
|
+
this._wiredControlName = void 0;
|
|
1575
|
+
return;
|
|
1576
|
+
}
|
|
1577
|
+
this.logWarning("A form control with the requested name already exists; reusing it.");
|
|
1578
|
+
this._formControl = existing;
|
|
1579
|
+
this._ownsFormControl = false;
|
|
1580
|
+
} else {
|
|
1581
|
+
const control = new FormControl(this.getModelPropertyValue(this.getViewModelValue(), name, null));
|
|
1582
|
+
try {
|
|
1583
|
+
parent.addControl(key, control);
|
|
1584
|
+
this._formControl = control;
|
|
1585
|
+
this._ownsFormControl = true;
|
|
1586
|
+
} catch (error) {
|
|
1587
|
+
this.logError("Error adding form control.", error);
|
|
1588
|
+
return;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
this._formControlContainer = parent;
|
|
1592
|
+
this._formControlKey = key;
|
|
1593
|
+
this._wiredFormGroup = formGroup;
|
|
1594
|
+
this._wiredControlName = name;
|
|
1595
|
+
this._disabledBeforeManagement = this._formControl.disabled;
|
|
1596
|
+
this.attachFormControlDirective();
|
|
1597
|
+
this.bindFormControlValueChanges(name);
|
|
1598
|
+
}
|
|
1599
|
+
ensureFormGroupPath(root, segments) {
|
|
1600
|
+
let current = root;
|
|
1601
|
+
for (const segment of segments) {
|
|
1602
|
+
const existing = current.get(segment);
|
|
1603
|
+
if (existing == null) {
|
|
1604
|
+
const group = new FormGroup({});
|
|
1112
1605
|
try {
|
|
1113
|
-
|
|
1114
|
-
else formGroup.addControl(name, this._formControl);
|
|
1606
|
+
current.addControl(segment, group);
|
|
1115
1607
|
} catch (error) {
|
|
1116
|
-
this.logError("Error
|
|
1608
|
+
this.logError("Error creating nested form group.", error);
|
|
1609
|
+
return null;
|
|
1117
1610
|
}
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
viewModel = structuredClone(this.viewModel());
|
|
1123
|
-
} catch {
|
|
1124
|
-
try {
|
|
1125
|
-
viewModel = JSON.parse(JSON.stringify(this.viewModel()));
|
|
1126
|
-
} catch {
|
|
1127
|
-
viewModel = this.viewModel();
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
this.setModelPropertyValue(viewModel, name, value);
|
|
1131
|
-
try {
|
|
1132
|
-
this.viewModel.set(viewModel);
|
|
1133
|
-
} catch (error) {
|
|
1134
|
-
this.logError("Error updating view model.", error);
|
|
1135
|
-
}
|
|
1611
|
+
this._createdFormGroups.push({
|
|
1612
|
+
parent: current,
|
|
1613
|
+
key: segment,
|
|
1614
|
+
group
|
|
1136
1615
|
});
|
|
1137
|
-
|
|
1138
|
-
} else if (
|
|
1616
|
+
current = group;
|
|
1617
|
+
} else if (existing instanceof FormGroup) {
|
|
1618
|
+
if (this.formControlPolicy()?.allowExistingControls !== true) {
|
|
1619
|
+
this.logWarning(`Cannot reuse existing nested form group "${segment}" because formControlPolicy disables it.`);
|
|
1620
|
+
return null;
|
|
1621
|
+
}
|
|
1622
|
+
current = existing;
|
|
1623
|
+
} else {
|
|
1624
|
+
this.logWarning(`Cannot create nested form group "${segment}" because a different control already exists.`);
|
|
1625
|
+
return null;
|
|
1626
|
+
}
|
|
1139
1627
|
}
|
|
1628
|
+
return current;
|
|
1629
|
+
}
|
|
1630
|
+
bindFormControlValueChanges(name) {
|
|
1631
|
+
if (this._formControlSubscription) try {
|
|
1632
|
+
this._formControlSubscription.unsubscribe();
|
|
1633
|
+
} catch (e) {}
|
|
1634
|
+
this._formControlSubscription = this._formControl.valueChanges.subscribe((value) => {
|
|
1635
|
+
const currentModel = this.getViewModelValue();
|
|
1636
|
+
if (currentModel == null) return;
|
|
1637
|
+
const viewModel = this.cloneForMutation(currentModel);
|
|
1638
|
+
this.setModelPropertyValue(viewModel, name, value);
|
|
1639
|
+
try {
|
|
1640
|
+
this.viewModel.set(viewModel);
|
|
1641
|
+
if (this._componentRef?.changeDetectorRef) this._componentRef.changeDetectorRef.markForCheck();
|
|
1642
|
+
} catch (error) {
|
|
1643
|
+
this.logError("Error updating view model.", error);
|
|
1644
|
+
}
|
|
1645
|
+
});
|
|
1646
|
+
}
|
|
1647
|
+
cloneForMutation(value, seen = /* @__PURE__ */ new WeakMap()) {
|
|
1648
|
+
if (value == null || typeof value !== "object") return value;
|
|
1649
|
+
const source = value;
|
|
1650
|
+
if (seen.has(source)) return seen.get(source);
|
|
1651
|
+
if (Array.isArray(value)) {
|
|
1652
|
+
const copy = [];
|
|
1653
|
+
seen.set(source, copy);
|
|
1654
|
+
for (const item of value) copy.push(this.cloneForMutation(item, seen));
|
|
1655
|
+
return copy;
|
|
1656
|
+
}
|
|
1657
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1658
|
+
if (prototype === Object.prototype || prototype === null) {
|
|
1659
|
+
const copy = {};
|
|
1660
|
+
seen.set(source, copy);
|
|
1661
|
+
for (const key of Object.keys(value)) this.defineOwn(copy, key, this.cloneForMutation(value[key], seen));
|
|
1662
|
+
return copy;
|
|
1663
|
+
}
|
|
1664
|
+
return value;
|
|
1665
|
+
}
|
|
1666
|
+
setControlDisabled(disabled) {
|
|
1667
|
+
if (!this._formControl) return;
|
|
1668
|
+
try {
|
|
1669
|
+
if (disabled && this._formControl.enabled) this._formControl.disable({
|
|
1670
|
+
onlySelf: true,
|
|
1671
|
+
emitEvent: false
|
|
1672
|
+
});
|
|
1673
|
+
else if (!disabled && this._formControl.disabled) this._formControl.enable({
|
|
1674
|
+
onlySelf: true,
|
|
1675
|
+
emitEvent: false
|
|
1676
|
+
});
|
|
1677
|
+
} catch (error) {
|
|
1678
|
+
this.logError("Error updating form control status.", error);
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
restoreManagedDisabledState() {
|
|
1682
|
+
if (!this._formControl || !this._disabledManaged) return;
|
|
1683
|
+
this.setControlDisabled(this._disabledBeforeManagement === true);
|
|
1684
|
+
this._disabledManaged = false;
|
|
1685
|
+
this._disabledBeforeManagement = void 0;
|
|
1140
1686
|
}
|
|
1141
1687
|
setFormControlStatus() {
|
|
1142
1688
|
if (!this._formControl) return;
|
|
1143
1689
|
const attributes = this.configuration()?.attributes;
|
|
1144
|
-
if (!attributes)
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
if (disabledAttr == null || disabledAttr === false || disabledAttr === "") {
|
|
1148
|
-
if (this._formControl.disabled) try {
|
|
1149
|
-
this._formControl.enable({
|
|
1150
|
-
onlySelf: true,
|
|
1151
|
-
emitEvent: false
|
|
1152
|
-
});
|
|
1153
|
-
} catch (e) {}
|
|
1154
|
-
try {
|
|
1155
|
-
this._formControl.updateValueAndValidity({
|
|
1156
|
-
onlySelf: true,
|
|
1157
|
-
emitEvent: false
|
|
1158
|
-
});
|
|
1159
|
-
} catch (e) {}
|
|
1160
|
-
return;
|
|
1161
|
-
}
|
|
1162
|
-
const isDisabled = this.evaluateExpression(disabledAttr, this.viewModel);
|
|
1163
|
-
if (isDisabled === true || typeof isDisabled === "string" && isDisabled === "true") {
|
|
1164
|
-
if (this._formControl.enabled || !this._formControl.disabled) try {
|
|
1165
|
-
this._formControl.disable({
|
|
1166
|
-
onlySelf: true,
|
|
1167
|
-
emitEvent: false
|
|
1168
|
-
});
|
|
1169
|
-
} catch (e) {}
|
|
1170
|
-
} else if (isDisabled === false || isDisabled === "" || isDisabled === null || isDisabled === void 0 || typeof isDisabled === "string" && isDisabled === "false") {
|
|
1171
|
-
if (this._formControl.disabled) try {
|
|
1172
|
-
this._formControl.enable({
|
|
1173
|
-
onlySelf: true,
|
|
1174
|
-
emitEvent: false
|
|
1175
|
-
});
|
|
1176
|
-
} catch (e) {}
|
|
1177
|
-
} else if (typeof isDisabled === "boolean") {
|
|
1178
|
-
if (isDisabled && this._formControl.enabled) try {
|
|
1179
|
-
this._formControl.disable({
|
|
1180
|
-
onlySelf: true,
|
|
1181
|
-
emitEvent: false
|
|
1182
|
-
});
|
|
1183
|
-
} catch (e) {}
|
|
1184
|
-
else if (!isDisabled && this._formControl.disabled) try {
|
|
1185
|
-
this._formControl.enable({
|
|
1186
|
-
onlySelf: true,
|
|
1187
|
-
emitEvent: false
|
|
1188
|
-
});
|
|
1189
|
-
} catch (e) {}
|
|
1190
|
-
}
|
|
1690
|
+
if (!attributes || !Object.hasOwn(attributes, "disabled")) {
|
|
1691
|
+
this.restoreManagedDisabledState();
|
|
1692
|
+
return;
|
|
1191
1693
|
}
|
|
1694
|
+
const disabledAttr = attributes["disabled"];
|
|
1695
|
+
const evaluated = this.evaluateExpression(disabledAttr, this.getViewModelValue());
|
|
1696
|
+
if (this.isUnresolvedExpression(disabledAttr, evaluated)) return;
|
|
1697
|
+
const shouldDisable = this.toBoolean(evaluated);
|
|
1698
|
+
if (!this._disabledManaged) {
|
|
1699
|
+
this._disabledBeforeManagement = this._formControl.disabled;
|
|
1700
|
+
this._disabledManaged = true;
|
|
1701
|
+
}
|
|
1702
|
+
this.setControlDisabled(shouldDisable);
|
|
1192
1703
|
}
|
|
1193
1704
|
setFormControlValidators() {
|
|
1194
1705
|
if (!this._formControl) return;
|
|
1195
1706
|
if (this._managedValidatorFns.length > 0) {
|
|
1196
1707
|
try {
|
|
1197
1708
|
this._formControl.removeValidators(this._managedValidatorFns);
|
|
1198
|
-
} catch (
|
|
1709
|
+
} catch (error) {
|
|
1710
|
+
this.logError("Error removing managed validators.", error);
|
|
1711
|
+
}
|
|
1199
1712
|
this._managedValidatorFns = [];
|
|
1200
1713
|
try {
|
|
1201
1714
|
this._formControl.updateValueAndValidity({
|
|
1202
1715
|
onlySelf: true,
|
|
1203
1716
|
emitEvent: false
|
|
1204
1717
|
});
|
|
1205
|
-
} catch (
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
this.logError("Error updating form control validity.", error);
|
|
1720
|
+
}
|
|
1206
1721
|
}
|
|
1207
1722
|
const attributes = this.configuration()?.attributes;
|
|
1208
1723
|
if (attributes && Object.keys(attributes).length > 0 && this._componentRef?.location?.nativeElement) {
|
|
1209
1724
|
const validators = [];
|
|
1210
1725
|
if (Object.hasOwn(attributes, "min")) {
|
|
1211
|
-
const min = this.
|
|
1212
|
-
if (typeof min === "number" && !isNaN(min)) validators.push(Validators.min(min));
|
|
1726
|
+
const { value: min, unresolved } = this.evaluateAttribute(attributes, "min");
|
|
1727
|
+
if (!unresolved && typeof min === "number" && !isNaN(min)) validators.push(Validators.min(min));
|
|
1213
1728
|
}
|
|
1214
1729
|
if (Object.hasOwn(attributes, "max")) {
|
|
1215
|
-
const max = this.
|
|
1216
|
-
if (typeof max === "number" && !isNaN(max)) validators.push(Validators.max(max));
|
|
1730
|
+
const { value: max, unresolved } = this.evaluateAttribute(attributes, "max");
|
|
1731
|
+
if (!unresolved && typeof max === "number" && !isNaN(max)) validators.push(Validators.max(max));
|
|
1217
1732
|
}
|
|
1218
1733
|
if (Object.hasOwn(attributes, "required")) {
|
|
1219
|
-
|
|
1734
|
+
const { value: required, unresolved } = this.evaluateAttribute(attributes, "required");
|
|
1735
|
+
if (!unresolved && required === true) validators.push(Validators.required);
|
|
1220
1736
|
}
|
|
1221
1737
|
if (Object.hasOwn(attributes, "email")) {
|
|
1222
|
-
|
|
1738
|
+
const { value: email, unresolved } = this.evaluateAttribute(attributes, "email");
|
|
1739
|
+
if (!unresolved && email === true) validators.push(Validators.email);
|
|
1223
1740
|
}
|
|
1224
1741
|
if (Object.hasOwn(attributes, "maxlength")) {
|
|
1225
|
-
const maxLength = this.
|
|
1226
|
-
if (typeof maxLength === "number" && !isNaN(maxLength) && maxLength >= 0) validators.push(Validators.maxLength(maxLength));
|
|
1742
|
+
const { value: maxLength, unresolved } = this.evaluateAttribute(attributes, "maxlength");
|
|
1743
|
+
if (!unresolved && typeof maxLength === "number" && !isNaN(maxLength) && maxLength >= 0) validators.push(Validators.maxLength(maxLength));
|
|
1227
1744
|
}
|
|
1228
1745
|
if (Object.hasOwn(attributes, "minlength")) {
|
|
1229
|
-
const minLength = this.
|
|
1230
|
-
if (typeof minLength === "number" && !isNaN(minLength) && minLength >= 0) validators.push(Validators.minLength(minLength));
|
|
1746
|
+
const { value: minLength, unresolved } = this.evaluateAttribute(attributes, "minlength");
|
|
1747
|
+
if (!unresolved && typeof minLength === "number" && !isNaN(minLength) && minLength >= 0) validators.push(Validators.minLength(minLength));
|
|
1231
1748
|
}
|
|
1232
1749
|
if (Object.hasOwn(attributes, "pattern")) {
|
|
1233
|
-
const pattern = this.
|
|
1234
|
-
const patternValidator = this.createPatternValidator(pattern);
|
|
1750
|
+
const { value: pattern, unresolved } = this.evaluateAttribute(attributes, "pattern");
|
|
1751
|
+
const patternValidator = unresolved ? null : this.createPatternValidator(pattern);
|
|
1235
1752
|
if (patternValidator) validators.push(patternValidator);
|
|
1236
1753
|
}
|
|
1237
1754
|
if (validators.length > 0) {
|
|
1238
1755
|
this._managedValidatorFns = validators;
|
|
1239
1756
|
try {
|
|
1240
1757
|
this._formControl.addValidators(this._managedValidatorFns);
|
|
1241
|
-
} catch (
|
|
1758
|
+
} catch (error) {
|
|
1759
|
+
this.logError("Error adding managed validators.", error);
|
|
1760
|
+
}
|
|
1242
1761
|
} else this._managedValidatorFns = [];
|
|
1243
1762
|
try {
|
|
1244
1763
|
this._formControl.updateValueAndValidity({
|
|
1245
1764
|
onlySelf: true,
|
|
1246
1765
|
emitEvent: false
|
|
1247
1766
|
});
|
|
1248
|
-
} catch (
|
|
1767
|
+
} catch (error) {
|
|
1768
|
+
this.logError("Error updating form control validity.", error);
|
|
1769
|
+
}
|
|
1249
1770
|
} else this._managedValidatorFns = [];
|
|
1250
1771
|
}
|
|
1251
1772
|
createPatternValidator(pattern) {
|
|
@@ -1271,7 +1792,12 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1271
1792
|
this.logWarning("Pattern validator was ignored because the expression is potentially unsafe.");
|
|
1272
1793
|
return null;
|
|
1273
1794
|
}
|
|
1274
|
-
|
|
1795
|
+
try {
|
|
1796
|
+
regex = new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
|
|
1797
|
+
} catch (error) {
|
|
1798
|
+
this.logError("Pattern validator was ignored because the expression is invalid.", error);
|
|
1799
|
+
return null;
|
|
1800
|
+
}
|
|
1275
1801
|
} else return null;
|
|
1276
1802
|
const baseValidator = Validators.pattern(regex);
|
|
1277
1803
|
return (control) => {
|
|
@@ -1284,9 +1810,80 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1284
1810
|
}
|
|
1285
1811
|
isUnsafeRegex(source) {
|
|
1286
1812
|
if (source.length > MAX_PATTERN_LENGTH) return true;
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1813
|
+
const stack = [{
|
|
1814
|
+
hasQuantifier: false,
|
|
1815
|
+
hasAlternation: false
|
|
1816
|
+
}];
|
|
1817
|
+
let inCharacterClass = false;
|
|
1818
|
+
const isQuantifierAt = (index) => {
|
|
1819
|
+
const character = source[index];
|
|
1820
|
+
if (character === "+" || character === "*") return true;
|
|
1821
|
+
if (character !== "{") return false;
|
|
1822
|
+
const match = /^\{\d+(?:,\d*)?\}/.exec(source.slice(index));
|
|
1823
|
+
if (!match) return false;
|
|
1824
|
+
const bounds = /^\{(\d+)(?:,(\d*))?\}/.exec(match[0]);
|
|
1825
|
+
if (bounds) {
|
|
1826
|
+
const upper = bounds[2] === void 0 || bounds[2] === "" ? Infinity : Number(bounds[2]);
|
|
1827
|
+
if (Number.isFinite(upper) && upper > 1e4) return true;
|
|
1828
|
+
}
|
|
1829
|
+
return true;
|
|
1830
|
+
};
|
|
1831
|
+
for (let index = 0; index < source.length; index++) {
|
|
1832
|
+
const character = source[index];
|
|
1833
|
+
if (character === "\\") {
|
|
1834
|
+
const next = source[index + 1];
|
|
1835
|
+
if (next && /[1-9]/.test(next)) {
|
|
1836
|
+
let cursor = index + 2;
|
|
1837
|
+
while (cursor < source.length && /\d/.test(source[cursor])) cursor++;
|
|
1838
|
+
if (isQuantifierAt(cursor)) return true;
|
|
1839
|
+
}
|
|
1840
|
+
index++;
|
|
1841
|
+
continue;
|
|
1842
|
+
}
|
|
1843
|
+
if (inCharacterClass) {
|
|
1844
|
+
if (character === "]") inCharacterClass = false;
|
|
1845
|
+
continue;
|
|
1846
|
+
}
|
|
1847
|
+
if (character === "[") {
|
|
1848
|
+
inCharacterClass = true;
|
|
1849
|
+
continue;
|
|
1850
|
+
}
|
|
1851
|
+
if (character === "(") {
|
|
1852
|
+
stack.push({
|
|
1853
|
+
hasQuantifier: false,
|
|
1854
|
+
hasAlternation: false
|
|
1855
|
+
});
|
|
1856
|
+
if (source[index + 1] === "?") index++;
|
|
1857
|
+
continue;
|
|
1858
|
+
}
|
|
1859
|
+
if (character === ")") {
|
|
1860
|
+
const group = stack.pop();
|
|
1861
|
+
if (group) {
|
|
1862
|
+
const quantified = isQuantifierAt(index + 1);
|
|
1863
|
+
if (quantified && (group.hasQuantifier || group.hasAlternation)) return true;
|
|
1864
|
+
const parent = stack[stack.length - 1];
|
|
1865
|
+
if (parent) {
|
|
1866
|
+
if (quantified || group.hasQuantifier) parent.hasQuantifier = true;
|
|
1867
|
+
if (group.hasAlternation) parent.hasAlternation = true;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
continue;
|
|
1871
|
+
}
|
|
1872
|
+
if (character === "|") {
|
|
1873
|
+
stack[stack.length - 1].hasAlternation = true;
|
|
1874
|
+
continue;
|
|
1875
|
+
}
|
|
1876
|
+
if (character === "+" || character === "*" || character === "{" || character === "?") {
|
|
1877
|
+
if (character === "?" && source[index - 1] === "(") continue;
|
|
1878
|
+
if (character === "{" && !/^\{\d+(?:,\d*)?\}/.test(source.slice(index))) continue;
|
|
1879
|
+
if (character === "{" && isQuantifierAt(index)) {
|
|
1880
|
+
const bounds = /^\{(\d+)(?:,(\d*))?\}/.exec(source.slice(index));
|
|
1881
|
+
const upper = bounds && bounds[2] !== void 0 && bounds[2] !== "" ? Number(bounds[2]) : Infinity;
|
|
1882
|
+
if (Number.isFinite(upper) && upper > 1e4) return true;
|
|
1883
|
+
}
|
|
1884
|
+
stack[stack.length - 1].hasQuantifier = true;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1290
1887
|
return false;
|
|
1291
1888
|
}
|
|
1292
1889
|
attachFormControlDirective() {
|
|
@@ -1308,14 +1905,81 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1308
1905
|
if (property == null) return null;
|
|
1309
1906
|
let pathArray = null;
|
|
1310
1907
|
if (Array.isArray(property)) pathArray = property.filter((segment) => segment != null && segment !== "").map((segment) => String(segment));
|
|
1311
|
-
else if (typeof property === "string") pathArray =
|
|
1908
|
+
else if (typeof property === "string") pathArray = this.parseStringPath(property);
|
|
1312
1909
|
if (!pathArray || pathArray.length === 0 || pathArray.length > MAX_PATH_DEPTH) return null;
|
|
1313
1910
|
for (const segment of pathArray) {
|
|
1314
|
-
if (segment.length > MAX_PATH_SEGMENT_LENGTH) return null;
|
|
1911
|
+
if (segment.length === 0 || segment.length > MAX_PATH_SEGMENT_LENGTH) return null;
|
|
1315
1912
|
if (FORBIDDEN_PATH_SEGMENTS.has(segment.toLowerCase())) return null;
|
|
1316
1913
|
}
|
|
1317
1914
|
return pathArray;
|
|
1318
1915
|
}
|
|
1916
|
+
parseStringPath(property) {
|
|
1917
|
+
const source = property.trim();
|
|
1918
|
+
if (source.length === 0) return null;
|
|
1919
|
+
const segments = [];
|
|
1920
|
+
let index = 0;
|
|
1921
|
+
let expectingSegment = true;
|
|
1922
|
+
while (index < source.length) {
|
|
1923
|
+
const character = source[index];
|
|
1924
|
+
if (character === ".") {
|
|
1925
|
+
if (expectingSegment) return null;
|
|
1926
|
+
expectingSegment = true;
|
|
1927
|
+
index++;
|
|
1928
|
+
continue;
|
|
1929
|
+
}
|
|
1930
|
+
if (character === "[") {
|
|
1931
|
+
index++;
|
|
1932
|
+
let value = "";
|
|
1933
|
+
if (source[index] === "\"" || source[index] === "'") {
|
|
1934
|
+
const quote = source[index];
|
|
1935
|
+
index++;
|
|
1936
|
+
let closed = false;
|
|
1937
|
+
while (index < source.length) {
|
|
1938
|
+
const current = source[index];
|
|
1939
|
+
if (current === "\\") {
|
|
1940
|
+
if (index + 1 >= source.length) return null;
|
|
1941
|
+
value += source[index + 1];
|
|
1942
|
+
index += 2;
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
if (current === quote) {
|
|
1946
|
+
index++;
|
|
1947
|
+
closed = true;
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
value += current;
|
|
1951
|
+
index++;
|
|
1952
|
+
}
|
|
1953
|
+
if (!closed) return null;
|
|
1954
|
+
} else {
|
|
1955
|
+
const start = index;
|
|
1956
|
+
while (index < source.length && source[index] !== "]") {
|
|
1957
|
+
if (source[index] === "[" || source[index] === ".") return null;
|
|
1958
|
+
value += source[index];
|
|
1959
|
+
index++;
|
|
1960
|
+
}
|
|
1961
|
+
if (index === start) return null;
|
|
1962
|
+
value = value.trim();
|
|
1963
|
+
}
|
|
1964
|
+
if (source[index] !== "]" || value.length === 0) return null;
|
|
1965
|
+
index++;
|
|
1966
|
+
segments.push(value);
|
|
1967
|
+
expectingSegment = false;
|
|
1968
|
+
continue;
|
|
1969
|
+
}
|
|
1970
|
+
if (!expectingSegment) return null;
|
|
1971
|
+
let value = "";
|
|
1972
|
+
while (index < source.length && source[index] !== "." && source[index] !== "[") {
|
|
1973
|
+
value += source[index];
|
|
1974
|
+
index++;
|
|
1975
|
+
}
|
|
1976
|
+
if (value.length === 0) return null;
|
|
1977
|
+
segments.push(value);
|
|
1978
|
+
expectingSegment = false;
|
|
1979
|
+
}
|
|
1980
|
+
if (expectingSegment) return null;
|
|
1981
|
+
return segments;
|
|
1982
|
+
}
|
|
1319
1983
|
isSafePath(property) {
|
|
1320
1984
|
return this.parsePath(property) !== null;
|
|
1321
1985
|
}
|
|
@@ -1327,6 +1991,12 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1327
1991
|
configurable: true
|
|
1328
1992
|
});
|
|
1329
1993
|
}
|
|
1994
|
+
isMutableContainer(value) {
|
|
1995
|
+
if (value == null || typeof value !== "object") return false;
|
|
1996
|
+
if (Array.isArray(value)) return true;
|
|
1997
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1998
|
+
return prototype === Object.prototype || prototype === null;
|
|
1999
|
+
}
|
|
1330
2000
|
getModelPropertyValue(model, property, defaultValue) {
|
|
1331
2001
|
if (model == null) return defaultValue;
|
|
1332
2002
|
const pathArray = this.parsePath(property);
|
|
@@ -1353,7 +2023,7 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1353
2023
|
for (let index = 0; index < pathArray.length; index++) {
|
|
1354
2024
|
const key = pathArray[index];
|
|
1355
2025
|
const isLast = index === pathArray.length - 1;
|
|
1356
|
-
if (current
|
|
2026
|
+
if (!this.isMutableContainer(current)) return;
|
|
1357
2027
|
if (isLast) {
|
|
1358
2028
|
this.defineOwn(current, key, value);
|
|
1359
2029
|
return;
|
|
@@ -1365,10 +2035,8 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1365
2035
|
this.defineOwn(current, key, next);
|
|
1366
2036
|
current = next;
|
|
1367
2037
|
} else if (isNumericKey && !Array.isArray(existing)) {
|
|
1368
|
-
if (typeof existing
|
|
1369
|
-
|
|
1370
|
-
this.defineOwn(current, key, next);
|
|
1371
|
-
current = next;
|
|
2038
|
+
if (existing !== null && typeof existing === "object") current = existing;
|
|
2039
|
+
else return;
|
|
1372
2040
|
} else if (!isNumericKey && typeof existing !== "object") {
|
|
1373
2041
|
const next = {};
|
|
1374
2042
|
this.defineOwn(current, key, next);
|
|
@@ -1380,10 +2048,21 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1380
2048
|
}
|
|
1381
2049
|
}
|
|
1382
2050
|
setInputs() {
|
|
2051
|
+
if (!this._componentRef) return;
|
|
1383
2052
|
const inputs = this.configuration()?.inputs;
|
|
1384
|
-
|
|
1385
|
-
for (const inputName of
|
|
1386
|
-
|
|
2053
|
+
const currentNames = inputs && typeof inputs === "object" ? Object.keys(inputs) : [];
|
|
2054
|
+
for (const inputName of Array.from(this._appliedInputs)) if (!currentNames.includes(inputName)) {
|
|
2055
|
+
try {
|
|
2056
|
+
this._componentRef.setInput(inputName, void 0);
|
|
2057
|
+
} catch (error) {
|
|
2058
|
+
this.logError(`Error resetting dynamic input "${inputName}".`, error);
|
|
2059
|
+
}
|
|
2060
|
+
this._appliedInputs.delete(inputName);
|
|
2061
|
+
}
|
|
2062
|
+
if (!inputs || typeof inputs !== "object") return;
|
|
2063
|
+
for (const inputName of currentNames) try {
|
|
2064
|
+
this._componentRef.setInput(inputName, this.evaluateExpression(inputs[inputName], this.getViewModelValue()));
|
|
2065
|
+
this._appliedInputs.add(inputName);
|
|
1387
2066
|
} catch (error) {
|
|
1388
2067
|
this.logError(`Error setting dynamic input "${inputName}".`, error);
|
|
1389
2068
|
}
|
|
@@ -1391,26 +2070,46 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1391
2070
|
setAttributes() {
|
|
1392
2071
|
const attributes = this.configuration()?.attributes;
|
|
1393
2072
|
const element = this._componentRef?.location?.nativeElement;
|
|
1394
|
-
if (!
|
|
1395
|
-
|
|
2073
|
+
if (!element) return;
|
|
2074
|
+
const currentNames = attributes && typeof attributes === "object" ? Object.keys(attributes) : [];
|
|
2075
|
+
for (const attributeName of Array.from(this._appliedAttributes)) if (!currentNames.includes(attributeName) || !this.isAllowedAttribute(attributeName)) {
|
|
2076
|
+
this._renderer.removeAttribute(element, attributeName);
|
|
2077
|
+
this._appliedAttributes.delete(attributeName);
|
|
2078
|
+
}
|
|
2079
|
+
if (!attributes || typeof attributes !== "object") return;
|
|
2080
|
+
for (const attributeName of currentNames) {
|
|
1396
2081
|
if (!this.isAllowedAttribute(attributeName)) {
|
|
1397
2082
|
this.logWarning(`Attribute "${attributeName}" is not allowed and was skipped.`);
|
|
1398
2083
|
continue;
|
|
1399
2084
|
}
|
|
1400
2085
|
try {
|
|
1401
|
-
const
|
|
2086
|
+
const rawValue = attributes[attributeName];
|
|
2087
|
+
const value = this.evaluateExpression(rawValue, this.getViewModelValue());
|
|
2088
|
+
if (this.isUnresolvedExpression(rawValue, value)) continue;
|
|
2089
|
+
const lower = attributeName.toLowerCase();
|
|
2090
|
+
if (BOOLEAN_ATTRIBUTES.has(lower)) {
|
|
2091
|
+
if (!this.toBoolean(value)) {
|
|
2092
|
+
this._renderer.removeAttribute(element, attributeName);
|
|
2093
|
+
this._appliedAttributes.delete(attributeName);
|
|
2094
|
+
} else if (element.getAttribute(attributeName) !== "") {
|
|
2095
|
+
this._renderer.setAttribute(element, attributeName, "");
|
|
2096
|
+
this._appliedAttributes.add(attributeName);
|
|
2097
|
+
} else this._appliedAttributes.add(attributeName);
|
|
2098
|
+
continue;
|
|
2099
|
+
}
|
|
1402
2100
|
const stringValue = this.attributeValueToString(value);
|
|
1403
2101
|
if (stringValue === void 0) continue;
|
|
1404
|
-
if (stringValue === element.getAttribute(attributeName)) continue;
|
|
1405
2102
|
if (stringValue === null) {
|
|
1406
2103
|
this._renderer.removeAttribute(element, attributeName);
|
|
2104
|
+
this._appliedAttributes.delete(attributeName);
|
|
1407
2105
|
continue;
|
|
1408
2106
|
}
|
|
1409
|
-
if (URL_ATTRIBUTES.has(
|
|
2107
|
+
if (URL_ATTRIBUTES.has(lower) && !this.isSafeUrl(stringValue)) {
|
|
1410
2108
|
this.logWarning(`Unsafe URL for attribute "${attributeName}" was ignored.`);
|
|
1411
2109
|
continue;
|
|
1412
2110
|
}
|
|
1413
|
-
this._renderer.setAttribute(element, attributeName, stringValue);
|
|
2111
|
+
if (element.getAttribute(attributeName) !== stringValue) this._renderer.setAttribute(element, attributeName, stringValue);
|
|
2112
|
+
this._appliedAttributes.add(attributeName);
|
|
1414
2113
|
} catch (error) {
|
|
1415
2114
|
this.logError(`Error setting dynamic attribute "${attributeName}".`, error);
|
|
1416
2115
|
}
|
|
@@ -1421,6 +2120,7 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1421
2120
|
const lower = name.toLowerCase();
|
|
1422
2121
|
if (lower.startsWith("on")) return false;
|
|
1423
2122
|
if (!/^[a-z][a-z0-9_.-]*$/i.test(name)) return false;
|
|
2123
|
+
if (this.attributePolicy()?.strict === true && STRICT_DISALLOWED_ATTRIBUTES.has(lower)) return false;
|
|
1424
2124
|
if (lower.startsWith("data-") || lower.startsWith("aria-")) return true;
|
|
1425
2125
|
return ALLOWED_ATTRIBUTES.has(lower);
|
|
1426
2126
|
}
|
|
@@ -1445,18 +2145,54 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1445
2145
|
if (!scheme) return true;
|
|
1446
2146
|
return scheme[1] === "http" || scheme[1] === "https" || scheme[1] === "mailto" || scheme[1] === "tel";
|
|
1447
2147
|
}
|
|
1448
|
-
|
|
2148
|
+
evaluateAttribute(attributes, name) {
|
|
2149
|
+
const raw = attributes[name];
|
|
2150
|
+
const value = this.evaluateExpression(raw, this.getViewModelValue());
|
|
2151
|
+
return {
|
|
2152
|
+
value,
|
|
2153
|
+
unresolved: this.isUnresolvedExpression(raw, value)
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
isUnresolvedExpression(source, result) {
|
|
2157
|
+
return typeof source === "string" && result === source && (source.includes("$vm") || source.includes("$event") || source.includes("$ev"));
|
|
2158
|
+
}
|
|
2159
|
+
toBoolean(value) {
|
|
2160
|
+
if (typeof value === "boolean") return value;
|
|
2161
|
+
if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
|
|
2162
|
+
if (typeof value === "string") {
|
|
2163
|
+
const normalized = value.trim().toLowerCase();
|
|
2164
|
+
return normalized !== "" && normalized !== "false" && normalized !== "0" && normalized !== "null" && normalized !== "undefined";
|
|
2165
|
+
}
|
|
2166
|
+
return value != null;
|
|
2167
|
+
}
|
|
2168
|
+
evaluateExpression(value, viewModelValue, eventParam, hasEventContext = false) {
|
|
1449
2169
|
if (typeof value !== "string") return value;
|
|
1450
2170
|
const hasVm = value.includes("$vm");
|
|
1451
|
-
const hasEvent = value.includes("$event");
|
|
2171
|
+
const hasEvent = value.includes("$event") || value.includes("$ev");
|
|
1452
2172
|
if (!hasVm && !hasEvent) return value;
|
|
1453
|
-
if (hasVm &&
|
|
2173
|
+
if (hasVm && viewModelValue == null) return value;
|
|
2174
|
+
if (hasEvent && !hasEventContext) return value;
|
|
1454
2175
|
try {
|
|
1455
|
-
const
|
|
2176
|
+
const policy = this.expressionPolicy() ?? {};
|
|
2177
|
+
const allowedMethods = new Set(Array.isArray(policy.allowedMethods) ? policy.allowedMethods : []);
|
|
2178
|
+
const $vm = () => this.getViewModelValue();
|
|
2179
|
+
if (policy.allowViewModelMutation === true) {
|
|
2180
|
+
$vm.set = (nextValue) => {
|
|
2181
|
+
this.viewModel.set(nextValue);
|
|
2182
|
+
};
|
|
2183
|
+
$vm.update = (updateFn) => {
|
|
2184
|
+
this.viewModel.update(updateFn);
|
|
2185
|
+
};
|
|
2186
|
+
allowedMethods.add("set");
|
|
2187
|
+
allowedMethods.add("update");
|
|
2188
|
+
}
|
|
1456
2189
|
return evaluateSafeExpression(value, {
|
|
1457
|
-
$vm
|
|
2190
|
+
$vm,
|
|
1458
2191
|
$event: eventParam,
|
|
1459
2192
|
$ev: eventParam
|
|
2193
|
+
}, {
|
|
2194
|
+
allowCustomMethods: policy.allowCustomMethods === true,
|
|
2195
|
+
allowedMethods: Array.from(allowedMethods)
|
|
1460
2196
|
});
|
|
1461
2197
|
} catch {
|
|
1462
2198
|
this.logWarning("Expression could not be evaluated safely and was ignored.");
|
|
@@ -1487,24 +2223,32 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1487
2223
|
this._formControlSubscription.unsubscribe();
|
|
1488
2224
|
} catch (e) {}
|
|
1489
2225
|
this._formControlSubscription = void 0;
|
|
1490
|
-
|
|
1491
|
-
const attributeName = (this.configuration()?.attributes)?.["name"];
|
|
1492
|
-
if (attributeName) {
|
|
1493
|
-
const controlName = this.evaluateExpression(attributeName, this.viewModel);
|
|
1494
|
-
if (typeof controlName === "string" && controlName.length > 0 && this.isSafePath(controlName)) {
|
|
1495
|
-
const formGroup = this.formGroup();
|
|
1496
|
-
if (formGroup.get(controlName) === this._formControl) try {
|
|
1497
|
-
formGroup.removeControl(controlName);
|
|
1498
|
-
} catch (e) {}
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
} catch (e) {}
|
|
1502
|
-
this._formControl = void 0;
|
|
1503
|
-
this._managedValidatorFns = [];
|
|
2226
|
+
this.restoreManagedDisabledState();
|
|
1504
2227
|
if (this._formControlDirective) try {
|
|
1505
2228
|
this._formControlDirective.ngOnDestroy();
|
|
1506
2229
|
} catch (e) {}
|
|
1507
2230
|
this._formControlDirective = void 0;
|
|
2231
|
+
if (this._ownsFormControl && this._formControl && this._formControlContainer && this._formControlKey) try {
|
|
2232
|
+
if (this._formControlContainer.get(this._formControlKey) === this._formControl) this._formControlContainer.removeControl(this._formControlKey);
|
|
2233
|
+
} catch (e) {}
|
|
2234
|
+
for (let index = this._createdFormGroups.length - 1; index >= 0; index--) {
|
|
2235
|
+
const { parent, key, group } = this._createdFormGroups[index];
|
|
2236
|
+
try {
|
|
2237
|
+
if (parent.get(key) === group && Object.keys(group.controls).length === 0) parent.removeControl(key);
|
|
2238
|
+
} catch (e) {}
|
|
2239
|
+
}
|
|
2240
|
+
this._createdFormGroups = [];
|
|
2241
|
+
this._formControl = void 0;
|
|
2242
|
+
this._formControlContainer = void 0;
|
|
2243
|
+
this._formControlKey = void 0;
|
|
2244
|
+
this._ownsFormControl = false;
|
|
2245
|
+
this._disabledManaged = false;
|
|
2246
|
+
this._disabledBeforeManagement = void 0;
|
|
2247
|
+
this._wiredFormGroup = void 0;
|
|
2248
|
+
this._wiredControlName = void 0;
|
|
2249
|
+
this._managedValidatorFns = [];
|
|
2250
|
+
this._appliedAttributes.clear();
|
|
2251
|
+
this._appliedInputs.clear();
|
|
1508
2252
|
if (this._componentRef) try {
|
|
1509
2253
|
this._componentRef.destroy();
|
|
1510
2254
|
} catch (e) {}
|
|
@@ -1558,6 +2302,41 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1558
2302
|
isSignal: true,
|
|
1559
2303
|
isRequired: false,
|
|
1560
2304
|
transformFunction: null
|
|
2305
|
+
},
|
|
2306
|
+
expressionPolicy: {
|
|
2307
|
+
classPropertyName: "expressionPolicy",
|
|
2308
|
+
publicName: "expressionPolicy",
|
|
2309
|
+
isSignal: true,
|
|
2310
|
+
isRequired: false,
|
|
2311
|
+
transformFunction: null
|
|
2312
|
+
},
|
|
2313
|
+
formControlPolicy: {
|
|
2314
|
+
classPropertyName: "formControlPolicy",
|
|
2315
|
+
publicName: "formControlPolicy",
|
|
2316
|
+
isSignal: true,
|
|
2317
|
+
isRequired: false,
|
|
2318
|
+
transformFunction: null
|
|
2319
|
+
},
|
|
2320
|
+
typePolicy: {
|
|
2321
|
+
classPropertyName: "typePolicy",
|
|
2322
|
+
publicName: "typePolicy",
|
|
2323
|
+
isSignal: true,
|
|
2324
|
+
isRequired: false,
|
|
2325
|
+
transformFunction: null
|
|
2326
|
+
},
|
|
2327
|
+
attributePolicy: {
|
|
2328
|
+
classPropertyName: "attributePolicy",
|
|
2329
|
+
publicName: "attributePolicy",
|
|
2330
|
+
isSignal: true,
|
|
2331
|
+
isRequired: false,
|
|
2332
|
+
transformFunction: null
|
|
2333
|
+
},
|
|
2334
|
+
depth: {
|
|
2335
|
+
classPropertyName: "depth",
|
|
2336
|
+
publicName: "depth",
|
|
2337
|
+
isSignal: true,
|
|
2338
|
+
isRequired: false,
|
|
2339
|
+
transformFunction: null
|
|
1561
2340
|
}
|
|
1562
2341
|
},
|
|
1563
2342
|
outputs: { viewModel: "viewModelChange" },
|
|
@@ -1580,7 +2359,7 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1580
2359
|
template: `
|
|
1581
2360
|
<ng-container #viewContainer></ng-container>
|
|
1582
2361
|
@for (item of items(); track $index) {
|
|
1583
|
-
<fg-dynamic #dynamicItem [configuration]="item" [(viewModel)]="viewModel" [formGroup]="formGroup()" [registry]="registry()" />
|
|
2362
|
+
<fg-dynamic #dynamicItem [configuration]="item" [(viewModel)]="viewModel" [formGroup]="formGroup()" [registry]="registry()" [expressionPolicy]="expressionPolicy()" [formControlPolicy]="formControlPolicy()" [typePolicy]="typePolicy()" [attributePolicy]="attributePolicy()" [depth]="depth() + 1" />
|
|
1584
2363
|
}
|
|
1585
2364
|
`,
|
|
1586
2365
|
isInline: true,
|
|
@@ -1593,7 +2372,12 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1593
2372
|
"configuration",
|
|
1594
2373
|
"viewModel",
|
|
1595
2374
|
"formGroup",
|
|
1596
|
-
"registry"
|
|
2375
|
+
"registry",
|
|
2376
|
+
"expressionPolicy",
|
|
2377
|
+
"formControlPolicy",
|
|
2378
|
+
"typePolicy",
|
|
2379
|
+
"attributePolicy",
|
|
2380
|
+
"depth"
|
|
1597
2381
|
],
|
|
1598
2382
|
outputs: ["viewModelChange"]
|
|
1599
2383
|
}],
|
|
@@ -1613,7 +2397,7 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1613
2397
|
template: `
|
|
1614
2398
|
<ng-container #viewContainer></ng-container>
|
|
1615
2399
|
@for (item of items(); track $index) {
|
|
1616
|
-
<fg-dynamic #dynamicItem [configuration]="item" [(viewModel)]="viewModel" [formGroup]="formGroup()" [registry]="registry()" />
|
|
2400
|
+
<fg-dynamic #dynamicItem [configuration]="item" [(viewModel)]="viewModel" [formGroup]="formGroup()" [registry]="registry()" [expressionPolicy]="expressionPolicy()" [formControlPolicy]="formControlPolicy()" [typePolicy]="typePolicy()" [attributePolicy]="attributePolicy()" [depth]="depth() + 1" />
|
|
1617
2401
|
}
|
|
1618
2402
|
`,
|
|
1619
2403
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
@@ -1657,6 +2441,46 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1657
2441
|
required: false
|
|
1658
2442
|
}]
|
|
1659
2443
|
}],
|
|
2444
|
+
expressionPolicy: [{
|
|
2445
|
+
type: i0.Input,
|
|
2446
|
+
args: [{
|
|
2447
|
+
isSignal: true,
|
|
2448
|
+
alias: "expressionPolicy",
|
|
2449
|
+
required: false
|
|
2450
|
+
}]
|
|
2451
|
+
}],
|
|
2452
|
+
formControlPolicy: [{
|
|
2453
|
+
type: i0.Input,
|
|
2454
|
+
args: [{
|
|
2455
|
+
isSignal: true,
|
|
2456
|
+
alias: "formControlPolicy",
|
|
2457
|
+
required: false
|
|
2458
|
+
}]
|
|
2459
|
+
}],
|
|
2460
|
+
typePolicy: [{
|
|
2461
|
+
type: i0.Input,
|
|
2462
|
+
args: [{
|
|
2463
|
+
isSignal: true,
|
|
2464
|
+
alias: "typePolicy",
|
|
2465
|
+
required: false
|
|
2466
|
+
}]
|
|
2467
|
+
}],
|
|
2468
|
+
attributePolicy: [{
|
|
2469
|
+
type: i0.Input,
|
|
2470
|
+
args: [{
|
|
2471
|
+
isSignal: true,
|
|
2472
|
+
alias: "attributePolicy",
|
|
2473
|
+
required: false
|
|
2474
|
+
}]
|
|
2475
|
+
}],
|
|
2476
|
+
depth: [{
|
|
2477
|
+
type: i0.Input,
|
|
2478
|
+
args: [{
|
|
2479
|
+
isSignal: true,
|
|
2480
|
+
alias: "depth",
|
|
2481
|
+
required: false
|
|
2482
|
+
}]
|
|
2483
|
+
}],
|
|
1660
2484
|
_viewContainerRef: [{
|
|
1661
2485
|
type: i0.ViewChild,
|
|
1662
2486
|
args: ["viewContainer", {
|