@rolder/kit 3.0.0-alpha.17 → 3.0.0-alpha.18
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/ai/index.d.ts +2 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/ui/conversation/ConversationContext.d.ts +7 -0
- package/dist/ai/ui/conversation/ConversationContext.js +8 -0
- package/dist/ai/ui/conversation/ConversationProvider.d.ts +2 -0
- package/dist/ai/ui/conversation/ConversationProvider.js +14 -0
- package/dist/ai/ui/conversation/Empty.d.ts +1 -0
- package/dist/ai/ui/conversation/Empty.js +21 -0
- package/dist/ai/ui/conversation/File.d.ts +4 -0
- package/dist/ai/ui/conversation/File.js +42 -0
- package/dist/ai/ui/conversation/FileIcon.d.ts +3 -0
- package/dist/ai/ui/conversation/FileIcon.js +43 -0
- package/dist/ai/ui/conversation/Loader.d.ts +2 -0
- package/dist/ai/ui/conversation/Loader.js +12 -0
- package/dist/ai/ui/conversation/Message.d.ts +4 -0
- package/dist/ai/ui/conversation/Message.js +25 -0
- package/dist/ai/ui/conversation/Root.d.ts +2 -0
- package/dist/ai/ui/conversation/Root.js +26 -0
- package/dist/ai/ui/conversation/index.d.ts +13 -0
- package/dist/ai/ui/conversation/index.js +15 -0
- package/dist/ai/ui/conversation/types.d.ts +7 -0
- package/dist/ai/ui/conversation/types.js +0 -0
- package/dist/ai/ui/conversation/useChatMessage.d.ts +2 -0
- package/dist/ai/ui/conversation/useChatMessage.js +12 -0
- package/dist/ai/ui/index.d.ts +2 -0
- package/dist/ai/ui/index.js +2 -0
- package/dist/ai/ui/promptInput/File.d.ts +2 -0
- package/dist/ai/ui/promptInput/File.js +68 -0
- package/dist/ai/ui/promptInput/FileIcon.d.ts +3 -0
- package/dist/ai/ui/promptInput/FileIcon.js +43 -0
- package/dist/ai/ui/promptInput/Footer.d.ts +2 -0
- package/dist/ai/ui/promptInput/Footer.js +8 -0
- package/dist/ai/ui/promptInput/PromptInputContext.d.ts +12 -0
- package/dist/ai/ui/promptInput/PromptInputContext.js +8 -0
- package/dist/ai/ui/promptInput/PromptInputProvider.d.ts +2 -0
- package/dist/ai/ui/promptInput/PromptInputProvider.js +50 -0
- package/dist/ai/ui/promptInput/Root.d.ts +3 -0
- package/dist/ai/ui/promptInput/Root.js +17 -0
- package/dist/ai/ui/promptInput/Submit.d.ts +2 -0
- package/dist/ai/ui/promptInput/Submit.js +21 -0
- package/dist/ai/ui/promptInput/Textarea.d.ts +2 -0
- package/dist/ai/ui/promptInput/Textarea.js +33 -0
- package/dist/ai/ui/promptInput/index.d.ts +8 -0
- package/dist/ai/ui/promptInput/index.js +14 -0
- package/dist/ai/ui/promptInput/types.d.ts +11 -0
- package/dist/ai/ui/promptInput/types.js +0 -0
- package/dist/ai/utils/convertFileUIPartBlobToDataURL.d.ts +5 -0
- package/dist/ai/utils/convertFileUIPartBlobToDataURL.js +21 -0
- package/dist/ai/utils/index.d.ts +2 -0
- package/dist/ai/utils/index.js +2 -0
- package/dist/ai/utils/parseAiMessagePart.d.ts +2 -0
- package/dist/ai/utils/parseAiMessagePart.js +12 -0
- package/dist/app/defaultTheme.d.ts +1 -1
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/useMutation.d.ts +4 -0
- package/dist/hooks/useMutation.js +8 -0
- package/dist/hooks/useMutationWithInvalidate.d.ts +4 -0
- package/dist/hooks/useMutationWithInvalidate.js +16 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/styles.css +74 -0
- package/dist/ui/AnimatedChevron.d.ts +6 -0
- package/dist/ui/AnimatedChevron.js +13 -0
- package/dist/ui/JsonInput.d.ts +2 -0
- package/dist/ui/JsonInput.js +45 -0
- package/dist/ui/RouterLink.d.ts +16 -0
- package/dist/ui/RouterLink.js +36 -0
- package/dist/ui/editor/Content.d.ts +3 -0
- package/dist/ui/editor/Content.js +13 -0
- package/dist/ui/editor/Provider.d.ts +17 -0
- package/dist/ui/editor/Provider.js +80 -0
- package/dist/ui/editor/Root.d.ts +2 -0
- package/dist/ui/editor/Root.js +18 -0
- package/dist/ui/editor/Toolbar.d.ts +5 -0
- package/dist/ui/editor/Toolbar.js +138 -0
- package/dist/ui/editor/index.d.ts +12 -0
- package/dist/ui/editor/index.js +11 -0
- package/dist/ui/editor/types.d.ts +7 -0
- package/dist/ui/editor/types.js +0 -0
- package/dist/ui/error/DefaultError.d.ts +2 -0
- package/dist/ui/error/DefaultError.js +62 -0
- package/dist/ui/error/DefaultNotFound.d.ts +1 -0
- package/dist/ui/error/DefaultNotFound.js +37 -0
- package/dist/ui/error/Forbidden.d.ts +1 -0
- package/dist/ui/error/Forbidden.js +32 -0
- package/dist/ui/error/defaultErrorNotification.d.ts +1 -0
- package/dist/ui/error/defaultErrorNotification.js +8 -0
- package/dist/ui/error/index.d.ts +4 -0
- package/dist/ui/error/index.js +5 -0
- package/dist/ui/form/blurOnError.d.ts +4 -0
- package/dist/ui/form/blurOnError.js +11 -0
- package/dist/ui/form/buttons/CancelButton.d.ts +5 -0
- package/dist/ui/form/buttons/CancelButton.js +22 -0
- package/dist/ui/form/buttons/SubmitButton.d.ts +5 -0
- package/dist/ui/form/buttons/SubmitButton.js +22 -0
- package/dist/ui/form/buttons/SubscribeActionIcon.d.ts +4 -0
- package/dist/ui/form/buttons/SubscribeActionIcon.js +15 -0
- package/dist/ui/form/buttons/SubscribeButton.d.ts +5 -0
- package/dist/ui/form/buttons/SubscribeButton.js +16 -0
- package/dist/ui/form/buttons/index.d.ts +4 -0
- package/dist/ui/form/buttons/index.js +4 -0
- package/dist/ui/form/context.d.ts +83 -0
- package/dist/ui/form/context.js +26 -0
- package/dist/ui/form/fields/JsonField.d.ts +2 -0
- package/dist/ui/form/fields/JsonField.js +13 -0
- package/dist/ui/form/fields/MultiSelectField.d.ts +2 -0
- package/dist/ui/form/fields/MultiSelectField.js +15 -0
- package/dist/ui/form/fields/NumberField.d.ts +2 -0
- package/dist/ui/form/fields/NumberField.js +15 -0
- package/dist/ui/form/fields/PassowrdField.d.ts +2 -0
- package/dist/ui/form/fields/PassowrdField.js +18 -0
- package/dist/ui/form/fields/SelectField.d.ts +2 -0
- package/dist/ui/form/fields/SelectField.js +15 -0
- package/dist/ui/form/fields/SwitchField.d.ts +2 -0
- package/dist/ui/form/fields/SwitchField.js +15 -0
- package/dist/ui/form/fields/TextField.d.ts +2 -0
- package/dist/ui/form/fields/TextField.js +15 -0
- package/dist/ui/form/fields/TextPassowrdField.d.ts +2 -0
- package/dist/ui/form/fields/TextPassowrdField.js +29 -0
- package/dist/ui/form/fields/TextareaField.d.ts +2 -0
- package/dist/ui/form/fields/TextareaField.js +15 -0
- package/dist/ui/form/fields/index.d.ts +9 -0
- package/dist/ui/form/fields/index.js +9 -0
- package/dist/ui/form/fieldsSchema.d.ts +12 -0
- package/dist/ui/form/fieldsSchema.js +13 -0
- package/dist/ui/form/index.d.ts +3 -0
- package/dist/ui/form/index.js +4 -0
- package/dist/ui/hoverPaper/HoverPaper.d.ts +6 -0
- package/dist/ui/hoverPaper/HoverPaper.js +15 -0
- package/dist/ui/hoverPaper/index.d.ts +2 -0
- package/dist/ui/hoverPaper/index.js +3 -0
- package/dist/ui/hoverPaper/usePaperHover.d.ts +4 -0
- package/dist/ui/hoverPaper/usePaperHover.js +9 -0
- package/dist/ui/index.d.ts +9 -0
- package/dist/ui/index.js +9 -0
- package/dist/ui/saveInput/JsonInput.d.ts +6 -0
- package/dist/ui/saveInput/JsonInput.js +34 -0
- package/dist/ui/saveInput/NumberInput.d.ts +6 -0
- package/dist/ui/saveInput/NumberInput.js +27 -0
- package/dist/ui/saveInput/SaveInput.d.ts +36 -0
- package/dist/ui/saveInput/SaveInput.js +15 -0
- package/dist/ui/saveInput/Select.d.ts +6 -0
- package/dist/ui/saveInput/Select.js +27 -0
- package/dist/ui/saveInput/Switch.d.ts +6 -0
- package/dist/ui/saveInput/Switch.js +30 -0
- package/dist/ui/saveInput/TextInput.d.ts +6 -0
- package/dist/ui/saveInput/TextInput.js +26 -0
- package/dist/ui/saveInput/Textarea.d.ts +6 -0
- package/dist/ui/saveInput/Textarea.js +26 -0
- package/dist/ui/saveInput/index.d.ts +1 -0
- package/dist/ui/saveInput/index.js +2 -0
- package/dist/ui/scrollArea/ScrollArea.d.ts +62 -0
- package/dist/ui/scrollArea/ScrollArea.js +30 -0
- package/dist/ui/scrollArea/ScrollAreaButton.d.ts +5 -0
- package/dist/ui/scrollArea/ScrollAreaButton.js +30 -0
- package/dist/ui/scrollArea/ScrollAreaContent.d.ts +6 -0
- package/dist/ui/scrollArea/ScrollAreaContent.js +29 -0
- package/dist/ui/scrollArea/context.d.ts +28 -0
- package/dist/ui/scrollArea/context.js +10 -0
- package/dist/ui/scrollArea/index.d.ts +3 -0
- package/dist/ui/scrollArea/index.js +3 -0
- package/dist/ui/scrollArea/types.d.ts +65 -0
- package/dist/ui/scrollArea/types.js +0 -0
- package/dist/ui/scrollArea/useScrollArea.d.ts +9 -0
- package/dist/ui/scrollArea/useScrollArea.js +146 -0
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ScrollAreaContextValue, ScrollAreaHook } from './types';
|
|
2
|
+
/** Внутренний контекст для передачи состояния ScrollArea */
|
|
3
|
+
export declare const ScrollAreaContext: import("react").Context<ScrollAreaContextValue | null>;
|
|
4
|
+
export declare const ScrollAreaProvider: import("react").Provider<ScrollAreaContextValue | null>;
|
|
5
|
+
/**
|
|
6
|
+
* Хук для доступа к состоянию и методам ScrollArea
|
|
7
|
+
*
|
|
8
|
+
* @returns Объект с индикаторами позиции, методами управления и ref на viewport
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* function MyComponent() {
|
|
13
|
+
* const { isAtBottom, scrollToTop, viewportRef } = useScrollArea();
|
|
14
|
+
*
|
|
15
|
+
* const scrollToElement = () => {
|
|
16
|
+
* const target = viewportRef.current?.querySelector('[data-target]');
|
|
17
|
+
* target?.scrollIntoView();
|
|
18
|
+
* };
|
|
19
|
+
*
|
|
20
|
+
* return (
|
|
21
|
+
* <button onClick={scrollToTop} disabled={isAtTop}>
|
|
22
|
+
* В начало
|
|
23
|
+
* </button>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const useScrollArea: () => ScrollAreaHook;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
const ScrollAreaContext = /*#__PURE__*/ createContext(null);
|
|
3
|
+
const ScrollAreaProvider = ScrollAreaContext.Provider;
|
|
4
|
+
const useScrollArea = ()=>{
|
|
5
|
+
const context = useContext(ScrollAreaContext);
|
|
6
|
+
if (!context) throw new Error('useScrollArea must be used within ScrollArea');
|
|
7
|
+
const { _callbackRef, mantineProps: _, radius: __, ...publicAPI } = context;
|
|
8
|
+
return publicAPI;
|
|
9
|
+
};
|
|
10
|
+
export { ScrollAreaContext, ScrollAreaProvider, useScrollArea };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { MantineRadius, ScrollAreaProps as MantineScrollAreaProps } from '@mantine/core';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
export interface ScrollAreaProps extends Omit<MantineScrollAreaProps, 'children'> {
|
|
4
|
+
/** Включение автоскролла при добавлении контента (по умолчанию false) */
|
|
5
|
+
autoScroll?: boolean;
|
|
6
|
+
/** Прокрутить к концу при инициализации компонента (по умолчанию false) */
|
|
7
|
+
scrollToBottomOnInit?: boolean;
|
|
8
|
+
/** Анимированная прокрутка (по умолчанию true) */
|
|
9
|
+
animated?: boolean;
|
|
10
|
+
/** Отступ для near-зон в пикселях (по умолчанию 100) */
|
|
11
|
+
nearThreshold?: number;
|
|
12
|
+
/** Радиус для viewport и scrollbar на тот случай, когда они "торчат" углами*/
|
|
13
|
+
radius?: MantineRadius;
|
|
14
|
+
/** Дочерние элементы - автоматически оборачиваются в ScrollArea.Content */
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
export interface ScrollAreaHook {
|
|
18
|
+
/** Точно в начале (scrollTop === 0) */
|
|
19
|
+
isAtTop: boolean;
|
|
20
|
+
/** В пределах nearThreshold от начала */
|
|
21
|
+
isNearTop: boolean;
|
|
22
|
+
/** Точно в конце (scrollTop + clientHeight >= scrollHeight) */
|
|
23
|
+
isAtBottom: boolean;
|
|
24
|
+
/** В пределах nearThreshold от конца */
|
|
25
|
+
isNearBottom: boolean;
|
|
26
|
+
/** Выше центральной точки области прокрутки */
|
|
27
|
+
isAboveCenter: boolean;
|
|
28
|
+
/** Есть контент требующий прокрутки */
|
|
29
|
+
hasScrollableContent: boolean;
|
|
30
|
+
/** Прокрутить к началу области */
|
|
31
|
+
scrollToTop: (animated?: boolean) => void;
|
|
32
|
+
/** Прокрутить к концу области */
|
|
33
|
+
scrollToBottom: (animated?: boolean) => void;
|
|
34
|
+
/** React ref на viewport элемент для прямого доступа к DOM */
|
|
35
|
+
viewportRef: React.RefObject<HTMLDivElement | null>;
|
|
36
|
+
}
|
|
37
|
+
export interface ScrollAreaState extends ScrollAreaHook {
|
|
38
|
+
/** Внутренний callback ref для подключения к Mantine ScrollArea */
|
|
39
|
+
_callbackRef: (node: HTMLDivElement | null) => void;
|
|
40
|
+
/** Внутренний ref для наблюдения за изменениями контента */
|
|
41
|
+
_contentResizeRef: (node: HTMLDivElement | null) => void;
|
|
42
|
+
}
|
|
43
|
+
export interface ScrollAreaContextValue extends ScrollAreaState {
|
|
44
|
+
/** Радиус для viewport и scrollbar на тот случай, когда они "торчат" углами*/
|
|
45
|
+
radius?: MantineRadius;
|
|
46
|
+
/** Пропсы Mantine ScrollArea, переданные в корневой компонент */
|
|
47
|
+
mantineProps: Omit<MantineScrollAreaProps, 'children'>;
|
|
48
|
+
}
|
|
49
|
+
export interface ScrollButtonProps {
|
|
50
|
+
/** CSS классы для стилизации кнопки */
|
|
51
|
+
className?: string;
|
|
52
|
+
/** Иконка для прокрутки вверх (по умолчанию IconChevronUp) */
|
|
53
|
+
upIcon?: ReactNode;
|
|
54
|
+
/** Иконка для прокрутки вниз (по умолчанию IconChevronDown) */
|
|
55
|
+
downIcon?: ReactNode;
|
|
56
|
+
}
|
|
57
|
+
/** Внутренний тип для отслеживания позиции скролла */
|
|
58
|
+
export interface ScrollPosition {
|
|
59
|
+
/** Текущая позиция скролла сверху */
|
|
60
|
+
scrollTop: number;
|
|
61
|
+
/** Высота видимой области */
|
|
62
|
+
clientHeight: number;
|
|
63
|
+
/** Общая высота прокручиваемого контента */
|
|
64
|
+
scrollHeight: number;
|
|
65
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ScrollAreaState } from './types';
|
|
2
|
+
interface UseScrollAreaOptions {
|
|
3
|
+
autoScroll?: boolean;
|
|
4
|
+
scrollToBottomOnInit?: boolean;
|
|
5
|
+
animated?: boolean;
|
|
6
|
+
nearThreshold?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const useScrollAreaState: (options?: UseScrollAreaOptions) => ScrollAreaState;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { useDebouncedCallback, useMergedRef, useResizeObserver } from "@mantine/hooks";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
const useScrollAreaState = (options = {})=>{
|
|
4
|
+
const { autoScroll = false, scrollToBottomOnInit = false, animated = true, nearThreshold = 32 } = options;
|
|
5
|
+
const scrollAreaRef = useRef(null);
|
|
6
|
+
const isUserInteractingRef = useRef(false);
|
|
7
|
+
const userInteractionTimeoutRef = useRef(void 0);
|
|
8
|
+
const isInitializedRef = useRef(false);
|
|
9
|
+
const [contentResizeRef, contentRect] = useResizeObserver();
|
|
10
|
+
const [scrollPosition, setScrollPosition] = useState({
|
|
11
|
+
scrollTop: 0,
|
|
12
|
+
clientHeight: 0,
|
|
13
|
+
scrollHeight: 0
|
|
14
|
+
});
|
|
15
|
+
const isAtTop = 0 === scrollPosition.scrollTop;
|
|
16
|
+
const isAtBottom = scrollPosition.scrollTop + scrollPosition.clientHeight >= scrollPosition.scrollHeight;
|
|
17
|
+
const isNearTop = scrollPosition.scrollTop <= nearThreshold;
|
|
18
|
+
const isNearBottom = scrollPosition.scrollTop + scrollPosition.clientHeight >= scrollPosition.scrollHeight - nearThreshold;
|
|
19
|
+
const isAboveCenter = scrollPosition.scrollTop < (scrollPosition.scrollHeight - scrollPosition.clientHeight) / 2;
|
|
20
|
+
const hasScrollableContent = scrollPosition.scrollHeight > scrollPosition.clientHeight;
|
|
21
|
+
const debouncedUpdatePosition = useDebouncedCallback((element)=>{
|
|
22
|
+
const newPosition = {
|
|
23
|
+
scrollTop: element.scrollTop,
|
|
24
|
+
clientHeight: element.clientHeight,
|
|
25
|
+
scrollHeight: element.scrollHeight
|
|
26
|
+
};
|
|
27
|
+
setScrollPosition(newPosition);
|
|
28
|
+
}, {
|
|
29
|
+
delay: 16
|
|
30
|
+
});
|
|
31
|
+
const scrollToTop = useCallback((isAnimated)=>{
|
|
32
|
+
const element = scrollAreaRef.current;
|
|
33
|
+
if (!element) return;
|
|
34
|
+
const shouldAnimate = isAnimated ?? animated;
|
|
35
|
+
if (shouldAnimate) element.scrollTo({
|
|
36
|
+
top: 0,
|
|
37
|
+
behavior: 'smooth'
|
|
38
|
+
});
|
|
39
|
+
else element.scrollTop = 0;
|
|
40
|
+
}, [
|
|
41
|
+
animated
|
|
42
|
+
]);
|
|
43
|
+
const scrollToBottom = useCallback((isAnimated)=>{
|
|
44
|
+
const element = scrollAreaRef.current;
|
|
45
|
+
if (!element) return;
|
|
46
|
+
const shouldAnimate = isAnimated ?? animated;
|
|
47
|
+
if (shouldAnimate) element.scrollTo({
|
|
48
|
+
top: element.scrollHeight,
|
|
49
|
+
behavior: 'smooth'
|
|
50
|
+
});
|
|
51
|
+
else element.scrollTop = element.scrollHeight;
|
|
52
|
+
const scrollHeightBefore = element.scrollHeight;
|
|
53
|
+
setTimeout(()=>{
|
|
54
|
+
const scrollHeightAfter = element.scrollHeight;
|
|
55
|
+
const diff = element.scrollHeight - (element.scrollTop + element.clientHeight);
|
|
56
|
+
if (diff > 1 && scrollHeightAfter !== scrollHeightBefore) element.scrollTop = element.scrollHeight;
|
|
57
|
+
}, 50);
|
|
58
|
+
}, [
|
|
59
|
+
animated
|
|
60
|
+
]);
|
|
61
|
+
const performAutoScroll = useCallback(()=>{
|
|
62
|
+
if (!autoScroll || isUserInteractingRef.current || !scrollAreaRef.current) return;
|
|
63
|
+
if (isAtBottom) scrollToBottom(false);
|
|
64
|
+
}, [
|
|
65
|
+
autoScroll,
|
|
66
|
+
isAtBottom,
|
|
67
|
+
scrollToBottom
|
|
68
|
+
]);
|
|
69
|
+
const handleUserInteraction = useCallback(()=>{
|
|
70
|
+
isUserInteractingRef.current = true;
|
|
71
|
+
if (userInteractionTimeoutRef.current) clearTimeout(userInteractionTimeoutRef.current);
|
|
72
|
+
userInteractionTimeoutRef.current = setTimeout(()=>{
|
|
73
|
+
isUserInteractingRef.current = false;
|
|
74
|
+
}, 150);
|
|
75
|
+
}, []);
|
|
76
|
+
const handleScroll = useCallback((event)=>{
|
|
77
|
+
const element = event.target;
|
|
78
|
+
debouncedUpdatePosition(element);
|
|
79
|
+
}, [
|
|
80
|
+
debouncedUpdatePosition
|
|
81
|
+
]);
|
|
82
|
+
useEffect(()=>{
|
|
83
|
+
if (!scrollToBottomOnInit || isInitializedRef.current) return;
|
|
84
|
+
if (hasScrollableContent) {
|
|
85
|
+
scrollToBottom(animated);
|
|
86
|
+
isInitializedRef.current = true;
|
|
87
|
+
}
|
|
88
|
+
}, [
|
|
89
|
+
scrollToBottomOnInit,
|
|
90
|
+
hasScrollableContent,
|
|
91
|
+
scrollToBottom,
|
|
92
|
+
animated
|
|
93
|
+
]);
|
|
94
|
+
useEffect(()=>{
|
|
95
|
+
const element = scrollAreaRef.current;
|
|
96
|
+
if (!element || 0 === contentRect.height) return;
|
|
97
|
+
debouncedUpdatePosition(element);
|
|
98
|
+
const timeoutId = setTimeout(performAutoScroll, 10);
|
|
99
|
+
return ()=>clearTimeout(timeoutId);
|
|
100
|
+
}, [
|
|
101
|
+
contentRect.height,
|
|
102
|
+
debouncedUpdatePosition,
|
|
103
|
+
performAutoScroll
|
|
104
|
+
]);
|
|
105
|
+
useEffect(()=>{
|
|
106
|
+
const element = scrollAreaRef.current;
|
|
107
|
+
if (!element) return;
|
|
108
|
+
const events = [
|
|
109
|
+
'wheel',
|
|
110
|
+
'touchstart',
|
|
111
|
+
'touchmove',
|
|
112
|
+
'mousedown'
|
|
113
|
+
];
|
|
114
|
+
element.addEventListener('scroll', handleScroll);
|
|
115
|
+
events.forEach((event)=>{
|
|
116
|
+
element.addEventListener(event, handleUserInteraction);
|
|
117
|
+
});
|
|
118
|
+
debouncedUpdatePosition(element);
|
|
119
|
+
return ()=>{
|
|
120
|
+
element.removeEventListener('scroll', handleScroll);
|
|
121
|
+
events.forEach((event)=>{
|
|
122
|
+
element.removeEventListener(event, handleUserInteraction);
|
|
123
|
+
});
|
|
124
|
+
if (userInteractionTimeoutRef.current) clearTimeout(userInteractionTimeoutRef.current);
|
|
125
|
+
};
|
|
126
|
+
}, [
|
|
127
|
+
handleScroll,
|
|
128
|
+
handleUserInteraction,
|
|
129
|
+
debouncedUpdatePosition
|
|
130
|
+
]);
|
|
131
|
+
const callbackRef = useMergedRef(scrollAreaRef);
|
|
132
|
+
return {
|
|
133
|
+
isAtTop,
|
|
134
|
+
isNearTop,
|
|
135
|
+
isAtBottom,
|
|
136
|
+
isNearBottom,
|
|
137
|
+
isAboveCenter,
|
|
138
|
+
hasScrollableContent,
|
|
139
|
+
scrollToTop,
|
|
140
|
+
scrollToBottom,
|
|
141
|
+
viewportRef: scrollAreaRef,
|
|
142
|
+
_callbackRef: callbackRef,
|
|
143
|
+
_contentResizeRef: contentResizeRef
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export { useScrollAreaState };
|