UNPKG

@atlaskit/editor-plugin-indentation

Version:

Indentation plugin for @atlaskit/editor-core

55 lines 2.07 kB
import { indentation } from '@atlaskit/adf-schema'; import { MAX_INDENTATION_LEVEL } from '@atlaskit/editor-common/indentation'; import { getIndentCommand, getOutdentCommand, isIndentationAllowed } from './editor-commands'; import { keymapPlugin } from './pm-plugins/keymap'; export const indentationPlugin = ({ api }) => { var _api$analytics, _api$analytics2; return { name: 'indentation', marks() { return [{ name: 'indentation', mark: indentation }]; }, actions: { indentParagraphOrHeading: getIndentCommand(api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions), outdentParagraphOrHeading: getOutdentCommand(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions) }, getSharedState(editorState) { var _ref; if (!editorState) { return undefined; } const { tr: { selection }, schema: { marks: { indentation } } } = editorState; const node = selection.$from.node(); const indentationMark = node.marks.find(mark => mark.type === indentation); return { isIndentationAllowed: isIndentationAllowed(editorState.schema, node), // @ts-ignore - TS2869 TypeScript 5.9.2 upgrade indentDisabled: (_ref = (indentationMark === null || indentationMark === void 0 ? void 0 : indentationMark.attrs.level) >= MAX_INDENTATION_LEVEL) !== null && _ref !== void 0 ? _ref : false, outdentDisabled: !indentationMark }; }, pmPlugins() { return [{ name: 'indentationKeymap', plugin: () => { var _api$analytics3; return keymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions); } }]; } }; };