mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 22:21:20 +02:00
Add withHistory page to docs, reorganize the History docs in general and update Summary.md
This commit is contained in:
7
docs/libraries/slate-history/README.md
Normal file
7
docs/libraries/slate-history/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Slate History
|
||||
|
||||
This sub-library tracks changes to the Slate value state over time, and enables undo and redo functionality.
|
||||
|
||||
- [withHistory](./with-history.md)
|
||||
- [HistoryEditor](./history-editor.md)
|
||||
- [History](./history.md)
|
78
docs/libraries/slate-history/history-editor.md
Normal file
78
docs/libraries/slate-history/history-editor.md
Normal file
@@ -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 in Slate.
|
||||
|
||||
There are also static methods for 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 next saved state.
|
||||
|
||||
#### `HistoryEditor.undo(editor: HistoryEditor): void`
|
||||
|
||||
Undo to the previous saved state.
|
||||
|
||||
### Merging and Saving
|
||||
|
||||
#### `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`
|
27
docs/libraries/slate-history/history.md
Normal file
27
docs/libraries/slate-history/history.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# History
|
||||
|
||||
The `History` object contains the undo and redo history for the editor.
|
||||
|
||||
It can be accessed from an `Editor` instance as the property `history`.
|
||||
|
||||
This property is only available on the `Editor` if the editor was instantiated using the `withHistory` method which adds undo/redo functionality to the Slate editor.
|
||||
|
||||
```typescript
|
||||
export interface History {
|
||||
redos: Batch[]
|
||||
undos: Batch[]
|
||||
}
|
||||
|
||||
interface Batch {
|
||||
operations: Operation[]
|
||||
selectionBefore: Range | null
|
||||
}
|
||||
```
|
||||
|
||||
- [Static Methods](history.md#static-methods)
|
||||
|
||||
## Static Methods
|
||||
|
||||
#### `History.isHistory(value: any): value is History`
|
||||
|
||||
Returns `true` if the passed in `value` is a `History` object and also acts as a type guard for `History`.
|
13
docs/libraries/slate-history/with-history.md
Normal file
13
docs/libraries/slate-history/with-history.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# withHistory
|
||||
|
||||
The `withHistory` plugin adds the `HistoryEditor` to an `Editor` instance and keeps track of the operation history of a Slate editor as operations are applied to it, using undo and redo stacks.
|
||||
|
||||
#### `withHistory<T extends Editor>(editor: T): T & HistoryEditor`
|
||||
|
||||
Add `HistoryEditor` interface to an instance of any `Editor`.
|
||||
|
||||
When used with `withReact`, `withHistory` should be applied inside. For example:
|
||||
|
||||
```javascript
|
||||
const [editor] = useState(() => withReact(withHistory(createEditor())))
|
||||
```
|
Reference in New Issue
Block a user