From feab2c4f46a46e5cd302e8ec88d9d4311706415a Mon Sep 17 00:00:00 2001 From: Sunny Hirai Date: Tue, 11 Apr 2023 23:07:32 -0700 Subject: [PATCH] Add docs for HistoryEditor --- docs/Summary.md | 1 + docs/history/history-editor.md | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 docs/history/history-editor.md diff --git a/docs/Summary.md b/docs/Summary.md index 22c9f134c..9dc3afd8c 100644 --- a/docs/Summary.md +++ b/docs/Summary.md @@ -55,6 +55,7 @@ - [Slate React](libraries/slate-react.md) - [Slate History](libraries/slate-history.md) - [History](/history/history.md) + - [HistoryEditor](/history/history-editor.md) - [Slate Hyperscript](libraries/slate-hyperscript.md) ## General diff --git a/docs/history/history-editor.md b/docs/history/history-editor.md new file mode 100644 index 000000000..3f73a5b2d --- /dev/null +++ b/docs/history/history-editor.md @@ -0,0 +1,78 @@ +# History Editor + +The `HistoryEditor` interface is added to the `Editor` when it is instantiated using the `withHistory` method. + +```typescript +const [editor] = useState(() => withReact(withHistory(createEditor()))) +``` + +This adds properties to `editor` that enables undo and redo to Slate. + +There are also a number of static methods to help while working with the Editor's undo/redo history. + +```typescript +export interface HistoryEditor extends BaseEditor { + history: History + undo: () => void + redo: () => void + writeHistory: (stack: 'undos' | 'redos', batch: any) => void +} +``` + +- [Static methods](history-editor.md#static-methods) + - [Undo and Redo](history-editor.md#undo-and-redo) + - [Merging and Saving](history-editor.md#merging-and-saving) + - [Check methods](history-editor.md#check-methods) +- [Instance methods](history-editor.md#instance-methods) + +## Static methods + +### Undo and Redo + +#### `HistoryEditor.redo(editor: HistoryEditor): void` + +Redo to the previous saved state. + +#### `HistoryEditor.undo(editor: HistoryEditor): void` + +Undo to the previous saved state. + +### Merging and Savings + +#### `HistoryEditor.withoutMerging(editor: HistoryEditor, fn: () => void): void` + +Apply a series of changes inside a synchronous `fn`, without merging any of +the new operations into previous save point in the history. + +#### `HistoryEditor.withoutSaving(editor: HistoryEditor, fn: () => void): void` + +Apply a series of changes inside a synchronous `fn`, without saving any of +their operations into the history. + +### Check methods + +#### `HistoryEditor.isHistoryEditor(value: any): value is HistoryEditor` + +Check if a value is a `HistoryEditor` (i.e. it has the `HistoryEditor` interface). + +#### `HistoryEditor.isMerging(editor: HistoryEditor): boolean | undefined` + +Get the merge flag's current value. + +#### `HistoryEditor.isSaving(editor: HistoryEditor): boolean | undefined` + +Get the saving flag's current value. + +## Instance methods + +#### `undo(): void` + +Undo the last batch of operations + +#### `redo(): void` + +Redo the last undone batch of operations + +#### `writeHistory(stack: 'undos'| 'redos', batch: any) => void` + +Push a batch of operations as either `undos` or `redos` onto `editor.undos` or `editor.redos`