@jsonforms/core 3.2.0-beta.0 → 3.2.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,7 +25,7 @@ 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 declare type CoreActions = InitAction | UpdateCoreAction | UpdateAction | UpdateErrorsAction | SetAjvAction | SetSchemaAction | SetUISchemaAction | SetValidationModeAction;
28
+ export type CoreActions = InitAction | UpdateCoreAction | UpdateAction | UpdateErrorsAction | SetAjvAction | SetSchemaAction | SetUISchemaAction | SetValidationModeAction;
29
29
  export interface UpdateAction {
30
30
  type: 'jsonforms/UPDATE';
31
31
  path: string;
@@ -140,7 +140,7 @@ export interface SetConfigAction {
140
140
  }
141
141
  export declare const setConfig: (config: any) => SetConfigAction;
142
142
  export declare const setValidationMode: (validationMode: ValidationMode) => SetValidationModeAction;
143
- export declare type UISchemaActions = AddUISchemaAction | RemoveUISchemaAction;
143
+ export type UISchemaActions = AddUISchemaAction | RemoveUISchemaAction;
144
144
  export interface AddUISchemaAction {
145
145
  type: 'jsonforms/ADD_UI_SCHEMA';
146
146
  tester: UISchemaTester;
@@ -152,7 +152,7 @@ export interface RemoveUISchemaAction {
152
152
  tester: UISchemaTester;
153
153
  }
154
154
  export declare const unregisterUISchema: (tester: UISchemaTester) => RemoveUISchemaAction;
155
- export declare type I18nActions = SetLocaleAction | SetTranslatorAction | UpdateI18nAction;
155
+ export type I18nActions = SetLocaleAction | SetTranslatorAction | UpdateI18nAction;
156
156
  export interface SetLocaleAction {
157
157
  type: 'jsonforms/SET_LOCALE';
158
158
  locale: string | undefined;
@@ -18,7 +18,7 @@ export declare enum ArrayTranslationEnum {
18
18
  up = "up",
19
19
  down = "down"
20
20
  }
21
- export declare type ArrayTranslations = {
21
+ export type ArrayTranslations = {
22
22
  [key in ArrayTranslationEnum]?: string;
23
23
  };
24
24
  export declare const arrayDefaultTranslations: ArrayDefaultTranslation[];
@@ -8,7 +8,7 @@ export declare enum CombinatorTranslationEnum {
8
8
  clearDialogAccept = "clearDialogAccept",
9
9
  clearDialogDecline = "clearDialogDecline"
10
10
  }
11
- export declare type CombinatorTranslations = {
11
+ export type CombinatorTranslations = {
12
12
  [key in CombinatorTranslationEnum]?: string;
13
13
  };
14
14
  export declare const combinatorDefaultTranslations: CombinatorDefaultTranslation[];
@@ -1,16 +1,16 @@
1
1
  import type { ErrorObject } from 'ajv';
2
2
  import type { JsonSchema, UISchemaElement } from '../models';
3
- export declare type Translator = {
3
+ export type Translator = {
4
4
  (id: string, defaultMessage: string, values?: any): string;
5
5
  (id: string, defaultMessage: undefined, values?: any): string | undefined;
6
6
  (id: string, defaultMessage?: string, values?: any): string | undefined;
7
7
  };
8
- export declare type ErrorTranslator = (error: ErrorObject, translate: Translator, uischema?: UISchemaElement) => string;
8
+ export type ErrorTranslator = (error: ErrorObject, translate: Translator, uischema?: UISchemaElement) => string;
9
9
  export interface JsonFormsI18nState {
10
10
  locale?: string;
11
11
  translate?: Translator;
12
12
  translateError?: ErrorTranslator;
13
13
  }
14
- export declare type i18nJsonSchema = JsonSchema & {
14
+ export type i18nJsonSchema = JsonSchema & {
15
15
  i18n?: string;
16
16
  };
@@ -568,8 +568,7 @@ var coreReducer = function (state, action) {
568
568
  ? undefined
569
569
  : currentAjv.compile(state.schema);
570
570
  var errors = validate(validator, state.data);
571
- return __assign(__assign({}, state), { validator: validator,
572
- errors: errors });
571
+ return __assign(__assign({}, state), { validator: validator, errors: errors });
573
572
  }
574
573
  case SET_SCHEMA: {
575
574
  var needsNewValidator = action.schema && state.ajv && state.validationMode !== 'NoValidation';
@@ -619,8 +618,7 @@ var coreReducer = function (state, action) {
619
618
  if (state.validationMode === 'NoValidation') {
620
619
  var validator = state.ajv.compile(state.schema);
621
620
  var errors = validate(validator, state.data);
622
- return __assign(__assign({}, state), { validator: validator,
623
- errors: errors, validationMode: action.validationMode });
621
+ return __assign(__assign({}, state), { validator: validator, errors: errors, validationMode: action.validationMode });
624
622
  }
625
623
  return __assign(__assign({}, state), { validationMode: action.validationMode });
626
624
  }
@@ -648,7 +646,7 @@ var getControlPath = function (error) {
648
646
  controlPath = controlPath.replace(/\//g, '.');
649
647
  var invalidProperty = getInvalidProperty(error);
650
648
  if (invalidProperty !== undefined && !controlPath.endsWith(invalidProperty)) {
651
- controlPath = controlPath + "." + invalidProperty;
649
+ controlPath = "".concat(controlPath, ".").concat(invalidProperty);
652
650
  }
653
651
  controlPath = controlPath.replace(/^./, '');
654
652
  controlPath = decode(controlPath);
@@ -691,7 +689,7 @@ var getErrorsAt = function (instancePath, schema, matchPath) {
691
689
  var additionalErrors = (_b = state.additionalErrors) !== null && _b !== void 0 ? _b : [];
692
690
  return errorsAt(instancePath, schema, matchPath)(state.validationMode === 'ValidateAndHide'
693
691
  ? additionalErrors
694
- : __spreadArray(__spreadArray([], errors), additionalErrors));
692
+ : __spreadArray(__spreadArray([], errors, true), additionalErrors, true));
695
693
  };
696
694
  };
697
695
  var errorAt = function (instancePath, schema) {
@@ -733,20 +731,20 @@ var getI18nKeyPrefix = function (schema, uischema, path) {
733
731
  return ((_a = getI18nKeyPrefixBySchema(schema, uischema)) !== null && _a !== void 0 ? _a : transformPathToI18nPrefix(path));
734
732
  };
735
733
  var getI18nKey = function (schema, uischema, path, key) {
736
- return getI18nKeyPrefix(schema, uischema, path) + "." + key;
734
+ return "".concat(getI18nKeyPrefix(schema, uischema, path), ".").concat(key);
737
735
  };
738
736
  var addI18nKeyToPrefix = function (i18nKeyPrefix, key) {
739
- return i18nKeyPrefix + "." + key;
737
+ return "".concat(i18nKeyPrefix, ".").concat(key);
740
738
  };
741
739
  var defaultTranslator = function (_id, defaultMessage) { return defaultMessage; };
742
740
  var defaultErrorTranslator = function (error, t, uischema) {
743
741
  var _a;
744
- var i18nKey = getI18nKey(error.parentSchema, uischema, getControlPath(error), "error." + error.keyword);
742
+ var i18nKey = getI18nKey(error.parentSchema, uischema, getControlPath(error), "error.".concat(error.keyword));
745
743
  var specializedKeywordMessage = t(i18nKey, undefined, { error: error });
746
744
  if (specializedKeywordMessage !== undefined) {
747
745
  return specializedKeywordMessage;
748
746
  }
749
- var genericKeywordMessage = t("error." + error.keyword, undefined, {
747
+ var genericKeywordMessage = t("error.".concat(error.keyword), undefined, {
750
748
  error: error,
751
749
  });
752
750
  if (genericKeywordMessage !== undefined) {
@@ -792,7 +790,7 @@ var deriveLabelForUISchemaElement = function (uischema, t) {
792
790
  : JSON.stringify(uischema.label);
793
791
  var i18nKeyPrefix = getI18nKeyPrefixBySchema(undefined, uischema);
794
792
  var i18nKey = typeof i18nKeyPrefix === 'string'
795
- ? i18nKeyPrefix + ".label"
793
+ ? "".concat(i18nKeyPrefix, ".label")
796
794
  : stringifiedLabel;
797
795
  return t(i18nKey, stringifiedLabel, { uischema: uischema });
798
796
  };
@@ -833,11 +831,11 @@ exports.ArrayTranslationEnum = void 0;
833
831
  var arrayDefaultTranslations = [
834
832
  {
835
833
  key: exports.ArrayTranslationEnum.addTooltip,
836
- default: function (input) { return (input ? "Add to " + input : 'Add'); },
834
+ default: function (input) { return (input ? "Add to ".concat(input) : 'Add'); },
837
835
  },
838
836
  {
839
837
  key: exports.ArrayTranslationEnum.addAriaLabel,
840
- default: function (input) { return (input ? "Add to " + input + " button" : 'Add button'); },
838
+ default: function (input) { return (input ? "Add to ".concat(input, " button") : 'Add button'); },
841
839
  },
842
840
  { key: exports.ArrayTranslationEnum.removeTooltip, default: function () { return 'Delete'; } },
843
841
  { key: exports.ArrayTranslationEnum.removeAriaLabel, default: function () { return 'Delete button'; } },
@@ -895,9 +893,7 @@ var i18nReducer = function (state, action) {
895
893
  if (locale !== state.locale ||
896
894
  translate !== state.translate ||
897
895
  translateError !== state.translateError) {
898
- return __assign(__assign({}, state), { locale: locale,
899
- translate: translate,
900
- translateError: translateError });
896
+ return __assign(__assign({}, state), { locale: locale, translate: translate, translateError: translateError });
901
897
  }
902
898
  return state;
903
899
  }
@@ -1358,6 +1354,10 @@ var getRenderers = function (state) { return get__default["default"](state, 'jso
1358
1354
  var getCells = function (state) { return get__default["default"](state, 'jsonforms.cells'); };
1359
1355
  var getUISchemas = function (state) { return get__default["default"](state, 'jsonforms.uischemas'); };
1360
1356
 
1357
+ var defaultMiddleware = function (state, action, defaultReducer) {
1358
+ return defaultReducer(state, action);
1359
+ };
1360
+
1361
1361
  var compose = function (path1, path2) {
1362
1362
  var p1 = path1;
1363
1363
  if (!isEmpty__default["default"](path1) && !isEmpty__default["default"](path2) && !path2.startsWith('[')) {
@@ -1370,7 +1370,7 @@ var compose = function (path1, path2) {
1370
1370
  return p1;
1371
1371
  }
1372
1372
  else {
1373
- return "" + p1 + path2;
1373
+ return "".concat(p1).concat(path2);
1374
1374
  }
1375
1375
  };
1376
1376
  var toDataPathSegments = function (schemaPath) {
@@ -1482,7 +1482,7 @@ var resolveSchemaWithSegments = function (schema, pathSegments, rootSchema) {
1482
1482
  var subSchemas = [].concat((_a = schema.oneOf) !== null && _a !== void 0 ? _a : [], (_b = schema.allOf) !== null && _b !== void 0 ? _b : [], (_c = schema.anyOf) !== null && _c !== void 0 ? _c : [], (_d = schema.then) !== null && _d !== void 0 ? _d : [], (_e = schema.else) !== null && _e !== void 0 ? _e : []);
1483
1483
  for (var _i = 0, subSchemas_1 = subSchemas; _i < subSchemas_1.length; _i++) {
1484
1484
  var subSchema = subSchemas_1[_i];
1485
- alternativeResolveResult = resolveSchemaWithSegments(subSchema, __spreadArray([segment], remainingSegments), rootSchema);
1485
+ alternativeResolveResult = resolveSchemaWithSegments(subSchema, __spreadArray([segment], remainingSegments, true), rootSchema);
1486
1486
  if (alternativeResolveResult) {
1487
1487
  break;
1488
1488
  }
@@ -1743,7 +1743,7 @@ var isRequired = function (schema, schemaPath, rootSchema) {
1743
1743
  nextHigherSchema.required.indexOf(lastSegment) !== -1);
1744
1744
  };
1745
1745
  var computeLabel = function (label, required, hideRequiredAsterisk) {
1746
- return "" + (label !== null && label !== void 0 ? label : '') + (required && !hideRequiredAsterisk ? '*' : '');
1746
+ return "".concat(label !== null && label !== void 0 ? label : '').concat(required && !hideRequiredAsterisk ? '*' : '');
1747
1747
  };
1748
1748
  var showAsRequired = function (required, hideRequiredAsterisk) {
1749
1749
  return required && !hideRequiredAsterisk;
@@ -1806,7 +1806,7 @@ var enumToEnumOptionMapper = function (e, t, i18nKey) {
1806
1806
  var label = typeof e === 'string' ? e : JSON.stringify(e);
1807
1807
  if (t) {
1808
1808
  if (i18nKey) {
1809
- label = t(i18nKey + "." + label, label);
1809
+ label = t("".concat(i18nKey, ".").concat(label), label);
1810
1810
  }
1811
1811
  else {
1812
1812
  label = t(label, label);
@@ -1822,7 +1822,7 @@ var oneOfToEnumOptionMapper = function (e, t, fallbackI18nKey) {
1822
1822
  label = t(e.i18n, label);
1823
1823
  }
1824
1824
  else if (fallbackI18nKey) {
1825
- label = t(fallbackI18nKey + "." + label, label);
1825
+ label = t("".concat(fallbackI18nKey, ".").concat(label), label);
1826
1826
  }
1827
1827
  else {
1828
1828
  label = t(label, label);
@@ -1939,7 +1939,7 @@ var mapStateToMasterListItemProps = function (state, ownProps) {
1939
1939
  prop.type === 'integer');
1940
1940
  })
1941
1941
  : undefined;
1942
- var childPath = compose(path, "" + index);
1942
+ var childPath = compose(path, "".concat(index));
1943
1943
  var childData = Resolve.data(getData(state), childPath);
1944
1944
  var childLabel = firstPrimitiveProp ? childData[firstPrimitiveProp] : '';
1945
1945
  return __assign(__assign({}, ownProps), { childLabel: childLabel });
@@ -1953,9 +1953,7 @@ var mapStateToArrayControlProps = function (state, ownProps) {
1953
1953
  var resolvedSchema = Resolve.schema(schema, 'items', props.rootSchema);
1954
1954
  var childErrors = getSubErrorsAt(path, resolvedSchema)(state);
1955
1955
  var t = getTranslator()(state);
1956
- return __assign(__assign({}, props), { label: label,
1957
- path: path,
1958
- uischema: uischema, schema: resolvedSchema, childErrors: childErrors, renderers: ownProps.renderers || getRenderers(state), cells: ownProps.cells || getCells(state), translations: getArrayTranslations(t, arrayDefaultTranslations, i18nKeyPrefix, label) });
1956
+ return __assign(__assign({}, props), { label: label, path: path, uischema: uischema, schema: resolvedSchema, childErrors: childErrors, renderers: ownProps.renderers || getRenderers(state), cells: ownProps.cells || getCells(state), translations: getArrayTranslations(t, arrayDefaultTranslations, i18nKeyPrefix, label) });
1959
1957
  };
1960
1958
  var mapDispatchToArrayControlProps = function (dispatch) { return ({
1961
1959
  addItem: function (path, value) { return function () {
@@ -2037,9 +2035,7 @@ var mapStateToLayoutProps = function (state, ownProps) {
2037
2035
  var label = isLabelable(uischema)
2038
2036
  ? deriveLabelForUISchemaElement(uischema, t)
2039
2037
  : undefined;
2040
- return __assign(__assign({}, layoutDefaultProps), { renderers: ownProps.renderers || getRenderers(state), cells: ownProps.cells || getCells(state), visible: visible,
2041
- enabled: enabled, path: ownProps.path, data: data, uischema: ownProps.uischema, schema: ownProps.schema, direction: (_a = ownProps.direction) !== null && _a !== void 0 ? _a : getDirection(uischema), config: config,
2042
- label: label });
2038
+ return __assign(__assign({}, layoutDefaultProps), { renderers: ownProps.renderers || getRenderers(state), cells: ownProps.cells || getCells(state), visible: visible, enabled: enabled, path: ownProps.path, data: data, uischema: ownProps.uischema, schema: ownProps.schema, direction: (_a = ownProps.direction) !== null && _a !== void 0 ? _a : getDirection(uischema), config: config, label: label });
2043
2039
  };
2044
2040
  var mapStateToJsonFormsRendererProps = function (state, ownProps) {
2045
2041
  return {
@@ -2090,11 +2086,7 @@ var mapStateToCombinatorRendererProps = function (state, ownProps, keyword) {
2090
2086
  console.debug("Combinator subschema is not self contained, can't hand it over to AJV");
2091
2087
  }
2092
2088
  }
2093
- return __assign(__assign({ data: data,
2094
- schema: schema,
2095
- rootSchema: rootSchema }, props), { i18nKeyPrefix: i18nKeyPrefix,
2096
- label: label,
2097
- indexOfFittingSchema: indexOfFittingSchema, uischemas: getUISchemas(state), translations: translations });
2089
+ return __assign(__assign({ data: data, schema: schema, rootSchema: rootSchema }, props), { i18nKeyPrefix: i18nKeyPrefix, label: label, indexOfFittingSchema: indexOfFittingSchema, uischemas: getUISchemas(state), translations: translations });
2098
2090
  };
2099
2091
  var mapStateToAllOfProps = function (state, ownProps) {
2100
2092
  return mapStateToCombinatorRendererProps(state, ownProps, 'allOf');
@@ -2113,9 +2105,7 @@ var mapStateToArrayLayoutProps = function (state, ownProps) {
2113
2105
  var allErrors = errors +
2114
2106
  (errors.length > 0 && childErrors.length > 0 ? '\n' : '') +
2115
2107
  childErrors;
2116
- return __assign(__assign({}, props), { label: label,
2117
- path: path,
2118
- uischema: uischema, schema: resolvedSchema, data: props.data ? props.data.length : 0, errors: allErrors, minItems: schema.minItems, translations: getArrayTranslations(t, arrayDefaultTranslations, i18nKeyPrefix, label) });
2108
+ return __assign(__assign({}, props), { label: label, path: path, uischema: uischema, schema: resolvedSchema, data: props.data ? props.data.length : 0, errors: allErrors, minItems: schema.minItems, translations: getArrayTranslations(t, arrayDefaultTranslations, i18nKeyPrefix, label) });
2119
2109
  };
2120
2110
  var mapStateToLabelProps = function (state, props) {
2121
2111
  var uischema = props.uischema;
@@ -2125,7 +2115,7 @@ var mapStateToLabelProps = function (state, props) {
2125
2115
  var text = uischema.text;
2126
2116
  var t = getTranslator()(state);
2127
2117
  var i18nKeyPrefix = getI18nKeyPrefixBySchema(undefined, uischema);
2128
- var i18nKey = i18nKeyPrefix ? i18nKeyPrefix + ".text" : text !== null && text !== void 0 ? text : '';
2118
+ var i18nKey = i18nKeyPrefix ? "".concat(i18nKeyPrefix, ".text") : text !== null && text !== void 0 ? text : '';
2129
2119
  var i18nText = t(i18nKey, text, { uischema: uischema });
2130
2120
  return {
2131
2121
  text: i18nText,
@@ -2217,7 +2207,7 @@ var createCombinatorRenderInfos = function (combinatorSubSchemas, rootSchema, ke
2217
2207
  return {
2218
2208
  schema: schema,
2219
2209
  uischema: findUISchema(uischemas, schema, control.scope, path, undefined, control, rootSchema),
2220
- label: (_b = (_a = subSchema.title) !== null && _a !== void 0 ? _a : resolvedSubSchema === null || resolvedSubSchema === void 0 ? void 0 : resolvedSubSchema.title) !== null && _b !== void 0 ? _b : keyword + "-" + subSchemaIndex,
2210
+ label: (_b = (_a = subSchema.title) !== null && _a !== void 0 ? _a : resolvedSubSchema === null || resolvedSubSchema === void 0 ? void 0 : resolvedSubSchema.title) !== null && _b !== void 0 ? _b : "".concat(keyword, "-").concat(subSchemaIndex),
2221
2211
  };
2222
2212
  });
2223
2213
  };
@@ -2294,6 +2284,10 @@ var createAjv = function (options) {
2294
2284
  return ajv;
2295
2285
  };
2296
2286
 
2287
+ var defaultDateFormat = 'YYYY-MM-DD';
2288
+ var defaultTimeFormat = 'HH:mm:ss';
2289
+ var defaultDateTimeFormat = 'YYYY-MM-DDTHH:mm:ss.sssZ';
2290
+
2297
2291
  var createLayout = function (layoutType) { return ({
2298
2292
  type: layoutType,
2299
2293
  elements: [],
@@ -2359,7 +2353,7 @@ var generateUISchema = function (jsonSchema, schemaElements, currentRef, schemaN
2359
2353
  var nextRef_1 = currentRef + '/properties';
2360
2354
  Object.keys(jsonSchema.properties).map(function (propName) {
2361
2355
  var value = jsonSchema.properties[propName];
2362
- var ref = nextRef_1 + "/" + encode(propName);
2356
+ var ref = "".concat(nextRef_1, "/").concat(encode(propName));
2363
2357
  if (value.$ref !== undefined) {
2364
2358
  value = resolveSchema(rootSchema, value.$ref, rootSchema);
2365
2359
  }
@@ -2374,6 +2368,7 @@ var generateUISchema = function (jsonSchema, schemaElements, currentRef, schemaN
2374
2368
  case 'string':
2375
2369
  case 'number':
2376
2370
  case 'integer':
2371
+ case 'null':
2377
2372
  case 'boolean': {
2378
2373
  var controlObject = createControlElement(currentRef);
2379
2374
  schemaElements.push(controlObject);
@@ -2626,10 +2621,14 @@ exports.createId = createId;
2626
2621
  exports.createLabelDescriptionFrom = createLabelDescriptionFrom;
2627
2622
  exports.decode = decode;
2628
2623
  exports.defaultDataReducer = defaultDataReducer;
2624
+ exports.defaultDateFormat = defaultDateFormat;
2625
+ exports.defaultDateTimeFormat = defaultDateTimeFormat;
2629
2626
  exports.defaultErrorTranslator = defaultErrorTranslator;
2630
2627
  exports.defaultJsonFormsI18nState = defaultJsonFormsI18nState;
2631
2628
  exports.defaultMapDispatchToControlProps = defaultMapDispatchToControlProps;
2632
2629
  exports.defaultMapStateToEnumCellProps = defaultMapStateToEnumCellProps;
2630
+ exports.defaultMiddleware = defaultMiddleware;
2631
+ exports.defaultTimeFormat = defaultTimeFormat;
2633
2632
  exports.defaultTranslator = defaultTranslator;
2634
2633
  exports.deriveLabelForUISchemaElement = deriveLabelForUISchemaElement;
2635
2634
  exports.deriveTypes = deriveTypes;