@king-design/react 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.
Files changed (117) hide show
  1. package/components/cascader/index.spec.js +18 -19
  2. package/components/datepicker/basepicker.d.ts +6 -25
  3. package/components/datepicker/basepicker.js +22 -234
  4. package/components/datepicker/calendar.d.ts +36 -6
  5. package/components/datepicker/calendar.js +4 -0
  6. package/components/datepicker/calendar.vdt.js +21 -5
  7. package/components/datepicker/dayjs.d.ts +2 -2
  8. package/components/datepicker/dayjs.js +6 -0
  9. package/components/datepicker/helpers.d.ts +8 -7
  10. package/components/datepicker/helpers.js +2 -3
  11. package/components/datepicker/index.d.ts +26 -19
  12. package/components/datepicker/index.js +21 -13
  13. package/components/datepicker/index.spec.js +1389 -633
  14. package/components/datepicker/index.vdt.js +43 -46
  15. package/components/datepicker/shortcuts.d.ts +1 -1
  16. package/components/datepicker/styles.d.ts +22 -0
  17. package/components/datepicker/styles.js +26 -4
  18. package/components/datepicker/useConfirm.d.ts +6 -0
  19. package/components/datepicker/useConfirm.js +65 -0
  20. package/components/datepicker/useDisabled.d.ts +7 -5
  21. package/components/datepicker/useDisabled.js +22 -27
  22. package/components/datepicker/useFormats.d.ts +2 -2
  23. package/components/datepicker/useFormats.js +9 -3
  24. package/components/datepicker/useHighlight.d.ts +14 -0
  25. package/components/datepicker/useHighlight.js +60 -0
  26. package/components/datepicker/useKeyboards.js +2 -1
  27. package/components/datepicker/useMergeRange.d.ts +5 -0
  28. package/components/datepicker/useMergeRange.js +45 -0
  29. package/components/datepicker/useMonths.js +5 -3
  30. package/components/datepicker/usePanel.d.ts +1 -10
  31. package/components/datepicker/usePanel.js +19 -32
  32. package/components/datepicker/useQuarters.d.ts +15 -0
  33. package/components/datepicker/useQuarters.js +36 -0
  34. package/components/datepicker/useShowDate.js +10 -2
  35. package/components/datepicker/useStatus.d.ts +1 -1
  36. package/components/datepicker/useStatus.js +33 -16
  37. package/components/datepicker/useValue.d.ts +12 -6
  38. package/components/datepicker/useValue.js +49 -45
  39. package/components/datepicker/useValueBase.d.ts +28 -0
  40. package/components/datepicker/useValueBase.js +277 -0
  41. package/components/datepicker/useWeeks.d.ts +19 -0
  42. package/components/datepicker/useWeeks.js +48 -0
  43. package/components/datepicker/useYears.js +6 -3
  44. package/components/dialog/useFixBody.js +6 -58
  45. package/components/dropdown/dropdown.d.ts +1 -0
  46. package/components/dropdown/dropdown.js +7 -4
  47. package/components/ellipsis/styles.js +1 -1
  48. package/components/form/styles.js +1 -1
  49. package/components/input/index.d.ts +2 -0
  50. package/components/input/index.js +6 -0
  51. package/components/input/index.spec.js +45 -0
  52. package/components/input/index.vdt.js +4 -3
  53. package/components/input/useAutoWidth.d.ts +2 -0
  54. package/components/input/useAutoWidth.js +19 -1
  55. package/components/scrollSelect/index.spec.js +4 -6
  56. package/components/scrollSelect/useMouseEvents.js +22 -9
  57. package/components/select/base.d.ts +1 -1
  58. package/components/select/base.js +3 -2
  59. package/components/select/base.vdt.js +5 -2
  60. package/components/select/index.spec.js +329 -82
  61. package/components/select/option.d.ts +1 -0
  62. package/components/select/option.js +10 -2
  63. package/components/select/select.d.ts +1 -0
  64. package/components/select/select.js +4 -2
  65. package/components/select/styles.d.ts +79 -0
  66. package/components/select/styles.js +1 -0
  67. package/components/select/useFilterable.js +2 -1
  68. package/components/select/useInput.d.ts +1 -1
  69. package/components/select/useInput.js +7 -4
  70. package/components/select/useSearchable.js +1 -0
  71. package/components/table/index.spec.js +84 -6
  72. package/components/table/useStickyHeader.js +1 -1
  73. package/components/timepicker/index.spec.js +298 -128
  74. package/components/timepicker/panelPicker.d.ts +23 -17
  75. package/components/timepicker/panelPicker.js +7 -4
  76. package/components/timepicker/panelPicker.vdt.js +8 -4
  77. package/components/timepicker/selectPicker.d.ts +5 -4
  78. package/components/timepicker/useConfirm.d.ts +6 -0
  79. package/components/timepicker/useConfirm.js +19 -0
  80. package/components/timepicker/useDefaultValue.d.ts +4 -0
  81. package/components/timepicker/useDefaultValue.js +27 -0
  82. package/components/timepicker/useDisabled.d.ts +7 -4
  83. package/components/timepicker/useDisabled.js +13 -4
  84. package/components/timepicker/useFormats.d.ts +1 -1
  85. package/components/timepicker/useValue.d.ts +14 -8
  86. package/components/timepicker/useValue.js +14 -15
  87. package/components/tour/index.d.ts +2 -0
  88. package/components/tour/index.js +2 -0
  89. package/components/tour/index.spec.d.ts +1 -0
  90. package/components/tour/index.spec.js +356 -0
  91. package/components/tour/step.d.ts +23 -0
  92. package/components/tour/step.js +46 -0
  93. package/components/tour/step.vdt.js +74 -0
  94. package/components/tour/styles.d.ts +7 -0
  95. package/components/tour/styles.js +84 -0
  96. package/components/tour/tour.d.ts +73 -0
  97. package/components/tour/tour.js +70 -0
  98. package/components/tour/tour.vdt.js +66 -0
  99. package/components/tour/useArrow.d.ts +4 -0
  100. package/components/tour/useArrow.js +40 -0
  101. package/components/tour/useFixBody.d.ts +4 -0
  102. package/components/tour/useFixBody.js +17 -0
  103. package/components/tour/useHighlight.d.ts +4 -0
  104. package/components/tour/useHighlight.js +31 -0
  105. package/components/tour/useMaskClosable.d.ts +1 -0
  106. package/components/tour/useMaskClosable.js +25 -0
  107. package/components/tour/useNavigation.d.ts +5 -0
  108. package/components/tour/useNavigation.js +103 -0
  109. package/components/tour/usePosition.d.ts +6 -0
  110. package/components/tour/usePosition.js +93 -0
  111. package/components/tour/useSteps.d.ts +6 -0
  112. package/components/tour/useSteps.js +68 -0
  113. package/hooks/useFixBody.d.ts +11 -0
  114. package/hooks/useFixBody.js +72 -0
  115. package/index.d.ts +3 -2
  116. package/index.js +3 -2
  117. package/package.json +2 -2
@@ -160,7 +160,7 @@ describe('Cascader', function () {
160
160
  }, _callee5);
161
161
  })));
162
162
  it('filter', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6() {
163
- var _mount5, instance, element, input, dropdown, dropdown1, _getElements2, _dropdown1, _dropdown2, _dropdown3;
163
+ var _mount5, instance, element, input, dropdown1, _getElements2, _dropdown1, _dropdown2, _dropdown3;
164
164
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
165
165
  while (1) switch (_context6.prev = _context6.next) {
166
166
  case 0:
@@ -170,53 +170,52 @@ describe('Cascader', function () {
170
170
  _context6.next = 5;
171
171
  return wait();
172
172
  case 5:
173
+ // FIXME: maybe we should show no-data layer
173
174
  // should show layer when input empty string
174
- input.value = ' ';
175
+ // input.value = ' ';
176
+ // dispatchEvent(input, 'input');
177
+ // await wait();
178
+ // const dropdown = getElement('.k-cascader-menu')!;
179
+ // expect(dropdown.innerHTML).to.matchSnapshot();
180
+ // expect(dropdown.innerText).to.eql('北京\n湖南');
181
+ input.value = '长沙';
175
182
  dispatchEvent(input, 'input');
176
183
  _context6.next = 9;
177
184
  return wait();
178
185
  case 9:
179
- dropdown = getElement('.k-cascader-menu');
180
- expect(dropdown.innerHTML).to.matchSnapshot();
181
- expect(dropdown.innerText).to.eql('北京\n湖南');
182
- input.value = '长沙';
183
- dispatchEvent(input, 'input');
184
- _context6.next = 16;
185
- return wait();
186
- case 16:
187
186
  dropdown1 = getElement('.k-cascader-filter');
188
187
  expect(dropdown1.innerHTML).to.matchSnapshot();
189
188
  expect(dropdown1.innerText).to.eql('湖南 / 长沙市 / 岳麓区');
190
189
  // should show no-data layer
191
190
  input.value = 'xxx';
192
191
  dispatchEvent(input, 'input');
193
- _context6.next = 23;
192
+ _context6.next = 16;
194
193
  return wait();
195
- case 23:
194
+ case 16:
196
195
  expect(dropdown1.innerHTML).to.matchSnapshot();
197
196
  expect(dropdown1.innerText).to.eql('无匹配数据');
198
197
  input.value = '岳阳';
199
198
  dispatchEvent(input, 'input');
200
- _context6.next = 29;
199
+ _context6.next = 22;
201
200
  return wait();
202
- case 29:
201
+ case 22:
203
202
  expect(dropdown1.innerHTML).to.matchSnapshot();
204
203
  expect(dropdown1.childElementCount).to.eql(2);
205
204
  dropdown1.querySelector('.k-dropdown-item').click();
206
- _context6.next = 34;
205
+ _context6.next = 27;
207
206
  return wait();
208
- case 34:
207
+ case 27:
209
208
  expect(instance.get('value')).to.eql(['hunan', 'yueyang', 'yueyanglou']);
210
209
  // show again to test the position
211
210
  input.click();
212
- _context6.next = 38;
211
+ _context6.next = 31;
213
212
  return wait();
214
- case 38:
213
+ case 31:
215
214
  _getElements2 = getElements('.k-cascader-menu'), _dropdown1 = _getElements2[0], _dropdown2 = _getElements2[1], _dropdown3 = _getElements2[2];
216
215
  expect(_dropdown1.style.top).not.eql('0px');
217
216
  expect(_dropdown2.style.top).not.eql('0px');
218
217
  expect(_dropdown3.style.top).not.eql('0px');
219
- case 42:
218
+ case 35:
220
219
  case "end":
221
220
  return _context6.stop();
222
221
  }
@@ -2,20 +2,12 @@
2
2
  * The base hook for handling value of Datepicker and Timepicker
3
3
  */
4
4
  import { TypeDefs } from 'intact-react';
5
- import { State } from '../../hooks/useState';
6
- import { Dayjs, OpUnitType } from './dayjs';
5
+ import { Dayjs } from './dayjs';
7
6
  import type { useFormats } from './useFormats';
8
- import type { useDisabled } from './useDisabled';
9
- import { PanelFlags, usePanel } from './usePanel';
7
+ import { usePanel } from './usePanel';
10
8
  import { BaseSelect, BaseSelectProps, BaseSelectEvents, BaseSelectBlocks } from '../select/base';
11
9
  import type { Events } from '../types';
12
- export type StateValueRange = [Dayjs, Dayjs?];
13
- export type StateValueItem = Dayjs | StateValueRange;
14
- export type StateValue = StateValueItem[];
15
- export type StringValue = string | string[] | [string, string] | [string, string][];
16
- export type DayjsValueRange = [Dayjs, Dayjs];
17
- export type DayjsValueItem = Dayjs | DayjsValueRange;
18
- export type DayjsValue = DayjsValueItem[];
10
+ import type { useValueBase, StateValueRange, Value } from './useValueBase';
19
11
  export interface BasePickerProps<V extends Value = Value, Multipe extends boolean = boolean, Range extends boolean = boolean> extends BaseSelectProps<V | [V, V], Multipe> {
20
12
  value?: Multipe extends true ? Range extends true ? [
21
13
  V,
@@ -33,27 +25,16 @@ export interface BasePickerProps<V extends Value = Value, Multipe extends boolea
33
25
  disabledDate?: (v: Dayjs) => boolean;
34
26
  }
35
27
  export interface BasePickerEvents extends BaseSelectEvents {
36
- selecting: [StateValueRange];
28
+ selecting: [StateValueRange, boolean];
37
29
  }
38
30
  export interface BasePickerBlocks<V extends Value = Value, R extends boolean = boolean> extends BaseSelectBlocks<R extends true ? [Value, Value] : Value> {
39
31
  }
40
- export type Value = string | Date | number | Dayjs;
41
32
  export declare abstract class BasePicker<T extends BasePickerProps = BasePickerProps, E extends BasePickerEvents = BasePickerEvents, B extends BasePickerBlocks<any> = BasePickerBlocks<any>> extends BaseSelect<T, E, B> {
42
33
  static typeDefs: Required<TypeDefs<BasePickerProps<Value, boolean, boolean>>>;
43
34
  static defaults: () => Partial<BasePickerProps<any, boolean, boolean>>;
44
35
  static events: Events<BasePickerEvents>;
45
- abstract value: ReturnType<typeof useValue>;
36
+ abstract value: ReturnType<typeof useValueBase>;
46
37
  abstract formats: ReturnType<typeof useFormats>;
47
38
  abstract panel: ReturnType<typeof usePanel>;
48
- resetKeywords(keywords: State<string>): void;
39
+ resetKeywords(silent?: boolean): void;
49
40
  }
50
- export declare function useValue({ createDateByValueFormat, createDateByShowFormat, getShowString, getValueString, }: ReturnType<typeof useFormats>, { isDisabled, minDate }: ReturnType<typeof useDisabled>, panel: ReturnType<typeof usePanel>, shouldUpdateValue: (v: StateValueItem) => boolean, updateValueOnInput: (v: DayjsValueItem) => void, getEqualType: () => OpUnitType, updateStateValue: (v: DayjsValue, value: State<StateValue>) => void): {
51
- value: State<StateValue>;
52
- format: () => string | string[];
53
- onConfirm: () => void;
54
- onChangeTime: (date: Dayjs, flag: PanelFlags) => void;
55
- getTimeValue: (flag: PanelFlags) => Dayjs | null | undefined;
56
- setValue: (v: StateValueItem, fromInput: boolean) => void;
57
- convertToDayjs: (v: BasePickerProps<Value>['value']) => DayjsValue;
58
- getDayjsValue: () => DayjsValue;
59
- };
@@ -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-react';
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],
@@ -38,232 +28,30 @@ export var BasePicker = /*#__PURE__*/function (_BaseSelect) {
38
28
  return _BaseSelect.apply(this, arguments) || this;
39
29
  }
40
30
  var _proto = BasePicker.prototype;
41
- _proto.resetKeywords = function resetKeywords(keywords) {
42
- var _this$get = this.get(),
43
- multiple = _this$get.multiple,
44
- range = _this$get.range;
45
- var dayjsValue = this.value.getDayjsValue();
46
- var getShowString = this.formats.getShowString;
47
- var value = last(dayjsValue);
48
- keywords.set(multiple ? '' : !range ? value ? getShowString(value) : '' : value ? [getShowString(value[0]), 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
+ }
49
51
  };
50
52
  return BasePicker;
51
53
  }(BaseSelect);
52
54
  BasePicker.typeDefs = typeDefs;
53
55
  BasePicker.defaults = defaults;
54
56
  BasePicker.events = events;
55
- __decorate([bind], BasePicker.prototype, "resetKeywords", null);
56
- export function useValue(_ref, _ref2, panel, shouldUpdateValue, updateValueOnInput, getEqualType, updateStateValue) {
57
- var createDateByValueFormat = _ref.createDateByValueFormat,
58
- createDateByShowFormat = _ref.createDateByShowFormat,
59
- getShowString = _ref.getShowString,
60
- getValueString = _ref.getValueString;
61
- var isDisabled = _ref2.isDisabled,
62
- minDate = _ref2.minDate;
63
- // Normalize the value to multipe values, no matter it's multipe or not
64
- var value = useState([]);
65
- var instance = useInstance();
66
- var dayjsValue = [];
67
- instance.watch('value', function (newValue, oldValue) {
68
- if (isEqualArray(newValue, oldValue)) return;
69
- dayjsValue = convertToDayjs(newValue);
70
- updateStateValue(dayjsValue, value);
71
- // should update keywords
72
- instance.resetKeywords(instance.input.keywords);
73
- });
74
- watchState(instance.input.keywords, function (v) {
75
- var _instance$get = instance.get(),
76
- range = _instance$get.range,
77
- multiple = _instance$get.multiple;
78
- if (!multiple && v === '') return instance.set('value', null);
79
- if (range) {
80
- var _context;
81
- var _v$split$map = _mapInstanceProperty(_context = v.split(/\s*~\s*/)).call(_context, function (s) {
82
- return _trimInstanceProperty(s).call(s);
83
- }),
84
- start = _v$split$map[0],
85
- end = _v$split$map[1];
86
- if (start && end) {
87
- var startDate = createDateByShowFormat(start);
88
- if (!isValidDate(startDate)) {
89
- return;
90
- }
91
- var endDate = createDateByShowFormat(end);
92
- if (!isValidDate(endDate)) {
93
- return;
94
- }
95
- if (endDate.isAfter(startDate)) {
96
- updateValueOnInput([startDate, endDate]);
97
- }
98
- }
99
- } else {
100
- var date = createDateByShowFormat(v);
101
- if (isValidDate(date)) {
102
- updateValueOnInput(date);
103
- }
104
- }
105
- });
106
- function convertToDayjs(v) {
107
- if (!v || Array.isArray(v) && !v.length) return [];
108
- var _instance$get2 = instance.get(),
109
- multiple = _instance$get2.multiple;
110
- if (!multiple) {
111
- v = [v];
112
- }
113
- return _mapInstanceProperty(v).call(v, function (value) {
114
- if (Array.isArray(value)) {
115
- // range
116
- return _mapInstanceProperty(value).call(value, createDateByValueFormat);
117
- }
118
- return createDateByValueFormat(value);
119
- });
120
- }
121
- function convertToValueString(v) {
122
- var results = _mapInstanceProperty(v).call(v, function (value) {
123
- if (Array.isArray(value)) {
124
- return _mapInstanceProperty(value).call(value, getValueString);
125
- }
126
- return getValueString(value);
127
- });
128
- if (!instance.get('multiple')) {
129
- return results[0] || null;
130
- }
131
- return results;
132
- }
133
- function format() {
134
- var results = _mapInstanceProperty(dayjsValue).call(dayjsValue, function (value) {
135
- if (Array.isArray(value)) {
136
- return _mapInstanceProperty(value).call(value, getShowString).join(' ~ ');
137
- }
138
- return getShowString(value);
139
- });
140
- if (!instance.get('multiple')) {
141
- return results[0];
142
- }
143
- return results;
144
- }
145
- function setSingleDate(v, fromInput) {
146
- var _instance$get3 = instance.get(),
147
- range = _instance$get3.range;
148
- value.set([v]);
149
- if (fromInput || shouldUpdateValue(v)) {
150
- updateValue();
151
- }
152
- }
153
- function addMultipeDate(v, fromInput) {
154
- var _instance$get4 = instance.get(),
155
- range = _instance$get4.range;
156
- var _value = value.value;
157
- _value = !_value ? [] : _sliceInstanceProperty(_value).call(_value);
158
- if (range && v.length === 2) {
159
- // pop the last value firstly, if it only has the start date
160
- var lastValue = last(_value);
161
- if (lastValue && lastValue.length < 2) {
162
- _value.pop();
163
- }
164
- }
165
- var _shouldUpdateValue = true;
166
- if (fromInput || shouldUpdateValue(v)) {
167
- // if select the date/year/month, then toggle the value.
168
- // if from input, treat the value as the final value
169
- var index = findValueIndex(_value, v, getEqualType());
170
- if (index > -1) {
171
- _spliceInstanceProperty(_value).call(_value, index, 1);
172
- } else {
173
- _value.push(v);
174
- }
175
- } else {
176
- // select the datetime, only push the value,
177
- // and unique the array on click confrim button
178
- _value.push(v);
179
- _shouldUpdateValue = false;
180
- }
181
- value.set(_value);
182
- if (_shouldUpdateValue) {
183
- updateValue();
184
- }
185
- }
186
- function setValue(v, fromInput) {
187
- var multiple = instance.get('multiple');
188
- if (multiple) {
189
- addMultipeDate(v, fromInput);
190
- } else {
191
- setSingleDate(v, fromInput);
192
- }
193
- }
194
- function updateValue() {
195
- var _value = value.value;
196
- var valueStr = convertToValueString(_value);
197
- instance.set('value', valueStr);
198
- instance.resetKeywords(instance.input.keywords);
199
- }
200
- function onConfirm() {
201
- // unique
202
- if (!instance.get('multiple')) {
203
- instance.hide();
204
- } else {
205
- unique();
206
- panel.reset();
207
- }
208
- updateValue();
209
- }
210
- function unique() {
211
- var _value = value.value;
212
- var map = {};
213
- var results = [];
214
- _value.forEach(function (value) {
215
- var key;
216
- if (Array.isArray(value)) {
217
- key = _mapInstanceProperty(value).call(value, getValueString).join(' ~ ');
218
- } else {
219
- key = getValueString(value);
220
- }
221
- if (!map[key]) {
222
- map[key] = true;
223
- results.push(value);
224
- }
225
- });
226
- value.set(results);
227
- }
228
- function isValidDate(date) {
229
- return date.isValid() && !isDisabled(date, getEqualType());
230
- }
231
- function onChangeTime(date, flag) {
232
- var _context2;
233
- var _instance$get5 = instance.get(),
234
- range = _instance$get5.range;
235
- var values = _sliceInstanceProperty(_context2 = value.value).call(_context2);
236
- var lastIndex = values.length - 1;
237
- var _value = date;
238
- if (range) {
239
- var _context3;
240
- _value = _sliceInstanceProperty(_context3 = values[lastIndex]).call(_context3);
241
- _value[flag] = date;
242
- instance.trigger('selecting', _value);
243
- }
244
- values[lastIndex] = _value;
245
- value.set(values);
246
- }
247
- function getTimeValue(flag) {
248
- var _value = value.value;
249
- if (!_value.length) return null;
250
- var _instance$get6 = instance.get(),
251
- range = _instance$get6.range,
252
- min = _instance$get6.min;
253
- var lastValue = last(_value);
254
- return range ? lastValue[flag] : lastValue;
255
- }
256
- function getDayjsValue() {
257
- return dayjsValue;
258
- }
259
- return {
260
- value: value,
261
- format: format,
262
- onConfirm: onConfirm,
263
- onChangeTime: onChangeTime,
264
- getTimeValue: getTimeValue,
265
- setValue: setValue,
266
- convertToDayjs: convertToDayjs,
267
- getDayjsValue: getDayjsValue
268
- };
269
- }
57
+ __decorate([bind], BasePicker.prototype, "resetKeywords", null);
@@ -1,12 +1,14 @@
1
1
  import { Component } from 'intact-react';
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
- type?: 'date' | 'year' | 'month';
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];
@@ -14,7 +16,7 @@ export interface DatepickerCalendarEvents {
14
16
  export declare class DatepickerCalendar extends Component<DatepickerCalendarProps, DatepickerCalendarEvents> {
15
17
  static template: string | import('intact-react').Template<any>;
16
18
  static defaults: () => Partial<DatepickerCalendarProps>;
17
- type: import("../../hooks/useState").State<Required<"date" | "month" | "year" | undefined>>;
19
+ type: import("../../hooks/useState").State<Required<"date" | "month" | "week" | "year" | "quarter" | undefined>>;
18
20
  datepicker: Datepicker;
19
21
  showDate: {
20
22
  date: import("../../hooks/useState").State<Dayjs>;
@@ -30,9 +32,9 @@ export declare class DatepickerCalendar extends Component<DatepickerCalendarProp
30
32
  prevTenYears: () => void;
31
33
  };
32
34
  status: {
33
- isActive: (date: Dayjs, type: "date" | "month" | "year" | undefined) => boolean;
34
- isInRange: (date: Dayjs, type: "date" | "month" | "year" | undefined) => boolean;
35
- isDisabled: (value: Dayjs, type?: import("dayjs").OpUnitType) => boolean;
35
+ isActive: (date: Dayjs, type: "date" | "month" | "week" | "year" | "quarter" | undefined) => boolean;
36
+ isInRange: (date: Dayjs, type: "date" | "month" | "week" | "year" | "quarter" | undefined) => boolean;
37
+ isDisabled: (value: 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;
36
38
  };
37
39
  days: {
38
40
  getDays: (now: Dayjs) => {
@@ -74,6 +76,34 @@ export declare class DatepickerCalendar extends Component<DatepickerCalendarProp
74
76
  }[];
75
77
  onClick: (date: Dayjs) => void;
76
78
  };
79
+ weeks: {
80
+ getWeeks: (now: Dayjs) => {
81
+ week: number;
82
+ days: {
83
+ isExceed: boolean;
84
+ label: number;
85
+ value: Dayjs;
86
+ isActive: boolean;
87
+ isToday: boolean;
88
+ isDisabled: boolean;
89
+ isHover: boolean;
90
+ isInRange: boolean;
91
+ }[];
92
+ }[];
93
+ onClick: (day: Dayjs) => void;
94
+ };
95
+ quarters: {
96
+ getQuarters: (now: Dayjs) => {
97
+ isActive: boolean;
98
+ isToday: boolean;
99
+ isDisabled: boolean;
100
+ isHover: boolean;
101
+ isInRange: boolean;
102
+ label: string;
103
+ value: Dayjs;
104
+ }[];
105
+ onClick: (date: Dayjs) => void;
106
+ };
77
107
  private config;
78
108
  triggerChange(value: Dayjs): void;
79
109
  }
@@ -11,6 +11,8 @@ import { useShowDate } from './useShowDate';
11
11
  import { bind } from '../utils';
12
12
  import { useYears } from './useYears';
13
13
  import { useMonths } from './useMonths';
14
+ import { useWeeks } from './useWeeks';
15
+ import { useQuarters } from './useQuarters';
14
16
  import { useStatus } from './useStatus';
15
17
  import { useConfigContext } from '../config';
16
18
  var defaults = function defaults() {
@@ -34,6 +36,8 @@ export var DatepickerCalendar = /*#__PURE__*/function (_Component) {
34
36
  _this.days = useDays(_this.showDate.date, _this.status, _this.datepicker.focusDate.focusDate);
35
37
  _this.years = useYears(_this.showDate.date, _this.status, _this.datepicker.focusDate.focusDate);
36
38
  _this.months = useMonths(_this.showDate.date, _this.status, _this.datepicker.focusDate.focusDate);
39
+ _this.weeks = useWeeks(_this.showDate.date, _this.status, _this.datepicker.focusDate.focusDate);
40
+ _this.quarters = useQuarters(_this.showDate.date, _this.status, _this.datepicker.focusDate.focusDate);
37
41
  _this.config = useConfigContext();
38
42
  return _this;
39
43
  }
@@ -12,7 +12,12 @@ export default function ($props, $blocks, $__proto__) {
12
12
  var $this = this;
13
13
  var type = this.type.value;
14
14
  var isYear = type === 'year';
15
+ var isWeek = type === 'week';
16
+ var isQuarter = type === 'quarter';
15
17
  var isYearOrMonth = isYear || type === 'month';
18
+ var isDateOrDateTime = type === 'date' || type === 'datetime';
19
+ // isDateOrDateTime & isWeek合并
20
+ var showDateWeeks = isDateOrDateTime || isWeek;
16
21
  var k = this.config.k;
17
22
  var classNameObj = (_classNameObj = {}, _classNameObj[k + "-datepicker-calendar"] = true, _classNameObj[makeCalendarStyles(k)] = true, _classNameObj);
18
23
  var now = getNowDate();
@@ -58,7 +63,7 @@ export default function ($props, $blocks, $__proto__) {
58
63
  'className': _$cn(k + "-icon-left"),
59
64
  'size': 'small'
60
65
  })]
61
- }), !isYearOrMonth ? _$cc(Button, {
66
+ }), showDateWeeks ? _$cc(Button, {
62
67
  'icon': true,
63
68
  'type': 'none',
64
69
  'size': 'small',
@@ -73,7 +78,7 @@ export default function ($props, $blocks, $__proto__) {
73
78
  return _$ce(2, 'span', $value.value, 0, _$cn(k + "-month-value"), {
74
79
  'ev-click': $value.onClick
75
80
  });
76
- }, $this) : _$ce(2, 'span', this.years.getYearLabel(), 0, _$cn(k + "-month-value")), 0, _$cn(k + "-month-values")), _$ce(2, 'div', [!isYearOrMonth ? _$cc(Button, {
81
+ }, $this) : _$ce(2, 'span', this.years.getYearLabel(), 0, _$cn(k + "-month-value")), 0, _$cn(k + "-month-values")), _$ce(2, 'div', [showDateWeeks ? _$cc(Button, {
77
82
  'icon': true,
78
83
  'type': 'none',
79
84
  'size': 'small',
@@ -98,11 +103,22 @@ export default function ($props, $blocks, $__proto__) {
98
103
  'className': _$cn(k + "-icon-right"),
99
104
  'size': 'small'
100
105
  })]
101
- })], 0, _$cn(k + "-right-btns"))], 4, _$cn(k + "-datepicker-month")), !isYearOrMonth ? [_$ce(2, 'div', _$ma([_$('日'), _$('一'), _$('二'), _$('三'), _$('四'), _$('五'), _$('六')], function ($value, $key) {
106
+ })], 0, _$cn(k + "-right-btns"))], 4, _$cn(k + "-datepicker-month")), showDateWeeks ? [_$ce(2, 'div', _$ma([_$('日'), _$('一'), _$('二'), _$('三'), _$('四'), _$('五'), _$('六')], function ($value, $key) {
102
107
  return _$ce(2, 'div', $value, 0, _$cn(k + "-weekday"));
103
- }, $this), 4, _$cn(k + "-weekdays")), _$ce(2, 'div', getItems(getDays(now), onClickDay), 0, _$cn(k + "-days"), {
108
+ }, $this), 4, _$cn(k + "-weekdays")), isWeek ? _$ce(2, 'div', _$ma(this.weeks.getWeeks(now), function ($value, $key) {
109
+ return _$ce(2, 'div', [_$ce(2, 'div', $value.week, 0, _$cn(k + "-week-number"), {
110
+ 'ev-click': function evClick(e) {
111
+ onClickDay($value.days[0].value);
112
+ },
113
+ 'ev-mouseenter': function evMouseenter() {
114
+ return focusDate.set($value.days[0].value);
115
+ }
116
+ }), getItems($value.days, onClickDay)], 0, 'week-row');
117
+ }, $this), 4, _$cn(k + "-weeks"), {
104
118
  'ev-mouseleave': resetFocusDate
105
- })] : _$ce(2, 'div', isYear ? getItems(this.years.getYears(now), this.years.onClick) : getItems(this.months.getMonths(now), this.months.onClick), 0, _$cn(k + "-years"), {
119
+ }) : _$ce(2, 'div', getItems(getDays(now), onClickDay), 0, _$cn(k + "-days"), {
120
+ 'ev-mouseleave': resetFocusDate
121
+ })] : _$ce(2, 'div', isYear ? getItems(this.years.getYears(now), this.years.onClick) : isQuarter ? getItems(this.quarters.getQuarters(now), this.quarters.onClick) : getItems(this.months.getMonths(now), this.months.onClick), 0, _$cn(k + "-years"), {
106
122
  'ev-mouseleave': resetFocusDate
107
123
  })], 0, _$cn(classNameObj));
108
124
  }
@@ -1,3 +1,3 @@
1
- import dayjs, { Dayjs, OpUnitType } from 'dayjs';
1
+ import dayjs, { Dayjs, OpUnitType, QUnitType } from 'dayjs';
2
2
  export default dayjs;
3
- export type { Dayjs, OpUnitType };
3
+ export type { Dayjs, OpUnitType, QUnitType };
@@ -1,4 +1,10 @@
1
1
  import dayjs 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
  dayjs.extend(customParseFormat);
7
+ dayjs.extend(weekOfYear);
8
+ dayjs.extend(quarterOfYear);
9
+ dayjs.extend(advancedFormat);
4
10
  export default dayjs;
@@ -1,11 +1,12 @@
1
- import dayjs, { Dayjs, OpUnitType } from 'dayjs';
2
- import { StateValueItem } from './basepicker';
1
+ import dayjs, { Dayjs, OpUnitType, QUnitType } from 'dayjs';
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;
6
- export declare function isEqual(a: Dayjs | undefined | null, b: Dayjs | undefined | null, type?: OpUnitType): boolean;
7
- export declare function isLT(a: Dayjs | undefined | null, b: Dayjs | undefined | null, type?: OpUnitType): boolean;
8
- export declare function isGT(a: Dayjs | undefined | null, b: Dayjs | undefined | null, type?: OpUnitType): boolean;
7
+ export declare function isEqual(a: Dayjs | undefined | null, b: Dayjs | undefined | null, type?: OpUnitType | QUnitType): boolean;
8
+ export declare function isLT(a: Dayjs | undefined | null, b: Dayjs | undefined | null, type?: OpUnitType | QUnitType): boolean;
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
- export declare function findValueIndex(values: StateValueItem[], value: StateValueItem, type: OpUnitType): number;
11
- export declare function last<T>(arr: T[]): T | undefined;
11
+ export declare function findValueIndex(values: StateValueItem[], value: StateValueItem, type: OpUnitType | QUnitType): number;
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 };