@jsonforms/core 3.6.0-alpha.1 → 3.6.0-beta.0
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/jsonforms-core.cjs.js +22 -8
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +20 -8
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/models/uischema.d.ts +20 -1
- package/package.json +1 -1
- package/src/models/uischema.ts +23 -1
- package/src/util/resolvers.ts +5 -5
- package/src/util/runtime.ts +20 -3
|
@@ -283,15 +283,15 @@ const resolveSchema = (schema, schemaPath, rootSchema) => {
|
|
|
283
283
|
return resolveSchemaWithSegments(schema, segments, rootSchema);
|
|
284
284
|
};
|
|
285
285
|
const resolveSchemaWithSegments = (schema, pathSegments, rootSchema) => {
|
|
286
|
-
if (
|
|
287
|
-
return undefined;
|
|
288
|
-
}
|
|
289
|
-
if (typeof schema.$ref === 'string') {
|
|
286
|
+
if (typeof schema?.$ref === 'string') {
|
|
290
287
|
schema = resolveSchema(rootSchema, schema.$ref, rootSchema);
|
|
291
288
|
}
|
|
292
289
|
if (!pathSegments || pathSegments.length === 0) {
|
|
293
290
|
return schema;
|
|
294
291
|
}
|
|
292
|
+
if (isEmpty(schema)) {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
295
|
const [segment, ...remainingSegments] = pathSegments;
|
|
296
296
|
if (invalidSegment(segment)) {
|
|
297
297
|
return resolveSchemaWithSegments(schema, remainingSegments, rootSchema);
|
|
@@ -535,15 +535,17 @@ const isOrCondition = (condition) => condition.type === 'OR';
|
|
|
535
535
|
const isAndCondition = (condition) => condition.type === 'AND';
|
|
536
536
|
const isLeafCondition = (condition) => condition.type === 'LEAF';
|
|
537
537
|
const isSchemaCondition = (condition) => has(condition, 'schema');
|
|
538
|
+
const isValidateFunctionCondition = (condition) => has(condition, 'validate') &&
|
|
539
|
+
typeof condition.validate === 'function';
|
|
538
540
|
const getConditionScope = (condition, path) => {
|
|
539
541
|
return composeWithUi(condition, path);
|
|
540
542
|
};
|
|
541
|
-
const evaluateCondition = (data, condition, path, ajv) => {
|
|
543
|
+
const evaluateCondition = (data, uischema, condition, path, ajv) => {
|
|
542
544
|
if (isAndCondition(condition)) {
|
|
543
|
-
return condition.conditions.reduce((acc, cur) => acc && evaluateCondition(data, cur, path, ajv), true);
|
|
545
|
+
return condition.conditions.reduce((acc, cur) => acc && evaluateCondition(data, uischema, cur, path, ajv), true);
|
|
544
546
|
}
|
|
545
547
|
else if (isOrCondition(condition)) {
|
|
546
|
-
return condition.conditions.reduce((acc, cur) => acc || evaluateCondition(data, cur, path, ajv), false);
|
|
548
|
+
return condition.conditions.reduce((acc, cur) => acc || evaluateCondition(data, uischema, cur, path, ajv), false);
|
|
547
549
|
}
|
|
548
550
|
else if (isLeafCondition(condition)) {
|
|
549
551
|
const value = resolveData(data, getConditionScope(condition, path));
|
|
@@ -556,13 +558,23 @@ const evaluateCondition = (data, condition, path, ajv) => {
|
|
|
556
558
|
}
|
|
557
559
|
return ajv.validate(condition.schema, value);
|
|
558
560
|
}
|
|
561
|
+
else if (isValidateFunctionCondition(condition)) {
|
|
562
|
+
const value = resolveData(data, getConditionScope(condition, path));
|
|
563
|
+
const context = {
|
|
564
|
+
data: value,
|
|
565
|
+
fullData: data,
|
|
566
|
+
path,
|
|
567
|
+
uischemaElement: uischema,
|
|
568
|
+
};
|
|
569
|
+
return condition.validate(context);
|
|
570
|
+
}
|
|
559
571
|
else {
|
|
560
572
|
return true;
|
|
561
573
|
}
|
|
562
574
|
};
|
|
563
575
|
const isRuleFulfilled = (uischema, data, path, ajv) => {
|
|
564
576
|
const condition = uischema.rule.condition;
|
|
565
|
-
return evaluateCondition(data, condition, path, ajv);
|
|
577
|
+
return evaluateCondition(data, uischema, condition, path, ajv);
|
|
566
578
|
};
|
|
567
579
|
const evalVisibility = (uischema, data, path = undefined, ajv) => {
|
|
568
580
|
const fulfilled = isRuleFulfilled(uischema, data, path, ajv);
|