update the history extension page, add a demo with tests
This commit is contained in:
71
docs/src/demos/Extensions/History/index.spec.js
Normal file
71
docs/src/demos/Extensions/History/index.spec.js
Normal file
@@ -0,0 +1,71 @@
|
||||
context('/api/extensions/history', () => {
|
||||
beforeEach(() => {
|
||||
cy.visit('/api/extensions/history')
|
||||
|
||||
cy.get('.ProseMirror').window().then(window => {
|
||||
const { editor } = window
|
||||
editor.setContent('<p>Mistake</p>')
|
||||
})
|
||||
})
|
||||
|
||||
describe('undo', () => {
|
||||
it('should make the last change undone', () => {
|
||||
cy.get('.ProseMirror').window().then(window => {
|
||||
const { editor } = window
|
||||
cy.get('.ProseMirror').should('contain', 'Mistake')
|
||||
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror').should('not.contain', 'Mistake')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('redo', () => {
|
||||
it('should apply the last undone change again', () => {
|
||||
cy.get('.ProseMirror').window().then(window => {
|
||||
const { editor } = window
|
||||
cy.get('.ProseMirror').should('contain', 'Mistake')
|
||||
|
||||
cy.get('.demo__preview button:first').click({ force: true })
|
||||
cy.get('.ProseMirror').should('not.contain', 'Mistake')
|
||||
cy.get('.demo__preview button:nth-child(2)').click({ force: true })
|
||||
cy.get('.ProseMirror').should('contain', 'Mistake')
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
// context('/api/extensions/history', () => {
|
||||
// beforeEach(() => {
|
||||
// cy.visit('/api/extensions/history')
|
||||
|
||||
// cy.get('.ProseMirror').window().then(window => {
|
||||
// const { editor } = window
|
||||
// editor.setContent('<p>as</p>')
|
||||
// })
|
||||
// })
|
||||
|
||||
// describe('history', () => {
|
||||
// it('should make the selected text history', () => {
|
||||
// cy.get('.ProseMirror').window().then(window => {
|
||||
// const { editor } = window
|
||||
// const html = editor.html()
|
||||
|
||||
// cy.get('.ProseMirror').type('Mistake', { force: true })
|
||||
// // cy.get('.ProseMirror').should('contain', 'Mistake')
|
||||
// // cy.get('.demo__preview button:first').click({ force: true })
|
||||
// // cy.get('.ProseMirror').should('contain', 'Mistake')
|
||||
// })
|
||||
// })
|
||||
|
||||
|
||||
// editor.insertText('Mistake')
|
||||
// cy.get('.ProseMirror h2:first').should('contain', 'Mistake')
|
||||
|
||||
// // it('should toggle the selected text history', () => {
|
||||
// // cy.get('.demo__preview button:first').dblclick({ force: true })
|
||||
// // cy.get('.ProseMirror em').should('not.exist')
|
||||
// // })
|
||||
// })
|
||||
// })
|
||||
53
docs/src/demos/Extensions/History/index.vue
Normal file
53
docs/src/demos/Extensions/History/index.vue
Normal file
@@ -0,0 +1,53 @@
|
||||
<template>
|
||||
<div v-if="editor">
|
||||
<button @click="editor.focus().undo()">
|
||||
undo
|
||||
</button>
|
||||
<button @click="editor.focus().redo()">
|
||||
redo
|
||||
</button>
|
||||
|
||||
<editor-content :editor="editor" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor } from '@tiptap/core'
|
||||
import { EditorContent } from '@tiptap/vue'
|
||||
import Document from '@tiptap/extension-document'
|
||||
import Paragraph from '@tiptap/extension-paragraph'
|
||||
import Text from '@tiptap/extension-text'
|
||||
import History from '@tiptap/extension-history'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
extensions: [
|
||||
new Document(),
|
||||
new Paragraph(),
|
||||
new Text(),
|
||||
new History(),
|
||||
],
|
||||
content: `
|
||||
<p>Edit this text and press undo to test this extension.</p>
|
||||
`,
|
||||
})
|
||||
|
||||
window.editor = this.editor
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -1,58 +1,25 @@
|
||||
# History
|
||||
Enables history support.
|
||||
This extension provides history support. All changes to the document will be tracked and can be removed with `undo`. Undone changes can be applied with `redo` again.
|
||||
|
||||
## Options
|
||||
*None*
|
||||
|
||||
## Commands
|
||||
| Command | Options | Description |
|
||||
| ------ | ---- | ---------------- |
|
||||
| undo | — | Undo the latest change. |
|
||||
| redo | — | Redo the latest change. |
|
||||
| ------- | ------- | ----------- |
|
||||
| undo | — | Undo the last change. |
|
||||
| redo | — | Redo the last change. |
|
||||
|
||||
## Keybindings
|
||||
* Windows & Linux: `Control` + `Z` → Undo
|
||||
* Windows & Linux: `Shift` + `Control` + `Z` → Redo
|
||||
* macOS: `Command` + `Z` → Undo
|
||||
* macOS: `Shift` + `Command` + `Z` → Redo
|
||||
* Windows & Linux: `Control` + `Z`
|
||||
* macOS: `Command` + `Z`
|
||||
|
||||
### Redo
|
||||
* Windows & Linux: `Shift` + `Control` + `Z`
|
||||
* macOS: `Shift` + `Command` + `Z`
|
||||
|
||||
## Source Code
|
||||
[packages/extension-history/](https://github.com/ueberdosis/tiptap-next/blob/main/packages/extension-history/)
|
||||
|
||||
## Usage
|
||||
```markup
|
||||
<template>
|
||||
<div>
|
||||
<editor-menu-bar :editor="editor" v-slot="{ commands, isActive }">
|
||||
<div>
|
||||
<button type="button" @click="commands.undo">
|
||||
Undo
|
||||
</button>
|
||||
<button type="button" @click="commands.redo">
|
||||
Redo
|
||||
</button>
|
||||
</div>
|
||||
</editor-menu-bar>
|
||||
|
||||
<editor-content :editor="editor" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor, EditorContent, EditorMenuBar } from 'tiptap'
|
||||
import { History } from 'tiptap-extensions'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorMenuBar,
|
||||
EditorContent,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
editor: new Editor({
|
||||
extensions: [
|
||||
new History(),
|
||||
],
|
||||
}),
|
||||
}
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
<demo name="Extensions/History" highlight="3-8,20,39" />
|
||||
@@ -137,7 +137,6 @@
|
||||
draft: true
|
||||
- title: History
|
||||
link: /api/extensions/history
|
||||
draft: true
|
||||
- title: HorizontalRule
|
||||
link: /api/extensions/horizontal-rule
|
||||
draft: true
|
||||
|
||||
Reference in New Issue
Block a user