@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.
@@ -17,6 +17,7 @@ import isArray from 'lodash/isArray';
17
17
  import reduce from 'lodash/reduce';
18
18
  import toPairs from 'lodash/toPairs';
19
19
  import includes from 'lodash/includes';
20
+ import isUndefined from 'lodash/isUndefined';
20
21
  import find from 'lodash/find';
21
22
  import range from 'lodash/range';
22
23
  import has from 'lodash/has';
@@ -929,6 +930,13 @@ const optionIs = (optionName, optionValue) => (uischema) => {
929
930
  const options = uischema.options;
930
931
  return !isEmpty(options) && options[optionName] === optionValue;
931
932
  };
933
+ const hasOption = (optionName) => (uischema) => {
934
+ if (isEmpty(uischema)) {
935
+ return false;
936
+ }
937
+ const options = uischema.options;
938
+ return !isEmpty(options) && !isUndefined(options[optionName]);
939
+ };
932
940
  const scopeEndsWith = (expected) => (uischema) => {
933
941
  if (isEmpty(expected) || !isControl(uischema)) {
934
942
  return false;
@@ -1085,6 +1093,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
1085
1093
  formatIs: formatIs,
1086
1094
  uiTypeIs: uiTypeIs,
1087
1095
  optionIs: optionIs,
1096
+ hasOption: hasOption,
1088
1097
  scopeEndsWith: scopeEndsWith,
1089
1098
  scopeEndIs: scopeEndIs,
1090
1099
  and: and,
@@ -1788,7 +1797,7 @@ const mapDispatchToArrayControlProps = (dispatch) => ({
1788
1797
  }
1789
1798
  array.push(value);
1790
1799
  return array;
1791
- }));
1800
+ }, { type: 'ADD', values: [value] }));
1792
1801
  },
1793
1802
  removeItems: (path, toDelete) => () => {
1794
1803
  dispatch(update(path, (array) => {
@@ -1797,18 +1806,24 @@ const mapDispatchToArrayControlProps = (dispatch) => ({
1797
1806
  .reverse()
1798
1807
  .forEach((s) => array.splice(s, 1));
1799
1808
  return array;
1800
- }));
1809
+ }, { type: 'REMOVE', indices: toDelete }));
1801
1810
  },
1802
1811
  moveUp: (path, toMove) => () => {
1803
1812
  dispatch(update(path, (array) => {
1804
1813
  moveUp(array, toMove);
1805
1814
  return array;
1815
+ }, {
1816
+ type: 'MOVE',
1817
+ moves: [{ from: toMove, to: toMove - 1 }],
1806
1818
  }));
1807
1819
  },
1808
1820
  moveDown: (path, toMove) => () => {
1809
1821
  dispatch(update(path, (array) => {
1810
1822
  moveDown(array, toMove);
1811
1823
  return array;
1824
+ }, {
1825
+ type: 'MOVE',
1826
+ moves: [{ from: toMove, to: toMove + 1 }],
1812
1827
  }));
1813
1828
  },
1814
1829
  });
@@ -2267,6 +2282,40 @@ const SET_TRANSLATOR = 'jsonforms/SET_TRANSLATOR';
2267
2282
  const UPDATE_I18N = 'jsonforms/UPDATE_I18N';
2268
2283
  const ADD_DEFAULT_DATA = 'jsonforms/ADD_DEFAULT_DATA';
2269
2284
  const REMOVE_DEFAULT_DATA = 'jsonforms/REMOVE_DEFAULT_DATA';
2285
+ const isUpdateArrayContext = (context) => {
2286
+ if (!('type' in context)) {
2287
+ return false;
2288
+ }
2289
+ if (typeof context.type !== 'string') {
2290
+ return false;
2291
+ }
2292
+ switch (context.type) {
2293
+ case 'ADD': {
2294
+ return ('values' in context &&
2295
+ Array.isArray(context.values) &&
2296
+ context.values.length > 0);
2297
+ }
2298
+ case 'REMOVE': {
2299
+ return ('indices' in context &&
2300
+ Array.isArray(context.indices) &&
2301
+ context.indices.length > 0 &&
2302
+ context.indices.every((i) => typeof i === 'number'));
2303
+ }
2304
+ case 'MOVE': {
2305
+ return ('moves' in context &&
2306
+ Array.isArray(context.moves) &&
2307
+ context.moves.length > 0 &&
2308
+ context.moves.every((m) => typeof m === 'object' &&
2309
+ m !== null &&
2310
+ 'from' in m &&
2311
+ 'to' in m &&
2312
+ typeof m.from === 'number' &&
2313
+ typeof m.to === 'number'));
2314
+ }
2315
+ default:
2316
+ return false;
2317
+ }
2318
+ };
2270
2319
  const init = (data, schema = generateJsonSchema(data), uischema, options) => ({
2271
2320
  type: INIT,
2272
2321
  data,
@@ -2294,10 +2343,11 @@ const setAjv = (ajv) => ({
2294
2343
  type: SET_AJV,
2295
2344
  ajv,
2296
2345
  });
2297
- const update = (path, updater) => ({
2346
+ const update = (path, updater, context) => ({
2298
2347
  type: UPDATE_DATA,
2299
2348
  path,
2300
2349
  updater,
2350
+ context,
2301
2351
  });
2302
2352
  const updateErrors = (errors) => ({
2303
2353
  type: UPDATE_ERRORS,
@@ -2391,6 +2441,7 @@ var index = /*#__PURE__*/Object.freeze({
2391
2441
  UPDATE_I18N: UPDATE_I18N,
2392
2442
  ADD_DEFAULT_DATA: ADD_DEFAULT_DATA,
2393
2443
  REMOVE_DEFAULT_DATA: REMOVE_DEFAULT_DATA,
2444
+ isUpdateArrayContext: isUpdateArrayContext,
2394
2445
  init: init,
2395
2446
  updateCore: updateCore,
2396
2447
  registerDefaultData: registerDefaultData,
@@ -2418,5 +2469,5 @@ const Helpers = {
2418
2469
  convertToValidClassName,
2419
2470
  };
2420
2471
 
2421
- export { ADD_CELL, ADD_DEFAULT_DATA, ADD_RENDERER, ADD_UI_SCHEMA, index as Actions, ArrayTranslationEnum, CombinatorTranslationEnum, Draft4, Generate, Helpers, INIT, NOT_APPLICABLE, Paths, REMOVE_CELL, REMOVE_DEFAULT_DATA, REMOVE_RENDERER, REMOVE_UI_SCHEMA, Resolve, RuleEffect, Runtime, SET_AJV, SET_CONFIG, SET_LOCALE, SET_SCHEMA, SET_TRANSLATOR, SET_UISCHEMA, SET_VALIDATION_MODE, index$1 as Test, UPDATE_CORE, UPDATE_DATA, UPDATE_ERRORS, UPDATE_I18N, VALIDATE, addI18nKeyToPrefix, and, arrayDefaultTranslations, categorizationHasCategory, cellReducer, clearAllIds, combinatorDefaultTranslations, compose, compose as composePaths, composeWithUi, computeLabel, configReducer, controlDefaultProps, convertDateToString, convertToValidClassName, coreReducer, createAjv, createCleanLabel, createCombinatorRenderInfos, createControlElement, createDefaultValue, createId, createLabelDescriptionFrom, decode, defaultDataReducer, defaultDateFormat, defaultDateTimeFormat, defaultErrorTranslator, defaultJsonFormsI18nState, defaultMapDispatchToControlProps, defaultMapStateToEnumCellProps, defaultMiddleware, defaultTimeFormat, defaultTranslator, deriveLabelForUISchemaElement, deriveTypes, encode, enumToEnumOptionMapper, errorAt, errorsAt, evalEnablement, evalVisibility, extractAjv, extractData, extractDefaultData, extractDefaults, extractSchema, extractUiSchema, fetchErrorTranslator, fetchLocale, fetchTranslator, findAllRefs, findMatchingUISchema, findUISchema, formatErrorMessage, formatIs, generateDefaultUISchema, generateJsonSchema, getAjv, getArrayTranslations, getCells, getCombinatorTranslations, getCombinedErrorMessage, getConfig, getControlPath, getData, getDefaultData, getErrorAt, getErrorTranslator, getFirstPrimitiveProp, getI18nKey, getI18nKeyPrefix, getI18nKeyPrefixBySchema, getLocale, getRenderers, getSchema, getSubErrorsAt, getTranslator, getUISchemas, getUiSchema, hasCategory, hasEnableRule, hasShowRule, hasType, i18nReducer, init, isAllOfControl, isAnyOfControl, isArrayObjectControl, isBooleanControl, isCategorization, isCategory, isControl, isDateControl, isDateTimeControl, isDescriptionHidden, isEnabled, isEnumControl, isGroup, isInherentlyEnabled, isIntegerControl, isInternationalized, isLabelable, isLabeled, isLayout, isMultiLineControl, isNumberControl, isNumberFormatControl, isObjectArray, isObjectArrayControl, isObjectArrayWithNesting, isObjectControl, isOneOfControl, isOneOfEnumControl, isOneOfEnumSchema, isPrimitiveArrayControl, isRangeControl, isScopable, isScoped, isStringControl, isTimeControl, isVisible, iterateSchema, jsonFormsReducerConfig, layoutDefaultProps, mapDispatchToArrayControlProps, mapDispatchToCellProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToArrayControlProps, mapStateToArrayLayoutProps, mapStateToCellProps, mapStateToCombinatorRendererProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToDispatchCellProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLabelProps, mapStateToLayoutProps, mapStateToMasterListItemProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumCellProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, moveDown, moveUp, not, oneOfToEnumOptionMapper, optionIs, or, rankWith, registerCell, registerDefaultData, registerRenderer, registerUISchema, removeId, rendererReducer, resolveData, resolveSchema, schemaMatches, schemaSubPathMatches, schemaTypeIs, scopeEndIs, scopeEndsWith, setAjv, setConfig, setLocale, setReadonly, setSchema, setTranslator, setUISchema, setValidationMode, showAsRequired, subErrorsAt, toDataPath, toDataPathSegments, transformPathToI18nPrefix, uiTypeIs, uischemaRegistryReducer, unregisterCell, unregisterDefaultData, unregisterRenderer, unregisterUISchema, unsetReadonly, update, updateCore, updateErrors, updateI18n, validate, withIncreasedRank };
2472
+ export { ADD_CELL, ADD_DEFAULT_DATA, ADD_RENDERER, ADD_UI_SCHEMA, index as Actions, ArrayTranslationEnum, CombinatorTranslationEnum, Draft4, Generate, Helpers, INIT, NOT_APPLICABLE, Paths, REMOVE_CELL, REMOVE_DEFAULT_DATA, REMOVE_RENDERER, REMOVE_UI_SCHEMA, Resolve, RuleEffect, Runtime, SET_AJV, SET_CONFIG, SET_LOCALE, SET_SCHEMA, SET_TRANSLATOR, SET_UISCHEMA, SET_VALIDATION_MODE, index$1 as Test, UPDATE_CORE, UPDATE_DATA, UPDATE_ERRORS, UPDATE_I18N, VALIDATE, addI18nKeyToPrefix, and, arrayDefaultTranslations, categorizationHasCategory, cellReducer, clearAllIds, combinatorDefaultTranslations, compose, compose as composePaths, composeWithUi, computeLabel, configReducer, controlDefaultProps, convertDateToString, convertToValidClassName, coreReducer, createAjv, createCleanLabel, createCombinatorRenderInfos, createControlElement, createDefaultValue, createId, createLabelDescriptionFrom, decode, defaultDataReducer, defaultDateFormat, defaultDateTimeFormat, defaultErrorTranslator, defaultJsonFormsI18nState, defaultMapDispatchToControlProps, defaultMapStateToEnumCellProps, defaultMiddleware, defaultTimeFormat, defaultTranslator, deriveLabelForUISchemaElement, deriveTypes, encode, enumToEnumOptionMapper, errorAt, errorsAt, evalEnablement, evalVisibility, extractAjv, extractData, extractDefaultData, extractDefaults, extractSchema, extractUiSchema, fetchErrorTranslator, fetchLocale, fetchTranslator, findAllRefs, findMatchingUISchema, findUISchema, formatErrorMessage, formatIs, generateDefaultUISchema, generateJsonSchema, getAjv, getArrayTranslations, getCells, getCombinatorTranslations, getCombinedErrorMessage, getConfig, getControlPath, getData, getDefaultData, getErrorAt, getErrorTranslator, getFirstPrimitiveProp, getI18nKey, getI18nKeyPrefix, getI18nKeyPrefixBySchema, getLocale, getRenderers, getSchema, getSubErrorsAt, getTranslator, getUISchemas, getUiSchema, hasCategory, hasEnableRule, hasOption, hasShowRule, hasType, i18nReducer, init, isAllOfControl, isAnyOfControl, isArrayObjectControl, isBooleanControl, isCategorization, isCategory, isControl, isDateControl, isDateTimeControl, isDescriptionHidden, isEnabled, isEnumControl, isGroup, isInherentlyEnabled, isIntegerControl, isInternationalized, isLabelable, isLabeled, isLayout, isMultiLineControl, isNumberControl, isNumberFormatControl, isObjectArray, isObjectArrayControl, isObjectArrayWithNesting, isObjectControl, isOneOfControl, isOneOfEnumControl, isOneOfEnumSchema, isPrimitiveArrayControl, isRangeControl, isScopable, isScoped, isStringControl, isTimeControl, isUpdateArrayContext, isVisible, iterateSchema, jsonFormsReducerConfig, layoutDefaultProps, mapDispatchToArrayControlProps, mapDispatchToCellProps, mapDispatchToControlProps, mapDispatchToMultiEnumProps, mapStateToAllOfProps, mapStateToAnyOfProps, mapStateToArrayControlProps, mapStateToArrayLayoutProps, mapStateToCellProps, mapStateToCombinatorRendererProps, mapStateToControlProps, mapStateToControlWithDetailProps, mapStateToDispatchCellProps, mapStateToEnumControlProps, mapStateToJsonFormsRendererProps, mapStateToLabelProps, mapStateToLayoutProps, mapStateToMasterListItemProps, mapStateToMultiEnumControlProps, mapStateToOneOfEnumCellProps, mapStateToOneOfEnumControlProps, mapStateToOneOfProps, moveDown, moveUp, not, oneOfToEnumOptionMapper, optionIs, or, rankWith, registerCell, registerDefaultData, registerRenderer, registerUISchema, removeId, rendererReducer, resolveData, resolveSchema, schemaMatches, schemaSubPathMatches, schemaTypeIs, scopeEndIs, scopeEndsWith, setAjv, setConfig, setLocale, setReadonly, setSchema, setTranslator, setUISchema, setValidationMode, showAsRequired, subErrorsAt, toDataPath, toDataPathSegments, transformPathToI18nPrefix, uiTypeIs, uischemaRegistryReducer, unregisterCell, unregisterDefaultData, unregisterRenderer, unregisterUISchema, unsetReadonly, update, updateCore, updateErrors, updateI18n, validate, withIncreasedRank };
2422
2473
  //# sourceMappingURL=jsonforms-core.esm.js.map