@atlaskit/editor-plugin-paste
Version:
Paste plugin for @atlaskit/editor-core
29 lines (28 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.normalizePastedCodeBlockAttrs = void 0;
var _codeBlock = require("@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, (0, _codeBlock.getDefaultCodeBlockAttrs)(node.attrs), node.marks);
});
};
var normalizePastedCodeBlockAttrs = exports.normalizePastedCodeBlockAttrs = function normalizePastedCodeBlockAttrs(tr, codeBlockType) {
if (!codeBlockType) {
return tr;
}
var insertedCodeBlocks = (0, _codeBlock.getInsertedCodeBlocksInTransaction)(tr, codeBlockType, {
filter: isCodeBlockWithUnsetWrap
});
if (insertedCodeBlocks.length) {
patchInsertedCodeBlocks(tr, insertedCodeBlocks);
}
return tr;
};