@strictly/react-form 0.0.34 → 0.0.36

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.
@@ -1,5 +1,5 @@
1
1
  import { type FriendlyExhaustiveArrayOfUnion } from '@strictly/base';
2
- import { type ComponentProps, type ComponentType, type DependencyList, type ForwardRefExoticComponent, type PropsWithoutRef, type Ref, type RefAttributes } from 'react';
2
+ import { type ComponentProps, type ComponentType, type DependencyList, type ForwardRefExoticComponent, type JSX, type PropsWithoutRef, type Ref, type RefAttributes } from 'react';
3
3
  export type RefOfProps<P, Fallback = unknown> = P extends RefAttributes<infer R> ? R : Fallback;
4
4
  export type PartialComponent<Component extends ComponentType<any>, CurriedProps, AdditionalProps = {}> = Exclude<keyof CurriedProps, keyof ComponentProps<Component>> extends never ? UnsafePartialComponent<Component, CurriedProps, AdditionalProps> : keyof CurriedProps extends (string | number) ? `unmatched prop: ${Exclude<keyof CurriedProps, keyof ComponentProps<Component>>}` : Exclude<keyof CurriedProps, keyof ComponentProps<Component>>;
5
5
  export type UnsafePartialComponent<Component extends ComponentType<any>, CurriedProps, AdditionalProps = {}, R = RefOfProps<ComponentProps<Component>>> = ForwardRefExoticComponent<PropsWithoutRef<RemainingComponentProps<Component, CurriedProps> & AdditionalProps> & {
@@ -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 60.01 KB
11
- ESM ⚡️ Build success in 127ms
12
- CJS dist/index.cjs 64.19 KB
13
- CJS ⚡️ Build success in 158ms
10
+ CJS dist/index.cjs 64.40 KB
11
+ CJS ⚡️ Build success in 140ms
12
+ ESM dist/index.js 60.22 KB
13
+ ESM ⚡️ Build success in 155ms
14
14
  DTS Build start
15
- DTS ⚡️ Build success in 6824ms
16
- DTS dist/index.d.cts 38.69 KB
17
- DTS dist/index.d.ts 38.69 KB
18
- Done in 8.27s.
15
+ DTS ⚡️ Build success in 5375ms
16
+ DTS dist/index.d.cts 39.00 KB
17
+ DTS dist/index.d.ts 39.00 KB
18
+ Done in 6.87s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ tsc -b
3
- Done in 0.41s.
3
+ Done in 0.32s.
@@ -134,6 +134,10 @@ export type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string
134
134
 
135
135
  export type FormMode = 'edit' | 'create'
136
136
 
137
+ export type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
138
+ forPath(value: V, valuePath: ValuePath): ContextType,
139
+ }
140
+
137
141
  export abstract class FormModel<
138
142
  T extends Type,
139
143
  ValueToTypePaths extends Readonly<Record<string, string>>,
@@ -169,6 +173,11 @@ export abstract class FormModel<
169
173
  readonly type: T,
170
174
  private readonly originalValue: ValueOfType<ReadonlyTypeOfType<T>>,
171
175
  protected readonly adapters: TypePathsToAdapters,
176
+ protected readonly contextSource: FormModelContextSource<
177
+ ContextType,
178
+ ValueOfType<ReadonlyTypeOfType<T>>,
179
+ keyof ValuePathsToAdapters
180
+ >,
172
181
  protected readonly mode: FormMode,
173
182
  ) {
174
183
  this.originalValues = flattenValuesOfType<ReadonlyTypeOfType<T>>(type, originalValue, this.listIndicesToKeys)
@@ -188,7 +197,7 @@ export abstract class FormModel<
188
197
  valuePath,
189
198
  ): AnnotatedFieldConversion<FieldOverride> | undefined => {
190
199
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
191
- const contextValue = this.toContext(originalValue, valuePath as keyof ValuePathsToAdapters)
200
+ const contextValue = contextSource.forPath(originalValue, valuePath as keyof ValuePathsToAdapters)
192
201
 
193
202
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
194
203
  const adapter = this.adapters[typePath as keyof TypePathsToAdapters]
@@ -214,11 +223,6 @@ export abstract class FormModel<
214
223
  }) as FlattenedFieldOverrides<ValuePathsToAdapters>
215
224
  }
216
225
 
217
- protected abstract toContext(
218
- value: ValueOfType<ReadonlyTypeOfType<T>>,
219
- valuePath: keyof ValuePathsToAdapters,
220
- ): ContextType
221
-
222
226
  get forceMutableFields() {
223
227
  switch (this.mode) {
224
228
  case 'create':
@@ -310,7 +314,7 @@ export abstract class FormModel<
310
314
  const accessor = this.getAccessorForValuePath(valuePath)
311
315
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
312
316
  const fieldTypeDef = this.flattenedTypeDefs[typePath as string]
313
- const context = this.toContext(this.observableValue, valuePath)
317
+ const context = this.contextSource.forPath(this.observableValue, valuePath)
314
318
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
315
319
  const defaultValue = create(valuePath as string, context)
316
320
 
@@ -499,7 +503,7 @@ export abstract class FormModel<
499
503
  elementTypePath as string,
500
504
  // TODO what can we use for the value path here?
501
505
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
502
- this.toContext(this.observableValue, valuePath as unknown as keyof ValuePathsToAdapters),
506
+ this.contextSource.forPath(this.observableValue, valuePath as unknown as keyof ValuePathsToAdapters),
503
507
  )
504
508
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
505
509
  const originalList: any[] = accessor.value
@@ -569,7 +573,7 @@ export abstract class FormModel<
569
573
  assertExists(revert, 'setting value not supported {}', valuePath)
570
574
 
571
575
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
572
- const conversion = revert(value, valuePath as any, this.toContext(this.observableValue, valuePath))
576
+ const conversion = revert(value, valuePath as any, this.contextSource.forPath(this.observableValue, valuePath))
573
577
  const accessor = this.getAccessorForValuePath(valuePath)
574
578
  return runInAction(() => {
575
579
  this.fieldOverrides[valuePath] = [value]
@@ -631,8 +635,9 @@ export abstract class FormModel<
631
635
  convert,
632
636
  create,
633
637
  } = adapter
634
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
635
- const context = this.toContext(this.observableValue, valuePath as unknown as keyof ValuePathsToAdapters)
638
+
639
+ const context = this.contextSource.forPath(this.observableValue, // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
640
+ valuePath as unknown as keyof ValuePathsToAdapters)
636
641
  const value = create(valuePath, context)
637
642
  const {
638
643
  value: displayValue,
@@ -7,6 +7,7 @@ import {
7
7
  nullType,
8
8
  numberType,
9
9
  object,
10
+ type ReadonlyTypeOfType,
10
11
  record,
11
12
  stringType,
12
13
  type Type,
@@ -24,7 +25,9 @@ import {
24
25
  } from 'core/mobx/fieldAdapterBuilder'
25
26
  import {
26
27
  type FlattenedTypePathsToAdaptersOf,
28
+ type FormMode,
27
29
  FormModel,
30
+ type FormModelContextSource,
28
31
  Validation,
29
32
  type ValuePathsToAdaptersOf,
30
33
  } from 'core/mobx/FormModel'
@@ -54,6 +57,19 @@ const originalIntegerToStringAdapter = adapterFromTwoWayConverter(
54
57
 
55
58
  const originalBooleanToBooleanAdapter = identityAdapter(false)
56
59
 
60
+ class TestFormContextSource<V, ValuePath extends string | number | symbol> implements FormModelContextSource<
61
+ {},
62
+ V,
63
+ ValuePath
64
+ > {
65
+ forPath(value: V, valuePath: ValuePath): {} {
66
+ return {
67
+ value,
68
+ valuePath,
69
+ }
70
+ }
71
+ }
72
+
57
73
  class TestFormModel<
58
74
  T extends Type,
59
75
  ValueToTypePaths extends Readonly<Record<string, string>>,
@@ -62,14 +78,13 @@ class TestFormModel<
62
78
  {}
63
79
  >,
64
80
  > extends FormModel<T, ValueToTypePaths, TypePathsToAdapters, {}> {
65
- override toContext(
66
- value: ValueOfType<T>,
67
- valuePath: keyof ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>,
81
+ constructor(
82
+ type: T,
83
+ originalValue: ValueOfType<ReadonlyTypeOfType<T>>,
84
+ adapters: TypePathsToAdapters,
85
+ mode: FormMode,
68
86
  ) {
69
- return {
70
- value,
71
- valuePath,
72
- }
87
+ super(type, originalValue, adapters, new TestFormContextSource(), mode)
73
88
  }
74
89
 
75
90
  setFieldValueAndValidate<K extends keyof ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>>(
package/dist/index.cjs CHANGED
@@ -367,10 +367,11 @@ var Validation = /* @__PURE__ */ ((Validation2) => {
367
367
  var _validateAll_dec, _validateField_dec, _setFieldValue_dec, _valueChanged_dec, _dirty_dec, _accessors_dec, _knownFields_dec, _fields_dec, _value_dec, _validation_dec, _errorOverrides_dec, _fieldOverrides_dec, _observableValue_dec, _init, _observableValue, _fieldOverrides, _errorOverrides, _validation;
368
368
  _observableValue_dec = [import_mobx.observable.ref], _fieldOverrides_dec = [import_mobx.observable.shallow], _errorOverrides_dec = [import_mobx.observable.shallow], _validation_dec = [import_mobx.observable.shallow], _value_dec = [import_mobx.computed], _fields_dec = [import_mobx.computed], _knownFields_dec = [import_mobx.computed], _accessors_dec = [import_mobx.computed], _dirty_dec = [import_mobx.computed], _valueChanged_dec = [import_mobx.computed], _setFieldValue_dec = [import_mobx.action], _validateField_dec = [import_mobx.action], _validateAll_dec = [import_mobx.action];
369
369
  var FormModel = class {
370
- constructor(type, originalValue, adapters, mode) {
370
+ constructor(type, originalValue, adapters, contextSource, mode) {
371
371
  this.type = type;
372
372
  this.originalValue = originalValue;
373
373
  this.adapters = adapters;
374
+ this.contextSource = contextSource;
374
375
  this.mode = mode;
375
376
  __runInitializers(_init, 5, this);
376
377
  __privateAdd(this, _observableValue, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
@@ -392,7 +393,7 @@ var FormModel = class {
392
393
  () => {
393
394
  },
394
395
  (_t, fieldValue, _setter, typePath, valuePath) => {
395
- const contextValue = this.toContext(originalValue, valuePath);
396
+ const contextValue = contextSource.forPath(originalValue, valuePath);
396
397
  const adapter2 = this.adapters[typePath];
397
398
  if (adapter2 == null) {
398
399
  return;
@@ -486,7 +487,7 @@ var FormModel = class {
486
487
  const fieldOverride = this.fieldOverrides[valuePath];
487
488
  const accessor = this.getAccessorForValuePath(valuePath);
488
489
  const fieldTypeDef = this.flattenedTypeDefs[typePath];
489
- const context = this.toContext(this.observableValue, valuePath);
490
+ const context = this.contextSource.forPath(this.observableValue, valuePath);
490
491
  const defaultValue = create(valuePath, context);
491
492
  const {
492
493
  value,
@@ -627,7 +628,7 @@ var FormModel = class {
627
628
  elementTypePath,
628
629
  // TODO what can we use for the value path here?
629
630
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
630
- this.toContext(this.observableValue, valuePath)
631
+ this.contextSource.forPath(this.observableValue, valuePath)
631
632
  );
632
633
  const originalList = accessor.value;
633
634
  const newList = [
@@ -682,7 +683,7 @@ var FormModel = class {
682
683
  internalSetFieldValue(valuePath, value, validation) {
683
684
  const { revert } = this.getAdapterForValuePath(valuePath);
684
685
  (0, import_base2.assertExists)(revert, "setting value not supported {}", valuePath);
685
- const conversion = revert(value, valuePath, this.toContext(this.observableValue, valuePath));
686
+ const conversion = revert(value, valuePath, this.contextSource.forPath(this.observableValue, valuePath));
686
687
  const accessor = this.getAccessorForValuePath(valuePath);
687
688
  return (0, import_mobx.runInAction)(() => {
688
689
  this.fieldOverrides[valuePath] = [value];
@@ -737,7 +738,11 @@ var FormModel = class {
737
738
  convert,
738
739
  create
739
740
  } = adapter2;
740
- const context = this.toContext(this.observableValue, valuePath);
741
+ const context = this.contextSource.forPath(
742
+ this.observableValue,
743
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
744
+ valuePath
745
+ );
741
746
  const value = create(valuePath, context);
742
747
  const {
743
748
  value: displayValue
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Maybe, ElementOfArray, StringConcatOf, StringKeyOf as StringKeyOf$1, ExhaustiveArrayOfUnion, FriendlyExhaustiveArrayOfUnion } from '@strictly/base';
2
2
  import { Type, ValueOfType, ReadonlyTypeOfType, FlattenedTypesOfType, ListTypeDef, FlattenedValuesOfType, Accessor, Validator, UnionTypeDef, ValueTypesOfDiscriminatedUnion, LiteralTypeDef } from '@strictly/define';
3
3
  import { ValueOf, SimplifyDeep, ReadonlyDeep, UnionToIntersection, StringKeyOf, Simplify } from 'type-fest';
4
- import { ComponentType, RefAttributes, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, Ref, DependencyList } from 'react';
4
+ import { ComponentType, RefAttributes, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, Ref, DependencyList, JSX } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { CheckboxProps, PillProps, RadioProps, RadioGroupProps, TextInputProps, SelectProps } from '@mantine/core';
7
7
  import { Observer } from 'mobx-react';
@@ -132,10 +132,14 @@ type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, Field
132
132
  readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : unknown extends ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>> ? never : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
133
133
  }[keyof TypePathsToAdapters] | {}>;
134
134
  type FormMode = 'edit' | 'create';
135
+ type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
136
+ forPath(value: V, valuePath: ValuePath): ContextType;
137
+ };
135
138
  declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record<string, string>>, TypePathsToAdapters extends FlattenedTypePathsToAdaptersOf<FlattenedValuesOfType<T, '*'>, ContextType>, ContextType = ContextOf<TypePathsToAdapters>, ValuePathsToAdapters extends ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths> = ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>> {
136
139
  readonly type: T;
137
140
  private readonly originalValue;
138
141
  protected readonly adapters: TypePathsToAdapters;
142
+ protected readonly contextSource: FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, keyof ValuePathsToAdapters>;
139
143
  protected readonly mode: FormMode;
140
144
  private accessor observableValue;
141
145
  accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
@@ -144,8 +148,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
144
148
  private readonly flattenedTypeDefs;
145
149
  private readonly originalValues;
146
150
  private readonly listIndicesToKeys;
147
- constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
148
- protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
151
+ constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, contextSource: FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, keyof ValuePathsToAdapters>, mode: FormMode);
149
152
  get forceMutableFields(): boolean;
150
153
  get value(): ValueOfType<ReadonlyTypeOfType<T>>;
151
154
  get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
@@ -468,4 +471,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
468
471
 
469
472
  declare function Empty(): null;
470
473
 
471
- export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, type ContextOf, type ContextOfFieldAdapter, DefaultErrorRenderer, Empty, type ErrorOfField, type ErrorOfFieldAdapter, type ErrorRenderer, type ErrorRendererProps, type Field, type FieldAdapter, type FieldAdaptersOfValues, type FieldValueFactory, type Fields, type FieldsViewProps, type FlattenedAdaptersOfFields, type FlattenedConvertedFieldsOf, type FlattenedTypePathsToAdaptersOf, type FormFieldsOfFieldAdapters, type FormMode, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, type RefOfProps, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, Validation, type ValuePathOfFieldAdapter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, peek, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
474
+ export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, type ContextOf, type ContextOfFieldAdapter, DefaultErrorRenderer, Empty, type ErrorOfField, type ErrorOfFieldAdapter, type ErrorRenderer, type ErrorRendererProps, type Field, type FieldAdapter, type FieldAdaptersOfValues, type FieldValueFactory, type Fields, type FieldsViewProps, type FlattenedAdaptersOfFields, type FlattenedConvertedFieldsOf, type FlattenedTypePathsToAdaptersOf, type FormFieldsOfFieldAdapters, type FormMode, FormModel, type FormModelContextSource, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, type RefOfProps, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, Validation, type ValuePathOfFieldAdapter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, peek, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Maybe, ElementOfArray, StringConcatOf, StringKeyOf as StringKeyOf$1, ExhaustiveArrayOfUnion, FriendlyExhaustiveArrayOfUnion } from '@strictly/base';
2
2
  import { Type, ValueOfType, ReadonlyTypeOfType, FlattenedTypesOfType, ListTypeDef, FlattenedValuesOfType, Accessor, Validator, UnionTypeDef, ValueTypesOfDiscriminatedUnion, LiteralTypeDef } from '@strictly/define';
3
3
  import { ValueOf, SimplifyDeep, ReadonlyDeep, UnionToIntersection, StringKeyOf, Simplify } from 'type-fest';
4
- import { ComponentType, RefAttributes, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, Ref, DependencyList } from 'react';
4
+ import { ComponentType, RefAttributes, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, Ref, DependencyList, JSX } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { CheckboxProps, PillProps, RadioProps, RadioGroupProps, TextInputProps, SelectProps } from '@mantine/core';
7
7
  import { Observer } from 'mobx-react';
@@ -132,10 +132,14 @@ type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, Field
132
132
  readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : unknown extends ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>> ? never : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
133
133
  }[keyof TypePathsToAdapters] | {}>;
134
134
  type FormMode = 'edit' | 'create';
135
+ type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
136
+ forPath(value: V, valuePath: ValuePath): ContextType;
137
+ };
135
138
  declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record<string, string>>, TypePathsToAdapters extends FlattenedTypePathsToAdaptersOf<FlattenedValuesOfType<T, '*'>, ContextType>, ContextType = ContextOf<TypePathsToAdapters>, ValuePathsToAdapters extends ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths> = ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>> {
136
139
  readonly type: T;
137
140
  private readonly originalValue;
138
141
  protected readonly adapters: TypePathsToAdapters;
142
+ protected readonly contextSource: FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, keyof ValuePathsToAdapters>;
139
143
  protected readonly mode: FormMode;
140
144
  private accessor observableValue;
141
145
  accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
@@ -144,8 +148,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
144
148
  private readonly flattenedTypeDefs;
145
149
  private readonly originalValues;
146
150
  private readonly listIndicesToKeys;
147
- constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
148
- protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
151
+ constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, contextSource: FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, keyof ValuePathsToAdapters>, mode: FormMode);
149
152
  get forceMutableFields(): boolean;
150
153
  get value(): ValueOfType<ReadonlyTypeOfType<T>>;
151
154
  get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
@@ -468,4 +471,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
468
471
 
469
472
  declare function Empty(): null;
470
473
 
471
- export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, type ContextOf, type ContextOfFieldAdapter, DefaultErrorRenderer, Empty, type ErrorOfField, type ErrorOfFieldAdapter, type ErrorRenderer, type ErrorRendererProps, type Field, type FieldAdapter, type FieldAdaptersOfValues, type FieldValueFactory, type Fields, type FieldsViewProps, type FlattenedAdaptersOfFields, type FlattenedConvertedFieldsOf, type FlattenedTypePathsToAdaptersOf, type FormFieldsOfFieldAdapters, type FormMode, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, type RefOfProps, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, Validation, type ValuePathOfFieldAdapter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, peek, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
474
+ export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, type ContextOf, type ContextOfFieldAdapter, DefaultErrorRenderer, Empty, type ErrorOfField, type ErrorOfFieldAdapter, type ErrorRenderer, type ErrorRendererProps, type Field, type FieldAdapter, type FieldAdaptersOfValues, type FieldValueFactory, type Fields, type FieldsViewProps, type FlattenedAdaptersOfFields, type FlattenedConvertedFieldsOf, type FlattenedTypePathsToAdaptersOf, type FormFieldsOfFieldAdapters, type FormMode, FormModel, type FormModelContextSource, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, type RefOfProps, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, Validation, type ValuePathOfFieldAdapter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, peek, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
package/dist/index.js CHANGED
@@ -337,10 +337,11 @@ var Validation = /* @__PURE__ */ ((Validation2) => {
337
337
  var _validateAll_dec, _validateField_dec, _setFieldValue_dec, _valueChanged_dec, _dirty_dec, _accessors_dec, _knownFields_dec, _fields_dec, _value_dec, _validation_dec, _errorOverrides_dec, _fieldOverrides_dec, _observableValue_dec, _init, _observableValue, _fieldOverrides, _errorOverrides, _validation;
338
338
  _observableValue_dec = [observable.ref], _fieldOverrides_dec = [observable.shallow], _errorOverrides_dec = [observable.shallow], _validation_dec = [observable.shallow], _value_dec = [computed], _fields_dec = [computed], _knownFields_dec = [computed], _accessors_dec = [computed], _dirty_dec = [computed], _valueChanged_dec = [computed], _setFieldValue_dec = [action], _validateField_dec = [action], _validateAll_dec = [action];
339
339
  var FormModel = class {
340
- constructor(type, originalValue, adapters, mode) {
340
+ constructor(type, originalValue, adapters, contextSource, mode) {
341
341
  this.type = type;
342
342
  this.originalValue = originalValue;
343
343
  this.adapters = adapters;
344
+ this.contextSource = contextSource;
344
345
  this.mode = mode;
345
346
  __runInitializers(_init, 5, this);
346
347
  __privateAdd(this, _observableValue, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
@@ -362,7 +363,7 @@ var FormModel = class {
362
363
  () => {
363
364
  },
364
365
  (_t, fieldValue, _setter, typePath, valuePath) => {
365
- const contextValue = this.toContext(originalValue, valuePath);
366
+ const contextValue = contextSource.forPath(originalValue, valuePath);
366
367
  const adapter2 = this.adapters[typePath];
367
368
  if (adapter2 == null) {
368
369
  return;
@@ -456,7 +457,7 @@ var FormModel = class {
456
457
  const fieldOverride = this.fieldOverrides[valuePath];
457
458
  const accessor = this.getAccessorForValuePath(valuePath);
458
459
  const fieldTypeDef = this.flattenedTypeDefs[typePath];
459
- const context = this.toContext(this.observableValue, valuePath);
460
+ const context = this.contextSource.forPath(this.observableValue, valuePath);
460
461
  const defaultValue = create(valuePath, context);
461
462
  const {
462
463
  value,
@@ -597,7 +598,7 @@ var FormModel = class {
597
598
  elementTypePath,
598
599
  // TODO what can we use for the value path here?
599
600
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
600
- this.toContext(this.observableValue, valuePath)
601
+ this.contextSource.forPath(this.observableValue, valuePath)
601
602
  );
602
603
  const originalList = accessor.value;
603
604
  const newList = [
@@ -652,7 +653,7 @@ var FormModel = class {
652
653
  internalSetFieldValue(valuePath, value, validation) {
653
654
  const { revert } = this.getAdapterForValuePath(valuePath);
654
655
  assertExists(revert, "setting value not supported {}", valuePath);
655
- const conversion = revert(value, valuePath, this.toContext(this.observableValue, valuePath));
656
+ const conversion = revert(value, valuePath, this.contextSource.forPath(this.observableValue, valuePath));
656
657
  const accessor = this.getAccessorForValuePath(valuePath);
657
658
  return runInAction(() => {
658
659
  this.fieldOverrides[valuePath] = [value];
@@ -707,7 +708,11 @@ var FormModel = class {
707
708
  convert,
708
709
  create
709
710
  } = adapter2;
710
- const context = this.toContext(this.observableValue, valuePath);
711
+ const context = this.contextSource.forPath(
712
+ this.observableValue,
713
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
714
+ valuePath
715
+ );
711
716
  const value = create(valuePath, context);
712
717
  const {
713
718
  value: displayValue
package/package.json CHANGED
@@ -18,8 +18,8 @@
18
18
  "@strictly/support-vite": "*",
19
19
  "@testing-library/dom": "^10.4.0",
20
20
  "@testing-library/react": "^16.0.1",
21
- "@types/react": "^18.3.12",
22
- "@types/react-dom": "^18.3.1",
21
+ "@types/react": "^19.0.0",
22
+ "@types/react-dom": "^19.0.0",
23
23
  "@vitejs/plugin-react": "^4.3.3",
24
24
  "concurrently": "^9.1.2",
25
25
  "jsdom": "^25.0.1",
@@ -73,7 +73,7 @@
73
73
  "test:watch": "vitest"
74
74
  },
75
75
  "type": "module",
76
- "version": "0.0.34",
76
+ "version": "0.0.36",
77
77
  "exports": {
78
78
  ".": {
79
79
  "import": {
package/util/Partial.tsx CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  type ForwardedRef,
8
8
  forwardRef,
9
9
  type ForwardRefExoticComponent,
10
+ type JSX,
10
11
  type PropsWithoutRef,
11
12
  type Ref,
12
13
  type RefAttributes,