UNPKG

@atlaskit/editor-plugin-interaction

Version:

Interaction plugin for @atlaskit/editor-core

48 lines 1.62 kB
import _typeof from "@babel/runtime/helpers/typeof"; import { SafePlugin } from '@atlaskit/editor-common/safe-plugin'; import { PluginKey } from '@atlaskit/editor-prosemirror/state'; export var key = new 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; }; export var createPlugin = function createPlugin() { return new SafePlugin({ key: key, state: { init: function init() { return { hasHadInteraction: false }; }, apply: function apply(tr, oldPluginState) { var meta = tr.getMeta(key); if (_typeof(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 } } }); };