@jsonforms/core 3.1.0-alpha.1 → 3.1.0-alpha.3
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/README.md +3 -3
- package/lib/actions/actions.d.ts +21 -21
- package/lib/i18n/arrayTranslations.d.ts +24 -0
- package/lib/i18n/i18nUtil.d.ts +3 -0
- package/lib/i18n/index.d.ts +1 -0
- package/lib/jsonforms-core.cjs.js +436 -262
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +318 -201
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/util/cell.d.ts +0 -1
- package/lib/util/renderer.d.ts +6 -2
- package/lib/util/schema.d.ts +5 -0
- package/package.json +11 -4
- package/src/Helpers.ts +1 -1
- package/src/actions/actions.ts +52 -55
- package/src/configDefault.ts +1 -1
- package/src/generators/Generate.ts +3 -1
- package/src/generators/schema.ts +29 -25
- package/src/generators/uischema.ts +7 -6
- package/src/i18n/arrayTranslations.ts +54 -0
- package/src/i18n/i18nTypes.ts +10 -6
- package/src/i18n/i18nUtil.ts +64 -14
- package/src/i18n/index.ts +1 -0
- package/src/models/draft4.ts +33 -33
- package/src/models/uischema.ts +17 -6
- package/src/reducers/cells.ts +8 -7
- package/src/reducers/core.ts +119 -75
- package/src/reducers/default-data.ts +7 -7
- package/src/reducers/i18n.ts +21 -9
- package/src/reducers/reducers.ts +20 -30
- package/src/reducers/renderers.ts +7 -7
- package/src/reducers/selectors.ts +4 -5
- package/src/reducers/uischemas.ts +25 -24
- package/src/store.ts +1 -1
- package/src/testers/testers.ts +202 -148
- package/src/util/cell.ts +24 -26
- package/src/util/combinators.ts +5 -3
- package/src/util/label.ts +1 -1
- package/src/util/path.ts +11 -7
- package/src/util/renderer.ts +118 -67
- package/src/util/resolvers.ts +15 -13
- package/src/util/runtime.ts +2 -2
- package/src/util/schema.ts +10 -1
- package/src/util/type.ts +5 -3
- package/src/util/uischema.ts +9 -9
- package/src/util/util.ts +52 -52
- package/src/util/validator.ts +1 -1
package/src/util/schema.ts
CHANGED
|
@@ -24,10 +24,11 @@
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import find from 'lodash/find';
|
|
27
|
+
import { JsonSchema } from '../models';
|
|
27
28
|
|
|
28
29
|
export const getFirstPrimitiveProp = (schema: any) => {
|
|
29
30
|
if (schema.properties) {
|
|
30
|
-
return find(Object.keys(schema.properties), propName => {
|
|
31
|
+
return find(Object.keys(schema.properties), (propName) => {
|
|
31
32
|
const prop = schema.properties[propName];
|
|
32
33
|
return (
|
|
33
34
|
prop.type === 'string' ||
|
|
@@ -38,3 +39,11 @@ export const getFirstPrimitiveProp = (schema: any) => {
|
|
|
38
39
|
}
|
|
39
40
|
return undefined;
|
|
40
41
|
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Tests whether the schema has an enum based on oneOf.
|
|
45
|
+
*/
|
|
46
|
+
export const isOneOfEnumSchema = (schema: JsonSchema) =>
|
|
47
|
+
schema?.hasOwnProperty('oneOf') &&
|
|
48
|
+
schema?.oneOf &&
|
|
49
|
+
(schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined);
|
package/src/util/type.ts
CHANGED
|
@@ -62,7 +62,9 @@ export interface AnyAction extends Action {
|
|
|
62
62
|
* @template A The type of things (actions or otherwise) which may be
|
|
63
63
|
* dispatched.
|
|
64
64
|
*/
|
|
65
|
-
export type Dispatch<A extends Action = AnyAction> = <T extends A>(
|
|
65
|
+
export type Dispatch<A extends Action = AnyAction> = <T extends A>(
|
|
66
|
+
action: T
|
|
67
|
+
) => T;
|
|
66
68
|
|
|
67
69
|
// Copied from https://github.com/reduxjs/redux/blob/master/src/types/store.ts
|
|
68
70
|
/**
|
|
@@ -171,7 +173,7 @@ export type Observable<T> = {
|
|
|
171
173
|
* emission of values from the observable.
|
|
172
174
|
*/
|
|
173
175
|
subscribe(observer: Observer<T>): { unsubscribe: Unsubscribe };
|
|
174
|
-
[Symbol.observable](): Observable<T
|
|
176
|
+
[Symbol.observable](): Observable<T>;
|
|
175
177
|
};
|
|
176
178
|
|
|
177
179
|
// Copied from https://github.com/reduxjs/redux/blob/master/src/types/store.ts
|
|
@@ -180,7 +182,7 @@ export type Observable<T> = {
|
|
|
180
182
|
* an argument to subscribe.
|
|
181
183
|
*/
|
|
182
184
|
export type Observer<T> = {
|
|
183
|
-
next?(value: T): void
|
|
185
|
+
next?(value: T): void;
|
|
184
186
|
};
|
|
185
187
|
|
|
186
188
|
// Copied from https://github.com/reduxjs/redux/blob/master/src/types/reducers.ts
|
package/src/util/uischema.ts
CHANGED
|
@@ -28,14 +28,14 @@ import { isLayout, UISchemaElement } from '../models';
|
|
|
28
28
|
|
|
29
29
|
export type IterateCallback = (uischema: UISchemaElement) => void;
|
|
30
30
|
|
|
31
|
-
const setReadonlyPropertyValue =
|
|
32
|
-
|
|
33
|
-
): void => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
};
|
|
31
|
+
const setReadonlyPropertyValue =
|
|
32
|
+
(value: boolean): IterateCallback =>
|
|
33
|
+
(child: UISchemaElement): void => {
|
|
34
|
+
if (!child.options) {
|
|
35
|
+
child.options = {};
|
|
36
|
+
}
|
|
37
|
+
child.options.readonly = value;
|
|
38
|
+
};
|
|
39
39
|
export const setReadonly = (uischema: UISchemaElement): void => {
|
|
40
40
|
iterateSchema(uischema, setReadonlyPropertyValue(true));
|
|
41
41
|
};
|
|
@@ -50,7 +50,7 @@ export const iterateSchema = (
|
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
if (isLayout(uischema)) {
|
|
53
|
-
uischema.elements.forEach(child => iterateSchema(child, toApply));
|
|
53
|
+
uischema.elements.forEach((child) => iterateSchema(child, toApply));
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
toApply(uischema);
|
package/src/util/util.ts
CHANGED
|
@@ -41,87 +41,87 @@ import type Ajv from 'ajv';
|
|
|
41
41
|
* @returns {string} the escaped string
|
|
42
42
|
*/
|
|
43
43
|
export const convertToValidClassName = (s: string): string =>
|
|
44
|
-
s.replace('#', 'root').replace(new RegExp('/', 'g'), '_');
|
|
44
|
+
s.replace('#', 'root').replace(new RegExp('/', 'g'), '_');
|
|
45
45
|
|
|
46
46
|
export const formatErrorMessage = (errors: string[]) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
if (errors === undefined || errors === null) {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
return errors.join('\n');
|
|
52
52
|
};
|
|
53
53
|
|
|
54
54
|
export const hasType = (jsonSchema: JsonSchema, expected: string): boolean => {
|
|
55
|
-
|
|
55
|
+
return includes(deriveTypes(jsonSchema), expected);
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Derives the type of the jsonSchema element
|
|
60
60
|
*/
|
|
61
61
|
export const deriveTypes = (jsonSchema: JsonSchema): string[] => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
62
|
+
if (isEmpty(jsonSchema)) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
if (!isEmpty(jsonSchema.type) && typeof jsonSchema.type === 'string') {
|
|
66
|
+
return [jsonSchema.type];
|
|
67
|
+
}
|
|
68
|
+
if (isArray(jsonSchema.type)) {
|
|
69
|
+
return jsonSchema.type;
|
|
70
|
+
}
|
|
71
|
+
if (
|
|
72
|
+
!isEmpty(jsonSchema.properties) ||
|
|
73
|
+
!isEmpty(jsonSchema.additionalProperties)
|
|
74
|
+
) {
|
|
75
|
+
return ['object'];
|
|
76
|
+
}
|
|
77
|
+
if (!isEmpty(jsonSchema.items)) {
|
|
78
|
+
return ['array'];
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
if (!isEmpty(jsonSchema.allOf)) {
|
|
82
|
+
const allOfType = find(
|
|
83
|
+
jsonSchema.allOf,
|
|
84
|
+
(schema: JsonSchema) => deriveTypes(schema).length !== 0
|
|
85
|
+
);
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
if (allOfType) {
|
|
88
|
+
return deriveTypes(allOfType);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// ignore all remaining cases
|
|
92
|
+
return [];
|
|
93
93
|
};
|
|
94
94
|
|
|
95
95
|
/**
|
|
96
96
|
* Convenience wrapper around resolveData and resolveSchema.
|
|
97
97
|
*/
|
|
98
98
|
export const Resolve: {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
schema(
|
|
100
|
+
schema: JsonSchema,
|
|
101
|
+
schemaPath: string,
|
|
102
|
+
rootSchema: JsonSchema
|
|
103
|
+
): JsonSchema;
|
|
104
|
+
data(data: any, path: string): any;
|
|
105
105
|
} = {
|
|
106
|
-
|
|
107
|
-
|
|
106
|
+
schema: resolveSchema,
|
|
107
|
+
data: resolveData,
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
// Paths --
|
|
111
111
|
const fromScoped = (scopable: Scoped): string =>
|
|
112
|
-
|
|
112
|
+
toDataPathSegments(scopable.scope).join('.');
|
|
113
113
|
|
|
114
114
|
export const Paths = {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
compose: composePaths,
|
|
116
|
+
fromScoped,
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
// Runtime --
|
|
120
120
|
export const Runtime = {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
121
|
+
isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
|
|
122
|
+
return isEnabled(uischema, data, undefined, ajv);
|
|
123
|
+
},
|
|
124
|
+
isVisible(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
|
|
125
|
+
return isVisible(uischema, data, undefined, ajv);
|
|
126
|
+
},
|
|
127
127
|
};
|