intelicoreact 1.5.10 → 1.5.12
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.
|
@@ -23,6 +23,7 @@ const FormWithDependOn = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
23
23
|
form,
|
|
24
24
|
formId,
|
|
25
25
|
setForm,
|
|
26
|
+
getActualForm: getActualFormOuter,
|
|
26
27
|
onChange,
|
|
27
28
|
renderField,
|
|
28
29
|
getAnotherActions,
|
|
@@ -35,6 +36,7 @@ const FormWithDependOn = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
35
36
|
const [initialForm] = (0, _react.useState)((0, _utils.clone)(form));
|
|
36
37
|
const safelySetForm = typeof setForm === "function" ? setForm : () => {};
|
|
37
38
|
const safelyOnChange = typeof onChange === "function" ? onChange : () => {};
|
|
39
|
+
const getActualForm = typeof getActualFormOuter === "function" ? getActualFormOuter : () => form;
|
|
38
40
|
const {
|
|
39
41
|
assignChangesToField
|
|
40
42
|
} = (0, _useFormFieldsChangesManager.default)({
|
|
@@ -47,7 +49,8 @@ const FormWithDependOn = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
47
49
|
|
|
48
50
|
const anotherActions = typeof getAnotherActions === "function" ? getAnotherActions({
|
|
49
51
|
setForm,
|
|
50
|
-
assign
|
|
52
|
+
assign,
|
|
53
|
+
getActualForm
|
|
51
54
|
}) : {};
|
|
52
55
|
const getMainOfAdditional = (onChange, additionalOfOnChange) => ({
|
|
53
56
|
actions: anotherActions,
|
|
@@ -56,11 +59,13 @@ const FormWithDependOn = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
56
59
|
onChange,
|
|
57
60
|
setForm: safelySetForm,
|
|
58
61
|
assign,
|
|
62
|
+
getActualForm,
|
|
59
63
|
initialForm,
|
|
60
64
|
typeOfUse
|
|
61
65
|
});
|
|
62
66
|
const startDependOn = (0, _utils2.getDependOnStarter)({
|
|
63
|
-
assign
|
|
67
|
+
assign,
|
|
68
|
+
getActualForm
|
|
64
69
|
});
|
|
65
70
|
|
|
66
71
|
// ? Местный handleChange добавляет логику dependOn к верхнему onChange,
|
|
@@ -68,9 +73,13 @@ const FormWithDependOn = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
68
73
|
const handleChange = (newValue, fieldKey, propKey, additionalOfOnChange) => {
|
|
69
74
|
const {
|
|
70
75
|
updatedForm = null,
|
|
71
|
-
isMakeChangesAnyway = false
|
|
76
|
+
isMakeChangesAnyway = false,
|
|
77
|
+
isUseActualForm = false
|
|
72
78
|
} = (0, _utils.getIsOnlyAnObject)(additionalOfOnChange) ? additionalOfOnChange : {};
|
|
73
|
-
const currentForm = (0, _utils.clone)(
|
|
79
|
+
const currentForm = (0, _utils.clone)((() => {
|
|
80
|
+
if (isUseActualForm) return getActualForm();
|
|
81
|
+
return Array.isArray(updatedForm) ? updatedForm : form;
|
|
82
|
+
})());
|
|
74
83
|
const currField = (0, _utils.clone)(currentForm.find(field => field.key === fieldKey));
|
|
75
84
|
|
|
76
85
|
// ? Защита от дублирующих вызовов onChange снизу
|
|
@@ -82,7 +91,10 @@ const FormWithDependOn = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
82
91
|
if (currField[propKey || "value"] === newValue && !isMakeChangesAnyway) return;
|
|
83
92
|
|
|
84
93
|
// ? Сразу же мутируем
|
|
85
|
-
safelyOnChange(newValue, fieldKey, propKey,
|
|
94
|
+
safelyOnChange(newValue, fieldKey, propKey, {
|
|
95
|
+
...additionalOfOnChange,
|
|
96
|
+
updatedForm: currentForm
|
|
97
|
+
});
|
|
86
98
|
|
|
87
99
|
// ? Механика dependOn (обработка зависимостей)
|
|
88
100
|
// ? В текущей реализации отделил от экшена all.
|
|
@@ -139,9 +151,7 @@ const FormWithDependOn = /*#__PURE__*/_react.default.forwardRef((_ref, ref) => {
|
|
|
139
151
|
}, [isInitializeByDependOn]);
|
|
140
152
|
|
|
141
153
|
// ***** output *****
|
|
142
|
-
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
|
|
143
|
-
ref: ref
|
|
144
|
-
}, formId ? {
|
|
154
|
+
return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({}, formId ? {
|
|
145
155
|
id: formId
|
|
146
156
|
} : {}, {
|
|
147
157
|
className: (0, _classnames.default)(RC, className)
|
|
@@ -32,7 +32,7 @@ const getDependOnStarter = props => {
|
|
|
32
32
|
// ! Для звисимого филда есть 2 способа назначить обработчик
|
|
33
33
|
|
|
34
34
|
// ? - прописать в объекте dependOn callback, который будет вызываться для каждой зависимости,
|
|
35
|
-
// ? а уже
|
|
35
|
+
// ? а уже внутри самого колбэка разбираться, для какой имменно зависимости вызван обработчик
|
|
36
36
|
|
|
37
37
|
// ? - прописать в объекте dependOn пропу callbacks, передать в нее объект в формате
|
|
38
38
|
// ? { ... [ключ_доминирующего_поля]: соответствующий_коллбэк, ... }
|