@strictly/react-form 0.0.8 → 0.0.10
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 +4 -0
- package/.out/core/mobx/field_adapter_builder.js +31 -0
- package/.out/core/mobx/form_presenter.d.ts +5 -5
- package/.out/core/mobx/form_presenter.js +8 -6
- package/.out/core/mobx/hooks.d.ts +24 -4
- package/.out/core/mobx/hooks.js +24 -3
- package/.out/core/mobx/specs/form_presenter.tests.js +10 -5
- package/.out/core/mobx/sub_form_field_adapters.d.ts +2 -2
- package/.out/field_converters/chain_field_converter.js +3 -3
- package/.out/mantine/create_fields_view.d.ts +9 -1
- package/.out/mantine/create_fields_view.js +13 -1
- package/.out/mantine/error_renderer.d.ts +7 -3
- package/.out/mantine/hooks.d.ts +2 -1
- package/.out/mantine/hooks.js +1 -1
- 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 +26 -7
- package/.out/mantine/specs/fields_view_hooks.tests.js +21 -1
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/specs/error_of_field.tests.d.ts +1 -0
- package/.out/types/specs/{error_type_of_field.tests.js → error_of_field.tests.js} +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/core/mobx/field_adapter_builder.ts +71 -0
- package/core/mobx/form_presenter.ts +15 -14
- package/core/mobx/hooks.tsx +196 -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 +290 -220
- package/dist/index.d.cts +63 -32
- package/dist/index.d.ts +63 -32
- package/dist/index.js +288 -219
- package/field_converters/chain_field_converter.ts +3 -3
- package/mantine/create_fields_view.tsx +66 -31
- package/mantine/error_renderer.ts +12 -3
- 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/types/specs/{error_type_of_field.tests.ts → error_of_field.tests.ts} +1 -1
- package/core/mobx/hooks.ts +0 -112
- /package/.out/{types/specs/error_type_of_field.tests.d.ts → mantine/specs/create_fields_view.tests.d.ts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -45,6 +45,7 @@ __export(index_exports, {
|
|
|
45
45
|
mergeValidators: () => mergeValidators,
|
|
46
46
|
prototypingFieldValueFactory: () => prototypingFieldValueFactory,
|
|
47
47
|
subFormFieldAdapters: () => subFormFieldAdapters,
|
|
48
|
+
trimmingStringAdapter: () => trimmingStringAdapter,
|
|
48
49
|
useDefaultMobxFormHooks: () => useDefaultMobxFormHooks,
|
|
49
50
|
useMantineFormFields: () => useMantineFormFields,
|
|
50
51
|
usePartialComponent: () => usePartialComponent,
|
|
@@ -105,18 +106,18 @@ function chainAnnotatedFieldConverter(from, to) {
|
|
|
105
106
|
return function(value, valuePath, context) {
|
|
106
107
|
const {
|
|
107
108
|
required: intermediateRequired,
|
|
108
|
-
readonly:
|
|
109
|
+
readonly: intermediateReadonly,
|
|
109
110
|
value: intermediateValue
|
|
110
111
|
} = from(value, valuePath, context);
|
|
111
112
|
const {
|
|
112
113
|
required: finalRequired,
|
|
113
|
-
readonly:
|
|
114
|
+
readonly: finalReadonly,
|
|
114
115
|
value: finalValue
|
|
115
116
|
} = to(intermediateValue, valuePath, context);
|
|
116
117
|
return {
|
|
117
118
|
value: finalValue,
|
|
118
119
|
required: intermediateRequired || finalRequired,
|
|
119
|
-
readonly:
|
|
120
|
+
readonly: intermediateReadonly || finalReadonly
|
|
120
121
|
};
|
|
121
122
|
};
|
|
122
123
|
}
|
|
@@ -155,6 +156,25 @@ var MaybeIdentityConverter = class {
|
|
|
155
156
|
}
|
|
156
157
|
};
|
|
157
158
|
|
|
159
|
+
// field_converters/trimming_string_converter.ts
|
|
160
|
+
var TrimmingStringConverter = class {
|
|
161
|
+
constructor() {
|
|
162
|
+
}
|
|
163
|
+
convert(to) {
|
|
164
|
+
return {
|
|
165
|
+
value: to.trim(),
|
|
166
|
+
required: false,
|
|
167
|
+
readonly: false
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
revert(from) {
|
|
171
|
+
return {
|
|
172
|
+
type: 0 /* Success */,
|
|
173
|
+
value: from.trim()
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
158
178
|
// field_value_factories/prototyping_field_value_factory.ts
|
|
159
179
|
function prototypingFieldValueFactory(prototype) {
|
|
160
180
|
return function() {
|
|
@@ -189,6 +209,32 @@ var FieldAdapterBuilder = class _FieldAdapterBuilder {
|
|
|
189
209
|
reverter
|
|
190
210
|
);
|
|
191
211
|
}
|
|
212
|
+
nullable() {
|
|
213
|
+
return this.or(null);
|
|
214
|
+
}
|
|
215
|
+
optional() {
|
|
216
|
+
return this.or(void 0);
|
|
217
|
+
}
|
|
218
|
+
or(proto) {
|
|
219
|
+
function isFrom(v) {
|
|
220
|
+
return v !== proto;
|
|
221
|
+
}
|
|
222
|
+
function isTo(v) {
|
|
223
|
+
return v !== proto;
|
|
224
|
+
}
|
|
225
|
+
return new _FieldAdapterBuilder(
|
|
226
|
+
(v, valuePath, context) => isFrom(v) ? this.convert(v, valuePath, context) : {
|
|
227
|
+
value: v,
|
|
228
|
+
readonly: false,
|
|
229
|
+
required: false
|
|
230
|
+
},
|
|
231
|
+
this.create,
|
|
232
|
+
(v, valuePath, context) => isTo(v) && this.revert ? this.revert(v, valuePath, context) : {
|
|
233
|
+
type: 0 /* Success */,
|
|
234
|
+
value: proto
|
|
235
|
+
}
|
|
236
|
+
);
|
|
237
|
+
}
|
|
192
238
|
withIdentity(isFrom) {
|
|
193
239
|
const identityConverter = new MaybeIdentityConverter({
|
|
194
240
|
convert: this.convert,
|
|
@@ -226,6 +272,12 @@ function identityAdapter(prototype, required) {
|
|
|
226
272
|
unreliableIdentityConverter()
|
|
227
273
|
);
|
|
228
274
|
}
|
|
275
|
+
function trimmingStringAdapter() {
|
|
276
|
+
return adapterFromTwoWayConverter(
|
|
277
|
+
new TrimmingStringConverter(),
|
|
278
|
+
prototypingFieldValueFactory("")
|
|
279
|
+
);
|
|
280
|
+
}
|
|
229
281
|
function listAdapter() {
|
|
230
282
|
return new FieldAdapterBuilder(
|
|
231
283
|
annotatedIdentityConverter(false),
|
|
@@ -433,8 +485,7 @@ var FormPresenter = class {
|
|
|
433
485
|
convert,
|
|
434
486
|
create
|
|
435
487
|
} = adapter2;
|
|
436
|
-
const
|
|
437
|
-
const value = accessor == null ? create(valuePath, model.value) : accessor.value;
|
|
488
|
+
const value = create(valuePath, model.value);
|
|
438
489
|
const {
|
|
439
490
|
value: displayValue
|
|
440
491
|
} = convert(value, valuePath, model.value);
|
|
@@ -455,7 +506,7 @@ var FormPresenter = class {
|
|
|
455
506
|
const keys = new Set(Object.keys(values));
|
|
456
507
|
return keys.has(valuePath);
|
|
457
508
|
}
|
|
458
|
-
validateField(model, valuePath) {
|
|
509
|
+
validateField(model, valuePath, ignoreDefaultValue = false) {
|
|
459
510
|
const {
|
|
460
511
|
convert,
|
|
461
512
|
revert,
|
|
@@ -474,6 +525,14 @@ var FormPresenter = class {
|
|
|
474
525
|
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
475
526
|
const dirty = storedValue !== value;
|
|
476
527
|
(0, import_base2.assertExists)(revert, "changing field directly not supported {}", valuePath);
|
|
528
|
+
if (ignoreDefaultValue) {
|
|
529
|
+
const {
|
|
530
|
+
value: defaultDisplayValue
|
|
531
|
+
} = convert(create(valuePath, model.value), valuePath, model.value);
|
|
532
|
+
if (defaultDisplayValue === value) {
|
|
533
|
+
return true;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
477
536
|
const conversion = revert(value, valuePath, model.value);
|
|
478
537
|
return (0, import_mobx.runInAction)(function() {
|
|
479
538
|
switch (conversion.type) {
|
|
@@ -544,13 +603,6 @@ var FormPresenter = class {
|
|
|
544
603
|
);
|
|
545
604
|
});
|
|
546
605
|
}
|
|
547
|
-
createModel(value) {
|
|
548
|
-
return new FormModel(
|
|
549
|
-
this.type,
|
|
550
|
-
value,
|
|
551
|
-
this.adapters
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
606
|
};
|
|
555
607
|
var FormModel = class {
|
|
556
608
|
constructor(type, value, adapters) {
|
|
@@ -688,19 +740,173 @@ var FormModel = class {
|
|
|
688
740
|
}
|
|
689
741
|
};
|
|
690
742
|
|
|
691
|
-
// core/mobx/hooks.
|
|
743
|
+
// core/mobx/hooks.tsx
|
|
744
|
+
var import_react2 = require("react");
|
|
745
|
+
|
|
746
|
+
// util/partial.tsx
|
|
747
|
+
var import_mobx_react = require("mobx-react");
|
|
692
748
|
var import_react = require("react");
|
|
749
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
750
|
+
function createSimplePartialComponent(Component, curriedProps) {
|
|
751
|
+
return (0, import_react.forwardRef)(
|
|
752
|
+
function(exposedProps, ref) {
|
|
753
|
+
const C = Component;
|
|
754
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
755
|
+
C,
|
|
756
|
+
{
|
|
757
|
+
ref,
|
|
758
|
+
...curriedProps,
|
|
759
|
+
...exposedProps
|
|
760
|
+
}
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
function createPartialComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
766
|
+
return (0, import_react.forwardRef)(
|
|
767
|
+
function(props, ref) {
|
|
768
|
+
const C = Component;
|
|
769
|
+
const [
|
|
770
|
+
additionalProps,
|
|
771
|
+
exposedProps
|
|
772
|
+
] = additionalPropKeys.reduce(
|
|
773
|
+
function([
|
|
774
|
+
additionalProps2,
|
|
775
|
+
exposedProps2
|
|
776
|
+
], key) {
|
|
777
|
+
const value = props[
|
|
778
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
779
|
+
key
|
|
780
|
+
];
|
|
781
|
+
delete exposedProps2[key];
|
|
782
|
+
additionalProps2[key] = value;
|
|
783
|
+
return [
|
|
784
|
+
additionalProps2,
|
|
785
|
+
exposedProps2
|
|
786
|
+
];
|
|
787
|
+
},
|
|
788
|
+
[
|
|
789
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
790
|
+
{},
|
|
791
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
792
|
+
{ ...props }
|
|
793
|
+
]
|
|
794
|
+
);
|
|
795
|
+
const curriedProps = curriedPropsSource(additionalProps);
|
|
796
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
797
|
+
C,
|
|
798
|
+
{
|
|
799
|
+
ref,
|
|
800
|
+
...curriedProps,
|
|
801
|
+
...exposedProps
|
|
802
|
+
}
|
|
803
|
+
);
|
|
804
|
+
}
|
|
805
|
+
);
|
|
806
|
+
}
|
|
807
|
+
function usePartialComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
808
|
+
return (0, import_react.useMemo)(
|
|
809
|
+
function() {
|
|
810
|
+
return createPartialComponent(
|
|
811
|
+
Component,
|
|
812
|
+
curriedPropsSource,
|
|
813
|
+
additionalPropKeys
|
|
814
|
+
);
|
|
815
|
+
},
|
|
816
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
817
|
+
[
|
|
818
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
819
|
+
...deps,
|
|
820
|
+
Component,
|
|
821
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
822
|
+
...additionalPropKeys
|
|
823
|
+
]
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
function createPartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
827
|
+
return createUnsafePartialObserverComponent(
|
|
828
|
+
Component,
|
|
829
|
+
curriedPropsSource,
|
|
830
|
+
additionalPropKeys
|
|
831
|
+
);
|
|
832
|
+
}
|
|
833
|
+
function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
834
|
+
return (0, import_mobx_react.observer)(
|
|
835
|
+
(0, import_react.forwardRef)(
|
|
836
|
+
function(props, ref) {
|
|
837
|
+
const C = Component;
|
|
838
|
+
const [
|
|
839
|
+
additionalProps,
|
|
840
|
+
exposedProps
|
|
841
|
+
] = additionalPropKeys.reduce(
|
|
842
|
+
function([
|
|
843
|
+
additionalProps2,
|
|
844
|
+
exposedProps2
|
|
845
|
+
], key) {
|
|
846
|
+
const value = props[
|
|
847
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
848
|
+
key
|
|
849
|
+
];
|
|
850
|
+
delete exposedProps2[key];
|
|
851
|
+
additionalProps2[key] = value;
|
|
852
|
+
return [
|
|
853
|
+
additionalProps2,
|
|
854
|
+
exposedProps2
|
|
855
|
+
];
|
|
856
|
+
},
|
|
857
|
+
[
|
|
858
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
859
|
+
{},
|
|
860
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
861
|
+
{ ...props }
|
|
862
|
+
]
|
|
863
|
+
);
|
|
864
|
+
const curriedProps = curriedPropsSource(additionalProps);
|
|
865
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
866
|
+
C,
|
|
867
|
+
{
|
|
868
|
+
ref,
|
|
869
|
+
...curriedProps,
|
|
870
|
+
...exposedProps
|
|
871
|
+
}
|
|
872
|
+
);
|
|
873
|
+
}
|
|
874
|
+
)
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
878
|
+
return (0, import_react.useMemo)(
|
|
879
|
+
function() {
|
|
880
|
+
return createPartialObserverComponent(
|
|
881
|
+
Component,
|
|
882
|
+
curriedPropsSource,
|
|
883
|
+
additionalPropKeys
|
|
884
|
+
);
|
|
885
|
+
},
|
|
886
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
887
|
+
[
|
|
888
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
889
|
+
...deps,
|
|
890
|
+
Component,
|
|
891
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
892
|
+
...additionalPropKeys
|
|
893
|
+
]
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// core/mobx/hooks.tsx
|
|
693
898
|
function useDefaultMobxFormHooks(presenter, value, {
|
|
694
899
|
onValidFieldSubmit,
|
|
695
|
-
onValidFormSubmit
|
|
696
|
-
|
|
697
|
-
|
|
900
|
+
onValidFormSubmit,
|
|
901
|
+
FormFieldsView
|
|
902
|
+
} = {}) {
|
|
903
|
+
const model = (0, import_react2.useMemo)(function() {
|
|
698
904
|
return presenter.createModel(value);
|
|
699
905
|
}, [
|
|
700
906
|
presenter,
|
|
701
907
|
value
|
|
702
908
|
]);
|
|
703
|
-
const onFieldValueChange = (0,
|
|
909
|
+
const onFieldValueChange = (0, import_react2.useCallback)(
|
|
704
910
|
function(path, value2) {
|
|
705
911
|
presenter.clearFieldError(model, path);
|
|
706
912
|
presenter.setFieldValue(model, path, value2);
|
|
@@ -710,7 +916,7 @@ function useDefaultMobxFormHooks(presenter, value, {
|
|
|
710
916
|
model
|
|
711
917
|
]
|
|
712
918
|
);
|
|
713
|
-
const onFieldSubmit = (0,
|
|
919
|
+
const onFieldSubmit = (0, import_react2.useCallback)(
|
|
714
920
|
function(valuePath) {
|
|
715
921
|
if (presenter.validateField(model, valuePath)) {
|
|
716
922
|
onValidFieldSubmit?.(model, valuePath);
|
|
@@ -723,11 +929,11 @@ function useDefaultMobxFormHooks(presenter, value, {
|
|
|
723
929
|
onValidFieldSubmit
|
|
724
930
|
]
|
|
725
931
|
);
|
|
726
|
-
const onFieldBlur = (0,
|
|
932
|
+
const onFieldBlur = (0, import_react2.useCallback)(
|
|
727
933
|
function(path) {
|
|
728
934
|
setTimeout(function() {
|
|
729
935
|
if (presenter.isValuePathActive(model, path)) {
|
|
730
|
-
presenter.validateField(model, path);
|
|
936
|
+
presenter.validateField(model, path, true);
|
|
731
937
|
}
|
|
732
938
|
}, 100);
|
|
733
939
|
},
|
|
@@ -736,7 +942,7 @@ function useDefaultMobxFormHooks(presenter, value, {
|
|
|
736
942
|
model
|
|
737
943
|
]
|
|
738
944
|
);
|
|
739
|
-
const onFormSubmit = (0,
|
|
945
|
+
const onFormSubmit = (0, import_react2.useCallback)(
|
|
740
946
|
function() {
|
|
741
947
|
if (presenter.validateAll(model)) {
|
|
742
948
|
onValidFormSubmit?.(model, model.value);
|
|
@@ -748,12 +954,33 @@ function useDefaultMobxFormHooks(presenter, value, {
|
|
|
748
954
|
onValidFormSubmit
|
|
749
955
|
]
|
|
750
956
|
);
|
|
957
|
+
const FormFields = (0, import_react2.useMemo)(() => {
|
|
958
|
+
if (FormFieldsView == null) {
|
|
959
|
+
return void 0;
|
|
960
|
+
}
|
|
961
|
+
return createUnsafePartialObserverComponent(FormFieldsView, () => {
|
|
962
|
+
return {
|
|
963
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
964
|
+
fields: model.fields,
|
|
965
|
+
onFieldBlur,
|
|
966
|
+
onFieldSubmit,
|
|
967
|
+
onFieldValueChange
|
|
968
|
+
};
|
|
969
|
+
});
|
|
970
|
+
}, [
|
|
971
|
+
model,
|
|
972
|
+
FormFieldsView,
|
|
973
|
+
onFieldBlur,
|
|
974
|
+
onFieldSubmit,
|
|
975
|
+
onFieldValueChange
|
|
976
|
+
]);
|
|
751
977
|
return {
|
|
752
978
|
model,
|
|
753
979
|
onFieldValueChange,
|
|
754
980
|
onFieldSubmit,
|
|
755
981
|
onFieldBlur,
|
|
756
|
-
onFormSubmit
|
|
982
|
+
onFormSubmit,
|
|
983
|
+
FormFields
|
|
757
984
|
};
|
|
758
985
|
}
|
|
759
986
|
|
|
@@ -1025,25 +1252,6 @@ var SelectStringConverter = class extends AbstractSelectValueTypeConverter {
|
|
|
1025
1252
|
}
|
|
1026
1253
|
};
|
|
1027
1254
|
|
|
1028
|
-
// field_converters/trimming_string_converter.ts
|
|
1029
|
-
var TrimmingStringConverter = class {
|
|
1030
|
-
constructor() {
|
|
1031
|
-
}
|
|
1032
|
-
convert(to) {
|
|
1033
|
-
return {
|
|
1034
|
-
value: to.trim(),
|
|
1035
|
-
required: false,
|
|
1036
|
-
readonly: false
|
|
1037
|
-
};
|
|
1038
|
-
}
|
|
1039
|
-
revert(from) {
|
|
1040
|
-
return {
|
|
1041
|
-
type: 0 /* Success */,
|
|
1042
|
-
value: from.trim()
|
|
1043
|
-
};
|
|
1044
|
-
}
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
1255
|
// field_converters/validating_converter.ts
|
|
1048
1256
|
var import_define6 = require("@strictly/define");
|
|
1049
1257
|
function validatingConverter(validators = []) {
|
|
@@ -1084,157 +1292,6 @@ var import_base6 = require("@strictly/base");
|
|
|
1084
1292
|
var import_mobx2 = require("mobx");
|
|
1085
1293
|
var import_react4 = require("react");
|
|
1086
1294
|
|
|
1087
|
-
// util/partial.tsx
|
|
1088
|
-
var import_mobx_react = require("mobx-react");
|
|
1089
|
-
var import_react2 = require("react");
|
|
1090
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1091
|
-
function createSimplePartialComponent(Component, curriedProps) {
|
|
1092
|
-
return (0, import_react2.forwardRef)(
|
|
1093
|
-
function(exposedProps, ref) {
|
|
1094
|
-
const C = Component;
|
|
1095
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1096
|
-
C,
|
|
1097
|
-
{
|
|
1098
|
-
ref,
|
|
1099
|
-
...curriedProps,
|
|
1100
|
-
...exposedProps
|
|
1101
|
-
}
|
|
1102
|
-
);
|
|
1103
|
-
}
|
|
1104
|
-
);
|
|
1105
|
-
}
|
|
1106
|
-
function createPartialComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1107
|
-
return (0, import_react2.forwardRef)(
|
|
1108
|
-
function(props, ref) {
|
|
1109
|
-
const C = Component;
|
|
1110
|
-
const [
|
|
1111
|
-
additionalProps,
|
|
1112
|
-
exposedProps
|
|
1113
|
-
] = additionalPropKeys.reduce(
|
|
1114
|
-
function([
|
|
1115
|
-
additionalProps2,
|
|
1116
|
-
exposedProps2
|
|
1117
|
-
], key) {
|
|
1118
|
-
const value = props[
|
|
1119
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1120
|
-
key
|
|
1121
|
-
];
|
|
1122
|
-
delete exposedProps2[key];
|
|
1123
|
-
additionalProps2[key] = value;
|
|
1124
|
-
return [
|
|
1125
|
-
additionalProps2,
|
|
1126
|
-
exposedProps2
|
|
1127
|
-
];
|
|
1128
|
-
},
|
|
1129
|
-
[
|
|
1130
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1131
|
-
{},
|
|
1132
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1133
|
-
{ ...props }
|
|
1134
|
-
]
|
|
1135
|
-
);
|
|
1136
|
-
const curriedProps = curriedPropsSource(additionalProps);
|
|
1137
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1138
|
-
C,
|
|
1139
|
-
{
|
|
1140
|
-
ref,
|
|
1141
|
-
...curriedProps,
|
|
1142
|
-
...exposedProps
|
|
1143
|
-
}
|
|
1144
|
-
);
|
|
1145
|
-
}
|
|
1146
|
-
);
|
|
1147
|
-
}
|
|
1148
|
-
function usePartialComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1149
|
-
return (0, import_react2.useMemo)(
|
|
1150
|
-
function() {
|
|
1151
|
-
return createPartialComponent(
|
|
1152
|
-
Component,
|
|
1153
|
-
curriedPropsSource,
|
|
1154
|
-
additionalPropKeys
|
|
1155
|
-
);
|
|
1156
|
-
},
|
|
1157
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1158
|
-
[
|
|
1159
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1160
|
-
...deps,
|
|
1161
|
-
Component,
|
|
1162
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1163
|
-
...additionalPropKeys
|
|
1164
|
-
]
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
function createPartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1168
|
-
return createUnsafePartialObserverComponent(
|
|
1169
|
-
Component,
|
|
1170
|
-
curriedPropsSource,
|
|
1171
|
-
additionalPropKeys
|
|
1172
|
-
);
|
|
1173
|
-
}
|
|
1174
|
-
function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1175
|
-
return (0, import_mobx_react.observer)(
|
|
1176
|
-
(0, import_react2.forwardRef)(
|
|
1177
|
-
function(props, ref) {
|
|
1178
|
-
const C = Component;
|
|
1179
|
-
const [
|
|
1180
|
-
additionalProps,
|
|
1181
|
-
exposedProps
|
|
1182
|
-
] = additionalPropKeys.reduce(
|
|
1183
|
-
function([
|
|
1184
|
-
additionalProps2,
|
|
1185
|
-
exposedProps2
|
|
1186
|
-
], key) {
|
|
1187
|
-
const value = props[
|
|
1188
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1189
|
-
key
|
|
1190
|
-
];
|
|
1191
|
-
delete exposedProps2[key];
|
|
1192
|
-
additionalProps2[key] = value;
|
|
1193
|
-
return [
|
|
1194
|
-
additionalProps2,
|
|
1195
|
-
exposedProps2
|
|
1196
|
-
];
|
|
1197
|
-
},
|
|
1198
|
-
[
|
|
1199
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1200
|
-
{},
|
|
1201
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1202
|
-
{ ...props }
|
|
1203
|
-
]
|
|
1204
|
-
);
|
|
1205
|
-
const curriedProps = curriedPropsSource(additionalProps);
|
|
1206
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1207
|
-
C,
|
|
1208
|
-
{
|
|
1209
|
-
ref,
|
|
1210
|
-
...curriedProps,
|
|
1211
|
-
...exposedProps
|
|
1212
|
-
}
|
|
1213
|
-
);
|
|
1214
|
-
}
|
|
1215
|
-
)
|
|
1216
|
-
);
|
|
1217
|
-
}
|
|
1218
|
-
function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
|
|
1219
|
-
return (0, import_react2.useMemo)(
|
|
1220
|
-
function() {
|
|
1221
|
-
return createPartialObserverComponent(
|
|
1222
|
-
Component,
|
|
1223
|
-
curriedPropsSource,
|
|
1224
|
-
additionalPropKeys
|
|
1225
|
-
);
|
|
1226
|
-
},
|
|
1227
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1228
|
-
[
|
|
1229
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1230
|
-
...deps,
|
|
1231
|
-
Component,
|
|
1232
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1233
|
-
...additionalPropKeys
|
|
1234
|
-
]
|
|
1235
|
-
);
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
1295
|
// mantine/create_checkbox.tsx
|
|
1239
1296
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1240
1297
|
function createCheckbox(valuePath, Checkbox) {
|
|
@@ -1305,34 +1362,46 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
|
1305
1362
|
function onFieldSubmit(subKey) {
|
|
1306
1363
|
observableProps.onFieldSubmit?.(toKey(subKey));
|
|
1307
1364
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
(
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1365
|
+
const Component = (0, import_mobx_react2.observer)(
|
|
1366
|
+
function(props) {
|
|
1367
|
+
const subFields = Object.entries(observableProps.fields).reduce(
|
|
1368
|
+
(acc, [
|
|
1369
|
+
fieldKey,
|
|
1370
|
+
fieldValue
|
|
1371
|
+
]) => {
|
|
1372
|
+
if (fieldKey.startsWith(valuePath)) {
|
|
1373
|
+
acc[toSubKey(fieldKey)] = fieldValue;
|
|
1374
|
+
}
|
|
1375
|
+
return acc;
|
|
1376
|
+
},
|
|
1377
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
1378
|
+
{}
|
|
1379
|
+
);
|
|
1380
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1381
|
+
FieldsView,
|
|
1382
|
+
{
|
|
1383
|
+
// maybe we can do this in a more type safe way
|
|
1384
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/consistent-type-assertions
|
|
1385
|
+
...props,
|
|
1386
|
+
fields: subFields,
|
|
1387
|
+
onFieldBlur,
|
|
1388
|
+
onFieldFocus,
|
|
1389
|
+
onFieldSubmit,
|
|
1390
|
+
onFieldValueChange
|
|
1316
1391
|
}
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
)
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
onFieldFocus,
|
|
1331
|
-
onFieldSubmit,
|
|
1332
|
-
onFieldValueChange
|
|
1333
|
-
}
|
|
1334
|
-
);
|
|
1335
|
-
});
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
);
|
|
1395
|
+
const callbackMapper = (callback) => {
|
|
1396
|
+
return (subFormValuePath, ...args) => {
|
|
1397
|
+
const valuePath2 = toKey(subFormValuePath);
|
|
1398
|
+
return callback(valuePath2, ...args);
|
|
1399
|
+
};
|
|
1400
|
+
};
|
|
1401
|
+
return {
|
|
1402
|
+
Component,
|
|
1403
|
+
callbackMapper
|
|
1404
|
+
};
|
|
1336
1405
|
}
|
|
1337
1406
|
|
|
1338
1407
|
// mantine/create_form.tsx
|
|
@@ -1783,6 +1852,7 @@ function mergeValidators(validators1, validators2) {
|
|
|
1783
1852
|
mergeValidators,
|
|
1784
1853
|
prototypingFieldValueFactory,
|
|
1785
1854
|
subFormFieldAdapters,
|
|
1855
|
+
trimmingStringAdapter,
|
|
1786
1856
|
useDefaultMobxFormHooks,
|
|
1787
1857
|
useMantineFormFields,
|
|
1788
1858
|
usePartialComponent,
|