UNPKG

@atlaskit/editor-plugin-toolbar-lists-indentation

Version:

Toolbar lists and indentation plugin for @atlaskit/editor-core

50 lines (48 loc) 2.65 kB
import { MAX_INDENTATION_LEVEL } from '@atlaskit/editor-common/indentation'; import { getListItemAttributes } from '@atlaskit/editor-common/lists'; import { hasParentNodeOfType } from '@atlaskit/editor-prosemirror/utils'; export 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 = 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 >= 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 = 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 === null || indentationState === void 0 ? void 0 : indentationState.indentDisabled) !== undefined && (indentationState === null || indentationState === void 0 ? void 0 : indentationState.outdentDisabled) !== undefined) { return { indentDisabled: indentationState.indentDisabled, outdentDisabled: indentationState.outdentDisabled, node: 'paragraph_heading' }; } return state; }