mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-08 10:03:00 +08:00
fix(vue-3): fix editor.state updating too late during a transaction due to reactiveState fixes #4870 (#5252)
This commit is contained in:
parent
dfacb3b987
commit
509676ed4a
6
.changeset/tasty-moons-move.md
Normal file
6
.changeset/tasty-moons-move.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@tiptap/core": patch
|
||||||
|
"@tiptap/vue-3": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Vue 3 bubble menus are properly synchronized with state transitions with the new beforeTransaction hook which is fired before the transaction is applied to the view
|
@ -406,6 +406,11 @@ export class Editor extends EventEmitter<EditorEvents> {
|
|||||||
const state = this.state.apply(transaction)
|
const state = this.state.apply(transaction)
|
||||||
const selectionHasChanged = !this.state.selection.eq(state.selection)
|
const selectionHasChanged = !this.state.selection.eq(state.selection)
|
||||||
|
|
||||||
|
this.emit('beforeTransaction', {
|
||||||
|
editor: this,
|
||||||
|
transaction,
|
||||||
|
nextState: state,
|
||||||
|
})
|
||||||
this.view.updateState(state)
|
this.view.updateState(state)
|
||||||
this.emit('transaction', {
|
this.emit('transaction', {
|
||||||
editor: this,
|
editor: this,
|
||||||
|
@ -50,6 +50,7 @@ export interface EditorEvents {
|
|||||||
}
|
}
|
||||||
update: { editor: Editor; transaction: Transaction }
|
update: { editor: Editor; transaction: Transaction }
|
||||||
selectionUpdate: { editor: Editor; transaction: Transaction }
|
selectionUpdate: { editor: Editor; transaction: Transaction }
|
||||||
|
beforeTransaction: { editor: Editor; transaction: Transaction, nextState: EditorState }
|
||||||
transaction: { editor: Editor; transaction: Transaction }
|
transaction: { editor: Editor; transaction: Transaction }
|
||||||
focus: { editor: Editor; event: FocusEvent; transaction: Transaction }
|
focus: { editor: Editor; event: FocusEvent; transaction: Transaction }
|
||||||
blur: { editor: Editor; event: FocusEvent; transaction: Transaction }
|
blur: { editor: Editor; event: FocusEvent; transaction: Transaction }
|
||||||
|
@ -50,8 +50,8 @@ export class Editor extends CoreEditor {
|
|||||||
this.reactiveState = useDebouncedRef(this.view.state)
|
this.reactiveState = useDebouncedRef(this.view.state)
|
||||||
this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage)
|
this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage)
|
||||||
|
|
||||||
this.on('transaction', () => {
|
this.on('beforeTransaction', ({ nextState }) => {
|
||||||
this.reactiveState.value = this.view.state
|
this.reactiveState.value = nextState
|
||||||
this.reactiveExtensionStorage.value = this.extensionStorage
|
this.reactiveExtensionStorage.value = this.extensionStorage
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user