Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onSetValue plugin hook #2602

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/reference/slate/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Plugins are plain JavaScript objects, containing a set of middleware functions t
onChange: Function,
onCommand: Function,
onConstruct: Function,
onSetValue: Function,
onQuery: Function,
validateNode: Function,
}
Expand Down Expand Up @@ -88,6 +89,12 @@ The `onConstruct` hook is called when a new instance of `Editor` is created. Thi

> 🤖 This is always called with the low-level `Editor` instance, and not the React `<Editor>` component. And it is called before the React editor has its `value` set based on its props. It is purely used for editor-related configuration setup, and not for any schema-related or value-related purposes.

### `onSetValue`

`onSetValue(editor: Editor, next: Function) => Void`

The `onSetValue` hook is called when current value changes without an operation being applied, e.g. when the `Editor` is first created or as a result of `Editor.setValue()`.

### `onQuery`

`onQuery(query: Object, editor: Editor, next: Function) => Void`
Expand Down
2 changes: 2 additions & 0 deletions packages/slate/src/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ class Editor {
const { normalize = value !== this.value } = options
this.value = value

this.run('onSetValue')

if (normalize) {
this.normalize()
}
Expand Down