refactoring

This commit is contained in:
Philipp Kühn 2020-11-17 21:04:38 +01:00
parent ad3418e1d2
commit 99aebcc18b
2 changed files with 15 additions and 3 deletions

View File

@ -33,6 +33,7 @@ module.exports = {
],
rules: {
'no-alert': 'off',
'no-console': ['error', { allow: ['warn', 'error'] }],
semi: ['error', 'never'],
'import/extensions': 'off',
'import/no-extraneous-dependencies': 'off',

View File

@ -1,6 +1,11 @@
import { EditorState, Plugin, Transaction } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import { Schema, DOMParser } from 'prosemirror-model'
import {
Schema,
DOMParser,
ParseOptions,
Node,
} from 'prosemirror-model'
import magicMethods from './utils/magicMethods'
import elementFromString from './utils/elementFromString'
import nodeIsActive from './utils/nodeIsActive'
@ -260,12 +265,18 @@ export class Editor extends EventEmitter {
/**
* Creates a ProseMirror document.
*/
public createDocument = (content: EditorContent, parseOptions: any = {}): any => {
public createDocument = (content: EditorContent, parseOptions: ParseOptions = {}): Node => {
if (content && typeof content === 'object') {
try {
return this.schema.nodeFromJSON(content)
} catch (error) {
console.warn('[tiptap warn]: Invalid content.', 'Passed value:', content, 'Error:', error)
console.warn(
'[tiptap warn]: Invalid content.',
'Passed value:',
content,
'Error:',
error,
)
return this.createDocument('')
}
}