@react-typed-forms/schemas 11.0.0 → 11.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.
@@ -155,7 +155,7 @@ export interface ControlRenderOptions extends FormContextOptions {
155
155
  }
156
156
  export declare function useControlRenderer(definition: ControlDefinition, fields: SchemaField[], renderer: FormRenderer, options?: ControlRenderOptions): FC<ControlRenderProps>;
157
157
  export declare function lookupSchemaField(c: ControlDefinition, fields: SchemaField[]): SchemaField[] | undefined;
158
- export declare function getControlData(fieldPath: SchemaField[] | undefined, parentContext: ControlDataContext, elementIndex: number | undefined): [Control<any> | undefined, Control<any> | undefined, ControlDataContext];
158
+ export declare function getControlData(fieldPath: SchemaField[] | undefined, parentContext: ControlDataContext, elementIndex: number | undefined): [Control<any>, Control<any> | undefined, ControlDataContext];
159
159
  export declare function ControlRenderer({ definition, fields, renderer, options, control, parentPath, }: {
160
160
  definition: ControlDefinition;
161
161
  fields: SchemaField[];
package/lib/index.js CHANGED
@@ -1366,7 +1366,7 @@ function useControlRenderer(definition, fields, renderer, options) {
1366
1366
  control = _getControlData[1],
1367
1367
  controlDataContext = _getControlData[2];
1368
1368
  core.useControlEffect(function () {
1369
- return [visibility.value, defaultValueControl.value, control, isDataControlDefinition(definition) && definition.dontClearHidden, parentControl == null ? void 0 : parentControl.isNull, _options.hidden];
1369
+ return [visibility.value, defaultValueControl.value, control, isDataControlDefinition(definition) && definition.dontClearHidden, parentControl.isNull, _options.hidden];
1370
1370
  }, function (_ref2) {
1371
1371
  var vc = _ref2[0],
1372
1372
  dv = _ref2[1],
@@ -1383,8 +1383,10 @@ function useControlRenderer(definition, fields, renderer, options) {
1383
1383
  cd.value = dv;
1384
1384
  }
1385
1385
  }
1386
- if (parentNull && parentControl != null && parentControl.isNull) {
1387
- parentControl.value = {};
1386
+ if (parentNull) {
1387
+ parentControl.setValue(function (x) {
1388
+ return x != null ? x : {};
1389
+ });
1388
1390
  }
1389
1391
  }, true);
1390
1392
  var myOptions = core.useCalculatedControl(function () {
@@ -1402,7 +1404,7 @@ function useControlRenderer(definition, fields, renderer, options) {
1402
1404
  React.useEffect(function () {
1403
1405
  if (control && typeof myOptions.disabled === "boolean") control.disabled = myOptions.disabled;
1404
1406
  }, [control, myOptions.disabled]);
1405
- if (parentControl != null && parentControl.isNull) return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null);
1407
+ if (parentControl.isNull) return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null);
1406
1408
  var adornments = (_definition$adornment = (_definition$adornment2 = definition.adornments) == null ? void 0 : _definition$adornment2.map(function (x) {
1407
1409
  return renderer.renderAdornment({
1408
1410
  adornment: x
@@ -1472,14 +1474,35 @@ function getControlData(fieldPath, parentContext, elementIndex) {
1472
1474
  })) != null ? _fieldPath$slice$map : [];
1473
1475
  var path = [].concat(pp, extraPath);
1474
1476
  var schemaField = fieldPath == null ? void 0 : fieldPath.at(-1);
1475
- var parentControl = data.lookupControl(path);
1477
+ var _lookupControl = lookupControl(data, path),
1478
+ parentControl = _lookupControl[0],
1479
+ found = _lookupControl[1];
1476
1480
  var childPath = schemaField ? elementIndex != null ? [].concat(path, [schemaField.field, elementIndex]) : [].concat(path, [schemaField.field]) : path;
1477
- var childControl = schemaField && parentControl ? (_parentControl$fields = parentControl.fields) == null ? void 0 : _parentControl$fields[schemaField.field] : undefined;
1481
+ var childControl = schemaField && found ? (_parentControl$fields = parentControl.fields) == null ? void 0 : _parentControl$fields[schemaField.field] : undefined;
1478
1482
  return [parentControl, childControl && elementIndex != null ? (_childControl$element = childControl.elements) == null ? void 0 : _childControl$element[elementIndex] : childControl, schemaField ? _extends({}, parentContext, {
1479
1483
  path: childPath,
1480
1484
  fields: isCompoundField(schemaField) ? schemaField.children : parentContext.fields
1481
1485
  }) : parentContext];
1482
1486
  }
1487
+ function lookupControl(control, path) {
1488
+ var _base;
1489
+ var base = control;
1490
+ var index = 0;
1491
+ while (index < path.length && base) {
1492
+ control = base;
1493
+ var childId = path[index];
1494
+ var c = base.current;
1495
+ if (typeof childId === "string") {
1496
+ var _c$fields;
1497
+ base = (_c$fields = c.fields) == null ? void 0 : _c$fields[childId];
1498
+ } else {
1499
+ var _c$elements;
1500
+ base = (_c$elements = c.elements) == null ? void 0 : _c$elements[childId];
1501
+ }
1502
+ index++;
1503
+ }
1504
+ return [(_base = base) != null ? _base : control, !!base];
1505
+ }
1483
1506
  function ControlRenderer(_ref3) {
1484
1507
  var _effect = core.useComponentTracking();
1485
1508
  try {