@jsonforms/material-renderers 3.1.0-alpha.2 → 3.1.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.
@@ -1,19 +1,3 @@
1
- import { TextFieldProps } from '@mui/material';
2
1
  import dayjs from 'dayjs';
3
- import React from 'react';
4
- export declare const createOnChangeHandler: (path: string, handleChange: (path: string, value: any) => void, saveFormat: string | undefined) => (time: dayjs.Dayjs, textInputValue: string) => void;
2
+ export declare const createOnChangeHandler: (path: string, handleChange: (path: string, value: any) => void, saveFormat: string | undefined) => (time: dayjs.Dayjs) => void;
5
3
  export declare const getData: (data: any, saveFormat: string | undefined) => dayjs.Dayjs | null;
6
- declare type ResettableTextFieldProps = TextFieldProps & {
7
- rawValue: any;
8
- dayjsValueIsValid: boolean;
9
- valueInInputFormat: string;
10
- focused: boolean;
11
- };
12
- /**
13
- * The dayjs formatter/parser is very lenient and for example ignores additional digits and/or characters.
14
- * In these cases the input text can look vastly different than the actual value stored in the data.
15
- * The 'ResettableTextField' component adjusts the text field to reflect the actual value stored in the data
16
- * once it's no longer 'focused', i.e. when the user stops editing.
17
- */
18
- export declare const ResettableTextField: React.FC<ResettableTextFieldProps>;
19
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonforms/material-renderers",
3
- "version": "3.1.0-alpha.2",
3
+ "version": "3.1.0-beta.0",
4
4
  "description": "Material Renderer Set for JSON Forms",
5
5
  "repository": "https://github.com/eclipsesource/jsonforms",
6
6
  "bugs": "https://github.com/eclipsesource/jsonforms/issues",
@@ -82,20 +82,20 @@
82
82
  "peerDependencies": {
83
83
  "@emotion/react": "^11.4.1",
84
84
  "@emotion/styled": "^11.3.0",
85
- "@jsonforms/core": "3.1.0-alpha.2",
86
- "@jsonforms/react": "3.1.0-alpha.2",
87
- "@mui/icons-material": "~5.2.2",
88
- "@mui/material": "~5.2.2",
89
- "@mui/x-date-pickers": "^5.0.0-beta.5"
85
+ "@jsonforms/core": "3.1.0-beta.0",
86
+ "@jsonforms/react": "3.1.0-beta.0",
87
+ "@mui/icons-material": "~5.11.16",
88
+ "@mui/material": "~5.13.0",
89
+ "@mui/x-date-pickers": "^6.0.0"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@emotion/react": "^11.5.0",
93
93
  "@emotion/styled": "^11.3.0",
94
- "@jsonforms/core": "^3.1.0-alpha.2",
95
- "@jsonforms/react": "^3.1.0-alpha.2",
96
- "@mui/icons-material": "~5.2.0",
97
- "@mui/material": "~5.2.2",
98
- "@mui/x-date-pickers": "^5.0.0-beta.5",
94
+ "@jsonforms/core": "^3.1.0-beta.0",
95
+ "@jsonforms/react": "^3.1.0-beta.0",
96
+ "@mui/icons-material": "~5.11.16",
97
+ "@mui/material": "~5.13.0",
98
+ "@mui/x-date-pickers": "^6.5.0",
99
99
  "@rollup/plugin-commonjs": "^23.0.3",
100
100
  "@rollup/plugin-json": "^5.0.2",
101
101
  "@rollup/plugin-node-resolve": "^15.0.1",
@@ -132,5 +132,5 @@
132
132
  "webpack-cli": "^3.2.1",
133
133
  "webpack-dev-server": "^3.9.0"
134
134
  },
135
- "gitHead": "1e1ccad5f7ebfaf80412c8af3e422faebb12d0d5"
135
+ "gitHead": "a5fdca6fb6afa9820eabe8051401785675f53ad7"
136
136
  }
@@ -133,7 +133,9 @@ const hasEnumAndText = (schemas: JsonSchema[]) => {
133
133
  const simpleAnyOf = and(
134
134
  uiTypeIs('Control'),
135
135
  schemaMatches(
136
- (schema) => schema.hasOwnProperty('anyOf') && hasEnumAndText(schema.anyOf)
136
+ (schema) =>
137
+ Object.prototype.hasOwnProperty.call(schema, 'anyOf') &&
138
+ hasEnumAndText(schema.anyOf)
137
139
  )
138
140
  );
139
141
  export const materialAnyOfStringOrEnumControlTester: RankedTester = rankWith(
@@ -1,19 +1,19 @@
1
1
  /*
2
2
  The MIT License
3
-
3
+
4
4
  Copyright (c) 2017-2019 EclipseSource Munich
5
5
  https://github.com/eclipsesource/jsonforms
6
-
6
+
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
9
9
  in the Software without restriction, including without limitation the rights
10
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
11
  copies of the Software, and to permit persons to whom the Software is
12
12
  furnished to do so, subject to the following conditions:
13
-
13
+
14
14
  The above copyright notice and this permission notice shall be included in
15
15
  all copies or substantial portions of the Software.
16
-
16
+
17
17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -35,12 +35,7 @@ import { withJsonFormsControlProps } from '@jsonforms/react';
35
35
  import { FormHelperText, Hidden } from '@mui/material';
36
36
  import { DatePicker, LocalizationProvider } from '@mui/x-date-pickers';
37
37
  import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
38
- import {
39
- createOnChangeHandler,
40
- getData,
41
- ResettableTextField,
42
- useFocus,
43
- } from '../util';
38
+ import { createOnChangeHandler, getData, useFocus } from '../util';
44
39
 
45
40
  export const MaterialDateControl = (props: ControlProps) => {
46
41
  const [focused, onFocus, onBlur] = useFocus();
@@ -84,7 +79,6 @@ export const MaterialDateControl = (props: ControlProps) => {
84
79
  );
85
80
 
86
81
  const value = getData(data, saveFormat);
87
- const valueInInputFormat = value ? value.format(format) : '';
88
82
 
89
83
  return (
90
84
  <Hidden xsUp={!visible}>
@@ -93,40 +87,32 @@ export const MaterialDateControl = (props: ControlProps) => {
93
87
  label={label}
94
88
  value={value}
95
89
  onChange={onChange}
96
- inputFormat={format}
97
- disableMaskedInput
90
+ format={format}
98
91
  views={views}
99
92
  disabled={!enabled}
100
- componentsProps={{
101
- actionBar: {
102
- actions: (variant) =>
103
- variant === 'desktop' ? [] : ['clear', 'cancel', 'accept'],
93
+ slotProps={{
94
+ actionBar: ({ wrapperVariant }) => ({
95
+ actions:
96
+ wrapperVariant === 'desktop'
97
+ ? []
98
+ : ['clear', 'cancel', 'accept'],
99
+ }),
100
+ textField: {
101
+ id: id + '-input',
102
+ required:
103
+ required && !appliedUiSchemaOptions.hideRequiredAsterisk,
104
+ autoFocus: appliedUiSchemaOptions.focus,
105
+ error: !isValid,
106
+ fullWidth: !appliedUiSchemaOptions.trim,
107
+ inputProps: {
108
+ type: 'text',
109
+ },
110
+ InputLabelProps: data ? { shrink: true } : undefined,
111
+ onFocus: onFocus,
112
+ onBlur: onBlur,
113
+ variant: 'standard',
104
114
  },
105
115
  }}
106
- renderInput={(params) => (
107
- <ResettableTextField
108
- {...params}
109
- rawValue={data}
110
- dayjsValueIsValid={value !== null}
111
- valueInInputFormat={valueInInputFormat}
112
- focused={focused}
113
- id={id + '-input'}
114
- required={
115
- required && !appliedUiSchemaOptions.hideRequiredAsterisk
116
- }
117
- autoFocus={appliedUiSchemaOptions.focus}
118
- error={!isValid}
119
- fullWidth={!appliedUiSchemaOptions.trim}
120
- inputProps={{
121
- ...params.inputProps,
122
- type: 'text',
123
- }}
124
- InputLabelProps={data ? { shrink: true } : undefined}
125
- onFocus={onFocus}
126
- onBlur={onBlur}
127
- variant={'standard'}
128
- />
129
- )}
130
116
  />
131
117
  <FormHelperText error={!isValid && !showDescription}>
132
118
  {firstFormHelperText}
@@ -1,19 +1,19 @@
1
1
  /*
2
2
  The MIT License
3
-
3
+
4
4
  Copyright (c) 2017-2019 EclipseSource Munich
5
5
  https://github.com/eclipsesource/jsonforms
6
-
6
+
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
9
9
  in the Software without restriction, including without limitation the rights
10
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
11
  copies of the Software, and to permit persons to whom the Software is
12
12
  furnished to do so, subject to the following conditions:
13
-
13
+
14
14
  The above copyright notice and this permission notice shall be included in
15
15
  all copies or substantial portions of the Software.
16
-
16
+
17
17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -35,12 +35,7 @@ import { withJsonFormsControlProps } from '@jsonforms/react';
35
35
  import { FormHelperText, Hidden } from '@mui/material';
36
36
  import { DateTimePicker, LocalizationProvider } from '@mui/x-date-pickers';
37
37
  import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
38
- import {
39
- createOnChangeHandler,
40
- getData,
41
- ResettableTextField,
42
- useFocus,
43
- } from '../util';
38
+ import { createOnChangeHandler, getData, useFocus } from '../util';
44
39
 
45
40
  export const MaterialDateTimeControl = (props: ControlProps) => {
46
41
  const [focused, onFocus, onBlur] = useFocus();
@@ -91,7 +86,6 @@ export const MaterialDateTimeControl = (props: ControlProps) => {
91
86
  );
92
87
 
93
88
  const value = getData(data, saveFormat);
94
- const valueInInputFormat = value ? value.format(format) : '';
95
89
 
96
90
  return (
97
91
  <Hidden xsUp={!visible}>
@@ -100,41 +94,33 @@ export const MaterialDateTimeControl = (props: ControlProps) => {
100
94
  label={label}
101
95
  value={value}
102
96
  onChange={onChange}
103
- inputFormat={format}
104
- disableMaskedInput
97
+ format={format}
105
98
  ampm={!!appliedUiSchemaOptions.ampm}
106
99
  views={views}
107
100
  disabled={!enabled}
108
- componentsProps={{
109
- actionBar: {
110
- actions: (variant) =>
111
- variant === 'desktop' ? [] : ['clear', 'cancel', 'accept'],
101
+ slotProps={{
102
+ actionBar: ({ wrapperVariant }) => ({
103
+ actions:
104
+ wrapperVariant === 'desktop'
105
+ ? []
106
+ : ['clear', 'cancel', 'accept'],
107
+ }),
108
+ textField: {
109
+ id: id + '-input',
110
+ required:
111
+ required && !appliedUiSchemaOptions.hideRequiredAsterisk,
112
+ autoFocus: appliedUiSchemaOptions.focus,
113
+ error: !isValid,
114
+ fullWidth: !appliedUiSchemaOptions.trim,
115
+ inputProps: {
116
+ type: 'text',
117
+ },
118
+ InputLabelProps: data ? { shrink: true } : undefined,
119
+ onFocus: onFocus,
120
+ onBlur: onBlur,
121
+ variant: 'standard',
112
122
  },
113
123
  }}
114
- renderInput={(params) => (
115
- <ResettableTextField
116
- {...params}
117
- rawValue={data}
118
- dayjsValueIsValid={value !== null}
119
- valueInInputFormat={valueInInputFormat}
120
- focused={focused}
121
- id={id + '-input'}
122
- required={
123
- required && !appliedUiSchemaOptions.hideRequiredAsterisk
124
- }
125
- autoFocus={appliedUiSchemaOptions.focus}
126
- error={!isValid}
127
- fullWidth={!appliedUiSchemaOptions.trim}
128
- inputProps={{
129
- ...params.inputProps,
130
- type: 'text',
131
- }}
132
- InputLabelProps={data ? { shrink: true } : undefined}
133
- onFocus={onFocus}
134
- onBlur={onBlur}
135
- variant={'standard'}
136
- />
137
- )}
138
124
  />
139
125
  <FormHelperText error={!isValid && !showDescription}>
140
126
  {firstFormHelperText}
@@ -1,19 +1,19 @@
1
1
  /*
2
2
  The MIT License
3
-
3
+
4
4
  Copyright (c) 2017-2019 EclipseSource Munich
5
5
  https://github.com/eclipsesource/jsonforms
6
-
6
+
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
9
9
  in the Software without restriction, including without limitation the rights
10
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
11
  copies of the Software, and to permit persons to whom the Software is
12
12
  furnished to do so, subject to the following conditions:
13
-
13
+
14
14
  The above copyright notice and this permission notice shall be included in
15
15
  all copies or substantial portions of the Software.
16
-
16
+
17
17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -35,12 +35,7 @@ import { withJsonFormsControlProps } from '@jsonforms/react';
35
35
  import { FormHelperText, Hidden } from '@mui/material';
36
36
  import { TimePicker, LocalizationProvider } from '@mui/x-date-pickers';
37
37
  import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
38
- import {
39
- createOnChangeHandler,
40
- getData,
41
- ResettableTextField,
42
- useFocus,
43
- } from '../util';
38
+ import { createOnChangeHandler, getData, useFocus } from '../util';
44
39
 
45
40
  export const MaterialTimeControl = (props: ControlProps) => {
46
41
  const [focused, onFocus, onBlur] = useFocus();
@@ -86,8 +81,6 @@ export const MaterialTimeControl = (props: ControlProps) => {
86
81
  );
87
82
 
88
83
  const value = getData(data, saveFormat);
89
- const valueInInputFormat = value ? value.format(format) : '';
90
-
91
84
  return (
92
85
  <Hidden xsUp={!visible}>
93
86
  <LocalizationProvider dateAdapter={AdapterDayjs}>
@@ -95,41 +88,33 @@ export const MaterialTimeControl = (props: ControlProps) => {
95
88
  label={label}
96
89
  value={value}
97
90
  onChange={onChange}
98
- inputFormat={format}
99
- disableMaskedInput
91
+ format={format}
100
92
  ampm={!!appliedUiSchemaOptions.ampm}
101
93
  views={views}
102
94
  disabled={!enabled}
103
- componentsProps={{
104
- actionBar: {
105
- actions: (variant) =>
106
- variant === 'desktop' ? [] : ['clear', 'cancel', 'accept'],
95
+ slotProps={{
96
+ actionBar: ({ wrapperVariant }) => ({
97
+ actions:
98
+ wrapperVariant === 'desktop'
99
+ ? []
100
+ : ['clear', 'cancel', 'accept'],
101
+ }),
102
+ textField: {
103
+ id: id + '-input',
104
+ required:
105
+ required && !appliedUiSchemaOptions.hideRequiredAsterisk,
106
+ autoFocus: appliedUiSchemaOptions.focus,
107
+ error: !isValid,
108
+ fullWidth: !appliedUiSchemaOptions.trim,
109
+ inputProps: {
110
+ type: 'text',
111
+ },
112
+ InputLabelProps: data ? { shrink: true } : undefined,
113
+ onFocus: onFocus,
114
+ onBlur: onBlur,
115
+ variant: 'standard',
107
116
  },
108
117
  }}
109
- renderInput={(params) => (
110
- <ResettableTextField
111
- {...params}
112
- rawValue={data}
113
- dayjsValueIsValid={value !== null}
114
- valueInInputFormat={valueInInputFormat}
115
- focused={focused}
116
- id={id + '-input'}
117
- required={
118
- required && !appliedUiSchemaOptions.hideRequiredAsterisk
119
- }
120
- autoFocus={appliedUiSchemaOptions.focus}
121
- error={!isValid}
122
- fullWidth={!appliedUiSchemaOptions.trim}
123
- inputProps={{
124
- ...params.inputProps,
125
- type: 'text',
126
- }}
127
- InputLabelProps={data ? { shrink: true } : undefined}
128
- onFocus={onFocus}
129
- onBlur={onBlur}
130
- variant={'standard'}
131
- />
132
- )}
133
118
  />
134
119
  <FormHelperText error={!isValid && !showDescription}>
135
120
  {firstFormHelperText}
@@ -1,7 +1,5 @@
1
- import { TextField, TextFieldProps } from '@mui/material';
2
1
  import dayjs from 'dayjs';
3
2
  import customParsing from 'dayjs/plugin/customParseFormat';
4
- import React, { useRef } from 'react';
5
3
 
6
4
  // required for the custom save formats in the date, time and date-time pickers
7
5
  dayjs.extend(customParsing);
@@ -12,13 +10,13 @@ export const createOnChangeHandler =
12
10
  handleChange: (path: string, value: any) => void,
13
11
  saveFormat: string | undefined
14
12
  ) =>
15
- (time: dayjs.Dayjs, textInputValue: string) => {
13
+ (time: dayjs.Dayjs) => {
16
14
  if (!time) {
17
15
  handleChange(path, undefined);
18
16
  return;
19
17
  }
20
18
  const result = dayjs(time).format(saveFormat);
21
- handleChange(path, result === 'Invalid Date' ? textInputValue : result);
19
+ handleChange(path, result);
22
20
  };
23
21
 
24
22
  export const getData = (
@@ -34,61 +32,3 @@ export const getData = (
34
32
  }
35
33
  return dayjsData;
36
34
  };
37
-
38
- interface InputRef {
39
- lastInput: string;
40
- toShow: string;
41
- }
42
-
43
- type ResettableTextFieldProps = TextFieldProps & {
44
- rawValue: any;
45
- dayjsValueIsValid: boolean;
46
- valueInInputFormat: string;
47
- focused: boolean;
48
- };
49
-
50
- /**
51
- * The dayjs formatter/parser is very lenient and for example ignores additional digits and/or characters.
52
- * In these cases the input text can look vastly different than the actual value stored in the data.
53
- * The 'ResettableTextField' component adjusts the text field to reflect the actual value stored in the data
54
- * once it's no longer 'focused', i.e. when the user stops editing.
55
- */
56
- export const ResettableTextField: React.FC<ResettableTextFieldProps> = ({
57
- rawValue,
58
- dayjsValueIsValid,
59
- valueInInputFormat,
60
- focused,
61
- inputProps,
62
- ...props
63
- }) => {
64
- const value = useRef<InputRef>({
65
- lastInput: inputProps?.value,
66
- toShow: inputProps?.value,
67
- });
68
- if (!focused) {
69
- // The input text is not focused, therefore let's show the value actually stored in the data
70
- if (!dayjsValueIsValid) {
71
- // pass through the "raw" value in case it can't be formatted by dayjs
72
- value.current.toShow =
73
- typeof rawValue === 'string' ||
74
- rawValue === null ||
75
- rawValue === undefined
76
- ? rawValue
77
- : JSON.stringify(rawValue);
78
- } else {
79
- // otherwise use the specified format
80
- value.current.toShow = valueInInputFormat;
81
- }
82
- }
83
- if (focused && inputProps?.value !== value.current.lastInput) {
84
- // Show the current text the user is typing into the text input
85
- value.current.lastInput = inputProps?.value;
86
- value.current.toShow = inputProps?.value;
87
- }
88
- return (
89
- <TextField
90
- {...props}
91
- inputProps={{ ...inputProps, value: value.current.toShow || '' }}
92
- />
93
- );
94
- };
package/src/util/index.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  /*
2
2
  The MIT License
3
-
3
+
4
4
  Copyright (c) 2017-2019 EclipseSource Munich
5
5
  https://github.com/eclipsesource/jsonforms
6
-
6
+
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
9
9
  in the Software without restriction, including without limitation the rights
10
10
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
11
  copies of the Software, and to permit persons to whom the Software is
12
12
  furnished to do so, subject to the following conditions:
13
-
13
+
14
14
  The above copyright notice and this permission notice shall be included in
15
15
  all copies or substantial portions of the Software.
16
-
16
+
17
17
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
18
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
19
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE