@king-design/intact 3.6.0-beta.0 → 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/cascader/index.spec.ts +7 -6
- 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 +551 -139
- 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 +309 -0
- package/components/datepicker/useWeeks.ts +1 -1
- package/components/datepicker/useYears.ts +7 -3
- package/components/descriptions/.DS_Store +0 -0
- 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/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/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 +107 -34
- package/components/select/option.ts +2 -1
- package/components/select/select.ts +1 -0
- package/components/select/styles.ts +3 -1
- package/components/select/useInput.ts +5 -9
- 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/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/.DS_Store +0 -0
- package/components/tour/index.spec.ts +1 -1
- 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 -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 +1333 -578
- 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 +277 -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/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/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 +158 -84
- 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/useInput.d.ts +1 -1
- package/es/components/select/useInput.js +4 -4
- 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/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/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/index.ts +2 -2
- package/package.json +2 -2
- package/styles/.DS_Store +0 -0
- 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
|
@@ -1,18 +1,8 @@
|
|
|
1
1
|
import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
|
|
2
2
|
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
3
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
4
|
-
import _trimInstanceProperty from "@babel/runtime-corejs3/core-js/instance/trim";
|
|
5
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
|
|
6
|
-
import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/splice";
|
|
7
3
|
import { __decorate } from "tslib";
|
|
8
|
-
/**
|
|
9
|
-
* The base hook for handling value of Datepicker and Timepicker
|
|
10
|
-
*/
|
|
11
|
-
import { useInstance } from 'intact';
|
|
12
|
-
import { useState, watchState } from '../../hooks/useState';
|
|
13
4
|
import dayjs from './dayjs';
|
|
14
|
-
import {
|
|
15
|
-
import { isEqualArray, last, bind } from '../utils';
|
|
5
|
+
import { last, bind } from '../utils';
|
|
16
6
|
import { BaseSelect } from '../select/base';
|
|
17
7
|
var typeDefs = _extends({}, BaseSelect.typeDefs, {
|
|
18
8
|
value: [String, Array, Date, Number, dayjs],
|
|
@@ -30,8 +20,7 @@ var defaults = function defaults() {
|
|
|
30
20
|
});
|
|
31
21
|
};
|
|
32
22
|
var events = _extends({}, BaseSelect.events, {
|
|
33
|
-
selecting: true
|
|
34
|
-
togglePosition: true
|
|
23
|
+
selecting: true
|
|
35
24
|
});
|
|
36
25
|
export var BasePicker = /*#__PURE__*/function (_BaseSelect) {
|
|
37
26
|
_inheritsLoose(BasePicker, _BaseSelect);
|
|
@@ -39,264 +28,30 @@ export var BasePicker = /*#__PURE__*/function (_BaseSelect) {
|
|
|
39
28
|
return _BaseSelect.apply(this, arguments) || this;
|
|
40
29
|
}
|
|
41
30
|
var _proto = BasePicker.prototype;
|
|
42
|
-
_proto.resetKeywords = function resetKeywords(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var value = last(
|
|
49
|
-
keywords
|
|
31
|
+
_proto.resetKeywords = function resetKeywords(silent) {
|
|
32
|
+
if (silent === void 0) {
|
|
33
|
+
silent = false;
|
|
34
|
+
}
|
|
35
|
+
// const {multiple} = this.get();
|
|
36
|
+
// const dayjsValue = this.value.getDayjsValue();
|
|
37
|
+
var value = last(this.value.value.value);
|
|
38
|
+
var keywords = this.input.keywords;
|
|
39
|
+
var _keywords = '';
|
|
40
|
+
if (value && !this.value.allValuesUpdatedInMultipleMode()) {
|
|
41
|
+
_keywords = this.value.formatSingleValue(value);
|
|
42
|
+
}
|
|
43
|
+
if (!silent) {
|
|
44
|
+
keywords.set(_keywords);
|
|
45
|
+
} else {
|
|
46
|
+
// update keywords will update value, because it is been watched in useValueBase
|
|
47
|
+
// silent in this case to update keywords to show it in input
|
|
48
|
+
keywords.value = _keywords;
|
|
49
|
+
this.forceUpdate();
|
|
50
|
+
}
|
|
50
51
|
};
|
|
51
52
|
return BasePicker;
|
|
52
53
|
}(BaseSelect);
|
|
53
54
|
BasePicker.typeDefs = typeDefs;
|
|
54
55
|
BasePicker.defaults = defaults;
|
|
55
56
|
BasePicker.events = events;
|
|
56
|
-
__decorate([bind], BasePicker.prototype, "resetKeywords", null);
|
|
57
|
-
export function useValue(_ref, _ref2, panel, shouldUpdateValue, updateValueOnInput, getEqualType, updateStateValue) {
|
|
58
|
-
var createDateByValueFormat = _ref.createDateByValueFormat,
|
|
59
|
-
createDateByShowFormat = _ref.createDateByShowFormat,
|
|
60
|
-
getShowString = _ref.getShowString,
|
|
61
|
-
getValueString = _ref.getValueString;
|
|
62
|
-
var isDisabled = _ref2.isDisabled,
|
|
63
|
-
minDate = _ref2.minDate;
|
|
64
|
-
// Normalize the value to multipe values, no matter it's multipe or not
|
|
65
|
-
var value = useState([]);
|
|
66
|
-
var instance = useInstance();
|
|
67
|
-
var dayjsValue = [];
|
|
68
|
-
instance.watch('value', function (newValue, oldValue) {
|
|
69
|
-
if (isEqualArray(newValue, oldValue)) return;
|
|
70
|
-
// 检查是否与当前 dayjsValue 对应的字符串相同,避免循环
|
|
71
|
-
var currentValueStr = convertToValueString(dayjsValue);
|
|
72
|
-
if (newValue === currentValueStr) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// 只执行一次转换和更新逻辑
|
|
76
|
-
var _value = convertToDayjs(newValue);
|
|
77
|
-
dayjsValue = _value;
|
|
78
|
-
updateStateValue(_value, value);
|
|
79
|
-
instance.resetKeywords(instance.input.keywords);
|
|
80
|
-
});
|
|
81
|
-
watchState(instance.input.keywords, function (v) {
|
|
82
|
-
var _instance$get = instance.get(),
|
|
83
|
-
range = _instance$get.range,
|
|
84
|
-
multiple = _instance$get.multiple;
|
|
85
|
-
if (!multiple && v === '') return instance.set('value', null);
|
|
86
|
-
if (range) {
|
|
87
|
-
var _context;
|
|
88
|
-
var _v$split$map = _mapInstanceProperty(_context = v.split(/\s*~\s*/)).call(_context, function (s) {
|
|
89
|
-
return _trimInstanceProperty(s).call(s);
|
|
90
|
-
}),
|
|
91
|
-
start = _v$split$map[0],
|
|
92
|
-
end = _v$split$map[1];
|
|
93
|
-
if (start && end) {
|
|
94
|
-
var startDate = createDateByShowFormat(start);
|
|
95
|
-
if (!isValidDate(startDate)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
var endDate = createDateByShowFormat(end);
|
|
99
|
-
if (!isValidDate(endDate)) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
if (endDate.isAfter(startDate)) {
|
|
103
|
-
updateValueOnInput([startDate, endDate]);
|
|
104
|
-
} else {
|
|
105
|
-
updateValueOnInput([endDate, startDate]);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
var date = createDateByShowFormat(v);
|
|
110
|
-
if (isValidDate(date)) {
|
|
111
|
-
updateValueOnInput(date);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
function convertToDayjs(v) {
|
|
116
|
-
if (!v || Array.isArray(v) && !v.length) return [];
|
|
117
|
-
var _instance$get2 = instance.get(),
|
|
118
|
-
multiple = _instance$get2.multiple;
|
|
119
|
-
if (!multiple) {
|
|
120
|
-
v = [v];
|
|
121
|
-
}
|
|
122
|
-
return _mapInstanceProperty(v).call(v, function (value) {
|
|
123
|
-
if (Array.isArray(value)) {
|
|
124
|
-
// range
|
|
125
|
-
return _mapInstanceProperty(value).call(value, createDateByValueFormat);
|
|
126
|
-
}
|
|
127
|
-
return createDateByValueFormat(value);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
function convertToValueString(v) {
|
|
131
|
-
var results = _mapInstanceProperty(v).call(v, function (value) {
|
|
132
|
-
if (Array.isArray(value)) {
|
|
133
|
-
return _mapInstanceProperty(value).call(value, getValueString);
|
|
134
|
-
}
|
|
135
|
-
return getValueString(value);
|
|
136
|
-
});
|
|
137
|
-
if (!instance.get('multiple')) {
|
|
138
|
-
return results[0] || null;
|
|
139
|
-
}
|
|
140
|
-
return results;
|
|
141
|
-
}
|
|
142
|
-
function format() {
|
|
143
|
-
var results = _mapInstanceProperty(dayjsValue).call(dayjsValue, function (value) {
|
|
144
|
-
if (Array.isArray(value)) {
|
|
145
|
-
return _mapInstanceProperty(value).call(value, getShowString).join(' ~ ');
|
|
146
|
-
}
|
|
147
|
-
return getShowString(value);
|
|
148
|
-
});
|
|
149
|
-
if (!instance.get('multiple')) {
|
|
150
|
-
return results[0];
|
|
151
|
-
}
|
|
152
|
-
return results;
|
|
153
|
-
}
|
|
154
|
-
function setSingleDate(v, fromInput) {
|
|
155
|
-
value.set([v]);
|
|
156
|
-
if (fromInput || shouldUpdateValue(v)) {
|
|
157
|
-
updateValue();
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
function addMultipeDate(v, fromInput) {
|
|
161
|
-
var _instance$get3 = instance.get(),
|
|
162
|
-
range = _instance$get3.range;
|
|
163
|
-
var _value = value.value;
|
|
164
|
-
_value = !_value ? [] : _sliceInstanceProperty(_value).call(_value);
|
|
165
|
-
if (range && v.length === 2) {
|
|
166
|
-
// pop the last value firstly, if it only has the start date
|
|
167
|
-
var lastValue = last(_value);
|
|
168
|
-
if (lastValue && lastValue.length < 2) {
|
|
169
|
-
_value.pop();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
var _shouldUpdateValue = true;
|
|
173
|
-
if (fromInput || shouldUpdateValue(v)) {
|
|
174
|
-
// if select the date/year/month, then toggle the value.
|
|
175
|
-
// if from input, treat the value as the final value
|
|
176
|
-
var index = findValueIndex(_value, v, getEqualType());
|
|
177
|
-
if (index > -1) {
|
|
178
|
-
_spliceInstanceProperty(_value).call(_value, index, 1);
|
|
179
|
-
} else {
|
|
180
|
-
_value.push(v);
|
|
181
|
-
}
|
|
182
|
-
} else {
|
|
183
|
-
// select the datetime, only push the value,
|
|
184
|
-
// and unique the array on click confrim button
|
|
185
|
-
_value.push(v);
|
|
186
|
-
_shouldUpdateValue = false;
|
|
187
|
-
}
|
|
188
|
-
value.set(_value);
|
|
189
|
-
if (_shouldUpdateValue) {
|
|
190
|
-
updateValue();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function setValue(v, fromInput) {
|
|
194
|
-
var multiple = instance.get('multiple');
|
|
195
|
-
if (multiple) {
|
|
196
|
-
addMultipeDate(v, fromInput);
|
|
197
|
-
} else {
|
|
198
|
-
setSingleDate(v, fromInput);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function updateValue() {
|
|
202
|
-
var _value = value.value;
|
|
203
|
-
var valueStr = convertToValueString(_value);
|
|
204
|
-
// 检查是否需要更新,避免循环调用
|
|
205
|
-
if (instance.get('value') === valueStr) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
// 在设置 value 之前先更新 dayjsValue
|
|
209
|
-
dayjsValue = _value;
|
|
210
|
-
instance.set('value', valueStr);
|
|
211
|
-
instance.resetKeywords(instance.input.keywords);
|
|
212
|
-
}
|
|
213
|
-
function onConfirm() {
|
|
214
|
-
var lastValue = last(instance.value.value.value);
|
|
215
|
-
var _instance$get4 = instance.get(),
|
|
216
|
-
multiple = _instance$get4.multiple,
|
|
217
|
-
range = _instance$get4.range;
|
|
218
|
-
if (!multiple) {
|
|
219
|
-
if (range) {
|
|
220
|
-
// 范围选择:需要开始和结束时间都选择完才关闭
|
|
221
|
-
if (lastValue.length === 2) {
|
|
222
|
-
instance.hide();
|
|
223
|
-
}
|
|
224
|
-
instance.trigger('togglePosition');
|
|
225
|
-
} else {
|
|
226
|
-
// 单选:选择完时间就关闭
|
|
227
|
-
if (lastValue) {
|
|
228
|
-
instance.hide();
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
} else {
|
|
232
|
-
unique();
|
|
233
|
-
panel.reset();
|
|
234
|
-
}
|
|
235
|
-
updateValue();
|
|
236
|
-
}
|
|
237
|
-
function setMoment() {
|
|
238
|
-
var now = dayjs();
|
|
239
|
-
setValue(now, true);
|
|
240
|
-
instance.hide();
|
|
241
|
-
}
|
|
242
|
-
function unique() {
|
|
243
|
-
var _value = value.value;
|
|
244
|
-
var map = {};
|
|
245
|
-
var results = [];
|
|
246
|
-
_value.forEach(function (value) {
|
|
247
|
-
var key;
|
|
248
|
-
if (Array.isArray(value)) {
|
|
249
|
-
key = _mapInstanceProperty(value).call(value, getValueString).join(' ~ ');
|
|
250
|
-
} else {
|
|
251
|
-
key = getValueString(value);
|
|
252
|
-
}
|
|
253
|
-
if (!map[key]) {
|
|
254
|
-
map[key] = true;
|
|
255
|
-
results.push(value);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
value.set(results);
|
|
259
|
-
}
|
|
260
|
-
function isValidDate(date) {
|
|
261
|
-
return date.isValid() && !isDisabled(date, getEqualType());
|
|
262
|
-
}
|
|
263
|
-
function onChangeTime(date, flag) {
|
|
264
|
-
var _context2;
|
|
265
|
-
var _instance$get5 = instance.get(),
|
|
266
|
-
range = _instance$get5.range;
|
|
267
|
-
var values = _sliceInstanceProperty(_context2 = value.value).call(_context2);
|
|
268
|
-
var lastIndex = values.length - 1;
|
|
269
|
-
var _value = date;
|
|
270
|
-
if (range) {
|
|
271
|
-
var _context3;
|
|
272
|
-
_value = _sliceInstanceProperty(_context3 = values[lastIndex]).call(_context3);
|
|
273
|
-
_value[flag] = date;
|
|
274
|
-
instance.trigger('selecting', _value);
|
|
275
|
-
}
|
|
276
|
-
values[lastIndex] = _value;
|
|
277
|
-
value.set(values);
|
|
278
|
-
}
|
|
279
|
-
function getTimeValue(flag) {
|
|
280
|
-
var _value = value.value;
|
|
281
|
-
if (!_value.length) return null;
|
|
282
|
-
var _instance$get6 = instance.get(),
|
|
283
|
-
range = _instance$get6.range,
|
|
284
|
-
min = _instance$get6.min;
|
|
285
|
-
var lastValue = last(_value);
|
|
286
|
-
return range ? lastValue[flag] : lastValue;
|
|
287
|
-
}
|
|
288
|
-
function getDayjsValue() {
|
|
289
|
-
return dayjsValue;
|
|
290
|
-
}
|
|
291
|
-
return {
|
|
292
|
-
value: value,
|
|
293
|
-
format: format,
|
|
294
|
-
onConfirm: onConfirm,
|
|
295
|
-
onChangeTime: onChangeTime,
|
|
296
|
-
getTimeValue: getTimeValue,
|
|
297
|
-
setValue: setValue,
|
|
298
|
-
convertToDayjs: convertToDayjs,
|
|
299
|
-
getDayjsValue: getDayjsValue,
|
|
300
|
-
setMoment: setMoment
|
|
301
|
-
};
|
|
302
|
-
}
|
|
57
|
+
__decorate([bind], BasePicker.prototype, "resetKeywords", null);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { Component } from 'intact';
|
|
2
2
|
import { Dayjs } from 'dayjs';
|
|
3
3
|
import type { Datepicker } from './index';
|
|
4
|
-
import { StateValue } from './
|
|
4
|
+
import type { StateValue } from './useValueBase';
|
|
5
5
|
import { PanelFlags } from './usePanel';
|
|
6
|
+
import { Position } from './useHighlight';
|
|
6
7
|
export interface DatepickerCalendarProps {
|
|
7
8
|
value: StateValue;
|
|
8
9
|
type?: 'date' | 'year' | 'month' | 'week' | 'quarter';
|
|
9
10
|
flag: PanelFlags;
|
|
11
|
+
highlightPosition: Position;
|
|
10
12
|
}
|
|
11
13
|
export interface DatepickerCalendarEvents {
|
|
12
14
|
change: [Dayjs, PanelFlags];
|
|
@@ -20,7 +22,7 @@ export declare class DatepickerCalendar extends Component<DatepickerCalendarProp
|
|
|
20
22
|
date: import("../../hooks/useState").State<Dayjs>;
|
|
21
23
|
getDateLabel: () => {
|
|
22
24
|
value: string;
|
|
23
|
-
onClick
|
|
25
|
+
onClick(e: import("../../hooks/useDocumentClick").IgnoreClickEvent): void;
|
|
24
26
|
}[];
|
|
25
27
|
prevMonth: () => void;
|
|
26
28
|
nextMonth: () => void;
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import dayjs, { Dayjs, OpUnitType
|
|
2
|
-
export type OpUnitType = DayjsOpUnitType;
|
|
3
|
-
export type QUnitType = DayjsQUnitType;
|
|
4
|
-
declare module 'dayjs' {
|
|
5
|
-
interface Dayjs {
|
|
6
|
-
isSame(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
|
|
7
|
-
isBefore(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
|
|
8
|
-
isAfter(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
|
|
9
|
-
add(value: number, unit?: DayjsOpUnitType | DayjsQUnitType): dayjs.Dayjs;
|
|
10
|
-
subtract(value: number, unit?: DayjsOpUnitType | DayjsQUnitType): dayjs.Dayjs;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
import dayjs, { Dayjs, OpUnitType, QUnitType } from 'dayjs';
|
|
13
2
|
export default dayjs;
|
|
14
|
-
export type { Dayjs };
|
|
3
|
+
export type { Dayjs, OpUnitType, QUnitType };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import dayjs, { Dayjs, OpUnitType, QUnitType } from 'dayjs';
|
|
2
|
-
import {
|
|
2
|
+
import { last } from '../utils';
|
|
3
|
+
import { StateValueItem } from './useValueBase';
|
|
3
4
|
export declare function getNowDate(isEnd?: boolean): dayjs.Dayjs;
|
|
4
5
|
export declare function clearTime(date: Date): void;
|
|
5
6
|
export declare function endTime(date: Date): void;
|
|
@@ -8,4 +9,4 @@ export declare function isLT(a: Dayjs | undefined | null, b: Dayjs | undefined |
|
|
|
8
9
|
export declare function isGT(a: Dayjs | undefined | null, b: Dayjs | undefined | null, type?: OpUnitType | QUnitType): boolean;
|
|
9
10
|
export declare function createDate(date: string): Date;
|
|
10
11
|
export declare function findValueIndex(values: StateValueItem[], value: StateValueItem, type: OpUnitType | QUnitType): number;
|
|
11
|
-
export
|
|
12
|
+
export { last };
|
|
@@ -2,6 +2,7 @@ import _construct from "@babel/runtime-corejs3/helpers/construct";
|
|
|
2
2
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
|
|
3
3
|
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js/instance/find-index";
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
|
+
import { last } from '../utils';
|
|
5
6
|
export function getNowDate(isEnd) {
|
|
6
7
|
// only date without time
|
|
7
8
|
var now = new Date();
|
|
@@ -73,6 +74,4 @@ export function findValueIndex(values, value, type) {
|
|
|
73
74
|
}
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
|
-
export
|
|
77
|
-
return arr[arr.length - 1];
|
|
78
|
-
}
|
|
77
|
+
export { last };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { TypeDefs } from 'intact';
|
|
2
2
|
import dayjs from './dayjs';
|
|
3
|
-
import { State } from '../../hooks/useState';
|
|
4
3
|
import { Shortcut } from './shortcuts';
|
|
5
|
-
import { BasePicker, BasePickerProps, BasePickerEvents, BasePickerBlocks
|
|
4
|
+
import { BasePicker, BasePickerProps, BasePickerEvents, BasePickerBlocks } from './basepicker';
|
|
5
|
+
import { Value } from './useValueBase';
|
|
6
6
|
export * as shortcuts from './shortcuts';
|
|
7
7
|
export { dayjs };
|
|
8
8
|
export interface DatepickerProps<V extends Value = Value, M extends boolean = boolean, R extends boolean = boolean> extends BasePickerProps<V extends string ? V : V | string, M, R> {
|
|
9
9
|
type?: 'date' | 'datetime' | 'year' | 'month' | 'week' | 'quarter';
|
|
10
10
|
shortcuts?: Shortcut[];
|
|
11
|
-
isMerge?: boolean;
|
|
12
11
|
}
|
|
13
12
|
export interface DatepickerEvents extends BasePickerEvents {
|
|
14
13
|
}
|
|
@@ -28,52 +27,45 @@ export declare class Datepicker<V extends Value = Value, M extends boolean = fal
|
|
|
28
27
|
};
|
|
29
28
|
disabled: {
|
|
30
29
|
isDisabled: (value: dayjs.Dayjs, type?: "h" | "s" | "y" | "date" | "month" | "week" | "millisecond" | "second" | "minute" | "hour" | "day" | "year" | "milliseconds" | "seconds" | "minutes" | "hours" | "days" | "months" | "years" | "dates" | "d" | "D" | "M" | "m" | "ms" | "weeks" | "w" | "quarter" | "quarters" | "Q") => boolean;
|
|
31
|
-
isDisabledTime: (value: dayjs.Dayjs
|
|
30
|
+
isDisabledTime: (value: dayjs.Dayjs) => boolean;
|
|
32
31
|
isDisabledConfirm: () => boolean;
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
isDisabledValue: (value: import("./useValueBase").StateValueItem) => boolean;
|
|
33
|
+
maxDate: import("../../hooks/useState").State<dayjs.Dayjs | null>;
|
|
34
|
+
minDate: import("../../hooks/useState").State<dayjs.Dayjs | null>;
|
|
35
35
|
};
|
|
36
36
|
panel: {
|
|
37
|
-
startPanel: State<import("./usePanel").PanelTypes>;
|
|
38
|
-
endPanel: State<import("./usePanel").PanelTypes>;
|
|
39
|
-
changePanel: (type: import("./usePanel").PanelTypes, flag?: import("./usePanel").PanelFlags) => void;
|
|
40
|
-
getPanel: (flag: import("./usePanel").PanelFlags) => State<import("./usePanel").PanelTypes>;
|
|
41
|
-
reset: () => void;
|
|
42
37
|
startRef: import("intact").RefObject<import("./calendar").DatepickerCalendar>;
|
|
43
38
|
endRef: import("intact").RefObject<import("./calendar").DatepickerCalendar>;
|
|
44
39
|
};
|
|
45
40
|
focusDate: {
|
|
46
|
-
focusDate: State<dayjs.Dayjs | null>;
|
|
41
|
+
focusDate: import("../../hooks/useState").State<dayjs.Dayjs | null>;
|
|
47
42
|
reset: () => void;
|
|
48
43
|
};
|
|
49
44
|
value: {
|
|
50
45
|
format: () => string | string[];
|
|
51
|
-
|
|
46
|
+
formatSingleValue: (value: import("./useValueBase").StateValueItem) => string;
|
|
52
47
|
onChangeTime: (date: dayjs.Dayjs, flag: import("./usePanel").PanelFlags) => void;
|
|
53
48
|
getTimeValue: (flag: import("./usePanel").PanelFlags) => dayjs.Dayjs | null | undefined;
|
|
54
|
-
convertToDayjs: (v: Value | [Value, Value] | Value[] | [Value, Value][] | null | undefined) => import("./
|
|
55
|
-
|
|
49
|
+
convertToDayjs: (v: Value | [Value, Value] | Value[] | [Value, Value][] | null | undefined) => import("./useValueBase").DayjsValue;
|
|
50
|
+
unique: () => void;
|
|
56
51
|
setMoment: () => void;
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
updateValue: () => void;
|
|
53
|
+
value: import("../../hooks/useState").State<import("./useValueBase").StateValue>;
|
|
54
|
+
setValue: (v: import("./useValueBase").StateValueItem, fromInput: boolean) => void;
|
|
59
55
|
onChangeDate: (v: dayjs.Dayjs, flag: import("./usePanel").PanelFlags) => void;
|
|
56
|
+
getDayjsValue: () => import("./useValueBase").DayjsValue;
|
|
57
|
+
allValuesUpdatedInMultipleMode: () => boolean | undefined;
|
|
60
58
|
};
|
|
61
|
-
|
|
62
|
-
position: State<"
|
|
63
|
-
|
|
64
|
-
startTextLength: State<number>;
|
|
65
|
-
handleInputClick: (e: MouseEvent) => void;
|
|
66
|
-
resetPosition: (pos?: "end" | "start") => void;
|
|
59
|
+
highlight: {
|
|
60
|
+
position: import("../../hooks/useState").State<import("./useHighlight").Position>;
|
|
61
|
+
handleInputClick: () => void;
|
|
67
62
|
togglePosition: () => void;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
71
|
-
mergeRange: {
|
|
72
|
-
formatMultipleValues: (dayjsValue: import("./basepicker").DayjsValue, results: string[]) => string[];
|
|
63
|
+
highlightWidth: import("../../hooks/useState").State<number>;
|
|
64
|
+
highlightLeft: import("../../hooks/useState").State<number>;
|
|
73
65
|
};
|
|
66
|
+
private confirm;
|
|
74
67
|
init(): void;
|
|
75
68
|
protected getPlaceholder(): string | number | boolean | import("misstime/dist/utils/types").VNode<any> | import("intact").Children[];
|
|
76
69
|
protected getLabel(): string | string[];
|
|
77
|
-
protected clear(e: MouseEvent): void;
|
|
78
70
|
private setByShortcut;
|
|
79
71
|
}
|
|
@@ -15,21 +15,22 @@ import { useFormats } from './useFormats';
|
|
|
15
15
|
import { usePanel } from './usePanel';
|
|
16
16
|
import { useFocusDate } from './useFocusDate';
|
|
17
17
|
import { useKeyboards } from './useKeyboards';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import { useHighlight } from './useHighlight';
|
|
19
|
+
// import {useMergeRange} from './useMergeRange';
|
|
20
20
|
import { BasePicker } from './basepicker';
|
|
21
|
+
import { useConfirm } from './useConfirm';
|
|
21
22
|
import * as _shortcuts from './shortcuts';
|
|
22
23
|
export { _shortcuts as shortcuts };
|
|
23
24
|
export { dayjs };
|
|
24
25
|
var typeDefs = _extends({}, BasePicker.typeDefs, {
|
|
25
26
|
type: ['date', 'datetime', 'year', 'month', 'week', 'quarter'],
|
|
26
|
-
shortcuts: Array
|
|
27
|
-
isMerge: Boolean
|
|
27
|
+
shortcuts: Array
|
|
28
|
+
// isMerge: Boolean
|
|
28
29
|
});
|
|
29
30
|
var defaults = function defaults() {
|
|
30
31
|
return _extends({}, BasePicker.defaults(), {
|
|
31
|
-
type: 'date'
|
|
32
|
-
isMerge: false
|
|
32
|
+
type: 'date'
|
|
33
|
+
// isMerge: false
|
|
33
34
|
});
|
|
34
35
|
};
|
|
35
36
|
export var Datepicker = /*#__PURE__*/function (_BasePicker) {
|
|
@@ -42,12 +43,17 @@ export var Datepicker = /*#__PURE__*/function (_BasePicker) {
|
|
|
42
43
|
}
|
|
43
44
|
_this = _BasePicker.call.apply(_BasePicker, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
|
|
44
45
|
_this.formats = useFormats();
|
|
45
|
-
_this.disabled = useDisabled(_this.formats)
|
|
46
|
+
_this.disabled = useDisabled(_this.formats, function () {
|
|
47
|
+
return _this.highlight.position;
|
|
48
|
+
});
|
|
46
49
|
_this.panel = usePanel();
|
|
47
50
|
_this.focusDate = useFocusDate();
|
|
48
|
-
_this.value = useValue(_this.formats, _this.disabled, _this.panel)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
_this.value = useValue(_this.formats, _this.disabled, _this.panel, function () {
|
|
52
|
+
return _this.highlight.position;
|
|
53
|
+
});
|
|
54
|
+
_this.highlight = useHighlight(_this.value.value, _this.formats.getShowString, _this.input.keywords);
|
|
55
|
+
// public mergeRange = useMergeRange(this.formats);
|
|
56
|
+
_this.confirm = useConfirm(_this.highlight, _this.value, _this.formats.getValueString);
|
|
51
57
|
return _this;
|
|
52
58
|
}
|
|
53
59
|
var _proto = Datepicker.prototype;
|
|
@@ -55,7 +61,6 @@ export var Datepicker = /*#__PURE__*/function (_BasePicker) {
|
|
|
55
61
|
_BasePicker.prototype.init.call(this);
|
|
56
62
|
provide(DATEPICKER, this);
|
|
57
63
|
useKeyboards(this.panel.startRef, this.focusDate.focusDate);
|
|
58
|
-
this.activePosition.setupEventListeners();
|
|
59
64
|
};
|
|
60
65
|
_proto.getPlaceholder = function getPlaceholder() {
|
|
61
66
|
var _this$get = this.get(),
|
|
@@ -67,40 +72,26 @@ export var Datepicker = /*#__PURE__*/function (_BasePicker) {
|
|
|
67
72
|
case 'datetime':
|
|
68
73
|
return range ? _$('开始时间 ~ 结束时间') : _$('请选择日期和时间');
|
|
69
74
|
case 'year':
|
|
70
|
-
return _$('请选择年份');
|
|
75
|
+
return range ? _$('开始年份 ~ 结束年份') : _$('请选择年份');
|
|
71
76
|
case 'month':
|
|
72
|
-
return _$('请选择月份');
|
|
77
|
+
return range ? _$('开始月份 ~ 结束月份') : _$('请选择月份');
|
|
73
78
|
case 'week':
|
|
74
|
-
return _$('请选择周');
|
|
79
|
+
return range ? _$('开始周 ~ 结束周') : _$('请选择周');
|
|
75
80
|
case 'quarter':
|
|
76
|
-
return _$('请选择季度');
|
|
81
|
+
return range ? _$('开始季度 ~ 结束季度') : _$('请选择季度');
|
|
77
82
|
default:
|
|
78
83
|
return range ? _$('开始日期 ~ 结束日期') : _$('请选择日期');
|
|
79
84
|
}
|
|
80
85
|
};
|
|
81
86
|
_proto.getLabel = function getLabel() {
|
|
82
|
-
var _this$get2 = this.get(),
|
|
83
|
-
multiple = _this$get2.multiple;
|
|
84
|
-
if (multiple) {
|
|
85
|
-
var results = this.value.format();
|
|
86
|
-
var dayjsValue = this.value.getDayjsValue();
|
|
87
|
-
return this.mergeRange.formatMultipleValues(dayjsValue, results);
|
|
88
|
-
}
|
|
89
87
|
return this.value.format();
|
|
90
88
|
};
|
|
91
|
-
_proto.clear = function clear(e) {
|
|
92
|
-
_BasePicker.prototype.clear.call(this, e);
|
|
93
|
-
if (this.get('type') === 'datetime') {
|
|
94
|
-
// reset the state to let user re-select
|
|
95
|
-
this.panel.reset();
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
89
|
_proto.setByShortcut = function setByShortcut(shortcut) {
|
|
99
90
|
var _this$value = this.value,
|
|
100
91
|
setValue = _this$value.setValue,
|
|
101
92
|
convertToDayjs = _this$value.convertToDayjs;
|
|
102
|
-
var _this$
|
|
103
|
-
multiple = _this$
|
|
93
|
+
var _this$get2 = this.get(),
|
|
94
|
+
multiple = _this$get2.multiple;
|
|
104
95
|
setValue(convertToDayjs(shortcut.value())[0], true);
|
|
105
96
|
if (!multiple) {
|
|
106
97
|
this.hide();
|
|
@@ -111,5 +102,4 @@ export var Datepicker = /*#__PURE__*/function (_BasePicker) {
|
|
|
111
102
|
Datepicker.template = template;
|
|
112
103
|
Datepicker.typeDefs = typeDefs;
|
|
113
104
|
Datepicker.defaults = defaults;
|
|
114
|
-
__decorate([bind], Datepicker.prototype, "clear", null);
|
|
115
105
|
__decorate([bind], Datepicker.prototype, "setByShortcut", null);
|