UNPKG

@atlaskit/editor-plugin-user-intent

Version:

UserIntent plugin for @atlaskit/editor-core

35 lines (34 loc) 1.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.userIntentPluginKey = exports.createPlugin = void 0; var _safePlugin = require("@atlaskit/editor-common/safe-plugin"); var _state = require("@atlaskit/editor-prosemirror/state"); var userIntentPluginKey = exports.userIntentPluginKey = new _state.PluginKey('userIntentPlugin'); var initialState = { currentUserIntent: 'default' }; var createPlugin = exports.createPlugin = function createPlugin() { return new _safePlugin.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; } } }); };