@atlaskit/editor-plugin-paste
Version:
Paste plugin for @atlaskit/editor-core
23 lines • 886 B
JavaScript
import { getDefaultCodeBlockAttrs, getInsertedCodeBlocksInTransaction } from '@atlaskit/editor-common/code-block';
var isCodeBlockWithUnsetWrap = function isCodeBlockWithUnsetWrap(node) {
return node.attrs.wrap === null;
};
var patchInsertedCodeBlocks = function patchInsertedCodeBlocks(tr, insertedCodeBlocks) {
insertedCodeBlocks.forEach(function (_ref) {
var node = _ref.node,
pos = _ref.pos;
tr.setNodeMarkup(pos, undefined, getDefaultCodeBlockAttrs(node.attrs), node.marks);
});
};
export var normalizePastedCodeBlockAttrs = function normalizePastedCodeBlockAttrs(tr, codeBlockType) {
if (!codeBlockType) {
return tr;
}
var insertedCodeBlocks = getInsertedCodeBlocksInTransaction(tr, codeBlockType, {
filter: isCodeBlockWithUnsetWrap
});
if (insertedCodeBlocks.length) {
patchInsertedCodeBlocks(tr, insertedCodeBlocks);
}
return tr;
};