@strictly/react-form 0.0.4 → 0.0.6
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.d.ts +1 -1
- package/.out/core/mobx/field_adapter_builder.js +1 -2
- package/.out/core/mobx/hooks.d.ts +10 -0
- package/.out/core/mobx/hooks.js +47 -0
- package/.out/core/props.d.ts +2 -2
- package/.out/index.d.ts +1 -0
- package/.out/index.js +1 -0
- package/.out/mantine/create_fields_view.d.ts +7 -0
- package/.out/mantine/{create_sub_form.js → create_fields_view.js} +4 -5
- package/.out/mantine/create_form.d.ts +7 -0
- package/.out/mantine/create_form.js +13 -0
- package/.out/mantine/create_list.d.ts +5 -4
- package/.out/mantine/create_list.js +4 -2
- package/.out/mantine/hooks.d.ts +8 -5
- package/.out/mantine/hooks.js +17 -7
- package/.out/mantine/specs/checkbox_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/checkbox_hooks.stories.js +2 -2
- package/.out/mantine/specs/{sub_form_hooks.stories.d.ts → fields_view_hooks.stories.d.ts} +2 -2
- package/.out/mantine/specs/{sub_form_hooks.stories.js → fields_view_hooks.stories.js} +9 -8
- package/.out/mantine/specs/fields_view_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/fields_view_hooks.tests.js +12 -0
- package/.out/mantine/specs/form_hooks.stories.d.ts +12 -0
- package/.out/mantine/specs/form_hooks.stories.js +60 -0
- package/.out/mantine/specs/form_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/form_hooks.tests.js +12 -0
- package/.out/mantine/specs/list_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/list_hooks.stories.js +8 -8
- package/.out/mantine/specs/radio_group_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/radio_group_hooks.stories.js +2 -2
- package/.out/mantine/specs/select_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/select_hooks.stories.js +2 -2
- package/.out/mantine/specs/text_input_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/text_input_hooks.stories.js +2 -2
- package/.out/mantine/specs/value_input_hooks.stories.d.ts +2 -2
- package/.out/mantine/specs/value_input_hooks.stories.js +2 -2
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.turbo/turbo-build.log +7 -7
- package/.turbo/turbo-check-types.log +1 -1
- package/core/mobx/field_adapter_builder.ts +3 -4
- package/core/mobx/hooks.ts +94 -0
- package/core/props.ts +2 -2
- package/dist/index.cjs +175 -95
- package/dist/index.d.cts +48 -39
- package/dist/index.d.ts +48 -39
- package/dist/index.js +170 -86
- package/index.ts +1 -0
- package/mantine/{create_sub_form.tsx → create_fields_view.tsx} +27 -16
- package/mantine/create_form.tsx +43 -0
- package/mantine/create_list.tsx +10 -4
- package/mantine/hooks.tsx +51 -16
- package/mantine/specs/__snapshots__/fields_view_hooks.tests.tsx.snap +460 -0
- package/mantine/specs/__snapshots__/form_hooks.tests.tsx.snap +273 -0
- package/mantine/specs/__snapshots__/list_hooks.tests.tsx.snap +56 -8
- package/mantine/specs/checkbox_hooks.stories.tsx +4 -4
- package/mantine/specs/{sub_form_hooks.stories.tsx → fields_view_hooks.stories.tsx} +23 -11
- package/mantine/specs/fields_view_hooks.tests.tsx +15 -0
- package/mantine/specs/form_hooks.stories.tsx +107 -0
- package/mantine/specs/form_hooks.tests.tsx +15 -0
- package/mantine/specs/list_hooks.stories.tsx +20 -10
- package/mantine/specs/radio_group_hooks.stories.tsx +4 -4
- package/mantine/specs/select_hooks.stories.tsx +4 -4
- package/mantine/specs/text_input_hooks.stories.tsx +4 -4
- package/mantine/specs/value_input_hooks.stories.tsx +4 -4
- package/package.json +1 -1
- package/.out/field_converters/list_converter.d.ts +0 -2
- package/.out/field_converters/list_converter.js +0 -13
- package/.out/mantine/create_sub_form.d.ts +0 -6
- package/field_converters/list_converter.ts +0 -20
package/.turbo/turbo-build.log
CHANGED
|
@@ -7,12 +7,12 @@ $ tsup
|
|
|
7
7
|
[34mCLI[39m Target: esnext
|
|
8
8
|
[34mCJS[39m Build start
|
|
9
9
|
[34mESM[39m Build start
|
|
10
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
11
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
10
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m49.29 KB[39m
|
|
11
|
+
[32mCJS[39m ⚡️ Build success in 106ms
|
|
12
|
+
[32mESM[39m [1mdist/index.js [22m[32m45.41 KB[39m
|
|
13
13
|
[32mESM[39m ⚡️ Build success in 106ms
|
|
14
14
|
[34mDTS[39m Build start
|
|
15
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
-
[32mDTS[39m [1mdist/index.d.cts [22m[
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
18
|
-
Done in
|
|
15
|
+
[32mDTS[39m ⚡️ Build success in 10312ms
|
|
16
|
+
[32mDTS[39m [1mdist/index.d.cts [22m[32m35.93 KB[39m
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m35.93 KB[39m
|
|
18
|
+
Done in 11.43s.
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
annotatedIdentityConverter,
|
|
7
7
|
unreliableIdentityConverter,
|
|
8
8
|
} from 'field_converters/identity_converter'
|
|
9
|
-
import { listConverter } from 'field_converters/list_converter'
|
|
10
9
|
import { MaybeIdentityConverter } from 'field_converters/maybe_identity_converter'
|
|
11
10
|
import { prototypingFieldValueFactory } from 'field_value_factories/prototyping_field_value_factory'
|
|
12
11
|
import {
|
|
@@ -266,12 +265,12 @@ export function identityAdapter<
|
|
|
266
265
|
|
|
267
266
|
export function listAdapter<
|
|
268
267
|
E,
|
|
269
|
-
K extends string,
|
|
270
268
|
ValuePath extends string,
|
|
271
269
|
Context,
|
|
272
270
|
>() {
|
|
273
|
-
return new FieldAdapterBuilder<readonly E[], readonly
|
|
274
|
-
|
|
271
|
+
return new FieldAdapterBuilder<readonly E[], readonly E[], never, ValuePath, Context>(
|
|
272
|
+
annotatedIdentityConverter<readonly E[], ValuePath, Context>(false),
|
|
275
273
|
prototypingFieldValueFactory<readonly E[], ValuePath, Context>([]),
|
|
274
|
+
unreliableIdentityConverter<readonly E[], ValuePath, Context>(),
|
|
276
275
|
)
|
|
277
276
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ReadonlyTypeOfType,
|
|
3
|
+
type ValueOfType,
|
|
4
|
+
} from '@strictly/define'
|
|
5
|
+
import { type FieldsViewProps } from 'core/props'
|
|
6
|
+
import {
|
|
7
|
+
useCallback,
|
|
8
|
+
useMemo,
|
|
9
|
+
} from 'react'
|
|
10
|
+
import { type FormPresenter } from './form_presenter'
|
|
11
|
+
import {
|
|
12
|
+
type ToValueOfPresenterValuePath,
|
|
13
|
+
type ValuePathsOfPresenter,
|
|
14
|
+
} from './types'
|
|
15
|
+
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
type ValueOfPresenter<P extends FormPresenter<any, any, any, any>> = P extends FormPresenter<infer T, any, any, any>
|
|
18
|
+
? ValueOfType<ReadonlyTypeOfType<T>>
|
|
19
|
+
: never
|
|
20
|
+
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
type ModelOfPresenter<P extends FormPresenter<any, any, any, any>> = ReturnType<P['createModel']>
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
export function useDefaultMobxFormHooks<P extends FormPresenter<any, any, any, any>>(
|
|
26
|
+
presenter: P,
|
|
27
|
+
value: ValueOfPresenter<P>,
|
|
28
|
+
onValidSubmit?: <Path extends ValuePathsOfPresenter<P>>(
|
|
29
|
+
model: ModelOfPresenter<P>,
|
|
30
|
+
valuePath: Path,
|
|
31
|
+
) => void,
|
|
32
|
+
): {
|
|
33
|
+
model: ModelOfPresenter<P>,
|
|
34
|
+
} & Omit<FieldsViewProps<ModelOfPresenter<P>['fields']>, 'fields'> {
|
|
35
|
+
const model = useMemo(function () {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
37
|
+
return presenter.createModel(value) as ReturnType<P['createModel']>
|
|
38
|
+
}, [
|
|
39
|
+
presenter,
|
|
40
|
+
value,
|
|
41
|
+
])
|
|
42
|
+
|
|
43
|
+
const onFieldValueChange = useCallback(
|
|
44
|
+
function<Path extends ValuePathsOfPresenter<P>> (
|
|
45
|
+
path: Path,
|
|
46
|
+
value: ToValueOfPresenterValuePath<P, Path>,
|
|
47
|
+
) {
|
|
48
|
+
presenter.clearFieldError(model, path)
|
|
49
|
+
presenter.setFieldValue<Path>(model, path, value)
|
|
50
|
+
},
|
|
51
|
+
[
|
|
52
|
+
presenter,
|
|
53
|
+
model,
|
|
54
|
+
],
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
const onFieldSubmit = useCallback(
|
|
58
|
+
function<Path extends ValuePathsOfPresenter<P>> (valuePath: Path) {
|
|
59
|
+
if (presenter.validateField(model, valuePath)) {
|
|
60
|
+
onValidSubmit?.(model, valuePath)
|
|
61
|
+
}
|
|
62
|
+
return false
|
|
63
|
+
},
|
|
64
|
+
[
|
|
65
|
+
presenter,
|
|
66
|
+
model,
|
|
67
|
+
onValidSubmit,
|
|
68
|
+
],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const onFieldBlur = useCallback(
|
|
72
|
+
function<Path extends ValuePathsOfPresenter<P>> (path: Path) {
|
|
73
|
+
// work around potential loss of focus prior to state potentially invalidating change triggering
|
|
74
|
+
// (e.g. changing a discriminator)
|
|
75
|
+
// TODO debounce?
|
|
76
|
+
setTimeout(function () {
|
|
77
|
+
if (presenter.isValuePathActive(model, path)) {
|
|
78
|
+
presenter.validateField(model, path)
|
|
79
|
+
}
|
|
80
|
+
}, 100)
|
|
81
|
+
},
|
|
82
|
+
[
|
|
83
|
+
presenter,
|
|
84
|
+
model,
|
|
85
|
+
],
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
model,
|
|
90
|
+
onFieldValueChange,
|
|
91
|
+
onFieldSubmit,
|
|
92
|
+
onFieldBlur,
|
|
93
|
+
}
|
|
94
|
+
}
|
package/core/props.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type Fields } from 'types/field'
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type FieldsViewProps<F extends Fields> = {
|
|
4
4
|
fields: F,
|
|
5
5
|
|
|
6
6
|
onFieldValueChange<K extends keyof F>(this: void, key: K, value: F[K]['value']): void,
|
|
@@ -14,7 +14,7 @@ export type FormProps<F extends Fields> = {
|
|
|
14
14
|
onFieldSubmit?(this: void, key: keyof F): boolean | void,
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export type
|
|
17
|
+
export type FormProps<O> = {
|
|
18
18
|
value: O,
|
|
19
19
|
|
|
20
20
|
onValueChange: (value: O) => void,
|
package/dist/index.cjs
CHANGED
|
@@ -45,7 +45,8 @@ __export(index_exports, {
|
|
|
45
45
|
mergeValidators: () => mergeValidators,
|
|
46
46
|
prototypingFieldValueFactory: () => prototypingFieldValueFactory,
|
|
47
47
|
subFormFieldAdapters: () => subFormFieldAdapters,
|
|
48
|
-
|
|
48
|
+
useDefaultMobxFormHooks: () => useDefaultMobxFormHooks,
|
|
49
|
+
useMantineFormFields: () => useMantineFormFields,
|
|
49
50
|
usePartialComponent: () => usePartialComponent,
|
|
50
51
|
usePartialObserverComponent: () => usePartialObserverComponent,
|
|
51
52
|
validatingConverter: () => validatingConverter
|
|
@@ -139,20 +140,6 @@ function unreliableIdentityConverter() {
|
|
|
139
140
|
};
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
// field_converters/list_converter.ts
|
|
143
|
-
function listConverter() {
|
|
144
|
-
return function(from, valuePath) {
|
|
145
|
-
const value = from.map(function(_v, i) {
|
|
146
|
-
return `${valuePath}.${i}`;
|
|
147
|
-
});
|
|
148
|
-
return {
|
|
149
|
-
value,
|
|
150
|
-
required: false,
|
|
151
|
-
readonly: false
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
143
|
// field_converters/maybe_identity_converter.ts
|
|
157
144
|
var MaybeIdentityConverter = class {
|
|
158
145
|
constructor(converter, isFrom) {
|
|
@@ -241,8 +228,9 @@ function identityAdapter(prototype, required) {
|
|
|
241
228
|
}
|
|
242
229
|
function listAdapter() {
|
|
243
230
|
return new FieldAdapterBuilder(
|
|
244
|
-
|
|
245
|
-
prototypingFieldValueFactory([])
|
|
231
|
+
annotatedIdentityConverter(false),
|
|
232
|
+
prototypingFieldValueFactory([]),
|
|
233
|
+
unreliableIdentityConverter()
|
|
246
234
|
);
|
|
247
235
|
}
|
|
248
236
|
|
|
@@ -700,6 +688,59 @@ var FormModel = class {
|
|
|
700
688
|
}
|
|
701
689
|
};
|
|
702
690
|
|
|
691
|
+
// core/mobx/hooks.ts
|
|
692
|
+
var import_react = require("react");
|
|
693
|
+
function useDefaultMobxFormHooks(presenter, value, onValidSubmit) {
|
|
694
|
+
const model = (0, import_react.useMemo)(function() {
|
|
695
|
+
return presenter.createModel(value);
|
|
696
|
+
}, [
|
|
697
|
+
presenter,
|
|
698
|
+
value
|
|
699
|
+
]);
|
|
700
|
+
const onFieldValueChange = (0, import_react.useCallback)(
|
|
701
|
+
function(path, value2) {
|
|
702
|
+
presenter.clearFieldError(model, path);
|
|
703
|
+
presenter.setFieldValue(model, path, value2);
|
|
704
|
+
},
|
|
705
|
+
[
|
|
706
|
+
presenter,
|
|
707
|
+
model
|
|
708
|
+
]
|
|
709
|
+
);
|
|
710
|
+
const onFieldSubmit = (0, import_react.useCallback)(
|
|
711
|
+
function(valuePath) {
|
|
712
|
+
if (presenter.validateField(model, valuePath)) {
|
|
713
|
+
onValidSubmit?.(model, valuePath);
|
|
714
|
+
}
|
|
715
|
+
return false;
|
|
716
|
+
},
|
|
717
|
+
[
|
|
718
|
+
presenter,
|
|
719
|
+
model,
|
|
720
|
+
onValidSubmit
|
|
721
|
+
]
|
|
722
|
+
);
|
|
723
|
+
const onFieldBlur = (0, import_react.useCallback)(
|
|
724
|
+
function(path) {
|
|
725
|
+
setTimeout(function() {
|
|
726
|
+
if (presenter.isValuePathActive(model, path)) {
|
|
727
|
+
presenter.validateField(model, path);
|
|
728
|
+
}
|
|
729
|
+
}, 100);
|
|
730
|
+
},
|
|
731
|
+
[
|
|
732
|
+
presenter,
|
|
733
|
+
model
|
|
734
|
+
]
|
|
735
|
+
);
|
|
736
|
+
return {
|
|
737
|
+
model,
|
|
738
|
+
onFieldValueChange,
|
|
739
|
+
onFieldSubmit,
|
|
740
|
+
onFieldBlur
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
|
|
703
744
|
// core/mobx/merge_field_adapters_with_two_way_converter.ts
|
|
704
745
|
var import_base3 = require("@strictly/base");
|
|
705
746
|
function mergeFieldAdaptersWithTwoWayConverter(fieldAdapters, converter) {
|
|
@@ -1003,14 +1044,14 @@ function DefaultErrorRenderer({
|
|
|
1003
1044
|
var import_core = require("@mantine/core");
|
|
1004
1045
|
var import_base6 = require("@strictly/base");
|
|
1005
1046
|
var import_mobx2 = require("mobx");
|
|
1006
|
-
var
|
|
1047
|
+
var import_react4 = require("react");
|
|
1007
1048
|
|
|
1008
1049
|
// util/partial.tsx
|
|
1009
1050
|
var import_mobx_react = require("mobx-react");
|
|
1010
|
-
var
|
|
1051
|
+
var import_react2 = require("react");
|
|
1011
1052
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1012
1053
|
function createSimplePartialComponent(Component, curriedProps) {
|
|
1013
|
-
return (0,
|
|
1054
|
+
return (0, import_react2.forwardRef)(
|
|
1014
1055
|
function(exposedProps, ref) {
|
|
1015
1056
|
const C = Component;
|
|
1016
1057
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -1025,7 +1066,7 @@ function createSimplePartialComponent(Component, curriedProps) {
|
|
|
1025
1066
|
);
|
|
1026
1067
|
}
|
|
1027
1068
|
function createPartialComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1028
|
-
return (0,
|
|
1069
|
+
return (0, import_react2.forwardRef)(
|
|
1029
1070
|
function(props, ref) {
|
|
1030
1071
|
const C = Component;
|
|
1031
1072
|
const [
|
|
@@ -1067,7 +1108,7 @@ function createPartialComponent(Component, curriedPropsSource, additionalPropKey
|
|
|
1067
1108
|
);
|
|
1068
1109
|
}
|
|
1069
1110
|
function usePartialComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1070
|
-
return (0,
|
|
1111
|
+
return (0, import_react2.useMemo)(
|
|
1071
1112
|
function() {
|
|
1072
1113
|
return createPartialComponent(
|
|
1073
1114
|
Component,
|
|
@@ -1094,7 +1135,7 @@ function createPartialObserverComponent(Component, curriedPropsSource, additiona
|
|
|
1094
1135
|
}
|
|
1095
1136
|
function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1096
1137
|
return (0, import_mobx_react.observer)(
|
|
1097
|
-
(0,
|
|
1138
|
+
(0, import_react2.forwardRef)(
|
|
1098
1139
|
function(props, ref) {
|
|
1099
1140
|
const C = Component;
|
|
1100
1141
|
const [
|
|
@@ -1137,7 +1178,7 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
|
|
|
1137
1178
|
);
|
|
1138
1179
|
}
|
|
1139
1180
|
function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1140
|
-
return (0,
|
|
1181
|
+
return (0, import_react2.useMemo)(
|
|
1141
1182
|
function() {
|
|
1142
1183
|
return createPartialObserverComponent(
|
|
1143
1184
|
Component,
|
|
@@ -1204,23 +1245,97 @@ function createCheckbox(valuePath, Checkbox) {
|
|
|
1204
1245
|
);
|
|
1205
1246
|
}
|
|
1206
1247
|
|
|
1207
|
-
// mantine/
|
|
1248
|
+
// mantine/create_fields_view.tsx
|
|
1249
|
+
var import_mobx_react2 = require("mobx-react");
|
|
1208
1250
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1251
|
+
function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
1252
|
+
function toKey(subKey) {
|
|
1253
|
+
return subKey.replace("$", valuePath);
|
|
1254
|
+
}
|
|
1255
|
+
function toSubKey(key) {
|
|
1256
|
+
return key.replace(valuePath, "$");
|
|
1257
|
+
}
|
|
1258
|
+
function onFieldValueChange(subKey, value) {
|
|
1259
|
+
observableProps.onFieldValueChange(toKey(subKey), value);
|
|
1260
|
+
}
|
|
1261
|
+
function onFieldBlur(subKey) {
|
|
1262
|
+
observableProps.onFieldBlur?.(toKey(subKey));
|
|
1263
|
+
}
|
|
1264
|
+
function onFieldFocus(subKey) {
|
|
1265
|
+
observableProps.onFieldFocus?.(toKey(subKey));
|
|
1266
|
+
}
|
|
1267
|
+
function onFieldSubmit(subKey) {
|
|
1268
|
+
observableProps.onFieldSubmit?.(toKey(subKey));
|
|
1269
|
+
}
|
|
1270
|
+
return (0, import_mobx_react2.observer)(function(props) {
|
|
1271
|
+
const subFields = Object.entries(observableProps.fields).reduce((acc, [
|
|
1272
|
+
fieldKey,
|
|
1273
|
+
fieldValue
|
|
1274
|
+
]) => {
|
|
1275
|
+
if (fieldKey.startsWith(valuePath)) {
|
|
1276
|
+
acc[toSubKey(fieldKey)] = fieldValue;
|
|
1277
|
+
}
|
|
1278
|
+
return acc;
|
|
1279
|
+
}, {});
|
|
1280
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1281
|
+
FieldsView,
|
|
1282
|
+
{
|
|
1283
|
+
// maybe we can do this in a more type safe way
|
|
1284
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
1285
|
+
...props,
|
|
1286
|
+
fields: subFields,
|
|
1287
|
+
onFieldBlur,
|
|
1288
|
+
onFieldFocus,
|
|
1289
|
+
onFieldSubmit,
|
|
1290
|
+
onFieldValueChange
|
|
1291
|
+
}
|
|
1292
|
+
);
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// mantine/create_form.tsx
|
|
1297
|
+
var import_mobx_react3 = require("mobx-react");
|
|
1298
|
+
var import_react3 = require("react");
|
|
1299
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1300
|
+
function createForm(valuePath, Form, observableProps) {
|
|
1301
|
+
return (0, import_mobx_react3.observer)((props) => {
|
|
1302
|
+
const { value } = observableProps.fields[valuePath];
|
|
1303
|
+
const onValueChange = (0, import_react3.useCallback)((value2) => {
|
|
1304
|
+
observableProps.onFieldValueChange(valuePath, value2);
|
|
1305
|
+
}, []);
|
|
1306
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1307
|
+
Form,
|
|
1308
|
+
{
|
|
1309
|
+
// maybe we can do this in a more type safe way
|
|
1310
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
1311
|
+
...props,
|
|
1312
|
+
onValueChange,
|
|
1313
|
+
value
|
|
1314
|
+
}
|
|
1315
|
+
);
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
// mantine/create_list.tsx
|
|
1320
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1209
1321
|
function createList(valuePath, List) {
|
|
1210
1322
|
const propSource = () => {
|
|
1211
1323
|
const values = [...this.fields[valuePath].value];
|
|
1212
1324
|
return {
|
|
1213
|
-
values
|
|
1325
|
+
values,
|
|
1326
|
+
listPath: valuePath
|
|
1214
1327
|
};
|
|
1215
1328
|
};
|
|
1216
1329
|
return createUnsafePartialObserverComponent(List, propSource);
|
|
1217
1330
|
}
|
|
1218
1331
|
function DefaultList({
|
|
1219
1332
|
values,
|
|
1333
|
+
listPath,
|
|
1220
1334
|
children
|
|
1221
1335
|
}) {
|
|
1222
|
-
return /* @__PURE__ */ (0,
|
|
1223
|
-
|
|
1336
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: values.map(function(value, index) {
|
|
1337
|
+
const valuePath = `${listPath}.${index}`;
|
|
1338
|
+
return children(valuePath, value, index);
|
|
1224
1339
|
}) });
|
|
1225
1340
|
}
|
|
1226
1341
|
|
|
@@ -1257,7 +1372,7 @@ function createRadio(valuePath, value, Radio) {
|
|
|
1257
1372
|
}
|
|
1258
1373
|
|
|
1259
1374
|
// mantine/create_radio_group.tsx
|
|
1260
|
-
var
|
|
1375
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1261
1376
|
function createRadioGroup(valuePath, RadioGroup) {
|
|
1262
1377
|
const onChange = (value) => {
|
|
1263
1378
|
this.onFieldValueChange?.(valuePath, value);
|
|
@@ -1285,7 +1400,7 @@ function createRadioGroup(valuePath, RadioGroup) {
|
|
|
1285
1400
|
name: valuePath,
|
|
1286
1401
|
value,
|
|
1287
1402
|
required,
|
|
1288
|
-
error: error && /* @__PURE__ */ (0,
|
|
1403
|
+
error: error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorRenderer, { error }),
|
|
1289
1404
|
onChange,
|
|
1290
1405
|
onFocus,
|
|
1291
1406
|
onBlur,
|
|
@@ -1295,53 +1410,8 @@ function createRadioGroup(valuePath, RadioGroup) {
|
|
|
1295
1410
|
return createUnsafePartialObserverComponent(RadioGroup, propSource, ["ErrorRenderer"]);
|
|
1296
1411
|
}
|
|
1297
1412
|
|
|
1298
|
-
// mantine/create_sub_form.tsx
|
|
1299
|
-
var import_mobx_react2 = require("mobx-react");
|
|
1300
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1301
|
-
function createSubForm(valuePath, SubForm, observableProps) {
|
|
1302
|
-
function toKey(subKey) {
|
|
1303
|
-
return subKey.replace("$", valuePath);
|
|
1304
|
-
}
|
|
1305
|
-
function toSubKey(key) {
|
|
1306
|
-
return key.replace(valuePath, "$");
|
|
1307
|
-
}
|
|
1308
|
-
function onFieldValueChange(subKey, value) {
|
|
1309
|
-
observableProps.onFieldValueChange(toKey(subKey), value);
|
|
1310
|
-
}
|
|
1311
|
-
function onFieldBlur(subKey) {
|
|
1312
|
-
observableProps.onFieldBlur?.(toKey(subKey));
|
|
1313
|
-
}
|
|
1314
|
-
function onFieldFocus(subKey) {
|
|
1315
|
-
observableProps.onFieldFocus?.(toKey(subKey));
|
|
1316
|
-
}
|
|
1317
|
-
function onFieldSubmit(subKey) {
|
|
1318
|
-
observableProps.onFieldSubmit?.(toKey(subKey));
|
|
1319
|
-
}
|
|
1320
|
-
return (0, import_mobx_react2.observer)(function() {
|
|
1321
|
-
const subFields = Object.entries(observableProps.fields).reduce((acc, [
|
|
1322
|
-
fieldKey,
|
|
1323
|
-
fieldValue
|
|
1324
|
-
]) => {
|
|
1325
|
-
if (fieldKey.startsWith(valuePath)) {
|
|
1326
|
-
acc[toSubKey(fieldKey)] = fieldValue;
|
|
1327
|
-
}
|
|
1328
|
-
return acc;
|
|
1329
|
-
}, {});
|
|
1330
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1331
|
-
SubForm,
|
|
1332
|
-
{
|
|
1333
|
-
fields: subFields,
|
|
1334
|
-
onFieldBlur,
|
|
1335
|
-
onFieldFocus,
|
|
1336
|
-
onFieldSubmit,
|
|
1337
|
-
onFieldValueChange
|
|
1338
|
-
}
|
|
1339
|
-
);
|
|
1340
|
-
});
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
1413
|
// mantine/create_text_input.tsx
|
|
1344
|
-
var
|
|
1414
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1345
1415
|
function createTextInput(valuePath, TextInput) {
|
|
1346
1416
|
const onChange = (e) => {
|
|
1347
1417
|
this.onFieldValueChange?.(valuePath, e.target.value);
|
|
@@ -1375,7 +1445,7 @@ function createTextInput(valuePath, TextInput) {
|
|
|
1375
1445
|
value,
|
|
1376
1446
|
disabled: readonly,
|
|
1377
1447
|
required,
|
|
1378
|
-
error: error && /* @__PURE__ */ (0,
|
|
1448
|
+
error: error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ErrorRenderer, { error }),
|
|
1379
1449
|
onChange,
|
|
1380
1450
|
onFocus,
|
|
1381
1451
|
onBlur,
|
|
@@ -1390,7 +1460,7 @@ function createTextInput(valuePath, TextInput) {
|
|
|
1390
1460
|
}
|
|
1391
1461
|
|
|
1392
1462
|
// mantine/create_value_input.tsx
|
|
1393
|
-
var
|
|
1463
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1394
1464
|
function createValueInput(valuePath, ValueInput) {
|
|
1395
1465
|
const onChange = (value) => {
|
|
1396
1466
|
this.onFieldValueChange?.(valuePath, value);
|
|
@@ -1424,7 +1494,7 @@ function createValueInput(valuePath, ValueInput) {
|
|
|
1424
1494
|
value,
|
|
1425
1495
|
disabled: readonly,
|
|
1426
1496
|
required,
|
|
1427
|
-
error: error && /* @__PURE__ */ (0,
|
|
1497
|
+
error: error && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ErrorRenderer, { error }),
|
|
1428
1498
|
onChange,
|
|
1429
1499
|
onFocus,
|
|
1430
1500
|
onBlur,
|
|
@@ -1439,18 +1509,18 @@ function createValueInput(valuePath, ValueInput) {
|
|
|
1439
1509
|
}
|
|
1440
1510
|
|
|
1441
1511
|
// mantine/hooks.tsx
|
|
1442
|
-
var
|
|
1512
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1443
1513
|
function SimpleSelect(props) {
|
|
1444
|
-
return /* @__PURE__ */ (0,
|
|
1514
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_core.Select, { ...props });
|
|
1445
1515
|
}
|
|
1446
|
-
function
|
|
1516
|
+
function useMantineFormFields({
|
|
1447
1517
|
onFieldValueChange,
|
|
1448
1518
|
onFieldBlur,
|
|
1449
1519
|
onFieldFocus,
|
|
1450
1520
|
onFieldSubmit,
|
|
1451
1521
|
fields
|
|
1452
1522
|
}) {
|
|
1453
|
-
const form = (0,
|
|
1523
|
+
const form = (0, import_react4.useMemo)(
|
|
1454
1524
|
function() {
|
|
1455
1525
|
return new MantineFormImpl(fields);
|
|
1456
1526
|
},
|
|
@@ -1458,7 +1528,7 @@ function useMantineForm({
|
|
|
1458
1528
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1459
1529
|
[]
|
|
1460
1530
|
);
|
|
1461
|
-
(0,
|
|
1531
|
+
(0, import_react4.useEffect)(function() {
|
|
1462
1532
|
(0, import_mobx2.runInAction)(function() {
|
|
1463
1533
|
form.fields = fields;
|
|
1464
1534
|
});
|
|
@@ -1466,25 +1536,25 @@ function useMantineForm({
|
|
|
1466
1536
|
form,
|
|
1467
1537
|
fields
|
|
1468
1538
|
]);
|
|
1469
|
-
(0,
|
|
1539
|
+
(0, import_react4.useEffect)(function() {
|
|
1470
1540
|
form.onFieldValueChange = onFieldValueChange;
|
|
1471
1541
|
}, [
|
|
1472
1542
|
form,
|
|
1473
1543
|
onFieldValueChange
|
|
1474
1544
|
]);
|
|
1475
|
-
(0,
|
|
1545
|
+
(0, import_react4.useEffect)(function() {
|
|
1476
1546
|
form.onFieldBlur = onFieldBlur;
|
|
1477
1547
|
}, [
|
|
1478
1548
|
form,
|
|
1479
1549
|
onFieldBlur
|
|
1480
1550
|
]);
|
|
1481
|
-
(0,
|
|
1551
|
+
(0, import_react4.useEffect)(function() {
|
|
1482
1552
|
form.onFieldFocus = onFieldFocus;
|
|
1483
1553
|
}, [
|
|
1484
1554
|
form,
|
|
1485
1555
|
onFieldFocus
|
|
1486
1556
|
]);
|
|
1487
|
-
(0,
|
|
1557
|
+
(0, import_react4.useEffect)(function() {
|
|
1488
1558
|
form.onFieldSubmit = onFieldSubmit;
|
|
1489
1559
|
}, [
|
|
1490
1560
|
form,
|
|
@@ -1514,9 +1584,10 @@ var MantineFormImpl = class {
|
|
|
1514
1584
|
listCache = new import_base6.Cache(
|
|
1515
1585
|
createList.bind(this)
|
|
1516
1586
|
);
|
|
1517
|
-
|
|
1518
|
-
|
|
1587
|
+
fieldsViewCache = new import_base6.Cache(
|
|
1588
|
+
createFieldsView.bind(this)
|
|
1519
1589
|
);
|
|
1590
|
+
formCache = new import_base6.Cache(createForm.bind(this));
|
|
1520
1591
|
@import_mobx2.observable.ref
|
|
1521
1592
|
accessor fields;
|
|
1522
1593
|
onFieldValueChange;
|
|
@@ -1582,13 +1653,21 @@ var MantineFormImpl = class {
|
|
|
1582
1653
|
DefaultList
|
|
1583
1654
|
);
|
|
1584
1655
|
}
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1656
|
+
fieldsView(valuePath, FieldsView) {
|
|
1657
|
+
return this.fieldsViewCache.retrieveOrCreate(
|
|
1658
|
+
valuePath,
|
|
1659
|
+
// strip props from component since we lose information in the cache
|
|
1660
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1661
|
+
FieldsView,
|
|
1662
|
+
this
|
|
1663
|
+
);
|
|
1664
|
+
}
|
|
1665
|
+
form(valuePath, Form) {
|
|
1666
|
+
return this.formCache.retrieveOrCreate(
|
|
1588
1667
|
valuePath,
|
|
1589
1668
|
// strip props from component since we lose information in the cache
|
|
1590
1669
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1591
|
-
|
|
1670
|
+
Form,
|
|
1592
1671
|
this
|
|
1593
1672
|
);
|
|
1594
1673
|
}
|
|
@@ -1659,7 +1738,8 @@ function mergeValidators(validators1, validators2) {
|
|
|
1659
1738
|
mergeValidators,
|
|
1660
1739
|
prototypingFieldValueFactory,
|
|
1661
1740
|
subFormFieldAdapters,
|
|
1662
|
-
|
|
1741
|
+
useDefaultMobxFormHooks,
|
|
1742
|
+
useMantineFormFields,
|
|
1663
1743
|
usePartialComponent,
|
|
1664
1744
|
usePartialObserverComponent,
|
|
1665
1745
|
validatingConverter
|