@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
|
@@ -579,14 +579,21 @@ function useInputComponent() {
|
|
|
579
579
|
}
|
|
580
580
|
|
|
581
581
|
var eventToValue$3 = function (ev) { return ev.target.value; };
|
|
582
|
-
var useDebouncedChange = function (handleChange, defaultValue, data, path, eventToValueFunction, timeout) {
|
|
582
|
+
var useDebouncedChange = function (handleChange, defaultValue, data, path, eventToValueFunction, timeout, flushOnBlur, focused) {
|
|
583
583
|
if (eventToValueFunction === void 0) { eventToValueFunction = eventToValue$3; }
|
|
584
584
|
if (timeout === void 0) { timeout = 300; }
|
|
585
|
+
if (flushOnBlur === void 0) { flushOnBlur = false; }
|
|
586
|
+
if (focused === void 0) { focused = false; }
|
|
585
587
|
var _a = React.useState(data !== null && data !== void 0 ? data : defaultValue), input = _a[0], setInput = _a[1];
|
|
586
588
|
React.useEffect(function () {
|
|
587
589
|
setInput(data !== null && data !== void 0 ? data : defaultValue);
|
|
588
590
|
}, [data]);
|
|
589
591
|
var debouncedUpdate = React.useCallback(debounce__default["default"](function (newValue) { return handleChange(path, newValue); }, timeout), [handleChange, path, timeout]);
|
|
592
|
+
React.useEffect(function () {
|
|
593
|
+
if (!focused && flushOnBlur) {
|
|
594
|
+
debouncedUpdate.flush();
|
|
595
|
+
}
|
|
596
|
+
}, [focused, flushOnBlur, debouncedUpdate]);
|
|
590
597
|
var onChange = React.useCallback(function (ev) {
|
|
591
598
|
var newValue = eventToValueFunction(ev);
|
|
592
599
|
setInput(newValue !== null && newValue !== void 0 ? newValue : defaultValue);
|
|
@@ -608,12 +615,13 @@ var toNumber$1 = function (value) {
|
|
|
608
615
|
};
|
|
609
616
|
var eventToValue$2 = function (ev) { return toNumber$1(ev.target.value); };
|
|
610
617
|
var MuiInputInteger = React__default["default"].memo(function MuiInputInteger(props) {
|
|
618
|
+
var _a = useFocus(), focused = _a[0], onFocus = _a[1], onBlur = _a[2];
|
|
611
619
|
var data = props.data, className = props.className, id = props.id, enabled = props.enabled, uischema = props.uischema, isValid = props.isValid, path = props.path, handleChange = props.handleChange, config = props.config, label = props.label;
|
|
612
620
|
var InputComponent = useInputComponent();
|
|
613
621
|
var inputProps = { step: '1' };
|
|
614
622
|
var appliedUiSchemaOptions = merge__default["default"]({}, config, uischema.options);
|
|
615
|
-
var
|
|
616
|
-
return (React__default["default"].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 }));
|
|
623
|
+
var _b = useDebouncedChange(handleChange, '', data, path, eventToValue$2, undefined, true, focused), inputValue = _b[0], onChange = _b[1];
|
|
624
|
+
return (React__default["default"].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 }));
|
|
617
625
|
});
|
|
618
626
|
|
|
619
627
|
var toNumber = function (value) {
|
|
@@ -621,15 +629,17 @@ var toNumber = function (value) {
|
|
|
621
629
|
};
|
|
622
630
|
var eventToValue$1 = function (ev) { return toNumber(ev.target.value); };
|
|
623
631
|
var MuiInputNumber = React__default["default"].memo(function MuiInputNumber(props) {
|
|
632
|
+
var _a = useFocus(), focused = _a[0], onFocus = _a[1], onBlur = _a[2];
|
|
624
633
|
var data = props.data, className = props.className, id = props.id, enabled = props.enabled, uischema = props.uischema, isValid = props.isValid, path = props.path, handleChange = props.handleChange, config = props.config, label = props.label;
|
|
625
634
|
var InputComponent = useInputComponent();
|
|
626
635
|
var inputProps = { step: '0.1' };
|
|
627
636
|
var appliedUiSchemaOptions = merge__default["default"]({}, config, uischema.options);
|
|
628
|
-
var
|
|
629
|
-
return (React__default["default"].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 }));
|
|
637
|
+
var _b = useDebouncedChange(handleChange, '', data, path, eventToValue$1, undefined, true, focused), inputValue = _b[0], onChange = _b[1];
|
|
638
|
+
return (React__default["default"].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 }));
|
|
630
639
|
});
|
|
631
640
|
|
|
632
641
|
var MuiInputNumberFormat = React__default["default"].memo(function MuiInputNumberFormat(props) {
|
|
642
|
+
var _a = useFocus(), focused = _a[0], onFocus = _a[1], onBlur = _a[2];
|
|
633
643
|
var className = props.className, id = props.id, enabled = props.enabled, uischema = props.uischema, isValid = props.isValid, path = props.path, handleChange = props.handleChange, schema = props.schema, config = props.config, label = props.label;
|
|
634
644
|
var InputComponent = useInputComponent();
|
|
635
645
|
var maxLength = schema.maxLength;
|
|
@@ -643,8 +653,8 @@ var MuiInputNumberFormat = React__default["default"].memo(function MuiInputNumbe
|
|
|
643
653
|
}
|
|
644
654
|
var formattedNumber = props.toFormatted(props.data);
|
|
645
655
|
var validStringNumber = React.useCallback(function (ev) { return props.fromFormatted(ev.currentTarget.value); }, [props.fromFormatted]);
|
|
646
|
-
var
|
|
647
|
-
return (React__default["default"].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 }));
|
|
656
|
+
var _b = useDebouncedChange(handleChange, '', formattedNumber, path, validStringNumber, undefined, true, focused), inputValue = _b[0], onChange = _b[1];
|
|
657
|
+
return (React__default["default"].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 }));
|
|
648
658
|
});
|
|
649
659
|
|
|
650
660
|
var eventToValue = function (ev) {
|
|
@@ -652,7 +662,8 @@ var eventToValue = function (ev) {
|
|
|
652
662
|
};
|
|
653
663
|
var MuiInputText = React__default["default"].memo(function MuiInputText(props) {
|
|
654
664
|
var _a, _b, _c;
|
|
655
|
-
var _d =
|
|
665
|
+
var _d = useFocus(), focused = _d[0], onFocus = _d[1], onBlur = _d[2];
|
|
666
|
+
var _e = React.useState(false), showAdornment = _e[0], setShowAdornment = _e[1];
|
|
656
667
|
var data = props.data, config = props.config, className = props.className, id = props.id, enabled = props.enabled, uischema = props.uischema, isValid = props.isValid, path = props.path, handleChange = props.handleChange, schema = props.schema, muiInputProps = props.muiInputProps, label = props.label, inputComponent = props.inputComponent;
|
|
657
668
|
var InputComponent = useInputComponent();
|
|
658
669
|
var maxLength = schema.maxLength;
|
|
@@ -668,7 +679,7 @@ var MuiInputText = React__default["default"].memo(function MuiInputText(props) {
|
|
|
668
679
|
if (appliedUiSchemaOptions.trim && maxLength !== undefined) {
|
|
669
680
|
inputProps.size = maxLength;
|
|
670
681
|
}
|
|
671
|
-
var
|
|
682
|
+
var _f = useDebouncedChange(handleChange, '', data, path, eventToValue, undefined, true, focused), inputText = _f[0], onChange = _f[1], onClear = _f[2];
|
|
672
683
|
var onPointerEnter = function () { return setShowAdornment(true); };
|
|
673
684
|
var onPointerLeave = function () { return setShowAdornment(false); };
|
|
674
685
|
var theme = material.useTheme();
|
|
@@ -677,7 +688,7 @@ var MuiInputText = React__default["default"].memo(function MuiInputText(props) {
|
|
|
677
688
|
theme.palette.background.default,
|
|
678
689
|
borderRadius: '50%',
|
|
679
690
|
};
|
|
680
|
-
return (React__default["default"].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__default["default"].createElement(material.InputAdornment, { position: 'end', style: {
|
|
691
|
+
return (React__default["default"].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__default["default"].createElement(material.InputAdornment, { position: 'end', style: {
|
|
681
692
|
display: !showAdornment || !enabled || data === undefined
|
|
682
693
|
? 'none'
|
|
683
694
|
: 'flex',
|
|
@@ -932,6 +943,7 @@ var findTextSchema = function (schemas) {
|
|
|
932
943
|
return schemas.find(function (s) { return s.type === 'string' && s.enum === undefined; });
|
|
933
944
|
};
|
|
934
945
|
var MuiAutocompleteInputText = function (props) {
|
|
946
|
+
var _a = useFocus(), focused = _a[0], onFocus = _a[1], onBlur = _a[2];
|
|
935
947
|
var data = props.data, config = props.config, className = props.className, id = props.id, enabled = props.enabled, uischema = props.uischema, isValid = props.isValid, path = props.path, handleChange = props.handleChange, schema = props.schema, label = props.label;
|
|
936
948
|
var InputComponent = useInputComponent();
|
|
937
949
|
var enumSchema = findEnumSchema(schema.anyOf);
|
|
@@ -949,9 +961,9 @@ var MuiAutocompleteInputText = function (props) {
|
|
|
949
961
|
propMemo.list = props.id + 'datalist';
|
|
950
962
|
return propMemo;
|
|
951
963
|
}, [appliedUiSchemaOptions, props.id]);
|
|
952
|
-
var
|
|
964
|
+
var _b = useDebouncedChange(handleChange, '', data, path, undefined, undefined, true, focused), inputText = _b[0], onChange = _b[1];
|
|
953
965
|
var dataList = (React__default["default"].createElement("datalist", { id: props.id + 'datalist' }, enumSchema.enum.map(function (optionValue) { return (React__default["default"].createElement("option", { value: optionValue, key: optionValue })); })));
|
|
954
|
-
return (React__default["default"].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 }));
|
|
966
|
+
return (React__default["default"].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 }));
|
|
955
967
|
};
|
|
956
968
|
var MaterialAnyOfStringOrEnumControl = (function (_super) {
|
|
957
969
|
__extends(MaterialAnyOfStringOrEnumControl, _super);
|
|
@@ -1199,7 +1211,7 @@ var MaterialNativeControl = function (props) {
|
|
|
1199
1211
|
var id = props.id, errors = props.errors, label = props.label, schema = props.schema, description = props.description, enabled = props.enabled, visible = props.visible, required = props.required, path = props.path, handleChange = props.handleChange, data = props.data, config = props.config;
|
|
1200
1212
|
var isValid = errors.length === 0;
|
|
1201
1213
|
var appliedUiSchemaOptions = merge__default["default"]({}, config, props.uischema.options);
|
|
1202
|
-
var _c = useDebouncedChange(handleChange, '', data, path), inputValue = _c[0], onChange = _c[1];
|
|
1214
|
+
var _c = useDebouncedChange(handleChange, '', data, path, undefined, undefined, true, focused), inputValue = _c[0], onChange = _c[1];
|
|
1203
1215
|
var fieldType = (_a = appliedUiSchemaOptions.format) !== null && _a !== void 0 ? _a : schema.format;
|
|
1204
1216
|
var showDescription = !core.isDescriptionHidden(visible, description, focused, appliedUiSchemaOptions.showUnfocusedDescription);
|
|
1205
1217
|
if (!visible) {
|