diff --git a/src/renderer/src/components/native-chat/native-chat-composer-attachments-test-probe.tsx b/src/renderer/src/components/native-chat/native-chat-composer-attachments-test-probe.tsx new file mode 100644 index 00000000000..1a8e9292acc --- /dev/null +++ b/src/renderer/src/components/native-chat/native-chat-composer-attachments-test-probe.tsx @@ -0,0 +1,114 @@ +import { act, createElement, useEffect, useRef, useState } from 'react' +import { createRoot, type Root } from 'react-dom/client' +import type { NativeChatResolvedTarget } from './native-chat-composer-target' +import { useNativeChatComposerAttachments } from './use-native-chat-composer-attachments' + +type AttachmentApi = ReturnType +type ProbeApi = AttachmentApi & { adoptDraft: (draft: string) => void } + +const target: NativeChatResolvedTarget = { + ptyId: 'pty-1' +} + +function Probe({ + scopeKey, + structured = false, + disabled = false, + isComposing, + onReady +}: { + scopeKey: string + structured?: boolean + disabled?: boolean + isComposing: () => boolean + onReady: (api: ProbeApi) => void +}): React.JSX.Element { + const [caret, setCaret] = useState(0) + const [draftValue, setDraftValue] = useState('') + const [notice, setNotice] = useState(null) + const textareaRef = useRef(null) + const api = useNativeChatComposerAttachments({ + attachmentScopeKey: scopeKey, + allowWithoutTarget: structured, + imageReferences: structured, + caret, + disabled, + isComposing, + resolveTarget: () => (structured ? null : target), + textareaRef, + setCaret, + setDraft: (updater) => setDraftValue((previous) => updater(previous)), + setNotice + }) + useEffect(() => { + onReady({ ...api, adoptDraft: setDraftValue }) + }, [api, onReady]) + return ( +
+