@react-typed-forms/schemas 16.0.0 → 16.0.1
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/lib/index.cjs +26 -5
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +24 -8
- package/lib/index.js.map +1 -1
- package/lib/util.d.ts +1 -0
- package/package.json +1 -1
- package/src/util.ts +22 -2
package/lib/util.d.ts
CHANGED
|
@@ -222,6 +222,7 @@ export declare function getExternalEditData(c: Control<any>): Control<ExternalEd
|
|
|
222
222
|
export declare function getLastDefinedValue<V>(control: Control<V>): Control<V>;
|
|
223
223
|
export declare function getIsEditing(control: Control<any>): Control<boolean | undefined>;
|
|
224
224
|
export declare function getAllValues(control: Control<any>): Control<unknown[]>;
|
|
225
|
+
export declare function clearMultiValues(dataNode: SchemaDataNode): void;
|
|
225
226
|
export declare function applyValues(dataNode: SchemaDataNode, value: unknown): void;
|
|
226
227
|
export declare function collectDifferences(dataNode: SchemaDataNode, values: unknown[]): () => {
|
|
227
228
|
editable: number;
|
package/package.json
CHANGED
package/src/util.ts
CHANGED
|
@@ -859,6 +859,9 @@ export function getNullToggler(c: Control<any>): Control<boolean> {
|
|
|
859
859
|
c.value = currentNotNull ? lastDefined.current.value : null;
|
|
860
860
|
c.disabled = !currentNotNull;
|
|
861
861
|
}, ControlChange.Value);
|
|
862
|
+
c.subscribe(() => {
|
|
863
|
+
notNull.value = c.current.value != null;
|
|
864
|
+
}, ControlChange.Value);
|
|
862
865
|
return notNull;
|
|
863
866
|
function disableIfNotEditing() {
|
|
864
867
|
notNull.disabled = isEditing.current.value === false;
|
|
@@ -916,6 +919,21 @@ export function getAllValues(control: Control<any>): Control<unknown[]> {
|
|
|
916
919
|
);
|
|
917
920
|
}
|
|
918
921
|
|
|
922
|
+
export function clearMultiValues(dataNode: SchemaDataNode): void {
|
|
923
|
+
const c = dataNode.control;
|
|
924
|
+
const sf = dataNode.schema.field;
|
|
925
|
+
if (sf.collection) {
|
|
926
|
+
return;
|
|
927
|
+
} else if (isCompoundField(sf)) {
|
|
928
|
+
dataNode.schema.getChildNodes().forEach((c) => {
|
|
929
|
+
clearMultiValues(dataNode.getChild(c));
|
|
930
|
+
});
|
|
931
|
+
} else {
|
|
932
|
+
const allValues = getAllValues(c);
|
|
933
|
+
allValues.setValue((x) => [c.current.value]);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
|
|
919
937
|
export function applyValues(dataNode: SchemaDataNode, value: unknown): void {
|
|
920
938
|
const c = dataNode.control;
|
|
921
939
|
const sf = dataNode.schema.field;
|
|
@@ -945,8 +963,10 @@ export function collectDifferences(
|
|
|
945
963
|
values: unknown[],
|
|
946
964
|
): () => { editable: number; editing: number } {
|
|
947
965
|
values.forEach((v, i) => {
|
|
948
|
-
if (i == 0)
|
|
949
|
-
|
|
966
|
+
if (i == 0) {
|
|
967
|
+
dataNode.control.setInitialValue(v);
|
|
968
|
+
clearMultiValues(dataNode);
|
|
969
|
+
} else applyValues(dataNode, v);
|
|
950
970
|
});
|
|
951
971
|
const allEdits: Control<boolean | undefined>[] = [];
|
|
952
972
|
resetMultiValues(dataNode);
|