@jsonforms/core 3.0.0-alpha.1 → 3.0.0-beta.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/docs/assets/js/search.json +1 -1
- package/docs/globals.html +822 -405
- package/docs/index.html +69 -36
- package/docs/interfaces/addcellrendereraction.html +3 -3
- package/docs/interfaces/addrendereraction.html +3 -3
- package/docs/interfaces/adduischemaaction.html +3 -3
- package/docs/interfaces/arraycontrolprops.html +21 -21
- package/docs/interfaces/arraylayoutprops.html +21 -21
- package/docs/interfaces/cellprops.html +14 -14
- package/docs/interfaces/combinatorrendererprops.html +13 -13
- package/docs/interfaces/controlprops.html +16 -16
- package/docs/interfaces/controlstate.html +2 -2
- package/docs/interfaces/controlwithdetailprops.html +17 -17
- 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/initaction.html +6 -6
- package/docs/interfaces/initactionoptions.html +3 -3
- package/docs/interfaces/jsonformscore.html +7 -7
- package/docs/interfaces/{jsonformslocalestate.html → jsonformsi18nstate.html} +20 -20
- package/docs/interfaces/jsonformsprops.html +9 -9
- package/docs/interfaces/jsonformssubstates.html +11 -1
- package/docs/interfaces/layoutprops.html +10 -10
- 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/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 +17 -17
- package/docs/interfaces/statepropsofarraylayout.html +17 -17
- package/docs/interfaces/statepropsofcell.html +13 -13
- package/docs/interfaces/statepropsofcombinator.html +12 -12
- package/docs/interfaces/statepropsofcontrol.html +15 -15
- package/docs/interfaces/statepropsofcontrolwithdetail.html +16 -16
- 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/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/withclassname.html +1 -1
- package/lib/Helpers.d.ts +5 -5
- package/lib/actions/actions.d.ts +181 -177
- package/lib/actions/index.d.ts +1 -1
- package/lib/configDefault.d.ts +6 -6
- package/lib/generators/Generate.d.ts +6 -6
- package/lib/generators/index.d.ts +3 -3
- package/lib/generators/schema.d.ts +8 -8
- package/lib/generators/uischema.d.ts +12 -12
- 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 -10
- 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 -5
- 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 -9
- package/lib/reducers/reducers.d.ts +29 -36
- package/lib/reducers/renderers.d.ts +10 -10
- package/lib/reducers/selectors.d.ts +15 -15
- package/lib/reducers/uischemas.d.ts +10 -10
- package/lib/store.d.ts +53 -52
- package/lib/testers/index.d.ts +1 -1
- package/lib/testers/testers.d.ts +203 -203
- 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 -10
- package/lib/util/ids.d.ts +3 -3
- package/lib/util/index.d.ts +15 -15
- package/lib/util/label.d.ts +9 -9
- package/lib/util/path.d.ts +25 -25
- package/lib/util/renderer.d.ts +398 -387
- 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 -31
- package/lib/util/validator.d.ts +3 -2
- package/package.json +18 -14
- package/rollup.config.js +44 -0
- package/src/actions/actions.ts +46 -36
- 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 +1 -0
- package/src/reducers/core.ts +70 -48
- package/src/reducers/i18n.ts +41 -35
- package/src/reducers/reducers.ts +10 -29
- package/src/reducers/selectors.ts +1 -1
- package/src/store.ts +4 -4
- package/src/util/cell.ts +26 -6
- package/src/util/renderer.ts +127 -38
- package/src/util/runtime.ts +1 -1
- package/src/util/util.ts +1 -1
- package/src/util/validator.ts +5 -9
- package/stats.html +3279 -0
- package/{lib/reducers/cells.js → test/i18n/i18nUtil.test.ts} +25 -17
- package/test/reducers/core.test.ts +31 -44
- package/test/util/cell.test.ts +2 -2
- package/test/util/renderer.test.ts +488 -35
- package/lib/Helpers.js +0 -32
- package/lib/Helpers.js.map +0 -1
- package/lib/actions/actions.js +0 -149
- package/lib/actions/actions.js.map +0 -1
- package/lib/actions/index.js +0 -29
- package/lib/actions/index.js.map +0 -1
- package/lib/configDefault.js +0 -47
- package/lib/configDefault.js.map +0 -1
- package/lib/generators/Generate.js +0 -34
- package/lib/generators/Generate.js.map +0 -1
- package/lib/generators/index.js +0 -31
- 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 -166
- package/lib/generators/uischema.js.map +0 -1
- package/lib/index.js +0 -37
- 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/index.js +0 -30
- package/lib/models/index.js.map +0 -1
- package/lib/models/jsonSchema.js +0 -27
- package/lib/models/jsonSchema.js.map +0 -1
- package/lib/models/jsonSchema4.js +0 -30
- 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 -55
- package/lib/models/uischema.js.map +0 -1
- 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 -65
- package/lib/reducers/i18n.js.map +0 -1
- package/lib/reducers/index.js +0 -37
- package/lib/reducers/index.js.map +0 -1
- package/lib/reducers/reducers.js +0 -99
- package/lib/reducers/reducers.js.map +0 -1
- package/lib/reducers/renderers.js +0 -41
- package/lib/reducers/renderers.js.map +0 -1
- package/lib/reducers/selectors.js +0 -47
- package/lib/reducers/selectors.js.map +0 -1
- package/lib/reducers/uischemas.js +0 -57
- package/lib/reducers/uischemas.js.map +0 -1
- package/lib/store.js +0 -27
- package/lib/store.js.map +0 -1
- package/lib/testers/index.js +0 -29
- package/lib/testers/index.js.map +0 -1
- package/lib/testers/testers.js +0 -401
- package/lib/testers/testers.js.map +0 -1
- package/lib/util/Formatted.js +0 -27
- package/lib/util/Formatted.js.map +0 -1
- package/lib/util/array.js +0 -43
- 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 -41
- 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 -85
- package/lib/util/path.js.map +0 -1
- package/lib/util/renderer.js +0 -451
- 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 -40
- package/lib/util/schema.js.map +0 -1
- package/lib/util/type.js +0 -27
- 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/util.js +0 -107
- package/lib/util/util.js.map +0 -1
- package/lib/util/validator.js +0 -36
- package/lib/util/validator.js.map +0 -1
- package/webpack.build.js +0 -13
package/src/reducers/reducers.ts
CHANGED
|
@@ -27,25 +27,20 @@ import { ControlElement, UISchemaElement } from '../models';
|
|
|
27
27
|
import {
|
|
28
28
|
coreReducer,
|
|
29
29
|
errorAt,
|
|
30
|
-
errorsAt,
|
|
31
|
-
JsonFormsCore,
|
|
32
30
|
subErrorsAt,
|
|
33
|
-
ValidationMode
|
|
34
31
|
} from './core';
|
|
35
32
|
import { defaultDataReducer } from './default-data';
|
|
36
33
|
import { rendererReducer } from './renderers';
|
|
37
34
|
import { JsonFormsState } from '../store';
|
|
35
|
+
import type { JsonFormsUISchemaRegistryEntry } from './uischemas';
|
|
38
36
|
import {
|
|
39
37
|
findMatchingUISchema,
|
|
40
|
-
JsonFormsUISchemaRegistryEntry,
|
|
41
38
|
uischemaRegistryReducer,
|
|
42
|
-
UISchemaTester
|
|
43
39
|
} from './uischemas';
|
|
44
40
|
import {
|
|
41
|
+
fetchErrorTranslator,
|
|
45
42
|
fetchLocale,
|
|
46
|
-
|
|
47
|
-
findLocalizedUISchema,
|
|
48
|
-
i18nReducer
|
|
43
|
+
i18nReducer,
|
|
49
44
|
} from './i18n';
|
|
50
45
|
|
|
51
46
|
import { Generate } from '../generators';
|
|
@@ -54,19 +49,8 @@ import { JsonSchema } from '../models/jsonSchema';
|
|
|
54
49
|
import { cellReducer } from './cells';
|
|
55
50
|
import { configReducer } from './config';
|
|
56
51
|
import get from 'lodash/get';
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
rendererReducer,
|
|
60
|
-
cellReducer,
|
|
61
|
-
coreReducer,
|
|
62
|
-
i18nReducer,
|
|
63
|
-
configReducer,
|
|
64
|
-
UISchemaTester,
|
|
65
|
-
uischemaRegistryReducer,
|
|
66
|
-
findMatchingUISchema,
|
|
67
|
-
JsonFormsUISchemaRegistryEntry
|
|
68
|
-
};
|
|
69
|
-
export { JsonFormsCore, ValidationMode };
|
|
52
|
+
import { fetchTranslator } from '.';
|
|
53
|
+
import { ErrorTranslator, Translator } from '../i18n';
|
|
70
54
|
|
|
71
55
|
export const jsonFormsReducerConfig = {
|
|
72
56
|
core: coreReducer,
|
|
@@ -75,7 +59,7 @@ export const jsonFormsReducerConfig = {
|
|
|
75
59
|
config: configReducer,
|
|
76
60
|
uischemas: uischemaRegistryReducer,
|
|
77
61
|
defaultData: defaultDataReducer,
|
|
78
|
-
i18n: i18nReducer
|
|
62
|
+
i18n: i18nReducer,
|
|
79
63
|
};
|
|
80
64
|
|
|
81
65
|
/**
|
|
@@ -126,8 +110,6 @@ export const getErrorAt = (instancePath: string, schema: JsonSchema) => (
|
|
|
126
110
|
return errorAt(instancePath, schema)(state.jsonforms.core);
|
|
127
111
|
};
|
|
128
112
|
|
|
129
|
-
export { errorsAt };
|
|
130
|
-
|
|
131
113
|
export const getSubErrorsAt = (instancePath: string, schema: JsonSchema) => (
|
|
132
114
|
state: JsonFormsState
|
|
133
115
|
) => subErrorsAt(instancePath, schema)(state.jsonforms.core);
|
|
@@ -137,11 +119,10 @@ export const getConfig = (state: JsonFormsState) => state.jsonforms.config;
|
|
|
137
119
|
export const getLocale = (state: JsonFormsState) =>
|
|
138
120
|
fetchLocale(get(state, 'jsonforms.i18n'));
|
|
139
121
|
|
|
140
|
-
export const
|
|
122
|
+
export const getTranslator = () => (
|
|
141
123
|
state: JsonFormsState
|
|
142
|
-
):
|
|
124
|
+
): Translator => fetchTranslator(get(state, 'jsonforms.i18n'));
|
|
143
125
|
|
|
144
|
-
export const
|
|
126
|
+
export const getErrorTranslator = () => (
|
|
145
127
|
state: JsonFormsState
|
|
146
|
-
):
|
|
147
|
-
findLocalizedUISchema(locale)(get(state, 'jsonforms.i18n'));
|
|
128
|
+
): ErrorTranslator => fetchErrorTranslator(get(state, 'jsonforms.i18n'));
|
package/src/store.ts
CHANGED
|
@@ -28,9 +28,9 @@ import {
|
|
|
28
28
|
JsonFormsCore,
|
|
29
29
|
JsonFormsCellRendererRegistryEntry,
|
|
30
30
|
JsonFormsRendererRegistryEntry,
|
|
31
|
-
JsonFormsLocaleState,
|
|
32
31
|
JsonFormsUISchemaRegistryEntry
|
|
33
32
|
} from './reducers';
|
|
33
|
+
import { JsonFormsI18nState } from './i18n';
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* JSONForms store.
|
|
@@ -65,11 +65,11 @@ export interface JsonFormsSubStates {
|
|
|
65
65
|
*/
|
|
66
66
|
cells?: JsonFormsCellRendererRegistryEntry[];
|
|
67
67
|
/**
|
|
68
|
-
*
|
|
68
|
+
* I18n settings.
|
|
69
69
|
*/
|
|
70
|
-
i18n?:
|
|
70
|
+
i18n?: JsonFormsI18nState;
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
72
|
+
* The UI schema registry used in detail renderers.
|
|
73
73
|
*/
|
|
74
74
|
uischemas?: JsonFormsUISchemaRegistryEntry[];
|
|
75
75
|
/**
|
package/src/util/cell.ts
CHANGED
|
@@ -25,13 +25,14 @@
|
|
|
25
25
|
|
|
26
26
|
import isEmpty from 'lodash/isEmpty';
|
|
27
27
|
import union from 'lodash/union';
|
|
28
|
+
import type { JsonFormsCellRendererRegistryEntry } from '../reducers';
|
|
28
29
|
import {
|
|
30
|
+
getAjv,
|
|
29
31
|
getConfig,
|
|
30
32
|
getData,
|
|
31
33
|
getErrorAt,
|
|
32
34
|
getSchema,
|
|
33
|
-
|
|
34
|
-
JsonFormsCellRendererRegistryEntry
|
|
35
|
+
getTranslator,
|
|
35
36
|
} from '../reducers';
|
|
36
37
|
import { AnyAction, Dispatch } from './type';
|
|
37
38
|
import {
|
|
@@ -54,8 +55,9 @@ import {
|
|
|
54
55
|
} from './renderer';
|
|
55
56
|
import { JsonFormsState } from '../store';
|
|
56
57
|
import { JsonSchema } from '../models';
|
|
58
|
+
import { getI18nKeyPrefix } from '../i18n';
|
|
57
59
|
|
|
58
|
-
export { JsonFormsCellRendererRegistryEntry };
|
|
60
|
+
export type { JsonFormsCellRendererRegistryEntry };
|
|
59
61
|
|
|
60
62
|
export interface OwnPropsOfCell extends OwnPropsOfControl {
|
|
61
63
|
data?: any;
|
|
@@ -196,8 +198,20 @@ export const defaultMapStateToEnumCellProps = (
|
|
|
196
198
|
const props: StatePropsOfCell = mapStateToCellProps(state, ownProps);
|
|
197
199
|
const options: EnumOption[] =
|
|
198
200
|
ownProps.options ||
|
|
199
|
-
props.schema.enum?.map(
|
|
200
|
-
|
|
201
|
+
props.schema.enum?.map(e =>
|
|
202
|
+
enumToEnumOptionMapper(
|
|
203
|
+
e,
|
|
204
|
+
getTranslator()(state),
|
|
205
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
206
|
+
)
|
|
207
|
+
) ||
|
|
208
|
+
(props.schema.const && [
|
|
209
|
+
enumToEnumOptionMapper(
|
|
210
|
+
props.schema.const,
|
|
211
|
+
getTranslator()(state),
|
|
212
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
213
|
+
)
|
|
214
|
+
]);
|
|
201
215
|
return {
|
|
202
216
|
...props,
|
|
203
217
|
options
|
|
@@ -217,7 +231,13 @@ export const mapStateToOneOfEnumCellProps = (
|
|
|
217
231
|
const props: StatePropsOfCell = mapStateToCellProps(state, ownProps);
|
|
218
232
|
const options: EnumOption[] =
|
|
219
233
|
ownProps.options ||
|
|
220
|
-
(props.schema.oneOf as JsonSchema[])?.map(
|
|
234
|
+
(props.schema.oneOf as JsonSchema[])?.map(oneOfSubSchema =>
|
|
235
|
+
oneOfToEnumOptionMapper(
|
|
236
|
+
oneOfSubSchema,
|
|
237
|
+
getTranslator()(state),
|
|
238
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
239
|
+
)
|
|
240
|
+
);
|
|
221
241
|
return {
|
|
222
242
|
...props,
|
|
223
243
|
options
|
package/src/util/renderer.ts
CHANGED
|
@@ -25,8 +25,11 @@
|
|
|
25
25
|
|
|
26
26
|
import get from 'lodash/get';
|
|
27
27
|
import { ControlElement, JsonSchema, UISchemaElement } from '../models';
|
|
28
|
-
import union from 'lodash/union';
|
|
29
28
|
import find from 'lodash/find';
|
|
29
|
+
import type {
|
|
30
|
+
JsonFormsCellRendererRegistryEntry,
|
|
31
|
+
JsonFormsRendererRegistryEntry,
|
|
32
|
+
} from '../reducers';
|
|
30
33
|
import {
|
|
31
34
|
findUISchema,
|
|
32
35
|
getAjv,
|
|
@@ -34,28 +37,26 @@ import {
|
|
|
34
37
|
getConfig,
|
|
35
38
|
getData,
|
|
36
39
|
getErrorAt,
|
|
40
|
+
getErrorTranslator,
|
|
37
41
|
getRenderers,
|
|
38
42
|
getSchema,
|
|
39
43
|
getSubErrorsAt,
|
|
44
|
+
getTranslator,
|
|
40
45
|
getUiSchema,
|
|
41
|
-
JsonFormsCellRendererRegistryEntry,
|
|
42
|
-
JsonFormsRendererRegistryEntry,
|
|
43
46
|
JsonFormsUISchemaRegistryEntry,
|
|
44
47
|
} from '../reducers';
|
|
45
48
|
import { RankedTester } from '../testers';
|
|
46
|
-
import { isInherentlyEnabled,
|
|
49
|
+
import { hasShowRule, isInherentlyEnabled, isVisible } from './runtime';
|
|
47
50
|
import { createLabelDescriptionFrom } from './label';
|
|
48
51
|
import { CombinatorKeyword, resolveSubSchemas } from './combinators';
|
|
49
52
|
import { moveDown, moveUp } from './array';
|
|
50
53
|
import { AnyAction, Dispatch } from './type';
|
|
51
|
-
import {
|
|
54
|
+
import { Resolve } from './util';
|
|
52
55
|
import { composePaths, composeWithUi } from './path';
|
|
53
|
-
import { isVisible } from './runtime';
|
|
54
56
|
import { CoreActions, update } from '../actions';
|
|
55
57
|
import { ErrorObject } from 'ajv';
|
|
56
58
|
import { JsonFormsState } from '../store';
|
|
57
|
-
|
|
58
|
-
export { JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry };
|
|
59
|
+
import { getCombinedErrorMessage, getI18nKey, getI18nKeyPrefix, Translator } from '../i18n';
|
|
59
60
|
|
|
60
61
|
const isRequired = (
|
|
61
62
|
schema: JsonSchema,
|
|
@@ -86,16 +87,31 @@ const isRequired = (
|
|
|
86
87
|
* Adds an asterisk to the given label string based
|
|
87
88
|
* on the required parameter.
|
|
88
89
|
*
|
|
89
|
-
* @param {string} label the label string
|
|
90
|
+
* @param {string | undefined} label the label string
|
|
90
91
|
* @param {boolean} required whether the label belongs to a control which is required
|
|
92
|
+
* @param {boolean} hideRequiredAsterisk applied UI Schema option
|
|
91
93
|
* @returns {string} the label string
|
|
92
94
|
*/
|
|
93
95
|
export const computeLabel = (
|
|
94
|
-
label: string,
|
|
96
|
+
label: string | undefined,
|
|
95
97
|
required: boolean,
|
|
96
98
|
hideRequiredAsterisk: boolean
|
|
97
99
|
): string => {
|
|
98
|
-
return required && !hideRequiredAsterisk ?
|
|
100
|
+
return `${label ?? ''}${ required && !hideRequiredAsterisk ? '*' : ''}`;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Indicates whether to mark a field as required.
|
|
105
|
+
*
|
|
106
|
+
* @param {boolean} required whether the label belongs to a control which is required
|
|
107
|
+
* @param {boolean} hideRequiredAsterisk applied UI Schema option
|
|
108
|
+
* @returns {boolean} should the field be marked as required
|
|
109
|
+
*/
|
|
110
|
+
export const showAsRequired = (
|
|
111
|
+
required: boolean,
|
|
112
|
+
hideRequiredAsterisk: boolean
|
|
113
|
+
): boolean => {
|
|
114
|
+
return required && !hideRequiredAsterisk;
|
|
99
115
|
};
|
|
100
116
|
|
|
101
117
|
/**
|
|
@@ -139,7 +155,7 @@ export const createDefaultValue = (schema: JsonSchema) => {
|
|
|
139
155
|
*/
|
|
140
156
|
export const isDescriptionHidden = (
|
|
141
157
|
visible: boolean,
|
|
142
|
-
description: string,
|
|
158
|
+
description: string | undefined,
|
|
143
159
|
isFocused: boolean,
|
|
144
160
|
showUnfocusedDescription: boolean
|
|
145
161
|
): boolean => {
|
|
@@ -159,16 +175,45 @@ export interface EnumOption {
|
|
|
159
175
|
value: any;
|
|
160
176
|
}
|
|
161
177
|
|
|
162
|
-
export const enumToEnumOptionMapper = (
|
|
163
|
-
|
|
164
|
-
|
|
178
|
+
export const enumToEnumOptionMapper = (
|
|
179
|
+
e: any,
|
|
180
|
+
t?: Translator,
|
|
181
|
+
i18nKey?: string
|
|
182
|
+
): EnumOption => {
|
|
183
|
+
let label = typeof e === 'string' ? e : JSON.stringify(e);
|
|
184
|
+
if (t) {
|
|
185
|
+
if (i18nKey) {
|
|
186
|
+
label = t(`${i18nKey}.${label}`, label);
|
|
187
|
+
} else {
|
|
188
|
+
label = t(label, label);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return { label, value: e };
|
|
165
192
|
};
|
|
166
193
|
|
|
167
|
-
export const oneOfToEnumOptionMapper = (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
194
|
+
export const oneOfToEnumOptionMapper = (
|
|
195
|
+
e: any,
|
|
196
|
+
t?: Translator,
|
|
197
|
+
fallbackI18nKey?: string
|
|
198
|
+
): EnumOption => {
|
|
199
|
+
let label =
|
|
200
|
+
e.title ??
|
|
201
|
+
(typeof e.const === 'string' ? e.const : JSON.stringify(e.const));
|
|
202
|
+
if (t) {
|
|
203
|
+
// prefer schema keys as they can be more specialized
|
|
204
|
+
if (e.i18n) {
|
|
205
|
+
label = t(e.i18n, label);
|
|
206
|
+
} else if (fallbackI18nKey) {
|
|
207
|
+
label = t(`${fallbackI18nKey}.${label}`, label);
|
|
208
|
+
} else {
|
|
209
|
+
label = t(label, label);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
label,
|
|
214
|
+
value: e.const,
|
|
215
|
+
};
|
|
216
|
+
};
|
|
172
217
|
|
|
173
218
|
export interface OwnPropsOfRenderer {
|
|
174
219
|
/**
|
|
@@ -398,9 +443,8 @@ export const mapStateToControlProps = (
|
|
|
398
443
|
controlElement.scope,
|
|
399
444
|
rootSchema
|
|
400
445
|
);
|
|
401
|
-
const errors =
|
|
402
|
-
|
|
403
|
-
);
|
|
446
|
+
const errors = getErrorAt(path, resolvedSchema)(state);
|
|
447
|
+
|
|
404
448
|
const description =
|
|
405
449
|
resolvedSchema !== undefined ? resolvedSchema.description : '';
|
|
406
450
|
const data = Resolve.data(rootData, path);
|
|
@@ -415,18 +459,26 @@ export const mapStateToControlProps = (
|
|
|
415
459
|
rootData,
|
|
416
460
|
config
|
|
417
461
|
);
|
|
462
|
+
|
|
463
|
+
const schema = resolvedSchema ?? rootSchema;
|
|
464
|
+
const t = getTranslator()(state);
|
|
465
|
+
const te = getErrorTranslator()(state);
|
|
466
|
+
const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label);
|
|
467
|
+
const i18nDescription = t(getI18nKey(schema, uischema, path, 'description'), description);
|
|
468
|
+
const i18nErrorMessage = getCombinedErrorMessage(errors, te, t, schema, uischema, path);
|
|
469
|
+
|
|
418
470
|
return {
|
|
419
471
|
data,
|
|
420
|
-
description,
|
|
421
|
-
errors,
|
|
422
|
-
label,
|
|
472
|
+
description: i18nDescription,
|
|
473
|
+
errors: i18nErrorMessage,
|
|
474
|
+
label: i18nLabel,
|
|
423
475
|
visible,
|
|
424
476
|
enabled,
|
|
425
477
|
id,
|
|
426
478
|
path,
|
|
427
479
|
required,
|
|
428
|
-
uischema
|
|
429
|
-
schema
|
|
480
|
+
uischema,
|
|
481
|
+
schema,
|
|
430
482
|
config: getConfig(state),
|
|
431
483
|
cells: ownProps.cells || state.jsonforms.cells,
|
|
432
484
|
rootSchema
|
|
@@ -461,8 +513,20 @@ export const mapStateToEnumControlProps = (
|
|
|
461
513
|
const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
|
|
462
514
|
const options: EnumOption[] =
|
|
463
515
|
ownProps.options ||
|
|
464
|
-
props.schema.enum?.map(
|
|
465
|
-
|
|
516
|
+
props.schema.enum?.map(e =>
|
|
517
|
+
enumToEnumOptionMapper(
|
|
518
|
+
e,
|
|
519
|
+
getTranslator()(state),
|
|
520
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
521
|
+
)
|
|
522
|
+
) ||
|
|
523
|
+
(props.schema.const && [
|
|
524
|
+
enumToEnumOptionMapper(
|
|
525
|
+
props.schema.const,
|
|
526
|
+
getTranslator()(state),
|
|
527
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
528
|
+
)
|
|
529
|
+
]);
|
|
466
530
|
return {
|
|
467
531
|
...props,
|
|
468
532
|
options
|
|
@@ -482,7 +546,13 @@ export const mapStateToOneOfEnumControlProps = (
|
|
|
482
546
|
const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
|
|
483
547
|
const options: EnumOption[] =
|
|
484
548
|
ownProps.options ||
|
|
485
|
-
(props.schema.oneOf as JsonSchema[])?.map(
|
|
549
|
+
(props.schema.oneOf as JsonSchema[])?.map(oneOfSubSchema =>
|
|
550
|
+
oneOfToEnumOptionMapper(
|
|
551
|
+
oneOfSubSchema,
|
|
552
|
+
getTranslator()(state),
|
|
553
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
554
|
+
)
|
|
555
|
+
);
|
|
486
556
|
return {
|
|
487
557
|
...props,
|
|
488
558
|
options
|
|
@@ -504,8 +574,20 @@ export const mapStateToMultiEnumControlProps = (
|
|
|
504
574
|
const options: EnumOption[] =
|
|
505
575
|
ownProps.options ||
|
|
506
576
|
(items?.oneOf &&
|
|
507
|
-
(items.oneOf as JsonSchema[]).map(
|
|
508
|
-
|
|
577
|
+
(items.oneOf as JsonSchema[]).map(oneOfSubSchema =>
|
|
578
|
+
oneOfToEnumOptionMapper(
|
|
579
|
+
oneOfSubSchema,
|
|
580
|
+
state.jsonforms.i18n?.translate,
|
|
581
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
582
|
+
)
|
|
583
|
+
)) ||
|
|
584
|
+
items?.enum?.map(e =>
|
|
585
|
+
enumToEnumOptionMapper(
|
|
586
|
+
e,
|
|
587
|
+
state.jsonforms.i18n?.translate,
|
|
588
|
+
getI18nKeyPrefix(props.schema, props.uischema, props.path)
|
|
589
|
+
)
|
|
590
|
+
);
|
|
509
591
|
return {
|
|
510
592
|
...props,
|
|
511
593
|
options
|
|
@@ -840,7 +922,7 @@ export interface StatePropsOfCombinator extends OwnPropsOfControl {
|
|
|
840
922
|
data: any;
|
|
841
923
|
}
|
|
842
924
|
|
|
843
|
-
const mapStateToCombinatorRendererProps = (
|
|
925
|
+
export const mapStateToCombinatorRendererProps = (
|
|
844
926
|
state: JsonFormsState,
|
|
845
927
|
ownProps: OwnPropsOfControl,
|
|
846
928
|
keyword: CombinatorKeyword
|
|
@@ -961,9 +1043,18 @@ export const mapStateToArrayLayoutProps = (
|
|
|
961
1043
|
} = mapStateToControlWithDetailProps(state, ownProps);
|
|
962
1044
|
|
|
963
1045
|
const resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
|
|
964
|
-
|
|
965
|
-
|
|
1046
|
+
|
|
1047
|
+
// TODO Does not consider a specialized '.custom' error message overriding all other error messages
|
|
1048
|
+
// TODO Does not consider 'i18n' keys which are specified in the ui schemas of the sub errors
|
|
1049
|
+
const childErrors = getCombinedErrorMessage(
|
|
1050
|
+
getSubErrorsAt(path, resolvedSchema)(state),
|
|
1051
|
+
getErrorTranslator()(state),
|
|
1052
|
+
getTranslator()(state),
|
|
1053
|
+
undefined,
|
|
1054
|
+
undefined,
|
|
1055
|
+
undefined
|
|
966
1056
|
);
|
|
1057
|
+
|
|
967
1058
|
const allErrors =
|
|
968
1059
|
errors +
|
|
969
1060
|
(errors.length > 0 && childErrors.length > 0 ? '\n' : '') +
|
|
@@ -979,8 +1070,6 @@ export const mapStateToArrayLayoutProps = (
|
|
|
979
1070
|
};
|
|
980
1071
|
};
|
|
981
1072
|
|
|
982
|
-
export type CombinatorProps = StatePropsOfCombinator & DispatchPropsOfControl;
|
|
983
|
-
|
|
984
1073
|
/**
|
|
985
1074
|
* Props of an array control.
|
|
986
1075
|
*/
|
package/src/util/runtime.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
} from '../models';
|
|
37
37
|
import { resolveData } from './resolvers';
|
|
38
38
|
import { composeWithUi } from './path';
|
|
39
|
-
import
|
|
39
|
+
import Ajv from 'ajv';
|
|
40
40
|
import { getAjv } from '../reducers';
|
|
41
41
|
import { JsonFormsState } from '../store';
|
|
42
42
|
import { JsonSchema } from '../models/jsonSchema';
|
package/src/util/util.ts
CHANGED
|
@@ -31,7 +31,7 @@ import { JsonSchema, Scopable, UISchemaElement } from '..';
|
|
|
31
31
|
import { resolveData, resolveSchema } from './resolvers';
|
|
32
32
|
import { composePaths, toDataPathSegments } from './path';
|
|
33
33
|
import { isEnabled, isVisible } from './runtime';
|
|
34
|
-
import
|
|
34
|
+
import Ajv from 'ajv';
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Escape the given string such that it can be used as a class name,
|
package/src/util/validator.ts
CHANGED
|
@@ -22,21 +22,17 @@
|
|
|
22
22
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
|
|
26
|
-
import
|
|
25
|
+
import Ajv from 'ajv';
|
|
26
|
+
import addFormats from 'ajv-formats';
|
|
27
27
|
import { Options } from 'ajv';
|
|
28
|
-
import { Draft4 } from '../models';
|
|
29
28
|
|
|
30
29
|
export const createAjv = (options?: Options) => {
|
|
31
|
-
const ajv = new
|
|
32
|
-
schemaId: 'auto',
|
|
30
|
+
const ajv = new Ajv({
|
|
33
31
|
allErrors: true,
|
|
34
|
-
jsonPointers: true,
|
|
35
|
-
errorDataPath: 'property',
|
|
36
32
|
verbose: true,
|
|
33
|
+
strict: false,
|
|
37
34
|
...options
|
|
38
35
|
});
|
|
39
|
-
ajv
|
|
40
|
-
ajv.addMetaSchema(Draft4);
|
|
36
|
+
addFormats(ajv);
|
|
41
37
|
return ajv;
|
|
42
38
|
};
|