UNPKG

@atlaskit/editor-plugin-interaction

Version:

Interaction plugin for @atlaskit/editor-core

39 lines 1.22 kB
import { createPlugin, key } from './pm-plugins/main'; export const interactionPlugin = () => { return { name: 'interaction', getSharedState(editorState) { var _key$getState; if (!editorState) { return { interactionState: 'hasNotHadInteraction' }; } return { /** * Interaction state can either be null or 'hasNotHadInteraction'. We * are specifically only returning an explicit value for 'hasNotHadInteraction' * because behaviour should only change when the user has _not_ ineteracted * with the editor. The behaviour of when `hasHadInteraction` is true and * when the plugin is undefined should be the same. */ interactionState: (_key$getState = key.getState(editorState)) !== null && _key$getState !== void 0 && _key$getState.hasHadInteraction ? null : 'hasNotHadInteraction' }; }, commands: { handleInteraction: ({ tr }) => { return tr.setMeta(key, { hasHadInteraction: true }); } }, pmPlugins() { return [{ name: 'interactionHandlerPlugin', plugin: createPlugin }]; } }; };