fg-dynamic-component 3.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/README.md +106 -17
- package/fesm2022/fg-dynamic-component.mjs +1432 -309
- package/fesm2022/fg-dynamic-component.mjs.map +1 -1
- package/package.json +5 -3
- package/types/fg-dynamic-component.d.ts +290 -19
|
@@ -1,11 +1,18 @@
|
|
|
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;
|
|
11
|
+
const RESERVED_BINDING_NAMES = /* @__PURE__ */ new Set([
|
|
12
|
+
"$vm",
|
|
13
|
+
"$event",
|
|
14
|
+
"$ev"
|
|
15
|
+
]);
|
|
9
16
|
const FORBIDDEN_PROPERTIES = /* @__PURE__ */ new Set([
|
|
10
17
|
"__proto__",
|
|
11
18
|
"prototype",
|
|
@@ -16,8 +23,327 @@ const FORBIDDEN_PROPERTIES = /* @__PURE__ */ new Set([
|
|
|
16
23
|
"__defineGetter__",
|
|
17
24
|
"__defineSetter__",
|
|
18
25
|
"__lookupGetter__",
|
|
19
|
-
"__lookupSetter__"
|
|
26
|
+
"__lookupSetter__",
|
|
27
|
+
"call",
|
|
28
|
+
"apply",
|
|
29
|
+
"bind",
|
|
30
|
+
"window",
|
|
31
|
+
"self",
|
|
32
|
+
"globalThis",
|
|
33
|
+
"global",
|
|
34
|
+
"top",
|
|
35
|
+
"parent",
|
|
36
|
+
"frames",
|
|
37
|
+
"opener",
|
|
38
|
+
"document",
|
|
39
|
+
"ownerDocument",
|
|
40
|
+
"defaultView",
|
|
41
|
+
"contentWindow",
|
|
42
|
+
"contentDocument",
|
|
43
|
+
"location",
|
|
44
|
+
"cookie",
|
|
45
|
+
"localStorage",
|
|
46
|
+
"sessionStorage",
|
|
47
|
+
"indexedDB",
|
|
48
|
+
"navigator",
|
|
49
|
+
"history",
|
|
50
|
+
"screen",
|
|
51
|
+
"fetch",
|
|
52
|
+
"XMLHttpRequest",
|
|
53
|
+
"WebSocket",
|
|
54
|
+
"Worker",
|
|
55
|
+
"importScripts",
|
|
56
|
+
"postMessage",
|
|
57
|
+
"sendBeacon",
|
|
58
|
+
"setTimeout",
|
|
59
|
+
"setInterval",
|
|
60
|
+
"setImmediate",
|
|
61
|
+
"requestAnimationFrame",
|
|
62
|
+
"open",
|
|
63
|
+
"close",
|
|
64
|
+
"write",
|
|
65
|
+
"writeln",
|
|
66
|
+
"innerHTML",
|
|
67
|
+
"outerHTML",
|
|
68
|
+
"insertAdjacentHTML",
|
|
69
|
+
"eval",
|
|
70
|
+
"Function"
|
|
71
|
+
]);
|
|
72
|
+
const SAFE_NATIVE_METHODS = /* @__PURE__ */ new Set([
|
|
73
|
+
Array.prototype.at,
|
|
74
|
+
Array.prototype.concat,
|
|
75
|
+
Array.prototype.entries,
|
|
76
|
+
Array.prototype.every,
|
|
77
|
+
Array.prototype.filter,
|
|
78
|
+
Array.prototype.find,
|
|
79
|
+
Array.prototype.findIndex,
|
|
80
|
+
Array.prototype.flat,
|
|
81
|
+
Array.prototype.flatMap,
|
|
82
|
+
Array.prototype.forEach,
|
|
83
|
+
Array.prototype.includes,
|
|
84
|
+
Array.prototype.indexOf,
|
|
85
|
+
Array.prototype.join,
|
|
86
|
+
Array.prototype.keys,
|
|
87
|
+
Array.prototype.lastIndexOf,
|
|
88
|
+
Array.prototype.map,
|
|
89
|
+
Array.prototype.reduce,
|
|
90
|
+
Array.prototype.reduceRight,
|
|
91
|
+
Array.prototype.slice,
|
|
92
|
+
Array.prototype.some,
|
|
93
|
+
Array.prototype.toLocaleString,
|
|
94
|
+
Array.prototype.toString,
|
|
95
|
+
Array.prototype.values,
|
|
96
|
+
String.prototype.at,
|
|
97
|
+
String.prototype.charAt,
|
|
98
|
+
String.prototype.charCodeAt,
|
|
99
|
+
String.prototype.codePointAt,
|
|
100
|
+
String.prototype.concat,
|
|
101
|
+
String.prototype.endsWith,
|
|
102
|
+
String.prototype.includes,
|
|
103
|
+
String.prototype.indexOf,
|
|
104
|
+
String.prototype.lastIndexOf,
|
|
105
|
+
String.prototype.localeCompare,
|
|
106
|
+
String.prototype.normalize,
|
|
107
|
+
String.prototype.padEnd,
|
|
108
|
+
String.prototype.padStart,
|
|
109
|
+
String.prototype.repeat,
|
|
110
|
+
String.prototype.replace,
|
|
111
|
+
String.prototype.replaceAll,
|
|
112
|
+
String.prototype.slice,
|
|
113
|
+
String.prototype.split,
|
|
114
|
+
String.prototype.startsWith,
|
|
115
|
+
String.prototype.substring,
|
|
116
|
+
String.prototype.substr,
|
|
117
|
+
String.prototype.toLocaleLowerCase,
|
|
118
|
+
String.prototype.toLocaleUpperCase,
|
|
119
|
+
String.prototype.toLowerCase,
|
|
120
|
+
String.prototype.toString,
|
|
121
|
+
String.prototype.toUpperCase,
|
|
122
|
+
String.prototype.trim,
|
|
123
|
+
String.prototype.trimEnd,
|
|
124
|
+
String.prototype.trimStart,
|
|
125
|
+
String.prototype.valueOf,
|
|
126
|
+
Number.prototype.toExponential,
|
|
127
|
+
Number.prototype.toFixed,
|
|
128
|
+
Number.prototype.toLocaleString,
|
|
129
|
+
Number.prototype.toPrecision,
|
|
130
|
+
Number.prototype.toString,
|
|
131
|
+
Number.prototype.valueOf,
|
|
132
|
+
Boolean.prototype.toString,
|
|
133
|
+
Boolean.prototype.valueOf,
|
|
134
|
+
BigInt.prototype.toString,
|
|
135
|
+
BigInt.prototype.valueOf,
|
|
136
|
+
Date.prototype.getDate,
|
|
137
|
+
Date.prototype.getDay,
|
|
138
|
+
Date.prototype.getFullYear,
|
|
139
|
+
Date.prototype.getHours,
|
|
140
|
+
Date.prototype.getMilliseconds,
|
|
141
|
+
Date.prototype.getMinutes,
|
|
142
|
+
Date.prototype.getMonth,
|
|
143
|
+
Date.prototype.getSeconds,
|
|
144
|
+
Date.prototype.getTime,
|
|
145
|
+
Date.prototype.getUTCDate,
|
|
146
|
+
Date.prototype.getUTCFullYear,
|
|
147
|
+
Date.prototype.toISOString,
|
|
148
|
+
Date.prototype.toJSON,
|
|
149
|
+
Date.prototype.toLocaleDateString,
|
|
150
|
+
Date.prototype.toLocaleString,
|
|
151
|
+
Date.prototype.toLocaleTimeString,
|
|
152
|
+
Date.prototype.toString,
|
|
153
|
+
Date.prototype.valueOf,
|
|
154
|
+
Object.prototype.hasOwnProperty,
|
|
155
|
+
Object.prototype.isPrototypeOf,
|
|
156
|
+
Object.prototype.propertyIsEnumerable,
|
|
157
|
+
Object.prototype.toLocaleString,
|
|
158
|
+
Object.prototype.toString,
|
|
159
|
+
Object.prototype.valueOf
|
|
20
160
|
]);
|
|
161
|
+
const SAFE_COERCION_HOOKS = /* @__PURE__ */ new Set([
|
|
162
|
+
Object.prototype.toString,
|
|
163
|
+
Object.prototype.valueOf,
|
|
164
|
+
Object.prototype.toLocaleString,
|
|
165
|
+
Array.prototype.toString,
|
|
166
|
+
Array.prototype.toLocaleString,
|
|
167
|
+
Date.prototype.toString,
|
|
168
|
+
Date.prototype.valueOf,
|
|
169
|
+
Date.prototype.toLocaleString,
|
|
170
|
+
Date.prototype.toLocaleDateString,
|
|
171
|
+
Date.prototype.toLocaleTimeString,
|
|
172
|
+
Date.prototype[Symbol.toPrimitive],
|
|
173
|
+
Number.prototype.toString,
|
|
174
|
+
Number.prototype.valueOf,
|
|
175
|
+
Number.prototype.toLocaleString,
|
|
176
|
+
String.prototype.toString,
|
|
177
|
+
String.prototype.valueOf,
|
|
178
|
+
Boolean.prototype.toString,
|
|
179
|
+
Boolean.prototype.valueOf,
|
|
180
|
+
BigInt.prototype.toString,
|
|
181
|
+
BigInt.prototype.valueOf,
|
|
182
|
+
RegExp.prototype.toString,
|
|
183
|
+
Error.prototype.toString
|
|
184
|
+
]);
|
|
185
|
+
const INTERPRETER_FUNCTIONS = /* @__PURE__ */ new WeakSet();
|
|
186
|
+
const OPTIONAL_SHORT_CIRCUIT = Symbol("optional-short-circuit");
|
|
187
|
+
function normalizeOptional(value) {
|
|
188
|
+
return value === OPTIONAL_SHORT_CIRCUIT ? void 0 : value;
|
|
189
|
+
}
|
|
190
|
+
const CALLBACK_NATIVE_METHODS = /* @__PURE__ */ new Set([
|
|
191
|
+
Array.prototype.every,
|
|
192
|
+
Array.prototype.filter,
|
|
193
|
+
Array.prototype.find,
|
|
194
|
+
Array.prototype.findIndex,
|
|
195
|
+
Array.prototype.flatMap,
|
|
196
|
+
Array.prototype.forEach,
|
|
197
|
+
Array.prototype.map,
|
|
198
|
+
Array.prototype.reduce,
|
|
199
|
+
Array.prototype.reduceRight,
|
|
200
|
+
Array.prototype.some,
|
|
201
|
+
String.prototype.replace,
|
|
202
|
+
String.prototype.replaceAll
|
|
203
|
+
]);
|
|
204
|
+
function assertSafeCallbackArguments(fn, args, options) {
|
|
205
|
+
if (!CALLBACK_NATIVE_METHODS.has(fn)) return;
|
|
206
|
+
for (const argument of args) {
|
|
207
|
+
if (typeof argument !== "function") continue;
|
|
208
|
+
const argumentName = argument.name;
|
|
209
|
+
if (isNativeFunction(argument) || isInterpreterFunction(argument)) continue;
|
|
210
|
+
if (isMethodNameAllowed(argumentName, options)) continue;
|
|
211
|
+
fail("Calling custom methods is not allowed.");
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function assertSafeCoercion(fn, thisArg, args, options) {
|
|
215
|
+
for (const argument of args) assertSafeCoercionValue(argument, options, false);
|
|
216
|
+
if (fn === Array.prototype.join || fn === Array.prototype.toString) {
|
|
217
|
+
forEachArrayElement(thisArg, (value) => assertSafeCoercionValue(value, options, false));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
if (fn === Array.prototype.toLocaleString) {
|
|
221
|
+
forEachArrayElement(thisArg, (value) => assertSafeCoercionValue(value, options, true));
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (fn === Object.prototype.toLocaleString) assertSafeCoercionValue(thisArg, options, true);
|
|
225
|
+
}
|
|
226
|
+
function forEachArrayElement(value, callback) {
|
|
227
|
+
if (value == null || typeof value !== "object") return;
|
|
228
|
+
const lengthDescriptor = Object.getOwnPropertyDescriptor(value, "length");
|
|
229
|
+
if (!lengthDescriptor || !("value" in lengthDescriptor) || typeof lengthDescriptor.value !== "number") return;
|
|
230
|
+
if (lengthDescriptor.value > MAX_STRING_LENGTH) fail("Array coercion is too large.");
|
|
231
|
+
for (let index = 0; index < lengthDescriptor.value; index++) {
|
|
232
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, index);
|
|
233
|
+
if (!descriptor) continue;
|
|
234
|
+
if (!("value" in descriptor)) fail("Access to accessor properties is not allowed.");
|
|
235
|
+
callback(descriptor.value);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function assertSafeCoercionValue(value, options, locale, depth = 0) {
|
|
239
|
+
if (value == null || typeof value !== "object" && typeof value !== "function") return;
|
|
240
|
+
if (depth > 16) fail("Coercion chain is nested too deeply.");
|
|
241
|
+
if (Array.isArray(value)) {
|
|
242
|
+
forEachArrayElement(value, (element) => assertSafeCoercionValue(element, options, locale, depth + 1));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (typeof value === "function" && (isInterpreterFunction(value) || isNativeFunction(value))) return;
|
|
246
|
+
const hooks = locale ? [
|
|
247
|
+
"toLocaleString",
|
|
248
|
+
"toString",
|
|
249
|
+
"valueOf",
|
|
250
|
+
Symbol.toPrimitive,
|
|
251
|
+
Symbol.isConcatSpreadable
|
|
252
|
+
] : [
|
|
253
|
+
"toString",
|
|
254
|
+
"valueOf",
|
|
255
|
+
Symbol.toPrimitive,
|
|
256
|
+
Symbol.isConcatSpreadable
|
|
257
|
+
];
|
|
258
|
+
for (const hookName of hooks) {
|
|
259
|
+
const descriptor = findPropertyDescriptor(value, hookName);
|
|
260
|
+
if (!descriptor) continue;
|
|
261
|
+
if (!("value" in descriptor)) fail("Access to accessor properties is not allowed.");
|
|
262
|
+
const hook = descriptor.value;
|
|
263
|
+
if (typeof hook !== "function" || isNativeFunction(hook) || isInterpreterFunction(hook) || SAFE_COERCION_HOOKS.has(hook)) continue;
|
|
264
|
+
if (typeof hookName === "string" && isMethodNameAllowed(hookName, options)) continue;
|
|
265
|
+
fail("Calling custom methods is not allowed.");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function findPropertyDescriptor(value, property) {
|
|
269
|
+
let current = value;
|
|
270
|
+
while (current) {
|
|
271
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, property);
|
|
272
|
+
if (descriptor) return descriptor;
|
|
273
|
+
current = Object.getPrototypeOf(current);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
const HOST_OBJECT_TAGS = /* @__PURE__ */ new Set([
|
|
277
|
+
"Window",
|
|
278
|
+
"global",
|
|
279
|
+
"globalThis",
|
|
280
|
+
"Document",
|
|
281
|
+
"HTMLDocument",
|
|
282
|
+
"XMLDocument",
|
|
283
|
+
"DocumentFragment",
|
|
284
|
+
"DocumentType",
|
|
285
|
+
"Node",
|
|
286
|
+
"NodeList",
|
|
287
|
+
"HTMLCollection",
|
|
288
|
+
"NamedNodeMap",
|
|
289
|
+
"Element",
|
|
290
|
+
"Event",
|
|
291
|
+
"EventTarget",
|
|
292
|
+
"CustomEvent",
|
|
293
|
+
"MouseEvent",
|
|
294
|
+
"KeyboardEvent",
|
|
295
|
+
"PointerEvent",
|
|
296
|
+
"FocusEvent",
|
|
297
|
+
"InputEvent",
|
|
298
|
+
"Storage",
|
|
299
|
+
"Location",
|
|
300
|
+
"History",
|
|
301
|
+
"Navigator",
|
|
302
|
+
"Screen",
|
|
303
|
+
"XMLHttpRequest",
|
|
304
|
+
"WebSocket",
|
|
305
|
+
"Worker",
|
|
306
|
+
"MessagePort",
|
|
307
|
+
"MessageChannel",
|
|
308
|
+
"File",
|
|
309
|
+
"FileList",
|
|
310
|
+
"FileReader",
|
|
311
|
+
"Blob",
|
|
312
|
+
"FormData",
|
|
313
|
+
"URL",
|
|
314
|
+
"URLSearchParams",
|
|
315
|
+
"MutationObserver",
|
|
316
|
+
"IntersectionObserver",
|
|
317
|
+
"ResizeObserver",
|
|
318
|
+
"Performance"
|
|
319
|
+
]);
|
|
320
|
+
function isHostObject(value) {
|
|
321
|
+
if (value == null || typeof value !== "object" && typeof value !== "function") return false;
|
|
322
|
+
if (value === globalThis) return true;
|
|
323
|
+
try {
|
|
324
|
+
const tagDescriptor = findPropertyDescriptor(value, Symbol.toStringTag);
|
|
325
|
+
let tag;
|
|
326
|
+
if (tagDescriptor) {
|
|
327
|
+
if (!("value" in tagDescriptor) || typeof tagDescriptor.value !== "string") return true;
|
|
328
|
+
tag = tagDescriptor.value;
|
|
329
|
+
} else tag = Object.prototype.toString.call(value).slice(8, -1);
|
|
330
|
+
if (HOST_OBJECT_TAGS.has(tag)) return true;
|
|
331
|
+
if (/(?:Element|Event|Document|Node|Observer|Collection|List|Map)$/.test(tag) && tag !== "Map" && tag !== "WeakMap" && tag !== "Set" && tag !== "WeakSet") return true;
|
|
332
|
+
} catch {
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
function isNativeFunction(value) {
|
|
338
|
+
return typeof value === "function" && SAFE_NATIVE_METHODS.has(value);
|
|
339
|
+
}
|
|
340
|
+
function isInterpreterFunction(value) {
|
|
341
|
+
return typeof value === "function" && INTERPRETER_FUNCTIONS.has(value);
|
|
342
|
+
}
|
|
343
|
+
function assertSafeValue(value) {
|
|
344
|
+
if (isHostObject(value)) fail("Access to host objects is not allowed.");
|
|
345
|
+
return value;
|
|
346
|
+
}
|
|
21
347
|
const PUNCTUATORS = [
|
|
22
348
|
"===",
|
|
23
349
|
"!==",
|
|
@@ -248,14 +574,17 @@ var ExpressionParser = class {
|
|
|
248
574
|
}
|
|
249
575
|
parseArrow() {
|
|
250
576
|
const params = [];
|
|
251
|
-
if (this.current().type === "identifier")
|
|
252
|
-
|
|
577
|
+
if (this.current().type === "identifier") {
|
|
578
|
+
const parameter = this.advance().value;
|
|
579
|
+
if (FORBIDDEN_PROPERTIES.has(parameter) || RESERVED_BINDING_NAMES.has(parameter)) fail("Forbidden arrow function parameter name.");
|
|
580
|
+
params.push(parameter);
|
|
581
|
+
} else {
|
|
253
582
|
this.expectPunctuator("(");
|
|
254
583
|
if (!isPunctuator(this.current(), ")")) do {
|
|
255
584
|
if (isPunctuator(this.current(), ")")) break;
|
|
256
585
|
const parameter = this.advance();
|
|
257
586
|
if (parameter.type !== "identifier") fail("Arrow function parameters must be identifiers.");
|
|
258
|
-
if (FORBIDDEN_PROPERTIES.has(parameter.value)) fail("Forbidden arrow function parameter name.");
|
|
587
|
+
if (FORBIDDEN_PROPERTIES.has(parameter.value) || RESERVED_BINDING_NAMES.has(parameter.value)) fail("Forbidden arrow function parameter name.");
|
|
259
588
|
params.push(parameter.value);
|
|
260
589
|
} while (this.matchPunctuator(","));
|
|
261
590
|
this.expectPunctuator(")");
|
|
@@ -393,27 +722,46 @@ var ExpressionParser = class {
|
|
|
393
722
|
}
|
|
394
723
|
parseExponent() {
|
|
395
724
|
const left = this.parseUnary();
|
|
396
|
-
if (this.matchPunctuator("**"))
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
725
|
+
if (this.matchPunctuator("**")) {
|
|
726
|
+
this.enter();
|
|
727
|
+
try {
|
|
728
|
+
return {
|
|
729
|
+
type: "Binary",
|
|
730
|
+
operator: "**",
|
|
731
|
+
left,
|
|
732
|
+
right: this.parseExponent()
|
|
733
|
+
};
|
|
734
|
+
} finally {
|
|
735
|
+
this.leave();
|
|
736
|
+
}
|
|
737
|
+
}
|
|
402
738
|
return left;
|
|
403
739
|
}
|
|
404
740
|
parseUnary() {
|
|
405
|
-
if (isPunctuator(this.current(), "!") || isPunctuator(this.current(), "-") || isPunctuator(this.current(), "+"))
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
741
|
+
if (isPunctuator(this.current(), "!") || isPunctuator(this.current(), "-") || isPunctuator(this.current(), "+")) {
|
|
742
|
+
this.enter();
|
|
743
|
+
try {
|
|
744
|
+
return {
|
|
745
|
+
type: "Unary",
|
|
746
|
+
operator: this.advance().value,
|
|
747
|
+
argument: this.parseUnary()
|
|
748
|
+
};
|
|
749
|
+
} finally {
|
|
750
|
+
this.leave();
|
|
751
|
+
}
|
|
752
|
+
}
|
|
410
753
|
if (isIdentifier(this.current(), "typeof")) {
|
|
411
|
-
this.
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
754
|
+
this.enter();
|
|
755
|
+
try {
|
|
756
|
+
this.advance();
|
|
757
|
+
return {
|
|
758
|
+
type: "Unary",
|
|
759
|
+
operator: "typeof",
|
|
760
|
+
argument: this.parseUnary()
|
|
761
|
+
};
|
|
762
|
+
} finally {
|
|
763
|
+
this.leave();
|
|
764
|
+
}
|
|
417
765
|
}
|
|
418
766
|
return this.parsePostfix();
|
|
419
767
|
}
|
|
@@ -494,17 +842,22 @@ var ExpressionParser = class {
|
|
|
494
842
|
return node;
|
|
495
843
|
}
|
|
496
844
|
parseArguments() {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
spread
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
845
|
+
this.enter();
|
|
846
|
+
try {
|
|
847
|
+
const args = [];
|
|
848
|
+
if (!isPunctuator(this.current(), ")")) do {
|
|
849
|
+
if (isPunctuator(this.current(), ")")) break;
|
|
850
|
+
const spread = this.matchPunctuator("...");
|
|
851
|
+
args.push({
|
|
852
|
+
spread,
|
|
853
|
+
value: this.parseAssignment()
|
|
854
|
+
});
|
|
855
|
+
} while (this.matchPunctuator(","));
|
|
856
|
+
this.expectPunctuator(")");
|
|
857
|
+
return args;
|
|
858
|
+
} finally {
|
|
859
|
+
this.leave();
|
|
860
|
+
}
|
|
508
861
|
}
|
|
509
862
|
parsePrimary() {
|
|
510
863
|
const token = this.current();
|
|
@@ -565,70 +918,107 @@ var ExpressionParser = class {
|
|
|
565
918
|
return fail("Unexpected token in expression.");
|
|
566
919
|
}
|
|
567
920
|
parseArray() {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
spread
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
921
|
+
this.enter();
|
|
922
|
+
try {
|
|
923
|
+
const elements = [];
|
|
924
|
+
if (!isPunctuator(this.current(), "]")) do {
|
|
925
|
+
if (isPunctuator(this.current(), "]")) break;
|
|
926
|
+
const spread = this.matchPunctuator("...");
|
|
927
|
+
elements.push({
|
|
928
|
+
spread,
|
|
929
|
+
value: this.parseAssignment()
|
|
930
|
+
});
|
|
931
|
+
} while (this.matchPunctuator(","));
|
|
932
|
+
this.expectPunctuator("]");
|
|
933
|
+
return {
|
|
934
|
+
type: "Array",
|
|
935
|
+
elements
|
|
936
|
+
};
|
|
937
|
+
} finally {
|
|
938
|
+
this.leave();
|
|
939
|
+
}
|
|
582
940
|
}
|
|
583
941
|
parseObject() {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
if (this.
|
|
942
|
+
this.enter();
|
|
943
|
+
try {
|
|
944
|
+
const properties = [];
|
|
945
|
+
if (!isPunctuator(this.current(), "}")) do {
|
|
946
|
+
if (isPunctuator(this.current(), "}")) break;
|
|
947
|
+
if (this.matchPunctuator("...")) {
|
|
948
|
+
properties.push({
|
|
949
|
+
spread: true,
|
|
950
|
+
value: this.parseAssignment(),
|
|
951
|
+
computed: false
|
|
952
|
+
});
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
let key;
|
|
956
|
+
let computed = false;
|
|
957
|
+
if (this.matchPunctuator("[")) {
|
|
958
|
+
key = this.parseExpression();
|
|
959
|
+
this.expectPunctuator("]");
|
|
960
|
+
computed = true;
|
|
961
|
+
} else {
|
|
962
|
+
const keyToken = this.advance();
|
|
963
|
+
if (keyToken.type === "identifier" || keyToken.type === "string") key = {
|
|
964
|
+
type: "Literal",
|
|
965
|
+
value: keyToken.value
|
|
966
|
+
};
|
|
967
|
+
else if (keyToken.type === "number") key = {
|
|
968
|
+
type: "Literal",
|
|
969
|
+
value: String(Number(keyToken.value))
|
|
970
|
+
};
|
|
971
|
+
else return fail("Invalid object key.");
|
|
972
|
+
}
|
|
973
|
+
this.expectPunctuator(":");
|
|
974
|
+
const value = this.parseAssignment();
|
|
588
975
|
properties.push({
|
|
589
|
-
spread:
|
|
590
|
-
|
|
591
|
-
|
|
976
|
+
spread: false,
|
|
977
|
+
key,
|
|
978
|
+
value,
|
|
979
|
+
computed
|
|
592
980
|
});
|
|
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
|
-
};
|
|
981
|
+
} while (this.matchPunctuator(","));
|
|
982
|
+
this.expectPunctuator("}");
|
|
983
|
+
return {
|
|
984
|
+
type: "Object",
|
|
985
|
+
properties
|
|
986
|
+
};
|
|
987
|
+
} finally {
|
|
988
|
+
this.leave();
|
|
989
|
+
}
|
|
627
990
|
}
|
|
628
991
|
};
|
|
629
992
|
function assertSafeProperty(property) {
|
|
630
993
|
if (FORBIDDEN_PROPERTIES.has(property)) fail("Access to a forbidden property was blocked.");
|
|
631
994
|
}
|
|
995
|
+
function isMethodNameAllowed(name, options) {
|
|
996
|
+
if (options?.allowCustomMethods === true) return true;
|
|
997
|
+
if (!Array.isArray(options?.allowedMethods)) return false;
|
|
998
|
+
return options.allowedMethods.some((entry) => typeof entry === "string" ? entry === name : entry?.name === name);
|
|
999
|
+
}
|
|
1000
|
+
function isRootReceiver(receiver, state) {
|
|
1001
|
+
if (receiver == null || typeof receiver !== "object" && typeof receiver !== "function") return false;
|
|
1002
|
+
if (receiver === state.rootVm) return true;
|
|
1003
|
+
return state.rootVmValues.has(receiver);
|
|
1004
|
+
}
|
|
1005
|
+
function isMethodAllowedForReceiver(name, receiver, state, options) {
|
|
1006
|
+
if (options?.allowCustomMethods === true) return true;
|
|
1007
|
+
if (!Array.isArray(options?.allowedMethods)) return false;
|
|
1008
|
+
for (const entry of options.allowedMethods) {
|
|
1009
|
+
if (typeof entry === "string") {
|
|
1010
|
+
if (entry === name && isRootReceiver(receiver, state)) return true;
|
|
1011
|
+
continue;
|
|
1012
|
+
}
|
|
1013
|
+
if (entry == null || entry.name !== name) continue;
|
|
1014
|
+
if (entry.on !== void 0) {
|
|
1015
|
+
if (receiver === entry.on) return true;
|
|
1016
|
+
continue;
|
|
1017
|
+
}
|
|
1018
|
+
if ((entry.receiver ?? "root") === "any" || isRootReceiver(receiver, state)) return true;
|
|
1019
|
+
}
|
|
1020
|
+
return false;
|
|
1021
|
+
}
|
|
632
1022
|
function defineSafeProperty(target, key, value) {
|
|
633
1023
|
assertSafeProperty(key);
|
|
634
1024
|
Object.defineProperty(target, key, {
|
|
@@ -638,19 +1028,51 @@ function defineSafeProperty(target, key, value) {
|
|
|
638
1028
|
configurable: true
|
|
639
1029
|
});
|
|
640
1030
|
}
|
|
641
|
-
function readMember(target, key, optional) {
|
|
1031
|
+
function readMember(target, key, optional, state, options) {
|
|
1032
|
+
if (target === OPTIONAL_SHORT_CIRCUIT) return target;
|
|
642
1033
|
if (typeof key !== "string" && typeof key !== "number") fail("Property keys must be strings or numbers.");
|
|
643
1034
|
const property = String(key);
|
|
644
1035
|
assertSafeProperty(property);
|
|
645
1036
|
if (target == null) {
|
|
646
|
-
if (optional) return;
|
|
1037
|
+
if (optional) return OPTIONAL_SHORT_CIRCUIT;
|
|
647
1038
|
fail("Cannot read properties of null or undefined.");
|
|
648
1039
|
}
|
|
649
|
-
|
|
1040
|
+
if (isHostObject(target)) fail("Access to host objects is not allowed.");
|
|
1041
|
+
const object = Object(target);
|
|
1042
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, property);
|
|
1043
|
+
if (descriptor) {
|
|
1044
|
+
if (!("value" in descriptor)) fail("Access to accessor properties is not allowed.");
|
|
1045
|
+
const value = descriptor.value;
|
|
1046
|
+
if (typeof value === "function" && !isNativeFunction(value) && !isInterpreterFunction(value) && !isMethodAllowedForReceiver(property, target, state, options)) fail("Access to custom methods is not allowed.");
|
|
1047
|
+
return assertSafeValue(value);
|
|
1048
|
+
}
|
|
1049
|
+
let prototype = Object.getPrototypeOf(object);
|
|
1050
|
+
while (prototype) {
|
|
1051
|
+
const inheritedDescriptor = Object.getOwnPropertyDescriptor(prototype, property);
|
|
1052
|
+
if (inheritedDescriptor) {
|
|
1053
|
+
if (!("value" in inheritedDescriptor)) fail("Access to inherited accessor properties is not allowed.");
|
|
1054
|
+
const inherited = inheritedDescriptor.value;
|
|
1055
|
+
if (typeof inherited === "function") {
|
|
1056
|
+
if (isNativeFunction(inherited) || isInterpreterFunction(inherited) || isMethodAllowedForReceiver(property, target, state, options)) return inherited;
|
|
1057
|
+
fail("Access to custom methods is not allowed.");
|
|
1058
|
+
}
|
|
1059
|
+
fail("Access to inherited properties is not allowed.");
|
|
1060
|
+
}
|
|
1061
|
+
prototype = Object.getPrototypeOf(prototype);
|
|
1062
|
+
}
|
|
650
1063
|
}
|
|
651
1064
|
function spreadValues(value) {
|
|
652
|
-
if (Array.isArray(value))
|
|
653
|
-
|
|
1065
|
+
if (Array.isArray(value)) {
|
|
1066
|
+
const values = [];
|
|
1067
|
+
forEachArrayElement(value, (element) => {
|
|
1068
|
+
values.push(element);
|
|
1069
|
+
});
|
|
1070
|
+
return values;
|
|
1071
|
+
}
|
|
1072
|
+
if (typeof value === "string") {
|
|
1073
|
+
if (value.length > MAX_STRING_LENGTH) fail("Spread value is too large.");
|
|
1074
|
+
return value.split("");
|
|
1075
|
+
}
|
|
654
1076
|
return fail("Spread is only supported for arrays and strings.");
|
|
655
1077
|
}
|
|
656
1078
|
function isPrimitive(value) {
|
|
@@ -685,7 +1107,7 @@ function compareValues(operator, left, right) {
|
|
|
685
1107
|
default: return fail(`Unsupported comparison operator "${operator}".`);
|
|
686
1108
|
}
|
|
687
1109
|
}
|
|
688
|
-
function evaluateNode(node, environment, state) {
|
|
1110
|
+
function evaluateNode(node, environment, state, options) {
|
|
689
1111
|
state.steps++;
|
|
690
1112
|
state.depth++;
|
|
691
1113
|
if (state.steps > MAX_EVALUATION_STEPS) {
|
|
@@ -701,38 +1123,98 @@ function evaluateNode(node, environment, state) {
|
|
|
701
1123
|
case "Literal": return node.value;
|
|
702
1124
|
case "Identifier":
|
|
703
1125
|
if (!environment.has(node.name)) return fail(`Unknown identifier "${node.name}".`);
|
|
704
|
-
return environment.get(node.name);
|
|
705
|
-
case "Member":
|
|
1126
|
+
return assertSafeValue(environment.get(node.name));
|
|
1127
|
+
case "Member": {
|
|
1128
|
+
const object = evaluateNode(node.object, environment, state, options);
|
|
1129
|
+
if (object === OPTIONAL_SHORT_CIRCUIT) return object;
|
|
1130
|
+
return readMember(object, normalizeOptional(evaluateNode(node.property, environment, state, options)), node.optional, state, options);
|
|
1131
|
+
}
|
|
706
1132
|
case "Call": {
|
|
707
1133
|
let fn;
|
|
708
1134
|
let thisArg;
|
|
1135
|
+
let methodName;
|
|
709
1136
|
if (node.callee.type === "Member") {
|
|
710
|
-
const object = evaluateNode(node.callee.object, environment, state);
|
|
711
|
-
|
|
1137
|
+
const object = evaluateNode(node.callee.object, environment, state, options);
|
|
1138
|
+
if (object === OPTIONAL_SHORT_CIRCUIT) return object;
|
|
1139
|
+
const key = normalizeOptional(evaluateNode(node.callee.property, environment, state, options));
|
|
1140
|
+
fn = readMember(object, key, node.callee.optional, state, options);
|
|
712
1141
|
thisArg = object;
|
|
713
|
-
|
|
714
|
-
|
|
1142
|
+
methodName = String(key);
|
|
1143
|
+
} else {
|
|
1144
|
+
fn = evaluateNode(node.callee, environment, state, options);
|
|
1145
|
+
if (fn === OPTIONAL_SHORT_CIRCUIT) return fn;
|
|
1146
|
+
}
|
|
1147
|
+
if (fn === OPTIONAL_SHORT_CIRCUIT) return fn;
|
|
1148
|
+
if (fn == null) {
|
|
1149
|
+
if (node.optional) return OPTIONAL_SHORT_CIRCUIT;
|
|
1150
|
+
return fail("Attempted to call a non-function value.");
|
|
1151
|
+
}
|
|
715
1152
|
if (typeof fn !== "function") {
|
|
716
|
-
if (node.optional) return;
|
|
1153
|
+
if (node.optional) return OPTIONAL_SHORT_CIRCUIT;
|
|
717
1154
|
return fail("Attempted to call a non-function value.");
|
|
718
1155
|
}
|
|
719
1156
|
if (fn === Function || fn === eval) return fail("Calling global constructors is not allowed.");
|
|
1157
|
+
if (node.callee.type === "Member") {
|
|
1158
|
+
if (!isNativeFunction(fn) && !isInterpreterFunction(fn) && !isMethodAllowedForReceiver(methodName ?? "", thisArg, state, options)) return fail("Calling custom methods is not allowed.");
|
|
1159
|
+
} else if (!(node.callee.type === "Identifier" && node.callee.name === "$vm" && fn === state.rootVm) && !isInterpreterFunction(fn)) return fail("Calling custom functions is not allowed.");
|
|
720
1160
|
const args = [];
|
|
721
1161
|
for (const argument of node.args) {
|
|
722
|
-
const value = evaluateNode(argument.value, environment, state);
|
|
1162
|
+
const value = normalizeOptional(evaluateNode(argument.value, environment, state, options));
|
|
723
1163
|
if (argument.spread) args.push(...spreadValues(value));
|
|
724
1164
|
else args.push(value);
|
|
725
1165
|
}
|
|
726
|
-
|
|
1166
|
+
assertSafeCallbackArguments(fn, args, options);
|
|
1167
|
+
assertSafeCoercion(fn, thisArg, args, options);
|
|
1168
|
+
if (fn === String.prototype.repeat) {
|
|
1169
|
+
const count = args[0];
|
|
1170
|
+
const source = String(thisArg ?? "");
|
|
1171
|
+
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.");
|
|
1172
|
+
}
|
|
1173
|
+
if (fn === String.prototype.padStart || fn === String.prototype.padEnd) {
|
|
1174
|
+
const targetLength = args[0];
|
|
1175
|
+
if (typeof targetLength === "number" && targetLength > MAX_STRING_LENGTH) return fail("String padding is too large.");
|
|
1176
|
+
}
|
|
1177
|
+
if (fn === String.prototype.replace || fn === String.prototype.replaceAll) {
|
|
1178
|
+
const search = args[0];
|
|
1179
|
+
const replacement = args[1];
|
|
1180
|
+
if (typeof search === "string" && typeof replacement === "string" && typeof thisArg === "string") {
|
|
1181
|
+
const sourceLength = thisArg.length;
|
|
1182
|
+
const matchCount = search.length === 0 ? fn === String.prototype.replaceAll ? sourceLength + 1 : 1 : Math.floor(sourceLength / search.length);
|
|
1183
|
+
const growthPerMatch = replacement.length - search.length;
|
|
1184
|
+
if (growthPerMatch > 0 && sourceLength + matchCount * growthPerMatch > MAX_STRING_LENGTH) return fail("String replacement is too large.");
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
if (fn === Array.prototype.join && Array.isArray(thisArg)) {
|
|
1188
|
+
const separator = args[0];
|
|
1189
|
+
if (separator === void 0 || typeof separator === "string") {
|
|
1190
|
+
const separatorLength = typeof separator === "string" ? separator.length : 1;
|
|
1191
|
+
let totalLength = Math.max(0, thisArg.length - 1) * separatorLength;
|
|
1192
|
+
for (let index = 0; index < thisArg.length; index++) {
|
|
1193
|
+
const element = thisArg[index];
|
|
1194
|
+
if (element == null) continue;
|
|
1195
|
+
if (typeof element === "string" || typeof element === "number" || typeof element === "boolean" || typeof element === "bigint") totalLength += String(element).length;
|
|
1196
|
+
else {
|
|
1197
|
+
totalLength = -1;
|
|
1198
|
+
break;
|
|
1199
|
+
}
|
|
1200
|
+
if (totalLength > MAX_STRING_LENGTH) return fail("Array join is too large.");
|
|
1201
|
+
}
|
|
1202
|
+
if (totalLength > MAX_STRING_LENGTH) return fail("Array join is too large.");
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
const result = fn.apply(thisArg, args);
|
|
1206
|
+
if (fn === state.rootVm && result !== null && (typeof result === "object" || typeof result === "function")) state.rootVmValues.add(result);
|
|
1207
|
+
if (typeof result === "string" && result.length > MAX_STRING_LENGTH) return fail("Expression result is too large.");
|
|
1208
|
+
return assertSafeValue(result);
|
|
727
1209
|
}
|
|
728
1210
|
case "Unary": {
|
|
729
|
-
const argument = evaluateNode(node.argument, environment, state);
|
|
1211
|
+
const argument = normalizeOptional(evaluateNode(node.argument, environment, state, options));
|
|
730
1212
|
switch (node.operator) {
|
|
731
1213
|
case "!": return !argument;
|
|
732
1214
|
case "typeof": return typeof argument;
|
|
733
1215
|
case "-":
|
|
734
1216
|
if (typeof argument !== "number" && typeof argument !== "bigint") return fail("Unary \"-\" only supports numbers.");
|
|
735
|
-
return
|
|
1217
|
+
return -argument;
|
|
736
1218
|
case "+":
|
|
737
1219
|
if (typeof argument !== "number") return fail("Unary \"+\" only supports numbers.");
|
|
738
1220
|
return +argument;
|
|
@@ -740,8 +1222,8 @@ function evaluateNode(node, environment, state) {
|
|
|
740
1222
|
}
|
|
741
1223
|
}
|
|
742
1224
|
case "Binary": {
|
|
743
|
-
const left = evaluateNode(node.left, environment, state);
|
|
744
|
-
const right = evaluateNode(node.right, environment, state);
|
|
1225
|
+
const left = normalizeOptional(evaluateNode(node.left, environment, state, options));
|
|
1226
|
+
const right = normalizeOptional(evaluateNode(node.right, environment, state, options));
|
|
745
1227
|
switch (node.operator) {
|
|
746
1228
|
case "===": return left === right;
|
|
747
1229
|
case "!==": return left !== right;
|
|
@@ -761,19 +1243,19 @@ function evaluateNode(node, environment, state) {
|
|
|
761
1243
|
}
|
|
762
1244
|
}
|
|
763
1245
|
case "Logical": {
|
|
764
|
-
const left = evaluateNode(node.left, environment, state);
|
|
1246
|
+
const left = normalizeOptional(evaluateNode(node.left, environment, state, options));
|
|
765
1247
|
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;
|
|
1248
|
+
case "&&": return left ? evaluateNode(node.right, environment, state, options) : left;
|
|
1249
|
+
case "||": return left ? left : evaluateNode(node.right, environment, state, options);
|
|
1250
|
+
case "??": return left == null ? evaluateNode(node.right, environment, state, options) : left;
|
|
769
1251
|
default: return fail(`Unsupported logical operator "${node.operator}".`);
|
|
770
1252
|
}
|
|
771
1253
|
}
|
|
772
|
-
case "Conditional": return evaluateNode(node.test, environment, state) ? evaluateNode(node.consequent, environment, state) : evaluateNode(node.alternate, environment, state);
|
|
1254
|
+
case "Conditional": return normalizeOptional(evaluateNode(node.test, environment, state, options)) ? evaluateNode(node.consequent, environment, state, options) : evaluateNode(node.alternate, environment, state, options);
|
|
773
1255
|
case "Array": {
|
|
774
1256
|
const values = [];
|
|
775
1257
|
for (const element of node.elements) {
|
|
776
|
-
const value = evaluateNode(element.value, environment, state);
|
|
1258
|
+
const value = normalizeOptional(evaluateNode(element.value, environment, state, options));
|
|
777
1259
|
if (element.spread) values.push(...spreadValues(value));
|
|
778
1260
|
else values.push(value);
|
|
779
1261
|
}
|
|
@@ -783,7 +1265,7 @@ function evaluateNode(node, environment, state) {
|
|
|
783
1265
|
const result = {};
|
|
784
1266
|
for (const property of node.properties) {
|
|
785
1267
|
if (property.spread) {
|
|
786
|
-
const source = evaluateNode(property.value, environment, state);
|
|
1268
|
+
const source = normalizeOptional(evaluateNode(property.value, environment, state, options));
|
|
787
1269
|
if (source == null || typeof source !== "object") return fail("Object spread is only supported for objects.");
|
|
788
1270
|
for (const key of Object.keys(source)) {
|
|
789
1271
|
const descriptor = Object.getOwnPropertyDescriptor(source, key);
|
|
@@ -792,9 +1274,9 @@ function evaluateNode(node, environment, state) {
|
|
|
792
1274
|
continue;
|
|
793
1275
|
}
|
|
794
1276
|
if (!property.key) return fail("Invalid object property.");
|
|
795
|
-
const key = property.computed ? evaluateNode(property.key, environment, state) : property.key.value;
|
|
1277
|
+
const key = property.computed ? normalizeOptional(evaluateNode(property.key, environment, state, options)) : property.key.value;
|
|
796
1278
|
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));
|
|
1279
|
+
defineSafeProperty(result, String(key), normalizeOptional(evaluateNode(property.value, environment, state, options)));
|
|
798
1280
|
}
|
|
799
1281
|
return result;
|
|
800
1282
|
}
|
|
@@ -802,13 +1284,15 @@ function evaluateNode(node, environment, state) {
|
|
|
802
1284
|
const params = node.params;
|
|
803
1285
|
const body = node.body;
|
|
804
1286
|
const closure = new Map(environment);
|
|
805
|
-
|
|
1287
|
+
const arrowFunction = function evaluateArrowFunction(...args) {
|
|
806
1288
|
const local = new Map(closure);
|
|
807
1289
|
params.forEach((parameter, index) => {
|
|
808
1290
|
local.set(parameter, args[index]);
|
|
809
1291
|
});
|
|
810
|
-
return evaluateNode(body, local, state);
|
|
1292
|
+
return normalizeOptional(evaluateNode(body, local, state, options));
|
|
811
1293
|
};
|
|
1294
|
+
INTERPRETER_FUNCTIONS.add(arrowFunction);
|
|
1295
|
+
return arrowFunction;
|
|
812
1296
|
}
|
|
813
1297
|
default: return fail("Unsupported expression node.");
|
|
814
1298
|
}
|
|
@@ -816,18 +1300,24 @@ function evaluateNode(node, environment, state) {
|
|
|
816
1300
|
state.depth--;
|
|
817
1301
|
}
|
|
818
1302
|
}
|
|
819
|
-
function evaluateSafeExpression(source, variables = {}) {
|
|
1303
|
+
function evaluateSafeExpression(source, variables = {}, options) {
|
|
820
1304
|
if (typeof source !== "string") fail("Expression must be a string.");
|
|
821
1305
|
if (source.length === 0) fail("Expression is empty.");
|
|
822
1306
|
if (source.length > MAX_SOURCE_LENGTH) fail("Expression is too long.");
|
|
823
1307
|
const ast = new ExpressionParser(tokenize(source)).parse();
|
|
824
1308
|
const environment = /* @__PURE__ */ new Map();
|
|
825
1309
|
for (const [key, value] of Object.entries(variables)) environment.set(key, value);
|
|
826
|
-
return evaluateNode(ast, environment, {
|
|
1310
|
+
return assertSafeValue(normalizeOptional(evaluateNode(ast, environment, {
|
|
827
1311
|
steps: 0,
|
|
828
|
-
depth: 0
|
|
829
|
-
|
|
1312
|
+
depth: 0,
|
|
1313
|
+
rootVm: variables["$vm"],
|
|
1314
|
+
rootVmValues: /* @__PURE__ */ new WeakSet()
|
|
1315
|
+
}, options)));
|
|
830
1316
|
}
|
|
1317
|
+
const MISSING_FORM_VALUE = Symbol("missing-form-value");
|
|
1318
|
+
const EXPRESSION_CONTEXT_PATTERN = /\$(?:vm|event|ev)\b/;
|
|
1319
|
+
const VM_EXPRESSION_PATTERN = /\$vm\b/;
|
|
1320
|
+
const EVENT_EXPRESSION_PATTERN = /\$(?:event|ev)\b/;
|
|
831
1321
|
const FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set([
|
|
832
1322
|
"__proto__",
|
|
833
1323
|
"prototype",
|
|
@@ -836,6 +1326,10 @@ const FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set([
|
|
|
836
1326
|
const MAX_PATH_DEPTH = 32;
|
|
837
1327
|
const MAX_PATH_SEGMENT_LENGTH = 128;
|
|
838
1328
|
const MAX_CONFIGURATION_ITEMS = 1e3;
|
|
1329
|
+
const MAX_CONFIGURATION_DEPTH = 32;
|
|
1330
|
+
const MAX_TOTAL_CONFIGURATION_NODES = 2e3;
|
|
1331
|
+
const MAX_CONFIGURATION_KEYS = 100;
|
|
1332
|
+
const MAX_CONFIGURATION_KEY_LENGTH = 128;
|
|
839
1333
|
const MAX_ATTRIBUTE_NAME_LENGTH = 128;
|
|
840
1334
|
const MAX_ATTRIBUTE_VALUE_LENGTH = 8192;
|
|
841
1335
|
const MAX_PATTERN_LENGTH = 512;
|
|
@@ -871,6 +1365,22 @@ const ALLOWED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
|
871
1365
|
"src"
|
|
872
1366
|
]);
|
|
873
1367
|
const URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "src"]);
|
|
1368
|
+
const STRICT_DISALLOWED_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
1369
|
+
"id",
|
|
1370
|
+
"class",
|
|
1371
|
+
"for",
|
|
1372
|
+
"href",
|
|
1373
|
+
"src"
|
|
1374
|
+
]);
|
|
1375
|
+
const BOOLEAN_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
1376
|
+
"hidden",
|
|
1377
|
+
"disabled",
|
|
1378
|
+
"readonly",
|
|
1379
|
+
"required",
|
|
1380
|
+
"checked",
|
|
1381
|
+
"selected",
|
|
1382
|
+
"multiple"
|
|
1383
|
+
]);
|
|
874
1384
|
var FGDynamicRegistry = class {
|
|
875
1385
|
constructor() {
|
|
876
1386
|
this._components = /* @__PURE__ */ new Map();
|
|
@@ -926,9 +1436,17 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
926
1436
|
this.viewModel = model(...ngDevMode ? [void 0, { debugName: "viewModel" }] : /* istanbul ignore next */ []);
|
|
927
1437
|
this.formGroup = input(...ngDevMode ? [void 0, { debugName: "formGroup" }] : /* istanbul ignore next */ []);
|
|
928
1438
|
this.registry = input(FGDynamicService.registry, ...ngDevMode ? [{ debugName: "registry" }] : /* istanbul ignore next */ []);
|
|
1439
|
+
this.expressionPolicy = input({}, ...ngDevMode ? [{ debugName: "expressionPolicy" }] : /* istanbul ignore next */ []);
|
|
1440
|
+
this.formControlPolicy = input({}, ...ngDevMode ? [{ debugName: "formControlPolicy" }] : /* istanbul ignore next */ []);
|
|
1441
|
+
this.typePolicy = input({}, ...ngDevMode ? [{ debugName: "typePolicy" }] : /* istanbul ignore next */ []);
|
|
1442
|
+
this.attributePolicy = input({}, ...ngDevMode ? [{ debugName: "attributePolicy" }] : /* istanbul ignore next */ []);
|
|
1443
|
+
this.depth = input(0, ...ngDevMode ? [{ debugName: "depth" }] : /* istanbul ignore next */ []);
|
|
1444
|
+
this._configurationIsValid = computed(() => this.validateConfiguration(this.configuration()), ...ngDevMode ? [{ debugName: "_configurationIsValid" }] : /* istanbul ignore next */ []);
|
|
929
1445
|
this.items = computed(() => {
|
|
1446
|
+
if (this.depth() >= MAX_CONFIGURATION_DEPTH || !this._configurationIsValid()) return [];
|
|
930
1447
|
const configuration = this.configuration();
|
|
931
|
-
|
|
1448
|
+
if (configuration == null || typeof configuration !== "object" || Array.isArray(configuration)) return [];
|
|
1449
|
+
const items = configuration.items;
|
|
932
1450
|
if (!Array.isArray(items)) return [];
|
|
933
1451
|
return items.filter((item) => item != null && typeof item === "object" && !Array.isArray(item)).slice(0, MAX_CONFIGURATION_ITEMS);
|
|
934
1452
|
}, ...ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []);
|
|
@@ -945,62 +1463,164 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
945
1463
|
this._managedValidatorFns = [];
|
|
946
1464
|
this._injector = inject(Injector);
|
|
947
1465
|
this._ngOnChangesCounter = 0;
|
|
1466
|
+
this._destroyed = false;
|
|
1467
|
+
this._ownsFormControl = false;
|
|
1468
|
+
this._createdFormGroups = [];
|
|
1469
|
+
this._hasSyncedControlValue = false;
|
|
1470
|
+
this._disabledManaged = false;
|
|
1471
|
+
this._appliedAttributes = /* @__PURE__ */ new Set();
|
|
1472
|
+
this._appliedInputs = /* @__PURE__ */ new Set();
|
|
948
1473
|
}
|
|
949
1474
|
async ngOnChanges(changes) {
|
|
1475
|
+
if (this._destroyed) return;
|
|
950
1476
|
const counter = ++this._ngOnChangesCounter;
|
|
951
1477
|
try {
|
|
952
1478
|
const configuration = this.configuration();
|
|
953
1479
|
if (configuration != null && (typeof configuration !== "object" || Array.isArray(configuration))) {
|
|
954
1480
|
this.logError("Invalid configuration: expected an object.");
|
|
1481
|
+
this.clearResolvedComponent(counter);
|
|
955
1482
|
return;
|
|
956
1483
|
}
|
|
957
|
-
|
|
958
|
-
|
|
1484
|
+
if (!this._configurationIsValid()) {
|
|
1485
|
+
this.logError("Invalid configuration: it exceeds the structural limits.");
|
|
1486
|
+
this.clearResolvedComponent(counter);
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
await this.loadComponentAsync(counter);
|
|
1490
|
+
if (this._destroyed || counter !== this._ngOnChangesCounter) return;
|
|
959
1491
|
const items = this.items();
|
|
960
1492
|
const itemsSignature = items.length > 0 ? `${items.length}:${items.map((item, index) => `${index}:${item?.type}`).join("|")}` : "";
|
|
961
1493
|
if (this._componentRef && this._lastProjectedItemsSignature !== itemsSignature) {
|
|
962
1494
|
this.cleanup();
|
|
963
1495
|
this._lastProjectedItemsSignature = itemsSignature;
|
|
964
1496
|
} else if (!this._componentRef) this._lastProjectedItemsSignature = itemsSignature;
|
|
1497
|
+
this.rewireFormIfNeeded();
|
|
965
1498
|
this.createComponent();
|
|
966
|
-
if (counter !== this._ngOnChangesCounter) return;
|
|
1499
|
+
if (this._destroyed || counter !== this._ngOnChangesCounter) return;
|
|
967
1500
|
this.setInputs();
|
|
968
1501
|
this.setFormControlStatus();
|
|
969
1502
|
this.setFormControlValidators();
|
|
1503
|
+
this.syncFormControlFromViewModel();
|
|
970
1504
|
this.setAttributes();
|
|
971
1505
|
this.handleOutputsIfChanged();
|
|
972
1506
|
if (this._componentRef?.changeDetectorRef) this._componentRef.changeDetectorRef.markForCheck();
|
|
973
1507
|
} catch (error) {
|
|
974
|
-
|
|
1508
|
+
if (counter === this._ngOnChangesCounter) {
|
|
1509
|
+
this.logError("Error during component initialization.", error);
|
|
1510
|
+
this.clearResolvedComponent(counter);
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
clearResolvedComponent(counter) {
|
|
1515
|
+
if (this._destroyed || counter !== this._ngOnChangesCounter) return;
|
|
1516
|
+
this._component = void 0;
|
|
1517
|
+
if (this._componentRef) this.cleanup();
|
|
1518
|
+
}
|
|
1519
|
+
validateConfiguration(configuration) {
|
|
1520
|
+
if (configuration == null) return true;
|
|
1521
|
+
const stats = this.collectConfigurationStats(configuration);
|
|
1522
|
+
if (!stats) return false;
|
|
1523
|
+
return this.depth() + stats.maxDepth <= MAX_CONFIGURATION_DEPTH && stats.nodes <= MAX_TOTAL_CONFIGURATION_NODES;
|
|
1524
|
+
}
|
|
1525
|
+
collectConfigurationStats(configuration) {
|
|
1526
|
+
const stack = [{
|
|
1527
|
+
item: configuration,
|
|
1528
|
+
depth: 0
|
|
1529
|
+
}];
|
|
1530
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
1531
|
+
let nodes = 0;
|
|
1532
|
+
let maxDepth = 0;
|
|
1533
|
+
while (stack.length > 0) {
|
|
1534
|
+
const current = stack.pop();
|
|
1535
|
+
const item = current.item;
|
|
1536
|
+
if (item == null || typeof item !== "object" || Array.isArray(item)) {
|
|
1537
|
+
if (current.depth === 0) return null;
|
|
1538
|
+
continue;
|
|
1539
|
+
}
|
|
1540
|
+
if (seen.has(item)) return null;
|
|
1541
|
+
seen.add(item);
|
|
1542
|
+
nodes++;
|
|
1543
|
+
if (nodes > MAX_TOTAL_CONFIGURATION_NODES || current.depth > MAX_CONFIGURATION_DEPTH) return null;
|
|
1544
|
+
if (current.depth > maxDepth) maxDepth = current.depth;
|
|
1545
|
+
for (const field of [
|
|
1546
|
+
"inputs",
|
|
1547
|
+
"attributes",
|
|
1548
|
+
"outputs"
|
|
1549
|
+
]) {
|
|
1550
|
+
const map = item[field];
|
|
1551
|
+
if (map == null) continue;
|
|
1552
|
+
if (typeof map !== "object" || Array.isArray(map)) return null;
|
|
1553
|
+
const keys = Object.keys(map);
|
|
1554
|
+
if (keys.length > MAX_CONFIGURATION_KEYS) return null;
|
|
1555
|
+
if (keys.some((key) => key.length > MAX_CONFIGURATION_KEY_LENGTH || FORBIDDEN_PATH_SEGMENTS.has(key.toLowerCase()))) return null;
|
|
1556
|
+
}
|
|
1557
|
+
const items = item["items"];
|
|
1558
|
+
if (items == null) continue;
|
|
1559
|
+
if (!Array.isArray(items) || items.length > MAX_CONFIGURATION_ITEMS) return null;
|
|
1560
|
+
for (const child of items) stack.push({
|
|
1561
|
+
item: child,
|
|
1562
|
+
depth: current.depth + 1
|
|
1563
|
+
});
|
|
975
1564
|
}
|
|
1565
|
+
return {
|
|
1566
|
+
nodes,
|
|
1567
|
+
maxDepth
|
|
1568
|
+
};
|
|
976
1569
|
}
|
|
977
|
-
async loadComponentAsync() {
|
|
1570
|
+
async loadComponentAsync(counter) {
|
|
978
1571
|
const configurationType = this.configuration()?.type;
|
|
979
|
-
if (configurationType == null)
|
|
1572
|
+
if (configurationType == null) {
|
|
1573
|
+
this.clearResolvedComponent(counter);
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
if (this.typePolicy()?.requireScopedRegistry === true && this.isUsingGlobalRegistry()) {
|
|
1577
|
+
this.logWarning("A scoped registry is required by typePolicy but only the global registry is available.");
|
|
1578
|
+
this.clearResolvedComponent(counter);
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
980
1581
|
let candidate;
|
|
981
1582
|
if (typeof configurationType === "string") {
|
|
982
1583
|
candidate = this.getRegistry().get(configurationType);
|
|
983
1584
|
if (candidate == null) {
|
|
984
1585
|
this.logWarning(`Component type "${configurationType}" not found in the registry.`);
|
|
1586
|
+
this.clearResolvedComponent(counter);
|
|
985
1587
|
return;
|
|
986
1588
|
}
|
|
987
1589
|
} else candidate = configurationType;
|
|
1590
|
+
if (!this.isCandidateAllowed(candidate)) {
|
|
1591
|
+
this.logWarning("Component type was rejected by typePolicy (function/promise types are disabled).");
|
|
1592
|
+
this.clearResolvedComponent(counter);
|
|
1593
|
+
return;
|
|
1594
|
+
}
|
|
988
1595
|
try {
|
|
989
1596
|
const resolved = this.resolveCandidate(candidate);
|
|
990
|
-
const resolvedType = resolved
|
|
991
|
-
if (
|
|
1597
|
+
const resolvedType = this.isPromiseLike(resolved) ? await resolved : resolved;
|
|
1598
|
+
if (counter !== this._ngOnChangesCounter) return;
|
|
1599
|
+
if (!resolvedType) {
|
|
1600
|
+
this.clearResolvedComponent(counter);
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
if (this._component !== resolvedType) {
|
|
1604
|
+
this.cleanup();
|
|
1605
|
+
this._component = resolvedType;
|
|
1606
|
+
}
|
|
992
1607
|
} catch (error) {
|
|
1608
|
+
if (counter !== this._ngOnChangesCounter) return;
|
|
993
1609
|
this.logError("Unable to resolve the dynamic component type.", error);
|
|
1610
|
+
this.clearResolvedComponent(counter);
|
|
994
1611
|
}
|
|
995
1612
|
}
|
|
1613
|
+
isPromiseLike(value) {
|
|
1614
|
+
return value != null && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
1615
|
+
}
|
|
996
1616
|
resolveCandidate(candidate) {
|
|
997
1617
|
if (candidate == null) return;
|
|
998
|
-
if (candidate
|
|
1618
|
+
if (this.isPromiseLike(candidate)) return Promise.resolve(candidate).then((resolved) => this.toComponentType(resolved));
|
|
999
1619
|
if (typeof candidate === "function") {
|
|
1000
1620
|
if (this.isAngularComponentType(candidate)) return candidate;
|
|
1001
1621
|
if (candidate.length > 0) return candidate;
|
|
1002
1622
|
const result = candidate();
|
|
1003
|
-
if (result
|
|
1623
|
+
if (this.isPromiseLike(result)) return Promise.resolve(result).then((resolved) => this.toComponentType(resolved));
|
|
1004
1624
|
return this.toComponentType(result);
|
|
1005
1625
|
}
|
|
1006
1626
|
this.logWarning("Invalid component type in configuration.");
|
|
@@ -1013,6 +1633,15 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1013
1633
|
const metadata = candidate;
|
|
1014
1634
|
return Boolean(metadata["ɵcmp"] || metadata["ɵdir"] || metadata["ɵpipe"] || metadata["ɵfac"] || metadata["ngComponentDef"] || metadata["ngDirectiveDef"]);
|
|
1015
1635
|
}
|
|
1636
|
+
isCandidateAllowed(candidate) {
|
|
1637
|
+
if (candidate == null) return false;
|
|
1638
|
+
if (this.typePolicy()?.allowFunctionTypes === true) return true;
|
|
1639
|
+
return typeof candidate === "function" && this.isAngularComponentType(candidate);
|
|
1640
|
+
}
|
|
1641
|
+
isUsingGlobalRegistry() {
|
|
1642
|
+
const registry = this.registry();
|
|
1643
|
+
return registry == null || registry === FGDynamicService.registry;
|
|
1644
|
+
}
|
|
1016
1645
|
getRegistry() {
|
|
1017
1646
|
return this.registry() ?? FGDynamicService.registry;
|
|
1018
1647
|
}
|
|
@@ -1020,20 +1649,17 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1020
1649
|
if (this._componentRef && this._component !== this._componentRef.componentType) this.cleanup();
|
|
1021
1650
|
if (this._component && !this._componentRef && this._viewContainerRef()) {
|
|
1022
1651
|
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.");
|
|
1652
|
+
const formGroup = this.formGroup();
|
|
1653
|
+
const controlName = this.resolveFormControlName();
|
|
1654
|
+
if (formGroup && controlName) {
|
|
1655
|
+
this._formControlDirective = new FormControlDirective(null, null, null, null);
|
|
1656
|
+
injector = Injector.create({
|
|
1657
|
+
providers: [{
|
|
1658
|
+
provide: NgControl,
|
|
1659
|
+
useValue: this._formControlDirective
|
|
1660
|
+
}],
|
|
1661
|
+
parent: this._injector
|
|
1662
|
+
});
|
|
1037
1663
|
}
|
|
1038
1664
|
const dynamicItems = this._dynamicItems();
|
|
1039
1665
|
this._componentRef = this._viewContainerRef().createComponent(this._component, {
|
|
@@ -1042,7 +1668,7 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1042
1668
|
});
|
|
1043
1669
|
if (this._componentRef?.changeDetectorRef) this._componentRef.changeDetectorRef.markForCheck();
|
|
1044
1670
|
this.handleOutputs();
|
|
1045
|
-
this.
|
|
1671
|
+
this.wireFormControl();
|
|
1046
1672
|
}
|
|
1047
1673
|
}
|
|
1048
1674
|
handleOutputs() {
|
|
@@ -1060,21 +1686,26 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1060
1686
|
const instance = this._componentRef.instance;
|
|
1061
1687
|
for (const outputName of Object.keys(outputs)) {
|
|
1062
1688
|
const emitter = instance[outputName];
|
|
1063
|
-
if (!(emitter
|
|
1064
|
-
|
|
1689
|
+
if (!this.isOutputEmitter(emitter)) continue;
|
|
1690
|
+
const subscription = emitter.subscribe(($event) => {
|
|
1065
1691
|
try {
|
|
1066
1692
|
const expr = outputs[outputName];
|
|
1067
1693
|
const viewModelValue = this.getViewModelValue();
|
|
1068
|
-
const result = typeof expr === "string" ? this.evaluateExpression(expr,
|
|
1694
|
+
const result = typeof expr === "string" ? this.evaluateExpression(expr, viewModelValue, $event, true) : expr;
|
|
1069
1695
|
if (typeof result === "function") result.call(viewModelValue, $event);
|
|
1070
|
-
else if (typeof expr === "function") expr.call(viewModelValue, $event);
|
|
1071
1696
|
} catch (error) {
|
|
1072
1697
|
this.logError("Error handling output.", error);
|
|
1073
1698
|
}
|
|
1074
|
-
})
|
|
1699
|
+
});
|
|
1700
|
+
if (subscription && typeof subscription.unsubscribe === "function") this._outputsSubscriptions.push(subscription);
|
|
1075
1701
|
}
|
|
1076
1702
|
}
|
|
1077
1703
|
}
|
|
1704
|
+
isOutputEmitter(value) {
|
|
1705
|
+
if (value == null) return false;
|
|
1706
|
+
const emitter = value;
|
|
1707
|
+
return typeof emitter["subscribe"] === "function" && typeof emitter["emit"] === "function";
|
|
1708
|
+
}
|
|
1078
1709
|
handleOutputsIfChanged() {
|
|
1079
1710
|
const outputs = this.configuration()?.outputs;
|
|
1080
1711
|
const current = this._currentOutputsConfig;
|
|
@@ -1094,158 +1725,316 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1094
1725
|
return;
|
|
1095
1726
|
}
|
|
1096
1727
|
}
|
|
1097
|
-
|
|
1728
|
+
resolveFormControlName() {
|
|
1098
1729
|
const attributes = this.configuration()?.attributes;
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1730
|
+
if (!attributes || !Object.hasOwn(attributes, "name")) return;
|
|
1731
|
+
const nameAttr = attributes["name"];
|
|
1732
|
+
if (nameAttr == null) return;
|
|
1733
|
+
const viewModelValue = this.getViewModelValue();
|
|
1734
|
+
if (viewModelValue == null) return;
|
|
1735
|
+
const name = this.evaluateExpression(nameAttr, viewModelValue);
|
|
1736
|
+
if (typeof name !== "string" || name.length === 0) return;
|
|
1737
|
+
if (!this.isSafePath(name)) {
|
|
1738
|
+
this.logWarning("Unsafe form control name was ignored.");
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
const allowedNames = this.formControlPolicy()?.allowedControlNames;
|
|
1742
|
+
if (allowedNames !== void 0 && (!Array.isArray(allowedNames) || !allowedNames.includes(name))) {
|
|
1743
|
+
this.logWarning("Form control name was rejected by formControlPolicy.");
|
|
1744
|
+
return;
|
|
1745
|
+
}
|
|
1746
|
+
return name;
|
|
1747
|
+
}
|
|
1748
|
+
rewireFormIfNeeded() {
|
|
1749
|
+
if (!this._componentRef) return;
|
|
1750
|
+
const formGroup = this.formGroup();
|
|
1751
|
+
const controlName = this.resolveFormControlName();
|
|
1752
|
+
const desiredGroup = formGroup && controlName ? formGroup : void 0;
|
|
1753
|
+
const allowExistingControls = this.formControlPolicy()?.allowExistingControls === true;
|
|
1754
|
+
const policyChanged = desiredGroup !== void 0 && this._wiredAllowExistingControls !== allowExistingControls;
|
|
1755
|
+
if (this._wiredFormGroup !== desiredGroup || this._wiredControlName !== controlName || policyChanged) this.cleanup();
|
|
1756
|
+
}
|
|
1757
|
+
wireFormControl() {
|
|
1758
|
+
const formGroup = this.formGroup();
|
|
1759
|
+
const name = this.resolveFormControlName();
|
|
1760
|
+
if (!formGroup || !name) {
|
|
1761
|
+
this._wiredFormGroup = void 0;
|
|
1762
|
+
this._wiredControlName = void 0;
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
const path = this.parsePath(name);
|
|
1766
|
+
if (!path) {
|
|
1767
|
+
this._wiredFormGroup = void 0;
|
|
1768
|
+
this._wiredControlName = void 0;
|
|
1769
|
+
return;
|
|
1770
|
+
}
|
|
1771
|
+
const parent = this.ensureFormGroupPath(formGroup, path.slice(0, -1));
|
|
1772
|
+
if (!parent) {
|
|
1773
|
+
this.pruneCreatedFormGroups();
|
|
1774
|
+
this._wiredFormGroup = void 0;
|
|
1775
|
+
this._wiredControlName = void 0;
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
const key = path[path.length - 1];
|
|
1779
|
+
const existing = parent.get(key);
|
|
1780
|
+
if (existing) {
|
|
1781
|
+
if (this.formControlPolicy()?.allowExistingControls !== true) {
|
|
1782
|
+
this.logWarning("A form control with the requested name already exists; reuse is disabled by formControlPolicy.");
|
|
1783
|
+
this.pruneCreatedFormGroups();
|
|
1784
|
+
this._wiredFormGroup = void 0;
|
|
1785
|
+
this._wiredControlName = void 0;
|
|
1786
|
+
return;
|
|
1787
|
+
}
|
|
1788
|
+
if (!(existing instanceof FormControl)) {
|
|
1789
|
+
this.logWarning("A form control with the requested name already exists and is not a FormControl.");
|
|
1790
|
+
this.pruneCreatedFormGroups();
|
|
1791
|
+
this._wiredFormGroup = void 0;
|
|
1792
|
+
this._wiredControlName = void 0;
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
this.logWarning("A form control with the requested name already exists; reusing it.");
|
|
1796
|
+
this._formControl = existing;
|
|
1797
|
+
this._ownsFormControl = false;
|
|
1798
|
+
} else {
|
|
1799
|
+
const control = new FormControl(this.getModelPropertyValue(this.getViewModelValue(), name, null));
|
|
1800
|
+
try {
|
|
1801
|
+
parent.addControl(key, control);
|
|
1802
|
+
this._formControl = control;
|
|
1803
|
+
this._ownsFormControl = true;
|
|
1804
|
+
} catch (error) {
|
|
1805
|
+
this.logError("Error adding form control.", error);
|
|
1806
|
+
this.pruneCreatedFormGroups();
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
this._formControlContainer = parent;
|
|
1811
|
+
this._formControlKey = key;
|
|
1812
|
+
this._wiredFormGroup = formGroup;
|
|
1813
|
+
this._wiredControlName = name;
|
|
1814
|
+
this._wiredAllowExistingControls = this.formControlPolicy()?.allowExistingControls === true;
|
|
1815
|
+
this._disabledBeforeManagement = this._formControl.disabled;
|
|
1816
|
+
this._lastSyncedControlValue = this._formControl.value;
|
|
1817
|
+
this._hasSyncedControlValue = true;
|
|
1818
|
+
this.attachFormControlDirective();
|
|
1819
|
+
this.bindFormControlValueChanges(name);
|
|
1820
|
+
}
|
|
1821
|
+
ensureFormGroupPath(root, segments) {
|
|
1822
|
+
let current = root;
|
|
1823
|
+
for (const segment of segments) {
|
|
1824
|
+
const existing = current.get(segment);
|
|
1825
|
+
if (existing == null) {
|
|
1826
|
+
const group = new FormGroup({});
|
|
1112
1827
|
try {
|
|
1113
|
-
|
|
1114
|
-
else formGroup.addControl(name, this._formControl);
|
|
1828
|
+
current.addControl(segment, group);
|
|
1115
1829
|
} catch (error) {
|
|
1116
|
-
this.logError("Error
|
|
1830
|
+
this.logError("Error creating nested form group.", error);
|
|
1831
|
+
this.pruneCreatedFormGroups();
|
|
1832
|
+
return null;
|
|
1117
1833
|
}
|
|
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
|
-
}
|
|
1834
|
+
this._createdFormGroups.push({
|
|
1835
|
+
parent: current,
|
|
1836
|
+
key: segment,
|
|
1837
|
+
group
|
|
1136
1838
|
});
|
|
1137
|
-
|
|
1138
|
-
} else if (
|
|
1839
|
+
current = group;
|
|
1840
|
+
} else if (existing instanceof FormGroup) {
|
|
1841
|
+
if (this.formControlPolicy()?.allowExistingControls !== true) {
|
|
1842
|
+
this.logWarning(`Cannot reuse existing nested form group "${segment}" because formControlPolicy disables it.`);
|
|
1843
|
+
this.pruneCreatedFormGroups();
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
current = existing;
|
|
1847
|
+
} else {
|
|
1848
|
+
this.logWarning(`Cannot create nested form group "${segment}" because a different control already exists.`);
|
|
1849
|
+
this.pruneCreatedFormGroups();
|
|
1850
|
+
return null;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
return current;
|
|
1854
|
+
}
|
|
1855
|
+
bindFormControlValueChanges(name) {
|
|
1856
|
+
if (this._formControlSubscription) try {
|
|
1857
|
+
this._formControlSubscription.unsubscribe();
|
|
1858
|
+
} catch (e) {}
|
|
1859
|
+
this._formControlSubscription = this._formControl.valueChanges.subscribe((value) => {
|
|
1860
|
+
const currentModel = this.getViewModelValue();
|
|
1861
|
+
if (currentModel == null) return;
|
|
1862
|
+
const path = this.parsePath(name);
|
|
1863
|
+
if (!path) return;
|
|
1864
|
+
const viewModel = this.cloneAlongPathForMutation(currentModel, path);
|
|
1865
|
+
this.setModelPropertyValue(viewModel, path, value);
|
|
1866
|
+
this._lastSyncedControlValue = value;
|
|
1867
|
+
this._hasSyncedControlValue = true;
|
|
1868
|
+
try {
|
|
1869
|
+
this.viewModel.set(viewModel);
|
|
1870
|
+
if (this._componentRef?.changeDetectorRef) this._componentRef.changeDetectorRef.markForCheck();
|
|
1871
|
+
} catch (error) {
|
|
1872
|
+
this.logError("Error updating view model.", error);
|
|
1873
|
+
}
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
cloneAlongPathForMutation(value, path) {
|
|
1877
|
+
if (path.length === 0 || !this.isMutableContainer(value)) return value;
|
|
1878
|
+
const copy = this.cloneContainerShallow(value);
|
|
1879
|
+
if (path.length === 1) return copy;
|
|
1880
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, path[0]);
|
|
1881
|
+
if (!descriptor || !("value" in descriptor)) return copy;
|
|
1882
|
+
const child = descriptor.value;
|
|
1883
|
+
if (child == null || !this.isMutableContainer(child)) return copy;
|
|
1884
|
+
this.defineOwn(copy, path[0], this.cloneAlongPathForMutation(child, path.slice(1)));
|
|
1885
|
+
return copy;
|
|
1886
|
+
}
|
|
1887
|
+
cloneContainerShallow(value) {
|
|
1888
|
+
const copy = Array.isArray(value) ? [] : {};
|
|
1889
|
+
for (const key of Object.keys(value)) {
|
|
1890
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1891
|
+
if (!descriptor) continue;
|
|
1892
|
+
if ("value" in descriptor) this.defineOwn(copy, key, descriptor.value);
|
|
1893
|
+
else Object.defineProperty(copy, key, descriptor);
|
|
1894
|
+
}
|
|
1895
|
+
if (Array.isArray(value)) copy.length = value.length;
|
|
1896
|
+
return copy;
|
|
1897
|
+
}
|
|
1898
|
+
syncFormControlFromViewModel() {
|
|
1899
|
+
if (!this._formControl || !this._hasSyncedControlValue) return;
|
|
1900
|
+
const name = this._wiredControlName;
|
|
1901
|
+
const model = this.getViewModelValue();
|
|
1902
|
+
if (!name || model == null) return;
|
|
1903
|
+
const path = this.parsePath(name);
|
|
1904
|
+
if (!path) return;
|
|
1905
|
+
const nextValue = this.getModelPropertyValue(model, path, MISSING_FORM_VALUE);
|
|
1906
|
+
if (nextValue === MISSING_FORM_VALUE || this.valuesEqual(nextValue, this._lastSyncedControlValue)) return;
|
|
1907
|
+
try {
|
|
1908
|
+
this._formControl.setValue(nextValue, { emitEvent: false });
|
|
1909
|
+
this._lastSyncedControlValue = nextValue;
|
|
1910
|
+
} catch (error) {
|
|
1911
|
+
this.logError("Error synchronizing the form control with the view model.", error);
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
valuesEqual(left, right, depth = 0) {
|
|
1915
|
+
if (Object.is(left, right)) return true;
|
|
1916
|
+
if (depth >= 8 || left == null || right == null || typeof left !== "object" || typeof right !== "object") return false;
|
|
1917
|
+
if (Array.isArray(left) !== Array.isArray(right)) return false;
|
|
1918
|
+
if (Object.getPrototypeOf(left) !== Object.getPrototypeOf(right)) return false;
|
|
1919
|
+
const leftKeys = Object.keys(left);
|
|
1920
|
+
const rightKeys = Object.keys(right);
|
|
1921
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
1922
|
+
for (const key of leftKeys) {
|
|
1923
|
+
if (!Object.hasOwn(right, key)) return false;
|
|
1924
|
+
const leftDescriptor = Object.getOwnPropertyDescriptor(left, key);
|
|
1925
|
+
const rightDescriptor = Object.getOwnPropertyDescriptor(right, key);
|
|
1926
|
+
if (!leftDescriptor || !rightDescriptor || !("value" in leftDescriptor) || !("value" in rightDescriptor)) return false;
|
|
1927
|
+
if (!this.valuesEqual(leftDescriptor.value, rightDescriptor.value, depth + 1)) return false;
|
|
1928
|
+
}
|
|
1929
|
+
return true;
|
|
1930
|
+
}
|
|
1931
|
+
pruneCreatedFormGroups() {
|
|
1932
|
+
const kept = [];
|
|
1933
|
+
for (let index = this._createdFormGroups.length - 1; index >= 0; index--) {
|
|
1934
|
+
const entry = this._createdFormGroups[index];
|
|
1935
|
+
let remove = false;
|
|
1936
|
+
try {
|
|
1937
|
+
remove = entry.parent.get(entry.key) === entry.group && Object.keys(entry.group.controls).length === 0;
|
|
1938
|
+
if (remove) entry.parent.removeControl(entry.key);
|
|
1939
|
+
} catch {
|
|
1940
|
+
remove = false;
|
|
1941
|
+
}
|
|
1942
|
+
if (!remove) kept.unshift(entry);
|
|
1943
|
+
}
|
|
1944
|
+
this._createdFormGroups = kept;
|
|
1945
|
+
}
|
|
1946
|
+
setControlDisabled(disabled) {
|
|
1947
|
+
if (!this._formControl) return;
|
|
1948
|
+
try {
|
|
1949
|
+
if (disabled && this._formControl.enabled) this._formControl.disable({ emitEvent: false });
|
|
1950
|
+
else if (!disabled && this._formControl.disabled) this._formControl.enable({ emitEvent: false });
|
|
1951
|
+
} catch (error) {
|
|
1952
|
+
this.logError("Error updating form control status.", error);
|
|
1139
1953
|
}
|
|
1140
1954
|
}
|
|
1955
|
+
restoreManagedDisabledState() {
|
|
1956
|
+
if (!this._formControl || !this._disabledManaged) return;
|
|
1957
|
+
this.setControlDisabled(this._disabledBeforeManagement === true);
|
|
1958
|
+
this._disabledManaged = false;
|
|
1959
|
+
this._disabledBeforeManagement = void 0;
|
|
1960
|
+
}
|
|
1141
1961
|
setFormControlStatus() {
|
|
1142
1962
|
if (!this._formControl) return;
|
|
1143
1963
|
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
|
-
}
|
|
1964
|
+
if (!attributes || !Object.hasOwn(attributes, "disabled")) {
|
|
1965
|
+
this.restoreManagedDisabledState();
|
|
1966
|
+
return;
|
|
1191
1967
|
}
|
|
1968
|
+
const disabledAttr = attributes["disabled"];
|
|
1969
|
+
const evaluated = this.evaluateExpression(disabledAttr, this.getViewModelValue());
|
|
1970
|
+
if (this.isUnresolvedExpression(disabledAttr, evaluated)) return;
|
|
1971
|
+
const shouldDisable = this.toBoolean(evaluated);
|
|
1972
|
+
if (!this._disabledManaged) {
|
|
1973
|
+
this._disabledBeforeManagement = this._formControl.disabled;
|
|
1974
|
+
this._disabledManaged = true;
|
|
1975
|
+
}
|
|
1976
|
+
this.setControlDisabled(shouldDisable);
|
|
1192
1977
|
}
|
|
1193
1978
|
setFormControlValidators() {
|
|
1194
1979
|
if (!this._formControl) return;
|
|
1195
1980
|
if (this._managedValidatorFns.length > 0) {
|
|
1196
1981
|
try {
|
|
1197
1982
|
this._formControl.removeValidators(this._managedValidatorFns);
|
|
1198
|
-
} catch (
|
|
1983
|
+
} catch (error) {
|
|
1984
|
+
this.logError("Error removing managed validators.", error);
|
|
1985
|
+
}
|
|
1199
1986
|
this._managedValidatorFns = [];
|
|
1200
1987
|
try {
|
|
1201
|
-
this._formControl.updateValueAndValidity({
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
} catch (e) {}
|
|
1988
|
+
this._formControl.updateValueAndValidity({ emitEvent: false });
|
|
1989
|
+
} catch (error) {
|
|
1990
|
+
this.logError("Error updating form control validity.", error);
|
|
1991
|
+
}
|
|
1206
1992
|
}
|
|
1207
1993
|
const attributes = this.configuration()?.attributes;
|
|
1208
1994
|
if (attributes && Object.keys(attributes).length > 0 && this._componentRef?.location?.nativeElement) {
|
|
1209
1995
|
const validators = [];
|
|
1210
1996
|
if (Object.hasOwn(attributes, "min")) {
|
|
1211
|
-
const min = this.
|
|
1212
|
-
if (typeof min === "number" && !isNaN(min)) validators.push(Validators.min(min));
|
|
1997
|
+
const { value: min, unresolved } = this.evaluateAttribute(attributes, "min");
|
|
1998
|
+
if (!unresolved && typeof min === "number" && !isNaN(min)) validators.push(Validators.min(min));
|
|
1213
1999
|
}
|
|
1214
2000
|
if (Object.hasOwn(attributes, "max")) {
|
|
1215
|
-
const max = this.
|
|
1216
|
-
if (typeof max === "number" && !isNaN(max)) validators.push(Validators.max(max));
|
|
2001
|
+
const { value: max, unresolved } = this.evaluateAttribute(attributes, "max");
|
|
2002
|
+
if (!unresolved && typeof max === "number" && !isNaN(max)) validators.push(Validators.max(max));
|
|
1217
2003
|
}
|
|
1218
2004
|
if (Object.hasOwn(attributes, "required")) {
|
|
1219
|
-
|
|
2005
|
+
const { value: required, unresolved } = this.evaluateAttribute(attributes, "required");
|
|
2006
|
+
if (!unresolved && required === true) validators.push(Validators.required);
|
|
1220
2007
|
}
|
|
1221
2008
|
if (Object.hasOwn(attributes, "email")) {
|
|
1222
|
-
|
|
2009
|
+
const { value: email, unresolved } = this.evaluateAttribute(attributes, "email");
|
|
2010
|
+
if (!unresolved && email === true) validators.push(Validators.email);
|
|
1223
2011
|
}
|
|
1224
2012
|
if (Object.hasOwn(attributes, "maxlength")) {
|
|
1225
|
-
const maxLength = this.
|
|
1226
|
-
if (typeof maxLength === "number" && !isNaN(maxLength) && maxLength >= 0) validators.push(Validators.maxLength(maxLength));
|
|
2013
|
+
const { value: maxLength, unresolved } = this.evaluateAttribute(attributes, "maxlength");
|
|
2014
|
+
if (!unresolved && typeof maxLength === "number" && !isNaN(maxLength) && maxLength >= 0) validators.push(Validators.maxLength(maxLength));
|
|
1227
2015
|
}
|
|
1228
2016
|
if (Object.hasOwn(attributes, "minlength")) {
|
|
1229
|
-
const minLength = this.
|
|
1230
|
-
if (typeof minLength === "number" && !isNaN(minLength) && minLength >= 0) validators.push(Validators.minLength(minLength));
|
|
2017
|
+
const { value: minLength, unresolved } = this.evaluateAttribute(attributes, "minlength");
|
|
2018
|
+
if (!unresolved && typeof minLength === "number" && !isNaN(minLength) && minLength >= 0) validators.push(Validators.minLength(minLength));
|
|
1231
2019
|
}
|
|
1232
2020
|
if (Object.hasOwn(attributes, "pattern")) {
|
|
1233
|
-
const pattern = this.
|
|
1234
|
-
const patternValidator = this.createPatternValidator(pattern);
|
|
2021
|
+
const { value: pattern, unresolved } = this.evaluateAttribute(attributes, "pattern");
|
|
2022
|
+
const patternValidator = unresolved ? null : this.createPatternValidator(pattern);
|
|
1235
2023
|
if (patternValidator) validators.push(patternValidator);
|
|
1236
2024
|
}
|
|
1237
2025
|
if (validators.length > 0) {
|
|
1238
2026
|
this._managedValidatorFns = validators;
|
|
1239
2027
|
try {
|
|
1240
2028
|
this._formControl.addValidators(this._managedValidatorFns);
|
|
1241
|
-
} catch (
|
|
2029
|
+
} catch (error) {
|
|
2030
|
+
this.logError("Error adding managed validators.", error);
|
|
2031
|
+
}
|
|
1242
2032
|
} else this._managedValidatorFns = [];
|
|
1243
2033
|
try {
|
|
1244
|
-
this._formControl.updateValueAndValidity({
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
} catch (e) {}
|
|
2034
|
+
this._formControl.updateValueAndValidity({ emitEvent: false });
|
|
2035
|
+
} catch (error) {
|
|
2036
|
+
this.logError("Error updating form control validity.", error);
|
|
2037
|
+
}
|
|
1249
2038
|
} else this._managedValidatorFns = [];
|
|
1250
2039
|
}
|
|
1251
2040
|
createPatternValidator(pattern) {
|
|
@@ -1271,7 +2060,12 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1271
2060
|
this.logWarning("Pattern validator was ignored because the expression is potentially unsafe.");
|
|
1272
2061
|
return null;
|
|
1273
2062
|
}
|
|
1274
|
-
|
|
2063
|
+
try {
|
|
2064
|
+
regex = new RegExp(pattern.source, pattern.flags.replace(/[gy]/g, ""));
|
|
2065
|
+
} catch (error) {
|
|
2066
|
+
this.logError("Pattern validator was ignored because the expression is invalid.", error);
|
|
2067
|
+
return null;
|
|
2068
|
+
}
|
|
1275
2069
|
} else return null;
|
|
1276
2070
|
const baseValidator = Validators.pattern(regex);
|
|
1277
2071
|
return (control) => {
|
|
@@ -1284,15 +2078,88 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1284
2078
|
}
|
|
1285
2079
|
isUnsafeRegex(source) {
|
|
1286
2080
|
if (source.length > MAX_PATTERN_LENGTH) return true;
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
2081
|
+
const stack = [{
|
|
2082
|
+
hasQuantifier: false,
|
|
2083
|
+
hasAlternation: false
|
|
2084
|
+
}];
|
|
2085
|
+
let inCharacterClass = false;
|
|
2086
|
+
const isQuantifierAt = (index) => {
|
|
2087
|
+
const character = source[index];
|
|
2088
|
+
if (character === "+" || character === "*") return true;
|
|
2089
|
+
if (character !== "{") return false;
|
|
2090
|
+
const match = /^\{\d+(?:,\d*)?\}/.exec(source.slice(index));
|
|
2091
|
+
if (!match) return false;
|
|
2092
|
+
const bounds = /^\{(\d+)(?:,(\d*))?\}/.exec(match[0]);
|
|
2093
|
+
if (bounds) {
|
|
2094
|
+
const upper = bounds[2] === void 0 || bounds[2] === "" ? Infinity : Number(bounds[2]);
|
|
2095
|
+
if (Number.isFinite(upper) && upper > 1e4) return true;
|
|
2096
|
+
}
|
|
2097
|
+
return true;
|
|
2098
|
+
};
|
|
2099
|
+
for (let index = 0; index < source.length; index++) {
|
|
2100
|
+
const character = source[index];
|
|
2101
|
+
if (character === "\\") {
|
|
2102
|
+
const next = source[index + 1];
|
|
2103
|
+
if (next && /[1-9]/.test(next)) {
|
|
2104
|
+
let cursor = index + 2;
|
|
2105
|
+
while (cursor < source.length && /\d/.test(source[cursor])) cursor++;
|
|
2106
|
+
if (isQuantifierAt(cursor)) return true;
|
|
2107
|
+
}
|
|
2108
|
+
index++;
|
|
2109
|
+
continue;
|
|
2110
|
+
}
|
|
2111
|
+
if (inCharacterClass) {
|
|
2112
|
+
if (character === "]") inCharacterClass = false;
|
|
2113
|
+
continue;
|
|
2114
|
+
}
|
|
2115
|
+
if (character === "[") {
|
|
2116
|
+
inCharacterClass = true;
|
|
2117
|
+
continue;
|
|
2118
|
+
}
|
|
2119
|
+
if (character === "(") {
|
|
2120
|
+
stack.push({
|
|
2121
|
+
hasQuantifier: false,
|
|
2122
|
+
hasAlternation: false
|
|
2123
|
+
});
|
|
2124
|
+
if (source[index + 1] === "?") index++;
|
|
2125
|
+
continue;
|
|
2126
|
+
}
|
|
2127
|
+
if (character === ")") {
|
|
2128
|
+
const group = stack.pop();
|
|
2129
|
+
if (group) {
|
|
2130
|
+
const quantified = isQuantifierAt(index + 1);
|
|
2131
|
+
if (quantified && (group.hasQuantifier || group.hasAlternation)) return true;
|
|
2132
|
+
const parent = stack[stack.length - 1];
|
|
2133
|
+
if (parent) {
|
|
2134
|
+
if (quantified || group.hasQuantifier) parent.hasQuantifier = true;
|
|
2135
|
+
if (group.hasAlternation) parent.hasAlternation = true;
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
continue;
|
|
2139
|
+
}
|
|
2140
|
+
if (character === "|") {
|
|
2141
|
+
stack[stack.length - 1].hasAlternation = true;
|
|
2142
|
+
continue;
|
|
2143
|
+
}
|
|
2144
|
+
if (character === "+" || character === "*" || character === "{" || character === "?") {
|
|
2145
|
+
if (character === "?" && source[index - 1] === "(") continue;
|
|
2146
|
+
if (character === "{" && !/^\{\d+(?:,\d*)?\}/.test(source.slice(index))) continue;
|
|
2147
|
+
if (character === "{" && isQuantifierAt(index)) {
|
|
2148
|
+
const bounds = /^\{(\d+)(?:,(\d*))?\}/.exec(source.slice(index));
|
|
2149
|
+
const upper = bounds && bounds[2] !== void 0 && bounds[2] !== "" ? Number(bounds[2]) : Infinity;
|
|
2150
|
+
if (Number.isFinite(upper) && upper > 1e4) return true;
|
|
2151
|
+
}
|
|
2152
|
+
stack[stack.length - 1].hasQuantifier = true;
|
|
2153
|
+
}
|
|
2154
|
+
}
|
|
1290
2155
|
return false;
|
|
1291
2156
|
}
|
|
1292
2157
|
attachFormControlDirective() {
|
|
1293
2158
|
if (this._formControlDirective && this._componentRef?.injector && this._formControl) try {
|
|
1294
2159
|
const valueAccessors = this._componentRef.injector.get(NG_VALUE_ACCESSOR, null);
|
|
1295
|
-
|
|
2160
|
+
const valueAccessor = Array.isArray(valueAccessors) && valueAccessors.length > 0 ? valueAccessors[0] : null;
|
|
2161
|
+
if (!valueAccessor) this.logWarning("The dynamic component does not provide an NG_VALUE_ACCESSOR; the form control will not be bound to its view.");
|
|
2162
|
+
this._formControlDirective.valueAccessor = valueAccessor;
|
|
1296
2163
|
this._formControlDirective.form = this._formControl;
|
|
1297
2164
|
this._formControlDirective.ngOnChanges({ form: {
|
|
1298
2165
|
firstChange: true,
|
|
@@ -1308,14 +2175,81 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1308
2175
|
if (property == null) return null;
|
|
1309
2176
|
let pathArray = null;
|
|
1310
2177
|
if (Array.isArray(property)) pathArray = property.filter((segment) => segment != null && segment !== "").map((segment) => String(segment));
|
|
1311
|
-
else if (typeof property === "string") pathArray =
|
|
2178
|
+
else if (typeof property === "string") pathArray = this.parseStringPath(property);
|
|
1312
2179
|
if (!pathArray || pathArray.length === 0 || pathArray.length > MAX_PATH_DEPTH) return null;
|
|
1313
2180
|
for (const segment of pathArray) {
|
|
1314
|
-
if (segment.length > MAX_PATH_SEGMENT_LENGTH) return null;
|
|
2181
|
+
if (segment.length === 0 || segment.length > MAX_PATH_SEGMENT_LENGTH) return null;
|
|
1315
2182
|
if (FORBIDDEN_PATH_SEGMENTS.has(segment.toLowerCase())) return null;
|
|
1316
2183
|
}
|
|
1317
2184
|
return pathArray;
|
|
1318
2185
|
}
|
|
2186
|
+
parseStringPath(property) {
|
|
2187
|
+
const source = property.trim();
|
|
2188
|
+
if (source.length === 0) return null;
|
|
2189
|
+
const segments = [];
|
|
2190
|
+
let index = 0;
|
|
2191
|
+
let expectingSegment = true;
|
|
2192
|
+
while (index < source.length) {
|
|
2193
|
+
const character = source[index];
|
|
2194
|
+
if (character === ".") {
|
|
2195
|
+
if (expectingSegment) return null;
|
|
2196
|
+
expectingSegment = true;
|
|
2197
|
+
index++;
|
|
2198
|
+
continue;
|
|
2199
|
+
}
|
|
2200
|
+
if (character === "[") {
|
|
2201
|
+
index++;
|
|
2202
|
+
let value = "";
|
|
2203
|
+
if (source[index] === "\"" || source[index] === "'") {
|
|
2204
|
+
const quote = source[index];
|
|
2205
|
+
index++;
|
|
2206
|
+
let closed = false;
|
|
2207
|
+
while (index < source.length) {
|
|
2208
|
+
const current = source[index];
|
|
2209
|
+
if (current === "\\") {
|
|
2210
|
+
if (index + 1 >= source.length) return null;
|
|
2211
|
+
value += source[index + 1];
|
|
2212
|
+
index += 2;
|
|
2213
|
+
continue;
|
|
2214
|
+
}
|
|
2215
|
+
if (current === quote) {
|
|
2216
|
+
index++;
|
|
2217
|
+
closed = true;
|
|
2218
|
+
break;
|
|
2219
|
+
}
|
|
2220
|
+
value += current;
|
|
2221
|
+
index++;
|
|
2222
|
+
}
|
|
2223
|
+
if (!closed) return null;
|
|
2224
|
+
} else {
|
|
2225
|
+
const start = index;
|
|
2226
|
+
while (index < source.length && source[index] !== "]") {
|
|
2227
|
+
if (source[index] === "[" || source[index] === ".") return null;
|
|
2228
|
+
value += source[index];
|
|
2229
|
+
index++;
|
|
2230
|
+
}
|
|
2231
|
+
if (index === start) return null;
|
|
2232
|
+
value = value.trim();
|
|
2233
|
+
}
|
|
2234
|
+
if (source[index] !== "]" || value.length === 0) return null;
|
|
2235
|
+
index++;
|
|
2236
|
+
segments.push(value);
|
|
2237
|
+
expectingSegment = false;
|
|
2238
|
+
continue;
|
|
2239
|
+
}
|
|
2240
|
+
if (!expectingSegment) return null;
|
|
2241
|
+
let value = "";
|
|
2242
|
+
while (index < source.length && source[index] !== "." && source[index] !== "[") {
|
|
2243
|
+
value += source[index];
|
|
2244
|
+
index++;
|
|
2245
|
+
}
|
|
2246
|
+
if (value.length === 0) return null;
|
|
2247
|
+
segments.push(value);
|
|
2248
|
+
expectingSegment = false;
|
|
2249
|
+
}
|
|
2250
|
+
if (expectingSegment) return null;
|
|
2251
|
+
return segments;
|
|
2252
|
+
}
|
|
1319
2253
|
isSafePath(property) {
|
|
1320
2254
|
return this.parsePath(property) !== null;
|
|
1321
2255
|
}
|
|
@@ -1327,6 +2261,12 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1327
2261
|
configurable: true
|
|
1328
2262
|
});
|
|
1329
2263
|
}
|
|
2264
|
+
isMutableContainer(value) {
|
|
2265
|
+
if (value == null || typeof value !== "object") return false;
|
|
2266
|
+
if (Array.isArray(value)) return true;
|
|
2267
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2268
|
+
return prototype === Object.prototype || prototype === null;
|
|
2269
|
+
}
|
|
1330
2270
|
getModelPropertyValue(model, property, defaultValue) {
|
|
1331
2271
|
if (model == null) return defaultValue;
|
|
1332
2272
|
const pathArray = this.parsePath(property);
|
|
@@ -1337,7 +2277,9 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1337
2277
|
if (current == null) return defaultValue;
|
|
1338
2278
|
const container = Object(current);
|
|
1339
2279
|
if (!Object.hasOwn(container, key)) return defaultValue;
|
|
1340
|
-
|
|
2280
|
+
const descriptor = Object.getOwnPropertyDescriptor(container, key);
|
|
2281
|
+
if (!descriptor || !("value" in descriptor)) return defaultValue;
|
|
2282
|
+
current = descriptor.value;
|
|
1341
2283
|
}
|
|
1342
2284
|
return current != null ? current : defaultValue;
|
|
1343
2285
|
} catch {
|
|
@@ -1353,22 +2295,27 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1353
2295
|
for (let index = 0; index < pathArray.length; index++) {
|
|
1354
2296
|
const key = pathArray[index];
|
|
1355
2297
|
const isLast = index === pathArray.length - 1;
|
|
1356
|
-
if (current
|
|
2298
|
+
if (!this.isMutableContainer(current)) return;
|
|
1357
2299
|
if (isLast) {
|
|
2300
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
2301
|
+
if (descriptor && !("value" in descriptor)) return;
|
|
1358
2302
|
this.defineOwn(current, key, value);
|
|
1359
2303
|
return;
|
|
1360
2304
|
}
|
|
1361
2305
|
const isNumericKey = /^\d+$/.test(key);
|
|
1362
|
-
|
|
2306
|
+
let existing;
|
|
2307
|
+
if (Object.hasOwn(current, key)) {
|
|
2308
|
+
const descriptor = Object.getOwnPropertyDescriptor(current, key);
|
|
2309
|
+
if (!descriptor || !("value" in descriptor)) return;
|
|
2310
|
+
existing = descriptor.value;
|
|
2311
|
+
}
|
|
1363
2312
|
if (existing == null) {
|
|
1364
2313
|
const next = isNumericKey ? [] : {};
|
|
1365
2314
|
this.defineOwn(current, key, next);
|
|
1366
2315
|
current = next;
|
|
1367
2316
|
} else if (isNumericKey && !Array.isArray(existing)) {
|
|
1368
|
-
if (typeof existing
|
|
1369
|
-
|
|
1370
|
-
this.defineOwn(current, key, next);
|
|
1371
|
-
current = next;
|
|
2317
|
+
if (existing !== null && typeof existing === "object") current = existing;
|
|
2318
|
+
else return;
|
|
1372
2319
|
} else if (!isNumericKey && typeof existing !== "object") {
|
|
1373
2320
|
const next = {};
|
|
1374
2321
|
this.defineOwn(current, key, next);
|
|
@@ -1380,10 +2327,21 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1380
2327
|
}
|
|
1381
2328
|
}
|
|
1382
2329
|
setInputs() {
|
|
2330
|
+
if (!this._componentRef) return;
|
|
1383
2331
|
const inputs = this.configuration()?.inputs;
|
|
1384
|
-
|
|
1385
|
-
for (const inputName of
|
|
1386
|
-
|
|
2332
|
+
const currentNames = inputs && typeof inputs === "object" ? Object.keys(inputs) : [];
|
|
2333
|
+
for (const inputName of Array.from(this._appliedInputs)) if (!currentNames.includes(inputName)) {
|
|
2334
|
+
try {
|
|
2335
|
+
this._componentRef.setInput(inputName, void 0);
|
|
2336
|
+
} catch (error) {
|
|
2337
|
+
this.logError(`Error resetting dynamic input "${inputName}".`, error);
|
|
2338
|
+
}
|
|
2339
|
+
this._appliedInputs.delete(inputName);
|
|
2340
|
+
}
|
|
2341
|
+
if (!inputs || typeof inputs !== "object") return;
|
|
2342
|
+
for (const inputName of currentNames) try {
|
|
2343
|
+
this._componentRef.setInput(inputName, this.evaluateExpression(inputs[inputName], this.getViewModelValue()));
|
|
2344
|
+
this._appliedInputs.add(inputName);
|
|
1387
2345
|
} catch (error) {
|
|
1388
2346
|
this.logError(`Error setting dynamic input "${inputName}".`, error);
|
|
1389
2347
|
}
|
|
@@ -1391,26 +2349,46 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1391
2349
|
setAttributes() {
|
|
1392
2350
|
const attributes = this.configuration()?.attributes;
|
|
1393
2351
|
const element = this._componentRef?.location?.nativeElement;
|
|
1394
|
-
if (!
|
|
1395
|
-
|
|
2352
|
+
if (!element) return;
|
|
2353
|
+
const currentNames = attributes && typeof attributes === "object" ? Object.keys(attributes) : [];
|
|
2354
|
+
for (const attributeName of Array.from(this._appliedAttributes)) if (!currentNames.includes(attributeName) || !this.isAllowedAttribute(attributeName)) {
|
|
2355
|
+
this._renderer.removeAttribute(element, attributeName);
|
|
2356
|
+
this._appliedAttributes.delete(attributeName);
|
|
2357
|
+
}
|
|
2358
|
+
if (!attributes || typeof attributes !== "object") return;
|
|
2359
|
+
for (const attributeName of currentNames) {
|
|
1396
2360
|
if (!this.isAllowedAttribute(attributeName)) {
|
|
1397
2361
|
this.logWarning(`Attribute "${attributeName}" is not allowed and was skipped.`);
|
|
1398
2362
|
continue;
|
|
1399
2363
|
}
|
|
1400
2364
|
try {
|
|
1401
|
-
const
|
|
2365
|
+
const rawValue = attributes[attributeName];
|
|
2366
|
+
const value = this.evaluateExpression(rawValue, this.getViewModelValue());
|
|
2367
|
+
if (this.isUnresolvedExpression(rawValue, value)) continue;
|
|
2368
|
+
const lower = attributeName.toLowerCase();
|
|
2369
|
+
if (BOOLEAN_ATTRIBUTES.has(lower)) {
|
|
2370
|
+
if (!this.toBoolean(value)) {
|
|
2371
|
+
this._renderer.removeAttribute(element, attributeName);
|
|
2372
|
+
this._appliedAttributes.delete(attributeName);
|
|
2373
|
+
} else if (element.getAttribute(attributeName) !== "") {
|
|
2374
|
+
this._renderer.setAttribute(element, attributeName, "");
|
|
2375
|
+
this._appliedAttributes.add(attributeName);
|
|
2376
|
+
} else this._appliedAttributes.add(attributeName);
|
|
2377
|
+
continue;
|
|
2378
|
+
}
|
|
1402
2379
|
const stringValue = this.attributeValueToString(value);
|
|
1403
2380
|
if (stringValue === void 0) continue;
|
|
1404
|
-
if (stringValue === element.getAttribute(attributeName)) continue;
|
|
1405
2381
|
if (stringValue === null) {
|
|
1406
2382
|
this._renderer.removeAttribute(element, attributeName);
|
|
2383
|
+
this._appliedAttributes.delete(attributeName);
|
|
1407
2384
|
continue;
|
|
1408
2385
|
}
|
|
1409
|
-
if (URL_ATTRIBUTES.has(
|
|
2386
|
+
if (URL_ATTRIBUTES.has(lower) && !this.isSafeUrl(stringValue)) {
|
|
1410
2387
|
this.logWarning(`Unsafe URL for attribute "${attributeName}" was ignored.`);
|
|
1411
2388
|
continue;
|
|
1412
2389
|
}
|
|
1413
|
-
this._renderer.setAttribute(element, attributeName, stringValue);
|
|
2390
|
+
if (element.getAttribute(attributeName) !== stringValue) this._renderer.setAttribute(element, attributeName, stringValue);
|
|
2391
|
+
this._appliedAttributes.add(attributeName);
|
|
1414
2392
|
} catch (error) {
|
|
1415
2393
|
this.logError(`Error setting dynamic attribute "${attributeName}".`, error);
|
|
1416
2394
|
}
|
|
@@ -1421,6 +2399,7 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1421
2399
|
const lower = name.toLowerCase();
|
|
1422
2400
|
if (lower.startsWith("on")) return false;
|
|
1423
2401
|
if (!/^[a-z][a-z0-9_.-]*$/i.test(name)) return false;
|
|
2402
|
+
if (this.attributePolicy()?.strict === true && STRICT_DISALLOWED_ATTRIBUTES.has(lower)) return false;
|
|
1424
2403
|
if (lower.startsWith("data-") || lower.startsWith("aria-")) return true;
|
|
1425
2404
|
return ALLOWED_ATTRIBUTES.has(lower);
|
|
1426
2405
|
}
|
|
@@ -1441,22 +2420,72 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1441
2420
|
isSafeUrl(value) {
|
|
1442
2421
|
const normalized = value.replace(/[\u0000-\u0020\u007f]/g, "").toLowerCase();
|
|
1443
2422
|
if (normalized.length === 0) return true;
|
|
2423
|
+
if (normalized.startsWith("//")) return this.allowsExternalUrls();
|
|
1444
2424
|
const scheme = /^([a-z][a-z0-9+.-]*):/.exec(normalized);
|
|
1445
2425
|
if (!scheme) return true;
|
|
1446
|
-
|
|
2426
|
+
if (scheme[1] === "mailto" || scheme[1] === "tel") return true;
|
|
2427
|
+
if (scheme[1] !== "http" && scheme[1] !== "https") return false;
|
|
2428
|
+
return this.allowsExternalUrls() || this.isSameOriginUrl(value);
|
|
2429
|
+
}
|
|
2430
|
+
allowsExternalUrls() {
|
|
2431
|
+
return this.attributePolicy()?.allowExternalUrls === true;
|
|
2432
|
+
}
|
|
2433
|
+
isSameOriginUrl(value) {
|
|
2434
|
+
if (typeof document === "undefined" || !document.baseURI) return false;
|
|
2435
|
+
try {
|
|
2436
|
+
return new URL(value, document.baseURI).origin === new URL(document.baseURI).origin;
|
|
2437
|
+
} catch {
|
|
2438
|
+
return false;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
evaluateAttribute(attributes, name) {
|
|
2442
|
+
const raw = attributes[name];
|
|
2443
|
+
const value = this.evaluateExpression(raw, this.getViewModelValue());
|
|
2444
|
+
return {
|
|
2445
|
+
value,
|
|
2446
|
+
unresolved: this.isUnresolvedExpression(raw, value)
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
isUnresolvedExpression(source, result) {
|
|
2450
|
+
return typeof source === "string" && result === source && EXPRESSION_CONTEXT_PATTERN.test(source);
|
|
1447
2451
|
}
|
|
1448
|
-
|
|
2452
|
+
toBoolean(value) {
|
|
2453
|
+
if (typeof value === "boolean") return value;
|
|
2454
|
+
if (typeof value === "number") return value !== 0 && !Number.isNaN(value);
|
|
2455
|
+
if (typeof value === "string") {
|
|
2456
|
+
const normalized = value.trim().toLowerCase();
|
|
2457
|
+
return normalized !== "" && normalized !== "false" && normalized !== "0" && normalized !== "null" && normalized !== "undefined";
|
|
2458
|
+
}
|
|
2459
|
+
return value != null;
|
|
2460
|
+
}
|
|
2461
|
+
evaluateExpression(value, viewModelValue, eventParam, hasEventContext = false) {
|
|
1449
2462
|
if (typeof value !== "string") return value;
|
|
1450
|
-
const hasVm =
|
|
1451
|
-
const hasEvent =
|
|
2463
|
+
const hasVm = VM_EXPRESSION_PATTERN.test(value);
|
|
2464
|
+
const hasEvent = EVENT_EXPRESSION_PATTERN.test(value);
|
|
1452
2465
|
if (!hasVm && !hasEvent) return value;
|
|
1453
|
-
if (hasVm &&
|
|
2466
|
+
if (hasVm && viewModelValue == null) return value;
|
|
2467
|
+
if (hasEvent && !hasEventContext) return value;
|
|
1454
2468
|
try {
|
|
1455
|
-
const
|
|
2469
|
+
const policy = this.expressionPolicy() ?? {};
|
|
2470
|
+
const allowedMethods = Array.isArray(policy.allowedMethods) ? [...policy.allowedMethods] : [];
|
|
2471
|
+
const $vm = () => this.getViewModelValue();
|
|
2472
|
+
if (policy.allowViewModelMutation === true) {
|
|
2473
|
+
$vm.set = (nextValue) => {
|
|
2474
|
+
this.viewModel.set(nextValue);
|
|
2475
|
+
};
|
|
2476
|
+
$vm.update = (updateFn) => {
|
|
2477
|
+
this.viewModel.update(updateFn);
|
|
2478
|
+
};
|
|
2479
|
+
allowedMethods.push("set");
|
|
2480
|
+
allowedMethods.push("update");
|
|
2481
|
+
}
|
|
1456
2482
|
return evaluateSafeExpression(value, {
|
|
1457
|
-
$vm
|
|
2483
|
+
$vm,
|
|
1458
2484
|
$event: eventParam,
|
|
1459
2485
|
$ev: eventParam
|
|
2486
|
+
}, {
|
|
2487
|
+
allowCustomMethods: policy.allowCustomMethods === true,
|
|
2488
|
+
allowedMethods
|
|
1460
2489
|
});
|
|
1461
2490
|
} catch {
|
|
1462
2491
|
this.logWarning("Expression could not be evaluated safely and was ignored.");
|
|
@@ -1487,30 +2516,44 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1487
2516
|
this._formControlSubscription.unsubscribe();
|
|
1488
2517
|
} catch (e) {}
|
|
1489
2518
|
this._formControlSubscription = void 0;
|
|
1490
|
-
if (this._formControl && this.
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
formGroup.removeControl(controlName);
|
|
1498
|
-
} catch (e) {}
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
} catch (e) {}
|
|
1502
|
-
this._formControl = void 0;
|
|
1503
|
-
this._managedValidatorFns = [];
|
|
2519
|
+
if (this._formControl && this._managedValidatorFns.length > 0) try {
|
|
2520
|
+
this._formControl.removeValidators(this._managedValidatorFns);
|
|
2521
|
+
this._formControl.updateValueAndValidity({ emitEvent: false });
|
|
2522
|
+
} catch (error) {
|
|
2523
|
+
this.logError("Error removing managed validators.", error);
|
|
2524
|
+
}
|
|
2525
|
+
this.restoreManagedDisabledState();
|
|
1504
2526
|
if (this._formControlDirective) try {
|
|
1505
2527
|
this._formControlDirective.ngOnDestroy();
|
|
1506
2528
|
} catch (e) {}
|
|
1507
2529
|
this._formControlDirective = void 0;
|
|
2530
|
+
if (this._ownsFormControl && this._formControl && this._formControlContainer && this._formControlKey) try {
|
|
2531
|
+
if (this._formControlContainer.get(this._formControlKey) === this._formControl) this._formControlContainer.removeControl(this._formControlKey);
|
|
2532
|
+
} catch (e) {}
|
|
2533
|
+
this.pruneCreatedFormGroups();
|
|
2534
|
+
this._createdFormGroups = [];
|
|
2535
|
+
this._formControl = void 0;
|
|
2536
|
+
this._formControlContainer = void 0;
|
|
2537
|
+
this._formControlKey = void 0;
|
|
2538
|
+
this._ownsFormControl = false;
|
|
2539
|
+
this._disabledManaged = false;
|
|
2540
|
+
this._disabledBeforeManagement = void 0;
|
|
2541
|
+
this._wiredFormGroup = void 0;
|
|
2542
|
+
this._wiredControlName = void 0;
|
|
2543
|
+
this._wiredAllowExistingControls = void 0;
|
|
2544
|
+
this._hasSyncedControlValue = false;
|
|
2545
|
+
this._lastSyncedControlValue = void 0;
|
|
2546
|
+
this._managedValidatorFns = [];
|
|
2547
|
+
this._appliedAttributes.clear();
|
|
2548
|
+
this._appliedInputs.clear();
|
|
1508
2549
|
if (this._componentRef) try {
|
|
1509
2550
|
this._componentRef.destroy();
|
|
1510
2551
|
} catch (e) {}
|
|
1511
2552
|
this._componentRef = void 0;
|
|
1512
2553
|
}
|
|
1513
2554
|
ngOnDestroy() {
|
|
2555
|
+
this._destroyed = true;
|
|
2556
|
+
this._ngOnChangesCounter++;
|
|
1514
2557
|
this.cleanup();
|
|
1515
2558
|
}
|
|
1516
2559
|
static {
|
|
@@ -1558,6 +2601,41 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1558
2601
|
isSignal: true,
|
|
1559
2602
|
isRequired: false,
|
|
1560
2603
|
transformFunction: null
|
|
2604
|
+
},
|
|
2605
|
+
expressionPolicy: {
|
|
2606
|
+
classPropertyName: "expressionPolicy",
|
|
2607
|
+
publicName: "expressionPolicy",
|
|
2608
|
+
isSignal: true,
|
|
2609
|
+
isRequired: false,
|
|
2610
|
+
transformFunction: null
|
|
2611
|
+
},
|
|
2612
|
+
formControlPolicy: {
|
|
2613
|
+
classPropertyName: "formControlPolicy",
|
|
2614
|
+
publicName: "formControlPolicy",
|
|
2615
|
+
isSignal: true,
|
|
2616
|
+
isRequired: false,
|
|
2617
|
+
transformFunction: null
|
|
2618
|
+
},
|
|
2619
|
+
typePolicy: {
|
|
2620
|
+
classPropertyName: "typePolicy",
|
|
2621
|
+
publicName: "typePolicy",
|
|
2622
|
+
isSignal: true,
|
|
2623
|
+
isRequired: false,
|
|
2624
|
+
transformFunction: null
|
|
2625
|
+
},
|
|
2626
|
+
attributePolicy: {
|
|
2627
|
+
classPropertyName: "attributePolicy",
|
|
2628
|
+
publicName: "attributePolicy",
|
|
2629
|
+
isSignal: true,
|
|
2630
|
+
isRequired: false,
|
|
2631
|
+
transformFunction: null
|
|
2632
|
+
},
|
|
2633
|
+
depth: {
|
|
2634
|
+
classPropertyName: "depth",
|
|
2635
|
+
publicName: "depth",
|
|
2636
|
+
isSignal: true,
|
|
2637
|
+
isRequired: false,
|
|
2638
|
+
transformFunction: null
|
|
1561
2639
|
}
|
|
1562
2640
|
},
|
|
1563
2641
|
outputs: { viewModel: "viewModelChange" },
|
|
@@ -1580,7 +2658,7 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1580
2658
|
template: `
|
|
1581
2659
|
<ng-container #viewContainer></ng-container>
|
|
1582
2660
|
@for (item of items(); track $index) {
|
|
1583
|
-
<fg-dynamic #dynamicItem [configuration]="item" [(viewModel)]="viewModel" [formGroup]="formGroup()" [registry]="registry()" />
|
|
2661
|
+
<fg-dynamic #dynamicItem [configuration]="item" [(viewModel)]="viewModel" [formGroup]="formGroup()" [registry]="registry()" [expressionPolicy]="expressionPolicy()" [formControlPolicy]="formControlPolicy()" [typePolicy]="typePolicy()" [attributePolicy]="attributePolicy()" [depth]="depth() + 1" />
|
|
1584
2662
|
}
|
|
1585
2663
|
`,
|
|
1586
2664
|
isInline: true,
|
|
@@ -1593,7 +2671,12 @@ var FGDynamicComponent = class FGDynamicComponent {
|
|
|
1593
2671
|
"configuration",
|
|
1594
2672
|
"viewModel",
|
|
1595
2673
|
"formGroup",
|
|
1596
|
-
"registry"
|
|
2674
|
+
"registry",
|
|
2675
|
+
"expressionPolicy",
|
|
2676
|
+
"formControlPolicy",
|
|
2677
|
+
"typePolicy",
|
|
2678
|
+
"attributePolicy",
|
|
2679
|
+
"depth"
|
|
1597
2680
|
],
|
|
1598
2681
|
outputs: ["viewModelChange"]
|
|
1599
2682
|
}],
|
|
@@ -1613,7 +2696,7 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1613
2696
|
template: `
|
|
1614
2697
|
<ng-container #viewContainer></ng-container>
|
|
1615
2698
|
@for (item of items(); track $index) {
|
|
1616
|
-
<fg-dynamic #dynamicItem [configuration]="item" [(viewModel)]="viewModel" [formGroup]="formGroup()" [registry]="registry()" />
|
|
2699
|
+
<fg-dynamic #dynamicItem [configuration]="item" [(viewModel)]="viewModel" [formGroup]="formGroup()" [registry]="registry()" [expressionPolicy]="expressionPolicy()" [formControlPolicy]="formControlPolicy()" [typePolicy]="typePolicy()" [attributePolicy]="attributePolicy()" [depth]="depth() + 1" />
|
|
1617
2700
|
}
|
|
1618
2701
|
`,
|
|
1619
2702
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
@@ -1657,6 +2740,46 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
1657
2740
|
required: false
|
|
1658
2741
|
}]
|
|
1659
2742
|
}],
|
|
2743
|
+
expressionPolicy: [{
|
|
2744
|
+
type: i0.Input,
|
|
2745
|
+
args: [{
|
|
2746
|
+
isSignal: true,
|
|
2747
|
+
alias: "expressionPolicy",
|
|
2748
|
+
required: false
|
|
2749
|
+
}]
|
|
2750
|
+
}],
|
|
2751
|
+
formControlPolicy: [{
|
|
2752
|
+
type: i0.Input,
|
|
2753
|
+
args: [{
|
|
2754
|
+
isSignal: true,
|
|
2755
|
+
alias: "formControlPolicy",
|
|
2756
|
+
required: false
|
|
2757
|
+
}]
|
|
2758
|
+
}],
|
|
2759
|
+
typePolicy: [{
|
|
2760
|
+
type: i0.Input,
|
|
2761
|
+
args: [{
|
|
2762
|
+
isSignal: true,
|
|
2763
|
+
alias: "typePolicy",
|
|
2764
|
+
required: false
|
|
2765
|
+
}]
|
|
2766
|
+
}],
|
|
2767
|
+
attributePolicy: [{
|
|
2768
|
+
type: i0.Input,
|
|
2769
|
+
args: [{
|
|
2770
|
+
isSignal: true,
|
|
2771
|
+
alias: "attributePolicy",
|
|
2772
|
+
required: false
|
|
2773
|
+
}]
|
|
2774
|
+
}],
|
|
2775
|
+
depth: [{
|
|
2776
|
+
type: i0.Input,
|
|
2777
|
+
args: [{
|
|
2778
|
+
isSignal: true,
|
|
2779
|
+
alias: "depth",
|
|
2780
|
+
required: false
|
|
2781
|
+
}]
|
|
2782
|
+
}],
|
|
1660
2783
|
_viewContainerRef: [{
|
|
1661
2784
|
type: i0.ViewChild,
|
|
1662
2785
|
args: ["viewContainer", {
|