@opengeoweb/form-fields 14.1.0 → 14.2.1
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/index.esm.js +69 -14
- package/package.json +3 -3
package/index.esm.js
CHANGED
|
@@ -482,8 +482,7 @@ var ReactHookFormSelect = function ReactHookFormSelect(_ref) {
|
|
|
482
482
|
// default props
|
|
483
483
|
_onChange(changeEvent, child);
|
|
484
484
|
},
|
|
485
|
-
|
|
486
|
-
value: value || '',
|
|
485
|
+
value: value != null ? value : '',
|
|
487
486
|
variant: "filled"
|
|
488
487
|
}, otherProps, {
|
|
489
488
|
children: children
|
|
@@ -678,12 +677,10 @@ var ReactHookFormNumberField = function ReactHookFormNumberField(_ref) {
|
|
|
678
677
|
var before = inputElement.value.slice(0, inputElement.selectionStart);
|
|
679
678
|
var after = inputElement.value.slice(inputElement.selectionEnd);
|
|
680
679
|
var newValue = before + clipboardText + after;
|
|
681
|
-
|
|
682
|
-
if (inputMode === 'numeric' && !/^\-?[0-9]+$/.exec(newValue)) {
|
|
680
|
+
if (inputMode === 'numeric' && !/^-?[0-9]+$/.exec(newValue)) {
|
|
683
681
|
event.preventDefault();
|
|
684
682
|
}
|
|
685
|
-
|
|
686
|
-
if (inputMode === 'decimal' && !/^\-?[0-9]*(\.[0-9]+)?$/.exec(newValue)) {
|
|
683
|
+
if (inputMode === 'decimal' && !/^-?[0-9]*(.[0-9]+)?$/.exec(newValue)) {
|
|
687
684
|
event.preventDefault();
|
|
688
685
|
}
|
|
689
686
|
};
|
|
@@ -702,9 +699,50 @@ var ReactHookFormNumberField = function ReactHookFormNumberField(_ref) {
|
|
|
702
699
|
event.preventDefault();
|
|
703
700
|
}
|
|
704
701
|
};
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
702
|
+
// Transform number value to string for display, following React Hook Form transform pattern
|
|
703
|
+
var formatValueForDisplay = React.useCallback(function (numValue) {
|
|
704
|
+
if (numValue === null || numValue === undefined || isNaN(numValue)) {
|
|
705
|
+
return '';
|
|
706
|
+
}
|
|
707
|
+
return String(numValue);
|
|
708
|
+
}, []);
|
|
709
|
+
// Local state to preserve string precision during editing (e.g., trailing zeros), only sync from form value when not actively editing
|
|
710
|
+
var _React$useState = React.useState(null),
|
|
711
|
+
localValue = _React$useState[0],
|
|
712
|
+
setLocalValue = _React$useState[1];
|
|
713
|
+
var isFocusedRef = React.useRef(false);
|
|
714
|
+
var previousValueRef = React.useRef(value);
|
|
715
|
+
var lastSetValueRef = React.useRef(null);
|
|
716
|
+
// Sync local value from form value when value changes externally, but only when not actively editing and the change wasn't from our own update
|
|
717
|
+
React.useEffect(function () {
|
|
718
|
+
if (!isFocusedRef.current && value !== previousValueRef.current) {
|
|
719
|
+
var wasOurUpdate = lastSetValueRef.current !== null && lastSetValueRef.current === value;
|
|
720
|
+
if (!wasOurUpdate) {
|
|
721
|
+
setLocalValue(null); // Clear local value to use form value
|
|
722
|
+
} else if (localValue !== null) {
|
|
723
|
+
// It was our update, but check if localValue still represents this number accurately
|
|
724
|
+
var numFromLocal = convertNumericInputValue(localValue, inputMode);
|
|
725
|
+
if (numFromLocal !== value) {
|
|
726
|
+
// Local value no longer matches form value, clear it
|
|
727
|
+
setLocalValue(null);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
previousValueRef.current = value;
|
|
731
|
+
}
|
|
732
|
+
}, [value, localValue, inputMode]);
|
|
733
|
+
// Compute display value: prefer local value if it has more precision than number representation
|
|
734
|
+
var displayValue = React.useMemo(function () {
|
|
735
|
+
// Always use local value if it exists and represents the same number as form value
|
|
736
|
+
if (localValue !== null) {
|
|
737
|
+
var numFromLocal = convertNumericInputValue(localValue, inputMode);
|
|
738
|
+
var valuesMatch = numFromLocal === value || numFromLocal === null && value === null || numFromLocal !== null && typeof numFromLocal === 'number' && typeof value === 'number' && isNaN(numFromLocal) && isNaN(value);
|
|
739
|
+
if (valuesMatch) {
|
|
740
|
+
return localValue;
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
// When no local value or it doesn't match, use formatted form value
|
|
744
|
+
return formatValueForDisplay(value);
|
|
745
|
+
}, [value, localValue, inputMode, formatValueForDisplay]);
|
|
708
746
|
return jsx(ReactHookFormFormControl, {
|
|
709
747
|
className: className,
|
|
710
748
|
disabled: disabled,
|
|
@@ -719,12 +757,30 @@ var ReactHookFormNumberField = function ReactHookFormNumberField(_ref) {
|
|
|
719
757
|
inputRef: ref,
|
|
720
758
|
label: label,
|
|
721
759
|
name: name,
|
|
760
|
+
onBlur: function onBlur(evt) {
|
|
761
|
+
isFocusedRef.current = false;
|
|
762
|
+
// Keep local value on blur to preserve precision (e.g., trailing zeros), it will be cleared only if form value changes externally
|
|
763
|
+
previousValueRef.current = value;
|
|
764
|
+
otherProps.onBlur == null || otherProps.onBlur(evt);
|
|
765
|
+
},
|
|
722
766
|
onChange: function onChange(evt) {
|
|
723
|
-
var
|
|
724
|
-
|
|
725
|
-
|
|
767
|
+
var inputValue = evt.target.value;
|
|
768
|
+
// Update local value to preserve string precision during editing
|
|
769
|
+
setLocalValue(inputValue);
|
|
770
|
+
// Convert to number for form value
|
|
771
|
+
var numericValue = convertNumericInputValue(inputValue, inputMode);
|
|
772
|
+
lastSetValueRef.current = numericValue;
|
|
773
|
+
onChangeField(numericValue);
|
|
726
774
|
_onChange(null);
|
|
727
775
|
},
|
|
776
|
+
onFocus: function onFocus(evt) {
|
|
777
|
+
isFocusedRef.current = true;
|
|
778
|
+
// Initialize local value with current display value when focusing
|
|
779
|
+
if (localValue === null) {
|
|
780
|
+
setLocalValue(formatValueForDisplay(value));
|
|
781
|
+
}
|
|
782
|
+
otherProps.onFocus == null || otherProps.onFocus(evt);
|
|
783
|
+
},
|
|
728
784
|
onKeyDown: onKeyDown,
|
|
729
785
|
size: size,
|
|
730
786
|
type: "text",
|
|
@@ -1079,8 +1135,7 @@ var useDraftFormHelpers = function useDraftFormHelpers(isDefaultDraft) {
|
|
|
1079
1135
|
setValue(HIDDEN_INPUT_HELPER_IS_DRAFT, isDefaultDraft, {
|
|
1080
1136
|
shouldDirty: false
|
|
1081
1137
|
});
|
|
1082
|
-
|
|
1083
|
-
}, []);
|
|
1138
|
+
}, [isDefaultDraft, setValue]);
|
|
1084
1139
|
var isDraft = function isDraft() {
|
|
1085
1140
|
return getValues(HIDDEN_INPUT_HELPER_IS_DRAFT) === true;
|
|
1086
1141
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeoweb/form-fields",
|
|
3
|
-
"version": "14.1
|
|
3
|
+
"version": "14.2.1",
|
|
4
4
|
"description": "GeoWeb form-fields library for the opengeoweb project",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"url": "git@gitlab.com:opengeoweb/opengeoweb.git"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@opengeoweb/theme": "14.1
|
|
11
|
+
"@opengeoweb/theme": "14.2.1",
|
|
12
12
|
"react-hook-form": "^7.50.1",
|
|
13
13
|
"@mui/x-date-pickers": "^8.11.2",
|
|
14
14
|
"lodash": "^4.17.21",
|
|
15
|
-
"@opengeoweb/shared": "14.1
|
|
15
|
+
"@opengeoweb/shared": "14.2.1",
|
|
16
16
|
"react-i18next": "^15.1.1",
|
|
17
17
|
"@mui/material": "^7.0.1",
|
|
18
18
|
"i18next": "^25.0.1",
|