antd-mobile 5.38.0 → 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/bundle/antd-mobile.cjs.development.js +126 -119
- package/2x/bundle/antd-mobile.cjs.js +7 -7
- package/2x/bundle/antd-mobile.es.development.js +127 -120
- package/2x/bundle/antd-mobile.es.js +4458 -4441
- package/2x/bundle/antd-mobile.umd.development.js +126 -119
- package/2x/bundle/antd-mobile.umd.js +7 -7
- package/2x/bundle/style.css +1 -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/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/package.json +1 -1
- package/bundle/antd-mobile.cjs.development.js +126 -119
- package/bundle/antd-mobile.cjs.js +7 -7
- package/bundle/antd-mobile.compatible.umd.js +1 -1
- package/bundle/antd-mobile.es.development.js +127 -120
- package/bundle/antd-mobile.es.js +4458 -4441
- package/bundle/antd-mobile.umd.development.js +126 -119
- package/bundle/antd-mobile.umd.js +7 -7
- package/bundle/style.css +1 -1
- 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/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/package.json +1 -1
- package/umd/antd-mobile.js +1 -1
|
@@ -13774,6 +13774,113 @@ function betweenInclusive(i2, e2, n2) {
|
|
|
13774
13774
|
!function(i2) {
|
|
13775
13775
|
i2[i2.unit_1 = 1] = "unit_1", i2[i2.unit_2 = 2] = "unit_2", i2[i2.unit_4 = 4] = "unit_4";
|
|
13776
13776
|
}(n || (n = {}));
|
|
13777
|
+
const ELLIPSIS_TEXT = "...";
|
|
13778
|
+
const measureStyle = {
|
|
13779
|
+
visibility: "hidden",
|
|
13780
|
+
whiteSpace: "inherit",
|
|
13781
|
+
lineHeight: "inherit",
|
|
13782
|
+
fontSize: "inherit"
|
|
13783
|
+
};
|
|
13784
|
+
function useMeasure(containerRef, content, rows, direction, expanded, expandNode, collapseNode) {
|
|
13785
|
+
const contentChars = React$1.useMemo(() => runes(content), [content]);
|
|
13786
|
+
const [maxHeight, setMaxHeight] = React$1.useState(0);
|
|
13787
|
+
const [walkingIndexes, setWalkingIndexes] = React$1.useState([0, 0]);
|
|
13788
|
+
const midIndex = Math.ceil((walkingIndexes[0] + walkingIndexes[1]) / 2);
|
|
13789
|
+
const [status, setStatus] = React$1.useState(
|
|
13790
|
+
100
|
|
13791
|
+
/* STABLE_NO_ELLIPSIS */
|
|
13792
|
+
);
|
|
13793
|
+
const singleRowMeasureRef = React$1.useRef(null);
|
|
13794
|
+
const fullMeasureRef = React$1.useRef(null);
|
|
13795
|
+
const midMeasureRef = React$1.useRef(null);
|
|
13796
|
+
const startMeasure = useEvent(() => {
|
|
13797
|
+
setStatus(
|
|
13798
|
+
1
|
|
13799
|
+
/* PREPARE */
|
|
13800
|
+
);
|
|
13801
|
+
setWalkingIndexes([0, direction === "middle" ? Math.ceil(contentChars.length / 2) : contentChars.length]);
|
|
13802
|
+
});
|
|
13803
|
+
React$1.useLayoutEffect(() => {
|
|
13804
|
+
startMeasure();
|
|
13805
|
+
}, [contentChars, rows]);
|
|
13806
|
+
React$1.useLayoutEffect(() => {
|
|
13807
|
+
var _a, _b;
|
|
13808
|
+
if (status === 1) {
|
|
13809
|
+
const fullMeasureHeight = ((_a = fullMeasureRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
|
|
13810
|
+
const singleRowMeasureHeight = ((_b = singleRowMeasureRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
|
|
13811
|
+
const rowMeasureHeight = singleRowMeasureHeight * rows;
|
|
13812
|
+
if (fullMeasureHeight <= rowMeasureHeight) {
|
|
13813
|
+
setStatus(
|
|
13814
|
+
100
|
|
13815
|
+
/* STABLE_NO_ELLIPSIS */
|
|
13816
|
+
);
|
|
13817
|
+
} else {
|
|
13818
|
+
setMaxHeight(rowMeasureHeight);
|
|
13819
|
+
setStatus(
|
|
13820
|
+
2
|
|
13821
|
+
/* MEASURE_WALKING */
|
|
13822
|
+
);
|
|
13823
|
+
}
|
|
13824
|
+
}
|
|
13825
|
+
}, [status]);
|
|
13826
|
+
React$1.useLayoutEffect(() => {
|
|
13827
|
+
var _a;
|
|
13828
|
+
if (status === 2) {
|
|
13829
|
+
const diff = walkingIndexes[1] - walkingIndexes[0];
|
|
13830
|
+
const midHeight = ((_a = midMeasureRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
|
|
13831
|
+
if (diff > 1) {
|
|
13832
|
+
if (midHeight > maxHeight) {
|
|
13833
|
+
setWalkingIndexes([walkingIndexes[0], midIndex]);
|
|
13834
|
+
} else {
|
|
13835
|
+
setWalkingIndexes([midIndex, walkingIndexes[1]]);
|
|
13836
|
+
}
|
|
13837
|
+
} else {
|
|
13838
|
+
if (midHeight > maxHeight) {
|
|
13839
|
+
setWalkingIndexes([walkingIndexes[0], walkingIndexes[0]]);
|
|
13840
|
+
} else {
|
|
13841
|
+
setWalkingIndexes([walkingIndexes[1], walkingIndexes[1]]);
|
|
13842
|
+
}
|
|
13843
|
+
setStatus(
|
|
13844
|
+
99
|
|
13845
|
+
/* STABLE_ELLIPSIS */
|
|
13846
|
+
);
|
|
13847
|
+
}
|
|
13848
|
+
}
|
|
13849
|
+
}, [status, walkingIndexes]);
|
|
13850
|
+
const renderContent = (index2) => {
|
|
13851
|
+
const prefixContent = contentChars.slice(0, index2);
|
|
13852
|
+
const suffixContent = contentChars.slice(contentChars.length - index2);
|
|
13853
|
+
return React$1.createElement(React$1.Fragment, null, direction === "start" && React$1.createElement(React$1.Fragment, null, expandNode, ELLIPSIS_TEXT), direction !== "start" && prefixContent.join(""), direction === "middle" && React$1.createElement(React$1.Fragment, null, ELLIPSIS_TEXT, expandNode, ELLIPSIS_TEXT), direction !== "end" && suffixContent.join(""), direction === "end" && React$1.createElement(React$1.Fragment, null, ELLIPSIS_TEXT, expandNode));
|
|
13854
|
+
};
|
|
13855
|
+
const finalContent = React$1.useMemo(() => {
|
|
13856
|
+
if (expanded || status === 100) {
|
|
13857
|
+
return React$1.createElement(React$1.Fragment, {
|
|
13858
|
+
key: "display"
|
|
13859
|
+
}, content, status === 99 && collapseNode);
|
|
13860
|
+
}
|
|
13861
|
+
if (status === 99) {
|
|
13862
|
+
return renderContent(midIndex);
|
|
13863
|
+
}
|
|
13864
|
+
return null;
|
|
13865
|
+
}, [expanded, status, content, collapseNode, midIndex]);
|
|
13866
|
+
const allNodes = React$1.createElement(React$1.Fragment, null, status === 1 && React$1.createElement("div", {
|
|
13867
|
+
key: "full",
|
|
13868
|
+
"aria-hidden": true,
|
|
13869
|
+
ref: fullMeasureRef,
|
|
13870
|
+
style: measureStyle
|
|
13871
|
+
}, content, expandNode), status === 1 && React$1.createElement("div", {
|
|
13872
|
+
key: "stable",
|
|
13873
|
+
"aria-hidden": true,
|
|
13874
|
+
ref: singleRowMeasureRef,
|
|
13875
|
+
style: measureStyle
|
|
13876
|
+
}, " "), status === 2 && React$1.createElement("div", {
|
|
13877
|
+
key: "walking-mid",
|
|
13878
|
+
"aria-hidden": true,
|
|
13879
|
+
ref: midMeasureRef,
|
|
13880
|
+
style: measureStyle
|
|
13881
|
+
}, renderContent(midIndex)), finalContent);
|
|
13882
|
+
return [allNodes, startMeasure];
|
|
13883
|
+
}
|
|
13777
13884
|
const classPrefix$U = `adm-ellipsis`;
|
|
13778
13885
|
const defaultProps$F = {
|
|
13779
13886
|
direction: "end",
|
|
@@ -13788,140 +13895,40 @@ const defaultProps$F = {
|
|
|
13788
13895
|
};
|
|
13789
13896
|
const Ellipsis = (p) => {
|
|
13790
13897
|
const props = mergeProps(defaultProps$F, p);
|
|
13898
|
+
const {
|
|
13899
|
+
content,
|
|
13900
|
+
direction,
|
|
13901
|
+
rows,
|
|
13902
|
+
expandText,
|
|
13903
|
+
collapseText,
|
|
13904
|
+
stopPropagationForActionButtons,
|
|
13905
|
+
onContentClick,
|
|
13906
|
+
defaultExpanded
|
|
13907
|
+
} = props;
|
|
13791
13908
|
const rootRef = React$1.useRef(null);
|
|
13792
|
-
const
|
|
13793
|
-
const
|
|
13794
|
-
const [ellipsised, setEllipsised] = React$1.useState({});
|
|
13795
|
-
const [expanded, setExpanded] = React$1.useState(props.defaultExpanded);
|
|
13796
|
-
const [exceeded, setExceeded] = React$1.useState(false);
|
|
13797
|
-
const chars = React$1.useMemo(() => runes(props.content), [props.content]);
|
|
13798
|
-
function getSubString(start2, end) {
|
|
13799
|
-
return chars.slice(start2, end).join("");
|
|
13800
|
-
}
|
|
13801
|
-
function calcEllipsised() {
|
|
13802
|
-
var _a, _b;
|
|
13803
|
-
const root2 = rootRef.current;
|
|
13804
|
-
if (!root2)
|
|
13805
|
-
return;
|
|
13806
|
-
const originDisplay = root2.style.display;
|
|
13807
|
-
root2.style.display = "block";
|
|
13808
|
-
const originStyle = window.getComputedStyle(root2);
|
|
13809
|
-
const container = document.createElement("div");
|
|
13810
|
-
const styleNames = Array.prototype.slice.apply(originStyle);
|
|
13811
|
-
styleNames.forEach((name) => {
|
|
13812
|
-
container.style.setProperty(name, originStyle.getPropertyValue(name));
|
|
13813
|
-
});
|
|
13814
|
-
root2.style.display = originDisplay;
|
|
13815
|
-
container.style.height = "auto";
|
|
13816
|
-
container.style.minHeight = "auto";
|
|
13817
|
-
container.style.maxHeight = "auto";
|
|
13818
|
-
container.style.textOverflow = "clip";
|
|
13819
|
-
container.style.webkitLineClamp = "unset";
|
|
13820
|
-
container.style.display = "block";
|
|
13821
|
-
const lineHeight = pxToNumber(originStyle.lineHeight);
|
|
13822
|
-
const maxHeight = Math.floor(lineHeight * (props.rows + 0.5) + pxToNumber(originStyle.paddingTop) + pxToNumber(originStyle.paddingBottom));
|
|
13823
|
-
container.innerText = props.content;
|
|
13824
|
-
document.body.appendChild(container);
|
|
13825
|
-
if (container.offsetHeight <= maxHeight) {
|
|
13826
|
-
setExceeded(false);
|
|
13827
|
-
} else {
|
|
13828
|
-
let check = function(left, right) {
|
|
13829
|
-
if (right - left <= 1) {
|
|
13830
|
-
if (props.direction === "end") {
|
|
13831
|
-
return {
|
|
13832
|
-
leading: getSubString(0, left) + "..."
|
|
13833
|
-
};
|
|
13834
|
-
} else {
|
|
13835
|
-
return {
|
|
13836
|
-
tailing: "..." + getSubString(right, end)
|
|
13837
|
-
};
|
|
13838
|
-
}
|
|
13839
|
-
}
|
|
13840
|
-
const middle2 = Math.round((left + right) / 2);
|
|
13841
|
-
if (props.direction === "end") {
|
|
13842
|
-
container.innerHTML = getSubString(0, middle2) + "..." + actionText;
|
|
13843
|
-
} else {
|
|
13844
|
-
container.innerHTML = actionText + "..." + getSubString(middle2, end);
|
|
13845
|
-
}
|
|
13846
|
-
if (container.offsetHeight <= maxHeight) {
|
|
13847
|
-
if (props.direction === "end") {
|
|
13848
|
-
return check(middle2, right);
|
|
13849
|
-
} else {
|
|
13850
|
-
return check(left, middle2);
|
|
13851
|
-
}
|
|
13852
|
-
} else {
|
|
13853
|
-
if (props.direction === "end") {
|
|
13854
|
-
return check(left, middle2);
|
|
13855
|
-
} else {
|
|
13856
|
-
return check(middle2, right);
|
|
13857
|
-
}
|
|
13858
|
-
}
|
|
13859
|
-
}, checkMiddle = function(leftPart, rightPart) {
|
|
13860
|
-
if (leftPart[1] - leftPart[0] <= 1 && rightPart[1] - rightPart[0] <= 1) {
|
|
13861
|
-
return {
|
|
13862
|
-
leading: getSubString(0, leftPart[0]) + "...",
|
|
13863
|
-
tailing: "..." + getSubString(rightPart[1], end)
|
|
13864
|
-
};
|
|
13865
|
-
}
|
|
13866
|
-
const leftPartMiddle = Math.floor((leftPart[0] + leftPart[1]) / 2);
|
|
13867
|
-
const rightPartMiddle = Math.ceil((rightPart[0] + rightPart[1]) / 2);
|
|
13868
|
-
container.innerHTML = getSubString(0, leftPartMiddle) + "..." + actionText + "..." + getSubString(rightPartMiddle, end);
|
|
13869
|
-
if (container.offsetHeight <= maxHeight) {
|
|
13870
|
-
return checkMiddle([leftPartMiddle, leftPart[1]], [rightPart[0], rightPartMiddle]);
|
|
13871
|
-
} else {
|
|
13872
|
-
return checkMiddle([leftPart[0], leftPartMiddle], [rightPartMiddle, rightPart[1]]);
|
|
13873
|
-
}
|
|
13874
|
-
};
|
|
13875
|
-
setExceeded(true);
|
|
13876
|
-
const end = props.content.length;
|
|
13877
|
-
const collapseEl = typeof props.collapseText === "string" ? props.collapseText : (_a = collapseElRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML;
|
|
13878
|
-
const expandEl = typeof props.expandText === "string" ? props.expandText : (_b = expandElRef.current) === null || _b === void 0 ? void 0 : _b.innerHTML;
|
|
13879
|
-
const actionText = expanded ? collapseEl : expandEl;
|
|
13880
|
-
const middle = Math.floor((0 + end) / 2);
|
|
13881
|
-
const ellipsised2 = props.direction === "middle" ? checkMiddle([0, middle], [middle, end]) : check(0, end);
|
|
13882
|
-
setEllipsised(ellipsised2);
|
|
13883
|
-
}
|
|
13884
|
-
document.body.removeChild(container);
|
|
13885
|
-
}
|
|
13886
|
-
useResizeEffect(calcEllipsised, rootRef);
|
|
13887
|
-
useIsomorphicLayoutEffect$3(() => {
|
|
13888
|
-
calcEllipsised();
|
|
13889
|
-
}, [props.content, props.direction, props.rows, props.expandText, props.collapseText]);
|
|
13890
|
-
const expandActionElement = !!props.expandText && withStopPropagation(props.stopPropagationForActionButtons, React$1.createElement("a", {
|
|
13891
|
-
ref: expandElRef,
|
|
13909
|
+
const [expanded, setExpanded] = React$1.useState(defaultExpanded);
|
|
13910
|
+
const expandNode = expandText ? withStopPropagation(stopPropagationForActionButtons, React$1.createElement("a", {
|
|
13892
13911
|
onClick: () => {
|
|
13893
13912
|
setExpanded(true);
|
|
13894
13913
|
}
|
|
13895
|
-
},
|
|
13896
|
-
const
|
|
13897
|
-
ref: collapseElRef,
|
|
13914
|
+
}, expandText)) : null;
|
|
13915
|
+
const collapseNode = collapseText ? withStopPropagation(stopPropagationForActionButtons, React$1.createElement("a", {
|
|
13898
13916
|
onClick: () => {
|
|
13899
13917
|
setExpanded(false);
|
|
13900
13918
|
}
|
|
13901
|
-
},
|
|
13902
|
-
const
|
|
13903
|
-
|
|
13904
|
-
return props.content;
|
|
13905
|
-
if (expanded)
|
|
13906
|
-
return React$1.createElement(React$1.Fragment, null, props.content, collapseActionElement);
|
|
13907
|
-
return React$1.createElement(React$1.Fragment, null, ellipsised.leading, expandActionElement, ellipsised.tailing);
|
|
13908
|
-
};
|
|
13919
|
+
}, collapseText)) : null;
|
|
13920
|
+
const [measureNodes, forceResize] = useMeasure(rootRef, content, rows, direction, expanded, expandNode, collapseNode);
|
|
13921
|
+
useResizeEffect(forceResize, rootRef);
|
|
13909
13922
|
return withNativeProps(props, React$1.createElement("div", {
|
|
13910
13923
|
ref: rootRef,
|
|
13911
13924
|
className: classPrefix$U,
|
|
13912
13925
|
onClick: (e2) => {
|
|
13913
13926
|
if (e2.target === e2.currentTarget) {
|
|
13914
|
-
|
|
13927
|
+
onContentClick(e2);
|
|
13915
13928
|
}
|
|
13916
13929
|
}
|
|
13917
|
-
},
|
|
13930
|
+
}, measureNodes));
|
|
13918
13931
|
};
|
|
13919
|
-
function pxToNumber(value) {
|
|
13920
|
-
if (!value)
|
|
13921
|
-
return 0;
|
|
13922
|
-
const match = value.match(/^\d*(\.\d*)?/);
|
|
13923
|
-
return match ? Number(match[0]) : 0;
|
|
13924
|
-
}
|
|
13925
13932
|
const EmptyIcon = (props) => {
|
|
13926
13933
|
return withNativeProps(props, React$1.createElement("svg", {
|
|
13927
13934
|
viewBox: "0 0 64 41"
|