@strictly/react-form 0.0.1
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/.eslintrc.cjs +26 -0
- package/.out/.storybook/main.d.ts +3 -0
- package/.out/.storybook/main.js +32 -0
- package/.out/.storybook/preview.d.ts +4 -0
- package/.out/.storybook/preview.js +20 -0
- package/.out/.vitest/install_deterministic_random.d.ts +2 -0
- package/.out/.vitest/install_deterministic_random.js +15 -0
- package/.out/.vitest/install_storybook_preview.d.ts +1 -0
- package/.out/.vitest/install_storybook_preview.js +7 -0
- package/.out/.vitest/match_media.d.ts +1 -0
- package/.out/.vitest/match_media.js +5 -0
- package/.out/.vitest/resize_observer.d.ts +1 -0
- package/.out/.vitest/resize_observer.js +4 -0
- package/.out/core/mobx/field_adapter.d.ts +9 -0
- package/.out/core/mobx/field_adapter.js +1 -0
- package/.out/core/mobx/field_adapter_builder.d.ts +22 -0
- package/.out/core/mobx/field_adapter_builder.js +56 -0
- package/.out/core/mobx/flattened_adapters_of_fields.d.ts +9 -0
- package/.out/core/mobx/flattened_adapters_of_fields.js +1 -0
- package/.out/core/mobx/flattened_list_type_defs_of.d.ts +8 -0
- package/.out/core/mobx/flattened_list_type_defs_of.js +1 -0
- package/.out/core/mobx/form_presenter.d.ts +61 -0
- package/.out/core/mobx/form_presenter.js +425 -0
- package/.out/core/mobx/specs/flattened_adapters_of_fields.tests.d.ts +1 -0
- package/.out/core/mobx/specs/flattened_adapters_of_fields.tests.js +13 -0
- package/.out/core/mobx/specs/flattened_list_type_defs_of.tests.d.ts +1 -0
- package/.out/core/mobx/specs/flattened_list_type_defs_of.tests.js +16 -0
- package/.out/core/mobx/specs/form_presenter.tests.d.ts +1 -0
- package/.out/core/mobx/specs/form_presenter.tests.js +697 -0
- package/.out/core/mobx/types.d.ts +19 -0
- package/.out/core/mobx/types.js +1 -0
- package/.out/core/props.d.ts +12 -0
- package/.out/core/props.js +1 -0
- package/.out/field_converters/chain_field_converter.d.ts +3 -0
- package/.out/field_converters/chain_field_converter.js +46 -0
- package/.out/field_converters/identity_converter.d.ts +3 -0
- package/.out/field_converters/identity_converter.js +14 -0
- package/.out/field_converters/integer_to_string_converter.d.ts +7 -0
- package/.out/field_converters/integer_to_string_converter.js +26 -0
- package/.out/field_converters/list_converter.d.ts +2 -0
- package/.out/field_converters/list_converter.js +8 -0
- package/.out/field_converters/maybe_identity_converter.d.ts +8 -0
- package/.out/field_converters/maybe_identity_converter.js +15 -0
- package/.out/field_converters/nullable_to_boolean_converter.d.ts +11 -0
- package/.out/field_converters/nullable_to_boolean_converter.js +31 -0
- package/.out/field_converters/select_value_type_converter.d.ts +23 -0
- package/.out/field_converters/select_value_type_converter.js +60 -0
- package/.out/field_converters/trimming_string_converter.d.ts +6 -0
- package/.out/field_converters/trimming_string_converter.js +14 -0
- package/.out/field_converters/validating_converter.d.ts +3 -0
- package/.out/field_converters/validating_converter.js +21 -0
- package/.out/field_validators/minimum_string_length_field_validator.d.ts +2 -0
- package/.out/field_validators/minimum_string_length_field_validator.js +8 -0
- package/.out/field_value_factories/prototyping_field_value_factory.d.ts +2 -0
- package/.out/field_value_factories/prototyping_field_value_factory.js +5 -0
- package/.out/index.d.ts +16 -0
- package/.out/index.js +16 -0
- package/.out/mantine/create_checkbox.d.ts +9 -0
- package/.out/mantine/create_checkbox.js +37 -0
- package/.out/mantine/create_list.d.ts +15 -0
- package/.out/mantine/create_list.js +16 -0
- package/.out/mantine/create_pill.d.ts +7 -0
- package/.out/mantine/create_pill.js +15 -0
- package/.out/mantine/create_radio.d.ts +8 -0
- package/.out/mantine/create_radio.js +10 -0
- package/.out/mantine/create_radio_group.d.ts +9 -0
- package/.out/mantine/create_radio_group.js +34 -0
- package/.out/mantine/create_text_input.d.ts +19 -0
- package/.out/mantine/create_text_input.js +38 -0
- package/.out/mantine/create_value_input.d.ts +17 -0
- package/.out/mantine/create_value_input.js +38 -0
- package/.out/mantine/hooks.d.ts +56 -0
- package/.out/mantine/hooks.js +135 -0
- package/.out/mantine/specs/checkbox_constants.d.ts +1 -0
- package/.out/mantine/specs/checkbox_constants.js +1 -0
- package/.out/mantine/specs/checkbox_hooks.stories.d.ts +13 -0
- package/.out/mantine/specs/checkbox_hooks.stories.js +63 -0
- package/.out/mantine/specs/checkbox_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/checkbox_hooks.tests.js +74 -0
- package/.out/mantine/specs/list_hooks.stories.d.ts +11 -0
- package/.out/mantine/specs/list_hooks.stories.js +48 -0
- package/.out/mantine/specs/list_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/list_hooks.tests.js +12 -0
- package/.out/mantine/specs/radio_group_constants.d.ts +4 -0
- package/.out/mantine/specs/radio_group_constants.js +11 -0
- package/.out/mantine/specs/radio_group_hooks.stories.d.ts +14 -0
- package/.out/mantine/specs/radio_group_hooks.stories.js +68 -0
- package/.out/mantine/specs/radio_group_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/radio_group_hooks.tests.js +62 -0
- package/.out/mantine/specs/select_hooks.stories.d.ts +12 -0
- package/.out/mantine/specs/select_hooks.stories.js +57 -0
- package/.out/mantine/specs/select_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/select_hooks.tests.js +12 -0
- package/.out/mantine/specs/select_hooks_constant.d.ts +1 -0
- package/.out/mantine/specs/select_hooks_constant.js +1 -0
- package/.out/mantine/specs/text_input_constants.d.ts +1 -0
- package/.out/mantine/specs/text_input_constants.js +1 -0
- package/.out/mantine/specs/text_input_hooks.stories.d.ts +21 -0
- package/.out/mantine/specs/text_input_hooks.stories.js +88 -0
- package/.out/mantine/specs/text_input_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/text_input_hooks.tests.js +79 -0
- package/.out/mantine/specs/value_input_constants.d.ts +2 -0
- package/.out/mantine/specs/value_input_constants.js +2 -0
- package/.out/mantine/specs/value_input_hooks.stories.d.ts +23 -0
- package/.out/mantine/specs/value_input_hooks.stories.js +124 -0
- package/.out/mantine/specs/value_input_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/value_input_hooks.tests.js +12 -0
- package/.out/mantine/types.d.ts +11 -0
- package/.out/mantine/types.js +1 -0
- package/.out/tsconfig.json +27 -0
- package/.out/tsconfig.tsbuildinfo +1 -0
- package/.out/tsup.config.d.ts +3 -0
- package/.out/tsup.config.js +12 -0
- package/.out/types/all_fields_of_fields.d.ts +5 -0
- package/.out/types/all_fields_of_fields.js +1 -0
- package/.out/types/boolean_fields_of_fields.d.ts +5 -0
- package/.out/types/boolean_fields_of_fields.js +1 -0
- package/.out/types/error_type_of_field.d.ts +2 -0
- package/.out/types/error_type_of_field.js +1 -0
- package/.out/types/field.d.ts +7 -0
- package/.out/types/field.js +1 -0
- package/.out/types/field_converters.d.ts +29 -0
- package/.out/types/field_converters.js +5 -0
- package/.out/types/field_validator.d.ts +3 -0
- package/.out/types/field_validator.js +1 -0
- package/.out/types/flattened_form_fields_of.d.ts +9 -0
- package/.out/types/flattened_form_fields_of.js +1 -0
- package/.out/types/list_fields_of_fields.d.ts +5 -0
- package/.out/types/list_fields_of_fields.js +1 -0
- package/.out/types/specs/boolean_fields_of_fields.tests.d.ts +1 -0
- package/.out/types/specs/boolean_fields_of_fields.tests.js +11 -0
- package/.out/types/specs/error_type_of_field.tests.d.ts +1 -0
- package/.out/types/specs/error_type_of_field.tests.js +7 -0
- package/.out/types/specs/flattened_form_fields_of.tests.d.ts +1 -0
- package/.out/types/specs/flattened_form_fields_of.tests.js +13 -0
- package/.out/types/specs/string_fields_of_fields.tests.d.ts +1 -0
- package/.out/types/specs/string_fields_of_fields.tests.js +19 -0
- package/.out/types/specs/value_type_of_field.tests.d.ts +1 -0
- package/.out/types/specs/value_type_of_field.tests.js +7 -0
- package/.out/types/string_fields_of_fields.d.ts +5 -0
- package/.out/types/string_fields_of_fields.js +1 -0
- package/.out/types/value_type_of_field.d.ts +2 -0
- package/.out/types/value_type_of_field.js +1 -0
- package/.out/util/partial.d.ts +11 -0
- package/.out/util/partial.js +74 -0
- package/.out/vitest.workspace.d.ts +2 -0
- package/.out/vitest.workspace.js +22 -0
- package/.storybook/main.ts +40 -0
- package/.storybook/preview.tsx +28 -0
- package/.storybook/vite.config.mts +38 -0
- package/.turbo/turbo-build.log +18 -0
- package/.turbo/turbo-check-types.log +3 -0
- package/.turbo/turbo-release$colon$exports.log +3 -0
- package/.vitest/install_deterministic_random.ts +17 -0
- package/.vitest/install_storybook_preview.ts +9 -0
- package/.vitest/match_media.ts +7 -0
- package/.vitest/resize_observer.ts +5 -0
- package/README.md +2 -0
- package/core/mobx/field_adapter.ts +32 -0
- package/core/mobx/field_adapter_builder.ts +313 -0
- package/core/mobx/flattened_adapters_of_fields.ts +35 -0
- package/core/mobx/flattened_list_type_defs_of.ts +17 -0
- package/core/mobx/form_presenter.ts +705 -0
- package/core/mobx/specs/flattened_adapters_of_fields.tests.ts +72 -0
- package/core/mobx/specs/flattened_list_type_defs_of.tests.ts +35 -0
- package/core/mobx/specs/form_presenter.tests.ts +989 -0
- package/core/mobx/types.ts +54 -0
- package/core/props.ts +21 -0
- package/dist/index.cjs +11479 -0
- package/dist/index.d.cts +345 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +11486 -0
- package/field_converters/chain_field_converter.ts +74 -0
- package/field_converters/identity_converter.ts +39 -0
- package/field_converters/integer_to_string_converter.ts +32 -0
- package/field_converters/list_converter.ts +15 -0
- package/field_converters/maybe_identity_converter.ts +23 -0
- package/field_converters/nullable_to_boolean_converter.ts +56 -0
- package/field_converters/select_value_type_converter.ts +141 -0
- package/field_converters/trimming_string_converter.ts +23 -0
- package/field_converters/validating_converter.ts +35 -0
- package/field_validators/minimum_string_length_field_validator.ts +13 -0
- package/field_value_factories/prototyping_field_value_factory.ts +11 -0
- package/index.ts +16 -0
- package/mantine/create_checkbox.tsx +79 -0
- package/mantine/create_list.tsx +58 -0
- package/mantine/create_pill.tsx +43 -0
- package/mantine/create_radio.tsx +36 -0
- package/mantine/create_radio_group.tsx +71 -0
- package/mantine/create_text_input.tsx +80 -0
- package/mantine/create_value_input.tsx +81 -0
- package/mantine/hooks.tsx +394 -0
- package/mantine/specs/__snapshots__/check_box_hooks.tests.tsx.snap +227 -0
- package/mantine/specs/__snapshots__/checkbox_hooks.tests.tsx.snap +227 -0
- package/mantine/specs/__snapshots__/list_hooks.tests.tsx.snap +68 -0
- package/mantine/specs/__snapshots__/radio_group_hooks.tests.tsx.snap +695 -0
- package/mantine/specs/__snapshots__/select_hooks.tests.tsx.snap +225 -0
- package/mantine/specs/__snapshots__/text_input_hooks.tests.tsx.snap +202 -0
- package/mantine/specs/__snapshots__/value_input_hooks.tests.tsx.snap +613 -0
- package/mantine/specs/checkbox_constants.ts +1 -0
- package/mantine/specs/checkbox_hooks.stories.tsx +79 -0
- package/mantine/specs/checkbox_hooks.tests.tsx +100 -0
- package/mantine/specs/list_hooks.stories.tsx +83 -0
- package/mantine/specs/list_hooks.tests.tsx +15 -0
- package/mantine/specs/radio_group_constants.ts +12 -0
- package/mantine/specs/radio_group_hooks.stories.tsx +103 -0
- package/mantine/specs/radio_group_hooks.tests.tsx +92 -0
- package/mantine/specs/select_hooks.stories.tsx +77 -0
- package/mantine/specs/select_hooks.tests.tsx +14 -0
- package/mantine/specs/select_hooks_constant.ts +1 -0
- package/mantine/specs/text_input_constants.ts +1 -0
- package/mantine/specs/text_input_hooks.stories.tsx +124 -0
- package/mantine/specs/text_input_hooks.tests.tsx +106 -0
- package/mantine/specs/value_input_constants.ts +2 -0
- package/mantine/specs/value_input_hooks.stories.tsx +182 -0
- package/mantine/specs/value_input_hooks.tests.tsx +14 -0
- package/mantine/types.ts +13 -0
- package/package.exports.json +18 -0
- package/package.json +74 -0
- package/tsconfig.build.json +13 -0
- package/tsconfig.json +27 -0
- package/tsup.config.ts +16 -0
- package/types/all_fields_of_fields.ts +9 -0
- package/types/boolean_fields_of_fields.ts +8 -0
- package/types/error_type_of_field.ts +3 -0
- package/types/field.ts +9 -0
- package/types/field_converters.ts +64 -0
- package/types/field_validator.ts +7 -0
- package/types/flattened_form_fields_of.ts +16 -0
- package/types/list_fields_of_fields.ts +7 -0
- package/types/specs/boolean_fields_of_fields.tests.ts +23 -0
- package/types/specs/error_type_of_field.tests.ts +10 -0
- package/types/specs/flattened_form_fields_of.tests.ts +43 -0
- package/types/specs/string_fields_of_fields.tests.ts +40 -0
- package/types/specs/value_type_of_field.tests.ts +10 -0
- package/types/string_fields_of_fields.ts +6 -0
- package/types/value_type_of_field.ts +3 -0
- package/util/partial.tsx +200 -0
- package/vitest.workspace.ts +26 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ToTypeOfFieldAdapter } from './field_adapter';
|
|
2
|
+
import { type FlattenedConvertedFieldsOf, type FormPresenter } from './form_presenter';
|
|
3
|
+
/**
|
|
4
|
+
* Used to extract the supported value paths from a presenter
|
|
5
|
+
*/
|
|
6
|
+
export type ValuePathsOfPresenter<Presenter extends FormPresenter<any, any, any, any>> = Presenter extends FormPresenter<infer _1, infer _2, infer _3, infer ValuePathsToAdapters> ? keyof ValuePathsToAdapters : never;
|
|
7
|
+
/**
|
|
8
|
+
* Used to extract the render type (so the value that is passed to the view) of a given value path
|
|
9
|
+
* from a presenter
|
|
10
|
+
*/
|
|
11
|
+
export type ToTypeOfPresenterValuePath<Presenter extends FormPresenter<any, any, any, any>, K extends ValuePathsOfPresenter<Presenter>> = Presenter extends FormPresenter<infer _1, infer _2, infer _3, infer ValuePathsToAdapters> ? ToTypeOfFieldAdapter<ValuePathsToAdapters[K]> : never;
|
|
12
|
+
/**
|
|
13
|
+
* Extracts the form fields from the presenter. The recommended way is to
|
|
14
|
+
* define the form fields explicitly and use that type to enforce the types
|
|
15
|
+
* of your converters, but generating the FormFields from your presenter
|
|
16
|
+
* is less typing, albeit at the cost of potentially getting type errors
|
|
17
|
+
* reported a long way away from the source
|
|
18
|
+
*/
|
|
19
|
+
export type FormFieldsOfPresenter<Presenter extends FormPresenter<any, any, any, any>> = Presenter extends FormPresenter<infer _1, infer _2, infer _3, infer ValuePathsToAdapters> ? FlattenedConvertedFieldsOf<ValuePathsToAdapters> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Fields } from 'types/field';
|
|
2
|
+
export type FormProps<F extends Fields> = {
|
|
3
|
+
fields: F;
|
|
4
|
+
onFieldValueChange<K extends keyof F>(this: void, key: K, value: F[K]['value']): void;
|
|
5
|
+
onFieldFocus?(this: void, key: keyof F): void;
|
|
6
|
+
onFieldBlur?(this: void, key: keyof F): void;
|
|
7
|
+
onFieldSubmit?(this: void, key: keyof F): boolean | void;
|
|
8
|
+
};
|
|
9
|
+
export type EditorProps<O> = {
|
|
10
|
+
value: O;
|
|
11
|
+
onValueChange: (value: O) => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type FieldConverter, type SafeFieldConverter } from 'types/field_converters';
|
|
2
|
+
export declare function chainFieldConverter<From, Intermediate, To, E1, E2, ValuePath extends string, Context>(from: FieldConverter<From, Intermediate, E1, ValuePath, Context>, to: FieldConverter<Intermediate, To, E2, ValuePath, Context>): FieldConverter<From, To, E1 | E2, ValuePath, Context>;
|
|
3
|
+
export declare function chainSafeFieldConverter<From, Intermediate, To, ValuePath extends string, Context>(from: SafeFieldConverter<From, Intermediate, ValuePath, Context>, to: SafeFieldConverter<Intermediate, To, ValuePath, Context>): SafeFieldConverter<From, To, ValuePath, Context>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { UnreachableError, } from '@strictly/base';
|
|
2
|
+
import { FieldConversionResult, } from 'types/field_converters';
|
|
3
|
+
export function chainFieldConverter(from, to) {
|
|
4
|
+
return function (value, valuePath, context) {
|
|
5
|
+
const fromConversion = from(value, valuePath, context);
|
|
6
|
+
switch (fromConversion.type) {
|
|
7
|
+
case FieldConversionResult.Success:
|
|
8
|
+
return to(fromConversion.value, valuePath, context);
|
|
9
|
+
case FieldConversionResult.Failure:
|
|
10
|
+
if (fromConversion.value != null) {
|
|
11
|
+
const toConversion = to(fromConversion.value[0], valuePath, context);
|
|
12
|
+
switch (toConversion.type) {
|
|
13
|
+
case FieldConversionResult.Success:
|
|
14
|
+
return {
|
|
15
|
+
type: FieldConversionResult.Failure,
|
|
16
|
+
error: fromConversion.error,
|
|
17
|
+
value: [toConversion.value],
|
|
18
|
+
};
|
|
19
|
+
case FieldConversionResult.Failure:
|
|
20
|
+
return {
|
|
21
|
+
type: FieldConversionResult.Failure,
|
|
22
|
+
error: fromConversion.error,
|
|
23
|
+
value: toConversion.value,
|
|
24
|
+
};
|
|
25
|
+
default:
|
|
26
|
+
throw new UnreachableError(toConversion);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return {
|
|
31
|
+
type: FieldConversionResult.Failure,
|
|
32
|
+
error: fromConversion.error,
|
|
33
|
+
value: null,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
default:
|
|
37
|
+
throw new UnreachableError(fromConversion);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function chainSafeFieldConverter(from, to) {
|
|
42
|
+
return function (value, valuePath, context) {
|
|
43
|
+
const intermediate = from(value, valuePath, context);
|
|
44
|
+
return to(intermediate, valuePath, context);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type FieldConverter, type SafeFieldConverter } from 'types/field_converters';
|
|
2
|
+
export declare function safeIdentityConverter<V, ValuePath extends string, Context>(): SafeFieldConverter<V, V, ValuePath, Context>;
|
|
3
|
+
export declare function identityConverter<V, ValuePath extends string, Context>(): FieldConverter<V, V, never, ValuePath, Context>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FieldConversionResult, } from 'types/field_converters';
|
|
2
|
+
export function safeIdentityConverter() {
|
|
3
|
+
return function (v) {
|
|
4
|
+
return v;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export function identityConverter() {
|
|
8
|
+
return function (value) {
|
|
9
|
+
return {
|
|
10
|
+
type: FieldConversionResult.Success,
|
|
11
|
+
value,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type FieldConversion, type TwoWayFieldConverter } from 'types/field_converters';
|
|
2
|
+
export declare class IntegerToStringConverter<E, ValuePath extends string, Context> implements TwoWayFieldConverter<number, string, E, ValuePath, Context> {
|
|
3
|
+
private readonly isNanError;
|
|
4
|
+
constructor(isNanError: E);
|
|
5
|
+
convert(from: number): string;
|
|
6
|
+
revert(from: string): FieldConversion<number, E>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { FieldConversionResult, } from 'types/field_converters';
|
|
2
|
+
export class IntegerToStringConverter {
|
|
3
|
+
isNanError;
|
|
4
|
+
constructor(isNanError) {
|
|
5
|
+
this.isNanError = isNanError;
|
|
6
|
+
}
|
|
7
|
+
convert(from) {
|
|
8
|
+
return Math.floor(from).toString();
|
|
9
|
+
}
|
|
10
|
+
revert(from) {
|
|
11
|
+
const value = parseInt(from, 10);
|
|
12
|
+
if (Number.isNaN(value)) {
|
|
13
|
+
return {
|
|
14
|
+
type: FieldConversionResult.Failure,
|
|
15
|
+
error: this.isNanError,
|
|
16
|
+
value: null,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return {
|
|
21
|
+
type: FieldConversionResult.Success,
|
|
22
|
+
value,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FieldConversion, type TwoWayFieldConverter } from 'types/field_converters';
|
|
2
|
+
export declare class MaybeIdentityConverter<From, To, E, ValuePath extends string, Context> implements TwoWayFieldConverter<From, From | To, E, ValuePath, Context> {
|
|
3
|
+
private readonly converter;
|
|
4
|
+
private readonly isFrom;
|
|
5
|
+
constructor(converter: TwoWayFieldConverter<From, To, E, ValuePath, Context>, isFrom: (to: From | To) => to is From);
|
|
6
|
+
convert(from: From, valuePath: ValuePath, context: Context): To | From;
|
|
7
|
+
revert(from: To | From, valuePath: ValuePath, context: Context): FieldConversion<From, E>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export class MaybeIdentityConverter {
|
|
2
|
+
converter;
|
|
3
|
+
isFrom;
|
|
4
|
+
constructor(converter, isFrom) {
|
|
5
|
+
this.converter = converter;
|
|
6
|
+
this.isFrom = isFrom;
|
|
7
|
+
}
|
|
8
|
+
convert(from, valuePath, context) {
|
|
9
|
+
return this.converter.convert(from, valuePath, context);
|
|
10
|
+
}
|
|
11
|
+
revert(from, valuePath, context) {
|
|
12
|
+
const value = this.isFrom(from) ? this.converter.convert(from, valuePath, context) : from;
|
|
13
|
+
return this.converter.revert(value, valuePath, context);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ReadonlyTypeDefOf, type Type, type ValueTypeOf } from '@strictly/define';
|
|
2
|
+
import { type FieldConversion, type TwoWayFieldConverterWithValueFactory } from 'types/field_converters';
|
|
3
|
+
export declare class NullableToBooleanConverter<T extends Type, E, ValuePath extends string, Context> implements TwoWayFieldConverterWithValueFactory<ValueTypeOf<ReadonlyTypeDefOf<T>> | null, boolean, E, ValuePath, Context> {
|
|
4
|
+
private readonly typeDef;
|
|
5
|
+
private readonly prototype;
|
|
6
|
+
readonly defaultValue: ValueTypeOf<ReadonlyTypeDefOf<T>> | null;
|
|
7
|
+
constructor(typeDef: T, prototype: ValueTypeOf<ReadonlyTypeDefOf<T>>, defaultToNull?: boolean);
|
|
8
|
+
convert(from: ValueTypeOf<ReadonlyTypeDefOf<T>> | null): boolean;
|
|
9
|
+
revert(from: boolean): FieldConversion<ValueTypeOf<ReadonlyTypeDefOf<T>> | null, E>;
|
|
10
|
+
create(): ValueTypeOf<ReadonlyTypeDefOf<T>> | null;
|
|
11
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { copy, } from '@strictly/define';
|
|
2
|
+
import { FieldConversionResult, } from 'types/field_converters';
|
|
3
|
+
export class NullableToBooleanConverter {
|
|
4
|
+
typeDef;
|
|
5
|
+
prototype;
|
|
6
|
+
defaultValue;
|
|
7
|
+
constructor(typeDef, prototype, defaultToNull = true) {
|
|
8
|
+
this.typeDef = typeDef;
|
|
9
|
+
this.prototype = prototype;
|
|
10
|
+
this.defaultValue = defaultToNull ? null : prototype;
|
|
11
|
+
}
|
|
12
|
+
convert(from) {
|
|
13
|
+
return from != null;
|
|
14
|
+
}
|
|
15
|
+
revert(from) {
|
|
16
|
+
if (from) {
|
|
17
|
+
const value = copy(this.typeDef, this.prototype);
|
|
18
|
+
return {
|
|
19
|
+
type: FieldConversionResult.Success,
|
|
20
|
+
value,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
type: FieldConversionResult.Success,
|
|
25
|
+
value: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
create() {
|
|
29
|
+
return this.defaultValue;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type StringKeyOf } from '@strictly/base';
|
|
2
|
+
import { type LiteralTypeDef, type Type, type UnionTypeDef, type ValueTypeOf, type ValueTypesOfDiscriminatedUnion } from '@strictly/define';
|
|
3
|
+
import { type FieldConversion, type TwoWayFieldConverterWithValueFactory } from 'types/field_converters';
|
|
4
|
+
export declare abstract class AbstractSelectValueTypeConverter<T extends Type, To extends string | null, Values extends Readonly<Record<NonNullable<To>, ValueTypeOf<T>>>, NoSuchValueError, ValuePath extends string, Context> implements TwoWayFieldConverterWithValueFactory<ValueTypeOf<T>, keyof Values | null, NoSuchValueError, ValuePath, Context> {
|
|
5
|
+
protected readonly typeDef: T;
|
|
6
|
+
protected readonly values: Values;
|
|
7
|
+
private readonly defaultValueKey;
|
|
8
|
+
private readonly noSuchValueError;
|
|
9
|
+
constructor(typeDef: T, values: Values, defaultValueKey: keyof Values | null, noSuchValueError: NoSuchValueError | null);
|
|
10
|
+
revert(from: keyof Values | null): FieldConversion<ValueTypeOf<T>, NoSuchValueError>;
|
|
11
|
+
convert(from: ValueTypeOf<T>): To;
|
|
12
|
+
protected abstract doConvert(from: ValueTypeOf<T>): To;
|
|
13
|
+
create(): ValueTypeOf<T>;
|
|
14
|
+
}
|
|
15
|
+
export declare class SelectDiscriminatedUnionConverter<U extends UnionTypeDef, To extends StringKeyOf<U['unions']> | null, ValuePath extends string, Context> extends AbstractSelectValueTypeConverter<Type<U>, To, ValueTypesOfDiscriminatedUnion<U>, never, ValuePath, Context> {
|
|
16
|
+
constructor(typeDef: Type<U>, values: ValueTypesOfDiscriminatedUnion<U>, defaultValueKey: keyof U['unions']);
|
|
17
|
+
protected doConvert(from: ValueTypeOf<Type<U>>): any;
|
|
18
|
+
}
|
|
19
|
+
export declare class SelectLiteralConverter<L extends string | number | null, To extends string | null, Values extends Record<NonNullable<L>, NonNullable<To>>, NoSuchValueError, ValuePath extends string, Context> extends AbstractSelectValueTypeConverter<Type<LiteralTypeDef<L>>, To, Record<NonNullable<To>, L>, NoSuchValueError, ValuePath, Context> {
|
|
20
|
+
private readonly valuesToStrings;
|
|
21
|
+
constructor(typeDef: Type<LiteralTypeDef<L>>, valuesToStrings: Values, defaultValue: L | null, noSuchValueError: NoSuchValueError | null);
|
|
22
|
+
protected doConvert(from: L): Values[NonNullable<L>];
|
|
23
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { reverse, } from '@strictly/base';
|
|
2
|
+
import { copy, } from '@strictly/define';
|
|
3
|
+
import { FieldConversionResult, } from 'types/field_converters';
|
|
4
|
+
export class AbstractSelectValueTypeConverter {
|
|
5
|
+
typeDef;
|
|
6
|
+
values;
|
|
7
|
+
defaultValueKey;
|
|
8
|
+
noSuchValueError;
|
|
9
|
+
constructor(typeDef, values, defaultValueKey, noSuchValueError) {
|
|
10
|
+
this.typeDef = typeDef;
|
|
11
|
+
this.values = values;
|
|
12
|
+
this.defaultValueKey = defaultValueKey;
|
|
13
|
+
this.noSuchValueError = noSuchValueError;
|
|
14
|
+
}
|
|
15
|
+
revert(from) {
|
|
16
|
+
const prototype = from == null ? null : this.values[from];
|
|
17
|
+
if (prototype == null && this.noSuchValueError != null) {
|
|
18
|
+
return {
|
|
19
|
+
type: FieldConversionResult.Failure,
|
|
20
|
+
error: this.noSuchValueError,
|
|
21
|
+
value: null,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const value = prototype == null ? null : copy(this.typeDef, prototype);
|
|
25
|
+
// TODO given we are dealing with strings, maybe we should have a check to make sure value is in the record
|
|
26
|
+
// of values?
|
|
27
|
+
return {
|
|
28
|
+
type: FieldConversionResult.Success,
|
|
29
|
+
value: value,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
convert(from) {
|
|
33
|
+
if (from == null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return this.doConvert(from);
|
|
37
|
+
}
|
|
38
|
+
create() {
|
|
39
|
+
return this.defaultValueKey != null ? this.values[this.defaultValueKey] : null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export class SelectDiscriminatedUnionConverter extends AbstractSelectValueTypeConverter {
|
|
43
|
+
constructor(typeDef, values, defaultValueKey) {
|
|
44
|
+
super(typeDef, values, defaultValueKey, null);
|
|
45
|
+
}
|
|
46
|
+
doConvert(from) {
|
|
47
|
+
const { definition: { discriminator, }, } = this.typeDef;
|
|
48
|
+
return from[discriminator];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
export class SelectLiteralConverter extends AbstractSelectValueTypeConverter {
|
|
52
|
+
valuesToStrings;
|
|
53
|
+
constructor(typeDef, valuesToStrings, defaultValue, noSuchValueError) {
|
|
54
|
+
super(typeDef, reverse(valuesToStrings), defaultValue && valuesToStrings[defaultValue], noSuchValueError);
|
|
55
|
+
this.valuesToStrings = valuesToStrings;
|
|
56
|
+
}
|
|
57
|
+
doConvert(from) {
|
|
58
|
+
return from && this.valuesToStrings[from];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type FieldConversion, type TwoWayFieldConverter } from 'types/field_converters';
|
|
2
|
+
export declare class TrimmingStringConverter<ValuePath extends string, Context> implements TwoWayFieldConverter<string, string, never, ValuePath, Context> {
|
|
3
|
+
constructor();
|
|
4
|
+
convert(to: string): string;
|
|
5
|
+
revert(from: string): FieldConversion<string, never>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FieldConversionResult, } from 'types/field_converters';
|
|
2
|
+
export class TrimmingStringConverter {
|
|
3
|
+
constructor() {
|
|
4
|
+
}
|
|
5
|
+
convert(to) {
|
|
6
|
+
return to.trim();
|
|
7
|
+
}
|
|
8
|
+
revert(from) {
|
|
9
|
+
return {
|
|
10
|
+
type: FieldConversionResult.Success,
|
|
11
|
+
value: from.trim(),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type FieldConverter } from 'types/field_converters';
|
|
2
|
+
import { type FieldValidator } from 'types/field_validator';
|
|
3
|
+
export declare function validatingConverter<V, E, ValuePath extends string, Context>(validators?: readonly FieldValidator<V, E, ValuePath, Context>[]): FieldConverter<V, V, E, ValuePath, Context>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FieldConversionResult, } from 'types/field_converters';
|
|
2
|
+
export function validatingConverter(validators = []) {
|
|
3
|
+
return function (value, valuePath, context) {
|
|
4
|
+
return validators.reduce(function (acc, validator) {
|
|
5
|
+
if (acc.type === FieldConversionResult.Success) {
|
|
6
|
+
const error = validator(value, valuePath, context);
|
|
7
|
+
if (error != null) {
|
|
8
|
+
return {
|
|
9
|
+
type: FieldConversionResult.Failure,
|
|
10
|
+
error,
|
|
11
|
+
value: [value],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return acc;
|
|
16
|
+
}, {
|
|
17
|
+
type: FieldConversionResult.Success,
|
|
18
|
+
value,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
}
|
package/.out/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './core/mobx/field_adapter_builder';
|
|
2
|
+
export * from './core/mobx/flattened_adapters_of_fields';
|
|
3
|
+
export * from './core/mobx/form_presenter';
|
|
4
|
+
export * from './core/mobx/types';
|
|
5
|
+
export * from './core/props';
|
|
6
|
+
export * from './field_converters/integer_to_string_converter';
|
|
7
|
+
export * from './field_converters/nullable_to_boolean_converter';
|
|
8
|
+
export * from './field_converters/select_value_type_converter';
|
|
9
|
+
export * from './field_converters/trimming_string_converter';
|
|
10
|
+
export * from './field_converters/validating_converter';
|
|
11
|
+
export * from './field_validators/minimum_string_length_field_validator';
|
|
12
|
+
export * from './field_value_factories/prototyping_field_value_factory';
|
|
13
|
+
export * from './mantine/hooks';
|
|
14
|
+
export * from './types/field';
|
|
15
|
+
export * from './types/flattened_form_fields_of';
|
|
16
|
+
export * from './util/partial';
|
package/.out/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './core/mobx/field_adapter_builder';
|
|
2
|
+
export * from './core/mobx/flattened_adapters_of_fields';
|
|
3
|
+
export * from './core/mobx/form_presenter';
|
|
4
|
+
export * from './core/mobx/types';
|
|
5
|
+
export * from './core/props';
|
|
6
|
+
export * from './field_converters/integer_to_string_converter';
|
|
7
|
+
export * from './field_converters/nullable_to_boolean_converter';
|
|
8
|
+
export * from './field_converters/select_value_type_converter';
|
|
9
|
+
export * from './field_converters/trimming_string_converter';
|
|
10
|
+
export * from './field_converters/validating_converter';
|
|
11
|
+
export * from './field_validators/minimum_string_length_field_validator';
|
|
12
|
+
export * from './field_value_factories/prototyping_field_value_factory';
|
|
13
|
+
export * from './mantine/hooks';
|
|
14
|
+
export * from './types/field';
|
|
15
|
+
export * from './types/flattened_form_fields_of';
|
|
16
|
+
export * from './util/partial';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type CheckboxProps } from '@mantine/core';
|
|
2
|
+
import { type ComponentType } from 'react';
|
|
3
|
+
import { type BooleanFieldsOfFields } from 'types/boolean_fields_of_fields';
|
|
4
|
+
import { type ErrorTypeOfField } from 'types/error_type_of_field';
|
|
5
|
+
import { type Fields } from 'types/field';
|
|
6
|
+
import { type ErrorRenderer } from './hooks';
|
|
7
|
+
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
8
|
+
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>, ErrorRenderer: ErrorRenderer<ErrorTypeOfField<F[K]>>): MantineFieldComponent<SuppliedCheckboxProps, Props>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
3
|
+
export function createCheckbox(valuePath, Checkbox, ErrorRenderer) {
|
|
4
|
+
const onChange = (e) => {
|
|
5
|
+
this.onFieldValueChange?.(valuePath, e.target.checked);
|
|
6
|
+
};
|
|
7
|
+
const onFocus = () => {
|
|
8
|
+
this.onFieldFocus?.(valuePath);
|
|
9
|
+
};
|
|
10
|
+
const onBlur = () => {
|
|
11
|
+
this.onFieldBlur?.(valuePath);
|
|
12
|
+
};
|
|
13
|
+
const onKeyUp = (e) => {
|
|
14
|
+
if (e.key === 'Enter') {
|
|
15
|
+
if (this.onFieldSubmit?.(valuePath)) {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const propSource = () => {
|
|
21
|
+
const { disabled, required, value, error,
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
23
|
+
} = this.fields[valuePath];
|
|
24
|
+
return {
|
|
25
|
+
name: valuePath,
|
|
26
|
+
checked: value,
|
|
27
|
+
disabled,
|
|
28
|
+
required,
|
|
29
|
+
error: error && _jsx(ErrorRenderer, { error: error }),
|
|
30
|
+
onChange,
|
|
31
|
+
onFocus,
|
|
32
|
+
onBlur,
|
|
33
|
+
onKeyUp,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
return createUnsafePartialObserverComponent(Checkbox, propSource);
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ElementOfArray } from '@strictly/base';
|
|
2
|
+
import { type ComponentType } from 'react';
|
|
3
|
+
import { type Fields } from 'types/field';
|
|
4
|
+
import { type ListFieldsOfFields } from 'types/list_fields_of_fields';
|
|
5
|
+
import { type ValueTypeOfField } from 'types/value_type_of_field';
|
|
6
|
+
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
7
|
+
export type SuppliedListProps<Value = any> = {
|
|
8
|
+
values: readonly Value[];
|
|
9
|
+
};
|
|
10
|
+
export declare function createList<F extends Fields, K extends keyof ListFieldsOfFields<F>, Props extends SuppliedListProps<ElementOfArray<ValueTypeOfField<F[K]>>> & {
|
|
11
|
+
children: (value: ElementOfArray<ValueTypeOfField<F[K]>>, index: number) => React.ReactNode;
|
|
12
|
+
}>(this: MantineForm<F>, valuePath: K, List: ComponentType<Props>): MantineFieldComponent<SuppliedListProps<ElementOfArray<ValueTypeOfField<F[K]>>>, Props>;
|
|
13
|
+
export declare function DefaultList<Value>({ values, children, }: SuppliedListProps<Value> & {
|
|
14
|
+
children: (value: Value, index: number) => React.ReactNode;
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
3
|
+
export function createList(valuePath, List) {
|
|
4
|
+
const propSource = () => {
|
|
5
|
+
const values = [...this.fields[valuePath].value];
|
|
6
|
+
return {
|
|
7
|
+
values,
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
return createUnsafePartialObserverComponent(List, propSource);
|
|
11
|
+
}
|
|
12
|
+
export function DefaultList({ values, children, }) {
|
|
13
|
+
return (_jsx(_Fragment, { children: values.map(function (value, index) {
|
|
14
|
+
return children(value, index);
|
|
15
|
+
}) }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type PillProps } from '@mantine/core';
|
|
2
|
+
import { type ComponentType } from 'react';
|
|
3
|
+
import { type AllFieldsOfFields } from 'types/all_fields_of_fields';
|
|
4
|
+
import { type Fields } from 'types/field';
|
|
5
|
+
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
6
|
+
export type SuppliedPillProps = Pick<PillProps, 'children' | 'disabled'>;
|
|
7
|
+
export declare function createPill<F extends Fields, K extends keyof AllFieldsOfFields<F>, Props extends SuppliedPillProps>(this: MantineForm<F>, valuePath: K, Pill: ComponentType<Props>): MantineFieldComponent<SuppliedPillProps, Props>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
2
|
+
export function createPill(valuePath, Pill) {
|
|
3
|
+
const propSource = () => {
|
|
4
|
+
const { disabled, value,
|
|
5
|
+
// note: individual pills cannot display an error!
|
|
6
|
+
// error,
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
8
|
+
} = this.fields[valuePath];
|
|
9
|
+
return {
|
|
10
|
+
children: value,
|
|
11
|
+
disabled,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
return createUnsafePartialObserverComponent(Pill, propSource);
|
|
15
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type RadioProps } from '@mantine/core';
|
|
2
|
+
import { type ComponentType } from 'react';
|
|
3
|
+
import { type Fields } from 'types/field';
|
|
4
|
+
import { type StringFieldsOfFields } from 'types/string_fields_of_fields';
|
|
5
|
+
import { type ValueTypeOfField } from 'types/value_type_of_field';
|
|
6
|
+
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
7
|
+
export type SuppliedRadioProps = Pick<RadioProps, 'value' | 'disabled'>;
|
|
8
|
+
export declare function createRadio<F extends Fields, K extends keyof StringFieldsOfFields<F>, Props extends SuppliedRadioProps>(this: MantineForm<F>, valuePath: K, value: ValueTypeOfField<F[K]>, Radio: ComponentType<Props>): MantineFieldComponent<SuppliedRadioProps, Props>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
2
|
+
export function createRadio(valuePath, value, Radio) {
|
|
3
|
+
const propSource = () => {
|
|
4
|
+
return {
|
|
5
|
+
disabled: this.fields[valuePath].disabled,
|
|
6
|
+
value,
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
return createUnsafePartialObserverComponent(Radio, propSource);
|
|
10
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RadioGroupProps } from '@mantine/core';
|
|
2
|
+
import { type ComponentType } from 'react';
|
|
3
|
+
import { type ErrorTypeOfField } from 'types/error_type_of_field';
|
|
4
|
+
import { type Fields } from 'types/field';
|
|
5
|
+
import { type StringFieldsOfFields } from 'types/string_fields_of_fields';
|
|
6
|
+
import { type ErrorRenderer } from './hooks';
|
|
7
|
+
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
8
|
+
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>, ErrorRenderer: ErrorRenderer<ErrorTypeOfField<F[K]>>): MantineFieldComponent<SuppliedRadioGroupProps, Props>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createUnsafePartialObserverComponent, } from 'util/partial';
|
|
3
|
+
export function createRadioGroup(valuePath, RadioGroup, ErrorRenderer) {
|
|
4
|
+
const onChange = (value) => {
|
|
5
|
+
this.onFieldValueChange?.(valuePath, value);
|
|
6
|
+
};
|
|
7
|
+
const onFocus = () => {
|
|
8
|
+
this.onFieldFocus?.(valuePath);
|
|
9
|
+
};
|
|
10
|
+
const onBlur = () => {
|
|
11
|
+
this.onFieldBlur?.(valuePath);
|
|
12
|
+
};
|
|
13
|
+
const onKeyUp = (e) => {
|
|
14
|
+
if (e.key === 'Enter') {
|
|
15
|
+
if (this.onFieldSubmit?.(valuePath)) {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const propSource = () => {
|
|
21
|
+
const { required, value, error, } = this.fields[valuePath];
|
|
22
|
+
return {
|
|
23
|
+
name: valuePath,
|
|
24
|
+
value,
|
|
25
|
+
required,
|
|
26
|
+
error: error && _jsx(ErrorRenderer, { error: error }),
|
|
27
|
+
onChange,
|
|
28
|
+
onFocus,
|
|
29
|
+
onBlur,
|
|
30
|
+
onKeyUp,
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
return createUnsafePartialObserverComponent(RadioGroup, propSource);
|
|
34
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ErrorTypeOfField } from 'types/error_type_of_field';
|
|
2
|
+
import { type Fields } from 'types/field';
|
|
3
|
+
import { type StringFieldsOfFields } from 'types/string_fields_of_fields';
|
|
4
|
+
import { type ErrorRenderer } from './hooks';
|
|
5
|
+
import { type MantineFieldComponent, type MantineForm } from './types';
|
|
6
|
+
export type TextInputTarget = Element & {
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
export type SuppliedTextInputProps<T extends TextInputTarget = TextInputTarget> = Partial<{
|
|
10
|
+
name: string;
|
|
11
|
+
value: string | number | readonly string[] | undefined;
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
required: boolean;
|
|
14
|
+
onChange: (e: React.ChangeEvent<T>) => void;
|
|
15
|
+
onFocus: (e: React.FocusEvent<T>) => void;
|
|
16
|
+
onBlur: (e: React.FocusEvent<T>) => void;
|
|
17
|
+
onKeyUp: (e: React.KeyboardEvent<T>) => void;
|
|
18
|
+
}>;
|
|
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>, ErrorRenderer: ErrorRenderer<ErrorTypeOfField<F[K]>>): MantineFieldComponent<SuppliedTextInputProps, Props>;
|