@strictly/react-form 0.0.5 → 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/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/hooks.d.ts +6 -4
- 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 +2 -2
- 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 +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/.turbo/turbo-release$colon$exports.log +1 -1
- package/core/mobx/hooks.ts +94 -0
- package/core/props.ts +2 -2
- package/dist/index.cjs +167 -77
- package/dist/index.d.cts +42 -34
- package/dist/index.d.ts +42 -34
- package/dist/index.js +162 -68
- 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/hooks.tsx +48 -14
- 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/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 +4 -4
- 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/mantine/create_sub_form.d.ts +0 -6
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
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
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
|
+
[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 11.
|
|
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.
|
|
@@ -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
|
|
@@ -687,6 +688,59 @@ var FormModel = class {
|
|
|
687
688
|
}
|
|
688
689
|
};
|
|
689
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
|
+
|
|
690
744
|
// core/mobx/merge_field_adapters_with_two_way_converter.ts
|
|
691
745
|
var import_base3 = require("@strictly/base");
|
|
692
746
|
function mergeFieldAdaptersWithTwoWayConverter(fieldAdapters, converter) {
|
|
@@ -990,14 +1044,14 @@ function DefaultErrorRenderer({
|
|
|
990
1044
|
var import_core = require("@mantine/core");
|
|
991
1045
|
var import_base6 = require("@strictly/base");
|
|
992
1046
|
var import_mobx2 = require("mobx");
|
|
993
|
-
var
|
|
1047
|
+
var import_react4 = require("react");
|
|
994
1048
|
|
|
995
1049
|
// util/partial.tsx
|
|
996
1050
|
var import_mobx_react = require("mobx-react");
|
|
997
|
-
var
|
|
1051
|
+
var import_react2 = require("react");
|
|
998
1052
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
999
1053
|
function createSimplePartialComponent(Component, curriedProps) {
|
|
1000
|
-
return (0,
|
|
1054
|
+
return (0, import_react2.forwardRef)(
|
|
1001
1055
|
function(exposedProps, ref) {
|
|
1002
1056
|
const C = Component;
|
|
1003
1057
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -1012,7 +1066,7 @@ function createSimplePartialComponent(Component, curriedProps) {
|
|
|
1012
1066
|
);
|
|
1013
1067
|
}
|
|
1014
1068
|
function createPartialComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1015
|
-
return (0,
|
|
1069
|
+
return (0, import_react2.forwardRef)(
|
|
1016
1070
|
function(props, ref) {
|
|
1017
1071
|
const C = Component;
|
|
1018
1072
|
const [
|
|
@@ -1054,7 +1108,7 @@ function createPartialComponent(Component, curriedPropsSource, additionalPropKey
|
|
|
1054
1108
|
);
|
|
1055
1109
|
}
|
|
1056
1110
|
function usePartialComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1057
|
-
return (0,
|
|
1111
|
+
return (0, import_react2.useMemo)(
|
|
1058
1112
|
function() {
|
|
1059
1113
|
return createPartialComponent(
|
|
1060
1114
|
Component,
|
|
@@ -1081,7 +1135,7 @@ function createPartialObserverComponent(Component, curriedPropsSource, additiona
|
|
|
1081
1135
|
}
|
|
1082
1136
|
function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1083
1137
|
return (0, import_mobx_react.observer)(
|
|
1084
|
-
(0,
|
|
1138
|
+
(0, import_react2.forwardRef)(
|
|
1085
1139
|
function(props, ref) {
|
|
1086
1140
|
const C = Component;
|
|
1087
1141
|
const [
|
|
@@ -1124,7 +1178,7 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
|
|
|
1124
1178
|
);
|
|
1125
1179
|
}
|
|
1126
1180
|
function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1127
|
-
return (0,
|
|
1181
|
+
return (0, import_react2.useMemo)(
|
|
1128
1182
|
function() {
|
|
1129
1183
|
return createPartialObserverComponent(
|
|
1130
1184
|
Component,
|
|
@@ -1191,8 +1245,79 @@ function createCheckbox(valuePath, Checkbox) {
|
|
|
1191
1245
|
);
|
|
1192
1246
|
}
|
|
1193
1247
|
|
|
1194
|
-
// mantine/
|
|
1248
|
+
// mantine/create_fields_view.tsx
|
|
1249
|
+
var import_mobx_react2 = require("mobx-react");
|
|
1195
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");
|
|
1196
1321
|
function createList(valuePath, List) {
|
|
1197
1322
|
const propSource = () => {
|
|
1198
1323
|
const values = [...this.fields[valuePath].value];
|
|
@@ -1208,7 +1333,7 @@ function DefaultList({
|
|
|
1208
1333
|
listPath,
|
|
1209
1334
|
children
|
|
1210
1335
|
}) {
|
|
1211
|
-
return /* @__PURE__ */ (0,
|
|
1336
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: values.map(function(value, index) {
|
|
1212
1337
|
const valuePath = `${listPath}.${index}`;
|
|
1213
1338
|
return children(valuePath, value, index);
|
|
1214
1339
|
}) });
|
|
@@ -1247,7 +1372,7 @@ function createRadio(valuePath, value, Radio) {
|
|
|
1247
1372
|
}
|
|
1248
1373
|
|
|
1249
1374
|
// mantine/create_radio_group.tsx
|
|
1250
|
-
var
|
|
1375
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1251
1376
|
function createRadioGroup(valuePath, RadioGroup) {
|
|
1252
1377
|
const onChange = (value) => {
|
|
1253
1378
|
this.onFieldValueChange?.(valuePath, value);
|
|
@@ -1275,7 +1400,7 @@ function createRadioGroup(valuePath, RadioGroup) {
|
|
|
1275
1400
|
name: valuePath,
|
|
1276
1401
|
value,
|
|
1277
1402
|
required,
|
|
1278
|
-
error: error && /* @__PURE__ */ (0,
|
|
1403
|
+
error: error && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorRenderer, { error }),
|
|
1279
1404
|
onChange,
|
|
1280
1405
|
onFocus,
|
|
1281
1406
|
onBlur,
|
|
@@ -1285,53 +1410,8 @@ function createRadioGroup(valuePath, RadioGroup) {
|
|
|
1285
1410
|
return createUnsafePartialObserverComponent(RadioGroup, propSource, ["ErrorRenderer"]);
|
|
1286
1411
|
}
|
|
1287
1412
|
|
|
1288
|
-
// mantine/create_sub_form.tsx
|
|
1289
|
-
var import_mobx_react2 = require("mobx-react");
|
|
1290
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1291
|
-
function createSubForm(valuePath, SubForm, observableProps) {
|
|
1292
|
-
function toKey(subKey) {
|
|
1293
|
-
return subKey.replace("$", valuePath);
|
|
1294
|
-
}
|
|
1295
|
-
function toSubKey(key) {
|
|
1296
|
-
return key.replace(valuePath, "$");
|
|
1297
|
-
}
|
|
1298
|
-
function onFieldValueChange(subKey, value) {
|
|
1299
|
-
observableProps.onFieldValueChange(toKey(subKey), value);
|
|
1300
|
-
}
|
|
1301
|
-
function onFieldBlur(subKey) {
|
|
1302
|
-
observableProps.onFieldBlur?.(toKey(subKey));
|
|
1303
|
-
}
|
|
1304
|
-
function onFieldFocus(subKey) {
|
|
1305
|
-
observableProps.onFieldFocus?.(toKey(subKey));
|
|
1306
|
-
}
|
|
1307
|
-
function onFieldSubmit(subKey) {
|
|
1308
|
-
observableProps.onFieldSubmit?.(toKey(subKey));
|
|
1309
|
-
}
|
|
1310
|
-
return (0, import_mobx_react2.observer)(function() {
|
|
1311
|
-
const subFields = Object.entries(observableProps.fields).reduce((acc, [
|
|
1312
|
-
fieldKey,
|
|
1313
|
-
fieldValue
|
|
1314
|
-
]) => {
|
|
1315
|
-
if (fieldKey.startsWith(valuePath)) {
|
|
1316
|
-
acc[toSubKey(fieldKey)] = fieldValue;
|
|
1317
|
-
}
|
|
1318
|
-
return acc;
|
|
1319
|
-
}, {});
|
|
1320
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1321
|
-
SubForm,
|
|
1322
|
-
{
|
|
1323
|
-
fields: subFields,
|
|
1324
|
-
onFieldBlur,
|
|
1325
|
-
onFieldFocus,
|
|
1326
|
-
onFieldSubmit,
|
|
1327
|
-
onFieldValueChange
|
|
1328
|
-
}
|
|
1329
|
-
);
|
|
1330
|
-
});
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
1413
|
// mantine/create_text_input.tsx
|
|
1334
|
-
var
|
|
1414
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1335
1415
|
function createTextInput(valuePath, TextInput) {
|
|
1336
1416
|
const onChange = (e) => {
|
|
1337
1417
|
this.onFieldValueChange?.(valuePath, e.target.value);
|
|
@@ -1365,7 +1445,7 @@ function createTextInput(valuePath, TextInput) {
|
|
|
1365
1445
|
value,
|
|
1366
1446
|
disabled: readonly,
|
|
1367
1447
|
required,
|
|
1368
|
-
error: error && /* @__PURE__ */ (0,
|
|
1448
|
+
error: error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ErrorRenderer, { error }),
|
|
1369
1449
|
onChange,
|
|
1370
1450
|
onFocus,
|
|
1371
1451
|
onBlur,
|
|
@@ -1380,7 +1460,7 @@ function createTextInput(valuePath, TextInput) {
|
|
|
1380
1460
|
}
|
|
1381
1461
|
|
|
1382
1462
|
// mantine/create_value_input.tsx
|
|
1383
|
-
var
|
|
1463
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1384
1464
|
function createValueInput(valuePath, ValueInput) {
|
|
1385
1465
|
const onChange = (value) => {
|
|
1386
1466
|
this.onFieldValueChange?.(valuePath, value);
|
|
@@ -1414,7 +1494,7 @@ function createValueInput(valuePath, ValueInput) {
|
|
|
1414
1494
|
value,
|
|
1415
1495
|
disabled: readonly,
|
|
1416
1496
|
required,
|
|
1417
|
-
error: error && /* @__PURE__ */ (0,
|
|
1497
|
+
error: error && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ErrorRenderer, { error }),
|
|
1418
1498
|
onChange,
|
|
1419
1499
|
onFocus,
|
|
1420
1500
|
onBlur,
|
|
@@ -1429,18 +1509,18 @@ function createValueInput(valuePath, ValueInput) {
|
|
|
1429
1509
|
}
|
|
1430
1510
|
|
|
1431
1511
|
// mantine/hooks.tsx
|
|
1432
|
-
var
|
|
1512
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1433
1513
|
function SimpleSelect(props) {
|
|
1434
|
-
return /* @__PURE__ */ (0,
|
|
1514
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_core.Select, { ...props });
|
|
1435
1515
|
}
|
|
1436
|
-
function
|
|
1516
|
+
function useMantineFormFields({
|
|
1437
1517
|
onFieldValueChange,
|
|
1438
1518
|
onFieldBlur,
|
|
1439
1519
|
onFieldFocus,
|
|
1440
1520
|
onFieldSubmit,
|
|
1441
1521
|
fields
|
|
1442
1522
|
}) {
|
|
1443
|
-
const form = (0,
|
|
1523
|
+
const form = (0, import_react4.useMemo)(
|
|
1444
1524
|
function() {
|
|
1445
1525
|
return new MantineFormImpl(fields);
|
|
1446
1526
|
},
|
|
@@ -1448,7 +1528,7 @@ function useMantineForm({
|
|
|
1448
1528
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1449
1529
|
[]
|
|
1450
1530
|
);
|
|
1451
|
-
(0,
|
|
1531
|
+
(0, import_react4.useEffect)(function() {
|
|
1452
1532
|
(0, import_mobx2.runInAction)(function() {
|
|
1453
1533
|
form.fields = fields;
|
|
1454
1534
|
});
|
|
@@ -1456,25 +1536,25 @@ function useMantineForm({
|
|
|
1456
1536
|
form,
|
|
1457
1537
|
fields
|
|
1458
1538
|
]);
|
|
1459
|
-
(0,
|
|
1539
|
+
(0, import_react4.useEffect)(function() {
|
|
1460
1540
|
form.onFieldValueChange = onFieldValueChange;
|
|
1461
1541
|
}, [
|
|
1462
1542
|
form,
|
|
1463
1543
|
onFieldValueChange
|
|
1464
1544
|
]);
|
|
1465
|
-
(0,
|
|
1545
|
+
(0, import_react4.useEffect)(function() {
|
|
1466
1546
|
form.onFieldBlur = onFieldBlur;
|
|
1467
1547
|
}, [
|
|
1468
1548
|
form,
|
|
1469
1549
|
onFieldBlur
|
|
1470
1550
|
]);
|
|
1471
|
-
(0,
|
|
1551
|
+
(0, import_react4.useEffect)(function() {
|
|
1472
1552
|
form.onFieldFocus = onFieldFocus;
|
|
1473
1553
|
}, [
|
|
1474
1554
|
form,
|
|
1475
1555
|
onFieldFocus
|
|
1476
1556
|
]);
|
|
1477
|
-
(0,
|
|
1557
|
+
(0, import_react4.useEffect)(function() {
|
|
1478
1558
|
form.onFieldSubmit = onFieldSubmit;
|
|
1479
1559
|
}, [
|
|
1480
1560
|
form,
|
|
@@ -1504,9 +1584,10 @@ var MantineFormImpl = class {
|
|
|
1504
1584
|
listCache = new import_base6.Cache(
|
|
1505
1585
|
createList.bind(this)
|
|
1506
1586
|
);
|
|
1507
|
-
|
|
1508
|
-
|
|
1587
|
+
fieldsViewCache = new import_base6.Cache(
|
|
1588
|
+
createFieldsView.bind(this)
|
|
1509
1589
|
);
|
|
1590
|
+
formCache = new import_base6.Cache(createForm.bind(this));
|
|
1510
1591
|
@import_mobx2.observable.ref
|
|
1511
1592
|
accessor fields;
|
|
1512
1593
|
onFieldValueChange;
|
|
@@ -1572,13 +1653,21 @@ var MantineFormImpl = class {
|
|
|
1572
1653
|
DefaultList
|
|
1573
1654
|
);
|
|
1574
1655
|
}
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
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(
|
|
1578
1667
|
valuePath,
|
|
1579
1668
|
// strip props from component since we lose information in the cache
|
|
1580
1669
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1581
|
-
|
|
1670
|
+
Form,
|
|
1582
1671
|
this
|
|
1583
1672
|
);
|
|
1584
1673
|
}
|
|
@@ -1649,7 +1738,8 @@ function mergeValidators(validators1, validators2) {
|
|
|
1649
1738
|
mergeValidators,
|
|
1650
1739
|
prototypingFieldValueFactory,
|
|
1651
1740
|
subFormFieldAdapters,
|
|
1652
|
-
|
|
1741
|
+
useDefaultMobxFormHooks,
|
|
1742
|
+
useMantineFormFields,
|
|
1653
1743
|
usePartialComponent,
|
|
1654
1744
|
usePartialObserverComponent,
|
|
1655
1745
|
validatingConverter
|