improve createDocument
This commit is contained in:
@@ -15,7 +15,7 @@ import ExtensionManager from './ExtensionManager'
|
|||||||
import Extension from './Extension'
|
import Extension from './Extension'
|
||||||
import Node from './Node'
|
import Node from './Node'
|
||||||
|
|
||||||
type EditorContent = string | JSON
|
type EditorContent = string | JSON | null
|
||||||
type Command = (next: Function, editor: Editor, ...args: any) => any
|
type Command = (next: Function, editor: Editor, ...args: any) => any
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
@@ -125,18 +125,19 @@ export class Editor extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private createDocument(content: EditorContent, parseOptions: any = {}): any {
|
private createDocument(content: EditorContent, parseOptions: any = {}): any {
|
||||||
// if (content === null) {
|
if (content === null) {
|
||||||
// return this.schema.nodeFromJSON(this.options.emptyDocument)
|
// this.options.emptyDocument
|
||||||
// }
|
return this.createDocument('')
|
||||||
|
}
|
||||||
|
|
||||||
// if (typeof content === 'object') {
|
if (typeof content === 'object') {
|
||||||
// try {
|
try {
|
||||||
// return this.schema.nodeFromJSON(content)
|
return this.schema.nodeFromJSON(content)
|
||||||
// } catch (error) {
|
} 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.schema.nodeFromJSON(this.options.emptyDocument)
|
return this.createDocument('')
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (typeof content === 'string') {
|
if (typeof content === 'string') {
|
||||||
return DOMParser
|
return DOMParser
|
||||||
|
|||||||
Reference in New Issue
Block a user