Git Product home page Git Product logo

element-tiptap-vue3's Introduction

ElTiptap logo

npm GitHub Release Date npm peer dependency version semantic-release GitHub

Element Tiptap Editor

A WYSIWYG rich-text editor using tiptap and Element Plus for Vue3

that's easy to use, friendly to developers, fully extensible and clean in design.

It' s version of alpha tiptap 2.0.1 with fixed bugs and repaire previous functionality. Also deleted most warns in console while using.

It' s final version of lib i fixed all bugs, which i saw, welcome issues if you found bugs or warnings, i will try to fix it.

I only done fix bugs and corrected some extentions and delete warnings original

if you are Russian company you can refer me job ([email protected])

English

🎄 Demo

👾Code Sandbox

✨ Features

  • 🎨Use element-plus components
  • 💅Many out of box extensions (welcome to submit an issue for feature request👏)
  • 🔖Markdown support
  • 📘TypeScript support
  • 🌐I18n support(en, zh, pl, ru, de, ko, es, zh_tw, fr, pt_br, nl, he). welcome to contribute more languages
  • 🎈Events you might use: create, transaction, focus, blur, destroy
  • 🍀Fully extensible, you can customize editor extension and its menu button view
  • 💻Also can control the behavior of the editor directly, customize the editor for yourself.

📦 Installation

NPM

npm i element-tiptap-vue3-fixed

Install plugin

import { createApp } from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus';
import ElementTiptapPlugin from 'element-tiptap-vue3-fixed';
// import ElementTiptap's styles
import 'element-tiptap-vue3-fixed/lib/style.css';

const app = createApp(App);

// use ElementPlus's plugin
app.use(ElementPlus);
// use this package's plugin
app.use(ElementTiptapPlugin);
// Now you register `'el-tiptap'` component globally.

app.mount('#app');

Or

Partial import

<template>
  <el-tiptap ...></el-tiptap>
</template>

<script setup>
import { ElementTiptap } from 'element-tiptap-vue3-fixed';
</script>

🚀 Usage

<template>
  <el-tiptap v-model:content="content" :extensions="extensions" />
</template>

<script setup>
import { ref } from 'vue';
import {
  // necessary extensions
  Doc,
  Text,
  Paragraph,
  //________________________
  Heading,
  Bold,
  Underline,
  Italic,
  Strike,
  BulletList,
  OrderedList,
} from 'element-tiptap-vue3-fixed';

// editor extensions
// they will be added to menubar and bubble menu by the order you declare.
const extensions = [
  Doc,
  Text,
  Paragraph,
  Heading.configure({ level: 5 }),
  Bold.configure({ bubble: true }), // render command-button in bubble menu.
  Underline.configure({ bubble: true, menubar: false }), // render command-button in bubble menu but not in menubar.
  Italic,
  Strike,
  BulletList,
  OrderedList,
];

// editor's content
const content = ref(`
  <h1>Heading</h1>
  <p>This Editor is awesome!</p>
`);
</script>

📔 Props

extensions

Type: Array

You can use the necessary extensions. The corresponding command-buttons will be added by declaring the order of the extension.

All available extensions:

  • Doc
  • Text
  • Paragraph
  • Heading
  • Bold
  • Italic
  • Strike
  • Underline
  • Link
  • Image
  • Iframe
  • CodeBlock
  • Blockquote
  • BulletList
  • OrderedList
  • TaskList
  • TextAlign
  • Indent
  • LineHeight
  • HorizontalRule
  • HardBreak
  • History
  • Table
  • FormatClear
  • Color
  • Highlight
  • Print
  • Fullscreen
  • SelectAll
  • FontFamily
  • FontSize
  • CodeView
  • CodeBlockLowlight
  • Gapcursor
  • Dropcursor
  • Commands

You can find all extensions docs here.

Addendum to the link above

Extension: Commands

Usage

import {
  ...
  Commands,
  getSuggestionItems,
  renderItems
} from 'element-tiptap-vue3-fixed';

Commands.configure({
  suggestion: {
    items: getSuggestionItems,
    render: renderItems
  }
}),

Extension: All

Custom svg for extensions

 Image.configure({
    buttonIcon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" height="16" width="16" fill="currentColor"> ... </svg>'
 })

for (Indent, History) ['swg', 'swg'] for (TextAlign) ['swg', 'swg', 'swg', 'swg']

.. pull-quote:: Warning

NB: Although the buttonIcon attribute supports incoming HTML fragments, it is very dangerous to dynamically render arbitrary HTML on the website, because it is easy to cause XSS attack. Please make sure that the content of buttonIcon is trustworthy. Never assign user-submitted content to the buttonIcon attribute.

Extention: Image

Insert images with original width

 Image.configure({
    defaultWidth: null
  })

Insert images with width: 400px

 Image.configure({
    defaultWidth: 400
  })

Dragging images (tests) adding button which allow to move images

 Image.configure({
    draggable: true
  })

Extention: Link

placeholder

  Link.configure({ 
    addLinkPlaceholder: 'add link', // placeholder for adding link
    editLinkPlaceholder: 'edit link' // placeholder for editing link
  }),

You can customize the extension. See [Custom extensions](https://tiptap.dev/guide/custom-extensions).
### Example custom extension
```vue
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight';
import {
  Editor
} from '@tiptap/core';
import { CommandButton } from 'element-tiptap-vue3-fixed';

export default CodeBlockLowlight.extend({
  addOptions() {
    return {
      ...this.parent?.(),
      button({ editor, t }: { editor: Editor; t: (...args: any[]) => string }) {
        return {
          component: CommandButton, // component of button which is used in menubar or bubblemenu (u can write your own component of button)
          componentProps: { // props is used in component
            command: () => { // command on click button
              editor.commands.toggleCodeBlock();
            },
            // WARNING buttonIcon attribute supports incoming HTML fragments, it is very dangerous to dynamically render arbitrary HTML on the website, because it is easy to cause XSS attack.
            buttonIcon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" height="16" width="16" fill="currentColor"> ... </svg>', // your custom svg, if there is not uses default
            isActive: editor.isActive('codeBlock'),
            icon: 'code', // name of element-tiptap icon (don't customized)
            tooltip: t('editor.extensions.CodeBlock.tooltip'),
          },
        };
      },
    };
  },
});

setContent

<el-tiptap ref="editor" />
this.$refs.editor.setContent(Content); 
can do reactive, but history brokes so add this function, to change content if necessary.

placeholder

Type: string

Default: ''

When editor is empty, placeholder will display.

<el-tiptap placeholder="Write something …" />

content

Type: object for output json

Default: ''

Type: string for output html

Default: ''

Editor's content

<el-tiptap :content="content" @onUpdate="onEditorUpdate" />

or Use 'v-model'

<el-tiptap v-model:content="content" />

output

Type: string

Default: 'html'

Output can be defined to 'html' or 'json'.

<el-tiptap output="json" />

further reading: prosemirror data structure

readonly

Type: boolean

Default: false

<el-tiptap readonly />

when readonly is true, editor is not editable.

spellcheck

Type: boolean

Default: false

<el-tiptap spellcheck> </el-tiptap>

Whether the content is spellcheck enabled.

editorProps

Type: Object

Default: {}

<el-tiptap :editorProps="{handlePaste: ...}"> </el-tiptap>

about editorProps

width, height

Type: string | number

A string value with unit or a simple value (the default unit is px):

<el-tiptap :width="700" height="100%"> </el-tiptap>

The above example will be converted to:

width: 700px;
height: 100%;

enableCharCount

Type: boolean

Default: true

Enables or disables the display of the character counter.

tooltip

Type: boolean

Default: true

Control if tooltips are shown when getting with mouse over the buttons from the toolbar.

locale

Specifies the editor i18n language.

<template>
  <el-tiptap :lang="en"></el-tiptap>
</template>

<script setup>
import { ElementTiptap } from 'element-tiptap-vue3-fixed';
import en from 'element-tiptap-vue3-fixed/lib/locales/en';
</script>

Available languages:

  • en(default)
  • zh
  • pl by @FurtakM
  • ru by @baitkul
  • de by @Thesicstar
  • ko by @Hotbrains
  • es by @koas
  • zh_tw by @eric0324
  • fr by @LPABelgium
  • pt_br by @valterleonardo
  • nl by @Arne-Jan
  • he by @shovalPMS

Welcome contribution.

👽 Events

onCreate

<template>
  <el-tiptap @onCreate="onCreate" />
</template>

<script setup>
/**
 * the tiptap editor instance
 * see https://tiptap.dev/api/editor
 */
const onCreate = ({ editor }) => {
  // ...
};
</script>

onTransaction, onFocus, onBlur, onDestroy

The same as onCreate

🏗 Contributing

Please see CONTRIBUTING for details.

📄 License

MIT

element-tiptap-vue3's People

Contributors

okijhhyu avatar snyk-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

element-tiptap-vue3's Issues

Slash Command

The "Slash Command" has become more popular, with the ease of typing a simple "/" character to show a list of command suggestion. I wonder if you can add that as an extension. Tiptap is also looking to add that as an extension as well so it would be nice if this editor can support Slash Command
Describe the solution you'd like
I want a drop down list of commands shown to me when I type "/" in the editor. I also can search for command by typing commands alias. For example, if I type "/big heading", the command to set heading to level 1 shown up. I can choose this command by either click on it or hit the "Enter" key.

使用element-tiptap-vue3,选中文本内容,然后设置h1,h2,h3标题不起作用,看不到字号大小变化

我的解决思路:
(1)这个组件用了富文本编辑器,就把这个组件里把style 里的 scpoed 去掉 【最主要是这个原因】
(2)在浏览器开发者工具里,找编辑器自带的为h标题设置的样式,自己修改字号
`<style>

/*找到的,我加了个 font-weight:bold; */
.el-tiptap-editor__content h1,
.el-tiptap-editor__content h2,
.el-tiptap-editor__content h3,
.el-tiptap-editor__content h4,
.el-tiptap-editor__content h5 {
margin-top: 20px;
margin-bottom: 20px;
font-weight: bold;
}

.el-tiptap-editor__content h1 {
font-size: 24px;
}

.el-tiptap-editor__content h2 {
font-size: 22px;
}
.el-tiptap-editor__content h2 {
font-size: 20px;
}

<style>`

I want to extend the existing Link dialog form

作者你好,我有个问题想要请教一下。
我现在想要写一个自定义的"Link"标签,我想基于项目中的Link弹框进行拓展,例如我想在menu里面点击就支持Link 的text、href的编辑
以及想增加一个下拉框,实现拼接参数在Link的href链接后面
我该如何自定义这个插件,项目里面我并没有看到相关的例子。
总结来说,我想拓展原有的Link弹窗表单

Hello, author. I have a question I'd like to ask.
I want to create a custom "Link" tag now, and I'd like to extend it based on the project's Link dialog. For example, I want to support editing the text and href of the Link by clicking on it in the menu. Additionally, I'd like to add a dropdown menu to append parameters to the href link of the Link.
How can I customize this plugin? I haven't found any relevant examples in the project.
In summary, I want to extend the existing Link dialog form.

paste image event

Hello author, can you add a paste image event? As the format of the paste image is base64, I would like to upload the paste image to a remote server.

Fix bugs

Use element-plus params in styles, test uploader link in images.

About `FontFamily` configuration issues

I‘m Chinese and my English is very poor. This is machine translated content, please forgive me.
In the FontFamily configuration of extensions, according to the description of d. ts, there is only a types attribute and the value is a string []。
image
However, in reality, in the element-tiptap-vue3- fixed. es.js file, in the _ sfc_main$4 component, in the computed attribute, function fontFaimlies return fontFamilyOptions.fontFamilyMap. If following the instructions in d. ts, it should return fontFamilyOptions.types.
image

Weird behaviour when setting height

Hello! First of all HUGE THANK YOU for fixing the original project.. it was such a pain to find a nice version of tiptap that already has all the icons working in the menubar that doesn't force you to use something like Quasar Framework.

Your version works amazing!! Big thanks for your initiative!

I noticed that when setting the width and height like this:


  <el-tiptap
    lang="en"
    ref="editor"
    output="html"
    :extensions="allExtensions"
    v-model:content="content"
    width="100%"
    height="50vh"
  />

The editor appears to grow in height, however when you try to focus inside the blank space to start writing.. it will not allow you to click on most of the blank space.. it only works if you click near the top.. unsure what is going on.. it's like the outer editor grows in height but not the inner editor.

Would be great if you could fix this! : )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.