flatten history plugin options

This commit is contained in:
Hans Pagel
2020-09-27 10:52:09 +02:00
parent 5d9b16c9f1
commit e536087cb2
2 changed files with 12 additions and 6 deletions

View File

@@ -12,8 +12,9 @@ yarn add @tiptap/extension-history
## Settings ## Settings
| Option | Type | Default | Description | | Option | Type | Default | Description |
| -------------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| historyPluginOptions | Object | {} | Supports the following configuration options:<br /><br />**depth:** The amount of history events that are collected before the oldest events are discarded. Defaults to 100.<br /><br />**newGroupDelay:** The delay between changes after which a new group should be started. Defaults to 500 (milliseconds). Note that when changes aren't adjacent, a new group is always started. | | depth | number | 100 | The amount of history events that are collected before the oldest events are discarded. Defaults to 100. |
| newGroupDelay | number | 500 | The delay between changes after which a new group should be started (in milliseconds). When changes arent adjacent, a new group is always started. |
## Commands ## Commands
| Command | Options | Description | | Command | Options | Description |

View File

@@ -13,13 +13,15 @@ declare module '@tiptap/core/src/Editor' {
} }
export interface HistoryOptions { export interface HistoryOptions {
historyPluginOptions: Record<string, unknown>, depth: any,
newGroupDelay: any,
} }
export default new Extension<HistoryOptions>() export default new Extension<HistoryOptions>()
.name('history') .name('history')
.defaults({ .defaults({
historyPluginOptions: {}, depth: 100,
newGroupDelay: 500,
}) })
.commands(() => ({ .commands(() => ({
undo: () => ({ state, dispatch }) => { undo: () => ({ state, dispatch }) => {
@@ -35,6 +37,9 @@ export default new Extension<HistoryOptions>()
'Shift-Mod-z': () => editor.redo(), 'Shift-Mod-z': () => editor.redo(),
})) }))
.plugins(({ options }) => [ .plugins(({ options }) => [
history(options.historyPluginOptions), history({
...options.depth,
...options.newGroupDelay,
}),
]) ])
.create() .create()