@jsonforms/core 2.5.2-alpha.0 → 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.
Files changed (273) hide show
  1. package/README.md +1 -1
  2. package/docs/assets/js/search.json +1 -1
  3. package/docs/enums/ruleeffect.html +4 -4
  4. package/docs/globals.html +1061 -1120
  5. package/docs/index.html +64 -91
  6. package/docs/interfaces/addcellrendereraction.html +3 -3
  7. package/docs/interfaces/addrendereraction.html +3 -3
  8. package/docs/interfaces/adduischemaaction.html +3 -3
  9. package/docs/interfaces/andcondition.html +2 -2
  10. package/docs/interfaces/arraycontrolprops.html +22 -22
  11. package/docs/interfaces/arraylayoutprops.html +22 -22
  12. package/docs/interfaces/categorization.html +5 -5
  13. package/docs/interfaces/category.html +5 -5
  14. package/docs/interfaces/cellprops.html +14 -14
  15. package/docs/interfaces/combinatorrendererprops.html +13 -13
  16. package/docs/interfaces/combinatorsubschemarenderinfo.html +3 -3
  17. package/docs/interfaces/composablecondition.html +2 -2
  18. package/docs/interfaces/condition.html +1 -1
  19. package/docs/interfaces/controlelement.html +5 -5
  20. package/docs/interfaces/controlprops.html +17 -17
  21. package/docs/interfaces/controlstate.html +2 -2
  22. package/docs/interfaces/controlwithdetailprops.html +18 -18
  23. package/docs/interfaces/dispatchcellprops.html +13 -13
  24. package/docs/interfaces/dispatchcellstateprops.html +13 -13
  25. package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
  26. package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
  27. package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
  28. package/docs/interfaces/enumcellprops.html +15 -15
  29. package/docs/interfaces/enumoption.html +2 -2
  30. package/docs/interfaces/formatted.html +2 -2
  31. package/docs/interfaces/grouplayout.html +5 -5
  32. package/docs/interfaces/horizontallayout.html +4 -4
  33. package/docs/interfaces/initaction.html +6 -6
  34. package/docs/interfaces/initactionoptions.html +3 -17
  35. package/docs/interfaces/jsonformscellrendererregistryentry.html +2 -2
  36. package/docs/interfaces/jsonformscore.html +7 -21
  37. package/docs/interfaces/jsonformsdefaultdataregistryentry.html +2 -2
  38. package/docs/interfaces/jsonformsextendedstate.html +1 -1
  39. package/docs/interfaces/{jsonformslocalestate.html → jsonformsi18nstate.html} +20 -20
  40. package/docs/interfaces/jsonformsprops.html +9 -24
  41. package/docs/interfaces/jsonformsrendererregistryentry.html +2 -2
  42. package/docs/interfaces/jsonformsstate.html +1 -1
  43. package/docs/interfaces/jsonformsstore.html +5 -5
  44. package/docs/interfaces/jsonformssubstates.html +18 -8
  45. package/docs/interfaces/jsonformsuischemaregistryentry.html +2 -2
  46. package/docs/interfaces/labeldescription.html +2 -2
  47. package/docs/interfaces/labelelement.html +4 -4
  48. package/docs/interfaces/layout.html +4 -4
  49. package/docs/interfaces/layoutprops.html +10 -10
  50. package/docs/interfaces/leafcondition.html +3 -3
  51. package/docs/interfaces/orcondition.html +2 -2
  52. package/docs/interfaces/ownpropsofcell.html +10 -10
  53. package/docs/interfaces/ownpropsofcontrol.html +9 -9
  54. package/docs/interfaces/ownpropsofenum.html +1 -1
  55. package/docs/interfaces/ownpropsofenumcell.html +11 -11
  56. package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
  57. package/docs/interfaces/ownpropsoflayout.html +9 -9
  58. package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
  59. package/docs/interfaces/ownpropsofrenderer.html +8 -8
  60. package/docs/interfaces/registerdefaultdataaction.html +3 -3
  61. package/docs/interfaces/removecellrendereraction.html +3 -3
  62. package/docs/interfaces/removerendereraction.html +3 -3
  63. package/docs/interfaces/removeuischemaaction.html +2 -2
  64. package/docs/interfaces/rendererprops.html +9 -9
  65. package/docs/interfaces/rule.html +2 -2
  66. package/docs/interfaces/schemabasedcondition.html +3 -3
  67. package/docs/interfaces/scopable.html +1 -1
  68. package/docs/interfaces/setajvaction.html +3 -3
  69. package/docs/interfaces/setconfigaction.html +2 -2
  70. package/docs/interfaces/setlocaleaction.html +3 -3
  71. package/docs/interfaces/setschemaaction.html +2 -2
  72. package/docs/interfaces/{setlocalizeduischemasaction.html → settranslatoraction.html} +29 -15
  73. package/docs/interfaces/setuischemaaction.html +2 -2
  74. package/docs/interfaces/setvalidationmodeaction.html +2 -2
  75. package/docs/interfaces/statepropsofarraycontrol.html +18 -18
  76. package/docs/interfaces/statepropsofarraylayout.html +18 -18
  77. package/docs/interfaces/statepropsofcell.html +13 -13
  78. package/docs/interfaces/statepropsofcombinator.html +12 -12
  79. package/docs/interfaces/statepropsofcontrol.html +16 -16
  80. package/docs/interfaces/statepropsofcontrolwithdetail.html +17 -17
  81. package/docs/interfaces/statepropsofenumcell.html +14 -14
  82. package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -23
  83. package/docs/interfaces/statepropsoflayout.html +10 -10
  84. package/docs/interfaces/statepropsofmasteritem.html +7 -7
  85. package/docs/interfaces/statepropsofrenderer.html +9 -9
  86. package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
  87. package/docs/interfaces/uischemaelement.html +3 -3
  88. package/docs/interfaces/unregisterdefaultdataaction.html +2 -2
  89. package/docs/interfaces/updateaction.html +3 -3
  90. package/docs/interfaces/updatecoreaction.html +6 -6
  91. package/docs/interfaces/updateerrorsaction.html +2 -2
  92. package/docs/interfaces/{setlocalizedschemasaction.html → updatei18naction.html} +43 -15
  93. package/docs/interfaces/verticallayout.html +4 -4
  94. package/docs/interfaces/withclassname.html +1 -1
  95. package/lib/Helpers.d.ts +5 -0
  96. package/lib/Helpers.js +33 -0
  97. package/lib/Helpers.js.map +1 -0
  98. package/lib/actions/actions.d.ts +181 -0
  99. package/lib/actions/actions.js +173 -0
  100. package/lib/actions/actions.js.map +1 -0
  101. package/lib/actions/index.d.ts +1 -180
  102. package/lib/actions/index.js +26 -122
  103. package/lib/actions/index.js.map +1 -1
  104. package/lib/configDefault.js +2 -1
  105. package/lib/configDefault.js.map +1 -1
  106. package/lib/generators/Generate.d.ts +6 -0
  107. package/lib/generators/Generate.js +35 -0
  108. package/lib/generators/Generate.js.map +1 -0
  109. package/lib/generators/index.d.ts +3 -10
  110. package/lib/generators/index.js +28 -9
  111. package/lib/generators/index.js.map +1 -1
  112. package/lib/generators/schema.d.ts +1 -1
  113. package/lib/generators/schema.js +3 -1
  114. package/lib/generators/schema.js.map +1 -1
  115. package/lib/generators/uischema.d.ts +1 -2
  116. package/lib/generators/uischema.js +12 -10
  117. package/lib/generators/uischema.js.map +1 -1
  118. package/lib/i18n/i18nTypes.d.ts +15 -0
  119. package/lib/i18n/i18nTypes.js +3 -0
  120. package/lib/i18n/i18nTypes.js.map +1 -0
  121. package/lib/i18n/i18nUtil.d.ts +11 -0
  122. package/lib/i18n/i18nUtil.js +58 -0
  123. package/lib/i18n/i18nUtil.js.map +1 -0
  124. package/lib/i18n/index.d.ts +2 -0
  125. package/lib/i18n/index.js +6 -0
  126. package/lib/i18n/index.js.map +1 -0
  127. package/lib/index.d.ts +6 -18
  128. package/lib/index.js +10 -15
  129. package/lib/index.js.map +1 -1
  130. package/lib/jsonforms-core.js +9 -12
  131. package/lib/jsonforms-core.js.map +1 -1
  132. package/lib/models/draft4.js +2 -1
  133. package/lib/models/draft4.js.map +1 -1
  134. package/lib/models/index.d.ts +5 -0
  135. package/lib/models/index.js +33 -0
  136. package/lib/models/index.js.map +1 -0
  137. package/lib/models/jsonSchema.js +24 -0
  138. package/lib/models/jsonSchema.js.map +1 -1
  139. package/lib/models/uischema.js +29 -2
  140. package/lib/models/uischema.js.map +1 -1
  141. package/lib/reducers/cells.d.ts +1 -1
  142. package/lib/reducers/cells.js +27 -1
  143. package/lib/reducers/cells.js.map +1 -1
  144. package/lib/reducers/config.d.ts +1 -1
  145. package/lib/reducers/config.js +5 -3
  146. package/lib/reducers/config.js.map +1 -1
  147. package/lib/reducers/core.d.ts +5 -7
  148. package/lib/reducers/core.js +78 -63
  149. package/lib/reducers/core.js.map +1 -1
  150. package/lib/reducers/default-data.d.ts +1 -1
  151. package/lib/reducers/default-data.js +6 -3
  152. package/lib/reducers/default-data.js.map +1 -1
  153. package/lib/reducers/i18n.d.ts +8 -11
  154. package/lib/reducers/i18n.js +40 -23
  155. package/lib/reducers/i18n.js.map +1 -1
  156. package/lib/reducers/index.d.ts +9 -49
  157. package/lib/reducers/index.js +33 -91
  158. package/lib/reducers/index.js.map +1 -1
  159. package/lib/reducers/reducers.d.ts +37 -0
  160. package/lib/reducers/reducers.js +107 -0
  161. package/lib/reducers/reducers.js.map +1 -0
  162. package/lib/reducers/renderers.d.ts +1 -1
  163. package/lib/reducers/renderers.js +27 -1
  164. package/lib/reducers/renderers.js.map +1 -1
  165. package/lib/reducers/selectors.d.ts +15 -0
  166. package/lib/reducers/selectors.js +56 -0
  167. package/lib/reducers/selectors.js.map +1 -0
  168. package/lib/reducers/uischemas.d.ts +2 -2
  169. package/lib/reducers/uischemas.js +9 -6
  170. package/lib/reducers/uischemas.js.map +1 -1
  171. package/lib/store.d.ts +5 -8
  172. package/lib/store.js +24 -0
  173. package/lib/store.js.map +1 -1
  174. package/lib/testers/index.d.ts +1 -204
  175. package/lib/testers/index.js +3 -376
  176. package/lib/testers/index.js.map +1 -1
  177. package/lib/testers/testers.d.ts +203 -0
  178. package/lib/testers/testers.js +421 -0
  179. package/lib/testers/testers.js.map +1 -0
  180. package/lib/util/Formatted.js +24 -0
  181. package/lib/util/Formatted.js.map +1 -1
  182. package/lib/util/array.js +25 -0
  183. package/lib/util/array.js.map +1 -1
  184. package/lib/util/cell.d.ts +11 -4
  185. package/lib/util/cell.js +61 -17
  186. package/lib/util/cell.js.map +1 -1
  187. package/lib/util/combinators.d.ts +2 -3
  188. package/lib/util/combinators.js +5 -2
  189. package/lib/util/combinators.js.map +1 -1
  190. package/lib/util/ids.js +8 -4
  191. package/lib/util/ids.js.map +1 -1
  192. package/lib/util/index.d.ts +11 -45
  193. package/lib/util/index.js +14 -104
  194. package/lib/util/index.js.map +1 -1
  195. package/lib/util/label.d.ts +1 -2
  196. package/lib/util/label.js +7 -4
  197. package/lib/util/label.js.map +1 -1
  198. package/lib/util/path.d.ts +2 -1
  199. package/lib/util/path.js +12 -6
  200. package/lib/util/path.js.map +1 -1
  201. package/lib/util/renderer.d.ts +17 -17
  202. package/lib/util/renderer.js +163 -76
  203. package/lib/util/renderer.js.map +1 -1
  204. package/lib/util/resolvers.d.ts +1 -14
  205. package/lib/util/resolvers.js +9 -215
  206. package/lib/util/resolvers.js.map +1 -1
  207. package/lib/util/runtime.d.ts +12 -2
  208. package/lib/util/runtime.js +59 -17
  209. package/lib/util/runtime.js.map +1 -1
  210. package/lib/util/schema.js +27 -1
  211. package/lib/util/schema.js.map +1 -1
  212. package/lib/util/uischema.d.ts +1 -1
  213. package/lib/util/uischema.js +11 -7
  214. package/lib/util/uischema.js.map +1 -1
  215. package/lib/util/util.d.ts +31 -0
  216. package/lib/util/util.js +112 -0
  217. package/lib/util/util.js.map +1 -0
  218. package/lib/util/validator.d.ts +3 -2
  219. package/lib/util/validator.js +6 -5
  220. package/lib/util/validator.js.map +1 -1
  221. package/package.json +7 -9
  222. package/src/Helpers.ts +38 -0
  223. package/src/actions/actions.ts +345 -0
  224. package/src/actions/index.ts +1 -312
  225. package/src/configDefault.ts +1 -0
  226. package/src/generators/Generate.ts +43 -0
  227. package/src/generators/index.ts +3 -21
  228. package/src/generators/schema.ts +1 -1
  229. package/src/generators/uischema.ts +4 -4
  230. package/src/i18n/i18nTypes.ts +17 -0
  231. package/src/i18n/i18nUtil.ts +76 -0
  232. package/src/i18n/index.ts +2 -0
  233. package/src/index.ts +7 -31
  234. package/src/models/draft4.ts +1 -0
  235. package/src/models/index.ts +30 -0
  236. package/src/models/jsonSchema.ts +1 -0
  237. package/src/models/uischema.ts +1 -0
  238. package/src/reducers/cells.ts +2 -1
  239. package/src/reducers/config.ts +2 -1
  240. package/src/reducers/core.ts +74 -81
  241. package/src/reducers/default-data.ts +2 -1
  242. package/src/reducers/i18n.ts +42 -35
  243. package/src/reducers/index.ts +9 -158
  244. package/src/reducers/reducers.ts +148 -0
  245. package/src/reducers/renderers.ts +2 -1
  246. package/src/reducers/selectors.ts +65 -0
  247. package/src/reducers/uischemas.ts +4 -2
  248. package/src/store.ts +11 -8
  249. package/src/testers/index.ts +1 -516
  250. package/src/testers/testers.ts +547 -0
  251. package/src/util/Formatted.ts +1 -0
  252. package/src/util/array.ts +25 -0
  253. package/src/util/cell.ts +91 -19
  254. package/src/util/combinators.ts +2 -4
  255. package/src/util/ids.ts +1 -0
  256. package/src/util/index.ts +11 -126
  257. package/src/util/label.ts +2 -2
  258. package/src/util/path.ts +4 -1
  259. package/src/util/renderer.ts +168 -85
  260. package/src/util/resolvers.ts +2 -261
  261. package/src/util/runtime.ts +46 -2
  262. package/src/util/schema.ts +26 -1
  263. package/src/util/uischema.ts +2 -1
  264. package/src/util/util.ts +127 -0
  265. package/src/util/validator.ts +5 -8
  266. package/test/reducers/core.test.ts +31 -223
  267. package/test/util/cell.test.ts +33 -2
  268. package/test/util/renderer.test.ts +483 -3
  269. package/test/util/resolvers.test.ts +1 -59
  270. package/test/util/runtime.test.ts +264 -4
  271. package/docs/interfaces/labels.html +0 -157
  272. package/docs/interfaces/schemaref.html +0 -160
  273. package/docs/interfaces/schemarefs.html +0 -138
@@ -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 { Ajv, ErrorObject, ValidateFunction } from 'ajv';
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/validator';
48
- import { Reducer } from '../util/type';
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: alwaysValid,
78
+ validator: undefined,
92
79
  ajv: undefined,
93
- refParserOptions: undefined,
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' ? alwaysValid : thisAjv.compile(action.schema);
180
- const e = sanitizeErrors(v, action.data);
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
- refParserOptions: o,
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
- ? alwaysValid
173
+ ? undefined
209
174
  : thisAjv.compile(action.schema);
210
- errors = sanitizeErrors(validator, action.data);
175
+ errors = validate(validator, action.data);
211
176
  } else if (state.data !== action.data) {
212
- errors = sanitizeErrors(validator, action.data);
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.refParserOptions !== refParserOptions ||
223
- state.validationMode !== validationMode;
187
+ state.validationMode !== validationMode
224
188
  return stateChanged
225
189
  ? {
226
190
  ...state,
227
- data: state.data === action.data ? state.data : action.data,
228
- schema: state.schema === action.schema ? state.schema : action.schema,
229
- uischema: state.uischema === action.uischema ? state.uischema : action.uischema,
230
- ajv: thisAjv === state.ajv ? state.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 === state.validator ? state.validator : validator,
233
- refParserOptions: refParserOptions === state.refParserOptions ? state.refParserOptions : refParserOptions,
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' ? alwaysValid : currentAjv.compile(state.schema);
241
- const errors = sanitizeErrors(validator, state.data);
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 = sanitizeErrors(v, state.data);
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 = sanitizeErrors(state.validator, result);
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 = sanitizeErrors(state.validator, newState);
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 = sanitizeErrors(alwaysValid, state.data);
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 = sanitizeErrors(validator, state.data);
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
- ).map(error => error.dataPath);
349
-
350
- return filter(errors, error => {
351
- // Filter errors that match any keyword that we don't want to show in the UI
352
- if (filteredErrorKeywords.indexOf(error.keyword) !== -1) {
353
- return false;
354
- }
355
-
356
- let result = matchPath(error.dataPath);
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/type';
32
+ import { Reducer } from '../util';
32
33
 
33
34
  export interface JsonFormsDefaultDataRegistryEntry {
34
35
  schemaPath: string;
@@ -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
- export interface JsonFormsLocaleState {
30
- locale?: string;
31
- localizedSchemas: Map<string, JsonSchema>;
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 initState: JsonFormsLocaleState = {
36
- locale: undefined,
37
- localizedSchemas: new Map(),
38
- localizedUISchemas: new Map()
30
+ export const defaultJsonFormsI18nState: JsonFormsI18nState = {
31
+ locale: 'en',
32
+ translate: defaultTranslator,
33
+ translateError: defaultErrorTranslator
39
34
  };
40
35
 
41
- export const i18nReducer: Reducer<any, any> = (state = initState, action) => {
36
+ export const i18nReducer: Reducer<JsonFormsI18nState, I18nActions> = (state = defaultJsonFormsI18nState, action) => {
42
37
  switch (action.type) {
43
- case SET_LOCALIZED_SCHEMAS:
44
- return {
45
- ...state,
46
- localizedSchemas: action.localizedSchemas
47
- };
48
- case SET_LOCALIZED_UISCHEMAS:
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
- localizedUISchemas: action.localizedUISchemas
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?: JsonFormsLocaleState) => {
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 findLocalizedSchema = (locale: string) => (
72
- state?: JsonFormsLocaleState
73
- ): JsonSchema => {
82
+ export const fetchTranslator = (state?: JsonFormsI18nState) => {
74
83
  if (state === undefined) {
75
- return undefined;
84
+ return defaultTranslator;
76
85
  }
77
- return state.localizedSchemas.get(locale);
78
- };
86
+ return state.translate;
87
+ }
79
88
 
80
- export const findLocalizedUISchema = (locale: string) => (
81
- state?: JsonFormsLocaleState
82
- ): UISchemaElement => {
89
+ export const fetchErrorTranslator = (state?: JsonFormsI18nState) => {
83
90
  if (state === undefined) {
84
- return undefined;
91
+ return defaultErrorTranslator;
85
92
  }
86
- return state.localizedUISchemas.get(locale);
87
- };
93
+ return state.translateError;
94
+ }
@@ -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
- import { Generate } from '../generators';
60
- import { JsonFormsCellRendererRegistryEntry } from './cells';
61
- import { JsonSchema } from '../models/jsonSchema';
62
- import RefParser from 'json-schema-ref-parser';
63
-
64
- import { cellReducer } from './cells';
65
- import { configReducer } from './config';
66
- import get from 'lodash/get';
67
- import { Ajv } from 'ajv';
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';