dirk-cfx-react 1.1.50 → 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/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,
@@ -2170,56 +2185,28 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2170
2185
  if (!history.length) return;
2171
2186
  const prev = history.pop();
2172
2187
  future.push(get().values);
2173
- const initial = get().initialValues;
2174
- let partial = {};
2175
- changed.clear();
2176
- const allKeys = /* @__PURE__ */ new Set([
2177
- ...Object.keys(prev ?? {}),
2178
- ...Object.keys(initial ?? {}),
2179
- ...Object.keys(flatRules)
2180
- ]);
2181
- for (const path of allKeys) {
2182
- const val = getNested(prev, path);
2183
- if (val !== getNested(initial, path)) {
2184
- changed.add(path);
2185
- partial = setNested(partial, path, val);
2186
- }
2187
- }
2188
+ const { fields, partial } = computeChanged(prev, get().initialValues);
2188
2189
  set({
2189
2190
  values: prev,
2190
2191
  partialChanged: partial,
2191
2192
  canBack: history.length > 0,
2192
2193
  canForward: true,
2193
- changedFields: Array.from(changed),
2194
- changedCount: changed.size
2194
+ changedFields: fields,
2195
+ changedCount: fields.length
2195
2196
  });
2196
2197
  },
2197
2198
  forward: () => {
2198
2199
  if (!future.length) return;
2199
2200
  const next = future.pop();
2200
2201
  history.push(get().values);
2201
- const initial = get().initialValues;
2202
- let partial = {};
2203
- changed.clear();
2204
- const allKeys = /* @__PURE__ */ new Set([
2205
- ...Object.keys(next ?? {}),
2206
- ...Object.keys(initial ?? {}),
2207
- ...Object.keys(flatRules)
2208
- ]);
2209
- for (const path of allKeys) {
2210
- const val = getNested(next, path);
2211
- if (val !== getNested(initial, path)) {
2212
- changed.add(path);
2213
- partial = setNested(partial, path, val);
2214
- }
2215
- }
2202
+ const { fields, partial } = computeChanged(next, get().initialValues);
2216
2203
  set({
2217
2204
  values: next,
2218
2205
  partialChanged: partial,
2219
2206
  canBack: true,
2220
2207
  canForward: future.length > 0,
2221
- changedFields: Array.from(changed),
2222
- changedCount: changed.size
2208
+ changedFields: fields,
2209
+ changedCount: fields.length
2223
2210
  });
2224
2211
  }
2225
2212
  }));