UNPKG

@atlaskit/editor-core

Version:

A package contains Atlassian editor core functionality

44 lines 1.51 kB
import { Plugin, PluginKey, } from '../../prosemirror'; var ReactNodeViewState = (function () { function ReactNodeViewState() { this.changeHandlers = []; this.changeHandlers = []; } ReactNodeViewState.prototype.subscribe = function (cb) { this.changeHandlers.push(cb); }; ReactNodeViewState.prototype.unsubscribe = function (cb) { this.changeHandlers = this.changeHandlers.filter(function (ch) { return ch !== cb; }); }; ReactNodeViewState.prototype.notifyNewSelection = function (anchorPos, headPos) { this.changeHandlers.forEach(function (cb) { return cb(anchorPos, headPos); }); }; return ReactNodeViewState; }()); export { ReactNodeViewState }; export var stateKey = new PluginKey('reactNodeView'); export var plugin = new Plugin({ state: { init: function (config, state) { return new ReactNodeViewState(); }, apply: function (tr, pluginState, oldState, newState) { return pluginState; } }, key: stateKey, view: function (view) { var pluginState = stateKey.getState(view.state); return { update: function (view, prevState) { var _a = view.state.selection, $anchor = _a.$anchor, $head = _a.$head; pluginState.notifyNewSelection($anchor.pos, $head.pos); } }; } }); var plugins = function (schema) { return [plugin]; }; export default plugins; //# sourceMappingURL=index.js.map