@arcblock/react-hooks 2.10.8 → 2.10.9
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/lib/useLineClamp.d.ts +2 -1
- package/lib/useLineClamp.js +5 -1
- package/package.json +2 -2
- package/src/useLineClamp.ts +5 -1
package/lib/useLineClamp.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ export default function useLineClamp({ text, ellipsis, lines, expanded, debounce
|
|
|
9
9
|
}): {
|
|
10
10
|
textRef: import("react").MutableRefObject<HTMLElement | null | undefined>;
|
|
11
11
|
buttonRef: import("react").MutableRefObject<HTMLElement | null | undefined>;
|
|
12
|
+
needClamp: boolean;
|
|
12
13
|
noClamp: boolean;
|
|
13
14
|
clampedText: string;
|
|
14
15
|
key: string;
|
|
15
|
-
run: (
|
|
16
|
+
run: () => void;
|
|
16
17
|
};
|
package/lib/useLineClamp.js
CHANGED
|
@@ -13,6 +13,7 @@ export default function useLineClamp({
|
|
|
13
13
|
offset = 1
|
|
14
14
|
}) {
|
|
15
15
|
const currentState = useReactive({
|
|
16
|
+
needClamp: true,
|
|
16
17
|
noClamp: false,
|
|
17
18
|
clampedText: "\u2026",
|
|
18
19
|
key: getNewKey()
|
|
@@ -54,6 +55,7 @@ export default function useLineClamp({
|
|
|
54
55
|
node.appendChild(button.cloneNode(true));
|
|
55
56
|
}
|
|
56
57
|
if (middle === originalText.length) {
|
|
58
|
+
currentState.needClamp = false;
|
|
57
59
|
currentState.noClamp = true;
|
|
58
60
|
currentState.clampedText = originalText;
|
|
59
61
|
currentState.key = getNewKey();
|
|
@@ -65,6 +67,7 @@ export default function useLineClamp({
|
|
|
65
67
|
node.innerText = clampedText;
|
|
66
68
|
if (button)
|
|
67
69
|
node.appendChild(button.cloneNode(true));
|
|
70
|
+
currentState.needClamp = true;
|
|
68
71
|
currentState.noClamp = false;
|
|
69
72
|
currentState.clampedText = clampedText;
|
|
70
73
|
currentState.key = getNewKey();
|
|
@@ -115,9 +118,10 @@ export default function useLineClamp({
|
|
|
115
118
|
return {
|
|
116
119
|
textRef,
|
|
117
120
|
buttonRef,
|
|
121
|
+
needClamp: currentState.needClamp,
|
|
118
122
|
noClamp: currentState.noClamp,
|
|
119
123
|
clampedText: currentState.clampedText,
|
|
120
124
|
key: currentState.key,
|
|
121
|
-
run:
|
|
125
|
+
run: resizeListener
|
|
122
126
|
};
|
|
123
127
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/react-hooks",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.9",
|
|
4
4
|
"description": "React hooks used by arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"jest": "^28.1.3",
|
|
47
47
|
"unbuild": "^2.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "9eccd40a20ce65bf32982abbf82f38d7e177b525"
|
|
50
50
|
}
|
package/src/useLineClamp.ts
CHANGED
|
@@ -28,6 +28,7 @@ export default function useLineClamp({
|
|
|
28
28
|
offset?: number;
|
|
29
29
|
}) {
|
|
30
30
|
const currentState = useReactive({
|
|
31
|
+
needClamp: true,
|
|
31
32
|
noClamp: false,
|
|
32
33
|
clampedText: '…',
|
|
33
34
|
key: getNewKey(),
|
|
@@ -77,6 +78,7 @@ export default function useLineClamp({
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
if (middle === originalText.length) {
|
|
81
|
+
currentState.needClamp = false;
|
|
80
82
|
currentState.noClamp = true;
|
|
81
83
|
currentState.clampedText = originalText;
|
|
82
84
|
currentState.key = getNewKey();
|
|
@@ -91,6 +93,7 @@ export default function useLineClamp({
|
|
|
91
93
|
node.innerText = clampedText;
|
|
92
94
|
if (button) node.appendChild(button.cloneNode(true));
|
|
93
95
|
|
|
96
|
+
currentState.needClamp = true;
|
|
94
97
|
currentState.noClamp = false;
|
|
95
98
|
currentState.clampedText = clampedText;
|
|
96
99
|
currentState.key = getNewKey();
|
|
@@ -144,9 +147,10 @@ export default function useLineClamp({
|
|
|
144
147
|
return {
|
|
145
148
|
textRef,
|
|
146
149
|
buttonRef,
|
|
150
|
+
needClamp: currentState.needClamp,
|
|
147
151
|
noClamp: currentState.noClamp,
|
|
148
152
|
clampedText: currentState.clampedText,
|
|
149
153
|
key: currentState.key,
|
|
150
|
-
run:
|
|
154
|
+
run: resizeListener,
|
|
151
155
|
};
|
|
152
156
|
}
|