antd-mobile 5.6.1 → 5.7.2

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 (139) hide show
  1. package/2x/cjs/components/calendar/calendar.d.ts +4 -3
  2. package/2x/cjs/components/calendar/calendar.js +67 -56
  3. package/2x/cjs/components/calendar/convert.d.ts +2 -0
  4. package/2x/cjs/components/calendar/convert.js +22 -0
  5. package/2x/cjs/components/collapse/collapse.js +7 -0
  6. package/2x/cjs/components/dialog/confirm.js +9 -1
  7. package/2x/cjs/components/form/form-item.js +6 -3
  8. package/2x/cjs/components/modal/confirm.js +9 -1
  9. package/2x/cjs/components/passcode-input/passcode-input.js +1 -1
  10. package/2x/cjs/components/picker/picker.js +6 -9
  11. package/2x/cjs/components/picker-view/columns-extend.d.ts +3 -0
  12. package/2x/cjs/components/picker-view/columns-extend.js +45 -0
  13. package/2x/cjs/components/picker-view/picker-view.d.ts +1 -0
  14. package/2x/cjs/components/picker-view/picker-view.js +14 -16
  15. package/2x/cjs/components/pull-to-refresh/pull-to-refresh.js +11 -1
  16. package/2x/cjs/components/result/result.d.ts +2 -2
  17. package/2x/cjs/components/virtual-input/virtual-input.js +25 -14
  18. package/2x/cjs/locales/base.d.ts +6 -0
  19. package/2x/cjs/locales/base.js +7 -1
  20. package/2x/cjs/locales/en-US.d.ts +6 -0
  21. package/2x/cjs/locales/fa-IR.d.ts +101 -0
  22. package/2x/cjs/locales/fa-IR.js +108 -0
  23. package/2x/cjs/locales/zh-CN.d.ts +6 -0
  24. package/2x/cjs/locales/zh-CN.js +7 -1
  25. package/2x/cjs/locales/zh-HK.d.ts +101 -0
  26. package/2x/cjs/locales/zh-HK.js +58 -0
  27. package/2x/cjs/locales/zh-TW.d.ts +101 -0
  28. package/2x/cjs/locales/zh-TW.js +58 -0
  29. package/2x/cjs/utils/with-cache.d.ts +1 -0
  30. package/2x/cjs/utils/with-cache.js +17 -0
  31. package/2x/es/components/calendar/calendar.d.ts +4 -3
  32. package/2x/es/components/calendar/calendar.js +67 -58
  33. package/2x/es/components/calendar/convert.d.ts +2 -0
  34. package/2x/es/components/calendar/convert.js +15 -0
  35. package/2x/es/components/collapse/collapse.js +7 -0
  36. package/2x/es/components/dialog/confirm.js +8 -1
  37. package/2x/es/components/form/form-item.js +6 -3
  38. package/2x/es/components/modal/confirm.js +8 -1
  39. package/2x/es/components/passcode-input/passcode-input.js +1 -1
  40. package/2x/es/components/picker/picker.js +6 -8
  41. package/2x/es/components/picker-view/columns-extend.d.ts +3 -0
  42. package/2x/es/components/picker-view/columns-extend.js +34 -0
  43. package/2x/es/components/picker-view/picker-view.d.ts +1 -0
  44. package/2x/es/components/picker-view/picker-view.js +14 -15
  45. package/2x/es/components/pull-to-refresh/pull-to-refresh.js +10 -1
  46. package/2x/es/components/result/result.d.ts +2 -2
  47. package/2x/es/components/virtual-input/virtual-input.js +23 -14
  48. package/2x/es/locales/base.d.ts +6 -0
  49. package/2x/es/locales/base.js +7 -1
  50. package/2x/es/locales/en-US.d.ts +6 -0
  51. package/2x/es/locales/fa-IR.d.ts +101 -0
  52. package/2x/es/locales/fa-IR.js +98 -0
  53. package/2x/es/locales/zh-CN.d.ts +6 -0
  54. package/2x/es/locales/zh-CN.js +7 -1
  55. package/2x/es/locales/zh-HK.d.ts +101 -0
  56. package/2x/es/locales/zh-HK.js +48 -0
  57. package/2x/es/locales/zh-TW.d.ts +101 -0
  58. package/2x/es/locales/zh-TW.js +48 -0
  59. package/2x/es/utils/with-cache.d.ts +1 -0
  60. package/2x/es/utils/with-cache.js +10 -0
  61. package/2x/package.json +1 -1
  62. package/cjs/components/calendar/calendar.d.ts +4 -3
  63. package/cjs/components/calendar/calendar.js +67 -56
  64. package/cjs/components/calendar/convert.d.ts +2 -0
  65. package/cjs/components/calendar/convert.js +22 -0
  66. package/cjs/components/collapse/collapse.js +7 -0
  67. package/cjs/components/dialog/confirm.js +9 -1
  68. package/cjs/components/form/form-item.js +6 -3
  69. package/cjs/components/modal/confirm.js +9 -1
  70. package/cjs/components/passcode-input/passcode-input.js +1 -1
  71. package/cjs/components/picker/picker.js +6 -9
  72. package/cjs/components/picker-view/columns-extend.d.ts +3 -0
  73. package/cjs/components/picker-view/columns-extend.js +45 -0
  74. package/cjs/components/picker-view/picker-view.d.ts +1 -0
  75. package/cjs/components/picker-view/picker-view.js +14 -16
  76. package/cjs/components/pull-to-refresh/pull-to-refresh.js +11 -1
  77. package/cjs/components/result/result.d.ts +2 -2
  78. package/cjs/components/virtual-input/virtual-input.js +25 -14
  79. package/cjs/locales/base.d.ts +6 -0
  80. package/cjs/locales/base.js +7 -1
  81. package/cjs/locales/en-US.d.ts +6 -0
  82. package/cjs/locales/fa-IR.d.ts +101 -0
  83. package/cjs/locales/fa-IR.js +108 -0
  84. package/cjs/locales/zh-CN.d.ts +6 -0
  85. package/cjs/locales/zh-CN.js +7 -1
  86. package/cjs/locales/zh-HK.d.ts +101 -0
  87. package/cjs/locales/zh-HK.js +58 -0
  88. package/cjs/locales/zh-TW.d.ts +101 -0
  89. package/cjs/locales/zh-TW.js +58 -0
  90. package/cjs/utils/with-cache.d.ts +1 -0
  91. package/cjs/utils/with-cache.js +17 -0
  92. package/es/components/calendar/calendar.d.ts +4 -3
  93. package/es/components/calendar/calendar.js +67 -58
  94. package/es/components/calendar/convert.d.ts +2 -0
  95. package/es/components/calendar/convert.js +15 -0
  96. package/es/components/collapse/collapse.js +7 -0
  97. package/es/components/dialog/confirm.js +8 -1
  98. package/es/components/form/form-item.js +6 -3
  99. package/es/components/modal/confirm.js +8 -1
  100. package/es/components/passcode-input/passcode-input.js +1 -1
  101. package/es/components/picker/picker.js +6 -8
  102. package/es/components/picker-view/columns-extend.d.ts +3 -0
  103. package/es/components/picker-view/columns-extend.js +34 -0
  104. package/es/components/picker-view/picker-view.d.ts +1 -0
  105. package/es/components/picker-view/picker-view.js +14 -15
  106. package/es/components/pull-to-refresh/pull-to-refresh.js +10 -1
  107. package/es/components/result/result.d.ts +2 -2
  108. package/es/components/virtual-input/virtual-input.js +23 -14
  109. package/es/locales/base.d.ts +6 -0
  110. package/es/locales/base.js +7 -1
  111. package/es/locales/en-US.d.ts +6 -0
  112. package/es/locales/fa-IR.d.ts +101 -0
  113. package/es/locales/fa-IR.js +98 -0
  114. package/es/locales/zh-CN.d.ts +6 -0
  115. package/es/locales/zh-CN.js +7 -1
  116. package/es/locales/zh-HK.d.ts +101 -0
  117. package/es/locales/zh-HK.js +48 -0
  118. package/es/locales/zh-TW.d.ts +101 -0
  119. package/es/locales/zh-TW.js +48 -0
  120. package/es/utils/with-cache.d.ts +1 -0
  121. package/es/utils/with-cache.js +10 -0
  122. package/package.json +1 -1
  123. package/umd/antd-mobile.js +1 -1
  124. package/2x/cjs/components/picker-view/use-columns.d.ts +0 -2
  125. package/2x/cjs/components/picker-view/use-columns.js +0 -18
  126. package/2x/cjs/components/picker-view/use-picker-value-extend.d.ts +0 -2
  127. package/2x/cjs/components/picker-view/use-picker-value-extend.js +0 -37
  128. package/2x/es/components/picker-view/use-columns.d.ts +0 -2
  129. package/2x/es/components/picker-view/use-columns.js +0 -10
  130. package/2x/es/components/picker-view/use-picker-value-extend.d.ts +0 -2
  131. package/2x/es/components/picker-view/use-picker-value-extend.js +0 -26
  132. package/cjs/components/picker-view/use-columns.d.ts +0 -2
  133. package/cjs/components/picker-view/use-columns.js +0 -18
  134. package/cjs/components/picker-view/use-picker-value-extend.d.ts +0 -2
  135. package/cjs/components/picker-view/use-picker-value-extend.js +0 -37
  136. package/es/components/picker-view/use-columns.d.ts +0 -2
  137. package/es/components/picker-view/use-columns.js +0 -10
  138. package/es/components/picker-view/use-picker-value-extend.d.ts +0 -2
  139. package/es/components/picker-view/use-picker-value-extend.js +0 -26
@@ -0,0 +1,98 @@
1
+ import { mergeLocale } from '../utils/merge-locale';
2
+ import { base } from './base';
3
+ const typeTemplate = '${label} یک ${type} معتبر نیست';
4
+ const faIR = mergeLocale(base, {
5
+ common: {
6
+ confirm: 'تایید',
7
+ cancel: 'لغو'
8
+ },
9
+ Calendar: {
10
+ markItems: ['شنبه', 'یک‌شنبه', 'دو‌شنبه', 'سه‌شنبه', 'چهار‌شنبه', 'پنج‌نشبه', 'جمعه'],
11
+ renderYearAndMonth: (year, month) => `${year}/${month}`
12
+ },
13
+ Cascader: {
14
+ placeholder: 'انتخاب کنید'
15
+ },
16
+ Dialog: {
17
+ ok: 'باشه'
18
+ },
19
+ ErrorBlock: {
20
+ default: {
21
+ title: 'اوه، مشکلی پیش آمد',
22
+ description: 'لطفاً یک دقیقه صبر کنید و دوباره امتحان کنید'
23
+ },
24
+ busy: {
25
+ title: 'اوه، بارگیری نمی شود',
26
+ description: 'سعی کنید صفحه را به روز کنید'
27
+ },
28
+ disconnected: {
29
+ title: 'شبکه مشغول است',
30
+ description: 'سعی کنید صفحه را به روز کنید'
31
+ },
32
+ empty: {
33
+ title: 'هوم، نتونستم پیداش کنم...',
34
+ description: 'آیا می خواهید یک جستجوی جدید را امتحان کنید؟'
35
+ }
36
+ },
37
+ Form: {
38
+ required: 'اجباری',
39
+ optional: 'اختیاری',
40
+ defaultValidateMessages: {
41
+ default: 'خطای اعتبارسنجی فیلد برای ${label}',
42
+ required: 'لطفا وارد کنید ${label}',
43
+ enum: '${label} باید یکی از [${enum}]',
44
+ whitespace: '${label} نمی تواند یک کاراکتر خالی باشد',
45
+ date: {
46
+ format: '${label} قالب تاریخ نامعتبر است',
47
+ parse: '${label} نمی توان به تاریخ تبدیل کرد',
48
+ invalid: '${label} تاریخ نامعتبر است'
49
+ },
50
+ types: {
51
+ string: typeTemplate,
52
+ method: typeTemplate,
53
+ array: typeTemplate,
54
+ object: typeTemplate,
55
+ number: typeTemplate,
56
+ date: typeTemplate,
57
+ boolean: typeTemplate,
58
+ integer: typeTemplate,
59
+ float: typeTemplate,
60
+ regexp: typeTemplate,
61
+ email: typeTemplate,
62
+ url: typeTemplate,
63
+ hex: typeTemplate
64
+ },
65
+ string: {
66
+ len: 'تعداد کاراکترهای ${label} باید ${len} کاراکتر باشد',
67
+ min: 'حداقل کاراکترهای ${label} باید ${min} کاراکتر باشد',
68
+ max: 'حداکثر کاراکترهای ${label} باید ${max} کاراکتر باشد',
69
+ range: 'تعداد کاراکترهای ${label} باید بین ${min}-${max} کاراکتر باشد'
70
+ },
71
+ number: {
72
+ len: 'تعداد اعداد ${label} باید برابر با ${len} باشد',
73
+ min: 'تعداد اعداد ${label} باید حداقل ${min} باشد',
74
+ max: 'تعداد اعداد ${label} باید حداکثر ${max} باشد',
75
+ range: 'تعداد اعداد ${label} باید بین ${min}-${max} باشد'
76
+ },
77
+ array: {
78
+ len: 'طول آیتم‌های ${label} باید برابر با ${len} باشد',
79
+ min: 'آیتم‌های ${label} باید حداقل ${min} باشد',
80
+ max: 'آیتم‌های ${label} باید حداکثر ${max} باشد',
81
+ range: 'آیتم‌های ${label} باید بین ${min}-${max} باشد'
82
+ },
83
+ pattern: {
84
+ mismatch: '${label} با الگوی ${pattern} مطابقت ندارد'
85
+ }
86
+ }
87
+ },
88
+ ImageUploader: {
89
+ uploading: 'در حال آپلود...'
90
+ },
91
+ Mask: {
92
+ name: 'ماسک'
93
+ },
94
+ Modal: {
95
+ ok: 'باشه'
96
+ }
97
+ });
98
+ export default faIR;
@@ -2,6 +2,7 @@ declare const zhCN: {
2
2
  common: {
3
3
  confirm: string;
4
4
  cancel: string;
5
+ loading: string;
5
6
  };
6
7
  Calendar: {
7
8
  markItems: string[];
@@ -91,5 +92,10 @@ declare const zhCN: {
91
92
  Modal: {
92
93
  ok: string;
93
94
  };
95
+ PullToRefresh: {
96
+ pulling: string;
97
+ canRelease: string;
98
+ complete: string;
99
+ };
94
100
  };
95
101
  export default zhCN;
@@ -4,7 +4,8 @@ const typeTemplate = '${label}不是一个有效的${type}';
4
4
  const zhCN = mergeLocale(base, {
5
5
  common: {
6
6
  confirm: '确定',
7
- cancel: '取消'
7
+ cancel: '取消',
8
+ loading: '加载中……'
8
9
  },
9
10
  Calendar: {
10
11
  markItems: ['一', '二', '三', '四', '五', '六', '日'],
@@ -93,6 +94,11 @@ const zhCN = mergeLocale(base, {
93
94
  },
94
95
  Modal: {
95
96
  ok: '我知道了'
97
+ },
98
+ PullToRefresh: {
99
+ pulling: '下拉刷新',
100
+ canRelease: '释放立即刷新',
101
+ complete: '刷新成功'
96
102
  }
97
103
  });
98
104
  export default zhCN;
@@ -0,0 +1,101 @@
1
+ declare const zhHK: {
2
+ common: {
3
+ confirm: string;
4
+ cancel: string;
5
+ loading: string;
6
+ };
7
+ Calendar: {
8
+ markItems: string[];
9
+ renderYearAndMonth: (year: number, month: number) => string;
10
+ };
11
+ Cascader: {
12
+ placeholder: string;
13
+ };
14
+ Dialog: {
15
+ ok: string;
16
+ };
17
+ ErrorBlock: {
18
+ default: {
19
+ title: string;
20
+ description: string;
21
+ };
22
+ busy: {
23
+ title: string;
24
+ description: string;
25
+ };
26
+ disconnected: {
27
+ title: string;
28
+ description: string;
29
+ };
30
+ empty: {
31
+ title: string;
32
+ description: string;
33
+ };
34
+ };
35
+ Form: {
36
+ required: string;
37
+ optional: string;
38
+ defaultValidateMessages: {
39
+ default: string;
40
+ required: string;
41
+ enum: string;
42
+ whitespace: string;
43
+ date: {
44
+ format: string;
45
+ parse: string;
46
+ invalid: string;
47
+ };
48
+ types: {
49
+ string: string;
50
+ method: string;
51
+ array: string;
52
+ object: string;
53
+ number: string;
54
+ date: string;
55
+ boolean: string;
56
+ integer: string;
57
+ float: string;
58
+ regexp: string;
59
+ email: string;
60
+ url: string;
61
+ hex: string;
62
+ };
63
+ string: {
64
+ len: string;
65
+ min: string;
66
+ max: string;
67
+ range: string;
68
+ };
69
+ number: {
70
+ len: string;
71
+ min: string;
72
+ max: string;
73
+ range: string;
74
+ };
75
+ array: {
76
+ len: string;
77
+ min: string;
78
+ max: string;
79
+ range: string;
80
+ };
81
+ pattern: {
82
+ mismatch: string;
83
+ };
84
+ };
85
+ };
86
+ ImageUploader: {
87
+ uploading: string;
88
+ };
89
+ Mask: {
90
+ name: string;
91
+ };
92
+ Modal: {
93
+ ok: string;
94
+ };
95
+ PullToRefresh: {
96
+ pulling: string;
97
+ canRelease: string;
98
+ complete: string;
99
+ };
100
+ };
101
+ export default zhHK;
@@ -0,0 +1,48 @@
1
+ import { mergeLocale } from '../utils/merge-locale';
2
+ import { base } from './base';
3
+ const zhHK = mergeLocale(base, {
4
+ common: {
5
+ confirm: '確定',
6
+ cancel: '取消',
7
+ loading: '加載中……'
8
+ },
9
+ Cascader: {
10
+ placeholder: '請選擇'
11
+ },
12
+ Dialog: {
13
+ ok: '我知道了'
14
+ },
15
+ ErrorBlock: {
16
+ default: {
17
+ title: '頁面遇到一些小問題',
18
+ description: '待會來試試'
19
+ },
20
+ busy: {
21
+ title: '前方擁堵',
22
+ description: '刷新試試'
23
+ },
24
+ disconnected: {
25
+ title: '網絡有點忙',
26
+ description: '動動手指幫忙修復'
27
+ },
28
+ empty: {
29
+ title: '沒有找到您需要的東西',
30
+ description: '找找其他的吧'
31
+ }
32
+ },
33
+ ImageUploader: {
34
+ uploading: '上傳中...'
35
+ },
36
+ Mask: {
37
+ name: '遮罩層'
38
+ },
39
+ Modal: {
40
+ ok: '我知道了'
41
+ },
42
+ PullToRefresh: {
43
+ pulling: '下拉刷新',
44
+ canRelease: '釋放立即刷新',
45
+ complete: '刷新成功'
46
+ }
47
+ });
48
+ export default zhHK;
@@ -0,0 +1,101 @@
1
+ declare const zhTW: {
2
+ common: {
3
+ confirm: string;
4
+ cancel: string;
5
+ loading: string;
6
+ };
7
+ Calendar: {
8
+ markItems: string[];
9
+ renderYearAndMonth: (year: number, month: number) => string;
10
+ };
11
+ Cascader: {
12
+ placeholder: string;
13
+ };
14
+ Dialog: {
15
+ ok: string;
16
+ };
17
+ ErrorBlock: {
18
+ default: {
19
+ title: string;
20
+ description: string;
21
+ };
22
+ busy: {
23
+ title: string;
24
+ description: string;
25
+ };
26
+ disconnected: {
27
+ title: string;
28
+ description: string;
29
+ };
30
+ empty: {
31
+ title: string;
32
+ description: string;
33
+ };
34
+ };
35
+ Form: {
36
+ required: string;
37
+ optional: string;
38
+ defaultValidateMessages: {
39
+ default: string;
40
+ required: string;
41
+ enum: string;
42
+ whitespace: string;
43
+ date: {
44
+ format: string;
45
+ parse: string;
46
+ invalid: string;
47
+ };
48
+ types: {
49
+ string: string;
50
+ method: string;
51
+ array: string;
52
+ object: string;
53
+ number: string;
54
+ date: string;
55
+ boolean: string;
56
+ integer: string;
57
+ float: string;
58
+ regexp: string;
59
+ email: string;
60
+ url: string;
61
+ hex: string;
62
+ };
63
+ string: {
64
+ len: string;
65
+ min: string;
66
+ max: string;
67
+ range: string;
68
+ };
69
+ number: {
70
+ len: string;
71
+ min: string;
72
+ max: string;
73
+ range: string;
74
+ };
75
+ array: {
76
+ len: string;
77
+ min: string;
78
+ max: string;
79
+ range: string;
80
+ };
81
+ pattern: {
82
+ mismatch: string;
83
+ };
84
+ };
85
+ };
86
+ ImageUploader: {
87
+ uploading: string;
88
+ };
89
+ Mask: {
90
+ name: string;
91
+ };
92
+ Modal: {
93
+ ok: string;
94
+ };
95
+ PullToRefresh: {
96
+ pulling: string;
97
+ canRelease: string;
98
+ complete: string;
99
+ };
100
+ };
101
+ export default zhTW;
@@ -0,0 +1,48 @@
1
+ import { mergeLocale } from '../utils/merge-locale';
2
+ import { base } from './base';
3
+ const zhTW = mergeLocale(base, {
4
+ common: {
5
+ confirm: '確定',
6
+ cancel: '取消',
7
+ loading: '加載中……'
8
+ },
9
+ Cascader: {
10
+ placeholder: '請選擇'
11
+ },
12
+ Dialog: {
13
+ ok: '我知道了'
14
+ },
15
+ ErrorBlock: {
16
+ default: {
17
+ title: '頁面遇到一些小問題',
18
+ description: '待會來試試'
19
+ },
20
+ busy: {
21
+ title: '前方擁堵',
22
+ description: '刷新試試'
23
+ },
24
+ disconnected: {
25
+ title: '網路有點忙',
26
+ description: '動動手指幫忙修復'
27
+ },
28
+ empty: {
29
+ title: '沒有找到您需要的東西',
30
+ description: '找找其他的吧'
31
+ }
32
+ },
33
+ ImageUploader: {
34
+ uploading: '上傳中...'
35
+ },
36
+ Mask: {
37
+ name: '遮罩層'
38
+ },
39
+ Modal: {
40
+ ok: '我知道了'
41
+ },
42
+ PullToRefresh: {
43
+ pulling: '下拉刷新',
44
+ canRelease: '釋放立即刷新',
45
+ complete: '刷新成功'
46
+ }
47
+ });
48
+ export default zhTW;
@@ -0,0 +1 @@
1
+ export declare function withCache<T>(generate: () => T): () => T;
@@ -0,0 +1,10 @@
1
+ export function withCache(generate) {
2
+ let cache = null;
3
+ return () => {
4
+ if (cache === null) {
5
+ cache = generate();
6
+ }
7
+
8
+ return cache;
9
+ };
10
+ }
package/2x/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-mobile",
3
- "version": "5.6.1",
3
+ "version": "5.7.2",
4
4
  "dependencies": {
5
5
  "@floating-ui/dom": "^0.3.1",
6
6
  "@react-spring/web": "^9.4.3",
@@ -9,9 +9,10 @@ export declare type CalenderRef = {
9
9
  jumpToToday: () => void;
10
10
  };
11
11
  export declare type CalendarProps = {
12
+ onPageChange?: (year: number, month: number) => void;
12
13
  weekStartsOn?: 'Monday' | 'Sunday';
13
14
  renderLabel?: (date: Date) => string | null | undefined;
14
- onPageChange?: (year: number, month: number) => void;
15
+ allowClear?: boolean;
15
16
  } & ({
16
17
  selectionMode?: undefined;
17
18
  value?: undefined;
@@ -21,12 +22,12 @@ export declare type CalendarProps = {
21
22
  selectionMode: 'single';
22
23
  value?: Date | null;
23
24
  defaultValue?: Date | null;
24
- onChange?: (val: Date) => void;
25
+ onChange?: (val: Date | null) => void;
25
26
  } | {
26
27
  selectionMode: 'range';
27
28
  value?: [Date, Date] | null;
28
29
  defaultValue?: [Date, Date] | null;
29
- onChange?: (val: [Date, Date]) => void;
30
+ onChange?: (val: [Date, Date] | null) => void;
30
31
  }) & NativeProps;
31
32
  export declare const Calendar: React.ForwardRefExoticComponent<CalendarProps & React.RefAttributes<CalenderRef>>;
32
33
  export {};
@@ -25,6 +25,10 @@ var _isoWeek = _interopRequireDefault(require("dayjs/plugin/isoWeek"));
25
25
 
26
26
  var _ahooks = require("ahooks");
27
27
 
28
+ var _usePropsValue = require("../../utils/use-props-value");
29
+
30
+ var _convert = require("./convert");
31
+
28
32
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
33
 
30
34
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -35,7 +39,9 @@ _dayjs.default.extend(_isoWeek.default);
35
39
 
36
40
  const classPrefix = 'adm-calendar';
37
41
  const defaultProps = {
38
- weekStartsOn: 'Sunday'
42
+ weekStartsOn: 'Sunday',
43
+ defaultValue: null,
44
+ allowClear: true
39
45
  };
40
46
  const Calendar = (0, _react.forwardRef)((p, ref) => {
41
47
  const today = (0, _dayjs.default)();
@@ -50,29 +56,21 @@ const Calendar = (0, _react.forwardRef)((p, ref) => {
50
56
  if (item) markItems.unshift(item);
51
57
  }
52
58
 
53
- const dateRange = (0, _react.useMemo)(() => {
54
- var _a, _b, _c, _d;
59
+ const [dateRange, setDateRange] = (0, _usePropsValue.usePropsValue)({
60
+ value: props.value === undefined ? undefined : (0, _convert.convertValueToRange)(props.selectionMode, props.value),
61
+ defaultValue: (0, _convert.convertValueToRange)(props.selectionMode, props.defaultValue),
62
+ onChange: v => {
63
+ var _a, _b;
55
64
 
56
- if (props.selectionMode === 'single') {
57
- const value = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.defaultValue) !== null && _b !== void 0 ? _b : null;
58
- return [value, value];
59
- } else if (props.selectionMode === 'range') {
60
- return (_d = (_c = props.value) !== null && _c !== void 0 ? _c : props.defaultValue) !== null && _d !== void 0 ? _d : [null, null];
61
- } else {
62
- return [null, null];
65
+ if (props.selectionMode === 'single') {
66
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v ? v[0] : null);
67
+ } else if (props.selectionMode === 'range') {
68
+ (_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, v);
69
+ }
63
70
  }
64
- }, [props.selectionMode, props.value, props.defaultValue]);
65
- const [begin, setBegin] = (0, _react.useState)(null);
66
- const [end, setEnd] = (0, _react.useState)(null);
67
- (0, _ahooks.useIsomorphicLayoutEffect)(() => {
68
- setBegin(dateRange[0] ? (0, _dayjs.default)(dateRange[0]) : null);
69
- setEnd(dateRange[1] ? (0, _dayjs.default)(dateRange[1]) : null);
70
- }, [dateRange[0], dateRange[1]]);
71
- const [current, setCurrent] = (0, _react.useState)(() => {
72
- var _a;
73
-
74
- return (0, _dayjs.default)((_a = dateRange[0]) !== null && _a !== void 0 ? _a : today).date(1);
75
71
  });
72
+ const [intermediate, setIntermediate] = (0, _react.useState)(false);
73
+ const [current, setCurrent] = (0, _react.useState)(() => (0, _dayjs.default)(dateRange ? dateRange[0] : today).date(1));
76
74
  (0, _ahooks.useUpdateEffect)(() => {
77
75
  var _a;
78
76
 
@@ -136,14 +134,16 @@ const Calendar = (0, _react.forwardRef)((p, ref) => {
136
134
 
137
135
  while (cells.length < 6 * 7) {
138
136
  const d = iterator;
139
-
140
- const isSelect = (() => {
141
- if (!begin) return false;
142
- if (d.isSame(begin, 'day')) return true;
143
- if (!end) return false;
144
- if (d.isSame(end, 'day')) return true;
145
- return d.isAfter(begin, 'day') && d.isBefore(end, 'day');
146
- })();
137
+ let isSelect = false;
138
+ let isBegin = false;
139
+ let isEnd = false;
140
+
141
+ if (dateRange) {
142
+ const [begin, end] = dateRange;
143
+ isBegin = d.isSame(begin, 'day');
144
+ isEnd = d.isSame(end, 'day');
145
+ isSelect = isBegin || isEnd || d.isAfter(begin, 'day') && d.isBefore(end, 'day');
146
+ }
147
147
 
148
148
  const inThisMonth = d.month() === current.month();
149
149
  cells.push(_react.default.createElement("div", {
@@ -151,41 +151,52 @@ const Calendar = (0, _react.forwardRef)((p, ref) => {
151
151
  className: (0, _classnames.default)(`${classPrefix}-cell`, inThisMonth ? `${classPrefix}-cell-in` : `${classPrefix}-cell-out`, inThisMonth && {
152
152
  [`${classPrefix}-cell-today`]: d.isSame(today, 'day'),
153
153
  [`${classPrefix}-cell-selected`]: isSelect,
154
- [`${classPrefix}-cell-selected-begin`]: isSelect && d.isSame(begin, 'day'),
155
- [`${classPrefix}-cell-selected-end`]: isSelect && (!end || d.isSame(end, 'day'))
154
+ [`${classPrefix}-cell-selected-begin`]: isBegin,
155
+ [`${classPrefix}-cell-selected-end`]: isEnd
156
156
  }),
157
157
  onClick: () => {
158
- var _a, _b, _c;
159
-
160
158
  if (!props.selectionMode) return;
159
+ const date = d.toDate();
160
+
161
+ if (!inThisMonth) {
162
+ setCurrent(d.clone().date(1));
163
+ }
164
+
165
+ function shouldClear() {
166
+ if (!props.allowClear) return false;
167
+ if (!dateRange) return false;
168
+ const [begin, end] = dateRange;
169
+ return d.isSame(begin, 'date') && d.isSame(end, 'day');
170
+ }
161
171
 
162
172
  if (props.selectionMode === 'single') {
163
- setBegin(d);
164
- setEnd(d);
165
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, d.toDate());
173
+ if (props.allowClear && shouldClear()) {
174
+ setDateRange(null);
175
+ return;
176
+ }
177
+
178
+ setDateRange([date, date]);
166
179
  } else if (props.selectionMode === 'range') {
167
- if (begin !== null && end === null) {
168
- if (begin.isSame(d.toDate())) {
169
- setBegin(null);
170
- setEnd(null);
171
- } else {
172
- if (d.isBefore(begin)) {
173
- setEnd(begin);
174
- setBegin(d);
175
- (_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, [d.toDate(), begin.toDate()]);
176
- } else {
177
- setEnd(d);
178
- (_c = props.onChange) === null || _c === void 0 ? void 0 : _c.call(props, [begin.toDate(), d.toDate()]);
179
- }
180
- }
181
- } else {
182
- setBegin(d);
183
- setEnd(null);
180
+ if (!dateRange) {
181
+ setDateRange([date, date]);
182
+ setIntermediate(true);
183
+ return;
184
184
  }
185
- }
186
185
 
187
- if (!inThisMonth) {
188
- setCurrent(d.clone().date(1));
186
+ if (shouldClear()) {
187
+ setDateRange(null);
188
+ setIntermediate(false);
189
+ return;
190
+ }
191
+
192
+ if (intermediate) {
193
+ const another = dateRange[0];
194
+ setDateRange(another > date ? [date, another] : [another, date]);
195
+ setIntermediate(false);
196
+ } else {
197
+ setDateRange([date, date]);
198
+ setIntermediate(true);
199
+ }
189
200
  }
190
201
  }
191
202
  }, _react.default.createElement("div", {
@@ -0,0 +1,2 @@
1
+ export declare type DateRange = [Date, Date] | null;
2
+ export declare function convertValueToRange(selectionMode: 'single' | 'range' | undefined, value: Date | [Date, Date] | null): DateRange;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertValueToRange = convertValueToRange;
7
+
8
+ function convertValueToRange(selectionMode, value) {
9
+ if (selectionMode === undefined) {
10
+ return null;
11
+ }
12
+
13
+ if (value === null) {
14
+ return null;
15
+ }
16
+
17
+ if (Array.isArray(value)) {
18
+ return value;
19
+ }
20
+
21
+ return [value, value];
22
+ }