UNPKG

@atlaskit/editor-plugin-interaction

Version:

Interaction plugin for @atlaskit/editor-core

55 lines (54 loc) 1.92 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.key = exports.createPlugin = void 0; var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); var _safePlugin = require("@atlaskit/editor-common/safe-plugin"); var _state = require("@atlaskit/editor-prosemirror/state"); var key = exports.key = new _state.PluginKey('interactionPluginHandler'); var handleInteraction = function handleInteraction(view) { var interactionState = key.getState(view.state); if (!(interactionState !== null && interactionState !== void 0 && interactionState.hasHadInteraction)) { view.dispatch(view.state.tr.setMeta(key, { hasHadInteraction: true })); } return false; }; var createPlugin = exports.createPlugin = function createPlugin() { return new _safePlugin.SafePlugin({ key: key, state: { init: function init() { return { hasHadInteraction: false }; }, apply: function apply(tr, oldPluginState) { var meta = tr.getMeta(key); if ((0, _typeof2.default)(meta) === 'object') { if (meta.hasHadInteraction !== oldPluginState.hasHadInteraction) { return { hasHadInteraction: meta.hasHadInteraction }; } } return oldPluginState; } }, props: { handleDOMEvents: { // Handle all pointer click events (includes drag inside editor) mousedown: handleInteraction, // Handle keyboard events. Must be keyup to handle tabbing into editor (keyup occurs // on the "next focused" element) keyup: handleInteraction, // Handle drag and drop _into_ the editor from outside. Eg image DnD drop: handleInteraction, focus: handleInteraction } } }); };