UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

32 lines 823 B
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; const key = new PluginKey('editorStateNotificationPlugin'); export const createEditorStateNotificationPlugin = (onEditorStateUpdated, onEditorViewStateUpdatedCallbacks) => { const transactions = []; return new SafePlugin({ key: key, state: { init() { return { latestTransaction: undefined }; }, apply(tr) { transactions.push(tr); return { latestTransaction: tr }; } }, view: () => { return { update: (view, oldEditorState) => { onEditorStateUpdated({ oldEditorState, newEditorState: view.state }); } }; } }); };