@jsonforms/material-renderers 3.6.0-alpha.1 → 3.6.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 +1 @@
1
- export declare const useDebouncedChange: (handleChange: (path: string, value: any) => void, defaultValue: any, data: any, path: string, eventToValueFunction?: (ev: any) => any, timeout?: number) => [any, React.ChangeEventHandler, () => void];
1
+ export declare const useDebouncedChange: (handleChange: (path: string, value: any) => void, defaultValue: any, data: any, path: string, eventToValueFunction?: (ev: any) => any, timeout?: number, flushOnBlur?: boolean, focused?: boolean) => [any, React.ChangeEventHandler, () => void];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsonforms/material-renderers",
3
- "version": "3.6.0-alpha.1",
3
+ "version": "3.6.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",
@@ -73,8 +73,8 @@
73
73
  "peerDependencies": {
74
74
  "@emotion/react": "^11.4.1",
75
75
  "@emotion/styled": "^11.3.0",
76
- "@jsonforms/core": "3.6.0-alpha.1",
77
- "@jsonforms/react": "3.6.0-alpha.1",
76
+ "@jsonforms/core": "3.6.0",
77
+ "@jsonforms/react": "3.6.0",
78
78
  "@mui/icons-material": "^5.11.16 || ^6.0.0",
79
79
  "@mui/material": "^5.13.0 || ^6.0.0",
80
80
  "@mui/x-date-pickers": "^6.0.0 || ^7.0.0",
@@ -126,8 +126,8 @@
126
126
  "webpack": "^5.78.0",
127
127
  "webpack-cli": "^5.1.4",
128
128
  "webpack-dev-server": "^4.15.1",
129
- "@jsonforms/core": "3.6.0-alpha.1",
130
- "@jsonforms/react": "3.6.0-alpha.1"
129
+ "@jsonforms/core": "3.6.0",
130
+ "@jsonforms/react": "3.6.0"
131
131
  },
132
132
  "scripts": {
133
133
  "build": "rollup -c rollup.config.js",
@@ -38,7 +38,12 @@ import { Control, withJsonFormsControlProps } from '@jsonforms/react';
38
38
  import { InputBaseComponentProps } from '@mui/material';
39
39
  import merge from 'lodash/merge';
40
40
  import React, { useMemo } from 'react';
41
- import { useDebouncedChange, useInputComponent, WithInputProps } from '../util';
41
+ import {
42
+ useDebouncedChange,
43
+ useInputComponent,
44
+ WithInputProps,
45
+ useFocus,
46
+ } from '../util';
42
47
  import { MaterialInputControl } from './MaterialInputControl';
43
48
 
44
49
  const findEnumSchema = (schemas: JsonSchema[]) =>
@@ -51,6 +56,7 @@ const findTextSchema = (schemas: JsonSchema[]) =>
51
56
  const MuiAutocompleteInputText = (
52
57
  props: EnumCellProps & WithClassname & WithInputProps
53
58
  ) => {
59
+ const [focused, onFocus, onBlur] = useFocus();
54
60
  const {
55
61
  data,
56
62
  config,
@@ -87,7 +93,11 @@ const MuiAutocompleteInputText = (
87
93
  handleChange,
88
94
  '',
89
95
  data,
90
- path
96
+ path,
97
+ undefined,
98
+ undefined,
99
+ true,
100
+ focused
91
101
  );
92
102
 
93
103
  const dataList = (
@@ -102,6 +112,8 @@ const MuiAutocompleteInputText = (
102
112
  type='text'
103
113
  value={inputText}
104
114
  onChange={onChange}
115
+ onFocus={onFocus}
116
+ onBlur={onBlur}
105
117
  className={className}
106
118
  id={id}
107
119
  label={label}
@@ -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
@@ -60,7 +60,11 @@ export const MaterialNativeControl = (props: ControlProps) => {
60
60
  handleChange,
61
61
  '',
62
62
  data,
63
- path
63
+ path,
64
+ undefined,
65
+ undefined,
66
+ true,
67
+ focused
64
68
  );
65
69
  const fieldType = appliedUiSchemaOptions.format ?? schema.format;
66
70
  const showDescription = !isDescriptionHidden(
@@ -25,7 +25,12 @@
25
25
  import React from 'react';
26
26
  import { CellProps, WithClassname } from '@jsonforms/core';
27
27
  import merge from 'lodash/merge';
28
- import { useDebouncedChange, useInputComponent, WithInputProps } from '../util';
28
+ import {
29
+ useDebouncedChange,
30
+ useInputComponent,
31
+ WithInputProps,
32
+ useFocus,
33
+ } from '../util';
29
34
 
30
35
  const toNumber = (value: string) =>
31
36
  value === '' ? undefined : parseInt(value, 10);
@@ -34,6 +39,7 @@ const eventToValue = (ev: any) => toNumber(ev.target.value);
34
39
  export const MuiInputInteger = React.memo(function MuiInputInteger(
35
40
  props: CellProps & WithClassname & WithInputProps
36
41
  ) {
42
+ const [focused, onFocus, onBlur] = useFocus();
37
43
  const {
38
44
  data,
39
45
  className,
@@ -56,7 +62,10 @@ export const MuiInputInteger = React.memo(function MuiInputInteger(
56
62
  '',
57
63
  data,
58
64
  path,
59
- eventToValue
65
+ eventToValue,
66
+ undefined,
67
+ true,
68
+ focused
60
69
  );
61
70
 
62
71
  return (
@@ -64,6 +73,8 @@ export const MuiInputInteger = React.memo(function MuiInputInteger(
64
73
  label={label}
65
74
  type='number'
66
75
  value={inputValue}
76
+ onFocus={onFocus}
77
+ onBlur={onBlur}
67
78
  onChange={onChange}
68
79
  className={className}
69
80
  id={id}
@@ -25,7 +25,12 @@
25
25
  import React from 'react';
26
26
  import { CellProps, WithClassname } from '@jsonforms/core';
27
27
  import merge from 'lodash/merge';
28
- import { useDebouncedChange, useInputComponent, WithInputProps } from '../util';
28
+ import {
29
+ useDebouncedChange,
30
+ useInputComponent,
31
+ WithInputProps,
32
+ useFocus,
33
+ } from '../util';
29
34
 
30
35
  const toNumber = (value: string) =>
31
36
  value === '' ? undefined : parseFloat(value);
@@ -33,6 +38,7 @@ const eventToValue = (ev: any) => toNumber(ev.target.value);
33
38
  export const MuiInputNumber = React.memo(function MuiInputNumber(
34
39
  props: CellProps & WithClassname & WithInputProps
35
40
  ) {
41
+ const [focused, onFocus, onBlur] = useFocus();
36
42
  const {
37
43
  data,
38
44
  className,
@@ -54,7 +60,10 @@ export const MuiInputNumber = React.memo(function MuiInputNumber(
54
60
  '',
55
61
  data,
56
62
  path,
57
- eventToValue
63
+ eventToValue,
64
+ undefined,
65
+ true,
66
+ focused
58
67
  );
59
68
 
60
69
  return (
@@ -63,6 +72,8 @@ export const MuiInputNumber = React.memo(function MuiInputNumber(
63
72
  label={label}
64
73
  value={inputValue}
65
74
  onChange={onChange}
75
+ onFocus={onFocus}
76
+ onBlur={onBlur}
66
77
  className={className}
67
78
  id={id}
68
79
  disabled={!enabled}
@@ -25,11 +25,17 @@
25
25
  import React, { useCallback } from 'react';
26
26
  import { CellProps, Formatted, WithClassname } from '@jsonforms/core';
27
27
  import merge from 'lodash/merge';
28
- import { useDebouncedChange, useInputComponent, WithInputProps } from '../util';
28
+ import {
29
+ useDebouncedChange,
30
+ useInputComponent,
31
+ WithInputProps,
32
+ useFocus,
33
+ } from '../util';
29
34
 
30
35
  export const MuiInputNumberFormat = React.memo(function MuiInputNumberFormat(
31
36
  props: CellProps & WithClassname & Formatted<number> & WithInputProps
32
37
  ) {
38
+ const [focused, onFocus, onBlur] = useFocus();
33
39
  const {
34
40
  className,
35
41
  id,
@@ -62,7 +68,10 @@ export const MuiInputNumberFormat = React.memo(function MuiInputNumberFormat(
62
68
  '',
63
69
  formattedNumber,
64
70
  path,
65
- validStringNumber
71
+ validStringNumber,
72
+ undefined,
73
+ true,
74
+ focused
66
75
  );
67
76
 
68
77
  return (
@@ -70,6 +79,8 @@ export const MuiInputNumberFormat = React.memo(function MuiInputNumberFormat(
70
79
  type='text'
71
80
  value={inputValue}
72
81
  onChange={onChange}
82
+ onFocus={onFocus}
83
+ onBlur={onBlur}
73
84
  className={className}
74
85
  id={id}
75
86
  label={label}
@@ -38,6 +38,7 @@ import {
38
38
  WithInputProps,
39
39
  useDebouncedChange,
40
40
  useInputComponent,
41
+ useFocus,
41
42
  } from '../util';
42
43
 
43
44
  interface MuiTextInputProps {
@@ -51,6 +52,7 @@ const eventToValue = (ev: any) =>
51
52
  export const MuiInputText = React.memo(function MuiInputText(
52
53
  props: CellProps & WithClassname & MuiTextInputProps & WithInputProps
53
54
  ) {
55
+ const [focused, onFocus, onBlur] = useFocus();
54
56
  const [showAdornment, setShowAdornment] = useState(false);
55
57
  const {
56
58
  data,
@@ -88,7 +90,10 @@ export const MuiInputText = React.memo(function MuiInputText(
88
90
  '',
89
91
  data,
90
92
  path,
91
- eventToValue
93
+ eventToValue,
94
+ undefined,
95
+ true,
96
+ focused
92
97
  );
93
98
  const onPointerEnter = () => setShowAdornment(true);
94
99
  const onPointerLeave = () => setShowAdornment(false);
@@ -109,6 +114,8 @@ export const MuiInputText = React.memo(function MuiInputText(
109
114
  value={inputText}
110
115
  onChange={onChange}
111
116
  className={className}
117
+ onBlur={onBlur}
118
+ onFocus={onFocus}
112
119
  id={id}
113
120
  disabled={!enabled}
114
121
  autoFocus={appliedUiSchemaOptions.focus}
@@ -1,19 +1,19 @@
1
1
  /*
2
2
  The MIT License
3
-
3
+
4
4
  Copyright (c) 2021 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
@@ -32,7 +32,9 @@ export const useDebouncedChange = (
32
32
  data: any,
33
33
  path: string,
34
34
  eventToValueFunction: (ev: any) => any = eventToValue,
35
- timeout = 300
35
+ timeout = 300,
36
+ flushOnBlur = false,
37
+ focused = false
36
38
  ): [any, React.ChangeEventHandler, () => void] => {
37
39
  const [input, setInput] = useState(data ?? defaultValue);
38
40
  useEffect(() => {
@@ -42,6 +44,11 @@ export const useDebouncedChange = (
42
44
  debounce((newValue: string) => handleChange(path, newValue), timeout),
43
45
  [handleChange, path, timeout]
44
46
  );
47
+ useEffect(() => {
48
+ if (!focused && flushOnBlur) {
49
+ debouncedUpdate.flush();
50
+ }
51
+ }, [focused, flushOnBlur, debouncedUpdate]);
45
52
  const onChange = useCallback(
46
53
  (ev: any) => {
47
54
  const newValue = eventToValueFunction(ev);