Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix: input ui (#6490)

Peter Chinman1ac414b834eb
diff --git a/apps/web/src/components/ui/components/CollapsedInput.tsx b/apps/web/src/components/ui/components/CollapsedInput.tsx
index b37e3c1515..feed036405 100644
--- a/apps/web/src/components/ui/components/CollapsedInput.tsx
+++ b/apps/web/src/components/ui/components/CollapsedInput.tsx
@@ -1,7 +1,6 @@
import { focusInput } from '@core/directive/focusInput';
import { isMobile } from '@core/mobile/isMobile';
import PaperclipIcon from '@phosphor/paperclip.svg';
-import PlusIcon from '@phosphor/plus.svg';
import { type Accessor, type JSX, Show } from 'solid-js';
import { cn } from '../utils/classname';
import { Button } from './Button';
@@ -67,7 +66,7 @@ export function CollapsedInput(props: CollapsedInputProps) {
label="Attach files"
onClick={() => props.onAttach?.()}
>
- <PlusIcon />
+ <PaperclipIcon />
</Button>
<button
type="button"
diff --git a/apps/web/src/features/block-channel/component/Compose.tsx b/apps/web/src/features/block-channel/component/Compose.tsx
index 854efd3a4a..94da7a2b7e 100644
--- a/apps/web/src/features/block-channel/component/Compose.tsx
+++ b/apps/web/src/features/block-channel/component/Compose.tsx
@@ -20,7 +20,7 @@ import {
} from '@components/app/split-layout/components/SplitLabel';
import { SplitToolbarLeft } from '@components/app/split-layout/components/SplitToolbar';
import { ComposerEditor } from '@core/component/LexicalMarkdown/component/ComposerEditor';
-import { createHasLineBreaks } from '@core/component/LexicalMarkdown/utils/create-has-line-breaks';
+import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/create-composer-layout';
import { RecipientSelector } from '@core/component/RecipientSelector';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { useCombinedRecipients } from '@core/signal/useCombinedRecipient';
@@ -44,6 +44,7 @@ import { ComposerSurface } from '@ui';
import { createEffect, createMemo, createSignal, on, Show } from 'solid-js';
export function ChannelCompose() {
+ const [layout, setLayout] = createSignal<HTMLDivElement>();
const [channelName, setChannelName] = createSignal<string>('');
const { users: destinationOptions } = useCombinedRecipients();
@@ -197,8 +198,16 @@ export function ChannelCompose() {
},
});
clearComposer = () => markdownEditor.controls.clear();
- const hasLineBreaks = createHasLineBreaks(
- markdownEditor.buildHandle().lexical
+ const { isCompact: oneLineInput } = createComposerLayout(
+ markdownEditor.buildHandle().lexical,
+ {
+ container: layout,
+ mode: () =>
+ inputState.view().showFormatRibbon ||
+ inputState.view().attachments?.length
+ ? 'expanded'
+ : 'auto',
+ }
);
const placeholder = createMemo(() => {
@@ -280,13 +289,7 @@ export function ChannelCompose() {
onDragStart={(valid) => inputState.setIsDraggedOver(valid)}
onDragEnd={() => inputState.setIsDraggedOver(false)}
>
- <Input.Layout
- oneLineInput={
- !inputState.view().showFormatRibbon &&
- !inputState.view().attachments?.length &&
- !hasLineBreaks()
- }
- >
+ <Input.Layout ref={setLayout} oneLineInput={oneLineInput()}>
<Input.DropOverlay />
<Input.Layout.Body>
<Input.FormatRibbon>
diff --git a/apps/web/src/features/channel/Input/ActionButton.tsx b/apps/web/src/features/channel/Input/ActionButton.tsx
index a87518084d..f344f72a39 100644
--- a/apps/web/src/features/channel/Input/ActionButton.tsx
+++ b/apps/web/src/features/channel/Input/ActionButton.tsx
@@ -10,7 +10,6 @@ export function InputActionButton(props: {
}) {
return (
<Button
- title={props.label}
aria-label={props.label}
label={props.label}
variant={props.active ? 'accent' : 'ghost'}
diff --git a/apps/web/src/features/channel/Input/ChannelInput.tsx b/apps/web/src/features/channel/Input/ChannelInput.tsx
index 7024bdbaab..1f3d5b6b98 100644
--- a/apps/web/src/features/channel/Input/ChannelInput.tsx
+++ b/apps/web/src/features/channel/Input/ChannelInput.tsx
@@ -7,7 +7,7 @@ import {
INSERT_DOCUMENT_MENTION_COMMAND,
} from '@core/component/LexicalMarkdown/plugins';
import { singleLineMarkdownTheme } from '@core/component/LexicalMarkdown/theme';
-import { createHasLineBreaks } from '@core/component/LexicalMarkdown/utils/create-has-line-breaks';
+import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/create-composer-layout';
import {
clearDragInsertPreview,
insertDocumentMentionAtDragCoordinates,
@@ -143,6 +143,7 @@ function DefaultActions(props: { input: InputData }) {
}
export function ChannelInput(props: ChannelInputProps) {
+ const [layout, setLayout] = createSignal<HTMLDivElement>();
const [scrollContainer, setScrollContainer] = createSignal<HTMLElement>();
const mentionsTracker = createMentionsTracker();
const attachmentTracker =
@@ -344,7 +345,15 @@ export function ChannelInput(props: ChannelInputProps) {
});
const markdownHandle = markdownEditor.buildHandle();
const lexicalEditor = () => markdownHandle.lexical;
- const hasLineBreaks = createHasLineBreaks(lexicalEditor());
+ const { isCompact: oneLineInput } = createComposerLayout(lexicalEditor(), {
+ container: layout,
+ mode: () =>
+ isReplyInput(inputState.view()) ||
+ inputState.view().showFormatRibbon ||
+ inputState.view().attachments?.length
+ ? 'expanded'
+ : 'auto',
+ });
const [entityDragInsertStore, setEntityDragInsertStore] =
createDragInsertStore();
@@ -458,13 +467,7 @@ export function ChannelInput(props: ChannelInputProps) {
onDragStart={(valid) => inputState.setIsDraggedOver(valid)}
onDragEnd={() => inputState.setIsDraggedOver(false)}
>
- <Input.Layout
- oneLineInput={
- !inputState.view().showFormatRibbon &&
- !inputState.view().attachments?.length &&
- !hasLineBreaks()
- }
- >
+ <Input.Layout ref={setLayout} oneLineInput={oneLineInput()}>
<Input.DropOverlay />
<Input.Layout.Body>
<Input.FormatRibbon>
diff --git a/apps/web/src/features/channel/Input/FormatButtons.tsx b/apps/web/src/features/channel/Input/FormatButtons.tsx
index ca601df2ba..06cec30675 100644
--- a/apps/web/src/features/channel/Input/FormatButtons.tsx
+++ b/apps/web/src/features/channel/Input/FormatButtons.tsx
@@ -105,7 +105,6 @@ function FormatButton(props: FormatButtonProps) {
return (
<Button
aria-label={props.label}
- title={props.label}
label={props.label}
hotkey={props.hotkeyToken}
variant="ghost"
diff --git a/apps/web/src/features/channel/Input/InputActions.tsx b/apps/web/src/features/channel/Input/InputActions.tsx
index afaf090e0d..03c6247cba 100644
--- a/apps/web/src/features/channel/Input/InputActions.tsx
+++ b/apps/web/src/features/channel/Input/InputActions.tsx
@@ -1,5 +1,5 @@
import { pickNativePhotoLibraryMedia } from '@core/mobile/nativePhotoLibrary';
-import PlusIcon from '@phosphor/plus.svg';
+import PaperclipIcon from '@phosphor/paperclip.svg';
import FormatIcon from '@phosphor/text-aa.svg';
import TrashIcon from '@phosphor/trash.svg';
import type { JSX } from 'solid-js';
@@ -37,7 +37,7 @@ export function AttachFilesAction() {
label="Attach files"
onClick={() => fileInputRef?.click()}
>
- <PlusIcon />
+ <PaperclipIcon />
</InputActionButton>
</>
);
@@ -85,7 +85,7 @@ export function AttachNativeMediaAction() {
label="Attach photos or videos"
onClick={() => void onAttachMedia()}
>
- <PlusIcon />
+ <PaperclipIcon />
</InputActionButton>
</>
);
diff --git a/apps/web/src/features/channel/Input/Layout.module.css b/apps/web/src/features/channel/Input/Layout.module.css
new file mode 100644
index 0000000000..419dd76682
--- /dev/null
+++ b/apps/web/src/features/channel/Input/Layout.module.css
@@ -0,0 +1,64 @@
+@layer components {
+ .layout {
+ display: grid;
+ grid-template-columns: auto minmax(0, 1fr) auto;
+ width: 100%;
+
+ /* Shared with the hidden compact-layout measurement copy. */
+ &[data-composer-compact='true'] {
+ grid-template-areas: 'left body right';
+ align-items: flex-end;
+ gap: 3.75px;
+ min-height: 48.75px;
+ padding: 7.5px;
+ --input-editor-padding: 4.6875px 3.75px;
+ }
+
+ &[data-composer-compact='false'] {
+ grid-template-areas:
+ 'body body body'
+ 'left . right';
+ align-items: center;
+
+ :global(html:not([data-touch-device='true'])) & {
+ row-gap: 3.75px;
+ padding: 7.5px;
+ --input-editor-padding: 4.6875px 9.375px;
+ }
+
+ :global(html[data-touch-device='true']) & {
+ padding-bottom: calc(var(--spacing) * 2);
+ --input-editor-padding: 0.5rem 0.75rem;
+
+ @container (width >= 40rem) {
+ --input-editor-padding: 0.5rem 0.75rem 1rem;
+ }
+
+ > [data-input-actions-left],
+ > [data-input-actions-right] {
+ height: calc(var(--spacing) * 8);
+ }
+
+ > [data-input-actions-left] {
+ padding-left: calc(var(--spacing) * 2);
+ }
+
+ > [data-input-actions-right] {
+ padding-right: calc(var(--spacing) * 2);
+ }
+ }
+ }
+ }
+
+ .body {
+ grid-area: body;
+ }
+
+ .actionsLeft {
+ grid-area: left;
+ }
+
+ .actionsRight {
+ grid-area: right;
+ }
+}
diff --git a/apps/web/src/features/channel/Input/Layout.tsx b/apps/web/src/features/channel/Input/Layout.tsx
index 3394915829..9c64e88375 100644
--- a/apps/web/src/features/channel/Input/Layout.tsx
+++ b/apps/web/src/features/channel/Input/Layout.tsx
@@ -1,5 +1,6 @@
import { cn } from '@ui/utils/classname';
import { type JSX, splitProps } from 'solid-js';
+import styles from './Layout.module.css';
function LayoutRoot(
props: JSX.HTMLAttributes<HTMLDivElement> & { oneLineInput?: boolean }
@@ -14,19 +15,8 @@ function LayoutRoot(
<div
data-input-layout
data-one-line-input={local.oneLineInput ? '' : undefined}
- class={cn(
- 'grid grid-cols-[auto_minmax(0,1fr)_auto] w-full',
- local.oneLineInput
- ? "[grid-template-areas:'left_body_right'] items-end gap-[3.75px] min-h-[48.75px] p-[7.5px] [--input-editor-padding:4.6875px_3.75px]"
- : [
- "[grid-template-areas:'body_body_body'_'left_._right'] items-center",
- 'not-touch:gap-y-[3.75px] not-touch:p-[7.5px] not-touch:[--input-editor-padding:4.6875px_9.375px]',
- 'touch:pb-2 touch:[--input-editor-padding:0.5rem_0.75rem] touch:@[40rem]:[--input-editor-padding:0.5rem_0.75rem_1rem]',
- 'touch:[&>[data-input-actions-left]]:h-8 touch:[&>[data-input-actions-left]]:pl-2',
- 'touch:[&>[data-input-actions-right]]:h-8 touch:[&>[data-input-actions-right]]:pr-2',
- ],
- local.class
- )}
+ data-composer-compact={local.oneLineInput ? 'true' : 'false'}
+ class={cn(styles.layout, local.class)}
{...rest}
>
{local.children}
@@ -41,7 +31,7 @@ function Body(props: JSX.HTMLAttributes<HTMLDivElement>) {
<div
{...rest}
data-input-body
- class={cn('[grid-area:body] flex flex-col min-w-0', local.class)}
+ class={cn(styles.body, 'flex flex-col min-w-0', local.class)}
/>
);
}
@@ -70,7 +60,8 @@ function ActionsLeft(props: JSX.HTMLAttributes<HTMLDivElement>) {
{...rest}
data-input-actions-left
class={cn(
- '[grid-area:left] flex items-center not-touch:gap-[3.75px] touch:gap-2',
+ styles.actionsLeft,
+ 'flex items-center not-touch:gap-[3.75px] touch:gap-2',
local.class
)}
/>
@@ -85,7 +76,8 @@ function ActionsRight(props: JSX.HTMLAttributes<HTMLDivElement>) {
{...rest}
data-input-actions-right
class={cn(
- '[grid-area:right] flex items-center not-touch:gap-[3.75px] touch:gap-2',
+ styles.actionsRight,
+ 'flex items-center not-touch:gap-[3.75px] touch:gap-2',
local.class
)}
/>
diff --git a/apps/web/src/features/channel/Input/tests/input-slots.test.tsx b/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
index 11dfeecf13..c8bd531ef3 100644
--- a/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
+++ b/apps/web/src/features/channel/Input/tests/input-slots.test.tsx
@@ -31,8 +31,14 @@ vi.hoisted(() => {
});
});
-vi.mock('@core/component/LexicalMarkdown/utils/create-has-line-breaks', () => ({
- createHasLineBreaks: () => () => false,
+vi.mock('@core/component/LexicalMarkdown/utils/create-composer-layout', () => ({
+ createComposerLayout: (
+ _editor: unknown,
+ options: { mode?: () => 'auto' | 'expanded' | 'collapsed' }
+ ) => ({
+ isCompact: () => options.mode?.() !== 'expanded',
+ hasMultilineContent: () => false,
+ }),
}));
vi.mock('@core/util/upload', () => ({
diff --git a/apps/web/src/lib/core/comments/discussion/DiscussionInput.test.tsx b/apps/web/src/lib/core/comments/discussion/DiscussionInput.test.tsx
index 04adc902c1..263e31247a 100644
--- a/apps/web/src/lib/core/comments/discussion/DiscussionInput.test.tsx
+++ b/apps/web/src/lib/core/comments/discussion/DiscussionInput.test.tsx
@@ -23,8 +23,14 @@ vi.mock('@core/mobile/nativePhotoLibrary', () => ({
vi.mock('@core/util/platform', () => ({
isPlatform: (platform: string) => platform === 'ios' && editor.isIOS,
}));
-vi.mock('@core/component/LexicalMarkdown/utils/create-has-line-breaks', () => ({
- createHasLineBreaks: () => () => false,
+vi.mock('@core/component/LexicalMarkdown/utils/create-composer-layout', () => ({
+ createComposerLayout: (
+ _editor: unknown,
+ options: { mode?: () => 'auto' | 'expanded' | 'collapsed' }
+ ) => ({
+ isCompact: () => options.mode?.() !== 'expanded',
+ hasMultilineContent: () => false,
+ }),
}));
vi.mock('@channel/Input/ActionButton', () => ({}));
vi.mock('@channel/Input/context', () => ({}));
diff --git a/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx b/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx
index fbc9fb22cb..27e6fc06c7 100644
--- a/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx
+++ b/apps/web/src/lib/core/comments/discussion/DiscussionInput.tsx
@@ -19,7 +19,7 @@ import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/S
import type { ItemMention } from '@core/component/LexicalMarkdown/plugins';
import { addMediaFromFile } from '@core/component/LexicalMarkdown/plugins/media';
import { singleLineMarkdownTheme } from '@core/component/LexicalMarkdown/theme';
-import { createHasLineBreaks } from '@core/component/LexicalMarkdown/utils/create-has-line-breaks';
+import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/create-composer-layout';
import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import type { IUser } from '@core/user/types';
@@ -105,6 +105,7 @@ function DefaultActions(props: { input: InputData; isSending: boolean }) {
}
export function DiscussionInput(props: DiscussionInputProps) {
+ const [layout, setLayout] = createSignal<HTMLDivElement>();
const [scrollContainer, setScrollContainer] = createSignal<HTMLElement>();
const [value, setValue] = createSignal(props.input.value ?? '');
const [mentions, setMentions] = createSignal<ItemMention[]>([]);
@@ -156,7 +157,13 @@ export function DiscussionInput(props: DiscussionInputProps) {
// Build the editor handle immediately to ensure lexical is available for commands
markdownEditor.buildHandle();
- const hasLineBreaks = createHasLineBreaks(markdownEditor.lexical);
+ const { isCompact: oneLineInput } = createComposerLayout(
+ markdownEditor.lexical,
+ {
+ container: layout,
+ mode: () => (isTouchDevice() || showFormatRibbon() ? 'expanded' : 'auto'),
+ }
+ );
const commands = {
send: async () => {
@@ -285,11 +292,7 @@ export function DiscussionInput(props: DiscussionInputProps) {
collapsedInput.collapse();
}}
>
- <Input.Layout
- oneLineInput={
- !isTouchDevice() && !showFormatRibbon() && !hasLineBreaks()
- }
- >
+ <Input.Layout ref={setLayout} oneLineInput={oneLineInput()}>
<Input.Layout.Body>
<Input.FormatRibbon>
<FormatButtons
diff --git a/apps/web/src/lib/core/component/AI/component/input/ChatInput.model.test.tsx b/apps/web/src/lib/core/component/AI/component/input/ChatInput.model.test.tsx
index b1e9dbe701..c21e75e440 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ChatInput.model.test.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ChatInput.model.test.tsx
@@ -108,8 +108,14 @@ vi.mock('@service-cognition/client', () => ({
vi.mock('@app/lib/analytics/analytics-context', () => ({
useAnalytics: () => ({ track: vi.fn() }),
}));
-vi.mock('@core/component/LexicalMarkdown/utils/create-has-line-breaks', () => ({
- createHasLineBreaks: () => () => false,
+vi.mock('@core/component/LexicalMarkdown/utils/create-composer-layout', () => ({
+ createComposerLayout: (
+ _editor: unknown,
+ options: { mode?: () => 'auto' | 'expanded' | 'collapsed' }
+ ) => ({
+ isCompact: () => options.mode?.() !== 'expanded',
+ hasMultilineContent: () => false,
+ }),
}));
vi.mock('@core/auth/license', () => ({ useHasPaidAccess: () => () => true }));
vi.mock('@core/component/AI/signal/attachment', () => ({
diff --git a/apps/web/src/lib/core/component/AI/component/input/ChatInput.test.tsx b/apps/web/src/lib/core/component/AI/component/input/ChatInput.test.tsx
index 5d61528f72..ab7a477966 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ChatInput.test.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ChatInput.test.tsx
@@ -16,8 +16,14 @@ const mocks = vi.hoisted(() => ({
vi.mock('@app/lib/analytics/analytics-context', () => ({
useAnalytics: () => ({ track: vi.fn() }),
}));
-vi.mock('@core/component/LexicalMarkdown/utils/create-has-line-breaks', () => ({
- createHasLineBreaks: () => () => true,
+vi.mock('@core/component/LexicalMarkdown/utils/create-composer-layout', () => ({
+ createComposerLayout: (
+ _editor: unknown,
+ options: { mode?: () => 'auto' | 'expanded' | 'collapsed' }
+ ) => ({
+ isCompact: () => options.mode?.() === 'collapsed',
+ hasMultilineContent: () => true,
+ }),
}));
vi.mock('@core/auth/license', () => ({ useHasPaidAccess: () => () => false }));
vi.mock('@core/component/AI/constant', () => ({
diff --git a/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx b/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
index aae6d3658c..de0871b697 100644
--- a/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
+++ b/apps/web/src/lib/core/component/AI/component/input/ChatInput.tsx
@@ -14,7 +14,7 @@ import { isImageAttachment } from '@core/component/AI/util/attachment';
import { insertChatAttachmentMention } from '@core/component/AI/util/chatAttachmentMention';
import type { EditorConfigBuilder } from '@core/component/LexicalMarkdown/builder/MarkdownConfigBuilder';
import { ComposerEditor } from '@core/component/LexicalMarkdown/component/ComposerEditor';
-import { createHasLineBreaks } from '@core/component/LexicalMarkdown/utils/create-has-line-breaks';
+import { createComposerLayout } from '@core/component/LexicalMarkdown/utils/create-composer-layout';
import { toast } from '@core/component/Toast/Toast';
import { fileTypeToBlockName } from '@core/constant/allBlocks';
import { PaywallKey, usePaywallState } from '@core/constant/PaywallState';
@@ -26,7 +26,6 @@ import { useTouchOutsideToDismissKeyboard } from '@core/mobile/useTouchOutsideTo
import { getItemBlockName } from '@core/util/getItemBlockName';
import { handleFileFolderDrop } from '@core/util/upload';
import PaperclipIcon from '@phosphor/paperclip.svg';
-import PlusIcon from '@phosphor/plus.svg';
import { createElementSize } from '@solid-primitives/resize-observer';
import { createCallback } from '@solid-primitives/rootless';
import { Button, ComposerSurface, cn, SendButton as UiSendButton } from '@ui';
@@ -170,17 +169,19 @@ export function ChatInput(props: ChatInputComponentProps) {
!generating() &&
!hasUploadingAttachments();
- const LINE_HEIGHT_THRESHOLD = 40;
let mdRef: undefined | HTMLDivElement;
- const isMultiline = () => {
- if (isCollapsed()) return false;
- // Access markdownText to create reactive dependency
- const text = markdownText();
- if (hasLineBreaks()) return true;
- if (text.trim().length === 0) return false;
- if (!mdRef) return false;
- return mdRef.scrollHeight > LINE_HEIGHT_THRESHOLD;
- };
+
+ const isTallVariant = createMemo(
+ () =>
+ props.variant === 'tall' ||
+ (isTouchDevice() && props.variant !== 'default')
+ );
+ const isCollapsed = () =>
+ props.collapseOnBlur &&
+ isTouchDevice() &&
+ !isTallVariant() &&
+ !isFocused() &&
+ !isEmptyInput();
const sendMessage = createCallback(
async (opts?: { modelOverride?: Model; metaKey?: boolean }) => {
@@ -228,7 +229,18 @@ export function ChatInput(props: ChatInputComponentProps) {
props.onChange?.(md);
});
- const hasLineBreaks = createHasLineBreaks(props.editor.buildHandle().lexical);
+ const composerLayout = createComposerLayout(
+ props.editor.buildHandle().lexical,
+ {
+ container: lineEl,
+ mode: () => {
+ if (isTallVariant()) return 'expanded';
+ return isCollapsed() ? 'collapsed' : 'auto';
+ },
+ }
+ );
+ const isMultiline = () =>
+ !isCollapsed() && composerLayout.hasMultilineContent();
const hasAttachments = () =>
attachments.attached().some(isImageAttachment) ||
@@ -247,9 +259,7 @@ export function ChatInput(props: ChatInputComponentProps) {
else fileInputRef?.click();
}}
>
- <Show when={isTouchDevice()} fallback={<PaperclipIcon />}>
- <PlusIcon />
- </Show>
+ <PaperclipIcon />
</Button>
);
@@ -317,19 +327,7 @@ export function ChatInput(props: ChatInputComponentProps) {
</Show>
);
- const isTallVariant = createMemo(
- () =>
- props.variant === 'tall' ||
- (isTouchDevice() && props.variant !== 'default')
- );
- const isCollapsed = () =>
- props.collapseOnBlur &&
- isTouchDevice() &&
- !isTallVariant() &&
- !isFocused() &&
- !isEmptyInput();
- const isCompactMobile = () =>
- isTouchDevice() && !isTallVariant() && !isMultiline();
+ const isCompactMobile = () => isTouchDevice() && composerLayout.isCompact();
return (
<div class="relative">
@@ -357,9 +355,8 @@ export function ChatInput(props: ChatInputComponentProps) {
<ComposerSurface
class={cn(
'h-auto',
- !isMultiline() &&
+ composerLayout.isCompact() &&
!hasAttachments() &&
- !isTallVariant() &&
'touch:rounded-full',
props.class
)}
@@ -403,9 +400,13 @@ export function ChatInput(props: ChatInputComponentProps) {
<div
data-chat-input-layout=""
+ data-composer-compact={
+ composerLayout.isCompact() ? 'true' : 'false'
+ }
ref={setLineEl}
class={cn(
- 'relative px-[7.5px] touch:px-2 touch:min-h-12.5 touch:py-[9px]',
+ 'group/composer relative px-[7.5px] touch:px-2 touch:min-h-12.5 touch:py-[9px]',
+ 'data-[composer-compact=true]:px-[7.5px] data-[composer-compact=true]:touch:px-2',
{
'flex flex-col pt-[11.25px] pb-[7.5px] touch:p-0':
isTallVariant(),
@@ -443,11 +444,11 @@ export function ChatInput(props: ChatInputComponentProps) {
id={CHAT_INPUT_TEXT_AREA_ID}
class={cn(
'text-base text-ink touch:px-3 touch:py-2 not-touch:leading-[24.375px] not-touch:text-composer-ink',
- isCompactMobile() && 'w-full touch:py-0',
- (isMultiline() || isTallVariant()) && 'not-touch:px-[9.375px]'
+ 'group-data-[composer-compact=true]/composer:touch:w-full group-data-[composer-compact=true]/composer:touch:py-0',
+ 'group-data-[composer-compact=false]/composer:not-touch:px-[9.375px]',
+ 'group-data-[composer-compact=true]/composer:pl-[41.25px] group-data-[composer-compact=true]/composer:touch:pl-10 group-data-[composer-compact=true]/composer:pr-(--composer-right-inset)'
)}
classList={{
- 'pl-[41.25px] touch:pl-10': !isMultiline() && !isTallVariant(),
'pb-[37.5px] touch:pb-10': isMultiline() && !isTallVariant(),
'max-h-[calc(32*var(--dvh,1dvh))] overflow-y-auto':
isMobile() && isMultiline(),
@@ -461,11 +462,7 @@ export function ChatInput(props: ChatInputComponentProps) {
'max-h-5 overflow-hidden [&_[contenteditable]>:first-child]:mt-0!':
isCollapsed(),
}}
- style={
- !isMultiline() && !isTallVariant()
- ? { 'padding-right': `${rightControlsInset()}px` }
- : undefined
- }
+ style={{ '--composer-right-inset': `${rightControlsInset()}px` }}
ref={mdRef}
>
<ComposerEditor
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-composer-layout.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-composer-layout.test.ts
new file mode 100644
index 0000000000..9a000689c6
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-composer-layout.test.ts
@@ -0,0 +1,273 @@
+/** @vitest-environment jsdom */
+
+import { $createQuoteNode, QuoteNode } from '@lexical/rich-text';
+import {
+ $createParagraphNode,
+ $createTextNode,
+ $getRoot,
+ createEditor,
+} from 'lexical';
+import { createEffect, createRoot, createSignal } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import {
+ type ComposerLayoutMode,
+ createComposerLayout,
+} from './create-composer-layout';
+
+const resize = vi.hoisted(() => ({ notify: () => {} }));
+vi.mock('@solid-primitives/resize-observer', () => ({
+ createResizeObserver: (_targets: unknown, callback: () => void) => {
+ resize.notify = callback;
+ },
+}));
+
+const cleanups: Array<() => void> = [];
+
+beforeEach(() => {
+ const original = Object.getOwnPropertyDescriptor(
+ Range.prototype,
+ 'getBoundingClientRect'
+ );
+ cleanups.push(() => {
+ if (original) {
+ Object.defineProperty(Range.prototype, 'getBoundingClientRect', original);
+ } else {
+ Reflect.deleteProperty(Range.prototype, 'getBoundingClientRect');
+ }
+ });
+ // jsdom has no layout engine. Model text at 10px per character / 20px per
+ // line so these tests exercise width changes and observer timing.
+ Object.defineProperty(Range.prototype, 'getBoundingClientRect', {
+ configurable: true,
+ value: vi.fn(function (this: Range) {
+ const probe = this.commonAncestorContainer as HTMLElement;
+ const width = probe.getBoundingClientRect().width;
+ const lines = Math.max(
+ 1,
+ Math.ceil(((probe.textContent?.length ?? 0) * 10) / width)
+ );
+ return new DOMRect(0, 0, width, lines * 20);
+ }),
+ });
+});
+
+afterEach(() => {
+ for (const cleanup of cleanups.splice(0)) cleanup();
+ vi.restoreAllMocks();
+});
+
+function setup(initialText = '', initialQuote = false) {
+ const container = document.createElement('div');
+ const element = document.createElement('div');
+ element.style.lineHeight = '20px';
+ container.append(element);
+ document.body.append(container);
+ cleanups.push(() => container.remove());
+ const editor = createEditor({ nodes: [QuoteNode] });
+ const setText = (text: string, quote = false) =>
+ editor.update(
+ () => {
+ $getRoot()
+ .clear()
+ .append(
+ (quote ? $createQuoteNode() : $createParagraphNode()).append(
+ $createTextNode(text)
+ )
+ );
+ },
+ { discrete: true }
+ );
+ setText(initialText, initialQuote);
+ let containerWidth = 400;
+ let controlsWidth = 80;
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation(
+ function (this: HTMLElement) {
+ if (this.hasAttribute('data-composer-compact'))
+ return new DOMRect(0, 0, containerWidth, 60);
+ const compact =
+ this.closest('[data-composer-compact]')?.getAttribute(
+ 'data-composer-compact'
+ ) === 'true';
+ return new DOMRect(
+ 0,
+ 0,
+ containerWidth - (compact ? controlsWidth : 0),
+ 20
+ );
+ }
+ );
+ return createRoot((dispose) => {
+ cleanups.push(dispose);
+ const [mode, setMode] = createSignal<ComposerLayoutMode>('auto');
+ const layout = createComposerLayout(editor, {
+ container: () => container,
+ mode,
+ });
+ const compactStates: boolean[] = [];
+ createEffect(() => {
+ compactStates.push(layout.isCompact());
+ container.setAttribute(
+ 'data-composer-compact',
+ String(layout.isCompact())
+ );
+ });
+ editor.setRootElement(element);
+ cleanups.push(() => editor.setRootElement(null));
+ return {
+ ...layout,
+ setText,
+ setMode,
+ compactStates,
+ element,
+ container,
+ dispose,
+ setControlsWidth: (width: number) => {
+ controlsWidth = width;
+ // A control change need not resize an already-expanded container.
+ container.append(document.createElement('button'));
+ },
+ resize: (width: number) => {
+ containerWidth = width;
+ resize.notify();
+ },
+ };
+ });
+}
+
+async function flushMeasurements() {
+ // Includes the second measurement after the layout reacts to wrapping.
+ await Promise.resolve();
+ await Promise.resolve();
+ await Promise.resolve();
+}
+
+describe('composer layout', () => {
+ it('expands for wrapped text without newlines and stays expanded at the wider layout', async () => {
+ const input = setup();
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+
+ input.setText('a'.repeat(33));
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ expect(input.element.getBoundingClientRect().width).toBe(400);
+ resize.notify();
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+
+ input.setText('short draft');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+ expect(document.querySelectorAll('[data-lexical-editor]')).toHaveLength(1);
+ });
+
+ it('rechecks the same draft when its container narrows or widens', async () => {
+ const input = setup('a'.repeat(30));
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+ input.resize(300);
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ input.resize(500);
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+ });
+
+ it('measures restored content when the editor connects', async () => {
+ const input = setup('a'.repeat(50));
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ input.setText('');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+ });
+
+ it('cancels pending work when disposed', async () => {
+ const input = setup('a'.repeat(40));
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+
+ input.resize(1000);
+ input.dispose();
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ expect(document.querySelectorAll('[data-lexical-editor]')).toHaveLength(1);
+ });
+
+ it('expands when a short paragraph becomes a blockquote and compacts when converted back', async () => {
+ const input = setup('short draft');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+
+ input.setText('short draft', true);
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ expect(input.hasMultilineContent()).toBe(true);
+
+ input.setText('short draft');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+ });
+
+ it('keeps forced expansion separate from whether the content needs multiple lines', async () => {
+ const input = setup('short draft');
+ input.setMode('expanded');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ expect(input.hasMultilineContent()).toBe(false);
+
+ input.setText('another short draft');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+
+ input.setMode('auto');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+ });
+
+ it('never collapses a wrapping paragraph converted from a draft that mounted expanded', async () => {
+ const input = setup('a'.repeat(33), true);
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+
+ input.setText('a'.repeat(33));
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ expect(input.compactStates).not.toContain(true);
+ });
+
+ it('remeasures controls changed while expanded without visiting compact mode', async () => {
+ const input = setup('a'.repeat(30), true);
+ await flushMeasurements();
+ input.setControlsWidth(120);
+ await flushMeasurements();
+
+ input.setText('a'.repeat(30));
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ expect(input.compactStates).not.toContain(true);
+ });
+
+ it('tracks draft changes while collapsed and expands when auto mode resumes', async () => {
+ const input = setup();
+ input.setMode('collapsed');
+ input.setText('a'.repeat(50));
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+ expect(input.hasMultilineContent()).toBe(true);
+
+ input.setMode('auto');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+
+ input.setMode('collapsed');
+ input.setText('short quote', true);
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(true);
+ expect(input.hasMultilineContent()).toBe(true);
+
+ input.setMode('auto');
+ await flushMeasurements();
+ expect(input.isCompact()).toBe(false);
+ });
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-composer-layout.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-composer-layout.ts
new file mode 100644
index 0000000000..0f69cc2e34
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-composer-layout.ts
@@ -0,0 +1,137 @@
+import { createResizeObserver } from '@solid-primitives/resize-observer';
+import type { LexicalEditor } from 'lexical';
+import { type Accessor, createEffect, createSignal, onCleanup } from 'solid-js';
+import { match } from 'ts-pattern';
+import { createHasMultilineStructure } from './create-has-multiline-structure';
+
+/** Auto fits the content; expanded and collapsed are host presentation overrides. */
+export type ComposerLayoutMode = 'auto' | 'expanded' | 'collapsed';
+
+/**
+ * Own the layout decision and measure wrapping at the compact layout's width.
+ * The container must use data-composer-compact="true"/"false" for width styles
+ * so an inert copy can measure the compact layout without changing the live one.
+ */
+export function createComposerLayout(
+ editor: LexicalEditor,
+ options: {
+ container: Accessor<HTMLElement | undefined>;
+ mode?: Accessor<ComposerLayoutMode>;
+ }
+) {
+ const [root, setRoot] = createSignal<HTMLElement | null>(null);
+ const hasMultilineStructure = createHasMultilineStructure(editor);
+ const [hasWrappedLines, setHasWrappedLines] = createSignal(false);
+ const hasMultilineContent = () =>
+ hasMultilineStructure() || hasWrappedLines();
+ const isCompact = () =>
+ match(options.mode?.() ?? 'auto')
+ .with('auto', () => !hasMultilineContent())
+ .with('expanded', () => false)
+ .with('collapsed', () => true)
+ .exhaustive();
+ let queued = false;
+ let disposed = false;
+
+ const measure = () => {
+ const element = root();
+ const container = options.container();
+ if (!element || !container?.parentElement || !container.contains(element))
+ return;
+ const containerWidth = container.getBoundingClientRect().width;
+ if (containerWidth <= 0) return;
+
+ // Measure the actual compact CSS, including controls and padding, even if
+ // this composer mounted expanded or its controls changed while expanded.
+ const probe = container.cloneNode(true) as HTMLElement;
+ const probeEditor = probe.querySelector<HTMLElement>(
+ '[data-lexical-editor="true"]'
+ );
+ if (!probeEditor) return;
+ probe.removeAttribute('id');
+ for (const child of probe.querySelectorAll('[id]'))
+ child.removeAttribute('id');
+ for (const editable of probe.querySelectorAll<HTMLElement>(
+ '[contenteditable]'
+ ))
+ editable.contentEditable = 'false';
+ probe.inert = true;
+ probe.setAttribute('aria-hidden', 'true');
+ probe.setAttribute('data-composer-compact', 'true');
+ Object.assign(probe.style, {
+ position: 'absolute',
+ visibility: 'hidden',
+ pointerEvents: 'none',
+ top: '0',
+ left: '0',
+ boxSizing: 'border-box',
+ width: `${containerWidth}px`,
+ height: 'auto',
+ minHeight: '0',
+ maxHeight: 'none',
+ overflow: 'hidden',
+ });
+ container.parentElement.append(probe);
+ try {
+ if (probeEditor.getBoundingClientRect().width <= 0) return;
+ const range = element.ownerDocument.createRange();
+ range.selectNodeContents(probeEditor);
+ const lineHeight = Number.parseFloat(
+ getComputedStyle(probeEditor).lineHeight
+ );
+ setHasWrappedLines(range.getBoundingClientRect().height > lineHeight + 1);
+ } finally {
+ probe.remove();
+ }
+ };
+
+ // Lexical and Solid may still be updating the DOM when a draft changes.
+ // A microtask measures the committed layout, including in background tabs.
+ const schedule = () => {
+ if (queued || disposed) return;
+ queued = true;
+ queueMicrotask(() => {
+ queued = false;
+ if (!disposed) measure();
+ });
+ };
+
+ onCleanup(
+ editor.registerRootListener((element) => {
+ setRoot(element);
+ })
+ );
+ onCleanup(editor.registerUpdateListener(schedule));
+ createResizeObserver(() => [root(), options.container()], schedule);
+ createEffect(() => {
+ isCompact();
+ options.container();
+ schedule();
+ });
+ createEffect(() => {
+ const element = root();
+ const container = options.container();
+ if (!element || !container) return;
+ // Decorators can finish rendering after Lexical commits; controls can also
+ // change the available inline width without resizing the expanded editor.
+ const observer = new MutationObserver(schedule);
+ observer.observe(container, {
+ childList: true,
+ characterData: true,
+ attributes: true,
+ subtree: true,
+ });
+ const fonts = element.ownerDocument.fonts;
+ fonts?.addEventListener('loadingdone', schedule);
+ schedule();
+ onCleanup(() => {
+ observer.disconnect();
+ fonts?.removeEventListener('loadingdone', schedule);
+ });
+ });
+ onCleanup(() => {
+ disposed = true;
+ });
+
+ return { isCompact, hasMultilineContent };
+}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-line-breaks.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-line-breaks.test.ts
deleted file mode 100644
index 07529c301f..0000000000
--- a/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-line-breaks.test.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-import {
- $createLineBreakNode,
- $createParagraphNode,
- $createTextNode,
- $getRoot,
- createEditor,
-} from 'lexical';
-import { createRoot } from 'solid-js';
-import { describe, expect, it } from 'vitest';
-import { createHasLineBreaks } from './create-has-line-breaks';
-
-describe('composer line breaks', () => {
- it('expands for blank paragraphs and collapses when they are removed', () => {
- createRoot((dispose) => {
- const editor = createEditor();
- const hasLineBreaks = createHasLineBreaks(editor);
- editor.update(() => $getRoot().append($createParagraphNode()), {
- discrete: true,
- });
- expect(hasLineBreaks()).toBe(false);
- editor.update(() => $getRoot().append($createParagraphNode()), {
- discrete: true,
- });
- expect(hasLineBreaks()).toBe(true);
- editor.update(() => $getRoot().clear().append($createParagraphNode()), {
- discrete: true,
- });
- expect(hasLineBreaks()).toBe(false);
- dispose();
- });
- });
-
- it('detects a trailing soft break before another character is typed', () => {
- createRoot((dispose) => {
- const editor = createEditor();
- const hasLineBreaks = createHasLineBreaks(editor);
- editor.update(
- () =>
- $getRoot().append(
- $createParagraphNode().append(
- $createTextNode('Hello'),
- $createLineBreakNode()
- )
- ),
- { discrete: true }
- );
- expect(hasLineBreaks()).toBe(true);
- dispose();
- });
- });
-});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-line-breaks.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-line-breaks.ts
deleted file mode 100644
index a4599d0f96..0000000000
--- a/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-line-breaks.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { $getRoot, type LexicalEditor } from 'lexical';
-import { createSignal, onCleanup } from 'solid-js';
-
-/** Track explicit line breaks, including blank paragraphs, for composer layout. */
-export function createHasLineBreaks(editor: LexicalEditor) {
- const read = () => {
- const root = $getRoot();
- return root.getChildrenSize() > 1 || root.getTextContent().includes('\n');
- };
-
- const [hasLineBreaks, setHasLineBreaks] = createSignal(
- editor.getEditorState().read(read)
- );
-
- const unsubscribe = editor.registerUpdateListener(({ editorState }) => {
- setHasLineBreaks(editorState.read(read));
- });
-
- onCleanup(unsubscribe);
- return hasLineBreaks;
-}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-multiline-structure.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-multiline-structure.test.ts
new file mode 100644
index 0000000000..ce970775aa
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-multiline-structure.test.ts
@@ -0,0 +1,156 @@
+import {
+ $createListItemNode,
+ $createListNode,
+ ListItemNode,
+ ListNode,
+} from '@lexical/list';
+import {
+ $createHeadingNode,
+ $createQuoteNode,
+ HeadingNode,
+ QuoteNode,
+} from '@lexical/rich-text';
+import {
+ $createLineBreakNode,
+ $createParagraphNode,
+ $createTextNode,
+ $getRoot,
+ createEditor,
+} from 'lexical';
+import { createRoot } from 'solid-js';
+import { describe, expect, it } from 'vitest';
+import { createHasMultilineStructure } from './create-has-multiline-structure';
+
+describe('composer multiline structure', () => {
+ it.each([
+ [
+ 'bullet list',
+ () => $createListNode('bullet').append($createListItemNode()),
+ ],
+ [
+ 'numbered list',
+ () => $createListNode('number').append($createListItemNode()),
+ ],
+ ['checklist', () => $createListNode('check').append($createListItemNode())],
+ ['blockquote', $createQuoteNode],
+ ['heading', () => $createHeadingNode('h2')],
+ ] as const)(
+ 'expands a short %s and compacts when converted back to a paragraph',
+ (_name, createBlock) => {
+ createRoot((dispose) => {
+ const editor = createEditor({
+ nodes: [ListNode, ListItemNode, QuoteNode, HeadingNode],
+ });
+ const hasMultilineStructure = createHasMultilineStructure(editor);
+ editor.update(
+ () =>
+ $getRoot().append(
+ $createParagraphNode().append($createTextNode('Short'))
+ ),
+ { discrete: true }
+ );
+ expect(hasMultilineStructure()).toBe(false);
+
+ editor.update(
+ () => {
+ const block = createBlock();
+ const textContainer = block.getFirstChild() ?? block;
+ if (textContainer instanceof ListItemNode) {
+ textContainer.append($createTextNode('Short'));
+ } else {
+ block.append($createTextNode('Short'));
+ }
+ $getRoot().clear().append(block);
+ },
+ { discrete: true }
+ );
+ expect(
+ editor.getEditorState().read(() => $getRoot().getTextContent())
+ ).toBe('Short');
+ expect(hasMultilineStructure()).toBe(true);
+
+ editor.update(
+ () =>
+ $getRoot()
+ .clear()
+ .append($createParagraphNode().append($createTextNode('Short'))),
+ { discrete: true }
+ );
+ expect(hasMultilineStructure()).toBe(false);
+ dispose();
+ });
+ }
+ );
+
+ it('keeps inline formatting in a single paragraph compact', () => {
+ createRoot((dispose) => {
+ const editor = createEditor();
+ const hasMultilineStructure = createHasMultilineStructure(editor);
+ expect(hasMultilineStructure()).toBe(false);
+ editor.update(
+ () =>
+ $getRoot().append(
+ $createParagraphNode().append(
+ $createTextNode('Bold').toggleFormat('bold'),
+ $createTextNode('Italic').toggleFormat('italic'),
+ $createTextNode('Code').toggleFormat('code')
+ )
+ ),
+ { discrete: true }
+ );
+ expect(hasMultilineStructure()).toBe(false);
+ dispose();
+ });
+ });
+
+ it('expands an empty blockquote restored before the observer starts', () => {
+ createRoot((dispose) => {
+ const editor = createEditor({ nodes: [QuoteNode] });
+ editor.update(() => $getRoot().append($createQuoteNode()), {
+ discrete: true,
+ });
+ const hasMultilineStructure = createHasMultilineStructure(editor);
+ expect(hasMultilineStructure()).toBe(true);
+ dispose();
+ });
+ });
+
+ it('expands for blank paragraphs and collapses when they are removed', () => {
+ createRoot((dispose) => {
+ const editor = createEditor();
+ const hasMultilineStructure = createHasMultilineStructure(editor);
+ editor.update(() => $getRoot().append($createParagraphNode()), {
+ discrete: true,
+ });
+ expect(hasMultilineStructure()).toBe(false);
+ editor.update(() => $getRoot().append($createParagraphNode()), {
+ discrete: true,
+ });
+ expect(hasMultilineStructure()).toBe(true);
+ editor.update(() => $getRoot().clear().append($createParagraphNode()), {
+ discrete: true,
+ });
+ expect(hasMultilineStructure()).toBe(false);
+ dispose();
+ });
+ });
+
+ it('detects a trailing soft break before another character is typed', () => {
+ createRoot((dispose) => {
+ const editor = createEditor();
+ const hasMultilineStructure = createHasMultilineStructure(editor);
+ editor.update(
+ () =>
+ $getRoot().append(
+ $createParagraphNode().append(
+ $createTextNode('Hello'),
+ $createLineBreakNode()
+ )
+ ),
+ { discrete: true }
+ );
+ expect(hasMultilineStructure()).toBe(true);
+ dispose();
+ });
+ });
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-multiline-structure.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-multiline-structure.ts
new file mode 100644
index 0000000000..94104cde5e
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils/create-has-multiline-structure.ts
@@ -0,0 +1,26 @@
+import { $getRoot, $isParagraphNode, type LexicalEditor } from 'lexical';
+import { createSignal, onCleanup } from 'solid-js';
+
+/** Only a single paragraph without line breaks can use the compact layout. */
+export function createHasMultilineStructure(editor: LexicalEditor) {
+ const read = () => {
+ const root = $getRoot();
+ const firstChild = root.getFirstChild();
+ return (
+ root.getChildrenSize() > 1 ||
+ (firstChild !== null && !$isParagraphNode(firstChild)) ||
+ root.getTextContent().includes('\n')
+ );
+ };
+
+ const [hasMultilineStructure, setHasMultilineStructure] = createSignal(
+ editor.getEditorState().read(read)
+ );
+
+ const unsubscribe = editor.registerUpdateListener(({ editorState }) => {
+ setHasMultilineStructure(editorState.read(read));
+ });
+
+ onCleanup(unsubscribe);
+ return hasMultilineStructure;
+}
diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.md
index fd0f9168e8..ee38c549f8 100644
--- a/docs/AGENT_GUIDE/ai-chat.md
+++ b/docs/AGENT_GUIDE/ai-chat.md
@@ -22,8 +22,12 @@ More opens the full create menu in a glass bottom sheet. Other views show
to the left of the navigation pill's right edge below. Agents has no separate
create button; its AI input fills the row.
The composer's compact height is 46px, matching the mobile chrome buttons,
-with a plus attachment control and centered text and actions. It expands for
-longer prompts while focused. Leaving the AI composer collapses a long draft to
+with a paperclip attachment control and centered text and actions. It expands for
+longer prompts while focused, including text that wraps without an explicit
+line break. Lists, blockquotes, headings, and other non-paragraph blocks also
+expand while editing, even when their text is short. Shortening a paragraph
+draft or widening the pane restores the compact layout when the text fits
+beside its controls. Leaving the AI composer collapses a long draft to
a single-line preview in the accessory row; tapping it expands the same editor
with the full draft intact. Screens with an available composer or reply controls show those
instead; opening mobile search shows scope pills in their place. When neither
diff --git a/docs/AGENT_GUIDE/channels.md b/docs/AGENT_GUIDE/channels.md
index 4fad718922..4450cb6bda 100644
--- a/docs/AGENT_GUIDE/channels.md
+++ b/docs/AGENT_GUIDE/channels.md
@@ -36,10 +36,23 @@ toolbar, consistent at narrow and wide composer widths.
The new-message compose screen and channel message/reply inputs use the same
attachment and send controls on mobile and desktop, with no format toggle.
iOS uses the native media attachment picker.
-Short drafts place attachment, message text, and send on one row on both mobile
-and desktop. Multiline drafts and attachments expand the composer with its
-actions below the editor.
-When checking this transition, add and remove a line break or attachment and
+Short top-level drafts place attachment, message text, and send on one row on
+both mobile and desktop. Text that wraps onto a second line, explicit line
+breaks, non-paragraph blocks (lists, blockquotes, headings, etc.), and attachments
+expand the composer with its actions below the editor. Even a short or empty
+non-paragraph block uses the expanded layout; converting it back to a single
+short paragraph restores the compact layout. A restored block draft that becomes a
+wrapping paragraph should stay expanded without briefly collapsing; check this
+after reopening the channel with a draft already saved. Open reply composers always place the editor
+above the action row, including for empty and single-line drafts, so the
+attachment, delete-reply, and send controls have their own space.
+Attachment controls use a paperclip in both expanded and collapsed composers,
+including the iOS media picker. Input action and formatting buttons show the
+app tooltip without a second native browser tooltip.
+When checking this transition, type a long draft without pressing Enter, then
+shorten it and resize the pane. It should expand when the text no longer fits
+beside the buttons and collapse when it fits again, without flickering between
+layouts. Also add and remove a line break or attachment and
confirm the draft and caret position survive. The attachment and send controls
should remain usable in both layouts, including when editing an existing message.
The iOS share sheet keeps its editor above the attachment and formatting controls.
diff --git a/docs/AGENT_GUIDE/documents.md b/docs/AGENT_GUIDE/documents.md
index 0b4ee3e718..b26a02597c 100644
--- a/docs/AGENT_GUIDE/documents.md
+++ b/docs/AGENT_GUIDE/documents.md
@@ -118,8 +118,11 @@ access to the title and property controls.
Below the editor: `Discussion` section with a `Leave a comment...` contenteditable.
Desktop uses the same compact 15px composer as channels and AI chat, with an
-an `Attach images` paperclip that opens the image picker directly. Shift+Enter
-expands the editor above the controls. Touch keeps separate `Attach images` and
+`Attach images` paperclip that opens the image picker directly. Wrapping text or
+Shift+Enter expands the editor above the controls. Lists, blockquotes, and other
+non-paragraph blocks always expand while editing. A single paragraph returns to
+the compact layout once it fits on one line.
+Touch keeps separate `Attach images` and
`Format` buttons. `Send comment` is disabled until text exists. Click the
composer, `type_text`, then click `Send comment` (Enter also submits). The comment renders
above the composer with author + timestamp. `@`-mentions in comments notify the mentioned
@@ -129,7 +132,7 @@ When the comment composer is unavailable, the default Ask AI row appears instead
Tap `Leave a comment...`
to expand the channel-style input; use Send comment to submit (Enter inserts a
newline on mobile). Submitting clears and unfocuses the mobile input, returning
-it to its compact state and dismissing the keyboard. The compact input's plus
+it to its compact state and dismissing the keyboard. The compact input's paperclip
opens the native photo library in the iOS app, with a file-picker fallback when
unavailable; browsers use the file picker. Cancelling adds no images.
While the main document editor is focused with the virtual keyboard