@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,251 @@
|
|
|
1
|
+
import { chainAnnotatedFieldConverter, chainUnreliableFieldConverter, } from 'field_converters/chain_field_converter';
|
|
2
|
+
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
3
|
+
const CONTEXT = 'ctx';
|
|
4
|
+
const ERROR1 = 'error 1';
|
|
5
|
+
const ERROR2 = 'error 2';
|
|
6
|
+
describe('chainUnreliableFieldConverter', function () {
|
|
7
|
+
const from = vi.fn();
|
|
8
|
+
const to = vi.fn();
|
|
9
|
+
let chained;
|
|
10
|
+
let result;
|
|
11
|
+
beforeEach(function () {
|
|
12
|
+
from.mockReset();
|
|
13
|
+
to.mockReset();
|
|
14
|
+
chained = chainUnreliableFieldConverter(from, to);
|
|
15
|
+
});
|
|
16
|
+
describe('from succeeds', function () {
|
|
17
|
+
beforeEach(function () {
|
|
18
|
+
from.mockReturnValue({
|
|
19
|
+
type: UnreliableFieldConversionType.Success,
|
|
20
|
+
value: true,
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe('to succeeds', function () {
|
|
24
|
+
beforeEach(function () {
|
|
25
|
+
to.mockReturnValue({
|
|
26
|
+
type: UnreliableFieldConversionType.Success,
|
|
27
|
+
value: 'x',
|
|
28
|
+
});
|
|
29
|
+
result = chained(1, 'x', CONTEXT);
|
|
30
|
+
});
|
|
31
|
+
it('equals expected type', function () {
|
|
32
|
+
expect(result).toEqual({
|
|
33
|
+
type: UnreliableFieldConversionType.Success,
|
|
34
|
+
value: 'x',
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
it('has the original value passed to the from converter', function () {
|
|
38
|
+
expect(from).toHaveBeenCalledOnce();
|
|
39
|
+
expect(from).toHaveBeenCalledWith(1, 'x', CONTEXT);
|
|
40
|
+
});
|
|
41
|
+
it('has passed the from result to the to converter', function () {
|
|
42
|
+
expect(to).toHaveBeenCalledOnce();
|
|
43
|
+
expect(to).toHaveBeenCalledWith(true, 'x', CONTEXT);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('to fails with result', function () {
|
|
47
|
+
beforeEach(function () {
|
|
48
|
+
to.mockReturnValue({
|
|
49
|
+
type: UnreliableFieldConversionType.Failure,
|
|
50
|
+
value: ['y'],
|
|
51
|
+
error: ERROR2,
|
|
52
|
+
});
|
|
53
|
+
result = chained(1, 'x', CONTEXT);
|
|
54
|
+
});
|
|
55
|
+
it('equals expected type', function () {
|
|
56
|
+
expect(result).toEqual({
|
|
57
|
+
type: UnreliableFieldConversionType.Failure,
|
|
58
|
+
value: ['y'],
|
|
59
|
+
error: ERROR2,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('from fails with a value', function () {
|
|
65
|
+
beforeEach(function () {
|
|
66
|
+
from.mockReturnValue({
|
|
67
|
+
type: UnreliableFieldConversionType.Failure,
|
|
68
|
+
value: [true],
|
|
69
|
+
error: ERROR1,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
describe('to succeeds', function () {
|
|
73
|
+
beforeEach(function () {
|
|
74
|
+
to.mockReturnValue({
|
|
75
|
+
type: UnreliableFieldConversionType.Success,
|
|
76
|
+
value: 'x',
|
|
77
|
+
});
|
|
78
|
+
result = chained(1, 'x', CONTEXT);
|
|
79
|
+
});
|
|
80
|
+
it('equals expected type', function () {
|
|
81
|
+
expect(result).toEqual({
|
|
82
|
+
type: UnreliableFieldConversionType.Failure,
|
|
83
|
+
value: ['x'],
|
|
84
|
+
error: ERROR1,
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it('has the original value passed to the from converter', function () {
|
|
88
|
+
expect(from).toHaveBeenCalledOnce();
|
|
89
|
+
expect(from).toHaveBeenCalledWith(1, 'x', CONTEXT);
|
|
90
|
+
});
|
|
91
|
+
it('passes the failure result to the to converter', function () {
|
|
92
|
+
expect(to).toHaveBeenCalledOnce();
|
|
93
|
+
expect(to).toHaveBeenCalledWith(true, 'x', CONTEXT);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('to fails', function () {
|
|
97
|
+
beforeEach(function () {
|
|
98
|
+
to.mockReturnValue({
|
|
99
|
+
type: UnreliableFieldConversionType.Failure,
|
|
100
|
+
value: ['x'],
|
|
101
|
+
error: ERROR2,
|
|
102
|
+
});
|
|
103
|
+
result = chained(1, 'x', CONTEXT);
|
|
104
|
+
});
|
|
105
|
+
it('equals expected type', function () {
|
|
106
|
+
expect(result).toEqual({
|
|
107
|
+
type: UnreliableFieldConversionType.Failure,
|
|
108
|
+
value: ['x'],
|
|
109
|
+
error: ERROR1,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
describe('from fails with no value', function () {
|
|
115
|
+
beforeEach(function () {
|
|
116
|
+
from.mockReturnValue({
|
|
117
|
+
type: UnreliableFieldConversionType.Failure,
|
|
118
|
+
value: null,
|
|
119
|
+
error: ERROR1,
|
|
120
|
+
});
|
|
121
|
+
result = chained(1, 'x', CONTEXT);
|
|
122
|
+
});
|
|
123
|
+
it('equals expected type', function () {
|
|
124
|
+
expect(result).toEqual({
|
|
125
|
+
type: UnreliableFieldConversionType.Failure,
|
|
126
|
+
value: null,
|
|
127
|
+
error: ERROR1,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
it('does not call to converter', function () {
|
|
131
|
+
expect(to).not.toHaveBeenCalled();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe('chainAnnotatedFieldConverter', function () {
|
|
136
|
+
const from = vi.fn();
|
|
137
|
+
const to = vi.fn();
|
|
138
|
+
let chained;
|
|
139
|
+
let result;
|
|
140
|
+
beforeEach(function () {
|
|
141
|
+
from.mockReset();
|
|
142
|
+
to.mockReset();
|
|
143
|
+
chained = chainAnnotatedFieldConverter(from, to);
|
|
144
|
+
});
|
|
145
|
+
describe('value', function () {
|
|
146
|
+
beforeEach(function () {
|
|
147
|
+
from.mockReturnValue({
|
|
148
|
+
value: true,
|
|
149
|
+
readonly: false,
|
|
150
|
+
required: false,
|
|
151
|
+
});
|
|
152
|
+
to.mockReturnValue({
|
|
153
|
+
value: 1,
|
|
154
|
+
readonly: false,
|
|
155
|
+
required: false,
|
|
156
|
+
});
|
|
157
|
+
result = chained('z', 'x', CONTEXT);
|
|
158
|
+
});
|
|
159
|
+
it('returns expected value', function () {
|
|
160
|
+
expect(result).toEqual(expect.objectContaining({
|
|
161
|
+
value: 1,
|
|
162
|
+
}));
|
|
163
|
+
});
|
|
164
|
+
it('calls the from converter', function () {
|
|
165
|
+
expect(from).toHaveBeenCalledOnce();
|
|
166
|
+
expect(from).toHaveBeenCalledWith('z', 'x', CONTEXT);
|
|
167
|
+
});
|
|
168
|
+
it('calls the to converter', function () {
|
|
169
|
+
expect(to).toHaveBeenCalledOnce();
|
|
170
|
+
expect(to).toHaveBeenCalledWith(true, 'x', CONTEXT);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe.each([
|
|
174
|
+
[
|
|
175
|
+
true,
|
|
176
|
+
true,
|
|
177
|
+
true,
|
|
178
|
+
],
|
|
179
|
+
[
|
|
180
|
+
true,
|
|
181
|
+
false,
|
|
182
|
+
true,
|
|
183
|
+
],
|
|
184
|
+
[
|
|
185
|
+
false,
|
|
186
|
+
true,
|
|
187
|
+
true,
|
|
188
|
+
],
|
|
189
|
+
[
|
|
190
|
+
false,
|
|
191
|
+
false,
|
|
192
|
+
false,
|
|
193
|
+
],
|
|
194
|
+
])('from required %s to required %s result %s', function (fromRequired, toRequired, required) {
|
|
195
|
+
beforeEach(function () {
|
|
196
|
+
from.mockReturnValue({
|
|
197
|
+
value: true,
|
|
198
|
+
readonly: false,
|
|
199
|
+
required: fromRequired,
|
|
200
|
+
});
|
|
201
|
+
to.mockReturnValue({
|
|
202
|
+
value: 1,
|
|
203
|
+
readonly: false,
|
|
204
|
+
required: toRequired,
|
|
205
|
+
});
|
|
206
|
+
result = chained('z', 'x', CONTEXT);
|
|
207
|
+
});
|
|
208
|
+
it('required matches expected', function () {
|
|
209
|
+
expect(result.required).toEqual(required);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe.each([
|
|
213
|
+
[
|
|
214
|
+
true,
|
|
215
|
+
true,
|
|
216
|
+
true,
|
|
217
|
+
],
|
|
218
|
+
[
|
|
219
|
+
true,
|
|
220
|
+
false,
|
|
221
|
+
true,
|
|
222
|
+
],
|
|
223
|
+
[
|
|
224
|
+
false,
|
|
225
|
+
true,
|
|
226
|
+
true,
|
|
227
|
+
],
|
|
228
|
+
[
|
|
229
|
+
false,
|
|
230
|
+
false,
|
|
231
|
+
false,
|
|
232
|
+
],
|
|
233
|
+
])('from disabled %s to disabled %s result %s', function (fromDisabled, toDisabled, disabled) {
|
|
234
|
+
beforeEach(function () {
|
|
235
|
+
from.mockReturnValue({
|
|
236
|
+
value: true,
|
|
237
|
+
readonly: fromDisabled,
|
|
238
|
+
required: false,
|
|
239
|
+
});
|
|
240
|
+
to.mockReturnValue({
|
|
241
|
+
value: 1,
|
|
242
|
+
readonly: toDisabled,
|
|
243
|
+
required: false,
|
|
244
|
+
});
|
|
245
|
+
result = chained('z', 'x', CONTEXT);
|
|
246
|
+
});
|
|
247
|
+
it('required matches expected', function () {
|
|
248
|
+
expect(result.readonly).toEqual(disabled);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type AnnotatedFieldConversion, type TwoWayFieldConverter, type UnreliableFieldConversion } from 'types/field_converters';
|
|
2
2
|
export declare class TrimmingStringConverter<ValuePath extends string, Context> implements TwoWayFieldConverter<string, string, never, ValuePath, Context> {
|
|
3
3
|
constructor();
|
|
4
|
-
convert(to: string): string
|
|
5
|
-
revert(from: string):
|
|
4
|
+
convert(to: string): AnnotatedFieldConversion<string>;
|
|
5
|
+
revert(from: string): UnreliableFieldConversion<string, never>;
|
|
6
6
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
2
2
|
export class TrimmingStringConverter {
|
|
3
3
|
constructor() {
|
|
4
4
|
}
|
|
5
5
|
convert(to) {
|
|
6
|
-
return
|
|
6
|
+
return {
|
|
7
|
+
value: to.trim(),
|
|
8
|
+
required: false,
|
|
9
|
+
readonly: false,
|
|
10
|
+
};
|
|
7
11
|
}
|
|
8
12
|
revert(from) {
|
|
9
13
|
return {
|
|
10
|
-
type:
|
|
14
|
+
type: UnreliableFieldConversionType.Success,
|
|
11
15
|
value: from.trim(),
|
|
12
16
|
};
|
|
13
17
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type
|
|
3
|
-
export declare function validatingConverter<V, E, ValuePath extends string, Context>(validators?: readonly
|
|
1
|
+
import { type Validator } from '@strictly/define';
|
|
2
|
+
import { type UnreliableFieldConverter } from 'types/field_converters';
|
|
3
|
+
export declare function validatingConverter<V, E, ValuePath extends string, Context>(validators?: readonly Validator<V, E, ValuePath, Context>[]): UnreliableFieldConverter<V, V, E, ValuePath, Context>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { validate, } from '@strictly/define';
|
|
2
|
+
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
3
|
+
// delete this?
|
|
2
4
|
export function validatingConverter(validators = []) {
|
|
3
5
|
return function (value, valuePath, context) {
|
|
4
6
|
return validators.reduce(function (acc, validator) {
|
|
5
|
-
if (acc.type ===
|
|
6
|
-
const error = validator
|
|
7
|
+
if (acc.type === UnreliableFieldConversionType.Success) {
|
|
8
|
+
const error = validate(validator, value, valuePath, context);
|
|
7
9
|
if (error != null) {
|
|
8
10
|
return {
|
|
9
|
-
type:
|
|
11
|
+
type: UnreliableFieldConversionType.Failure,
|
|
10
12
|
error,
|
|
11
13
|
value: [value],
|
|
12
14
|
};
|
|
@@ -14,7 +16,7 @@ export function validatingConverter(validators = []) {
|
|
|
14
16
|
}
|
|
15
17
|
return acc;
|
|
16
18
|
}, {
|
|
17
|
-
type:
|
|
19
|
+
type: UnreliableFieldConversionType.Success,
|
|
18
20
|
value,
|
|
19
21
|
});
|
|
20
22
|
};
|
package/.out/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
export * from './core/mobx/field_adapter';
|
|
1
2
|
export * from './core/mobx/field_adapter_builder';
|
|
3
|
+
export * from './core/mobx/field_adapters_of_values';
|
|
2
4
|
export * from './core/mobx/flattened_adapters_of_fields';
|
|
5
|
+
export * from './core/mobx/form_fields_of_field_adapters';
|
|
3
6
|
export * from './core/mobx/form_presenter';
|
|
7
|
+
export * from './core/mobx/merge_field_adapters_with_two_way_converter';
|
|
8
|
+
export * from './core/mobx/merge_field_adapters_with_validators';
|
|
4
9
|
export * from './core/mobx/types';
|
|
5
10
|
export * from './core/props';
|
|
6
11
|
export * from './field_converters/integer_to_string_converter';
|
|
@@ -8,9 +13,11 @@ export * from './field_converters/nullable_to_boolean_converter';
|
|
|
8
13
|
export * from './field_converters/select_value_type_converter';
|
|
9
14
|
export * from './field_converters/trimming_string_converter';
|
|
10
15
|
export * from './field_converters/validating_converter';
|
|
11
|
-
export * from './field_validators/minimum_string_length_field_validator';
|
|
12
16
|
export * from './field_value_factories/prototyping_field_value_factory';
|
|
17
|
+
export * from './mantine/error_renderer';
|
|
13
18
|
export * from './mantine/hooks';
|
|
19
|
+
export * from './types/error_of_field';
|
|
14
20
|
export * from './types/field';
|
|
15
|
-
export * from './types/
|
|
21
|
+
export * from './types/field_converters';
|
|
22
|
+
export * from './types/merge_validators';
|
|
16
23
|
export * from './util/partial';
|
package/.out/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
export * from './core/mobx/field_adapter';
|
|
1
2
|
export * from './core/mobx/field_adapter_builder';
|
|
3
|
+
export * from './core/mobx/field_adapters_of_values';
|
|
2
4
|
export * from './core/mobx/flattened_adapters_of_fields';
|
|
5
|
+
export * from './core/mobx/form_fields_of_field_adapters';
|
|
3
6
|
export * from './core/mobx/form_presenter';
|
|
7
|
+
export * from './core/mobx/merge_field_adapters_with_two_way_converter';
|
|
8
|
+
export * from './core/mobx/merge_field_adapters_with_validators';
|
|
4
9
|
export * from './core/mobx/types';
|
|
5
10
|
export * from './core/props';
|
|
6
11
|
export * from './field_converters/integer_to_string_converter';
|
|
@@ -8,9 +13,11 @@ export * from './field_converters/nullable_to_boolean_converter';
|
|
|
8
13
|
export * from './field_converters/select_value_type_converter';
|
|
9
14
|
export * from './field_converters/trimming_string_converter';
|
|
10
15
|
export * from './field_converters/validating_converter';
|
|
11
|
-
export * from './field_validators/minimum_string_length_field_validator';
|
|
12
16
|
export * from './field_value_factories/prototyping_field_value_factory';
|
|
17
|
+
export * from './mantine/error_renderer';
|
|
13
18
|
export * from './mantine/hooks';
|
|
19
|
+
export * from './types/error_of_field';
|
|
14
20
|
export * from './types/field';
|
|
15
|
-
export * from './types/
|
|
21
|
+
export * from './types/field_converters';
|
|
22
|
+
export * from './types/merge_validators';
|
|
16
23
|
export * from './util/partial';
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type CheckboxProps } from '@mantine/core';
|
|
2
2
|
import { type ComponentType } from 'react';
|
|
3
3
|
import { type BooleanFieldsOfFields } from 'types/boolean_fields_of_fields';
|
|
4
|
-
import { type
|
|
4
|
+
import { type ErrorOfField } from 'types/error_of_field';
|
|
5
5
|
import { type Fields } from 'types/field';
|
|
6
|
-
import { type ErrorRenderer } from './hooks';
|
|
7
6
|
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
8
7
|
export type SuppliedCheckboxProps = Pick<CheckboxProps, 'name' | 'checked' | 'disabled' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
|
|
9
|
-
export declare function createCheckbox<F extends Fields, K extends keyof BooleanFieldsOfFields<F>, Props extends SuppliedCheckboxProps>(this: MantineForm<F>, valuePath: K, Checkbox: ComponentType<Props
|
|
8
|
+
export declare function createCheckbox<F extends Fields, K extends keyof BooleanFieldsOfFields<F>, Props extends SuppliedCheckboxProps>(this: MantineForm<F>, valuePath: K, Checkbox: ComponentType<Props>): MantineFieldComponent<SuppliedCheckboxProps, Props, ErrorOfField<F[K]>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
3
|
-
|
|
3
|
+
import { DefaultErrorRenderer, } from './error_renderer';
|
|
4
|
+
export function createCheckbox(valuePath, Checkbox) {
|
|
4
5
|
const onChange = (e) => {
|
|
5
6
|
this.onFieldValueChange?.(valuePath, e.target.checked);
|
|
6
7
|
};
|
|
@@ -17,14 +18,14 @@ export function createCheckbox(valuePath, Checkbox, ErrorRenderer) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
const propSource = () => {
|
|
21
|
-
const {
|
|
21
|
+
const propSource = ({ ErrorRenderer = DefaultErrorRenderer, }) => {
|
|
22
|
+
const { readonly, required, value, error,
|
|
22
23
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
23
24
|
} = this.fields[valuePath];
|
|
24
25
|
return {
|
|
25
26
|
name: valuePath,
|
|
26
27
|
checked: value,
|
|
27
|
-
disabled,
|
|
28
|
+
disabled: readonly,
|
|
28
29
|
required,
|
|
29
30
|
error: error && _jsx(ErrorRenderer, { error: error }),
|
|
30
31
|
onChange,
|
|
@@ -33,5 +34,5 @@ export function createCheckbox(valuePath, Checkbox, ErrorRenderer) {
|
|
|
33
34
|
onKeyUp,
|
|
34
35
|
};
|
|
35
36
|
};
|
|
36
|
-
return createUnsafePartialObserverComponent(Checkbox, propSource);
|
|
37
|
+
return createUnsafePartialObserverComponent(Checkbox, propSource, ['ErrorRenderer']);
|
|
37
38
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
2
2
|
export function createPill(valuePath, Pill) {
|
|
3
3
|
const propSource = () => {
|
|
4
|
-
const {
|
|
4
|
+
const { readonly, value,
|
|
5
5
|
// note: individual pills cannot display an error!
|
|
6
6
|
// error,
|
|
7
7
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
8
8
|
} = this.fields[valuePath];
|
|
9
9
|
return {
|
|
10
10
|
children: value,
|
|
11
|
-
disabled,
|
|
11
|
+
disabled: readonly,
|
|
12
12
|
};
|
|
13
13
|
};
|
|
14
14
|
return createUnsafePartialObserverComponent(Pill, propSource);
|
|
@@ -2,7 +2,7 @@ import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
|
2
2
|
export function createRadio(valuePath, value, Radio) {
|
|
3
3
|
const propSource = () => {
|
|
4
4
|
return {
|
|
5
|
-
disabled: this.fields[valuePath].
|
|
5
|
+
disabled: this.fields[valuePath].readonly,
|
|
6
6
|
value,
|
|
7
7
|
};
|
|
8
8
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { type RadioGroupProps } from '@mantine/core';
|
|
2
2
|
import { type ComponentType } from 'react';
|
|
3
|
-
import { type
|
|
3
|
+
import { type ErrorOfField } from 'types/error_of_field';
|
|
4
4
|
import { type Fields } from 'types/field';
|
|
5
5
|
import { type StringFieldsOfFields } from 'types/string_fields_of_fields';
|
|
6
|
-
import { type ErrorRenderer } from './hooks';
|
|
7
6
|
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
8
7
|
export type SuppliedRadioGroupProps = Pick<RadioGroupProps, 'name' | 'value' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
|
|
9
|
-
export declare function createRadioGroup<F extends Fields, K extends keyof StringFieldsOfFields<F>, Props extends SuppliedRadioGroupProps>(this: MantineForm<F>, valuePath: K, RadioGroup: ComponentType<Props
|
|
8
|
+
export declare function createRadioGroup<F extends Fields, K extends keyof StringFieldsOfFields<F>, Props extends SuppliedRadioGroupProps>(this: MantineForm<F>, valuePath: K, RadioGroup: ComponentType<Props>): MantineFieldComponent<SuppliedRadioGroupProps, Props, ErrorOfField<F[K]>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createUnsafePartialObserverComponent, } from 'util/partial';
|
|
3
|
-
|
|
3
|
+
import { DefaultErrorRenderer, } from './error_renderer';
|
|
4
|
+
export function createRadioGroup(valuePath, RadioGroup) {
|
|
4
5
|
const onChange = (value) => {
|
|
5
6
|
this.onFieldValueChange?.(valuePath, value);
|
|
6
7
|
};
|
|
@@ -17,7 +18,7 @@ export function createRadioGroup(valuePath, RadioGroup, ErrorRenderer) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
const propSource = () => {
|
|
21
|
+
const propSource = ({ ErrorRenderer = DefaultErrorRenderer }) => {
|
|
21
22
|
const { required, value, error, } = this.fields[valuePath];
|
|
22
23
|
return {
|
|
23
24
|
name: valuePath,
|
|
@@ -30,5 +31,5 @@ export function createRadioGroup(valuePath, RadioGroup, ErrorRenderer) {
|
|
|
30
31
|
onKeyUp,
|
|
31
32
|
};
|
|
32
33
|
};
|
|
33
|
-
return createUnsafePartialObserverComponent(RadioGroup, propSource);
|
|
34
|
+
return createUnsafePartialObserverComponent(RadioGroup, propSource, ['ErrorRenderer']);
|
|
34
35
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ErrorOfField } from 'types/error_of_field';
|
|
2
2
|
import { type Fields } from 'types/field';
|
|
3
3
|
import { type StringFieldsOfFields } from 'types/string_fields_of_fields';
|
|
4
|
-
import { type ErrorRenderer } from './hooks';
|
|
5
4
|
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
6
5
|
export type TextInputTarget = Element & {
|
|
7
6
|
value: string;
|
|
@@ -16,4 +15,4 @@ export type SuppliedTextInputProps<T extends TextInputTarget = TextInputTarget>
|
|
|
16
15
|
onBlur: (e: React.FocusEvent<T>) => void;
|
|
17
16
|
onKeyUp: (e: React.KeyboardEvent<T>) => void;
|
|
18
17
|
}>;
|
|
19
|
-
export declare function createTextInput<F extends Fields, K extends keyof StringFieldsOfFields<F>, Props extends SuppliedTextInputProps>(this: MantineForm<F>, valuePath: K, TextInput: React.ComponentType<Props
|
|
18
|
+
export declare function createTextInput<F extends Fields, K extends keyof StringFieldsOfFields<F>, Props extends SuppliedTextInputProps>(this: MantineForm<F>, valuePath: K, TextInput: React.ComponentType<Props>): MantineFieldComponent<SuppliedTextInputProps, Props, ErrorOfField<F[K]>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
3
|
-
|
|
3
|
+
import { DefaultErrorRenderer, } from './error_renderer';
|
|
4
|
+
export function createTextInput(valuePath, TextInput) {
|
|
4
5
|
const onChange = (e) => {
|
|
5
6
|
this.onFieldValueChange?.(valuePath, e.target.value);
|
|
6
7
|
};
|
|
@@ -17,15 +18,15 @@ export function createTextInput(valuePath, TextInput, ErrorRenderer) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
const propSource = () => {
|
|
21
|
-
const {
|
|
21
|
+
const propSource = ({ ErrorRenderer = DefaultErrorRenderer, }) => {
|
|
22
|
+
const { readonly, required, value, error,
|
|
22
23
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
23
24
|
} = this.fields[valuePath];
|
|
24
25
|
return {
|
|
25
26
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
26
27
|
name: valuePath,
|
|
27
28
|
value,
|
|
28
|
-
disabled,
|
|
29
|
+
disabled: readonly,
|
|
29
30
|
required,
|
|
30
31
|
error: error && _jsx(ErrorRenderer, { error: error }),
|
|
31
32
|
onChange,
|
|
@@ -34,5 +35,5 @@ export function createTextInput(valuePath, TextInput, ErrorRenderer) {
|
|
|
34
35
|
onKeyUp,
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
|
-
return createUnsafePartialObserverComponent(TextInput, propSource);
|
|
38
|
+
return createUnsafePartialObserverComponent(TextInput, propSource, ['ErrorRenderer']);
|
|
38
39
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type AllFieldsOfFields } from 'types/all_fields_of_fields';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ErrorOfField } from 'types/error_of_field';
|
|
3
3
|
import { type Fields } from 'types/field';
|
|
4
4
|
import { type ValueTypeOfField } from 'types/value_type_of_field';
|
|
5
|
-
import { type ErrorRenderer } from './hooks';
|
|
6
5
|
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
7
6
|
export type SuppliedValueInputProps<V, T extends Element = Element> = Partial<{
|
|
8
7
|
name: string;
|
|
@@ -14,4 +13,4 @@ export type SuppliedValueInputProps<V, T extends Element = Element> = Partial<{
|
|
|
14
13
|
onBlur: (e: React.FocusEvent<T>) => void;
|
|
15
14
|
onKeyUp: (e: React.KeyboardEvent<T>) => void;
|
|
16
15
|
}>;
|
|
17
|
-
export declare function createValueInput<F extends Fields, K extends keyof AllFieldsOfFields<F>, Props extends SuppliedValueInputProps<ValueTypeOfField<F[K]>>>(this: MantineForm<F>, valuePath: K, ValueInput: React.ComponentType<Props
|
|
16
|
+
export declare function createValueInput<F extends Fields, K extends keyof AllFieldsOfFields<F>, Props extends SuppliedValueInputProps<ValueTypeOfField<F[K]>>>(this: MantineForm<F>, valuePath: K, ValueInput: React.ComponentType<Props>): MantineFieldComponent<SuppliedValueInputProps<ValueTypeOfField<F[K]>>, Props, ErrorOfField<F[K]>>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
3
|
-
|
|
3
|
+
import { DefaultErrorRenderer, } from './error_renderer';
|
|
4
|
+
export function createValueInput(valuePath, ValueInput) {
|
|
4
5
|
const onChange = (value) => {
|
|
5
6
|
this.onFieldValueChange?.(valuePath, value);
|
|
6
7
|
};
|
|
@@ -17,15 +18,15 @@ export function createValueInput(valuePath, ValueInput, ErrorRenderer) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
const propSource = () => {
|
|
21
|
-
const {
|
|
21
|
+
const propSource = ({ ErrorRenderer = DefaultErrorRenderer, }) => {
|
|
22
|
+
const { readonly, required, value, error,
|
|
22
23
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
23
24
|
} = this.fields[valuePath];
|
|
24
25
|
return {
|
|
25
26
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
26
27
|
name: valuePath,
|
|
27
28
|
value,
|
|
28
|
-
disabled,
|
|
29
|
+
disabled: readonly,
|
|
29
30
|
required,
|
|
30
31
|
error: error && _jsx(ErrorRenderer, { error: error }),
|
|
31
32
|
onChange,
|
|
@@ -34,5 +35,5 @@ export function createValueInput(valuePath, ValueInput, ErrorRenderer) {
|
|
|
34
35
|
onKeyUp,
|
|
35
36
|
};
|
|
36
37
|
};
|
|
37
|
-
return createUnsafePartialObserverComponent(ValueInput, propSource);
|
|
38
|
+
return createUnsafePartialObserverComponent(ValueInput, propSource, ['ErrorRenderer']);
|
|
38
39
|
}
|