@king-design/intact 3.5.2 → 3.6.0
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/.DS_Store +0 -0
- package/components/button/index.md +1 -0
- package/components/cascader/index.spec.ts +7 -6
- package/components/datepicker/basepicker.ts +26 -267
- package/components/datepicker/calendar.ts +8 -2
- package/components/datepicker/calendar.vdt +23 -6
- package/components/datepicker/dayjs.ts +8 -2
- package/components/datepicker/demos/multiple.md +1 -1
- package/components/datepicker/demos/yearMonth.md +1 -1
- package/components/datepicker/helpers.ts +10 -12
- package/components/datepicker/index.md +2 -2
- package/components/datepicker/index.spec.ts +619 -190
- package/components/datepicker/index.ts +22 -21
- package/components/datepicker/index.vdt +47 -42
- package/components/datepicker/shortcuts.ts +1 -1
- package/components/datepicker/styles.ts +112 -4
- package/components/datepicker/useConfirm.ts +82 -0
- package/components/datepicker/useDisabled.ts +31 -33
- package/components/datepicker/useFormats.ts +10 -4
- package/components/datepicker/useHighlight.ts +81 -0
- package/components/datepicker/useKeyboards.ts +2 -1
- package/components/datepicker/useMergeRange.ts +54 -0
- package/components/datepicker/useMonths.ts +6 -3
- package/components/datepicker/usePanel.ts +19 -19
- package/components/datepicker/useQuarters.ts +47 -0
- package/components/datepicker/useShowDate.ts +14 -3
- package/components/datepicker/useStatus.ts +34 -15
- package/components/datepicker/useValue.ts +41 -39
- package/components/datepicker/useValueBase.ts +309 -0
- package/components/datepicker/useWeeks.ts +58 -0
- package/components/datepicker/useYears.ts +7 -3
- package/components/descriptions/.DS_Store +0 -0
- package/components/dialog/useFixBody.ts +7 -64
- 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/ellipsis/styles.ts +4 -0
- package/components/form/styles.ts +1 -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/.DS_Store +0 -0
- package/components/menu/demos/.DS_Store +0 -0
- package/components/scrollSelect/index.spec.ts +3 -3
- package/components/scrollSelect/useMouseEvents.ts +24 -10
- package/components/select/base.ts +3 -2
- package/components/select/base.vdt +3 -1
- package/components/select/demos/creatable.md +13 -0
- package/components/select/index.md +1 -0
- package/components/select/index.spec.ts +225 -6
- package/components/select/option.ts +10 -1
- package/components/select/select.ts +3 -0
- package/components/select/styles.ts +3 -1
- package/components/select/useFilterable.ts +1 -1
- package/components/select/useInput.ts +7 -9
- package/components/select/useSearchable.ts +2 -2
- package/components/table/.DS_Store +0 -0
- package/components/table/index.spec.ts +69 -1
- package/components/table/useStickyHeader.ts +1 -1
- package/components/timepicker/demos/step.md +1 -1
- package/components/timepicker/index.spec.ts +145 -27
- package/components/timepicker/panelPicker.ts +10 -4
- package/components/timepicker/panelPicker.vdt +5 -3
- 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/.DS_Store +0 -0
- package/components/tour/demos/basic.md +73 -0
- package/components/tour/demos/beforeChange.md +109 -0
- package/components/tour/demos/closable.md +70 -0
- package/components/tour/demos/custom.md +98 -0
- package/components/tour/demos/customText.md +94 -0
- package/components/tour/demos/declarative.md +72 -0
- package/components/tour/demos/events.md +101 -0
- package/components/tour/demos/maskClosable.md +76 -0
- package/components/tour/demos/notarget.md +59 -0
- package/components/tour/index.md +48 -0
- package/components/tour/index.spec.ts +259 -0
- package/components/tour/index.ts +2 -0
- package/components/tour/step.ts +55 -0
- package/components/tour/step.vdt +75 -0
- package/components/tour/styles.ts +283 -0
- package/components/tour/tour.ts +107 -0
- package/components/tour/tour.vdt +83 -0
- package/components/tour/useArrow.ts +46 -0
- package/components/tour/useFixBody.ts +22 -0
- package/components/tour/useHighlight.ts +36 -0
- package/components/tour/useMaskClosable.ts +26 -0
- package/components/tour/useNavigation.ts +46 -0
- package/components/tour/usePosition.ts +91 -0
- package/components/tour/useSteps.ts +80 -0
- package/components/virtualList/.DS_Store +0 -0
- package/components/virtualList/demos/.DS_Store +0 -0
- package/es/components/cascader/index.spec.js +18 -19
- package/es/components/datepicker/basepicker.d.ts +6 -25
- package/es/components/datepicker/basepicker.js +22 -234
- package/es/components/datepicker/calendar.d.ts +36 -6
- package/es/components/datepicker/calendar.js +4 -0
- package/es/components/datepicker/calendar.vdt.js +21 -5
- package/es/components/datepicker/dayjs.d.ts +2 -2
- package/es/components/datepicker/dayjs.js +6 -0
- package/es/components/datepicker/helpers.d.ts +8 -7
- package/es/components/datepicker/helpers.js +2 -3
- package/es/components/datepicker/index.d.ts +26 -19
- package/es/components/datepicker/index.js +21 -13
- package/es/components/datepicker/index.spec.js +1389 -633
- package/es/components/datepicker/index.vdt.js +43 -46
- package/es/components/datepicker/shortcuts.d.ts +1 -1
- package/es/components/datepicker/styles.d.ts +22 -0
- package/es/components/datepicker/styles.js +26 -4
- package/es/components/datepicker/useConfirm.d.ts +6 -0
- package/es/components/datepicker/useConfirm.js +65 -0
- package/es/components/datepicker/useDisabled.d.ts +7 -5
- package/es/components/datepicker/useDisabled.js +22 -27
- package/es/components/datepicker/useFormats.d.ts +2 -2
- package/es/components/datepicker/useFormats.js +9 -3
- 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 +5 -0
- package/es/components/datepicker/useMergeRange.js +45 -0
- 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/useQuarters.d.ts +15 -0
- package/es/components/datepicker/useQuarters.js +36 -0
- package/es/components/datepicker/useShowDate.js +10 -2
- package/es/components/datepicker/useStatus.d.ts +1 -1
- package/es/components/datepicker/useStatus.js +33 -16
- package/es/components/datepicker/useValue.d.ts +12 -6
- package/es/components/datepicker/useValue.js +49 -45
- package/es/components/datepicker/useValueBase.d.ts +28 -0
- package/es/components/datepicker/useValueBase.js +277 -0
- package/es/components/datepicker/useWeeks.d.ts +19 -0
- package/es/components/datepicker/useWeeks.js +48 -0
- package/es/components/datepicker/useYears.js +6 -3
- package/es/components/dialog/useFixBody.js +6 -58
- package/es/components/dropdown/dropdown.d.ts +1 -0
- package/es/components/dropdown/dropdown.js +7 -4
- package/es/components/ellipsis/styles.js +1 -1
- package/es/components/form/styles.js +1 -1
- 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/scrollSelect/index.spec.js +4 -6
- package/es/components/scrollSelect/useMouseEvents.js +22 -9
- package/es/components/select/base.d.ts +1 -1
- package/es/components/select/base.js +3 -2
- package/es/components/select/base.vdt.js +5 -2
- package/es/components/select/index.spec.js +329 -82
- package/es/components/select/option.d.ts +1 -0
- package/es/components/select/option.js +10 -2
- package/es/components/select/select.d.ts +1 -0
- package/es/components/select/select.js +4 -2
- package/es/components/select/styles.d.ts +79 -0
- package/es/components/select/styles.js +1 -0
- package/es/components/select/useFilterable.js +2 -1
- package/es/components/select/useInput.d.ts +1 -1
- package/es/components/select/useInput.js +7 -4
- package/es/components/select/useSearchable.js +1 -0
- 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 +23 -17
- package/es/components/timepicker/panelPicker.js +7 -4
- package/es/components/timepicker/panelPicker.vdt.js +8 -4
- package/es/components/timepicker/selectPicker.d.ts +5 -4
- 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 +7 -4
- package/es/components/timepicker/useDisabled.js +13 -4
- package/es/components/timepicker/useFormats.d.ts +1 -1
- package/es/components/timepicker/useValue.d.ts +14 -8
- package/es/components/timepicker/useValue.js +14 -15
- package/es/components/tour/index.d.ts +2 -0
- package/es/components/tour/index.js +2 -0
- package/es/components/tour/index.spec.d.ts +1 -0
- package/es/components/tour/index.spec.js +356 -0
- package/es/components/tour/step.d.ts +23 -0
- package/es/components/tour/step.js +46 -0
- package/es/components/tour/step.vdt.js +74 -0
- package/es/components/tour/styles.d.ts +7 -0
- package/es/components/tour/styles.js +84 -0
- package/es/components/tour/tour.d.ts +73 -0
- package/es/components/tour/tour.js +70 -0
- package/es/components/tour/tour.vdt.js +66 -0
- package/es/components/tour/useArrow.d.ts +4 -0
- package/es/components/tour/useArrow.js +40 -0
- package/es/components/tour/useFixBody.d.ts +4 -0
- package/es/components/tour/useFixBody.js +17 -0
- package/es/components/tour/useHighlight.d.ts +4 -0
- package/es/components/tour/useHighlight.js +31 -0
- package/es/components/tour/useMaskClosable.d.ts +1 -0
- package/es/components/tour/useMaskClosable.js +25 -0
- package/es/components/tour/useNavigation.d.ts +5 -0
- package/es/components/tour/useNavigation.js +103 -0
- package/es/components/tour/usePosition.d.ts +6 -0
- package/es/components/tour/usePosition.js +93 -0
- package/es/components/tour/useSteps.d.ts +6 -0
- package/es/components/tour/useSteps.js +68 -0
- package/es/hooks/useFixBody.d.ts +11 -0
- package/es/hooks/useFixBody.js +72 -0
- package/es/index.d.ts +3 -2
- package/es/index.js +3 -2
- package/es/site/data/components/datepicker/demos/multiple/react.js +2 -2
- package/es/site/data/components/select/demos/creatable/index.d.ts +1 -0
- package/es/site/data/components/select/demos/creatable/index.js +2 -1
- package/es/site/data/components/select/demos/creatable/react.d.ts +1 -0
- package/es/site/data/components/select/demos/creatable/react.js +31 -2
- package/es/site/data/components/tour/demos/basic/index.d.ts +17 -0
- package/es/site/data/components/tour/demos/basic/index.js +46 -0
- package/es/site/data/components/tour/demos/basic/react.d.ts +16 -0
- package/es/site/data/components/tour/demos/basic/react.js +82 -0
- package/es/site/data/components/tour/demos/beforeChange/index.d.ts +20 -0
- package/es/site/data/components/tour/demos/beforeChange/index.js +69 -0
- package/es/site/data/components/tour/demos/beforeChange/react.d.ts +19 -0
- package/es/site/data/components/tour/demos/beforeChange/react.js +129 -0
- package/es/site/data/components/tour/demos/closable/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/closable/index.js +42 -0
- package/es/site/data/components/tour/demos/closable/react.d.ts +17 -0
- package/es/site/data/components/tour/demos/closable/react.js +85 -0
- package/es/site/data/components/tour/demos/custom/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/custom/index.js +35 -0
- package/es/site/data/components/tour/demos/custom/react.d.ts +11 -0
- package/es/site/data/components/tour/demos/custom/react.js +108 -0
- package/es/site/data/components/tour/demos/customText/index.d.ts +33 -0
- package/es/site/data/components/tour/demos/customText/index.js +55 -0
- package/es/site/data/components/tour/demos/customText/react.d.ts +33 -0
- package/es/site/data/components/tour/demos/customText/react.js +99 -0
- package/es/site/data/components/tour/demos/declarative/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/declarative/index.js +36 -0
- package/es/site/data/components/tour/demos/declarative/react.d.ts +10 -0
- package/es/site/data/components/tour/demos/declarative/react.js +80 -0
- package/es/site/data/components/tour/demos/events/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/events/index.js +58 -0
- package/es/site/data/components/tour/demos/events/react.d.ts +18 -0
- package/es/site/data/components/tour/demos/events/react.js +101 -0
- package/es/site/data/components/tour/demos/maskClosable/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/maskClosable/index.js +47 -0
- package/es/site/data/components/tour/demos/maskClosable/react.d.ts +17 -0
- package/es/site/data/components/tour/demos/maskClosable/react.js +95 -0
- package/es/site/data/components/tour/demos/notarget/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/notarget/index.js +35 -0
- package/es/site/data/components/tour/demos/notarget/react.d.ts +10 -0
- package/es/site/data/components/tour/demos/notarget/react.js +61 -0
- package/es/site/data/components/tour/index.d.ts +57 -0
- package/es/site/data/components/tour/index.js +32 -0
- package/hooks/useFixBody.ts +87 -0
- package/index.ts +3 -2
- package/package.json +2 -2
- package/styles/.DS_Store +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {useInstance, onMounted, nextTick} from 'intact';
|
|
2
|
+
import type {Datepicker} from '.';
|
|
3
|
+
import { useState, watchState, State } from '../../hooks/useState';
|
|
4
|
+
import {last} from '../utils';
|
|
5
|
+
import { StateValue, StateValueRange, Value } from './useValueBase';
|
|
6
|
+
import dayjs, {Dayjs} from 'dayjs';
|
|
7
|
+
|
|
8
|
+
type FullDatepickerType =
|
|
9
|
+
| Datepicker<Value, true, true>
|
|
10
|
+
| Datepicker<Value, true, false>
|
|
11
|
+
| Datepicker<Value, false, true>
|
|
12
|
+
| Datepicker<Value, false, false>;
|
|
13
|
+
|
|
14
|
+
export enum Position {
|
|
15
|
+
Start,
|
|
16
|
+
End
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const DELIMITER_WIDTH = 14;
|
|
20
|
+
const fakeDate = dayjs();
|
|
21
|
+
|
|
22
|
+
export function useHighlight(
|
|
23
|
+
value: State<StateValue>,
|
|
24
|
+
getShowString: (value: Dayjs) => string,
|
|
25
|
+
keywords: State<string>,
|
|
26
|
+
) {
|
|
27
|
+
const instance = useInstance() as FullDatepickerType;
|
|
28
|
+
const position = useState<Position>(Position.Start);
|
|
29
|
+
const highlightWidth = useState<number>(0);
|
|
30
|
+
const highlightLeft = useState<number>(0);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* calculate the real width by rendering the showString to fake div
|
|
34
|
+
*/
|
|
35
|
+
onMounted(() => {
|
|
36
|
+
const showString = getShowString(fakeDate);
|
|
37
|
+
instance.input.inputRef.value!.getStringWidth(showString).then((width) => {
|
|
38
|
+
highlightWidth.set(width);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* change the left of style on position changed
|
|
44
|
+
*/
|
|
45
|
+
watchState(position, (position) => {
|
|
46
|
+
highlightLeft.set(position === Position.Start ? 0 : highlightWidth.value + DELIMITER_WIDTH);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// if value is cleared reset the position to start
|
|
50
|
+
instance.watch('value', (v) => {
|
|
51
|
+
if (!v || Array.isArray(v) && !v.length) {
|
|
52
|
+
position.set(Position.Start);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
function handleInputClick() {
|
|
57
|
+
const { range, type } = instance.get();
|
|
58
|
+
if (!range) return;
|
|
59
|
+
|
|
60
|
+
const cursorPosition = instance.input.inputRef.value!.getSelectionStart();
|
|
61
|
+
|
|
62
|
+
const showString = getShowString(fakeDate);
|
|
63
|
+
if (!cursorPosition || cursorPosition <= showString.length + 1 /* one whitespace */) {
|
|
64
|
+
position.set(Position.Start);
|
|
65
|
+
} else {
|
|
66
|
+
position.set(Position.End);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function togglePosition() {
|
|
71
|
+
position.set(position.value === Position.Start ? Position.End : Position.Start);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
position,
|
|
76
|
+
handleInputClick,
|
|
77
|
+
togglePosition,
|
|
78
|
+
highlightWidth,
|
|
79
|
+
highlightLeft,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -92,7 +92,8 @@ export function useKeyboards(
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
let _focusDate = focusDate.value;
|
|
95
|
-
|
|
95
|
+
const unit = type === 'date' ? 'day' : type;
|
|
96
|
+
_focusDate = _focusDate.add(offset, unit as any);
|
|
96
97
|
focusDate.set(_focusDate);
|
|
97
98
|
|
|
98
99
|
// change panel show date
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {useInstance} from 'intact';
|
|
2
|
+
import {Dayjs} from './dayjs';
|
|
3
|
+
import type {Datepicker} from './index';
|
|
4
|
+
import {DayjsValueRange, DayjsValue} from './useValueBase';
|
|
5
|
+
import type {useFormats} from './useFormats';
|
|
6
|
+
|
|
7
|
+
// TODO isMerge
|
|
8
|
+
export function useMergeRange(formats: ReturnType<typeof useFormats>) {
|
|
9
|
+
const instance = useInstance() as Datepicker;
|
|
10
|
+
|
|
11
|
+
function _mergeRanges(dayjsValue: DayjsValue, getShowString: (value: Dayjs) => string) {
|
|
12
|
+
const ranges = dayjsValue
|
|
13
|
+
.filter(Array.isArray)
|
|
14
|
+
.map(range => ({
|
|
15
|
+
start: (range as DayjsValueRange)[0],
|
|
16
|
+
end: (range as DayjsValueRange)[1]
|
|
17
|
+
}))
|
|
18
|
+
.sort((a, b) => a.start.valueOf() - b.start.valueOf());
|
|
19
|
+
|
|
20
|
+
if (ranges.length === 0) return [];
|
|
21
|
+
|
|
22
|
+
// 合并有交集的时间范围
|
|
23
|
+
const mergedRange = ranges.reduce((acc, curr) => {
|
|
24
|
+
if (!acc) return curr;
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
start: acc.start,
|
|
28
|
+
end: curr.end.valueOf() > acc.end.valueOf() ? curr.end : acc.end
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return [`${getShowString(mergedRange.start)} ~ ${getShowString(mergedRange.end)}`];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function formatMultipleValues(dayjsValue: DayjsValue, results: string[]): string[] {
|
|
36
|
+
// const {isMerge, nowrap} = instance.get();
|
|
37
|
+
|
|
38
|
+
// if (isMerge && nowrap) {
|
|
39
|
+
// const mergedResults = _mergeRanges(dayjsValue, (v: Dayjs) => v.format(formats.getShowFormat()));
|
|
40
|
+
// if (mergedResults.length > 0) {
|
|
41
|
+
// return [
|
|
42
|
+
// ...mergedResults,
|
|
43
|
+
// ...results.slice(1).map((result, index) => `${result}-${index}`)
|
|
44
|
+
// ];
|
|
45
|
+
// }
|
|
46
|
+
// }
|
|
47
|
+
|
|
48
|
+
return results;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
formatMultipleValues
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {useInstance} from 'intact';
|
|
2
|
+
import dayjs, {Dayjs} from 'dayjs';
|
|
3
|
+
import {isEqual} from './helpers';
|
|
4
|
+
import type {DatepickerCalendar} from './calendar';
|
|
5
|
+
import {State} from '../../hooks/useState';
|
|
6
|
+
import {_$} from '../../i18n';
|
|
7
|
+
import type {useStatus} from './useStatus';
|
|
8
|
+
|
|
9
|
+
export function useQuarters(
|
|
10
|
+
showDate: State<Dayjs>,
|
|
11
|
+
status: ReturnType<typeof useStatus>,
|
|
12
|
+
focusDate: State<Dayjs | null>
|
|
13
|
+
) {
|
|
14
|
+
const instance = useInstance() as DatepickerCalendar;
|
|
15
|
+
|
|
16
|
+
function getQuarters(now: Dayjs) {
|
|
17
|
+
const ret = [];
|
|
18
|
+
const year = showDate.value.year();
|
|
19
|
+
|
|
20
|
+
for (let i = 1; i <= 4; i++) {
|
|
21
|
+
const quarterStart = dayjs().year(year).quarter(i).startOf('quarter');
|
|
22
|
+
|
|
23
|
+
ret.push({
|
|
24
|
+
isActive: status.isActive(quarterStart, 'quarter'),
|
|
25
|
+
isToday: now.isSame(quarterStart, 'quarter'),
|
|
26
|
+
isDisabled: status.isDisabled(quarterStart),
|
|
27
|
+
isHover: isEqual(quarterStart, focusDate.value, 'quarter'),
|
|
28
|
+
isInRange: status.isInRange(quarterStart, 'quarter'),
|
|
29
|
+
label: _$(`Q${i}`),
|
|
30
|
+
value: quarterStart,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return ret;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function onClick(date: Dayjs) {
|
|
38
|
+
const quarterStart = date.startOf('quarter');
|
|
39
|
+
showDate.set(quarterStart);
|
|
40
|
+
const datepickerType = instance.datepicker.get('type');
|
|
41
|
+
if (datepickerType === 'quarter') {
|
|
42
|
+
instance.triggerChange(quarterStart);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return {getQuarters, onClick};
|
|
47
|
+
}
|
|
@@ -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,10 +79,12 @@ 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
|
-
|
|
82
|
+
case 'week':
|
|
83
|
+
return date.add(isEnd ? 1 : -1, 'week');
|
|
84
|
+
case 'quarter':
|
|
85
|
+
return date.add(isEnd ? 1 : -1, 'quarter');
|
|
80
86
|
default:
|
|
81
87
|
return date.add(isEnd ? 1 : -1, 'month');
|
|
82
|
-
break;
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
|
|
@@ -88,11 +93,17 @@ export function useShowDate(panel: ReturnType<typeof usePanel>) {
|
|
|
88
93
|
MM: _$(`${showDate.value.get('month') + 1}月`),
|
|
89
94
|
YYYY: _$(`{n}年`, {n: showDate.value.get('year')}),
|
|
90
95
|
};
|
|
91
|
-
|
|
96
|
+
|
|
92
97
|
let yearMonthFormat = _$('yearMonthFormat');
|
|
93
98
|
if (yearMonthFormat === 'yearMonthFormat') {
|
|
94
99
|
yearMonthFormat = 'YYYY MM';
|
|
95
100
|
}
|
|
101
|
+
|
|
102
|
+
// quarter类型只显示年份
|
|
103
|
+
if (instance.get('type') === 'quarter') {
|
|
104
|
+
yearMonthFormat = 'YYYY';
|
|
105
|
+
}
|
|
106
|
+
|
|
96
107
|
const format = yearMonthFormat.split(' ') as (keyof typeof map)[];
|
|
97
108
|
|
|
98
109
|
return format.map(item => ({
|
|
@@ -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,51 +1,59 @@
|
|
|
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
|
|
|
@@ -55,36 +63,29 @@ export function useValue(
|
|
|
55
63
|
|
|
56
64
|
if (range) {
|
|
57
65
|
const oldValue = last(value.value as StateValueRange[]);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* if we select the first value or re-select the value
|
|
61
|
-
* no matter what the flag is, we should set flag to start panel
|
|
62
|
-
* #877
|
|
63
|
-
*/
|
|
64
|
-
flag = PanelFlags.Start;
|
|
66
|
+
const position = getHighlightPosition().value;
|
|
67
|
+
if (!oldValue || allValuesUpdatedInMultipleMode()) {
|
|
65
68
|
_value = [fixDatetimeWithMinDate(v)];
|
|
69
|
+
} else if (position === Position.Start) {
|
|
70
|
+
if (oldValue.length === 1) {
|
|
71
|
+
_value = [fixDatetimeWithMinDate(v)];
|
|
72
|
+
} else {
|
|
73
|
+
_value = [fixDatetimeWithMinDate(v), oldValue[1]];
|
|
74
|
+
}
|
|
66
75
|
} else {
|
|
67
76
|
_value = [oldValue[0], fixDatetimeWithMaxDate(v)];
|
|
68
|
-
(_value as DayjsValueRange).sort((a, b) => a.isAfter(b) ? 1 : -1);
|
|
69
77
|
}
|
|
70
|
-
|
|
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);
|
|
71
80
|
} else {
|
|
72
81
|
_value = fixDatetimeWithMinDate(v);
|
|
73
82
|
}
|
|
74
83
|
|
|
75
84
|
setValue(_value, false);
|
|
76
85
|
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if ((_value as StateValueRange).length === 2) {
|
|
81
|
-
panel.changePanel(PanelTypes.Time, PanelFlags.Start);
|
|
82
|
-
panel.changePanel(PanelTypes.Time, PanelFlags.End);
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
panel.changePanel(PanelTypes.Time, flag);
|
|
86
|
-
}
|
|
87
|
-
} 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') {
|
|
88
89
|
instance.hide();
|
|
89
90
|
}
|
|
90
91
|
}
|
|
@@ -99,17 +100,18 @@ export function useValue(
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
function fixDatetimeWithMaxDate(v: Dayjs) {
|
|
102
|
-
// 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
|
|
103
105
|
const maxDate = disabled.maxDate.value;
|
|
104
|
-
const date = v.toDate();
|
|
106
|
+
// const date = v.toDate();
|
|
105
107
|
|
|
106
|
-
endTime(date);
|
|
107
|
-
v = dayjs(date);
|
|
108
|
+
// endTime(date);
|
|
109
|
+
// v = dayjs(date);
|
|
108
110
|
if (maxDate && v.isAfter(maxDate)) {
|
|
109
111
|
return maxDate;
|
|
110
112
|
}
|
|
111
113
|
return v;
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
return {value, setValue, onChangeDate, ...rest};
|
|
116
|
+
return {value, setValue, onChangeDate, getDayjsValue, allValuesUpdatedInMultipleMode, ...rest};
|
|
115
117
|
}
|