Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(channels): unified input mode (i.e. no inline input mode) (#4571)
Peter Chinman8dc28e544c10
diff --git a/js/app/packages/app/component/useAppSquishHandlers.ts b/js/app/packages/app/component/useAppSquishHandlers.tsindex 1010bad62f..df1719a3ba 100644--- a/js/app/packages/app/component/useAppSquishHandlers.ts+++ b/js/app/packages/app/component/useAppSquishHandlers.ts@@ -15,13 +15,13 @@ function getViewportHeight() {}function resetVirtualKeyboardState() {- setVirtualKeyboardVisible(false);- setVirtualKeyboardHeight(0);document.documentElement.style.setProperty('--dvh', '1dvh');document.documentElement.style.setProperty('--virtual-keyboard-height','0px');+ setVirtualKeyboardVisible(false);+ setVirtualKeyboardHeight(0);}function createActiveElementPolling(onActiveElementLost: () => void) {@@ -74,8 +74,6 @@ export function useAppSquishHandlers() {);const handleKeyboardWillShow = (event: VirtualKeyboardEvent) => {- setVirtualKeyboardVisible(true);- setVirtualKeyboardHeight(event.detail?.height ?? 0);activeElementPolling.start();const newViewportHeight =(window.visualViewport?.height ?? 0) - (event.detail?.height ?? 0);@@ -85,6 +83,8 @@ export function useAppSquishHandlers() {'--virtual-keyboard-height',`${event.detail?.height ?? 0}px`);+ setVirtualKeyboardVisible(true);+ setVirtualKeyboardHeight(event.detail?.height ?? 0);};const handleKeyboardWillHide = () => {@@ -178,12 +178,12 @@ export function useAppSquishHandlers() {const viewportHeight = getViewportHeight();if (viewportHeight < viewportHeightBeforeFocus) {- setVirtualKeyboardVisible(true);activeElementPolling.start();syncViewportHeight();setTimeout(() => {window.scrollTo(0, 0);});+ setVirtualKeyboardVisible(true);}};diff --git a/js/app/packages/app/index.css b/js/app/packages/app/index.cssindex c5efd5db4a..a64ade26e9 100644--- a/js/app/packages/app/index.css+++ b/js/app/packages/app/index.css@@ -352,18 +352,12 @@@keyframes long-press-message-highlight {from {- background-color: oklch(from var(--color-accent) l c h / 0%);- outline-color: transparent;- outline-offset: -1px;- outline-style: solid;- outline-width: 1px;+ background-color: oklch(from var(--color-ink) l c h / 0%);+ border-radius: var(--radius-sm);}to {- background-color: oklch(from var(--color-accent) l c h / 5%);- outline-color: oklch(from var(--color-accent) l c h / 20%);- outline-offset: -1px;- outline-style: solid;- outline-width: 1px;+ background-color: oklch(from var(--color-ink) l c h / 5%);+ border-radius: var(--radius-sm);}}@@ -378,11 +372,6 @@100% { transform: translateX(350%); }}-@keyframes long-press-accent-bar {- from { opacity: 0; }- to { opacity: 1; }-}-/* Big hammer fix for cursor pointer. */@utility cursor-pointer {cursor: default;@@ -533,6 +522,7 @@ a {@utility macro-message-width {max-width: 100%;+ width: 100%;@media (min-width: 640px) {max-width: 800px;min-width: 250px;@@ -597,25 +587,25 @@ a {opacity: 0 !important;}-/* Channel message hover + non-selection highlight */+/* Channel message hover + selection-cursor highlight *//* Suppressed on touch devices *//* Background-only — borders/rings are reserved for structural UI edges. */-html:not([data-touch-device="true"]) [data-message][data-highlighted],+[data-message][data-selected],html:not([data-touch-device="true"]) [data-message]:hover{@apply bg-ink/5 rounded-sm;}+/* Accent bar marking the targeted message (unified-input target, navigation target) */+[data-message][data-targeted] > .message-accent-bar {+ opacity: 1;+}+/* Channel message long-press animation */.channel-message-long-press-highlight [data-swipe-content],[data-message].channel-message-long-press-highlight{animation: long-press-message-highlight 400ms ease-in both;}-[data-message].channel-message-long-press-highlight > .message-accent-bar,-.channel-message-long-press-highlight [data-accent-bar] {- animation: long-press-accent-bar 400ms ease-in both;-}-/* Immediate touch feedback for mobile soup entity rows */[data-soup-entity].touch-highlight [data-swipe-content],[data-soup-entity].touch-highlight .soup-list-entity {diff --git a/js/app/packages/block-call/component/CallTranscript.tsx b/js/app/packages/block-call/component/CallTranscript.tsxindex 53d149602f..9a98173c94 100644--- a/js/app/packages/block-call/component/CallTranscript.tsx+++ b/js/app/packages/block-call/component/CallTranscript.tsx@@ -111,7 +111,6 @@ function TranscriptSegmentRow(props: {<Thread.Row message={message}><Message.Rootmessage={message}- highlighted={props.isActive}selected={props.isActive}onClick={() => {if (videoTimestamp !== null) props.onSeekToSeconds?.(videoTimestamp);@@ -169,7 +168,6 @@ function GroupedTranscriptSegmentRow(props: {<Thread.Row message={message}><Message.Rootmessage={message}- highlighted={props.isActive}selected={props.isActive}onClick={() => {if (videoTimestamp !== null) props.onSeekToSeconds?.(videoTimestamp);diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsxindex 542bd535a7..6759c63fd8 100644--- a/js/app/packages/channel/Channel/Channel.tsx+++ b/js/app/packages/channel/Channel/Channel.tsx@@ -11,7 +11,10 @@ import {makeAttachmentTrackerPersistenceKey,makeInputValuePersistenceKey,} from '@channel/Input/utils/persistence';-import { SearchHighlightTermsProvider } from '@channel/Message';+import {+ type MessageData,+ SearchHighlightTermsProvider,+} from '@channel/Message';import { MaybeMessageActionDrawerManager } from '@channel/Mobile/MessageActionDrawerManager';import { useChannelParticipants } from '@channel/use-channel-participants';import { FindBar } from '@core/component/FindBar';@@ -54,10 +57,12 @@ import {createEffect,createMemo,createSignal,+ Match,on,onCleanup,onMount,Show,+ Switch,} from 'solid-js';import {ChannelInput,@@ -69,15 +74,15 @@ import { ChannelInputContainer } from '../Input/ChannelInputContainer';import { hasSendableInputContent } from '../Input/utils/sendable-content';import { ChannelThread } from '../Thread';import { buildQuoteReplyValue } from '../Thread/utils/message-actions';+import { isUnifiedInputMode } from '../unified-input-mode';import { ActiveCallMessage } from './ActiveCallMessage';import { ChannelDropZone } from './ChannelDropZone';import { createChannelDragState } from './create-channel-drag-state';import { createChannelFindBar } from './create-channel-find-bar';import { createChannelHotkeys } from './create-channel-hotkeys';+import { createChannelKeyboardHandler } from './create-channel-keyboard-handler';import { createChannelMessageActions } from './create-channel-message-actions';import { createDeleteMessageConfirmation } from './create-delete-message-confirmation';-import { createInlineInputKeyboardHandler } from './create-inline-input-keyboard-handler';-import { createMainInputKeyboardHandler } from './create-main-input-keyboard-handler';import { createMessageEditor } from './create-message-editor';import { createMessageSelection } from './create-message-selection';import {@@ -101,6 +106,12 @@ import {type ThreadManagerSnapshot,} from './thread-manager';import { createThreadPaginator } from './thread-paginator';+import { UnifiedEditInput } from './UnifiedEditInput';+import { UnifiedReplyInput } from './UnifiedReplyInput';+import {+ createUnifiedInputManager,+ type UnifiedReplyTargetSnapshot,+} from './unified-input-manager';export type ChannelProps = {channelId: string;@@ -116,6 +127,8 @@ export type ChannelProps = {export type ChannelMessagesStateSnapshot = {scroll?: ThreadListScrollSnapshot;threads?: ThreadManagerSnapshot;+ /** The unified input's reply binding, persisted by ids only. */+ replyTarget?: UnifiedReplyTargetSnapshot;};export type ChannelHandle = {@@ -151,8 +164,6 @@ export function Channel(props: ChannelProps) {createSignal<ThreadListNavigation>();const [threadListScrollState, setThreadListScrollState] =createSignal<ThreadListScrollState>();- const [messageListElement, setMessageListElement] =- createSignal<HTMLDivElement>();// When opening without a target, clear stale data that was previously// restored from a load-around session so the query fetches from the bottom.@@ -232,16 +243,27 @@ export function Channel(props: ChannelProps) {markAsViewed();});+ const unifiedInput = createUnifiedInputManager({+ initialReplyTarget: props.initialMessagesStateSnapshot?.replyTarget,+ // Clear any highlight left by tapping the reply flag's navigate action.+ onReplyThreadReleased: (threadId) => releaseSelectionAndTarget(threadId),+ });+const threadManager = createThreadManager(props.initialMessagesStateSnapshot?.threads);- const [isChannelInputHidden, setIsChannelInputHidden] = createSignal(false);- const [channelInputEl, setChannelInputEl] = createSignal<HTMLDivElement>();const threadPaginator = createThreadPaginator(messagesQuery);const messageEditor = createMessageEditor({channelId: () => props.channelId,participantIds: () => participants.ids(),patchMessage: patchMessageMutation.mutate,+ onEditEnded: (message) => {+ // Clear any highlight left by tapping the edit flag's navigate action+ // (which selects and nav-targets the edited message's thread).+ if (isUnifiedInputMode()) {+ releaseSelectionAndTarget(message.thread_id ?? message.id);+ }+ },});const threadListInitialScrollTarget: Accessor<ThreadListScrollTarget> = () =>@@ -288,22 +310,20 @@ export function Channel(props: ChannelProps) {},});- const openReplyInput = (message: {- id: string;- thread_id?: string | null;- }) => {+ const openReplyInput = (message: MessageData) => {const threadId = message.thread_id ?? message.id;const state = threadManager.getOrCreateThreadState(threadId);- state.setIsReplying(true);+ if (isUnifiedInputMode()) {+ unifiedInput.bindReply(message);+ state.setIsExpanded(true);+ } else {+ state.setIsReplying(true);+ }state.replyInputFocusRequest.request();return state;};- const openQuoteReplyInput = (message: {- id: string;- content: string;- thread_id?: string | null;- }) => {+ const openQuoteReplyInput = (message: MessageData) => {const threadId = message.thread_id ?? message.id;const state = threadManager.getOrCreateThreadState(threadId);const beforeSnapshot = state.replyInputState();@@ -317,7 +337,12 @@ export function Channel(props: ChannelProps) {};state.setReplyInputState(nextSnapshot);- state.setIsReplying(true);+ if (isUnifiedInputMode()) {+ unifiedInput.bindReply(message);+ state.setIsExpanded(true);+ } else {+ state.setIsReplying(true);+ }requestAnimationFrame(() => {state.replyInputHandle?.()?.restoreSnapshot(nextSnapshot, {focus: false,@@ -389,6 +414,11 @@ export function Channel(props: ChannelProps) {targetMessageController.goToMessage(messageId, replyId);};+ const releaseSelectionAndTarget = (threadId: string) => {+ if (selection.selectedId() === threadId) clearSelection();+ targetMessageController.clearActiveTarget(threadId);+ };+const [threadListScrollSnapshot, setThreadListScrollSnapshot] = createSignal<ThreadListScrollSnapshot | undefined>(props.initialMessagesStateSnapshot?.scroll);@@ -397,10 +427,12 @@ export function Channel(props: ChannelProps) {() => {const scroll = threadListScrollSnapshot();const threads = threadManager.getSnapshot();- if (!scroll && !threads) return undefined;+ const boundReplyTarget = unifiedInput.getReplyTargetSnapshot();+ if (!scroll && !threads && !boundReplyTarget) return undefined;return {...(scroll ? { scroll } : {}),...(threads ? { threads } : {}),+ ...(boundReplyTarget ? { replyTarget: boundReplyTarget } : {}),};};@@ -467,14 +499,20 @@ export function Channel(props: ChannelProps) {scrollToBottom: () => threadListNavigation()?.scrollToBottom(),});- // On Mobile when a thread reply input is focused, we want to hide the main Channel input- createInlineInputKeyboardHandler(messageListElement, setIsChannelInputHidden);- // On Native iOS app, when the main channel input is focused, scroll to bottom if already near bottom- createMainInputKeyboardHandler(- channelInputEl,- threadListNavigation,- messageListElement- );+ createChannelKeyboardHandler({+ navigation: threadListNavigation,+ isNearBottom: () => threadListScrollState()?.isNearBottom ?? false,+ // The unified input's current binding — the edited message (the edit+ // face covers the reply face), else the reply target.+ boundMessageId: () => {+ const editing = messageEditor.state();+ if (editing) return editing.messageId;+ const replyTarget = unifiedInput.replyTarget();+ return replyTarget+ ? (replyTarget.replyId ?? replyTarget.threadId)+ : undefined;+ },+ });const onSend: ChannelInputProps['onSend'] = (snapshot) => {const senderId = userId();@@ -532,7 +570,6 @@ export function Channel(props: ChannelProps) {<divclass="ph-no-capture relative flex-1 min-h-0 outline-none flex flex-col"ref={(element) => {- setMessageListElement(element);attachMessageListRef(element);}}tabIndex={-1}@@ -582,7 +619,8 @@ export function Channel(props: ChannelProps) {getMessageActions={getMessageActions}targetThreadId={targetMessageController.activeTargetMessageId()}targetReplyId={targetMessageController.pendingTargetReplyId()}- selectedReplyId={targetMessageController.activeTargetMessageReplyId()}+ activeTargetReplyId={targetMessageController.activeTargetMessageReplyId()}+ unifiedReplyTarget={unifiedInput.replyTarget()}onTargetReplyScrolled={(replyId) => {targetMessageController.completePendingReplyScroll(m().id,@@ -596,6 +634,7 @@ export function Channel(props: ChannelProps) {replyInputState={state.replyInputState}setReplyInputState={state.setReplyInputState}setReplyInputEl={state.setReplyInputEl}+ replyInputHandle={state.replyInputHandle}setReplyInputHandle={state.setReplyInputHandle}replyInputFocusRequest={state.replyInputFocusRequest@@ -634,45 +673,102 @@ export function Channel(props: ChannelProps) {<ChannelInputContainerref={(el) => {attachInputRef(el);- setChannelInputEl(el);}}- isHidden={isChannelInputHidden()}>- <ChannelInput- autofocus={props.autofocus}- collapsible- input={{- mode: 'channel',- id: `channel-input-${props.channelId}`,- placeholder: 'Message channel',- }}- participants={participants.users}- attachmentTracker={attachmentTracker}- persistenceKey={makeInputValuePersistenceKey({- channelId: props.channelId,- })}- onReady={(handle) => {- dragState.setAttachFilesToChannel(handle.attachFiles);- dragState.setEntityMentionInputHandlers(handle);- setChannelInputHandle(handle);- }}- onChange={(snapshot) =>- void setChannelInputSnapshot(snapshot)- }- onSend={onSend}- onStartTyping={() =>- typingMutation.mutate({- channelId: props.channelId,- action: 'start',- })- }- onStopTyping={() =>- typingMutation.mutate({- channelId: props.channelId,- action: 'stop',- })- }- />+ <Switch>+ <Match+ when={+ isUnifiedInputMode() &&+ messageEditor.state()?.messageId+ }+ keyed+ >+ {(_messageId) => (+ <UnifiedEditInput+ channelId={props.channelId}+ messageEditor={messageEditor}+ onNavigateToMessage={(message) =>+ goToMessage(+ message.thread_id ?? message.id,+ message.thread_id ? message.id : undefined+ )+ }+ />+ )}+ </Match>+ <Match+ when={+ isUnifiedInputMode() &&+ unifiedInput.replyTarget()?.threadId+ }+ keyed+ >+ {(threadId) => (+ <UnifiedReplyInput+ channelId={props.channelId}+ threadId={threadId}+ state={threadManager.getOrCreateThreadState(+ threadId+ )}+ getTargetMessage={() => {+ const target = unifiedInput.replyTarget();+ if (target?.message) return target.message;+ // A restored quote-reply has no resolvable+ // message (messageById only indexes thread+ // roots) — don't misattribute it to the root.+ if (target?.replyId) return undefined;+ return messageById().get(threadId);+ }}+ onNavigateToTarget={() =>+ goToMessage(+ threadId,+ unifiedInput.replyTarget()?.replyId+ )+ }+ onExit={unifiedInput.closeReply}+ />+ )}+ </Match>+ <Match when={true}>+ <ChannelInput+ autofocus={props.autofocus}+ collapsible+ input={{+ mode: 'channel',+ id: `channel-input-${props.channelId}`,+ placeholder: 'Message channel',+ }}+ participants={participants.users}+ attachmentTracker={attachmentTracker}+ persistenceKey={makeInputValuePersistenceKey({+ channelId: props.channelId,+ })}+ onReady={(handle) => {+ dragState.setAttachFilesToChannel(+ handle.attachFiles+ );+ dragState.setEntityMentionInputHandlers(handle);+ setChannelInputHandle(handle);+ }}+ onChange={(snapshot) =>+ void setChannelInputSnapshot(snapshot)+ }+ onSend={onSend}+ onStartTyping={() =>+ typingMutation.mutate({+ channelId: props.channelId,+ action: 'start',+ })+ }+ onStopTyping={() =>+ typingMutation.mutate({+ channelId: props.channelId,+ action: 'stop',+ })+ }+ />+ </Match>+ </Switch></ChannelInputContainer></FloatRegionOrInline></DebugSuspense>diff --git a/js/app/packages/channel/Channel/InlineMessageEditor.tsx b/js/app/packages/channel/Channel/InlineMessageEditor.tsxindex 4dc058e64c..1c29a84167 100644--- a/js/app/packages/channel/Channel/InlineMessageEditor.tsx+++ b/js/app/packages/channel/Channel/InlineMessageEditor.tsx@@ -3,25 +3,39 @@ import { TOKENS } from '@core/hotkey/tokens';import type { IUser } from '@core/user/types';import { cn } from '@ui';import type { Accessor } from 'solid-js';-import { ChannelInput, createInputAttachmentTracker, Input } from '../Input';-import { useMessage } from '../Message';+import {+ ChannelInput,+ createInputAttachmentTracker,+ Input,+ type InputHandle,+} from '../Input';+import type { MessageData } from '../Message';import type { MessageEditor } from './create-message-editor';type MessageEditorContentProps = {channelId: string;+ message: MessageData;messageEditor: MessageEditor;participants?: Accessor<IUser[]>;class?: string;+ collapsible?: boolean;+ /** Defaults to `!isMobile()` inside `ChannelInput`. */+ autofocus?: boolean;+ onReady?: (handle: InputHandle) => void;};+/**+ * The wired `ChannelInput` for editing a message. Shared by the inline+ * message editor and the unified-input mode's `UnifiedEditInput`, which only+ * differ in the chrome around it.+ */export function MessageEditorContent(props: MessageEditorContentProps) {- const message = useMessage();const snapshot = () => props.messageEditor.state()?.snapshot;const attachmentTracker = createInputAttachmentTracker({initialAttachments: snapshot()?.attachments,});- const [attachHotkeys, scopeId] = useHotkeyDOMScope('inline-message-editor');+ const [attachHotkeys, scopeId] = useHotkeyDOMScope('message-editor');registerHotkey({scopeId,@@ -30,34 +44,33 @@ export function MessageEditorContent(props: MessageEditorContentProps) {description: 'Discard edit',runWithInputFocused: true,keyDownHandler: () => {- props.messageEditor.cancel(message().id);+ props.messageEditor.cancel(props.message.id);return true;},});return (- <div- ref={attachHotkeys}- class={cn('w-full min-w-0', props.class)}- data-inline-input-container-id={message().id}- >+ <div ref={attachHotkeys} class={cn('w-full min-w-0', props.class)}><ChannelInputinput={{mode: 'channel',- id: `edit-message-input-${message().id}`,+ id: `edit-message-input-${props.message.id}`,value: snapshot()?.value,attachments: snapshot()?.attachments,placeholder: 'Edit message',}}+ collapsible={props.collapsible}+ autofocus={props.autofocus}attachmentTracker={attachmentTracker}participants={props.participants}- markdownNamespace={`edit-message-${props.channelId}-${message().id}`}+ markdownNamespace={`edit-message-${props.channelId}-${props.message.id}`}+ onReady={props.onReady}onChange={(nextSnapshot) =>- props.messageEditor.update(message(), nextSnapshot)+ props.messageEditor.update(props.message, nextSnapshot)}- onClose={() => props.messageEditor.cancel(message().id)}+ onClose={() => props.messageEditor.cancel(props.message.id)}onSend={(nextSnapshot) =>- props.messageEditor.save(message(), nextSnapshot)+ props.messageEditor.save(props.message, nextSnapshot)}><Input.Actions>diff --git a/js/app/packages/channel/Channel/UnifiedEditInput.tsx b/js/app/packages/channel/Channel/UnifiedEditInput.tsxnew file mode 100644index 0000000000..49464fbd3f--- /dev/null+++ b/js/app/packages/channel/Channel/UnifiedEditInput.tsx@@ -0,0 +1,46 @@+import { Show } from 'solid-js';+import { InputFlag } from '../Input';+import type { MessageData } from '../Message';+import { useChannelParticipants } from '../use-channel-participants';+import type { MessageEditor } from './create-message-editor';+import { MessageEditorContent } from './InlineMessageEditor';++/**+ * Edit face of the unified-input mode: the inline editor's wiring+ * (`MessageEditorContent`) hosted in the floating input with a flag.+ */+export function UnifiedEditInput(props: {+ channelId: string;+ messageEditor: MessageEditor;+ onNavigateToMessage: (message: MessageData) => void;+}) {+ const participants = useChannelParticipants(() => props.channelId);++ return (+ <Show when={props.messageEditor.state()?.message} keyed>+ {(message) => (+ <div data-keep-keyboard class="w-full min-w-0 flex flex-col gap-1">+ <InputFlag+ label="Editing message"+ dismissLabel="Cancel edit"+ onActivate={() => props.onNavigateToMessage(message)}+ onDismiss={() => props.messageEditor.cancel(message.id)}+ />+ <MessageEditorContent+ channelId={props.channelId}+ message={message}+ messageEditor={props.messageEditor}+ participants={participants.users}+ collapsible+ autofocus={false}+ onReady={(handle) => {+ // Backstop focus; on mobile the action drawer's focusInput+ // machinery is the primary path.+ requestAnimationFrame(() => handle.focus());+ }}+ />+ </div>+ )}+ </Show>+ );+}diff --git a/js/app/packages/channel/Channel/UnifiedReplyInput.tsx b/js/app/packages/channel/Channel/UnifiedReplyInput.tsxnew file mode 100644index 0000000000..1902e7ef03--- /dev/null+++ b/js/app/packages/channel/Channel/UnifiedReplyInput.tsx@@ -0,0 +1,63 @@+import { Show } from 'solid-js';+import { InputFlag } from '../Input';+import type { MessageData } from '../Message';+import { SenderName } from '../Message/SenderName';+import type { ThreadState } from '../Thread';+import { ThreadReplyChannelInput } from '../Thread/ThreadReplyChannelInput';++/**+ * Thread-reply face of the unified-input mode. Registers into the same+ * `ThreadState` slots and persistence keys as the inline `ThreadReplyInput`,+ * so drafts and the `openReplyInput`/`openQuoteReplyInput` flows are shared+ * between inline and unified-input modes.+ */+export function UnifiedReplyInput(props: {+ channelId: string;+ threadId: string;+ state: ThreadState;+ /**+ * The message the reply is bound to — a specific reply for quote-replies,+ * otherwise the thread root.+ */+ getTargetMessage: () => MessageData | undefined;+ onNavigateToTarget: () => void;+ onExit: () => void;+}) {+ return (+ <div+ data-keep-keyboard+ class="relative w-full flex flex-col items-center gap-1"+ >+ <InputFlag+ label={+ <Show+ when={props.getTargetMessage()}+ keyed+ fallback="Replying to thread"+ >+ {(target) => (+ <>+ Replying to <SenderName message={target} />+ </>+ )}+ </Show>+ }+ dismissLabel="Stop replying"+ onActivate={() => props.onNavigateToTarget()}+ onDismiss={() => props.onExit()}+ />+ <ThreadReplyChannelInput+ channelId={props.channelId}+ threadId={props.threadId}+ replyInputState={props.state.replyInputState}+ setReplyInputState={props.state.setReplyInputState}+ replyInputHandle={props.state.replyInputHandle}+ setReplyInputHandle={props.state.setReplyInputHandle}+ focusRequest={props.state.replyInputFocusRequest}+ host="unified"+ collapsible+ onExit={() => props.onExit()}+ />+ </div>+ );+}diff --git a/js/app/packages/channel/Channel/create-channel-keyboard-handler.ts b/js/app/packages/channel/Channel/create-channel-keyboard-handler.tsnew file mode 100644index 0000000000..b420b82cb4--- /dev/null+++ b/js/app/packages/channel/Channel/create-channel-keyboard-handler.ts@@ -0,0 +1,87 @@+import { FloatRegions } from '@app/component/mobile/float-regions/float-region-state';+import { virtualKeyboardHeight } from '@core/mobile/virtualKeyboard';+import { isPlatform } from '@core/util/platform';+import {+ type Accessor,+ createEffect,+ createSignal,+ on,+ onCleanup,+} from 'solid-js';+import { scrollMessageAboveKeyboard } from '../scroll-utils';+import type { ThreadListNavigation } from './ThreadList';++type CreateChannelKeyboardHandlerOptions = {+ navigation: Accessor<ThreadListNavigation | undefined>;+ /**+ * Whether the user is near the bottom of the message list. ThreadList+ * re-emits this on viewport resizes, so it stays fresh across keyboard+ * squishes; at keyboardWillShow time it still holds the pre-squish value.+ */+ isNearBottom: Accessor<boolean>;+ /**+ * The message the unified input is currently bound to — the message being+ * edited, or the reply target. Every binding change schedules a one-shot+ * reveal for the next keyboard appearance.+ */+ boundMessageId: Accessor<string | undefined>;+};++/**+ * Channel scroll behavior for virtual-keyboard appearance (native iOS).+ *+ * Both behaviors react to the `keyboardWillShow` event, which is why they+ * live together — a pending target reveal takes precedence over the+ * near-bottom follow so they don't fight over the scroll position:+ * - Target reveal: whenever the unified input binds to a message, a one-shot+ * scroll is scheduled that brings the bound message above the keyboard and+ * the floating input riding on it.+ * - Near-bottom follow: when the user was near the bottom of the message+ * list, scroll back to the bottom so messages are not hidden behind the+ * keyboard.+ *+ * Listening to the event rather than the keyboard-height signal is what makes+ * measuring safe here: `useAppSquishHandlers` registered its listener first,+ * so the --dvh squish is applied before these handlers run.+ */+export function createChannelKeyboardHandler(+ options: CreateChannelKeyboardHandlerOptions+): void {+ if (!isPlatform('ios')) return;++ // The pending reveal mirrors the binding (rather than being requested by+ // each bind site): new bind flows get the reveal for free, an unbind+ // clears any not-yet-consumed request, and — because the mirror is+ // synchronous — a consumed request is always the current binding.+ const [pendingTargetReveal, setPendingTargetReveal] = createSignal<string>();+ createEffect(+ on(options.boundMessageId, (messageId) => setPendingTargetReveal(messageId))+ );++ /**+ * Consume a pending reveal. Returns whether the reveal owned this keyboard+ * appearance (even if the bound message was already fully visible).+ */+ const revealPendingTarget = (): boolean => {+ const messageId = pendingTargetReveal();+ if (!messageId) return false;+ setPendingTargetReveal(undefined);+ scrollMessageAboveKeyboard(+ messageId,+ virtualKeyboardHeight() + FloatRegions.hostHeight()+ );+ return true;+ };++ createEffect(() => {+ const handleKeyboardWillShow = () => {+ // A bound-target reveal owns the scroll for this keyboard appearance.+ if (revealPendingTarget()) return;+ if (options.isNearBottom()) options.navigation()?.scrollToBottom();+ };+ window.addEventListener('keyboardWillShow', handleKeyboardWillShow);+ onCleanup(() => {+ window.removeEventListener('keyboardWillShow', handleKeyboardWillShow);+ });+ });+}diff --git a/js/app/packages/channel/Channel/create-inline-input-keyboard-handler.ts b/js/app/packages/channel/Channel/create-inline-input-keyboard-handler.tsdeleted file mode 100644index e7c59d0216..0000000000--- a/js/app/packages/channel/Channel/create-inline-input-keyboard-handler.ts+++ /dev/null@@ -1,116 +0,0 @@-import { isNativeMobilePlatform } from '@core/mobile/isNativeMobilePlatform';-import { isTouchDevice } from '@core/mobile/isTouchDevice';-import {- virtualKeyboardHeight,- virtualKeyboardVisible,-} from '@core/mobile/virtualKeyboard';-import { isPlatform } from '@core/util/platform';-import {- type Accessor,- createEffect,- on,- onCleanup,- type Setter,-} from 'solid-js';-import { scrollElementAboveKeyboard } from '../scroll-utils';--const INPUT_CONTAINER_SELECTOR = '[data-inline-input-container-id]';--export function createInlineInputKeyboardHandler(- containerEl: Accessor<HTMLElement | undefined>,- setIsChannelInputHidden: Setter<boolean>-) {- let activeInputContainer: HTMLElement | undefined;-- const reset = () => {- setIsChannelInputHidden(false);- activeInputContainer = undefined;- };-- const keyboardWillShowHandler = (event: Event) => {- const height =- (event as CustomEvent<{ height: number }>).detail?.height ?? 0;- if (activeInputContainer) {- scrollElementAboveKeyboard(activeInputContainer, height);- }- };-- const handleFocusIn = (e: FocusEvent) => {- const inputContainer = (e.target as HTMLElement).closest<HTMLElement>(- INPUT_CONTAINER_SELECTOR- );- if (!inputContainer) return;- activeInputContainer = inputContainer;-- // HACK: on mobile safari, we need to ensure that the input container is scrolled into view BEFORE we hide the input, and then perform the subsequent scroll. Some sort of weird Safari focus behavior going on.- if (!isPlatform('ios')) {- activeInputContainer.scrollIntoView({ block: 'end' });- }-- setIsChannelInputHidden(true);-- if (isPlatform('ios')) {- const currentKeyboardHeight = virtualKeyboardHeight();-- if (currentKeyboardHeight > 0) {- scrollElementAboveKeyboard(activeInputContainer, currentKeyboardHeight);- } else {- window.addEventListener('keyboardWillShow', keyboardWillShowHandler, {- once: true,- });- }- } else {- // HACK: on mobile safari need to jettison this scroll out past the layout changes caused by the virtual keyboard appearing- setTimeout(() => {- if (!activeInputContainer) return;- activeInputContainer.scrollIntoView({ block: 'end' });- }, 500);- }- };-- const handleFocusOut = (e: FocusEvent) => {- if (!activeInputContainer) return;- const nextInputContainer = (e.relatedTarget as HTMLElement | null)?.closest(- INPUT_CONTAINER_SELECTOR- );- if (!nextInputContainer) {- reset();- }- };-- // Attach focus in handler- createEffect(- on(containerEl, () => {- if (!isTouchDevice()) return;- const el = containerEl();- if (!el) return;- el.addEventListener('focusin', handleFocusIn);- el.addEventListener('focusout', handleFocusOut);-- onCleanup(() => {- el.removeEventListener('focusin', handleFocusIn);- el.removeEventListener('focusout', handleFocusOut);- });- })- );-- createEffect(- on(virtualKeyboardVisible, () => {- if (!isTouchDevice()) return;- if (!virtualKeyboardVisible()) {- reset();- return;- }- // Mobile web only: scroll active input into view when keyboard appears.- if (isNativeMobilePlatform()) return;- setTimeout(() => {- if (!activeInputContainer) return;- activeInputContainer.scrollIntoView({- block: 'center',- behavior: 'smooth',- });- }, 0);- }),- { defer: true }- );-}diff --git a/js/app/packages/channel/Channel/create-main-input-keyboard-handler.ts b/js/app/packages/channel/Channel/create-main-input-keyboard-handler.tsdeleted file mode 100644index 0138040467..0000000000--- a/js/app/packages/channel/Channel/create-main-input-keyboard-handler.ts+++ /dev/null@@ -1,57 +0,0 @@-import { isPlatform } from '@core/util/platform';-import { type Accessor, createEffect, onCleanup } from 'solid-js';-import { NEAR_BOTTOM_THRESHOLD } from './constants';-import type { ThreadListNavigation } from './ThreadList';--/**- * On native ios app, when the main channel input is focused and the user was near the- * bottom of the message list, scrolls to the bottom after the virtual keyboard- * appears (so messages aren't hidden behind the keyboard).- */-export function createMainInputKeyboardHandler(- inputContainerEl: Accessor<HTMLElement | undefined>,- navigation: Accessor<ThreadListNavigation | undefined>,- channelRoot: Accessor<HTMLElement | undefined>-): void {- if (!isPlatform('ios')) return;-- // Read from the DOM directly: the scrollState signal is only updated on scroll- // events, which can fire after the keyboard has already shrunk the viewport,- // leaving a stale isNearBottom=false that persists until the next user scroll.- let wasNearBottom = false;-- const captureNearBottom = () => {- const root = channelRoot();- const scrollEl = root?.querySelector<HTMLElement>('[data-channel-scroll]');- if (!scrollEl) {- wasNearBottom = false;- return;- }- const distanceFromBottom =- scrollEl.scrollHeight - scrollEl.scrollTop - scrollEl.clientHeight;- wasNearBottom = distanceFromBottom <= NEAR_BOTTOM_THRESHOLD;- };-- createEffect(() => {- const el = inputContainerEl();- if (!el) return;-- const handleTouchStart = () => captureNearBottom();- el.addEventListener('touchstart', handleTouchStart, {- capture: true,- passive: true,- });-- const handleKeyboardWillShow = () => {- if (!el.contains(document.activeElement)) return;- if (wasNearBottom) navigation()?.scrollToBottom();- };- window.addEventListener('keyboardWillShow', handleKeyboardWillShow);- onCleanup(() => {- el.removeEventListener('touchstart', handleTouchStart, {- capture: true,- });- window.removeEventListener('keyboardWillShow', handleKeyboardWillShow);- });- });-}diff --git a/js/app/packages/channel/Channel/create-message-editor.ts b/js/app/packages/channel/Channel/create-message-editor.tsindex f9c5de2119..82affccd5c 100644--- a/js/app/packages/channel/Channel/create-message-editor.ts+++ b/js/app/packages/channel/Channel/create-message-editor.ts@@ -25,6 +25,11 @@ type CreateMessageEditorOptions = {channelId: () => string;participantIds: () => string[];patchMessage: (input: PatchMessageInput) => void;+ /**+ * Called when an edit session ends — saved, cancelled, or abandoned by+ * starting an edit on a different message.+ */+ onEditEnded?: (message: MessageData) => void;};export type MessageEditor = {@@ -40,9 +45,19 @@ export function createMessageEditor(): MessageEditor {const [editState, setEditState] = createSignal<MessageEditState>();+ const endEdit = (message: MessageData) => {+ setEditState(undefined);+ options.onEditEnded?.(message);+ };+const start: MessageEditor['start'] = (message: MessageData) => {+ const previous = editState();+ if (previous && previous.messageId !== message.id) {+ options.onEditEnded?.(previous.message);+ }setEditState({messageId: message.id,+ message,snapshot: buildMessageEditSnapshot(message),});};@@ -55,8 +70,9 @@ export function createMessageEditor(};const cancel: MessageEditor['cancel'] = (messageId: string) => {- if (editState()?.messageId !== messageId) return;- setEditState(undefined);+ const current = editState();+ if (!current || current.messageId !== messageId) return;+ endEdit(current.message);};const save: MessageEditor['save'] = (message, snapshot) => {@@ -80,7 +96,7 @@ export function createMessageEditor(const hasAttachmentChanges =attachmentIDsToDelete.length > 0 || newAttachments.length > 0;if (!hasContentChanged && !hasAttachmentChanges) {- setEditState(undefined);+ endEdit(message);return;}@@ -92,7 +108,7 @@ export function createMessageEditor(attachmentIDsToDelete,attachmentsToAdd: newAttachments.length > 0 ? newAttachments : undefined,});- setEditState(undefined);+ endEdit(message);};return {diff --git a/js/app/packages/channel/Channel/create-target-message-controller.ts b/js/app/packages/channel/Channel/create-target-message-controller.tsindex aaf8575ca5..92aa1c616c 100644--- a/js/app/packages/channel/Channel/create-target-message-controller.ts+++ b/js/app/packages/channel/Channel/create-target-message-controller.ts@@ -131,6 +131,21 @@ export function createTargetMessageController(});};+ /**+ * Clear the active target (and any pending scroll) if it still points at+ * `messageId`; no-op if navigation has since moved elsewhere. Leaves+ * `loadAroundMessageId` untouched so pagination is not disturbed.+ */+ const clearActiveTarget = (messageId: string) => {+ if (targetMessageData['activeTargetMessageId'] !== messageId) return;+ setTargetMessageData({+ activeTargetMessageId: undefined,+ activeTargetMessageReplyId: undefined,+ pendingScrollTargetId: undefined,+ pendingTargetReplyId: undefined,+ });+ };+return {activeTargetMessageId: () => targetMessageData['activeTargetMessageId'],activeTargetMessageReplyId: () =>@@ -142,6 +157,7 @@ export function createTargetMessageController(goToMessage,completePendingScroll,completePendingReplyScroll,+ clearActiveTarget,reset,};}diff --git a/js/app/packages/channel/Channel/mobile-channel-input-visibility.tsx b/js/app/packages/channel/Channel/mobile-channel-input-visibility.tsxdeleted file mode 100644index b7167bef0b..0000000000--- a/js/app/packages/channel/Channel/mobile-channel-input-visibility.tsx+++ /dev/null@@ -1,45 +0,0 @@-import { isMobile } from '@core/mobile/isMobile';-import {- type Accessor,- createContext,- createSignal,- type JSX,- useContext,-} from 'solid-js';--type MobileChannelInputVisibilityState = {- isHidden: Accessor<boolean>;- hide: () => void;- show: () => void;-};--const MobileChannelInputVisibilityContext =- createContext<MobileChannelInputVisibilityState>();--/**- * On mobile: creates reactive hide/show state and provides it via context.- * On desktop: renders children as-is with no context or signals.- */-export function MaybeMobileChannelInputVisibilityProvider(props: {- children: JSX.Element;-}) {- if (!isMobile()) return props.children;- const [isHidden, setIsHidden] = createSignal(false);- return (- <MobileChannelInputVisibilityContext.Provider- value={{- isHidden,- hide: () => setIsHidden(true),- show: () => setIsHidden(false),- }}- >- {props.children}- </MobileChannelInputVisibilityContext.Provider>- );-}--export function useMobileChannelInputVisibility():- | MobileChannelInputVisibilityState- | undefined {- return useContext(MobileChannelInputVisibilityContext);-}diff --git a/js/app/packages/channel/Channel/tests/unified-input-manager.test.ts b/js/app/packages/channel/Channel/tests/unified-input-manager.test.tsnew file mode 100644index 0000000000..39ff08d260--- /dev/null+++ b/js/app/packages/channel/Channel/tests/unified-input-manager.test.ts@@ -0,0 +1,113 @@+import { createRoot } from 'solid-js';+import { describe, expect, it } from 'vitest';+import type { MessageData } from '../../Message';+import { createUnifiedInputManager } from '../unified-input-manager';++const root = { id: 'root-1', thread_id: null } as MessageData;+const reply = { id: 'reply-1', thread_id: 'root-1' } as MessageData;+const otherRoot = { id: 'root-2', thread_id: null } as MessageData;++describe('createUnifiedInputManager', () => {+ it('binds a root message as a root-bound pointer', () => {+ createRoot((dispose) => {+ const manager = createUnifiedInputManager();++ manager.bindReply(root);++ expect(manager.replyTarget()).toEqual({+ threadId: 'root-1',+ replyId: undefined,+ message: root,+ });++ dispose();+ });+ });++ it('binds a thread reply as a reply-bound pointer to its root thread', () => {+ createRoot((dispose) => {+ const manager = createUnifiedInputManager();++ manager.bindReply(reply);++ expect(manager.replyTarget()).toEqual({+ threadId: 'root-1',+ replyId: 'reply-1',+ message: reply,+ });++ dispose();+ });+ });++ it('releases the previous thread when the binding moves to another thread', () => {+ createRoot((dispose) => {+ const released: string[] = [];+ const manager = createUnifiedInputManager({+ onReplyThreadReleased: (threadId) => released.push(threadId),+ });++ manager.bindReply(root);+ // Rebinding within the same thread is not a release.+ manager.bindReply(reply);+ expect(released).toEqual([]);++ manager.bindReply(otherRoot);+ expect(released).toEqual(['root-1']);++ manager.closeReply();+ expect(released).toEqual(['root-1', 'root-2']);+ expect(manager.replyTarget()).toBeUndefined();++ dispose();+ });+ });++ it('closeReply without a binding is a no-op', () => {+ createRoot((dispose) => {+ const released: string[] = [];+ const manager = createUnifiedInputManager({+ onReplyThreadReleased: (threadId) => released.push(threadId),+ });++ manager.closeReply();++ expect(released).toEqual([]);++ dispose();+ });+ });++ it('restores an id-only binding from a snapshot', () => {+ createRoot((dispose) => {+ const manager = createUnifiedInputManager({+ initialReplyTarget: { threadId: 'root-1', replyId: 'reply-1' },+ });++ expect(manager.replyTarget()).toEqual({+ threadId: 'root-1',+ replyId: 'reply-1',+ });+ expect(manager.replyTarget()?.message).toBeUndefined();++ dispose();+ });+ });++ it('snapshots the binding by ids only, never the entity', () => {+ createRoot((dispose) => {+ const manager = createUnifiedInputManager();++ expect(manager.getReplyTargetSnapshot()).toBeUndefined();++ manager.bindReply(reply);++ expect(manager.getReplyTargetSnapshot()).toEqual({+ threadId: 'root-1',+ replyId: 'reply-1',+ });++ dispose();+ });+ });+});diff --git a/js/app/packages/channel/Channel/unified-input-manager.ts b/js/app/packages/channel/Channel/unified-input-manager.tsnew file mode 100644index 0000000000..15b8a9b863--- /dev/null+++ b/js/app/packages/channel/Channel/unified-input-manager.ts@@ -0,0 +1,73 @@+import { createSignal } from 'solid-js';+import type { MessageData } from '../Message';++/** The unified input's reply binding, persisted by ids only. */+export type UnifiedReplyTargetSnapshot = {+ threadId: string;+ replyId?: string;+};++/**+ * The unified input's reply binding: a message pointer shaped like every+ * other one in channels — the thread root plus an optional reply (set for+ * quote-replies). `message` is the bound message itself; it is absent when+ * the binding was restored from a history snapshot (a reply's MessageData is+ * not resolvable at restore time).+ */+export type UnifiedReplyTarget = UnifiedReplyTargetSnapshot & {+ message?: MessageData;+};++/**+ * The unified input's reply binding — at most one, channel-wide.+ */+export function createUnifiedInputManager(options?: {+ /** Binding restored from a history snapshot. */+ initialReplyTarget?: UnifiedReplyTargetSnapshot;+ /**+ * Called when a thread stops being the reply target — the reply closed, or+ * the binding moved to another thread — so the caller can clear anything+ * still pointing at it (e.g. a highlight set by the reply flag's navigate+ * action).+ */+ onReplyThreadReleased?: (threadId: string) => void;+}) {+ const [replyTarget, setReplyTarget] = createSignal<+ UnifiedReplyTarget | undefined+ >(options?.initialReplyTarget);++ const bindReply = (message: MessageData) => {+ const previous = replyTarget();+ const threadId = message.thread_id ?? message.id;+ if (previous && previous.threadId !== threadId) {+ options?.onReplyThreadReleased?.(previous.threadId);+ }+ setReplyTarget({+ threadId,+ replyId: message.thread_id ? message.id : undefined,+ message,+ });+ };++ const closeReply = () => {+ const target = replyTarget();+ if (!target) return;+ setReplyTarget(undefined);+ options?.onReplyThreadReleased?.(target.threadId);+ };++ /** The binding for a history snapshot — ids only */+ const getReplyTargetSnapshot = (): UnifiedReplyTargetSnapshot | undefined => {+ const target = replyTarget();+ return target+ ? { threadId: target.threadId, replyId: target.replyId }+ : undefined;+ };++ return {+ replyTarget,+ bindReply,+ closeReply,+ getReplyTargetSnapshot,+ };+}diff --git a/js/app/packages/channel/Input/ChannelInput.tsx b/js/app/packages/channel/Input/ChannelInput.tsxindex 6f280e3357..e3e1dfa2ad 100644--- a/js/app/packages/channel/Input/ChannelInput.tsx+++ b/js/app/packages/channel/Input/ChannelInput.tsx@@ -335,7 +335,12 @@ export function ChannelInput(props: ChannelInputProps) {props.onReady?.({clear: () => markdownEditor.controls.clear(),- focus: focusEditor,+ focus: () => {+ // A collapsed pill hides the editor; programmatic focus implies intent+ // to type, so expand first.+ collapsedInput.expand();+ focusEditor();+ },send: () => inputState.commands.send(),attachFiles: (files) => inputState.commands.attachFiles(files),insertEntityMention,diff --git a/js/app/packages/channel/Input/ChannelInputContainer.tsx b/js/app/packages/channel/Input/ChannelInputContainer.tsxindex 1c251af79c..c43db81cd3 100644--- a/js/app/packages/channel/Input/ChannelInputContainer.tsx+++ b/js/app/packages/channel/Input/ChannelInputContainer.tsx@@ -1,17 +1,12 @@-import { cn } from '@ui';import type { JSX } from 'solid-js';export function ChannelInputContainer(props: {ref?: (el: HTMLDivElement) => void;children: JSX.Element;- isHidden?: boolean;}) {return (<div- class={cn(- 'pb-2 mobile:pb-0 w-full flex justify-center **:data-input-editor-shell:max-h-[calc(60*var(--dvh,1dvh))] mobile:**:data-input-editor-shell:max-h-[calc(32*var(--dvh,1dvh))] mobile:px-(--mobile-chrome-gutter) mobile:pointer-events-auto',- props.isHidden && 'hidden'- )}+ class="pb-2 mobile:pb-0 w-full flex justify-center **:data-input-editor-shell:max-h-[calc(60*var(--dvh,1dvh))] mobile:**:data-input-editor-shell:max-h-[calc(32*var(--dvh,1dvh))] mobile:px-(--mobile-chrome-gutter) mobile:pointer-events-auto"ref={props.ref}>{props.children}diff --git a/js/app/packages/channel/Input/InputFlag.tsx b/js/app/packages/channel/Input/InputFlag.tsxnew file mode 100644index 0000000000..f8e15a2074--- /dev/null+++ b/js/app/packages/channel/Input/InputFlag.tsx@@ -0,0 +1,59 @@+import XIcon from '@phosphor/x.svg';+import { Layer } from '@ui';+import { type JSX, Show } from 'solid-js';++const labelClass =+ 'min-w-0 truncate text-left text-xs text-ink-muted pl-3 py-1.5';++/**+ * A contextual flag pinned to the top edge of the channel input, for surfacing+ * something about the input's current mode or state — the message being+ * replied to or edited, etc.+ *+ * `label` is the flag's content. Pass `onActivate` to make it tappable (its+ * primary action, e.g. jump to the referenced message); omit it for a purely+ * informational flag. Pass `onDismiss` to show a dismiss (×) button.+ */+export function InputFlag(props: {+ label: JSX.Element;+ onActivate?: () => void;+ /** Accessible name for the dismiss button; required when `onDismiss` is set. */+ dismissLabel?: string;+ onDismiss?: () => void;+}) {+ return (+ <Layer depth={2}>+ {/* Opt into the input's keyboard-safe zone so tapping the flag (a sibling+ of ChannelInput, outside its container) doesn't dismiss the keyboard. */}+ <div+ data-keep-keyboard+ class="w-full macro-message-width flex justify-center"+ >+ <div class="w-[calc(100%-2px)] max-w-full flex items-center justify-between bg-surface rounded-t-2xl border-t border-l border-r border-edge -mb-6.5 pb-6">+ <Show+ when={props.onActivate}+ fallback={<div class={labelClass}>{props.label}</div>}+ >+ <button+ type="button"+ class={labelClass}+ onClick={() => props.onActivate?.()}+ >+ {props.label}+ </button>+ </Show>+ <Show when={props.onDismiss}>+ <button+ type="button"+ aria-label={props.dismissLabel}+ class="shrink-0 px-2 py-1.5 text-ink-muted"+ onClick={() => props.onDismiss?.()}+ >+ <XIcon class="size-5" aria-hidden="true" />+ </button>+ </Show>+ </div>+ </div>+ </Layer>+ );+}diff --git a/js/app/packages/channel/Input/Root.tsx b/js/app/packages/channel/Input/Root.tsxindex 6978048884..ee9259167d 100644--- a/js/app/packages/channel/Input/Root.tsx+++ b/js/app/packages/channel/Input/Root.tsx@@ -3,7 +3,11 @@ import { useTouchOutsideToDismissKeyboard } from '@core/mobile/useTouchOutsideToimport { cn } from '@ui';import { type JSX, splitProps } from 'solid-js';import { InputProvider } from './context';-import { type InputCommands, type InputData, isReplyInput } from './types';+import {+ type InputCommands,+ type InputData,+ isInlineReplyInput,+} from './types';const NoopInputCommands: InputCommands = {send: async () => false,@@ -37,7 +41,7 @@ export function Root(props: RootProps) {}}class={cn('relative macro-message-width flex flex-col flex-1 items-center justify-between',- isReplyInput(local.input) && 'mb-4',+ isInlineReplyInput(local.input) && 'mb-4',local.class)}data-inputdiff --git a/js/app/packages/channel/Input/create-collapsed-input-state.ts b/js/app/packages/channel/Input/create-collapsed-input-state.tsindex 4e2f3c318d..61e5694f63 100644--- a/js/app/packages/channel/Input/create-collapsed-input-state.ts+++ b/js/app/packages/channel/Input/create-collapsed-input-state.ts@@ -1,7 +1,13 @@import { isMobile } from '@core/mobile/isMobile';import { pickNativePhotoLibraryMedia } from '@core/mobile/nativePhotoLibrary';import { isPlatform } from '@core/util/platform';-import { type Accessor, createEffect, createSignal, on } from 'solid-js';+import {+ type Accessor,+ createEffect,+ createMemo,+ createSignal,+ on,+} from 'solid-js';/*** State and handlers for the `CollapsedInput` that stands in for a full@@ -16,9 +22,12 @@ export function createCollapsedInputState(options: {let filePickerRef: HTMLInputElement | undefined;// Collapse again when the surrounding view switches to another input.- createEffect(- on(options.inputId, () => setIsExpanded(false), { defer: true })- );+ // The memo equality-gates the id: callers' `input` prop getters can track+ // more than the id (e.g. the unified reply/edit input feeds the live draft+ // value back into `input`), and `on()` re-fires on any tracked change, not+ // value change — without the memo every keystroke would collapse the input.+ const inputId = createMemo(options.inputId);+ createEffect(on(inputId, () => setIsExpanded(false), { defer: true }));const attachFiles = async (files: File[]) => {if (files.length === 0) return;diff --git a/js/app/packages/channel/Input/index.ts b/js/app/packages/channel/Input/index.tsindex 33d539254a..b2be5344f7 100644--- a/js/app/packages/channel/Input/index.ts+++ b/js/app/packages/channel/Input/index.ts@@ -22,6 +22,7 @@ export {DiscardDraftAction,ToggleFormatAction,} from './InputActions';+export { InputFlag } from './InputFlag';export { Layout } from './Layout';export { createMentionsTracker } from './mentions-tracker';export type {diff --git a/js/app/packages/channel/Input/types.ts b/js/app/packages/channel/Input/types.tsindex c2a9e91430..bec4bd8649 100644--- a/js/app/packages/channel/Input/types.ts+++ b/js/app/packages/channel/Input/types.ts@@ -33,12 +33,20 @@ type InputDataBase = {};export type ChannelInputMode = InputDataBase & { mode: 'channel' };-export type ReplyInputMode = InputDataBase & { mode: 'reply' };+export type ReplyInputMode = InputDataBase & {+ mode: 'reply';+ /** Where the reply input is hosted. Defaults to 'inline' (in the thread). */+ host?: 'inline' | 'unified';+};export type InputData = ChannelInputMode | ReplyInputMode;export const isReplyInput = (input: InputData): input is ReplyInputMode =>input.mode === 'reply';+/** A reply input rendered inline inside a thread (not the unified input). */+export const isInlineReplyInput = (input: InputData): input is ReplyInputMode =>+ isReplyInput(input) && input.host !== 'unified';+export type InputActionEvent = MouseEvent | KeyboardEvent;export type InputSnapshot = {diff --git a/js/app/packages/channel/Message/ChannelMessage.tsx b/js/app/packages/channel/Message/ChannelMessage.tsxindex 5d5931aaeb..7253a0ebc6 100644--- a/js/app/packages/channel/Message/ChannelMessage.tsx+++ b/js/app/packages/channel/Message/ChannelMessage.tsx@@ -7,8 +7,8 @@ import { cn } from '@ui';import { type Accessor, type JSX, Match, Show, Switch } from 'solid-js';import type { MessageEditor } from '../Channel/create-message-editor';import { MessageEditorContent } from '../Channel/InlineMessageEditor';-import type { MessageSelectionState } from './context';-import { MessageSelectionProvider, useMessage } from './context';+import { isUnifiedInputMode } from '../unified-input-mode';+import { useMessage } from './context';import type { ChannelMessageListMeta } from './list-meta';import { Message } from './Message';import type { MessageActions, MessageData } from './types';@@ -20,8 +20,12 @@ type ChannelMessageProps = {listMeta?: ChannelMessageListMeta;messageEditor?: MessageEditor;participants?: Accessor<IUser[]>;- highlighted?: boolean;- selectionState?: MessageSelectionState;+ selected?: boolean;+ /**+ * The unified-input mode's floating reply/edit input, or message+ * navigation, points at this message.+ */+ targeted?: boolean;onClick?: JSX.EventHandlerUnion<HTMLDivElement, MouseEvent>;};@@ -43,10 +47,11 @@ function MessageContentSlot(props: {return (<Switch>- <Match when={isEditing() && props.messageEditor}>+ <Match when={isEditing() && !isUnifiedInputMode() && props.messageEditor}>{(messageEditor) => (<MessageEditorContentchannelId={props.channelId}+ message={message()}messageEditor={messageEditor()}participants={props.participants}class={props.class}@@ -197,8 +202,14 @@ export function ChannelMessage(props: ChannelMessageProps) {<Message.Rootmessage={props.message}actions={props.actions}- highlighted={props.highlighted}- selected={props.selectionState?.isSelected}+ selected={props.selected}+ targeted={+ props.targeted ||+ // In unified-input mode the edit happens in the floating input; the+ // accent bar marks the message it is bound to.+ (isUnifiedInputMode() &&+ isEditingMessage(props.messageEditor, props.message.id))+ }onClick={props.onClick}ref={(el) =>touchHandler(el, () => ({@@ -209,27 +220,25 @@ export function ChannelMessage(props: ChannelMessageProps) {}))}>- <MessageSelectionProvider value={props.selectionState}>- <Switch>- <Match when={props.message.deleted_at != null}>- <DeletedMessageLayout />- </Match>- <Match when={isGrouped()}>- <GroupedMessageLayout- channelId={props.channelId}- messageEditor={props.messageEditor}- participants={props.participants}- />- </Match>- <Match when={true}>- <RegularMessageLayout- channelId={props.channelId}- messageEditor={props.messageEditor}- participants={props.participants}- />- </Match>- </Switch>- </MessageSelectionProvider>+ <Switch>+ <Match when={props.message.deleted_at != null}>+ <DeletedMessageLayout />+ </Match>+ <Match when={isGrouped()}>+ <GroupedMessageLayout+ channelId={props.channelId}+ messageEditor={props.messageEditor}+ participants={props.participants}+ />+ </Match>+ <Match when={true}>+ <RegularMessageLayout+ channelId={props.channelId}+ messageEditor={props.messageEditor}+ participants={props.participants}+ />+ </Match>+ </Switch></Message.Root>);}diff --git a/js/app/packages/channel/Message/Message.ts b/js/app/packages/channel/Message/Message.tsindex 3093acf81f..46481329cb 100644--- a/js/app/packages/channel/Message/Message.ts+++ b/js/app/packages/channel/Message/Message.ts@@ -13,7 +13,7 @@ import { NewDivider } from './NewDivider';import { Reactions } from './Reactions';import { Root } from './Root';import { SenderIcon } from './SenderIcon';-import { SenderName } from './SenderName';+import { MessageSenderName } from './SenderName';import { Slot } from './Slot';import { Timestamp } from './Timestamp';@@ -21,7 +21,7 @@ export const Message = {Root,Layout,Slot,- SenderName,+ SenderName: MessageSenderName,AgentBadge,FromPill,SenderIcon,diff --git a/js/app/packages/channel/Message/Root.tsx b/js/app/packages/channel/Message/Root.tsxindex a641f2d9ec..c53dc0ae29 100644--- a/js/app/packages/channel/Message/Root.tsx+++ b/js/app/packages/channel/Message/Root.tsx@@ -6,8 +6,13 @@ import type { MessageActions, MessageData } from './types';type RootProps = JSX.HTMLAttributes<HTMLDivElement> & {message: MessageData;actions?: MessageActions;- highlighted?: boolean;+ /** This message is the selection cursor. Renders the background highlight. */selected?: boolean;+ /**+ * The unified-input mode's floating reply/edit input, or message+ * navigation, points at this message. Renders the accent bar.+ */+ targeted?: boolean;};export function Root(props: RootProps) {@@ -16,8 +21,8 @@ export function Root(props: RootProps) {'class','message','actions',- 'highlighted','selected',+ 'targeted',]);return (@@ -25,8 +30,8 @@ export function Root(props: RootProps) {class={cn('group/message relative touch:no-select-children', local.class)}data-messagedata-message-id={local.message.id}- data-highlighted={local.highlighted ? '' : undefined}data-selected={local.selected ? '' : undefined}+ data-targeted={local.targeted ? '' : undefined}{...rest}><div class="absolute h-full w-1 left-0 top-0 bg-accent opacity-0 message-accent-bar" />diff --git a/js/app/packages/channel/Message/SenderName.tsx b/js/app/packages/channel/Message/SenderName.tsxindex 109e841019..ed60b651e8 100644--- a/js/app/packages/channel/Message/SenderName.tsx+++ b/js/app/packages/channel/Message/SenderName.tsx@@ -5,6 +5,7 @@ import { cn } from '@ui';import { Show } from 'solid-js';import { MACRO_AI_BOT_ID, MACRO_AI_NAME } from '../macroAi';import { useMessage } from './context';+import type { MessageData } from './types';type SenderNameProps = {class?: string;@@ -22,17 +23,22 @@ function botName(return parsed.id === MACRO_AI_BOT_ID ? MACRO_AI_NAME : 'Bot';}-export function SenderName(props: SenderNameProps) {+export function MessageSenderName(props: SenderNameProps) {const message = useMessage();- const macroId = () => tryMacroId(message().sender_id);- const [displayName] = useDisplayName(macroId());- const agentName = () => botName(message().sender_id, message().sender);return (<Show when={!props.hidden}><span class={cn('text-sm font-medium truncate', props.class)}>- {agentName() ?? displayName()}+ <SenderName message={message()} /></span></Show>);}++export function SenderName(props: { message: MessageData }) {+ const macroId = () => tryMacroId(props.message.sender_id);+ const [displayName] = useDisplayName(macroId());+ const agentName = () =>+ botName(props.message.sender_id, props.message.sender);+ return <>{agentName() ?? displayName()}</>;+}diff --git a/js/app/packages/channel/Message/context.ts b/js/app/packages/channel/Message/context.tsindex 9f0a8cb2be..f1ff8f63c1 100644--- a/js/app/packages/channel/Message/context.ts+++ b/js/app/packages/channel/Message/context.ts@@ -46,14 +46,3 @@ export const MessageActionDrawerContextProvider =export function useMessageActionDrawer(): MessageActionDrawerState | undefined {return useContext(MessageActionDrawerContext);}--export type MessageSelectionState = {- isSelected: boolean;-};--const MessageSelectionContext = createContext<MessageSelectionState>();-export const MessageSelectionProvider = MessageSelectionContext.Provider;--export function useMessageSelection(): MessageSelectionState | undefined {- return useContext(MessageSelectionContext);-}diff --git a/js/app/packages/channel/Message/index.ts b/js/app/packages/channel/Message/index.tsindex feef75449e..796035eb11 100644--- a/js/app/packages/channel/Message/index.ts+++ b/js/app/packages/channel/Message/index.ts@@ -1,20 +1,15 @@import {MessageActionsProvider,- MessageSelectionProvider,SearchHighlightTermsProvider,useMessage,useMessageActions,- useMessageSelection,useSearchHighlightTermsLookup,} from './context';export { ActionMenu } from './ActionMenu';export { Attachments } from './Attachments';export { ChannelMessage } from './ChannelMessage';-export type {- MessageSelectionState,- SearchHighlightTermsLookup,-} from './context';+export type { SearchHighlightTermsLookup } from './context';export { DateDivider } from './DateDivider';export type { ChannelMessageListMeta } from './list-meta';export { MediaPreview } from './MediaPreview';@@ -30,10 +25,8 @@ export type {} from './types';export {MessageActionsProvider,- MessageSelectionProvider,SearchHighlightTermsProvider,useMessage,useMessageActions,- useMessageSelection,useSearchHighlightTermsLookup,};diff --git a/js/app/packages/channel/Mobile/ActionDrawer.tsx b/js/app/packages/channel/Mobile/ActionDrawer.tsxindex ddd5a87f80..2bb33ea87c 100644--- a/js/app/packages/channel/Mobile/ActionDrawer.tsx+++ b/js/app/packages/channel/Mobile/ActionDrawer.tsx@@ -46,18 +46,21 @@ type ActionItem = {function buildActionItems(actions: MessageActions | undefined,- messageId: string | undefined+ message: { id: string; thread_id?: string | null } | undefined): ActionItem[] {+ const messageId = message?.id;+ // Reply inputs are keyed by the thread root, not the long-pressed message.+ const replyThreadId = message ? (message.thread_id ?? message.id) : undefined;return [{id: 'reply',label: 'Reply',icon: ReplyIcon,onClick: actions?.onReply,- getFocusTarget: messageId+ getFocusTarget: replyThreadId? () =>document.querySelector<HTMLElement>(- `[data-input-id="thread-reply-input-${messageId}"] [contenteditable]`+ `[data-input-id="thread-reply-input-${replyThreadId}"] [contenteditable]`): undefined,},@@ -176,7 +179,7 @@ export function ActionDrawer() {drawerState.close();};- const actionItems = () => buildActionItems(actions(), message()?.id);+ const actionItems = () => buildActionItems(actions(), message());const nonDestructiveActions = () =>actionItems().filter((item) => item.onClick && !item.destructive);const destructiveActions = () =>diff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsxindex ac2bfb70ad..c17ebb78bb 100644--- a/js/app/packages/channel/Thread/ChannelThread.tsx+++ b/js/app/packages/channel/Thread/ChannelThread.tsx@@ -1,5 +1,6 @@import { DebugSuspense } from '@channel/DebugSuspense';import { useUserId } from '@core/context/user';+import { isTouchDevice } from '@core/mobile/isTouchDevice';import { tryMacroId, useDisplayName } from '@core/user';import { MarkMessageNotifications } from '@notifications/components/MarkMessageNotifications';import { useThreadRepliesQuery } from '@queries/channel/thread-replies';@@ -7,6 +8,7 @@ import type { ApiThreadReply } from '@service-storage/generated/schemas/apiThreaimport { createEffect, createSignal, on, Show, untrack } from 'solid-js';import { createMessageSelection } from '../Channel/create-message-selection';import { ChannelMessage } from '../Message';+import { isUnifiedInputMode } from '../unified-input-mode';import { createThreadHotkeys } from './create-thread-hotkeys';import { Thread } from './Thread';import type { ThreadReplyListHandle } from './ThreadReplyList';@@ -33,6 +35,17 @@ export function ChannelThread(props: ThreadProps) {const isSelected = () => props.selectedMessageId?.() === props.data().id;+ // The unified input's reply binding, resolved against this thread.+ // `undefined` unless the binding points into this thread; otherwise it is+ // bound either to the root or to one of this thread's replies.+ const unifiedReplyBinding = () => {+ const target = props.unifiedReplyTarget;+ if (!isUnifiedInputMode() || target?.threadId !== props.data().id) {+ return undefined;+ }+ return { boundToRoot: !target.replyId, boundReplyId: target.replyId };+ };+const repliesQuery = useThreadRepliesQuery(props.channelId,() => props.data().id,@@ -85,6 +98,8 @@ export function ChannelThread(props: ThreadProps) {const isThreadFocused = () => !!replySelection.selectedId();const selectThreadMessage = () => {+ // On touch devices, we want to block "click to select"+ if (isTouchDevice()) return;if (isSelected() && !isThreadFocused()) {props.onClearSelection?.();return;@@ -95,6 +110,8 @@ export function ChannelThread(props: ThreadProps) {};const selectReply = (replyId: string) => {+ // On touch devices, we want to block "click to select"+ if (isTouchDevice()) return;if (isSelected() && replySelection.selectedId() === replyId) {replySelection.clear();props.onClearSelection?.();@@ -145,32 +162,40 @@ export function ChannelThread(props: ThreadProps) {getUniqueReplyUserIds(activeReplies().slice(DEFAULT_VISIBLE_REPLY_COUNT));const collapsedLatestReplyAt = () =>getThreadLatestReplyAt(thread().latest_reply_at, activeReplies());+ // Replying to this thread — inline input open, or the unified input bound.+ const isReplyingToThread = () =>+ props.isReplying() || unifiedReplyBinding() !== undefined;const shouldShowCollapsedIndicator = () =>- !props.isReplying() && !props.isExpanded() && collapsedRepliesCount() > 0;+ !isReplyingToThread() && !props.isExpanded() && collapsedRepliesCount() > 0;const replyAction = () => props.getMessageActions?.(props.data())?.onReply;const shouldShowReplyButton = () =>+ !isUnifiedInputMode() &&hasReplies() &&!!replyAction() &&- !props.isReplying() &&+ !isReplyingToThread() &&!shouldShowCollapsedIndicator();const [replyListHandle, setReplyListHandle] =createSignal<ThreadReplyListHandle>();createEffect(on(- [() => props.selectedReplyId, () => props.targetReplyId, loadedReplies],- ([selectedReplyId, _targetReplyId, replies]) => {- if (!selectedReplyId) {+ [+ () => props.activeTargetReplyId,+ () => props.targetReplyId,+ loadedReplies,+ ],+ ([activeTargetReplyId, _targetReplyId, replies]) => {+ if (!activeTargetReplyId) {if (replySelection.selectedId()) replySelection.clear();return;}- const found = replies.some((r) => r.id === selectedReplyId);+ const found = replies.some((r) => r.id === activeTargetReplyId);if (!found) {if (replySelection.selectedId()) replySelection.clear();return;}props.onSelectMessage?.(props.data().id);- replySelection.select(selectedReplyId);+ replySelection.select(activeTargetReplyId);}));@@ -239,20 +264,26 @@ export function ChannelThread(props: ThreadProps) {messageEditor={props.messageEditor}participants={props.participants}onClick={selectThreadMessage}- highlighted={isSelected() && !isThreadFocused()}- selectionState={- isSelected() && !isThreadFocused()- ? { isSelected: true }- : undefined+ selected={isSelected() && !isThreadFocused()}+ targeted={+ // The unified input's reply is bound to this root, or+ // channel navigation landed on it (and not on one of its+ // replies).+ unifiedReplyBinding()?.boundToRoot ||+ (!!props.targetThreadId &&+ props.targetThreadId === props.data().id &&+ !props.activeTargetReplyId)}/></DebugSuspense></MarkMessageNotifications>- <Show when={hasReplies() || props.isReplying()}>+ <Show+ when={hasReplies() || (props.isReplying() && !isUnifiedInputMode())}+ ><div class="relative w-full"><DebugSuspense name="ChannelThread.reply-rail"><Thread.ReplyRailDecorations- isReplying={props.isReplying}+ isReplying={isReplyingToThread}firstThreadReplyNewMessage={firstReplyIsNewMessage()}/></DebugSuspense>@@ -269,12 +300,16 @@ export function ChannelThread(props: ThreadProps) {isNewMessage={props.isNewMessage}onReady={setReplyListHandle}selectedReplyId={replySelection.selectedId}+ targetedReplyId={() =>+ props.activeTargetReplyId ??+ unifiedReplyBinding()?.boundReplyId+ }isThreadFocused={isThreadFocused}onSelectReply={selectReply}/></DebugSuspense>- <Show when={props.isReplying()}>+ <Show when={props.isReplying() && !isUnifiedInputMode()}><divref={(el) => {attachReplyInputRef(el);@@ -294,6 +329,7 @@ export function ChannelThread(props: ThreadProps) {replyInputState={props.replyInputState}setReplyInputState={props.setReplyInputState}setIsReplying={props.setIsReplying}+ replyInputHandle={props.replyInputHandle}setReplyInputEl={props.setReplyInputEl}setReplyInputHandle={props.setReplyInputHandle}focusRequest={props.replyInputFocusRequest}@@ -319,9 +355,13 @@ export function ChannelThread(props: ThreadProps) {<Show when={shouldShowReplyButton()}><Thread.ReplyButtongetFocusTarget={() =>- replyInputContainerRef?.querySelector<HTMLElement>(- '[contenteditable]'- ) ?? null+ !isUnifiedInputMode()+ ? (replyInputContainerRef?.querySelector<HTMLElement>(+ '[contenteditable]'+ ) ?? null)+ : document.querySelector<HTMLElement>(+ `[data-input-id="thread-reply-input-${props.data().id}"] [contenteditable]`+ )}onClick={(event) =>replyAction()?.({ message: props.data(), event })diff --git a/js/app/packages/channel/Thread/ThreadReplyChannelInput.tsx b/js/app/packages/channel/Thread/ThreadReplyChannelInput.tsxnew file mode 100644index 0000000000..2bed8eb9fc--- /dev/null+++ b/js/app/packages/channel/Thread/ThreadReplyChannelInput.tsx@@ -0,0 +1,170 @@+import { useUserId } from '@core/context/user';+import { useSendMessageMutation } from '@queries/channel/message';+import { usePostTypingUpdateMutation } from '@queries/channel/typing';+import {+ type Accessor,+ createEffect,+ createSignal,+ onCleanup,+ type Setter,+} from 'solid-js';+import type { InputHandle, InputSnapshot } from '../Input';+import { ChannelInput, createInputAttachmentTracker } from '../Input';+import { buildPostMessageSendPayload } from '../Input/message-payload';+import {+ makeAttachmentTrackerPersistenceKey,+ makeInputValuePersistenceKey,+} from '../Input/utils/persistence';+import { hasSendableInputContent } from '../Input/utils/sendable-content';+import { useChannelParticipants } from '../use-channel-participants';+import type { FocusRequest } from './focus-request';++type ThreadReplyChannelInputProps = {+ channelId: string;+ threadId: string;+ replyInputState: Accessor<InputSnapshot | undefined>;+ setReplyInputState: Setter<InputSnapshot | undefined>;+ /**+ * Shared handle slot from `ThreadState`; used to restore a failed send's+ * draft into whichever reply input is mounted by then.+ */+ replyInputHandle?: Accessor<InputHandle | undefined>;+ setReplyInputHandle?: Setter<InputHandle | undefined>;+ focusRequest?: FocusRequest;+ /** Exit reply mode. Called on close and (immediately) on send. */+ onExit: () => void;+ /** Where the reply input is hosted. Defaults to 'inline' (in the thread). */+ host?: 'inline' | 'unified';+ collapsible?: boolean;+ /** Observe the mounted input's handle (e.g. for entity drops). */+ onReady?: (handle: InputHandle) => void;+};++/**+ * The wired `ChannelInput` for thread replies: draft registration and+ * restore, focus requests, typing signals, and the send pipeline. Shared by+ * the inline `ThreadReplyInput` and the unified-input mode's+ * `UnifiedReplyInput`, which only differ in the chrome around it.+ */+export function ThreadReplyChannelInput(props: ThreadReplyChannelInputProps) {+ onCleanup(() => {+ props.setReplyInputHandle?.(undefined);+ });++ const userId = useUserId();+ const sendMessageMutation = useSendMessageMutation();+ const typingMutation = usePostTypingUpdateMutation();+ const participants = useChannelParticipants(() => props.channelId);++ const tracker = createInputAttachmentTracker({+ persistenceKey: makeAttachmentTrackerPersistenceKey({+ channelId: props.channelId,+ threadId: props.threadId,+ }),+ initialAttachments: props.replyInputState()?.attachments,+ });++ const [replyInputHandle, setLocalReplyInputHandle] =+ createSignal<InputHandle>();++ const focusIfRequested = () => {+ const handle = replyInputHandle();+ if (!handle) return;+ if (!props.focusRequest?.consume()) return;++ handle.focus();+ };++ createEffect(() => {+ props.focusRequest?.pending();+ focusIfRequested();+ });++ const onReady = (handle: InputHandle) => {+ setLocalReplyInputHandle(handle);+ props.setReplyInputHandle?.(handle);+ props.onReady?.(handle);++ const snapshot = props.replyInputState();+ requestAnimationFrame(() => {+ if (snapshot) handle.restoreSnapshot(snapshot, { focus: false });+ focusIfRequested();+ });+ };++ return (+ <ChannelInput+ input={{+ id: `thread-reply-input-${props.threadId}`,+ placeholder: 'Send a reply',+ value: props.replyInputState()?.value,+ attachments: props.replyInputState()?.attachments,+ mode: 'reply',+ host: props.host,+ }}+ collapsible={props.collapsible}+ autofocus={false}+ participants={participants.users}+ attachmentTracker={tracker}+ persistenceKey={makeInputValuePersistenceKey({+ channelId: props.channelId,+ threadId: props.threadId,+ })}+ markdownNamespace={`thread-reply-input-${props.threadId}-markdown`}+ onReady={onReady}+ onChange={(snapshot) => void props.setReplyInputState(snapshot)}+ onStartTyping={() =>+ typingMutation.mutate({+ channelId: props.channelId,+ action: 'start',+ threadId: props.threadId,+ })+ }+ onStopTyping={() =>+ typingMutation.mutate({+ channelId: props.channelId,+ action: 'stop',+ threadId: props.threadId,+ })+ }+ onClose={() => {+ props.setReplyInputState(undefined);+ props.onExit();+ }}+ onSend={(snapshot) => {+ const senderId = userId();+ if (!senderId) return;+ const payload = buildPostMessageSendPayload({+ snapshot,+ threadId: props.threadId,+ participantIds: participants.ids(),+ });++ sendMessageMutation.mutate(+ {+ channelID: props.channelId,+ senderId,+ optimisticId: crypto.randomUUID(),+ ...payload,+ },+ {+ onError: () => {+ // The user may have started a new draft by now; keep it.+ const current = props.replyInputState();+ if (current && hasSendableInputContent(current)) return;+ props.setReplyInputState(snapshot);+ props.replyInputHandle?.()?.restoreSnapshot(snapshot, {+ focus: false,+ });+ },+ }+ );++ // Exit right away — the send is optimistic; the mutation's failure+ // toast plus the draft restore above cover the error case.+ props.setReplyInputState(undefined);+ props.onExit();+ }}+ />+ );+}diff --git a/js/app/packages/channel/Thread/ThreadReplyInput.tsx b/js/app/packages/channel/Thread/ThreadReplyInput.tsxindex 4295d6fc0e..3a833bf7f3 100644--- a/js/app/packages/channel/Thread/ThreadReplyInput.tsx+++ b/js/app/packages/channel/Thread/ThreadReplyInput.tsx@@ -1,24 +1,8 @@-import {- makeAttachmentTrackerPersistenceKey,- makeInputValuePersistenceKey,-} from '@channel/Input/utils/persistence';-import { useChannelParticipants } from '@channel/use-channel-participants';-import { useUserId } from '@core/context/user';-import { useSendMessageMutation } from '@queries/channel/message';-import { usePostTypingUpdateMutation } from '@queries/channel/typing';-import {- type Accessor,- createEffect,- createSignal,- onCleanup,- type Setter,-} from 'solid-js';+import { type Accessor, createSignal, onCleanup, type Setter } from 'solid-js';import { createEntityDropZone } from '../Channel/create-entity-drop-zone';import type { InputHandle, InputSnapshot } from '../Input';-import { ChannelInput, createInputAttachmentTracker } from '../Input';-import { buildPostMessageSendPayload } from '../Input/message-payload';-import { hasSendableInputContent } from '../Input/utils/sendable-content';import type { FocusRequest } from './focus-request';+import { ThreadReplyChannelInput } from './ThreadReplyChannelInput';import { ThreadReplyInputConnector } from './ThreadReplyInputConnector';import { replyInputOffsetX } from './utils/thread-rail-geometry';@@ -28,47 +12,24 @@ type ThreadReplyInputProps = {replyInputState: Accessor<InputSnapshot | undefined>;setReplyInputState: Setter<InputSnapshot | undefined>;setIsReplying: Setter<boolean>;+ replyInputHandle?: Accessor<InputHandle | undefined>;setReplyInputEl?: Setter<HTMLElement | undefined>;setReplyInputHandle?: Setter<InputHandle | undefined>;focusRequest?: FocusRequest;};+/**+ * Inline face of the thread reply input: thread-rail chrome and entity drops+ * around the shared `ThreadReplyChannelInput` wiring.+ */export function ThreadReplyInput(props: ThreadReplyInputProps) {onCleanup(() => {props.setReplyInputEl?.(undefined);- props.setReplyInputHandle?.(undefined);- });-- const userId = useUserId();- const sendMessageMutation = useSendMessageMutation();- const typingMutation = usePostTypingUpdateMutation();-- const participants = useChannelParticipants(() => props.channelId);-- const tracker = createInputAttachmentTracker({- persistenceKey: makeAttachmentTrackerPersistenceKey({- channelId: props.channelId,- threadId: props.messageId,- }),- initialAttachments: props.replyInputState()?.attachments,});const [replyInputHandle, setLocalReplyInputHandle] =createSignal<InputHandle>();- const focusIfRequested = () => {- const handle = replyInputHandle();- if (!handle) return;- if (!props.focusRequest?.consume()) return;-- handle.focus();- };-- createEffect(() => {- props.focusRequest?.pending();- focusIfRequested();- });-const entityDropZone = createEntityDropZone({droppableId: `thread-reply-entity-drop-${props.messageId}`,onDropEntity: (entity, coordinates) =>@@ -79,24 +40,12 @@ export function ThreadReplyInput(props: ThreadReplyInputProps) {replyInputHandle()?.clearEntityMentionInsertionPreview?.(),});- const setReplyInputHandle = (handle: InputHandle) => {- setLocalReplyInputHandle(handle);- props.setReplyInputHandle?.(handle);-- const snapshot = props.replyInputState();- requestAnimationFrame(() => {- if (snapshot) handle.restoreSnapshot(snapshot, { focus: false });- focusIfRequested();- });- };-return (<divclass="relative pt-2"style={{ 'margin-left': replyInputOffsetX }}ref={(el) => props.setReplyInputEl?.(el)}data-reply-input- data-inline-input-container-id={props.messageId}><ThreadReplyInputConnector />{(() => {@@ -104,73 +53,16 @@ export function ThreadReplyInput(props: ThreadReplyInputProps) {false && droppable;return (<div class="relative" use:droppable>- <ChannelInput- input={{- id: `thread-reply-input-${props.messageId}`,- placeholder: 'Send a reply',- value: props.replyInputState()?.value,- attachments: props.replyInputState()?.attachments,- mode: 'reply',- }}- participants={participants.users}- attachmentTracker={tracker}- persistenceKey={makeInputValuePersistenceKey({- channelId: props.channelId,- threadId: props.messageId,- })}- markdownNamespace={`thread-reply-input-${props.messageId}-markdown`}- autofocus={false}- onReady={setReplyInputHandle}- onChange={(snapshot) => void props.setReplyInputState(snapshot)}- onStartTyping={() =>- typingMutation.mutate({- channelId: props.channelId,- action: 'start',- threadId: props.messageId,- })- }- onStopTyping={() =>- typingMutation.mutate({- channelId: props.channelId,- action: 'stop',- threadId: props.messageId,- })- }- onClose={() => {- props.setReplyInputState(undefined);- props.setIsReplying(false);- }}- onSend={(snapshot) => {- const senderId = userId();- if (!senderId) return;- const payload = buildPostMessageSendPayload({- snapshot,- threadId: props.messageId,- participantIds: participants.ids(),- });-- sendMessageMutation.mutate(- {- channelID: props.channelId,- senderId,- optimisticId: crypto.randomUUID(),- ...payload,- },- {- onSuccess: () => {- props.setReplyInputState(undefined);- props.setIsReplying(false);- },- onError: () => {- const handle = replyInputHandle();- if (!handle) return;- const current = props.replyInputState();- if (current && hasSendableInputContent(current)) return;- handle.restoreSnapshot(snapshot);- },- }- );- }}+ <ThreadReplyChannelInput+ channelId={props.channelId}+ threadId={props.messageId}+ replyInputState={props.replyInputState}+ setReplyInputState={props.setReplyInputState}+ replyInputHandle={props.replyInputHandle}+ setReplyInputHandle={props.setReplyInputHandle}+ focusRequest={props.focusRequest}+ onReady={setLocalReplyInputHandle}+ onExit={() => props.setIsReplying(false)}/></div>);diff --git a/js/app/packages/channel/Thread/ThreadReplyList.tsx b/js/app/packages/channel/Thread/ThreadReplyList.tsxindex a0e4c960a1..cc2f001fcd 100644--- a/js/app/packages/channel/Thread/ThreadReplyList.tsx+++ b/js/app/packages/channel/Thread/ThreadReplyList.tsx@@ -34,6 +34,10 @@ export function ThreadReplyList(props: {isNewMessage?: (message: NewMessageCheckable) => boolean;onReady?: (handle: ThreadReplyListHandle) => void;selectedReplyId?: Accessor<string | undefined>;+ /**+ * Reply targeted by channel navigation or bound to the unified input's reply (quote-reply).+ */+ targetedReplyId?: Accessor<string | undefined>;isThreadFocused?: Accessor<boolean>;onSelectReply?: (replyId: string) => void;}) {@@ -89,10 +93,8 @@ export function ThreadReplyList(props: {messageEditor={props.messageEditor}participants={props.participants}onClick={() => props.onSelectReply?.(reply.id)}- highlighted={isReplySelected()}- selectionState={- isReplySelected() ? { isSelected: true } : undefined- }+ selected={isReplySelected()}+ targeted={props.targetedReplyId?.() === reply.id}/></MarkMessageNotifications></div>diff --git a/js/app/packages/channel/Thread/types.ts b/js/app/packages/channel/Thread/types.tsindex e023ad7642..22d7cc1f0b 100644--- a/js/app/packages/channel/Thread/types.ts+++ b/js/app/packages/channel/Thread/types.ts@@ -31,6 +31,8 @@ export type ThreadState = {export type MessageEditState = {messageId: string;+ /** The message as it was when the edit started. */+ message: MessageData;snapshot: InputSnapshot;};@@ -46,8 +48,10 @@ export type ThreadProps = {/** One-shot scroll target. Caller must clear via `onTargetReplyScrolled`. */targetReplyId?: string;onTargetReplyScrolled?: (replyId: string) => void;- /** Persistent highlight target. */- selectedReplyId?: string;+ /** Navigation target reply */+ activeTargetReplyId?: string;+ /** The unified input's reply binding */+ unifiedReplyTarget?: { threadId: string; replyId?: string };isNewMessage?: (reply: NewMessageCheckable) => boolean;selectedMessageId?: Accessor<string | undefined>;onSelectMessage?: (messageId: string) => void;diff --git a/js/app/packages/channel/scroll-utils.ts b/js/app/packages/channel/scroll-utils.tsindex 459d6f7846..a81df66cd2 100644--- a/js/app/packages/channel/scroll-utils.ts+++ b/js/app/packages/channel/scroll-utils.ts@@ -4,12 +4,6 @@ function getMessageElement(messageId: string) {);}-function getReplyInputElement(messageId: string) {- return document.querySelector<HTMLElement>(- `[data-inline-input-container-id="${messageId}"]`- );-}-function getChannelScrollElement(element: HTMLElement) {return element.closest('[data-channel-scroll]');}@@ -21,42 +15,45 @@ export function scrollMessageIntoView(messageId: string) {return true;}-export function scrollReplyInputIntoView(messageId: string) {- const element = getReplyInputElement(messageId);- if (!element) return false;- element.scrollIntoView({ block: 'nearest' });- return true;-}-/*** Scrolls the channel's scroll container so the given element is not hidden- * behind the virtual keyboard. Call this after the keyboard has appeared and- * its height is known.+ * behind whatever covers the bottom of the screen — the virtual keyboard+ * plus any chrome floating on top of it (e.g. the unified input). Call this+ * after the keyboard has appeared and its height is known.*/-export function scrollElementAboveKeyboard(+export function scrollElementAboveObstruction(el: HTMLElement,- keyboardHeight: number+ obstructionHeight: number): boolean {- if (keyboardHeight <= 0) return false;+ if (obstructionHeight <= 0) return false;const scrollContainer = getChannelScrollElement(el);if (!scrollContainer) return false;- const inputRect = el.getBoundingClientRect();+ const elRect = el.getBoundingClientRect();const containerRect = scrollContainer.getBoundingClientRect();- // The keyboard rises from the bottom of the screen, so the visible bottom of- // the scroll container is capped at (screen bottom - keyboard height).+ // The obstruction rises from the bottom of the screen, so the visible+ // bottom of the scroll container is capped at (screen bottom - obstruction).const visibleBottom = Math.min(containerRect.bottom,- window.innerHeight - keyboardHeight+ window.innerHeight - obstructionHeight);const SCROLL_OFFSET = 8;- if (inputRect.bottom > visibleBottom - SCROLL_OFFSET) {- scrollContainer.scrollTop +=- inputRect.bottom - visibleBottom + SCROLL_OFFSET;+ if (elRect.bottom > visibleBottom - SCROLL_OFFSET) {+ scrollContainer.scrollTop += elRect.bottom - visibleBottom + SCROLL_OFFSET;return true;}return false;}++/** `scrollElementAboveKeyboard` for a message row, looked up by id. */+export function scrollMessageAboveKeyboard(+ messageId: string,+ obstructionHeight: number+): boolean {+ const element = getMessageElement(messageId);+ if (!element) return false;+ return scrollElementAboveObstruction(element, obstructionHeight);+}diff --git a/js/app/packages/channel/unified-input-mode.ts b/js/app/packages/channel/unified-input-mode.tsnew file mode 100644index 0000000000..4ffbbe6199--- /dev/null+++ b/js/app/packages/channel/unified-input-mode.ts@@ -0,0 +1,15 @@+import { UNIFIED_CHANNEL_INPUT } from '@core/constant/featureFlags';+import { isMobile } from '@core/mobile/isMobile';++/**+ * Whether the channel is in unified-input mode: one floating input handles+ * channel messages, thread replies, and message edits, with a flag above it+ * naming the current target. When off, threads render inline inputs instead+ * (thread-reply inputs inside each thread, in-place message editing).+ *+ * Always on for mobile; on desktop behind `DISABLE_INLINE_INPUTS`.+ * Reactive: `isMobile()` is signal-backed, so this flips on viewport resize.+ */+export function isUnifiedInputMode(): boolean {+ return isMobile() || UNIFIED_CHANNEL_INPUT;+}diff --git a/js/app/packages/core/comments/discussion/Discussion.tsx b/js/app/packages/core/comments/discussion/Discussion.tsxindex ff1424155f..33a03d368b 100644--- a/js/app/packages/core/comments/discussion/Discussion.tsx+++ b/js/app/packages/core/comments/discussion/Discussion.tsx@@ -310,7 +310,7 @@ function DiscussionMessageView(props: {<Message.Rootmessage={messageData()}actions={props.actions}- highlighted={props.isHighlighted}+ selected={props.isHighlighted}><Message.Layout class="pt-(--regular-message-padding-t)"><Message.Slot placement="icon">diff --git a/js/app/packages/core/constant/featureFlags.ts b/js/app/packages/core/constant/featureFlags.tsindex b37bb8edfe..d3444dea6c 100644--- a/js/app/packages/core/constant/featureFlags.ts+++ b/js/app/packages/core/constant/featureFlags.ts@@ -489,3 +489,9 @@ export const ENABLE_TAGS_FE_OVERRIDE =export const ENABLE_TAGS_SEARCH_FE_FLAG = 'enable-tags-search-fe';export const ENABLE_TAGS_SEARCH_FE_OVERRIDE =resolveFeatureFlag('ENABLE_TAGS_SEARCH_FE', DEV_MODE_ENV) || undefined;++// Channel mode where replying and editing do not happen inline, but in a single unified input instead.+export const UNIFIED_CHANNEL_INPUT = resolveFeatureFlag(+ 'UNIFIED_CHANNEL_INPUT',+ false+);diff --git a/js/app/packages/core/mobile/usePreserveFocusOnButtonTaps.ts b/js/app/packages/core/mobile/usePreserveFocusOnButtonTaps.tsindex 2b8032074d..13ba41d412 100644--- a/js/app/packages/core/mobile/usePreserveFocusOnButtonTaps.ts+++ b/js/app/packages/core/mobile/usePreserveFocusOnButtonTaps.ts@@ -36,7 +36,14 @@ export function usePreserveFocusOnButtonTaps(const target = e.target instanceof Element ? e.target : null;const button = target?.closest<HTMLElement>('button, [role="button"]');- if (!button || !container.contains(button)) return;+ if (!button) return;+ // Preserve focus for buttons inside the container, plus sibling regions+ // that opt into the keyboard-safe zone (e.g. the input flag).+ if (+ !container.contains(button) &&+ !button.closest('[data-keep-keyboard]')+ )+ return;e.preventDefault();diff --git a/js/app/packages/core/mobile/useTouchOutsideToDismissKeyboard.ts b/js/app/packages/core/mobile/useTouchOutsideToDismissKeyboard.tsindex 9124cfec8c..079faf7103 100644--- a/js/app/packages/core/mobile/useTouchOutsideToDismissKeyboard.ts+++ b/js/app/packages/core/mobile/useTouchOutsideToDismissKeyboard.ts@@ -31,10 +31,14 @@ export function useTouchOutsideToDismissKeyboard(const touch = e.touches[0];if (!touch) return;- const target = e.target as Node | null;+ const target = e.target instanceof Element ? e.target : null;// Touch is inside the container — leave the keyboard alone.if (!target || container.contains(target)) return;+ // Sibling regions that opt into the keyboard-safe zone (e.g. the input+ // flag, rendered outside the input) must not dismiss the keyboard either.+ if (target.closest('[data-keep-keyboard]')) return;+// If the active element sits inside a Kobalte dialog, focusing the// dialog root instead of calling blur() satisfies the focus-trap while// still dismissing the keyboard.