import { chainCommands as chain } from "prosemirror-commands"; import { AllSelection, EditorState } from "prosemirror-state"; import { ux as attachmentUx } from "./attachment/commands"; import { ux as bqUx } from "./blockquote/commands"; import { ux as bUx } from "./bold/commands"; import { UxCommand } from "./constants"; import { ux as genericUx } from "./genericCommands"; import { ux as headingUx } from "./heading/commands"; import { ux as historyUx } from "./history/commands"; import { ux as horizontalRuleUx } from "./horizontalrule/commands"; import { ux as iUx } from "./italic/commands"; import { ux as linkUx } from "./link/commands"; import { ux as listUx } from "./list/commands"; import { selectDocEnd, selectDocStart } from "./operation"; import { ux as pUx } from "./pCommands"; import { ux as sUx } from "./strikethrough/commands"; import { ux as tableUx } from "./table/commands"; import { Dispatch } from "./types"; import { ux as uUx } from "./underline/commands"; import { ux as wedgeUx } from "./wedge/commands"; function selectStartWhenAllSelection(state: EditorState, dispatch?: Dispatch): boolean { if (state.selection instanceof AllSelection) { const tr = state.tr; if (selectDocStart(tr)) { if (dispatch !== undefined) { dispatch(tr); } return true; } } return false; } function selectEndWhenAllSelection(state: EditorState, dispatch?: Dispatch): boolean { if (state.selection instanceof AllSelection) { const tr = state.tr; if (selectDocEnd(tr)) { if (dispatch !== undefined) { dispatch(tr); } return true; } } return false; } export const uxCommands = { [UxCommand.ArrowDown]: chain(selectEndWhenAllSelection, wedgeUx[UxCommand.ArrowDown], tableUx[UxCommand.ArrowDown]), [UxCommand.ArrowLeft]: chain(wedgeUx[UxCommand.ArrowLeft], tableUx[UxCommand.ArrowLeft]), [UxCommand.ArrowRight]: chain(wedgeUx[UxCommand.ArrowRight], tableUx[UxCommand.ArrowRight]), [UxCommand.ArrowUp]: chain(selectStartWhenAllSelection, wedgeUx[UxCommand.ArrowUp], tableUx[UxCommand.ArrowUp]), [UxCommand.DeleteBackward]: chain( tableUx[UxCommand.DeleteBackward], headingUx[UxCommand.DeleteBackward], listUx[UxCommand.DeleteBackward], genericUx[UxCommand.DeleteBackward] ), [UxCommand.DeleteForward]: chain( tableUx[UxCommand.DeleteForward], listUx[UxCommand.DeleteForward], genericUx[UxCommand.DeleteForward] ), [UxCommand.Enter]: chain(listUx[UxCommand.Enter], genericUx[UxCommand.Enter]), [UxCommand.EnterHard]: pUx[UxCommand.EnterHard], [UxCommand.Bold]: bUx[UxCommand.Bold], [UxCommand.ComposeLink]: linkUx[UxCommand.ComposeLink], [UxCommand.Italic]: iUx[UxCommand.Italic], [UxCommand.InsertHorizontalRule]: horizontalRuleUx[UxCommand.InsertHorizontalRule], [UxCommand.InsertTable]: tableUx[UxCommand.InsertTable], [UxCommand.Lift]: chain(listUx[UxCommand.Lift], genericUx[UxCommand.Lift]), [UxCommand.PickAttachmentFile]: attachmentUx[UxCommand.PickAttachmentFile], [UxCommand.PickAttachmentImage]: attachmentUx[UxCommand.PickAttachmentImage], [UxCommand.Redo]: historyUx[UxCommand.Redo], [UxCommand.SelectAll]: chain(tableUx[UxCommand.SelectAll], genericUx[UxCommand.SelectAll]), [UxCommand.Sink]: chain(listUx[UxCommand.Sink], genericUx[UxCommand.Sink]), [UxCommand.ShiftArrowDown]: tableUx[UxCommand.ShiftArrowDown], [UxCommand.ShiftArrowLeft]: tableUx[UxCommand.ShiftArrowLeft], [UxCommand.ShiftArrowRight]: tableUx[UxCommand.ShiftArrowRight], [UxCommand.ShiftArrowUp]: tableUx[UxCommand.ShiftArrowUp], [UxCommand.Strikethrough]: sUx[UxCommand.Strikethrough], [UxCommand.TabBackward]: chain(listUx[UxCommand.TabBackward], genericUx[UxCommand.TabBackward]), [UxCommand.TabForward]: chain(listUx[UxCommand.TabForward], genericUx[UxCommand.TabForward]), [UxCommand.ToggleBlockquote]: bqUx[UxCommand.ToggleBlockquote], [UxCommand.ToggleHeading1]: headingUx[UxCommand.ToggleHeading1], [UxCommand.ToggleHeading2]: headingUx[UxCommand.ToggleHeading2], [UxCommand.ToggleOrderedList]: listUx[UxCommand.ToggleOrderedList], [UxCommand.ToggleTableHeaderCell]: tableUx[UxCommand.ToggleTableHeaderCell], [UxCommand.ToggleUnorderedList]: listUx[UxCommand.ToggleUnorderedList], [UxCommand.Underline]: uUx[UxCommand.Underline], [UxCommand.Undo]: historyUx[UxCommand.Undo] };