import { TIPTAP_TABLE_CELL_TYPE, TIPTAP_TABLE_HEADER_CELL_TYPE } from "./../ricos-content/consts.js";
import { createShortcut } from "./../ricos-types/index.js";
import { findParentNodeClosestToPos } from "./../tiptap/index.js";
import { isInTable } from "./tiptap/commands/queries.js";
import { TableQuery } from "./tiptap/table-query.js";
import { findTable } from "./tiptap/utilities/find-table.js";
import { isRicosCellSelection } from "./tiptap/utilities/is-selection-type.js";
const shortcuts = [
  createShortcut({
    name: "MoveToNextCellTab",
    description: "ShortcutsSheet_Table_MoveToTheNextCell",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Tab",
      windows: "Tab"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "MoveToNextCellArrow",
    description: "ShortcutsSheet_Table_MoveToTheNextCell",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Arrow",
      windows: "Arrow"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "MoveToPreviousCellTab",
    description: "ShortcutsSheet_Table_MoveToThePreviousCell",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Shift+Tab",
      windows: "Shift+Tab"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "MoveToPreviousCellArrow",
    description: "ShortcutsSheet_Table_MoveToThePreviousCell",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Arrow",
      windows: "Arrow"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "EnterExitCell",
    description: "ShortcutsSheet_Table_EnterExitASelectedCell",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Enter",
      windows: "Enter"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "AddNewLineShift",
    description: "ShortcutsSheet_Table_AddANewLineWithinCell",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Shift+Enter",
      windows: "Shift+Enter"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "AddNewLineAlt",
    description: "ShortcutsSheet_Table_AddANewLineWithinCell",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Meta+Enter",
      windows: "Meta+Enter"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "SelectContentInCell",
    description: "ShortcutsSheet_Table_SelectingAllContentInsideCell",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Meta+A",
      windows: "Ctrl+A"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "SelectColumn",
    description: "ShortcutsSheet_Table_SelectColumn",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Alt+Space",
      windows: "Alt+Space"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "SelectRow",
    description: "ShortcutsSheet_Table_SelectRow",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Shift+Space",
      windows: "Shift+Space"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "SelectTable",
    description: "ShortcutsSheet_Table_SelectTable",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Meta+A",
      windows: "Ctrl+A"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "AddNewColumnRow",
    description: "ShortcutsSheet_Table_AddNewColumnRow",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Alt+Ctrl+=",
      windows: "Alt+Ctrl+="
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "DeleteColumnRow",
    description: "ShortcutsSheet_Table_DeleteSelectedColumnRow",
    group: "ShortcutsSheet_Section_Table",
    keys: {
      macOs: "Alt+Ctrl+-",
      windows: "Alt+Ctrl+-"
    },
    enabled: false,
    showInShortcutSheet: true,
    command: () => "continue"
  }),
  createShortcut({
    name: "TableEscapeNavigation",
    group: "ShortcutsSheet_Section_Formatting",
    description: void 0,
    keys: {
      macOs: "Escape",
      windows: "Escape"
    },
    enabled: true,
    showInShortcutSheet: false,
    command: ({ editor, event }) => {
      const { state } = editor.view;
      const { selection } = state;
      if (!isInTable(state)) {
        return "continue";
      }
      if (isRicosCellSelection(selection)) {
        const table = TableQuery.of(selection);
        if (table && table.isTableSelected()) {
          return "continue";
        }
        editor.commands.selectWholeTable();
        event?.preventDefault();
        event?.stopImmediatePropagation();
        return "handled";
      }
      const tablePos = findTable(selection);
      if (!tablePos) {
        return "continue";
      }
      const cell = findParentNodeClosestToPos(
        selection.$from,
        (node) => [TIPTAP_TABLE_CELL_TYPE, TIPTAP_TABLE_HEADER_CELL_TYPE].includes(node.type.name)
      );
      if (!cell) {
        return "continue";
      }
      editor.commands.setCellSelection(cell.pos);
      event?.preventDefault();
      event?.stopImmediatePropagation();
      return "handled";
    }
  })
];
export {
  shortcuts
};
//# sourceMappingURL=shortcuts.js.map
