@strictly/react-form 0.0.15 → 0.0.17
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/form_model.d.ts +9 -6
- package/.out/core/mobx/form_model.js +77 -42
- package/.out/core/mobx/specs/form_model.tests.js +80 -20
- package/.out/core/mobx/types.d.ts +4 -4
- package/.out/core/props.d.ts +2 -0
- package/.out/index.d.ts +0 -1
- package/.out/index.js +0 -1
- package/.out/mantine/create_field_view.d.ts +20 -0
- package/.out/mantine/create_field_view.js +54 -0
- package/.out/mantine/create_list.js +3 -2
- package/.out/mantine/hooks.d.ts +4 -1
- package/.out/mantine/hooks.js +14 -2
- package/.out/mantine/specs/field_view_hooks.stories.d.ts +12 -0
- package/.out/mantine/specs/field_view_hooks.stories.js +61 -0
- package/.out/mantine/specs/field_view_hooks.tests.d.ts +1 -0
- package/.out/mantine/specs/field_view_hooks.tests.js +12 -0
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/core/mobx/field_adapter_builder.ts +2 -2
- package/core/mobx/form_model.ts +89 -47
- package/core/mobx/specs/form_model.tests.ts +131 -11
- package/core/mobx/types.ts +4 -4
- package/core/props.ts +4 -0
- package/dist/index.cjs +165 -89
- package/dist/index.d.cts +45 -40
- package/dist/index.d.ts +45 -40
- package/dist/index.js +162 -81
- package/index.ts +0 -1
- package/mantine/create_field_view.tsx +94 -0
- package/mantine/create_list.tsx +9 -2
- package/mantine/hooks.tsx +19 -2
- package/mantine/specs/__snapshots__/field_view_hooks.tests.tsx.snap +153 -0
- package/mantine/specs/field_view_hooks.stories.tsx +112 -0
- package/mantine/specs/field_view_hooks.tests.tsx +15 -0
- package/package.json +1 -1
- package/.out/mantine/field_view.d.ts +0 -18
- package/.out/mantine/field_view.js +0 -16
- package/mantine/field_view.tsx +0 -39
package/dist/index.cjs
CHANGED
|
@@ -89,7 +89,6 @@ __export(index_exports, {
|
|
|
89
89
|
AbstractSelectValueTypeConverter: () => AbstractSelectValueTypeConverter,
|
|
90
90
|
DefaultErrorRenderer: () => DefaultErrorRenderer,
|
|
91
91
|
Empty: () => Empty,
|
|
92
|
-
FieldView: () => FieldView,
|
|
93
92
|
FormModel: () => FormModel,
|
|
94
93
|
IntegerToStringConverter: () => IntegerToStringConverter,
|
|
95
94
|
NullableToBooleanConverter: () => NullableToBooleanConverter,
|
|
@@ -357,26 +356,28 @@ function listAdapter() {
|
|
|
357
356
|
var import_base2 = require("@strictly/base");
|
|
358
357
|
var import_define = require("@strictly/define");
|
|
359
358
|
var import_mobx = require("mobx");
|
|
360
|
-
var _accessors_dec, _knownFields_dec, _fields_dec,
|
|
361
|
-
_value_dec = [import_mobx.observable.ref], _fieldOverrides_dec = [import_mobx.observable.shallow], _errors_dec = [import_mobx.observable.shallow],
|
|
359
|
+
var _accessors_dec, _knownFields_dec, _fields_dec, _errors_dec, _fieldOverrides_dec, _value_dec, _init, _value, _fieldOverrides, _errors;
|
|
360
|
+
_value_dec = [import_mobx.observable.ref], _fieldOverrides_dec = [import_mobx.observable.shallow], _errors_dec = [import_mobx.observable.shallow], _fields_dec = [import_mobx.computed], _knownFields_dec = [import_mobx.computed], _accessors_dec = [import_mobx.computed];
|
|
362
361
|
var FormModel = class {
|
|
363
|
-
constructor(type,
|
|
362
|
+
constructor(type, originalValue, adapters, mode) {
|
|
364
363
|
this.type = type;
|
|
364
|
+
this.originalValue = originalValue;
|
|
365
365
|
this.adapters = adapters;
|
|
366
|
+
this.mode = mode;
|
|
366
367
|
__runInitializers(_init, 5, this);
|
|
367
368
|
__privateAdd(this, _value, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
|
|
368
369
|
__privateAdd(this, _fieldOverrides, __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
|
|
369
370
|
__privateAdd(this, _errors, __runInitializers(_init, 16, this, {})), __runInitializers(_init, 19, this);
|
|
370
371
|
__publicField(this, "flattenedTypeDefs");
|
|
371
|
-
this.value = (0, import_define.mobxCopy)(type,
|
|
372
|
+
this.value = (0, import_define.mobxCopy)(type, originalValue);
|
|
372
373
|
this.flattenedTypeDefs = (0, import_define.flattenTypesOfType)(type);
|
|
373
|
-
const contextValue = this.toContext(value);
|
|
374
374
|
const conversions = (0, import_define.flattenValueTo)(
|
|
375
375
|
type,
|
|
376
376
|
this.value,
|
|
377
377
|
() => {
|
|
378
378
|
},
|
|
379
|
-
(_t,
|
|
379
|
+
(_t, fieldValue, _setter, typePath, valuePath) => {
|
|
380
|
+
const contextValue = this.toContext(originalValue, valuePath);
|
|
380
381
|
const adapter2 = this.adapters[typePath];
|
|
381
382
|
if (adapter2 == null) {
|
|
382
383
|
return;
|
|
@@ -388,15 +389,22 @@ var FormModel = class {
|
|
|
388
389
|
if (revert == null) {
|
|
389
390
|
return;
|
|
390
391
|
}
|
|
391
|
-
return convert(
|
|
392
|
+
return convert(fieldValue, valuePath, contextValue);
|
|
392
393
|
}
|
|
393
394
|
);
|
|
394
395
|
this.fieldOverrides = (0, import_base2.map)(conversions, function(_k, v) {
|
|
395
396
|
return v && [v.value];
|
|
396
397
|
});
|
|
397
398
|
}
|
|
398
|
-
get
|
|
399
|
-
|
|
399
|
+
get forceMutableFields() {
|
|
400
|
+
switch (this.mode) {
|
|
401
|
+
case "create":
|
|
402
|
+
return true;
|
|
403
|
+
case "edit":
|
|
404
|
+
return false;
|
|
405
|
+
default:
|
|
406
|
+
return this.mode;
|
|
407
|
+
}
|
|
400
408
|
}
|
|
401
409
|
get fields() {
|
|
402
410
|
return new Proxy(
|
|
@@ -457,6 +465,7 @@ var FormModel = class {
|
|
|
457
465
|
const fieldOverride = this.fieldOverrides[valuePath];
|
|
458
466
|
const accessor = this.getAccessorForValuePath(valuePath);
|
|
459
467
|
const fieldTypeDef = this.flattenedTypeDefs[typePath];
|
|
468
|
+
const context = this.toContext(this.value, valuePath);
|
|
460
469
|
const {
|
|
461
470
|
value,
|
|
462
471
|
required,
|
|
@@ -465,17 +474,17 @@ var FormModel = class {
|
|
|
465
474
|
accessor != null ? accessor.value : fieldTypeDef != null ? (0, import_define.mobxCopy)(
|
|
466
475
|
fieldTypeDef,
|
|
467
476
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
468
|
-
create(valuePath,
|
|
469
|
-
) : create(valuePath,
|
|
477
|
+
create(valuePath, context)
|
|
478
|
+
) : create(valuePath, context),
|
|
470
479
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
471
480
|
valuePath,
|
|
472
|
-
|
|
481
|
+
context
|
|
473
482
|
);
|
|
474
483
|
const error = this.errors[valuePath];
|
|
475
484
|
return {
|
|
476
485
|
value: fieldOverride != null ? fieldOverride[0] : value,
|
|
477
486
|
error,
|
|
478
|
-
readonly,
|
|
487
|
+
readonly: readonly && !this.forceMutableFields,
|
|
479
488
|
required
|
|
480
489
|
};
|
|
481
490
|
}
|
|
@@ -527,7 +536,9 @@ var FormModel = class {
|
|
|
527
536
|
const element = elementValue != null ? elementValue[0] : elementAdapter.create(
|
|
528
537
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
529
538
|
elementTypePath,
|
|
530
|
-
|
|
539
|
+
// TODO what can we use for the value path here?
|
|
540
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
541
|
+
this.toContext(this.value, valuePath)
|
|
531
542
|
);
|
|
532
543
|
const originalList = accessor.value;
|
|
533
544
|
const newList = [
|
|
@@ -645,7 +656,7 @@ var FormModel = class {
|
|
|
645
656
|
internalSetFieldValue(valuePath, value, displayValidation) {
|
|
646
657
|
const { revert } = this.getAdapterForValuePath(valuePath);
|
|
647
658
|
(0, import_base2.assertExists)(revert, "setting value not supported {}", valuePath);
|
|
648
|
-
const conversion = revert(value, valuePath, this.
|
|
659
|
+
const conversion = revert(value, valuePath, this.toContext(this.value, valuePath));
|
|
649
660
|
const accessor = this.getAccessorForValuePath(valuePath);
|
|
650
661
|
return (0, import_mobx.runInAction)(() => {
|
|
651
662
|
this.fieldOverrides[valuePath] = [value];
|
|
@@ -685,10 +696,11 @@ var FormModel = class {
|
|
|
685
696
|
convert,
|
|
686
697
|
create
|
|
687
698
|
} = adapter2;
|
|
688
|
-
const
|
|
699
|
+
const context = this.toContext(this.value, valuePath);
|
|
700
|
+
const value = create(valuePath, context);
|
|
689
701
|
const {
|
|
690
702
|
value: displayValue
|
|
691
|
-
} = convert(value, valuePath,
|
|
703
|
+
} = convert(value, valuePath, context);
|
|
692
704
|
const key = valuePath;
|
|
693
705
|
(0, import_mobx.runInAction)(() => {
|
|
694
706
|
this.fieldOverrides[key] = [displayValue];
|
|
@@ -714,13 +726,14 @@ var FormModel = class {
|
|
|
714
726
|
} = this.getAdapterForValuePath(valuePath);
|
|
715
727
|
const fieldOverride = this.fieldOverrides[valuePath];
|
|
716
728
|
const accessor = this.getAccessorForValuePath(valuePath);
|
|
729
|
+
const context = this.toContext(this.value, valuePath);
|
|
717
730
|
const {
|
|
718
731
|
value: storedValue
|
|
719
732
|
} = convert(
|
|
720
|
-
accessor != null ? accessor.value : create(valuePath,
|
|
733
|
+
accessor != null ? accessor.value : create(valuePath, context),
|
|
721
734
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
722
735
|
valuePath,
|
|
723
|
-
|
|
736
|
+
context
|
|
724
737
|
);
|
|
725
738
|
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
726
739
|
const dirty = storedValue !== value;
|
|
@@ -728,12 +741,12 @@ var FormModel = class {
|
|
|
728
741
|
if (ignoreDefaultValue) {
|
|
729
742
|
const {
|
|
730
743
|
value: defaultDisplayValue
|
|
731
|
-
} = convert(create(valuePath,
|
|
744
|
+
} = convert(create(valuePath, context), valuePath, context);
|
|
732
745
|
if (defaultDisplayValue === value) {
|
|
733
746
|
return true;
|
|
734
747
|
}
|
|
735
748
|
}
|
|
736
|
-
const conversion = revert(value, valuePath,
|
|
749
|
+
const conversion = revert(value, valuePath, context);
|
|
737
750
|
return (0, import_mobx.runInAction)(() => {
|
|
738
751
|
switch (conversion.type) {
|
|
739
752
|
case 1 /* Failure */:
|
|
@@ -753,10 +766,11 @@ var FormModel = class {
|
|
|
753
766
|
}
|
|
754
767
|
});
|
|
755
768
|
}
|
|
756
|
-
validateAll() {
|
|
769
|
+
validateAll(force = this.mode === "create") {
|
|
757
770
|
const accessors = (0, import_base2.toArray)(this.accessors).toSorted(function([a], [b]) {
|
|
758
771
|
return a.length - b.length;
|
|
759
772
|
});
|
|
773
|
+
const flattenedOriginalValues = (0, import_define.flattenValuesOfType)(this.type, this.originalValue);
|
|
760
774
|
return (0, import_mobx.runInAction)(() => {
|
|
761
775
|
return accessors.reduce(
|
|
762
776
|
(success, [
|
|
@@ -776,28 +790,38 @@ var FormModel = class {
|
|
|
776
790
|
return success;
|
|
777
791
|
}
|
|
778
792
|
const fieldOverride = this.fieldOverrides[adapterPath];
|
|
793
|
+
const context = this.toContext(this.value, valuePath);
|
|
779
794
|
const {
|
|
780
795
|
value: storedValue
|
|
781
|
-
} = convert(accessor.value, valuePath,
|
|
796
|
+
} = convert(accessor.value, valuePath, context);
|
|
782
797
|
const value = fieldOverride != null ? fieldOverride[0] : storedValue;
|
|
783
798
|
const dirty = fieldOverride != null && fieldOverride[0] !== storedValue;
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
799
|
+
const needsValidation = force || !(valuePath in flattenedOriginalValues) || storedValue !== convert(
|
|
800
|
+
flattenedOriginalValues[valuePath],
|
|
801
|
+
valuePath,
|
|
802
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
803
|
+
this.toContext(this.originalValue, valuePath)
|
|
804
|
+
).value;
|
|
805
|
+
if (needsValidation) {
|
|
806
|
+
const conversion = revert(value, valuePath, context);
|
|
807
|
+
switch (conversion.type) {
|
|
808
|
+
case 1 /* Failure */:
|
|
809
|
+
this.errors[adapterPath] = conversion.error;
|
|
810
|
+
if (conversion.value != null && dirty) {
|
|
811
|
+
accessor.set(conversion.value[0]);
|
|
812
|
+
}
|
|
813
|
+
return false;
|
|
814
|
+
case 0 /* Success */:
|
|
815
|
+
if (dirty) {
|
|
816
|
+
accessor.set(conversion.value);
|
|
817
|
+
}
|
|
818
|
+
delete this.errors[adapterPath];
|
|
819
|
+
return success;
|
|
820
|
+
default:
|
|
821
|
+
throw new import_base2.UnreachableError(conversion);
|
|
822
|
+
}
|
|
800
823
|
}
|
|
824
|
+
return success;
|
|
801
825
|
},
|
|
802
826
|
true
|
|
803
827
|
);
|
|
@@ -811,7 +835,6 @@ _errors = new WeakMap();
|
|
|
811
835
|
__decorateElement(_init, 4, "value", _value_dec, FormModel, _value);
|
|
812
836
|
__decorateElement(_init, 4, "fieldOverrides", _fieldOverrides_dec, FormModel, _fieldOverrides);
|
|
813
837
|
__decorateElement(_init, 4, "errors", _errors_dec, FormModel, _errors);
|
|
814
|
-
__decorateElement(_init, 2, "context", _context_dec, FormModel);
|
|
815
838
|
__decorateElement(_init, 2, "fields", _fields_dec, FormModel);
|
|
816
839
|
__decorateElement(_init, 2, "knownFields", _knownFields_dec, FormModel);
|
|
817
840
|
__decorateElement(_init, 2, "accessors", _accessors_dec, FormModel);
|
|
@@ -1167,49 +1190,21 @@ function DefaultErrorRenderer({
|
|
|
1167
1190
|
return JSON.stringify(error);
|
|
1168
1191
|
}
|
|
1169
1192
|
|
|
1170
|
-
// mantine/field_view.tsx
|
|
1171
|
-
var import_mobx_react = require("mobx-react");
|
|
1172
|
-
|
|
1173
|
-
// util/empty.tsx
|
|
1174
|
-
function Empty() {
|
|
1175
|
-
return null;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
// mantine/field_view.tsx
|
|
1179
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1180
|
-
function FieldView({
|
|
1181
|
-
fields,
|
|
1182
|
-
valuePath,
|
|
1183
|
-
children
|
|
1184
|
-
}) {
|
|
1185
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mobx_react.Observer, { children: () => {
|
|
1186
|
-
const {
|
|
1187
|
-
value,
|
|
1188
|
-
error
|
|
1189
|
-
} = fields[valuePath];
|
|
1190
|
-
return children({
|
|
1191
|
-
value,
|
|
1192
|
-
error,
|
|
1193
|
-
ErrorSink: Empty
|
|
1194
|
-
});
|
|
1195
|
-
} });
|
|
1196
|
-
}
|
|
1197
|
-
|
|
1198
1193
|
// mantine/hooks.tsx
|
|
1199
1194
|
var import_core = require("@mantine/core");
|
|
1200
1195
|
var import_base6 = require("@strictly/base");
|
|
1201
1196
|
var import_mobx2 = require("mobx");
|
|
1202
|
-
var
|
|
1197
|
+
var import_react6 = require("react");
|
|
1203
1198
|
|
|
1204
1199
|
// util/partial.tsx
|
|
1205
|
-
var
|
|
1200
|
+
var import_mobx_react = require("mobx-react");
|
|
1206
1201
|
var import_react2 = require("react");
|
|
1207
|
-
var
|
|
1202
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1208
1203
|
function createSimplePartialComponent(Component, curriedProps) {
|
|
1209
1204
|
return (0, import_react2.forwardRef)(
|
|
1210
1205
|
function(exposedProps, ref) {
|
|
1211
1206
|
const C = Component;
|
|
1212
|
-
return /* @__PURE__ */ (0,
|
|
1207
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1213
1208
|
C,
|
|
1214
1209
|
__spreadValues(__spreadValues({
|
|
1215
1210
|
ref
|
|
@@ -1249,7 +1244,7 @@ function createPartialComponent(Component, curriedPropsSource, additionalPropKey
|
|
|
1249
1244
|
]
|
|
1250
1245
|
);
|
|
1251
1246
|
const curriedProps = curriedPropsSource(additionalProps);
|
|
1252
|
-
return /* @__PURE__ */ (0,
|
|
1247
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1253
1248
|
C,
|
|
1254
1249
|
__spreadValues(__spreadValues({
|
|
1255
1250
|
ref
|
|
@@ -1285,7 +1280,7 @@ function createPartialObserverComponent(Component, curriedPropsSource, additiona
|
|
|
1285
1280
|
);
|
|
1286
1281
|
}
|
|
1287
1282
|
function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
|
|
1288
|
-
return (0,
|
|
1283
|
+
return (0, import_mobx_react.observer)(
|
|
1289
1284
|
(0, import_react2.forwardRef)(
|
|
1290
1285
|
function(props, ref) {
|
|
1291
1286
|
const C = Component;
|
|
@@ -1316,7 +1311,7 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
|
|
|
1316
1311
|
]
|
|
1317
1312
|
);
|
|
1318
1313
|
const curriedProps = curriedPropsSource(additionalProps);
|
|
1319
|
-
return /* @__PURE__ */ (0,
|
|
1314
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
1320
1315
|
C,
|
|
1321
1316
|
__spreadValues(__spreadValues({
|
|
1322
1317
|
ref
|
|
@@ -1347,7 +1342,7 @@ function usePartialObserverComponent(curriedPropsSource, deps, Component, additi
|
|
|
1347
1342
|
}
|
|
1348
1343
|
|
|
1349
1344
|
// mantine/create_checkbox.tsx
|
|
1350
|
-
var
|
|
1345
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
1351
1346
|
function createCheckbox(valuePath, Checkbox) {
|
|
1352
1347
|
const onChange = (e) => {
|
|
1353
1348
|
var _a;
|
|
@@ -1384,7 +1379,7 @@ function createCheckbox(valuePath, Checkbox) {
|
|
|
1384
1379
|
checked: value,
|
|
1385
1380
|
disabled: readonly,
|
|
1386
1381
|
required,
|
|
1387
|
-
error: error && /* @__PURE__ */ (0,
|
|
1382
|
+
error: error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorRenderer, { error }),
|
|
1388
1383
|
onChange,
|
|
1389
1384
|
onFocus,
|
|
1390
1385
|
onBlur,
|
|
@@ -1398,6 +1393,78 @@ function createCheckbox(valuePath, Checkbox) {
|
|
|
1398
1393
|
);
|
|
1399
1394
|
}
|
|
1400
1395
|
|
|
1396
|
+
// mantine/create_field_view.tsx
|
|
1397
|
+
var import_mobx_react2 = require("mobx-react");
|
|
1398
|
+
var import_react3 = require("react");
|
|
1399
|
+
|
|
1400
|
+
// util/empty.tsx
|
|
1401
|
+
function Empty() {
|
|
1402
|
+
return null;
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// mantine/create_field_view.tsx
|
|
1406
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1407
|
+
function FieldView({
|
|
1408
|
+
valuePath,
|
|
1409
|
+
form,
|
|
1410
|
+
children
|
|
1411
|
+
}) {
|
|
1412
|
+
const onFocus = (0, import_react3.useCallback)(() => {
|
|
1413
|
+
var _a;
|
|
1414
|
+
(_a = form.onFieldFocus) == null ? void 0 : _a.call(form, valuePath);
|
|
1415
|
+
}, [
|
|
1416
|
+
form,
|
|
1417
|
+
valuePath
|
|
1418
|
+
]);
|
|
1419
|
+
const onBlur = (0, import_react3.useCallback)(() => {
|
|
1420
|
+
var _a;
|
|
1421
|
+
(_a = form.onFieldBlur) == null ? void 0 : _a.call(form, valuePath);
|
|
1422
|
+
}, [
|
|
1423
|
+
form,
|
|
1424
|
+
valuePath
|
|
1425
|
+
]);
|
|
1426
|
+
const onValueChange = (0, import_react3.useCallback)((value) => {
|
|
1427
|
+
var _a;
|
|
1428
|
+
(_a = form.onFieldValueChange) == null ? void 0 : _a.call(form, valuePath, value);
|
|
1429
|
+
}, [
|
|
1430
|
+
form,
|
|
1431
|
+
valuePath
|
|
1432
|
+
]);
|
|
1433
|
+
const onSubmit = (0, import_react3.useCallback)(() => {
|
|
1434
|
+
var _a;
|
|
1435
|
+
(_a = form.onFieldSubmit) == null ? void 0 : _a.call(form, valuePath);
|
|
1436
|
+
}, [
|
|
1437
|
+
form,
|
|
1438
|
+
valuePath
|
|
1439
|
+
]);
|
|
1440
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mobx_react2.Observer, { children: () => {
|
|
1441
|
+
const {
|
|
1442
|
+
value,
|
|
1443
|
+
error
|
|
1444
|
+
} = form.fields[valuePath];
|
|
1445
|
+
return children({
|
|
1446
|
+
value,
|
|
1447
|
+
error,
|
|
1448
|
+
ErrorSink: Empty,
|
|
1449
|
+
onFocus,
|
|
1450
|
+
onBlur,
|
|
1451
|
+
onValueChange,
|
|
1452
|
+
onSubmit
|
|
1453
|
+
});
|
|
1454
|
+
} });
|
|
1455
|
+
}
|
|
1456
|
+
function createFieldView(valuePath) {
|
|
1457
|
+
return (props) => {
|
|
1458
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1459
|
+
FieldView,
|
|
1460
|
+
__spreadValues({
|
|
1461
|
+
form: this,
|
|
1462
|
+
valuePath
|
|
1463
|
+
}, props)
|
|
1464
|
+
);
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1401
1468
|
// mantine/create_fields_view.tsx
|
|
1402
1469
|
var import_define6 = require("@strictly/define");
|
|
1403
1470
|
var import_mobx_react3 = require("mobx-react");
|
|
@@ -1465,12 +1532,12 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
|
|
|
1465
1532
|
|
|
1466
1533
|
// mantine/create_form.tsx
|
|
1467
1534
|
var import_mobx_react4 = require("mobx-react");
|
|
1468
|
-
var
|
|
1535
|
+
var import_react4 = require("react");
|
|
1469
1536
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1470
1537
|
function createForm(valuePath, Form, observableProps) {
|
|
1471
1538
|
return (0, import_mobx_react4.observer)((props) => {
|
|
1472
1539
|
const { value } = observableProps.fields[valuePath];
|
|
1473
|
-
const onValueChange = (0,
|
|
1540
|
+
const onValueChange = (0, import_react4.useCallback)((value2) => {
|
|
1474
1541
|
observableProps.onFieldValueChange(valuePath, value2);
|
|
1475
1542
|
}, []);
|
|
1476
1543
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
@@ -1484,6 +1551,7 @@ function createForm(valuePath, Form, observableProps) {
|
|
|
1484
1551
|
}
|
|
1485
1552
|
|
|
1486
1553
|
// mantine/create_list.tsx
|
|
1554
|
+
var import_react5 = require("react");
|
|
1487
1555
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1488
1556
|
function createList(valuePath, List) {
|
|
1489
1557
|
const propSource = () => {
|
|
@@ -1502,7 +1570,7 @@ function DefaultList({
|
|
|
1502
1570
|
}) {
|
|
1503
1571
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: values.map(function(value, index) {
|
|
1504
1572
|
const valuePath = `${listPath}.${index}`;
|
|
1505
|
-
return children(valuePath, value, index);
|
|
1573
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react5.Fragment, { children: children(valuePath, value, index) }, valuePath);
|
|
1506
1574
|
}) });
|
|
1507
1575
|
}
|
|
1508
1576
|
|
|
@@ -1701,16 +1769,17 @@ function useMantineFormFields({
|
|
|
1701
1769
|
onFieldFocus,
|
|
1702
1770
|
onFieldSubmit,
|
|
1703
1771
|
fields
|
|
1772
|
+
// should use FieldView rather than observing fields directly from here
|
|
1704
1773
|
}) {
|
|
1705
|
-
const form = (0,
|
|
1774
|
+
const form = (0, import_react6.useMemo)(
|
|
1706
1775
|
function() {
|
|
1707
1776
|
return new MantineFormImpl(fields);
|
|
1708
1777
|
},
|
|
1709
|
-
// handled separately below
|
|
1778
|
+
// fields handled separately below
|
|
1710
1779
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1711
1780
|
[]
|
|
1712
1781
|
);
|
|
1713
|
-
(0,
|
|
1782
|
+
(0, import_react6.useEffect)(function() {
|
|
1714
1783
|
(0, import_mobx2.runInAction)(function() {
|
|
1715
1784
|
form.fields = fields;
|
|
1716
1785
|
});
|
|
@@ -1718,25 +1787,25 @@ function useMantineFormFields({
|
|
|
1718
1787
|
form,
|
|
1719
1788
|
fields
|
|
1720
1789
|
]);
|
|
1721
|
-
(0,
|
|
1790
|
+
(0, import_react6.useEffect)(function() {
|
|
1722
1791
|
form.onFieldValueChange = onFieldValueChange;
|
|
1723
1792
|
}, [
|
|
1724
1793
|
form,
|
|
1725
1794
|
onFieldValueChange
|
|
1726
1795
|
]);
|
|
1727
|
-
(0,
|
|
1796
|
+
(0, import_react6.useEffect)(function() {
|
|
1728
1797
|
form.onFieldBlur = onFieldBlur;
|
|
1729
1798
|
}, [
|
|
1730
1799
|
form,
|
|
1731
1800
|
onFieldBlur
|
|
1732
1801
|
]);
|
|
1733
|
-
(0,
|
|
1802
|
+
(0, import_react6.useEffect)(function() {
|
|
1734
1803
|
form.onFieldFocus = onFieldFocus;
|
|
1735
1804
|
}, [
|
|
1736
1805
|
form,
|
|
1737
1806
|
onFieldFocus
|
|
1738
1807
|
]);
|
|
1739
|
-
(0,
|
|
1808
|
+
(0, import_react6.useEffect)(function() {
|
|
1740
1809
|
form.onFieldSubmit = onFieldSubmit;
|
|
1741
1810
|
}, [
|
|
1742
1811
|
form,
|
|
@@ -1769,6 +1838,9 @@ var MantineFormImpl = class {
|
|
|
1769
1838
|
__publicField(this, "listCache", new import_base6.Cache(
|
|
1770
1839
|
createList.bind(this)
|
|
1771
1840
|
));
|
|
1841
|
+
__publicField(this, "fieldViewCache", new import_base6.Cache(
|
|
1842
|
+
createFieldView.bind(this)
|
|
1843
|
+
));
|
|
1772
1844
|
__publicField(this, "fieldsViewCache", new import_base6.Cache(
|
|
1773
1845
|
createFieldsView.bind(this)
|
|
1774
1846
|
));
|
|
@@ -1836,6 +1908,11 @@ var MantineFormImpl = class {
|
|
|
1836
1908
|
DefaultList
|
|
1837
1909
|
);
|
|
1838
1910
|
}
|
|
1911
|
+
fieldView(valuePath) {
|
|
1912
|
+
return this.fieldViewCache.retrieveOrCreate(
|
|
1913
|
+
valuePath
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1839
1916
|
fieldsView(valuePath, FieldsView) {
|
|
1840
1917
|
return this.fieldsViewCache.retrieveOrCreate(
|
|
1841
1918
|
valuePath,
|
|
@@ -1901,7 +1978,6 @@ function mergeValidators(validators1, validators2) {
|
|
|
1901
1978
|
AbstractSelectValueTypeConverter,
|
|
1902
1979
|
DefaultErrorRenderer,
|
|
1903
1980
|
Empty,
|
|
1904
|
-
FieldView,
|
|
1905
1981
|
FormModel,
|
|
1906
1982
|
IntegerToStringConverter,
|
|
1907
1983
|
NullableToBooleanConverter,
|