-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yaoshun01
committed
Nov 27, 2024
1 parent
f8621b3
commit 8ad7471
Showing
26 changed files
with
1,929 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
react/src/YXUIKit/im-kit-ui/src/chat/components/ChatMessageInput/useImgPaste.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React, { useCallback, MutableRefObject } from 'react' | ||
|
||
interface useImgPasteProps { | ||
focus?: boolean | ||
textareaRef?: MutableRefObject<HTMLTextAreaElement | undefined> | ||
onSendImg: (file: File) => void | ||
} | ||
|
||
export const useImgPaste = (props: useImgPasteProps) => { | ||
const { textareaRef, onSendImg } = props | ||
|
||
const handleImgPaste = useCallback( | ||
async (e: React.ClipboardEvent | any) => { | ||
if (!(e.clipboardData && e.clipboardData.items)) { | ||
return | ||
// 右键粘贴 | ||
} else if (e.clipboardData.files.length) { | ||
if (e.clipboardData.files[0].type.match(/^image\//i)) { | ||
return onSendImg && onSendImg(e.clipboardData.files[0]) | ||
} | ||
} | ||
|
||
const { types, items } = e.clipboardData | ||
|
||
types.find((type, index) => { | ||
const item = items[index] | ||
|
||
switch (type) { | ||
case 'Files': { | ||
const file = item.getAsFile() | ||
|
||
if (item && item.kind === 'file' && item.type.match(/^image\//i)) { | ||
onSendImg && onSendImg(file) | ||
} | ||
|
||
return true | ||
} | ||
|
||
default: | ||
return true | ||
} | ||
}) | ||
}, | ||
[textareaRef, onSendImg] | ||
) | ||
|
||
return { | ||
handleImgPaste, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.