@strictly/react-form 0.0.1 → 0.0.3
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/field_adapter.d.ts +7 -6
- package/.out/core/mobx/field_adapter_builder.d.ts +12 -13
- package/.out/core/mobx/field_adapter_builder.js +8 -12
- package/.out/core/mobx/field_adapters_of_values.d.ts +4 -0
- package/.out/core/mobx/flattened_adapters_of_fields.d.ts +2 -2
- package/.out/core/mobx/flattened_list_types_of_type.d.ts +8 -0
- package/.out/core/mobx/form_fields_of_field_adapters.d.ts +8 -0
- package/.out/core/mobx/form_presenter.d.ts +21 -24
- package/.out/core/mobx/form_presenter.js +64 -69
- package/.out/core/mobx/merge_field_adapters_with_two_way_converter.d.ts +13 -0
- package/.out/core/mobx/merge_field_adapters_with_two_way_converter.js +11 -0
- package/.out/core/mobx/merge_field_adapters_with_validators.d.ts +11 -0
- package/.out/core/mobx/merge_field_adapters_with_validators.js +45 -0
- package/.out/core/mobx/specs/fixtures.d.ts +7 -0
- package/.out/core/mobx/specs/fixtures.js +20 -0
- package/.out/core/mobx/specs/flattened_adapters_of_fields.tests.js +5 -2
- package/.out/core/mobx/specs/{flattened_list_type_defs_of.tests.js → flattened_list_types_of_types.tests.js} +7 -7
- package/.out/core/mobx/specs/form_presenter.tests.js +162 -60
- package/.out/core/mobx/specs/merge_field_adapters_with_two_way_converter.js +89 -0
- package/.out/core/mobx/specs/merge_field_adapters_with_validators.tests.js +172 -0
- package/.out/core/mobx/types.d.ts +2 -2
- package/.out/field_converters/chain_field_converter.d.ts +3 -3
- package/.out/field_converters/chain_field_converter.js +17 -12
- package/.out/field_converters/identity_converter.d.ts +3 -3
- package/.out/field_converters/identity_converter.js +10 -6
- package/.out/field_converters/integer_to_string_converter.d.ts +5 -4
- package/.out/field_converters/integer_to_string_converter.js +13 -6
- package/.out/field_converters/list_converter.d.ts +2 -2
- package/.out/field_converters/list_converter.js +6 -1
- package/.out/field_converters/maybe_identity_converter.d.ts +3 -3
- package/.out/field_converters/maybe_identity_converter.js +3 -1
- package/.out/field_converters/nullable_to_boolean_converter.d.ts +9 -8
- package/.out/field_converters/nullable_to_boolean_converter.js +13 -7
- package/.out/field_converters/select_value_type_converter.d.ts +20 -15
- package/.out/field_converters/select_value_type_converter.js +29 -14
- package/.out/field_converters/specs/chain_field_converter.tests.d.ts +1 -0
- package/.out/field_converters/specs/chain_field_converter.tests.js +251 -0
- package/.out/field_converters/trimming_string_converter.d.ts +3 -3
- package/.out/field_converters/trimming_string_converter.js +7 -3
- package/.out/field_converters/validating_converter.d.ts +3 -3
- package/.out/field_converters/validating_converter.js +7 -5
- package/.out/index.d.ts +9 -2
- package/.out/index.js +9 -2
- package/.out/mantine/create_checkbox.d.ts +2 -3
- package/.out/mantine/create_checkbox.js +6 -5
- package/.out/mantine/create_pill.js +2 -2
- package/.out/mantine/create_radio.js +1 -1
- package/.out/mantine/create_radio_group.d.ts +2 -3
- package/.out/mantine/create_radio_group.js +4 -3
- package/.out/mantine/create_text_input.d.ts +2 -3
- package/.out/mantine/create_text_input.js +6 -5
- package/.out/mantine/create_value_input.d.ts +2 -3
- package/.out/mantine/create_value_input.js +6 -5
- package/.out/mantine/error_renderer.d.ts +6 -0
- package/.out/mantine/error_renderer.js +5 -0
- package/.out/mantine/hooks.d.ts +9 -13
- package/.out/mantine/hooks.js +10 -15
- package/.out/mantine/specs/checkbox_hooks.stories.d.ts +7 -2
- package/.out/mantine/specs/checkbox_hooks.stories.js +33 -6
- package/.out/mantine/specs/list_hooks.stories.js +2 -2
- package/.out/mantine/specs/radio_group_hooks.stories.d.ts +7 -2
- package/.out/mantine/specs/radio_group_hooks.stories.js +33 -6
- package/.out/mantine/specs/select_hooks.stories.d.ts +8 -2
- package/.out/mantine/specs/select_hooks.stories.js +45 -8
- package/.out/mantine/specs/text_input_hooks.stories.d.ts +5 -1
- package/.out/mantine/specs/text_input_hooks.stories.js +23 -8
- package/.out/mantine/specs/value_input_hooks.stories.d.ts +7 -2
- package/.out/mantine/specs/value_input_hooks.stories.js +49 -15
- package/.out/mantine/types.d.ts +4 -1
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/error_of_field.d.ts +2 -0
- package/.out/types/error_of_field.js +1 -0
- package/.out/types/field.d.ts +1 -1
- package/.out/types/field_converters.d.ts +17 -10
- package/.out/types/field_converters.js +5 -5
- package/.out/types/flattened_validators_of_fields.d.ts +8 -0
- package/.out/types/flattened_validators_of_fields.js +1 -0
- package/.out/types/merge_validators.d.ts +7 -0
- package/.out/types/merge_validators.js +38 -0
- package/.out/types/specs/flattened_validators_of_fields.tests.d.ts +1 -0
- package/.out/types/specs/flattened_validators_of_fields.tests.js +16 -0
- package/.out/types/specs/merge_validators.tests.d.ts +1 -0
- package/.out/types/specs/merge_validators.tests.js +192 -0
- package/.out/util/partial.d.ts +11 -5
- package/.out/util/partial.js +55 -15
- package/.turbo/turbo-build.log +9 -9
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/README.md +5 -1
- package/core/mobx/field_adapter.ts +15 -7
- package/core/mobx/field_adapter_builder.ts +39 -75
- package/core/mobx/field_adapters_of_values.ts +17 -0
- package/core/mobx/flattened_adapters_of_fields.ts +3 -3
- package/core/mobx/flattened_list_types_of_type.ts +17 -0
- package/core/mobx/form_fields_of_field_adapters.ts +16 -0
- package/core/mobx/form_presenter.ts +117 -104
- package/core/mobx/merge_field_adapters_with_two_way_converter.ts +68 -0
- package/core/mobx/merge_field_adapters_with_validators.ts +99 -0
- package/core/mobx/specs/fixtures.ts +73 -0
- package/core/mobx/specs/flattened_adapters_of_fields.tests.ts +23 -2
- package/core/mobx/specs/flattened_list_types_of_types.tests.ts +35 -0
- package/core/mobx/specs/form_presenter.tests.ts +248 -124
- package/core/mobx/specs/merge_field_adapters_with_two_way_converter.ts +140 -0
- package/core/mobx/specs/merge_field_adapters_with_validators.tests.ts +259 -0
- package/core/mobx/types.ts +3 -3
- package/dist/index.cjs +527 -10412
- package/dist/index.d.cts +153 -111
- package/dist/index.d.ts +153 -111
- package/dist/index.js +527 -10420
- package/field_converters/chain_field_converter.ts +37 -23
- package/field_converters/identity_converter.ts +14 -10
- package/field_converters/integer_to_string_converter.ts +15 -9
- package/field_converters/list_converter.ts +8 -3
- package/field_converters/maybe_identity_converter.ts +7 -4
- package/field_converters/nullable_to_boolean_converter.ts +23 -16
- package/field_converters/select_value_type_converter.ts +86 -26
- package/field_converters/specs/chain_field_converter.tests.ts +302 -0
- package/field_converters/trimming_string_converter.ts +11 -6
- package/field_converters/validating_converter.ts +21 -11
- package/index.ts +9 -2
- package/mantine/create_checkbox.tsx +15 -8
- package/mantine/create_list.tsx +1 -4
- package/mantine/create_pill.tsx +2 -2
- package/mantine/create_radio.tsx +1 -1
- package/mantine/create_radio_group.tsx +8 -6
- package/mantine/create_text_input.tsx +20 -8
- package/mantine/create_value_input.tsx +17 -8
- package/mantine/error_renderer.ts +15 -0
- package/mantine/hooks.tsx +25 -51
- package/mantine/specs/__snapshots__/checkbox_hooks.tests.tsx.snap +126 -0
- package/mantine/specs/__snapshots__/radio_group_hooks.tests.tsx.snap +356 -0
- package/mantine/specs/__snapshots__/select_hooks.tests.tsx.snap +208 -12
- package/mantine/specs/__snapshots__/text_input_hooks.tests.tsx.snap +45 -0
- package/mantine/specs/__snapshots__/value_input_hooks.tests.tsx.snap +194 -8
- package/mantine/specs/checkbox_hooks.stories.tsx +47 -7
- package/mantine/specs/list_hooks.stories.tsx +2 -2
- package/mantine/specs/radio_group_hooks.stories.tsx +47 -7
- package/mantine/specs/select_hooks.stories.tsx +55 -8
- package/mantine/specs/text_input_hooks.stories.tsx +32 -7
- package/mantine/specs/value_input_hooks.stories.tsx +57 -16
- package/mantine/types.ts +5 -1
- package/package.json +20 -7
- package/tsconfig.json +1 -0
- package/types/error_of_field.ts +3 -0
- package/types/field.ts +1 -1
- package/types/field_converters.ts +21 -10
- package/types/flattened_validators_of_fields.ts +34 -0
- package/types/merge_validators.ts +80 -0
- package/types/specs/error_type_of_field.tests.ts +2 -2
- package/types/specs/flattened_validators_of_fields.tests.ts +93 -0
- package/types/specs/merge_validators.tests.ts +267 -0
- package/util/partial.tsx +200 -16
- package/.out/core/mobx/flattened_list_type_defs_of.d.ts +0 -8
- package/.out/field_validators/minimum_string_length_field_validator.d.ts +0 -2
- package/.out/field_validators/minimum_string_length_field_validator.js +0 -8
- package/.out/types/error_type_of_field.d.ts +0 -2
- package/.out/types/field_validator.d.ts +0 -3
- package/.out/types/flattened_form_fields_of.d.ts +0 -9
- package/.out/types/specs/flattened_form_fields_of.tests.js +0 -13
- package/core/mobx/flattened_list_type_defs_of.ts +0 -17
- package/core/mobx/specs/flattened_list_type_defs_of.tests.ts +0 -35
- package/field_validators/minimum_string_length_field_validator.ts +0 -13
- package/mantine/specs/__snapshots__/check_box_hooks.tests.tsx.snap +0 -227
- package/types/error_type_of_field.ts +0 -3
- package/types/field_validator.ts +0 -7
- package/types/flattened_form_fields_of.ts +0 -16
- package/types/specs/flattened_form_fields_of.tests.ts +0 -43
- /package/.out/core/mobx/{flattened_list_type_defs_of.js → field_adapters_of_values.js} +0 -0
- /package/.out/core/mobx/{specs/flattened_list_type_defs_of.tests.d.ts → flattened_list_types_of_type.js} +0 -0
- /package/.out/{types/error_type_of_field.js → core/mobx/form_fields_of_field_adapters.js} +0 -0
- /package/.out/{types/field_validator.js → core/mobx/specs/flattened_list_types_of_types.tests.d.ts} +0 -0
- /package/.out/{types/flattened_form_fields_of.js → core/mobx/specs/merge_field_adapters_with_two_way_converter.d.ts} +0 -0
- /package/.out/{types/specs/flattened_form_fields_of.tests.d.ts → core/mobx/specs/merge_field_adapters_with_validators.tests.d.ts} +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type FieldAdapter } from 'core/mobx/field_adapter'
|
|
2
|
+
import { type TwoWayFieldConverter } from 'types/field_converters'
|
|
3
|
+
import { type Mocked } from 'vitest'
|
|
4
|
+
import {
|
|
5
|
+
mock,
|
|
6
|
+
mockReset,
|
|
7
|
+
} from 'vitest-mock-extended'
|
|
8
|
+
|
|
9
|
+
export function createMockedAdapter<
|
|
10
|
+
E,
|
|
11
|
+
To,
|
|
12
|
+
From,
|
|
13
|
+
ValuePath extends string,
|
|
14
|
+
>(_original: FieldAdapter<From, To, E, ValuePath>): Mocked<
|
|
15
|
+
Required<FieldAdapter<From, To, E, ValuePath>>
|
|
16
|
+
> {
|
|
17
|
+
return mock<Required<FieldAdapter<From, To, E, ValuePath>>>()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function resetMockAdapter<
|
|
21
|
+
E,
|
|
22
|
+
To,
|
|
23
|
+
From,
|
|
24
|
+
ValuePath extends string,
|
|
25
|
+
>(
|
|
26
|
+
{
|
|
27
|
+
convert,
|
|
28
|
+
revert,
|
|
29
|
+
create,
|
|
30
|
+
}: FieldAdapter<From, To, E, ValuePath>,
|
|
31
|
+
mockedAdapter: Mocked<
|
|
32
|
+
Required<FieldAdapter<From, To, E, ValuePath>>
|
|
33
|
+
>,
|
|
34
|
+
): void {
|
|
35
|
+
mockReset(mockedAdapter)
|
|
36
|
+
if (revert) {
|
|
37
|
+
mockedAdapter.revert?.mockImplementation(revert)
|
|
38
|
+
}
|
|
39
|
+
mockedAdapter.convert.mockImplementation(convert)
|
|
40
|
+
mockedAdapter.create.mockImplementation(create)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function createMockTwoWayFieldConverter<
|
|
44
|
+
From,
|
|
45
|
+
To,
|
|
46
|
+
E,
|
|
47
|
+
ValuePath extends string,
|
|
48
|
+
Context,
|
|
49
|
+
>(_original: TwoWayFieldConverter<From, To, E, ValuePath, Context>): Mocked<
|
|
50
|
+
TwoWayFieldConverter<From, To, E, ValuePath, Context>
|
|
51
|
+
> {
|
|
52
|
+
return mock<TwoWayFieldConverter<From, To, E, ValuePath, Context>>()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function resetMockTwoWayFieldConverter<
|
|
56
|
+
From,
|
|
57
|
+
To,
|
|
58
|
+
E,
|
|
59
|
+
ValuePath extends string,
|
|
60
|
+
Context,
|
|
61
|
+
>(
|
|
62
|
+
{
|
|
63
|
+
convert,
|
|
64
|
+
revert,
|
|
65
|
+
}: TwoWayFieldConverter<From, To, E, ValuePath, Context>,
|
|
66
|
+
mockedConverter: Mocked<
|
|
67
|
+
TwoWayFieldConverter<From, To, E, ValuePath, Context>
|
|
68
|
+
>,
|
|
69
|
+
) {
|
|
70
|
+
mockReset(mockedConverter)
|
|
71
|
+
mockedConverter.convert.mockImplementation(convert)
|
|
72
|
+
mockedConverter.revert.mockImplementation(revert)
|
|
73
|
+
}
|
|
@@ -9,7 +9,7 @@ import { type Field } from 'types/field'
|
|
|
9
9
|
const error = Symbol()
|
|
10
10
|
type Error = typeof error
|
|
11
11
|
|
|
12
|
-
describe('
|
|
12
|
+
describe('FlattenedAdaptersOfFields', function () {
|
|
13
13
|
it('maps the converter types', function () {
|
|
14
14
|
type Fields = {
|
|
15
15
|
a: Field<string, Error>,
|
|
@@ -48,7 +48,7 @@ describe('FlattenedAdaptersOfFIelds', function () {
|
|
|
48
48
|
}>()
|
|
49
49
|
})
|
|
50
50
|
|
|
51
|
-
it('handles multiple fields
|
|
51
|
+
it('handles multiple fields', function () {
|
|
52
52
|
type FormFields = {
|
|
53
53
|
a: Field<string, Error>,
|
|
54
54
|
c: Field<boolean, never>,
|
|
@@ -69,4 +69,25 @@ describe('FlattenedAdaptersOfFIelds', function () {
|
|
|
69
69
|
readonly d: FieldAdapter<boolean, boolean, never, 'c'>,
|
|
70
70
|
}>()
|
|
71
71
|
})
|
|
72
|
+
|
|
73
|
+
it('allows synthesized fields', function () {
|
|
74
|
+
type FormFields = {
|
|
75
|
+
a: Field<string, Error>,
|
|
76
|
+
c: Field<boolean, never>,
|
|
77
|
+
}
|
|
78
|
+
type T = FlattenedAdaptersOfFields<
|
|
79
|
+
{
|
|
80
|
+
a: 'b',
|
|
81
|
+
c: 'd',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
b: typeof numberType,
|
|
85
|
+
},
|
|
86
|
+
FormFields
|
|
87
|
+
>
|
|
88
|
+
expectTypeOf<T>().toEqualTypeOf<{
|
|
89
|
+
readonly b: FieldAdapter<number, string, Error, 'a'>,
|
|
90
|
+
readonly d: FieldAdapter<boolean, boolean, never, 'c'>,
|
|
91
|
+
}>()
|
|
92
|
+
})
|
|
72
93
|
})
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
list,
|
|
3
|
+
nullType,
|
|
4
|
+
numberType,
|
|
5
|
+
object,
|
|
6
|
+
record,
|
|
7
|
+
stringType,
|
|
8
|
+
union,
|
|
9
|
+
} from '@strictly/define'
|
|
10
|
+
import {
|
|
11
|
+
type FlattenedListTypesOfType,
|
|
12
|
+
} from 'core/mobx/flattened_list_types_of_type'
|
|
13
|
+
|
|
14
|
+
describe('FlattenedListTypesOfType', function () {
|
|
15
|
+
it('filters lists types', function () {
|
|
16
|
+
const listTypeDef = list(numberType)
|
|
17
|
+
const recordTypeDef = record<typeof stringType, string>(stringType)
|
|
18
|
+
const objectTypeDef = object()
|
|
19
|
+
const unionTypeDef = union().or('0', numberType).or('1', nullType)
|
|
20
|
+
const typeDef = object()
|
|
21
|
+
.field('literal', numberType)
|
|
22
|
+
.field('list', listTypeDef)
|
|
23
|
+
.field('record', recordTypeDef)
|
|
24
|
+
.field('object', objectTypeDef)
|
|
25
|
+
.field('union', unionTypeDef)
|
|
26
|
+
|
|
27
|
+
type F = FlattenedListTypesOfType<typeof typeDef._type>
|
|
28
|
+
|
|
29
|
+
type E = {
|
|
30
|
+
readonly '$.list': typeof listTypeDef._type,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
expectTypeOf<F>().toEqualTypeOf<E>()
|
|
34
|
+
})
|
|
35
|
+
})
|