@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
30 lines (27 loc) • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.normalizeCellBackground = exports.isCellBackgroundChanged = exports.isCellAttrChanged = void 0;
var _diffableAttrs = require("./diffableAttrs");
/**
* A cell background as it renders: absent, empty and `"null"` — the string agent payloads send for
* no background — all mean the cell has none.
*/
var normalizeCellBackground = exports.normalizeCellBackground = function normalizeCellBackground(background) {
return typeof background === 'string' && background !== '' && background !== 'null' ? background : null;
};
/** Whether two cells render different backgrounds. */
var isCellBackgroundChanged = exports.isCellBackgroundChanged = function isCellBackgroundChanged(left, right) {
return normalizeCellBackground(left.attrs.background) !== normalizeCellBackground(right.attrs.background);
};
/**
* Whether two cells differ by an attribute that represents a change, such as their background or
* span, as opposed to only their content.
*/
var isCellAttrChanged = exports.isCellAttrChanged = function isCellAttrChanged(left, right) {
var _getDiffableAttrNames;
return ((_getDiffableAttrNames = (0, _diffableAttrs.getDiffableAttrNames)(left.type.name, left.attrs)) !== null && _getDiffableAttrNames !== void 0 ? _getDiffableAttrNames : []).some(function (name) {
return name === 'background' ? isCellBackgroundChanged(left, right) : left.attrs[name] !== right.attrs[name];
});
};