@strictly/react-form 0.0.26 → 0.0.27

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.
@@ -7,12 +7,12 @@ $ tsup
7
7
  CLI Target: es6
8
8
  CJS Build start
9
9
  ESM Build start
10
- ESM dist/index.js 59.53 KB
11
- ESM ⚡️ Build success in 105ms
12
- CJS dist/index.cjs 63.62 KB
13
- CJS ⚡️ Build success in 110ms
10
+ CJS dist/index.cjs 63.79 KB
11
+ CJS ⚡️ Build success in 126ms
12
+ ESM dist/index.js 59.70 KB
13
+ ESM ⚡️ Build success in 132ms
14
14
  DTS Build start
15
- DTS ⚡️ Build success in 30914ms
16
- DTS dist/index.d.cts 38.03 KB
17
- DTS dist/index.d.ts 38.03 KB
18
- Done in 32.12s.
15
+ DTS ⚡️ Build success in 32334ms
16
+ DTS dist/index.d.cts 38.14 KB
17
+ DTS dist/index.d.ts 38.14 KB
18
+ Done in 33.47s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ tsc -b
3
- Done in 0.43s.
3
+ Done in 0.40s.
@@ -599,6 +599,8 @@ export abstract class FormModel<
599
599
  const validation = this.validation[fromJsonPath]
600
600
  delete this.validation[fromJsonPath]
601
601
  this.validation[toJsonPath] = validation
602
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
603
+ this.moveListItem(fromJsonPath as any, toJsonPath as any)
602
604
  })
603
605
  accessor.set(newList)
604
606
  // delete any value overrides so the new list isn't shadowed
@@ -608,6 +610,13 @@ export abstract class FormModel<
608
610
  })
609
611
  }
610
612
 
613
+ protected moveListItem<K extends keyof FlattenedListTypesOfType<T>>(fromValuePath: K, toValuePath: K) {
614
+ // do nothing, this is for subclasses to override
615
+ // put in some nonsense so TS doesn't complain about the parameters not being used
616
+ fromValuePath satisfies K
617
+ toValuePath satisfies K
618
+ }
619
+
611
620
  private internalSetFieldValue<K extends keyof ValuePathsToAdapters>(
612
621
  valuePath: K,
613
622
  value: ToOfFieldAdapter<ValuePathsToAdapters[K]>,
@@ -66,8 +66,8 @@ export function useDefaultMobxFormHooks<
66
66
  // (e.g. changing a discriminator)
67
67
  // TODO debounce?
68
68
  setTimeout(function () {
69
- // only start validation if the user has changed the field
70
- if (model.isValuePathActive(path) && model.isFieldDirty(path)) {
69
+ // only start validation if the user has changed the field and there isn't already an error visible
70
+ if (model.isValuePathActive(path) && model.isFieldDirty(path) && model.fields[path].error == null) {
71
71
  // further workaround to make sure we don't downgrade the existing validation
72
72
  model.validateField(path, Math.max(Validation.Changed, model.getValidation(path)))
73
73
  }
package/dist/index.cjs CHANGED
@@ -720,12 +720,17 @@ var FormModel = class {
720
720
  const validation = this.validation[fromJsonPath];
721
721
  delete this.validation[fromJsonPath];
722
722
  this.validation[toJsonPath] = validation;
723
+ this.moveListItem(fromJsonPath, toJsonPath);
723
724
  });
724
725
  accessor.set(newList);
725
726
  delete this.fieldOverrides[listValuePath];
726
727
  });
727
728
  });
728
729
  }
730
+ moveListItem(fromValuePath, toValuePath) {
731
+ fromValuePath;
732
+ toValuePath;
733
+ }
729
734
  internalSetFieldValue(valuePath, value, validation) {
730
735
  const { revert } = this.getAdapterForValuePath(valuePath);
731
736
  (0, import_base2.assertExists)(revert, "setting value not supported {}", valuePath);
@@ -915,7 +920,7 @@ function useDefaultMobxFormHooks(model, {
915
920
  const onFieldBlur = (0, import_react.useCallback)(
916
921
  function(path) {
917
922
  setTimeout(function() {
918
- if (model.isValuePathActive(path) && model.isFieldDirty(path)) {
923
+ if (model.isValuePathActive(path) && model.isFieldDirty(path) && model.fields[path].error == null) {
919
924
  model.validateField(path, Math.max(1 /* Changed */, model.getValidation(path)));
920
925
  }
921
926
  }, 100);
package/dist/index.d.cts CHANGED
@@ -157,6 +157,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
157
157
  setFieldValue<K extends keyof ValuePathsToAdapters>(valuePath: K, value: ToOfFieldAdapter<ValuePathsToAdapters[K]>, validation?: Validation): boolean;
158
158
  addListItem<K extends keyof FlattenedListTypesOfType<T>>(valuePath: K, elementValue?: Maybe<ElementOfArray<FlattenedValuesOfType<T>[K]>>, index?: number): void;
159
159
  removeListItem<K extends keyof FlattenedListTypesOfType<T>>(...elementValuePaths: readonly `${K}.${number}`[]): void;
160
+ protected moveListItem<K extends keyof FlattenedListTypesOfType<T>>(fromValuePath: K, toValuePath: K): void;
160
161
  private internalSetFieldValue;
161
162
  /**
162
163
  * Forces an error onto a field. Error will be removed if the field value changes
package/dist/index.d.ts CHANGED
@@ -157,6 +157,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
157
157
  setFieldValue<K extends keyof ValuePathsToAdapters>(valuePath: K, value: ToOfFieldAdapter<ValuePathsToAdapters[K]>, validation?: Validation): boolean;
158
158
  addListItem<K extends keyof FlattenedListTypesOfType<T>>(valuePath: K, elementValue?: Maybe<ElementOfArray<FlattenedValuesOfType<T>[K]>>, index?: number): void;
159
159
  removeListItem<K extends keyof FlattenedListTypesOfType<T>>(...elementValuePaths: readonly `${K}.${number}`[]): void;
160
+ protected moveListItem<K extends keyof FlattenedListTypesOfType<T>>(fromValuePath: K, toValuePath: K): void;
160
161
  private internalSetFieldValue;
161
162
  /**
162
163
  * Forces an error onto a field. Error will be removed if the field value changes
package/dist/index.js CHANGED
@@ -690,12 +690,17 @@ var FormModel = class {
690
690
  const validation = this.validation[fromJsonPath];
691
691
  delete this.validation[fromJsonPath];
692
692
  this.validation[toJsonPath] = validation;
693
+ this.moveListItem(fromJsonPath, toJsonPath);
693
694
  });
694
695
  accessor.set(newList);
695
696
  delete this.fieldOverrides[listValuePath];
696
697
  });
697
698
  });
698
699
  }
700
+ moveListItem(fromValuePath, toValuePath) {
701
+ fromValuePath;
702
+ toValuePath;
703
+ }
699
704
  internalSetFieldValue(valuePath, value, validation) {
700
705
  const { revert } = this.getAdapterForValuePath(valuePath);
701
706
  assertExists(revert, "setting value not supported {}", valuePath);
@@ -887,7 +892,7 @@ function useDefaultMobxFormHooks(model, {
887
892
  const onFieldBlur = useCallback(
888
893
  function(path) {
889
894
  setTimeout(function() {
890
- if (model.isValuePathActive(path) && model.isFieldDirty(path)) {
895
+ if (model.isValuePathActive(path) && model.isFieldDirty(path) && model.fields[path].error == null) {
891
896
  model.validateField(path, Math.max(1 /* Changed */, model.getValidation(path)));
892
897
  }
893
898
  }, 100);
package/package.json CHANGED
@@ -72,7 +72,7 @@
72
72
  "test:watch": "vitest"
73
73
  },
74
74
  "type": "module",
75
- "version": "0.0.26",
75
+ "version": "0.0.27",
76
76
  "exports": {
77
77
  ".": {
78
78
  "import": {