@strictly/react-form 0.0.7 → 0.0.8

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.
Files changed (72) hide show
  1. package/.out/core/mobx/hooks.d.ts +5 -1
  2. package/.out/core/mobx/hooks.js +13 -3
  3. package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +56 -9
  4. package/.out/core/mobx/sub_form_field_adapters.d.ts +5 -5
  5. package/.out/core/mobx/sub_form_field_adapters.js +13 -10
  6. package/.out/field_converters/nullable_to_boolean_converter.d.ts +2 -2
  7. package/.out/mantine/create_checkbox.js +1 -0
  8. package/.out/mantine/create_fields_view.d.ts +1 -1
  9. package/.out/mantine/create_fields_view.js +4 -4
  10. package/.out/mantine/create_form.d.ts +1 -1
  11. package/.out/mantine/create_list.d.ts +1 -1
  12. package/.out/mantine/create_pill.d.ts +1 -1
  13. package/.out/mantine/create_radio.d.ts +1 -1
  14. package/.out/mantine/create_radio_group.js +1 -0
  15. package/.out/mantine/create_text_input.js +7 -2
  16. package/.out/mantine/create_value_input.js +1 -0
  17. package/.out/mantine/error_renderer.d.ts +1 -1
  18. package/.out/mantine/error_renderer.js +1 -1
  19. package/.out/mantine/hooks.d.ts +9 -9
  20. package/.out/mantine/specs/checkbox_hooks.stories.d.ts +2 -6
  21. package/.out/mantine/specs/checkbox_hooks.stories.js +4 -16
  22. package/.out/mantine/specs/fields_view_hooks.stories.d.ts +1 -1
  23. package/.out/mantine/specs/fields_view_hooks.stories.js +6 -3
  24. package/.out/mantine/specs/form_hooks.stories.d.ts +2 -2
  25. package/.out/mantine/specs/form_hooks.stories.js +4 -1
  26. package/.out/mantine/specs/radio_group_hooks.stories.d.ts +2 -6
  27. package/.out/mantine/specs/radio_group_hooks.stories.js +5 -17
  28. package/.out/mantine/specs/select_hooks.stories.d.ts +2 -6
  29. package/.out/mantine/specs/select_hooks.stories.js +4 -16
  30. package/.out/mantine/specs/text_input_hooks.stories.d.ts +2 -5
  31. package/.out/mantine/specs/text_input_hooks.stories.js +5 -5
  32. package/.out/mantine/specs/value_input_hooks.stories.d.ts +2 -5
  33. package/.out/mantine/specs/value_input_hooks.stories.js +5 -5
  34. package/.out/mantine/types.d.ts +4 -2
  35. package/.out/tsconfig.tsbuildinfo +1 -1
  36. package/.turbo/turbo-build.log +8 -8
  37. package/.turbo/turbo-check-types.log +1 -1
  38. package/.turbo/turbo-release$colon$exports.log +1 -1
  39. package/core/mobx/hooks.ts +24 -6
  40. package/core/mobx/specs/sub_form_field_adapters.tests.ts +108 -15
  41. package/core/mobx/sub_form_field_adapters.ts +41 -25
  42. package/dist/index.cjs +52 -27
  43. package/dist/index.d.cts +25 -19
  44. package/dist/index.d.ts +25 -19
  45. package/dist/index.js +52 -27
  46. package/field_converters/nullable_to_boolean_converter.ts +2 -3
  47. package/mantine/create_checkbox.tsx +2 -1
  48. package/mantine/create_fields_view.tsx +17 -14
  49. package/mantine/create_form.tsx +2 -2
  50. package/mantine/create_list.tsx +1 -1
  51. package/mantine/create_pill.tsx +1 -1
  52. package/mantine/create_radio.tsx +1 -1
  53. package/mantine/create_radio_group.tsx +6 -2
  54. package/mantine/create_text_input.tsx +9 -3
  55. package/mantine/create_value_input.tsx +2 -1
  56. package/mantine/error_renderer.ts +1 -1
  57. package/mantine/hooks.tsx +19 -14
  58. package/mantine/specs/__snapshots__/checkbox_hooks.tests.tsx.snap +1 -64
  59. package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +52 -52
  60. package/mantine/specs/__snapshots__/radio_group_hooks.tests.tsx.snap +1 -179
  61. package/mantine/specs/__snapshots__/select_hooks.tests.tsx.snap +1 -83
  62. package/mantine/specs/__snapshots__/text_input_hooks.tests.tsx.snap +27 -27
  63. package/mantine/specs/__snapshots__/value_input_hooks.tests.tsx.snap +31 -31
  64. package/mantine/specs/checkbox_hooks.stories.tsx +5 -21
  65. package/mantine/specs/fields_view_hooks.stories.tsx +16 -4
  66. package/mantine/specs/form_hooks.stories.tsx +10 -3
  67. package/mantine/specs/radio_group_hooks.stories.tsx +6 -20
  68. package/mantine/specs/select_hooks.stories.tsx +5 -21
  69. package/mantine/specs/text_input_hooks.stories.tsx +5 -8
  70. package/mantine/specs/value_input_hooks.stories.tsx +5 -8
  71. package/mantine/types.ts +7 -3
  72. package/package.json +2 -1
package/dist/index.d.ts CHANGED
@@ -181,8 +181,12 @@ type FormFieldsOfPresenter<Presenter extends FormPresenter<any, any, any, any>>
181
181
 
182
182
  type ValueOfPresenter<P extends FormPresenter<any, any, any, any>> = P extends FormPresenter<infer T, any, any, any> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
183
183
  type ModelOfPresenter<P extends FormPresenter<any, any, any, any>> = ReturnType<P['createModel']>;
184
- declare function useDefaultMobxFormHooks<P extends FormPresenter<any, any, any, any>>(presenter: P, value: ValueOfPresenter<P>, onValidSubmit?: <Path extends ValuePathsOfPresenter<P>>(model: ModelOfPresenter<P>, valuePath: Path) => void): {
184
+ declare function useDefaultMobxFormHooks<P extends FormPresenter<any, any, any, any>>(presenter: P, value: ValueOfPresenter<P>, { onValidFieldSubmit, onValidFormSubmit, }: {
185
+ onValidFieldSubmit?: <Path extends ValuePathsOfPresenter<P>>(model: ModelOfPresenter<P>, valuePath: Path) => void;
186
+ onValidFormSubmit?: (model: ModelOfPresenter<P>, value: ValueOfPresenter<P>) => void;
187
+ }): {
185
188
  model: ModelOfPresenter<P>;
189
+ onFormSubmit?: (value: ValueOfPresenter<P>) => void;
186
190
  } & Omit<FieldsViewProps<ModelOfPresenter<P>['fields']>, 'fields'>;
187
191
 
188
192
  type MergedOfFieldAdaptersWithTwoWayConverter<FieldAdapters extends Readonly<Record<string, FieldAdapter>>, E, Context> = {
@@ -204,11 +208,11 @@ type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<K
204
208
  type MergedOfFieldAdapterWithValidator<A extends FieldAdapter, V extends Validator | undefined> = undefined extends V ? A : A extends FieldAdapter<infer From, infer To, infer E1, infer P1, infer C1> ? V extends Validator<From, infer E2, infer P2, infer C2> ? FieldAdapter<From, To, E1 | E2, P1 | P2, C1 | C2> : never : never;
205
209
  declare function mergeAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Readonly<Record<string, Validator>>, Key extends keyof Validators = keyof Validators>(adapters: FieldAdapters, validators: Validators): MergedOfFieldAdaptersWithValidators<FieldAdapters, Validators, Key>;
206
210
 
207
- type SubFormFieldAdapter<F extends FieldAdapter, P extends string, Context> = FieldAdapter<FromOfFieldAdapter<F>, ToOfFieldAdapter<F>, ErrorOfFieldAdapter<F>, P, Context>;
208
- type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string, Context> = {
209
- [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: K extends StringConcatOf<'$', infer S> ? SubFormFieldAdapter<SubAdapters[K], `${P}${S}`, Context> : never;
211
+ type SubFormFieldAdapter<F extends FieldAdapter, ValuePath extends string, Context> = FieldAdapter<FromOfFieldAdapter<F>, ToOfFieldAdapter<F>, ErrorOfFieldAdapter<F>, ValuePathOfFieldAdapter<F> extends StringConcatOf<'$', infer ValuePathSuffix> ? `${ValuePath}${ValuePathSuffix}` : string, Context>;
212
+ type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, ValuePath extends string, Context> = {
213
+ [K in keyof SubAdapters as K extends StringConcatOf<'$', infer TypePathSuffix> ? `${TypePath}${TypePathSuffix}` : never]: SubFormFieldAdapter<SubAdapters[K], ValuePath, Context>;
210
214
  };
211
- declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string, ContextType extends Type>(subAdapters: SubAdapters, prefix: P, contextType: ContextType): SubFormFieldAdapters<SubAdapters, P, ValueOfType<ContextType>>;
215
+ declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, TypePathsToValuePaths extends Record<TypePath, string>, ContextType extends Type>(subAdapters: SubAdapters, parentTypePath: TypePath, contextType: ContextType): SubFormFieldAdapters<SubAdapters, TypePath, TypePathsToValuePaths[TypePath], ValueOfType<ContextType>>;
212
216
 
213
217
  declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
214
218
  private readonly isNanError;
@@ -218,14 +222,14 @@ declare class IntegerToStringConverter<E, ValuePath extends string, Context> imp
218
222
  revert(from: string): UnreliableFieldConversion<number, E>;
219
223
  }
220
224
 
221
- declare class NullableToBooleanConverter<T extends Type, E, ValuePath extends string, Context, NullType extends null | undefined> implements TwoWayFieldConverterWithValueFactory<ValueOfType<ReadonlyTypeOfType<T>> | NullType, boolean, E, ValuePath, Context> {
225
+ declare class NullableToBooleanConverter<T extends Type, ValuePath extends string, Context, NullType extends null | undefined> implements TwoWayFieldConverterWithValueFactory<ValueOfType<ReadonlyTypeOfType<T>> | NullType, boolean, never, ValuePath, Context> {
222
226
  private readonly typeDef;
223
227
  private readonly prototype;
224
228
  private readonly nullType;
225
229
  readonly defaultValue: ValueOfType<ReadonlyTypeOfType<T>> | NullType;
226
230
  constructor(typeDef: T, prototype: ValueOfType<ReadonlyTypeOfType<T>>, nullType: NullType, defaultToNull?: boolean);
227
231
  convert(from: ValueOfType<ReadonlyTypeOfType<T>> | NullType): AnnotatedFieldConversion<boolean>;
228
- revert(from: boolean): UnreliableFieldConversion<ValueOfType<ReadonlyTypeOfType<T>> | NullType, E>;
232
+ revert(from: boolean): UnreliableFieldConversion<ValueOfType<ReadonlyTypeOfType<T>> | NullType, never>;
229
233
  create(): ValueOfType<ReadonlyTypeOfType<T>> | NullType;
230
234
  }
231
235
 
@@ -269,7 +273,7 @@ type ErrorRendererProps<E> = {
269
273
  error: E;
270
274
  };
271
275
  type ErrorRenderer<E = any> = ComponentType<ErrorRendererProps<E>>;
272
- declare function DefaultErrorRenderer({ error, }: ErrorRendererProps<any>): any;
276
+ declare function DefaultErrorRenderer({ error, }: ErrorRendererProps<any>): string;
273
277
 
274
278
  type ValueTypeOfField<F extends Field> = F extends Field<infer V> ? V : never;
275
279
 
@@ -319,8 +323,10 @@ type MantineForm<F extends Fields> = {
319
323
  onFieldBlur: ((this: void, key: keyof F) => void) | undefined;
320
324
  onFieldSubmit: ((this: void, key: keyof F) => boolean | void) | undefined;
321
325
  };
322
- type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<ComponentType<P>, T, {
323
- ErrorRenderer?: ErrorRenderer<E>;
326
+ type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<ComponentType<P>, T, [
327
+ E
328
+ ] extends [never] ? {} : {
329
+ ErrorRenderer: ErrorRenderer<E>;
324
330
  }>;
325
331
 
326
332
  type SuppliedCheckboxProps = Pick<CheckboxProps, 'name' | 'checked' | 'disabled' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
@@ -384,21 +390,21 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
384
390
  onFieldBlur: ((this: void, key: keyof F) => void) | undefined;
385
391
  onFieldSubmit: ((this: void, key: keyof F) => boolean | void) | undefined;
386
392
  constructor(fields: F);
387
- textInput<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, TextInputProps>;
388
- textInput<K extends keyof StringFieldsOfFields<F>, P extends SuppliedTextInputProps<any>>(valuePath: K, TextInput?: ComponentType<P>): MantineFieldComponent<SuppliedTextInputProps, P>;
393
+ textInput<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, TextInputProps, ErrorOfField<F[K]>>;
394
+ textInput<K extends keyof StringFieldsOfFields<F>, P extends SuppliedTextInputProps<any>>(valuePath: K, TextInput?: ComponentType<P>): MantineFieldComponent<SuppliedTextInputProps, P, ErrorOfField<F[K]>>;
389
395
  valueInput<K extends keyof AllFieldsOfFields<F>, P extends SuppliedValueInputProps<ValueTypeOfField<F[K]>, any>>(valuePath: K, ValueInput: ComponentType<P>): MantineFieldComponent<SuppliedValueInputProps<ValueTypeOfField<F[K]>>, P, ErrorOfField<F[K]>>;
390
396
  select<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, ComponentProps<typeof SimpleSelect>, ErrorOfField<F[K]>>;
391
- checkbox<K extends keyof BooleanFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedCheckboxProps, CheckboxProps>;
397
+ checkbox<K extends keyof BooleanFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedCheckboxProps, CheckboxProps, ErrorOfField<F[K]>>;
392
398
  checkbox<K extends keyof BooleanFieldsOfFields<F>, P extends SuppliedCheckboxProps>(valuePath: K, Checkbox: ComponentType<P>): MantineFieldComponent<SuppliedCheckboxProps, P, ErrorOfField<F[K]>>;
393
- radioGroup<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedRadioGroupProps, RadioGroupProps>;
394
- radioGroup<K extends keyof StringFieldsOfFields<F>, P extends SuppliedRadioGroupProps>(valuePath: K, RadioGroup: ComponentType<P>): MantineFieldComponent<SuppliedRadioGroupProps, P>;
399
+ radioGroup<K extends keyof StringFieldsOfFields<F>, P extends RadioGroupProps = RadioGroupProps>(valuePath: K): MantineFieldComponent<SuppliedRadioGroupProps, P, ErrorOfField<F[K]>>;
400
+ radioGroup<K extends keyof StringFieldsOfFields<F>, P extends SuppliedRadioGroupProps>(valuePath: K, RadioGroup: ComponentType<P>): MantineFieldComponent<SuppliedRadioGroupProps, P, ErrorOfField<F[K]>>;
395
401
  radio<K extends keyof StringFieldsOfFields<F>>(valuePath: K, value: ValueTypeOfField<F[K]>): MantineFieldComponent<SuppliedRadioProps, RadioProps, ErrorOfField<F[K]>>;
396
402
  radio<K extends keyof StringFieldsOfFields<F>, P extends SuppliedRadioProps>(valuePath: K, value: ValueTypeOfField<F[K]>, Radio: ComponentType<P>): MantineFieldComponent<SuppliedRadioProps, P, ErrorOfField<F[K]>>;
397
403
  pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
398
- pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P>;
399
- list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>>;
400
- fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): MantineFieldComponent<FieldsViewProps<P['fields']>, P>;
401
- form<K extends keyof AllFieldsOfFields<F>, P extends FormProps<ValueTypeOfField<F[K]>> = FormProps<ValueTypeOfField<F[K]>>>(valuePath: K, Form: ComponentType<P>): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P>;
404
+ pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P, ErrorOfField<F[K]>>;
405
+ list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>, never>;
406
+ fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): MantineFieldComponent<FieldsViewProps<P['fields']>, P, never>;
407
+ form<K extends keyof AllFieldsOfFields<F>, P extends FormProps<ValueTypeOfField<F[K]>> = FormProps<ValueTypeOfField<F[K]>>>(valuePath: K, Form: ComponentType<P>): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never>;
402
408
  }
403
409
 
404
410
  type MergedOfValidators<Validators1 extends Partial<Readonly<Record<Keys, Validator>>>, Validators2 extends Partial<Readonly<Record<Keys, Validator>>>, Keys extends string = Extract<keyof Validators1 | keyof Validators2, string>> = Simplify<{
package/dist/index.js CHANGED
@@ -660,7 +660,10 @@ import {
660
660
  useCallback,
661
661
  useMemo
662
662
  } from "react";
663
- function useDefaultMobxFormHooks(presenter, value, onValidSubmit) {
663
+ function useDefaultMobxFormHooks(presenter, value, {
664
+ onValidFieldSubmit,
665
+ onValidFormSubmit
666
+ }) {
664
667
  const model = useMemo(function() {
665
668
  return presenter.createModel(value);
666
669
  }, [
@@ -680,14 +683,14 @@ function useDefaultMobxFormHooks(presenter, value, onValidSubmit) {
680
683
  const onFieldSubmit = useCallback(
681
684
  function(valuePath) {
682
685
  if (presenter.validateField(model, valuePath)) {
683
- onValidSubmit?.(model, valuePath);
686
+ onValidFieldSubmit?.(model, valuePath);
684
687
  }
685
688
  return false;
686
689
  },
687
690
  [
688
691
  presenter,
689
692
  model,
690
- onValidSubmit
693
+ onValidFieldSubmit
691
694
  ]
692
695
  );
693
696
  const onFieldBlur = useCallback(
@@ -703,11 +706,24 @@ function useDefaultMobxFormHooks(presenter, value, onValidSubmit) {
703
706
  model
704
707
  ]
705
708
  );
709
+ const onFormSubmit = useCallback(
710
+ function() {
711
+ if (presenter.validateAll(model)) {
712
+ onValidFormSubmit?.(model, model.value);
713
+ }
714
+ },
715
+ [
716
+ presenter,
717
+ model,
718
+ onValidFormSubmit
719
+ ]
720
+ );
706
721
  return {
707
722
  model,
708
723
  onFieldValueChange,
709
724
  onFieldSubmit,
710
- onFieldBlur
725
+ onFieldBlur,
726
+ onFormSubmit
711
727
  };
712
728
  }
713
729
 
@@ -793,32 +809,34 @@ function mergeAdaptersWithValidators(adapters, validators) {
793
809
  import {
794
810
  flattenValuesOfType as flattenValuesOfType2
795
811
  } from "@strictly/define";
796
- function subFormFieldAdapters(subAdapters, prefix, contextType) {
812
+ function subFormFieldAdapters(subAdapters, parentTypePath, contextType) {
813
+ const dotCount = parentTypePath.split(".").length;
797
814
  function getSubValuePathAndContext(valuePath, context) {
798
- const subValuePath = valuePath.replace(prefix, "$");
799
- const subContext = flattenValuesOfType2(contextType, context)[prefix];
815
+ const parentValuePath = valuePath.split(".").slice(0, dotCount).join(".");
816
+ const subValuePath = valuePath.replace(parentValuePath, "$");
817
+ const subContext = flattenValuesOfType2(contextType, context)[parentValuePath];
800
818
  return [
801
819
  subValuePath,
802
820
  subContext
803
821
  ];
804
822
  }
805
823
  return Object.entries(subAdapters).reduce((acc, [
806
- subKey,
807
- subValue
824
+ subTypePath,
825
+ subAdapter
808
826
  ]) => {
809
- const key = subKey.replace("$", prefix);
827
+ const typePath = subTypePath.replace("$", parentTypePath);
810
828
  const adaptedAdapter = {
811
829
  convert: (from, valuePath, context) => {
812
- return subValue.convert(from, ...getSubValuePathAndContext(valuePath, context));
830
+ return subAdapter.convert(from, ...getSubValuePathAndContext(valuePath, context));
813
831
  },
814
832
  create: (valuePath, context) => {
815
- return subValue.create(...getSubValuePathAndContext(valuePath, context));
833
+ return subAdapter.create(...getSubValuePathAndContext(valuePath, context));
816
834
  },
817
- revert: subValue.revert && ((from, valuePath, context) => {
818
- return subValue.revert(from, ...getSubValuePathAndContext(valuePath, context));
835
+ revert: subAdapter.revert && ((from, valuePath, context) => {
836
+ return subAdapter.revert(from, ...getSubValuePathAndContext(valuePath, context));
819
837
  })
820
838
  };
821
- acc[key] = adaptedAdapter;
839
+ acc[typePath] = adaptedAdapter;
822
840
  return acc;
823
841
  }, {});
824
842
  }
@@ -1040,7 +1058,7 @@ function DefaultErrorRenderer({
1040
1058
  error
1041
1059
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1042
1060
  }) {
1043
- return error;
1061
+ return JSON.stringify(error);
1044
1062
  }
1045
1063
 
1046
1064
  // mantine/hooks.tsx
@@ -1288,15 +1306,19 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
1288
1306
  observableProps.onFieldSubmit?.(toKey(subKey));
1289
1307
  }
1290
1308
  return observer2(function(props) {
1291
- const subFields = Object.entries(observableProps.fields).reduce((acc, [
1292
- fieldKey,
1293
- fieldValue
1294
- ]) => {
1295
- if (fieldKey.startsWith(valuePath)) {
1296
- acc[toSubKey(fieldKey)] = fieldValue;
1297
- }
1298
- return acc;
1299
- }, {});
1309
+ const subFields = Object.entries(observableProps.fields).reduce(
1310
+ (acc, [
1311
+ fieldKey,
1312
+ fieldValue
1313
+ ]) => {
1314
+ if (fieldKey.startsWith(valuePath)) {
1315
+ acc[toSubKey(fieldKey)] = fieldValue;
1316
+ }
1317
+ return acc;
1318
+ },
1319
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1320
+ {}
1321
+ );
1300
1322
  return /* @__PURE__ */ jsx3(
1301
1323
  FieldsView,
1302
1324
  {
@@ -1454,13 +1476,16 @@ function createTextInput(valuePath, TextInput) {
1454
1476
  const propSource = ({
1455
1477
  ErrorRenderer = DefaultErrorRenderer
1456
1478
  }) => {
1479
+ const field = this.fields[valuePath];
1480
+ if (field == null) {
1481
+ throw new Error(`invalid field ${valuePath}`);
1482
+ }
1457
1483
  const {
1458
1484
  readonly,
1459
1485
  required,
1460
1486
  value,
1461
1487
  error
1462
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1463
- } = this.fields[valuePath];
1488
+ } = field;
1464
1489
  return {
1465
1490
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1466
1491
  name: valuePath,
@@ -13,14 +13,13 @@ import {
13
13
 
14
14
  export class NullableToBooleanConverter<
15
15
  T extends Type,
16
- E,
17
16
  ValuePath extends string,
18
17
  Context,
19
18
  NullType extends null | undefined,
20
19
  > implements TwoWayFieldConverterWithValueFactory<
21
20
  ValueOfType<ReadonlyTypeOfType<T>> | NullType,
22
21
  boolean,
23
- E,
22
+ never,
24
23
  ValuePath,
25
24
  Context
26
25
  > {
@@ -43,7 +42,7 @@ export class NullableToBooleanConverter<
43
42
  }
44
43
  }
45
44
 
46
- revert(from: boolean): UnreliableFieldConversion<ValueOfType<ReadonlyTypeOfType<T>> | NullType, E> {
45
+ revert(from: boolean): UnreliableFieldConversion<ValueOfType<ReadonlyTypeOfType<T>> | NullType, never> {
47
46
  if (from) {
48
47
  const value: ValueOfType<T> = copy(this.typeDef, this.prototype)
49
48
  return {
@@ -78,9 +78,10 @@ export function createCheckbox<
78
78
  onKeyUp,
79
79
  }
80
80
  }
81
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
81
82
  return createUnsafePartialObserverComponent(
82
83
  Checkbox,
83
84
  propSource,
84
85
  ['ErrorRenderer'],
85
- )
86
+ ) as MantineFieldComponent<SuppliedCheckboxProps, Props, ErrorOfField<F[K]>>
86
87
  }
@@ -18,7 +18,7 @@ export function createFieldsView<
18
18
  valuePath: K,
19
19
  FieldsView: ComponentType<P>,
20
20
  observableProps: FieldsViewProps<F>,
21
- ): MantineFieldComponent<FieldsViewProps<P['fields']>, P> {
21
+ ): MantineFieldComponent<FieldsViewProps<P['fields']>, P, never> {
22
22
  function toKey(subKey: string | number | symbol): string {
23
23
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
24
24
  return (subKey as string).replace('$', valuePath as string)
@@ -49,18 +49,22 @@ export function createFieldsView<
49
49
  }
50
50
 
51
51
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
52
- return observer(function (props: ComponentProps<MantineFieldComponent<FieldsViewProps<P['fields']>, P>>) {
52
+ return observer(function (props: ComponentProps<MantineFieldComponent<FieldsViewProps<P['fields']>, P, never>>) {
53
53
  // convert fields to sub-fields
54
- const subFields = Object.entries(observableProps.fields).reduce<Record<string, unknown>>((acc, [
55
- fieldKey,
56
- fieldValue,
57
- ]) => {
54
+ const subFields = Object.entries(observableProps.fields).reduce<Record<string, unknown>>(
55
+ (acc, [
56
+ fieldKey,
57
+ fieldValue,
58
+ ]) => {
59
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
60
+ if (fieldKey.startsWith(valuePath as string)) {
61
+ acc[toSubKey(fieldKey)] = fieldValue
62
+ }
63
+ return acc
64
+ },
58
65
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
59
- if (fieldKey.startsWith(valuePath as string)) {
60
- acc[toSubKey(fieldKey)] = fieldValue
61
- }
62
- return acc
63
- }, {})
66
+ {} as P['fields'],
67
+ )
64
68
 
65
69
  return (
66
70
  <FieldsView
@@ -69,13 +73,12 @@ export function createFieldsView<
69
73
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
70
74
  ...props as any
71
75
  }
72
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
73
- fields={subFields as P['fields']}
76
+ fields={subFields}
74
77
  onFieldBlur={onFieldBlur}
75
78
  onFieldFocus={onFieldFocus}
76
79
  onFieldSubmit={onFieldSubmit}
77
80
  onFieldValueChange={onFieldValueChange}
78
81
  />
79
82
  )
80
- }) as unknown as MantineFieldComponent<FieldsViewProps<P['fields']>, P>
83
+ }) as unknown as MantineFieldComponent<FieldsViewProps<P['fields']>, P, never>
81
84
  }
@@ -21,7 +21,7 @@ export function createForm<
21
21
  valuePath: K,
22
22
  Form: ComponentType<P>,
23
23
  observableProps: FieldsViewProps<F>,
24
- ): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P> {
24
+ ): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never> {
25
25
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
26
26
  return observer((props: ComponentProps<MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P>>) => {
27
27
  const { value } = observableProps.fields[valuePath]
@@ -39,5 +39,5 @@ export function createForm<
39
39
  value={value}
40
40
  />
41
41
  )
42
- }) as MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P>
42
+ }) as MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never>
43
43
  }
@@ -29,7 +29,7 @@ export function createList<
29
29
  this: MantineForm<F>,
30
30
  valuePath: K,
31
31
  List: ComponentType<Props>,
32
- ): MantineFieldComponent<SuppliedListProps<ElementOfArray<ValueTypeOfField<F[K]>>>, Props> {
32
+ ): MantineFieldComponent<SuppliedListProps<ElementOfArray<ValueTypeOfField<F[K]>>>, Props, never> {
33
33
  const propSource = () => {
34
34
  const values = [...this.fields[valuePath].value]
35
35
  return {
@@ -25,7 +25,7 @@ export function createPill<
25
25
  this: MantineForm<F>,
26
26
  valuePath: K,
27
27
  Pill: ComponentType<Props>,
28
- ): MantineFieldComponent<SuppliedPillProps, Props> {
28
+ ): MantineFieldComponent<SuppliedPillProps, Props, never> {
29
29
  const propSource = () => {
30
30
  const {
31
31
  readonly,
@@ -22,7 +22,7 @@ export function createRadio<
22
22
  valuePath: K,
23
23
  value: ValueTypeOfField<F[K]>,
24
24
  Radio: ComponentType<Props>,
25
- ): MantineFieldComponent<SuppliedRadioProps, Props> {
25
+ ): MantineFieldComponent<SuppliedRadioProps, Props, never> {
26
26
  const propSource = () => {
27
27
  return {
28
28
  disabled: this.fields[valuePath].readonly,
@@ -68,6 +68,10 @@ export function createRadioGroup<
68
68
  onKeyUp,
69
69
  }
70
70
  }
71
-
72
- return createUnsafePartialObserverComponent(RadioGroup, propSource, ['ErrorRenderer'])
71
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
72
+ return createUnsafePartialObserverComponent(RadioGroup, propSource, ['ErrorRenderer']) as MantineFieldComponent<
73
+ SuppliedRadioGroupProps,
74
+ Props,
75
+ ErrorOfField<F[K]>
76
+ >
73
77
  }
@@ -59,13 +59,18 @@ export function createTextInput<
59
59
  }: {
60
60
  ErrorRenderer?: ErrorRenderer<ErrorOfField<F[K]>>,
61
61
  }) => {
62
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
63
+ const field = this.fields[valuePath as string]
64
+ if (field == null) {
65
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
66
+ throw new Error(`invalid field ${valuePath as string}`)
67
+ }
62
68
  const {
63
69
  readonly,
64
70
  required,
65
71
  value,
66
72
  error,
67
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
68
- } = this.fields[valuePath as string]
73
+ } = field
69
74
  return {
70
75
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
71
76
  name: valuePath as string,
@@ -79,6 +84,7 @@ export function createTextInput<
79
84
  onKeyUp,
80
85
  }
81
86
  }
87
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
82
88
  return createUnsafePartialObserverComponent<
83
89
  typeof TextInput,
84
90
  SuppliedTextInputProps,
@@ -88,5 +94,5 @@ export function createTextInput<
88
94
  TextInput,
89
95
  propSource,
90
96
  ['ErrorRenderer'],
91
- )
97
+ ) as MantineFieldComponent<SuppliedTextInputProps, Props, ErrorOfField<F[K]>>
92
98
  }
@@ -77,6 +77,7 @@ export function createValueInput<
77
77
  onKeyUp,
78
78
  }
79
79
  }
80
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
80
81
  return createUnsafePartialObserverComponent<
81
82
  typeof ValueInput,
82
83
  SuppliedValueInputProps<ValueTypeOfField<F[K]>>,
@@ -86,5 +87,5 @@ export function createValueInput<
86
87
  ValueInput,
87
88
  propSource,
88
89
  ['ErrorRenderer'],
89
- )
90
+ ) as MantineFieldComponent<SuppliedValueInputProps<ValueTypeOfField<F[K]>>, Props, ErrorOfField<F[K]>>
90
91
  }
@@ -11,5 +11,5 @@ export function DefaultErrorRenderer({
11
11
  error,
12
12
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
13
  }: ErrorRendererProps<any>) {
14
- return error
14
+ return JSON.stringify(error)
15
15
  }
package/mantine/hooks.tsx CHANGED
@@ -209,7 +209,7 @@ class MantineFormImpl<
209
209
 
210
210
  textInput<
211
211
  K extends keyof StringFieldsOfFields<F>,
212
- >(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, TextInputProps>
212
+ >(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, TextInputProps, ErrorOfField<F[K]>>
213
213
  textInput<
214
214
  K extends keyof StringFieldsOfFields<F>,
215
215
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -217,7 +217,7 @@ class MantineFormImpl<
217
217
  >(
218
218
  valuePath: K,
219
219
  TextInput?: ComponentType<P>,
220
- ): MantineFieldComponent<SuppliedTextInputProps, P>
220
+ ): MantineFieldComponent<SuppliedTextInputProps, P, ErrorOfField<F[K]>>
221
221
  textInput<
222
222
  K extends keyof StringFieldsOfFields<F>,
223
223
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -264,7 +264,7 @@ class MantineFormImpl<
264
264
 
265
265
  checkbox<
266
266
  K extends keyof BooleanFieldsOfFields<F>,
267
- >(valuePath: K): MantineFieldComponent<SuppliedCheckboxProps, CheckboxProps>
267
+ >(valuePath: K): MantineFieldComponent<SuppliedCheckboxProps, CheckboxProps, ErrorOfField<F[K]>>
268
268
  checkbox<
269
269
  K extends keyof BooleanFieldsOfFields<F>,
270
270
  P extends SuppliedCheckboxProps,
@@ -282,19 +282,21 @@ class MantineFormImpl<
282
282
  valuePath,
283
283
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
284
284
  Checkbox as ComponentType<SuppliedCheckboxProps>,
285
- ) as MantineFieldComponent<SuppliedCheckboxProps, P>
285
+ ) as MantineFieldComponent<SuppliedCheckboxProps, P, ErrorOfField<F[K]>>
286
286
  }
287
287
 
288
+ // this should work?
288
289
  radioGroup<
289
290
  K extends keyof StringFieldsOfFields<F>,
290
- >(valuePath: K): MantineFieldComponent<SuppliedRadioGroupProps, RadioGroupProps>
291
+ P extends RadioGroupProps = RadioGroupProps,
292
+ >(valuePath: K): MantineFieldComponent<SuppliedRadioGroupProps, P, ErrorOfField<F[K]>>
291
293
  radioGroup<
292
294
  K extends keyof StringFieldsOfFields<F>,
293
295
  P extends SuppliedRadioGroupProps,
294
296
  >(
295
297
  valuePath: K,
296
298
  RadioGroup: ComponentType<P>,
297
- ): MantineFieldComponent<SuppliedRadioGroupProps, P>
299
+ ): MantineFieldComponent<SuppliedRadioGroupProps, P, ErrorOfField<F[K]>>
298
300
  radioGroup<
299
301
  K extends keyof StringFieldsOfFields<F>,
300
302
  P extends SuppliedRadioGroupProps,
@@ -340,7 +342,7 @@ class MantineFormImpl<
340
342
  value,
341
343
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
342
344
  Radio as ComponentType<SuppliedRadioProps>,
343
- ) as MantineFieldComponent<SuppliedRadioProps, P>
345
+ ) as MantineFieldComponent<SuppliedRadioProps, P, ErrorOfField<F[K]>>
344
346
  }
345
347
 
346
348
  pill<
@@ -352,7 +354,7 @@ class MantineFormImpl<
352
354
  >(
353
355
  valuePath: K,
354
356
  Pill: ComponentType<P>,
355
- ): MantineFieldComponent<SuppliedPillProps, P>
357
+ ): MantineFieldComponent<SuppliedPillProps, P, ErrorOfField<F[K]>>
356
358
  pill<
357
359
  K extends keyof AllFieldsOfFields<F>,
358
360
  P extends SuppliedPillProps,
@@ -373,7 +375,8 @@ class MantineFormImpl<
373
375
  K extends keyof ListFieldsOfFields<F>,
374
376
  >(valuePath: K): MantineFieldComponent<
375
377
  SuppliedListProps<`${K}.${number}`>,
376
- ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>
378
+ ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>,
379
+ never
377
380
  > {
378
381
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
379
382
  return this.listCache.retrieveOrCreate(
@@ -382,7 +385,7 @@ class MantineFormImpl<
382
385
  ) as MantineFieldComponent<
383
386
  SuppliedListProps<`${K}.${number}`>,
384
387
  ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>,
385
- ErrorOfField<F[K]>
388
+ never
386
389
  >
387
390
  }
388
391
 
@@ -391,7 +394,8 @@ class MantineFormImpl<
391
394
  P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>,
392
395
  >(valuePath: K, FieldsView: ComponentType<P>): MantineFieldComponent<
393
396
  FieldsViewProps<P['fields']>,
394
- P
397
+ P,
398
+ never
395
399
  > {
396
400
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
397
401
  return this.fieldsViewCache.retrieveOrCreate(
@@ -402,7 +406,8 @@ class MantineFormImpl<
402
406
  this,
403
407
  ) as unknown as MantineFieldComponent<
404
408
  FieldsViewProps<P['fields']>,
405
- P
409
+ P,
410
+ never
406
411
  >
407
412
  }
408
413
 
@@ -412,7 +417,7 @@ class MantineFormImpl<
412
417
  >(
413
418
  valuePath: K,
414
419
  Form: ComponentType<P>,
415
- ): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P> {
420
+ ): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never> {
416
421
  // strip props from component since we lose information in the cache
417
422
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
418
423
  return this.formCache.retrieveOrCreate(
@@ -421,6 +426,6 @@ class MantineFormImpl<
421
426
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
422
427
  Form as ComponentType,
423
428
  this,
424
- ) as unknown as MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P>
429
+ ) as unknown as MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never>
425
430
  }
426
431
  }