fg-dynamic-component 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,11 @@ const MAX_EVALUATION_STEPS = 2e4;
8
8
  const MAX_EVALUATION_DEPTH = 80;
9
9
  const MAX_STRING_LENGTH = 1e5;
10
10
  const MAX_REPEAT_COUNT = 1e4;
11
+ const RESERVED_BINDING_NAMES = /* @__PURE__ */ new Set([
12
+ "$vm",
13
+ "$event",
14
+ "$ev"
15
+ ]);
11
16
  const FORBIDDEN_PROPERTIES = /* @__PURE__ */ new Set([
12
17
  "__proto__",
13
18
  "prototype",
@@ -153,7 +158,121 @@ const SAFE_NATIVE_METHODS = /* @__PURE__ */ new Set([
153
158
  Object.prototype.toString,
154
159
  Object.prototype.valueOf
155
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
+ ]);
156
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
+ }
157
276
  const HOST_OBJECT_TAGS = /* @__PURE__ */ new Set([
158
277
  "Window",
159
278
  "global",
@@ -202,7 +321,12 @@ function isHostObject(value) {
202
321
  if (value == null || typeof value !== "object" && typeof value !== "function") return false;
203
322
  if (value === globalThis) return true;
204
323
  try {
205
- const tag = Object.prototype.toString.call(value).slice(8, -1);
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);
206
330
  if (HOST_OBJECT_TAGS.has(tag)) return true;
207
331
  if (/(?:Element|Event|Document|Node|Observer|Collection|List|Map)$/.test(tag) && tag !== "Map" && tag !== "WeakMap" && tag !== "Set" && tag !== "WeakSet") return true;
208
332
  } catch {
@@ -450,14 +574,17 @@ var ExpressionParser = class {
450
574
  }
451
575
  parseArrow() {
452
576
  const params = [];
453
- if (this.current().type === "identifier") params.push(this.advance().value);
454
- else {
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 {
455
582
  this.expectPunctuator("(");
456
583
  if (!isPunctuator(this.current(), ")")) do {
457
584
  if (isPunctuator(this.current(), ")")) break;
458
585
  const parameter = this.advance();
459
586
  if (parameter.type !== "identifier") fail("Arrow function parameters must be identifiers.");
460
- 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.");
461
588
  params.push(parameter.value);
462
589
  } while (this.matchPunctuator(","));
463
590
  this.expectPunctuator(")");
@@ -865,9 +992,32 @@ var ExpressionParser = class {
865
992
  function assertSafeProperty(property) {
866
993
  if (FORBIDDEN_PROPERTIES.has(property)) fail("Access to a forbidden property was blocked.");
867
994
  }
868
- function isMethodAllowed(name, options) {
995
+ function isMethodNameAllowed(name, options) {
869
996
  if (options?.allowCustomMethods === true) return true;
870
- return Array.isArray(options?.allowedMethods) && options.allowedMethods.includes(name);
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;
871
1021
  }
872
1022
  function defineSafeProperty(target, key, value) {
873
1023
  assertSafeProperty(key);
@@ -878,12 +1028,13 @@ function defineSafeProperty(target, key, value) {
878
1028
  configurable: true
879
1029
  });
880
1030
  }
881
- function readMember(target, key, optional, options) {
1031
+ function readMember(target, key, optional, state, options) {
1032
+ if (target === OPTIONAL_SHORT_CIRCUIT) return target;
882
1033
  if (typeof key !== "string" && typeof key !== "number") fail("Property keys must be strings or numbers.");
883
1034
  const property = String(key);
884
1035
  assertSafeProperty(property);
885
1036
  if (target == null) {
886
- if (optional) return;
1037
+ if (optional) return OPTIONAL_SHORT_CIRCUIT;
887
1038
  fail("Cannot read properties of null or undefined.");
888
1039
  }
889
1040
  if (isHostObject(target)) fail("Access to host objects is not allowed.");
@@ -892,7 +1043,7 @@ function readMember(target, key, optional, options) {
892
1043
  if (descriptor) {
893
1044
  if (!("value" in descriptor)) fail("Access to accessor properties is not allowed.");
894
1045
  const value = descriptor.value;
895
- if (typeof value === "function" && !isNativeFunction(value) && !isInterpreterFunction(value) && !isMethodAllowed(property, options)) fail("Access to custom methods is not allowed.");
1046
+ if (typeof value === "function" && !isNativeFunction(value) && !isInterpreterFunction(value) && !isMethodAllowedForReceiver(property, target, state, options)) fail("Access to custom methods is not allowed.");
896
1047
  return assertSafeValue(value);
897
1048
  }
898
1049
  let prototype = Object.getPrototypeOf(object);
@@ -902,7 +1053,7 @@ function readMember(target, key, optional, options) {
902
1053
  if (!("value" in inheritedDescriptor)) fail("Access to inherited accessor properties is not allowed.");
903
1054
  const inherited = inheritedDescriptor.value;
904
1055
  if (typeof inherited === "function") {
905
- if (isNativeFunction(inherited) || isInterpreterFunction(inherited) || isMethodAllowed(property, options)) return inherited;
1056
+ if (isNativeFunction(inherited) || isInterpreterFunction(inherited) || isMethodAllowedForReceiver(property, target, state, options)) return inherited;
906
1057
  fail("Access to custom methods is not allowed.");
907
1058
  }
908
1059
  fail("Access to inherited properties is not allowed.");
@@ -911,7 +1062,13 @@ function readMember(target, key, optional, options) {
911
1062
  }
912
1063
  }
913
1064
  function spreadValues(value) {
914
- if (Array.isArray(value)) return value.slice();
1065
+ if (Array.isArray(value)) {
1066
+ const values = [];
1067
+ forEachArrayElement(value, (element) => {
1068
+ values.push(element);
1069
+ });
1070
+ return values;
1071
+ }
915
1072
  if (typeof value === "string") {
916
1073
  if (value.length > MAX_STRING_LENGTH) fail("Spread value is too large.");
917
1074
  return value.split("");
@@ -967,33 +1124,47 @@ function evaluateNode(node, environment, state, options) {
967
1124
  case "Identifier":
968
1125
  if (!environment.has(node.name)) return fail(`Unknown identifier "${node.name}".`);
969
1126
  return assertSafeValue(environment.get(node.name));
970
- case "Member": return readMember(evaluateNode(node.object, environment, state, options), evaluateNode(node.property, environment, state, options), node.optional, options);
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
+ }
971
1132
  case "Call": {
972
1133
  let fn;
973
1134
  let thisArg;
974
1135
  let methodName;
975
1136
  if (node.callee.type === "Member") {
976
1137
  const object = evaluateNode(node.callee.object, environment, state, options);
977
- const key = evaluateNode(node.callee.property, environment, state, options);
978
- fn = readMember(object, key, node.callee.optional, options);
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);
979
1141
  thisArg = object;
980
1142
  methodName = String(key);
981
- } else fn = evaluateNode(node.callee, environment, state, options);
982
- if (fn == null && node.optional) return;
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
+ }
983
1152
  if (typeof fn !== "function") {
984
- if (node.optional) return;
1153
+ if (node.optional) return OPTIONAL_SHORT_CIRCUIT;
985
1154
  return fail("Attempted to call a non-function value.");
986
1155
  }
987
1156
  if (fn === Function || fn === eval) return fail("Calling global constructors is not allowed.");
988
1157
  if (node.callee.type === "Member") {
989
- if (!isNativeFunction(fn) && !isInterpreterFunction(fn) && !isMethodAllowed(methodName ?? "", options)) return fail("Calling custom methods is not allowed.");
990
- } else if (!(node.callee.type === "Identifier" && node.callee.name === "$vm") && !isInterpreterFunction(fn) && !isMethodAllowed("", options)) return fail("Calling custom functions is not allowed.");
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.");
991
1160
  const args = [];
992
1161
  for (const argument of node.args) {
993
- const value = evaluateNode(argument.value, environment, state, options);
1162
+ const value = normalizeOptional(evaluateNode(argument.value, environment, state, options));
994
1163
  if (argument.spread) args.push(...spreadValues(value));
995
1164
  else args.push(value);
996
1165
  }
1166
+ assertSafeCallbackArguments(fn, args, options);
1167
+ assertSafeCoercion(fn, thisArg, args, options);
997
1168
  if (fn === String.prototype.repeat) {
998
1169
  const count = args[0];
999
1170
  const source = String(thisArg ?? "");
@@ -1003,13 +1174,41 @@ function evaluateNode(node, environment, state, options) {
1003
1174
  const targetLength = args[0];
1004
1175
  if (typeof targetLength === "number" && targetLength > MAX_STRING_LENGTH) return fail("String padding is too large.");
1005
1176
  }
1006
- if (fn === Array.prototype.join && Array.isArray(thisArg) && thisArg.length > MAX_STRING_LENGTH) return fail("Array join is too large.");
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
+ }
1007
1205
  const result = fn.apply(thisArg, args);
1206
+ if (fn === state.rootVm && result !== null && (typeof result === "object" || typeof result === "function")) state.rootVmValues.add(result);
1008
1207
  if (typeof result === "string" && result.length > MAX_STRING_LENGTH) return fail("Expression result is too large.");
1009
1208
  return assertSafeValue(result);
1010
1209
  }
1011
1210
  case "Unary": {
1012
- const argument = evaluateNode(node.argument, environment, state, options);
1211
+ const argument = normalizeOptional(evaluateNode(node.argument, environment, state, options));
1013
1212
  switch (node.operator) {
1014
1213
  case "!": return !argument;
1015
1214
  case "typeof": return typeof argument;
@@ -1023,8 +1222,8 @@ function evaluateNode(node, environment, state, options) {
1023
1222
  }
1024
1223
  }
1025
1224
  case "Binary": {
1026
- const left = evaluateNode(node.left, environment, state, options);
1027
- const right = evaluateNode(node.right, environment, state, options);
1225
+ const left = normalizeOptional(evaluateNode(node.left, environment, state, options));
1226
+ const right = normalizeOptional(evaluateNode(node.right, environment, state, options));
1028
1227
  switch (node.operator) {
1029
1228
  case "===": return left === right;
1030
1229
  case "!==": return left !== right;
@@ -1044,7 +1243,7 @@ function evaluateNode(node, environment, state, options) {
1044
1243
  }
1045
1244
  }
1046
1245
  case "Logical": {
1047
- const left = evaluateNode(node.left, environment, state, options);
1246
+ const left = normalizeOptional(evaluateNode(node.left, environment, state, options));
1048
1247
  switch (node.operator) {
1049
1248
  case "&&": return left ? evaluateNode(node.right, environment, state, options) : left;
1050
1249
  case "||": return left ? left : evaluateNode(node.right, environment, state, options);
@@ -1052,11 +1251,11 @@ function evaluateNode(node, environment, state, options) {
1052
1251
  default: return fail(`Unsupported logical operator "${node.operator}".`);
1053
1252
  }
1054
1253
  }
1055
- case "Conditional": return evaluateNode(node.test, environment, state, options) ? evaluateNode(node.consequent, environment, state, options) : evaluateNode(node.alternate, environment, state, options);
1254
+ case "Conditional": return normalizeOptional(evaluateNode(node.test, environment, state, options)) ? evaluateNode(node.consequent, environment, state, options) : evaluateNode(node.alternate, environment, state, options);
1056
1255
  case "Array": {
1057
1256
  const values = [];
1058
1257
  for (const element of node.elements) {
1059
- const value = evaluateNode(element.value, environment, state, options);
1258
+ const value = normalizeOptional(evaluateNode(element.value, environment, state, options));
1060
1259
  if (element.spread) values.push(...spreadValues(value));
1061
1260
  else values.push(value);
1062
1261
  }
@@ -1066,7 +1265,7 @@ function evaluateNode(node, environment, state, options) {
1066
1265
  const result = {};
1067
1266
  for (const property of node.properties) {
1068
1267
  if (property.spread) {
1069
- const source = evaluateNode(property.value, environment, state, options);
1268
+ const source = normalizeOptional(evaluateNode(property.value, environment, state, options));
1070
1269
  if (source == null || typeof source !== "object") return fail("Object spread is only supported for objects.");
1071
1270
  for (const key of Object.keys(source)) {
1072
1271
  const descriptor = Object.getOwnPropertyDescriptor(source, key);
@@ -1075,9 +1274,9 @@ function evaluateNode(node, environment, state, options) {
1075
1274
  continue;
1076
1275
  }
1077
1276
  if (!property.key) return fail("Invalid object property.");
1078
- const key = property.computed ? evaluateNode(property.key, environment, state, options) : property.key.value;
1277
+ const key = property.computed ? normalizeOptional(evaluateNode(property.key, environment, state, options)) : property.key.value;
1079
1278
  if (typeof key !== "string" && typeof key !== "number") return fail("Object keys must be strings or numbers.");
1080
- defineSafeProperty(result, String(key), evaluateNode(property.value, environment, state, options));
1279
+ defineSafeProperty(result, String(key), normalizeOptional(evaluateNode(property.value, environment, state, options)));
1081
1280
  }
1082
1281
  return result;
1083
1282
  }
@@ -1090,7 +1289,7 @@ function evaluateNode(node, environment, state, options) {
1090
1289
  params.forEach((parameter, index) => {
1091
1290
  local.set(parameter, args[index]);
1092
1291
  });
1093
- return evaluateNode(body, local, state, options);
1292
+ return normalizeOptional(evaluateNode(body, local, state, options));
1094
1293
  };
1095
1294
  INTERPRETER_FUNCTIONS.add(arrowFunction);
1096
1295
  return arrowFunction;
@@ -1108,11 +1307,17 @@ function evaluateSafeExpression(source, variables = {}, options) {
1108
1307
  const ast = new ExpressionParser(tokenize(source)).parse();
1109
1308
  const environment = /* @__PURE__ */ new Map();
1110
1309
  for (const [key, value] of Object.entries(variables)) environment.set(key, value);
1111
- return assertSafeValue(evaluateNode(ast, environment, {
1310
+ return assertSafeValue(normalizeOptional(evaluateNode(ast, environment, {
1112
1311
  steps: 0,
1113
- depth: 0
1114
- }, options));
1312
+ depth: 0,
1313
+ rootVm: variables["$vm"],
1314
+ rootVmValues: /* @__PURE__ */ new WeakSet()
1315
+ }, options)));
1115
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/;
1116
1321
  const FORBIDDEN_PATH_SEGMENTS = /* @__PURE__ */ new Set([
1117
1322
  "__proto__",
1118
1323
  "prototype",
@@ -1236,11 +1441,12 @@ var FGDynamicComponent = class FGDynamicComponent {
1236
1441
  this.typePolicy = input({}, ...ngDevMode ? [{ debugName: "typePolicy" }] : /* istanbul ignore next */ []);
1237
1442
  this.attributePolicy = input({}, ...ngDevMode ? [{ debugName: "attributePolicy" }] : /* istanbul ignore next */ []);
1238
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 */ []);
1239
1445
  this.items = computed(() => {
1240
- if (this.depth() >= MAX_CONFIGURATION_DEPTH) return [];
1446
+ if (this.depth() >= MAX_CONFIGURATION_DEPTH || !this._configurationIsValid()) return [];
1241
1447
  const configuration = this.configuration();
1242
- if (!this.validateConfiguration(configuration)) return [];
1243
- const items = configuration && typeof configuration === "object" && !Array.isArray(configuration) ? configuration.items : void 0;
1448
+ if (configuration == null || typeof configuration !== "object" || Array.isArray(configuration)) return [];
1449
+ const items = configuration.items;
1244
1450
  if (!Array.isArray(items)) return [];
1245
1451
  return items.filter((item) => item != null && typeof item === "object" && !Array.isArray(item)).slice(0, MAX_CONFIGURATION_ITEMS);
1246
1452
  }, ...ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []);
@@ -1257,13 +1463,16 @@ var FGDynamicComponent = class FGDynamicComponent {
1257
1463
  this._managedValidatorFns = [];
1258
1464
  this._injector = inject(Injector);
1259
1465
  this._ngOnChangesCounter = 0;
1466
+ this._destroyed = false;
1260
1467
  this._ownsFormControl = false;
1261
1468
  this._createdFormGroups = [];
1469
+ this._hasSyncedControlValue = false;
1262
1470
  this._disabledManaged = false;
1263
1471
  this._appliedAttributes = /* @__PURE__ */ new Set();
1264
1472
  this._appliedInputs = /* @__PURE__ */ new Set();
1265
1473
  }
1266
1474
  async ngOnChanges(changes) {
1475
+ if (this._destroyed) return;
1267
1476
  const counter = ++this._ngOnChangesCounter;
1268
1477
  try {
1269
1478
  const configuration = this.configuration();
@@ -1272,13 +1481,13 @@ var FGDynamicComponent = class FGDynamicComponent {
1272
1481
  this.clearResolvedComponent(counter);
1273
1482
  return;
1274
1483
  }
1275
- if (!this.validateConfiguration(configuration)) {
1484
+ if (!this._configurationIsValid()) {
1276
1485
  this.logError("Invalid configuration: it exceeds the structural limits.");
1277
1486
  this.clearResolvedComponent(counter);
1278
1487
  return;
1279
1488
  }
1280
1489
  await this.loadComponentAsync(counter);
1281
- if (counter !== this._ngOnChangesCounter) return;
1490
+ if (this._destroyed || counter !== this._ngOnChangesCounter) return;
1282
1491
  const items = this.items();
1283
1492
  const itemsSignature = items.length > 0 ? `${items.length}:${items.map((item, index) => `${index}:${item?.type}`).join("|")}` : "";
1284
1493
  if (this._componentRef && this._lastProjectedItemsSignature !== itemsSignature) {
@@ -1287,10 +1496,11 @@ var FGDynamicComponent = class FGDynamicComponent {
1287
1496
  } else if (!this._componentRef) this._lastProjectedItemsSignature = itemsSignature;
1288
1497
  this.rewireFormIfNeeded();
1289
1498
  this.createComponent();
1290
- if (counter !== this._ngOnChangesCounter) return;
1499
+ if (this._destroyed || counter !== this._ngOnChangesCounter) return;
1291
1500
  this.setInputs();
1292
1501
  this.setFormControlStatus();
1293
1502
  this.setFormControlValidators();
1503
+ this.syncFormControlFromViewModel();
1294
1504
  this.setAttributes();
1295
1505
  this.handleOutputsIfChanged();
1296
1506
  if (this._componentRef?.changeDetectorRef) this._componentRef.changeDetectorRef.markForCheck();
@@ -1302,7 +1512,7 @@ var FGDynamicComponent = class FGDynamicComponent {
1302
1512
  }
1303
1513
  }
1304
1514
  clearResolvedComponent(counter) {
1305
- if (counter !== this._ngOnChangesCounter) return;
1515
+ if (this._destroyed || counter !== this._ngOnChangesCounter) return;
1306
1516
  this._component = void 0;
1307
1517
  if (this._componentRef) this.cleanup();
1308
1518
  }
@@ -1323,7 +1533,10 @@ var FGDynamicComponent = class FGDynamicComponent {
1323
1533
  while (stack.length > 0) {
1324
1534
  const current = stack.pop();
1325
1535
  const item = current.item;
1326
- if (item == null || typeof item !== "object" || Array.isArray(item)) return null;
1536
+ if (item == null || typeof item !== "object" || Array.isArray(item)) {
1537
+ if (current.depth === 0) return null;
1538
+ continue;
1539
+ }
1327
1540
  if (seen.has(item)) return null;
1328
1541
  seen.add(item);
1329
1542
  nodes++;
@@ -1537,7 +1750,9 @@ var FGDynamicComponent = class FGDynamicComponent {
1537
1750
  const formGroup = this.formGroup();
1538
1751
  const controlName = this.resolveFormControlName();
1539
1752
  const desiredGroup = formGroup && controlName ? formGroup : void 0;
1540
- if (this._wiredFormGroup !== desiredGroup || this._wiredControlName !== controlName) this.cleanup();
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();
1541
1756
  }
1542
1757
  wireFormControl() {
1543
1758
  const formGroup = this.formGroup();
@@ -1555,6 +1770,7 @@ var FGDynamicComponent = class FGDynamicComponent {
1555
1770
  }
1556
1771
  const parent = this.ensureFormGroupPath(formGroup, path.slice(0, -1));
1557
1772
  if (!parent) {
1773
+ this.pruneCreatedFormGroups();
1558
1774
  this._wiredFormGroup = void 0;
1559
1775
  this._wiredControlName = void 0;
1560
1776
  return;
@@ -1564,12 +1780,14 @@ var FGDynamicComponent = class FGDynamicComponent {
1564
1780
  if (existing) {
1565
1781
  if (this.formControlPolicy()?.allowExistingControls !== true) {
1566
1782
  this.logWarning("A form control with the requested name already exists; reuse is disabled by formControlPolicy.");
1783
+ this.pruneCreatedFormGroups();
1567
1784
  this._wiredFormGroup = void 0;
1568
1785
  this._wiredControlName = void 0;
1569
1786
  return;
1570
1787
  }
1571
1788
  if (!(existing instanceof FormControl)) {
1572
1789
  this.logWarning("A form control with the requested name already exists and is not a FormControl.");
1790
+ this.pruneCreatedFormGroups();
1573
1791
  this._wiredFormGroup = void 0;
1574
1792
  this._wiredControlName = void 0;
1575
1793
  return;
@@ -1585,6 +1803,7 @@ var FGDynamicComponent = class FGDynamicComponent {
1585
1803
  this._ownsFormControl = true;
1586
1804
  } catch (error) {
1587
1805
  this.logError("Error adding form control.", error);
1806
+ this.pruneCreatedFormGroups();
1588
1807
  return;
1589
1808
  }
1590
1809
  }
@@ -1592,7 +1811,10 @@ var FGDynamicComponent = class FGDynamicComponent {
1592
1811
  this._formControlKey = key;
1593
1812
  this._wiredFormGroup = formGroup;
1594
1813
  this._wiredControlName = name;
1814
+ this._wiredAllowExistingControls = this.formControlPolicy()?.allowExistingControls === true;
1595
1815
  this._disabledBeforeManagement = this._formControl.disabled;
1816
+ this._lastSyncedControlValue = this._formControl.value;
1817
+ this._hasSyncedControlValue = true;
1596
1818
  this.attachFormControlDirective();
1597
1819
  this.bindFormControlValueChanges(name);
1598
1820
  }
@@ -1606,6 +1828,7 @@ var FGDynamicComponent = class FGDynamicComponent {
1606
1828
  current.addControl(segment, group);
1607
1829
  } catch (error) {
1608
1830
  this.logError("Error creating nested form group.", error);
1831
+ this.pruneCreatedFormGroups();
1609
1832
  return null;
1610
1833
  }
1611
1834
  this._createdFormGroups.push({
@@ -1617,11 +1840,13 @@ var FGDynamicComponent = class FGDynamicComponent {
1617
1840
  } else if (existing instanceof FormGroup) {
1618
1841
  if (this.formControlPolicy()?.allowExistingControls !== true) {
1619
1842
  this.logWarning(`Cannot reuse existing nested form group "${segment}" because formControlPolicy disables it.`);
1843
+ this.pruneCreatedFormGroups();
1620
1844
  return null;
1621
1845
  }
1622
1846
  current = existing;
1623
1847
  } else {
1624
1848
  this.logWarning(`Cannot create nested form group "${segment}" because a different control already exists.`);
1849
+ this.pruneCreatedFormGroups();
1625
1850
  return null;
1626
1851
  }
1627
1852
  }
@@ -1634,8 +1859,12 @@ var FGDynamicComponent = class FGDynamicComponent {
1634
1859
  this._formControlSubscription = this._formControl.valueChanges.subscribe((value) => {
1635
1860
  const currentModel = this.getViewModelValue();
1636
1861
  if (currentModel == null) return;
1637
- const viewModel = this.cloneForMutation(currentModel);
1638
- this.setModelPropertyValue(viewModel, name, value);
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;
1639
1868
  try {
1640
1869
  this.viewModel.set(viewModel);
1641
1870
  if (this._componentRef?.changeDetectorRef) this._componentRef.changeDetectorRef.markForCheck();
@@ -1644,36 +1873,81 @@ var FGDynamicComponent = class FGDynamicComponent {
1644
1873
  }
1645
1874
  });
1646
1875
  }
1647
- cloneForMutation(value, seen = /* @__PURE__ */ new WeakMap()) {
1648
- if (value == null || typeof value !== "object") return value;
1649
- const source = value;
1650
- if (seen.has(source)) return seen.get(source);
1651
- if (Array.isArray(value)) {
1652
- const copy = [];
1653
- seen.set(source, copy);
1654
- for (const item of value) copy.push(this.cloneForMutation(item, seen));
1655
- return copy;
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;
1656
1928
  }
1657
- const prototype = Object.getPrototypeOf(value);
1658
- if (prototype === Object.prototype || prototype === null) {
1659
- const copy = {};
1660
- seen.set(source, copy);
1661
- for (const key of Object.keys(value)) this.defineOwn(copy, key, this.cloneForMutation(value[key], seen));
1662
- return copy;
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);
1663
1943
  }
1664
- return value;
1944
+ this._createdFormGroups = kept;
1665
1945
  }
1666
1946
  setControlDisabled(disabled) {
1667
1947
  if (!this._formControl) return;
1668
1948
  try {
1669
- if (disabled && this._formControl.enabled) this._formControl.disable({
1670
- onlySelf: true,
1671
- emitEvent: false
1672
- });
1673
- else if (!disabled && this._formControl.disabled) this._formControl.enable({
1674
- onlySelf: true,
1675
- emitEvent: false
1676
- });
1949
+ if (disabled && this._formControl.enabled) this._formControl.disable({ emitEvent: false });
1950
+ else if (!disabled && this._formControl.disabled) this._formControl.enable({ emitEvent: false });
1677
1951
  } catch (error) {
1678
1952
  this.logError("Error updating form control status.", error);
1679
1953
  }
@@ -1711,10 +1985,7 @@ var FGDynamicComponent = class FGDynamicComponent {
1711
1985
  }
1712
1986
  this._managedValidatorFns = [];
1713
1987
  try {
1714
- this._formControl.updateValueAndValidity({
1715
- onlySelf: true,
1716
- emitEvent: false
1717
- });
1988
+ this._formControl.updateValueAndValidity({ emitEvent: false });
1718
1989
  } catch (error) {
1719
1990
  this.logError("Error updating form control validity.", error);
1720
1991
  }
@@ -1760,10 +2031,7 @@ var FGDynamicComponent = class FGDynamicComponent {
1760
2031
  }
1761
2032
  } else this._managedValidatorFns = [];
1762
2033
  try {
1763
- this._formControl.updateValueAndValidity({
1764
- onlySelf: true,
1765
- emitEvent: false
1766
- });
2034
+ this._formControl.updateValueAndValidity({ emitEvent: false });
1767
2035
  } catch (error) {
1768
2036
  this.logError("Error updating form control validity.", error);
1769
2037
  }
@@ -1889,7 +2157,9 @@ var FGDynamicComponent = class FGDynamicComponent {
1889
2157
  attachFormControlDirective() {
1890
2158
  if (this._formControlDirective && this._componentRef?.injector && this._formControl) try {
1891
2159
  const valueAccessors = this._componentRef.injector.get(NG_VALUE_ACCESSOR, null);
1892
- this._formControlDirective.valueAccessor = Array.isArray(valueAccessors) && valueAccessors.length > 0 ? valueAccessors[0] : null;
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;
1893
2163
  this._formControlDirective.form = this._formControl;
1894
2164
  this._formControlDirective.ngOnChanges({ form: {
1895
2165
  firstChange: true,
@@ -2007,7 +2277,9 @@ var FGDynamicComponent = class FGDynamicComponent {
2007
2277
  if (current == null) return defaultValue;
2008
2278
  const container = Object(current);
2009
2279
  if (!Object.hasOwn(container, key)) return defaultValue;
2010
- current = container[key];
2280
+ const descriptor = Object.getOwnPropertyDescriptor(container, key);
2281
+ if (!descriptor || !("value" in descriptor)) return defaultValue;
2282
+ current = descriptor.value;
2011
2283
  }
2012
2284
  return current != null ? current : defaultValue;
2013
2285
  } catch {
@@ -2025,11 +2297,18 @@ var FGDynamicComponent = class FGDynamicComponent {
2025
2297
  const isLast = index === pathArray.length - 1;
2026
2298
  if (!this.isMutableContainer(current)) return;
2027
2299
  if (isLast) {
2300
+ const descriptor = Object.getOwnPropertyDescriptor(current, key);
2301
+ if (descriptor && !("value" in descriptor)) return;
2028
2302
  this.defineOwn(current, key, value);
2029
2303
  return;
2030
2304
  }
2031
2305
  const isNumericKey = /^\d+$/.test(key);
2032
- const existing = Object.hasOwn(current, key) ? current[key] : void 0;
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
+ }
2033
2312
  if (existing == null) {
2034
2313
  const next = isNumericKey ? [] : {};
2035
2314
  this.defineOwn(current, key, next);
@@ -2141,9 +2420,23 @@ var FGDynamicComponent = class FGDynamicComponent {
2141
2420
  isSafeUrl(value) {
2142
2421
  const normalized = value.replace(/[\u0000-\u0020\u007f]/g, "").toLowerCase();
2143
2422
  if (normalized.length === 0) return true;
2423
+ if (normalized.startsWith("//")) return this.allowsExternalUrls();
2144
2424
  const scheme = /^([a-z][a-z0-9+.-]*):/.exec(normalized);
2145
2425
  if (!scheme) return true;
2146
- return scheme[1] === "http" || scheme[1] === "https" || scheme[1] === "mailto" || scheme[1] === "tel";
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
+ }
2147
2440
  }
2148
2441
  evaluateAttribute(attributes, name) {
2149
2442
  const raw = attributes[name];
@@ -2154,7 +2447,7 @@ var FGDynamicComponent = class FGDynamicComponent {
2154
2447
  };
2155
2448
  }
2156
2449
  isUnresolvedExpression(source, result) {
2157
- return typeof source === "string" && result === source && (source.includes("$vm") || source.includes("$event") || source.includes("$ev"));
2450
+ return typeof source === "string" && result === source && EXPRESSION_CONTEXT_PATTERN.test(source);
2158
2451
  }
2159
2452
  toBoolean(value) {
2160
2453
  if (typeof value === "boolean") return value;
@@ -2167,14 +2460,14 @@ var FGDynamicComponent = class FGDynamicComponent {
2167
2460
  }
2168
2461
  evaluateExpression(value, viewModelValue, eventParam, hasEventContext = false) {
2169
2462
  if (typeof value !== "string") return value;
2170
- const hasVm = value.includes("$vm");
2171
- const hasEvent = value.includes("$event") || value.includes("$ev");
2463
+ const hasVm = VM_EXPRESSION_PATTERN.test(value);
2464
+ const hasEvent = EVENT_EXPRESSION_PATTERN.test(value);
2172
2465
  if (!hasVm && !hasEvent) return value;
2173
2466
  if (hasVm && viewModelValue == null) return value;
2174
2467
  if (hasEvent && !hasEventContext) return value;
2175
2468
  try {
2176
2469
  const policy = this.expressionPolicy() ?? {};
2177
- const allowedMethods = new Set(Array.isArray(policy.allowedMethods) ? policy.allowedMethods : []);
2470
+ const allowedMethods = Array.isArray(policy.allowedMethods) ? [...policy.allowedMethods] : [];
2178
2471
  const $vm = () => this.getViewModelValue();
2179
2472
  if (policy.allowViewModelMutation === true) {
2180
2473
  $vm.set = (nextValue) => {
@@ -2183,8 +2476,8 @@ var FGDynamicComponent = class FGDynamicComponent {
2183
2476
  $vm.update = (updateFn) => {
2184
2477
  this.viewModel.update(updateFn);
2185
2478
  };
2186
- allowedMethods.add("set");
2187
- allowedMethods.add("update");
2479
+ allowedMethods.push("set");
2480
+ allowedMethods.push("update");
2188
2481
  }
2189
2482
  return evaluateSafeExpression(value, {
2190
2483
  $vm,
@@ -2192,7 +2485,7 @@ var FGDynamicComponent = class FGDynamicComponent {
2192
2485
  $ev: eventParam
2193
2486
  }, {
2194
2487
  allowCustomMethods: policy.allowCustomMethods === true,
2195
- allowedMethods: Array.from(allowedMethods)
2488
+ allowedMethods
2196
2489
  });
2197
2490
  } catch {
2198
2491
  this.logWarning("Expression could not be evaluated safely and was ignored.");
@@ -2223,6 +2516,12 @@ var FGDynamicComponent = class FGDynamicComponent {
2223
2516
  this._formControlSubscription.unsubscribe();
2224
2517
  } catch (e) {}
2225
2518
  this._formControlSubscription = void 0;
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
+ }
2226
2525
  this.restoreManagedDisabledState();
2227
2526
  if (this._formControlDirective) try {
2228
2527
  this._formControlDirective.ngOnDestroy();
@@ -2231,12 +2530,7 @@ var FGDynamicComponent = class FGDynamicComponent {
2231
2530
  if (this._ownsFormControl && this._formControl && this._formControlContainer && this._formControlKey) try {
2232
2531
  if (this._formControlContainer.get(this._formControlKey) === this._formControl) this._formControlContainer.removeControl(this._formControlKey);
2233
2532
  } catch (e) {}
2234
- for (let index = this._createdFormGroups.length - 1; index >= 0; index--) {
2235
- const { parent, key, group } = this._createdFormGroups[index];
2236
- try {
2237
- if (parent.get(key) === group && Object.keys(group.controls).length === 0) parent.removeControl(key);
2238
- } catch (e) {}
2239
- }
2533
+ this.pruneCreatedFormGroups();
2240
2534
  this._createdFormGroups = [];
2241
2535
  this._formControl = void 0;
2242
2536
  this._formControlContainer = void 0;
@@ -2246,6 +2540,9 @@ var FGDynamicComponent = class FGDynamicComponent {
2246
2540
  this._disabledBeforeManagement = void 0;
2247
2541
  this._wiredFormGroup = void 0;
2248
2542
  this._wiredControlName = void 0;
2543
+ this._wiredAllowExistingControls = void 0;
2544
+ this._hasSyncedControlValue = false;
2545
+ this._lastSyncedControlValue = void 0;
2249
2546
  this._managedValidatorFns = [];
2250
2547
  this._appliedAttributes.clear();
2251
2548
  this._appliedInputs.clear();
@@ -2255,6 +2552,8 @@ var FGDynamicComponent = class FGDynamicComponent {
2255
2552
  this._componentRef = void 0;
2256
2553
  }
2257
2554
  ngOnDestroy() {
2555
+ this._destroyed = true;
2556
+ this._ngOnChangesCounter++;
2258
2557
  this.cleanup();
2259
2558
  }
2260
2559
  static {