mirror of
https://github.com/harness/drone.git
synced 2025-05-20 10:59:56 +08:00
feat: [code-1316]: add video support in comment box (#965)
This commit is contained in:
parent
123267c918
commit
634a70a833
@ -79,6 +79,7 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
|
|||||||
const { getString } = useStrings()
|
const { getString } = useStrings()
|
||||||
const view = useRef<EditorView>()
|
const view = useRef<EditorView>()
|
||||||
const ref = useRef<HTMLDivElement>()
|
const ref = useRef<HTMLDivElement>()
|
||||||
|
const [fileData, setFile] = useState<File>()
|
||||||
|
|
||||||
const languageConfig = useMemo(() => new Compartment(), [])
|
const languageConfig = useMemo(() => new Compartment(), [])
|
||||||
const [markdownContent, setMarkdownContent] = useState('')
|
const [markdownContent, setMarkdownContent] = useState('')
|
||||||
@ -103,7 +104,7 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
|
|||||||
const updateContentWithoutStateChange = () => {
|
const updateContentWithoutStateChange = () => {
|
||||||
setUploading(true)
|
setUploading(true)
|
||||||
if (view.current && markdownContent && !inGitBlame) {
|
if (view.current && markdownContent && !inGitBlame) {
|
||||||
const markdownInsert = ``
|
const markdownInsert = fileData?.type.startsWith('image/') ? `` : `${markdownContent}`
|
||||||
const range = view.current.state.selection.main
|
const range = view.current.state.selection.main
|
||||||
const cursorPos = range.from
|
const cursorPos = range.from
|
||||||
const newCursorPos = cursorPos + markdownInsert.length
|
const newCursorPos = cursorPos + markdownInsert.length
|
||||||
@ -206,6 +207,7 @@ export const Editor = React.memo(function CodeMirrorReactEditor({
|
|||||||
}, [filename, forMarkdown, view, languageConfig, markdownLanguageSupport])
|
}, [filename, forMarkdown, view, languageConfig, markdownLanguageSupport])
|
||||||
const handleUploadCallback = (file: File) => {
|
const handleUploadCallback = (file: File) => {
|
||||||
if (!inGitBlame) {
|
if (!inGitBlame) {
|
||||||
|
setFile(file)
|
||||||
handleUpload(file, setMarkdownContent, repoMetadata, showError, standalone, routingId)
|
handleUpload(file, setMarkdownContent, repoMetadata, showError, standalone, routingId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,7 @@ export function MarkdownEditorWithPreview({
|
|||||||
}
|
}
|
||||||
|
|
||||||
case ToolbarAction.UPLOAD: {
|
case ToolbarAction.UPLOAD: {
|
||||||
|
setFile(undefined)
|
||||||
setOpen(true)
|
setOpen(true)
|
||||||
|
|
||||||
break
|
break
|
||||||
@ -303,7 +304,7 @@ export function MarkdownEditorWithPreview({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const view = viewRef.current
|
const view = viewRef.current
|
||||||
if (markdownContent && view) {
|
if (markdownContent && view) {
|
||||||
const insertText = ``
|
const insertText = file?.type.startsWith('image/') ? `` : `${markdownContent}`
|
||||||
view.dispatch(
|
view.dispatch(
|
||||||
view.state.changeByRange(range => ({
|
view.state.changeByRange(range => ({
|
||||||
changes: [{ from: range.from, insert: insertText }],
|
changes: [{ from: range.from, insert: insertText }],
|
||||||
@ -384,7 +385,6 @@ export function MarkdownEditorWithPreview({
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
handleUpload(file as File, setMarkdownContent, repoMetadata, showError, standalone, routingId)
|
handleUpload(file as File, setMarkdownContent, repoMetadata, showError, standalone, routingId)
|
||||||
setOpen(false)
|
setOpen(false)
|
||||||
setFile(undefined)
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
|
@ -852,7 +852,7 @@ enterBitbucketPlaceholder: https://bitbucket.org/
|
|||||||
changeRepoVis: Change repository visibility
|
changeRepoVis: Change repository visibility
|
||||||
changeRepoVisContent: Are you sure you want to make this repository {repoVis}? {repoText}
|
changeRepoVisContent: Are you sure you want to make this repository {repoVis}? {repoText}
|
||||||
repoVisibility: Repository Visibility
|
repoVisibility: Repository Visibility
|
||||||
attachText: Attach images by dragging & dropping, selecting or pasting them.
|
attachText: Attach images & videos by dragging & dropping, selecting or pasting them.
|
||||||
key: Key
|
key: Key
|
||||||
setting: Setting
|
setting: Setting
|
||||||
mergeCommit: Merge commit
|
mergeCommit: Merge commit
|
||||||
|
@ -258,7 +258,7 @@ export const handlePaste = (event: { preventDefault: () => void; clipboardData:
|
|||||||
|
|
||||||
if (items.length > 0) {
|
if (items.length > 0) {
|
||||||
const firstItem = items[0]
|
const firstItem = items[0]
|
||||||
if (firstItem.type.startsWith('image/')) {
|
if (firstItem.type.startsWith('image/') || firstItem.type.startsWith('video/')) {
|
||||||
const blob = firstItem.getAsFile()
|
const blob = firstItem.getAsFile()
|
||||||
callback(blob)
|
callback(blob)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user