@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
@@ -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,158 +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
- extractSchema,
33
- extractUiSchema,
34
- JsonFormsCore,
35
- subErrorsAt,
36
- ValidationMode
37
- } from './core';
38
- import {
39
- extractDefaultData,
40
- JsonFormsDefaultDataRegistryEntry
41
- } from './default-data';
42
- import { defaultDataReducer } from '../reducers/default-data';
43
- import { JsonFormsRendererRegistryEntry, rendererReducer } from './renderers';
44
- import { JsonFormsState } from '../store';
45
- import {
46
- findMatchingUISchema,
47
- JsonFormsUISchemaRegistryEntry,
48
- uischemaRegistryReducer,
49
- UISchemaTester
50
- } from './uischemas';
51
- import {
52
- fetchLocale,
53
- findLocalizedSchema,
54
- findLocalizedUISchema,
55
- i18nReducer
56
- } from './i18n';
57
25
 
58
- import { Generate } from '../generators';
59
- import { JsonFormsCellRendererRegistryEntry } from './cells';
60
- import { JsonSchema } from '../models/jsonSchema';
61
-
62
- import { cellReducer } from './cells';
63
- import { configReducer } from './config';
64
- import get from 'lodash/get';
65
- import { Ajv } from 'ajv';
66
-
67
- export {
68
- rendererReducer,
69
- cellReducer,
70
- coreReducer,
71
- i18nReducer,
72
- configReducer,
73
- UISchemaTester,
74
- uischemaRegistryReducer,
75
- findMatchingUISchema,
76
- JsonFormsUISchemaRegistryEntry
77
- };
78
- export { JsonFormsCore, ValidationMode };
79
-
80
- export const jsonFormsReducerConfig = {
81
- core: coreReducer,
82
- renderers: rendererReducer,
83
- cells: cellReducer,
84
- config: configReducer,
85
- uischemas: uischemaRegistryReducer,
86
- defaultData: defaultDataReducer,
87
- i18n: i18nReducer
88
- };
89
-
90
- export const getData = (state: JsonFormsState) =>
91
- extractData(get(state, 'jsonforms.core'));
92
- export const getSchema = (state: JsonFormsState): JsonSchema =>
93
- extractSchema(get(state, 'jsonforms.core'));
94
- export const getUiSchema = (state: JsonFormsState): UISchemaElement =>
95
- extractUiSchema(get(state, 'jsonforms.core'));
96
- export const getAjv = (
97
- state: JsonFormsState
98
- ): Ajv => extractAjv(get(state, 'jsonforms.core'));
99
- export const getDefaultData = (
100
- state: JsonFormsState
101
- ): JsonFormsDefaultDataRegistryEntry[] =>
102
- extractDefaultData(get(state, 'jsonforms.defaultData'));
103
- export const getRenderers = (
104
- state: JsonFormsState
105
- ): JsonFormsRendererRegistryEntry[] => get(state, 'jsonforms.renderers');
106
- export const getCells = (
107
- state: JsonFormsState
108
- ): JsonFormsCellRendererRegistryEntry[] => get(state, 'jsonforms.cells');
109
- export const getUISchemas = (
110
- state: JsonFormsState
111
- ): JsonFormsUISchemaRegistryEntry[] => get(state, 'jsonforms.uischemas');
112
-
113
- /**
114
- * Finds a registered UI schema to use, if any.
115
- * @param schema the JSON schema describing the data to be rendered
116
- * @param schemaPath the according schema path
117
- * @param path the instance path
118
- * @param fallbackLayoutType the type of the layout to use
119
- * @param control may be checked for embedded inline uischema options
120
- */
121
- export const findUISchema = (
122
- uischemas: JsonFormsUISchemaRegistryEntry[],
123
- schema: JsonSchema,
124
- schemaPath: string,
125
- path: string,
126
- fallbackLayoutType = 'VerticalLayout',
127
- control?: ControlElement,
128
- rootSchema?: JsonSchema
129
- ): UISchemaElement => {
130
- // handle options
131
- if (control && control.options && control.options.detail) {
132
- if (typeof control.options.detail === 'string') {
133
- if (control.options.detail.toUpperCase() === 'GENERATE') {
134
- // force generation of uischema
135
- return Generate.uiSchema(schema, fallbackLayoutType);
136
- }
137
- } else if (typeof control.options.detail === 'object') {
138
- // check if detail is a valid uischema
139
- if (
140
- control.options.detail.type &&
141
- typeof control.options.detail.type === 'string'
142
- ) {
143
- return control.options.detail as UISchemaElement;
144
- }
145
- }
146
- }
147
- // default
148
- const uiSchema = findMatchingUISchema(uischemas)(schema, schemaPath, path);
149
- if (uiSchema === undefined) {
150
- return Generate.uiSchema(schema, fallbackLayoutType, '#', rootSchema);
151
- }
152
- return uiSchema;
153
- };
154
-
155
- export const getErrorAt = (instancePath: string, schema: JsonSchema) => (
156
- state: JsonFormsState
157
- ) => {
158
- return errorAt(instancePath, schema)(state.jsonforms.core);
159
- };
160
-
161
- export { errorsAt };
162
-
163
- export const getSubErrorsAt = (instancePath: string, schema: JsonSchema) => (
164
- state: JsonFormsState
165
- ) => subErrorsAt(instancePath, schema)(state.jsonforms.core);
166
-
167
- export const getConfig = (state: JsonFormsState) => state.jsonforms.config;
168
-
169
- export const getLocale = (state: JsonFormsState) =>
170
- fetchLocale(get(state, 'jsonforms.i18n'));
171
-
172
- export const getLocalizedSchema = (locale: string) => (
173
- state: JsonFormsState
174
- ): JsonSchema => findLocalizedSchema(locale)(get(state, 'jsonforms.i18n'));
175
-
176
- export const getLocalizedUISchema = (locale: string) => (
177
- state: JsonFormsState
178
- ): UISchemaElement =>
179
- 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';
@@ -0,0 +1,128 @@
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 { ControlElement, UISchemaElement } from '../models';
27
+ import {
28
+ coreReducer,
29
+ errorAt,
30
+ subErrorsAt,
31
+ } from './core';
32
+ import { defaultDataReducer } from './default-data';
33
+ import { rendererReducer } from './renderers';
34
+ import { JsonFormsState } from '../store';
35
+ import type { JsonFormsUISchemaRegistryEntry } from './uischemas';
36
+ import {
37
+ findMatchingUISchema,
38
+ uischemaRegistryReducer,
39
+ } from './uischemas';
40
+ import {
41
+ fetchErrorTranslator,
42
+ fetchLocale,
43
+ i18nReducer,
44
+ } from './i18n';
45
+
46
+ import { Generate } from '../generators';
47
+ import { JsonSchema } from '../models/jsonSchema';
48
+
49
+ import { cellReducer } from './cells';
50
+ import { configReducer } from './config';
51
+ import get from 'lodash/get';
52
+ import { fetchTranslator } from '.';
53
+ import { ErrorTranslator, Translator } from '../i18n';
54
+
55
+ export const jsonFormsReducerConfig = {
56
+ core: coreReducer,
57
+ renderers: rendererReducer,
58
+ cells: cellReducer,
59
+ config: configReducer,
60
+ uischemas: uischemaRegistryReducer,
61
+ defaultData: defaultDataReducer,
62
+ i18n: i18nReducer,
63
+ };
64
+
65
+ /**
66
+ * Finds a registered UI schema to use, if any.
67
+ * @param schema the JSON schema describing the data to be rendered
68
+ * @param schemaPath the according schema path
69
+ * @param path the instance path
70
+ * @param fallbackLayoutType the type of the layout to use
71
+ * @param control may be checked for embedded inline uischema options
72
+ */
73
+ export const findUISchema = (
74
+ uischemas: JsonFormsUISchemaRegistryEntry[],
75
+ schema: JsonSchema,
76
+ schemaPath: string,
77
+ path: string,
78
+ fallbackLayoutType = 'VerticalLayout',
79
+ control?: ControlElement,
80
+ rootSchema?: JsonSchema
81
+ ): UISchemaElement => {
82
+ // handle options
83
+ if (control && control.options && control.options.detail) {
84
+ if (typeof control.options.detail === 'string') {
85
+ if (control.options.detail.toUpperCase() === 'GENERATE') {
86
+ // force generation of uischema
87
+ return Generate.uiSchema(schema, fallbackLayoutType);
88
+ }
89
+ } else if (typeof control.options.detail === 'object') {
90
+ // check if detail is a valid uischema
91
+ if (
92
+ control.options.detail.type &&
93
+ typeof control.options.detail.type === 'string'
94
+ ) {
95
+ return control.options.detail as UISchemaElement;
96
+ }
97
+ }
98
+ }
99
+ // default
100
+ const uiSchema = findMatchingUISchema(uischemas)(schema, schemaPath, path);
101
+ if (uiSchema === undefined) {
102
+ return Generate.uiSchema(schema, fallbackLayoutType, '#', rootSchema);
103
+ }
104
+ return uiSchema;
105
+ };
106
+
107
+ export const getErrorAt = (instancePath: string, schema: JsonSchema) => (
108
+ state: JsonFormsState
109
+ ) => {
110
+ return errorAt(instancePath, schema)(state.jsonforms.core);
111
+ };
112
+
113
+ export const getSubErrorsAt = (instancePath: string, schema: JsonSchema) => (
114
+ state: JsonFormsState
115
+ ) => subErrorsAt(instancePath, schema)(state.jsonforms.core);
116
+
117
+ export const getConfig = (state: JsonFormsState) => state.jsonforms.config;
118
+
119
+ export const getLocale = (state: JsonFormsState) =>
120
+ fetchLocale(get(state, 'jsonforms.i18n'));
121
+
122
+ export const getTranslator = () => (
123
+ state: JsonFormsState
124
+ ): Translator => fetchTranslator(get(state, 'jsonforms.i18n'));
125
+
126
+ export const getErrorTranslator = () => (
127
+ state: JsonFormsState
128
+ ): ErrorTranslator => fetchErrorTranslator(get(state, 'jsonforms.i18n'));
@@ -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 { RankedTester } from '../testers';
26
27
  import {
27
28
  ADD_RENDERER,
@@ -29,7 +30,7 @@ import {
29
30
  REMOVE_RENDERER,
30
31
  RemoveRendererAction
31
32
  } from '../actions';
32
- import { Reducer } from '../util/type';
33
+ import { Reducer } from '../util';
33
34
 
34
35
  export interface JsonFormsRendererRegistryEntry {
35
36
  tester: RankedTester;
@@ -0,0 +1,65 @@
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 get from 'lodash/get';
27
+ import Ajv from 'ajv';
28
+ import { JsonFormsState } from '../store';
29
+ import { JsonSchema, UISchemaElement } from '../models';
30
+ import {
31
+ extractAjv,
32
+ extractData,
33
+ extractSchema,
34
+ extractUiSchema,
35
+ } from './core';
36
+ import {
37
+ extractDefaultData,
38
+ JsonFormsDefaultDataRegistryEntry
39
+ } from './default-data';
40
+ import { JsonFormsRendererRegistryEntry } from './renderers';
41
+ import { JsonFormsCellRendererRegistryEntry } from './cells';
42
+ import { JsonFormsUISchemaRegistryEntry } from './uischemas';
43
+
44
+ export const getData = (state: JsonFormsState) =>
45
+ extractData(get(state, 'jsonforms.core'));
46
+ export const getSchema = (state: JsonFormsState): JsonSchema =>
47
+ extractSchema(get(state, 'jsonforms.core'));
48
+ export const getUiSchema = (state: JsonFormsState): UISchemaElement =>
49
+ extractUiSchema(get(state, 'jsonforms.core'));
50
+ export const getAjv = (
51
+ state: JsonFormsState
52
+ ): Ajv => extractAjv(get(state, 'jsonforms.core'));
53
+ export const getDefaultData = (
54
+ state: JsonFormsState
55
+ ): JsonFormsDefaultDataRegistryEntry[] =>
56
+ extractDefaultData(get(state, 'jsonforms.defaultData'));
57
+ export const getRenderers = (
58
+ state: JsonFormsState
59
+ ): JsonFormsRendererRegistryEntry[] => get(state, 'jsonforms.renderers');
60
+ export const getCells = (
61
+ state: JsonFormsState
62
+ ): JsonFormsCellRendererRegistryEntry[] => get(state, 'jsonforms.cells');
63
+ export const getUISchemas = (
64
+ state: JsonFormsState
65
+ ): JsonFormsUISchemaRegistryEntry[] => get(state, 'jsonforms.uischemas')
@@ -22,11 +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
+
25
26
  import maxBy from 'lodash/maxBy';
26
27
  import remove from 'lodash/remove';
27
28
  import { ADD_UI_SCHEMA, REMOVE_UI_SCHEMA, UISchemaActions } from '../actions';
28
- import { JsonSchema, NOT_APPLICABLE, UISchemaElement } from '..';
29
- import { Reducer } from '../util/type';
29
+ import { NOT_APPLICABLE } from '../testers';
30
+ import { JsonSchema, UISchemaElement } from '../models';
31
+ import { Reducer } from '../util';
30
32
 
31
33
  export type UISchemaTester = (
32
34
  schema: JsonSchema,
package/src/store.ts CHANGED
@@ -22,12 +22,15 @@
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 { Store } from './util';
26
- import { JsonFormsCore } from './reducers/core';
27
- import { JsonFormsCellRendererRegistryEntry } from './reducers/cells';
28
- import { JsonFormsRendererRegistryEntry } from './reducers/renderers';
29
- import { JsonFormsLocaleState } from './reducers/i18n';
30
- import { JsonFormsUISchemaRegistryEntry } from './reducers/uischemas';
27
+ import {
28
+ JsonFormsCore,
29
+ JsonFormsCellRendererRegistryEntry,
30
+ JsonFormsRendererRegistryEntry,
31
+ JsonFormsUISchemaRegistryEntry
32
+ } from './reducers';
33
+ import { JsonFormsI18nState } from './i18n';
31
34
 
32
35
  /**
33
36
  * JSONForms store.
@@ -62,11 +65,11 @@ export interface JsonFormsSubStates {
62
65
  */
63
66
  cells?: JsonFormsCellRendererRegistryEntry[];
64
67
  /**
65
- *
68
+ * I18n settings.
66
69
  */
67
- i18n?: JsonFormsLocaleState;
70
+ i18n?: JsonFormsI18nState;
68
71
  /**
69
- *
72
+ * The UI schema registry used in detail renderers.
70
73
  */
71
74
  uischemas?: JsonFormsUISchemaRegistryEntry[];
72
75
  /**