@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
25 lines (22 loc) • 1.22 kB
JavaScript
import { getDiffableAttrNames } from './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.
*/
export var normalizeCellBackground = function normalizeCellBackground(background) {
return typeof background === 'string' && background !== '' && background !== 'null' ? background : null;
};
/** Whether two cells render different backgrounds. */
export var 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.
*/
export var isCellAttrChanged = function isCellAttrChanged(left, right) {
var _getDiffableAttrNames;
return ((_getDiffableAttrNames = 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];
});
};