@react-typed-forms/schemas 16.0.0 → 16.0.2
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 +42 -5
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +32 -6
- package/lib/index.js.map +1 -1
- package/lib/util.d.ts +1 -0
- package/package.json +2 -2
- package/src/RenderForm.tsx +15 -2
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-typed-forms/schemas",
|
|
3
|
-
"version": "16.0.
|
|
3
|
+
"version": "16.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.cjs",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"clsx": "^1 || ^2",
|
|
35
35
|
"uuid": "^10.0.0",
|
|
36
36
|
"jsonata": "^2.0.4",
|
|
37
|
-
"@astroapps/forms-core": "^1.0.
|
|
37
|
+
"@astroapps/forms-core": "^1.0.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "^18.2.0 || ^19",
|
package/src/RenderForm.tsx
CHANGED
|
@@ -45,6 +45,7 @@ export interface RenderFormProps {
|
|
|
45
45
|
renderer: FormRenderer;
|
|
46
46
|
options?: ControlRenderOptions;
|
|
47
47
|
}
|
|
48
|
+
|
|
48
49
|
/* @trackControls */
|
|
49
50
|
export function RenderForm({
|
|
50
51
|
data,
|
|
@@ -56,7 +57,10 @@ export function RenderForm({
|
|
|
56
57
|
const [formState, setFormState] = useState(
|
|
57
58
|
() => options?.formState ?? createFormState(schemaInterface),
|
|
58
59
|
);
|
|
59
|
-
const
|
|
60
|
+
const effects: (() => void)[] = [];
|
|
61
|
+
const state = formState.getControlState(data, form, options, (cb) =>
|
|
62
|
+
effects.push(cb),
|
|
63
|
+
);
|
|
60
64
|
|
|
61
65
|
useEffect(() => {
|
|
62
66
|
if (!options?.formState) {
|
|
@@ -160,6 +164,7 @@ export function RenderForm({
|
|
|
160
164
|
parent ?? state.dataNode ?? data,
|
|
161
165
|
child,
|
|
162
166
|
childOptions,
|
|
167
|
+
(cb) => effects.push(cb),
|
|
163
168
|
);
|
|
164
169
|
},
|
|
165
170
|
runExpression: (scope, expr, returnResult) => {
|
|
@@ -169,6 +174,7 @@ export function RenderForm({
|
|
|
169
174
|
dataNode: data,
|
|
170
175
|
schemaInterface,
|
|
171
176
|
returnResult,
|
|
177
|
+
runAsync: (cb) => effects.push(cb),
|
|
172
178
|
});
|
|
173
179
|
}
|
|
174
180
|
},
|
|
@@ -182,7 +188,14 @@ export function RenderForm({
|
|
|
182
188
|
const renderedControl = renderer.renderLayout(
|
|
183
189
|
options.adjustLayout?.(dataContext, layoutProps) ?? layoutProps,
|
|
184
190
|
);
|
|
185
|
-
|
|
191
|
+
const rendered = renderer.renderVisibility({
|
|
192
|
+
visibility,
|
|
193
|
+
...renderedControl,
|
|
194
|
+
});
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
effects.forEach((cb) => cb());
|
|
197
|
+
}, [effects]);
|
|
198
|
+
return rendered;
|
|
186
199
|
}
|
|
187
200
|
|
|
188
201
|
/**
|
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);
|