@atlaskit/editor-plugin-toolbar-lists-indentation
Version:
Toolbar lists and indentation plugin for @atlaskit/editor-core
56 lines (53 loc) • 2.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getIndentationButtonsState = getIndentationButtonsState;
var _indentation = require("@atlaskit/editor-common/indentation");
var _lists = require("@atlaskit/editor-common/lists");
var _utils = require("@atlaskit/editor-prosemirror/utils");
function getIndentationButtonsState(editorState, allowHeadingAndParagraphIndentation, taskDecisionState, indentationState, isInsideListItem) {
var _indentationState$isI;
var state = {
indentDisabled: true,
outdentDisabled: true,
node: null
};
var selection = editorState.selection;
// Handle bullet and numbered lists seperately as they do
// not use the indentation mark.
// Check for lists before paragraphs and headings in case
// the selection is in a list nested in a layout column.
if (isInsideListItem !== null && isInsideListItem !== void 0 && isInsideListItem(editorState.tr)) {
var _getListItemAttribute = (0, _lists.getListItemAttributes)(selection.$head),
indentLevel = _getListItemAttribute.indentLevel,
itemIndex = _getListItemAttribute.itemIndex;
return {
// List indent levels are zero indexed so we need to subtract 1
indentDisabled: itemIndex === 0 || indentLevel >= _indentation.MAX_INDENTATION_LEVEL - 1,
outdentDisabled: false,
node: 'list'
};
}
// Handle tasks seperately as they do not use the indentation mark
// and have different behaviour for outdent compared to lists
if (taskDecisionState !== null && taskDecisionState !== void 0 && taskDecisionState.isInsideTask) {
return {
indentDisabled: taskDecisionState.indentDisabled,
outdentDisabled: taskDecisionState.outdentDisabled,
node: 'taskList'
};
}
var isTopLevelParagraphOrHeading = selection.$from.depth === 1;
var isInLayoutNode = (0, _utils.hasParentNodeOfType)(editorState.schema.nodes.layoutColumn)(selection) &&
// depth of non-nested paragraphs and headings in layouts will always be 3
selection.$from.depth === 3;
if (allowHeadingAndParagraphIndentation && ((_indentationState$isI = indentationState === null || indentationState === void 0 ? void 0 : indentationState.isIndentationAllowed) !== null && _indentationState$isI !== void 0 ? _indentationState$isI : false) && (isTopLevelParagraphOrHeading || isInLayoutNode) && indentationState) {
return {
indentDisabled: indentationState.indentDisabled,
outdentDisabled: indentationState.outdentDisabled,
node: 'paragraph_heading'
};
}
return state;
}