1export function resolveComposerMenuActiveItemId(input: {
2 items: ReadonlyArray<{ id: string }>;
3 highlightedItemId: string | null;
4 currentSearchKey: string | null;
5 highlightedSearchKey: string | null;
6}): string | null {
7 if (input.items.length === 0) {
8 return null;
9 }
10
11 if (
12 input.currentSearchKey === input.highlightedSearchKey &&
13 input.highlightedItemId &&
14 input.items.some((item) => item.id === input.highlightedItemId)
15 ) {
16 return input.highlightedItemId;
17 }
18
19 return input.items[0]?.id ?? null;
20}
21
22export function composerEmojiKeyAction(
23 event: Pick<
24 KeyboardEvent,
25 "key" | "shiftKey" | "altKey" | "metaKey" | "ctrlKey" | "isComposing" | "keyCode"
26 >,
27): "select" | "next" | "previous" | "dismiss" | null {
28 if (event.isComposing || event.keyCode === 229) return null;
29 if (event.key === "Escape") return "dismiss";
30 if (event.shiftKey || event.altKey || event.metaKey || event.ctrlKey) return null;
31 if (event.key === "Enter" || event.key === "Tab") return "select";
32 if (event.key === "ArrowDown") return "next";
33 if (event.key === "ArrowUp") return "previous";
34 return null;
35}