@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
|
Binary file
|
|
@@ -35,6 +35,7 @@ sidebar: doc
|
|
|
35
35
|
| fluid | 是否宽度100% | `boolean` | `false` |
|
|
36
36
|
| seperate | 是否展示间隔,此属性为错别字,将会在下个版本被删除,请使用正确的属性 `separate`,若两个属性同时使用,则会优先使用`separate`属性 | `boolean` | `false` |
|
|
37
37
|
| separate | 是否展示间隔 | `boolean` | `false` |
|
|
38
|
+
| btnWidth | 指定按钮组每个按钮的固定宽度,默认根据内容撑开 | `number` | `string` | `undefined` |
|
|
38
39
|
|
|
39
40
|
# 方法
|
|
40
41
|
|
|
@@ -104,13 +104,14 @@ describe('Cascader', () => {
|
|
|
104
104
|
input.click();
|
|
105
105
|
await wait();
|
|
106
106
|
|
|
107
|
+
// FIXME: maybe we should show no-data layer
|
|
107
108
|
// should show layer when input empty string
|
|
108
|
-
input.value = ' ';
|
|
109
|
-
dispatchEvent(input, 'input');
|
|
110
|
-
await wait();
|
|
111
|
-
const dropdown = getElement('.k-cascader-menu')!;
|
|
112
|
-
expect(dropdown.innerHTML).to.matchSnapshot();
|
|
113
|
-
expect(dropdown.innerText).to.eql('北京\n湖南');
|
|
109
|
+
// input.value = ' ';
|
|
110
|
+
// dispatchEvent(input, 'input');
|
|
111
|
+
// await wait();
|
|
112
|
+
// const dropdown = getElement('.k-cascader-menu')!;
|
|
113
|
+
// expect(dropdown.innerHTML).to.matchSnapshot();
|
|
114
|
+
// expect(dropdown.innerText).to.eql('北京\n湖南');
|
|
114
115
|
|
|
115
116
|
input.value = '长沙';
|
|
116
117
|
dispatchEvent(input, 'input');
|
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The base hook for handling value of Datepicker and Timepicker
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import dayjs, {Dayjs
|
|
7
|
-
import {findValueIndex} from './helpers';
|
|
4
|
+
import {TypeDefs} from 'intact';
|
|
5
|
+
import {State} from '../../hooks/useState';
|
|
6
|
+
import dayjs, {Dayjs} from './dayjs';
|
|
8
7
|
import type {useFormats} from './useFormats';
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {PanelTypes, PanelFlags, usePanel} from './usePanel';
|
|
8
|
+
import {last, bind} from '../utils';
|
|
9
|
+
import {usePanel} from './usePanel';
|
|
12
10
|
import {BaseSelect, BaseSelectProps, BaseSelectEvents, BaseSelectBlocks} from '../select/base';
|
|
13
11
|
import type {Events} from '../types';
|
|
14
|
-
|
|
15
|
-
export type StateValueRange = [Dayjs, Dayjs?];
|
|
16
|
-
export type StateValueItem = Dayjs | StateValueRange;
|
|
17
|
-
export type StateValue = StateValueItem[]
|
|
18
|
-
|
|
19
|
-
export type StringValue = string | string[] | [string, string] | [string, string][]
|
|
20
|
-
export type DayjsValueRange = [Dayjs, Dayjs]
|
|
21
|
-
export type DayjsValueItem = Dayjs | DayjsValueRange
|
|
22
|
-
export type DayjsValue = DayjsValueItem[]
|
|
12
|
+
import type {useValueBase, StateValueRange, DayjsValueRange, Value} from './useValueBase';
|
|
23
13
|
|
|
24
14
|
export interface BasePickerProps<
|
|
25
15
|
V extends Value = Value,
|
|
@@ -44,7 +34,7 @@ export interface BasePickerProps<
|
|
|
44
34
|
}
|
|
45
35
|
|
|
46
36
|
export interface BasePickerEvents extends BaseSelectEvents {
|
|
47
|
-
selecting: [StateValueRange]
|
|
37
|
+
selecting: [StateValueRange, boolean],
|
|
48
38
|
}
|
|
49
39
|
|
|
50
40
|
export interface BasePickerBlocks<
|
|
@@ -52,8 +42,6 @@ export interface BasePickerBlocks<
|
|
|
52
42
|
R extends boolean = boolean,
|
|
53
43
|
> extends BaseSelectBlocks<R extends true ? [Value, Value] : Value> { }
|
|
54
44
|
|
|
55
|
-
export type Value = string | Date | number | Dayjs;
|
|
56
|
-
|
|
57
45
|
const typeDefs: Required<TypeDefs<BasePickerProps<Value>>> = {
|
|
58
46
|
...BaseSelect.typeDefs,
|
|
59
47
|
value: [String, Array, Date, Number, dayjs],
|
|
@@ -85,25 +73,30 @@ export abstract class BasePicker<
|
|
|
85
73
|
static defaults = defaults;
|
|
86
74
|
static events = events;
|
|
87
75
|
|
|
88
|
-
public abstract value: ReturnType<typeof
|
|
76
|
+
public abstract value: ReturnType<typeof useValueBase>
|
|
89
77
|
public abstract formats: ReturnType<typeof useFormats>
|
|
90
78
|
public abstract panel: ReturnType<typeof usePanel>
|
|
91
79
|
|
|
92
80
|
@bind
|
|
93
|
-
public resetKeywords(
|
|
94
|
-
const {multiple
|
|
95
|
-
const dayjsValue = this.value.getDayjsValue();
|
|
96
|
-
const
|
|
97
|
-
const
|
|
81
|
+
public resetKeywords(silent: boolean = false) {
|
|
82
|
+
// const {multiple} = this.get();
|
|
83
|
+
// const dayjsValue = this.value.getDayjsValue();
|
|
84
|
+
const value = last(this.value.value.value);
|
|
85
|
+
const keywords = this.input.keywords;
|
|
86
|
+
|
|
87
|
+
let _keywords = '';
|
|
88
|
+
if (value && !this.value.allValuesUpdatedInMultipleMode()) {
|
|
89
|
+
_keywords = this.value.formatSingleValue(value);
|
|
90
|
+
}
|
|
98
91
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
92
|
+
if (!silent) {
|
|
93
|
+
keywords.set(_keywords);
|
|
94
|
+
} else {
|
|
95
|
+
// update keywords will update value, because it is been watched in useValueBase
|
|
96
|
+
// silent in this case to update keywords to show it in input
|
|
97
|
+
(keywords as any).value = _keywords;
|
|
98
|
+
this.forceUpdate();
|
|
99
|
+
}
|
|
107
100
|
}
|
|
108
101
|
|
|
109
102
|
// @bind
|
|
@@ -113,237 +106,3 @@ export abstract class BasePicker<
|
|
|
113
106
|
// }
|
|
114
107
|
}
|
|
115
108
|
|
|
116
|
-
export function useValue(
|
|
117
|
-
{
|
|
118
|
-
createDateByValueFormat,
|
|
119
|
-
createDateByShowFormat,
|
|
120
|
-
getShowString,
|
|
121
|
-
getValueString,
|
|
122
|
-
}: ReturnType<typeof useFormats>,
|
|
123
|
-
{isDisabled, minDate}: ReturnType<typeof useDisabled>,
|
|
124
|
-
panel: ReturnType<typeof usePanel>,
|
|
125
|
-
shouldUpdateValue: (v: StateValueItem) => boolean,
|
|
126
|
-
updateValueOnInput: (v: DayjsValueItem) => void,
|
|
127
|
-
getEqualType: () => OpUnitType,
|
|
128
|
-
updateStateValue: (v: DayjsValue, value: State<StateValue>) => void,
|
|
129
|
-
) {
|
|
130
|
-
// Normalize the value to multipe values, no matter it's multipe or not
|
|
131
|
-
const value = useState<StateValue>([]);
|
|
132
|
-
const instance = useInstance() as BasePicker<BasePickerProps<Value>>;
|
|
133
|
-
let dayjsValue: DayjsValue = [];
|
|
134
|
-
|
|
135
|
-
instance.watch('value', (newValue, oldValue) => {
|
|
136
|
-
if (isEqualArray(newValue, oldValue)) return;
|
|
137
|
-
dayjsValue = convertToDayjs(newValue);
|
|
138
|
-
updateStateValue(dayjsValue, value);
|
|
139
|
-
// should update keywords
|
|
140
|
-
instance.resetKeywords(instance.input.keywords);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
watchState(instance.input.keywords, v => {
|
|
144
|
-
const {range, multiple} = instance.get();
|
|
145
|
-
if (!multiple && v === '') return instance.set('value', null);
|
|
146
|
-
|
|
147
|
-
if (range) {
|
|
148
|
-
const [start, end] = v.split(/\s*~\s*/).map(s => s.trim());
|
|
149
|
-
if (start && end) {
|
|
150
|
-
const startDate = createDateByShowFormat(start);
|
|
151
|
-
if (!isValidDate(startDate)) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const endDate = createDateByShowFormat(end);
|
|
155
|
-
if (!isValidDate(endDate)) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (endDate.isAfter(startDate)) {
|
|
159
|
-
updateValueOnInput([startDate, endDate]);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
const date = createDateByShowFormat(v);
|
|
164
|
-
if (isValidDate(date)) {
|
|
165
|
-
updateValueOnInput(date);
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
function convertToDayjs(v: BasePickerProps<Value>['value']): DayjsValue {
|
|
171
|
-
if (!v || Array.isArray(v) && !v.length) return [];
|
|
172
|
-
|
|
173
|
-
const {multiple} = instance.get();
|
|
174
|
-
if (!multiple) {
|
|
175
|
-
v = [v] as any;
|
|
176
|
-
}
|
|
177
|
-
return (v as (Value | [Value, Value])[]).map(value => {
|
|
178
|
-
if (Array.isArray(value)) {
|
|
179
|
-
// range
|
|
180
|
-
return value.map(createDateByValueFormat);
|
|
181
|
-
}
|
|
182
|
-
return createDateByValueFormat(value);
|
|
183
|
-
}) as DayjsValue;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function convertToValueString(v: DayjsValue): StringValue | null {
|
|
187
|
-
const results = v.map(value => {
|
|
188
|
-
if (Array.isArray(value)) {
|
|
189
|
-
return value.map(getValueString);
|
|
190
|
-
}
|
|
191
|
-
return getValueString(value);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
if (!instance.get('multiple')) {
|
|
195
|
-
return results[0] || null;
|
|
196
|
-
}
|
|
197
|
-
return results as StringValue;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function format(): string | string[] {
|
|
201
|
-
const results = dayjsValue.map(value => {
|
|
202
|
-
if (Array.isArray(value)) {
|
|
203
|
-
return value.map(getShowString).join(' ~ ');
|
|
204
|
-
}
|
|
205
|
-
return getShowString(value);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
if (!instance.get('multiple')) {
|
|
209
|
-
return results[0];
|
|
210
|
-
}
|
|
211
|
-
return results;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function setSingleDate(v: StateValueItem, fromInput: boolean) {
|
|
215
|
-
const {range} = instance.get();
|
|
216
|
-
value.set([v]);
|
|
217
|
-
if (fromInput || shouldUpdateValue(v)) {
|
|
218
|
-
updateValue();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
function addMultipeDate(v: StateValueItem, fromInput: boolean) {
|
|
223
|
-
const {range} = instance.get();
|
|
224
|
-
let _value = value.value as StateValueItem[];
|
|
225
|
-
_value = !_value ? [] : _value.slice();
|
|
226
|
-
|
|
227
|
-
if (range && (v as StateValueRange).length === 2) {
|
|
228
|
-
// pop the last value firstly, if it only has the start date
|
|
229
|
-
const lastValue = last(_value);
|
|
230
|
-
if (lastValue && (lastValue as StateValueRange).length < 2) {
|
|
231
|
-
_value.pop();
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
let _shouldUpdateValue = true;
|
|
236
|
-
if (fromInput || shouldUpdateValue(v)) {
|
|
237
|
-
// if select the date/year/month, then toggle the value.
|
|
238
|
-
// if from input, treat the value as the final value
|
|
239
|
-
const index = findValueIndex(_value, v, getEqualType());
|
|
240
|
-
if (index > -1) {
|
|
241
|
-
_value.splice(index, 1);
|
|
242
|
-
} else {
|
|
243
|
-
_value.push(v);
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
// select the datetime, only push the value,
|
|
247
|
-
// and unique the array on click confrim button
|
|
248
|
-
_value.push(v);
|
|
249
|
-
_shouldUpdateValue = false;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
value.set(_value);
|
|
253
|
-
|
|
254
|
-
if (_shouldUpdateValue) {
|
|
255
|
-
updateValue();
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function setValue(v: StateValueItem, fromInput: boolean) {
|
|
260
|
-
const multiple = instance.get('multiple');
|
|
261
|
-
if (multiple) {
|
|
262
|
-
addMultipeDate(v, fromInput);
|
|
263
|
-
} else {
|
|
264
|
-
setSingleDate(v, fromInput);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function updateValue() {
|
|
269
|
-
const _value = value.value as DayjsValue;
|
|
270
|
-
const valueStr = convertToValueString(_value);
|
|
271
|
-
instance.set('value', valueStr);
|
|
272
|
-
instance.resetKeywords(instance.input.keywords);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function onConfirm() {
|
|
276
|
-
// unique
|
|
277
|
-
if (!instance.get('multiple')) {
|
|
278
|
-
instance.hide();
|
|
279
|
-
} else {
|
|
280
|
-
unique();
|
|
281
|
-
panel.reset();
|
|
282
|
-
}
|
|
283
|
-
updateValue();
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
function unique() {
|
|
287
|
-
const _value = value.value;
|
|
288
|
-
const map: Record<string, true> = {};
|
|
289
|
-
const results: StateValue = [];
|
|
290
|
-
_value.forEach(value => {
|
|
291
|
-
let key: string;
|
|
292
|
-
if (Array.isArray(value)) {
|
|
293
|
-
key = (value as DayjsValueRange).map(getValueString).join(' ~ ');
|
|
294
|
-
} else {
|
|
295
|
-
key = getValueString(value);
|
|
296
|
-
}
|
|
297
|
-
if (!map[key]) {
|
|
298
|
-
map[key] = true;
|
|
299
|
-
results.push(value);
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
value.set(results);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
function isValidDate(date: Dayjs) {
|
|
307
|
-
return date.isValid() && !isDisabled(date, getEqualType());
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
function onChangeTime(date: Dayjs, flag: PanelFlags) {
|
|
311
|
-
const {range} = instance.get();
|
|
312
|
-
const values = value.value.slice();
|
|
313
|
-
const lastIndex = values.length - 1;
|
|
314
|
-
let _value: StateValueItem = date;
|
|
315
|
-
|
|
316
|
-
if (range) {
|
|
317
|
-
_value = (values as DayjsValueRange[])[lastIndex].slice() as DayjsValueRange;
|
|
318
|
-
_value[flag] = date;
|
|
319
|
-
instance.trigger('selecting', _value);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
values[lastIndex] = _value;
|
|
323
|
-
value.set(values);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function getTimeValue(flag: PanelFlags): Dayjs | null | undefined {
|
|
327
|
-
const _value = value.value;
|
|
328
|
-
if (!_value.length) return null;
|
|
329
|
-
|
|
330
|
-
const {range, min} = instance.get();
|
|
331
|
-
const lastValue = last(_value);
|
|
332
|
-
return range ? (lastValue as StateValueRange)[flag] : lastValue as Dayjs;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function getDayjsValue() {
|
|
336
|
-
return dayjsValue;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return {
|
|
340
|
-
value,
|
|
341
|
-
format,
|
|
342
|
-
onConfirm,
|
|
343
|
-
onChangeTime,
|
|
344
|
-
getTimeValue,
|
|
345
|
-
setValue,
|
|
346
|
-
convertToDayjs,
|
|
347
|
-
getDayjsValue,
|
|
348
|
-
};
|
|
349
|
-
}
|
|
@@ -10,15 +10,19 @@ import {useShowDate} from './useShowDate';
|
|
|
10
10
|
import {bind} from '../utils';
|
|
11
11
|
import {useYears} from './useYears';
|
|
12
12
|
import {useMonths} from './useMonths';
|
|
13
|
-
import {
|
|
13
|
+
import {useWeeks} from './useWeeks';
|
|
14
|
+
import {useQuarters} from './useQuarters';
|
|
15
|
+
import type {StateValue} from './useValueBase';
|
|
14
16
|
import {useStatus} from './useStatus';
|
|
15
17
|
import {PanelFlags} from './usePanel';
|
|
16
18
|
import { useConfigContext } from '../config';
|
|
19
|
+
import { Position } from './useHighlight';
|
|
17
20
|
|
|
18
21
|
export interface DatepickerCalendarProps {
|
|
19
22
|
value: StateValue
|
|
20
|
-
type?: 'date' | 'year' | 'month'
|
|
23
|
+
type?: 'date' | 'year' | 'month' | 'week' | 'quarter'
|
|
21
24
|
flag: PanelFlags
|
|
25
|
+
highlightPosition: Position
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
export interface DatepickerCalendarEvents {
|
|
@@ -40,6 +44,8 @@ export class DatepickerCalendar extends Component<DatepickerCalendarProps, Datep
|
|
|
40
44
|
public days = useDays(this.showDate.date, this.status, this.datepicker.focusDate.focusDate);
|
|
41
45
|
public years = useYears(this.showDate.date, this.status, this.datepicker.focusDate.focusDate);
|
|
42
46
|
public months = useMonths(this.showDate.date, this.status, this.datepicker.focusDate.focusDate);
|
|
47
|
+
public weeks = useWeeks(this.showDate.date, this.status, this.datepicker.focusDate.focusDate);
|
|
48
|
+
public quarters = useQuarters(this.showDate.date, this.status, this.datepicker.focusDate.focusDate);
|
|
43
49
|
private config = useConfigContext();
|
|
44
50
|
|
|
45
51
|
@bind
|
|
@@ -7,7 +7,12 @@ import {getNowDate} from './helpers';
|
|
|
7
7
|
|
|
8
8
|
const type = this.type.value;
|
|
9
9
|
const isYear = type === 'year';
|
|
10
|
+
const isWeek = type === 'week';
|
|
11
|
+
const isQuarter = type === 'quarter';
|
|
10
12
|
const isYearOrMonth = isYear || type === 'month';
|
|
13
|
+
const isDateOrDateTime = type === 'date' || type === 'datetime'
|
|
14
|
+
// isDateOrDateTime & isWeek合并
|
|
15
|
+
const showDateWeeks = isDateOrDateTime || isWeek
|
|
11
16
|
const { k } = this.config;
|
|
12
17
|
const classNameObj = {
|
|
13
18
|
[`${k}-datepicker-calendar`]: true,
|
|
@@ -59,7 +64,7 @@ const {
|
|
|
59
64
|
<Button icon type="none" size="small" class={`${k}-prev`}
|
|
60
65
|
tagName="div"
|
|
61
66
|
ev-click={prevMonth}
|
|
62
|
-
v-if={
|
|
67
|
+
v-if={showDateWeeks}
|
|
63
68
|
>
|
|
64
69
|
<Icon class={`${k}-icon-left`} size="small" />
|
|
65
70
|
</Button>
|
|
@@ -79,7 +84,7 @@ const {
|
|
|
79
84
|
<Button icon type="none" size="small" class={`${k}-next`}
|
|
80
85
|
tagName="div"
|
|
81
86
|
ev-click={nextMonth}
|
|
82
|
-
v-if={
|
|
87
|
+
v-if={showDateWeeks}
|
|
83
88
|
>
|
|
84
89
|
<Icon class={`${k}-icon-right`} size="small" />
|
|
85
90
|
</Button>
|
|
@@ -92,20 +97,32 @@ const {
|
|
|
92
97
|
</Button>
|
|
93
98
|
</div>
|
|
94
99
|
</div>
|
|
95
|
-
<template v-if={
|
|
100
|
+
<template v-if={showDateWeeks}>
|
|
96
101
|
<div class={`${k}-weekdays`}>
|
|
97
102
|
<div class={`${k}-weekday`}
|
|
98
103
|
v-for={[_$('日'), _$('一'), _$('二'), _$('三'), _$('四'), _$('五'), _$('六')]}
|
|
99
104
|
>{$value}</div>
|
|
100
105
|
</div>
|
|
101
|
-
<div class={`${k}-
|
|
106
|
+
<div v-if={isWeek} class={`${k}-weeks`} ev-mouseleave={resetFocusDate}>
|
|
107
|
+
<div v-for={this.weeks.getWeeks(now)} class="week-row">
|
|
108
|
+
<div
|
|
109
|
+
class={`${k}-week-number`}
|
|
110
|
+
ev-click={e => {onClickDay($value.days[0].value)}}
|
|
111
|
+
ev-mouseenter={() => focusDate.set($value.days[0].value)}
|
|
112
|
+
>{$value.week}</div>
|
|
113
|
+
{getItems($value.days, onClickDay)}
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
<div v-else class={`${k}-days`} ev-mouseleave={resetFocusDate}>
|
|
102
117
|
{getItems(getDays(now), onClickDay)}
|
|
103
118
|
</div>
|
|
104
119
|
</template>
|
|
105
120
|
<div v-else class={`${k}-years`} ev-mouseleave={resetFocusDate}>
|
|
106
121
|
{isYear ?
|
|
107
|
-
getItems(this.years.getYears(now), this.years.onClick) :
|
|
108
|
-
|
|
122
|
+
getItems(this.years.getYears(now), this.years.onClick) :
|
|
123
|
+
isQuarter ?
|
|
124
|
+
getItems(this.quarters.getQuarters(now), this.quarters.onClick) :
|
|
125
|
+
getItems(this.months.getMonths(now), this.months.onClick)
|
|
109
126
|
}
|
|
110
127
|
</div>
|
|
111
128
|
</div>
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import dayjs, {Dayjs, OpUnitType} from 'dayjs';
|
|
1
|
+
import dayjs, {Dayjs, OpUnitType, QUnitType} from 'dayjs';
|
|
2
|
+
import weekOfYear from 'dayjs/plugin/weekOfYear'
|
|
3
|
+
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
2
4
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
5
|
+
import advancedFormat from 'dayjs/plugin/advancedFormat';
|
|
3
6
|
|
|
4
7
|
dayjs.extend(customParseFormat);
|
|
8
|
+
dayjs.extend(weekOfYear);
|
|
9
|
+
dayjs.extend(quarterOfYear);
|
|
10
|
+
dayjs.extend(advancedFormat);
|
|
5
11
|
|
|
6
12
|
export default dayjs;
|
|
7
|
-
export type {Dayjs, OpUnitType};
|
|
13
|
+
export type {Dayjs, OpUnitType, QUnitType};
|
|
@@ -24,7 +24,7 @@ import {Datepicker} from 'kpc';
|
|
|
24
24
|
<Datepicker multiple range v-model="dateRange" />
|
|
25
25
|
You selected: {JSON.stringify(this.get('dateRange'))}
|
|
26
26
|
<br /><br />
|
|
27
|
-
<Datepicker multiple range v-model="datetimeRange"
|
|
27
|
+
<Datepicker multiple range type="datetime" v-model="datetimeRange" />
|
|
28
28
|
You selected: {JSON.stringify(this.get('datetimeRange'))}
|
|
29
29
|
<br /><br />
|
|
30
30
|
</div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import dayjs, {Dayjs, OpUnitType} from 'dayjs';
|
|
2
|
-
import {strPad, range} from '../utils';
|
|
1
|
+
import dayjs, {Dayjs, OpUnitType, QUnitType} from 'dayjs';
|
|
2
|
+
import {strPad, range, last} from '../utils';
|
|
3
3
|
import {_$} from '../../i18n';
|
|
4
|
-
import {StateValueItem} from './
|
|
4
|
+
import {StateValueItem} from './useValueBase';
|
|
5
5
|
|
|
6
6
|
export function getNowDate(isEnd?: boolean) {
|
|
7
7
|
// only date without time
|
|
@@ -28,10 +28,10 @@ export function endTime(date: Date) {
|
|
|
28
28
|
export function isEqual(
|
|
29
29
|
a: Dayjs | undefined | null,
|
|
30
30
|
b: Dayjs | undefined | null,
|
|
31
|
-
type: OpUnitType = 'date'
|
|
31
|
+
type: OpUnitType | QUnitType = 'date'
|
|
32
32
|
) {
|
|
33
33
|
if (a && b) {
|
|
34
|
-
return a.isSame(b, type);
|
|
34
|
+
return a.isSame(b, type as any);
|
|
35
35
|
}
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
@@ -39,10 +39,10 @@ export function isEqual(
|
|
|
39
39
|
export function isLT(
|
|
40
40
|
a: Dayjs | undefined | null,
|
|
41
41
|
b: Dayjs | undefined | null,
|
|
42
|
-
type: OpUnitType = 'date'
|
|
42
|
+
type: OpUnitType | QUnitType = 'date'
|
|
43
43
|
) {
|
|
44
44
|
if (a && b) {
|
|
45
|
-
return a.isBefore(b, type);
|
|
45
|
+
return a.isBefore(b, type as any);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
return false;
|
|
@@ -51,7 +51,7 @@ export function isLT(
|
|
|
51
51
|
export function isGT(
|
|
52
52
|
a: Dayjs | undefined | null,
|
|
53
53
|
b: Dayjs | undefined | null,
|
|
54
|
-
type: OpUnitType = 'date'
|
|
54
|
+
type: OpUnitType | QUnitType = 'date'
|
|
55
55
|
) {
|
|
56
56
|
return isLT(b, a, type);
|
|
57
57
|
}
|
|
@@ -70,7 +70,7 @@ export function createDate(date: string) {
|
|
|
70
70
|
return new Date(date);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
export function findValueIndex(values: StateValueItem[], value: StateValueItem, type: OpUnitType) {
|
|
73
|
+
export function findValueIndex(values: StateValueItem[], value: StateValueItem, type: OpUnitType | QUnitType) {
|
|
74
74
|
return values.findIndex(item => {
|
|
75
75
|
if (Array.isArray(item)) {
|
|
76
76
|
// is multipe range values
|
|
@@ -82,6 +82,4 @@ export function findValueIndex(values: StateValueItem[], value: StateValueItem,
|
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
export
|
|
86
|
-
return arr[arr.length - 1];
|
|
87
|
-
}
|
|
85
|
+
export { last }
|
|
@@ -28,13 +28,13 @@ sidebar: doc
|
|
|
28
28
|
| max | 最大可选日期 | `Value` | `undefind` |
|
|
29
29
|
| min | 最小可选日期 | `Value` | `undefind` |
|
|
30
30
|
| disabledDate | 该属性值是一个函数,用于定义那些日期被禁止选择,函数参数为日期字符串,返回`true`则表示禁用该日期 | `(v: Dayjs) => boolean` | `undefined` |
|
|
31
|
-
| type | 组件类型:`"date"` 只选择日期;`"datetime"` 选择日期和时间;`"year"` 选择年份;`"month"` 选择月份 |
|
|
31
|
+
| type | 组件类型:`"date"` 只选择日期;`"datetime"` 选择日期和时间;`"year"` 选择年份;`"month"` 选择月份 | | `"datetime"` | `"year"` | `"month"` | `"date"` |
|
|
32
32
|
| shortcuts | 指定快捷方式 | `Shortcut[]` | `undefined` |
|
|
33
33
|
| show | 是否展示菜单项 | `boolean` | `false` |
|
|
34
34
|
| position | 菜单弹出的位置,默认与触发器左侧对齐向下偏移`8px`的地方 | `Position` | `"left"` | `"bottom"` | `"right"` | `"top"` | `{my: 'left top+8', 'left bottom'}` |
|
|
35
35
|
| flat | 是否展示扁平样式 | `boolean` | `false` |
|
|
36
36
|
| draggable | 多选值是否支持拖动排序 | `boolean` | `false` |
|
|
37
|
-
|
|
37
|
+
| nowrap | 日期多选时, 是否换行显示 | `boolean` | `false` |
|
|
38
38
|
```ts
|
|
39
39
|
import {Dayjs} from 'dayjs';
|
|
40
40
|
import {VNode} from 'intact';
|