@atlaskit/editor-plugin-indentation
Version:
Indentation plugin for @atlaskit/editor-core
48 lines • 2.13 kB
JavaScript
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 var indentationPlugin = function indentationPlugin(_ref) {
var _api$analytics, _api$analytics2;
var api = _ref.api;
return {
name: 'indentation',
marks: function marks() {
return [{
name: 'indentation',
mark: indentation
}];
},
actions: {
indentParagraphOrHeading: getIndentCommand(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions),
outdentParagraphOrHeading: getOutdentCommand(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)
},
getSharedState: function getSharedState(editorState) {
var _ref2;
if (!editorState) {
return undefined;
}
var selection = editorState.tr.selection,
indentation = editorState.schema.marks.indentation;
var node = selection.$from.node();
var indentationMark = node.marks.find(function (mark) {
return mark.type === indentation;
});
return {
isIndentationAllowed: isIndentationAllowed(editorState.schema, node),
// @ts-ignore - TS2869 TypeScript 5.9.2 upgrade
indentDisabled: (_ref2 = (indentationMark === null || indentationMark === void 0 ? void 0 : indentationMark.attrs.level) >= MAX_INDENTATION_LEVEL) !== null && _ref2 !== void 0 ? _ref2 : false,
outdentDisabled: !indentationMark
};
},
pmPlugins: function pmPlugins() {
return [{
name: 'indentationKeymap',
plugin: function plugin() {
var _api$analytics3;
return keymapPlugin(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
}
}];
}
};
};