dirk-cfx-react 1.1.51 → 1.1.52
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/dist/hooks/index.cjs +28 -25
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.js +28 -25
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +28 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2041,6 +2041,21 @@ function createFormStore(initialValues, validationRules, onSubmit) {
|
|
|
2041
2041
|
const history = [];
|
|
2042
2042
|
const future = [];
|
|
2043
2043
|
const changed = /* @__PURE__ */ new Set();
|
|
2044
|
+
function computeChanged(values, initialVals) {
|
|
2045
|
+
const allKeys = /* @__PURE__ */ new Set([
|
|
2046
|
+
...Object.keys(values),
|
|
2047
|
+
...Object.keys(initialVals)
|
|
2048
|
+
]);
|
|
2049
|
+
const fields = [];
|
|
2050
|
+
let partial = {};
|
|
2051
|
+
for (const key of allKeys) {
|
|
2052
|
+
if (values[key] !== initialVals[key]) {
|
|
2053
|
+
fields.push(key);
|
|
2054
|
+
partial = setNested(partial, key, values[key]);
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
return { fields, partial };
|
|
2058
|
+
}
|
|
2044
2059
|
return zustand.createStore((set, get) => ({
|
|
2045
2060
|
initialValues,
|
|
2046
2061
|
values: initialValues,
|
|
@@ -2078,7 +2093,7 @@ function createFormStore(initialValues, validationRules, onSubmit) {
|
|
|
2078
2093
|
const newValues = setNested(currentValues, path, value);
|
|
2079
2094
|
const oldValue = getNested(state.initialValues, path);
|
|
2080
2095
|
const hasChanged = value !== oldValue;
|
|
2081
|
-
history.push(
|
|
2096
|
+
history.push(currentValues);
|
|
2082
2097
|
future.length = 0;
|
|
2083
2098
|
let newPartial = state.partialChanged;
|
|
2084
2099
|
if (hasChanged) {
|
|
@@ -2168,42 +2183,30 @@ function createFormStore(initialValues, validationRules, onSubmit) {
|
|
|
2168
2183
|
},
|
|
2169
2184
|
back: () => {
|
|
2170
2185
|
if (!history.length) return;
|
|
2171
|
-
const
|
|
2172
|
-
future.push(
|
|
2173
|
-
|
|
2174
|
-
for (const f of entry.changed) changed.add(f);
|
|
2175
|
-
let partial = {};
|
|
2176
|
-
for (const path of changed) {
|
|
2177
|
-
const val = getNested(entry.values, path);
|
|
2178
|
-
partial = setNested(partial, path, val);
|
|
2179
|
-
}
|
|
2186
|
+
const prev = history.pop();
|
|
2187
|
+
future.push(get().values);
|
|
2188
|
+
const { fields, partial } = computeChanged(prev, get().initialValues);
|
|
2180
2189
|
set({
|
|
2181
|
-
values:
|
|
2190
|
+
values: prev,
|
|
2182
2191
|
partialChanged: partial,
|
|
2183
2192
|
canBack: history.length > 0,
|
|
2184
2193
|
canForward: true,
|
|
2185
|
-
changedFields:
|
|
2186
|
-
changedCount:
|
|
2194
|
+
changedFields: fields,
|
|
2195
|
+
changedCount: fields.length
|
|
2187
2196
|
});
|
|
2188
2197
|
},
|
|
2189
2198
|
forward: () => {
|
|
2190
2199
|
if (!future.length) return;
|
|
2191
|
-
const
|
|
2192
|
-
history.push(
|
|
2193
|
-
|
|
2194
|
-
for (const f of entry.changed) changed.add(f);
|
|
2195
|
-
let partial = {};
|
|
2196
|
-
for (const path of changed) {
|
|
2197
|
-
const val = getNested(entry.values, path);
|
|
2198
|
-
partial = setNested(partial, path, val);
|
|
2199
|
-
}
|
|
2200
|
+
const next = future.pop();
|
|
2201
|
+
history.push(get().values);
|
|
2202
|
+
const { fields, partial } = computeChanged(next, get().initialValues);
|
|
2200
2203
|
set({
|
|
2201
|
-
values:
|
|
2204
|
+
values: next,
|
|
2202
2205
|
partialChanged: partial,
|
|
2203
2206
|
canBack: true,
|
|
2204
2207
|
canForward: future.length > 0,
|
|
2205
|
-
changedFields:
|
|
2206
|
-
changedCount:
|
|
2208
|
+
changedFields: fields,
|
|
2209
|
+
changedCount: fields.length
|
|
2207
2210
|
});
|
|
2208
2211
|
}
|
|
2209
2212
|
}));
|