@rolder/kit 3.0.0-alpha.6 → 3.0.0-alpha.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.
Files changed (263) hide show
  1. package/package.json +3 -3
  2. package/rslib.config.ts +21 -0
  3. package/src/ai/ui/conversation/ConversationContext.ts +21 -0
  4. package/src/ai/ui/conversation/ConversationProvider.tsx +21 -0
  5. package/src/ai/ui/conversation/Empty.tsx +15 -0
  6. package/src/ai/ui/conversation/File.tsx +40 -0
  7. package/src/ai/ui/conversation/FileIcon.tsx +143 -0
  8. package/src/ai/ui/conversation/Loader.tsx +8 -0
  9. package/src/ai/ui/conversation/Message.tsx +34 -0
  10. package/src/ai/ui/conversation/Root.tsx +24 -0
  11. package/src/ai/ui/conversation/index.ts +16 -0
  12. package/{dist/ai/ui/conversation/types.d.ts → src/ai/ui/conversation/types.ts} +5 -4
  13. package/src/ai/ui/conversation/useChatMessage.ts +13 -0
  14. package/src/ai/ui/promptInput/File.tsx +98 -0
  15. package/src/ai/ui/promptInput/FileIcon.tsx +149 -0
  16. package/src/ai/ui/promptInput/Footer.tsx +5 -0
  17. package/src/ai/ui/promptInput/PromptInputContext.ts +24 -0
  18. package/src/ai/ui/promptInput/PromptInputProvider.tsx +54 -0
  19. package/src/ai/ui/promptInput/Root.tsx +29 -0
  20. package/src/ai/ui/promptInput/Submit.tsx +39 -0
  21. package/src/ai/ui/promptInput/Textarea.tsx +39 -0
  22. package/src/ai/ui/promptInput/index.ts +15 -0
  23. package/src/ai/ui/promptInput/types.ts +9 -0
  24. package/src/ai/utils/convertFileUIPartBlobToDataURL.ts +29 -0
  25. package/src/ai/utils/parseAiMessagePart.ts +19 -0
  26. package/src/app/AppDefaults.tsx +21 -0
  27. package/src/app/DefaultApp.tsx +50 -0
  28. package/src/app/cookieColorSchemeManager.ts +70 -0
  29. package/src/app/defaultRequestMiddlewares.ts +22 -0
  30. package/src/app/defaultTheme.ts +22 -0
  31. package/src/functions/getCookie.ts +36 -0
  32. package/src/functions/setCookie.ts +29 -0
  33. package/src/functions/setCookies.ts +24 -0
  34. package/src/hooks/useMutation.ts +14 -0
  35. package/src/hooks/useMutationWithInvalidate.ts +23 -0
  36. package/{dist/index.d.ts → src/index.ts} +45 -5
  37. package/{dist → src}/styles.css +21 -11
  38. package/src/surreal/connection.ts +72 -0
  39. package/src/surreal/deafaultCrud.ts +25 -0
  40. package/src/surreal/deserialize.ts +144 -0
  41. package/src/surreal/encryption.ts +51 -0
  42. package/src/ui/AnimatedChevron.tsx +32 -0
  43. package/src/ui/JsonInput.tsx +52 -0
  44. package/src/ui/RouterLink.tsx +78 -0
  45. package/src/ui/editor/Content.tsx +11 -0
  46. package/src/ui/editor/Provider.tsx +96 -0
  47. package/src/ui/editor/Root.tsx +25 -0
  48. package/src/ui/editor/Toolbar.tsx +92 -0
  49. package/src/ui/editor/index.ts +13 -0
  50. package/src/ui/editor/types.ts +7 -0
  51. package/src/ui/error/DefaultError.tsx +60 -0
  52. package/src/ui/error/DefaultNotFound.tsx +19 -0
  53. package/src/ui/error/Forbidden.tsx +18 -0
  54. package/src/ui/error/defaultErrorNotification.ts +9 -0
  55. package/src/ui/form/blurOnError.ts +21 -0
  56. package/src/ui/form/buttons/CancelButton.tsx +42 -0
  57. package/src/ui/form/buttons/SubmitButton.tsx +43 -0
  58. package/src/ui/form/buttons/SubscribeActionIcon.tsx +18 -0
  59. package/src/ui/form/buttons/SubscribeButton.tsx +17 -0
  60. package/src/ui/form/context.ts +45 -0
  61. package/src/ui/form/fields/JsonField.tsx +16 -0
  62. package/src/ui/form/fields/MultiSelectField.tsx +17 -0
  63. package/src/ui/form/fields/NumberField.tsx +17 -0
  64. package/src/ui/form/fields/PassowrdField.tsx +20 -0
  65. package/src/ui/form/fields/SelectField.tsx +17 -0
  66. package/src/ui/form/fields/SwitchField.tsx +17 -0
  67. package/src/ui/form/fields/TextField.tsx +17 -0
  68. package/src/ui/form/fields/TextPassowrdField.tsx +51 -0
  69. package/src/ui/form/fields/TextareaField.tsx +17 -0
  70. package/src/ui/form/fieldsSchema.ts +24 -0
  71. package/src/ui/hoverPaper/HoverPaper.tsx +17 -0
  72. package/src/ui/hoverPaper/usePaperHover.ts +9 -0
  73. package/src/ui/saveInput/JsonInput.tsx +40 -0
  74. package/src/ui/saveInput/NumberInput.tsx +40 -0
  75. package/src/ui/saveInput/SaveInput.tsx +15 -0
  76. package/src/ui/saveInput/Select.tsx +41 -0
  77. package/src/ui/saveInput/Switch.tsx +46 -0
  78. package/src/ui/saveInput/TextInput.tsx +40 -0
  79. package/src/ui/saveInput/Textarea.tsx +40 -0
  80. package/src/ui/scrollArea/ARCH.md +204 -0
  81. package/src/ui/scrollArea/README.md +369 -0
  82. package/{dist/ui/scrollArea/ScrollArea.d.ts → src/ui/scrollArea/ScrollArea.tsx} +41 -10
  83. package/src/ui/scrollArea/ScrollAreaButton.tsx +56 -0
  84. package/src/ui/scrollArea/ScrollAreaContent.tsx +36 -0
  85. package/{dist/ui/scrollArea/context.d.ts → src/ui/scrollArea/context.tsx} +18 -3
  86. package/src/ui/scrollArea/index.ts +10 -0
  87. package/src/ui/scrollArea/types.ts +77 -0
  88. package/src/ui/scrollArea/useScrollArea.ts +227 -0
  89. package/tsconfig.json +14 -0
  90. package/dist/ai/ui/conversation/ConversationContext.d.ts +0 -7
  91. package/dist/ai/ui/conversation/ConversationContext.js +0 -8
  92. package/dist/ai/ui/conversation/ConversationProvider.d.ts +0 -2
  93. package/dist/ai/ui/conversation/ConversationProvider.js +0 -14
  94. package/dist/ai/ui/conversation/Empty.d.ts +0 -1
  95. package/dist/ai/ui/conversation/Empty.js +0 -21
  96. package/dist/ai/ui/conversation/File.d.ts +0 -4
  97. package/dist/ai/ui/conversation/File.js +0 -42
  98. package/dist/ai/ui/conversation/FileIcon.d.ts +0 -3
  99. package/dist/ai/ui/conversation/FileIcon.js +0 -225
  100. package/dist/ai/ui/conversation/Loader.d.ts +0 -2
  101. package/dist/ai/ui/conversation/Loader.js +0 -12
  102. package/dist/ai/ui/conversation/Message.d.ts +0 -4
  103. package/dist/ai/ui/conversation/Message.js +0 -25
  104. package/dist/ai/ui/conversation/Root.d.ts +0 -2
  105. package/dist/ai/ui/conversation/Root.js +0 -26
  106. package/dist/ai/ui/conversation/index.d.ts +0 -13
  107. package/dist/ai/ui/conversation/index.js +0 -14
  108. package/dist/ai/ui/conversation/types.js +0 -0
  109. package/dist/ai/ui/conversation/useChatMessage.d.ts +0 -2
  110. package/dist/ai/ui/conversation/useChatMessage.js +0 -12
  111. package/dist/ai/ui/promptInput/File.d.ts +0 -2
  112. package/dist/ai/ui/promptInput/File.js +0 -117
  113. package/dist/ai/ui/promptInput/FileIcon.d.ts +0 -3
  114. package/dist/ai/ui/promptInput/FileIcon.js +0 -225
  115. package/dist/ai/ui/promptInput/Footer.d.ts +0 -2
  116. package/dist/ai/ui/promptInput/Footer.js +0 -8
  117. package/dist/ai/ui/promptInput/PromptInputContext.d.ts +0 -12
  118. package/dist/ai/ui/promptInput/PromptInputContext.js +0 -8
  119. package/dist/ai/ui/promptInput/PromptInputProvider.d.ts +0 -2
  120. package/dist/ai/ui/promptInput/PromptInputProvider.js +0 -50
  121. package/dist/ai/ui/promptInput/Root.d.ts +0 -3
  122. package/dist/ai/ui/promptInput/Root.js +0 -17
  123. package/dist/ai/ui/promptInput/Submit.d.ts +0 -2
  124. package/dist/ai/ui/promptInput/Submit.js +0 -40
  125. package/dist/ai/ui/promptInput/Textarea.d.ts +0 -2
  126. package/dist/ai/ui/promptInput/Textarea.js +0 -33
  127. package/dist/ai/ui/promptInput/index.d.ts +0 -8
  128. package/dist/ai/ui/promptInput/index.js +0 -13
  129. package/dist/ai/ui/promptInput/types.d.ts +0 -11
  130. package/dist/ai/ui/promptInput/types.js +0 -0
  131. package/dist/ai/utils/convertFileUIPartBlobToDataURL.d.ts +0 -5
  132. package/dist/ai/utils/convertFileUIPartBlobToDataURL.js +0 -21
  133. package/dist/ai/utils/parseAiMessagePart.d.ts +0 -2
  134. package/dist/ai/utils/parseAiMessagePart.js +0 -12
  135. package/dist/app/AppDefaults.d.ts +0 -3
  136. package/dist/app/AppDefaults.js +0 -27
  137. package/dist/app/DefaultApp.d.ts +0 -6
  138. package/dist/app/DefaultApp.js +0 -43
  139. package/dist/app/cookieColorSchemeManager.d.ts +0 -6
  140. package/dist/app/cookieColorSchemeManager.js +0 -46
  141. package/dist/app/defaultRequestMiddlewares.d.ts +0 -4
  142. package/dist/app/defaultRequestMiddlewares.js +0 -24
  143. package/dist/app/defaultTheme.d.ts +0 -141
  144. package/dist/app/defaultTheme.js +0 -24
  145. package/dist/functions/getCookie.d.ts +0 -3
  146. package/dist/functions/getCookie.js +0 -8
  147. package/dist/functions/setCookie.d.ts +0 -10
  148. package/dist/functions/setCookie.js +0 -19
  149. package/dist/functions/setCookies.d.ts +0 -14
  150. package/dist/functions/setCookies.js +0 -13
  151. package/dist/hooks/useMutation.d.ts +0 -4
  152. package/dist/hooks/useMutation.js +0 -8
  153. package/dist/hooks/useMutationWithInvalidate.d.ts +0 -4
  154. package/dist/hooks/useMutationWithInvalidate.js +0 -16
  155. package/dist/index.js +0 -26
  156. package/dist/surreal/connection.d.ts +0 -9
  157. package/dist/surreal/connection.js +0 -49
  158. package/dist/surreal/deafaultCrud.d.ts +0 -2
  159. package/dist/surreal/deafaultCrud.js +0 -18
  160. package/dist/surreal/deserialize.d.ts +0 -17
  161. package/dist/surreal/deserialize.js +0 -46
  162. package/dist/surreal/encryption.d.ts +0 -6
  163. package/dist/surreal/encryption.js +0 -30
  164. package/dist/ui/AnimatedChevron.d.ts +0 -6
  165. package/dist/ui/AnimatedChevron.js +0 -31
  166. package/dist/ui/JsonInput.d.ts +0 -2
  167. package/dist/ui/JsonInput.js +0 -45
  168. package/dist/ui/RouterLink.d.ts +0 -16
  169. package/dist/ui/RouterLink.js +0 -36
  170. package/dist/ui/editor/Content.d.ts +0 -3
  171. package/dist/ui/editor/Content.js +0 -13
  172. package/dist/ui/editor/Provider.d.ts +0 -17
  173. package/dist/ui/editor/Provider.js +0 -80
  174. package/dist/ui/editor/Root.d.ts +0 -2
  175. package/dist/ui/editor/Root.js +0 -18
  176. package/dist/ui/editor/Toolbar.d.ts +0 -5
  177. package/dist/ui/editor/Toolbar.js +0 -156
  178. package/dist/ui/editor/index.d.ts +0 -12
  179. package/dist/ui/editor/index.js +0 -11
  180. package/dist/ui/editor/types.d.ts +0 -7
  181. package/dist/ui/editor/types.js +0 -0
  182. package/dist/ui/error/DefaultError.d.ts +0 -2
  183. package/dist/ui/error/DefaultError.js +0 -62
  184. package/dist/ui/error/DefaultNotFound.d.ts +0 -1
  185. package/dist/ui/error/DefaultNotFound.js +0 -37
  186. package/dist/ui/error/Forbidden.d.ts +0 -1
  187. package/dist/ui/error/Forbidden.js +0 -32
  188. package/dist/ui/error/defaultErrorNotification.d.ts +0 -1
  189. package/dist/ui/error/defaultErrorNotification.js +0 -8
  190. package/dist/ui/error/index.js +0 -5
  191. package/dist/ui/form/blurOnError.d.ts +0 -4
  192. package/dist/ui/form/blurOnError.js +0 -11
  193. package/dist/ui/form/buttons/CancelButton.d.ts +0 -5
  194. package/dist/ui/form/buttons/CancelButton.js +0 -44
  195. package/dist/ui/form/buttons/SubmitButton.d.ts +0 -5
  196. package/dist/ui/form/buttons/SubmitButton.js +0 -47
  197. package/dist/ui/form/buttons/SubscribeActionIcon.d.ts +0 -4
  198. package/dist/ui/form/buttons/SubscribeActionIcon.js +0 -15
  199. package/dist/ui/form/buttons/SubscribeButton.d.ts +0 -5
  200. package/dist/ui/form/buttons/SubscribeButton.js +0 -16
  201. package/dist/ui/form/buttons/index.js +0 -4
  202. package/dist/ui/form/context.d.ts +0 -83
  203. package/dist/ui/form/context.js +0 -26
  204. package/dist/ui/form/fields/JsonField.d.ts +0 -2
  205. package/dist/ui/form/fields/JsonField.js +0 -13
  206. package/dist/ui/form/fields/MultiSelectField.d.ts +0 -2
  207. package/dist/ui/form/fields/MultiSelectField.js +0 -15
  208. package/dist/ui/form/fields/NumberField.d.ts +0 -2
  209. package/dist/ui/form/fields/NumberField.js +0 -15
  210. package/dist/ui/form/fields/PassowrdField.d.ts +0 -2
  211. package/dist/ui/form/fields/PassowrdField.js +0 -18
  212. package/dist/ui/form/fields/SelectField.d.ts +0 -2
  213. package/dist/ui/form/fields/SelectField.js +0 -15
  214. package/dist/ui/form/fields/SwitchField.d.ts +0 -2
  215. package/dist/ui/form/fields/SwitchField.js +0 -15
  216. package/dist/ui/form/fields/TextField.d.ts +0 -2
  217. package/dist/ui/form/fields/TextField.js +0 -15
  218. package/dist/ui/form/fields/TextPassowrdField.d.ts +0 -2
  219. package/dist/ui/form/fields/TextPassowrdField.js +0 -51
  220. package/dist/ui/form/fields/TextareaField.d.ts +0 -2
  221. package/dist/ui/form/fields/TextareaField.js +0 -15
  222. package/dist/ui/form/fields/index.js +0 -9
  223. package/dist/ui/form/fieldsSchema.d.ts +0 -12
  224. package/dist/ui/form/fieldsSchema.js +0 -13
  225. package/dist/ui/form/index.js +0 -4
  226. package/dist/ui/hoverPaper/HoverPaper.d.ts +0 -6
  227. package/dist/ui/hoverPaper/HoverPaper.js +0 -15
  228. package/dist/ui/hoverPaper/index.js +0 -3
  229. package/dist/ui/hoverPaper/usePaperHover.d.ts +0 -4
  230. package/dist/ui/hoverPaper/usePaperHover.js +0 -9
  231. package/dist/ui/saveInput/JsonInput.d.ts +0 -6
  232. package/dist/ui/saveInput/JsonInput.js +0 -34
  233. package/dist/ui/saveInput/NumberInput.d.ts +0 -6
  234. package/dist/ui/saveInput/NumberInput.js +0 -27
  235. package/dist/ui/saveInput/SaveInput.d.ts +0 -36
  236. package/dist/ui/saveInput/SaveInput.js +0 -15
  237. package/dist/ui/saveInput/Select.d.ts +0 -6
  238. package/dist/ui/saveInput/Select.js +0 -27
  239. package/dist/ui/saveInput/Switch.d.ts +0 -6
  240. package/dist/ui/saveInput/Switch.js +0 -30
  241. package/dist/ui/saveInput/TextInput.d.ts +0 -6
  242. package/dist/ui/saveInput/TextInput.js +0 -26
  243. package/dist/ui/saveInput/Textarea.d.ts +0 -6
  244. package/dist/ui/saveInput/Textarea.js +0 -26
  245. package/dist/ui/saveInput/index.js +0 -2
  246. package/dist/ui/scrollArea/ScrollArea.js +0 -30
  247. package/dist/ui/scrollArea/ScrollAreaButton.d.ts +0 -5
  248. package/dist/ui/scrollArea/ScrollAreaButton.js +0 -51
  249. package/dist/ui/scrollArea/ScrollAreaContent.d.ts +0 -6
  250. package/dist/ui/scrollArea/ScrollAreaContent.js +0 -29
  251. package/dist/ui/scrollArea/context.js +0 -10
  252. package/dist/ui/scrollArea/index.d.ts +0 -3
  253. package/dist/ui/scrollArea/index.js +0 -3
  254. package/dist/ui/scrollArea/types.d.ts +0 -65
  255. package/dist/ui/scrollArea/types.js +0 -0
  256. package/dist/ui/scrollArea/useScrollArea.d.ts +0 -9
  257. package/dist/ui/scrollArea/useScrollArea.js +0 -146
  258. /package/{dist/ui/error/index.d.ts → src/ui/error/index.ts} +0 -0
  259. /package/{dist/ui/form/buttons/index.d.ts → src/ui/form/buttons/index.ts} +0 -0
  260. /package/{dist/ui/form/fields/index.d.ts → src/ui/form/fields/index.ts} +0 -0
  261. /package/{dist/ui/form/index.d.ts → src/ui/form/index.ts} +0 -0
  262. /package/{dist/ui/hoverPaper/index.d.ts → src/ui/hoverPaper/index.ts} +0 -0
  263. /package/{dist/ui/saveInput/index.d.ts → src/ui/saveInput/index.ts} +0 -0
@@ -0,0 +1,227 @@
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 ADDED
@@ -0,0 +1,14 @@
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
+ }
@@ -1,7 +0,0 @@
1
- export interface ConversationContext {
2
- loading: boolean;
3
- streaming: boolean;
4
- empty: boolean;
5
- }
6
- export declare const ConversationContext: import("react").Context<ConversationContext | null>;
7
- export declare const useConversation: () => ConversationContext;
@@ -1,8 +0,0 @@
1
- import { createContext, useContext } from "react";
2
- const ConversationContext = createContext(null);
3
- const useConversation = ()=>{
4
- const context = useContext(ConversationContext);
5
- if (!context) throw new Error('useConversation must be used within a ConversationProvider');
6
- return context;
7
- };
8
- export { ConversationContext, useConversation };
@@ -1,2 +0,0 @@
1
- import type { ConversationProps } from './types';
2
- export declare const Provider: ({ children, loading, streaming, empty, }: ConversationProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,14 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { ConversationContext } from "./ConversationContext.js";
3
- const Provider = ({ children, loading, streaming, empty })=>{
4
- const value = {
5
- loading,
6
- streaming,
7
- empty
8
- };
9
- return /*#__PURE__*/ jsx(ConversationContext.Provider, {
10
- value: value,
11
- children: children
12
- });
13
- };
14
- export { Provider };
@@ -1 +0,0 @@
1
- export declare const Empty: () => import("react/jsx-runtime").JSX.Element | null;
@@ -1,21 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { Stack, Text } from "@mantine/core";
3
- import { useConversation } from "./ConversationContext.js";
4
- const Empty = ()=>{
5
- const { empty } = useConversation();
6
- return empty ? null : /*#__PURE__*/ jsxs(Stack, {
7
- align: "center",
8
- gap: 0,
9
- children: [
10
- /*#__PURE__*/ jsx(Text, {
11
- children: "Нет сообщений"
12
- }),
13
- /*#__PURE__*/ jsx(Text, {
14
- size: "sm",
15
- c: "dimmed",
16
- children: "Начните общение, чтобы увидеть сообщения здесь"
17
- })
18
- ]
19
- });
20
- };
21
- export { Empty };
@@ -1,4 +0,0 @@
1
- import type { UIMessage } from 'ai';
2
- export declare const File: <T extends UIMessage>({ message }: {
3
- message: T;
4
- }) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,42 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { Image, Paper } from "@mantine/core";
3
- import { FileIcon } from "./FileIcon.js";
4
- const File = ({ message })=>{
5
- const textFileType = message.id.split('-')[1];
6
- const fileParts = message.parts?.filter((i)=>'file' === i.type);
7
- const lastFilePart = fileParts[fileParts.length - 1];
8
- const FileComponent = ()=>{
9
- switch(textFileType){
10
- case 'excel':
11
- return /*#__PURE__*/ jsx(FileIcon, {
12
- mimeType: "excel"
13
- });
14
- case 'word':
15
- return /*#__PURE__*/ jsx(FileIcon, {
16
- mimeType: "word"
17
- });
18
- case 'powerpoint':
19
- return /*#__PURE__*/ jsx(FileIcon, {
20
- mimeType: "powerpoint"
21
- });
22
- }
23
- if (lastFilePart.mediaType.includes('image/')) return /*#__PURE__*/ jsx(Image, {
24
- radius: "md",
25
- h: 128,
26
- src: lastFilePart.url,
27
- alt: "Image Preview"
28
- });
29
- return /*#__PURE__*/ jsx(FileIcon, {
30
- mimeType: lastFilePart.mediaType
31
- });
32
- };
33
- return textFileType || lastFilePart ? /*#__PURE__*/ jsx(Paper, {
34
- radius: "md",
35
- px: "md",
36
- py: "sm",
37
- ml: "auto",
38
- bg: "var(--mantine-color-default-hover)",
39
- children: /*#__PURE__*/ jsx(FileComponent, {})
40
- }) : null;
41
- };
42
- export { File };
@@ -1,3 +0,0 @@
1
- export declare const FileIcon: ({ mimeType }: {
2
- mimeType: string;
3
- }) => import("react/jsx-runtime").JSX.Element;
@@ -1,225 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- const FileIcon = ({ mimeType })=>{
3
- switch(true){
4
- case mimeType.includes('image/'):
5
- return /*#__PURE__*/ jsxs("svg", {
6
- xmlns: "http://www.w3.org/2000/svg",
7
- width: "36",
8
- height: "36",
9
- viewBox: "0 0 36 36",
10
- fill: "none",
11
- stroke: "var(--mantine-color-text)",
12
- strokeWidth: "1.5",
13
- strokeLinecap: "round",
14
- strokeLinejoin: "round",
15
- role: "img",
16
- "aria-label": "Image",
17
- children: [
18
- /*#__PURE__*/ jsx("path", {
19
- stroke: "none",
20
- d: "M0 0h24v24H0z",
21
- fill: "none"
22
- }),
23
- /*#__PURE__*/ jsx("path", {
24
- d: "M15 8h.01"
25
- }),
26
- /*#__PURE__*/ jsx("path", {
27
- d: "M3 6a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v12a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3v-12"
28
- }),
29
- /*#__PURE__*/ jsx("path", {
30
- d: "M3 16l5 -5c.928 -.893 2.072 -.893 3 0l5 5"
31
- }),
32
- /*#__PURE__*/ jsx("path", {
33
- d: "M14 14l1 -1c.928 -.893 2.072 -.893 3 0l3 3"
34
- })
35
- ]
36
- });
37
- case mimeType.includes('application/pdf'):
38
- return /*#__PURE__*/ jsxs("svg", {
39
- xmlns: "http://www.w3.org/2000/svg",
40
- width: "36",
41
- height: "36",
42
- viewBox: "0 0 36 36",
43
- fill: "none",
44
- stroke: "var(--mantine-color-text)",
45
- strokeWidth: "1.5",
46
- strokeLinecap: "round",
47
- strokeLinejoin: "round",
48
- role: "img",
49
- "aria-label": "FilePdf",
50
- children: [
51
- /*#__PURE__*/ jsx("path", {
52
- stroke: "none",
53
- d: "M0 0h24v24H0z",
54
- fill: "none"
55
- }),
56
- /*#__PURE__*/ jsx("path", {
57
- d: "M14 3v4a1 1 0 0 0 1 1h4"
58
- }),
59
- /*#__PURE__*/ jsx("path", {
60
- d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"
61
- }),
62
- /*#__PURE__*/ jsx("path", {
63
- d: "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"
64
- }),
65
- /*#__PURE__*/ jsx("path", {
66
- d: "M17 18h2"
67
- }),
68
- /*#__PURE__*/ jsx("path", {
69
- d: "M20 15h-3v6"
70
- }),
71
- /*#__PURE__*/ jsx("path", {
72
- d: "M11 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1"
73
- })
74
- ]
75
- });
76
- case 'word' === mimeType:
77
- return /*#__PURE__*/ jsxs("svg", {
78
- xmlns: "http://www.w3.org/2000/svg",
79
- width: "36",
80
- height: "36",
81
- viewBox: "0 0 36 36",
82
- fill: "none",
83
- stroke: "var(--mantine-color-text)",
84
- strokeWidth: "1.5",
85
- strokeLinecap: "round",
86
- strokeLinejoin: "round",
87
- role: "img",
88
- "aria-label": "FileDoc",
89
- children: [
90
- /*#__PURE__*/ jsx("path", {
91
- stroke: "none",
92
- d: "M0 0h24v24H0z",
93
- fill: "none"
94
- }),
95
- /*#__PURE__*/ jsx("path", {
96
- d: "M14 3v4a1 1 0 0 0 1 1h4"
97
- }),
98
- /*#__PURE__*/ jsx("path", {
99
- d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"
100
- }),
101
- /*#__PURE__*/ jsx("path", {
102
- d: "M5 15v6h1a2 2 0 0 0 2 -2v-2a2 2 0 0 0 -2 -2h-1"
103
- }),
104
- /*#__PURE__*/ jsx("path", {
105
- d: "M20 16.5a1.5 1.5 0 0 0 -3 0v3a1.5 1.5 0 0 0 3 0"
106
- }),
107
- /*#__PURE__*/ jsx("path", {
108
- d: "M12.5 15a1.5 1.5 0 0 1 1.5 1.5v3a1.5 1.5 0 0 1 -3 0v-3a1.5 1.5 0 0 1 1.5 -1.5"
109
- })
110
- ]
111
- });
112
- case 'excel' === mimeType:
113
- return /*#__PURE__*/ jsxs("svg", {
114
- xmlns: "http://www.w3.org/2000/svg",
115
- width: "36",
116
- height: "36",
117
- viewBox: "0 0 36 36",
118
- fill: "none",
119
- stroke: "var(--mantine-color-text)",
120
- strokeWidth: "1.5",
121
- strokeLinecap: "round",
122
- strokeLinejoin: "round",
123
- role: "img",
124
- "aria-label": "FileXls",
125
- children: [
126
- /*#__PURE__*/ jsx("path", {
127
- stroke: "none",
128
- d: "M0 0h24v24H0z",
129
- fill: "none"
130
- }),
131
- /*#__PURE__*/ jsx("path", {
132
- d: "M14 3v4a1 1 0 0 0 1 1h4"
133
- }),
134
- /*#__PURE__*/ jsx("path", {
135
- d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"
136
- }),
137
- /*#__PURE__*/ jsx("path", {
138
- d: "M4 15l4 6"
139
- }),
140
- /*#__PURE__*/ jsx("path", {
141
- d: "M4 21l4 -6"
142
- }),
143
- /*#__PURE__*/ jsx("path", {
144
- d: "M17 20.25c0 .414 .336 .75 .75 .75h1.25a1 1 0 0 0 1 -1v-1a1 1 0 0 0 -1 -1h-1a1 1 0 0 1 -1 -1v-1a1 1 0 0 1 1 -1h1.25a.75 .75 0 0 1 .75 .75"
145
- }),
146
- /*#__PURE__*/ jsx("path", {
147
- d: "M11 15v6h3"
148
- })
149
- ]
150
- });
151
- case 'powerpoint' === mimeType:
152
- return /*#__PURE__*/ jsxs("svg", {
153
- xmlns: "http://www.w3.org/2000/svg",
154
- width: "36",
155
- height: "36",
156
- viewBox: "0 0 36 36",
157
- fill: "none",
158
- stroke: "var(--mantine-color-text)",
159
- strokeWidth: "1.5",
160
- strokeLinecap: "round",
161
- strokeLinejoin: "round",
162
- role: "img",
163
- "aria-label": "FilePpt",
164
- children: [
165
- /*#__PURE__*/ jsx("path", {
166
- stroke: "none",
167
- d: "M0 0h24v24H0z",
168
- fill: "none"
169
- }),
170
- /*#__PURE__*/ jsx("path", {
171
- d: "M14 3v4a1 1 0 0 0 1 1h4"
172
- }),
173
- /*#__PURE__*/ jsx("path", {
174
- d: "M14 3v4a1 1 0 0 0 1 1h4"
175
- }),
176
- /*#__PURE__*/ jsx("path", {
177
- d: "M5 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"
178
- }),
179
- /*#__PURE__*/ jsx("path", {
180
- d: "M11 18h1.5a1.5 1.5 0 0 0 0 -3h-1.5v6"
181
- }),
182
- /*#__PURE__*/ jsx("path", {
183
- d: "M16.5 15h3"
184
- }),
185
- /*#__PURE__*/ jsx("path", {
186
- d: "M18 15v6"
187
- }),
188
- /*#__PURE__*/ jsx("path", {
189
- d: "M5 12v-7a2 2 0 0 1 2 -2h7l5 5v4"
190
- })
191
- ]
192
- });
193
- default:
194
- return /*#__PURE__*/ jsxs("svg", {
195
- xmlns: "http://www.w3.org/2000/svg",
196
- width: "36",
197
- height: "36",
198
- viewBox: "0 0 36 36",
199
- fill: "none",
200
- stroke: "var(--mantine-color-text)",
201
- strokeWidth: "1.5",
202
- strokeLinecap: "round",
203
- strokeLinejoin: "round",
204
- role: "img",
205
- "aria-label": "File",
206
- children: [
207
- /*#__PURE__*/ jsx("path", {
208
- stroke: "none",
209
- d: "M0 0h24v24H0z",
210
- fill: "none"
211
- }),
212
- /*#__PURE__*/ jsx("path", {
213
- d: "M15 3v4a1 1 0 0 0 1 1h4"
214
- }),
215
- /*#__PURE__*/ jsx("path", {
216
- d: "M18 17h-7a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h4l5 5v7a2 2 0 0 1 -2 2"
217
- }),
218
- /*#__PURE__*/ jsx("path", {
219
- d: "M16 17v2a2 2 0 0 1 -2 2h-7a2 2 0 0 1 -2 -2v-10a2 2 0 0 1 2 -2h2"
220
- })
221
- ]
222
- });
223
- }
224
- };
225
- export { FileIcon };
@@ -1,2 +0,0 @@
1
- import { type LoaderProps } from '@mantine/core';
2
- export declare const Loader: (props: LoaderProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,12 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { Loader } from "@mantine/core";
3
- import { useConversation } from "./ConversationContext.js";
4
- const Loader_Loader = (props)=>{
5
- const { loading } = useConversation();
6
- return loading ? /*#__PURE__*/ jsx(Loader, {
7
- size: 28,
8
- type: "dots",
9
- ...props
10
- }) : null;
11
- };
12
- export { Loader_Loader as Loader };
@@ -1,4 +0,0 @@
1
- import type { UIMessage } from 'ai';
2
- export declare const Message: <T extends UIMessage>({ message }: {
3
- message: T;
4
- }) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,25 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { Paper } from "@mantine/core";
3
- import { Streamdown } from "streamdown";
4
- import { useConversation } from "./ConversationContext.js";
5
- import { useChatMessage } from "./useChatMessage.js";
6
- const Message = ({ message })=>{
7
- const textParts = message?.parts?.filter((i)=>'text' === i.type);
8
- const lastTextPart = textParts?.[textParts.length - 1];
9
- const chatMessage = useChatMessage(lastTextPart);
10
- const { streaming } = useConversation();
11
- return chatMessage && 'system' !== message.role ? /*#__PURE__*/ jsx(Paper, {
12
- radius: "md",
13
- px: "md",
14
- py: "sm",
15
- maw: "80%",
16
- ml: 'user' === message.role ? 'auto' : void 0,
17
- bg: 'user' === message.role ? 'var(--mantine-color-default-hover)' : 'var(--mantine-primary-color-light)',
18
- fz: "sm",
19
- children: /*#__PURE__*/ jsx(Streamdown, {
20
- isAnimating: streaming && 'assistant' === message.role,
21
- children: chatMessage
22
- })
23
- }) : null;
24
- };
25
- export { Message };
@@ -1,2 +0,0 @@
1
- import type { ConversationProps } from './types';
2
- export declare const Root: ({ children, loading, streaming, empty, ...props }: ConversationProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,26 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { Paper, Stack } from "@mantine/core";
3
- import { ScrollArea } from "../../../ui/scrollArea/index.js";
4
- import { Provider } from "./ConversationProvider.js";
5
- const Root = ({ children, loading, streaming, empty, ...props })=>/*#__PURE__*/ jsx(Provider, {
6
- loading: loading,
7
- streaming: streaming,
8
- empty: empty,
9
- children: /*#__PURE__*/ jsx(Paper, {
10
- withBorder: true,
11
- radius: "md",
12
- ...props,
13
- children: /*#__PURE__*/ jsxs(ScrollArea, {
14
- autoScroll: true,
15
- scrollToBottomOnInit: true,
16
- p: "md",
17
- children: [
18
- /*#__PURE__*/ jsx(Stack, {
19
- children: children
20
- }),
21
- /*#__PURE__*/ jsx(ScrollArea.ScrollButton, {})
22
- ]
23
- })
24
- })
25
- });
26
- export { Root };