mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 03:39:01 +08:00
parent
3efb23be9b
commit
8ea34e405e
5
.changeset/perfect-dryers-glow.md
Normal file
5
.changeset/perfect-dryers-glow.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@tiptap/react": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
This resolves a bug with `useEditor` where event handlers were being called 2x for what should have been a single registration
|
@ -136,18 +136,20 @@ class EditorInstanceManager {
|
|||||||
* Create a new editor instance. And attach event listeners.
|
* Create a new editor instance. And attach event listeners.
|
||||||
*/
|
*/
|
||||||
private createEditor(): Editor {
|
private createEditor(): Editor {
|
||||||
const editor = new Editor(this.options.current)
|
const optionsToApply: Partial<EditorOptions> = {
|
||||||
|
...this.options.current,
|
||||||
// Always call the most recent version of the callback function by default
|
// Always call the most recent version of the callback function by default
|
||||||
editor.on('beforeCreate', (...args) => this.options.current.onBeforeCreate?.(...args))
|
onBeforeCreate: (...args) => this.options.current.onBeforeCreate?.(...args),
|
||||||
editor.on('blur', (...args) => this.options.current.onBlur?.(...args))
|
onBlur: (...args) => this.options.current.onBlur?.(...args),
|
||||||
editor.on('create', (...args) => this.options.current.onCreate?.(...args))
|
onCreate: (...args) => this.options.current.onCreate?.(...args),
|
||||||
editor.on('destroy', (...args) => this.options.current.onDestroy?.(...args))
|
onDestroy: (...args) => this.options.current.onDestroy?.(...args),
|
||||||
editor.on('focus', (...args) => this.options.current.onFocus?.(...args))
|
onFocus: (...args) => this.options.current.onFocus?.(...args),
|
||||||
editor.on('selectionUpdate', (...args) => this.options.current.onSelectionUpdate?.(...args))
|
onSelectionUpdate: (...args) => this.options.current.onSelectionUpdate?.(...args),
|
||||||
editor.on('transaction', (...args) => this.options.current.onTransaction?.(...args))
|
onTransaction: (...args) => this.options.current.onTransaction?.(...args),
|
||||||
editor.on('update', (...args) => this.options.current.onUpdate?.(...args))
|
onUpdate: (...args) => this.options.current.onUpdate?.(...args),
|
||||||
editor.on('contentError', (...args) => this.options.current.onContentError?.(...args))
|
onContentError: (...args) => this.options.current.onContentError?.(...args),
|
||||||
|
}
|
||||||
|
const editor = new Editor(optionsToApply)
|
||||||
|
|
||||||
// no need to keep track of the event listeners, they will be removed when the editor is destroyed
|
// no need to keep track of the event listeners, they will be removed when the editor is destroyed
|
||||||
|
|
||||||
@ -215,7 +217,6 @@ class EditorInstanceManager {
|
|||||||
* Recreate the editor instance if the dependencies have changed.
|
* Recreate the editor instance if the dependencies have changed.
|
||||||
*/
|
*/
|
||||||
private refreshEditorInstance(deps: DependencyList) {
|
private refreshEditorInstance(deps: DependencyList) {
|
||||||
|
|
||||||
if (this.editor && !this.editor.isDestroyed) {
|
if (this.editor && !this.editor.isDestroyed) {
|
||||||
// Editor instance already exists
|
// Editor instance already exists
|
||||||
if (this.previousDeps === null) {
|
if (this.previousDeps === null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user