@sheinx/hooks 3.7.3-beta.3 → 3.7.3-beta.5
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/cjs/components/use-datepicker/use-date.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-date.js +12 -4
- package/cjs/components/use-datepicker/use-date.type.d.ts +2 -1
- package/cjs/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-range.js +2 -2
- package/cjs/components/use-form/use-form.js +2 -2
- package/esm/components/use-datepicker/use-date.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-date.js +12 -4
- package/esm/components/use-datepicker/use-date.type.d.ts +2 -1
- package/esm/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-range.js +2 -2
- package/esm/components/use-form/use-form.js +2 -2
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-date.d.ts","sourceRoot":"","sources":["use-date.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,QAAA,MAAM,OAAO,UAAW,YAAY;;;;;;;;;;
|
1
|
+
{"version":3,"file":"use-date.d.ts","sourceRoot":"","sources":["use-date.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,QAAA,MAAM,OAAO,UAAW,YAAY;;;;;;;;;;wBAoBX,IAAI;2BAkDD,IAAI;yBAkBN,IAAI;0BAgEH,IAAI;+BAtFC,IAAI;+BAiDJ,IAAI,YAAY,OAAO;0BAnB5B,IAAI;2BAIH,IAAI;;gCAIC,IAAI;;CA+FpC,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -28,14 +28,16 @@ var useDate = function useDate(props) {
|
|
28
28
|
cachedDays: []
|
29
29
|
}),
|
30
30
|
context = _useRef.current;
|
31
|
-
var current = props.current === undefined ? currentState : props.current;
|
31
|
+
var current = props.current === undefined || !props.current ? currentState : props.current;
|
32
32
|
var setCurrent = function setCurrent(date) {
|
33
33
|
var _props$onCurrentChang2;
|
34
34
|
if (props.current !== undefined) {
|
35
35
|
var _props$onCurrentChang;
|
36
36
|
(_props$onCurrentChang = props.onCurrentChange) === null || _props$onCurrentChang === void 0 || _props$onCurrentChang.call(props, date);
|
37
37
|
} else {
|
38
|
-
|
38
|
+
if (date) {
|
39
|
+
setCurrentState(date);
|
40
|
+
}
|
39
41
|
}
|
40
42
|
(_props$onCurrentChang2 = props.onCurrentChange) === null || _props$onCurrentChang2 === void 0 || _props$onCurrentChang2.call(props, date);
|
41
43
|
};
|
@@ -110,9 +112,15 @@ var useDate = function useDate(props) {
|
|
110
112
|
var _props$onChange;
|
111
113
|
if (isDisabled(date)) return;
|
112
114
|
var newDate = getDateWithTime(date);
|
113
|
-
|
115
|
+
var index = position === 'start' ? 0 : 1;
|
116
|
+
if (props.allowSingle && props.rangeDate && Array.isArray(props.rangeDate) && props.rangeDate[index] && _util.default.clearHMS(newDate, options).getTime() === _util.default.clearHMS(props.rangeDate[index], options).getTime()) {
|
117
|
+
newDate = '';
|
118
|
+
}
|
119
|
+
props === null || props === void 0 || props.onClearInputArr(index);
|
114
120
|
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newDate, noClose);
|
115
|
-
|
121
|
+
if (newDate) {
|
122
|
+
setCurrent(newDate);
|
123
|
+
}
|
116
124
|
};
|
117
125
|
var getTimeStr = function getTimeStr() {
|
118
126
|
var format = props.format,
|
@@ -6,7 +6,8 @@ export interface UseDateProps {
|
|
6
6
|
onCurrentChange?: (date: Date) => void;
|
7
7
|
onClearInputArr: (index?: number | undefined) => void;
|
8
8
|
value?: Date;
|
9
|
-
|
9
|
+
allowSingle?: boolean;
|
10
|
+
onChange?: (date: Date | string, noClose?: boolean) => void;
|
10
11
|
min?: Date;
|
11
12
|
max?: Date;
|
12
13
|
position?: 'start' | 'end';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-date.type.d.ts","sourceRoot":"","sources":["use-date.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACvC,eAAe,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IACtD,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"use-date.type.d.ts","sourceRoot":"","sources":["use-date.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;IACvC,eAAe,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IACtD,KAAK,CAAC,EAAE,IAAI,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC5D,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,QAAQ,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC;IAC/C,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACrC,OAAO,EAAE;QACP,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH"}
|
@@ -37,7 +37,7 @@ var useRangePick = function useRangePick(props) {
|
|
37
37
|
setDateArr(function (arr) {
|
38
38
|
var newArr = _toConsumableArray(arr);
|
39
39
|
newArr[index] = date;
|
40
|
-
if (range && index === 0 && newArr[1]) {
|
40
|
+
if (date && range && index === 0 && newArr[1]) {
|
41
41
|
if (typeof range === 'number') {
|
42
42
|
var rangeMax = _util.default.addSeconds(date, range, options);
|
43
43
|
if (rangeMax.getTime() < newArr[1].getTime()) {
|
@@ -66,7 +66,7 @@ var useRangePick = function useRangePick(props) {
|
|
66
66
|
var newArr = _toConsumableArray(arr);
|
67
67
|
newArr[index] = date;
|
68
68
|
var modeCache = context.modeCache;
|
69
|
-
if (modeCache[0] === modeCache[1]) {
|
69
|
+
if (date && modeCache[0] === modeCache[1]) {
|
70
70
|
var mode = modeCache[0];
|
71
71
|
if (range && index === 0 && newArr[1]) {
|
72
72
|
if (mode === 'year') {
|
@@ -410,14 +410,14 @@ var useForm = function useForm(props) {
|
|
410
410
|
});
|
411
411
|
case 6:
|
412
412
|
result = _context.sent;
|
413
|
-
if (activeEl) activeEl.focus();
|
414
413
|
if (result === true) {
|
415
414
|
(_props$onSubmit2 = props.onSubmit) === null || _props$onSubmit2 === void 0 || _props$onSubmit2.call(props, (_context$value2 = context.value) !== null && _context$value2 !== void 0 ? _context$value2 : {});
|
415
|
+
if (activeEl) activeEl.focus();
|
416
416
|
} else {
|
417
417
|
handleSubmitError(result);
|
418
418
|
}
|
419
419
|
callback === null || callback === void 0 || callback();
|
420
|
-
case
|
420
|
+
case 9:
|
421
421
|
case "end":
|
422
422
|
return _context.stop();
|
423
423
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-date.d.ts","sourceRoot":"","sources":["use-date.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,QAAA,MAAM,OAAO,UAAW,YAAY;;;;;;;;;;
|
1
|
+
{"version":3,"file":"use-date.d.ts","sourceRoot":"","sources":["use-date.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C,QAAA,MAAM,OAAO,UAAW,YAAY;;;;;;;;;;wBAoBX,IAAI;2BAkDD,IAAI;yBAkBN,IAAI;0BAgEH,IAAI;+BAtFC,IAAI;+BAiDJ,IAAI,YAAY,OAAO;0BAnB5B,IAAI;2BAIH,IAAI;;gCAIC,IAAI;;CA+FpC,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -22,14 +22,16 @@ var useDate = function useDate(props) {
|
|
22
22
|
cachedDays: []
|
23
23
|
}),
|
24
24
|
context = _useRef.current;
|
25
|
-
var current = props.current === undefined ? currentState : props.current;
|
25
|
+
var current = props.current === undefined || !props.current ? currentState : props.current;
|
26
26
|
var setCurrent = function setCurrent(date) {
|
27
27
|
var _props$onCurrentChang2;
|
28
28
|
if (props.current !== undefined) {
|
29
29
|
var _props$onCurrentChang;
|
30
30
|
(_props$onCurrentChang = props.onCurrentChange) === null || _props$onCurrentChang === void 0 || _props$onCurrentChang.call(props, date);
|
31
31
|
} else {
|
32
|
-
|
32
|
+
if (date) {
|
33
|
+
setCurrentState(date);
|
34
|
+
}
|
33
35
|
}
|
34
36
|
(_props$onCurrentChang2 = props.onCurrentChange) === null || _props$onCurrentChang2 === void 0 || _props$onCurrentChang2.call(props, date);
|
35
37
|
};
|
@@ -104,9 +106,15 @@ var useDate = function useDate(props) {
|
|
104
106
|
var _props$onChange;
|
105
107
|
if (isDisabled(date)) return;
|
106
108
|
var newDate = getDateWithTime(date);
|
107
|
-
|
109
|
+
var index = position === 'start' ? 0 : 1;
|
110
|
+
if (props.allowSingle && props.rangeDate && Array.isArray(props.rangeDate) && props.rangeDate[index] && utils.clearHMS(newDate, options).getTime() === utils.clearHMS(props.rangeDate[index], options).getTime()) {
|
111
|
+
newDate = '';
|
112
|
+
}
|
113
|
+
props === null || props === void 0 || props.onClearInputArr(index);
|
108
114
|
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newDate, noClose);
|
109
|
-
|
115
|
+
if (newDate) {
|
116
|
+
setCurrent(newDate);
|
117
|
+
}
|
110
118
|
};
|
111
119
|
var getTimeStr = function getTimeStr() {
|
112
120
|
var format = props.format,
|
@@ -6,7 +6,8 @@ export interface UseDateProps {
|
|
6
6
|
onCurrentChange?: (date: Date) => void;
|
7
7
|
onClearInputArr: (index?: number | undefined) => void;
|
8
8
|
value?: Date;
|
9
|
-
|
9
|
+
allowSingle?: boolean;
|
10
|
+
onChange?: (date: Date | string, noClose?: boolean) => void;
|
10
11
|
min?: Date;
|
11
12
|
max?: Date;
|
12
13
|
position?: 'start' | 'end';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-date.type.d.ts","sourceRoot":"","sources":["use-date.type.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,CAAC;IACpC,cAAc,CAAC,EAAE,IAAI,CAAC;IACtB,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,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AE;QACP,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH"}
|
@@ -30,7 +30,7 @@ var useRangePick = function useRangePick(props) {
|
|
30
30
|
setDateArr(function (arr) {
|
31
31
|
var newArr = _toConsumableArray(arr);
|
32
32
|
newArr[index] = date;
|
33
|
-
if (range && index === 0 && newArr[1]) {
|
33
|
+
if (date && range && index === 0 && newArr[1]) {
|
34
34
|
if (typeof range === 'number') {
|
35
35
|
var rangeMax = utils.addSeconds(date, range, options);
|
36
36
|
if (rangeMax.getTime() < newArr[1].getTime()) {
|
@@ -59,7 +59,7 @@ var useRangePick = function useRangePick(props) {
|
|
59
59
|
var newArr = _toConsumableArray(arr);
|
60
60
|
newArr[index] = date;
|
61
61
|
var modeCache = context.modeCache;
|
62
|
-
if (modeCache[0] === modeCache[1]) {
|
62
|
+
if (date && modeCache[0] === modeCache[1]) {
|
63
63
|
var mode = modeCache[0];
|
64
64
|
if (range && index === 0 && newArr[1]) {
|
65
65
|
if (mode === 'year') {
|
@@ -401,14 +401,14 @@ var useForm = function useForm(props) {
|
|
401
401
|
});
|
402
402
|
case 6:
|
403
403
|
result = _context.sent;
|
404
|
-
if (activeEl) activeEl.focus();
|
405
404
|
if (result === true) {
|
406
405
|
(_props$onSubmit2 = props.onSubmit) === null || _props$onSubmit2 === void 0 || _props$onSubmit2.call(props, (_context$value2 = context.value) !== null && _context$value2 !== void 0 ? _context$value2 : {});
|
406
|
+
if (activeEl) activeEl.focus();
|
407
407
|
} else {
|
408
408
|
handleSubmitError(result);
|
409
409
|
}
|
410
410
|
callback === null || callback === void 0 || callback();
|
411
|
-
case
|
411
|
+
case 9:
|
412
412
|
case "end":
|
413
413
|
return _context.stop();
|
414
414
|
}
|