@strictly/react-form 0.0.9 → 0.0.11
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_builder.js +18 -6
- package/.out/core/mobx/form_presenter.d.ts +5 -5
- package/.out/core/mobx/form_presenter.js +232 -127
- package/.out/core/mobx/hooks.d.ts +24 -4
- package/.out/core/mobx/hooks.js +26 -5
- package/.out/core/mobx/merge_field_adapters_with_validators.js +1 -5
- package/.out/core/mobx/specs/fixtures.js +2 -1
- package/.out/core/mobx/specs/form_presenter.tests.js +16 -8
- package/.out/core/mobx/specs/sub_form_field_adapters.tests.js +2 -1
- package/.out/core/mobx/sub_form_field_adapters.d.ts +2 -2
- package/.out/field_converters/integer_to_string_converter.js +12 -4
- package/.out/field_converters/maybe_identity_converter.js +12 -4
- package/.out/field_converters/nullable_to_boolean_converter.js +24 -7
- package/.out/field_converters/select_value_type_converter.js +36 -12
- package/.out/mantine/create_checkbox.js +8 -4
- package/.out/mantine/create_fields_view.d.ts +9 -1
- package/.out/mantine/create_fields_view.js +20 -5
- package/.out/mantine/create_form.js +1 -1
- package/.out/mantine/create_radio_group.js +8 -4
- package/.out/mantine/create_text_input.js +8 -4
- package/.out/mantine/create_value_input.js +8 -4
- package/.out/mantine/hooks.d.ts +2 -1
- package/.out/mantine/hooks.js +219 -93
- package/.out/mantine/specs/checkbox_hooks.stories.js +13 -1
- package/.out/mantine/specs/checkbox_hooks.tests.js +22 -9
- package/.out/mantine/specs/create_fields_view.tests.d.ts +1 -0
- package/.out/mantine/specs/create_fields_view.tests.js +17 -0
- package/.out/mantine/specs/fields_view_hooks.stories.d.ts +6 -2
- package/.out/mantine/specs/fields_view_hooks.stories.js +39 -7
- package/.out/mantine/specs/fields_view_hooks.tests.js +30 -1
- package/.out/mantine/specs/radio_group_hooks.stories.js +13 -1
- package/.out/mantine/specs/radio_group_hooks.tests.js +23 -10
- package/.out/mantine/specs/select_hooks.stories.js +13 -1
- package/.out/mantine/specs/text_input_hooks.stories.js +13 -1
- package/.out/mantine/specs/text_input_hooks.tests.js +18 -7
- package/.out/mantine/specs/value_input_hooks.stories.js +14 -2
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/tsup.config.js +2 -9
- package/.out/types/merge_validators.js +1 -4
- package/.out/util/partial.js +5 -5
- package/.out/vitest.workspace.js +2 -10
- 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/core/mobx/form_presenter.ts +15 -14
- package/core/mobx/hooks.tsx +197 -0
- package/core/mobx/specs/form_presenter.tests.ts +24 -5
- package/core/mobx/sub_form_field_adapters.ts +14 -3
- package/dist/index.cjs +395 -277
- package/dist/index.d.cts +52 -26
- package/dist/index.d.ts +52 -26
- package/dist/index.js +398 -276
- package/mantine/create_fields_view.tsx +66 -31
- package/mantine/hooks.tsx +9 -6
- package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +194 -197
- package/mantine/specs/create_fields_view.tests.ts +29 -0
- package/mantine/specs/fields_view_hooks.stories.tsx +58 -15
- package/mantine/specs/fields_view_hooks.tests.tsx +26 -0
- package/package.json +1 -1
- package/core/mobx/hooks.ts +0 -112
|
@@ -9,6 +9,11 @@ import { prototypingFieldValueFactory } from 'field_value_factories/prototyping_
|
|
|
9
9
|
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
10
10
|
import { createMockedAdapter, resetMockAdapter, } from './fixtures';
|
|
11
11
|
const IS_NAN_ERROR = 1;
|
|
12
|
+
class TestFormPresenter extends FormPresenter {
|
|
13
|
+
createModel(value) {
|
|
14
|
+
return new FormModel(this.type, value, this.adapters);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
12
17
|
const originalIntegerToStringAdapter = adapterFromTwoWayConverter(new IntegerToStringConverter(IS_NAN_ERROR), prototypingFieldValueFactory(0));
|
|
13
18
|
const originalBooleanToBooleanAdapter = identityAdapter(false);
|
|
14
19
|
describe('all', function () {
|
|
@@ -286,7 +291,7 @@ describe('all', function () {
|
|
|
286
291
|
const adapters = {
|
|
287
292
|
$: integerToStringAdapter,
|
|
288
293
|
};
|
|
289
|
-
const presenter = new
|
|
294
|
+
const presenter = new TestFormPresenter(typeDef, adapters);
|
|
290
295
|
const originalValue = 2;
|
|
291
296
|
let model;
|
|
292
297
|
beforeEach(function () {
|
|
@@ -330,7 +335,8 @@ describe('all', function () {
|
|
|
330
335
|
const newValue = -1;
|
|
331
336
|
const errorCode = 65;
|
|
332
337
|
beforeEach(function () {
|
|
333
|
-
|
|
338
|
+
var _a;
|
|
339
|
+
(_a = integerToStringAdapter.revert) === null || _a === void 0 ? void 0 : _a.mockReturnValueOnce({
|
|
334
340
|
type: UnreliableFieldConversionType.Failure,
|
|
335
341
|
error: errorCode,
|
|
336
342
|
value: [newValue],
|
|
@@ -383,7 +389,7 @@ describe('all', function () {
|
|
|
383
389
|
const converters = {
|
|
384
390
|
'$.*': integerToStringAdapter,
|
|
385
391
|
};
|
|
386
|
-
const presenter = new
|
|
392
|
+
const presenter = new TestFormPresenter(typeDef, converters);
|
|
387
393
|
let originalValue;
|
|
388
394
|
let model;
|
|
389
395
|
beforeEach(function () {
|
|
@@ -543,7 +549,8 @@ describe('all', function () {
|
|
|
543
549
|
'7',
|
|
544
550
|
],
|
|
545
551
|
])('it reports the value of field %s as %s', function (path, fieldValue) {
|
|
546
|
-
|
|
552
|
+
var _a;
|
|
553
|
+
expect((_a = model.fields[path]) === null || _a === void 0 ? void 0 : _a.value).toBe(fieldValue);
|
|
547
554
|
});
|
|
548
555
|
it.each([
|
|
549
556
|
[
|
|
@@ -563,7 +570,8 @@ describe('all', function () {
|
|
|
563
570
|
2,
|
|
564
571
|
],
|
|
565
572
|
])('it reports the error of field %s', function (path, error) {
|
|
566
|
-
|
|
573
|
+
var _a;
|
|
574
|
+
expect((_a = model.fields[path]) === null || _a === void 0 ? void 0 : _a.error).toBe(error);
|
|
567
575
|
});
|
|
568
576
|
});
|
|
569
577
|
describe('add defined value', function () {
|
|
@@ -661,7 +669,7 @@ describe('all', function () {
|
|
|
661
669
|
$: adapterFromTwoWayConverter(new NullableToBooleanConverter(type, [1], null)),
|
|
662
670
|
'$.*': integerToStringAdapter,
|
|
663
671
|
};
|
|
664
|
-
const presenter = new
|
|
672
|
+
const presenter = new TestFormPresenter(type, adapters);
|
|
665
673
|
let originalValue;
|
|
666
674
|
let model;
|
|
667
675
|
beforeEach(function () {
|
|
@@ -709,7 +717,7 @@ describe('all', function () {
|
|
|
709
717
|
'$.x:a': identityAdapter(0).narrow,
|
|
710
718
|
'$.y:b': identityAdapter(false).narrow,
|
|
711
719
|
};
|
|
712
|
-
const presenter = new
|
|
720
|
+
const presenter = new TestFormPresenter(type, adapters);
|
|
713
721
|
describe('isValuePathActive', function () {
|
|
714
722
|
describe('discriminator x', function () {
|
|
715
723
|
const model = presenter.createModel({
|
|
@@ -766,7 +774,7 @@ describe('all', function () {
|
|
|
766
774
|
$: integerToStringAdapter,
|
|
767
775
|
'$.fake': booleanToBooleanAdapter,
|
|
768
776
|
};
|
|
769
|
-
const presenter = new
|
|
777
|
+
const presenter = new TestFormPresenter(typeDef, converters);
|
|
770
778
|
let originalValue;
|
|
771
779
|
let model;
|
|
772
780
|
beforeEach(function () {
|
|
@@ -43,12 +43,13 @@ describe('subFormFieldAdapters', () => {
|
|
|
43
43
|
expect(returnedValue).toEqual(mockedReturnedValue);
|
|
44
44
|
});
|
|
45
45
|
it('calls revert with the correct paths and values', () => {
|
|
46
|
+
var _a, _b;
|
|
46
47
|
const mockedReturnedValue = {
|
|
47
48
|
type: UnreliableFieldConversionType.Success,
|
|
48
49
|
value: 'ok',
|
|
49
50
|
};
|
|
50
51
|
mockedFieldAdapter1.revert.mockReturnValue(mockedReturnedValue);
|
|
51
|
-
const returnedValue = adapters['$.a'].revert
|
|
52
|
+
const returnedValue = (_b = (_a = adapters['$.a']).revert) === null || _b === void 0 ? void 0 : _b.call(_a, true, '$.a', { a: 'y' });
|
|
52
53
|
expect(fieldAdapter1.revert).toHaveBeenCalledWith(true, '$', 'y');
|
|
53
54
|
expect(returnedValue).toEqual(mockedReturnedValue);
|
|
54
55
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type StringConcatOf } from '@strictly/base';
|
|
2
|
-
import { type Type, type ValueOfType } from '@strictly/define';
|
|
2
|
+
import { type ReadonlyTypeOfType, type Type, type ValueOfType } from '@strictly/define';
|
|
3
3
|
import { type ErrorOfFieldAdapter, type FieldAdapter, type FromOfFieldAdapter, type ToOfFieldAdapter, type ValuePathOfFieldAdapter } from './field_adapter';
|
|
4
4
|
type SubFormFieldAdapter<F extends FieldAdapter, ValuePath extends string, Context> = FieldAdapter<FromOfFieldAdapter<F>, ToOfFieldAdapter<F>, ErrorOfFieldAdapter<F>, ValuePathOfFieldAdapter<F> extends StringConcatOf<'$', infer ValuePathSuffix> ? `${ValuePath}${ValuePathSuffix}` : string, Context>;
|
|
5
5
|
type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, ValuePath extends string, Context> = {
|
|
6
6
|
[K in keyof SubAdapters as K extends StringConcatOf<'$', infer TypePathSuffix> ? `${TypePath}${TypePathSuffix}` : never]: SubFormFieldAdapter<SubAdapters[K], ValuePath, Context>;
|
|
7
7
|
};
|
|
8
|
-
export declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, TypePathsToValuePaths extends Record<TypePath, string>, ContextType extends Type>(subAdapters: SubAdapters, parentTypePath: TypePath, contextType: ContextType): SubFormFieldAdapters<SubAdapters, TypePath, TypePathsToValuePaths[TypePath], ValueOfType<ContextType
|
|
8
|
+
export declare function subFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, TypePathsToValuePaths extends Record<TypePath, string>, ContextType extends Type>(subAdapters: SubAdapters, parentTypePath: TypePath, contextType: ContextType): SubFormFieldAdapters<SubAdapters, TypePath, TypePathsToValuePaths[TypePath], ValueOfType<ReadonlyTypeOfType<ContextType>>>;
|
|
9
9
|
export {};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
2
2
|
export class IntegerToStringConverter {
|
|
3
|
-
isNanError;
|
|
4
|
-
base;
|
|
5
3
|
constructor(isNanError, base = 10) {
|
|
6
|
-
this
|
|
7
|
-
|
|
4
|
+
Object.defineProperty(this, "isNanError", {
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true,
|
|
8
|
+
value: isNanError
|
|
9
|
+
});
|
|
10
|
+
Object.defineProperty(this, "base", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
configurable: true,
|
|
13
|
+
writable: true,
|
|
14
|
+
value: base
|
|
15
|
+
});
|
|
8
16
|
}
|
|
9
17
|
convert(from) {
|
|
10
18
|
const value = Math.floor(from).toString();
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
export class MaybeIdentityConverter {
|
|
2
|
-
converter;
|
|
3
|
-
isFrom;
|
|
4
2
|
constructor(converter, isFrom) {
|
|
5
|
-
this
|
|
6
|
-
|
|
3
|
+
Object.defineProperty(this, "converter", {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true,
|
|
7
|
+
value: converter
|
|
8
|
+
});
|
|
9
|
+
Object.defineProperty(this, "isFrom", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
writable: true,
|
|
13
|
+
value: isFrom
|
|
14
|
+
});
|
|
7
15
|
}
|
|
8
16
|
convert(from, valuePath, context) {
|
|
9
17
|
return this.converter.convert(from, valuePath, context);
|
|
@@ -1,14 +1,31 @@
|
|
|
1
1
|
import { copy, } from '@strictly/define';
|
|
2
2
|
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
3
3
|
export class NullableToBooleanConverter {
|
|
4
|
-
typeDef;
|
|
5
|
-
prototype;
|
|
6
|
-
nullType;
|
|
7
|
-
defaultValue;
|
|
8
4
|
constructor(typeDef, prototype, nullType, defaultToNull = true) {
|
|
9
|
-
this
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
Object.defineProperty(this, "typeDef", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: typeDef
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(this, "prototype", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: prototype
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "nullType", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: nullType
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "defaultValue", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
12
29
|
this.defaultValue = defaultToNull ? this.nullType : prototype;
|
|
13
30
|
}
|
|
14
31
|
convert(from) {
|
|
@@ -2,17 +2,37 @@ import { reverse, } from '@strictly/base';
|
|
|
2
2
|
import { copy, } from '@strictly/define';
|
|
3
3
|
import { UnreliableFieldConversionType, } from 'types/field_converters';
|
|
4
4
|
export class AbstractSelectValueTypeConverter {
|
|
5
|
-
typeDef;
|
|
6
|
-
values;
|
|
7
|
-
defaultValueKey;
|
|
8
|
-
noSuchValueError;
|
|
9
|
-
required;
|
|
10
5
|
constructor(typeDef, values, defaultValueKey, noSuchValueError, required) {
|
|
11
|
-
this
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
Object.defineProperty(this, "typeDef", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
writable: true,
|
|
10
|
+
value: typeDef
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(this, "values", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: values
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "defaultValueKey", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: defaultValueKey
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "noSuchValueError", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: noSuchValueError
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(this, "required", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
configurable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
value: required
|
|
35
|
+
});
|
|
16
36
|
}
|
|
17
37
|
revert(from) {
|
|
18
38
|
const prototype = from == null ? null : this.values[from];
|
|
@@ -53,10 +73,14 @@ export class SelectDiscriminatedUnionConverter extends AbstractSelectValueTypeCo
|
|
|
53
73
|
}
|
|
54
74
|
}
|
|
55
75
|
export class SelectLiteralConverter extends AbstractSelectValueTypeConverter {
|
|
56
|
-
valuesToStrings;
|
|
57
76
|
constructor(typeDef, valuesToStrings, defaultValue, noSuchValueError, required) {
|
|
58
77
|
super(typeDef, reverse(valuesToStrings), defaultValue && valuesToStrings[defaultValue], noSuchValueError, required);
|
|
59
|
-
this
|
|
78
|
+
Object.defineProperty(this, "valuesToStrings", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true,
|
|
81
|
+
writable: true,
|
|
82
|
+
value: valuesToStrings
|
|
83
|
+
});
|
|
60
84
|
}
|
|
61
85
|
doConvert(from) {
|
|
62
86
|
return this.valuesToStrings[from];
|
|
@@ -3,17 +3,21 @@ import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
|
3
3
|
import { DefaultErrorRenderer, } from './error_renderer';
|
|
4
4
|
export function createCheckbox(valuePath, Checkbox) {
|
|
5
5
|
const onChange = (e) => {
|
|
6
|
-
|
|
6
|
+
var _a;
|
|
7
|
+
(_a = this.onFieldValueChange) === null || _a === void 0 ? void 0 : _a.call(this, valuePath, e.target.checked);
|
|
7
8
|
};
|
|
8
9
|
const onFocus = () => {
|
|
9
|
-
|
|
10
|
+
var _a;
|
|
11
|
+
(_a = this.onFieldFocus) === null || _a === void 0 ? void 0 : _a.call(this, valuePath);
|
|
10
12
|
};
|
|
11
13
|
const onBlur = () => {
|
|
12
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = this.onFieldBlur) === null || _a === void 0 ? void 0 : _a.call(this, valuePath);
|
|
13
16
|
};
|
|
14
17
|
const onKeyUp = (e) => {
|
|
18
|
+
var _a;
|
|
15
19
|
if (e.key === 'Enter') {
|
|
16
|
-
if (this.onFieldSubmit
|
|
20
|
+
if ((_a = this.onFieldSubmit) === null || _a === void 0 ? void 0 : _a.call(this, valuePath)) {
|
|
17
21
|
e.preventDefault();
|
|
18
22
|
}
|
|
19
23
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import { type StringConcatOf } from '@strictly/base';
|
|
1
2
|
import type { FieldsViewProps } from 'core/props';
|
|
2
3
|
import type { ComponentType } from 'react';
|
|
3
4
|
import type { AllFieldsOfFields } from 'types/all_fields_of_fields';
|
|
4
5
|
import type { Fields } from 'types/field';
|
|
5
6
|
import type { SubFormFields } from 'types/sub_form_fields';
|
|
6
7
|
import type { MantineFieldComponent } from './types';
|
|
7
|
-
export
|
|
8
|
+
export type CallbackMapper<ValuePath extends string> = {
|
|
9
|
+
<Cb extends (...args: any[]) => any>(cb: Cb): Parameters<Cb> extends [infer SubFormValuePath extends string, ...(infer Rest)] ? SubFormValuePath extends StringConcatOf<ValuePath, infer Postfix> ? (valuePath: `$${Postfix}`, ...rest: Rest) => ReturnType<Cb> : never : never;
|
|
10
|
+
};
|
|
11
|
+
export type FieldsView<ValuePath extends string = string, C extends ComponentType<any> = ComponentType<any>> = {
|
|
12
|
+
Component: C;
|
|
13
|
+
callbackMapper: CallbackMapper<ValuePath>;
|
|
14
|
+
};
|
|
15
|
+
export declare function createFieldsView<F extends Fields, K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>, observableProps: FieldsViewProps<F>): FieldsView<K, MantineFieldComponent<FieldsViewProps<P['fields']>, P, never>>;
|
|
@@ -14,16 +14,19 @@ export function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
|
14
14
|
observableProps.onFieldValueChange(toKey(subKey), value);
|
|
15
15
|
}
|
|
16
16
|
function onFieldBlur(subKey) {
|
|
17
|
-
|
|
17
|
+
var _a;
|
|
18
|
+
(_a = observableProps.onFieldBlur) === null || _a === void 0 ? void 0 : _a.call(observableProps, toKey(subKey));
|
|
18
19
|
}
|
|
19
20
|
function onFieldFocus(subKey) {
|
|
20
|
-
|
|
21
|
+
var _a;
|
|
22
|
+
(_a = observableProps.onFieldFocus) === null || _a === void 0 ? void 0 : _a.call(observableProps, toKey(subKey));
|
|
21
23
|
}
|
|
22
24
|
function onFieldSubmit(subKey) {
|
|
23
|
-
|
|
25
|
+
var _a;
|
|
26
|
+
(_a = observableProps.onFieldSubmit) === null || _a === void 0 ? void 0 : _a.call(observableProps, toKey(subKey));
|
|
24
27
|
}
|
|
25
28
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
26
|
-
|
|
29
|
+
const Component = observer(function (props) {
|
|
27
30
|
// convert fields to sub-fields
|
|
28
31
|
const subFields = Object.entries(observableProps.fields).reduce((acc, [fieldKey, fieldValue,]) => {
|
|
29
32
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
@@ -34,6 +37,18 @@ export function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
|
34
37
|
},
|
|
35
38
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
36
39
|
{});
|
|
37
|
-
return (_jsx(FieldsView, {
|
|
40
|
+
return (_jsx(FieldsView, Object.assign({}, props, { fields: subFields, onFieldBlur: onFieldBlur, onFieldFocus: onFieldFocus, onFieldSubmit: onFieldSubmit, onFieldValueChange: onFieldValueChange })));
|
|
38
41
|
});
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
43
|
+
const callbackMapper = ((callback) => {
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
+
return (subFormValuePath, ...args) => {
|
|
46
|
+
const valuePath = toKey(subFormValuePath);
|
|
47
|
+
return callback(valuePath, ...args);
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
Component,
|
|
52
|
+
callbackMapper,
|
|
53
|
+
};
|
|
39
54
|
}
|
|
@@ -8,6 +8,6 @@ export function createForm(valuePath, Form, observableProps) {
|
|
|
8
8
|
const onValueChange = useCallback((value) => {
|
|
9
9
|
observableProps.onFieldValueChange(valuePath, value);
|
|
10
10
|
}, []);
|
|
11
|
-
return (_jsx(Form, {
|
|
11
|
+
return (_jsx(Form, Object.assign({}, props, { onValueChange: onValueChange, value: value })));
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -3,17 +3,21 @@ import { createUnsafePartialObserverComponent, } from 'util/partial';
|
|
|
3
3
|
import { DefaultErrorRenderer, } from './error_renderer';
|
|
4
4
|
export function createRadioGroup(valuePath, RadioGroup) {
|
|
5
5
|
const onChange = (value) => {
|
|
6
|
-
|
|
6
|
+
var _a;
|
|
7
|
+
(_a = this.onFieldValueChange) === null || _a === void 0 ? void 0 : _a.call(this, valuePath, value);
|
|
7
8
|
};
|
|
8
9
|
const onFocus = () => {
|
|
9
|
-
|
|
10
|
+
var _a;
|
|
11
|
+
(_a = this.onFieldFocus) === null || _a === void 0 ? void 0 : _a.call(this, valuePath);
|
|
10
12
|
};
|
|
11
13
|
const onBlur = () => {
|
|
12
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = this.onFieldBlur) === null || _a === void 0 ? void 0 : _a.call(this, valuePath);
|
|
13
16
|
};
|
|
14
17
|
const onKeyUp = (e) => {
|
|
18
|
+
var _a;
|
|
15
19
|
if (e.key === 'Enter') {
|
|
16
|
-
if (this.onFieldSubmit
|
|
20
|
+
if ((_a = this.onFieldSubmit) === null || _a === void 0 ? void 0 : _a.call(this, valuePath)) {
|
|
17
21
|
e.preventDefault();
|
|
18
22
|
}
|
|
19
23
|
}
|
|
@@ -3,17 +3,21 @@ import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
|
3
3
|
import { DefaultErrorRenderer, } from './error_renderer';
|
|
4
4
|
export function createTextInput(valuePath, TextInput) {
|
|
5
5
|
const onChange = (e) => {
|
|
6
|
-
|
|
6
|
+
var _a;
|
|
7
|
+
(_a = this.onFieldValueChange) === null || _a === void 0 ? void 0 : _a.call(this, valuePath, e.target.value);
|
|
7
8
|
};
|
|
8
9
|
const onFocus = () => {
|
|
9
|
-
|
|
10
|
+
var _a;
|
|
11
|
+
(_a = this.onFieldFocus) === null || _a === void 0 ? void 0 : _a.call(this, valuePath);
|
|
10
12
|
};
|
|
11
13
|
const onBlur = () => {
|
|
12
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = this.onFieldBlur) === null || _a === void 0 ? void 0 : _a.call(this, valuePath);
|
|
13
16
|
};
|
|
14
17
|
const onKeyUp = (e) => {
|
|
18
|
+
var _a;
|
|
15
19
|
if (e.key === 'Enter') {
|
|
16
|
-
if (this.onFieldSubmit
|
|
20
|
+
if ((_a = this.onFieldSubmit) === null || _a === void 0 ? void 0 : _a.call(this, valuePath)) {
|
|
17
21
|
e.preventDefault();
|
|
18
22
|
}
|
|
19
23
|
}
|
|
@@ -3,17 +3,21 @@ import { createUnsafePartialObserverComponent } from 'util/partial';
|
|
|
3
3
|
import { DefaultErrorRenderer, } from './error_renderer';
|
|
4
4
|
export function createValueInput(valuePath, ValueInput) {
|
|
5
5
|
const onChange = (value) => {
|
|
6
|
-
|
|
6
|
+
var _a;
|
|
7
|
+
(_a = this.onFieldValueChange) === null || _a === void 0 ? void 0 : _a.call(this, valuePath, value);
|
|
7
8
|
};
|
|
8
9
|
const onFocus = () => {
|
|
9
|
-
|
|
10
|
+
var _a;
|
|
11
|
+
(_a = this.onFieldFocus) === null || _a === void 0 ? void 0 : _a.call(this, valuePath);
|
|
10
12
|
};
|
|
11
13
|
const onBlur = () => {
|
|
12
|
-
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = this.onFieldBlur) === null || _a === void 0 ? void 0 : _a.call(this, valuePath);
|
|
13
16
|
};
|
|
14
17
|
const onKeyUp = (e) => {
|
|
18
|
+
var _a;
|
|
15
19
|
if (e.key === 'Enter') {
|
|
16
|
-
if (this.onFieldSubmit
|
|
20
|
+
if ((_a = this.onFieldSubmit) === null || _a === void 0 ? void 0 : _a.call(this, valuePath)) {
|
|
17
21
|
e.preventDefault();
|
|
18
22
|
}
|
|
19
23
|
}
|
package/.out/mantine/hooks.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { type StringFieldsOfFields } from 'types/string_fields_of_fields';
|
|
|
11
11
|
import { type SubFormFields } from 'types/sub_form_fields';
|
|
12
12
|
import { type ValueTypeOfField } from 'types/value_type_of_field';
|
|
13
13
|
import { type SuppliedCheckboxProps } from './create_checkbox';
|
|
14
|
+
import { type FieldsView } from './create_fields_view';
|
|
14
15
|
import { DefaultList, type SuppliedListProps } from './create_list';
|
|
15
16
|
import { type SuppliedPillProps } from './create_pill';
|
|
16
17
|
import { type SuppliedRadioProps } from './create_radio';
|
|
@@ -51,7 +52,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
|
|
|
51
52
|
pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
|
|
52
53
|
pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P, ErrorOfField<F[K]>>;
|
|
53
54
|
list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>, never>;
|
|
54
|
-
fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): MantineFieldComponent<FieldsViewProps<P['fields']>, P, never
|
|
55
|
+
fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): FieldsView<K, MantineFieldComponent<FieldsViewProps<P['fields']>, P, never>>;
|
|
55
56
|
form<K extends keyof AllFieldsOfFields<F>, P extends FormProps<ValueTypeOfField<F[K]>> = FormProps<ValueTypeOfField<F[K]>>>(valuePath: K, Form: ComponentType<P>): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never>;
|
|
56
57
|
}
|
|
57
58
|
export {};
|