antd-mobile 5.38.0 → 5.39.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/bundle/antd-mobile.cjs.development.js +278 -237
- package/2x/bundle/antd-mobile.cjs.js +7 -7
- package/2x/bundle/antd-mobile.es.development.js +279 -238
- package/2x/bundle/antd-mobile.es.js +5466 -5430
- package/2x/bundle/antd-mobile.umd.development.js +278 -237
- package/2x/bundle/antd-mobile.umd.js +7 -7
- package/2x/bundle/style.css +17 -2
- package/2x/cjs/components/calendar-picker/calendar-picker.d.ts +9 -9
- package/2x/cjs/components/calendar-picker-view/calendar-picker-view.d.ts +5 -4
- package/2x/cjs/components/calendar-picker-view/calendar-picker-view.js +18 -11
- package/2x/cjs/components/date-picker/date-picker-week-utils.js +2 -2
- 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 +112 -0
- package/2x/cjs/components/ellipsis/~ellipsis.d.ts +15 -0
- package/2x/cjs/components/ellipsis/~ellipsis.js +161 -0
- package/2x/cjs/components/floating-panel/floating-panel.css +16 -2
- package/2x/cjs/components/floating-panel/floating-panel.d.ts +3 -1
- package/2x/cjs/components/floating-panel/floating-panel.js +43 -30
- package/2x/cjs/components/image-uploader/image-uploader.d.ts +3 -3
- package/2x/cjs/components/image-uploader/image-uploader.js +11 -11
- package/2x/cjs/components/image-viewer/image-viewer.d.ts +13 -4
- package/2x/cjs/components/image-viewer/image-viewer.js +8 -6
- package/2x/cjs/components/image-viewer/index.d.ts +4 -1
- package/2x/cjs/components/image-viewer/slide.d.ts +5 -1
- package/2x/cjs/components/image-viewer/slide.js +10 -5
- package/2x/cjs/components/image-viewer/slides.d.ts +4 -1
- package/2x/cjs/components/image-viewer/slides.js +14 -12
- package/2x/cjs/components/passcode-input/passcode-input.d.ts +7 -5
- package/2x/cjs/components/passcode-input/passcode-input.js +7 -6
- package/2x/cjs/components/popover/popover.d.ts +2 -2
- package/2x/cjs/components/popover/popover.js +11 -11
- package/2x/cjs/components/swipe-action/swipe-action.d.ts +3 -1
- package/2x/cjs/components/swipe-action/swipe-action.js +25 -23
- package/2x/es/components/calendar-picker/calendar-picker.d.ts +9 -9
- package/2x/es/components/calendar-picker-view/calendar-picker-view.d.ts +5 -4
- package/2x/es/components/calendar-picker-view/calendar-picker-view.js +18 -11
- package/2x/es/components/date-picker/date-picker-week-utils.js +2 -2
- 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 +105 -0
- package/2x/es/components/ellipsis/~ellipsis.d.ts +15 -0
- package/2x/es/components/ellipsis/~ellipsis.js +151 -0
- package/2x/es/components/floating-panel/floating-panel.css +16 -2
- package/2x/es/components/floating-panel/floating-panel.d.ts +3 -1
- package/2x/es/components/floating-panel/floating-panel.js +31 -19
- package/2x/es/components/image-uploader/image-uploader.d.ts +3 -3
- package/2x/es/components/image-uploader/image-uploader.js +11 -11
- package/2x/es/components/image-viewer/image-viewer.d.ts +13 -4
- package/2x/es/components/image-viewer/image-viewer.js +8 -6
- package/2x/es/components/image-viewer/index.d.ts +4 -1
- package/2x/es/components/image-viewer/slide.d.ts +5 -1
- package/2x/es/components/image-viewer/slide.js +11 -6
- package/2x/es/components/image-viewer/slides.d.ts +4 -1
- package/2x/es/components/image-viewer/slides.js +6 -4
- package/2x/es/components/passcode-input/passcode-input.d.ts +7 -5
- package/2x/es/components/passcode-input/passcode-input.js +6 -5
- package/2x/es/components/popover/popover.d.ts +2 -2
- package/2x/es/components/popover/popover.js +10 -10
- package/2x/es/components/swipe-action/swipe-action.d.ts +3 -1
- package/2x/es/components/swipe-action/swipe-action.js +9 -7
- package/2x/package.json +1 -1
- package/bundle/antd-mobile.cjs.development.js +278 -237
- package/bundle/antd-mobile.cjs.js +7 -7
- package/bundle/antd-mobile.compatible.umd.js +1 -1
- package/bundle/antd-mobile.es.development.js +279 -238
- package/bundle/antd-mobile.es.js +5466 -5430
- package/bundle/antd-mobile.umd.development.js +278 -237
- package/bundle/antd-mobile.umd.js +7 -7
- package/bundle/style.css +1 -1
- package/cjs/components/calendar-picker/calendar-picker.d.ts +9 -9
- package/cjs/components/calendar-picker-view/calendar-picker-view.d.ts +5 -4
- package/cjs/components/calendar-picker-view/calendar-picker-view.js +18 -11
- package/cjs/components/date-picker/date-picker-week-utils.js +2 -2
- 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 +112 -0
- package/cjs/components/ellipsis/~ellipsis.d.ts +15 -0
- package/cjs/components/ellipsis/~ellipsis.js +161 -0
- package/cjs/components/floating-panel/floating-panel.css +12 -2
- package/cjs/components/floating-panel/floating-panel.d.ts +3 -1
- package/cjs/components/floating-panel/floating-panel.js +43 -30
- package/cjs/components/image-uploader/image-uploader.d.ts +3 -3
- package/cjs/components/image-uploader/image-uploader.js +11 -11
- package/cjs/components/image-viewer/image-viewer.d.ts +13 -4
- package/cjs/components/image-viewer/image-viewer.js +8 -6
- package/cjs/components/image-viewer/index.d.ts +4 -1
- package/cjs/components/image-viewer/slide.d.ts +5 -1
- package/cjs/components/image-viewer/slide.js +10 -5
- package/cjs/components/image-viewer/slides.d.ts +4 -1
- package/cjs/components/image-viewer/slides.js +14 -12
- package/cjs/components/passcode-input/passcode-input.d.ts +7 -5
- package/cjs/components/passcode-input/passcode-input.js +7 -6
- package/cjs/components/popover/popover.d.ts +2 -2
- package/cjs/components/popover/popover.js +11 -11
- package/cjs/components/swipe-action/swipe-action.d.ts +3 -1
- package/cjs/components/swipe-action/swipe-action.js +25 -23
- package/es/components/calendar-picker/calendar-picker.d.ts +9 -9
- package/es/components/calendar-picker-view/calendar-picker-view.d.ts +5 -4
- package/es/components/calendar-picker-view/calendar-picker-view.js +18 -11
- package/es/components/date-picker/date-picker-week-utils.js +2 -2
- 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 +105 -0
- package/es/components/ellipsis/~ellipsis.d.ts +15 -0
- package/es/components/ellipsis/~ellipsis.js +151 -0
- package/es/components/floating-panel/floating-panel.css +12 -2
- package/es/components/floating-panel/floating-panel.d.ts +3 -1
- package/es/components/floating-panel/floating-panel.js +31 -19
- package/es/components/image-uploader/image-uploader.d.ts +3 -3
- package/es/components/image-uploader/image-uploader.js +11 -11
- package/es/components/image-viewer/image-viewer.d.ts +13 -4
- package/es/components/image-viewer/image-viewer.js +8 -6
- package/es/components/image-viewer/index.d.ts +4 -1
- package/es/components/image-viewer/slide.d.ts +5 -1
- package/es/components/image-viewer/slide.js +11 -6
- package/es/components/image-viewer/slides.d.ts +4 -1
- package/es/components/image-viewer/slides.js +6 -4
- package/es/components/passcode-input/passcode-input.d.ts +7 -5
- package/es/components/passcode-input/passcode-input.js +6 -5
- package/es/components/popover/popover.d.ts +2 -2
- package/es/components/popover/popover.js +10 -10
- package/es/components/swipe-action/swipe-action.d.ts +3 -1
- package/es/components/swipe-action/swipe-action.js +9 -7
- package/package.json +1 -1
- package/umd/antd-mobile.js +1 -1
package/2x/bundle/style.css
CHANGED
|
@@ -2345,6 +2345,7 @@ a.adm-list-item:active:not(.adm-list-item-disabled):after {
|
|
|
2345
2345
|
.adm-ellipsis {
|
|
2346
2346
|
overflow: hidden;
|
|
2347
2347
|
line-height: 1.5;
|
|
2348
|
+
word-break: break-word;
|
|
2348
2349
|
}
|
|
2349
2350
|
|
|
2350
2351
|
.adm-empty {
|
|
@@ -2489,7 +2490,6 @@ a.adm-list-item:active:not(.adm-list-item-disabled):after {
|
|
|
2489
2490
|
--z-index: var(--adm-floating-panel-z-index, 900);
|
|
2490
2491
|
position: fixed;
|
|
2491
2492
|
z-index: var(--z-index);
|
|
2492
|
-
bottom: 0;
|
|
2493
2493
|
left: 0;
|
|
2494
2494
|
width: 100vw;
|
|
2495
2495
|
display: flex;
|
|
@@ -2511,7 +2511,6 @@ a.adm-list-item:active:not(.adm-list-item-disabled):after {
|
|
|
2511
2511
|
content: "";
|
|
2512
2512
|
display: block;
|
|
2513
2513
|
position: absolute;
|
|
2514
|
-
bottom: -100vh;
|
|
2515
2514
|
height: 100vh;
|
|
2516
2515
|
width: 100vw;
|
|
2517
2516
|
background: var(--adm-color-background);
|
|
@@ -2545,6 +2544,22 @@ a.adm-list-item:active:not(.adm-list-item-disabled):after {
|
|
|
2545
2544
|
background: var(--adm-color-background);
|
|
2546
2545
|
}
|
|
2547
2546
|
|
|
2547
|
+
.adm-floating-panel-top {
|
|
2548
|
+
top: 0;
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
.adm-floating-panel-top:after {
|
|
2552
|
+
top: -100vh;
|
|
2553
|
+
}
|
|
2554
|
+
|
|
2555
|
+
.adm-floating-panel-bottom {
|
|
2556
|
+
bottom: 0;
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
.adm-floating-panel-bottom:after {
|
|
2560
|
+
bottom: -100vh;
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2548
2563
|
.adm-form {
|
|
2549
2564
|
--border-inner: solid 2px var(--adm-border-color);
|
|
2550
2565
|
--border-top: solid 2px var(--adm-border-color);
|
|
@@ -27,9 +27,9 @@ export declare const CalendarPicker: React.ForwardRefExoticComponent<(({
|
|
|
27
27
|
title?: React.ReactNode;
|
|
28
28
|
confirmText?: string | undefined;
|
|
29
29
|
weekStartsOn?: "Monday" | "Sunday" | undefined;
|
|
30
|
-
renderTop?: (
|
|
31
|
-
renderDate?: (
|
|
32
|
-
renderBottom?: (
|
|
30
|
+
renderTop?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
31
|
+
renderDate?: import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
32
|
+
renderBottom?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
33
33
|
allowClear?: boolean | undefined;
|
|
34
34
|
max?: Date | undefined;
|
|
35
35
|
min?: Date | undefined;
|
|
@@ -61,9 +61,9 @@ export declare const CalendarPicker: React.ForwardRefExoticComponent<(({
|
|
|
61
61
|
title?: React.ReactNode;
|
|
62
62
|
confirmText?: string | undefined;
|
|
63
63
|
weekStartsOn?: "Monday" | "Sunday" | undefined;
|
|
64
|
-
renderTop?: (
|
|
65
|
-
renderDate?: (
|
|
66
|
-
renderBottom?: (
|
|
64
|
+
renderTop?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
65
|
+
renderDate?: import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
66
|
+
renderBottom?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
67
67
|
allowClear?: boolean | undefined;
|
|
68
68
|
max?: Date | undefined;
|
|
69
69
|
min?: Date | undefined;
|
|
@@ -95,9 +95,9 @@ export declare const CalendarPicker: React.ForwardRefExoticComponent<(({
|
|
|
95
95
|
title?: React.ReactNode;
|
|
96
96
|
confirmText?: string | undefined;
|
|
97
97
|
weekStartsOn?: "Monday" | "Sunday" | undefined;
|
|
98
|
-
renderTop?: (
|
|
99
|
-
renderDate?: (
|
|
100
|
-
renderBottom?: (
|
|
98
|
+
renderTop?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
99
|
+
renderDate?: import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
100
|
+
renderBottom?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
|
|
101
101
|
allowClear?: boolean | undefined;
|
|
102
102
|
max?: Date | undefined;
|
|
103
103
|
min?: Date | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
import { DateRange, Page } from './convert';
|
|
4
4
|
export declare const Context: React.Context<{
|
|
@@ -9,13 +9,14 @@ export declare type CalendarPickerViewRef = {
|
|
|
9
9
|
jumpToToday: () => void;
|
|
10
10
|
getDateRange: () => DateRange;
|
|
11
11
|
};
|
|
12
|
+
export declare type CalendarPickerViewColumRender = (date: Date) => ReactNode;
|
|
12
13
|
export declare type CalendarPickerViewProps = {
|
|
13
14
|
title?: React.ReactNode | false;
|
|
14
15
|
confirmText?: string;
|
|
15
16
|
weekStartsOn?: 'Monday' | 'Sunday';
|
|
16
|
-
renderTop?:
|
|
17
|
-
renderDate?:
|
|
18
|
-
renderBottom?:
|
|
17
|
+
renderTop?: CalendarPickerViewColumRender | false;
|
|
18
|
+
renderDate?: CalendarPickerViewColumRender;
|
|
19
|
+
renderBottom?: CalendarPickerViewColumRender | false;
|
|
19
20
|
allowClear?: boolean;
|
|
20
21
|
max?: Date;
|
|
21
22
|
min?: Date;
|
|
@@ -145,7 +145,6 @@ const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
|
145
145
|
})), _react.default.createElement("div", {
|
|
146
146
|
className: `${classPrefix}-cells`
|
|
147
147
|
}, presetEmptyCells, Array(monthIterator.daysInMonth()).fill(null).map((_, index) => {
|
|
148
|
-
var _a;
|
|
149
148
|
const d = monthIterator.date(index + 1);
|
|
150
149
|
let isSelect = false;
|
|
151
150
|
let isBegin = false;
|
|
@@ -165,21 +164,33 @@ const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
|
165
164
|
const disabled = props.shouldDisableDate ? props.shouldDisableDate(d.toDate()) : maxDay && d.isAfter(maxDay, 'day') || minDay && d.isBefore(minDay, 'day');
|
|
166
165
|
const renderTop = () => {
|
|
167
166
|
var _a;
|
|
167
|
+
if (props.renderTop === false) return null;
|
|
168
|
+
const contentWrapper = content => _react.default.createElement("div", {
|
|
169
|
+
className: `${classPrefix}-cell-top`
|
|
170
|
+
}, content);
|
|
168
171
|
const top = (_a = props.renderTop) === null || _a === void 0 ? void 0 : _a.call(props, d.toDate());
|
|
169
172
|
if (top) {
|
|
170
|
-
return top;
|
|
173
|
+
return contentWrapper(top);
|
|
171
174
|
}
|
|
172
175
|
if (props.selectionMode === 'range') {
|
|
173
176
|
if (isBegin) {
|
|
174
|
-
return locale.Calendar.start;
|
|
177
|
+
return contentWrapper(locale.Calendar.start);
|
|
175
178
|
}
|
|
176
179
|
if (isEnd) {
|
|
177
|
-
return locale.Calendar.end;
|
|
180
|
+
return contentWrapper(locale.Calendar.end);
|
|
178
181
|
}
|
|
179
182
|
}
|
|
180
183
|
if (d.isSame(today, 'day') && !isSelect) {
|
|
181
|
-
return locale.Calendar.today;
|
|
184
|
+
return contentWrapper(locale.Calendar.today);
|
|
182
185
|
}
|
|
186
|
+
return contentWrapper(null);
|
|
187
|
+
};
|
|
188
|
+
const renderBottom = () => {
|
|
189
|
+
var _a;
|
|
190
|
+
if (props.renderBottom === false) return null;
|
|
191
|
+
return _react.default.createElement("div", {
|
|
192
|
+
className: `${classPrefix}-cell-bottom`
|
|
193
|
+
}, (_a = props.renderBottom) === null || _a === void 0 ? void 0 : _a.call(props, d.toDate()));
|
|
183
194
|
};
|
|
184
195
|
return _react.default.createElement("div", {
|
|
185
196
|
key: d.valueOf(),
|
|
@@ -229,13 +240,9 @@ const CalendarPickerView = (0, _react.forwardRef)((p, ref) => {
|
|
|
229
240
|
}
|
|
230
241
|
}
|
|
231
242
|
}
|
|
232
|
-
}, _react.default.createElement("div", {
|
|
233
|
-
className: `${classPrefix}-cell-top`
|
|
234
|
-
}, renderTop()), _react.default.createElement("div", {
|
|
243
|
+
}, renderTop(), _react.default.createElement("div", {
|
|
235
244
|
className: `${classPrefix}-cell-date`
|
|
236
|
-
}, props.renderDate ? props.renderDate(d.toDate()) : d.date()),
|
|
237
|
-
className: `${classPrefix}-cell-bottom`
|
|
238
|
-
}, (_a = props.renderBottom) === null || _a === void 0 ? void 0 : _a.call(props, d.toDate())));
|
|
245
|
+
}, props.renderDate ? props.renderDate(d.toDate()) : d.date()), renderBottom());
|
|
239
246
|
}))));
|
|
240
247
|
monthIterator = monthIterator.add(1, 'month');
|
|
241
248
|
}
|
|
@@ -7,9 +7,9 @@ exports.convertDateToStringArray = convertDateToStringArray;
|
|
|
7
7
|
exports.convertStringArrayToDate = convertStringArrayToDate;
|
|
8
8
|
exports.generateDatePickerColumns = generateDatePickerColumns;
|
|
9
9
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
10
|
+
var _isLeapYear = _interopRequireDefault(require("dayjs/plugin/isLeapYear"));
|
|
10
11
|
var _isoWeek = _interopRequireDefault(require("dayjs/plugin/isoWeek"));
|
|
11
12
|
var _isoWeeksInYear = _interopRequireDefault(require("dayjs/plugin/isoWeeksInYear"));
|
|
12
|
-
var _isLeapYear = _interopRequireDefault(require("dayjs/plugin/isLeapYear"));
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
14
|
_dayjs.default.extend(_isoWeek.default);
|
|
15
15
|
_dayjs.default.extend(_isoWeeksInYear.default);
|
|
@@ -93,6 +93,6 @@ function convertStringArrayToDate(value) {
|
|
|
93
93
|
const yearString = (_a = value[0]) !== null && _a !== void 0 ? _a : '1900';
|
|
94
94
|
const weekString = (_b = value[1]) !== null && _b !== void 0 ? _b : '1';
|
|
95
95
|
const weekdayString = (_c = value[2]) !== null && _c !== void 0 ? _c : '1';
|
|
96
|
-
const day = (0, _dayjs.default)(
|
|
96
|
+
const day = (0, _dayjs.default)(`${parseInt(yearString)}-01-01`).isoWeek(parseInt(weekString)).isoWeekday(parseInt(weekdayString)).hour(0).minute(0).second(0);
|
|
97
97
|
return day.toDate();
|
|
98
98
|
}
|
|
@@ -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 = {
|
|
@@ -4,16 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Ellipsis = void 0;
|
|
7
|
-
var _react =
|
|
8
|
-
var _runes = _interopRequireDefault(require("runes2"));
|
|
9
|
-
var _withDefaultProps = require("../../utils/with-default-props");
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
10
8
|
var _nativeProps = require("../../utils/native-props");
|
|
11
9
|
var _useResizeEffect = require("../../utils/use-resize-effect");
|
|
12
|
-
var
|
|
10
|
+
var _withDefaultProps = require("../../utils/with-default-props");
|
|
13
11
|
var _withStopPropagation = require("../../utils/with-stop-propagation");
|
|
12
|
+
var _useMeasure = _interopRequireDefault(require("./useMeasure"));
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
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); }
|
|
16
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
14
|
const classPrefix = `adm-ellipsis`;
|
|
18
15
|
const defaultProps = {
|
|
19
16
|
direction: 'end',
|
|
@@ -27,135 +24,42 @@ const defaultProps = {
|
|
|
27
24
|
};
|
|
28
25
|
const Ellipsis = p => {
|
|
29
26
|
const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
root.style.display = 'block';
|
|
46
|
-
const originStyle = window.getComputedStyle(root);
|
|
47
|
-
const container = document.createElement('div');
|
|
48
|
-
const styleNames = Array.prototype.slice.apply(originStyle);
|
|
49
|
-
styleNames.forEach(name => {
|
|
50
|
-
container.style.setProperty(name, originStyle.getPropertyValue(name));
|
|
51
|
-
});
|
|
52
|
-
root.style.display = originDisplay;
|
|
53
|
-
container.style.height = 'auto';
|
|
54
|
-
container.style.minHeight = 'auto';
|
|
55
|
-
container.style.maxHeight = 'auto';
|
|
56
|
-
container.style.textOverflow = 'clip';
|
|
57
|
-
container.style.webkitLineClamp = 'unset';
|
|
58
|
-
container.style.display = 'block';
|
|
59
|
-
const lineHeight = pxToNumber(originStyle.lineHeight);
|
|
60
|
-
const maxHeight = Math.floor(lineHeight * (props.rows + 0.5) + pxToNumber(originStyle.paddingTop) + pxToNumber(originStyle.paddingBottom));
|
|
61
|
-
container.innerText = props.content;
|
|
62
|
-
document.body.appendChild(container);
|
|
63
|
-
if (container.offsetHeight <= maxHeight) {
|
|
64
|
-
setExceeded(false);
|
|
65
|
-
} else {
|
|
66
|
-
setExceeded(true);
|
|
67
|
-
const end = props.content.length;
|
|
68
|
-
const collapseEl = typeof props.collapseText === 'string' ? props.collapseText : (_a = collapseElRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML;
|
|
69
|
-
const expandEl = typeof props.expandText === 'string' ? props.expandText : (_b = expandElRef.current) === null || _b === void 0 ? void 0 : _b.innerHTML;
|
|
70
|
-
const actionText = expanded ? collapseEl : expandEl;
|
|
71
|
-
function check(left, right) {
|
|
72
|
-
if (right - left <= 1) {
|
|
73
|
-
if (props.direction === 'end') {
|
|
74
|
-
return {
|
|
75
|
-
leading: getSubString(0, left) + '...'
|
|
76
|
-
};
|
|
77
|
-
} else {
|
|
78
|
-
return {
|
|
79
|
-
tailing: '...' + getSubString(right, end)
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const middle = Math.round((left + right) / 2);
|
|
84
|
-
if (props.direction === 'end') {
|
|
85
|
-
container.innerHTML = getSubString(0, middle) + '...' + actionText;
|
|
86
|
-
} else {
|
|
87
|
-
container.innerHTML = actionText + '...' + getSubString(middle, end);
|
|
88
|
-
}
|
|
89
|
-
if (container.offsetHeight <= maxHeight) {
|
|
90
|
-
if (props.direction === 'end') {
|
|
91
|
-
return check(middle, right);
|
|
92
|
-
} else {
|
|
93
|
-
return check(left, middle);
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
if (props.direction === 'end') {
|
|
97
|
-
return check(left, middle);
|
|
98
|
-
} else {
|
|
99
|
-
return check(middle, right);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function checkMiddle(leftPart, rightPart) {
|
|
104
|
-
if (leftPart[1] - leftPart[0] <= 1 && rightPart[1] - rightPart[0] <= 1) {
|
|
105
|
-
return {
|
|
106
|
-
leading: getSubString(0, leftPart[0]) + '...',
|
|
107
|
-
tailing: '...' + getSubString(rightPart[1], end)
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
const leftPartMiddle = Math.floor((leftPart[0] + leftPart[1]) / 2);
|
|
111
|
-
const rightPartMiddle = Math.ceil((rightPart[0] + rightPart[1]) / 2);
|
|
112
|
-
container.innerHTML = getSubString(0, leftPartMiddle) + '...' + actionText + '...' + getSubString(rightPartMiddle, end);
|
|
113
|
-
if (container.offsetHeight <= maxHeight) {
|
|
114
|
-
return checkMiddle([leftPartMiddle, leftPart[1]], [rightPart[0], rightPartMiddle]);
|
|
115
|
-
} else {
|
|
116
|
-
return checkMiddle([leftPart[0], leftPartMiddle], [rightPartMiddle, rightPart[1]]);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
const middle = Math.floor((0 + end) / 2);
|
|
120
|
-
const ellipsised = props.direction === 'middle' ? checkMiddle([0, middle], [middle, end]) : check(0, end);
|
|
121
|
-
setEllipsised(ellipsised);
|
|
122
|
-
}
|
|
123
|
-
document.body.removeChild(container);
|
|
124
|
-
}
|
|
125
|
-
(0, _useResizeEffect.useResizeEffect)(calcEllipsised, rootRef);
|
|
126
|
-
(0, _ahooks.useIsomorphicLayoutEffect)(() => {
|
|
127
|
-
calcEllipsised();
|
|
128
|
-
}, [props.content, props.direction, props.rows, props.expandText, props.collapseText]);
|
|
129
|
-
const expandActionElement = !!props.expandText && (0, _withStopPropagation.withStopPropagation)(props.stopPropagationForActionButtons, _react.default.createElement("a", {
|
|
130
|
-
ref: expandElRef,
|
|
27
|
+
const {
|
|
28
|
+
content,
|
|
29
|
+
direction,
|
|
30
|
+
rows,
|
|
31
|
+
expandText,
|
|
32
|
+
collapseText,
|
|
33
|
+
stopPropagationForActionButtons,
|
|
34
|
+
onContentClick,
|
|
35
|
+
defaultExpanded
|
|
36
|
+
} = props;
|
|
37
|
+
// ============================ Refs ============================
|
|
38
|
+
const rootRef = _react.default.useRef(null);
|
|
39
|
+
// ========================== Expanded ==========================
|
|
40
|
+
const [expanded, setExpanded] = _react.default.useState(defaultExpanded);
|
|
41
|
+
const expandNode = expandText ? (0, _withStopPropagation.withStopPropagation)(stopPropagationForActionButtons, _react.default.createElement("a", {
|
|
131
42
|
onClick: () => {
|
|
132
43
|
setExpanded(true);
|
|
133
44
|
}
|
|
134
|
-
},
|
|
135
|
-
const
|
|
136
|
-
ref: collapseElRef,
|
|
45
|
+
}, expandText)) : null;
|
|
46
|
+
const collapseNode = collapseText ? (0, _withStopPropagation.withStopPropagation)(stopPropagationForActionButtons, _react.default.createElement("a", {
|
|
137
47
|
onClick: () => {
|
|
138
48
|
setExpanded(false);
|
|
139
49
|
}
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
};
|
|
50
|
+
}, collapseText)) : null;
|
|
51
|
+
// ========================== Ellipsis ==========================
|
|
52
|
+
const [measureNodes, forceResize] = (0, _useMeasure.default)(rootRef, content, rows, direction, expanded, expandNode, collapseNode);
|
|
53
|
+
(0, _useResizeEffect.useResizeEffect)(forceResize, rootRef);
|
|
54
|
+
// =========================== Render ===========================
|
|
146
55
|
return (0, _nativeProps.withNativeProps)(props, _react.default.createElement("div", {
|
|
147
56
|
ref: rootRef,
|
|
148
57
|
className: classPrefix,
|
|
149
58
|
onClick: e => {
|
|
150
59
|
if (e.target === e.currentTarget) {
|
|
151
|
-
|
|
60
|
+
onContentClick(e);
|
|
152
61
|
}
|
|
153
62
|
}
|
|
154
|
-
},
|
|
63
|
+
}, measureNodes));
|
|
155
64
|
};
|
|
156
|
-
exports.Ellipsis = Ellipsis;
|
|
157
|
-
function pxToNumber(value) {
|
|
158
|
-
if (!value) return 0;
|
|
159
|
-
const match = value.match(/^\d*(\.\d*)?/);
|
|
160
|
-
return match ? Number(match[0]) : 0;
|
|
161
|
-
}
|
|
65
|
+
exports.Ellipsis = Ellipsis;
|
|
@@ -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,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useMeasure;
|
|
7
|
+
var _rcUtil = require("rc-util");
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
var _reactDom = require("react-dom");
|
|
10
|
+
var _runes = _interopRequireDefault(require("runes2"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
const ELLIPSIS_TEXT = '...';
|
|
13
|
+
const measureStyle = {
|
|
14
|
+
visibility: 'hidden',
|
|
15
|
+
whiteSpace: 'inherit',
|
|
16
|
+
lineHeight: 'inherit',
|
|
17
|
+
fontSize: 'inherit'
|
|
18
|
+
};
|
|
19
|
+
function useMeasure(containerRef, content, rows, direction, expanded, expandNode, collapseNode) {
|
|
20
|
+
const contentChars = _react.default.useMemo(() => (0, _runes.default)(content), [content]);
|
|
21
|
+
const [maxHeight, setMaxHeight] = _react.default.useState(0);
|
|
22
|
+
const [walkingIndexes, setWalkingIndexes] = _react.default.useState([0, 0]);
|
|
23
|
+
const midIndex = Math.ceil((walkingIndexes[0] + walkingIndexes[1]) / 2);
|
|
24
|
+
const [status, setStatus] = _react.default.useState(100 /* STABLE_NO_ELLIPSIS */);
|
|
25
|
+
// ============================ Refs ============================
|
|
26
|
+
const singleRowMeasureRef = _react.default.useRef(null);
|
|
27
|
+
const fullMeasureRef = _react.default.useRef(null);
|
|
28
|
+
const midMeasureRef = _react.default.useRef(null);
|
|
29
|
+
const startMeasure = (0, _rcUtil.useEvent)(() => {
|
|
30
|
+
// use batch update to avoid async update trigger 2 render
|
|
31
|
+
(0, _reactDom.unstable_batchedUpdates)(() => {
|
|
32
|
+
setStatus(1 /* PREPARE */);
|
|
33
|
+
setWalkingIndexes([0, direction === 'middle' ? Math.ceil(contentChars.length / 2) : contentChars.length]);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
// Initialize
|
|
37
|
+
_react.default.useLayoutEffect(() => {
|
|
38
|
+
startMeasure();
|
|
39
|
+
}, [contentChars, rows]);
|
|
40
|
+
// Measure element height
|
|
41
|
+
_react.default.useLayoutEffect(() => {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
if (status === 1 /* PREPARE */) {
|
|
44
|
+
const fullMeasureHeight = ((_a = fullMeasureRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
|
|
45
|
+
const singleRowMeasureHeight = ((_b = singleRowMeasureRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
|
|
46
|
+
const rowMeasureHeight = singleRowMeasureHeight * (rows + 0.5);
|
|
47
|
+
if (fullMeasureHeight <= rowMeasureHeight) {
|
|
48
|
+
setStatus(100 /* STABLE_NO_ELLIPSIS */);
|
|
49
|
+
} else {
|
|
50
|
+
setMaxHeight(rowMeasureHeight);
|
|
51
|
+
setStatus(2 /* MEASURE_WALKING */);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}, [status]);
|
|
55
|
+
// Walking measure
|
|
56
|
+
_react.default.useLayoutEffect(() => {
|
|
57
|
+
var _a;
|
|
58
|
+
if (status === 2 /* MEASURE_WALKING */) {
|
|
59
|
+
const diff = walkingIndexes[1] - walkingIndexes[0];
|
|
60
|
+
const midHeight = ((_a = midMeasureRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
|
|
61
|
+
if (diff > 1) {
|
|
62
|
+
if (midHeight > maxHeight) {
|
|
63
|
+
setWalkingIndexes([walkingIndexes[0], midIndex]);
|
|
64
|
+
} else {
|
|
65
|
+
setWalkingIndexes([midIndex, walkingIndexes[1]]);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (midHeight > maxHeight) {
|
|
69
|
+
setWalkingIndexes([walkingIndexes[0], walkingIndexes[0]]);
|
|
70
|
+
} else {
|
|
71
|
+
setWalkingIndexes([walkingIndexes[1], walkingIndexes[1]]);
|
|
72
|
+
}
|
|
73
|
+
setStatus(99 /* STABLE_ELLIPSIS */);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, [status, walkingIndexes]);
|
|
77
|
+
// =========================== Render ===========================
|
|
78
|
+
/** Render by cut index */
|
|
79
|
+
const renderContent = index => {
|
|
80
|
+
const prefixContent = contentChars.slice(0, index);
|
|
81
|
+
const suffixContent = contentChars.slice(contentChars.length - index);
|
|
82
|
+
return _react.default.createElement(_react.default.Fragment, null, direction === 'start' && _react.default.createElement(_react.default.Fragment, null, expandNode, ELLIPSIS_TEXT), direction !== 'start' && prefixContent.join(''), direction === 'middle' && _react.default.createElement(_react.default.Fragment, null, ELLIPSIS_TEXT, expandNode, ELLIPSIS_TEXT), direction !== 'end' && suffixContent.join(''), direction === 'end' && _react.default.createElement(_react.default.Fragment, null, ELLIPSIS_TEXT, expandNode));
|
|
83
|
+
};
|
|
84
|
+
const finalContent = _react.default.useMemo(() => {
|
|
85
|
+
if (expanded || status === 100 /* STABLE_NO_ELLIPSIS */) {
|
|
86
|
+
return _react.default.createElement(_react.default.Fragment, {
|
|
87
|
+
key: 'display'
|
|
88
|
+
}, content, status === 99 /* STABLE_ELLIPSIS */ && collapseNode);
|
|
89
|
+
}
|
|
90
|
+
if (status === 99 /* STABLE_ELLIPSIS */) {
|
|
91
|
+
return renderContent(midIndex);
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}, [expanded, status, content, collapseNode, midIndex]);
|
|
95
|
+
const allNodes = _react.default.createElement(_react.default.Fragment, null, status === 1 /* PREPARE */ && _react.default.createElement("div", {
|
|
96
|
+
key: 'full',
|
|
97
|
+
"aria-hidden": true,
|
|
98
|
+
ref: fullMeasureRef,
|
|
99
|
+
style: measureStyle
|
|
100
|
+
}, content, expandNode), status === 1 /* PREPARE */ && _react.default.createElement("div", {
|
|
101
|
+
key: 'stable',
|
|
102
|
+
"aria-hidden": true,
|
|
103
|
+
ref: singleRowMeasureRef,
|
|
104
|
+
style: measureStyle
|
|
105
|
+
}, '\u00A0'), status === 2 /* MEASURE_WALKING */ && _react.default.createElement("div", {
|
|
106
|
+
key: 'walking-mid',
|
|
107
|
+
"aria-hidden": true,
|
|
108
|
+
ref: midMeasureRef,
|
|
109
|
+
style: measureStyle
|
|
110
|
+
}, renderContent(midIndex)), finalContent);
|
|
111
|
+
return [allNodes, startMeasure];
|
|
112
|
+
}
|
|
@@ -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>;
|