UNPKG

@atlaskit/editor-plugin-block-type

Version:

BlockType plugin for @atlaskit/editor-core

69 lines (63 loc) • 4.63 kB
"use strict"; var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = keymapPlugin; var _enums = require("@atlaskit/editor-common/analytics/types/enums"); var _keymap = require("@atlaskit/editor-common/keymap"); var _keymaps = require("@atlaskit/editor-common/keymaps"); var _commands = require("@atlaskit/editor-common/utils/commands"); var _commands2 = require("@atlaskit/editor-prosemirror/commands"); var _redo = require("@atlaskit/prosemirror-history/redo"); var _undo = require("@atlaskit/prosemirror-history/undo"); var blockTypes = _interopRequireWildcard(require("./block-types")); var _blockType = require("./commands/block-type"); var _deleteAndMoveCursor = require("./commands/delete-and-move-cursor"); var _deleteBlockContent = require("./commands/delete-block-content"); var _splitHeadingWithTrailingSpace = require("./commands/split-heading-with-trailing-space"); var _utils = require("./utils"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); } // Ignored via go/ees005 // eslint-disable-next-line import/no-namespace var backspaceCommand = (0, _commands2.chainCommands)(_blockType.cleanUpAtTheStartOfDocument, (0, _deleteBlockContent.deleteBlockContent)(_utils.isNodeAWrappingBlockNode), _deleteAndMoveCursor.deleteAndMoveCursor); var del = (0, _commands2.chainCommands)((0, _commands.deleteEmptyParagraphAndMoveBlockUp)(_utils.isNodeAWrappingBlockNode), (0, _deleteBlockContent.deleteBlockContent)(_utils.isNodeAWrappingBlockNode), _deleteAndMoveCursor.deleteAndMoveCursor); function keymapPlugin(editorAnalyticsApi, schema, _featureFlags) { var _enter$common; var list = {}; (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.insertNewLine.common, (0, _commands.insertNewLineWithAnalytics)(editorAnalyticsApi), list); // Fixes the "Enter after a heading with trailing whitespace creates another // heading instead of a paragraph" bug. The command is a no-op (returns false) // in every case except that exact scenario, so other Enter handlers are // unaffected. (0, _keymaps.bindKeymapWithCommand)((_enter$common = _keymaps.enter.common) !== null && _enter$common !== void 0 ? _enter$common : 'Enter', _splitHeadingWithTrailingSpace.splitHeadingWithTrailingSpace, list); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveUp.common, _commands.createNewParagraphAbove, list); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.bindKeymapWithCommand)(_keymaps.moveDown.common, _commands.createNewParagraphBelow, list); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.bindKeymapWithCommand)((0, _keymaps.findKeyMapForBrowser)(_keymaps.redo), _redo.redo, list); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.bindKeymapWithCommand)(_keymaps.undo.common, _undo.undo, list); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, backspaceCommand, list); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.bindKeymapWithCommand)(_keymaps.deleteKey.common, del, list); (0, _keymaps.bindKeymapWithCommand)(_keymaps.forwardDelete.mac, del, list); if (schema.nodes[blockTypes.BLOCK_QUOTE.nodeName]) { (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.findShortcutByKeymap)(_keymaps.toggleBlockQuote), (0, _blockType.insertBlockQuoteWithAnalytics)(_enums.INPUT_METHOD.KEYBOARD, editorAnalyticsApi), list); } return (0, _keymap.keymap)(list); }