UNPKG

@atlaskit/editor-plugin-user-intent

Version:

UserIntent plugin for @atlaskit/editor-core

29 lines 969 B
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; export var userIntentPluginKey = new PluginKey('userIntentPlugin'); var initialState = { currentUserIntent: 'default' }; export var createPlugin = function createPlugin() { return new SafePlugin({ key: userIntentPluginKey, state: { init: function init() { return initialState; }, apply: function apply(tr, currentPluginState) { var meta = tr.getMeta(userIntentPluginKey); if (meta) { // If the incoming currentUserIntent is the same as the existing one, return the existing state if (meta.data.currentUserIntent === currentPluginState.currentUserIntent) { return currentPluginState; } return { currentUserIntent: meta.data.currentUserIntent }; } return currentPluginState; } } }); };