@ng-forge/dynamic-forms 1.0.0 → 1.1.0-next.1

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.
@@ -1720,12 +1720,15 @@ class FieldContextRegistryService {
1720
1720
  },
1721
1721
  };
1722
1722
  }
1723
- createDisplayOnlyContext(fieldPath, customFunctions) {
1724
- const formValue = this.rootFormRegistry.formValue();
1723
+ createDisplayOnlyContext(fieldPath, customFunctions, arrayScope) {
1724
+ const rootFormValue = this.rootFormRegistry.formValue();
1725
+ if (arrayScope) {
1726
+ return this.buildArrayScopedContext(rootFormValue, arrayScope, undefined, customFunctions, true);
1727
+ }
1725
1728
  const rootFormSignal = this.rootFormRegistry.rootForm;
1726
1729
  return {
1727
1730
  fieldValue: undefined,
1728
- formValue,
1731
+ formValue: rootFormValue,
1729
1732
  fieldPath,
1730
1733
  customFunctions: customFunctions || {},
1731
1734
  externalData: this.resolveExternalData(true),
@@ -2328,7 +2331,10 @@ function evaluateLogicCondition(condition, ctx) {
2328
2331
  if (isFormStateCondition(condition)) {
2329
2332
  return evaluateFormStateCondition(condition, ctx);
2330
2333
  }
2331
- const formValue = (ctx.formValue ?? ctx.form().value());
2334
+ if (ctx.evaluationContext) {
2335
+ return evaluateCondition(condition, ctx.evaluationContext());
2336
+ }
2337
+ const formValue = (ctx.formValue ?? ctx.form().value());
2332
2338
  const evaluationContext = {
2333
2339
  fieldValue: undefined,
2334
2340
  formValue,
@@ -2356,6 +2362,7 @@ function evaluateLogicOfType(fieldLogic, logicType, ctx) {
2356
2362
  const buttonCtx = {
2357
2363
  form: ctx.form,
2358
2364
  formValue: ctx.formValue,
2365
+ evaluationContext: ctx.evaluationContext,
2359
2366
  logger: ctx.logger,
2360
2367
  };
2361
2368
  return fieldLogic.filter((logic) => logic.type === logicType).some((logic) => evaluateLogicCondition(logic.condition, buttonCtx));
@@ -2412,6 +2419,7 @@ function evaluateNonFieldHidden(ctx) {
2412
2419
  return evaluateLogicOfType(ctx.fieldLogic, 'hidden', {
2413
2420
  form: ctx.form,
2414
2421
  formValue: ctx.formValue,
2422
+ evaluationContext: ctx.evaluationContext,
2415
2423
  logger: ctx.logger,
2416
2424
  });
2417
2425
  }
@@ -2428,6 +2436,7 @@ function evaluateNonFieldDisabled(ctx) {
2428
2436
  return evaluateLogicOfType(ctx.fieldLogic, 'disabled', {
2429
2437
  form: ctx.form,
2430
2438
  formValue: ctx.formValue,
2439
+ evaluationContext: ctx.evaluationContext,
2431
2440
  logger: ctx.logger,
2432
2441
  });
2433
2442
  }
@@ -2436,6 +2445,17 @@ function evaluateNonFieldDisabled(ctx) {
2436
2445
  function resolveNonFieldDisabled(ctx) {
2437
2446
  return computed(() => evaluateNonFieldDisabled(ctx));
2438
2447
  }
2448
+ function injectNonFieldEvaluationContext(fieldDef, options = {}) {
2449
+ const fieldContextRegistry = inject(FieldContextRegistryService);
2450
+ const functionRegistry = inject(FunctionRegistryService);
2451
+ const arrayContext = options.scopeToArrayItem ? inject(ARRAY_CONTEXT, { optional: true }) : null;
2452
+ return () => {
2453
+ const arrayScope = arrayContext
2454
+ ? { arrayKey: arrayContext.arrayKey, index: arrayContext.index(), localKey: fieldDef.key ?? '' }
2455
+ : undefined;
2456
+ return fieldContextRegistry.createDisplayOnlyContext(fieldDef.key ?? '', functionRegistry.getCustomFunctions(), arrayScope);
2457
+ };
2458
+ }
2439
2459
 
2440
2460
  function isFunctionHttpValidator(config) {
2441
2461
  const c = config;
@@ -2989,7 +3009,7 @@ function buildClassName(fieldDef) {
2989
3009
  return classes.length > 0 ? classes.join(' ') : undefined;
2990
3010
  }
2991
3011
 
2992
- function applyHiddenLogic(inputs, fieldDef, rootFormRegistry) {
3012
+ function applyHiddenLogic(inputs, fieldDef, rootFormRegistry, evaluationContext) {
2993
3013
  const rootForm = rootFormRegistry.rootForm();
2994
3014
  if (rootForm && (fieldDef.hidden === true || fieldDef.logic?.some((l) => l.type === 'hidden'))) {
2995
3015
  inputs['hidden'] = evaluateNonFieldHidden({
@@ -2997,12 +3017,14 @@ function applyHiddenLogic(inputs, fieldDef, rootFormRegistry) {
2997
3017
  fieldLogic: fieldDef.logic,
2998
3018
  explicitValue: fieldDef.hidden,
2999
3019
  formValue: rootFormRegistry.formValue(),
3020
+ evaluationContext,
3000
3021
  });
3001
3022
  }
3002
3023
  }
3003
3024
 
3004
3025
  function arrayFieldMapper(fieldDef) {
3005
3026
  const rootFormRegistry = inject(RootFormRegistryService);
3027
+ const evaluationContext = injectNonFieldEvaluationContext(fieldDef, { scopeToArrayItem: true });
3006
3028
  const className = buildClassName(fieldDef);
3007
3029
  return computed(() => {
3008
3030
  const inputs = {
@@ -3010,7 +3032,7 @@ function arrayFieldMapper(fieldDef) {
3010
3032
  field: fieldDef,
3011
3033
  ...(className !== undefined && { className }),
3012
3034
  };
3013
- applyHiddenLogic(inputs, fieldDef, rootFormRegistry);
3035
+ applyHiddenLogic(inputs, fieldDef, rootFormRegistry, evaluationContext);
3014
3036
  return inputs;
3015
3037
  });
3016
3038
  }
@@ -3055,6 +3077,7 @@ function baseFieldMapper(fieldDef) {
3055
3077
 
3056
3078
  function containerFieldMapper(fieldDef) {
3057
3079
  const rootFormRegistry = inject(RootFormRegistryService);
3080
+ const evaluationContext = injectNonFieldEvaluationContext(fieldDef, { scopeToArrayItem: true });
3058
3081
  const className = buildClassName(fieldDef);
3059
3082
  return computed(() => {
3060
3083
  const containerField = { ...fieldDef, wrappers: undefined, skipAutoWrappers: undefined, skipDefaultWrappers: undefined };
@@ -3063,13 +3086,14 @@ function containerFieldMapper(fieldDef) {
3063
3086
  field: containerField,
3064
3087
  ...(className !== undefined && { className }),
3065
3088
  };
3066
- applyHiddenLogic(inputs, fieldDef, rootFormRegistry);
3089
+ applyHiddenLogic(inputs, fieldDef, rootFormRegistry, evaluationContext);
3067
3090
  return inputs;
3068
3091
  });
3069
3092
  }
3070
3093
 
3071
3094
  function groupFieldMapper(fieldDef) {
3072
3095
  const rootFormRegistry = inject(RootFormRegistryService);
3096
+ const evaluationContext = injectNonFieldEvaluationContext(fieldDef, { scopeToArrayItem: true });
3073
3097
  const className = buildClassName(fieldDef);
3074
3098
  return computed(() => {
3075
3099
  const inputs = {
@@ -3077,7 +3101,7 @@ function groupFieldMapper(fieldDef) {
3077
3101
  field: fieldDef,
3078
3102
  ...(className !== undefined && { className }),
3079
3103
  };
3080
- applyHiddenLogic(inputs, fieldDef, rootFormRegistry);
3104
+ applyHiddenLogic(inputs, fieldDef, rootFormRegistry, evaluationContext);
3081
3105
  return inputs;
3082
3106
  });
3083
3107
  }
@@ -3085,6 +3109,7 @@ function groupFieldMapper(fieldDef) {
3085
3109
  const ROW_WRAPPERS = [{ type: 'row' }];
3086
3110
  function rowFieldMapper(fieldDef) {
3087
3111
  const rootFormRegistry = inject(RootFormRegistryService);
3112
+ const evaluationContext = injectNonFieldEvaluationContext(fieldDef, { scopeToArrayItem: true });
3088
3113
  const className = buildClassName(fieldDef);
3089
3114
  return computed(() => {
3090
3115
  const containerField = { ...fieldDef, type: 'container', wrappers: ROW_WRAPPERS };
@@ -3093,7 +3118,7 @@ function rowFieldMapper(fieldDef) {
3093
3118
  field: containerField,
3094
3119
  ...(className !== undefined && { className }),
3095
3120
  };
3096
- applyHiddenLogic(inputs, fieldDef, rootFormRegistry);
3121
+ applyHiddenLogic(inputs, fieldDef, rootFormRegistry, evaluationContext);
3097
3122
  return inputs;
3098
3123
  });
3099
3124
  }
@@ -3109,11 +3134,12 @@ function pageFieldMapper(fieldDef) {
3109
3134
 
3110
3135
  function textFieldMapper(fieldDef) {
3111
3136
  const rootFormRegistry = inject(RootFormRegistryService);
3137
+ const evaluationContext = injectNonFieldEvaluationContext(fieldDef, { scopeToArrayItem: true });
3112
3138
  const defaultProps = inject(DEFAULT_PROPS);
3113
3139
  return computed(() => {
3114
3140
  const baseInputs = buildBaseInputs(fieldDef, defaultProps());
3115
3141
  const inputs = { ...baseInputs };
3116
- applyHiddenLogic(inputs, fieldDef, rootFormRegistry);
3142
+ applyHiddenLogic(inputs, fieldDef, rootFormRegistry, evaluationContext);
3117
3143
  return inputs;
3118
3144
  });
3119
3145
  }
@@ -3605,5 +3631,5 @@ function createWarningTracker() {
3605
3631
 
3606
3632
 
3607
3633
 
3608
- export { ADDON_ACTION_HANDLERS, ADDON_ACTION_REGISTRY, ADDON_TYPE_COMPONENT_CACHE, ADDON_TYPE_DEFINITIONS, ADDON_TYPE_REGISTRY, ARRAY_CONTEXT, AsyncConditionFunctionCacheService, ComponentInitializedEvent, DEFAULT_PROPS, DEFAULT_VALIDATION_MESSAGES, DEFAULT_WRAPPERS, DEPRECATION_WARNING_TRACKER, DF_FIELD_TEMPLATES, DfAddonSlot, DynamicFormError, DynamicFormLogger, DynamicTextPipe, DynamicValueFunctionCacheService, EMIT_FORM_VALUE_ON_EVENTS, EXTERNAL_DATA, EventBus, ExpressionParser, ExpressionParserError, FIELD_REGISTRY, FIELD_SIGNAL_CONTEXT, FORM_ID_PREFIX, FORM_OPTIONS, FieldContextRegistryService, FunctionRegistryService, GROUP_CONTEXT, HTTP_CONDITION_CACHE, HttpConditionCache, HttpConditionFunctionCacheService, INITIALIZATION_TIMEOUT_MS, LogicFunctionCacheService, NoopLogger, READONLY_FIELD_TREE_CACHE, RootFormRegistryService, TokenType, WRAPPER_AUTO_ASSOCIATIONS, WRAPPER_COMPONENT_CACHE, WRAPPER_REGISTRY, applyMetaToElement, applyValidator, applyValidators, arrayFieldMapper, assertNever, baseFieldMapper, buildBaseInputs, compareValues, containerFieldMapper, createAddonActionRegistry, createDebouncedLogicFunction, createDefaultDerivationLogConfig, createDynamicValueFunction, createFormFieldStateMap, createInitializationTracker, createLogicFunction, createWarningTracker, deepMergeDefaults, derivedFromDeferred, detectFormMode, dynamicTextToObservable, evaluateCondition, evaluateNonFieldDisabled, evaluateNonFieldHidden, extractExpressionDependencies, extractStringDependencies, getArrayLength, getChangedKeys, getFieldValueHandling, getNestedValue, groupFieldMapper, hasChildFields, hasCrossFieldWhenCondition, hasFormValue, hasNestedProperty, hasTargetProperty, injectAddonTypeRegistry, injectFieldSignalContext, injectFieldsSupportingAddons, interpolateParams, isArrayField, isCheckedField, isContainerField, isCrossFieldBuiltInValidator, isCrossFieldExpression, isCrossFieldSchema, isCrossFieldStateLogic, isCrossFieldValidator, isDerivationLogicConfig, isDisplayOnlyField, isEqual, isFieldBoundContext, isFormStateCondition, isFunctionHttpValidator, isGenericContainerField, isGroupField, isHiddenField, isLeafField, isNonPagedForm, isPageField, isPagedForm, isResourceBasedValidator, isRowField, isSimplifiedArrayField, isStateLogicConfig, isValidNonPagedForm, isValidPagedForm, isValueBearingField, isValueField, isWrapperTypeDefinition, keyBy, mapValues, memoize, normalizeFieldsArray, omit, pageFieldMapper, readFieldStateInfo, resolveDynamicValue, resolveHttpRequest, resolveNextButtonDisabled, resolveNonFieldDisabled, resolveNonFieldHidden, resolveSubmitButtonDisabled, resolveTokens, rowFieldMapper, runPresetAction, setupInitializationTracking, shouldLog, textFieldMapper, toReadonlyFieldTree, toReadonlyFieldTreeCached, validatePageNesting, withPreviousValue, writeToFieldValue };
3634
+ export { ADDON_ACTION_HANDLERS, ADDON_ACTION_REGISTRY, ADDON_TYPE_COMPONENT_CACHE, ADDON_TYPE_DEFINITIONS, ADDON_TYPE_REGISTRY, ARRAY_CONTEXT, AsyncConditionFunctionCacheService, ComponentInitializedEvent, DEFAULT_PROPS, DEFAULT_VALIDATION_MESSAGES, DEFAULT_WRAPPERS, DEPRECATION_WARNING_TRACKER, DF_FIELD_TEMPLATES, DfAddonSlot, DynamicFormError, DynamicFormLogger, DynamicTextPipe, DynamicValueFunctionCacheService, EMIT_FORM_VALUE_ON_EVENTS, EXTERNAL_DATA, EventBus, ExpressionParser, ExpressionParserError, FIELD_REGISTRY, FIELD_SIGNAL_CONTEXT, FORM_ID_PREFIX, FORM_OPTIONS, FieldContextRegistryService, FunctionRegistryService, GROUP_CONTEXT, HTTP_CONDITION_CACHE, HttpConditionCache, HttpConditionFunctionCacheService, INITIALIZATION_TIMEOUT_MS, LogicFunctionCacheService, NoopLogger, READONLY_FIELD_TREE_CACHE, RootFormRegistryService, TokenType, WRAPPER_AUTO_ASSOCIATIONS, WRAPPER_COMPONENT_CACHE, WRAPPER_REGISTRY, applyMetaToElement, applyValidator, applyValidators, arrayFieldMapper, assertNever, baseFieldMapper, buildBaseInputs, compareValues, containerFieldMapper, createAddonActionRegistry, createDebouncedLogicFunction, createDefaultDerivationLogConfig, createDynamicValueFunction, createFormFieldStateMap, createInitializationTracker, createLogicFunction, createWarningTracker, deepMergeDefaults, derivedFromDeferred, detectFormMode, dynamicTextToObservable, evaluateCondition, evaluateNonFieldDisabled, evaluateNonFieldHidden, extractExpressionDependencies, extractStringDependencies, getArrayLength, getChangedKeys, getFieldValueHandling, getNestedValue, groupFieldMapper, hasChildFields, hasCrossFieldWhenCondition, hasFormValue, hasNestedProperty, hasTargetProperty, injectAddonTypeRegistry, injectFieldSignalContext, injectFieldsSupportingAddons, injectNonFieldEvaluationContext, interpolateParams, isArrayField, isCheckedField, isContainerField, isCrossFieldBuiltInValidator, isCrossFieldExpression, isCrossFieldSchema, isCrossFieldStateLogic, isCrossFieldValidator, isDerivationLogicConfig, isDisplayOnlyField, isEqual, isFieldBoundContext, isFormStateCondition, isFunctionHttpValidator, isGenericContainerField, isGroupField, isHiddenField, isLeafField, isNonPagedForm, isPageField, isPagedForm, isResourceBasedValidator, isRowField, isSimplifiedArrayField, isStateLogicConfig, isValidNonPagedForm, isValidPagedForm, isValueBearingField, isValueField, isWrapperTypeDefinition, keyBy, mapValues, memoize, normalizeFieldsArray, omit, pageFieldMapper, readFieldStateInfo, resolveDynamicValue, resolveHttpRequest, resolveNextButtonDisabled, resolveNonFieldDisabled, resolveNonFieldHidden, resolveSubmitButtonDisabled, resolveTokens, rowFieldMapper, runPresetAction, setupInitializationTracking, shouldLog, textFieldMapper, toReadonlyFieldTree, toReadonlyFieldTreeCached, validatePageNesting, withPreviousValue, writeToFieldValue };
3609
3635
  //# sourceMappingURL=ng-forge-dynamic-forms-internal.mjs.map