@jsonforms/core 3.1.0-alpha.0 → 3.1.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.
Files changed (205) hide show
  1. package/README.md +3 -3
  2. package/lib/Helpers.d.ts +1 -1
  3. package/lib/actions/actions.d.ts +27 -26
  4. package/lib/generators/Generate.d.ts +1 -1
  5. package/lib/generators/schema.d.ts +1 -1
  6. package/lib/i18n/arrayTranslations.d.ts +24 -0
  7. package/lib/i18n/i18nTypes.d.ts +3 -2
  8. package/lib/i18n/i18nUtil.d.ts +5 -2
  9. package/lib/i18n/index.d.ts +1 -0
  10. package/lib/jsonforms-core.cjs.js +428 -259
  11. package/lib/jsonforms-core.cjs.js.map +1 -1
  12. package/lib/jsonforms-core.esm.js +313 -200
  13. package/lib/jsonforms-core.esm.js.map +1 -1
  14. package/lib/models/jsonSchema.d.ts +2 -2
  15. package/lib/models/uischema.d.ts +1 -1
  16. package/lib/reducers/cells.d.ts +2 -2
  17. package/lib/reducers/config.d.ts +1 -1
  18. package/lib/reducers/core.d.ts +3 -2
  19. package/lib/reducers/default-data.d.ts +1 -1
  20. package/lib/reducers/i18n.d.ts +1 -1
  21. package/lib/reducers/reducers.d.ts +4 -4
  22. package/lib/reducers/renderers.d.ts +2 -2
  23. package/lib/reducers/selectors.d.ts +6 -6
  24. package/lib/reducers/uischemas.d.ts +2 -2
  25. package/lib/store.d.ts +3 -3
  26. package/lib/testers/testers.d.ts +1 -1
  27. package/lib/util/cell.d.ts +3 -4
  28. package/lib/util/combinators.d.ts +1 -1
  29. package/lib/util/label.d.ts +1 -1
  30. package/lib/util/path.d.ts +6 -3
  31. package/lib/util/renderer.d.ts +11 -7
  32. package/lib/util/resolvers.d.ts +1 -1
  33. package/lib/util/runtime.d.ts +2 -2
  34. package/lib/util/util.d.ts +2 -2
  35. package/lib/util/validator.d.ts +1 -1
  36. package/package.json +16 -5
  37. package/src/Helpers.ts +2 -2
  38. package/src/actions/actions.ts +59 -61
  39. package/src/configDefault.ts +1 -1
  40. package/src/generators/Generate.ts +4 -2
  41. package/src/generators/schema.ts +30 -26
  42. package/src/generators/uischema.ts +7 -6
  43. package/src/i18n/arrayTranslations.ts +54 -0
  44. package/src/i18n/i18nTypes.ts +12 -7
  45. package/src/i18n/i18nUtil.ts +66 -16
  46. package/src/i18n/index.ts +1 -0
  47. package/src/models/draft4.ts +33 -33
  48. package/src/models/jsonSchema.ts +2 -2
  49. package/src/models/uischema.ts +18 -7
  50. package/src/reducers/cells.ts +10 -9
  51. package/src/reducers/config.ts +1 -1
  52. package/src/reducers/core.ts +115 -75
  53. package/src/reducers/default-data.ts +8 -8
  54. package/src/reducers/i18n.ts +22 -10
  55. package/src/reducers/reducers.ts +24 -34
  56. package/src/reducers/renderers.ts +9 -9
  57. package/src/reducers/selectors.ts +10 -11
  58. package/src/reducers/uischemas.ts +27 -26
  59. package/src/store.ts +4 -4
  60. package/src/testers/testers.ts +200 -147
  61. package/src/util/cell.ts +27 -29
  62. package/src/util/combinators.ts +6 -4
  63. package/src/util/label.ts +2 -2
  64. package/src/util/path.ts +15 -8
  65. package/src/util/renderer.ts +123 -72
  66. package/src/util/resolvers.ts +16 -14
  67. package/src/util/runtime.ts +4 -4
  68. package/src/util/schema.ts +1 -1
  69. package/src/util/type.ts +5 -3
  70. package/src/util/uischema.ts +9 -9
  71. package/src/util/util.ts +54 -54
  72. package/src/util/validator.ts +2 -2
  73. package/.nycrc +0 -6
  74. package/docs/assets/css/main.css +0 -1
  75. package/docs/assets/images/icons.png +0 -0
  76. package/docs/assets/images/icons@2x.png +0 -0
  77. package/docs/assets/images/widgets.png +0 -0
  78. package/docs/assets/images/widgets@2x.png +0 -0
  79. package/docs/assets/js/main.js +0 -51
  80. package/docs/assets/js/search.json +0 -1
  81. package/docs/classes/gen.html +0 -406
  82. package/docs/enums/ruleeffect.html +0 -214
  83. package/docs/globals.html +0 -10568
  84. package/docs/index.html +0 -1297
  85. package/docs/interfaces/action.html +0 -166
  86. package/docs/interfaces/addcellrendereraction.html +0 -181
  87. package/docs/interfaces/addrendereraction.html +0 -181
  88. package/docs/interfaces/adduischemaaction.html +0 -181
  89. package/docs/interfaces/andcondition.html +0 -181
  90. package/docs/interfaces/anyaction.html +0 -189
  91. package/docs/interfaces/arraycontrolprops.html +0 -653
  92. package/docs/interfaces/arraylayoutprops.html +0 -648
  93. package/docs/interfaces/categorization.html +0 -281
  94. package/docs/interfaces/category.html +0 -279
  95. package/docs/interfaces/cellprops.html +0 -452
  96. package/docs/interfaces/combinatorrendererprops.html +0 -503
  97. package/docs/interfaces/combinatorsubschemarenderinfo.html +0 -181
  98. package/docs/interfaces/composablecondition.html +0 -193
  99. package/docs/interfaces/condition.html +0 -176
  100. package/docs/interfaces/controlelement.html +0 -280
  101. package/docs/interfaces/controlprops.html +0 -497
  102. package/docs/interfaces/controlstate.html +0 -184
  103. package/docs/interfaces/controlwithdetailprops.html +0 -501
  104. package/docs/interfaces/dispatchcellprops.html +0 -388
  105. package/docs/interfaces/dispatchcellstateprops.html +0 -408
  106. package/docs/interfaces/dispatchpropsofarraycontrol.html +0 -322
  107. package/docs/interfaces/dispatchpropsofcontrol.html +0 -204
  108. package/docs/interfaces/dispatchpropsofmultienumcontrol.html +0 -215
  109. package/docs/interfaces/enumcellprops.html +0 -467
  110. package/docs/interfaces/enumoption.html +0 -167
  111. package/docs/interfaces/formatted.html +0 -226
  112. package/docs/interfaces/grouplayout.html +0 -284
  113. package/docs/interfaces/horizontallayout.html +0 -234
  114. package/docs/interfaces/initaction.html +0 -209
  115. package/docs/interfaces/initactionoptions.html +0 -181
  116. package/docs/interfaces/internationalizable.html +0 -170
  117. package/docs/interfaces/jsonformscellrendererregistryentry.html +0 -167
  118. package/docs/interfaces/jsonformscore.html +0 -251
  119. package/docs/interfaces/jsonformsdefaultdataregistryentry.html +0 -167
  120. package/docs/interfaces/jsonformsextendedstate.html +0 -175
  121. package/docs/interfaces/jsonformsi18nstate.html +0 -181
  122. package/docs/interfaces/jsonformsprops.html +0 -321
  123. package/docs/interfaces/jsonformsrendererregistryentry.html +0 -167
  124. package/docs/interfaces/jsonformsstate.html +0 -170
  125. package/docs/interfaces/jsonformsstore.html +0 -376
  126. package/docs/interfaces/jsonformssubstates.html +0 -276
  127. package/docs/interfaces/jsonformsuischemaregistryentry.html +0 -167
  128. package/docs/interfaces/jsonschema4.html +0 -758
  129. package/docs/interfaces/jsonschema7.html +0 -884
  130. package/docs/interfaces/labelable.html +0 -184
  131. package/docs/interfaces/labeldescription.html +0 -184
  132. package/docs/interfaces/labeled.html +0 -182
  133. package/docs/interfaces/labelelement.html +0 -251
  134. package/docs/interfaces/labelprops.html +0 -339
  135. package/docs/interfaces/layout.html +0 -253
  136. package/docs/interfaces/layoutprops.html +0 -359
  137. package/docs/interfaces/leafcondition.html +0 -209
  138. package/docs/interfaces/orcondition.html +0 -181
  139. package/docs/interfaces/ownpropsofcell.html +0 -321
  140. package/docs/interfaces/ownpropsofcontrol.html +0 -305
  141. package/docs/interfaces/ownpropsofenum.html +0 -161
  142. package/docs/interfaces/ownpropsofenumcell.html +0 -335
  143. package/docs/interfaces/ownpropsofjsonformsrenderer.html +0 -296
  144. package/docs/interfaces/ownpropsoflabel.html +0 -286
  145. package/docs/interfaces/ownpropsoflayout.html +0 -305
  146. package/docs/interfaces/ownpropsofmasterlistitem.html +0 -289
  147. package/docs/interfaces/ownpropsofrenderer.html +0 -292
  148. package/docs/interfaces/referenceschemamap.html +0 -138
  149. package/docs/interfaces/registerdefaultdataaction.html +0 -181
  150. package/docs/interfaces/removecellrendereraction.html +0 -181
  151. package/docs/interfaces/removerendereraction.html +0 -181
  152. package/docs/interfaces/removeuischemaaction.html +0 -167
  153. package/docs/interfaces/rendererprops.html +0 -331
  154. package/docs/interfaces/rule.html +0 -185
  155. package/docs/interfaces/schemabasedcondition.html +0 -202
  156. package/docs/interfaces/scopable.html +0 -171
  157. package/docs/interfaces/scoped.html +0 -183
  158. package/docs/interfaces/setajvaction.html +0 -167
  159. package/docs/interfaces/setconfigaction.html +0 -167
  160. package/docs/interfaces/setlocaleaction.html +0 -167
  161. package/docs/interfaces/setschemaaction.html +0 -167
  162. package/docs/interfaces/settranslatoraction.html +0 -181
  163. package/docs/interfaces/setuischemaaction.html +0 -167
  164. package/docs/interfaces/setvalidationmodeaction.html +0 -167
  165. package/docs/interfaces/statepropsofarraycontrol.html +0 -474
  166. package/docs/interfaces/statepropsofarraylayout.html +0 -461
  167. package/docs/interfaces/statepropsofcell.html +0 -408
  168. package/docs/interfaces/statepropsofcombinator.html +0 -449
  169. package/docs/interfaces/statepropsofcontrol.html +0 -451
  170. package/docs/interfaces/statepropsofcontrolwithdetail.html +0 -463
  171. package/docs/interfaces/statepropsofenumcell.html +0 -422
  172. package/docs/interfaces/statepropsofjsonformsrenderer.html +0 -324
  173. package/docs/interfaces/statepropsoflabel.html +0 -343
  174. package/docs/interfaces/statepropsoflayout.html +0 -369
  175. package/docs/interfaces/statepropsofmasteritem.html +0 -309
  176. package/docs/interfaces/statepropsofrenderer.html +0 -331
  177. package/docs/interfaces/statepropsofscopedrenderer.html +0 -391
  178. package/docs/interfaces/store.html +0 -386
  179. package/docs/interfaces/testercontext.html +0 -184
  180. package/docs/interfaces/uischemaelement.html +0 -225
  181. package/docs/interfaces/unregisterdefaultdataaction.html +0 -167
  182. package/docs/interfaces/updateaction.html +0 -202
  183. package/docs/interfaces/updatecoreaction.html +0 -209
  184. package/docs/interfaces/updateerrorsaction.html +0 -167
  185. package/docs/interfaces/updatei18naction.html +0 -195
  186. package/docs/interfaces/verticallayout.html +0 -234
  187. package/docs/interfaces/withclassname.html +0 -153
  188. package/rollup.config.js +0 -44
  189. package/stats.html +0 -3279
  190. package/test/actions/actions.test.ts +0 -93
  191. package/test/generators/schema.test.ts +0 -224
  192. package/test/generators/uischema.test.ts +0 -576
  193. package/test/i18n/i18nUtil.test.ts +0 -88
  194. package/test/reducers/core.test.ts +0 -1682
  195. package/test/reducers/uischemas.test.ts +0 -173
  196. package/test/testers.test.ts +0 -948
  197. package/test/util/array.test.ts +0 -28
  198. package/test/util/cell.test.ts +0 -354
  199. package/test/util/derivetype.test.ts +0 -101
  200. package/test/util/label.test.ts +0 -364
  201. package/test/util/path.test.ts +0 -259
  202. package/test/util/renderer.test.ts +0 -1830
  203. package/test/util/resolvers.test.ts +0 -157
  204. package/test/util/runtime.test.ts +0 -779
  205. package/tsconfig.json +0 -13
@@ -23,33 +23,34 @@
23
23
  THE SOFTWARE.
24
24
  */
25
25
 
26
- import { RankedTester } from '../testers';
26
+ import type { RankedTester } from '../testers';
27
27
  import {
28
28
  ADD_CELL,
29
29
  AddCellRendererAction,
30
30
  REMOVE_CELL,
31
- RemoveCellRendererAction
31
+ RemoveCellRendererAction,
32
32
  } from '../actions';
33
- import { Reducer } from '../util';
33
+ import type { Reducer } from '../util';
34
34
 
35
35
  type ValidCellReducerActions = AddCellRendererAction | RemoveCellRendererAction;
36
36
 
37
- export type JsonFormsCellRendererRegistryState = JsonFormsCellRendererRegistryEntry[];
37
+ export type JsonFormsCellRendererRegistryState =
38
+ JsonFormsCellRendererRegistryEntry[];
38
39
 
39
40
  export interface JsonFormsCellRendererRegistryEntry {
40
41
  tester: RankedTester;
41
42
  cell: any;
42
43
  }
43
44
 
44
- export const cellReducer: Reducer<JsonFormsCellRendererRegistryState, ValidCellReducerActions> = (
45
- state = [],
46
- { type, tester, cell }
47
- ) => {
45
+ export const cellReducer: Reducer<
46
+ JsonFormsCellRendererRegistryState,
47
+ ValidCellReducerActions
48
+ > = (state = [], { type, tester, cell }) => {
48
49
  switch (type) {
49
50
  case ADD_CELL:
50
51
  return state.concat([{ tester, cell }]);
51
52
  case REMOVE_CELL:
52
- return state.filter(t => t.tester !== tester);
53
+ return state.filter((t) => t.tester !== tester);
53
54
  default:
54
55
  return state;
55
56
  }
@@ -26,7 +26,7 @@
26
26
  import merge from 'lodash/merge';
27
27
  import { SET_CONFIG, SetConfigAction } from '../actions';
28
28
  import { configDefault } from '../configDefault';
29
- import { Reducer } from '../util';
29
+ import type { Reducer } from '../util';
30
30
 
31
31
  const applyDefaultConfiguration = (config: any = {}) =>
32
32
  merge({}, configDefault, config);
@@ -29,7 +29,8 @@ 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 Ajv, { ErrorObject, ValidateFunction } from 'ajv';
32
+ import type Ajv from 'ajv';
33
+ import type { ErrorObject, ValidateFunction } from 'ajv';
33
34
  import {
34
35
  CoreActions,
35
36
  INIT,
@@ -42,12 +43,15 @@ import {
42
43
  UPDATE_DATA,
43
44
  UPDATE_ERRORS,
44
45
  UPDATE_CORE,
45
- UpdateCoreAction
46
+ UpdateCoreAction,
46
47
  } from '../actions';
47
48
  import { createAjv, Reducer } from '../util';
48
- import { JsonSchema, UISchemaElement } from '../models';
49
+ import type { JsonSchema, UISchemaElement } from '../models';
49
50
 
50
- export const validate = (validator: ValidateFunction | undefined, data: any): ErrorObject[] => {
51
+ export const validate = (
52
+ validator: ValidateFunction | undefined,
53
+ data: any
54
+ ): ErrorObject[] => {
51
55
  if (validator === undefined) {
52
56
  return [];
53
57
  }
@@ -58,7 +62,10 @@ export const validate = (validator: ValidateFunction | undefined, data: any): Er
58
62
  return validator.errors;
59
63
  };
60
64
 
61
- export type ValidationMode = 'ValidateAndShow' | 'ValidateAndHide' | 'NoValidation';
65
+ export type ValidationMode =
66
+ | 'ValidateAndShow'
67
+ | 'ValidateAndHide'
68
+ | 'NoValidation';
62
69
 
63
70
  export interface JsonFormsCore {
64
71
  data: any;
@@ -79,7 +86,7 @@ const initState: JsonFormsCore = {
79
86
  validator: undefined,
80
87
  ajv: undefined,
81
88
  validationMode: 'ValidateAndShow',
82
- additionalErrors: []
89
+ additionalErrors: [],
83
90
  };
84
91
 
85
92
  const reuseAjvForSchema = (ajv: Ajv, schema: JsonSchema): Ajv => {
@@ -89,14 +96,15 @@ const reuseAjvForSchema = (ajv: Ajv, schema: JsonSchema): Ajv => {
89
96
  return ajv;
90
97
  };
91
98
 
92
- const getOrCreateAjv = (state: JsonFormsCore, action?: InitAction | UpdateCoreAction): Ajv => {
99
+ const getOrCreateAjv = (
100
+ state: JsonFormsCore,
101
+ action?: InitAction | UpdateCoreAction
102
+ ): Ajv => {
93
103
  if (action) {
94
104
  if (hasAjvOption(action.options)) {
95
105
  // options object with ajv
96
106
  return action.options.ajv;
97
- } else if (
98
- action.options !== undefined
99
- ) {
107
+ } else if (action.options !== undefined) {
100
108
  // it is not an option object => should be ajv itself => check for compile function
101
109
  if (isFunction(action.options.compile)) {
102
110
  return action.options;
@@ -135,7 +143,9 @@ const hasValidationModeOption = (option: any): option is InitActionOptions => {
135
143
  return false;
136
144
  };
137
145
 
138
- const hasAdditionalErrorsOption = (option: any): option is InitActionOptions => {
146
+ const hasAdditionalErrorsOption = (
147
+ option: any
148
+ ): option is InitActionOptions => {
139
149
  if (option) {
140
150
  return option.additionalErrors !== undefined;
141
151
  }
@@ -152,7 +162,6 @@ const getAdditionalErrors = (
152
162
  return state.additionalErrors;
153
163
  };
154
164
 
155
- // tslint:disable-next-line: cyclomatic-complexity
156
165
  export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
157
166
  state = initState,
158
167
  action
@@ -162,7 +171,10 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
162
171
  const thisAjv = getOrCreateAjv(state, action);
163
172
 
164
173
  const validationMode = getValidationMode(state, action);
165
- const v = validationMode === 'NoValidation' ? undefined : thisAjv.compile(action.schema);
174
+ const v =
175
+ validationMode === 'NoValidation'
176
+ ? undefined
177
+ : thisAjv.compile(action.schema);
166
178
  const e = validate(v, action.data);
167
179
  const additionalErrors = getAdditionalErrors(state, action);
168
180
 
@@ -207,7 +219,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
207
219
  state.errors !== errors ||
208
220
  state.validator !== validator ||
209
221
  state.validationMode !== validationMode ||
210
- state.additionalErrors !== additionalErrors
222
+ state.additionalErrors !== additionalErrors;
211
223
  return stateChanged
212
224
  ? {
213
225
  ...state,
@@ -218,22 +230,26 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
218
230
  errors: isEqual(errors, state.errors) ? state.errors : errors,
219
231
  validator: validator,
220
232
  validationMode: validationMode,
221
- additionalErrors
233
+ additionalErrors,
222
234
  }
223
235
  : state;
224
236
  }
225
237
  case SET_AJV: {
226
238
  const currentAjv = action.ajv;
227
- const validator = state.validationMode === 'NoValidation' ? undefined : currentAjv.compile(state.schema);
239
+ const validator =
240
+ state.validationMode === 'NoValidation'
241
+ ? undefined
242
+ : currentAjv.compile(state.schema);
228
243
  const errors = validate(validator, state.data);
229
244
  return {
230
245
  ...state,
231
246
  validator,
232
- errors
247
+ errors,
233
248
  };
234
249
  }
235
250
  case SET_SCHEMA: {
236
- const needsNewValidator = action.schema && state.ajv && state.validationMode !== 'NoValidation';
251
+ const needsNewValidator =
252
+ action.schema && state.ajv && state.validationMode !== 'NoValidation';
237
253
  const v = needsNewValidator
238
254
  ? reuseAjvForSchema(state.ajv, action.schema).compile(action.schema)
239
255
  : state.validator;
@@ -242,13 +258,13 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
242
258
  ...state,
243
259
  validator: v,
244
260
  schema: action.schema,
245
- errors
261
+ errors,
246
262
  };
247
263
  }
248
264
  case SET_UISCHEMA: {
249
265
  return {
250
266
  ...state,
251
- uischema: action.uischema
267
+ uischema: action.uischema,
252
268
  };
253
269
  }
254
270
  case UPDATE_DATA: {
@@ -261,7 +277,7 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
261
277
  return {
262
278
  ...state,
263
279
  data: result,
264
- errors
280
+ errors,
265
281
  };
266
282
  } else {
267
283
  const oldData: any = get(state.data, action.path);
@@ -275,14 +291,14 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
275
291
  return {
276
292
  ...state,
277
293
  data: newState,
278
- errors
294
+ errors,
279
295
  };
280
296
  }
281
297
  }
282
298
  case UPDATE_ERRORS: {
283
299
  return {
284
300
  ...state,
285
- errors: action.errors
301
+ errors: action.errors,
286
302
  };
287
303
  }
288
304
  case SET_VALIDATION_MODE: {
@@ -294,22 +310,24 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
294
310
  return {
295
311
  ...state,
296
312
  errors,
297
- validationMode: action.validationMode
313
+ validationMode: action.validationMode,
298
314
  };
299
315
  }
300
316
  if (state.validationMode === 'NoValidation') {
301
- const validator = reuseAjvForSchema(state.ajv, state.schema).compile(state.schema);
317
+ const validator = reuseAjvForSchema(state.ajv, state.schema).compile(
318
+ state.schema
319
+ );
302
320
  const errors = validate(validator, state.data);
303
321
  return {
304
322
  ...state,
305
323
  validator,
306
324
  errors,
307
- validationMode: action.validationMode
325
+ validationMode: action.validationMode,
308
326
  };
309
327
  }
310
328
  return {
311
329
  ...state,
312
- validationMode: action.validationMode
330
+ validationMode: action.validationMode,
313
331
  };
314
332
  }
315
333
  default:
@@ -341,62 +359,67 @@ export const getControlPath = (error: ErrorObject) => {
341
359
  return dataPath.replace(/\//g, '.').substr(1);
342
360
  }
343
361
  // dataPath was renamed to instancePath in AJV v8
344
- var controlPath: string = error.instancePath;
362
+ let controlPath: string = error.instancePath;
345
363
 
346
364
  // change '/' chars to '.'
347
365
  controlPath = controlPath.replace(/\//g, '.');
348
-
366
+
349
367
  const invalidProperty = getInvalidProperty(error);
350
368
  if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
351
369
  controlPath = `${controlPath}.${invalidProperty}`;
352
370
  }
353
-
371
+
354
372
  // remove '.' chars at the beginning of paths
355
373
  controlPath = controlPath.replace(/^./, '');
356
374
  return controlPath;
357
- }
375
+ };
358
376
 
359
- export const errorsAt = (
360
- instancePath: string,
361
- schema: JsonSchema,
362
- matchPath: (path: string) => boolean
363
- ) => (errors: ErrorObject[]): ErrorObject[] => {
364
- // Get data paths of oneOf and anyOf errors to later determine whether an error occurred inside a subschema of oneOf or anyOf.
365
- const combinatorPaths = filter(
366
- errors,
367
- error => error.keyword === 'oneOf' || error.keyword === 'anyOf'
368
- ).map(error => getControlPath(error));
369
-
370
- return filter(errors, error => {
377
+ export const errorsAt =
378
+ (
379
+ instancePath: string,
380
+ schema: JsonSchema,
381
+ matchPath: (path: string) => boolean
382
+ ) =>
383
+ (errors: ErrorObject[]): ErrorObject[] => {
384
+ // Get data paths of oneOf and anyOf errors to later determine whether an error occurred inside a subschema of oneOf or anyOf.
385
+ const combinatorPaths = filter(
386
+ errors,
387
+ (error) => error.keyword === 'oneOf' || error.keyword === 'anyOf'
388
+ ).map((error) => getControlPath(error));
389
+
390
+ return filter(errors, (error) => {
371
391
  // Filter errors that match any keyword that we don't want to show in the UI
372
392
  if (filteredErrorKeywords.indexOf(error.keyword) !== -1) {
373
393
  return false;
374
394
  }
375
- const controlPath = getControlPath(error);
376
- let result = matchPath(controlPath);
377
- // In anyOf and oneOf blocks with "primitive" (i.e. string, number etc.) or array subschemas,
378
- // we want to make sure that errors are only shown for the correct subschema.
379
- // Therefore, we compare the error's parent schema with the property's schema.
380
- // In the primitive case the error's data path is the same for all subschemas:
381
- // It directly points to the property defining the anyOf/oneOf.
382
- // The same holds true for errors on the array level (e.g. min item amount).
383
- // In contrast, this comparison must not be done for errors whose parent schema defines an object
384
- // because the parent schema can never match the property schema (e.g. for 'required' checks).
385
- const parentSchema: JsonSchema | undefined = error.parentSchema;
386
- if (result && !isObjectSchema(parentSchema)
387
- && combinatorPaths.findIndex(p => instancePath.startsWith(p)) !== -1) {
388
- result = result && isEqual(parentSchema, schema);
389
- }
390
- return result;
391
- });
392
- };
395
+ const controlPath = getControlPath(error);
396
+ let result = matchPath(controlPath);
397
+ // In anyOf and oneOf blocks with "primitive" (i.e. string, number etc.) or array subschemas,
398
+ // we want to make sure that errors are only shown for the correct subschema.
399
+ // Therefore, we compare the error's parent schema with the property's schema.
400
+ // In the primitive case the error's data path is the same for all subschemas:
401
+ // It directly points to the property defining the anyOf/oneOf.
402
+ // The same holds true for errors on the array level (e.g. min item amount).
403
+ // In contrast, this comparison must not be done for errors whose parent schema defines an object
404
+ // because the parent schema can never match the property schema (e.g. for 'required' checks).
405
+ const parentSchema: JsonSchema | undefined = error.parentSchema;
406
+ if (
407
+ result &&
408
+ !isObjectSchema(parentSchema) &&
409
+ combinatorPaths.findIndex((p) => instancePath.startsWith(p)) !== -1
410
+ ) {
411
+ result = result && isEqual(parentSchema, schema);
412
+ }
413
+ return result;
414
+ });
415
+ };
393
416
 
394
417
  /**
395
418
  * @returns true if the schema describes an object.
396
419
  */
397
420
  const isObjectSchema = (schema?: JsonSchema): boolean => {
398
421
  return schema?.type === 'object' || !!schema?.properties;
399
- }
422
+ };
400
423
 
401
424
  /**
402
425
  * The error-type of an AJV error is defined by its `keyword` property.
@@ -409,19 +432,36 @@ const isObjectSchema = (schema?: JsonSchema): boolean => {
409
432
  * - anyOf: Indicates that an anyOf definition itself is not valid because none of its subschemas matches.
410
433
  * - oneOf: Indicates that an oneOf definition itself is not valid because not exactly one of its subschemas matches.
411
434
  */
412
- const filteredErrorKeywords = ['additionalProperties', 'allOf', 'anyOf', 'oneOf'];
413
-
414
- const getErrorsAt = (
415
- instancePath: string,
416
- schema: JsonSchema,
417
- matchPath: (path: string) => boolean
418
- ) => (state: JsonFormsCore): ErrorObject[] => {
419
- const errors = state.errors ?? [];
420
- const additionalErrors = state.additionalErrors ?? [];
421
- return errorsAt(instancePath, schema, matchPath)(state.validationMode === 'ValidateAndHide' ? additionalErrors : [...errors, ...additionalErrors]);
422
- }
435
+ const filteredErrorKeywords = [
436
+ 'additionalProperties',
437
+ 'allOf',
438
+ 'anyOf',
439
+ 'oneOf',
440
+ ];
441
+
442
+ const getErrorsAt =
443
+ (
444
+ instancePath: string,
445
+ schema: JsonSchema,
446
+ matchPath: (path: string) => boolean
447
+ ) =>
448
+ (state: JsonFormsCore): ErrorObject[] => {
449
+ const errors = state.errors ?? [];
450
+ const additionalErrors = state.additionalErrors ?? [];
451
+ return errorsAt(
452
+ instancePath,
453
+ schema,
454
+ matchPath
455
+ )(
456
+ state.validationMode === 'ValidateAndHide'
457
+ ? additionalErrors
458
+ : [...errors, ...additionalErrors]
459
+ );
460
+ };
423
461
 
424
462
  export const errorAt = (instancePath: string, schema: JsonSchema) =>
425
- getErrorsAt(instancePath, schema, path => path === instancePath);
463
+ getErrorsAt(instancePath, schema, (path) => path === instancePath);
426
464
  export const subErrorsAt = (instancePath: string, schema: JsonSchema) =>
427
- getErrorsAt(instancePath, schema, path => path.startsWith(instancePath));
465
+ getErrorsAt(instancePath, schema, (path) =>
466
+ path.startsWith(instancePath + '.')
467
+ );
@@ -27,9 +27,9 @@ import {
27
27
  ADD_DEFAULT_DATA,
28
28
  RegisterDefaultDataAction,
29
29
  REMOVE_DEFAULT_DATA,
30
- UnregisterDefaultDataAction
30
+ UnregisterDefaultDataAction,
31
31
  } from '../actions';
32
- import { Reducer } from '../util';
32
+ import type { Reducer } from '../util';
33
33
 
34
34
  export interface JsonFormsDefaultDataRegistryEntry {
35
35
  schemaPath: string;
@@ -40,17 +40,17 @@ type ValidDefaultDataActions =
40
40
  | RegisterDefaultDataAction
41
41
  | UnregisterDefaultDataAction;
42
42
 
43
- export const defaultDataReducer: Reducer<JsonFormsDefaultDataRegistryEntry[], ValidDefaultDataActions> = (
44
- state = [],
45
- action
46
- ) => {
43
+ export const defaultDataReducer: Reducer<
44
+ JsonFormsDefaultDataRegistryEntry[],
45
+ ValidDefaultDataActions
46
+ > = (state = [], action) => {
47
47
  switch (action.type) {
48
48
  case ADD_DEFAULT_DATA:
49
49
  return state.concat([
50
- { schemaPath: action.schemaPath, data: action.data }
50
+ { schemaPath: action.schemaPath, data: action.data },
51
51
  ]);
52
52
  case REMOVE_DEFAULT_DATA:
53
- return state.filter(t => t.schemaPath !== action.schemaPath);
53
+ return state.filter((t) => t.schemaPath !== action.schemaPath);
54
54
  default:
55
55
  return state;
56
56
  }
@@ -23,17 +23,29 @@
23
23
  THE SOFTWARE.
24
24
  */
25
25
 
26
- import { defaultErrorTranslator, defaultTranslator, JsonFormsI18nState } from '../i18n';
27
- import { I18nActions, SET_LOCALE, SET_TRANSLATOR, UPDATE_I18N } from '../actions';
28
- import { Reducer } from '../util';
26
+ import {
27
+ defaultErrorTranslator,
28
+ defaultTranslator,
29
+ JsonFormsI18nState,
30
+ } from '../i18n';
31
+ import {
32
+ I18nActions,
33
+ SET_LOCALE,
34
+ SET_TRANSLATOR,
35
+ UPDATE_I18N,
36
+ } from '../actions';
37
+ import type { Reducer } from '../util';
29
38
 
30
39
  export const defaultJsonFormsI18nState: Required<JsonFormsI18nState> = {
31
40
  locale: 'en',
32
41
  translate: defaultTranslator,
33
- translateError: defaultErrorTranslator
42
+ translateError: defaultErrorTranslator,
34
43
  };
35
44
 
36
- export const i18nReducer: Reducer<JsonFormsI18nState, I18nActions> = (state = defaultJsonFormsI18nState, action) => {
45
+ export const i18nReducer: Reducer<JsonFormsI18nState, I18nActions> = (
46
+ state = defaultJsonFormsI18nState,
47
+ action
48
+ ) => {
37
49
  switch (action.type) {
38
50
  case UPDATE_I18N: {
39
51
  const locale = action.locale ?? defaultJsonFormsI18nState.locale;
@@ -51,7 +63,7 @@ export const i18nReducer: Reducer<JsonFormsI18nState, I18nActions> = (state = de
51
63
  ...state,
52
64
  locale,
53
65
  translate,
54
- translateError
66
+ translateError,
55
67
  };
56
68
  }
57
69
  return state;
@@ -60,12 +72,12 @@ export const i18nReducer: Reducer<JsonFormsI18nState, I18nActions> = (state = de
60
72
  return {
61
73
  ...state,
62
74
  translate: action.translator ?? defaultTranslator,
63
- translateError: action.errorTranslator ?? defaultErrorTranslator
75
+ translateError: action.errorTranslator ?? defaultErrorTranslator,
64
76
  };
65
77
  case SET_LOCALE:
66
78
  return {
67
79
  ...state,
68
- locale: action.locale ?? navigator.languages[0]
80
+ locale: action.locale ?? navigator.languages[0],
69
81
  };
70
82
  default:
71
83
  return state;
@@ -84,11 +96,11 @@ export const fetchTranslator = (state?: JsonFormsI18nState) => {
84
96
  return defaultTranslator;
85
97
  }
86
98
  return state.translate;
87
- }
99
+ };
88
100
 
89
101
  export const fetchErrorTranslator = (state?: JsonFormsI18nState) => {
90
102
  if (state === undefined) {
91
103
  return defaultErrorTranslator;
92
104
  }
93
105
  return state.translateError;
94
- }
106
+ };
@@ -23,34 +23,23 @@
23
23
  THE SOFTWARE.
24
24
  */
25
25
 
26
- import { ControlElement, UISchemaElement } from '../models';
27
- import {
28
- coreReducer,
29
- errorAt,
30
- subErrorsAt,
31
- } from './core';
26
+ import type { ControlElement, UISchemaElement } from '../models';
27
+ import { coreReducer, errorAt, subErrorsAt } from './core';
32
28
  import { defaultDataReducer } from './default-data';
33
29
  import { rendererReducer } from './renderers';
34
- import { JsonFormsState } from '../store';
30
+ import type { JsonFormsState } from '../store';
35
31
  import type { JsonFormsUISchemaRegistryEntry } from './uischemas';
36
- import {
37
- findMatchingUISchema,
38
- uischemaRegistryReducer,
39
- } from './uischemas';
40
- import {
41
- fetchErrorTranslator,
42
- fetchLocale,
43
- i18nReducer,
44
- } from './i18n';
32
+ import { findMatchingUISchema, uischemaRegistryReducer } from './uischemas';
33
+ import { fetchErrorTranslator, fetchLocale, i18nReducer } from './i18n';
45
34
 
46
35
  import { Generate } from '../generators';
47
- import { JsonSchema } from '../models/jsonSchema';
36
+ import type { JsonSchema } from '../models/jsonSchema';
48
37
 
49
38
  import { cellReducer } from './cells';
50
39
  import { configReducer } from './config';
51
40
  import get from 'lodash/get';
52
41
  import { fetchTranslator } from '.';
53
- import { ErrorTranslator, Translator } from '../i18n';
42
+ import type { ErrorTranslator, Translator } from '../i18n';
54
43
 
55
44
  export const jsonFormsReducerConfig = {
56
45
  core: coreReducer,
@@ -84,7 +73,7 @@ export const findUISchema = (
84
73
  if (typeof control.options.detail === 'string') {
85
74
  if (control.options.detail.toUpperCase() === 'GENERATE') {
86
75
  //use fallback generation function
87
- if(typeof fallback === "function"){
76
+ if (typeof fallback === 'function') {
88
77
  return fallback();
89
78
  }
90
79
  // force generation of uischema
@@ -104,7 +93,7 @@ export const findUISchema = (
104
93
  const uiSchema = findMatchingUISchema(uischemas)(schema, schemaPath, path);
105
94
  if (uiSchema === undefined) {
106
95
  //use fallback generation function
107
- if(typeof fallback === 'function'){
96
+ if (typeof fallback === 'function') {
108
97
  return fallback();
109
98
  }
110
99
  return Generate.uiSchema(schema, fallback, '#', rootSchema);
@@ -112,25 +101,26 @@ export const findUISchema = (
112
101
  return uiSchema;
113
102
  };
114
103
 
115
- export const getErrorAt = (instancePath: string, schema: JsonSchema) => (
116
- state: JsonFormsState
117
- ) => {
118
- return errorAt(instancePath, schema)(state.jsonforms.core);
119
- };
104
+ export const getErrorAt =
105
+ (instancePath: string, schema: JsonSchema) => (state: JsonFormsState) => {
106
+ return errorAt(instancePath, schema)(state.jsonforms.core);
107
+ };
120
108
 
121
- export const getSubErrorsAt = (instancePath: string, schema: JsonSchema) => (
122
- state: JsonFormsState
123
- ) => subErrorsAt(instancePath, schema)(state.jsonforms.core);
109
+ export const getSubErrorsAt =
110
+ (instancePath: string, schema: JsonSchema) => (state: JsonFormsState) =>
111
+ subErrorsAt(instancePath, schema)(state.jsonforms.core);
124
112
 
125
113
  export const getConfig = (state: JsonFormsState) => state.jsonforms.config;
126
114
 
127
115
  export const getLocale = (state: JsonFormsState) =>
128
116
  fetchLocale(get(state, 'jsonforms.i18n'));
129
117
 
130
- export const getTranslator = () => (
131
- state: JsonFormsState
132
- ): Translator => fetchTranslator(get(state, 'jsonforms.i18n'));
118
+ export const getTranslator =
119
+ () =>
120
+ (state: JsonFormsState): Translator =>
121
+ fetchTranslator(get(state, 'jsonforms.i18n'));
133
122
 
134
- export const getErrorTranslator = () => (
135
- state: JsonFormsState
136
- ): ErrorTranslator => fetchErrorTranslator(get(state, 'jsonforms.i18n'));
123
+ export const getErrorTranslator =
124
+ () =>
125
+ (state: JsonFormsState): ErrorTranslator =>
126
+ fetchErrorTranslator(get(state, 'jsonforms.i18n'));
@@ -23,14 +23,14 @@
23
23
  THE SOFTWARE.
24
24
  */
25
25
 
26
- import { RankedTester } from '../testers';
26
+ import type { RankedTester } from '../testers';
27
27
  import {
28
28
  ADD_RENDERER,
29
29
  AddRendererAction,
30
30
  REMOVE_RENDERER,
31
- RemoveRendererAction
31
+ RemoveRendererAction,
32
32
  } from '../actions';
33
- import { Reducer } from '../util';
33
+ import type { Reducer } from '../util';
34
34
 
35
35
  export interface JsonFormsRendererRegistryEntry {
36
36
  tester: RankedTester;
@@ -39,17 +39,17 @@ export interface JsonFormsRendererRegistryEntry {
39
39
 
40
40
  type ValidRendererReducerActions = AddRendererAction | RemoveRendererAction;
41
41
 
42
- export const rendererReducer: Reducer<JsonFormsRendererRegistryEntry[], ValidRendererReducerActions> = (
43
- state = [],
44
- action
45
- ) => {
42
+ export const rendererReducer: Reducer<
43
+ JsonFormsRendererRegistryEntry[],
44
+ ValidRendererReducerActions
45
+ > = (state = [], action) => {
46
46
  switch (action.type) {
47
47
  case ADD_RENDERER:
48
48
  return state.concat([
49
- { tester: action.tester, renderer: action.renderer }
49
+ { tester: action.tester, renderer: action.renderer },
50
50
  ]);
51
51
  case REMOVE_RENDERER:
52
- return state.filter(t => t.tester !== action.tester);
52
+ return state.filter((t) => t.tester !== action.tester);
53
53
  default:
54
54
  return state;
55
55
  }