@jsonforms/material-renderers 3.6.0-alpha.1 → 3.6.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.
- package/lib/jsonforms-react-material.cjs.js +25 -13
- package/lib/jsonforms-react-material.cjs.js.map +1 -1
- package/lib/jsonforms-react-material.esm.js +22 -12
- package/lib/jsonforms-react-material.esm.js.map +1 -1
- package/lib/util/debounce.d.ts +1 -1
- package/package.json +5 -5
- package/src/controls/MaterialAnyOfStringOrEnumControl.tsx +14 -2
- package/src/controls/MaterialNativeControl.tsx +9 -5
- package/src/mui-controls/MuiInputInteger.tsx +13 -2
- package/src/mui-controls/MuiInputNumber.tsx +13 -2
- package/src/mui-controls/MuiInputNumberFormat.tsx +13 -2
- package/src/mui-controls/MuiInputText.tsx +8 -1
- package/src/util/debounce.ts +12 -5
|
@@ -456,12 +456,17 @@ function useInputComponent() {
|
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
const eventToValue$3 = (ev) => ev.target.value;
|
|
459
|
-
const useDebouncedChange = (handleChange, defaultValue, data, path, eventToValueFunction = eventToValue$3, timeout = 300) => {
|
|
459
|
+
const useDebouncedChange = (handleChange, defaultValue, data, path, eventToValueFunction = eventToValue$3, timeout = 300, flushOnBlur = false, focused = false) => {
|
|
460
460
|
const [input, setInput] = useState(data ?? defaultValue);
|
|
461
461
|
useEffect(() => {
|
|
462
462
|
setInput(data ?? defaultValue);
|
|
463
463
|
}, [data]);
|
|
464
464
|
const debouncedUpdate = useCallback(debounce((newValue) => handleChange(path, newValue), timeout), [handleChange, path, timeout]);
|
|
465
|
+
useEffect(() => {
|
|
466
|
+
if (!focused && flushOnBlur) {
|
|
467
|
+
debouncedUpdate.flush();
|
|
468
|
+
}
|
|
469
|
+
}, [focused, flushOnBlur, debouncedUpdate]);
|
|
465
470
|
const onChange = useCallback((ev) => {
|
|
466
471
|
const newValue = eventToValueFunction(ev);
|
|
467
472
|
setInput(newValue ?? defaultValue);
|
|
@@ -481,26 +486,29 @@ const i18nDefaults = {
|
|
|
481
486
|
const toNumber$1 = (value) => value === '' ? undefined : parseInt(value, 10);
|
|
482
487
|
const eventToValue$2 = (ev) => toNumber$1(ev.target.value);
|
|
483
488
|
const MuiInputInteger = React.memo(function MuiInputInteger(props) {
|
|
489
|
+
const [focused, onFocus, onBlur] = useFocus();
|
|
484
490
|
const { data, className, id, enabled, uischema, isValid, path, handleChange, config, label, } = props;
|
|
485
491
|
const InputComponent = useInputComponent();
|
|
486
492
|
const inputProps = { step: '1' };
|
|
487
493
|
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
488
|
-
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path, eventToValue$2);
|
|
489
|
-
return (React.createElement(InputComponent, { label: label, type: 'number', value: inputValue, onChange: onChange, className: className, id: id, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, inputProps: inputProps, fullWidth: true, error: !isValid }));
|
|
494
|
+
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path, eventToValue$2, undefined, true, focused);
|
|
495
|
+
return (React.createElement(InputComponent, { label: label, type: 'number', value: inputValue, onFocus: onFocus, onBlur: onBlur, onChange: onChange, className: className, id: id, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, inputProps: inputProps, fullWidth: true, error: !isValid }));
|
|
490
496
|
});
|
|
491
497
|
|
|
492
498
|
const toNumber = (value) => value === '' ? undefined : parseFloat(value);
|
|
493
499
|
const eventToValue$1 = (ev) => toNumber(ev.target.value);
|
|
494
500
|
const MuiInputNumber = React.memo(function MuiInputNumber(props) {
|
|
501
|
+
const [focused, onFocus, onBlur] = useFocus();
|
|
495
502
|
const { data, className, id, enabled, uischema, isValid, path, handleChange, config, label, } = props;
|
|
496
503
|
const InputComponent = useInputComponent();
|
|
497
504
|
const inputProps = { step: '0.1' };
|
|
498
505
|
const appliedUiSchemaOptions = merge({}, config, uischema.options);
|
|
499
|
-
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path, eventToValue$1);
|
|
500
|
-
return (React.createElement(InputComponent, { type: 'number', label: label, value: inputValue, onChange: onChange, className: className, id: id, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, inputProps: inputProps, fullWidth: true, error: !isValid }));
|
|
506
|
+
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path, eventToValue$1, undefined, true, focused);
|
|
507
|
+
return (React.createElement(InputComponent, { type: 'number', label: label, value: inputValue, onChange: onChange, onFocus: onFocus, onBlur: onBlur, className: className, id: id, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, inputProps: inputProps, fullWidth: true, error: !isValid }));
|
|
501
508
|
});
|
|
502
509
|
|
|
503
510
|
const MuiInputNumberFormat = React.memo(function MuiInputNumberFormat(props) {
|
|
511
|
+
const [focused, onFocus, onBlur] = useFocus();
|
|
504
512
|
const { className, id, enabled, uischema, isValid, path, handleChange, schema, config, label, } = props;
|
|
505
513
|
const InputComponent = useInputComponent();
|
|
506
514
|
const maxLength = schema.maxLength;
|
|
@@ -514,12 +522,13 @@ const MuiInputNumberFormat = React.memo(function MuiInputNumberFormat(props) {
|
|
|
514
522
|
}
|
|
515
523
|
const formattedNumber = props.toFormatted(props.data);
|
|
516
524
|
const validStringNumber = useCallback((ev) => props.fromFormatted(ev.currentTarget.value), [props.fromFormatted]);
|
|
517
|
-
const [inputValue, onChange] = useDebouncedChange(handleChange, '', formattedNumber, path, validStringNumber);
|
|
518
|
-
return (React.createElement(InputComponent, { type: 'text', value: inputValue, onChange: onChange, className: className, id: id, label: label, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, multiline: appliedUiSchemaOptions.multi, fullWidth: !appliedUiSchemaOptions.trim || maxLength === undefined, inputProps: inputProps, error: !isValid }));
|
|
525
|
+
const [inputValue, onChange] = useDebouncedChange(handleChange, '', formattedNumber, path, validStringNumber, undefined, true, focused);
|
|
526
|
+
return (React.createElement(InputComponent, { type: 'text', value: inputValue, onChange: onChange, onFocus: onFocus, onBlur: onBlur, className: className, id: id, label: label, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, multiline: appliedUiSchemaOptions.multi, fullWidth: !appliedUiSchemaOptions.trim || maxLength === undefined, inputProps: inputProps, error: !isValid }));
|
|
519
527
|
});
|
|
520
528
|
|
|
521
529
|
const eventToValue = (ev) => ev.target.value === '' ? undefined : ev.target.value;
|
|
522
530
|
const MuiInputText = React.memo(function MuiInputText(props) {
|
|
531
|
+
const [focused, onFocus, onBlur] = useFocus();
|
|
523
532
|
const [showAdornment, setShowAdornment] = useState(false);
|
|
524
533
|
const { data, config, className, id, enabled, uischema, isValid, path, handleChange, schema, muiInputProps, label, inputComponent, } = props;
|
|
525
534
|
const InputComponent = useInputComponent();
|
|
@@ -536,7 +545,7 @@ const MuiInputText = React.memo(function MuiInputText(props) {
|
|
|
536
545
|
if (appliedUiSchemaOptions.trim && maxLength !== undefined) {
|
|
537
546
|
inputProps.size = maxLength;
|
|
538
547
|
}
|
|
539
|
-
const [inputText, onChange, onClear] = useDebouncedChange(handleChange, '', data, path, eventToValue);
|
|
548
|
+
const [inputText, onChange, onClear] = useDebouncedChange(handleChange, '', data, path, eventToValue, undefined, true, focused);
|
|
540
549
|
const onPointerEnter = () => setShowAdornment(true);
|
|
541
550
|
const onPointerLeave = () => setShowAdornment(false);
|
|
542
551
|
const theme = useTheme();
|
|
@@ -545,7 +554,7 @@ const MuiInputText = React.memo(function MuiInputText(props) {
|
|
|
545
554
|
theme.palette.background.default,
|
|
546
555
|
borderRadius: '50%',
|
|
547
556
|
};
|
|
548
|
-
return (React.createElement(InputComponent, { label: label, type: appliedUiSchemaOptions.format === 'password' ? 'password' : 'text', value: inputText, onChange: onChange, className: className, id: id, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, multiline: appliedUiSchemaOptions.multi, fullWidth: !appliedUiSchemaOptions.trim || maxLength === undefined, inputProps: inputProps, error: !isValid, onPointerEnter: onPointerEnter, onPointerLeave: onPointerLeave, endAdornment: React.createElement(InputAdornment, { position: 'end', style: {
|
|
557
|
+
return (React.createElement(InputComponent, { label: label, type: appliedUiSchemaOptions.format === 'password' ? 'password' : 'text', value: inputText, onChange: onChange, className: className, onBlur: onBlur, onFocus: onFocus, id: id, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, multiline: appliedUiSchemaOptions.multi, fullWidth: !appliedUiSchemaOptions.trim || maxLength === undefined, inputProps: inputProps, error: !isValid, onPointerEnter: onPointerEnter, onPointerLeave: onPointerLeave, endAdornment: React.createElement(InputAdornment, { position: 'end', style: {
|
|
549
558
|
display: !showAdornment || !enabled || data === undefined
|
|
550
559
|
? 'none'
|
|
551
560
|
: 'flex',
|
|
@@ -774,6 +783,7 @@ const MaterialInputControl = (props) => {
|
|
|
774
783
|
const findEnumSchema = (schemas) => schemas.find((s) => s.enum !== undefined && (s.type === 'string' || s.type === undefined));
|
|
775
784
|
const findTextSchema = (schemas) => schemas.find((s) => s.type === 'string' && s.enum === undefined);
|
|
776
785
|
const MuiAutocompleteInputText = (props) => {
|
|
786
|
+
const [focused, onFocus, onBlur] = useFocus();
|
|
777
787
|
const { data, config, className, id, enabled, uischema, isValid, path, handleChange, schema, label, } = props;
|
|
778
788
|
const InputComponent = useInputComponent();
|
|
779
789
|
const enumSchema = findEnumSchema(schema.anyOf);
|
|
@@ -791,9 +801,9 @@ const MuiAutocompleteInputText = (props) => {
|
|
|
791
801
|
propMemo.list = props.id + 'datalist';
|
|
792
802
|
return propMemo;
|
|
793
803
|
}, [appliedUiSchemaOptions, props.id]);
|
|
794
|
-
const [inputText, onChange] = useDebouncedChange(handleChange, '', data, path);
|
|
804
|
+
const [inputText, onChange] = useDebouncedChange(handleChange, '', data, path, undefined, undefined, true, focused);
|
|
795
805
|
const dataList = (React.createElement("datalist", { id: props.id + 'datalist' }, enumSchema.enum.map((optionValue) => (React.createElement("option", { value: optionValue, key: optionValue })))));
|
|
796
|
-
return (React.createElement(InputComponent, { type: 'text', value: inputText, onChange: onChange, className: className, id: id, label: label, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, fullWidth: !appliedUiSchemaOptions.trim || maxLength === undefined, inputProps: inputProps, error: !isValid, endAdornment: dataList }));
|
|
806
|
+
return (React.createElement(InputComponent, { type: 'text', value: inputText, onChange: onChange, onFocus: onFocus, onBlur: onBlur, className: className, id: id, label: label, disabled: !enabled, autoFocus: appliedUiSchemaOptions.focus, fullWidth: !appliedUiSchemaOptions.trim || maxLength === undefined, inputProps: inputProps, error: !isValid, endAdornment: dataList }));
|
|
797
807
|
};
|
|
798
808
|
class MaterialAnyOfStringOrEnumControl extends Control {
|
|
799
809
|
render() {
|
|
@@ -1019,7 +1029,7 @@ const MaterialNativeControl = (props) => {
|
|
|
1019
1029
|
const { id, errors, label, schema, description, enabled, visible, required, path, handleChange, data, config, } = props;
|
|
1020
1030
|
const isValid = errors.length === 0;
|
|
1021
1031
|
const appliedUiSchemaOptions = merge({}, config, props.uischema.options);
|
|
1022
|
-
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path);
|
|
1032
|
+
const [inputValue, onChange] = useDebouncedChange(handleChange, '', data, path, undefined, undefined, true, focused);
|
|
1023
1033
|
const fieldType = appliedUiSchemaOptions.format ?? schema.format;
|
|
1024
1034
|
const showDescription = !isDescriptionHidden(visible, description, focused, appliedUiSchemaOptions.showUnfocusedDescription);
|
|
1025
1035
|
if (!visible) {
|