at dev 19 lines 447 B view raw
1import { Plugin, PluginKey } from "prosemirror-state"; 2import type { EditorView } from "prosemirror-view"; 3 4/** 5 * Plugin that calls a callback on every state update. 6 * Used to trigger React re-renders for toolbar state. 7 */ 8export function createUpdatePlugin(onUpdate: (view: EditorView) => void) { 9 return new Plugin({ 10 key: new PluginKey("reactUpdate"), 11 view() { 12 return { 13 update(view) { 14 onUpdate(view); 15 }, 16 }; 17 }, 18 }); 19}