@fabianactor/dsh-lil-whale-group-ui 1.8.12 → 1.8.15
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/client.js +34 -5
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -1809,6 +1809,9 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
1809
1809
|
// 翻历史时记住"眼睛在哪":内容一变(新消息、渲染窗口挪动)就把 scrollTop 放回去。
|
|
1810
1810
|
// 2026-11-16 报的闪烁:历史态收到新消息,视觉上先弹到底再弹回来。
|
|
1811
1811
|
const historyTopRef = useRef(-1)
|
|
1812
|
+
// 平滑滚动的截止时刻:这段时间里浏览器自己在动 scrollTop,
|
|
1813
|
+
// 位置记录与"把眼睛放回去"都该让路,否则两边各推一把,会滚一半停住。
|
|
1814
|
+
const smoothScrollRef = useRef(0)
|
|
1812
1815
|
const messagesLenRef = useRef(0)
|
|
1813
1816
|
const pendingScrollRef = useRef(null)
|
|
1814
1817
|
const pendingHistoryRef = useRef(null)
|
|
@@ -1823,6 +1826,17 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
1823
1826
|
const historyVisitedRef = useRef(false)
|
|
1824
1827
|
const [historyAbove, setHistoryAbove] = useState(false)
|
|
1825
1828
|
// 线是不是在视口上方 —— 只回答这一件事,不回答"该不该显示"。
|
|
1829
|
+
const smoothTo = useCallback((el, top) => {
|
|
1830
|
+
const until = Date.now() + 1500
|
|
1831
|
+
smoothScrollRef.current = until
|
|
1832
|
+
el.scrollTo({ top: Math.max(0, top), behavior: 'smooth' })
|
|
1833
|
+
// 没有 scrollend 的浏览器(老版本):到点自己收尾,别让"让路"一直开着。
|
|
1834
|
+
window.setTimeout(() => {
|
|
1835
|
+
if (smoothScrollRef.current !== until) return
|
|
1836
|
+
smoothScrollRef.current = 0
|
|
1837
|
+
historyTopRef.current = (el.scrollHeight - el.scrollTop - el.clientHeight > 40) ? el.scrollTop : -1
|
|
1838
|
+
}, 1600)
|
|
1839
|
+
}, [])
|
|
1826
1840
|
const measureHistory = useCallback(() => {
|
|
1827
1841
|
const el = scrollRef.current
|
|
1828
1842
|
const line = dividerRef.current
|
|
@@ -1844,7 +1858,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
1844
1858
|
const line = dividerRef.current
|
|
1845
1859
|
if (line) {
|
|
1846
1860
|
const top = line.getBoundingClientRect().top - el.getBoundingClientRect().top + el.scrollTop - 8
|
|
1847
|
-
el
|
|
1861
|
+
smoothTo(el, top)
|
|
1848
1862
|
return
|
|
1849
1863
|
}
|
|
1850
1864
|
// 线不在当前窗口里(消息多、只挂了最近 N 条):先把窗口扩到线那里,渲染完再滚。
|
|
@@ -1856,7 +1870,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
1856
1870
|
return
|
|
1857
1871
|
}
|
|
1858
1872
|
// 没有线(没有新消息)就跳到最早的一条:两种情况下这个按钮都得做事。
|
|
1859
|
-
el
|
|
1873
|
+
smoothTo(el, 0)
|
|
1860
1874
|
}, [messages])
|
|
1861
1875
|
|
|
1862
1876
|
const refresh = useCallback(async () => {
|
|
@@ -1963,7 +1977,7 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
1963
1977
|
const line = dividerRef.current
|
|
1964
1978
|
if (line && el) {
|
|
1965
1979
|
const top = line.getBoundingClientRect().top - el.getBoundingClientRect().top + el.scrollTop - 8
|
|
1966
|
-
el
|
|
1980
|
+
smoothTo(el, top)
|
|
1967
1981
|
}
|
|
1968
1982
|
}
|
|
1969
1983
|
}, [renderLimit])
|
|
@@ -1974,6 +1988,8 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
1974
1988
|
const el = scrollRef.current
|
|
1975
1989
|
// 「加载更早」「跳历史线」自带位置补偿,这里让路,免得两头各推一把。
|
|
1976
1990
|
if (pendingScrollRef.current || pendingHistoryRef.current) return
|
|
1991
|
+
// 平滑滚动进行中:scrollTop 由浏览器接管,这里插手就会把它拽回来。
|
|
1992
|
+
if (Date.now() < smoothScrollRef.current) return
|
|
1977
1993
|
if (atBottom || !el || historyTopRef.current < 0) return
|
|
1978
1994
|
if (Math.abs(el.scrollTop - historyTopRef.current) > 1) el.scrollTop = historyTopRef.current
|
|
1979
1995
|
}, [messages.length, renderLimit, atBottom])
|
|
@@ -2010,6 +2026,17 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
2010
2026
|
}, [messages, atBottom, tab])
|
|
2011
2027
|
useEffect(() => { if (atBottom) setNewBelow(0) }, [atBottom])
|
|
2012
2028
|
// 线一旦挂上来就要立刻量:只靠 scroll 事件的话,进页面时的第一帧量不到。
|
|
2029
|
+
useEffect(() => {
|
|
2030
|
+
const el = scrollRef.current
|
|
2031
|
+
if (!el) return undefined
|
|
2032
|
+
const done = () => {
|
|
2033
|
+
smoothScrollRef.current = 0
|
|
2034
|
+
historyTopRef.current = (el.scrollHeight - el.scrollTop - el.clientHeight > 40) ? el.scrollTop : -1
|
|
2035
|
+
}
|
|
2036
|
+
el.addEventListener('scrollend', done)
|
|
2037
|
+
return () => el.removeEventListener('scrollend', done)
|
|
2038
|
+
}, [])
|
|
2039
|
+
|
|
2013
2040
|
useEffect(() => { measureHistory() })
|
|
2014
2041
|
|
|
2015
2042
|
const persistWidth = useCallback(() => {
|
|
@@ -2264,8 +2291,10 @@ const Bubble = React.memo(function Bubble({ config, message, onMention, animate
|
|
|
2264
2291
|
onScroll: () => {
|
|
2265
2292
|
const el = scrollRef.current
|
|
2266
2293
|
if (el) {
|
|
2267
|
-
//
|
|
2268
|
-
|
|
2294
|
+
// 平滑滚动进行中:这几帧的 scrollTop 是半路值,记下来会把目标位置带偏。
|
|
2295
|
+
if (Date.now() >= smoothScrollRef.current) {
|
|
2296
|
+
historyTopRef.current = (el.scrollHeight - el.scrollTop - el.clientHeight > 40) ? el.scrollTop : -1
|
|
2297
|
+
}
|
|
2269
2298
|
}
|
|
2270
2299
|
measureBottom()
|
|
2271
2300
|
measureHistory()
|