@strictly/react-form 0.0.35 → 0.0.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,12 +7,12 @@ $ tsup
7
7
  CLI Target: es6
8
8
  CJS Build start
9
9
  ESM Build start
10
- ESM dist/index.js 60.01 KB
11
- ESM ⚡️ Build success in 153ms
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 127ms
12
+ ESM dist/index.js 60.22 KB
13
+ ESM ⚡️ Build success in 128ms
14
14
  DTS Build start
15
- DTS ⚡️ Build success in 5621ms
16
- DTS dist/index.d.cts 38.70 KB
17
- DTS dist/index.d.ts 38.70 KB
18
- Done in 7.27s.
15
+ DTS ⚡️ Build success in 5539ms
16
+ DTS dist/index.d.cts 39.05 KB
17
+ DTS dist/index.d.ts 39.05 KB
18
+ Done in 6.93s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ tsc -b
3
- Done in 0.34s.
3
+ Done in 0.30s.
@@ -1,3 +1,3 @@
1
1
  yarn run v1.22.22
2
2
  $ json -f package.json -f package.exports.json --merge > package.release.json
3
- Done in 0.11s.
3
+ Done in 0.13s.
@@ -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>>,
@@ -142,6 +146,9 @@ export abstract class FormModel<
142
146
  ContextType
143
147
  >,
144
148
  ContextType = ContextOf<TypePathsToAdapters>,
149
+ ContextSource extends FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>,
150
+ keyof ValuePathsToAdapters> = FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>,
151
+ string | number | symbol>,
145
152
  ValuePathsToAdapters extends ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths> = ValuePathsToAdaptersOf<
146
153
  TypePathsToAdapters,
147
154
  ValueToTypePaths
@@ -169,6 +176,7 @@ export abstract class FormModel<
169
176
  readonly type: T,
170
177
  private readonly originalValue: ValueOfType<ReadonlyTypeOfType<T>>,
171
178
  protected readonly adapters: TypePathsToAdapters,
179
+ protected readonly contextSource: ContextSource,
172
180
  protected readonly mode: FormMode,
173
181
  ) {
174
182
  this.originalValues = flattenValuesOfType<ReadonlyTypeOfType<T>>(type, originalValue, this.listIndicesToKeys)
@@ -188,7 +196,7 @@ export abstract class FormModel<
188
196
  valuePath,
189
197
  ): AnnotatedFieldConversion<FieldOverride> | undefined => {
190
198
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
191
- const contextValue = this.toContext(originalValue, valuePath as keyof ValuePathsToAdapters)
199
+ const contextValue = contextSource.forPath(originalValue, valuePath as keyof ValuePathsToAdapters)
192
200
 
193
201
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
194
202
  const adapter = this.adapters[typePath as keyof TypePathsToAdapters]
@@ -214,11 +222,6 @@ export abstract class FormModel<
214
222
  }) as FlattenedFieldOverrides<ValuePathsToAdapters>
215
223
  }
216
224
 
217
- protected abstract toContext(
218
- value: ValueOfType<ReadonlyTypeOfType<T>>,
219
- valuePath: keyof ValuePathsToAdapters,
220
- ): ContextType
221
-
222
225
  get forceMutableFields() {
223
226
  switch (this.mode) {
224
227
  case 'create':
@@ -310,7 +313,7 @@ export abstract class FormModel<
310
313
  const accessor = this.getAccessorForValuePath(valuePath)
311
314
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
312
315
  const fieldTypeDef = this.flattenedTypeDefs[typePath as string]
313
- const context = this.toContext(this.observableValue, valuePath)
316
+ const context = this.contextSource.forPath(this.observableValue, valuePath)
314
317
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
315
318
  const defaultValue = create(valuePath as string, context)
316
319
 
@@ -499,7 +502,7 @@ export abstract class FormModel<
499
502
  elementTypePath as string,
500
503
  // TODO what can we use for the value path here?
501
504
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
502
- this.toContext(this.observableValue, valuePath as unknown as keyof ValuePathsToAdapters),
505
+ this.contextSource.forPath(this.observableValue, valuePath as unknown as keyof ValuePathsToAdapters),
503
506
  )
504
507
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
505
508
  const originalList: any[] = accessor.value
@@ -569,7 +572,7 @@ export abstract class FormModel<
569
572
  assertExists(revert, 'setting value not supported {}', valuePath)
570
573
 
571
574
  // 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))
575
+ const conversion = revert(value, valuePath as any, this.contextSource.forPath(this.observableValue, valuePath))
573
576
  const accessor = this.getAccessorForValuePath(valuePath)
574
577
  return runInAction(() => {
575
578
  this.fieldOverrides[valuePath] = [value]
@@ -631,8 +634,9 @@ export abstract class FormModel<
631
634
  convert,
632
635
  create,
633
636
  } = adapter
634
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
635
- const context = this.toContext(this.observableValue, valuePath as unknown as keyof ValuePathsToAdapters)
637
+
638
+ const context = this.contextSource.forPath(this.observableValue, // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
639
+ valuePath as unknown as keyof ValuePathsToAdapters)
636
640
  const value = create(valuePath, context)
637
641
  const {
638
642
  value: displayValue,
@@ -16,7 +16,7 @@ import { peek } from './peek'
16
16
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
17
  type FormModelInterface<T extends Type = any> = Pick<
18
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- FormModel<T, any, any, any, any>,
19
+ FormModel<T, any, any, any, any, any>,
20
20
  | 'fields'
21
21
  | 'value'
22
22
  | 'getValidation'
@@ -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
@@ -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
- 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>> {
135
+ type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
136
+ forPath(value: V, valuePath: ValuePath): ContextType;
137
+ };
138
+ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record<string, string>>, TypePathsToAdapters extends FlattenedTypePathsToAdaptersOf<FlattenedValuesOfType<T, '*'>, ContextType>, ContextType = ContextOf<TypePathsToAdapters>, ContextSource extends FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, keyof ValuePathsToAdapters> = FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, string | number | symbol>, 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: ContextSource;
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: ContextSource, mode: FormMode);
149
152
  get forceMutableFields(): boolean;
150
153
  get value(): ValueOfType<ReadonlyTypeOfType<T>>;
151
154
  get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
@@ -181,7 +184,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
181
184
  validateSubmit(): boolean;
182
185
  }
183
186
 
184
- type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
187
+ type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
185
188
  type ValueOfModel<M extends FormModelInterface> = M extends FormModelInterface<infer T> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
186
189
  declare function useDefaultMobxFormHooks<M extends FormModelInterface, F extends M['fields'] = M['fields']>(model: M, { onValidFieldSubmit, onValidFormSubmit, }?: {
187
190
  onValidFieldSubmit?: <Path extends keyof F>(valuePath: Path) => void;
@@ -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
@@ -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
- 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>> {
135
+ type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
136
+ forPath(value: V, valuePath: ValuePath): ContextType;
137
+ };
138
+ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record<string, string>>, TypePathsToAdapters extends FlattenedTypePathsToAdaptersOf<FlattenedValuesOfType<T, '*'>, ContextType>, ContextType = ContextOf<TypePathsToAdapters>, ContextSource extends FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, keyof ValuePathsToAdapters> = FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, string | number | symbol>, 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: ContextSource;
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: ContextSource, mode: FormMode);
149
152
  get forceMutableFields(): boolean;
150
153
  get value(): ValueOfType<ReadonlyTypeOfType<T>>;
151
154
  get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
@@ -181,7 +184,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
181
184
  validateSubmit(): boolean;
182
185
  }
183
186
 
184
- type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
187
+ type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
185
188
  type ValueOfModel<M extends FormModelInterface> = M extends FormModelInterface<infer T> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
186
189
  declare function useDefaultMobxFormHooks<M extends FormModelInterface, F extends M['fields'] = M['fields']>(model: M, { onValidFieldSubmit, onValidFormSubmit, }?: {
187
190
  onValidFieldSubmit?: <Path extends keyof F>(valuePath: Path) => void;
@@ -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
@@ -73,7 +73,7 @@
73
73
  "test:watch": "vitest"
74
74
  },
75
75
  "type": "module",
76
- "version": "0.0.35",
76
+ "version": "0.0.37",
77
77
  "exports": {
78
78
  ".": {
79
79
  "import": {