@astroapps/forms-core 1.0.0 → 1.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/evalExpression.d.ts +1 -0
- package/lib/formState.d.ts +1 -1
- package/lib/index.cjs +16 -9
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +14 -9
- package/lib/index.js.map +1 -1
- package/lib/validators.d.ts +2 -1
- package/package.json +1 -1
- package/src/evalExpression.ts +4 -2
- package/src/formState.ts +4 -0
- package/src/validators.ts +5 -1
package/lib/validators.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface ValidationEvalContext {
|
|
|
13
13
|
data: SchemaDataNode;
|
|
14
14
|
schemaInterface: SchemaInterface;
|
|
15
15
|
formContext: Control<FormContextOptions>;
|
|
16
|
+
runAsync(af: () => void): void;
|
|
16
17
|
}
|
|
17
18
|
export type ValidatorEval<T extends SchemaValidator> = (validation: T, context: ValidationEvalContext) => void;
|
|
18
19
|
export declare const jsonataValidator: ValidatorEval<JsonataValidator>;
|
|
@@ -20,4 +21,4 @@ export declare const lengthValidator: ValidatorEval<LengthValidator>;
|
|
|
20
21
|
export declare const dateValidator: ValidatorEval<DateValidator>;
|
|
21
22
|
export declare const defaultValidators: Record<string, ValidatorEval<any>>;
|
|
22
23
|
export declare function createValidators(def: ControlDefinition, context: ValidationEvalContext): void;
|
|
23
|
-
export declare function setupValidation(controlImpl: Control<FormContextOptions>, definition: ControlDefinition, dataNode: Control<SchemaDataNode | undefined>, schemaInterface: SchemaInterface, parent: SchemaDataNode, formNode: FormNode): void;
|
|
24
|
+
export declare function setupValidation(controlImpl: Control<FormContextOptions>, definition: ControlDefinition, dataNode: Control<SchemaDataNode | undefined>, schemaInterface: SchemaInterface, parent: SchemaDataNode, formNode: FormNode, runAsync: (af: () => void) => void): void;
|
package/package.json
CHANGED
package/src/evalExpression.ts
CHANGED
|
@@ -28,6 +28,7 @@ export interface ExpressionEvalContext {
|
|
|
28
28
|
dataNode: SchemaDataNode;
|
|
29
29
|
schemaInterface: SchemaInterface;
|
|
30
30
|
variables?: Value<Record<string, any> | undefined>;
|
|
31
|
+
runAsync(effect: () => void): void;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
export type ExpressionEval<T extends EntityExpression> = (
|
|
@@ -72,7 +73,7 @@ const notEmptyEval: ExpressionEval<NotEmptyExpression> = (
|
|
|
72
73
|
|
|
73
74
|
export const jsonataEval: ExpressionEval<JsonataExpression> = (
|
|
74
75
|
expr,
|
|
75
|
-
{ scope, returnResult, dataNode, variables },
|
|
76
|
+
{ scope, returnResult, dataNode, variables, runAsync },
|
|
76
77
|
) => {
|
|
77
78
|
const path = getJsonPath(dataNode);
|
|
78
79
|
const pathString = jsonPathString(path, (x) => `#$i[${x}]`);
|
|
@@ -102,7 +103,8 @@ export const jsonataEval: ExpressionEval<JsonataExpression> = (
|
|
|
102
103
|
collectChanges(effect.collectUsage, () => returnResult(evalResult));
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
createAsyncEffect(runJsonata, scope);
|
|
106
|
+
const asyncEffect = createAsyncEffect(runJsonata, scope);
|
|
107
|
+
runAsync(() => asyncEffect.start());
|
|
106
108
|
};
|
|
107
109
|
|
|
108
110
|
export const uuidEval: ExpressionEval<EntityExpression> = (_, ctx) => {
|
package/src/formState.ts
CHANGED
|
@@ -82,6 +82,7 @@ export interface FormState {
|
|
|
82
82
|
parent: SchemaDataNode,
|
|
83
83
|
formNode: FormNode,
|
|
84
84
|
context: FormContextOptions,
|
|
85
|
+
runAsync: (af: () => void) => void,
|
|
85
86
|
): ControlState;
|
|
86
87
|
|
|
87
88
|
cleanup(): void;
|
|
@@ -116,6 +117,7 @@ export function createFormState(
|
|
|
116
117
|
parent: SchemaDataNode,
|
|
117
118
|
formNode: FormNode,
|
|
118
119
|
context: FormContextOptions,
|
|
120
|
+
runAsync: (af: () => void) => void,
|
|
119
121
|
): ControlState {
|
|
120
122
|
const stateId = parent.id + "$" + formNode.id + (context.stateKey ?? "");
|
|
121
123
|
const controlImpl = controlStates.fields[stateId];
|
|
@@ -137,6 +139,7 @@ export function createFormState(
|
|
|
137
139
|
dataNode: parent,
|
|
138
140
|
variables: controlImpl.fields.variables,
|
|
139
141
|
schemaInterface,
|
|
142
|
+
runAsync,
|
|
140
143
|
});
|
|
141
144
|
return true;
|
|
142
145
|
}
|
|
@@ -365,6 +368,7 @@ export function createFormState(
|
|
|
365
368
|
schemaInterface,
|
|
366
369
|
parent,
|
|
367
370
|
formNode,
|
|
371
|
+
runAsync,
|
|
368
372
|
);
|
|
369
373
|
|
|
370
374
|
createSyncEffect(() => {
|
package/src/validators.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface ValidationEvalContext {
|
|
|
32
32
|
data: SchemaDataNode;
|
|
33
33
|
schemaInterface: SchemaInterface;
|
|
34
34
|
formContext: Control<FormContextOptions>;
|
|
35
|
+
runAsync(af: () => void): void;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
export type ValidatorEval<T extends SchemaValidator> = (
|
|
@@ -51,11 +52,12 @@ export const jsonataValidator: ValidatorEval<JsonataValidator> = (
|
|
|
51
52
|
dataNode: context.parentData,
|
|
52
53
|
returnResult: (v) => {
|
|
53
54
|
trackControlChange(context.data.control, ControlChange.Validate);
|
|
54
|
-
console.log("Setting jsonata error", v);
|
|
55
|
+
// console.log("Setting jsonata error", v);
|
|
55
56
|
context.data.control.setError("jsonata", v?.toString());
|
|
56
57
|
},
|
|
57
58
|
schemaInterface: context.schemaInterface,
|
|
58
59
|
variables: context.formContext.fields.variables,
|
|
60
|
+
runAsync: context.runAsync,
|
|
59
61
|
},
|
|
60
62
|
);
|
|
61
63
|
};
|
|
@@ -169,6 +171,7 @@ export function setupValidation(
|
|
|
169
171
|
schemaInterface: SchemaInterface,
|
|
170
172
|
parent: SchemaDataNode,
|
|
171
173
|
formNode: FormNode,
|
|
174
|
+
runAsync: (af: () => void) => void,
|
|
172
175
|
) {
|
|
173
176
|
const validationEnabled = createScopedComputed(
|
|
174
177
|
controlImpl,
|
|
@@ -193,6 +196,7 @@ export function setupValidation(
|
|
|
193
196
|
validatorsScope.addCleanup(cleanup);
|
|
194
197
|
},
|
|
195
198
|
formContext: controlImpl,
|
|
199
|
+
runAsync,
|
|
196
200
|
});
|
|
197
201
|
|
|
198
202
|
createEffect(
|