@strictly/react-form 0.0.27 → 0.0.29
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/form_model.d.ts +3 -1
- package/.out/core/mobx/form_model.js +50 -100
- package/.out/core/mobx/specs/form_model.tests.js +14 -12
- package/.out/mantine/create_list.d.ts +2 -1
- package/.out/mantine/create_list.js +15 -3
- package/.out/mantine/specs/list_hooks.stories.js +8 -0
- package/.out/tsconfig.tsbuildinfo +1 -1
- package/.out/types/field.d.ts +1 -0
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-check-types.log +1 -1
- package/core/mobx/form_model.ts +48 -115
- package/core/mobx/specs/form_model.tests.ts +14 -12
- package/dist/index.cjs +80 -115
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +71 -105
- package/mantine/create_list.tsx +27 -3
- package/mantine/specs/__snapshots__/list_hooks.tests.tsx.snap +3 -3
- package/mantine/specs/list_hooks.stories.tsx +8 -0
- package/package.json +1 -1
- package/types/field.ts +1 -0
package/dist/index.cjs
CHANGED
|
@@ -363,11 +363,12 @@ var Validation = /* @__PURE__ */ ((Validation2) => {
|
|
|
363
363
|
Validation2[Validation2["Always"] = 2] = "Always";
|
|
364
364
|
return Validation2;
|
|
365
365
|
})(Validation || {});
|
|
366
|
-
var _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];
|
|
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];
|
|
368
368
|
var FormModel = class {
|
|
369
369
|
constructor(type, originalValue, adapters, mode) {
|
|
370
370
|
this.type = type;
|
|
371
|
+
this.originalValue = originalValue;
|
|
371
372
|
this.adapters = adapters;
|
|
372
373
|
this.mode = mode;
|
|
373
374
|
__runInitializers(_init, 5, this);
|
|
@@ -379,7 +380,9 @@ var FormModel = class {
|
|
|
379
380
|
// cannot be type safe
|
|
380
381
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
381
382
|
__publicField(this, "originalValues");
|
|
382
|
-
|
|
383
|
+
// maintains the value paths of lists when the original order is destroyed by deletes or reordering
|
|
384
|
+
__publicField(this, "listIndicesToKeys", {});
|
|
385
|
+
this.originalValues = (0, import_define.flattenValuesOfType)(type, originalValue, this.listIndicesToKeys);
|
|
383
386
|
this.value = (0, import_define.mobxCopy)(type, originalValue);
|
|
384
387
|
this.flattenedTypeDefs = (0, import_define.flattenTypesOfType)(type);
|
|
385
388
|
const conversions = (0, import_define.flattenValueTo)(
|
|
@@ -401,7 +404,8 @@ var FormModel = class {
|
|
|
401
404
|
return;
|
|
402
405
|
}
|
|
403
406
|
return convert(fieldValue, valuePath, contextValue);
|
|
404
|
-
}
|
|
407
|
+
},
|
|
408
|
+
this.listIndicesToKeys
|
|
405
409
|
);
|
|
406
410
|
this.fieldOverrides = (0, import_base2.map)(conversions, function(_k, v) {
|
|
407
411
|
return v && [v.value];
|
|
@@ -447,7 +451,8 @@ var FormModel = class {
|
|
|
447
451
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
448
452
|
typePath
|
|
449
453
|
);
|
|
450
|
-
}
|
|
454
|
+
},
|
|
455
|
+
this.listIndicesToKeys
|
|
451
456
|
);
|
|
452
457
|
}
|
|
453
458
|
maybeSynthesizeFieldByValuePath(valuePath) {
|
|
@@ -506,7 +511,7 @@ var FormModel = class {
|
|
|
506
511
|
};
|
|
507
512
|
}
|
|
508
513
|
synthesizeFieldByPaths(valuePath, typePath) {
|
|
509
|
-
var _a;
|
|
514
|
+
var _a, _b;
|
|
510
515
|
const field = this.getField(valuePath, typePath);
|
|
511
516
|
if (field == null) {
|
|
512
517
|
return;
|
|
@@ -556,7 +561,10 @@ var FormModel = class {
|
|
|
556
561
|
value: displayedValue,
|
|
557
562
|
error,
|
|
558
563
|
readonly: readonly && !this.forceMutableFields,
|
|
559
|
-
required
|
|
564
|
+
required,
|
|
565
|
+
// make a copy of the index mapping and remove the final value (next id)
|
|
566
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
567
|
+
listIndexToKey: (_b = this.listIndicesToKeys[valuePath]) == null ? void 0 : _b.slice(0, -1)
|
|
560
568
|
};
|
|
561
569
|
}
|
|
562
570
|
getAccessorForValuePath(valuePath) {
|
|
@@ -569,7 +577,8 @@ var FormModel = class {
|
|
|
569
577
|
this.value,
|
|
570
578
|
(value) => {
|
|
571
579
|
this.value = (0, import_define.mobxCopy)(this.type, value);
|
|
572
|
-
}
|
|
580
|
+
},
|
|
581
|
+
this.listIndicesToKeys
|
|
573
582
|
);
|
|
574
583
|
}
|
|
575
584
|
maybeGetAdapterForValuePath(valuePath) {
|
|
@@ -588,6 +597,9 @@ var FormModel = class {
|
|
|
588
597
|
return this.isFieldDirty(valuePath);
|
|
589
598
|
});
|
|
590
599
|
}
|
|
600
|
+
get valueChanged() {
|
|
601
|
+
return !(0, import_define.equals)(this.type, this.value, this.originalValue);
|
|
602
|
+
}
|
|
591
603
|
typePath(valuePath) {
|
|
592
604
|
return (0, import_define.valuePathToTypePath)(this.type, valuePath, true);
|
|
593
605
|
}
|
|
@@ -619,118 +631,50 @@ var FormModel = class {
|
|
|
619
631
|
element,
|
|
620
632
|
...originalList.slice(definedIndex)
|
|
621
633
|
];
|
|
622
|
-
const targetPaths = Object.keys(this.fieldOverrides).filter(function(v) {
|
|
623
|
-
return v.startsWith(`${listValuePath}.`);
|
|
624
|
-
}).map(function(v) {
|
|
625
|
-
const parts = v.substring(listValuePath.length + 1).split(".");
|
|
626
|
-
const index2 = parseInt(parts[0]);
|
|
627
|
-
return [
|
|
628
|
-
index2,
|
|
629
|
-
parts.slice(1)
|
|
630
|
-
];
|
|
631
|
-
}).filter(function([index2]) {
|
|
632
|
-
return index2 >= definedIndex;
|
|
633
|
-
}).sort(function([a], [b]) {
|
|
634
|
-
return b - a;
|
|
635
|
-
});
|
|
636
634
|
(0, import_mobx.runInAction)(() => {
|
|
637
|
-
targetPaths.forEach(([
|
|
638
|
-
index2,
|
|
639
|
-
postfix
|
|
640
|
-
]) => {
|
|
641
|
-
const fromJsonPath = [
|
|
642
|
-
listValuePath,
|
|
643
|
-
`${index2}`,
|
|
644
|
-
...postfix
|
|
645
|
-
].join(".");
|
|
646
|
-
const toJsonPath = [
|
|
647
|
-
listValuePath,
|
|
648
|
-
`${index2 + 1}`,
|
|
649
|
-
...postfix
|
|
650
|
-
].join(".");
|
|
651
|
-
const fieldOverride = this.fieldOverrides[fromJsonPath];
|
|
652
|
-
delete this.fieldOverrides[fromJsonPath];
|
|
653
|
-
this.fieldOverrides[toJsonPath] = fieldOverride;
|
|
654
|
-
const validation = this.validation[fromJsonPath];
|
|
655
|
-
delete this.validation[fromJsonPath];
|
|
656
|
-
this.validation[toJsonPath] = validation;
|
|
657
|
-
});
|
|
658
635
|
accessor.set(newList);
|
|
659
636
|
delete this.fieldOverrides[listValuePath];
|
|
637
|
+
const indicesToKeys = (0, import_base2.assertExistsAndReturn)(
|
|
638
|
+
this.listIndicesToKeys[listValuePath],
|
|
639
|
+
"no index to key mapping for list {}",
|
|
640
|
+
listValuePath
|
|
641
|
+
);
|
|
642
|
+
const nextKey = indicesToKeys[indicesToKeys.length - 1];
|
|
643
|
+
indicesToKeys.splice(definedIndex, 0, nextKey);
|
|
644
|
+
indicesToKeys[indicesToKeys.length - 1] = nextKey + 1;
|
|
660
645
|
});
|
|
661
646
|
}
|
|
662
647
|
removeListItem(...elementValuePaths) {
|
|
663
|
-
const orderedElementValuePaths = elementValuePaths.toSorted().reverse();
|
|
664
648
|
(0, import_mobx.runInAction)(() => {
|
|
665
|
-
|
|
649
|
+
elementValuePaths.forEach((elementValuePath) => {
|
|
650
|
+
var _a;
|
|
666
651
|
const [
|
|
667
652
|
listValuePath,
|
|
668
|
-
|
|
653
|
+
elementKeyString
|
|
669
654
|
] = (0, import_base2.assertExistsAndReturn)(
|
|
670
655
|
(0, import_define.jsonPathPop)(elementValuePath),
|
|
671
656
|
"expected a path with two or more segments {}",
|
|
672
657
|
elementValuePath
|
|
673
658
|
);
|
|
674
659
|
const accessor = this.accessors[listValuePath];
|
|
675
|
-
const
|
|
676
|
-
parseInt(
|
|
677
|
-
"unexpected
|
|
678
|
-
|
|
679
|
-
elementValuePath
|
|
680
|
-
);
|
|
681
|
-
const newList = [...accessor.value];
|
|
682
|
-
(0, import_base2.assertState)(
|
|
683
|
-
elementIndex >= 0 && elementIndex < newList.length,
|
|
684
|
-
"invalid index from path {} ({})",
|
|
685
|
-
elementIndex,
|
|
660
|
+
const elementKey = (0, import_base2.checkValidNumber)(
|
|
661
|
+
parseInt(elementKeyString),
|
|
662
|
+
"unexpected id {} ({})",
|
|
663
|
+
elementKeyString,
|
|
686
664
|
elementValuePath
|
|
687
665
|
);
|
|
688
|
-
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
];
|
|
698
|
-
}).filter(function([index]) {
|
|
699
|
-
return index > elementIndex;
|
|
700
|
-
}).sort(function([a], [b]) {
|
|
701
|
-
return a - b;
|
|
702
|
-
});
|
|
703
|
-
targetPaths.forEach(([
|
|
704
|
-
index,
|
|
705
|
-
postfix
|
|
706
|
-
]) => {
|
|
707
|
-
const fromJsonPath = [
|
|
708
|
-
listValuePath,
|
|
709
|
-
`${index}`,
|
|
710
|
-
...postfix
|
|
711
|
-
].join(".");
|
|
712
|
-
const toJsonPath = [
|
|
713
|
-
listValuePath,
|
|
714
|
-
`${index - 1}`,
|
|
715
|
-
...postfix
|
|
716
|
-
].join(".");
|
|
717
|
-
const fieldOverride = this.fieldOverrides[fromJsonPath];
|
|
718
|
-
delete this.fieldOverrides[fromJsonPath];
|
|
719
|
-
this.fieldOverrides[toJsonPath] = fieldOverride;
|
|
720
|
-
const validation = this.validation[fromJsonPath];
|
|
721
|
-
delete this.validation[fromJsonPath];
|
|
722
|
-
this.validation[toJsonPath] = validation;
|
|
723
|
-
this.moveListItem(fromJsonPath, toJsonPath);
|
|
724
|
-
});
|
|
725
|
-
accessor.set(newList);
|
|
726
|
-
delete this.fieldOverrides[listValuePath];
|
|
666
|
+
const indicesToKeys = this.listIndicesToKeys[listValuePath];
|
|
667
|
+
const elementIndex = (_a = indicesToKeys == null ? void 0 : indicesToKeys.indexOf(elementKey)) != null ? _a : -1;
|
|
668
|
+
if (elementIndex >= 0) {
|
|
669
|
+
const newList = [...accessor.value];
|
|
670
|
+
newList.splice(elementIndex, 1);
|
|
671
|
+
accessor.set(newList);
|
|
672
|
+
delete this.fieldOverrides[listValuePath];
|
|
673
|
+
indicesToKeys.splice(elementIndex, 1);
|
|
674
|
+
}
|
|
727
675
|
});
|
|
728
676
|
});
|
|
729
677
|
}
|
|
730
|
-
moveListItem(fromValuePath, toValuePath) {
|
|
731
|
-
fromValuePath;
|
|
732
|
-
toValuePath;
|
|
733
|
-
}
|
|
734
678
|
internalSetFieldValue(valuePath, value, validation) {
|
|
735
679
|
const { revert } = this.getAdapterForValuePath(valuePath);
|
|
736
680
|
(0, import_base2.assertExists)(revert, "setting value not supported {}", valuePath);
|
|
@@ -810,7 +754,7 @@ var FormModel = class {
|
|
|
810
754
|
});
|
|
811
755
|
}
|
|
812
756
|
isValuePathActive(valuePath) {
|
|
813
|
-
const values = (0, import_define.flattenValuesOfType)(this.type, this.value);
|
|
757
|
+
const values = (0, import_define.flattenValuesOfType)(this.type, this.value, this.listIndicesToKeys);
|
|
814
758
|
const keys = new Set(Object.keys(values));
|
|
815
759
|
return keys.has(valuePath);
|
|
816
760
|
}
|
|
@@ -890,6 +834,7 @@ __decorateElement(_init, 2, "fields", _fields_dec, FormModel);
|
|
|
890
834
|
__decorateElement(_init, 2, "knownFields", _knownFields_dec, FormModel);
|
|
891
835
|
__decorateElement(_init, 2, "accessors", _accessors_dec, FormModel);
|
|
892
836
|
__decorateElement(_init, 2, "dirty", _dirty_dec, FormModel);
|
|
837
|
+
__decorateElement(_init, 2, "valueChanged", _valueChanged_dec, FormModel);
|
|
893
838
|
__decoratorMetadata(_init, FormModel);
|
|
894
839
|
|
|
895
840
|
// core/mobx/hooks.tsx
|
|
@@ -1245,7 +1190,7 @@ function DefaultErrorRenderer({
|
|
|
1245
1190
|
|
|
1246
1191
|
// mantine/hooks.tsx
|
|
1247
1192
|
var import_core = require("@mantine/core");
|
|
1248
|
-
var
|
|
1193
|
+
var import_base7 = require("@strictly/base");
|
|
1249
1194
|
var import_mobx2 = require("mobx");
|
|
1250
1195
|
var import_react6 = require("react");
|
|
1251
1196
|
|
|
@@ -1604,25 +1549,45 @@ function createForm(valuePath, Form, observableProps) {
|
|
|
1604
1549
|
}
|
|
1605
1550
|
|
|
1606
1551
|
// mantine/create_list.tsx
|
|
1552
|
+
var import_base6 = require("@strictly/base");
|
|
1607
1553
|
var import_react5 = require("react");
|
|
1608
1554
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1609
1555
|
function createList(valuePath, List) {
|
|
1610
1556
|
const propSource = () => {
|
|
1611
|
-
const
|
|
1557
|
+
const field = this.fields[valuePath];
|
|
1558
|
+
const values = [...field.value];
|
|
1612
1559
|
return {
|
|
1613
1560
|
values,
|
|
1614
|
-
listPath: valuePath
|
|
1561
|
+
listPath: valuePath,
|
|
1562
|
+
indexKeys: (0, import_base6.assertExistsAndReturn)(field.listIndexToKey, "list index to key mapping missing in {}", valuePath)
|
|
1615
1563
|
};
|
|
1616
1564
|
};
|
|
1617
1565
|
return createUnsafePartialObserverComponent(List, propSource);
|
|
1618
1566
|
}
|
|
1619
1567
|
function DefaultList({
|
|
1620
1568
|
values,
|
|
1569
|
+
indexKeys,
|
|
1621
1570
|
listPath,
|
|
1622
1571
|
children
|
|
1623
1572
|
}) {
|
|
1624
1573
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: values.map(function(value, index) {
|
|
1625
|
-
|
|
1574
|
+
return [
|
|
1575
|
+
value,
|
|
1576
|
+
index,
|
|
1577
|
+
indexKeys[index]
|
|
1578
|
+
];
|
|
1579
|
+
}).filter(function([
|
|
1580
|
+
_value2,
|
|
1581
|
+
_index,
|
|
1582
|
+
key
|
|
1583
|
+
]) {
|
|
1584
|
+
return key != null;
|
|
1585
|
+
}).map(function([
|
|
1586
|
+
value,
|
|
1587
|
+
index,
|
|
1588
|
+
key
|
|
1589
|
+
]) {
|
|
1590
|
+
const valuePath = `${listPath}.${key}`;
|
|
1626
1591
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react5.Fragment, { children: children(valuePath, value, index) }, valuePath);
|
|
1627
1592
|
}) });
|
|
1628
1593
|
}
|
|
@@ -1870,34 +1835,34 @@ var _fields_dec2, _init2, _fields;
|
|
|
1870
1835
|
_fields_dec2 = [import_mobx2.observable.ref];
|
|
1871
1836
|
var MantineFormImpl = class {
|
|
1872
1837
|
constructor(fields) {
|
|
1873
|
-
__publicField(this, "textInputCache", new
|
|
1838
|
+
__publicField(this, "textInputCache", new import_base7.Cache(
|
|
1874
1839
|
createTextInput.bind(this)
|
|
1875
1840
|
));
|
|
1876
|
-
__publicField(this, "valueInputCache", new
|
|
1841
|
+
__publicField(this, "valueInputCache", new import_base7.Cache(
|
|
1877
1842
|
createValueInput.bind(this)
|
|
1878
1843
|
));
|
|
1879
|
-
__publicField(this, "checkboxCache", new
|
|
1844
|
+
__publicField(this, "checkboxCache", new import_base7.Cache(
|
|
1880
1845
|
createCheckbox.bind(this)
|
|
1881
1846
|
));
|
|
1882
|
-
__publicField(this, "radioGroupCache", new
|
|
1847
|
+
__publicField(this, "radioGroupCache", new import_base7.Cache(
|
|
1883
1848
|
createRadioGroup.bind(this)
|
|
1884
1849
|
));
|
|
1885
|
-
__publicField(this, "radioCache", new
|
|
1850
|
+
__publicField(this, "radioCache", new import_base7.Cache(
|
|
1886
1851
|
createRadio.bind(this)
|
|
1887
1852
|
));
|
|
1888
|
-
__publicField(this, "pillCache", new
|
|
1853
|
+
__publicField(this, "pillCache", new import_base7.Cache(
|
|
1889
1854
|
createPill.bind(this)
|
|
1890
1855
|
));
|
|
1891
|
-
__publicField(this, "listCache", new
|
|
1856
|
+
__publicField(this, "listCache", new import_base7.Cache(
|
|
1892
1857
|
createList.bind(this)
|
|
1893
1858
|
));
|
|
1894
|
-
__publicField(this, "fieldViewCache", new
|
|
1859
|
+
__publicField(this, "fieldViewCache", new import_base7.Cache(
|
|
1895
1860
|
createFieldView.bind(this)
|
|
1896
1861
|
));
|
|
1897
|
-
__publicField(this, "fieldsViewCache", new
|
|
1862
|
+
__publicField(this, "fieldsViewCache", new import_base7.Cache(
|
|
1898
1863
|
createFieldsView.bind(this)
|
|
1899
1864
|
));
|
|
1900
|
-
__publicField(this, "formCache", new
|
|
1865
|
+
__publicField(this, "formCache", new import_base7.Cache(createForm.bind(this)));
|
|
1901
1866
|
__privateAdd(this, _fields, __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this);
|
|
1902
1867
|
__publicField(this, "onFieldValueChange");
|
|
1903
1868
|
__publicField(this, "onFieldFocus");
|
package/dist/index.d.cts
CHANGED
|
@@ -84,6 +84,7 @@ type Field<V = any, E = any> = {
|
|
|
84
84
|
readonly error?: E | undefined;
|
|
85
85
|
readonly readonly: boolean;
|
|
86
86
|
readonly required: boolean;
|
|
87
|
+
readonly listIndexToKey?: number[];
|
|
87
88
|
};
|
|
88
89
|
type Fields = Readonly<Record<string, Field>>;
|
|
89
90
|
|
|
@@ -132,6 +133,7 @@ type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, Field
|
|
|
132
133
|
type FormMode = 'edit' | 'create';
|
|
133
134
|
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>> {
|
|
134
135
|
readonly type: T;
|
|
136
|
+
private readonly originalValue;
|
|
135
137
|
protected readonly adapters: TypePathsToAdapters;
|
|
136
138
|
protected readonly mode: FormMode;
|
|
137
139
|
accessor value: MobxValueOfType<T>;
|
|
@@ -140,6 +142,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
140
142
|
accessor validation: FlattenedValidation<ValuePathsToAdapters>;
|
|
141
143
|
private readonly flattenedTypeDefs;
|
|
142
144
|
private readonly originalValues;
|
|
145
|
+
private readonly listIndicesToKeys;
|
|
143
146
|
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
|
|
144
147
|
protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
|
|
145
148
|
get forceMutableFields(): boolean;
|
|
@@ -153,11 +156,11 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
153
156
|
private maybeGetAdapterForValuePath;
|
|
154
157
|
private getAdapterForValuePath;
|
|
155
158
|
get dirty(): boolean;
|
|
159
|
+
get valueChanged(): boolean;
|
|
156
160
|
typePath<K extends keyof ValueToTypePaths>(valuePath: K): ValueToTypePaths[K];
|
|
157
161
|
setFieldValue<K extends keyof ValuePathsToAdapters>(valuePath: K, value: ToOfFieldAdapter<ValuePathsToAdapters[K]>, validation?: Validation): boolean;
|
|
158
162
|
addListItem<K extends keyof FlattenedListTypesOfType<T>>(valuePath: K, elementValue?: Maybe<ElementOfArray<FlattenedValuesOfType<T>[K]>>, index?: number): void;
|
|
159
163
|
removeListItem<K extends keyof FlattenedListTypesOfType<T>>(...elementValuePaths: readonly `${K}.${number}`[]): void;
|
|
160
|
-
protected moveListItem<K extends keyof FlattenedListTypesOfType<T>>(fromValuePath: K, toValuePath: K): void;
|
|
161
164
|
private internalSetFieldValue;
|
|
162
165
|
/**
|
|
163
166
|
* Forces an error onto a field. Error will be removed if the field value changes
|
|
@@ -371,9 +374,10 @@ type FieldsView<ValuePath extends string = string, C extends ComponentType<any>
|
|
|
371
374
|
|
|
372
375
|
type SuppliedListProps<Value = any, ListPath extends string = string> = {
|
|
373
376
|
values: readonly Value[];
|
|
377
|
+
indexKeys: number[];
|
|
374
378
|
listPath: ListPath;
|
|
375
379
|
};
|
|
376
|
-
declare function DefaultList<Value, ListPath extends string>({ values, listPath, children, }: SuppliedListProps<Value, ListPath> & {
|
|
380
|
+
declare function DefaultList<Value, ListPath extends string>({ values, indexKeys, listPath, children, }: SuppliedListProps<Value, ListPath> & {
|
|
377
381
|
children: (valuePath: `${ListPath}.${number}`, value: Value, index: number) => React.ReactNode;
|
|
378
382
|
}): react_jsx_runtime.JSX.Element;
|
|
379
383
|
|
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,7 @@ type Field<V = any, E = any> = {
|
|
|
84
84
|
readonly error?: E | undefined;
|
|
85
85
|
readonly readonly: boolean;
|
|
86
86
|
readonly required: boolean;
|
|
87
|
+
readonly listIndexToKey?: number[];
|
|
87
88
|
};
|
|
88
89
|
type Fields = Readonly<Record<string, Field>>;
|
|
89
90
|
|
|
@@ -132,6 +133,7 @@ type ContextOf<TypePathsToAdapters extends Partial<Readonly<Record<string, Field
|
|
|
132
133
|
type FormMode = 'edit' | 'create';
|
|
133
134
|
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>> {
|
|
134
135
|
readonly type: T;
|
|
136
|
+
private readonly originalValue;
|
|
135
137
|
protected readonly adapters: TypePathsToAdapters;
|
|
136
138
|
protected readonly mode: FormMode;
|
|
137
139
|
accessor value: MobxValueOfType<T>;
|
|
@@ -140,6 +142,7 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
140
142
|
accessor validation: FlattenedValidation<ValuePathsToAdapters>;
|
|
141
143
|
private readonly flattenedTypeDefs;
|
|
142
144
|
private readonly originalValues;
|
|
145
|
+
private readonly listIndicesToKeys;
|
|
143
146
|
constructor(type: T, originalValue: ValueOfType<ReadonlyTypeOfType<T>>, adapters: TypePathsToAdapters, mode: FormMode);
|
|
144
147
|
protected abstract toContext(value: ValueOfType<ReadonlyTypeOfType<T>>, valuePath: keyof ValuePathsToAdapters): ContextType;
|
|
145
148
|
get forceMutableFields(): boolean;
|
|
@@ -153,11 +156,11 @@ declare abstract class FormModel<T extends Type, ValueToTypePaths extends Readon
|
|
|
153
156
|
private maybeGetAdapterForValuePath;
|
|
154
157
|
private getAdapterForValuePath;
|
|
155
158
|
get dirty(): boolean;
|
|
159
|
+
get valueChanged(): boolean;
|
|
156
160
|
typePath<K extends keyof ValueToTypePaths>(valuePath: K): ValueToTypePaths[K];
|
|
157
161
|
setFieldValue<K extends keyof ValuePathsToAdapters>(valuePath: K, value: ToOfFieldAdapter<ValuePathsToAdapters[K]>, validation?: Validation): boolean;
|
|
158
162
|
addListItem<K extends keyof FlattenedListTypesOfType<T>>(valuePath: K, elementValue?: Maybe<ElementOfArray<FlattenedValuesOfType<T>[K]>>, index?: number): void;
|
|
159
163
|
removeListItem<K extends keyof FlattenedListTypesOfType<T>>(...elementValuePaths: readonly `${K}.${number}`[]): void;
|
|
160
|
-
protected moveListItem<K extends keyof FlattenedListTypesOfType<T>>(fromValuePath: K, toValuePath: K): void;
|
|
161
164
|
private internalSetFieldValue;
|
|
162
165
|
/**
|
|
163
166
|
* Forces an error onto a field. Error will be removed if the field value changes
|
|
@@ -371,9 +374,10 @@ type FieldsView<ValuePath extends string = string, C extends ComponentType<any>
|
|
|
371
374
|
|
|
372
375
|
type SuppliedListProps<Value = any, ListPath extends string = string> = {
|
|
373
376
|
values: readonly Value[];
|
|
377
|
+
indexKeys: number[];
|
|
374
378
|
listPath: ListPath;
|
|
375
379
|
};
|
|
376
|
-
declare function DefaultList<Value, ListPath extends string>({ values, listPath, children, }: SuppliedListProps<Value, ListPath> & {
|
|
380
|
+
declare function DefaultList<Value, ListPath extends string>({ values, indexKeys, listPath, children, }: SuppliedListProps<Value, ListPath> & {
|
|
377
381
|
children: (valuePath: `${ListPath}.${number}`, value: Value, index: number) => React.ReactNode;
|
|
378
382
|
}): react_jsx_runtime.JSX.Element;
|
|
379
383
|
|