@king-design/intact 3.5.2 → 3.6.0

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