@jsonforms/core 3.0.0-alpha.0 → 3.0.0-beta.0

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 (268) 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 +1095 -703
  5. package/docs/index.html +70 -43
  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 -3
  35. package/docs/interfaces/jsonformscellrendererregistryentry.html +2 -2
  36. package/docs/interfaces/jsonformscore.html +7 -7
  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 -9
  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/{setlocalizedschemasaction.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 -9
  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/{setlocalizeduischemasaction.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/actions/actions.d.ts +181 -0
  97. package/lib/actions/index.d.ts +1 -178
  98. package/lib/configDefault.d.ts +6 -6
  99. package/lib/generators/Generate.d.ts +6 -0
  100. package/lib/generators/index.d.ts +3 -10
  101. package/lib/generators/schema.d.ts +8 -8
  102. package/lib/generators/uischema.d.ts +12 -13
  103. package/lib/i18n/i18nTypes.d.ts +15 -0
  104. package/lib/i18n/i18nUtil.d.ts +18 -0
  105. package/lib/i18n/index.d.ts +2 -0
  106. package/lib/index.d.ts +11 -23
  107. package/lib/jsonforms-core.cjs.js +2445 -0
  108. package/lib/jsonforms-core.cjs.js.map +1 -0
  109. package/lib/jsonforms-core.esm.js +2164 -0
  110. package/lib/jsonforms-core.esm.js.map +1 -0
  111. package/lib/models/draft4.d.ts +198 -198
  112. package/lib/models/index.d.ts +5 -0
  113. package/lib/models/jsonSchema.d.ts +3 -3
  114. package/lib/models/jsonSchema4.d.ts +110 -110
  115. package/lib/models/jsonSchema7.d.ts +119 -119
  116. package/lib/models/uischema.d.ts +201 -201
  117. package/lib/reducers/cells.d.ts +11 -11
  118. package/lib/reducers/config.d.ts +3 -3
  119. package/lib/reducers/core.d.ts +24 -23
  120. package/lib/reducers/default-data.d.ts +10 -10
  121. package/lib/reducers/i18n.d.ts +8 -11
  122. package/lib/reducers/index.d.ts +9 -47
  123. package/lib/reducers/reducers.d.ts +29 -0
  124. package/lib/reducers/renderers.d.ts +10 -10
  125. package/lib/reducers/selectors.d.ts +15 -0
  126. package/lib/reducers/uischemas.d.ts +10 -10
  127. package/lib/store.d.ts +53 -56
  128. package/lib/testers/index.d.ts +1 -204
  129. package/lib/testers/testers.d.ts +203 -0
  130. package/lib/util/Formatted.d.ts +19 -19
  131. package/lib/util/array.d.ts +3 -3
  132. package/lib/util/cell.d.ts +79 -79
  133. package/lib/util/combinators.d.ts +10 -11
  134. package/lib/util/ids.d.ts +3 -3
  135. package/lib/util/index.d.ts +15 -49
  136. package/lib/util/label.d.ts +9 -10
  137. package/lib/util/path.d.ts +25 -24
  138. package/lib/util/renderer.d.ts +398 -395
  139. package/lib/util/resolvers.d.ts +25 -25
  140. package/lib/util/runtime.d.ts +18 -19
  141. package/lib/util/schema.d.ts +1 -1
  142. package/lib/util/type.d.ts +174 -174
  143. package/lib/util/uischema.d.ts +5 -5
  144. package/lib/util/util.d.ts +31 -0
  145. package/lib/util/validator.d.ts +3 -2
  146. package/package.json +18 -14
  147. package/rollup.config.js +44 -0
  148. package/{lib/models/jsonSchema4.js → src/Helpers.ts} +16 -8
  149. package/src/actions/actions.ts +345 -0
  150. package/src/actions/index.ts +1 -310
  151. package/src/configDefault.ts +1 -0
  152. package/{lib/util/validator.js → src/generators/Generate.ts} +18 -11
  153. package/src/generators/index.ts +3 -21
  154. package/src/generators/schema.ts +1 -1
  155. package/src/generators/uischema.ts +4 -4
  156. package/src/i18n/i18nTypes.ts +17 -0
  157. package/src/i18n/i18nUtil.ts +105 -0
  158. package/src/i18n/index.ts +2 -0
  159. package/src/index.ts +7 -31
  160. package/src/models/draft4.ts +1 -0
  161. package/{lib/util/type.js → src/models/index.ts} +10 -7
  162. package/src/models/jsonSchema.ts +1 -0
  163. package/src/models/uischema.ts +1 -0
  164. package/src/reducers/cells.ts +2 -1
  165. package/src/reducers/config.ts +2 -1
  166. package/src/reducers/core.ts +74 -52
  167. package/src/reducers/default-data.ts +2 -1
  168. package/src/reducers/i18n.ts +42 -35
  169. package/src/reducers/index.ts +9 -154
  170. package/src/reducers/reducers.ts +128 -0
  171. package/src/reducers/renderers.ts +2 -1
  172. package/src/reducers/selectors.ts +65 -0
  173. package/src/reducers/uischemas.ts +4 -2
  174. package/src/store.ts +11 -8
  175. package/src/testers/index.ts +1 -516
  176. package/src/testers/testers.ts +547 -0
  177. package/src/util/Formatted.ts +1 -0
  178. package/src/util/array.ts +25 -0
  179. package/src/util/cell.ts +45 -10
  180. package/src/util/combinators.ts +2 -4
  181. package/src/util/ids.ts +1 -0
  182. package/src/util/index.ts +11 -123
  183. package/src/util/label.ts +2 -2
  184. package/src/util/path.ts +4 -1
  185. package/src/util/renderer.ts +139 -66
  186. package/src/util/resolvers.ts +2 -1
  187. package/src/util/runtime.ts +3 -2
  188. package/src/util/schema.ts +26 -1
  189. package/src/util/uischema.ts +2 -1
  190. package/src/util/util.ts +127 -0
  191. package/src/util/validator.ts +5 -8
  192. package/stats.html +3279 -0
  193. package/{lib/configDefault.js → test/i18n/i18nUtil.test.ts} +25 -24
  194. package/test/reducers/core.test.ts +31 -44
  195. package/test/util/cell.test.ts +2 -2
  196. package/test/util/renderer.test.ts +543 -31
  197. package/docs/interfaces/labels.html +0 -157
  198. package/lib/actions/index.js +0 -125
  199. package/lib/actions/index.js.map +0 -1
  200. package/lib/configDefault.js.map +0 -1
  201. package/lib/generators/index.js +0 -12
  202. package/lib/generators/index.js.map +0 -1
  203. package/lib/generators/schema.js +0 -152
  204. package/lib/generators/schema.js.map +0 -1
  205. package/lib/generators/uischema.js +0 -167
  206. package/lib/generators/uischema.js.map +0 -1
  207. package/lib/index.js +0 -45
  208. package/lib/index.js.map +0 -1
  209. package/lib/jsonforms-core.js +0 -19
  210. package/lib/jsonforms-core.js.map +0 -1
  211. package/lib/models/draft4.js +0 -173
  212. package/lib/models/draft4.js.map +0 -1
  213. package/lib/models/jsonSchema.js +0 -3
  214. package/lib/models/jsonSchema.js.map +0 -1
  215. package/lib/models/jsonSchema4.js.map +0 -1
  216. package/lib/models/jsonSchema7.js +0 -30
  217. package/lib/models/jsonSchema7.js.map +0 -1
  218. package/lib/models/uischema.js +0 -31
  219. package/lib/models/uischema.js.map +0 -1
  220. package/lib/reducers/cells.js +0 -16
  221. package/lib/reducers/cells.js.map +0 -1
  222. package/lib/reducers/config.js +0 -44
  223. package/lib/reducers/config.js.map +0 -1
  224. package/lib/reducers/core.js +0 -259
  225. package/lib/reducers/core.js.map +0 -1
  226. package/lib/reducers/default-data.js +0 -42
  227. package/lib/reducers/default-data.js.map +0 -1
  228. package/lib/reducers/i18n.js +0 -66
  229. package/lib/reducers/i18n.js.map +0 -1
  230. package/lib/reducers/index.js +0 -92
  231. package/lib/reducers/index.js.map +0 -1
  232. package/lib/reducers/renderers.js +0 -17
  233. package/lib/reducers/renderers.js.map +0 -1
  234. package/lib/reducers/uischemas.js +0 -57
  235. package/lib/reducers/uischemas.js.map +0 -1
  236. package/lib/store.js +0 -3
  237. package/lib/store.js.map +0 -1
  238. package/lib/testers/index.js +0 -402
  239. package/lib/testers/index.js.map +0 -1
  240. package/lib/util/Formatted.js +0 -3
  241. package/lib/util/Formatted.js.map +0 -1
  242. package/lib/util/array.js +0 -19
  243. package/lib/util/array.js.map +0 -1
  244. package/lib/util/cell.js +0 -133
  245. package/lib/util/cell.js.map +0 -1
  246. package/lib/util/combinators.js +0 -56
  247. package/lib/util/combinators.js.map +0 -1
  248. package/lib/util/ids.js +0 -50
  249. package/lib/util/ids.js.map +0 -1
  250. package/lib/util/index.js +0 -132
  251. package/lib/util/index.js.map +0 -1
  252. package/lib/util/label.js +0 -70
  253. package/lib/util/label.js.map +0 -1
  254. package/lib/util/path.js +0 -84
  255. package/lib/util/path.js.map +0 -1
  256. package/lib/util/renderer.js +0 -447
  257. package/lib/util/renderer.js.map +0 -1
  258. package/lib/util/resolvers.js +0 -165
  259. package/lib/util/resolvers.js.map +0 -1
  260. package/lib/util/runtime.js +0 -159
  261. package/lib/util/runtime.js.map +0 -1
  262. package/lib/util/schema.js +0 -16
  263. package/lib/util/schema.js.map +0 -1
  264. package/lib/util/type.js.map +0 -1
  265. package/lib/util/uischema.js +0 -52
  266. package/lib/util/uischema.js.map +0 -1
  267. package/lib/util/validator.js.map +0 -1
  268. package/webpack.build.js +0 -13
package/src/util/index.ts CHANGED
@@ -22,131 +22,19 @@
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 isEmpty from 'lodash/isEmpty';
26
- import isArray from 'lodash/isArray';
27
- import includes from 'lodash/includes';
28
- import find from 'lodash/find';
29
- import { JsonSchema, Scopable, UISchemaElement } from '../';
30
- import { resolveData, resolveSchema } from './resolvers';
31
- import {
32
- compose as composePaths,
33
- composeWithUi,
34
- toDataPath,
35
- toDataPathSegments
36
- } from './path';
37
- import { isEnabled, isVisible } from './runtime';
38
- import { Ajv } from 'ajv';
39
25
 
40
- export { createCleanLabel, createLabelDescriptionFrom } from './label';
41
-
42
- /**
43
- * Escape the given string such that it can be used as a class name,
44
- * i.e. hashes and slashes will be replaced.
45
- *
46
- * @param {string} s the string that should be converted to a valid class name
47
- * @returns {string} the escaped string
48
- */
49
- export const convertToValidClassName = (s: string): string =>
50
- s.replace('#', 'root').replace(new RegExp('/', 'g'), '_');
51
-
52
- export const formatErrorMessage = (errors: string[]) => {
53
- if (errors === undefined || errors === null) {
54
- return '';
55
- }
56
-
57
- return errors.join('\n');
58
- };
59
-
60
- const hasType = (jsonSchema: JsonSchema, expected: string): boolean => {
61
- return includes(deriveTypes(jsonSchema), expected);
62
- };
63
-
64
- /**
65
- * Derives the type of the jsonSchema element
66
- */
67
- const deriveTypes = (jsonSchema: JsonSchema): string[] => {
68
- if (isEmpty(jsonSchema)) {
69
- return [];
70
- }
71
- if (!isEmpty(jsonSchema.type) && typeof jsonSchema.type === 'string') {
72
- return [jsonSchema.type];
73
- }
74
- if (isArray(jsonSchema.type)) {
75
- return jsonSchema.type;
76
- }
77
- if (
78
- !isEmpty(jsonSchema.properties) ||
79
- !isEmpty(jsonSchema.additionalProperties)
80
- ) {
81
- return ['object'];
82
- }
83
- if (!isEmpty(jsonSchema.items)) {
84
- return ['array'];
85
- }
86
-
87
- if (!isEmpty(jsonSchema.allOf)) {
88
- const allOfType = find(
89
- jsonSchema.allOf,
90
- (schema: JsonSchema) => deriveTypes(schema).length !== 0
91
- );
92
-
93
- if (allOfType) {
94
- return deriveTypes(allOfType);
95
- }
96
- }
97
- // ignore all remaining cases
98
- return [];
99
- };
100
-
101
- /**
102
- * Convenience wrapper around resolveData and resolveSchema.
103
- */
104
- const Resolve: {
105
- schema(
106
- schema: JsonSchema,
107
- schemaPath: string,
108
- rootSchema?: JsonSchema
109
- ): JsonSchema;
110
- data(data: any, path: string): any;
111
- } = {
112
- schema: resolveSchema,
113
- data: resolveData
114
- };
115
- export {
116
- resolveData,
117
- resolveSchema,
118
- } from './resolvers';
119
- export { Resolve };
120
-
121
- // Paths --
122
- const fromScopable = (scopable: Scopable) =>
123
- toDataPathSegments(scopable.scope).join('.');
124
-
125
- const Paths = {
126
- compose: composePaths,
127
- fromScopable
128
- };
129
- export { composePaths, composeWithUi, Paths, toDataPath };
130
-
131
- // Runtime --
132
- const Runtime = {
133
- isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
134
- return isEnabled(uischema, data,undefined, ajv);
135
- },
136
- isVisible(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
137
- return isVisible(uischema, data, undefined, ajv);
138
- }
139
- };
140
- export { isEnabled, isVisible, Runtime, deriveTypes, hasType };
141
-
142
- export * from './renderer';
26
+ export * from './array';
143
27
  export * from './cell';
144
- export * from './runtime';
28
+ export * from './combinators';
145
29
  export * from './Formatted';
146
30
  export * from './ids';
147
- export * from './validator';
148
- export * from './combinators';
149
- export * from './uischema';
150
- export * from './array';
151
- export * from './type';
31
+ export * from './label';
32
+ export * from './path';
33
+ export * from './renderer';
34
+ export * from './resolvers';
35
+ export * from './runtime';
152
36
  export * from './schema';
37
+ export * from './type';
38
+ export * from './uischema';
39
+ export * from './util';
40
+ export * from './validator';
package/src/util/label.ts CHANGED
@@ -22,10 +22,10 @@
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 startCase from 'lodash/startCase';
26
27
 
27
- import { ControlElement, LabelDescription } from '../models/uischema';
28
- import { JsonSchema } from '../models/jsonSchema';
28
+ import { ControlElement, JsonSchema, LabelDescription } from '../models';
29
29
 
30
30
  const deriveLabel = (
31
31
  controlElement: ControlElement,
package/src/util/path.ts CHANGED
@@ -22,9 +22,10 @@
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 isEmpty from 'lodash/isEmpty';
26
27
  import range from 'lodash/range';
27
- import { Scopable } from '../';
28
+ import { Scopable } from '../models';
28
29
 
29
30
  export const compose = (path1: string, path2: string) => {
30
31
  let p1 = path1;
@@ -41,6 +42,8 @@ export const compose = (path1: string, path2: string) => {
41
42
  }
42
43
  };
43
44
 
45
+ export { compose as composePaths };
46
+
44
47
  /**
45
48
  * Convert a schema path (i.e. JSON pointer) to an array by splitting
46
49
  * at the '/' character and removing all schema-specific keywords.
@@ -22,10 +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 get from 'lodash/get';
26
- import { ControlElement, UISchemaElement } from '../models/uischema';
27
- import union from 'lodash/union';
27
+ import { ControlElement, JsonSchema, UISchemaElement } from '../models';
28
28
  import find from 'lodash/find';
29
+ import type {
30
+ JsonFormsCellRendererRegistryEntry,
31
+ JsonFormsRendererRegistryEntry,
32
+ } from '../reducers';
29
33
  import {
30
34
  findUISchema,
31
35
  getAjv,
@@ -33,46 +37,26 @@ import {
33
37
  getConfig,
34
38
  getData,
35
39
  getErrorAt,
40
+ getErrorTranslator,
36
41
  getRenderers,
37
42
  getSchema,
38
43
  getSubErrorsAt,
39
- getUiSchema
44
+ getTranslator,
45
+ getUiSchema,
46
+ JsonFormsUISchemaRegistryEntry,
40
47
  } from '../reducers';
41
48
  import { RankedTester } from '../testers';
42
- import { JsonSchema } from '../models/jsonSchema';
43
- import {
44
- AnyAction,
45
- CombinatorKeyword,
46
- composePaths,
47
- composeWithUi,
48
- createLabelDescriptionFrom,
49
- Dispatch,
50
- formatErrorMessage,
51
- hasShowRule,
52
- isInherentlyEnabled,
53
- isVisible,
54
- moveDown,
55
- moveUp,
56
- Resolve,
57
- resolveSubSchemas
58
- } from '../util';
49
+ import { hasShowRule, isInherentlyEnabled, isVisible } from './runtime';
50
+ import { createLabelDescriptionFrom } from './label';
51
+ import { CombinatorKeyword, resolveSubSchemas } from './combinators';
52
+ import { moveDown, moveUp } from './array';
53
+ import { AnyAction, Dispatch } from './type';
54
+ import { Resolve } from './util';
55
+ import { composePaths, composeWithUi } from './path';
59
56
  import { CoreActions, update } from '../actions';
60
57
  import { ErrorObject } from 'ajv';
61
58
  import { JsonFormsState } from '../store';
62
- import { JsonFormsRendererRegistryEntry } from '../reducers/renderers';
63
- import { JsonFormsCellRendererRegistryEntry } from '../reducers/cells';
64
- import { JsonFormsUISchemaRegistryEntry } from '../reducers/uischemas';
65
-
66
- export { JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry };
67
-
68
- export interface Labels {
69
- default: string;
70
- [additionalLabels: string]: string;
71
- }
72
-
73
- export const isPlainLabel = (label: string | Labels): label is string => {
74
- return typeof label === 'string';
75
- };
59
+ import { getCombinedErrorMessage, getI18nKey, getI18nKeyPrefix, Translator } from '../i18n';
76
60
 
77
61
  const isRequired = (
78
62
  schema: JsonSchema,
@@ -103,16 +87,31 @@ const isRequired = (
103
87
  * Adds an asterisk to the given label string based
104
88
  * on the required parameter.
105
89
  *
106
- * @param {string} label the label string
90
+ * @param {string | undefined} label the label string
107
91
  * @param {boolean} required whether the label belongs to a control which is required
92
+ * @param {boolean} hideRequiredAsterisk applied UI Schema option
108
93
  * @returns {string} the label string
109
94
  */
110
95
  export const computeLabel = (
111
- label: string,
96
+ label: string | undefined,
112
97
  required: boolean,
113
98
  hideRequiredAsterisk: boolean
114
99
  ): string => {
115
- return required && !hideRequiredAsterisk ? label + '*' : label;
100
+ return `${label ?? ''}${ required && !hideRequiredAsterisk ? '*' : ''}`;
101
+ };
102
+
103
+ /**
104
+ * Indicates whether to mark a field as required.
105
+ *
106
+ * @param {boolean} required whether the label belongs to a control which is required
107
+ * @param {boolean} hideRequiredAsterisk applied UI Schema option
108
+ * @returns {boolean} should the field be marked as required
109
+ */
110
+ export const showAsRequired = (
111
+ required: boolean,
112
+ hideRequiredAsterisk: boolean
113
+ ): boolean => {
114
+ return required && !hideRequiredAsterisk;
116
115
  };
117
116
 
118
117
  /**
@@ -156,7 +155,7 @@ export const createDefaultValue = (schema: JsonSchema) => {
156
155
  */
157
156
  export const isDescriptionHidden = (
158
157
  visible: boolean,
159
- description: string,
158
+ description: string | undefined,
160
159
  isFocused: boolean,
161
160
  showUnfocusedDescription: boolean
162
161
  ): boolean => {
@@ -176,16 +175,45 @@ export interface EnumOption {
176
175
  value: any;
177
176
  }
178
177
 
179
- export const enumToEnumOptionMapper = (e: any): EnumOption => {
180
- const stringifiedEnum = typeof e === 'string' ? e : JSON.stringify(e);
181
- return { label: stringifiedEnum, value: e };
178
+ export const enumToEnumOptionMapper = (
179
+ e: any,
180
+ t?: Translator,
181
+ i18nKey?: string
182
+ ): EnumOption => {
183
+ let label = typeof e === 'string' ? e : JSON.stringify(e);
184
+ if (t) {
185
+ if (i18nKey) {
186
+ label = t(`${i18nKey}.${label}`, label);
187
+ } else {
188
+ label = t(label, label);
189
+ }
190
+ }
191
+ return { label, value: e };
182
192
  };
183
193
 
184
- export const oneOfToEnumOptionMapper = (e: any): EnumOption => ({
185
- value: e.const,
186
- label:
187
- e.title ?? (typeof e.const === 'string' ? e.const : JSON.stringify(e.const))
188
- });
194
+ export const oneOfToEnumOptionMapper = (
195
+ e: any,
196
+ t?: Translator,
197
+ fallbackI18nKey?: string
198
+ ): EnumOption => {
199
+ let label =
200
+ e.title ??
201
+ (typeof e.const === 'string' ? e.const : JSON.stringify(e.const));
202
+ if (t) {
203
+ // prefer schema keys as they can be more specialized
204
+ if (e.i18n) {
205
+ label = t(e.i18n, label);
206
+ } else if (fallbackI18nKey) {
207
+ label = t(`${fallbackI18nKey}.${label}`, label);
208
+ } else {
209
+ label = t(label, label);
210
+ }
211
+ }
212
+ return {
213
+ label,
214
+ value: e.const,
215
+ };
216
+ };
189
217
 
190
218
  export interface OwnPropsOfRenderer {
191
219
  /**
@@ -325,7 +353,7 @@ export interface StatePropsOfControl extends StatePropsOfScopedRenderer {
325
353
  /**
326
354
  * The label for the rendered element.
327
355
  */
328
- label: string | Labels;
356
+ label: string;
329
357
 
330
358
  /**
331
359
  * Description of input cell
@@ -415,9 +443,8 @@ export const mapStateToControlProps = (
415
443
  controlElement.scope,
416
444
  rootSchema
417
445
  );
418
- const errors = formatErrorMessage(
419
- union(getErrorAt(path, resolvedSchema)(state).map(error => error.message))
420
- );
446
+ const errors = getErrorAt(path, resolvedSchema)(state);
447
+
421
448
  const description =
422
449
  resolvedSchema !== undefined ? resolvedSchema.description : '';
423
450
  const data = Resolve.data(rootData, path);
@@ -432,18 +459,26 @@ export const mapStateToControlProps = (
432
459
  rootData,
433
460
  config
434
461
  );
462
+
463
+ const schema = resolvedSchema ?? rootSchema;
464
+ const t = getTranslator()(state);
465
+ const te = getErrorTranslator()(state);
466
+ const i18nLabel = t(getI18nKey(schema, uischema, path, 'label'), label);
467
+ const i18nDescription = t(getI18nKey(schema, uischema, path, 'description'), description);
468
+ const i18nErrorMessage = getCombinedErrorMessage(errors, te, t, schema, uischema, path);
469
+
435
470
  return {
436
471
  data,
437
- description,
438
- errors,
439
- label,
472
+ description: i18nDescription,
473
+ errors: i18nErrorMessage,
474
+ label: i18nLabel,
440
475
  visible,
441
476
  enabled,
442
477
  id,
443
478
  path,
444
479
  required,
445
- uischema: ownProps.uischema,
446
- schema: resolvedSchema || rootSchema,
480
+ uischema,
481
+ schema,
447
482
  config: getConfig(state),
448
483
  cells: ownProps.cells || state.jsonforms.cells,
449
484
  rootSchema
@@ -478,8 +513,20 @@ export const mapStateToEnumControlProps = (
478
513
  const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
479
514
  const options: EnumOption[] =
480
515
  ownProps.options ||
481
- props.schema.enum?.map(enumToEnumOptionMapper) ||
482
- (props.schema.const && [enumToEnumOptionMapper(props.schema.const)]);
516
+ props.schema.enum?.map(e =>
517
+ enumToEnumOptionMapper(
518
+ e,
519
+ getTranslator()(state),
520
+ getI18nKeyPrefix(props.schema, props.uischema, props.path)
521
+ )
522
+ ) ||
523
+ (props.schema.const && [
524
+ enumToEnumOptionMapper(
525
+ props.schema.const,
526
+ getTranslator()(state),
527
+ getI18nKeyPrefix(props.schema, props.uischema, props.path)
528
+ )
529
+ ]);
483
530
  return {
484
531
  ...props,
485
532
  options
@@ -499,7 +546,13 @@ export const mapStateToOneOfEnumControlProps = (
499
546
  const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
500
547
  const options: EnumOption[] =
501
548
  ownProps.options ||
502
- (props.schema.oneOf as JsonSchema[])?.map(oneOfToEnumOptionMapper);
549
+ (props.schema.oneOf as JsonSchema[])?.map(oneOfSubSchema =>
550
+ oneOfToEnumOptionMapper(
551
+ oneOfSubSchema,
552
+ getTranslator()(state),
553
+ getI18nKeyPrefix(props.schema, props.uischema, props.path)
554
+ )
555
+ );
503
556
  return {
504
557
  ...props,
505
558
  options
@@ -521,8 +574,20 @@ export const mapStateToMultiEnumControlProps = (
521
574
  const options: EnumOption[] =
522
575
  ownProps.options ||
523
576
  (items?.oneOf &&
524
- (items.oneOf as JsonSchema[]).map(oneOfToEnumOptionMapper)) ||
525
- items?.enum?.map(enumToEnumOptionMapper);
577
+ (items.oneOf as JsonSchema[]).map(oneOfSubSchema =>
578
+ oneOfToEnumOptionMapper(
579
+ oneOfSubSchema,
580
+ state.jsonforms.i18n?.translate,
581
+ getI18nKeyPrefix(props.schema, props.uischema, props.path)
582
+ )
583
+ )) ||
584
+ items?.enum?.map(e =>
585
+ enumToEnumOptionMapper(
586
+ e,
587
+ state.jsonforms.i18n?.translate,
588
+ getI18nKeyPrefix(props.schema, props.uischema, props.path)
589
+ )
590
+ );
526
591
  return {
527
592
  ...props,
528
593
  options
@@ -857,7 +922,7 @@ export interface StatePropsOfCombinator extends OwnPropsOfControl {
857
922
  data: any;
858
923
  }
859
924
 
860
- const mapStateToCombinatorRendererProps = (
925
+ export const mapStateToCombinatorRendererProps = (
861
926
  state: JsonFormsState,
862
927
  ownProps: OwnPropsOfControl,
863
928
  keyword: CombinatorKeyword
@@ -885,7 +950,8 @@ const mapStateToCombinatorRendererProps = (
885
950
  'required',
886
951
  'additionalProperties',
887
952
  'type',
888
- 'enum'
953
+ 'enum',
954
+ 'const'
889
955
  ];
890
956
  const dataIsValid = (errors: ErrorObject[]): boolean => {
891
957
  return (
@@ -977,9 +1043,18 @@ export const mapStateToArrayLayoutProps = (
977
1043
  } = mapStateToControlWithDetailProps(state, ownProps);
978
1044
 
979
1045
  const resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
980
- const childErrors = formatErrorMessage(
981
- getSubErrorsAt(path, resolvedSchema)(state).map(error => error.message)
1046
+
1047
+ // TODO Does not consider a specialized '.custom' error message overriding all other error messages
1048
+ // TODO Does not consider 'i18n' keys which are specified in the ui schemas of the sub errors
1049
+ const childErrors = getCombinedErrorMessage(
1050
+ getSubErrorsAt(path, resolvedSchema)(state),
1051
+ getErrorTranslator()(state),
1052
+ getTranslator()(state),
1053
+ undefined,
1054
+ undefined,
1055
+ undefined
982
1056
  );
1057
+
983
1058
  const allErrors =
984
1059
  errors +
985
1060
  (errors.length > 0 && childErrors.length > 0 ? '\n' : '') +
@@ -995,8 +1070,6 @@ export const mapStateToArrayLayoutProps = (
995
1070
  };
996
1071
  };
997
1072
 
998
- export type CombinatorProps = StatePropsOfCombinator & DispatchPropsOfControl;
999
-
1000
1073
  /**
1001
1074
  * Props of an array control.
1002
1075
  */
@@ -22,9 +22,10 @@
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 isEmpty from 'lodash/isEmpty';
26
27
  import get from 'lodash/get';
27
- import { JsonSchema } from '../models/jsonSchema';
28
+ import { JsonSchema } from '../models';
28
29
 
29
30
  /**
30
31
  * Map for storing refs and the respective schemas they are pointing to.
@@ -22,6 +22,7 @@
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 has from 'lodash/has';
26
27
  import {
27
28
  AndCondition,
@@ -32,10 +33,10 @@ import {
32
33
  SchemaBasedCondition,
33
34
  Scopable,
34
35
  UISchemaElement
35
- } from '../models/uischema';
36
+ } from '../models';
36
37
  import { resolveData } from './resolvers';
37
38
  import { composeWithUi } from './path';
38
- import { Ajv } from 'ajv';
39
+ import Ajv from 'ajv';
39
40
  import { getAjv } from '../reducers';
40
41
  import { JsonFormsState } from '../store';
41
42
  import { JsonSchema } from '../models/jsonSchema';
@@ -1,4 +1,29 @@
1
- import find from "lodash/find";
1
+ /*
2
+ The MIT License
3
+
4
+ Copyright (c) 2017-2019 EclipseSource Munich
5
+ https://github.com/eclipsesource/jsonforms
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+ */
25
+
26
+ import find from 'lodash/find';
2
27
 
3
28
  export const getFirstPrimitiveProp = (schema: any) => {
4
29
  if (schema.properties) {
@@ -22,8 +22,9 @@
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 isEmpty from 'lodash/isEmpty';
26
- import { isLayout, UISchemaElement } from '../models/uischema';
27
+ import { isLayout, UISchemaElement } from '../models';
27
28
 
28
29
  export type IterateCallback = (uischema: UISchemaElement) => void;
29
30