@strictly/react-form 0.0.6 → 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 (77) 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/form_presenter.tests.js +3 -6
  4. package/.out/core/mobx/specs/{merge_field_adapters_with_two_way_converter.js → merge_field_adapters_with_two_way_converter.tests.js} +15 -16
  5. package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +127 -12
  6. package/.out/core/mobx/sub_form_field_adapters.d.ts +6 -4
  7. package/.out/core/mobx/sub_form_field_adapters.js +28 -4
  8. package/.out/field_converters/nullable_to_boolean_converter.d.ts +2 -2
  9. package/.out/mantine/create_checkbox.js +1 -0
  10. package/.out/mantine/create_fields_view.d.ts +1 -1
  11. package/.out/mantine/create_fields_view.js +4 -4
  12. package/.out/mantine/create_form.d.ts +1 -1
  13. package/.out/mantine/create_list.d.ts +1 -1
  14. package/.out/mantine/create_pill.d.ts +1 -1
  15. package/.out/mantine/create_radio.d.ts +1 -1
  16. package/.out/mantine/create_radio_group.js +1 -0
  17. package/.out/mantine/create_text_input.js +7 -2
  18. package/.out/mantine/create_value_input.js +1 -0
  19. package/.out/mantine/error_renderer.d.ts +1 -1
  20. package/.out/mantine/error_renderer.js +1 -1
  21. package/.out/mantine/hooks.d.ts +9 -9
  22. package/.out/mantine/specs/checkbox_hooks.stories.d.ts +2 -6
  23. package/.out/mantine/specs/checkbox_hooks.stories.js +4 -16
  24. package/.out/mantine/specs/fields_view_hooks.stories.d.ts +1 -1
  25. package/.out/mantine/specs/fields_view_hooks.stories.js +6 -3
  26. package/.out/mantine/specs/form_hooks.stories.d.ts +2 -2
  27. package/.out/mantine/specs/form_hooks.stories.js +4 -1
  28. package/.out/mantine/specs/radio_group_hooks.stories.d.ts +2 -6
  29. package/.out/mantine/specs/radio_group_hooks.stories.js +5 -17
  30. package/.out/mantine/specs/select_hooks.stories.d.ts +2 -6
  31. package/.out/mantine/specs/select_hooks.stories.js +4 -16
  32. package/.out/mantine/specs/text_input_hooks.stories.d.ts +2 -5
  33. package/.out/mantine/specs/text_input_hooks.stories.js +5 -5
  34. package/.out/mantine/specs/value_input_hooks.stories.d.ts +2 -5
  35. package/.out/mantine/specs/value_input_hooks.stories.js +5 -5
  36. package/.out/mantine/types.d.ts +4 -2
  37. package/.out/tsconfig.tsbuildinfo +1 -1
  38. package/.turbo/turbo-build.log +8 -8
  39. package/.turbo/turbo-check-types.log +1 -1
  40. package/.turbo/turbo-release$colon$exports.log +1 -1
  41. package/core/mobx/hooks.ts +24 -6
  42. package/core/mobx/specs/form_presenter.tests.ts +6 -6
  43. package/core/mobx/specs/{merge_field_adapters_with_two_way_converter.ts → merge_field_adapters_with_two_way_converter.tests.ts} +16 -16
  44. package/core/mobx/specs/sub_form_field_adapters.tests.ts +193 -17
  45. package/core/mobx/sub_form_field_adapters.ts +74 -11
  46. package/dist/index.cjs +77 -32
  47. package/dist/index.d.cts +25 -18
  48. package/dist/index.d.ts +25 -18
  49. package/dist/index.js +68 -21
  50. package/field_converters/nullable_to_boolean_converter.ts +2 -3
  51. package/mantine/create_checkbox.tsx +2 -1
  52. package/mantine/create_fields_view.tsx +17 -14
  53. package/mantine/create_form.tsx +2 -2
  54. package/mantine/create_list.tsx +1 -1
  55. package/mantine/create_pill.tsx +1 -1
  56. package/mantine/create_radio.tsx +1 -1
  57. package/mantine/create_radio_group.tsx +6 -2
  58. package/mantine/create_text_input.tsx +9 -3
  59. package/mantine/create_value_input.tsx +2 -1
  60. package/mantine/error_renderer.ts +1 -1
  61. package/mantine/hooks.tsx +19 -14
  62. package/mantine/specs/__snapshots__/checkbox_hooks.tests.tsx.snap +1 -64
  63. package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +52 -52
  64. package/mantine/specs/__snapshots__/radio_group_hooks.tests.tsx.snap +1 -179
  65. package/mantine/specs/__snapshots__/select_hooks.tests.tsx.snap +1 -83
  66. package/mantine/specs/__snapshots__/text_input_hooks.tests.tsx.snap +27 -27
  67. package/mantine/specs/__snapshots__/value_input_hooks.tests.tsx.snap +31 -31
  68. package/mantine/specs/checkbox_hooks.stories.tsx +5 -21
  69. package/mantine/specs/fields_view_hooks.stories.tsx +16 -4
  70. package/mantine/specs/form_hooks.stories.tsx +10 -3
  71. package/mantine/specs/radio_group_hooks.stories.tsx +6 -20
  72. package/mantine/specs/select_hooks.stories.tsx +5 -21
  73. package/mantine/specs/text_input_hooks.stories.tsx +5 -8
  74. package/mantine/specs/value_input_hooks.stories.tsx +5 -8
  75. package/mantine/types.ts +7 -3
  76. package/package.json +2 -1
  77. /package/.out/core/mobx/specs/{merge_field_adapters_with_two_way_converter.d.ts → merge_field_adapters_with_two_way_converter.tests.d.ts} +0 -0
package/dist/index.cjs CHANGED
@@ -690,7 +690,10 @@ var FormModel = class {
690
690
 
691
691
  // core/mobx/hooks.ts
692
692
  var import_react = require("react");
693
- function useDefaultMobxFormHooks(presenter, value, onValidSubmit) {
693
+ function useDefaultMobxFormHooks(presenter, value, {
694
+ onValidFieldSubmit,
695
+ onValidFormSubmit
696
+ }) {
694
697
  const model = (0, import_react.useMemo)(function() {
695
698
  return presenter.createModel(value);
696
699
  }, [
@@ -710,14 +713,14 @@ function useDefaultMobxFormHooks(presenter, value, onValidSubmit) {
710
713
  const onFieldSubmit = (0, import_react.useCallback)(
711
714
  function(valuePath) {
712
715
  if (presenter.validateField(model, valuePath)) {
713
- onValidSubmit?.(model, valuePath);
716
+ onValidFieldSubmit?.(model, valuePath);
714
717
  }
715
718
  return false;
716
719
  },
717
720
  [
718
721
  presenter,
719
722
  model,
720
- onValidSubmit
723
+ onValidFieldSubmit
721
724
  ]
722
725
  );
723
726
  const onFieldBlur = (0, import_react.useCallback)(
@@ -733,11 +736,24 @@ function useDefaultMobxFormHooks(presenter, value, onValidSubmit) {
733
736
  model
734
737
  ]
735
738
  );
739
+ const onFormSubmit = (0, import_react.useCallback)(
740
+ function() {
741
+ if (presenter.validateAll(model)) {
742
+ onValidFormSubmit?.(model, model.value);
743
+ }
744
+ },
745
+ [
746
+ presenter,
747
+ model,
748
+ onValidFormSubmit
749
+ ]
750
+ );
736
751
  return {
737
752
  model,
738
753
  onFieldValueChange,
739
754
  onFieldSubmit,
740
- onFieldBlur
755
+ onFieldBlur,
756
+ onFormSubmit
741
757
  };
742
758
  }
743
759
 
@@ -817,13 +833,35 @@ function mergeAdaptersWithValidators(adapters, validators) {
817
833
  }
818
834
 
819
835
  // core/mobx/sub_form_field_adapters.ts
820
- function subFormFieldAdapters(subAdapters, prefix) {
836
+ var import_define3 = require("@strictly/define");
837
+ function subFormFieldAdapters(subAdapters, parentTypePath, contextType) {
838
+ const dotCount = parentTypePath.split(".").length;
839
+ function getSubValuePathAndContext(valuePath, context) {
840
+ const parentValuePath = valuePath.split(".").slice(0, dotCount).join(".");
841
+ const subValuePath = valuePath.replace(parentValuePath, "$");
842
+ const subContext = (0, import_define3.flattenValuesOfType)(contextType, context)[parentValuePath];
843
+ return [
844
+ subValuePath,
845
+ subContext
846
+ ];
847
+ }
821
848
  return Object.entries(subAdapters).reduce((acc, [
822
- subKey,
823
- subValue
849
+ subTypePath,
850
+ subAdapter
824
851
  ]) => {
825
- const key = subKey.replace("$", prefix);
826
- acc[key] = subValue;
852
+ const typePath = subTypePath.replace("$", parentTypePath);
853
+ const adaptedAdapter = {
854
+ convert: (from, valuePath, context) => {
855
+ return subAdapter.convert(from, ...getSubValuePathAndContext(valuePath, context));
856
+ },
857
+ create: (valuePath, context) => {
858
+ return subAdapter.create(...getSubValuePathAndContext(valuePath, context));
859
+ },
860
+ revert: subAdapter.revert && ((from, valuePath, context) => {
861
+ return subAdapter.revert(from, ...getSubValuePathAndContext(valuePath, context));
862
+ })
863
+ };
864
+ acc[typePath] = adaptedAdapter;
827
865
  return acc;
828
866
  }, {});
829
867
  }
@@ -860,7 +898,7 @@ var IntegerToStringConverter = class {
860
898
  };
861
899
 
862
900
  // field_converters/nullable_to_boolean_converter.ts
863
- var import_define3 = require("@strictly/define");
901
+ var import_define4 = require("@strictly/define");
864
902
  var NullableToBooleanConverter = class {
865
903
  constructor(typeDef, prototype, nullType, defaultToNull = true) {
866
904
  this.typeDef = typeDef;
@@ -878,7 +916,7 @@ var NullableToBooleanConverter = class {
878
916
  }
879
917
  revert(from) {
880
918
  if (from) {
881
- const value = (0, import_define3.copy)(this.typeDef, this.prototype);
919
+ const value = (0, import_define4.copy)(this.typeDef, this.prototype);
882
920
  return {
883
921
  type: 0 /* Success */,
884
922
  value
@@ -896,7 +934,7 @@ var NullableToBooleanConverter = class {
896
934
 
897
935
  // field_converters/select_value_type_converter.ts
898
936
  var import_base5 = require("@strictly/base");
899
- var import_define4 = require("@strictly/define");
937
+ var import_define5 = require("@strictly/define");
900
938
  var AbstractSelectValueTypeConverter = class {
901
939
  constructor(typeDef, values, defaultValueKey, noSuchValueError, required) {
902
940
  this.typeDef = typeDef;
@@ -914,7 +952,7 @@ var AbstractSelectValueTypeConverter = class {
914
952
  value: null
915
953
  };
916
954
  }
917
- const value = prototype == null ? prototype : (0, import_define4.copy)(this.typeDef, prototype);
955
+ const value = prototype == null ? prototype : (0, import_define5.copy)(this.typeDef, prototype);
918
956
  return {
919
957
  type: 0 /* Success */,
920
958
  value
@@ -1007,13 +1045,13 @@ var TrimmingStringConverter = class {
1007
1045
  };
1008
1046
 
1009
1047
  // field_converters/validating_converter.ts
1010
- var import_define5 = require("@strictly/define");
1048
+ var import_define6 = require("@strictly/define");
1011
1049
  function validatingConverter(validators = []) {
1012
1050
  return function(value, valuePath, context) {
1013
1051
  return validators.reduce(
1014
1052
  function(acc, validator) {
1015
1053
  if (acc.type === 0 /* Success */) {
1016
- const error = (0, import_define5.validate)(validator, value, valuePath, context);
1054
+ const error = (0, import_define6.validate)(validator, value, valuePath, context);
1017
1055
  if (error != null) {
1018
1056
  return {
1019
1057
  type: 1 /* Failure */,
@@ -1037,7 +1075,7 @@ function DefaultErrorRenderer({
1037
1075
  error
1038
1076
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1039
1077
  }) {
1040
- return error;
1078
+ return JSON.stringify(error);
1041
1079
  }
1042
1080
 
1043
1081
  // mantine/hooks.tsx
@@ -1268,15 +1306,19 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
1268
1306
  observableProps.onFieldSubmit?.(toKey(subKey));
1269
1307
  }
1270
1308
  return (0, import_mobx_react2.observer)(function(props) {
1271
- const subFields = Object.entries(observableProps.fields).reduce((acc, [
1272
- fieldKey,
1273
- fieldValue
1274
- ]) => {
1275
- if (fieldKey.startsWith(valuePath)) {
1276
- acc[toSubKey(fieldKey)] = fieldValue;
1277
- }
1278
- return acc;
1279
- }, {});
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
+ );
1280
1322
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1281
1323
  FieldsView,
1282
1324
  {
@@ -1432,13 +1474,16 @@ function createTextInput(valuePath, TextInput) {
1432
1474
  const propSource = ({
1433
1475
  ErrorRenderer = DefaultErrorRenderer
1434
1476
  }) => {
1477
+ const field = this.fields[valuePath];
1478
+ if (field == null) {
1479
+ throw new Error(`invalid field ${valuePath}`);
1480
+ }
1435
1481
  const {
1436
1482
  readonly,
1437
1483
  required,
1438
1484
  value,
1439
1485
  error
1440
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1441
- } = this.fields[valuePath];
1486
+ } = field;
1442
1487
  return {
1443
1488
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1444
1489
  name: valuePath,
@@ -1674,7 +1719,7 @@ var MantineFormImpl = class {
1674
1719
  };
1675
1720
 
1676
1721
  // types/merge_validators.ts
1677
- var import_define6 = require("@strictly/define");
1722
+ var import_define7 = require("@strictly/define");
1678
1723
  function mergeValidators(validators1, validators2) {
1679
1724
  const validators = {
1680
1725
  ...validators1,
@@ -1689,16 +1734,16 @@ function mergeValidators(validators1, validators2) {
1689
1734
  validators3[key] = {
1690
1735
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1691
1736
  validate: function(value, valuePath, context) {
1692
- const error = (0, import_define6.validate)(validator1, value, valuePath, context);
1737
+ const error = (0, import_define7.validate)(validator1, value, valuePath, context);
1693
1738
  if (error != null) {
1694
1739
  return error;
1695
1740
  }
1696
- return (0, import_define6.validate)(validator2, value, valuePath, context);
1741
+ return (0, import_define7.validate)(validator2, value, valuePath, context);
1697
1742
  },
1698
1743
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1699
1744
  annotations: function(valuePath, context) {
1700
- const annotations1 = (0, import_define6.annotations)(validator1, valuePath, context);
1701
- const annotations22 = (0, import_define6.annotations)(validator2, valuePath, context);
1745
+ const annotations1 = (0, import_define7.annotations)(validator1, valuePath, context);
1746
+ const annotations22 = (0, import_define7.annotations)(validator2, valuePath, context);
1702
1747
  return {
1703
1748
  readonly: annotations1.readonly || annotations22.readonly,
1704
1749
  required: annotations1.required || annotations22.required
package/dist/index.d.cts 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,10 +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 SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
208
- [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K];
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>;
209
214
  };
210
- declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(subAdapters: SubAdapters, prefix: P): SubFormFieldAdapters<SubAdapters, P>;
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>>;
211
216
 
212
217
  declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
213
218
  private readonly isNanError;
@@ -217,14 +222,14 @@ declare class IntegerToStringConverter<E, ValuePath extends string, Context> imp
217
222
  revert(from: string): UnreliableFieldConversion<number, E>;
218
223
  }
219
224
 
220
- 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> {
221
226
  private readonly typeDef;
222
227
  private readonly prototype;
223
228
  private readonly nullType;
224
229
  readonly defaultValue: ValueOfType<ReadonlyTypeOfType<T>> | NullType;
225
230
  constructor(typeDef: T, prototype: ValueOfType<ReadonlyTypeOfType<T>>, nullType: NullType, defaultToNull?: boolean);
226
231
  convert(from: ValueOfType<ReadonlyTypeOfType<T>> | NullType): AnnotatedFieldConversion<boolean>;
227
- revert(from: boolean): UnreliableFieldConversion<ValueOfType<ReadonlyTypeOfType<T>> | NullType, E>;
232
+ revert(from: boolean): UnreliableFieldConversion<ValueOfType<ReadonlyTypeOfType<T>> | NullType, never>;
228
233
  create(): ValueOfType<ReadonlyTypeOfType<T>> | NullType;
229
234
  }
230
235
 
@@ -268,7 +273,7 @@ type ErrorRendererProps<E> = {
268
273
  error: E;
269
274
  };
270
275
  type ErrorRenderer<E = any> = ComponentType<ErrorRendererProps<E>>;
271
- declare function DefaultErrorRenderer({ error, }: ErrorRendererProps<any>): any;
276
+ declare function DefaultErrorRenderer({ error, }: ErrorRendererProps<any>): string;
272
277
 
273
278
  type ValueTypeOfField<F extends Field> = F extends Field<infer V> ? V : never;
274
279
 
@@ -318,8 +323,10 @@ type MantineForm<F extends Fields> = {
318
323
  onFieldBlur: ((this: void, key: keyof F) => void) | undefined;
319
324
  onFieldSubmit: ((this: void, key: keyof F) => boolean | void) | undefined;
320
325
  };
321
- type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<ComponentType<P>, T, {
322
- ErrorRenderer?: ErrorRenderer<E>;
326
+ type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<ComponentType<P>, T, [
327
+ E
328
+ ] extends [never] ? {} : {
329
+ ErrorRenderer: ErrorRenderer<E>;
323
330
  }>;
324
331
 
325
332
  type SuppliedCheckboxProps = Pick<CheckboxProps, 'name' | 'checked' | 'disabled' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
@@ -383,21 +390,21 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
383
390
  onFieldBlur: ((this: void, key: keyof F) => void) | undefined;
384
391
  onFieldSubmit: ((this: void, key: keyof F) => boolean | void) | undefined;
385
392
  constructor(fields: F);
386
- textInput<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, TextInputProps>;
387
- 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]>>;
388
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]>>;
389
396
  select<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, ComponentProps<typeof SimpleSelect>, ErrorOfField<F[K]>>;
390
- 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]>>;
391
398
  checkbox<K extends keyof BooleanFieldsOfFields<F>, P extends SuppliedCheckboxProps>(valuePath: K, Checkbox: ComponentType<P>): MantineFieldComponent<SuppliedCheckboxProps, P, ErrorOfField<F[K]>>;
392
- radioGroup<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedRadioGroupProps, RadioGroupProps>;
393
- 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]>>;
394
401
  radio<K extends keyof StringFieldsOfFields<F>>(valuePath: K, value: ValueTypeOfField<F[K]>): MantineFieldComponent<SuppliedRadioProps, RadioProps, ErrorOfField<F[K]>>;
395
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]>>;
396
403
  pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
397
- pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P>;
398
- list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>>;
399
- fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): MantineFieldComponent<FieldsViewProps<P['fields']>, P>;
400
- 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>;
401
408
  }
402
409
 
403
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.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,10 +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 SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string> = {
208
- [K in keyof SubAdapters as K extends StringConcatOf<'$', infer S> ? `${P}${S}` : never]: SubAdapters[K];
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>;
209
214
  };
210
- declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, P extends string>(subAdapters: SubAdapters, prefix: P): SubFormFieldAdapters<SubAdapters, P>;
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>>;
211
216
 
212
217
  declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
213
218
  private readonly isNanError;
@@ -217,14 +222,14 @@ declare class IntegerToStringConverter<E, ValuePath extends string, Context> imp
217
222
  revert(from: string): UnreliableFieldConversion<number, E>;
218
223
  }
219
224
 
220
- 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> {
221
226
  private readonly typeDef;
222
227
  private readonly prototype;
223
228
  private readonly nullType;
224
229
  readonly defaultValue: ValueOfType<ReadonlyTypeOfType<T>> | NullType;
225
230
  constructor(typeDef: T, prototype: ValueOfType<ReadonlyTypeOfType<T>>, nullType: NullType, defaultToNull?: boolean);
226
231
  convert(from: ValueOfType<ReadonlyTypeOfType<T>> | NullType): AnnotatedFieldConversion<boolean>;
227
- revert(from: boolean): UnreliableFieldConversion<ValueOfType<ReadonlyTypeOfType<T>> | NullType, E>;
232
+ revert(from: boolean): UnreliableFieldConversion<ValueOfType<ReadonlyTypeOfType<T>> | NullType, never>;
228
233
  create(): ValueOfType<ReadonlyTypeOfType<T>> | NullType;
229
234
  }
230
235
 
@@ -268,7 +273,7 @@ type ErrorRendererProps<E> = {
268
273
  error: E;
269
274
  };
270
275
  type ErrorRenderer<E = any> = ComponentType<ErrorRendererProps<E>>;
271
- declare function DefaultErrorRenderer({ error, }: ErrorRendererProps<any>): any;
276
+ declare function DefaultErrorRenderer({ error, }: ErrorRendererProps<any>): string;
272
277
 
273
278
  type ValueTypeOfField<F extends Field> = F extends Field<infer V> ? V : never;
274
279
 
@@ -318,8 +323,10 @@ type MantineForm<F extends Fields> = {
318
323
  onFieldBlur: ((this: void, key: keyof F) => void) | undefined;
319
324
  onFieldSubmit: ((this: void, key: keyof F) => boolean | void) | undefined;
320
325
  };
321
- type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<ComponentType<P>, T, {
322
- ErrorRenderer?: ErrorRenderer<E>;
326
+ type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<ComponentType<P>, T, [
327
+ E
328
+ ] extends [never] ? {} : {
329
+ ErrorRenderer: ErrorRenderer<E>;
323
330
  }>;
324
331
 
325
332
  type SuppliedCheckboxProps = Pick<CheckboxProps, 'name' | 'checked' | 'disabled' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
@@ -383,21 +390,21 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
383
390
  onFieldBlur: ((this: void, key: keyof F) => void) | undefined;
384
391
  onFieldSubmit: ((this: void, key: keyof F) => boolean | void) | undefined;
385
392
  constructor(fields: F);
386
- textInput<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, TextInputProps>;
387
- 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]>>;
388
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]>>;
389
396
  select<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedTextInputProps, ComponentProps<typeof SimpleSelect>, ErrorOfField<F[K]>>;
390
- 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]>>;
391
398
  checkbox<K extends keyof BooleanFieldsOfFields<F>, P extends SuppliedCheckboxProps>(valuePath: K, Checkbox: ComponentType<P>): MantineFieldComponent<SuppliedCheckboxProps, P, ErrorOfField<F[K]>>;
392
- radioGroup<K extends keyof StringFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedRadioGroupProps, RadioGroupProps>;
393
- 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]>>;
394
401
  radio<K extends keyof StringFieldsOfFields<F>>(valuePath: K, value: ValueTypeOfField<F[K]>): MantineFieldComponent<SuppliedRadioProps, RadioProps, ErrorOfField<F[K]>>;
395
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]>>;
396
403
  pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
397
- pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P>;
398
- list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>>;
399
- fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): MantineFieldComponent<FieldsViewProps<P['fields']>, P>;
400
- 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>;
401
408
  }
402
409
 
403
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
 
@@ -790,13 +806,37 @@ function mergeAdaptersWithValidators(adapters, validators) {
790
806
  }
791
807
 
792
808
  // core/mobx/sub_form_field_adapters.ts
793
- function subFormFieldAdapters(subAdapters, prefix) {
809
+ import {
810
+ flattenValuesOfType as flattenValuesOfType2
811
+ } from "@strictly/define";
812
+ function subFormFieldAdapters(subAdapters, parentTypePath, contextType) {
813
+ const dotCount = parentTypePath.split(".").length;
814
+ function getSubValuePathAndContext(valuePath, context) {
815
+ const parentValuePath = valuePath.split(".").slice(0, dotCount).join(".");
816
+ const subValuePath = valuePath.replace(parentValuePath, "$");
817
+ const subContext = flattenValuesOfType2(contextType, context)[parentValuePath];
818
+ return [
819
+ subValuePath,
820
+ subContext
821
+ ];
822
+ }
794
823
  return Object.entries(subAdapters).reduce((acc, [
795
- subKey,
796
- subValue
824
+ subTypePath,
825
+ subAdapter
797
826
  ]) => {
798
- const key = subKey.replace("$", prefix);
799
- acc[key] = subValue;
827
+ const typePath = subTypePath.replace("$", parentTypePath);
828
+ const adaptedAdapter = {
829
+ convert: (from, valuePath, context) => {
830
+ return subAdapter.convert(from, ...getSubValuePathAndContext(valuePath, context));
831
+ },
832
+ create: (valuePath, context) => {
833
+ return subAdapter.create(...getSubValuePathAndContext(valuePath, context));
834
+ },
835
+ revert: subAdapter.revert && ((from, valuePath, context) => {
836
+ return subAdapter.revert(from, ...getSubValuePathAndContext(valuePath, context));
837
+ })
838
+ };
839
+ acc[typePath] = adaptedAdapter;
800
840
  return acc;
801
841
  }, {});
802
842
  }
@@ -1018,7 +1058,7 @@ function DefaultErrorRenderer({
1018
1058
  error
1019
1059
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1020
1060
  }) {
1021
- return error;
1061
+ return JSON.stringify(error);
1022
1062
  }
1023
1063
 
1024
1064
  // mantine/hooks.tsx
@@ -1266,15 +1306,19 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
1266
1306
  observableProps.onFieldSubmit?.(toKey(subKey));
1267
1307
  }
1268
1308
  return observer2(function(props) {
1269
- const subFields = Object.entries(observableProps.fields).reduce((acc, [
1270
- fieldKey,
1271
- fieldValue
1272
- ]) => {
1273
- if (fieldKey.startsWith(valuePath)) {
1274
- acc[toSubKey(fieldKey)] = fieldValue;
1275
- }
1276
- return acc;
1277
- }, {});
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
+ );
1278
1322
  return /* @__PURE__ */ jsx3(
1279
1323
  FieldsView,
1280
1324
  {
@@ -1432,13 +1476,16 @@ function createTextInput(valuePath, TextInput) {
1432
1476
  const propSource = ({
1433
1477
  ErrorRenderer = DefaultErrorRenderer
1434
1478
  }) => {
1479
+ const field = this.fields[valuePath];
1480
+ if (field == null) {
1481
+ throw new Error(`invalid field ${valuePath}`);
1482
+ }
1435
1483
  const {
1436
1484
  readonly,
1437
1485
  required,
1438
1486
  value,
1439
1487
  error
1440
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1441
- } = this.fields[valuePath];
1488
+ } = field;
1442
1489
  return {
1443
1490
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1444
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
  }