@jsonforms/core 3.2.1 → 3.3.0-alpha.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.
@@ -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';
@@ -21,6 +21,7 @@ var isArray = require('lodash/isArray');
21
21
  var reduce = require('lodash/reduce');
22
22
  var toPairs = require('lodash/toPairs');
23
23
  var includes = require('lodash/includes');
24
+ var isUndefined = require('lodash/isUndefined');
24
25
  var find = require('lodash/find');
25
26
  var range = require('lodash/range');
26
27
  var has = require('lodash/has');
@@ -48,6 +49,7 @@ var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
48
49
  var reduce__default = /*#__PURE__*/_interopDefaultLegacy(reduce);
49
50
  var toPairs__default = /*#__PURE__*/_interopDefaultLegacy(toPairs);
50
51
  var includes__default = /*#__PURE__*/_interopDefaultLegacy(includes);
52
+ var isUndefined__default = /*#__PURE__*/_interopDefaultLegacy(isUndefined);
51
53
  var find__default = /*#__PURE__*/_interopDefaultLegacy(find);
52
54
  var range__default = /*#__PURE__*/_interopDefaultLegacy(range);
53
55
  var has__default = /*#__PURE__*/_interopDefaultLegacy(has);
@@ -1005,6 +1007,15 @@ var optionIs = function (optionName, optionValue) {
1005
1007
  return !isEmpty__default["default"](options) && options[optionName] === optionValue;
1006
1008
  };
1007
1009
  };
1010
+ var hasOption = function (optionName) {
1011
+ return function (uischema) {
1012
+ if (isEmpty__default["default"](uischema)) {
1013
+ return false;
1014
+ }
1015
+ var options = uischema.options;
1016
+ return !isEmpty__default["default"](options) && !isUndefined__default["default"](options[optionName]);
1017
+ };
1018
+ };
1008
1019
  var scopeEndsWith = function (expected) {
1009
1020
  return function (uischema) {
1010
1021
  if (isEmpty__default["default"](expected) || !isControl(uischema)) {
@@ -1215,6 +1226,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
1215
1226
  formatIs: formatIs,
1216
1227
  uiTypeIs: uiTypeIs,
1217
1228
  optionIs: optionIs,
1229
+ hasOption: hasOption,
1218
1230
  scopeEndsWith: scopeEndsWith,
1219
1231
  scopeEndIs: scopeEndIs,
1220
1232
  and: and,
@@ -1963,7 +1975,7 @@ var mapDispatchToArrayControlProps = function (dispatch) { return ({
1963
1975
  }
1964
1976
  array.push(value);
1965
1977
  return array;
1966
- }));
1978
+ }, { type: 'ADD', values: [value] }));
1967
1979
  }; },
1968
1980
  removeItems: function (path, toDelete) { return function () {
1969
1981
  dispatch(update(path, function (array) {
@@ -1972,18 +1984,24 @@ var mapDispatchToArrayControlProps = function (dispatch) { return ({
1972
1984
  .reverse()
1973
1985
  .forEach(function (s) { return array.splice(s, 1); });
1974
1986
  return array;
1975
- }));
1987
+ }, { type: 'REMOVE', indices: toDelete }));
1976
1988
  }; },
1977
1989
  moveUp: function (path, toMove) { return function () {
1978
1990
  dispatch(update(path, function (array) {
1979
1991
  moveUp(array, toMove);
1980
1992
  return array;
1993
+ }, {
1994
+ type: 'MOVE',
1995
+ moves: [{ from: toMove, to: toMove - 1 }],
1981
1996
  }));
1982
1997
  }; },
1983
1998
  moveDown: function (path, toMove) { return function () {
1984
1999
  dispatch(update(path, function (array) {
1985
2000
  moveDown(array, toMove);
1986
2001
  return array;
2002
+ }, {
2003
+ type: 'MOVE',
2004
+ moves: [{ from: toMove, to: toMove + 1 }],
1987
2005
  }));
1988
2006
  }; },
1989
2007
  }); };
@@ -2412,6 +2430,42 @@ var SET_TRANSLATOR = 'jsonforms/SET_TRANSLATOR';
2412
2430
  var UPDATE_I18N = 'jsonforms/UPDATE_I18N';
2413
2431
  var ADD_DEFAULT_DATA = 'jsonforms/ADD_DEFAULT_DATA';
2414
2432
  var REMOVE_DEFAULT_DATA = 'jsonforms/REMOVE_DEFAULT_DATA';
2433
+ var isUpdateArrayContext = function (context) {
2434
+ if (!('type' in context)) {
2435
+ return false;
2436
+ }
2437
+ if (typeof context.type !== 'string') {
2438
+ return false;
2439
+ }
2440
+ switch (context.type) {
2441
+ case 'ADD': {
2442
+ return ('values' in context &&
2443
+ Array.isArray(context.values) &&
2444
+ context.values.length > 0);
2445
+ }
2446
+ case 'REMOVE': {
2447
+ return ('indices' in context &&
2448
+ Array.isArray(context.indices) &&
2449
+ context.indices.length > 0 &&
2450
+ context.indices.every(function (i) { return typeof i === 'number'; }));
2451
+ }
2452
+ case 'MOVE': {
2453
+ return ('moves' in context &&
2454
+ Array.isArray(context.moves) &&
2455
+ context.moves.length > 0 &&
2456
+ context.moves.every(function (m) {
2457
+ return typeof m === 'object' &&
2458
+ m !== null &&
2459
+ 'from' in m &&
2460
+ 'to' in m &&
2461
+ typeof m.from === 'number' &&
2462
+ typeof m.to === 'number';
2463
+ }));
2464
+ }
2465
+ default:
2466
+ return false;
2467
+ }
2468
+ };
2415
2469
  var init = function (data, schema, uischema, options) {
2416
2470
  if (schema === void 0) { schema = generateJsonSchema(data); }
2417
2471
  return ({
@@ -2442,10 +2496,11 @@ var setAjv = function (ajv) { return ({
2442
2496
  type: SET_AJV,
2443
2497
  ajv: ajv,
2444
2498
  }); };
2445
- var update = function (path, updater) { return ({
2499
+ var update = function (path, updater, context) { return ({
2446
2500
  type: UPDATE_DATA,
2447
2501
  path: path,
2448
2502
  updater: updater,
2503
+ context: context,
2449
2504
  }); };
2450
2505
  var updateErrors = function (errors) { return ({
2451
2506
  type: UPDATE_ERRORS,
@@ -2539,6 +2594,7 @@ var index = /*#__PURE__*/Object.freeze({
2539
2594
  UPDATE_I18N: UPDATE_I18N,
2540
2595
  ADD_DEFAULT_DATA: ADD_DEFAULT_DATA,
2541
2596
  REMOVE_DEFAULT_DATA: REMOVE_DEFAULT_DATA,
2597
+ isUpdateArrayContext: isUpdateArrayContext,
2542
2598
  init: init,
2543
2599
  updateCore: updateCore,
2544
2600
  registerDefaultData: registerDefaultData,
@@ -2678,6 +2734,7 @@ exports.getUISchemas = getUISchemas;
2678
2734
  exports.getUiSchema = getUiSchema;
2679
2735
  exports.hasCategory = hasCategory;
2680
2736
  exports.hasEnableRule = hasEnableRule;
2737
+ exports.hasOption = hasOption;
2681
2738
  exports.hasShowRule = hasShowRule;
2682
2739
  exports.hasType = hasType;
2683
2740
  exports.i18nReducer = i18nReducer;
@@ -2717,6 +2774,7 @@ exports.isScopable = isScopable;
2717
2774
  exports.isScoped = isScoped;
2718
2775
  exports.isStringControl = isStringControl;
2719
2776
  exports.isTimeControl = isTimeControl;
2777
+ exports.isUpdateArrayContext = isUpdateArrayContext;
2720
2778
  exports.isVisible = isVisible;
2721
2779
  exports.iterateSchema = iterateSchema;
2722
2780
  exports.jsonFormsReducerConfig = jsonFormsReducerConfig;