antd-mobile 5.37.1 → 5.38.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.
- package/2x/README.md +2 -2
- package/2x/bundle/antd-mobile.cjs.development.js +2276 -1113
- package/2x/bundle/antd-mobile.cjs.js +7 -7
- package/2x/bundle/antd-mobile.es.development.js +2279 -1116
- package/2x/bundle/antd-mobile.es.js +7914 -7141
- package/2x/bundle/antd-mobile.umd.development.js +2276 -1113
- package/2x/bundle/antd-mobile.umd.js +7 -7
- package/2x/bundle/css-vars-patch.css +42 -0
- package/2x/bundle/style.css +142 -4
- package/2x/cjs/components/calendar-picker-view/calendar-picker-view.d.ts +1 -1
- package/2x/cjs/components/calendar-picker-view/calendar-picker-view.js +31 -10
- package/2x/cjs/components/card/card.css +1 -0
- package/2x/cjs/components/card/card.d.ts +2 -1
- package/2x/cjs/components/card/card.js +7 -3
- package/2x/cjs/components/card/card.patch.css +8 -0
- package/2x/cjs/components/date-picker/date-picker-quarter-utils.d.ts +7 -0
- package/2x/cjs/components/date-picker/date-picker-quarter-utils.js +77 -0
- package/2x/cjs/components/date-picker/date-picker-utils.d.ts +3 -2
- package/2x/cjs/components/date-picker/date-picker-utils.js +7 -0
- package/2x/cjs/components/ellipsis/ellipsis.css +1 -0
- package/2x/cjs/components/ellipsis/ellipsis.d.ts +1 -1
- package/2x/cjs/components/ellipsis/ellipsis.js +28 -124
- package/2x/cjs/components/ellipsis/useMeasure.d.ts +2 -0
- package/2x/cjs/components/ellipsis/useMeasure.js +108 -0
- package/2x/cjs/components/ellipsis/~ellipsis.d.ts +15 -0
- package/2x/cjs/components/ellipsis/~ellipsis.js +161 -0
- package/2x/cjs/components/image-uploader/image-uploader.js +2 -2
- package/2x/cjs/components/input/input.d.ts +2 -2
- package/2x/cjs/components/input/input.js +1 -0
- package/2x/cjs/components/notice-bar/notice-bar.css +30 -4
- package/2x/cjs/components/notice-bar/notice-bar.d.ts +5 -1
- package/2x/cjs/components/notice-bar/notice-bar.js +7 -3
- package/2x/cjs/components/search-bar/search-bar.d.ts +2 -2
- package/2x/cjs/components/search-bar/search-bar.js +1 -0
- package/2x/cjs/components/segmented/index.d.ts +4 -0
- package/2x/cjs/components/segmented/index.js +10 -0
- package/2x/cjs/components/segmented/segmented.css +113 -0
- package/2x/cjs/components/segmented/segmented.d.ts +21 -0
- package/2x/cjs/components/segmented/segmented.js +57 -0
- package/2x/cjs/components/segmented/segmented.patch.css +41 -0
- package/2x/cjs/components/tab-bar/tab-bar.d.ts +1 -0
- package/2x/cjs/components/tab-bar/tab-bar.js +2 -0
- package/2x/cjs/components/tabs/tabs.js +1 -1
- package/2x/cjs/components/toast/methods.js +9 -3
- package/2x/cjs/global/css-vars-patch.css +42 -0
- package/2x/cjs/index.d.ts +2 -0
- package/2x/cjs/index.js +7 -0
- package/2x/cjs/locales/cnr-ME.d.ts +139 -0
- package/2x/cjs/locales/cnr-ME.js +149 -0
- package/2x/cjs/locales/hr-HR.d.ts +139 -0
- package/2x/cjs/locales/hr-HR.js +149 -0
- package/2x/cjs/locales/kk-KZ.js +6 -6
- package/2x/cjs/locales/sr-RS.d.ts +139 -0
- package/2x/cjs/locales/sr-RS.js +149 -0
- package/2x/cjs/utils/render-imperatively.d.ts +1 -0
- package/2x/cjs/utils/render-imperatively.js +6 -3
- package/2x/es/components/calendar-picker-view/calendar-picker-view.d.ts +1 -1
- package/2x/es/components/calendar-picker-view/calendar-picker-view.js +32 -11
- package/2x/es/components/card/card.css +1 -0
- package/2x/es/components/card/card.d.ts +2 -1
- package/2x/es/components/card/card.js +7 -3
- package/2x/es/components/card/card.patch.css +8 -0
- package/2x/es/components/date-picker/date-picker-quarter-utils.d.ts +7 -0
- package/2x/es/components/date-picker/date-picker-quarter-utils.js +68 -0
- package/2x/es/components/date-picker/date-picker-utils.d.ts +3 -2
- package/2x/es/components/date-picker/date-picker-utils.js +7 -0
- package/2x/es/components/ellipsis/ellipsis.css +1 -0
- package/2x/es/components/ellipsis/ellipsis.d.ts +1 -1
- package/2x/es/components/ellipsis/ellipsis.js +28 -122
- package/2x/es/components/ellipsis/useMeasure.d.ts +2 -0
- package/2x/es/components/ellipsis/useMeasure.js +101 -0
- package/2x/es/components/ellipsis/~ellipsis.d.ts +15 -0
- package/2x/es/components/ellipsis/~ellipsis.js +151 -0
- package/2x/es/components/image-uploader/image-uploader.js +2 -2
- package/2x/es/components/input/input.d.ts +2 -2
- package/2x/es/components/input/input.js +1 -0
- package/2x/es/components/notice-bar/notice-bar.css +30 -4
- package/2x/es/components/notice-bar/notice-bar.d.ts +5 -1
- package/2x/es/components/notice-bar/notice-bar.js +7 -3
- package/2x/es/components/search-bar/search-bar.d.ts +2 -2
- package/2x/es/components/search-bar/search-bar.js +1 -0
- package/2x/es/components/segmented/index.d.ts +4 -0
- package/2x/es/components/segmented/index.js +3 -0
- package/2x/es/components/segmented/segmented.css +113 -0
- package/2x/es/components/segmented/segmented.d.ts +21 -0
- package/2x/es/components/segmented/segmented.js +48 -0
- package/2x/es/components/segmented/segmented.patch.css +41 -0
- package/2x/es/components/tab-bar/tab-bar.d.ts +1 -0
- package/2x/es/components/tab-bar/tab-bar.js +2 -0
- package/2x/es/components/tabs/tabs.js +1 -1
- package/2x/es/components/toast/methods.js +9 -3
- package/2x/es/global/css-vars-patch.css +42 -0
- package/2x/es/index.d.ts +2 -0
- package/2x/es/index.js +1 -0
- package/2x/es/locales/cnr-ME.d.ts +139 -0
- package/2x/es/locales/cnr-ME.js +142 -0
- package/2x/es/locales/hr-HR.d.ts +139 -0
- package/2x/es/locales/hr-HR.js +142 -0
- package/2x/es/locales/kk-KZ.js +6 -6
- package/2x/es/locales/sr-RS.d.ts +139 -0
- package/2x/es/locales/sr-RS.js +142 -0
- package/2x/es/utils/render-imperatively.d.ts +1 -0
- package/2x/es/utils/render-imperatively.js +6 -3
- package/2x/package.json +3 -2
- package/README.md +2 -2
- package/bundle/antd-mobile.cjs.development.js +2276 -1113
- package/bundle/antd-mobile.cjs.js +7 -7
- package/bundle/antd-mobile.compatible.umd.js +1 -1
- package/bundle/antd-mobile.es.development.js +2279 -1116
- package/bundle/antd-mobile.es.js +7914 -7141
- package/bundle/antd-mobile.umd.development.js +2276 -1113
- package/bundle/antd-mobile.umd.js +7 -7
- package/bundle/css-vars-patch.css +32 -0
- package/bundle/style.css +1 -1
- package/cjs/components/calendar-picker-view/calendar-picker-view.d.ts +1 -1
- package/cjs/components/calendar-picker-view/calendar-picker-view.js +31 -10
- package/cjs/components/card/card.css +1 -0
- package/cjs/components/card/card.d.ts +2 -1
- package/cjs/components/card/card.js +7 -3
- package/cjs/components/card/card.patch.css +6 -0
- package/cjs/components/date-picker/date-picker-quarter-utils.d.ts +7 -0
- package/cjs/components/date-picker/date-picker-quarter-utils.js +77 -0
- package/cjs/components/date-picker/date-picker-utils.d.ts +3 -2
- package/cjs/components/date-picker/date-picker-utils.js +7 -0
- package/cjs/components/ellipsis/ellipsis.css +1 -0
- package/cjs/components/ellipsis/ellipsis.d.ts +1 -1
- package/cjs/components/ellipsis/ellipsis.js +28 -124
- package/cjs/components/ellipsis/useMeasure.d.ts +2 -0
- package/cjs/components/ellipsis/useMeasure.js +108 -0
- package/cjs/components/ellipsis/~ellipsis.d.ts +15 -0
- package/cjs/components/ellipsis/~ellipsis.js +161 -0
- package/cjs/components/image-uploader/image-uploader.js +2 -2
- package/cjs/components/input/input.d.ts +2 -2
- package/cjs/components/input/input.js +1 -0
- package/cjs/components/notice-bar/notice-bar.css +25 -4
- package/cjs/components/notice-bar/notice-bar.d.ts +5 -1
- package/cjs/components/notice-bar/notice-bar.js +7 -3
- package/cjs/components/search-bar/search-bar.d.ts +2 -2
- package/cjs/components/search-bar/search-bar.js +1 -0
- package/cjs/components/segmented/index.d.ts +4 -0
- package/cjs/components/segmented/index.js +10 -0
- package/cjs/components/segmented/segmented.css +97 -0
- package/cjs/components/segmented/segmented.d.ts +21 -0
- package/cjs/components/segmented/segmented.js +57 -0
- package/cjs/components/segmented/segmented.patch.css +32 -0
- package/cjs/components/tab-bar/tab-bar.d.ts +1 -0
- package/cjs/components/tab-bar/tab-bar.js +2 -0
- package/cjs/components/tabs/tabs.js +1 -1
- package/cjs/components/toast/methods.js +9 -3
- package/cjs/global/css-vars-patch.css +32 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +7 -0
- package/cjs/locales/cnr-ME.d.ts +139 -0
- package/cjs/locales/cnr-ME.js +149 -0
- package/cjs/locales/hr-HR.d.ts +139 -0
- package/cjs/locales/hr-HR.js +149 -0
- package/cjs/locales/kk-KZ.js +6 -6
- package/cjs/locales/sr-RS.d.ts +139 -0
- package/cjs/locales/sr-RS.js +149 -0
- package/cjs/utils/render-imperatively.d.ts +1 -0
- package/cjs/utils/render-imperatively.js +6 -3
- package/es/components/calendar-picker-view/calendar-picker-view.d.ts +1 -1
- package/es/components/calendar-picker-view/calendar-picker-view.js +32 -11
- package/es/components/card/card.css +1 -0
- package/es/components/card/card.d.ts +2 -1
- package/es/components/card/card.js +7 -3
- package/es/components/card/card.patch.css +6 -0
- package/es/components/date-picker/date-picker-quarter-utils.d.ts +7 -0
- package/es/components/date-picker/date-picker-quarter-utils.js +68 -0
- package/es/components/date-picker/date-picker-utils.d.ts +3 -2
- package/es/components/date-picker/date-picker-utils.js +7 -0
- package/es/components/ellipsis/ellipsis.css +1 -0
- package/es/components/ellipsis/ellipsis.d.ts +1 -1
- package/es/components/ellipsis/ellipsis.js +28 -122
- package/es/components/ellipsis/useMeasure.d.ts +2 -0
- package/es/components/ellipsis/useMeasure.js +101 -0
- package/es/components/ellipsis/~ellipsis.d.ts +15 -0
- package/es/components/ellipsis/~ellipsis.js +151 -0
- package/es/components/image-uploader/image-uploader.js +2 -2
- package/es/components/input/input.d.ts +2 -2
- package/es/components/input/input.js +1 -0
- package/es/components/notice-bar/notice-bar.css +25 -4
- package/es/components/notice-bar/notice-bar.d.ts +5 -1
- package/es/components/notice-bar/notice-bar.js +7 -3
- package/es/components/search-bar/search-bar.d.ts +2 -2
- package/es/components/search-bar/search-bar.js +1 -0
- package/es/components/segmented/index.d.ts +4 -0
- package/es/components/segmented/index.js +3 -0
- package/es/components/segmented/segmented.css +97 -0
- package/es/components/segmented/segmented.d.ts +21 -0
- package/es/components/segmented/segmented.js +48 -0
- package/es/components/segmented/segmented.patch.css +32 -0
- package/es/components/tab-bar/tab-bar.d.ts +1 -0
- package/es/components/tab-bar/tab-bar.js +2 -0
- package/es/components/tabs/tabs.js +1 -1
- package/es/components/toast/methods.js +9 -3
- package/es/global/css-vars-patch.css +32 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +1 -0
- package/es/locales/cnr-ME.d.ts +139 -0
- package/es/locales/cnr-ME.js +142 -0
- package/es/locales/hr-HR.d.ts +139 -0
- package/es/locales/hr-HR.js +142 -0
- package/es/locales/kk-KZ.js +6 -6
- package/es/locales/sr-RS.d.ts +139 -0
- package/es/locales/sr-RS.js +142 -0
- package/es/utils/render-imperatively.d.ts +1 -0
- package/es/utils/render-imperatively.js +6 -3
- package/package.json +3 -2
- package/umd/antd-mobile.js +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
4
3
|
import isoWeek from 'dayjs/plugin/isoWeek';
|
|
5
|
-
import
|
|
4
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
5
|
+
import React, { forwardRef, useContext, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
6
6
|
import { withNativeProps } from '../../utils/native-props';
|
|
7
7
|
import { usePropsValue } from '../../utils/use-props-value';
|
|
8
8
|
import { mergeProps } from '../../utils/with-default-props';
|
|
@@ -49,12 +49,33 @@ export const CalendarPickerView = forwardRef((p, ref) => {
|
|
|
49
49
|
});
|
|
50
50
|
const [intermediate, setIntermediate] = useState(false);
|
|
51
51
|
const [current, setCurrent] = useState(() => dayjs(dateRange ? dateRange[0] : today).date(1));
|
|
52
|
+
const onDateChange = v => {
|
|
53
|
+
if (v) {
|
|
54
|
+
setCurrent(dayjs(v[0]).date(1));
|
|
55
|
+
}
|
|
56
|
+
setDateRange(v);
|
|
57
|
+
};
|
|
58
|
+
const showHeader = props.title !== false;
|
|
52
59
|
// =============================== Scroll ===============================
|
|
53
60
|
const context = useContext(Context);
|
|
54
61
|
const scrollTo = useSyncScroll(current, context.visible, bodyRef);
|
|
55
62
|
// ============================== Boundary ==============================
|
|
56
|
-
|
|
57
|
-
const
|
|
63
|
+
// 记录默认的 min 和 max,并在外部的值超出边界时自动扩充
|
|
64
|
+
const [defaultMin, setDefaultMin] = useState(current);
|
|
65
|
+
const [defaultMax, setDefaultMax] = useState(() => current.add(6, 'month'));
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (dateRange) {
|
|
68
|
+
const [startDate, endDate] = dateRange;
|
|
69
|
+
if (!props.min && startDate && dayjs(startDate).isBefore(defaultMin)) {
|
|
70
|
+
setDefaultMin(dayjs(startDate).date(1));
|
|
71
|
+
}
|
|
72
|
+
if (!props.max && endDate && dayjs(endDate).isAfter(defaultMax)) {
|
|
73
|
+
setDefaultMax(dayjs(endDate).endOf('month'));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, [dateRange]);
|
|
77
|
+
const maxDay = useMemo(() => props.max ? dayjs(props.max) : defaultMax, [props.max, defaultMax]);
|
|
78
|
+
const minDay = useMemo(() => props.min ? dayjs(props.min) : defaultMin, [props.min, defaultMin]);
|
|
58
79
|
// ================================ Refs ================================
|
|
59
80
|
useImperativeHandle(ref, () => ({
|
|
60
81
|
jumpTo: pageOrPageGenerator => {
|
|
@@ -173,27 +194,27 @@ export const CalendarPickerView = forwardRef((p, ref) => {
|
|
|
173
194
|
}
|
|
174
195
|
if (props.selectionMode === 'single') {
|
|
175
196
|
if (props.allowClear && shouldClear()) {
|
|
176
|
-
|
|
197
|
+
onDateChange(null);
|
|
177
198
|
return;
|
|
178
199
|
}
|
|
179
|
-
|
|
200
|
+
onDateChange([date, date]);
|
|
180
201
|
} else if (props.selectionMode === 'range') {
|
|
181
202
|
if (!dateRange) {
|
|
182
|
-
|
|
203
|
+
onDateChange([date, date]);
|
|
183
204
|
setIntermediate(true);
|
|
184
205
|
return;
|
|
185
206
|
}
|
|
186
207
|
if (shouldClear()) {
|
|
187
|
-
|
|
208
|
+
onDateChange(null);
|
|
188
209
|
setIntermediate(false);
|
|
189
210
|
return;
|
|
190
211
|
}
|
|
191
212
|
if (intermediate) {
|
|
192
213
|
const another = dateRange[0];
|
|
193
|
-
|
|
214
|
+
onDateChange(another > date ? [date, another] : [another, date]);
|
|
194
215
|
setIntermediate(false);
|
|
195
216
|
} else {
|
|
196
|
-
|
|
217
|
+
onDateChange([date, date]);
|
|
197
218
|
setIntermediate(true);
|
|
198
219
|
}
|
|
199
220
|
}
|
|
@@ -222,5 +243,5 @@ export const CalendarPickerView = forwardRef((p, ref) => {
|
|
|
222
243
|
}, item)));
|
|
223
244
|
return withNativeProps(props, React.createElement("div", {
|
|
224
245
|
className: classPrefix
|
|
225
|
-
}, header, mark, body));
|
|
246
|
+
}, showHeader && header, mark, body));
|
|
226
247
|
});
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { CSSProperties, FC, ReactNode } from 'react';
|
|
1
2
|
import React from 'react';
|
|
2
|
-
import type { FC, ReactNode, CSSProperties } from 'react';
|
|
3
3
|
import { NativeProps } from '../../utils/native-props';
|
|
4
4
|
export declare type CardProps = {
|
|
5
5
|
title?: ReactNode;
|
|
6
|
+
icon?: ReactNode;
|
|
6
7
|
extra?: ReactNode;
|
|
7
8
|
headerStyle?: CSSProperties;
|
|
8
9
|
headerClassName?: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import classNames from 'classnames';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
import { withNativeProps } from '../../utils/native-props';
|
|
4
4
|
const classPrefix = `adm-card`;
|
|
5
5
|
export const Card = props => {
|
|
@@ -11,9 +11,13 @@ export const Card = props => {
|
|
|
11
11
|
className: classNames(`${classPrefix}-header`, props.headerClassName),
|
|
12
12
|
style: props.headerStyle,
|
|
13
13
|
onClick: props.onHeaderClick
|
|
14
|
-
}, React.createElement("div", {
|
|
14
|
+
}, props.icon && React.createElement("div", {
|
|
15
|
+
className: `${classPrefix}-header-icon`
|
|
16
|
+
}, props.icon), React.createElement("div", {
|
|
15
17
|
className: `${classPrefix}-header-title`
|
|
16
|
-
}, props.title), props.extra
|
|
18
|
+
}, props.title), props.extra && React.createElement("div", {
|
|
19
|
+
className: `${classPrefix}-header-extra`
|
|
20
|
+
}, props.extra));
|
|
17
21
|
};
|
|
18
22
|
const renderBody = () => {
|
|
19
23
|
if (!props.children) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { PickerColumn } from '../picker';
|
|
3
|
+
import type { DatePickerFilter } from './date-picker-utils';
|
|
4
|
+
export declare type QuarterPrecision = 'year' | 'quarter';
|
|
5
|
+
export declare function generateDatePickerColumns(selected: string[], min: Date, max: Date, precision: QuarterPrecision, renderLabel: (type: QuarterPrecision, data: number) => ReactNode, filter: DatePickerFilter | undefined): PickerColumn[];
|
|
6
|
+
export declare function convertDateToStringArray(date: Date | undefined | null): string[];
|
|
7
|
+
export declare function convertStringArrayToDate<T extends string | number | null | undefined>(value: T[]): Date;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import quarterOfYear from 'dayjs/plugin/quarterOfYear';
|
|
3
|
+
dayjs.extend(quarterOfYear);
|
|
4
|
+
const precisionRankRecord = {
|
|
5
|
+
year: 0,
|
|
6
|
+
quarter: 1
|
|
7
|
+
};
|
|
8
|
+
export function generateDatePickerColumns(selected, min, max, precision, renderLabel, filter) {
|
|
9
|
+
const ret = [];
|
|
10
|
+
const minYear = min.getFullYear();
|
|
11
|
+
const maxYear = max.getFullYear();
|
|
12
|
+
const rank = precisionRankRecord[precision];
|
|
13
|
+
const selectedYear = parseInt(selected[0]);
|
|
14
|
+
const isInMinYear = selectedYear === minYear;
|
|
15
|
+
const isInMaxYear = selectedYear === maxYear;
|
|
16
|
+
const minDay = dayjs(min);
|
|
17
|
+
const maxDay = dayjs(max);
|
|
18
|
+
const minQuarter = minDay.quarter();
|
|
19
|
+
const maxQuarter = maxDay.quarter();
|
|
20
|
+
const generateColumn = (from, to, precision) => {
|
|
21
|
+
let column = [];
|
|
22
|
+
for (let i = from; i <= to; i++) {
|
|
23
|
+
column.push(i);
|
|
24
|
+
}
|
|
25
|
+
const prefix = selected.slice(0, precisionRankRecord[precision]);
|
|
26
|
+
const currentFilter = filter === null || filter === void 0 ? void 0 : filter[precision];
|
|
27
|
+
if (currentFilter && typeof currentFilter === 'function') {
|
|
28
|
+
column = column.filter(i => currentFilter(i, {
|
|
29
|
+
get date() {
|
|
30
|
+
const stringArray = [...prefix, i.toString()];
|
|
31
|
+
return convertStringArrayToDate(stringArray);
|
|
32
|
+
}
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
return column;
|
|
36
|
+
};
|
|
37
|
+
if (rank >= precisionRankRecord.year) {
|
|
38
|
+
const lower = minYear;
|
|
39
|
+
const upper = maxYear;
|
|
40
|
+
const years = generateColumn(lower, upper, 'year');
|
|
41
|
+
ret.push(years.map(v => ({
|
|
42
|
+
label: renderLabel('year', v),
|
|
43
|
+
value: v.toString()
|
|
44
|
+
})));
|
|
45
|
+
}
|
|
46
|
+
if (rank >= precisionRankRecord.quarter) {
|
|
47
|
+
const lower = isInMinYear ? minQuarter : 1;
|
|
48
|
+
const upper = isInMaxYear ? maxQuarter : 4;
|
|
49
|
+
const quarters = generateColumn(lower, upper, 'quarter');
|
|
50
|
+
ret.push(quarters.map(v => ({
|
|
51
|
+
label: renderLabel('quarter', v),
|
|
52
|
+
value: v.toString()
|
|
53
|
+
})));
|
|
54
|
+
}
|
|
55
|
+
return ret;
|
|
56
|
+
}
|
|
57
|
+
export function convertDateToStringArray(date) {
|
|
58
|
+
if (!date) return [];
|
|
59
|
+
const day = dayjs(date);
|
|
60
|
+
return [day.year().toString(), day.quarter().toString()];
|
|
61
|
+
}
|
|
62
|
+
export function convertStringArrayToDate(value) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const yearString = (_a = value[0]) !== null && _a !== void 0 ? _a : '1900';
|
|
65
|
+
const quarterString = (_b = value[1]) !== null && _b !== void 0 ? _b : '1';
|
|
66
|
+
const day = dayjs().year(parseInt(yearString)).quarter(parseInt(quarterString)).hour(0).minute(0).second(0);
|
|
67
|
+
return day.toDate();
|
|
68
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { RenderLabel } from '../date-picker-view/date-picker-view';
|
|
1
2
|
import type { DatePrecision } from './date-picker-date-utils';
|
|
3
|
+
import type { QuarterPrecision } from './date-picker-quarter-utils';
|
|
2
4
|
import type { WeekPrecision } from './date-picker-week-utils';
|
|
3
|
-
|
|
4
|
-
export declare type Precision = DatePrecision | WeekPrecision;
|
|
5
|
+
export declare type Precision = DatePrecision | WeekPrecision | QuarterPrecision;
|
|
5
6
|
export declare type DatePickerFilter = Partial<Record<Precision, (val: number, extend: {
|
|
6
7
|
date: Date;
|
|
7
8
|
}) => boolean>>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as dateUtils from './date-picker-date-utils';
|
|
2
|
+
import * as quarterUtils from './date-picker-quarter-utils';
|
|
2
3
|
import * as weekUtils from './date-picker-week-utils';
|
|
3
4
|
import { TILL_NOW } from './util';
|
|
4
5
|
const precisionLengthRecord = {
|
|
@@ -12,6 +13,8 @@ const precisionLengthRecord = {
|
|
|
12
13
|
export const convertDateToStringArray = (date, precision) => {
|
|
13
14
|
if (precision.includes('week')) {
|
|
14
15
|
return weekUtils.convertDateToStringArray(date);
|
|
16
|
+
} else if (precision.includes('quarter')) {
|
|
17
|
+
return quarterUtils.convertDateToStringArray(date);
|
|
15
18
|
} else {
|
|
16
19
|
const datePrecision = precision;
|
|
17
20
|
const stringArray = dateUtils.convertDateToStringArray(date);
|
|
@@ -27,6 +30,8 @@ export const convertStringArrayToDate = (value, precision) => {
|
|
|
27
30
|
}
|
|
28
31
|
if (precision.includes('week')) {
|
|
29
32
|
return weekUtils.convertStringArrayToDate(value);
|
|
33
|
+
} else if (precision.includes('quarter')) {
|
|
34
|
+
return quarterUtils.convertStringArrayToDate(value);
|
|
30
35
|
} else {
|
|
31
36
|
return dateUtils.convertStringArrayToDate(value);
|
|
32
37
|
}
|
|
@@ -34,6 +39,8 @@ export const convertStringArrayToDate = (value, precision) => {
|
|
|
34
39
|
export const generateDatePickerColumns = (selected, min, max, precision, renderLabel, filter, tillNow) => {
|
|
35
40
|
if (precision.startsWith('week')) {
|
|
36
41
|
return weekUtils.generateDatePickerColumns(selected, min, max, precision, renderLabel, filter);
|
|
42
|
+
} else if (precision.startsWith('quarter')) {
|
|
43
|
+
return quarterUtils.generateDatePickerColumns(selected, min, max, precision, renderLabel, filter);
|
|
37
44
|
} else {
|
|
38
45
|
return dateUtils.generateDatePickerColumns(selected, min, max, precision, renderLabel, filter, tillNow);
|
|
39
46
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
import type { FC, ReactNode } from 'react';
|
|
2
|
+
import React from 'react';
|
|
3
3
|
import { NativeProps } from '../../utils/native-props';
|
|
4
4
|
import { PropagationEvent } from '../../utils/with-stop-propagation';
|
|
5
5
|
export declare type EllipsisProps = {
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import runes from 'runes2';
|
|
3
|
-
import { mergeProps } from '../../utils/with-default-props';
|
|
1
|
+
import React from 'react';
|
|
4
2
|
import { withNativeProps } from '../../utils/native-props';
|
|
5
3
|
import { useResizeEffect } from '../../utils/use-resize-effect';
|
|
6
|
-
import {
|
|
4
|
+
import { mergeProps } from '../../utils/with-default-props';
|
|
7
5
|
import { withStopPropagation } from '../../utils/with-stop-propagation';
|
|
6
|
+
import useMeasure from './useMeasure';
|
|
8
7
|
const classPrefix = `adm-ellipsis`;
|
|
9
8
|
const defaultProps = {
|
|
10
9
|
direction: 'end',
|
|
@@ -18,134 +17,41 @@ const defaultProps = {
|
|
|
18
17
|
};
|
|
19
18
|
export const Ellipsis = p => {
|
|
20
19
|
const props = mergeProps(defaultProps, p);
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
root.style.display = 'block';
|
|
37
|
-
const originStyle = window.getComputedStyle(root);
|
|
38
|
-
const container = document.createElement('div');
|
|
39
|
-
const styleNames = Array.prototype.slice.apply(originStyle);
|
|
40
|
-
styleNames.forEach(name => {
|
|
41
|
-
container.style.setProperty(name, originStyle.getPropertyValue(name));
|
|
42
|
-
});
|
|
43
|
-
root.style.display = originDisplay;
|
|
44
|
-
container.style.height = 'auto';
|
|
45
|
-
container.style.minHeight = 'auto';
|
|
46
|
-
container.style.maxHeight = 'auto';
|
|
47
|
-
container.style.textOverflow = 'clip';
|
|
48
|
-
container.style.webkitLineClamp = 'unset';
|
|
49
|
-
container.style.display = 'block';
|
|
50
|
-
const lineHeight = pxToNumber(originStyle.lineHeight);
|
|
51
|
-
const maxHeight = Math.floor(lineHeight * (props.rows + 0.5) + pxToNumber(originStyle.paddingTop) + pxToNumber(originStyle.paddingBottom));
|
|
52
|
-
container.innerText = props.content;
|
|
53
|
-
document.body.appendChild(container);
|
|
54
|
-
if (container.offsetHeight <= maxHeight) {
|
|
55
|
-
setExceeded(false);
|
|
56
|
-
} else {
|
|
57
|
-
setExceeded(true);
|
|
58
|
-
const end = props.content.length;
|
|
59
|
-
const collapseEl = typeof props.collapseText === 'string' ? props.collapseText : (_a = collapseElRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML;
|
|
60
|
-
const expandEl = typeof props.expandText === 'string' ? props.expandText : (_b = expandElRef.current) === null || _b === void 0 ? void 0 : _b.innerHTML;
|
|
61
|
-
const actionText = expanded ? collapseEl : expandEl;
|
|
62
|
-
function check(left, right) {
|
|
63
|
-
if (right - left <= 1) {
|
|
64
|
-
if (props.direction === 'end') {
|
|
65
|
-
return {
|
|
66
|
-
leading: getSubString(0, left) + '...'
|
|
67
|
-
};
|
|
68
|
-
} else {
|
|
69
|
-
return {
|
|
70
|
-
tailing: '...' + getSubString(right, end)
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const middle = Math.round((left + right) / 2);
|
|
75
|
-
if (props.direction === 'end') {
|
|
76
|
-
container.innerHTML = getSubString(0, middle) + '...' + actionText;
|
|
77
|
-
} else {
|
|
78
|
-
container.innerHTML = actionText + '...' + getSubString(middle, end);
|
|
79
|
-
}
|
|
80
|
-
if (container.offsetHeight <= maxHeight) {
|
|
81
|
-
if (props.direction === 'end') {
|
|
82
|
-
return check(middle, right);
|
|
83
|
-
} else {
|
|
84
|
-
return check(left, middle);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
if (props.direction === 'end') {
|
|
88
|
-
return check(left, middle);
|
|
89
|
-
} else {
|
|
90
|
-
return check(middle, right);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
function checkMiddle(leftPart, rightPart) {
|
|
95
|
-
if (leftPart[1] - leftPart[0] <= 1 && rightPart[1] - rightPart[0] <= 1) {
|
|
96
|
-
return {
|
|
97
|
-
leading: getSubString(0, leftPart[0]) + '...',
|
|
98
|
-
tailing: '...' + getSubString(rightPart[1], end)
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
const leftPartMiddle = Math.floor((leftPart[0] + leftPart[1]) / 2);
|
|
102
|
-
const rightPartMiddle = Math.ceil((rightPart[0] + rightPart[1]) / 2);
|
|
103
|
-
container.innerHTML = getSubString(0, leftPartMiddle) + '...' + actionText + '...' + getSubString(rightPartMiddle, end);
|
|
104
|
-
if (container.offsetHeight <= maxHeight) {
|
|
105
|
-
return checkMiddle([leftPartMiddle, leftPart[1]], [rightPart[0], rightPartMiddle]);
|
|
106
|
-
} else {
|
|
107
|
-
return checkMiddle([leftPart[0], leftPartMiddle], [rightPartMiddle, rightPart[1]]);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const middle = Math.floor((0 + end) / 2);
|
|
111
|
-
const ellipsised = props.direction === 'middle' ? checkMiddle([0, middle], [middle, end]) : check(0, end);
|
|
112
|
-
setEllipsised(ellipsised);
|
|
113
|
-
}
|
|
114
|
-
document.body.removeChild(container);
|
|
115
|
-
}
|
|
116
|
-
useResizeEffect(calcEllipsised, rootRef);
|
|
117
|
-
useIsomorphicLayoutEffect(() => {
|
|
118
|
-
calcEllipsised();
|
|
119
|
-
}, [props.content, props.direction, props.rows, props.expandText, props.collapseText]);
|
|
120
|
-
const expandActionElement = !!props.expandText && withStopPropagation(props.stopPropagationForActionButtons, React.createElement("a", {
|
|
121
|
-
ref: expandElRef,
|
|
20
|
+
const {
|
|
21
|
+
content,
|
|
22
|
+
direction,
|
|
23
|
+
rows,
|
|
24
|
+
expandText,
|
|
25
|
+
collapseText,
|
|
26
|
+
stopPropagationForActionButtons,
|
|
27
|
+
onContentClick,
|
|
28
|
+
defaultExpanded
|
|
29
|
+
} = props;
|
|
30
|
+
// ============================ Refs ============================
|
|
31
|
+
const rootRef = React.useRef(null);
|
|
32
|
+
// ========================== Expanded ==========================
|
|
33
|
+
const [expanded, setExpanded] = React.useState(defaultExpanded);
|
|
34
|
+
const expandNode = expandText ? withStopPropagation(stopPropagationForActionButtons, React.createElement("a", {
|
|
122
35
|
onClick: () => {
|
|
123
36
|
setExpanded(true);
|
|
124
37
|
}
|
|
125
|
-
},
|
|
126
|
-
const
|
|
127
|
-
ref: collapseElRef,
|
|
38
|
+
}, expandText)) : null;
|
|
39
|
+
const collapseNode = collapseText ? withStopPropagation(stopPropagationForActionButtons, React.createElement("a", {
|
|
128
40
|
onClick: () => {
|
|
129
41
|
setExpanded(false);
|
|
130
42
|
}
|
|
131
|
-
},
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
};
|
|
43
|
+
}, collapseText)) : null;
|
|
44
|
+
// ========================== Ellipsis ==========================
|
|
45
|
+
const [measureNodes, forceResize] = useMeasure(rootRef, content, rows, direction, expanded, expandNode, collapseNode);
|
|
46
|
+
useResizeEffect(forceResize, rootRef);
|
|
47
|
+
// =========================== Render ===========================
|
|
137
48
|
return withNativeProps(props, React.createElement("div", {
|
|
138
49
|
ref: rootRef,
|
|
139
50
|
className: classPrefix,
|
|
140
51
|
onClick: e => {
|
|
141
52
|
if (e.target === e.currentTarget) {
|
|
142
|
-
|
|
53
|
+
onContentClick(e);
|
|
143
54
|
}
|
|
144
55
|
}
|
|
145
|
-
},
|
|
146
|
-
};
|
|
147
|
-
function pxToNumber(value) {
|
|
148
|
-
if (!value) return 0;
|
|
149
|
-
const match = value.match(/^\d*(\.\d*)?/);
|
|
150
|
-
return match ? Number(match[0]) : 0;
|
|
151
|
-
}
|
|
56
|
+
}, measureNodes));
|
|
57
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default function useMeasure(containerRef: React.RefObject<HTMLDivElement>, content: string, rows: number, direction: 'start' | 'end' | 'middle', expanded: boolean, expandNode: React.ReactElement | null, collapseNode: React.ReactElement | null): readonly [React.JSX.Element, () => void];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useEvent } from 'rc-util';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import runes from 'runes2';
|
|
4
|
+
const ELLIPSIS_TEXT = '...';
|
|
5
|
+
const measureStyle = {
|
|
6
|
+
visibility: 'hidden',
|
|
7
|
+
whiteSpace: 'inherit',
|
|
8
|
+
lineHeight: 'inherit',
|
|
9
|
+
fontSize: 'inherit'
|
|
10
|
+
};
|
|
11
|
+
export default function useMeasure(containerRef, content, rows, direction, expanded, expandNode, collapseNode) {
|
|
12
|
+
const contentChars = React.useMemo(() => runes(content), [content]);
|
|
13
|
+
const [maxHeight, setMaxHeight] = React.useState(0);
|
|
14
|
+
const [walkingIndexes, setWalkingIndexes] = React.useState([0, 0]);
|
|
15
|
+
const midIndex = Math.ceil((walkingIndexes[0] + walkingIndexes[1]) / 2);
|
|
16
|
+
const [status, setStatus] = React.useState(100 /* STABLE_NO_ELLIPSIS */);
|
|
17
|
+
// ============================ Refs ============================
|
|
18
|
+
const singleRowMeasureRef = React.useRef(null);
|
|
19
|
+
const fullMeasureRef = React.useRef(null);
|
|
20
|
+
const midMeasureRef = React.useRef(null);
|
|
21
|
+
const startMeasure = useEvent(() => {
|
|
22
|
+
setStatus(1 /* PREPARE */);
|
|
23
|
+
setWalkingIndexes([0, direction === 'middle' ? Math.ceil(contentChars.length / 2) : contentChars.length]);
|
|
24
|
+
});
|
|
25
|
+
// Initialize
|
|
26
|
+
React.useLayoutEffect(() => {
|
|
27
|
+
startMeasure();
|
|
28
|
+
}, [contentChars, rows]);
|
|
29
|
+
// Measure element height
|
|
30
|
+
React.useLayoutEffect(() => {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
if (status === 1 /* PREPARE */) {
|
|
33
|
+
const fullMeasureHeight = ((_a = fullMeasureRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
|
|
34
|
+
const singleRowMeasureHeight = ((_b = singleRowMeasureRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
|
|
35
|
+
const rowMeasureHeight = singleRowMeasureHeight * rows;
|
|
36
|
+
if (fullMeasureHeight <= rowMeasureHeight) {
|
|
37
|
+
setStatus(100 /* STABLE_NO_ELLIPSIS */);
|
|
38
|
+
} else {
|
|
39
|
+
setMaxHeight(rowMeasureHeight);
|
|
40
|
+
setStatus(2 /* MEASURE_WALKING */);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, [status]);
|
|
44
|
+
// Walking measure
|
|
45
|
+
React.useLayoutEffect(() => {
|
|
46
|
+
var _a;
|
|
47
|
+
if (status === 2 /* MEASURE_WALKING */) {
|
|
48
|
+
const diff = walkingIndexes[1] - walkingIndexes[0];
|
|
49
|
+
const midHeight = ((_a = midMeasureRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
|
|
50
|
+
if (diff > 1) {
|
|
51
|
+
if (midHeight > maxHeight) {
|
|
52
|
+
setWalkingIndexes([walkingIndexes[0], midIndex]);
|
|
53
|
+
} else {
|
|
54
|
+
setWalkingIndexes([midIndex, walkingIndexes[1]]);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
if (midHeight > maxHeight) {
|
|
58
|
+
setWalkingIndexes([walkingIndexes[0], walkingIndexes[0]]);
|
|
59
|
+
} else {
|
|
60
|
+
setWalkingIndexes([walkingIndexes[1], walkingIndexes[1]]);
|
|
61
|
+
}
|
|
62
|
+
setStatus(99 /* STABLE_ELLIPSIS */);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}, [status, walkingIndexes]);
|
|
66
|
+
// =========================== Render ===========================
|
|
67
|
+
/** Render by cut index */
|
|
68
|
+
const renderContent = index => {
|
|
69
|
+
const prefixContent = contentChars.slice(0, index);
|
|
70
|
+
const suffixContent = contentChars.slice(contentChars.length - index);
|
|
71
|
+
return React.createElement(React.Fragment, null, direction === 'start' && React.createElement(React.Fragment, null, expandNode, ELLIPSIS_TEXT), direction !== 'start' && prefixContent.join(''), direction === 'middle' && React.createElement(React.Fragment, null, ELLIPSIS_TEXT, expandNode, ELLIPSIS_TEXT), direction !== 'end' && suffixContent.join(''), direction === 'end' && React.createElement(React.Fragment, null, ELLIPSIS_TEXT, expandNode));
|
|
72
|
+
};
|
|
73
|
+
const finalContent = React.useMemo(() => {
|
|
74
|
+
if (expanded || status === 100 /* STABLE_NO_ELLIPSIS */) {
|
|
75
|
+
return React.createElement(React.Fragment, {
|
|
76
|
+
key: 'display'
|
|
77
|
+
}, content, status === 99 /* STABLE_ELLIPSIS */ && collapseNode);
|
|
78
|
+
}
|
|
79
|
+
if (status === 99 /* STABLE_ELLIPSIS */) {
|
|
80
|
+
return renderContent(midIndex);
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}, [expanded, status, content, collapseNode, midIndex]);
|
|
84
|
+
const allNodes = React.createElement(React.Fragment, null, status === 1 /* PREPARE */ && React.createElement("div", {
|
|
85
|
+
key: 'full',
|
|
86
|
+
"aria-hidden": true,
|
|
87
|
+
ref: fullMeasureRef,
|
|
88
|
+
style: measureStyle
|
|
89
|
+
}, content, expandNode), status === 1 /* PREPARE */ && React.createElement("div", {
|
|
90
|
+
key: 'stable',
|
|
91
|
+
"aria-hidden": true,
|
|
92
|
+
ref: singleRowMeasureRef,
|
|
93
|
+
style: measureStyle
|
|
94
|
+
}, '\u00A0'), status === 2 /* MEASURE_WALKING */ && React.createElement("div", {
|
|
95
|
+
key: 'walking-mid',
|
|
96
|
+
"aria-hidden": true,
|
|
97
|
+
ref: midMeasureRef,
|
|
98
|
+
style: measureStyle
|
|
99
|
+
}, renderContent(midIndex)), finalContent);
|
|
100
|
+
return [allNodes, startMeasure];
|
|
101
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { FC, ReactNode } from 'react';
|
|
3
|
+
import { NativeProps } from '../../utils/native-props';
|
|
4
|
+
import { PropagationEvent } from '../../utils/with-stop-propagation';
|
|
5
|
+
export declare type EllipsisProps = {
|
|
6
|
+
content: string;
|
|
7
|
+
direction?: 'start' | 'end' | 'middle';
|
|
8
|
+
rows?: number;
|
|
9
|
+
expandText?: ReactNode;
|
|
10
|
+
collapseText?: ReactNode;
|
|
11
|
+
stopPropagationForActionButtons?: PropagationEvent[];
|
|
12
|
+
onContentClick?: (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
13
|
+
defaultExpanded?: boolean;
|
|
14
|
+
} & NativeProps;
|
|
15
|
+
export declare const Ellipsis: FC<EllipsisProps>;
|