Merge branch 'main' of github.com:ueberdosis/tiptap-next into main

# Conflicts:
#	docs/src/demos/Examples/MarkdownShortcuts/index.spec.js
#	docs/src/demos/Extensions/Blockquote/index.spec.js
#	docs/src/demos/Extensions/Bold/index.spec.js
#	docs/src/demos/Extensions/Code/index.spec.js
#	docs/src/demos/Extensions/CodeBlock/index.spec.js
#	docs/src/demos/Extensions/HardBreak/index.spec.js
#	docs/src/demos/Extensions/Heading/index.spec.js
#	docs/src/demos/Extensions/History/index.spec.js
#	docs/src/demos/Extensions/HorizontalRule/index.spec.js
#	docs/src/demos/Extensions/Italic/index.spec.js
#	docs/src/demos/Extensions/Paragraph/index.spec.js
#	docs/src/demos/Extensions/Strike/index.spec.js
#	docs/src/demos/Extensions/Underline/index.spec.js
This commit is contained in:
Hans Pagel
2020-09-11 18:20:56 +02:00
18 changed files with 45 additions and 58 deletions

View File

@@ -4,8 +4,7 @@ context('/examples/export-html-or-json', () => {
}) })
it('should return json', () => { it('should return json', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
const json = editor.json() const json = editor.json()
expect(json).to.deep.equal({ expect(json).to.deep.equal({
@@ -52,8 +51,7 @@ context('/examples/export-html-or-json', () => {
}) })
it('should return html', () => { it('should return html', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
const html = editor.html() const html = editor.html()
expect(html).to.equal('<p>You are able to export your data as <code>HTML</code> or <code>JSON</code>.</p>') expect(html).to.equal('<p>You are able to export your data as <code>HTML</code> or <code>JSON</code>.</p>')

View File

@@ -4,8 +4,7 @@ context('/examples/focus', () => {
}) })
it('should have class', () => { it('should have class', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.focus('start') editor.focus('start')
cy.get('.ProseMirror p:first').should('have.class', 'has-focus') cy.get('.ProseMirror p:first').should('have.class', 'has-focus')

View File

@@ -4,8 +4,7 @@ context('/examples/history', () => {
}) })
it('should not have a mistake', () => { it('should not have a mistake', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
const html = editor.html() const html = editor.html()
cy.get('.ProseMirror h2:first').should('not.contain', 'Mistake') cy.get('.ProseMirror h2:first').should('not.contain', 'Mistake')
@@ -13,8 +12,7 @@ context('/examples/history', () => {
}) })
it('should have a mistake', () => { it('should have a mistake', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
const html = editor.html() const html = editor.html()
editor.insertText('Mistake') editor.insertText('Mistake')
@@ -23,8 +21,7 @@ context('/examples/history', () => {
}) })
it('the mistake should be removed again', () => { it('the mistake should be removed again', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
const html = editor.html() const html = editor.html()
editor.undo() editor.undo()

View File

@@ -4,8 +4,7 @@ context('/examples/markdown-shortcuts', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.clearContent() editor.clearContent()
done() done()
}) })

View File

@@ -4,10 +4,9 @@ context('/examples/read-only', () => {
}) })
it.skip('should be read-only', () => { it.skip('should be read-only', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
cy.get('#editable').uncheck() cy.get('#editable').uncheck()
const { editor } = window
editor.insertText('Edited: ') editor.insertText('Edited: ')
cy.get('.ProseMirror p:first').should('not.contain', 'Edited: ') cy.get('.ProseMirror p:first').should('not.contain', 'Edited: ')
@@ -15,10 +14,9 @@ context('/examples/read-only', () => {
}) })
it.skip('should be editable', () => { it.skip('should be editable', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
cy.get('#editable').check() cy.get('#editable').check()
const { editor } = window
editor.insertText('Edited: ') editor.insertText('Edited: ')
cy.get('.ProseMirror p:first').should('contain', 'Edited: ') cy.get('.ProseMirror p:first').should('contain', 'Edited: ')

View File

@@ -4,8 +4,7 @@ context('/api/extensions/blockquote', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
editor.selectAll() editor.selectAll()
done() done()

View File

@@ -4,8 +4,7 @@ context('/api/extensions/bold', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
editor.selectAll() editor.selectAll()
done() done()

View File

@@ -4,8 +4,7 @@ context('/api/extensions/code', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
editor.selectAll() editor.selectAll()
done() done()

View File

@@ -4,8 +4,7 @@ context('/api/extensions/code-block', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
editor.selectAll() editor.selectAll()
done() done()

View File

@@ -4,8 +4,7 @@ context('/api/extensions/hard-break', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
done() done()
}) })

View File

@@ -4,8 +4,7 @@ context('/api/extensions/heading', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
editor.selectAll() editor.selectAll()
done() done()

View File

@@ -4,20 +4,17 @@ context('/api/extensions/history', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Mistake</p>') editor.setContent('<p>Mistake</p>')
done() done()
}) })
}) })
it('should make the last change undone', () => { it('should make the last change undone', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').should('contain', 'Mistake')
cy.get('.ProseMirror').should('contain', 'Mistake')
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror').should('not.contain', 'Mistake') cy.get('.ProseMirror').should('not.contain', 'Mistake')
})
}) })
it('the keyboard shortcut should make the last change undone', () => { it('the keyboard shortcut should make the last change undone', () => {
@@ -26,14 +23,12 @@ context('/api/extensions/history', () => {
}) })
it('should apply the last undone change again', () => { it('should apply the last undone change again', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').should('contain', 'Mistake')
cy.get('.ProseMirror').should('contain', 'Mistake')
cy.get('.demo__preview button:first').click({ force: true }) cy.get('.demo__preview button:first').click({ force: true })
cy.get('.ProseMirror').should('not.contain', 'Mistake') cy.get('.ProseMirror').should('not.contain', 'Mistake')
cy.get('.demo__preview button:nth-child(2)').click({ force: true }) cy.get('.demo__preview button:nth-child(2)').click({ force: true })
cy.get('.ProseMirror').should('contain', 'Mistake') cy.get('.ProseMirror').should('contain', 'Mistake')
})
}) })
it.skip('the keyboard shortcut should apply the last undone change again', () => { it.skip('the keyboard shortcut should apply the last undone change again', () => {

View File

@@ -4,8 +4,7 @@ context('/api/extensions/horizontal-rule', () => {
}) })
beforeEach(() => { beforeEach(() => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
}) })
}) })
@@ -17,8 +16,7 @@ context('/api/extensions/horizontal-rule', () => {
}) })
it('the default markdown shortcut should add a horizontal rule', () => { it('the default markdown shortcut should add a horizontal rule', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.clearContent() editor.clearContent()
cy.get('.ProseMirror hr').should('not.exist') cy.get('.ProseMirror hr').should('not.exist')
@@ -28,8 +26,7 @@ context('/api/extensions/horizontal-rule', () => {
}) })
it('the alternative markdown shortcut should add a horizontal rule', () => { it('the alternative markdown shortcut should add a horizontal rule', () => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.clearContent() editor.clearContent()
cy.get('.ProseMirror hr').should('not.exist') cy.get('.ProseMirror hr').should('not.exist')

View File

@@ -4,8 +4,7 @@ context('/api/extensions/italic', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
editor.selectAll() editor.selectAll()
done() done()

View File

@@ -4,8 +4,7 @@ context('/api/extensions/paragraph', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.clearContent() editor.clearContent()
done() done()
}) })

View File

@@ -4,8 +4,7 @@ context('/api/extensions/strike', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
editor.selectAll() editor.selectAll()
done() done()

View File

@@ -4,8 +4,7 @@ context('/api/extensions/underline', () => {
}) })
beforeEach((done) => { beforeEach((done) => {
cy.get('.ProseMirror').window().then(window => { cy.get('.ProseMirror').then(([{ editor }]) => {
const { editor } = window
editor.setContent('<p>Example Text</p>') editor.setContent('<p>Example Text</p>')
editor.selectAll() editor.selectAll()
done() done()

View File

@@ -28,6 +28,16 @@ export interface CommandSpec {
type EditorContent = string | JSON | null type EditorContent = string | JSON | null
// interface Element {
// editor?: Editor
// }
interface HTMLElement {
editor?: Editor
}
// Element.prototype.editor = Editor
interface EditorOptions { interface EditorOptions {
element: Element, element: Element,
content: EditorContent, content: EditorContent,
@@ -241,6 +251,10 @@ export class Editor extends EventEmitter {
dispatchTransaction: this.dispatchTransaction.bind(this), dispatchTransaction: this.dispatchTransaction.bind(this),
nodeViews: this.extensionManager.nodeViews, nodeViews: this.extensionManager.nodeViews,
}) })
// store editor in dom element for better testing
const dom = this.view.dom as HTMLElement
dom.editor = this.proxy
} }
/** /**