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