@react-typed-forms/schemas 11.0.3 → 11.1.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/lib/index.js CHANGED
@@ -417,6 +417,9 @@ function useUpdatedRef(a) {
417
417
  function isControlReadonly(c) {
418
418
  return isDataControl(c) && !!c.readonly;
419
419
  }
420
+ function isControlDisabled(c) {
421
+ return isDataControl(c) && !!c.disabled;
422
+ }
420
423
  function getDisplayOnlyOptions(d) {
421
424
  return isDataControlDefinition(d) && d.renderOptions && isDisplayOnlyRenderer(d.renderOptions) ? d.renderOptions : undefined;
422
425
  }
@@ -490,17 +493,17 @@ function lookupChildControlPath(data, jsonPath) {
490
493
  var childPath = [].concat(data.path, jsonPath);
491
494
  return watchControlLookup(data.data, childPath);
492
495
  }
493
- function cleanDataForSchema(v, fields) {
496
+ function cleanDataForSchema(v, fields, removeIfDefault) {
494
497
  if (!v) return v;
495
498
  var typeField = fields.find(function (x) {
496
499
  return x.isTypeField;
497
500
  });
498
501
  if (!typeField) return v;
499
502
  var typeValue = v[typeField.field];
500
- var cleanableFields = fields.filter(function (x) {
503
+ var cleanableFields = !removeIfDefault ? fields.filter(function (x) {
501
504
  var _x$onlyForTypes$lengt, _x$onlyForTypes;
502
505
  return isCompoundField(x) || ((_x$onlyForTypes$lengt = (_x$onlyForTypes = x.onlyForTypes) == null ? void 0 : _x$onlyForTypes.length) != null ? _x$onlyForTypes$lengt : 0) > 0;
503
- });
506
+ }) : fields;
504
507
  if (!cleanableFields.length) return v;
505
508
  var out = _extends({}, v);
506
509
  cleanableFields.forEach(function (x) {
@@ -515,15 +518,15 @@ function cleanDataForSchema(v, fields) {
515
518
  if (x.collection) {
516
519
  if (Array.isArray(childValue)) {
517
520
  out[x.field] = childValue.map(function (cv) {
518
- return cleanDataForSchema(cv, childFields);
521
+ return cleanDataForSchema(cv, childFields, removeIfDefault);
519
522
  });
520
523
  }
521
524
  } else {
522
- out[x.field] = cleanDataForSchema(childValue, childFields);
525
+ out[x.field] = cleanDataForSchema(childValue, childFields, removeIfDefault);
523
526
  }
524
527
  }
525
528
  function canBeNull() {
526
- return x.collection && Array.isArray(childValue) && !childValue.length
529
+ return removeIfDefault && x.defaultValue === childValue || x.collection && Array.isArray(childValue) && !childValue.length
527
530
  //|| (x.type === FieldType.Bool && childValue === false)
528
531
  ;
529
532
  }
@@ -957,7 +960,9 @@ function useEvalAllowedOptionsHook(useEvalExpressionHook, definition) {
957
960
  function useEvalDisabledHook(useEvalExpressionHook, definition) {
958
961
  var dynamicDisabled = useEvalDynamicBoolHook(definition, exports.DynamicPropertyType.Disabled, useEvalExpressionHook);
959
962
  return makeDynamicPropertyHook(dynamicDisabled, function () {
960
- return core.useControl(false);
963
+ return core.useComputed(function () {
964
+ return isControlDisabled(definition);
965
+ });
961
966
  }, undefined);
962
967
  }
963
968
  function useEvalDisplayHook(useEvalExpressionHook, definition) {
@@ -2806,6 +2811,7 @@ exports.htmlDisplayControl = htmlDisplayControl;
2806
2811
  exports.intField = intField;
2807
2812
  exports.isActionControlsDefinition = isActionControlsDefinition;
2808
2813
  exports.isCompoundField = isCompoundField;
2814
+ exports.isControlDisabled = isControlDisabled;
2809
2815
  exports.isControlReadonly = isControlReadonly;
2810
2816
  exports.isDataControl = isDataControl;
2811
2817
  exports.isDataControlDefinition = isDataControlDefinition;