@king-design/intact 3.6.0-beta.0 → 3.6.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/components/button/demos/basic.md +0 -1
- package/components/cascader/index.spec.ts +7 -6
- package/components/copy/index.spec.ts +9 -14
- package/components/datepicker/basepicker.ts +26 -314
- package/components/datepicker/calendar.ts +3 -1
- package/components/datepicker/calendar.vdt +5 -2
- package/components/datepicker/dayjs.ts +2 -16
- package/components/datepicker/demos/multiple.md +5 -0
- package/components/datepicker/demos/yearMonth.md +2 -8
- package/components/datepicker/helpers.ts +5 -7
- package/components/datepicker/index.md +1 -2
- package/components/datepicker/index.spec.ts +596 -157
- package/components/datepicker/index.ts +16 -33
- package/components/datepicker/index.vdt +41 -35
- package/components/datepicker/shortcuts.ts +1 -1
- package/components/datepicker/styles.ts +27 -18
- package/components/datepicker/useConfirm.ts +82 -0
- package/components/datepicker/useDisabled.ts +29 -31
- package/components/datepicker/useFormats.ts +8 -4
- package/components/datepicker/useHighlight.ts +81 -0
- package/components/datepicker/useKeyboards.ts +2 -1
- package/components/datepicker/useMergeRange.ts +12 -12
- package/components/datepicker/useMonths.ts +6 -3
- package/components/datepicker/usePanel.ts +19 -19
- package/components/datepicker/useShowDate.ts +21 -41
- package/components/datepicker/useStatus.ts +34 -15
- package/components/datepicker/useValue.ts +43 -72
- package/components/datepicker/useValueBase.ts +312 -0
- package/components/datepicker/useWeeks.ts +1 -1
- package/components/datepicker/useYears.ts +7 -3
- package/components/dropdown/dropdown.ts +5 -4
- package/components/dropdown/index.md +1 -0
- package/components/dropdown/item.ts +1 -1
- package/components/dropdown/useKeyboard.ts +0 -1
- package/components/form/form.ts +4 -0
- package/components/form/index.md +2 -1
- package/components/form/index.spec.ts +2 -0
- package/components/input/index.spec.ts +42 -0
- package/components/input/index.ts +8 -0
- package/components/input/index.vdt +3 -4
- package/components/input/useAutoWidth.ts +19 -1
- package/components/menu/demos/horizontal.md +7 -1
- package/components/menu/index.spec.ts +19 -0
- package/components/menu/styles.ts +2 -1
- package/components/scrollSelect/useMouseEvents.ts +5 -4
- package/components/select/base.ts +3 -2
- package/components/select/base.vdt +2 -1
- package/components/select/demos/creatable.md +2 -2
- package/components/select/index.md +1 -1
- package/components/select/index.spec.ts +142 -36
- package/components/select/menu.ts +1 -1
- package/components/select/option.ts +2 -1
- package/components/select/select.ts +1 -0
- package/components/select/styles.ts +3 -1
- package/components/select/useCard.ts +22 -4
- package/components/select/useInput.ts +5 -9
- package/components/spinner/index.spec.ts +18 -0
- package/components/spinner/useValue.ts +2 -1
- package/components/table/index.spec.ts +69 -1
- package/components/table/useStickyHeader.ts +1 -1
- package/components/timepicker/index.spec.ts +145 -27
- package/components/timepicker/panelPicker.ts +10 -4
- package/components/timepicker/panelPicker.vdt +3 -5
- package/components/timepicker/styles.ts +1 -0
- package/components/timepicker/useConfirm.ts +33 -0
- package/components/timepicker/useDefaultValue.ts +30 -0
- package/components/timepicker/useDisabled.ts +17 -4
- package/components/timepicker/useFormats.ts +1 -1
- package/components/timepicker/useValue.ts +22 -19
- package/components/tour/index.spec.ts +1 -1
- package/es/components/cascader/index.spec.js +18 -19
- package/es/components/copy/index.spec.js +14 -31
- package/es/components/datepicker/basepicker.d.ts +6 -27
- package/es/components/datepicker/basepicker.js +23 -268
- package/es/components/datepicker/calendar.d.ts +4 -2
- package/es/components/datepicker/dayjs.d.ts +2 -13
- package/es/components/datepicker/helpers.d.ts +3 -2
- package/es/components/datepicker/helpers.js +2 -3
- package/es/components/datepicker/index.d.ts +21 -29
- package/es/components/datepicker/index.js +22 -32
- package/es/components/datepicker/index.spec.js +1277 -484
- package/es/components/datepicker/index.vdt.js +39 -38
- package/es/components/datepicker/shortcuts.d.ts +1 -1
- package/es/components/datepicker/styles.d.ts +7 -2
- package/es/components/datepicker/styles.js +10 -15
- package/es/components/datepicker/useConfirm.d.ts +6 -0
- package/es/components/datepicker/useConfirm.js +65 -0
- package/es/components/datepicker/useDisabled.d.ts +5 -3
- package/es/components/datepicker/useDisabled.js +22 -27
- package/es/components/datepicker/useFormats.d.ts +2 -2
- package/es/components/datepicker/useFormats.js +6 -2
- package/es/components/datepicker/useHighlight.d.ts +14 -0
- package/es/components/datepicker/useHighlight.js +60 -0
- package/es/components/datepicker/useKeyboards.js +2 -1
- package/es/components/datepicker/useMergeRange.d.ts +1 -1
- package/es/components/datepicker/useMergeRange.js +11 -16
- package/es/components/datepicker/useMonths.js +5 -3
- package/es/components/datepicker/usePanel.d.ts +1 -10
- package/es/components/datepicker/usePanel.js +19 -32
- package/es/components/datepicker/useShowDate.d.ts +1 -1
- package/es/components/datepicker/useShowDate.js +15 -40
- package/es/components/datepicker/useStatus.js +33 -16
- package/es/components/datepicker/useValue.d.ts +11 -6
- package/es/components/datepicker/useValue.js +49 -69
- package/es/components/datepicker/useValueBase.d.ts +28 -0
- package/es/components/datepicker/useValueBase.js +280 -0
- package/es/components/datepicker/useYears.js +6 -3
- package/es/components/dropdown/dropdown.d.ts +1 -0
- package/es/components/dropdown/dropdown.js +7 -4
- package/es/components/form/form.d.ts +1 -0
- package/es/components/form/form.js +7 -0
- package/es/components/form/index.spec.js +10 -8
- package/es/components/input/index.d.ts +2 -0
- package/es/components/input/index.js +6 -0
- package/es/components/input/index.spec.js +45 -0
- package/es/components/input/index.vdt.js +4 -3
- package/es/components/input/useAutoWidth.d.ts +2 -0
- package/es/components/input/useAutoWidth.js +19 -1
- package/es/components/menu/index.spec.js +28 -0
- package/es/components/menu/styles.js +2 -2
- package/es/components/scrollSelect/useMouseEvents.js +5 -4
- package/es/components/select/base.d.ts +1 -1
- package/es/components/select/base.js +3 -2
- package/es/components/select/base.vdt.js +4 -3
- package/es/components/select/index.spec.js +346 -218
- package/es/components/select/menu.js +1 -1
- package/es/components/select/option.js +2 -1
- package/es/components/select/select.js +2 -1
- package/es/components/select/styles.d.ts +79 -0
- package/es/components/select/styles.js +1 -0
- package/es/components/select/useCard.d.ts +4 -3
- package/es/components/select/useCard.js +15 -4
- package/es/components/select/useInput.d.ts +1 -1
- package/es/components/select/useInput.js +4 -4
- package/es/components/spinner/index.spec.js +82 -44
- package/es/components/spinner/useValue.js +2 -1
- package/es/components/table/index.spec.js +84 -6
- package/es/components/table/useStickyHeader.js +1 -1
- package/es/components/timepicker/index.spec.js +298 -128
- package/es/components/timepicker/panelPicker.d.ts +21 -16
- package/es/components/timepicker/panelPicker.js +7 -4
- package/es/components/timepicker/panelPicker.vdt.js +5 -9
- package/es/components/timepicker/selectPicker.d.ts +4 -3
- package/es/components/timepicker/styles.js +1 -1
- package/es/components/timepicker/useConfirm.d.ts +6 -0
- package/es/components/timepicker/useConfirm.js +19 -0
- package/es/components/timepicker/useDefaultValue.d.ts +4 -0
- package/es/components/timepicker/useDefaultValue.js +27 -0
- package/es/components/timepicker/useDisabled.d.ts +6 -3
- package/es/components/timepicker/useDisabled.js +13 -4
- package/es/components/timepicker/useFormats.d.ts +1 -1
- package/es/components/timepicker/useValue.d.ts +13 -8
- package/es/components/timepicker/useValue.js +14 -15
- package/es/components/tour/index.spec.js +1 -1
- package/es/index.d.ts +2 -2
- package/es/index.js +2 -2
- package/es/site/data/components/button/demos/basic/react.js +0 -2
- package/es/site/data/components/datepicker/demos/multiple/index.d.ts +1 -0
- package/es/site/data/components/datepicker/demos/multiple/index.js +2 -1
- package/es/site/data/components/datepicker/demos/multiple/react.d.ts +1 -0
- package/es/site/data/components/datepicker/demos/multiple/react.js +13 -2
- package/es/site/data/components/datepicker/demos/yearMonth/index.d.ts +0 -2
- package/es/site/data/components/datepicker/demos/yearMonth/index.js +1 -3
- package/es/site/data/components/datepicker/demos/yearMonth/react.d.ts +0 -2
- package/es/site/data/components/datepicker/demos/yearMonth/react.js +1 -21
- package/es/site/data/components/menu/demos/horizontal/react.js +5 -1
- package/es/site/data/components/select/demos/creatable/react.js +2 -2
- package/es/site/data/components/select/demos/searchable/index.js +1 -1
- package/es/site/data/components/select/demos/searchable/react.js +1 -1
- package/es/site/data/components/tour/demos/customText/index.d.ts +19 -6
- package/es/site/data/components/tour/demos/customText/index.js +18 -17
- package/es/site/data/components/tour/demos/customText/react.d.ts +20 -6
- package/es/site/data/components/tour/demos/customText/react.js +31 -27
- package/es/test/demos.js +1 -1
- package/index.ts +2 -2
- package/package.json +2 -2
- package/components/datepicker/demos/nowrap.md +0 -35
- package/components/datepicker/usePosition.ts +0 -169
- package/es/components/datepicker/usePosition.d.ts +0 -10
- package/es/components/datepicker/usePosition.js +0 -166
- package/es/site/data/components/datepicker/demos/nowrap/index.d.ts +0 -10
- package/es/site/data/components/datepicker/demos/nowrap/index.js +0 -19
- package/es/site/data/components/datepicker/demos/nowrap/react.d.ts +0 -10
- package/es/site/data/components/datepicker/demos/nowrap/react.js +0 -49
- package/es/site/data/components/tour/demos/customButtons/index.d.ts +0 -33
- package/es/site/data/components/tour/demos/customButtons/index.js +0 -55
- package/es/site/data/components/tour/demos/customButtons/react.d.ts +0 -33
- package/es/site/data/components/tour/demos/customButtons/react.js +0 -99
|
@@ -41,10 +41,13 @@ export function useMonths(
|
|
|
41
41
|
function onClick(date: Dayjs) {
|
|
42
42
|
showDate.set(date);
|
|
43
43
|
const datepickerType = instance.datepicker.get('type');
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} else {
|
|
44
|
+
|
|
45
|
+
if (datepickerType === 'month' || datepickerType === 'year') {
|
|
47
46
|
instance.triggerChange(date);
|
|
47
|
+
} else if (datepickerType === 'week') {
|
|
48
|
+
instance.type.set('week');
|
|
49
|
+
} else {
|
|
50
|
+
instance.type.set('date');
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -3,37 +3,37 @@ import {useState} from '../../hooks/useState';
|
|
|
3
3
|
import {Datepicker} from './index';
|
|
4
4
|
import {DatepickerCalendar} from './calendar';
|
|
5
5
|
|
|
6
|
-
export enum PanelTypes {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
6
|
+
// export enum PanelTypes {
|
|
7
|
+
// Date,
|
|
8
|
+
// Time
|
|
9
|
+
// }
|
|
10
10
|
|
|
11
11
|
export enum PanelFlags {
|
|
12
12
|
Start,
|
|
13
13
|
End
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function usePanel(
|
|
16
|
+
export function usePanel() {
|
|
17
17
|
const instance = useInstance() as Datepicker;
|
|
18
|
-
const startPanel = useState<PanelTypes>(type);
|
|
19
|
-
const endPanel = useState<PanelTypes>(type);
|
|
18
|
+
// const startPanel = useState<PanelTypes>(type);
|
|
19
|
+
// const endPanel = useState<PanelTypes>(type);
|
|
20
20
|
const startRef = createRef<DatepickerCalendar>();
|
|
21
21
|
const endRef = createRef<DatepickerCalendar>();
|
|
22
22
|
|
|
23
|
-
function changePanel(type: PanelTypes, flag: PanelFlags = PanelFlags.Start) {
|
|
24
|
-
|
|
25
|
-
}
|
|
23
|
+
// function changePanel(type: PanelTypes, flag: PanelFlags = PanelFlags.Start) {
|
|
24
|
+
// getPanel(flag).set(type);
|
|
25
|
+
// }
|
|
26
26
|
|
|
27
|
-
function getPanel(flag: PanelFlags) {
|
|
28
|
-
|
|
29
|
-
}
|
|
27
|
+
// function getPanel(flag: PanelFlags) {
|
|
28
|
+
// return flag === PanelFlags.Start ? startPanel : endPanel;
|
|
29
|
+
// }
|
|
30
30
|
|
|
31
|
-
function reset() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
31
|
+
// function reset() {
|
|
32
|
+
// startPanel.set(type);
|
|
33
|
+
// endPanel.set(type);
|
|
34
|
+
// }
|
|
35
35
|
|
|
36
|
-
instance.on('show', reset);
|
|
36
|
+
// instance.on('show', reset);
|
|
37
37
|
|
|
38
|
-
return {startPanel, endPanel, changePanel, getPanel, reset,
|
|
38
|
+
return {/* startPanel, endPanel, changePanel, getPanel, reset, */startRef, endRef};
|
|
39
39
|
}
|
|
@@ -45,6 +45,9 @@ export function useShowDate(panel: ReturnType<typeof usePanel>) {
|
|
|
45
45
|
|
|
46
46
|
// ensure the start panel's date is before the end panel's
|
|
47
47
|
watchState(showDate, v => {
|
|
48
|
+
// only check on dual panels
|
|
49
|
+
if (!panel.startRef.value || !panel.endRef.value) return
|
|
50
|
+
|
|
48
51
|
if (flag === PanelFlags.Start) {
|
|
49
52
|
const endPanel = anotherPanel.value;
|
|
50
53
|
if (endPanel) {
|
|
@@ -76,61 +79,38 @@ export function useShowDate(panel: ReturnType<typeof usePanel>) {
|
|
|
76
79
|
return date.add(isEnd ? 10 : -10, 'year');
|
|
77
80
|
case 'month':
|
|
78
81
|
return date.add(isEnd ? 1 : -1, 'year');
|
|
79
|
-
break;
|
|
80
82
|
case 'week':
|
|
81
83
|
return date.add(isEnd ? 1 : -1, 'week');
|
|
82
|
-
break;
|
|
83
84
|
case 'quarter':
|
|
84
85
|
return date.add(isEnd ? 1 : -1, 'quarter');
|
|
85
|
-
break;
|
|
86
86
|
default:
|
|
87
87
|
return date.add(isEnd ? 1 : -1, 'month');
|
|
88
|
-
break;
|
|
89
88
|
}
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
function getDateLabel() {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const map: { [key: string]: string } = {
|
|
97
|
-
'MM': _$(`${month}月`), // 月标签
|
|
98
|
-
'YYYY': _$(`{n}年`, {n: year}), // 年标签
|
|
99
|
-
'YYYY MM': _$(`{n}年{y}月`, {n: year, y: month}) // 年月组合标签
|
|
92
|
+
const map = {
|
|
93
|
+
MM: _$(`${showDate.value.get('month') + 1}月`),
|
|
94
|
+
YYYY: _$(`{n}年`, {n: showDate.value.get('year')}),
|
|
100
95
|
};
|
|
101
|
-
|
|
102
|
-
let
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
format = ['YYYY MM']; // week 类型显示年月组合
|
|
106
|
-
break;
|
|
107
|
-
case 'quarter':
|
|
108
|
-
format = ['YYYY']; // quarter 类型仅显示年
|
|
109
|
-
break;
|
|
110
|
-
default:
|
|
111
|
-
let yearMonthFormat = _$('yearMonthFormat');
|
|
112
|
-
if (yearMonthFormat === 'yearMonthFormat') {
|
|
113
|
-
yearMonthFormat = 'YYYY MM'; // 默认格式
|
|
114
|
-
}
|
|
115
|
-
format = yearMonthFormat.split(' '); // 其他类型按配置拆分
|
|
116
|
-
break;
|
|
96
|
+
|
|
97
|
+
let yearMonthFormat = _$('yearMonthFormat');
|
|
98
|
+
if (yearMonthFormat === 'yearMonthFormat') {
|
|
99
|
+
yearMonthFormat = 'YYYY MM';
|
|
117
100
|
}
|
|
101
|
+
|
|
102
|
+
// quarter类型只显示年份
|
|
103
|
+
if (instance.get('type') === 'quarter') {
|
|
104
|
+
yearMonthFormat = 'YYYY';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const format = yearMonthFormat.split(' ') as (keyof typeof map)[];
|
|
118
108
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
onClick: (e: IgnoreClickEvent) => {
|
|
109
|
+
return format.map(item => ({
|
|
110
|
+
value: map[item],
|
|
111
|
+
onClick(e: IgnoreClickEvent) {
|
|
123
112
|
e._ignore = true;
|
|
124
|
-
|
|
125
|
-
if (item === 'YYYY MM') {
|
|
126
|
-
instance.type.set('week'); // 点击年月组合,保持 week
|
|
127
|
-
} else if (item === 'YYYY') {
|
|
128
|
-
instance.type.set(type === 'quarter' ? 'quarter' : 'year'); // 根据当前 type 决定
|
|
129
|
-
} else if (item === 'MM') {
|
|
130
|
-
instance.type.set('month'); // 点击月,切换到 month
|
|
131
|
-
} else {
|
|
132
|
-
instance.type.set('date'); // 默认切换到 date
|
|
133
|
-
}
|
|
113
|
+
instance.type.set(item === 'YYYY' ? 'year' : 'month');
|
|
134
114
|
}
|
|
135
115
|
}));
|
|
136
116
|
}
|
|
@@ -1,41 +1,60 @@
|
|
|
1
1
|
import {useInstance} from 'intact';
|
|
2
2
|
import {State} from '../../hooks/useState';
|
|
3
3
|
import {Dayjs} from 'dayjs';
|
|
4
|
-
import {isGT, isLT, isEqual} from './helpers';
|
|
5
|
-
import type {StateValueItem, StateValueRange} from './
|
|
4
|
+
import {isGT, isLT, isEqual, last} from './helpers';
|
|
5
|
+
import type {StateValueItem, StateValueRange} from './useValueBase';
|
|
6
6
|
import type {DatepickerCalendar, DatepickerCalendarProps} from './calendar';
|
|
7
|
+
import { Position } from './useHighlight';
|
|
7
8
|
|
|
8
9
|
export function useStatus(focusDate: State<Dayjs | null>) {
|
|
9
10
|
const instance = useInstance() as DatepickerCalendar;
|
|
11
|
+
|
|
12
|
+
// if focusDate exists, use it as the active date in range mode
|
|
13
|
+
function getValueByFocusDate() {
|
|
14
|
+
const { value, highlightPosition } = instance.get();
|
|
15
|
+
const { range, multiple } = instance.datepicker.get();
|
|
16
|
+
|
|
17
|
+
if (!focusDate.value || !range || multiple) return value;
|
|
18
|
+
|
|
19
|
+
let lastValue = last(value) as StateValueRange;
|
|
20
|
+
if (!lastValue) return value;
|
|
21
|
+
|
|
22
|
+
lastValue = lastValue.slice() as StateValueRange;
|
|
23
|
+
if (highlightPosition === Position.Start) {
|
|
24
|
+
lastValue[0] = focusDate.value;
|
|
25
|
+
} else {
|
|
26
|
+
lastValue[1] = focusDate.value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return value.slice(0, -1).concat([lastValue]);
|
|
30
|
+
}
|
|
10
31
|
|
|
11
32
|
function isActive(date: Dayjs, type: DatepickerCalendarProps['type']) {
|
|
12
|
-
const
|
|
33
|
+
const _isActive = (values: StateValueItem | StateValueItem[] | undefined): boolean => {
|
|
13
34
|
return Array.isArray(values) ?
|
|
14
|
-
!!(values as StateValueItem[]).find(v =>
|
|
35
|
+
!!(values as StateValueItem[]).find(v => _isActive(v)) :
|
|
15
36
|
isEqual(values, date, type);
|
|
16
37
|
};
|
|
17
|
-
|
|
38
|
+
|
|
39
|
+
return _isActive(getValueByFocusDate());
|
|
18
40
|
}
|
|
19
41
|
|
|
20
42
|
function isInRange(date: Dayjs, type: DatepickerCalendarProps['type']) {
|
|
21
|
-
const {range
|
|
22
|
-
const value =
|
|
43
|
+
const {range} = instance.datepicker.get();
|
|
44
|
+
const value = getValueByFocusDate();
|
|
23
45
|
|
|
24
46
|
if (range) {
|
|
25
|
-
if (!value)
|
|
26
|
-
|
|
27
|
-
}
|
|
47
|
+
if (!value) return false;
|
|
48
|
+
|
|
28
49
|
return (value as StateValueRange[]).some(([start, end]): boolean => {
|
|
29
|
-
if (
|
|
30
|
-
end
|
|
31
|
-
if (end && isLT(end, start, type)) {
|
|
50
|
+
if (start && end) {
|
|
51
|
+
if (isLT(end, start, type)) {
|
|
32
52
|
// maybe the focusDate is less than start date
|
|
33
53
|
const tmp = start;
|
|
34
54
|
start = end;
|
|
35
55
|
end = tmp;
|
|
36
56
|
}
|
|
37
|
-
|
|
38
|
-
if (start && end) {
|
|
57
|
+
|
|
39
58
|
return isGT(date, start, type) && isLT(date, end, type);
|
|
40
59
|
}
|
|
41
60
|
return false;
|
|
@@ -1,121 +1,91 @@
|
|
|
1
1
|
import {useInstance} from 'intact';
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
useValueBase,
|
|
4
4
|
StateValueItem,
|
|
5
5
|
StateValueRange,
|
|
6
6
|
DayjsValueItem,
|
|
7
7
|
DayjsValueRange,
|
|
8
8
|
DayjsValue,
|
|
9
|
-
} from './
|
|
9
|
+
} from './useValueBase';
|
|
10
10
|
import dayjs, {Dayjs} from 'dayjs';
|
|
11
|
-
import {Datepicker} from './index';
|
|
11
|
+
import type {Datepicker} from './index';
|
|
12
12
|
import type {useFormats} from './useFormats';
|
|
13
13
|
import type {useDisabled} from './useDisabled';
|
|
14
14
|
import {last} from '../utils';
|
|
15
15
|
import { endTime } from './helpers';
|
|
16
|
-
import {
|
|
16
|
+
import {PanelFlags, usePanel} from './usePanel';
|
|
17
|
+
import { State } from '../../hooks/useState';
|
|
18
|
+
import { Position } from './useHighlight';
|
|
17
19
|
|
|
18
20
|
export function useValue(
|
|
19
21
|
formats: ReturnType<typeof useFormats>,
|
|
20
22
|
disabled: ReturnType<typeof useDisabled>,
|
|
21
23
|
panel: ReturnType<typeof usePanel>,
|
|
24
|
+
getHighlightPosition: () => State<Position>,
|
|
22
25
|
) {
|
|
23
26
|
const instance = useInstance() as Datepicker;
|
|
24
27
|
|
|
25
|
-
const {setValue, value, ...rest} = useValueBase(
|
|
28
|
+
const {setValue, value, getDayjsValue, allValuesUpdatedInMultipleMode, ...rest} = useValueBase(
|
|
26
29
|
formats,
|
|
27
30
|
disabled,
|
|
28
31
|
panel,
|
|
32
|
+
// shouldUpdateValue
|
|
29
33
|
function(v: StateValueItem) {
|
|
30
34
|
const {type, range} = instance.get();
|
|
31
|
-
|
|
35
|
+
if (type === 'datetime') return false;
|
|
36
|
+
if (range) {
|
|
37
|
+
const [start, end] = v as StateValueRange;
|
|
38
|
+
if (!start || !end || end.isBefore(start)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return true;
|
|
32
44
|
},
|
|
45
|
+
// updateValueOnInput
|
|
33
46
|
function(v: DayjsValueItem) {
|
|
34
47
|
setValue(v, true);
|
|
35
48
|
},
|
|
49
|
+
// getEqualType
|
|
36
50
|
function() {
|
|
37
51
|
const {type} = instance.get();
|
|
38
52
|
return type === 'datetime' ? 'second' : type!;
|
|
39
53
|
},
|
|
54
|
+
// updateStateValue
|
|
40
55
|
function(dayjsValue, value) {
|
|
41
|
-
|
|
42
|
-
instance.get('multiple') &&
|
|
43
|
-
panel.getPanel(PanelFlags.Start).value === PanelTypes.Time
|
|
44
|
-
) {
|
|
45
|
-
value.set(dayjsValue.concat([last(value.value)] as DayjsValue));
|
|
46
|
-
} else {
|
|
47
|
-
value.set(dayjsValue.slice(0));
|
|
48
|
-
}
|
|
56
|
+
value.set(dayjsValue.slice(0));
|
|
49
57
|
}
|
|
50
58
|
);
|
|
51
59
|
|
|
52
60
|
function onChangeDate(v: Dayjs, flag: PanelFlags) {
|
|
53
61
|
const {multiple, type, range} = instance.get();
|
|
54
|
-
const activePosition = instance.activePosition.position.value;
|
|
55
62
|
let _value: StateValueItem;
|
|
63
|
+
|
|
56
64
|
if (range) {
|
|
57
65
|
const oldValue = last(value.value as StateValueRange[]);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
flag = PanelFlags.Start;
|
|
65
|
-
if((type === 'datetime' || type === 'date') && oldValue?.length === 2) {
|
|
66
|
-
// Use activePosition instead of Coordinate
|
|
67
|
-
_value = activePosition === 'end' ?
|
|
68
|
-
[oldValue[0], fixDatetimeWithMinDate(v)] : multiple ?
|
|
69
|
-
[fixDatetimeWithMinDate(v)] :
|
|
70
|
-
[fixDatetimeWithMinDate(v), oldValue[1]];
|
|
71
|
-
} else {
|
|
72
|
-
_value = [fixDatetimeWithMinDate(v)];
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
if (type === 'datetime') {
|
|
76
|
-
if (oldValue.length === 1) {
|
|
77
|
-
// 如果只有开始日期,根据activePosition决定是替换开始日期还是设置结束日期
|
|
78
|
-
_value = activePosition === 'end' ?
|
|
79
|
-
[oldValue[0], fixDatetimeWithMaxDate(v)] :
|
|
80
|
-
[fixDatetimeWithMaxDate(v)];
|
|
81
|
-
} else {
|
|
82
|
-
// oldValue.length === 2的情况
|
|
83
|
-
_value = activePosition === 'end' ?
|
|
84
|
-
[oldValue[0], fixDatetimeWithMaxDate(v)] : multiple ?
|
|
85
|
-
[fixDatetimeWithMaxDate(v)] :
|
|
86
|
-
[fixDatetimeWithMaxDate(v), oldValue[1]];
|
|
87
|
-
}
|
|
66
|
+
const position = getHighlightPosition().value;
|
|
67
|
+
if (!oldValue || allValuesUpdatedInMultipleMode()) {
|
|
68
|
+
_value = [fixDatetimeWithMinDate(v)];
|
|
69
|
+
} else if (position === Position.Start) {
|
|
70
|
+
if (oldValue.length === 1) {
|
|
71
|
+
_value = [fixDatetimeWithMinDate(v)];
|
|
88
72
|
} else {
|
|
89
|
-
_value = [
|
|
73
|
+
_value = [fixDatetimeWithMinDate(v), oldValue[1]];
|
|
90
74
|
}
|
|
91
|
-
|
|
75
|
+
} else {
|
|
76
|
+
_value = [oldValue[0], fixDatetimeWithMaxDate(v)];
|
|
92
77
|
}
|
|
93
|
-
|
|
78
|
+
// fix after selection is completed, refer to the updateValue function in useValueBase
|
|
79
|
+
// (_value as DayjsValueRange).sort((a, b) => a.isAfter(b) ? 1 : -1);
|
|
94
80
|
} else {
|
|
95
81
|
_value = fixDatetimeWithMinDate(v);
|
|
96
82
|
}
|
|
97
83
|
|
|
98
84
|
setValue(_value, false);
|
|
99
85
|
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if ((_value as StateValueRange).length === 2) {
|
|
104
|
-
panel.changePanel(PanelTypes.Time, PanelFlags.Start);
|
|
105
|
-
panel.changePanel(PanelTypes.Time, PanelFlags.End);
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
panel.changePanel(PanelTypes.Time, flag);
|
|
109
|
-
}
|
|
110
|
-
} else if(type === 'week') {
|
|
111
|
-
_value = v.startOf('week')
|
|
112
|
-
setValue(_value, false);
|
|
113
|
-
instance.hide();
|
|
114
|
-
} else if(type === 'quarter') {
|
|
115
|
-
_value = v.startOf('quarter');
|
|
116
|
-
setValue(_value, false);
|
|
117
|
-
instance.hide();
|
|
118
|
-
} else if (!multiple && (!range || (_value as StateValueRange).length === 2)) {
|
|
86
|
+
if (range) {
|
|
87
|
+
instance.trigger('selecting', _value as StateValueRange, false);
|
|
88
|
+
} else if (!multiple && type !== 'datetime') {
|
|
119
89
|
instance.hide();
|
|
120
90
|
}
|
|
121
91
|
}
|
|
@@ -130,17 +100,18 @@ export function useValue(
|
|
|
130
100
|
}
|
|
131
101
|
|
|
132
102
|
function fixDatetimeWithMaxDate(v: Dayjs) {
|
|
133
|
-
// the
|
|
103
|
+
// the time of end datetime should be set to 23:59:59, #878
|
|
104
|
+
// @modify: don't set to 23:59:59 in new UE
|
|
134
105
|
const maxDate = disabled.maxDate.value;
|
|
135
|
-
const date = v.toDate();
|
|
106
|
+
// const date = v.toDate();
|
|
136
107
|
|
|
137
|
-
endTime(date);
|
|
138
|
-
v = dayjs(date);
|
|
108
|
+
// endTime(date);
|
|
109
|
+
// v = dayjs(date);
|
|
139
110
|
if (maxDate && v.isAfter(maxDate)) {
|
|
140
111
|
return maxDate;
|
|
141
112
|
}
|
|
142
113
|
return v;
|
|
143
114
|
}
|
|
144
115
|
|
|
145
|
-
return {value, setValue, onChangeDate, ...rest};
|
|
116
|
+
return {value, setValue, onChangeDate, getDayjsValue, allValuesUpdatedInMultipleMode, ...rest};
|
|
146
117
|
}
|