@strictly/react-form 0.0.31 → 0.0.33

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/dist/index.cjs CHANGED
@@ -110,6 +110,7 @@ __export(index_exports, {
110
110
  mergeAdaptersWithValidators: () => mergeAdaptersWithValidators,
111
111
  mergeFieldAdaptersWithTwoWayConverter: () => mergeFieldAdaptersWithTwoWayConverter,
112
112
  mergeValidators: () => mergeValidators,
113
+ peek: () => peek,
113
114
  prototypingFieldValueFactory: () => prototypingFieldValueFactory,
114
115
  subFormFieldAdapters: () => subFormFieldAdapters,
115
116
  trimmingStringAdapter: () => trimmingStringAdapter,
@@ -363,8 +364,8 @@ var Validation = /* @__PURE__ */ ((Validation2) => {
363
364
  Validation2[Validation2["Always"] = 2] = "Always";
364
365
  return Validation2;
365
366
  })(Validation || {});
366
- var _valueChanged_dec, _dirty_dec, _accessors_dec, _knownFields_dec, _fields_dec, _validation_dec, _errorOverrides_dec, _fieldOverrides_dec, _value_dec, _init, _value, _fieldOverrides, _errorOverrides, _validation;
367
- _value_dec = [import_mobx.observable.ref], _fieldOverrides_dec = [import_mobx.observable.shallow], _errorOverrides_dec = [import_mobx.observable.shallow], _validation_dec = [import_mobx.observable.shallow], _fields_dec = [import_mobx.computed], _knownFields_dec = [import_mobx.computed], _accessors_dec = [import_mobx.computed], _dirty_dec = [import_mobx.computed], _valueChanged_dec = [import_mobx.computed];
367
+ var _validateAll_dec, _validateField_dec, _setFieldValue_dec, _valueChanged_dec, _dirty_dec, _accessors_dec, _knownFields_dec, _fields_dec, _value_dec, _validation_dec, _errorOverrides_dec, _fieldOverrides_dec, _observableValue_dec, _init, _observableValue, _fieldOverrides, _errorOverrides, _validation;
368
+ _observableValue_dec = [import_mobx.observable.ref], _fieldOverrides_dec = [import_mobx.observable.shallow], _errorOverrides_dec = [import_mobx.observable.shallow], _validation_dec = [import_mobx.observable.shallow], _value_dec = [import_mobx.computed], _fields_dec = [import_mobx.computed], _knownFields_dec = [import_mobx.computed], _accessors_dec = [import_mobx.computed], _dirty_dec = [import_mobx.computed], _valueChanged_dec = [import_mobx.computed], _setFieldValue_dec = [import_mobx.action], _validateField_dec = [import_mobx.action], _validateAll_dec = [import_mobx.action];
368
369
  var FormModel = class {
369
370
  constructor(type, originalValue, adapters, mode) {
370
371
  this.type = type;
@@ -372,7 +373,7 @@ var FormModel = class {
372
373
  this.adapters = adapters;
373
374
  this.mode = mode;
374
375
  __runInitializers(_init, 5, this);
375
- __privateAdd(this, _value, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
376
+ __privateAdd(this, _observableValue, __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this);
376
377
  __privateAdd(this, _fieldOverrides, __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
377
378
  __privateAdd(this, _errorOverrides, __runInitializers(_init, 16, this, {})), __runInitializers(_init, 19, this);
378
379
  __privateAdd(this, _validation, __runInitializers(_init, 20, this, {})), __runInitializers(_init, 23, this);
@@ -383,11 +384,11 @@ var FormModel = class {
383
384
  // maintains the value paths of lists when the original order is destroyed by deletes or reordering
384
385
  __publicField(this, "listIndicesToKeys", {});
385
386
  this.originalValues = (0, import_define.flattenValuesOfType)(type, originalValue, this.listIndicesToKeys);
386
- this.value = (0, import_define.mobxCopy)(type, originalValue);
387
+ this.observableValue = (0, import_define.mobxCopy)(type, originalValue);
387
388
  this.flattenedTypeDefs = (0, import_define.flattenTypesOfType)(type);
388
389
  const conversions = (0, import_define.flattenValueTo)(
389
390
  type,
390
- this.value,
391
+ originalValue,
391
392
  () => {
392
393
  },
393
394
  (_t, fieldValue, _setter, typePath, valuePath) => {
@@ -421,6 +422,9 @@ var FormModel = class {
421
422
  throw new import_base2.UnreachableError(this.mode);
422
423
  }
423
424
  }
425
+ get value() {
426
+ return (0, import_define.copy)(this.type, this.observableValue);
427
+ }
424
428
  get fields() {
425
429
  return new Proxy(
426
430
  this.knownFields,
@@ -440,7 +444,7 @@ var FormModel = class {
440
444
  get knownFields() {
441
445
  return (0, import_define.flattenValueTo)(
442
446
  this.type,
443
- this.value,
447
+ this.observableValue,
444
448
  () => {
445
449
  },
446
450
  // TODO swap these to valuePath, typePath in flatten
@@ -482,7 +486,7 @@ var FormModel = class {
482
486
  const fieldOverride = this.fieldOverrides[valuePath];
483
487
  const accessor = this.getAccessorForValuePath(valuePath);
484
488
  const fieldTypeDef = this.flattenedTypeDefs[typePath];
485
- const context = this.toContext(this.value, valuePath);
489
+ const context = this.toContext(this.observableValue, valuePath);
486
490
  const defaultValue = create(valuePath, context);
487
491
  const {
488
492
  value,
@@ -574,9 +578,9 @@ var FormModel = class {
574
578
  get accessors() {
575
579
  return (0, import_define.flattenAccessorsOfType)(
576
580
  this.type,
577
- this.value,
581
+ this.observableValue,
578
582
  (value) => {
579
- this.value = (0, import_define.mobxCopy)(this.type, value);
583
+ this.observableValue = (0, import_define.mobxCopy)(this.type, value);
580
584
  },
581
585
  this.listIndicesToKeys
582
586
  );
@@ -598,7 +602,7 @@ var FormModel = class {
598
602
  });
599
603
  }
600
604
  get valueChanged() {
601
- return !(0, import_define.equals)(this.type, this.value, this.originalValue);
605
+ return !(0, import_define.equals)(this.type, this.observableValue, this.originalValue);
602
606
  }
603
607
  typePath(valuePath) {
604
608
  return (0, import_define.valuePathToTypePath)(this.type, valuePath, true);
@@ -623,7 +627,7 @@ var FormModel = class {
623
627
  elementTypePath,
624
628
  // TODO what can we use for the value path here?
625
629
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
626
- this.toContext(this.value, valuePath)
630
+ this.toContext(this.observableValue, valuePath)
627
631
  );
628
632
  const originalList = accessor.value;
629
633
  const newList = [
@@ -678,7 +682,7 @@ var FormModel = class {
678
682
  internalSetFieldValue(valuePath, value, validation) {
679
683
  const { revert } = this.getAdapterForValuePath(valuePath);
680
684
  (0, import_base2.assertExists)(revert, "setting value not supported {}", valuePath);
681
- const conversion = revert(value, valuePath, this.toContext(this.value, valuePath));
685
+ const conversion = revert(value, valuePath, this.toContext(this.observableValue, valuePath));
682
686
  const accessor = this.getAccessorForValuePath(valuePath);
683
687
  return (0, import_mobx.runInAction)(() => {
684
688
  this.fieldOverrides[valuePath] = [value];
@@ -733,7 +737,7 @@ var FormModel = class {
733
737
  convert,
734
738
  create
735
739
  } = adapter2;
736
- const context = this.toContext(this.value, valuePath);
740
+ const context = this.toContext(this.observableValue, valuePath);
737
741
  const value = create(valuePath, context);
738
742
  const {
739
743
  value: displayValue
@@ -750,11 +754,11 @@ var FormModel = class {
750
754
  this.validation = {};
751
755
  this.fieldOverrides = {};
752
756
  this.errorOverrides = {};
753
- this.value = (0, import_define.mobxCopy)(this.type, value);
757
+ this.observableValue = (0, import_define.mobxCopy)(this.type, value);
754
758
  });
755
759
  }
756
760
  isValuePathActive(valuePath) {
757
- const values = (0, import_define.flattenValuesOfType)(this.type, this.value, this.listIndicesToKeys);
761
+ const values = (0, import_define.flattenValuesOfType)(this.type, this.observableValue, this.listIndicesToKeys);
758
762
  const keys = new Set(Object.keys(values));
759
763
  return keys.has(valuePath);
760
764
  }
@@ -797,18 +801,14 @@ var FormModel = class {
797
801
  return displayedValue !== originalDisplayedValue;
798
802
  }
799
803
  validateField(valuePath, validation = 2 /* Always */) {
800
- (0, import_mobx.runInAction)(() => {
801
- this.validation[valuePath] = validation;
802
- delete this.errorOverrides[valuePath];
803
- });
804
+ this.validation[valuePath] = validation;
805
+ delete this.errorOverrides[valuePath];
804
806
  return this.fields[valuePath].error == null;
805
807
  }
806
808
  validateAll(validation = 2 /* Always */) {
807
809
  const accessors = (0, import_base2.toArray)(this.accessors);
808
- (0, import_mobx.runInAction)(() => {
809
- accessors.forEach(([valuePath]) => {
810
- this.validation[valuePath] = validation;
811
- });
810
+ accessors.forEach(([valuePath]) => {
811
+ this.validation[valuePath] = validation;
812
812
  });
813
813
  return accessors.every(
814
814
  ([valuePath]) => {
@@ -822,30 +822,48 @@ var FormModel = class {
822
822
  }
823
823
  };
824
824
  _init = __decoratorStart(null);
825
- _value = new WeakMap();
825
+ _observableValue = new WeakMap();
826
826
  _fieldOverrides = new WeakMap();
827
827
  _errorOverrides = new WeakMap();
828
828
  _validation = new WeakMap();
829
- __decorateElement(_init, 4, "value", _value_dec, FormModel, _value);
829
+ __decorateElement(_init, 4, "observableValue", _observableValue_dec, FormModel, _observableValue);
830
830
  __decorateElement(_init, 4, "fieldOverrides", _fieldOverrides_dec, FormModel, _fieldOverrides);
831
831
  __decorateElement(_init, 4, "errorOverrides", _errorOverrides_dec, FormModel, _errorOverrides);
832
832
  __decorateElement(_init, 4, "validation", _validation_dec, FormModel, _validation);
833
+ __decorateElement(_init, 2, "value", _value_dec, FormModel);
833
834
  __decorateElement(_init, 2, "fields", _fields_dec, FormModel);
834
835
  __decorateElement(_init, 2, "knownFields", _knownFields_dec, FormModel);
835
836
  __decorateElement(_init, 2, "accessors", _accessors_dec, FormModel);
836
837
  __decorateElement(_init, 2, "dirty", _dirty_dec, FormModel);
837
838
  __decorateElement(_init, 2, "valueChanged", _valueChanged_dec, FormModel);
839
+ __decorateElement(_init, 1, "setFieldValue", _setFieldValue_dec, FormModel);
840
+ __decorateElement(_init, 1, "validateField", _validateField_dec, FormModel);
841
+ __decorateElement(_init, 1, "validateAll", _validateAll_dec, FormModel);
838
842
  __decoratorMetadata(_init, FormModel);
839
843
 
840
844
  // core/mobx/hooks.tsx
841
845
  var import_react = require("react");
846
+
847
+ // core/mobx/peek.ts
848
+ var import_mobx2 = require("mobx");
849
+ function peek(operation) {
850
+ let result;
851
+ void (0, import_mobx2.when)(() => {
852
+ result = operation();
853
+ return true;
854
+ });
855
+ return result;
856
+ }
857
+
858
+ // core/mobx/hooks.tsx
842
859
  function useDefaultMobxFormHooks(model, {
843
860
  onValidFieldSubmit,
844
861
  onValidFormSubmit
845
862
  } = {}) {
846
863
  const onFieldValueChange = (0, import_react.useCallback)(
847
864
  function(path, value) {
848
- const validation = Math.min(model.getValidation(path), 1 /* Changed */);
865
+ const activeValidation = peek(() => model.getValidation(path));
866
+ const validation = Math.min(activeValidation, 1 /* Changed */);
849
867
  model.setFieldValue(path, value, validation);
850
868
  },
851
869
  [model]
@@ -865,8 +883,16 @@ function useDefaultMobxFormHooks(model, {
865
883
  const onFieldBlur = (0, import_react.useCallback)(
866
884
  function(path) {
867
885
  setTimeout(function() {
868
- if (model.isValuePathActive(path) && model.isFieldDirty(path) && model.fields[path].error == null) {
869
- model.validateField(path, Math.max(1 /* Changed */, model.getValidation(path)));
886
+ const [
887
+ validate4,
888
+ activeValidation
889
+ ] = peek(() => [
890
+ model.isValuePathActive(path) && model.isFieldDirty(path) && model.fields[path].error == null,
891
+ model.getValidation(path)
892
+ ]);
893
+ if (validate4) {
894
+ const validation = Math.max(1 /* Changed */, activeValidation);
895
+ model.validateField(path, validation);
870
896
  }
871
897
  }, 100);
872
898
  },
@@ -874,8 +900,10 @@ function useDefaultMobxFormHooks(model, {
874
900
  );
875
901
  const onFormSubmit = (0, import_react.useCallback)(
876
902
  function() {
877
- if (model.validateSubmit()) {
878
- onValidFormSubmit == null ? void 0 : onValidFormSubmit(model.value);
903
+ const valid = peek(() => model.validateSubmit());
904
+ if (valid && onValidFormSubmit) {
905
+ const value = peek(() => model.value);
906
+ onValidFormSubmit(value);
879
907
  }
880
908
  },
881
909
  [
@@ -1191,7 +1219,7 @@ function DefaultErrorRenderer({
1191
1219
  // mantine/hooks.tsx
1192
1220
  var import_core = require("@mantine/core");
1193
1221
  var import_base7 = require("@strictly/base");
1194
- var import_mobx2 = require("mobx");
1222
+ var import_mobx3 = require("mobx");
1195
1223
  var import_react6 = require("react");
1196
1224
 
1197
1225
  // util/Partial.tsx
@@ -1278,36 +1306,36 @@ function createPartialObserverComponent(Component, curriedPropsSource, additiona
1278
1306
  );
1279
1307
  }
1280
1308
  function createUnsafePartialObserverComponent(Component, curriedPropsSource, additionalPropKeys = []) {
1281
- return (0, import_mobx_react.observer)(
1282
- (0, import_react2.forwardRef)(
1283
- function(props, ref) {
1284
- const C = Component;
1285
- const [
1286
- additionalProps,
1287
- exposedProps
1288
- ] = additionalPropKeys.reduce(
1289
- function([
1309
+ return (0, import_react2.forwardRef)(
1310
+ function(props, ref) {
1311
+ const C = Component;
1312
+ const [
1313
+ additionalProps,
1314
+ exposedProps
1315
+ ] = additionalPropKeys.reduce(
1316
+ function([
1317
+ additionalProps2,
1318
+ exposedProps2
1319
+ ], key) {
1320
+ const value = props[
1321
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1322
+ key
1323
+ ];
1324
+ delete exposedProps2[key];
1325
+ additionalProps2[key] = value;
1326
+ return [
1290
1327
  additionalProps2,
1291
1328
  exposedProps2
1292
- ], key) {
1293
- const value = props[
1294
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1295
- key
1296
- ];
1297
- delete exposedProps2[key];
1298
- additionalProps2[key] = value;
1299
- return [
1300
- additionalProps2,
1301
- exposedProps2
1302
- ];
1303
- },
1304
- [
1305
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1306
- {},
1307
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1308
- __spreadValues({}, props)
1309
- ]
1310
- );
1329
+ ];
1330
+ },
1331
+ [
1332
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1333
+ {},
1334
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
1335
+ __spreadValues({}, props)
1336
+ ]
1337
+ );
1338
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mobx_react.Observer, { children: () => {
1311
1339
  const curriedProps = curriedPropsSource(additionalProps);
1312
1340
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1313
1341
  C,
@@ -1315,8 +1343,8 @@ function createUnsafePartialObserverComponent(Component, curriedPropsSource, add
1315
1343
  ref
1316
1344
  }, curriedProps), exposedProps)
1317
1345
  );
1318
- }
1319
- )
1346
+ } });
1347
+ }
1320
1348
  );
1321
1349
  }
1322
1350
  function usePartialObserverComponent(curriedPropsSource, deps, Component, additionalPropKeys = []) {
@@ -1577,7 +1605,7 @@ function DefaultList({
1577
1605
  indexKeys[index]
1578
1606
  ];
1579
1607
  }).filter(function([
1580
- _value2,
1608
+ _value,
1581
1609
  _index,
1582
1610
  key
1583
1611
  ]) {
@@ -1798,7 +1826,7 @@ function useMantineFormFields({
1798
1826
  []
1799
1827
  );
1800
1828
  (0, import_react6.useEffect)(function() {
1801
- (0, import_mobx2.runInAction)(function() {
1829
+ (0, import_mobx3.runInAction)(function() {
1802
1830
  form.fields = fields;
1803
1831
  });
1804
1832
  }, [
@@ -1832,7 +1860,7 @@ function useMantineFormFields({
1832
1860
  return form;
1833
1861
  }
1834
1862
  var _fields_dec2, _init2, _fields;
1835
- _fields_dec2 = [import_mobx2.observable.ref];
1863
+ _fields_dec2 = [import_mobx3.observable.ref];
1836
1864
  var MantineFormImpl = class {
1837
1865
  constructor(fields) {
1838
1866
  __publicField(this, "textInputCache", new import_base7.Cache(
@@ -1949,7 +1977,7 @@ var MantineFormImpl = class {
1949
1977
  this
1950
1978
  );
1951
1979
  }
1952
- // TODO have an option to bind to a Text/(value: T) => JSX.Element for viewing form fields
1980
+ // TODO have an option to bind to a Text/(value: T) => ReactNode for viewing form fields
1953
1981
  };
1954
1982
  _init2 = __decoratorStart(null);
1955
1983
  _fields = new WeakMap();
@@ -2017,6 +2045,7 @@ function mergeValidators(validators1, validators2) {
2017
2045
  mergeAdaptersWithValidators,
2018
2046
  mergeFieldAdaptersWithTwoWayConverter,
2019
2047
  mergeValidators,
2048
+ peek,
2020
2049
  prototypingFieldValueFactory,
2021
2050
  subFormFieldAdapters,
2022
2051
  trimmingStringAdapter,
package/dist/index.d.cts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Maybe, ElementOfArray, StringConcatOf, StringKeyOf as StringKeyOf$1, ExhaustiveArrayOfUnion, FriendlyExhaustiveArrayOfUnion } from '@strictly/base';
2
- import { Type, ValueOfType, ReadonlyTypeOfType, FlattenedTypesOfType, ListTypeDef, FlattenedValuesOfType, MobxValueOfType, Accessor, Validator, UnionTypeDef, ValueTypesOfDiscriminatedUnion, LiteralTypeDef } from '@strictly/define';
2
+ import { Type, ValueOfType, ReadonlyTypeOfType, FlattenedTypesOfType, ListTypeDef, FlattenedValuesOfType, Accessor, Validator, UnionTypeDef, ValueTypesOfDiscriminatedUnion, LiteralTypeDef } from '@strictly/define';
3
3
  import { ValueOf, SimplifyDeep, ReadonlyDeep, UnionToIntersection, StringKeyOf, Simplify } from 'type-fest';
4
4
  import { ComponentType, RefAttributes, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, Ref, DependencyList } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { CheckboxProps, PillProps, RadioProps, RadioGroupProps, TextInputProps, SelectProps } from '@mantine/core';
7
+ import { Observer } from 'mobx-react';
7
8
 
8
9
  declare enum UnreliableFieldConversionType {
9
10
  Success = 0,
@@ -136,7 +137,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
136
137
  private readonly originalValue;
137
138
  protected readonly adapters: TypePathsToAdapters;
138
139
  protected readonly mode: FormMode;
139
- accessor value: MobxValueOfType<T>;
140
+ private accessor observableValue;
140
141
  accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
141
142
  accessor errorOverrides: FlattenedErrorOverrides<ValuePathsToAdapters>;
142
143
  accessor validation: FlattenedValidation<ValuePathsToAdapters>;
@@ -146,6 +147,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
146
147
  constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
147
148
  protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
148
149
  get forceMutableFields(): boolean;
150
+ get value(): ValueOfType<ReadonlyTypeOfType<T>>;
149
151
  get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
150
152
  private get knownFields();
151
153
  private maybeSynthesizeFieldByValuePath;
@@ -210,6 +212,12 @@ type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<K
210
212
  type MergedOfFieldAdapterWithValidator<A extends FieldAdapter, V extends Validator | undefined> = undefined extends V ? A : A extends FieldAdapter<infer From, infer To, infer E1, infer P1, infer C1> ? V extends Validator<From, infer E2, infer P2, infer C2> ? FieldAdapter<From, To, E1 | E2, P1 | P2, C1 & C2> : never : never;
211
213
  declare function mergeAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Readonly<Record<string, Validator>>, Key extends keyof Validators = keyof Validators>(adapters: FieldAdapters, validators: Validators): MergedOfFieldAdaptersWithValidators<FieldAdapters, Validators, Key>;
212
214
 
215
+ /**
216
+ * Used for when you want to look at the value of an observable without observing it (or triggering
217
+ * the mobx runtime linter)
218
+ */
219
+ declare function peek<T>(operation: () => T): T;
220
+
213
221
  type SubFormFieldAdapter<F extends FieldAdapter, ValuePath extends string> = FieldAdapter<FromOfFieldAdapter<F>, ToOfFieldAdapter<F>, ErrorOfFieldAdapter<F>, ValuePathOfFieldAdapter<F> extends StringConcatOf<'$', infer ValuePathSuffix> ? `${ValuePath}${ValuePathSuffix}` : string, ContextOfFieldAdapter<F>>;
214
222
  type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, ValuePath extends string> = {
215
223
  [K in keyof SubAdapters as K extends StringConcatOf<'$', infer TypePathSuffix> ? `${TypePath}${TypePathSuffix}` : never]: SubFormFieldAdapter<SubAdapters[K], ValuePath>;
@@ -369,7 +377,7 @@ type FieldViewProps<F extends Fields, K extends keyof F> = {
369
377
  onBlur: () => void;
370
378
  onValueChange: (v: ValueTypeOfField<F[K]>) => void;
371
379
  onSubmit: () => void;
372
- }) => JSX.Element;
380
+ }) => ReturnType<NonNullable<ComponentProps<typeof Observer>['render']>>;
373
381
  };
374
382
 
375
383
  type SuppliedListProps<Value = any, ListPath extends string = string> = {
@@ -459,4 +467,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
459
467
 
460
468
  declare function Empty(): null;
461
469
 
462
- 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 FormMode, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, type RefOfProps, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, Validation, type ValuePathOfFieldAdapter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
470
+ 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 FormMode, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, type RefOfProps, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, Validation, type ValuePathOfFieldAdapter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, peek, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { Maybe, ElementOfArray, StringConcatOf, StringKeyOf as StringKeyOf$1, ExhaustiveArrayOfUnion, FriendlyExhaustiveArrayOfUnion } from '@strictly/base';
2
- import { Type, ValueOfType, ReadonlyTypeOfType, FlattenedTypesOfType, ListTypeDef, FlattenedValuesOfType, MobxValueOfType, Accessor, Validator, UnionTypeDef, ValueTypesOfDiscriminatedUnion, LiteralTypeDef } from '@strictly/define';
2
+ import { Type, ValueOfType, ReadonlyTypeOfType, FlattenedTypesOfType, ListTypeDef, FlattenedValuesOfType, Accessor, Validator, UnionTypeDef, ValueTypesOfDiscriminatedUnion, LiteralTypeDef } from '@strictly/define';
3
3
  import { ValueOf, SimplifyDeep, ReadonlyDeep, UnionToIntersection, StringKeyOf, Simplify } from 'type-fest';
4
4
  import { ComponentType, RefAttributes, ComponentProps, ForwardRefExoticComponent, PropsWithoutRef, Ref, DependencyList } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { CheckboxProps, PillProps, RadioProps, RadioGroupProps, TextInputProps, SelectProps } from '@mantine/core';
7
+ import { Observer } from 'mobx-react';
7
8
 
8
9
  declare enum UnreliableFieldConversionType {
9
10
  Success = 0,
@@ -136,7 +137,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
136
137
  private readonly originalValue;
137
138
  protected readonly adapters: TypePathsToAdapters;
138
139
  protected readonly mode: FormMode;
139
- accessor value: MobxValueOfType<T>;
140
+ private accessor observableValue;
140
141
  accessor fieldOverrides: FlattenedFieldOverrides<ValuePathsToAdapters>;
141
142
  accessor errorOverrides: FlattenedErrorOverrides<ValuePathsToAdapters>;
142
143
  accessor validation: FlattenedValidation<ValuePathsToAdapters>;
@@ -146,6 +147,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
146
147
  constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
147
148
  protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
148
149
  get forceMutableFields(): boolean;
150
+ get value(): ValueOfType<ReadonlyTypeOfType<T>>;
149
151
  get fields(): SimplifyDeep<FlattenedConvertedFieldsOf<ValuePathsToAdapters>>;
150
152
  private get knownFields();
151
153
  private maybeSynthesizeFieldByValuePath;
@@ -210,6 +212,12 @@ type MergedOfFieldAdaptersWithValidators<FieldAdapters extends Readonly<Record<K
210
212
  type MergedOfFieldAdapterWithValidator<A extends FieldAdapter, V extends Validator | undefined> = undefined extends V ? A : A extends FieldAdapter<infer From, infer To, infer E1, infer P1, infer C1> ? V extends Validator<From, infer E2, infer P2, infer C2> ? FieldAdapter<From, To, E1 | E2, P1 | P2, C1 & C2> : never : never;
211
213
  declare function mergeAdaptersWithValidators<FieldAdapters extends Readonly<Record<Key, FieldAdapter>>, Validators extends Readonly<Record<string, Validator>>, Key extends keyof Validators = keyof Validators>(adapters: FieldAdapters, validators: Validators): MergedOfFieldAdaptersWithValidators<FieldAdapters, Validators, Key>;
212
214
 
215
+ /**
216
+ * Used for when you want to look at the value of an observable without observing it (or triggering
217
+ * the mobx runtime linter)
218
+ */
219
+ declare function peek<T>(operation: () => T): T;
220
+
213
221
  type SubFormFieldAdapter<F extends FieldAdapter, ValuePath extends string> = FieldAdapter<FromOfFieldAdapter<F>, ToOfFieldAdapter<F>, ErrorOfFieldAdapter<F>, ValuePathOfFieldAdapter<F> extends StringConcatOf<'$', infer ValuePathSuffix> ? `${ValuePath}${ValuePathSuffix}` : string, ContextOfFieldAdapter<F>>;
214
222
  type SubFormFieldAdapters<SubAdapters extends Record<string, FieldAdapter>, TypePath extends string, ValuePath extends string> = {
215
223
  [K in keyof SubAdapters as K extends StringConcatOf<'$', infer TypePathSuffix> ? `${TypePath}${TypePathSuffix}` : never]: SubFormFieldAdapter<SubAdapters[K], ValuePath>;
@@ -369,7 +377,7 @@ type FieldViewProps<F extends Fields, K extends keyof F> = {
369
377
  onBlur: () => void;
370
378
  onValueChange: (v: ValueTypeOfField<F[K]>) => void;
371
379
  onSubmit: () => void;
372
- }) => JSX.Element;
380
+ }) => ReturnType<NonNullable<ComponentProps<typeof Observer>['render']>>;
373
381
  };
374
382
 
375
383
  type SuppliedListProps<Value = any, ListPath extends string = string> = {
@@ -459,4 +467,4 @@ declare function mergeValidators<Validators1 extends Partial<Readonly<Record<Key
459
467
 
460
468
  declare function Empty(): null;
461
469
 
462
- 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 FormMode, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, type RefOfProps, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, Validation, type ValuePathOfFieldAdapter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };
470
+ 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 FormMode, FormModel, type FormProps, type FromOfFieldAdapter, IntegerToStringConverter, type MergedOfFieldAdaptersWithTwoWayConverter, type MergedOfFieldAdaptersWithValidators, type MergedOfValidator, type MergedOfValidators, NullableToBooleanConverter, type PartialComponent, type RefOfProps, SelectDiscriminatedUnionConverter, SelectLiteralConverter, SelectStringConverter, type ToOfFieldAdapter, TrimmingStringConverter, type TwoWayFieldConverter, type TwoWayFieldConverterWithValueFactory, type UnreliableFieldConversion, UnreliableFieldConversionType, type UnreliableFieldConverter, type UnsafePartialComponent, Validation, type ValuePathOfFieldAdapter, type ValuePathsToAdaptersOf, adapter, adapterFromPrototype, adapterFromTwoWayConverter, createPartialComponent, createPartialObserverComponent, createSimplePartialComponent, createUnsafePartialObserverComponent, identityAdapter, listAdapter, mergeAdaptersWithValidators, mergeFieldAdaptersWithTwoWayConverter, mergeValidators, peek, prototypingFieldValueFactory, subFormFieldAdapters, trimmingStringAdapter, useDefaultMobxFormHooks, useMantineFormFields, usePartialComponent, usePartialObserverComponent, validatingConverter };