Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/ui/content/docs/components/composer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ To extend the anatomy above, pass `triggers={triggers}` to `Composer` and insert
</ComposerPopup>
```

Configure only the triggers you need. Queries can contain spaces: `@sam r` finds Sam Rivera. A space immediately after the trigger closes the suggestions. By default, selecting an item inserts a token into the draft; it does not send the message or execute an action. Supply `onAction` to handle items with `type: "action"` as commands: Composer removes the active query and calls your handler without inserting a token or submitting. Your application owns execution.
Configure only the triggers you need. Queries can contain spaces: `@sam r` finds Sam Rivera. A space keeps the suggestions open only while a name continues past the word just typed, so `@sam ` still shows Sam Rivera, while `@sa ` and `@sam rivera ` close them. A space immediately after the trigger closes them too. By default, selecting an item inserts a token into the draft; it does not send the message or execute an action. Supply `onAction` to handle items with `type: "action"` as commands: Composer removes the active query and calls your handler without inserting a token or submitting. Your application owns execution.

To open a trigger from a button inside `ComposerActions`, call `useComposerContext().insertTrigger("@")` or `insertTrigger("/")`. The trigger is inserted at the caret and opens the same suggestions as typing it.

Expand All @@ -215,6 +215,14 @@ The default filter ignores case and accents. Set a trigger's `filter` to customi

<ComponentPreview name="p-composer-5" />

### People and tags

List people and tags apart: team members first, then contacts, then tags. Each person shows their tags next to their name, and a tag row mentions everyone who has that tag. Typing a tag name also lists its people, and once two or more letters start a tag’s name, the tag moves to the top so it is highlighted first.

To mention several people in a row, the list can stay open. Enter or a click mentions the highlighted row and closes the list; holding Shift while pressing Enter or clicking mentions it and keeps the list open on the same search. Escape then closes the list and removes the leftover query.

<ComponentPreview name="p-composer-13" />

### Emoji

Give an item `type: "text"` to replace the query with its `text` as ordinary characters, instead of inserting a token. This demo uses it for Slack-style emoji: typing `:thu` suggests 👍, and selecting it replaces `:thu` with the emoji and a space. The emoji is plain draft text, so backspace, copy, undo, and `getComposerText` treat it like any typed character.
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/public/r/composer-document.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/ui/public/r/composer-query.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"files": [
{
"path": "registry/default/lib/composer-query.ts",
"content": "export function getComposerQuery(\n text: string,\n caret: number,\n triggers: readonly string[],\n): { character: string; text: string; start: number; end: number } | null {\n let start = -1;\n let character = \"\";\n for (const trigger of triggers) {\n if (!trigger || trigger.length > caret) continue;\n const index = text.lastIndexOf(trigger, caret - trigger.length);\n if (index > start) {\n start = index;\n character = trigger;\n }\n }\n if (start < 0 || (start > 0 && !/\\s/u.test(text.charAt(start - 1))))\n return null;\n\n const beforeCaret = text.slice(start + character.length, caret);\n if (/^\\s/u.test(beforeCaret)) return null;\n if (!/^[\\p{L}\\p{M}\\p{N}\\p{Zs}_.’'-]*$/u.test(beforeCaret)) return null;\n\n // Complete the word at the caret without consuming subsequent prose.\n const suffix = /^[\\p{L}\\p{M}\\p{N}_.’'-]*/u.exec(text.slice(caret))?.[0] ?? \"\";\n return {\n character,\n text: (beforeCaret + suffix).replace(/\\p{Zs}+/gu, \" \").trim(),\n start,\n end: caret + suffix.length,\n };\n}\n",
"content": "export function getComposerQuery(\n text: string,\n caret: number,\n triggers: readonly string[],\n): {\n character: string;\n text: string;\n start: number;\n end: number;\n spaceAfter: boolean;\n} | null {\n let start = -1;\n let character = \"\";\n for (const trigger of triggers) {\n if (!trigger || trigger.length > caret) continue;\n const index = text.lastIndexOf(trigger, caret - trigger.length);\n if (index > start) {\n start = index;\n character = trigger;\n }\n }\n if (start < 0 || (start > 0 && !/\\s/u.test(text.charAt(start - 1))))\n return null;\n\n const beforeCaret = text.slice(start + character.length, caret);\n if (/^\\s/u.test(beforeCaret)) return null;\n if (!/^[\\p{L}\\p{M}\\p{N}\\p{Zs}_.’'-]*$/u.test(beforeCaret)) return null;\n\n // Complete the word at the caret without consuming subsequent prose.\n const suffix = /^[\\p{L}\\p{M}\\p{N}_.’'-]*/u.exec(text.slice(caret))?.[0] ?? \"\";\n return {\n character,\n text: (beforeCaret + suffix).replace(/\\p{Zs}+/gu, \" \").trim(),\n start,\n end: caret + suffix.length,\n spaceAfter: !suffix && /\\p{Zs}$/u.test(beforeCaret),\n };\n}\n\nexport function continuesPastQuery(label: string, query: string): boolean {\n const normalize = (text: string) =>\n text\n .normalize(\"NFD\")\n .replace(/\\p{M}/gu, \"\")\n .replace(/\\s+/gu, \" \")\n .toLocaleLowerCase();\n return ` ${normalize(label)}`.includes(` ${normalize(query)} `);\n}\n",
"type": "registry:lib"
}
],
Expand Down
2 changes: 1 addition & 1 deletion apps/ui/public/r/composer.json

Large diffs are not rendered by default.

Loading
Loading