committed by
GitHub
parent
916852fdee
commit
e6f67caef3
@@ -133,6 +133,12 @@ export class Editor extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
public setOptions(options: Partial<EditorOptions> = {}): void {
|
public setOptions(options: Partial<EditorOptions> = {}): void {
|
||||||
this.options = { ...this.options, ...options }
|
this.options = { ...this.options, ...options }
|
||||||
|
|
||||||
|
// Update editorProps directly on the view and store reference to configured props
|
||||||
|
if (this.view) {
|
||||||
|
if (options.editorProps) this.view.setProps(options.editorProps)
|
||||||
|
this.options.editorProps = this.view.props
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -251,6 +257,9 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
55
tests/cypress/integration/core/editorProps.spec.ts
Normal file
55
tests/cypress/integration/core/editorProps.spec.ts
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/// <reference types="cypress" />
|
||||||
|
|
||||||
|
import { Editor } from '@tiptap/core'
|
||||||
|
import Document from '@tiptap/extension-document'
|
||||||
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
|
import Text from '@tiptap/extension-text'
|
||||||
|
|
||||||
|
describe('editorProps', () => {
|
||||||
|
it('editorProps can be set while constructing Editor', () => {
|
||||||
|
function transformPastedHTML(html: string) {
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
|
const editor = new Editor({
|
||||||
|
extensions: [Document, Paragraph, Text],
|
||||||
|
editorProps: { transformPastedHTML },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(transformPastedHTML)
|
||||||
|
.to.eq(editor.options.editorProps.transformPastedHTML)
|
||||||
|
.and.to.eq(editor.options.editorProps.transformPastedHTML)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('editorProps can be set through setOptions', () => {
|
||||||
|
function transformPastedHTML(html: string) {
|
||||||
|
return html
|
||||||
|
}
|
||||||
|
|
||||||
|
const editor = new Editor({
|
||||||
|
extensions: [Document, Paragraph, Text],
|
||||||
|
})
|
||||||
|
|
||||||
|
editor.setOptions({ editorProps: { transformPastedHTML } })
|
||||||
|
|
||||||
|
expect(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