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

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 (228) hide show
  1. package/docs/assets/js/search.json +1 -1
  2. package/docs/globals.html +822 -405
  3. package/docs/index.html +69 -36
  4. package/docs/interfaces/addcellrendereraction.html +3 -3
  5. package/docs/interfaces/addrendereraction.html +3 -3
  6. package/docs/interfaces/adduischemaaction.html +3 -3
  7. package/docs/interfaces/arraycontrolprops.html +21 -21
  8. package/docs/interfaces/arraylayoutprops.html +21 -21
  9. package/docs/interfaces/cellprops.html +14 -14
  10. package/docs/interfaces/combinatorrendererprops.html +13 -13
  11. package/docs/interfaces/controlprops.html +16 -16
  12. package/docs/interfaces/controlstate.html +2 -2
  13. package/docs/interfaces/controlwithdetailprops.html +17 -17
  14. package/docs/interfaces/dispatchcellprops.html +13 -13
  15. package/docs/interfaces/dispatchcellstateprops.html +13 -13
  16. package/docs/interfaces/dispatchpropsofarraycontrol.html +4 -4
  17. package/docs/interfaces/dispatchpropsofcontrol.html +1 -1
  18. package/docs/interfaces/dispatchpropsofmultienumcontrol.html +2 -2
  19. package/docs/interfaces/enumcellprops.html +15 -15
  20. package/docs/interfaces/enumoption.html +2 -2
  21. package/docs/interfaces/initaction.html +6 -6
  22. package/docs/interfaces/initactionoptions.html +3 -3
  23. package/docs/interfaces/jsonformscore.html +7 -7
  24. package/docs/interfaces/{jsonformslocalestate.html → jsonformsi18nstate.html} +20 -20
  25. package/docs/interfaces/jsonformsprops.html +9 -9
  26. package/docs/interfaces/jsonformssubstates.html +11 -1
  27. package/docs/interfaces/layoutprops.html +10 -10
  28. package/docs/interfaces/ownpropsofcell.html +10 -10
  29. package/docs/interfaces/ownpropsofcontrol.html +9 -9
  30. package/docs/interfaces/ownpropsofenum.html +1 -1
  31. package/docs/interfaces/ownpropsofenumcell.html +11 -11
  32. package/docs/interfaces/ownpropsofjsonformsrenderer.html +8 -8
  33. package/docs/interfaces/ownpropsoflayout.html +9 -9
  34. package/docs/interfaces/ownpropsofmasterlistitem.html +6 -6
  35. package/docs/interfaces/ownpropsofrenderer.html +8 -8
  36. package/docs/interfaces/registerdefaultdataaction.html +3 -3
  37. package/docs/interfaces/removecellrendereraction.html +3 -3
  38. package/docs/interfaces/removerendereraction.html +3 -3
  39. package/docs/interfaces/removeuischemaaction.html +2 -2
  40. package/docs/interfaces/rendererprops.html +9 -9
  41. package/docs/interfaces/setajvaction.html +3 -3
  42. package/docs/interfaces/setconfigaction.html +2 -2
  43. package/docs/interfaces/setlocaleaction.html +3 -3
  44. package/docs/interfaces/setschemaaction.html +2 -2
  45. package/docs/interfaces/{setlocalizedschemasaction.html → settranslatoraction.html} +29 -15
  46. package/docs/interfaces/setuischemaaction.html +2 -2
  47. package/docs/interfaces/setvalidationmodeaction.html +2 -2
  48. package/docs/interfaces/statepropsofarraycontrol.html +17 -17
  49. package/docs/interfaces/statepropsofarraylayout.html +17 -17
  50. package/docs/interfaces/statepropsofcell.html +13 -13
  51. package/docs/interfaces/statepropsofcombinator.html +12 -12
  52. package/docs/interfaces/statepropsofcontrol.html +15 -15
  53. package/docs/interfaces/statepropsofcontrolwithdetail.html +16 -16
  54. package/docs/interfaces/statepropsofenumcell.html +14 -14
  55. package/docs/interfaces/statepropsofjsonformsrenderer.html +9 -9
  56. package/docs/interfaces/statepropsoflayout.html +10 -10
  57. package/docs/interfaces/statepropsofmasteritem.html +7 -7
  58. package/docs/interfaces/statepropsofrenderer.html +9 -9
  59. package/docs/interfaces/statepropsofscopedrenderer.html +12 -12
  60. package/docs/interfaces/unregisterdefaultdataaction.html +2 -2
  61. package/docs/interfaces/updateaction.html +3 -3
  62. package/docs/interfaces/updatecoreaction.html +6 -6
  63. package/docs/interfaces/updateerrorsaction.html +2 -2
  64. package/docs/interfaces/{setlocalizeduischemasaction.html → updatei18naction.html} +43 -15
  65. package/docs/interfaces/withclassname.html +1 -1
  66. package/lib/Helpers.d.ts +5 -5
  67. package/lib/actions/actions.d.ts +181 -177
  68. package/lib/actions/index.d.ts +1 -1
  69. package/lib/configDefault.d.ts +6 -6
  70. package/lib/generators/Generate.d.ts +6 -6
  71. package/lib/generators/index.d.ts +3 -3
  72. package/lib/generators/schema.d.ts +8 -8
  73. package/lib/generators/uischema.d.ts +12 -12
  74. package/lib/i18n/i18nTypes.d.ts +15 -0
  75. package/lib/i18n/i18nUtil.d.ts +18 -0
  76. package/lib/i18n/index.d.ts +2 -0
  77. package/lib/index.d.ts +11 -10
  78. package/lib/jsonforms-core.cjs.js +2445 -0
  79. package/lib/jsonforms-core.cjs.js.map +1 -0
  80. package/lib/jsonforms-core.esm.js +2164 -0
  81. package/lib/jsonforms-core.esm.js.map +1 -0
  82. package/lib/models/draft4.d.ts +198 -198
  83. package/lib/models/index.d.ts +5 -5
  84. package/lib/models/jsonSchema.d.ts +3 -3
  85. package/lib/models/jsonSchema4.d.ts +110 -110
  86. package/lib/models/jsonSchema7.d.ts +119 -119
  87. package/lib/models/uischema.d.ts +201 -201
  88. package/lib/reducers/cells.d.ts +11 -11
  89. package/lib/reducers/config.d.ts +3 -3
  90. package/lib/reducers/core.d.ts +24 -23
  91. package/lib/reducers/default-data.d.ts +10 -10
  92. package/lib/reducers/i18n.d.ts +8 -11
  93. package/lib/reducers/index.d.ts +9 -9
  94. package/lib/reducers/reducers.d.ts +29 -36
  95. package/lib/reducers/renderers.d.ts +10 -10
  96. package/lib/reducers/selectors.d.ts +15 -15
  97. package/lib/reducers/uischemas.d.ts +10 -10
  98. package/lib/store.d.ts +53 -52
  99. package/lib/testers/index.d.ts +1 -1
  100. package/lib/testers/testers.d.ts +203 -203
  101. package/lib/util/Formatted.d.ts +19 -19
  102. package/lib/util/array.d.ts +3 -3
  103. package/lib/util/cell.d.ts +79 -79
  104. package/lib/util/combinators.d.ts +10 -10
  105. package/lib/util/ids.d.ts +3 -3
  106. package/lib/util/index.d.ts +15 -15
  107. package/lib/util/label.d.ts +9 -9
  108. package/lib/util/path.d.ts +25 -25
  109. package/lib/util/renderer.d.ts +398 -387
  110. package/lib/util/resolvers.d.ts +25 -25
  111. package/lib/util/runtime.d.ts +18 -19
  112. package/lib/util/schema.d.ts +1 -1
  113. package/lib/util/type.d.ts +174 -174
  114. package/lib/util/uischema.d.ts +5 -5
  115. package/lib/util/util.d.ts +31 -31
  116. package/lib/util/validator.d.ts +3 -2
  117. package/package.json +18 -14
  118. package/rollup.config.js +44 -0
  119. package/src/actions/actions.ts +46 -36
  120. package/src/i18n/i18nTypes.ts +17 -0
  121. package/src/i18n/i18nUtil.ts +105 -0
  122. package/src/i18n/index.ts +2 -0
  123. package/src/index.ts +1 -0
  124. package/src/reducers/core.ts +70 -48
  125. package/src/reducers/i18n.ts +41 -35
  126. package/src/reducers/reducers.ts +10 -29
  127. package/src/reducers/selectors.ts +1 -1
  128. package/src/store.ts +4 -4
  129. package/src/util/cell.ts +26 -6
  130. package/src/util/renderer.ts +127 -38
  131. package/src/util/runtime.ts +1 -1
  132. package/src/util/util.ts +1 -1
  133. package/src/util/validator.ts +5 -9
  134. package/stats.html +3279 -0
  135. package/{lib/reducers/cells.js → test/i18n/i18nUtil.test.ts} +25 -17
  136. package/test/reducers/core.test.ts +31 -44
  137. package/test/util/cell.test.ts +2 -2
  138. package/test/util/renderer.test.ts +488 -35
  139. package/lib/Helpers.js +0 -32
  140. package/lib/Helpers.js.map +0 -1
  141. package/lib/actions/actions.js +0 -149
  142. package/lib/actions/actions.js.map +0 -1
  143. package/lib/actions/index.js +0 -29
  144. package/lib/actions/index.js.map +0 -1
  145. package/lib/configDefault.js +0 -47
  146. package/lib/configDefault.js.map +0 -1
  147. package/lib/generators/Generate.js +0 -34
  148. package/lib/generators/Generate.js.map +0 -1
  149. package/lib/generators/index.js +0 -31
  150. package/lib/generators/index.js.map +0 -1
  151. package/lib/generators/schema.js +0 -152
  152. package/lib/generators/schema.js.map +0 -1
  153. package/lib/generators/uischema.js +0 -166
  154. package/lib/generators/uischema.js.map +0 -1
  155. package/lib/index.js +0 -37
  156. package/lib/index.js.map +0 -1
  157. package/lib/jsonforms-core.js +0 -19
  158. package/lib/jsonforms-core.js.map +0 -1
  159. package/lib/models/draft4.js +0 -173
  160. package/lib/models/draft4.js.map +0 -1
  161. package/lib/models/index.js +0 -30
  162. package/lib/models/index.js.map +0 -1
  163. package/lib/models/jsonSchema.js +0 -27
  164. package/lib/models/jsonSchema.js.map +0 -1
  165. package/lib/models/jsonSchema4.js +0 -30
  166. package/lib/models/jsonSchema4.js.map +0 -1
  167. package/lib/models/jsonSchema7.js +0 -30
  168. package/lib/models/jsonSchema7.js.map +0 -1
  169. package/lib/models/uischema.js +0 -55
  170. package/lib/models/uischema.js.map +0 -1
  171. package/lib/reducers/cells.js.map +0 -1
  172. package/lib/reducers/config.js +0 -44
  173. package/lib/reducers/config.js.map +0 -1
  174. package/lib/reducers/core.js +0 -259
  175. package/lib/reducers/core.js.map +0 -1
  176. package/lib/reducers/default-data.js +0 -42
  177. package/lib/reducers/default-data.js.map +0 -1
  178. package/lib/reducers/i18n.js +0 -65
  179. package/lib/reducers/i18n.js.map +0 -1
  180. package/lib/reducers/index.js +0 -37
  181. package/lib/reducers/index.js.map +0 -1
  182. package/lib/reducers/reducers.js +0 -99
  183. package/lib/reducers/reducers.js.map +0 -1
  184. package/lib/reducers/renderers.js +0 -41
  185. package/lib/reducers/renderers.js.map +0 -1
  186. package/lib/reducers/selectors.js +0 -47
  187. package/lib/reducers/selectors.js.map +0 -1
  188. package/lib/reducers/uischemas.js +0 -57
  189. package/lib/reducers/uischemas.js.map +0 -1
  190. package/lib/store.js +0 -27
  191. package/lib/store.js.map +0 -1
  192. package/lib/testers/index.js +0 -29
  193. package/lib/testers/index.js.map +0 -1
  194. package/lib/testers/testers.js +0 -401
  195. package/lib/testers/testers.js.map +0 -1
  196. package/lib/util/Formatted.js +0 -27
  197. package/lib/util/Formatted.js.map +0 -1
  198. package/lib/util/array.js +0 -43
  199. package/lib/util/array.js.map +0 -1
  200. package/lib/util/cell.js +0 -133
  201. package/lib/util/cell.js.map +0 -1
  202. package/lib/util/combinators.js +0 -56
  203. package/lib/util/combinators.js.map +0 -1
  204. package/lib/util/ids.js +0 -50
  205. package/lib/util/ids.js.map +0 -1
  206. package/lib/util/index.js +0 -41
  207. package/lib/util/index.js.map +0 -1
  208. package/lib/util/label.js +0 -70
  209. package/lib/util/label.js.map +0 -1
  210. package/lib/util/path.js +0 -85
  211. package/lib/util/path.js.map +0 -1
  212. package/lib/util/renderer.js +0 -451
  213. package/lib/util/renderer.js.map +0 -1
  214. package/lib/util/resolvers.js +0 -165
  215. package/lib/util/resolvers.js.map +0 -1
  216. package/lib/util/runtime.js +0 -159
  217. package/lib/util/runtime.js.map +0 -1
  218. package/lib/util/schema.js +0 -40
  219. package/lib/util/schema.js.map +0 -1
  220. package/lib/util/type.js +0 -27
  221. package/lib/util/type.js.map +0 -1
  222. package/lib/util/uischema.js +0 -52
  223. package/lib/util/uischema.js.map +0 -1
  224. package/lib/util/util.js +0 -107
  225. package/lib/util/util.js.map +0 -1
  226. package/lib/util/validator.js +0 -36
  227. package/lib/util/validator.js.map +0 -1
  228. package/webpack.build.js +0 -13
@@ -23,43 +23,25 @@
23
23
  THE SOFTWARE.
24
24
  */
25
25
  import * as _ from 'lodash';
26
- import { init, update, UPDATE_DATA, UpdateAction } from '../../src/actions';
27
26
  import * as Redux from 'redux';
28
- import {
29
- clearAllIds,
30
- computeLabel,
31
- createAjv,
32
- createDefaultValue,
33
- mapDispatchToArrayControlProps,
34
- mapDispatchToControlProps,
35
- mapStateToArrayLayoutProps,
36
- mapStateToControlProps,
37
- mapStateToJsonFormsRendererProps,
38
- mapStateToLayoutProps,
39
- mapStateToOneOfProps,
40
- mapStateToMultiEnumControlProps,
41
- mapDispatchToMultiEnumProps
42
- } from '../../src/util';
43
27
  import configureStore from 'redux-mock-store';
44
28
  import test from 'ava';
45
- import { generateDefaultUISchema } from '../../src/generators';
46
- import {
47
- ControlElement,
48
- CoreActions,
49
- coreReducer,
50
- Dispatch,
51
- JsonFormsCore,
52
- JsonFormsState,
53
- JsonSchema,
54
- JsonSchema7,
55
- mapStateToAnyOfProps,
56
- OwnPropsOfControl,
57
- rankWith,
58
- RuleEffect,
59
- UISchemaElement
60
- } from '../../src';
29
+
61
30
  import { ErrorObject } from 'ajv';
62
- import { setValidationMode } from '../../lib';
31
+ import { JsonFormsState } from '../../src/store';
32
+ import { coreReducer, JsonFormsCore } from '../../src/reducers/core';
33
+ import { Dispatch } from '../../src/util/type';
34
+ import { CoreActions, init, setValidationMode, update, UpdateAction, UPDATE_DATA } from '../../src/actions/actions';
35
+ import { ControlElement, RuleEffect, UISchemaElement } from '../../src/models/uischema';
36
+ import { computeLabel, createDefaultValue, mapDispatchToArrayControlProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAnyOfProps, mapStateToArrayLayoutProps, mapStateToControlProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLayoutProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, OwnPropsOfControl } from '../../src/util/renderer';
37
+ import { clearAllIds } from '../../src/util/ids';
38
+ import { generateDefaultUISchema } from '../../src/generators/uischema';
39
+ import { JsonSchema } from '../../src/models/jsonSchema';
40
+ import { rankWith } from '../../src/testers/testers';
41
+ import { createAjv } from '../../src/util/validator';
42
+ import { JsonSchema7 } from '../../src/models/jsonSchema7';
43
+ import { defaultJsonFormsI18nState } from '../../src/reducers/i18n';
44
+ import { i18nJsonSchema } from '../../src/i18n/i18nTypes';
63
45
 
64
46
  const middlewares: Redux.Middleware[] = [];
65
47
  const mockStore = configureStore<JsonFormsState>(middlewares);
@@ -384,7 +366,7 @@ test('mapStateToControlProps - errors', t => {
384
366
  };
385
367
  const clonedState = _.cloneDeep(createState(coreUISchema));
386
368
  const error: ErrorObject = {
387
- dataPath: 'firstName',
369
+ instancePath: '/firstName',
388
370
  message: 'Duff beer',
389
371
  keyword: 'whatever',
390
372
  schemaPath: '',
@@ -1274,6 +1256,477 @@ test('mapStateToAnyOfProps - const constraint in anyOf schema should return corr
1274
1256
  }
1275
1257
  };
1276
1258
  const props = mapStateToAnyOfProps(state, ownProps);
1277
- console.log(JSON.stringify(props, null, 2));
1278
1259
  t.is(props.indexOfFittingSchema, 2);
1279
1260
  });
1261
+
1262
+ test('mapStateToControlProps - i18n - mapStateToControlProps should not crash without i18n', t => {
1263
+ const ownProps = {
1264
+ uischema: coreUISchema
1265
+ };
1266
+ const state: JsonFormsState = createState(coreUISchema);
1267
+ state.jsonforms.i18n = undefined;
1268
+
1269
+ const props = mapStateToControlProps(state, ownProps);
1270
+ t.is(props.label, 'First Name');
1271
+ });
1272
+
1273
+ test('mapStateToControlProps - i18n - default translation has no effect', t => {
1274
+ const ownProps = {
1275
+ uischema: coreUISchema
1276
+ };
1277
+ const state: JsonFormsState = createState(coreUISchema);
1278
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1279
+
1280
+ const props = mapStateToControlProps(state, ownProps);
1281
+ t.is(props.label, 'First Name');
1282
+ t.is(props.description, undefined);
1283
+ });
1284
+
1285
+ test('mapStateToControlProps - i18n - translation via path key', t => {
1286
+ const ownProps = {
1287
+ uischema: coreUISchema
1288
+ };
1289
+ const state: JsonFormsState = createState(coreUISchema);
1290
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1291
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1292
+ switch(key){
1293
+ case 'firstName.label': return 'my translation';
1294
+ default: return defaultMessage;
1295
+ }
1296
+ }
1297
+
1298
+ const props = mapStateToControlProps(state, ownProps);
1299
+ t.is(props.label, 'my translation');
1300
+ t.is(props.description, undefined);
1301
+ });
1302
+
1303
+ test('mapStateToControlProps - i18n - translation via default message', t => {
1304
+ const ownProps = {
1305
+ uischema: coreUISchema
1306
+ };
1307
+ const state: JsonFormsState = createState(coreUISchema);
1308
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1309
+ state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
1310
+ switch(defaultMessage){
1311
+ case 'First Name': return 'my translation';
1312
+ default: return defaultMessage;
1313
+ }
1314
+ }
1315
+
1316
+ const props = mapStateToControlProps(state, ownProps);
1317
+ t.is(props.label, 'my translation');
1318
+ t.is(props.description, undefined);
1319
+ });
1320
+
1321
+ test('mapStateToControlProps - i18n - translation via JSON Schema i18n key', t => {
1322
+ const ownProps = {
1323
+ uischema: coreUISchema
1324
+ };
1325
+ const state: JsonFormsState = createState(coreUISchema);
1326
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1327
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1328
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1329
+ switch(key){
1330
+ case 'my-key.label': return 'my label';
1331
+ case 'my-key.description': return 'my description';
1332
+ default: return defaultMessage;
1333
+ }
1334
+ }
1335
+
1336
+ const props = mapStateToControlProps(state, ownProps);
1337
+ t.is(props.label, 'my label');
1338
+ t.is(props.description, 'my description');
1339
+ });
1340
+
1341
+ test('mapStateToControlProps - i18n - translation via UI Schema i18n key', t => {
1342
+ const ownProps = {
1343
+ uischema: coreUISchema
1344
+ };
1345
+ const state: JsonFormsState = createState(coreUISchema);
1346
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1347
+ ownProps.uischema = {...ownProps.uischema, options: {i18n: 'my-key'}};
1348
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1349
+ switch(key){
1350
+ case 'my-key.label': return 'my label';
1351
+ case 'my-key.description': return 'my description';
1352
+ default: return defaultMessage;
1353
+ }
1354
+ }
1355
+
1356
+ const props = mapStateToControlProps(state, ownProps);
1357
+ t.is(props.label, 'my label');
1358
+ t.is(props.description, 'my description');
1359
+ });
1360
+
1361
+ test('mapStateToControlProps - i18n errors - should not crash without i18n', t => {
1362
+ const ownProps = {
1363
+ uischema: coreUISchema
1364
+ };
1365
+ const state: JsonFormsState = createState(coreUISchema);
1366
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
1367
+ state.jsonforms.core = coreReducer(
1368
+ state.jsonforms.core,
1369
+ init(
1370
+ state.jsonforms.core.data,
1371
+ state.jsonforms.core.schema,
1372
+ state.jsonforms.core.uischema,
1373
+ createAjv()
1374
+ )
1375
+ );
1376
+ state.jsonforms.i18n = undefined;
1377
+
1378
+ const props = mapStateToControlProps(state, ownProps);
1379
+ t.is(props.errors, 'must match pattern "[0-9]+"');
1380
+ });
1381
+
1382
+ test('mapStateToControlProps - i18n errors - default translation has no effect', t => {
1383
+ const ownProps = {
1384
+ uischema: coreUISchema
1385
+ };
1386
+ const state: JsonFormsState = createState(coreUISchema);
1387
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
1388
+ state.jsonforms.core = coreReducer(
1389
+ state.jsonforms.core,
1390
+ init(
1391
+ state.jsonforms.core.data,
1392
+ state.jsonforms.core.schema,
1393
+ state.jsonforms.core.uischema,
1394
+ createAjv()
1395
+ )
1396
+ );
1397
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1398
+
1399
+ const props = mapStateToControlProps(state, ownProps);
1400
+ t.is(props.errors, 'must match pattern "[0-9]+"');
1401
+ });
1402
+
1403
+ test('mapStateToControlProps - i18n errors - translate via error message key', t => {
1404
+ const ownProps = {
1405
+ uischema: coreUISchema
1406
+ };
1407
+ const state: JsonFormsState = createState(coreUISchema);
1408
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+"
1409
+ state.jsonforms.core = coreReducer(
1410
+ state.jsonforms.core,
1411
+ init(
1412
+ state.jsonforms.core.data,
1413
+ state.jsonforms.core.schema,
1414
+ state.jsonforms.core.uischema,
1415
+ createAjv()
1416
+ )
1417
+ );
1418
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1419
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1420
+ switch(key){
1421
+ case 'must match pattern "[0-9]+"': return 'my error message';
1422
+ default: return defaultMessage;
1423
+ }
1424
+ }
1425
+
1426
+ const props = mapStateToControlProps(state, ownProps);
1427
+ t.is(props.errors, 'my error message');
1428
+ });
1429
+
1430
+ test('mapStateToControlProps - i18n errors - translate via i18 specialized error keyword key', t => {
1431
+ const ownProps = {
1432
+ uischema: coreUISchema
1433
+ };
1434
+ const state: JsonFormsState = createState(coreUISchema);
1435
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1436
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1437
+ state.jsonforms.core = coreReducer(
1438
+ state.jsonforms.core,
1439
+ init(
1440
+ state.jsonforms.core.data,
1441
+ state.jsonforms.core.schema,
1442
+ state.jsonforms.core.uischema,
1443
+ createAjv()
1444
+ )
1445
+ );
1446
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1447
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1448
+ switch(key){
1449
+ case 'my-key.error.pattern': return 'my error message';
1450
+ default: return defaultMessage;
1451
+ }
1452
+ }
1453
+
1454
+ const props = mapStateToControlProps(state, ownProps);
1455
+ t.is(props.errors, 'my error message');
1456
+ });
1457
+
1458
+ test('mapStateToControlProps - i18n errors - translate via i18 general error keyword key', t => {
1459
+ const ownProps = {
1460
+ uischema: coreUISchema
1461
+ };
1462
+ const state: JsonFormsState = createState(coreUISchema);
1463
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1464
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1465
+ state.jsonforms.core = coreReducer(
1466
+ state.jsonforms.core,
1467
+ init(
1468
+ state.jsonforms.core.data,
1469
+ state.jsonforms.core.schema,
1470
+ state.jsonforms.core.uischema,
1471
+ createAjv()
1472
+ )
1473
+ );
1474
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1475
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1476
+ switch(key){
1477
+ case 'error.pattern': return 'my error message';
1478
+ default: return defaultMessage;
1479
+ }
1480
+ }
1481
+
1482
+ const props = mapStateToControlProps(state, ownProps);
1483
+ t.is(props.errors, 'my error message');
1484
+ });
1485
+
1486
+ test('mapStateToControlProps - i18n errors - specialized keyword wins over generic keyword', t => {
1487
+ const ownProps = {
1488
+ uischema: coreUISchema
1489
+ };
1490
+ const state: JsonFormsState = createState(coreUISchema);
1491
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1492
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1493
+ state.jsonforms.core = coreReducer(
1494
+ state.jsonforms.core,
1495
+ init(
1496
+ state.jsonforms.core.data,
1497
+ state.jsonforms.core.schema,
1498
+ state.jsonforms.core.uischema,
1499
+ createAjv()
1500
+ )
1501
+ );
1502
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1503
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1504
+ switch(key){
1505
+ case 'my-key.error.pattern': return 'my key error message';
1506
+ case 'error.pattern': return 'my error message';
1507
+ default: return defaultMessage;
1508
+ }
1509
+ }
1510
+
1511
+ const props = mapStateToControlProps(state, ownProps);
1512
+ t.is(props.errors, 'my key error message');
1513
+ });
1514
+
1515
+ test('mapStateToControlProps - i18n errors - multiple errors customization', t => {
1516
+ const ownProps = {
1517
+ uischema: coreUISchema
1518
+ };
1519
+ const state: JsonFormsState = createState(coreUISchema);
1520
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1521
+ state.jsonforms.core.schema.properties.firstName.maxLength = 2;
1522
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1523
+ state.jsonforms.core = coreReducer(
1524
+ state.jsonforms.core,
1525
+ init(
1526
+ state.jsonforms.core.data,
1527
+ state.jsonforms.core.schema,
1528
+ state.jsonforms.core.uischema,
1529
+ createAjv()
1530
+ )
1531
+ );
1532
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1533
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1534
+ switch(key){
1535
+ case 'error.maxLength': return 'max length message';
1536
+ case 'my-key.error.pattern': return 'my key error message';
1537
+ default: return defaultMessage;
1538
+ }
1539
+ }
1540
+
1541
+ const props = mapStateToControlProps(state, ownProps);
1542
+ t.is(props.errors, 'max length message\nmy key error message');
1543
+ });
1544
+
1545
+ test('mapStateToControlProps - i18n errors - custom keyword wins over all other errors', t => {
1546
+ const ownProps = {
1547
+ uischema: coreUISchema
1548
+ };
1549
+ const state: JsonFormsState = createState(coreUISchema);
1550
+ state.jsonforms.core.schema.properties.firstName.pattern = "[0-9]+";
1551
+ state.jsonforms.core.schema.properties.firstName.maxLength = 2;
1552
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1553
+ state.jsonforms.core = coreReducer(
1554
+ state.jsonforms.core,
1555
+ init(
1556
+ state.jsonforms.core.data,
1557
+ state.jsonforms.core.schema,
1558
+ state.jsonforms.core.uischema,
1559
+ createAjv()
1560
+ )
1561
+ );
1562
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1563
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1564
+ switch(key){
1565
+ case 'my-key.error.custom': return 'this is my error custom error message';
1566
+ case 'my-key.error.pattern': return 'my key error message';
1567
+ case 'error.pattern': return 'my error message';
1568
+ default: return defaultMessage;
1569
+ }
1570
+ }
1571
+
1572
+ const props = mapStateToControlProps(state, ownProps);
1573
+ t.is(props.errors, 'this is my error custom error message');
1574
+ });
1575
+
1576
+ test('mapStateToEnumControlProps - i18n - should not crash without i18n', t => {
1577
+ const ownProps = {
1578
+ uischema: coreUISchema
1579
+ };
1580
+ const state: JsonFormsState = createState(coreUISchema);
1581
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1582
+ state.jsonforms.i18n = undefined;
1583
+
1584
+ const props = mapStateToEnumControlProps(state, ownProps);
1585
+ t.is(props.options[0].label, 'a');
1586
+ });
1587
+
1588
+ test('mapStateToEnumControlProps - i18n - default translation has no effect', t => {
1589
+ const ownProps = {
1590
+ uischema: coreUISchema
1591
+ };
1592
+ const state: JsonFormsState = createState(coreUISchema);
1593
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1594
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1595
+
1596
+ const props = mapStateToEnumControlProps(state, ownProps);
1597
+ t.is(props.options[0].label, 'a');
1598
+ });
1599
+
1600
+ test('mapStateToEnumControlProps - i18n - path label translation', t => {
1601
+ const ownProps = {
1602
+ uischema: coreUISchema
1603
+ };
1604
+ const state: JsonFormsState = createState(coreUISchema);
1605
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1606
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1607
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1608
+ switch(key){
1609
+ case 'firstName.a': return 'my message';
1610
+ default: return defaultMessage;
1611
+ }
1612
+ }
1613
+
1614
+ const props = mapStateToEnumControlProps(state, ownProps);
1615
+ t.is(props.options[0].label, 'my message');
1616
+ });
1617
+
1618
+ test('mapStateToEnumControlProps - i18n - defaultMessage translation', t => {
1619
+ const ownProps = {
1620
+ uischema: coreUISchema
1621
+ };
1622
+ const state: JsonFormsState = createState(coreUISchema);
1623
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1624
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1625
+ state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
1626
+ switch(defaultMessage){
1627
+ case 'a': return 'my message';
1628
+ default: return defaultMessage;
1629
+ }
1630
+ }
1631
+
1632
+ const props = mapStateToEnumControlProps(state, ownProps);
1633
+ t.is(props.options[0].label, 'my message');
1634
+ });
1635
+
1636
+ test('mapStateToEnumControlProps - i18n - i18n key translation', t => {
1637
+ const ownProps = {
1638
+ uischema: coreUISchema
1639
+ };
1640
+ const state: JsonFormsState = createState(coreUISchema);
1641
+ state.jsonforms.core.schema.properties.firstName.enum = ['a', 'b'];
1642
+ (state.jsonforms.core.schema.properties.firstName as i18nJsonSchema).i18n = 'my-key';
1643
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1644
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1645
+ switch(key){
1646
+ case 'my-key.a': return 'my message';
1647
+ default: return defaultMessage;
1648
+ }
1649
+ }
1650
+
1651
+ const props = mapStateToEnumControlProps(state, ownProps);
1652
+ t.is(props.options[0].label, 'my message');
1653
+ });
1654
+
1655
+ test('mapStateToOneOfEnumControlProps - i18n - should not crash without i18n', t => {
1656
+ const ownProps = {
1657
+ uischema: coreUISchema
1658
+ };
1659
+ const state: JsonFormsState = createState(coreUISchema);
1660
+ state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
1661
+ state.jsonforms.i18n = undefined;
1662
+
1663
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1664
+ t.is(props.options[0].label, 'foo');
1665
+ });
1666
+
1667
+ test('mapStateToOneOfEnumControlProps- i18n - default translation has no effect', t => {
1668
+ const ownProps = {
1669
+ uischema: coreUISchema
1670
+ };
1671
+ const state: JsonFormsState = createState(coreUISchema);
1672
+ state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
1673
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1674
+
1675
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1676
+ t.is(props.options[0].label, 'foo');
1677
+ });
1678
+
1679
+ test('mapStateToOneOfEnumControlProps - i18n - path label translation', t => {
1680
+ const ownProps = {
1681
+ uischema: coreUISchema
1682
+ };
1683
+ const state: JsonFormsState = createState(coreUISchema);
1684
+ state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
1685
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1686
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1687
+ switch(key){
1688
+ case 'firstName.foo': return 'my message';
1689
+ default: return defaultMessage;
1690
+ }
1691
+ }
1692
+
1693
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1694
+ t.is(props.options[0].label, 'my message');
1695
+ });
1696
+
1697
+ test('mapStateToOneOfEnumControlProps - i18n - default message translation', t => {
1698
+ const ownProps = {
1699
+ uischema: coreUISchema
1700
+ };
1701
+ const state: JsonFormsState = createState(coreUISchema);
1702
+ state.jsonforms.core.schema.properties.firstName.oneOf = [{const: 'a', title: 'foo'}, {const: 'b', title: 'bar'}]
1703
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1704
+ state.jsonforms.i18n.translate = (_key: string, defaultMessage: string | undefined) => {
1705
+ switch(defaultMessage){
1706
+ case 'foo': return 'my message';
1707
+ default: return defaultMessage;
1708
+ }
1709
+ }
1710
+
1711
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1712
+ t.is(props.options[0].label, 'my message');
1713
+ });
1714
+
1715
+ test('mapStateToOneOfEnumControlProps - i18n - i18n key translation', t => {
1716
+ const ownProps = {
1717
+ uischema: coreUISchema
1718
+ };
1719
+ const state: JsonFormsState = createState(coreUISchema);
1720
+ (state.jsonforms.core.schema.properties.firstName.oneOf as any) =
1721
+ [{const: 'a', title: 'foo', i18n: 'my-foo'}, {const: 'b', title: 'bar', i18n:'my-bar'}];
1722
+ state.jsonforms.i18n = defaultJsonFormsI18nState;
1723
+ state.jsonforms.i18n.translate = (key: string, defaultMessage: string | undefined) => {
1724
+ switch(key){
1725
+ case 'my-foo': return 'my message';
1726
+ default: return defaultMessage;
1727
+ }
1728
+ }
1729
+
1730
+ const props = mapStateToOneOfEnumControlProps(state, ownProps);
1731
+ t.is(props.options[0].label, 'my message');
1732
+ });
package/lib/Helpers.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- /*
3
- The MIT License
4
-
5
- Copyright (c) 2017-2019 EclipseSource Munich
6
- https://github.com/eclipsesource/jsonforms
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining a copy
9
- of this software and associated documentation files (the "Software"), to deal
10
- in the Software without restriction, including without limitation the rights
11
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- copies of the Software, and to permit persons to whom the Software is
13
- furnished to do so, subject to the following conditions:
14
-
15
- The above copyright notice and this permission notice shall be included in
16
- all copies or substantial portions of the Software.
17
-
18
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
- THE SOFTWARE.
25
- */
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- var util_1 = require("./util");
28
- exports.Helpers = {
29
- createLabelDescriptionFrom: util_1.createLabelDescriptionFrom,
30
- convertToValidClassName: util_1.convertToValidClassName
31
- };
32
- //# sourceMappingURL=Helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Helpers.js","sourceRoot":"","sources":["../src/Helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;EAuBE;;AAEF,+BAA6E;AAGhE,QAAA,OAAO,GAMhB;IACF,0BAA0B,mCAAA;IAC1B,uBAAuB,gCAAA;CACxB,CAAC"}