@assistant-ui/react 0.11.39 → 0.11.43
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/client/AssistantClient.d.ts.map +1 -1
- package/dist/client/AssistantClient.js.map +1 -1
- package/dist/client/ModelContext.d.ts +1 -1
- package/dist/client/ModelContext.d.ts.map +1 -1
- package/dist/client/ModelContext.js.map +1 -1
- package/dist/client/ModelContextClient.d.ts +1 -1
- package/dist/client/ThreadMessageClient.d.ts +1 -0
- package/dist/client/ThreadMessageClient.d.ts.map +1 -1
- package/dist/client/ThreadMessageClient.js +3 -1
- package/dist/client/ThreadMessageClient.js.map +1 -1
- package/dist/client/types/Message.d.ts +2 -0
- package/dist/client/types/Message.d.ts.map +1 -1
- package/dist/client/types/ModelContext.d.ts +1 -1
- package/dist/client/types/ModelContext.d.ts.map +1 -1
- package/dist/client/types/Tools.d.ts +1 -2
- package/dist/client/types/Tools.d.ts.map +1 -1
- package/dist/context/providers/ThreadViewportProvider.d.ts +5 -1
- package/dist/context/providers/ThreadViewportProvider.d.ts.map +1 -1
- package/dist/context/providers/ThreadViewportProvider.js +17 -6
- package/dist/context/providers/ThreadViewportProvider.js.map +1 -1
- package/dist/context/react/AssistantApiContext.d.ts +1 -1
- package/dist/context/react/AssistantApiContext.d.ts.map +1 -1
- package/dist/context/react/AssistantApiContext.js +1 -2
- package/dist/context/react/AssistantApiContext.js.map +1 -1
- package/dist/context/stores/ThreadViewport.d.ts +33 -3
- package/dist/context/stores/ThreadViewport.d.ts.map +1 -1
- package/dist/context/stores/ThreadViewport.js +67 -5
- package/dist/context/stores/ThreadViewport.js.map +1 -1
- package/dist/devtools/DevToolsHooks.d.ts +1 -1
- package/dist/devtools/DevToolsHooks.d.ts.map +1 -1
- package/dist/devtools/DevToolsHooks.js.map +1 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.js +2 -1
- package/dist/legacy-runtime/AssistantRuntimeProvider.js.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts +3 -3
- package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/client/EventManagerRuntimeClient.d.ts +1 -1
- package/dist/legacy-runtime/client/ThreadRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/runtime/MessageRuntime.d.ts +3 -0
- package/dist/legacy-runtime/runtime/MessageRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime/MessageRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime/RuntimeBindings.d.ts +2 -0
- package/dist/legacy-runtime/runtime/RuntimeBindings.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts +1 -0
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.js +6 -3
- package/dist/legacy-runtime/runtime/ThreadRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/runManager.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +8 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +23 -11
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js +5 -5
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts +2 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts +2 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/RemoteThreadListThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js +2 -1
- package/dist/legacy-runtime/runtime-cores/utils/MessageRepository.js.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.d.ts +2 -2
- package/dist/primitives/composer/ComposerAttachmentDropzone.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerAttachmentDropzone.js +31 -11
- package/dist/primitives/composer/ComposerAttachmentDropzone.js.map +1 -1
- package/dist/primitives/composer/index.d.ts +1 -0
- package/dist/primitives/composer/index.d.ts.map +1 -1
- package/dist/primitives/composer/index.js +2 -0
- package/dist/primitives/composer/index.js.map +1 -1
- package/dist/primitives/message/MessageRoot.d.ts +3 -0
- package/dist/primitives/message/MessageRoot.d.ts.map +1 -1
- package/dist/primitives/message/MessageRoot.js +24 -2
- package/dist/primitives/message/MessageRoot.js.map +1 -1
- package/dist/primitives/messagePart/useMessagePartData.d.ts.map +1 -1
- package/dist/primitives/messagePart/useMessagePartData.js.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.d.ts +7 -2
- package/dist/primitives/thread/ThreadScrollToBottom.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadScrollToBottom.js +7 -4
- package/dist/primitives/thread/ThreadScrollToBottom.js.map +1 -1
- package/dist/primitives/thread/ThreadViewport.d.ts +17 -3
- package/dist/primitives/thread/ThreadViewport.d.ts.map +1 -1
- package/dist/primitives/thread/ThreadViewport.js +19 -5
- package/dist/primitives/thread/ThreadViewport.js.map +1 -1
- package/dist/primitives/thread/ThreadViewportFooter.d.ts +31 -0
- package/dist/primitives/thread/ThreadViewportFooter.d.ts.map +1 -0
- package/dist/primitives/thread/ThreadViewportFooter.js +27 -0
- package/dist/primitives/thread/ThreadViewportFooter.js.map +1 -0
- package/dist/primitives/thread/ThreadViewportSlack.d.ts +20 -0
- package/dist/primitives/thread/ThreadViewportSlack.d.ts.map +1 -0
- package/dist/primitives/thread/ThreadViewportSlack.js +77 -0
- package/dist/primitives/thread/ThreadViewportSlack.js.map +1 -0
- package/dist/primitives/thread/index.d.ts +3 -0
- package/dist/primitives/thread/index.d.ts.map +1 -1
- package/dist/primitives/thread/index.js +7 -1
- package/dist/primitives/thread/index.js.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts +6 -0
- package/dist/primitives/thread/useThreadViewportAutoScroll.d.ts.map +1 -1
- package/dist/primitives/thread/useThreadViewportAutoScroll.js +17 -8
- package/dist/primitives/thread/useThreadViewportAutoScroll.js.map +1 -1
- package/dist/tests/setup.js +14 -14
- package/dist/tests/setup.js.map +1 -1
- package/dist/utils/hooks/useOnScrollToBottom.d.ts +3 -1
- package/dist/utils/hooks/useOnScrollToBottom.d.ts.map +1 -1
- package/dist/utils/hooks/useOnScrollToBottom.js.map +1 -1
- package/dist/utils/hooks/useSizeHandle.d.ts +11 -0
- package/dist/utils/hooks/useSizeHandle.d.ts.map +1 -0
- package/dist/utils/hooks/useSizeHandle.js +30 -0
- package/dist/utils/hooks/useSizeHandle.js.map +1 -0
- package/dist/utils/tap-store/derived-scopes.d.ts +2 -1
- package/dist/utils/tap-store/derived-scopes.d.ts.map +1 -1
- package/dist/utils/tap-store/derived-scopes.js.map +1 -1
- package/dist/utils/tap-store/store.d.ts +2 -1
- package/dist/utils/tap-store/store.d.ts.map +1 -1
- package/dist/utils/tap-store/store.js.map +1 -1
- package/package.json +6 -6
- package/src/client/AssistantClient.ts +1 -1
- package/src/client/ModelContext.ts +1 -1
- package/src/client/ThreadMessageClient.tsx +4 -1
- package/src/client/types/Message.ts +3 -0
- package/src/client/types/ModelContext.ts +1 -1
- package/src/client/types/Tools.ts +1 -2
- package/src/context/providers/ThreadViewportProvider.tsx +27 -5
- package/src/context/react/AssistantApiContext.tsx +2 -5
- package/src/context/stores/ThreadViewport.tsx +125 -7
- package/src/devtools/DevToolsHooks.ts +1 -1
- package/src/legacy-runtime/AssistantRuntimeProvider.tsx +6 -1
- package/src/legacy-runtime/client/ComposerRuntimeClient.ts +3 -3
- package/src/legacy-runtime/client/ThreadRuntimeClient.ts +2 -2
- package/src/legacy-runtime/runtime/MessageRuntime.ts +2 -0
- package/src/legacy-runtime/runtime/RuntimeBindings.ts +2 -0
- package/src/legacy-runtime/runtime/ThreadRuntime.ts +6 -3
- package/src/legacy-runtime/runtime-cores/assistant-transport/runManager.ts +2 -2
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +8 -1
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +26 -11
- package/src/legacy-runtime/runtime-cores/assistant-transport/useToolInvocations.ts +5 -5
- package/src/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.tsx +1 -0
- package/src/legacy-runtime/runtime-cores/utils/MessageRepository.tsx +1 -0
- package/src/primitives/composer/ComposerAttachmentDropzone.tsx +35 -12
- package/src/primitives/composer/index.ts +1 -0
- package/src/primitives/message/MessageRoot.tsx +45 -2
- package/src/primitives/messagePart/useMessagePartData.tsx +0 -1
- package/src/primitives/thread/ThreadScrollToBottom.tsx +12 -3
- package/src/primitives/thread/ThreadViewport.tsx +35 -9
- package/src/primitives/thread/ThreadViewportFooter.tsx +57 -0
- package/src/primitives/thread/ThreadViewportSlack.tsx +109 -0
- package/src/primitives/thread/index.ts +3 -0
- package/src/primitives/thread/useThreadViewportAutoScroll.tsx +24 -12
- package/src/utils/hooks/useOnScrollToBottom.tsx +3 -1
- package/src/utils/hooks/useSizeHandle.ts +43 -0
- package/src/utils/tap-store/derived-scopes.ts +2 -1
- package/src/utils/tap-store/store.ts +1 -1
|
@@ -5,5 +5,6 @@ export { ComposerPrimitiveCancel as Cancel } from "./ComposerCancel";
|
|
|
5
5
|
export { ComposerPrimitiveAddAttachment as AddAttachment } from "./ComposerAddAttachment";
|
|
6
6
|
export { ComposerPrimitiveAttachments as Attachments } from "./ComposerAttachments";
|
|
7
7
|
export { ComposerPrimitiveAttachmentByIndex as AttachmentByIndex } from "./ComposerAttachments";
|
|
8
|
+
export { ComposerPrimitiveAttachmentDropzone as AttachmentDropzone } from "./ComposerAttachmentDropzone";
|
|
8
9
|
export { ComposerPrimitiveIf as If } from "./ComposerIf";
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,sBAAsB,IAAI,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,8BAA8B,IAAI,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,4BAA4B,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,kCAAkC,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,mBAAmB,IAAI,EAAE,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/composer/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,sBAAsB,IAAI,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,qBAAqB,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,uBAAuB,IAAI,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,EAAE,8BAA8B,IAAI,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,4BAA4B,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,kCAAkC,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAE,mCAAmC,IAAI,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACzG,OAAO,EAAE,mBAAmB,IAAI,EAAE,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -6,10 +6,12 @@ import { ComposerPrimitiveCancel } from "./ComposerCancel.js";
|
|
|
6
6
|
import { ComposerPrimitiveAddAttachment } from "./ComposerAddAttachment.js";
|
|
7
7
|
import { ComposerPrimitiveAttachments } from "./ComposerAttachments.js";
|
|
8
8
|
import { ComposerPrimitiveAttachmentByIndex } from "./ComposerAttachments.js";
|
|
9
|
+
import { ComposerPrimitiveAttachmentDropzone } from "./ComposerAttachmentDropzone.js";
|
|
9
10
|
import { ComposerPrimitiveIf } from "./ComposerIf.js";
|
|
10
11
|
export {
|
|
11
12
|
ComposerPrimitiveAddAttachment as AddAttachment,
|
|
12
13
|
ComposerPrimitiveAttachmentByIndex as AttachmentByIndex,
|
|
14
|
+
ComposerPrimitiveAttachmentDropzone as AttachmentDropzone,
|
|
13
15
|
ComposerPrimitiveAttachments as Attachments,
|
|
14
16
|
ComposerPrimitiveCancel as Cancel,
|
|
15
17
|
ComposerPrimitiveIf as If,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/composer/index.ts"],"sourcesContent":["export { ComposerPrimitiveRoot as Root } from \"./ComposerRoot\";\nexport { ComposerPrimitiveInput as Input } from \"./ComposerInput\";\nexport { ComposerPrimitiveSend as Send } from \"./ComposerSend\";\nexport { ComposerPrimitiveCancel as Cancel } from \"./ComposerCancel\";\nexport { ComposerPrimitiveAddAttachment as AddAttachment } from \"./ComposerAddAttachment\";\nexport { ComposerPrimitiveAttachments as Attachments } from \"./ComposerAttachments\";\nexport { ComposerPrimitiveAttachmentByIndex as AttachmentByIndex } from \"./ComposerAttachments\";\nexport { ComposerPrimitiveIf as If } from \"./ComposerIf\";\n"],"mappings":";AAAA,SAAkC,6BAAY;AAC9C,SAAmC,8BAAa;AAChD,SAAkC,6BAAY;AAC9C,SAAoC,+BAAc;AAClD,SAA2C,sCAAqB;AAChE,SAAyC,oCAAmB;AAC5D,SAA+C,0CAAyB;AACxE,SAAgC,2BAAU;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/composer/index.ts"],"sourcesContent":["export { ComposerPrimitiveRoot as Root } from \"./ComposerRoot\";\nexport { ComposerPrimitiveInput as Input } from \"./ComposerInput\";\nexport { ComposerPrimitiveSend as Send } from \"./ComposerSend\";\nexport { ComposerPrimitiveCancel as Cancel } from \"./ComposerCancel\";\nexport { ComposerPrimitiveAddAttachment as AddAttachment } from \"./ComposerAddAttachment\";\nexport { ComposerPrimitiveAttachments as Attachments } from \"./ComposerAttachments\";\nexport { ComposerPrimitiveAttachmentByIndex as AttachmentByIndex } from \"./ComposerAttachments\";\nexport { ComposerPrimitiveAttachmentDropzone as AttachmentDropzone } from \"./ComposerAttachmentDropzone\";\nexport { ComposerPrimitiveIf as If } from \"./ComposerIf\";\n"],"mappings":";AAAA,SAAkC,6BAAY;AAC9C,SAAmC,8BAAa;AAChD,SAAkC,6BAAY;AAC9C,SAAoC,+BAAc;AAClD,SAA2C,sCAAqB;AAChE,SAAyC,oCAAmB;AAC5D,SAA+C,0CAAyB;AACxE,SAAgD,2CAA0B;AAC1E,SAAgC,2BAAU;","names":[]}
|
|
@@ -15,6 +15,9 @@ export declare namespace MessagePrimitiveRoot {
|
|
|
15
15
|
* hover state management for the message. It automatically tracks when the user
|
|
16
16
|
* is hovering over the message, which can be used by child components like action bars.
|
|
17
17
|
*
|
|
18
|
+
* When `turnAnchor="top"` is set on the viewport, this component
|
|
19
|
+
* registers itself as the scroll anchor if it's the last user message.
|
|
20
|
+
*
|
|
18
21
|
* @example
|
|
19
22
|
* ```tsx
|
|
20
23
|
* <MessagePrimitive.Root>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,wBAAwB,EAEzB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"MessageRoot.d.ts","sourceRoot":"","sources":["../../../src/primitives/message/MessageRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,wBAAwB,EAEzB,MAAM,OAAO,CAAC;AAkEf,yBAAiB,oBAAoB,CAAC;IACpC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACzD;;;OAGG;IACH,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;CACpE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,oBAAoB;;0DAiB/B,CAAC"}
|
|
@@ -8,7 +8,10 @@ import {
|
|
|
8
8
|
} from "react";
|
|
9
9
|
import { useAssistantApi, useAssistantState } from "../../context/index.js";
|
|
10
10
|
import { useManagedRef } from "../../utils/hooks/useManagedRef.js";
|
|
11
|
+
import { useSizeHandle } from "../../utils/hooks/useSizeHandle.js";
|
|
11
12
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
13
|
+
import { useThreadViewport } from "../../context/react/ThreadViewportContext.js";
|
|
14
|
+
import { ThreadPrimitiveViewportSlack } from "../thread/ThreadViewportSlack.js";
|
|
12
15
|
import { jsx } from "react/jsx-runtime";
|
|
13
16
|
var useIsHoveringRef = () => {
|
|
14
17
|
const api = useAssistantApi();
|
|
@@ -34,10 +37,29 @@ var useIsHoveringRef = () => {
|
|
|
34
37
|
);
|
|
35
38
|
return useManagedRef(callbackRef);
|
|
36
39
|
};
|
|
40
|
+
var useMessageViewportRef = () => {
|
|
41
|
+
const turnAnchor = useThreadViewport((s) => s.turnAnchor);
|
|
42
|
+
const registerUserHeight = useThreadViewport(
|
|
43
|
+
(s) => s.registerUserMessageHeight
|
|
44
|
+
);
|
|
45
|
+
const shouldRegisterAsInset = useAssistantState(
|
|
46
|
+
({ thread, message }) => turnAnchor === "top" && message.role === "user" && message.index === thread.messages.length - 2 && thread.messages.at(-1)?.role === "assistant"
|
|
47
|
+
);
|
|
48
|
+
const getHeight = useCallback((el) => el.offsetHeight, []);
|
|
49
|
+
return useSizeHandle(
|
|
50
|
+
shouldRegisterAsInset ? registerUserHeight : null,
|
|
51
|
+
getHeight
|
|
52
|
+
);
|
|
53
|
+
};
|
|
37
54
|
var MessagePrimitiveRoot = forwardRef((props, forwardRef2) => {
|
|
38
55
|
const isHoveringRef = useIsHoveringRef();
|
|
39
|
-
const
|
|
40
|
-
|
|
56
|
+
const anchorUserMessageRef = useMessageViewportRef();
|
|
57
|
+
const ref = useComposedRefs(
|
|
58
|
+
forwardRef2,
|
|
59
|
+
isHoveringRef,
|
|
60
|
+
anchorUserMessageRef
|
|
61
|
+
);
|
|
62
|
+
return /* @__PURE__ */ jsx(ThreadPrimitiveViewportSlack, { children: /* @__PURE__ */ jsx(Primitive.div, { ...props, ref }) });
|
|
41
63
|
});
|
|
42
64
|
MessagePrimitiveRoot.displayName = "MessagePrimitive.Root";
|
|
43
65
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/message/MessageRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ComponentRef,\n forwardRef,\n ComponentPropsWithoutRef,\n useCallback,\n} from \"react\";\nimport { useAssistantApi, useAssistantState } from \"../../context\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\n\nconst useIsHoveringRef = () => {\n const api = useAssistantApi();\n const message = useAssistantState(() => api.message());\n\n const callbackRef = useCallback(\n (el: HTMLElement) => {\n const handleMouseEnter = () => {\n message.setIsHovering(true);\n };\n const handleMouseLeave = () => {\n message.setIsHovering(false);\n };\n\n el.addEventListener(\"mouseenter\", handleMouseEnter);\n el.addEventListener(\"mouseleave\", handleMouseLeave);\n\n if (el.matches(\":hover\")) message.setIsHovering(true);\n\n return () => {\n el.removeEventListener(\"mouseenter\", handleMouseEnter);\n el.removeEventListener(\"mouseleave\", handleMouseLeave);\n message.setIsHovering(false);\n };\n },\n [message],\n );\n\n return useManagedRef(callbackRef);\n};\n\nexport namespace MessagePrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.div>;\n /**\n * Props for the MessagePrimitive.Root component.\n * Accepts all standard div element props.\n */\n export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;\n}\n\n/**\n * The root container component for a message.\n *\n * This component provides the foundational wrapper for message content and handles\n * hover state management for the message. It automatically tracks when the user\n * is hovering over the message, which can be used by child components like action bars.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Root>\n * <MessagePrimitive.Content />\n * <ActionBarPrimitive.Root>\n * <ActionBarPrimitive.Copy />\n * <ActionBarPrimitive.Edit />\n * </ActionBarPrimitive.Root>\n * </MessagePrimitive.Root>\n * ```\n */\nexport const MessagePrimitiveRoot = forwardRef<\n MessagePrimitiveRoot.Element,\n MessagePrimitiveRoot.Props\n>((props, forwardRef) => {\n const isHoveringRef = useIsHoveringRef();\n const ref = useComposedRefs<HTMLDivElement>(forwardRef
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/message/MessageRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ComponentRef,\n forwardRef,\n ComponentPropsWithoutRef,\n useCallback,\n} from \"react\";\nimport { useAssistantApi, useAssistantState } from \"../../context\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\nimport { useSizeHandle } from \"../../utils/hooks/useSizeHandle\";\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { useThreadViewport } from \"../../context/react/ThreadViewportContext\";\nimport { ThreadPrimitiveViewportSlack } from \"../thread/ThreadViewportSlack\";\n\nconst useIsHoveringRef = () => {\n const api = useAssistantApi();\n const message = useAssistantState(() => api.message());\n\n const callbackRef = useCallback(\n (el: HTMLElement) => {\n const handleMouseEnter = () => {\n message.setIsHovering(true);\n };\n const handleMouseLeave = () => {\n message.setIsHovering(false);\n };\n\n el.addEventListener(\"mouseenter\", handleMouseEnter);\n el.addEventListener(\"mouseleave\", handleMouseLeave);\n\n if (el.matches(\":hover\")) message.setIsHovering(true);\n\n return () => {\n el.removeEventListener(\"mouseenter\", handleMouseEnter);\n el.removeEventListener(\"mouseleave\", handleMouseLeave);\n message.setIsHovering(false);\n };\n },\n [message],\n );\n\n return useManagedRef(callbackRef);\n};\n\n/**\n * Hook that registers the anchor user message as a content inset.\n * Only registers if: user message, at index messages.length-2, and last message is assistant.\n */\nconst useMessageViewportRef = () => {\n const turnAnchor = useThreadViewport((s) => s.turnAnchor);\n const registerUserHeight = useThreadViewport(\n (s) => s.registerUserMessageHeight,\n );\n\n // inset rules:\n // - the previous user message before the last assistant message registers its full height\n const shouldRegisterAsInset = useAssistantState(\n ({ thread, message }) =>\n turnAnchor === \"top\" &&\n message.role === \"user\" &&\n message.index === thread.messages.length - 2 &&\n thread.messages.at(-1)?.role === \"assistant\",\n );\n\n const getHeight = useCallback((el: HTMLElement) => el.offsetHeight, []);\n\n return useSizeHandle(\n shouldRegisterAsInset ? registerUserHeight : null,\n getHeight,\n );\n};\n\nexport namespace MessagePrimitiveRoot {\n export type Element = ComponentRef<typeof Primitive.div>;\n /**\n * Props for the MessagePrimitive.Root component.\n * Accepts all standard div element props.\n */\n export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;\n}\n\n/**\n * The root container component for a message.\n *\n * This component provides the foundational wrapper for message content and handles\n * hover state management for the message. It automatically tracks when the user\n * is hovering over the message, which can be used by child components like action bars.\n *\n * When `turnAnchor=\"top\"` is set on the viewport, this component\n * registers itself as the scroll anchor if it's the last user message.\n *\n * @example\n * ```tsx\n * <MessagePrimitive.Root>\n * <MessagePrimitive.Content />\n * <ActionBarPrimitive.Root>\n * <ActionBarPrimitive.Copy />\n * <ActionBarPrimitive.Edit />\n * </ActionBarPrimitive.Root>\n * </MessagePrimitive.Root>\n * ```\n */\nexport const MessagePrimitiveRoot = forwardRef<\n MessagePrimitiveRoot.Element,\n MessagePrimitiveRoot.Props\n>((props, forwardRef) => {\n const isHoveringRef = useIsHoveringRef();\n const anchorUserMessageRef = useMessageViewportRef();\n const ref = useComposedRefs<HTMLDivElement>(\n forwardRef,\n isHoveringRef,\n anchorUserMessageRef,\n );\n\n return (\n <ThreadPrimitiveViewportSlack>\n <Primitive.div {...props} ref={ref} />\n </ThreadPrimitiveViewportSlack>\n );\n});\n\nMessagePrimitiveRoot.displayName = \"MessagePrimitive.Root\";\n"],"mappings":";;;AAEA,SAAS,iBAAiB;AAC1B;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,iBAAiB,yBAAyB;AACnD,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,uBAAuB;AAChC,SAAS,yBAAyB;AAClC,SAAS,oCAAoC;AAwGvC;AAtGN,IAAM,mBAAmB,MAAM;AAC7B,QAAM,MAAM,gBAAgB;AAC5B,QAAM,UAAU,kBAAkB,MAAM,IAAI,QAAQ,CAAC;AAErD,QAAM,cAAc;AAAA,IAClB,CAAC,OAAoB;AACnB,YAAM,mBAAmB,MAAM;AAC7B,gBAAQ,cAAc,IAAI;AAAA,MAC5B;AACA,YAAM,mBAAmB,MAAM;AAC7B,gBAAQ,cAAc,KAAK;AAAA,MAC7B;AAEA,SAAG,iBAAiB,cAAc,gBAAgB;AAClD,SAAG,iBAAiB,cAAc,gBAAgB;AAElD,UAAI,GAAG,QAAQ,QAAQ,EAAG,SAAQ,cAAc,IAAI;AAEpD,aAAO,MAAM;AACX,WAAG,oBAAoB,cAAc,gBAAgB;AACrD,WAAG,oBAAoB,cAAc,gBAAgB;AACrD,gBAAQ,cAAc,KAAK;AAAA,MAC7B;AAAA,IACF;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,SAAO,cAAc,WAAW;AAClC;AAMA,IAAM,wBAAwB,MAAM;AAClC,QAAM,aAAa,kBAAkB,CAAC,MAAM,EAAE,UAAU;AACxD,QAAM,qBAAqB;AAAA,IACzB,CAAC,MAAM,EAAE;AAAA,EACX;AAIA,QAAM,wBAAwB;AAAA,IAC5B,CAAC,EAAE,QAAQ,QAAQ,MACjB,eAAe,SACf,QAAQ,SAAS,UACjB,QAAQ,UAAU,OAAO,SAAS,SAAS,KAC3C,OAAO,SAAS,GAAG,EAAE,GAAG,SAAS;AAAA,EACrC;AAEA,QAAM,YAAY,YAAY,CAAC,OAAoB,GAAG,cAAc,CAAC,CAAC;AAEtE,SAAO;AAAA,IACL,wBAAwB,qBAAqB;AAAA,IAC7C;AAAA,EACF;AACF;AAgCO,IAAM,uBAAuB,WAGlC,CAAC,OAAOA,gBAAe;AACvB,QAAM,gBAAgB,iBAAiB;AACvC,QAAM,uBAAuB,sBAAsB;AACnD,QAAM,MAAM;AAAA,IACVA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SACE,oBAAC,gCACC,8BAAC,UAAU,KAAV,EAAe,GAAG,OAAO,KAAU,GACtC;AAEJ,CAAC;AAED,qBAAqB,cAAc;","names":["forwardRef"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMessagePartData.d.ts","sourceRoot":"","sources":["../../../src/primitives/messagePart/useMessagePartData.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"useMessagePartData.d.ts","sourceRoot":"","sources":["../../../src/primitives/messagePart/useMessagePartData.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,eAAO,MAAM,kBAAkB,GAAI,CAAC,GAAG,GAAG,EAAG,OAAO,MAAM,8BAiBzD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/messagePart/useMessagePartData.tsx"],"sourcesContent":["\"use client\";\n\nimport { useAssistantState } from \"../../context\";\nimport { DataMessagePart } from \"../../types\";\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/messagePart/useMessagePartData.tsx"],"sourcesContent":["\"use client\";\n\nimport { useAssistantState } from \"../../context\";\nimport { DataMessagePart } from \"../../types\";\n\nexport const useMessagePartData = <T = any,>(name?: string) => {\n const part = useAssistantState(({ part }) => {\n if (part.type !== \"data\") {\n return null;\n }\n return part as DataMessagePart<T>;\n });\n\n if (!part) {\n return null;\n }\n\n if (name && part.name !== name) {\n return null;\n }\n\n return part;\n};\n"],"mappings":";;;AAEA,SAAS,yBAAyB;AAG3B,IAAM,qBAAqB,CAAW,SAAkB;AAC7D,QAAM,OAAO,kBAAkB,CAAC,EAAE,MAAAA,MAAK,MAAM;AAC3C,QAAIA,MAAK,SAAS,QAAQ;AACxB,aAAO;AAAA,IACT;AACA,WAAOA;AAAA,EACT,CAAC;AAED,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,MAAI,QAAQ,KAAK,SAAS,MAAM;AAC9B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":["part"]}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { ActionButtonElement, ActionButtonProps } from "../../utils/createActionButton";
|
|
2
|
-
declare
|
|
2
|
+
export declare namespace useThreadScrollToBottom {
|
|
3
|
+
type Options = {
|
|
4
|
+
behavior?: ScrollBehavior | undefined;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
declare const useThreadScrollToBottom: ({ behavior, }?: useThreadScrollToBottom.Options) => (() => void) | null;
|
|
3
8
|
export declare namespace ThreadPrimitiveScrollToBottom {
|
|
4
9
|
type Element = ActionButtonElement;
|
|
5
10
|
type Props = ActionButtonProps<typeof useThreadScrollToBottom>;
|
|
6
11
|
}
|
|
7
12
|
export declare const ThreadPrimitiveScrollToBottom: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLButtonElement> & import("react").ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
8
13
|
asChild?: boolean;
|
|
9
|
-
}, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
14
|
+
}, "ref"> & useThreadScrollToBottom.Options & import("react").RefAttributes<HTMLButtonElement>>;
|
|
10
15
|
export {};
|
|
11
16
|
//# sourceMappingURL=ThreadScrollToBottom.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadScrollToBottom.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadScrollToBottom.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EAElB,MAAM,gCAAgC,CAAC;AAOxC,QAAA,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"ThreadScrollToBottom.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadScrollToBottom.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EAElB,MAAM,gCAAgC,CAAC;AAOxC,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,OAAO,GAAG;QACpB,QAAQ,CAAC,EAAE,cAAc,GAAG,SAAS,CAAC;KACvC,CAAC;CACH;AAED,QAAA,MAAM,uBAAuB,GAAI,gBAE9B,uBAAuB,CAAC,OAAY,wBAWtC,CAAC;AAEF,yBAAiB,6BAA6B,CAAC;IAC7C,KAAY,OAAO,GAAG,mBAAmB,CAAC;IAC1C,KAAY,KAAK,GAAG,iBAAiB,CAAC,OAAO,uBAAuB,CAAC,CAAC;CACvE;AAED,eAAO,MAAM,6BAA6B;;+FAIzC,CAAC"}
|
|
@@ -9,18 +9,21 @@ import {
|
|
|
9
9
|
useThreadViewport,
|
|
10
10
|
useThreadViewportStore
|
|
11
11
|
} from "../../context/react/ThreadViewportContext.js";
|
|
12
|
-
var useThreadScrollToBottom = (
|
|
12
|
+
var useThreadScrollToBottom = ({
|
|
13
|
+
behavior
|
|
14
|
+
} = {}) => {
|
|
13
15
|
const isAtBottom = useThreadViewport((s) => s.isAtBottom);
|
|
14
16
|
const threadViewportStore = useThreadViewportStore();
|
|
15
17
|
const handleScrollToBottom = useCallback(() => {
|
|
16
|
-
threadViewportStore.getState().scrollToBottom();
|
|
17
|
-
}, [threadViewportStore]);
|
|
18
|
+
threadViewportStore.getState().scrollToBottom({ behavior });
|
|
19
|
+
}, [threadViewportStore, behavior]);
|
|
18
20
|
if (isAtBottom) return null;
|
|
19
21
|
return handleScrollToBottom;
|
|
20
22
|
};
|
|
21
23
|
var ThreadPrimitiveScrollToBottom = createActionButton(
|
|
22
24
|
"ThreadPrimitive.ScrollToBottom",
|
|
23
|
-
useThreadScrollToBottom
|
|
25
|
+
useThreadScrollToBottom,
|
|
26
|
+
["behavior"]
|
|
24
27
|
);
|
|
25
28
|
export {
|
|
26
29
|
ThreadPrimitiveScrollToBottom
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/thread/ThreadScrollToBottom.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ActionButtonElement,\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useCallback } from \"react\";\nimport {\n useThreadViewport,\n useThreadViewportStore,\n} from \"../../context/react/ThreadViewportContext\";\n\nconst useThreadScrollToBottom = () => {\n const isAtBottom = useThreadViewport((s) => s.isAtBottom);\n\n const threadViewportStore = useThreadViewportStore();\n\n const handleScrollToBottom = useCallback(() => {\n threadViewportStore.getState().scrollToBottom();\n }, [threadViewportStore]);\n\n if (isAtBottom) return null;\n return handleScrollToBottom;\n};\n\nexport namespace ThreadPrimitiveScrollToBottom {\n export type Element = ActionButtonElement;\n export type Props = ActionButtonProps<typeof useThreadScrollToBottom>;\n}\n\nexport const ThreadPrimitiveScrollToBottom = createActionButton(\n \"ThreadPrimitive.ScrollToBottom\",\n useThreadScrollToBottom,\n);\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,OACK;
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/thread/ThreadScrollToBottom.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n ActionButtonElement,\n ActionButtonProps,\n createActionButton,\n} from \"../../utils/createActionButton\";\nimport { useCallback } from \"react\";\nimport {\n useThreadViewport,\n useThreadViewportStore,\n} from \"../../context/react/ThreadViewportContext\";\n\nexport namespace useThreadScrollToBottom {\n export type Options = {\n behavior?: ScrollBehavior | undefined;\n };\n}\n\nconst useThreadScrollToBottom = ({\n behavior,\n}: useThreadScrollToBottom.Options = {}) => {\n const isAtBottom = useThreadViewport((s) => s.isAtBottom);\n\n const threadViewportStore = useThreadViewportStore();\n\n const handleScrollToBottom = useCallback(() => {\n threadViewportStore.getState().scrollToBottom({ behavior });\n }, [threadViewportStore, behavior]);\n\n if (isAtBottom) return null;\n return handleScrollToBottom;\n};\n\nexport namespace ThreadPrimitiveScrollToBottom {\n export type Element = ActionButtonElement;\n export type Props = ActionButtonProps<typeof useThreadScrollToBottom>;\n}\n\nexport const ThreadPrimitiveScrollToBottom = createActionButton(\n \"ThreadPrimitive.ScrollToBottom\",\n useThreadScrollToBottom,\n [\"behavior\"],\n);\n"],"mappings":";;;AAEA;AAAA,EAGE;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAQP,IAAM,0BAA0B,CAAC;AAAA,EAC/B;AACF,IAAqC,CAAC,MAAM;AAC1C,QAAM,aAAa,kBAAkB,CAAC,MAAM,EAAE,UAAU;AAExD,QAAM,sBAAsB,uBAAuB;AAEnD,QAAM,uBAAuB,YAAY,MAAM;AAC7C,wBAAoB,SAAS,EAAE,eAAe,EAAE,SAAS,CAAC;AAAA,EAC5D,GAAG,CAAC,qBAAqB,QAAQ,CAAC;AAElC,MAAI,WAAY,QAAO;AACvB,SAAO;AACT;AAOO,IAAM,gCAAgC;AAAA,EAC3C;AAAA,EACA;AAAA,EACA,CAAC,UAAU;AACb;","names":[]}
|
|
@@ -6,9 +6,16 @@ export declare namespace ThreadPrimitiveViewport {
|
|
|
6
6
|
/**
|
|
7
7
|
* Whether to automatically scroll to the bottom when new messages are added.
|
|
8
8
|
* When enabled, the viewport will automatically scroll to show the latest content.
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* Default false if `turnAnchor` is "top", otherwise defaults to true.
|
|
10
11
|
*/
|
|
11
12
|
autoScroll?: boolean | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Controls scroll anchoring behavior for new messages.
|
|
15
|
+
* - "bottom" (default): Messages anchor at the bottom, classic chat behavior.
|
|
16
|
+
* - "top": New user messages anchor at the top of the viewport for a focused reading experience.
|
|
17
|
+
*/
|
|
18
|
+
turnAnchor?: "top" | "bottom" | undefined;
|
|
12
19
|
};
|
|
13
20
|
}
|
|
14
21
|
/**
|
|
@@ -20,7 +27,7 @@ export declare namespace ThreadPrimitiveViewport {
|
|
|
20
27
|
*
|
|
21
28
|
* @example
|
|
22
29
|
* ```tsx
|
|
23
|
-
* <ThreadPrimitive.Viewport
|
|
30
|
+
* <ThreadPrimitive.Viewport turnAnchor="top">
|
|
24
31
|
* <ThreadPrimitive.Messages components={{ Message: MyMessage }} />
|
|
25
32
|
* </ThreadPrimitive.Viewport>
|
|
26
33
|
* ```
|
|
@@ -31,8 +38,15 @@ export declare const ThreadPrimitiveViewport: import("react").ForwardRefExoticCo
|
|
|
31
38
|
/**
|
|
32
39
|
* Whether to automatically scroll to the bottom when new messages are added.
|
|
33
40
|
* When enabled, the viewport will automatically scroll to show the latest content.
|
|
34
|
-
*
|
|
41
|
+
*
|
|
42
|
+
* Default false if `turnAnchor` is "top", otherwise defaults to true.
|
|
35
43
|
*/
|
|
36
44
|
autoScroll?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Controls scroll anchoring behavior for new messages.
|
|
47
|
+
* - "bottom" (default): Messages anchor at the bottom, classic chat behavior.
|
|
48
|
+
* - "top": New user messages anchor at the top of the viewport for a focused reading experience.
|
|
49
|
+
*/
|
|
50
|
+
turnAnchor?: "top" | "bottom" | undefined;
|
|
37
51
|
} & import("react").RefAttributes<HTMLDivElement>>;
|
|
38
52
|
//# sourceMappingURL=ThreadViewport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThreadViewport.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadViewport.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,
|
|
1
|
+
{"version":3,"file":"ThreadViewport.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadViewport.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,wBAAwB,EAEzB,MAAM,OAAO,CAAC;AAMf,yBAAiB,uBAAuB,CAAC;IACvC,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACzD,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,GAAG;QACnE;;;;;WAKG;QACH,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAEjC;;;;WAIG;QACH,UAAU,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,SAAS,CAAC;KAC3C,CAAC;CACH;AAiCD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB;;;IA9DhC;;;;;OAKG;iBACU,OAAO,GAAG,SAAS;IAEhC;;;;OAIG;iBACU,KAAK,GAAG,QAAQ,GAAG,SAAS;kDA0D3C,CAAC"}
|
|
@@ -3,20 +3,34 @@
|
|
|
3
3
|
// src/primitives/thread/ThreadViewport.tsx
|
|
4
4
|
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
5
5
|
import { Primitive } from "@radix-ui/react-primitive";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
forwardRef,
|
|
8
|
+
useCallback
|
|
9
|
+
} from "react";
|
|
7
10
|
import { useThreadViewportAutoScroll } from "./useThreadViewportAutoScroll.js";
|
|
8
|
-
import {
|
|
11
|
+
import { ThreadPrimitiveViewportProvider } from "../../context/providers/ThreadViewportProvider.js";
|
|
12
|
+
import { useSizeHandle } from "../../utils/hooks/useSizeHandle.js";
|
|
13
|
+
import { useThreadViewport } from "../../context/react/ThreadViewportContext.js";
|
|
9
14
|
import { jsx } from "react/jsx-runtime";
|
|
15
|
+
var useViewportSizeRef = () => {
|
|
16
|
+
const register = useThreadViewport((s) => s.registerViewport);
|
|
17
|
+
const getHeight = useCallback(
|
|
18
|
+
(el) => el.clientHeight - parseFloat(getComputedStyle(el).paddingTop),
|
|
19
|
+
[]
|
|
20
|
+
);
|
|
21
|
+
return useSizeHandle(register, getHeight);
|
|
22
|
+
};
|
|
10
23
|
var ThreadPrimitiveViewportScrollable = forwardRef(({ autoScroll, children, ...rest }, forwardedRef) => {
|
|
11
24
|
const autoScrollRef = useThreadViewportAutoScroll({
|
|
12
25
|
autoScroll
|
|
13
26
|
});
|
|
14
|
-
const
|
|
27
|
+
const viewportSizeRef = useViewportSizeRef();
|
|
28
|
+
const ref = useComposedRefs(forwardedRef, autoScrollRef, viewportSizeRef);
|
|
15
29
|
return /* @__PURE__ */ jsx(Primitive.div, { ...rest, ref, children });
|
|
16
30
|
});
|
|
17
31
|
ThreadPrimitiveViewportScrollable.displayName = "ThreadPrimitive.ViewportScrollable";
|
|
18
|
-
var ThreadPrimitiveViewport = forwardRef((props, ref) => {
|
|
19
|
-
return /* @__PURE__ */ jsx(
|
|
32
|
+
var ThreadPrimitiveViewport = forwardRef(({ turnAnchor, ...props }, ref) => {
|
|
33
|
+
return /* @__PURE__ */ jsx(ThreadPrimitiveViewportProvider, { options: { turnAnchor }, children: /* @__PURE__ */ jsx(ThreadPrimitiveViewportScrollable, { ...props, ref }) });
|
|
20
34
|
});
|
|
21
35
|
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
|
22
36
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/thread/ThreadViewport.tsx"],"sourcesContent":["\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/thread/ThreadViewport.tsx"],"sourcesContent":["\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ComponentRef,\n forwardRef,\n ComponentPropsWithoutRef,\n useCallback,\n} from \"react\";\nimport { useThreadViewportAutoScroll } from \"./useThreadViewportAutoScroll\";\nimport { ThreadPrimitiveViewportProvider } from \"../../context/providers/ThreadViewportProvider\";\nimport { useSizeHandle } from \"../../utils/hooks/useSizeHandle\";\nimport { useThreadViewport } from \"../../context/react/ThreadViewportContext\";\n\nexport namespace ThreadPrimitiveViewport {\n export type Element = ComponentRef<typeof Primitive.div>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.div> & {\n /**\n * Whether to automatically scroll to the bottom when new messages are added.\n * When enabled, the viewport will automatically scroll to show the latest content.\n *\n * Default false if `turnAnchor` is \"top\", otherwise defaults to true.\n */\n autoScroll?: boolean | undefined;\n\n /**\n * Controls scroll anchoring behavior for new messages.\n * - \"bottom\" (default): Messages anchor at the bottom, classic chat behavior.\n * - \"top\": New user messages anchor at the top of the viewport for a focused reading experience.\n */\n turnAnchor?: \"top\" | \"bottom\" | undefined;\n };\n}\n\nconst useViewportSizeRef = () => {\n const register = useThreadViewport((s) => s.registerViewport);\n const getHeight = useCallback(\n (el: HTMLElement) =>\n el.clientHeight - parseFloat(getComputedStyle(el).paddingTop),\n [],\n );\n\n return useSizeHandle(register, getHeight);\n};\n\nconst ThreadPrimitiveViewportScrollable = forwardRef<\n ThreadPrimitiveViewport.Element,\n ThreadPrimitiveViewport.Props\n>(({ autoScroll, children, ...rest }, forwardedRef) => {\n const autoScrollRef = useThreadViewportAutoScroll<HTMLDivElement>({\n autoScroll,\n });\n const viewportSizeRef = useViewportSizeRef();\n const ref = useComposedRefs(forwardedRef, autoScrollRef, viewportSizeRef);\n\n return (\n <Primitive.div {...rest} ref={ref}>\n {children}\n </Primitive.div>\n );\n});\n\nThreadPrimitiveViewportScrollable.displayName =\n \"ThreadPrimitive.ViewportScrollable\";\n\n/**\n * A scrollable viewport container for thread messages.\n *\n * This component provides a scrollable area for displaying thread messages with\n * automatic scrolling capabilities. It manages the viewport state and provides\n * context for child components to access viewport-related functionality.\n *\n * @example\n * ```tsx\n * <ThreadPrimitive.Viewport turnAnchor=\"top\">\n * <ThreadPrimitive.Messages components={{ Message: MyMessage }} />\n * </ThreadPrimitive.Viewport>\n * ```\n */\nexport const ThreadPrimitiveViewport = forwardRef<\n ThreadPrimitiveViewport.Element,\n ThreadPrimitiveViewport.Props\n>(({ turnAnchor, ...props }, ref) => {\n return (\n <ThreadPrimitiveViewportProvider options={{ turnAnchor }}>\n <ThreadPrimitiveViewportScrollable {...props} ref={ref} />\n </ThreadPrimitiveViewportProvider>\n );\n});\n\nThreadPrimitiveViewport.displayName = \"ThreadPrimitive.Viewport\";\n"],"mappings":";;;AAEA,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAC1B;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,mCAAmC;AAC5C,SAAS,uCAAuC;AAChD,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AA4C9B;AAtBJ,IAAM,qBAAqB,MAAM;AAC/B,QAAM,WAAW,kBAAkB,CAAC,MAAM,EAAE,gBAAgB;AAC5D,QAAM,YAAY;AAAA,IAChB,CAAC,OACC,GAAG,eAAe,WAAW,iBAAiB,EAAE,EAAE,UAAU;AAAA,IAC9D,CAAC;AAAA,EACH;AAEA,SAAO,cAAc,UAAU,SAAS;AAC1C;AAEA,IAAM,oCAAoC,WAGxC,CAAC,EAAE,YAAY,UAAU,GAAG,KAAK,GAAG,iBAAiB;AACrD,QAAM,gBAAgB,4BAA4C;AAAA,IAChE;AAAA,EACF,CAAC;AACD,QAAM,kBAAkB,mBAAmB;AAC3C,QAAM,MAAM,gBAAgB,cAAc,eAAe,eAAe;AAExE,SACE,oBAAC,UAAU,KAAV,EAAe,GAAG,MAAM,KACtB,UACH;AAEJ,CAAC;AAED,kCAAkC,cAChC;AAgBK,IAAM,0BAA0B,WAGrC,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,QAAQ;AACnC,SACE,oBAAC,mCAAgC,SAAS,EAAE,WAAW,GACrD,8BAAC,qCAAmC,GAAG,OAAO,KAAU,GAC1D;AAEJ,CAAC;AAED,wBAAwB,cAAc;","names":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Primitive } from "@radix-ui/react-primitive";
|
|
2
|
+
import { type ComponentRef, ComponentPropsWithoutRef } from "react";
|
|
3
|
+
export declare namespace ThreadPrimitiveViewportFooter {
|
|
4
|
+
type Element = ComponentRef<typeof Primitive.div>;
|
|
5
|
+
type Props = ComponentPropsWithoutRef<typeof Primitive.div>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A footer container that measures its height for scroll calculations.
|
|
9
|
+
*
|
|
10
|
+
* This component measures its height and provides it to the viewport context
|
|
11
|
+
* for use in scroll calculations (e.g., ViewportSlack min-height).
|
|
12
|
+
*
|
|
13
|
+
* Multiple ViewportFooter components can be used - their heights are summed.
|
|
14
|
+
*
|
|
15
|
+
* Typically used with `className="sticky bottom-0"` to keep the footer
|
|
16
|
+
* visible at the bottom of the viewport while scrolling.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <ThreadPrimitive.Viewport>
|
|
21
|
+
* <ThreadPrimitive.Messages components={{ ... }} />
|
|
22
|
+
* <ThreadPrimitive.ViewportFooter className="sticky bottom-0">
|
|
23
|
+
* <Composer />
|
|
24
|
+
* </ThreadPrimitive.ViewportFooter>
|
|
25
|
+
* </ThreadPrimitive.Viewport>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare const ThreadPrimitiveViewportFooter: import("react").ForwardRefExoticComponent<Omit<import("react").ClassAttributes<HTMLDivElement> & import("react").HTMLAttributes<HTMLDivElement> & {
|
|
29
|
+
asChild?: boolean;
|
|
30
|
+
}, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
31
|
+
//# sourceMappingURL=ThreadViewportFooter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThreadViewportFooter.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadViewportFooter.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EACL,KAAK,YAAY,EAEjB,wBAAwB,EAEzB,MAAM,OAAO,CAAC;AAIf,yBAAiB,6BAA6B,CAAC;IAC7C,KAAY,OAAO,GAAG,YAAY,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;IACzD,KAAY,KAAK,GAAG,wBAAwB,CAAC,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC;CACpE;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,6BAA6B;;0DAexC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/primitives/thread/ThreadViewportFooter.tsx
|
|
4
|
+
import { useComposedRefs } from "@radix-ui/react-compose-refs";
|
|
5
|
+
import { Primitive } from "@radix-ui/react-primitive";
|
|
6
|
+
import {
|
|
7
|
+
forwardRef,
|
|
8
|
+
useCallback
|
|
9
|
+
} from "react";
|
|
10
|
+
import { useSizeHandle } from "../../utils/hooks/useSizeHandle.js";
|
|
11
|
+
import { useThreadViewport } from "../../context/react/ThreadViewportContext.js";
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
var ThreadPrimitiveViewportFooter = forwardRef((props, forwardedRef) => {
|
|
14
|
+
const register = useThreadViewport((s) => s.registerContentInset);
|
|
15
|
+
const getHeight = useCallback((el) => {
|
|
16
|
+
const marginTop = parseFloat(getComputedStyle(el).marginTop) || 0;
|
|
17
|
+
return el.offsetHeight + marginTop;
|
|
18
|
+
}, []);
|
|
19
|
+
const resizeRef = useSizeHandle(register, getHeight);
|
|
20
|
+
const ref = useComposedRefs(forwardedRef, resizeRef);
|
|
21
|
+
return /* @__PURE__ */ jsx(Primitive.div, { ...props, ref });
|
|
22
|
+
});
|
|
23
|
+
ThreadPrimitiveViewportFooter.displayName = "ThreadPrimitive.ViewportFooter";
|
|
24
|
+
export {
|
|
25
|
+
ThreadPrimitiveViewportFooter
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=ThreadViewportFooter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/thread/ThreadViewportFooter.tsx"],"sourcesContent":["\"use client\";\n\nimport { useComposedRefs } from \"@radix-ui/react-compose-refs\";\nimport { Primitive } from \"@radix-ui/react-primitive\";\nimport {\n type ComponentRef,\n forwardRef,\n ComponentPropsWithoutRef,\n useCallback,\n} from \"react\";\nimport { useSizeHandle } from \"../../utils/hooks/useSizeHandle\";\nimport { useThreadViewport } from \"../../context/react/ThreadViewportContext\";\n\nexport namespace ThreadPrimitiveViewportFooter {\n export type Element = ComponentRef<typeof Primitive.div>;\n export type Props = ComponentPropsWithoutRef<typeof Primitive.div>;\n}\n\n/**\n * A footer container that measures its height for scroll calculations.\n *\n * This component measures its height and provides it to the viewport context\n * for use in scroll calculations (e.g., ViewportSlack min-height).\n *\n * Multiple ViewportFooter components can be used - their heights are summed.\n *\n * Typically used with `className=\"sticky bottom-0\"` to keep the footer\n * visible at the bottom of the viewport while scrolling.\n *\n * @example\n * ```tsx\n * <ThreadPrimitive.Viewport>\n * <ThreadPrimitive.Messages components={{ ... }} />\n * <ThreadPrimitive.ViewportFooter className=\"sticky bottom-0\">\n * <Composer />\n * </ThreadPrimitive.ViewportFooter>\n * </ThreadPrimitive.Viewport>\n * ```\n */\nexport const ThreadPrimitiveViewportFooter = forwardRef<\n ThreadPrimitiveViewportFooter.Element,\n ThreadPrimitiveViewportFooter.Props\n>((props, forwardedRef) => {\n const register = useThreadViewport((s) => s.registerContentInset);\n const getHeight = useCallback((el: HTMLElement) => {\n const marginTop = parseFloat(getComputedStyle(el).marginTop) || 0;\n return el.offsetHeight + marginTop;\n }, []);\n\n const resizeRef = useSizeHandle(register, getHeight);\n\n const ref = useComposedRefs(forwardedRef, resizeRef);\n\n return <Primitive.div {...props} ref={ref} />;\n});\n\nThreadPrimitiveViewportFooter.displayName = \"ThreadPrimitive.ViewportFooter\";\n"],"mappings":";;;AAEA,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAC1B;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,qBAAqB;AAC9B,SAAS,yBAAyB;AA0CzB;AAdF,IAAM,gCAAgC,WAG3C,CAAC,OAAO,iBAAiB;AACzB,QAAM,WAAW,kBAAkB,CAAC,MAAM,EAAE,oBAAoB;AAChE,QAAM,YAAY,YAAY,CAAC,OAAoB;AACjD,UAAM,YAAY,WAAW,iBAAiB,EAAE,EAAE,SAAS,KAAK;AAChE,WAAO,GAAG,eAAe;AAAA,EAC3B,GAAG,CAAC,CAAC;AAEL,QAAM,YAAY,cAAc,UAAU,SAAS;AAEnD,QAAM,MAAM,gBAAgB,cAAc,SAAS;AAEnD,SAAO,oBAAC,UAAU,KAAV,EAAe,GAAG,OAAO,KAAU;AAC7C,CAAC;AAED,8BAA8B,cAAc;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type FC, type ReactNode } from "react";
|
|
2
|
+
export type ThreadViewportSlackProps = {
|
|
3
|
+
/** Threshold at which the user message height clamps to the offset */
|
|
4
|
+
fillClampThreshold?: string;
|
|
5
|
+
/** Offset used when clamping large user messages */
|
|
6
|
+
fillClampOffset?: string;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A slot component that provides minimum height to enable scroll anchoring.
|
|
11
|
+
*
|
|
12
|
+
* When using `turnAnchor="top"`, this component ensures there is
|
|
13
|
+
* enough scroll room below the anchor point (last user message) for it to scroll
|
|
14
|
+
* to the top of the viewport. The min-height is applied only to the last
|
|
15
|
+
* assistant message.
|
|
16
|
+
*
|
|
17
|
+
* This component is used internally by MessagePrimitive.Root.
|
|
18
|
+
*/
|
|
19
|
+
export declare const ThreadPrimitiveViewportSlack: FC<ThreadViewportSlackProps>;
|
|
20
|
+
//# sourceMappingURL=ThreadViewportSlack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThreadViewportSlack.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/ThreadViewportSlack.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,EAAE,EACP,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AA2Bf,MAAM,MAAM,wBAAwB,GAAG;IACrC,sEAAsE;IACtE,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,oDAAoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,EAAE,EAAE,CAAC,wBAAwB,CAoDrE,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/primitives/thread/ThreadViewportSlack.tsx
|
|
4
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
5
|
+
import {
|
|
6
|
+
createContext,
|
|
7
|
+
useCallback,
|
|
8
|
+
useContext
|
|
9
|
+
} from "react";
|
|
10
|
+
import { useThreadViewportStore } from "../../context/react/ThreadViewportContext.js";
|
|
11
|
+
import { useAssistantState } from "../../context/index.js";
|
|
12
|
+
import { useManagedRef } from "../../utils/hooks/useManagedRef.js";
|
|
13
|
+
import { jsx } from "react/jsx-runtime";
|
|
14
|
+
var SlackNestingContext = createContext(false);
|
|
15
|
+
var parseCssLength = (value, element) => {
|
|
16
|
+
const match = value.match(/^([\d.]+)(em|px|rem)$/);
|
|
17
|
+
if (!match) return 0;
|
|
18
|
+
const num = parseFloat(match[1]);
|
|
19
|
+
const unit = match[2];
|
|
20
|
+
if (unit === "px") return num;
|
|
21
|
+
if (unit === "em") {
|
|
22
|
+
const fontSize = parseFloat(getComputedStyle(element).fontSize) || 16;
|
|
23
|
+
return num * fontSize;
|
|
24
|
+
}
|
|
25
|
+
if (unit === "rem") {
|
|
26
|
+
const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
|
|
27
|
+
return num * rootFontSize;
|
|
28
|
+
}
|
|
29
|
+
return 0;
|
|
30
|
+
};
|
|
31
|
+
var ThreadPrimitiveViewportSlack = ({
|
|
32
|
+
children,
|
|
33
|
+
fillClampThreshold = "10em",
|
|
34
|
+
fillClampOffset = "6em"
|
|
35
|
+
}) => {
|
|
36
|
+
const isLast = useAssistantState(({ message }) => message.isLast);
|
|
37
|
+
const threadViewportStore = useThreadViewportStore({ optional: true });
|
|
38
|
+
const isNested = useContext(SlackNestingContext);
|
|
39
|
+
const callback = useCallback(
|
|
40
|
+
(el) => {
|
|
41
|
+
if (!threadViewportStore || isNested) return;
|
|
42
|
+
const updateMinHeight = () => {
|
|
43
|
+
const state = threadViewportStore.getState();
|
|
44
|
+
if (state.turnAnchor === "top" && isLast) {
|
|
45
|
+
const { viewport, inset, userMessage } = state.height;
|
|
46
|
+
const threshold = parseCssLength(fillClampThreshold, el);
|
|
47
|
+
const offset = parseCssLength(fillClampOffset, el);
|
|
48
|
+
const clampAdjustment = userMessage <= threshold ? userMessage : offset;
|
|
49
|
+
const minHeight = Math.max(0, viewport - inset - clampAdjustment);
|
|
50
|
+
el.style.minHeight = `${minHeight}px`;
|
|
51
|
+
el.style.flexShrink = "0";
|
|
52
|
+
el.style.transition = "min-height 0s";
|
|
53
|
+
} else {
|
|
54
|
+
el.style.minHeight = "";
|
|
55
|
+
el.style.flexShrink = "";
|
|
56
|
+
el.style.transition = "";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
updateMinHeight();
|
|
60
|
+
return threadViewportStore.subscribe(updateMinHeight);
|
|
61
|
+
},
|
|
62
|
+
[
|
|
63
|
+
threadViewportStore,
|
|
64
|
+
isLast,
|
|
65
|
+
isNested,
|
|
66
|
+
fillClampThreshold,
|
|
67
|
+
fillClampOffset
|
|
68
|
+
]
|
|
69
|
+
);
|
|
70
|
+
const ref = useManagedRef(callback);
|
|
71
|
+
return /* @__PURE__ */ jsx(SlackNestingContext.Provider, { value: true, children: /* @__PURE__ */ jsx(Slot, { ref, children }) });
|
|
72
|
+
};
|
|
73
|
+
ThreadPrimitiveViewportSlack.displayName = "ThreadPrimitive.ViewportSlack";
|
|
74
|
+
export {
|
|
75
|
+
ThreadPrimitiveViewportSlack
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=ThreadViewportSlack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/thread/ThreadViewportSlack.tsx"],"sourcesContent":["\"use client\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport {\n createContext,\n type FC,\n type ReactNode,\n useCallback,\n useContext,\n} from \"react\";\nimport { useThreadViewportStore } from \"../../context/react/ThreadViewportContext\";\nimport { useAssistantState } from \"../../context\";\nimport { useManagedRef } from \"../../utils/hooks/useManagedRef\";\n\nconst SlackNestingContext = createContext(false);\n\nconst parseCssLength = (value: string, element: HTMLElement): number => {\n const match = value.match(/^([\\d.]+)(em|px|rem)$/);\n if (!match) return 0;\n\n const num = parseFloat(match[1]!);\n const unit = match[2];\n\n if (unit === \"px\") return num;\n if (unit === \"em\") {\n const fontSize = parseFloat(getComputedStyle(element).fontSize) || 16;\n return num * fontSize;\n }\n if (unit === \"rem\") {\n const rootFontSize =\n parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;\n return num * rootFontSize;\n }\n return 0;\n};\n\nexport type ThreadViewportSlackProps = {\n /** Threshold at which the user message height clamps to the offset */\n fillClampThreshold?: string;\n /** Offset used when clamping large user messages */\n fillClampOffset?: string;\n children: ReactNode;\n};\n\n/**\n * A slot component that provides minimum height to enable scroll anchoring.\n *\n * When using `turnAnchor=\"top\"`, this component ensures there is\n * enough scroll room below the anchor point (last user message) for it to scroll\n * to the top of the viewport. The min-height is applied only to the last\n * assistant message.\n *\n * This component is used internally by MessagePrimitive.Root.\n */\nexport const ThreadPrimitiveViewportSlack: FC<ThreadViewportSlackProps> = ({\n children,\n fillClampThreshold = \"10em\",\n fillClampOffset = \"6em\",\n}) => {\n const isLast = useAssistantState(({ message }) => message.isLast);\n const threadViewportStore = useThreadViewportStore({ optional: true });\n const isNested = useContext(SlackNestingContext);\n\n const callback = useCallback(\n (el: HTMLElement) => {\n if (!threadViewportStore || isNested) return;\n\n const updateMinHeight = () => {\n const state = threadViewportStore.getState();\n if (state.turnAnchor === \"top\" && isLast) {\n const { viewport, inset, userMessage } = state.height;\n const threshold = parseCssLength(fillClampThreshold, el);\n const offset = parseCssLength(fillClampOffset, el);\n const clampAdjustment =\n userMessage <= threshold ? userMessage : offset;\n\n const minHeight = Math.max(0, viewport - inset - clampAdjustment);\n el.style.minHeight = `${minHeight}px`;\n el.style.flexShrink = \"0\";\n el.style.transition = \"min-height 0s\";\n } else {\n el.style.minHeight = \"\";\n el.style.flexShrink = \"\";\n el.style.transition = \"\";\n }\n };\n\n updateMinHeight();\n return threadViewportStore.subscribe(updateMinHeight);\n },\n [\n threadViewportStore,\n isLast,\n isNested,\n fillClampThreshold,\n fillClampOffset,\n ],\n );\n\n const ref = useManagedRef<HTMLElement>(callback);\n\n return (\n <SlackNestingContext.Provider value={true}>\n <Slot ref={ref}>{children}</Slot>\n </SlackNestingContext.Provider>\n );\n};\n\nThreadPrimitiveViewportSlack.displayName = \"ThreadPrimitive.ViewportSlack\";\n"],"mappings":";;;AAEA,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC,SAAS,yBAAyB;AAClC,SAAS,qBAAqB;AA2FxB;AAzFN,IAAM,sBAAsB,cAAc,KAAK;AAE/C,IAAM,iBAAiB,CAAC,OAAe,YAAiC;AACtE,QAAM,QAAQ,MAAM,MAAM,uBAAuB;AACjD,MAAI,CAAC,MAAO,QAAO;AAEnB,QAAM,MAAM,WAAW,MAAM,CAAC,CAAE;AAChC,QAAM,OAAO,MAAM,CAAC;AAEpB,MAAI,SAAS,KAAM,QAAO;AAC1B,MAAI,SAAS,MAAM;AACjB,UAAM,WAAW,WAAW,iBAAiB,OAAO,EAAE,QAAQ,KAAK;AACnE,WAAO,MAAM;AAAA,EACf;AACA,MAAI,SAAS,OAAO;AAClB,UAAM,eACJ,WAAW,iBAAiB,SAAS,eAAe,EAAE,QAAQ,KAAK;AACrE,WAAO,MAAM;AAAA,EACf;AACA,SAAO;AACT;AAoBO,IAAM,+BAA6D,CAAC;AAAA,EACzE;AAAA,EACA,qBAAqB;AAAA,EACrB,kBAAkB;AACpB,MAAM;AACJ,QAAM,SAAS,kBAAkB,CAAC,EAAE,QAAQ,MAAM,QAAQ,MAAM;AAChE,QAAM,sBAAsB,uBAAuB,EAAE,UAAU,KAAK,CAAC;AACrE,QAAM,WAAW,WAAW,mBAAmB;AAE/C,QAAM,WAAW;AAAA,IACf,CAAC,OAAoB;AACnB,UAAI,CAAC,uBAAuB,SAAU;AAEtC,YAAM,kBAAkB,MAAM;AAC5B,cAAM,QAAQ,oBAAoB,SAAS;AAC3C,YAAI,MAAM,eAAe,SAAS,QAAQ;AACxC,gBAAM,EAAE,UAAU,OAAO,YAAY,IAAI,MAAM;AAC/C,gBAAM,YAAY,eAAe,oBAAoB,EAAE;AACvD,gBAAM,SAAS,eAAe,iBAAiB,EAAE;AACjD,gBAAM,kBACJ,eAAe,YAAY,cAAc;AAE3C,gBAAM,YAAY,KAAK,IAAI,GAAG,WAAW,QAAQ,eAAe;AAChE,aAAG,MAAM,YAAY,GAAG,SAAS;AACjC,aAAG,MAAM,aAAa;AACtB,aAAG,MAAM,aAAa;AAAA,QACxB,OAAO;AACL,aAAG,MAAM,YAAY;AACrB,aAAG,MAAM,aAAa;AACtB,aAAG,MAAM,aAAa;AAAA,QACxB;AAAA,MACF;AAEA,sBAAgB;AAChB,aAAO,oBAAoB,UAAU,eAAe;AAAA,IACtD;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,MAAM,cAA2B,QAAQ;AAE/C,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,MACnC,8BAAC,QAAK,KAAW,UAAS,GAC5B;AAEJ;AAEA,6BAA6B,cAAc;","names":[]}
|
|
@@ -2,6 +2,9 @@ export { ThreadPrimitiveRoot as Root } from "./ThreadRoot";
|
|
|
2
2
|
export { ThreadPrimitiveEmpty as Empty } from "./ThreadEmpty";
|
|
3
3
|
export { ThreadPrimitiveIf as If } from "./ThreadIf";
|
|
4
4
|
export { ThreadPrimitiveViewport as Viewport } from "./ThreadViewport";
|
|
5
|
+
export { ThreadPrimitiveViewportProvider as ViewportProvider } from "../../context/providers/ThreadViewportProvider";
|
|
6
|
+
export { ThreadPrimitiveViewportFooter as ViewportFooter } from "./ThreadViewportFooter";
|
|
7
|
+
export { ThreadPrimitiveViewportSlack as ViewportSlack } from "./ThreadViewportSlack";
|
|
5
8
|
export { ThreadPrimitiveMessages as Messages } from "./ThreadMessages";
|
|
6
9
|
export { ThreadPrimitiveMessageByIndex as MessageByIndex } from "./ThreadMessages";
|
|
7
10
|
export { ThreadPrimitiveScrollToBottom as ScrollToBottom } from "./ThreadScrollToBottom";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,IAAI,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,oBAAoB,IAAI,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,iBAAiB,IAAI,EAAE,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,uBAAuB,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,uBAAuB,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,6BAA6B,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,6BAA6B,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,yBAAyB,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,IAAI,IAAI,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,oBAAoB,IAAI,KAAK,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,iBAAiB,IAAI,EAAE,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,uBAAuB,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,+BAA+B,IAAI,gBAAgB,EAAE,MAAM,gDAAgD,CAAC;AACrH,OAAO,EAAE,6BAA6B,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,4BAA4B,IAAI,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtF,OAAO,EAAE,uBAAuB,IAAI,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,EAAE,6BAA6B,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,6BAA6B,IAAI,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,yBAAyB,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -3,6 +3,9 @@ import { ThreadPrimitiveRoot } from "./ThreadRoot.js";
|
|
|
3
3
|
import { ThreadPrimitiveEmpty } from "./ThreadEmpty.js";
|
|
4
4
|
import { ThreadPrimitiveIf } from "./ThreadIf.js";
|
|
5
5
|
import { ThreadPrimitiveViewport } from "./ThreadViewport.js";
|
|
6
|
+
import { ThreadPrimitiveViewportProvider } from "../../context/providers/ThreadViewportProvider.js";
|
|
7
|
+
import { ThreadPrimitiveViewportFooter } from "./ThreadViewportFooter.js";
|
|
8
|
+
import { ThreadPrimitiveViewportSlack } from "./ThreadViewportSlack.js";
|
|
6
9
|
import { ThreadPrimitiveMessages } from "./ThreadMessages.js";
|
|
7
10
|
import { ThreadPrimitiveMessageByIndex } from "./ThreadMessages.js";
|
|
8
11
|
import { ThreadPrimitiveScrollToBottom } from "./ThreadScrollToBottom.js";
|
|
@@ -15,6 +18,9 @@ export {
|
|
|
15
18
|
ThreadPrimitiveRoot as Root,
|
|
16
19
|
ThreadPrimitiveScrollToBottom as ScrollToBottom,
|
|
17
20
|
ThreadPrimitiveSuggestion as Suggestion,
|
|
18
|
-
ThreadPrimitiveViewport as Viewport
|
|
21
|
+
ThreadPrimitiveViewport as Viewport,
|
|
22
|
+
ThreadPrimitiveViewportFooter as ViewportFooter,
|
|
23
|
+
ThreadPrimitiveViewportProvider as ViewportProvider,
|
|
24
|
+
ThreadPrimitiveViewportSlack as ViewportSlack
|
|
19
25
|
};
|
|
20
26
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/primitives/thread/index.ts"],"sourcesContent":["export { ThreadPrimitiveRoot as Root } from \"./ThreadRoot\";\nexport { ThreadPrimitiveEmpty as Empty } from \"./ThreadEmpty\";\nexport { ThreadPrimitiveIf as If } from \"./ThreadIf\";\nexport { ThreadPrimitiveViewport as Viewport } from \"./ThreadViewport\";\nexport { ThreadPrimitiveMessages as Messages } from \"./ThreadMessages\";\nexport { ThreadPrimitiveMessageByIndex as MessageByIndex } from \"./ThreadMessages\";\nexport { ThreadPrimitiveScrollToBottom as ScrollToBottom } from \"./ThreadScrollToBottom\";\nexport { ThreadPrimitiveSuggestion as Suggestion } from \"./ThreadSuggestion\";\n"],"mappings":";AAAA,SAAgC,2BAAY;AAC5C,SAAiC,4BAAa;AAC9C,SAA8B,yBAAU;AACxC,SAAoC,+BAAgB;AACpD,SAAoC,+BAAgB;AACpD,SAA0C,qCAAsB;AAChE,SAA0C,qCAAsB;AAChE,SAAsC,iCAAkB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/primitives/thread/index.ts"],"sourcesContent":["export { ThreadPrimitiveRoot as Root } from \"./ThreadRoot\";\nexport { ThreadPrimitiveEmpty as Empty } from \"./ThreadEmpty\";\nexport { ThreadPrimitiveIf as If } from \"./ThreadIf\";\nexport { ThreadPrimitiveViewport as Viewport } from \"./ThreadViewport\";\nexport { ThreadPrimitiveViewportProvider as ViewportProvider } from \"../../context/providers/ThreadViewportProvider\";\nexport { ThreadPrimitiveViewportFooter as ViewportFooter } from \"./ThreadViewportFooter\";\nexport { ThreadPrimitiveViewportSlack as ViewportSlack } from \"./ThreadViewportSlack\";\nexport { ThreadPrimitiveMessages as Messages } from \"./ThreadMessages\";\nexport { ThreadPrimitiveMessageByIndex as MessageByIndex } from \"./ThreadMessages\";\nexport { ThreadPrimitiveScrollToBottom as ScrollToBottom } from \"./ThreadScrollToBottom\";\nexport { ThreadPrimitiveSuggestion as Suggestion } from \"./ThreadSuggestion\";\n"],"mappings":";AAAA,SAAgC,2BAAY;AAC5C,SAAiC,4BAAa;AAC9C,SAA8B,yBAAU;AACxC,SAAoC,+BAAgB;AACpD,SAA4C,uCAAwB;AACpE,SAA0C,qCAAsB;AAChE,SAAyC,oCAAqB;AAC9D,SAAoC,+BAAgB;AACpD,SAA0C,qCAAsB;AAChE,SAA0C,qCAAsB;AAChE,SAAsC,iCAAkB;","names":[]}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { RefCallback } from "react";
|
|
2
2
|
export declare namespace useThreadViewportAutoScroll {
|
|
3
3
|
type Options = {
|
|
4
|
+
/**
|
|
5
|
+
* Whether to automatically scroll to the bottom when new messages are added.
|
|
6
|
+
* When enabled, the viewport will automatically scroll to show the latest content.
|
|
7
|
+
*
|
|
8
|
+
* Default false if `turnAnchor` is "top", otherwise defaults to true.
|
|
9
|
+
*/
|
|
4
10
|
autoScroll?: boolean | undefined;
|
|
5
11
|
};
|
|
6
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThreadViewportAutoScroll.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/useThreadViewportAutoScroll.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAuB,MAAM,OAAO,CAAC;AAQzD,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,OAAO,GAAG;QACpB,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAClC,CAAC;CACH;AAED,eAAO,MAAM,2BAA2B,GAAI,QAAQ,SAAS,WAAW,EAAE,iBAEvE,2BAA2B,CAAC,OAAO,KAAG,WAAW,CAAC,QAAQ,
|
|
1
|
+
{"version":3,"file":"useThreadViewportAutoScroll.d.ts","sourceRoot":"","sources":["../../../src/primitives/thread/useThreadViewportAutoScroll.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAuB,MAAM,OAAO,CAAC;AAQzD,yBAAiB,2BAA2B,CAAC;IAC3C,KAAY,OAAO,GAAG;QACpB;;;;;WAKG;QACH,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;KAClC,CAAC;CACH;AAED,eAAO,MAAM,2BAA2B,GAAI,QAAQ,SAAS,WAAW,EAAE,iBAEvE,2BAA2B,CAAC,OAAO,KAAG,WAAW,CAAC,QAAQ,CAiF5D,CAAC"}
|