@jsonforms/core 3.3.0-alpha.0 → 3.3.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.
@@ -25,11 +25,26 @@ export declare const SET_TRANSLATOR: "jsonforms/SET_TRANSLATOR";
25
25
  export declare const UPDATE_I18N: "jsonforms/UPDATE_I18N";
26
26
  export declare const ADD_DEFAULT_DATA: "jsonforms/ADD_DEFAULT_DATA";
27
27
  export declare const REMOVE_DEFAULT_DATA: "jsonforms/REMOVE_DEFAULT_DATA";
28
+ export type UpdateArrayContext = {
29
+ type: 'ADD';
30
+ values: any[];
31
+ } | {
32
+ type: 'REMOVE';
33
+ indices: number[];
34
+ } | {
35
+ type: 'MOVE';
36
+ moves: {
37
+ from: number;
38
+ to: number;
39
+ }[];
40
+ };
41
+ export declare const isUpdateArrayContext: (context: object) => context is UpdateArrayContext;
28
42
  export type CoreActions = InitAction | UpdateCoreAction | UpdateAction | UpdateErrorsAction | SetAjvAction | SetSchemaAction | SetUISchemaAction | SetValidationModeAction;
29
43
  export interface UpdateAction {
30
44
  type: 'jsonforms/UPDATE';
31
45
  path: string;
32
46
  updater(existingData?: any): any;
47
+ context?: object;
33
48
  }
34
49
  export interface UpdateErrorsAction {
35
50
  type: 'jsonforms/UPDATE_ERRORS';
@@ -92,7 +107,7 @@ export declare const setAjv: (ajv: AJV) => {
92
107
  type: "jsonforms/SET_AJV";
93
108
  ajv: AJV;
94
109
  };
95
- export declare const update: (path: string, updater: (existingData: any) => any) => UpdateAction;
110
+ export declare const update: (path: string, updater: (existingData: any) => any, context?: object) => UpdateAction;
96
111
  export declare const updateErrors: (errors: ErrorObject[]) => UpdateErrorsAction;
97
112
  export interface AddRendererAction {
98
113
  type: 'jsonforms/ADD_RENDERER';
@@ -356,6 +356,7 @@ var isLabelable = function (obj) {
356
356
  var isLabeled = function (obj) {
357
357
  return isLabelable(obj) && ['string', 'boolean'].includes(typeof obj.label);
358
358
  };
359
+ var isControlElement = function (uiSchema) { return uiSchema.type === 'Control'; };
359
360
 
360
361
  var move = function (array, index, delta) {
361
362
  var newIndex = index + delta;
@@ -1079,11 +1080,7 @@ var isAnyOfControl = and(uiTypeIs('Control'), schemaMatches(function (schema) {
1079
1080
  var isOneOfControl = and(uiTypeIs('Control'), schemaMatches(function (schema) {
1080
1081
  return Object.prototype.hasOwnProperty.call(schema, 'oneOf');
1081
1082
  }));
1082
- var isEnumControl = and(uiTypeIs('Control'), or(schemaMatches(function (schema) {
1083
- return Object.prototype.hasOwnProperty.call(schema, 'enum');
1084
- }), schemaMatches(function (schema) {
1085
- return Object.prototype.hasOwnProperty.call(schema, 'const');
1086
- })));
1083
+ var isEnumControl = and(uiTypeIs('Control'), schemaMatches(function (schema) { return isEnumSchema(schema); }));
1087
1084
  var isOneOfEnumControl = and(uiTypeIs('Control'), schemaMatches(function (schema) { return isOneOfEnumSchema(schema); }));
1088
1085
  var isIntegerControl = and(uiTypeIs('Control'), schemaTypeIs('integer'));
1089
1086
  var isNumberControl = and(uiTypeIs('Control'), schemaTypeIs('number'));
@@ -1708,6 +1705,81 @@ var Runtime = {
1708
1705
  },
1709
1706
  };
1710
1707
 
1708
+ var getFirstPrimitiveProp = function (schema) {
1709
+ if (schema.properties) {
1710
+ return find__default["default"](Object.keys(schema.properties), function (propName) {
1711
+ var prop = schema.properties[propName];
1712
+ return (prop.type === 'string' ||
1713
+ prop.type === 'number' ||
1714
+ prop.type === 'integer');
1715
+ });
1716
+ }
1717
+ return undefined;
1718
+ };
1719
+ var isOneOfEnumSchema = function (schema) {
1720
+ return !!schema &&
1721
+ Object.prototype.hasOwnProperty.call(schema, 'oneOf') &&
1722
+ schema.oneOf &&
1723
+ schema.oneOf.every(function (s) { return s.const !== undefined; });
1724
+ };
1725
+ var isEnumSchema = function (schema) {
1726
+ return !!schema &&
1727
+ typeof schema === 'object' &&
1728
+ (Object.prototype.hasOwnProperty.call(schema, 'enum') ||
1729
+ Object.prototype.hasOwnProperty.call(schema, 'const'));
1730
+ };
1731
+
1732
+ var setReadonlyPropertyValue = function (value) {
1733
+ return function (child) {
1734
+ if (!child.options) {
1735
+ child.options = {};
1736
+ }
1737
+ child.options.readonly = value;
1738
+ };
1739
+ };
1740
+ var setReadonly = function (uischema) {
1741
+ iterateSchema(uischema, setReadonlyPropertyValue(true));
1742
+ };
1743
+ var unsetReadonly = function (uischema) {
1744
+ iterateSchema(uischema, setReadonlyPropertyValue(false));
1745
+ };
1746
+ var iterateSchema = function (uischema, toApply) {
1747
+ if (isEmpty__default["default"](uischema)) {
1748
+ return;
1749
+ }
1750
+ if (isLayout(uischema)) {
1751
+ uischema.elements.forEach(function (child) { return iterateSchema(child, toApply); });
1752
+ return;
1753
+ }
1754
+ toApply(uischema);
1755
+ };
1756
+ var getPropPath = function (path) {
1757
+ return "/properties/".concat(path
1758
+ .split('.')
1759
+ .map(function (p) { return encode(p); })
1760
+ .join('/properties/'));
1761
+ };
1762
+ var findUiControl = function (uiSchema, path) {
1763
+ var _a;
1764
+ if (isControlElement(uiSchema)) {
1765
+ if (isScoped(uiSchema) && uiSchema.scope.endsWith(getPropPath(path))) {
1766
+ return uiSchema;
1767
+ }
1768
+ else if ((_a = uiSchema.options) === null || _a === void 0 ? void 0 : _a.detail) {
1769
+ return findUiControl(uiSchema.options.detail, path);
1770
+ }
1771
+ }
1772
+ if (isLayout(uiSchema)) {
1773
+ for (var _i = 0, _b = uiSchema.elements; _i < _b.length; _i++) {
1774
+ var elem = _b[_i];
1775
+ var result = findUiControl(elem, path);
1776
+ if (result !== undefined)
1777
+ return result;
1778
+ }
1779
+ }
1780
+ return undefined;
1781
+ };
1782
+
1711
1783
  var deriveLabel = function (controlElement, schemaElement) {
1712
1784
  if (schemaElement && typeof schemaElement.title === 'string') {
1713
1785
  return schemaElement.title;
@@ -1743,6 +1815,34 @@ var labelDescription = function (text, show) { return ({
1743
1815
  text: text,
1744
1816
  show: show,
1745
1817
  }); };
1818
+ var computeChildLabel = function (data, childPath, childLabelProp, schema, rootSchema, translateFct, uiSchema) {
1819
+ var childData = Resolve.data(data, childPath);
1820
+ if (!childLabelProp) {
1821
+ childLabelProp = getFirstPrimitiveProp(schema);
1822
+ }
1823
+ if (!childLabelProp) {
1824
+ return '';
1825
+ }
1826
+ var currentValue = get__default["default"](childData, childLabelProp);
1827
+ if (currentValue === undefined) {
1828
+ return '';
1829
+ }
1830
+ var childSchema = Resolve.schema(schema, '#' + getPropPath(childLabelProp), rootSchema);
1831
+ var enumOption = undefined;
1832
+ if (isEnumSchema(childSchema)) {
1833
+ enumOption = enumToEnumOptionMapper(currentValue, translateFct, getI18nKeyPrefix(childSchema, findUiControl(uiSchema, childLabelProp), childPath + '.' + childLabelProp));
1834
+ }
1835
+ else if (isOneOfEnumSchema(childSchema)) {
1836
+ var oneOfArray = childSchema.oneOf;
1837
+ var oneOfSchema = oneOfArray.find(function (e) {
1838
+ return isEqual__default["default"](e.const, currentValue);
1839
+ });
1840
+ if (oneOfSchema) {
1841
+ enumOption = oneOfToEnumOptionMapper(oneOfSchema, translateFct, getI18nKeyPrefix(oneOfSchema, undefined, childPath + '.' + childLabelProp));
1842
+ }
1843
+ }
1844
+ return enumOption ? enumOption.label : currentValue;
1845
+ };
1746
1846
 
1747
1847
  var isRequired = function (schema, schemaPath, rootSchema) {
1748
1848
  var pathSegments = schemaPath.split('/');
@@ -1942,18 +2042,9 @@ var mapStateToMultiEnumControlProps = function (state, ownProps) {
1942
2042
  return __assign(__assign({}, props), { options: options });
1943
2043
  };
1944
2044
  var mapStateToMasterListItemProps = function (state, ownProps) {
1945
- var schema = ownProps.schema, path = ownProps.path, index = ownProps.index;
1946
- var firstPrimitiveProp = schema.properties
1947
- ? find__default["default"](Object.keys(schema.properties), function (propName) {
1948
- var prop = schema.properties[propName];
1949
- return (prop.type === 'string' ||
1950
- prop.type === 'number' ||
1951
- prop.type === 'integer');
1952
- })
1953
- : undefined;
2045
+ var schema = ownProps.schema, path = ownProps.path, uischema = ownProps.uischema, childLabelProp = ownProps.childLabelProp, index = ownProps.index;
1954
2046
  var childPath = compose(path, "".concat(index));
1955
- var childData = Resolve.data(getData(state), childPath);
1956
- var childLabel = firstPrimitiveProp ? childData[firstPrimitiveProp] : '';
2047
+ var childLabel = computeChildLabel(getData(state), childPath, childLabelProp, schema, getSchema(state), state.jsonforms.i18n.translate, uischema);
1957
2048
  return __assign(__assign({}, ownProps), { childLabel: childLabel });
1958
2049
  };
1959
2050
  var mapStateToControlWithDetailProps = function (state, ownProps) {
@@ -1975,7 +2066,7 @@ var mapDispatchToArrayControlProps = function (dispatch) { return ({
1975
2066
  }
1976
2067
  array.push(value);
1977
2068
  return array;
1978
- }));
2069
+ }, { type: 'ADD', values: [value] }));
1979
2070
  }; },
1980
2071
  removeItems: function (path, toDelete) { return function () {
1981
2072
  dispatch(update(path, function (array) {
@@ -1984,18 +2075,24 @@ var mapDispatchToArrayControlProps = function (dispatch) { return ({
1984
2075
  .reverse()
1985
2076
  .forEach(function (s) { return array.splice(s, 1); });
1986
2077
  return array;
1987
- }));
2078
+ }, { type: 'REMOVE', indices: toDelete }));
1988
2079
  }; },
1989
2080
  moveUp: function (path, toMove) { return function () {
1990
2081
  dispatch(update(path, function (array) {
1991
2082
  moveUp(array, toMove);
1992
2083
  return array;
2084
+ }, {
2085
+ type: 'MOVE',
2086
+ moves: [{ from: toMove, to: toMove - 1 }],
1993
2087
  }));
1994
2088
  }; },
1995
2089
  moveDown: function (path, toMove) { return function () {
1996
2090
  dispatch(update(path, function (array) {
1997
2091
  moveDown(array, toMove);
1998
2092
  return array;
2093
+ }, {
2094
+ type: 'MOVE',
2095
+ moves: [{ from: toMove, to: toMove + 1 }],
1999
2096
  }));
2000
2097
  }; },
2001
2098
  }); };
@@ -2247,49 +2344,6 @@ var createId = function (proposedId) {
2247
2344
  var removeId = function (id) { return usedIds.delete(id); };
2248
2345
  var clearAllIds = function () { return usedIds.clear(); };
2249
2346
 
2250
- var getFirstPrimitiveProp = function (schema) {
2251
- if (schema.properties) {
2252
- return find__default["default"](Object.keys(schema.properties), function (propName) {
2253
- var prop = schema.properties[propName];
2254
- return (prop.type === 'string' ||
2255
- prop.type === 'number' ||
2256
- prop.type === 'integer');
2257
- });
2258
- }
2259
- return undefined;
2260
- };
2261
- var isOneOfEnumSchema = function (schema) {
2262
- return !!schema &&
2263
- Object.prototype.hasOwnProperty.call(schema, 'oneOf') &&
2264
- schema.oneOf &&
2265
- schema.oneOf.every(function (s) { return s.const !== undefined; });
2266
- };
2267
-
2268
- var setReadonlyPropertyValue = function (value) {
2269
- return function (child) {
2270
- if (!child.options) {
2271
- child.options = {};
2272
- }
2273
- child.options.readonly = value;
2274
- };
2275
- };
2276
- var setReadonly = function (uischema) {
2277
- iterateSchema(uischema, setReadonlyPropertyValue(true));
2278
- };
2279
- var unsetReadonly = function (uischema) {
2280
- iterateSchema(uischema, setReadonlyPropertyValue(false));
2281
- };
2282
- var iterateSchema = function (uischema, toApply) {
2283
- if (isEmpty__default["default"](uischema)) {
2284
- return;
2285
- }
2286
- if (isLayout(uischema)) {
2287
- uischema.elements.forEach(function (child) { return iterateSchema(child, toApply); });
2288
- return;
2289
- }
2290
- toApply(uischema);
2291
- };
2292
-
2293
2347
  var createAjv = function (options) {
2294
2348
  var ajv = new Ajv__default["default"](__assign({ allErrors: true, verbose: true, strict: false, addUsedSchema: false }, options));
2295
2349
  addFormats__default["default"](ajv);
@@ -2424,6 +2478,42 @@ var SET_TRANSLATOR = 'jsonforms/SET_TRANSLATOR';
2424
2478
  var UPDATE_I18N = 'jsonforms/UPDATE_I18N';
2425
2479
  var ADD_DEFAULT_DATA = 'jsonforms/ADD_DEFAULT_DATA';
2426
2480
  var REMOVE_DEFAULT_DATA = 'jsonforms/REMOVE_DEFAULT_DATA';
2481
+ var isUpdateArrayContext = function (context) {
2482
+ if (!('type' in context)) {
2483
+ return false;
2484
+ }
2485
+ if (typeof context.type !== 'string') {
2486
+ return false;
2487
+ }
2488
+ switch (context.type) {
2489
+ case 'ADD': {
2490
+ return ('values' in context &&
2491
+ Array.isArray(context.values) &&
2492
+ context.values.length > 0);
2493
+ }
2494
+ case 'REMOVE': {
2495
+ return ('indices' in context &&
2496
+ Array.isArray(context.indices) &&
2497
+ context.indices.length > 0 &&
2498
+ context.indices.every(function (i) { return typeof i === 'number'; }));
2499
+ }
2500
+ case 'MOVE': {
2501
+ return ('moves' in context &&
2502
+ Array.isArray(context.moves) &&
2503
+ context.moves.length > 0 &&
2504
+ context.moves.every(function (m) {
2505
+ return typeof m === 'object' &&
2506
+ m !== null &&
2507
+ 'from' in m &&
2508
+ 'to' in m &&
2509
+ typeof m.from === 'number' &&
2510
+ typeof m.to === 'number';
2511
+ }));
2512
+ }
2513
+ default:
2514
+ return false;
2515
+ }
2516
+ };
2427
2517
  var init = function (data, schema, uischema, options) {
2428
2518
  if (schema === void 0) { schema = generateJsonSchema(data); }
2429
2519
  return ({
@@ -2454,10 +2544,11 @@ var setAjv = function (ajv) { return ({
2454
2544
  type: SET_AJV,
2455
2545
  ajv: ajv,
2456
2546
  }); };
2457
- var update = function (path, updater) { return ({
2547
+ var update = function (path, updater, context) { return ({
2458
2548
  type: UPDATE_DATA,
2459
2549
  path: path,
2460
2550
  updater: updater,
2551
+ context: context,
2461
2552
  }); };
2462
2553
  var updateErrors = function (errors) { return ({
2463
2554
  type: UPDATE_ERRORS,
@@ -2551,6 +2642,7 @@ var index = /*#__PURE__*/Object.freeze({
2551
2642
  UPDATE_I18N: UPDATE_I18N,
2552
2643
  ADD_DEFAULT_DATA: ADD_DEFAULT_DATA,
2553
2644
  REMOVE_DEFAULT_DATA: REMOVE_DEFAULT_DATA,
2645
+ isUpdateArrayContext: isUpdateArrayContext,
2554
2646
  init: init,
2555
2647
  updateCore: updateCore,
2556
2648
  registerDefaultData: registerDefaultData,
@@ -2618,6 +2710,7 @@ exports.combinatorDefaultTranslations = combinatorDefaultTranslations;
2618
2710
  exports.compose = compose;
2619
2711
  exports.composePaths = compose;
2620
2712
  exports.composeWithUi = composeWithUi;
2713
+ exports.computeChildLabel = computeChildLabel;
2621
2714
  exports.computeLabel = computeLabel;
2622
2715
  exports.configReducer = configReducer;
2623
2716
  exports.controlDefaultProps = controlDefaultProps;
@@ -2662,6 +2755,7 @@ exports.fetchTranslator = fetchTranslator;
2662
2755
  exports.findAllRefs = findAllRefs;
2663
2756
  exports.findMatchingUISchema = findMatchingUISchema;
2664
2757
  exports.findUISchema = findUISchema;
2758
+ exports.findUiControl = findUiControl;
2665
2759
  exports.formatErrorMessage = formatErrorMessage;
2666
2760
  exports.formatIs = formatIs;
2667
2761
  exports.generateDefaultUISchema = generateDefaultUISchema;
@@ -2682,6 +2776,7 @@ exports.getI18nKey = getI18nKey;
2682
2776
  exports.getI18nKeyPrefix = getI18nKeyPrefix;
2683
2777
  exports.getI18nKeyPrefixBySchema = getI18nKeyPrefixBySchema;
2684
2778
  exports.getLocale = getLocale;
2779
+ exports.getPropPath = getPropPath;
2685
2780
  exports.getRenderers = getRenderers;
2686
2781
  exports.getSchema = getSchema;
2687
2782
  exports.getSubErrorsAt = getSubErrorsAt;
@@ -2702,11 +2797,13 @@ exports.isBooleanControl = isBooleanControl;
2702
2797
  exports.isCategorization = isCategorization;
2703
2798
  exports.isCategory = isCategory;
2704
2799
  exports.isControl = isControl;
2800
+ exports.isControlElement = isControlElement;
2705
2801
  exports.isDateControl = isDateControl;
2706
2802
  exports.isDateTimeControl = isDateTimeControl;
2707
2803
  exports.isDescriptionHidden = isDescriptionHidden;
2708
2804
  exports.isEnabled = isEnabled;
2709
2805
  exports.isEnumControl = isEnumControl;
2806
+ exports.isEnumSchema = isEnumSchema;
2710
2807
  exports.isGroup = isGroup;
2711
2808
  exports.isInherentlyEnabled = isInherentlyEnabled;
2712
2809
  exports.isIntegerControl = isIntegerControl;
@@ -2730,6 +2827,7 @@ exports.isScopable = isScopable;
2730
2827
  exports.isScoped = isScoped;
2731
2828
  exports.isStringControl = isStringControl;
2732
2829
  exports.isTimeControl = isTimeControl;
2830
+ exports.isUpdateArrayContext = isUpdateArrayContext;
2733
2831
  exports.isVisible = isVisible;
2734
2832
  exports.iterateSchema = iterateSchema;
2735
2833
  exports.jsonFormsReducerConfig = jsonFormsReducerConfig;