@jsonforms/core 3.0.0-alpha.0 → 3.0.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/README.md +1 -1
- package/docs/assets/js/search.json +1 -1
- package/docs/enums/ruleeffect.html +4 -4
- package/docs/globals.html +1095 -703
- package/docs/index.html +70 -43
- package/docs/interfaces/addcellrendereraction.html +3 -3
- package/docs/interfaces/addrendereraction.html +3 -3
- package/docs/interfaces/adduischemaaction.html +3 -3
- package/docs/interfaces/andcondition.html +2 -2
- package/docs/interfaces/arraycontrolprops.html +22 -22
- package/docs/interfaces/arraylayoutprops.html +22 -22
- package/docs/interfaces/categorization.html +5 -5
- package/docs/interfaces/category.html +5 -5
- package/docs/interfaces/cellprops.html +14 -14
- package/docs/interfaces/combinatorrendererprops.html +13 -13
- package/docs/interfaces/combinatorsubschemarenderinfo.html +3 -3
- package/docs/interfaces/composablecondition.html +2 -2
- package/docs/interfaces/condition.html +1 -1
- package/docs/interfaces/controlelement.html +5 -5
- package/docs/interfaces/controlprops.html +17 -17
- package/docs/interfaces/controlstate.html +2 -2
- package/docs/interfaces/controlwithdetailprops.html +18 -18
- package/docs/interfaces/dispatchcellprops.html +13 -13
- package/docs/interfaces/dispatchcellstateprops.html +13 -13
- package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
- package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
- package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
- package/docs/interfaces/enumcellprops.html +15 -15
- package/docs/interfaces/enumoption.html +2 -2
- package/docs/interfaces/formatted.html +2 -2
- package/docs/interfaces/grouplayout.html +5 -5
- package/docs/interfaces/horizontallayout.html +4 -4
- package/docs/interfaces/initaction.html +6 -6
- package/docs/interfaces/initactionoptions.html +3 -3
- package/docs/interfaces/jsonformscellrendererregistryentry.html +2 -2
- package/docs/interfaces/jsonformscore.html +7 -7
- package/docs/interfaces/jsonformsdefaultdataregistryentry.html +2 -2
- package/docs/interfaces/jsonformsextendedstate.html +1 -1
- package/docs/interfaces/{jsonformslocalestate.html → jsonformsi18nstate.html} +20 -20
- package/docs/interfaces/jsonformsprops.html +9 -9
- package/docs/interfaces/jsonformsrendererregistryentry.html +2 -2
- package/docs/interfaces/jsonformsstate.html +1 -1
- package/docs/interfaces/jsonformsstore.html +5 -5
- package/docs/interfaces/jsonformssubstates.html +18 -8
- package/docs/interfaces/jsonformsuischemaregistryentry.html +2 -2
- package/docs/interfaces/labeldescription.html +2 -2
- package/docs/interfaces/labelelement.html +4 -4
- package/docs/interfaces/layout.html +4 -4
- package/docs/interfaces/layoutprops.html +10 -10
- package/docs/interfaces/leafcondition.html +3 -3
- package/docs/interfaces/orcondition.html +2 -2
- package/docs/interfaces/ownpropsofcell.html +10 -10
- package/docs/interfaces/ownpropsofcontrol.html +9 -9
- package/docs/interfaces/ownpropsofenum.html +1 -1
- package/docs/interfaces/ownpropsofenumcell.html +11 -11
- package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
- package/docs/interfaces/ownpropsoflayout.html +9 -9
- package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
- package/docs/interfaces/ownpropsofrenderer.html +8 -8
- package/docs/interfaces/registerdefaultdataaction.html +3 -3
- package/docs/interfaces/removecellrendereraction.html +3 -3
- package/docs/interfaces/removerendereraction.html +3 -3
- package/docs/interfaces/removeuischemaaction.html +2 -2
- package/docs/interfaces/rendererprops.html +9 -9
- package/docs/interfaces/rule.html +2 -2
- package/docs/interfaces/schemabasedcondition.html +3 -3
- package/docs/interfaces/scopable.html +1 -1
- package/docs/interfaces/setajvaction.html +3 -3
- package/docs/interfaces/setconfigaction.html +2 -2
- package/docs/interfaces/setlocaleaction.html +3 -3
- package/docs/interfaces/setschemaaction.html +2 -2
- package/docs/interfaces/{setlocalizedschemasaction.html → settranslatoraction.html} +29 -15
- package/docs/interfaces/setuischemaaction.html +2 -2
- package/docs/interfaces/setvalidationmodeaction.html +2 -2
- package/docs/interfaces/statepropsofarraycontrol.html +18 -18
- package/docs/interfaces/statepropsofarraylayout.html +18 -18
- package/docs/interfaces/statepropsofcell.html +13 -13
- package/docs/interfaces/statepropsofcombinator.html +12 -12
- package/docs/interfaces/statepropsofcontrol.html +16 -16
- package/docs/interfaces/statepropsofcontrolwithdetail.html +17 -17
- package/docs/interfaces/statepropsofenumcell.html +14 -14
- package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -9
- package/docs/interfaces/statepropsoflayout.html +10 -10
- package/docs/interfaces/statepropsofmasteritem.html +7 -7
- package/docs/interfaces/statepropsofrenderer.html +9 -9
- package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
- package/docs/interfaces/uischemaelement.html +3 -3
- package/docs/interfaces/unregisterdefaultdataaction.html +2 -2
- package/docs/interfaces/updateaction.html +3 -3
- package/docs/interfaces/updatecoreaction.html +6 -6
- package/docs/interfaces/updateerrorsaction.html +2 -2
- package/docs/interfaces/{setlocalizeduischemasaction.html → updatei18naction.html} +43 -15
- package/docs/interfaces/verticallayout.html +4 -4
- package/docs/interfaces/withclassname.html +1 -1
- package/lib/Helpers.d.ts +5 -0
- package/lib/actions/actions.d.ts +181 -0
- package/lib/actions/index.d.ts +1 -178
- package/lib/configDefault.d.ts +6 -6
- package/lib/generators/Generate.d.ts +6 -0
- package/lib/generators/index.d.ts +3 -10
- package/lib/generators/schema.d.ts +8 -8
- package/lib/generators/uischema.d.ts +12 -13
- package/lib/i18n/i18nTypes.d.ts +15 -0
- package/lib/i18n/i18nUtil.d.ts +18 -0
- package/lib/i18n/index.d.ts +2 -0
- package/lib/index.d.ts +11 -23
- package/lib/jsonforms-core.cjs.js +2445 -0
- package/lib/jsonforms-core.cjs.js.map +1 -0
- package/lib/jsonforms-core.esm.js +2164 -0
- package/lib/jsonforms-core.esm.js.map +1 -0
- package/lib/models/draft4.d.ts +198 -198
- package/lib/models/index.d.ts +5 -0
- package/lib/models/jsonSchema.d.ts +3 -3
- package/lib/models/jsonSchema4.d.ts +110 -110
- package/lib/models/jsonSchema7.d.ts +119 -119
- package/lib/models/uischema.d.ts +201 -201
- package/lib/reducers/cells.d.ts +11 -11
- package/lib/reducers/config.d.ts +3 -3
- package/lib/reducers/core.d.ts +24 -23
- package/lib/reducers/default-data.d.ts +10 -10
- package/lib/reducers/i18n.d.ts +8 -11
- package/lib/reducers/index.d.ts +9 -47
- package/lib/reducers/reducers.d.ts +29 -0
- package/lib/reducers/renderers.d.ts +10 -10
- package/lib/reducers/selectors.d.ts +15 -0
- package/lib/reducers/uischemas.d.ts +10 -10
- package/lib/store.d.ts +53 -56
- package/lib/testers/index.d.ts +1 -204
- package/lib/testers/testers.d.ts +203 -0
- package/lib/util/Formatted.d.ts +19 -19
- package/lib/util/array.d.ts +3 -3
- package/lib/util/cell.d.ts +79 -79
- package/lib/util/combinators.d.ts +10 -11
- package/lib/util/ids.d.ts +3 -3
- package/lib/util/index.d.ts +15 -49
- package/lib/util/label.d.ts +9 -10
- package/lib/util/path.d.ts +25 -24
- package/lib/util/renderer.d.ts +398 -395
- package/lib/util/resolvers.d.ts +25 -25
- package/lib/util/runtime.d.ts +18 -19
- package/lib/util/schema.d.ts +1 -1
- package/lib/util/type.d.ts +174 -174
- package/lib/util/uischema.d.ts +5 -5
- package/lib/util/util.d.ts +31 -0
- package/lib/util/validator.d.ts +3 -2
- package/package.json +18 -14
- package/rollup.config.js +44 -0
- package/{lib/models/jsonSchema4.js → src/Helpers.ts} +16 -8
- package/src/actions/actions.ts +345 -0
- package/src/actions/index.ts +1 -310
- package/src/configDefault.ts +1 -0
- package/{lib/util/validator.js → src/generators/Generate.ts} +18 -11
- package/src/generators/index.ts +3 -21
- package/src/generators/schema.ts +1 -1
- package/src/generators/uischema.ts +4 -4
- package/src/i18n/i18nTypes.ts +17 -0
- package/src/i18n/i18nUtil.ts +105 -0
- package/src/i18n/index.ts +2 -0
- package/src/index.ts +7 -31
- package/src/models/draft4.ts +1 -0
- package/{lib/util/type.js → src/models/index.ts} +10 -7
- package/src/models/jsonSchema.ts +1 -0
- package/src/models/uischema.ts +1 -0
- package/src/reducers/cells.ts +2 -1
- package/src/reducers/config.ts +2 -1
- package/src/reducers/core.ts +74 -52
- package/src/reducers/default-data.ts +2 -1
- package/src/reducers/i18n.ts +42 -35
- package/src/reducers/index.ts +9 -154
- package/src/reducers/reducers.ts +128 -0
- package/src/reducers/renderers.ts +2 -1
- package/src/reducers/selectors.ts +65 -0
- package/src/reducers/uischemas.ts +4 -2
- package/src/store.ts +11 -8
- package/src/testers/index.ts +1 -516
- package/src/testers/testers.ts +547 -0
- package/src/util/Formatted.ts +1 -0
- package/src/util/array.ts +25 -0
- package/src/util/cell.ts +45 -10
- package/src/util/combinators.ts +2 -4
- package/src/util/ids.ts +1 -0
- package/src/util/index.ts +11 -123
- package/src/util/label.ts +2 -2
- package/src/util/path.ts +4 -1
- package/src/util/renderer.ts +139 -66
- package/src/util/resolvers.ts +2 -1
- package/src/util/runtime.ts +3 -2
- package/src/util/schema.ts +26 -1
- package/src/util/uischema.ts +2 -1
- package/src/util/util.ts +127 -0
- package/src/util/validator.ts +5 -8
- package/stats.html +3279 -0
- package/{lib/configDefault.js → test/i18n/i18nUtil.test.ts} +25 -24
- package/test/reducers/core.test.ts +31 -44
- package/test/util/cell.test.ts +2 -2
- package/test/util/renderer.test.ts +543 -31
- package/docs/interfaces/labels.html +0 -157
- package/lib/actions/index.js +0 -125
- package/lib/actions/index.js.map +0 -1
- package/lib/configDefault.js.map +0 -1
- package/lib/generators/index.js +0 -12
- package/lib/generators/index.js.map +0 -1
- package/lib/generators/schema.js +0 -152
- package/lib/generators/schema.js.map +0 -1
- package/lib/generators/uischema.js +0 -167
- package/lib/generators/uischema.js.map +0 -1
- package/lib/index.js +0 -45
- package/lib/index.js.map +0 -1
- package/lib/jsonforms-core.js +0 -19
- package/lib/jsonforms-core.js.map +0 -1
- package/lib/models/draft4.js +0 -173
- package/lib/models/draft4.js.map +0 -1
- package/lib/models/jsonSchema.js +0 -3
- package/lib/models/jsonSchema.js.map +0 -1
- package/lib/models/jsonSchema4.js.map +0 -1
- package/lib/models/jsonSchema7.js +0 -30
- package/lib/models/jsonSchema7.js.map +0 -1
- package/lib/models/uischema.js +0 -31
- package/lib/models/uischema.js.map +0 -1
- package/lib/reducers/cells.js +0 -16
- package/lib/reducers/cells.js.map +0 -1
- package/lib/reducers/config.js +0 -44
- package/lib/reducers/config.js.map +0 -1
- package/lib/reducers/core.js +0 -259
- package/lib/reducers/core.js.map +0 -1
- package/lib/reducers/default-data.js +0 -42
- package/lib/reducers/default-data.js.map +0 -1
- package/lib/reducers/i18n.js +0 -66
- package/lib/reducers/i18n.js.map +0 -1
- package/lib/reducers/index.js +0 -92
- package/lib/reducers/index.js.map +0 -1
- package/lib/reducers/renderers.js +0 -17
- package/lib/reducers/renderers.js.map +0 -1
- package/lib/reducers/uischemas.js +0 -57
- package/lib/reducers/uischemas.js.map +0 -1
- package/lib/store.js +0 -3
- package/lib/store.js.map +0 -1
- package/lib/testers/index.js +0 -402
- package/lib/testers/index.js.map +0 -1
- package/lib/util/Formatted.js +0 -3
- package/lib/util/Formatted.js.map +0 -1
- package/lib/util/array.js +0 -19
- package/lib/util/array.js.map +0 -1
- package/lib/util/cell.js +0 -133
- package/lib/util/cell.js.map +0 -1
- package/lib/util/combinators.js +0 -56
- package/lib/util/combinators.js.map +0 -1
- package/lib/util/ids.js +0 -50
- package/lib/util/ids.js.map +0 -1
- package/lib/util/index.js +0 -132
- package/lib/util/index.js.map +0 -1
- package/lib/util/label.js +0 -70
- package/lib/util/label.js.map +0 -1
- package/lib/util/path.js +0 -84
- package/lib/util/path.js.map +0 -1
- package/lib/util/renderer.js +0 -447
- package/lib/util/renderer.js.map +0 -1
- package/lib/util/resolvers.js +0 -165
- package/lib/util/resolvers.js.map +0 -1
- package/lib/util/runtime.js +0 -159
- package/lib/util/runtime.js.map +0 -1
- package/lib/util/schema.js +0 -16
- package/lib/util/schema.js.map +0 -1
- package/lib/util/type.js.map +0 -1
- package/lib/util/uischema.js +0 -52
- package/lib/util/uischema.js.map +0 -1
- package/lib/util/validator.js.map +0 -1
- package/webpack.build.js +0 -13
package/src/generators/index.ts
CHANGED
|
@@ -22,25 +22,7 @@
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
import { ControlElement, JsonSchema, UISchemaElement } from '../';
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export const Generate: {
|
|
31
|
-
jsonSchema(instance: Object, options?: any): JsonSchema;
|
|
32
|
-
uiSchema(
|
|
33
|
-
jsonSchema: JsonSchema,
|
|
34
|
-
layoutType?: string,
|
|
35
|
-
prefix?: string,
|
|
36
|
-
rootSchema?: JsonSchema
|
|
37
|
-
): UISchemaElement;
|
|
38
|
-
controlElement(ref: string): ControlElement;
|
|
39
|
-
} = {
|
|
40
|
-
jsonSchema: generateJsonSchema,
|
|
41
|
-
uiSchema: generateDefaultUISchema,
|
|
42
|
-
controlElement: createControlElement
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export { generateJsonSchema };
|
|
46
|
-
export { generateDefaultUISchema };
|
|
26
|
+
export * from './Generate';
|
|
27
|
+
export * from './schema';
|
|
28
|
+
export * from './uischema';
|
package/src/generators/schema.ts
CHANGED
|
@@ -22,20 +22,20 @@
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
+
|
|
25
26
|
import isEmpty from 'lodash/isEmpty';
|
|
26
27
|
import startCase from 'lodash/startCase';
|
|
27
28
|
import keys from 'lodash/keys';
|
|
28
|
-
import { JsonSchema } from '../models/jsonSchema';
|
|
29
29
|
import {
|
|
30
30
|
ControlElement,
|
|
31
31
|
isGroup,
|
|
32
32
|
isLayout,
|
|
33
|
+
JsonSchema,
|
|
33
34
|
LabelElement,
|
|
34
35
|
Layout,
|
|
35
36
|
UISchemaElement
|
|
36
|
-
} from '../models
|
|
37
|
-
import { resolveSchema } from '../util
|
|
38
|
-
import { deriveTypes } from '../util';
|
|
37
|
+
} from '../models';
|
|
38
|
+
import { deriveTypes, resolveSchema } from '../util';
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
41
|
* Creates a new ILayout.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ErrorObject } from 'ajv';
|
|
2
|
+
import { JsonSchema, UISchemaElement } from '../models';
|
|
3
|
+
|
|
4
|
+
export type Translator = {
|
|
5
|
+
(id: string, defaultMessage: string, values?: any): string;
|
|
6
|
+
(id: string, defaultMessage: undefined, values?: any): string | undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type ErrorTranslator = (error: ErrorObject, translate: Translator, uischema?: UISchemaElement) => string;
|
|
10
|
+
|
|
11
|
+
export interface JsonFormsI18nState {
|
|
12
|
+
locale?: string;
|
|
13
|
+
translate?: Translator;
|
|
14
|
+
translateError?: ErrorTranslator;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type i18nJsonSchema = JsonSchema & {i18n?: string};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ErrorObject } from 'ajv';
|
|
2
|
+
import { UISchemaElement } from '../models';
|
|
3
|
+
import { getControlPath } from '../reducers';
|
|
4
|
+
import { formatErrorMessage } from '../util';
|
|
5
|
+
import { i18nJsonSchema, ErrorTranslator, Translator } from './i18nTypes';
|
|
6
|
+
|
|
7
|
+
export const getI18nKeyPrefixBySchema = (
|
|
8
|
+
schema: i18nJsonSchema | undefined,
|
|
9
|
+
uischema: UISchemaElement | undefined
|
|
10
|
+
): string | undefined => {
|
|
11
|
+
return uischema?.options?.i18n ?? schema?.i18n ?? undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Transforms a given path to a prefix which can be used for i18n keys.
|
|
16
|
+
* Returns 'root' for empty paths and removes array indices
|
|
17
|
+
*/
|
|
18
|
+
export const transformPathToI18nPrefix = (path: string) => {
|
|
19
|
+
return (
|
|
20
|
+
path
|
|
21
|
+
?.split('.')
|
|
22
|
+
.filter(segment => !/^\d+$/.test(segment))
|
|
23
|
+
.join('.') || 'root'
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getI18nKeyPrefix = (
|
|
28
|
+
schema: i18nJsonSchema | undefined,
|
|
29
|
+
uischema: UISchemaElement | undefined,
|
|
30
|
+
path: string | undefined
|
|
31
|
+
): string | undefined => {
|
|
32
|
+
return (
|
|
33
|
+
getI18nKeyPrefixBySchema(schema, uischema) ??
|
|
34
|
+
transformPathToI18nPrefix(path)
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const getI18nKey = (
|
|
39
|
+
schema: i18nJsonSchema | undefined,
|
|
40
|
+
uischema: UISchemaElement | undefined,
|
|
41
|
+
path: string | undefined,
|
|
42
|
+
key: string
|
|
43
|
+
): string | undefined => {
|
|
44
|
+
return `${getI18nKeyPrefix(schema, uischema, path)}.${key}`;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const defaultTranslator: Translator = (_id: string, defaultMessage: string | undefined) => defaultMessage;
|
|
48
|
+
|
|
49
|
+
export const defaultErrorTranslator: ErrorTranslator = (error, t, uischema) => {
|
|
50
|
+
// check whether there is a special keyword message
|
|
51
|
+
const i18nKey = getI18nKey(
|
|
52
|
+
error.parentSchema,
|
|
53
|
+
uischema,
|
|
54
|
+
getControlPath(error),
|
|
55
|
+
`error.${error.keyword}`
|
|
56
|
+
);
|
|
57
|
+
const specializedKeywordMessage = t(i18nKey, undefined);
|
|
58
|
+
if (specializedKeywordMessage !== undefined) {
|
|
59
|
+
return specializedKeywordMessage;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// check whether there is a generic keyword message
|
|
63
|
+
const genericKeywordMessage = t(`error.${error.keyword}`, undefined);
|
|
64
|
+
if (genericKeywordMessage !== undefined) {
|
|
65
|
+
return genericKeywordMessage;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// check whether there is a customization for the default message
|
|
69
|
+
const messageCustomization = t(error.message, undefined);
|
|
70
|
+
if (messageCustomization !== undefined) {
|
|
71
|
+
return messageCustomization;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// rewrite required property messages (if they were not customized) as we place them next to the respective input
|
|
75
|
+
if (error.keyword === 'required' && error.message?.startsWith('must have required property')) {
|
|
76
|
+
return t('is a required property', 'is a required property');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return error.message;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns the determined error message for the given errors.
|
|
84
|
+
* All errors must correspond to the given schema, uischema or path.
|
|
85
|
+
*/
|
|
86
|
+
export const getCombinedErrorMessage = (
|
|
87
|
+
errors: ErrorObject[],
|
|
88
|
+
et: ErrorTranslator,
|
|
89
|
+
t: Translator,
|
|
90
|
+
schema?: i18nJsonSchema,
|
|
91
|
+
uischema?: UISchemaElement,
|
|
92
|
+
path?: string
|
|
93
|
+
) => {
|
|
94
|
+
if (errors.length > 0 && t) {
|
|
95
|
+
// check whether there is a special message which overwrites all others
|
|
96
|
+
const customErrorKey = getI18nKey(schema, uischema, path, 'error.custom');
|
|
97
|
+
const specializedErrorMessage = t(customErrorKey, undefined);
|
|
98
|
+
if (specializedErrorMessage !== undefined) {
|
|
99
|
+
return specializedErrorMessage;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return formatErrorMessage(
|
|
103
|
+
errors.map(error => et(error, t, uischema))
|
|
104
|
+
);
|
|
105
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -22,40 +22,16 @@
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
export * from './util';
|
|
26
25
|
|
|
27
|
-
export { JsonSchema } from './models/jsonSchema';
|
|
28
|
-
export { JsonSchema4 } from './models/jsonSchema4';
|
|
29
|
-
export { JsonSchema7 } from './models/jsonSchema7';
|
|
30
|
-
export * from './store';
|
|
31
26
|
export * from './actions';
|
|
32
|
-
|
|
33
|
-
export { Actions };
|
|
34
|
-
export * from './reducers';
|
|
27
|
+
export * as Actions from './actions';
|
|
35
28
|
export * from './generators';
|
|
36
|
-
|
|
37
|
-
export * from './
|
|
38
|
-
|
|
39
|
-
import * as Test from './testers';
|
|
29
|
+
export * from './models';
|
|
30
|
+
export * from './reducers';
|
|
40
31
|
export * from './testers';
|
|
41
|
-
export
|
|
42
|
-
|
|
43
|
-
import { convertToValidClassName, createLabelDescriptionFrom } from './util';
|
|
44
|
-
import { ControlElement, LabelDescription } from './models/uischema';
|
|
45
|
-
import { JsonSchema } from './models/jsonSchema';
|
|
46
|
-
|
|
47
|
-
const Helpers: {
|
|
48
|
-
createLabelDescriptionFrom(
|
|
49
|
-
withLabel: ControlElement,
|
|
50
|
-
schema: JsonSchema
|
|
51
|
-
): LabelDescription;
|
|
52
|
-
convertToValidClassName(s: string): string;
|
|
53
|
-
} = {
|
|
54
|
-
createLabelDescriptionFrom,
|
|
55
|
-
convertToValidClassName
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export { Helpers };
|
|
59
|
-
|
|
32
|
+
export * as Test from './testers';
|
|
60
33
|
export * from './util';
|
|
34
|
+
|
|
35
|
+
export * from './Helpers';
|
|
61
36
|
export * from './store';
|
|
37
|
+
export * from './i18n';
|
package/src/models/draft4.ts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
The MIT License
|
|
4
|
-
|
|
3
|
+
|
|
5
4
|
Copyright (c) 2017-2019 EclipseSource Munich
|
|
6
5
|
https://github.com/eclipsesource/jsonforms
|
|
7
|
-
|
|
6
|
+
|
|
8
7
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
8
|
of this software and associated documentation files (the "Software"), to deal
|
|
10
9
|
in the Software without restriction, including without limitation the rights
|
|
11
10
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
11
|
copies of the Software, and to permit persons to whom the Software is
|
|
13
12
|
furnished to do so, subject to the following conditions:
|
|
14
|
-
|
|
13
|
+
|
|
15
14
|
The above copyright notice and this permission notice shall be included in
|
|
16
15
|
all copies or substantial portions of the Software.
|
|
17
|
-
|
|
16
|
+
|
|
18
17
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
18
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
19
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
@@ -23,5 +22,9 @@
|
|
|
23
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
23
|
THE SOFTWARE.
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
export * from './draft4';
|
|
27
|
+
export * from './jsonSchema';
|
|
28
|
+
export * from './jsonSchema4';
|
|
29
|
+
export * from './jsonSchema7';
|
|
30
|
+
export * from './uischema';
|
package/src/models/jsonSchema.ts
CHANGED
package/src/models/uischema.ts
CHANGED
package/src/reducers/cells.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
+
|
|
25
26
|
import { RankedTester } from '../testers';
|
|
26
27
|
import {
|
|
27
28
|
ADD_CELL,
|
|
@@ -29,7 +30,7 @@ import {
|
|
|
29
30
|
REMOVE_CELL,
|
|
30
31
|
RemoveCellRendererAction
|
|
31
32
|
} from '../actions';
|
|
32
|
-
import { Reducer } from '../util
|
|
33
|
+
import { Reducer } from '../util';
|
|
33
34
|
|
|
34
35
|
type ValidCellReducerActions = AddCellRendererAction | RemoveCellRendererAction;
|
|
35
36
|
|
package/src/reducers/config.ts
CHANGED
|
@@ -22,10 +22,11 @@
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
+
|
|
25
26
|
import merge from 'lodash/merge';
|
|
26
27
|
import { SET_CONFIG, SetConfigAction } from '../actions';
|
|
27
28
|
import { configDefault } from '../configDefault';
|
|
28
|
-
import { Reducer } from '../util
|
|
29
|
+
import { Reducer } from '../util';
|
|
29
30
|
|
|
30
31
|
const applyDefaultConfiguration = (config: any = {}) =>
|
|
31
32
|
merge({}, configDefault, config);
|
package/src/reducers/core.ts
CHANGED
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
+
|
|
25
26
|
import cloneDeep from 'lodash/cloneDeep';
|
|
26
27
|
import setFp from 'lodash/fp/set';
|
|
27
28
|
import get from 'lodash/get';
|
|
28
29
|
import filter from 'lodash/filter';
|
|
29
30
|
import isEqual from 'lodash/isEqual';
|
|
30
31
|
import isFunction from 'lodash/isFunction';
|
|
31
|
-
import
|
|
32
|
+
import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
|
32
33
|
import {
|
|
33
34
|
CoreActions,
|
|
34
35
|
INIT,
|
|
@@ -43,32 +44,20 @@ import {
|
|
|
43
44
|
UPDATE_CORE,
|
|
44
45
|
UpdateCoreAction
|
|
45
46
|
} from '../actions';
|
|
46
|
-
import { createAjv } from '../util
|
|
47
|
-
import {
|
|
48
|
-
import { JsonSchema, UISchemaElement } from '..';
|
|
47
|
+
import { createAjv, Reducer } from '../util';
|
|
48
|
+
import { JsonSchema, UISchemaElement } from '../models';
|
|
49
49
|
|
|
50
|
-
const validate = (validator: ValidateFunction, data: any): ErrorObject[] => {
|
|
50
|
+
export const validate = (validator: ValidateFunction | undefined, data: any): ErrorObject[] => {
|
|
51
|
+
if (validator === undefined) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
51
54
|
const valid = validator(data);
|
|
52
55
|
if (valid) {
|
|
53
56
|
return [];
|
|
54
57
|
}
|
|
55
|
-
|
|
56
58
|
return validator.errors;
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
export const sanitizeErrors = (validator: ValidateFunction, data: any) => {
|
|
60
|
-
if (validator === alwaysValid) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
return validate(validator, data).map(error => {
|
|
64
|
-
error.dataPath = error.dataPath.replace(/\//g, '.').substr(1);
|
|
65
|
-
|
|
66
|
-
return error;
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
const alwaysValid: ValidateFunction = () => true;
|
|
71
|
-
|
|
72
61
|
export type ValidationMode = 'ValidateAndShow' | 'ValidateAndHide' | 'NoValidation';
|
|
73
62
|
|
|
74
63
|
export interface JsonFormsCore {
|
|
@@ -86,9 +75,9 @@ const initState: JsonFormsCore = {
|
|
|
86
75
|
schema: {},
|
|
87
76
|
uischema: undefined,
|
|
88
77
|
errors: [],
|
|
89
|
-
validator:
|
|
78
|
+
validator: undefined,
|
|
90
79
|
ajv: undefined,
|
|
91
|
-
validationMode: 'ValidateAndShow'
|
|
80
|
+
validationMode: 'ValidateAndShow',
|
|
92
81
|
};
|
|
93
82
|
|
|
94
83
|
const reuseAjvForSchema = (ajv: Ajv, schema: JsonSchema): Ajv => {
|
|
@@ -104,7 +93,7 @@ const getOrCreateAjv = (state: JsonFormsCore, action?: InitAction | UpdateCoreAc
|
|
|
104
93
|
// options object with ajv
|
|
105
94
|
return action.options.ajv;
|
|
106
95
|
} else if (
|
|
107
|
-
action.options !== undefined
|
|
96
|
+
action.options !== undefined
|
|
108
97
|
) {
|
|
109
98
|
// it is not an option object => should be ajv itself => check for compile function
|
|
110
99
|
if (isFunction(action.options.compile)) {
|
|
@@ -154,8 +143,8 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
154
143
|
const thisAjv = getOrCreateAjv(state, action);
|
|
155
144
|
|
|
156
145
|
const validationMode = getValidationMode(state, action);
|
|
157
|
-
const v = validationMode === 'NoValidation' ?
|
|
158
|
-
const e =
|
|
146
|
+
const v = validationMode === 'NoValidation' ? undefined : thisAjv.compile(action.schema);
|
|
147
|
+
const e = validate(v, action.data);
|
|
159
148
|
|
|
160
149
|
return {
|
|
161
150
|
...state,
|
|
@@ -165,7 +154,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
165
154
|
errors: e,
|
|
166
155
|
validator: v,
|
|
167
156
|
ajv: thisAjv,
|
|
168
|
-
validationMode
|
|
157
|
+
validationMode,
|
|
169
158
|
};
|
|
170
159
|
}
|
|
171
160
|
case UPDATE_CORE: {
|
|
@@ -181,11 +170,11 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
181
170
|
// revalidate only if necessary
|
|
182
171
|
validator =
|
|
183
172
|
validationMode === 'NoValidation'
|
|
184
|
-
?
|
|
173
|
+
? undefined
|
|
185
174
|
: thisAjv.compile(action.schema);
|
|
186
|
-
errors =
|
|
175
|
+
errors = validate(validator, action.data);
|
|
187
176
|
} else if (state.data !== action.data) {
|
|
188
|
-
errors =
|
|
177
|
+
errors = validate(validator, action.data);
|
|
189
178
|
}
|
|
190
179
|
|
|
191
180
|
const stateChanged =
|
|
@@ -195,24 +184,24 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
195
184
|
state.ajv !== thisAjv ||
|
|
196
185
|
state.errors !== errors ||
|
|
197
186
|
state.validator !== validator ||
|
|
198
|
-
state.validationMode !== validationMode
|
|
187
|
+
state.validationMode !== validationMode
|
|
199
188
|
return stateChanged
|
|
200
189
|
? {
|
|
201
190
|
...state,
|
|
202
|
-
data:
|
|
203
|
-
schema:
|
|
204
|
-
uischema:
|
|
205
|
-
ajv: thisAjv
|
|
191
|
+
data: action.data,
|
|
192
|
+
schema: action.schema,
|
|
193
|
+
uischema: action.uischema,
|
|
194
|
+
ajv: thisAjv,
|
|
206
195
|
errors: isEqual(errors, state.errors) ? state.errors : errors,
|
|
207
|
-
validator: validator
|
|
208
|
-
validationMode: validationMode
|
|
196
|
+
validator: validator,
|
|
197
|
+
validationMode: validationMode,
|
|
209
198
|
}
|
|
210
199
|
: state;
|
|
211
200
|
}
|
|
212
201
|
case SET_AJV: {
|
|
213
202
|
const currentAjv = action.ajv;
|
|
214
|
-
const validator = state.validationMode === 'NoValidation' ?
|
|
215
|
-
const errors =
|
|
203
|
+
const validator = state.validationMode === 'NoValidation' ? undefined : currentAjv.compile(state.schema);
|
|
204
|
+
const errors = validate(validator, state.data);
|
|
216
205
|
return {
|
|
217
206
|
...state,
|
|
218
207
|
validator,
|
|
@@ -224,7 +213,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
224
213
|
const v = needsNewValidator
|
|
225
214
|
? reuseAjvForSchema(state.ajv, action.schema).compile(action.schema)
|
|
226
215
|
: state.validator;
|
|
227
|
-
const errors =
|
|
216
|
+
const errors = validate(v, state.data);
|
|
228
217
|
return {
|
|
229
218
|
...state,
|
|
230
219
|
validator: v,
|
|
@@ -244,7 +233,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
244
233
|
} else if (action.path === '') {
|
|
245
234
|
// empty path is ok
|
|
246
235
|
const result = action.updater(cloneDeep(state.data));
|
|
247
|
-
const errors =
|
|
236
|
+
const errors = validate(state.validator, result);
|
|
248
237
|
return {
|
|
249
238
|
...state,
|
|
250
239
|
data: result,
|
|
@@ -258,7 +247,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
258
247
|
newData,
|
|
259
248
|
state.data === undefined ? {} : state.data
|
|
260
249
|
);
|
|
261
|
-
const errors =
|
|
250
|
+
const errors = validate(state.validator, newState);
|
|
262
251
|
return {
|
|
263
252
|
...state,
|
|
264
253
|
data: newState,
|
|
@@ -277,17 +266,16 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
277
266
|
return state;
|
|
278
267
|
}
|
|
279
268
|
if (action.validationMode === 'NoValidation') {
|
|
280
|
-
const errors =
|
|
269
|
+
const errors = validate(undefined, state.data);
|
|
281
270
|
return {
|
|
282
271
|
...state,
|
|
283
|
-
validator: alwaysValid,
|
|
284
272
|
errors,
|
|
285
273
|
validationMode: action.validationMode
|
|
286
274
|
};
|
|
287
275
|
}
|
|
288
276
|
if (state.validationMode === 'NoValidation') {
|
|
289
277
|
const validator = reuseAjvForSchema(state.ajv, state.schema).compile(state.schema);
|
|
290
|
-
const errors =
|
|
278
|
+
const errors = validate(validator, state.data);
|
|
291
279
|
return {
|
|
292
280
|
...state,
|
|
293
281
|
validator,
|
|
@@ -310,6 +298,40 @@ export const extractSchema = (state: JsonFormsCore) => get(state, 'schema');
|
|
|
310
298
|
export const extractUiSchema = (state: JsonFormsCore) => get(state, 'uischema');
|
|
311
299
|
export const extractAjv = (state: JsonFormsCore) => get(state, 'ajv');
|
|
312
300
|
|
|
301
|
+
const getInvalidProperty = (error: ErrorObject): string | undefined => {
|
|
302
|
+
switch (error.keyword) {
|
|
303
|
+
case 'required':
|
|
304
|
+
case 'dependencies':
|
|
305
|
+
return error.params.missingProperty;
|
|
306
|
+
case 'additionalProperties':
|
|
307
|
+
return error.params.additionalProperty;
|
|
308
|
+
default:
|
|
309
|
+
return undefined;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
export const getControlPath = (error: ErrorObject) => {
|
|
314
|
+
const dataPath = (error as any).dataPath;
|
|
315
|
+
// older AJV version
|
|
316
|
+
if (dataPath) {
|
|
317
|
+
return dataPath.replace(/\//g, '.').substr(1);
|
|
318
|
+
}
|
|
319
|
+
// dataPath was renamed to instancePath in AJV v8
|
|
320
|
+
var controlPath: string = error.instancePath;
|
|
321
|
+
|
|
322
|
+
// change '/' chars to '.'
|
|
323
|
+
controlPath = controlPath.replace(/\//g, '.');
|
|
324
|
+
|
|
325
|
+
const invalidProperty = getInvalidProperty(error);
|
|
326
|
+
if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
|
|
327
|
+
controlPath = `${controlPath}.${invalidProperty}`;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// remove '.' chars at the beginning of paths
|
|
331
|
+
controlPath = controlPath.replace(/^./, '');
|
|
332
|
+
return controlPath;
|
|
333
|
+
}
|
|
334
|
+
|
|
313
335
|
export const errorsAt = (
|
|
314
336
|
instancePath: string,
|
|
315
337
|
schema: JsonSchema,
|
|
@@ -319,15 +341,15 @@ export const errorsAt = (
|
|
|
319
341
|
const combinatorPaths = filter(
|
|
320
342
|
errors,
|
|
321
343
|
error => error.keyword === 'oneOf' || error.keyword === 'anyOf'
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
let result = matchPath(
|
|
344
|
+
).map(error => getControlPath(error));
|
|
345
|
+
|
|
346
|
+
return filter(errors, error => {
|
|
347
|
+
// Filter errors that match any keyword that we don't want to show in the UI
|
|
348
|
+
if (filteredErrorKeywords.indexOf(error.keyword) !== -1) {
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
const controlPath = getControlPath(error);
|
|
352
|
+
let result = matchPath(controlPath);
|
|
331
353
|
// In anyOf and oneOf blocks with "primitive" (i.e. string, number etc.) or array subschemas,
|
|
332
354
|
// we want to make sure that errors are only shown for the correct subschema.
|
|
333
355
|
// Therefore, we compare the error's parent schema with the property's schema.
|
|
@@ -22,13 +22,14 @@
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
+
|
|
25
26
|
import {
|
|
26
27
|
ADD_DEFAULT_DATA,
|
|
27
28
|
RegisterDefaultDataAction,
|
|
28
29
|
REMOVE_DEFAULT_DATA,
|
|
29
30
|
UnregisterDefaultDataAction
|
|
30
31
|
} from '../actions';
|
|
31
|
-
import { Reducer } from '../util
|
|
32
|
+
import { Reducer } from '../util';
|
|
32
33
|
|
|
33
34
|
export interface JsonFormsDefaultDataRegistryEntry {
|
|
34
35
|
schemaPath: string;
|