@rolder/kit 3.0.0-alpha.8 → 3.0.0-alpha.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/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 +225 -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 +14 -0
- package/{src/ai/ui/conversation/types.ts → dist/ai/ui/conversation/types.d.ts} +4 -5
- 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/promptInput/File.d.ts +2 -0
- package/dist/ai/ui/promptInput/File.js +117 -0
- package/dist/ai/ui/promptInput/FileIcon.d.ts +3 -0
- package/dist/ai/ui/promptInput/FileIcon.js +225 -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 +40 -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 +13 -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/parseAiMessagePart.d.ts +2 -0
- package/dist/ai/utils/parseAiMessagePart.js +12 -0
- package/dist/app/AppDefaults.d.ts +3 -0
- package/dist/app/AppDefaults.js +27 -0
- package/dist/app/DefaultApp.d.ts +6 -0
- package/dist/app/DefaultApp.js +43 -0
- package/dist/app/cookieColorSchemeManager.d.ts +6 -0
- package/dist/app/cookieColorSchemeManager.js +46 -0
- package/dist/app/defaultRequestMiddlewares.d.ts +4 -0
- package/dist/app/defaultRequestMiddlewares.js +24 -0
- package/dist/app/defaultTheme.d.ts +141 -0
- package/dist/app/defaultTheme.js +24 -0
- package/dist/functions/getCookie.d.ts +3 -0
- package/dist/functions/getCookie.js +8 -0
- package/dist/functions/setCookie.d.ts +10 -0
- package/dist/functions/setCookie.js +19 -0
- package/dist/functions/setCookies.d.ts +14 -0
- package/dist/functions/setCookies.js +13 -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/{src/index.ts → dist/index.d.ts} +5 -45
- package/dist/index.js +26 -0
- package/{src → dist}/styles.css +11 -21
- package/dist/surreal/connection.d.ts +9 -0
- package/dist/surreal/connection.js +49 -0
- package/dist/surreal/deafaultCrud.d.ts +2 -0
- package/dist/surreal/deafaultCrud.js +18 -0
- package/dist/surreal/deserialize.d.ts +17 -0
- package/dist/surreal/deserialize.js +46 -0
- package/dist/surreal/encryption.d.ts +6 -0
- package/dist/surreal/encryption.js +30 -0
- package/dist/ui/AnimatedChevron.d.ts +6 -0
- package/dist/ui/AnimatedChevron.js +31 -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 +156 -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.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 +44 -0
- package/dist/ui/form/buttons/SubmitButton.d.ts +5 -0
- package/dist/ui/form/buttons/SubmitButton.js +47 -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.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 +51 -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.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.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.js +3 -0
- package/dist/ui/hoverPaper/usePaperHover.d.ts +4 -0
- package/dist/ui/hoverPaper/usePaperHover.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.js +2 -0
- package/{src/ui/scrollArea/ScrollArea.tsx → dist/ui/scrollArea/ScrollArea.d.ts} +10 -41
- package/dist/ui/scrollArea/ScrollArea.js +30 -0
- package/dist/ui/scrollArea/ScrollAreaButton.d.ts +5 -0
- package/dist/ui/scrollArea/ScrollAreaButton.js +51 -0
- package/dist/ui/scrollArea/ScrollAreaContent.d.ts +6 -0
- package/dist/ui/scrollArea/ScrollAreaContent.js +29 -0
- package/{src/ui/scrollArea/context.tsx → dist/ui/scrollArea/context.d.ts} +3 -18
- 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 +4 -1
- package/rslib.config.ts +0 -21
- package/src/ai/ui/conversation/ConversationContext.ts +0 -21
- package/src/ai/ui/conversation/ConversationProvider.tsx +0 -21
- package/src/ai/ui/conversation/Empty.tsx +0 -15
- package/src/ai/ui/conversation/File.tsx +0 -40
- package/src/ai/ui/conversation/FileIcon.tsx +0 -143
- package/src/ai/ui/conversation/Loader.tsx +0 -8
- package/src/ai/ui/conversation/Message.tsx +0 -34
- package/src/ai/ui/conversation/Root.tsx +0 -24
- package/src/ai/ui/conversation/index.ts +0 -16
- package/src/ai/ui/conversation/useChatMessage.ts +0 -13
- package/src/ai/ui/promptInput/File.tsx +0 -98
- package/src/ai/ui/promptInput/FileIcon.tsx +0 -149
- package/src/ai/ui/promptInput/Footer.tsx +0 -5
- package/src/ai/ui/promptInput/PromptInputContext.ts +0 -24
- package/src/ai/ui/promptInput/PromptInputProvider.tsx +0 -54
- package/src/ai/ui/promptInput/Root.tsx +0 -29
- package/src/ai/ui/promptInput/Submit.tsx +0 -39
- package/src/ai/ui/promptInput/Textarea.tsx +0 -39
- package/src/ai/ui/promptInput/index.ts +0 -15
- package/src/ai/ui/promptInput/types.ts +0 -9
- package/src/ai/utils/convertFileUIPartBlobToDataURL.ts +0 -29
- package/src/ai/utils/parseAiMessagePart.ts +0 -19
- package/src/app/AppDefaults.tsx +0 -21
- package/src/app/DefaultApp.tsx +0 -50
- package/src/app/cookieColorSchemeManager.ts +0 -70
- package/src/app/defaultRequestMiddlewares.ts +0 -22
- package/src/app/defaultTheme.ts +0 -22
- package/src/functions/getCookie.ts +0 -36
- package/src/functions/setCookie.ts +0 -29
- package/src/functions/setCookies.ts +0 -24
- package/src/hooks/useMutation.ts +0 -14
- package/src/hooks/useMutationWithInvalidate.ts +0 -23
- package/src/surreal/connection.ts +0 -72
- package/src/surreal/deafaultCrud.ts +0 -25
- package/src/surreal/deserialize.ts +0 -144
- package/src/surreal/encryption.ts +0 -51
- package/src/ui/AnimatedChevron.tsx +0 -32
- package/src/ui/JsonInput.tsx +0 -52
- package/src/ui/RouterLink.tsx +0 -78
- package/src/ui/editor/Content.tsx +0 -11
- package/src/ui/editor/Provider.tsx +0 -96
- package/src/ui/editor/Root.tsx +0 -25
- package/src/ui/editor/Toolbar.tsx +0 -92
- package/src/ui/editor/index.ts +0 -13
- package/src/ui/editor/types.ts +0 -7
- package/src/ui/error/DefaultError.tsx +0 -60
- package/src/ui/error/DefaultNotFound.tsx +0 -19
- package/src/ui/error/Forbidden.tsx +0 -18
- package/src/ui/error/defaultErrorNotification.ts +0 -9
- package/src/ui/form/blurOnError.ts +0 -21
- package/src/ui/form/buttons/CancelButton.tsx +0 -42
- package/src/ui/form/buttons/SubmitButton.tsx +0 -43
- package/src/ui/form/buttons/SubscribeActionIcon.tsx +0 -18
- package/src/ui/form/buttons/SubscribeButton.tsx +0 -17
- package/src/ui/form/context.ts +0 -45
- package/src/ui/form/fields/JsonField.tsx +0 -16
- package/src/ui/form/fields/MultiSelectField.tsx +0 -17
- package/src/ui/form/fields/NumberField.tsx +0 -17
- package/src/ui/form/fields/PassowrdField.tsx +0 -20
- package/src/ui/form/fields/SelectField.tsx +0 -17
- package/src/ui/form/fields/SwitchField.tsx +0 -17
- package/src/ui/form/fields/TextField.tsx +0 -17
- package/src/ui/form/fields/TextPassowrdField.tsx +0 -51
- package/src/ui/form/fields/TextareaField.tsx +0 -17
- package/src/ui/form/fieldsSchema.ts +0 -24
- package/src/ui/hoverPaper/HoverPaper.tsx +0 -17
- package/src/ui/hoverPaper/usePaperHover.ts +0 -9
- package/src/ui/saveInput/JsonInput.tsx +0 -40
- package/src/ui/saveInput/NumberInput.tsx +0 -40
- package/src/ui/saveInput/SaveInput.tsx +0 -15
- package/src/ui/saveInput/Select.tsx +0 -41
- package/src/ui/saveInput/Switch.tsx +0 -46
- package/src/ui/saveInput/TextInput.tsx +0 -40
- package/src/ui/saveInput/Textarea.tsx +0 -40
- package/src/ui/scrollArea/ARCH.md +0 -204
- package/src/ui/scrollArea/README.md +0 -369
- package/src/ui/scrollArea/ScrollAreaButton.tsx +0 -56
- package/src/ui/scrollArea/ScrollAreaContent.tsx +0 -36
- package/src/ui/scrollArea/index.ts +0 -10
- package/src/ui/scrollArea/types.ts +0 -77
- package/src/ui/scrollArea/useScrollArea.ts +0 -227
- package/tsconfig.json +0 -14
- /package/{src/ui/error/index.ts → dist/ui/error/index.d.ts} +0 -0
- /package/{src/ui/form/buttons/index.ts → dist/ui/form/buttons/index.d.ts} +0 -0
- /package/{src/ui/form/fields/index.ts → dist/ui/form/fields/index.d.ts} +0 -0
- /package/{src/ui/form/index.ts → dist/ui/form/index.d.ts} +0 -0
- /package/{src/ui/hoverPaper/index.ts → dist/ui/hoverPaper/index.d.ts} +0 -0
- /package/{src/ui/saveInput/index.ts → dist/ui/saveInput/index.d.ts} +0 -0
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useDebouncedCallback,
|
|
3
|
-
useMergedRef,
|
|
4
|
-
useResizeObserver,
|
|
5
|
-
} from '@mantine/hooks';
|
|
6
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
7
|
-
import type { ScrollAreaState, ScrollPosition } from './types';
|
|
8
|
-
|
|
9
|
-
interface UseScrollAreaOptions {
|
|
10
|
-
autoScroll?: boolean;
|
|
11
|
-
scrollToBottomOnInit?: boolean;
|
|
12
|
-
animated?: boolean;
|
|
13
|
-
nearThreshold?: number;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const useScrollAreaState = (
|
|
17
|
-
options: UseScrollAreaOptions = {},
|
|
18
|
-
): ScrollAreaState => {
|
|
19
|
-
const {
|
|
20
|
-
autoScroll = false,
|
|
21
|
-
scrollToBottomOnInit = false,
|
|
22
|
-
animated = true,
|
|
23
|
-
nearThreshold = 32,
|
|
24
|
-
} = options;
|
|
25
|
-
|
|
26
|
-
const scrollAreaRef = useRef<HTMLDivElement | null>(null);
|
|
27
|
-
const isUserInteractingRef = useRef(false);
|
|
28
|
-
const userInteractionTimeoutRef = useRef<NodeJS.Timeout | undefined>(
|
|
29
|
-
undefined,
|
|
30
|
-
);
|
|
31
|
-
const isInitializedRef = useRef(false);
|
|
32
|
-
|
|
33
|
-
// Единый ResizeObserver для отслеживания изменений размера контента
|
|
34
|
-
const [contentResizeRef, contentRect] = useResizeObserver();
|
|
35
|
-
|
|
36
|
-
const [scrollPosition, setScrollPosition] = useState<ScrollPosition>({
|
|
37
|
-
scrollTop: 0,
|
|
38
|
-
clientHeight: 0,
|
|
39
|
-
scrollHeight: 0,
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
// Вычисляемые состояния позиции
|
|
43
|
-
const isAtTop = scrollPosition.scrollTop === 0;
|
|
44
|
-
const isAtBottom =
|
|
45
|
-
scrollPosition.scrollTop + scrollPosition.clientHeight >=
|
|
46
|
-
scrollPosition.scrollHeight;
|
|
47
|
-
const isNearTop = scrollPosition.scrollTop <= nearThreshold;
|
|
48
|
-
const isNearBottom =
|
|
49
|
-
scrollPosition.scrollTop + scrollPosition.clientHeight >=
|
|
50
|
-
scrollPosition.scrollHeight - nearThreshold;
|
|
51
|
-
const isAboveCenter =
|
|
52
|
-
scrollPosition.scrollTop <
|
|
53
|
-
(scrollPosition.scrollHeight - scrollPosition.clientHeight) / 2;
|
|
54
|
-
const hasScrollableContent =
|
|
55
|
-
scrollPosition.scrollHeight > scrollPosition.clientHeight;
|
|
56
|
-
|
|
57
|
-
// Используем useDebouncedCallback для оптимизации производительности
|
|
58
|
-
const debouncedUpdatePosition = useDebouncedCallback(
|
|
59
|
-
(element: HTMLElement) => {
|
|
60
|
-
const newPosition: ScrollPosition = {
|
|
61
|
-
scrollTop: element.scrollTop,
|
|
62
|
-
clientHeight: element.clientHeight,
|
|
63
|
-
scrollHeight: element.scrollHeight,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
setScrollPosition(newPosition);
|
|
67
|
-
},
|
|
68
|
-
{ delay: 16 }, // 60fps
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
// Методы управления прокруткой
|
|
72
|
-
const scrollToTop = useCallback(
|
|
73
|
-
(isAnimated?: boolean) => {
|
|
74
|
-
const element = scrollAreaRef.current;
|
|
75
|
-
if (!element) return;
|
|
76
|
-
|
|
77
|
-
const shouldAnimate = isAnimated ?? animated;
|
|
78
|
-
|
|
79
|
-
if (shouldAnimate) {
|
|
80
|
-
element.scrollTo({ top: 0, behavior: 'smooth' });
|
|
81
|
-
} else {
|
|
82
|
-
element.scrollTop = 0;
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
[animated],
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
const scrollToBottom = useCallback(
|
|
89
|
-
(isAnimated?: boolean) => {
|
|
90
|
-
const element = scrollAreaRef.current;
|
|
91
|
-
if (!element) return;
|
|
92
|
-
|
|
93
|
-
const shouldAnimate = isAnimated ?? animated;
|
|
94
|
-
|
|
95
|
-
if (shouldAnimate) {
|
|
96
|
-
element.scrollTo({ top: element.scrollHeight, behavior: 'smooth' });
|
|
97
|
-
} else {
|
|
98
|
-
element.scrollTop = element.scrollHeight;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Запоминаем scrollHeight до скролла
|
|
102
|
-
const scrollHeightBefore = element.scrollHeight;
|
|
103
|
-
|
|
104
|
-
// Проверка результата и повтор если нужно
|
|
105
|
-
setTimeout(() => {
|
|
106
|
-
const scrollHeightAfter = element.scrollHeight;
|
|
107
|
-
const diff =
|
|
108
|
-
element.scrollHeight - (element.scrollTop + element.clientHeight);
|
|
109
|
-
|
|
110
|
-
if (diff > 1 && scrollHeightAfter !== scrollHeightBefore) {
|
|
111
|
-
// ScrollHeight изменился после скролла - повторяем
|
|
112
|
-
element.scrollTop = element.scrollHeight;
|
|
113
|
-
}
|
|
114
|
-
}, 50);
|
|
115
|
-
},
|
|
116
|
-
[animated],
|
|
117
|
-
);
|
|
118
|
-
|
|
119
|
-
// Универсальная функция автоскролла
|
|
120
|
-
const performAutoScroll = useCallback(() => {
|
|
121
|
-
if (!autoScroll || isUserInteractingRef.current || !scrollAreaRef.current) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Для автоскролла используем isAtBottom (точная позиция)
|
|
126
|
-
if (isAtBottom) {
|
|
127
|
-
scrollToBottom(false);
|
|
128
|
-
}
|
|
129
|
-
}, [autoScroll, isAtBottom, scrollToBottom]);
|
|
130
|
-
|
|
131
|
-
// Детекция пользовательского взаимодействия
|
|
132
|
-
const handleUserInteraction = useCallback(() => {
|
|
133
|
-
isUserInteractingRef.current = true;
|
|
134
|
-
|
|
135
|
-
if (userInteractionTimeoutRef.current) {
|
|
136
|
-
clearTimeout(userInteractionTimeoutRef.current);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
userInteractionTimeoutRef.current = setTimeout(() => {
|
|
140
|
-
isUserInteractingRef.current = false;
|
|
141
|
-
}, 150);
|
|
142
|
-
}, []);
|
|
143
|
-
|
|
144
|
-
// Обработчик скролла
|
|
145
|
-
const handleScroll = useCallback(
|
|
146
|
-
(event: Event) => {
|
|
147
|
-
const element = event.target as HTMLElement;
|
|
148
|
-
debouncedUpdatePosition(element);
|
|
149
|
-
},
|
|
150
|
-
[debouncedUpdatePosition],
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
// Прокрутка к концу при инициализации
|
|
154
|
-
useEffect(() => {
|
|
155
|
-
if (!scrollToBottomOnInit || isInitializedRef.current) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (hasScrollableContent) {
|
|
160
|
-
scrollToBottom(animated);
|
|
161
|
-
isInitializedRef.current = true;
|
|
162
|
-
}
|
|
163
|
-
}, [scrollToBottomOnInit, hasScrollableContent, scrollToBottom, animated]);
|
|
164
|
-
|
|
165
|
-
// Единый эффект для автоскролла при изменении контента
|
|
166
|
-
useEffect(() => {
|
|
167
|
-
const element = scrollAreaRef.current;
|
|
168
|
-
|
|
169
|
-
if (!element || contentRect.height === 0) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// Обновляем позицию
|
|
174
|
-
debouncedUpdatePosition(element);
|
|
175
|
-
|
|
176
|
-
// Автоскролл с небольшой задержкой
|
|
177
|
-
const timeoutId = setTimeout(performAutoScroll, 10);
|
|
178
|
-
|
|
179
|
-
return () => clearTimeout(timeoutId);
|
|
180
|
-
}, [contentRect.height, debouncedUpdatePosition, performAutoScroll]);
|
|
181
|
-
|
|
182
|
-
// Установка обработчиков событий
|
|
183
|
-
useEffect(() => {
|
|
184
|
-
const element = scrollAreaRef.current;
|
|
185
|
-
if (!element) return;
|
|
186
|
-
|
|
187
|
-
const events = ['wheel', 'touchstart', 'touchmove', 'mousedown'] as const;
|
|
188
|
-
|
|
189
|
-
element.addEventListener('scroll', handleScroll);
|
|
190
|
-
events.forEach((event) => {
|
|
191
|
-
element.addEventListener(event, handleUserInteraction);
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// Инициализация позиции
|
|
195
|
-
debouncedUpdatePosition(element);
|
|
196
|
-
|
|
197
|
-
return () => {
|
|
198
|
-
element.removeEventListener('scroll', handleScroll);
|
|
199
|
-
events.forEach((event) => {
|
|
200
|
-
element.removeEventListener(event, handleUserInteraction);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
if (userInteractionTimeoutRef.current) {
|
|
204
|
-
clearTimeout(userInteractionTimeoutRef.current);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
}, [handleScroll, handleUserInteraction, debouncedUpdatePosition]);
|
|
208
|
-
|
|
209
|
-
// Единый ref
|
|
210
|
-
const callbackRef = useMergedRef(scrollAreaRef);
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
isAtTop,
|
|
214
|
-
isNearTop,
|
|
215
|
-
isAtBottom,
|
|
216
|
-
isNearBottom,
|
|
217
|
-
isAboveCenter,
|
|
218
|
-
hasScrollableContent,
|
|
219
|
-
scrollToTop,
|
|
220
|
-
scrollToBottom,
|
|
221
|
-
viewportRef: scrollAreaRef,
|
|
222
|
-
_callbackRef: callbackRef,
|
|
223
|
-
_contentResizeRef: contentResizeRef as unknown as (
|
|
224
|
-
node: HTMLDivElement | null,
|
|
225
|
-
) => void,
|
|
226
|
-
};
|
|
227
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["DOM", "ES2022"],
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"jsx": "react-jsx",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
"isolatedModules": true,
|
|
9
|
-
"resolveJsonModule": true,
|
|
10
|
-
"moduleResolution": "bundler",
|
|
11
|
-
"useDefineForClassFields": true
|
|
12
|
-
},
|
|
13
|
-
"include": ["src"]
|
|
14
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|