Merge branch 'master' into add-dropcursor

This commit is contained in:
Philipp Kühn
2018-12-20 08:13:37 +01:00
committed by GitHub
12 changed files with 760 additions and 481 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "tiptap",
"version": "1.4.0",
"version": "1.5.0",
"description": "A rich-text editor for Vue.js",
"homepage": "https://tiptap.scrumpy.io",
"license": "MIT",
@@ -28,8 +28,8 @@
"prosemirror-model": "^1.6.3",
"prosemirror-state": "^1.2.1",
"prosemirror-view": "^1.6.7",
"tiptap-commands": "^1.2.0",
"tiptap-utils": "^1.0.1"
"tiptap-commands": "^1.3.0",
"tiptap-utils": "^1.1.0"
},
"peerDependencies": {
"vue": "^2.5.17",

View File

@@ -13,11 +13,32 @@ import { Doc, Paragraph, Text } from './Nodes'
export default class Editor {
constructor(options = {}) {
this.defaultOptions = {
editable: true,
extensions: [],
content: '',
emptyDocument: {
type: 'doc',
content: [{
type: 'paragraph',
}],
},
useBuiltInExtensions: true,
dropCursor: {},
onInit: () => {},
onUpdate: () => {},
onFocus: () => {},
onBlur: () => {},
}
this.init(options)
}
init(options = {}) {
this.setOptions(options)
this.setOptions({
...this.defaultOptions,
...options,
})
this.element = document.createElement('div')
this.extensions = this.createExtensions()
this.nodes = this.createNodes()
@@ -38,27 +59,13 @@ export default class Editor {
}
setOptions(options) {
const defaultOptions = {
editable: true,
extensions: [],
content: '',
dropCursor: {},
emptyDocument: {
type: 'doc',
content: [{
type: 'paragraph',
}],
},
useBuiltInExtensions: true,
onInit: () => {},
onUpdate: () => {},
onFocus: () => {},
onBlur: () => {},
this.options = {
...this.options,
...options,
}
this.options = {
...defaultOptions,
...options,
if (this.view && this.state) {
this.view.updateState(this.state)
}
}
@@ -181,12 +188,14 @@ export default class Editor {
view.dom.style.whiteSpace = 'pre-wrap'
view.dom.addEventListener('focus', () => this.options.onFocus({
view.dom.addEventListener('focus', event => this.options.onFocus({
event,
state: this.state,
view: this.view,
}))
view.dom.addEventListener('blur', () => this.options.onBlur({
view.dom.addEventListener('blur', event => this.options.onBlur({
event,
state: this.state,
view: this.view,
}))