Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -11,7 +11,21 @@ import { useAtom, useAtomValue } from 'jotai';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { EventType, IContent, MsgType, RelationType, Room } from 'matrix-js-sdk';
|
||||
import { Transforms, Editor } from 'slate';
|
||||
import { Box, Dialog, IconButton, Line, Overlay, OverlayBackdrop, OverlayCenter, PopOut, Scroll, Text, color, config, toRem } from 'folds';
|
||||
import {
|
||||
Box,
|
||||
Dialog,
|
||||
IconButton,
|
||||
Line,
|
||||
Overlay,
|
||||
OverlayBackdrop,
|
||||
OverlayCenter,
|
||||
PopOut,
|
||||
Scroll,
|
||||
Text,
|
||||
color,
|
||||
config,
|
||||
toRem,
|
||||
} from 'folds';
|
||||
|
||||
import { Icon, Icons } from '../../components/icons';
|
||||
import { useMatrixClient } from '../../hooks/useMatrixClient';
|
||||
@@ -43,12 +57,7 @@ import {
|
||||
} from '../../components/editor';
|
||||
import { EmojiBoard, EmojiBoardTab } from '../../components/emoji-board';
|
||||
import { UseStateProvider } from '../../components/UseStateProvider';
|
||||
import {
|
||||
TUploadContent,
|
||||
getImageInfo,
|
||||
getMxIdLocalPart,
|
||||
mxcUrlToHttp,
|
||||
} from '../../utils/matrix';
|
||||
import { TUploadContent, getImageInfo, getMxIdLocalPart, mxcUrlToHttp } from '../../utils/matrix';
|
||||
import { useTypingStatusUpdater } from '../../hooks/useTypingStatusUpdater';
|
||||
import { useFilePicker } from '../../hooks/useFilePicker';
|
||||
import { useFilePasteHandler } from '../../hooks/useFilePasteHandler';
|
||||
@@ -85,7 +94,12 @@ import {
|
||||
getImageMsgContent,
|
||||
getVideoMsgContent,
|
||||
} from './msgContent';
|
||||
import { getMemberDisplayName, getMentionContent, trimReplyFromBody } from '../../utils/room';
|
||||
import {
|
||||
getMemberDisplayName,
|
||||
getMentionContent,
|
||||
trimReplyFromBody,
|
||||
getMemberAvatarMxc,
|
||||
} from '../../utils/room';
|
||||
import { CommandAutocomplete } from './CommandAutocomplete';
|
||||
import { Command, SHRUG, TABLEFLIP, UNFLIP, useCommands } from '../../hooks/useCommands';
|
||||
import { pluginRegistry } from '../settings/plugins/PluginAPI';
|
||||
@@ -105,7 +119,6 @@ import { useRoomCreatorsTag } from '../../hooks/useRoomCreatorsTag';
|
||||
import { usePowerLevelTags } from '../../hooks/usePowerLevelTags';
|
||||
import { useComposingCheck } from '../../hooks/useComposingCheck';
|
||||
import { useOtherUserColor } from '../../hooks/useUserColor';
|
||||
import { getMemberAvatarMxc } from '../../utils/room';
|
||||
import { convertEmoticons, convertEmoticonsInHtml } from '../../utils/emoticonConverter';
|
||||
import * as css from './RoomInput.css';
|
||||
|
||||
@@ -151,7 +164,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
replyPreviewHighlightClassName,
|
||||
onMessageSent,
|
||||
},
|
||||
ref
|
||||
ref,
|
||||
) => {
|
||||
const mx = useMatrixClient();
|
||||
const useAuthentication = useMediaAuthentication();
|
||||
@@ -179,7 +192,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
const accessibleTagColors = useAccessiblePowerTagColors(
|
||||
theme.kind,
|
||||
creatorsTag,
|
||||
powerLevelTags
|
||||
powerLevelTags,
|
||||
);
|
||||
|
||||
// Get custom user color from avatar metadata
|
||||
@@ -191,13 +204,14 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
: undefined;
|
||||
// Priority: custom user color > legacy/direct colorMXID > tag color
|
||||
const replyUsernameColor =
|
||||
replyCustomColor ?? (legacyUsernameColor || direct ? colorMXID(replyUserID ?? '') : replyPowerColor);
|
||||
replyCustomColor ??
|
||||
(legacyUsernameColor || direct ? colorMXID(replyUserID ?? '') : replyPowerColor);
|
||||
|
||||
const [uploadBoard, setUploadBoard] = useState(true);
|
||||
const [selectedFiles, setSelectedFiles] = useAtom(roomIdToUploadItemsAtomFamily(roomId));
|
||||
const uploadFamilyObserverAtom = createUploadFamilyObserverAtom(
|
||||
roomUploadAtomFamily,
|
||||
selectedFiles.map((f) => f.file)
|
||||
selectedFiles.map((f) => f.file),
|
||||
);
|
||||
const uploadBoardHandlers = useRef<UploadBoardImperativeHandlers>();
|
||||
const editorRef = useRef<HTMLDivElement>(null);
|
||||
@@ -218,7 +232,9 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
useEffect(() => {
|
||||
setCommandValidator((commandName: string) => {
|
||||
const isBuiltInCommand = commands[commandName as Command];
|
||||
const isPluginCommand = pluginRegistry.getCommands().some(cmd => cmd.name === commandName);
|
||||
const isPluginCommand = pluginRegistry
|
||||
.getCommands()
|
||||
.some((cmd) => cmd.name === commandName);
|
||||
return !!(isBuiltInCommand || isPluginCommand);
|
||||
});
|
||||
}, [commands]);
|
||||
@@ -229,7 +245,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
setUploadBoard(true);
|
||||
await enqueueFiles(files);
|
||||
},
|
||||
[enqueueFiles]
|
||||
[enqueueFiles],
|
||||
);
|
||||
const pickFile = useFilePicker(handleFiles, true);
|
||||
const handlePaste = useFilePasteHandler(handleFiles);
|
||||
@@ -252,7 +268,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
resetEditor(editor);
|
||||
resetEditorHistory(editor);
|
||||
},
|
||||
[roomId, editor, setMsgDraft]
|
||||
[roomId, editor, setMsgDraft],
|
||||
);
|
||||
|
||||
const handleFileMetadata = useCallback(
|
||||
@@ -263,7 +279,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
replacement: { ...fileItem, metadata },
|
||||
});
|
||||
},
|
||||
[setSelectedFiles]
|
||||
[setSelectedFiles],
|
||||
);
|
||||
|
||||
const handleRemoveUpload = useCallback(
|
||||
@@ -275,7 +291,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
});
|
||||
uploads.forEach((u) => roomUploadAtomFamily.remove(u));
|
||||
},
|
||||
[setSelectedFiles, selectedFiles]
|
||||
[setSelectedFiles, selectedFiles],
|
||||
);
|
||||
|
||||
const handleCancelUpload = (uploads: Upload[]) => {
|
||||
@@ -294,7 +310,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
});
|
||||
const carouselUuid = imageUploads.length > 1 ? createCarouselUuid() : undefined;
|
||||
const imageUploadIndexByFile = new Map(
|
||||
imageUploads.map((upload, index) => [upload.file, index] as const)
|
||||
imageUploads.map((upload, index) => [upload.file, index] as const),
|
||||
);
|
||||
|
||||
const contentsPromises = uploads.map(async (upload) => {
|
||||
@@ -314,7 +330,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
index: imageIndex,
|
||||
total: imageUploads.length,
|
||||
}
|
||||
: undefined
|
||||
: undefined,
|
||||
);
|
||||
}
|
||||
if (fileItem.file.type.startsWith('video')) {
|
||||
@@ -340,7 +356,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
allowTextFormatting: true,
|
||||
allowBlockMarkdown: isMarkdown,
|
||||
allowInlineMarkdown: isMarkdown,
|
||||
})
|
||||
}),
|
||||
);
|
||||
let msgType = MsgType.Text;
|
||||
|
||||
@@ -351,8 +367,10 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
const potentialCommand = match[1];
|
||||
// Check if it's a valid command (built-in or plugin)
|
||||
const isBuiltInCommand = commands[potentialCommand as Command];
|
||||
const isPluginCommand = pluginRegistry.getCommands().some(cmd => cmd.name === potentialCommand);
|
||||
|
||||
const isPluginCommand = pluginRegistry
|
||||
.getCommands()
|
||||
.some((cmd) => cmd.name === potentialCommand);
|
||||
|
||||
if (isBuiltInCommand || isPluginCommand) {
|
||||
commandName = potentialCommand;
|
||||
}
|
||||
@@ -459,7 +477,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
'm.in_reply_to': { event_id: inReplyToEventId },
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Process message through plugin interceptors
|
||||
try {
|
||||
const messageContext = {
|
||||
@@ -470,7 +488,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
metadata: {},
|
||||
};
|
||||
const processedContext = await pluginRegistry.processBeforeSend(messageContext);
|
||||
|
||||
|
||||
// Update content with intercepted values
|
||||
content.body = processedContext.content;
|
||||
if (processedContext.formatted) {
|
||||
@@ -479,7 +497,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
} catch (err) {
|
||||
console.error('[RoomInput] Plugin interceptor error:', err);
|
||||
}
|
||||
|
||||
|
||||
mx.sendMessage(roomId, content as any);
|
||||
resetEditor(editor);
|
||||
resetEditorHistory(editor);
|
||||
@@ -487,7 +505,20 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
setCommandHint(undefined);
|
||||
sendTypingStatus(false);
|
||||
onMessageSent?.();
|
||||
}, [mx, roomId, threadRootId, threadReplyToEventId, editor, replyDraft, sendTypingStatus, setReplyDraft, isMarkdown, commands, autoConvertEmoticons, onMessageSent]);
|
||||
}, [
|
||||
mx,
|
||||
roomId,
|
||||
threadRootId,
|
||||
threadReplyToEventId,
|
||||
editor,
|
||||
replyDraft,
|
||||
sendTypingStatus,
|
||||
setReplyDraft,
|
||||
isMarkdown,
|
||||
commands,
|
||||
autoConvertEmoticons,
|
||||
onMessageSent,
|
||||
]);
|
||||
|
||||
const handleKeyDown: KeyboardEventHandler = useCallback(
|
||||
(evt) => {
|
||||
@@ -511,7 +542,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
setReplyDraft(undefined);
|
||||
}
|
||||
},
|
||||
[submit, setReplyDraft, enterForNewline, autocompleteQuery, isComposing, commandHint]
|
||||
[submit, setReplyDraft, enterForNewline, autocompleteQuery, isComposing, commandHint],
|
||||
);
|
||||
|
||||
const handleKeyUp: KeyboardEventHandler = useCallback(
|
||||
@@ -534,12 +565,12 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
// Check if user is typing a command and show hint
|
||||
const plainText = toPlainText(editor.children, false).trim();
|
||||
const commandMatch = plainText.match(/^\/(\w+)(\s|$)/);
|
||||
|
||||
|
||||
if (commandMatch) {
|
||||
const commandName = commandMatch[1];
|
||||
const builtInCmd = commands[commandName as Command];
|
||||
const pluginCmd = pluginRegistry.getCommands().find(cmd => cmd.name === commandName);
|
||||
|
||||
const pluginCmd = pluginRegistry.getCommands().find((cmd) => cmd.name === commandName);
|
||||
|
||||
if (builtInCmd) {
|
||||
setCommandHint({
|
||||
command: commandName,
|
||||
@@ -558,7 +589,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
setCommandHint(undefined);
|
||||
}
|
||||
},
|
||||
[editor, sendTypingStatus, hideActivity, commands]
|
||||
[editor, sendTypingStatus, hideActivity, commands],
|
||||
);
|
||||
|
||||
const handleCloseAutocomplete = useCallback(() => {
|
||||
@@ -577,7 +608,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
|
||||
const info = await getImageInfo(
|
||||
await loadImageElement(stickerUrl),
|
||||
await getImageUrlBlob(stickerUrl)
|
||||
await getImageUrlBlob(stickerUrl),
|
||||
);
|
||||
|
||||
mx.sendEvent(roomId, EventType.Sticker, {
|
||||
@@ -705,7 +736,10 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
<Text size="T200" priority="400">
|
||||
<b>/{commandHint.command}</b>
|
||||
{commandHint.args && commandHint.args.length > 0 && (
|
||||
<span style={{ opacity: 0.6 }}> {commandHint.args.map(arg => `[${arg}]`).join(' ')}</span>
|
||||
<span style={{ opacity: 0.6 }}>
|
||||
{' '}
|
||||
{commandHint.args.map((arg) => `[${arg}]`).join(' ')}
|
||||
</span>
|
||||
)}
|
||||
</Text>
|
||||
{commandHint.description && (
|
||||
@@ -738,7 +772,9 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
className={replyPreviewHighlightClassName}
|
||||
>
|
||||
{!hideReplyThreadIndicator &&
|
||||
replyDraft.relation?.rel_type === RelationType.Thread && <ThreadIndicator />}
|
||||
replyDraft.relation?.rel_type === RelationType.Thread && (
|
||||
<ThreadIndicator />
|
||||
)}
|
||||
<ReplyLayout
|
||||
userColor={replyUsernameColor}
|
||||
username={
|
||||
@@ -794,7 +830,7 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
anchor={
|
||||
emojiBoardTab === undefined
|
||||
? undefined
|
||||
: emojiBtnRef.current?.getBoundingClientRect() ?? undefined
|
||||
: (emojiBtnRef.current?.getBoundingClientRect() ?? undefined)
|
||||
}
|
||||
content={
|
||||
<EmojiBoard
|
||||
@@ -851,5 +887,5 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user