antd-mobile 5.40.0 → 5.41.0-alpha.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 +150 -16
- package/2x/bundle/antd-mobile.cjs.js +6 -6
- package/2x/bundle/antd-mobile.es.development.js +150 -16
- package/2x/bundle/antd-mobile.es.js +3983 -3914
- package/2x/bundle/antd-mobile.umd.development.js +150 -16
- package/2x/bundle/antd-mobile.umd.js +7 -7
- package/2x/bundle/style.css +4 -1
- package/2x/cjs/components/date-picker/date-picker-week-utils.js +2 -1
- package/2x/cjs/components/ellipsis/ellipsis.d.ts +3 -0
- package/2x/cjs/components/ellipsis/ellipsis.js +10 -2
- package/2x/cjs/components/swiper/swiper.js +1 -1
- package/2x/cjs/components/tabs/tabs.js +45 -13
- package/2x/cjs/components/virtual-input/virtual-input.css +4 -1
- package/2x/cjs/components/virtual-input/virtual-input.d.ts +6 -0
- package/2x/cjs/components/virtual-input/virtual-input.js +105 -8
- package/2x/es/components/date-picker/date-picker-week-utils.js +2 -1
- package/2x/es/components/ellipsis/ellipsis.d.ts +3 -0
- package/2x/es/components/ellipsis/ellipsis.js +10 -2
- package/2x/es/components/swiper/swiper.js +1 -1
- package/2x/es/components/tabs/tabs.js +44 -12
- package/2x/es/components/virtual-input/virtual-input.css +4 -1
- package/2x/es/components/virtual-input/virtual-input.d.ts +6 -0
- package/2x/es/components/virtual-input/virtual-input.js +105 -8
- package/2x/package.json +3 -3
- package/bundle/antd-mobile.cjs.development.js +150 -16
- package/bundle/antd-mobile.cjs.js +6 -6
- package/bundle/antd-mobile.compatible.umd.js +1 -1
- package/bundle/antd-mobile.es.development.js +150 -16
- package/bundle/antd-mobile.es.js +3983 -3914
- package/bundle/antd-mobile.umd.development.js +150 -16
- package/bundle/antd-mobile.umd.js +7 -7
- package/bundle/style.css +1 -1
- package/cjs/components/date-picker/date-picker-week-utils.js +2 -1
- package/cjs/components/ellipsis/ellipsis.d.ts +3 -0
- package/cjs/components/ellipsis/ellipsis.js +10 -2
- package/cjs/components/swiper/swiper.js +1 -1
- package/cjs/components/tabs/tabs.js +45 -13
- package/cjs/components/virtual-input/virtual-input.css +3 -1
- package/cjs/components/virtual-input/virtual-input.d.ts +6 -0
- package/cjs/components/virtual-input/virtual-input.js +105 -8
- package/es/components/date-picker/date-picker-week-utils.js +2 -1
- package/es/components/ellipsis/ellipsis.d.ts +3 -0
- package/es/components/ellipsis/ellipsis.js +10 -2
- package/es/components/swiper/swiper.js +1 -1
- package/es/components/tabs/tabs.js +44 -12
- package/es/components/virtual-input/virtual-input.css +3 -1
- package/es/components/virtual-input/virtual-input.d.ts +6 -0
- package/es/components/virtual-input/virtual-input.js +105 -8
- package/package.json +3 -3
- package/umd/antd-mobile.js +1 -1
- package/2x/cjs/components/ellipsis/~ellipsis.d.ts +0 -15
- package/2x/cjs/components/ellipsis/~ellipsis.js +0 -161
- package/2x/es/components/ellipsis/~ellipsis.d.ts +0 -15
- package/2x/es/components/ellipsis/~ellipsis.js +0 -151
- package/cjs/components/ellipsis/~ellipsis.d.ts +0 -15
- package/cjs/components/ellipsis/~ellipsis.js +0 -161
- package/es/components/ellipsis/~ellipsis.d.ts +0 -15
- package/es/components/ellipsis/~ellipsis.js +0 -151
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import React, { useMemo, useRef, useState } from 'react';
|
|
2
|
-
import runes from 'runes2';
|
|
3
|
-
import { mergeProps } from '../../utils/with-default-props';
|
|
4
|
-
import { withNativeProps } from '../../utils/native-props';
|
|
5
|
-
import { useResizeEffect } from '../../utils/use-resize-effect';
|
|
6
|
-
import { useIsomorphicLayoutEffect } from 'ahooks';
|
|
7
|
-
import { withStopPropagation } from '../../utils/with-stop-propagation';
|
|
8
|
-
const classPrefix = `adm-ellipsis`;
|
|
9
|
-
const defaultProps = {
|
|
10
|
-
direction: 'end',
|
|
11
|
-
rows: 1,
|
|
12
|
-
expandText: '',
|
|
13
|
-
content: '',
|
|
14
|
-
collapseText: '',
|
|
15
|
-
stopPropagationForActionButtons: [],
|
|
16
|
-
onContentClick: () => {},
|
|
17
|
-
defaultExpanded: false
|
|
18
|
-
};
|
|
19
|
-
export const Ellipsis = p => {
|
|
20
|
-
const props = mergeProps(defaultProps, p);
|
|
21
|
-
const rootRef = useRef(null);
|
|
22
|
-
const expandElRef = useRef(null);
|
|
23
|
-
const collapseElRef = useRef(null);
|
|
24
|
-
const [ellipsised, setEllipsised] = useState({});
|
|
25
|
-
const [expanded, setExpanded] = useState(props.defaultExpanded);
|
|
26
|
-
const [exceeded, setExceeded] = useState(false);
|
|
27
|
-
const chars = useMemo(() => runes(props.content), [props.content]);
|
|
28
|
-
function getSubString(start, end) {
|
|
29
|
-
return chars.slice(start, end).join('');
|
|
30
|
-
}
|
|
31
|
-
function calcEllipsised() {
|
|
32
|
-
var _a, _b;
|
|
33
|
-
const root = rootRef.current;
|
|
34
|
-
if (!root) return;
|
|
35
|
-
const originDisplay = root.style.display;
|
|
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,
|
|
122
|
-
onClick: () => {
|
|
123
|
-
setExpanded(true);
|
|
124
|
-
}
|
|
125
|
-
}, props.expandText));
|
|
126
|
-
const collapseActionElement = !!props.collapseText && withStopPropagation(props.stopPropagationForActionButtons, React.createElement("a", {
|
|
127
|
-
ref: collapseElRef,
|
|
128
|
-
onClick: () => {
|
|
129
|
-
setExpanded(false);
|
|
130
|
-
}
|
|
131
|
-
}, props.collapseText));
|
|
132
|
-
const renderContent = () => {
|
|
133
|
-
if (!exceeded) return props.content;
|
|
134
|
-
if (expanded) return React.createElement(React.Fragment, null, props.content, collapseActionElement);
|
|
135
|
-
return React.createElement(React.Fragment, null, ellipsised.leading, expandActionElement, ellipsised.tailing);
|
|
136
|
-
};
|
|
137
|
-
return withNativeProps(props, React.createElement("div", {
|
|
138
|
-
ref: rootRef,
|
|
139
|
-
className: classPrefix,
|
|
140
|
-
onClick: e => {
|
|
141
|
-
if (e.target === e.currentTarget) {
|
|
142
|
-
props.onContentClick(e);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}, renderContent()));
|
|
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
|
-
}
|