@pdg/react-form 1.0.17 → 1.0.19
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/dist/index.js
CHANGED
|
@@ -7404,7 +7404,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7404
7404
|
// ID --------------------------------------------------------------------------------------------------------------
|
|
7405
7405
|
var initVariant = _a.variant, initSize = _a.size, initColor = _a.color, initFocused = _a.focused, initLabelShrink = _a.labelShrink, initFullWidth = _a.fullWidth,
|
|
7406
7406
|
//----------------------------------------------------------------------------------------------------------------
|
|
7407
|
-
name = _a.name, labelIcon = _a.labelIcon, label = _a.label, initLoading = _a.loading, initItems = _a.items, initValue = _a.value, initError = _a.error, initHelperText = _a.helperText, initDisabled = _a.disabled, readOnly = _a.readOnly, required = _a.required, exceptValue = _a.exceptValue, width = _a.width, placeholder = _a.placeholder, multiple = _a.multiple, formValueSeparator = _a.formValueSeparator, formValueSort = _a.formValueSort, disablePortal = _a.disablePortal, noOptionsText = _a.noOptionsText, loadingText = _a.loadingText, limitTags = _a.limitTags, openOnFocus = _a.openOnFocus, disableClearable = _a.disableClearable, onLoadItems = _a.onLoadItems, onRenderItem = _a.onRenderItem, onRenderTag = _a.onRenderTag, onAddItem = _a.onAddItem,
|
|
7407
|
+
name = _a.name, labelIcon = _a.labelIcon, label = _a.label, initLoading = _a.loading, initItems = _a.items, initValue = _a.value, initError = _a.error, initHelperText = _a.helperText, initDisabled = _a.disabled, readOnly = _a.readOnly, required = _a.required, exceptValue = _a.exceptValue, width = _a.width, placeholder = _a.placeholder, multiple = _a.multiple, formValueSeparator = _a.formValueSeparator, formValueSort = _a.formValueSort, disablePortal = _a.disablePortal, noOptionsText = _a.noOptionsText, loadingText = _a.loadingText, limitTags = _a.limitTags, openOnFocus = _a.openOnFocus, disableClearable = _a.disableClearable, async = _a.async, onLoadItems = _a.onLoadItems, onRenderItem = _a.onRenderItem, onRenderTag = _a.onRenderTag, onAddItem = _a.onAddItem,
|
|
7408
7408
|
//----------------------------------------------------------------------------------------------------------------
|
|
7409
7409
|
onChange = _a.onChange, onValue = _a.onValue, onValidate = _a.onValidate,
|
|
7410
7410
|
//----------------------------------------------------------------------------------------------------------------
|
|
@@ -7412,6 +7412,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7412
7412
|
var id = React.useId();
|
|
7413
7413
|
// Ref -------------------------------------------------------------------------------------------------------------
|
|
7414
7414
|
var textFieldRef = React.useRef(null);
|
|
7415
|
+
var asyncTimerRef = React.useRef(null);
|
|
7415
7416
|
// FormState -------------------------------------------------------------------------------------------------------
|
|
7416
7417
|
var _b = useFormState(), formVariant = _b.variant, formSize = _b.size, formColor = _b.color, formFocused = _b.focused, formLabelShrink = _b.labelShrink, formFullWidth = _b.fullWidth, onAddValueItem = _b.onAddValueItem, onRemoveValueItem = _b.onRemoveValueItem, onValueChange = _b.onValueChange, onValueChangeByUser = _b.onValueChangeByUser, onRequestSearchSubmit = _b.onRequestSearchSubmit;
|
|
7417
7418
|
// Memo - FormState ------------------------------------------------------------------------------------------------
|
|
@@ -7428,6 +7429,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7428
7429
|
var _f = useAutoUpdateLayoutState(initHelperText), helperText = _f[0], setHelperText = _f[1];
|
|
7429
7430
|
var _g = useAutoUpdateLayoutState(initLoading), loading = _g[0], setLoading = _g[1];
|
|
7430
7431
|
var _h = useAutoUpdateLayoutState(initDisabled), disabled = _h[0], setDisabled = _h[1];
|
|
7432
|
+
var _j = React.useState(undefined), inputValue = _j[0], setInputValue = _j[1];
|
|
7431
7433
|
// Memo --------------------------------------------------------------------------------------------------------------
|
|
7432
7434
|
var itemsValues = React.useMemo(function () {
|
|
7433
7435
|
if (items) {
|
|
@@ -7497,7 +7499,7 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7497
7499
|
return onValue ? onValue(finalValue) : finalValue;
|
|
7498
7500
|
}, [multiple, formValueSeparator, itemsValues, onValue]);
|
|
7499
7501
|
// State - value ---------------------------------------------------------------------------------------------------
|
|
7500
|
-
var
|
|
7502
|
+
var _k = useAutoUpdateLayoutState(initValue, getFinalValue), value = _k[0], setValue = _k[1];
|
|
7501
7503
|
var componentValue = React.useMemo(function () {
|
|
7502
7504
|
var finalValue = value;
|
|
7503
7505
|
if (finalValue != null) {
|
|
@@ -7527,6 +7529,13 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7527
7529
|
return multiple ? [] : null;
|
|
7528
7530
|
}
|
|
7529
7531
|
}, [value, multiple, items]);
|
|
7532
|
+
// Function ----------------------------------------------------------------------------------------------------------
|
|
7533
|
+
var showOnGetItemLoading = React.useCallback(function () {
|
|
7534
|
+
setIsOnGetItemLoading(true);
|
|
7535
|
+
}, []);
|
|
7536
|
+
var hideOnGetItemLoading = React.useCallback(function () {
|
|
7537
|
+
setIsOnGetItemLoading(false);
|
|
7538
|
+
}, []);
|
|
7530
7539
|
// Effect ----------------------------------------------------------------------------------------------------------
|
|
7531
7540
|
React.useEffect(function () {
|
|
7532
7541
|
if (value !== initValue) {
|
|
@@ -7534,13 +7543,19 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7534
7543
|
onChange(value);
|
|
7535
7544
|
onValueChange(name, value);
|
|
7536
7545
|
}
|
|
7537
|
-
if (onLoadItems) {
|
|
7538
|
-
|
|
7546
|
+
if (!async && onLoadItems) {
|
|
7547
|
+
showOnGetItemLoading();
|
|
7539
7548
|
onLoadItems().then(function (items) {
|
|
7540
7549
|
setItems(items);
|
|
7541
|
-
|
|
7550
|
+
hideOnGetItemLoading();
|
|
7542
7551
|
});
|
|
7543
7552
|
}
|
|
7553
|
+
return function () {
|
|
7554
|
+
if (asyncTimerRef.current) {
|
|
7555
|
+
clearTimeout(asyncTimerRef.current);
|
|
7556
|
+
asyncTimerRef.current = null;
|
|
7557
|
+
}
|
|
7558
|
+
};
|
|
7544
7559
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
7545
7560
|
}, []);
|
|
7546
7561
|
useFirstSkipEffect$1(function () {
|
|
@@ -7550,6 +7565,26 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7550
7565
|
onChange(value);
|
|
7551
7566
|
onValueChange(name, value);
|
|
7552
7567
|
}, [value]);
|
|
7568
|
+
React.useEffect(function () {
|
|
7569
|
+
if (async && onLoadItems && inputValue != null) {
|
|
7570
|
+
if (asyncTimerRef.current) {
|
|
7571
|
+
clearTimeout(asyncTimerRef.current);
|
|
7572
|
+
asyncTimerRef.current = null;
|
|
7573
|
+
}
|
|
7574
|
+
showOnGetItemLoading();
|
|
7575
|
+
asyncTimerRef.current = setTimeout(function () {
|
|
7576
|
+
asyncTimerRef.current = null;
|
|
7577
|
+
onLoadItems(inputValue)
|
|
7578
|
+
.then(function (items) {
|
|
7579
|
+
setItems(items);
|
|
7580
|
+
})
|
|
7581
|
+
.finally(function () {
|
|
7582
|
+
hideOnGetItemLoading();
|
|
7583
|
+
});
|
|
7584
|
+
}, 300);
|
|
7585
|
+
}
|
|
7586
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
7587
|
+
}, [async, inputValue]);
|
|
7553
7588
|
// Function - focus ------------------------------------------------------------------------------------------------
|
|
7554
7589
|
var focus = React.useCallback(function () {
|
|
7555
7590
|
var _a;
|
|
@@ -7715,7 +7750,11 @@ FormTextEditor.defaultProps = FormTextEditorDefaultProps;var FormAutocompleteDef
|
|
|
7715
7750
|
}
|
|
7716
7751
|
}, [multiple, getFinalValue, value, setValue, onValueChangeByUser, name, onRequestSearchSubmit, onAddItem]);
|
|
7717
7752
|
// Render ----------------------------------------------------------------------------------------------------------
|
|
7718
|
-
return (React__default["default"].createElement(material.Autocomplete, { options: items || [], className: classNames$1(className, 'FormValueItem', 'FormAutocomplete'), sx: sx, multiple: multiple, fullWidth: !width && fullWidth, openOnFocus: openOnFocus, disableClearable: disableClearable, disablePortal: disablePortal, noOptionsText: noOptionsText, value: componentValue, style: style, isOptionEqualToValue: function (option, value) { return option.value === value.value; }, disabled: disabled, readOnly: readOnly, loading: loading || isOnGetItemLoading, loadingText: loadingText, limitTags: limitTags, onChange: function (e, value, reason, details) { return handleChange(value, reason, details); }, renderOption: function (props, option) { return (React__default["default"].createElement("li", __assign$4({}, props, { key: option.value }), onRenderItem ? onRenderItem(option) : option.label)); },
|
|
7753
|
+
return (React__default["default"].createElement(material.Autocomplete, { options: items || [], className: classNames$1(className, 'FormValueItem', 'FormAutocomplete'), sx: sx, multiple: multiple, fullWidth: !width && fullWidth, openOnFocus: openOnFocus, disableClearable: disableClearable, disablePortal: disablePortal, noOptionsText: noOptionsText, value: componentValue, style: style, isOptionEqualToValue: function (option, value) { return option.value === value.value; }, disabled: disabled, readOnly: readOnly, loading: loading || isOnGetItemLoading, loadingText: loadingText, limitTags: limitTags, onChange: function (e, value, reason, details) { return handleChange(value, reason, details); }, renderOption: function (props, option) { return (React__default["default"].createElement("li", __assign$4({}, props, { key: option.value }), onRenderItem ? onRenderItem(option) : option.label)); }, onInputChange: function (event, newInputValue, reason) {
|
|
7754
|
+
if (reason === 'input') {
|
|
7755
|
+
setInputValue(newInputValue);
|
|
7756
|
+
}
|
|
7757
|
+
}, renderTags: function (value, getTagProps) {
|
|
7719
7758
|
return value.map(function (option, index) { return (React__default["default"].createElement(material.Chip, __assign$4({ size: 'small', label: onRenderTag ? onRenderTag(option) : option.label }, getTagProps({ index: index })))); });
|
|
7720
7759
|
}, renderInput: function (params) { return (React__default["default"].createElement(FormTextField, __assign$4({}, params, { ref: textFieldRef, name: name, variant: variant, size: size, color: color, labelIcon: labelIcon, label: label, labelShrink: labelShrink, required: required, focused: focused, error: error, helperText: helperText, placeholder: placeholder, noFormValueItem: true, InputProps: __assign$4(__assign$4({}, params.InputProps), { endAdornment: (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
7721
7760
|
loading || isOnGetItemLoading ? React__default["default"].createElement(CircularProgress__default["default"], { color: 'inherit', size: 20 }) : null,
|