mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-28 23:59:25 +08:00
add editorcontent component
This commit is contained in:
parent
a067259da1
commit
a580e257f5
@ -1,5 +1,7 @@
|
|||||||
import { Editor } from './src/Editor'
|
import { Editor } from './src/Editor'
|
||||||
|
|
||||||
export default Editor
|
export default Editor
|
||||||
|
export { Editor }
|
||||||
export { default as Extension } from './src/Extension'
|
export { default as Extension } from './src/Extension'
|
||||||
export { default as Node } from './src/Node'
|
export { default as Node } from './src/Node'
|
||||||
|
export { default as EditorContent } from './src/components/EditorContent'
|
@ -18,7 +18,6 @@ type EditorContent = string | JSON
|
|||||||
type Command = (next: Function, editor: Editor, ...args: any) => any
|
type Command = (next: Function, editor: Editor, ...args: any) => any
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
element?: globalThis.Node
|
|
||||||
content: EditorContent
|
content: EditorContent
|
||||||
extensions: (Extension | Node)[]
|
extensions: (Extension | Node)[]
|
||||||
injectCSS: Boolean
|
injectCSS: Boolean
|
||||||
@ -26,6 +25,7 @@ interface Options {
|
|||||||
|
|
||||||
export class Editor extends EventEmitter {
|
export class Editor extends EventEmitter {
|
||||||
|
|
||||||
|
element = document.createElement('div')
|
||||||
extensionManager!: ExtensionManager
|
extensionManager!: ExtensionManager
|
||||||
schema!: Schema
|
schema!: Schema
|
||||||
view!: EditorView
|
view!: EditorView
|
||||||
@ -77,7 +77,7 @@ export class Editor extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private createView() {
|
private createView() {
|
||||||
this.view = new EditorView(this.options.element, {
|
this.view = new EditorView(this.element, {
|
||||||
state: EditorState.create({
|
state: EditorState.create({
|
||||||
doc: this.createDocument(this.options.content),
|
doc: this.createDocument(this.options.content),
|
||||||
plugins: this.plugins,
|
plugins: this.plugins,
|
||||||
@ -172,6 +172,22 @@ export class Editor extends EventEmitter {
|
|||||||
return this[name](...args)
|
return this[name](...args)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public setParentComponent(component = null) {
|
||||||
|
// if (!component) {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// this.view.setProps({
|
||||||
|
// nodeViews: this.initNodeViews({
|
||||||
|
// parent: component,
|
||||||
|
// extensions: [
|
||||||
|
// ...this.builtInExtensions,
|
||||||
|
// ...this.options.extensions,
|
||||||
|
// ],
|
||||||
|
// }),
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
public json() {
|
public json() {
|
||||||
return this.state.doc.toJSON()
|
return this.state.doc.toJSON()
|
||||||
}
|
}
|
||||||
|
32
packages/tiptap-core/src/components/EditorContent.ts
Normal file
32
packages/tiptap-core/src/components/EditorContent.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
export default Vue.extend({
|
||||||
|
props: {
|
||||||
|
editor: {
|
||||||
|
default: null,
|
||||||
|
type: Object,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
editor: {
|
||||||
|
immediate: true,
|
||||||
|
handler(editor) {
|
||||||
|
if (editor && editor.element) {
|
||||||
|
this.$nextTick(() => {
|
||||||
|
this.$el.appendChild(editor.element.firstChild)
|
||||||
|
// editor.setParentComponent(this)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
render(createElement) {
|
||||||
|
return createElement('div')
|
||||||
|
},
|
||||||
|
|
||||||
|
beforeDestroy() {
|
||||||
|
this.editor.element = this.$el
|
||||||
|
},
|
||||||
|
})
|
@ -1,12 +1,16 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="editor"></div>
|
<editor-content :editor="editor" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Editor from '@tiptap/core'
|
import { Editor, EditorContent } from '@tiptap/core'
|
||||||
import extensions from '@tiptap/starter-kit'
|
import extensions from '@tiptap/starter-kit'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
EditorContent,
|
||||||
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
editor: null,
|
editor: null,
|
||||||
@ -15,7 +19,6 @@ export default {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.editor = new Editor({
|
this.editor = new Editor({
|
||||||
element: this.$refs.editor,
|
|
||||||
content: '<p>foo</p>',
|
content: '<p>foo</p>',
|
||||||
extensions: extensions(),
|
extensions: extensions(),
|
||||||
})
|
})
|
||||||
|
@ -8,18 +8,22 @@
|
|||||||
redo
|
redo
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div ref="editor"></div>
|
<editor-content :editor="editor" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Editor from '@tiptap/core'
|
import { Editor, EditorContent } from '@tiptap/core'
|
||||||
import Document from '@tiptap/document-extension'
|
import Document from '@tiptap/document-extension'
|
||||||
import Paragraph from '@tiptap/paragraph-extension'
|
import Paragraph from '@tiptap/paragraph-extension'
|
||||||
import Text from '@tiptap/text-extension'
|
import Text from '@tiptap/text-extension'
|
||||||
import History from '@tiptap/history-extension'
|
import History from '@tiptap/history-extension'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
components: {
|
||||||
|
EditorContent,
|
||||||
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
editor: null,
|
editor: null,
|
||||||
@ -28,7 +32,6 @@ export default {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.editor = new Editor({
|
this.editor = new Editor({
|
||||||
element: this.$refs.editor,
|
|
||||||
content: '<p>foo</p>',
|
content: '<p>foo</p>',
|
||||||
extensions: [
|
extensions: [
|
||||||
new Document(),
|
new Document(),
|
||||||
|
Loading…
Reference in New Issue
Block a user