UNPKG

@atlaskit/editor-plugin-date

Version:

Date plugin for @atlaskit/editor-core

40 lines 1.47 kB
import { bindKeymapWithCommand, enter, keymap, tab } from '@atlaskit/editor-common/keymaps'; import { NodeSelection } from '@atlaskit/editor-prosemirror/state'; import { closeDatePicker, focusDateInput, openDatePicker } from './actions'; import { getPluginState } from './main'; export function keymapPlugin() { var list = {}; bindKeymapWithCommand( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion enter.common, function (state, dispatch) { var datePlugin = getPluginState(state); var isDateNode = state.selection instanceof NodeSelection ? state.selection.node.type === state.schema.nodes.date : false; if (!isDateNode) { return false; } if (!datePlugin.showDatePickerAt) { openDatePicker()(state, dispatch); return true; } closeDatePicker()(state, dispatch); return true; }, list); bindKeymapWithCommand( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion tab.common, function (state, dispatch) { var datePlugin = getPluginState(state); var isDateNode = state.selection instanceof NodeSelection ? state.selection.node.type === state.schema.nodes.date : false; if (!isDateNode) { return false; } if (datePlugin.showDatePickerAt) { focusDateInput()(state, dispatch); return true; } return false; }, list); return keymap(list); } export default keymapPlugin;