From e536087cb2d9a82a1cb4acb34074ac77e27b4a9a Mon Sep 17 00:00:00 2001 From: Hans Pagel Date: Sun, 27 Sep 2020 10:52:09 +0200 Subject: [PATCH 1/2] flatten history plugin options --- docs/src/docPages/api/extensions/history.md | 7 ++++--- packages/extension-history/index.ts | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/src/docPages/api/extensions/history.md b/docs/src/docPages/api/extensions/history.md index 4c1c6de8..30b04fd1 100644 --- a/docs/src/docPages/api/extensions/history.md +++ b/docs/src/docPages/api/extensions/history.md @@ -11,9 +11,10 @@ yarn add @tiptap/extension-history ``` ## Settings -| Option | Type | Default | Description | -| -------------------- | ------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| historyPluginOptions | Object | {} | Supports the following configuration options:

**depth:** The amount of history events that are collected before the oldest events are discarded. Defaults to 100.

**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. | +| Option | Type | Default | Description | +| ------------- | ------ | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | +| 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 aren’t adjacent, a new group is always started. | ## Commands | Command | Options | Description | diff --git a/packages/extension-history/index.ts b/packages/extension-history/index.ts index 764d6715..ef2ceed0 100644 --- a/packages/extension-history/index.ts +++ b/packages/extension-history/index.ts @@ -13,13 +13,15 @@ declare module '@tiptap/core/src/Editor' { } export interface HistoryOptions { - historyPluginOptions: Record, + depth: any, + newGroupDelay: any, } export default new Extension() .name('history') .defaults({ - historyPluginOptions: {}, + depth: 100, + newGroupDelay: 500, }) .commands(() => ({ undo: () => ({ state, dispatch }) => { @@ -35,6 +37,9 @@ export default new Extension() 'Shift-Mod-z': () => editor.redo(), })) .plugins(({ options }) => [ - history(options.historyPluginOptions), + history({ + ...options.depth, + ...options.newGroupDelay, + }), ]) .create() From 54bbd8a8616f3e325e90f2664dfd774c38a64e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Sun, 27 Sep 2020 21:29:51 +0200 Subject: [PATCH 2/2] refactoring --- packages/extension-history/index.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/extension-history/index.ts b/packages/extension-history/index.ts index ef2ceed0..3401b4e9 100644 --- a/packages/extension-history/index.ts +++ b/packages/extension-history/index.ts @@ -13,8 +13,8 @@ declare module '@tiptap/core/src/Editor' { } export interface HistoryOptions { - depth: any, - newGroupDelay: any, + depth: number, + newGroupDelay: number, } export default new Extension() @@ -37,9 +37,6 @@ export default new Extension() 'Shift-Mod-z': () => editor.redo(), })) .plugins(({ options }) => [ - history({ - ...options.depth, - ...options.newGroupDelay, - }), + history(options), ]) .create()