refactoring
This commit is contained in:
@@ -132,13 +132,20 @@ export class Editor extends EventEmitter {
|
|||||||
* @param options A list of options
|
* @param options A list of options
|
||||||
*/
|
*/
|
||||||
public setOptions(options: Partial<EditorOptions> = {}): void {
|
public setOptions(options: Partial<EditorOptions> = {}): void {
|
||||||
this.options = { ...this.options, ...options }
|
this.options = {
|
||||||
|
...this.options,
|
||||||
// Update editorProps directly on the view and store reference to configured props
|
...options,
|
||||||
if (this.view) {
|
|
||||||
if (options.editorProps) this.view.setProps(options.editorProps)
|
|
||||||
this.options.editorProps = this.view.props
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.view || !this.state || this.isDestroyed) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.editorProps) {
|
||||||
|
this.view.setProps(this.options.editorProps)
|
||||||
|
}
|
||||||
|
|
||||||
|
this.view.updateState(this.state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,10 +153,6 @@ export class Editor extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
public setEditable(editable: boolean): void {
|
public setEditable(editable: boolean): void {
|
||||||
this.setOptions({ editable })
|
this.setOptions({ editable })
|
||||||
|
|
||||||
if (this.view && this.state && !this.isDestroyed) {
|
|
||||||
this.view.updateState(this.state)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -257,9 +260,6 @@ export class Editor extends EventEmitter {
|
|||||||
// So we’ll have access to it for tests.
|
// So we’ll have access to it for tests.
|
||||||
const dom = this.view.dom as HTMLElement
|
const dom = this.view.dom as HTMLElement
|
||||||
dom.editor = this
|
dom.editor = this
|
||||||
|
|
||||||
// Reference the resulting view props in our options
|
|
||||||
this.options.editorProps = this.view.props
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ describe('editorProps', () => {
|
|||||||
editorProps: { transformPastedHTML },
|
editorProps: { transformPastedHTML },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(transformPastedHTML)
|
expect(transformPastedHTML).to.eq(editor.view.props.transformPastedHTML)
|
||||||
.to.eq(editor.options.editorProps.transformPastedHTML)
|
|
||||||
.and.to.eq(editor.options.editorProps.transformPastedHTML)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('editorProps can be set through setOptions', () => {
|
it('editorProps can be set through setOptions', () => {
|
||||||
@@ -32,24 +30,6 @@ describe('editorProps', () => {
|
|||||||
|
|
||||||
editor.setOptions({ editorProps: { transformPastedHTML } })
|
editor.setOptions({ editorProps: { transformPastedHTML } })
|
||||||
|
|
||||||
expect(transformPastedHTML)
|
expect(transformPastedHTML).to.eq(editor.view.props.transformPastedHTML)
|
||||||
.to.eq(editor.options.editorProps.transformPastedHTML)
|
|
||||||
.and.to.eq(editor.options.editorProps.transformPastedHTML)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('editorProps can be set directly through options', () => {
|
|
||||||
function transformPastedHTML(html: string) {
|
|
||||||
return html
|
|
||||||
}
|
|
||||||
|
|
||||||
const editor = new Editor({
|
|
||||||
extensions: [Document, Paragraph, Text],
|
|
||||||
})
|
|
||||||
|
|
||||||
editor.options.editorProps.transformPastedHTML = transformPastedHTML
|
|
||||||
|
|
||||||
expect(transformPastedHTML)
|
|
||||||
.to.eq(editor.options.editorProps.transformPastedHTML)
|
|
||||||
.and.to.eq(editor.options.editorProps.transformPastedHTML)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user