@autobest-ui/components 2.13.11 → 2.14.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/esm/carousel/index.d.ts +4 -0
- package/esm/carousel/index.js +10 -1
- package/esm/checkbox/Checkbox.js +3 -19
- package/esm/checkbox/style/index.css +1 -1
- package/esm/index.d.ts +6 -0
- package/esm/index.js +4 -1
- package/esm/input/Adorn.d.ts +4 -0
- package/esm/input/Adorn.js +7 -3
- package/esm/input/Input.d.ts +1 -0
- package/esm/input/Input.js +5 -1
- package/esm/input/TextArea.d.ts +1 -0
- package/esm/input/TextArea.js +4 -1
- package/esm/input-number/index.d.ts +1 -0
- package/esm/input-number/index.js +5 -1
- package/esm/input-phone/index.d.ts +1 -0
- package/esm/input-phone/index.js +1 -0
- package/esm/lazy-image/index.d.ts +10 -30
- package/esm/lazy-image/index.js +30 -51
- package/esm/lazy-image/style/index.css +1 -1
- package/esm/loading-container/index.d.ts +1 -19
- package/esm/loading-container/index.js +16 -122
- package/esm/loading-icon/index.d.ts +1 -1
- package/esm/loading-icon/index.js +3 -21
- package/esm/move/index.d.ts +10 -0
- package/esm/move/index.js +12 -7
- package/esm/radio/Radio.js +10 -7
- package/esm/radio/RadioGroup.js +3 -6
- package/esm/radio/style/index.css +1 -1
- package/esm/radio/type.d.ts +0 -2
- package/esm/read-more/index.d.ts +92 -0
- package/esm/read-more/index.js +377 -0
- package/esm/read-more/style/index.css +1 -0
- package/esm/read-more-html/index.d.ts +89 -0
- package/esm/read-more-html/index.js +362 -0
- package/esm/read-more-html/style/index.css +1 -0
- package/esm/select/index.d.ts +0 -3
- package/esm/select/index.js +4 -25
- package/esm/select/style/index.css +1 -1
- package/esm/show-more/index.d.ts +27 -12
- package/esm/show-more/index.js +87 -41
- package/esm/show-more/style/index.css +1 -1
- package/esm/style.css +1 -1
- package/esm/table/style/index.css +1 -1
- package/esm/trigger/index.d.ts +3 -10
- package/esm/trigger/index.js +19 -39
- package/lib/carousel/index.d.ts +4 -0
- package/lib/carousel/index.js +10 -1
- package/lib/checkbox/Checkbox.js +3 -19
- package/lib/checkbox/style/index.css +1 -1
- package/lib/index.d.ts +6 -0
- package/lib/index.js +20 -0
- package/lib/input/Adorn.d.ts +4 -0
- package/lib/input/Adorn.js +7 -3
- package/lib/input/Input.d.ts +1 -0
- package/lib/input/Input.js +5 -1
- package/lib/input/TextArea.d.ts +1 -0
- package/lib/input/TextArea.js +4 -1
- package/lib/input-number/index.d.ts +1 -0
- package/lib/input-number/index.js +5 -1
- package/lib/input-phone/index.d.ts +1 -0
- package/lib/input-phone/index.js +1 -0
- package/lib/lazy-image/index.d.ts +10 -30
- package/lib/lazy-image/index.js +30 -51
- package/lib/lazy-image/style/index.css +1 -1
- package/lib/loading-container/index.d.ts +1 -19
- package/lib/loading-container/index.js +16 -125
- package/lib/loading-icon/index.d.ts +1 -1
- package/lib/loading-icon/index.js +3 -21
- package/lib/move/index.d.ts +10 -0
- package/lib/move/index.js +12 -7
- package/lib/radio/Radio.js +10 -7
- package/lib/radio/RadioGroup.js +3 -6
- package/lib/radio/style/index.css +1 -1
- package/lib/radio/type.d.ts +0 -2
- package/lib/read-more/index.d.ts +92 -0
- package/lib/read-more/index.js +388 -0
- package/lib/read-more/style/index.css +1 -0
- package/lib/read-more-html/index.d.ts +89 -0
- package/lib/read-more-html/index.js +373 -0
- package/lib/read-more-html/style/index.css +1 -0
- package/lib/select/index.d.ts +0 -3
- package/lib/select/index.js +4 -25
- package/lib/select/style/index.css +1 -1
- package/lib/show-more/index.d.ts +27 -12
- package/lib/show-more/index.js +86 -40
- package/lib/show-more/style/index.css +1 -1
- package/lib/style.css +1 -1
- package/lib/table/style/index.css +1 -1
- package/lib/trigger/index.d.ts +3 -10
- package/lib/trigger/index.js +19 -39
- package/package.json +3 -3
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
var __assign = this && this.__assign || function () {
|
|
2
|
-
__assign = Object.assign || function (t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) {
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
1
|
import React from 'react';
|
|
14
2
|
import classNames from 'classnames';
|
|
15
3
|
var cls = 'ab-svg-loading';
|
|
16
4
|
var LoadingIcon = function LoadingIcon(props) {
|
|
17
|
-
var className = props.className
|
|
18
|
-
upperRef = props.upperRef;
|
|
5
|
+
var className = props.className;
|
|
19
6
|
return /*#__PURE__*/React.createElement("span", {
|
|
20
|
-
className: classNames(className, cls)
|
|
21
|
-
ref: upperRef
|
|
7
|
+
className: classNames(className, cls)
|
|
22
8
|
}, /*#__PURE__*/React.createElement("svg", {
|
|
23
9
|
xmlns: "http://www.w3.org/2000/svg",
|
|
24
10
|
width: "24",
|
|
@@ -67,8 +53,4 @@ var LoadingIcon = function LoadingIcon(props) {
|
|
|
67
53
|
fill: "#fff"
|
|
68
54
|
})));
|
|
69
55
|
};
|
|
70
|
-
export default /*#__PURE__*/React.memo(
|
|
71
|
-
return /*#__PURE__*/React.createElement(LoadingIcon, __assign({}, props, {
|
|
72
|
-
upperRef: ref
|
|
73
|
-
}));
|
|
74
|
-
}));
|
|
56
|
+
export default /*#__PURE__*/React.memo(LoadingIcon);
|
package/esm/move/index.d.ts
CHANGED
|
@@ -36,6 +36,14 @@ export interface MoveProps {
|
|
|
36
36
|
* 点击的回调函数, 如果移动,则不是click
|
|
37
37
|
*/
|
|
38
38
|
onClick?: (event: any) => void;
|
|
39
|
+
/**
|
|
40
|
+
* 禁止水平方向的移动
|
|
41
|
+
*/
|
|
42
|
+
horizontalMoveDisabled?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 禁止垂直方向的移动
|
|
45
|
+
*/
|
|
46
|
+
verticalMoveDisabled?: boolean;
|
|
39
47
|
}
|
|
40
48
|
declare class Move extends React.Component<MoveProps> {
|
|
41
49
|
readonly prefixCls = "ab-move";
|
|
@@ -46,6 +54,8 @@ declare class Move extends React.Component<MoveProps> {
|
|
|
46
54
|
maxScalable: number;
|
|
47
55
|
horizontalPlacement: string;
|
|
48
56
|
verticalPlacement: string;
|
|
57
|
+
horizontalMoveDisabled: boolean;
|
|
58
|
+
verticalMoveDisabled: boolean;
|
|
49
59
|
};
|
|
50
60
|
prevElementSize: {
|
|
51
61
|
width: number;
|
package/esm/move/index.js
CHANGED
|
@@ -205,13 +205,16 @@ var Move = /** @class */function (_super) {
|
|
|
205
205
|
if (_this.isTouchScale && event.touches.length <= 1) {
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
|
+
var _a = _this.props,
|
|
209
|
+
horizontalMoveDisabled = _a.horizontalMoveDisabled,
|
|
210
|
+
verticalMoveDisabled = _a.verticalMoveDisabled;
|
|
208
211
|
_this.moveObj = {
|
|
209
212
|
left: event.touches ? event.touches[0].pageX : event.clientX,
|
|
210
213
|
top: event.touches ? event.touches[0].pageY : event.clientY
|
|
211
214
|
};
|
|
212
215
|
_this.currentObj = {
|
|
213
|
-
left: _this.prevObj.left + _this.moveObj.left - _this.startObj.left,
|
|
214
|
-
top: _this.prevObj.top + _this.moveObj.top - _this.startObj.top
|
|
216
|
+
left: horizontalMoveDisabled ? _this.prevObj.left : _this.prevObj.left + _this.moveObj.left - _this.startObj.left,
|
|
217
|
+
top: verticalMoveDisabled ? _this.prevObj.top : _this.prevObj.top + _this.moveObj.top - _this.startObj.top
|
|
215
218
|
};
|
|
216
219
|
_this.setElementInfo(element);
|
|
217
220
|
};
|
|
@@ -223,6 +226,10 @@ var Move = /** @class */function (_super) {
|
|
|
223
226
|
if (event.stopPropagation) {
|
|
224
227
|
event.stopPropagation();
|
|
225
228
|
}
|
|
229
|
+
var onClick = _this.props.onClick;
|
|
230
|
+
if (onClick && _this.currentObj.left === _this.prevObj.left && _this.currentObj.top === _this.prevObj.top && _this.prevScaleSize === _this.currentScaleSize) {
|
|
231
|
+
onClick(event);
|
|
232
|
+
}
|
|
226
233
|
var _a = _this.checkRange(),
|
|
227
234
|
nextX = _a.nextX,
|
|
228
235
|
nextY = _a.nextY,
|
|
@@ -237,10 +244,6 @@ var Move = /** @class */function (_super) {
|
|
|
237
244
|
_this.currentScaleSize = nextScaleSize;
|
|
238
245
|
_this.setElementInfo(element);
|
|
239
246
|
}
|
|
240
|
-
var onClick = _this.props.onClick;
|
|
241
|
-
if (onClick && _this.currentObj.left === _this.prevObj.left && _this.currentObj.top === _this.prevObj.top && _this.prevScaleSize === _this.currentScaleSize) {
|
|
242
|
-
onClick(event);
|
|
243
|
-
}
|
|
244
247
|
};
|
|
245
248
|
_this.onTransitionEnd = function () {
|
|
246
249
|
var element = _this.getDomNode();
|
|
@@ -375,7 +378,9 @@ var Move = /** @class */function (_super) {
|
|
|
375
378
|
minScalable: 1,
|
|
376
379
|
maxScalable: 1,
|
|
377
380
|
horizontalPlacement: 'left',
|
|
378
|
-
verticalPlacement: 'top'
|
|
381
|
+
verticalPlacement: 'top',
|
|
382
|
+
horizontalMoveDisabled: false,
|
|
383
|
+
verticalMoveDisabled: false
|
|
379
384
|
};
|
|
380
385
|
return Move;
|
|
381
386
|
}(React.Component);
|
package/esm/radio/Radio.js
CHANGED
|
@@ -50,13 +50,14 @@ var Radio = function Radio(props) {
|
|
|
50
50
|
if (mergedProps.disabled) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
|
+
var checkedValue = ev.target.value;
|
|
53
54
|
if (onChange) {
|
|
54
|
-
onChange(
|
|
55
|
+
onChange(checkedValue, mergedProps.name, ev.target.checked);
|
|
55
56
|
return;
|
|
56
57
|
}
|
|
57
58
|
// radioGroup
|
|
58
59
|
if (groupContext.onChange) {
|
|
59
|
-
groupContext.onChange(
|
|
60
|
+
groupContext.onChange(checkedValue, mergedProps.name);
|
|
60
61
|
return;
|
|
61
62
|
}
|
|
62
63
|
setChecked(!checked);
|
|
@@ -74,6 +75,7 @@ var Radio = function Radio(props) {
|
|
|
74
75
|
},
|
|
75
76
|
type: "radio",
|
|
76
77
|
checked: checked,
|
|
78
|
+
value: value,
|
|
77
79
|
onChange: onRadioChange
|
|
78
80
|
}, mergedProps)), /*#__PURE__*/React.createElement("span", {
|
|
79
81
|
className: "".concat(cls, "-control"),
|
|
@@ -86,20 +88,21 @@ var Radio = function Radio(props) {
|
|
|
86
88
|
className: "".concat(cls, "-outer"),
|
|
87
89
|
focusable: "false",
|
|
88
90
|
"aria-hidden": "true",
|
|
89
|
-
viewBox: "0 0
|
|
91
|
+
viewBox: "0 0 512 512"
|
|
90
92
|
}, /*#__PURE__*/React.createElement("path", {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
d: "M448,256c0-106-86-192-192-192S64,150,64,256s86,192,192,192S448,362,448,256Z",
|
|
94
|
+
strokeWidth: "1.5em",
|
|
95
|
+
fill: "#fff"
|
|
93
96
|
})), /*#__PURE__*/React.createElement("svg", {
|
|
94
97
|
className: "".concat(cls, "-dot"),
|
|
95
98
|
focusable: "false",
|
|
96
99
|
"aria-hidden": "true",
|
|
97
100
|
viewBox: "0 0 24 24"
|
|
98
101
|
}, /*#__PURE__*/React.createElement("path", {
|
|
99
|
-
d: "
|
|
102
|
+
d: "M8.465 8.465C9.37 7.56 10.62 7 12 7C14.76 7 17 9.24 17 12C17 13.38 16.44 14.63 15.535 15.535C14.63 16.44 13.38 17 12 17C9.24 17 7 14.76 7 12C7 10.62 7.56 9.37 8.465 8.465Z"
|
|
100
103
|
}))), children);
|
|
101
104
|
};
|
|
102
105
|
Radio.defaultProps = {
|
|
103
|
-
size:
|
|
106
|
+
size: 16
|
|
104
107
|
};
|
|
105
108
|
export default Radio;
|
package/esm/radio/RadioGroup.js
CHANGED
|
@@ -21,7 +21,6 @@ var __extends = this && this.__extends || function () {
|
|
|
21
21
|
};
|
|
22
22
|
}();
|
|
23
23
|
import React, { Component, Fragment } from 'react';
|
|
24
|
-
import classNames from 'classnames';
|
|
25
24
|
import { isEmptyArray, isUndef } from '@autobest-ui/utils';
|
|
26
25
|
import { RadioGroupContextProvider } from './context';
|
|
27
26
|
import Radio from './Radio';
|
|
@@ -96,12 +95,10 @@ var RadioGroup = /** @class */function (_super) {
|
|
|
96
95
|
return null;
|
|
97
96
|
};
|
|
98
97
|
RadioGroup.prototype.render = function () {
|
|
99
|
-
var _a = this.props,
|
|
100
|
-
|
|
101
|
-
direction = _b === void 0 ? 'horizontal' : _b,
|
|
102
|
-
className = _a.className;
|
|
98
|
+
var _a = this.props.direction,
|
|
99
|
+
direction = _a === void 0 ? 'horizontal' : _a;
|
|
103
100
|
return /*#__PURE__*/React.createElement("div", {
|
|
104
|
-
className:
|
|
101
|
+
className: "".concat(cls, "-group-").concat(direction)
|
|
105
102
|
}, 'options' in this.props ? this.renderRadioList() : this.renderRadioGroup());
|
|
106
103
|
};
|
|
107
104
|
return RadioGroup;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.ab-radio{position:relative;display:inline-flex;align-items:center;cursor:pointer}.ab-radio:hover .ab-radio-control{color:#4f4f4f}.ab-radio input{cursor:inherit;position:absolute;margin:0;padding:0;opacity:0;top:
|
|
1
|
+
.ab-radio{position:relative;overflow:hidden;display:inline-flex;align-items:center;cursor:pointer;font-size:.14rem}.ab-radio:hover .ab-radio-control{color:#4f4f4f}.ab-radio input{cursor:inherit;position:absolute;margin:0;padding:0;opacity:0;top:0;left:0;z-index:1}.ab-radio-checked:hover .ab-radio-control{color:#005cc8}.ab-radio-checked .ab-radio-control{color:#0075ff}.ab-radio-checked .ab-radio-control svg{display:inline-block}.ab-radio-disabled{cursor:not-allowed}.ab-radio-disabled .ab-radio-control,.ab-radio-disabled:hover .ab-radio-control{color:#d1d1d1}.ab-radio-control{margin-right:.06rem;position:relative;color:#767676}.ab-radio-control svg{width:1em;height:1em;user-select:none;flex-shrink:0;fill:currentcolor;stroke:currentcolor}.ab-radio-dot,.ab-radio-outer{position:absolute;left:0;top:0}.ab-radio-dot{display:none}.ab-radio-group-horizontal{display:flex}.ab-radio-group-horizontal .ab-radio-item{margin-right:.2rem}.ab-radio-group-horizontal .ab-radio-item:last-child{margin-right:0}.ab-radio-group-vertical{display:flex;flex-direction:column}.ab-radio-group-vertical .ab-radio-item{margin-bottom:.15rem}.ab-radio-group-vertical .ab-radio-item:last-child{margin-bottom:0}
|
package/esm/radio/type.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ReactChild } from 'react';
|
|
2
1
|
export declare type RadioValue = string | number;
|
|
3
2
|
export interface RadioProps {
|
|
4
3
|
name?: string;
|
|
@@ -9,7 +8,6 @@ export interface RadioProps {
|
|
|
9
8
|
size?: number;
|
|
10
9
|
onChange?: (value: RadioValue, name?: string, checked?: boolean) => void;
|
|
11
10
|
className?: string;
|
|
12
|
-
children?: ReactChild | ReactChild[];
|
|
13
11
|
}
|
|
14
12
|
export declare type RadioOptionItem = Pick<RadioProps, 'disabled' | 'name' | 'value'>;
|
|
15
13
|
export interface RadioGroupProps extends Pick<RadioProps, 'value' | 'name' | 'disabled' | 'className' | 'size'> {
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
export interface ReadMoreProps {
|
|
3
|
+
/**
|
|
4
|
+
* 需要显示的内容
|
|
5
|
+
*/
|
|
6
|
+
children: React.ReactChild[] | React.ReactChild;
|
|
7
|
+
/**
|
|
8
|
+
* 整体样式
|
|
9
|
+
*/
|
|
10
|
+
className?: string;
|
|
11
|
+
/**
|
|
12
|
+
* 需要忽略的类名数组,例如 ['mc_title']
|
|
13
|
+
*/
|
|
14
|
+
ignoreClassList?: string[];
|
|
15
|
+
/**
|
|
16
|
+
* 展开文本
|
|
17
|
+
*/
|
|
18
|
+
expandText?: string;
|
|
19
|
+
/**
|
|
20
|
+
* 折叠文本, 展开后点击收起的文字
|
|
21
|
+
*/
|
|
22
|
+
collapseText?: string;
|
|
23
|
+
/**
|
|
24
|
+
* 初始时,显示的行数
|
|
25
|
+
*/
|
|
26
|
+
lines?: number;
|
|
27
|
+
/**
|
|
28
|
+
* 是否执行resizeObserver监听宽度变化
|
|
29
|
+
*/
|
|
30
|
+
isResizeObserver?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 垂直方向触发换行的判定阈值 (默认 1px), 当一行中有字体,大小不同时,需要根据情况动态触发换行
|
|
33
|
+
*/
|
|
34
|
+
lineThreshold?: number;
|
|
35
|
+
/**
|
|
36
|
+
* [不推荐]设置Wrap最大高度, 用于解决初始化时页面抖动问题,建议通过屏幕大小动态设置className
|
|
37
|
+
*/
|
|
38
|
+
defaultWrapMaxHeight?: number;
|
|
39
|
+
/**
|
|
40
|
+
* 右下角按钮宽度
|
|
41
|
+
*/
|
|
42
|
+
buttonWidth?: number;
|
|
43
|
+
/**
|
|
44
|
+
* 默认是否折叠
|
|
45
|
+
*/
|
|
46
|
+
defaultCollapsed?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* 点击展开/收起前的回调函数,返回false时阻止change
|
|
49
|
+
*/
|
|
50
|
+
onBeforeChange?: (isCollapsed: boolean) => Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* 点击展开/收起后的回调函数
|
|
53
|
+
*/
|
|
54
|
+
onAfterChange?: (isCollapsed: boolean) => void;
|
|
55
|
+
}
|
|
56
|
+
interface ReadMoreState {
|
|
57
|
+
wrapStyle: React.CSSProperties;
|
|
58
|
+
}
|
|
59
|
+
declare class ReadMore extends Component<ReadMoreProps, ReadMoreState> {
|
|
60
|
+
static defaultProps: {
|
|
61
|
+
onAfterChange: () => void;
|
|
62
|
+
isResizeObserver: boolean;
|
|
63
|
+
defaultCollapsed: boolean;
|
|
64
|
+
expandText: string;
|
|
65
|
+
buttonWidth: number;
|
|
66
|
+
collapseText: string;
|
|
67
|
+
lineThreshold: number;
|
|
68
|
+
lines: number;
|
|
69
|
+
};
|
|
70
|
+
cacheWrapWidth: number;
|
|
71
|
+
isCollapsed: boolean;
|
|
72
|
+
resizeObserver: ResizeObserver;
|
|
73
|
+
originalContent: string;
|
|
74
|
+
wrapRef: React.RefObject<HTMLDivElement>;
|
|
75
|
+
prefixCls: string;
|
|
76
|
+
constructor(props: ReadMoreProps);
|
|
77
|
+
componentDidMount(): void;
|
|
78
|
+
componentDidUpdate(prevProps: ReadMoreProps): void;
|
|
79
|
+
componentWillUnmount(): void;
|
|
80
|
+
/**
|
|
81
|
+
* 计算高度并设置样式
|
|
82
|
+
*/
|
|
83
|
+
delayCalculate(): void;
|
|
84
|
+
/**
|
|
85
|
+
* 创建Show More/Show Less 按钮
|
|
86
|
+
*/
|
|
87
|
+
getButtonElement: (wrapElement: HTMLDivElement, isCollapsed: boolean) => HTMLSpanElement;
|
|
88
|
+
applyToggle: (wrapElement: HTMLDivElement, node: any, index: number) => void;
|
|
89
|
+
onResizeObserver: () => void;
|
|
90
|
+
render(): JSX.Element;
|
|
91
|
+
}
|
|
92
|
+
export default ReadMore;
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
var __extends = this && this.__extends || function () {
|
|
2
|
+
var _extendStatics = function extendStatics(d, b) {
|
|
3
|
+
_extendStatics = Object.setPrototypeOf || {
|
|
4
|
+
__proto__: []
|
|
5
|
+
} instanceof Array && function (d, b) {
|
|
6
|
+
d.__proto__ = b;
|
|
7
|
+
} || function (d, b) {
|
|
8
|
+
for (var p in b) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
return _extendStatics(d, b);
|
|
13
|
+
};
|
|
14
|
+
return function (d, b) {
|
|
15
|
+
if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
16
|
+
_extendStatics(d, b);
|
|
17
|
+
function __() {
|
|
18
|
+
this.constructor = d;
|
|
19
|
+
}
|
|
20
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
21
|
+
};
|
|
22
|
+
}();
|
|
23
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
24
|
+
function adopt(value) {
|
|
25
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
26
|
+
resolve(value);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
30
|
+
function fulfilled(value) {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function rejected(value) {
|
|
38
|
+
try {
|
|
39
|
+
step(generator["throw"](value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function step(result) {
|
|
45
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
46
|
+
}
|
|
47
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
var __generator = this && this.__generator || function (thisArg, body) {
|
|
51
|
+
var _ = {
|
|
52
|
+
label: 0,
|
|
53
|
+
sent: function sent() {
|
|
54
|
+
if (t[0] & 1) throw t[1];
|
|
55
|
+
return t[1];
|
|
56
|
+
},
|
|
57
|
+
trys: [],
|
|
58
|
+
ops: []
|
|
59
|
+
},
|
|
60
|
+
f,
|
|
61
|
+
y,
|
|
62
|
+
t,
|
|
63
|
+
g;
|
|
64
|
+
return g = {
|
|
65
|
+
next: verb(0),
|
|
66
|
+
"throw": verb(1),
|
|
67
|
+
"return": verb(2)
|
|
68
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
69
|
+
return this;
|
|
70
|
+
}), g;
|
|
71
|
+
function verb(n) {
|
|
72
|
+
return function (v) {
|
|
73
|
+
return step([n, v]);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function step(op) {
|
|
77
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
78
|
+
while (_) {
|
|
79
|
+
try {
|
|
80
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
81
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
82
|
+
switch (op[0]) {
|
|
83
|
+
case 0:
|
|
84
|
+
case 1:
|
|
85
|
+
t = op;
|
|
86
|
+
break;
|
|
87
|
+
case 4:
|
|
88
|
+
_.label++;
|
|
89
|
+
return {
|
|
90
|
+
value: op[1],
|
|
91
|
+
done: false
|
|
92
|
+
};
|
|
93
|
+
case 5:
|
|
94
|
+
_.label++;
|
|
95
|
+
y = op[1];
|
|
96
|
+
op = [0];
|
|
97
|
+
continue;
|
|
98
|
+
case 7:
|
|
99
|
+
op = _.ops.pop();
|
|
100
|
+
_.trys.pop();
|
|
101
|
+
continue;
|
|
102
|
+
default:
|
|
103
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
104
|
+
_ = 0;
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
108
|
+
_.label = op[1];
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
112
|
+
_.label = t[1];
|
|
113
|
+
t = op;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
if (t && _.label < t[2]) {
|
|
117
|
+
_.label = t[2];
|
|
118
|
+
_.ops.push(op);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
if (t[2]) _.ops.pop();
|
|
122
|
+
_.trys.pop();
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
op = body.call(thisArg, _);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
op = [6, e];
|
|
128
|
+
y = 0;
|
|
129
|
+
} finally {
|
|
130
|
+
f = t = 0;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (op[0] & 5) throw op[1];
|
|
134
|
+
return {
|
|
135
|
+
value: op[0] ? op[1] : void 0,
|
|
136
|
+
done: true
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
import React, { Component } from 'react';
|
|
141
|
+
import classNames from 'classnames';
|
|
142
|
+
import { debounce } from '@autobest-ui/utils';
|
|
143
|
+
var ReadMore = /** @class */function (_super) {
|
|
144
|
+
__extends(ReadMore, _super);
|
|
145
|
+
function ReadMore(props) {
|
|
146
|
+
var _this = _super.call(this, props) || this;
|
|
147
|
+
_this.wrapRef = /*#__PURE__*/React.createRef();
|
|
148
|
+
_this.prefixCls = 'ab-read-more';
|
|
149
|
+
/**
|
|
150
|
+
* 创建Show More/Show Less 按钮
|
|
151
|
+
*/
|
|
152
|
+
_this.getButtonElement = function (wrapElement, isCollapsed) {
|
|
153
|
+
var cls = _this.prefixCls;
|
|
154
|
+
var _a = _this.props,
|
|
155
|
+
collapseText = _a.collapseText,
|
|
156
|
+
expandText = _a.expandText;
|
|
157
|
+
var btn = document.createElement('span');
|
|
158
|
+
btn.setAttribute('data-collapse', collapseText);
|
|
159
|
+
btn.setAttribute('data-expand', expandText);
|
|
160
|
+
_this.isCollapsed = isCollapsed;
|
|
161
|
+
btn.className = "".concat(cls, "-btn ").concat(isCollapsed ? "".concat(cls, "-collapse") : "".concat(cls, "-expand"));
|
|
162
|
+
var self = _this;
|
|
163
|
+
btn.onclick = function () {
|
|
164
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
165
|
+
var _a;
|
|
166
|
+
return __generator(this, function (_b) {
|
|
167
|
+
switch (_b.label) {
|
|
168
|
+
case 0:
|
|
169
|
+
_a = self.props.onBeforeChange;
|
|
170
|
+
if (!_a) return [3 /*break*/, 2];
|
|
171
|
+
return [4 /*yield*/, self.props.onBeforeChange(!self.isCollapsed)];
|
|
172
|
+
case 1:
|
|
173
|
+
_a = !_b.sent();
|
|
174
|
+
_b.label = 2;
|
|
175
|
+
case 2:
|
|
176
|
+
if (_a) {
|
|
177
|
+
return [2 /*return*/];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (self.isCollapsed) {
|
|
181
|
+
self.isCollapsed = false;
|
|
182
|
+
btn.className = "".concat(cls, "-btn ").concat(cls, "-expand");
|
|
183
|
+
wrapElement.innerHTML = self.originalContent;
|
|
184
|
+
wrapElement.appendChild(btn);
|
|
185
|
+
} else {
|
|
186
|
+
self.isCollapsed = true;
|
|
187
|
+
wrapElement.innerHTML = self.originalContent;
|
|
188
|
+
self.delayCalculate();
|
|
189
|
+
}
|
|
190
|
+
if (self.props.onAfterChange) {
|
|
191
|
+
self.props.onAfterChange(self.isCollapsed);
|
|
192
|
+
}
|
|
193
|
+
return [2 /*return*/];
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
return btn;
|
|
200
|
+
};
|
|
201
|
+
_this.applyToggle = function (wrapElement, node, index) {
|
|
202
|
+
// 1. 将文本节点在 index 处切分为两个
|
|
203
|
+
var remainingTextNode = node.splitText(index);
|
|
204
|
+
// 2. 创建一个“隐藏层”容器
|
|
205
|
+
var hiddenWrapper = document.createElement('div');
|
|
206
|
+
hiddenWrapper.className = "".concat(_this.prefixCls, "-hidden");
|
|
207
|
+
// 3. 将截断点之后的所有兄弟节点(不限于文本,包括 HTML 标签)移入隐藏层
|
|
208
|
+
var nextSibling = remainingTextNode;
|
|
209
|
+
while (nextSibling) {
|
|
210
|
+
var current = nextSibling;
|
|
211
|
+
nextSibling = nextSibling.nextSibling;
|
|
212
|
+
hiddenWrapper.appendChild(current);
|
|
213
|
+
// appendChild 会将节点从原位置移动到 hiddenWrapper 中,而不销毁
|
|
214
|
+
}
|
|
215
|
+
// 同样需要递归移入父级元素之后的所有兄弟节点,确保彻底隐藏
|
|
216
|
+
var parent = node.parentNode;
|
|
217
|
+
while (parent && parent !== wrapElement) {
|
|
218
|
+
var sib = parent.nextSibling;
|
|
219
|
+
while (sib) {
|
|
220
|
+
var currentSib = sib;
|
|
221
|
+
sib = sib.nextSibling;
|
|
222
|
+
hiddenWrapper.appendChild(currentSib);
|
|
223
|
+
}
|
|
224
|
+
parent = parent.parentNode;
|
|
225
|
+
}
|
|
226
|
+
var buttonElement = _this.getButtonElement(wrapElement, true);
|
|
227
|
+
node.parentNode.insertBefore(buttonElement, node.nextSibling);
|
|
228
|
+
wrapElement.appendChild(hiddenWrapper);
|
|
229
|
+
_this.setState({
|
|
230
|
+
wrapStyle: {
|
|
231
|
+
maxHeight: 'none'
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
_this.onResizeObserver = function () {
|
|
236
|
+
var debounceCalculate = debounce(function (newWidth) {
|
|
237
|
+
if (newWidth !== _this.cacheWrapWidth) {
|
|
238
|
+
_this.cacheWrapWidth = newWidth;
|
|
239
|
+
_this.delayCalculate();
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
_this.resizeObserver = new ResizeObserver(function (entries) {
|
|
243
|
+
debounceCalculate(entries[0].contentRect.width);
|
|
244
|
+
});
|
|
245
|
+
_this.resizeObserver.observe(_this.wrapRef.current);
|
|
246
|
+
};
|
|
247
|
+
_this.isCollapsed = props.lines >= 1 && props.defaultCollapsed;
|
|
248
|
+
_this.state = {
|
|
249
|
+
wrapStyle: {
|
|
250
|
+
maxHeight: props.defaultWrapMaxHeight
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
return _this;
|
|
254
|
+
}
|
|
255
|
+
ReadMore.prototype.componentDidMount = function () {
|
|
256
|
+
var wrapElement = this.wrapRef.current;
|
|
257
|
+
if (!wrapElement) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
this.originalContent = wrapElement.innerHTML;
|
|
261
|
+
if (!this.isCollapsed) {
|
|
262
|
+
var buttonElement = this.getButtonElement(wrapElement, false);
|
|
263
|
+
wrapElement.appendChild(buttonElement);
|
|
264
|
+
this.setState({
|
|
265
|
+
wrapStyle: {
|
|
266
|
+
maxHeight: 'none'
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
this.delayCalculate();
|
|
271
|
+
if (this.props.isResizeObserver) {
|
|
272
|
+
this.onResizeObserver();
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
ReadMore.prototype.componentDidUpdate = function (prevProps) {
|
|
276
|
+
if (this.props.children !== prevProps.children || this.props.lines !== prevProps.lines) {
|
|
277
|
+
this.originalContent = this.wrapRef.current ? this.wrapRef.current.innerHTML : '';
|
|
278
|
+
// 执行render,并且跳过shouldComponentUpdate
|
|
279
|
+
this.delayCalculate();
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
ReadMore.prototype.componentWillUnmount = function () {
|
|
283
|
+
if (this.resizeObserver && this.wrapRef.current) {
|
|
284
|
+
this.resizeObserver.unobserve(this.wrapRef.current);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* 计算高度并设置样式
|
|
289
|
+
*/
|
|
290
|
+
ReadMore.prototype.delayCalculate = function () {
|
|
291
|
+
var wrapElement = this.wrapRef.current;
|
|
292
|
+
if (!this.isCollapsed || this.props.lines < 1 || !wrapElement || !document.createTreeWalker) {
|
|
293
|
+
this.setState({
|
|
294
|
+
wrapStyle: {
|
|
295
|
+
maxHeight: 'none'
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
var wrapRect = wrapElement.getBoundingClientRect();
|
|
301
|
+
this.cacheWrapWidth = wrapRect.width;
|
|
302
|
+
var _a = this.props,
|
|
303
|
+
ignoreClassList = _a.ignoreClassList,
|
|
304
|
+
lineThreshold = _a.lineThreshold,
|
|
305
|
+
lines = _a.lines,
|
|
306
|
+
buttonWidth = _a.buttonWidth;
|
|
307
|
+
// 将数组转换为选择器字符串: ".ignore-text1, .ignore-text2"
|
|
308
|
+
var ignoreSelector = (ignoreClassList || []).map(function (cls) {
|
|
309
|
+
return ".".concat(cls);
|
|
310
|
+
}).join(', ');
|
|
311
|
+
var range = document.createRange();
|
|
312
|
+
var treeWalker = document.createTreeWalker(wrapElement, NodeFilter.SHOW_TEXT, {
|
|
313
|
+
acceptNode: function acceptNode(node) {
|
|
314
|
+
// 如果 ignoreClassList 为空,或者当前节点不属于任何忽略名单,则接受
|
|
315
|
+
if (ignoreSelector && node.parentElement.closest(ignoreSelector)) {
|
|
316
|
+
return NodeFilter.FILTER_REJECT;
|
|
317
|
+
}
|
|
318
|
+
return NodeFilter.FILTER_ACCEPT;
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
var lineCount = 0;
|
|
322
|
+
var lastTop = -1;
|
|
323
|
+
var targetNode = null;
|
|
324
|
+
var splitIndex = 0;
|
|
325
|
+
// 1. 寻找第 targetLine 行的末尾空格位置
|
|
326
|
+
var node = null;
|
|
327
|
+
while (node = treeWalker.nextNode()) {
|
|
328
|
+
var text = node.textContent;
|
|
329
|
+
for (var i = 0; i < text.length; i++) {
|
|
330
|
+
range.setStart(node, i);
|
|
331
|
+
range.setEnd(node, i + 1);
|
|
332
|
+
var rect = range.getBoundingClientRect();
|
|
333
|
+
if (rect.height > 0) {
|
|
334
|
+
if (lastTop === -1 || Math.abs(rect.top - lastTop) > lineThreshold) {
|
|
335
|
+
lineCount++;
|
|
336
|
+
lastTop = rect.top;
|
|
337
|
+
}
|
|
338
|
+
// 仅在目标行寻找合适的截断点(空格且留够按钮位)
|
|
339
|
+
if (lineCount === lines) {
|
|
340
|
+
if ((text[i] === ' ' || text[i] === '\n') && wrapRect.right - rect.right > buttonWidth) {
|
|
341
|
+
targetNode = node;
|
|
342
|
+
splitIndex = i;
|
|
343
|
+
}
|
|
344
|
+
} else if (lineCount > lines) break;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (lineCount > lines) break;
|
|
348
|
+
}
|
|
349
|
+
if (targetNode) {
|
|
350
|
+
this.applyToggle(wrapElement, targetNode, splitIndex);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
ReadMore.prototype.render = function () {
|
|
354
|
+
var cls = this.prefixCls;
|
|
355
|
+
var _a = this.props,
|
|
356
|
+
className = _a.className,
|
|
357
|
+
children = _a.children;
|
|
358
|
+
var wrapStyle = this.state.wrapStyle;
|
|
359
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
360
|
+
ref: this.wrapRef,
|
|
361
|
+
style: wrapStyle,
|
|
362
|
+
className: classNames(cls, className)
|
|
363
|
+
}, children);
|
|
364
|
+
};
|
|
365
|
+
ReadMore.defaultProps = {
|
|
366
|
+
onAfterChange: function onAfterChange() {},
|
|
367
|
+
isResizeObserver: true,
|
|
368
|
+
defaultCollapsed: true,
|
|
369
|
+
expandText: 'Show Less',
|
|
370
|
+
buttonWidth: 75,
|
|
371
|
+
collapseText: '...Show More',
|
|
372
|
+
lineThreshold: 10,
|
|
373
|
+
lines: 2
|
|
374
|
+
};
|
|
375
|
+
return ReadMore;
|
|
376
|
+
}(Component);
|
|
377
|
+
export default ReadMore;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ab-read-more{overflow:hidden}.ab-read-more-hidden{display:none}.ab-read-more-collapse,.ab-read-more-expand{user-select:none}.ab-read-more-collapse::after,.ab-read-more-expand::after{color:#4068b0;cursor:pointer}.ab-read-more-collapse::after{content:" " attr(data-collapse)}.ab-read-more-expand::after{content:" " attr(data-expand)}
|