@king-design/intact 3.6.0-beta.0 → 3.6.1

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 (188) hide show
  1. package/components/button/demos/basic.md +0 -1
  2. package/components/cascader/index.spec.ts +7 -6
  3. package/components/copy/index.spec.ts +9 -14
  4. package/components/datepicker/basepicker.ts +26 -314
  5. package/components/datepicker/calendar.ts +3 -1
  6. package/components/datepicker/calendar.vdt +5 -2
  7. package/components/datepicker/dayjs.ts +2 -16
  8. package/components/datepicker/demos/multiple.md +5 -0
  9. package/components/datepicker/demos/yearMonth.md +2 -8
  10. package/components/datepicker/helpers.ts +5 -7
  11. package/components/datepicker/index.md +1 -2
  12. package/components/datepicker/index.spec.ts +596 -157
  13. package/components/datepicker/index.ts +16 -33
  14. package/components/datepicker/index.vdt +41 -35
  15. package/components/datepicker/shortcuts.ts +1 -1
  16. package/components/datepicker/styles.ts +27 -18
  17. package/components/datepicker/useConfirm.ts +82 -0
  18. package/components/datepicker/useDisabled.ts +29 -31
  19. package/components/datepicker/useFormats.ts +8 -4
  20. package/components/datepicker/useHighlight.ts +81 -0
  21. package/components/datepicker/useKeyboards.ts +2 -1
  22. package/components/datepicker/useMergeRange.ts +12 -12
  23. package/components/datepicker/useMonths.ts +6 -3
  24. package/components/datepicker/usePanel.ts +19 -19
  25. package/components/datepicker/useShowDate.ts +21 -41
  26. package/components/datepicker/useStatus.ts +34 -15
  27. package/components/datepicker/useValue.ts +43 -72
  28. package/components/datepicker/useValueBase.ts +312 -0
  29. package/components/datepicker/useWeeks.ts +1 -1
  30. package/components/datepicker/useYears.ts +7 -3
  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/form/form.ts +4 -0
  36. package/components/form/index.md +2 -1
  37. package/components/form/index.spec.ts +2 -0
  38. package/components/input/index.spec.ts +42 -0
  39. package/components/input/index.ts +8 -0
  40. package/components/input/index.vdt +3 -4
  41. package/components/input/useAutoWidth.ts +19 -1
  42. package/components/menu/demos/horizontal.md +7 -1
  43. package/components/menu/index.spec.ts +19 -0
  44. package/components/menu/styles.ts +2 -1
  45. package/components/scrollSelect/useMouseEvents.ts +5 -4
  46. package/components/select/base.ts +3 -2
  47. package/components/select/base.vdt +2 -1
  48. package/components/select/demos/creatable.md +2 -2
  49. package/components/select/index.md +1 -1
  50. package/components/select/index.spec.ts +142 -36
  51. package/components/select/menu.ts +1 -1
  52. package/components/select/option.ts +2 -1
  53. package/components/select/select.ts +1 -0
  54. package/components/select/styles.ts +3 -1
  55. package/components/select/useCard.ts +22 -4
  56. package/components/select/useInput.ts +5 -9
  57. package/components/spinner/index.spec.ts +18 -0
  58. package/components/spinner/useValue.ts +2 -1
  59. package/components/table/index.spec.ts +69 -1
  60. package/components/table/useStickyHeader.ts +1 -1
  61. package/components/timepicker/index.spec.ts +145 -27
  62. package/components/timepicker/panelPicker.ts +10 -4
  63. package/components/timepicker/panelPicker.vdt +3 -5
  64. package/components/timepicker/styles.ts +1 -0
  65. package/components/timepicker/useConfirm.ts +33 -0
  66. package/components/timepicker/useDefaultValue.ts +30 -0
  67. package/components/timepicker/useDisabled.ts +17 -4
  68. package/components/timepicker/useFormats.ts +1 -1
  69. package/components/timepicker/useValue.ts +22 -19
  70. package/components/tour/index.spec.ts +1 -1
  71. package/es/components/cascader/index.spec.js +18 -19
  72. package/es/components/copy/index.spec.js +14 -31
  73. package/es/components/datepicker/basepicker.d.ts +6 -27
  74. package/es/components/datepicker/basepicker.js +23 -268
  75. package/es/components/datepicker/calendar.d.ts +4 -2
  76. package/es/components/datepicker/dayjs.d.ts +2 -13
  77. package/es/components/datepicker/helpers.d.ts +3 -2
  78. package/es/components/datepicker/helpers.js +2 -3
  79. package/es/components/datepicker/index.d.ts +21 -29
  80. package/es/components/datepicker/index.js +22 -32
  81. package/es/components/datepicker/index.spec.js +1277 -484
  82. package/es/components/datepicker/index.vdt.js +39 -38
  83. package/es/components/datepicker/shortcuts.d.ts +1 -1
  84. package/es/components/datepicker/styles.d.ts +7 -2
  85. package/es/components/datepicker/styles.js +10 -15
  86. package/es/components/datepicker/useConfirm.d.ts +6 -0
  87. package/es/components/datepicker/useConfirm.js +65 -0
  88. package/es/components/datepicker/useDisabled.d.ts +5 -3
  89. package/es/components/datepicker/useDisabled.js +22 -27
  90. package/es/components/datepicker/useFormats.d.ts +2 -2
  91. package/es/components/datepicker/useFormats.js +6 -2
  92. package/es/components/datepicker/useHighlight.d.ts +14 -0
  93. package/es/components/datepicker/useHighlight.js +60 -0
  94. package/es/components/datepicker/useKeyboards.js +2 -1
  95. package/es/components/datepicker/useMergeRange.d.ts +1 -1
  96. package/es/components/datepicker/useMergeRange.js +11 -16
  97. package/es/components/datepicker/useMonths.js +5 -3
  98. package/es/components/datepicker/usePanel.d.ts +1 -10
  99. package/es/components/datepicker/usePanel.js +19 -32
  100. package/es/components/datepicker/useShowDate.d.ts +1 -1
  101. package/es/components/datepicker/useShowDate.js +15 -40
  102. package/es/components/datepicker/useStatus.js +33 -16
  103. package/es/components/datepicker/useValue.d.ts +11 -6
  104. package/es/components/datepicker/useValue.js +49 -69
  105. package/es/components/datepicker/useValueBase.d.ts +28 -0
  106. package/es/components/datepicker/useValueBase.js +280 -0
  107. package/es/components/datepicker/useYears.js +6 -3
  108. package/es/components/dropdown/dropdown.d.ts +1 -0
  109. package/es/components/dropdown/dropdown.js +7 -4
  110. package/es/components/form/form.d.ts +1 -0
  111. package/es/components/form/form.js +7 -0
  112. package/es/components/form/index.spec.js +10 -8
  113. package/es/components/input/index.d.ts +2 -0
  114. package/es/components/input/index.js +6 -0
  115. package/es/components/input/index.spec.js +45 -0
  116. package/es/components/input/index.vdt.js +4 -3
  117. package/es/components/input/useAutoWidth.d.ts +2 -0
  118. package/es/components/input/useAutoWidth.js +19 -1
  119. package/es/components/menu/index.spec.js +28 -0
  120. package/es/components/menu/styles.js +2 -2
  121. package/es/components/scrollSelect/useMouseEvents.js +5 -4
  122. package/es/components/select/base.d.ts +1 -1
  123. package/es/components/select/base.js +3 -2
  124. package/es/components/select/base.vdt.js +4 -3
  125. package/es/components/select/index.spec.js +346 -218
  126. package/es/components/select/menu.js +1 -1
  127. package/es/components/select/option.js +2 -1
  128. package/es/components/select/select.js +2 -1
  129. package/es/components/select/styles.d.ts +79 -0
  130. package/es/components/select/styles.js +1 -0
  131. package/es/components/select/useCard.d.ts +4 -3
  132. package/es/components/select/useCard.js +15 -4
  133. package/es/components/select/useInput.d.ts +1 -1
  134. package/es/components/select/useInput.js +4 -4
  135. package/es/components/spinner/index.spec.js +82 -44
  136. package/es/components/spinner/useValue.js +2 -1
  137. package/es/components/table/index.spec.js +84 -6
  138. package/es/components/table/useStickyHeader.js +1 -1
  139. package/es/components/timepicker/index.spec.js +298 -128
  140. package/es/components/timepicker/panelPicker.d.ts +21 -16
  141. package/es/components/timepicker/panelPicker.js +7 -4
  142. package/es/components/timepicker/panelPicker.vdt.js +5 -9
  143. package/es/components/timepicker/selectPicker.d.ts +4 -3
  144. package/es/components/timepicker/styles.js +1 -1
  145. package/es/components/timepicker/useConfirm.d.ts +6 -0
  146. package/es/components/timepicker/useConfirm.js +19 -0
  147. package/es/components/timepicker/useDefaultValue.d.ts +4 -0
  148. package/es/components/timepicker/useDefaultValue.js +27 -0
  149. package/es/components/timepicker/useDisabled.d.ts +6 -3
  150. package/es/components/timepicker/useDisabled.js +13 -4
  151. package/es/components/timepicker/useFormats.d.ts +1 -1
  152. package/es/components/timepicker/useValue.d.ts +13 -8
  153. package/es/components/timepicker/useValue.js +14 -15
  154. package/es/components/tour/index.spec.js +1 -1
  155. package/es/index.d.ts +2 -2
  156. package/es/index.js +2 -2
  157. package/es/site/data/components/button/demos/basic/react.js +0 -2
  158. package/es/site/data/components/datepicker/demos/multiple/index.d.ts +1 -0
  159. package/es/site/data/components/datepicker/demos/multiple/index.js +2 -1
  160. package/es/site/data/components/datepicker/demos/multiple/react.d.ts +1 -0
  161. package/es/site/data/components/datepicker/demos/multiple/react.js +13 -2
  162. package/es/site/data/components/datepicker/demos/yearMonth/index.d.ts +0 -2
  163. package/es/site/data/components/datepicker/demos/yearMonth/index.js +1 -3
  164. package/es/site/data/components/datepicker/demos/yearMonth/react.d.ts +0 -2
  165. package/es/site/data/components/datepicker/demos/yearMonth/react.js +1 -21
  166. package/es/site/data/components/menu/demos/horizontal/react.js +5 -1
  167. package/es/site/data/components/select/demos/creatable/react.js +2 -2
  168. package/es/site/data/components/select/demos/searchable/index.js +1 -1
  169. package/es/site/data/components/select/demos/searchable/react.js +1 -1
  170. package/es/site/data/components/tour/demos/customText/index.d.ts +19 -6
  171. package/es/site/data/components/tour/demos/customText/index.js +18 -17
  172. package/es/site/data/components/tour/demos/customText/react.d.ts +20 -6
  173. package/es/site/data/components/tour/demos/customText/react.js +31 -27
  174. package/es/test/demos.js +1 -1
  175. package/index.ts +2 -2
  176. package/package.json +2 -2
  177. package/components/datepicker/demos/nowrap.md +0 -35
  178. package/components/datepicker/usePosition.ts +0 -169
  179. package/es/components/datepicker/usePosition.d.ts +0 -10
  180. package/es/components/datepicker/usePosition.js +0 -166
  181. package/es/site/data/components/datepicker/demos/nowrap/index.d.ts +0 -10
  182. package/es/site/data/components/datepicker/demos/nowrap/index.js +0 -19
  183. package/es/site/data/components/datepicker/demos/nowrap/react.d.ts +0 -10
  184. package/es/site/data/components/datepicker/demos/nowrap/react.js +0 -49
  185. package/es/site/data/components/tour/demos/customButtons/index.d.ts +0 -33
  186. package/es/site/data/components/tour/demos/customButtons/index.js +0 -55
  187. package/es/site/data/components/tour/demos/customButtons/react.d.ts +0 -33
  188. package/es/site/data/components/tour/demos/customButtons/react.js +0 -99
@@ -20,7 +20,6 @@ import {Button} from 'kpc';
20
20
  <Button type="flat">flat</Button>
21
21
  <Button color="red">custom</Button>
22
22
  <Button color="#0000ea">custom</Button>
23
- <Button color="rgb(183, 18, 193)">custom</Button>
24
23
  </div>
25
24
  ```
26
25
 
@@ -104,13 +104,14 @@ describe('Cascader', () => {
104
104
  input.click();
105
105
  await wait();
106
106
 
107
+ // FIXME: maybe we should show no-data layer
107
108
  // should show layer when input empty string
108
- input.value = ' ';
109
- dispatchEvent(input, 'input');
110
- await wait();
111
- const dropdown = getElement('.k-cascader-menu')!;
112
- expect(dropdown.innerHTML).to.matchSnapshot();
113
- expect(dropdown.innerText).to.eql('北京\n湖南');
109
+ // input.value = ' ';
110
+ // dispatchEvent(input, 'input');
111
+ // await wait();
112
+ // const dropdown = getElement('.k-cascader-menu')!;
113
+ // expect(dropdown.innerHTML).to.matchSnapshot();
114
+ // expect(dropdown.innerText).to.eql('北京\n湖南');
114
115
 
115
116
  input.value = '长沙';
116
117
  dispatchEvent(input, 'input');
@@ -10,19 +10,18 @@ describe('Copy', () => {
10
10
  });
11
11
 
12
12
  it('should copy', async function() {
13
+ const spy = sinon.spy(navigator.clipboard, 'writeText');
13
14
  const [instance, element] = mount(BasicDemo);
14
15
 
15
16
  element.click();
16
- try {
17
- const text = await navigator.clipboard.readText();
18
- expect(text).to.eql('Hello King Desgin!');
19
- } catch (e) {
20
- // Read permisson denied
21
- console.log(e);
22
- }
17
+ await wait();
18
+ expect(spy.calledWith('Hello King Desgin!')).to.be.true;
19
+
20
+ spy.restore();
23
21
  });
24
22
 
25
23
  it('wrap copy with tooltip', async () => {
24
+ const spy = sinon.spy(navigator.clipboard, 'writeText');
26
25
  class Demo extends Component {
27
26
  static template = `
28
27
  const { Tooltip, Copy } = this;
@@ -38,12 +37,8 @@ describe('Copy', () => {
38
37
 
39
38
  element.click();
40
39
  await wait();
41
- try {
42
- const text = await navigator.clipboard.readText();
43
- expect(text).to.eql('test');
44
- } catch (e) {
45
- // Read permisson denied
46
- console.log(e);
47
- }
40
+ expect(spy.calledWith('test')).to.be.true;
41
+
42
+ spy.restore();
48
43
  });
49
44
  });
@@ -1,25 +1,15 @@
1
1
  /**
2
2
  * The base hook for handling value of Datepicker and Timepicker
3
3
  */
4
- import {useInstance, Component, TypeDefs} from 'intact';
5
- import {useState, watchState, State} from '../../hooks/useState';
6
- import dayjs, {Dayjs, OpUnitType, QUnitType} from './dayjs';
7
- import {findValueIndex} from './helpers';
4
+ import {TypeDefs} from 'intact';
5
+ import {State} from '../../hooks/useState';
6
+ import dayjs, {Dayjs} from './dayjs';
8
7
  import type {useFormats} from './useFormats';
9
- import type {useDisabled} from './useDisabled';
10
- import {isEqualArray, last, bind} from '../utils';
11
- import {PanelTypes, PanelFlags, usePanel} from './usePanel';
8
+ import {last, bind} from '../utils';
9
+ import {usePanel} from './usePanel';
12
10
  import {BaseSelect, BaseSelectProps, BaseSelectEvents, BaseSelectBlocks} from '../select/base';
13
11
  import type {Events} from '../types';
14
-
15
- export type StateValueRange = [Dayjs, Dayjs?];
16
- export type StateValueItem = Dayjs | StateValueRange;
17
- export type StateValue = StateValueItem[]
18
-
19
- export type StringValue = string | string[] | [string, string] | [string, string][]
20
- export type DayjsValueRange = [Dayjs, Dayjs]
21
- export type DayjsValueItem = Dayjs | DayjsValueRange
22
- export type DayjsValue = DayjsValueItem[]
12
+ import type {useValueBase, StateValueRange, DayjsValueRange, Value} from './useValueBase';
23
13
 
24
14
  export interface BasePickerProps<
25
15
  V extends Value = Value,
@@ -44,8 +34,7 @@ export interface BasePickerProps<
44
34
  }
45
35
 
46
36
  export interface BasePickerEvents extends BaseSelectEvents {
47
- selecting: [StateValueRange],
48
- togglePosition: []
37
+ selecting: [StateValueRange, boolean],
49
38
  }
50
39
 
51
40
  export interface BasePickerBlocks<
@@ -53,8 +42,6 @@ export interface BasePickerBlocks<
53
42
  R extends boolean = boolean,
54
43
  > extends BaseSelectBlocks<R extends true ? [Value, Value] : Value> { }
55
44
 
56
- export type Value = string | Date | number | Dayjs;
57
-
58
45
  const typeDefs: Required<TypeDefs<BasePickerProps<Value>>> = {
59
46
  ...BaseSelect.typeDefs,
60
47
  value: [String, Array, Date, Number, dayjs],
@@ -75,7 +62,6 @@ const defaults = (): Partial<BasePickerProps<any>> => ({
75
62
  const events: Events<BasePickerEvents> = {
76
63
  ...BaseSelect.events,
77
64
  selecting: true,
78
- togglePosition: true,
79
65
  };
80
66
 
81
67
  export abstract class BasePicker<
@@ -87,25 +73,30 @@ export abstract class BasePicker<
87
73
  static defaults = defaults;
88
74
  static events = events;
89
75
 
90
- public abstract value: ReturnType<typeof useValue>
76
+ public abstract value: ReturnType<typeof useValueBase>
91
77
  public abstract formats: ReturnType<typeof useFormats>
92
78
  public abstract panel: ReturnType<typeof usePanel>
93
79
 
94
80
  @bind
95
- public resetKeywords(keywords: State<string>) {
96
- const {multiple, range} = this.get();
97
- const dayjsValue = this.value.getDayjsValue();
98
- const {getShowString} = this.formats;
99
- const value = last(dayjsValue);
81
+ public resetKeywords(silent: boolean = false) {
82
+ // const {multiple} = this.get();
83
+ // const dayjsValue = this.value.getDayjsValue();
84
+ const value = last(this.value.value.value);
85
+ const keywords = this.input.keywords;
86
+
87
+ let _keywords = '';
88
+ if (value && !this.value.allValuesUpdatedInMultipleMode()) {
89
+ _keywords = this.value.formatSingleValue(value);
90
+ }
100
91
 
101
- keywords.set(
102
- multiple ? '' : !range ?
103
- value ? getShowString(value as Dayjs) : '' :
104
- value ? [
105
- (value as DayjsValueRange)[0] ? getShowString((value as DayjsValueRange)[0]) : '',
106
- (value as DayjsValueRange)[1] ? getShowString((value as DayjsValueRange)[1]) : '',
107
- ].join(' ~ ') : ''
108
- );
92
+ if (!silent) {
93
+ keywords.set(_keywords);
94
+ } else {
95
+ // update keywords will update value, because it is been watched in useValueBase
96
+ // silent in this case to update keywords to show it in input
97
+ (keywords as any).value = _keywords;
98
+ this.forceUpdate();
99
+ }
109
100
  }
110
101
 
111
102
  // @bind
@@ -115,282 +106,3 @@ export abstract class BasePicker<
115
106
  // }
116
107
  }
117
108
 
118
- export function useValue(
119
- {
120
- createDateByValueFormat,
121
- createDateByShowFormat,
122
- getShowString,
123
- getValueString,
124
- }: ReturnType<typeof useFormats>,
125
- {isDisabled, minDate}: ReturnType<typeof useDisabled>,
126
- panel: ReturnType<typeof usePanel>,
127
- shouldUpdateValue: (v: StateValueItem) => boolean,
128
- updateValueOnInput: (v: DayjsValueItem) => void,
129
- getEqualType: () => OpUnitType | QUnitType,
130
- updateStateValue: (v: DayjsValue, value: State<StateValue>) => void,
131
- ) {
132
- // Normalize the value to multipe values, no matter it's multipe or not
133
- const value = useState<StateValue>([]);
134
- const instance = useInstance() as BasePicker<BasePickerProps<Value>>;
135
- let dayjsValue: DayjsValue = [];
136
-
137
- instance.watch('value', (newValue, oldValue) => {
138
-
139
- if (isEqualArray(newValue, oldValue)) return;
140
-
141
- // 检查是否与当前 dayjsValue 对应的字符串相同,避免循环
142
- const currentValueStr = convertToValueString(dayjsValue);
143
- if (newValue === currentValueStr) {
144
- return;
145
- }
146
-
147
- // 只执行一次转换和更新逻辑
148
- const _value = convertToDayjs(newValue);
149
-
150
- dayjsValue = _value;
151
- updateStateValue(_value, value);
152
- instance.resetKeywords(instance.input.keywords);
153
-
154
-
155
- });
156
-
157
- watchState(instance.input.keywords, v => {
158
- const {range, multiple} = instance.get();
159
- if (!multiple && v === '') return instance.set('value', null);
160
-
161
- if (range) {
162
- const [start, end] = v.split(/\s*~\s*/).map(s => s.trim());
163
- if (start && end) {
164
- const startDate = createDateByShowFormat(start);
165
- if (!isValidDate(startDate)) {
166
- return;
167
- }
168
- const endDate = createDateByShowFormat(end);
169
- if (!isValidDate(endDate)) {
170
- return;
171
- }
172
- if (endDate.isAfter(startDate)) {
173
- updateValueOnInput([startDate, endDate]);
174
- } else {
175
- updateValueOnInput([endDate, startDate]);
176
- }
177
- }
178
- } else {
179
- const date = createDateByShowFormat(v);
180
- if (isValidDate(date)) {
181
- updateValueOnInput(date);
182
- }
183
- }
184
- });
185
-
186
- function convertToDayjs(v: BasePickerProps<Value>['value']): DayjsValue {
187
- if (!v || Array.isArray(v) && !v.length) return [];
188
-
189
- const {multiple} = instance.get();
190
- if (!multiple) {
191
- v = [v] as any;
192
- }
193
- return (v as (Value | [Value, Value])[]).map(value => {
194
- if (Array.isArray(value)) {
195
- // range
196
- return value.map(createDateByValueFormat);
197
- }
198
- return createDateByValueFormat(value);
199
- }) as DayjsValue;
200
- }
201
-
202
- function convertToValueString(v: DayjsValue): StringValue | null {
203
- const results = v.map(value => {
204
- if (Array.isArray(value)) {
205
- return value.map(getValueString);
206
- }
207
- return getValueString(value);
208
- });
209
-
210
- if (!instance.get('multiple')) {
211
- return results[0] || null;
212
- }
213
- return results as StringValue;
214
- }
215
-
216
- function format(): string | string[] {
217
- const results = dayjsValue.map(value => {
218
- if (Array.isArray(value)) {
219
- return value.map(getShowString).join(' ~ ');
220
- }
221
- return getShowString(value);
222
- });
223
-
224
- if (!instance.get('multiple')) {
225
- return results[0];
226
- }
227
- return results;
228
- }
229
-
230
- function setSingleDate(v: StateValueItem, fromInput: boolean) {
231
- value.set([v]);
232
- if (fromInput || shouldUpdateValue(v)) {
233
- updateValue();
234
- }
235
- }
236
-
237
- function addMultipeDate(v: StateValueItem, fromInput: boolean) {
238
- const {range} = instance.get();
239
- let _value = value.value as StateValueItem[];
240
- _value = !_value ? [] : _value.slice();
241
-
242
- if (range && (v as StateValueRange).length === 2) {
243
- // pop the last value firstly, if it only has the start date
244
- const lastValue = last(_value);
245
- if (lastValue && (lastValue as StateValueRange).length < 2) {
246
- _value.pop();
247
- }
248
- }
249
-
250
- let _shouldUpdateValue = true;
251
- if (fromInput || shouldUpdateValue(v)) {
252
- // if select the date/year/month, then toggle the value.
253
- // if from input, treat the value as the final value
254
- const index = findValueIndex(_value, v, getEqualType());
255
- if (index > -1) {
256
- _value.splice(index, 1);
257
- } else {
258
- _value.push(v);
259
- }
260
- } else {
261
- // select the datetime, only push the value,
262
- // and unique the array on click confrim button
263
- _value.push(v);
264
- _shouldUpdateValue = false;
265
- }
266
-
267
- value.set(_value);
268
-
269
- if (_shouldUpdateValue) {
270
- updateValue();
271
- }
272
- }
273
-
274
- function setValue(v: StateValueItem, fromInput: boolean) {
275
- const multiple = instance.get('multiple');
276
- if (multiple) {
277
- addMultipeDate(v, fromInput);
278
- } else {
279
- setSingleDate(v, fromInput);
280
- }
281
- }
282
-
283
- function updateValue() {
284
- const _value = value.value as DayjsValue;
285
-
286
- const valueStr = convertToValueString(_value);
287
-
288
- // 检查是否需要更新,避免循环调用
289
- if (instance.get('value') === valueStr) {
290
- return;
291
- }
292
-
293
- // 在设置 value 之前先更新 dayjsValue
294
- dayjsValue = _value;
295
- instance.set('value', valueStr);
296
-
297
- instance.resetKeywords(instance.input.keywords);
298
-
299
- }
300
-
301
- function onConfirm() {
302
- const lastValue = last(instance.value.value.value);
303
- const {multiple, range} = instance.get();
304
- if (!multiple) {
305
-
306
- if (range) {
307
- // 范围选择:需要开始和结束时间都选择完才关闭
308
- if((lastValue as [Dayjs, Dayjs?]).length === 2) {
309
- instance.hide();
310
- }
311
- instance.trigger('togglePosition');
312
- } else {
313
- // 单选:选择完时间就关闭
314
- if (lastValue) {
315
- instance.hide();
316
- }
317
- }
318
-
319
- } else {
320
- unique();
321
- panel.reset();
322
- }
323
- updateValue();
324
- }
325
-
326
- function setMoment() {
327
- const now = dayjs();
328
- setValue(now, true);
329
- instance.hide();
330
- }
331
-
332
- function unique() {
333
- const _value = value.value;
334
- const map: Record<string, true> = {};
335
- const results: StateValue = [];
336
- _value.forEach(value => {
337
- let key: string;
338
- if (Array.isArray(value)) {
339
- key = (value as DayjsValueRange).map(getValueString).join(' ~ ');
340
- } else {
341
- key = getValueString(value);
342
- }
343
- if (!map[key]) {
344
- map[key] = true;
345
- results.push(value);
346
- }
347
- });
348
-
349
- value.set(results);
350
- }
351
-
352
- function isValidDate(date: Dayjs) {
353
- return date.isValid() && !isDisabled(date, getEqualType());
354
- }
355
-
356
- function onChangeTime(date: Dayjs, flag: PanelFlags) {
357
- const {range} = instance.get();
358
- const values = value.value.slice();
359
- const lastIndex = values.length - 1;
360
- let _value: StateValueItem = date;
361
-
362
- if (range) {
363
- _value = (values as DayjsValueRange[])[lastIndex].slice() as DayjsValueRange;
364
- _value[flag] = date;
365
- instance.trigger('selecting', _value);
366
- }
367
-
368
- values[lastIndex] = _value;
369
- value.set(values);
370
- }
371
-
372
- function getTimeValue(flag: PanelFlags): Dayjs | null | undefined {
373
- const _value = value.value;
374
- if (!_value.length) return null;
375
-
376
- const {range, min} = instance.get();
377
- const lastValue = last(_value);
378
- return range ? (lastValue as StateValueRange)[flag] : lastValue as Dayjs;
379
- }
380
-
381
- function getDayjsValue() {
382
- return dayjsValue;
383
- }
384
-
385
- return {
386
- value,
387
- format,
388
- onConfirm,
389
- onChangeTime,
390
- getTimeValue,
391
- setValue,
392
- convertToDayjs,
393
- getDayjsValue,
394
- setMoment,
395
- };
396
- }
@@ -12,15 +12,17 @@ import {useYears} from './useYears';
12
12
  import {useMonths} from './useMonths';
13
13
  import {useWeeks} from './useWeeks';
14
14
  import {useQuarters} from './useQuarters';
15
- import {StateValue} from './basepicker';
15
+ import type {StateValue} from './useValueBase';
16
16
  import {useStatus} from './useStatus';
17
17
  import {PanelFlags} from './usePanel';
18
18
  import { useConfigContext } from '../config';
19
+ import { Position } from './useHighlight';
19
20
 
20
21
  export interface DatepickerCalendarProps {
21
22
  value: StateValue
22
23
  type?: 'date' | 'year' | 'month' | 'week' | 'quarter'
23
24
  flag: PanelFlags
25
+ highlightPosition: Position
24
26
  }
25
27
 
26
28
  export interface DatepickerCalendarEvents {
@@ -105,8 +105,11 @@ const {
105
105
  </div>
106
106
  <div v-if={isWeek} class={`${k}-weeks`} ev-mouseleave={resetFocusDate}>
107
107
  <div v-for={this.weeks.getWeeks(now)} class="week-row">
108
- <div class={`${k}-week-number`} ev-click={e => {onClickDay($value.days[0].value)}}
109
- ev-mouseenter={() => focusDate.set($value.days[0].value)}>{$value.week}</div>
108
+ <div
109
+ class={`${k}-week-number`}
110
+ ev-click={e => {onClickDay($value.days[0].value)}}
111
+ ev-mouseenter={() => focusDate.set($value.days[0].value)}
112
+ >{$value.week}</div>
110
113
  {getItems($value.days, onClickDay)}
111
114
  </div>
112
115
  </div>
@@ -1,4 +1,4 @@
1
- import dayjs, {Dayjs, OpUnitType as DayjsOpUnitType, QUnitType as DayjsQUnitType} from 'dayjs';
1
+ import dayjs, {Dayjs, OpUnitType, QUnitType} from 'dayjs';
2
2
  import weekOfYear from 'dayjs/plugin/weekOfYear'
3
3
  import quarterOfYear from 'dayjs/plugin/quarterOfYear';
4
4
  import customParseFormat from 'dayjs/plugin/customParseFormat';
@@ -9,19 +9,5 @@ dayjs.extend(weekOfYear);
9
9
  dayjs.extend(quarterOfYear);
10
10
  dayjs.extend(advancedFormat);
11
11
 
12
- // 重新声明类型以避免私有名称错误
13
- export type OpUnitType = DayjsOpUnitType;
14
- export type QUnitType = DayjsQUnitType;
15
-
16
- declare module 'dayjs' {
17
- interface Dayjs {
18
- isSame(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
19
- isBefore(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
20
- isAfter(date?: dayjs.ConfigType, unit?: DayjsOpUnitType | DayjsQUnitType): boolean;
21
- add(value: number, unit?: DayjsOpUnitType | DayjsQUnitType): dayjs.Dayjs;
22
- subtract(value: number, unit?: DayjsOpUnitType | DayjsQUnitType): dayjs.Dayjs;
23
- }
24
- }
25
-
26
12
  export default dayjs;
27
- export type {Dayjs};
13
+ export type {Dayjs, OpUnitType, QUnitType};
@@ -24,6 +24,9 @@ import {Datepicker} from 'kpc';
24
24
  <Datepicker multiple range v-model="dateRange" />
25
25
  You selected: {JSON.stringify(this.get('dateRange'))}
26
26
  <br /><br />
27
+ <Datepicker multiple range type="datetime" v-model="datetimeRange" />
28
+ You selected: {JSON.stringify(this.get('datetimeRange'))}
29
+ <br /><br />
27
30
  </div>
28
31
  ```
29
32
 
@@ -34,6 +37,7 @@ interface Props {
34
37
  year?: string[]
35
38
  month?: string[]
36
39
  dateRange?: [string, string][]
40
+ datetimeRange?: [string, string][]
37
41
  }
38
42
 
39
43
  export default class extends Component<Props> {
@@ -45,6 +49,7 @@ export default class extends Component<Props> {
45
49
  year: [],
46
50
  month: [],
47
51
  dateRange: [],
52
+ datetimeRange: [],
48
53
  } as Props;
49
54
  }
50
55
  }
@@ -1,9 +1,9 @@
1
1
  ---
2
- title: 选择年、月、周、季度
2
+ title: 选择年、月
3
3
  order: 5.1
4
4
  ---
5
5
 
6
- 将`type`属性指定为`year`或`month``或`week``或`quarter`可以只选择“年”或“月””或“周””或“季度”
6
+ 将`type`属性指定为`year`或`month`可以只选择“年”或“月”
7
7
 
8
8
  ```vdt
9
9
  import {Datepicker} from 'kpc';
@@ -11,8 +11,6 @@ import {Datepicker} from 'kpc';
11
11
  <div>
12
12
  <Datepicker type="year" v-model="year" />
13
13
  <Datepicker type="month" v-model="month" clearable />
14
- <Datepicker type="week" v-model="week" clearable />
15
- <Datepicker type="quarter" v-model="quarter" clearable />
16
14
  </div>
17
15
  ```
18
16
 
@@ -25,8 +23,6 @@ import {Datepicker} from 'kpc';
25
23
  interface Props {
26
24
  year?: string | null
27
25
  month?: string | null
28
- week?: string | null
29
- quarter?: string | null
30
26
  }
31
27
 
32
28
  export default class extends Component<Props> {
@@ -35,8 +31,6 @@ export default class extends Component<Props> {
35
31
  return {
36
32
  year: null,
37
33
  month: null,
38
- week: null,
39
- quarter: null,
40
34
  } as Props;
41
35
  }
42
36
  }
@@ -1,7 +1,7 @@
1
1
  import dayjs, {Dayjs, OpUnitType, QUnitType} from 'dayjs';
2
- import {strPad, range} from '../utils';
2
+ import {strPad, range, last} from '../utils';
3
3
  import {_$} from '../../i18n';
4
- import {StateValueItem} from './basepicker';
4
+ import {StateValueItem} from './useValueBase';
5
5
 
6
6
  export function getNowDate(isEnd?: boolean) {
7
7
  // only date without time
@@ -31,7 +31,7 @@ export function isEqual(
31
31
  type: OpUnitType | QUnitType = 'date'
32
32
  ) {
33
33
  if (a && b) {
34
- return a.isSame(b, type);
34
+ return a.isSame(b, type as any);
35
35
  }
36
36
  return false;
37
37
  }
@@ -42,7 +42,7 @@ export function isLT(
42
42
  type: OpUnitType | QUnitType = 'date'
43
43
  ) {
44
44
  if (a && b) {
45
- return a.isBefore(b, type);
45
+ return a.isBefore(b, type as any);
46
46
  }
47
47
 
48
48
  return false;
@@ -82,6 +82,4 @@ export function findValueIndex(values: StateValueItem[], value: StateValueItem,
82
82
  });
83
83
  }
84
84
 
85
- export function last<T>(arr: T[]): T | undefined {
86
- return arr[arr.length - 1];
87
- }
85
+ export { last }
@@ -28,14 +28,13 @@ sidebar: doc
28
28
  | max | 最大可选日期 | `Value` | `undefind` |
29
29
  | min | 最小可选日期 | `Value` | `undefind` |
30
30
  | disabledDate | 该属性值是一个函数,用于定义那些日期被禁止选择,函数参数为日期字符串,返回`true`则表示禁用该日期 | `(v: Dayjs) => boolean` | `undefined` |
31
- | type | 组件类型:`"date"` 只选择日期;`"datetime"` 选择日期和时间;`"year"` 选择年份;`"month"` 选择月份 `"quarter"` 选择季度;`"week` 选择周;| &#124; `"datetime"` &#124; `"year"` &#124; `"month"` &#124; `"quarter"` &#124; `"week"` | `"date"` |
31
+ | type | 组件类型:`"date"` 只选择日期;`"datetime"` 选择日期和时间;`"year"` 选择年份;`"month"` 选择月份 | &#124; `"datetime"` &#124; `"year"` &#124; `"month"` | `"date"` |
32
32
  | shortcuts | 指定快捷方式 | `Shortcut[]` | `undefined` |
33
33
  | show | 是否展示菜单项 | `boolean` | `false` |
34
34
  | position | 菜单弹出的位置,默认与触发器左侧对齐向下偏移`8px`的地方 | `Position` &#124; `"left"` &#124; `"bottom"` &#124; `"right"` &#124; `"top"` | `{my: 'left top+8', 'left bottom'}` |
35
35
  | flat | 是否展示扁平样式 | `boolean` | `false` |
36
36
  | draggable | 多选值是否支持拖动排序 | `boolean` | `false` |
37
37
  | nowrap | 日期多选时, 是否换行显示 | `boolean` | `false` |
38
- | isMerge | 日期范围多选时,在nowrap状态下是否交叉自动合并 | `boolean` | `false` |
39
38
  ```ts
40
39
  import {Dayjs} from 'dayjs';
41
40
  import {VNode} from 'intact';