@jsonforms/core 3.4.0-alpha.0 → 3.4.0-alpha.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/actions/actions.d.ts +3 -4
- package/lib/generators/Generate.d.ts +1 -1
- package/lib/i18n/i18nUtil.d.ts +1 -1
- package/lib/i18n/index.d.ts +2 -2
- package/lib/i18n/selectors.d.ts +7 -0
- package/lib/index.d.ts +1 -1
- package/lib/jsonforms-core.cjs.js +1921 -1916
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +1606 -1604
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/{util → mappers}/cell.d.ts +1 -3
- package/lib/{util → mappers}/combinators.d.ts +1 -1
- package/lib/mappers/index.d.ts +4 -0
- package/lib/{util → mappers}/renderer.d.ts +17 -6
- package/lib/mappers/util.d.ts +10 -0
- package/lib/models/uischema.d.ts +0 -8
- package/lib/reducers/cells.d.ts +1 -6
- package/lib/reducers/config.d.ts +1 -1
- package/lib/reducers/core.d.ts +7 -25
- package/lib/reducers/default-data.d.ts +3 -1
- package/lib/reducers/i18n.d.ts +2 -5
- package/lib/reducers/index.d.ts +0 -1
- package/lib/reducers/middleware.d.ts +1 -1
- package/lib/reducers/reducers.d.ts +8 -16
- package/lib/reducers/renderers.d.ts +2 -6
- package/lib/reducers/uischemas.d.ts +2 -6
- package/lib/store/index.d.ts +4 -0
- package/lib/store/jsonFormsCore.d.ts +19 -0
- package/lib/{store.d.ts → store/store.d.ts} +28 -3
- package/lib/testers/testers.d.ts +1 -0
- package/lib/util/errors.d.ts +5 -0
- package/lib/{Helpers.d.ts → util/helpers.d.ts} +1 -1
- package/lib/util/index.d.ts +2 -5
- package/lib/util/label.d.ts +1 -13
- package/lib/util/path.d.ts +6 -2
- package/lib/util/runtime.d.ts +1 -10
- package/lib/util/schema.d.ts +1 -1
- package/lib/util/uischema.d.ts +10 -7
- package/lib/util/util.d.ts +1 -2
- package/lib/util/validator.d.ts +2 -1
- package/package.json +1 -1
- package/src/actions/actions.ts +3 -4
- package/src/generators/Generate.ts +1 -1
- package/src/generators/uischema.ts +1 -3
- package/src/i18n/i18nUtil.ts +7 -4
- package/src/i18n/index.ts +2 -2
- package/src/i18n/selectors.ts +67 -0
- package/src/index.ts +1 -2
- package/src/{util → mappers}/cell.ts +19 -15
- package/src/{util → mappers}/combinators.ts +3 -2
- package/src/mappers/index.ts +29 -0
- package/src/{util → mappers}/renderer.ts +137 -32
- package/src/mappers/util.ts +43 -0
- package/src/models/uischema.ts +0 -29
- package/src/reducers/cells.ts +1 -7
- package/src/reducers/config.ts +1 -1
- package/src/reducers/core.ts +33 -200
- package/src/reducers/default-data.ts +8 -2
- package/src/reducers/i18n.ts +3 -27
- package/src/reducers/index.ts +0 -1
- package/src/reducers/middleware.ts +1 -1
- package/src/reducers/reducers.ts +3 -31
- package/src/reducers/renderers.ts +2 -7
- package/src/reducers/uischemas.ts +2 -12
- package/src/{util/array.ts → store/index.ts} +5 -19
- package/src/store/jsonFormsCore.ts +72 -0
- package/src/{store.ts → store/store.ts} +36 -8
- package/src/testers/testers.ts +6 -0
- package/src/util/errors.ts +142 -0
- package/src/{Helpers.ts → util/helpers.ts} +3 -2
- package/src/util/index.ts +2 -5
- package/src/util/label.ts +1 -98
- package/src/util/path.ts +12 -15
- package/src/util/runtime.ts +1 -44
- package/src/util/schema.ts +1 -1
- package/src/util/uischema.ts +52 -16
- package/src/util/util.ts +1 -9
- package/src/util/validator.ts +15 -1
- package/lib/reducers/selectors.d.ts +0 -15
- package/lib/util/array.d.ts +0 -3
- package/src/reducers/selectors.ts +0 -64
- /package/lib/{i18n → store}/i18nTypes.d.ts +0 -0
- /package/lib/{util → store}/type.d.ts +0 -0
- /package/src/{i18n → store}/i18nTypes.ts +0 -0
- /package/src/{util → store}/type.ts +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/*
|
|
2
|
+
The MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2017-2019 EclipseSource Munich
|
|
5
|
+
https://github.com/eclipsesource/jsonforms
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
THE SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { ErrorObject } from 'ajv';
|
|
27
|
+
import { decode } from './path';
|
|
28
|
+
import { JsonSchema } from '../models';
|
|
29
|
+
import { isOneOfEnumSchema } from './schema';
|
|
30
|
+
import filter from 'lodash/filter';
|
|
31
|
+
import isEqual from 'lodash/isEqual';
|
|
32
|
+
|
|
33
|
+
const getInvalidProperty = (error: ErrorObject): string | undefined => {
|
|
34
|
+
switch (error.keyword) {
|
|
35
|
+
case 'required':
|
|
36
|
+
case 'dependencies':
|
|
37
|
+
return error.params.missingProperty;
|
|
38
|
+
case 'additionalProperties':
|
|
39
|
+
return error.params.additionalProperty;
|
|
40
|
+
default:
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const getControlPath = (error: ErrorObject) => {
|
|
46
|
+
// Up until AJV v7 the path property was called 'dataPath'
|
|
47
|
+
// With AJV v8 the property was renamed to 'instancePath'
|
|
48
|
+
let controlPath = (error as any).dataPath || error.instancePath || '';
|
|
49
|
+
|
|
50
|
+
// change '/' chars to '.'
|
|
51
|
+
controlPath = controlPath.replace(/\//g, '.');
|
|
52
|
+
|
|
53
|
+
const invalidProperty = getInvalidProperty(error);
|
|
54
|
+
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
|
|
55
|
+
controlPath = `${controlPath}.${invalidProperty}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// remove '.' chars at the beginning of paths
|
|
59
|
+
controlPath = controlPath.replace(/^./, '');
|
|
60
|
+
|
|
61
|
+
// decode JSON Pointer escape sequences
|
|
62
|
+
controlPath = decode(controlPath);
|
|
63
|
+
return controlPath;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const errorsAt =
|
|
67
|
+
(
|
|
68
|
+
instancePath: string,
|
|
69
|
+
schema: JsonSchema,
|
|
70
|
+
matchPath: (path: string) => boolean
|
|
71
|
+
) =>
|
|
72
|
+
(errors: ErrorObject[]): ErrorObject[] => {
|
|
73
|
+
// Get data paths of oneOf and anyOf errors to later determine whether an error occurred inside a subschema of oneOf or anyOf.
|
|
74
|
+
const combinatorPaths = filter(
|
|
75
|
+
errors,
|
|
76
|
+
(error) => error.keyword === 'oneOf' || error.keyword === 'anyOf'
|
|
77
|
+
).map((error) => getControlPath(error));
|
|
78
|
+
|
|
79
|
+
return filter(errors, (error) => {
|
|
80
|
+
// Filter errors that match any keyword that we don't want to show in the UI
|
|
81
|
+
// but keep the errors for oneOf enums
|
|
82
|
+
if (
|
|
83
|
+
filteredErrorKeywords.indexOf(error.keyword) !== -1 &&
|
|
84
|
+
!isOneOfEnumSchema(error.parentSchema)
|
|
85
|
+
) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
const controlPath = getControlPath(error);
|
|
89
|
+
let result = matchPath(controlPath);
|
|
90
|
+
// In anyOf and oneOf blocks with "primitive" (i.e. string, number etc.) or array subschemas,
|
|
91
|
+
// we want to make sure that errors are only shown for the correct subschema.
|
|
92
|
+
// Therefore, we compare the error's parent schema with the property's schema.
|
|
93
|
+
// In the primitive case the error's data path is the same for all subschemas:
|
|
94
|
+
// It directly points to the property defining the anyOf/oneOf.
|
|
95
|
+
// The same holds true for errors on the array level (e.g. min item amount).
|
|
96
|
+
// In contrast, this comparison must not be done for errors whose parent schema defines an object or a oneOf enum,
|
|
97
|
+
// because the parent schema can never match the property schema (e.g. for 'required' checks).
|
|
98
|
+
const parentSchema: JsonSchema | undefined = error.parentSchema;
|
|
99
|
+
if (
|
|
100
|
+
result &&
|
|
101
|
+
!isObjectSchema(parentSchema) &&
|
|
102
|
+
!isOneOfEnumSchema(parentSchema) &&
|
|
103
|
+
combinatorPaths.findIndex((p) => instancePath.startsWith(p)) !== -1
|
|
104
|
+
) {
|
|
105
|
+
result = result && isEqual(parentSchema, schema);
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @returns true if the schema describes an object.
|
|
113
|
+
*/
|
|
114
|
+
const isObjectSchema = (schema?: JsonSchema): boolean => {
|
|
115
|
+
return schema?.type === 'object' || !!schema?.properties;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The error-type of an AJV error is defined by its `keyword` property.
|
|
120
|
+
* Certain errors are filtered because they don't fit to any rendered control.
|
|
121
|
+
* All of them have in common that we don't want to show them in the UI
|
|
122
|
+
* because controls will show the actual reason why they don't match their correponding sub schema.
|
|
123
|
+
* - additionalProperties: Indicates that a property is present that is not defined in the schema.
|
|
124
|
+
* Jsonforms only allows to edit defined properties. These errors occur if an oneOf doesn't match.
|
|
125
|
+
* - allOf: Indicates that not all of the allOf definitions match as a whole.
|
|
126
|
+
* - anyOf: Indicates that an anyOf definition itself is not valid because none of its subschemas matches.
|
|
127
|
+
* - oneOf: Indicates that an oneOf definition itself is not valid because not exactly one of its subschemas matches.
|
|
128
|
+
*/
|
|
129
|
+
const filteredErrorKeywords = [
|
|
130
|
+
'additionalProperties',
|
|
131
|
+
'allOf',
|
|
132
|
+
'anyOf',
|
|
133
|
+
'oneOf',
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
export const formatErrorMessage = (errors: string[]) => {
|
|
137
|
+
if (errors === undefined || errors === null) {
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return errors.join('\n');
|
|
142
|
+
};
|
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import {
|
|
27
|
-
import
|
|
26
|
+
import type { ControlElement, JsonSchema, LabelDescription } from '../models';
|
|
27
|
+
import { createLabelDescriptionFrom } from './label';
|
|
28
|
+
import { convertToValidClassName } from './util';
|
|
28
29
|
|
|
29
30
|
export const Helpers: {
|
|
30
31
|
createLabelDescriptionFrom(
|
package/src/util/index.ts
CHANGED
|
@@ -23,19 +23,16 @@
|
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
export * from './array';
|
|
27
|
-
export * from './cell';
|
|
28
|
-
export * from './combinators';
|
|
29
26
|
export * from './Formatted';
|
|
30
27
|
export * from './ids';
|
|
31
28
|
export * from './label';
|
|
32
29
|
export * from './path';
|
|
33
|
-
export * from './renderer';
|
|
34
30
|
export * from './resolvers';
|
|
35
31
|
export * from './runtime';
|
|
36
32
|
export * from './schema';
|
|
37
|
-
export * from './type';
|
|
38
33
|
export * from './uischema';
|
|
39
34
|
export * from './util';
|
|
40
35
|
export * from './validator';
|
|
41
36
|
export * from './defaultDateFormat';
|
|
37
|
+
export * from './errors';
|
|
38
|
+
export * from './helpers';
|
package/src/util/label.ts
CHANGED
|
@@ -25,28 +25,8 @@
|
|
|
25
25
|
|
|
26
26
|
import startCase from 'lodash/startCase';
|
|
27
27
|
|
|
28
|
-
import {
|
|
29
|
-
ControlElement,
|
|
30
|
-
JsonSchema,
|
|
31
|
-
LabelDescription,
|
|
32
|
-
UISchemaElement,
|
|
33
|
-
} from '../models';
|
|
28
|
+
import { ControlElement, JsonSchema, LabelDescription } from '../models';
|
|
34
29
|
import { decode } from './path';
|
|
35
|
-
import { getI18nKeyPrefix, Translator } from '../i18n';
|
|
36
|
-
import { Resolve } from './util';
|
|
37
|
-
import {
|
|
38
|
-
getFirstPrimitiveProp,
|
|
39
|
-
isEnumSchema,
|
|
40
|
-
isOneOfEnumSchema,
|
|
41
|
-
} from './schema';
|
|
42
|
-
import get from 'lodash/get';
|
|
43
|
-
import { findUiControl, getPropPath } from './uischema';
|
|
44
|
-
import {
|
|
45
|
-
EnumOption,
|
|
46
|
-
enumToEnumOptionMapper,
|
|
47
|
-
oneOfToEnumOptionMapper,
|
|
48
|
-
} from './renderer';
|
|
49
|
-
import isEqual from 'lodash/isEqual';
|
|
50
30
|
|
|
51
31
|
const deriveLabel = (
|
|
52
32
|
controlElement: ControlElement,
|
|
@@ -101,80 +81,3 @@ const labelDescription = (text: string, show: boolean): LabelDescription => ({
|
|
|
101
81
|
text: text,
|
|
102
82
|
show: show,
|
|
103
83
|
});
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Compute the child label title for array based controls
|
|
107
|
-
* @param data the data of the control
|
|
108
|
-
* @param childPath the child path
|
|
109
|
-
* @param childLabelProp the dotted path to the value used as child label
|
|
110
|
-
* @param {JsonSchema} schema the json schema for this control
|
|
111
|
-
* @param {JsonSchema} rootSchema the root json schema
|
|
112
|
-
* @param {Translator} translateFct the translator fonction
|
|
113
|
-
* @param {UISchemaElement} uiSchema the uiSchema of the control
|
|
114
|
-
*/
|
|
115
|
-
export const computeChildLabel = (
|
|
116
|
-
data: any,
|
|
117
|
-
childPath: string,
|
|
118
|
-
childLabelProp: string,
|
|
119
|
-
schema: JsonSchema,
|
|
120
|
-
rootSchema: JsonSchema,
|
|
121
|
-
translateFct: Translator,
|
|
122
|
-
uiSchema: UISchemaElement
|
|
123
|
-
): string => {
|
|
124
|
-
const childData = Resolve.data(data, childPath);
|
|
125
|
-
|
|
126
|
-
if (!childLabelProp) {
|
|
127
|
-
childLabelProp = getFirstPrimitiveProp(schema);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// return early in case there is no prop we can query
|
|
131
|
-
if (!childLabelProp) {
|
|
132
|
-
return '';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const currentValue = get(childData, childLabelProp);
|
|
136
|
-
|
|
137
|
-
// in case there is no value, then we can't map it to an enum or oneOf
|
|
138
|
-
if (currentValue === undefined) {
|
|
139
|
-
return '';
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// check whether the value is part of a oneOf or enum and needs to be translated
|
|
143
|
-
const childSchema = Resolve.schema(
|
|
144
|
-
schema,
|
|
145
|
-
'#' + getPropPath(childLabelProp),
|
|
146
|
-
rootSchema
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
let enumOption: EnumOption = undefined;
|
|
150
|
-
if (isEnumSchema(childSchema)) {
|
|
151
|
-
enumOption = enumToEnumOptionMapper(
|
|
152
|
-
currentValue,
|
|
153
|
-
translateFct,
|
|
154
|
-
getI18nKeyPrefix(
|
|
155
|
-
childSchema,
|
|
156
|
-
findUiControl(uiSchema, childLabelProp),
|
|
157
|
-
childPath + '.' + childLabelProp
|
|
158
|
-
)
|
|
159
|
-
);
|
|
160
|
-
} else if (isOneOfEnumSchema(childSchema)) {
|
|
161
|
-
const oneOfArray = childSchema.oneOf as JsonSchema[];
|
|
162
|
-
const oneOfSchema = oneOfArray.find((e: JsonSchema) =>
|
|
163
|
-
isEqual(e.const, currentValue)
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
if (oneOfSchema) {
|
|
167
|
-
enumOption = oneOfToEnumOptionMapper(
|
|
168
|
-
oneOfSchema,
|
|
169
|
-
translateFct,
|
|
170
|
-
getI18nKeyPrefix(
|
|
171
|
-
oneOfSchema,
|
|
172
|
-
undefined,
|
|
173
|
-
childPath + '.' + childLabelProp
|
|
174
|
-
)
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return enumOption ? enumOption.label : currentValue;
|
|
180
|
-
};
|
package/src/util/path.ts
CHANGED
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
|
|
26
26
|
import isEmpty from 'lodash/isEmpty';
|
|
27
27
|
import range from 'lodash/range';
|
|
28
|
-
import { isScoped, Scopable } from '../models';
|
|
29
28
|
|
|
30
29
|
export const compose = (path1: string, path2: string) => {
|
|
31
30
|
let p1 = path1;
|
|
@@ -85,20 +84,6 @@ export const toDataPath = (schemaPath: string): string => {
|
|
|
85
84
|
return toDataPathSegments(schemaPath).join('.');
|
|
86
85
|
};
|
|
87
86
|
|
|
88
|
-
export const composeWithUi = (scopableUi: Scopable, path: string): string => {
|
|
89
|
-
if (!isScoped(scopableUi)) {
|
|
90
|
-
return path ?? '';
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const segments = toDataPathSegments(scopableUi.scope);
|
|
94
|
-
|
|
95
|
-
if (isEmpty(segments)) {
|
|
96
|
-
return path ?? '';
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return compose(path, segments.join('.'));
|
|
100
|
-
};
|
|
101
|
-
|
|
102
87
|
/**
|
|
103
88
|
* Encodes the given segment to be used as part of a JSON Pointer
|
|
104
89
|
*
|
|
@@ -111,3 +96,15 @@ export const encode = (segment: string) =>
|
|
|
111
96
|
*/
|
|
112
97
|
export const decode = (pointerSegment: string) =>
|
|
113
98
|
pointerSegment?.replace(/~1/g, '/').replace(/~0/, '~');
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Transform a dotted path to a uiSchema properties path
|
|
102
|
+
* @param path a dotted prop path to a schema value (i.e. articles.comment.author)
|
|
103
|
+
* @return the uiSchema properties path (i.e. /properties/articles/properties/comment/properties/author)
|
|
104
|
+
*/
|
|
105
|
+
export const getPropPath = (path: string): string => {
|
|
106
|
+
return `/properties/${path
|
|
107
|
+
.split('.')
|
|
108
|
+
.map((p) => encode(p))
|
|
109
|
+
.join('/properties/')}`;
|
|
110
|
+
};
|
package/src/util/runtime.ts
CHANGED
|
@@ -27,7 +27,6 @@ import has from 'lodash/has';
|
|
|
27
27
|
import {
|
|
28
28
|
AndCondition,
|
|
29
29
|
Condition,
|
|
30
|
-
JsonSchema,
|
|
31
30
|
LeafCondition,
|
|
32
31
|
OrCondition,
|
|
33
32
|
RuleEffect,
|
|
@@ -36,10 +35,8 @@ import {
|
|
|
36
35
|
UISchemaElement,
|
|
37
36
|
} from '../models';
|
|
38
37
|
import { resolveData } from './resolvers';
|
|
39
|
-
import { composeWithUi } from './path';
|
|
40
38
|
import type Ajv from 'ajv';
|
|
41
|
-
import {
|
|
42
|
-
import type { JsonFormsState } from '../store';
|
|
39
|
+
import { composeWithUi } from './uischema';
|
|
43
40
|
|
|
44
41
|
const isOrCondition = (condition: Condition): condition is OrCondition =>
|
|
45
42
|
condition.type === 'OR';
|
|
@@ -184,43 +181,3 @@ export const isEnabled = (
|
|
|
184
181
|
|
|
185
182
|
return true;
|
|
186
183
|
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Indicates whether the given `uischema` element shall be enabled or disabled.
|
|
190
|
-
* Checks the global readonly flag, uischema rule, uischema options (including the config),
|
|
191
|
-
* the schema and the enablement indicator of the parent.
|
|
192
|
-
*/
|
|
193
|
-
export const isInherentlyEnabled = (
|
|
194
|
-
state: JsonFormsState,
|
|
195
|
-
ownProps: any,
|
|
196
|
-
uischema: UISchemaElement,
|
|
197
|
-
schema: (JsonSchema & { readOnly?: boolean }) | undefined,
|
|
198
|
-
rootData: any,
|
|
199
|
-
config: any
|
|
200
|
-
) => {
|
|
201
|
-
if (state?.jsonforms?.readonly) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
if (uischema && hasEnableRule(uischema)) {
|
|
205
|
-
return isEnabled(uischema, rootData, ownProps?.path, getAjv(state));
|
|
206
|
-
}
|
|
207
|
-
if (typeof uischema?.options?.readonly === 'boolean') {
|
|
208
|
-
return !uischema.options.readonly;
|
|
209
|
-
}
|
|
210
|
-
if (typeof uischema?.options?.readOnly === 'boolean') {
|
|
211
|
-
return !uischema.options.readOnly;
|
|
212
|
-
}
|
|
213
|
-
if (typeof config?.readonly === 'boolean') {
|
|
214
|
-
return !config.readonly;
|
|
215
|
-
}
|
|
216
|
-
if (typeof config?.readOnly === 'boolean') {
|
|
217
|
-
return !config.readOnly;
|
|
218
|
-
}
|
|
219
|
-
if (schema?.readOnly === true) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
if (typeof ownProps?.enabled === 'boolean') {
|
|
223
|
-
return ownProps.enabled;
|
|
224
|
-
}
|
|
225
|
-
return true;
|
|
226
|
-
};
|
package/src/util/schema.ts
CHANGED
package/src/util/uischema.ts
CHANGED
|
@@ -25,12 +25,17 @@
|
|
|
25
25
|
|
|
26
26
|
import isEmpty from 'lodash/isEmpty';
|
|
27
27
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
ControlElement,
|
|
29
|
+
GroupLayout,
|
|
30
|
+
Internationalizable,
|
|
31
|
+
Labelable,
|
|
32
|
+
Labeled,
|
|
33
|
+
Layout,
|
|
34
|
+
Scopable,
|
|
35
|
+
Scoped,
|
|
31
36
|
UISchemaElement,
|
|
32
37
|
} from '../models';
|
|
33
|
-
import {
|
|
38
|
+
import { compose, getPropPath, toDataPathSegments } from './path';
|
|
34
39
|
|
|
35
40
|
export type IterateCallback = (uischema: UISchemaElement) => void;
|
|
36
41
|
|
|
@@ -62,18 +67,6 @@ export const iterateSchema = (
|
|
|
62
67
|
toApply(uischema);
|
|
63
68
|
};
|
|
64
69
|
|
|
65
|
-
/**
|
|
66
|
-
* Transform a dotted path to a uiSchema properties path
|
|
67
|
-
* @param path a dotted prop path to a schema value (i.e. articles.comment.author)
|
|
68
|
-
* @return the uiSchema properties path (i.e. /properties/articles/properties/comment/properties/author)
|
|
69
|
-
*/
|
|
70
|
-
export const getPropPath = (path: string): string => {
|
|
71
|
-
return `/properties/${path
|
|
72
|
-
.split('.')
|
|
73
|
-
.map((p) => encode(p))
|
|
74
|
-
.join('/properties/')}`;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
70
|
/**
|
|
78
71
|
* Find a control in a uiSchema, based on the dotted path of the schema value
|
|
79
72
|
* @param {UISchemaElement} uiSchema the uiSchema to search from
|
|
@@ -101,3 +94,46 @@ export const findUiControl = (
|
|
|
101
94
|
|
|
102
95
|
return undefined;
|
|
103
96
|
};
|
|
97
|
+
|
|
98
|
+
export const composeWithUi = (scopableUi: Scopable, path: string): string => {
|
|
99
|
+
if (!isScoped(scopableUi)) {
|
|
100
|
+
return path ?? '';
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const segments = toDataPathSegments(scopableUi.scope);
|
|
104
|
+
|
|
105
|
+
if (isEmpty(segments)) {
|
|
106
|
+
return path ?? '';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return compose(path, segments.join('.'));
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const isInternationalized = (
|
|
113
|
+
element: unknown
|
|
114
|
+
): element is Required<Internationalizable> =>
|
|
115
|
+
typeof element === 'object' &&
|
|
116
|
+
element !== null &&
|
|
117
|
+
typeof (element as Internationalizable).i18n === 'string';
|
|
118
|
+
|
|
119
|
+
export const isGroup = (layout: Layout): layout is GroupLayout =>
|
|
120
|
+
layout.type === 'Group';
|
|
121
|
+
|
|
122
|
+
export const isLayout = (uischema: UISchemaElement): uischema is Layout =>
|
|
123
|
+
(uischema as Layout).elements !== undefined;
|
|
124
|
+
|
|
125
|
+
export const isScopable = (obj: unknown): obj is Scopable =>
|
|
126
|
+
!!obj && typeof obj === 'object';
|
|
127
|
+
|
|
128
|
+
export const isScoped = (obj: unknown): obj is Scoped =>
|
|
129
|
+
isScopable(obj) && typeof obj.scope === 'string';
|
|
130
|
+
|
|
131
|
+
export const isLabelable = (obj: unknown): obj is Labelable =>
|
|
132
|
+
!!obj && typeof obj === 'object';
|
|
133
|
+
|
|
134
|
+
export const isLabeled = <T = never>(obj: unknown): obj is Labeled<T> =>
|
|
135
|
+
isLabelable(obj) && ['string', 'boolean'].includes(typeof obj.label);
|
|
136
|
+
|
|
137
|
+
export const isControlElement = (
|
|
138
|
+
uiSchema: UISchemaElement
|
|
139
|
+
): uiSchema is ControlElement => uiSchema.type === 'Control';
|
package/src/util/util.ts
CHANGED
|
@@ -27,11 +27,11 @@ import isEmpty from 'lodash/isEmpty';
|
|
|
27
27
|
import isArray from 'lodash/isArray';
|
|
28
28
|
import includes from 'lodash/includes';
|
|
29
29
|
import find from 'lodash/find';
|
|
30
|
-
import type { JsonSchema, Scoped, UISchemaElement } from '..';
|
|
31
30
|
import { resolveData, resolveSchema } from './resolvers';
|
|
32
31
|
import { composePaths, toDataPathSegments } from './path';
|
|
33
32
|
import { isEnabled, isVisible } from './runtime';
|
|
34
33
|
import type Ajv from 'ajv';
|
|
34
|
+
import type { JsonSchema, Scoped, UISchemaElement } from '../models';
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Returns the string representation of the given date. The format of the output string can be specified:
|
|
@@ -86,14 +86,6 @@ export const convertDateToString = (
|
|
|
86
86
|
export const convertToValidClassName = (s: string): string =>
|
|
87
87
|
s.replace('#', 'root').replace(new RegExp('/', 'g'), '_');
|
|
88
88
|
|
|
89
|
-
export const formatErrorMessage = (errors: string[]) => {
|
|
90
|
-
if (errors === undefined || errors === null) {
|
|
91
|
-
return '';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return errors.join('\n');
|
|
95
|
-
};
|
|
96
|
-
|
|
97
89
|
export const hasType = (jsonSchema: JsonSchema, expected: string): boolean => {
|
|
98
90
|
return includes(deriveTypes(jsonSchema), expected);
|
|
99
91
|
};
|
package/src/util/validator.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import Ajv from 'ajv';
|
|
26
26
|
import addFormats from 'ajv-formats';
|
|
27
|
-
import type { Options } from 'ajv';
|
|
27
|
+
import type { ErrorObject, Options, ValidateFunction } from 'ajv';
|
|
28
28
|
|
|
29
29
|
export const createAjv = (options?: Options) => {
|
|
30
30
|
const ajv = new Ajv({
|
|
@@ -37,3 +37,17 @@ export const createAjv = (options?: Options) => {
|
|
|
37
37
|
addFormats(ajv);
|
|
38
38
|
return ajv;
|
|
39
39
|
};
|
|
40
|
+
|
|
41
|
+
export const validate = (
|
|
42
|
+
validator: ValidateFunction | undefined,
|
|
43
|
+
data: any
|
|
44
|
+
): ErrorObject[] => {
|
|
45
|
+
if (validator === undefined) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const valid = validator(data);
|
|
49
|
+
if (valid) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return validator.errors;
|
|
53
|
+
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type Ajv from 'ajv';
|
|
2
|
-
import type { JsonFormsState } from '../store';
|
|
3
|
-
import type { JsonSchema, UISchemaElement } from '../models';
|
|
4
|
-
import { JsonFormsDefaultDataRegistryEntry } from './default-data';
|
|
5
|
-
import type { JsonFormsRendererRegistryEntry } from './renderers';
|
|
6
|
-
import type { JsonFormsCellRendererRegistryEntry } from './cells';
|
|
7
|
-
import type { JsonFormsUISchemaRegistryEntry } from './uischemas';
|
|
8
|
-
export declare const getData: (state: JsonFormsState) => any;
|
|
9
|
-
export declare const getSchema: (state: JsonFormsState) => JsonSchema;
|
|
10
|
-
export declare const getUiSchema: (state: JsonFormsState) => UISchemaElement;
|
|
11
|
-
export declare const getAjv: (state: JsonFormsState) => Ajv;
|
|
12
|
-
export declare const getDefaultData: (state: JsonFormsState) => JsonFormsDefaultDataRegistryEntry[];
|
|
13
|
-
export declare const getRenderers: (state: JsonFormsState) => JsonFormsRendererRegistryEntry[];
|
|
14
|
-
export declare const getCells: (state: JsonFormsState) => JsonFormsCellRendererRegistryEntry[];
|
|
15
|
-
export declare const getUISchemas: (state: JsonFormsState) => JsonFormsUISchemaRegistryEntry[];
|
package/lib/util/array.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The MIT License
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2017-2019 EclipseSource Munich
|
|
5
|
-
https://github.com/eclipsesource/jsonforms
|
|
6
|
-
|
|
7
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
in the Software without restriction, including without limitation the rights
|
|
10
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
furnished to do so, subject to the following conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be included in
|
|
15
|
-
all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
-
THE SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import get from 'lodash/get';
|
|
27
|
-
import type Ajv from 'ajv';
|
|
28
|
-
import type { JsonFormsState } from '../store';
|
|
29
|
-
import type { JsonSchema, UISchemaElement } from '../models';
|
|
30
|
-
import {
|
|
31
|
-
extractAjv,
|
|
32
|
-
extractData,
|
|
33
|
-
extractSchema,
|
|
34
|
-
extractUiSchema,
|
|
35
|
-
} from './core';
|
|
36
|
-
import {
|
|
37
|
-
extractDefaultData,
|
|
38
|
-
JsonFormsDefaultDataRegistryEntry,
|
|
39
|
-
} from './default-data';
|
|
40
|
-
import type { JsonFormsRendererRegistryEntry } from './renderers';
|
|
41
|
-
import type { JsonFormsCellRendererRegistryEntry } from './cells';
|
|
42
|
-
import type { JsonFormsUISchemaRegistryEntry } from './uischemas';
|
|
43
|
-
|
|
44
|
-
export const getData = (state: JsonFormsState) =>
|
|
45
|
-
extractData(get(state, 'jsonforms.core'));
|
|
46
|
-
export const getSchema = (state: JsonFormsState): JsonSchema =>
|
|
47
|
-
extractSchema(get(state, 'jsonforms.core'));
|
|
48
|
-
export const getUiSchema = (state: JsonFormsState): UISchemaElement =>
|
|
49
|
-
extractUiSchema(get(state, 'jsonforms.core'));
|
|
50
|
-
export const getAjv = (state: JsonFormsState): Ajv =>
|
|
51
|
-
extractAjv(get(state, 'jsonforms.core'));
|
|
52
|
-
export const getDefaultData = (
|
|
53
|
-
state: JsonFormsState
|
|
54
|
-
): JsonFormsDefaultDataRegistryEntry[] =>
|
|
55
|
-
extractDefaultData(get(state, 'jsonforms.defaultData'));
|
|
56
|
-
export const getRenderers = (
|
|
57
|
-
state: JsonFormsState
|
|
58
|
-
): JsonFormsRendererRegistryEntry[] => get(state, 'jsonforms.renderers');
|
|
59
|
-
export const getCells = (
|
|
60
|
-
state: JsonFormsState
|
|
61
|
-
): JsonFormsCellRendererRegistryEntry[] => get(state, 'jsonforms.cells');
|
|
62
|
-
export const getUISchemas = (
|
|
63
|
-
state: JsonFormsState
|
|
64
|
-
): JsonFormsUISchemaRegistryEntry[] => get(state, 'jsonforms.uischemas');
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|