@atlaskit/editor-plugin-interaction
Version:
Interaction plugin for @atlaskit/editor-core
38 lines • 1.31 kB
JavaScript
import { createPlugin, key } from './pm-plugins/main';
export var interactionPlugin = function interactionPlugin() {
return {
name: 'interaction',
getSharedState: function 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: function handleInteraction(_ref) {
var tr = _ref.tr;
return tr.setMeta(key, {
hasHadInteraction: true
});
}
},
pmPlugins: function pmPlugins() {
return [{
name: 'interactionHandlerPlugin',
plugin: createPlugin
}];
}
};
};