@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.
Files changed (171) hide show
  1. package/components/.DS_Store +0 -0
  2. package/components/cascader/index.spec.ts +7 -6
  3. package/components/datepicker/basepicker.ts +26 -314
  4. package/components/datepicker/calendar.ts +3 -1
  5. package/components/datepicker/calendar.vdt +5 -2
  6. package/components/datepicker/dayjs.ts +2 -16
  7. package/components/datepicker/demos/multiple.md +5 -0
  8. package/components/datepicker/demos/yearMonth.md +2 -8
  9. package/components/datepicker/helpers.ts +5 -7
  10. package/components/datepicker/index.md +1 -2
  11. package/components/datepicker/index.spec.ts +551 -139
  12. package/components/datepicker/index.ts +16 -33
  13. package/components/datepicker/index.vdt +41 -35
  14. package/components/datepicker/shortcuts.ts +1 -1
  15. package/components/datepicker/styles.ts +27 -18
  16. package/components/datepicker/useConfirm.ts +82 -0
  17. package/components/datepicker/useDisabled.ts +29 -31
  18. package/components/datepicker/useFormats.ts +8 -4
  19. package/components/datepicker/useHighlight.ts +81 -0
  20. package/components/datepicker/useKeyboards.ts +2 -1
  21. package/components/datepicker/useMergeRange.ts +12 -12
  22. package/components/datepicker/useMonths.ts +6 -3
  23. package/components/datepicker/usePanel.ts +19 -19
  24. package/components/datepicker/useShowDate.ts +21 -41
  25. package/components/datepicker/useStatus.ts +34 -15
  26. package/components/datepicker/useValue.ts +43 -72
  27. package/components/datepicker/useValueBase.ts +309 -0
  28. package/components/datepicker/useWeeks.ts +1 -1
  29. package/components/datepicker/useYears.ts +7 -3
  30. package/components/descriptions/.DS_Store +0 -0
  31. package/components/dropdown/dropdown.ts +5 -4
  32. package/components/dropdown/index.md +1 -0
  33. package/components/dropdown/item.ts +1 -1
  34. package/components/dropdown/useKeyboard.ts +0 -1
  35. package/components/input/index.spec.ts +42 -0
  36. package/components/input/index.ts +8 -0
  37. package/components/input/index.vdt +3 -4
  38. package/components/input/useAutoWidth.ts +19 -1
  39. package/components/menu/.DS_Store +0 -0
  40. package/components/menu/demos/.DS_Store +0 -0
  41. package/components/scrollSelect/useMouseEvents.ts +5 -4
  42. package/components/select/base.ts +3 -2
  43. package/components/select/base.vdt +2 -1
  44. package/components/select/demos/creatable.md +2 -2
  45. package/components/select/index.md +1 -1
  46. package/components/select/index.spec.ts +107 -34
  47. package/components/select/option.ts +2 -1
  48. package/components/select/select.ts +1 -0
  49. package/components/select/styles.ts +3 -1
  50. package/components/select/useInput.ts +5 -9
  51. package/components/table/.DS_Store +0 -0
  52. package/components/table/index.spec.ts +69 -1
  53. package/components/table/useStickyHeader.ts +1 -1
  54. package/components/timepicker/index.spec.ts +145 -27
  55. package/components/timepicker/panelPicker.ts +10 -4
  56. package/components/timepicker/panelPicker.vdt +3 -5
  57. package/components/timepicker/styles.ts +1 -0
  58. package/components/timepicker/useConfirm.ts +33 -0
  59. package/components/timepicker/useDefaultValue.ts +30 -0
  60. package/components/timepicker/useDisabled.ts +17 -4
  61. package/components/timepicker/useFormats.ts +1 -1
  62. package/components/timepicker/useValue.ts +22 -19
  63. package/components/tour/.DS_Store +0 -0
  64. package/components/tour/index.spec.ts +1 -1
  65. package/components/virtualList/.DS_Store +0 -0
  66. package/components/virtualList/demos/.DS_Store +0 -0
  67. package/es/components/cascader/index.spec.js +18 -19
  68. package/es/components/datepicker/basepicker.d.ts +6 -27
  69. package/es/components/datepicker/basepicker.js +23 -268
  70. package/es/components/datepicker/calendar.d.ts +4 -2
  71. package/es/components/datepicker/dayjs.d.ts +2 -13
  72. package/es/components/datepicker/helpers.d.ts +3 -2
  73. package/es/components/datepicker/helpers.js +2 -3
  74. package/es/components/datepicker/index.d.ts +21 -29
  75. package/es/components/datepicker/index.js +22 -32
  76. package/es/components/datepicker/index.spec.js +1333 -578
  77. package/es/components/datepicker/index.vdt.js +39 -38
  78. package/es/components/datepicker/shortcuts.d.ts +1 -1
  79. package/es/components/datepicker/styles.d.ts +7 -2
  80. package/es/components/datepicker/styles.js +10 -15
  81. package/es/components/datepicker/useConfirm.d.ts +6 -0
  82. package/es/components/datepicker/useConfirm.js +65 -0
  83. package/es/components/datepicker/useDisabled.d.ts +5 -3
  84. package/es/components/datepicker/useDisabled.js +22 -27
  85. package/es/components/datepicker/useFormats.d.ts +2 -2
  86. package/es/components/datepicker/useFormats.js +6 -2
  87. package/es/components/datepicker/useHighlight.d.ts +14 -0
  88. package/es/components/datepicker/useHighlight.js +60 -0
  89. package/es/components/datepicker/useKeyboards.js +2 -1
  90. package/es/components/datepicker/useMergeRange.d.ts +1 -1
  91. package/es/components/datepicker/useMergeRange.js +11 -16
  92. package/es/components/datepicker/useMonths.js +5 -3
  93. package/es/components/datepicker/usePanel.d.ts +1 -10
  94. package/es/components/datepicker/usePanel.js +19 -32
  95. package/es/components/datepicker/useShowDate.d.ts +1 -1
  96. package/es/components/datepicker/useShowDate.js +15 -40
  97. package/es/components/datepicker/useStatus.js +33 -16
  98. package/es/components/datepicker/useValue.d.ts +11 -6
  99. package/es/components/datepicker/useValue.js +49 -69
  100. package/es/components/datepicker/useValueBase.d.ts +28 -0
  101. package/es/components/datepicker/useValueBase.js +277 -0
  102. package/es/components/datepicker/useYears.js +6 -3
  103. package/es/components/dropdown/dropdown.d.ts +1 -0
  104. package/es/components/dropdown/dropdown.js +7 -4
  105. package/es/components/input/index.d.ts +2 -0
  106. package/es/components/input/index.js +6 -0
  107. package/es/components/input/index.spec.js +45 -0
  108. package/es/components/input/index.vdt.js +4 -3
  109. package/es/components/input/useAutoWidth.d.ts +2 -0
  110. package/es/components/input/useAutoWidth.js +19 -1
  111. package/es/components/scrollSelect/useMouseEvents.js +5 -4
  112. package/es/components/select/base.d.ts +1 -1
  113. package/es/components/select/base.js +3 -2
  114. package/es/components/select/base.vdt.js +4 -3
  115. package/es/components/select/index.spec.js +158 -84
  116. package/es/components/select/option.js +2 -1
  117. package/es/components/select/select.js +2 -1
  118. package/es/components/select/styles.d.ts +79 -0
  119. package/es/components/select/styles.js +1 -0
  120. package/es/components/select/useInput.d.ts +1 -1
  121. package/es/components/select/useInput.js +4 -4
  122. package/es/components/table/index.spec.js +84 -6
  123. package/es/components/table/useStickyHeader.js +1 -1
  124. package/es/components/timepicker/index.spec.js +298 -128
  125. package/es/components/timepicker/panelPicker.d.ts +21 -16
  126. package/es/components/timepicker/panelPicker.js +7 -4
  127. package/es/components/timepicker/panelPicker.vdt.js +5 -9
  128. package/es/components/timepicker/selectPicker.d.ts +4 -3
  129. package/es/components/timepicker/styles.js +1 -1
  130. package/es/components/timepicker/useConfirm.d.ts +6 -0
  131. package/es/components/timepicker/useConfirm.js +19 -0
  132. package/es/components/timepicker/useDefaultValue.d.ts +4 -0
  133. package/es/components/timepicker/useDefaultValue.js +27 -0
  134. package/es/components/timepicker/useDisabled.d.ts +6 -3
  135. package/es/components/timepicker/useDisabled.js +13 -4
  136. package/es/components/timepicker/useFormats.d.ts +1 -1
  137. package/es/components/timepicker/useValue.d.ts +13 -8
  138. package/es/components/timepicker/useValue.js +14 -15
  139. package/es/components/tour/index.spec.js +1 -1
  140. package/es/index.d.ts +2 -2
  141. package/es/index.js +2 -2
  142. package/es/site/data/components/datepicker/demos/multiple/index.d.ts +1 -0
  143. package/es/site/data/components/datepicker/demos/multiple/index.js +2 -1
  144. package/es/site/data/components/datepicker/demos/multiple/react.d.ts +1 -0
  145. package/es/site/data/components/datepicker/demos/multiple/react.js +13 -2
  146. package/es/site/data/components/datepicker/demos/yearMonth/index.d.ts +0 -2
  147. package/es/site/data/components/datepicker/demos/yearMonth/index.js +1 -3
  148. package/es/site/data/components/datepicker/demos/yearMonth/react.d.ts +0 -2
  149. package/es/site/data/components/datepicker/demos/yearMonth/react.js +1 -21
  150. package/es/site/data/components/select/demos/creatable/react.js +2 -2
  151. package/es/site/data/components/select/demos/searchable/index.js +1 -1
  152. package/es/site/data/components/select/demos/searchable/react.js +1 -1
  153. package/es/site/data/components/tour/demos/customText/index.d.ts +19 -6
  154. package/es/site/data/components/tour/demos/customText/index.js +18 -17
  155. package/es/site/data/components/tour/demos/customText/react.d.ts +20 -6
  156. package/es/site/data/components/tour/demos/customText/react.js +31 -27
  157. package/index.ts +2 -2
  158. package/package.json +2 -2
  159. package/styles/.DS_Store +0 -0
  160. package/components/datepicker/demos/nowrap.md +0 -35
  161. package/components/datepicker/usePosition.ts +0 -169
  162. package/es/components/datepicker/usePosition.d.ts +0 -10
  163. package/es/components/datepicker/usePosition.js +0 -166
  164. package/es/site/data/components/datepicker/demos/nowrap/index.d.ts +0 -10
  165. package/es/site/data/components/datepicker/demos/nowrap/index.js +0 -19
  166. package/es/site/data/components/datepicker/demos/nowrap/react.d.ts +0 -10
  167. package/es/site/data/components/datepicker/demos/nowrap/react.js +0 -49
  168. package/es/site/data/components/tour/demos/customButtons/index.d.ts +0 -33
  169. package/es/site/data/components/tour/demos/customButtons/index.js +0 -55
  170. package/es/site/data/components/tour/demos/customButtons/react.d.ts +0 -33
  171. 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 { findValueIndex } from './helpers';
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(keywords) {
43
- var _this$get = this.get(),
44
- multiple = _this$get.multiple,
45
- range = _this$get.range;
46
- var dayjsValue = this.value.getDayjsValue();
47
- var getShowString = this.formats.getShowString;
48
- var value = last(dayjsValue);
49
- keywords.set(multiple ? '' : !range ? value ? getShowString(value) : '' : value ? [value[0] ? getShowString(value[0]) : '', value[1] ? getShowString(value[1]) : ''].join(' ~ ') : '');
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 './basepicker';
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: (e: import("../../hooks/useDocumentClick").IgnoreClickEvent) => void;
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 as DayjsOpUnitType, QUnitType as DayjsQUnitType } from 'dayjs';
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 { StateValueItem } from './basepicker';
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 declare function last<T>(arr: T[]): T | undefined;
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 function last(arr) {
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, Value } from './basepicker';
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, flag: import("./usePanel").PanelFlags) => boolean;
30
+ isDisabledTime: (value: dayjs.Dayjs) => boolean;
32
31
  isDisabledConfirm: () => boolean;
33
- maxDate: State<dayjs.Dayjs | null>;
34
- minDate: State<dayjs.Dayjs | null>;
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
- onConfirm: () => void;
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("./basepicker").DayjsValue;
55
- getDayjsValue: () => import("./basepicker").DayjsValue;
49
+ convertToDayjs: (v: Value | [Value, Value] | Value[] | [Value, Value][] | null | undefined) => import("./useValueBase").DayjsValue;
50
+ unique: () => void;
56
51
  setMoment: () => void;
57
- value: State<import("./basepicker").StateValue>;
58
- setValue: (v: import("./basepicker").StateValueItem, fromInput: boolean) => void;
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
- activePosition: {
62
- position: State<"end" | "start">;
63
- charLength: State<number>;
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
- setupEventListeners: () => void;
69
- resetToStart: () => void;
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 { usePosition } from './usePosition';
19
- import { useMergeRange } from './useMergeRange';
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
- _this.activePosition = usePosition();
50
- _this.mergeRange = useMergeRange(_this.formats);
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$get3 = this.get(),
103
- multiple = _this$get3.multiple;
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);