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): new channel input (#1761)
teoe4ca00973279
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsxindex 9fa3cecd8a..87d7be4670 100644--- a/js/app/packages/channel/Channel/Channel.tsx+++ b/js/app/packages/channel/Channel/Channel.tsx@@ -34,9 +34,12 @@ import type { DateValue } from '@core/util/date';import { buildChannelMessageListMeta } from './message-list-meta';import { ScrollToBottomOverlay } from './ScrollToBottomOverlay';import { ChannelThread } from '../Thread';+import { ChannelInput } from '../Input';import { createChannelMessageActions } from './create-channel-message-actions';import { createActivityTracker } from '@channel/activity-tracker';import { useChannelActivity } from '@core/context/channels';+import { createChannelDragState } from './create-channel-drag-state';+import { ChannelDropZone } from './ChannelDropZone';type ChannelProps = {channelId: string;@@ -90,6 +93,10 @@ export function Channel(props: ChannelProps) {buildChannelMessageListMeta(messages(), activityTracker.isNewMessage));+ const dragState = createChannelDragState({+ channelId: props.channelId,+ });+const getMessageActions = createChannelMessageActions({channelId: () => props.channelId,userId,@@ -97,46 +104,74 @@ export function Channel(props: ChannelProps) {deleteMessage: deleteMessageMutation.mutate,addReaction: addReactionMutation.mutate,removeReaction: removeReactionMutation.mutate,+ onReply: (ctx) => {+ const state = threadManager.getOrCreateThreadState(ctx.message.id);+ state.setIsReplying(true);+ },});return (<Suspense>- <Show when={messages().length > 0}>- <StaticMarkdownContext>- <div class="relative h-full">- <ThreadList- data={messages}- initialScrollTarget={threadListInitialScrollTarget()}- shift={shift}- onScrollNearTop={threadPaginator.shiftPaginate}- onScrollNearBottom={threadPaginator.prependPaginate}- onNavigationReady={setThreadListNavigation}- onScrollStateChange={setThreadListScrollState}- >- {(item) => {- const state = threadManager.getOrCreateThreadState(item.id);- return (- <ChannelThread- data={() => item}- channelId={() => props.channelId}- getMessageActions={getMessageActions}- isExpanded={state.isExpanded}- setIsExpanded={state.setIsExpanded}- listMeta={listMetaByMessageId()[item.id]}- threadActions={{- onDismissNewMessages: activityTracker.dismissNewMessages,- }}- />- );- }}- </ThreadList>- <ScrollToBottomOverlay- navigation={threadListNavigation}- scrollState={threadListScrollState}- />- </div>- </StaticMarkdownContext>- </Show>+ <StaticMarkdownContext>+ <ChannelDropZone dragState={dragState}>+ <Show when={messages().length > 0}>+ <div class="relative flex-1 min-h-0">+ <ThreadList+ data={messages}+ initialScrollTarget={threadListInitialScrollTarget()}+ shift={shift}+ onScrollNearTop={threadPaginator.shiftPaginate}+ onScrollNearBottom={threadPaginator.prependPaginate}+ onNavigationReady={setThreadListNavigation}+ onScrollStateChange={setThreadListScrollState}+ >+ {(item) => {+ const state = threadManager.getOrCreateThreadState(item.id);+ return (+ <ChannelThread+ data={() => item}+ channelId={() => props.channelId}+ getMessageActions={getMessageActions}+ isExpanded={state.isExpanded}+ setIsExpanded={state.setIsExpanded}+ isReplying={state.isReplying}+ setIsReplying={state.setIsReplying}+ replyInputState={state.replyInputState}+ setReplyInputState={state.setReplyInputState}+ listMeta={listMetaByMessageId()[item.id]}+ threadActions={{+ onDismissNewMessages:+ activityTracker.dismissNewMessages,+ }}+ />+ );+ }}+ </ThreadList>+ <ScrollToBottomOverlay+ navigation={threadListNavigation}+ scrollState={threadListScrollState}+ />+ </div>+ </Show>+ <Suspense>+ <div class="pb-2 w-full flex justify-center">+ <ChannelInput+ input={{+ mode: 'channel',+ id: `channel-input-${props.channelId}`,+ placeholder: 'Message channel',+ isDraggingOverChannel: dragState.isDraggingOverChannel(),+ isValidChannelDrag: dragState.isValidChannelDrag(),+ }}+ attachmentTracker={dragState.tracker}+ onReady={(handle) => {+ dragState.setAttachFilesToChannel(handle.attachFiles);+ }}+ />+ </div>+ </Suspense>+ </ChannelDropZone>+ </StaticMarkdownContext></Suspense>);}diff --git a/js/app/packages/channel/Channel/ChannelDropZone.tsx b/js/app/packages/channel/Channel/ChannelDropZone.tsxnew file mode 100644index 0000000000..428f4900ba--- /dev/null+++ b/js/app/packages/channel/Channel/ChannelDropZone.tsx@@ -0,0 +1,38 @@+import { fileFolderDrop } from '@core/directive/fileFolderDrop';+import { handleFileFolderDrop } from '@core/util/upload';+import type { ParentProps } from 'solid-js';+import type { ChannelDragState } from './create-channel-drag-state';++false && fileFolderDrop;++type ChannelDropZoneProps = ParentProps & {+ dragState: ChannelDragState;+};++export function ChannelDropZone(props: ChannelDropZoneProps) {+ const droppable = props.dragState.entityDropZone.droppable;+ false && droppable;++ return (+ <div+ class="relative h-full flex flex-col"+ use:fileFolderDrop={{+ onDragStart: (valid) => {+ props.dragState.setIsDraggingOverChannel(true);+ props.dragState.setIsValidChannelDrag(valid);+ },+ onDragEnd: () => props.dragState.setIsDraggingOverChannel(false),+ onDrop: (files, folders) => {+ handleFileFolderDrop(files, folders, (entries) => {+ void props.dragState.attachFilesToChannel?.(+ entries.map((e) => e.file)+ );+ });+ },+ }}+ >+ <div class="absolute pointer-events-none inset-0" use:droppable />+ {props.children}+ </div>+ );+}diff --git a/js/app/packages/channel/Channel/create-channel-drag-state.ts b/js/app/packages/channel/Channel/create-channel-drag-state.tsnew file mode 100644index 0000000000..7d4acac6f8--- /dev/null+++ b/js/app/packages/channel/Channel/create-channel-drag-state.ts@@ -0,0 +1,50 @@+import { createSignal, type Accessor } from 'solid-js';+import { createInputAttachmentTracker } from '../Input';+import type { InputAttachmentTracker } from '../Input';+import { createEntityDropZone } from './create-entity-drop-zone';++type CreateChannelDragStateOptions = {+ channelId: string;+};++export type ChannelDragState = {+ tracker: InputAttachmentTracker;+ entityDropZone: ReturnType<typeof createEntityDropZone>;+ isDraggingOverChannel: Accessor<boolean>;+ isValidChannelDrag: Accessor<boolean>;+ setIsDraggingOverChannel: (value: boolean) => void;+ setIsValidChannelDrag: (value: boolean) => void;+ attachFilesToChannel: ((files: File[]) => Promise<void>) | undefined;+ setAttachFilesToChannel: (fn: (files: File[]) => Promise<void>) => void;+};++export function createChannelDragState(+ options: CreateChannelDragStateOptions+): ChannelDragState {+ const tracker = createInputAttachmentTracker();+ const [isDraggingOverChannel, setIsDraggingOverChannel] = createSignal(false);+ const [isValidChannelDrag, setIsValidChannelDrag] = createSignal(true);++ const entityDropZone = createEntityDropZone({+ droppableId: `channel-entity-drop-${options.channelId}`,+ tracker,+ });++ let attachFilesToChannel: ((files: File[]) => Promise<void>) | undefined;++ return {+ tracker,+ entityDropZone,+ isDraggingOverChannel: () =>+ isDraggingOverChannel() || entityDropZone.isDraggingOver(),+ isValidChannelDrag,+ setIsDraggingOverChannel,+ setIsValidChannelDrag,+ get attachFilesToChannel() {+ return attachFilesToChannel;+ },+ setAttachFilesToChannel: (fn) => {+ attachFilesToChannel = fn;+ },+ };+}diff --git a/js/app/packages/channel/Channel/create-channel-message-actions.ts b/js/app/packages/channel/Channel/create-channel-message-actions.tsindex 9f118f934c..9e439f6ab4 100644--- a/js/app/packages/channel/Channel/create-channel-message-actions.ts+++ b/js/app/packages/channel/Channel/create-channel-message-actions.ts@@ -12,7 +12,7 @@ import {canReplyToMessage,DEFAULT_REACTION_EMOJI,hasReactionFromUser,-} from '../Thread/message-actions';+} from '../Thread/utils/message-actions';type AddReactionInput = {channelId: string;diff --git a/js/app/packages/channel/Channel/create-entity-drop-zone.ts b/js/app/packages/channel/Channel/create-entity-drop-zone.tsnew file mode 100644index 0000000000..dd7e836404--- /dev/null+++ b/js/app/packages/channel/Channel/create-entity-drop-zone.ts@@ -0,0 +1,60 @@+import type { EntityDragData, EntityDragEvent } from '@entity';+import { createDroppable, useDragDropContext } from '@thisbeyond/solid-dnd';+import { createMemo, type Accessor } from 'solid-js';+import type { InputAttachmentTracker } from '../Input';++type CreateEntityDropZoneOptions = {+ droppableId: string;+ tracker: InputAttachmentTracker;+};++type EntityDropZone = {+ droppable: ReturnType<typeof createDroppable>;+ isDraggingOver: Accessor<boolean>;+};++export function createEntityDropZone(+ options: CreateEntityDropZoneOptions+): EntityDropZone {+ const droppable = createDroppable(options.droppableId);++ const [state, { onDragEnd }] = useDragDropContext() ?? [+ undefined,+ { onDragEnd: () => {} },+ ];++ const entityDragData = createMemo(() => {+ const draggable = state?.active.draggable;+ if (!draggable) return;+ const dragData = draggable.data;+ if (!dragData || dragData.dragType !== 'entity') return;+ return dragData as EntityDragData;+ });++ const isDraggingOver = createMemo(() => {+ const dragData = entityDragData();+ if (!dragData) return false;++ const activeDroppable = state?.active.droppable;+ return !!activeDroppable && activeDroppable.id === options.droppableId;+ });++ onDragEnd((event: EntityDragEvent) => {+ if (!event.droppable) return;+ if (event.droppable.id !== options.droppableId) return;++ const data = event.draggable?.data;+ if (!data || data.dragType !== 'entity') return;++ const fileType = 'fileType' in data ? data.fileType : undefined;++ options.tracker.addAttachment({+ id: data.id,+ name: data.name,+ kind: 'document',+ iconType: fileType ?? data.type,+ });+ });++ return { droppable, isDraggingOver };+}diff --git a/js/app/packages/channel/Channel/thread-manager.ts b/js/app/packages/channel/Channel/thread-manager.tsindex 32c4e712a3..afc0d8d656 100644--- a/js/app/packages/channel/Channel/thread-manager.ts+++ b/js/app/packages/channel/Channel/thread-manager.ts@@ -1,6 +1,7 @@import { createStore } from 'solid-js/store';import type { ThreadState } from '../Thread';import { createSignal } from 'solid-js';+import type { InputSnapshot } from '@channel/Input';type ThreadStore = Record<string, ThreadState>;export function createThreadManager() {@@ -8,9 +9,18 @@ export function createThreadManager() {function initThreadState(threadId: string): ThreadState {const [isExpanded, setIsExpanded] = createSignal<boolean>(false);- const state = {+ const [isReplying, setIsReplying] = createSignal<boolean>(false);+ const [replyInputState, setReplyInputState] = createSignal<+ InputSnapshot | undefined+ >();++ const state: ThreadState = {isExpanded,setIsExpanded,+ isReplying,+ setIsReplying,+ replyInputState,+ setReplyInputState,};setThreadStore(threadId, state);diff --git a/js/app/packages/channel/Input/Attachments.tsx b/js/app/packages/channel/Input/Attachments.tsxnew file mode 100644index 0000000000..fe8bf69b57--- /dev/null+++ b/js/app/packages/channel/Input/Attachments.tsx@@ -0,0 +1,166 @@+import {+ children,+ For,+ Match,+ Show,+ splitProps,+ Switch,+ type JSX,+} from 'solid-js';+import { EntityIcon } from '@core/component/EntityIcon';+import { ImagePreview } from '@core/component/ImagePreview';+import { VideoPreview } from '@core/component/VideoPreview';+import { cn } from '@ui/utils/classname';+import { useInput, useInputCommands } from './context';+import type { InputAttachmentData, InputAttachmentKind } from './types';+import XIcon from '@icon/regular/x.svg';+import SpinnerIcon from '@icon/bold/spinner-gap-bold.svg';+import { renderIcon } from './utils/render-icon';++type AttachmentsProps = JSX.HTMLAttributes<HTMLDivElement> & {+ kind?: InputAttachmentKind | 'media';+};++function RemoveButton(props: {+ attachment: InputAttachmentData;+ onRemove: (attachment: InputAttachmentData) => void;+ class?: string;+}) {+ return (+ <button+ type="button"+ class={cn(+ 'hover:bg-hover hover-transition-bg rounded-md p-1 items-center flex',+ props.class+ )}+ onClick={(event) => {+ event.stopPropagation();+ props.onRemove(props.attachment);+ }}+ aria-label={`Remove ${props.attachment.name}`}+ >+ {renderIcon(XIcon, 'text-ink-muted group-hover:text-failure size-3')}+ </button>+ );+}++function MediaAttachmentItem(props: {+ attachment: InputAttachmentData;+ onRemove: (attachment: InputAttachmentData) => void;+}) {+ return (+ <div class="relative group">+ <RemoveButton+ attachment={props.attachment}+ onRemove={props.onRemove}+ class="absolute -top-2 -right-2 z-[10] rounded-full bg-menu border border-edge-muted opacity-0 group-hover:opacity-100 focus-visible:opacity-100"+ />+ <Show+ when={!props.attachment.pending && props.attachment.kind === 'image'}+ fallback={+ <Show+ when={+ !props.attachment.pending && props.attachment.kind === 'video'+ }+ fallback={+ <div class="flex flex-col items-center justify-center gap-2 w-[60px] h-[60px] border border-edge-muted rounded-md bg-menu">+ {renderIcon(SpinnerIcon, 'w-4 h-4 animate-spin')}+ </div>+ }+ >+ <VideoPreview id={props.attachment.id} variant="small" />+ </Show>+ }+ >+ <ImagePreview image={{ id: props.attachment.id }} variant="small" />+ </Show>+ </div>+ );+}++function DocumentAttachmentItem(props: {+ attachment: InputAttachmentData;+ onRemove: (attachment: InputAttachmentData) => void;+}) {+ return (+ <div class="group flex items-center px-2 py-1.5 space-x-1.5 hover:bg-hover hover-transition-bg cursor-default text-sm border border-edge-muted rounded-xs">+ <Show+ when={!props.attachment.pending}+ fallback={renderIcon(SpinnerIcon, 'w-4 h-4 animate-spin')}+ >+ <EntityIcon+ targetType={props.attachment.iconType ?? 'unknown'}+ size="xs"+ />+ </Show>+ <span class="truncate max-w-[16rem]">{props.attachment.name}</span>+ <RemoveButton attachment={props.attachment} onRemove={props.onRemove} />+ </div>+ );+}++export function Attachments(props: AttachmentsProps) {+ const input = useInput();+ const commands = useInputCommands();+ const [local, rest] = splitProps(props, ['class', 'children', 'kind']);+ const resolved = children(() => local.children);++ const visibleAttachments = () => {+ const items = input().attachments ?? [];+ if (!local.kind) return items;+ if (local.kind === 'media') {+ return items.filter(+ (attachment) =>+ attachment.kind === 'image' || attachment.kind === 'video'+ );+ }+ return items.filter((attachment) => attachment.kind === local.kind);+ };++ const handleRemove = (attachment: InputAttachmentData) => {+ commands.removeAttachment(attachment);+ };++ return (+ <Show when={visibleAttachments().length > 0}>+ <div+ class={cn(+ 'flex flex-row w-full px-2 py-1 gap-2 flex-wrap',+ local.class+ )}+ data-input-attachments={local.kind ?? 'all'}+ {...rest}+ >+ <Show+ when={resolved()}+ fallback={+ <For each={visibleAttachments()}>+ {(attachment) => (+ <Switch>+ <Match+ when={+ attachment.kind === 'image' || attachment.kind === 'video'+ }+ >+ <MediaAttachmentItem+ attachment={attachment}+ onRemove={handleRemove}+ />+ </Match>+ <Match when={attachment.kind === 'document'}>+ <DocumentAttachmentItem+ attachment={attachment}+ onRemove={handleRemove}+ />+ </Match>+ </Switch>+ )}+ </For>+ }+ >+ {(children) => children()}+ </Show>+ </div>+ </Show>+ );+}diff --git a/js/app/packages/channel/Input/ChannelInput.tsx b/js/app/packages/channel/Input/ChannelInput.tsxnew file mode 100644index 0000000000..a5fffd4ac8--- /dev/null+++ b/js/app/packages/channel/Input/ChannelInput.tsx@@ -0,0 +1,131 @@+import { MarkdownShell } from '@core/component/LexicalMarkdown/builder/MarkdownShell';+import { isMobile } from '@core/mobile/isMobile';+import { Input } from './Input';+import { FormatButtons } from './FormatButtons';+import { createConfiguredChannelMarkdownEditor } from './configured-markdown-editor';+import { createInputAttachmentTracker } from './attachment-tracker';+import { createInputState } from './create-input-state';+import { createMentionsTracker } from './mentions-tracker';+import { chatRuleset, uploadFile } from '@core/util/upload';+import { uploadInputAttachments } from './upload-attachments';+import type {+ InputAttachmentTracker,+ InputCallbacks,+ InputData,+ InputDraftAdapter,+ InputHandle,+} from './types';+import { applyInlineFormat, applyNodeFormat } from './utils/formatting';++type ChannelInputProps = InputCallbacks & {+ input: InputData;+ markdownNamespace?: string;+ draft?: InputDraftAdapter;+ attachmentTracker?: InputAttachmentTracker;+ onReady?: (handle: InputHandle) => void;+};++export function ChannelInput(props: ChannelInputProps) {+ const mentionsTracker = createMentionsTracker();+ const attachmentTracker =+ props.attachmentTracker ??+ createInputAttachmentTracker({+ initialAttachments: props.input.attachments,+ });++ const inputState = createInputState({+ initialInput: props.input,+ mentions: mentionsTracker.mentions,+ attachmentTracker,+ attachFiles: async (files) => {+ await uploadInputAttachments({+ files,+ tracker: attachmentTracker,+ uploadFile: async (file) => {+ return uploadFile(file, chatRuleset, {+ hideProgressIndicator: true,+ });+ },+ });+ },+ callbacks: {+ onChange: props.onChange,+ onSend: props.onSend,+ onToggleFormatRibbon: props.onToggleFormatRibbon,+ onCloseDraft: props.onCloseDraft,+ onRemoveAttachment: props.onRemoveAttachment,+ },+ draft: props.draft,+ });++ const markdownEditor = createConfiguredChannelMarkdownEditor({+ namespace: props.markdownNamespace ?? 'channel-input-markdown',+ enableMentions: true,+ onMentionCreate: (mention) => {+ mentionsTracker.onMentionCreate(mention);+ },+ onMentionRemove: (mention) => {+ mentionsTracker.onMentionRemove(mention);+ },+ onChange: (markdown) => {+ inputState.setValue(markdown);+ },+ onEnter: () => {+ if (isMobile()) return false;+ inputState.commands.send();+ return true;+ },+ });++ props.onReady?.({+ clear: () => markdownEditor.controls.clear(),+ focus: () => markdownEditor.controls.focus(),+ attachFiles: (files) => inputState.commands.attachFiles(files),+ });++ return (+ <Input.Root input={inputState.view()} commands={inputState.commands}>+ <Input.DropZone+ onDragStart={(valid) => inputState.setIsDraggedOver(valid)}+ onDragEnd={() => inputState.setIsDraggedOver(false)}+ >+ <Input.Layout>+ <Input.DropOverlay />+ <Input.FormatRibbon>+ <FormatButtons+ selectionState={() => markdownEditor.selection}+ onInlineFormat={(format) =>+ applyInlineFormat(markdownEditor.lexical, format)+ }+ onNodeFormat={(format) =>+ applyNodeFormat(markdownEditor.lexical, format)+ }+ />+ </Input.FormatRibbon>+ <Input.EditorShell+ onClick={(event) => {+ event.stopPropagation();+ markdownEditor.controls.focus();+ }}+ >+ <Input.Editor>+ <MarkdownShell+ config={markdownEditor}+ placeholder={inputState.view().placeholder}+ initialValue={props.input.value}+ autofocus={!isMobile()}+ class="text-sm mobile:text-base"+ />+ </Input.Editor>+ </Input.EditorShell>+ <Input.Attachments kind="media" />+ <Input.Attachments kind="document" />+ <Input.Footer>+ <Input.PrimaryActions />+ <Input.SendAction />+ </Input.Footer>+ </Input.Layout>+ </Input.DropZone>+ </Input.Root>+ );+}diff --git a/js/app/packages/channel/Input/DropOverlay.tsx b/js/app/packages/channel/Input/DropOverlay.tsxnew file mode 100644index 0000000000..ce24e625c7--- /dev/null+++ b/js/app/packages/channel/Input/DropOverlay.tsx@@ -0,0 +1,50 @@+import { children, Show, splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';+import { useInput } from './context';+import { isReplyInput } from './types';++type DropOverlayProps = JSX.HTMLAttributes<HTMLDivElement> & {+ invalidMessage?: string;+ hint?: string;+};++export function DropOverlay(props: DropOverlayProps) {+ const input = useInput();+ const [local, rest] = splitProps(props, [+ 'class',+ 'children',+ 'invalidMessage',+ 'hint',+ ]);+ const resolved = children(() => local.children);++ const open = () =>+ !!input().isDraggedOver ||+ (!!input().isDraggingOverChannel && !isReplyInput(input()));+ const valid = () => input().isValidChannelDrag !== false;++ return (+ <Show when={open()}>+ <div+ class={cn(+ 'absolute inset-0 z-20 bg-modal-overlay pattern-diagonal-8 flex items-center justify-center',+ valid() ? 'pattern-edge-muted' : 'pattern-failure-bg',+ local.class+ )}+ data-input-drop-overlay+ {...rest}+ >+ <div class="bg-menu border-1 border-edge px-8 py-4 text-xs text-ink-muted shadow-md font-mono">+ <Show+ when={valid()}+ fallback={local.invalidMessage ?? 'Invalid file'}+ >+ {resolved() ??+ local.hint ??+ 'Drop any file here to add it to the conversation'}+ </Show>+ </div>+ </div>+ </Show>+ );+}diff --git a/js/app/packages/channel/Input/DropZone.tsx b/js/app/packages/channel/Input/DropZone.tsxnew file mode 100644index 0000000000..cc066010bc--- /dev/null+++ b/js/app/packages/channel/Input/DropZone.tsx@@ -0,0 +1,32 @@+import { fileFolderDrop } from '@core/directive/fileFolderDrop';+import { handleFileFolderDrop } from '@core/util/upload';+import type { ParentProps } from 'solid-js';+import { useInputCommands } from './context';++false && fileFolderDrop;++type DropZoneProps = ParentProps & {+ onDragStart?: (valid: boolean) => void;+ onDragEnd?: () => void;+};++export function DropZone(props: DropZoneProps) {+ const commands = useInputCommands();++ return (+ <div+ class="contents"+ use:fileFolderDrop={{+ onDragStart: (valid) => props.onDragStart?.(valid),+ onDragEnd: () => props.onDragEnd?.(),+ onDrop: (files, folders) => {+ handleFileFolderDrop(files, folders, (entries) => {+ void commands.attachFiles(entries.map((e) => e.file));+ });+ },+ }}+ >+ {props.children}+ </div>+ );+}diff --git a/js/app/packages/channel/Input/Editor.tsx b/js/app/packages/channel/Input/Editor.tsxnew file mode 100644index 0000000000..e726f3adff--- /dev/null+++ b/js/app/packages/channel/Input/Editor.tsx@@ -0,0 +1,28 @@+import { children, Show, splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';+import { useInput } from './context';++export function Editor(props: JSX.HTMLAttributes<HTMLDivElement>) {+ const input = useInput();+ const [local, rest] = splitProps(props, ['class', 'children']);+ const resolved = children(() => local.children);++ return (+ <div+ class={cn('min-h-6 text-sm whitespace-pre-wrap break-words', local.class)}+ data-input-editor+ {...rest}+ >+ <Show+ when={resolved()}+ fallback={+ <span class="text-ink-placeholder">+ {input().value?.trim() ? input().value : input().placeholder}+ </span>+ }+ >+ {(children) => children()}+ </Show>+ </div>+ );+}diff --git a/js/app/packages/channel/Input/EditorShell.tsx b/js/app/packages/channel/Input/EditorShell.tsxnew file mode 100644index 0000000000..463c742e80--- /dev/null+++ b/js/app/packages/channel/Input/EditorShell.tsx@@ -0,0 +1,19 @@+import { splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';++export function EditorShell(props: JSX.HTMLAttributes<HTMLDivElement>) {+ const [local, rest] = splitProps(props, ['class', 'children']);++ return (+ <div+ class={cn(+ 'transition-all duration-150 px-3 pt-2 pb-2 @min-[40rem]:pb-4 overflow-y-auto placeholder:text-ink-placeholder text-ink w-full text-sm mobile:text-base',+ local.class+ )}+ data-input-editor-shell+ {...rest}+ >+ {local.children}+ </div>+ );+}diff --git a/js/app/packages/channel/Input/Footer.tsx b/js/app/packages/channel/Input/Footer.tsxnew file mode 100644index 0000000000..d3e070349d--- /dev/null+++ b/js/app/packages/channel/Input/Footer.tsx@@ -0,0 +1,19 @@+import { splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';++export function Footer(props: JSX.HTMLAttributes<HTMLDivElement>) {+ const [local, rest] = splitProps(props, ['class', 'children']);++ return (+ <div+ class={cn(+ 'flex flex-row w-full h-8 justify-between items-center p-2 mb-2 space-x-2 allow-css-brackets',+ local.class+ )}+ data-input-footer+ {...rest}+ >+ {local.children}+ </div>+ );+}diff --git a/js/app/packages/channel/Input/FormatButtons.tsx b/js/app/packages/channel/Input/FormatButtons.tsxnew file mode 100644index 0000000000..6168865ff5--- /dev/null+++ b/js/app/packages/channel/Input/FormatButtons.tsx@@ -0,0 +1,78 @@+import type { Accessor } from 'solid-js';+import TextBoldIcon from '@icon/bold/text-b-bold.svg';+import TextCodeIcon from '@icon/regular/code.svg';+import ListBulletsIcon from '@icon/regular/list-bullets.svg';+import ListChecksIcon from '@icon/regular/list-checks.svg';+import ListNumbersIcon from '@icon/regular/list-numbers.svg';+import TextItalicIcon from '@icon/regular/text-italic.svg';+import TextStrikethroughIcon from '@icon/regular/text-strikethrough.svg';+import type {+ NodeTransformType,+ SelectionData,+} from '@core/component/LexicalMarkdown/plugins';+import type { TextFormatType } from 'lexical';+import { renderIcon } from './utils/render-icon';+import { RibbonButton } from './RibbonButton';++type FormatButtonsProps = {+ selectionState: Accessor<SelectionData | undefined>;+ onInlineFormat: (format: TextFormatType) => void;+ onNodeFormat: (format: NodeTransformType) => void;+};++export function FormatButtons(props: FormatButtonsProps) {+ return (+ <>+ <RibbonButton+ label="Bold"+ active={props.selectionState()?.bold}+ onClick={() => props.onInlineFormat('bold')}+ >+ {renderIcon(TextBoldIcon, 'size-5')}+ </RibbonButton>+ <RibbonButton+ label="Italic"+ active={props.selectionState()?.italic}+ onClick={() => props.onInlineFormat('italic')}+ >+ {renderIcon(TextItalicIcon, 'size-5')}+ </RibbonButton>+ <RibbonButton+ label="Strikethrough"+ active={props.selectionState()?.strikethrough}+ onClick={() => props.onInlineFormat('strikethrough')}+ >+ {renderIcon(TextStrikethroughIcon, 'size-5')}+ </RibbonButton>+ <RibbonButton+ label="Code"+ active={props.selectionState()?.code}+ onClick={() => props.onInlineFormat('code')}+ >+ {renderIcon(TextCodeIcon, 'size-5')}+ </RibbonButton>+ <div class="w-px h-5 bg-edge-muted" />+ <RibbonButton+ label="Bullet list"+ active={props.selectionState()?.elementsInRange.has('list-bullet')}+ onClick={() => props.onNodeFormat('list-bullet')}+ >+ {renderIcon(ListBulletsIcon, 'size-5')}+ </RibbonButton>+ <RibbonButton+ label="Numbered list"+ active={props.selectionState()?.elementsInRange.has('list-number')}+ onClick={() => props.onNodeFormat('list-number')}+ >+ {renderIcon(ListNumbersIcon, 'size-5')}+ </RibbonButton>+ <RibbonButton+ label="Checklist"+ active={props.selectionState()?.elementsInRange.has('list-check')}+ onClick={() => props.onNodeFormat('list-check')}+ >+ {renderIcon(ListChecksIcon, 'size-5')}+ </RibbonButton>+ </>+ );+}diff --git a/js/app/packages/channel/Input/FormatRibbon.tsx b/js/app/packages/channel/Input/FormatRibbon.tsxnew file mode 100644index 0000000000..3ee0fbf731--- /dev/null+++ b/js/app/packages/channel/Input/FormatRibbon.tsx@@ -0,0 +1,20 @@+import { Show, splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';+import { useInput } from './context';++export function FormatRibbon(props: JSX.HTMLAttributes<HTMLDivElement>) {+ const input = useInput();+ const [local, rest] = splitProps(props, ['class', 'children']);++ return (+ <Show when={input().showFormatRibbon}>+ <div+ class={cn('flex flex-row w-full gap-2 items-center p-2', local.class)}+ data-input-format-ribbon+ {...rest}+ >+ {local.children}+ </div>+ </Show>+ );+}diff --git a/js/app/packages/channel/Input/Input.ts b/js/app/packages/channel/Input/Input.tsnew file mode 100644index 0000000000..495a930cbd--- /dev/null+++ b/js/app/packages/channel/Input/Input.ts@@ -0,0 +1,25 @@+import { Root } from './Root';+import { Layout } from './Layout';+import { DropOverlay } from './DropOverlay';+import { DropZone } from './DropZone';+import { FormatRibbon } from './FormatRibbon';+import { EditorShell } from './EditorShell';+import { Editor } from './Editor';+import { Attachments } from './Attachments';+import { Footer } from './Footer';+import { PrimaryActions } from './PrimaryActions';+import { SendAction } from './SendAction';++export const Input = {+ Root,+ Layout,+ DropOverlay,+ DropZone,+ FormatRibbon,+ EditorShell,+ Editor,+ Attachments,+ Footer,+ PrimaryActions,+ SendAction,+};diff --git a/js/app/packages/channel/Input/Layout.tsx b/js/app/packages/channel/Input/Layout.tsxnew file mode 100644index 0000000000..96f35d222d--- /dev/null+++ b/js/app/packages/channel/Input/Layout.tsx@@ -0,0 +1,12 @@+import { splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';++export function Layout(props: JSX.HTMLAttributes<HTMLDivElement>) {+ const [local, rest] = splitProps(props, ['class', 'children']);++ return (+ <div class={cn('flex flex-col w-full', local.class)} {...rest}>+ {local.children}+ </div>+ );+}diff --git a/js/app/packages/channel/Input/PrimaryActions.tsx b/js/app/packages/channel/Input/PrimaryActions.tsxnew file mode 100644index 0000000000..7b86cfdc54--- /dev/null+++ b/js/app/packages/channel/Input/PrimaryActions.tsx@@ -0,0 +1,101 @@+import { children, Show, splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';+import { useInput, useInputCommands } from './context';+import { isReplyInput } from './types';+import FormatIcon from '@icon/regular/text-aa.svg';+import TrashIcon from '@icon/regular/trash.svg';+import PaperclipIcon from '@phosphor-icons/core/regular/paperclip.svg?component-solid';+import { renderIcon } from './utils/render-icon';+import { Button } from '@ui/components/Button';+import { LabelAndHotKey } from '@core/component/Tooltip';+import { CHANNEL_FILE_PICKER_ACCEPT } from './accepted-file-types';++function InputActionButton(props: {+ label: string;+ onClick?: (event: MouseEvent) => void;+ active?: boolean;+ children: JSX.Element;+}) {+ return (+ <Button+ title={props.label}+ aria-label={props.label}+ tooltip={<LabelAndHotKey label={props.label} />}+ onClick={(event) => props.onClick?.(event)}+ classList={{ 'bg-active': props.active }}+ >+ {props.children}+ </Button>+ );+}++export function PrimaryActions(props: JSX.HTMLAttributes<HTMLDivElement>) {+ const input = useInput();+ const commands = useInputCommands();+ const [local, rest] = splitProps(props, ['class', 'children']);+ const resolved = children(() => local.children);+ let fileInputRef: HTMLInputElement | undefined;++ const openAttachPicker = () => {+ fileInputRef?.click();+ };++ const onAttachFiles: JSX.EventHandlerUnion<HTMLInputElement, Event> = (+ event+ ) => {+ const files = Array.from(event.currentTarget.files ?? []);+ event.currentTarget.value = '';+ if (files.length === 0) return;+ void commands.attachFiles(files);+ };++ return (+ <div+ class={cn('flex flex-row items-center gap-2', local.class)}+ data-input-primary-actions+ {...rest}+ >+ <input+ ref={(element) => {+ fileInputRef = element;+ }}+ type="file"+ class="hidden"+ multiple+ accept={CHANNEL_FILE_PICKER_ACCEPT}+ onChange={onAttachFiles}+ data-input-attach-file-picker+ />+ <Show+ when={resolved()}+ fallback={+ <>+ <InputActionButton+ label="Attach files"+ onClick={() => openAttachPicker()}+ >+ {renderIcon(PaperclipIcon, 'size-5')}+ </InputActionButton>+ <InputActionButton+ label="Format"+ active={input().showFormatRibbon}+ onClick={() => commands.toggleFormatRibbon()}+ >+ {renderIcon(FormatIcon, 'size-5')}+ </InputActionButton>+ <Show when={isReplyInput(input())}>+ <InputActionButton+ label="Delete reply"+ onClick={() => commands.closeDraft()}+ >+ {renderIcon(TrashIcon, 'size-5')}+ </InputActionButton>+ </Show>+ </>+ }+ >+ {(children) => children()}+ </Show>+ </div>+ );+}diff --git a/js/app/packages/channel/Input/RibbonButton.tsx b/js/app/packages/channel/Input/RibbonButton.tsxnew file mode 100644index 0000000000..f1cb031545--- /dev/null+++ b/js/app/packages/channel/Input/RibbonButton.tsx@@ -0,0 +1,31 @@+import type { JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';++type RibbonButtonProps = {+ label: string;+ active?: boolean;+ onClick: () => void;+ children: JSX.Element;+};++export function RibbonButton(props: RibbonButtonProps) {+ return (+ <button+ type="button"+ aria-label={props.label}+ title={props.label}+ class={cn(+ 'flex flex-col items-center justify-center h-[28px] w-[28px] hover:bg-hover hover-transition-bg rounded-md',+ {+ 'bg-active': props.active,+ }+ )}+ onClick={(event) => {+ event.preventDefault();+ props.onClick();+ }}+ >+ {props.children}+ </button>+ );+}diff --git a/js/app/packages/channel/Input/Root.tsx b/js/app/packages/channel/Input/Root.tsxnew file mode 100644index 0000000000..ec09565646--- /dev/null+++ b/js/app/packages/channel/Input/Root.tsx@@ -0,0 +1,50 @@+import { splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';+import { InputProvider } from './context';+import { isReplyInput, type InputCommands, type InputData } from './types';++const NoopInputCommands: InputCommands = {+ send: async () => false,+ attachFiles: async () => {},+ toggleFormatRibbon: () => {},+ closeDraft: () => {},+ removeAttachment: () => {},+};++type RootProps = JSX.HTMLAttributes<HTMLDivElement> & {+ input: InputData;+ commands?: InputCommands;+};++export function Root(props: RootProps) {+ const [local, rest] = splitProps(props, [+ 'children',+ 'class',+ 'input',+ 'commands',+ ]);++ return (+ <div+ class={cn(+ 'relative macro-message-width flex flex-col flex-1 items-center justify-between bg-input border border-edge-muted rounded-[5px]',+ local.class,+ {+ 'rounded-b-[5px] border-b mb-4': isReplyInput(local.input),+ }+ )}+ data-input+ data-input-id={local.input.id}+ {...rest}+ >+ <InputProvider+ value={{+ view: () => local.input,+ commands: local.commands ?? NoopInputCommands,+ }}+ >+ {local.children}+ </InputProvider>+ </div>+ );+}diff --git a/js/app/packages/channel/Input/SendAction.tsx b/js/app/packages/channel/Input/SendAction.tsxnew file mode 100644index 0000000000..c11b6ef300--- /dev/null+++ b/js/app/packages/channel/Input/SendAction.tsx@@ -0,0 +1,52 @@+import { children, Show, splitProps, type JSX } from 'solid-js';+import { cn } from '@ui/utils/classname';+import { useInput, useInputCommands } from './context';+import ArrowUpIcon from '@icon/bold/arrow-up-bold.svg';+import SpinnerIcon from '@icon/bold/spinner-gap-bold.svg';+import { renderIcon } from './utils/render-icon';+import { Button } from '@ui/components/Button';+import { LabelAndHotKey } from '@core/component/Tooltip';++export function SendAction(props: JSX.ButtonHTMLAttributes<HTMLButtonElement>) {+ const input = useInput();+ const commands = useInputCommands();+ const [local, rest] = splitProps(props, ['class', 'children']);+ const resolved = children(() => local.children);+ const isBlockedByPending = () => !!input().hasPendingAttachments;++ return (+ <Button+ aria-label="Send message"+ title="Send message"+ tooltip={<LabelAndHotKey label="Send message" />}+ data-input-action="send"+ disabled={isBlockedByPending()}+ class={cn(+ 'group transition ease-in-out hover:bg-transparent',+ local.class+ )}+ onPointerDown={(event) => {+ event.preventDefault();+ void commands.send();+ }}+ {...rest}+ >+ <Show+ when={!isBlockedByPending()}+ fallback={renderIcon(+ SpinnerIcon,+ 'size-6 animate-spin cursor-disabled'+ )}+ >+ {resolved() ?? (+ <div class="group-hover:scale-115 group-hover:bg-accent transition ease-in-out size-6 touch:size-8 border border-accent rounded-full flex items-center justify-center">+ {renderIcon(+ ArrowUpIcon,+ 'group-hover:!text-input group-hover:!fill-input !text-accent-ink !fill-accent size-4 transition ease-in-out'+ )}+ </div>+ )}+ </Show>+ </Button>+ );+}diff --git a/js/app/packages/channel/Input/ThreadInput.tsx b/js/app/packages/channel/Input/ThreadInput.tsxnew file mode 100644index 0000000000..25d52e1759--- /dev/null+++ b/js/app/packages/channel/Input/ThreadInput.tsx@@ -0,0 +1,17 @@+import type { ComponentProps } from 'solid-js';+import { ChannelInput } from './ChannelInput';++type ThreadInputProps = ComponentProps<typeof ChannelInput>;++export function ThreadInput(props: ThreadInputProps) {+ return (+ <ChannelInput+ {...props}+ input={{+ ...props.input,+ mode: 'reply',+ }}+ markdownNamespace={props.markdownNamespace ?? 'thread-input-markdown'}+ />+ );+}diff --git a/js/app/packages/channel/Input/accepted-file-types.ts b/js/app/packages/channel/Input/accepted-file-types.tsnew file mode 100644index 0000000000..1a391d52c5--- /dev/null+++ b/js/app/packages/channel/Input/accepted-file-types.ts@@ -0,0 +1,56 @@+export const CHANNEL_IMAGE_FILE_EXTENSIONS = [+ 'apng',+ 'avif',+ 'bmp',+ 'gif',+ 'heic',+ 'heif',+ 'jpeg',+ 'jpg',+ 'png',+ 'svg',+ 'tif',+ 'tiff',+ 'webp',+] as const;++export const CHANNEL_VIDEO_FILE_EXTENSIONS = [+ 'avi',+ 'm4v',+ 'mkv',+ 'mov',+ 'mp4',+ 'mpeg',+ 'mpg',+ 'webm',+] as const;++export const CHANNEL_DOCUMENT_FILE_EXTENSIONS = [+ 'canvas',+ 'csv',+ 'doc',+ 'docx',+ 'json',+ 'md',+ 'pdf',+ 'ppt',+ 'pptx',+ 'rtf',+ 'txt',+ 'xls',+ 'xlsx',+ 'xml',+ 'yaml',+ 'yml',+ 'zip',+] as const;++export const CHANNEL_ACCEPTED_FILE_EXTENSIONS = [+ ...CHANNEL_IMAGE_FILE_EXTENSIONS,+ ...CHANNEL_VIDEO_FILE_EXTENSIONS,+ ...CHANNEL_DOCUMENT_FILE_EXTENSIONS,+] as const;++export const CHANNEL_FILE_PICKER_ACCEPT = CHANNEL_ACCEPTED_FILE_EXTENSIONS.map(+ (extension) => `.${extension}`+).join(',');diff --git a/js/app/packages/channel/Input/attachment-tracker.ts b/js/app/packages/channel/Input/attachment-tracker.tsnew file mode 100644index 0000000000..f554d14b32--- /dev/null+++ b/js/app/packages/channel/Input/attachment-tracker.ts@@ -0,0 +1,70 @@+import { createMemo, createSignal, type Accessor } from 'solid-js';+import type { InputAttachmentData } from './types';++export type InputAttachmentTracker = {+ attachments: Accessor<InputAttachmentData[]>;+ hasPending: Accessor<boolean>;+ addAttachment: (attachment: InputAttachmentData) => void;+ removeAttachment: (attachmentId: string) => void;+ setAttachmentPending: (attachmentId: string, pending: boolean) => void;+ setAttachments: (attachments: InputAttachmentData[]) => void;+ clearAttachments: () => void;+};++type CreateInputAttachmentTrackerOptions = {+ initialAttachments?: InputAttachmentData[];+ maxAttachments?: number;+};++export function createInputAttachmentTracker(+ options: CreateInputAttachmentTrackerOptions = {}+): InputAttachmentTracker {+ const [attachments, setAttachments] = createSignal<InputAttachmentData[]>(+ options.initialAttachments ?? []+ );+ const maxAttachments = options.maxAttachments ?? 10;++ const hasPending = createMemo(() =>+ attachments().some((attachment) => attachment.pending === true)+ );++ const addAttachment = (attachment: InputAttachmentData) => {+ setAttachments((current) => {+ if (current.some((item) => item.id === attachment.id)) return current;+ if (current.length >= maxAttachments) return current;+ return [...current, attachment];+ });+ };++ const removeAttachment = (attachmentId: string) => {+ setAttachments((current) =>+ current.filter((attachment) => attachment.id !== attachmentId)+ );+ };++ const setAttachmentPending = (attachmentId: string, pending: boolean) => {+ setAttachments((current) =>+ current.map((attachment) =>+ attachment.id === attachmentId ? { ...attachment, pending } : attachment+ )+ );+ };++ const replaceAttachments = (nextAttachments: InputAttachmentData[]) => {+ setAttachments(nextAttachments);+ };++ const clearAttachments = () => {+ setAttachments([]);+ };++ return {+ attachments,+ hasPending,+ addAttachment,+ removeAttachment,+ setAttachmentPending,+ setAttachments: replaceAttachments,+ clearAttachments,+ };+}diff --git a/js/app/packages/channel/Input/configured-markdown-editor.ts b/js/app/packages/channel/Input/configured-markdown-editor.tsnew file mode 100644index 0000000000..2264f72872--- /dev/null+++ b/js/app/packages/channel/Input/configured-markdown-editor.ts@@ -0,0 +1,54 @@+import { buildConfig } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';+import {+ DefaultShortcuts,+ type ItemMention,+ keyboardShortcutsPlugin,+} from '@core/component/LexicalMarkdown/plugins';+import { tableCellResizerPlugin } from '@core/component/LexicalMarkdown/plugins/tables/tableCellResizerPlugin';+import { tablePlugin } from '@core/component/LexicalMarkdown/plugins/tables/tablePlugin';++type CreateConfiguredChannelMarkdownEditorOptions = {+ namespace: string;+ enableMentions?: boolean;+ onMentionCreate?: (mention: ItemMention) => void;+ onMentionRemove?: (mention: ItemMention) => void;+ onChange?: (markdown: string) => void;+ onEnter?: (event: KeyboardEvent, markdown: string) => boolean;+};++export function createConfiguredChannelMarkdownEditor(+ options: CreateConfiguredChannelMarkdownEditorOptions+) {+ const editor = buildConfig('chat').namespace(options.namespace);++ if (options.enableMentions !== false) {+ editor.withMentions({+ onCreate: options.onMentionCreate,+ onRemove: options.onMentionRemove,+ });+ }++ return editor+ .withEmojis()+ .withLinks({ floatingMenu: true })+ .withHistory({ timeGap: 400 })+ .withCode()+ .withRestoreFocus()+ .withSelectionData()+ .use(+ tablePlugin({+ hasCellMerge: true,+ hasCellBackgroundColor: false,+ hasTabHandler: true,+ hasHorizontalScroll: true,+ })+ )+ .use(tableCellResizerPlugin())+ .use(+ keyboardShortcutsPlugin({+ shortcuts: DefaultShortcuts,+ })+ )+ .onChange(options.onChange)+ .onEnter(options.onEnter);+}diff --git a/js/app/packages/channel/Input/context.ts b/js/app/packages/channel/Input/context.tsnew file mode 100644index 0000000000..1ee29abce0--- /dev/null+++ b/js/app/packages/channel/Input/context.ts@@ -0,0 +1,23 @@+import { createContext, useContext, type Accessor } from 'solid-js';+import type { InputCommands, InputData } from './types';++type InputContextValue = {+ view: Accessor<InputData>;+ commands: InputCommands;+};++const InputContext = createContext<InputContextValue>();+export const InputProvider = InputContext.Provider;++export function useInput(): Accessor<InputData> {+ const ctx = useContext(InputContext);+ if (!ctx) throw new Error('useInput must be used within <Input.Root>');+ return ctx.view;+}++export function useInputCommands(): InputCommands {+ const ctx = useContext(InputContext);+ if (!ctx)+ throw new Error('useInputCommands must be used within <Input.Root>');+ return ctx.commands;+}diff --git a/js/app/packages/channel/Input/create-input-commands.ts b/js/app/packages/channel/Input/create-input-commands.tsnew file mode 100644index 0000000000..8135b33580--- /dev/null+++ b/js/app/packages/channel/Input/create-input-commands.ts@@ -0,0 +1,68 @@+import type { Accessor } from 'solid-js';+import type {+ InputAttachmentData,+ InputCallbacks,+ InputCommands,+ InputData,+ InputDraftAdapter,+ InputSnapshot,+} from './types';++type CreateInputCommandsDeps = {+ view: Accessor<InputData>;+ snapshot: Accessor<InputSnapshot>;+ setIsSending: (value: boolean) => void;+ setShowFormatRibbon: (updater: (prev: boolean) => boolean) => void;+ reset: () => void;+ removeTrackedAttachment: (id: string) => void;+ attachFiles?: (files: File[]) => Promise<void> | void;+ callbacks?: InputCallbacks;+ draft?: InputDraftAdapter;+};++export function createInputCommands(+ deps: CreateInputCommandsDeps+): InputCommands {+ const removeAttachment = (attachment: InputAttachmentData) => {+ deps.removeTrackedAttachment(attachment.id);+ const current = deps.snapshot();+ void deps.callbacks?.onRemoveAttachment?.(attachment, current);+ void deps.draft?.save?.(current);+ };++ return {+ send: async () => {+ if (deps.view().hasPendingAttachments) return false;+ if (!deps.callbacks?.onSend) return false;++ const current = deps.snapshot();+ deps.setIsSending(true);+ try {+ await deps.callbacks.onSend(current);+ deps.reset();+ deps.draft?.clear?.();+ return true;+ } finally {+ deps.setIsSending(false);+ }+ },+ attachFiles: async (files: File[]) => {+ if (files.length === 0) return;+ await deps.attachFiles?.(files);+ },+ toggleFormatRibbon: () => {+ deps.setShowFormatRibbon((open) => {+ const next = !open;+ deps.callbacks?.onToggleFormatRibbon?.(next);+ return next;+ });+ },+ closeDraft: () => {+ const current = deps.snapshot();+ deps.reset();+ deps.callbacks?.onCloseDraft?.(current);+ deps.draft?.clear?.();+ },+ removeAttachment,+ };+}diff --git a/js/app/packages/channel/Input/create-input-state.ts b/js/app/packages/channel/Input/create-input-state.tsnew file mode 100644index 0000000000..6b1570a8dd--- /dev/null+++ b/js/app/packages/channel/Input/create-input-state.ts@@ -0,0 +1,62 @@+import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';+import type { Accessor } from 'solid-js';+import { createInputView } from './create-input-view';+import { createInputCommands } from './create-input-commands';+import type {+ InputAttachmentTracker,+ InputCallbacks,+ InputCommands,+ InputData,+ InputDraftAdapter,+ InputSnapshot,+} from './types';++type CreateInputStateOptions = {+ initialInput: InputData;+ mentions: Accessor<ItemMention[]>;+ attachmentTracker: InputAttachmentTracker;+ attachFiles?: (files: File[]) => Promise<void> | void;+ callbacks?: InputCallbacks;+ draft?: InputDraftAdapter;+};++export type InputState = {+ view: Accessor<InputData>;+ snapshot: Accessor<InputSnapshot>;+ commands: InputCommands;+ setValue: (value: string) => void;+ setIsDraggedOver: (value: boolean) => void;+ reset: () => void;+};++export function createInputState(options: CreateInputStateOptions): InputState {+ const view = createInputView({+ initialInput: options.initialInput,+ mentions: options.mentions,+ attachmentTracker: options.attachmentTracker,+ callbacks: options.callbacks,+ draft: options.draft,+ });++ const commands = createInputCommands({+ view: view.view,+ snapshot: view.snapshot,+ setIsSending: view.setIsSending,+ setShowFormatRibbon: view.setShowFormatRibbon,+ reset: view.reset,+ removeTrackedAttachment: (id) =>+ options.attachmentTracker.removeAttachment(id),+ attachFiles: options.attachFiles,+ callbacks: options.callbacks,+ draft: options.draft,+ });++ return {+ view: view.view,+ snapshot: view.snapshot,+ commands,+ setValue: view.setValue,+ setIsDraggedOver: view.setIsDraggedOver,+ reset: view.reset,+ };+}diff --git a/js/app/packages/channel/Input/create-input-view.ts b/js/app/packages/channel/Input/create-input-view.tsnew file mode 100644index 0000000000..10514700d9--- /dev/null+++ b/js/app/packages/channel/Input/create-input-view.ts@@ -0,0 +1,96 @@+import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';+import {+ createEffect,+ createMemo,+ createSignal,+ on,+ type Accessor,+} from 'solid-js';+import type {+ InputAttachmentTracker,+ InputCallbacks,+ InputData,+ InputDraftAdapter,+ InputSnapshot,+} from './types';++type CreateInputViewOptions = {+ initialInput: InputData;+ mentions: Accessor<ItemMention[]>;+ attachmentTracker: InputAttachmentTracker;+ callbacks?: InputCallbacks;+ draft?: InputDraftAdapter;+};++export type InputView = {+ view: Accessor<InputData>;+ snapshot: Accessor<InputSnapshot>;+ value: Accessor<string>;+ showFormatRibbon: Accessor<boolean>;+ isSending: Accessor<boolean>;+ setValue: (value: string) => void;+ setShowFormatRibbon: (updater: (prev: boolean) => boolean) => void;+ setIsSending: (value: boolean) => void;+ setIsDraggedOver: (value: boolean) => void;+ reset: () => void;+};++export function createInputView(options: CreateInputViewOptions): InputView {+ const [value, setValueSignal] = createSignal(+ options.initialInput.value ?? ''+ );+ const [showFormatRibbon, setShowFormatRibbon] = createSignal(+ !!options.initialInput.showFormatRibbon+ );+ const [isSending, setIsSending] = createSignal(false);+ const [isDraggedOver, setIsDraggedOver] = createSignal(false);++ const snapshot = createMemo<InputSnapshot>(() => ({+ value: value(),+ mentions: options.mentions(),+ attachments: options.attachmentTracker.attachments(),+ }));++ const view = createMemo<InputData>(() => ({+ ...options.initialInput,+ value: value(),+ isDraggedOver: isDraggedOver() || options.initialInput.isDraggedOver,+ showFormatRibbon: showFormatRibbon(),+ hasPendingAttachments:+ isSending() || options.attachmentTracker.hasPending(),+ attachments: options.attachmentTracker.attachments(),+ }));++ createEffect(+ on(+ snapshot,+ (current) => {+ void options.callbacks?.onChange?.(current);+ void options.draft?.save?.(current);+ },+ { defer: true }+ )+ );++ const setValue = (nextValue: string) => {+ setValueSignal(nextValue);+ };++ const reset = () => {+ setValueSignal('');+ options.attachmentTracker.clearAttachments();+ };++ return {+ view,+ snapshot,+ value,+ showFormatRibbon,+ isSending,+ setValue,+ setShowFormatRibbon,+ setIsSending,+ setIsDraggedOver,+ reset,+ };+}diff --git a/js/app/packages/channel/Input/index.ts b/js/app/packages/channel/Input/index.tsnew file mode 100644index 0000000000..2c49c39924--- /dev/null+++ b/js/app/packages/channel/Input/index.ts@@ -0,0 +1,38 @@+export { Input } from './Input';+export { ChannelInput } from './ChannelInput';+export { ThreadInput } from './ThreadInput';+export { createInputAttachmentTracker } from './attachment-tracker';+export { createInputState } from './create-input-state';+export { createConfiguredChannelMarkdownEditor } from './configured-markdown-editor';++export { Root } from './Root';+export { Layout } from './Layout';+export { DropOverlay } from './DropOverlay';+export { DropZone } from './DropZone';+export { FormatRibbon } from './FormatRibbon';+export { EditorShell } from './EditorShell';+export { Editor } from './Editor';+export { Attachments } from './Attachments';+export { Footer } from './Footer';+export { PrimaryActions } from './PrimaryActions';+export { SendAction } from './SendAction';+export { RibbonButton } from './RibbonButton';+export { FormatButtons } from './FormatButtons';+export { useInput, useInputCommands, InputProvider } from './context';++export { isReplyInput } from './types';++export type {+ InputData,+ ChannelInputMode,+ ReplyInputMode,+ InputAttachmentData,+ InputAttachmentKind,+ InputSnapshot,+ InputCallbacks,+ InputDraftAdapter,+ InputCommands,+ InputHandle,+ InputActionEvent,+ InputAttachmentTracker,+} from './types';diff --git a/js/app/packages/channel/Input/mentions-tracker.ts b/js/app/packages/channel/Input/mentions-tracker.tsnew file mode 100644index 0000000000..0a17cffd54--- /dev/null+++ b/js/app/packages/channel/Input/mentions-tracker.ts@@ -0,0 +1,33 @@+import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';+import { createSignal, type Accessor } from 'solid-js';++type MentionFn = (item: ItemMention) => void;+export type MentionsTracker = {+ onMentionCreate: MentionFn;+ onMentionRemove: MentionFn;+ mentions: Accessor<ItemMention[]>;+};++export function createMentionsTracker(): MentionsTracker {+ const [mentions, setMentions] = createSignal<ItemMention[]>([]);+ const onMentionRemove = (mention: ItemMention) => {+ setMentions((current) => {+ const index = current.findIndex(+ (item) =>+ item.itemType === mention.itemType && item.itemId === mention.itemId+ );+ if (index < 0) return current;+ return [...current.slice(0, index), ...current.slice(index + 1)];+ });+ };++ const onMentionCreate = (mention: ItemMention) => {+ setMentions((current) => [...current, mention]);+ };++ return {+ onMentionCreate,+ onMentionRemove,+ mentions,+ };+}diff --git a/js/app/packages/channel/Input/tests/attachment-tracker.test.ts b/js/app/packages/channel/Input/tests/attachment-tracker.test.tsnew file mode 100644index 0000000000..2656ba7ded--- /dev/null+++ b/js/app/packages/channel/Input/tests/attachment-tracker.test.ts@@ -0,0 +1,41 @@+/**+ * @vitest-environment jsdom+ */++import { createRoot } from 'solid-js';+import { describe, expect, it } from 'vitest';+import { createInputAttachmentTracker } from '../attachment-tracker';++describe('input attachment tracker', () => {+ it('deduplicates by id and tracks pending state', () => {+ createRoot((dispose) => {+ const tracker = createInputAttachmentTracker();++ tracker.addAttachment({ id: 'a1', kind: 'image', name: 'a.png' });+ tracker.addAttachment({ id: 'a1', kind: 'image', name: 'a.png' });+ expect(tracker.attachments()).toHaveLength(1);++ tracker.setAttachmentPending('a1', true);+ expect(tracker.hasPending()).toBe(true);++ tracker.setAttachmentPending('a1', false);+ expect(tracker.hasPending()).toBe(false);++ dispose();+ });+ });++ it('supports explicit add/remove operations', () => {+ createRoot((dispose) => {+ const tracker = createInputAttachmentTracker();++ tracker.addAttachment({ id: 'a1', kind: 'document', name: 'spec.md' });+ expect(tracker.attachments()).toHaveLength(1);++ tracker.removeAttachment('a1');++ expect(tracker.attachments()).toHaveLength(0);+ dispose();+ });+ });+});diff --git a/js/app/packages/channel/Input/tests/input-slots.test.tsx b/js/app/packages/channel/Input/tests/input-slots.test.tsxnew file mode 100644index 0000000000..f2b94689dc--- /dev/null+++ b/js/app/packages/channel/Input/tests/input-slots.test.tsx@@ -0,0 +1,172 @@+/**+ * @vitest-environment jsdom+ */++import userEvent from '@testing-library/user-event';+import { render, screen } from '@solidjs/testing-library';+import { beforeAll, describe, expect, it, vi } from 'vitest';++beforeAll(() => {+ Object.defineProperty(window, 'matchMedia', {+ writable: true,+ value: (query: string) => ({+ matches: false,+ media: query,+ onchange: null,+ addListener: () => {},+ removeListener: () => {},+ addEventListener: () => {},+ removeEventListener: () => {},+ dispatchEvent: () => true,+ }),+ });+});++vi.mock('@core/util/upload', () => ({+ chatRuleset: {},+ uploadFile: vi.fn(),+}));++vi.mock('@core/constant/allBlocks', () => ({+ fileTypeToBlockName: (type?: string | null) => type ?? 'unknown',+}));++vi.mock('../utils/render-icon', () => ({+ renderIcon: () => null,+}));++vi.mock('@core/component/EntityIcon', () => ({+ EntityIcon: () => <span data-testid="entity-icon" />,+}));++vi.mock('@core/component/ImagePreview', () => ({+ ImagePreview: (props: { image: { id: string } }) => (+ <div data-testid={`image-preview-${props.image.id}`} />+ ),+}));++vi.mock('@core/component/VideoPreview', () => ({+ VideoPreview: (props: { id: string }) => (+ <div data-testid={`video-preview-${props.id}`} />+ ),+}));++vi.mock('@core/component/LexicalMarkdown/builder/MarkdownShell', () => ({+ MarkdownShell: (props: { placeholder?: string }) => (+ <div data-testid="markdown-shell">{props.placeholder}</div>+ ),+}));++vi.mock(+ '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder',+ () => ({+ buildConfig: () => {+ const builder: any = {+ namespace: () => builder,+ withMentions: () => builder,+ withEmojis: () => builder,+ withLinks: () => builder,+ withHistory: () => builder,+ withCode: () => builder,+ withRestoreFocus: () => builder,+ withSelectionData: () => builder,+ use: () => builder,+ onChange: () => builder,+ onEnter: () => builder,+ controls: {+ clear: vi.fn(),+ focus: vi.fn(),+ },+ lexical: {+ focus: vi.fn(),+ dispatchCommand: vi.fn(),+ },+ selection: undefined,+ };+ return builder;+ },+ })+);++vi.mock('@core/component/LexicalMarkdown/plugins', () => ({+ DefaultShortcuts: {},+ NODE_TRANSFORM: 'NODE_TRANSFORM',+ keyboardShortcutsPlugin: () => () => () => {},+}));++vi.mock('@core/component/LexicalMarkdown/plugins/tables/tablePlugin', () => ({+ tablePlugin: () => () => () => {},+}));++vi.mock(+ '@core/component/LexicalMarkdown/plugins/tables/tableCellResizerPlugin',+ () => ({+ tableCellResizerPlugin: () => () => () => {},+ })+);++import { ChannelInput } from '../ChannelInput';+import { Root } from '../Root';+import { DropOverlay } from '../DropOverlay';+import type { InputData } from '../types';++const baseInput: InputData = {+ mode: 'channel',+ id: 'input-1',+ placeholder: 'Message channel',+ value: '',+ showFormatRibbon: false,+ hasPendingAttachments: false,+ attachments: [],+};++describe('Input slots', () => {+ it('wires send and primary action handlers through context', async () => {+ const user = userEvent.setup();+ const onSend = vi.fn();+ const onToggleFormatRibbon = vi.fn();+ const onCloseDraft = vi.fn();++ render(() =>+ (() => {+ return (+ <ChannelInput+ input={{ ...baseInput, mode: 'reply' }}+ onSend={onSend}+ onToggleFormatRibbon={onToggleFormatRibbon}+ onCloseDraft={onCloseDraft}+ />+ );+ })()+ );++ await user.click(screen.getByRole('button', { name: 'Send message' }));+ const clickSpy = vi.spyOn(HTMLInputElement.prototype, 'click');+ await user.click(screen.getByRole('button', { name: 'Attach files' }));+ await user.click(screen.getByRole('button', { name: 'Format' }));+ await user.click(screen.getByRole('button', { name: 'Delete reply' }));++ expect(onSend).toHaveBeenCalledOnce();+ expect(clickSpy).toHaveBeenCalledOnce();+ clickSpy.mockRestore();+ expect(onToggleFormatRibbon).toHaveBeenCalledOnce();+ expect(onCloseDraft).toHaveBeenCalledOnce();+ expect(onSend.mock.calls[0]?.[0]?.value).toBe('');+ });++ it('shows invalid state in drop overlay', () => {+ render(() => (+ <Root+ input={{+ ...baseInput,+ isDraggedOver: true,+ isValidChannelDrag: false,+ }}+ >+ <DropOverlay invalidMessage="[!] Invalid attachment file" />+ </Root>+ ));++ expect(screen.getByText('[!] Invalid attachment file')).toBeTruthy();+ });+});diff --git a/js/app/packages/channel/Input/tests/upload-attachments.test.ts b/js/app/packages/channel/Input/tests/upload-attachments.test.tsnew file mode 100644index 0000000000..444b148eef--- /dev/null+++ b/js/app/packages/channel/Input/tests/upload-attachments.test.ts@@ -0,0 +1,119 @@+/**+ * @vitest-environment jsdom+ */++import { beforeEach, describe, expect, it, vi } from 'vitest';++vi.mock('@core/constant/allBlocks', () => ({+ fileTypeToBlockName: (type?: string | null) => type ?? 'unknown',+}));++import { createInputAttachmentTracker } from '../attachment-tracker';+import { getAttachmentKindFromFile } from '../utils/file-helpers';+import { uploadInputAttachments } from '../upload-attachments';++const { toastFailureMock } = vi.hoisted(() => {+ return {+ toastFailureMock: vi.fn(),+ };+});++vi.mock('@core/component/Toast/Toast', () => ({+ toast: {+ failure: toastFailureMock,+ },+}));++describe('uploadInputAttachments', () => {+ beforeEach(() => {+ toastFailureMock.mockReset();+ });++ it('infers attachment kind from mime type and extension', () => {+ expect(+ getAttachmentKindFromFile({+ name: 'image.png',+ type: '',+ } as File)+ ).toBe('image');+ expect(+ getAttachmentKindFromFile({+ name: 'clip.mov',+ type: '',+ } as File)+ ).toBe('video');+ expect(+ getAttachmentKindFromFile({+ name: 'spec.md',+ type: '',+ } as File)+ ).toBe('document');+ });++ it('replaces pending attachment with uploaded attachment', async () => {+ const tracker = createInputAttachmentTracker();+ const file = new File(['abc'], 'image.png', { type: 'image/png' });++ await uploadInputAttachments({+ files: [file],+ tracker,+ uploadFile: async () => ({+ failed: false,+ destination: 'static',+ id: 'uploaded-image-1',+ }),+ });++ expect(tracker.attachments()).toEqual([+ {+ id: 'uploaded-image-1',+ name: 'image.png',+ kind: 'image',+ },+ ]);+ });++ it('removes pending attachment and shows toast on failed upload', async () => {+ const tracker = createInputAttachmentTracker();+ const file = new File(['abc'], 'spec.md', { type: 'text/markdown' });++ await uploadInputAttachments({+ files: [file],+ tracker,+ uploadFile: async () => ({+ failed: true,+ }),+ });++ expect(tracker.attachments()).toEqual([]);+ expect(toastFailureMock).toHaveBeenCalledWith('Failed to upload spec.md');+ });++ it('stores document icon type from upload result', async () => {+ const tracker = createInputAttachmentTracker();+ const file = new File(['abc'], 'manual.pdf', {+ type: 'application/pdf',+ });++ await uploadInputAttachments({+ files: [file],+ tracker,+ uploadFile: async () => ({+ failed: false,+ destination: 'dss',+ type: 'document',+ documentId: 'doc-1',+ fileType: 'pdf',+ }),+ });++ expect(tracker.attachments()).toEqual([+ {+ id: 'doc-1',+ name: 'manual',+ kind: 'document',+ iconType: 'pdf',+ },+ ]);+ });+});diff --git a/js/app/packages/channel/Input/types.ts b/js/app/packages/channel/Input/types.tsnew file mode 100644index 0000000000..2df80d6420--- /dev/null+++ b/js/app/packages/channel/Input/types.ts@@ -0,0 +1,72 @@+import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';+import type { EntityIconSelector } from '@core/component/EntityIcon';+import type { InputAttachmentTracker as Tracker } from './attachment-tracker';++export type InputAttachmentKind = 'video' | 'image' | 'document';++export type InputAttachmentData = {+ id: string;+ name: string;+ kind: InputAttachmentKind;+ iconType?: EntityIconSelector;+ pending?: boolean;+};++type InputDataBase = {+ id?: string;+ placeholder?: string;+ value?: string;+ isDraggedOver?: boolean;+ isDraggingOverChannel?: boolean;+ isValidChannelDrag?: boolean;+ showFormatRibbon?: boolean;+ hasPendingAttachments?: boolean;+ attachments?: InputAttachmentData[];+};++export type ChannelInputMode = InputDataBase & { mode: 'channel' };+export type ReplyInputMode = InputDataBase & { mode: 'reply' };+export type InputData = ChannelInputMode | ReplyInputMode;++export const isReplyInput = (input: InputData): input is ReplyInputMode =>+ input.mode === 'reply';++export type InputActionEvent = MouseEvent | KeyboardEvent;++export type InputSnapshot = {+ value: string;+ mentions: ItemMention[];+ attachments: InputAttachmentData[];+};++export type InputCallbacks = {+ onChange?: (snapshot: InputSnapshot) => void | Promise<void>;+ onSend?: (snapshot: InputSnapshot) => void | Promise<void>;+ onToggleFormatRibbon?: (open: boolean) => void | Promise<void>;+ onCloseDraft?: (snapshot: InputSnapshot) => void | Promise<void>;+ onRemoveAttachment?: (+ attachment: InputAttachmentData,+ snapshot: InputSnapshot+ ) => void | Promise<void>;+};++export type InputDraftAdapter = {+ save?: (snapshot: InputSnapshot) => void | Promise<void>;+ clear?: () => void | Promise<void>;+};++export type InputCommands = {+ send: () => Promise<boolean>;+ attachFiles: (files: File[]) => Promise<void>;+ toggleFormatRibbon: () => void;+ closeDraft: () => void;+ removeAttachment: (attachment: InputAttachmentData) => void;+};++export type InputHandle = {+ clear: () => void;+ focus: () => void;+ attachFiles: (files: File[]) => Promise<void>;+};++export type InputAttachmentTracker = Tracker;diff --git a/js/app/packages/channel/Input/upload-attachments.ts b/js/app/packages/channel/Input/upload-attachments.tsnew file mode 100644index 0000000000..e98389fd69--- /dev/null+++ b/js/app/packages/channel/Input/upload-attachments.ts@@ -0,0 +1,56 @@+import { toast } from '@core/component/Toast/Toast';+import {+ getAttachmentKindFromFile,+ iconTypeFromFilename,+ buildUploadedAttachment,+ type UploadResult,+} from './utils/file-helpers';+import type { InputAttachmentTracker } from './types';++export { getAttachmentKindFromFile } from './utils/file-helpers';++export async function uploadInputAttachments(options: {+ files: File[];+ tracker: InputAttachmentTracker;+ uploadFile: (file: File) => Promise<UploadResult>;+}): Promise<void> {+ for (const file of options.files) {+ const pendingId = crypto.randomUUID();+ const pendingKind = getAttachmentKindFromFile(file);++ options.tracker.addAttachment({+ id: pendingId,+ name: file.name,+ kind: pendingKind,+ iconType:+ pendingKind === 'document'+ ? iconTypeFromFilename(file.name)+ : undefined,+ pending: true,+ });++ try {+ const result = await options.uploadFile(file);++ if (result.failed) {+ options.tracker.removeAttachment(pendingId);+ toast.failure(`Failed to upload ${file.name}`);+ continue;+ }++ const uploaded = buildUploadedAttachment(file, pendingKind, result);+ if (!uploaded) {+ options.tracker.removeAttachment(pendingId);+ toast.failure(`Failed to upload ${file.name}`);+ continue;+ }++ options.tracker.removeAttachment(pendingId);+ options.tracker.addAttachment(uploaded);+ } catch (error) {+ console.error('failed to upload attachment', error);+ options.tracker.removeAttachment(pendingId);+ toast.failure(`Failed to upload ${file.name}`);+ }+ }+}diff --git a/js/app/packages/channel/Input/utils/file-helpers.ts b/js/app/packages/channel/Input/utils/file-helpers.tsnew file mode 100644index 0000000000..d59d33626f--- /dev/null+++ b/js/app/packages/channel/Input/utils/file-helpers.ts@@ -0,0 +1,97 @@+import { fileTypeToBlockName } from '@core/constant/allBlocks';+import { filenameWithoutExtension } from '@service-storage/util/filename';+import {+ CHANNEL_IMAGE_FILE_EXTENSIONS,+ CHANNEL_VIDEO_FILE_EXTENSIONS,+} from '../accepted-file-types';+import type { InputAttachmentData, InputAttachmentKind } from '../types';++export type UploadFailedResult = {+ failed: true;+};++export type UploadStaticSuccessResult = {+ failed: false;+ destination: 'static';+ id: string;+};++export type UploadDocumentSuccessResult = {+ failed: false;+ destination: 'dss';+ type: 'document';+ documentId: string;+ fileType?: string;+};++export type UploadResult =+ | UploadFailedResult+ | UploadStaticSuccessResult+ | UploadDocumentSuccessResult+ | {+ failed: false;+ destination: 'dss';+ type: string;+ };++export type UploadSuccess = Exclude<UploadResult, UploadFailedResult>;++const IMAGE_EXTENSIONS: ReadonlySet<string> = new Set(+ CHANNEL_IMAGE_FILE_EXTENSIONS+);+const VIDEO_EXTENSIONS: ReadonlySet<string> = new Set(+ CHANNEL_VIDEO_FILE_EXTENSIONS+);++export function fileExtension(filename: string): string | undefined {+ const extension = filename.split('.').pop()?.toLowerCase();+ if (!extension || extension === filename.toLowerCase()) return;+ return extension;+}++export function iconTypeFromFilename(filename: string) {+ return fileTypeToBlockName(fileExtension(filename), true);+}++export function getAttachmentKindFromFile(+ file: Pick<File, 'name' | 'type'>+): InputAttachmentKind {+ if (file.type.startsWith('image/')) return 'image';+ if (file.type.startsWith('video/')) return 'video';++ const extension = fileExtension(file.name);+ if (!extension) return 'document';++ if (IMAGE_EXTENSIONS.has(extension)) return 'image';+ if (VIDEO_EXTENSIONS.has(extension)) return 'video';+ return 'document';+}++export function buildUploadedAttachment(+ file: File,+ pendingKind: InputAttachmentKind,+ result: UploadSuccess+): InputAttachmentData | undefined {+ if (result.destination === 'static') {+ return {+ id: result.id,+ name: file.name,+ kind: pendingKind === 'video' ? 'video' : 'image',+ };+ }++ if (+ result.destination === 'dss' &&+ result.type === 'document' &&+ 'documentId' in result+ ) {+ return {+ id: result.documentId,+ name: filenameWithoutExtension(file.name) ?? file.name,+ kind: 'document',+ iconType: fileTypeToBlockName(result.fileType, true),+ };+ }++ return undefined;+}diff --git a/js/app/packages/channel/Input/utils/formatting.ts b/js/app/packages/channel/Input/utils/formatting.tsnew file mode 100644index 0000000000..22ceca75dc--- /dev/null+++ b/js/app/packages/channel/Input/utils/formatting.ts@@ -0,0 +1,33 @@+import {+ NODE_TRANSFORM,+ type NodeTransformType,+} from '@core/component/LexicalMarkdown/plugins';+import {+ FORMAT_TEXT_COMMAND,+ type LexicalEditor,+ type TextFormatType,+} from 'lexical';++export function applyInlineFormat(+ editor: LexicalEditor,+ format: TextFormatType+) {+ try {+ editor.focus();+ editor.dispatchCommand(FORMAT_TEXT_COMMAND, format);+ } catch {+ console.error('failed to apply formatting');+ }+}++export function applyNodeFormat(+ editor: LexicalEditor,+ format: NodeTransformType+) {+ try {+ editor.focus();+ editor.dispatchCommand(NODE_TRANSFORM, format);+ } catch {+ console.error('failed to apply formatting');+ }+}diff --git a/js/app/packages/channel/Input/utils/index.ts b/js/app/packages/channel/Input/utils/index.tsnew file mode 100644index 0000000000..23e58d3fe9--- /dev/null+++ b/js/app/packages/channel/Input/utils/index.ts@@ -0,0 +1,13 @@+export {+ fileExtension,+ iconTypeFromFilename,+ getAttachmentKindFromFile,+ buildUploadedAttachment,+ type UploadResult,+ type UploadSuccess,+ type UploadFailedResult,+ type UploadStaticSuccessResult,+ type UploadDocumentSuccessResult,+} from './file-helpers';+export { applyInlineFormat, applyNodeFormat } from './formatting';+export { renderIcon } from './render-icon';diff --git a/js/app/packages/channel/Input/utils/render-icon.tsx b/js/app/packages/channel/Input/utils/render-icon.tsxnew file mode 100644index 0000000000..52c086b151--- /dev/null+++ b/js/app/packages/channel/Input/utils/render-icon.tsx@@ -0,0 +1,14 @@+import { cn } from '@ui/utils/classname';+import type { Component, JSX } from 'solid-js';++export function renderIcon(+ icon: Component<JSX.SvgSVGAttributes<SVGSVGElement>> | string,+ className?: string+): JSX.Element {+ if (typeof icon === 'string') {+ return <img src={icon} alt="" class={cn('size-4', className)} />;+ }++ const Icon = icon;+ return <Icon class={cn('size-4', className)} />;+}diff --git a/js/app/packages/channel/Message/Root.tsx b/js/app/packages/channel/Message/Root.tsxindex e946c1a880..fc5a3922e2 100644--- a/js/app/packages/channel/Message/Root.tsx+++ b/js/app/packages/channel/Message/Root.tsx@@ -1,4 +1,4 @@-import { Show, splitProps, type JSX } from 'solid-js';+import { splitProps, type JSX } from 'solid-js';import { cn } from '@ui/utils/classname';import { MessageActionsProvider, MessageProvider } from './context';import type { MessageActions, MessageData } from './types';@@ -39,11 +39,9 @@ export function Root(props: RootProps) {)}/><MessageProvider value={() => local.message}>- <Show when={local.actions !== undefined} fallback={local.children}>- <MessageActionsProvider value={local.actions}>- {local.children}- </MessageActionsProvider>- </Show>+ <MessageActionsProvider value={local.actions}>+ {props.children}+ </MessageActionsProvider></MessageProvider></div>);diff --git a/js/app/packages/channel/Message/tests/action-menu.test.tsx b/js/app/packages/channel/Message/tests/action-menu.test.tsxdeleted file mode 100644index 557185137a..0000000000--- a/js/app/packages/channel/Message/tests/action-menu.test.tsx+++ /dev/null@@ -1,155 +0,0 @@-/**- * @vitest-environment jsdom- */--import userEvent from '@testing-library/user-event';-import { render, screen } from '@solidjs/testing-library';-import { describe, expect, it, vi } from 'vitest';-import { ActionMenu } from '../ActionMenu';-import { MessageActionsProvider } from '../context';-import { Root } from '../Root';-import type { MessageData } from '../types';--const message: MessageData = {- id: 'message-1',- content: 'hello',- sender_id: 'user-1',- created_at: '2026-02-25T00:00:00.000Z',- updated_at: '2026-02-25T00:00:00.000Z',- attachments: [],- reactions: [],-};--describe('ActionMenu', () => {- it('does not render when no actions are provided', () => {- render(() => (- <Root message={message}>- <ActionMenu />- </Root>- ));-- expect(screen.queryAllByRole('button')).toHaveLength(0);- });-- it('renders only actions that are provided', () => {- render(() => (- <Root- message={message}- actions={{- onReply: () => undefined,- onDelete: () => undefined,- }}- >- <ActionMenu />- </Root>- ));-- expect(screen.getByRole('button', { name: 'Reply' })).toBeTruthy();- expect(screen.getByRole('button', { name: 'Delete' })).toBeTruthy();- expect(screen.queryByRole('button', { name: 'Edit' })).toBeNull();- });-- it('uses actions from an outer provider when Root does not override', async () => {- const user = userEvent.setup();- const onEdit = vi.fn();-- render(() => (- <MessageActionsProvider- value={{- onEdit,- }}- >- <Root message={message}>- <ActionMenu />- </Root>- </MessageActionsProvider>- ));-- const editButton = screen.getByRole('button', { name: 'Edit' });- await user.click(editButton);- expect(onEdit).toHaveBeenCalledTimes(1);- });-- it('calls provided handlers with the current message', async () => {- const user = userEvent.setup();- const onReply = vi.fn();- const onCopyLink = vi.fn();-- render(() => (- <Root- message={message}- actions={{- onReply,- onCopyLink,- }}- >- <ActionMenu />- </Root>- ));-- const replyButton = screen.getByRole('button', { name: 'Reply' });- const copyLinkButton = screen.getByRole('button', { name: 'Copy Link' });-- await user.click(replyButton);- await user.click(copyLinkButton);-- expect(onReply).toHaveBeenCalledTimes(1);- expect(onCopyLink).toHaveBeenCalledTimes(1);- expect(onReply.mock.calls[0]?.[0]?.message?.id).toBe(message.id);- expect(onCopyLink.mock.calls[0]?.[0]?.message?.id).toBe(message.id);- });-- it('renders quick reactions and calls onReact with selected emoji', async () => {- const user = userEvent.setup();- const onReact = vi.fn();-- render(() => (- <Root- message={message}- actions={{- onReact,- }}- >- <ActionMenu />- </Root>- ));-- const quickButtons = screen.getAllByRole('button', { name: /^React /u });- expect(quickButtons).toHaveLength(3);- expect(screen.getByRole('button', { name: 'More reactions' })).toBeTruthy();-- const thumbsUp = screen.getByRole('button', { name: 'React 👍' });- await user.click(thumbsUp);-- expect(onReact).toHaveBeenCalledTimes(1);- expect(onReact.mock.calls[0]?.[0]?.message?.id).toBe(message.id);- expect(onReact.mock.calls[0]?.[0]?.emoji).toBe('👍');- });-- it('keeps hover actions visible while emoji menu is open', async () => {- const user = userEvent.setup();- const { container } = render(() => (- <Root- message={message}- actions={{- onReact: () => undefined,- }}- >- <ActionMenu />- </Root>- ));-- const hoverActions = container.querySelector(- '[data-message-hover-actions]'- ) as HTMLDivElement | null;- const emojiMenuTrigger = screen.getByRole('button', {- name: 'More reactions',- });-- expect(hoverActions).not.toBeNull();- expect(hoverActions?.className).toContain('opacity-0');-- await user.click(emojiMenuTrigger);- expect(hoverActions?.className).toContain('opacity-100');- });-});diff --git a/js/app/packages/channel/Message/tests/date-divider.test.tsx b/js/app/packages/channel/Message/tests/date-divider.test.tsxindex b9e192aa31..b78525e33d 100644--- a/js/app/packages/channel/Message/tests/date-divider.test.tsx+++ b/js/app/packages/channel/Message/tests/date-divider.test.tsx@@ -31,33 +31,28 @@ describe('DateDivider', () => {expect(screen.getByText('Today')).toBeTruthy();});- it('does not render for replies', () => {+ it('does not render when the message is a reply or there is no day boundary', () => {const { container } = render(() => (- <DateDivider- createdAt="2026-02-22T10:00:00.000Z"- isReply- listMeta={{- index: 0,- isNewMessage: false,- isFirstNewMessage: false,- }}- />- ));-- expect(container.textContent).toBe('');- });-- it('does not render when there is no day boundary', () => {- const { container } = render(() => (- <DateDivider- createdAt="2026-02-22T10:00:00.000Z"- listMeta={{- index: 1,- isNewMessage: false,- isFirstNewMessage: false,- previousTopLevelCreatedAt: '2026-02-22T09:00:00.000Z',- }}- />+ <>+ <DateDivider+ createdAt="2026-02-22T10:00:00.000Z"+ isReply+ listMeta={{+ index: 0,+ isNewMessage: false,+ isFirstNewMessage: false,+ }}+ />+ <DateDivider+ createdAt="2026-02-22T10:00:00.000Z"+ listMeta={{+ index: 1,+ isNewMessage: false,+ isFirstNewMessage: false,+ previousTopLevelCreatedAt: '2026-02-22T09:00:00.000Z',+ }}+ />+ </>));expect(container.textContent).toBe('');@@ -85,20 +80,4 @@ describe('NewDivider', () => {await user.click(button);expect(onDismiss).toHaveBeenCalledOnce();});-- it('does not render for replies', () => {- render(() => (- <NewDivider- isReply- listMeta={{- index: 2,- isNewMessage: true,- isFirstNewMessage: true,- previousTopLevelCreatedAt: '2026-02-21T09:00:00.000Z',- }}- />- ));-- expect(screen.queryByRole('button', { name: 'New' })).toBeNull();- });});diff --git a/js/app/packages/channel/Message/reactions.test.tsx b/js/app/packages/channel/Message/tests/reactions.test.tsxsimilarity index 64%rename from js/app/packages/channel/Message/reactions.test.tsxrename to js/app/packages/channel/Message/tests/reactions.test.tsxindex 4f5648bd68..d492f1bc5d 100644--- a/js/app/packages/channel/Message/reactions.test.tsx+++ b/js/app/packages/channel/Message/tests/reactions.test.tsx@@ -5,9 +5,9 @@import userEvent from '@testing-library/user-event';import { render, screen } from '@solidjs/testing-library';import { describe, expect, it, vi } from 'vitest';-import { Root } from './Root';-import { Reactions } from './Reactions';-import type { MessageData } from './types';+import { Root } from '../Root';+import { Reactions } from '../Reactions';+import type { MessageData } from '../types';vi.mock('@core/context/user', () => ({useUserId: () => () => 'user-1',@@ -43,32 +43,6 @@ describe('Reactions', () => {expect(screen.queryByRole('button', { name: 'Add reaction' })).toBeNull();});- it('renders styled reaction chips and add-reaction button when reactions exist', () => {- const { container } = render(() => (- <Root- message={{- ...baseMessage,- reactions: [{ emoji: '👍', users: ['user-1', 'user-3'] }],- }}- actions={{- onReact: () => undefined,- }}- >- <Reactions />- </Root>- ));-- const row = container.querySelector('[data-message-reactions-row]');- const chip = screen.getByRole('button', { name: /👍/u });- const addButton = screen.getByRole('button', { name: 'Add reaction' });-- expect(row).not.toBeNull();- expect(chip).not.toBeNull();- expect(chip.className).toContain('border-accent');- expect(chip.textContent).toContain('2');- expect(addButton).not.toBeNull();- });-it('calls onReact with chip emoji when a reaction chip is clicked', async () => {const user = userEvent.setup();const onReact = vi.fn();diff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsxindex 3d82d7e98c..cf58c0bf49 100644--- a/js/app/packages/channel/Thread/ChannelThread.tsx+++ b/js/app/packages/channel/Thread/ChannelThread.tsx@@ -1,15 +1,16 @@import { useThreadRepliesQuery } from '@queries/channel/thread-replies';-import { createSignal, Show, Suspense, type Accessor } from 'solid-js';+import { Show, Suspense, type Accessor } from 'solid-js';import { ChannelMessage } from '../Message';+import { useUserId } from '@core/context/user';+import { tryMacroId, useDisplayName } from '@core/user';import { Thread } from './Thread';-import { replyCenterOffsetX } from './thread-rail-geometry';import type { ThreadProps } from './types';import {DEFAULT_VISIBLE_REPLY_COUNT,getCollapsedRepliesCount,getThreadLatestReplyAt,getUniqueReplyUserIds,-} from './thread-reply-indicator-helpers';+} from './utils/thread-reply-indicator-helpers';function sliceIf<T>(val: Array<T>,@@ -21,8 +22,10 @@ function sliceIf<T>(}export function ChannelThread(props: ThreadProps) {- const [isReplying, setIsReplying] = createSignal(false);-+ const userId = useUserId();+ const replyUserId = () => userId() ?? props.data().sender_id;+ const macroId = () => tryMacroId(replyUserId());+ const [displayName] = useDisplayName(macroId());const thread = () => props.data().thread;const hasReplies = () => thread().reply_count > 0;const fetchRepliesEnabled = () => props.data().thread.reply_count > 0;@@ -52,9 +55,9 @@ export function ChannelThread(props: ThreadProps) {const collapsedLatestReplyAt = () =>getThreadLatestReplyAt(thread().latest_reply_at, activeReplies());const shouldShowCollapsedIndicator = () =>- !isReplying() && !props.isExpanded() && collapsedRepliesCount() > 0;+ !props.isReplying() && !props.isExpanded() && collapsedRepliesCount() > 0;const shouldShowReplyButton = () =>- hasReplies() && !isReplying() && !shouldShowCollapsedIndicator();+ hasReplies() && !props.isReplying() && !shouldShowCollapsedIndicator();const expand = () => {props.setIsExpanded(true);@@ -72,9 +75,9 @@ export function ChannelThread(props: ThreadProps) {message={props.data()}actions={props.getMessageActions?.(props.data())}/>- <Show when={hasReplies()}>+ <Show when={hasReplies() || props.isReplying()}><div class="relative w-full">- <Thread.RailDecorations isReplying={isReplying} />+ <Thread.RailDecorations isReplying={props.isReplying} /><Thread.RepliesContainer><Showwhen={@@ -97,17 +100,27 @@ export function ChannelThread(props: ThreadProps) {</Suspense></Show>+ <Show when={props.isReplying()}>+ <Show when={!hasReplies()}>+ <Thread.ReplyAuthor+ userId={replyUserId()}+ displayName={displayName()}+ />+ </Show>+ <Thread.ReplyInput+ messageId={props.data().id}+ replyInputState={props.replyInputState}+ setReplyInputState={props.setReplyInputState}+ setIsReplying={props.setIsReplying}+ />+ </Show>+<Showwhen={shouldShowCollapsedIndicator() || shouldShowReplyButton()}>- <div- class="relative z-10 w-fit"- style={{- 'margin-left': `calc(${replyCenterOffsetX} - var(--user-icon-width) / 2)`,- }}- >+ <Thread.ActionsFooter><Show when={shouldShowCollapsedIndicator()}><Thread.CollapsedIndicatorcollapsedRepliesCount={collapsedRepliesCount()}@@ -118,11 +131,11 @@ export function ChannelThread(props: ThreadProps) {</Show><Show when={shouldShowReplyButton()}><Thread.ReplyButton- onClick={() => setIsReplying(true)}+ onClick={() => props.setIsReplying(true)}aria-label="Reply"/></Show>- </div>+ </Thread.ActionsFooter></Show></Thread.RepliesContainer></div>diff --git a/js/app/packages/channel/Thread/Thread.ts b/js/app/packages/channel/Thread/Thread.tsindex b4f68be944..b8854e791a 100644--- a/js/app/packages/channel/Thread/Thread.ts+++ b/js/app/packages/channel/Thread/Thread.ts@@ -4,6 +4,10 @@ import { ThreadRepliesContainer } from './ThreadRepliesContainer';import { ThreadReplyButton } from './ThreadReplyButton';import { ThreadReplyList } from './ThreadReplyList';import { ThreadCollapsedIndicator } from './ThreadCollapsedIndicator';+import { ThreadReplyInputConnector } from './ThreadReplyInputConnector';+import { ThreadReplyAuthor } from './ThreadReplyAuthor';+import { ThreadReplyInput } from './ThreadReplyInput';+import { ThreadActionsFooter } from './ThreadActionsFooter';export const Thread = {Row: ThreadRow,@@ -12,4 +16,8 @@ export const Thread = {ReplyButton: ThreadReplyButton,ReplyList: ThreadReplyList,CollapsedIndicator: ThreadCollapsedIndicator,+ ReplyInputConnector: ThreadReplyInputConnector,+ ReplyAuthor: ThreadReplyAuthor,+ ReplyInput: ThreadReplyInput,+ ActionsFooter: ThreadActionsFooter,};diff --git a/js/app/packages/channel/Thread/ThreadActionsFooter.tsx b/js/app/packages/channel/Thread/ThreadActionsFooter.tsxnew file mode 100644index 0000000000..80f38462bd--- /dev/null+++ b/js/app/packages/channel/Thread/ThreadActionsFooter.tsx@@ -0,0 +1,19 @@+import type { JSX } from 'solid-js';+import { replyCenterOffsetX } from './utils/thread-rail-geometry';++type ThreadActionsFooterProps = {+ children: JSX.Element;+};++export function ThreadActionsFooter(props: ThreadActionsFooterProps) {+ return (+ <div+ class="relative z-10 w-fit"+ style={{+ 'margin-left': `calc(${replyCenterOffsetX} - var(--user-icon-width) / 2)`,+ }}+ >+ {props.children}+ </div>+ );+}diff --git a/js/app/packages/channel/Thread/ThreadCollapsedIndicator.tsx b/js/app/packages/channel/Thread/ThreadCollapsedIndicator.tsxindex e60266a31b..73a3c6fe9d 100644--- a/js/app/packages/channel/Thread/ThreadCollapsedIndicator.tsx+++ b/js/app/packages/channel/Thread/ThreadCollapsedIndicator.tsx@@ -11,7 +11,7 @@ import {splitProps,type JSX,} from 'solid-js';-import { getThreadReplyCountLabel } from './thread-reply-indicator-helpers';+import { getThreadReplyCountLabel } from './utils/thread-reply-indicator-helpers';type ThreadCollapsedIndicatorProps =JSX.ButtonHTMLAttributes<HTMLButtonElement> & {diff --git a/js/app/packages/channel/Thread/ThreadRailDecorations.tsx b/js/app/packages/channel/Thread/ThreadRailDecorations.tsxindex 700eede240..782b762eca 100644--- a/js/app/packages/channel/Thread/ThreadRailDecorations.tsx+++ b/js/app/packages/channel/Thread/ThreadRailDecorations.tsx@@ -4,7 +4,7 @@ import {innerRailTop,innerRailX,threadConnectorStyle,-} from './thread-rail-geometry';+} from './utils/thread-rail-geometry';type ThreadRailDecorationsProps = {isReplying: Accessor<boolean>;diff --git a/js/app/packages/channel/Thread/ThreadRepliesContainer.tsx b/js/app/packages/channel/Thread/ThreadRepliesContainer.tsxindex 87ed8ffde2..b1e54134f3 100644--- a/js/app/packages/channel/Thread/ThreadRepliesContainer.tsx+++ b/js/app/packages/channel/Thread/ThreadRepliesContainer.tsx@@ -1,5 +1,5 @@import type { ParentProps } from 'solid-js';-import { threadOffsetX } from './thread-rail-geometry';+import { threadOffsetX } from './utils/thread-rail-geometry';export function ThreadRepliesContainer(props: ParentProps) {return (diff --git a/js/app/packages/channel/Thread/ThreadReplyAuthor.tsx b/js/app/packages/channel/Thread/ThreadReplyAuthor.tsxnew file mode 100644index 0000000000..0b9b90f904--- /dev/null+++ b/js/app/packages/channel/Thread/ThreadReplyAuthor.tsx@@ -0,0 +1,19 @@+import { UserIcon } from '@core/component/UserIcon';++type ThreadReplyAuthorProps = {+ userId: string;+ displayName: string;+};++export function ThreadReplyAuthor(props: ThreadReplyAuthorProps) {+ return (+ <div class="flex items-start gap-2 p-2">+ <div class="flex-shrink-0 size-[var(--user-icon-width)]">+ <UserIcon id={props.userId} size="fill" />+ </div>+ <span class="text-sm font-semibold truncate mt-1">+ {props.displayName}+ </span>+ </div>+ );+}diff --git a/js/app/packages/channel/Thread/ThreadReplyInput.tsx b/js/app/packages/channel/Thread/ThreadReplyInput.tsxnew file mode 100644index 0000000000..04fe3c91fc--- /dev/null+++ b/js/app/packages/channel/Thread/ThreadReplyInput.tsx@@ -0,0 +1,59 @@+import type { Accessor, Setter } from 'solid-js';+import { ChannelInput, createInputAttachmentTracker } from '../Input';+import type { InputSnapshot } from '../Input';+import { createEntityDropZone } from '../Channel/create-entity-drop-zone';+import { replyInputOffsetX } from './utils/thread-rail-geometry';+import { ThreadReplyInputConnector } from './ThreadReplyInputConnector';++type ThreadReplyInputProps = {+ messageId: string;+ replyInputState: Accessor<InputSnapshot | undefined>;+ setReplyInputState: Setter<InputSnapshot | undefined>;+ setIsReplying: Setter<boolean>;+};++export function ThreadReplyInput(props: ThreadReplyInputProps) {+ const tracker = createInputAttachmentTracker({+ initialAttachments: props.replyInputState()?.attachments,+ });++ const entityDropZone = createEntityDropZone({+ droppableId: `thread-reply-entity-drop-${props.messageId}`,+ tracker,+ });++ return (+ <div class="relative" style={{ 'margin-left': replyInputOffsetX }}>+ <ThreadReplyInputConnector />+ {(() => {+ const droppable = entityDropZone.droppable;+ 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,+ isDraggingOverChannel: entityDropZone.isDraggingOver(),+ mode: 'reply',+ }}+ attachmentTracker={tracker}+ markdownNamespace={`thread-reply-input-${props.messageId}-markdown`}+ onChange={(snapshot) => void props.setReplyInputState(snapshot)}+ onCloseDraft={() => {+ props.setReplyInputState(undefined);+ props.setIsReplying(false);+ }}+ onSend={async () => {+ props.setReplyInputState(undefined);+ props.setIsReplying(false);+ }}+ />+ </div>+ );+ })()}+ </div>+ );+}diff --git a/js/app/packages/channel/Thread/ThreadReplyInputConnector.tsx b/js/app/packages/channel/Thread/ThreadReplyInputConnector.tsxnew file mode 100644index 0000000000..2c619d6ee0--- /dev/null+++ b/js/app/packages/channel/Thread/ThreadReplyInputConnector.tsx@@ -0,0 +1,45 @@+/**+ * Connector from the inner vertical rail to the reply input area.+ * Renders a short vertical rail segment + a curved diagonal connector,+ * matching the block-channel Message component's thread-append connector.+ *+ * Must be rendered inside a `position: relative` wrapper whose left edge+ * is at `icon-width/2` to the right of the inner rail.+ */+export function ThreadReplyInputConnector() {+ return (+ <>+ {/* Short vertical rail segment from wrapper top to connector start */}+ <div+ class="absolute border-l border-edge-muted/80"+ style={{+ left: 'calc((var(--user-icon-width) / 2) * -1)',+ height:+ 'calc(50% - (var(--user-icon-width) / 2 + 1px) / 24 * 18 + 1px)',+ }}+ />+ {/* Curved connector from rail to vertical center of the input area */}+ <div+ class="absolute text-edge-muted -z-1"+ style={{+ left: 'calc((var(--user-icon-width) / 2) * -1)',+ bottom: '50%',+ width: 'calc(var(--user-icon-width) / 2 + 1px)',+ }}+ >+ <svg+ xmlns="http://www.w3.org/2000/svg"+ fill="none"+ viewBox="0 0 24 18"+ width="100%"+ >+ <path+ stroke="currentColor"+ vector-effect="non-scaling-stroke"+ d="M23 17 4 6.0303C2.5 5.1643.5 4 .5.5"+ />+ </svg>+ </div>+ </>+ );+}diff --git a/js/app/packages/channel/Thread/tests/message-actions.test.ts b/js/app/packages/channel/Thread/tests/message-actions.test.tsindex 496ca47ef2..b15088e9af 100644--- a/js/app/packages/channel/Thread/tests/message-actions.test.ts+++ b/js/app/packages/channel/Thread/tests/message-actions.test.ts@@ -5,7 +5,7 @@ import {canReplyToMessage,DEFAULT_REACTION_EMOJI,hasReactionFromUser,-} from '../message-actions';+} from '../utils/message-actions';describe('message-actions helpers', () => {it('allows edit/delete only for own non-deleted messages', () => {diff --git a/js/app/packages/channel/Thread/tests/thread-rail-geometry.test.ts b/js/app/packages/channel/Thread/tests/thread-rail-geometry.test.tsdeleted file mode 100644index 851dbe0a44..0000000000--- a/js/app/packages/channel/Thread/tests/thread-rail-geometry.test.ts+++ /dev/null@@ -1,42 +0,0 @@-import { describe, expect, it } from 'vitest';-import {- getInnerRailBottom,- innerRailTop,- innerRailX,- replyCenterOffsetX,- threadConnectorStyle,- threadOffsetX,-} from '../thread-rail-geometry';--describe('thread-rail-geometry', () => {- it('exports stable offsets for thread layout alignment', () => {- expect(replyCenterOffsetX).toBe(- 'calc(var(--user-icon-width) / 2 + var(--body-padding))'- );- expect(threadOffsetX).toBe(- 'calc(var(--left-of-connector) + var(--thread-shift) - var(--user-icon-width) / 2 - var(--body-padding))'- );- expect(innerRailX).toBe(- 'calc(var(--left-of-connector) + var(--thread-shift))'- );- expect(innerRailTop).toBe(- 'calc(var(--body-padding) + var(--user-icon-width) / 2)'- );- });-- it('exposes connector style geometry', () => {- expect(threadConnectorStyle).toEqual({- left: 'calc(var(--left-of-connector) - 8px)',- top: 'calc(var(--body-padding) + var(--user-icon-width) / 2 - 20px)',- width: 'calc(var(--thread-shift) + 2px)',- height: '18px',- });- });-- it('extends inner rail to bottom while replying', () => {- expect(getInnerRailBottom(true)).toBe('0px');- expect(getInnerRailBottom(false)).toBe(- 'calc(var(--user-icon-width) / 2 + 0.5rem)'- );- });-});diff --git a/js/app/packages/channel/Thread/tests/thread-reply-indicator-helpers.test.ts b/js/app/packages/channel/Thread/tests/thread-reply-indicator-helpers.test.tsindex 826db923da..992935f3ec 100644--- a/js/app/packages/channel/Thread/tests/thread-reply-indicator-helpers.test.ts+++ b/js/app/packages/channel/Thread/tests/thread-reply-indicator-helpers.test.ts@@ -5,7 +5,7 @@ import {getThreadLatestReplyAt,getThreadReplyCountLabel,getUniqueReplyUserIds,-} from '../thread-reply-indicator-helpers';+} from '../utils/thread-reply-indicator-helpers';describe('thread-reply-indicator-helpers', () => {it('computes the number of collapsed replies', () => {diff --git a/js/app/packages/channel/Thread/types.ts b/js/app/packages/channel/Thread/types.tsindex cfbe3cb857..c5ebf51c48 100644--- a/js/app/packages/channel/Thread/types.ts+++ b/js/app/packages/channel/Thread/types.ts@@ -5,6 +5,7 @@ import type {MessageData,} from '../Message';import type { Accessor, Setter } from 'solid-js';+import type { InputSnapshot } from '@channel/Input';export type ThreadActions = {onDismissNewMessages?: () => void;@@ -13,6 +14,10 @@ export type ThreadActions = {export type ThreadState = {isExpanded: Accessor<boolean>;setIsExpanded: Setter<boolean>;+ isReplying: Accessor<boolean>;+ setIsReplying: Setter<boolean>;+ replyInputState: Accessor<InputSnapshot | undefined>;+ setReplyInputState: Setter<InputSnapshot | undefined>;};export type ThreadProps = {diff --git a/js/app/packages/channel/Thread/utils/index.ts b/js/app/packages/channel/Thread/utils/index.tsnew file mode 100644index 0000000000..2fc1762c2f--- /dev/null+++ b/js/app/packages/channel/Thread/utils/index.ts@@ -0,0 +1,27 @@+export {+ DEFAULT_VISIBLE_REPLY_COUNT,+ getCollapsedRepliesCount,+ getThreadReplyCountLabel,+ getUniqueReplyUserIds,+ getThreadLatestReplyAt,+} from './thread-reply-indicator-helpers';++export {+ threadOffsetX,+ replyInputOffsetX,+ replyCenterOffsetX,+ innerRailX,+ innerRailTop,+ getInnerRailBottom,+ threadConnectorStyle,+} from './thread-rail-geometry';++export {+ DEFAULT_REACTION_EMOJI,+ type ActionableMessage,+ isOwnMessage,+ canEditOrDeleteMessage,+ canReplyToMessage,+ hasReactionFromUser,+ buildMessageLink,+} from './message-actions';diff --git a/js/app/packages/channel/Thread/message-actions.ts b/js/app/packages/channel/Thread/utils/message-actions.tssimilarity index 96%rename from js/app/packages/channel/Thread/message-actions.tsrename to js/app/packages/channel/Thread/utils/message-actions.tsindex 55b816c1d9..67b4a5bbc5 100644--- a/js/app/packages/channel/Thread/message-actions.ts+++ b/js/app/packages/channel/Thread/utils/message-actions.ts@@ -1,4 +1,4 @@-import type { MessageData } from '../Message';+import type { MessageData } from '../../Message';export const DEFAULT_REACTION_EMOJI = '👍';diff --git a/js/app/packages/channel/Thread/thread-rail-geometry.ts b/js/app/packages/channel/Thread/utils/thread-rail-geometry.tssimilarity index 60%rename from js/app/packages/channel/Thread/thread-rail-geometry.tsrename to js/app/packages/channel/Thread/utils/thread-rail-geometry.tsindex 9712ad47e9..a76ddb3749 100644--- a/js/app/packages/channel/Thread/thread-rail-geometry.ts+++ b/js/app/packages/channel/Thread/utils/thread-rail-geometry.ts@@ -17,6 +17,13 @@ export const threadConnectorStyle = {height: '18px',} as const;+/** Left offset for the reply-input wrapper, placing it icon-width/2 right of the inner rail. */+export const replyInputOffsetX =+ 'calc(var(--user-icon-width) / 2 + var(--body-padding) + var(--user-icon-width) / 2)';+export function getInnerRailBottom(isReplying: boolean): string {- return isReplying ? '0px' : 'calc(var(--user-icon-width) / 2 + 0.5rem)';+ if (!isReplying) return 'calc(var(--user-icon-width) / 2 + 0.5rem)';+ // When replying, the rail stops above the reply-input connector+ // (roughly at 50% of the reply input area).+ return 'calc(var(--user-icon-width) * 2 + 1rem)';}diff --git a/js/app/packages/channel/Thread/thread-reply-indicator-helpers.ts b/js/app/packages/channel/Thread/utils/thread-reply-indicator-helpers.tssimilarity index 100%rename from js/app/packages/channel/Thread/thread-reply-indicator-helpers.tsrename to js/app/packages/channel/Thread/utils/thread-reply-indicator-helpers.tsdiff --git a/js/app/packages/core/component/VideoPreview.tsx b/js/app/packages/core/component/VideoPreview.tsxindex 791db5239e..fa24491c52 100644--- a/js/app/packages/core/component/VideoPreview.tsx+++ b/js/app/packages/core/component/VideoPreview.tsx@@ -7,16 +7,26 @@ export type VideoPreviewProps = {height?: string | number | undefined | null;};-const THEMES = {- small: 'min-h-[80px] size-15',+const CONTAINER_THEMES = {+ small:+ 'size-15 overflow-hidden rounded-2xl border border-edge-muted bg-menu select-none',dynamic: 'flex min-h-20 max-w-[480px] max-h-[480px] not-first:mt-2',};+const VIDEO_THEMES = {+ small: 'size-full object-cover',+ dynamic: '',+};+export function VideoPreview(props: VideoPreviewProps) {return (- <div class={THEMES[props.variant]}>+ <div class={CONTAINER_THEMES[props.variant]}><video- controls+ class={VIDEO_THEMES[props.variant]}+ controls={props.variant !== 'small'}+ preload="metadata"+ playsinline+ muted={props.variant === 'small'}src={staticFileIdEndpoint(props.id)}width={props.width ?? undefined}height={props.height ?? undefined}