@react-typed-forms/schemas 11.14.1 → 11.15.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.
@@ -18,6 +18,9 @@ export interface FormRenderer {
18
18
  }
19
19
  export interface AdornmentProps {
20
20
  adornment: ControlAdornment;
21
+ dataContext?: ControlDataContext;
22
+ parentContext: ControlDataContext;
23
+ useExpr?: UseEvalExpressionHook;
21
24
  designMode?: boolean;
22
25
  }
23
26
  export declare const AppendAdornmentPriority = 0;
package/lib/index.js CHANGED
@@ -75,6 +75,7 @@ exports.ControlAdornmentType = void 0;
75
75
  ControlAdornmentType["Accordion"] = "Accordion";
76
76
  ControlAdornmentType["HelpText"] = "HelpText";
77
77
  ControlAdornmentType["Icon"] = "Icon";
78
+ ControlAdornmentType["SetField"] = "SetField";
78
79
  })(exports.ControlAdornmentType || (exports.ControlAdornmentType = {}));
79
80
  exports.DataRenderType = void 0;
80
81
  (function (DataRenderType) {
@@ -1570,7 +1571,10 @@ function useControlRenderer(definition, fields, renderer, options) {
1570
1571
  if (parentControl.isNull) return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null);
1571
1572
  var adornments = (_definition$adornment = (_definition$adornment2 = definition.adornments) == null ? void 0 : _definition$adornment2.map(function (x) {
1572
1573
  return renderer.renderAdornment({
1573
- adornment: x
1574
+ adornment: x,
1575
+ dataContext: controlDataContext,
1576
+ parentContext: parentDataContext,
1577
+ useExpr: useExpr
1574
1578
  });
1575
1579
  })) != null ? _definition$adornment : [];
1576
1580
  var labelAndChildren = renderControlLayout({
@@ -1977,6 +1981,9 @@ function isIconAdornment(a) {
1977
1981
  function isAccordionAdornment(a) {
1978
1982
  return a.type === exports.ControlAdornmentType.Accordion;
1979
1983
  }
1984
+ function isSetFieldAdornment(a) {
1985
+ return a.type === exports.ControlAdornmentType.SetField;
1986
+ }
1980
1987
  function createLayoutRenderer(render, options) {
1981
1988
  return _extends({
1982
1989
  type: "layout",
@@ -2912,9 +2919,46 @@ function createDefaultAdornmentRenderer(options) {
2912
2919
  type: "adornment",
2913
2920
  render: function render(_ref6, renderers) {
2914
2921
  var adornment = _ref6.adornment,
2915
- designMode = _ref6.designMode;
2922
+ designMode = _ref6.designMode,
2923
+ parentContext = _ref6.parentContext,
2924
+ useExpr = _ref6.useExpr;
2916
2925
  return {
2917
2926
  apply: function apply(rl) {
2927
+ if (isSetFieldAdornment(adornment) && useExpr) {
2928
+ var setFieldWrapper = function setFieldWrapper(_ref7) {
2929
+ var children = _ref7.children,
2930
+ adornment = _ref7.adornment,
2931
+ parentContext = _ref7.parentContext;
2932
+ var _dynamicHooks = dynamicHooks(parentContext),
2933
+ value = _dynamicHooks.value;
2934
+ var refField = findFieldPath(parentContext.fields, adornment.field);
2935
+ var otherField = refField ? lookupChildControl(parentContext, refField) : undefined;
2936
+ var always = !adornment.defaultOnly;
2937
+ core.useControlEffect(function () {
2938
+ return [value == null ? void 0 : value.value, (otherField == null ? void 0 : otherField.value) == null];
2939
+ }, function (_ref8) {
2940
+ var v = _ref8[0];
2941
+ otherField == null || otherField.setValue(function (x) {
2942
+ return always || x == null ? v : x;
2943
+ });
2944
+ }, true);
2945
+ return children;
2946
+ };
2947
+ var hook = useExpr(adornment.expression, function (x) {
2948
+ return x;
2949
+ });
2950
+ var dynamicHooks = useDynamicHooks({
2951
+ value: hook
2952
+ });
2953
+ var _SetFieldWrapper = React.useCallback(setFieldWrapper, [dynamicHooks]);
2954
+ return wrapLayout(function (x) {
2955
+ return /*#__PURE__*/React__default["default"].createElement(_SetFieldWrapper, {
2956
+ children: x,
2957
+ parentContext: parentContext,
2958
+ adornment: adornment
2959
+ });
2960
+ })(rl);
2961
+ }
2918
2962
  if (isIconAdornment(adornment)) {
2919
2963
  var _adornment$placement;
2920
2964
  return appendMarkupAt((_adornment$placement = adornment.placement) != null ? _adornment$placement : exports.AdornmentPlacement.ControlStart, /*#__PURE__*/React__default["default"].createElement("i", {
@@ -3278,6 +3322,7 @@ exports.isGroupControl = isGroupControl;
3278
3322
  exports.isGroupControlsDefinition = isGroupControlsDefinition;
3279
3323
  exports.isIconAdornment = isIconAdornment;
3280
3324
  exports.isScalarField = isScalarField;
3325
+ exports.isSetFieldAdornment = isSetFieldAdornment;
3281
3326
  exports.isTextfieldRenderer = isTextfieldRenderer;
3282
3327
  exports.jsonPathString = jsonPathString;
3283
3328
  exports.jsonataExpr = jsonataExpr;