@easyv/biz-components 0.0.7 → 0.0.8
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/dist/components/ScrollController/ScrollController.d.ts +11 -0
- package/dist/components/ScrollController/ScrollController.es.js +42 -0
- package/dist/components/ScrollController/ScrollController.es.js.map +1 -0
- package/dist/components/ScrollController/index.d.ts +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useDivAutoScroll.d.ts +9 -0
- package/dist/hooks/useDivAutoScroll.es.js +28 -0
- package/dist/hooks/useDivAutoScroll.es.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +8 -4
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
interface ScrollControllerProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
containerHeight?: string;
|
|
6
|
+
scrollBuffer?: number;
|
|
7
|
+
scrollBehavior?: 'auto' | 'smooth';
|
|
8
|
+
className?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function ScrollController(props: ScrollControllerProps): JSX.Element;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { j as v } from "../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.es.js";
|
|
2
|
+
import { useState as E, useRef as l, useCallback as s, useEffect as S } from "react";
|
|
3
|
+
function R(d) {
|
|
4
|
+
const {
|
|
5
|
+
children: i,
|
|
6
|
+
containerHeight: p = "100%",
|
|
7
|
+
scrollBuffer: u = 50,
|
|
8
|
+
scrollBehavior: o = "smooth",
|
|
9
|
+
className: g
|
|
10
|
+
} = d, [a, f] = E(!0), r = l(null), t = l(!1), n = l(), h = s(() => {
|
|
11
|
+
if (!r.current) return !1;
|
|
12
|
+
const { scrollHeight: e, scrollTop: T, clientHeight: j } = r.current;
|
|
13
|
+
return e - T - j < u;
|
|
14
|
+
}, [u]), m = s(() => {
|
|
15
|
+
a && r.current && r.current.scrollTo({
|
|
16
|
+
top: r.current.scrollHeight,
|
|
17
|
+
behavior: o
|
|
18
|
+
});
|
|
19
|
+
}, [a, o]), c = s(() => {
|
|
20
|
+
r.current && (n.current && clearTimeout(n.current), t.current || (t.current = !0), n.current = setTimeout(() => {
|
|
21
|
+
t.current = !1;
|
|
22
|
+
}, 100), h() ? f(!0) : f(!1));
|
|
23
|
+
}, [h]);
|
|
24
|
+
S(() => {
|
|
25
|
+
const e = r.current;
|
|
26
|
+
if (e)
|
|
27
|
+
return e.addEventListener("scroll", c), () => e.removeEventListener("scroll", c);
|
|
28
|
+
}, [c]), S(() => {
|
|
29
|
+
t.current || m();
|
|
30
|
+
}, [i, m]);
|
|
31
|
+
const x = {
|
|
32
|
+
height: p,
|
|
33
|
+
overflowY: "auto",
|
|
34
|
+
scrollBehavior: o,
|
|
35
|
+
position: "relative"
|
|
36
|
+
};
|
|
37
|
+
return /* @__PURE__ */ v.jsx("div", { ref: r, style: x, className: g, children: /* @__PURE__ */ v.jsx("div", { children: i }) });
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
R as ScrollController
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=ScrollController.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ScrollController.es.js","sources":["../../../src/components/ScrollController/ScrollController.tsx"],"sourcesContent":["import React, { CSSProperties, ReactNode, useCallback, useEffect, useRef, useState } from 'react';\n\ninterface ScrollControllerProps {\n children: ReactNode;\n containerHeight?: string;\n scrollBuffer?: number;\n scrollBehavior?: 'auto' | 'smooth';\n className?: string;\n}\n\nexport function ScrollController(props: ScrollControllerProps) {\n const {\n children,\n containerHeight = '100%',\n scrollBuffer = 50,\n scrollBehavior = 'smooth',\n className,\n } = props;\n const [isAutoScroll, setIsAutoScroll] = useState(true);\n const containerRef = useRef<HTMLDivElement>(null);\n const isUserScrolling = useRef(false);\n const scrollTimeout = useRef<NodeJS.Timeout>();\n\n // 检测是否接近底部\n const isNearBottom = useCallback(() => {\n if (!containerRef.current) return false;\n const { scrollHeight, scrollTop, clientHeight } = containerRef.current;\n return scrollHeight - scrollTop - clientHeight < scrollBuffer;\n }, [scrollBuffer]);\n\n // 自动滚动逻辑\n const autoScroll = useCallback(() => {\n if (isAutoScroll && containerRef.current) {\n containerRef.current.scrollTo({\n top: containerRef.current.scrollHeight,\n behavior: scrollBehavior,\n });\n }\n }, [isAutoScroll, scrollBehavior]);\n\n // 处理滚动事件\n const handleScroll = useCallback(() => {\n if (!containerRef.current) return;\n\n // 清除之前的定时器\n if (scrollTimeout.current) clearTimeout(scrollTimeout.current);\n\n // 标记用户滚动行为\n if (!isUserScrolling.current) {\n isUserScrolling.current = true;\n }\n\n // 设置滚动状态重置\n scrollTimeout.current = setTimeout(() => {\n isUserScrolling.current = false;\n }, 100);\n\n // 判断是否接近底部\n if (isNearBottom()) {\n setIsAutoScroll(true);\n } else {\n setIsAutoScroll(false);\n }\n }, [isNearBottom]);\n\n // 初始化事件监听\n useEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n\n container.addEventListener('scroll', handleScroll);\n return () => container.removeEventListener('scroll', handleScroll);\n }, [handleScroll]);\n\n // 内容变化时自动滚动\n useEffect(() => {\n if (!isUserScrolling.current) {\n autoScroll();\n }\n }, [children, autoScroll]);\n\n // 容器样式\n const containerStyle: CSSProperties = {\n height: containerHeight,\n overflowY: 'auto',\n scrollBehavior: scrollBehavior,\n position: 'relative',\n };\n\n return (\n <div ref={containerRef} style={containerStyle} className={className}>\n <div>{children}</div>\n </div>\n );\n}\n"],"names":["ScrollController","props","children","containerHeight","scrollBuffer","scrollBehavior","className","isAutoScroll","setIsAutoScroll","useState","containerRef","useRef","isUserScrolling","scrollTimeout","isNearBottom","useCallback","scrollHeight","scrollTop","clientHeight","autoScroll","handleScroll","useEffect","container","containerStyle","jsx"],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GACC,CAACjB,GAAUiB,CAAU,CAAC;AAGzB,QAAMI,IAAgC;AAAA,IACpC,QAAQpB;AAAA,IACR,WAAW;AAAA,IACX,gBAAAE;AAAA,IACA,UAAU;AAAA,EACZ;AAGE,SAAAmB,gBAAAA,EAAA,IAAC,OAAI,EAAA,KAAKd,GAAc,OAAOa,GAAgB,WAAAjB,GAC7C,UAAAkB,gBAAAA,EAAAA,IAAC,OAAK,EAAA,UAAAtB,EAAA,CAAS,EACjB,CAAA;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ScrollController } from './ScrollController';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useDivAutoScroll';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
|
|
3
|
+
interface ScrollControllerProps {
|
|
4
|
+
scrollBuffer?: number;
|
|
5
|
+
scrollBehavior?: 'auto' | 'smooth';
|
|
6
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
7
|
+
}
|
|
8
|
+
export declare function useDivAutoScroll(params: ScrollControllerProps): () => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState as v, useRef as S, useCallback as o, useEffect as A } from "react";
|
|
2
|
+
function d(g) {
|
|
3
|
+
const { scrollBuffer: n = 50, scrollBehavior: s = "smooth", containerRef: r } = g, [u, i] = v(!0), e = S(!1), c = S(), f = o(() => {
|
|
4
|
+
if (!r.current) return !1;
|
|
5
|
+
const { scrollHeight: t, scrollTop: m, clientHeight: h } = r.current;
|
|
6
|
+
return t - m - h < n;
|
|
7
|
+
}, [r, n]), a = o(() => {
|
|
8
|
+
u && r.current && r.current.scrollTo({
|
|
9
|
+
top: r.current.scrollHeight,
|
|
10
|
+
behavior: s
|
|
11
|
+
});
|
|
12
|
+
}, [r, u, s]), l = o(() => {
|
|
13
|
+
r.current && (c.current && clearTimeout(c.current), e.current || (e.current = !0), c.current = setTimeout(() => {
|
|
14
|
+
e.current = !1;
|
|
15
|
+
}, 100), f() ? i(!0) : i(!1));
|
|
16
|
+
}, [r, f]);
|
|
17
|
+
return A(() => {
|
|
18
|
+
const t = r.current;
|
|
19
|
+
if (t)
|
|
20
|
+
return t.addEventListener("scroll", l), () => t.removeEventListener("scroll", l);
|
|
21
|
+
}, [r, l]), o(() => {
|
|
22
|
+
e.current || a();
|
|
23
|
+
}, [a, e]);
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
d as useDivAutoScroll
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=useDivAutoScroll.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDivAutoScroll.es.js","sources":["../../src/hooks/useDivAutoScroll.ts"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\n\ninterface ScrollControllerProps {\n scrollBuffer?: number;\n scrollBehavior?: 'auto' | 'smooth';\n containerRef: React.RefObject<HTMLDivElement | null>;\n}\n\nexport function useDivAutoScroll(params: ScrollControllerProps) {\n const { scrollBuffer = 50, scrollBehavior = 'smooth', containerRef } = params;\n const [isAutoScroll, setIsAutoScroll] = useState(true);\n const isUserScrolling = useRef(false);\n const scrollTimeout = useRef<NodeJS.Timeout>();\n\n // 检测是否接近底部\n const isNearBottom = useCallback(() => {\n if (!containerRef.current) return false;\n const { scrollHeight, scrollTop, clientHeight } = containerRef.current;\n return scrollHeight - scrollTop - clientHeight < scrollBuffer;\n }, [containerRef, scrollBuffer]);\n\n // 自动滚动逻辑\n const autoScroll = useCallback(() => {\n if (isAutoScroll && containerRef.current) {\n containerRef.current.scrollTo({\n top: containerRef.current.scrollHeight,\n behavior: scrollBehavior,\n });\n }\n }, [containerRef, isAutoScroll, scrollBehavior]);\n\n // 处理滚动事件\n const handleScroll = useCallback(() => {\n if (!containerRef.current) return;\n\n // 清除之前的定时器\n if (scrollTimeout.current) clearTimeout(scrollTimeout.current);\n\n // 标记用户滚动行为\n if (!isUserScrolling.current) {\n isUserScrolling.current = true;\n }\n\n // 设置滚动状态重置\n scrollTimeout.current = setTimeout(() => {\n isUserScrolling.current = false;\n }, 100);\n\n // 判断是否接近底部\n if (isNearBottom()) {\n setIsAutoScroll(true);\n } else {\n setIsAutoScroll(false);\n }\n }, [containerRef, isNearBottom]);\n\n // 初始化事件监听\n useEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n\n container.addEventListener('scroll', handleScroll);\n return () => container.removeEventListener('scroll', handleScroll);\n }, [containerRef, handleScroll]);\n\n // 内容变化时自动滚动\n const triggerAutoScroll = useCallback(() => {\n if (!isUserScrolling.current) {\n autoScroll();\n }\n }, [autoScroll, isUserScrolling]);\n\n return triggerAutoScroll;\n}\n"],"names":["useDivAutoScroll","params","scrollBuffer","scrollBehavior","containerRef","isAutoScroll","setIsAutoScroll","useState","isUserScrolling","useRef","scrollTimeout","isNearBottom","useCallback","scrollHeight","scrollTop","clientHeight","autoScroll","handleScroll","useEffect","container"],"mappings":";AAQO,SAASA,EAAiBC,GAA+B;AAC9D,QAAM,EAAE,cAAAC,IAAe,IAAI,gBAAAC,IAAiB,UAAU,cAAAC,MAAiBH,GACjE,CAACI,GAAcC,CAAe,IAAIC,EAAS,EAAI,GAC/CC,IAAkBC,EAAO,EAAK,GAC9BC,IAAgBD,EAAuB,GAGvCE,IAAeC,EAAY,MAAM;AACjC,QAAA,CAACR,EAAa,QAAgB,QAAA;AAClC,UAAM,EAAE,cAAAS,GAAc,WAAAC,GAAW,cAAAC,MAAiBX,EAAa;AACxD,WAAAS,IAAeC,IAAYC,IAAeb;AAAA,EAAA,GAChD,CAACE,GAAcF,CAAY,CAAC,GAGzBc,IAAaJ,EAAY,MAAM;AAC/B,IAAAP,KAAgBD,EAAa,WAC/BA,EAAa,QAAQ,SAAS;AAAA,MAC5B,KAAKA,EAAa,QAAQ;AAAA,MAC1B,UAAUD;AAAA,IAAA,CACX;AAAA,EAEF,GAAA,CAACC,GAAcC,GAAcF,CAAc,CAAC,GAGzCc,IAAeL,EAAY,MAAM;AACjC,IAACR,EAAa,YAGdM,EAAc,WAAsB,aAAAA,EAAc,OAAO,GAGxDF,EAAgB,YACnBA,EAAgB,UAAU,KAIdE,EAAA,UAAU,WAAW,MAAM;AACvC,MAAAF,EAAgB,UAAU;AAAA,OACzB,GAAG,GAGFG,MACFL,EAAgB,EAAI,IAEpBA,EAAgB,EAAK;AAAA,EACvB,GACC,CAACF,GAAcO,CAAY,CAAC;AAG/B,SAAAO,EAAU,MAAM;AACd,UAAMC,IAAYf,EAAa;AAC/B,QAAKe;AAEK,aAAAA,EAAA,iBAAiB,UAAUF,CAAY,GAC1C,MAAME,EAAU,oBAAoB,UAAUF,CAAY;AAAA,EAAA,GAChE,CAACb,GAAca,CAAY,CAAC,GAGLL,EAAY,MAAM;AACtC,IAACJ,EAAgB,WACRQ,EAAA;AAAA,EACb,GACC,CAACA,GAAYR,CAAe,CAAC;AAGlC;"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.es.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { AiMessageRender as
|
|
2
|
-
import { ShadowDom as
|
|
1
|
+
import { AiMessageRender as e } from "./components/AiMessageRender/AiMessageRender.es.js";
|
|
2
|
+
import { ShadowDom as t } from "./components/ShadowDom/ShadowDom.es.js";
|
|
3
|
+
import { ScrollController as f } from "./components/ScrollController/ScrollController.es.js";
|
|
4
|
+
import { useDivAutoScroll as x } from "./hooks/useDivAutoScroll.es.js";
|
|
3
5
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
e as AiMessageRender,
|
|
7
|
+
f as ScrollController,
|
|
8
|
+
t as ShadowDom,
|
|
9
|
+
x as useDivAutoScroll
|
|
6
10
|
};
|
|
7
11
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|