@jsonforms/core 3.1.0-alpha.1 → 3.1.0-alpha.3

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 (47) hide show
  1. package/README.md +3 -3
  2. package/lib/actions/actions.d.ts +21 -21
  3. package/lib/i18n/arrayTranslations.d.ts +24 -0
  4. package/lib/i18n/i18nUtil.d.ts +3 -0
  5. package/lib/i18n/index.d.ts +1 -0
  6. package/lib/jsonforms-core.cjs.js +436 -262
  7. package/lib/jsonforms-core.cjs.js.map +1 -1
  8. package/lib/jsonforms-core.esm.js +318 -201
  9. package/lib/jsonforms-core.esm.js.map +1 -1
  10. package/lib/util/cell.d.ts +0 -1
  11. package/lib/util/renderer.d.ts +6 -2
  12. package/lib/util/schema.d.ts +5 -0
  13. package/package.json +11 -4
  14. package/src/Helpers.ts +1 -1
  15. package/src/actions/actions.ts +52 -55
  16. package/src/configDefault.ts +1 -1
  17. package/src/generators/Generate.ts +3 -1
  18. package/src/generators/schema.ts +29 -25
  19. package/src/generators/uischema.ts +7 -6
  20. package/src/i18n/arrayTranslations.ts +54 -0
  21. package/src/i18n/i18nTypes.ts +10 -6
  22. package/src/i18n/i18nUtil.ts +64 -14
  23. package/src/i18n/index.ts +1 -0
  24. package/src/models/draft4.ts +33 -33
  25. package/src/models/uischema.ts +17 -6
  26. package/src/reducers/cells.ts +8 -7
  27. package/src/reducers/core.ts +119 -75
  28. package/src/reducers/default-data.ts +7 -7
  29. package/src/reducers/i18n.ts +21 -9
  30. package/src/reducers/reducers.ts +20 -30
  31. package/src/reducers/renderers.ts +7 -7
  32. package/src/reducers/selectors.ts +4 -5
  33. package/src/reducers/uischemas.ts +25 -24
  34. package/src/store.ts +1 -1
  35. package/src/testers/testers.ts +202 -148
  36. package/src/util/cell.ts +24 -26
  37. package/src/util/combinators.ts +5 -3
  38. package/src/util/label.ts +1 -1
  39. package/src/util/path.ts +11 -7
  40. package/src/util/renderer.ts +118 -67
  41. package/src/util/resolvers.ts +15 -13
  42. package/src/util/runtime.ts +2 -2
  43. package/src/util/schema.ts +10 -1
  44. package/src/util/type.ts +5 -3
  45. package/src/util/uischema.ts +9 -9
  46. package/src/util/util.ts +52 -52
  47. package/src/util/validator.ts +1 -1
@@ -24,10 +24,11 @@
24
24
  */
25
25
 
26
26
  import find from 'lodash/find';
27
+ import { JsonSchema } from '../models';
27
28
 
28
29
  export const getFirstPrimitiveProp = (schema: any) => {
29
30
  if (schema.properties) {
30
- return find(Object.keys(schema.properties), propName => {
31
+ return find(Object.keys(schema.properties), (propName) => {
31
32
  const prop = schema.properties[propName];
32
33
  return (
33
34
  prop.type === 'string' ||
@@ -38,3 +39,11 @@ export const getFirstPrimitiveProp = (schema: any) => {
38
39
  }
39
40
  return undefined;
40
41
  };
42
+
43
+ /**
44
+ * Tests whether the schema has an enum based on oneOf.
45
+ */
46
+ export const isOneOfEnumSchema = (schema: JsonSchema) =>
47
+ schema?.hasOwnProperty('oneOf') &&
48
+ schema?.oneOf &&
49
+ (schema.oneOf as JsonSchema[]).every((s) => s.const !== undefined);
package/src/util/type.ts CHANGED
@@ -62,7 +62,9 @@ export interface AnyAction extends Action {
62
62
  * @template A The type of things (actions or otherwise) which may be
63
63
  * dispatched.
64
64
  */
65
- export type Dispatch<A extends Action = AnyAction> = <T extends A>(action: T) => T;
65
+ export type Dispatch<A extends Action = AnyAction> = <T extends A>(
66
+ action: T
67
+ ) => T;
66
68
 
67
69
  // Copied from https://github.com/reduxjs/redux/blob/master/src/types/store.ts
68
70
  /**
@@ -171,7 +173,7 @@ export type Observable<T> = {
171
173
  * emission of values from the observable.
172
174
  */
173
175
  subscribe(observer: Observer<T>): { unsubscribe: Unsubscribe };
174
- [Symbol.observable](): Observable<T>
176
+ [Symbol.observable](): Observable<T>;
175
177
  };
176
178
 
177
179
  // Copied from https://github.com/reduxjs/redux/blob/master/src/types/store.ts
@@ -180,7 +182,7 @@ export type Observable<T> = {
180
182
  * an argument to subscribe.
181
183
  */
182
184
  export type Observer<T> = {
183
- next?(value: T): void
185
+ next?(value: T): void;
184
186
  };
185
187
 
186
188
  // Copied from https://github.com/reduxjs/redux/blob/master/src/types/reducers.ts
@@ -28,14 +28,14 @@ import { isLayout, UISchemaElement } from '../models';
28
28
 
29
29
  export type IterateCallback = (uischema: UISchemaElement) => void;
30
30
 
31
- const setReadonlyPropertyValue = (value: boolean): IterateCallback => (
32
- child: UISchemaElement
33
- ): void => {
34
- if (!child.options) {
35
- child.options = {};
36
- }
37
- child.options.readonly = value;
38
- };
31
+ const setReadonlyPropertyValue =
32
+ (value: boolean): IterateCallback =>
33
+ (child: UISchemaElement): void => {
34
+ if (!child.options) {
35
+ child.options = {};
36
+ }
37
+ child.options.readonly = value;
38
+ };
39
39
  export const setReadonly = (uischema: UISchemaElement): void => {
40
40
  iterateSchema(uischema, setReadonlyPropertyValue(true));
41
41
  };
@@ -50,7 +50,7 @@ export const iterateSchema = (
50
50
  return;
51
51
  }
52
52
  if (isLayout(uischema)) {
53
- uischema.elements.forEach(child => iterateSchema(child, toApply));
53
+ uischema.elements.forEach((child) => iterateSchema(child, toApply));
54
54
  return;
55
55
  }
56
56
  toApply(uischema);
package/src/util/util.ts CHANGED
@@ -41,87 +41,87 @@ import type Ajv from 'ajv';
41
41
  * @returns {string} the escaped string
42
42
  */
43
43
  export const convertToValidClassName = (s: string): string =>
44
- s.replace('#', 'root').replace(new RegExp('/', 'g'), '_');
44
+ s.replace('#', 'root').replace(new RegExp('/', 'g'), '_');
45
45
 
46
46
  export const formatErrorMessage = (errors: string[]) => {
47
- if (errors === undefined || errors === null) {
48
- return '';
49
- }
47
+ if (errors === undefined || errors === null) {
48
+ return '';
49
+ }
50
50
 
51
- return errors.join('\n');
51
+ return errors.join('\n');
52
52
  };
53
53
 
54
54
  export const hasType = (jsonSchema: JsonSchema, expected: string): boolean => {
55
- return includes(deriveTypes(jsonSchema), expected);
55
+ return includes(deriveTypes(jsonSchema), expected);
56
56
  };
57
57
 
58
58
  /**
59
59
  * Derives the type of the jsonSchema element
60
60
  */
61
61
  export const deriveTypes = (jsonSchema: JsonSchema): string[] => {
62
- if (isEmpty(jsonSchema)) {
63
- return [];
64
- }
65
- if (!isEmpty(jsonSchema.type) && typeof jsonSchema.type === 'string') {
66
- return [jsonSchema.type];
67
- }
68
- if (isArray(jsonSchema.type)) {
69
- return jsonSchema.type;
70
- }
71
- if (
72
- !isEmpty(jsonSchema.properties) ||
73
- !isEmpty(jsonSchema.additionalProperties)
74
- ) {
75
- return ['object'];
76
- }
77
- if (!isEmpty(jsonSchema.items)) {
78
- return ['array'];
79
- }
62
+ if (isEmpty(jsonSchema)) {
63
+ return [];
64
+ }
65
+ if (!isEmpty(jsonSchema.type) && typeof jsonSchema.type === 'string') {
66
+ return [jsonSchema.type];
67
+ }
68
+ if (isArray(jsonSchema.type)) {
69
+ return jsonSchema.type;
70
+ }
71
+ if (
72
+ !isEmpty(jsonSchema.properties) ||
73
+ !isEmpty(jsonSchema.additionalProperties)
74
+ ) {
75
+ return ['object'];
76
+ }
77
+ if (!isEmpty(jsonSchema.items)) {
78
+ return ['array'];
79
+ }
80
80
 
81
- if (!isEmpty(jsonSchema.allOf)) {
82
- const allOfType = find(
83
- jsonSchema.allOf,
84
- (schema: JsonSchema) => deriveTypes(schema).length !== 0
85
- );
81
+ if (!isEmpty(jsonSchema.allOf)) {
82
+ const allOfType = find(
83
+ jsonSchema.allOf,
84
+ (schema: JsonSchema) => deriveTypes(schema).length !== 0
85
+ );
86
86
 
87
- if (allOfType) {
88
- return deriveTypes(allOfType);
89
- }
90
- }
91
- // ignore all remaining cases
92
- return [];
87
+ if (allOfType) {
88
+ return deriveTypes(allOfType);
89
+ }
90
+ }
91
+ // ignore all remaining cases
92
+ return [];
93
93
  };
94
94
 
95
95
  /**
96
96
  * Convenience wrapper around resolveData and resolveSchema.
97
97
  */
98
98
  export const Resolve: {
99
- schema(
100
- schema: JsonSchema,
101
- schemaPath: string,
102
- rootSchema: JsonSchema
103
- ): JsonSchema;
104
- data(data: any, path: string): any;
99
+ schema(
100
+ schema: JsonSchema,
101
+ schemaPath: string,
102
+ rootSchema: JsonSchema
103
+ ): JsonSchema;
104
+ data(data: any, path: string): any;
105
105
  } = {
106
- schema: resolveSchema,
107
- data: resolveData
106
+ schema: resolveSchema,
107
+ data: resolveData,
108
108
  };
109
109
 
110
110
  // Paths --
111
111
  const fromScoped = (scopable: Scoped): string =>
112
- toDataPathSegments(scopable.scope).join('.');
112
+ toDataPathSegments(scopable.scope).join('.');
113
113
 
114
114
  export const Paths = {
115
- compose: composePaths,
116
- fromScoped
115
+ compose: composePaths,
116
+ fromScoped,
117
117
  };
118
118
 
119
119
  // Runtime --
120
120
  export const Runtime = {
121
- isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
122
- return isEnabled(uischema, data, undefined, ajv);
123
- },
124
- isVisible(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
125
- return isVisible(uischema, data, undefined, ajv);
126
- }
121
+ isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
122
+ return isEnabled(uischema, data, undefined, ajv);
123
+ },
124
+ isVisible(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
125
+ return isVisible(uischema, data, undefined, ajv);
126
+ },
127
127
  };
@@ -31,7 +31,7 @@ export const createAjv = (options?: Options) => {
31
31
  allErrors: true,
32
32
  verbose: true,
33
33
  strict: false,
34
- ...options
34
+ ...options,
35
35
  });
36
36
  addFormats(ajv);
37
37
  return ajv;