Tiptap Dropcursor 扩展,当你在编辑器里面拖拽一个对象比如图片时,它显示一个光标要拖拽到的位置。
npm install @tiptap/extension-dropcursor
color 光栅Dropcursor的颜色。
Dropcursor.configure({
color: '#ff0000',
})
width 光栅Dropcursor的宽度
Dropcursor.configure({
width: 2,
})
class 自定义样式
Dropcursor.configure({
class: 'my-custom-class',
})
Vue 例子
React 例子
React CSS
<template>
<editor-content :editor="editor" />
</template>
<script>
import Document from '@tiptap/extension-document'
import Dropcursor from '@tiptap/extension-dropcursor'
import Image from '@tiptap/extension-image'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { Editor, EditorContent } from '@tiptap/vue-3'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
Document,
Paragraph,
Text,
Image,
Dropcursor,
],
content: `
<p>拖动下面的图片试试看</p>
<img src="https://www.itxst.com/img/logov31.png" />
`,
})
},
beforeUnmount() {
this.editor.destroy()
},
}
</script>
<style>
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
img {
max-width: 100%;
height: auto;
}
}
</style>
import './styles.scss'
import Document from '@tiptap/extension-document'
import Dropcursor from '@tiptap/extension-dropcursor'
import Image from '@tiptap/extension-image'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
import { EditorContent, useEditor } from '@tiptap/react'
import React from 'react'
export default () => {
const editor = useEditor({
extensions: [Document, Paragraph, Text, Image, Dropcursor],
content: `
<p>拖动图片试试看</p>
<img src="https://www.itxst.com/img/logov31.png" />
`,
})
return <EditorContent editor={editor} />
}
/* Basic editor styles */
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
img {
height: auto;
max-width: 100%;
}
}