UNPKG

@atlaskit/editor-plugin-indentation

Version:

Indentation plugin for @atlaskit/editor-core

62 lines (60 loc) 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; exports.keymapPlugin = keymapPlugin; var _analytics = require("@atlaskit/editor-common/analytics"); var _keymaps = require("@atlaskit/editor-common/keymaps"); var _utils = require("@atlaskit/editor-common/utils"); var _keymap = require("@atlaskit/editor-prosemirror/keymap"); var _utils2 = require("@atlaskit/editor-prosemirror/utils"); var _editorCommands = require("../editor-commands"); function keymapPlugin(editorAnalyticsAPI) { var list = {}; (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.findShortcutByKeymap)(_keymaps.indent), function (state, dispatch) { var _state$schema$nodes = state.schema.nodes, blockTaskItem = _state$schema$nodes.blockTaskItem, paragraph = _state$schema$nodes.paragraph, doc = _state$schema$nodes.doc; if (blockTaskItem) { var hasBlockTaskItem = false; var hasParagraphAtDocLevel = false; // Check if the selection contains a blockTaskItem state.doc.nodesBetween(state.selection.from, state.selection.to, function (node, _pos, parent) { if (node.type === blockTaskItem) { hasBlockTaskItem = true; return false; // stop iterating } if (node.type === paragraph && (parent === null || parent === void 0 ? void 0 : parent.type) === doc) { hasParagraphAtDocLevel = true; } }); if (hasBlockTaskItem && !hasParagraphAtDocLevel) { return false; // let `editor-plugin-tasks-and-decisions` handle indentation } } return (0, _editorCommands.getIndentCommand)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD)(state, dispatch); }, list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.findShortcutByKeymap)(_keymaps.outdent), (0, _editorCommands.getOutdentCommand)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.findShortcutByKeymap)(_keymaps.backspace), function (state, dispatch) { var selection = state.selection; var blockTaskItem = state.schema.nodes.blockTaskItem; // Let `editor-plugin-tasks-and-decisions` handle indentation inside blockTaskItems if ((0, _utils.isTextSelection)(selection) && selection.$cursor && selection.$cursor.parentOffset === 0 && !(0, _utils2.hasParentNodeOfType)([blockTaskItem])(selection)) { return dispatch ? (0, _editorCommands.getOutdentCommand)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD)(state, dispatch) : false; } return false; }, list); return (0, _keymap.keymap)(list); } var _default = exports.default = keymapPlugin;