@dmitryvim/form-builder 0.2.15 → 0.2.16

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.
@@ -3739,6 +3739,18 @@ function updateSliderField(element, fieldPath, value, context) {
3739
3739
  }
3740
3740
 
3741
3741
  // src/components/container.ts
3742
+ function extractChildDefaults(elements) {
3743
+ const defaults = {};
3744
+ for (const child of elements) {
3745
+ if ("default" in child && child.default !== void 0) {
3746
+ defaults[child.key] = child.default;
3747
+ }
3748
+ }
3749
+ return defaults;
3750
+ }
3751
+ function mergeWithDefaults(prefill, defaults) {
3752
+ return { ...defaults, ...prefill };
3753
+ }
3742
3754
  function extractRootFormData(formRoot) {
3743
3755
  const data = {};
3744
3756
  const inputs = formRoot.querySelectorAll(
@@ -3814,10 +3826,13 @@ function renderSingleContainerElement(element, ctx, wrapper, pathKey) {
3814
3826
  containerWrap.appendChild(hintsElement);
3815
3827
  }
3816
3828
  }
3829
+ const childDefaults = extractChildDefaults(element.elements);
3830
+ const containerPrefill = ((_a = ctx.prefill) == null ? void 0 : _a[element.key]) || {};
3831
+ const mergedPrefill = mergeWithDefaults(containerPrefill, childDefaults);
3817
3832
  const subCtx = {
3818
3833
  path: pathJoin(ctx.path, element.key),
3819
- prefill: ((_a = ctx.prefill) == null ? void 0 : _a[element.key]) || {},
3820
- // Sliced data for value population
3834
+ prefill: mergedPrefill,
3835
+ // Merged prefill with defaults for enableIf evaluation
3821
3836
  formData: (_b = ctx.formData) != null ? _b : ctx.prefill,
3822
3837
  // Complete root data for enableIf evaluation
3823
3838
  state: ctx.state
@@ -3848,6 +3863,7 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3848
3863
  const min = (_a = element.minCount) != null ? _a : 0;
3849
3864
  const max = (_b = element.maxCount) != null ? _b : Infinity;
3850
3865
  const pre = Array.isArray((_c = ctx.prefill) == null ? void 0 : _c[element.key]) ? ctx.prefill[element.key] : null;
3866
+ const childDefaults = extractChildDefaults(element.elements);
3851
3867
  const countItems = () => itemsWrap.querySelectorAll(":scope > .containerItem").length;
3852
3868
  const createAddButton = () => {
3853
3869
  const add = document.createElement("button");
@@ -3874,7 +3890,8 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3874
3890
  const subCtx = {
3875
3891
  state: ctx.state,
3876
3892
  path: pathJoin(ctx.path, `${element.key}[${idx}]`),
3877
- prefill: {},
3893
+ prefill: childDefaults,
3894
+ // Defaults for enableIf evaluation
3878
3895
  formData: currentFormData
3879
3896
  // Current root data from DOM for enableIf
3880
3897
  };
@@ -3938,10 +3955,12 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3938
3955
  if (pre && Array.isArray(pre)) {
3939
3956
  pre.forEach((prefillObj, idx) => {
3940
3957
  var _a2;
3958
+ const mergedPrefill = mergeWithDefaults(prefillObj || {}, childDefaults);
3941
3959
  const subCtx = {
3942
3960
  state: ctx.state,
3943
3961
  path: pathJoin(ctx.path, `${element.key}[${idx}]`),
3944
- prefill: prefillObj || {},
3962
+ prefill: mergedPrefill,
3963
+ // Merged prefill with defaults for enableIf
3945
3964
  formData: (_a2 = ctx.formData) != null ? _a2 : ctx.prefill
3946
3965
  // Complete root data for enableIf
3947
3966
  };
@@ -3993,7 +4012,8 @@ function renderMultipleContainerElement(element, ctx, wrapper, _pathKey) {
3993
4012
  const subCtx = {
3994
4013
  state: ctx.state,
3995
4014
  path: pathJoin(ctx.path, `${element.key}[${idx}]`),
3996
- prefill: {},
4015
+ prefill: childDefaults,
4016
+ // Defaults for enableIf evaluation
3997
4017
  formData: (_d = ctx.formData) != null ? _d : ctx.prefill
3998
4018
  // Complete root data for enableIf
3999
4019
  };
@@ -4348,13 +4368,14 @@ if (typeof document !== "undefined") {
4348
4368
  });
4349
4369
  }
4350
4370
  function shouldDisableElement(element, ctx) {
4351
- var _a, _b;
4371
+ var _a, _b, _c;
4352
4372
  if (!element.enableIf) {
4353
4373
  return false;
4354
4374
  }
4355
4375
  try {
4356
4376
  const rootFormData = (_b = (_a = ctx.formData) != null ? _a : ctx.prefill) != null ? _b : {};
4357
- const containerData = ctx.path ? getValueByPath(rootFormData, ctx.path) : void 0;
4377
+ const scope = (_c = element.enableIf.scope) != null ? _c : "relative";
4378
+ const containerData = scope === "relative" && ctx.path ? ctx.prefill : void 0;
4358
4379
  const shouldEnable = evaluateEnableCondition(
4359
4380
  element.enableIf,
4360
4381
  rootFormData,