@assistant-ui/react 0.10.10 → 0.10.12
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/primitives/composer/ComposerAttachmentDropzone.d.ts +13 -0
- package/dist/primitives/composer/ComposerAttachmentDropzone.d.ts.map +1 -0
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +56 -0
- package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -0
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +10 -7
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/tests/setup.js +8 -8
- package/dist/tests/setup.js.map +1 -1
- package/package.json +9 -9
- package/src/primitives/composer/ComposerAttachmentDropzone.tsx +70 -0
- package/src/primitives/thread/useThreadViewportAutoScroll.tsx +11 -8
package/package.json
CHANGED
@@ -28,7 +28,7 @@
|
|
28
28
|
"conversational-ui",
|
29
29
|
"conversational-ai"
|
30
30
|
],
|
31
|
-
"version": "0.10.
|
31
|
+
"version": "0.10.12",
|
32
32
|
"license": "MIT",
|
33
33
|
"type": "module",
|
34
34
|
"exports": {
|
@@ -51,18 +51,18 @@
|
|
51
51
|
"@radix-ui/primitive": "^1.1.2",
|
52
52
|
"@radix-ui/react-compose-refs": "^1.1.2",
|
53
53
|
"@radix-ui/react-context": "^1.1.2",
|
54
|
-
"@radix-ui/react-popover": "^1.1.
|
55
|
-
"@radix-ui/react-primitive": "^2.1.
|
56
|
-
"@radix-ui/react-slot": "^1.2.
|
54
|
+
"@radix-ui/react-popover": "^1.1.14",
|
55
|
+
"@radix-ui/react-primitive": "^2.1.3",
|
56
|
+
"@radix-ui/react-slot": "^1.2.3",
|
57
57
|
"@radix-ui/react-use-callback-ref": "^1.1.1",
|
58
58
|
"@radix-ui/react-use-escape-keydown": "^1.1.1",
|
59
59
|
"@standard-schema/spec": "^1.0.0",
|
60
|
-
"assistant-stream": "^0.2.
|
60
|
+
"assistant-stream": "^0.2.10",
|
61
61
|
"json-schema": "^0.4.0",
|
62
62
|
"nanoid": "5.1.5",
|
63
63
|
"react-textarea-autosize": "^8.5.9",
|
64
|
-
"zod": "^3.
|
65
|
-
"zustand": "^5.0.
|
64
|
+
"zod": "^3.25.28",
|
65
|
+
"zustand": "^5.0.5"
|
66
66
|
},
|
67
67
|
"peerDependencies": {
|
68
68
|
"@types/react": "*",
|
@@ -82,11 +82,11 @@
|
|
82
82
|
"@stryker-mutator/core": "^9.0.1",
|
83
83
|
"@stryker-mutator/vitest-runner": "^9.0.1",
|
84
84
|
"@types/json-schema": "^7.0.15",
|
85
|
-
"@types/node": "^22.15.
|
85
|
+
"@types/node": "^22.15.21",
|
86
86
|
"eslint": "^9",
|
87
87
|
"eslint-config-next": "15.3.2",
|
88
88
|
"tsx": "^4.19.4",
|
89
|
-
"vitest": "^3.1.
|
89
|
+
"vitest": "^3.1.4",
|
90
90
|
"@assistant-ui/x-buildutils": "0.0.1"
|
91
91
|
},
|
92
92
|
"publishConfig": {
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { forwardRef, useCallback, useState } from "react";
|
2
|
+
|
3
|
+
import { Slot } from "@radix-ui/react-slot";
|
4
|
+
import React from "react";
|
5
|
+
import { useComposerRuntime } from "../../context";
|
6
|
+
|
7
|
+
export namespace ComposerAttachmentDropzonePrimitive {
|
8
|
+
export type Element = HTMLDivElement;
|
9
|
+
export type Props = React.HTMLAttributes<HTMLDivElement> & {
|
10
|
+
asChild?: boolean | undefined;
|
11
|
+
disabled?: boolean | undefined;
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
export const ComposerAttachmentDropzone = forwardRef<
|
16
|
+
HTMLDivElement,
|
17
|
+
ComposerAttachmentDropzonePrimitive.Props
|
18
|
+
>(({ disabled, asChild = false, children, ...rest }, ref) => {
|
19
|
+
const [isDragging, setIsDragging] = useState(false);
|
20
|
+
const composerRuntime = useComposerRuntime();
|
21
|
+
|
22
|
+
const handleDrag = useCallback(
|
23
|
+
(e: React.DragEvent) => {
|
24
|
+
if (disabled) return;
|
25
|
+
e.preventDefault();
|
26
|
+
e.stopPropagation();
|
27
|
+
setIsDragging(e.type === "dragenter" || e.type === "dragover");
|
28
|
+
},
|
29
|
+
[disabled],
|
30
|
+
);
|
31
|
+
|
32
|
+
const handleDrop = useCallback(
|
33
|
+
async (e: React.DragEvent) => {
|
34
|
+
if (disabled) return;
|
35
|
+
e.preventDefault();
|
36
|
+
e.stopPropagation();
|
37
|
+
setIsDragging(false);
|
38
|
+
for (const file of e.dataTransfer.files) {
|
39
|
+
try {
|
40
|
+
await composerRuntime.addAttachment(file);
|
41
|
+
} catch (error) {
|
42
|
+
console.error("Failed to add attachment:", error);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
},
|
46
|
+
[disabled, composerRuntime],
|
47
|
+
);
|
48
|
+
|
49
|
+
const dragProps = {
|
50
|
+
onDragEnter: handleDrag,
|
51
|
+
onDragOver: handleDrag,
|
52
|
+
onDragLeave: handleDrag,
|
53
|
+
onDrop: handleDrop,
|
54
|
+
};
|
55
|
+
|
56
|
+
const Comp = asChild ? Slot : "div";
|
57
|
+
|
58
|
+
return (
|
59
|
+
<Comp
|
60
|
+
{...(isDragging ? { "data-dragging": "true" } : null)}
|
61
|
+
ref={ref}
|
62
|
+
{...dragProps}
|
63
|
+
{...rest}
|
64
|
+
>
|
65
|
+
{children}
|
66
|
+
</Comp>
|
67
|
+
);
|
68
|
+
});
|
69
|
+
|
70
|
+
ComposerAttachmentDropzone.displayName = "ComposerPrimitive.AttachmentDropzone";
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use client";
|
2
2
|
|
3
3
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
4
|
-
import { RefCallback, useEffect, useRef } from "react";
|
4
|
+
import { RefCallback, useCallback, useEffect, useRef } from "react";
|
5
5
|
import { useThreadRuntime } from "../../context/react/ThreadContext";
|
6
6
|
import { useOnResizeContent } from "../../utils/hooks/useOnResizeContent";
|
7
7
|
import { useOnScrollToBottom } from "../../utils/hooks/useOnScrollToBottom";
|
@@ -28,13 +28,16 @@ export const useThreadViewportAutoScroll = <TElement extends HTMLElement>({
|
|
28
28
|
// fix: delay the state change until the scroll is done
|
29
29
|
const isScrollingToBottomRef = useRef(false);
|
30
30
|
|
31
|
-
const scrollToBottom = (
|
32
|
-
|
33
|
-
|
31
|
+
const scrollToBottom = useCallback(
|
32
|
+
(behavior: ScrollBehavior) => {
|
33
|
+
const div = divRef.current;
|
34
|
+
if (!div || !autoScroll) return;
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
isScrollingToBottomRef.current = true;
|
37
|
+
div.scrollTo({ top: div.scrollHeight, behavior });
|
38
|
+
},
|
39
|
+
[autoScroll],
|
40
|
+
);
|
38
41
|
|
39
42
|
const handleScroll = () => {
|
40
43
|
const div = divRef.current;
|
@@ -90,5 +93,5 @@ export const useThreadViewportAutoScroll = <TElement extends HTMLElement>({
|
|
90
93
|
}, [scrollToBottom, threadRuntime]);
|
91
94
|
|
92
95
|
const autoScrollRef = useComposedRefs<TElement>(resizeRef, scrollRef, divRef);
|
93
|
-
return autoScrollRef
|
96
|
+
return autoScrollRef as RefCallback<TElement>;
|
94
97
|
};
|