-
Notifications
You must be signed in to change notification settings - Fork 168
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
Showing
9 changed files
with
223 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<template> | ||
<div> | ||
<command-button | ||
tooltip="Image" | ||
icon="image" | ||
@click.native="imageUploadDialogVisible = true" | ||
/> | ||
|
||
<el-dialog title="Upload image" :visible.sync="imageUploadDialogVisible"> | ||
<el-upload | ||
:http-request="uploadImage" | ||
:show-file-list="false" | ||
class="image-upload" | ||
action="#" | ||
drag | ||
accept="image/*" | ||
> | ||
<div class="image-upload__icon"> | ||
<i class="fa fa-upload" /> | ||
</div> | ||
<div class="el-upload__text"> | ||
Choose an image file or drag it here | ||
</div> | ||
</el-upload> | ||
</el-dialog> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { readFileDataUrl } from '@/utils/shared'; | ||
import CommandButton from './CommandButton'; | ||
export default { | ||
name: 'ImageUploadCommandButton', | ||
components: { | ||
CommandButton, | ||
}, | ||
props: { | ||
editorContext: { | ||
type: Object, | ||
required: true, | ||
}, | ||
}, | ||
data () { | ||
return { | ||
imageUploadDialogVisible: false, | ||
}; | ||
}, | ||
methods: { | ||
uploadImage (uploadOptions) { | ||
const { file } = uploadOptions; | ||
readFileDataUrl(file) | ||
.then((url) => { | ||
this.editorContext.commands.image({ src: url }); | ||
this.imageUploadDialogVisible = false; | ||
}); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style lang="scss"> | ||
.el-upload { | ||
display: flex; | ||
width: 100%; | ||
.el-upload-dragger { | ||
align-items: center; | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
justify-content: center; | ||
height: 300px; | ||
width: auto; | ||
.image-upload__icon { | ||
font-size: 50px; | ||
margin-bottom: 10px; | ||
} | ||
&:hover { | ||
.image-upload__icon { | ||
color: #409EFF; | ||
} | ||
} | ||
} | ||
} | ||
</style> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { Image as TiptapImage } from 'tiptap-extensions'; | ||
import { NodeSelection } from 'prosemirror-state'; | ||
|
||
export default class Image extends TiptapImage { | ||
get schema () { | ||
return { | ||
inline: true, | ||
attrs: { | ||
src: { | ||
default: '', | ||
}, | ||
alt: { | ||
default: '', | ||
}, | ||
title: { | ||
default: '', | ||
}, | ||
width: { | ||
default: null, | ||
}, | ||
height: { | ||
default: null, | ||
}, | ||
}, | ||
group: 'inline', | ||
draggable: true, | ||
parseDOM: [{ | ||
tag: 'img[src]', | ||
getAttrs: dom => { | ||
const width = dom.getAttribute('width') || dom.style.width; | ||
const height = dom.getAttribute('height') || dom.style.height; | ||
|
||
return { | ||
src: dom.getAttribute('src'), | ||
title: dom.getAttribute('title'), | ||
alt: dom.getAttribute('alt'), | ||
width: parseInt(width, 10), | ||
height: parseInt(height, 10), | ||
}; | ||
}, | ||
} ], | ||
toDOM: node => ['img', node.attrs], | ||
}; | ||
} | ||
|
||
get view () { | ||
return { | ||
name: 'ImageView', | ||
|
||
template: ` | ||
<span | ||
:class="{ 'image-view--focused': selected }" | ||
class="image-view" | ||
@click="handleImageViewClick" | ||
> | ||
<img | ||
:src="node.attrs.src" | ||
:title="node.attrs.title" | ||
:alt="node.attrs.alt" | ||
:width="node.attrs.width" | ||
:height="node.attrs.height" | ||
> | ||
</span> | ||
`, | ||
|
||
props: ['node', 'view', 'getPos', 'selected'], | ||
|
||
methods: { | ||
// https://github.com/scrumpy/tiptap/issues/361#issuecomment-540299541 | ||
handleImageViewClick () { | ||
let tr = this.view.state.tr; | ||
const pos = this.getPos(); | ||
let pos1 = this.view.state.doc.resolve(pos); | ||
let selection = new NodeSelection(pos1); | ||
tr.setSelection(selection); | ||
this.view.dispatch(tr); | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
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
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