antd-mobile 5.6.1 → 5.7.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.
- package/2x/cjs/components/calendar/calendar.d.ts +4 -3
- package/2x/cjs/components/calendar/calendar.js +67 -56
- package/2x/cjs/components/calendar/convert.d.ts +2 -0
- package/2x/cjs/components/calendar/convert.js +22 -0
- package/2x/cjs/components/picker/picker.js +6 -9
- package/2x/cjs/components/picker-view/columns-extend.d.ts +3 -0
- package/2x/cjs/components/picker-view/columns-extend.js +45 -0
- package/2x/cjs/components/picker-view/picker-view.d.ts +1 -0
- package/2x/cjs/components/picker-view/picker-view.js +14 -16
- package/2x/cjs/utils/with-cache.d.ts +1 -0
- package/2x/cjs/utils/with-cache.js +17 -0
- package/2x/es/components/calendar/calendar.d.ts +4 -3
- package/2x/es/components/calendar/calendar.js +67 -58
- package/2x/es/components/calendar/convert.d.ts +2 -0
- package/2x/es/components/calendar/convert.js +15 -0
- package/2x/es/components/picker/picker.js +6 -8
- package/2x/es/components/picker-view/columns-extend.d.ts +3 -0
- package/2x/es/components/picker-view/columns-extend.js +34 -0
- package/2x/es/components/picker-view/picker-view.d.ts +1 -0
- package/2x/es/components/picker-view/picker-view.js +14 -15
- package/2x/es/utils/with-cache.d.ts +1 -0
- package/2x/es/utils/with-cache.js +10 -0
- package/2x/package.json +1 -1
- package/cjs/components/calendar/calendar.d.ts +4 -3
- package/cjs/components/calendar/calendar.js +67 -56
- package/cjs/components/calendar/convert.d.ts +2 -0
- package/cjs/components/calendar/convert.js +22 -0
- package/cjs/components/picker/picker.js +6 -9
- package/cjs/components/picker-view/columns-extend.d.ts +3 -0
- package/cjs/components/picker-view/columns-extend.js +45 -0
- package/cjs/components/picker-view/picker-view.d.ts +1 -0
- package/cjs/components/picker-view/picker-view.js +14 -16
- package/cjs/utils/with-cache.d.ts +1 -0
- package/cjs/utils/with-cache.js +17 -0
- package/es/components/calendar/calendar.d.ts +4 -3
- package/es/components/calendar/calendar.js +67 -58
- package/es/components/calendar/convert.d.ts +2 -0
- package/es/components/calendar/convert.js +15 -0
- package/es/components/picker/picker.js +6 -8
- package/es/components/picker-view/columns-extend.d.ts +3 -0
- package/es/components/picker-view/columns-extend.js +34 -0
- package/es/components/picker-view/picker-view.d.ts +1 -0
- package/es/components/picker-view/picker-view.js +14 -15
- package/es/utils/with-cache.d.ts +1 -0
- package/es/utils/with-cache.js +10 -0
- package/package.json +1 -1
- package/umd/antd-mobile.js +1 -1
- package/2x/cjs/components/picker-view/use-columns.d.ts +0 -2
- package/2x/cjs/components/picker-view/use-columns.js +0 -18
- package/2x/cjs/components/picker-view/use-picker-value-extend.d.ts +0 -2
- package/2x/cjs/components/picker-view/use-picker-value-extend.js +0 -37
- package/2x/es/components/picker-view/use-columns.d.ts +0 -2
- package/2x/es/components/picker-view/use-columns.js +0 -10
- package/2x/es/components/picker-view/use-picker-value-extend.d.ts +0 -2
- package/2x/es/components/picker-view/use-picker-value-extend.js +0 -26
- package/cjs/components/picker-view/use-columns.d.ts +0 -2
- package/cjs/components/picker-view/use-columns.js +0 -18
- package/cjs/components/picker-view/use-picker-value-extend.d.ts +0 -2
- package/cjs/components/picker-view/use-picker-value-extend.js +0 -37
- package/es/components/picker-view/use-columns.d.ts +0 -2
- package/es/components/picker-view/use-columns.js +0 -10
- package/es/components/picker-view/use-picker-value-extend.d.ts +0 -2
- package/es/components/picker-view/use-picker-value-extend.js +0 -26
|
@@ -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
|
-
|
|
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,
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
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`]:
|
|
155
|
-
[`${classPrefix}-cell-selected-end`]:
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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 (
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
188
|
-
|
|
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,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
|
+
}
|
|
@@ -17,12 +17,10 @@ var _usePropsValue = require("../../utils/use-props-value");
|
|
|
17
17
|
|
|
18
18
|
var _pickerView = _interopRequireDefault(require("../picker-view"));
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _columnsExtend = require("../picker-view/columns-extend");
|
|
21
21
|
|
|
22
22
|
var _configProvider = require("../config-provider");
|
|
23
23
|
|
|
24
|
-
var _usePickerValueExtend = require("../picker-view/use-picker-value-extend");
|
|
25
|
-
|
|
26
24
|
var _ahooks = require("ahooks");
|
|
27
25
|
|
|
28
26
|
var _safeArea = _interopRequireDefault(require("../safe-area"));
|
|
@@ -52,12 +50,11 @@ const Picker = (0, _react.memo)(p => {
|
|
|
52
50
|
onChange: val => {
|
|
53
51
|
var _a;
|
|
54
52
|
|
|
55
|
-
|
|
53
|
+
const extend = (0, _columnsExtend.generateColumnsExtend)(props.columns, val);
|
|
54
|
+
(_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(props, val, extend);
|
|
56
55
|
}
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
const columns = (0, _useColumns.useColumns)(props.columns, value);
|
|
60
|
-
const generateValueExtend = (0, _usePickerValueExtend.usePickerValueExtend)(columns);
|
|
56
|
+
}));
|
|
57
|
+
const extend = (0, _columnsExtend.useColumnsExtend)(props.columns, value);
|
|
61
58
|
const [innerValue, setInnerValue] = (0, _react.useState)(value);
|
|
62
59
|
(0, _react.useEffect)(() => {
|
|
63
60
|
if (innerValue !== value) {
|
|
@@ -130,7 +127,7 @@ const Picker = (0, _react.memo)(p => {
|
|
|
130
127
|
position: 'bottom'
|
|
131
128
|
}));
|
|
132
129
|
|
|
133
|
-
return _react.default.createElement(_react.default.Fragment, null, popupElement, (_a = props.children) === null || _a === void 0 ? void 0 : _a.call(props,
|
|
130
|
+
return _react.default.createElement(_react.default.Fragment, null, popupElement, (_a = props.children) === null || _a === void 0 ? void 0 : _a.call(props, extend.items));
|
|
134
131
|
});
|
|
135
132
|
exports.Picker = Picker;
|
|
136
133
|
Picker.displayName = 'Picker';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PickerViewProps, PickerValue, PickerValueExtend } from './picker-view';
|
|
2
|
+
export declare function generateColumnsExtend(rawColumns: PickerViewProps['columns'], val: PickerValue[]): PickerValueExtend;
|
|
3
|
+
export declare function useColumnsExtend(rawColumns: PickerViewProps['columns'], value: PickerValue[]): PickerValueExtend;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateColumnsExtend = generateColumnsExtend;
|
|
7
|
+
exports.useColumnsExtend = useColumnsExtend;
|
|
8
|
+
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
|
|
11
|
+
var _withCache = require("../../utils/with-cache");
|
|
12
|
+
|
|
13
|
+
function generateColumnsExtend(rawColumns, val) {
|
|
14
|
+
const columns = (0, _withCache.withCache)(() => {
|
|
15
|
+
const c = typeof rawColumns === 'function' ? rawColumns(val) : rawColumns;
|
|
16
|
+
return c.map(column => column.map(item => typeof item === 'string' ? {
|
|
17
|
+
label: item,
|
|
18
|
+
value: item
|
|
19
|
+
} : item));
|
|
20
|
+
});
|
|
21
|
+
const items = (0, _withCache.withCache)(() => {
|
|
22
|
+
return val.map((v, index) => {
|
|
23
|
+
var _a;
|
|
24
|
+
|
|
25
|
+
const column = columns()[index];
|
|
26
|
+
if (!column) return null;
|
|
27
|
+
return (_a = column.find(item => item.value === v)) !== null && _a !== void 0 ? _a : null;
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
const extend = {
|
|
31
|
+
get columns() {
|
|
32
|
+
return columns();
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
get items() {
|
|
36
|
+
return items();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
};
|
|
40
|
+
return extend;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function useColumnsExtend(rawColumns, value) {
|
|
44
|
+
return (0, _react.useMemo)(() => generateColumnsExtend(rawColumns, value), [rawColumns, value]);
|
|
45
|
+
}
|
|
@@ -2,6 +2,7 @@ import React, { ReactNode } from 'react';
|
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
export declare type PickerValue = string | null;
|
|
4
4
|
export declare type PickerValueExtend = {
|
|
5
|
+
columns: PickerColumnItem[][];
|
|
5
6
|
items: (PickerColumnItem | null)[];
|
|
6
7
|
};
|
|
7
8
|
export declare type PickerColumnItem = {
|
|
@@ -11,12 +11,10 @@ var _withDefaultProps = require("../../utils/with-default-props");
|
|
|
11
11
|
|
|
12
12
|
var _wheel = require("./wheel");
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var _columnsExtend = require("./columns-extend");
|
|
15
15
|
|
|
16
16
|
var _nativeProps = require("../../utils/native-props");
|
|
17
17
|
|
|
18
|
-
var _usePickerValueExtend = require("./use-picker-value-extend");
|
|
19
|
-
|
|
20
18
|
var _ahooks = require("ahooks");
|
|
21
19
|
|
|
22
20
|
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); }
|
|
@@ -29,17 +27,7 @@ const defaultProps = {
|
|
|
29
27
|
};
|
|
30
28
|
const PickerView = (0, _react.memo)(p => {
|
|
31
29
|
const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
|
|
32
|
-
const [innerValue, setInnerValue] = (0, _react.useState)(props.value === undefined ? props.defaultValue : props.value);
|
|
33
|
-
(0, _ahooks.useDebounceEffect)(() => {
|
|
34
|
-
var _a;
|
|
35
|
-
|
|
36
|
-
if (props.value === innerValue) return;
|
|
37
|
-
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, innerValue, generateValueExtend(innerValue));
|
|
38
|
-
}, [innerValue], {
|
|
39
|
-
wait: 0,
|
|
40
|
-
leading: false,
|
|
41
|
-
trailing: true
|
|
42
|
-
}); // Sync `value` to `innerValue`
|
|
30
|
+
const [innerValue, setInnerValue] = (0, _react.useState)(props.value === undefined ? props.defaultValue : props.value); // Sync `value` to `innerValue`
|
|
43
31
|
|
|
44
32
|
(0, _react.useEffect)(() => {
|
|
45
33
|
if (props.value === undefined) return; // Uncontrolled mode
|
|
@@ -58,8 +46,18 @@ const PickerView = (0, _react.memo)(p => {
|
|
|
58
46
|
window.clearTimeout(timeout);
|
|
59
47
|
};
|
|
60
48
|
}, [props.value, innerValue]);
|
|
61
|
-
const
|
|
62
|
-
const
|
|
49
|
+
const extend = (0, _columnsExtend.useColumnsExtend)(props.columns, innerValue);
|
|
50
|
+
const columns = extend.columns;
|
|
51
|
+
(0, _ahooks.useDebounceEffect)(() => {
|
|
52
|
+
var _a;
|
|
53
|
+
|
|
54
|
+
if (props.value === innerValue) return;
|
|
55
|
+
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, innerValue, extend);
|
|
56
|
+
}, [innerValue], {
|
|
57
|
+
wait: 0,
|
|
58
|
+
leading: false,
|
|
59
|
+
trailing: true
|
|
60
|
+
});
|
|
63
61
|
const handleSelect = (0, _react.useCallback)((val, index) => {
|
|
64
62
|
setInnerValue(prev => {
|
|
65
63
|
const next = [...prev];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withCache<T>(generate: () => T): () => T;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.withCache = withCache;
|
|
7
|
+
|
|
8
|
+
function withCache(generate) {
|
|
9
|
+
let cache = null;
|
|
10
|
+
return () => {
|
|
11
|
+
if (cache === null) {
|
|
12
|
+
cache = generate();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return cache;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -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
|
-
|
|
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 {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef,
|
|
1
|
+
import React, { forwardRef, useState, useImperativeHandle } from 'react';
|
|
2
2
|
import { withNativeProps } from '../../utils/native-props';
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
import classNames from 'classnames';
|
|
@@ -7,11 +7,15 @@ import { ArrowLeft } from './arrow-left';
|
|
|
7
7
|
import { ArrowLeftDouble } from './arrow-left-double';
|
|
8
8
|
import { useConfig } from '../config-provider';
|
|
9
9
|
import isoWeek from 'dayjs/plugin/isoWeek';
|
|
10
|
-
import {
|
|
10
|
+
import { useUpdateEffect } from 'ahooks';
|
|
11
|
+
import { usePropsValue } from '../../utils/use-props-value';
|
|
12
|
+
import { convertValueToRange } from './convert';
|
|
11
13
|
dayjs.extend(isoWeek);
|
|
12
14
|
const classPrefix = 'adm-calendar';
|
|
13
15
|
const defaultProps = {
|
|
14
|
-
weekStartsOn: 'Sunday'
|
|
16
|
+
weekStartsOn: 'Sunday',
|
|
17
|
+
defaultValue: null,
|
|
18
|
+
allowClear: true
|
|
15
19
|
};
|
|
16
20
|
export const Calendar = forwardRef((p, ref) => {
|
|
17
21
|
const today = dayjs();
|
|
@@ -26,29 +30,21 @@ export const Calendar = forwardRef((p, ref) => {
|
|
|
26
30
|
if (item) markItems.unshift(item);
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
const dateRange =
|
|
30
|
-
|
|
33
|
+
const [dateRange, setDateRange] = usePropsValue({
|
|
34
|
+
value: props.value === undefined ? undefined : convertValueToRange(props.selectionMode, props.value),
|
|
35
|
+
defaultValue: convertValueToRange(props.selectionMode, props.defaultValue),
|
|
36
|
+
onChange: v => {
|
|
37
|
+
var _a, _b;
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
} else {
|
|
38
|
-
return [null, null];
|
|
39
|
+
if (props.selectionMode === 'single') {
|
|
40
|
+
(_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, v ? v[0] : null);
|
|
41
|
+
} else if (props.selectionMode === 'range') {
|
|
42
|
+
(_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, v);
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
|
-
}, [props.selectionMode, props.value, props.defaultValue]);
|
|
41
|
-
const [begin, setBegin] = useState(null);
|
|
42
|
-
const [end, setEnd] = useState(null);
|
|
43
|
-
useIsomorphicLayoutEffect(() => {
|
|
44
|
-
setBegin(dateRange[0] ? dayjs(dateRange[0]) : null);
|
|
45
|
-
setEnd(dateRange[1] ? dayjs(dateRange[1]) : null);
|
|
46
|
-
}, [dateRange[0], dateRange[1]]);
|
|
47
|
-
const [current, setCurrent] = useState(() => {
|
|
48
|
-
var _a;
|
|
49
|
-
|
|
50
|
-
return dayjs((_a = dateRange[0]) !== null && _a !== void 0 ? _a : today).date(1);
|
|
51
45
|
});
|
|
46
|
+
const [intermediate, setIntermediate] = useState(false);
|
|
47
|
+
const [current, setCurrent] = useState(() => dayjs(dateRange ? dateRange[0] : today).date(1));
|
|
52
48
|
useUpdateEffect(() => {
|
|
53
49
|
var _a;
|
|
54
50
|
|
|
@@ -111,14 +107,16 @@ export const Calendar = forwardRef((p, ref) => {
|
|
|
111
107
|
|
|
112
108
|
while (cells.length < 6 * 7) {
|
|
113
109
|
const d = iterator;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
110
|
+
let isSelect = false;
|
|
111
|
+
let isBegin = false;
|
|
112
|
+
let isEnd = false;
|
|
113
|
+
|
|
114
|
+
if (dateRange) {
|
|
115
|
+
const [begin, end] = dateRange;
|
|
116
|
+
isBegin = d.isSame(begin, 'day');
|
|
117
|
+
isEnd = d.isSame(end, 'day');
|
|
118
|
+
isSelect = isBegin || isEnd || d.isAfter(begin, 'day') && d.isBefore(end, 'day');
|
|
119
|
+
}
|
|
122
120
|
|
|
123
121
|
const inThisMonth = d.month() === current.month();
|
|
124
122
|
cells.push(React.createElement("div", {
|
|
@@ -126,41 +124,52 @@ export const Calendar = forwardRef((p, ref) => {
|
|
|
126
124
|
className: classNames(`${classPrefix}-cell`, inThisMonth ? `${classPrefix}-cell-in` : `${classPrefix}-cell-out`, inThisMonth && {
|
|
127
125
|
[`${classPrefix}-cell-today`]: d.isSame(today, 'day'),
|
|
128
126
|
[`${classPrefix}-cell-selected`]: isSelect,
|
|
129
|
-
[`${classPrefix}-cell-selected-begin`]:
|
|
130
|
-
[`${classPrefix}-cell-selected-end`]:
|
|
127
|
+
[`${classPrefix}-cell-selected-begin`]: isBegin,
|
|
128
|
+
[`${classPrefix}-cell-selected-end`]: isEnd
|
|
131
129
|
}),
|
|
132
130
|
onClick: () => {
|
|
133
|
-
var _a, _b, _c;
|
|
134
|
-
|
|
135
131
|
if (!props.selectionMode) return;
|
|
132
|
+
const date = d.toDate();
|
|
133
|
+
|
|
134
|
+
if (!inThisMonth) {
|
|
135
|
+
setCurrent(d.clone().date(1));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function shouldClear() {
|
|
139
|
+
if (!props.allowClear) return false;
|
|
140
|
+
if (!dateRange) return false;
|
|
141
|
+
const [begin, end] = dateRange;
|
|
142
|
+
return d.isSame(begin, 'date') && d.isSame(end, 'day');
|
|
143
|
+
}
|
|
136
144
|
|
|
137
145
|
if (props.selectionMode === 'single') {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
146
|
+
if (props.allowClear && shouldClear()) {
|
|
147
|
+
setDateRange(null);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
setDateRange([date, date]);
|
|
141
152
|
} else if (props.selectionMode === 'range') {
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} else {
|
|
147
|
-
if (d.isBefore(begin)) {
|
|
148
|
-
setEnd(begin);
|
|
149
|
-
setBegin(d);
|
|
150
|
-
(_b = props.onChange) === null || _b === void 0 ? void 0 : _b.call(props, [d.toDate(), begin.toDate()]);
|
|
151
|
-
} else {
|
|
152
|
-
setEnd(d);
|
|
153
|
-
(_c = props.onChange) === null || _c === void 0 ? void 0 : _c.call(props, [begin.toDate(), d.toDate()]);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
} else {
|
|
157
|
-
setBegin(d);
|
|
158
|
-
setEnd(null);
|
|
153
|
+
if (!dateRange) {
|
|
154
|
+
setDateRange([date, date]);
|
|
155
|
+
setIntermediate(true);
|
|
156
|
+
return;
|
|
159
157
|
}
|
|
160
|
-
}
|
|
161
158
|
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
if (shouldClear()) {
|
|
160
|
+
setDateRange(null);
|
|
161
|
+
setIntermediate(false);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (intermediate) {
|
|
166
|
+
const another = dateRange[0];
|
|
167
|
+
setDateRange(another > date ? [date, another] : [another, date]);
|
|
168
|
+
setIntermediate(false);
|
|
169
|
+
} else {
|
|
170
|
+
setDateRange([date, date]);
|
|
171
|
+
setIntermediate(true);
|
|
172
|
+
}
|
|
164
173
|
}
|
|
165
174
|
}
|
|
166
175
|
}, React.createElement("div", {
|
|
@@ -4,9 +4,8 @@ import { mergeProps } from '../../utils/with-default-props';
|
|
|
4
4
|
import { withNativeProps } from '../../utils/native-props';
|
|
5
5
|
import { usePropsValue } from '../../utils/use-props-value';
|
|
6
6
|
import PickerView from '../picker-view';
|
|
7
|
-
import {
|
|
7
|
+
import { generateColumnsExtend, useColumnsExtend } from '../picker-view/columns-extend';
|
|
8
8
|
import { useConfig } from '../config-provider';
|
|
9
|
-
import { usePickerValueExtend } from '../picker-view/use-picker-value-extend';
|
|
10
9
|
import { useMemoizedFn } from 'ahooks';
|
|
11
10
|
import SafeArea from '../safe-area';
|
|
12
11
|
const classPrefix = `adm-picker`;
|
|
@@ -28,12 +27,11 @@ export const Picker = memo(p => {
|
|
|
28
27
|
onChange: val => {
|
|
29
28
|
var _a;
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
const extend = generateColumnsExtend(props.columns, val);
|
|
31
|
+
(_a = props.onConfirm) === null || _a === void 0 ? void 0 : _a.call(props, val, extend);
|
|
32
32
|
}
|
|
33
|
-
}));
|
|
34
|
-
|
|
35
|
-
const columns = useColumns(props.columns, value);
|
|
36
|
-
const generateValueExtend = usePickerValueExtend(columns);
|
|
33
|
+
}));
|
|
34
|
+
const extend = useColumnsExtend(props.columns, value);
|
|
37
35
|
const [innerValue, setInnerValue] = useState(value);
|
|
38
36
|
useEffect(() => {
|
|
39
37
|
if (innerValue !== value) {
|
|
@@ -104,6 +102,6 @@ export const Picker = memo(p => {
|
|
|
104
102
|
}, pickerElement, React.createElement(SafeArea, {
|
|
105
103
|
position: 'bottom'
|
|
106
104
|
}));
|
|
107
|
-
return React.createElement(React.Fragment, null, popupElement, (_a = props.children) === null || _a === void 0 ? void 0 : _a.call(props,
|
|
105
|
+
return React.createElement(React.Fragment, null, popupElement, (_a = props.children) === null || _a === void 0 ? void 0 : _a.call(props, extend.items));
|
|
108
106
|
});
|
|
109
107
|
Picker.displayName = 'Picker';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { PickerViewProps, PickerValue, PickerValueExtend } from './picker-view';
|
|
2
|
+
export declare function generateColumnsExtend(rawColumns: PickerViewProps['columns'], val: PickerValue[]): PickerValueExtend;
|
|
3
|
+
export declare function useColumnsExtend(rawColumns: PickerViewProps['columns'], value: PickerValue[]): PickerValueExtend;
|