@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.
- package/.out/core/mobx/FormModel.d.ts +5 -2
- package/.out/core/mobx/FormModel.js +13 -7
- package/.out/core/mobx/specs/FormModel.tests.js +7 -2
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/util/Partial.d.ts +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/core/mobx/FormModel.ts +16 -11
- package/core/mobx/specs/FormModel.tests.ts +22 -7
- package/dist/index.cjs +11 -6
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +11 -6
- package/package.json +3 -3
- package/util/Partial.tsx +1 -0
|
@@ -32,10 +32,14 @@ export type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string
|
|
|
32
32
|
readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : unknown extends ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>> ? never : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
|
|
33
33
|
}[keyof TypePathsToAdapters] | {}>;
|
|
34
34
|
export type FormMode = 'edit' | 'create';
|
|
35
|
+
export type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
|
|
36
|
+
forPath(value: V, valuePath: ValuePath): ContextType;
|
|
37
|
+
};
|
|
35
38
|
export 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>> {
|
|
36
39
|
readonly type: T;
|
|
37
40
|
private readonly originalValue;
|
|
38
41
|
protected readonly adapters: TypePathsToAdapters;
|
|
42
|
+
protected readonly contextSource: FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, keyof ValuePathsToAdapters>;
|
|
39
43
|
protected readonly mode: FormMode;
|
|
40
44
|
private accessor observableValue;
|
|
41
45
|
accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
|
|
@@ -44,8 +48,7 @@ export declare abstract class FormModel<T extends Type, ValueToTypePaths extends
|
|
|
44
48
|
private readonly flattenedTypeDefs;
|
|
45
49
|
private readonly originalValues;
|
|
46
50
|
private readonly listIndicesToKeys;
|
|
47
|
-
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
|
|
48
|
-
protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
|
|
51
|
+
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, contextSource: FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>, keyof ValuePathsToAdapters>, mode: FormMode);
|
|
49
52
|
get forceMutableFields(): boolean;
|
|
50
53
|
get value(): ValueOfType<ReadonlyTypeOfType<T>>;
|
|
51
54
|
get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
|
|
@@ -87,7 +87,7 @@ let FormModel = (() => {
|
|
|
87
87
|
set errorOverrides(value) { __classPrivateFieldSet(this, _FormModel_errorOverrides_accessor_storage, value, "f"); }
|
|
88
88
|
get validation() { return __classPrivateFieldGet(this, _FormModel_validation_accessor_storage, "f"); }
|
|
89
89
|
set validation(value) { __classPrivateFieldSet(this, _FormModel_validation_accessor_storage, value, "f"); }
|
|
90
|
-
constructor(type, originalValue, adapters, mode) {
|
|
90
|
+
constructor(type, originalValue, adapters, contextSource, mode) {
|
|
91
91
|
Object.defineProperty(this, "type", {
|
|
92
92
|
enumerable: true,
|
|
93
93
|
configurable: true,
|
|
@@ -106,6 +106,12 @@ let FormModel = (() => {
|
|
|
106
106
|
writable: true,
|
|
107
107
|
value: adapters
|
|
108
108
|
});
|
|
109
|
+
Object.defineProperty(this, "contextSource", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
configurable: true,
|
|
112
|
+
writable: true,
|
|
113
|
+
value: contextSource
|
|
114
|
+
});
|
|
109
115
|
Object.defineProperty(this, "mode", {
|
|
110
116
|
enumerable: true,
|
|
111
117
|
configurable: true,
|
|
@@ -144,7 +150,7 @@ let FormModel = (() => {
|
|
|
144
150
|
// then returned to
|
|
145
151
|
const conversions = flattenValueTo(type, originalValue, () => { }, (_t, fieldValue, _setter, typePath, valuePath) => {
|
|
146
152
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
147
|
-
const contextValue =
|
|
153
|
+
const contextValue = contextSource.forPath(originalValue, valuePath);
|
|
148
154
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
149
155
|
const adapter = this.adapters[typePath];
|
|
150
156
|
if (adapter == null) {
|
|
@@ -230,7 +236,7 @@ let FormModel = (() => {
|
|
|
230
236
|
const accessor = this.getAccessorForValuePath(valuePath);
|
|
231
237
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
232
238
|
const fieldTypeDef = this.flattenedTypeDefs[typePath];
|
|
233
|
-
const context = this.
|
|
239
|
+
const context = this.contextSource.forPath(this.observableValue, valuePath);
|
|
234
240
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
235
241
|
const defaultValue = create(valuePath, context);
|
|
236
242
|
const { value, required, readonly, } = convert(accessor != null
|
|
@@ -362,7 +368,7 @@ let FormModel = (() => {
|
|
|
362
368
|
elementTypePath,
|
|
363
369
|
// TODO what can we use for the value path here?
|
|
364
370
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
365
|
-
this.
|
|
371
|
+
this.contextSource.forPath(this.observableValue, valuePath));
|
|
366
372
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
367
373
|
const originalList = accessor.value;
|
|
368
374
|
const newList = [
|
|
@@ -408,7 +414,7 @@ let FormModel = (() => {
|
|
|
408
414
|
const { revert } = this.getAdapterForValuePath(valuePath);
|
|
409
415
|
assertExists(revert, 'setting value not supported {}', valuePath);
|
|
410
416
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|
|
411
|
-
const conversion = revert(value, valuePath, this.
|
|
417
|
+
const conversion = revert(value, valuePath, this.contextSource.forPath(this.observableValue, valuePath));
|
|
412
418
|
const accessor = this.getAccessorForValuePath(valuePath);
|
|
413
419
|
return runInAction(() => {
|
|
414
420
|
this.fieldOverrides[valuePath] = [value];
|
|
@@ -462,8 +468,8 @@ let FormModel = (() => {
|
|
|
462
468
|
return;
|
|
463
469
|
}
|
|
464
470
|
const { convert, create, } = adapter;
|
|
465
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
466
|
-
|
|
471
|
+
const context = this.contextSource.forPath(this.observableValue, // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
472
|
+
valuePath);
|
|
467
473
|
const value = create(valuePath, context);
|
|
468
474
|
const { value: displayValue, } = convert(value, valuePath, context);
|
|
469
475
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
@@ -12,13 +12,18 @@ import { createMockedAdapter, resetMockAdapter, } from './fixtures';
|
|
|
12
12
|
const IS_NAN_ERROR = 1;
|
|
13
13
|
const originalIntegerToStringAdapter = adapterFromTwoWayConverter(new IntegerToStringConverter(IS_NAN_ERROR), prototypingFieldValueFactory(0));
|
|
14
14
|
const originalBooleanToBooleanAdapter = identityAdapter(false);
|
|
15
|
-
class
|
|
16
|
-
|
|
15
|
+
class TestFormContextSource {
|
|
16
|
+
forPath(value, valuePath) {
|
|
17
17
|
return {
|
|
18
18
|
value,
|
|
19
19
|
valuePath,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
}
|
|
23
|
+
class TestFormModel extends FormModel {
|
|
24
|
+
constructor(type, originalValue, adapters, mode) {
|
|
25
|
+
super(type, originalValue, adapters, new TestFormContextSource(), mode);
|
|
26
|
+
}
|
|
22
27
|
setFieldValueAndValidate(valuePath, value) {
|
|
23
28
|
this.setFieldValue(valuePath, value, Validation.Always);
|
|
24
29
|
}
|