Tiptap Dropcursor 拖动光标扩展

Tiptap Dropcursor 扩展,当你在编辑器里面拖拽一个对象比如图片时,它显示一个光标要拖拽到的位置。

Install 安装

npm install @tiptap/extension-dropcursor

Settings 配置

color 光栅Dropcursor的颜色。

Dropcursor.configure({
  color: '#ff0000',
})

width 光栅Dropcursor的宽度

Dropcursor.configure({
  width: 2,
})

class 自定义样式

Dropcursor.configure({
  class: 'my-custom-class',
})

源代码

dropcursor 源代码

在线例子

vue 在线例子

Dropcursor 例子

  • 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%;
  }
}

下载教程 Demo

本教程Demo的源码点击这里下载,Tiptap Demo,下载完成后运行npm i初始化依赖包。