@react-typed-forms/schemas 16.0.0 → 16.0.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.
package/lib/index.js CHANGED
@@ -32,10 +32,9 @@ function _objectWithoutPropertiesLoose(r, e) {
32
32
  * @returns The record with default values applied.
33
33
  */
34
34
  function applyDefaultValues(v, fields, doneSet) {
35
- var _doneSet;
36
35
  if (!v) return defaultValueForFields(fields);
37
36
  if (doneSet && doneSet.has(v)) return v;
38
- (_doneSet = doneSet) != null ? _doneSet : doneSet = new Set();
37
+ doneSet != null ? doneSet : doneSet = new Set();
39
38
  doneSet.add(v);
40
39
  const applyValue = fields.filter(x => isCompoundField(x) || !(x.field in v));
41
40
  if (!applyValue.length) return v;
@@ -312,10 +311,7 @@ function addMissingControlsForSchema(schema, controls, warning) {
312
311
  children: [],
313
312
  parent: parentNode
314
313
  };
315
- entry.children = (_c$children$map = (_c$children = c.children) == null ? void 0 : _c$children.map(x => {
316
- var _dataSchema;
317
- return toControlAndSchema(x, (_dataSchema = dataSchema) != null ? _dataSchema : parentSchema, entry, dontRegister);
318
- })) != null ? _c$children$map : [];
314
+ entry.children = (_c$children$map = (_c$children = c.children) == null ? void 0 : _c$children.map(x => toControlAndSchema(x, dataSchema != null ? dataSchema : parentSchema, entry, dontRegister))) != null ? _c$children$map : [];
319
315
  if (!dontRegister && c.id) controlMap[c.id] = entry;
320
316
  if (dataSchema) {
321
317
  addSchemaMapEntry(dataSchema.id, entry);
@@ -597,6 +593,9 @@ function getNullToggler(c) {
597
593
  c.value = currentNotNull ? lastDefined.current.value : null;
598
594
  c.disabled = !currentNotNull;
599
595
  }, ControlChange.Value);
596
+ c.subscribe(() => {
597
+ notNull.value = c.current.value != null;
598
+ }, ControlChange.Value);
600
599
  return notNull;
601
600
  function disableIfNotEditing() {
602
601
  notNull.disabled = isEditing.current.value === false;
@@ -632,6 +631,20 @@ function getIsEditing(control) {
632
631
  function getAllValues(control) {
633
632
  return ensureMetaValue(control, "$allValues", () => newControl([control.value]));
634
633
  }
634
+ function clearMultiValues(dataNode) {
635
+ const c = dataNode.control;
636
+ const sf = dataNode.schema.field;
637
+ if (sf.collection) {
638
+ return;
639
+ } else if (isCompoundField(sf)) {
640
+ dataNode.schema.getChildNodes().forEach(c => {
641
+ clearMultiValues(dataNode.getChild(c));
642
+ });
643
+ } else {
644
+ const allValues = getAllValues(c);
645
+ allValues.setValue(x => [c.current.value]);
646
+ }
647
+ }
635
648
  function applyValues(dataNode, value) {
636
649
  const c = dataNode.control;
637
650
  const sf = dataNode.schema.field;
@@ -650,7 +663,10 @@ function applyValues(dataNode, value) {
650
663
  }
651
664
  function collectDifferences(dataNode, values) {
652
665
  values.forEach((v, i) => {
653
- if (i == 0) dataNode.control.setInitialValue(v);else applyValues(dataNode, v);
666
+ if (i == 0) {
667
+ dataNode.control.setInitialValue(v);
668
+ clearMultiValues(dataNode);
669
+ } else applyValues(dataNode, v);
654
670
  });
655
671
  const allEdits = [];
656
672
  resetMultiValues(dataNode);
@@ -1691,5 +1707,5 @@ function useControlRenderer(definition, fields, renderer, options = {}) {
1691
1707
  }, [r]);
1692
1708
  }
1693
1709
 
1694
- export { AppendAdornmentPriority, ControlRenderer, LabelType, NewControlRenderer, RenderForm, WrapAdornmentPriority, accordionOptions, actionControl, actionHandlers, addMissingControls, addMissingControlsForSchema, adornmentOptions, appendMarkup, appendMarkupAt, applyArrayLengthRestrictions, applyDefaultForField, applyDefaultValues, applyExtensionToSchema, applyExtensionsToSchema, applyLengthRestrictions, applyValues, autocompleteOptions, checkListOptions, cleanDataForSchema, coerceToString, collectDifferences, compoundControl, controlTitle, createAction, createActionRenderer, createAdornmentRenderer, createArrayActions, createArrayRenderer, createDataRenderer, createDisplayRenderer, createFormRenderer, createGroupRenderer, createLabelRenderer, createLayoutRenderer, createVisibilityRenderer, dataControl, dateValidatorOptions, deepMerge, defaultControlForField, defaultDataProps, defaultValueForField, defaultValueForFields, displayOnlyOptions, dynamicDefaultValue, dynamicDisabled, dynamicReadonly, dynamicVisibility, elementValueForField, emptyGroupDefinition, fieldDisplayName, fieldEqExpr, fieldExpr, fieldHasTag, fieldOptionAdornment, findChildDefinition, findCompoundField, findControlsForCompound, findFieldPath, findNonDataGroups, findScalarField, getAllReferencedClasses, getAllValues, getDiffObject, getExternalEditData, getGroupClassOverrides, getIsEditing, getLastDefinedValue, getLengthRestrictions, getNullToggler, getOverrideClass, groupedControl, hasOptions, htmlDisplayControl, isAccordionAdornment, isIconAdornment, isOptionalAdornment, isSetFieldAdornment, jsonataExpr, jsonataOptions, jsonataValidatorOptions, layoutKeyForPlacement, lengthValidatorOptions, lookupChildDataContext, mergeObjects, radioButtonOptions, renderControlLayout, renderLayoutParts, renderOptionsFor, rendererClass, textDisplayControl, textfieldOptions, useControlDefinitionForSchema, useControlRenderer, useControlRendererComponent, useExpression, useUpdatedRef, validationVisitor, validatorOptions, wrapLayout, wrapMarkup, wrapMarkupAt };
1710
+ export { AppendAdornmentPriority, ControlRenderer, LabelType, NewControlRenderer, RenderForm, WrapAdornmentPriority, accordionOptions, actionControl, actionHandlers, addMissingControls, addMissingControlsForSchema, adornmentOptions, appendMarkup, appendMarkupAt, applyArrayLengthRestrictions, applyDefaultForField, applyDefaultValues, applyExtensionToSchema, applyExtensionsToSchema, applyLengthRestrictions, applyValues, autocompleteOptions, checkListOptions, cleanDataForSchema, clearMultiValues, coerceToString, collectDifferences, compoundControl, controlTitle, createAction, createActionRenderer, createAdornmentRenderer, createArrayActions, createArrayRenderer, createDataRenderer, createDisplayRenderer, createFormRenderer, createGroupRenderer, createLabelRenderer, createLayoutRenderer, createVisibilityRenderer, dataControl, dateValidatorOptions, deepMerge, defaultControlForField, defaultDataProps, defaultValueForField, defaultValueForFields, displayOnlyOptions, dynamicDefaultValue, dynamicDisabled, dynamicReadonly, dynamicVisibility, elementValueForField, emptyGroupDefinition, fieldDisplayName, fieldEqExpr, fieldExpr, fieldHasTag, fieldOptionAdornment, findChildDefinition, findCompoundField, findControlsForCompound, findFieldPath, findNonDataGroups, findScalarField, getAllReferencedClasses, getAllValues, getDiffObject, getExternalEditData, getGroupClassOverrides, getIsEditing, getLastDefinedValue, getLengthRestrictions, getNullToggler, getOverrideClass, groupedControl, hasOptions, htmlDisplayControl, isAccordionAdornment, isIconAdornment, isOptionalAdornment, isSetFieldAdornment, jsonataExpr, jsonataOptions, jsonataValidatorOptions, layoutKeyForPlacement, lengthValidatorOptions, lookupChildDataContext, mergeObjects, radioButtonOptions, renderControlLayout, renderLayoutParts, renderOptionsFor, rendererClass, textDisplayControl, textfieldOptions, useControlDefinitionForSchema, useControlRenderer, useControlRendererComponent, useExpression, useUpdatedRef, validationVisitor, validatorOptions, wrapLayout, wrapMarkup, wrapMarkupAt };
1695
1711
  //# sourceMappingURL=index.js.map