dirk-cfx-react 1.1.14 → 1.1.15

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
@@ -2034,6 +2034,7 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2034
2034
  initialValues,
2035
2035
  values: initialValues,
2036
2036
  errors: {},
2037
+ partialChanged: {},
2037
2038
  canBack: false,
2038
2039
  canForward: false,
2039
2040
  changedFields: [],
@@ -2048,25 +2049,34 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2048
2049
  },
2049
2050
  resetChangeCount: () => {
2050
2051
  changed.clear();
2051
- set({ changedFields: [], changedCount: 0 });
2052
+ set({ changedFields: [], changedCount: 0, partialChanged: {} });
2052
2053
  },
2053
2054
  setInitialValues: (newInitialValues) => set({ initialValues: newInitialValues }),
2054
2055
  setValue: (path, value, options) => {
2055
- const currentValues = get().values;
2056
+ const state = get();
2057
+ const currentValues = state.values;
2056
2058
  const newValues = setNested(currentValues, path, value);
2057
- const oldValue = getNested(get().initialValues, path);
2059
+ const oldValue = getNested(state.initialValues, path);
2060
+ const hasChanged = value !== oldValue;
2058
2061
  history.push(currentValues);
2059
2062
  future.length = 0;
2060
- if (value !== oldValue) changed.add(path);
2061
- else changed.delete(path);
2063
+ let newPartial = state.partialChanged;
2064
+ if (hasChanged) {
2065
+ changed.add(path);
2066
+ newPartial = setNested(newPartial, path, value);
2067
+ } else {
2068
+ changed.delete(path);
2069
+ newPartial = deleteNested(newPartial, path);
2070
+ }
2062
2071
  set({
2063
2072
  values: newValues,
2073
+ partialChanged: newPartial,
2064
2074
  canBack: history.length > 0,
2065
2075
  canForward: false,
2066
2076
  changedFields: Array.from(changed),
2067
2077
  changedCount: changed.size
2068
2078
  });
2069
- if (options?.validate == false) return;
2079
+ if (options?.validate === false) return;
2070
2080
  const rule = flatRules[path];
2071
2081
  if (!rule) return;
2072
2082
  Promise.resolve(runRule(rule, value, newValues)).then((error2) => {
@@ -2114,6 +2124,7 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2114
2124
  set({
2115
2125
  values: initialValues,
2116
2126
  errors: {},
2127
+ partialChanged: {},
2117
2128
  canBack: false,
2118
2129
  canForward: false,
2119
2130
  changedFields: [],
@@ -2124,14 +2135,19 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2124
2135
  if (!history.length) return;
2125
2136
  const prev = history.pop();
2126
2137
  future.push(get().values);
2127
- changed.clear();
2128
2138
  const initial = get().initialValues;
2129
- for (const key in prev) {
2130
- if (JSON.stringify(prev[key]) !== JSON.stringify(initial[key]))
2131
- changed.add(key);
2139
+ let partial = {};
2140
+ changed.clear();
2141
+ for (const path of Object.keys(flatRules)) {
2142
+ const val = getNested(prev, path);
2143
+ if (val !== getNested(initial, path)) {
2144
+ changed.add(path);
2145
+ partial = setNested(partial, path, val);
2146
+ }
2132
2147
  }
2133
2148
  set({
2134
2149
  values: prev,
2150
+ partialChanged: partial,
2135
2151
  canBack: history.length > 0,
2136
2152
  canForward: true,
2137
2153
  changedFields: Array.from(changed),
@@ -2142,14 +2158,19 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2142
2158
  if (!future.length) return;
2143
2159
  const next = future.pop();
2144
2160
  history.push(get().values);
2145
- changed.clear();
2146
2161
  const initial = get().initialValues;
2147
- for (const key in next) {
2148
- if (JSON.stringify(next[key]) !== JSON.stringify(initial[key]))
2149
- changed.add(key);
2162
+ let partial = {};
2163
+ changed.clear();
2164
+ for (const path of Object.keys(flatRules)) {
2165
+ const val = getNested(next, path);
2166
+ if (val !== getNested(initial, path)) {
2167
+ changed.add(path);
2168
+ partial = setNested(partial, path, val);
2169
+ }
2150
2170
  }
2151
2171
  set({
2152
2172
  values: next,
2173
+ partialChanged: partial,
2153
2174
  canBack: true,
2154
2175
  canForward: future.length > 0,
2155
2176
  changedFields: Array.from(changed),