@maif/react-forms 1.0.52 → 1.0.55
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/esm/index.js +55 -29
- package/lib/index.js +54 -28
- package/package.json +2 -3
package/lib/esm/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import React, { useState, useEffect, useRef, useImperativeHandle } from 'react';
|
|
|
3
3
|
import { yupResolver } from '@hookform/resolvers/yup';
|
|
4
4
|
import classNames from 'classnames';
|
|
5
5
|
import { Eye, EyeOff, PlusCircle, MinusCircle, Trash2, ChevronDown, ChevronUp, HelpCircle, Loader, Upload } from 'react-feather';
|
|
6
|
-
import {
|
|
6
|
+
import { useFormContext, useController, useForm, FormProvider, Controller, useFieldArray, useWatch } from 'react-hook-form';
|
|
7
7
|
import { DatePicker } from 'react-rainbow-components';
|
|
8
8
|
import ReactToolTip from 'react-tooltip';
|
|
9
9
|
import { v4 } from 'uuid';
|
|
@@ -970,6 +970,9 @@ var valueToSelectOption = function valueToSelectOption(value) {
|
|
|
970
970
|
};
|
|
971
971
|
|
|
972
972
|
var SelectInput = /*#__PURE__*/React.forwardRef(function (props, _) {
|
|
973
|
+
var _useFormContext = useFormContext(),
|
|
974
|
+
getValues = _useFormContext.getValues;
|
|
975
|
+
|
|
973
976
|
var classes = useCustomStyle();
|
|
974
977
|
var possibleValues = (props.possibleValues || []).map(function (v) {
|
|
975
978
|
return props.transformer ? typeof props.transformer === 'function' ? props.transformer(v) : {
|
|
@@ -1009,9 +1012,24 @@ var SelectInput = /*#__PURE__*/React.forwardRef(function (props, _) {
|
|
|
1009
1012
|
|
|
1010
1013
|
if (cond) {
|
|
1011
1014
|
setLoading(true);
|
|
1012
|
-
var promise
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
+
var promise;
|
|
1016
|
+
|
|
1017
|
+
if (isPromise(props.optionsFrom)) {
|
|
1018
|
+
promise = props.optionsFrom;
|
|
1019
|
+
} else if (typeof props.optionsFrom === 'function') {
|
|
1020
|
+
var result = props.optionsFrom({
|
|
1021
|
+
rawValues: getValues(),
|
|
1022
|
+
value: getValues(props.id)
|
|
1023
|
+
});
|
|
1024
|
+
promise = isPromise(result) ? result : props.httpClient(result, 'GET').then(function (r) {
|
|
1025
|
+
return r.json();
|
|
1026
|
+
});
|
|
1027
|
+
} else {
|
|
1028
|
+
promise = props.httpClient(props.optionsFrom, 'GET').then(function (r) {
|
|
1029
|
+
return r.json();
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1015
1033
|
promise.then(function (values) {
|
|
1016
1034
|
return values.map(function (x) {
|
|
1017
1035
|
return props.transformer ? props.transformer(x) : valueToSelectOption(x, values, props.isMulti, props.transformer);
|
|
@@ -28863,18 +28881,28 @@ var buildSubResolver = function buildSubResolver(props, key, dependencies, rawDa
|
|
|
28863
28881
|
return s.condition === ref;
|
|
28864
28882
|
}
|
|
28865
28883
|
});
|
|
28866
|
-
return option(filterSwitch).
|
|
28884
|
+
return option(filterSwitch).orElse(condiSchema["switch"].find(function (s) {
|
|
28867
28885
|
return s["default"];
|
|
28868
|
-
}))
|
|
28869
|
-
|
|
28886
|
+
})).getOrElse({
|
|
28887
|
+
schema: {},
|
|
28888
|
+
flow: []
|
|
28889
|
+
});
|
|
28890
|
+
}).getOrElse({
|
|
28891
|
+
schema: {},
|
|
28892
|
+
flow: []
|
|
28893
|
+
}),
|
|
28870
28894
|
schema = _option$map$getOrElse.schema,
|
|
28871
28895
|
flow = _option$map$getOrElse.flow;
|
|
28872
28896
|
|
|
28873
|
-
var
|
|
28897
|
+
var realFlow = flow || Object.keys(schema);
|
|
28874
28898
|
|
|
28875
|
-
|
|
28876
|
-
|
|
28877
|
-
|
|
28899
|
+
if (realFlow.length) {
|
|
28900
|
+
var _subResolver2 = getShapeAndDependencies(flow || Object.keys(schema), schema, dependencies, rawData);
|
|
28901
|
+
|
|
28902
|
+
return constraints.reduce(function (resolver, constraint) {
|
|
28903
|
+
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
28904
|
+
}, yup.object().shape(_subResolver2.shape, dependencies));
|
|
28905
|
+
}
|
|
28878
28906
|
} else {
|
|
28879
28907
|
return constraints.reduce(function (resolver, constraint) {
|
|
28880
28908
|
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
@@ -28928,12 +28956,7 @@ var CustomizableInput$1 = /*#__PURE__*/React.memo(function (props) {
|
|
|
28928
28956
|
|
|
28929
28957
|
return props.children;
|
|
28930
28958
|
}, function (prev, next) {
|
|
28931
|
-
|
|
28932
|
-
prev: prev,
|
|
28933
|
-
next: next
|
|
28934
|
-
});
|
|
28935
|
-
|
|
28936
|
-
if (next.render) {
|
|
28959
|
+
if (next.render || next.conditionalSchema) {
|
|
28937
28960
|
return false;
|
|
28938
28961
|
}
|
|
28939
28962
|
|
|
@@ -29322,9 +29345,9 @@ var Form = /*#__PURE__*/React.forwardRef(function (_ref7, ref) {
|
|
|
29322
29345
|
initialReseted && trigger();
|
|
29323
29346
|
}, [trigger, initialReseted]);
|
|
29324
29347
|
var _handleSubmit = methods.handleSubmit,
|
|
29325
|
-
_methods$formState = methods.formState
|
|
29326
|
-
|
|
29327
|
-
dirtyFields = _methods$formState.dirtyFields,
|
|
29348
|
+
_methods$formState = methods.formState;
|
|
29349
|
+
_methods$formState.errors;
|
|
29350
|
+
var dirtyFields = _methods$formState.dirtyFields,
|
|
29328
29351
|
_reset = methods.reset,
|
|
29329
29352
|
trigger = methods.trigger,
|
|
29330
29353
|
getValues = methods.getValues,
|
|
@@ -29385,9 +29408,6 @@ var Form = /*#__PURE__*/React.forwardRef(function (_ref7, ref) {
|
|
|
29385
29408
|
return null;
|
|
29386
29409
|
}
|
|
29387
29410
|
|
|
29388
|
-
_typeof$1(entry) === 'object' ? undefined : entry.split('.').reduce(function (object, key) {
|
|
29389
|
-
return object && object[key];
|
|
29390
|
-
}, errors);
|
|
29391
29411
|
var visibleStep = option(step).map(function (s) {
|
|
29392
29412
|
return s.visible;
|
|
29393
29413
|
}).map(function (visible) {
|
|
@@ -30037,7 +30057,7 @@ var ArrayStep = function ArrayStep(_ref11) {
|
|
|
30037
30057
|
};
|
|
30038
30058
|
|
|
30039
30059
|
var NestedForm = function NestedForm(_ref12) {
|
|
30040
|
-
var _classNames17;
|
|
30060
|
+
var _step$conditionalSche, _classNames17;
|
|
30041
30061
|
|
|
30042
30062
|
var schema = _ref12.schema,
|
|
30043
30063
|
flow = _ref12.flow,
|
|
@@ -30054,8 +30074,6 @@ var NestedForm = function NestedForm(_ref12) {
|
|
|
30054
30074
|
getValues = _useFormContext4.getValues,
|
|
30055
30075
|
setValue = _useFormContext4.setValue,
|
|
30056
30076
|
watch = _useFormContext4.watch;
|
|
30057
|
-
_useFormContext4.trigger;
|
|
30058
|
-
_useFormContext4.formState;
|
|
30059
30077
|
|
|
30060
30078
|
var _useState7 = useState(!!step.collapsed),
|
|
30061
30079
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
@@ -30063,6 +30081,7 @@ var NestedForm = function NestedForm(_ref12) {
|
|
|
30063
30081
|
setCollapsed = _useState8[1];
|
|
30064
30082
|
|
|
30065
30083
|
var classes = useCustomStyle();
|
|
30084
|
+
useWatch(step === null || step === void 0 ? void 0 : (_step$conditionalSche = step.conditionalSchema) === null || _step$conditionalSche === void 0 ? void 0 : _step$conditionalSche.ref);
|
|
30066
30085
|
var schemaAndFlow = option(step.conditionalSchema).map(function (condiSchema) {
|
|
30067
30086
|
var ref = option(condiSchema.ref).map(function (ref) {
|
|
30068
30087
|
return getValues(ref);
|
|
@@ -30078,9 +30097,16 @@ var NestedForm = function NestedForm(_ref12) {
|
|
|
30078
30097
|
return s.condition === ref;
|
|
30079
30098
|
}
|
|
30080
30099
|
});
|
|
30081
|
-
|
|
30100
|
+
var schemaAndFlow = option(filterSwitch).orElse(condiSchema["switch"].find(function (s) {
|
|
30082
30101
|
return s["default"];
|
|
30083
|
-
}))
|
|
30102
|
+
})).getOrElse({
|
|
30103
|
+
schema: {},
|
|
30104
|
+
flow: []
|
|
30105
|
+
});
|
|
30106
|
+
return {
|
|
30107
|
+
schema: schemaAndFlow.schema,
|
|
30108
|
+
flow: schemaAndFlow.flow || Object.keys(schemaAndFlow.schema)
|
|
30109
|
+
};
|
|
30084
30110
|
}).getOrElse({
|
|
30085
30111
|
schema: schema,
|
|
30086
30112
|
flow: flow
|
|
@@ -30122,7 +30148,7 @@ var NestedForm = function NestedForm(_ref12) {
|
|
|
30122
30148
|
}, []);
|
|
30123
30149
|
var bordered = computedSandF.filter(function (x) {
|
|
30124
30150
|
return x.visibleStep;
|
|
30125
|
-
}).length
|
|
30151
|
+
}).length >= 1 && step.label !== null;
|
|
30126
30152
|
return /*#__PURE__*/React.createElement("div", {
|
|
30127
30153
|
className: classNames((_classNames17 = {}, _defineProperty$1(_classNames17, classes.nestedform__border, bordered), _defineProperty$1(_classNames17, classes.border__error, !!errorDisplayed), _classNames17)),
|
|
30128
30154
|
style: {
|
package/lib/index.js
CHANGED
|
@@ -1004,6 +1004,9 @@ var valueToSelectOption = function valueToSelectOption(value) {
|
|
|
1004
1004
|
};
|
|
1005
1005
|
|
|
1006
1006
|
var SelectInput = /*#__PURE__*/React__default["default"].forwardRef(function (props, _) {
|
|
1007
|
+
var _useFormContext = reactHookForm.useFormContext(),
|
|
1008
|
+
getValues = _useFormContext.getValues;
|
|
1009
|
+
|
|
1007
1010
|
var classes = useCustomStyle();
|
|
1008
1011
|
var possibleValues = (props.possibleValues || []).map(function (v) {
|
|
1009
1012
|
return props.transformer ? typeof props.transformer === 'function' ? props.transformer(v) : {
|
|
@@ -1043,9 +1046,24 @@ var SelectInput = /*#__PURE__*/React__default["default"].forwardRef(function (pr
|
|
|
1043
1046
|
|
|
1044
1047
|
if (cond) {
|
|
1045
1048
|
setLoading(true);
|
|
1046
|
-
var promise
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
+
var promise;
|
|
1050
|
+
|
|
1051
|
+
if (isPromise(props.optionsFrom)) {
|
|
1052
|
+
promise = props.optionsFrom;
|
|
1053
|
+
} else if (typeof props.optionsFrom === 'function') {
|
|
1054
|
+
var result = props.optionsFrom({
|
|
1055
|
+
rawValues: getValues(),
|
|
1056
|
+
value: getValues(props.id)
|
|
1057
|
+
});
|
|
1058
|
+
promise = isPromise(result) ? result : props.httpClient(result, 'GET').then(function (r) {
|
|
1059
|
+
return r.json();
|
|
1060
|
+
});
|
|
1061
|
+
} else {
|
|
1062
|
+
promise = props.httpClient(props.optionsFrom, 'GET').then(function (r) {
|
|
1063
|
+
return r.json();
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1049
1067
|
promise.then(function (values) {
|
|
1050
1068
|
return values.map(function (x) {
|
|
1051
1069
|
return props.transformer ? props.transformer(x) : valueToSelectOption(x, values, props.isMulti, props.transformer);
|
|
@@ -28897,18 +28915,28 @@ var buildSubResolver = function buildSubResolver(props, key, dependencies, rawDa
|
|
|
28897
28915
|
return s.condition === ref;
|
|
28898
28916
|
}
|
|
28899
28917
|
});
|
|
28900
|
-
return option(filterSwitch).
|
|
28918
|
+
return option(filterSwitch).orElse(condiSchema["switch"].find(function (s) {
|
|
28901
28919
|
return s["default"];
|
|
28902
|
-
}))
|
|
28903
|
-
|
|
28920
|
+
})).getOrElse({
|
|
28921
|
+
schema: {},
|
|
28922
|
+
flow: []
|
|
28923
|
+
});
|
|
28924
|
+
}).getOrElse({
|
|
28925
|
+
schema: {},
|
|
28926
|
+
flow: []
|
|
28927
|
+
}),
|
|
28904
28928
|
schema = _option$map$getOrElse.schema,
|
|
28905
28929
|
flow = _option$map$getOrElse.flow;
|
|
28906
28930
|
|
|
28907
|
-
var
|
|
28931
|
+
var realFlow = flow || Object.keys(schema);
|
|
28908
28932
|
|
|
28909
|
-
|
|
28910
|
-
|
|
28911
|
-
|
|
28933
|
+
if (realFlow.length) {
|
|
28934
|
+
var _subResolver2 = getShapeAndDependencies(flow || Object.keys(schema), schema, dependencies, rawData);
|
|
28935
|
+
|
|
28936
|
+
return constraints.reduce(function (resolver, constraint) {
|
|
28937
|
+
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
28938
|
+
}, yup__namespace.object().shape(_subResolver2.shape, dependencies));
|
|
28939
|
+
}
|
|
28912
28940
|
} else {
|
|
28913
28941
|
return constraints.reduce(function (resolver, constraint) {
|
|
28914
28942
|
return jsonOrFunctionConstraint(constraint, resolver, key, dependencies);
|
|
@@ -28962,12 +28990,7 @@ var CustomizableInput$1 = /*#__PURE__*/React__default["default"].memo(function (
|
|
|
28962
28990
|
|
|
28963
28991
|
return props.children;
|
|
28964
28992
|
}, function (prev, next) {
|
|
28965
|
-
|
|
28966
|
-
prev: prev,
|
|
28967
|
-
next: next
|
|
28968
|
-
});
|
|
28969
|
-
|
|
28970
|
-
if (next.render) {
|
|
28993
|
+
if (next.render || next.conditionalSchema) {
|
|
28971
28994
|
return false;
|
|
28972
28995
|
}
|
|
28973
28996
|
|
|
@@ -29356,9 +29379,9 @@ var Form = /*#__PURE__*/React__default["default"].forwardRef(function (_ref7, re
|
|
|
29356
29379
|
initialReseted && trigger();
|
|
29357
29380
|
}, [trigger, initialReseted]);
|
|
29358
29381
|
var _handleSubmit = methods.handleSubmit,
|
|
29359
|
-
_methods$formState = methods.formState
|
|
29360
|
-
|
|
29361
|
-
dirtyFields = _methods$formState.dirtyFields,
|
|
29382
|
+
_methods$formState = methods.formState;
|
|
29383
|
+
_methods$formState.errors;
|
|
29384
|
+
var dirtyFields = _methods$formState.dirtyFields,
|
|
29362
29385
|
_reset = methods.reset,
|
|
29363
29386
|
trigger = methods.trigger,
|
|
29364
29387
|
getValues = methods.getValues,
|
|
@@ -29419,9 +29442,6 @@ var Form = /*#__PURE__*/React__default["default"].forwardRef(function (_ref7, re
|
|
|
29419
29442
|
return null;
|
|
29420
29443
|
}
|
|
29421
29444
|
|
|
29422
|
-
_typeof$1(entry) === 'object' ? undefined : entry.split('.').reduce(function (object, key) {
|
|
29423
|
-
return object && object[key];
|
|
29424
|
-
}, errors);
|
|
29425
29445
|
var visibleStep = option(step).map(function (s) {
|
|
29426
29446
|
return s.visible;
|
|
29427
29447
|
}).map(function (visible) {
|
|
@@ -30071,7 +30091,7 @@ var ArrayStep = function ArrayStep(_ref11) {
|
|
|
30071
30091
|
};
|
|
30072
30092
|
|
|
30073
30093
|
var NestedForm = function NestedForm(_ref12) {
|
|
30074
|
-
var _classNames17;
|
|
30094
|
+
var _step$conditionalSche, _classNames17;
|
|
30075
30095
|
|
|
30076
30096
|
var schema = _ref12.schema,
|
|
30077
30097
|
flow = _ref12.flow,
|
|
@@ -30088,8 +30108,6 @@ var NestedForm = function NestedForm(_ref12) {
|
|
|
30088
30108
|
getValues = _useFormContext4.getValues,
|
|
30089
30109
|
setValue = _useFormContext4.setValue,
|
|
30090
30110
|
watch = _useFormContext4.watch;
|
|
30091
|
-
_useFormContext4.trigger;
|
|
30092
|
-
_useFormContext4.formState;
|
|
30093
30111
|
|
|
30094
30112
|
var _useState7 = React.useState(!!step.collapsed),
|
|
30095
30113
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
@@ -30097,6 +30115,7 @@ var NestedForm = function NestedForm(_ref12) {
|
|
|
30097
30115
|
setCollapsed = _useState8[1];
|
|
30098
30116
|
|
|
30099
30117
|
var classes = useCustomStyle();
|
|
30118
|
+
reactHookForm.useWatch(step === null || step === void 0 ? void 0 : (_step$conditionalSche = step.conditionalSchema) === null || _step$conditionalSche === void 0 ? void 0 : _step$conditionalSche.ref);
|
|
30100
30119
|
var schemaAndFlow = option(step.conditionalSchema).map(function (condiSchema) {
|
|
30101
30120
|
var ref = option(condiSchema.ref).map(function (ref) {
|
|
30102
30121
|
return getValues(ref);
|
|
@@ -30112,9 +30131,16 @@ var NestedForm = function NestedForm(_ref12) {
|
|
|
30112
30131
|
return s.condition === ref;
|
|
30113
30132
|
}
|
|
30114
30133
|
});
|
|
30115
|
-
|
|
30134
|
+
var schemaAndFlow = option(filterSwitch).orElse(condiSchema["switch"].find(function (s) {
|
|
30116
30135
|
return s["default"];
|
|
30117
|
-
}))
|
|
30136
|
+
})).getOrElse({
|
|
30137
|
+
schema: {},
|
|
30138
|
+
flow: []
|
|
30139
|
+
});
|
|
30140
|
+
return {
|
|
30141
|
+
schema: schemaAndFlow.schema,
|
|
30142
|
+
flow: schemaAndFlow.flow || Object.keys(schemaAndFlow.schema)
|
|
30143
|
+
};
|
|
30118
30144
|
}).getOrElse({
|
|
30119
30145
|
schema: schema,
|
|
30120
30146
|
flow: flow
|
|
@@ -30156,7 +30182,7 @@ var NestedForm = function NestedForm(_ref12) {
|
|
|
30156
30182
|
}, []);
|
|
30157
30183
|
var bordered = computedSandF.filter(function (x) {
|
|
30158
30184
|
return x.visibleStep;
|
|
30159
|
-
}).length
|
|
30185
|
+
}).length >= 1 && step.label !== null;
|
|
30160
30186
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
30161
30187
|
className: classNames__default["default"]((_classNames17 = {}, _defineProperty$1(_classNames17, classes.nestedform__border, bordered), _defineProperty$1(_classNames17, classes.border__error, !!errorDisplayed), _classNames17)),
|
|
30162
30188
|
style: {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maif/react-forms",
|
|
3
3
|
"description": "Build react safe forms as fast as possible",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.55",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
7
7
|
"types": "lib/index.js",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
]
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"react": "^17.0.2"
|
|
59
|
+
"react": "^17.0.2 || 18"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@babel/cli": "^7.17.6",
|
|
@@ -98,7 +98,6 @@
|
|
|
98
98
|
"@codemirror/theme-one-dark": "^0.19.1",
|
|
99
99
|
"@fortawesome/fontawesome-free": "^5.15.3",
|
|
100
100
|
"@hookform/resolvers": "2.4.0",
|
|
101
|
-
"@maif/react-forms": "^1.0.37-rc.1",
|
|
102
101
|
"@popperjs/core": "^2.11.2",
|
|
103
102
|
"@testing-library/jest-dom": "^5.11.4",
|
|
104
103
|
"@testing-library/react": "^11.1.0",
|