@jsonforms/material-renderers 3.0.0-beta.1 → 3.0.0-beta.4

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.
Files changed (52) hide show
  1. package/README.md +71 -13
  2. package/docs/globals.html +55 -85
  3. package/docs/index.html +70 -13
  4. package/docs/interfaces/emptytableprops.html +1 -1
  5. package/docs/interfaces/nonemptycellcomponentprops.html +9 -9
  6. package/docs/interfaces/nonemptycellprops.html +9 -9
  7. package/docs/interfaces/ownoneofprops.html +1 -1
  8. package/docs/interfaces/ownpropsofnonemptycell.html +6 -6
  9. package/docs/interfaces/tableheadercellprops.html +1 -1
  10. package/lib/additional/MaterialListWithDetailRenderer.d.ts +1 -1
  11. package/lib/jsonforms-react-material.cjs.js +20 -28
  12. package/lib/jsonforms-react-material.cjs.js.map +1 -1
  13. package/lib/jsonforms-react-material.esm.js +19 -27
  14. package/lib/jsonforms-react-material.esm.js.map +1 -1
  15. package/lib/layouts/MaterialArrayLayoutRenderer.d.ts +1 -1
  16. package/package.json +8 -6
  17. package/src/additional/MaterialListWithDetailRenderer.tsx +5 -3
  18. package/src/complex/MaterialAllOfRenderer.tsx +3 -5
  19. package/src/complex/MaterialAnyOfRenderer.tsx +3 -5
  20. package/src/complex/MaterialEnumArrayRenderer.tsx +1 -2
  21. package/src/complex/MaterialObjectRenderer.tsx +3 -8
  22. package/src/complex/MaterialOneOfRenderer.tsx +3 -5
  23. package/src/complex/MaterialTableControl.tsx +6 -6
  24. package/src/layouts/ExpandPanelRenderer.tsx +2 -1
  25. package/src/layouts/MaterialArrayLayoutRenderer.tsx +3 -25
  26. package/stats.html +1 -1
  27. package/test/renderers/MaterialAnyOfStringOrEnumControl.test.tsx +7 -7
  28. package/test/renderers/MaterialArrayLayout.test.tsx +66 -8
  29. package/test/renderers/MaterialBooleanCell.test.tsx +10 -7
  30. package/test/renderers/MaterialBooleanToggleCell.test.tsx +14 -9
  31. package/test/renderers/MaterialBooleanToggleControl.test.tsx +14 -9
  32. package/test/renderers/MaterialCategorizationLayout.test.tsx +12 -12
  33. package/test/renderers/MaterialCategorizationStepperLayout.test.tsx +12 -12
  34. package/test/renderers/MaterialDateCell.test.tsx +10 -7
  35. package/test/renderers/MaterialDateControl.test.tsx +12 -8
  36. package/test/renderers/MaterialDateTimeControl.test.tsx +12 -8
  37. package/test/renderers/MaterialEnumArrayRenderer.test.tsx +9 -7
  38. package/test/renderers/MaterialEnumCell.test.tsx +2 -1
  39. package/test/renderers/MaterialEnumControl.test.tsx +75 -0
  40. package/test/renderers/MaterialIntegerCell.test.tsx +10 -7
  41. package/test/renderers/MaterialLabelRenderer.test.tsx +4 -4
  42. package/test/renderers/MaterialListWithDetailRenderer.test.tsx +5 -5
  43. package/test/renderers/MaterialNumberCell.test.tsx +10 -7
  44. package/test/renderers/MaterialObjectControl.test.tsx +10 -7
  45. package/test/renderers/MaterialOneOfEnumCell.test.tsx +2 -1
  46. package/test/renderers/MaterialOneOfRadioGroupControl.test.tsx +3 -2
  47. package/test/renderers/MaterialOneOfRenderer.test.tsx +12 -7
  48. package/test/renderers/MaterialRadioGroupControl.test.tsx +2 -2
  49. package/test/renderers/MaterialSliderControl.test.tsx +20 -12
  50. package/test/renderers/MaterialTextCell.test.tsx +10 -7
  51. package/test/renderers/MaterialTimeCell.test.tsx +10 -7
  52. package/test/renderers/MaterialTimeControl.test.tsx +12 -8
@@ -1,4 +1,4 @@
1
- import { createDefaultValue, Resolve, Paths, formatErrorMessage, errorsAt, rankWith, isObjectControl, findUISchema, isAllOfControl, resolveSubSchemas, findMatchingUISchema, createCombinatorRenderInfos, Generate, isAnyOfControl, isOneOfControl, getAjv, and, uiTypeIs, schemaMatches, hasType, schemaSubPathMatches, or, isObjectArrayControl, isPrimitiveArrayControl, isObjectArray, computeLabel, composePaths, isBooleanControl, optionIs, isDescriptionHidden, showAsRequired, isEnumControl, isDateControl, isTimeControl, isDateTimeControl, isRangeControl, isIntegerControl, isNumberControl, isStringControl, isOneOfEnumControl, withIncreasedRank, isVisible, update, moveUp, moveDown, getFirstPrimitiveProp, createId, removeId, isObjectArrayWithNesting, isNumberFormatControl, categorizationHasCategory } from '@jsonforms/core';
1
+ import { createDefaultValue, Resolve, encode, Paths, formatErrorMessage, errorsAt, rankWith, isObjectControl, findUISchema, Generate, isAllOfControl, findMatchingUISchema, createCombinatorRenderInfos, isAnyOfControl, isOneOfControl, getAjv, and, uiTypeIs, schemaMatches, hasType, schemaSubPathMatches, or, isObjectArrayControl, isPrimitiveArrayControl, isObjectArray, computeLabel, composePaths, isBooleanControl, optionIs, isDescriptionHidden, showAsRequired, isEnumControl, isDateControl, isTimeControl, isDateTimeControl, isRangeControl, isIntegerControl, isNumberControl, isStringControl, isOneOfEnumControl, withIncreasedRank, isVisible, update, moveUp, moveDown, getFirstPrimitiveProp, createId, removeId, isObjectArrayWithNesting, isNumberFormatControl, categorizationHasCategory } from '@jsonforms/core';
2
2
  import React, { useMemo, Fragment, useState, useCallback, useEffect } from 'react';
3
3
  import { DispatchCell, useJsonForms, withJsonFormsArrayLayoutProps, withJsonFormsDetailProps, JsonFormsDispatch, withJsonFormsAllOfProps, withJsonFormsAnyOfProps, withJsonFormsOneOfProps, withJsonFormsMultiEnumProps, withJsonFormsLayoutProps, withJsonFormsMasterListItemProps, withJsonFormsControlProps, withJsonFormsEnumProps, Control, withJsonFormsOneOfEnumProps, withJsonFormsContext, withJsonFormsCellProps, withJsonFormsEnumCellProps, withJsonFormsOneOfEnumCellProps } from '@jsonforms/react';
4
4
  import isEmpty from 'lodash/isEmpty';
@@ -132,7 +132,7 @@ const controlWithoutLabel = (scope) => ({
132
132
  });
133
133
  const NonEmptyCellComponent = React.memo(({ path, propName, schema, rootSchema, errors, enabled, renderers, cells, isValid }) => {
134
134
  return (React.createElement(NoBorderTableCell, null,
135
- schema.properties ? (React.createElement(DispatchCell, { schema: Resolve.schema(schema, `#/properties/${propName}`, rootSchema), uischema: controlWithoutLabel(`#/properties/${propName}`), path: path, enabled: enabled, renderers: renderers, cells: cells })) : (React.createElement(DispatchCell, { schema: schema, uischema: controlWithoutLabel('#'), path: path, enabled: enabled, renderers: renderers, cells: cells })),
135
+ schema.properties ? (React.createElement(DispatchCell, { schema: Resolve.schema(schema, `#/properties/${encode(propName)}`, rootSchema), uischema: controlWithoutLabel(`#/properties/${encode(propName)}`), path: path, enabled: enabled, renderers: renderers, cells: cells })) : (React.createElement(DispatchCell, { schema: schema, uischema: controlWithoutLabel('#'), path: path, enabled: enabled, renderers: renderers, cells: cells })),
136
136
  React.createElement(FormHelperText, { error: !isValid }, !isValid && errors)));
137
137
  });
138
138
  const NonEmptyCell = (ownProps) => {
@@ -168,7 +168,7 @@ const TableRows = ({ data, path, schema, openDeleteDialog, moveUp, moveDown, uis
168
168
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
169
169
  return (React.createElement(React.Fragment, null, range(data).map((index) => {
170
170
  const childPath = Paths.compose(path, `${index}`);
171
- return (React.createElement(NonEmptyRow, { key: childPath, childPath: childPath, rowIndex: index, schema: schema, openDeleteDialog: openDeleteDialog, moveUpCreator: moveUp, moveDownCreator: moveDown, enableUp: index !== 0, enableDown: index !== data - 1, showSortButtons: appliedUiSchemaOptions.showSortButtons, enabled: enabled, cells: cells, path: path }));
171
+ return (React.createElement(NonEmptyRow, { key: childPath, childPath: childPath, rowIndex: index, schema: schema, openDeleteDialog: openDeleteDialog, moveUpCreator: moveUp, moveDownCreator: moveDown, enableUp: index !== 0, enableDown: index !== data - 1, showSortButtons: appliedUiSchemaOptions.showSortButtons || appliedUiSchemaOptions.showArrayTableSortButtons, enabled: enabled, cells: cells, path: path }));
172
172
  })));
173
173
  };
174
174
  class MaterialTableControl extends React.Component {
@@ -229,13 +229,7 @@ const MaterialArrayControlRenderer = (props) => {
229
229
  var MaterialArrayControlRenderer$1 = withJsonFormsArrayLayoutProps(MaterialArrayControlRenderer);
230
230
 
231
231
  const MaterialObjectRenderer = ({ renderers, cells, uischemas, schema, label, path, visible, enabled, uischema, rootSchema }) => {
232
- const detailUiSchema = useMemo(() => findUISchema(uischemas, schema, uischema.scope, path, 'Group', uischema, rootSchema), [uischemas, schema, uischema.scope, path, uischema, rootSchema]);
233
- if (isEmpty(path)) {
234
- detailUiSchema.type = 'VerticalLayout';
235
- }
236
- else {
237
- detailUiSchema.label = label;
238
- }
232
+ const detailUiSchema = useMemo(() => findUISchema(uischemas, schema, uischema.scope, path, () => isEmpty(path) ? Generate.uiSchema(schema, 'VerticalLayout') : { ...Generate.uiSchema(schema, 'Group'), label }, uischema, rootSchema), [uischemas, schema, uischema.scope, path, label, uischema, rootSchema]);
239
233
  return (React.createElement(Hidden, { xsUp: !visible },
240
234
  React.createElement(JsonFormsDispatch, { visible: visible, enabled: enabled, schema: schema, uischema: detailUiSchema, path: path, renderers: renderers, cells: cells })));
241
235
  };
@@ -243,13 +237,12 @@ const materialObjectControlTester = rankWith(2, isObjectControl);
243
237
  var MaterialObjectRenderer$1 = withJsonFormsDetailProps(MaterialObjectRenderer);
244
238
 
245
239
  const MaterialAllOfRenderer = ({ schema, rootSchema, visible, renderers, cells, path, uischemas, uischema }) => {
246
- const _schema = resolveSubSchemas(schema, rootSchema, 'allOf');
247
- const delegateUISchema = findMatchingUISchema(uischemas)(_schema, uischema.scope, path);
240
+ const delegateUISchema = findMatchingUISchema(uischemas)(schema, uischema.scope, path);
248
241
  if (delegateUISchema) {
249
242
  return (React.createElement(Hidden, { xsUp: !visible },
250
- React.createElement(JsonFormsDispatch, { schema: _schema, uischema: delegateUISchema, path: path, renderers: renderers, cells: cells })));
243
+ React.createElement(JsonFormsDispatch, { schema: schema, uischema: delegateUISchema, path: path, renderers: renderers, cells: cells })));
251
244
  }
252
- const allOfRenderInfos = createCombinatorRenderInfos(_schema.allOf, rootSchema, 'allOf', uischema, path, uischemas);
245
+ const allOfRenderInfos = createCombinatorRenderInfos(schema.allOf, rootSchema, 'allOf', uischema, path, uischemas);
253
246
  return (React.createElement(Hidden, { xsUp: !visible }, allOfRenderInfos.map((allOfRenderInfo, allOfIndex) => (React.createElement(JsonFormsDispatch, { key: allOfIndex, schema: allOfRenderInfo.schema, uischema: allOfRenderInfo.uischema, path: path, renderers: renderers, cells: cells })))));
254
247
  };
255
248
  const materialAllOfControlTester = rankWith(3, isAllOfControl);
@@ -276,10 +269,9 @@ const MaterialAnyOfRenderer = ({ schema, rootSchema, indexOfFittingSchema, visib
276
269
  const [selectedAnyOf, setSelectedAnyOf] = useState(indexOfFittingSchema || 0);
277
270
  const handleChange = useCallback((_ev, value) => setSelectedAnyOf(value), [setSelectedAnyOf]);
278
271
  const anyOf = 'anyOf';
279
- const _schema = resolveSubSchemas(schema, rootSchema, anyOf);
280
- const anyOfRenderInfos = createCombinatorRenderInfos(_schema.anyOf, rootSchema, anyOf, uischema, path, uischemas);
272
+ const anyOfRenderInfos = createCombinatorRenderInfos(schema.anyOf, rootSchema, anyOf, uischema, path, uischemas);
281
273
  return (React.createElement(Hidden, { xsUp: !visible },
282
- React.createElement(CombinatorProperties, { schema: _schema, combinatorKeyword: 'anyOf', path: path }),
274
+ React.createElement(CombinatorProperties, { schema: schema, combinatorKeyword: anyOf, path: path }),
283
275
  React.createElement(Tabs, { value: selectedAnyOf, onChange: handleChange }, anyOfRenderInfos.map(anyOfRenderInfo => (React.createElement(Tab, { key: anyOfRenderInfo.label, label: anyOfRenderInfo.label })))),
284
276
  anyOfRenderInfos.map((anyOfRenderInfo, anyOfIndex) => selectedAnyOf === anyOfIndex && (React.createElement(JsonFormsDispatch, { key: anyOfIndex, schema: anyOfRenderInfo.schema, uischema: anyOfRenderInfo.uischema, path: path, renderers: renderers, cells: cells })))));
285
277
  };
@@ -294,10 +286,9 @@ const MaterialOneOfRenderer = ({ handleChange, schema, path, renderers, cells, r
294
286
  const cancel = useCallback(() => {
295
287
  setOpen(false);
296
288
  }, [setOpen]);
297
- const _schema = resolveSubSchemas(schema, rootSchema, 'oneOf');
298
- const oneOfRenderInfos = createCombinatorRenderInfos(_schema.oneOf, rootSchema, 'oneOf', uischema, path, uischemas);
289
+ const oneOfRenderInfos = createCombinatorRenderInfos(schema.oneOf, rootSchema, 'oneOf', uischema, path, uischemas);
299
290
  const openNewTab = (newIndex) => {
300
- handleChange(path, createDefaultValue(schema.oneOf[newIndex]));
291
+ handleChange(path, createDefaultValue(oneOfRenderInfos[newIndex].schema));
301
292
  setSelectedIndex(newIndex);
302
293
  };
303
294
  const confirm = useCallback(() => {
@@ -314,7 +305,7 @@ const MaterialOneOfRenderer = ({ handleChange, schema, path, renderers, cells, r
314
305
  }
315
306
  }, [setOpen, setSelectedIndex, data]);
316
307
  return (React.createElement(Hidden, { xsUp: !visible },
317
- React.createElement(CombinatorProperties, { schema: _schema, combinatorKeyword: 'oneOf', path: path }),
308
+ React.createElement(CombinatorProperties, { schema: schema, combinatorKeyword: 'oneOf', path: path }),
318
309
  React.createElement(Tabs, { value: selectedIndex, onChange: handleTabChange }, oneOfRenderInfos.map(oneOfRenderInfo => React.createElement(Tab, { key: oneOfRenderInfo.label, label: oneOfRenderInfo.label }))),
319
310
  oneOfRenderInfos.map((oneOfRenderInfo, oneOfIndex) => (selectedIndex === oneOfIndex && (React.createElement(JsonFormsDispatch, { key: oneOfIndex, schema: oneOfRenderInfo.schema, uischema: oneOfRenderInfo.uischema, path: path, renderers: renderers, cells: cells })))),
320
311
  React.createElement(Dialog, { open: open, onClose: handleClose, "aria-labelledby": 'alert-dialog-title', "aria-describedby": 'alert-dialog-description' },
@@ -492,7 +483,7 @@ const MaterialEnumArrayRenderer = ({ schema, visible, errors, path, options, dat
492
483
  : undefined;
493
484
  return (React.createElement(FormControlLabel, { id: option.value, key: option.value, control: React.createElement(MuiCheckbox, Object.assign({ key: 'checkbox-' + option.value, isValid: isEmpty(errors), path: optionPath, handleChange: (_childPath, newValue) => newValue
494
485
  ? addItem(path, option.value)
495
- : removeItem(path, option.value), data: checkboxValue, errors: errors, schema: schema, visible: visible }, otherProps)), label: startCase(option.label) }));
486
+ : removeItem(path, option.value), data: checkboxValue, errors: errors, schema: schema, visible: visible }, otherProps)), label: option.label }));
496
487
  })),
497
488
  React.createElement(FormHelperText, { error: true }, errors))));
498
489
  };
@@ -546,7 +537,7 @@ const ListWithDetailMasterItem = ({ index, childLabel, selected, handleSelect, r
546
537
  };
547
538
  var ListWithDetailMasterItem$1 = withJsonFormsMasterListItemProps(ListWithDetailMasterItem);
548
539
 
549
- const MaterialListWithDetailRenderer = ({ uischemas, schema, uischema, path, errors, visible, label, required, removeItems, addItem, data, renderers, cells, config }) => {
540
+ const MaterialListWithDetailRenderer = ({ uischemas, schema, uischema, path, errors, visible, label, required, removeItems, addItem, data, renderers, cells, config, rootSchema }) => {
550
541
  const [selectedIndex, setSelectedIndex] = useState(undefined);
551
542
  const handleRemoveItem = useCallback((p, value) => () => {
552
543
  removeItems(p, [value])();
@@ -559,7 +550,7 @@ const MaterialListWithDetailRenderer = ({ uischemas, schema, uischema, path, err
559
550
  }, [removeItems, setSelectedIndex]);
560
551
  const handleListItemClick = useCallback((index) => () => setSelectedIndex(index), [setSelectedIndex]);
561
552
  const handleCreateDefaultValue = useCallback(() => createDefaultValue(schema), [createDefaultValue]);
562
- const foundUISchema = useMemo(() => findUISchema(uischemas, schema, uischema.scope, path, undefined, uischema), [uischemas, schema, uischema.scope, path, uischema]);
553
+ const foundUISchema = useMemo(() => findUISchema(uischemas, schema, uischema.scope, path, undefined, uischema, rootSchema), [uischemas, schema, uischema.scope, path, uischema, rootSchema]);
563
554
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
564
555
  return (React.createElement(Hidden, { xsUp: !visible },
565
556
  React.createElement(ArrayLayoutToolbar, { label: computeLabel(label, required, appliedUiSchemaOptions.hideRequiredAsterisk), errors: errors, path: path, addItem: addItem, createDefault: handleCreateDefaultValue }),
@@ -951,6 +942,7 @@ const ExpandPanelRendererComponent = (props) => {
951
942
  const { childLabel, childPath, index, expanded, moveDown, moveUp, enableMoveDown, enableMoveUp, handleExpansion, removeItems, path, rootSchema, schema, uischema, uischemas, renderers, cells, config } = props;
952
943
  const foundUISchema = useMemo(() => findUISchema(uischemas, schema, uischema.scope, path, undefined, uischema, rootSchema), [uischemas, schema, uischema.scope, path, uischema, rootSchema]);
953
944
  const appliedUiSchemaOptions = merge({}, config, uischema.options);
945
+ const showSortButtons = appliedUiSchemaOptions.showSortButtons || appliedUiSchemaOptions.showArrayLayoutSortButtons;
954
946
  return (React.createElement(Accordion, { "aria-labelledby": labelHtmlId, expanded: expanded, onChange: handleExpansion(childPath) },
955
947
  React.createElement(AccordionSummary, { expandIcon: React.createElement(ExpandMoreIcon, null) },
956
948
  React.createElement(Grid, { container: true, alignItems: 'center' },
@@ -964,7 +956,7 @@ const ExpandPanelRendererComponent = (props) => {
964
956
  React.createElement(Grid, { container: true, justifyContent: 'flex-end' },
965
957
  React.createElement(Grid, { item: true },
966
958
  React.createElement(Grid, { container: true, direction: 'row', justifyContent: 'center', alignItems: 'center' },
967
- appliedUiSchemaOptions.showSortButtons ? (React.createElement(Fragment, null,
959
+ showSortButtons ? (React.createElement(Fragment, null,
968
960
  React.createElement(Grid, { item: true },
969
961
  React.createElement(IconButton, { onClick: moveUp(path, index), style: iconStyle, disabled: !enableMoveUp, "aria-label": `Move up`, size: 'large' },
970
962
  React.createElement(ArrowUpward, null))),
@@ -1034,12 +1026,12 @@ const MaterialArrayLayoutComponent = (props) => {
1034
1026
  };
1035
1027
  const MaterialArrayLayout$1 = React.memo(MaterialArrayLayoutComponent);
1036
1028
 
1037
- const MaterialArrayLayoutRenderer = ({ visible, enabled, id, uischema, schema, label, rootSchema, renderers, cells, data, path, errors, uischemas, addItem }) => {
1029
+ const MaterialArrayLayoutRenderer = ({ visible, addItem, ...props }) => {
1038
1030
  const addItemCb = useCallback((p, value) => addItem(p, value), [
1039
1031
  addItem
1040
1032
  ]);
1041
1033
  return (React.createElement(Hidden, { xsUp: !visible },
1042
- React.createElement(MaterialArrayLayout$1, { label: label, uischema: uischema, schema: schema, id: id, rootSchema: rootSchema, errors: errors, enabled: enabled, visible: visible, data: data, path: path, addItem: addItemCb, renderers: renderers, cells: cells, uischemas: uischemas })));
1034
+ React.createElement(MaterialArrayLayout$1, Object.assign({ visible: visible, addItem: addItemCb }, props))));
1043
1035
  };
1044
1036
  const materialArrayLayoutTester = rankWith(4, isObjectArrayWithNesting);
1045
1037
  var MaterialArrayLayout = withJsonFormsArrayLayoutProps(MaterialArrayLayoutRenderer);