@atlaskit/editor-plugin-toolbar-lists-indentation
Version:
Toolbar lists and indentation plugin for @atlaskit/editor-core
64 lines (63 loc) • 3.41 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.OutdentMenuItem = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactIntl = require("react-intl");
var _keymaps = require("@atlaskit/editor-common/keymaps");
var _messages = require("@atlaskit/editor-common/messages");
var _toolbar = require("@atlaskit/editor-common/toolbar");
var _editorToolbar = require("@atlaskit/editor-toolbar");
var _hooks = require("../utils/hooks");
var OutdentMenuItem = exports.OutdentMenuItem = function OutdentMenuItem(_ref) {
var api = _ref.api,
allowHeadingAndParagraphIndentation = _ref.allowHeadingAndParagraphIndentation,
showIndentationButtons = _ref.showIndentationButtons,
parents = _ref.parents;
var _useIntl = (0, _reactIntl.useIntl)(),
formatMessage = _useIntl.formatMessage;
var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
editorView = _useEditorToolbar.editorView;
var indentationState = (0, _hooks.useIndentationState)({
api: api,
allowHeadingAndParagraphIndentation: allowHeadingAndParagraphIndentation,
state: editorView === null || editorView === void 0 ? void 0 : editorView.state
});
if (!showIndentationButtons) {
return null;
}
var onClick = function onClick() {
var inputMethod = (0, _toolbar.getInputMethodFromParentKeys)(parents);
var node = indentationState === null || indentationState === void 0 ? void 0 : indentationState.node;
if (node === 'paragraph_heading') {
if (editorView !== null && editorView !== void 0 && editorView.state) {
var _api$indentation;
api === null || api === void 0 || (_api$indentation = api.indentation) === null || _api$indentation === void 0 || _api$indentation.actions.outdentParagraphOrHeading(inputMethod)(editorView === null || editorView === void 0 ? void 0 : editorView.state, editorView === null || editorView === void 0 ? void 0 : editorView.dispatch);
}
}
if (node === 'list') {
api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.list.commands.outdentList(inputMethod));
}
if (node === 'taskList') {
if (editorView !== null && editorView !== void 0 && editorView.state) {
var _api$taskDecision;
api === null || api === void 0 || (_api$taskDecision = api.taskDecision) === null || _api$taskDecision === void 0 || _api$taskDecision.actions.outdentTaskList(inputMethod)(editorView === null || editorView === void 0 ? void 0 : editorView.state, editorView === null || editorView === void 0 ? void 0 : editorView.dispatch);
}
}
};
var shortcut = (0, _keymaps.formatShortcut)(_keymaps.outdent);
return /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarDropdownItem, {
elemBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.OutdentIcon, {
size: "small",
label: ""
}),
elemAfter: shortcut ? /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarKeyboardShortcutHint, {
shortcut: shortcut
}) : undefined,
isDisabled: indentationState === null || indentationState === void 0 ? void 0 : indentationState.outdentDisabled,
ariaKeyshortcuts: shortcut,
onClick: onClick
}, formatMessage(_messages.indentationMessages.outdent));
};