react-better-html 1.1.229 → 1.1.231
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.d.mts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/index.js +113 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +113 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3188,6 +3188,18 @@ var decryptString = (text) => {
|
|
|
3188
3188
|
});
|
|
3189
3189
|
return decrypted.toString(CryptoJS.enc.Utf8);
|
|
3190
3190
|
};
|
|
3191
|
+
function findClosestNumber(numbers, target) {
|
|
3192
|
+
let closest = numbers[0];
|
|
3193
|
+
let minDistance = Math.abs(target - numbers[0]);
|
|
3194
|
+
for (let index = 1; index < numbers.length; index++) {
|
|
3195
|
+
const distance = Math.abs(target - numbers[index]);
|
|
3196
|
+
if (distance < minDistance || distance === minDistance && numbers[index] < closest) {
|
|
3197
|
+
closest = numbers[index];
|
|
3198
|
+
minDistance = distance;
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
return closest;
|
|
3202
|
+
}
|
|
3191
3203
|
|
|
3192
3204
|
// src/utils/localStorage.ts
|
|
3193
3205
|
function generateLocalStorage() {
|
|
@@ -4749,13 +4761,29 @@ InputFieldComponent.date = forwardRef11(function Date2({ minDate, maxDate, ...pr
|
|
|
4749
4761
|
}
|
|
4750
4762
|
);
|
|
4751
4763
|
});
|
|
4752
|
-
InputFieldComponent.dateTime = forwardRef11(function DateTime({
|
|
4764
|
+
InputFieldComponent.dateTime = forwardRef11(function DateTime({
|
|
4765
|
+
hoursToRender,
|
|
4766
|
+
minutesToRender,
|
|
4767
|
+
minDate,
|
|
4768
|
+
maxDate,
|
|
4769
|
+
defaultDateAfterTimePick,
|
|
4770
|
+
defaultTimeAfterDatePick = "00:00",
|
|
4771
|
+
...props
|
|
4772
|
+
}, ref) {
|
|
4753
4773
|
const theme2 = useTheme19();
|
|
4754
4774
|
const holderRef = useRef5(null);
|
|
4755
4775
|
const selectedHourRef = useRef5(null);
|
|
4756
4776
|
const selectedMinuteRef = useRef5(null);
|
|
4757
4777
|
const isMobileIOS = isMobileDevice && getBrowser() === "safari";
|
|
4758
4778
|
const { internalValue, setInternalValue, inputFieldProps, insideInputFieldComponentProps, isOpen } = useComponentInputFieldDateProps(props, holderRef, isMobileIOS);
|
|
4779
|
+
const readyHours = useMemo6(
|
|
4780
|
+
() => hoursToRender?.filter((hour) => hour >= 0 && hour <= 23) ?? hours,
|
|
4781
|
+
[hoursToRender]
|
|
4782
|
+
);
|
|
4783
|
+
const readyMinutes = useMemo6(
|
|
4784
|
+
() => minutesToRender?.filter((hour) => hour >= 0 && hour <= 59) ?? minutes,
|
|
4785
|
+
[minutesToRender]
|
|
4786
|
+
);
|
|
4759
4787
|
const onChange = useCallback10(
|
|
4760
4788
|
(date) => {
|
|
4761
4789
|
const newValue = date ? `${date}T${internalValue?.toString().split("T")[1] ?? defaultTimeAfterDatePick}` : "";
|
|
@@ -4764,6 +4792,32 @@ InputFieldComponent.dateTime = forwardRef11(function DateTime({ minDate, maxDate
|
|
|
4764
4792
|
},
|
|
4765
4793
|
[internalValue, defaultTimeAfterDatePick, inputFieldProps.onChangeValue]
|
|
4766
4794
|
);
|
|
4795
|
+
const onBlur = useCallback10(
|
|
4796
|
+
(event) => {
|
|
4797
|
+
if (hoursToRender || minutesToRender) {
|
|
4798
|
+
const value = event.target.value;
|
|
4799
|
+
const hours2 = parseInt(value.split(":")[0] || "0");
|
|
4800
|
+
const minutes2 = parseInt(value.split(":")[1] || "0");
|
|
4801
|
+
const readyHour = readyHours.includes(hours2) ? hours2 : findClosestNumber(readyHours, hours2);
|
|
4802
|
+
const readyMinute = readyMinutes.includes(minutes2) ? minutes2 : findClosestNumber(readyMinutes, minutes2);
|
|
4803
|
+
const newTime = `${readyHour.toString().padStart(2, "0")}:${readyMinute.toString().padStart(2, "0")}`;
|
|
4804
|
+
const today = defaultDateAfterTimePick ?? `${(/* @__PURE__ */ new Date()).getFullYear()}-${((/* @__PURE__ */ new Date()).getMonth() + 1).toString().padStart(2, "0")}-${(/* @__PURE__ */ new Date()).getDate().toString().padStart(2, "0")}`;
|
|
4805
|
+
const newValue = `${(internalValue.trim() || today)?.toString().split("T")[0]}T${newTime}`;
|
|
4806
|
+
inputFieldProps.onChangeValue?.(newValue);
|
|
4807
|
+
}
|
|
4808
|
+
inputFieldProps.onBlur?.(event);
|
|
4809
|
+
},
|
|
4810
|
+
[
|
|
4811
|
+
defaultDateAfterTimePick,
|
|
4812
|
+
internalValue,
|
|
4813
|
+
hoursToRender,
|
|
4814
|
+
minutesToRender,
|
|
4815
|
+
readyHours,
|
|
4816
|
+
readyMinutes,
|
|
4817
|
+
inputFieldProps.onChangeValue,
|
|
4818
|
+
inputFieldProps.onBlur
|
|
4819
|
+
]
|
|
4820
|
+
);
|
|
4767
4821
|
const onClickHour = useCallback10(
|
|
4768
4822
|
(hour) => {
|
|
4769
4823
|
const newTime = `${hour.toString().padStart(2, "0")}:${internalValue?.toString().split(":")[1] || "00"}`;
|
|
@@ -4832,7 +4886,7 @@ InputFieldComponent.dateTime = forwardRef11(function DateTime({ minDate, maxDate
|
|
|
4832
4886
|
height: `calc(100% - ${16 + theme2.styles.gap / 2}px)`,
|
|
4833
4887
|
overflowY: "auto",
|
|
4834
4888
|
tabIndex: -1,
|
|
4835
|
-
children:
|
|
4889
|
+
children: readyHours.map((hour) => {
|
|
4836
4890
|
const isSelected = hour.toString() === valueHour;
|
|
4837
4891
|
return /* @__PURE__ */ jsx17(
|
|
4838
4892
|
Div_default.row,
|
|
@@ -4866,7 +4920,7 @@ InputFieldComponent.dateTime = forwardRef11(function DateTime({ minDate, maxDate
|
|
|
4866
4920
|
height: `calc(100% - ${16 + theme2.styles.gap / 2}px)`,
|
|
4867
4921
|
overflowY: "auto",
|
|
4868
4922
|
tabIndex: -1,
|
|
4869
|
-
children:
|
|
4923
|
+
children: readyMinutes.map((minute) => {
|
|
4870
4924
|
const isSelected = minute.toString() === valueMinute;
|
|
4871
4925
|
return /* @__PURE__ */ jsx17(
|
|
4872
4926
|
Div_default.row,
|
|
@@ -4899,17 +4953,58 @@ InputFieldComponent.dateTime = forwardRef11(function DateTime({ minDate, maxDate
|
|
|
4899
4953
|
holderRef,
|
|
4900
4954
|
ref,
|
|
4901
4955
|
...props,
|
|
4902
|
-
...inputFieldProps
|
|
4956
|
+
...inputFieldProps,
|
|
4957
|
+
onBlur
|
|
4903
4958
|
}
|
|
4904
4959
|
);
|
|
4905
4960
|
});
|
|
4906
|
-
InputFieldComponent.time = forwardRef11(function Time({ ...props }, ref) {
|
|
4961
|
+
InputFieldComponent.time = forwardRef11(function Time({ hoursToRender, minutesToRender, minTime, maxTime, ...props }, ref) {
|
|
4907
4962
|
const theme2 = useTheme19();
|
|
4908
4963
|
const holderRef = useRef5(null);
|
|
4909
4964
|
const selectedHourRef = useRef5(null);
|
|
4910
4965
|
const selectedMinuteRef = useRef5(null);
|
|
4911
4966
|
const isMobileIOS = isMobileDevice && getBrowser() === "safari";
|
|
4967
|
+
const minHours = minTime ? parseInt(minTime.split(":")[0]) : void 0;
|
|
4968
|
+
const minMinutes = minTime ? parseInt(minTime.split(":")[1]) : void 0;
|
|
4969
|
+
const maxHours = maxTime ? parseInt(maxTime.split(":")[0]) : void 0;
|
|
4970
|
+
const maxMinutes = maxTime ? parseInt(maxTime.split(":")[1]) : void 0;
|
|
4912
4971
|
const { internalValue, setInternalValue, inputFieldProps, insideInputFieldComponentProps, isOpen } = useComponentInputFieldDateProps(props, holderRef, isMobileIOS);
|
|
4972
|
+
const readyHours = useMemo6(
|
|
4973
|
+
() => hoursToRender?.filter((hour) => hour >= 0 && hour <= 23) ?? hours,
|
|
4974
|
+
[hoursToRender]
|
|
4975
|
+
);
|
|
4976
|
+
const readyMinutes = useMemo6(
|
|
4977
|
+
() => minutesToRender?.filter((hour) => hour >= 0 && hour <= 59) ?? minutes,
|
|
4978
|
+
[minutesToRender]
|
|
4979
|
+
);
|
|
4980
|
+
const onBlur = useCallback10(
|
|
4981
|
+
(event) => {
|
|
4982
|
+
if (!!minHours || !!maxHours || !!minMinutes || !!maxMinutes || hoursToRender || minutesToRender) {
|
|
4983
|
+
const value = event.target.value;
|
|
4984
|
+
const hours2 = parseInt(value.split(":")[0] || "0");
|
|
4985
|
+
const minutes2 = parseInt(value.split(":")[1] || "0");
|
|
4986
|
+
const readyHour = readyHours.includes(hours2) ? hours2 : findClosestNumber(readyHours, hours2);
|
|
4987
|
+
const readyMinute = readyMinutes.includes(minutes2) ? minutes2 : findClosestNumber(readyMinutes, minutes2);
|
|
4988
|
+
const finalHour = minHours && readyHour < minHours ? minHours : maxHours && readyHour > maxHours ? maxHours : readyHour;
|
|
4989
|
+
const finalMinute = minHours !== void 0 && minMinutes !== void 0 && finalHour === minHours && readyMinute < minMinutes ? minMinutes : maxHours !== void 0 && maxMinutes !== void 0 && finalHour === maxHours && readyMinute > maxMinutes ? maxMinutes : readyMinute;
|
|
4990
|
+
const newValue = `${finalHour.toString().padStart(2, "0")}:${finalMinute.toString().padStart(2, "0")}`;
|
|
4991
|
+
inputFieldProps.onChangeValue?.(newValue);
|
|
4992
|
+
}
|
|
4993
|
+
inputFieldProps.onBlur?.(event);
|
|
4994
|
+
},
|
|
4995
|
+
[
|
|
4996
|
+
minHours,
|
|
4997
|
+
maxHours,
|
|
4998
|
+
minMinutes,
|
|
4999
|
+
maxMinutes,
|
|
5000
|
+
hoursToRender,
|
|
5001
|
+
minutesToRender,
|
|
5002
|
+
readyHours,
|
|
5003
|
+
readyMinutes,
|
|
5004
|
+
inputFieldProps.onChangeValue,
|
|
5005
|
+
inputFieldProps.onBlur
|
|
5006
|
+
]
|
|
5007
|
+
);
|
|
4913
5008
|
const onClickHour = useCallback10(
|
|
4914
5009
|
(hour) => {
|
|
4915
5010
|
const value = `${hour.toString().padStart(2, "0")}:${internalValue?.toString().split(":")[1] || "00"}`;
|
|
@@ -4962,8 +5057,9 @@ InputFieldComponent.time = forwardRef11(function Time({ ...props }, ref) {
|
|
|
4962
5057
|
height: "100%",
|
|
4963
5058
|
overflowY: "auto",
|
|
4964
5059
|
tabIndex: -1,
|
|
4965
|
-
children:
|
|
5060
|
+
children: readyHours.map((hour) => {
|
|
4966
5061
|
const isSelected = hour.toString() === valueHour;
|
|
5062
|
+
const isDisabled = minHours && hour < minHours || maxHours && hour > maxHours;
|
|
4967
5063
|
return /* @__PURE__ */ jsx17(
|
|
4968
5064
|
Div_default.row,
|
|
4969
5065
|
{
|
|
@@ -4972,10 +5068,11 @@ InputFieldComponent.time = forwardRef11(function Time({ ...props }, ref) {
|
|
|
4972
5068
|
color: isSelected ? theme2.colors.base : theme2.colors.textPrimary,
|
|
4973
5069
|
backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
|
|
4974
5070
|
filterHover: "brightness(0.9)",
|
|
4975
|
-
cursor: "pointer",
|
|
5071
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
4976
5072
|
padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
|
|
5073
|
+
opacity: isDisabled ? 0.6 : void 0,
|
|
4977
5074
|
value: hour,
|
|
4978
|
-
onClickWithValue: onClickHour,
|
|
5075
|
+
onClickWithValue: !isDisabled ? onClickHour : void 0,
|
|
4979
5076
|
ref: isSelected ? selectedHourRef : void 0,
|
|
4980
5077
|
children: /* @__PURE__ */ jsx17(Text_default, { textAlign: "center", children: hour.toString().padStart(2, "0") })
|
|
4981
5078
|
},
|
|
@@ -4992,8 +5089,10 @@ InputFieldComponent.time = forwardRef11(function Time({ ...props }, ref) {
|
|
|
4992
5089
|
height: "100%",
|
|
4993
5090
|
overflowY: "auto",
|
|
4994
5091
|
tabIndex: -1,
|
|
4995
|
-
children:
|
|
5092
|
+
children: readyMinutes.map((minute) => {
|
|
4996
5093
|
const isSelected = minute.toString() === valueMinute;
|
|
5094
|
+
const currentHour = parseInt(valueHour);
|
|
5095
|
+
const isDisabled = minHours !== void 0 && minMinutes !== void 0 && currentHour === minHours && minute < minMinutes || maxHours !== void 0 && maxMinutes !== void 0 && currentHour === maxHours && minute > maxMinutes;
|
|
4997
5096
|
return /* @__PURE__ */ jsx17(
|
|
4998
5097
|
Div_default.row,
|
|
4999
5098
|
{
|
|
@@ -5002,10 +5101,11 @@ InputFieldComponent.time = forwardRef11(function Time({ ...props }, ref) {
|
|
|
5002
5101
|
color: isSelected ? theme2.colors.base : theme2.colors.textPrimary,
|
|
5003
5102
|
backgroundColor: isSelected ? theme2.colors.primary : theme2.colors.backgroundContent,
|
|
5004
5103
|
filterHover: "brightness(0.9)",
|
|
5005
|
-
cursor: "pointer",
|
|
5104
|
+
cursor: isDisabled ? "not-allowed" : "pointer",
|
|
5006
5105
|
padding: `${theme2.styles.space / 2}px ${theme2.styles.space + theme2.styles.gap}px`,
|
|
5106
|
+
opacity: isDisabled ? 0.6 : void 0,
|
|
5007
5107
|
value: minute,
|
|
5008
|
-
onClickWithValue: onClickMinute,
|
|
5108
|
+
onClickWithValue: !isDisabled ? onClickMinute : void 0,
|
|
5009
5109
|
ref: isSelected ? selectedMinuteRef : void 0,
|
|
5010
5110
|
children: /* @__PURE__ */ jsx17(Text_default, { textAlign: "center", children: minute.toString().padStart(2, "0") })
|
|
5011
5111
|
},
|
|
@@ -5021,7 +5121,8 @@ InputFieldComponent.time = forwardRef11(function Time({ ...props }, ref) {
|
|
|
5021
5121
|
ref,
|
|
5022
5122
|
...props,
|
|
5023
5123
|
...inputFieldProps,
|
|
5024
|
-
minWidth: buttonWidth * 2 + 2
|
|
5124
|
+
minWidth: buttonWidth * 2 + 2,
|
|
5125
|
+
onBlur
|
|
5025
5126
|
}
|
|
5026
5127
|
);
|
|
5027
5128
|
});
|