@strictly/react-form 0.0.36 → 0.0.38
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 +3 -6
- package/.out/core/mobx/FormModel.js +2 -18
- package/.out/core/mobx/hooks.d.ts +1 -1
- package/.out/core/mobx/specs/FormModel.tests.js +28 -37
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/core/mobx/FormModel.ts +5 -20
- package/core/mobx/hooks.tsx +1 -1
- package/core/mobx/specs/FormModel.tests.ts +20 -57
- package/dist/index.cjs +2 -13
- package/dist/index.d.cts +5 -8
- package/dist/index.d.ts +5 -8
- package/dist/index.js +2 -13
- package/package.json +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -7,12 +7,12 @@ $ tsup
|
|
|
7
7
|
[34mCLI[39m Target: es6
|
|
8
8
|
[34mCJS[39m Build start
|
|
9
9
|
[34mESM[39m Build start
|
|
10
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m64.
|
|
11
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
13
|
-
[32mESM[39m ⚡️ Build success in
|
|
10
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m64.12 KB[39m
|
|
11
|
+
[32mCJS[39m ⚡️ Build success in 167ms
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m59.95 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 161ms
|
|
14
14
|
[34mDTS[39m Build start
|
|
15
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
18
|
-
Done in 6.
|
|
15
|
+
[32mDTS[39m ⚡️ Build success in 5483ms
|
|
16
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m38.91 KB[39m
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m38.91 KB[39m
|
|
18
|
+
Done in 6.91s.
|
package/core/mobx/FormModel.ts
CHANGED
|
@@ -132,8 +132,6 @@ export type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string
|
|
|
132
132
|
| {}
|
|
133
133
|
>
|
|
134
134
|
|
|
135
|
-
export type FormMode = 'edit' | 'create'
|
|
136
|
-
|
|
137
135
|
export type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
|
|
138
136
|
forPath(value: V, valuePath: ValuePath): ContextType,
|
|
139
137
|
}
|
|
@@ -146,6 +144,9 @@ export abstract class FormModel<
|
|
|
146
144
|
ContextType
|
|
147
145
|
>,
|
|
148
146
|
ContextType = ContextOf<TypePathsToAdapters>,
|
|
147
|
+
ContextSource extends FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>,
|
|
148
|
+
keyof ValuePathsToAdapters> = FormModelContextSource<ContextType, ValueOfType<ReadonlyTypeOfType<T>>,
|
|
149
|
+
string | number | symbol>,
|
|
149
150
|
ValuePathsToAdapters extends ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths> = ValuePathsToAdaptersOf<
|
|
150
151
|
TypePathsToAdapters,
|
|
151
152
|
ValueToTypePaths
|
|
@@ -173,12 +174,7 @@ export abstract class FormModel<
|
|
|
173
174
|
readonly type: T,
|
|
174
175
|
private readonly originalValue: ValueOfType<ReadonlyTypeOfType<T>>,
|
|
175
176
|
protected readonly adapters: TypePathsToAdapters,
|
|
176
|
-
protected readonly contextSource:
|
|
177
|
-
ContextType,
|
|
178
|
-
ValueOfType<ReadonlyTypeOfType<T>>,
|
|
179
|
-
keyof ValuePathsToAdapters
|
|
180
|
-
>,
|
|
181
|
-
protected readonly mode: FormMode,
|
|
177
|
+
protected readonly contextSource: ContextSource,
|
|
182
178
|
) {
|
|
183
179
|
this.originalValues = flattenValuesOfType<ReadonlyTypeOfType<T>>(type, originalValue, this.listIndicesToKeys)
|
|
184
180
|
this.observableValue = mobxCopy(type, originalValue)
|
|
@@ -223,17 +219,6 @@ export abstract class FormModel<
|
|
|
223
219
|
}) as FlattenedFieldOverrides<ValuePathsToAdapters>
|
|
224
220
|
}
|
|
225
221
|
|
|
226
|
-
get forceMutableFields() {
|
|
227
|
-
switch (this.mode) {
|
|
228
|
-
case 'create':
|
|
229
|
-
return true
|
|
230
|
-
case 'edit':
|
|
231
|
-
return false
|
|
232
|
-
default:
|
|
233
|
-
throw new UnreachableError(this.mode)
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
222
|
@computed
|
|
238
223
|
get value(): ValueOfType<ReadonlyTypeOfType<T>> {
|
|
239
224
|
// copy and strip out the mobx so this computed will fire every time anything changes
|
|
@@ -408,7 +393,7 @@ export abstract class FormModel<
|
|
|
408
393
|
return {
|
|
409
394
|
value: displayedValue,
|
|
410
395
|
error,
|
|
411
|
-
readonly
|
|
396
|
+
readonly,
|
|
412
397
|
required,
|
|
413
398
|
// make a copy of the index mapping and remove the final value (next id)
|
|
414
399
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
package/core/mobx/hooks.tsx
CHANGED
|
@@ -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'
|
|
@@ -2,7 +2,7 @@ import { expectDefinedAndReturn } from '@strictly/base'
|
|
|
2
2
|
import {
|
|
3
3
|
booleanType,
|
|
4
4
|
type FlattenedValuesOfType,
|
|
5
|
-
|
|
5
|
+
flattenValidatorsOfValidatingTypeWithMutability,
|
|
6
6
|
list,
|
|
7
7
|
nullType,
|
|
8
8
|
numberType,
|
|
@@ -25,7 +25,6 @@ import {
|
|
|
25
25
|
} from 'core/mobx/fieldAdapterBuilder'
|
|
26
26
|
import {
|
|
27
27
|
type FlattenedTypePathsToAdaptersOf,
|
|
28
|
-
type FormMode,
|
|
29
28
|
FormModel,
|
|
30
29
|
type FormModelContextSource,
|
|
31
30
|
Validation,
|
|
@@ -57,13 +56,23 @@ const originalIntegerToStringAdapter = adapterFromTwoWayConverter(
|
|
|
57
56
|
|
|
58
57
|
const originalBooleanToBooleanAdapter = identityAdapter(false)
|
|
59
58
|
|
|
59
|
+
type TextFormContext = {
|
|
60
|
+
forceMutable: boolean,
|
|
61
|
+
value: unknown,
|
|
62
|
+
valuePath: unknown,
|
|
63
|
+
}
|
|
64
|
+
|
|
60
65
|
class TestFormContextSource<V, ValuePath extends string | number | symbol> implements FormModelContextSource<
|
|
61
|
-
|
|
66
|
+
TextFormContext,
|
|
62
67
|
V,
|
|
63
68
|
ValuePath
|
|
64
69
|
> {
|
|
65
|
-
|
|
70
|
+
constructor(private readonly forceMutable: boolean) {
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
forPath(value: V, valuePath: ValuePath): TextFormContext {
|
|
66
74
|
return {
|
|
75
|
+
forceMutable: this.forceMutable,
|
|
67
76
|
value,
|
|
68
77
|
valuePath,
|
|
69
78
|
}
|
|
@@ -82,9 +91,9 @@ class TestFormModel<
|
|
|
82
91
|
type: T,
|
|
83
92
|
originalValue: ValueOfType<ReadonlyTypeOfType<T>>,
|
|
84
93
|
adapters: TypePathsToAdapters,
|
|
85
|
-
|
|
94
|
+
forceMutable = false,
|
|
86
95
|
) {
|
|
87
|
-
super(type, originalValue, adapters, new TestFormContextSource()
|
|
96
|
+
super(type, originalValue, adapters, new TestFormContextSource(forceMutable))
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
setFieldValueAndValidate<K extends keyof ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>>(
|
|
@@ -229,7 +238,6 @@ describe('all', function () {
|
|
|
229
238
|
typeDef,
|
|
230
239
|
originalValue,
|
|
231
240
|
adapters,
|
|
232
|
-
'create',
|
|
233
241
|
)
|
|
234
242
|
})
|
|
235
243
|
|
|
@@ -290,7 +298,6 @@ describe('all', function () {
|
|
|
290
298
|
typeDef,
|
|
291
299
|
originalValue,
|
|
292
300
|
adapters,
|
|
293
|
-
'create',
|
|
294
301
|
)
|
|
295
302
|
})
|
|
296
303
|
|
|
@@ -332,7 +339,6 @@ describe('all', function () {
|
|
|
332
339
|
typeDef,
|
|
333
340
|
value,
|
|
334
341
|
adapters,
|
|
335
|
-
'create',
|
|
336
342
|
)
|
|
337
343
|
})
|
|
338
344
|
|
|
@@ -411,7 +417,6 @@ describe('all', function () {
|
|
|
411
417
|
typeDef,
|
|
412
418
|
value,
|
|
413
419
|
converters,
|
|
414
|
-
'create',
|
|
415
420
|
)
|
|
416
421
|
})
|
|
417
422
|
|
|
@@ -482,7 +487,6 @@ describe('all', function () {
|
|
|
482
487
|
typeDef,
|
|
483
488
|
value,
|
|
484
489
|
converters,
|
|
485
|
-
'create',
|
|
486
490
|
)
|
|
487
491
|
})
|
|
488
492
|
|
|
@@ -548,7 +552,6 @@ describe('all', function () {
|
|
|
548
552
|
typeDef,
|
|
549
553
|
originalValue,
|
|
550
554
|
adapters,
|
|
551
|
-
'create',
|
|
552
555
|
)
|
|
553
556
|
})
|
|
554
557
|
|
|
@@ -675,7 +678,6 @@ describe('all', function () {
|
|
|
675
678
|
typeDef,
|
|
676
679
|
originalValue,
|
|
677
680
|
converters,
|
|
678
|
-
'create',
|
|
679
681
|
)
|
|
680
682
|
})
|
|
681
683
|
|
|
@@ -804,6 +806,7 @@ describe('all', function () {
|
|
|
804
806
|
// if the value has since changed
|
|
805
807
|
value: model.value,
|
|
806
808
|
valuePath: '$.2',
|
|
809
|
+
forceMutable: false,
|
|
807
810
|
},
|
|
808
811
|
)
|
|
809
812
|
})
|
|
@@ -817,6 +820,7 @@ describe('all', function () {
|
|
|
817
820
|
7,
|
|
818
821
|
],
|
|
819
822
|
valuePath: '$.2',
|
|
823
|
+
forceMutable: false,
|
|
820
824
|
})
|
|
821
825
|
})
|
|
822
826
|
})
|
|
@@ -1031,7 +1035,6 @@ describe('all', function () {
|
|
|
1031
1035
|
type,
|
|
1032
1036
|
originalValue,
|
|
1033
1037
|
adapters,
|
|
1034
|
-
'create',
|
|
1035
1038
|
)
|
|
1036
1039
|
})
|
|
1037
1040
|
|
|
@@ -1100,7 +1103,6 @@ describe('all', function () {
|
|
|
1100
1103
|
a: 1,
|
|
1101
1104
|
},
|
|
1102
1105
|
adapters,
|
|
1103
|
-
'create',
|
|
1104
1106
|
)
|
|
1105
1107
|
it.each([
|
|
1106
1108
|
[
|
|
@@ -1133,7 +1135,6 @@ describe('all', function () {
|
|
|
1133
1135
|
b: false,
|
|
1134
1136
|
},
|
|
1135
1137
|
adapters,
|
|
1136
|
-
'create',
|
|
1137
1138
|
)
|
|
1138
1139
|
it.each([
|
|
1139
1140
|
[
|
|
@@ -1183,7 +1184,6 @@ describe('all', function () {
|
|
|
1183
1184
|
typeDef,
|
|
1184
1185
|
originalValue,
|
|
1185
1186
|
converters,
|
|
1186
|
-
'create',
|
|
1187
1187
|
)
|
|
1188
1188
|
})
|
|
1189
1189
|
|
|
@@ -1210,14 +1210,14 @@ describe('all', function () {
|
|
|
1210
1210
|
})
|
|
1211
1211
|
})
|
|
1212
1212
|
|
|
1213
|
-
describe('interaction with
|
|
1213
|
+
describe('interaction with mutability', () => {
|
|
1214
1214
|
const typeDef = object().readonlyField('n', numberType.enforce(n => n < 10 ? 'err' : null))
|
|
1215
1215
|
const adapters = mergeAdaptersWithValidators(
|
|
1216
1216
|
{
|
|
1217
1217
|
$: identityAdapter({ n: 0 }),
|
|
1218
1218
|
'$.n': integerToStringAdapter,
|
|
1219
1219
|
} as const,
|
|
1220
|
-
|
|
1220
|
+
flattenValidatorsOfValidatingTypeWithMutability(typeDef),
|
|
1221
1221
|
)
|
|
1222
1222
|
type JsonPaths = {
|
|
1223
1223
|
$: '$',
|
|
@@ -1244,7 +1244,7 @@ describe('all', function () {
|
|
|
1244
1244
|
typeDef,
|
|
1245
1245
|
originalValue,
|
|
1246
1246
|
adapters,
|
|
1247
|
-
|
|
1247
|
+
true,
|
|
1248
1248
|
)
|
|
1249
1249
|
})
|
|
1250
1250
|
|
|
@@ -1261,43 +1261,6 @@ describe('all', function () {
|
|
|
1261
1261
|
expect(model.validateAll()).toBeTruthy()
|
|
1262
1262
|
})
|
|
1263
1263
|
})
|
|
1264
|
-
describe('edit model', () => {
|
|
1265
|
-
let model: FormModel<
|
|
1266
|
-
typeof typeDef,
|
|
1267
|
-
JsonPaths,
|
|
1268
|
-
typeof adapters
|
|
1269
|
-
>
|
|
1270
|
-
beforeEach(function () {
|
|
1271
|
-
model = new TestFormModel<
|
|
1272
|
-
typeof typeDef,
|
|
1273
|
-
JsonPaths,
|
|
1274
|
-
typeof adapters
|
|
1275
|
-
>(
|
|
1276
|
-
typeDef,
|
|
1277
|
-
originalValue,
|
|
1278
|
-
adapters,
|
|
1279
|
-
'edit',
|
|
1280
|
-
)
|
|
1281
|
-
})
|
|
1282
|
-
|
|
1283
|
-
it('respects the field being readonly', () => {
|
|
1284
|
-
expect(model.fields['$.n'].readonly).toBeTruthy()
|
|
1285
|
-
})
|
|
1286
|
-
|
|
1287
|
-
it('fails validation with invalid, clean data', () => {
|
|
1288
|
-
expect(model.validateAll()).toBeFalsy()
|
|
1289
|
-
})
|
|
1290
|
-
|
|
1291
|
-
it('fails validation with invalid, dirty data', () => {
|
|
1292
|
-
model.setFieldValue('$.n', '2')
|
|
1293
|
-
expect(model.validateAll()).toBeFalsy()
|
|
1294
|
-
})
|
|
1295
|
-
|
|
1296
|
-
it('passes validation with valid, dirty data', () => {
|
|
1297
|
-
model.setFieldValue('$.n', '10')
|
|
1298
|
-
expect(model.validateAll()).toBeTruthy()
|
|
1299
|
-
})
|
|
1300
|
-
})
|
|
1301
1264
|
})
|
|
1302
1265
|
})
|
|
1303
1266
|
})
|
package/dist/index.cjs
CHANGED
|
@@ -367,12 +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, contextSource
|
|
370
|
+
constructor(type, originalValue, adapters, contextSource) {
|
|
371
371
|
this.type = type;
|
|
372
372
|
this.originalValue = originalValue;
|
|
373
373
|
this.adapters = adapters;
|
|
374
374
|
this.contextSource = contextSource;
|
|
375
|
-
this.mode = mode;
|
|
376
375
|
__runInitializers(_init, 5, this);
|
|
377
376
|
__privateAdd(this, _observableValue, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
378
377
|
__privateAdd(this, _fieldOverrides, __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
@@ -413,16 +412,6 @@ var FormModel = class {
|
|
|
413
412
|
return v && [v.value];
|
|
414
413
|
});
|
|
415
414
|
}
|
|
416
|
-
get forceMutableFields() {
|
|
417
|
-
switch (this.mode) {
|
|
418
|
-
case "create":
|
|
419
|
-
return true;
|
|
420
|
-
case "edit":
|
|
421
|
-
return false;
|
|
422
|
-
default:
|
|
423
|
-
throw new import_base2.UnreachableError(this.mode);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
415
|
get value() {
|
|
427
416
|
return (0, import_define.copy)(this.type, this.observableValue);
|
|
428
417
|
}
|
|
@@ -565,7 +554,7 @@ var FormModel = class {
|
|
|
565
554
|
return {
|
|
566
555
|
value: displayedValue,
|
|
567
556
|
error,
|
|
568
|
-
readonly
|
|
557
|
+
readonly,
|
|
569
558
|
required,
|
|
570
559
|
// make a copy of the index mapping and remove the final value (next id)
|
|
571
560
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
package/dist/index.d.cts
CHANGED
|
@@ -131,16 +131,14 @@ type ValuePathsToAdaptersOf<TypePathsToAdapters extends Partial<Readonly<Record<
|
|
|
131
131
|
type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, FieldAdapter>>>> = UnionToIntersection<{
|
|
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
|
-
type FormMode = 'edit' | 'create';
|
|
135
134
|
type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
|
|
136
135
|
forPath(value: V, valuePath: ValuePath): ContextType;
|
|
137
136
|
};
|
|
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>> {
|
|
137
|
+
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>> {
|
|
139
138
|
readonly type: T;
|
|
140
139
|
private readonly originalValue;
|
|
141
140
|
protected readonly adapters: TypePathsToAdapters;
|
|
142
|
-
protected readonly contextSource:
|
|
143
|
-
protected readonly mode: FormMode;
|
|
141
|
+
protected readonly contextSource: ContextSource;
|
|
144
142
|
private accessor observableValue;
|
|
145
143
|
accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
|
|
146
144
|
accessor errorOverrides: FlattenedErrorOverrides<ValuePathsToAdapters>;
|
|
@@ -148,8 +146,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
148
146
|
private readonly flattenedTypeDefs;
|
|
149
147
|
private readonly originalValues;
|
|
150
148
|
private readonly listIndicesToKeys;
|
|
151
|
-
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, contextSource:
|
|
152
|
-
get forceMutableFields(): boolean;
|
|
149
|
+
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, contextSource: ContextSource);
|
|
153
150
|
get value(): ValueOfType<ReadonlyTypeOfType<T>>;
|
|
154
151
|
get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
|
|
155
152
|
private get knownFields();
|
|
@@ -184,7 +181,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
184
181
|
validateSubmit(): boolean;
|
|
185
182
|
}
|
|
186
183
|
|
|
187
|
-
type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
|
|
184
|
+
type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
|
|
188
185
|
type ValueOfModel<M extends FormModelInterface> = M extends FormModelInterface<infer T> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
|
|
189
186
|
declare function useDefaultMobxFormHooks<M extends FormModelInterface, F extends M['fields'] = M['fields']>(model: M, { onValidFieldSubmit, onValidFormSubmit, }?: {
|
|
190
187
|
onValidFieldSubmit?: <Path extends keyof F>(valuePath: Path) => void;
|
|
@@ -471,4 +468,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
|
|
|
471
468
|
|
|
472
469
|
declare function Empty(): null;
|
|
473
470
|
|
|
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,
|
|
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, 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
|
@@ -131,16 +131,14 @@ type ValuePathsToAdaptersOf<TypePathsToAdapters extends Partial<Readonly<Record<
|
|
|
131
131
|
type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, FieldAdapter>>>> = UnionToIntersection<{
|
|
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
|
-
type FormMode = 'edit' | 'create';
|
|
135
134
|
type FormModelContextSource<ContextType, V, ValuePath extends string | number | symbol> = {
|
|
136
135
|
forPath(value: V, valuePath: ValuePath): ContextType;
|
|
137
136
|
};
|
|
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>> {
|
|
137
|
+
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>> {
|
|
139
138
|
readonly type: T;
|
|
140
139
|
private readonly originalValue;
|
|
141
140
|
protected readonly adapters: TypePathsToAdapters;
|
|
142
|
-
protected readonly contextSource:
|
|
143
|
-
protected readonly mode: FormMode;
|
|
141
|
+
protected readonly contextSource: ContextSource;
|
|
144
142
|
private accessor observableValue;
|
|
145
143
|
accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
|
|
146
144
|
accessor errorOverrides: FlattenedErrorOverrides<ValuePathsToAdapters>;
|
|
@@ -148,8 +146,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
148
146
|
private readonly flattenedTypeDefs;
|
|
149
147
|
private readonly originalValues;
|
|
150
148
|
private readonly listIndicesToKeys;
|
|
151
|
-
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, contextSource:
|
|
152
|
-
get forceMutableFields(): boolean;
|
|
149
|
+
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, contextSource: ContextSource);
|
|
153
150
|
get value(): ValueOfType<ReadonlyTypeOfType<T>>;
|
|
154
151
|
get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
|
|
155
152
|
private get knownFields();
|
|
@@ -184,7 +181,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
184
181
|
validateSubmit(): boolean;
|
|
185
182
|
}
|
|
186
183
|
|
|
187
|
-
type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
|
|
184
|
+
type FormModelInterface<T extends Type = any> = Pick<FormModel<T, any, any, any, any, any>, 'fields' | 'value' | 'getValidation' | 'validateField' | 'setFieldValue' | 'validateSubmit' | 'isFieldDirty' | 'isValuePathActive'>;
|
|
188
185
|
type ValueOfModel<M extends FormModelInterface> = M extends FormModelInterface<infer T> ? ValueOfType<ReadonlyTypeOfType<T>> : never;
|
|
189
186
|
declare function useDefaultMobxFormHooks<M extends FormModelInterface, F extends M['fields'] = M['fields']>(model: M, { onValidFieldSubmit, onValidFormSubmit, }?: {
|
|
190
187
|
onValidFieldSubmit?: <Path extends keyof F>(valuePath: Path) => void;
|
|
@@ -471,4 +468,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
|
|
|
471
468
|
|
|
472
469
|
declare function Empty(): null;
|
|
473
470
|
|
|
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,
|
|
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, 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,12 +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, contextSource
|
|
340
|
+
constructor(type, originalValue, adapters, contextSource) {
|
|
341
341
|
this.type = type;
|
|
342
342
|
this.originalValue = originalValue;
|
|
343
343
|
this.adapters = adapters;
|
|
344
344
|
this.contextSource = contextSource;
|
|
345
|
-
this.mode = mode;
|
|
346
345
|
__runInitializers(_init, 5, this);
|
|
347
346
|
__privateAdd(this, _observableValue, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
348
347
|
__privateAdd(this, _fieldOverrides, __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
@@ -383,16 +382,6 @@ var FormModel = class {
|
|
|
383
382
|
return v && [v.value];
|
|
384
383
|
});
|
|
385
384
|
}
|
|
386
|
-
get forceMutableFields() {
|
|
387
|
-
switch (this.mode) {
|
|
388
|
-
case "create":
|
|
389
|
-
return true;
|
|
390
|
-
case "edit":
|
|
391
|
-
return false;
|
|
392
|
-
default:
|
|
393
|
-
throw new UnreachableError2(this.mode);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
385
|
get value() {
|
|
397
386
|
return copy(this.type, this.observableValue);
|
|
398
387
|
}
|
|
@@ -535,7 +524,7 @@ var FormModel = class {
|
|
|
535
524
|
return {
|
|
536
525
|
value: displayedValue,
|
|
537
526
|
error,
|
|
538
|
-
readonly
|
|
527
|
+
readonly,
|
|
539
528
|
required,
|
|
540
529
|
// make a copy of the index mapping and remove the final value (next id)
|
|
541
530
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|