Group conversations
Let people mention teammates and link issues while writing a message, then render the saved text with MentionText.
Components / Forms
Composer is a set of parts you assemble into a message box: a growing text field, and optional mentions, file attachments, dictation, and a send button. Your application owns message delivery, file uploads, and speech recognition.
Last changed in version 0.14.2: Improve keyboard navigation, action feedback, and selected colors across Vue components.
Installing Composer also includes MentionText, which displays the same references in saved messages. Each part is its own file, so you only import the ones you use.
bunx --bun @getweini/cli@latest add composerComposer the form root: draft model, state, send
├─ ComposerAttachments file rules and the attached-file list (enables picker, drop, paste)
├─ ComposerField the text field
│ ├─ ComposerMentions @ and # suggestions
│ └─ ComposerExpand grow and collapse control
├─ ComposerActions a group of controls; align="start" or "end"
│ ├─ ComposerAttach opens the file picker
│ ├─ ComposerDictation starts and stops dictation
│ └─ ComposerSend sends the draftComposer needs children, and ComposerField is the only required part. Leave out any part you do not need. For example, skip ComposerAttachments and ComposerAttach for a text-only box.
The smallest composition is a field and a send button:
Mention a teammate with @ or link an issue with #. Attachments are ready to send with your message.
The microphone demonstrates the adapter with sample text. Your application supplies speech recognition.
<script setup lang="ts">
import { ref } from 'vue'
import Composer from './components/ui/composer/Composer.vue'
import ComposerActions from './components/ui/composer/ComposerActions.vue'
import ComposerAttach from './components/ui/composer/ComposerAttach.vue'
import ComposerAttachments from './components/ui/composer/ComposerAttachments.vue'
import ComposerDictation from './components/ui/composer/ComposerDictation.vue'
import ComposerExpand from './components/ui/composer/ComposerExpand.vue'
import ComposerField from './components/ui/composer/ComposerField.vue'
import ComposerMentions from './components/ui/composer/ComposerMentions.vue'
import ComposerSend from './components/ui/composer/ComposerSend.vue'
import type {
ComposerDictationAdapter,
ComposerValue,
MentionEntity,
MentionRange,
} from './components/ui/composer/types'
import MentionText from './components/ui/mention-text/MentionText.vue'
const mariaAvatar = `data:image/svg+xml,${encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><rect width="64" height="64" fill="#e4e4e7"/><circle cx="32" cy="23" r="12" fill="#71717a"/><path d="M9 64c2-15 10-23 23-23s21 8 23 23" fill="#71717a"/></svg>',
)}`
interface SentMessage {
id: number
text: string
mentions: MentionRange[]
files: string[]
}
const peopleAndTeams: MentionEntity[] = [
{
id: 'person-maria',
label: 'Maria',
kind: 'person',
description: 'Product designer',
avatar: mariaAvatar,
},
{
id: 'person-alex',
label: 'Alex',
kind: 'person',
description: 'Design',
href: '/people/alex-design',
},
{
id: 'person-alex-engineering',
label: 'Alex',
kind: 'person',
description: 'Engineering',
href: '/people/alex-engineering',
},
{ id: 'team-design', label: 'Design', kind: 'team', description: '8 members' },
]
const issues: MentionEntity[] = [
{ id: 'issue-142', label: 'WEI-142', kind: 'issue', description: 'Review launch checklist' },
{ id: 'issue-158', label: 'WEI-158', kind: 'issue', description: 'Update onboarding screens' },
]
const mentionSources = [
{ trigger: '@', label: 'People and teams', items: peopleAndTeams },
{ trigger: '#', label: 'Issues', items: issues },
]
const draft = ref<ComposerValue>({ text: '', mentions: [], files: [] })
const messages = ref<SentMessage[]>([])
const dictation: ComposerDictationAdapter = {
start({ signal, onResult }) {
// Demo adapter: connect your speech service here and pass final text to onResult.
if (!signal.aborted) onResult('sample dictated words')
},
}
let nextMessageId = 1
function sendMessage(value: ComposerValue) {
messages.value.push({
id: nextMessageId++,
text: value.text,
mentions: [...value.mentions],
files: value.files.map((file) => file.name),
})
// This local demo displays the selected names. Upload value.files in your app before clearing after success.
draft.value = { text: '', mentions: [], files: [] }
}
</script>
<template>
<section
class="grid w-full max-w-2xl gap-4"
aria-label="Project group conversation"
data-composer-chat-demo
>
<div class="grid gap-3" aria-live="polite">
<article
v-for="(message, index) in messages"
:key="message.id"
class="max-w-[90%] rounded-xl border border-border bg-card px-4 py-3 text-card-foreground"
:class="index % 2 ? 'ms-auto' : ''"
>
<p class="text-sm leading-6">
<MentionText :text="message.text" :mentions="message.mentions" />
</p>
<ul
v-if="message.files.length"
class="mt-2 flex flex-wrap gap-2"
aria-label="Attached files"
>
<li
v-for="(file, fileIndex) in message.files"
:key="`${file}:${fileIndex}`"
class="rounded-md bg-secondary px-2 py-1 text-xs text-secondary-foreground"
>
{{ file }}
</li>
</ul>
</article>
<p
v-if="!messages.length"
class="rounded-xl border border-dashed border-border px-4 py-5 text-center text-sm text-muted-foreground"
>
Mention a teammate with @ or link an issue with #. Attachments are ready to send with your
message.
</p>
</div>
<Composer v-model="draft" @send="sendMessage">
<ComposerAttachments accept="image/*,.pdf" :max-files="4" />
<ComposerField aria-label="Message the project group" placeholder="Message the group…">
<ComposerMentions :sources="mentionSources" />
<ComposerExpand />
</ComposerField>
<ComposerActions>
<ComposerAttach />
</ComposerActions>
<ComposerActions align="end">
<ComposerDictation :adapter="dictation" />
<ComposerSend />
</ComposerActions>
</Composer>
<p class="text-xs text-muted-foreground">
The microphone demonstrates the adapter with sample text. Your application supplies speech
recognition.
</p>
</section>
</template>Add an optional avatar URL to an entity, for example { id: 'person-maria', label: 'Maria', avatar: '/avatars/maria.jpg' }. A 32px rounded avatar appears beside Maria in suggestions, and a smaller decorative avatar appears beside the padded, rounded mention in saved messages rendered with MentionText. Composer keeps the draft as plain text; the avatar is part of the displayed chip, not the text.
Let people mention teammates and link issues while writing a message, then render the saved text with MentionText.
Offer references to files, projects, or other records alongside message text. The application decides which entity types are available.
Pass final transcription chunks to onResult, and call onEnd when recognition finishes. If stopping the service delivers a final transcript asynchronously, return a promise from stop() that settles after that final result.
The dictation adapter above inserts sample text. Connect your preferred speech service for real dictation.
<script setup lang="ts">
import { ref } from 'vue'
import Composer from './components/ui/composer/Composer.vue'
import ComposerActions from './components/ui/composer/ComposerActions.vue'
import ComposerDictation from './components/ui/composer/ComposerDictation.vue'
import ComposerField from './components/ui/composer/ComposerField.vue'
import ComposerMentions from './components/ui/composer/ComposerMentions.vue'
import ComposerSend from './components/ui/composer/ComposerSend.vue'
import type {
ComposerDictationAdapter,
ComposerValue,
MentionEntity,
} from './components/ui/composer/types'
const draft = ref<ComposerValue>({ text: '', mentions: [], files: [] })
const sentText = ref('')
const people: MentionEntity[] = [
{ id: 'person-maria', label: 'Maria', kind: 'person' },
{ id: 'person-samira', label: 'Samira', kind: 'person' },
]
async function searchPeople(query: string, { signal }: { signal: AbortSignal }) {
// Replace this local filter with your API request. Composer aborts stale searches.
if (signal.aborted) return []
return people.filter((person) => person.label.toLowerCase().includes(query.toLowerCase()))
}
const dictation: ComposerDictationAdapter = {
start({ signal, onResult }) {
// Demo only: replace with your speech service and call onResult as text arrives.
if (!signal.aborted) onResult('sample dictated words')
},
}
function send(value: ComposerValue) {
// Send the text, stable mention IDs, and files to your application service.
sentText.value = value.text
draft.value = { text: '', mentions: [], files: [] }
}
</script>
<template>
<div class="grid w-full max-w-2xl gap-2">
<Composer v-model="draft" @send="send">
<ComposerField aria-label="Write an update" placeholder="Write an update…">
<ComposerMentions
:sources="[{ trigger: '@', label: 'People', search: searchPeople, minLength: 1 }]"
/>
</ComposerField>
<ComposerActions align="end">
<ComposerDictation :adapter="dictation" />
<ComposerSend />
</ComposerActions>
</Composer>
<p class="text-xs text-muted-foreground">
The dictation adapter above inserts sample text. Connect your preferred speech service for
real dictation.
</p>
<p v-if="sentText" role="status" class="text-sm text-muted-foreground">
Last sent:{{ sentText }}
</p>
</div>
</template>Pass file states from your upload flow to show progress and keep sending disabled until uploads are ready. Pass fileStates to ComposerAttachments. accept, maxFiles, and maxFileSize on the same part apply to picker, drop, and pasted files.
The application reports each upload state. Sending becomes available when all attached files are ready.
<script setup lang="ts">
import { computed, onMounted, ref } from 'vue'
import Composer from './components/ui/composer/Composer.vue'
import ComposerActions from './components/ui/composer/ComposerActions.vue'
import ComposerAttach from './components/ui/composer/ComposerAttach.vue'
import ComposerAttachments from './components/ui/composer/ComposerAttachments.vue'
import ComposerField from './components/ui/composer/ComposerField.vue'
import ComposerSend from './components/ui/composer/ComposerSend.vue'
import type { ComposerValue } from './components/ui/composer/types'
const draft = ref<ComposerValue>({
text: 'The selected files are still uploading.',
mentions: [],
files: [],
})
const fileStates = computed(() =>
draft.value.files.map((file) => ({ file, status: 'uploading' as const, progress: 62 })),
)
onMounted(() => {
draft.value.files = [
new File(['Example project brief'], 'launch-brief.pdf', { type: 'application/pdf' }),
]
})
</script>
<template>
<div class="grid w-full max-w-2xl gap-3">
<Composer v-model="draft" data-composer-upload-demo>
<ComposerAttachments
accept="image/*,.pdf"
:max-files="3"
:max-file-size="10 * 1024 * 1024"
:file-states="fileStates"
/>
<ComposerField
aria-label="Write a message while files upload"
placeholder="Write a message…"
/>
<ComposerActions>
<ComposerAttach />
</ComposerActions>
<ComposerActions align="end">
<ComposerSend />
</ComposerActions>
</Composer>
<p class="text-xs text-muted-foreground">
The application reports each upload state. Sending becomes available when all attached files
are ready.
</p>
</div>
</template>References use stable record IDs. Suggestion descriptions distinguish people with the same name; editing a reference turns it into ordinary text while untouched references keep their identity.
<script setup lang="ts">
import { ref } from 'vue'
import Composer from './components/ui/composer/Composer.vue'
import ComposerActions from './components/ui/composer/ComposerActions.vue'
import ComposerField from './components/ui/composer/ComposerField.vue'
import ComposerMentions from './components/ui/composer/ComposerMentions.vue'
import ComposerSend from './components/ui/composer/ComposerSend.vue'
import type { ComposerValue, MentionEntity } from './components/ui/composer/types'
const people: MentionEntity[] = [
{ id: 'alex-design', label: 'Alex', description: 'Design team', href: '/people/alex-design' },
{ id: 'alex-engineering', label: 'Alex', description: 'Engineering team' },
]
const draft = ref<ComposerValue>({
text: '@Alex @Alex',
mentions: people.map((entity, index) => ({
start: index * 6,
end: index * 6 + 5,
trigger: '@',
entity,
})),
files: [],
})
const sentIds = ref('')
function send(value: ComposerValue) {
sentIds.value = value.mentions.map((mention) => mention.entity.id).join(', ')
}
</script>
<template>
<div data-composer-identities class="grid w-full max-w-2xl gap-2">
<Composer v-model="draft" @send="send">
<ComposerField aria-label="Message with matching names">
<ComposerMentions :sources="[{ trigger: '@', items: people }]" />
</ComposerField>
<ComposerActions align="end">
<ComposerSend />
</ComposerActions>
</Composer>
<p class="text-xs text-muted-foreground">
Each Alex keeps a separate record ID. Edit or remove either reference without changing the
other.
</p>
<output v-if="sentIds" class="text-sm text-muted-foreground">
Referenced records:{{ sentIds }}
</output>
</div>
</template>Sends the draft. It is disabled while the field is empty, files are uploading, dictation is active, or sending, invalid, disabled or readonly is set.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
readonlyprop | boolean | undefined | Not set | Show the value while preventing edits. |
requiredprop | boolean | undefined | Not set | Ask the browser to require a value before form submission. |
invalidprop | boolean | undefined | Not set | Show the invalid state; also provide a visible error message. |
sendingprop | boolean | undefined | Not set | Controls the sending behavior of Composer. |
sendOnEnterprop | boolean | undefined | true | Controls the send on enter behavior of Composer. |
localeTextprop | Partial<ComposerLocaleText> | undefined | Not set | Controls the locale text behavior of Composer. |
modelValuemodel | ComposerValue | undefined | Not set | Current value. Use v-model to keep it in sync with your page. |
update:modelValueevent | [value: ComposerValue | undefined] | — | Requests a new model value from the parent. |
sendevent | [value: ComposerValue] | — | Emitted when send happens. |
defaultslot | () => unknown | Required | Content shown inside Composer. |
elementexposed | HTMLElement | null | — | Reference to the underlying HTML element. |
focusexposed | () => void | — | Move keyboard focus to this control. |
clearexposed | () => void | — | Access clear from a component template ref. |
expandexposed | () => void | — | Access expand from a component template ref. |
collapseexposed | () => void | — | Access collapse from a component template ref. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
alignprop | "start" | "end" | undefined | "start" | Which end of the writing row or toolbar the group sits at. |
defaultslot | () => unknown | Required | Content shown inside ComposerActions. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | (() => unknown) | undefined | Optional | Content shown inside ComposerAttach. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
acceptprop | string | undefined | Not set | Limit the file types that can be chosen. |
multipleprop | boolean | undefined | true | Allow more than one item or file to be selected. |
maxFilesprop | number | undefined | Not set | Controls the max files behavior of ComposerAttachments. |
maxFileSizeprop | number | undefined | Not set | Controls the max file size behavior of ComposerAttachments. |
fileStatesprop | readonly ComposerFileState[] | undefined | Not set | Controls the file states behavior of ComposerAttachments. |
rejectevent | [files: File[], reason: "accept" | "max-files" | "max-file-size"] | — | Emitted when reject happens. |
defaultslot | ((props: ComposerAttachmentSlotProps) => unknown) | undefined | Optional | Content shown inside ComposerAttachments. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
adapterprop | ComposerDictationAdapter | Required | | ComposerDictation | Dictation button, waveform, status | adapter; icon slot | |
defaultslot | ((props: { listening: boolean; }) => unknown) | undefined | Optional | Content shown inside ComposerDictation. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | ((props: { expanded: boolean; }) => unknown) | undefined | Optional | Content shown inside ComposerExpand. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
maxRowsprop | number | undefined | Not set | When the text wraps or files are attached, the field takes its own row and the actions move to a toolbar row beneath it; the writing area then grows up to maxRows (6 by default) and scrolls. |
listsprop | boolean | undefined | true | Markdown-style lists: Enter or Ctrl/Cmd+Enter continues an item; Tab changes depth. Default true. |
defaultslot | (() => unknown) | undefined | Optional | Content shown inside ComposerField. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
sourcesprop | readonly MentionSource[] | Required | Controls the sources behavior of ComposerMentions. |
defaultslot | ((props: ComposerSuggestionSlotProps) => unknown) | undefined | Optional | Content shown inside ComposerMentions. |
| Name | Type or signature | Default | What it does |
|---|---|---|---|
defaultslot | (() => unknown) | undefined | Optional | Content shown inside ComposerSend. |
// packages/frameworks/vue/components/composer/types.ts
import type { ComposerFileState } from '@getweini/vue/primitives/composer'
import type { MentionEntity } from '@getweini/vue/primitives/mention'
export type {
ComposerActionsProps,
ComposerAttachmentsProps,
ComposerDictationAdapter,
ComposerDictationProps,
ComposerFieldProps,
ComposerFileState,
ComposerLocaleText,
ComposerMentionsProps,
ComposerProps,
ComposerRejectReason,
ComposerValue,
MentionSource,
} from '@getweini/vue/primitives/composer'
export type { MentionEntity, MentionRange } from '@getweini/vue/primitives/mention'
/** Slot values for one attached file; `preview` is a local object URL for images. */
export interface ComposerAttachmentSlotProps {
file: File
index: number
state?: ComposerFileState
preview?: string
remove: () => void
}
export interface ComposerSuggestionSlotProps {
entity: MentionEntity
query: string
active: boolean
}
// packages/frameworks/vue/dist/vue/primitives/composer/index.d.ts
import { type InjectionKey, type Ref } from 'vue';
import { createComposerCore } from './core';
import { createComposerDictation } from './dictation';
import { createComposerField } from './field';
import { createComposerFiles } from './files';
import { createComposerMentions } from './mentions';
import type { ComposerAttachmentsProps, ComposerDictationAdapter, ComposerFieldProps, ComposerProps, ComposerRejectReason, ComposerValue, MentionSource } from './types';
export type { MentionEntity, MentionRange } from '../mention';
export { defaultComposerLocaleText } from './locale';
export type { ComposerActionsProps, ComposerAttachmentsProps, ComposerDictationAdapter, ComposerDictationProps, ComposerFieldProps, ComposerFileState, ComposerLocaleText, ComposerMentionsProps, ComposerProps, ComposerRejectReason, ComposerValue, MentionSource, } from './types';
export interface ComposerContext {
id: string;
props: ComposerProps;
core: ReturnType<typeof createComposerCore>;
field: ReturnType<typeof createComposerField>;
mentions: ReturnType<typeof createComposerMentions>;
files: ReturnType<typeof createComposerFiles>;
dictation: ReturnType<typeof createComposerDictation>;
fileInput: Ref<HTMLInputElement | null>;
/** Registered by the part that owns the feature; `null` or empty while the part is absent. */
attachments: Ref<ComposerAttachmentsProps | null>;
rejectHandler: Ref<RejectHandler | null>;
adapter: Ref<ComposerDictationAdapter | null>;
sources: Ref<readonly MentionSource[]>;
maxRows: Ref<number>;
lists: Ref<boolean>;
hasExpand: Ref<boolean>;
nativeValid: Ref<boolean>;
canSend: Readonly<Ref<boolean>>;
send: () => void;
}
type RejectHandler = (files: File[], reason: ComposerRejectReason) => void;
export declare const composerContext: InjectionKey<ComposerContext>;
export declare function useComposerContext(component: string): ComposerContext;
export declare function useComposerRoot(props: ComposerProps, model: {
value: ComposerValue | undefined;
}, emit: {
send: (value: ComposerValue) => void;
}): {
context: ComposerContext;
/** Bindings for the root `<fieldset>`. */
bindings: import("vue").ComputedRef<{
'data-composer': string;
disabled: boolean | undefined;
'data-multiline': true | undefined;
'data-expanded': true | undefined;
'data-dragging': true | undefined;
'aria-busy': true | undefined;
onDragover: (event: DragEvent) => void;
onDragleave: (event: DragEvent) => void;
onDrop: (event: DragEvent) => void;
onKeydown: (event: KeyboardEvent) => void;
}>;
/** The editor must follow a controlled parent that rejects a change. */
restoreText: () => void;
exposed: {
element: Ref<HTMLElement | null, HTMLElement | null>;
focus: () => void;
clear: () => void;
expand: () => void;
collapse: () => void;
};
};
export declare function useComposerField(attrs: Record<string, unknown>, props: ComposerFieldProps): {
context: ComposerContext;
bindings: () => {
[x: string]: unknown;
};
carrierBindings: () => {
value: string;
disabled: boolean | undefined;
readonly: boolean | undefined;
required: boolean | undefined;
tabindex: number;
'aria-hidden': boolean;
onFocus: () => void;
};
text: import("vue").ComputedRef<string>;
maxRows: Ref<number, number>;
placeholder: import("vue").ComputedRef<string>;
mentions: import("vue").ComputedRef<import(".").MentionRange[]>;
multiline: Ref<boolean, boolean>;
/** Reserve inline-end room for the expand control when one is rendered. */
reserveEnd: import("vue").ComputedRef<boolean>;
setTextarea: (node: unknown) => void;
setEditor: (node: unknown) => void;
};
export declare function useComposerMentions(props: {
sources: readonly MentionSource[];
}): {
state: {
trigger: Ref<{
trigger: string;
label?: string | undefined;
items?: readonly {
id: string;
label: string;
kind?: string | undefined;
description?: string | undefined;
avatar?: string | undefined;
href?: string | undefined;
disabled?: boolean | undefined;
}[] | undefined;
search?: ((query: string, context: {
signal: AbortSignal;
}) => Promise<readonly import(".").MentionEntity[]>) | undefined;
minLength?: number | undefined;
} | null, MentionSource | {
trigger: string;
label?: string | undefined;
items?: readonly {
id: string;
label: string;
kind?: string | undefined;
description?: string | undefined;
avatar?: string | undefined;
href?: string | undefined;
disabled?: boolean | undefined;
}[] | undefined;
search?: ((query: string, context: {
signal: AbortSignal;
}) => Promise<readonly import(".").MentionEntity[]>) | undefined;
minLength?: number | undefined;
} | null>;
query: Ref<string, string>;
suggestions: Ref<{
id: string;
label: string;
kind?: string | undefined;
description?: string | undefined;
avatar?: string | undefined;
href?: string | undefined;
disabled?: boolean | undefined;
}[], import(".").MentionEntity[] | {
id: string;
label: string;
kind?: string | undefined;
description?: string | undefined;
avatar?: string | undefined;
href?: string | undefined;
disabled?: boolean | undefined;
}[]>;
activeIndex: Ref<number, number>;
isLoading: Ref<boolean, boolean>;
searchError: Ref<boolean, boolean>;
style: Ref<Record<string, string>, Record<string, string>>;
isComposing: Ref<boolean, boolean>;
resetDismissed: () => void;
position: (offset: number) => void;
resolveText: (text: string, from: number, to: number) => {
mentions: import(".").MentionRange[];
unresolved: {
start: number;
end: number;
}[];
};
resolveRemote: (ranges: readonly {
start: number;
end: number;
}[]) => void;
close: () => void;
sync: () => void;
insert: (entity: import(".").MentionEntity) => void;
retry: () => void;
handleKeydown: (event: KeyboardEvent) => boolean;
handleFocusout: (event: FocusEvent) => void;
dispose: () => void;
};
open: import("vue").ComputedRef<boolean>;
locale: import("vue").ComputedRef<import("./types").ComposerLocaleText>;
listboxId: string;
optionId: (index: number) => string;
label: import("vue").ComputedRef<string>;
};
export declare function useComposerAttachments(props: ComposerAttachmentsProps, onReject: RejectHandler): {
state: {
enabled: import("vue").ComputedRef<boolean>;
isDragging: Ref<boolean, boolean>;
rejectionMessage: Ref<string, string>;
imagePreviews: Ref<Map<File, string> & Omit<Map<File, string>, keyof Map<any, any>>, Map<File, string> | (Map<File, string> & Omit<Map<File, string>, keyof Map<any, any>>)>;
fileStates: import("vue").ComputedRef<readonly import("./types").ComposerFileState[]>;
filesReady: import("vue").ComputedRef<boolean>;
add: (candidates: readonly File[]) => void;
remove: (index: number) => void;
openPicker: () => void;
handlePreviewError: (file: File) => void;
handleFileChange: (event: Event) => void;
handleDragOver: (event: DragEvent) => void;
handleDragLeave: (event: DragEvent) => void;
handleDrop: (event: DragEvent) => void;
handlePaste: (event: ClipboardEvent) => void;
clearRejection: () => void;
mount: () => void;
dispose: () => void;
};
items: import("vue").ComputedRef<{
file: File;
key: string;
index: number;
state: import("./types").ComposerFileState | undefined;
preview: string | undefined;
remove: () => void;
}[]>;
locale: import("vue").ComputedRef<import("./types").ComposerLocaleText>;
disabled: import("vue").ComputedRef<boolean | undefined>;
inputBindings: import("vue").ComputedRef<{
type: string;
hidden: boolean;
tabindex: number;
accept: string | undefined;
multiple: boolean;
disabled: boolean;
onChange: (event: Event) => void;
}>;
setInput: (node: unknown) => void;
};
export declare function useComposerAttach(): {
label: import("vue").ComputedRef<string>;
disabled: import("vue").ComputedRef<boolean>;
open: () => void;
};
export declare function useComposerDictation(props: {
adapter: ComposerDictationAdapter;
}): {
state: {
listening: Ref<boolean, boolean>;
processing: Ref<boolean, boolean>;
error: Ref<string, string>;
toggle: () => void;
cancel: (target?: ComposerDictationAdapter | null) => void;
};
locale: import("vue").ComputedRef<import("./types").ComposerLocaleText>;
label: import("vue").ComputedRef<string>;
disabled: import("vue").ComputedRef<boolean>;
};
export declare function useComposerSend(): {
canSend: Readonly<Ref<boolean, boolean>>;
sending: import("vue").ComputedRef<boolean>;
label: import("vue").ComputedRef<string>;
send: () => void;
};
export declare function useComposerExpand(): {
expanded: Ref<boolean, boolean>;
label: import("vue").ComputedRef<string>;
disabled: import("vue").ComputedRef<boolean>;
toggle: () => void;
};
/** Layout state for parts that change shape between the inline and stacked layouts. */
export declare function useComposerLayout(): {
multiline: Ref<boolean, boolean>;
expanded: Ref<boolean, boolean>;
};
// packages/frameworks/vue/dist/vue/primitives/composer/core.d.ts
import { type ComputedRef, type Ref } from 'vue';
import type { MentionRange } from '../mention';
import { type UnresolvedRange } from '../rich-text/editor';
import type { ComposerLocaleText, ComposerProps, ComposerValue } from './types';
export declare const EMPTY_VALUE: () => ComposerValue;
export interface TextEdit {
start: number;
end: number;
text: string;
}
/** State every feature module reads: the draft, who may edit it, and the field elements. */
export interface ComposerCore {
props: ComposerProps;
value: ComputedRef<ComposerValue>;
validMentions: ComputedRef<MentionRange[]>;
canEdit: ComputedRef<boolean>;
locale: ComputedRef<ComposerLocaleText>;
/** The editable surface. */
editor: Ref<HTMLElement | null>;
/** Hidden native textarea that carries the draft for form submission, validation and reset. */
textarea: Ref<HTMLTextAreaElement | null>;
lists: Ref<boolean>;
update: (next: ComposerValue) => void;
/** Selection as offsets into the draft text, or null when the editor has none. */
selection: () => {
start: number;
end: number;
} | null;
select: (start: number, end?: number) => void;
/** Apply sequential text edits, keep unaffected mentions, render, and place the caret. */
edit: (edits: readonly TextEdit[], caret?: number, mention?: MentionRange | readonly MentionRange[], unresolved?: readonly UnresolvedRange[]) => void;
/** Mention-looking text that matched no entity; drawn with a squiggle, never part of the model. */
unresolved: () => readonly UnresolvedRange[];
setUnresolved: (ranges: readonly UnresolvedRange[]) => void;
/** Turn an unresolved range into a mention once it can be resolved (for example by an async search). */
resolve: (range: UnresolvedRange, mention: MentionRange) => void;
/** Rebuild the editor from the model when it differs, keeping the selection. */
syncFromModel: (force?: boolean) => void;
/** Draw the given draft in the editor, then adopt whatever the DOM normalizes it to. */
show: (text: string, mentions: readonly MentionRange[], caret?: number) => void;
rangeAt: (start: number, end: number) => Range | null;
/** Remember the draft before an edit so undo can restore it. `key` merges rapid typing into one step. */
remember: (selection?: {
start: number;
end: number;
} | null, key?: string) => void;
undo: () => void;
redo: () => void;
resetHistory: () => void;
}
export declare function createComposerCore(props: ComposerProps, model: {
value: ComposerValue | undefined;
}, textarea: Ref<HTMLTextAreaElement | null>, editor: Ref<HTMLElement | null>, lists: Ref<boolean>): ComposerCore;
// packages/frameworks/vue/dist/vue/primitives/mention/index.d.ts
import type { MentionEditRange, MentionRange, MentionSegment } from './types';
export type { MentionEditRange, MentionEntity, MentionRange, MentionSegment } from './types';
/** Keep only valid mention ranges, in text order, dropping overlaps deterministically. */
export declare function normalizeMentions(text: string, mentions: readonly MentionRange[]): MentionRange[];
/** Split plain text around valid mentions without changing or losing any characters. */
export declare function getMentionSegments(text: string, mentions: readonly MentionRange[]): MentionSegment[];
/** Apply the smallest contiguous text edit to mention offsets, dropping edited mentions. */
export declare function updateMentionRanges(previousText: string, nextText: string, mentions: readonly MentionRange[], edit?: MentionEditRange): MentionRange[];
/** Allow ordinary relative links and http(s)/mailto URLs while rejecting executable schemes. */
export declare function isSafeMentionHref(href: string | undefined): href is string;
// packages/frameworks/vue/dist/vue/primitives/mention/types.d.ts
export interface MentionEntity {
id: string;
label: string;
kind?: string;
description?: string;
avatar?: string;
href?: string;
disabled?: boolean;
}
/** A mention's UTF-16 range in the plain message text. */
export interface MentionRange {
start: number;
end: number;
trigger: string;
entity: MentionEntity;
}
export interface MentionSegment {
text: string;
mention?: MentionRange;
}
/** UTF-16 selection in the previous text that the user replaced. */
export interface MentionEditRange {
start: number;
end: number;
}
// packages/frameworks/vue/dist/vue/primitives/rich-text/editor.d.ts
import type { MentionRange } from '../mention';
/**
* Plain-text <-> editable DOM translation for the Composer field.
*
* The draft stays a string. Lists are written as markdown lines (`- item`, `1. item`, two spaces
* of indent per depth, a soft line break inside an item continues on a line indented under it),
* and the editor shows them as real lists. `readEditor` is the inverse of `renderEditor`, and it
* records where every text offset lives in the DOM so selection can move between the two.
*/
/** A span of text that looks like a mention but matched no known entity. */
export interface UnresolvedRange {
start: number;
end: number;
}
export interface EditorSnapshot {
text: string;
mentions: MentionRange[];
unresolved: UnresolvedRange[];
}
interface Stop {
node: Node;
/** DOM offset inside `node` for a text stop, or the child index for an element stop. */
domOffset: number;
start: number;
end: number;
/** Atomic stops (mentions) cannot hold a caret; offsets inside snap to their edges. */
atomic?: boolean;
}
interface Reading extends EditorSnapshot {
stops: Stop[];
starts: Map<Node, number>;
ends: Map<Node, number>;
}
declare const MENTION_ATTRIBUTE = "data-composer-mention";
/** Replace the editor's content with the DOM for `text`. */
export declare function renderEditor(root: HTMLElement, text: string, mentions: readonly MentionRange[], lists?: boolean, unresolved?: readonly UnresolvedRange[]): void;
/** Parse the editor DOM into the draft text, its mention ranges, and a DOM position map. */
export declare function readEditor(root: HTMLElement): Reading;
export declare function getEditorSelection(root: HTMLElement, reading?: Reading): {
start: number;
end: number;
} | null;
export declare function createEditorRange(root: HTMLElement, start: number, end: number, reading?: Reading): Range;
export declare function setEditorSelection(root: HTMLElement, start: number, end?: number): void;
/** Scroll the editor so the caret line is fully visible, keeping its padding as breathing room. */
export declare function scrollCaretIntoView(root: HTMLElement): void;
/** Escape text for use in an HTML string. */
export declare function escapeHtml(value: string): string;
export declare function mentionHtml(mention: MentionRange, label: string): string;
export { MENTION_ATTRIBUTE };
// packages/frameworks/vue/dist/vue/primitives/composer/types.d.ts
import type { MentionEntity, MentionRange } from '../mention';
export interface ComposerValue {
text: string;
mentions: MentionRange[];
files: File[];
}
export interface MentionSource {
trigger: string;
label?: string;
items?: readonly MentionEntity[];
search?: (query: string, context: {
signal: AbortSignal;
}) => Promise<readonly MentionEntity[]>;
minLength?: number;
}
export interface ComposerFileState {
file: File;
status: 'uploading' | 'ready' | 'error';
progress?: number;
error?: string;
}
export interface ComposerDictationAdapter {
start(context: {
signal: AbortSignal;
onResult: (text: string) => void;
onEnd: () => void;
}): void | Promise<void>;
stop?: () => void | Promise<void>;
}
export interface ComposerLocaleText {
attach: string;
expand: string;
collapse: string;
send: string;
sending: string;
startDictation: string;
stopDictation: string;
dictationError: string;
dictationListening: string;
dictationProcessing: string;
searchLoading: string;
searchError: string;
retry: string;
removeFile: (name: string) => string;
suggestions: string;
noSuggestions: string;
fileTooLarge: (name: string) => string;
tooManyFiles: (count: number) => string;
fileNotAccepted: (name: string) => string;
}
export type ComposerRejectReason = 'accept' | 'max-files' | 'max-file-size';
/** State shared by every part: the draft model, field state, and localized labels. */
export interface ComposerProps {
disabled?: boolean;
readonly?: boolean;
required?: boolean;
invalid?: boolean;
sending?: boolean;
sendOnEnter?: boolean;
localeText?: Partial<ComposerLocaleText>;
}
export interface ComposerFieldProps {
maxRows?: number;
/** Markdown-style lists: Enter or Ctrl/Cmd+Enter continues an item; Tab changes depth. Default true. */
lists?: boolean;
}
/** File rules apply to picker, drop, and paste. Rendering `ComposerAttachments` enables files. */
export interface ComposerAttachmentsProps {
accept?: string;
multiple?: boolean;
maxFiles?: number;
maxFileSize?: number;
fileStates?: readonly ComposerFileState[];
}
export interface ComposerMentionsProps {
sources: readonly MentionSource[];
}
export interface ComposerDictationProps {
adapter: ComposerDictationAdapter;
}
export interface ComposerActionsProps {
/** Which end of the writing row or toolbar the group sits at. */
align?: 'start' | 'end';
}
// packages/frameworks/vue/dist/vue/primitives/composer/dictation.d.ts
import { type Ref } from 'vue';
import type { ComposerCore } from './core';
import type { ComposerDictationAdapter } from './types';
/** Adapter lifecycle for opt-in dictation; the adapter owns microphone access. */
export declare function createComposerDictation(core: ComposerCore, adapter: Ref<ComposerDictationAdapter | null>): {
listening: Ref<boolean, boolean>;
processing: Ref<boolean, boolean>;
error: Ref<string, string>;
toggle: () => void;
cancel: (target?: ComposerDictationAdapter | null) => void;
};
export type ComposerDictation = ReturnType<typeof createComposerDictation>;
// packages/frameworks/vue/dist/vue/primitives/composer/field.d.ts
import { type Ref } from 'vue';
import type { ComposerCore } from './core';
import type { ComposerMentions } from './mentions';
/** Editing behavior for the field: input, list keys, paste, undo, sizing, layout mode, and Enter-to-send. */
export declare function createComposerField(core: ComposerCore, mentions: ComposerMentions, maxRows: Ref<number>, send: () => void): {
expanded: Ref<boolean, boolean>;
isMultiline: Ref<boolean, boolean>;
maxRows: Ref<number, number>;
resize: () => void;
focus: () => void;
expand: () => void;
collapse: () => void;
resetHistory: () => void;
handleBeforeInput: (event: InputEvent) => void;
handleInput: (event: Event) => void;
handleKeydown: (event: KeyboardEvent) => void;
handleKeyup: (event: KeyboardEvent) => void;
handlePaste: (event: ClipboardEvent) => void;
handleRootKeydown: (event: KeyboardEvent) => void;
handleCompositionStart: () => void;
handleCompositionEnd: () => void;
handleBlur: (event: FocusEvent) => void;
};
export type ComposerFieldBehavior = ReturnType<typeof createComposerField>;
// packages/frameworks/vue/dist/vue/primitives/composer/mentions.d.ts
import { type Ref } from 'vue';
import type { MentionEntity, MentionRange } from '../mention';
import type { ComposerCore } from './core';
import type { MentionSource } from './types';
/** Trigger parsing, suggestion search, popup state, and mention insertion. */
export declare function createComposerMentions(core: ComposerCore, sources: Ref<readonly MentionSource[]>): {
trigger: Ref<{
trigger: string;
label?: string | undefined;
items?: readonly {
id: string;
label: string;
kind?: string | undefined;
description?: string | undefined;
avatar?: string | undefined;
href?: string | undefined;
disabled?: boolean | undefined;
}[] | undefined;
search?: ((query: string, context: {
signal: AbortSignal;
}) => Promise<readonly MentionEntity[]>) | undefined;
minLength?: number | undefined;
} | null, MentionSource | {
trigger: string;
label?: string | undefined;
items?: readonly {
id: string;
label: string;
kind?: string | undefined;
description?: string | undefined;
avatar?: string | undefined;
href?: string | undefined;
disabled?: boolean | undefined;
}[] | undefined;
search?: ((query: string, context: {
signal: AbortSignal;
}) => Promise<readonly MentionEntity[]>) | undefined;
minLength?: number | undefined;
} | null>;
query: Ref<string, string>;
suggestions: Ref<{
id: string;
label: string;
kind?: string | undefined;
description?: string | undefined;
avatar?: string | undefined;
href?: string | undefined;
disabled?: boolean | undefined;
}[], MentionEntity[] | {
id: string;
label: string;
kind?: string | undefined;
description?: string | undefined;
avatar?: string | undefined;
href?: string | undefined;
disabled?: boolean | undefined;
}[]>;
activeIndex: Ref<number, number>;
isLoading: Ref<boolean, boolean>;
searchError: Ref<boolean, boolean>;
style: Ref<Record<string, string>, Record<string, string>>;
isComposing: Ref<boolean, boolean>;
/** The user edited the text after dismissing; allow the same trigger to reopen. */
resetDismissed: () => void;
position: (offset: number) => void;
resolveText: (text: string, from: number, to: number) => {
mentions: MentionRange[];
unresolved: {
start: number;
end: number;
}[];
};
resolveRemote: (ranges: readonly {
start: number;
end: number;
}[]) => void;
close: () => void;
sync: () => void;
insert: (entity: MentionEntity) => void;
retry: () => void;
handleKeydown: (event: KeyboardEvent) => boolean;
handleFocusout: (event: FocusEvent) => void;
dispose: () => void;
};
export type ComposerMentions = ReturnType<typeof createComposerMentions>;
// packages/frameworks/vue/dist/vue/primitives/composer/files.d.ts
import { type Ref } from 'vue';
import type { ComposerCore } from './core';
import type { ComposerAttachmentsProps, ComposerRejectReason } from './types';
/** File rules, previews, and drag/paste intake. Active only while attachments are rendered. */
export declare function createComposerFiles(core: ComposerCore, config: Ref<ComposerAttachmentsProps | null>, fileInput: Ref<HTMLInputElement | null>, onReject: (files: File[], reason: ComposerRejectReason) => void): {
enabled: import("vue").ComputedRef<boolean>;
isDragging: Ref<boolean, boolean>;
rejectionMessage: Ref<string, string>;
imagePreviews: Ref<Map<File, string> & Omit<Map<File, string>, keyof Map<any, any>>, Map<File, string> | (Map<File, string> & Omit<Map<File, string>, keyof Map<any, any>>)>;
fileStates: import("vue").ComputedRef<readonly import("./types").ComposerFileState[]>;
filesReady: import("vue").ComputedRef<boolean>;
add: (candidates: readonly File[]) => void;
remove: (index: number) => void;
openPicker: () => void;
handlePreviewError: (file: File) => void;
handleFileChange: (event: Event) => void;
handleDragOver: (event: DragEvent) => void;
handleDragLeave: (event: DragEvent) => void;
handleDrop: (event: DragEvent) => void;
handlePaste: (event: ClipboardEvent) => void;
clearRejection: () => void;
mount: () => void;
dispose: () => void;
};
export type ComposerFiles = ReturnType<typeof createComposerFiles>;
// packages/frameworks/vue/dist/vue/primitives/composer/locale.d.ts
export declare const defaultComposerLocaleText: {
attach: string;
expand: string;
collapse: string;
send: string;
sending: string;
startDictation: string;
stopDictation: string;
dictationError: string;
dictationListening: string;
dictationProcessing: string;
searchLoading: string;
searchError: string;
retry: string;
removeFile: (name: string) => string;
suggestions: string;
noSuggestions: string;
fileTooLarge: (name: string) => string;
tooManyFiles: (count: number) => string;
fileNotAccepted: (name: string) => string;
};Part summary:
The root is a fieldset. Use v-model to manage the draft or clear it after a successful send. The send event emits a snapshot and does not clear the model.
Native attributes such as name, placeholder, and aria-label go to the editor, except name, form, maxlength and minlength, which go to the hidden textarea that carries the draft for forms. It can host ComposerMentions and ComposerExpand.
Takes sources and an optional suggestion slot. Place it inside ComposerField.
A button that grows or collapses the field. Place it inside ComposerField.
Rendering this part turns on the picker, drop, and paste. Its default slot customizes each attached file.
The button that opens the file picker. It needs ComposerAttachments in the same Composer.
Groups controls. Use align="start" (default) or align="end".
Takes an adapter. The button shows listening and error states.
Sends the draft. It is disabled while the field is empty, files are uploading, dictation is active, or sending, invalid, disabled or readonly is set.
1. one creates 2. ; pressing it again on that empty item creates a normal line without sending. Ctrl/Cmd+Enter sends when the caret is outside a list.- or 1. at the start of a line to start a list. Enter on an empty item, or Shift+Enter twice, leaves the list; Tab and Shift+Tab nest and outdent. Set :lists="false" on ComposerField to turn lists off. Press Escape then Tab to move focus out of a list. Set :send-on-enter="false" for a multiline-first workflow.maxRows on ComposerField (6 by default), then scrolls. ComposerExpand preserves the current text selection.reject to explain rejected files.fileStates lets your application report upload progress, ready state, or errors. Sending remains unavailable while a listed file is uploading or has failed.adapter is supplied by your application. Render ComposerDictation only when the feature is available to the user.readonly, disabled, invalid, and sending describe the field state; labels can be localized with localeText.aria-label.localeText and suggestion content through your entity labels or the suggestion slot.