@jsonforms/core 3.4.1 → 3.5.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.
- package/lib/jsonforms-core.cjs.js +57 -16
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +52 -12
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/mappers/renderer.d.ts +12 -1
- package/lib/util/uischema.d.ts +1 -1
- package/lib/util/util.d.ts +1 -1
- package/package.json +2 -2
- package/src/mappers/renderer.ts +87 -12
- package/src/util/resolvers.ts +2 -1
|
@@ -32,6 +32,12 @@ export declare const showAsRequired: (required: boolean, hideRequiredAsterisk: b
|
|
|
32
32
|
* @returns {any}
|
|
33
33
|
*/
|
|
34
34
|
export declare const createDefaultValue: (schema: JsonSchema, rootSchema: JsonSchema) => any;
|
|
35
|
+
/**
|
|
36
|
+
* Create a default value based on the given schema.
|
|
37
|
+
* @param schema the schema for which to create a default value.
|
|
38
|
+
* @returns the default value to use, undefined if none was found
|
|
39
|
+
*/
|
|
40
|
+
export declare const doCreateDefaultValue: (schema: JsonSchema, rootSchema: JsonSchema) => any;
|
|
35
41
|
/**
|
|
36
42
|
* Returns the default value defined in the given schema.
|
|
37
43
|
* @param schema the schema for which to create a default value.
|
|
@@ -310,6 +316,7 @@ export interface ControlWithDetailProps extends StatePropsOfControlWithDetail, D
|
|
|
310
316
|
* State-based props of a table control.
|
|
311
317
|
*/
|
|
312
318
|
export interface StatePropsOfArrayControl extends StatePropsOfControlWithDetail {
|
|
319
|
+
arraySchema: JsonSchema;
|
|
313
320
|
childErrors?: ErrorObject[];
|
|
314
321
|
}
|
|
315
322
|
/**
|
|
@@ -374,7 +381,7 @@ export declare const controlDefaultProps: {
|
|
|
374
381
|
visible: boolean;
|
|
375
382
|
enabled: boolean;
|
|
376
383
|
path: string;
|
|
377
|
-
direction:
|
|
384
|
+
direction: "row" | "column";
|
|
378
385
|
};
|
|
379
386
|
export interface StatePropsOfCombinator extends StatePropsOfControl {
|
|
380
387
|
rootSchema: JsonSchema;
|
|
@@ -398,6 +405,10 @@ export declare const mapStateToAnyOfProps: (state: JsonFormsState, ownProps: Own
|
|
|
398
405
|
export declare const mapStateToOneOfProps: (state: JsonFormsState, ownProps: OwnPropsOfControl) => StatePropsOfCombinator;
|
|
399
406
|
export interface StatePropsOfArrayLayout extends StatePropsOfControlWithDetail {
|
|
400
407
|
data: number;
|
|
408
|
+
arraySchema: JsonSchema;
|
|
409
|
+
/**
|
|
410
|
+
* @deprecated Use `arraySchema.minItems` instead.
|
|
411
|
+
*/
|
|
401
412
|
minItems?: number;
|
|
402
413
|
disableRemove?: boolean;
|
|
403
414
|
disableAdd?: boolean;
|
package/lib/util/uischema.d.ts
CHANGED
|
@@ -16,6 +16,6 @@ export declare const isGroup: (layout: Layout) => layout is GroupLayout;
|
|
|
16
16
|
export declare const isLayout: (uischema: UISchemaElement) => uischema is Layout;
|
|
17
17
|
export declare const isScopable: (obj: unknown) => obj is Scopable;
|
|
18
18
|
export declare const isScoped: (obj: unknown) => obj is Scoped;
|
|
19
|
-
export declare const isLabelable: (obj: unknown) => obj is Labelable
|
|
19
|
+
export declare const isLabelable: (obj: unknown) => obj is Labelable;
|
|
20
20
|
export declare const isLabeled: <T = never>(obj: unknown) => obj is Labeled<T>;
|
|
21
21
|
export declare const isControlElement: (uiSchema: UISchemaElement) => uiSchema is ControlElement;
|
package/lib/util/util.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ import type { JsonSchema, Scoped, UISchemaElement } from '../models';
|
|
|
25
25
|
* // returns '2023-11-09T14:22:54.131Z'
|
|
26
26
|
* convertDateToString(new Date('2023-11-09T14:22:54.131Z'));
|
|
27
27
|
*/
|
|
28
|
-
export declare const convertDateToString: (date: Date, format?:
|
|
28
|
+
export declare const convertDateToString: (date: Date, format?: "date" | "time" | "date-time") => string;
|
|
29
29
|
/**
|
|
30
30
|
* Escape the given string such that it can be used as a class name,
|
|
31
31
|
* i.e. hashes and slashes will be replaced.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsonforms/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0-beta.1",
|
|
4
4
|
"description": "Core module of JSON Forms",
|
|
5
5
|
"repository": "https://github.com/eclipsesource/jsonforms",
|
|
6
6
|
"bugs": "https://github.com/eclipsesource/jsonforms/issues",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"ts-node": "^10.4.0",
|
|
87
87
|
"tslib": "^2.5.0",
|
|
88
88
|
"typedoc": "~0.25.3",
|
|
89
|
-
"typescript": "~5.
|
|
89
|
+
"typescript": "~5.5.0"
|
|
90
90
|
},
|
|
91
91
|
"scripts": {
|
|
92
92
|
"build": "rollup -c rollup.config.js",
|
package/src/mappers/renderer.ts
CHANGED
|
@@ -170,7 +170,25 @@ export const createDefaultValue = (
|
|
|
170
170
|
schema: JsonSchema,
|
|
171
171
|
rootSchema: JsonSchema
|
|
172
172
|
) => {
|
|
173
|
-
const
|
|
173
|
+
const defaultValue = doCreateDefaultValue(schema, rootSchema);
|
|
174
|
+
|
|
175
|
+
// preserve the backward compatibility where it is returning an empty object if we can't determine the default value
|
|
176
|
+
return defaultValue === undefined ? {} : defaultValue;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Create a default value based on the given schema.
|
|
181
|
+
* @param schema the schema for which to create a default value.
|
|
182
|
+
* @returns the default value to use, undefined if none was found
|
|
183
|
+
*/
|
|
184
|
+
export const doCreateDefaultValue = (
|
|
185
|
+
schema: JsonSchema,
|
|
186
|
+
rootSchema: JsonSchema
|
|
187
|
+
) => {
|
|
188
|
+
const resolvedSchema =
|
|
189
|
+
typeof schema.$ref === 'string'
|
|
190
|
+
? Resolve.schema(rootSchema, schema.$ref, rootSchema)
|
|
191
|
+
: schema;
|
|
174
192
|
if (resolvedSchema.default !== undefined) {
|
|
175
193
|
return extractDefaults(resolvedSchema, rootSchema);
|
|
176
194
|
}
|
|
@@ -183,22 +201,56 @@ export const createDefaultValue = (
|
|
|
183
201
|
return convertDateToString(new Date(), resolvedSchema.format);
|
|
184
202
|
}
|
|
185
203
|
return '';
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
hasType(resolvedSchema, 'number')
|
|
189
|
-
) {
|
|
204
|
+
}
|
|
205
|
+
if (hasType(resolvedSchema, 'integer') || hasType(resolvedSchema, 'number')) {
|
|
190
206
|
return 0;
|
|
191
|
-
}
|
|
207
|
+
}
|
|
208
|
+
if (hasType(resolvedSchema, 'boolean')) {
|
|
192
209
|
return false;
|
|
193
|
-
}
|
|
210
|
+
}
|
|
211
|
+
if (hasType(resolvedSchema, 'array')) {
|
|
194
212
|
return [];
|
|
195
|
-
}
|
|
213
|
+
}
|
|
214
|
+
if (hasType(resolvedSchema, 'object')) {
|
|
196
215
|
return extractDefaults(resolvedSchema, rootSchema);
|
|
197
|
-
}
|
|
216
|
+
}
|
|
217
|
+
if (hasType(resolvedSchema, 'null')) {
|
|
198
218
|
return null;
|
|
199
|
-
} else {
|
|
200
|
-
return {};
|
|
201
219
|
}
|
|
220
|
+
|
|
221
|
+
const combinators: CombinatorKeyword[] = ['oneOf', 'anyOf', 'allOf'];
|
|
222
|
+
for (const combinator of combinators) {
|
|
223
|
+
if (schema[combinator] && Array.isArray(schema[combinator])) {
|
|
224
|
+
const combinatorDefault = createDefaultValueForCombinatorSchema(
|
|
225
|
+
schema[combinator],
|
|
226
|
+
rootSchema
|
|
227
|
+
);
|
|
228
|
+
if (combinatorDefault !== undefined) {
|
|
229
|
+
return combinatorDefault;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// no default value found
|
|
235
|
+
return undefined;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const createDefaultValueForCombinatorSchema = (
|
|
239
|
+
combinatorSchemas: JsonSchema[],
|
|
240
|
+
rootSchema: JsonSchema
|
|
241
|
+
): any => {
|
|
242
|
+
if (combinatorSchemas.length > 0) {
|
|
243
|
+
for (const combinatorSchema of combinatorSchemas) {
|
|
244
|
+
const result = doCreateDefaultValue(combinatorSchema, rootSchema);
|
|
245
|
+
if (result !== undefined) {
|
|
246
|
+
// return the first one with type information
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// no default value found
|
|
253
|
+
return undefined;
|
|
202
254
|
};
|
|
203
255
|
|
|
204
256
|
/**
|
|
@@ -214,10 +266,26 @@ export const extractDefaults = (schema: JsonSchema, rootSchema: JsonSchema) => {
|
|
|
214
266
|
const resolvedProperty = property.$ref
|
|
215
267
|
? Resolve.schema(rootSchema, property.$ref, rootSchema)
|
|
216
268
|
: property;
|
|
217
|
-
if (resolvedProperty.default !== undefined) {
|
|
269
|
+
if (resolvedProperty && resolvedProperty.default !== undefined) {
|
|
218
270
|
result[key] = cloneDeep(resolvedProperty.default);
|
|
219
271
|
}
|
|
220
272
|
}
|
|
273
|
+
// there could be more properties in allOf schemas
|
|
274
|
+
if (schema.allOf && Array.isArray(schema.allOf)) {
|
|
275
|
+
schema.allOf.forEach((allOfSchema) => {
|
|
276
|
+
if (allOfSchema && allOfSchema.properties) {
|
|
277
|
+
for (const key in allOfSchema.properties) {
|
|
278
|
+
const property = allOfSchema.properties[key];
|
|
279
|
+
const resolvedProperty = property.$ref
|
|
280
|
+
? Resolve.schema(rootSchema, property.$ref, rootSchema)
|
|
281
|
+
: property;
|
|
282
|
+
if (resolvedProperty && resolvedProperty.default !== undefined) {
|
|
283
|
+
result[key] = cloneDeep(resolvedProperty.default);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
}
|
|
221
289
|
return result;
|
|
222
290
|
}
|
|
223
291
|
return cloneDeep(schema.default);
|
|
@@ -785,6 +853,7 @@ export interface ControlWithDetailProps
|
|
|
785
853
|
*/
|
|
786
854
|
export interface StatePropsOfArrayControl
|
|
787
855
|
extends StatePropsOfControlWithDetail {
|
|
856
|
+
arraySchema: JsonSchema;
|
|
788
857
|
childErrors?: ErrorObject[];
|
|
789
858
|
}
|
|
790
859
|
|
|
@@ -811,6 +880,7 @@ export const mapStateToArrayControlProps = (
|
|
|
811
880
|
path,
|
|
812
881
|
uischema,
|
|
813
882
|
schema: resolvedSchema,
|
|
883
|
+
arraySchema: schema,
|
|
814
884
|
childErrors,
|
|
815
885
|
renderers: ownProps.renderers || getRenderers(state),
|
|
816
886
|
cells: ownProps.cells || getCells(state),
|
|
@@ -1139,6 +1209,10 @@ export const mapStateToOneOfProps = (
|
|
|
1139
1209
|
|
|
1140
1210
|
export interface StatePropsOfArrayLayout extends StatePropsOfControlWithDetail {
|
|
1141
1211
|
data: number;
|
|
1212
|
+
arraySchema: JsonSchema;
|
|
1213
|
+
/**
|
|
1214
|
+
* @deprecated Use `arraySchema.minItems` instead.
|
|
1215
|
+
*/
|
|
1142
1216
|
minItems?: number;
|
|
1143
1217
|
disableRemove?: boolean;
|
|
1144
1218
|
disableAdd?: boolean;
|
|
@@ -1179,6 +1253,7 @@ export const mapStateToArrayLayoutProps = (
|
|
|
1179
1253
|
path,
|
|
1180
1254
|
uischema,
|
|
1181
1255
|
schema: resolvedSchema,
|
|
1256
|
+
arraySchema: schema,
|
|
1182
1257
|
data: props.data ? props.data.length : 0,
|
|
1183
1258
|
errors: allErrors,
|
|
1184
1259
|
minItems: schema.minItems,
|
package/src/util/resolvers.ts
CHANGED
|
@@ -127,7 +127,8 @@ const resolveSchemaWithSegments = (
|
|
|
127
127
|
return undefined;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
|
|
130
|
+
// use typeof because schema can by of any type - check singleSegmentResolveSchema below
|
|
131
|
+
if (typeof schema.$ref === 'string') {
|
|
131
132
|
schema = resolveSchema(rootSchema, schema.$ref, rootSchema);
|
|
132
133
|
}
|
|
133
134
|
|