@jsonforms/core 3.0.0-alpha.1 → 3.0.0-alpha.2
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 +716 -401
- package/docs/index.html +60 -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.js +1 -0
- package/lib/Helpers.js.map +1 -1
- package/lib/actions/actions.d.ts +29 -25
- package/lib/actions/actions.js +52 -28
- package/lib/actions/actions.js.map +1 -1
- package/lib/configDefault.js +1 -0
- package/lib/configDefault.js.map +1 -1
- package/lib/generators/Generate.js +1 -0
- package/lib/generators/Generate.js.map +1 -1
- package/lib/generators/schema.js +3 -1
- package/lib/generators/schema.js.map +1 -1
- package/lib/generators/uischema.js +5 -2
- 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 +11 -0
- package/lib/i18n/i18nUtil.js +58 -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 +1 -0
- package/lib/index.js +3 -0
- package/lib/index.js.map +1 -1
- package/lib/jsonforms-core.js +9 -3
- package/lib/jsonforms-core.js.map +1 -1
- package/lib/models/draft4.js +1 -0
- package/lib/models/draft4.js.map +1 -1
- package/lib/models/index.js +3 -0
- package/lib/models/index.js.map +1 -1
- package/lib/models/uischema.js +5 -2
- package/lib/models/uischema.js.map +1 -1
- package/lib/reducers/cells.js +3 -1
- package/lib/reducers/cells.js.map +1 -1
- package/lib/reducers/config.js +3 -1
- package/lib/reducers/config.js.map +1 -1
- package/lib/reducers/core.d.ts +3 -2
- package/lib/reducers/core.js +72 -37
- package/lib/reducers/core.js.map +1 -1
- package/lib/reducers/default-data.js +5 -2
- package/lib/reducers/default-data.js.map +1 -1
- package/lib/reducers/i18n.d.ts +7 -10
- package/lib/reducers/i18n.js +38 -20
- package/lib/reducers/i18n.js.map +1 -1
- package/lib/reducers/reducers.d.ts +8 -7
- package/lib/reducers/reducers.js +25 -17
- package/lib/reducers/reducers.js.map +1 -1
- package/lib/reducers/renderers.js +3 -1
- package/lib/reducers/renderers.js.map +1 -1
- package/lib/reducers/selectors.d.ts +1 -1
- package/lib/reducers/selectors.js +17 -8
- package/lib/reducers/selectors.js.map +1 -1
- package/lib/reducers/uischemas.js +5 -2
- package/lib/reducers/uischemas.js.map +1 -1
- package/lib/store.d.ts +5 -4
- package/lib/testers/testers.js +39 -19
- package/lib/testers/testers.js.map +1 -1
- package/lib/util/array.js +1 -0
- package/lib/util/array.js.map +1 -1
- package/lib/util/cell.js +25 -9
- package/lib/util/cell.js.map +1 -1
- package/lib/util/combinators.js +5 -2
- package/lib/util/combinators.js.map +1 -1
- package/lib/util/ids.js +7 -3
- package/lib/util/ids.js.map +1 -1
- package/lib/util/index.js +2 -0
- package/lib/util/index.js.map +1 -1
- package/lib/util/label.js +5 -2
- package/lib/util/label.js.map +1 -1
- package/lib/util/path.js +9 -4
- package/lib/util/path.js.map +1 -1
- package/lib/util/renderer.d.ts +13 -4
- package/lib/util/renderer.js +120 -39
- package/lib/util/renderer.js.map +1 -1
- package/lib/util/resolvers.js +7 -3
- package/lib/util/resolvers.js.map +1 -1
- package/lib/util/runtime.d.ts +4 -5
- package/lib/util/runtime.js +15 -7
- package/lib/util/runtime.js.map +1 -1
- package/lib/util/schema.js +3 -1
- package/lib/util/schema.js.map +1 -1
- package/lib/util/uischema.js +7 -3
- package/lib/util/uischema.js.map +1 -1
- package/lib/util/util.d.ts +1 -1
- package/lib/util/util.js +9 -4
- package/lib/util/util.js.map +1 -1
- package/lib/util/validator.d.ts +3 -2
- package/lib/util/validator.js +8 -7
- package/lib/util/validator.js.map +1 -1
- package/package.json +5 -4
- package/src/actions/actions.ts +46 -36
- package/src/i18n/i18nTypes.ts +17 -0
- package/src/i18n/i18nUtil.ts +76 -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 -9
- package/src/reducers/selectors.ts +1 -1
- package/src/store.ts +4 -4
- package/src/util/cell.ts +24 -4
- package/src/util/renderer.ts +116 -27
- package/src/util/runtime.ts +1 -1
- package/src/util/util.ts +1 -1
- package/src/util/validator.ts +5 -9
- package/test/reducers/core.test.ts +29 -41
- package/test/util/cell.test.ts +2 -2
- package/test/util/renderer.test.ts +425 -4
package/src/reducers/core.ts
CHANGED
|
@@ -29,7 +29,7 @@ import get from 'lodash/get';
|
|
|
29
29
|
import filter from 'lodash/filter';
|
|
30
30
|
import isEqual from 'lodash/isEqual';
|
|
31
31
|
import isFunction from 'lodash/isFunction';
|
|
32
|
-
import
|
|
32
|
+
import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
|
33
33
|
import {
|
|
34
34
|
CoreActions,
|
|
35
35
|
INIT,
|
|
@@ -47,28 +47,17 @@ import {
|
|
|
47
47
|
import { createAjv, Reducer } from '../util';
|
|
48
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 => {
|
|
@@ -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.
|
package/src/reducers/i18n.ts
CHANGED
|
@@ -23,66 +23,72 @@
|
|
|
23
23
|
THE SOFTWARE.
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
26
|
+
import { defaultErrorTranslator, defaultTranslator, JsonFormsI18nState } from '../i18n';
|
|
27
|
+
import { I18nActions, SET_LOCALE, SET_TRANSLATOR, UPDATE_I18N } from '../actions';
|
|
28
28
|
import { Reducer } from '../util';
|
|
29
29
|
|
|
30
|
-
export
|
|
31
|
-
locale
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const initState: JsonFormsLocaleState = {
|
|
37
|
-
locale: undefined,
|
|
38
|
-
localizedSchemas: new Map(),
|
|
39
|
-
localizedUISchemas: new Map()
|
|
30
|
+
export const defaultJsonFormsI18nState: JsonFormsI18nState = {
|
|
31
|
+
locale: 'en',
|
|
32
|
+
translate: defaultTranslator,
|
|
33
|
+
translateError: defaultErrorTranslator
|
|
40
34
|
};
|
|
41
35
|
|
|
42
|
-
export const i18nReducer: Reducer<
|
|
36
|
+
export const i18nReducer: Reducer<JsonFormsI18nState, I18nActions> = (state = defaultJsonFormsI18nState, action) => {
|
|
43
37
|
switch (action.type) {
|
|
44
|
-
case
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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:
|
|
50
60
|
return {
|
|
51
61
|
...state,
|
|
52
|
-
|
|
62
|
+
translate: action.translator ?? defaultTranslator,
|
|
63
|
+
translateError: action.errorTranslator ?? defaultErrorTranslator
|
|
53
64
|
};
|
|
54
65
|
case SET_LOCALE:
|
|
55
66
|
return {
|
|
56
67
|
...state,
|
|
57
|
-
locale:
|
|
58
|
-
action.locale === undefined ? navigator.languages[0] : action.locale
|
|
68
|
+
locale: action.locale ?? navigator.languages[0]
|
|
59
69
|
};
|
|
60
70
|
default:
|
|
61
71
|
return state;
|
|
62
72
|
}
|
|
63
73
|
};
|
|
64
74
|
|
|
65
|
-
export const fetchLocale = (state?:
|
|
75
|
+
export const fetchLocale = (state?: JsonFormsI18nState) => {
|
|
66
76
|
if (state === undefined) {
|
|
67
77
|
return undefined;
|
|
68
78
|
}
|
|
69
79
|
return state.locale;
|
|
70
80
|
};
|
|
71
81
|
|
|
72
|
-
export const
|
|
73
|
-
state?: JsonFormsLocaleState
|
|
74
|
-
): JsonSchema => {
|
|
82
|
+
export const fetchTranslator = (state?: JsonFormsI18nState) => {
|
|
75
83
|
if (state === undefined) {
|
|
76
|
-
return
|
|
84
|
+
return defaultTranslator;
|
|
77
85
|
}
|
|
78
|
-
return state.
|
|
79
|
-
}
|
|
86
|
+
return state.translate;
|
|
87
|
+
}
|
|
80
88
|
|
|
81
|
-
export const
|
|
82
|
-
state?: JsonFormsLocaleState
|
|
83
|
-
): UISchemaElement => {
|
|
89
|
+
export const fetchErrorTranslator = (state?: JsonFormsI18nState) => {
|
|
84
90
|
if (state === undefined) {
|
|
85
|
-
return
|
|
91
|
+
return defaultErrorTranslator;
|
|
86
92
|
}
|
|
87
|
-
return state.
|
|
88
|
-
}
|
|
93
|
+
return state.translateError;
|
|
94
|
+
}
|
package/src/reducers/reducers.ts
CHANGED
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
coreReducer,
|
|
29
29
|
errorAt,
|
|
30
30
|
errorsAt,
|
|
31
|
+
getControlPath,
|
|
31
32
|
JsonFormsCore,
|
|
32
33
|
subErrorsAt,
|
|
33
34
|
ValidationMode
|
|
@@ -42,10 +43,9 @@ import {
|
|
|
42
43
|
UISchemaTester
|
|
43
44
|
} from './uischemas';
|
|
44
45
|
import {
|
|
46
|
+
fetchErrorTranslator,
|
|
45
47
|
fetchLocale,
|
|
46
|
-
|
|
47
|
-
findLocalizedUISchema,
|
|
48
|
-
i18nReducer
|
|
48
|
+
i18nReducer,
|
|
49
49
|
} from './i18n';
|
|
50
50
|
|
|
51
51
|
import { Generate } from '../generators';
|
|
@@ -54,6 +54,8 @@ import { JsonSchema } from '../models/jsonSchema';
|
|
|
54
54
|
import { cellReducer } from './cells';
|
|
55
55
|
import { configReducer } from './config';
|
|
56
56
|
import get from 'lodash/get';
|
|
57
|
+
import { fetchTranslator } from '.';
|
|
58
|
+
import { ErrorTranslator, Translator } from '../i18n';
|
|
57
59
|
|
|
58
60
|
export {
|
|
59
61
|
rendererReducer,
|
|
@@ -126,7 +128,7 @@ export const getErrorAt = (instancePath: string, schema: JsonSchema) => (
|
|
|
126
128
|
return errorAt(instancePath, schema)(state.jsonforms.core);
|
|
127
129
|
};
|
|
128
130
|
|
|
129
|
-
export { errorsAt };
|
|
131
|
+
export { errorsAt, getControlPath };
|
|
130
132
|
|
|
131
133
|
export const getSubErrorsAt = (instancePath: string, schema: JsonSchema) => (
|
|
132
134
|
state: JsonFormsState
|
|
@@ -137,11 +139,10 @@ export const getConfig = (state: JsonFormsState) => state.jsonforms.config;
|
|
|
137
139
|
export const getLocale = (state: JsonFormsState) =>
|
|
138
140
|
fetchLocale(get(state, 'jsonforms.i18n'));
|
|
139
141
|
|
|
140
|
-
export const
|
|
142
|
+
export const getTranslator = () => (
|
|
141
143
|
state: JsonFormsState
|
|
142
|
-
):
|
|
144
|
+
): Translator => fetchTranslator(get(state, 'jsonforms.i18n'));
|
|
143
145
|
|
|
144
|
-
export const
|
|
146
|
+
export const getErrorTranslator = () => (
|
|
145
147
|
state: JsonFormsState
|
|
146
|
-
):
|
|
147
|
-
findLocalizedUISchema(locale)(get(state, 'jsonforms.i18n'));
|
|
148
|
+
): 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
|
@@ -31,7 +31,8 @@ import {
|
|
|
31
31
|
getErrorAt,
|
|
32
32
|
getSchema,
|
|
33
33
|
getAjv,
|
|
34
|
-
JsonFormsCellRendererRegistryEntry
|
|
34
|
+
JsonFormsCellRendererRegistryEntry,
|
|
35
|
+
getTranslator
|
|
35
36
|
} from '../reducers';
|
|
36
37
|
import { AnyAction, Dispatch } from './type';
|
|
37
38
|
import {
|
|
@@ -54,6 +55,7 @@ import {
|
|
|
54
55
|
} from './renderer';
|
|
55
56
|
import { JsonFormsState } from '../store';
|
|
56
57
|
import { JsonSchema } from '../models';
|
|
58
|
+
import { i18nJsonSchema } from '..';
|
|
57
59
|
|
|
58
60
|
export { JsonFormsCellRendererRegistryEntry };
|
|
59
61
|
|
|
@@ -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
|
+
props.uischema?.options?.i18n ?? (props.schema as i18nJsonSchema).i18n
|
|
206
|
+
)
|
|
207
|
+
) ||
|
|
208
|
+
(props.schema.const && [
|
|
209
|
+
enumToEnumOptionMapper(
|
|
210
|
+
props.schema.const,
|
|
211
|
+
getTranslator()(state),
|
|
212
|
+
props.uischema?.options?.i18n ?? (props.schema as i18nJsonSchema).i18n
|
|
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
|
+
props.uischema?.options?.i18n
|
|
239
|
+
)
|
|
240
|
+
);
|
|
221
241
|
return {
|
|
222
242
|
...props,
|
|
223
243
|
options
|