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.js CHANGED
@@ -2025,6 +2025,7 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2025
2025
  initialValues,
2026
2026
  values: initialValues,
2027
2027
  errors: {},
2028
+ partialChanged: {},
2028
2029
  canBack: false,
2029
2030
  canForward: false,
2030
2031
  changedFields: [],
@@ -2039,25 +2040,34 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2039
2040
  },
2040
2041
  resetChangeCount: () => {
2041
2042
  changed.clear();
2042
- set({ changedFields: [], changedCount: 0 });
2043
+ set({ changedFields: [], changedCount: 0, partialChanged: {} });
2043
2044
  },
2044
2045
  setInitialValues: (newInitialValues) => set({ initialValues: newInitialValues }),
2045
2046
  setValue: (path, value, options) => {
2046
- const currentValues = get().values;
2047
+ const state = get();
2048
+ const currentValues = state.values;
2047
2049
  const newValues = setNested(currentValues, path, value);
2048
- const oldValue = getNested(get().initialValues, path);
2050
+ const oldValue = getNested(state.initialValues, path);
2051
+ const hasChanged = value !== oldValue;
2049
2052
  history.push(currentValues);
2050
2053
  future.length = 0;
2051
- if (value !== oldValue) changed.add(path);
2052
- else changed.delete(path);
2054
+ let newPartial = state.partialChanged;
2055
+ if (hasChanged) {
2056
+ changed.add(path);
2057
+ newPartial = setNested(newPartial, path, value);
2058
+ } else {
2059
+ changed.delete(path);
2060
+ newPartial = deleteNested(newPartial, path);
2061
+ }
2053
2062
  set({
2054
2063
  values: newValues,
2064
+ partialChanged: newPartial,
2055
2065
  canBack: history.length > 0,
2056
2066
  canForward: false,
2057
2067
  changedFields: Array.from(changed),
2058
2068
  changedCount: changed.size
2059
2069
  });
2060
- if (options?.validate == false) return;
2070
+ if (options?.validate === false) return;
2061
2071
  const rule = flatRules[path];
2062
2072
  if (!rule) return;
2063
2073
  Promise.resolve(runRule(rule, value, newValues)).then((error2) => {
@@ -2105,6 +2115,7 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2105
2115
  set({
2106
2116
  values: initialValues,
2107
2117
  errors: {},
2118
+ partialChanged: {},
2108
2119
  canBack: false,
2109
2120
  canForward: false,
2110
2121
  changedFields: [],
@@ -2115,14 +2126,19 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2115
2126
  if (!history.length) return;
2116
2127
  const prev = history.pop();
2117
2128
  future.push(get().values);
2118
- changed.clear();
2119
2129
  const initial = get().initialValues;
2120
- for (const key in prev) {
2121
- if (JSON.stringify(prev[key]) !== JSON.stringify(initial[key]))
2122
- changed.add(key);
2130
+ let partial = {};
2131
+ changed.clear();
2132
+ for (const path of Object.keys(flatRules)) {
2133
+ const val = getNested(prev, path);
2134
+ if (val !== getNested(initial, path)) {
2135
+ changed.add(path);
2136
+ partial = setNested(partial, path, val);
2137
+ }
2123
2138
  }
2124
2139
  set({
2125
2140
  values: prev,
2141
+ partialChanged: partial,
2126
2142
  canBack: history.length > 0,
2127
2143
  canForward: true,
2128
2144
  changedFields: Array.from(changed),
@@ -2133,14 +2149,19 @@ function createFormStore(initialValues, validationRules, onSubmit) {
2133
2149
  if (!future.length) return;
2134
2150
  const next = future.pop();
2135
2151
  history.push(get().values);
2136
- changed.clear();
2137
2152
  const initial = get().initialValues;
2138
- for (const key in next) {
2139
- if (JSON.stringify(next[key]) !== JSON.stringify(initial[key]))
2140
- changed.add(key);
2153
+ let partial = {};
2154
+ changed.clear();
2155
+ for (const path of Object.keys(flatRules)) {
2156
+ const val = getNested(next, path);
2157
+ if (val !== getNested(initial, path)) {
2158
+ changed.add(path);
2159
+ partial = setNested(partial, path, val);
2160
+ }
2141
2161
  }
2142
2162
  set({
2143
2163
  values: next,
2164
+ partialChanged: partial,
2144
2165
  canBack: true,
2145
2166
  canForward: future.length > 0,
2146
2167
  changedFields: Array.from(changed),