@jsonforms/core 2.5.2 → 3.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/docs/assets/js/search.json +1 -1
- package/docs/enums/ruleeffect.html +4 -4
- package/docs/globals.html +1124 -1081
- package/docs/index.html +70 -88
- 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 -17
- package/docs/interfaces/jsonformscellrendererregistryentry.html +2 -2
- package/docs/interfaces/jsonformscore.html +7 -21
- 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 -24
- 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/{setlocalizeduischemasaction.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 -23
- 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/{setlocalizedschemasaction.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/Helpers.js +33 -0
- package/lib/Helpers.js.map +1 -0
- package/lib/actions/actions.d.ts +181 -0
- package/lib/actions/actions.js +173 -0
- package/lib/actions/actions.js.map +1 -0
- package/lib/actions/index.d.ts +1 -180
- package/lib/actions/index.js +26 -122
- package/lib/actions/index.js.map +1 -1
- package/lib/configDefault.js +2 -1
- package/lib/configDefault.js.map +1 -1
- package/lib/generators/Generate.d.ts +6 -0
- package/lib/generators/Generate.js +35 -0
- package/lib/generators/Generate.js.map +1 -0
- package/lib/generators/index.d.ts +3 -10
- package/lib/generators/index.js +28 -9
- package/lib/generators/index.js.map +1 -1
- package/lib/generators/schema.d.ts +1 -1
- package/lib/generators/schema.js +3 -1
- package/lib/generators/schema.js.map +1 -1
- package/lib/generators/uischema.d.ts +1 -2
- package/lib/generators/uischema.js +12 -10
- package/lib/generators/uischema.js.map +1 -1
- package/lib/i18n/i18nTypes.d.ts +15 -0
- package/lib/i18n/i18nTypes.js +3 -0
- package/lib/i18n/i18nTypes.js.map +1 -0
- package/lib/i18n/i18nUtil.d.ts +18 -0
- package/lib/i18n/i18nUtil.js +71 -0
- package/lib/i18n/i18nUtil.js.map +1 -0
- package/lib/i18n/index.d.ts +2 -0
- package/lib/i18n/index.js +6 -0
- package/lib/i18n/index.js.map +1 -0
- package/lib/index.d.ts +6 -18
- package/lib/index.js +10 -15
- package/lib/index.js.map +1 -1
- package/lib/jsonforms-core.js +9 -12
- package/lib/jsonforms-core.js.map +1 -1
- package/lib/models/draft4.js +2 -1
- package/lib/models/draft4.js.map +1 -1
- package/lib/models/index.d.ts +5 -0
- package/lib/models/index.js +33 -0
- package/lib/models/index.js.map +1 -0
- package/lib/models/jsonSchema.js +24 -0
- package/lib/models/jsonSchema.js.map +1 -1
- package/lib/models/uischema.js +29 -2
- package/lib/models/uischema.js.map +1 -1
- package/lib/reducers/cells.d.ts +1 -1
- package/lib/reducers/cells.js +27 -1
- package/lib/reducers/cells.js.map +1 -1
- package/lib/reducers/config.d.ts +1 -1
- package/lib/reducers/config.js +5 -3
- package/lib/reducers/config.js.map +1 -1
- package/lib/reducers/core.d.ts +5 -7
- package/lib/reducers/core.js +78 -63
- package/lib/reducers/core.js.map +1 -1
- package/lib/reducers/default-data.d.ts +1 -1
- package/lib/reducers/default-data.js +6 -3
- package/lib/reducers/default-data.js.map +1 -1
- package/lib/reducers/i18n.d.ts +8 -11
- package/lib/reducers/i18n.js +40 -23
- package/lib/reducers/i18n.js.map +1 -1
- package/lib/reducers/index.d.ts +9 -49
- package/lib/reducers/index.js +33 -91
- package/lib/reducers/index.js.map +1 -1
- package/lib/reducers/reducers.d.ts +29 -0
- package/lib/reducers/reducers.js +98 -0
- package/lib/reducers/reducers.js.map +1 -0
- package/lib/reducers/renderers.d.ts +1 -1
- package/lib/reducers/renderers.js +27 -1
- package/lib/reducers/renderers.js.map +1 -1
- package/lib/reducers/selectors.d.ts +15 -0
- package/lib/reducers/selectors.js +56 -0
- package/lib/reducers/selectors.js.map +1 -0
- package/lib/reducers/uischemas.d.ts +2 -2
- package/lib/reducers/uischemas.js +9 -6
- package/lib/reducers/uischemas.js.map +1 -1
- package/lib/store.d.ts +5 -8
- package/lib/store.js +24 -0
- package/lib/store.js.map +1 -1
- package/lib/testers/index.d.ts +1 -204
- package/lib/testers/index.js +3 -376
- package/lib/testers/index.js.map +1 -1
- package/lib/testers/testers.d.ts +203 -0
- package/lib/testers/testers.js +421 -0
- package/lib/testers/testers.js.map +1 -0
- package/lib/util/Formatted.js +24 -0
- package/lib/util/Formatted.js.map +1 -1
- package/lib/util/array.js +25 -0
- package/lib/util/array.js.map +1 -1
- package/lib/util/cell.d.ts +11 -4
- package/lib/util/cell.js +60 -17
- package/lib/util/cell.js.map +1 -1
- package/lib/util/combinators.d.ts +2 -3
- package/lib/util/combinators.js +5 -2
- package/lib/util/combinators.js.map +1 -1
- package/lib/util/ids.js +8 -4
- package/lib/util/ids.js.map +1 -1
- package/lib/util/index.d.ts +11 -45
- package/lib/util/index.js +14 -104
- package/lib/util/index.js.map +1 -1
- package/lib/util/label.d.ts +1 -2
- package/lib/util/label.js +7 -4
- package/lib/util/label.js.map +1 -1
- package/lib/util/path.d.ts +2 -1
- package/lib/util/path.js +12 -6
- package/lib/util/path.js.map +1 -1
- package/lib/util/renderer.d.ts +19 -18
- package/lib/util/renderer.js +163 -78
- package/lib/util/renderer.js.map +1 -1
- package/lib/util/resolvers.d.ts +1 -14
- package/lib/util/resolvers.js +9 -215
- package/lib/util/resolvers.js.map +1 -1
- package/lib/util/runtime.d.ts +12 -2
- package/lib/util/runtime.js +59 -17
- package/lib/util/runtime.js.map +1 -1
- package/lib/util/schema.js +27 -1
- package/lib/util/schema.js.map +1 -1
- package/lib/util/uischema.d.ts +1 -1
- package/lib/util/uischema.js +11 -7
- package/lib/util/uischema.js.map +1 -1
- package/lib/util/util.d.ts +31 -0
- package/lib/util/util.js +112 -0
- package/lib/util/util.js.map +1 -0
- package/lib/util/validator.d.ts +3 -2
- package/lib/util/validator.js +6 -5
- package/lib/util/validator.js.map +1 -1
- package/package.json +6 -8
- package/src/Helpers.ts +38 -0
- package/src/actions/actions.ts +345 -0
- package/src/actions/index.ts +1 -312
- package/src/configDefault.ts +1 -0
- package/src/generators/Generate.ts +43 -0
- 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/src/models/index.ts +30 -0
- 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 -81
- package/src/reducers/default-data.ts +2 -1
- package/src/reducers/i18n.ts +42 -35
- package/src/reducers/index.ts +9 -158
- 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 +91 -19
- package/src/util/combinators.ts +2 -4
- package/src/util/ids.ts +1 -0
- package/src/util/index.ts +11 -126
- package/src/util/label.ts +2 -2
- package/src/util/path.ts +4 -1
- package/src/util/renderer.ts +170 -88
- package/src/util/resolvers.ts +2 -261
- package/src/util/runtime.ts +46 -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/test/i18n/i18nUtil.test.ts +48 -0
- package/test/reducers/core.test.ts +33 -226
- package/test/util/cell.test.ts +33 -2
- package/test/util/renderer.test.ts +543 -31
- package/test/util/resolvers.test.ts +1 -59
- package/test/util/runtime.test.ts +264 -4
- package/docs/interfaces/labels.html +0 -157
- package/docs/interfaces/schemaref.html +0 -160
- package/docs/interfaces/schemarefs.html +0 -138
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,14 +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 RefParser from 'json-schema-ref-parser';
|
|
32
|
+
import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
|
33
33
|
import {
|
|
34
34
|
CoreActions,
|
|
35
35
|
INIT,
|
|
@@ -44,32 +44,20 @@ import {
|
|
|
44
44
|
UPDATE_CORE,
|
|
45
45
|
UpdateCoreAction
|
|
46
46
|
} from '../actions';
|
|
47
|
-
import { createAjv } from '../util
|
|
48
|
-
import {
|
|
49
|
-
import { JsonSchema, UISchemaElement } from '..';
|
|
47
|
+
import { createAjv, Reducer } from '../util';
|
|
48
|
+
import { JsonSchema, UISchemaElement } from '../models';
|
|
50
49
|
|
|
51
|
-
const validate = (validator: ValidateFunction, data: any): ErrorObject[] => {
|
|
50
|
+
export const validate = (validator: ValidateFunction | undefined, data: any): ErrorObject[] => {
|
|
51
|
+
if (validator === undefined) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
52
54
|
const valid = validator(data);
|
|
53
55
|
if (valid) {
|
|
54
56
|
return [];
|
|
55
57
|
}
|
|
56
|
-
|
|
57
58
|
return validator.errors;
|
|
58
59
|
};
|
|
59
60
|
|
|
60
|
-
export const sanitizeErrors = (validator: ValidateFunction, data: any) => {
|
|
61
|
-
if (validator === alwaysValid) {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
return validate(validator, data).map(error => {
|
|
65
|
-
error.dataPath = error.dataPath.replace(/\//g, '.').substr(1);
|
|
66
|
-
|
|
67
|
-
return error;
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const alwaysValid: ValidateFunction = () => true;
|
|
72
|
-
|
|
73
61
|
export type ValidationMode = 'ValidateAndShow' | 'ValidateAndHide' | 'NoValidation';
|
|
74
62
|
|
|
75
63
|
export interface JsonFormsCore {
|
|
@@ -79,7 +67,6 @@ export interface JsonFormsCore {
|
|
|
79
67
|
errors?: ErrorObject[];
|
|
80
68
|
validator?: ValidateFunction;
|
|
81
69
|
ajv?: Ajv;
|
|
82
|
-
refParserOptions?: RefParser.Options;
|
|
83
70
|
validationMode?: ValidationMode;
|
|
84
71
|
}
|
|
85
72
|
|
|
@@ -88,10 +75,9 @@ const initState: JsonFormsCore = {
|
|
|
88
75
|
schema: {},
|
|
89
76
|
uischema: undefined,
|
|
90
77
|
errors: [],
|
|
91
|
-
validator:
|
|
78
|
+
validator: undefined,
|
|
92
79
|
ajv: undefined,
|
|
93
|
-
|
|
94
|
-
validationMode: 'ValidateAndShow'
|
|
80
|
+
validationMode: 'ValidateAndShow',
|
|
95
81
|
};
|
|
96
82
|
|
|
97
83
|
const reuseAjvForSchema = (ajv: Ajv, schema: JsonSchema): Ajv => {
|
|
@@ -107,8 +93,7 @@ const getOrCreateAjv = (state: JsonFormsCore, action?: InitAction | UpdateCoreAc
|
|
|
107
93
|
// options object with ajv
|
|
108
94
|
return action.options.ajv;
|
|
109
95
|
} else if (
|
|
110
|
-
action.options !== undefined
|
|
111
|
-
!hasRefParserOption(action.options)
|
|
96
|
+
action.options !== undefined
|
|
112
97
|
) {
|
|
113
98
|
// it is not an option object => should be ajv itself => check for compile function
|
|
114
99
|
if (isFunction(action.options.compile)) {
|
|
@@ -124,23 +109,6 @@ const getOrCreateAjv = (state: JsonFormsCore, action?: InitAction | UpdateCoreAc
|
|
|
124
109
|
return createAjv();
|
|
125
110
|
};
|
|
126
111
|
|
|
127
|
-
const getRefParserOptions = (
|
|
128
|
-
state: JsonFormsCore,
|
|
129
|
-
action?: InitAction | UpdateCoreAction
|
|
130
|
-
): RefParser.Options => {
|
|
131
|
-
if (action && hasRefParserOption(action.options)) {
|
|
132
|
-
return action.options.refParserOptions;
|
|
133
|
-
}
|
|
134
|
-
return state.refParserOptions;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const hasRefParserOption = (option: any): option is InitActionOptions => {
|
|
138
|
-
if (option) {
|
|
139
|
-
return option.refParserOptions !== undefined;
|
|
140
|
-
}
|
|
141
|
-
return false;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
112
|
const hasAjvOption = (option: any): option is InitActionOptions => {
|
|
145
113
|
if (option) {
|
|
146
114
|
return option.ajv !== undefined;
|
|
@@ -173,11 +141,10 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
173
141
|
switch (action.type) {
|
|
174
142
|
case INIT: {
|
|
175
143
|
const thisAjv = getOrCreateAjv(state, action);
|
|
176
|
-
const o = getRefParserOptions(state, action);
|
|
177
144
|
|
|
178
145
|
const validationMode = getValidationMode(state, action);
|
|
179
|
-
const v = validationMode === 'NoValidation' ?
|
|
180
|
-
const e =
|
|
146
|
+
const v = validationMode === 'NoValidation' ? undefined : thisAjv.compile(action.schema);
|
|
147
|
+
const e = validate(v, action.data);
|
|
181
148
|
|
|
182
149
|
return {
|
|
183
150
|
...state,
|
|
@@ -187,13 +154,11 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
187
154
|
errors: e,
|
|
188
155
|
validator: v,
|
|
189
156
|
ajv: thisAjv,
|
|
190
|
-
|
|
191
|
-
validationMode
|
|
157
|
+
validationMode,
|
|
192
158
|
};
|
|
193
159
|
}
|
|
194
160
|
case UPDATE_CORE: {
|
|
195
161
|
const thisAjv = getOrCreateAjv(state, action);
|
|
196
|
-
const refParserOptions = getRefParserOptions(state, action);
|
|
197
162
|
const validationMode = getValidationMode(state, action);
|
|
198
163
|
let validator = state.validator;
|
|
199
164
|
let errors = state.errors;
|
|
@@ -205,11 +170,11 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
205
170
|
// revalidate only if necessary
|
|
206
171
|
validator =
|
|
207
172
|
validationMode === 'NoValidation'
|
|
208
|
-
?
|
|
173
|
+
? undefined
|
|
209
174
|
: thisAjv.compile(action.schema);
|
|
210
|
-
errors =
|
|
175
|
+
errors = validate(validator, action.data);
|
|
211
176
|
} else if (state.data !== action.data) {
|
|
212
|
-
errors =
|
|
177
|
+
errors = validate(validator, action.data);
|
|
213
178
|
}
|
|
214
179
|
|
|
215
180
|
const stateChanged =
|
|
@@ -219,26 +184,24 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
219
184
|
state.ajv !== thisAjv ||
|
|
220
185
|
state.errors !== errors ||
|
|
221
186
|
state.validator !== validator ||
|
|
222
|
-
state.
|
|
223
|
-
state.validationMode !== validationMode;
|
|
187
|
+
state.validationMode !== validationMode
|
|
224
188
|
return stateChanged
|
|
225
189
|
? {
|
|
226
190
|
...state,
|
|
227
|
-
data:
|
|
228
|
-
schema:
|
|
229
|
-
uischema:
|
|
230
|
-
ajv: thisAjv
|
|
191
|
+
data: action.data,
|
|
192
|
+
schema: action.schema,
|
|
193
|
+
uischema: action.uischema,
|
|
194
|
+
ajv: thisAjv,
|
|
231
195
|
errors: isEqual(errors, state.errors) ? state.errors : errors,
|
|
232
|
-
validator: validator
|
|
233
|
-
|
|
234
|
-
validationMode: validationMode === state.validationMode ? state.validationMode : validationMode
|
|
196
|
+
validator: validator,
|
|
197
|
+
validationMode: validationMode,
|
|
235
198
|
}
|
|
236
199
|
: state;
|
|
237
200
|
}
|
|
238
201
|
case SET_AJV: {
|
|
239
202
|
const currentAjv = action.ajv;
|
|
240
|
-
const validator = state.validationMode === 'NoValidation' ?
|
|
241
|
-
const errors =
|
|
203
|
+
const validator = state.validationMode === 'NoValidation' ? undefined : currentAjv.compile(state.schema);
|
|
204
|
+
const errors = validate(validator, state.data);
|
|
242
205
|
return {
|
|
243
206
|
...state,
|
|
244
207
|
validator,
|
|
@@ -250,7 +213,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
250
213
|
const v = needsNewValidator
|
|
251
214
|
? reuseAjvForSchema(state.ajv, action.schema).compile(action.schema)
|
|
252
215
|
: state.validator;
|
|
253
|
-
const errors =
|
|
216
|
+
const errors = validate(v, state.data);
|
|
254
217
|
return {
|
|
255
218
|
...state,
|
|
256
219
|
validator: v,
|
|
@@ -270,7 +233,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
270
233
|
} else if (action.path === '') {
|
|
271
234
|
// empty path is ok
|
|
272
235
|
const result = action.updater(cloneDeep(state.data));
|
|
273
|
-
const errors =
|
|
236
|
+
const errors = validate(state.validator, result);
|
|
274
237
|
return {
|
|
275
238
|
...state,
|
|
276
239
|
data: result,
|
|
@@ -284,7 +247,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
284
247
|
newData,
|
|
285
248
|
state.data === undefined ? {} : state.data
|
|
286
249
|
);
|
|
287
|
-
const errors =
|
|
250
|
+
const errors = validate(state.validator, newState);
|
|
288
251
|
return {
|
|
289
252
|
...state,
|
|
290
253
|
data: newState,
|
|
@@ -303,17 +266,16 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
|
|
|
303
266
|
return state;
|
|
304
267
|
}
|
|
305
268
|
if (action.validationMode === 'NoValidation') {
|
|
306
|
-
const errors =
|
|
269
|
+
const errors = validate(undefined, state.data);
|
|
307
270
|
return {
|
|
308
271
|
...state,
|
|
309
|
-
validator: alwaysValid,
|
|
310
272
|
errors,
|
|
311
273
|
validationMode: action.validationMode
|
|
312
274
|
};
|
|
313
275
|
}
|
|
314
276
|
if (state.validationMode === 'NoValidation') {
|
|
315
277
|
const validator = reuseAjvForSchema(state.ajv, state.schema).compile(state.schema);
|
|
316
|
-
const errors =
|
|
278
|
+
const errors = validate(validator, state.data);
|
|
317
279
|
return {
|
|
318
280
|
...state,
|
|
319
281
|
validator,
|
|
@@ -336,6 +298,40 @@ export const extractSchema = (state: JsonFormsCore) => get(state, 'schema');
|
|
|
336
298
|
export const extractUiSchema = (state: JsonFormsCore) => get(state, 'uischema');
|
|
337
299
|
export const extractAjv = (state: JsonFormsCore) => get(state, 'ajv');
|
|
338
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
|
+
|
|
339
335
|
export const errorsAt = (
|
|
340
336
|
instancePath: string,
|
|
341
337
|
schema: JsonSchema,
|
|
@@ -345,15 +341,15 @@ export const errorsAt = (
|
|
|
345
341
|
const combinatorPaths = filter(
|
|
346
342
|
errors,
|
|
347
343
|
error => error.keyword === 'oneOf' || error.keyword === 'anyOf'
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
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);
|
|
357
353
|
// In anyOf and oneOf blocks with "primitive" (i.e. string, number etc.) or array subschemas,
|
|
358
354
|
// we want to make sure that errors are only shown for the correct subschema.
|
|
359
355
|
// Therefore, we compare the error's parent schema with the property's schema.
|
|
@@ -402,6 +398,3 @@ export const errorAt = (instancePath: string, schema: JsonSchema) =>
|
|
|
402
398
|
getErrorsAt(instancePath, schema, path => path === instancePath);
|
|
403
399
|
export const subErrorsAt = (instancePath: string, schema: JsonSchema) =>
|
|
404
400
|
getErrorsAt(instancePath, schema, path => path.startsWith(instancePath));
|
|
405
|
-
|
|
406
|
-
export const extractRefParserOptions = (state: JsonFormsCore) =>
|
|
407
|
-
get(state, 'refParserOptions');
|
|
@@ -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;
|
package/src/reducers/i18n.ts
CHANGED
|
@@ -22,66 +22,73 @@
|
|
|
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 { SET_LOCALE, SET_LOCALIZED_SCHEMAS } from '../actions';
|
|
26
|
-
import { JsonSchema, SET_LOCALIZED_UISCHEMAS, UISchemaElement } from '..';
|
|
27
|
-
import { Reducer } from '../util/type';
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
localizedUISchemas: Map<string, UISchemaElement>;
|
|
33
|
-
}
|
|
26
|
+
import { defaultErrorTranslator, defaultTranslator, JsonFormsI18nState } from '../i18n';
|
|
27
|
+
import { I18nActions, SET_LOCALE, SET_TRANSLATOR, UPDATE_I18N } from '../actions';
|
|
28
|
+
import { Reducer } from '../util';
|
|
34
29
|
|
|
35
|
-
const
|
|
36
|
-
locale:
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
export const defaultJsonFormsI18nState: JsonFormsI18nState = {
|
|
31
|
+
locale: 'en',
|
|
32
|
+
translate: defaultTranslator,
|
|
33
|
+
translateError: defaultErrorTranslator
|
|
39
34
|
};
|
|
40
35
|
|
|
41
|
-
export const i18nReducer: Reducer<
|
|
36
|
+
export const i18nReducer: Reducer<JsonFormsI18nState, I18nActions> = (state = defaultJsonFormsI18nState, action) => {
|
|
42
37
|
switch (action.type) {
|
|
43
|
-
case
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
case UPDATE_I18N: {
|
|
39
|
+
const locale = action.locale ?? defaultJsonFormsI18nState.locale;
|
|
40
|
+
const translate =
|
|
41
|
+
action.translator ?? defaultJsonFormsI18nState.translate;
|
|
42
|
+
const translateError =
|
|
43
|
+
action.errorTranslator ?? defaultJsonFormsI18nState.translateError;
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
locale !== state.locale ||
|
|
47
|
+
translate !== state.translate ||
|
|
48
|
+
translateError !== state.translateError
|
|
49
|
+
) {
|
|
50
|
+
return {
|
|
51
|
+
...state,
|
|
52
|
+
locale,
|
|
53
|
+
translate,
|
|
54
|
+
translateError
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return state;
|
|
58
|
+
}
|
|
59
|
+
case SET_TRANSLATOR:
|
|
49
60
|
return {
|
|
50
61
|
...state,
|
|
51
|
-
|
|
62
|
+
translate: action.translator ?? defaultTranslator,
|
|
63
|
+
translateError: action.errorTranslator ?? defaultErrorTranslator
|
|
52
64
|
};
|
|
53
65
|
case SET_LOCALE:
|
|
54
66
|
return {
|
|
55
67
|
...state,
|
|
56
|
-
locale:
|
|
57
|
-
action.locale === undefined ? navigator.languages[0] : action.locale
|
|
68
|
+
locale: action.locale ?? navigator.languages[0]
|
|
58
69
|
};
|
|
59
70
|
default:
|
|
60
71
|
return state;
|
|
61
72
|
}
|
|
62
73
|
};
|
|
63
74
|
|
|
64
|
-
export const fetchLocale = (state?:
|
|
75
|
+
export const fetchLocale = (state?: JsonFormsI18nState) => {
|
|
65
76
|
if (state === undefined) {
|
|
66
77
|
return undefined;
|
|
67
78
|
}
|
|
68
79
|
return state.locale;
|
|
69
80
|
};
|
|
70
81
|
|
|
71
|
-
export const
|
|
72
|
-
state?: JsonFormsLocaleState
|
|
73
|
-
): JsonSchema => {
|
|
82
|
+
export const fetchTranslator = (state?: JsonFormsI18nState) => {
|
|
74
83
|
if (state === undefined) {
|
|
75
|
-
return
|
|
84
|
+
return defaultTranslator;
|
|
76
85
|
}
|
|
77
|
-
return state.
|
|
78
|
-
}
|
|
86
|
+
return state.translate;
|
|
87
|
+
}
|
|
79
88
|
|
|
80
|
-
export const
|
|
81
|
-
state?: JsonFormsLocaleState
|
|
82
|
-
): UISchemaElement => {
|
|
89
|
+
export const fetchErrorTranslator = (state?: JsonFormsI18nState) => {
|
|
83
90
|
if (state === undefined) {
|
|
84
|
-
return
|
|
91
|
+
return defaultErrorTranslator;
|
|
85
92
|
}
|
|
86
|
-
return state.
|
|
87
|
-
}
|
|
93
|
+
return state.translateError;
|
|
94
|
+
}
|
package/src/reducers/index.ts
CHANGED
|
@@ -22,162 +22,13 @@
|
|
|
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, UISchemaElement } from '../models/uischema';
|
|
26
|
-
import {
|
|
27
|
-
coreReducer,
|
|
28
|
-
errorAt,
|
|
29
|
-
errorsAt,
|
|
30
|
-
extractAjv,
|
|
31
|
-
extractData,
|
|
32
|
-
extractRefParserOptions,
|
|
33
|
-
extractSchema,
|
|
34
|
-
extractUiSchema,
|
|
35
|
-
JsonFormsCore,
|
|
36
|
-
subErrorsAt,
|
|
37
|
-
ValidationMode
|
|
38
|
-
} from './core';
|
|
39
|
-
import {
|
|
40
|
-
extractDefaultData,
|
|
41
|
-
JsonFormsDefaultDataRegistryEntry
|
|
42
|
-
} from './default-data';
|
|
43
|
-
import { defaultDataReducer } from '../reducers/default-data';
|
|
44
|
-
import { JsonFormsRendererRegistryEntry, rendererReducer } from './renderers';
|
|
45
|
-
import { JsonFormsState } from '../store';
|
|
46
|
-
import {
|
|
47
|
-
findMatchingUISchema,
|
|
48
|
-
JsonFormsUISchemaRegistryEntry,
|
|
49
|
-
uischemaRegistryReducer,
|
|
50
|
-
UISchemaTester
|
|
51
|
-
} from './uischemas';
|
|
52
|
-
import {
|
|
53
|
-
fetchLocale,
|
|
54
|
-
findLocalizedSchema,
|
|
55
|
-
findLocalizedUISchema,
|
|
56
|
-
i18nReducer
|
|
57
|
-
} from './i18n';
|
|
58
25
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export {
|
|
70
|
-
rendererReducer,
|
|
71
|
-
cellReducer,
|
|
72
|
-
coreReducer,
|
|
73
|
-
i18nReducer,
|
|
74
|
-
configReducer,
|
|
75
|
-
UISchemaTester,
|
|
76
|
-
uischemaRegistryReducer,
|
|
77
|
-
findMatchingUISchema,
|
|
78
|
-
JsonFormsUISchemaRegistryEntry
|
|
79
|
-
};
|
|
80
|
-
export { JsonFormsCore, ValidationMode };
|
|
81
|
-
|
|
82
|
-
export const jsonFormsReducerConfig = {
|
|
83
|
-
core: coreReducer,
|
|
84
|
-
renderers: rendererReducer,
|
|
85
|
-
cells: cellReducer,
|
|
86
|
-
config: configReducer,
|
|
87
|
-
uischemas: uischemaRegistryReducer,
|
|
88
|
-
defaultData: defaultDataReducer,
|
|
89
|
-
i18n: i18nReducer
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export const getData = (state: JsonFormsState) =>
|
|
93
|
-
extractData(get(state, 'jsonforms.core'));
|
|
94
|
-
export const getSchema = (state: JsonFormsState): JsonSchema =>
|
|
95
|
-
extractSchema(get(state, 'jsonforms.core'));
|
|
96
|
-
export const getUiSchema = (state: JsonFormsState): UISchemaElement =>
|
|
97
|
-
extractUiSchema(get(state, 'jsonforms.core'));
|
|
98
|
-
export const getRefParserOptions = (state: JsonFormsState): RefParser.Options =>
|
|
99
|
-
extractRefParserOptions(get(state, 'jsonforms.core'));
|
|
100
|
-
export const getAjv = (
|
|
101
|
-
state: JsonFormsState
|
|
102
|
-
): Ajv => extractAjv(get(state, 'jsonforms.core'));
|
|
103
|
-
export const getDefaultData = (
|
|
104
|
-
state: JsonFormsState
|
|
105
|
-
): JsonFormsDefaultDataRegistryEntry[] =>
|
|
106
|
-
extractDefaultData(get(state, 'jsonforms.defaultData'));
|
|
107
|
-
export const getRenderers = (
|
|
108
|
-
state: JsonFormsState
|
|
109
|
-
): JsonFormsRendererRegistryEntry[] => get(state, 'jsonforms.renderers');
|
|
110
|
-
export const getCells = (
|
|
111
|
-
state: JsonFormsState
|
|
112
|
-
): JsonFormsCellRendererRegistryEntry[] => get(state, 'jsonforms.cells');
|
|
113
|
-
export const getUISchemas = (
|
|
114
|
-
state: JsonFormsState
|
|
115
|
-
): JsonFormsUISchemaRegistryEntry[] => get(state, 'jsonforms.uischemas');
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Finds a registered UI schema to use, if any.
|
|
119
|
-
* @param schema the JSON schema describing the data to be rendered
|
|
120
|
-
* @param schemaPath the according schema path
|
|
121
|
-
* @param path the instance path
|
|
122
|
-
* @param fallbackLayoutType the type of the layout to use
|
|
123
|
-
* @param control may be checked for embedded inline uischema options
|
|
124
|
-
*/
|
|
125
|
-
export const findUISchema = (
|
|
126
|
-
uischemas: JsonFormsUISchemaRegistryEntry[],
|
|
127
|
-
schema: JsonSchema,
|
|
128
|
-
schemaPath: string,
|
|
129
|
-
path: string,
|
|
130
|
-
fallbackLayoutType = 'VerticalLayout',
|
|
131
|
-
control?: ControlElement,
|
|
132
|
-
rootSchema?: JsonSchema
|
|
133
|
-
): UISchemaElement => {
|
|
134
|
-
// handle options
|
|
135
|
-
if (control && control.options && control.options.detail) {
|
|
136
|
-
if (typeof control.options.detail === 'string') {
|
|
137
|
-
if (control.options.detail.toUpperCase() === 'GENERATE') {
|
|
138
|
-
// force generation of uischema
|
|
139
|
-
return Generate.uiSchema(schema, fallbackLayoutType);
|
|
140
|
-
}
|
|
141
|
-
} else if (typeof control.options.detail === 'object') {
|
|
142
|
-
// check if detail is a valid uischema
|
|
143
|
-
if (
|
|
144
|
-
control.options.detail.type &&
|
|
145
|
-
typeof control.options.detail.type === 'string'
|
|
146
|
-
) {
|
|
147
|
-
return control.options.detail as UISchemaElement;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
// default
|
|
152
|
-
const uiSchema = findMatchingUISchema(uischemas)(schema, schemaPath, path);
|
|
153
|
-
if (uiSchema === undefined) {
|
|
154
|
-
return Generate.uiSchema(schema, fallbackLayoutType, '#', rootSchema);
|
|
155
|
-
}
|
|
156
|
-
return uiSchema;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export const getErrorAt = (instancePath: string, schema: JsonSchema) => (
|
|
160
|
-
state: JsonFormsState
|
|
161
|
-
) => {
|
|
162
|
-
return errorAt(instancePath, schema)(state.jsonforms.core);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
export { errorsAt };
|
|
166
|
-
|
|
167
|
-
export const getSubErrorsAt = (instancePath: string, schema: JsonSchema) => (
|
|
168
|
-
state: JsonFormsState
|
|
169
|
-
) => subErrorsAt(instancePath, schema)(state.jsonforms.core);
|
|
170
|
-
|
|
171
|
-
export const getConfig = (state: JsonFormsState) => state.jsonforms.config;
|
|
172
|
-
|
|
173
|
-
export const getLocale = (state: JsonFormsState) =>
|
|
174
|
-
fetchLocale(get(state, 'jsonforms.i18n'));
|
|
175
|
-
|
|
176
|
-
export const getLocalizedSchema = (locale: string) => (
|
|
177
|
-
state: JsonFormsState
|
|
178
|
-
): JsonSchema => findLocalizedSchema(locale)(get(state, 'jsonforms.i18n'));
|
|
179
|
-
|
|
180
|
-
export const getLocalizedUISchema = (locale: string) => (
|
|
181
|
-
state: JsonFormsState
|
|
182
|
-
): UISchemaElement =>
|
|
183
|
-
findLocalizedUISchema(locale)(get(state, 'jsonforms.i18n'));
|
|
26
|
+
export * from './cells';
|
|
27
|
+
export * from './config';
|
|
28
|
+
export * from './core';
|
|
29
|
+
export * from './default-data';
|
|
30
|
+
export * from './i18n';
|
|
31
|
+
export * from './reducers';
|
|
32
|
+
export * from './renderers';
|
|
33
|
+
export * from './selectors';
|
|
34
|
+
export * from './uischemas';
|