UNPKG

@atlaskit/editor-plugin-table

Version:

Table plugin for the @atlaskit/editor

198 lines (193 loc) 12.5 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 _preset = require("@atlaskit/editor-common/preset"); var _commands = require("@atlaskit/editor-prosemirror/commands"); var _keymap = require("@atlaskit/editor-prosemirror/keymap"); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var _commandsWithAnalytics = require("../pm-plugins/drag-and-drop/commands-with-analytics"); var _commands2 = require("./commands"); var _columnResize = require("./commands/column-resize"); var _commandsWithAnalytics2 = require("./commands/commands-with-analytics"); var _goToNextCell = require("./commands/go-to-next-cell"); var _insert = require("./commands/insert"); function keymapPlugin(getEditorContainerWidth, api, nodeViewPortalProviderAPI, editorAnalyticsAPI, dragAndDropEnabled) { var _pluginInjectionApi$a; var isTableScalingEnabled = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false; var isTableAlignmentEnabled = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false; var isFullWidthEnabled = arguments.length > 7 ? arguments[7] : undefined; var pluginInjectionApi = arguments.length > 8 ? arguments[8] : undefined; var getIntl = arguments.length > 9 ? arguments[9] : undefined; var isTableFixedColumnWidthsOptionEnabled = arguments.length > 10 && arguments[10] !== undefined ? arguments[10] : false; var shouldUseIncreasedScalingPercent = arguments.length > 11 ? arguments[11] : undefined; var isCommentEditor = arguments.length > 12 ? arguments[12] : undefined; var isChromelessEditor = arguments.length > 13 ? arguments[13] : undefined; var isTableResizingEnabled = arguments.length > 14 ? arguments[14] : undefined; var list = {}; var ariaNotifyPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.accessibilityUtils) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.ariaNotify; (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.nextCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(1), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.previousCell.common, (0, _commands2.goToNextCell)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(-1), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.toggleTable.common, (0, _preset.editorCommandToPMCommand)((0, _insert.insertTableWithNestingSupport)({ isTableScalingEnabled: isTableScalingEnabled, isTableAlignmentEnabled: isTableAlignmentEnabled, isFullWidthModeEnabled: !!isFullWidthEnabled, isCommentEditor: isCommentEditor, isChromelessEditor: isChromelessEditor, isTableResizingEnabled: isTableResizingEnabled }, api, { action: _analytics.ACTION.INSERTED, actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT, actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE, attributes: { inputMethod: _analytics.INPUT_METHOD.SHORTCUT }, eventType: _analytics.EVENT_TYPE.TRACK })), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.backspace.common, (0, _commands.chainCommands)((0, _commandsWithAnalytics2.deleteTableIfSelectedWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD), (0, _commandsWithAnalytics2.emptyMultipleCellsWithAnalytics)(editorAnalyticsAPI)(_analytics.INPUT_METHOD.KEYBOARD)), list); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.bindKeymapWithCommand)(_keymaps.backspace.common, _commands2.moveCursorBackward, list); // Add row/column shortcuts (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.addRowBefore.common, (0, _commandsWithAnalytics2.addRowAroundSelection)(editorAnalyticsAPI)('TOP'), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.addRowAfter.common, (0, _commandsWithAnalytics2.addRowAroundSelection)(editorAnalyticsAPI)('BOTTOM'), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.addColumnBefore.common, (0, _insert.addColumnBefore)(api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.addColumnAfter.common, (0, _insert.addColumnAfter)(api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.addRowBeforeVO.common, (0, _commandsWithAnalytics2.addRowAroundSelection)(editorAnalyticsAPI)('TOP'), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.addRowAfterVO.common, (0, _commandsWithAnalytics2.addRowAroundSelection)(editorAnalyticsAPI)('BOTTOM'), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.addColumnBeforeVO.common, (0, _insert.addColumnBefore)(api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.addColumnAfterVO.common, (0, _insert.addColumnAfter)(api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list); if (dragAndDropEnabled && _keymaps.moveRowDown.common && _keymaps.moveRowUp.common && _keymaps.moveColumnLeft.common && _keymaps.moveColumnRight.common) { var isNewKeyMapExperiment = (0, _expValEquals.expValEquals)('editor-a11y-fy26-keyboard-move-row-column', 'isEnabled', true); // Move row/column shortcuts /** * NOTE: If the keyboard shortcut for moving rows or columns is changed, we need to update the handleKeyDown function * in packages/editor/editor-plugin-table/src/pm-plugins/drag-and-drop/plugin.ts * to make sure the logic for holding the shortcut keys is valid * See ticket ED-22154 https://product-fabric.atlassian.net/browse/ED-22154 */ (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 isNewKeyMapExperiment ? _keymaps.moveRowDown.common : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.moveRowDownOld.common, (0, _commandsWithAnalytics.moveSourceWithAnalyticsViaShortcut)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)('table-row', 1), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 isNewKeyMapExperiment ? _keymaps.moveRowUp.common : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.moveRowUpOld.common, (0, _commandsWithAnalytics.moveSourceWithAnalyticsViaShortcut)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)('table-row', -1), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 isNewKeyMapExperiment ? _keymaps.moveColumnLeft.common : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.moveColumnLeftOld.common, (0, _commandsWithAnalytics.moveSourceWithAnalyticsViaShortcut)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)('table-column', -1), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 isNewKeyMapExperiment ? _keymaps.moveColumnRight.common : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.moveColumnRightOld.common, (0, _commandsWithAnalytics.moveSourceWithAnalyticsViaShortcut)(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)('table-column', 1), list); // Delete row/column shortcuts (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.deleteColumn.common, (0, _commandsWithAnalytics2.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut)(editorAnalyticsAPI, api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.deleteRow.common, (0, _commandsWithAnalytics2.deleteSelectedRowsOrColumnsWithAnalyticsViaShortcut)(editorAnalyticsAPI, api, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, shouldUseIncreasedScalingPercent), list); } (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.startColumnResizing.common, (0, _columnResize.initiateKeyboardColumnResizing)({ ariaNotify: ariaNotifyPlugin, getIntl: getIntl, nodeViewPortalProviderAPI: nodeViewPortalProviderAPI }), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.moveRight.common, (0, _columnResize.activateNextResizeArea)({ direction: 1, ariaNotify: ariaNotifyPlugin, getIntl: getIntl, nodeViewPortalProviderAPI: nodeViewPortalProviderAPI }), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.moveLeft.common, (0, _columnResize.activateNextResizeArea)({ direction: -1, ariaNotify: ariaNotifyPlugin, getIntl: getIntl, nodeViewPortalProviderAPI: nodeViewPortalProviderAPI }), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.moveDown.common, (0, _goToNextCell.goToNextCellVertical)(1), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.moveUp.common, (0, _goToNextCell.goToNextCellVertical)(-1), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.decreaseMediaSize.common, (0, _commandsWithAnalytics2.changeColumnWidthByStepWithAnalytics)(editorAnalyticsAPI, api)(-10, getEditorContainerWidth, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, !!isCommentEditor, _analytics.INPUT_METHOD.SHORTCUT, ariaNotifyPlugin, getIntl), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.increaseMediaSize.common, (0, _commandsWithAnalytics2.changeColumnWidthByStepWithAnalytics)(editorAnalyticsAPI, api)(10, getEditorContainerWidth, isTableScalingEnabled, isTableFixedColumnWidthsOptionEnabled, !!isCommentEditor, _analytics.INPUT_METHOD.SHORTCUT, ariaNotifyPlugin, getIntl), list); (0, _keymaps.bindKeymapWithCommand)( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion _keymaps.escape.common, (0, _columnResize.stopKeyboardColumnResizing)({ ariaNotify: ariaNotifyPlugin, getIntl: getIntl }), list); // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion (0, _keymaps.bindKeymapWithCommand)(_keymaps.focusToContextMenuTrigger.common, (0, _commands2.setFocusToCellMenu)(), list); return (0, _keymap.keymap)(list); } var _default = exports.default = keymapPlugin;