@strictly/react-form 0.0.15 → 0.0.16

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.
Files changed (38) hide show
  1. package/.out/core/mobx/field_adapter_builder.d.ts +1 -1
  2. package/.out/core/mobx/form_model.d.ts +3 -4
  3. package/.out/core/mobx/form_model.js +27 -23
  4. package/.out/core/mobx/specs/form_model.tests.js +18 -8
  5. package/.out/core/mobx/types.d.ts +4 -4
  6. package/.out/index.d.ts +0 -1
  7. package/.out/index.js +0 -1
  8. package/.out/mantine/create_field_view.d.ts +20 -0
  9. package/.out/mantine/create_field_view.js +54 -0
  10. package/.out/mantine/create_list.js +3 -2
  11. package/.out/mantine/hooks.d.ts +4 -1
  12. package/.out/mantine/hooks.js +13 -1
  13. package/.out/mantine/specs/field_view_hooks.stories.d.ts +12 -0
  14. package/.out/mantine/specs/field_view_hooks.stories.js +61 -0
  15. package/.out/mantine/specs/field_view_hooks.tests.d.ts +1 -0
  16. package/.out/mantine/specs/field_view_hooks.tests.js +12 -0
  17. package/.out/tsconfig.tsbuildinfo +1 -1
  18. package/.turbo/turbo-build.log +8 -8
  19. package/.turbo/turbo-check-types.log +1 -1
  20. package/core/mobx/field_adapter_builder.ts +2 -2
  21. package/core/mobx/form_model.ts +43 -27
  22. package/core/mobx/specs/form_model.tests.ts +28 -11
  23. package/core/mobx/types.ts +4 -4
  24. package/dist/index.cjs +124 -70
  25. package/dist/index.d.cts +26 -26
  26. package/dist/index.d.ts +26 -26
  27. package/dist/index.js +121 -62
  28. package/index.ts +0 -1
  29. package/mantine/create_field_view.tsx +94 -0
  30. package/mantine/create_list.tsx +9 -2
  31. package/mantine/hooks.tsx +18 -1
  32. package/mantine/specs/__snapshots__/field_view_hooks.tests.tsx.snap +153 -0
  33. package/mantine/specs/field_view_hooks.stories.tsx +112 -0
  34. package/mantine/specs/field_view_hooks.tests.tsx +15 -0
  35. package/package.json +1 -1
  36. package/.out/mantine/field_view.d.ts +0 -18
  37. package/.out/mantine/field_view.js +0 -16
  38. 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,8 +356,8 @@ 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, _context_dec, _errors_dec, _fieldOverrides_dec, _value_dec, _init, _value, _fieldOverrides, _errors;
361
- _value_dec = [import_mobx.observable.ref], _fieldOverrides_dec = [import_mobx.observable.shallow], _errors_dec = [import_mobx.observable.shallow], _context_dec = [import_mobx.computed.struct], _fields_dec = [import_mobx.computed], _knownFields_dec = [import_mobx.computed], _accessors_dec = [import_mobx.computed];
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
362
  constructor(type, value, adapters) {
364
363
  this.type = type;
@@ -370,13 +369,13 @@ var FormModel = class {
370
369
  __publicField(this, "flattenedTypeDefs");
371
370
  this.value = (0, import_define.mobxCopy)(type, value);
372
371
  this.flattenedTypeDefs = (0, import_define.flattenTypesOfType)(type);
373
- const contextValue = this.toContext(value);
374
372
  const conversions = (0, import_define.flattenValueTo)(
375
373
  type,
376
374
  this.value,
377
375
  () => {
378
376
  },
379
- (_t, value2, _setter, typePath, valuePath) => {
377
+ (_t, fieldValue, _setter, typePath, valuePath) => {
378
+ const contextValue = this.toContext(value, valuePath);
380
379
  const adapter2 = this.adapters[typePath];
381
380
  if (adapter2 == null) {
382
381
  return;
@@ -388,16 +387,13 @@ var FormModel = class {
388
387
  if (revert == null) {
389
388
  return;
390
389
  }
391
- return convert(value2, valuePath, contextValue);
390
+ return convert(fieldValue, valuePath, contextValue);
392
391
  }
393
392
  );
394
393
  this.fieldOverrides = (0, import_base2.map)(conversions, function(_k, v) {
395
394
  return v && [v.value];
396
395
  });
397
396
  }
398
- get context() {
399
- return this.toContext(this.value);
400
- }
401
397
  get fields() {
402
398
  return new Proxy(
403
399
  this.knownFields,
@@ -457,6 +453,7 @@ var FormModel = class {
457
453
  const fieldOverride = this.fieldOverrides[valuePath];
458
454
  const accessor = this.getAccessorForValuePath(valuePath);
459
455
  const fieldTypeDef = this.flattenedTypeDefs[typePath];
456
+ const context = this.toContext(this.value, valuePath);
460
457
  const {
461
458
  value,
462
459
  required,
@@ -465,11 +462,11 @@ var FormModel = class {
465
462
  accessor != null ? accessor.value : fieldTypeDef != null ? (0, import_define.mobxCopy)(
466
463
  fieldTypeDef,
467
464
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
468
- create(valuePath, this.context)
469
- ) : create(valuePath, this.context),
465
+ create(valuePath, context)
466
+ ) : create(valuePath, context),
470
467
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
471
468
  valuePath,
472
- this.context
469
+ context
473
470
  );
474
471
  const error = this.errors[valuePath];
475
472
  return {
@@ -527,7 +524,9 @@ var FormModel = class {
527
524
  const element = elementValue != null ? elementValue[0] : elementAdapter.create(
528
525
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
529
526
  elementTypePath,
530
- this.context
527
+ // TODO what can we use for the value path here?
528
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
529
+ this.toContext(this.value, valuePath)
531
530
  );
532
531
  const originalList = accessor.value;
533
532
  const newList = [
@@ -645,7 +644,7 @@ var FormModel = class {
645
644
  internalSetFieldValue(valuePath, value, displayValidation) {
646
645
  const { revert } = this.getAdapterForValuePath(valuePath);
647
646
  (0, import_base2.assertExists)(revert, "setting value not supported {}", valuePath);
648
- const conversion = revert(value, valuePath, this.context);
647
+ const conversion = revert(value, valuePath, this.toContext(this.value, valuePath));
649
648
  const accessor = this.getAccessorForValuePath(valuePath);
650
649
  return (0, import_mobx.runInAction)(() => {
651
650
  this.fieldOverrides[valuePath] = [value];
@@ -685,10 +684,11 @@ var FormModel = class {
685
684
  convert,
686
685
  create
687
686
  } = adapter2;
688
- const value = create(valuePath, this.context);
687
+ const context = this.toContext(this.value, valuePath);
688
+ const value = create(valuePath, context);
689
689
  const {
690
690
  value: displayValue
691
- } = convert(value, valuePath, this.context);
691
+ } = convert(value, valuePath, context);
692
692
  const key = valuePath;
693
693
  (0, import_mobx.runInAction)(() => {
694
694
  this.fieldOverrides[key] = [displayValue];
@@ -714,13 +714,14 @@ var FormModel = class {
714
714
  } = this.getAdapterForValuePath(valuePath);
715
715
  const fieldOverride = this.fieldOverrides[valuePath];
716
716
  const accessor = this.getAccessorForValuePath(valuePath);
717
+ const context = this.toContext(this.value, valuePath);
717
718
  const {
718
719
  value: storedValue
719
720
  } = convert(
720
- accessor != null ? accessor.value : create(valuePath, this.context),
721
+ accessor != null ? accessor.value : create(valuePath, context),
721
722
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
722
723
  valuePath,
723
- this.context
724
+ context
724
725
  );
725
726
  const value = fieldOverride != null ? fieldOverride[0] : storedValue;
726
727
  const dirty = storedValue !== value;
@@ -728,12 +729,12 @@ var FormModel = class {
728
729
  if (ignoreDefaultValue) {
729
730
  const {
730
731
  value: defaultDisplayValue
731
- } = convert(create(valuePath, this.context), valuePath, this.context);
732
+ } = convert(create(valuePath, context), valuePath, context);
732
733
  if (defaultDisplayValue === value) {
733
734
  return true;
734
735
  }
735
736
  }
736
- const conversion = revert(value, valuePath, this.context);
737
+ const conversion = revert(value, valuePath, context);
737
738
  return (0, import_mobx.runInAction)(() => {
738
739
  switch (conversion.type) {
739
740
  case 1 /* Failure */:
@@ -776,12 +777,13 @@ var FormModel = class {
776
777
  return success;
777
778
  }
778
779
  const fieldOverride = this.fieldOverrides[adapterPath];
780
+ const context = this.toContext(this.value, valuePath);
779
781
  const {
780
782
  value: storedValue
781
- } = convert(accessor.value, valuePath, this.context);
783
+ } = convert(accessor.value, valuePath, context);
782
784
  const value = fieldOverride != null ? fieldOverride[0] : storedValue;
783
785
  const dirty = fieldOverride != null && fieldOverride[0] !== storedValue;
784
- const conversion = revert(value, valuePath, this.context);
786
+ const conversion = revert(value, valuePath, context);
785
787
  switch (conversion.type) {
786
788
  case 1 /* Failure */:
787
789
  this.errors[adapterPath] = conversion.error;
@@ -811,7 +813,6 @@ _errors = new WeakMap();
811
813
  __decorateElement(_init, 4, "value", _value_dec, FormModel, _value);
812
814
  __decorateElement(_init, 4, "fieldOverrides", _fieldOverrides_dec, FormModel, _fieldOverrides);
813
815
  __decorateElement(_init, 4, "errors", _errors_dec, FormModel, _errors);
814
- __decorateElement(_init, 2, "context", _context_dec, FormModel);
815
816
  __decorateElement(_init, 2, "fields", _fields_dec, FormModel);
816
817
  __decorateElement(_init, 2, "knownFields", _knownFields_dec, FormModel);
817
818
  __decorateElement(_init, 2, "accessors", _accessors_dec, FormModel);
@@ -1167,49 +1168,21 @@ function DefaultErrorRenderer({
1167
1168
  return JSON.stringify(error);
1168
1169
  }
1169
1170
 
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
1171
  // mantine/hooks.tsx
1199
1172
  var import_core = require("@mantine/core");
1200
1173
  var import_base6 = require("@strictly/base");
1201
1174
  var import_mobx2 = require("mobx");
1202
- var import_react4 = require("react");
1175
+ var import_react6 = require("react");
1203
1176
 
1204
1177
  // util/partial.tsx
1205
- var import_mobx_react2 = require("mobx-react");
1178
+ var import_mobx_react = require("mobx-react");
1206
1179
  var import_react2 = require("react");
1207
- var import_jsx_runtime2 = require("react/jsx-runtime");
1180
+ var import_jsx_runtime = require("react/jsx-runtime");
1208
1181
  function createSimplePartialComponent(Component, curriedProps) {
1209
1182
  return (0, import_react2.forwardRef)(
1210
1183
  function(exposedProps, ref) {
1211
1184
  const C = Component;
1212
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1185
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1213
1186
  C,
1214
1187
  __spreadValues(__spreadValues({
1215
1188
  ref
@@ -1249,7 +1222,7 @@ function createPartialComponent(Component, curriedPropsSource, additionalPropKey
1249
1222
  ]
1250
1223
  );
1251
1224
  const curriedProps = curriedPropsSource(additionalProps);
1252
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1225
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1253
1226
  C,
1254
1227
  __spreadValues(__spreadValues({
1255
1228
  ref
@@ -1285,7 +1258,7 @@ function createPartialObserverComponent(Component, curriedPropsSource, additiona
1285
1258
  );
1286
1259
  }
1287
1260
  function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
1288
- return (0, import_mobx_react2.observer)(
1261
+ return (0, import_mobx_react.observer)(
1289
1262
  (0, import_react2.forwardRef)(
1290
1263
  function(props, ref) {
1291
1264
  const C = Component;
@@ -1316,7 +1289,7 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
1316
1289
  ]
1317
1290
  );
1318
1291
  const curriedProps = curriedPropsSource(additionalProps);
1319
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1292
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1320
1293
  C,
1321
1294
  __spreadValues(__spreadValues({
1322
1295
  ref
@@ -1347,7 +1320,7 @@ function usePartialObserverComponent(curriedPropsSource, deps, Component, additi
1347
1320
  }
1348
1321
 
1349
1322
  // mantine/create_checkbox.tsx
1350
- var import_jsx_runtime3 = require("react/jsx-runtime");
1323
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1351
1324
  function createCheckbox(valuePath, Checkbox) {
1352
1325
  const onChange = (e) => {
1353
1326
  var _a;
@@ -1384,7 +1357,7 @@ function createCheckbox(valuePath, Checkbox) {
1384
1357
  checked: value,
1385
1358
  disabled: readonly,
1386
1359
  required,
1387
- error: error && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorRenderer, { error }),
1360
+ error: error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ErrorRenderer, { error }),
1388
1361
  onChange,
1389
1362
  onFocus,
1390
1363
  onBlur,
@@ -1398,6 +1371,78 @@ function createCheckbox(valuePath, Checkbox) {
1398
1371
  );
1399
1372
  }
1400
1373
 
1374
+ // mantine/create_field_view.tsx
1375
+ var import_mobx_react2 = require("mobx-react");
1376
+ var import_react3 = require("react");
1377
+
1378
+ // util/empty.tsx
1379
+ function Empty() {
1380
+ return null;
1381
+ }
1382
+
1383
+ // mantine/create_field_view.tsx
1384
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1385
+ function FieldView({
1386
+ valuePath,
1387
+ form,
1388
+ children
1389
+ }) {
1390
+ const onFocus = (0, import_react3.useCallback)(() => {
1391
+ var _a;
1392
+ (_a = form.onFieldFocus) == null ? void 0 : _a.call(form, valuePath);
1393
+ }, [
1394
+ form,
1395
+ valuePath
1396
+ ]);
1397
+ const onBlur = (0, import_react3.useCallback)(() => {
1398
+ var _a;
1399
+ (_a = form.onFieldBlur) == null ? void 0 : _a.call(form, valuePath);
1400
+ }, [
1401
+ form,
1402
+ valuePath
1403
+ ]);
1404
+ const onValueChange = (0, import_react3.useCallback)((value) => {
1405
+ var _a;
1406
+ (_a = form.onFieldValueChange) == null ? void 0 : _a.call(form, valuePath, value);
1407
+ }, [
1408
+ form,
1409
+ valuePath
1410
+ ]);
1411
+ const onSubmit = (0, import_react3.useCallback)(() => {
1412
+ var _a;
1413
+ (_a = form.onFieldSubmit) == null ? void 0 : _a.call(form, valuePath);
1414
+ }, [
1415
+ form,
1416
+ valuePath
1417
+ ]);
1418
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_mobx_react2.Observer, { children: () => {
1419
+ const {
1420
+ value,
1421
+ error
1422
+ } = form.fields[valuePath];
1423
+ return children({
1424
+ value,
1425
+ error,
1426
+ ErrorSink: Empty,
1427
+ onFocus,
1428
+ onBlur,
1429
+ onValueChange,
1430
+ onSubmit
1431
+ });
1432
+ } });
1433
+ }
1434
+ function createFieldView(valuePath) {
1435
+ return (props) => {
1436
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1437
+ FieldView,
1438
+ __spreadValues({
1439
+ form: this,
1440
+ valuePath
1441
+ }, props)
1442
+ );
1443
+ };
1444
+ }
1445
+
1401
1446
  // mantine/create_fields_view.tsx
1402
1447
  var import_define6 = require("@strictly/define");
1403
1448
  var import_mobx_react3 = require("mobx-react");
@@ -1465,12 +1510,12 @@ function createFieldsView(valuePath, FieldsView, observableProps) {
1465
1510
 
1466
1511
  // mantine/create_form.tsx
1467
1512
  var import_mobx_react4 = require("mobx-react");
1468
- var import_react3 = require("react");
1513
+ var import_react4 = require("react");
1469
1514
  var import_jsx_runtime5 = require("react/jsx-runtime");
1470
1515
  function createForm(valuePath, Form, observableProps) {
1471
1516
  return (0, import_mobx_react4.observer)((props) => {
1472
1517
  const { value } = observableProps.fields[valuePath];
1473
- const onValueChange = (0, import_react3.useCallback)((value2) => {
1518
+ const onValueChange = (0, import_react4.useCallback)((value2) => {
1474
1519
  observableProps.onFieldValueChange(valuePath, value2);
1475
1520
  }, []);
1476
1521
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -1484,6 +1529,7 @@ function createForm(valuePath, Form, observableProps) {
1484
1529
  }
1485
1530
 
1486
1531
  // mantine/create_list.tsx
1532
+ var import_react5 = require("react");
1487
1533
  var import_jsx_runtime6 = require("react/jsx-runtime");
1488
1534
  function createList(valuePath, List) {
1489
1535
  const propSource = () => {
@@ -1502,7 +1548,7 @@ function DefaultList({
1502
1548
  }) {
1503
1549
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: values.map(function(value, index) {
1504
1550
  const valuePath = `${listPath}.${index}`;
1505
- return children(valuePath, value, index);
1551
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react5.Fragment, { children: children(valuePath, value, index) }, valuePath);
1506
1552
  }) });
1507
1553
  }
1508
1554
 
@@ -1701,8 +1747,9 @@ function useMantineFormFields({
1701
1747
  onFieldFocus,
1702
1748
  onFieldSubmit,
1703
1749
  fields
1750
+ // should use FieldView rather than observing fields directly from here
1704
1751
  }) {
1705
- const form = (0, import_react4.useMemo)(
1752
+ const form = (0, import_react6.useMemo)(
1706
1753
  function() {
1707
1754
  return new MantineFormImpl(fields);
1708
1755
  },
@@ -1710,7 +1757,7 @@ function useMantineFormFields({
1710
1757
  // eslint-disable-next-line react-hooks/exhaustive-deps
1711
1758
  []
1712
1759
  );
1713
- (0, import_react4.useEffect)(function() {
1760
+ (0, import_react6.useEffect)(function() {
1714
1761
  (0, import_mobx2.runInAction)(function() {
1715
1762
  form.fields = fields;
1716
1763
  });
@@ -1718,25 +1765,25 @@ function useMantineFormFields({
1718
1765
  form,
1719
1766
  fields
1720
1767
  ]);
1721
- (0, import_react4.useEffect)(function() {
1768
+ (0, import_react6.useEffect)(function() {
1722
1769
  form.onFieldValueChange = onFieldValueChange;
1723
1770
  }, [
1724
1771
  form,
1725
1772
  onFieldValueChange
1726
1773
  ]);
1727
- (0, import_react4.useEffect)(function() {
1774
+ (0, import_react6.useEffect)(function() {
1728
1775
  form.onFieldBlur = onFieldBlur;
1729
1776
  }, [
1730
1777
  form,
1731
1778
  onFieldBlur
1732
1779
  ]);
1733
- (0, import_react4.useEffect)(function() {
1780
+ (0, import_react6.useEffect)(function() {
1734
1781
  form.onFieldFocus = onFieldFocus;
1735
1782
  }, [
1736
1783
  form,
1737
1784
  onFieldFocus
1738
1785
  ]);
1739
- (0, import_react4.useEffect)(function() {
1786
+ (0, import_react6.useEffect)(function() {
1740
1787
  form.onFieldSubmit = onFieldSubmit;
1741
1788
  }, [
1742
1789
  form,
@@ -1769,6 +1816,9 @@ var MantineFormImpl = class {
1769
1816
  __publicField(this, "listCache", new import_base6.Cache(
1770
1817
  createList.bind(this)
1771
1818
  ));
1819
+ __publicField(this, "fieldViewCache", new import_base6.Cache(
1820
+ createFieldView.bind(this)
1821
+ ));
1772
1822
  __publicField(this, "fieldsViewCache", new import_base6.Cache(
1773
1823
  createFieldsView.bind(this)
1774
1824
  ));
@@ -1836,6 +1886,11 @@ var MantineFormImpl = class {
1836
1886
  DefaultList
1837
1887
  );
1838
1888
  }
1889
+ fieldView(valuePath) {
1890
+ return this.fieldViewCache.retrieveOrCreate(
1891
+ valuePath
1892
+ );
1893
+ }
1839
1894
  fieldsView(valuePath, FieldsView) {
1840
1895
  return this.fieldsViewCache.retrieveOrCreate(
1841
1896
  valuePath,
@@ -1901,7 +1956,6 @@ function mergeValidators(validators1, validators2) {
1901
1956
  AbstractSelectValueTypeConverter,
1902
1957
  DefaultErrorRenderer,
1903
1958
  Empty,
1904
- FieldView,
1905
1959
  FormModel,
1906
1960
  IntegerToStringConverter,
1907
1961
  NullableToBooleanConverter,
package/dist/index.d.cts CHANGED
@@ -73,7 +73,7 @@ declare function adapterFromPrototype<From, To, ValuePath extends string, Contex
73
73
  declare function adapterFromPrototype<From, To, E, ValuePath extends string, Context>(converter: TwoWayFieldConverter<From, To, E, ValuePath, Context>, prototype: From): FieldAdapterBuilder<From, To, E, ValuePath, Context>;
74
74
  declare function identityAdapter<V, ValuePath extends string, Context>(prototype: V, required?: boolean): FieldAdapterBuilder<V, V, never, ValuePath, Context>;
75
75
  declare function trimmingStringAdapter<ValuePath extends string, Context>(): FieldAdapterBuilder<string, string, never, ValuePath, Context>;
76
- declare function listAdapter<E, ValuePath extends string, Context>(): FieldAdapterBuilder<readonly E[], readonly E[], never, ValuePath, Context>;
76
+ declare function listAdapter<E, ValuePath extends string = string, Context = unknown>(): FieldAdapterBuilder<readonly E[], readonly E[], never, ValuePath, Context>;
77
77
 
78
78
  type FieldAdaptersOfValues<FlattenedValues extends Readonly<Record<string, any>>, TypePathsToValuePaths extends Readonly<Record<keyof FlattenedValues, string>> = Readonly<Record<keyof FlattenedValues, any>>, Context = any> = {
79
79
  readonly [K in keyof FlattenedValues]: FieldAdapter<FlattenedValues[K], any, any, TypePathsToValuePaths[K], Context>;
@@ -119,8 +119,8 @@ type ValuePathsToAdaptersOf<TypePathsToAdapters extends Partial<Readonly<Record<
119
119
  readonly [K in keyof ValuePathsToTypePaths as unknown extends TypePathsToAdapters[ValuePathsToTypePaths[K]] ? never : K]: NonNullable<TypePathsToAdapters[ValuePathsToTypePaths[K]]>;
120
120
  } : never;
121
121
  type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, FieldAdapter>>>> = UnionToIntersection<{
122
- readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
123
- }[keyof TypePathsToAdapters]>;
122
+ readonly [K in keyof TypePathsToAdapters]: TypePathsToAdapters[K] extends undefined ? undefined : unknown extends ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>> ? never : ContextOfFieldAdapter<NonNullable<TypePathsToAdapters[K]>>;
123
+ }[keyof TypePathsToAdapters] | {}>;
124
124
  declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readonly<Record<string, string>>, TypePathsToAdapters extends FlattenedTypePathsToAdaptersOf<FlattenedValuesOfType<T, '*'>, ContextType>, ContextType = ContextOf<TypePathsToAdapters>, ValuePathsToAdapters extends ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths> = ValuePathsToAdaptersOf<TypePathsToAdapters, ValueToTypePaths>> {
125
125
  readonly type: T;
126
126
  protected readonly adapters: TypePathsToAdapters;
@@ -129,8 +129,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
129
129
  accessor errors: FlattenedErrors<ValuePathsToAdapters>;
130
130
  private readonly flattenedTypeDefs;
131
131
  constructor(type: T, value: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters);
132
- get context(): ContextType;
133
- protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>): ContextType;
132
+ protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
134
133
  get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
135
134
  private get knownFields();
136
135
  private maybeSynthesizeFieldByValuePath;
@@ -154,18 +153,18 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
154
153
  }
155
154
 
156
155
  /**
157
- * Used to extract the supported value paths from a presenter
156
+ * Used to extract the supported value paths from a model
158
157
  */
159
158
  type ValuePathsOfModel<Model extends FormModel<any, any, any, any, any>> = Model extends FormModel<infer _1, infer _2, infer _3, infer _4, infer ValuePathsToAdapters> ? keyof ValuePathsToAdapters : never;
160
159
  /**
161
160
  * Used to extract the render type (so the value that is passed to the view) of a given value path
162
- * from a presenter
161
+ * from a model
163
162
  */
164
163
  type ToValueOfModelValuePath<Model extends FormModel<any, any, any, any, any>, K extends ValuePathsOfModel<Model>> = Model extends FormModel<infer _1, infer _2, infer _3, infer _4, infer ValuePathsToAdapters> ? ToOfFieldAdapter<ValuePathsToAdapters[K]> : never;
165
164
  /**
166
- * Extracts the form fields from the presenter. The recommended way is to
165
+ * Extracts the form fields from a form model. The recommended way is to
167
166
  * define the form fields explicitly and use that type to enforce the types
168
- * of your converters, but generating the FormFields from your presenter
167
+ * of your converters, but generating the FormFields from your model
169
168
  * is less typing, albeit at the cost of potentially getting type errors
170
169
  * reported a long way away from the source
171
170
  */
@@ -286,21 +285,6 @@ declare function DefaultErrorRenderer({ error, }: InternalErrorRendererProps<any
286
285
 
287
286
  type ValueTypeOfField<F extends Field> = F extends Field<infer V> ? V : never;
288
287
 
289
- /**
290
- * Displays current value and error of a field
291
- */
292
- declare function FieldView<F extends Fields, K extends keyof F>({ fields, valuePath, children, }: {
293
- fields: F;
294
- valuePath: K;
295
- children: (props: {
296
- value: ValueTypeOfField<F[K]>;
297
- error: ErrorOfField<F[K]> | undefined;
298
- ErrorSink: ComponentType<{
299
- error: ErrorOfField<F[K]>;
300
- }>;
301
- }) => JSX.Element;
302
- }): react_jsx_runtime.JSX.Element;
303
-
304
288
  type AllFieldsOfFields<F extends Fields> = {
305
289
  [K in keyof F as ValueTypeOfField<F[K]> extends any ? K : never]: F[K];
306
290
  };
@@ -353,6 +337,20 @@ type MantineFieldComponent<T, P = T, E = any> = UnsafePartialComponent<Component
353
337
 
354
338
  type SuppliedCheckboxProps = Pick<CheckboxProps, 'name' | 'checked' | 'disabled' | 'required' | 'error' | 'onChange' | 'onFocus' | 'onBlur' | 'onKeyUp'>;
355
339
 
340
+ type FieldViewProps<F extends Fields, K extends keyof F> = {
341
+ children: (props: {
342
+ value: ValueTypeOfField<F[K]>;
343
+ error: ErrorOfField<F[K]> | undefined;
344
+ ErrorSink: ComponentType<{
345
+ error: ErrorOfField<F[K]>;
346
+ }>;
347
+ onFocus: () => void;
348
+ onBlur: () => void;
349
+ onValueChange: (v: ValueTypeOfField<F[K]>) => void;
350
+ onSubmit: () => void;
351
+ }) => JSX.Element;
352
+ };
353
+
356
354
  type CallbackMapper<ValuePath extends string> = {
357
355
  <Cb extends (...args: any[]) => any>(cb: Cb): Parameters<Cb> extends [infer SubFormValuePath extends string, ...(infer Rest)] ? SubFormValuePath extends StringConcatOf<ValuePath, infer Postfix> ? (valuePath: `$${Postfix}`, ...rest: Rest) => ReturnType<Cb> : never : never;
358
356
  };
@@ -403,7 +401,7 @@ type SuppliedValueInputProps<V, T extends Element = Element> = Partial<{
403
401
  declare function SimpleSelect(props: SelectProps & {
404
402
  onChange?: (value: string | null) => void;
405
403
  }): react_jsx_runtime.JSX.Element;
406
- declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): MantineFormImpl<F>;
404
+ declare function useMantineFormFields<F extends Fields>({ onFieldValueChange, onFieldBlur, onFieldFocus, onFieldSubmit, fields, }: FieldsViewProps<F>): Omit<MantineFormImpl<F>, 'fields'>;
407
405
  declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
408
406
  private readonly textInputCache;
409
407
  private readonly valueInputCache;
@@ -412,6 +410,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
412
410
  private readonly radioCache;
413
411
  private readonly pillCache;
414
412
  private readonly listCache;
413
+ private readonly fieldViewCache;
415
414
  private readonly fieldsViewCache;
416
415
  private readonly formCache;
417
416
  accessor fields: F;
@@ -433,6 +432,7 @@ declare class MantineFormImpl<F extends Fields> implements MantineForm<F> {
433
432
  pill<K extends keyof AllFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedPillProps, PillProps, ErrorOfField<F[K]>>;
434
433
  pill<K extends keyof AllFieldsOfFields<F>, P extends SuppliedPillProps>(valuePath: K, Pill: ComponentType<P>): MantineFieldComponent<SuppliedPillProps, P, ErrorOfField<F[K]>>;
435
434
  list<K extends keyof ListFieldsOfFields<F>>(valuePath: K): MantineFieldComponent<SuppliedListProps<`${K}.${number}`>, ComponentProps<typeof DefaultList<ElementOfArray<F[K]['value']>, K>>, never>;
435
+ fieldView<K extends keyof AllFieldsOfFields<F>>(valuePath: K): ComponentType<FieldViewProps<F, K>>;
436
436
  fieldsView<K extends keyof AllFieldsOfFields<F>, P extends FieldsViewProps<Fields> = FieldsViewProps<SubFormFields<F, K>>>(valuePath: K, FieldsView: ComponentType<P>): FieldsView<K, MantineFieldComponent<FieldsViewProps<P['fields']>, P, never>>;
437
437
  form<K extends keyof AllFieldsOfFields<F>, P extends FormProps<ValueTypeOfField<F[K]>> = FormProps<ValueTypeOfField<F[K]>>>(valuePath: K, Form: ComponentType<P>): MantineFieldComponent<FormProps<ValueTypeOfField<F[K]>>, P, never>;
438
438
  }
@@ -445,4 +445,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
445
445
 
446
446
  declare function Empty(): null;
447
447
 
448
- export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, type ContextOf, type ContextOfFieldAdapter, DefaultErrorRenderer, Empty, type ErrorOfField, type ErrorOfFieldAdapter, type ErrorRenderer, type ErrorRendererProps, type Field, type FieldAdapter, type FieldAdaptersOfValues, type FieldValueFactory, FieldView, type Fields, type FieldsViewProps, type FlattenedAdaptersOfFields, type FlattenedConvertedFieldsOf, type FlattenedTypePathsToAdaptersOf, type FormFieldsOfFieldAdapters, type FormFieldsOfModel, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, type ToValueOfModelValuePath, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, type ValuePathOfFieldAdapter, type ValuePathsOfModel, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
448
+ export { AbstractSelectValueTypeConverter, type AnnotatedFieldConversion, type AnnotatedFieldConverter, type Annotation, type ContextOf, type ContextOfFieldAdapter, DefaultErrorRenderer, Empty, type ErrorOfField, type ErrorOfFieldAdapter, type ErrorRenderer, type ErrorRendererProps, type Field, type FieldAdapter, type FieldAdaptersOfValues, type FieldValueFactory, type Fields, type FieldsViewProps, type FlattenedAdaptersOfFields, type FlattenedConvertedFieldsOf, type FlattenedTypePathsToAdaptersOf, type FormFieldsOfFieldAdapters, type FormFieldsOfModel, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, type ToValueOfModelValuePath, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, type ValuePathOfFieldAdapter, type ValuePathsOfModel, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };